のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

rustのワーニング help: consider prefixing with an underscore:

fn main() {
    let n1 = 10_000;
    let n2 = 0u8;
    let n3 = -100_isize;

    let n4 = 10;
    let n5 = n3 + n4;
}

help: consider prefixing with an underscore: _n1 のワーニングがでる。

PS > cargo run --example "ch04_03_integer"    
warning: file found to be present in multiple build targets: 
\rustbook\ch04\ex04\examples\ch04_01_units.rs
   Compiling ex04 v0.1.0 (rustbook\ch04\ex04)
warning: unused variable: `n1`
 --> examples\ch04_03_integer.rs:2:9
  |
2 |     let n1 = 10_000;
  |         ^^ help: consider prefixing with an underscore: `_n1`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `n2`
 --> examples\ch04_03_integer.rs:3:9
  |
3 |     let n2 = 0u8;
  |         ^^ help: consider prefixing with an underscore: `_n2`

warning: unused variable: `n5`
 --> examples\ch04_03_integer.rs:7:9
  |
7 |     let n5 = n3 + n4;
  |         ^^ help: consider prefixing with an underscore: `_n5`

    Finished dev [unoptimized + debuginfo] target(s) in 1.15s
     Running `target\debug\examples\ch04_03_integer.exe`

アンダーバーを変数の前につけると、ワーニングは消えた。

fn main() {
    let _n1 = 10_000;
    let _n2 = 0u8;
    let _n3 = -100_isize;

    let _n4 = 10;
    let _n5 = _n3 + _n4;
}

使用している、rustの教科書。

実践Rust入門[言語仕様から開発手法まで]

実践Rust入門[言語仕様から開発手法まで]