Skip to content

Commit 005fc6e

Browse files
committed
Suggest removal of auto trait super traits and type params
1 parent 6fba412 commit 005fc6e

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

src/librustc_ast_passes/ast_validation.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
910910
item.ident.span,
911911
"auto trait cannot have generic parameters",
912912
);
913+
err.span_suggestion_verbose(
914+
generics.span,
915+
"remove the parameters for the auto trait to be valid",
916+
String::new(),
917+
Applicability::MachineApplicable,
918+
);
913919
err.emit();
914920
}
915921
if !bounds.is_empty() {
@@ -922,6 +928,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
922928
E0568,
923929
"auto traits cannot have super traits"
924930
);
931+
err.span_label(item.ident.span, "auto trait cannot have super traits");
925932
if let Some(span) = last {
926933
err.span_label(
927934
span,
@@ -931,8 +938,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
931938
s = pluralize!(len)
932939
),
933940
);
941+
err.span_suggestion_verbose(
942+
generics.span.shrink_to_hi().to(span),
943+
"remove the super traits for the auto trait to be valid",
944+
String::new(),
945+
Applicability::MachineApplicable,
946+
);
934947
}
935-
err.span_label(item.ident.span, "auto trait cannot have super traits");
936948
err.emit();
937949
}
938950
if !trait_items.is_empty() {

src/test/ui/auto-trait-validation.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ LL | auto trait Generic<T> {}
55
| ------- ^ cannot have this generic parameter
66
| |
77
| auto trait cannot have generic parameters
8+
|
9+
help: remove the parameters for the auto trait to be valid
10+
|
11+
LL | auto trait Generic {}
12+
| --
813

914
error[E0568]: auto traits cannot have super traits
1015
--> $DIR/auto-trait-validation.rs:5:20
@@ -13,6 +18,11 @@ LL | auto trait Bound : Copy {}
1318
| ----- ^^^^ cannot have this super trait
1419
| |
1520
| auto trait cannot have super traits
21+
|
22+
help: remove the super traits for the auto trait to be valid
23+
|
24+
LL | auto trait Bound {}
25+
| --
1626

1727
error[E0380]: auto traits cannot have methods or associated items
1828
--> $DIR/auto-trait-validation.rs:7:25

src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ LL | auto trait Magic: Copy {}
55
| ----- ^^^^ cannot have this super trait
66
| |
77
| auto trait cannot have super traits
8+
|
9+
help: remove the super traits for the auto trait to be valid
10+
|
11+
LL | auto trait Magic {}
12+
| --
813

914
error[E0277]: the trait bound `NoClone: std::marker::Copy` is not satisfied
1015
--> $DIR/traits-inductive-overflow-supertrait-oibit.rs:15:23

src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ LL | auto trait Magic : Sized where Option<Self> : Magic {}
55
| ----- ^^^^^ cannot have this super trait
66
| |
77
| auto trait cannot have super traits
8+
|
9+
help: remove the super traits for the auto trait to be valid
10+
|
11+
LL | auto trait Magic where Option<Self> : Magic {}
12+
| --
813

914
error: aborting due to previous error
1015

src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ LL | auto trait Magic: Copy {}
55
| ----- ^^^^ cannot have this super trait
66
| |
77
| auto trait cannot have super traits
8+
|
9+
help: remove the super traits for the auto trait to be valid
10+
|
11+
LL | auto trait Magic {}
12+
| --
813

914
error: aborting due to previous error
1015

0 commit comments

Comments
 (0)