Skip to content

Commit 66c0183

Browse files
committed
Remove special handling for impl Trait for .. syntax errors.
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.
1 parent a84bb95 commit 66c0183

File tree

7 files changed

+6
-78
lines changed

7 files changed

+6
-78
lines changed

compiler/rustc_parse/src/parser/item.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -588,15 +588,8 @@ impl<'a> Parser<'a> {
588588
let has_for = self.eat_keyword(kw::For);
589589
let missing_for_span = self.prev_token.span.between(self.token.span);
590590

591-
let ty_second = if self.token == token::DotDot {
592-
// We need to report this error after `cfg` expansion for compatibility reasons
593-
self.bump(); // `..`, do not add it to expected tokens
594-
Some(self.mk_ty(self.prev_token.span, TyKind::Err))
595-
} else if has_for || self.token.can_begin_type() {
596-
Some(self.parse_ty()?)
597-
} else {
598-
None
599-
};
591+
let ty_second =
592+
if has_for || self.token.can_begin_type() { Some(self.parse_ty()?) } else { None };
600593

601594
generics.where_clause = self.parse_where_clause()?;
602595

tests/ui/parser/impl-parsing.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ impl ! {} // OK
22
impl ! where u8: Copy {} // OK
33

44
impl Trait Type {} //~ ERROR missing `for` in a trait impl
5-
impl Trait .. {} //~ ERROR missing `for` in a trait impl
65
impl ?Sized for Type {} //~ ERROR expected a trait, found type
7-
impl ?Sized for .. {} //~ ERROR expected a trait, found type
86

97
default unsafe FAIL //~ ERROR expected item, found keyword `unsafe`
108
//~^ ERROR `default` is not followed by an item

tests/ui/parser/impl-parsing.stderr

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,27 @@ error: missing `for` in a trait impl
44
LL | impl Trait Type {}
55
| ^ help: add `for` here
66

7-
error: missing `for` in a trait impl
8-
--> $DIR/impl-parsing.rs:5:11
9-
|
10-
LL | impl Trait .. {}
11-
| ^ help: add `for` here
12-
137
error: expected a trait, found type
14-
--> $DIR/impl-parsing.rs:6:6
8+
--> $DIR/impl-parsing.rs:5:6
159
|
1610
LL | impl ?Sized for Type {}
1711
| ^^^^^^
1812

19-
error: expected a trait, found type
20-
--> $DIR/impl-parsing.rs:7:6
21-
|
22-
LL | impl ?Sized for .. {}
23-
| ^^^^^^
24-
2513
error: `default` is not followed by an item
26-
--> $DIR/impl-parsing.rs:9:1
14+
--> $DIR/impl-parsing.rs:7:1
2715
|
2816
LL | default unsafe FAIL
2917
| ^^^^^^^ the `default` qualifier
3018
|
3119
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
3220

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

41-
error: aborting due to 6 previous errors
29+
error: aborting due to 4 previous errors
4230

tests/ui/parser/issues/issue-27255.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/ui/parser/issues/issue-27255.stderr

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/ui/parser/obsolete-syntax-impl-for-dotdot.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/ui/parser/obsolete-syntax-impl-for-dotdot.stderr

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)