-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spurious unreachable_patterns with macro #80501
Comments
searched nightlies: from nightly-2020-12-09 to nightly-2020-12-29 bisected with cargo-bisect-rustc v0.6.0Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --preserve --start=2020-12-09 --end=2020-12-29 -- check |
cc @Nadrieril |
7090: Allow spurious warning from rust-lang/rust#80501 r=lnicola a=lnicola bors r+ Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
Assigning |
Slightly minimized: pub enum TypeCtor {
Slice,
Array,
}
pub struct ApplicationTy(TypeCtor);
macro_rules! ty_app {
($ctor:pat) => {
ApplicationTy($ctor)
};
}
fn _foo(ty: ApplicationTy) -> usize {
return match ty {
ty_app!(TypeCtor::Array) | ty_app!(TypeCtor::Slice) => 1,
};
// same as above, with the macro expanded
match ty {
crate::ApplicationTy(TypeCtor::Array)
| crate::ApplicationTy(TypeCtor::Slice) => {}
}
}
fn main() {} If you remove |
Oh boy, this is annoying. I had found a clever scheme in #80104 to deal with unreachable sub-patterns, but it relies on the assumption that the different alternatives in an or-pattern will have different spans. |
@Nadrieril I think if you call |
@jyn514 Sounds interesting! I'm not entirely sure it does what I want. What would macro_rules! foo {
() => {
(0 | 1)
};
}
fn main() {
match 0 {
foo!() -> {}
}
} |
Yup, that's right. My idea probably wouldn't work then, sorry. |
That gave me the idea for this cursed thing, where several different patterns really do have the same span. Unless I can distinguish a same span across different macro expansion paths, I don't think I can salvage my clever idea. |
@Nadrieril I did some experimentation, but wanted to confirm with you that we believe this one (unlike a previous similar sounding issue) is not a soundness bug, as we cannot actually remove the claimed-unreachable pattern in any case, right? |
@Mark-Simulacrum Agreed, this is not a soundness bug. The soundness-relevant code is independent of those |
Code
I tried this code:
I expected to see this happen: code should build fine
Instead, this happened:
unreachable pattern
in the first, but not on the second matchVersion it worked on
It most recently worked on:
Version with regression
@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged
The text was updated successfully, but these errors were encountered: