Add check for missing fields in enum variant pattern
This commit is contained in:
parent
5f04f98c9a
commit
d44f021904
3 changed files with 21 additions and 4 deletions
|
@ -3,6 +3,10 @@ struct Website {
|
|||
title: Option<String>,
|
||||
}
|
||||
|
||||
enum Foo {
|
||||
Bar { a: i32 },
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let website = Website {
|
||||
url: "http://www.example.com".into(),
|
||||
|
@ -18,4 +22,9 @@ fn main() {
|
|||
println!("[{}]({})", title, url); //~ ERROR cannot find value `title` in this scope
|
||||
//~^ NOTE not found in this scope
|
||||
}
|
||||
|
||||
let x = Foo::Bar { a: 1 };
|
||||
if let Foo::Bar { .. } = x { //~ NOTE this pattern
|
||||
println!("{a}"); //~ ERROR cannot find value `a` in this scope
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue