From 368ac73c11662dbb860db178dc170768078b282d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 22 Dec 2019 18:33:14 +0100 Subject: [PATCH 01/14] no longer promote non-pattern const functions --- src/libcore/time.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index c1d405239f96f..2ece2150e6bed 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -172,7 +172,6 @@ impl Duration { /// ``` #[stable(feature = "duration", since = "1.3.0")] #[inline] - #[rustc_promotable] #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] pub const fn from_millis(millis: u64) -> Duration { Duration { @@ -195,7 +194,6 @@ impl Duration { /// ``` #[stable(feature = "duration_from_micros", since = "1.27.0")] #[inline] - #[rustc_promotable] #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] pub const fn from_micros(micros: u64) -> Duration { Duration { @@ -218,7 +216,6 @@ impl Duration { /// ``` #[stable(feature = "duration_extras", since = "1.27.0")] #[inline] - #[rustc_promotable] #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] pub const fn from_nanos(nanos: u64) -> Duration { Duration { From 8d189ed2f1db856adc9745099d078d46fe54a087 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Sat, 30 Nov 2019 18:59:51 +0100 Subject: [PATCH 02/14] Suggest calling method when first argument is `self` --- src/doc/rustc-guide | 2 +- src/librustc_resolve/build_reduced_graph.rs | 10 +++---- src/librustc_resolve/late.rs | 2 +- src/librustc_resolve/late/diagnostics.rs | 31 +++++++++++++++++++++ src/test/ui/self/suggest-self-2.rs | 22 +++++++++++++++ src/test/ui/self/suggest-self-2.stderr | 28 +++++++++++++++++++ 6 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 src/test/ui/self/suggest-self-2.rs create mode 100644 src/test/ui/self/suggest-self-2.stderr diff --git a/src/doc/rustc-guide b/src/doc/rustc-guide index 7c56708aab798..934380b7cfcea 160000 --- a/src/doc/rustc-guide +++ b/src/doc/rustc-guide @@ -1 +1 @@ -Subproject commit 7c56708aab7986ca390221e8e8902f7de7f9b076 +Subproject commit 934380b7cfceaaa4e1b9bb0de4a372f32725520b diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index fed4202d96103..c356a7e31b177 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -759,8 +759,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { // These items live in both the type and value namespaces. ItemKind::Struct(ref vdata, _) => { // Define a name in the type namespace. - let def_id = self.r.definitions.local_def_id(item.id); - let res = Res::Def(DefKind::Struct, def_id); + let item_def_id = self.r.definitions.local_def_id(item.id); + let res = Res::Def(DefKind::Struct, item_def_id); self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion)); // Record field names for error reporting. @@ -798,12 +798,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { } ItemKind::Union(ref vdata, _) => { - let def_id = self.r.definitions.local_def_id(item.id); - let res = Res::Def(DefKind::Union, def_id); + let item_def_id = self.r.definitions.local_def_id(item.id); + let res = Res::Def(DefKind::Union, item_def_id); self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion)); // Record field names for error reporting. - self.insert_field_names_local(def_id, vdata); + self.insert_field_names_local(item_def_id, vdata); } ItemKind::Trait(..) => { diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 898ab6ae32211..dd1bef0c297a9 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -345,7 +345,7 @@ struct DiagnosticMetadata { /// The current self item if inside an ADT (used for better errors). current_self_item: Option, - /// The current enclosing funciton (used for better errors). + /// The current enclosing function (used for better errors). current_function: Option, /// A list of labels as of yet unused. Labels will be removed from this map when diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 6fb5c2f2de31f..e40c6fa708888 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -259,6 +259,37 @@ impl<'a> LateResolutionVisitor<'a, '_> { } return (err, candidates); } + + // Check if the first argument is `self` and suggest calling a method. + let mut has_self_arg = false; + if let PathSource::Expr(parent) = source { + match &parent.map(|p| &p.kind) { + Some(ExprKind::Call(_, args)) if args.len() > 0 => { + let mut expr_kind = &args.first().unwrap().kind; + loop { + match expr_kind { + ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => { + has_self_arg = arg_name.segments[0].ident.name == kw::SelfLower; + break; + }, + ExprKind::AddrOf(_, _, expr) => { expr_kind = &expr.kind; } + _ => break, + } + } + } + _ => (), + } + }; + + if has_self_arg { + err.span_suggestion( + span, + &"try calling method instead of passing `self` as parameter", + format!("self.{}", path_str), + Applicability::MachineApplicable, + ); + return (err, candidates); + } } // Try Levenshtein algorithm. diff --git a/src/test/ui/self/suggest-self-2.rs b/src/test/ui/self/suggest-self-2.rs new file mode 100644 index 0000000000000..1926ebe4b8317 --- /dev/null +++ b/src/test/ui/self/suggest-self-2.rs @@ -0,0 +1,22 @@ +struct Foo {} + +impl Foo { + fn foo(&self) { + bar(self); + //~^ ERROR cannot find function `bar` in this scope + //~| HELP try calling method instead of passing `self` as parameter + + + bar(&self); + //~^ ERROR cannot find function `bar` in this scope + //~| HELP try calling method instead of passing `self` as parameter + + bar(); + //~^ ERROR cannot find function `bar` in this scope + + self.bar(); + //~^ ERROR no method named `bar` found for type + } +} + +fn main() {} diff --git a/src/test/ui/self/suggest-self-2.stderr b/src/test/ui/self/suggest-self-2.stderr new file mode 100644 index 0000000000000..84dbaa9637898 --- /dev/null +++ b/src/test/ui/self/suggest-self-2.stderr @@ -0,0 +1,28 @@ +error[E0425]: cannot find function `bar` in this scope + --> $DIR/suggest-self-2.rs:5:9 + | +LL | bar(self); + | ^^^ help: try calling method instead of passing `self` as parameter: `self.bar` + +error[E0425]: cannot find function `bar` in this scope + --> $DIR/suggest-self-2.rs:10:9 + | +LL | bar(&self); + | ^^^ help: try calling method instead of passing `self` as parameter: `self.bar` + +error[E0425]: cannot find function `bar` in this scope + --> $DIR/suggest-self-2.rs:14:9 + | +LL | bar(); + | ^^^ not found in this scope + +error[E0599]: no method named `bar` found for type `&Foo` in the current scope + --> $DIR/suggest-self-2.rs:17:14 + | +LL | self.bar(); + | ^^^ method not found in `&Foo` + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0425, E0599. +For more information about an error, try `rustc --explain E0425`. From 8e5b2c80d3f30c9d83a8e921e78e6c10e54c8319 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Mon, 9 Dec 2019 16:05:45 +0100 Subject: [PATCH 03/14] Add more detailed suggestion --- src/doc/rustc-guide | 2 +- src/librustc_resolve/build_reduced_graph.rs | 10 +++++----- src/librustc_resolve/late/diagnostics.rs | 6 +++--- src/test/ui/self/suggest-self-2.rs | 9 ++++++--- src/test/ui/self/suggest-self-2.stderr | 20 +++++++++++++------- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/doc/rustc-guide b/src/doc/rustc-guide index 934380b7cfcea..7c56708aab798 160000 --- a/src/doc/rustc-guide +++ b/src/doc/rustc-guide @@ -1 +1 @@ -Subproject commit 934380b7cfceaaa4e1b9bb0de4a372f32725520b +Subproject commit 7c56708aab7986ca390221e8e8902f7de7f9b076 diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index c356a7e31b177..fed4202d96103 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -759,8 +759,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { // These items live in both the type and value namespaces. ItemKind::Struct(ref vdata, _) => { // Define a name in the type namespace. - let item_def_id = self.r.definitions.local_def_id(item.id); - let res = Res::Def(DefKind::Struct, item_def_id); + let def_id = self.r.definitions.local_def_id(item.id); + let res = Res::Def(DefKind::Struct, def_id); self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion)); // Record field names for error reporting. @@ -798,12 +798,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { } ItemKind::Union(ref vdata, _) => { - let item_def_id = self.r.definitions.local_def_id(item.id); - let res = Res::Def(DefKind::Union, item_def_id); + let def_id = self.r.definitions.local_def_id(item.id); + let res = Res::Def(DefKind::Union, def_id); self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion)); // Record field names for error reporting. - self.insert_field_names_local(item_def_id, vdata); + self.insert_field_names_local(def_id, vdata); } ItemKind::Trait(..) => { diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index e40c6fa708888..cc6fbf840a454 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -265,14 +265,14 @@ impl<'a> LateResolutionVisitor<'a, '_> { if let PathSource::Expr(parent) = source { match &parent.map(|p| &p.kind) { Some(ExprKind::Call(_, args)) if args.len() > 0 => { - let mut expr_kind = &args.first().unwrap().kind; + let mut expr_kind = &args[0].kind; loop { match expr_kind { ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => { has_self_arg = arg_name.segments[0].ident.name == kw::SelfLower; break; }, - ExprKind::AddrOf(_, _, expr) => { expr_kind = &expr.kind; } + ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind, _ => break, } } @@ -284,7 +284,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { if has_self_arg { err.span_suggestion( span, - &"try calling method instead of passing `self` as parameter", + &format!("try calling `{}` as a method", ident), format!("self.{}", path_str), Applicability::MachineApplicable, ); diff --git a/src/test/ui/self/suggest-self-2.rs b/src/test/ui/self/suggest-self-2.rs index 1926ebe4b8317..d6bf543352701 100644 --- a/src/test/ui/self/suggest-self-2.rs +++ b/src/test/ui/self/suggest-self-2.rs @@ -4,12 +4,15 @@ impl Foo { fn foo(&self) { bar(self); //~^ ERROR cannot find function `bar` in this scope - //~| HELP try calling method instead of passing `self` as parameter + //~| HELP try calling `bar` as a method + bar(&&self, 102); + //~^ ERROR cannot find function `bar` in this scope + //~| HELP try calling `bar` as a method - bar(&self); + bar(&mut self, 102, &"str"); //~^ ERROR cannot find function `bar` in this scope - //~| HELP try calling method instead of passing `self` as parameter + //~| HELP try calling `bar` as a method bar(); //~^ ERROR cannot find function `bar` in this scope diff --git a/src/test/ui/self/suggest-self-2.stderr b/src/test/ui/self/suggest-self-2.stderr index 84dbaa9637898..ba71498fae656 100644 --- a/src/test/ui/self/suggest-self-2.stderr +++ b/src/test/ui/self/suggest-self-2.stderr @@ -2,27 +2,33 @@ error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:5:9 | LL | bar(self); - | ^^^ help: try calling method instead of passing `self` as parameter: `self.bar` + | ^^^ help: try calling `bar` as a method: `self.bar` error[E0425]: cannot find function `bar` in this scope - --> $DIR/suggest-self-2.rs:10:9 + --> $DIR/suggest-self-2.rs:9:9 | -LL | bar(&self); - | ^^^ help: try calling method instead of passing `self` as parameter: `self.bar` +LL | bar(&&self, 102); + | ^^^ help: try calling `bar` as a method: `self.bar` error[E0425]: cannot find function `bar` in this scope - --> $DIR/suggest-self-2.rs:14:9 + --> $DIR/suggest-self-2.rs:13:9 + | +LL | bar(&mut self, 102, &"str"); + | ^^^ help: try calling `bar` as a method: `self.bar` + +error[E0425]: cannot find function `bar` in this scope + --> $DIR/suggest-self-2.rs:17:9 | LL | bar(); | ^^^ not found in this scope error[E0599]: no method named `bar` found for type `&Foo` in the current scope - --> $DIR/suggest-self-2.rs:17:14 + --> $DIR/suggest-self-2.rs:20:14 | LL | self.bar(); | ^^^ method not found in `&Foo` -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors Some errors have detailed explanations: E0425, E0599. For more information about an error, try `rustc --explain E0425`. From 091853946bc0f3e9138875bfe1952e857e601896 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Sat, 21 Dec 2019 19:13:12 +0100 Subject: [PATCH 04/14] Add arguments to suggestion method call --- src/librustc_resolve/late/diagnostics.rs | 17 ++++++++++++++++- src/test/ui/self/suggest-self-2.stderr | 6 +++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index cc6fbf840a454..43626d87d71d5 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -262,6 +262,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { // Check if the first argument is `self` and suggest calling a method. let mut has_self_arg = false; + let mut args_span = None; if let PathSource::Expr(parent) = source { match &parent.map(|p| &p.kind) { Some(ExprKind::Call(_, args)) if args.len() > 0 => { @@ -270,6 +271,13 @@ impl<'a> LateResolutionVisitor<'a, '_> { match expr_kind { ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => { has_self_arg = arg_name.segments[0].ident.name == kw::SelfLower; + if args.len() > 1 { + args_span = Some(Span::new( + args[1].span.lo(), + args.last().unwrap().span.hi(), + parent.unwrap().span.ctxt(), + )); + } break; }, ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind, @@ -282,10 +290,17 @@ impl<'a> LateResolutionVisitor<'a, '_> { }; if has_self_arg { + let mut args_snippet: String = String::from(""); + if let Some(args_span) = args_span { + if let Ok(snippet) = self.r.session.source_map().span_to_snippet(args_span) { + args_snippet = snippet; + } + } + err.span_suggestion( span, &format!("try calling `{}` as a method", ident), - format!("self.{}", path_str), + format!("self.{}({})", path_str, args_snippet), Applicability::MachineApplicable, ); return (err, candidates); diff --git a/src/test/ui/self/suggest-self-2.stderr b/src/test/ui/self/suggest-self-2.stderr index ba71498fae656..6148012ac0d92 100644 --- a/src/test/ui/self/suggest-self-2.stderr +++ b/src/test/ui/self/suggest-self-2.stderr @@ -2,19 +2,19 @@ error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:5:9 | LL | bar(self); - | ^^^ help: try calling `bar` as a method: `self.bar` + | ^^^ help: try calling `bar` as a method: `self.bar()` error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:9:9 | LL | bar(&&self, 102); - | ^^^ help: try calling `bar` as a method: `self.bar` + | ^^^ help: try calling `bar` as a method: `self.bar(102)` error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:13:9 | LL | bar(&mut self, 102, &"str"); - | ^^^ help: try calling `bar` as a method: `self.bar` + | ^^^ help: try calling `bar` as a method: `self.bar(102, &"str")` error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:17:9 From 7353afdfd9b992a0254b8c23592e91cde792d514 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Sun, 22 Dec 2019 22:48:45 +0100 Subject: [PATCH 05/14] Extend suggestion span to whole method call --- src/librustc_resolve/late/diagnostics.rs | 26 ++++++++++++++---------- src/test/ui/self/suggest-self-2.stderr | 12 ++++++++--- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 43626d87d71d5..a1cbcac1a9a76 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -261,8 +261,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { } // Check if the first argument is `self` and suggest calling a method. - let mut has_self_arg = false; - let mut args_span = None; + let mut has_self_arg = None; if let PathSource::Expr(parent) = source { match &parent.map(|p| &p.kind) { Some(ExprKind::Call(_, args)) if args.len() > 0 => { @@ -270,13 +269,18 @@ impl<'a> LateResolutionVisitor<'a, '_> { loop { match expr_kind { ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => { - has_self_arg = arg_name.segments[0].ident.name == kw::SelfLower; - if args.len() > 1 { - args_span = Some(Span::new( - args[1].span.lo(), - args.last().unwrap().span.hi(), - parent.unwrap().span.ctxt(), - )); + if arg_name.segments[0].ident.name == kw::SelfLower { + let call_span = parent.unwrap().span; + let args_span = if args.len() > 1 { + Some(Span::new( + args[1].span.lo(), + args.last().unwrap().span.hi(), + call_span.ctxt(), + )) + } else { + None + }; + has_self_arg = Some((call_span, args_span)); } break; }, @@ -289,7 +293,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { } }; - if has_self_arg { + if let Some((call_span, args_span)) = has_self_arg { let mut args_snippet: String = String::from(""); if let Some(args_span) = args_span { if let Ok(snippet) = self.r.session.source_map().span_to_snippet(args_span) { @@ -298,7 +302,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { } err.span_suggestion( - span, + call_span, &format!("try calling `{}` as a method", ident), format!("self.{}({})", path_str, args_snippet), Applicability::MachineApplicable, diff --git a/src/test/ui/self/suggest-self-2.stderr b/src/test/ui/self/suggest-self-2.stderr index 6148012ac0d92..452c31275153a 100644 --- a/src/test/ui/self/suggest-self-2.stderr +++ b/src/test/ui/self/suggest-self-2.stderr @@ -2,19 +2,25 @@ error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:5:9 | LL | bar(self); - | ^^^ help: try calling `bar` as a method: `self.bar()` + | ^^^------ + | | + | help: try calling `bar` as a method: `self.bar()` error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:9:9 | LL | bar(&&self, 102); - | ^^^ help: try calling `bar` as a method: `self.bar(102)` + | ^^^------------- + | | + | help: try calling `bar` as a method: `self.bar(102)` error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:13:9 | LL | bar(&mut self, 102, &"str"); - | ^^^ help: try calling `bar` as a method: `self.bar(102, &"str")` + | ^^^------------------------ + | | + | help: try calling `bar` as a method: `self.bar(102, &"str")` error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:17:9 From 2168c0b9791d55361177efa3bb7e79f7b944a423 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Mon, 23 Dec 2019 11:56:34 +0100 Subject: [PATCH 06/14] Extract checking for self arg to separate method --- src/librustc_resolve/late/diagnostics.rs | 75 +++++++++++++----------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index a1cbcac1a9a76..904a4125f2f72 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -260,41 +260,9 @@ impl<'a> LateResolutionVisitor<'a, '_> { return (err, candidates); } - // Check if the first argument is `self` and suggest calling a method. - let mut has_self_arg = None; - if let PathSource::Expr(parent) = source { - match &parent.map(|p| &p.kind) { - Some(ExprKind::Call(_, args)) if args.len() > 0 => { - let mut expr_kind = &args[0].kind; - loop { - match expr_kind { - ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => { - if arg_name.segments[0].ident.name == kw::SelfLower { - let call_span = parent.unwrap().span; - let args_span = if args.len() > 1 { - Some(Span::new( - args[1].span.lo(), - args.last().unwrap().span.hi(), - call_span.ctxt(), - )) - } else { - None - }; - has_self_arg = Some((call_span, args_span)); - } - break; - }, - ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind, - _ => break, - } - } - } - _ => (), - } - }; - - if let Some((call_span, args_span)) = has_self_arg { - let mut args_snippet: String = String::from(""); + // If the first argument in call is `self` suggest calling a method. + if let Some((call_span, args_span)) = self.call_has_self_arg(source) { + let mut args_snippet = String::new(); if let Some(args_span) = args_span { if let Ok(snippet) = self.r.session.source_map().span_to_snippet(args_span) { args_snippet = snippet; @@ -348,6 +316,43 @@ impl<'a> LateResolutionVisitor<'a, '_> { (err, candidates) } + /// Check if the source is call expression and the first argument is `self`. If true, + /// return the span of whole call and the span for all arguments expect the first one (`self`). + fn call_has_self_arg(&self, source: PathSource<'_>) -> Option<(Span, Option)> { + let mut has_self_arg = None; + if let PathSource::Expr(parent) = source { + match &parent.map(|p| &p.kind) { + Some(ExprKind::Call(_, args)) if args.len() > 0 => { + let mut expr_kind = &args[0].kind; + loop { + match expr_kind { + ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => { + if arg_name.segments[0].ident.name == kw::SelfLower { + let call_span = parent.unwrap().span; + let tail_args_span = if args.len() > 1 { + Some(Span::new( + args[1].span.lo(), + args.last().unwrap().span.hi(), + call_span.ctxt(), + )) + } else { + None + }; + has_self_arg = Some((call_span, tail_args_span)); + } + break; + } + ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind, + _ => break, + } + } + } + _ => (), + } + }; + return has_self_arg; + } + fn followed_by_brace(&self, span: Span) -> (bool, Option<(Span, String)>) { // HACK(estebank): find a better way to figure out that this was a // parser issue where a struct literal is being used on an expression From 7b91ef8837cb5e926418aeb4a675313ba928c877 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Mon, 23 Dec 2019 15:55:35 +0100 Subject: [PATCH 07/14] Simplify match expr --- src/librustc_resolve/late/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 904a4125f2f72..e3895e18d668d 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -321,8 +321,8 @@ impl<'a> LateResolutionVisitor<'a, '_> { fn call_has_self_arg(&self, source: PathSource<'_>) -> Option<(Span, Option)> { let mut has_self_arg = None; if let PathSource::Expr(parent) = source { - match &parent.map(|p| &p.kind) { - Some(ExprKind::Call(_, args)) if args.len() > 0 => { + match &parent?.kind { + ExprKind::Call(_, args) if args.len() > 0 => { let mut expr_kind = &args[0].kind; loop { match expr_kind { From cfab634972137e4625d3e7b7fb91b51d3f2d4cd4 Mon Sep 17 00:00:00 2001 From: Michal Terepeta Date: Wed, 1 Jan 2020 12:39:13 +0100 Subject: [PATCH 08/14] Add a test for #37333 The test checks that we reuse the CGU of a crate when the implementation details of an `extern crate` have changed. Signed-off-by: Michal Terepeta --- .../auxiliary/a.rs | 31 +++++++++++++++++++ .../change_implementation_cross_crate/main.rs | 20 ++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/test/incremental/change_implementation_cross_crate/auxiliary/a.rs create mode 100644 src/test/incremental/change_implementation_cross_crate/main.rs diff --git a/src/test/incremental/change_implementation_cross_crate/auxiliary/a.rs b/src/test/incremental/change_implementation_cross_crate/auxiliary/a.rs new file mode 100644 index 0000000000000..7320a97b9979a --- /dev/null +++ b/src/test/incremental/change_implementation_cross_crate/auxiliary/a.rs @@ -0,0 +1,31 @@ +#![allow(warnings)] +#![crate_name = "a"] +#![crate_type = "rlib"] + +#[cfg(rpass1)] +#[inline(never)] +pub fn foo(b: u8) -> u32 { + b as u32 +} + +#[cfg(rpass2)] +#[inline(never)] +pub fn foo(b: u8) -> u32 { + (b + 42) as u32 +} + +pub fn bar(b: u8) -> u32 { + bar_impl(b) as u32 +} + +#[cfg(rpass1)] +#[inline(never)] +fn bar_impl(b: u8) -> u16 { + b as u16 +} + +#[cfg(rpass2)] +#[inline(never)] +fn bar_impl(b: u8) -> u32 { + (b + 42) as u32 +} diff --git a/src/test/incremental/change_implementation_cross_crate/main.rs b/src/test/incremental/change_implementation_cross_crate/main.rs new file mode 100644 index 0000000000000..dee9ebd74a89f --- /dev/null +++ b/src/test/incremental/change_implementation_cross_crate/main.rs @@ -0,0 +1,20 @@ +// Test that we are able to reuse `main` despite the changes in the implementation of `foo` and +// `bar`. + +// revisions: rpass1 rpass2 +// aux-build: a.rs +// compile-flags: -Zquery-dep-graph + +#![feature(rustc_attrs)] +#![crate_type = "bin"] +#![rustc_partition_reused(module = "main", cfg = "rpass2")] + +extern crate a; + +pub fn main() { + let vec: Vec = vec![0, 1, 2, 3]; + for b in vec { + println!("{}", a::foo(b)); + println!("{}", a::bar(b)); + } +} From 23f543162a40d34cd9c3f53de48b58e4088a82c2 Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Wed, 1 Jan 2020 23:46:25 +0000 Subject: [PATCH 09/14] Cleanup linkchecker whitelist linkchecker is no longer run on the compiler docs so they can be removed from the whitelist. --- src/tools/linkchecker/main.rs | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs index 558913d84adaa..fb4611ed1ca4b 100644 --- a/src/tools/linkchecker/main.rs +++ b/src/tools/linkchecker/main.rs @@ -122,33 +122,22 @@ fn check(cache: &mut Cache, root: &Path, file: &Path, errors: &mut bool) -> Opti // Unfortunately we're not 100% full of valid links today to we need a few // whitelists to get this past `make check` today. // FIXME(#32129) - if file.ends_with("std/string/struct.String.html") - || file.ends_with("interpret/struct.ImmTy.html") - || file.ends_with("ast/struct.ThinVec.html") - || file.ends_with("util/struct.ThinVec.html") - || file.ends_with("layout/struct.TyLayout.html") - || file.ends_with("humantime/struct.Timestamp.html") - || file.ends_with("log/index.html") - || file.ends_with("ty/struct.Slice.html") - || file.ends_with("ty/enum.Attributes.html") - || file.ends_with("ty/struct.SymbolName.html") - || file.ends_with("io/struct.IoSlice.html") - || file.ends_with("io/struct.IoSliceMut.html") + if file.ends_with("std/io/struct.IoSlice.html") + || file.ends_with("std/string/struct.String.html") { return None; } // FIXME(#32553) - if file.ends_with("string/struct.String.html") { + if file.ends_with("alloc/string/struct.String.html") { return None; } // FIXME(#32130) - if file.ends_with("btree_set/struct.BTreeSet.html") - || file.ends_with("struct.BTreeSet.html") - || file.ends_with("btree_map/struct.BTreeMap.html") - || file.ends_with("hash_map/struct.HashMap.html") - || file.ends_with("hash_set/struct.HashSet.html") - || file.ends_with("sync/struct.Lrc.html") - || file.ends_with("sync/struct.RwLock.html") + if file.ends_with("alloc/collections/btree_map/struct.BTreeMap.html") + || file.ends_with("alloc/collections/btree_set/struct.BTreeSet.html") + || file.ends_with("std/collections/btree_map/struct.BTreeMap.html") + || file.ends_with("std/collections/btree_set/struct.BTreeSet.html") + || file.ends_with("std/collections/hash_map/struct.HashMap.html") + || file.ends_with("std/collections/hash_set/struct.HashSet.html") { return None; } From 562389d360f8d1e726055ae7c40f390f365a11d7 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 31 Dec 2019 21:25:16 +0100 Subject: [PATCH 10/14] - remove syntax::{span_warn!, span_err!, span_fatal!. struct_err!} - remove syntax::{help!, span_help!, span_note!} - remove unused syntax::{struct_span_fatal, struct_span_err_or_warn!, span_err_or_warn!} - lintify check_for_bindings_named_same_as_variants + conflicting_repr_hints - inline syntax::{struct_span_warn!, diagnostic_used!} - stringify_error_code! -> error_code! & use it more. - find_plugin_registrar: de-fatalize an error - de-fatalize metadata errors - move type_error_struct! to rustc_typeck - struct_span_err! -> rustc_errors --- Cargo.lock | 2 + src/librustc/hir/check_attr.rs | 23 ++- src/librustc/infer/error_reporting/mod.rs | 2 +- .../infer/error_reporting/need_type_info.rs | 15 +- .../nice_region_error/different_lifetimes.rs | 1 + .../nice_region_error/named_anon_conflict.rs | 2 +- src/librustc/infer/error_reporting/note.rs | 2 +- src/librustc/infer/opaque_types/mod.rs | 8 +- src/librustc/lint/builtin.rs | 13 ++ src/librustc/lint/context.rs | 7 +- src/librustc/lint/levels.rs | 7 +- src/librustc/middle/lang_items.rs | 6 +- src/librustc/middle/weak_lang_items.rs | 10 +- src/librustc/mir/interpret/error.rs | 2 +- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/on_unimplemented.rs | 11 +- src/librustc/traits/query/dropck_outlives.rs | 8 +- src/librustc/traits/specialize/mod.rs | 1 + src/librustc/ty/query/plumbing.rs | 6 +- src/librustc_ast_lowering/expr.rs | 18 +- src/librustc_ast_lowering/item.rs | 2 +- src/librustc_ast_lowering/lib.rs | 9 +- src/librustc_builtin_macros/asm.rs | 33 ++-- .../deriving/default.rs | 10 +- src/librustc_codegen_ssa/common.rs | 3 +- src/librustc_codegen_ssa/lib.rs | 2 - src/librustc_codegen_ssa/mir/statement.rs | 11 +- src/librustc_errors/diagnostic_builder.rs | 19 ++ src/librustc_metadata/creader.rs | 8 +- src/librustc_metadata/locator.rs | 17 +- src/librustc_metadata/native_libs.rs | 4 +- .../borrow_check/type_check/mod.rs | 1 + src/librustc_mir/hair/pattern/check_match.rs | 40 +++-- src/librustc_mir/hair/pattern/mod.rs | 7 +- src/librustc_mir/lib.rs | 2 - .../transform/check_consts/ops.rs | 18 +- .../transform/check_consts/validation.rs | 1 + src/librustc_mir/transform/check_unsafety.rs | 5 +- src/librustc_mir/util/borrowck_errors.rs | 5 +- src/librustc_parse/parser/diagnostics.rs | 4 +- src/librustc_parse/parser/item.rs | 3 +- src/librustc_parse/parser/mod.rs | 3 +- src/librustc_parse/parser/ty.rs | 3 +- src/librustc_passes/ast_validation.rs | 33 +++- src/librustc_passes/check_const.rs | 4 +- src/librustc_passes/diagnostic_items.rs | 2 +- src/librustc_passes/entry.rs | 9 +- src/librustc_passes/intrinsicck.rs | 1 + src/librustc_passes/lib.rs | 2 - src/librustc_passes/lib_features.rs | 1 + src/librustc_passes/loops.rs | 3 +- src/librustc_passes/region.rs | 4 +- src/librustc_passes/stability.rs | 1 + src/librustc_plugin_impl/Cargo.toml | 1 + src/librustc_plugin_impl/load.rs | 2 +- src/librustc_privacy/Cargo.toml | 1 + src/librustc_privacy/lib.rs | 4 +- src/librustc_resolve/build_reduced_graph.rs | 25 +-- src/librustc_resolve/diagnostics.rs | 3 +- src/librustc_resolve/imports.rs | 4 +- src/librustc_resolve/late.rs | 40 ++--- src/librustc_resolve/late/diagnostics.rs | 11 +- src/librustc_resolve/lib.rs | 4 +- src/librustc_resolve/lifetimes.rs | 44 +++-- src/librustc_typeck/astconv.rs | 25 ++- src/librustc_typeck/check/autoderef.rs | 1 + src/librustc_typeck/check/callee.rs | 3 +- src/librustc_typeck/check/cast.rs | 20 ++- src/librustc_typeck/check/coercion.rs | 2 +- src/librustc_typeck/check/compare_method.rs | 4 +- src/librustc_typeck/check/dropck.rs | 2 +- src/librustc_typeck/check/expr.rs | 13 +- src/librustc_typeck/check/intrinsic.rs | 16 +- src/librustc_typeck/check/method/probe.rs | 6 +- src/librustc_typeck/check/method/suggest.rs | 12 +- src/librustc_typeck/check/mod.rs | 33 +++- src/librustc_typeck/check/op.rs | 2 +- src/librustc_typeck/check/pat.rs | 13 +- src/librustc_typeck/check/wfcheck.rs | 6 +- src/librustc_typeck/coherence/builtin.rs | 42 ++--- .../coherence/inherent_impls.rs | 1 + .../coherence/inherent_impls_overlap.rs | 2 +- src/librustc_typeck/coherence/mod.rs | 1 + src/librustc_typeck/coherence/orphan.rs | 1 + src/librustc_typeck/coherence/unsafety.rs | 17 +- src/librustc_typeck/collect.rs | 47 +++-- src/librustc_typeck/impl_wf_check.rs | 1 + src/librustc_typeck/lib.rs | 3 +- src/librustc_typeck/outlives/test.rs | 6 +- src/librustc_typeck/structured_errors.rs | 6 +- src/librustc_typeck/variance/test.rs | 3 +- src/libsyntax/attr/builtin.rs | 73 +++++--- src/libsyntax/diagnostics/macros.rs | 169 ------------------ src/libsyntax/feature_gate/check.rs | 28 ++- src/libsyntax/lib.rs | 6 - src/test/ui/conflicting-repr-hints.stderr | 2 + .../feature-gate-repr-simd.stderr | 2 + src/test/ui/issues/issue-14221.stderr | 2 + src/test/ui/issues/issue-19100.stderr | 2 + src/test/ui/issues/issue-30302.stderr | 2 + src/test/ui/issues/issue-39720.stderr | 2 + src/test/ui/issues/issue-47094.stderr | 2 + .../ui/lint/lint-uppercase-variables.stderr | 2 + 103 files changed, 562 insertions(+), 573 deletions(-) delete mode 100644 src/libsyntax/diagnostics/macros.rs diff --git a/Cargo.lock b/Cargo.lock index ba0f55ab5af6f..9f5ce7dd195e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3774,6 +3774,7 @@ version = "0.0.0" dependencies = [ "rustc", "rustc_error_codes", + "rustc_errors", "rustc_metadata", "rustc_span", "syntax", @@ -3787,6 +3788,7 @@ dependencies = [ "rustc", "rustc_data_structures", "rustc_error_codes", + "rustc_errors", "rustc_span", "rustc_typeck", "syntax", diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 2b201cfe0a962..b212b4880d3c7 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -8,11 +8,13 @@ use crate::hir::def_id::DefId; use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; use crate::hir::DUMMY_HIR_ID; use crate::hir::{self, Attribute, HirId, Item, ItemKind, TraitItem, TraitItemKind}; -use crate::lint::builtin::UNUSED_ATTRIBUTES; +use crate::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES}; use crate::ty::query::Providers; use crate::ty::TyCtxt; +use errors::{error_code, struct_span_err}; use rustc_span::Span; + use std::fmt::{self, Display}; use syntax::{attr, symbol::sym}; @@ -192,7 +194,7 @@ impl CheckAttrVisitor<'tcx> { self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id)); } - self.check_repr(attrs, span, target, item); + self.check_repr(attrs, span, target, item, hir_id); self.check_used(attrs, target); } @@ -353,6 +355,7 @@ impl CheckAttrVisitor<'tcx> { span: &Span, target: Target, item: Option<&Item<'_>>, + hir_id: HirId, ) { // Extract the names of all repr hints, e.g., [foo, bar, align] for: // ``` @@ -428,21 +431,29 @@ impl CheckAttrVisitor<'tcx> { // Error on repr(transparent, ). if is_transparent && hints.len() > 1 { let hint_spans: Vec<_> = hint_spans.clone().collect(); - span_err!( + struct_span_err!( self.tcx.sess, hint_spans, E0692, "transparent {} cannot have other repr hints", target - ); + ) + .emit(); } // Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8) if (int_reprs > 1) || (is_simd && is_c) || (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item))) { - let hint_spans: Vec<_> = hint_spans.collect(); - span_warn!(self.tcx.sess, hint_spans, E0566, "conflicting representation hints"); + self.tcx + .struct_span_lint_hir( + CONFLICTING_REPR_HINTS, + hir_id, + hint_spans.collect::>(), + "conflicting representation hints", + ) + .code(error_code!(E0566)) + .emit(); } } diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index e2b70abe6f0f5..56473b43cdca6 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -65,7 +65,7 @@ use crate::ty::{ Region, Ty, TyCtxt, TypeFoldable, }; -use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder, DiagnosticStyledString}; use rustc_error_codes::*; use rustc_span::{Pos, Span}; use rustc_target::spec::abi; diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index a94595b227b2e..07afa4869f253 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -5,7 +5,7 @@ use crate::infer::type_variable::TypeVariableOriginKind; use crate::infer::InferCtxt; use crate::ty::print::Print; use crate::ty::{self, DefIdTree, Infer, Ty, TyVar}; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_span::Span; use std::borrow::Cow; use syntax::source_map::DesugaringKind; @@ -153,14 +153,11 @@ pub enum TypeAnnotationNeeded { impl Into for TypeAnnotationNeeded { fn into(self) -> errors::DiagnosticId { - syntax::diagnostic_used!(E0282); - syntax::diagnostic_used!(E0283); - syntax::diagnostic_used!(E0284); - errors::DiagnosticId::Error(match self { - Self::E0282 => "E0282".to_string(), - Self::E0283 => "E0283".to_string(), - Self::E0284 => "E0284".to_string(), - }) + match self { + Self::E0282 => errors::error_code!(E0282), + Self::E0283 => errors::error_code!(E0283), + Self::E0284 => errors::error_code!(E0284), + } } } diff --git a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs index cfb6d5bd244b9..b73fb40f637ed 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -5,6 +5,7 @@ use crate::infer::error_reporting::nice_region_error::util::AnonymousParamInfo; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::util::common::ErrorReported; +use errors::struct_span_err; use rustc_error_codes::*; impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { diff --git a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs index 94b8d16668a3f..f92ad5ce30ce7 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -3,7 +3,7 @@ use crate::hir::{FunctionRetTy, TyKind}; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::ty; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_error_codes::*; diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs index 979bcca619c2f..cb927cb6a2cda 100644 --- a/src/librustc/infer/error_reporting/note.rs +++ b/src/librustc/infer/error_reporting/note.rs @@ -2,7 +2,7 @@ use crate::infer::{self, InferCtxt, SubregionOrigin}; use crate::middle::region; use crate::ty::error::TypeError; use crate::ty::{self, Region}; -use errors::DiagnosticBuilder; +use errors::{struct_span_err, DiagnosticBuilder}; use rustc_error_codes::*; diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 8399737b3e610..4efa3cbab0f48 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -9,7 +9,7 @@ use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor}; use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef}; use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt}; use crate::util::nodemap::DefIdMap; -use errors::DiagnosticBuilder; +use errors::{struct_span_err, DiagnosticBuilder}; use rustc::session::config::nightly_options; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; @@ -523,11 +523,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { err.span_label(span, label); if nightly_options::is_nightly_build() { - help!( - err, - "add #![feature(member_constraints)] to the crate attributes \ - to enable" - ); + err.help("add #![feature(member_constraints)] to the crate attributes to enable"); } err.emit(); diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index fa6e93d867b4e..16fc142eb7a6e 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -95,6 +95,18 @@ declare_lint! { "detects overlapping patterns" } +declare_lint! { + pub BINDING_VARIANT_NAME, + Warn, + "detects pattern bindings with the same name as one of the matched variants" +} + +declare_lint! { + pub CONFLICTING_REPR_HINTS, + Warn, + "detects when more than one `#[repr(..)]` attribute, with different meaning, is applied" +} + declare_lint! { pub UNUSED_MACROS, Warn, @@ -459,6 +471,7 @@ declare_lint_pass! { UNREACHABLE_CODE, UNREACHABLE_PATTERNS, OVERLAPPING_PATTERNS, + BINDING_VARIANT_NAME, UNUSED_MACROS, WARNINGS, UNUSED_FEATURES, diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 6e0bb3a2a2b38..ba4ee8c1aefad 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -32,9 +32,9 @@ use crate::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt}; use crate::util::common::time; use crate::util::nodemap::FxHashMap; -use errors::DiagnosticBuilder; +use errors::{struct_span_err, DiagnosticBuilder}; use rustc_data_structures::sync::{self, join, par_iter, ParallelIterator}; -use rustc_span::{symbol::Symbol, MultiSpan, Span}; +use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP}; use std::slice; use syntax::ast; use syntax::util::lev_distance::find_best_match_for_name; @@ -295,7 +295,8 @@ impl LintStore { CheckLintNameResult::Ok(_) => None, CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)), CheckLintNameResult::NoLint(suggestion) => { - let mut err = struct_err!(sess, E0602, "unknown lint: `{}`", lint_name); + let mut err = + struct_span_err!(sess, DUMMY_SP, E0602, "unknown lint: `{}`", lint_name); if let Some(suggestion) = suggestion { err.help(&format!("did you mean: `{}`", suggestion)); diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index edf7df16c87fa..aba0c789c241a 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -7,7 +7,7 @@ use crate::lint::context::{CheckLintNameResult, LintStore}; use crate::lint::{self, Level, Lint, LintId, LintSource}; use crate::session::Session; use crate::util::nodemap::FxHashMap; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use syntax::ast; use syntax::attr; @@ -274,13 +274,14 @@ impl<'a> LintLevelsBuilder<'a> { let tool_name = if meta_item.path.segments.len() > 1 { let tool_ident = meta_item.path.segments[0].ident; if !attr::is_known_lint_tool(tool_ident) { - span_err!( + struct_span_err!( sess, tool_ident.span, E0710, "an unknown tool name found in scoped lint: `{}`", pprust::path_to_string(&meta_item.path), - ); + ) + .emit(); continue; } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index c07b65acff218..2807f3a7e9169 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -18,6 +18,7 @@ use crate::util::nodemap::FxHashMap; use crate::hir; use crate::hir::itemlikevisit::ItemLikeVisitor; +use errors::struct_span_err; use rustc_macros::HashStable; use rustc_span::Span; use syntax::ast; @@ -184,7 +185,8 @@ impl LanguageItemCollector<'tcx> { span, E0152, "duplicate lang item found: `{}`.", - name), + name + ), None => { match self.tcx.extern_crate(item_def_id) { Some(ExternCrate {dependency_of, ..}) => { @@ -204,7 +206,7 @@ impl LanguageItemCollector<'tcx> { }, }; if let Some(span) = self.tcx.hir().span_if_local(original_def_id) { - span_note!(&mut err, span, "first defined here."); + err.span_note(span, "first defined here."); } else { match self.tcx.extern_crate(original_def_id) { Some(ExternCrate {dependency_of, ..}) => { diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs index 011c9fc27e05e..1e365d944b6cb 100644 --- a/src/librustc/middle/weak_lang_items.rs +++ b/src/librustc/middle/weak_lang_items.rs @@ -8,6 +8,7 @@ use crate::hir::def_id::DefId; use crate::hir::intravisit; use crate::hir::intravisit::{NestedVisitorMap, Visitor}; use crate::ty::TyCtxt; +use errors::struct_span_err; use rustc_data_structures::fx::FxHashSet; use rustc_span::Span; use rustc_target::spec::PanicStrategy; @@ -124,9 +125,12 @@ impl<'a, 'tcx> Context<'a, 'tcx> { self.items.missing.push(lang_items::$item); } } else)* { - span_err!(self.tcx.sess, span, E0264, - "unknown external lang item: `{}`", - name); + struct_span_err!( + self.tcx.sess, span, E0264, + "unknown external lang item: `{}`", + name + ) + .emit(); } } } diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 2308da5d610e8..7daf58b705734 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -8,7 +8,7 @@ use crate::ty::query::TyCtxtAt; use crate::ty::{self, layout, Ty}; use backtrace::Backtrace; -use errors::DiagnosticBuilder; +use errors::{struct_span_err, DiagnosticBuilder}; use hir::GeneratorKind; use rustc_macros::HashStable; use rustc_span::{Pos, Span}; diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 8a5a92fcfa6d9..e7e8328707798 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -23,7 +23,7 @@ use crate::ty::TypeckTables; use crate::ty::{self, AdtKind, DefIdTree, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable}; use crate::util::nodemap::{FxHashMap, FxHashSet}; -use errors::{pluralize, Applicability, DiagnosticBuilder, Style}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, Style}; use rustc::hir::def_id::LOCAL_CRATE; use rustc_span::source_map::SourceMap; use rustc_span::{ExpnKind, MultiSpan, Span, DUMMY_SP}; diff --git a/src/librustc/traits/on_unimplemented.rs b/src/librustc/traits/on_unimplemented.rs index 5d90018e80a38..4225c3fbc3a1e 100644 --- a/src/librustc/traits/on_unimplemented.rs +++ b/src/librustc/traits/on_unimplemented.rs @@ -5,6 +5,7 @@ use crate::ty::{self, GenericParamDefKind, TyCtxt}; use crate::util::common::ErrorReported; use crate::util::nodemap::FxHashMap; +use errors::struct_span_err; use rustc_span::Span; use syntax::ast::{MetaItem, NestedMetaItem}; use syntax::attr; @@ -293,26 +294,28 @@ impl<'tcx> OnUnimplementedFormatString { match generics.params.iter().find(|param| param.name == s) { Some(_) => (), None => { - span_err!( + struct_span_err!( tcx.sess, span, E0230, "there is no parameter `{}` on trait `{}`", s, name - ); + ) + .emit(); result = Err(ErrorReported); } } } // `{:1}` and `{}` are not to be used Position::ArgumentIs(_) | Position::ArgumentImplicitlyIs(_) => { - span_err!( + struct_span_err!( tcx.sess, span, E0231, "only named substitution parameters are allowed" - ); + ) + .emit(); result = Err(ErrorReported); } }, diff --git a/src/librustc/traits/query/dropck_outlives.rs b/src/librustc/traits/query/dropck_outlives.rs index 80a82021c9a34..9f84b5e9fd4f7 100644 --- a/src/librustc/traits/query/dropck_outlives.rs +++ b/src/librustc/traits/query/dropck_outlives.rs @@ -76,15 +76,15 @@ pub struct DropckOutlivesResult<'tcx> { impl<'tcx> DropckOutlivesResult<'tcx> { pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) { if let Some(overflow_ty) = self.overflows.iter().next() { - let mut err = struct_span_err!( + errors::struct_span_err!( tcx.sess, span, E0320, "overflow while adding drop-check rules for {}", ty, - ); - err.note(&format!("overflowed on {}", overflow_ty)); - err.emit(); + ) + .note(&format!("overflowed on {}", overflow_ty)) + .emit(); } } diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 9d3e9e309c697..8193236b37390 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -18,6 +18,7 @@ use crate::traits::select::IntercrateAmbiguityCause; use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine}; use crate::ty::subst::{InternalSubsts, Subst, SubstsRef}; use crate::ty::{self, TyCtxt, TypeFoldable}; +use errors::struct_span_err; use rustc_data_structures::fx::FxHashSet; use rustc_span::DUMMY_SP; diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 0642de8c744c2..6ab41854bd30b 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -9,11 +9,7 @@ use crate::ty::query::Query; use crate::ty::tls; use crate::ty::{self, TyCtxt}; -use errors::Diagnostic; -use errors::DiagnosticBuilder; -use errors::FatalError; -use errors::Handler; -use errors::Level; +use errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, Handler, Level}; #[cfg(not(parallel_compiler))] use rustc_data_structures::cold_path; use rustc_data_structures::fx::{FxHashMap, FxHasher}; diff --git a/src/librustc_ast_lowering/expr.rs b/src/librustc_ast_lowering/expr.rs index a3e2bc04bd5fb..b299601fd480e 100644 --- a/src/librustc_ast_lowering/expr.rs +++ b/src/librustc_ast_lowering/expr.rs @@ -5,12 +5,12 @@ use rustc::hir; use rustc::hir::def::Res; use rustc_data_structures::thin_vec::ThinVec; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned}; use rustc_span::symbol::{sym, Symbol}; use syntax::ast::*; use syntax::attr; use syntax::ptr::P as AstP; -use syntax::{span_err, struct_span_err}; impl<'hir> LoweringContext<'_, 'hir> { fn lower_exprs(&mut self, exprs: &[AstP]) -> &'hir [hir::Expr<'hir>] { @@ -701,12 +701,13 @@ impl<'hir> LoweringContext<'_, 'hir> { match generator_kind { Some(hir::GeneratorKind::Gen) => { if !decl.inputs.is_empty() { - span_err!( + struct_span_err!( self.sess, fn_decl_span, E0628, "generators cannot have explicit parameters" - ); + ) + .emit(); } Some(movability) } @@ -715,7 +716,8 @@ impl<'hir> LoweringContext<'_, 'hir> { } None => { if movability == Movability::Static { - span_err!(self.sess, fn_decl_span, E0697, "closures cannot be static"); + struct_span_err!(self.sess, fn_decl_span, E0697, "closures cannot be static") + .emit(); } None } @@ -962,7 +964,13 @@ impl<'hir> LoweringContext<'_, 'hir> { match self.generator_kind { Some(hir::GeneratorKind::Gen) => {} Some(hir::GeneratorKind::Async(_)) => { - span_err!(self.sess, span, E0727, "`async` generators are not yet supported",); + struct_span_err!( + self.sess, + span, + E0727, + "`async` generators are not yet supported" + ) + .emit(); return hir::ExprKind::Err; } None => self.generator_kind = Some(hir::GeneratorKind::Gen), diff --git a/src/librustc_ast_lowering/item.rs b/src/librustc_ast_lowering/item.rs index c1eb8be0f8aad..08464180cf122 100644 --- a/src/librustc_ast_lowering/item.rs +++ b/src/librustc_ast_lowering/item.rs @@ -8,13 +8,13 @@ use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::DefId; use rustc::util::nodemap::NodeMap; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_span::source_map::{respan, DesugaringKind}; use rustc_span::symbol::{kw, sym}; use rustc_span::Span; use rustc_target::spec::abi; use syntax::ast::*; use syntax::attr; -use syntax::struct_span_err; use syntax::visit::{self, Visitor}; use log::debug; diff --git a/src/librustc_ast_lowering/lib.rs b/src/librustc_ast_lowering/lib.rs index a9214f31e7d2e..460f79d29b817 100644 --- a/src/librustc_ast_lowering/lib.rs +++ b/src/librustc_ast_lowering/lib.rs @@ -52,7 +52,7 @@ use rustc::{bug, span_bug}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use rustc_error_codes::*; -use rustc_errors::Applicability; +use rustc_errors::{struct_span_err, Applicability}; use rustc_index::vec::IndexVec; use rustc_span::hygiene::ExpnId; use rustc_span::source_map::{respan, DesugaringKind, ExpnData, ExpnKind, Spanned}; @@ -67,7 +67,7 @@ use syntax::sess::ParseSess; use syntax::token::{self, Nonterminal, Token}; use syntax::tokenstream::{TokenStream, TokenTree}; use syntax::visit::{self, Visitor}; -use syntax::{help, struct_span_err, walk_list}; +use syntax::walk_list; use log::{debug, trace}; use smallvec::{smallvec, SmallVec}; @@ -1347,10 +1347,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ); if pos == ImplTraitPosition::Binding && nightly_options::is_nightly_build() { - help!( - err, + err.help( "add `#![feature(impl_trait_in_bindings)]` to the crate \ - attributes to enable" + attributes to enable", ); } err.emit(); diff --git a/src/librustc_builtin_macros/asm.rs b/src/librustc_builtin_macros/asm.rs index 71d6d058d90be..bdae48b65a622 100644 --- a/src/librustc_builtin_macros/asm.rs +++ b/src/librustc_builtin_macros/asm.rs @@ -2,7 +2,7 @@ // use State::*; -use errors::{DiagnosticBuilder, PResult}; +use errors::{struct_span_err, DiagnosticBuilder, PResult}; use rustc_expand::base::*; use rustc_parse::parser::Parser; use rustc_span::Span; @@ -11,7 +11,6 @@ use syntax::ptr::P; use syntax::symbol::{kw, sym, Symbol}; use syntax::token::{self, Token}; use syntax::tokenstream::{self, TokenStream}; -use syntax::{span_err, struct_span_err}; use rustc_error_codes::*; @@ -173,12 +172,13 @@ fn parse_inline_asm<'a>( Some('=') => None, Some('+') => Some(Symbol::intern(&format!("={}", ch.as_str()))), _ => { - span_err!( - cx, + struct_span_err!( + cx.parse_sess.span_diagnostic, span, E0661, "output operand constraint lacks '=' or '+'" - ); + ) + .emit(); None } }; @@ -202,9 +202,21 @@ fn parse_inline_asm<'a>( let constraint = parse_asm_str(&mut p)?; if constraint.as_str().starts_with("=") { - span_err!(cx, p.prev_span, E0662, "input operand constraint contains '='"); + struct_span_err!( + cx.parse_sess.span_diagnostic, + p.prev_span, + E0662, + "input operand constraint contains '='" + ) + .emit(); } else if constraint.as_str().starts_with("+") { - span_err!(cx, p.prev_span, E0663, "input operand constraint contains '+'"); + struct_span_err!( + cx.parse_sess.span_diagnostic, + p.prev_span, + E0663, + "input operand constraint contains '+'" + ) + .emit(); } p.expect(&token::OpenDelim(token::Paren))?; @@ -225,12 +237,13 @@ fn parse_inline_asm<'a>( if OPTIONS.iter().any(|&opt| s == opt) { cx.span_warn(p.prev_span, "expected a clobber, found an option"); } else if s.as_str().starts_with("{") || s.as_str().ends_with("}") { - span_err!( - cx, + struct_span_err!( + cx.parse_sess.span_diagnostic, p.prev_span, E0664, "clobber should not be surrounded by braces" - ); + ) + .emit(); } clobs.push(s); diff --git a/src/librustc_builtin_macros/deriving/default.rs b/src/librustc_builtin_macros/deriving/default.rs index 43185f924e79c..235567e0004af 100644 --- a/src/librustc_builtin_macros/deriving/default.rs +++ b/src/librustc_builtin_macros/deriving/default.rs @@ -2,11 +2,11 @@ use crate::deriving::generic::ty::*; use crate::deriving::generic::*; use crate::deriving::path_std; +use errors::struct_span_err; use rustc_expand::base::{Annotatable, DummyResult, ExtCtxt}; use rustc_span::Span; use syntax::ast::{Expr, MetaItem}; use syntax::ptr::P; -use syntax::span_err; use syntax::symbol::{kw, sym}; use rustc_error_codes::*; @@ -74,7 +74,13 @@ fn default_substructure( } }, StaticEnum(..) => { - span_err!(cx, trait_span, E0665, "`Default` cannot be derived for enums, only structs"); + struct_span_err!( + cx.parse_sess.span_diagnostic, + trait_span, + E0665, + "`Default` cannot be derived for enums, only structs" + ) + .emit(); // let compilation continue DummyResult::raw_expr(trait_span, true) } diff --git a/src/librustc_codegen_ssa/common.rs b/src/librustc_codegen_ssa/common.rs index e0505daed8a62..d14aad10e96f0 100644 --- a/src/librustc_codegen_ssa/common.rs +++ b/src/librustc_codegen_ssa/common.rs @@ -2,6 +2,7 @@ use rustc::session::Session; use rustc::ty::{Ty, TyCtxt}; +use rustc_errors::struct_span_err; use rustc_span::Span; use crate::base; @@ -196,5 +197,5 @@ pub fn shift_mask_val<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( } pub fn span_invalid_monomorphization_error(a: &Session, b: Span, c: &str) { - span_err!(a, b, E0511, "{}", c); + struct_span_err!(a, b, E0511, "{}", c).emit(); } diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index fd31361d67950..1dffb77a833eb 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -21,8 +21,6 @@ extern crate log; #[macro_use] extern crate rustc; -#[macro_use] -extern crate syntax; use rustc::dep_graph::WorkProduct; use rustc::hir::def_id::CrateNum; diff --git a/src/librustc_codegen_ssa/mir/statement.rs b/src/librustc_codegen_ssa/mir/statement.rs index 48ba64143a708..574c06d9ceb41 100644 --- a/src/librustc_codegen_ssa/mir/statement.rs +++ b/src/librustc_codegen_ssa/mir/statement.rs @@ -1,4 +1,5 @@ use rustc::mir; +use rustc_errors::struct_span_err; use super::FunctionCx; use super::LocalRef; @@ -81,12 +82,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { if let OperandValue::Immediate(_) = op.val { acc.push(op.immediate()); } else { - span_err!( + struct_span_err!( bx.sess(), span.to_owned(), E0669, "invalid value for constraint in inline assembly" - ); + ) + .emit(); } acc }, @@ -100,12 +102,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { statement.source_info.span, ); if !res { - span_err!( + struct_span_err!( bx.sess(), statement.source_info.span, E0668, "malformed inline assembly" - ); + ) + .emit(); } } bx diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 79ec9ad7b0329..73f66d5503740 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -385,3 +385,22 @@ impl<'a> Drop for DiagnosticBuilder<'a> { } } } + +#[macro_export] +macro_rules! struct_span_err { + ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ + $session.struct_span_err_with_code( + $span, + &format!($($message)*), + $crate::error_code!($code), + ) + }) +} + +#[macro_export] +macro_rules! error_code { + ($code:ident) => {{ + let _ = $code; + $crate::DiagnosticId::Error(stringify!($code).to_owned()) + }}; +} diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index adb73d1c5fcc3..c0418b64bab25 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -20,6 +20,7 @@ use rustc_target::spec::{PanicStrategy, TargetTriple}; use std::path::Path; use std::{cmp, fs}; +use errors::struct_span_err; use log::{debug, info, log_enabled}; use proc_macro::bridge::client::ProcMacro; use rustc_expand::base::SyntaxExtension; @@ -28,7 +29,6 @@ use syntax::ast; use syntax::attr; use syntax::edition::Edition; use syntax::expand::allocator::{global_allocator_spans, AllocatorKind}; -use syntax::span_fatal; use syntax::symbol::{sym, Symbol}; use rustc_error_codes::*; @@ -261,7 +261,7 @@ impl<'a> CrateLoader<'a> { if self.local_crate_name == root.name() && self.sess.local_crate_disambiguator() == root.disambiguator() { - span_fatal!( + struct_span_err!( self.sess, span, E0519, @@ -271,6 +271,7 @@ impl<'a> CrateLoader<'a> { will result in symbol conflicts between the two.", root.name() ) + .emit() } // Check for conflicts with any crate loaded so far @@ -280,7 +281,7 @@ impl<'a> CrateLoader<'a> { other.hash() != root.hash() { // but different SVH - span_fatal!( + struct_span_err!( self.sess, span, E0523, @@ -289,6 +290,7 @@ impl<'a> CrateLoader<'a> { will result in symbol conflicts between the two.", root.name() ) + .emit(); } }); } diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index 93b29cf81d752..86e51eb5632fe 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -215,6 +215,7 @@ use crate::creader::Library; use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER}; +use errors::{struct_span_err, DiagnosticBuilder}; use rustc::middle::cstore::{CrateSource, MetadataLoader}; use rustc::session::filesearch::{FileDoesntMatch, FileMatches, FileSearch}; use rustc::session::search_paths::PathKind; @@ -223,13 +224,9 @@ use rustc::util::nodemap::FxHashMap; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::MetadataRef; - -use errors::DiagnosticBuilder; use rustc_span::Span; use rustc_target::spec::{Target, TargetTriple}; -use syntax::struct_span_err; use syntax::symbol::{sym, Symbol}; -use syntax::{span_err, span_fatal}; use std::cmp; use std::fmt; @@ -1039,28 +1036,28 @@ pub fn find_plugin_registrar( }; if target_only { - // Need to abort before syntax expansion. let message = format!( - "plugin `{}` is not available for triple `{}` \ - (only found {})", + "plugin `{}` is not available for triple `{}` (only found {})", name, config::host_triple(), sess.opts.target_triple ); - span_fatal!(sess, span, E0456, "{}", &message); + struct_span_err!(sess, span, E0456, "{}", &message).emit(); + return None; } match library.source.dylib { Some(dylib) => Some((dylib.0, library.metadata.get_root().disambiguator())), None => { - span_err!( + struct_span_err!( sess, span, E0457, "plugin `{}` only found in rlib format, but must be available \ in dylib format", name - ); + ) + .emit(); // No need to abort because the loading code will just ignore this // empty dylib. None diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index 06240994da3a8..00eb44e511a35 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -1,3 +1,4 @@ +use errors::struct_span_err; use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::middle::cstore::{self, NativeLibrary}; @@ -9,7 +10,6 @@ use syntax::attr; use syntax::feature_gate::feature_err; use syntax::source_map::Span; use syntax::symbol::{kw, sym, Symbol}; -use syntax::{span_err, struct_span_err}; use rustc_error_codes::*; @@ -159,7 +159,7 @@ impl Collector<'tcx> { if lib.kind == cstore::NativeFramework && !is_osx { let msg = "native frameworks are only available on macOS targets"; match span { - Some(span) => span_err!(self.tcx.sess, span, E0455, "{}", msg), + Some(span) => struct_span_err!(self.tcx.sess, span, E0455, "{}", msg).emit(), None => self.tcx.sess.err(msg), } } diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 369bce64724ab..d2b063099db31 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -30,6 +30,7 @@ use rustc::ty::{ }; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_index::vec::{Idx, IndexVec}; use rustc_span::{Span, DUMMY_SP}; diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 12d75033da2cf..73bcf296062b4 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -14,7 +14,7 @@ use rustc::session::Session; use rustc::ty::subst::{InternalSubsts, SubstsRef}; use rustc::ty::{self, Ty, TyCtxt}; use rustc_error_codes::*; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder}; use rustc_span::symbol::sym; use rustc_span::{MultiSpan, Span}; use syntax::ast::Mutability; @@ -116,7 +116,7 @@ impl PatCtxt<'_, '_> { } fn span_e0158(&self, span: Span, text: &str) { - span_err!(self.tcx.sess, span, E0158, "{}", text) + struct_span_err!(self.tcx.sess, span, E0158, "{}", text).emit(); } } @@ -291,24 +291,26 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa variant.ident == ident && variant.ctor_kind == CtorKind::Const }) { - // FIXME(Centril): Should be a lint? let ty_path = cx.tcx.def_path_str(edef.did); - let mut err = struct_span_warn!( - cx.tcx.sess, - p.span, - E0170, - "pattern binding `{}` is named the same as one \ - of the variants of the type `{}`", - ident, - ty_path - ); - err.span_suggestion( - p.span, - "to match on the variant, qualify the path", - format!("{}::{}", ty_path, ident), - Applicability::MachineApplicable, - ); - err.emit(); + cx.tcx + .struct_span_lint_hir( + lint::builtin::BINDING_VARIANT_NAME, + p.hir_id, + p.span, + &format!( + "pattern binding `{}` is named the same as one \ + of the variants of the type `{}`", + ident, ty_path + ), + ) + .code(error_code!(E0170)) + .span_suggestion( + p.span, + "to match on the variant, qualify the path", + format!("{}::{}", ty_path, ident), + Applicability::MachineApplicable, + ) + .emit(); } } } diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index f5d8ed877ec5c..c87bc35a0b452 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -19,7 +19,7 @@ use rustc::ty::layout::VariantIdx; use rustc::ty::subst::{GenericArg, SubstsRef}; use rustc::ty::{self, AdtDef, DefIdTree, Region, Ty, TyCtxt, UserType}; use rustc::ty::{CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations}; - +use rustc_errors::struct_span_err; use rustc_index::vec::Idx; use rustc_span::{Span, DUMMY_SP}; @@ -463,12 +463,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { PatKind::Range(PatRange { lo, hi, end }) } (RangeEnd::Excluded, _) => { - span_err!( + struct_span_err!( self.tcx.sess, lo_expr.span, E0579, "lower range bound must be less than upper", - ); + ) + .emit(); PatKind::Wild } (RangeEnd::Included, Some(Ordering::Equal)) => { diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 32b35c4139dad..9f70f1dd57688 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -35,8 +35,6 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! extern crate log; #[macro_use] extern crate rustc; -#[macro_use] -extern crate syntax; mod borrow_check; mod build; diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs index 37435fbf4d16f..402bf20626fb8 100644 --- a/src/librustc_mir/transform/check_consts/ops.rs +++ b/src/librustc_mir/transform/check_consts/ops.rs @@ -3,6 +3,7 @@ use rustc::hir::def_id::DefId; use rustc::session::config::nightly_options; use rustc::ty::TyCtxt; +use rustc_errors::struct_span_err; use rustc_span::{Span, Symbol}; use syntax::feature_gate::feature_err; use syntax::symbol::sym; @@ -115,12 +116,7 @@ impl NonConstOp for FnCallUnstable { &format!("`{}` is not yet stable as a const fn", item.tcx.def_path_str(def_id)), ); if nightly_options::is_nightly_build() { - help!( - &mut err, - "add `#![feature({})]` to the \ - crate attributes to enable", - feature - ); + err.help(&format!("add `#![feature({})]` to the crate attributes to enable", feature)); } err.emit(); } @@ -197,13 +193,14 @@ impl NonConstOp for Loop { pub struct CellBorrow; impl NonConstOp for CellBorrow { fn emit_error(&self, item: &Item<'_, '_>, span: Span) { - span_err!( + struct_span_err!( item.tcx.sess, span, E0492, "cannot borrow a constant which may contain \ interior mutability, create a static instead" - ); + ) + .emit(); } } @@ -375,13 +372,14 @@ impl NonConstOp for ThreadLocalAccess { const IS_SUPPORTED_IN_MIRI: bool = false; fn emit_error(&self, item: &Item<'_, '_>, span: Span) { - span_err!( + struct_span_err!( item.tcx.sess, span, E0625, "thread-local statics cannot be \ accessed at compile-time" - ); + ) + .emit(); } } diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index 19cad453e25e6..54282a845527b 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -8,6 +8,7 @@ use rustc::traits::{self, TraitEngine}; use rustc::ty::cast::CastTy; use rustc::ty::{self, TyCtxt}; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_index::bit_set::BitSet; use rustc_span::Span; use syntax::symbol::sym; diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 8b8f1b6f670ef..7dfa1b5eb5f4d 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -1,5 +1,3 @@ -use rustc_data_structures::fx::FxHashSet; - use rustc::hir; use rustc::hir::def_id::DefId; use rustc::hir::Node; @@ -9,7 +7,8 @@ use rustc::mir::*; use rustc::ty::cast::CastTy; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt}; - +use rustc_data_structures::fx::FxHashSet; +use rustc_errors::struct_span_err; use syntax::symbol::{sym, Symbol}; use std::ops::Bound; diff --git a/src/librustc_mir/util/borrowck_errors.rs b/src/librustc_mir/util/borrowck_errors.rs index 9f67109b34a1b..c275eecfb33b6 100644 --- a/src/librustc_mir/util/borrowck_errors.rs +++ b/src/librustc_mir/util/borrowck_errors.rs @@ -1,8 +1,7 @@ use rustc::ty::{self, Ty, TyCtxt}; -use rustc_errors::{DiagnosticBuilder, DiagnosticId}; -use rustc_span::{MultiSpan, Span}; - use rustc_error_codes::*; +use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId}; +use rustc_span::{MultiSpan, Span}; impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> { crate fn cannot_move_when_borrowed(&self, span: Span, desc: &str) -> DiagnosticBuilder<'cx> { diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index bf03f731c9f90..359386f4643d6 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -2,7 +2,8 @@ use super::{BlockMode, Parser, PathStyle, SemiColonMode, SeqSep, TokenExpectType use rustc_data_structures::fx::FxHashSet; use rustc_error_codes::*; -use rustc_errors::{self, pluralize, Applicability, DiagnosticBuilder, Handler, PResult}; +use rustc_errors::{pluralize, struct_span_err}; +use rustc_errors::{Applicability, DiagnosticBuilder, Handler, PResult}; use rustc_span::symbol::kw; use rustc_span::{MultiSpan, Span, SpanSnippetError, DUMMY_SP}; use syntax::ast::{ @@ -11,7 +12,6 @@ use syntax::ast::{ use syntax::ast::{AttrVec, ItemKind, Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind}; use syntax::print::pprust; use syntax::ptr::P; -use syntax::struct_span_err; use syntax::token::{self, token_can_begin_expr, TokenKind}; use syntax::util::parser::AssocOp; diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index a05bc48981efe..918e826fc26bf 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -4,7 +4,7 @@ use super::{FollowedByType, Parser, PathStyle}; use crate::maybe_whole; use rustc_error_codes::*; -use rustc_errors::{Applicability, DiagnosticBuilder, PResult, StashKey}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, PResult, StashKey}; use rustc_span::source_map::{self, respan, Span}; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::BytePos; @@ -16,7 +16,6 @@ use syntax::ast::{EnumDef, Generics, StructField, TraitRef, Ty, TyKind, Variant, use syntax::ast::{FnHeader, ForeignItem, ForeignItemKind, Mutability, Visibility, VisibilityKind}; use syntax::print::pprust; use syntax::ptr::P; -use syntax::struct_span_err; use syntax::token; use syntax::tokenstream::{DelimSpan, TokenStream, TokenTree}; diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index 6dcffcf0bd7b8..411397f63f5ea 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -15,7 +15,7 @@ use crate::lexer::UnmatchedBrace; use crate::{Directory, DirectoryOwnership}; use log::debug; -use rustc_errors::{Applicability, DiagnosticBuilder, FatalError, PResult}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, FatalError, PResult}; use rustc_span::source_map::respan; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::{BytePos, FileName, Span, DUMMY_SP}; @@ -24,7 +24,6 @@ use syntax::ast::{IsAsync, MacArgs, MacDelimiter, Mutability, StrLit, Visibility use syntax::print::pprust; use syntax::ptr::P; use syntax::sess::ParseSess; -use syntax::struct_span_err; use syntax::token::{self, DelimToken, Token, TokenKind}; use syntax::tokenstream::{self, DelimSpan, TokenStream, TokenTree, TreeAndJoint}; use syntax::util::comments::{doc_comment_style, strip_doc_comment_decoration}; diff --git a/src/librustc_parse/parser/ty.rs b/src/librustc_parse/parser/ty.rs index 4122aa17f83d3..f96c82a1ab37d 100644 --- a/src/librustc_parse/parser/ty.rs +++ b/src/librustc_parse/parser/ty.rs @@ -4,7 +4,7 @@ use super::{Parser, PathStyle, PrevTokenKind, TokenType}; use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole}; use rustc_error_codes::*; -use rustc_errors::{pluralize, Applicability, PResult}; +use rustc_errors::{pluralize, struct_span_err, Applicability, PResult}; use rustc_span::source_map::Span; use rustc_span::symbol::kw; use syntax::ast::{ @@ -15,7 +15,6 @@ use syntax::ast::{ }; use syntax::ast::{Mac, Mutability}; use syntax::ptr::P; -use syntax::struct_span_err; use syntax::token::{self, Token}; /// Returns `true` if `IDENT t` can start a type -- `IDENT::a::b`, `IDENT`, diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index a0d5467893de0..b49bec8fcaac6 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -6,7 +6,7 @@ // This pass is supposed to perform only simple checks not requiring name resolution // or type checking or some other kind of complex analysis. -use errors::{Applicability, FatalError}; +use errors::{struct_span_err, Applicability, FatalError}; use rustc::lint; use rustc::session::Session; use rustc_data_structures::fx::FxHashMap; @@ -20,7 +20,7 @@ use syntax::print::pprust; use syntax::source_map::Spanned; use syntax::symbol::{kw, sym}; use syntax::visit::{self, Visitor}; -use syntax::{span_err, struct_span_err, walk_list}; +use syntax::walk_list; use rustc_error_codes::*; @@ -470,7 +470,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { self.check_fn_decl(fn_decl); } ExprKind::InlineAsm(..) if !self.session.target.target.options.allow_asm => { - span_err!(self.session, expr.span, E0472, "asm! is unsupported on this target"); + struct_span_err!( + self.session, + expr.span, + E0472, + "asm! is unsupported on this target" + ) + .emit(); } _ => {} } @@ -498,12 +504,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { for bound in bounds { if let GenericBound::Outlives(ref lifetime) = *bound { if any_lifetime_bounds { - span_err!( + struct_span_err!( self.session, lifetime.ident.span, E0226, "only a single explicit lifetime bound is permitted" - ); + ) + .emit(); break; } any_lifetime_bounds = true; @@ -575,7 +582,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { .emit(); } if unsafety == Unsafety::Unsafe && polarity == ImplPolarity::Negative { - span_err!(self.session, item.span, E0198, "negative impls cannot be unsafe"); + struct_span_err!( + self.session, + item.span, + E0198, + "negative impls cannot be unsafe" + ) + .emit(); } for impl_item in impl_items { self.invalid_visibility(&impl_item.vis, None); @@ -591,7 +604,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { Some("place qualifiers on individual impl items instead"), ); if unsafety == Unsafety::Unsafe { - span_err!(self.session, item.span, E0197, "inherent impls cannot be unsafe"); + struct_span_err!( + self.session, + item.span, + E0197, + "inherent impls cannot be unsafe" + ) + .emit(); } if polarity == ImplPolarity::Negative { self.err_handler().span_err(item.span, "inherent impls cannot be negative"); diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index c08aab2e200fc..d68d207959831 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -7,6 +7,7 @@ //! errors. We still look for those primitives in the MIR const-checker to ensure nothing slips //! through, but errors for structured control flow in a `const` should be emitted here. +use errors::struct_span_err; use rustc::hir; use rustc::hir::def_id::DefId; use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; @@ -18,7 +19,6 @@ use rustc_error_codes::*; use rustc_span::{sym, Span, Symbol}; use syntax::ast::Mutability; use syntax::feature_gate::feature_err; -use syntax::span_err; use std::fmt; @@ -154,7 +154,7 @@ impl<'tcx> CheckConstVisitor<'tcx> { required_gates.iter().copied().filter(|&g| !features.enabled(g)).collect(); match missing_gates.as_slice() { - &[] => span_err!(self.tcx.sess, span, E0744, "{}", msg), + &[] => struct_span_err!(self.tcx.sess, span, E0744, "{}", msg).emit(), // If the user enabled `#![feature(const_loop)]` but not `#![feature(const_if_match)]`, // explain why their `while` loop is being rejected. diff --git a/src/librustc_passes/diagnostic_items.rs b/src/librustc_passes/diagnostic_items.rs index 65138fad43bd8..330e7bc8aba99 100644 --- a/src/librustc_passes/diagnostic_items.rs +++ b/src/librustc_passes/diagnostic_items.rs @@ -74,7 +74,7 @@ fn collect_item( )), }; if let Some(span) = tcx.hir().span_if_local(original_def_id) { - span_note!(&mut err, span, "first defined here."); + err.span_note(span, "first defined here."); } else { err.note(&format!( "first defined in crate `{}`.", diff --git a/src/librustc_passes/entry.rs b/src/librustc_passes/entry.rs index 3b7728a18d36d..96849137c4232 100644 --- a/src/librustc_passes/entry.rs +++ b/src/librustc_passes/entry.rs @@ -1,3 +1,4 @@ +use errors::struct_span_err; use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::map as hir_map; @@ -6,7 +7,7 @@ use rustc::session::config::EntryFnType; use rustc::session::{config, Session}; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; -use rustc_span::Span; +use rustc_span::{Span, DUMMY_SP}; use syntax::attr; use syntax::entry::EntryPointType; use syntax::symbol::sym; @@ -108,7 +109,8 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) { if ctxt.main_fn.is_none() { ctxt.main_fn = Some((item.hir_id, item.span)); } else { - span_err!(ctxt.session, item.span, E0136, "multiple `main` functions"); + struct_span_err!(ctxt.session, item.span, E0136, "multiple `main` functions") + .emit(); } } EntryPointType::OtherMain => { @@ -166,8 +168,9 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) { } // There is no main function. - let mut err = struct_err!( + let mut err = struct_span_err!( tcx.sess, + DUMMY_SP, E0601, "`main` function not found in crate `{}`", tcx.crate_name(LOCAL_CRATE) diff --git a/src/librustc_passes/intrinsicck.rs b/src/librustc_passes/intrinsicck.rs index 95dc31cc29bf4..4a94057fb71a4 100644 --- a/src/librustc_passes/intrinsicck.rs +++ b/src/librustc_passes/intrinsicck.rs @@ -1,3 +1,4 @@ +use errors::struct_span_err; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::DefId; use rustc::ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx}; diff --git a/src/librustc_passes/lib.rs b/src/librustc_passes/lib.rs index a692c45ced40b..f128d3891d7b8 100644 --- a/src/librustc_passes/lib.rs +++ b/src/librustc_passes/lib.rs @@ -14,8 +14,6 @@ extern crate rustc; #[macro_use] extern crate log; -#[macro_use] -extern crate syntax; use rustc::ty::query::Providers; diff --git a/src/librustc_passes/lib_features.rs b/src/librustc_passes/lib_features.rs index 2f486e3038fb8..a776f3e1bd240 100644 --- a/src/librustc_passes/lib_features.rs +++ b/src/librustc_passes/lib_features.rs @@ -4,6 +4,7 @@ // and `#[unstable (..)]`), but are not declared in one single location // (unlike lang features), which means we need to collect them instead. +use errors::struct_span_err; use rustc::hir::def_id::LOCAL_CRATE; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::middle::lib_features::LibFeatures; diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index f5011ceef142e..4d29ba4bd602d 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -2,7 +2,7 @@ use Context::*; use rustc::session::Session; -use errors::Applicability; +use errors::{struct_span_err, Applicability}; use rustc::hir::def_id::DefId; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; @@ -10,7 +10,6 @@ use rustc::hir::{self, Destination, Movability, Node}; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; use rustc_span::Span; -use syntax::struct_span_err; use rustc_error_codes::*; diff --git a/src/librustc_passes/region.rs b/src/librustc_passes/region.rs index 1004e639b6ef7..6d625a7dc2942 100644 --- a/src/librustc_passes/region.rs +++ b/src/librustc_passes/region.rs @@ -15,10 +15,10 @@ use rustc::middle::region::*; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; use rustc::util::nodemap::FxHashSet; - use rustc_index::vec::Idx; +use rustc_span::source_map; use rustc_span::Span; -use syntax::source_map; +use syntax::walk_list; use std::mem; diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index fcbc742b9a00b..0c96b3a4817ee 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -1,6 +1,7 @@ //! A pass that annotates every item and method with its stability level, //! propagating default levels lexically from parent to children ast nodes. +use errors::struct_span_err; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; diff --git a/src/librustc_plugin_impl/Cargo.toml b/src/librustc_plugin_impl/Cargo.toml index a9bbe429c00cc..0e873359e67ea 100644 --- a/src/librustc_plugin_impl/Cargo.toml +++ b/src/librustc_plugin_impl/Cargo.toml @@ -12,6 +12,7 @@ doctest = false [dependencies] rustc = { path = "../librustc" } +rustc_errors = { path = "../librustc_errors" } rustc_metadata = { path = "../librustc_metadata" } syntax = { path = "../libsyntax" } rustc_span = { path = "../librustc_span" } diff --git a/src/librustc_plugin_impl/load.rs b/src/librustc_plugin_impl/load.rs index 3010691dba20d..eff195292be73 100644 --- a/src/librustc_plugin_impl/load.rs +++ b/src/librustc_plugin_impl/load.rs @@ -3,6 +3,7 @@ use crate::Registry; use rustc::middle::cstore::MetadataLoader; use rustc::session::Session; +use rustc_errors::struct_span_err; use rustc_metadata::locator; use rustc_span::Span; @@ -11,7 +12,6 @@ use std::env; use std::mem; use std::path::PathBuf; use syntax::ast::{Crate, Ident}; -use syntax::struct_span_err; use syntax::symbol::sym; use rustc_error_codes::*; diff --git a/src/librustc_privacy/Cargo.toml b/src/librustc_privacy/Cargo.toml index e39c0b427dab1..59513d9ea5c91 100644 --- a/src/librustc_privacy/Cargo.toml +++ b/src/librustc_privacy/Cargo.toml @@ -10,6 +10,7 @@ path = "lib.rs" [dependencies] rustc = { path = "../librustc" } +rustc_errors = { path = "../librustc_errors" } rustc_typeck = { path = "../librustc_typeck" } syntax = { path = "../libsyntax" } rustc_span = { path = "../librustc_span" } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 6c3053f016bf0..3ac62d3b85a68 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -3,9 +3,6 @@ #![feature(nll)] #![recursion_limit = "256"] -#[macro_use] -extern crate syntax; - use rustc::bug; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; @@ -20,6 +17,7 @@ use rustc::ty::subst::InternalSubsts; use rustc::ty::{self, GenericParamDefKind, TraitRef, Ty, TyCtxt, TypeFoldable}; use rustc::util::nodemap::HirIdSet; use rustc_data_structures::fx::FxHashSet; +use rustc_errors::struct_span_err; use rustc_span::hygiene::Transparency; use rustc_span::Span; use syntax::ast::Ident; diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 911de5d2174e6..1690427991081 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -27,7 +27,7 @@ use rustc_data_structures::sync::Lrc; use std::cell::Cell; use std::ptr; -use errors::Applicability; +use errors::{struct_span_err, Applicability}; use rustc_expand::base::SyntaxExtension; use rustc_expand::expand::AstFragment; @@ -38,7 +38,6 @@ use syntax::ast::{AssocItem, AssocItemKind, MetaItemKind, StmtKind}; use syntax::ast::{Ident, Name}; use syntax::attr; use syntax::source_map::{respan, Spanned}; -use syntax::span_err; use syntax::symbol::{kw, sym}; use syntax::token::{self, Token}; use syntax::visit::{self, Visitor}; @@ -957,22 +956,27 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { for attr in &item.attrs { if attr.check_name(sym::macro_use) { if self.parent_scope.module.parent.is_some() { - span_err!( + struct_span_err!( self.r.session, item.span, E0468, "an `extern crate` loading macros must be at the crate root" - ); + ) + .emit(); } if let ItemKind::ExternCrate(Some(orig_name)) = item.kind { if orig_name == kw::SelfLower { - self.r.session.span_err( - attr.span, - "`macro_use` is not supported on `extern crate self`", - ); + self.r + .session + .struct_span_err( + attr.span, + "`macro_use` is not supported on `extern crate self`", + ) + .emit(); } } - let ill_formed = |span| span_err!(self.r.session, span, E0466, "bad macro import"); + let ill_formed = + |span| struct_span_err!(self.r.session, span, E0466, "bad macro import").emit(); match attr.meta() { Some(meta) => match meta.kind { MetaItemKind::Word => { @@ -1045,7 +1049,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { allow_shadowing, ); } else { - span_err!(self.r.session, ident.span, E0469, "imported macro not found"); + struct_span_err!(self.r.session, ident.span, E0469, "imported macro not found") + .emit(); } } } diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 2553ac6208c57..48aef0e352134 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -1,6 +1,6 @@ use std::cmp::Reverse; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use log::debug; use rustc::bug; use rustc::hir::def::Namespace::{self, *}; @@ -15,7 +15,6 @@ use rustc_span::{BytePos, MultiSpan, Span}; use syntax::ast::{self, Ident, Path}; use syntax::print::pprust; use syntax::source_map::SourceMap; -use syntax::struct_span_err; use syntax::symbol::{kw, Symbol}; use syntax::util::lev_distance::find_best_match_for_name; diff --git a/src/librustc_resolve/imports.rs b/src/librustc_resolve/imports.rs index c79a97f93f07f..8d09c1aacc0ca 100644 --- a/src/librustc_resolve/imports.rs +++ b/src/librustc_resolve/imports.rs @@ -11,7 +11,7 @@ use crate::{BindingKey, ModuleKind, ResolutionError, Resolver, Segment}; use crate::{CrateLint, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet, Weak}; use crate::{NameBinding, NameBindingKind, PathResult, PrivacyError, ToNameBinding}; -use errors::{pluralize, Applicability}; +use errors::{pluralize, struct_span_err, Applicability}; use rustc::hir::def::{self, Export, PartialRes}; use rustc::hir::def_id::DefId; @@ -27,8 +27,8 @@ use rustc_span::hygiene::ExpnId; use rustc_span::{MultiSpan, Span}; use syntax::ast::{Ident, Name, NodeId}; use syntax::symbol::kw; +use syntax::unwrap_or; use syntax::util::lev_distance::find_best_match_for_name; -use syntax::{struct_span_err, unwrap_or}; use rustc_error_codes::*; diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index a0d59fa4829e8..5c128b72e3490 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -11,6 +11,7 @@ use crate::{path_names_to_string, BindingError, CrateLint, LexicalScopeBinding}; use crate::{Module, ModuleOrUniformRoot, NameBindingKind, ParentScope, PathResult}; use crate::{ResolutionError, Resolver, Segment, UseError}; +use errors::DiagnosticId; use log::debug; use rustc::hir::def::Namespace::{self, *}; use rustc::hir::def::{self, CtorKind, DefKind, PartialRes, PerNS}; @@ -304,32 +305,21 @@ impl<'a> PathSource<'a> { } } - fn error_code(self, has_unexpected_resolution: bool) -> &'static str { - syntax::diagnostic_used!(E0404); - syntax::diagnostic_used!(E0405); - syntax::diagnostic_used!(E0412); - syntax::diagnostic_used!(E0422); - syntax::diagnostic_used!(E0423); - syntax::diagnostic_used!(E0425); - syntax::diagnostic_used!(E0531); - syntax::diagnostic_used!(E0532); - syntax::diagnostic_used!(E0573); - syntax::diagnostic_used!(E0574); - syntax::diagnostic_used!(E0575); - syntax::diagnostic_used!(E0576); + fn error_code(self, has_unexpected_resolution: bool) -> DiagnosticId { + use errors::error_code; match (self, has_unexpected_resolution) { - (PathSource::Trait(_), true) => "E0404", - (PathSource::Trait(_), false) => "E0405", - (PathSource::Type, true) => "E0573", - (PathSource::Type, false) => "E0412", - (PathSource::Struct, true) => "E0574", - (PathSource::Struct, false) => "E0422", - (PathSource::Expr(..), true) => "E0423", - (PathSource::Expr(..), false) => "E0425", - (PathSource::Pat, true) | (PathSource::TupleStruct, true) => "E0532", - (PathSource::Pat, false) | (PathSource::TupleStruct, false) => "E0531", - (PathSource::TraitItem(..), true) => "E0575", - (PathSource::TraitItem(..), false) => "E0576", + (PathSource::Trait(_), true) => error_code!(E0404), + (PathSource::Trait(_), false) => error_code!(E0405), + (PathSource::Type, true) => error_code!(E0573), + (PathSource::Type, false) => error_code!(E0412), + (PathSource::Struct, true) => error_code!(E0574), + (PathSource::Struct, false) => error_code!(E0422), + (PathSource::Expr(..), true) => error_code!(E0423), + (PathSource::Expr(..), false) => error_code!(E0425), + (PathSource::Pat, true) | (PathSource::TupleStruct, true) => error_code!(E0532), + (PathSource::Pat, false) | (PathSource::TupleStruct, false) => error_code!(E0531), + (PathSource::TraitItem(..), true) => error_code!(E0575), + (PathSource::TraitItem(..), false) => error_code!(E0576), } } } diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 5e59efac53647..cf8aed8962b4a 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -4,7 +4,7 @@ use crate::path_names_to_string; use crate::{CrateLint, Module, ModuleKind, ModuleOrUniformRoot}; use crate::{PathResult, PathSource, Segment}; -use errors::{Applicability, DiagnosticBuilder, DiagnosticId}; +use errors::{Applicability, DiagnosticBuilder}; use log::debug; use rustc::hir::def::Namespace::{self, *}; use rustc::hir::def::{self, CtorKind, DefKind}; @@ -73,7 +73,6 @@ impl<'a> LateResolutionVisitor<'a, '_> { let expected = source.descr_expected(); let path_str = Segment::names_to_string(path); let item_str = path.last().unwrap().ident; - let code = source.error_code(res.is_some()); let (base_msg, fallback_label, base_span, could_be_expr) = if let Some(res) = res { ( format!("expected {}, found {} `{}`", expected, res.descr(), path_str), @@ -123,7 +122,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { ) }; - let code = DiagnosticId::Error(code.into()); + let code = source.error_code(res.is_some()); let mut err = self.r.session.struct_span_err_with_code(base_span, &base_msg, code); // Emit help message for fake-self from other languages (e.g., `this` in Javascript). @@ -140,8 +139,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { // Emit special messages for unresolved `Self` and `self`. if is_self_type(path, ns) { - syntax::diagnostic_used!(E0411); - err.code(DiagnosticId::Error("E0411".into())); + err.code(errors::error_code!(E0411)); err.span_label( span, format!("`Self` is only available in impls, traits, and type definitions"), @@ -151,8 +149,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { if is_self_value(path, ns) { debug!("smart_resolve_path_fragment: E0424, source={:?}", source); - syntax::diagnostic_used!(E0424); - err.code(DiagnosticId::Error("E0424".into())); + err.code(errors::error_code!(E0424)); err.span_label(span, match source { PathSource::Pat => format!( "`self` value is a keyword and may not be bound to variables or shadowed", diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index b1be98834795a..6fbdaf2d14fe1 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -36,7 +36,7 @@ use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, NodeMap, NodeSet}; use rustc_metadata::creader::{CStore, CrateLoader}; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_expand::base::SyntaxExtension; use rustc_span::hygiene::{ExpnId, ExpnKind, MacroKind, SyntaxContext, Transparency}; use rustc_span::{Span, DUMMY_SP}; @@ -47,8 +47,8 @@ use syntax::attr; use syntax::print::pprust; use syntax::source_map::Spanned; use syntax::symbol::{kw, sym}; +use syntax::unwrap_or; use syntax::visit::{self, Visitor}; -use syntax::{struct_span_err, unwrap_or}; use log::debug; diff --git a/src/librustc_resolve/lifetimes.rs b/src/librustc_resolve/lifetimes.rs index 1f8573e44f1e1..52f1824024d58 100644 --- a/src/librustc_resolve/lifetimes.rs +++ b/src/librustc_resolve/lifetimes.rs @@ -11,7 +11,7 @@ use rustc::hir::map::Map; use rustc::hir::{GenericArg, GenericParam, LifetimeName, Node, ParamName, QPath}; use rustc::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt}; -use errors::{pluralize, Applicability, DiagnosticBuilder}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc::lint; use rustc::session::Session; use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet}; @@ -28,7 +28,7 @@ use rustc::hir::{self, GenericParamKind, LifetimeParamKind}; use log::debug; use rustc::{bug, span_bug}; -use syntax::{help, span_err, struct_span_err, walk_list}; +use syntax::walk_list; use rustc::middle::resolve_lifetime::*; use rustc_error_codes::*; @@ -592,13 +592,14 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { || krate.impl_items.contains_key(&parent_impl_id) || krate.trait_items.contains_key(&parent_trait_id)) { - span_err!( + struct_span_err!( self.tcx.sess, lifetime.span, E0657, "`impl Trait` can only capture lifetimes \ bound at the fn or impl level" - ); + ) + .emit(); self.uninsert_lifetime_on_error(lifetime, def.unwrap()); } } @@ -944,12 +945,13 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { }) { if self.trait_ref_hack { - span_err!( + struct_span_err!( self.tcx.sess, trait_ref.span, E0316, "nested quantification of lifetimes" - ); + ) + .emit(); } let next_early_index = self.next_early_index(); let scope = Scope::Binder { @@ -2434,36 +2436,32 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } if len == 0 { - help!( - db, - "this function's return type contains a borrowed value, but \ - there is no value for it to be borrowed from" + db.help( + "this function's return type contains a borrowed value, \ + but there is no value for it to be borrowed from", ); self.suggest_lifetime(db, span, "consider giving it a 'static lifetime") } else if elided_len == 0 { - help!( - db, + db.help( "this function's return type contains a borrowed value with \ an elided lifetime, but the lifetime cannot be derived from \ - the arguments" + the arguments", ); let msg = "consider giving it an explicit bounded or 'static lifetime"; self.suggest_lifetime(db, span, msg) } else if elided_len == 1 { - help!( - db, - "this function's return type contains a borrowed value, but \ - the signature does not say which {} it is borrowed from", + db.help(&format!( + "this function's return type contains a borrowed value, \ + but the signature does not say which {} it is borrowed from", m - ); + )); true } else { - help!( - db, - "this function's return type contains a borrowed value, but \ - the signature does not say whether it is borrowed from {}", + db.help(&format!( + "this function's return type contains a borrowed value, \ + but the signature does not say whether it is borrowed from {}", m - ); + )); true } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 8934fd4df742a..0e07bd969ce31 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -15,7 +15,7 @@ use crate::namespace::Namespace; use crate::require_c_abi_if_c_variadic; use crate::util::common::ErrorReported; use crate::util::nodemap::FxHashMap; -use errors::{Applicability, DiagnosticId}; +use errors::{struct_span_err, Applicability, DiagnosticId}; use rustc::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS; use rustc::traits; use rustc::ty::subst::{self, InternalSubsts, Subst, SubstsRef}; @@ -1118,13 +1118,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if unbound.is_none() { unbound = Some(&ptr.trait_ref); } else { - span_err!( + struct_span_err!( tcx.sess, span, E0203, "type parameter has more than one relaxed default \ bound, only one is supported" - ); + ) + .emit(); } } } @@ -1444,7 +1445,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } if regular_traits.is_empty() && auto_traits.is_empty() { - span_err!(tcx.sess, span, E0224, "at least one trait is required for an object type"); + struct_span_err!( + tcx.sess, + span, + E0224, + "at least one trait is required for an object type" + ) + .emit(); return tcx.types.err; } @@ -1599,13 +1606,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.ast_region_to_region(lifetime, None) } else { self.re_infer(None, span).unwrap_or_else(|| { - span_err!( + struct_span_err!( tcx.sess, span, E0228, "the lifetime bound for this object type cannot be deduced \ from context; please supply an explicit bound" - ); + ) + .emit(); tcx.lifetimes.re_static }) } @@ -2878,12 +2886,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // error. let r = derived_region_bounds[0]; if derived_region_bounds[1..].iter().any(|r1| r != *r1) { - span_err!( + struct_span_err!( tcx.sess, span, E0227, "ambiguous lifetime bound, explicit lifetime bound required" - ); + ) + .emit(); } return Some(r); } diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index 45c9922c579ce..8d2b7d6a39029 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -1,6 +1,7 @@ use super::method::MethodCallee; use super::{FnCtxt, Needs, PlaceOp}; +use errors::struct_span_err; use rustc::hir; use rustc::infer::{InferCtxt, InferOk}; use rustc::session::DiagnosticMessageId; diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 4b6bb2e05bfaa..19f9ee01b7566 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -1,8 +1,9 @@ use super::autoderef::Autoderef; use super::method::MethodCallee; use super::{Expectation, FnCtxt, Needs, TupleArgumentsFlag}; +use crate::type_error_struct; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use hir::def::Res; use hir::def_id::{DefId, LOCAL_CRATE}; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 445a723e3cb7d..13718dbf516c6 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -32,8 +32,9 @@ use super::FnCtxt; use crate::hir::def_id::DefId; use crate::lint; +use crate::type_error_struct; use crate::util::common::ErrorReported; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc::hir; use rustc::middle::lang_items; use rustc::session::Session; @@ -423,17 +424,16 @@ impl<'a, 'tcx> CastCheck<'tcx> { ); } Err(_) => { - span_help!(err, self.cast_span, "did you mean `&{}{}`?", mtstr, tstr) + let msg = &format!("did you mean `&{}{}`?", mtstr, tstr); + err.span_help(self.cast_span, msg); } } } else { - span_help!( - err, - self.span, + let msg = &format!( "consider using an implicit coercion to `&{}{}` instead", - mtstr, - tstr + mtstr, tstr ); + err.span_help(self.span, msg); } } ty::Adt(def, ..) if def.is_box() => { @@ -446,11 +446,13 @@ impl<'a, 'tcx> CastCheck<'tcx> { Applicability::MachineApplicable, ); } - Err(_) => span_help!(err, self.cast_span, "did you mean `Box<{}>`?", tstr), + Err(_) => { + err.span_help(self.cast_span, &format!("did you mean `Box<{}>`?", tstr)); + } } } _ => { - span_help!(err, self.expr.span, "consider using a box or reference as appropriate"); + err.span_help(self.expr.span, "consider using a box or reference as appropriate"); } } err.emit(); diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index e079b42f81d5e..4151706beebb6 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -51,7 +51,7 @@ //! we may want to adjust precisely when coercions occur. use crate::check::{FnCtxt, Needs}; -use errors::DiagnosticBuilder; +use errors::{struct_span_err, DiagnosticBuilder}; use rustc::hir; use rustc::hir::def_id::DefId; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index d6ef3889ee83d..eb714903da1ad 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -1,4 +1,4 @@ -use errors::{Applicability, DiagnosticId}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticId}; use rustc::hir::def::{DefKind, Res}; use rustc::hir::{self, GenericParamKind, ImplItemKind, TraitItemKind}; use rustc::infer::{self, InferOk}; @@ -8,9 +8,7 @@ use rustc::ty::subst::{InternalSubsts, Subst}; use rustc::ty::util::ExplicitSelf; use rustc::ty::{self, GenericParamDefKind, TyCtxt}; use rustc::util::common::ErrorReported; - use rustc_span::Span; -use syntax::errors::pluralize; use super::{potentially_plural_count, FnCtxt, Inherited}; diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 6f2d529bc34f7..a5764d0d9ea27 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -1,8 +1,8 @@ use crate::check::regionck::RegionCtxt; - use crate::hir; use crate::hir::def_id::DefId; use crate::util::common::ErrorReported; +use errors::struct_span_err; use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::{InferOk, SuppressRegionErrors}; use rustc::middle::region; diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 9ac047faa52fc..c4a09bd51bd5b 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -14,10 +14,11 @@ use crate::check::Expectation::{self, ExpectCastableToType, ExpectHasType, NoExp use crate::check::FnCtxt; use crate::check::Needs; use crate::check::TupleArgumentsFlag::DontTupleArguments; +use crate::type_error_struct; use crate::util::common::ErrorReported; use crate::util::nodemap::FxHashMap; -use errors::{pluralize, Applicability, DiagnosticBuilder, DiagnosticId}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc::hir; use rustc::hir::def::{CtorKind, DefKind, Res}; use rustc::hir::def_id::DefId; @@ -1108,13 +1109,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Prohibit struct expressions when non-exhaustive flag is set. let adt = adt_ty.ty_adt_def().expect("`check_struct_path` returned non-ADT type"); if !adt.did.is_local() && variant.is_field_list_non_exhaustive() { - span_err!( + struct_span_err!( self.tcx.sess, expr.span, E0639, "cannot create non-exhaustive {} using struct expression", adt.variant_descr() - ); + ) + .emit(); } let error_happened = self.check_expr_struct_fields( @@ -1152,12 +1154,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .insert(expr.hir_id, fru_field_types); } _ => { - span_err!( + struct_span_err!( self.tcx.sess, base_expr.span, E0436, "functional record update syntax requires a struct" - ); + ) + .emit(); } } } diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 66d3c797cf996..635bf01800f42 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -2,17 +2,16 @@ //! intrinsics that the compiler exposes. use crate::require_same_types; + +use errors::struct_span_err; +use rustc::hir; use rustc::traits::{ObligationCause, ObligationCauseCode}; use rustc::ty::subst::Subst; use rustc::ty::{self, Ty, TyCtxt}; - +use rustc_error_codes::*; use rustc_target::spec::abi::Abi; use syntax::symbol::Symbol; -use rustc::hir; - -use rustc_error_codes::*; - use std::iter; fn equate_intrinsic_type<'tcx>( @@ -413,19 +412,20 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) (2, params, param(1)) } Err(_) => { - span_err!( + struct_span_err!( tcx.sess, it.span, E0439, "invalid `simd_shuffle`, needs length: `{}`", name - ); + ) + .emit(); return; } }, _ => { let msg = format!("unrecognized platform-specific intrinsic function: `{}`", name); - tcx.sess.span_err(it.span, &msg); + tcx.sess.struct_span_err(it.span, &msg).emit(); return; } }; diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index acf449d384cca..7458fd53a931f 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -9,6 +9,7 @@ use crate::hir::def::DefKind; use crate::hir::def_id::DefId; use crate::namespace::Namespace; +use errors::struct_span_err; use rustc::hir; use rustc::infer::canonical::OriginalQueryValues; use rustc::infer::canonical::{Canonical, QueryResponse}; @@ -373,13 +374,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // so we do a future-compat lint here for the 2015 edition // (see https://github.com/rust-lang/rust/issues/46906) if self.tcx.sess.rust_2018() { - span_err!( + struct_span_err!( self.tcx.sess, span, E0699, "the type of this value must be known \ to call a method on a raw pointer on it" - ); + ) + .emit(); } else { self.tcx.lint_hir( lint::builtin::TYVAR_BEHIND_RAW_POINTER, diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 7c5671f0f5024..b9f792b819a5b 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -5,7 +5,7 @@ use crate::check::FnCtxt; use crate::middle::lang_items::FnOnceTraitLangItem; use crate::namespace::Namespace; use crate::util::nodemap::FxHashSet; -use errors::{pluralize, Applicability, DiagnosticBuilder}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::hir::map as hir_map; @@ -191,21 +191,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let item_span = self.tcx.sess.source_map().def_span(self.tcx.def_span(item.def_id)); let idx = if sources.len() > 1 { - span_note!( - err, - item_span, + let msg = &format!( "candidate #{} is defined in the trait `{}`", idx + 1, self.tcx.def_path_str(trait_did) ); + err.span_note(item_span, msg); Some(idx + 1) } else { - span_note!( - err, - item_span, + let msg = &format!( "the candidate is defined in the trait `{}`", self.tcx.def_path_str(trait_did) ); + err.span_note(item_span, msg); None }; let path = self.tcx.def_path_str(trait_did); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 86f92ce9b8923..1ff8821816fad 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -90,7 +90,7 @@ pub mod writeback; use crate::astconv::{AstConv, PathSeg}; use crate::middle::lang_items; use crate::namespace::Namespace; -use errors::{pluralize, Applicability, DiagnosticBuilder, DiagnosticId}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc::hir::def::{CtorOf, DefKind, Res}; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; @@ -155,6 +155,17 @@ use self::method::{MethodCallee, SelfSource}; pub use self::Expectation::*; use self::TupleArgumentsFlag::*; +#[macro_export] +macro_rules! type_error_struct { + ($session:expr, $span:expr, $typ:expr, $code:ident, $($message:tt)*) => ({ + if $typ.references_error() { + $session.diagnostic().struct_dummy() + } else { + errors::struct_span_err!($session, $span, $code, $($message)*) + } + }) +} + /// The type of a local binding, including the revealed type for anon types. #[derive(Copy, Clone, Debug)] pub struct LocalTy<'tcx> { @@ -2088,7 +2099,7 @@ fn check_impl_items_against_trait<'tcx>( if !invalidated_items.is_empty() { let invalidator = overridden_associated_type.unwrap(); - span_err!( + struct_span_err!( tcx.sess, invalidator.span, E0399, @@ -2096,6 +2107,7 @@ fn check_impl_items_against_trait<'tcx>( invalidator.ident, invalidated_items.iter().map(|name| name.to_string()).collect::>().join("`, `") ) + .emit(); } } @@ -2238,7 +2250,7 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) { if def.is_struct() { let fields = &def.non_enum_variant().fields; if fields.is_empty() { - span_err!(tcx.sess, sp, E0075, "SIMD vector cannot be empty"); + struct_span_err!(tcx.sess, sp, E0075, "SIMD vector cannot be empty").emit(); return; } let e = fields[0].ty(tcx, substs); @@ -2252,12 +2264,13 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) { ty::Param(_) => { /* struct(T, T, T, T) is ok */ } _ if e.is_machine() => { /* struct(u8, u8, u8, u8) is ok */ } _ => { - span_err!( + struct_span_err!( tcx.sess, sp, E0077, "SIMD vector element type should be machine type" - ); + ) + .emit(); return; } } @@ -2542,14 +2555,15 @@ pub fn check_enum<'tcx>( } fn report_unexpected_variant_res(tcx: TyCtxt<'_>, res: Res, span: Span, qpath: &QPath<'_>) { - span_err!( + struct_span_err!( tcx.sess, span, E0533, "expected unit struct, unit variant or constant, found {} `{}`", res.descr(), hir::print::to_string(tcx.hir(), |s| s.print_qpath(qpath, false)) - ); + ) + .emit(); } impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { @@ -3759,13 +3773,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { arg_types.iter().map(|k| k.expect_ty()).collect() } _ => { - span_err!( + struct_span_err!( tcx.sess, sp, E0059, "cannot use call notation; the first type parameter \ for the function trait is neither a tuple nor unit" - ); + ) + .emit(); expected_arg_tys = vec![]; self.err_args(args.len()) } diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index e0035c4afc7cc..0560f008c7d62 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -2,7 +2,7 @@ use super::method::MethodCallee; use super::{FnCtxt, Needs}; -use errors::{self, Applicability}; +use errors::{self, struct_span_err, Applicability}; use rustc::hir; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index 251c8427ffd54..703ee76fe0be6 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -1,6 +1,6 @@ use crate::check::FnCtxt; use crate::util::nodemap::FxHashMap; -use errors::{pluralize, Applicability, DiagnosticBuilder}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc::hir::def::{CtorKind, DefKind, Res}; use rustc::hir::pat_util::EnumerateAndAdjustIterator; use rustc::hir::{self, HirId, Pat, PatKind}; @@ -982,22 +982,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Require `..` if struct has non_exhaustive attribute. if variant.is_field_list_non_exhaustive() && !adt.did.is_local() && !etc { - span_err!( + struct_span_err!( tcx.sess, span, E0638, "`..` required with {} marked as non-exhaustive", kind_name - ); + ) + .emit(); } // Report an error if incorrect number of the fields were specified. if kind_name == "union" { if fields.len() != 1 { - tcx.sess.span_err(span, "union patterns should have exactly one field"); + tcx.sess + .struct_span_err(span, "union patterns should have exactly one field") + .emit(); } if etc { - tcx.sess.span_err(span, "`..` cannot be used in union patterns"); + tcx.sess.struct_span_err(span, "`..` cannot be used in union patterns").emit(); } } else if !etc && unmentioned_fields.len() > 0 { self.error_unmentioned_fields(span, &unmentioned_fields, variant); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index bf2c6776d1aa5..11afbd79141e0 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -2,14 +2,13 @@ use crate::check::{FnCtxt, Inherited}; use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter}; use crate::hir::def_id::DefId; +use errors::{struct_span_err, DiagnosticBuilder}; use rustc::infer::opaque_types::may_define_opaque_type; use rustc::middle::lang_items; use rustc::traits::{self, ObligationCause, ObligationCauseCode}; use rustc::ty::subst::{InternalSubsts, Subst}; use rustc::ty::{self, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable}; use rustc::util::nodemap::{FxHashMap, FxHashSet}; - -use errors::DiagnosticBuilder; use rustc_span::Span; use syntax::ast; use syntax::feature_gate; @@ -112,13 +111,14 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: DefId) { ty::ImplPolarity::Negative => { // FIXME(#27579): what amount of WF checking do we need for neg impls? if trait_ref.is_some() && !is_auto { - span_err!( + struct_span_err!( tcx.sess, item.span, E0192, "negative impls are only allowed for \ auto traits (e.g., `Send` and `Sync`)" ) + .emit() } } ty::ImplPolarity::Reservation => { diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 7f7e21838d22f..a41fb19d327c5 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -1,22 +1,19 @@ //! Check properties that are required by built-in traits and set //! up data structures required by type-checking/codegen. +use errors::struct_span_err; +use rustc::hir::def_id::DefId; +use rustc::hir::{self, ItemKind, Node}; +use rustc::infer; use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::SuppressRegionErrors; use rustc::middle::lang_items::UnsizeTraitLangItem; use rustc::middle::region; - -use rustc::infer; use rustc::traits::{self, ObligationCause, TraitEngine}; use rustc::ty::adjustment::CoerceUnsizedInfo; use rustc::ty::util::CopyImplementationError; use rustc::ty::TypeFoldable; use rustc::ty::{self, Ty, TyCtxt}; - -use hir::Node; -use rustc::hir::def_id::DefId; -use rustc::hir::{self, ItemKind}; - use rustc_error_codes::*; pub fn check_trait(tcx: TyCtxt<'_>, trait_def_id: DefId) { @@ -401,7 +398,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn if def_a != def_b { let source_path = tcx.def_path_str(def_a.did); let target_path = tcx.def_path_str(def_b.did); - span_err!( + struct_span_err!( tcx.sess, span, E0377, @@ -410,7 +407,8 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn definition; expected `{}`, found `{}`", source_path, target_path - ); + ) + .emit(); return err_info; } @@ -487,14 +485,15 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn .collect::>(); if diff_fields.is_empty() { - span_err!( + struct_span_err!( tcx.sess, span, E0374, "the trait `CoerceUnsized` may only be implemented \ for a coercion between structures with one field \ being coerced, none found" - ); + ) + .emit(); return err_info; } else if diff_fields.len() > 1 { let item = tcx.hir().expect_item(impl_hir_id); @@ -504,19 +503,19 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn tcx.hir().span(impl_hir_id) }; - let mut err = struct_span_err!( + struct_span_err!( tcx.sess, span, E0375, "implementing the trait \ `CoerceUnsized` requires multiple \ coercions" - ); - err.note( + ) + .note( "`CoerceUnsized` may only be implemented for \ a coercion between structures with one field being coerced", - ); - err.note(&format!( + ) + .note(&format!( "currently, {} fields need coercions: {}", diff_fields.len(), diff_fields @@ -526,9 +525,9 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn }) .collect::>() .join(", ") - )); - err.span_label(span, "requires multiple coercions"); - err.emit(); + )) + .span_label(span, "requires multiple coercions") + .emit(); return err_info; } @@ -538,13 +537,14 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn } _ => { - span_err!( + struct_span_err!( tcx.sess, span, E0376, "the trait `CoerceUnsized` may only be implemented \ for a coercion between structures" - ); + ) + .emit(); return err_info; } }; diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 4e75134a04cfd..67357964be9c5 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -7,6 +7,7 @@ //! `tcx.inherent_impls(def_id)`). That value, however, //! is computed by selecting an idea from this table. +use errors::struct_span_err; use rustc::hir; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::hir::itemlikevisit::ItemLikeVisitor; diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index 76eb8f5379c0e..a78e879b8d5b1 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -1,10 +1,10 @@ use crate::namespace::Namespace; +use errors::struct_span_err; use rustc::hir; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::traits::{self, IntercrateMode}; use rustc::ty::TyCtxt; - use rustc_error_codes::*; pub fn crate_inherent_impls_overlap_check(tcx: TyCtxt<'_>, crate_num: CrateNum) { diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index cba0436774d15..8071135f50ce5 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -7,6 +7,7 @@ use crate::hir::def_id::{DefId, LOCAL_CRATE}; use crate::hir::HirId; +use errors::struct_span_err; use rustc::traits; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt, TypeFoldable}; diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index b387a5d152017..3c6cf99b1780d 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -1,6 +1,7 @@ //! Orphan checker: every impl either implements a trait defined in this //! crate or pertains to a type defined in this crate. +use errors::struct_span_err; use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::traits; diff --git a/src/librustc_typeck/coherence/unsafety.rs b/src/librustc_typeck/coherence/unsafety.rs index eee292c55a8a4..296388210f00b 100644 --- a/src/librustc_typeck/coherence/unsafety.rs +++ b/src/librustc_typeck/coherence/unsafety.rs @@ -1,10 +1,10 @@ //! Unsafety checker: every impl either implements a trait defined in this //! crate or pertains to a type defined in this crate. +use errors::struct_span_err; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::{self, Unsafety}; use rustc::ty::TyCtxt; - use rustc_error_codes::*; pub fn check(tcx: TyCtxt<'_>) { @@ -32,23 +32,25 @@ impl UnsafetyChecker<'tcx> { }); match (trait_def.unsafety, unsafe_attr, unsafety, polarity) { (Unsafety::Normal, None, Unsafety::Unsafe, hir::ImplPolarity::Positive) => { - span_err!( + struct_span_err!( self.tcx.sess, item.span, E0199, "implementing the trait `{}` is not unsafe", trait_ref.print_only_trait_path() - ); + ) + .emit(); } (Unsafety::Unsafe, _, Unsafety::Normal, hir::ImplPolarity::Positive) => { - span_err!( + struct_span_err!( self.tcx.sess, item.span, E0200, "the trait `{}` requires an `unsafe impl` declaration", trait_ref.print_only_trait_path() - ); + ) + .emit(); } ( @@ -57,13 +59,14 @@ impl UnsafetyChecker<'tcx> { Unsafety::Normal, hir::ImplPolarity::Positive, ) => { - span_err!( + struct_span_err!( self.tcx.sess, item.span, E0569, "requires an `unsafe impl` declaration due to `#[{}]` attribute", attr_name - ); + ) + .emit(); } (_, _, Unsafety::Unsafe, hir::ImplPolarity::Negative) => { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index dfbeb0353a61c..ad2d010a32663 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -46,7 +46,7 @@ use rustc::hir::GenericParamKind; use rustc::hir::Node; use rustc::hir::{self, CodegenFnAttrFlags, CodegenFnAttrs, Unsafety}; -use errors::{Applicability, StashKey}; +use errors::{struct_span_err, Applicability, StashKey}; use rustc_error_codes::*; @@ -321,13 +321,14 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> { self.tcx().mk_projection(item_def_id, item_substs) } else { // There are no late-bound regions; we can just ignore the binder. - span_err!( + struct_span_err!( self.tcx().sess, span, E0212, "cannot extract an associated type from a higher-ranked trait bound \ in this context" - ); + ) + .emit(); self.tcx().types.err } } @@ -862,17 +863,14 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TraitDef { let paren_sugar = tcx.has_attr(def_id, sym::rustc_paren_sugar); if paren_sugar && !tcx.features().unboxed_closures { - let mut err = tcx.sess.struct_span_err( - item.span, - "the `#[rustc_paren_sugar]` attribute is a temporary means of controlling \ + tcx.sess + .struct_span_err( + item.span, + "the `#[rustc_paren_sugar]` attribute is a temporary means of controlling \ which traits can use parenthetical notation", - ); - help!( - &mut err, - "add `#![feature(unboxed_closures)]` to \ - the crate attributes to use it" - ); - err.emit(); + ) + .help("add `#![feature(unboxed_closures)]` to the crate attributes to use it") + .emit(); } let is_marker = tcx.has_attr(def_id, sym::marker); @@ -1207,12 +1205,13 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics { } fn report_assoc_ty_on_inherent_impl(tcx: TyCtxt<'_>, span: Span) { - span_err!( + struct_span_err!( tcx.sess, span, E0202, "associated types are not yet supported in inherent impls (see #8995)" - ); + ) + .emit(); } fn infer_placeholder_type( @@ -2768,14 +2767,26 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { mark_used(attr); inline_span = Some(attr.span); if items.len() != 1 { - span_err!(tcx.sess.diagnostic(), attr.span, E0534, "expected one argument"); + struct_span_err!( + tcx.sess.diagnostic(), + attr.span, + E0534, + "expected one argument" + ) + .emit(); InlineAttr::None } else if list_contains_name(&items[..], sym::always) { InlineAttr::Always } else if list_contains_name(&items[..], sym::never) { InlineAttr::Never } else { - span_err!(tcx.sess.diagnostic(), items[0].span(), E0535, "invalid argument"); + struct_span_err!( + tcx.sess.diagnostic(), + items[0].span(), + E0535, + "invalid argument" + ) + .emit(); InlineAttr::None } @@ -2789,7 +2800,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { if !attr.has_name(sym::optimize) { return ia; } - let err = |sp, s| span_err!(tcx.sess.diagnostic(), sp, E0722, "{}", s); + let err = |sp, s| struct_span_err!(tcx.sess.diagnostic(), sp, E0722, "{}", s).emit(); match attr.meta().map(|i| i.kind) { Some(MetaItemKind::Word) => { err(attr.span, "expected one argument"); diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index 82632bbc17c05..50875c99c5ea2 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -9,6 +9,7 @@ //! fixed, but for the moment it's easier to do these checks early. use crate::constrained_generic_params as cgp; +use errors::struct_span_err; use rustc::hir; use rustc::hir::def_id::DefId; use rustc::hir::itemlikevisit::ItemLikeVisitor; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 289a4dc3ecb6d..4006c3114788e 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -71,8 +71,6 @@ This API is completely unstable and subject to change. #[macro_use] extern crate log; -#[macro_use] -extern crate syntax; #[macro_use] extern crate rustc; @@ -93,6 +91,7 @@ mod outlives; mod structured_errors; mod variance; +use errors::struct_span_err; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::hir::{self, Node}; use rustc::infer::InferOk; diff --git a/src/librustc_typeck/outlives/test.rs b/src/librustc_typeck/outlives/test.rs index 13430b752c11a..a99518a98df42 100644 --- a/src/librustc_typeck/outlives/test.rs +++ b/src/librustc_typeck/outlives/test.rs @@ -1,9 +1,9 @@ +use errors::struct_span_err; use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::ty::TyCtxt; -use syntax::symbol::sym; - use rustc_error_codes::*; +use syntax::symbol::sym; pub fn test_inferred_outlives(tcx: TyCtxt<'_>) { tcx.hir().krate().visit_all_item_likes(&mut OutlivesTest { tcx }); @@ -21,7 +21,7 @@ impl ItemLikeVisitor<'tcx> for OutlivesTest<'tcx> { // attribute and report an error with various results if found. if self.tcx.has_attr(item_def_id, sym::rustc_outlives) { let inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id); - span_err!(self.tcx.sess, item.span, E0640, "{:?}", inferred_outlives_of); + struct_span_err!(self.tcx.sess, item.span, E0640, "{:?}", inferred_outlives_of).emit(); } } diff --git a/src/librustc_typeck/structured_errors.rs b/src/librustc_typeck/structured_errors.rs index 251732b6f1233..dc6c45b41842c 100644 --- a/src/librustc_typeck/structured_errors.rs +++ b/src/librustc_typeck/structured_errors.rs @@ -50,8 +50,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for VariadicError<'tcx> { } fn code(&self) -> DiagnosticId { - syntax::diagnostic_used!(E0617); - DiagnosticId::Error("E0617".to_owned()) + errors::error_code!(E0617) } fn common(&self) -> DiagnosticBuilder<'tcx> { @@ -112,8 +111,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCastError<'tcx> { } fn code(&self) -> DiagnosticId { - syntax::diagnostic_used!(E0607); - DiagnosticId::Error("E0607".to_owned()) + errors::error_code!(E0607) } fn common(&self) -> DiagnosticBuilder<'tcx> { diff --git a/src/librustc_typeck/variance/test.rs b/src/librustc_typeck/variance/test.rs index f098fb9de1009..6797c0086d23d 100644 --- a/src/librustc_typeck/variance/test.rs +++ b/src/librustc_typeck/variance/test.rs @@ -1,3 +1,4 @@ +use errors::struct_span_err; use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::ty::TyCtxt; @@ -21,7 +22,7 @@ impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> { // attribute and report an error with various results if found. if self.tcx.has_attr(item_def_id, sym::rustc_variance) { let variances_of = self.tcx.variances_of(item_def_id); - span_err!(self.tcx.sess, item.span, E0208, "{:?}", variances_of); + struct_span_err!(self.tcx.sess, item.span, E0208, "{:?}", variances_of).emit(); } } diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 04c28dd5c5bcb..b308d479545be 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -6,7 +6,7 @@ use crate::feature_gate::feature_err; use crate::print::pprust; use crate::sess::ParseSess; -use errors::{Applicability, Handler}; +use errors::{struct_span_err, Applicability, Handler}; use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg}; use rustc_macros::HashStable_Generic; use rustc_span::hygiene::Transparency; @@ -31,17 +31,21 @@ enum AttrError { fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) { let diag = &sess.span_diagnostic; match error { - AttrError::MultipleItem(item) => span_err!(diag, span, E0538, "multiple '{}' items", item), + AttrError::MultipleItem(item) => { + struct_span_err!(diag, span, E0538, "multiple '{}' items", item).emit(); + } AttrError::UnknownMetaItem(item, expected) => { let expected = expected.iter().map(|name| format!("`{}`", name)).collect::>(); struct_span_err!(diag, span, E0541, "unknown meta item '{}'", item) .span_label(span, format!("expected one of {}", expected.join(", "))) .emit(); } - AttrError::MissingSince => span_err!(diag, span, E0542, "missing 'since'"), - AttrError::MissingFeature => span_err!(diag, span, E0546, "missing 'feature'"), + AttrError::MissingSince => struct_span_err!(diag, span, E0542, "missing 'since'").emit(), + AttrError::MissingFeature => { + struct_span_err!(diag, span, E0546, "missing 'feature'").emit(); + } AttrError::MultipleStabilityLevels => { - span_err!(diag, span, E0544, "multiple stability levels") + struct_span_err!(diag, span, E0544, "multiple stability levels").emit(); } AttrError::UnsupportedLiteral(msg, is_bytestr) => { let mut err = struct_span_err!(diag, span, E0565, "{}", msg); @@ -283,7 +287,7 @@ where *item = Some(v); true } else { - span_err!(diagnostic, meta.span, E0539, "incorrect meta item"); + struct_span_err!(diagnostic, meta.span, E0539, "incorrect meta item").emit(); false } }; @@ -331,12 +335,13 @@ where match meta_name { sym::rustc_deprecated => { if rustc_depr.is_some() { - span_err!( + struct_span_err!( diagnostic, item_sp, E0540, "multiple rustc_deprecated attributes" - ); + ) + .emit(); continue 'outer; } @@ -351,7 +356,8 @@ where continue; } _ => { - span_err!(diagnostic, attr.span, E0543, "missing 'reason'"); + struct_span_err!(diagnostic, attr.span, E0543, "missing 'reason'") + .emit(); continue; } } @@ -426,12 +432,13 @@ where // Disallowing this requires updates to some submodules NonZeroU32::new(num) } else { - span_err!( + struct_span_err!( diagnostic, attr.span, E0545, "incorrect 'issue'" - ); + ) + .emit(); continue; } } @@ -453,7 +460,8 @@ where continue; } _ => { - span_err!(diagnostic, attr.span, E0547, "missing 'issue'"); + struct_span_err!(diagnostic, attr.span, E0547, "missing 'issue'") + .emit(); continue; } } @@ -539,13 +547,14 @@ where if let Some(ref mut stab) = stab { stab.rustc_depr = Some(rustc_depr); } else { - span_err!( + struct_span_err!( diagnostic, item_sp, E0549, "rustc_deprecated attribute must be paired with \ either stable or unstable attribute" - ); + ) + .emit(); } } @@ -555,14 +564,15 @@ where stab.promotable = promotable; stab.allow_const_fn_ptr = allow_const_fn_ptr; } else { - span_err!( + struct_span_err!( diagnostic, item_sp, E0717, "rustc_promotable and rustc_allow_const_fn_ptr attributes \ must be paired with either a rustc_const_unstable or a rustc_const_stable \ attribute" - ); + ) + .emit(); } } @@ -649,20 +659,27 @@ pub fn eval_condition( } sym::not => { if mis.len() != 1 { - span_err!(sess.span_diagnostic, cfg.span, E0536, "expected 1 cfg-pattern"); + struct_span_err!( + sess.span_diagnostic, + cfg.span, + E0536, + "expected 1 cfg-pattern" + ) + .emit(); return false; } !eval_condition(mis[0].meta_item().unwrap(), sess, eval) } _ => { - span_err!( + struct_span_err!( sess.span_diagnostic, cfg.span, E0537, "invalid predicate `{}`", pprust::path_to_string(&cfg.path) - ); + ) + .emit(); false } } @@ -703,7 +720,7 @@ where } if depr.is_some() { - span_err!(diagnostic, item_sp, E0550, "multiple deprecated attributes"); + struct_span_err!(diagnostic, item_sp, E0550, "multiple deprecated attributes").emit(); break; } @@ -741,7 +758,8 @@ where ), ); } else { - span_err!(diagnostic, meta.span, E0551, "incorrect meta item"); + struct_span_err!(diagnostic, meta.span, E0551, "incorrect meta item") + .emit(); } false @@ -900,13 +918,14 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec { }; } if let Some(literal_error) = literal_error { - span_err!( + struct_span_err!( diagnostic, item.span(), E0589, "invalid `repr(align)` attribute: {}", literal_error - ); + ) + .emit(); } } else { if let Some(meta_item) = item.meta_item() { @@ -945,7 +964,13 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec { } if !recognised { // Not a word we recognize - span_err!(diagnostic, item.span(), E0552, "unrecognized representation hint"); + struct_span_err!( + diagnostic, + item.span(), + E0552, + "unrecognized representation hint" + ) + .emit(); } } } diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs deleted file mode 100644 index 4ed17418c30ba..0000000000000 --- a/src/libsyntax/diagnostics/macros.rs +++ /dev/null @@ -1,169 +0,0 @@ -#[macro_export] -macro_rules! diagnostic_used { - ($code:ident) => { - let _ = $code; - }; -} - -#[macro_export] -macro_rules! span_fatal { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.span_fatal_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! span_err { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.span_err_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! span_warn { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.span_warn_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! struct_err { - ($session:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.struct_err_with_code( - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! span_err_or_warn { - ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - if $is_warning { - $session.span_warn_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - } else { - $session.span_err_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - } - }) -} - -#[macro_export] -macro_rules! struct_span_fatal { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.struct_span_fatal_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! struct_span_err { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.struct_span_err_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! stringify_error_code { - ($code:ident) => {{ - $crate::diagnostic_used!($code); - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()) - }}; -} - -#[macro_export] -macro_rules! type_error_struct { - ($session:expr, $span:expr, $typ:expr, $code:ident, $($message:tt)*) => ({ - if $typ.references_error() { - $session.diagnostic().struct_dummy() - } else { - struct_span_err!($session, $span, $code, $($message)*) - } - }) -} - -#[macro_export] -macro_rules! struct_span_warn { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.struct_span_warn_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! struct_span_err_or_warn { - ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - if $is_warning { - $session.struct_span_warn_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - } else { - $session.struct_span_err_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - } - }) -} - -#[macro_export] -macro_rules! span_note { - ($err:expr, $span:expr, $($message:tt)*) => ({ - ($err).span_note($span, &format!($($message)*)); - }) -} - -#[macro_export] -macro_rules! span_help { - ($err:expr, $span:expr, $($message:tt)*) => ({ - ($err).span_help($span, &format!($($message)*)); - }) -} - -#[macro_export] -macro_rules! help { - ($err:expr, $($message:tt)*) => ({ - ($err).help(&format!($($message)*)); - }) -} diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index e5635eaf1e915..4e48c6a95a578 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -14,7 +14,7 @@ use crate::source_map::Spanned; use crate::symbol::{sym, Symbol}; use crate::visit::{self, FnKind, Visitor}; -use errors::{Applicability, DiagnosticBuilder, Handler}; +use errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder, Handler}; use log::debug; use rustc_data_structures::fx::FxHashMap; use rustc_span::{MultiSpan, Span, DUMMY_SP}; @@ -92,9 +92,7 @@ fn leveled_feature_err<'a>( let diag = &sess.span_diagnostic; let mut err = match level { - GateStrength::Hard => { - diag.struct_span_err_with_code(span, explain, stringify_error_code!(E0658)) - } + GateStrength::Hard => diag.struct_span_err_with_code(span, explain, error_code!(E0658)), GateStrength::Soft => diag.struct_span_warn(span, explain), }; @@ -828,15 +826,9 @@ pub fn get_features( }; if let Some(edition) = edition_enabled_features.get(&name) { - struct_span_warn!( - span_handler, - mi.span(), - E0705, - "the feature `{}` is included in the Rust {} edition", - name, - edition, - ) - .emit(); + let msg = + &format!("the feature `{}` is included in the Rust {} edition", name, edition); + span_handler.struct_span_warn_with_code(mi.span(), msg, error_code!(E0705)).emit(); continue; } @@ -864,13 +856,14 @@ pub fn get_features( if let Some(allowed) = allow_features.as_ref() { if allowed.iter().find(|&f| name.as_str() == *f).is_none() { - span_err!( + struct_span_err!( span_handler, mi.span(), E0725, "the feature `{}` is not in the list of allowed features", name - ); + ) + .emit(); continue; } } @@ -954,13 +947,14 @@ pub fn check_crate( fn maybe_stage_features(span_handler: &Handler, krate: &ast::Crate, unstable: UnstableFeatures) { if !unstable.is_nightly_build() { for attr in krate.attrs.iter().filter(|attr| attr.check_name(sym::feature)) { - span_err!( + struct_span_err!( span_handler, attr.span, E0554, "`#![feature]` may not be used on the {} release channel", option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)") - ); + ) + .emit(); } } } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index b537f16ffcd9a..6fa9a8ffcf8a3 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -68,12 +68,6 @@ where scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals); -#[macro_use] -pub mod diagnostics { - #[macro_use] - pub mod macros; -} - pub mod util { pub mod classify; pub mod comments; diff --git a/src/test/ui/conflicting-repr-hints.stderr b/src/test/ui/conflicting-repr-hints.stderr index 414c15f93bc18..48ddd4503eebd 100644 --- a/src/test/ui/conflicting-repr-hints.stderr +++ b/src/test/ui/conflicting-repr-hints.stderr @@ -3,6 +3,8 @@ warning[E0566]: conflicting representation hints | LL | #[repr(C, u64)] | ^ ^^^ + | + = note: `#[warn(conflicting_repr_hints)]` on by default warning[E0566]: conflicting representation hints --> $DIR/conflicting-repr-hints.rs:12:8 diff --git a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr index 02c8400e03e82..d79d4ae27f11e 100644 --- a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr +++ b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr @@ -23,6 +23,8 @@ LL | #[repr(C)] | ^ LL | #[repr(simd)] | ^^^^ + | + = note: `#[warn(conflicting_repr_hints)]` on by default error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-14221.stderr b/src/test/ui/issues/issue-14221.stderr index 3e5e25a9f6d1f..a5dae1a1ce38b 100644 --- a/src/test/ui/issues/issue-14221.stderr +++ b/src/test/ui/issues/issue-14221.stderr @@ -3,6 +3,8 @@ warning[E0170]: pattern binding `A` is named the same as one of the variants of | LL | A => "A", | ^ help: to match on the variant, qualify the path: `E::A` + | + = note: `#[warn(binding_variant_name)]` on by default warning[E0170]: pattern binding `B` is named the same as one of the variants of the type `E` --> $DIR/issue-14221.rs:15:13 diff --git a/src/test/ui/issues/issue-19100.stderr b/src/test/ui/issues/issue-19100.stderr index 1ab13477e37ed..e7dd2c1e681d7 100644 --- a/src/test/ui/issues/issue-19100.stderr +++ b/src/test/ui/issues/issue-19100.stderr @@ -3,6 +3,8 @@ warning[E0170]: pattern binding `Bar` is named the same as one of the variants o | LL | Bar if true | ^^^ help: to match on the variant, qualify the path: `Foo::Bar` + | + = note: `#[warn(binding_variant_name)]` on by default warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` --> $DIR/issue-19100.rs:22:1 diff --git a/src/test/ui/issues/issue-30302.stderr b/src/test/ui/issues/issue-30302.stderr index d762d6f2b3d5e..14ae9aa5a7b50 100644 --- a/src/test/ui/issues/issue-30302.stderr +++ b/src/test/ui/issues/issue-30302.stderr @@ -3,6 +3,8 @@ warning[E0170]: pattern binding `Nil` is named the same as one of the variants o | LL | Nil => true, | ^^^ help: to match on the variant, qualify the path: `Stack::Nil` + | + = note: `#[warn(binding_variant_name)]` on by default error: unreachable pattern --> $DIR/issue-30302.rs:15:9 diff --git a/src/test/ui/issues/issue-39720.stderr b/src/test/ui/issues/issue-39720.stderr index 8121ed2894045..e33fc823fbecc 100644 --- a/src/test/ui/issues/issue-39720.stderr +++ b/src/test/ui/issues/issue-39720.stderr @@ -5,6 +5,8 @@ LL | #[repr(C)] | ^ LL | #[repr(simd)] | ^^^^ + | + = note: `#[warn(conflicting_repr_hints)]` on by default warning[E0566]: conflicting representation hints --> $DIR/issue-39720.rs:13:8 diff --git a/src/test/ui/issues/issue-47094.stderr b/src/test/ui/issues/issue-47094.stderr index 16bcec0c7bb3a..570fe53c26352 100644 --- a/src/test/ui/issues/issue-47094.stderr +++ b/src/test/ui/issues/issue-47094.stderr @@ -3,6 +3,8 @@ warning[E0566]: conflicting representation hints | LL | #[repr(C,u8)] | ^ ^^ + | + = note: `#[warn(conflicting_repr_hints)]` on by default warning[E0566]: conflicting representation hints --> $DIR/issue-47094.rs:9:8 diff --git a/src/test/ui/lint/lint-uppercase-variables.stderr b/src/test/ui/lint/lint-uppercase-variables.stderr index f614d5d71f88c..0519a63e05585 100644 --- a/src/test/ui/lint/lint-uppercase-variables.stderr +++ b/src/test/ui/lint/lint-uppercase-variables.stderr @@ -3,6 +3,8 @@ warning[E0170]: pattern binding `Foo` is named the same as one of the variants o | LL | Foo => {} | ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo` + | + = note: `#[warn(binding_variant_name)]` on by default warning: unused variable: `Foo` --> $DIR/lint-uppercase-variables.rs:22:9 From 67be07dab6b90b4ff48e1ba1526a6516e627d624 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 2 Jan 2020 13:50:01 +0100 Subject: [PATCH 11/14] address review comments --- src/librustc/hir/check_attr.rs | 23 +++++------- src/librustc/lint/builtin.rs | 10 +---- src/librustc_error_codes/error_codes/E0566.md | 4 +- src/librustc_mir/hair/pattern/check_match.rs | 2 +- src/test/run-make-fulldeps/simd-ffi/simd.rs | 35 ++++++++---------- src/test/ui/conflicting-repr-hints.rs | 35 ++++++++++++------ src/test/ui/conflicting-repr-hints.stderr | 37 ++++++++++--------- .../feature-gates/feature-gate-repr-simd.rs | 2 +- .../feature-gate-repr-simd.stderr | 6 +-- src/test/ui/issues/issue-14221.stderr | 2 +- src/test/ui/issues/issue-19100.stderr | 2 +- src/test/ui/issues/issue-30302.stderr | 2 +- src/test/ui/issues/issue-39720.rs | 10 ++--- src/test/ui/issues/issue-39720.stderr | 18 --------- src/test/ui/issues/issue-47094.rs | 6 +-- src/test/ui/issues/issue-47094.stderr | 17 +++++---- .../ui/lint/lint-uppercase-variables.stderr | 2 +- 17 files changed, 94 insertions(+), 119 deletions(-) delete mode 100644 src/test/ui/issues/issue-39720.stderr diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index b212b4880d3c7..af06030daf8c9 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -8,11 +8,11 @@ use crate::hir::def_id::DefId; use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; use crate::hir::DUMMY_HIR_ID; use crate::hir::{self, Attribute, HirId, Item, ItemKind, TraitItem, TraitItemKind}; -use crate::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES}; +use crate::lint::builtin::UNUSED_ATTRIBUTES; use crate::ty::query::Providers; use crate::ty::TyCtxt; -use errors::{error_code, struct_span_err}; +use errors::struct_span_err; use rustc_span::Span; use std::fmt::{self, Display}; @@ -194,7 +194,7 @@ impl CheckAttrVisitor<'tcx> { self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id)); } - self.check_repr(attrs, span, target, item, hir_id); + self.check_repr(attrs, span, target, item); self.check_used(attrs, target); } @@ -355,7 +355,6 @@ impl CheckAttrVisitor<'tcx> { span: &Span, target: Target, item: Option<&Item<'_>>, - hir_id: HirId, ) { // Extract the names of all repr hints, e.g., [foo, bar, align] for: // ``` @@ -445,15 +444,13 @@ impl CheckAttrVisitor<'tcx> { || (is_simd && is_c) || (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item))) { - self.tcx - .struct_span_lint_hir( - CONFLICTING_REPR_HINTS, - hir_id, - hint_spans.collect::>(), - "conflicting representation hints", - ) - .code(error_code!(E0566)) - .emit(); + struct_span_err!( + self.tcx.sess, + hint_spans.collect::>(), + E0566, + "conflicting representation hints", + ) + .emit(); } } diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 16fc142eb7a6e..b330ecd1fd104 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -96,17 +96,11 @@ declare_lint! { } declare_lint! { - pub BINDING_VARIANT_NAME, + pub BINDINGS_WITH_VARIANT_NAME, Warn, "detects pattern bindings with the same name as one of the matched variants" } -declare_lint! { - pub CONFLICTING_REPR_HINTS, - Warn, - "detects when more than one `#[repr(..)]` attribute, with different meaning, is applied" -} - declare_lint! { pub UNUSED_MACROS, Warn, @@ -471,7 +465,7 @@ declare_lint_pass! { UNREACHABLE_CODE, UNREACHABLE_PATTERNS, OVERLAPPING_PATTERNS, - BINDING_VARIANT_NAME, + BINDINGS_WITH_VARIANT_NAME, UNUSED_MACROS, WARNINGS, UNUSED_FEATURES, diff --git a/src/librustc_error_codes/error_codes/E0566.md b/src/librustc_error_codes/error_codes/E0566.md index 62fb66f614976..3dcd801a21a6d 100644 --- a/src/librustc_error_codes/error_codes/E0566.md +++ b/src/librustc_error_codes/error_codes/E0566.md @@ -2,8 +2,8 @@ Conflicting representation hints have been used on a same item. Erroneous code example: -``` -#[repr(u32, u64)] // warning! +```compile_fail,E0566 +#[repr(u32, u64)] enum Repr { A } ``` diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 73bcf296062b4..9ab7e98f3264c 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -294,7 +294,7 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa let ty_path = cx.tcx.def_path_str(edef.did); cx.tcx .struct_span_lint_hir( - lint::builtin::BINDING_VARIANT_NAME, + lint::builtin::BINDINGS_WITH_VARIANT_NAME, p.hir_id, p.span, &format!( diff --git a/src/test/run-make-fulldeps/simd-ffi/simd.rs b/src/test/run-make-fulldeps/simd-ffi/simd.rs index 75d95a4eaf146..c63fe4ddce214 100644 --- a/src/test/run-make-fulldeps/simd-ffi/simd.rs +++ b/src/test/run-make-fulldeps/simd-ffi/simd.rs @@ -4,35 +4,28 @@ // cross-compiled standard libraries. #![feature(no_core, optin_builtin_traits)] #![no_core] - #![feature(repr_simd, simd_ffi, link_llvm_intrinsics, lang_items, rustc_attrs)] - -#[repr(C)] #[derive(Copy)] #[repr(simd)] pub struct f32x4(f32, f32, f32, f32); - -extern { +extern "C" { #[link_name = "llvm.sqrt.v4f32"] fn vsqrt(x: f32x4) -> f32x4; } pub fn foo(x: f32x4) -> f32x4 { - unsafe {vsqrt(x)} + unsafe { vsqrt(x) } } -#[repr(C)] #[derive(Copy)] #[repr(simd)] pub struct i32x4(i32, i32, i32, i32); - -extern { +extern "C" { // _mm_sll_epi32 - #[cfg(any(target_arch = "x86", - target_arch = "x86-64"))] + #[cfg(any(target_arch = "x86", target_arch = "x86-64"))] #[link_name = "llvm.x86.sse2.psll.d"] fn integer(a: i32x4, b: i32x4) -> i32x4; @@ -48,22 +41,24 @@ extern { // just some substitute foreign symbol, not an LLVM intrinsic; so // we still get type checking, but not as detailed as (ab)using // LLVM. - #[cfg(not(any(target_arch = "x86", - target_arch = "x86-64", - target_arch = "arm", - target_arch = "aarch64")))] + #[cfg(not(any( + target_arch = "x86", + target_arch = "x86-64", + target_arch = "arm", + target_arch = "aarch64" + )))] fn integer(a: i32x4, b: i32x4) -> i32x4; } pub fn bar(a: i32x4, b: i32x4) -> i32x4 { - unsafe {integer(a, b)} + unsafe { integer(a, b) } } #[lang = "sized"] -pub trait Sized { } +pub trait Sized {} #[lang = "copy"] -pub trait Copy { } +pub trait Copy {} impl Copy for f32 {} impl Copy for i32 {} @@ -77,4 +72,6 @@ auto trait Freeze {} #[macro_export] #[rustc_builtin_macro] -macro_rules! Copy { () => () } +macro_rules! Copy { + () => {}; +} diff --git a/src/test/ui/conflicting-repr-hints.rs b/src/test/ui/conflicting-repr-hints.rs index cc986b2521962..8e9c11690a824 100644 --- a/src/test/ui/conflicting-repr-hints.rs +++ b/src/test/ui/conflicting-repr-hints.rs @@ -1,16 +1,24 @@ #![allow(dead_code)] #[repr(C)] -enum A { A } +enum A { + A, +} #[repr(u64)] -enum B { B } +enum B { + B, +} -#[repr(C, u64)] //~ WARNING conflicting representation hints -enum C { C } +#[repr(C, u64)] //~ ERROR conflicting representation hints +enum C { + C, +} -#[repr(u32, u64)] //~ WARNING conflicting representation hints -enum D { D } +#[repr(u32, u64)] //~ ERROR conflicting representation hints +enum D { + D, +} #[repr(C, packed)] struct E(i32); @@ -37,20 +45,23 @@ struct J(i32); //~ ERROR type has conflicting packed representation hints struct K(i32); #[repr(packed, align(8))] -union X { //~ ERROR type has conflicting packed and align representation hints - i: i32 +union X { + //~^ ERROR type has conflicting packed and align representation hints + i: i32, } #[repr(packed)] #[repr(align(8))] -union Y { //~ ERROR type has conflicting packed and align representation hints - i: i32 +union Y { + //~^ ERROR type has conflicting packed and align representation hints + i: i32, } #[repr(align(8))] #[repr(packed)] -union Z { //~ ERROR type has conflicting packed and align representation hints - i: i32 +union Z { + //~^ ERROR type has conflicting packed and align representation hints + i: i32, } fn main() {} diff --git a/src/test/ui/conflicting-repr-hints.stderr b/src/test/ui/conflicting-repr-hints.stderr index 48ddd4503eebd..0dfe360dbb3c4 100644 --- a/src/test/ui/conflicting-repr-hints.stderr +++ b/src/test/ui/conflicting-repr-hints.stderr @@ -1,72 +1,73 @@ -warning[E0566]: conflicting representation hints - --> $DIR/conflicting-repr-hints.rs:9:8 +error[E0566]: conflicting representation hints + --> $DIR/conflicting-repr-hints.rs:13:8 | LL | #[repr(C, u64)] | ^ ^^^ - | - = note: `#[warn(conflicting_repr_hints)]` on by default -warning[E0566]: conflicting representation hints - --> $DIR/conflicting-repr-hints.rs:12:8 +error[E0566]: conflicting representation hints + --> $DIR/conflicting-repr-hints.rs:18:8 | LL | #[repr(u32, u64)] | ^^^ ^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:19:1 + --> $DIR/conflicting-repr-hints.rs:27:1 | LL | struct F(i32); | ^^^^^^^^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:23:1 + --> $DIR/conflicting-repr-hints.rs:31:1 | LL | struct G(i32); | ^^^^^^^^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:27:1 + --> $DIR/conflicting-repr-hints.rs:35:1 | LL | struct H(i32); | ^^^^^^^^^^^^^^ error[E0634]: type has conflicting packed representation hints - --> $DIR/conflicting-repr-hints.rs:30:1 + --> $DIR/conflicting-repr-hints.rs:38:1 | LL | struct I(i32); | ^^^^^^^^^^^^^^ error[E0634]: type has conflicting packed representation hints - --> $DIR/conflicting-repr-hints.rs:34:1 + --> $DIR/conflicting-repr-hints.rs:42:1 | LL | struct J(i32); | ^^^^^^^^^^^^^^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:40:1 + --> $DIR/conflicting-repr-hints.rs:48:1 | LL | / union X { -LL | | i: i32 +LL | | +LL | | i: i32, LL | | } | |_^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:46:1 + --> $DIR/conflicting-repr-hints.rs:55:1 | LL | / union Y { -LL | | i: i32 +LL | | +LL | | i: i32, LL | | } | |_^ error[E0587]: type has conflicting packed and align representation hints - --> $DIR/conflicting-repr-hints.rs:52:1 + --> $DIR/conflicting-repr-hints.rs:62:1 | LL | / union Z { -LL | | i: i32 +LL | | +LL | | i: i32, LL | | } | |_^ -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0566, E0587. For more information about an error, try `rustc --explain E0566`. diff --git a/src/test/ui/feature-gates/feature-gate-repr-simd.rs b/src/test/ui/feature-gates/feature-gate-repr-simd.rs index 9d28f437415c9..1e4a404fa25a7 100644 --- a/src/test/ui/feature-gates/feature-gate-repr-simd.rs +++ b/src/test/ui/feature-gates/feature-gate-repr-simd.rs @@ -1,7 +1,7 @@ #[repr(simd)] //~ error: SIMD types are experimental struct Foo(u64, u64); -#[repr(C)] //~ warn: conflicting representation hints +#[repr(C)] //~ ERROR conflicting representation hints #[repr(simd)] //~ error: SIMD types are experimental struct Bar(u64, u64); diff --git a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr index d79d4ae27f11e..37a7bd0b1294d 100644 --- a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr +++ b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr @@ -16,17 +16,15 @@ LL | #[repr(simd)] = note: for more information, see https://github.com/rust-lang/rust/issues/27731 = help: add `#![feature(repr_simd)]` to the crate attributes to enable -warning[E0566]: conflicting representation hints +error[E0566]: conflicting representation hints --> $DIR/feature-gate-repr-simd.rs:4:8 | LL | #[repr(C)] | ^ LL | #[repr(simd)] | ^^^^ - | - = note: `#[warn(conflicting_repr_hints)]` on by default -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0566, E0658. For more information about an error, try `rustc --explain E0566`. diff --git a/src/test/ui/issues/issue-14221.stderr b/src/test/ui/issues/issue-14221.stderr index a5dae1a1ce38b..9864c0840d878 100644 --- a/src/test/ui/issues/issue-14221.stderr +++ b/src/test/ui/issues/issue-14221.stderr @@ -4,7 +4,7 @@ warning[E0170]: pattern binding `A` is named the same as one of the variants of LL | A => "A", | ^ help: to match on the variant, qualify the path: `E::A` | - = note: `#[warn(binding_variant_name)]` on by default + = note: `#[warn(bindings_with_variant_name)]` on by default warning[E0170]: pattern binding `B` is named the same as one of the variants of the type `E` --> $DIR/issue-14221.rs:15:13 diff --git a/src/test/ui/issues/issue-19100.stderr b/src/test/ui/issues/issue-19100.stderr index e7dd2c1e681d7..01e5313fcc1d9 100644 --- a/src/test/ui/issues/issue-19100.stderr +++ b/src/test/ui/issues/issue-19100.stderr @@ -4,7 +4,7 @@ warning[E0170]: pattern binding `Bar` is named the same as one of the variants o LL | Bar if true | ^^^ help: to match on the variant, qualify the path: `Foo::Bar` | - = note: `#[warn(binding_variant_name)]` on by default + = note: `#[warn(bindings_with_variant_name)]` on by default warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` --> $DIR/issue-19100.rs:22:1 diff --git a/src/test/ui/issues/issue-30302.stderr b/src/test/ui/issues/issue-30302.stderr index 14ae9aa5a7b50..ac1b5235f4423 100644 --- a/src/test/ui/issues/issue-30302.stderr +++ b/src/test/ui/issues/issue-30302.stderr @@ -4,7 +4,7 @@ warning[E0170]: pattern binding `Nil` is named the same as one of the variants o LL | Nil => true, | ^^^ help: to match on the variant, qualify the path: `Stack::Nil` | - = note: `#[warn(binding_variant_name)]` on by default + = note: `#[warn(bindings_with_variant_name)]` on by default error: unreachable pattern --> $DIR/issue-30302.rs:15:9 diff --git a/src/test/ui/issues/issue-39720.rs b/src/test/ui/issues/issue-39720.rs index 1a4775fc9600f..8cf841f937121 100644 --- a/src/test/ui/issues/issue-39720.rs +++ b/src/test/ui/issues/issue-39720.rs @@ -1,26 +1,22 @@ // run-pass -#![allow(non_snake_case)] - // ignore-emscripten FIXME(#45351) #![feature(repr_simd, platform_intrinsics)] -#[repr(C)] //~ WARNING conflicting representation hints #[repr(simd)] #[derive(Copy, Clone, Debug)] -pub struct char3(pub i8, pub i8, pub i8); +pub struct Char3(pub i8, pub i8, pub i8); -#[repr(C)] //~ WARNING conflicting representation hints #[repr(simd)] #[derive(Copy, Clone, Debug)] -pub struct short3(pub i16, pub i16, pub i16); +pub struct Short3(pub i16, pub i16, pub i16); extern "platform-intrinsic" { fn simd_cast(x: T) -> U; } fn main() { - let cast: short3 = unsafe { simd_cast(char3(10, -3, -9)) }; + let cast: Short3 = unsafe { simd_cast(Char3(10, -3, -9)) }; println!("{:?}", cast); } diff --git a/src/test/ui/issues/issue-39720.stderr b/src/test/ui/issues/issue-39720.stderr deleted file mode 100644 index e33fc823fbecc..0000000000000 --- a/src/test/ui/issues/issue-39720.stderr +++ /dev/null @@ -1,18 +0,0 @@ -warning[E0566]: conflicting representation hints - --> $DIR/issue-39720.rs:8:8 - | -LL | #[repr(C)] - | ^ -LL | #[repr(simd)] - | ^^^^ - | - = note: `#[warn(conflicting_repr_hints)]` on by default - -warning[E0566]: conflicting representation hints - --> $DIR/issue-39720.rs:13:8 - | -LL | #[repr(C)] - | ^ -LL | #[repr(simd)] - | ^^^^ - diff --git a/src/test/ui/issues/issue-47094.rs b/src/test/ui/issues/issue-47094.rs index 97da984d4afd0..3258ee92a7422 100644 --- a/src/test/ui/issues/issue-47094.rs +++ b/src/test/ui/issues/issue-47094.rs @@ -1,12 +1,10 @@ -// check-pass - -#[repr(C,u8)] //~ WARNING conflicting representation hints +#[repr(C, u8)] //~ ERROR conflicting representation hints enum Foo { A, B, } -#[repr(C)] //~ WARNING conflicting representation hints +#[repr(C)] //~ ERROR conflicting representation hints #[repr(u8)] enum Bar { A, diff --git a/src/test/ui/issues/issue-47094.stderr b/src/test/ui/issues/issue-47094.stderr index 570fe53c26352..c807f644fd310 100644 --- a/src/test/ui/issues/issue-47094.stderr +++ b/src/test/ui/issues/issue-47094.stderr @@ -1,16 +1,17 @@ -warning[E0566]: conflicting representation hints - --> $DIR/issue-47094.rs:3:8 +error[E0566]: conflicting representation hints + --> $DIR/issue-47094.rs:1:8 | -LL | #[repr(C,u8)] - | ^ ^^ - | - = note: `#[warn(conflicting_repr_hints)]` on by default +LL | #[repr(C, u8)] + | ^ ^^ -warning[E0566]: conflicting representation hints - --> $DIR/issue-47094.rs:9:8 +error[E0566]: conflicting representation hints + --> $DIR/issue-47094.rs:7:8 | LL | #[repr(C)] | ^ LL | #[repr(u8)] | ^^ +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0566`. diff --git a/src/test/ui/lint/lint-uppercase-variables.stderr b/src/test/ui/lint/lint-uppercase-variables.stderr index 0519a63e05585..b937832ac622d 100644 --- a/src/test/ui/lint/lint-uppercase-variables.stderr +++ b/src/test/ui/lint/lint-uppercase-variables.stderr @@ -4,7 +4,7 @@ warning[E0170]: pattern binding `Foo` is named the same as one of the variants o LL | Foo => {} | ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo` | - = note: `#[warn(binding_variant_name)]` on by default + = note: `#[warn(bindings_with_variant_name)]` on by default warning: unused variable: `Foo` --> $DIR/lint-uppercase-variables.rs:22:9 From 485e98aae2f4d6e7d795eb13170a08407a776fdf Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Thu, 2 Jan 2020 20:02:22 +0800 Subject: [PATCH 12/14] Implement uncommon_codepoints lint. --- Cargo.lock | 16 ++++++++++ src/librustc_lint/Cargo.toml | 1 + src/librustc_lint/non_ascii_idents.rs | 25 ++++++++++++--- src/test/ui/issues/issue-48508.rs | 1 + .../lint-uncommon-codepoints.rs | 11 +++++++ .../lint-uncommon-codepoints.stderr | 32 +++++++++++++++++++ src/tools/tidy/src/deps.rs | 2 ++ 7 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.rs create mode 100644 src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.stderr diff --git a/Cargo.lock b/Cargo.lock index ba0f55ab5af6f..45a1a169be446 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3642,6 +3642,7 @@ dependencies = [ "rustc_span", "rustc_target", "syntax", + "unicode-security", ] [[package]] @@ -4940,6 +4941,21 @@ dependencies = [ "smallvec 1.0.0", ] +[[package]] +name = "unicode-script" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b2c5c29e805da6817f5af6a627d65adb045cebf05cccd5a3493d6109454391c" + +[[package]] +name = "unicode-security" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c49d35967fa037b881acc34ef717c38c4b5560eba10e3685271b3f530bb19634" +dependencies = [ + "unicode-script", +] + [[package]] name = "unicode-segmentation" version = "1.6.0" diff --git a/src/librustc_lint/Cargo.toml b/src/librustc_lint/Cargo.toml index 600f7031ed5c0..a40c5d1697c43 100644 --- a/src/librustc_lint/Cargo.toml +++ b/src/librustc_lint/Cargo.toml @@ -10,6 +10,7 @@ path = "lib.rs" [dependencies] log = "0.4" +unicode-security = "0.0.2" rustc = { path = "../librustc" } rustc_target = { path = "../librustc_target" } syntax = { path = "../libsyntax" } diff --git a/src/librustc_lint/non_ascii_idents.rs b/src/librustc_lint/non_ascii_idents.rs index 9ec8455394295..f30d0bcbdd53f 100644 --- a/src/librustc_lint/non_ascii_idents.rs +++ b/src/librustc_lint/non_ascii_idents.rs @@ -7,15 +7,32 @@ declare_lint! { "detects non-ASCII identifiers" } -declare_lint_pass!(NonAsciiIdents => [NON_ASCII_IDENTS]); +declare_lint! { + pub UNCOMMON_CODEPOINTS, + Warn, + "detects uncommon Unicode codepoints in identifiers" +} + +declare_lint_pass!(NonAsciiIdents => [NON_ASCII_IDENTS, UNCOMMON_CODEPOINTS]); impl EarlyLintPass for NonAsciiIdents { fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) { - if !ident.name.as_str().is_ascii() { + use unicode_security::GeneralSecurityProfile; + let name_str = ident.name.as_str(); + if name_str.is_ascii() { + return; + } + cx.struct_span_lint( + NON_ASCII_IDENTS, + ident.span, + "identifier contains non-ASCII characters", + ) + .emit(); + if !name_str.chars().all(GeneralSecurityProfile::identifier_allowed) { cx.struct_span_lint( - NON_ASCII_IDENTS, + UNCOMMON_CODEPOINTS, ident.span, - "identifier contains non-ASCII characters", + "identifier contains uncommon Unicode codepoints", ) .emit(); } diff --git a/src/test/ui/issues/issue-48508.rs b/src/test/ui/issues/issue-48508.rs index b7aa642287638..87965c204ada7 100644 --- a/src/test/ui/issues/issue-48508.rs +++ b/src/test/ui/issues/issue-48508.rs @@ -11,6 +11,7 @@ // ignore-asmjs wasm2js does not support source maps yet #![feature(non_ascii_idents)] +#[allow(uncommon_codepoints)] #[path = "issue-48508-aux.rs"] mod other_file; diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.rs b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.rs new file mode 100644 index 0000000000000..7ac0d035d5bf1 --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.rs @@ -0,0 +1,11 @@ +#![feature(non_ascii_idents)] +#![deny(uncommon_codepoints)] + +const µ: f64 = 0.000001; //~ ERROR identifier contains uncommon Unicode codepoints + +fn dijkstra() {} //~ ERROR identifier contains uncommon Unicode codepoints + +fn main() { + let ㇻㇲㇳ = "rust"; //~ ERROR identifier contains uncommon Unicode codepoints + println!("{}", ㇻㇲㇳ); //~ ERROR identifier contains uncommon Unicode codepoints +} diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.stderr b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.stderr new file mode 100644 index 0000000000000..4580d25665ef9 --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.stderr @@ -0,0 +1,32 @@ +error: identifier contains uncommon Unicode codepoints + --> $DIR/lint-uncommon-codepoints.rs:4:7 + | +LL | const µ: f64 = 0.000001; + | ^ + | +note: lint level defined here + --> $DIR/lint-uncommon-codepoints.rs:2:9 + | +LL | #![deny(uncommon_codepoints)] + | ^^^^^^^^^^^^^^^^^^^ + +error: identifier contains uncommon Unicode codepoints + --> $DIR/lint-uncommon-codepoints.rs:6:4 + | +LL | fn dijkstra() {} + | ^^^^^^^ + +error: identifier contains uncommon Unicode codepoints + --> $DIR/lint-uncommon-codepoints.rs:9:9 + | +LL | let ㇻㇲㇳ = "rust"; + | ^^^^^^ + +error: identifier contains uncommon Unicode codepoints + --> $DIR/lint-uncommon-codepoints.rs:10:20 + | +LL | println!("{}", ㇻㇲㇳ); + | ^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index a3042803dd7e1..352c00dbe41bd 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -171,6 +171,8 @@ const WHITELIST: &[Crate<'_>] = &[ Crate("thread_local"), Crate("ucd-util"), Crate("unicode-normalization"), + Crate("unicode-script"), + Crate("unicode-security"), Crate("unicode-width"), Crate("unicode-xid"), Crate("unreachable"), From 7fd014d56986d7b52c49f07fb8db9529059d839d Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Fri, 3 Jan 2020 08:40:15 -0500 Subject: [PATCH 13/14] tweak wording of mismatched delimiter errors --- src/librustc_parse/lexer/tokentrees.rs | 10 +++++----- src/librustc_parse/parser/mod.rs | 8 ++++---- src/test/ui/issues/issue-62554.rs | 2 +- src/test/ui/issues/issue-62554.stderr | 14 +++++++------- src/test/ui/parser-recovery-1.rs | 2 +- src/test/ui/parser-recovery-1.stderr | 8 ++++---- src/test/ui/parser-recovery-2.rs | 2 +- src/test/ui/parser-recovery-2.stderr | 6 +++--- src/test/ui/parser/issue-10636-1.rs | 6 +++--- src/test/ui/parser/issue-10636-1.stderr | 6 +++--- src/test/ui/parser/issue-2354-1.rs | 2 +- src/test/ui/parser/issue-2354-1.stderr | 4 ++-- src/test/ui/parser/issue-2354.rs | 4 ++-- src/test/ui/parser/issue-2354.stderr | 8 ++++---- ...e-58094-missing-right-square-bracket.stderr | 4 ++-- src/test/ui/parser/issue-62524.stderr | 4 ++-- src/test/ui/parser/issue-62546.rs | 2 +- src/test/ui/parser/issue-62546.stderr | 8 ++++---- src/test/ui/parser/issue-62881.rs | 2 +- src/test/ui/parser/issue-62881.stderr | 8 ++++---- src/test/ui/parser/issue-62973.stderr | 18 +++++++++--------- src/test/ui/parser/issue-63116.stderr | 4 ++-- src/test/ui/parser/issue-63135.stderr | 6 +++--- .../macro-mismatched-delim-brace-paren.rs | 2 +- .../macro-mismatched-delim-brace-paren.stderr | 6 +++--- .../macro-mismatched-delim-paren-brace.rs | 4 ++-- .../macro-mismatched-delim-paren-brace.stderr | 10 +++++----- .../ui/parser/mbe_missing_right_paren.stderr | 4 ++-- .../missing-close-brace-in-impl-trait.rs | 2 +- .../missing-close-brace-in-impl-trait.stderr | 8 ++++---- .../missing-close-brace-in-struct.rs | 2 +- .../missing-close-brace-in-struct.stderr | 8 ++++---- .../missing-close-brace-in-trait.rs | 2 +- .../missing-close-brace-in-trait.stderr | 10 +++++----- .../mismatched-delim-brace-empty-block.rs | 2 +- .../mismatched-delim-brace-empty-block.stderr | 4 ++-- src/test/ui/parser/missing_right_paren.stderr | 6 +++--- src/test/ui/parser/unclosed-braces.rs | 4 ++-- src/test/ui/parser/unclosed-braces.stderr | 8 ++++---- .../ui/parser/unclosed-delimiter-in-dep.stderr | 8 ++++---- src/test/ui/parser/unclosed_delim_mod.rs | 2 +- src/test/ui/parser/unclosed_delim_mod.stderr | 8 ++++---- .../unmatched-delimiter-at-end-of-file.rs | 2 +- .../unmatched-delimiter-at-end-of-file.stderr | 6 +++--- .../ui/proc-macro/invalid-punct-ident-4.rs | 2 +- .../ui/proc-macro/invalid-punct-ident-4.stderr | 4 ++-- src/test/ui/resolve/token-error-correct-2.rs | 2 +- .../ui/resolve/token-error-correct-2.stderr | 6 +++--- src/test/ui/resolve/token-error-correct.rs | 2 +- src/test/ui/resolve/token-error-correct.stderr | 8 ++++---- 50 files changed, 135 insertions(+), 135 deletions(-) diff --git a/src/librustc_parse/lexer/tokentrees.rs b/src/librustc_parse/lexer/tokentrees.rs index 5beda290b9144..a28bff3babfbf 100644 --- a/src/librustc_parse/lexer/tokentrees.rs +++ b/src/librustc_parse/lexer/tokentrees.rs @@ -78,11 +78,11 @@ impl<'a> TokenTreesReader<'a> { let sm = self.string_reader.sess.source_map(); match self.token.kind { token::Eof => { - let msg = "this file contains an un-closed delimiter"; + let msg = "this file contains an unclosed delimiter"; let mut err = self.string_reader.sess.span_diagnostic.struct_span_err(self.token.span, msg); for &(_, sp) in &self.open_braces { - err.span_label(sp, "un-closed delimiter"); + err.span_label(sp, "unclosed delimiter"); self.unmatched_braces.push(UnmatchedBrace { expected_delim: token::DelimToken::Brace, found_delim: None, @@ -155,7 +155,7 @@ impl<'a> TokenTreesReader<'a> { close_brace_span, )); } - // Parse the close delimiter. + // Parse the closing delimiter. self.real_token(); } // Incorrect delimiter. @@ -218,7 +218,7 @@ impl<'a> TokenTreesReader<'a> { // An unexpected closing delimiter (i.e., there is no // matching opening delimiter). let token_str = token_to_string(&self.token); - let msg = format!("unexpected close delimiter: `{}`", token_str); + let msg = format!("unexpected closing delimiter: `{}`", token_str); let mut err = self.string_reader.sess.span_diagnostic.struct_span_err(self.token.span, &msg); @@ -228,7 +228,7 @@ impl<'a> TokenTreesReader<'a> { "this block is empty, you might have not meant to close it", ); } - err.span_label(self.token.span, "unexpected close delimiter"); + err.span_label(self.token.span, "unexpected closing delimiter"); Err(err) } _ => { diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index 6dcffcf0bd7b8..a2fa335cf72e2 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -1354,16 +1354,16 @@ crate fn make_unclosed_delims_error( let mut err = sess.span_diagnostic.struct_span_err( unmatched.found_span, &format!( - "incorrect close delimiter: `{}`", + "mismatched closing delimiter: `{}`", pprust::token_kind_to_string(&token::CloseDelim(found_delim)), ), ); - err.span_label(unmatched.found_span, "incorrect close delimiter"); + err.span_label(unmatched.found_span, "mismatched closing delimiter"); if let Some(sp) = unmatched.candidate_span { - err.span_label(sp, "close delimiter possibly meant for this"); + err.span_label(sp, "closing delimiter possibly meant for this"); } if let Some(sp) = unmatched.unclosed_span { - err.span_label(sp, "un-closed delimiter"); + err.span_label(sp, "unclosed delimiter"); } Some(err) } diff --git a/src/test/ui/issues/issue-62554.rs b/src/test/ui/issues/issue-62554.rs index 3d50674e624ff..20e84ec364b65 100644 --- a/src/test/ui/issues/issue-62554.rs +++ b/src/test/ui/issues/issue-62554.rs @@ -2,4 +2,4 @@ fn main() {} fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 { //~^ ERROR expected `{`, found `macro_rules` -//~ ERROR this file contains an un-closed delimiter +//~ ERROR this file contains an unclosed delimiter diff --git a/src/test/ui/issues/issue-62554.stderr b/src/test/ui/issues/issue-62554.stderr index d59546e23839a..692bfe02275a8 100644 --- a/src/test/ui/issues/issue-62554.stderr +++ b/src/test/ui/issues/issue-62554.stderr @@ -1,15 +1,15 @@ -error: this file contains an un-closed delimiter - --> $DIR/issue-62554.rs:5:53 +error: this file contains an unclosed delimiter + --> $DIR/issue-62554.rs:5:52 | LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 { - | - - - - - un-closed delimiter + | - - - - - unclosed delimiter | | | | | - | | | | un-closed delimiter - | | | un-closed delimiter - | un-closed delimiter un-closed delimiter + | | | | unclosed delimiter + | | | unclosed delimiter + | unclosed delimiter unclosed delimiter LL | LL | - | ^ + | ^ error: expected `{`, found `macro_rules` --> $DIR/issue-62554.rs:3:23 diff --git a/src/test/ui/parser-recovery-1.rs b/src/test/ui/parser-recovery-1.rs index 21d36048e6703..dcc0dc00a72ea 100644 --- a/src/test/ui/parser-recovery-1.rs +++ b/src/test/ui/parser-recovery-1.rs @@ -12,4 +12,4 @@ fn main() { let x = y.; //~^ ERROR unexpected token //~| ERROR cannot find value `y` in this scope -} //~ ERROR this file contains an un-closed delimiter +} //~ ERROR this file contains an unclosed delimiter diff --git a/src/test/ui/parser-recovery-1.stderr b/src/test/ui/parser-recovery-1.stderr index 83f8ef63c9954..4d881918c40cc 100644 --- a/src/test/ui/parser-recovery-1.stderr +++ b/src/test/ui/parser-recovery-1.stderr @@ -1,8 +1,8 @@ -error: this file contains an un-closed delimiter - --> $DIR/parser-recovery-1.rs:15:55 +error: this file contains an unclosed delimiter + --> $DIR/parser-recovery-1.rs:15:54 | LL | trait Foo { - | - un-closed delimiter + | - unclosed delimiter LL | fn bar() { | - this delimiter might not be properly closed... ... @@ -10,7 +10,7 @@ LL | } | - ...as it matches this but it has different indentation ... LL | } - | ^ + | ^ error: unexpected token: `;` --> $DIR/parser-recovery-1.rs:12:15 diff --git a/src/test/ui/parser-recovery-2.rs b/src/test/ui/parser-recovery-2.rs index be686ccbc22ed..dc5be96cc6405 100644 --- a/src/test/ui/parser-recovery-2.rs +++ b/src/test/ui/parser-recovery-2.rs @@ -5,7 +5,7 @@ trait Foo { fn bar() { let x = foo(); //~ ERROR cannot find function `foo` in this scope - ) //~ ERROR incorrect close delimiter: `)` + ) //~ ERROR mismatched closing delimiter: `)` } fn main() { diff --git a/src/test/ui/parser-recovery-2.stderr b/src/test/ui/parser-recovery-2.stderr index c246fa80b0a05..c48211d406479 100644 --- a/src/test/ui/parser-recovery-2.stderr +++ b/src/test/ui/parser-recovery-2.stderr @@ -4,14 +4,14 @@ error: unexpected token: `;` LL | let x = y.; | ^ -error: incorrect close delimiter: `)` +error: mismatched closing delimiter: `)` --> $DIR/parser-recovery-2.rs:8:5 | LL | fn bar() { - | - un-closed delimiter + | - unclosed delimiter LL | let x = foo(); LL | ) - | ^ incorrect close delimiter + | ^ mismatched closing delimiter error[E0425]: cannot find function `foo` in this scope --> $DIR/parser-recovery-2.rs:7:17 diff --git a/src/test/ui/parser/issue-10636-1.rs b/src/test/ui/parser/issue-10636-1.rs index e495c0411d816..77c6072d6fc0a 100644 --- a/src/test/ui/parser/issue-10636-1.rs +++ b/src/test/ui/parser/issue-10636-1.rs @@ -1,8 +1,8 @@ struct Obj { - //~^ NOTE: un-closed delimiter + //~^ NOTE: unclosed delimiter member: usize ) -//~^ ERROR incorrect close delimiter -//~| NOTE incorrect close delimiter +//~^ ERROR mismatched closing delimiter +//~| NOTE mismatched closing delimiter fn main() {} diff --git a/src/test/ui/parser/issue-10636-1.stderr b/src/test/ui/parser/issue-10636-1.stderr index 894139f24ddaf..ff90cb97096f7 100644 --- a/src/test/ui/parser/issue-10636-1.stderr +++ b/src/test/ui/parser/issue-10636-1.stderr @@ -1,11 +1,11 @@ -error: incorrect close delimiter: `)` +error: mismatched closing delimiter: `)` --> $DIR/issue-10636-1.rs:4:1 | LL | struct Obj { - | - un-closed delimiter + | - unclosed delimiter ... LL | ) - | ^ incorrect close delimiter + | ^ mismatched closing delimiter error: aborting due to previous error diff --git a/src/test/ui/parser/issue-2354-1.rs b/src/test/ui/parser/issue-2354-1.rs index 7e4e24fae1964..996cf1bcbf920 100644 --- a/src/test/ui/parser/issue-2354-1.rs +++ b/src/test/ui/parser/issue-2354-1.rs @@ -1 +1 @@ -static foo: isize = 2; } //~ ERROR unexpected close delimiter: +static foo: isize = 2; } //~ ERROR unexpected closing delimiter: diff --git a/src/test/ui/parser/issue-2354-1.stderr b/src/test/ui/parser/issue-2354-1.stderr index 7c083751228b6..7ea0f2a982855 100644 --- a/src/test/ui/parser/issue-2354-1.stderr +++ b/src/test/ui/parser/issue-2354-1.stderr @@ -1,8 +1,8 @@ -error: unexpected close delimiter: `}` +error: unexpected closing delimiter: `}` --> $DIR/issue-2354-1.rs:1:24 | LL | static foo: isize = 2; } - | ^ unexpected close delimiter + | ^ unexpected closing delimiter error: aborting due to previous error diff --git a/src/test/ui/parser/issue-2354.rs b/src/test/ui/parser/issue-2354.rs index c4fc471618283..c422040cbe300 100644 --- a/src/test/ui/parser/issue-2354.rs +++ b/src/test/ui/parser/issue-2354.rs @@ -1,4 +1,4 @@ -fn foo() { //~ NOTE un-closed delimiter +fn foo() { //~ NOTE unclosed delimiter match Some(10) { //~^ NOTE this delimiter might not be properly closed... Some(y) => { panic!(); } @@ -12,4 +12,4 @@ fn bar() { } fn main() {} -//~ ERROR this file contains an un-closed delimiter +//~ ERROR this file contains an unclosed delimiter diff --git a/src/test/ui/parser/issue-2354.stderr b/src/test/ui/parser/issue-2354.stderr index 45199b02cb8d4..b89ed3958357d 100644 --- a/src/test/ui/parser/issue-2354.stderr +++ b/src/test/ui/parser/issue-2354.stderr @@ -1,8 +1,8 @@ -error: this file contains an un-closed delimiter - --> $DIR/issue-2354.rs:15:53 +error: this file contains an unclosed delimiter + --> $DIR/issue-2354.rs:15:52 | LL | fn foo() { - | - un-closed delimiter + | - unclosed delimiter LL | match Some(10) { | - this delimiter might not be properly closed... ... @@ -10,7 +10,7 @@ LL | } | - ...as it matches this but it has different indentation ... LL | - | ^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/parser/issue-58094-missing-right-square-bracket.stderr b/src/test/ui/parser/issue-58094-missing-right-square-bracket.stderr index 2c987da81d833..00f6652b311da 100644 --- a/src/test/ui/parser/issue-58094-missing-right-square-bracket.stderr +++ b/src/test/ui/parser/issue-58094-missing-right-square-bracket.stderr @@ -1,10 +1,10 @@ -error: this file contains an un-closed delimiter +error: this file contains an unclosed delimiter --> $DIR/issue-58094-missing-right-square-bracket.rs:4:4 | LL | #[Ѕ | - ^ | | - | un-closed delimiter + | unclosed delimiter error: expected item after attributes --> $DIR/issue-58094-missing-right-square-bracket.rs:4:4 diff --git a/src/test/ui/parser/issue-62524.stderr b/src/test/ui/parser/issue-62524.stderr index 229768f4959fe..3482435cd1d03 100644 --- a/src/test/ui/parser/issue-62524.stderr +++ b/src/test/ui/parser/issue-62524.stderr @@ -1,8 +1,8 @@ -error: this file contains an un-closed delimiter +error: this file contains an unclosed delimiter --> $DIR/issue-62524.rs:4:3 | LL | y![ - | - un-closed delimiter + | - unclosed delimiter LL | Ϥ, | ^ diff --git a/src/test/ui/parser/issue-62546.rs b/src/test/ui/parser/issue-62546.rs index 75b95e7407302..f06b6505859cf 100644 --- a/src/test/ui/parser/issue-62546.rs +++ b/src/test/ui/parser/issue-62546.rs @@ -1,3 +1,3 @@ pub t(# //~^ ERROR missing `fn` or `struct` for function or struct definition -//~ ERROR this file contains an un-closed delimiter +//~ ERROR this file contains an unclosed delimiter diff --git a/src/test/ui/parser/issue-62546.stderr b/src/test/ui/parser/issue-62546.stderr index 631aac9550585..32c61391e1682 100644 --- a/src/test/ui/parser/issue-62546.stderr +++ b/src/test/ui/parser/issue-62546.stderr @@ -1,11 +1,11 @@ -error: this file contains an un-closed delimiter - --> $DIR/issue-62546.rs:3:53 +error: this file contains an unclosed delimiter + --> $DIR/issue-62546.rs:3:52 | LL | pub t(# - | - un-closed delimiter + | - unclosed delimiter LL | LL | - | ^ + | ^ error: missing `fn` or `struct` for function or struct definition --> $DIR/issue-62546.rs:1:4 diff --git a/src/test/ui/parser/issue-62881.rs b/src/test/ui/parser/issue-62881.rs index 1782c2e375df5..b9204595fb971 100644 --- a/src/test/ui/parser/issue-62881.rs +++ b/src/test/ui/parser/issue-62881.rs @@ -3,4 +3,4 @@ fn main() {} fn f() -> isize { fn f() -> isize {} pub f< //~^ ERROR missing `fn` or `struct` for function or struct definition //~| ERROR mismatched types -//~ ERROR this file contains an un-closed delimiter +//~ ERROR this file contains an unclosed delimiter diff --git a/src/test/ui/parser/issue-62881.stderr b/src/test/ui/parser/issue-62881.stderr index fdf772fcbdb77..87be69baadda5 100644 --- a/src/test/ui/parser/issue-62881.stderr +++ b/src/test/ui/parser/issue-62881.stderr @@ -1,11 +1,11 @@ -error: this file contains an un-closed delimiter - --> $DIR/issue-62881.rs:6:53 +error: this file contains an unclosed delimiter + --> $DIR/issue-62881.rs:6:52 | LL | fn f() -> isize { fn f() -> isize {} pub f< - | - un-closed delimiter + | - unclosed delimiter ... LL | - | ^ + | ^ error: missing `fn` or `struct` for function or struct definition --> $DIR/issue-62881.rs:3:41 diff --git a/src/test/ui/parser/issue-62973.stderr b/src/test/ui/parser/issue-62973.stderr index e2a5b4cba06f5..e95e629957c26 100644 --- a/src/test/ui/parser/issue-62973.stderr +++ b/src/test/ui/parser/issue-62973.stderr @@ -1,10 +1,10 @@ -error: this file contains an un-closed delimiter +error: this file contains an unclosed delimiter --> $DIR/issue-62973.rs:8:2 | LL | fn p() { match s { v, E { [) {) } - | - - un-closed delimiter + | - - unclosed delimiter | | - | un-closed delimiter + | unclosed delimiter LL | LL | | ^ @@ -44,21 +44,21 @@ LL | LL | | ^ expected one of `.`, `?`, `{`, or an operator -error: incorrect close delimiter: `)` +error: mismatched closing delimiter: `)` --> $DIR/issue-62973.rs:6:28 | LL | fn p() { match s { v, E { [) {) } - | -^ incorrect close delimiter + | -^ mismatched closing delimiter | | - | un-closed delimiter + | unclosed delimiter -error: incorrect close delimiter: `)` +error: mismatched closing delimiter: `)` --> $DIR/issue-62973.rs:6:31 | LL | fn p() { match s { v, E { [) {) } - | -^ incorrect close delimiter + | -^ mismatched closing delimiter | | - | un-closed delimiter + | unclosed delimiter error: aborting due to 6 previous errors diff --git a/src/test/ui/parser/issue-63116.stderr b/src/test/ui/parser/issue-63116.stderr index 0aed0386a907b..2beb73d83d261 100644 --- a/src/test/ui/parser/issue-63116.stderr +++ b/src/test/ui/parser/issue-63116.stderr @@ -1,10 +1,10 @@ -error: this file contains an un-closed delimiter +error: this file contains an unclosed delimiter --> $DIR/issue-63116.rs:3:18 | LL | impl W $DIR/issue-63116.rs:3:12 diff --git a/src/test/ui/parser/issue-63135.stderr b/src/test/ui/parser/issue-63135.stderr index 152601b353805..a6fb037b299f5 100644 --- a/src/test/ui/parser/issue-63135.stderr +++ b/src/test/ui/parser/issue-63135.stderr @@ -1,11 +1,11 @@ -error: this file contains an un-closed delimiter +error: this file contains an unclosed delimiter --> $DIR/issue-63135.rs:3:16 | LL | fn i(n{...,f # | - - ^ | | | - | | un-closed delimiter - | un-closed delimiter + | | unclosed delimiter + | unclosed delimiter error: expected field pattern, found `...` --> $DIR/issue-63135.rs:3:8 diff --git a/src/test/ui/parser/macro-mismatched-delim-brace-paren.rs b/src/test/ui/parser/macro-mismatched-delim-brace-paren.rs index 3f3e997deceb8..404aa7b806a51 100644 --- a/src/test/ui/parser/macro-mismatched-delim-brace-paren.rs +++ b/src/test/ui/parser/macro-mismatched-delim-brace-paren.rs @@ -3,5 +3,5 @@ macro_rules! foo { ($($tt:tt)*) => () } fn main() { foo! { bar, "baz", 1, 2.0 - ) //~ ERROR incorrect close delimiter + ) //~ ERROR mismatched closing delimiter } diff --git a/src/test/ui/parser/macro-mismatched-delim-brace-paren.stderr b/src/test/ui/parser/macro-mismatched-delim-brace-paren.stderr index f411ee8ce2ccc..93c5ab383d488 100644 --- a/src/test/ui/parser/macro-mismatched-delim-brace-paren.stderr +++ b/src/test/ui/parser/macro-mismatched-delim-brace-paren.stderr @@ -1,11 +1,11 @@ -error: incorrect close delimiter: `)` +error: mismatched closing delimiter: `)` --> $DIR/macro-mismatched-delim-brace-paren.rs:6:5 | LL | foo! { - | - un-closed delimiter + | - unclosed delimiter LL | bar, "baz", 1, 2.0 LL | ) - | ^ incorrect close delimiter + | ^ mismatched closing delimiter error: aborting due to previous error diff --git a/src/test/ui/parser/macro-mismatched-delim-paren-brace.rs b/src/test/ui/parser/macro-mismatched-delim-paren-brace.rs index 1185f882a1390..1a1b9edfbcb66 100644 --- a/src/test/ui/parser/macro-mismatched-delim-paren-brace.rs +++ b/src/test/ui/parser/macro-mismatched-delim-paren-brace.rs @@ -1,5 +1,5 @@ fn main() { foo! ( bar, "baz", 1, 2.0 - } //~ ERROR incorrect close delimiter -} //~ ERROR unexpected close delimiter: `}` + } //~ ERROR mismatched closing delimiter +} //~ ERROR unexpected closing delimiter: `}` diff --git a/src/test/ui/parser/macro-mismatched-delim-paren-brace.stderr b/src/test/ui/parser/macro-mismatched-delim-paren-brace.stderr index b68433936117a..042142ac35033 100644 --- a/src/test/ui/parser/macro-mismatched-delim-paren-brace.stderr +++ b/src/test/ui/parser/macro-mismatched-delim-paren-brace.stderr @@ -1,17 +1,17 @@ -error: unexpected close delimiter: `}` +error: unexpected closing delimiter: `}` --> $DIR/macro-mismatched-delim-paren-brace.rs:5:1 | LL | } - | ^ unexpected close delimiter + | ^ unexpected closing delimiter -error: incorrect close delimiter: `}` +error: mismatched closing delimiter: `}` --> $DIR/macro-mismatched-delim-paren-brace.rs:4:5 | LL | foo! ( - | - un-closed delimiter + | - unclosed delimiter LL | bar, "baz", 1, 2.0 LL | } - | ^ incorrect close delimiter + | ^ mismatched closing delimiter error: aborting due to 2 previous errors diff --git a/src/test/ui/parser/mbe_missing_right_paren.stderr b/src/test/ui/parser/mbe_missing_right_paren.stderr index 4504fc0eb0004..c5b3cc275ce9a 100644 --- a/src/test/ui/parser/mbe_missing_right_paren.stderr +++ b/src/test/ui/parser/mbe_missing_right_paren.stderr @@ -1,10 +1,10 @@ -error: this file contains an un-closed delimiter +error: this file contains an unclosed delimiter --> $DIR/mbe_missing_right_paren.rs:3:19 | LL | macro_rules! abc(ؼ | - ^ | | - | un-closed delimiter + | unclosed delimiter error: macros that expand to items must be delimited with braces or followed by a semicolon --> $DIR/mbe_missing_right_paren.rs:3:17 diff --git a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.rs b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.rs index 8d89905909e94..9f02a7a997bf2 100644 --- a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.rs +++ b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.rs @@ -9,4 +9,4 @@ trait T { //~ ERROR expected one of pub(crate) struct Bar(); fn main() {} -//~ ERROR this file contains an un-closed delimiter +//~ ERROR this file contains an unclosed delimiter diff --git a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.stderr b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.stderr index e1aed8a6b4ea3..a23cfeac58f84 100644 --- a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.stderr +++ b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.stderr @@ -1,11 +1,11 @@ -error: this file contains an un-closed delimiter - --> $DIR/missing-close-brace-in-impl-trait.rs:12:53 +error: this file contains an unclosed delimiter + --> $DIR/missing-close-brace-in-impl-trait.rs:12:52 | LL | impl T for () { - | - un-closed delimiter + | - unclosed delimiter ... LL | - | ^ + | ^ error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found keyword `trait` --> $DIR/missing-close-brace-in-impl-trait.rs:5:1 diff --git a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs index 5b716b1467cb1..0d53315839ceb 100644 --- a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs +++ b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs @@ -11,4 +11,4 @@ impl T for Bar { fn foo(&self) {} } -fn main() {} //~ ERROR this file contains an un-closed delimiter +fn main() {} //~ ERROR this file contains an unclosed delimiter diff --git a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr index 15ce94a6d00fa..ac8dd48a58879 100644 --- a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr +++ b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr @@ -1,11 +1,11 @@ -error: this file contains an un-closed delimiter - --> $DIR/missing-close-brace-in-struct.rs:14:66 +error: this file contains an unclosed delimiter + --> $DIR/missing-close-brace-in-struct.rs:14:65 | LL | pub(crate) struct Bar { - | - un-closed delimiter + | - unclosed delimiter ... LL | fn main() {} - | ^ + | ^ error: expected identifier, found keyword `trait` --> $DIR/missing-close-brace-in-struct.rs:4:1 diff --git a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-trait.rs b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-trait.rs index 9f3d78d584d44..5ec5d45bbe7b2 100644 --- a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-trait.rs +++ b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-trait.rs @@ -9,4 +9,4 @@ impl T for Bar { fn foo(&self) {} } -fn main() {} //~ ERROR this file contains an un-closed delimiter +fn main() {} //~ ERROR this file contains an unclosed delimiter diff --git a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-trait.stderr b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-trait.stderr index 7e8abf22d55ab..213640127829c 100644 --- a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-trait.stderr +++ b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-trait.stderr @@ -1,11 +1,11 @@ -error: this file contains an un-closed delimiter - --> $DIR/missing-close-brace-in-trait.rs:12:66 +error: this file contains an unclosed delimiter + --> $DIR/missing-close-brace-in-trait.rs:12:65 | LL | trait T { - | - un-closed delimiter + | - unclosed delimiter ... LL | fn main() {} - | ^ + | ^ error: expected one of `async`, `const`, `default`, `extern`, `fn`, `type`, or `unsafe`, found keyword `struct` --> $DIR/missing-close-brace-in-trait.rs:5:12 @@ -23,7 +23,7 @@ LL | | ... | LL | | LL | | fn main() {} - | |_________________________________________________________________^ consider adding a `main` function to `$DIR/missing-close-brace-in-trait.rs` + | |________________________________________________________________^ consider adding a `main` function to `$DIR/missing-close-brace-in-trait.rs` error: aborting due to 3 previous errors diff --git a/src/test/ui/parser/mismatched-delim-brace-empty-block.rs b/src/test/ui/parser/mismatched-delim-brace-empty-block.rs index 0f5a2cb09ecc4..61d7a9af22359 100644 --- a/src/test/ui/parser/mismatched-delim-brace-empty-block.rs +++ b/src/test/ui/parser/mismatched-delim-brace-empty-block.rs @@ -2,4 +2,4 @@ fn main() { } let _ = (); -} //~ ERROR unexpected close delimiter +} //~ ERROR unexpected closing delimiter diff --git a/src/test/ui/parser/mismatched-delim-brace-empty-block.stderr b/src/test/ui/parser/mismatched-delim-brace-empty-block.stderr index 5ae5fc91a4e8a..311f1768d829c 100644 --- a/src/test/ui/parser/mismatched-delim-brace-empty-block.stderr +++ b/src/test/ui/parser/mismatched-delim-brace-empty-block.stderr @@ -1,4 +1,4 @@ -error: unexpected close delimiter: `}` +error: unexpected closing delimiter: `}` --> $DIR/mismatched-delim-brace-empty-block.rs:5:1 | LL | fn main() { @@ -8,7 +8,7 @@ LL | | } | |_- this block is empty, you might have not meant to close it LL | let _ = (); LL | } - | ^ unexpected close delimiter + | ^ unexpected closing delimiter error: aborting due to previous error diff --git a/src/test/ui/parser/missing_right_paren.stderr b/src/test/ui/parser/missing_right_paren.stderr index ac16ebe641271..c98b6bb6991c7 100644 --- a/src/test/ui/parser/missing_right_paren.stderr +++ b/src/test/ui/parser/missing_right_paren.stderr @@ -1,11 +1,11 @@ -error: this file contains an un-closed delimiter +error: this file contains an unclosed delimiter --> $DIR/missing_right_paren.rs:3:11 | LL | fn main((ؼ | -- ^ | || - | |un-closed delimiter - | un-closed delimiter + | |unclosed delimiter + | unclosed delimiter error: expected one of `:` or `|`, found `)` --> $DIR/missing_right_paren.rs:3:11 diff --git a/src/test/ui/parser/unclosed-braces.rs b/src/test/ui/parser/unclosed-braces.rs index 9c9ab766130cf..ed94fff386438 100644 --- a/src/test/ui/parser/unclosed-braces.rs +++ b/src/test/ui/parser/unclosed-braces.rs @@ -11,7 +11,7 @@ fn foo() { } fn main() { -//~^ NOTE un-closed delimiter +//~^ NOTE unclosed delimiter { { //~^ NOTE this delimiter might not be properly closed... @@ -19,4 +19,4 @@ fn main() { } //~^ NOTE ...as it matches this but it has different indentation } -//~ ERROR this file contains an un-closed delimiter +//~ ERROR this file contains an unclosed delimiter diff --git a/src/test/ui/parser/unclosed-braces.stderr b/src/test/ui/parser/unclosed-braces.stderr index 44c7e930a3a43..cbc5f8de4c3a7 100644 --- a/src/test/ui/parser/unclosed-braces.stderr +++ b/src/test/ui/parser/unclosed-braces.stderr @@ -1,8 +1,8 @@ -error: this file contains an un-closed delimiter - --> $DIR/unclosed-braces.rs:22:53 +error: this file contains an unclosed delimiter + --> $DIR/unclosed-braces.rs:22:52 | LL | fn main() { - | - un-closed delimiter + | - unclosed delimiter ... LL | { | - this delimiter might not be properly closed... @@ -11,7 +11,7 @@ LL | } | - ...as it matches this but it has different indentation ... LL | - | ^ + | ^ error: aborting due to previous error diff --git a/src/test/ui/parser/unclosed-delimiter-in-dep.stderr b/src/test/ui/parser/unclosed-delimiter-in-dep.stderr index bda59d4dea644..a32a27bf987cd 100644 --- a/src/test/ui/parser/unclosed-delimiter-in-dep.stderr +++ b/src/test/ui/parser/unclosed-delimiter-in-dep.stderr @@ -1,13 +1,13 @@ -error: incorrect close delimiter: `}` +error: mismatched closing delimiter: `}` --> $DIR/unclosed_delim_mod.rs:7:1 | LL | pub fn new() -> Result { - | - close delimiter possibly meant for this + | - closing delimiter possibly meant for this LL | Ok(Value { - | - un-closed delimiter + | - unclosed delimiter LL | } LL | } - | ^ incorrect close delimiter + | ^ mismatched closing delimiter error[E0308]: mismatched types --> $DIR/unclosed-delimiter-in-dep.rs:4:20 diff --git a/src/test/ui/parser/unclosed_delim_mod.rs b/src/test/ui/parser/unclosed_delim_mod.rs index 486e23312819d..d977d2c03de7e 100644 --- a/src/test/ui/parser/unclosed_delim_mod.rs +++ b/src/test/ui/parser/unclosed_delim_mod.rs @@ -5,4 +5,4 @@ pub fn new() -> Result { Ok(Value { } } -//~^ ERROR incorrect close delimiter +//~^ ERROR mismatched closing delimiter diff --git a/src/test/ui/parser/unclosed_delim_mod.stderr b/src/test/ui/parser/unclosed_delim_mod.stderr index fe2d968af0f32..9c16707212367 100644 --- a/src/test/ui/parser/unclosed_delim_mod.stderr +++ b/src/test/ui/parser/unclosed_delim_mod.stderr @@ -1,13 +1,13 @@ -error: incorrect close delimiter: `}` +error: mismatched closing delimiter: `}` --> $DIR/unclosed_delim_mod.rs:7:1 | LL | pub fn new() -> Result { - | - close delimiter possibly meant for this + | - closing delimiter possibly meant for this LL | Ok(Value { - | - un-closed delimiter + | - unclosed delimiter LL | } LL | } - | ^ incorrect close delimiter + | ^ mismatched closing delimiter error: aborting due to previous error diff --git a/src/test/ui/parser/unmatched-delimiter-at-end-of-file.rs b/src/test/ui/parser/unmatched-delimiter-at-end-of-file.rs index 3eef75bafd39b..f56013266ce52 100644 --- a/src/test/ui/parser/unmatched-delimiter-at-end-of-file.rs +++ b/src/test/ui/parser/unmatched-delimiter-at-end-of-file.rs @@ -8,4 +8,4 @@ fn main() { y: 5 }; } -fn foo() { //~ ERROR this file contains an un-closed delimiter +fn foo() { //~ ERROR this file contains an unclosed delimiter diff --git a/src/test/ui/parser/unmatched-delimiter-at-end-of-file.stderr b/src/test/ui/parser/unmatched-delimiter-at-end-of-file.stderr index bfbdb0363ef68..430a13e6e0713 100644 --- a/src/test/ui/parser/unmatched-delimiter-at-end-of-file.stderr +++ b/src/test/ui/parser/unmatched-delimiter-at-end-of-file.stderr @@ -1,8 +1,8 @@ -error: this file contains an un-closed delimiter - --> $DIR/unmatched-delimiter-at-end-of-file.rs:11:64 +error: this file contains an unclosed delimiter + --> $DIR/unmatched-delimiter-at-end-of-file.rs:11:63 | LL | fn foo() { - | - un-closed delimiter ^ + | - unclosed delimiter ^ error: aborting due to previous error diff --git a/src/test/ui/proc-macro/invalid-punct-ident-4.rs b/src/test/ui/proc-macro/invalid-punct-ident-4.rs index 5918782169597..e50f24deae343 100644 --- a/src/test/ui/proc-macro/invalid-punct-ident-4.rs +++ b/src/test/ui/proc-macro/invalid-punct-ident-4.rs @@ -4,4 +4,4 @@ extern crate invalid_punct_ident; lexer_failure!(); //~ ERROR proc macro panicked - //~| ERROR unexpected close delimiter: `)` + //~| ERROR unexpected closing delimiter: `)` diff --git a/src/test/ui/proc-macro/invalid-punct-ident-4.stderr b/src/test/ui/proc-macro/invalid-punct-ident-4.stderr index 65e40172ef539..e7764004e8de7 100644 --- a/src/test/ui/proc-macro/invalid-punct-ident-4.stderr +++ b/src/test/ui/proc-macro/invalid-punct-ident-4.stderr @@ -1,10 +1,10 @@ -error: unexpected close delimiter: `)` +error: unexpected closing delimiter: `)` --> $DIR/invalid-punct-ident-4.rs:6:1 | LL | lexer_failure!(); | ^^^^^^^^^^^^^^^^^ | | - | unexpected close delimiter + | unexpected closing delimiter | in this macro invocation error: proc macro panicked diff --git a/src/test/ui/resolve/token-error-correct-2.rs b/src/test/ui/resolve/token-error-correct-2.rs index 807a39c8c7f4b..f7c7d908c784f 100644 --- a/src/test/ui/resolve/token-error-correct-2.rs +++ b/src/test/ui/resolve/token-error-correct-2.rs @@ -3,5 +3,5 @@ fn main() { if foo { //~^ ERROR: cannot find value `foo` - ) //~ ERROR: incorrect close delimiter: `)` + ) //~ ERROR: mismatched closing delimiter: `)` } diff --git a/src/test/ui/resolve/token-error-correct-2.stderr b/src/test/ui/resolve/token-error-correct-2.stderr index d568117d67626..4014af2f41b61 100644 --- a/src/test/ui/resolve/token-error-correct-2.stderr +++ b/src/test/ui/resolve/token-error-correct-2.stderr @@ -1,11 +1,11 @@ -error: incorrect close delimiter: `)` +error: mismatched closing delimiter: `)` --> $DIR/token-error-correct-2.rs:6:5 | LL | if foo { - | - un-closed delimiter + | - unclosed delimiter LL | LL | ) - | ^ incorrect close delimiter + | ^ mismatched closing delimiter error[E0425]: cannot find value `foo` in this scope --> $DIR/token-error-correct-2.rs:4:8 diff --git a/src/test/ui/resolve/token-error-correct.rs b/src/test/ui/resolve/token-error-correct.rs index d64907780efb5..4f74df0bf1f39 100644 --- a/src/test/ui/resolve/token-error-correct.rs +++ b/src/test/ui/resolve/token-error-correct.rs @@ -4,6 +4,6 @@ fn main() { foo(bar(; //~^ ERROR cannot find function `bar` in this scope } -//~^ ERROR: incorrect close delimiter: `}` +//~^ ERROR: mismatched closing delimiter: `}` fn foo(_: usize) {} diff --git a/src/test/ui/resolve/token-error-correct.stderr b/src/test/ui/resolve/token-error-correct.stderr index 9452e2d68deca..bf300ecd78173 100644 --- a/src/test/ui/resolve/token-error-correct.stderr +++ b/src/test/ui/resolve/token-error-correct.stderr @@ -1,13 +1,13 @@ -error: incorrect close delimiter: `}` +error: mismatched closing delimiter: `}` --> $DIR/token-error-correct.rs:6:1 | LL | fn main() { - | - close delimiter possibly meant for this + | - closing delimiter possibly meant for this LL | foo(bar(; - | - un-closed delimiter + | - unclosed delimiter LL | LL | } - | ^ incorrect close delimiter + | ^ mismatched closing delimiter error[E0425]: cannot find function `bar` in this scope --> $DIR/token-error-correct.rs:4:9 From ae002c1d84a2a8e8a272a3c0db28b7402064f072 Mon Sep 17 00:00:00 2001 From: jumbatm Date: Sat, 4 Jan 2020 08:42:05 +1000 Subject: [PATCH 14/14] Also remove const-hack for abs --- src/libcore/num/mod.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 14540394caba1..605ab98219f91 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1997,27 +1997,15 @@ $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] + #[allow_internal_unstable(const_if_match)] #[inline] #[rustc_inherit_overflow_checks] pub const fn abs(self) -> Self { - // Note that the #[inline] above means that the overflow - // semantics of the subtraction depend on the crate we're being - // inlined into. - - // sign is -1 (all ones) for negative numbers, 0 otherwise. - let sign = self >> ($BITS - 1); - // For positive self, sign == 0 so the expression is simply - // (self ^ 0) - 0 == self == abs(self). - // - // For negative self, self ^ sign == self ^ all_ones. - // But all_ones ^ self == all_ones - self == -1 - self. - // So for negative numbers, (self ^ sign) - sign is - // (-1 - self) - -1 == -self == abs(self). - // - // The subtraction overflows when self is min_value(), because - // (-1 - min_value()) - -1 is max_value() - -1 which overflows. - // This is exactly when we want self.abs() to overflow. - (self ^ sign) - sign + if self.is_negative() { + -self + } else { + self + } } }