Skip to content

Commit 26a9d8f

Browse files
Auto merge of #137831 - estebank:auto-trait-err, r=<try>
Tweak auto trait errors try-job: dist-ohos-x86_64
2 parents 6bcdcc7 + 91e606b commit 26a9d8f

19 files changed

+118
-43
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ast_passes_auto_generic = auto traits cannot have generic parameters
4040
4141
ast_passes_auto_items = auto traits cannot have associated items
4242
.label = {ast_passes_auto_items}
43-
.suggestion = remove these associated items
43+
.suggestion = remove the associated items
4444
4545
ast_passes_auto_super_lifetime = auto traits cannot have super traits or lifetime bounds
4646
.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
@@ -699,19 +699,23 @@ impl<'a> AstValidator<'a> {
699699
}
700700
}
701701

702-
fn deny_super_traits(&self, bounds: &GenericBounds, ident_span: Span) {
702+
fn deny_super_traits(&self, bounds: &GenericBounds, ident: Span) {
703703
if let [.., last] = &bounds[..] {
704-
let span = ident_span.shrink_to_hi().to(last.span());
705-
self.dcx().emit_err(errors::AutoTraitBounds { span, ident: ident_span });
704+
let span = bounds.iter().map(|b| b.span()).collect();
705+
let removal = ident.shrink_to_hi().to(last.span());
706+
self.dcx().emit_err(errors::AutoTraitBounds { span, removal, ident });
706707
}
707708
}
708709

709-
fn deny_where_clause(&self, where_clause: &WhereClause, ident_span: Span) {
710+
fn deny_where_clause(&self, where_clause: &WhereClause, ident: Span) {
710711
if !where_clause.predicates.is_empty() {
711712
// FIXME: The current diagnostic is misleading since it only talks about
712713
// super trait and lifetime bounds while we should just say “bounds”.
713-
self.dcx()
714-
.emit_err(errors::AutoTraitBounds { span: where_clause.span, ident: ident_span });
714+
self.dcx().emit_err(errors::AutoTraitBounds {
715+
span: vec![where_clause.span],
716+
removal: where_clause.span,
717+
ident,
718+
});
715719
}
716720
}
717721

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub(crate) struct ModuleNonAscii {
344344
#[diag(ast_passes_auto_generic, code = E0567)]
345345
pub(crate) struct AutoTraitGeneric {
346346
#[primary_span]
347-
#[suggestion(code = "", applicability = "machine-applicable")]
347+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
348348
pub span: Span,
349349
#[label]
350350
pub ident: Span,
@@ -354,8 +354,9 @@ pub(crate) struct AutoTraitGeneric {
354354
#[diag(ast_passes_auto_super_lifetime, code = E0568)]
355355
pub(crate) struct AutoTraitBounds {
356356
#[primary_span]
357-
#[suggestion(code = "", applicability = "machine-applicable")]
358-
pub span: Span,
357+
pub span: Vec<Span>,
358+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
359+
pub removal: Span,
359360
#[label]
360361
pub ident: Span,
361362
}
@@ -365,7 +366,7 @@ pub(crate) struct AutoTraitBounds {
365366
pub(crate) struct AutoTraitItems {
366367
#[primary_span]
367368
pub spans: Vec<Span>,
368-
#[suggestion(code = "", applicability = "machine-applicable")]
369+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
369370
pub total: Span,
370371
#[label]
371372
pub ident: Span,

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

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

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

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

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

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

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,15 @@ auto trait LifetimeBound {}
1111
//~^ ERROR auto traits cannot have super traits or lifetime bounds [E0568]
1212
auto trait MyTrait { }
1313
//~^ ERROR auto traits cannot have associated items [E0380]
14+
auto trait AssocTy { }
15+
//~^ ERROR auto traits cannot have associated items [E0380]
16+
auto trait All {
17+
//~^ ERROR auto traits cannot have generic parameters [E0567]
18+
19+
}
20+
// We can't test both generic params and super-traits because the suggestion span overlaps.
21+
auto trait All2 {
22+
//~^ ERROR auto traits cannot have super traits or lifetime bounds [E0568]
23+
24+
}
1425
fn main() {}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,19 @@ auto trait LifetimeBound : 'static {}
1111
//~^ ERROR auto traits cannot have super traits or lifetime bounds [E0568]
1212
auto trait MyTrait { fn foo() {} }
1313
//~^ ERROR auto traits cannot have associated items [E0380]
14+
auto trait AssocTy { type Bar; }
15+
//~^ ERROR auto traits cannot have associated items [E0380]
16+
auto trait All<'a, T> {
17+
//~^ ERROR auto traits cannot have generic parameters [E0567]
18+
type Bar;
19+
//~^ ERROR auto traits cannot have associated items [E0380]
20+
fn foo() {}
21+
}
22+
// We can't test both generic params and super-traits because the suggestion span overlaps.
23+
auto trait All2: Copy + 'static {
24+
//~^ ERROR auto traits cannot have super traits or lifetime bounds [E0568]
25+
type Bar;
26+
//~^ ERROR auto traits cannot have associated items [E0380]
27+
fn foo() {}
28+
}
1429
fn main() {}

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

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,83 @@ 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
88

99
error[E0568]: auto traits cannot have super traits or lifetime bounds
10-
--> $DIR/auto-trait-validation.rs:8:17
10+
--> $DIR/auto-trait-validation.rs:8:20
1111
|
1212
LL | auto trait Bound : Copy {}
13-
| -----^^^^^^^ help: remove the super traits or lifetime bounds
13+
| ----- ^^^^
1414
| |
1515
| auto traits cannot have super traits or lifetime bounds
1616

1717
error[E0568]: auto traits cannot have super traits or lifetime bounds
18-
--> $DIR/auto-trait-validation.rs:10:25
18+
--> $DIR/auto-trait-validation.rs:10:28
1919
|
2020
LL | auto trait LifetimeBound : 'static {}
21-
| -------------^^^^^^^^^^ help: remove the super traits or lifetime bounds
21+
| ------------- ^^^^^^^
2222
| |
2323
| auto traits cannot have super traits or lifetime bounds
2424

2525
error[E0380]: auto traits cannot have associated items
2626
--> $DIR/auto-trait-validation.rs:12:25
2727
|
2828
LL | auto trait MyTrait { fn foo() {} }
29-
| ------- ---^^^-----
30-
| | |
31-
| | help: remove these associated items
29+
| ------- ^^^
30+
| |
31+
| auto traits cannot have associated items
32+
33+
error[E0380]: auto traits cannot have associated items
34+
--> $DIR/auto-trait-validation.rs:14:27
35+
|
36+
LL | auto trait AssocTy { type Bar; }
37+
| ------- ^^^
38+
| |
3239
| auto traits cannot have associated items
3340

34-
error: aborting due to 4 previous errors
41+
error[E0567]: auto traits cannot have generic parameters
42+
--> $DIR/auto-trait-validation.rs:16:15
43+
|
44+
LL | auto trait All<'a, T> {
45+
| ---^^^^^^^
46+
| |
47+
| auto trait cannot have generic parameters
48+
49+
error[E0380]: auto traits cannot have associated items
50+
--> $DIR/auto-trait-validation.rs:18:10
51+
|
52+
LL | auto trait All<'a, T> {
53+
| --- auto traits cannot have associated items
54+
LL |
55+
LL | type Bar;
56+
| ^^^
57+
LL |
58+
LL | fn foo() {}
59+
| ^^^
60+
61+
error[E0568]: auto traits cannot have super traits or lifetime bounds
62+
--> $DIR/auto-trait-validation.rs:23:18
63+
|
64+
LL | auto trait All2: Copy + 'static {
65+
| ---- ^^^^ ^^^^^^^
66+
| |
67+
| auto traits cannot have super traits or lifetime bounds
68+
69+
error[E0380]: auto traits cannot have associated items
70+
--> $DIR/auto-trait-validation.rs:25:10
71+
|
72+
LL | auto trait All2: Copy + 'static {
73+
| ---- auto traits cannot have associated items
74+
LL |
75+
LL | type Bar;
76+
| ^^^
77+
LL |
78+
LL | fn foo() {}
79+
| ^^^
80+
81+
error: aborting due to 9 previous errors
3582

3683
Some errors have detailed explanations: E0380, E0567, E0568.
3784
For more information about an error, try `rustc --explain E0380`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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
88

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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
88

0 commit comments

Comments
 (0)