Skip to content

Commit 40f1be0

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 f8131a4 commit 40f1be0

File tree

9 files changed

+6
-88
lines changed

9 files changed

+6
-88
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

-5
Original file line numberDiff line numberDiff line change
@@ -881,11 +881,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
881881
&item.vis,
882882
errors::VisibilityNotPermittedNote::TraitImpl,
883883
);
884-
if let TyKind::Dummy = self_ty.kind {
885-
// Abort immediately otherwise the `TyKind::Dummy` will reach HIR lowering,
886-
// which isn't allowed. Not a problem for this obscure, obsolete syntax.
887-
this.dcx().emit_fatal(errors::ObsoleteAuto { span: item.span });
888-
}
889884
if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity)
890885
{
891886
this.dcx().emit_err(errors::UnsafeNegativeImpl {

compiler/rustc_parse/src/parser/item.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -597,19 +597,8 @@ impl<'a> Parser<'a> {
597597
let has_for = self.eat_keyword(kw::For);
598598
let missing_for_span = self.prev_token.span.between(self.token.span);
599599

600-
let ty_second = if self.token == token::DotDot {
601-
// We need to report this error after `cfg` expansion for compatibility reasons
602-
self.bump(); // `..`, do not add it to expected tokens
603-
604-
// AST validation later detects this `TyKind::Dummy` and emits an
605-
// error. (#121072 will hopefully remove all this special handling
606-
// of the obsolete `impl Trait for ..` and then this can go away.)
607-
Some(self.mk_ty(self.prev_token.span, TyKind::Dummy))
608-
} else if has_for || self.token.can_begin_type() {
609-
Some(self.parse_ty()?)
610-
} else {
611-
None
612-
};
600+
let ty_second =
601+
if has_for || self.token.can_begin_type() { Some(self.parse_ty()?) } else { None };
613602

614603
generics.where_clause = self.parse_where_clause()?;
615604

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)