Skip to content

Conversation

Nadrieril
Copy link
Member

@Nadrieril Nadrieril commented Jul 19, 2025

This adds an option to the rustc_pattern_analysis machinery to have it report a complete set of patterns when a match is non-exhaustive (by default we only guarantee to report some missing patterns). This is for use in rust-analyzer.

Leaving as draft until I'm sure this is what r-a needs.

r? ghost

@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 Jul 19, 2025
@rust-log-analyzer

This comment has been minimized.

@Nadrieril Nadrieril force-pushed the exhaustive-witnesses branch from b30d696 to 180b931 Compare July 19, 2025 15:09
Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

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

This needs a change in one more place:

let report_individual_missing_ctors = self.is_scrutinee || !all_missing;
if !missing_ctors.is_empty() && !report_individual_missing_ctors {
// Report `_` as missing.
missing_ctors = vec![Constructor::Wildcard];
} else if missing_ctors.iter().any(|c| c.is_non_exhaustive()) {
// We need to report a `_` anyway, so listing other constructors would be redundant.
// `NonExhaustive` is displayed as `_` just like `Wildcard`, but it will be picked
// up by diagnostics to add a note about why `_` is required here.
missing_ctors = vec![Constructor::NonExhaustive];
}

should be:

        let report_individual_missing_ctors =
            cx.exhaustive_witnesses() || self.is_scrutinee || !all_missing;
        if !missing_ctors.is_empty() && !report_individual_missing_ctors {
            // Report `_` as missing.
            missing_ctors = vec![Constructor::Wildcard];
        } else if !cx.exhaustive_witnesses() && missing_ctors.iter().any(|c| c.is_non_exhaustive())
        {
            // We need to report a `_` anyway, so listing other constructors would be redundant.
            // `NonExhaustive` is displayed as `_` just like `Wildcard`, but it will be picked
            // up by diagnostics to add a note about why `_` is required here.
            missing_ctors = vec![Constructor::NonExhaustive];
        }

@Nadrieril
Copy link
Member Author

Nadrieril commented Jul 19, 2025

I chose not to do that on purpose because that added too many witnesses. EDIT: you're right about the non_exhaustive case actually

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 20, 2025
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 20, 2025
@Nadrieril Nadrieril marked this pull request as ready for review July 20, 2025 16:27
@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 20, 2025
@rustbot

This comment has been minimized.

@Nadrieril Nadrieril force-pushed the exhaustive-witnesses branch from 3ca51e0 to af07c08 Compare July 20, 2025 16:28
@Nadrieril
Copy link
Member Author

r? compiler

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

Assuming this satisfies r-a's needs, r=me

@Nadrieril
Copy link
Member Author

I believe it does!

@bors r=davidtwco

@bors
Copy link
Collaborator

bors commented Jul 25, 2025

📌 Commit af07c08 has been approved by davidtwco

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 Jul 25, 2025
bors added a commit that referenced this pull request Jul 26, 2025
Rollup of 9 pull requests

Successful merges:

 - #144089 (Rehome 35 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`)
 - #144171 (pattern_analysis: add option to get a full set of witnesses)
 - #144201 (Mention type that could be `Clone` but isn't in more cases)
 - #144316 (bootstrap: Move musl-root fallback out of sanity check)
 - #144339 (Enable dwarf-mixed-versions-lto.rs test on RISC-V (riscv64))
 - #144341 (Enable const-vector.rs test on RISC-V (riscv64))
 - #144352 (RustWrapper: Suppress getNextNonDebugInfoInstruction)
 - #144356 (Add `ignore-backends` annotations in failing GCC backend ui tests)
 - #144364 (Update `dlmalloc` dependency of libstd)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3f7d497 into rust-lang:master Jul 26, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 26, 2025
rust-timer added a commit that referenced this pull request Jul 26, 2025
Rollup merge of #144171 - Nadrieril:exhaustive-witnesses, r=davidtwco

pattern_analysis: add option to get a full set of witnesses

This adds an option to the rustc_pattern_analysis machinery to have it report a complete set of patterns when a match is non-exhaustive (by default we only guarantee to report _some_ missing patterns). This is for use in rust-analyzer.

Leaving as draft until I'm sure this is what r-a needs.

r? ghost
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.

7 participants