Skip to content

Commit 3a7d5f3

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 bb59453 commit 3a7d5f3

File tree

8 files changed

+6
-95
lines changed

8 files changed

+6
-95
lines changed

compiler/rustc_parse/src/parser/item.rs

+2-25
Original file line numberDiff line numberDiff line change
@@ -588,31 +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-
595-
// FIXME(nnethercote): AST validation later detects this
596-
// `TyKind::Err` and emits an errors. So why the unchecked
597-
// ErrorGuaranteed?
598-
// - A `span_delayed_bug` doesn't work here, because rustfmt can
599-
// hit this path but then not hit the follow-up path in the AST
600-
// validator that issues the error, which results in ICEs.
601-
// - `TyKind::Dummy` doesn't work, because it ends up reaching HIR
602-
// lowering, which results in ICEs. Changing `TyKind::Dummy` to
603-
// `TyKind::Err` during AST validation might fix that, but that's
604-
// not possible because AST validation doesn't allow mutability.
605-
//
606-
// #121072 will hopefully remove all this special handling of the
607-
// obsolete `impl Trait for ..` and then this can go away.
608-
#[allow(deprecated)]
609-
let guar = rustc_errors::ErrorGuaranteed::unchecked_error_guaranteed();
610-
Some(self.mk_ty(self.prev_token.span, TyKind::Err(guar)))
611-
} else if has_for || self.token.can_begin_type() {
612-
Some(self.parse_ty()?)
613-
} else {
614-
None
615-
};
591+
let ty_second =
592+
if has_for || self.token.can_begin_type() { Some(self.parse_ty()?) } else { None };
616593

617594
generics.where_clause = self.parse_where_clause()?;
618595

src/tools/tidy/src/issues.txt

-1
Original file line numberDiff line numberDiff line change
@@ -3325,7 +3325,6 @@
33253325
"ui/parser/issues/issue-24197.rs",
33263326
"ui/parser/issues/issue-24375.rs",
33273327
"ui/parser/issues/issue-24780.rs",
3328-
"ui/parser/issues/issue-27255.rs",
33293328
"ui/parser/issues/issue-30318.rs",
33303329
"ui/parser/issues/issue-3036.rs",
33313330
"ui/parser/issues/issue-31804.rs",

tests/ui/parser/impl-parsing.rs

-2
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

+4-16
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

-10
This file was deleted.

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

-22
This file was deleted.

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

-9
This file was deleted.

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

-10
This file was deleted.

0 commit comments

Comments
 (0)