@@ -38,7 +38,7 @@ use rustc_mir_dataflow::move_paths::MoveData;
38
38
use rustc_mir_dataflow:: points:: DenseLocationMap ;
39
39
use rustc_span:: def_id:: CRATE_DEF_ID ;
40
40
use rustc_span:: source_map:: Spanned ;
41
- use rustc_span:: { DUMMY_SP , Span , sym} ;
41
+ use rustc_span:: { Span , sym} ;
42
42
use rustc_trait_selection:: traits:: query:: type_op:: custom:: scrape_region_constraints;
43
43
use rustc_trait_selection:: traits:: query:: type_op:: { TypeOp , TypeOpOutput } ;
44
44
use tracing:: { debug, instrument, trace} ;
@@ -51,7 +51,6 @@ use crate::polonius::legacy::{PoloniusFacts, PoloniusLocationTable};
51
51
use crate :: polonius:: { PoloniusContext , PoloniusLivenessContext } ;
52
52
use crate :: region_infer:: TypeTest ;
53
53
use crate :: region_infer:: values:: { LivenessValues , PlaceholderIndex , PlaceholderIndices } ;
54
- use crate :: renumber:: RegionCtxt ;
55
54
use crate :: session_diagnostics:: { MoveUnsized , SimdIntrinsicArgConst } ;
56
55
use crate :: type_check:: free_region_relations:: { CreateResult , UniversalRegionRelations } ;
57
56
use crate :: universal_regions:: { DefiningTy , UniversalRegions } ;
@@ -2121,35 +2120,31 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2121
2120
//
2122
2121
// Note that other checks (such as denying `dyn Send` -> `dyn
2123
2122
// 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 ( )
2126
2125
&& src_tty. principal ( ) . is_some ( )
2127
2126
&& dst_tty. principal ( ) . is_some ( )
2128
2127
{
2129
2128
// Remove auto traits.
2130
2129
// 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,
2132
2132
tcx. mk_poly_existential_predicates (
2133
2133
& src_tty. without_auto_traits ( ) . collect :: < Vec < _ > > ( ) ,
2134
2134
) ,
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,
2136
2138
ty:: Dyn ,
2137
- ) ) ;
2138
- let dst_obj = tcx. mk_ty_from_kind ( ty:: Dynamic (
2139
+ ) ;
2140
+ let dst_obj = Ty :: new_dynamic (
2141
+ tcx,
2139
2142
tcx. mk_poly_existential_predicates (
2140
2143
& dst_tty. without_auto_traits ( ) . collect :: < Vec < _ > > ( ) ,
2141
2144
) ,
2142
- tcx . lifetimes . re_static ,
2145
+ dst_lt ,
2143
2146
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
+ ) ;
2153
2148
2154
2149
debug ! ( ?src_tty, ?dst_tty, ?src_obj, ?dst_obj) ;
2155
2150
@@ -2707,16 +2702,3 @@ impl<'tcx> TypeOp<'tcx> for InstantiateOpaqueType<'tcx> {
2707
2702
Ok ( output)
2708
2703
}
2709
2704
}
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