@@ -282,6 +282,7 @@ pub enum Variance {
282
282
#[ derive( Clone , Debug ) ]
283
283
pub enum AutoAdjustment < ' tcx > {
284
284
AdjustReifyFnPointer ( ast:: DefId ) , // go from a fn-item type to a fn-pointer type
285
+ AdjustUnsafeFnPointer , // go from a safe fn pointer to an unsafe fn pointer
285
286
AdjustDerefRef ( AutoDerefRef < ' tcx > )
286
287
}
287
288
@@ -2637,6 +2638,17 @@ impl<'tcx> ctxt<'tcx> {
2637
2638
substs
2638
2639
}
2639
2640
2641
+ /// Create an unsafe fn ty based on a safe fn ty.
2642
+ pub fn safe_to_unsafe_fn_ty ( & self , bare_fn : & BareFnTy < ' tcx > ) -> Ty < ' tcx > {
2643
+ assert_eq ! ( bare_fn. unsafety, ast:: Unsafety :: Normal ) ;
2644
+ let unsafe_fn_ty_a = self . mk_bare_fn ( ty:: BareFnTy {
2645
+ unsafety : ast:: Unsafety :: Unsafe ,
2646
+ abi : bare_fn. abi ,
2647
+ sig : bare_fn. sig . clone ( )
2648
+ } ) ;
2649
+ ty:: mk_bare_fn ( self , None , unsafe_fn_ty_a)
2650
+ }
2651
+
2640
2652
pub fn mk_bare_fn ( & self , bare_fn : BareFnTy < ' tcx > ) -> & ' tcx BareFnTy < ' tcx > {
2641
2653
if let Some ( bare_fn) = self . bare_fn_interner . borrow ( ) . get ( & bare_fn) {
2642
2654
return * bare_fn;
@@ -4526,6 +4538,18 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
4526
4538
}
4527
4539
}
4528
4540
4541
+ AdjustUnsafeFnPointer => {
4542
+ match unadjusted_ty. sty {
4543
+ ty:: ty_bare_fn( None , b) => cx. safe_to_unsafe_fn_ty ( b) ,
4544
+ ref b => {
4545
+ cx. sess . bug (
4546
+ & format ! ( "AdjustReifyFnPointer adjustment on non-fn-item: \
4547
+ {:?}",
4548
+ b) ) ;
4549
+ }
4550
+ }
4551
+ }
4552
+
4529
4553
AdjustDerefRef ( ref adj) => {
4530
4554
let mut adjusted_ty = unadjusted_ty;
4531
4555
@@ -6695,6 +6719,7 @@ impl<'tcx> AutoAdjustment<'tcx> {
6695
6719
pub fn is_identity ( & self ) -> bool {
6696
6720
match * self {
6697
6721
AdjustReifyFnPointer ( ..) => false ,
6722
+ AdjustUnsafeFnPointer ( ..) => false ,
6698
6723
AdjustDerefRef ( ref r) => r. is_identity ( ) ,
6699
6724
}
6700
6725
}
@@ -6844,6 +6869,9 @@ impl<'tcx> Repr<'tcx> for AutoAdjustment<'tcx> {
6844
6869
AdjustReifyFnPointer ( def_id) => {
6845
6870
format ! ( "AdjustReifyFnPointer({})" , def_id. repr( tcx) )
6846
6871
}
6872
+ AdjustUnsafeFnPointer => {
6873
+ format ! ( "AdjustUnsafeFnPointer" )
6874
+ }
6847
6875
AdjustDerefRef ( ref data) => {
6848
6876
data. repr ( tcx)
6849
6877
}
0 commit comments