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 {
3939 pub fn raw (& self ) -> * const RawPoint {
4040 & self . raw
4141 }
42- // 如果听信 lint 的建议,将上面的 raw 函数参数 self 的引用去掉就是 raw_linted 函数
42+ // 如果听信 lint 的建议,将上面的 raw 函数参数 self 的引用去掉就是 raw_linted 函数, 这在没有编译优化的情况下(如只是 cargo build 运行在debug模式下)的时候不会出错,但在有编译优化的场景下(如 cargo build --release 运行在release模式)就会出现以下问题。
4343 pub fn raw_linted (self ) -> * const RawPoint {
4444 & self . raw
4545 }
@@ -50,7 +50,8 @@ fn main() {
5050
5151 // This passes
5252 assert_eq! (p . raw (), p . raw ());
53- // This fails 事实上,如果去掉那个 self 的引用,该函数的行为就变了
53+ // This fails
54+ // 事实上,如果去掉那个 self 的引用,该函数的行为就变了
5455 // 因为 结构体 Point 是 Copy 的,每次调用 raw_linted 方法,结构体实例就会被复制一次,得到的结果就不一样了
5556 assert_eq! (p . raw_linted (), p . raw_linted ());
5657}
You can’t perform that action at this time.
0 commit comments