@@ -4,7 +4,7 @@ use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
44
55use hir:: def:: DefKind ;
66use rustc_hir as hir;
7- use rustc_hir:: def_id:: DefId ;
7+ use rustc_hir:: def_id:: LocalDefId ;
88use rustc_hir:: lang_items:: LangItem ;
99use rustc_hir_analysis:: astconv:: AstConv ;
1010use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
@@ -41,18 +41,14 @@ struct ClosureSignatures<'tcx> {
4141}
4242
4343impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
44- #[ instrument( skip( self , expr , _capture , decl , body_id ) , level = "debug" ) ]
44+ #[ instrument( skip( self , closure ) , level = "debug" ) ]
4545 pub fn check_expr_closure (
4646 & 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 ,
5249 expected : Expectation < ' tcx > ,
5350 ) -> Ty < ' tcx > {
54- trace ! ( "decl = {:#?}" , decl) ;
55- trace ! ( "expr = {:#?}" , expr) ;
51+ trace ! ( "decl = {:#?}" , closure. fn_decl) ;
5652
5753 // It's always helpful for inference if we know the kind of
5854 // closure sooner rather than later, so first examine the expected
@@ -61,37 +57,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6157 Some ( ty) => self . deduce_expectations_from_expected_type ( ty) ,
6258 None => ( None , None ) ,
6359 } ;
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)
6662 }
6763
68- #[ instrument( skip( self , expr , body, decl ) , level = "debug" , ret) ]
64+ #[ instrument( skip( self , closure , body) , level = "debug" , ret) ]
6965 fn check_closure (
7066 & self ,
71- expr : & hir:: Expr < ' _ > ,
67+ closure : & hir:: Closure < ' tcx > ,
68+ expr_span : Span ,
7269 opt_kind : Option < ty:: ClosureKind > ,
73- decl : & ' tcx hir:: FnDecl < ' tcx > ,
7470 body : & ' tcx hir:: Body < ' tcx > ,
75- gen : Option < hir:: Movability > ,
7671 expected_sig : Option < ExpectedSig < ' tcx > > ,
7772 ) -> 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 ;
8075 debug ! ( ?expr_def_id) ;
8176
8277 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) ;
8479
8580 debug ! ( ?bound_sig, ?liberated_sig) ;
8681
8782 let generator_types = check_fn (
8883 self ,
8984 self . param_env . without_const ( ) ,
9085 liberated_sig,
91- decl ,
92- expr . hir_id ,
86+ closure . fn_decl ,
87+ expr_def_id ,
9388 body,
94- gen ,
89+ closure . movability ,
9590 )
9691 . 1 ;
9792
@@ -102,7 +97,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10297
10398 let tupled_upvars_ty = self . next_ty_var ( TypeVariableOrigin {
10499 kind : TypeVariableOriginKind :: ClosureSynthetic ,
105- span : self . tcx . hir ( ) . span ( expr . hir_id ) ,
100+ span : self . tcx . def_span ( expr_def_id ) ,
106101 } ) ;
107102
108103 if let Some ( GeneratorTypes { resume_ty, yield_ty, interior, movability } ) = generator_types
@@ -148,7 +143,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
148143 None => self . next_ty_var ( TypeVariableOrigin {
149144 // FIXME(eddyb) distinguish closure kind inference variables from the rest.
150145 kind : TypeVariableOriginKind :: ClosureSynthetic ,
151- span : expr . span ,
146+ span : expr_span ,
152147 } ) ,
153148 } ;
154149
@@ -342,30 +337,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
342337
343338 fn sig_of_closure (
344339 & self ,
345- hir_id : hir:: HirId ,
346- expr_def_id : DefId ,
340+ expr_def_id : LocalDefId ,
347341 decl : & hir:: FnDecl < ' _ > ,
348342 body : & hir:: Body < ' _ > ,
349343 expected_sig : Option < ExpectedSig < ' tcx > > ,
350344 ) -> ClosureSignatures < ' tcx > {
351345 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)
353347 } 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)
355349 }
356350 }
357351
358352 /// If there is no expected signature, then we will convert the
359353 /// 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" ) ]
361355 fn sig_of_closure_no_expectation (
362356 & self ,
363- hir_id : hir:: HirId ,
364- expr_def_id : DefId ,
357+ expr_def_id : LocalDefId ,
365358 decl : & hir:: FnDecl < ' _ > ,
366359 body : & hir:: Body < ' _ > ,
367360 ) -> 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) ;
369362
370363 self . closure_sigs ( expr_def_id, body, bound_sig)
371364 }
@@ -411,17 +404,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
411404 ///
412405 /// # Arguments
413406 ///
414- /// - `expr_def_id`: the `DefId ` of the closure expression
407+ /// - `expr_def_id`: the `LocalDefId ` of the closure expression
415408 /// - `decl`: the HIR declaration of the closure
416409 /// - `body`: the body of the closure
417410 /// - `expected_sig`: the expected signature (if any). Note that
418411 /// this is missing a binder: that is, there may be late-bound
419412 /// 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" ) ]
421414 fn sig_of_closure_with_expectation (
422415 & self ,
423- hir_id : hir:: HirId ,
424- expr_def_id : DefId ,
416+ expr_def_id : LocalDefId ,
425417 decl : & hir:: FnDecl < ' _ > ,
426418 body : & hir:: Body < ' _ > ,
427419 expected_sig : ExpectedSig < ' tcx > ,
@@ -430,7 +422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
430422 // expectation if things don't see to match up with what we
431423 // expect.
432424 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) ;
434426 } else if expected_sig. sig . skip_binder ( ) . inputs_and_output . len ( ) != decl. inputs . len ( ) + 1 {
435427 return self . sig_of_closure_with_mismatched_number_of_arguments (
436428 expr_def_id,
@@ -466,27 +458,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
466458 // Along the way, it also writes out entries for types that the user
467459 // wrote into our typeck results, which are then later used by the privacy
468460 // 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) {
476462 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) ,
478464 }
479465 }
480466
481467 fn sig_of_closure_with_mismatched_number_of_arguments (
482468 & self ,
483- expr_def_id : DefId ,
469+ expr_def_id : LocalDefId ,
484470 decl : & hir:: FnDecl < ' _ > ,
485471 body : & hir:: Body < ' _ > ,
486472 expected_sig : ExpectedSig < ' tcx > ,
487473 ) -> ClosureSignatures < ' tcx > {
488474 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) ;
490476 let expected_args: Vec < _ > = expected_sig
491477 . sig
492478 . skip_binder ( )
@@ -499,7 +485,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
499485 None => ( None , Vec :: new ( ) ) ,
500486 } ;
501487 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 ) ) ;
503489 self . report_arg_count_mismatch (
504490 expected_span,
505491 closure_span,
@@ -517,11 +503,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
517503 /// Enforce the user's types against the expectation. See
518504 /// `sig_of_closure_with_expectation` for details on the overall
519505 /// 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) ) ]
521507 fn merge_supplied_sig_with_expectation (
522508 & self ,
523- hir_id : hir:: HirId ,
524- expr_def_id : DefId ,
509+ expr_def_id : LocalDefId ,
525510 decl : & hir:: FnDecl < ' _ > ,
526511 body : & hir:: Body < ' _ > ,
527512 mut expected_sigs : ClosureSignatures < ' tcx > ,
@@ -530,7 +515,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
530515 //
531516 // (See comment on `sig_of_closure_with_expectation` for the
532517 // 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) ;
534519
535520 debug ! ( ?supplied_sig) ;
536521
@@ -610,8 +595,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
610595 #[ instrument( skip( self , decl, body) , level = "debug" , ret) ]
611596 fn supplied_sig_of_closure (
612597 & self ,
613- hir_id : hir:: HirId ,
614- expr_def_id : DefId ,
598+ expr_def_id : LocalDefId ,
615599 decl : & hir:: FnDecl < ' _ > ,
616600 body : & hir:: Body < ' _ > ,
617601 ) -> ty:: PolyFnSig < ' tcx > {
@@ -620,6 +604,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
620604 trace ! ( "decl = {:#?}" , decl) ;
621605 debug ! ( ?body. generator_kind) ;
622606
607+ let hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( expr_def_id) ;
623608 let bound_vars = self . tcx . late_bound_vars ( hir_id) ;
624609
625610 // First, convert the types that the user supplied (if any).
@@ -664,10 +649,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
664649 let result = self . normalize_associated_types_in ( self . tcx . hir ( ) . span ( hir_id) , result) ;
665650
666651 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) ;
671653
672654 result
673655 }
@@ -681,7 +663,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
681663 #[ instrument( skip( self ) , level = "debug" , ret) ]
682664 fn deduce_future_output_from_obligations (
683665 & self ,
684- expr_def_id : DefId ,
666+ expr_def_id : LocalDefId ,
685667 body_id : hir:: HirId ,
686668 ) -> Option < Ty < ' tcx > > {
687669 let ret_coercion = self . ret_coercion . as_ref ( ) . unwrap_or_else ( || {
@@ -830,14 +812,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
830812
831813 fn closure_sigs (
832814 & self ,
833- expr_def_id : DefId ,
815+ expr_def_id : LocalDefId ,
834816 body : & hir:: Body < ' _ > ,
835817 bound_sig : ty:: PolyFnSig < ' tcx > ,
836818 ) -> 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) ;
838821 let liberated_sig = self . inh . normalize_associated_types_in (
839822 body. value . span ,
840- body . value . hir_id ,
823+ self . tcx . hir ( ) . local_def_id_to_hir_id ( expr_def_id ) ,
841824 self . param_env ,
842825 liberated_sig,
843826 ) ;
0 commit comments