diff --git a/mk/ctags.mk b/mk/ctags.mk index a116f2aba6437..1fcb0bb4debbc 100644 --- a/mk/ctags.mk +++ b/mk/ctags.mk @@ -15,14 +15,21 @@ .PHONY: TAGS.emacs TAGS.vi -CTAGS_LOCATIONS=$(wildcard ${CFG_SRC_DIR}src/lib*) +CTAGS_RUSTC_LOCATIONS=$(patsubst ${CFG_SRC_DIR}src/lib%test,, \ + $(wildcard ${CFG_SRC_DIR}src/lib*)) ${CFG_SRC_DIR}src/libtest CTAGS_LOCATIONS=$(patsubst ${CFG_SRC_DIR}src/librust%,, \ $(patsubst ${CFG_SRC_DIR}src/lib%test,, \ $(wildcard ${CFG_SRC_DIR}src/lib*))) ${CFG_SRC_DIR}src/libtest -CTAGS_OPTS=--options="${CFG_SRC_DIR}src/etc/ctags.rust" --languages=Rust --recurse ${CTAGS_LOCATIONS} +CTAGS_OPTS=--options="${CFG_SRC_DIR}src/etc/ctags.rust" --languages=Rust --recurse + +TAGS.rustc.emacs: + ctags -e -f $@ ${CTAGS_OPTS} ${CTAGS_RUSTC_LOCATIONS} TAGS.emacs: - ctags -e -f $@ ${CTAGS_OPTS} + ctags -e -f $@ ${CTAGS_OPTS} ${CTAGS_LOCATIONS} + +TAGS.rustc.vi: + ctags -f $@ ${CTAGS_OPTS} ${CTAGS_RUSTC_LOCATIONS} TAGS.vi: - ctags -f $@ ${CTAGS_OPTS} + ctags -f $@ ${CTAGS_OPTS} ${CTAGS_LOCATIONS} diff --git a/mk/platform.mk b/mk/platform.mk index 59c8f7726c92f..c2644621c571a 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -169,7 +169,7 @@ ifdef CFG_CCACHE_BASEDIR export CCACHE_BASEDIR endif -FIND_COMPILER = $(word 1,$(1:ccache=)) +FIND_COMPILER = $(strip $(1:ccache=)) define CFG_MAKE_TOOLCHAIN # Prepend the tools with their prefix if cross compiling @@ -187,7 +187,7 @@ define CFG_MAKE_TOOLCHAIN endif endif - CFG_COMPILE_C_$(1) = '$$(CC_$(1))' \ + CFG_COMPILE_C_$(1) = '$$(call FIND_COMPILER,$$(CC_$(1)))' \ $$(CFLAGS) \ $$(CFG_GCCISH_CFLAGS) \ $$(CFG_GCCISH_CFLAGS_$(1)) \ @@ -198,7 +198,7 @@ define CFG_MAKE_TOOLCHAIN $$(CFG_GCCISH_LINK_FLAGS_$(1)) \ $$(CFG_GCCISH_DEF_FLAG_$(1))$$(3) $$(2) \ $$(call CFG_INSTALL_NAME_$(1),$$(4)) - CFG_COMPILE_CXX_$(1) = '$$(CXX_$(1))' \ + CFG_COMPILE_CXX_$(1) = '$$(call FIND_COMPILER,$$(CXX_$(1)))' \ $$(CXXFLAGS) \ $$(CFG_GCCISH_CFLAGS) \ $$(CFG_GCCISH_CXXFLAGS) \ diff --git a/mk/tests.mk b/mk/tests.mk index d1924c67b2ee1..cc712413d3b1c 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -635,8 +635,8 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) = \ --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \ --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \ --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \ - --cc '$$(CC_$(2))' \ - --cxx '$$(CXX_$(2))' \ + --cc '$$(call FIND_COMPILER,$$(CC_$(2)))' \ + --cxx '$$(call FIND_COMPILER,$$(CXX_$(2)))' \ --cflags "$$(CFG_GCCISH_CFLAGS_$(2))" \ --llvm-components "$$(LLVM_ALL_COMPONENTS_$(2))" \ --llvm-cxxflags "$$(LLVM_CXXFLAGS_$(2))" \ diff --git a/src/bootstrap/build/job.rs b/src/bootstrap/build/job.rs index a4e53bc45fcfb..4558e6f049432 100644 --- a/src/bootstrap/build/job.rs +++ b/src/bootstrap/build/job.rs @@ -54,7 +54,7 @@ pub unsafe fn setup() { // Indicate that when all handles to the job object are gone that all // process in the object should be killed. Note that this includes our - // entire process tree by default because we've added ourselves and and our + // entire process tree by default because we've added ourselves and our // children will reside in the job by default. let mut info = mem::zeroed::(); info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; diff --git a/src/doc/reference.md b/src/doc/reference.md index fcf9aefaba847..397abfe563c1f 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2063,33 +2063,41 @@ arbitrarily complex configurations through nesting. The following configurations must be defined by the implementation: -* `debug_assertions` - Enabled by default when compiling without optimizations. - This can be used to enable extra debugging code in development but not in - production. For example, it controls the behavior of the standard library's - `debug_assert!` macro. -* `target_arch = "..."` - Target CPU architecture, such as `"x86"`, `"x86_64"` - `"mips"`, `"powerpc"`, `"powerpc64"`, `"arm"`, or `"aarch64"`. -* `target_endian = "..."` - Endianness of the target CPU, either `"little"` or - `"big"`. -* `target_env = ".."` - An option provided by the compiler by default - describing the runtime environment of the target platform. Some examples of - this are `musl` for builds targeting the MUSL libc implementation, `msvc` for - Windows builds targeting MSVC, and `gnu` frequently the rest of the time. This - option may also be blank on some platforms. +* `target_arch = "..."` - Target CPU architecture, such as `"x86"`, + `"x86_64"` `"mips"`, `"powerpc"`, `"powerpc64"`, `"arm"`, or + `"aarch64"`. This value is closely related to the first element of + the platform target triple, though it is not identical. +* `target_os = "..."` - Operating system of the target, examples + include `"windows"`, `"macos"`, `"ios"`, `"linux"`, `"android"`, + `"freebsd"`, `"dragonfly"`, `"bitrig"` , `"openbsd"` or + `"netbsd"`. This value is closely related to the second and third + element of the platform target triple, though it is not identical. * `target_family = "..."` - Operating system family of the target, e. g. `"unix"` or `"windows"`. The value of this configuration option is defined as a configuration itself, like `unix` or `windows`. -* `target_os = "..."` - Operating system of the target, examples include - `"windows"`, `"macos"`, `"ios"`, `"linux"`, `"android"`, `"freebsd"`, `"dragonfly"`, - `"bitrig"` , `"openbsd"` or `"netbsd"`. +* `unix` - See `target_family`. +* `windows` - See `target_family`. +* `target_env = ".."` - Further disambiguates the target platform with + information about the ABI/libc. Presently this value is either + `"gnu"`, `"msvc"`, `"musl"`, or the empty string. For historical + reasons this value has only been defined as non-empty when needed + for disambiguation. Thus on many GNU platforms this value will be + empty. This value is closely related to the fourth element of the + platform target triple, though it is not identical. For example, + embedded ABIs such as `gnueabihf` will simply define `target_env` as + `"gnu"`. +* `target_endian = "..."` - Endianness of the target CPU, either `"little"` or + `"big"`. * `target_pointer_width = "..."` - Target pointer width in bits. This is set to `"32"` for targets with 32-bit pointers, and likewise set to `"64"` for 64-bit pointers. * `target_vendor = "..."` - Vendor of the target, for example `apple`, `pc`, or simply `"unknown"`. * `test` - Enabled when compiling the test harness (using the `--test` flag). -* `unix` - See `target_family`. -* `windows` - See `target_family`. +* `debug_assertions` - Enabled by default when compiling without optimizations. + This can be used to enable extra debugging code in development but not in + production. For example, it controls the behavior of the standard library's + `debug_assert!` macro. You can also set another attribute based on a `cfg` variable with `cfg_attr`: diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 588ad7a319ac3..0f77ebb3c5745 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -419,8 +419,8 @@ impl [T] { /// /// ```rust /// let v = &[1, 2, 3, 4, 5]; - /// for win in v.chunks(2) { - /// println!("{:?}", win); + /// for chunk in v.chunks(2) { + /// println!("{:?}", chunk); /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index 2033ae58d3804..b80f77c0d25a9 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -214,7 +214,7 @@ pub trait Iterator { /// Like most indexing operations, the count starts from zero, so `nth(0)` /// returns the first value, `nth(1)` the second, and so on. /// - /// `nth()` will return `None` if `n` is larger than the length of the + /// `nth()` will return `None` if `n` is greater than or equal to the length of the /// iterator. /// /// # Examples @@ -237,7 +237,7 @@ pub trait Iterator { /// assert_eq!(iter.nth(1), None); /// ``` /// - /// Returning `None` if there are less than `n` elements: + /// Returning `None` if there are less than `n + 1` elements: /// /// ``` /// let a = [1, 2, 3]; diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 589ac90b308ad..af4ac482cf7d0 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -37,6 +37,17 @@ use slice::SliceExt; /// `wrapping_add`, or through the `Wrapping` type, which says that /// all standard arithmetic operations on the underlying value are /// intended to have wrapping semantics. +/// +/// # Examples +/// +/// ``` +/// use std::num::Wrapping; +/// +/// let zero = Wrapping(0u32); +/// let one = Wrapping(1u32); +/// +/// assert_eq!(std::u32::MAX, (zero - one).0); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)] pub struct Wrapping(#[stable(feature = "rust1", since = "1.0.0")] pub T); diff --git a/src/librustc/dep_graph/thread.rs b/src/librustc/dep_graph/thread.rs index 5b0e4a909c8d3..b15e0e33b8402 100644 --- a/src/librustc/dep_graph/thread.rs +++ b/src/librustc/dep_graph/thread.rs @@ -176,6 +176,9 @@ pub fn main(swap_in: Receiver>, DepMessage::Query => query_out.send(edges.query()).unwrap(), } } - swap_out.send(messages).unwrap(); + if let Err(_) = swap_out.send(messages) { + // the receiver must have been dropped already + break; + } } } diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index b8dd750d3f1c2..1a2c1b9a09528 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1355,7 +1355,7 @@ pub mod nightly_options { early_error(ErrorOutputType::default(), &msg); } OptionStability::UnstableButNotReally => { - let msg = format!("the option `{}` is is unstable and should \ + let msg = format!("the option `{}` is unstable and should \ only be used on the nightly compiler, but \ it is currently accepted for backwards \ compatibility; this will soon change, \ diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index a0d6f5f912b2c..7fb13f49cb4a5 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -40,7 +40,7 @@ use std::rc::Rc; pub enum ProjectionMode { /// FIXME (#32205) /// At coherence-checking time, we're still constructing the - /// specialization graph, and thus we only project project + /// specialization graph, and thus we only project /// non-`default` associated types that are defined directly in /// the applicable impl. (This behavior should be improved over /// time, to allow for successful projections modulo cycles diff --git a/src/librustc/ty/trait_def.rs b/src/librustc/ty/trait_def.rs index faae95e711699..f194afaa81762 100644 --- a/src/librustc/ty/trait_def.rs +++ b/src/librustc/ty/trait_def.rs @@ -176,7 +176,7 @@ impl<'tcx> TraitDef<'tcx> { /// Records a trait-to-implementation mapping for a non-local impl. /// /// The `parent_impl` is the immediately-less-specialized impl, or the - /// trait's def ID if the impl is is not a specialization -- information that + /// trait's def ID if the impl is not a specialization -- information that /// should be pulled from the metadata. pub fn record_remote_impl(&self, tcx: &TyCtxt<'tcx>, diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 609252f948ab3..e362e295b414a 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -272,7 +272,7 @@ impl<'a,'tcx> WfPredicates<'a,'tcx> { /// into `self.out`. fn compute_projection(&mut self, data: ty::ProjectionTy<'tcx>) { // A projection is well-formed if (a) the trait ref itself is - // WF WF and (b) the trait-ref holds. (It may also be + // WF and (b) the trait-ref holds. (It may also be // normalizable and be WF that way.) self.compute_trait_ref(&data.trait_ref); diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 739107afcbd75..c2b86ce28f6c6 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -202,7 +202,7 @@ pub struct TargetOptions { pub post_link_args: Vec, /// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults - /// to "default". + /// to "generic". pub cpu: String, /// Default target features to pass to LLVM. These features will *always* be /// passed, and cannot be disabled even via `-C`. Corresponds to `llc diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs index e838921a83178..03fb5260c3992 100644 --- a/src/librustc_borrowck/diagnostics.rs +++ b/src/librustc_borrowck/diagnostics.rs @@ -286,6 +286,70 @@ You can read more about cell types in the API documentation: https://doc.rust-lang.org/std/cell/ "##, +E0389: r##" +An attempt was made to mutate data using a non-mutable reference. This +commonly occurs when attempting to assign to a non-mutable reference of a +mutable reference (`&(&mut T)`). + +Example of erroneous code: + +```compile_fail +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy = FancyNum{ num: 5 }; + let fancy_ref = &(&mut fancy); + fancy_ref.num = 6; // error: cannot assign to data in a `&` reference + println!("{}", fancy_ref.num); +} +``` + +Here, `&mut fancy` is mutable, but `&(&mut fancy)` is not. Creating an +immutable reference to a value borrows it immutably. There can be multiple +references of type `&(&mut T)` that point to the same value, so they must be +immutable to prevent multiple mutable references to the same value. + +To fix this, either remove the outer reference: + +``` +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy = FancyNum{ num: 5 }; + + let fancy_ref = &mut fancy; + // `fancy_ref` is now &mut FancyNum, rather than &(&mut FancyNum) + + fancy_ref.num = 6; // No error! + + println!("{}", fancy_ref.num); +} +``` + +Or make the outer reference mutable: + +``` +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy = FancyNum{ num: 5 }; + + let fancy_ref = &mut (&mut fancy); + // `fancy_ref` is now &mut(&mut FancyNum), rather than &(&mut FancyNum) + + fancy_ref.num = 6; // No error! + + println!("{}", fancy_ref.num); +} +``` +"##, + E0499: r##" A variable was borrowed as mutable more than once. Erroneous code example: @@ -390,6 +454,90 @@ fn foo(a: &mut i32) { ``` "##, +E0506: r##" +This error occurs when an attempt is made to assign to a borrowed value. + +Example of erroneous code: + +```compile_fail +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy_num = FancyNum { num: 5 }; + let fancy_ref = &fancy_num; + fancy_num = FancyNum { num: 6 }; + // error: cannot assign to `fancy_num` because it is borrowed + + println!("Num: {}, Ref: {}", fancy_num.num, fancy_ref.num); +} +``` + +Because `fancy_ref` still holds a reference to `fancy_num`, `fancy_num` can't +be assigned to a new value as it would invalidate the reference. + +Alternatively, we can move out of `fancy_num` into a second `fancy_num`: + +``` +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy_num = FancyNum { num: 5 }; + let moved_num = fancy_num; + fancy_num = FancyNum { num: 6 }; + + println!("Num: {}, Moved num: {}", fancy_num.num, moved_num.num); +} +``` + +If the value has to be borrowed, try limiting the lifetime of the borrow using +a scoped block: + +``` +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy_num = FancyNum { num: 5 }; + + { + let fancy_ref = &fancy_num; + println!("Ref: {}", fancy_ref.num); + } + + // Works because `fancy_ref` is no longer in scope + fancy_num = FancyNum { num: 6 }; + println!("Num: {}", fancy_num.num); +} +``` + +Or by moving the reference into a function: + +``` +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy_num = FancyNum { num: 5 }; + + print_fancy_ref(&fancy_num); + + // Works because function borrow has ended + fancy_num = FancyNum { num: 6 }; + println!("Num: {}", fancy_num.num); +} + +fn print_fancy_ref(fancy_ref: &FancyNum){ + println!("Ref: {}", fancy_ref.num); +} +``` +"##, + E0507: r##" You tried to move out of a value which was borrowed. Erroneous code example: @@ -510,13 +658,11 @@ http://doc.rust-lang.org/stable/book/references-and-borrowing.html register_diagnostics! { E0385, // {} in an aliasable location E0388, // {} in a static location - E0389, // {} in a `&` reference E0500, // closure requires unique access to `..` but .. is already borrowed E0502, // cannot borrow `..`.. as .. because .. is also borrowed as ... E0503, // cannot use `..` because it was mutably borrowed E0504, // cannot move `..` into closure because it is borrowed E0505, // cannot move out of `..` because it is borrowed - E0506, // cannot assign to `..` because it is borrowed E0508, // cannot move out of type `..`, a non-copy fixed-size array E0509, // cannot move out of type `..`, which defines the `Drop` trait E0524, // two closures require unique access to `..` at the same time diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 4aaeeed343016..3b25104437aee 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -352,7 +352,13 @@ fn handle_explain(code: &str, match descriptions.find_description(&normalised) { Some(ref description) => { // Slice off the leading newline and print. - print!("{}", &description[1..]); + print!("{}", &(&description[1..]).split("\n").map(|x| { + format!("{}\n", if x.starts_with("```") { + "```" + } else { + x + }) + }).collect::()); } None => { early_error(output, &format!("no extended information for {}", code)); diff --git a/src/librustc_trans/intrinsic.rs b/src/librustc_trans/intrinsic.rs index 1220fbafa29c9..7c5ce371ee919 100644 --- a/src/librustc_trans/intrinsic.rs +++ b/src/librustc_trans/intrinsic.rs @@ -1327,7 +1327,7 @@ fn generate_filter_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>, // %ret = call i32 @the_real_filter_function(%ehptrs, %arg) // ret i32 %ret // - // The recoverfp intrinsic is used to recover the frame frame pointer of the + // The recoverfp intrinsic is used to recover the frame pointer of the // `rust_try_fn` function, which is then in turn passed to the // `localrecover` intrinsic (pairing with the `localescape` intrinsic // mentioned above). Putting all this together means that we now have a diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 36da95279fb24..a3200e69e3c42 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -145,14 +145,19 @@ pub struct Implementor { /// Metadata about implementations for a type. #[derive(Clone)] pub struct Impl { - pub impl_: clean::Impl, - pub dox: Option, - pub stability: Option, + pub impl_item: clean::Item, } impl Impl { + fn inner_impl(&self) -> &clean::Impl { + match self.impl_item.inner { + clean::ImplItem(ref impl_) => impl_, + _ => panic!("non-impl item found in impl") + } + } + fn trait_did(&self) -> Option { - self.impl_.trait_.def_id() + self.inner_impl().trait_.def_id() } } @@ -1189,31 +1194,34 @@ impl DocFolder for Cache { // Once we've recursively found all the generics, then hoard off all the // implementations elsewhere let ret = self.fold_item_recur(item).and_then(|item| { - if let clean::Item { attrs, inner: clean::ImplItem(i), .. } = item { + if let clean::Item { inner: clean::ImplItem(_), .. } = item { // Figure out the id of this impl. This may map to a // primitive rather than always to a struct/enum. - let did = match i.for_ { - clean::ResolvedPath { did, .. } | - clean::BorrowedRef { - type_: box clean::ResolvedPath { did, .. }, .. - } => { - Some(did) - } - ref t => { - t.primitive_type().and_then(|t| { - self.primitive_locations.get(&t).map(|n| { - let id = t.to_def_index(); - DefId { krate: *n, index: id } + // Note: matching twice to restrict the lifetime of the `i` borrow. + let did = if let clean::Item { inner: clean::ImplItem(ref i), .. } = item { + match i.for_ { + clean::ResolvedPath { did, .. } | + clean::BorrowedRef { + type_: box clean::ResolvedPath { did, .. }, .. + } => { + Some(did) + } + ref t => { + t.primitive_type().and_then(|t| { + self.primitive_locations.get(&t).map(|n| { + let id = t.to_def_index(); + DefId { krate: *n, index: id } + }) }) - }) + } } + } else { + unreachable!() }; if !self.seen_mod { if let Some(did) = did { self.impls.entry(did).or_insert(vec![]).push(Impl { - impl_: i, - dox: attrs.value("doc").map(|s|s.to_owned()), - stability: item.stability.clone(), + impl_item: item, }); } } @@ -1510,11 +1518,15 @@ impl<'a> Item<'a> { // located, then we return `None`. } else { let cache = cache(); - let path = &cache.external_paths[&self.item.def_id]; - let root = match cache.extern_locations[&self.item.def_id.krate] { - (_, Remote(ref s)) => s.to_string(), - (_, Local) => self.cx.root_path.clone(), - (_, Unknown) => return None, + let path = match cache.external_paths.get(&self.item.def_id) { + Some(path) => path, + None => return None, + }; + let root = match cache.extern_locations.get(&self.item.def_id.krate) { + Some(&(_, Remote(ref s))) => s.to_string(), + Some(&(_, Local)) => self.cx.root_path.clone(), + Some(&(_, Unknown)) => return None, + None => return None, }; Some(format!("{root}{path}/{file}?gotosrc={goto}", root = root, @@ -2449,7 +2461,7 @@ fn render_assoc_items(w: &mut fmt::Formatter, None => return Ok(()), }; let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| { - i.impl_.trait_.is_none() + i.inner_impl().trait_.is_none() }); if !non_trait.is_empty() { let render_header = match what { @@ -2473,7 +2485,7 @@ fn render_assoc_items(w: &mut fmt::Formatter, } if !traits.is_empty() { let deref_impl = traits.iter().find(|t| { - t.impl_.trait_.def_id() == c.deref_trait_did + t.inner_impl().trait_.def_id() == c.deref_trait_did }); if let Some(impl_) = deref_impl { render_deref_methods(w, cx, impl_, containing_item)?; @@ -2481,11 +2493,11 @@ fn render_assoc_items(w: &mut fmt::Formatter, write!(w, "

