Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rust 为什么测试失败,并显示消息“测试失败”;对盒子感到恐慌<;任何>&引用;?_Rust_Panic - Fatal编程技术网

Rust 为什么测试失败,并显示消息“测试失败”;对盒子感到恐慌<;任何>&引用;?

Rust 为什么测试失败,并显示消息“测试失败”;对盒子感到恐慌<;任何>&引用;?,rust,panic,Rust,Panic,为什么会这样恐慌 pub fn testbool() -> bool { vec!['a', 'd', 'i', 'e', 'p', 'r'] .iter() .enumerate() .find(|(_i, &c)| c != 'c') .is_none() } #[test] fn test_testbool() { assert!(testbool(), true); } ----test\

为什么会这样恐慌

pub fn testbool() -> bool {
    vec!['a', 'd', 'i', 'e', 'p', 'r']
        .iter()
        .enumerate()
        .find(|(_i, &c)| c != 'c')
        .is_none()
}

#[test]
fn test_testbool() {
    assert!(testbool(), true);
}

----test\u testbool标准输出----
线程“test\u testbool”在“Box”处惊慌失措,src/lib.rs:11:5
注意:使用'RUST_BACKTRACE=1'环境变量运行以显示回溯。
它可能很简单,但我不明白。

您正在使用。这要求第一个参数是布尔表达式。任何后续参数都被视为格式字符串,并且其参数为:

assert!(testbool(), "Did not work: {}", 42);
线程“test\u testbool”恐慌于“未工作:42”
您可能希望删除
assert的第二个参数或切换到


我相信根问题来自于允许非格式字符串在某些情况下用作格式字符串的