Skip to content

Quiz answer assumes successful compilation despite type mismatch in Rust snippet in IF LET Quiz in Control FLow #12

@rustserv-er

Description

@rustserv-er

I came across a quiz as Lesson 22 question involving the following Rust code:

rust
let config: Option = Some(42);
let mut processed_value = 0;
if let Some(val) = config {
processed_value = val * 2;
}
The quiz marked 84 as the correct answer, implying that the code compiles and executes successfully. However, this snippet causes a type mismatch error because processed_value is inferred as i32, while val * 2 yields a u32. Rust does not implicitly coerce between these types.

Unless the code is fixed by either:

Explicitly annotating processed_value as u32, or

Casting val to i32,

...the code will not compile, and processed_value remains undefined.

I believe the quiz should either:

Include the corrected version of the code, or

Clarify that the answer assumes successful compilation.

Would love to hear thoughts from others in the community. Is this worth flagging for correction?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions