From e4dd785b591b771882b1c61a541048d57dc86442 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sat, 20 Aug 2016 15:20:22 -0400 Subject: [PATCH 01/15] Correct formatting docs: fmt::Result != io::Result<()> --- src/libcollections/fmt.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index b7cbfb60ec4e9..428ed319ce941 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -165,9 +165,9 @@ //! provides some helper methods. //! //! Additionally, the return value of this function is `fmt::Result` which is a -//! typedef to `Result<(), std::io::Error>` (also known as `std::io::Result<()>`). -//! Formatting implementations should ensure that they return errors from `write!` -//! correctly (propagating errors upward). +//! typedef to `Result<(), std::fmt::Error>`. Formatting implementations should +//! ensure that they return errors from `write!` correctly (propagating errors +//! upward). //! //! An example of implementing the formatting traits would look //! like: From f2655e23ff1b377f09cfbb19253a7ea50cd2c4f3 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sat, 20 Aug 2016 15:27:37 -0400 Subject: [PATCH 02/15] Note that formatters should not return spurious errors. Doing otherwise would break traits like `ToString`. --- src/libcollections/fmt.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index 428ed319ce941..a1b4461949c6e 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -166,8 +166,14 @@ //! //! Additionally, the return value of this function is `fmt::Result` which is a //! typedef to `Result<(), std::fmt::Error>`. Formatting implementations should -//! ensure that they return errors from `write!` correctly (propagating errors -//! upward). +//! ensure that they propagate errors from the `Formatter` (e.g., when calling +//! `write!`) however, they should never return errors spuriously. That is, a +//! formatting implementation must and may only return an error if the passed-in +//! `Formatter` returns an error. This is because, contrary to what the function +//! signature might suggest, string formatting is an infallible operation. +//! This function only returns a result because writing to the underlying stream +//! might fail and it must provide a way to propagate the fact that an error has +//! occurred back up the stack. //! //! An example of implementing the formatting traits would look //! like: From 31b7ff4a841dbccb007237df86d37be4527436ef Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Wed, 17 Aug 2016 14:51:50 -0400 Subject: [PATCH 03/15] refactor range examples This pull request adds a module-level example of how all the range operators work. It also slims down struct-level examples in lieu of a link to module examples. add feature for inclusive_range_syntax fix incorrectly closed code fences --- src/libcore/ops.rs | 66 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 5a1993e741c60..fe5c3099de3bb 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -68,6 +68,22 @@ //! ``` //! //! See the documentation for each trait for an example implementation. +//! +//! This example shows the behavior of the various `Range*` structs. +//! +//! ```rust +//! #![feature(inclusive_range_syntax)] +//! +//! let arr = [0, 1, 2, 3, 4]; +//! +//! assert_eq!(arr[ .. ], [0,1,2,3,4]); // RangeFull +//! assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo +//! assert_eq!(arr[1.. ], [ 1,2,3,4]); // RangeFrom +//! assert_eq!(arr[1..3], [ 1,2 ]); // Range +//! +//! assert_eq!(arr[ ...3], [0,1,2,3 ]); // RangeToIncusive +//! assert_eq!(arr[1...3], [ 1,2,3 ]); // RangeInclusive +//! ``` #![stable(feature = "rust1", since = "1.0.0")] @@ -1594,11 +1610,12 @@ pub trait IndexMut: Index { /// /// ``` /// let arr = [0, 1, 2, 3]; -/// assert_eq!(arr[ .. ], [0,1,2,3]); // RangeFull -/// assert_eq!(arr[ ..3], [0,1,2 ]); -/// assert_eq!(arr[1.. ], [ 1,2,3]); -/// assert_eq!(arr[1..3], [ 1,2 ]); +/// assert_eq!(arr[ .. ], [0, 1, 2, 3]); /// ``` +/// +/// See the [module examples] for the behavior of other range structs. +/// +/// [module examples]: ../#Examples #[derive(Copy, Clone, PartialEq, Eq, Hash)] #[stable(feature = "rust1", since = "1.0.0")] pub struct RangeFull; @@ -1623,12 +1640,13 @@ impl fmt::Debug for RangeFull { /// assert_eq!(3+4+5, (3..6).sum()); /// /// let arr = [0, 1, 2, 3]; -/// assert_eq!(arr[ .. ], [0,1,2,3]); -/// assert_eq!(arr[ ..3], [0,1,2 ]); -/// assert_eq!(arr[1.. ], [ 1,2,3]); -/// assert_eq!(arr[1..3], [ 1,2 ]); // Range +/// assert_eq!(arr[1..3], [1, 2]); /// } /// ``` +/// +/// See the [module examples] for the behavior of other range structs. +/// +/// [module examples]: ../#Examples #[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186 #[stable(feature = "rust1", since = "1.0.0")] pub struct Range { @@ -1686,12 +1704,13 @@ impl> Range { /// assert_eq!(2+3+4, (2..).take(3).sum()); /// /// let arr = [0, 1, 2, 3]; -/// assert_eq!(arr[ .. ], [0,1,2,3]); -/// assert_eq!(arr[ ..3], [0,1,2 ]); -/// assert_eq!(arr[1.. ], [ 1,2,3]); // RangeFrom -/// assert_eq!(arr[1..3], [ 1,2 ]); +/// assert_eq!(arr[1.. ], [1, 2, 3]); /// } /// ``` +/// +/// See the [module examples] for the behavior of other range structs. +/// +/// [module examples]: ../#Examples #[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186 #[stable(feature = "rust1", since = "1.0.0")] pub struct RangeFrom { @@ -1736,12 +1755,13 @@ impl> RangeFrom { /// assert_eq!((..5), std::ops::RangeTo{ end: 5 }); /// /// let arr = [0, 1, 2, 3]; -/// assert_eq!(arr[ .. ], [0,1,2,3]); -/// assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo -/// assert_eq!(arr[1.. ], [ 1,2,3]); -/// assert_eq!(arr[1..3], [ 1,2 ]); +/// assert_eq!(arr[ ..3], [0, 1, 2]); /// } /// ``` +/// +/// See the [module examples] for the behavior of other range structs. +/// +/// [module examples]: ../#Examples #[derive(Copy, Clone, PartialEq, Eq, Hash)] #[stable(feature = "rust1", since = "1.0.0")] pub struct RangeTo { @@ -1788,10 +1808,13 @@ impl> RangeTo { /// assert_eq!(3+4+5, (3...5).sum()); /// /// let arr = [0, 1, 2, 3]; -/// assert_eq!(arr[ ...2], [0,1,2 ]); -/// assert_eq!(arr[1...2], [ 1,2 ]); // RangeInclusive +/// assert_eq!(arr[1...2], [1, 2]); /// } /// ``` +/// +/// See the [module examples] for the behavior of other range structs. +/// +/// [module examples]: ../#Examples #[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186 #[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] pub enum RangeInclusive { @@ -1875,10 +1898,13 @@ impl> RangeInclusive { /// assert_eq!((...5), std::ops::RangeToInclusive{ end: 5 }); /// /// let arr = [0, 1, 2, 3]; -/// assert_eq!(arr[ ...2], [0,1,2 ]); // RangeToInclusive -/// assert_eq!(arr[1...2], [ 1,2 ]); +/// assert_eq!(arr[ ...2], [0, 1, 2]); /// } /// ``` +/// +/// See the [module examples] for the behavior of other range structs. +/// +/// [module examples]: ../#Examples #[derive(Copy, Clone, PartialEq, Eq, Hash)] #[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] pub struct RangeToInclusive { From 33560ee51c71548a553c46039cb83dbd581b0ed5 Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Sun, 21 Aug 2016 17:01:26 -0400 Subject: [PATCH 04/15] add links to interesting items in `std::ptr` documentation r? @steveklabnik add links for Box, Rc, and Vec --- src/libcore/intrinsics.rs | 15 ++++++++++----- src/libcore/ptr.rs | 32 ++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index c645608dda790..0a40a5d0b1462 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -224,15 +224,20 @@ extern "rust-intrinsic" { /// trait objects, because they can't be read out onto the stack and /// dropped normally. /// - /// * It is friendlier to the optimizer to do this over `ptr::read` when - /// dropping manually allocated memory (e.g. when writing Box/Rc/Vec), - /// as the compiler doesn't need to prove that it's sound to elide the - /// copy. + /// * It is friendlier to the optimizer to do this over [`ptr::read`] when + /// dropping manually allocated memory (e.g. when writing + /// [`Box`]/[`Rc`]/[`Vec`]), as the compiler doesn't need to prove that + /// it's sound to elide the copy. /// /// # Undefined Behavior /// - /// This has all the same safety problems as `ptr::read` with respect to + /// This has all the same safety problems as [`ptr::read`] with respect to /// invalid pointers, types, and double drops. + /// + /// [`ptr::read`]: fn.read.html + /// [`Box`]: ../boxed/struct.Box.html + /// [`Rc`]: ../rc/struct.Rc.html + /// [`Vec`]: ../vec/struct.Vec.html #[stable(feature = "drop_in_place", since = "1.8.0")] pub fn drop_in_place(to_drop: *mut T); diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 925cdfec900db..f111070b6a6b7 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -114,11 +114,17 @@ pub unsafe fn replace(dest: *mut T, mut src: T) -> T { /// # Safety /// /// Beyond accepting a raw pointer, this is unsafe because it semantically -/// moves the value out of `src` without preventing further usage of `src`. -/// If `T` is not `Copy`, then care must be taken to ensure that the value at -/// `src` is not used before the data is overwritten again (e.g. with `write`, -/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use -/// because it will attempt to drop the value previously at `*src`. +/// moves the value out of `src` without preventing further usage of `src`. If +/// `T` is not [`Copy`], then care must be taken to ensure that the value at +/// `src` is not used before the data is overwritten again (e.g. with +/// [`write`], [`zero_memory`], or [`copy_memory`]). Note that `*src = foo` +/// counts as a use because it will attempt to drop the value previously at +/// `*src`. +/// +/// [`Copy`]: ../marker/trait.Copy.html +/// [`write`]: fn.write.html +/// [`zero_memory`]: fn.zero_memory.html +/// [`copy_memory`]: fn.copy_memory.html /// /// # Examples /// @@ -206,11 +212,17 @@ pub unsafe fn write(dst: *mut T, src: T) { /// # Safety /// /// Beyond accepting a raw pointer, this is unsafe because it semantically -/// moves the value out of `src` without preventing further usage of `src`. -/// If `T` is not `Copy`, then care must be taken to ensure that the value at -/// `src` is not used before the data is overwritten again (e.g. with `write`, -/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use -/// because it will attempt to drop the value previously at `*src`. +/// moves the value out of `src` without preventing further usage of `src`. If +/// `T` is not [`Copy`], then care must be taken to ensure that the value at +/// `src` is not used before the data is overwritten again (e.g. with +/// [`write`], [`zero_memory`], or [`copy_memory`]). Note that `*src = foo` +/// counts as a use because it will attempt to drop the value previously at +/// `*src`. +/// +/// [`Copy`]: ../marker/trait.Copy.html +/// [`write`]: fn.write.html +/// [`zero_memory`]: fn.zero_memory.html +/// [`copy_memory`]: fn.copy_memory.html /// /// # Examples /// From a377adb9dbfd909df41888c86150df4b4d4ddf7b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 18 Aug 2016 17:50:28 +0200 Subject: [PATCH 05/15] Improve Path and PathBuf docs --- src/libstd/fs.rs | 7 +- src/libstd/path.rs | 174 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 148 insertions(+), 33 deletions(-) diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index b78db24e44b70..a191ce77117ee 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1511,8 +1511,11 @@ pub fn remove_dir_all>(path: P) -> io::Result<()> { /// Returns an iterator over the entries within a directory. /// -/// The iterator will yield instances of `io::Result`. New errors may -/// be encountered after an iterator is initially constructed. +/// The iterator will yield instances of [`io::Result<`][`DirEntry`]`>`. +/// New errors may be encountered after an iterator is initially constructed. +/// +/// [`io::Result<`]: ../io/type.Result.html +/// [`DirEntry`]: struct.DirEntry.html /// /// # Platform-specific behavior /// diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 2d19561139b58..fa15f73777f84 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -986,11 +986,16 @@ impl<'a> cmp::Ord for Components<'a> { // Basic types and traits //////////////////////////////////////////////////////////////////////////////// -/// An owned, mutable path (akin to `String`). +/// An owned, mutable path (akin to [`String`]). /// -/// This type provides methods like `push` and `set_extension` that mutate the -/// path in place. It also implements `Deref` to `Path`, meaning that all -/// methods on `Path` slices are available on `PathBuf` values as well. +/// This type provides methods like [`push`] and [`set_extension`] that mutate +/// the path in place. It also implements [`Deref`] to [`Path`], meaning that +/// all methods on [`Path`] slices are available on `PathBuf` values as well. +/// +/// [`String`]: ../string/struct.String.html +/// [`Path`]: struct.Path.html +/// [`push`]: struct.PathBuf.html#method.push +/// [`set_extension`]: struct.PathBuf.html#method.set_extension /// /// More details about the overall approach can be found in /// the module documentation. @@ -1017,12 +1022,31 @@ impl PathBuf { } /// Allocates an empty `PathBuf`. + /// + /// # Examples + /// + /// ``` + /// use std::path::PathBuf; + /// + /// let path = PathBuf::new(); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn new() -> PathBuf { PathBuf { inner: OsString::new() } } - /// Coerces to a `Path` slice. + /// Coerces to a [`Path`] slice. + /// + /// [`Path`]: struct.Path.html + /// + /// # Examples + /// + /// ``` + /// use std::path::{Path, PathBuf}; + /// + /// let p = PathBuf::from("/test"); + /// assert_eq!(Path::new("/test"), p.as_path()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn as_path(&self) -> &Path { self @@ -1087,10 +1111,26 @@ impl PathBuf { self.inner.push(path); } - /// Truncate `self` to `self.parent()`. + /// Truncate `self` to [`self.parent()`]. /// - /// Returns false and does nothing if `self.file_name()` is `None`. + /// Returns false and does nothing if [`self.file_name()`] is `None`. /// Otherwise, returns `true`. + /// + /// [`self.parent()`]: struct.PathBuf.html#method.parent + /// [`self.file_name()`]: struct.PathBuf.html#method.file_name + /// + /// # Examples + /// + /// ``` + /// use std::path::{Path, PathBuf}; + /// + /// let mut p = PathBuf::from("/test/test.rs"); + /// + /// p.pop(); + /// assert_eq!(Path::new("/test"), p.as_path()); + /// p.pop(); + /// assert_eq!(Path::new("/"), p.as_path()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn pop(&mut self) -> bool { match self.parent().map(|p| p.as_u8_slice().len()) { @@ -1102,11 +1142,13 @@ impl PathBuf { } } - /// Updates `self.file_name()` to `file_name`. + /// Updates [`self.file_name()`] to `file_name`. /// /// If `self.file_name()` was `None`, this is equivalent to pushing /// `file_name`. /// + /// [`self.file_name()`]: struct.PathBuf.html#method.file_name + /// /// # Examples /// /// ``` @@ -1133,12 +1175,29 @@ impl PathBuf { self.push(file_name); } - /// Updates `self.extension()` to `extension`. + /// Updates [`self.extension()`] to `extension`. + /// + /// If [`self.file_name()`] is `None`, does nothing and returns `false`. + /// + /// Otherwise, returns `true`; if [`self.extension()`] is `None`, the + /// extension is added; otherwise it is replaced. + /// + /// [`self.file_name()`]: struct.PathBuf.html#method.file_name + /// [`self.extension()`]: struct.PathBuf.html#method.extension + /// + /// # Examples + /// + /// ``` + /// use std::path::{Path, PathBuf}; /// - /// If `self.file_name()` is `None`, does nothing and returns `false`. + /// let mut p = PathBuf::from("/feel/the"); /// - /// Otherwise, returns `true`; if `self.extension()` is `None`, the extension - /// is added; otherwise it is replaced. + /// p.set_extension("force"); + /// assert_eq!(Path::new("/feel/the.force"), p.as_path()); + /// + /// p.set_extension("dark_side"); + /// assert_eq!(Path::new("/feel/the.dark_side"), p.as_path()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn set_extension>(&mut self, extension: S) -> bool { self._set_extension(extension.as_ref()) @@ -1163,7 +1222,18 @@ impl PathBuf { true } - /// Consumes the `PathBuf`, yielding its internal `OsString` storage. + /// Consumes the `PathBuf`, yielding its internal [`OsString`] storage. + /// + /// [`OsString`]: ../ffi/struct.OsString.html + /// + /// # Examples + /// + /// ``` + /// use std::path::PathBuf; + /// + /// let p = PathBuf::from("/the/head"); + /// let os_str = p.into_os_string(); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn into_os_string(self) -> OsString { self.inner @@ -1301,7 +1371,7 @@ impl Into for PathBuf { } } -/// A slice of a path (akin to `str`). +/// A slice of a path (akin to [`str`]). /// /// This type supports a number of operations for inspecting a path, including /// breaking the path into its components (separated by `/` or `\`, depending on @@ -1310,7 +1380,10 @@ impl Into for PathBuf { /// the module documentation. /// /// This is an *unsized* type, meaning that it must always be used behind a -/// pointer like `&` or `Box`. +/// pointer like `&` or [`Box`]. +/// +/// [`str`]: ../primitive.str.html +/// [`Box`]: ../boxed/struct.Box.html /// /// # Examples /// @@ -1372,7 +1445,9 @@ impl Path { unsafe { mem::transmute(s.as_ref()) } } - /// Yields the underlying `OsStr` slice. + /// Yields the underlying [`OsStr`] slice. + /// + /// [`OsStr`]: ../ffi/struct.OsStr.html /// /// # Examples /// @@ -1387,10 +1462,12 @@ impl Path { &self.inner } - /// Yields a `&str` slice if the `Path` is valid unicode. + /// Yields a [`&str`] slice if the `Path` is valid unicode. /// /// This conversion may entail doing a check for UTF-8 validity. /// + /// [`&str`]: ../primitive.str.html + /// /// # Examples /// /// ``` @@ -1404,10 +1481,12 @@ impl Path { self.inner.to_str() } - /// Converts a `Path` to a `Cow`. + /// Converts a `Path` to a [`Cow`]. /// /// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER. /// + /// [`Cow`]: ../borrow/enum.Cow.html + /// /// # Examples /// /// ``` @@ -1421,7 +1500,9 @@ impl Path { self.inner.to_string_lossy() } - /// Converts a `Path` to an owned `PathBuf`. + /// Converts a `Path` to an owned [`PathBuf`]. + /// + /// [`PathBuf`]: struct.PathBuf.html /// /// # Examples /// @@ -1569,6 +1650,18 @@ impl Path { /// /// If `base` is not a prefix of `self` (i.e. `starts_with` /// returns `false`), returns `Err`. + /// + /// # Examples + /// + /// ``` + /// use std::path::Path; + /// + /// let path = Path::new("/test/haha/foo.txt"); + /// + /// assert_eq!(path.strip_prefix("/test"), Ok(Path::new("haha/foo.txt"))); + /// assert_eq!(path.strip_prefix("test").is_ok(), false); + /// assert_eq!(path.strip_prefix("/haha").is_ok(), false); + /// ``` #[stable(since = "1.7.0", feature = "path_strip_prefix")] pub fn strip_prefix<'a, P: ?Sized>(&'a self, base: &'a P) -> Result<&'a Path, StripPrefixError> @@ -1630,7 +1723,9 @@ impl Path { iter_after(self.components().rev(), child.components().rev()).is_some() } - /// Extracts the stem (non-extension) portion of `self.file_name()`. + /// Extracts the stem (non-extension) portion of [`self.file_name()`]. + /// + /// [`self.file_name()`]: struct.Path.html#method.file_name /// /// The stem is: /// @@ -1653,7 +1748,9 @@ impl Path { self.file_name().map(split_file_at_dot).and_then(|(before, after)| before.or(after)) } - /// Extracts the extension of `self.file_name()`, if possible. + /// Extracts the extension of [`self.file_name()`], if possible. + /// + /// [`self.file_name()`]: struct.Path.html#method.file_name /// /// The extension is: /// @@ -1676,9 +1773,12 @@ impl Path { self.file_name().map(split_file_at_dot).and_then(|(before, after)| before.and(after)) } - /// Creates an owned `PathBuf` with `path` adjoined to `self`. + /// Creates an owned [`PathBuf`] with `path` adjoined to `self`. + /// + /// See [`PathBuf::push`] for more details on what it means to adjoin a path. /// - /// See `PathBuf::push` for more details on what it means to adjoin a path. + /// [`PathBuf`]: struct.PathBuf.html + /// [`PathBuf::push`]: struct.PathBuf.html#method.push /// /// # Examples /// @@ -1698,9 +1798,12 @@ impl Path { buf } - /// Creates an owned `PathBuf` like `self` but with the given file name. + /// Creates an owned [`PathBuf`] like `self` but with the given file name. /// - /// See `PathBuf::set_file_name` for more details. + /// See [`PathBuf::set_file_name`] for more details. + /// + /// [`PathBuf`]: struct.PathBuf.html + /// [`PathBuf::set_file_name`]: struct.PathBuf.html#method.set_file_name /// /// # Examples /// @@ -1721,9 +1824,12 @@ impl Path { buf } - /// Creates an owned `PathBuf` like `self` but with the given extension. + /// Creates an owned [`PathBuf`] like `self` but with the given extension. + /// + /// See [`PathBuf::set_extension`] for more details. /// - /// See `PathBuf::set_extension` for more details. + /// [`PathBuf`]: struct.PathBuf.html + /// [`PathBuf::set_extension`]: struct.PathBuf.html#method.set_extension /// /// # Examples /// @@ -1771,7 +1877,9 @@ impl Path { } } - /// Produce an iterator over the path's components viewed as `OsStr` slices. + /// Produce an iterator over the path's components viewed as [`OsStr`] slices. + /// + /// [`OsStr`]: ../ffi/struct.OsStr.html /// /// # Examples /// @@ -1790,9 +1898,11 @@ impl Path { Iter { inner: self.components() } } - /// Returns an object that implements `Display` for safely printing paths + /// Returns an object that implements [`Display`] for safely printing paths /// that may contain non-Unicode data. /// + /// [`Display`]: fmt/trait.Display.html + /// /// # Examples /// /// ``` @@ -1854,11 +1964,13 @@ impl Path { /// Returns an iterator over the entries within a directory. /// - /// The iterator will yield instances of `io::Result`. New errors may - /// be encountered after an iterator is initially constructed. + /// The iterator will yield instances of [`io::Result<`][`DirEntry`]`>`. New + /// errors may be encountered after an iterator is initially constructed. /// /// This is an alias to [`fs::read_dir`]. /// + /// [`io::Result<`]: ../io/type.Result.html + /// [`DirEntry`]: ../fs/struct.DirEntry.html /// [`fs::read_dir`]: ../fs/fn.read_dir.html #[stable(feature = "path_ext", since = "1.5.0")] pub fn read_dir(&self) -> io::Result { From c7d5f7e5e638775e45c4fdc64f3b91bdbfca9c28 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 23 Aug 2016 10:47:28 -0400 Subject: [PATCH 06/15] Rust has type aliases, not typedefs. They're the same thing but it's better to keep the terminology consistent. --- src/libcollections/fmt.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index a1b4461949c6e..beb3e6b3d4e31 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -165,15 +165,15 @@ //! provides some helper methods. //! //! Additionally, the return value of this function is `fmt::Result` which is a -//! typedef to `Result<(), std::fmt::Error>`. Formatting implementations should -//! ensure that they propagate errors from the `Formatter` (e.g., when calling -//! `write!`) however, they should never return errors spuriously. That is, a -//! formatting implementation must and may only return an error if the passed-in -//! `Formatter` returns an error. This is because, contrary to what the function -//! signature might suggest, string formatting is an infallible operation. -//! This function only returns a result because writing to the underlying stream -//! might fail and it must provide a way to propagate the fact that an error has -//! occurred back up the stack. +//! type alias of `Result<(), std::fmt::Error>`. Formatting implementations +//! should ensure that they propagate errors from the `Formatter` (e.g., when +//! calling `write!`) however, they should never return errors spuriously. That +//! is, a formatting implementation must and may only return an error if the +//! passed-in `Formatter` returns an error. This is because, contrary to what +//! the function signature might suggest, string formatting is an infallible +//! operation. This function only returns a result because writing to the +//! underlying stream might fail and it must provide a way to propagate the fact +//! that an error has occurred back up the stack. //! //! An example of implementing the formatting traits would look //! like: From b400a43c3eccce1ec82b6ea2474c78c89e4af9e3 Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Tue, 23 Aug 2016 12:26:07 -0400 Subject: [PATCH 07/15] add `fn main` wrappers to enable Rust Playground "Run" button --- src/libcore/ops.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index fe5c3099de3bb..8c19902d274ed 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -73,16 +73,17 @@ //! //! ```rust //! #![feature(inclusive_range_syntax)] +//! fn main() { +//! let arr = [0, 1, 2, 3, 4]; //! -//! let arr = [0, 1, 2, 3, 4]; -//! -//! assert_eq!(arr[ .. ], [0,1,2,3,4]); // RangeFull -//! assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo -//! assert_eq!(arr[1.. ], [ 1,2,3,4]); // RangeFrom -//! assert_eq!(arr[1..3], [ 1,2 ]); // Range +//! assert_eq!(arr[ .. ], [0,1,2,3,4]); // RangeFull +//! assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo +//! assert_eq!(arr[1.. ], [ 1,2,3,4]); // RangeFrom +//! assert_eq!(arr[1..3], [ 1,2 ]); // Range //! -//! assert_eq!(arr[ ...3], [0,1,2,3 ]); // RangeToIncusive -//! assert_eq!(arr[1...3], [ 1,2,3 ]); // RangeInclusive +//! assert_eq!(arr[ ...3], [0,1,2,3 ]); // RangeToIncusive +//! assert_eq!(arr[1...3], [ 1,2,3 ]); // RangeInclusive +//! } //! ``` #![stable(feature = "rust1", since = "1.0.0")] From 28f057da77f8b16d4b920cf37273466686b55bf8 Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Wed, 17 Aug 2016 14:12:19 -0400 Subject: [PATCH 08/15] accumulate vector and assert for RangeFrom and RangeInclusive examples PR #35695 for `Range` was approved, so it seems that this side-effect-free style is preferred for Range* examples. This PR performs the same translation for `RangeFrom` and `RangeInclusive`. It also removes what looks to be an erroneously commented line for `#![feature(step_by)]`, and an unnecessary primitive-type annotation in `0u8..`. add `fn main` wrappers to enable Rust Playground "Run" button --- src/libcore/iter/range.rs | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs index 079dfe2a81f80..cdffa0ca60ed2 100644 --- a/src/libcore/iter/range.rs +++ b/src/libcore/iter/range.rs @@ -267,14 +267,12 @@ impl ops::RangeFrom { /// # Examples /// /// ``` - /// # #![feature(step_by)] - /// - /// for i in (0u8..).step_by(2).take(10) { - /// println!("{}", i); + /// #![feature(step_by)] + /// fn main() { + /// let result: Vec<_> = (0..).step_by(2).take(5).collect(); + /// assert_eq!(result, vec![0, 2, 4, 6, 8]); /// } /// ``` - /// - /// This prints the first ten even natural integers (0 to 18). #[unstable(feature = "step_by", reason = "recent addition", issue = "27741")] pub fn step_by(self, by: A) -> StepBy { @@ -295,8 +293,10 @@ impl ops::Range { /// /// ``` /// #![feature(step_by)] - /// let result: Vec<_> = (0..10).step_by(2).collect(); - /// assert_eq!(result, vec![0, 2, 4, 6, 8]); + /// fn main() { + /// let result: Vec<_> = (0..10).step_by(2).collect(); + /// assert_eq!(result, vec![0, 2, 4, 6, 8]); + /// } /// ``` #[unstable(feature = "step_by", reason = "recent addition", issue = "27741")] @@ -319,20 +319,8 @@ impl ops::RangeInclusive { /// ``` /// #![feature(step_by, inclusive_range_syntax)] /// - /// for i in (0...10).step_by(2) { - /// println!("{}", i); - /// } - /// ``` - /// - /// This prints: - /// - /// ```text - /// 0 - /// 2 - /// 4 - /// 6 - /// 8 - /// 10 + /// let result: Vec<_> = (0...10).step_by(2).collect(); + /// assert_eq!(result, vec![0, 2, 4, 6, 8, 10]); /// ``` #[unstable(feature = "step_by", reason = "recent addition", issue = "27741")] From ff3a761f79cc43f5465215ad1301ac1789d6e4df Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Sat, 20 Aug 2016 15:42:16 -0400 Subject: [PATCH 09/15] add more-evocative examples for `Shl` and `Shr` r? @steveklabnik add examples that lift `<<` and `>>` to a trivial struct replace `Scalar` structs with struct tuples add `fn main` wrappers to enable Rust Playground "Run" button --- src/libcore/ops.rs | 94 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 18 deletions(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 5a1993e741c60..3bf7653935661 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -852,25 +852,54 @@ bitxor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// /// # Examples /// -/// A trivial implementation of `Shl`. When `Foo << Foo` happens, it ends up -/// calling `shl`, and therefore, `main` prints `Shifting left!`. +/// An implementation of `Shl` that lifts the `<<` operation on integers to a +/// `Scalar` struct. /// /// ``` /// use std::ops::Shl; /// -/// struct Foo; +/// #[derive(PartialEq, Debug)] +/// struct Scalar(usize); /// -/// impl Shl for Foo { -/// type Output = Foo; +/// impl Shl for Scalar { +/// type Output = Self; /// -/// fn shl(self, _rhs: Foo) -> Foo { -/// println!("Shifting left!"); -/// self +/// fn shl(self, Scalar(rhs): Self) -> Scalar { +/// let Scalar(lhs) = self; +/// Scalar(lhs << rhs) +/// } +/// } +/// fn main() { +/// assert_eq!(Scalar(4) << Scalar(2), Scalar(16)); +/// } +/// ``` +/// +/// An implementation of `Shl` that spins a vector leftward by a given amount. +/// +/// ``` +/// use std::ops::Shl; +/// +/// #[derive(PartialEq, Debug)] +/// struct SpinVector { +/// vec: Vec, +/// } +/// +/// impl Shl for SpinVector { +/// type Output = Self; +/// +/// fn shl(self, rhs: usize) -> SpinVector { +/// // rotate the vector by `rhs` places +/// let (a, b) = self.vec.split_at(rhs); +/// let mut spun_vector: Vec = vec![]; +/// spun_vector.extend_from_slice(b); +/// spun_vector.extend_from_slice(a); +/// SpinVector { vec: spun_vector } /// } /// } /// /// fn main() { -/// Foo << Foo; +/// assert_eq!(SpinVector { vec: vec![0, 1, 2, 3, 4] } << 2, +/// SpinVector { vec: vec![2, 3, 4, 0, 1] }); /// } /// ``` #[lang = "shl"] @@ -924,25 +953,54 @@ shl_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize } /// /// # Examples /// -/// A trivial implementation of `Shr`. When `Foo >> Foo` happens, it ends up -/// calling `shr`, and therefore, `main` prints `Shifting right!`. +/// An implementation of `Shr` that lifts the `>>` operation on integers to a +/// `Scalar` struct. /// /// ``` /// use std::ops::Shr; /// -/// struct Foo; +/// #[derive(PartialEq, Debug)] +/// struct Scalar(usize); /// -/// impl Shr for Foo { -/// type Output = Foo; +/// impl Shr for Scalar { +/// type Output = Self; /// -/// fn shr(self, _rhs: Foo) -> Foo { -/// println!("Shifting right!"); -/// self +/// fn shr(self, Scalar(rhs): Self) -> Scalar { +/// let Scalar(lhs) = self; +/// Scalar(lhs >> rhs) +/// } +/// } +/// fn main() { +/// assert_eq!(Scalar(16) >> Scalar(2), Scalar(4)); +/// } +/// ``` +/// +/// An implementation of `Shr` that spins a vector rightward by a given amount. +/// +/// ``` +/// use std::ops::Shr; +/// +/// #[derive(PartialEq, Debug)] +/// struct SpinVector { +/// vec: Vec, +/// } +/// +/// impl Shr for SpinVector { +/// type Output = Self; +/// +/// fn shr(self, rhs: usize) -> SpinVector { +/// // rotate the vector by `rhs` places +/// let (a, b) = self.vec.split_at(self.vec.len() - rhs); +/// let mut spun_vector: Vec = vec![]; +/// spun_vector.extend_from_slice(b); +/// spun_vector.extend_from_slice(a); +/// SpinVector { vec: spun_vector } /// } /// } /// /// fn main() { -/// Foo >> Foo; +/// assert_eq!(SpinVector { vec: vec![0, 1, 2, 3, 4] } >> 2, +/// SpinVector { vec: vec![3, 4, 0, 1, 2] }); /// } /// ``` #[lang = "shr"] From 711333f6c79ee1b35cf61beb814238c5a2c3b645 Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Tue, 23 Aug 2016 17:35:35 -0400 Subject: [PATCH 10/15] add a note that whitespace alignment is nonidiomatic --- src/libcore/ops.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 8c19902d274ed..73c60d5c2069e 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -85,6 +85,9 @@ //! assert_eq!(arr[1...3], [ 1,2,3 ]); // RangeInclusive //! } //! ``` +//! +//! Note: whitespace alignment is not idiomatic Rust. An exception is made in +//! this case to facilitate comparison. #![stable(feature = "rust1", since = "1.0.0")] From bf22a7a71ab47a7d2074134b02b02df1d6ce497e Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Wed, 24 Aug 2016 15:43:28 +0200 Subject: [PATCH 11/15] Updated code sample in chapter on syntax extensions. The affected API apparently had changed with commit d59accfb065843d12db9180a4f504664e3d23ef1. --- src/doc/book/compiler-plugins.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/book/compiler-plugins.md b/src/doc/book/compiler-plugins.md index 8426d5a626549..a9a81843ab199 100644 --- a/src/doc/book/compiler-plugins.md +++ b/src/doc/book/compiler-plugins.md @@ -46,10 +46,10 @@ extern crate rustc; extern crate rustc_plugin; use syntax::parse::token; -use syntax::ast::TokenTree; +use syntax::tokenstream::TokenTree; use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager}; use syntax::ext::build::AstBuilder; // trait for expr_usize -use syntax_pos::Span; +use syntax::ext::quote::rt::Span; use rustc_plugin::Registry; fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree]) @@ -69,7 +69,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree]) } let text = match args[0] { - TokenTree::Token(_, token::Ident(s, _)) => s.to_string(), + TokenTree::Token(_, token::Ident(s)) => s.to_string(), _ => { cx.span_err(sp, "argument should be a single identifier"); return DummyResult::any(sp); From 6f93d3ce46d157b97da1b9ddbbd72f4bd40fbc2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20L=C3=B6thberg?= Date: Thu, 25 Aug 2016 01:24:49 +0200 Subject: [PATCH 12/15] Make E0094 underline better MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #35966. Signed-off-by: Johannes Löthberg --- src/librustc_typeck/check/intrinsic.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 7f9e715b7fafc..616c99a6b9bc3 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -51,12 +51,17 @@ fn equate_intrinsic_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, })); let i_n_tps = i_ty.generics.types.len(); if i_n_tps != n_tps { - struct_span_err!(tcx.sess, it.span, E0094, - "intrinsic has wrong number of type \ - parameters: found {}, expected {}", - i_n_tps, n_tps) - .span_label(it.span, &format!("expected {} type parameter", n_tps)) - .emit(); + let span = match it.node { + hir::ForeignItemFn(_, ref generics) => generics.span().unwrap_or(it.span), + hir::ForeignItemStatic(_, _) => it.span + }; + + struct_span_err!(tcx.sess, span, E0094, + "intrinsic has wrong number of type \ + parameters: found {}, expected {}", + i_n_tps, n_tps) + .span_label(span, &format!("expected {} type parameter", n_tps)) + .emit(); } else { require_same_types(ccx, TypeOrigin::IntrinsicType(it.span), From 874a20d01d1c075b3f9a9c60562d78761ed08bc4 Mon Sep 17 00:00:00 2001 From: Mohit Agarwal Date: Thu, 25 Aug 2016 18:26:04 +0530 Subject: [PATCH 13/15] Update E0277 to new error format Fixes #35311. Part of #35233. r? @jonathandturner --- src/librustc/traits/error_reporting.rs | 5 +++-- src/test/compile-fail/E0277.rs | 5 ++++- .../associated-types-ICE-when-projecting-out-of-err.rs | 3 ++- src/test/compile-fail/cast-rfc0401.rs | 2 ++ src/test/compile-fail/const-unsized.rs | 4 ++++ src/test/compile-fail/impl-trait/auto-trait-leak.rs | 4 ++++ src/test/compile-fail/on-unimplemented/multiple-impls.rs | 3 +++ src/test/compile-fail/on-unimplemented/on-impl.rs | 1 + src/test/compile-fail/on-unimplemented/on-trait.rs | 2 ++ src/test/compile-fail/on-unimplemented/slice-index.rs | 2 ++ src/test/compile-fail/trait-suggest-where-clause.rs | 7 +++++++ 11 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index d6f263fcebeb0..adffc38b0befa 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -477,10 +477,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { return; } - let mut err = struct_span_err!( - self.tcx.sess, span, E0277, + let mut err = struct_span_err!(self.tcx.sess, span, E0277, "the trait bound `{}` is not satisfied", trait_ref.to_predicate()); + err.span_label(span, &format!("trait `{}` not satisfied", + trait_ref.to_predicate())); // Try to report a help message diff --git a/src/test/compile-fail/E0277.rs b/src/test/compile-fail/E0277.rs index 7737f12ac3714..12f9417f944cd 100644 --- a/src/test/compile-fail/E0277.rs +++ b/src/test/compile-fail/E0277.rs @@ -17,5 +17,8 @@ fn some_func(foo: T) { } fn main() { - some_func(5i32); //~ ERROR E0277 + some_func(5i32); + //~^ ERROR the trait bound `i32: Foo` is not satisfied + //~| NOTE trait `i32: Foo` not satisfied + //~| NOTE required by `some_func` } diff --git a/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs b/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs index 48bfa84fa8666..084616964674f 100644 --- a/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs +++ b/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs @@ -31,5 +31,6 @@ trait Add { fn ice(a: A) { let r = loop {}; r = r + a; - //~^ ERROR E0277 + //~^ ERROR the trait bound `(): Add` is not satisfied + //~| NOTE trait `(): Add` not satisfied } diff --git a/src/test/compile-fail/cast-rfc0401.rs b/src/test/compile-fail/cast-rfc0401.rs index 7839fb45d1c34..b6e81504a9d24 100644 --- a/src/test/compile-fail/cast-rfc0401.rs +++ b/src/test/compile-fail/cast-rfc0401.rs @@ -92,6 +92,7 @@ fn main() let _ = v as *const [u8]; //~ ERROR cannot cast let _ = fat_v as *const Foo; //~^ ERROR the trait bound `[u8]: std::marker::Sized` is not satisfied + //~| NOTE trait `[u8]: std::marker::Sized` not satisfied //~| NOTE `[u8]` does not have a constant size known at compile-time //~| NOTE required for the cast to the object type `Foo` let _ = foo as *const str; //~ ERROR casting @@ -106,6 +107,7 @@ fn main() let a : *const str = "hello"; let _ = a as *const Foo; //~^ ERROR the trait bound `str: std::marker::Sized` is not satisfied + //~| NOTE trait `str: std::marker::Sized` not satisfied //~| NOTE `str` does not have a constant size known at compile-time //~| NOTE required for the cast to the object type `Foo` diff --git a/src/test/compile-fail/const-unsized.rs b/src/test/compile-fail/const-unsized.rs index 72a5c5fff6084..a73164b957c83 100644 --- a/src/test/compile-fail/const-unsized.rs +++ b/src/test/compile-fail/const-unsized.rs @@ -12,21 +12,25 @@ use std::fmt::Debug; const CONST_0: Debug+Sync = *(&0 as &(Debug+Sync)); //~^ ERROR `std::fmt::Debug + Sync + 'static: std::marker::Sized` is not satisfied +//~| NOTE `std::fmt::Debug + Sync + 'static: std::marker::Sized` not satisfied //~| NOTE does not have a constant size known at compile-time //~| NOTE constant expressions must have a statically known size const CONST_FOO: str = *"foo"; //~^ ERROR `str: std::marker::Sized` is not satisfied +//~| NOTE `str: std::marker::Sized` not satisfied //~| NOTE does not have a constant size known at compile-time //~| NOTE constant expressions must have a statically known size static STATIC_1: Debug+Sync = *(&1 as &(Debug+Sync)); //~^ ERROR `std::fmt::Debug + Sync + 'static: std::marker::Sized` is not satisfied +//~| NOTE `std::fmt::Debug + Sync + 'static: std::marker::Sized` not satisfied //~| NOTE does not have a constant size known at compile-time //~| NOTE constant expressions must have a statically known size static STATIC_BAR: str = *"bar"; //~^ ERROR `str: std::marker::Sized` is not satisfied +//~| NOTE `str: std::marker::Sized` not satisfied //~| NOTE does not have a constant size known at compile-time //~| NOTE constant expressions must have a statically known size diff --git a/src/test/compile-fail/impl-trait/auto-trait-leak.rs b/src/test/compile-fail/impl-trait/auto-trait-leak.rs index 2c78ce2db29af..60ad266e7f7da 100644 --- a/src/test/compile-fail/impl-trait/auto-trait-leak.rs +++ b/src/test/compile-fail/impl-trait/auto-trait-leak.rs @@ -26,6 +26,7 @@ fn send(_: T) {} fn main() { send(before()); //~^ ERROR the trait bound `std::rc::Rc>: std::marker::Send` is not satisfied + //~| NOTE trait `std::rc::Rc>: std::marker::Send` not satisfied //~| NOTE `std::rc::Rc>` cannot be sent between threads safely //~| NOTE required because it appears within the type `[closure //~| NOTE required because it appears within the type `impl std::ops::Fn<(i32,)>` @@ -33,6 +34,7 @@ fn main() { send(after()); //~^ ERROR the trait bound `std::rc::Rc>: std::marker::Send` is not satisfied + //~| NOTE trait `std::rc::Rc>: std::marker::Send` not satisfied //~| NOTE `std::rc::Rc>` cannot be sent between threads safely //~| NOTE required because it appears within the type `[closure //~| NOTE required because it appears within the type `impl std::ops::Fn<(i32,)>` @@ -52,6 +54,7 @@ fn after() -> impl Fn(i32) { fn cycle1() -> impl Clone { send(cycle2().clone()); //~^ ERROR the trait bound `std::rc::Rc: std::marker::Send` is not satisfied + //~| NOTE trait `std::rc::Rc: std::marker::Send` not satisfied //~| NOTE `std::rc::Rc` cannot be sent between threads safely //~| NOTE required because it appears within the type `impl std::clone::Clone` //~| NOTE required by `send` @@ -62,6 +65,7 @@ fn cycle1() -> impl Clone { fn cycle2() -> impl Clone { send(cycle1().clone()); //~^ ERROR the trait bound `std::rc::Rc>: std::marker::Send` is not satisfied + //~| NOTE trait `std::rc::Rc>: std::marker::Send` not satisfied //~| NOTE `std::rc::Rc>` cannot be sent between threads safely //~| NOTE required because it appears within the type `impl std::clone::Clone` //~| NOTE required by `send` diff --git a/src/test/compile-fail/on-unimplemented/multiple-impls.rs b/src/test/compile-fail/on-unimplemented/multiple-impls.rs index 0df8c41ffe1a8..cc7c2f4f796d9 100644 --- a/src/test/compile-fail/on-unimplemented/multiple-impls.rs +++ b/src/test/compile-fail/on-unimplemented/multiple-impls.rs @@ -42,14 +42,17 @@ impl Index> for [i32] { fn main() { Index::index(&[] as &[i32], 2u32); //~^ ERROR E0277 + //~| NOTE not satisfied //~| NOTE trait message //~| NOTE required by Index::index(&[] as &[i32], Foo(2u32)); //~^ ERROR E0277 + //~| NOTE not satisfied //~| NOTE on impl for Foo //~| NOTE required by Index::index(&[] as &[i32], Bar(2u32)); //~^ ERROR E0277 + //~| NOTE not satisfied //~| NOTE on impl for Bar //~| NOTE required by } diff --git a/src/test/compile-fail/on-unimplemented/on-impl.rs b/src/test/compile-fail/on-unimplemented/on-impl.rs index 4471b625d7912..c22e48bede4ef 100644 --- a/src/test/compile-fail/on-unimplemented/on-impl.rs +++ b/src/test/compile-fail/on-unimplemented/on-impl.rs @@ -30,6 +30,7 @@ impl Index for [i32] { #[rustc_error] fn main() { Index::::index(&[1, 2, 3] as &[i32], 2u32); //~ ERROR E0277 + //~| NOTE not satisfied //~| NOTE a usize is required //~| NOTE required by } diff --git a/src/test/compile-fail/on-unimplemented/on-trait.rs b/src/test/compile-fail/on-unimplemented/on-trait.rs index 39ce1b33ca131..9ea2809374cd8 100644 --- a/src/test/compile-fail/on-unimplemented/on-trait.rs +++ b/src/test/compile-fail/on-unimplemented/on-trait.rs @@ -35,7 +35,9 @@ pub fn main() { //~^ ERROR //~^^ NOTE a collection of type `std::option::Option>` cannot be built from an iterator over elements of type `&u8` //~^^^ NOTE required by `collect` + //~| NOTE trait `std::option::Option>: MyFromIterator<&u8>` not satisfied let x: String = foobar(); //~ ERROR //~^ NOTE test error `std::string::String` with `u8` `_` `u32` //~^^ NOTE required by `foobar` + //~| NOTE trait `std::string::String: Foo` not satisfied } diff --git a/src/test/compile-fail/on-unimplemented/slice-index.rs b/src/test/compile-fail/on-unimplemented/slice-index.rs index 6a8f9d471e169..5c548b5d5bf20 100644 --- a/src/test/compile-fail/on-unimplemented/slice-index.rs +++ b/src/test/compile-fail/on-unimplemented/slice-index.rs @@ -18,7 +18,9 @@ use std::ops::Index; fn main() { let x = &[1, 2, 3] as &[i32]; x[1i32]; //~ ERROR E0277 + //~| NOTE trait `[i32]: std::ops::Index` not satisfied //~| NOTE slice indices are of type `usize` x[..1i32]; //~ ERROR E0277 + //~| NOTE trait `[i32]: std::ops::Index>` not satisfied //~| NOTE slice indices are of type `usize` } diff --git a/src/test/compile-fail/trait-suggest-where-clause.rs b/src/test/compile-fail/trait-suggest-where-clause.rs index a8ff1bae7a71a..d15e3536d60ca 100644 --- a/src/test/compile-fail/trait-suggest-where-clause.rs +++ b/src/test/compile-fail/trait-suggest-where-clause.rs @@ -16,11 +16,13 @@ fn check() { // suggest a where-clause, if needed mem::size_of::(); //~^ ERROR `U: std::marker::Sized` is not satisfied + //~| NOTE trait `U: std::marker::Sized` not satisfied //~| HELP consider adding a `where U: std::marker::Sized` bound //~| NOTE required by `std::mem::size_of` mem::size_of::>(); //~^ ERROR `U: std::marker::Sized` is not satisfied + //~| NOTE trait `U: std::marker::Sized` not satisfied //~| HELP consider adding a `where U: std::marker::Sized` bound //~| NOTE required because it appears within the type `Misc` //~| NOTE required by `std::mem::size_of` @@ -29,11 +31,13 @@ fn check() { >::from; //~^ ERROR `u64: std::convert::From` is not satisfied + //~| NOTE trait `u64: std::convert::From` not satisfied //~| HELP consider adding a `where u64: std::convert::From` bound //~| NOTE required by `std::convert::From::from` ::Item>>::from; //~^ ERROR `u64: std::convert::From<::Item>` is not satisfied + //~| NOTE trait `u64: std::convert::From<::Item>` not satisfied //~| HELP consider adding a `where u64: //~| NOTE required by `std::convert::From::from` @@ -41,17 +45,20 @@ fn check() { as From>::from; //~^ ERROR `Misc<_>: std::convert::From` is not satisfied + //~| NOTE trait `Misc<_>: std::convert::From` not satisfied //~| NOTE required by `std::convert::From::from` // ... and also not if the error is not related to the type mem::size_of::<[T]>(); //~^ ERROR `[T]: std::marker::Sized` is not satisfied + //~| NOTE `[T]: std::marker::Sized` not satisfied //~| NOTE `[T]` does not have a constant size //~| NOTE required by `std::mem::size_of` mem::size_of::<[&U]>(); //~^ ERROR `[&U]: std::marker::Sized` is not satisfied + //~| NOTE `[&U]: std::marker::Sized` not satisfied //~| NOTE `[&U]` does not have a constant size //~| NOTE required by `std::mem::size_of` } From 905644de5db7f73fab275345795562330d007315 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Wed, 24 Aug 2016 02:20:51 -0400 Subject: [PATCH 14/15] Rename {uint,int} methods to {usize,isize}. --- src/librbml/lib.rs | 8 ++++---- src/librbml/opaque.rs | 26 +++++++++++++------------- src/libserialize/collection_impls.rs | 4 ++-- src/libserialize/json.rs | 12 ++++++------ src/libserialize/serialize.rs | 16 ++++++++-------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index 4edbeab5dfb11..adbdc9af9cc8d 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -726,7 +726,7 @@ pub mod reader { fn read_u8(&mut self) -> DecodeResult { Ok(doc_as_u8(self.next_doc(EsU8)?)) } - fn read_uint(&mut self) -> DecodeResult { + fn read_usize(&mut self) -> DecodeResult { let v = self._next_int(EsU8, EsU64)?; if v > (::std::usize::MAX as u64) { Err(IntTooBig(v as usize)) @@ -747,7 +747,7 @@ pub mod reader { fn read_i8(&mut self) -> DecodeResult { Ok(doc_as_u8(self.next_doc(EsI8)?) as i8) } - fn read_int(&mut self) -> DecodeResult { + fn read_isize(&mut self) -> DecodeResult { let v = self._next_int(EsI8, EsI64)? as i64; if v > (isize::MAX as i64) || v < (isize::MIN as i64) { debug!("FIXME \\#6122: Removing this makes this function miscompile"); @@ -1219,7 +1219,7 @@ pub mod writer { Ok(()) } - fn emit_uint(&mut self, v: usize) -> EncodeResult { + fn emit_usize(&mut self, v: usize) -> EncodeResult { self.emit_u64(v as u64) } fn emit_u64(&mut self, v: u64) -> EncodeResult { @@ -1247,7 +1247,7 @@ pub mod writer { self.wr_tagged_raw_u8(EsU8 as usize, v) } - fn emit_int(&mut self, v: isize) -> EncodeResult { + fn emit_isize(&mut self, v: isize) -> EncodeResult { self.emit_i64(v as i64) } fn emit_i64(&mut self, v: i64) -> EncodeResult { diff --git a/src/librbml/opaque.rs b/src/librbml/opaque.rs index 10f419d169181..6dc7a72b1b1bb 100644 --- a/src/librbml/opaque.rs +++ b/src/librbml/opaque.rs @@ -54,7 +54,7 @@ impl<'a> serialize::Encoder for Encoder<'a> { Ok(()) } - fn emit_uint(&mut self, v: usize) -> EncodeResult { + fn emit_usize(&mut self, v: usize) -> EncodeResult { write_uleb128!(self, v) } @@ -75,7 +75,7 @@ impl<'a> serialize::Encoder for Encoder<'a> { Ok(()) } - fn emit_int(&mut self, v: isize) -> EncodeResult { + fn emit_isize(&mut self, v: isize) -> EncodeResult { write_sleb128!(self, v) } @@ -120,7 +120,7 @@ impl<'a> serialize::Encoder for Encoder<'a> { } fn emit_str(&mut self, v: &str) -> EncodeResult { - self.emit_uint(v.len())?; + self.emit_usize(v.len())?; let _ = self.cursor.write_all(v.as_bytes()); Ok(()) } @@ -139,7 +139,7 @@ impl<'a> serialize::Encoder for Encoder<'a> { -> EncodeResult where F: FnOnce(&mut Self) -> EncodeResult { - self.emit_uint(v_id)?; + self.emit_usize(v_id)?; f(self) } @@ -221,7 +221,7 @@ impl<'a> serialize::Encoder for Encoder<'a> { fn emit_seq(&mut self, len: usize, f: F) -> EncodeResult where F: FnOnce(&mut Encoder<'a>) -> EncodeResult { - self.emit_uint(len)?; + self.emit_usize(len)?; f(self) } @@ -234,7 +234,7 @@ impl<'a> serialize::Encoder for Encoder<'a> { fn emit_map(&mut self, len: usize, f: F) -> EncodeResult where F: FnOnce(&mut Encoder<'a>) -> EncodeResult { - self.emit_uint(len)?; + self.emit_usize(len)?; f(self) } @@ -329,7 +329,7 @@ impl<'a> serialize::Decoder for Decoder<'a> { Ok(value) } - fn read_uint(&mut self) -> Result { + fn read_usize(&mut self) -> Result { read_uleb128!(self, usize) } @@ -351,7 +351,7 @@ impl<'a> serialize::Decoder for Decoder<'a> { unsafe { Ok(::std::mem::transmute(as_u8)) } } - fn read_int(&mut self) -> Result { + fn read_isize(&mut self) -> Result { read_sleb128!(self, isize) } @@ -376,7 +376,7 @@ impl<'a> serialize::Decoder for Decoder<'a> { } fn read_str(&mut self) -> Result { - let len = self.read_uint()?; + let len = self.read_usize()?; let s = ::std::str::from_utf8(&self.data[self.position..self.position + len]).unwrap(); self.position += len; Ok(s.to_string()) @@ -391,7 +391,7 @@ impl<'a> serialize::Decoder for Decoder<'a> { fn read_enum_variant(&mut self, _: &[&str], mut f: F) -> Result where F: FnMut(&mut Decoder<'a>, usize) -> Result { - let disr = self.read_uint()?; + let disr = self.read_usize()?; f(self, disr) } @@ -404,7 +404,7 @@ impl<'a> serialize::Decoder for Decoder<'a> { fn read_enum_struct_variant(&mut self, _: &[&str], mut f: F) -> Result where F: FnMut(&mut Decoder<'a>, usize) -> Result { - let disr = self.read_uint()?; + let disr = self.read_usize()?; f(self, disr) } @@ -483,7 +483,7 @@ impl<'a> serialize::Decoder for Decoder<'a> { fn read_seq(&mut self, f: F) -> Result where F: FnOnce(&mut Decoder<'a>, usize) -> Result { - let len = self.read_uint()?; + let len = self.read_usize()?; f(self, len) } @@ -496,7 +496,7 @@ impl<'a> serialize::Decoder for Decoder<'a> { fn read_map(&mut self, f: F) -> Result where F: FnOnce(&mut Decoder<'a>, usize) -> Result { - let len = self.read_uint()?; + let len = self.read_usize()?; f(self, len) } diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs index 5d652ba2f55bb..7b5092e8848e4 100644 --- a/src/libserialize/collection_impls.rs +++ b/src/libserialize/collection_impls.rs @@ -136,7 +136,7 @@ impl< for item in self { bits |= item.to_usize(); } - s.emit_uint(bits) + s.emit_usize(bits) } } @@ -144,7 +144,7 @@ impl< T: Decodable + CLike > Decodable for EnumSet { fn decode(d: &mut D) -> Result, D::Error> { - let bits = d.read_uint()?; + let bits = d.read_usize()?; let mut set = EnumSet::new(); for bit in 0..(mem::size_of::()*8) { if bits & (1 << bit) != 0 { diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 6c4b6c4506b81..34df594e84756 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -495,13 +495,13 @@ impl<'a> ::Encoder for Encoder<'a> { Ok(()) } - fn emit_uint(&mut self, v: usize) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } + fn emit_usize(&mut self, v: usize) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_u64(&mut self, v: u64) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_u32(&mut self, v: u32) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_u16(&mut self, v: u16) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_u8(&mut self, v: u8) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } - fn emit_int(&mut self, v: isize) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } + fn emit_isize(&mut self, v: isize) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_i64(&mut self, v: i64) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_i32(&mut self, v: i32) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_i16(&mut self, v: i16) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } @@ -743,13 +743,13 @@ impl<'a> ::Encoder for PrettyEncoder<'a> { Ok(()) } - fn emit_uint(&mut self, v: usize) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } + fn emit_usize(&mut self, v: usize) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_u64(&mut self, v: u64) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_u32(&mut self, v: u32) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_u16(&mut self, v: u16) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_u8(&mut self, v: u8) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } - fn emit_int(&mut self, v: isize) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } + fn emit_isize(&mut self, v: isize) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_i64(&mut self, v: i64) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_i32(&mut self, v: i32) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } fn emit_i16(&mut self, v: i16) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) } @@ -2137,12 +2137,12 @@ impl ::Decoder for Decoder { expect!(self.pop(), Null) } - read_primitive! { read_uint, usize } + read_primitive! { read_usize, usize } read_primitive! { read_u8, u8 } read_primitive! { read_u16, u16 } read_primitive! { read_u32, u32 } read_primitive! { read_u64, u64 } - read_primitive! { read_int, isize } + read_primitive! { read_isize, isize } read_primitive! { read_i8, i8 } read_primitive! { read_i16, i16 } read_primitive! { read_i32, i32 } diff --git a/src/libserialize/serialize.rs b/src/libserialize/serialize.rs index 0fcab1347d160..b75ec5dad8ddd 100644 --- a/src/libserialize/serialize.rs +++ b/src/libserialize/serialize.rs @@ -24,12 +24,12 @@ pub trait Encoder { // Primitive types: fn emit_nil(&mut self) -> Result<(), Self::Error>; - fn emit_uint(&mut self, v: usize) -> Result<(), Self::Error>; + fn emit_usize(&mut self, v: usize) -> Result<(), Self::Error>; fn emit_u64(&mut self, v: u64) -> Result<(), Self::Error>; fn emit_u32(&mut self, v: u32) -> Result<(), Self::Error>; fn emit_u16(&mut self, v: u16) -> Result<(), Self::Error>; fn emit_u8(&mut self, v: u8) -> Result<(), Self::Error>; - fn emit_int(&mut self, v: isize) -> Result<(), Self::Error>; + fn emit_isize(&mut self, v: isize) -> Result<(), Self::Error>; fn emit_i64(&mut self, v: i64) -> Result<(), Self::Error>; fn emit_i32(&mut self, v: i32) -> Result<(), Self::Error>; fn emit_i16(&mut self, v: i16) -> Result<(), Self::Error>; @@ -108,12 +108,12 @@ pub trait Decoder { // Primitive types: fn read_nil(&mut self) -> Result<(), Self::Error>; - fn read_uint(&mut self) -> Result; + fn read_usize(&mut self) -> Result; fn read_u64(&mut self) -> Result; fn read_u32(&mut self) -> Result; fn read_u16(&mut self) -> Result; fn read_u8(&mut self) -> Result; - fn read_int(&mut self) -> Result; + fn read_isize(&mut self) -> Result; fn read_i64(&mut self) -> Result; fn read_i32(&mut self) -> Result; fn read_i16(&mut self) -> Result; @@ -200,13 +200,13 @@ pub trait Decodable: Sized { impl Encodable for usize { fn encode(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_uint(*self) + s.emit_usize(*self) } } impl Decodable for usize { fn decode(d: &mut D) -> Result { - d.read_uint() + d.read_usize() } } @@ -260,13 +260,13 @@ impl Decodable for u64 { impl Encodable for isize { fn encode(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_int(*self) + s.emit_isize(*self) } } impl Decodable for isize { fn decode(d: &mut D) -> Result { - d.read_int() + d.read_isize() } } From e4871c4b6ff66296219ff4d07f65e9a59eb4220c Mon Sep 17 00:00:00 2001 From: Mohit Agarwal Date: Thu, 25 Aug 2016 19:09:48 +0530 Subject: [PATCH 15/15] Update E0453 to new error format Fixes #35929. Part of #35233. r? @jonathandturner --- src/librustc/lint/context.rs | 5 +++-- src/test/compile-fail/E0453.rs | 5 ++++- src/test/compile-fail/lint-forbid-attr.rs | 6 ++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index daac315e14def..9c06f0cca1566 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -606,11 +606,12 @@ pub trait LintContext: Sized { "{}({}) overruled by outer forbid({})", level.as_str(), lint_name, lint_name); + diag_builder.span_label(span, &format!("overruled by previous forbid")); match now_source { LintSource::Default => &mut diag_builder, LintSource::Node(forbid_source_span) => { - diag_builder.span_note(forbid_source_span, - "`forbid` lint level set here") + diag_builder.span_label(forbid_source_span, + &format!("`forbid` level set here")) }, LintSource::CommandLine => { diag_builder.note("`forbid` lint level was set on command line") diff --git a/src/test/compile-fail/E0453.rs b/src/test/compile-fail/E0453.rs index 629b373cd7f12..6fed3dca94ef1 100644 --- a/src/test/compile-fail/E0453.rs +++ b/src/test/compile-fail/E0453.rs @@ -9,7 +9,10 @@ // except according to those terms. #![forbid(non_snake_case)] +//~^ NOTE `forbid` level set here -#[allow(non_snake_case)] //~ ERROR E0453 +#[allow(non_snake_case)] +//~^ ERROR allow(non_snake_case) overruled by outer forbid(non_snake_case) +//~| NOTE overruled by previous forbid fn main() { } diff --git a/src/test/compile-fail/lint-forbid-attr.rs b/src/test/compile-fail/lint-forbid-attr.rs index fd2513c5a066d..a23083b5c8c11 100644 --- a/src/test/compile-fail/lint-forbid-attr.rs +++ b/src/test/compile-fail/lint-forbid-attr.rs @@ -9,8 +9,10 @@ // except according to those terms. #![forbid(deprecated)] -//~^ NOTE `forbid` lint level set here +//~^ NOTE `forbid` level set here -#[allow(deprecated)] //~ ERROR allow(deprecated) overruled by outer forbid(deprecated) +#[allow(deprecated)] +//~^ ERROR allow(deprecated) overruled by outer forbid(deprecated) +//~| NOTE overruled by previous forbid fn main() { }