From f581d525e7e0c5576421c7846c0af400392b91df Mon Sep 17 00:00:00 2001 From: Rahul Sharma Date: Wed, 10 Aug 2016 16:36:41 +0530 Subject: [PATCH 1/8] Update E0261 and E0262 to new error format --- src/librustc/middle/resolve_lifetime.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 7f6614a959c89..d9990e2e2620c 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -697,9 +697,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } fn unresolved_lifetime_ref(&self, lifetime_ref: &hir::Lifetime) { - span_err!(self.sess, lifetime_ref.span, E0261, - "use of undeclared lifetime name `{}`", - lifetime_ref.name); + struct_span_err!(self.sess, lifetime_ref.span, E0261, + "use of undeclared lifetime name `{}`", lifetime_ref.name) + .span_label(lifetime_ref.span, &format!("undeclared lifetime")) + .emit(); } fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &[hir::LifetimeDef]) { @@ -708,8 +709,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { for lifetime in lifetimes { if lifetime.lifetime.name == keywords::StaticLifetime.name() { - span_err!(self.sess, lifetime.lifetime.span, E0262, - "invalid lifetime parameter name: `{}`", lifetime.lifetime.name); + let lifetime = lifetime.lifetime; + let mut err = struct_span_err!(self.sess, lifetime.span, E0262, + "invalid lifetime parameter name: `{}`", lifetime.name); + err.span_label(lifetime.span, + &format!("{} is a reserved lifetime name", lifetime.name)); + err.emit(); } } From 19a33371eb0dca0e53c7332e87e728e19e5206ac Mon Sep 17 00:00:00 2001 From: Terry Sun Date: Sat, 13 Aug 2016 21:57:13 -0400 Subject: [PATCH 2/8] Update E0207 label to report parameter type Fixes #35642. --- src/librustc_typeck/collect.rs | 3 +-- src/test/compile-fail/E0207.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 75bfad053a328..bc755821fba46 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -2323,7 +2323,6 @@ fn report_unused_parameter(ccx: &CrateCtxt, "the {} parameter `{}` is not constrained by the \ impl trait, self type, or predicates", kind, name) - .span_label(span, &format!("unconstrained lifetime parameter")) + .span_label(span, &format!("unconstrained {} parameter", kind)) .emit(); - } diff --git a/src/test/compile-fail/E0207.rs b/src/test/compile-fail/E0207.rs index 43ff085a4fa8e..fbddb81d7c70b 100644 --- a/src/test/compile-fail/E0207.rs +++ b/src/test/compile-fail/E0207.rs @@ -11,7 +11,7 @@ struct Foo; impl Foo { //~ ERROR E0207 - //~| NOTE unconstrained lifetime parameter + //~| NOTE unconstrained type parameter fn get(&self) -> T { ::default() } From 02fa14fc8ef3020b2ca52cc7d7f69db38520569f Mon Sep 17 00:00:00 2001 From: Rahul Sharma Date: Sun, 14 Aug 2016 16:18:58 +0530 Subject: [PATCH 3/8] updated compile-fail tests --- src/test/compile-fail/E0261.rs | 2 ++ src/test/compile-fail/E0262.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/test/compile-fail/E0261.rs b/src/test/compile-fail/E0261.rs index 4196ad370b887..558c1c381447e 100644 --- a/src/test/compile-fail/E0261.rs +++ b/src/test/compile-fail/E0261.rs @@ -9,9 +9,11 @@ // except according to those terms. fn foo(x: &'a str) { } //~ ERROR E0261 + //~| undeclared lifetime struct Foo { x: &'a str, //~ ERROR E0261 + //~| undeclared lifetime } fn main() {} diff --git a/src/test/compile-fail/E0262.rs b/src/test/compile-fail/E0262.rs index e09e4766d5174..41b6acaee4a1e 100644 --- a/src/test/compile-fail/E0262.rs +++ b/src/test/compile-fail/E0262.rs @@ -9,5 +9,6 @@ // except according to those terms. fn foo<'static>(x: &'static str) { } //~ ERROR E0262 + //~| 'static is a reserved lifetime name fn main() {} From e586d2174bd732bcc4a430266f371fbb82b39398 Mon Sep 17 00:00:00 2001 From: Christopher Serr Date: Sun, 14 Aug 2016 13:33:53 +0200 Subject: [PATCH 4/8] Improve `No stdlib` and related Documentation --- src/doc/book/lang-items.md | 8 ++++---- src/doc/book/no-stdlib.md | 33 +++++++++++++++++++++++++-------- src/libcore/lib.rs | 5 +++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/doc/book/lang-items.md b/src/doc/book/lang-items.md index 72a3c08225d03..de7dbab3f12ea 100644 --- a/src/doc/book/lang-items.md +++ b/src/doc/book/lang-items.md @@ -57,8 +57,8 @@ fn main(argc: isize, argv: *const *const u8) -> isize { 0 } -#[lang = "eh_personality"] extern fn eh_personality() {} -#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} } +#[lang = "eh_personality"] extern fn rust_eh_personality() {} +#[lang = "panic_fmt"] extern fn rust_begin_panic() -> ! { loop {} } # #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {} # #[no_mangle] pub extern fn rust_eh_register_frames () {} # #[no_mangle] pub extern fn rust_eh_unregister_frames () {} @@ -73,8 +73,8 @@ Other features provided by lang items include: `==`, `<`, dereferencing (`*`) and `+` (etc.) operators are all marked with lang items; those specific four are `eq`, `ord`, `deref`, and `add` respectively. -- stack unwinding and general failure; the `eh_personality`, `fail` - and `fail_bounds_checks` lang items. +- stack unwinding and general failure; the `eh_personality`, + `eh_unwind_resume`, `fail` and `fail_bounds_checks` lang items. - the traits in `std::marker` used to indicate types of various kinds; lang items `send`, `sync` and `copy`. - the marker types and variance indicators found in diff --git a/src/doc/book/no-stdlib.md b/src/doc/book/no-stdlib.md index 6fd7cf66920d4..2604ca8d4cab7 100644 --- a/src/doc/book/no-stdlib.md +++ b/src/doc/book/no-stdlib.md @@ -55,7 +55,13 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize { // provided by libstd. #[lang = "eh_personality"] #[no_mangle] -pub extern fn eh_personality() { +pub extern fn rust_eh_personality() { +} + +// This function may be needed based on the compilation target. +#[lang = "eh_unwind_resume"] +#[no_mangle] +pub extern fn rust_eh_unwind_resume() { } #[lang = "panic_fmt"] @@ -87,12 +93,18 @@ pub extern fn main(_argc: i32, _argv: *const *const u8) -> i32 { 0 } -// These functions and traits are used by the compiler, but not +// These functions are used by the compiler, but not // for a bare-bones hello world. These are normally // provided by libstd. #[lang = "eh_personality"] #[no_mangle] -pub extern fn eh_personality() { +pub extern fn rust_eh_personality() { +} + +// This function may be needed based on the compilation target. +#[lang = "eh_unwind_resume"] +#[no_mangle] +pub extern fn rust_eh_unwind_resume() { } #[lang = "panic_fmt"] @@ -104,7 +116,7 @@ pub extern fn rust_begin_panic(_msg: core::fmt::Arguments, } ``` -## More about the langauge items +## More about the language items The compiler currently makes a few assumptions about symbols which are available in the executable to call. Normally these functions are provided by @@ -112,15 +124,20 @@ the standard library, but without it you must define your own. These symbols are called "language items", and they each have an internal name, and then a signature that an implementation must conform to. -The first of these two functions, `eh_personality`, is used by the failure +The first of these functions, `rust_eh_personality`, is used by the failure mechanisms of the compiler. This is often mapped to GCC's personality function (see the [libstd implementation][unwind] for more information), but crates which do not trigger a panic can be assured that this function is never -called. Both the language item and the symbol name are `eh_personality`. - +called. The language item's name is `eh_personality`. + [unwind]: https://github.com/rust-lang/rust/blob/master/src/libpanic_unwind/gcc.rs -The second function, `panic_fmt`, is also used by the failure mechanisms of the +The second function, `rust_begin_panic`, is also used by the failure mechanisms of the compiler. When a panic happens, this controls the message that's displayed on the screen. While the language item's name is `panic_fmt`, the symbol name is `rust_begin_panic`. + +A third function, `rust_eh_unwind_resume`, is also needed if the `custom_unwind_resume` +flag is set in the options of the compilation target. It allows customizing the +process of resuming unwind at the end of the landing pads. The language item's name +is `eh_unwind_resume`. diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index fabb3900ec648..4949e66de54c9 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -42,6 +42,11 @@ //! line. It is up to consumers of this core library to define this panic //! function; it is only required to never return. This requires a `lang` //! attribute named `panic_fmt`. +//! +//! * `rust_eh_personality` - is used by the failure mechanisms of the +//! compiler. This is often mapped to GCC's personality function, but crates +//! which do not trigger a panic can be assured that this function is never +//! called. The `lang` attribute is called `eh_personality`. // Since libcore defines many fundamental lang items, all tests live in a // separate crate, libcoretest, to avoid bizarre issues. From 5286a5a0f84c5fcc697cfb43728751751af1833d Mon Sep 17 00:00:00 2001 From: Yossi Konstantinovsky Date: Sun, 14 Aug 2016 21:57:33 +0300 Subject: [PATCH 5/8] Update E0322 to new format --- src/librustc_typeck/coherence/orphan.rs | 6 ++++-- src/test/compile-fail/coherence-impls-sized.rs | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 15d4026254fa5..e950af5c13389 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -331,8 +331,10 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> { // Disallow *all* explicit impls of `Sized` and `Unsize` for now. if Some(trait_def_id) == self.tcx.lang_items.sized_trait() { - span_err!(self.tcx.sess, item.span, E0322, - "explicit impls for the `Sized` trait are not permitted"); + struct_span_err!(self.tcx.sess, item.span, E0322, + "explicit impls for the `Sized` trait are not permitted") + .span_label(item.span, &format!("impl of 'Sized' not allowed")) + .emit(); return; } if Some(trait_def_id) == self.tcx.lang_items.unsize_trait() { diff --git a/src/test/compile-fail/coherence-impls-sized.rs b/src/test/compile-fail/coherence-impls-sized.rs index 167067cb5fc0a..79767e5157b14 100644 --- a/src/test/compile-fail/coherence-impls-sized.rs +++ b/src/test/compile-fail/coherence-impls-sized.rs @@ -22,12 +22,15 @@ struct NotSync; impl !Sync for NotSync {} impl Sized for TestE {} //~ ERROR E0322 +//~^ impl of 'Sized' not allowed impl Sized for MyType {} //~ ERROR E0322 +//~^ impl of 'Sized' not allowed impl Sized for (MyType, MyType) {} //~ ERROR E0117 impl Sized for &'static NotSync {} //~ ERROR E0322 +//~^ impl of 'Sized' not allowed impl Sized for [MyType] {} //~ ERROR E0117 From a026e2c727312fc47b111cc29e684adec7caf341 Mon Sep 17 00:00:00 2001 From: Alexandre Oliveira Date: Sun, 14 Aug 2016 16:30:50 -0300 Subject: [PATCH 6/8] Update error E0365 to new format --- src/librustc_resolve/resolve_imports.rs | 12 ++++++------ src/test/compile-fail/E0365.rs | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 6986f99926e1e..67588912014ae 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -582,12 +582,12 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { source); self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, directive.span, msg); } else { - let msg = format!("`{}` is private, and cannot be reexported", source); - let note_msg = - format!("consider declaring type or module `{}` with `pub`", source); - struct_span_err!(self.session, directive.span, E0365, "{}", &msg) - .span_note(directive.span, ¬e_msg) - .emit(); + let mut err = struct_span_err!(self.session, directive.span, E0365, + "`{}` is private, and cannot be reexported", + source); + err.span_label(directive.span, &format!("reexport of private `{}`", source)); + err.note(&format!("consider declaring type or module `{}` with `pub`", source)); + err.emit(); } } diff --git a/src/test/compile-fail/E0365.rs b/src/test/compile-fail/E0365.rs index 7b0fbcc6203d7..ea5fd6ed4772f 100644 --- a/src/test/compile-fail/E0365.rs +++ b/src/test/compile-fail/E0365.rs @@ -12,6 +12,9 @@ mod foo { pub const X: u32 = 1; } -pub use foo as foo2; //~ ERROR E0365 +pub use foo as foo2; +//~^ ERROR `foo` is private, and cannot be reexported [E0365] +//~| NOTE reexport of private `foo` +//~| NOTE consider declaring type or module `foo` with `pub` fn main() {} From 6d998d664bb51f6f28f55dba3b68ff6434b3435a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Mon, 15 Aug 2016 00:12:42 +0300 Subject: [PATCH 7/8] Update E0392 to new error format --- src/librustc_typeck/check/wfcheck.rs | 6 ++++-- src/test/compile-fail/E0392.rs | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index e2080906ca242..628cb203ec7d1 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -653,8 +653,10 @@ fn error_380(ccx: &CrateCtxt, span: Span) { fn error_392<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, span: Span, param_name: ast::Name) -> DiagnosticBuilder<'tcx> { - struct_span_err!(ccx.tcx.sess, span, E0392, - "parameter `{}` is never used", param_name) + let mut err = struct_span_err!(ccx.tcx.sess, span, E0392, + "parameter `{}` is never used", param_name); + err.span_label(span, &format!("unused type parameter")); + err } fn error_194(tcx: TyCtxt, span: Span, name: ast::Name) { diff --git a/src/test/compile-fail/E0392.rs b/src/test/compile-fail/E0392.rs index 4c3efcf4e8d75..a21e500e519bb 100644 --- a/src/test/compile-fail/E0392.rs +++ b/src/test/compile-fail/E0392.rs @@ -9,6 +9,7 @@ // except according to those terms. enum Foo { Bar } //~ ERROR E0392 + //~| NOTE unused type parameter fn main() { } From 9e3986188d9c8f2702476a330892f7874055c30f Mon Sep 17 00:00:00 2001 From: Phil Ruffwind Date: Mon, 11 Jul 2016 15:25:12 -0400 Subject: [PATCH 8/8] Fix spacing in code of closures.md The spacing seems inconsistent with existing style conventions. --- src/doc/book/closures.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/book/closures.md b/src/doc/book/closures.md index 1470eac98295e..d332cac7d8d16 100644 --- a/src/doc/book/closures.md +++ b/src/doc/book/closures.md @@ -262,7 +262,7 @@ the result: ```rust fn call_with_one(some_closure: F) -> i32 - where F : Fn(i32) -> i32 { + where F: Fn(i32) -> i32 { some_closure(1) } @@ -279,7 +279,7 @@ Let’s examine the signature of `call_with_one` in more depth: ```rust fn call_with_one(some_closure: F) -> i32 -# where F : Fn(i32) -> i32 { +# where F: Fn(i32) -> i32 { # some_closure(1) } ``` @@ -288,7 +288,7 @@ isn’t interesting. The next part is: ```rust # fn call_with_one(some_closure: F) -> i32 - where F : Fn(i32) -> i32 { + where F: Fn(i32) -> i32 { # some_closure(1) } ```