8000 Tweak pedantic with desugaring; add f_mut_bad example · sarvex/rust-memory-model@2d740e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d740e5

Browse files
committed
Tweak pedantic with desugaring; add f_mut_bad example
1 parent f70f2fe commit 2d740e5

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

litmus_tests/f_mut_bad.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### Example
2+
3+
```rust
4+
fn f_mut_bad<'s>(&'s mut self) -> &'s mut Self {
5+
let ret = unsafe { transmute::<&'s Self, &'s mut Self>(self.f()) };
6+
ret // β-expansion should have no effect
7+
}
8+
```
9+
10+
### Explanation
11+
12+
In this variation on the lovely and delightful `f_mut` series, the
13+
`self.f()` point has a lifetime of `'s`, and thus the scope of the
14+
shared borrow extends past the unsafe block.
15+
16+
### Source
17+
18+
- https://github.com/rust-lang/rust/issues/30424#issuecomment-168541165

litmus_tests/f_mut_pedantic.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
```rust
44
fn f_mut_pedantic<'s>(&'s mut self) -> &'s mut Self {
55
let captured_self = self as *mut Self;
6-
unsafe { &mut *((*captured_self).f() as *const Self as *mut Self) }
6+
unsafe { &mut *((&*captured_self).f() as *const Self as *mut Self) }
77
}
88
```
99

@@ -17,4 +17,5 @@ again.
1717

1818
### Source
1919

20-
https://github.com/rust-lang/rust/issues/30424#issuecomment-167009462
20+
- https://github.com/rust-lang/rust/issues/30424#issuecomment-167009462
21+
- https://github.com/rust-lang/rust/issues/30424#issuecomment-168539718

0 commit comments

Comments
 (0)
0