Skip to content

Commit 585fb6f

Browse files
committed
Tweak auto trait errors
Make suggestions to remove params and super traits verbose. ``` error[E0567]: auto traits cannot have generic parameters --> $DIR/auto-trait-validation.rs:6:19 | LL | auto trait Generic<T> {} | -------^^^ | | | auto trait cannot have generic parameters | help: remove the parameters | LL - auto trait Generic<T> {} LL + auto trait Generic {} | error[E0568]: auto traits cannot have super traits or lifetime bounds --> $DIR/auto-trait-validation.rs:8:20 | LL | auto trait Bound : Copy {} | ----- ^^^^ | | | auto traits cannot have super traits or lifetime bounds | help: remove the super traits or lifetime bounds | LL - auto trait Bound : Copy {} LL + auto trait Bound {} | ``` Make suggestion to remove associated items hidden. ``` error[E0380]: auto traits cannot have associated items --> $DIR/issue-23080.rs:5:8 | LL | unsafe auto trait Trait { | ----- auto traits cannot have associated items LL | fn method(&self) { | ^^^^^^ | = help: remove the associated items ``` Make spans smaller.
1 parent f45d4ac commit 585fb6f

17 files changed

+123
-42
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ast_passes_auto_generic = auto traits cannot have generic parameters
1818
1919
ast_passes_auto_items = auto traits cannot have associated items
2020
.label = {ast_passes_auto_items}
21-
.suggestion = remove these associated items
21+
.suggestion = remove the associated items
2222
2323
ast_passes_auto_super_lifetime = auto traits cannot have super traits or lifetime bounds
2424
.label = {ast_passes_auto_super_lifetime}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -589,19 +589,23 @@ impl<'a> AstValidator<'a> {
589589
}
590590
}
591591

