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の教科書。
- 作者: κeen,河野達也,小松礼人
- 出版社/メーカー: 技術評論社
- 発売日: 2019/05/08
- メディア: 単行本(ソフトカバー)
- この商品を含むブログを見る
exampleの実行 "cargo run --example"
cargo run --example "ch04_02_bool" で、直接実行できた。
PS > cargo run --example "ch04_02_bool" warning: file found to be present in multiple build targets: \examples\ch04_01_units.rs Compiling ex04 v0.1.0 (rust_project\rustbook\ch04\ex04) error: expected item, found keyword `let` --> examples\ch04_02_bool.rs:1:1 | 1 | let b1 = true; | ^^^ expected item error: aborting due to previous error error: could not compile `ex04`. To learn more, run the command again with --verbose.
> tree /f C:. │ .gitignore │ Cargo.lock │ Cargo.toml │ ├─examples │ ch04_01_units.rs │ ch04_02_bool.rs
error: a bin target must be available for `cargo run`
error: a bin target must be available for cargo run
[package] 略 [dependencies]
以下のように、binを”Cargo.toml"に追加した。
[package] 略 [dependencies] [[bin]] name = "main1" path = "examples/ch04_01_units.rs"