diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index eff58ad4d9aab..df229e57cf0b7 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -910,6 +910,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> { item.ident.span, "auto trait cannot have generic parameters", ); + err.span_suggestion_verbose( + generics.span, + "remove the parameters for the auto trait to be valid", + String::new(), + Applicability::MachineApplicable, + ); err.emit(); } if !bounds.is_empty() { @@ -922,6 +928,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { 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, @@ -931,8 +938,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { 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_label(item.ident.span, "auto trait cannot have super traits"); 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 75919a1f9913f..17d9ca71d149a 100644 --- a/src/test/ui/auto-trait-validation.stderr +++ b/src/test/ui/auto-trait-validation.stderr @@ -5,6 +5,11 @@ LL | auto trait Generic {} | ------- ^ cannot have this generic parameter | | | 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 @@ -13,6 +18,11 @@ LL | auto trait Bound : Copy {} | ----- ^^^^ cannot have this super trait | | | 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 03d05f4c928a6..8714cfbedbbc1 100644 --- a/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr +++ b/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr @@ -5,6 +5,11 @@ LL | auto trait Magic: Copy {} | ----- ^^^^ cannot have this super trait | | | 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 45c95b191bd59..c652a0c6df03d 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 @@ -5,6 +5,11 @@ LL | auto trait Magic : Sized where Option : Magic {} | ----- ^^^^^ cannot have this super trait | | | 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 094f5d7dd24f2..fe6468bc71621 100644 --- a/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr +++ b/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr @@ -5,6 +5,11 @@ LL | auto trait Magic: Copy {} | ----- ^^^^ cannot have this super trait | | | 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