Skip to content

Better error message when bare type in impl parameter list#157466

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
bb1yd:issue-147889
Jul 6, 2026
Merged

Better error message when bare type in impl parameter list#157466
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
bb1yd:issue-147889

Conversation

@bb1yd

@bb1yd bb1yd commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #147889

Marking this PR ready for feedback on this problem.

The approach I'm trying is to create a snapshot parser and attempt to re-parse the input in another way. If it succeeds, we successfully predicted the user's intention and emit the related help message. If it fails, we cancel the errors produced during the attempt and report the original error.

The problem is that parse functions may internally recover from parse failures and emit errors directly, which means we can't cancel them later. I saw that we have a recovery field to control the recovery mechanism, but it seems there are (maybe) a lot of places in the parser that don't check the recovery field before doing their recovery logic.

Should we always use look_ahead instead of using a snapshot parser and calling another parse function?

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 5, 2026
@bb1yd
bb1yd marked this pull request as ready for review June 8, 2026 12:54
@rustbot

rustbot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 8, 2026
@rustbot

rustbot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

r? @adwinwhite

rustbot has assigned @adwinwhite.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, parser
  • compiler, parser expanded to 73 candidates
  • Random selection from 20 candidates

@adwinwhite

Copy link
Copy Markdown
Contributor

Sorry for being so slow. I should have rerolled earlier. Thought I would have time to look into the recovery mechanism.

@rustbot reroll

@rustbot rustbot assigned davidtwco and unassigned adwinwhite Jun 23, 2026
Comment thread compiler/rustc_parse/src/parser/diagnostics.rs Outdated
Comment thread compiler/rustc_parse/src/parser/item.rs
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 2, 2026
@rustbot

rustbot commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot

This comment has been minimized.

@rustbot

rustbot commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@bb1yd
bb1yd requested a review from davidtwco July 3, 2026 09:05
@bb1yd

bb1yd commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 3, 2026
@davidtwco

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 81a3c75 has been approved by davidtwco

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 6, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 6, 2026
Better error message when bare type in impl parameter list

Fixes rust-lang#147889

Marking this PR ready for feedback on this problem.

The approach I'm trying is to create a snapshot parser and attempt to re-parse the input in another way. If it succeeds, we successfully predicted the user's intention and emit the related help message. If it fails, we cancel the errors produced during the attempt and report the original error.

The problem is that parse functions may internally recover from parse failures and emit errors directly, which means we can't cancel them later. I saw that we have a `recovery` field to control the recovery mechanism, but it seems there are (maybe) a lot of places in the parser that don't check the recovery field before doing their recovery logic.

Should we always use `look_ahead` instead of using a snapshot parser and calling another parse function?
rust-bors Bot pushed a commit that referenced this pull request Jul 6, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #156976 (enable eager `param_env` norm in new solver)
 - #158537 (Add `std::io::cursor::WriteThroughCursor`)
 - #158540 (Move `std::io::Seek` to `core::io`)
 - #157820 (consider subtyping when checking if an infer var is sized)
 - #158505 (Update POSIX edition links)
 - #158853 (Fix typo for link on nto-qnx.md)
 - #157466 (Better error message when bare type in impl parameter list)
 - #157966 (Emit a suggestion to cast the never type into a concrete type when it fails to satisfy an `impl Trait` bound)
 - #158381 (Expose debug scope of statement and terminator in rustc_public)
 - #158405 (rustc_target: Add ARMv8-M related target features)
 - #158770 (Weaken guarantee for `From<legacy::RangeInclusive> for RangeInclusive`)
 - #158820 (Fix rustdoc ICE on deprecated note in inlined re-export chain)
@rust-bors
rust-bors Bot merged commit baf02d2 into rust-lang:main Jul 6, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 6, 2026
rust-timer added a commit that referenced this pull request Jul 6, 2026
Rollup merge of #157466 - bb1yd:issue-147889, r=davidtwco

Better error message when bare type in impl parameter list

Fixes #147889

Marking this PR ready for feedback on this problem.

The approach I'm trying is to create a snapshot parser and attempt to re-parse the input in another way. If it succeeds, we successfully predicted the user's intention and emit the related help message. If it fails, we cancel the errors produced during the attempt and report the original error.

The problem is that parse functions may internally recover from parse failures and emit errors directly, which means we can't cancel them later. I saw that we have a `recovery` field to control the recovery mechanism, but it seems there are (maybe) a lot of places in the parser that don't check the recovery field before doing their recovery logic.

Should we always use `look_ahead` instead of using a snapshot parser and calling another parse function?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bare type in impl parameter list causes non-intuitive parse error

4 participants