@@ -38,7 +38,7 @@ use rustc_mir_dataflow::move_paths::MoveData;
3838use  rustc_mir_dataflow:: points:: DenseLocationMap ; 
3939use  rustc_span:: def_id:: CRATE_DEF_ID ; 
4040use  rustc_span:: source_map:: Spanned ; 
41- use  rustc_span:: { DUMMY_SP ,   Span ,  sym} ; 
41+ use  rustc_span:: { Span ,  sym} ; 
4242use  rustc_trait_selection:: traits:: query:: type_op:: custom:: scrape_region_constraints; 
4343use  rustc_trait_selection:: traits:: query:: type_op:: { TypeOp ,  TypeOpOutput } ; 
4444use  tracing:: { debug,  instrument,  trace} ; 
@@ -51,7 +51,6 @@ use crate::polonius::legacy::{PoloniusFacts, PoloniusLocationTable};
5151use  crate :: polonius:: { PoloniusContext ,  PoloniusLivenessContext } ; 
5252use  crate :: region_infer:: TypeTest ; 
5353use  crate :: region_infer:: values:: { LivenessValues ,  PlaceholderIndex ,  PlaceholderIndices } ; 
54- use  crate :: renumber:: RegionCtxt ; 
5554use  crate :: session_diagnostics:: { MoveUnsized ,  SimdIntrinsicArgConst } ; 
5655use  crate :: type_check:: free_region_relations:: { CreateResult ,  UniversalRegionRelations } ; 
5756use  crate :: universal_regions:: { DefiningTy ,  UniversalRegions } ; 
@@ -2121,35 +2120,31 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21212120                                // 
21222121                                // Note that other checks (such as denying `dyn Send` -> `dyn 
21232122                                // Debug`) are in `rustc_hir_typeck`. 
2124-                                 if  let  ty:: Dynamic ( src_tty,  .. )  = src_tail. kind ( ) 
2125-                                     && let  ty:: Dynamic ( dst_tty,  .. )  = dst_tail. kind ( ) 
2123+                                 if  let  ty:: Dynamic ( src_tty,  _src_lt ,  _ )  = * src_tail. kind ( ) 
2124+                                     && let  ty:: Dynamic ( dst_tty,  dst_lt ,  _ )  = * dst_tail. kind ( ) 
21262125                                    && src_tty. principal ( ) . is_some ( ) 
21272126                                    && dst_tty. principal ( ) . is_some ( ) 
21282127                                { 
21292128                                    // Remove auto traits. 
21302129                                    // Auto trait checks are handled in `rustc_hir_typeck` as FCW. 
2131-                                     let  src_obj = tcx. mk_ty_from_kind ( ty:: Dynamic ( 
2130+                                     let  src_obj = Ty :: new_dynamic ( 
2131+                                         tcx, 
21322132                                        tcx. mk_poly_existential_predicates ( 
21332133                                            & src_tty. without_auto_traits ( ) . collect :: < Vec < _ > > ( ) , 
21342134                                        ) , 
2135-                                         tcx. lifetimes . re_static , 
2135+                                         // FIXME: Once we disallow casting `*const dyn Trait + 'short` 
2136+                                         // to `*const dyn Trait + 'long`, then this can just be `src_lt`. 
2137+                                         dst_lt, 
21362138                                        ty:: Dyn , 
2137-                                     ) ) ; 
2138-                                     let  dst_obj = tcx. mk_ty_from_kind ( ty:: Dynamic ( 
2139+                                     ) ; 
2140+                                     let  dst_obj = Ty :: new_dynamic ( 
2141+                                         tcx, 
21392142                                        tcx. mk_poly_existential_predicates ( 
21402143                                            & dst_tty. without_auto_traits ( ) . collect :: < Vec < _ > > ( ) , 
21412144                                        ) , 
2142-                                         tcx . lifetimes . re_static , 
2145+                                         dst_lt , 
21432146                                        ty:: Dyn , 
2144-                                     ) ) ; 
2145- 
2146-                                     // Replace trait object lifetimes with fresh vars, to allow 
2147-                                     // casts like 
2148-                                     // `*mut dyn FnOnce() + 'a` -> `*mut dyn FnOnce() + 'static` 
2149-                                     let  src_obj =
2150-                                         freshen_single_trait_object_lifetime ( self . infcx ,  src_obj) ; 
2151-                                     let  dst_obj =
2152-                                         freshen_single_trait_object_lifetime ( self . infcx ,  dst_obj) ; 
2147+                                     ) ; 
21532148
21542149                                    debug ! ( ?src_tty,  ?dst_tty,  ?src_obj,  ?dst_obj) ; 
21552150
@@ -2707,16 +2702,3 @@ impl<'tcx> TypeOp<'tcx> for InstantiateOpaqueType<'tcx> {
27072702        Ok ( output) 
27082703    } 
27092704} 
2710- 
2711- fn  freshen_single_trait_object_lifetime < ' tcx > ( 
2712-     infcx :  & BorrowckInferCtxt < ' tcx > , 
2713-     ty :  Ty < ' tcx > , 
2714- )  -> Ty < ' tcx >  { 
2715-     let  & ty:: Dynamic ( tty,  _,  dyn_kind @ ty:: Dyn )  = ty. kind ( )  else  {  bug ! ( "expected trait object" )  } ; 
2716- 
2717-     let  fresh = infcx
2718-         . next_region_var ( rustc_infer:: infer:: RegionVariableOrigin :: MiscVariable ( DUMMY_SP ) ,  || { 
2719-             RegionCtxt :: Unknown 
2720-         } ) ; 
2721-     infcx. tcx . mk_ty_from_kind ( ty:: Dynamic ( tty,  fresh,  dyn_kind) ) 
2722- } 
0 commit comments