Skip to content

Use the full path of bug_impl to avoid bogus errors in rust-analyzer - #163055

Open
Zalathar wants to merge 1 commit into
rust-lang:mainfrom
Zalathar:bug-impl
Open

Zalathar wants to merge 1 commit into
rust-lang:mainfrom
Zalathar:bug-impl

Conversation

@Zalathar

Copy link
Copy Markdown
Member

For whatever reason, rust-analyzer doesn't understand hygienic macros well enough to properly resolve this function call, which leads to bogus type errors appearing in rust-analyzer because it doesn't know that the function returns ! and therefore must diverge.

(For example, if bug!(..); with a trailing semicolon is used in the else block of a let-else statement, rust-analyzer will complain about it even though rustc is happy.)

If we specify the full path to the function, both rustc and rust-analyzer agree that it diverges.


I noticed this problem when rust-analyzer started flagging a lot more bogus warnings after #161873. Thankfully the workaround is very simple, so we don't really lose much by catering to rust-analyzer here.

There should be no change to compiler behaviour.

@Zalathar Zalathar added the A-contributor-roadblock Area: Makes things more difficult for new or seasoned contributors to Rust label Sep 20, 2026
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 20, 2026
@rustbot

rustbot commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

r? @mati865

rustbot has assigned @mati865.
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
  • compiler expanded to 77 candidates
  • Random selection from 17 candidates

@Zalathar

Copy link
Copy Markdown
Member Author

cc @mejrs for a surprising side-effect of #161873 😅

@Zalathar

Copy link
Copy Markdown
Member Author

I was originally going to do something like #153159 and delete a bunch of trailing semicolons throughout the compiler (since that also seems to work around the problem), but then I noticed that I could tweak the macros instead, which is a much smaller change.

@Zalathar

Copy link
Copy Markdown
Member Author

Ah, this would certainly explain things:

(found by @khyperia)

I guess we mostly get away with it because the compiler has very few macros-2 macros that don't override hygiene anyway, and for the remaining exceptions it usually doesn't end up causing problems.

For whatever reason, rust-analyzer doesn't understand hygienic macros well
enough to properly resolve this function call, which leads to bogus type errors
appearing in rust-analyzer because it doesn't know that the function returns
`!` and therefore must diverge.

(For example, if `bug!(..);` with a trailing semicolon is used in the else
block of a let-else statement, rust-analyzer will complain about it even though
rustc is happy.)

If we specify the full path to the function, both rustc and rust-analyzer agree
that it diverges.
@khyperia

Copy link
Copy Markdown
Member

aah nice thank you, I've been so annoyed by rust-analyzer here!

r=me when ci is green (sorry for asking you to change rustc_span:: to $crate:: and so needing to wait for ci again, haha. once again I wish for an automated "r=me when ci is green" command 😔)

@mati865 mati865 assigned khyperia and unassigned mati865 Sep 20, 2026
@Zalathar

Copy link
Copy Markdown
Member Author

PR CI is green.

@bors r=khyperia rollup

@rust-bors

rust-bors Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 07f15ab has been approved by khyperia

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 Sep 20, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 20, 2026
Use the full path of `bug_impl` to avoid bogus errors in rust-analyzer

For whatever reason, rust-analyzer doesn't understand hygienic macros well enough to properly resolve this function call, which leads to bogus type errors appearing in rust-analyzer because it doesn't know that the function returns `!` and therefore must diverge.

(For example, if `bug!(..);` with a trailing semicolon is used in the else block of a let-else statement, rust-analyzer will complain about it even though rustc is happy.)

If we specify the full path to the function, both rustc and rust-analyzer agree that it diverges.

---

I noticed this problem when rust-analyzer started flagging a lot more bogus warnings after rust-lang#161873. Thankfully the workaround is very simple, so we don't really lose much by catering to rust-analyzer here.

There should be no change to compiler behaviour.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 20, 2026
Use the full path of `bug_impl` to avoid bogus errors in rust-analyzer

For whatever reason, rust-analyzer doesn't understand hygienic macros well enough to properly resolve this function call, which leads to bogus type errors appearing in rust-analyzer because it doesn't know that the function returns `!` and therefore must diverge.

(For example, if `bug!(..);` with a trailing semicolon is used in the else block of a let-else statement, rust-analyzer will complain about it even though rustc is happy.)

If we specify the full path to the function, both rustc and rust-analyzer agree that it diverges.

---

I noticed this problem when rust-analyzer started flagging a lot more bogus warnings after rust-lang#161873. Thankfully the workaround is very simple, so we don't really lose much by catering to rust-analyzer here.

There should be no change to compiler behaviour.
rust-bors Bot pushed a commit that referenced this pull request Sep 20, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - #162726 (std: fix unix socket address panic on a full sun_path)
 - #163016 (Don't claim that escaping value is a reference in diagnostics)
 - #163040 (Tweak "use array's length as const param" suggestion)
 - #163060 (Point to fields that introduce trait requirements)
 - #163066 (don't mark `f128` as reliable on AIX)
 - #162098 (Tweak `Infallible` docs)
 - #162854 (Add safety section for atomic_load/store)
 - #163015 (add `minicore::ffi::VaList`)
 - #163021 (`va_arg`: pass in `TyAndLayout`)
 - #163036 ([rustdoc] Correctly handle `dyn` trait methods linking for jump to def feature)
 - #163042 (Remove redundant output from suggestion)
 - #163046 (Use verbose suggestion for `const _`)
 - #163050 (Use verbose suggestion for similarly named label suggestion)
 - #163052 (Use verbose suggestion for wrong primitive type names)
 - #163055 (Use the full path of `bug_impl` to avoid bogus errors in rust-analyzer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-contributor-roadblock Area: Makes things more difficult for new or seasoned contributors to Rust 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.

4 participants