Skip to content

Conversation

lukas-code
Copy link
Member

When defining an enum with multiple #[default] variants, we emit a tool-only suggestion for every #[default]ed variant to remove all other #[default]s. This PR improves the suggestion to correctly handle the cases where one variant has multiple #[default]s and where different #[default]s have the same span due to macro expansions.

fixes #118119

@rustbot
Copy link
Collaborator

rustbot commented Nov 21, 2023

r? @wesleywiser

(rustbot has picked a reviewer for you, use r? to override)

@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 Nov 21, 2023
@rust-log-analyzer

This comment has been minimized.

@Noratrieb
Copy link
Member

What's a tool-only suggestion?^^

@lukas-code
Copy link
Member Author

What's a tool-only suggestion?^^

It's a suggestion that doesn't show up on the CLI, but you can auto-apply it with rust-analyzer (and JetBrains IDE probably (?)). In this case we get a bunch of "make X default" options and clicking on one will remove all of the other #[default]s.

https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/diagnostic/struct.Diagnostic.html#method.tool_only_span_suggestion

@wesleywiser
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 22, 2023

📌 Commit f697a00 has been approved by wesleywiser

It is now in the queue for this repository.

@bors bors 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 Nov 22, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2023
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#118131 (improve tool-only help for multiple `#[default]` variants)
 - rust-lang#118146 (Rework supertrait lint once again)
 - rust-lang#118167 (make the 'abi_unadjusted' feature internal)
 - rust-lang#118169 (print query map for deadlock when using parallel front end)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 82538b7 into rust-lang:master Nov 23, 2023
@rustbot rustbot added this to the 1.76.0 milestone Nov 23, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2023
Rollup merge of rust-lang#118131 - lukas-code:multi-default, r=wesleywiser

improve tool-only help for multiple `#[default]` variants

When defining an enum with multiple `#[default]` variants, we emit a tool-only suggestion for every `#[default]`ed variant to remove all other `#[default]`s. This PR improves the suggestion to correctly handle the cases where one variant has multiple `#[default]`s and where different `#[default]`s have the same span due to macro expansions.

fixes rust-lang#118119
@lukas-code lukas-code deleted the multi-default branch November 23, 2023 08:20
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.

rustc panic when using multiple #[default] tags
6 participants