Open
Description
From https://users.rust-lang.org/t/how-to-match-t-and-t-in-the-same-arm/83835
Given the following code: playground
enum Foo<'a, T> {
A,
B(T),
C(&'a T),
}
fn main() {
let foo = Foo::<'static, ()>::A;
match foo {
Foo::A => {},
Foo::B(ref t) | Foo::C(t) => todo!(),
}
}
The current output is:
error[E0409]: variable `t` is bound inconsistently across alternatives separated by `|`
--> src/main.rs:12:32
|
12 | Foo::B(ref t) | Foo::C(t) => todo!(),
| - ^ bound in different ways
| |
| first binding
The cause of the error is a lifetime difference, where B(ref t)
binds &'_ T
(for some local lifetime) and C(t)
binds &'static T
. It would be nice to have a hint about this, possibly suggesting a fix into C(&ref t)
to reborrow that reference.
(Even better if the language/compiler could make that happen automatically!)
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsRelating to patterns and pattern matchingDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: An error or lint that needs small tweaks.`#![feature(or_patterns)]`Relevant to the compiler team, which will review and decide on the PR/issue.