-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Incorrect non-exhaustive pattern error #72476
Comments
It passes on the playground with 1.43.1 and 1.44.0-beta.3 |
Seems to be a problem when pattern matching on projections. trait A {
type Projection;
}
impl A for () {
type Projection = bool;
// using () instead of bool here does compile though
}
struct Next<T: A>(T::Projection);
fn e(item: Next<()>) {
match item {
Next(true) => {}
Next(false) => {}
}
}
fn main() {} |
Related to changes from #71930, cc @Nadrieril. |
Ok, the problem comes from the fact that we get a pattern with type It's a regression because of e5a2cd5. This commit keeps revealing weird quirks with types... |
You can try adding a |
@matthewjasper This works! It feels patchy though: should I always call this before inspecting a type? Is it normal to find a non-normalized type at this stage of compilation? Do you know if there is a principled way I can be sure not to run into a similar bug later? |
Assigning |
I have an easy workaround, should I push that first and we can investigate further later? |
@Nadrieril I believe you should, the technical details can be discussed as part of code review I think, and if performance tests need to be done, then you'll need a PR anyway. |
Here: #72506 |
Normalize after substituting via `field.ty()` Back in rust-lang#72476 I hadn't understood where the problem was coming from, and only worked around the issue. What happens is that calling `field.ty()` on a field of a generic struct substitutes the appropriate generics but doesn't normalize the resulting type. As a consumer of types I'm surprised that one would substitute without normalizing, feels like a footgun, so I added a comment. Fixes rust-lang#89393.
This provides a child `raw` module that exposes a SymbolId representing the inner value of each of the static newtypes. This is needed in situations where the type must match and the type of the static symbol is not important. In particular, when comparing against runtime-allocated symbols in `match` expressions. It is also worth noting that this commit managed to hit a bug in Rustc that was fixed on 10/1/2021. We use nightly, and it doesn't seem that this occurred in stable, from bug reports. - rust-lang/rust#89393 - rust-lang/rust@5ab1245 - Original issue: rust-lang/rust#72476 The error was: compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs:1191:22: Unexpected type for `Single` constructor: <u32 as sym::symbol::SymbolIndexSize>::NonZero thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1146:9 This occurred because we were trying to use `SymbolId` as the type, which uses a projected type as its inner value: `SymbolId<Ix: SymbolIndexSize>(Ix::NonZero)`. This was not a problem with the static newtypes because their inner type was simply `SymbolId<Ix>`, which is not projected. This is one of the risks of using nightly. But, the point is: if you receive this error, upgrade your toolchain.
Produces non-exhaustive pattern error (even though all patterns are covered):
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: