Skip to content

Commit 11392f4

Browse files
Emit dummy open drop for unsafe binder
1 parent 52bf0cf commit 11392f4

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

compiler/rustc_mir_transform/src/elaborate_drop.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,23 @@ where
12781278
}
12791279
ty::Slice(ety) => self.drop_loop_trio_for_slice(*ety),
12801280

1281+
ty::UnsafeBinder(_) => {
1282+
// Unsafe binders may elaborate drops if their inner type isn't copy.
1283+
// This is enforced in typeck, so this should never happen.
1284+
self.tcx().dcx().span_delayed_bug(
1285+
self.source_info.span,
1286+
"open drop for unsafe binder shouldn't be encountered",
1287+
);
1288+
self.elaborator.patch().new_block(BasicBlockData {
1289+
statements: vec![],
1290+
terminator: Some(Terminator {
1291+
source_info: self.source_info,
1292+
kind: TerminatorKind::Unreachable,
1293+
}),
1294+
is_cleanup: self.unwind.is_cleanup(),
1295+
})
1296+
}
1297+
12811298
_ => span_bug!(self.source_info.span, "open drop from non-ADT `{:?}`", ty),
12821299
}
12831300
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ compile-flags: -Zvalidate-mir
2+
3+
// Regression test for <https://github.com/rust-lang/rust/issues/141394>.
4+
5+
#![feature(unsafe_binders)]
6+
#![allow(incomplete_features)]
7+
8+
use std::unsafe_binder::unwrap_binder;
9+
10+
fn id<T>(x: unsafe<> T) -> T {
11+
//~^ ERROR the trait bound `T: Copy` is not satisfied
12+
unsafe { unwrap_binder!(x) }
13+
}
14+
15+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: the trait bound `T: Copy` is not satisfied
2+
--> $DIR/move-out-of-non-copy.rs:10:13
3+
|
4+
LL | fn id<T>(x: unsafe<> T) -> T {
5+
| ^^^^^^^^^^ the trait `Copy` is not implemented for `T`
6+
|
7+
help: consider restricting type parameter `T` with trait `Copy`
8+
|
9+
LL | fn id<T: std::marker::Copy>(x: unsafe<> T) -> T {
10+
| +++++++++++++++++++
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)