@@ -3,15 +3,18 @@ use rustc_index::bit_set::DenseBitSet;
33use rustc_index:: interval:: IntervalSet ;
44use rustc_infer:: infer:: canonical:: QueryRegionConstraints ;
55use rustc_infer:: infer:: outlives:: for_liveness;
6- use rustc_middle:: mir:: { BasicBlock , Body , ConstraintCategory , Local , Location } ;
6+ use rustc_middle:: mir:: { BasicBlock , Body , ConstraintCategory , HasLocalDecls , Local , Location } ;
77use rustc_middle:: traits:: query:: DropckOutlivesResult ;
88use rustc_middle:: ty:: relate:: Relate ;
99use rustc_middle:: ty:: { Ty , TyCtxt , TypeVisitable , TypeVisitableExt } ;
1010use rustc_mir_dataflow:: ResultsCursor ;
1111use rustc_mir_dataflow:: impls:: MaybeInitializedPlaces ;
1212use rustc_mir_dataflow:: move_paths:: { HasMoveData , MoveData , MovePathIndex } ;
1313use rustc_mir_dataflow:: points:: { DenseLocationMap , PointIndex } ;
14- use rustc_span:: DUMMY_SP ;
14+ use rustc_span:: { DUMMY_SP , Span } ;
15+ use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt ;
16+ use rustc_trait_selection:: traits:: ObligationCtxt ;
17+ use rustc_trait_selection:: traits:: query:: dropck_outlives;
1518use rustc_trait_selection:: traits:: query:: type_op:: { DropckOutlives , TypeOp , TypeOpOutput } ;
1619use tracing:: debug;
1720
@@ -162,9 +165,10 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
162165 fn dropck_boring_locals ( & mut self , boring_locals : Vec < Local > ) {
163166 for local in boring_locals {
164167 let local_ty = self . cx . body . local_decls [ local] . ty ;
168+ let local_span = self . cx . body . local_decls [ local] . source_info . span ;
165169 let drop_data = self . cx . drop_data . entry ( local_ty) . or_insert_with ( {
166170 let typeck = & self . cx . typeck ;
167- move || LivenessContext :: compute_drop_data ( typeck, local_ty)
171+ move || LivenessContext :: compute_drop_data ( typeck, local_ty, local_span )
168172 } ) ;
169173
170174 drop_data. dropck_result . report_overflows (
@@ -522,9 +526,10 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
522526 values:: pretty_print_points( self . location_map, live_at. iter( ) ) ,
523527 ) ;
524528
529+ let local_span = self . body . local_decls ( ) [ dropped_local] . source_info . span ;
525530 let drop_data = self . drop_data . entry ( dropped_ty) . or_insert_with ( {
526531 let typeck = & self . typeck ;
527- move || Self :: compute_drop_data ( typeck, dropped_ty)
532+ move || Self :: compute_drop_data ( typeck, dropped_ty, local_span )
528533 } ) ;
529534
530535 if let Some ( data) = & drop_data. region_constraint_data {
@@ -589,19 +594,43 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
589594 }
590595 }
591596
592- fn compute_drop_data ( typeck : & TypeChecker < ' _ , ' tcx > , dropped_ty : Ty < ' tcx > ) -> DropData < ' tcx > {
593- debug ! ( "compute_drop_data(dropped_ty={:?})" , dropped_ty, ) ;
597+ fn compute_drop_data (
598+ typeck : & TypeChecker < ' _ , ' tcx > ,
599+ dropped_ty : Ty < ' tcx > ,
600+ span : Span ,
601+ ) -> DropData < ' tcx > {
602+ debug ! ( "compute_drop_data(dropped_ty={:?})" , dropped_ty) ;
603+
604+ let op = typeck. infcx . param_env . and ( DropckOutlives { dropped_ty } ) ;
594605
595- match typeck
596- . infcx
597- . param_env
598- . and ( DropckOutlives { dropped_ty } )
599- . fully_perform ( typeck. infcx , DUMMY_SP )
600- {
606+ match op. fully_perform ( typeck. infcx , DUMMY_SP ) {
601607 Ok ( TypeOpOutput { output, constraints, .. } ) => {
602608 DropData { dropck_result : output, region_constraint_data : constraints }
603609 }
604- Err ( _) => DropData { dropck_result : Default :: default ( ) , region_constraint_data : None } ,
610+ Err ( _) => {
611+ // The `ErrorGuaranteed` from `fully_perform` comes from delay_span_bug,
612+ // so emitting an error here is not redundant.
613+ let ocx = ObligationCtxt :: new_with_diagnostics ( & typeck. infcx ) ;
614+ let errors = match dropck_outlives:: compute_dropck_outlives_with_errors (
615+ & ocx, op, span, true ,
616+ ) {
617+ Ok ( _) => ocx. select_all_or_error ( ) ,
618+ Err ( e) => {
619+ if e. is_empty ( ) {
620+ ocx. select_all_or_error ( )
621+ } else {
622+ e
623+ }
624+ }
625+ } ;
626+
627+ if !errors. is_empty ( ) {
628+ typeck. infcx . err_ctxt ( ) . report_fulfillment_errors ( errors) ;
629+ } else {
630+ rustc_middle:: span_bug!( span, "Rerunning drop data query produced no error." ) ;
631+ }
632+ DropData { dropck_result : Default :: default ( ) , region_constraint_data : None }
633+ }
605634 }
606635 }
607636}
0 commit comments