File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -1237,5 +1237,16 @@ pub macro pin($value:expr $(,)?) {
1237
1237
//
1238
1238
// See https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension
1239
1239
// for more info.
1240
- Pin { pointer : & mut { $value } }
1240
+ //
1241
+ // # Avoiding coercion
1242
+ //
1243
+ // We need to explicitly constrain the pointer type to avoid (unsound) coercion. Otherwise, you
1244
+ // could write code like
1245
+ // ```rust
1246
+ // let rc = Rc::new(PhantomPinned);
1247
+ // let _pinned: Pin<&PhantomPinned> = pin!(rc.clone());
1248
+ // let moved = Rc::into_inner(rc).unwrap();
1249
+ // ```
1250
+ // since the `&mut Rc` is coerced to a `&PhantomPinned`.
1251
+ Pin :: < & mut _ > { pointer : & mut { $value } }
1241
1252
}
You can’t perform that action at this time.
0 commit comments