-
-
Notifications
You must be signed in to change notification settings - Fork 67
Closed
Description
In question 7, the original code looks like this:
#[repr(u8)]
enum Enum {
First,
Second,
}
impl Enum {
fn p(self) {
match self {
First => print!("1"),
Second => print!("2"),
}
}
}
fn main() {
Enum::p(unsafe {
std::mem::transmute(1u8)
});
}We get compilation errors on lines
First => print!("1"),
Second => print!("2"),error[E0170]: pattern binding `First` is named the same as one of the variants of the type `Enum`
--> src/main.rs:10:13
|
10 | First => print!("1"),
| ^^^^^ help: to match on the variant, qualify the path: `Enum::First`
|
= note: `#[deny(bindings_with_variant_name)]` on by default
error[E0170]: pattern binding `Second` is named the same as one of the variants of the type `Enum`
--> src/main.rs:11:13
|
11 | Second => print!("2"),
| ^^^^^^ help: to match on the variant, qualify the path: `Enum::Second`
after fixing them by adding Enum::
Enum::First => print!("1"),
Enum::Second => print!("2"),the output is "2".
The answer matches the description, we get "1" for 0u8 and "2" for 1u8. It does not, however, match the "any" part nor the official answer stating the program would print "1".
Below, there are two possible ways for fixing the issue.
Either Enum:: should be added to the code and the answer changed to "2" or the answer should be changed to "The program does not compile".
Metadata
Metadata
Assignees
Labels
No labels