1
1
use itertools:: Itertools ;
2
2
use rustc_data_structures:: unord:: UnordSet ;
3
- use rustc_hir:: def_id:: { DefId , LocalDefId } ;
3
+ use rustc_hir:: def_id:: LocalDefId ;
4
4
use rustc_index:: bit_set:: BitSet ;
5
5
use rustc_macros:: LintDiagnostic ;
6
6
use rustc_middle:: mir:: {
@@ -13,7 +13,7 @@ use rustc_mir_dataflow::move_paths::{MoveData, MovePathIndex};
13
13
use rustc_mir_dataflow:: { Analysis , MaybeReachable } ;
14
14
use rustc_session:: lint;
15
15
use rustc_span:: Span ;
16
- use tracing:: debug;
16
+ use tracing:: { debug, instrument } ;
17
17
18
18
fn place_has_common_prefix < ' tcx > ( left : & Place < ' tcx > , right : & Place < ' tcx > ) -> bool {
19
19
left. local == right. local
@@ -68,9 +68,10 @@ fn print_ty_without_trimming(ty: Ty<'_>) -> String {
68
68
ty:: print:: with_no_trimmed_paths!( format!( "{}" , ty) )
69
69
}
70
70
71
+ #[ instrument( level = "debug" , skip( tcx, param_env) ) ]
71
72
fn extract_component_with_significant_dtor < ' tcx > (
72
73
tcx : TyCtxt < ' tcx > ,
73
- _body_did : DefId ,
74
+ param_env : ty :: ParamEnv < ' tcx > ,
74
75
ty : Ty < ' tcx > ,
75
76
) -> ( String , Vec < Span > ) {
76
77
let ty_def_span = |ty : Ty < ' _ > | match ty. kind ( ) {
@@ -104,10 +105,7 @@ fn extract_component_with_significant_dtor<'tcx>(
104
105
// I honestly don't know how to extract the span reliably from a param arbitrarily nested
105
106
ty:: Param ( _) => None ,
106
107
} ;
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 {
111
109
return ( print_ty_without_trimming ( ty) , vec ! [ ] ) ;
112
110
} ;
113
111
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<
164
162
}
165
163
166
164
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 ) ;
168
166
let is_closure_like = tcx. is_closure_like ( def_id. to_def_id ( ) ) ;
169
167
let move_data = MoveData :: gather_moves ( body, tcx, param_env, |_| true ) ;
170
168
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<
216
214
let observer_local_decl = & body. local_decls [ move_path. place . local ] ;
217
215
let ( ty_drop_components, ty_spans) = extract_component_with_significant_dtor (
218
216
tcx,
219
- def_id . to_def_id ( ) ,
217
+ param_env ,
220
218
linted_local_decl. ty ,
221
219
) ;
222
220
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) ;
228
222
debug ! ( ?candidate, ?place, ?move_path. place) ;
229
223
tcx. emit_node_span_lint (
230
224
lint:: builtin:: TAIL_EXPR_DROP_ORDER ,
0 commit comments