From 29be741c9c15a69487cb2eae9bb895399806731f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 10 Mar 2020 17:59:32 -0700 Subject: [PATCH] review comments --- src/librustc_ast_passes/ast_validation.rs | 53 ++++++------------- src/test/ui/auto-trait-validation.stderr | 16 ++---- ...inductive-overflow-supertrait-oibit.stderr | 7 +-- .../typeck-auto-trait-no-supertraits-2.stderr | 7 +-- .../typeck-auto-trait-no-supertraits.stderr | 7 +-- 5 files changed, 22 insertions(+), 68 deletions(-) diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index 24cf4556dad..668ac8047d1 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -13,7 +13,7 @@ use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor}; use rustc_ast::walk_list; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{error_code, pluralize, struct_span_err, Applicability}; +use rustc_errors::{error_code, struct_span_err, Applicability}; use rustc_parse::validate_attr; use rustc_session::lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY; use rustc_session::lint::LintBuffer; @@ -882,64 +882,43 @@ impl<'a> Visitor<'a> for AstValidator<'a> { if is_auto == IsAuto::Yes { // Auto traits cannot have generics, super traits nor contain items. if !generics.params.is_empty() { - let spans: Vec<_> = generics.params.iter().map(|i| i.ident.span).collect(); - let last = spans.iter().last().map(|s| *s); - let len = spans.len(); let mut err = struct_span_err!( self.session, - spans, + generics.span, E0567, "auto traits cannot have generic parameters" ); - if let Some(span) = last { - err.span_label( - span, - &format!( - "cannot have {these} generic parameter{s}", - these = if len == 1 { "this" } else { "these" }, - s = pluralize!(len) - ), - ); - } err.span_label( item.ident.span, "auto trait cannot have generic parameters", ); - err.span_suggestion_verbose( + err.span_suggestion( generics.span, - "remove the parameters for the auto trait to be valid", + "remove the parameters", String::new(), Applicability::MachineApplicable, ); err.emit(); } if !bounds.is_empty() { - let spans: Vec<_> = bounds.iter().map(|b| b.span()).collect(); - let last = spans.iter().last().map(|s| *s); - let len = spans.len(); + let span = match &bounds[..] { + [] => unreachable!(), + [single] => single.span(), + [first, .., last] => first.span().to(last.span()), + }; let mut err = struct_span_err!( self.session, - spans, + span, E0568, "auto traits cannot have super traits" ); err.span_label(item.ident.span, "auto trait cannot have super traits"); - if let Some(span) = last { - err.span_label( - span, - &format!( - "cannot have {these} super trait{s}", - these = if len == 1 { "this" } else { "these" }, - s = pluralize!(len) - ), - ); - err.span_suggestion_verbose( - generics.span.shrink_to_hi().to(span), - "remove the super traits for the auto trait to be valid", - String::new(), - Applicability::MachineApplicable, - ); - } + err.span_suggestion( + span, + "remove the super traits", + String::new(), + Applicability::MachineApplicable, + ); err.emit(); } if !trait_items.is_empty() { diff --git a/src/test/ui/auto-trait-validation.stderr b/src/test/ui/auto-trait-validation.stderr index 17d9ca71d14..4040e66c6af 100644 --- a/src/test/ui/auto-trait-validation.stderr +++ b/src/test/ui/auto-trait-validation.stderr @@ -1,28 +1,18 @@ error[E0567]: auto traits cannot have generic parameters - --> $DIR/auto-trait-validation.rs:3:20 + --> $DIR/auto-trait-validation.rs:3:19 | LL | auto trait Generic {} - | ------- ^ cannot have this generic parameter + | -------^^^ help: remove the parameters | | | auto trait cannot have generic parameters - | -help: remove the parameters for the auto trait to be valid - | -LL | auto trait Generic {} - | -- error[E0568]: auto traits cannot have super traits --> $DIR/auto-trait-validation.rs:5:20 | LL | auto trait Bound : Copy {} - | ----- ^^^^ cannot have this super trait + | ----- ^^^^ help: remove the super traits | | | auto trait cannot have super traits - | -help: remove the super traits for the auto trait to be valid - | -LL | auto trait Bound {} - | -- error[E0380]: auto traits cannot have methods or associated items --> $DIR/auto-trait-validation.rs:7:25 diff --git a/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr b/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr index 8714cfbedbb..a83ff370151 100644 --- a/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr +++ b/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr @@ -2,14 +2,9 @@ error[E0568]: auto traits cannot have super traits --> $DIR/traits-inductive-overflow-supertrait-oibit.rs:7:19 | LL | auto trait Magic: Copy {} - | ----- ^^^^ cannot have this super trait + | ----- ^^^^ help: remove the super traits | | | auto trait cannot have super traits - | -help: remove the super traits for the auto trait to be valid - | -LL | auto trait Magic {} - | -- error[E0277]: the trait bound `NoClone: std::marker::Copy` is not satisfied --> $DIR/traits-inductive-overflow-supertrait-oibit.rs:15:23 diff --git a/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr b/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr index c652a0c6df0..e3976293277 100644 --- a/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr +++ b/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr @@ -2,14 +2,9 @@ error[E0568]: auto traits cannot have super traits --> $DIR/typeck-auto-trait-no-supertraits-2.rs:3:20 | LL | auto trait Magic : Sized where Option : Magic {} - | ----- ^^^^^ cannot have this super trait + | ----- ^^^^^ help: remove the super traits | | | auto trait cannot have super traits - | -help: remove the super traits for the auto trait to be valid - | -LL | auto trait Magic where Option : Magic {} - | -- error: aborting due to previous error diff --git a/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr b/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr index fe6468bc716..b1602e3642e 100644 --- a/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr +++ b/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr @@ -2,14 +2,9 @@ error[E0568]: auto traits cannot have super traits --> $DIR/typeck-auto-trait-no-supertraits.rs:27:19 | LL | auto trait Magic: Copy {} - | ----- ^^^^ cannot have this super trait + | ----- ^^^^ help: remove the super traits | | | auto trait cannot have super traits - | -help: remove the super traits for the auto trait to be valid - | -LL | auto trait Magic {} - | -- error: aborting due to previous error