Skip to content

Commit

Permalink
Remove special handling for impl Trait for .. syntax errors.
Browse files Browse the repository at this point in the history
The ancient (pre-1.0) RFC 19 suggested using `impl Trait for ..` syntax
for default traits. That was later changed to `auto trait Trait {}`
syntax. The parser has special treatment for the `..` syntax, suggesting
the `auto` syntax.

Given that default traits have not be stabilized and the `..` syntax is
so old, the special case seems unnecessary, and it gets in the way of
adding `ErrorGuaranteed` to `TyKind::Err`. This commit removes it and
the tests.
  • Loading branch information
nnethercote committed Feb 21, 2024
1 parent f8131a4 commit 40f1be0
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 88 deletions.
5 changes: 0 additions & 5 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,11 +881,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
&item.vis,
errors::VisibilityNotPermittedNote::TraitImpl,
);
if let TyKind::Dummy = self_ty.kind {
// Abort immediately otherwise the `TyKind::Dummy` will reach HIR lowering,
// which isn't allowed. Not a problem for this obscure, obsolete syntax.
this.dcx().emit_fatal(errors::ObsoleteAuto { span: item.span });
}
if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity)
{
this.dcx().emit_err(errors::UnsafeNegativeImpl {
Expand Down
15 changes: 2 additions & 13 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,19 +597,8 @@ impl<'a> Parser<'a> {
let has_for = self.eat_keyword(kw::For);
let missing_for_span = self.prev_token.span.between(self.token.span);

let ty_second = if self.token == token::DotDot {
// We need to report this error after `cfg` expansion for compatibility reasons
self.bump(); // `..`, do not add it to expected tokens

// AST validation later detects this `TyKind::Dummy` and emits an
// error. (#121072 will hopefully remove all this special handling
// of the obsolete `impl Trait for ..` and then this can go away.)
Some(self.mk_ty(self.prev_token.span, TyKind::Dummy))
} else if has_for || self.token.can_begin_type() {
Some(self.parse_ty()?)
} else {
None
};
let ty_second =
if has_for || self.token.can_begin_type() { Some(self.parse_ty()?) } else { None };

generics.where_clause = self.parse_where_clause()?;

Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3325,7 +3325,6 @@
"ui/parser/issues/issue-24197.rs",
"ui/parser/issues/issue-24375.rs",
"ui/parser/issues/issue-24780.rs",
"ui/parser/issues/issue-27255.rs",
"ui/parser/issues/issue-30318.rs",
"ui/parser/issues/issue-3036.rs",
"ui/parser/issues/issue-31804.rs",
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/parser/impl-parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ impl ! {} // OK
impl ! where u8: Copy {} // OK

impl Trait Type {} //~ ERROR missing `for` in a trait impl
impl Trait .. {} //~ ERROR missing `for` in a trait impl
impl ?Sized for Type {} //~ ERROR expected a trait, found type
impl ?Sized for .. {} //~ ERROR expected a trait, found type

default unsafe FAIL //~ ERROR expected item, found keyword `unsafe`
//~^ ERROR `default` is not followed by an item
20 changes: 4 additions & 16 deletions tests/ui/parser/impl-parsing.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,27 @@ error: missing `for` in a trait impl
LL | impl Trait Type {}
| ^ help: add `for` here

error: missing `for` in a trait impl
--> $DIR/impl-parsing.rs:5:11
|
LL | impl Trait .. {}
| ^ help: add `for` here

error: expected a trait, found type
--> $DIR/impl-parsing.rs:6:6
--> $DIR/impl-parsing.rs:5:6
|
LL | impl ?Sized for Type {}
| ^^^^^^

error: expected a trait, found type
--> $DIR/impl-parsing.rs:7:6
|
LL | impl ?Sized for .. {}
| ^^^^^^

error: `default` is not followed by an item
--> $DIR/impl-parsing.rs:9:1
--> $DIR/impl-parsing.rs:7:1
|
LL | default unsafe FAIL
| ^^^^^^^ the `default` qualifier
|
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`

error: expected item, found keyword `unsafe`
--> $DIR/impl-parsing.rs:9:9
--> $DIR/impl-parsing.rs:7:9
|
LL | default unsafe FAIL
| ^^^^^^ expected item
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>

error: aborting due to 6 previous errors
error: aborting due to 4 previous errors

10 changes: 0 additions & 10 deletions tests/ui/parser/issues/issue-27255.rs

This file was deleted.

22 changes: 0 additions & 22 deletions tests/ui/parser/issues/issue-27255.stderr

This file was deleted.

9 changes: 0 additions & 9 deletions tests/ui/parser/obsolete-syntax-impl-for-dotdot.rs

This file was deleted.

10 changes: 0 additions & 10 deletions tests/ui/parser/obsolete-syntax-impl-for-dotdot.stderr

This file was deleted.

0 comments on commit 40f1be0

Please sign in to comment.