Skip to content

Commit 82bc482

Browse files
authored
Unrolled build for #154717
Rollup merge of #154717 - cijiugechu:fix/unsafe-binder-discriminant, r=jdonszelmann Fix ICE in unsafe binder discriminant helpers Forward discriminant-related helpers through `ty::UnsafeBinder` to the erased inner type, matching the existing layout behavior. Tracking issue: #130516 Closes #154424
2 parents c2efcc4 + 3569377 commit 82bc482

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,9 @@ impl<'tcx> Ty<'tcx> {
16401640
TyKind::Coroutine(def_id, args) => {
16411641
Some(args.as_coroutine().variant_range(*def_id, tcx))
16421642
}
1643+
TyKind::UnsafeBinder(bound_ty) => {
1644+
tcx.instantiate_bound_regions_with_erased((*bound_ty).into()).variant_range(tcx)
1645+
}
16431646
_ => None,
16441647
}
16451648
}
@@ -1661,6 +1664,9 @@ impl<'tcx> Ty<'tcx> {
16611664
TyKind::Coroutine(def_id, args) => {
16621665
Some(args.as_coroutine().discriminant_for_variant(*def_id, tcx, variant_index))
16631666
}
1667+
TyKind::UnsafeBinder(bound_ty) => tcx
1668+
.instantiate_bound_regions_with_erased((*bound_ty).into())
1669+
.discriminant_for_variant(tcx, variant_index),
16641670
_ => None,
16651671
}
16661672
}
@@ -1679,6 +1685,9 @@ impl<'tcx> Ty<'tcx> {
16791685
}
16801686

16811687
ty::Pat(ty, _) => ty.discriminant_ty(tcx),
1688+
ty::UnsafeBinder(bound_ty) => {
1689+
tcx.instantiate_bound_regions_with_erased((*bound_ty).into()).discriminant_ty(tcx)
1690+
}
16821691

16831692
ty::Bool
16841693
| ty::Char
@@ -1700,7 +1709,6 @@ impl<'tcx> Ty<'tcx> {
17001709
| ty::CoroutineWitness(..)
17011710
| ty::Never
17021711
| ty::Tuple(_)
1703-
| ty::UnsafeBinder(_)
17041712
| ty::Error(_)
17051713
| ty::Infer(IntVar(_) | FloatVar(_)) => tcx.types.u8,
17061714

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(unsafe_binders)]
2+
3+
const None: Option<unsafe<> Option<Box<dyn Send>>> = None;
4+
//~^ ERROR the trait bound `Box<(dyn Send + 'static)>: Copy` is not satisfied
5+
//~| ERROR the trait bound `Box<(dyn Send + 'static)>: Copy` is not satisfied
6+
7+
fn main() {
8+
match None {
9+
_ => {}
10+
}
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0277]: the trait bound `Box<(dyn Send + 'static)>: Copy` is not satisfied
2+
--> $DIR/discriminant-for-variant.rs:3:13
3+
|
4+
LL | const None: Option<unsafe<> Option<Box<dyn Send>>> = None;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<(dyn Send + 'static)>`
6+
|
7+
= note: required for `Option<Box<(dyn Send + 'static)>>` to implement `Copy`
8+
9+
error[E0277]: the trait bound `Box<(dyn Send + 'static)>: Copy` is not satisfied
10+
--> $DIR/discriminant-for-variant.rs:3:54
11+
|
12+
LL | const None: Option<unsafe<> Option<Box<dyn Send>>> = None;
13+
| ^^^^ the trait `Copy` is not implemented for `Box<(dyn Send + 'static)>`
14+
|
15+
= note: required for `Option<Box<(dyn Send + 'static)>>` to implement `Copy`
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)