@@ -4,7 +4,7 @@ use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
4
4
5
5
use hir:: def:: DefKind ;
6
6
use rustc_hir as hir;
7
- use rustc_hir:: def_id:: DefId ;
7
+ use rustc_hir:: def_id:: LocalDefId ;
8
8
use rustc_hir:: lang_items:: LangItem ;
9
9
use rustc_hir_analysis:: astconv:: AstConv ;
10
10
use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
@@ -41,18 +41,14 @@ struct ClosureSignatures<'tcx> {
41
41
}
42
42
43
43
impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
44
- #[ instrument( skip( self , expr , _capture , decl , body_id ) , level = "debug" ) ]
44
+ #[ instrument( skip( self , closure ) , level = "debug" ) ]
45
45
pub fn check_expr_closure (
46
46
& self ,
47
- expr : & hir:: Expr < ' _ > ,
48
- _capture : hir:: CaptureBy ,
49
- decl : & ' tcx hir:: FnDecl < ' tcx > ,
50
- body_id : hir:: BodyId ,
51
- gen : Option < hir:: Movability > ,
47
+ closure : & hir:: Closure < ' tcx > ,
48
+ expr_span : Span ,
52
49
expected : Expectation < ' tcx > ,
53
50
) -> Ty < ' tcx > {
54
- trace ! ( "decl = {:#?}" , decl) ;
55
- trace ! ( "expr = {:#?}" , expr) ;
51
+ trace ! ( "decl = {:#?}" , closure. fn_decl) ;
56
52
57
53
// It's always helpful for inference if we know the kind of
58
54
// closure sooner rather than later, so first examine the expected
@@ -61,37 +57,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
61
57
Some ( ty) => self . deduce_expectations_from_expected_type ( ty) ,
62
58
None => ( None , None ) ,
63
59
} ;
64
- let body = self . tcx . hir ( ) . body ( body_id ) ;
65
- self . check_closure ( expr , expected_kind , decl , body, gen , expected_sig)
60
+ let body = self . tcx . hir ( ) . body ( closure . body ) ;
61
+ self . check_closure ( closure , expr_span , expected_kind , body, expected_sig)
66
62
}
67
63
68
- #[ instrument( skip( self , expr , body, decl ) , level = "debug" , ret) ]
64
+ #[ instrument( skip( self , closure , body) , level = "debug" , ret) ]
69
65
fn check_closure (
70
66
& self ,
71
- expr : & hir:: Expr < ' _ > ,
67
+ closure : & hir:: Closure < ' tcx > ,
68
+ expr_span : Span ,
72
69
opt_kind : Option < ty:: ClosureKind > ,
73
- decl : & ' tcx hir:: FnDecl < ' tcx > ,
74
70
body : & ' tcx hir:: Body < ' tcx > ,
75
- gen : Option < hir:: Movability > ,
76
71
expected_sig : Option < ExpectedSig < ' tcx > > ,
77
72
) -> Ty < ' tcx > {
78
- trace ! ( "decl = {:#?}" , decl ) ;
79
- let expr_def_id = self . tcx . hir ( ) . local_def_id ( expr . hir_id ) ;
73
+ trace ! ( "decl = {:#?}" , closure . fn_decl ) ;
74
+ let expr_def_id = closure . def_id ;
80
75
debug ! ( ?expr_def_id) ;
81
76
82
77
let ClosureSignatures { bound_sig, liberated_sig } =
83
- self . sig_of_closure ( expr . hir_id , expr_def_id. to_def_id ( ) , decl , body, expected_sig) ;
78
+ self . sig_of_closure ( expr_def_id, closure . fn_decl , body, expected_sig) ;
84
79
85
80
debug ! ( ?bound_sig, ?liberated_sig) ;
86
81
87
82
let generator_types = check_fn (
88
83
self ,
89
84
self . param_env . without_const ( ) ,
90
85
liberated_sig,
91
- decl ,
92
- expr . hir_id ,
86
+ closure . fn_decl ,
87
+ expr_def_id ,
93
88
body,
94
- gen ,
89
+ closure . movability ,
95
90
)
96
91
. 1 ;
97
92
@@ -102,7 +97,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
102
97
103
98
let tupled_upvars_ty = self . next_ty_var ( TypeVariableOrigin {
104
99
kind : TypeVariableOriginKind :: ClosureSynthetic ,
105
- span : self . tcx . hir ( ) . span ( expr . hir_id ) ,
100
+ span : self . tcx . def_span ( expr_def_id ) ,
106
101
} ) ;
107
102
108
103
if let Some ( GeneratorTypes { resume_ty, yield_ty, interior, movability } ) = generator_types
@@ -148,7 +143,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
148
143
None => self . next_ty_var ( TypeVariableOrigin {
149
144
// FIXME(eddyb) distinguish closure kind inference variables from the rest.
150
145
kind : TypeVariableOriginKind :: ClosureSynthetic ,
151
- span : expr . span ,
146
+ span : expr_span ,
152
147
} ) ,
153
148
} ;
154
149
@@ -342,30 +337,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
342
337
343
338
fn sig_of_closure (
344
339
& self ,
345
- hir_id : hir:: HirId ,
346
- expr_def_id : DefId ,
340
+ expr_def_id : LocalDefId ,
347
341
decl : & hir:: FnDecl < ' _ > ,
348
342
body : & hir:: Body < ' _ > ,
349
343
expected_sig : Option < ExpectedSig < ' tcx > > ,
350
344
) -> ClosureSignatures < ' tcx > {
351
345
if let Some ( e) = expected_sig {
352
- self . sig_of_closure_with_expectation ( hir_id , expr_def_id, decl, body, e)
346
+ self . sig_of_closure_with_expectation ( expr_def_id, decl, body, e)
353
347
} else {
354
- self . sig_of_closure_no_expectation ( hir_id , expr_def_id, decl, body)
348
+ self . sig_of_closure_no_expectation ( expr_def_id, decl, body)
355
349
}
356
350
}
357
351
358
352
/// If there is no expected signature, then we will convert the
359
353
/// types that the user gave into a signature.
360
- #[ instrument( skip( self , hir_id , expr_def_id, decl, body) , level = "debug" ) ]
354
+ #[ instrument( skip( self , expr_def_id, decl, body) , level = "debug" ) ]
361
355
fn sig_of_closure_no_expectation (
362
356
& self ,
363
- hir_id : hir:: HirId ,
364
- expr_def_id : DefId ,
357
+ expr_def_id : LocalDefId ,
365
358
decl : & hir:: FnDecl < ' _ > ,
366
359
body : & hir:: Body < ' _ > ,
367
360
) -> ClosureSignatures < ' tcx > {
368
- let bound_sig = self . supplied_sig_of_closure ( hir_id , expr_def_id, decl, body) ;
361
+ let bound_sig = self . supplied_sig_of_closure ( expr_def_id, decl, body) ;
369
362
370
363
self . closure_sigs ( expr_def_id, body, bound_sig)
371
364
}
@@ -411,17 +404,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
411
404
///
412
405
/// # Arguments
413
406
///
414
- /// - `expr_def_id`: the `DefId ` of the closure expression
407
+ /// - `expr_def_id`: the `LocalDefId ` of the closure expression
415
408
/// - `decl`: the HIR declaration of the closure
416
409
/// - `body`: the body of the closure
417
410
/// - `expected_sig`: the expected signature (if any). Note that
418
411
/// this is missing a binder: that is, there may be late-bound
419
412
/// regions with depth 1, which are bound then by the closure.
420
- #[ instrument( skip( self , hir_id , expr_def_id, decl, body) , level = "debug" ) ]
413
+ #[ instrument( skip( self , expr_def_id, decl, body) , level = "debug" ) ]
421
414
fn sig_of_closure_with_expectation (
422
415
& self ,
423
- hir_id : hir:: HirId ,
424
- expr_def_id : DefId ,
416
+ expr_def_id : LocalDefId ,
425
417
decl : & hir:: FnDecl < ' _ > ,
426
418
body : & hir:: Body < ' _ > ,
427
419
expected_sig : ExpectedSig < ' tcx > ,
@@ -430,7 +422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
430
422
// expectation if things don't see to match up with what we
431
423
// expect.
432
424
if expected_sig. sig . c_variadic ( ) != decl. c_variadic {
433
- return self . sig_of_closure_no_expectation ( hir_id , expr_def_id, decl, body) ;
425
+ return self . sig_of_closure_no_expectation ( expr_def_id, decl, body) ;
434
426
} else if expected_sig. sig . skip_binder ( ) . inputs_and_output . len ( ) != decl. inputs . len ( ) + 1 {
435
427
return self . sig_of_closure_with_mismatched_number_of_arguments (
436
428
expr_def_id,
@@ -466,27 +458,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
466
458
// Along the way, it also writes out entries for types that the user
467
459
// wrote into our typeck results, which are then later used by the privacy
468
460
// check.
469
- match self . merge_supplied_sig_with_expectation (
470
- hir_id,
471
- expr_def_id,
472
- decl,
473
- body,
474
- closure_sigs,
475
- ) {
461
+ match self . merge_supplied_sig_with_expectation ( expr_def_id, decl, body, closure_sigs) {
476
462
Ok ( infer_ok) => self . register_infer_ok_obligations ( infer_ok) ,
477
- Err ( _) => self . sig_of_closure_no_expectation ( hir_id , expr_def_id, decl, body) ,
463
+ Err ( _) => self . sig_of_closure_no_expectation ( expr_def_id, decl, body) ,
478
464
}
479
465
}
480
466
481
467
fn sig_of_closure_with_mismatched_number_of_arguments (
482
468
& self ,
483
- expr_def_id : DefId ,
469
+ expr_def_id : LocalDefId ,
484
470
decl : & hir:: FnDecl < ' _ > ,
485
471
body : & hir:: Body < ' _ > ,
486
472
expected_sig : ExpectedSig < ' tcx > ,
487
473
) -> ClosureSignatures < ' tcx > {
488
474
let hir = self . tcx . hir ( ) ;
489
- let expr_map_node = hir. get_if_local ( expr_def_id) . unwrap ( ) ;
475
+ let expr_map_node = hir. get_by_def_id ( expr_def_id) ;
490
476
let expected_args: Vec < _ > = expected_sig
491
477
. sig
492
478
. skip_binder ( )
@@ -499,7 +485,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
499
485
None => ( None , Vec :: new ( ) ) ,
500
486
} ;
501
487
let expected_span =
502
- expected_sig. cause_span . unwrap_or_else ( || hir . span_if_local ( expr_def_id ) . unwrap ( ) ) ;
488
+ expected_sig. cause_span . unwrap_or_else ( || self . tcx . def_span ( expr_def_id ) ) ;
503
489
self . report_arg_count_mismatch (
504
490
expected_span,
505
491
closure_span,
@@ -517,11 +503,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
517
503
/// Enforce the user's types against the expectation. See
518
504
/// `sig_of_closure_with_expectation` for details on the overall
519
505
/// strategy.
520
- #[ instrument( level = "debug" , skip( self , hir_id , expr_def_id, decl, body, expected_sigs) ) ]
506
+ #[ instrument( level = "debug" , skip( self , expr_def_id, decl, body, expected_sigs) ) ]
521
507
fn merge_supplied_sig_with_expectation (
522
508
& self ,
523
- hir_id : hir:: HirId ,
524
- expr_def_id : DefId ,
509
+ expr_def_id : LocalDefId ,
525
510
decl : & hir:: FnDecl < ' _ > ,
526
511
body : & hir:: Body < ' _ > ,
527
512
mut expected_sigs : ClosureSignatures < ' tcx > ,
@@ -530,7 +515,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
530
515
//
531
516
// (See comment on `sig_of_closure_with_expectation` for the
532
517
// meaning of these letters.)
533
- let supplied_sig = self . supplied_sig_of_closure ( hir_id , expr_def_id, decl, body) ;
518
+ let supplied_sig = self . supplied_sig_of_closure ( expr_def_id, decl, body) ;
534
519
535
520
debug ! ( ?supplied_sig) ;
536
521
@@ -610,8 +595,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
610
595
#[ instrument( skip( self , decl, body) , level = "debug" , ret) ]
611
596
fn supplied_sig_of_closure (
612
597
& self ,
613
- hir_id : hir:: HirId ,
614
- expr_def_id : DefId ,
598
+ expr_def_id : LocalDefId ,
615
599
decl : & hir:: FnDecl < ' _ > ,
616
600
body : & hir:: Body < ' _ > ,
617
601
) -> ty:: PolyFnSig < ' tcx > {
@@ -620,6 +604,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
620
604
trace ! ( "decl = {:#?}" , decl) ;
621
605
debug ! ( ?body. generator_kind) ;
622
606
607
+ let hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( expr_def_id) ;
623
608
let bound_vars = self . tcx . late_bound_vars ( hir_id) ;
624
609
625
610
// First, convert the types that the user supplied (if any).
@@ -664,10 +649,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
664
649
let result = self . normalize_associated_types_in ( self . tcx . hir ( ) . span ( hir_id) , result) ;
665
650
666
651
let c_result = self . inh . infcx . canonicalize_response ( result) ;
667
- self . typeck_results
668
- . borrow_mut ( )
669
- . user_provided_sigs
670
- . insert ( expr_def_id. expect_local ( ) , c_result) ;
652
+ self . typeck_results . borrow_mut ( ) . user_provided_sigs . insert ( expr_def_id, c_result) ;
671
653
672
654
result
673
655
}
@@ -681,7 +663,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
681
663
#[ instrument( skip( self ) , level = "debug" , ret) ]
682
664
fn deduce_future_output_from_obligations (
683
665
& self ,
684
- expr_def_id : DefId ,
666
+ expr_def_id : LocalDefId ,
685
667
body_id : hir:: HirId ,
686
668
) -> Option < Ty < ' tcx > > {
687
669
let ret_coercion = self . ret_coercion . as_ref ( ) . unwrap_or_else ( || {
@@ -830,14 +812,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
830
812
831
813
fn closure_sigs (
832
814
& self ,
833
- expr_def_id : DefId ,
815
+ expr_def_id : LocalDefId ,
834
816
body : & hir:: Body < ' _ > ,
835
817
bound_sig : ty:: PolyFnSig < ' tcx > ,
836
818
) -> ClosureSignatures < ' tcx > {
837
- let liberated_sig = self . tcx ( ) . liberate_late_bound_regions ( expr_def_id, bound_sig) ;
819
+ let liberated_sig =
820
+ self . tcx ( ) . liberate_late_bound_regions ( expr_def_id. to_def_id ( ) , bound_sig) ;
838
821
let liberated_sig = self . inh . normalize_associated_types_in (
839
822
body. value . span ,
840
- body . value . hir_id ,
823
+ self . tcx . hir ( ) . local_def_id_to_hir_id ( expr_def_id ) ,
841
824
self . param_env ,
842
825
liberated_sig,
843
826
) ;
0 commit comments