@@ -5,16 +5,17 @@ use rustc_const_eval::util::{call_kind, CallDesugaringKind};
5
5
use rustc_errors:: { Applicability , Diagnostic } ;
6
6
use rustc_hir as hir;
7
7
use rustc_hir:: def:: Namespace ;
8
- use rustc_hir:: def_id:: DefId ;
9
8
use rustc_hir:: GeneratorKind ;
10
9
use rustc_infer:: infer:: TyCtxtInferExt ;
10
+ use rustc_middle:: mir:: tcx:: PlaceTy ;
11
11
use rustc_middle:: mir:: {
12
12
AggregateKind , Constant , FakeReadCause , Field , Local , LocalInfo , LocalKind , Location , Operand ,
13
13
Place , PlaceRef , ProjectionElem , Rvalue , Statement , StatementKind , Terminator , TerminatorKind ,
14
14
} ;
15
15
use rustc_middle:: ty:: print:: Print ;
16
16
use rustc_middle:: ty:: { self , DefIdTree , Instance , Ty , TyCtxt } ;
17
17
use rustc_mir_dataflow:: move_paths:: { InitLocation , LookupResult } ;
18
+ use rustc_span:: def_id:: LocalDefId ;
18
19
use rustc_span:: { symbol:: sym, Span , DUMMY_SP } ;
19
20
use rustc_target:: abi:: VariantIdx ;
20
21
use rustc_trait_selection:: traits:: type_known_to_meet_bound_modulo_regions;
@@ -41,7 +42,6 @@ pub(crate) use outlives_suggestion::OutlivesSuggestionBuilder;
41
42
pub ( crate ) use region_errors:: { ErrorConstraintInfo , RegionErrorKind , RegionErrors } ;
42
43
pub ( crate ) use region_name:: { RegionName , RegionNameSource } ;
43
44
pub ( crate ) use rustc_const_eval:: util:: CallKind ;
44
- use rustc_middle:: mir:: tcx:: PlaceTy ;
45
45
46
46
pub ( super ) struct IncludingDowncast ( pub ( super ) bool ) ;
47
47
@@ -325,10 +325,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
325
325
// so it's safe to call `expect_local`.
326
326
//
327
327
// We know the field exists so it's safe to call operator[] and `unwrap` here.
328
+ let def_id = def_id. expect_local ( ) ;
328
329
let var_id = self
329
330
. infcx
330
331
. tcx
331
- . typeck ( def_id. expect_local ( ) )
332
+ . typeck ( def_id)
332
333
. closure_min_captures_flattened ( def_id)
333
334
. nth ( field. index ( ) )
334
335
. unwrap ( )
@@ -715,12 +716,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
715
716
716
717
debug ! ( "move_spans: moved_place={:?} location={:?} stmt={:?}" , moved_place, location, stmt) ;
717
718
if let StatementKind :: Assign ( box ( _, Rvalue :: Aggregate ( ref kind, ref places) ) ) = stmt. kind {
718
- match kind {
719
- box AggregateKind :: Closure ( def_id, _)
720
- | box AggregateKind :: Generator ( def_id, _, _) => {
719
+ match * * kind {
720
+ AggregateKind :: Closure ( def_id, _) | AggregateKind :: Generator ( def_id, _, _) => {
721
721
debug ! ( "move_spans: def_id={:?} places={:?}" , def_id, places) ;
722
722
if let Some ( ( args_span, generator_kind, capture_kind_span, path_span) ) =
723
- self . closure_span ( * def_id, moved_place, places)
723
+ self . closure_span ( def_id, moved_place, places)
724
724
{
725
725
return ClosureUse {
726
726
generator_kind,
@@ -847,7 +847,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
847
847
if let StatementKind :: Assign ( box ( _, Rvalue :: Aggregate ( ref kind, ref places) ) ) =
848
848
stmt. kind
849
849
{
850
- let ( def_id, is_generator) = match kind {
850
+ let ( & def_id, is_generator) = match kind {
851
851
box AggregateKind :: Closure ( def_id, _) => ( def_id, false ) ,
852
852
box AggregateKind :: Generator ( def_id, _, _) => ( def_id, true ) ,
853
853
_ => continue ,
@@ -858,7 +858,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
858
858
def_id, is_generator, places
859
859
) ;
860
860
if let Some ( ( args_span, generator_kind, capture_kind_span, path_span) ) =
861
- self . closure_span ( * def_id, Place :: from ( target) . as_ref ( ) , places)
861
+ self . closure_span ( def_id, Place :: from ( target) . as_ref ( ) , places)
862
862
{
863
863
return ClosureUse { generator_kind, args_span, capture_kind_span, path_span } ;
864
864
} else {
@@ -879,25 +879,20 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
879
879
/// The second span is the location the use resulting in the captured path of the capture
880
880
fn closure_span (
881
881
& self ,
882
- def_id : DefId ,
882
+ def_id : LocalDefId ,
883
883
target_place : PlaceRef < ' tcx > ,
884
884
places : & [ Operand < ' tcx > ] ,
885
885
) -> Option < ( Span , Option < GeneratorKind > , Span , Span ) > {
886
886
debug ! (
887
887
"closure_span: def_id={:?} target_place={:?} places={:?}" ,
888
888
def_id, target_place, places
889
889
) ;
890
- let local_did = def_id. as_local ( ) ?;
891
- let hir_id = self . infcx . tcx . hir ( ) . local_def_id_to_hir_id ( local_did) ;
890
+ let hir_id = self . infcx . tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
892
891
let expr = & self . infcx . tcx . hir ( ) . expect_expr ( hir_id) . kind ;
893
892
debug ! ( "closure_span: hir_id={:?} expr={:?}" , hir_id, expr) ;
894
893
if let hir:: ExprKind :: Closure ( & hir:: Closure { body, fn_decl_span, .. } ) = expr {
895
- for ( captured_place, place) in self
896
- . infcx
897
- . tcx
898
- . typeck ( def_id. expect_local ( ) )
899
- . closure_min_captures_flattened ( def_id)
900
- . zip ( places)
894
+ for ( captured_place, place) in
895
+ self . infcx . tcx . typeck ( def_id) . closure_min_captures_flattened ( def_id) . zip ( places)
901
896
{
902
897
match place {
903
898
Operand :: Copy ( place) | Operand :: Move ( place)
0 commit comments