Rust really loves underscores😀

fn main() {
    let tup = (500, 6.4, 1);
    let (_x, _y, _z) = tup;

    println!("The value of y is: {}", _y);  
}

if (_x, _y, _z) changes to (x, y, z),the compiler would say:

warning: unused variable: `y`
 --> src\main.rs:3:13
  |
3 |     let (x, y, z) = tup;
  |             ^ help: if this is intentional, prefix it with an underscore: `_y`
1 Like

It would point out you didn't use x and z, but you did use y so it wouldn't point that one out.

It's letting you know you probably have a logical error in your code (though you may see such warnings a lot while checking or compiling partially completed functions or the like). You can add underscores to silence the errors... but you could also make use of the variables, or remove them entirely if you don't need them.

1 Like

thx~

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.