@@ -90,7 +90,6 @@ use rustc_index::{IndexSlice, IndexVec};
9090use rustc_middle:: middle:: region;
9191use rustc_middle:: mir:: * ;
9292use rustc_middle:: thir:: { ExprId , LintLevel } ;
93- use rustc_middle:: ty:: TypeVisitableExt ;
9493use rustc_middle:: { bug, span_bug} ;
9594use rustc_session:: lint:: Level ;
9695use rustc_span:: { Span , DUMMY_SP } ;
@@ -1143,8 +1142,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11431142 {
11441143 return ;
11451144 }
1146- // Opaque type may not have been scheduled if its underlying
1147- // type does not need drop.
11481145 _ => bug ! (
11491146 "found wrong drop, expected value drop of {:?} in scope {:?}, found {:?}, all scopes {:?}" ,
11501147 local,
@@ -1159,6 +1156,43 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11591156 bug ! ( "region scope {:?} not in scope to unschedule drop of {:?}" , region_scope, local) ;
11601157 }
11611158
1159+ pub ( crate ) fn may_unschedule_drop (
1160+ & mut self ,
1161+ region_scope : region:: Scope ,
1162+ local : Local ,
1163+ x : & dyn std:: fmt:: Debug ,
1164+ ) {
1165+ if !self . local_decls [ local] . ty . needs_drop ( self . tcx , self . param_env ) {
1166+ return ;
1167+ }
1168+ for scope in self . scopes . scopes . iter ( ) . rev ( ) {
1169+ if scope. region_scope == region_scope {
1170+ let drop = scope. drops . last ( ) ;
1171+
1172+ match drop {
1173+ Some ( & DropData { local : removed_local, kind : DropKind :: Value , .. } )
1174+ if removed_local == local =>
1175+ {
1176+ return ;
1177+ }
1178+ _ => tracing:: warn!(
1179+ "expected drop to unschedule {x:?}, expected value drop of {:?} in scope {:?}, found {:?}, all scopes {:?}" ,
1180+ local,
1181+ region_scope,
1182+ drop,
1183+ self . scopes. scopes,
1184+ ) ,
1185+ }
1186+ }
1187+ }
1188+
1189+ tracing:: warn!(
1190+ "region scope {:?} to unschedule {x:?} not in scope to unschedule drop of {:?}" ,
1191+ region_scope,
1192+ local
1193+ ) ;
1194+ }
1195+
11621196 /// Indicates that the "local operands" stored in `local` are
11631197 /// *moved* at some point during execution (see `local_scope` for
11641198 /// more information about what a "local operand" is -- in short,
0 commit comments