Skip to content

Commit

Permalink
Suggest removal of auto trait super traits and type params
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 6, 2020
1 parent 6fba412 commit 005fc6e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/librustc_ast_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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,
Expand All @@ -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() {
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/auto-trait-validation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ LL | auto trait Generic<T> {}
| ------- ^ 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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ LL | auto trait Magic : Sized where Option<Self> : 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<Self> : Magic {}
| --

error: aborting due to previous error

Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 005fc6e

Please sign in to comment.