-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Single-variant exception for match consequences for #[non_exhaustive] #147722
Copy link
Copy link
Open
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-exhaustiveness-checkingRelating to exhaustiveness / usefulness checking of patternsRelating to exhaustiveness / usefulness checking of patternsA-miriArea: The miri toolArea: The miri toolA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamT-opsemRelevant to the opsem teamRelevant to the opsem team
Metadata
Metadata
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-exhaustiveness-checkingRelating to exhaustiveness / usefulness checking of patternsRelating to exhaustiveness / usefulness checking of patternsA-miriArea: The miri toolArea: The miri toolA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamT-opsemRelevant to the opsem teamRelevant to the opsem team
Type
Fields
Give feedbackNo fields configured for issues without a type.
bar/src/lib.rs:
src/main.rs:
Running the above code in Miri detects UB as follows:
However, if I delete the
#[non_exhaustive]line, Miri does not detect any UB.This seems incorrect. I believe that
#[non_exhaustive]is supposed to only affect whether code compiles. It should not affect how code behaves.It seems that, without
#[non_exhaustive], rust does not even read the discriminant. But with#[non_exhaustive], rust does.Related to:
matchon uninhabited type does not trigger UB in Miri #142394non_exhaustivecan potentially be a breaking change cargo#16417Meta
rustc --version --verbose:cargo miri --version: