Master Rust track References feedback

Hi,
Out of interest going through this track, noticed some issues with the References section. While compilation error would be returned here

let s = String::from("hello");
let r1 = &s;
let r2 = &s;
// let r3 = &mut s; // This would be an error!

It would be a Cannot borrow immutable local variable s as mutable, not the referencing error. To get the actual reference compile error the code would have to be altered as

let mut s = String::from("hello");
let r1 = &s;
let r2 = &mut s;
println!("{:?}", r1);

Same applies to the previous example

let mut s = String::from("hello");
let r1 = &mut s;  
// let r2 = &mut s;

It’d actually compile just ok, but if changed to

let mut s = String::from("hello");
let r1 = &mut s;
let r2 = &mut s;
*r1 = String::from("world");

then it’d be a compile error

Hey @AndrewNikolin, thanks for highlighting the issue!

I’ll take a closer look and keep you updated when it’s fixed.

We’ve fixed the issues in Rust: References. Thanks again for highlighting them! @AndrewNikolin

1 Like

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