1
Fork 0

Add check for missing fields in enum variant pattern

This commit is contained in:
Esteban Küber 2025-01-08 00:10:16 +00:00
parent 5f04f98c9a
commit d44f021904
3 changed files with 21 additions and 4 deletions

View file

@ -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
}
}