592-
fn deny_super_traits(&self, bounds: &GenericBounds, ident_span: Span) {
592+
fn deny_super_traits(&self, bounds: &GenericBounds, ident: Span) {
593593
if let [.., last] = &bounds[..] {
594-
let span = ident_span.shrink_to_hi().to(last.span());
595-
self.dcx().emit_err(errors::AutoTraitBounds { span, ident: ident_span });
594+
let span = bounds.iter().map(|b| b.span()).collect();
595+
let removal = ident.shrink_to_hi().to(last.span());
596+
self.dcx().emit_err(errors::AutoTraitBounds { span, removal, ident });
596597
}
597598
}
598599

599-
fn deny_where_clause(&self, where_clause: &WhereClause, ident_span: Span) {
600+
fn deny_where_clause(&self, where_clause: &WhereClause, ident: Span) {
600601
if !where_clause.predicates.is_empty() {
601602
// FIXME: The current diagnostic is misleading since it only talks about
602603
// super trait and lifetime bounds while we should just say “bounds”.
603-
self.dcx()
604-
.emit_err(errors::AutoTraitBounds { span: where_clause.span, ident: ident_span });
604+
self.dcx().emit_err(errors::AutoTraitBounds {
605+
span: vec![where_clause.span],
606+
removal: where_clause.span,
607+
ident,
608+
});
605609
}
606610
}
607611

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ pub(crate) struct ModuleNonAscii {
343343
#[diag(ast_passes_auto_generic, code = E0567)]
344344
pub(crate) struct AutoTraitGeneric {
345345
#[primary_span]
346-
#[suggestion(code = "", applicability = "machine-applicable")]
346+
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
347347
pub span: Span,
348348
#[label]
349349
pub ident: Span,
@@ -353,8 +353,9 @@ pub(crate) struct AutoTraitGeneric {
353353
#[diag(ast_passes_auto_super_lifetime, code = E0568)]
354354
pub(crate) struct AutoTraitBounds {
355355
#[primary_span]
356-
#[suggestion(code = "", applicability = "machine-applicable")]
357-
pub span: Span,
356+
pub span: Vec<Span>,
357+
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
358+
pub removal: Span,
358359
#[label]
359360
pub ident: Span,
360361
}
@@ -364,7 +365,7 @@ pub(crate) struct AutoTraitBounds {
364365
pub(crate) struct AutoTraitItems {
365366
#[primary_span]
366367
pub spans: Vec<Span>,
367-
#[suggestion(code = "", applicability = "machine-applicable")]
368+
#[suggestion(code = "", applicability = "machine-applicable", style = "hidden")]
368369
pub total: Span,
369370
#[label]
370371
pub ident: Span,

tests/ui/auto-traits/assoc-ty.current.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ LL | auto trait Trait {
55
| ----- auto traits cannot have associated items
66
LL |
77
LL | type Output;
8-
| -----^^^^^^- help: remove these associated items
8+
| ^^^^^^
9+
|
10+
= help: remove the associated items
911

1012
error[E0658]: auto traits are experimental and possibly buggy
1113
--> $DIR/assoc-ty.rs:8:1

tests/ui/auto-traits/assoc-ty.next.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ LL | auto trait Trait {
55
| ----- auto traits cannot have associated items
66
LL |
77
LL | type Output;
8-
| -----^^^^^^- help: remove these associated items
8+
| ^^^^^^
9+
|
10+
= help: remove the associated items
911

1012
error[E0658]: auto traits are experimental and possibly buggy
1113
--> $DIR/assoc-ty.rs:8:1

tests/ui/auto-traits/auto-trait-validation.stderr

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,53 @@ error[E0567]: auto traits cannot have generic parameters
22
--> $DIR/auto-trait-validation.rs:6:19
33
|
44
LL | auto trait Generic<T> {}
5-
| -------^^^ help: remove the parameters
5+
| -------^^^
66
| |
77
| auto trait cannot have generic parameters
8+
|
9+
help: remove the parameters
10+
|
11+
LL - auto trait Generic<T> {}
12+
LL + auto trait Generic {}
13+
|
814

915
error[E0568]: auto traits cannot have super traits or lifetime bounds
10-
--> $DIR/auto-trait-validation.rs:8:17
16+
--> $DIR/auto-trait-validation.rs:8:20
1117
|
1218
LL | auto trait Bound : Copy {}
13-
| -----^^^^^^^ help: remove the super traits or lifetime bounds
19+
| ----- ^^^^
1420
| |
1521
| auto traits cannot have super traits or lifetime bounds
22+
|
23+
help: remove the super traits or lifetime bounds
24+
|
25+
LL - auto trait Bound : Copy {}
26+
LL + auto trait Bound {}
27+
|
1628

1729
error[E0568]: auto traits cannot have super traits or lifetime bounds
18-
--> $DIR/auto-trait-validation.rs:10:25
30+
--> $DIR/auto-trait-validation.rs:10:28
1931
|
2032
LL | auto trait LifetimeBound : 'static {}
21-
| -------------^^^^^^^^^^ help: remove the super traits or lifetime bounds
33+
| ------------- ^^^^^^^
2234
| |
2335
| auto traits cannot have super traits or lifetime bounds
36+
|
37+
help: remove the super traits or lifetime bounds
38+
|
39+
LL - auto trait LifetimeBound : 'static {}
40+
LL + auto trait LifetimeBound {}
41+
|
2442

2543
error[E0380]: auto traits cannot have associated items
2644
--> $DIR/auto-trait-validation.rs:12:25
2745
|
2846
LL | auto trait MyTrait { fn foo() {} }
29-
| ------- ---^^^-----
30-
| | |
31-
| | help: remove these associated items
47+
| ------- ^^^
48+
| |
3249
| auto traits cannot have associated items
50+
|
51+
= help: remove the associated items
3352

3453
error: aborting due to 4 previous errors
3554

tests/ui/auto-traits/bad-generics-on-dyn.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ error[E0567]: auto traits cannot have generic parameters
22
--> $DIR/bad-generics-on-dyn.rs:3:18
33
|
44
LL | auto trait Trait1<'a> {}
5-
| ------^^^^ help: remove the parameters
5+
| ------^^^^
66
| |
77
| auto trait cannot have generic parameters
8+
|
9+
help: remove the parameters
10+
|
11+
LL - auto trait Trait1<'a> {}
12+
LL + auto trait Trait1 {}
13+
|
814

915
error: aborting due to 1 previous error
1016

tests/ui/auto-traits/has-arguments.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ error[E0567]: auto traits cannot have generic parameters
22
--> $DIR/has-arguments.rs:3:18
33
|
44
LL | auto trait Trait1<'outer> {}
5-
| ------^^^^^^^^ help: remove the parameters
5+
| ------^^^^^^^^
66
| |
77
| auto trait cannot have generic parameters
8+
|
9+
help: remove the parameters
10+
|
11+
LL - auto trait Trait1<'outer> {}
12+
LL + auto trait Trait1 {}
13+
|
814

915
error: aborting due to 1 previous error
1016

tests/ui/auto-traits/issue-117789.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ error[E0567]: auto traits cannot have generic parameters
22
--> $DIR/issue-117789.rs:1:17
33
|
44
LL | auto trait Trait<P> {}
5-
| -----^^^ help: remove the parameters
5+
| -----^^^
66
| |
77
| auto trait cannot have generic parameters
8+
|
9+
help: remove the parameters
10+
|
11+
LL - auto trait Trait<P> {}
12+
LL + auto trait Trait {}
13+
|
814

915
error[E0658]: auto traits are experimental and possibly buggy
1016
--> $DIR/issue-117789.rs:1:1

tests/ui/auto-traits/issue-23080-2.current.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ error[E0380]: auto traits cannot have associated items
44
LL | unsafe auto trait Trait {
55
| ----- auto traits cannot have associated items
66
LL | type Output;
7-
| -----^^^^^^- help: remove these associated items
7+
| ^^^^^^
8+
|
9+
= help: remove the associated items
810

911
error: aborting due to 1 previous error
1012

tests/ui/auto-traits/issue-23080-2.next.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ error[E0380]: auto traits cannot have associated items
44
LL | unsafe auto trait Trait {
55
| ----- auto traits cannot have associated items
66
LL | type Output;
7-
| -----^^^^^^- help: remove these associated items
7+
| ^^^^^^
8+
|
9+
= help: remove the associated items
810

911
error: aborting due to 1 previous error
1012

tests/ui/auto-traits/issue-23080.stderr

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
error[E0380]: auto traits cannot have associated items
22
--> $DIR/issue-23080.rs:5:8
33
|
4-
LL | unsafe auto trait Trait {
5-
| ----- auto traits cannot have associated items
6-
LL | fn method(&self) {
7-
| _____- ^^^^^^
8-
LL | | println!("Hello");
9-
LL | | }
10-
| |_____- help: remove these associated items
4+
LL | unsafe auto trait Trait {
5+
| ----- auto traits cannot have associated items
6+
LL | fn method(&self) {
7+
| ^^^^^^
8+
|
9+
= help: remove the associated items
1110

1211
error: aborting due to 1 previous error
1312

tests/ui/auto-traits/issue-84075.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ error[E0568]: auto traits cannot have super traits or lifetime bounds
22
--> $DIR/issue-84075.rs:5:18
33
|
44
LL | auto trait Magic where Self: Copy {}
5-
| ----- ^^^^^^^^^^^^^^^^ help: remove the super traits or lifetime bounds
5+
| ----- ^^^^^^^^^^^^^^^^
66
| |
77
| auto traits cannot have super traits or lifetime bounds
8+
|
9+
help: remove the super traits or lifetime bounds
10+
|
11+
LL - auto trait Magic where Self: Copy {}
12+
LL + auto trait Magic {}
13+
|
814

915
error: aborting due to 1 previous error
1016

tests/ui/auto-traits/typeck-auto-trait-no-supertraits-2.stderr

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
error[E0568]: auto traits cannot have super traits or lifetime bounds
2-
--> $DIR/typeck-auto-trait-no-supertraits-2.rs:4:17
2+
--> $DIR/typeck-auto-trait-no-supertraits-2.rs:4:20
33
|
44
LL | auto trait Magic : Sized where Option<Self> : Magic {}
5-
| -----^^^^^^^^ help: remove the super traits or lifetime bounds
5+
| ----- ^^^^^
66
| |
77
| auto traits cannot have super traits or lifetime bounds
8+
|
9+
help: remove the super traits or lifetime bounds
10+
|
11+
LL - auto trait Magic : Sized where Option<Self> : Magic {}
12+
LL + auto trait Magic where Option<Self> : Magic {}
13+
|
814

915
error[E0568]: auto traits cannot have super traits or lifetime bounds
1016
--> $DIR/typeck-auto-trait-no-supertraits-2.rs:4:26
1117
|
1218
LL | auto trait Magic : Sized where Option<Self> : Magic {}
13-
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the super traits or lifetime bounds
19+
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^
1420
| |
1521
| auto traits cannot have super traits or lifetime bounds
22+
|
23+
help: remove the super traits or lifetime bounds
24+
|
25+
LL - auto trait Magic : Sized where Option<Self> : Magic {}
26+
LL + auto trait Magic : Sized {}
27+
|
1628

1729
error[E0382]: use of moved value: `x`
1830
--> $DIR/typeck-auto-trait-no-supertraits-2.rs:8:41

tests/ui/auto-traits/typeck-auto-trait-no-supertraits.stderr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
error[E0568]: auto traits cannot have super traits or lifetime bounds
2-
--> $DIR/typeck-auto-trait-no-supertraits.rs:28:17
2+
--> $DIR/typeck-auto-trait-no-supertraits.rs:28:19
33
|
44
LL | auto trait Magic: Copy {}
5-
| -----^^^^^^ help: remove the super traits or lifetime bounds
5+
| ----- ^^^^
66
| |
77
| auto traits cannot have super traits or lifetime bounds
8+
|
9+
help: remove the super traits or lifetime bounds
10+
|
11+
LL - auto trait Magic: Copy {}
12+
LL + auto trait Magic {}
13+
|
814

915
error: aborting due to 1 previous error
1016

tests/ui/methods/issues/issue-105732.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ error[E0380]: auto traits cannot have associated items
44
LL | auto trait Foo {
55
| --- auto traits cannot have associated items
66
LL | fn g(&self);
7-
| ---^-------- help: remove these associated items
7+
| ^
8+
|
9+
= help: remove the associated items
810

911
error[E0599]: no method named `g` found for reference `&Self` in the current scope
1012
--> $DIR/issue-105732.rs:10:14

tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
error[E0568]: auto traits cannot have super traits or lifetime bounds
2-
--> $DIR/supertrait-auto-trait.rs:8:17
2+
--> $DIR/supertrait-auto-trait.rs:8:19
33
|
44
LL | auto trait Magic: Copy {}
5-
| -----^^^^^^ help: remove the super traits or lifetime bounds
5+
| ----- ^^^^
66
| |
77
| auto traits cannot have super traits or lifetime bounds
8+
|
9+
help: remove the super traits or lifetime bounds
10+
|
11+
LL - auto trait Magic: Copy {}
12+
LL + auto trait Magic {}
13+
|
814

915
error[E0277]: the trait bound `NoClone: Magic` is not satisfied
1016
--> $DIR/supertrait-auto-trait.rs:16:23

0 commit comments

Comments
 (0)