Skip to content

Commit 0cb9827

Browse files
authored
Rollup merge of #137770 - compiler-errors:unsafe-binder-sized-crit, r=oli-obk
Fix sized constraint for unsafe binder Fixes #137705 r? oli-obk
2 parents 9e1ead6 + b67b6c0 commit 0cb9827

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

compiler/rustc_ty_utils/src/ty.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'
3737
| Never
3838
| Dynamic(_, _, ty::DynStar) => None,
3939

40-
UnsafeBinder(_) => todo!(),
41-
4240
// these are never sized
4341
Str | Slice(..) | Dynamic(_, _, ty::Dyn) | Foreign(..) => Some(ty),
4442

@@ -52,9 +50,14 @@ fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'
5250
sized_constraint_for_ty(tcx, ty)
5351
}),
5452

55-
// these can be sized or unsized
53+
// these can be sized or unsized.
5654
Param(..) | Alias(..) | Error(_) => Some(ty),
5755

56+
// We cannot instantiate the binder, so just return the *original* type back,
57+
// but only if the inner type has a sized constraint. Thus we skip the binder,
58+
// but don't actually use the result from `sized_constraint_for_ty`.
59+
UnsafeBinder(inner_ty) => sized_constraint_for_ty(tcx, inner_ty.skip_binder()).map(|_| ty),
60+
5861
Placeholder(..) | Bound(..) | Infer(..) => {
5962
bug!("unexpected type `{ty:?}` in sized_constraint_for_ty")
6063
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ check-pass
2+
3+
#![feature(unsafe_binders)]
4+
//~^ WARN the feature `unsafe_binders` is incomplete
5+
6+
use std::unsafe_binder::wrap_binder;
7+
8+
struct A {
9+
b: unsafe<> (),
10+
}
11+
12+
fn main() {
13+
unsafe {
14+
let _ = A {
15+
b: wrap_binder!(()),
16+
};
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/binder-sized-crit.rs:3:12
3+
|
4+
LL | #![feature(unsafe_binders)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)