From 2683e8494c265a986c76e2613e3f33052f8b58f0 Mon Sep 17 00:00:00 2001 From: Michael Gattozzi Date: Thu, 4 Aug 2016 18:07:29 -0400 Subject: [PATCH 01/18] Update HashMap docs regarding DoS protection Because of changes to how Rust acquires randomness HashMap is not guaranteed to be DoS resistant. This commit reflects these changes in the docs themselves and provides an alternative method to creating a hash that is resistant if needed. --- src/libstd/collections/hash/map.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index fd7b0a2e6bb..8039421ae77 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -199,13 +199,12 @@ fn test_resize_policy() { /// A hash map implementation which uses linear probing with Robin /// Hood bucket stealing. /// -/// The hashes are all keyed by the thread-local random number generator -/// on creation by default. This means that the ordering of the keys is -/// randomized, but makes the tables more resistant to -/// denial-of-service attacks (Hash DoS). No guarantees are made to the -/// quality of the random data. The implementation uses the best available -/// random data from your platform at the time of creation. This behavior -/// can be overridden with one of the constructors. +/// By default, HashMap uses a somewhat slow hashing algorithm which can provide resistance +/// to DoS attacks. Rust makes a best attempt at acquiring random numbers without IO +/// blocking from your system. Because of this HashMap is not guaranteed to provide +/// DoS resistance since the numbers generated might not be truly random. If you do +/// require this behavior you can create your own hashing function using +/// [BuildHasherDefault](../hash/struct.BuildHasherDefault.html). /// /// It is required that the keys implement the `Eq` and `Hash` traits, although /// this can frequently be achieved by using `#[derive(PartialEq, Eq, Hash)]`. From b79e15d32c4cd14b4428d1b05a16a7d2234490cc Mon Sep 17 00:00:00 2001 From: "Panashe M. Fundira" Date: Fri, 5 Aug 2016 17:20:47 -0400 Subject: [PATCH 02/18] 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 3b2bca4ab39..388f2fb53e6 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 489ebb033f8..dcfe441ab0d 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 2b34fcab24c..007f1d3a294 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 03/18] 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 aae6e3ad36d..cb1e8aef736 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 05f126baf9a..c3623e3177b 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 7c1bb9ae0d76ef0abdb1db34fc2a5e7d62fdf912 Mon Sep 17 00:00:00 2001 From: ubsan Date: Sat, 6 Aug 2016 23:57:18 -0700 Subject: [PATCH 04/18] Finish fixing the operator precedence tables Add the unstable `:` colon and `<-` inplace operators. --- src/doc/reference.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index f4ffe5774d2..f0ab1488d40 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3039,7 +3039,7 @@ The precedence of Rust binary operators is ordered as follows, going from strong to weak: ```{.text .precedence} -as +as : * / % + - << >> @@ -3050,6 +3050,7 @@ as && || .. ... +<- = ``` From 56eba5a446d2c61f6e185fda60c84b1a6ab68051 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 7 Aug 2016 13:55:08 +0200 Subject: [PATCH 05/18] Add run-pass test for issue 33498 --- src/test/run-pass/issue-33498.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/test/run-pass/issue-33498.rs diff --git a/src/test/run-pass/issue-33498.rs b/src/test/run-pass/issue-33498.rs new file mode 100644 index 00000000000..9b4e1918bae --- /dev/null +++ b/src/test/run-pass/issue-33498.rs @@ -0,0 +1,19 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub fn main() { + let x = (0, 2); + + match x { + (0, ref y) => {} + (y, 0) => {} + _ => (), + } +} From 98c6770a231d9bbaede40bbcf659218995958d6a Mon Sep 17 00:00:00 2001 From: "Novotnik, Petr" Date: Sun, 7 Aug 2016 17:44:47 +0200 Subject: [PATCH 06/18] 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 67fe8ba2c11..fcb7e0bc7ea 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 07/18] 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 50ffa52e88b..3fcd5395413 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 59609345ee5..e9c3cb72c11 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 08/18] 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 fdfd41a456b..25568a323e1 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 09/18] 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 50ffa52e88b..deba31db5df 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 8b111a7cf5dac2e592bdec013d8de3e06dcf19d3 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 7 Aug 2016 00:29:24 -0500 Subject: [PATCH 10/18] Updated E0087 to new format --- src/librustc_typeck/check/mod.rs | 19 +++++++++++-------- src/test/compile-fail/E0087.rs | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 8da06120873..2e05231f9fc 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4367,14 +4367,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if i < type_count { substs.types.push(space, t); } else if i == type_count { - span_err!(self.tcx.sess, typ.span, E0087, - "too many type parameters provided: \ - expected at most {} parameter{}, \ - found {} parameter{}", - type_count, - if type_count == 1 {""} else {"s"}, - data.types.len(), - if data.types.len() == 1 {""} else {"s"}); + struct_span_err!(self.tcx.sess, typ.span, E0087, + "too many type parameters provided: \ + expected at most {} parameter{}, \ + found {} parameter{}", + type_count, + if type_count == 1 {""} else {"s"}, + data.types.len(), + if data.types.len() == 1 {""} else {"s"}) + .span_label(typ.span , &format!("expected {} parameter{}", + type_count, + if type_count == 1 {""} else {"s"})).emit(); substs.types.truncate(space, 0); break; } diff --git a/src/test/compile-fail/E0087.rs b/src/test/compile-fail/E0087.rs index ec559fc8389..63115f093c3 100644 --- a/src/test/compile-fail/E0087.rs +++ b/src/test/compile-fail/E0087.rs @@ -12,4 +12,5 @@ fn foo() {} fn main() { foo::(); //~ ERROR E0087 + //~^ NOTE expected } From e40df1c88f0c3630df70c040ea9b9afc8ce05c5c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 7 Aug 2016 23:52:43 +0200 Subject: [PATCH 11/18] Fix E0132 error display --- src/librustc_typeck/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 6f0892cdcdf..0fc23995a5e 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -261,9 +261,10 @@ fn check_start_fn_ty(ccx: &CrateCtxt, match it.node { hir::ItemFn(_,_,_,_,ref ps,_) if ps.is_parameterized() => { - struct_span_err!(tcx.sess, start_span, E0132, + let sp = if let Some(sp) = ps.span() { sp } else { start_span }; + struct_span_err!(tcx.sess, sp, E0132, "start function is not allowed to have type parameters") - .span_label(ps.span().unwrap(), + .span_label(sp, &format!("start function cannot have type parameters")) .emit(); return; From c6e17ec2769cf8c67b71451e84cfa49a4f247103 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Sun, 7 Aug 2016 21:34:51 -0700 Subject: [PATCH 12/18] Shrink E0205 span label to the trait being implemented --- src/librustc_typeck/coherence/mod.rs | 19 ++++++++++++------- src/test/compile-fail/E0205.rs | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 939d81bf847..f0ab1984286 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -321,13 +321,18 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> { } Err(CopyImplementationError::InfrigingVariant(name)) => { - struct_span_err!(tcx.sess, span, E0205, - "the trait `Copy` may not be \ - implemented for this type") - .span_label(span, &format!("variant \ - `{}` does not implement `Copy`", - name)) - .emit() + let item = tcx.map.expect_item(impl_node_id); + let span = if let ItemImpl(_, _, _, Some(ref tr), _, _) = item.node { + tr.path.span + } else { + span + }; + + struct_span_err!(tcx.sess, span, E0205, + "the trait `Copy` may not be implemented for this type") + .span_label(span, &format!("variant `{}` does not implement `Copy`", + name)) + .emit() } Err(CopyImplementationError::NotAnAdt) => { span_err!(tcx.sess, span, E0206, diff --git a/src/test/compile-fail/E0205.rs b/src/test/compile-fail/E0205.rs index 37ac57af524..c73e7534301 100644 --- a/src/test/compile-fail/E0205.rs +++ b/src/test/compile-fail/E0205.rs @@ -14,11 +14,11 @@ enum Foo { } impl Copy for Foo { } -//~^ ERROR E0205 +//~^ ERROR the trait `Copy` may not be implemented for this type //~| NOTE variant `Bar` does not implement `Copy` #[derive(Copy)] -//~^ ERROR E0205 +//~^ ERROR the trait `Copy` may not be implemented for this type //~| NOTE variant `Bar` does not implement `Copy` //~| NOTE in this expansion of #[derive(Copy)] enum Foo2<'a> { From 18565c63db1982b927b291b9597368efc615d91c Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Sun, 7 Aug 2016 10:14:01 -0500 Subject: [PATCH 13/18] book: update example patterns to be more clear When using Point { x: 0, y: 0 } and showing pattern matching decomposing x and y individually its hard to understand. By using a different value for x and a different value for y it is more clear. --- src/doc/book/patterns.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/doc/book/patterns.md b/src/doc/book/patterns.md index a0245d4c7b1..910b1375476 100644 --- a/src/doc/book/patterns.md +++ b/src/doc/book/patterns.md @@ -109,14 +109,14 @@ struct Point { y: i32, } -let origin = Point { x: 0, y: 0 }; +let point = Point { x: 2, y: 3 }; -match origin { +match point { Point { x, .. } => println!("x is {}", x), } ``` -This prints `x is 0`. +This prints `x is 2`. You can do this kind of match on any member, not only the first: @@ -126,14 +126,14 @@ struct Point { y: i32, } -let origin = Point { x: 0, y: 0 }; +let point = Point { x: 2, y: 3 }; -match origin { +match point { Point { y, .. } => println!("y is {}", y), } ``` -This prints `y is 0`. +This prints `y is 3`. This ‘destructuring’ behavior works on any compound data type, like [tuples][tuples] or [enums][enums]. From a403ddf36dba3d3413c5a18268f357a6eee989ab Mon Sep 17 00:00:00 2001 From: hank-der-hafenarbeiter Date: Mon, 8 Aug 2016 18:42:07 +0200 Subject: [PATCH 14/18] Updated E0221 message to new format! --- src/librustc_typeck/astconv.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index b4e9fb5c65b..eaed2ac22c4 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1281,10 +1281,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { } if bounds.len() > 1 { - let mut err = struct_span_err!(self.tcx().sess, span, E0221, - "ambiguous associated type `{}` in bounds of `{}`", - assoc_name, - ty_param_name); + let mut err = struct_span_err!( + self.tcx().sess, span, E0221, + "ambiguous associated type `{}` in bounds of `{}`", + assoc_name, + ty_param_name); + err.span_label(span, &format!("ambiguous associated type `{}`", assoc_name)); for bound in &bounds { span_note!(&mut err, span, From 6eb0218075aa0bfcfd96c6872b30b64dbde1a8d6 Mon Sep 17 00:00:00 2001 From: hank-der-hafenarbeiter Date: Mon, 8 Aug 2016 19:14:03 +0200 Subject: [PATCH 15/18] updated unit test! --- .../associated-type-projection-from-multiple-supertraits.rs | 3 +++ 1 file changed, 3 insertions(+) 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 2b34fcab24c..b311683b32e 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 @@ -28,6 +28,7 @@ pub trait BoxCar : Box + Vehicle { fn dent(c: C, color: C::Color) { //~^ ERROR ambiguous associated type `Color` in bounds of `C` + //~| NOTE ambiguous associated type `Color` //~| NOTE could derive from `Vehicle` //~| NOTE could derive from `Box` } @@ -35,12 +36,14 @@ fn dent(c: C, color: C::Color) { fn dent_object(c: BoxCar) { //~^ ERROR ambiguous associated type //~| ERROR the value of the associated type `Color` (from the trait `Vehicle`) must be specified + //~| NOTE ambiguous associated type `Color` //~| NOTE could derive from `Vehicle` //~| NOTE could derive from `Box` } fn paint(c: C, d: C::Color) { //~^ ERROR ambiguous associated type `Color` in bounds of `C` + //~| NOTE ambiguous associated type `Color` //~| NOTE could derive from `Vehicle` //~| NOTE could derive from `Box` } From ee38609c2044ad7a497b52e3169fe755f4566440 Mon Sep 17 00:00:00 2001 From: Federico Ravasio Date: Mon, 8 Aug 2016 20:58:21 +0200 Subject: [PATCH 16/18] Updated E0026 to new format. --- src/librustc_typeck/check/_match.rs | 14 ++++++++++---- src/test/compile-fail/E0026.rs | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index fe68690d4e9..9f9b8aed6bd 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -682,10 +682,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { field_map.get(&field.name) .map(|f| self.field_ty(span, f, substs)) .unwrap_or_else(|| { - span_err!(tcx.sess, span, E0026, - "struct `{}` does not have a field named `{}`", - tcx.item_path_str(variant.did), - field.name); + struct_span_err!(tcx.sess, span, E0026, + "struct `{}` does not have a field named `{}`", + tcx.item_path_str(variant.did), + field.name) + .span_label(span, + &format!("struct `{}` does not have field `{}`", + tcx.item_path_str(variant.did), + field.name)) + .emit(); + tcx.types.err }) } diff --git a/src/test/compile-fail/E0026.rs b/src/test/compile-fail/E0026.rs index 359c2a822a2..ac609da4cbd 100644 --- a/src/test/compile-fail/E0026.rs +++ b/src/test/compile-fail/E0026.rs @@ -16,6 +16,8 @@ struct Thing { fn main() { let thing = Thing { x: 0, y: 0 }; match thing { - Thing { x, y, z } => {} //~ ERROR E0026 + Thing { x, y, z } => {} + //~^ ERROR struct `Thing` does not have a field named `z` [E0026] + //~| NOTE struct `Thing` does not have field `z` } } From daf7c60d16bad5979cb5c7fa951214282ea67565 Mon Sep 17 00:00:00 2001 From: Krzysztof Garczynski Date: Mon, 8 Aug 2016 21:42:49 +0200 Subject: [PATCH 17/18] Update E0162 to the new format --- src/librustc_const_eval/check_match.rs | 5 ++++- src/test/compile-fail/E0162.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index 599e3ec871a..366b58e06c4 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -316,7 +316,10 @@ fn check_arms(cx: &MatchCheckCtxt, let &(ref first_arm_pats, _) = &arms[0]; let first_pat = &first_arm_pats[0]; let span = first_pat.span; - span_err!(cx.tcx.sess, span, E0162, "irrefutable if-let pattern"); + struct_span_err!(cx.tcx.sess, span, E0162, + "irrefutable if-let pattern") + .span_label(span, &format!("irrefutable pattern")) + .emit(); printed_if_let_err = true; } }, diff --git a/src/test/compile-fail/E0162.rs b/src/test/compile-fail/E0162.rs index e13b0af6f79..0b63d7c3f85 100644 --- a/src/test/compile-fail/E0162.rs +++ b/src/test/compile-fail/E0162.rs @@ -13,6 +13,7 @@ struct Irrefutable(i32); fn main() { let irr = Irrefutable(0); if let Irrefutable(x) = irr { //~ ERROR E0162 + //~| NOTE irrefutable pattern println!("{}", x); } } From fb1c6acc81c3dfb9b4ae3b9747f24d503658c23f Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Tue, 9 Aug 2016 07:53:52 -0700 Subject: [PATCH 18/18] Update E0087.rs --- src/test/compile-fail/E0087.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/compile-fail/E0087.rs b/src/test/compile-fail/E0087.rs index 63115f093c3..437ad3698a2 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 expected }