@@ -90,7 +90,6 @@ use rustc_index::{IndexSlice, IndexVec};
90
90
use rustc_middle:: middle:: region;
91
91
use rustc_middle:: mir:: * ;
92
92
use rustc_middle:: thir:: { ExprId , LintLevel } ;
93
- use rustc_middle:: ty:: TypeVisitableExt ;
94
93
use rustc_middle:: { bug, span_bug} ;
95
94
use rustc_session:: lint:: Level ;
96
95
use rustc_span:: { Span , DUMMY_SP } ;
@@ -1143,8 +1142,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1143
1142
{
1144
1143
return ;
1145
1144
}
1146
- // Opaque type may not have been scheduled if its underlying
1147
- // type does not need drop.
1148
1145
_ => bug ! (
1149
1146
"found wrong drop, expected value drop of {:?} in scope {:?}, found {:?}, all scopes {:?}" ,
1150
1147
local,
@@ -1159,6 +1156,43 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1159
1156
bug ! ( "region scope {:?} not in scope to unschedule drop of {:?}" , region_scope, local) ;
1160
1157
}
1161
1158
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
+
1162
1196
/// Indicates that the "local operands" stored in `local` are
1163
1197
/// *moved* at some point during execution (see `local_scope` for
1164
1198
/// more information about what a "local operand" is -- in short,
0 commit comments