sunface / rust-by-practice

Learning Rust By Practice, narrowing the gap between beginner and skilled-dev through challenging examples, exercises and projects.

Home Page:https://practice.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem set Variables, Shadowing Problem 6. Incorrect Solution.

delta549 opened this issue · comments

Problem set Variables, Shadowing Problem 6. States:

// Remove a line in the code to make it compile
fn main() {
    let mut x: i32 = 1;
    x = 7;
    // Shadowing and re-binding
    let x = x; 
    x += 3;


    let y = 4;
    // Shadowing
    let y = "I can also be bound to text!"; 

    println!("Success!");
}

However the Solution in the rust-by-practice book states:
6.

fn main() {
    let mut x: i32 = 1;
    x = 7;
    // Shadowing and re-binding
    let mut x = x; 
    x += 3;


    let y = 4;
    // Shadowing
    let y = "I can also be bound to text!"; 

    println!("Success!");
}

I feel this is incorrect as making the variable mutable is not the question:
let mut x = x;

The real solution should be the removal of the:
x+=3;

as the questions asks:
// Remove a line in the code to make it compile

Thankyou for the Merge! 😄