File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed
src/safe-guides/coding_practice/fn-design Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ impl Point {
39
39
pub fn raw (& self ) -> * const RawPoint {
40
40
& self . raw
41
41
}
42
- // 如果听信 lint 的建议,将上面的 raw 函数参数 self 的引用去掉就是 raw_linted 函数
42
+ // 如果听信 lint 的建议,将上面的 raw 函数参数 self 的引用去掉就是 raw_linted 函数, 这在没有编译优化的情况下(如只是 cargo build 运行在debug模式下)的时候不会出错,但在有编译优化的场景下(如 cargo build --release 运行在release模式)就会出现以下问题。
43
43
pub fn raw_linted (self ) -> * const RawPoint {
44
44
& self . raw
45
45
}
@@ -50,7 +50,8 @@ fn main() {
50
50
51
51
// This passes
52
52
assert_eq! (p . raw (), p . raw ());
53
- // This fails 事实上,如果去掉那个 self 的引用,该函数的行为就变了
53
+ // This fails
54
+ // 事实上,如果去掉那个 self 的引用,该函数的行为就变了
54
55
// 因为 结构体 Point 是 Copy 的,每次调用 raw_linted 方法,结构体实例就会被复制一次,得到的结果就不一样了
55
56
assert_eq! (p . raw_linted (), p . raw_linted ());
56
57
}
You can’t perform that action at this time.
0 commit comments