Value assigned to 'var' is never read

Hello, I am the one of newbie of student from Korea.
Before asking, I'm not good at English well :wink:

    let mut s1 = String::new();
    s1 = String::from("Hello");

    s1.push_str(", World!");

    println!("{}", s1);

In this code( or like this ), why the compiler warn "value assigned to 's1' is never read." ?

It can be compiled but i just wonder this caused by ownership or variable syntax.

1 Like

You are assigning String::new() to s1.
Then you are assigning String::from("Hello") to s1

That means your original new empty string is never being read.

1 Like

I see and solve, thank you!

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.