rus*_*yhu 6 pointers reference rust
我以前觉得这和C++中的lvalue reference collapsing很像,所以从语法上&&T应该和,一样&T,但是我编译了下面的代码后就糊涂了:
fn check_ref(x: &i32) -> i32 {
println!("{}", x);
x + 2
}
fn main() {
for i in &[-3, 2, 39] {
// i is &i32
check_ref(i); // this works
check_ref(&i); // this works
check_ref(&&i); // this works
assert_eq!(i, &i); // error[E0277]: can't compare `i32` with `&i32`
}
}
Run Code Online (Sandbox Code Playgroud)
多个引用是否会崩溃,或者 ref-to-ref 是否有其他特定含义?
这个编译器错误assert_eq!仅仅是因为 Rust 宏中的一些技巧吗?
| 归档时间: |
|
| 查看次数: |
1321 次 |
| 最近记录: |