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 bb59453 commit 3a7d5f3
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 95 deletions.
27 changes: 2 additions & 25 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,31 +588,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

// FIXME(nnethercote): AST validation later detects this
// `TyKind::Err` and emits an errors. So why the unchecked
// ErrorGuaranteed?
// - A `span_delayed_bug` doesn't work here, because rustfmt can
// hit this path but then not hit the follow-up path in the AST
// validator that issues the error, which results in ICEs.
// - `TyKind::Dummy` doesn't work, because it ends up reaching HIR
// lowering, which results in ICEs. Changing `TyKind::Dummy` to
// `TyKind::Err` during AST validation might fix that, but that's
// not possible because AST validation doesn't allow mutability.
//
// #121072 will hopefully remove all this special handling of the
// obsolete `impl Trait for ..` and then this can go away.
#[allow(deprecated)]
let guar = rustc_errors::ErrorGuaranteed::unchecked_error_guaranteed();
Some(self.mk_ty(self.prev_token.span, TyKind::Err(guar)))
} 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 3a7d5f3

Please sign in to comment.