Skip to content

Tweak auto trait errors #137831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ast_passes_auto_generic = auto traits cannot have generic parameters

ast_passes_auto_items = auto traits cannot have associated items
.label = {ast_passes_auto_items}
.suggestion = remove these associated items
.suggestion = remove the associated items

ast_passes_auto_super_lifetime = auto traits cannot have super traits or lifetime bounds
.label = {ast_passes_auto_super_lifetime}
Expand Down
16 changes: 10 additions & 6 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,19 +589,23 @@ impl<'a> AstValidator<'a> {
}
}

fn deny_super_traits(&self, bounds: &GenericBounds, ident_span: Span) {
fn deny_super_traits(&self, bounds: &GenericBounds, ident: Span) {
if let [.., last] = &bounds[..] {
let span = ident_span.shrink_to_hi().to(last.span());
self.dcx().emit_err(errors::AutoTraitBounds { span, ident: ident_span });
let span = bounds.iter().map(|b| b.span()).collect();
let removal = ident.shrink_to_hi().to(last.span());
self.dcx().emit_err(errors::AutoTraitBounds { span, removal, ident });
}
}

fn deny_where_clause(&self, where_clause: &WhereClause, ident_span: Span) {
fn deny_where_clause(&self, where_clause: &WhereClause, ident: Span) {
if !where_clause.predicates.is_empty() {
// FIXME: The current diagnostic is misleading since it only talks about
// super trait and lifetime bounds while we should just say “bounds”.
self.dcx()
.emit_err(errors::AutoTraitBounds { span: where_clause.span, ident: ident_span });
self.dcx().emit_err(errors::AutoTraitBounds {
span: vec![where_clause.span],
removal: where_clause.span,
ident,
});
}
}

Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pub(crate) struct ModuleNonAscii {
#[diag(ast_passes_auto_generic, code = E0567)]
pub(crate) struct AutoTraitGeneric {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable")]
#[suggestion(code = "", applicability = "machine-applicable", style = "hidden")]
pub span: Span,
#[label]
pub ident: Span,
Expand All @@ -353,8 +353,9 @@ pub(crate) struct AutoTraitGeneric {
#[diag(ast_passes_auto_super_lifetime, code = E0568)]
pub(crate) struct AutoTraitBounds {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable")]
pub span: Span,
pub span: Vec<Span>,
#[suggestion(code = "", applicability = "machine-applicable", style = "hidden")]
pub removal: Span,
#[label]
pub ident: Span,
}
Expand All @@ -364,7 +365,7 @@ pub(crate) struct AutoTraitBounds {
pub(crate) struct AutoTraitItems {
#[primary_span]
pub spans: Vec<Span>,
#[suggestion(code = "", applicability = "machine-applicable")]
#[suggestion(code = "", applicability = "machine-applicable", style = "hidden")]
pub total: Span,
#[label]
pub ident: Span,
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/auto-traits/assoc-ty.current.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ LL | auto trait Trait {
| ----- auto traits cannot have associated items
LL |
LL | type Output;
| -----^^^^^^- help: remove these associated items
| ^^^^^^
|
= help: remove the associated items

error[E0658]: auto traits are experimental and possibly buggy
--> $DIR/assoc-ty.rs:8:1
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/auto-traits/assoc-ty.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ LL | auto trait Trait {
| ----- auto traits cannot have associated items
LL |
LL | type Output;
| -----^^^^^^- help: remove these associated items
| ^^^^^^
|
= help: remove the associated items

error[E0658]: auto traits are experimental and possibly buggy
--> $DIR/assoc-ty.rs:8:1
Expand Down
23 changes: 15 additions & 8 deletions tests/ui/auto-traits/auto-trait-validation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,41 @@ error[E0567]: auto traits cannot have generic parameters
--> $DIR/auto-trait-validation.rs:6:19
|
LL | auto trait Generic<T> {}
| -------^^^ help: remove the parameters
| -------^^^
| |
| auto trait cannot have generic parameters
|
= help: remove the parameters

error[E0568]: auto traits cannot have super traits or lifetime bounds
--> $DIR/auto-trait-validation.rs:8:17
--> $DIR/auto-trait-validation.rs:8:20
|
LL | auto trait Bound : Copy {}
| -----^^^^^^^ help: remove the super traits or lifetime bounds
| ----- ^^^^
| |
| auto traits cannot have super traits or lifetime bounds
|
= help: remove the super traits or lifetime bounds

error[E0568]: auto traits cannot have super traits or lifetime bounds
--> $DIR/auto-trait-validation.rs:10:25
--> $DIR/auto-trait-validation.rs:10:28
|
LL | auto trait LifetimeBound : 'static {}
| -------------^^^^^^^^^^ help: remove the super traits or lifetime bounds
| ------------- ^^^^^^^
| |
| auto traits cannot have super traits or lifetime bounds
|
= help: remove the super traits or lifetime bounds

error[E0380]: auto traits cannot have associated items
--> $DIR/auto-trait-validation.rs:12:25
|
LL | auto trait MyTrait { fn foo() {} }
| ------- ---^^^-----
| | |
| | help: remove these associated items
| ------- ^^^
| |
| auto traits cannot have associated items
|
= help: remove the associated items

error: aborting due to 4 previous errors

Expand Down
4 changes: 3 additions & 1 deletion tests/ui/auto-traits/bad-generics-on-dyn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ error[E0567]: auto traits cannot have generic parameters
--> $DIR/bad-generics-on-dyn.rs:3:18
|
LL | auto trait Trait1<'a> {}
| ------^^^^ help: remove the parameters
| ------^^^^
| |
| auto trait cannot have generic parameters
|
= help: remove the parameters

error: aborting due to 1 previous error

Expand Down
4 changes: 3 additions & 1 deletion tests/ui/auto-traits/has-arguments.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ error[E0567]: auto traits cannot have generic parameters
--> $DIR/has-arguments.rs:3:18
|
LL | auto trait Trait1<'outer> {}
| ------^^^^^^^^ help: remove the parameters
| ------^^^^^^^^
| |
| auto trait cannot have generic parameters
|
= help: remove the parameters

error: aborting due to 1 previous error

Expand Down
4 changes: 3 additions & 1 deletion tests/ui/auto-traits/issue-117789.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ error[E0567]: auto traits cannot have generic parameters
--> $DIR/issue-117789.rs:1:17
|
LL | auto trait Trait<P> {}
| -----^^^ help: remove the parameters
| -----^^^
| |
| auto trait cannot have generic parameters
|
= help: remove the parameters

error[E0658]: auto traits are experimental and possibly buggy
--> $DIR/issue-117789.rs:1:1
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/auto-traits/issue-23080-2.current.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ error[E0380]: auto traits cannot have associated items
LL | unsafe auto trait Trait {
| ----- auto traits cannot have associated items
LL | type Output;
| -----^^^^^^- help: remove these associated items
| ^^^^^^
|
= help: remove the associated items

error: aborting due to 1 previous error

Expand Down
4 changes: 3 additions & 1 deletion tests/ui/auto-traits/issue-23080-2.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ error[E0380]: auto traits cannot have associated items
LL | unsafe auto trait Trait {
| ----- auto traits cannot have associated items
LL | type Output;
| -----^^^^^^- help: remove these associated items
| ^^^^^^
|
= help: remove the associated items

error: aborting due to 1 previous error

Expand Down
13 changes: 6 additions & 7 deletions tests/ui/auto-traits/issue-23080.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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) {
| _____- ^^^^^^
LL | | println!("Hello");
LL | | }
| |_____- help: remove these associated items
LL | unsafe auto trait Trait {
| ----- auto traits cannot have associated items
LL | fn method(&self) {
| ^^^^^^
|
= help: remove the associated items

error: aborting due to 1 previous error

Expand Down
4 changes: 3 additions & 1 deletion tests/ui/auto-traits/issue-84075.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ error[E0568]: auto traits cannot have super traits or lifetime bounds
--> $DIR/issue-84075.rs:5:18
|
LL | auto trait Magic where Self: Copy {}
| ----- ^^^^^^^^^^^^^^^^ help: remove the super traits or lifetime bounds
| ----- ^^^^^^^^^^^^^^^^
| |
| auto traits cannot have super traits or lifetime bounds
|
= help: remove the super traits or lifetime bounds

error: aborting due to 1 previous error

Expand Down
10 changes: 7 additions & 3 deletions tests/ui/auto-traits/typeck-auto-trait-no-supertraits-2.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
error[E0568]: auto traits cannot have super traits or lifetime bounds
--> $DIR/typeck-auto-trait-no-supertraits-2.rs:4:17
--> $DIR/typeck-auto-trait-no-supertraits-2.rs:4:20
|
LL | auto trait Magic : Sized where Option<Self> : Magic {}
| -----^^^^^^^^ help: remove the super traits or lifetime bounds
| ----- ^^^^^
| |
| auto traits cannot have super traits or lifetime bounds
|
= help: remove the super traits or lifetime bounds

error[E0568]: auto traits cannot have super traits or lifetime bounds
--> $DIR/typeck-auto-trait-no-supertraits-2.rs:4:26
|
LL | auto trait Magic : Sized where Option<Self> : Magic {}
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the super traits or lifetime bounds
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| auto traits cannot have super traits or lifetime bounds
|
= help: remove the super traits or lifetime bounds

error[E0382]: use of moved value: `x`
--> $DIR/typeck-auto-trait-no-supertraits-2.rs:8:41
Expand Down
6 changes: 4 additions & 2 deletions tests/ui/auto-traits/typeck-auto-trait-no-supertraits.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
error[E0568]: auto traits cannot have super traits or lifetime bounds
--> $DIR/typeck-auto-trait-no-supertraits.rs:28:17
--> $DIR/typeck-auto-trait-no-supertraits.rs:28:19
|
LL | auto trait Magic: Copy {}
| -----^^^^^^ help: remove the super traits or lifetime bounds
| ----- ^^^^
| |
| auto traits cannot have super traits or lifetime bounds
|
= help: remove the super traits or lifetime bounds

error: aborting due to 1 previous error

Expand Down
4 changes: 3 additions & 1 deletion tests/ui/methods/issues/issue-105732.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ error[E0380]: auto traits cannot have associated items
LL | auto trait Foo {
| --- auto traits cannot have associated items
LL | fn g(&self);
| ---^-------- help: remove these associated items
| ^
|
= help: remove the associated items

error[E0599]: no method named `g` found for reference `&Self` in the current scope
--> $DIR/issue-105732.rs:10:14
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
error[E0568]: auto traits cannot have super traits or lifetime bounds
--> $DIR/supertrait-auto-trait.rs:8:17
--> $DIR/supertrait-auto-trait.rs:8:19
|
LL | auto trait Magic: Copy {}
| -----^^^^^^ help: remove the super traits or lifetime bounds
| ----- ^^^^
| |
| auto traits cannot have super traits or lifetime bounds
|
= help: remove the super traits or lifetime bounds

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