在这里生锈新手。当提供参数并将其在函数声明中保持未使用状态时(例如,在学习Rust ...时),编译器会警告变量在范围内未使用的事实,并建议考虑在其下划线。这样做,警告消失。
warning: unused variable: `y`
--> src/main.rs:23:29
|
23 | fn another_function(x: i32, y: i32) {
| ^ help: consider using `_y` instead
|
= note: #[warn(unused_variables)] on by default
Run Code Online (Sandbox Code Playgroud)
为什么?变量如何区别对待?