From 377ae44cf276599a5b7a21e545d83372067db754 Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Mon, 15 Aug 2016 18:46:19 -0400 Subject: [PATCH 01/24] explicitly show how iterating over `..` fails I've also removed the `main()` wrapper, which I believe is extraneous. LMK if that's incorrect. --- src/libcore/ops.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 9347ac2a8c82f..558b78a2fbfaa 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -1463,15 +1463,17 @@ pub trait IndexMut: Index { /// # Examples /// /// ``` -/// fn main() { -/// assert_eq!((..), std::ops::RangeFull); +/// assert_eq!((..), std::ops::RangeFull); /// -/// 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 ]); -/// } +/// // for i in .. { +/// // println!("This errors because .. has no Iterator impl"); +/// // } +/// +/// 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 ]); /// ``` #[derive(Copy, Clone, PartialEq, Eq, Hash)] #[stable(feature = "rust1", since = "1.0.0")] From c186da706dda6ddaa4df20691702249c4ef0d2dc Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Tue, 16 Aug 2016 06:54:45 -0400 Subject: [PATCH 02/24] RangeFull for-loop iteration fails because of IntoIterator Saying that "[for-loop iteration] fails because .. has no IntoIterator impl" is more direct than saying "...no Iterator impl" because for loops sugar into IntoIterator invocations. It just happens that the other Range* operators implement Iterator and rely on the fact that `IntoIterator` is implemented for `T: Iterator`. --- src/libcore/ops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 558b78a2fbfaa..cee374ccc7bc5 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -1466,7 +1466,7 @@ pub trait IndexMut: Index { /// assert_eq!((..), std::ops::RangeFull); /// /// // for i in .. { -/// // println!("This errors because .. has no Iterator impl"); +/// // println!("This errors because .. has no IntoIterator impl"); /// // } /// /// let arr = [0, 1, 2, 3]; From dcee93a8030c3a62c5a05b45b050f90251d93af8 Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Tue, 16 Aug 2016 04:11:48 -0400 Subject: [PATCH 03/24] replace Add example with something more evocative of addition Currently most of the operator traits use trivial implementation examples that only perform side effects. Honestly, that might not be too bad for the sake of documentation; but anyway, here's a proposal to move a slightly modified version of the module-level point-addition example into the `Add` documentation, since it's more evocative of addition semantics. Part of #29365 wrap identifiers in backticks minor rephrasing fix module-level documentation to be more truthful This branch changes the example for `Add` to no longer be a "minimum implementation that prints something to the screen". --- src/libcore/ops.rs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 9347ac2a8c82f..9e6310ed460d2 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -62,8 +62,7 @@ //! } //! ``` //! -//! See the documentation for each trait for a minimum implementation that -//! prints something to the screen. +//! See the documentation for each trait for an example implementation. #![stable(feature = "rust1", since = "1.0.0")] @@ -166,25 +165,38 @@ macro_rules! forward_ref_binop { /// /// # Examples /// -/// A trivial implementation of `Add`. When `Foo + Foo` happens, it ends up -/// calling `add`, and therefore, `main` prints `Adding!`. +/// This example creates a `Point` struct that implements the `Add` trait, and +/// then demonstrates adding two `Point`s. /// /// ``` /// use std::ops::Add; /// -/// struct Foo; +/// #[derive(Debug)] +/// struct Point { +/// x: i32, +/// y: i32, +/// } /// -/// impl Add for Foo { -/// type Output = Foo; +/// impl Add for Point { +/// type Output = Point; /// -/// fn add(self, _rhs: Foo) -> Foo { -/// println!("Adding!"); -/// self +/// fn add(self, other: Point) -> Point { +/// Point { +/// x: self.x + other.x, +/// y: self.y + other.y, +/// } +/// } +/// } +/// +/// impl PartialEq for Point { +/// fn eq(&self, other: &Self) -> bool { +/// self.x == other.x && self.y == other.y /// } /// } /// /// fn main() { -/// Foo + Foo; +/// assert_eq!(Point { x: 1, y: 0 } + Point { x: 2, y: 3 }, +/// Point { x: 3, y: 3 }); /// } /// ``` #[lang = "add"] From da1f7731f6cebcf8b8a896c65b38e19b102e19c4 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 3 Aug 2016 12:55:01 +1200 Subject: [PATCH 04/24] rustdoc: remove the `!` from macro URLs and titles --- src/librustdoc/clean/mod.rs | 8 +++++--- src/test/rustdoc/issue-26606.rs | 2 +- src/test/rustdoc/macros.rs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 75d21399f05e6..39b1a04e98e69 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2803,7 +2803,7 @@ pub struct Macro { impl Clean for doctree::Macro { fn clean(&self, cx: &DocContext) -> Item { - let name = format!("{}!", self.name.clean(cx)); + let name = self.name.clean(cx); Item { name: Some(name.clone()), attrs: self.attrs.clean(cx), @@ -2814,8 +2814,10 @@ impl Clean for doctree::Macro { def_id: cx.map.local_def_id(self.id), inner: MacroItem(Macro { source: format!("macro_rules! {} {{\n{}}}", - name.trim_right_matches('!'), self.matchers.iter().map(|span| - format!(" {} => {{ ... }};\n", span.to_src(cx))).collect::()), + name, + self.matchers.iter().map(|span| { + format!(" {} => {{ ... }};\n", span.to_src(cx)) + }).collect::()), imported_from: self.imported_from.clean(cx), }), } diff --git a/src/test/rustdoc/issue-26606.rs b/src/test/rustdoc/issue-26606.rs index df40c01686dcc..12de76654512d 100644 --- a/src/test/rustdoc/issue-26606.rs +++ b/src/test/rustdoc/issue-26606.rs @@ -12,7 +12,7 @@ // ignore-cross-compile // build-aux-docs -// @has issue_26606_macro/macro.make_item!.html +// @has issue_26606_macro/macro.make_item.html #[macro_use] extern crate issue_26606_macro; diff --git a/src/test/rustdoc/macros.rs b/src/test/rustdoc/macros.rs index b052ad2da2fa9..f4115d8229a54 100644 --- a/src/test/rustdoc/macros.rs +++ b/src/test/rustdoc/macros.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// @has macros/macro.my_macro!.html //pre 'macro_rules! my_macro {' +// @has macros/macro.my_macro.html //pre 'macro_rules! my_macro {' // @has - //pre '() => { ... };' // @has - //pre '($a:tt) => { ... };' // @has - //pre '($e:expr) => { ... };' From e6cc4c5d13f8819c72568f9675e84c1d17368c67 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Tue, 16 Aug 2016 10:36:39 +1200 Subject: [PATCH 05/24] Fix links --- src/doc/book/error-handling.md | 8 ++++---- src/libcollections/fmt.rs | 2 +- src/libstd/io/mod.rs | 6 +++--- src/libstd/lib.rs | 2 +- src/libstd/primitive_docs.rs | 2 +- src/tools/linkchecker/Cargo.lock | 6 ++++++ 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/doc/book/error-handling.md b/src/doc/book/error-handling.md index 6e13b464e4c25..a62e1b7dfa9c5 100644 --- a/src/doc/book/error-handling.md +++ b/src/doc/book/error-handling.md @@ -59,7 +59,7 @@ handling is reducing the amount of explicit case analysis the programmer has to do while keeping code composable. Keeping code composable is important, because without that requirement, we -could [`panic`](../std/macro.panic!.html) whenever we +could [`panic`](../std/macro.panic.html) whenever we come across something unexpected. (`panic` causes the current task to unwind, and in most cases, the entire program aborts.) Here's an example: @@ -944,7 +944,7 @@ macro_rules! try { } ``` -(The [real definition](../std/macro.try!.html) is a bit more +(The [real definition](../std/macro.try.html) is a bit more sophisticated. We will address that later.) Using the `try!` macro makes it very easy to simplify our last example. Since @@ -1271,7 +1271,7 @@ macro_rules! try { ``` This is not its real definition. Its real definition is -[in the standard library](../std/macro.try!.html): +[in the standard library](../std/macro.try.html): @@ -2178,7 +2178,7 @@ heuristics! [`From`](../std/convert/trait.From.html) and [`Error`](../std/error/trait.Error.html) - impls to make the [`try!`](../std/macro.try!.html) + impls to make the [`try!`](../std/macro.try.html) macro more ergonomic. * If you're writing a library and your code can produce errors, define your own error type and implement the diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index be0ef85d6b114..b7cbfb60ec4e9 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -530,7 +530,7 @@ use string; /// assert_eq!(s, "Hello, world!"); /// ``` /// -/// [format!]: ../macro.format!.html +/// [format!]: ../macro.format.html #[stable(feature = "rust1", since = "1.0.0")] pub fn format(args: Arguments) -> string::String { let mut output = string::String::new(); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 88fd4186e0a2a..307d014fd68c6 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -236,7 +236,7 @@ //! to read the line and print it, so we use `()`. //! //! [result]: type.Result.html -//! [try]: ../macro.try!.html +//! [try]: ../macro.try.html //! //! ## Platform-specific behavior //! @@ -957,8 +957,8 @@ pub trait Write { /// explicitly be called. The [`write!`][write] macro should be favored to /// invoke this method instead. /// - /// [formatargs]: ../macro.format_args!.html - /// [write]: ../macro.write!.html + /// [formatargs]: ../macro.format_args.html + /// [write]: ../macro.write.html /// /// This function internally uses the [`write_all`][writeall] method on /// this trait and hence will continuously write data so long as no errors diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index c05e0c3ca68df..ff3b9c6d04163 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -175,7 +175,7 @@ //! [`atomic`]: sync/atomic/index.html //! [`collections`]: collections/index.html //! [`for`]: ../book/loops.html#for -//! [`format!`]: macro.format!.html +//! [`format!`]: macro.format.html //! [`fs`]: fs/index.html //! [`io`]: io/index.html //! [`iter`]: iter/index.html diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index d31a593037622..2b92da6c684a4 100644 --- a/src/libstd/primitive_docs.rs +++ b/src/libstd/primitive_docs.rs @@ -27,7 +27,7 @@ /// assert!(!bool_val); /// ``` /// -/// [`assert!`]: macro.assert!.html +/// [`assert!`]: macro.assert.html /// [`if`]: ../book/if.html /// [`BitAnd`]: ops/trait.BitAnd.html /// [`BitOr`]: ops/trait.BitOr.html diff --git a/src/tools/linkchecker/Cargo.lock b/src/tools/linkchecker/Cargo.lock index ed5fe081ffb2e..d71df6d3f83a8 100644 --- a/src/tools/linkchecker/Cargo.lock +++ b/src/tools/linkchecker/Cargo.lock @@ -42,3 +42,9 @@ dependencies = [ "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[metadata] +"checksum idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1053236e00ce4f668aeca4a769a09b3bf5a682d802abd6f3cb39374f6b162c11" +"checksum matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "15305656809ce5a4805b1ff2946892810992197ce1270ff79baded852187942e" +"checksum unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c1f7ceb96afdfeedee42bade65a0d585a6a0106f681b6749c8ff4daa8df30b3f" +"checksum unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "26643a2f83bac55f1976fb716c10234485f9202dcd65cfbdf9da49867b271172" +"checksum url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afe9ec54bc4db14bc8744b7fed060d785ac756791450959b2248443319d5b119" From 0dc13ee7f23f878e626771c1a3925b37b19fd6e4 Mon Sep 17 00:00:00 2001 From: clementmiao Date: Wed, 17 Aug 2016 22:03:52 -0700 Subject: [PATCH 06/24] updated E0395 to new error format --- src/librustc_mir/transform/qualify_consts.rs | 11 ++++++++--- src/test/compile-fail/E0395.rs | 2 +- src/test/compile-fail/issue-25826.rs | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 103a15dadb61c..a9ef702ee0548 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -678,9 +678,14 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { self.add(Qualif::NOT_CONST); if self.mode != Mode::Fn { - span_err!(self.tcx.sess, self.span, E0395, - "raw pointers cannot be compared in {}s", - self.mode); + struct_span_err!( + self.tcx.sess, self.span, E0395, + "raw pointers cannot be compared in {}s", + self.mode) + .span_label( + self.span, + &format!("comparing raw pointers in static")) + .emit(); } } } diff --git a/src/test/compile-fail/E0395.rs b/src/test/compile-fail/E0395.rs index 6ab66313a0472..98f08cd68c22d 100644 --- a/src/test/compile-fail/E0395.rs +++ b/src/test/compile-fail/E0395.rs @@ -12,6 +12,6 @@ static FOO: i32 = 42; static BAR: i32 = 42; static BAZ: bool = { (&FOO as *const i32) == (&BAR as *const i32) }; //~ ERROR E0395 - + //~| NOTE comparing raw pointers in static fn main() { } diff --git a/src/test/compile-fail/issue-25826.rs b/src/test/compile-fail/issue-25826.rs index 00e1279d58a0e..468282fa7cca9 100644 --- a/src/test/compile-fail/issue-25826.rs +++ b/src/test/compile-fail/issue-25826.rs @@ -12,5 +12,6 @@ fn id(t: T) -> T { t } fn main() { const A: bool = id:: as *const () < id:: as *const (); //~^ ERROR raw pointers cannot be compared in constants [E0395] + //~^^ NOTE comparing raw pointers in static println!("{}", A); } From dae1406b822c1357f701047951e747dbca2b1446 Mon Sep 17 00:00:00 2001 From: clementmiao Date: Wed, 17 Aug 2016 22:45:21 -0700 Subject: [PATCH 07/24] updated E0396 to new error format --- src/librustc_mir/transform/qualify_consts.rs | 10 +++++++--- src/test/compile-fail/E0396.rs | 1 + src/test/compile-fail/const-deref-ptr.rs | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 103a15dadb61c..e5473d288d4f3 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -490,9 +490,13 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { if let ty::TyRawPtr(_) = base_ty.sty { this.add(Qualif::NOT_CONST); if this.mode != Mode::Fn { - span_err!(this.tcx.sess, this.span, E0396, - "raw pointers cannot be dereferenced in {}s", - this.mode); + struct_span_err!(this.tcx.sess, + this.span, E0396, + "raw pointers cannot be dereferenced in {}s", + this.mode) + .span_label(this.span, + &format!("dereference of raw pointer in constant")) + .emit(); } } } diff --git a/src/test/compile-fail/E0396.rs b/src/test/compile-fail/E0396.rs index 7f34acdfb9007..47080fb6e9ef7 100644 --- a/src/test/compile-fail/E0396.rs +++ b/src/test/compile-fail/E0396.rs @@ -11,6 +11,7 @@ const REG_ADDR: *const u8 = 0x5f3759df as *const u8; const VALUE: u8 = unsafe { *REG_ADDR }; //~ ERROR E0396 + //~| NOTE dereference of raw pointer in constant fn main() { } diff --git a/src/test/compile-fail/const-deref-ptr.rs b/src/test/compile-fail/const-deref-ptr.rs index fa15f3e87c694..c626801d48c03 100644 --- a/src/test/compile-fail/const-deref-ptr.rs +++ b/src/test/compile-fail/const-deref-ptr.rs @@ -12,5 +12,6 @@ fn main() { static C: u64 = unsafe {*(0xdeadbeef as *const u64)}; //~ ERROR E0396 + //~| NOTE dereference of raw pointer in constant println!("{}", C); } From 6976991569977e8097da5f7660a31a42d11e48d2 Mon Sep 17 00:00:00 2001 From: Erik Uggeldahl Date: Thu, 18 Aug 2016 02:03:42 -0400 Subject: [PATCH 08/24] Fix tiny spelling mistake in book Changed datastructure to data structure --- src/doc/book/borrow-and-asref.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/book/borrow-and-asref.md b/src/doc/book/borrow-and-asref.md index 1cfeb2620bd08..c30b2e68665f1 100644 --- a/src/doc/book/borrow-and-asref.md +++ b/src/doc/book/borrow-and-asref.md @@ -8,7 +8,7 @@ different. Here’s a quick refresher on what these two traits mean. # Borrow -The `Borrow` trait is used when you’re writing a datastructure, and you want to +The `Borrow` trait is used when you’re writing a data structure, and you want to use either an owned or borrowed type as synonymous for some purpose. For example, [`HashMap`][hashmap] has a [`get` method][get] which uses `Borrow`: @@ -86,7 +86,7 @@ We can see how they’re kind of the same: they both deal with owned and borrowe versions of some type. However, they’re a bit different. Choose `Borrow` when you want to abstract over different kinds of borrowing, or -when you’re building a datastructure that treats owned and borrowed values in +when you’re building a data structure that treats owned and borrowed values in equivalent ways, such as hashing and comparison. Choose `AsRef` when you want to convert something to a reference directly, and From c2b6f7211472d5e1321e9836f5b339aec1d916d8 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Wed, 17 Aug 2016 22:56:43 -0400 Subject: [PATCH 09/24] Add a few doc examples for `std::ffi::OsStr`. * `std::ffi::OsStr::new`. * `std::ffi::OsStr::is_empty`. * `std::ffi::OsStr::len`. --- src/libstd/ffi/os_str.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 0d29e62485abb..3d23a9a2383ff 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -251,6 +251,14 @@ impl Hash for OsString { impl OsStr { /// Coerces into an `OsStr` slice. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::OsStr; + /// + /// let os_str = OsStr::new("foo"); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn new + ?Sized>(s: &S) -> &OsStr { s.as_ref() @@ -283,6 +291,18 @@ impl OsStr { } /// Checks whether the `OsStr` is empty. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::OsStr; + /// + /// let os_str = OsStr::new(""); + /// assert!(os_str.is_empty()); + /// + /// let os_str = OsStr::new("foo"); + /// assert!(!os_str.is_empty()); + /// ``` #[stable(feature = "osstring_simple_functions", since = "1.9.0")] pub fn is_empty(&self) -> bool { self.inner.inner.is_empty() @@ -296,6 +316,18 @@ impl OsStr { /// other methods like `OsString::with_capacity` to avoid reallocations. /// /// See `OsStr` introduction for more information about encoding. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::OsStr; + /// + /// let os_str = OsStr::new(""); + /// assert_eq!(os_str.len(), 0); + /// + /// let os_str = OsStr::new("foo"); + /// assert_eq!(os_str.len(), 3); + /// ``` #[stable(feature = "osstring_simple_functions", since = "1.9.0")] pub fn len(&self) -> usize { self.inner.inner.len() From 06302cb983198bdf6b984510d24673f4d0f49a98 Mon Sep 17 00:00:00 2001 From: Andrew Cantino Date: Thu, 18 Aug 2016 15:06:05 -0400 Subject: [PATCH 10/24] Fix minor typo --- src/doc/book/closures.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/book/closures.md b/src/doc/book/closures.md index d332cac7d8d16..3ed85c1a90b69 100644 --- a/src/doc/book/closures.md +++ b/src/doc/book/closures.md @@ -340,7 +340,7 @@ fn call_with_ref<'a, F>(some_closure:F) -> i32 where F: Fn(&'a i32) -> i32 { ``` -However this presents a problem with in our case. When you specify the explicit +However this presents a problem in our case. When you specify the explicit lifetime on a function it binds that lifetime to the *entire* scope of the function instead of just the invocation scope of our closure. This means that the borrow checker will see a mutable reference in the same lifetime as our immutable reference and fail From 9563f14eb5d77d992f7cde5db227f8c83351427b Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Thu, 18 Aug 2016 16:04:53 -0400 Subject: [PATCH 11/24] demonstrate `RHS != Self` use cases for `Mul` and `Div` Vector-scalar multipication is a good usecase for this. Thanks #rust! --- src/libcore/ops.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 9347ac2a8c82f..aefafa1b739cb 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -295,6 +295,37 @@ sub_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// Foo * Foo; /// } /// ``` +/// +/// Note that `RHS = Self` by default, but this is not mandatory. Here is an +/// implementation which enables multiplication of vectors by scalars, as is +/// done in linear algebra. +/// +/// ``` +/// use std::ops::Mul; +/// +/// struct Scalar {value: usize}; +/// +/// #[derive(Debug)] +/// struct Vector {value: Vec}; +/// +/// impl Mul for Scalar { +/// type Output = Vector; +/// +/// fn mul(self, rhs: Vector) -> Vector { +/// Vector {value: rhs.value.iter().map(|v| self.value * v).collect()} +/// } +/// } +/// +/// impl PartialEq for Vector { +/// fn eq(&self, other: &Self) -> bool { +/// self.value == other.value +/// } +/// } +/// +/// let scalar = Scalar{value: 3}; +/// let vector = Vector{value: vec![2, 4, 6]}; +/// assert_eq!(scalar * vector, Vector{value: vec![6, 12, 18]}); +/// ``` #[lang = "mul"] #[stable(feature = "rust1", since = "1.0.0")] pub trait Mul { @@ -349,6 +380,37 @@ mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// Foo / Foo; /// } /// ``` +/// +/// Note that `RHS = Self` by default, but this is not mandatory. Here is an +/// implementation which enables division of vectors by scalars, as is done in +/// linear algebra. +/// +/// ``` +/// use std::ops::Div; +/// +/// struct Scalar {value: f32}; +/// +/// #[derive(Debug)] +/// struct Vector {value: Vec}; +/// +/// impl Div for Vector { +/// type Output = Vector; +/// +/// fn div(self, rhs: Scalar) -> Vector { +/// Vector {value: self.value.iter().map(|v| v / rhs.value).collect()} +/// } +/// } +/// +/// impl PartialEq for Vector { +/// fn eq(&self, other: &Self) -> bool { +/// self.value == other.value +/// } +/// } +/// +/// let scalar = Scalar{value: 2f32}; +/// let vector = Vector{value: vec![2f32, 4f32, 6f32]}; +/// assert_eq!(vector / scalar, Vector{value: vec![1f32, 2f32, 3f32]}); +/// ``` #[lang = "div"] #[stable(feature = "rust1", since = "1.0.0")] pub trait Div { From 469b7fd1c09e5759f8cbce0f4e42be91c6f1b81a Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Thu, 18 Aug 2016 16:12:40 -0400 Subject: [PATCH 12/24] split example into three sections with explanation --- src/libcore/ops.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index cee374ccc7bc5..932e5f086cbbe 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -1462,13 +1462,24 @@ pub trait IndexMut: Index { /// /// # Examples /// +/// The `..` syntax is a `RangeFull`: +/// /// ``` /// assert_eq!((..), std::ops::RangeFull); +/// ``` /// -/// // for i in .. { -/// // println!("This errors because .. has no IntoIterator impl"); -/// // } +/// It does not have an `IntoIterator` implementation, so you can't use it in a +/// `for` loop directly. This won't compile: /// +/// ```ignore +/// for i in .. { +/// // ... +/// } +/// ``` +/// +/// Used as a slicing index, `RangeFull` produces the full array as a slice. +/// +/// ``` /// let arr = [0, 1, 2, 3]; /// assert_eq!(arr[ .. ], [0,1,2,3]); // RangeFull /// assert_eq!(arr[ ..3], [0,1,2 ]); From 301401e568e6ed297ab0b06c5cf60d8ba8109750 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Tue, 16 Aug 2016 14:25:12 +1200 Subject: [PATCH 13/24] Redirect --- src/librustdoc/html/render.rs | 10 ++++++++++ src/test/rustdoc/macros.rs | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index d654429146d83..e02cfb96dddf1 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1426,6 +1426,16 @@ impl Context { .open(&redir_dst) { try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); } + + // If the item is a macro, redirect from the old macro URL (with !) + // to the new one (without). + // FIXME(#35705) remove this redirect. + if item_type == ItemType::Macro { + let redir_name = format!("{}.{}!.html", item_type, name); + let redir_dst = self.dst.join(redir_name); + let mut redirect_out = try_err!(File::create(&redir_dst), &redir_dst); + try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); + } } } Ok(()) diff --git a/src/test/rustdoc/macros.rs b/src/test/rustdoc/macros.rs index f4115d8229a54..9aeeb71707c90 100644 --- a/src/test/rustdoc/macros.rs +++ b/src/test/rustdoc/macros.rs @@ -12,6 +12,8 @@ // @has - //pre '() => { ... };' // @has - //pre '($a:tt) => { ... };' // @has - //pre '($e:expr) => { ... };' +// @has macros/macro.my_macro!.html +// @has - //a 'macro.my_macro.html' #[macro_export] macro_rules! my_macro { () => []; From 161cb36159337edfeba546c9ead24262bc5a5dfc Mon Sep 17 00:00:00 2001 From: pliniker Date: Thu, 18 Aug 2016 16:27:33 -0400 Subject: [PATCH 14/24] Update error message for E0084 --- src/librustc_typeck/check/mod.rs | 7 +++++-- src/test/compile-fail/E0084.rs | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ff0b86aa59540..78d311865aa87 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1245,8 +1245,11 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, let hint = *ccx.tcx.lookup_repr_hints(def_id).get(0).unwrap_or(&attr::ReprAny); if hint != attr::ReprAny && vs.is_empty() { - span_err!(ccx.tcx.sess, sp, E0084, - "unsupported representation for zero-variant enum"); + struct_span_err!( + ccx.tcx.sess, sp, E0084, + "unsupported representation for zero-variant enum") + .span_label(sp, &format!("unsupported enum representation")) + .emit(); } let repr_type_ty = ccx.tcx.enum_repr_type(Some(&hint)).to_ty(ccx.tcx); diff --git a/src/test/compile-fail/E0084.rs b/src/test/compile-fail/E0084.rs index c579101325f5d..c7c5662f1feda 100644 --- a/src/test/compile-fail/E0084.rs +++ b/src/test/compile-fail/E0084.rs @@ -9,7 +9,9 @@ // except according to those terms. #[repr(i32)] -enum Foo {} //~ ERROR E0084 +enum Foo {} +//~^ ERROR E0084 +//~| unsupported enum representation fn main() { } From a516dbb7d946fc26ed036ae4bd23f4c7abdff3a2 Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Tue, 16 Aug 2016 04:33:59 -0400 Subject: [PATCH 15/24] note that calling drop() explicitly is a compiler error Part of #29365 explain that std::mem::drop in prelude will invoke Drop change "prelude" -> "the prelude"; change links to reference-style move link references to links' section --- src/libcore/ops.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 9347ac2a8c82f..daa5ebb61f96d 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -102,6 +102,13 @@ pub trait Drop { /// /// After this function is over, the memory of `self` will be deallocated. /// + /// This function cannot be called explicitly. This is compiler error + /// [0040]. However, the [`std::mem::drop`] function in the prelude can be + /// used to call the argument's `Drop` implementation. + /// + /// [0040]: https://doc.rust-lang.org/error-index.html#E0040 + /// [`std::mem::drop`]: https://doc.rust-lang.org/std/mem/fn.drop.html + /// /// # Panics /// /// Given that a `panic!` will call `drop()` as it unwinds, any `panic!` in From 6c66eaa035e5fc47ebbff44b81d2cb3cf1d7d568 Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Thu, 18 Aug 2016 16:54:33 -0400 Subject: [PATCH 16/24] replace `AddAssign` example with something more evocative of addition This is analogous to PR #35709 for the `Add` trait. --- src/libcore/ops.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 9347ac2a8c82f..1a203a898f73e 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -894,25 +894,36 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize } /// /// # Examples /// -/// A trivial implementation of `AddAssign`. When `Foo += Foo` happens, it ends up -/// calling `add_assign`, and therefore, `main` prints `Adding!`. +/// This example creates a `Point` struct that implements the `AddAssign` +/// trait, and then demonstrates add-assigning to a mutable `Point`. /// /// ``` /// use std::ops::AddAssign; /// -/// struct Foo; +/// #[derive(Debug)] +/// struct Point { +/// x: i32, +/// y: i32, +/// } /// -/// impl AddAssign for Foo { -/// fn add_assign(&mut self, _rhs: Foo) { -/// println!("Adding!"); +/// impl AddAssign for Point { +/// fn add_assign(&mut self, other: Point) { +/// *self = Point { +/// x: self.x + other.x, +/// y: self.y + other.y, +/// }; /// } /// } /// -/// # #[allow(unused_assignments)] -/// fn main() { -/// let mut foo = Foo; -/// foo += Foo; +/// impl PartialEq for Point { +/// fn eq(&self, other: &Self) -> bool { +/// self.x == other.x && self.y == other.y +/// } /// } +/// +/// let mut point = Point { x: 1, y: 0 }; +/// point += Point { x: 2, y: 3 }; +/// assert_eq!(point, Point { x: 3, y: 3 }); /// ``` #[lang = "add_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] From ffbb8600fbba009598cbebf7149d0bd7a736b928 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 18 Aug 2016 15:22:23 -0700 Subject: [PATCH 17/24] Add workaround to detect correct compiler version --- src/bootstrap/bin/rustc.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index c64cbb9a74e09..175e32125f272 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -38,13 +38,19 @@ fn main() { // is passed (a bit janky...) let target = args.windows(2).find(|w| &*w[0] == "--target") .and_then(|w| w[1].to_str()); + let version = args.iter().find(|w| &**w == "-vV"); // Build scripts always use the snapshot compiler which is guaranteed to be // able to produce an executable, whereas intermediate compilers may not // have the standard library built yet and may not be able to produce an // executable. Otherwise we just use the standard compiler we're // bootstrapping with. - let (rustc, libdir) = if target.is_none() { + // + // Also note that cargo will detect the version of the compiler to trigger + // a rebuild when the compiler changes. If this happens, we want to make + // sure to use the actual compiler instead of the snapshot compiler becase + // that's the one that's actually changing. + let (rustc, libdir) = if target.is_none() && version.is_none() { ("RUSTC_SNAPSHOT", "RUSTC_SNAPSHOT_LIBDIR") } else { ("RUSTC_REAL", "RUSTC_LIBDIR") From 39f318bb4d7144a8deb10f520a01164133c1b6ec Mon Sep 17 00:00:00 2001 From: Michael Layne Date: Thu, 18 Aug 2016 14:40:59 -0700 Subject: [PATCH 18/24] Update error format for E0232 --- src/librustc_typeck/check/mod.rs | 9 ++++++--- src/test/compile-fail/E0232.rs | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ff0b86aa59540..3a21ffb5e7d93 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -903,9 +903,12 @@ fn check_on_unimplemented<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, } } } else { - span_err!(ccx.tcx.sess, attr.span, E0232, - "this attribute must have a value, \ - eg `#[rustc_on_unimplemented = \"foo\"]`") + struct_span_err!( + ccx.tcx.sess, attr.span, E0232, + "this attribute must have a value") + .span_label(attr.span, &format!("attribute requires a value")) + .note(&format!("eg `#[rustc_on_unimplemented = \"foo\"]`")) + .emit(); } } } diff --git a/src/test/compile-fail/E0232.rs b/src/test/compile-fail/E0232.rs index efeb869d71fa5..ce4f4638dac59 100644 --- a/src/test/compile-fail/E0232.rs +++ b/src/test/compile-fail/E0232.rs @@ -10,7 +10,10 @@ #![feature(on_unimplemented)] -#[rustc_on_unimplemented] //~ ERROR E0232 +#[rustc_on_unimplemented] +//~^ ERROR E0232 +//~| NOTE attribute requires a value +//~| NOTE eg `#[rustc_on_unimplemented = "foo"]` trait Bar {} fn main() { From 2128d31a41346c726d2271845d92533ccae882e7 Mon Sep 17 00:00:00 2001 From: Chiu-Hsiang Hsu Date: Fri, 19 Aug 2016 11:58:26 +0800 Subject: [PATCH 19/24] Fix label messages for E0133 Issue #35789 --- src/librustc/middle/effect.rs | 2 +- src/test/compile-fail/E0133.rs | 2 +- src/test/compile-fail/issue-28776.rs | 2 +- src/test/compile-fail/trait-safety-fn-body.rs | 2 +- src/test/compile-fail/unsafe-const-fn.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index 3ca6cf0399797..250ad80f5af6c 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -66,7 +66,7 @@ impl<'a, 'tcx> EffectCheckVisitor<'a, 'tcx> { struct_span_err!( self.tcx.sess, span, E0133, "{} requires unsafe function or block", description) - .span_label(span, &format!("unsafe call requires unsafe function or block")) + .span_label(span, &description) .emit(); } UnsafeBlock(block_id) => { diff --git a/src/test/compile-fail/E0133.rs b/src/test/compile-fail/E0133.rs index b8a4476fc5967..f60d9a5083f6f 100644 --- a/src/test/compile-fail/E0133.rs +++ b/src/test/compile-fail/E0133.rs @@ -13,5 +13,5 @@ unsafe fn f() { return; } fn main() { f(); //~^ ERROR E0133 - //~| NOTE unsafe call requires unsafe function or block + //~| NOTE call to unsafe function } diff --git a/src/test/compile-fail/issue-28776.rs b/src/test/compile-fail/issue-28776.rs index 52b0eba96cbdf..4a36bc88fa7d9 100644 --- a/src/test/compile-fail/issue-28776.rs +++ b/src/test/compile-fail/issue-28776.rs @@ -13,5 +13,5 @@ use std::ptr; fn main() { (&ptr::write)(1 as *mut _, 42); //~^ ERROR E0133 - //~| NOTE unsafe call requires unsafe function or block + //~| NOTE call to unsafe function } diff --git a/src/test/compile-fail/trait-safety-fn-body.rs b/src/test/compile-fail/trait-safety-fn-body.rs index 0df7ee8cabed2..65732a8ff69e5 100644 --- a/src/test/compile-fail/trait-safety-fn-body.rs +++ b/src/test/compile-fail/trait-safety-fn-body.rs @@ -20,7 +20,7 @@ unsafe impl UnsafeTrait for *mut isize { // Unsafe actions are not made legal by taking place in an unsafe trait: *self += 1; //~^ ERROR E0133 - //~| NOTE unsafe call requires unsafe function or block + //~| NOTE dereference of raw pointer } } diff --git a/src/test/compile-fail/unsafe-const-fn.rs b/src/test/compile-fail/unsafe-const-fn.rs index 174939b09009c..91e16592be472 100644 --- a/src/test/compile-fail/unsafe-const-fn.rs +++ b/src/test/compile-fail/unsafe-const-fn.rs @@ -18,7 +18,7 @@ const unsafe fn dummy(v: u32) -> u32 { const VAL: u32 = dummy(0xFFFF); //~^ ERROR E0133 -//~| NOTE unsafe call requires unsafe function or block +//~| NOTE call to unsafe function fn main() { assert_eq!(VAL, 0xFFFF0000); From 06147ac29152877830454330c16fd82f23d050df Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Fri, 19 Aug 2016 12:35:54 -0400 Subject: [PATCH 20/24] replace `Not` example with something more evocative --- src/libcore/ops.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 9347ac2a8c82f..67c25d42f1f4d 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -538,26 +538,31 @@ neg_impl_numeric! { isize i8 i16 i32 i64 f32 f64 } /// /// # Examples /// -/// A trivial implementation of `Not`. When `!Foo` happens, it ends up calling -/// `not`, and therefore, `main` prints `Not-ing!`. +/// An implementation of `Not` for `Answer`, which enables the use of `!` to +/// invert its value. /// /// ``` /// use std::ops::Not; /// -/// struct Foo; +/// #[derive(Debug, PartialEq)] +/// enum Answer { +/// Yes, +/// No, +/// } /// -/// impl Not for Foo { -/// type Output = Foo; +/// impl Not for Answer { +/// type Output = Answer; /// -/// fn not(self) -> Foo { -/// println!("Not-ing!"); -/// self +/// fn not(self) -> Answer { +/// match self { +/// Answer::Yes => Answer::No, +/// Answer::No => Answer::Yes +/// } /// } /// } /// -/// fn main() { -/// !Foo; -/// } +/// assert_eq!(!Answer::Yes, Answer::No); +/// assert_eq!(!Answer::No, Answer::Yes); /// ``` #[lang = "not"] #[stable(feature = "rust1", since = "1.0.0")] From c0eccb120326bc559a4cbe30ace4935d83420073 Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Fri, 19 Aug 2016 12:46:11 -0400 Subject: [PATCH 21/24] replace `Neg` example with something more evocative of negation --- src/libcore/ops.rs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 9347ac2a8c82f..73979d84ad314 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -470,26 +470,37 @@ rem_impl_float! { f32 f64 } /// /// # Examples /// -/// A trivial implementation of `Neg`. When `-Foo` happens, it ends up calling -/// `neg`, and therefore, `main` prints `Negating!`. +/// An implementation of `Neg` for `Sign`, which allows the use of `-` to +/// negate its value. /// /// ``` /// use std::ops::Neg; /// -/// struct Foo; +/// #[derive(Debug, PartialEq)] +/// enum Sign { +/// Negative, +/// Zero, +/// Positive, +/// } /// -/// impl Neg for Foo { -/// type Output = Foo; +/// impl Neg for Sign { +/// type Output = Sign; /// -/// fn neg(self) -> Foo { -/// println!("Negating!"); -/// self +/// fn neg(self) -> Sign { +/// match self { +/// Sign::Negative => Sign::Positive, +/// Sign::Zero => Sign::Zero, +/// Sign::Positive => Sign::Negative, +/// } /// } /// } /// -/// fn main() { -/// -Foo; -/// } +/// // a negative positive is a negative +/// assert_eq!(-Sign::Positive, Sign::Negative); +/// // a double negative is a positive +/// assert_eq!(-Sign::Negative, Sign::Positive); +/// // zero is its own negation +/// assert_eq!(-Sign::Zero, Sign::Zero); /// ``` #[lang = "neg"] #[stable(feature = "rust1", since = "1.0.0")] From 3b64cf669cef3aec090b2c6fa6ba7b8b23d4ba97 Mon Sep 17 00:00:00 2001 From: trixnz Date: Fri, 19 Aug 2016 19:19:34 +0200 Subject: [PATCH 22/24] Update E0428 to new format --- src/librustc_resolve/lib.rs | 6 +++++- src/test/compile-fail/E0428.rs | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index b91ede5b2fa8a..af39f8a415c67 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -3382,7 +3382,11 @@ impl<'a> Resolver<'a> { }, (true, _) | (_, true) => struct_span_err!(self.session, span, E0260, "{}", msg), _ => match (old_binding.is_import(), binding.is_import()) { - (false, false) => struct_span_err!(self.session, span, E0428, "{}", msg), + (false, false) => { + let mut e = struct_span_err!(self.session, span, E0428, "{}", msg); + e.span_label(span, &format!("already defined")); + e + }, (true, true) => { let mut e = struct_span_err!(self.session, span, E0252, "{}", msg); e.span_label(span, &format!("already imported")); diff --git a/src/test/compile-fail/E0428.rs b/src/test/compile-fail/E0428.rs index 42e237d31cbee..63b4efb73f0c5 100644 --- a/src/test/compile-fail/E0428.rs +++ b/src/test/compile-fail/E0428.rs @@ -8,9 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Bar; +struct Bar; //~ previous definition of `Bar` here + //~| previous definition of `Bar` here struct Bar; //~ ERROR E0428 - //~^ ERROR E0428 + //~| NOTE already defined + //~| ERROR E0428 + //~| NOTE already defined fn main () { } From 54d0acd2fc6414930ff27c01c8640f4e9c666ad5 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Fri, 19 Aug 2016 16:05:37 -0700 Subject: [PATCH 23/24] wording fixes in error messages --- src/librustc/ty/error.rs | 4 ++-- src/librustc_errors/emitter.rs | 4 +++- src/librustc_typeck/check/callee.rs | 2 +- src/librustc_typeck/check/compare_method.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 9 ++++----- src/librustc_typeck/coherence/orphan.rs | 2 +- src/librustc_typeck/diagnostics.rs | 2 +- src/test/compile-fail/E0040.rs | 2 +- src/test/compile-fail/E0053.rs | 6 +++--- src/test/compile-fail/E0087.rs | 2 +- .../compile-fail/associated-const-impl-wrong-type.rs | 2 +- src/test/compile-fail/coerce-mut.rs | 2 +- src/test/compile-fail/fn-variance-1.rs | 4 ++-- src/test/compile-fail/impl-wrong-item-for-trait.rs | 6 +++--- src/test/compile-fail/mut-pattern-mismatched.rs | 4 ++-- src/test/compile-fail/ptr-coercion.rs | 6 +++--- src/test/compile-fail/slice-mut.rs | 2 +- .../trait-impl-fn-incompatibility.stderr | 6 +++--- 18 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 17f9b6c25995c..32c87fb615a53 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -98,9 +98,9 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { values.expected, values.found) } - Mutability => write!(f, "values differ in mutability"), + Mutability => write!(f, "types differ in mutability"), BoxMutability => { - write!(f, "boxed values differ in mutability") + write!(f, "boxed types differ in mutability") } VecMutability => write!(f, "vectors differ in mutability"), PtrMutability => write!(f, "pointers differ in mutability"), diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 5fd9226aba9d4..793155cfa8f8f 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -426,7 +426,9 @@ impl EmitterWriter { continue; } // Check to make sure we're not in any <*macros> - if !cm.span_to_filename(def_site).contains("macros>") { + if !cm.span_to_filename(def_site).contains("macros>") && + !trace.macro_decl_name.starts_with("#[") + { new_labels.push((trace.call_site, "in this macro invocation".to_string())); break; diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 985c3be149617..acb6653214dcb 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -29,7 +29,7 @@ use rustc::hir; pub fn check_legal_trait_for_method_call(ccx: &CrateCtxt, span: Span, trait_id: DefId) { if ccx.tcx.lang_items.drop_trait() == Some(trait_id) { struct_span_err!(ccx.tcx.sess, span, E0040, "explicit use of destructor method") - .span_label(span, &format!("call to destructor method")) + .span_label(span, &format!("explicit destructor calls not allowed")) .emit(); } } diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 043883df035d0..0e42990a337d4 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -402,7 +402,7 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, infcx.note_type_err( &mut diag, origin, - trait_err_span.map(|sp| (sp, format!("original trait requirement"))), + trait_err_span.map(|sp| (sp, format!("type in trait"))), Some(infer::ValuePairs::Types(ExpectedFound { expected: trait_fty, found: impl_fty @@ -575,7 +575,7 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, infcx.note_type_err( &mut diag, origin, - Some((trait_c_span, format!("original trait requirement"))), + Some((trait_c_span, format!("type in trait"))), Some(infer::ValuePairs::Types(ExpectedFound { expected: trait_ty, found: impl_ty diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ff0b86aa59540..ca78345556926 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1013,7 +1013,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, // We can only get the spans from local trait definition // Same for E0324 and E0325 if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id()) { - err.span_label(trait_span, &format!("original trait requirement")); + err.span_label(trait_span, &format!("item in trait")); } err.emit() } @@ -1041,7 +1041,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, impl_trait_ref); err.span_label(impl_item.span, &format!("does not match trait")); if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id()) { - err.span_label(trait_span, &format!("original trait requirement")); + err.span_label(trait_span, &format!("item in trait")); } err.emit() } @@ -1064,7 +1064,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, impl_trait_ref); err.span_label(impl_item.span, &format!("does not match trait")); if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id()) { - err.span_label(trait_span, &format!("original trait requirement")); + err.span_label(trait_span, &format!("item in trait")); } err.emit() } @@ -4408,8 +4408,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { expected at most {}, found {}", count(type_defs.len()), count(types.len())) - .span_label(span, &format!("expected {}", - count(type_defs.len()))).emit(); + .span_label(span, &format!("too many type parameters")).emit(); // To prevent derived errors to accumulate due to extra // type parameters, we force instantiate_value_path to diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 7578ec3d813c1..a3c043fe7cbd3 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -37,7 +37,7 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> { "cannot define inherent `impl` for a type outside of the \ crate where the type is defined") .span_label(item.span, &format!("impl for type defined outside of crate.")) - .span_note(item.span, &format!("define and implement a trait or new type instead")) + .note("define and implement a trait or new type instead") .emit(); } } diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index fe1cb3d6badcd..8bb5efdcad2c3 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -572,7 +572,7 @@ impl Foo for Bar { // error, expected u16, found i16 fn foo(x: i16) { } - // error, values differ in mutability + // error, types differ in mutability fn bar(&mut self) { } } ``` diff --git a/src/test/compile-fail/E0040.rs b/src/test/compile-fail/E0040.rs index 80ff57c363595..edfe22186e162 100644 --- a/src/test/compile-fail/E0040.rs +++ b/src/test/compile-fail/E0040.rs @@ -22,5 +22,5 @@ fn main() { let mut x = Foo { x: -7 }; x.drop(); //~^ ERROR E0040 - //~| NOTE call to destructor method + //~| NOTE explicit destructor calls not allowed } diff --git a/src/test/compile-fail/E0053.rs b/src/test/compile-fail/E0053.rs index 7022010714aa7..933462e553e3b 100644 --- a/src/test/compile-fail/E0053.rs +++ b/src/test/compile-fail/E0053.rs @@ -9,8 +9,8 @@ // except according to those terms. trait Foo { - fn foo(x: u16); //~ NOTE original trait requirement - fn bar(&self); //~ NOTE original trait requirement + fn foo(x: u16); //~ NOTE type in trait + fn bar(&self); //~ NOTE type in trait } struct Bar; @@ -21,7 +21,7 @@ impl Foo for Bar { //~| NOTE expected u16 fn bar(&mut self) { } //~^ ERROR method `bar` has an incompatible type for trait - //~| NOTE values differ in mutability + //~| NOTE types differ in mutability //~| NOTE expected type `fn(&Bar)` //~| NOTE found type `fn(&mut Bar)` } diff --git a/src/test/compile-fail/E0087.rs b/src/test/compile-fail/E0087.rs index 437ad3698a206..7c98de59e2797 100644 --- a/src/test/compile-fail/E0087.rs +++ b/src/test/compile-fail/E0087.rs @@ -12,5 +12,5 @@ fn foo() {} fn main() { foo::(); //~ ERROR E0087 - //~^ NOTE expected + //~^ NOTE too many type parameters } diff --git a/src/test/compile-fail/associated-const-impl-wrong-type.rs b/src/test/compile-fail/associated-const-impl-wrong-type.rs index b3776091682da..ec495c87b1a3f 100644 --- a/src/test/compile-fail/associated-const-impl-wrong-type.rs +++ b/src/test/compile-fail/associated-const-impl-wrong-type.rs @@ -11,7 +11,7 @@ #![feature(associated_consts)] trait Foo { - const BAR: u32; //~ NOTE original trait requirement + const BAR: u32; //~ NOTE type in trait } struct SignedBar; diff --git a/src/test/compile-fail/coerce-mut.rs b/src/test/compile-fail/coerce-mut.rs index 86702a7463fd0..bc3d58ef33db0 100644 --- a/src/test/compile-fail/coerce-mut.rs +++ b/src/test/compile-fail/coerce-mut.rs @@ -16,5 +16,5 @@ fn main() { //~^ ERROR mismatched types //~| expected type `&mut i32` //~| found type `&{integer}` - //~| values differ in mutability + //~| types differ in mutability } diff --git a/src/test/compile-fail/fn-variance-1.rs b/src/test/compile-fail/fn-variance-1.rs index e9dd1cb719dbc..d0d911b6eb936 100644 --- a/src/test/compile-fail/fn-variance-1.rs +++ b/src/test/compile-fail/fn-variance-1.rs @@ -19,9 +19,9 @@ fn apply(t: T, f: F) where F: FnOnce(T) { fn main() { apply(&3, takes_imm); apply(&3, takes_mut); - //~^ ERROR (values differ in mutability) + //~^ ERROR (types differ in mutability) apply(&mut 3, takes_mut); apply(&mut 3, takes_imm); - //~^ ERROR (values differ in mutability) + //~^ ERROR (types differ in mutability) } diff --git a/src/test/compile-fail/impl-wrong-item-for-trait.rs b/src/test/compile-fail/impl-wrong-item-for-trait.rs index e0ea1a4cac58b..388c9a1729cca 100644 --- a/src/test/compile-fail/impl-wrong-item-for-trait.rs +++ b/src/test/compile-fail/impl-wrong-item-for-trait.rs @@ -12,9 +12,9 @@ trait Foo { fn bar(&self); - //~^ NOTE original trait requirement - //~| NOTE original trait requirement - const MY_CONST: u32; //~ NOTE original trait requirement + //~^ NOTE item in trait + //~| NOTE item in trait + const MY_CONST: u32; //~ NOTE item in trait } pub struct FooConstForMethod; diff --git a/src/test/compile-fail/mut-pattern-mismatched.rs b/src/test/compile-fail/mut-pattern-mismatched.rs index 318d121e4c2df..7685a5c0808a2 100644 --- a/src/test/compile-fail/mut-pattern-mismatched.rs +++ b/src/test/compile-fail/mut-pattern-mismatched.rs @@ -16,7 +16,7 @@ fn main() { let &_ //~ ERROR mismatched types //~| expected type `&mut {integer}` //~| found type `&_` - //~| values differ in mutability + //~| types differ in mutability = foo; let &mut _ = foo; @@ -25,6 +25,6 @@ fn main() { let &mut _ //~ ERROR mismatched types //~| expected type `&{integer}` //~| found type `&mut _` - //~| values differ in mutability + //~| types differ in mutability = bar; } diff --git a/src/test/compile-fail/ptr-coercion.rs b/src/test/compile-fail/ptr-coercion.rs index ff627e69d4c58..1390c9507c1c2 100644 --- a/src/test/compile-fail/ptr-coercion.rs +++ b/src/test/compile-fail/ptr-coercion.rs @@ -17,17 +17,17 @@ pub fn main() { let x: *mut isize = x; //~ ERROR mismatched types //~| expected type `*mut isize` //~| found type `*const isize` - //~| values differ in mutability + //~| types differ in mutability // & -> *mut let x: *mut isize = &42; //~ ERROR mismatched types //~| expected type `*mut isize` //~| found type `&isize` - //~| values differ in mutability + //~| types differ in mutability let x: *const isize = &42; let x: *mut isize = x; //~ ERROR mismatched types //~| expected type `*mut isize` //~| found type `*const isize` - //~| values differ in mutability + //~| types differ in mutability } diff --git a/src/test/compile-fail/slice-mut.rs b/src/test/compile-fail/slice-mut.rs index 874cca8cb3fd0..bee3704a353d3 100644 --- a/src/test/compile-fail/slice-mut.rs +++ b/src/test/compile-fail/slice-mut.rs @@ -18,5 +18,5 @@ fn main() { //~^ ERROR mismatched types //~| expected type `&mut [_]` //~| found type `&[isize]` - //~| values differ in mutability + //~| types differ in mutability } diff --git a/src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr b/src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr index e5dfdc8e910df..4a0ccc46525d0 100644 --- a/src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr +++ b/src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr @@ -2,7 +2,7 @@ error[E0053]: method `foo` has an incompatible type for trait --> $DIR/trait-impl-fn-incompatibility.rs:21:15 | 14 | fn foo(x: u16); - | --- original trait requirement + | --- type in trait ... 21 | fn foo(x: i16) { } | ^^^ expected u16, found i16 @@ -11,10 +11,10 @@ error[E0053]: method `bar` has an incompatible type for trait --> $DIR/trait-impl-fn-incompatibility.rs:22:28 | 15 | fn bar(&mut self, bar: &mut Bar); - | -------- original trait requirement + | -------- type in trait ... 22 | fn bar(&mut self, bar: &Bar) { } - | ^^^^ values differ in mutability + | ^^^^ types differ in mutability | = note: expected type `fn(&mut Bar, &mut Bar)` = note: found type `fn(&mut Bar, &Bar)` From d791aa1b3f2d67720f1baba31bf1f1a5e7988b8f Mon Sep 17 00:00:00 2001 From: trixnz Date: Sat, 20 Aug 2016 12:10:41 +0200 Subject: [PATCH 24/24] Fix broken tests for E0428 --- src/test/compile-fail/enum-and-module-in-same-scope.rs | 3 ++- src/test/compile-fail/issue-21546.rs | 6 ++++++ src/test/compile-fail/trait-duplicate-methods.rs | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/test/compile-fail/enum-and-module-in-same-scope.rs b/src/test/compile-fail/enum-and-module-in-same-scope.rs index a6793ee8b9fbd..527ac7505a654 100644 --- a/src/test/compile-fail/enum-and-module-in-same-scope.rs +++ b/src/test/compile-fail/enum-and-module-in-same-scope.rs @@ -8,11 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -enum Foo { //~ NOTE previous definition +enum Foo { //~ NOTE previous definition of `Foo` here X } mod Foo { //~ ERROR a type named `Foo` has already been defined + //~| NOTE already defined pub static X: isize = 42; fn f() { f() } // Check that this does not result in a resolution error } diff --git a/src/test/compile-fail/issue-21546.rs b/src/test/compile-fail/issue-21546.rs index 11d05ceb9a019..d103d45bc4cb7 100644 --- a/src/test/compile-fail/issue-21546.rs +++ b/src/test/compile-fail/issue-21546.rs @@ -17,6 +17,7 @@ mod Foo { } #[allow(dead_code)] struct Foo; //~^ ERROR a module named `Foo` has already been defined in this module +//~| NOTE already defined #[allow(non_snake_case)] mod Bar { } @@ -25,6 +26,7 @@ mod Bar { } #[allow(dead_code)] struct Bar(i32); //~^ ERROR a module named `Bar` has already been defined +//~| NOTE already defined #[allow(dead_code)] @@ -34,6 +36,7 @@ struct Baz(i32); #[allow(non_snake_case)] mod Baz { } //~^ ERROR a type named `Baz` has already been defined +//~| NOTE already defined #[allow(dead_code)] @@ -43,6 +46,7 @@ struct Qux { x: bool } #[allow(non_snake_case)] mod Qux { } //~^ ERROR a type named `Qux` has already been defined +//~| NOTE already defined #[allow(dead_code)] @@ -52,6 +56,7 @@ struct Quux; #[allow(non_snake_case)] mod Quux { } //~^ ERROR a type named `Quux` has already been defined +//~| NOTE already defined #[allow(dead_code)] @@ -61,5 +66,6 @@ enum Corge { A, B } #[allow(non_snake_case)] mod Corge { } //~^ ERROR a type named `Corge` has already been defined +//~| NOTE already defined fn main() { } diff --git a/src/test/compile-fail/trait-duplicate-methods.rs b/src/test/compile-fail/trait-duplicate-methods.rs index 41700b25bbb72..7bcab1f6ac56b 100644 --- a/src/test/compile-fail/trait-duplicate-methods.rs +++ b/src/test/compile-fail/trait-duplicate-methods.rs @@ -11,6 +11,7 @@ trait Foo { fn orange(&self); //~ NOTE previous definition of `orange` here fn orange(&self); //~ ERROR a value named `orange` has already been defined in this trait + //~| NOTE already define } fn main() {}