From 2f5294e1d6ec900f1d650879954016146e5df748 Mon Sep 17 00:00:00 2001 From: Mikhail Modin Date: Fri, 5 Aug 2016 18:57:37 +0300 Subject: [PATCH 01/14] Fixes #35304 --- src/librustc_typeck/collect.rs | 7 ++++--- src/test/compile-fail/impl-duplicate-methods.rs | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index ec95afe15bd51..6429faf35ff80 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -772,9 +772,10 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { let mut err = struct_span_err!(tcx.sess, impl_item.span, E0201, "duplicate definitions with name `{}`:", impl_item.name); - span_note!(&mut err, *entry.get(), - "previous definition of `{}` here", - impl_item.name); + err.span_label(*entry.get(), + &format!("previous definition of `{}` here", + impl_item.name)); + err.span_label(impl_item.span, &format!("duplicate definition")); err.emit(); } Vacant(entry) => { diff --git a/src/test/compile-fail/impl-duplicate-methods.rs b/src/test/compile-fail/impl-duplicate-methods.rs index 981eddc9dd96b..f6e9ab2d614bc 100644 --- a/src/test/compile-fail/impl-duplicate-methods.rs +++ b/src/test/compile-fail/impl-duplicate-methods.rs @@ -12,7 +12,9 @@ struct Foo; impl Foo { fn orange(&self) {} //~ NOTE previous definition of `orange` here - fn orange(&self) {} //~ ERROR duplicate definitions with name `orange` + fn orange(&self) {} + //~^ ERROR duplicate definition + //~| NOTE duplicate definition } fn main() {} From 9f09ee57f9fcd2cfece03985e6c6c234fff02224 Mon Sep 17 00:00:00 2001 From: Yojan Shrestha Date: Thu, 4 Aug 2016 23:21:24 -0500 Subject: [PATCH 02/14] Updates compiler error E0046 with new format --- src/librustc_typeck/check/mod.rs | 7 ++++++- src/test/compile-fail/E0046.rs | 4 +++- src/test/compile-fail/impl-wrong-item-for-trait.rs | 3 +++ src/test/compile-fail/issue-23729.rs | 3 ++- src/test/compile-fail/issue-23827.rs | 3 ++- src/test/compile-fail/issue-24356.rs | 3 ++- 6 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 6062bd048b3d2..2645b78db6cec 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1117,11 +1117,16 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, } if !missing_items.is_empty() { - span_err!(tcx.sess, impl_span, E0046, + struct_span_err!(tcx.sess, impl_span, E0046, "not all trait items implemented, missing: `{}`", missing_items.iter() .map(|name| name.to_string()) .collect::>().join("`, `")) + .span_label(impl_span, &format!("missing `{}` in implementation", + missing_items.iter() + .map(|name| name.to_string()) + .collect::>().join("`, `")) + ).emit(); } if !invalidated_items.is_empty() { diff --git a/src/test/compile-fail/E0046.rs b/src/test/compile-fail/E0046.rs index 63bd0a5ca2858..d2e6c12e1f285 100644 --- a/src/test/compile-fail/E0046.rs +++ b/src/test/compile-fail/E0046.rs @@ -14,7 +14,9 @@ trait Foo { struct Bar; -impl Foo for Bar {} //~ ERROR E0046 +impl Foo for Bar {} +//~^ ERROR E0046 +//~| NOTE missing `foo` in implementation fn main() { } 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 9b3e28cbc01ee..348c6765c1a8f 100644 --- a/src/test/compile-fail/impl-wrong-item-for-trait.rs +++ b/src/test/compile-fail/impl-wrong-item-for-trait.rs @@ -19,6 +19,7 @@ pub struct FooConstForMethod; impl Foo for FooConstForMethod { //~^ ERROR E0046 + //~| NOTE missing `bar` in implementation const bar: u64 = 1; //~^ ERROR E0323 const MY_CONST: u32 = 1; @@ -28,6 +29,7 @@ pub struct FooMethodForConst; impl Foo for FooMethodForConst { //~^ ERROR E0046 + //~| NOTE missing `MY_CONST` in implementation fn bar(&self) {} fn MY_CONST() {} //~^ ERROR E0324 @@ -37,6 +39,7 @@ pub struct FooTypeForMethod; impl Foo for FooTypeForMethod { //~^ ERROR E0046 + //~| NOTE missing `bar` in implementation type bar = u64; //~^ ERROR E0325 const MY_CONST: u32 = 1; diff --git a/src/test/compile-fail/issue-23729.rs b/src/test/compile-fail/issue-23729.rs index f98cf6575d6ec..b1047ce18cccd 100644 --- a/src/test/compile-fail/issue-23729.rs +++ b/src/test/compile-fail/issue-23729.rs @@ -18,7 +18,8 @@ fn main() { } impl Iterator for Recurrence { - //~^ ERROR not all trait items implemented, missing: `Item` [E0046] + //~^ ERROR E0046 + //~| NOTE missing `Item` in implementation #[inline] fn next(&mut self) -> Option { if self.pos < 2 { diff --git a/src/test/compile-fail/issue-23827.rs b/src/test/compile-fail/issue-23827.rs index 6c42c88bee6d0..2062e2373129b 100644 --- a/src/test/compile-fail/issue-23827.rs +++ b/src/test/compile-fail/issue-23827.rs @@ -34,7 +34,8 @@ impl FnMut<(C,)> for Prototype { } impl FnOnce<(C,)> for Prototype { - //~^ ERROR not all trait items implemented, missing: `Output` [E0046] + //~^ ERROR E0046 + //~| NOTE missing `Output` in implementation extern "rust-call" fn call_once(self, (comp,): (C,)) -> Prototype { Fn::call(&self, (comp,)) } diff --git a/src/test/compile-fail/issue-24356.rs b/src/test/compile-fail/issue-24356.rs index ede81bea32ae3..d39fd539dcebc 100644 --- a/src/test/compile-fail/issue-24356.rs +++ b/src/test/compile-fail/issue-24356.rs @@ -28,7 +28,8 @@ fn main() { // Causes ICE impl Deref for Thing { - //~^ ERROR not all trait items implemented, missing: `Target` [E0046] + //~^ ERROR E0046 + //~| NOTE missing `Target` in implementation fn deref(&self) -> i8 { self.0 } } From e5a4a7afcce936ea33f84b83d4e119feb788d3ab Mon Sep 17 00:00:00 2001 From: Yojan Shrestha Date: Thu, 4 Aug 2016 22:46:59 -0500 Subject: [PATCH 03/14] Updates compiler error E0040 with new format --- src/librustc_typeck/check/callee.rs | 4 +++- src/test/compile-fail/E0040.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index bd2c05ba66d47..e73c3aa352b56 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -28,7 +28,9 @@ use rustc::hir; /// method that is called) 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) { - span_err!(ccx.tcx.sess, span, E0040, "explicit use of destructor method"); + struct_span_err!(ccx.tcx.sess, span, E0040, "explicit use of destructor method") + .span_label(span, &format!("call to destructor method")) + .emit(); } } diff --git a/src/test/compile-fail/E0040.rs b/src/test/compile-fail/E0040.rs index f998778a50d66..8c2395eefceaf 100644 --- a/src/test/compile-fail/E0040.rs +++ b/src/test/compile-fail/E0040.rs @@ -20,5 +20,7 @@ impl Drop for Foo { fn main() { let mut x = Foo { x: -7 }; - x.drop(); //~ ERROR E0040 + x.drop(); + //~^ ERROR E0040 + //~| NOTE call to destructor method } From 5bab0e65eb9f8d23dfcb8a3b9d1595f25c9b11b4 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 5 Aug 2016 16:14:11 -0700 Subject: [PATCH 04/14] Update E0206 message to new format --- src/librustc_typeck/coherence/mod.rs | 15 +++++++++++---- src/test/compile-fail/E0206.rs | 10 +++++++--- src/test/compile-fail/coherence-impls-copy.rs | 15 ++++++++++----- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 198e9afd5e12c..333c2a690071a 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -316,10 +316,17 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> { name) } Err(CopyImplementationError::NotAnAdt) => { - span_err!(tcx.sess, span, E0206, - "the trait `Copy` may not be implemented \ - for this type; type is not a structure or \ - enumeration") + let item = tcx.map.expect_item(impl_node_id); + let span = if let ItemImpl(_, _, _, _, ref ty, _) = item.node { + ty.span + } else { + span + }; + + struct_span_err!(tcx.sess, span, E0206, + "the trait `Copy` may not be implemented for this type") + .span_label(span, &format!("type is not a structure or enumeration")) + .emit(); } Err(CopyImplementationError::HasDestructor) => { span_err!(tcx.sess, span, E0184, diff --git a/src/test/compile-fail/E0206.rs b/src/test/compile-fail/E0206.rs index 31b01da3d75b5..6e43812874f2d 100644 --- a/src/test/compile-fail/E0206.rs +++ b/src/test/compile-fail/E0206.rs @@ -10,13 +10,17 @@ type Foo = i32; -impl Copy for Foo { } //~ ERROR E0206 - //~^ ERROR E0117 +impl Copy for Foo { } +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration +//~| ERROR E0117 #[derive(Copy, Clone)] struct Bar; -impl Copy for &'static Bar { } //~ ERROR E0206 +impl Copy for &'static Bar { } +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration fn main() { } diff --git a/src/test/compile-fail/coherence-impls-copy.rs b/src/test/compile-fail/coherence-impls-copy.rs index 9c210c132a313..ec00041a88884 100644 --- a/src/test/compile-fail/coherence-impls-copy.rs +++ b/src/test/compile-fail/coherence-impls-copy.rs @@ -27,22 +27,27 @@ impl Clone for TestE { fn clone(&self) -> Self { *self } } impl Copy for MyType {} impl Copy for &'static mut MyType {} -//~^ ERROR E0206 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration impl Clone for MyType { fn clone(&self) -> Self { *self } } impl Copy for (MyType, MyType) {} -//~^ ERROR E0206 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration //~| ERROR E0117 impl Copy for &'static NotSync {} -//~^ ERROR E0206 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration impl Copy for [MyType] {} -//~^ ERROR E0206 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration //~| ERROR E0117 impl Copy for &'static [NotSync] {} -//~^ ERROR E0206 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration //~| ERROR E0117 fn main() { From 065c685e80930379ada8c4358cdd69c2c99ebb15 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 5 Aug 2016 20:41:25 -0700 Subject: [PATCH 05/14] Update E0223 to the new format --- src/librustc_typeck/astconv.rs | 10 ++++++---- src/test/compile-fail/E0223.rs | 5 ++++- .../associated-types-in-ambiguous-context.rs | 6 ++++++ src/test/compile-fail/issue-34209.rs | 4 +++- src/test/compile-fail/qualified-path-params-2.rs | 8 ++++++-- src/test/compile-fail/self-impl.rs | 8 ++++++-- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index a11df5ae05d6f..953c6b56948cb 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1211,10 +1211,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { type_str: &str, trait_str: &str, name: &str) { - span_err!(self.tcx().sess, span, E0223, - "ambiguous associated type; specify the type using the syntax \ - `<{} as {}>::{}`", - type_str, trait_str, name); + struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type") + .span_label(span, &format!("ambiguous associated type")) + .note(&format!("specify the type using the syntax `<{} as {}>::{}`", + type_str, trait_str, name)) + .emit(); + } // Search for a bound on a type parameter which includes the associated item diff --git a/src/test/compile-fail/E0223.rs b/src/test/compile-fail/E0223.rs index bbf7d762ef00b..56057b372599d 100644 --- a/src/test/compile-fail/E0223.rs +++ b/src/test/compile-fail/E0223.rs @@ -11,5 +11,8 @@ trait MyTrait { type X; } fn main() { - let foo: MyTrait::X; //~ ERROR E0223 + let foo: MyTrait::X; + //~^ ERROR ambiguous associated type + //~| NOTE ambiguous associated type + //~| NOTE specify the type using the syntax `::X` } diff --git a/src/test/compile-fail/associated-types-in-ambiguous-context.rs b/src/test/compile-fail/associated-types-in-ambiguous-context.rs index becbc27138b77..ff886e63dc59e 100644 --- a/src/test/compile-fail/associated-types-in-ambiguous-context.rs +++ b/src/test/compile-fail/associated-types-in-ambiguous-context.rs @@ -15,15 +15,21 @@ trait Get { fn get(x: T, y: U) -> Get::Value {} //~^ ERROR ambiguous associated type +//~| NOTE ambiguous associated type +//~| NOTE specify the type using the syntax `::Value` trait Grab { type Value; fn grab(&self) -> Grab::Value; //~^ ERROR ambiguous associated type + //~| NOTE ambiguous associated type + //~| NOTE specify the type using the syntax `::Value` } type X = std::ops::Deref::Target; //~^ ERROR ambiguous associated type +//~| NOTE ambiguous associated type +//~| NOTE specify the type using the syntax `::Target` fn main() { } diff --git a/src/test/compile-fail/issue-34209.rs b/src/test/compile-fail/issue-34209.rs index 6fae18dec10a6..5e3b777cc0b62 100644 --- a/src/test/compile-fail/issue-34209.rs +++ b/src/test/compile-fail/issue-34209.rs @@ -15,7 +15,9 @@ enum S { fn bug(l: S) { match l { S::B{ } => { }, - //~^ ERROR ambiguous associated type; specify the type using the syntax `::B` + //~^ ERROR ambiguous associated type + //~| NOTE ambiguous associated type + //~| NOTE specify the type using the syntax `::B` } } diff --git a/src/test/compile-fail/qualified-path-params-2.rs b/src/test/compile-fail/qualified-path-params-2.rs index 5c661bfcdc0c9..e685ebc272098 100644 --- a/src/test/compile-fail/qualified-path-params-2.rs +++ b/src/test/compile-fail/qualified-path-params-2.rs @@ -25,7 +25,11 @@ impl S { fn f() {} } -type A = ::A::f; //~ ERROR type parameters are not allowed on this type -//~^ ERROR ambiguous associated type; specify the type using the syntax `<::A as Trait>::f` +type A = ::A::f; +//~^ ERROR type parameters are not allowed on this type +//~| NOTE type parameter not allowed +//~| ERROR ambiguous associated type +//~| NOTE ambiguous associated type +//~| NOTE specify the type using the syntax `<::A as Trait>::f` fn main() {} diff --git a/src/test/compile-fail/self-impl.rs b/src/test/compile-fail/self-impl.rs index d058c6a5a3b93..860e69fcaec4d 100644 --- a/src/test/compile-fail/self-impl.rs +++ b/src/test/compile-fail/self-impl.rs @@ -31,9 +31,13 @@ impl SuperFoo for Bar { impl Bar { fn f() { let _: ::Baz = true; -//~^ERROR: ambiguous associated type; specify the type using the syntax `::Baz` + //~^ ERROR ambiguous associated type + //~| NOTE ambiguous associated type + //~| NOTE specify the type using the syntax `::Baz` let _: Self::Baz = true; -//~^ERROR: ambiguous associated type; specify the type using the syntax `::Baz` + //~^ ERROR ambiguous associated type + //~| NOTE ambiguous associated type + //~| NOTE specify the type using the syntax `::Baz` } } From c9e9d425769274b59734d852a8ae64c9fef16d78 Mon Sep 17 00:00:00 2001 From: silenuss Date: Fri, 5 Aug 2016 20:25:34 -0600 Subject: [PATCH 06/14] Update compiler error 0027 to use new error format. --- src/librustc_typeck/check/_match.rs | 8 +++++--- src/test/compile-fail/E0027.rs | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index aae6e3ad36dfe..47f75e2f4990e 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -700,9 +700,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { for field in variant.fields .iter() .filter(|field| !used_fields.contains_key(&field.name)) { - span_err!(tcx.sess, span, E0027, - "pattern does not mention field `{}`", - field.name); + struct_span_err!(tcx.sess, span, E0027, + "pattern does not mention field `{}`", + field.name) + .span_label(span, &format!("missing field `{}`", field.name)) + .emit(); } } } diff --git a/src/test/compile-fail/E0027.rs b/src/test/compile-fail/E0027.rs index b2f20442b77ad..ca496a24701fb 100644 --- a/src/test/compile-fail/E0027.rs +++ b/src/test/compile-fail/E0027.rs @@ -17,6 +17,8 @@ fn main() { let d = Dog { name: "Rusty".to_string(), age: 8 }; match d { - Dog { age: x } => {} //~ ERROR E0027 + Dog { age: x } => {} + //~^ ERROR pattern does not mention field `name` + //~| NOTE missing field `name` } } From 1d25e2eeccc40cbde2a1ed5be043889c1450cd93 Mon Sep 17 00:00:00 2001 From: silenuss Date: Sat, 6 Aug 2016 00:33:59 -0600 Subject: [PATCH 07/14] Update compiler error 0029 to use new error format. --- src/librustc_typeck/check/_match.rs | 13 ++++++------- src/test/compile-fail/E0029.rs | 6 +++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index aae6e3ad36dfe..82a100f189933 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -93,13 +93,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { end.span }; - // Note: spacing here is intentional, we want a space before "start" and "end". - span_err!(tcx.sess, span, E0029, - "only char and numeric types are allowed in range patterns\n \ - start type: {}\n end type: {}", - self.ty_to_string(lhs_ty), - self.ty_to_string(rhs_ty) - ); + struct_span_err!(tcx.sess, span, E0029, + "only char and numeric types are allowed in range patterns") + .span_label(span, &format!("ranges require char or numeric types")) + .note(&format!("start type: {}", self.ty_to_string(lhs_ty))) + .note(&format!("end type: {}", self.ty_to_string(rhs_ty))) + .emit(); return; } diff --git a/src/test/compile-fail/E0029.rs b/src/test/compile-fail/E0029.rs index 9cbdec9952053..ec84e2a3f8a36 100644 --- a/src/test/compile-fail/E0029.rs +++ b/src/test/compile-fail/E0029.rs @@ -12,7 +12,11 @@ fn main() { let s = "hoho"; match s { - "hello" ... "world" => {} //~ ERROR E0029 + "hello" ... "world" => {} + //~^ ERROR only char and numeric types are allowed in range patterns + //~| NOTE ranges require char or numeric types + //~| NOTE start type: &'static str + //~| NOTE end type: &'static str _ => {} } } From f4dd1f9500e5d5fedc79994b23f9fdf79672ce71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Medzi=C5=84ski?= Date: Fri, 5 Aug 2016 13:06:09 +0200 Subject: [PATCH 08/14] Updated error message E0252 --- src/librustc_resolve/lib.rs | 6 +++++- src/test/compile-fail/double-import.rs | 3 +-- src/test/compile-fail/issue-26886.rs | 2 ++ src/test/compile-fail/use-mod.rs | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index c1511b29c9e01..1c74546a4dc4a 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -3367,7 +3367,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), - (true, true) => struct_span_err!(self.session, span, E0252, "{}", msg), + (true, true) => { + let mut e = struct_span_err!(self.session, span, E0252, "{}", msg); + e.span_label(span, &format!("already imported")); + e + }, _ => { let mut e = struct_span_err!(self.session, span, E0255, "{}", msg); e.span_label(span, &format!("`{}` was already imported", name)); diff --git a/src/test/compile-fail/double-import.rs b/src/test/compile-fail/double-import.rs index 7b915647884f2..bd190a6df8e39 100644 --- a/src/test/compile-fail/double-import.rs +++ b/src/test/compile-fail/double-import.rs @@ -7,8 +7,6 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(no_core)] -#![no_core] // This tests that conflicting imports shows both `use` lines // when reporting the error. @@ -23,5 +21,6 @@ mod sub2 { use sub1::foo; //~ NOTE previous import of `foo` here use sub2::foo; //~ ERROR a value named `foo` has already been imported in this module [E0252] + //~| NOTE already imported fn main() {} diff --git a/src/test/compile-fail/issue-26886.rs b/src/test/compile-fail/issue-26886.rs index c849716f21a37..46e82363c8bd8 100644 --- a/src/test/compile-fail/issue-26886.rs +++ b/src/test/compile-fail/issue-26886.rs @@ -11,7 +11,9 @@ use std::sync::{self, Arc}; //~ NOTE previous import //~^ NOTE previous import use std::sync::Arc; //~ ERROR a type named + //~| NOTE already imported use std::sync; //~ ERROR a module named + //~| NOTE already imported fn main() { } diff --git a/src/test/compile-fail/use-mod.rs b/src/test/compile-fail/use-mod.rs index bbb063770c148..6be878dce1fb9 100644 --- a/src/test/compile-fail/use-mod.rs +++ b/src/test/compile-fail/use-mod.rs @@ -15,7 +15,8 @@ use foo::bar::{ Bar, self //~^ NOTE another `self` import appears here -//~^^ ERROR a module named `bar` has already been imported in this module +//~| ERROR a module named `bar` has already been imported in this module +//~| NOTE already imported }; use {self}; From eb469d60b6bba039b94d55ddf3b44e7f81bf3bda Mon Sep 17 00:00:00 2001 From: Federico Ravasio Date: Sat, 6 Aug 2016 15:29:12 +0200 Subject: [PATCH 09/14] Updated E0225 to new format. --- src/librustc_typeck/astconv.rs | 7 +++++-- src/test/compile-fail/E0225.rs | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index a11df5ae05d6f..749dcc4e1c614 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -2091,8 +2091,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { if !trait_bounds.is_empty() { let b = &trait_bounds[0]; - span_err!(self.tcx().sess, b.trait_ref.path.span, E0225, - "only the builtin traits can be used as closure or object bounds"); + let span = b.trait_ref.path.span; + struct_span_err!(self.tcx().sess, span, E0225, + "only the builtin traits can be used as closure or object bounds") + .span_label(span, &format!("non-builtin trait used as bounds")) + .emit(); } let region_bound = diff --git a/src/test/compile-fail/E0225.rs b/src/test/compile-fail/E0225.rs index 190350c5a5571..b013788ceff85 100644 --- a/src/test/compile-fail/E0225.rs +++ b/src/test/compile-fail/E0225.rs @@ -9,5 +9,7 @@ // except according to those terms. fn main() { - let _: Box; //~ ERROR E0225 + let _: Box; + //~^ ERROR only the builtin traits can be used as closure or object bounds [E0225] + //~| NOTE non-builtin trait used as bounds } From 6eba89e194f6b2990239d7010ab47bfa5a7bd266 Mon Sep 17 00:00:00 2001 From: Oliver Forral Date: Sat, 6 Aug 2016 07:51:53 -0700 Subject: [PATCH 10/14] Fixing compiler error E0121 --- src/librustc_typeck/collect.rs | 9 +++-- .../typeck_type_placeholder_item.rs | 34 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index cb9c0496246d5..7d9cbb2ad41bb 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -367,8 +367,13 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> { _substs: Option<&mut Substs<'tcx>>, _space: Option, span: Span) -> Ty<'tcx> { - span_err!(self.tcx().sess, span, E0121, - "the type placeholder `_` is not allowed within types on item signatures"); + struct_span_err!( + self.tcx().sess, + span, + E0121, + "the type placeholder `_` is not allowed within types on item signatures" + ).span_label(span, &format!("not allowed in type signatures")) + .emit(); self.tcx().types.err } diff --git a/src/test/compile-fail/typeck_type_placeholder_item.rs b/src/test/compile-fail/typeck_type_placeholder_item.rs index d4f3cdfd8b7e2..42db3b47a04f3 100644 --- a/src/test/compile-fail/typeck_type_placeholder_item.rs +++ b/src/test/compile-fail/typeck_type_placeholder_item.rs @@ -13,107 +13,141 @@ fn test() -> _ { 5 } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures fn test2() -> (_, _) { (5, 5) } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures +//~| NOTE not allowed in type signatures static TEST3: _ = "test"; //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures static TEST4: _ = 145; //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures static TEST5: (_, _) = (1, 2); //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures +//~| NOTE not allowed in type signatures fn test6(_: _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures fn test7(x: _) { let _x: usize = x; } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures fn test8(_f: fn() -> _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures struct Test9; impl Test9 { fn test9(&self) -> _ { () } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn test10(&self, _x : _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures } impl Clone for Test9 { fn clone(&self) -> _ { Test9 } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn clone_from(&mut self, other: _) { *self = Test9; } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures } struct Test10 { a: _, //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures b: (_, _), //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures + //~| NOTE not allowed in type signatures } pub fn main() { fn fn_test() -> _ { 5 } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn fn_test2() -> (_, _) { (5, 5) } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures + //~| NOTE not allowed in type signatures static FN_TEST3: _ = "test"; //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures static FN_TEST4: _ = 145; //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures static FN_TEST5: (_, _) = (1, 2); //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures + //~| NOTE not allowed in type signatures fn fn_test6(_: _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn fn_test7(x: _) { let _x: usize = x; } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn fn_test8(_f: fn() -> _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures struct FnTest9; impl FnTest9 { fn fn_test9(&self) -> _ { () } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn fn_test10(&self, _x : _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures } impl Clone for FnTest9 { fn clone(&self) -> _ { FnTest9 } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn clone_from(&mut self, other: _) { *self = FnTest9; } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures } struct FnTest10 { a: _, //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures b: (_, _), //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures + //~| NOTE not allowed in type signatures } } From 95cce86fa921a85ae8bc3f3eaec73007059f9b4c Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 6 Aug 2016 15:16:32 -0400 Subject: [PATCH 11/14] Indicate tracking issue for `exact_size_is_empty` unstability. --- src/libcore/iter/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs index 292d72dd362ad..4cbabe3f5edaf 100644 --- a/src/libcore/iter/traits.rs +++ b/src/libcore/iter/traits.rs @@ -548,7 +548,7 @@ pub trait ExactSizeIterator: Iterator { /// assert_eq!(one_element.next(), None); /// ``` #[inline] - #[unstable(feature = "exact_size_is_empty", issue = "0")] + #[unstable(feature = "exact_size_is_empty", issue = "35428")] fn is_empty(&self) -> bool { self.len() == 0 } From 19e45799a5e3b3b9137cad4a1db94d64dce9ae76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Medzi=C5=84ski?= Date: Fri, 5 Aug 2016 14:29:09 +0200 Subject: [PATCH 12/14] Updated error message E0282 --- src/librustc/traits/error_reporting.rs | 10 ++++++---- src/test/compile-fail/issue-12187-1.rs | 4 +++- src/test/compile-fail/issue-12187-2.rs | 4 +++- src/test/compile-fail/issue-23041.rs | 2 ++ src/test/compile-fail/issue-5062.rs | 2 +- src/test/compile-fail/issue-6458-2.rs | 2 +- src/test/compile-fail/issue-6458-3.rs | 4 +++- src/test/compile-fail/issue-6458-4.rs | 4 +++- src/test/compile-fail/issue-6458.rs | 4 +++- src/test/compile-fail/issue-7813.rs | 4 +++- .../method-ambig-one-trait-unknown-int-type.rs | 2 +- .../traits-multidispatch-convert-ambig-dest.rs | 4 +++- src/test/compile-fail/unconstrained-none.rs | 4 +++- src/test/compile-fail/unconstrained-ref.rs | 4 +++- src/test/compile-fail/vector-no-ann.rs | 4 +++- 15 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 67ad887530eb3..9950560b13a5a 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -870,10 +870,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { fn need_type_info(&self, span: Span, ty: Ty<'tcx>) { - span_err!(self.tcx.sess, span, E0282, - "unable to infer enough type information about `{}`; \ - type annotations or generic parameter binding required", - ty); + let mut err = struct_span_err!(self.tcx.sess, span, E0282, + "unable to infer enough type information about `{}`", + ty); + err.note("type annotations or generic parameter binding required"); + err.span_label(span, &format!("cannot infer type for `{}`", ty)); + err.emit() } fn note_obligation_cause(&self, diff --git a/src/test/compile-fail/issue-12187-1.rs b/src/test/compile-fail/issue-12187-1.rs index 5322966ae2ea0..001e4b51bebc4 100644 --- a/src/test/compile-fail/issue-12187-1.rs +++ b/src/test/compile-fail/issue-12187-1.rs @@ -14,5 +14,7 @@ fn new() -> &'static T { fn main() { let &v = new(); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/compile-fail/issue-12187-2.rs b/src/test/compile-fail/issue-12187-2.rs index dabc0acba370e..7cbee402b3682 100644 --- a/src/test/compile-fail/issue-12187-2.rs +++ b/src/test/compile-fail/issue-12187-2.rs @@ -14,5 +14,7 @@ fn new<'r, T>() -> &'r T { fn main() { let &v = new(); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/compile-fail/issue-23041.rs b/src/test/compile-fail/issue-23041.rs index 1a9bb4c29f3e0..1be082ba9bbba 100644 --- a/src/test/compile-fail/issue-23041.rs +++ b/src/test/compile-fail/issue-23041.rs @@ -14,4 +14,6 @@ fn main() fn bar(x:i32) ->i32 { 3*x }; let b:Box = Box::new(bar as fn(_)->_); b.downcast_ref::_>(); //~ ERROR E0282 + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding required } diff --git a/src/test/compile-fail/issue-5062.rs b/src/test/compile-fail/issue-5062.rs index 392d38a6144f1..f5aa4fadbed88 100644 --- a/src/test/compile-fail/issue-5062.rs +++ b/src/test/compile-fail/issue-5062.rs @@ -9,4 +9,4 @@ // except according to those terms. fn main() { format!("{:?}", None); } - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] diff --git a/src/test/compile-fail/issue-6458-2.rs b/src/test/compile-fail/issue-6458-2.rs index acf1d766b6a11..71f2805457915 100644 --- a/src/test/compile-fail/issue-6458-2.rs +++ b/src/test/compile-fail/issue-6458-2.rs @@ -11,5 +11,5 @@ fn main() { // Unconstrained type: format!("{:?}", None); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] } diff --git a/src/test/compile-fail/issue-6458-3.rs b/src/test/compile-fail/issue-6458-3.rs index 3f81e51efe2ef..e397805565bbd 100644 --- a/src/test/compile-fail/issue-6458-3.rs +++ b/src/test/compile-fail/issue-6458-3.rs @@ -12,5 +12,7 @@ use std::mem; fn main() { mem::transmute(0); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/compile-fail/issue-6458-4.rs b/src/test/compile-fail/issue-6458-4.rs index 7f408be9c02d4..c3f3a718ad0e2 100644 --- a/src/test/compile-fail/issue-6458-4.rs +++ b/src/test/compile-fail/issue-6458-4.rs @@ -10,7 +10,9 @@ fn foo(b: bool) -> Result { Err("bar".to_string()); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } fn main() { diff --git a/src/test/compile-fail/issue-6458.rs b/src/test/compile-fail/issue-6458.rs index c1f9dd6a4b893..a64522a0e5b75 100644 --- a/src/test/compile-fail/issue-6458.rs +++ b/src/test/compile-fail/issue-6458.rs @@ -17,7 +17,9 @@ pub fn foo(_: TypeWithState) {} pub fn bar() { foo(TypeWithState(marker::PhantomData)); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } fn main() { diff --git a/src/test/compile-fail/issue-7813.rs b/src/test/compile-fail/issue-7813.rs index 327fb6adf1d54..e3cb1d0c7daaf 100644 --- a/src/test/compile-fail/issue-7813.rs +++ b/src/test/compile-fail/issue-7813.rs @@ -10,5 +10,7 @@ fn main() { let v = &[]; - let it = v.iter(); //~ ERROR type annotations or generic parameter binding required + let it = v.iter(); //~ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs b/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs index 59d75c5a787a6..4f86909765ef1 100644 --- a/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs +++ b/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs @@ -32,7 +32,7 @@ impl foo for Vec { fn m1() { // we couldn't infer the type of the vector just based on calling foo()... let mut x = Vec::new(); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] x.foo(); } diff --git a/src/test/compile-fail/traits-multidispatch-convert-ambig-dest.rs b/src/test/compile-fail/traits-multidispatch-convert-ambig-dest.rs index c77494912bc75..e6545063dbd44 100644 --- a/src/test/compile-fail/traits-multidispatch-convert-ambig-dest.rs +++ b/src/test/compile-fail/traits-multidispatch-convert-ambig-dest.rs @@ -34,7 +34,9 @@ where T : Convert fn a() { test(22, std::default::Default::default()); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } fn main() {} diff --git a/src/test/compile-fail/unconstrained-none.rs b/src/test/compile-fail/unconstrained-none.rs index c14de98e03f14..380cdd266cd6e 100644 --- a/src/test/compile-fail/unconstrained-none.rs +++ b/src/test/compile-fail/unconstrained-none.rs @@ -11,5 +11,7 @@ // Issue #5062 fn main() { - None; //~ ERROR type annotations or generic parameter binding required + None; //~ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/compile-fail/unconstrained-ref.rs b/src/test/compile-fail/unconstrained-ref.rs index 02a3f2b9ab8d2..ba94bf613d217 100644 --- a/src/test/compile-fail/unconstrained-ref.rs +++ b/src/test/compile-fail/unconstrained-ref.rs @@ -13,5 +13,7 @@ struct S<'a, T:'a> { } fn main() { - S { o: &None }; //~ ERROR type annotations or generic parameter binding required + S { o: &None }; //~ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/compile-fail/vector-no-ann.rs b/src/test/compile-fail/vector-no-ann.rs index 419b8c4e1b015..25709f35246e3 100644 --- a/src/test/compile-fail/vector-no-ann.rs +++ b/src/test/compile-fail/vector-no-ann.rs @@ -11,5 +11,7 @@ fn main() { let _foo = Vec::new(); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } From 0a6b862ccd428e317f1cfc65213fbedc0c4e5e05 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 6 Aug 2016 17:50:37 -0400 Subject: [PATCH 13/14] Add doc example for `std::ffi::NulError::into_vec`. --- src/libstd/ffi/c_str.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index f800a6e228e9b..e0501f9cc61d2 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -373,6 +373,15 @@ impl NulError { /// Consumes this error, returning the underlying vector of bytes which /// generated the error in the first place. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let nul_error = CString::new("foo\0bar").unwrap_err(); + /// assert_eq!(nul_error.into_vec(), b"foo\0bar"); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn into_vec(self) -> Vec { self.1 } } From 5e06da29a73bba354903ba7dc1eddf3434ac112e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Hlusi=C4=8Dka?= Date: Sun, 7 Aug 2016 00:09:54 +0200 Subject: [PATCH 14/14] E0131 updated to new format --- src/librustc_typeck/lib.rs | 14 +++++++++----- src/test/compile-fail/E0131.rs | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 6f0892cdcdf16..65e00705121a7 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -211,11 +211,15 @@ fn check_main_fn_ty(ccx: &CrateCtxt, match tcx.map.find(main_id) { Some(hir_map::NodeItem(it)) => { match it.node { - hir::ItemFn(_, _, _, _, ref ps, _) - if ps.is_parameterized() => { - span_err!(ccx.tcx.sess, main_span, E0131, - "main function is not allowed to have type parameters"); - return; + hir::ItemFn(_, _, _, _, ref generics, _) => { + if let Some(gen_span) = generics.span() { + struct_span_err!(ccx.tcx.sess, gen_span, E0131, + "main function is not allowed to have type parameters") + .span_label(gen_span, + &format!("main cannot have type parameters")) + .emit(); + return; + } } _ => () } diff --git a/src/test/compile-fail/E0131.rs b/src/test/compile-fail/E0131.rs index aa11577ccdf1e..e6e924e2d966f 100644 --- a/src/test/compile-fail/E0131.rs +++ b/src/test/compile-fail/E0131.rs @@ -8,5 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn main() { //~ ERROR E0131 +fn main() { + //~^ ERROR E0131 + //~| NOTE main cannot have type parameters }