From b79e15d32c4cd14b4428d1b05a16a7d2234490cc Mon Sep 17 00:00:00 2001 From: "Panashe M. Fundira" Date: Fri, 5 Aug 2016 17:20:47 -0400 Subject: [PATCH 1/7] Update E0191 to the new error format --- src/librustc_typeck/astconv.rs | 7 +++++-- src/test/compile-fail/E0191.rs | 1 + ...associated-type-projection-from-multiple-supertraits.rs | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 3b2bca4ab3912..388f2fb53e651 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1194,10 +1194,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { } for (trait_def_id, name) in associated_types { - span_err!(tcx.sess, span, E0191, + struct_span_err!(tcx.sess, span, E0191, "the value of the associated type `{}` (from the trait `{}`) must be specified", name, - tcx.item_path_str(trait_def_id)); + tcx.item_path_str(trait_def_id)) + .span_label(span, &format!( + "missing associated type `{}` value", name)) + .emit(); } tcx.mk_trait(object.principal, object.bounds) diff --git a/src/test/compile-fail/E0191.rs b/src/test/compile-fail/E0191.rs index 489ebb033f84e..dcfe441ab0d00 100644 --- a/src/test/compile-fail/E0191.rs +++ b/src/test/compile-fail/E0191.rs @@ -13,6 +13,7 @@ trait Trait { } type Foo = Trait; //~ ERROR E0191 + //~| NOTE missing associated type `Bar` value fn main() { } diff --git a/src/test/compile-fail/associated-type-projection-from-multiple-supertraits.rs b/src/test/compile-fail/associated-type-projection-from-multiple-supertraits.rs index 2b34fcab24c04..007f1d3a2947d 100644 --- a/src/test/compile-fail/associated-type-projection-from-multiple-supertraits.rs +++ b/src/test/compile-fail/associated-type-projection-from-multiple-supertraits.rs @@ -37,6 +37,7 @@ fn dent_object(c: BoxCar) { //~| ERROR the value of the associated type `Color` (from the trait `Vehicle`) must be specified //~| NOTE could derive from `Vehicle` //~| NOTE could derive from `Box` + //~| NOTE missing associated type `Color` value } fn paint(c: C, d: C::Color) { From 2c563c69f40a140e82e2d653bafd9e4f88621f30 Mon Sep 17 00:00:00 2001 From: "Peter C. Norton" Date: Sun, 7 Aug 2016 00:26:31 -0400 Subject: [PATCH 2/7] Update E0023 to the new format Added some extra code to check for the appropriate ending for numbers == 1 vs. not 1 in error messages. Added an extra test so that the plural suffix is seen and exercised. --- src/librustc_typeck/check/_match.rs | 21 +++++++++++++++++---- src/test/compile-fail/E0023.rs | 5 +++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index aae6e3ad36dfe..cb1e8aef736d7 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -634,10 +634,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.check_pat(&subpat, field_ty); } } else { - span_err!(tcx.sess, pat.span, E0023, - "this pattern has {} field{s}, but the corresponding {} has {} field{s}", - subpats.len(), def.kind_name(), variant.fields.len(), - s = if variant.fields.len() == 1 {""} else {"s"}); + let subpats_ending = if subpats.len() == 1 { + "" + } else { + "s" + }; + let fields_ending = if variant.fields.len() == 1 { + "" + } else { + "s" + }; + struct_span_err!(tcx.sess, pat.span, E0023, + "this pattern has {} field{}, but the corresponding {} has {} field{}", + subpats.len(), subpats_ending, def.kind_name(), + variant.fields.len(), fields_ending) + .span_label(pat.span, &format!("expected {} field{}, found {}", + variant.fields.len(), fields_ending, subpats.len())) + .emit(); on_error(); } } diff --git a/src/test/compile-fail/E0023.rs b/src/test/compile-fail/E0023.rs index 05f126baf9a70..c3623e3177b56 100644 --- a/src/test/compile-fail/E0023.rs +++ b/src/test/compile-fail/E0023.rs @@ -13,10 +13,15 @@ enum Fruit { Pear(u32), } + fn main() { let x = Fruit::Apple(String::new(), String::new()); match x { Fruit::Apple(a) => {}, //~ ERROR E0023 + //~| NOTE expected 2 fields, found 1 Fruit::Apple(a, b, c) => {}, //~ ERROR E0023 + //~| NOTE expected 2 fields, found 3 + Fruit::Pear(1, 2) => {}, //~ ERROR E0023 + //~| NOTE expected 1 field, found 2 } } From 98c6770a231d9bbaede40bbcf659218995958d6a Mon Sep 17 00:00:00 2001 From: "Novotnik, Petr" Date: Sun, 7 Aug 2016 17:44:47 +0200 Subject: [PATCH 3/7] Fix formatting of module layout example --- src/doc/book/crates-and-modules.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/book/crates-and-modules.md b/src/doc/book/crates-and-modules.md index 67fe8ba2c11a4..fcb7e0bc7eacd 100644 --- a/src/doc/book/crates-and-modules.md +++ b/src/doc/book/crates-and-modules.md @@ -22,6 +22,7 @@ As an example, let’s make a *phrases* crate, which will give us various phrase in different languages. To keep things simple, we’ll stick to ‘greetings’ and ‘farewells’ as two kinds of phrases, and use English and Japanese (日本語) as two languages for those phrases to be in. We’ll use this module layout: + ```text +-----------+ +---| greetings | From f07f09352222c16f11cfd49aab4f83706ea3549e Mon Sep 17 00:00:00 2001 From: "Panashe M. Fundira" Date: Sun, 7 Aug 2016 13:21:23 -0400 Subject: [PATCH 4/7] Update E0214 to the new error format --- src/librustc_typeck/astconv.rs | 7 +++++-- src/test/compile-fail/E0214.rs | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 50ffa52e88ba4..3fcd53954137d 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -360,8 +360,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { self.convert_angle_bracketed_parameters(rscope, span, decl_generics, data) } hir::ParenthesizedParameters(..) => { - span_err!(tcx.sess, span, E0214, - "parenthesized parameters may only be used with a trait"); + struct_span_err!(tcx.sess, span, E0214, + "parenthesized parameters may only be used with a trait") + .span_label(span, &format!("only traits may use parentheses")) + .emit(); + let ty_param_defs = decl_generics.types.get_slice(TypeSpace); (Substs::empty(), ty_param_defs.iter().map(|_| tcx.types.err).collect(), diff --git a/src/test/compile-fail/E0214.rs b/src/test/compile-fail/E0214.rs index 59609345ee523..e9c3cb72c11b0 100644 --- a/src/test/compile-fail/E0214.rs +++ b/src/test/compile-fail/E0214.rs @@ -9,5 +9,7 @@ // except according to those terms. fn main() { - let v: Vec(&str) = vec!["foo"]; //~ ERROR E0214 + let v: Vec(&str) = vec!["foo"]; + //~^ ERROR E0214 + //~| NOTE only traits may use parentheses } From 4a99a9de034d27eabad833a6bf0904dcaab34dc7 Mon Sep 17 00:00:00 2001 From: ShyamSundarB Date: Mon, 8 Aug 2016 00:12:53 +0530 Subject: [PATCH 5/7] E0248 Change in issue format --- src/test/compile-fail/E0248.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/compile-fail/E0248.rs b/src/test/compile-fail/E0248.rs index fdfd41a456bf6..25568a323e161 100644 --- a/src/test/compile-fail/E0248.rs +++ b/src/test/compile-fail/E0248.rs @@ -13,6 +13,6 @@ enum Foo { } fn do_something(x: Foo::Bar) { } //~ ERROR E0248 - + //~| NOTE value used as a type fn main() { } From a848f11007e7cd44f816acb8128247d5d7a1359e Mon Sep 17 00:00:00 2001 From: ShyamSundarB Date: Mon, 8 Aug 2016 00:15:36 +0530 Subject: [PATCH 6/7] E0248 Change in issue format --- src/librustc_typeck/astconv.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 50ffa52e88ba4..deba31db5dfcf 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1582,9 +1582,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { return self.tcx().types.err; } _ => { - span_err!(tcx.sess, span, E0248, - "found value `{}` used as a type", - tcx.item_path_str(def.def_id())); + struct_span_err!(tcx.sess, span, E0248, + "found value `{}` used as a type", + tcx.item_path_str(def.def_id())) + .span_label(span, &format!("value used as a type")) + .emit(); return self.tcx().types.err; } } From 413c321e5f1ab199f2115d627d53915ba9703245 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 5 Aug 2016 16:14:11 -0700 Subject: [PATCH 7/7] 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 2d14b0dacf24c..f11adfc9c5ca0 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -325,10 +325,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() {