@@ -282,6 +282,7 @@ pub enum Variance {
282282#[ derive( Clone , Debug ) ]
283283pub enum AutoAdjustment < ' tcx > {
284284 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
285286 AdjustDerefRef ( AutoDerefRef < ' tcx > )
286287}
287288
@@ -2637,6 +2638,17 @@ impl<'tcx> ctxt<'tcx> {
26372638 substs
26382639 }
26392640
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+
26402652 pub fn mk_bare_fn ( & self , bare_fn : BareFnTy < ' tcx > ) -> & ' tcx BareFnTy < ' tcx > {
26412653 if let Some ( bare_fn) = self . bare_fn_interner . borrow ( ) . get ( & bare_fn) {
26422654 return * bare_fn;
@@ -4526,6 +4538,18 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
45264538 }
45274539 }
45284540
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+
45294553 AdjustDerefRef ( ref adj) => {
45304554 let mut adjusted_ty = unadjusted_ty;
45314555
@@ -6695,6 +6719,7 @@ impl<'tcx> AutoAdjustment<'tcx> {
66956719 pub fn is_identity ( & self ) -> bool {
66966720 match * self {
66976721 AdjustReifyFnPointer ( ..) => false ,
6722+ AdjustUnsafeFnPointer ( ..) => false ,
66986723 AdjustDerefRef ( ref r) => r. is_identity ( ) ,
66996724 }
67006725 }
@@ -6844,6 +6869,9 @@ impl<'tcx> Repr<'tcx> for AutoAdjustment<'tcx> {
68446869 AdjustReifyFnPointer ( def_id) => {
68456870 format ! ( "AdjustReifyFnPointer({})" , def_id. repr( tcx) )
68466871 }
6872+ AdjustUnsafeFnPointer => {
6873+ format ! ( "AdjustUnsafeFnPointer" )
6874+ }
68476875 AdjustDerefRef ( ref data) => {
68486876 data. repr ( tcx)
68496877 }
0 commit comments