基本的方法就是代码添加#[allow(dead_code)] 或 #![allow(dead_code)]。 #[allow(dead_code)]: 随时需要随时添加,添加到告警行代码的上方,只生效当前代码。若编写lib的时候,有些代码是为了导出给他人调用,可使用该方法 #![allow(dead_code, unused_imports)]: 一次添加,整体有效。添加到lib.rs或者main.rs...
如果要允许未使用的代码,在前面加上 #[allow(dead_code)] 即可。 参考文献: https://doc.rust-lang.org/rust-by-example/attribute/unused.html
#[allow(dead_code)]==>翻译是属性:允许未使用(死亡代码) 也就说,rust中没有使用的变量,rust称为dead_code。形式化理解先。我们继续。有时候,抑制好奇心是我们能够前进的动力。 fn main() { #[allow(dead_code)] #[derive(Debug)] struct User { name: String, age: u8, email: String, address: St...
#[allow(dead_code)] enumColor{ Red, Blue, Green, RGB(u32,u32,u32), HSV(u32,u32,u32), HSL(u32,u32,u32) } fnmain() { letcolor=Color::RGB(122,17,40); println!("what color is it ?"); matchcolor{ Color::Red=>println!("The color is Red!"), Color::RGB(a,b,c)=>...
rust note: `#[warn(dead_code)]` on by default,如果要允许未使用的代码,在前面加上#[allow(dead_code)]即可。参考文献:https://doc.rust-lang.org/rust-by-example/attribute/unused.html
("FREE: {:p}, size {}",ptr,layout.size());}}#[global_allocator]staticGLOBAL:MyAllocator=MyAllocator;#[allow(dead_code)]structMatrix{// 使用不规则的数字如 505 可以让 dbg! 的打印很容易分辨出来data:[u8;505],}implDefaultforMatrix{fndefault()->Self{Self{data:[0;505]}}}fnmain(){//...
use mongodb::{Client, options::ClientOptions, Database}; pub struct DataSource { client: Client, pub db_budshome: Database, } #[allow(dead_code)] impl DataSource { pub async fn client(&self) -> Client { self.client.clone() } pub async fn init() -> DataSource { // 解析 Mongo...
Q4:dss 为什么会 #allow(dead_code,unused)? A4:这是因为我们留了一些公开API交由学员实现时使用,测试本身不会直接用到,这就导致了 dead code 的误报。这些 allow 我们是要求学员在提交的作业的时候去掉的。有不少学员没有注意这点而被扣分了。
Derived code is intentionally ignored for dead code analysis - if you try just use std::str; #[derive(Debug)] enum ProcessError { Utf8(str::Utf8Error), Other, } You'll get a note explaining this. The note doesn't seem to be attached for never read warnings, just never used clubby...
fn complex_function(bytes: &Vec<u8>) {// … a lot of code …println!("{}", &Hex(bytes)); // That does not work.println!("{}", Hex(bytes.clone())); // That works but is slow.// … a lot of code …} 左右滑动查看完整代码 总之,newtype习语是一种漏洞百出的抽象,因为...