I was looking at the Rust reference book and it states that a tuple struct is "refutable when one of its subpatterns is refutable". It also states that identifier patterns are irrefutable when "the subpattern is not specified".
Given this, if I create a tuple struct pattern with a single irrefutable identifier subpattern, I would expect the tuple struct pattern to be irrefutable as well because its subpatterns are all irrefutable.
pub fn main() {
enum Foo {
Bar(i32),
Baz(i32),
}
// Compiler says Foo::Bar(x) is a refutable pattern
// but the reference book suggests it is irrefutable
let Foo::Bar(x) = Foo::Bar(50);
}
The AST of the code above confirms that the Foo::Bar(x) is a tuple struct pattern and the x is an identifier pattern. I feel that the compiler is correct here, but the reference book suggests the Foo::Bar(x) is irrefutable despite the compiler.
I understand the need for blocking refutable patterns given the multiple possible enum variants and how an if let or similar would help here but am confused by the contradicting quotes.
Is something going on here that I am missing, or is this an issue with the reference book?