11use itertools:: Itertools ;
22use rustc_data_structures:: unord:: UnordSet ;
3- use rustc_hir:: def_id:: { DefId , LocalDefId } ;
3+ use rustc_hir:: def_id:: LocalDefId ;
44use rustc_index:: bit_set:: BitSet ;
55use rustc_macros:: LintDiagnostic ;
66use rustc_middle:: mir:: {
@@ -13,7 +13,7 @@ use rustc_mir_dataflow::move_paths::{MoveData, MovePathIndex};
1313use rustc_mir_dataflow:: { Analysis , MaybeReachable } ;
1414use rustc_session:: lint;
1515use rustc_span:: Span ;
16- use tracing:: debug;
16+ use tracing:: { debug, instrument } ;
1717
1818fn place_has_common_prefix < ' tcx > ( left : & Place < ' tcx > , right : & Place < ' tcx > ) -> bool {
1919 left. local == right. local
@@ -68,9 +68,10 @@ fn print_ty_without_trimming(ty: Ty<'_>) -> String {
6868 ty:: print:: with_no_trimmed_paths!( format!( "{}" , ty) )
6969}
7070
71+ #[ instrument( level = "debug" , skip( tcx, param_env) ) ]
7172fn extract_component_with_significant_dtor < ' tcx > (
7273 tcx : TyCtxt < ' tcx > ,
73- _body_did : DefId ,
74+ param_env : ty :: ParamEnv < ' tcx > ,
7475 ty : Ty < ' tcx > ,
7576) -> ( String , Vec < Span > ) {
7677 let ty_def_span = |ty : Ty < ' _ > | match ty. kind ( ) {
@@ -104,10 +105,7 @@ fn extract_component_with_significant_dtor<'tcx>(
104105 // I honestly don't know how to extract the span reliably from a param arbitrarily nested
105106 ty:: Param ( _) => None ,
106107 } ;
107- let Some ( adt_def) = ty. ty_adt_def ( ) else {
108- return ( print_ty_without_trimming ( ty) , vec ! [ ] ) ;
109- } ;
110- let Ok ( tys) = tcx. adt_significant_drop_tys ( adt_def. did ( ) ) else {
108+ let Ok ( tys) = tcx. list_significant_drop_tys ( param_env. and ( ty) ) else {
111109 return ( print_ty_without_trimming ( ty) , vec ! [ ] ) ;
112110 } ;
113111 let ty_names = tys. iter ( ) . map ( print_ty_without_trimming) . join ( ", " ) ;
@@ -164,7 +162,7 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
164162 }
165163
166164 dump_mir ( tcx, false , "lint_tail_expr_drop_order" , & 0 as _ , body, |_, _| Ok ( ( ) ) ) ;
167- let param_env = tcx. param_env ( def_id) ;
165+ let param_env = tcx. param_env ( def_id) . with_reveal_all_normalized ( tcx ) ;
168166 let is_closure_like = tcx. is_closure_like ( def_id. to_def_id ( ) ) ;
169167 let move_data = MoveData :: gather_moves ( body, tcx, param_env, |_| true ) ;
170168 let maybe_init = MaybeInitializedPlaces :: new ( tcx, body, & move_data) ;
@@ -216,15 +214,11 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
216214 let observer_local_decl = & body. local_decls [ move_path. place . local ] ;
217215 let ( ty_drop_components, ty_spans) = extract_component_with_significant_dtor (
218216 tcx,
219- def_id . to_def_id ( ) ,
217+ param_env ,
220218 linted_local_decl. ty ,
221219 ) ;
222220 let ( observer_ty_drop_components, observer_ty_spans) =
223- extract_component_with_significant_dtor (
224- tcx,
225- def_id. to_def_id ( ) ,
226- observer_ty,
227- ) ;
221+ extract_component_with_significant_dtor ( tcx, param_env, observer_ty) ;
228222 debug ! ( ?candidate, ?place, ?move_path. place) ;
229223 tcx. emit_node_span_lint (
230224 lint:: builtin:: TAIL_EXPR_DROP_ORDER ,
0 commit comments