[Rust 奇技] 使用下划线开头解决 warning: unused variable: `c`

yufei       3 年, 1 月 前       1463

Rust 语言中,时不时的给给我们一个 warn,尤其是有些变量定义了但短暂用不到的时候,比如

fn main() {
    let x = 5;
}

编译运行的时候就会提示

warning: unused variable: `x`
  --> main.rs:18:6
   |
18 |     let x = 5;
   |         ^ help: if this is intentional, prefix it with an underscore: `_x`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

按照提示的内容,我们只要在变量之前放一个 下划线 即可

fn main() {
    let _x = 5;
}

这样就没提示了!

目前尚无回复
简单教程 = 简单教程,简单编程
简单教程 是一个关于技术和学习的地方
现在注册
已注册用户请 登入
关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.