You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0000-maybe-dangling.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Sometimes one has to work with references or boxes that either are already deall
19
19
This comes up particularly often with `ManuallyDrop`.
20
20
For example, the following code is UB at the time of writing this RFC:
21
21
22
-
```rust=
22
+
```rust
23
23
fnid<T>(x:T) ->T { x }
24
24
25
25
fnunsound(x:Box<i32>)
@@ -40,7 +40,7 @@ There exist more complex versions of this problem, relating to a subtle aspect o
40
40
when a reference is passed to a function as an argument (including nested in a struct), then that reference must remain live throughout the function.
41
41
(In LLVM terms: we are annotating that reference with `dereferenceable`, which means "dereferenceable for the entire duration of this function call"). In [issue #101983](https://github.com/rust-lang/rust/issues/101983), this leads to a bug in `scoped_thread`.
42
42
There we have a function that invokes a user-supplied `impl FnOnce` closure, roughly like this:
43
-
```rust=
43
+
```rust
44
44
// Not showing all the `'lifetime` tracking, the point is that
@@ -64,7 +64,7 @@ However, note that `thread` continues to run even after `signal_done`! Now consi
64
64
65
65
As a third example, consider a type that wants to store a "pointer together with some data borrowed from that pointer", like the `owning_ref` crate. This will usually boil down to something like this:
66
66
67
-
```rust=
67
+
```rust
68
68
unsafetraitStableDeref:Deref {}
69
69
70
70
structOwningRef<U, T:StableDeref<Target=U>> {
@@ -98,7 +98,7 @@ This means that the first example is actually fine:
98
98
the dangling `Box` was passed inside a `ManuallyDrop`, so there is no UB.
99
99
100
100
The 2nd example can be fixed by passing the closure in a `MaybeDangling`:
101
-
```rust=
101
+
```rust
102
102
// Argument is passed as `MaybeDangling` since we might actually keep
103
103
// it around after its lifetime ends (at which point the caller can
0 commit comments