Trait \ Implementations

")?; let (derived, manual): (Vec<_>, Vec<&Impl>) = traits.iter().partition(|i| { - i.impl_.derived + i.inner_impl().derived }); for i in &manual { let did = i.trait_did().unwrap(); - let assoc_link = AssocItemLink::GotoSource(did, &i.impl_.provided_trait_methods); + let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods); render_impl(w, cx, i, assoc_link, true, containing_item.stable_since())?; } if !derived.is_empty() { @@ -2494,7 +2506,8 @@ fn render_assoc_items(w: &mut fmt::Formatter, ")?; for i in &derived { let did = i.trait_did().unwrap(); - let assoc_link = AssocItemLink::GotoSource(did, &i.impl_.provided_trait_methods); + let assoc_link = AssocItemLink::GotoSource(did, + &i.inner_impl().provided_trait_methods); render_impl(w, cx, i, assoc_link, true, containing_item.stable_since())?; } } @@ -2504,8 +2517,8 @@ fn render_assoc_items(w: &mut fmt::Formatter, fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl, container_item: &clean::Item) -> fmt::Result { - let deref_type = impl_.impl_.trait_.as_ref().unwrap(); - let target = impl_.impl_.items.iter().filter_map(|item| { + let deref_type = impl_.inner_impl().trait_.as_ref().unwrap(); + let target = impl_.inner_impl().items.iter().filter_map(|item| { match item.inner { clean::TypedefItem(ref t, true) => Some(&t.type_), _ => None, @@ -2531,11 +2544,18 @@ fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl, fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLink, render_header: bool, outer_version: Option<&str>) -> fmt::Result { if render_header { - write!(w, "

{}", i.impl_)?; - let since = i.stability.as_ref().map(|s| &s.since[..]); + write!(w, "

{}", i.inner_impl())?; + let since = i.impl_item.stability.as_ref().map(|s| &s.since[..]); render_stability_since_raw(w, since, outer_version)?; - write!(w, "

")?; - if let Some(ref dox) = i.dox { + write!(w, "")?; + if let Some(l) = (Item { item: &i.impl_item, cx: cx }).href() { + write!(w, "[src]", + i.impl_item.def_id.index.as_usize(), l, "goto source code")?; + } + write!(w, "")?; + write!(w, "\n")?; + if let Some(ref dox) = i.impl_item.attrs.value("doc") { write!(w, "
{}
", Markdown(dox))?; } } @@ -2601,7 +2621,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi } write!(w, "
")?; - for trait_item in &i.impl_.items { + for trait_item in &i.inner_impl().items { doctraititem(w, cx, trait_item, link, render_header, false, outer_version)?; } @@ -2629,7 +2649,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi // default items which weren't overridden in the implementation block. if let Some(did) = i.trait_did() { if let Some(t) = cache().traits.get(&did) { - render_default_items(w, cx, t, &i.impl_, render_header, outer_version)?; + render_default_items(w, cx, t, &i.inner_impl(), render_header, outer_version)?; } } write!(w, "
")?; diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index ca15aa2d56c49..a058337a50afd 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -182,11 +182,10 @@ //! //! # fn foo() -> io::Result<()> { //! let f = try!(File::open("foo.txt")); -//! let mut reader = BufReader::new(f); +//! let reader = BufReader::new(f); //! //! for line in reader.lines() { -//! let line = try!(line); -//! println!("{}", line); +//! println!("{}", try!(line)); //! } //! //! # Ok(()) diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index adceee6d73ec5..45b85d600a656 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -89,7 +89,7 @@ impl Ipv4Addr { /// Returns true if this is a loopback address (127.0.0.0/8). /// - /// This property is defined by RFC 6890 + /// This property is defined by RFC 6890. #[stable(since = "1.7.0", feature = "ip_17")] pub fn is_loopback(&self) -> bool { self.octets()[0] == 127 @@ -97,7 +97,7 @@ impl Ipv4Addr { /// Returns true if this is a private address. /// - /// The private address ranges are defined in RFC1918 and include: + /// The private address ranges are defined in RFC 1918 and include: /// /// - 10.0.0.0/8 /// - 172.16.0.0/12 @@ -114,7 +114,7 @@ impl Ipv4Addr { /// Returns true if the address is link-local (169.254.0.0/16). /// - /// This property is defined by RFC 6890 + /// This property is defined by RFC 6890. #[stable(since = "1.7.0", feature = "ip_17")] pub fn is_link_local(&self) -> bool { self.octets()[0] == 169 && self.octets()[1] == 254 @@ -140,7 +140,7 @@ impl Ipv4Addr { /// Returns true if this is a multicast address. /// /// Multicast addresses have a most significant octet between 224 and 239, - /// and is defined by RFC 5771 + /// and is defined by RFC 5771. #[stable(since = "1.7.0", feature = "ip_17")] pub fn is_multicast(&self) -> bool { self.octets()[0] >= 224 && self.octets()[0] <= 239 @@ -354,7 +354,7 @@ impl Ipv6Addr { /// Returns true if this is a unique local address (IPv6). /// - /// Unique local addresses are defined in RFC4193 and have the form fc00::/7. + /// Unique local addresses are defined in RFC 4193 and have the form fc00::/7. pub fn is_unique_local(&self) -> bool { (self.segments()[0] & 0xfe00) == 0xfc00 } @@ -371,7 +371,7 @@ impl Ipv6Addr { } /// Returns true if this is an address reserved for documentation - /// This is defined to be 2001:db8::/32 in RFC RFC 3849 + /// This is defined to be 2001:db8::/32 in RFC 3849. pub fn is_documentation(&self) -> bool { (self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8) } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 1d2516a4c4099..7a86e726b3a6a 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -215,12 +215,38 @@ impl Command { /// /// Builder methods are provided to change these defaults and /// otherwise configure the process. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("sh") + /// .spawn() + /// .expect("sh command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn new>(program: S) -> Command { Command { inner: imp::Command::new(program.as_ref()) } } /// Add an argument to pass to the program. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .arg("-l") + /// .arg("-a") + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn arg>(&mut self, arg: S) -> &mut Command { self.inner.arg(arg.as_ref()); @@ -228,6 +254,19 @@ impl Command { } /// Add multiple arguments to pass to the program. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .args(&["-l", "-a"]) + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn args>(&mut self, args: &[S]) -> &mut Command { for arg in args { @@ -240,6 +279,19 @@ impl Command { /// /// Note that environment variable names are case-insensitive (but case-preserving) on Windows, /// and case-sensitive on all other platforms. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .env("PATH", "/bin") + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn env(&mut self, key: K, val: V) -> &mut Command where K: AsRef, V: AsRef @@ -249,6 +301,19 @@ impl Command { } /// Removes an environment variable mapping. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .env_remove("PATH") + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn env_remove>(&mut self, key: K) -> &mut Command { self.inner.env_remove(key.as_ref()); @@ -256,6 +321,19 @@ impl Command { } /// Clears the entire environment map for the child process. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .env_clear() + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn env_clear(&mut self) -> &mut Command { self.inner.env_clear(); @@ -263,6 +341,19 @@ impl Command { } /// Sets the working directory for the child process. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .current_dir("/bin") + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn current_dir>(&mut self, dir: P) -> &mut Command { self.inner.cwd(dir.as_ref().as_ref()); @@ -270,6 +361,19 @@ impl Command { } /// Configuration for the child process's stdin handle (file descriptor 0). + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::{Command, Stdio}; + /// + /// Command::new("ls") + /// .stdin(Stdio::null()) + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn stdin(&mut self, cfg: Stdio) -> &mut Command { self.inner.stdin(cfg.0); @@ -277,6 +381,19 @@ impl Command { } /// Configuration for the child process's stdout handle (file descriptor 1). + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::{Command, Stdio}; + /// + /// Command::new("ls") + /// .stdout(Stdio::null()) + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn stdout(&mut self, cfg: Stdio) -> &mut Command { self.inner.stdout(cfg.0); @@ -284,6 +401,19 @@ impl Command { } /// Configuration for the child process's stderr handle (file descriptor 2). + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::{Command, Stdio}; + /// + /// Command::new("ls") + /// .stderr(Stdio::null()) + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn stderr(&mut self, cfg: Stdio) -> &mut Command { self.inner.stderr(cfg.0); @@ -293,6 +423,18 @@ impl Command { /// Executes the command as a child process, returning a handle to it. /// /// By default, stdin, stdout and stderr are inherited from the parent. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn spawn(&mut self) -> io::Result { self.inner.spawn(imp::Stdio::Inherit, true).map(Child::from_inner) @@ -308,8 +450,10 @@ impl Command { /// /// ```should_panic /// use std::process::Command; - /// let output = Command::new("/bin/cat").arg("file.txt").output() - /// .expect("failed to execute process"); + /// let output = Command::new("/bin/cat") + /// .arg("file.txt") + /// .output() + /// .expect("failed to execute process"); /// /// println!("status: {}", output.status); /// println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); @@ -333,8 +477,10 @@ impl Command { /// ```should_panic /// use std::process::Command; /// - /// let status = Command::new("/bin/cat").arg("file.txt").status() - /// .expect("failed to execute process"); + /// let status = Command::new("/bin/cat") + /// .arg("file.txt") + /// .status() + /// .expect("failed to execute process"); /// /// println!("process exited with: {}", status); /// @@ -469,12 +615,42 @@ impl fmt::Display for ExitStatus { impl Child { /// Forces the child to exit. This is equivalent to sending a /// SIGKILL on unix platforms. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// let mut command = Command::new("yes"); + /// if let Ok(mut child) = command.spawn() { + /// child.kill().expect("command wasn't running"); + /// } else { + /// println!("yes command didn't start"); + /// } + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn kill(&mut self) -> io::Result<()> { self.handle.kill() } /// Returns the OS-assigned process identifier associated with this child. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// let mut command = Command::new("ls"); + /// if let Ok(child) = command.spawn() { + /// println!("Child's id is {}", child.id()); + /// } else { + /// println!("ls command didn't start"); + /// } + /// ``` #[stable(feature = "process_id", since = "1.3.0")] pub fn id(&self) -> u32 { self.handle.id() @@ -488,6 +664,22 @@ impl Child { /// before waiting. This helps avoid deadlock: it ensures that the /// child does not block waiting for input from the parent, while /// the parent waits for the child to exit. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// let mut command = Command::new("ls"); + /// if let Ok(mut child) = command.spawn() { + /// child.wait().expect("command wasn't running"); + /// println!("Child has finished its execution!"); + /// } else { + /// println!("ls command didn't start"); + /// } + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn wait(&mut self) -> io::Result { drop(self.stdin.take()); diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index b543240c15afb..b1267acdee61a 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -71,7 +71,7 @@ impl Barrier { } } - /// Blocks the current thread until all threads has rendezvoused here. + /// Blocks the current thread until all threads have rendezvoused here. /// /// Barriers are re-usable after all threads have rendezvoused once, and can /// be used continuously. diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 09b1b0a939dcd..cfb8ee16cb069 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -38,8 +38,8 @@ use sys_common::rwlock as sys; /// /// # Poisoning /// -/// RwLocks, like Mutexes, will become poisoned on panics. Note, however, that -/// an RwLock may only be poisoned if a panic occurs while it is locked +/// An `RwLock`, like `Mutex`, will become poisoned on a panic. Note, however, +/// that an `RwLock` may only be poisoned if a panic occurs while it is locked /// exclusively (write mode). If a panic occurs in any reader, then the lock /// will not be poisoned. /// diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 270c2096b2c3b..0500480add22f 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -147,7 +147,7 @@ impl Command { let new_key = pair_to_key(key, val, &mut self.saw_nul); let (map, envp) = self.init_env_map(); - // If `key` is already present then we we just update `envp` in place + // If `key` is already present then we just update `envp` in place // (and store the owned value), but if it's not there we override the // trailing NULL pointer, add a new NULL pointer, and store where we // were located. diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index b3549dc12645a..2f0dec759b3d5 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -13,7 +13,8 @@ //! ## The threading model //! //! An executing Rust program consists of a collection of native OS threads, -//! each with their own stack and local state. +//! each with their own stack and local state. Threads can be named, and +//! provide some built-in support for low-level synchronization. //! //! Communication between threads can be done through //! [channels](../../std/sync/mpsc/index.html), Rust's message-passing @@ -37,20 +38,6 @@ //! convenient facilities for automatically waiting for the termination of a //! child thread (i.e., join). //! -//! ## The `Thread` type -//! -//! Threads are represented via the `Thread` type, which you can -//! get in one of two ways: -//! -//! * By spawning a new thread, e.g. using the `thread::spawn` function. -//! * By requesting the current thread, using the `thread::current` function. -//! -//! Threads can be named, and provide some built-in support for low-level -//! synchronization (described below). -//! -//! The `thread::current()` function is available even for threads not spawned -//! by the APIs of this module. -//! //! ## Spawning a thread //! //! A new thread can be spawned using the `thread::spawn` function: @@ -99,6 +86,18 @@ //! }); //! ``` //! +//! ## The `Thread` type +//! +//! Threads are represented via the `Thread` type, which you can get in one of +//! two ways: +//! +//! * By spawning a new thread, e.g. using the `thread::spawn` function, and +//! calling `thread()` on the `JoinHandle`. +//! * By requesting the current thread, using the `thread::current` function. +//! +//! The `thread::current()` function is available even for threads not spawned +//! by the APIs of this module. +//! //! ## Blocking support: park and unpark //! //! Every thread is equipped with some basic low-level blocking support, via the diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 94e7d0a3939cf..48368cc025c85 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6013,7 +6013,7 @@ impl<'a> Parser<'a> { // FOREIGN STATIC ITEM return Ok(Some(self.parse_item_foreign_static(visibility, lo, attrs)?)); } - if self.check_keyword(keywords::Fn) || self.check_keyword(keywords::Unsafe) { + if self.check_keyword(keywords::Fn) { // FOREIGN FUNCTION ITEM return Ok(Some(self.parse_item_foreign_fn(visibility, lo, attrs)?)); } diff --git a/src/test/codegen-units/item-collection/cross-crate-closures.rs b/src/test/codegen-units/item-collection/cross-crate-closures.rs index 30f3ef12d0743..546bb235a5f50 100644 --- a/src/test/codegen-units/item-collection/cross-crate-closures.rs +++ b/src/test/codegen-units/item-collection/cross-crate-closures.rs @@ -27,7 +27,7 @@ fn main() { //~ TRANS_ITEM fn cgu_extern_closures::inlined_fn_generic[0]::{{closure}}[0] let _ = cgu_extern_closures::inlined_fn_generic(3, 4, 5i32); - // Nothing should be generated for this call, we just link to the instance instance + // Nothing should be generated for this call, we just link to the instance // in the extern crate. let _ = cgu_extern_closures::non_inlined_fn(6, 7); } diff --git a/src/test/parse-fail/extern-no-fn.rs b/src/test/parse-fail/extern-no-fn.rs index bf5cbe0c4592a..acf7187cf436f 100644 --- a/src/test/parse-fail/extern-no-fn.rs +++ b/src/test/parse-fail/extern-no-fn.rs @@ -11,7 +11,7 @@ // compile-flags: -Z parse-only extern { - f(); //~ ERROR expected one of `fn`, `pub`, `static`, `unsafe`, or `}`, found `f` + f(); //~ ERROR expected one of `fn`, `pub`, `static`, or `}`, found `f` } fn main() { diff --git a/src/test/parse-fail/removed-syntax-extern-const.rs b/src/test/parse-fail/removed-syntax-extern-const.rs index c42fae71237da..e632af6c83b1d 100644 --- a/src/test/parse-fail/removed-syntax-extern-const.rs +++ b/src/test/parse-fail/removed-syntax-extern-const.rs @@ -12,5 +12,5 @@ extern { const i: isize; - //~^ ERROR expected one of `fn`, `pub`, `static`, `unsafe`, or `}`, found `const` + //~^ ERROR expected one of `fn`, `pub`, `static`, or `}`, found `const` } diff --git a/src/test/run-pass/regions-lub-ref-ref-rc.rs b/src/test/run-pass/regions-lub-ref-ref-rc.rs index 41c64197acbe8..ade742863a9da 100644 --- a/src/test/run-pass/regions-lub-ref-ref-rc.rs +++ b/src/test/run-pass/regions-lub-ref-ref-rc.rs @@ -9,7 +9,7 @@ // except according to those terms. // Test a corner case of LUB coercion. In this case, one arm of the -// match requires a deref coercion and other other doesn't, and there +// match requires a deref coercion and the other doesn't, and there // is an extra `&` on the `rc`. We want to be sure that the lifetime // assigned to this `&rc` value is not `'a` but something smaller. In // other words, the type from `rc` is `&'a Rc` and the type diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs index 12419d4f7e5f7..a7c8c01fab850 100644 --- a/src/tools/linkchecker/main.rs +++ b/src/tools/linkchecker/main.rs @@ -110,7 +110,7 @@ fn walk(cache: &mut Cache, if let Some(pretty_path) = pretty_path { let entry = cache.get_mut(&pretty_path).unwrap(); // we don't need the source anymore, - // so drop to to reduce memory-usage + // so drop to reduce memory-usage entry.source = String::new(); } }