Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove special handling of obsolete impl Trait for .. syntax #121072

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggests that we intend the following (historically wrongly gated 😭) to pass:

#[cfg(dont)]
impl Trait for .. {}

given that this should have emitted a future compat warning (from a quick test it doesn't seem to do that though????, I might be doing it wrong though)

but this is a breaking change (a probably justified one, but one)

maybe this should just use some dummy node in the meantime to not block this

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.

Loading