@@ -43,7 +43,7 @@ struct CheckWfFcxBuilder<'tcx> {
4343impl < ' tcx > CheckWfFcxBuilder < ' tcx > {
4444 fn with_fcx < F > ( & mut self , f : F )
4545 where
46- F : for < ' b > FnOnce ( & FnCtxt < ' b , ' tcx > , TyCtxt < ' tcx > ) -> Vec < Ty < ' tcx > > ,
46+ F : for < ' b > FnOnce ( & FnCtxt < ' b , ' tcx > ) -> Vec < Ty < ' tcx > > ,
4747 {
4848 let id = self . id ;
4949 let span = self . span ;
@@ -56,7 +56,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> {
5656 // empty `param_env`.
5757 check_false_global_bounds ( & fcx, span, id) ;
5858 }
59- let wf_tys = f ( & fcx, fcx . tcx ) ;
59+ let wf_tys = f ( & fcx) ;
6060 fcx. select_all_obligations_or_error ( ) ;
6161 fcx. regionck_item ( id, span, & wf_tys) ;
6262 } ) ;
@@ -388,7 +388,7 @@ fn check_associated_item(
388388 debug ! ( "check_associated_item: {:?}" , item_id) ;
389389
390390 let code = ObligationCauseCode :: MiscObligation ;
391- for_id ( tcx, item_id, span) . with_fcx ( |fcx, tcx | {
391+ for_id ( tcx, item_id, span) . with_fcx ( |fcx| {
392392 let item = fcx. tcx . associated_item ( fcx. tcx . hir ( ) . local_def_id ( item_id) ) ;
393393
394394 let ( mut implied_bounds, self_ty) = match item. container {
@@ -409,7 +409,6 @@ fn check_associated_item(
409409 let sig = fcx. normalize_associated_types_in ( span, sig) ;
410410 let hir_sig = sig_if_method. expect ( "bad signature for method" ) ;
411411 check_fn_or_method (
412- tcx,
413412 fcx,
414413 item. ident . span ,
415414 sig,
@@ -467,25 +466,24 @@ fn check_type_defn<'tcx, F>(
467466) where
468467 F : for < ' fcx > FnMut ( & FnCtxt < ' fcx , ' tcx > ) -> Vec < AdtVariant < ' tcx > > ,
469468{
470- for_item ( tcx, item) . with_fcx ( |fcx, fcx_tcx | {
469+ for_item ( tcx, item) . with_fcx ( |fcx| {
471470 let variants = lookup_fields ( fcx) ;
472- let packed = fcx . tcx . adt_def ( item. def_id ) . repr . packed ( ) ;
471+ let packed = tcx. adt_def ( item. def_id ) . repr . packed ( ) ;
473472
474473 for variant in & variants {
475474 // For DST, or when drop needs to copy things around, all
476475 // intermediate types must be sized.
477476 let needs_drop_copy = || {
478477 packed && {
479478 let ty = variant. fields . last ( ) . unwrap ( ) . ty ;
480- let ty = fcx . tcx . erase_regions ( ty) ;
479+ let ty = tcx. erase_regions ( ty) ;
481480 if ty. needs_infer ( ) {
482- fcx_tcx
483- . sess
481+ tcx. sess
484482 . delay_span_bug ( item. span , & format ! ( "inference variables in {:?}" , ty) ) ;
485483 // Just treat unresolved type expression as if it needs drop.
486484 true
487485 } else {
488- ty. needs_drop ( fcx_tcx , fcx_tcx . param_env ( item. def_id ) )
486+ ty. needs_drop ( tcx , tcx . param_env ( item. def_id ) )
489487 }
490488 }
491489 } ;
@@ -497,7 +495,7 @@ fn check_type_defn<'tcx, F>(
497495 let last = idx == variant. fields . len ( ) - 1 ;
498496 fcx. register_bound (
499497 field. ty ,
500- fcx . tcx . require_lang_item ( LangItem :: Sized , None ) ,
498+ tcx. require_lang_item ( LangItem :: Sized , None ) ,
501499 traits:: ObligationCause :: new (
502500 field. span ,
503501 fcx. body_id ,
@@ -524,11 +522,10 @@ fn check_type_defn<'tcx, F>(
524522
525523 // Explicit `enum` discriminant values must const-evaluate successfully.
526524 if let Some ( discr_def_id) = variant. explicit_discr {
527- let discr_substs =
528- InternalSubsts :: identity_for_item ( fcx. tcx , discr_def_id. to_def_id ( ) ) ;
525+ let discr_substs = InternalSubsts :: identity_for_item ( tcx, discr_def_id. to_def_id ( ) ) ;
529526
530527 let cause = traits:: ObligationCause :: new (
531- fcx . tcx . def_span ( discr_def_id) ,
528+ tcx. def_span ( discr_def_id) ,
532529 fcx. body_id ,
533530 traits:: MiscObligation ,
534531 ) ;
@@ -539,12 +536,12 @@ fn check_type_defn<'tcx, F>(
539536 ty:: WithOptConstParam :: unknown ( discr_def_id. to_def_id ( ) ) ,
540537 discr_substs,
541538 )
542- . to_predicate ( fcx . tcx ) ,
539+ . to_predicate ( tcx) ,
543540 ) ) ;
544541 }
545542 }
546543
547- check_where_clauses ( tcx , fcx, item. span , item. def_id . to_def_id ( ) , None ) ;
544+ check_where_clauses ( fcx, item. span , item. def_id . to_def_id ( ) , None ) ;
548545
549546 // No implied bounds in a struct definition.
550547 vec ! [ ]
@@ -569,8 +566,9 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
569566 }
570567 }
571568
572- for_item ( tcx, item) . with_fcx ( |fcx, _| {
573- check_where_clauses ( tcx, fcx, item. span , item. def_id . to_def_id ( ) , None ) ;
569+ // FIXME: this shouldn't use an `FnCtxt` at all.
570+ for_item ( tcx, item) . with_fcx ( |fcx| {
571+ check_where_clauses ( fcx, item. span , item. def_id . to_def_id ( ) , None ) ;
574572
575573 vec ! [ ]
576574 } ) ;
@@ -610,28 +608,20 @@ fn check_item_fn(
610608 span : Span ,
611609 decl : & hir:: FnDecl < ' _ > ,
612610) {
613- for_id ( tcx, item_id, span) . with_fcx ( |fcx, tcx | {
614- let def_id = fcx . tcx . hir ( ) . local_def_id ( item_id) ;
615- let sig = fcx . tcx . fn_sig ( def_id) ;
611+ for_id ( tcx, item_id, span) . with_fcx ( |fcx| {
612+ let def_id = tcx. hir ( ) . local_def_id ( item_id) ;
613+ let sig = tcx. fn_sig ( def_id) ;
616614 let sig = fcx. normalize_associated_types_in ( span, sig) ;
617615 let mut implied_bounds = vec ! [ ] ;
618- check_fn_or_method (
619- tcx,
620- fcx,
621- ident. span ,
622- sig,
623- decl,
624- def_id. to_def_id ( ) ,
625- & mut implied_bounds,
626- ) ;
616+ check_fn_or_method ( fcx, ident. span , sig, decl, def_id. to_def_id ( ) , & mut implied_bounds) ;
627617 implied_bounds
628618 } )
629619}
630620
631621fn check_item_type ( tcx : TyCtxt < ' _ > , item_id : hir:: HirId , ty_span : Span , allow_foreign_ty : bool ) {
632622 debug ! ( "check_item_type: {:?}" , item_id) ;
633623
634- for_id ( tcx, item_id, ty_span) . with_fcx ( |fcx, tcx | {
624+ for_id ( tcx, item_id, ty_span) . with_fcx ( |fcx| {
635625 let ty = tcx. type_of ( tcx. hir ( ) . local_def_id ( item_id) ) ;
636626 let item_ty = fcx. normalize_associated_types_in ( ty_span, ty) ;
637627
@@ -647,7 +637,7 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: hir::HirId, ty_span: Span, allow_fo
647637 if forbid_unsized {
648638 fcx. register_bound (
649639 item_ty,
650- fcx . tcx . require_lang_item ( LangItem :: Sized , None ) ,
640+ tcx. require_lang_item ( LangItem :: Sized , None ) ,
651641 traits:: ObligationCause :: new ( ty_span, fcx. body_id , traits:: MiscObligation ) ,
652642 ) ;
653643 }
@@ -665,13 +655,13 @@ fn check_impl<'tcx>(
665655) {
666656 debug ! ( "check_impl: {:?}" , item) ;
667657
668- for_item ( tcx, item) . with_fcx ( |fcx, tcx | {
658+ for_item ( tcx, item) . with_fcx ( |fcx| {
669659 match * ast_trait_ref {
670660 Some ( ref ast_trait_ref) => {
671661 // `#[rustc_reservation_impl]` impls are not real impls and
672662 // therefore don't need to be WF (the trait's `Self: Trait` predicate
673663 // won't hold).
674- let trait_ref = fcx . tcx . impl_trait_ref ( item. def_id ) . unwrap ( ) ;
664+ let trait_ref = tcx. impl_trait_ref ( item. def_id ) . unwrap ( ) ;
675665 let trait_ref =
676666 fcx. normalize_associated_types_in ( ast_trait_ref. path . span , trait_ref) ;
677667 let obligations = traits:: wf:: trait_obligations (
@@ -687,7 +677,7 @@ fn check_impl<'tcx>(
687677 }
688678 }
689679 None => {
690- let self_ty = fcx . tcx . type_of ( item. def_id ) ;
680+ let self_ty = tcx. type_of ( item. def_id ) ;
691681 let self_ty = fcx. normalize_associated_types_in ( item. span , self_ty) ;
692682 fcx. register_wf_obligation (
693683 self_ty. into ( ) ,
@@ -697,23 +687,23 @@ fn check_impl<'tcx>(
697687 }
698688 }
699689
700- check_where_clauses ( tcx , fcx, item. span , item. def_id . to_def_id ( ) , None ) ;
690+ check_where_clauses ( fcx, item. span , item. def_id . to_def_id ( ) , None ) ;
701691
702692 fcx. impl_implied_bounds ( item. def_id . to_def_id ( ) , item. span )
703693 } ) ;
704694}
705695
706696/// Checks where-clauses and inline bounds that are declared on `def_id`.
707697fn check_where_clauses < ' tcx , ' fcx > (
708- tcx : TyCtxt < ' tcx > ,
709698 fcx : & FnCtxt < ' fcx , ' tcx > ,
710699 span : Span ,
711700 def_id : DefId ,
712701 return_ty : Option < ( Ty < ' tcx > , Span ) > ,
713702) {
714703 debug ! ( "check_where_clauses(def_id={:?}, return_ty={:?})" , def_id, return_ty) ;
704+ let tcx = fcx. tcx ;
715705
716- let predicates = fcx . tcx . predicates_of ( def_id) ;
706+ let predicates = tcx. predicates_of ( def_id) ;
717707 let generics = tcx. generics_of ( def_id) ;
718708
719709 let is_our_default = |def : & ty:: GenericParamDef | match def. kind {
@@ -734,14 +724,14 @@ fn check_where_clauses<'tcx, 'fcx>(
734724 match param. kind {
735725 GenericParamDefKind :: Type { .. } => {
736726 if is_our_default ( & param) {
737- let ty = fcx . tcx . type_of ( param. def_id ) ;
727+ let ty = tcx. type_of ( param. def_id ) ;
738728 // Ignore dependent defaults -- that is, where the default of one type
739729 // parameter includes another (e.g., `<T, U = T>`). In those cases, we can't
740730 // be sure if it will error or not as user might always specify the other.
741731 if !ty. needs_subst ( ) {
742732 fcx. register_wf_obligation (
743733 ty. into ( ) ,
744- fcx . tcx . def_span ( param. def_id ) ,
734+ tcx. def_span ( param. def_id ) ,
745735 ObligationCauseCode :: MiscObligation ,
746736 ) ;
747737 }
@@ -754,7 +744,7 @@ fn check_where_clauses<'tcx, 'fcx>(
754744 let default_ct = tcx. const_param_default ( param. def_id ) ;
755745 fcx. register_wf_obligation (
756746 default_ct. into ( ) ,
757- fcx . tcx . def_span ( param. def_id ) ,
747+ tcx. def_span ( param. def_id ) ,
758748 ObligationCauseCode :: MiscObligation ,
759749 ) ;
760750 }
@@ -772,25 +762,25 @@ fn check_where_clauses<'tcx, 'fcx>(
772762 // For more examples see tests `defaults-well-formedness.rs` and `type-check-defaults.rs`.
773763 //
774764 // First we build the defaulted substitution.
775- let substs = InternalSubsts :: for_item ( fcx . tcx , def_id, |param, _| {
765+ let substs = InternalSubsts :: for_item ( tcx, def_id, |param, _| {
776766 match param. kind {
777767 GenericParamDefKind :: Lifetime => {
778768 // All regions are identity.
779- fcx . tcx . mk_param_from_def ( param)
769+ tcx. mk_param_from_def ( param)
780770 }
781771
782772 GenericParamDefKind :: Type { .. } => {
783773 // If the param has a default, ...
784774 if is_our_default ( param) {
785- let default_ty = fcx . tcx . type_of ( param. def_id ) ;
775+ let default_ty = tcx. type_of ( param. def_id ) ;
786776 // ... and it's not a dependent default, ...
787777 if !default_ty. needs_subst ( ) {
788778 // ... then substitute it with the default.
789779 return default_ty. into ( ) ;
790780 }
791781 }
792782
793- fcx . tcx . mk_param_from_def ( param)
783+ tcx. mk_param_from_def ( param)
794784 }
795785 GenericParamDefKind :: Const { .. } => {
796786 // FIXME(const_generics_defaults): I(@lcnr) feel like always
@@ -811,7 +801,7 @@ fn check_where_clauses<'tcx, 'fcx>(
811801 }
812802 }
813803
814- fcx . tcx . mk_param_from_def ( param)
804+ tcx. mk_param_from_def ( param)
815805 }
816806 }
817807 } ) ;
@@ -848,7 +838,7 @@ fn check_where_clauses<'tcx, 'fcx>(
848838 }
849839 let mut param_count = CountParams :: default ( ) ;
850840 let has_region = pred. visit_with ( & mut param_count) . is_break ( ) ;
851- let substituted_pred = pred. subst ( fcx . tcx , substs) ;
841+ let substituted_pred = pred. subst ( tcx, substs) ;
852842 // Don't check non-defaulted params, dependent defaults (including lifetimes)
853843 // or preds with multiple params.
854844 if substituted_pred. has_param_types_or_consts ( )
@@ -879,14 +869,14 @@ fn check_where_clauses<'tcx, 'fcx>(
879869 traits:: Obligation :: new ( cause, fcx. param_env , pred)
880870 } ) ;
881871
882- let predicates = predicates. instantiate_identity ( fcx . tcx ) ;
872+ let predicates = predicates. instantiate_identity ( tcx) ;
883873
884874 if let Some ( ( mut return_ty, span) ) = return_ty {
885875 if return_ty. has_infer_types_or_consts ( ) {
886876 fcx. select_obligations_where_possible ( false , |_| { } ) ;
887877 return_ty = fcx. resolve_vars_if_possible ( return_ty) ;
888878 }
889- check_opaque_types ( tcx , fcx, def_id. expect_local ( ) , span, return_ty) ;
879+ check_opaque_types ( fcx, def_id. expect_local ( ) , span, return_ty) ;
890880 }
891881
892882 let predicates = fcx. normalize_associated_types_in ( span, predicates) ;
@@ -905,7 +895,6 @@ fn check_where_clauses<'tcx, 'fcx>(
905895}
906896
907897fn check_fn_or_method < ' fcx , ' tcx > (
908- tcx : TyCtxt < ' tcx > ,
909898 fcx : & FnCtxt < ' fcx , ' tcx > ,
910899 span : Span ,
911900 sig : ty:: PolyFnSig < ' tcx > ,
@@ -930,7 +919,7 @@ fn check_fn_or_method<'fcx, 'tcx>(
930919 // FIXME(#25759) return types should not be implied bounds
931920 implied_bounds. push ( sig. output ( ) ) ;
932921
933- check_where_clauses ( tcx , fcx, span, def_id, Some ( ( sig. output ( ) , hir_decl. output . span ( ) ) ) ) ;
922+ check_where_clauses ( fcx, span, def_id, Some ( ( sig. output ( ) , hir_decl. output . span ( ) ) ) ) ;
934923}
935924
936925/// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions
@@ -953,15 +942,16 @@ fn check_fn_or_method<'fcx, 'tcx>(
953942/// ```
954943///
955944fn check_opaque_types < ' fcx , ' tcx > (
956- tcx : TyCtxt < ' tcx > ,
957945 fcx : & FnCtxt < ' fcx , ' tcx > ,
958946 fn_def_id : LocalDefId ,
959947 span : Span ,
960948 ty : Ty < ' tcx > ,
961949) {
962- trace ! ( "check_opaque_types(ty={:?})" , ty) ;
950+ trace ! ( "check_opaque_types(fn_def_id={:?}, ty={:?})" , fn_def_id, ty) ;
951+ let tcx = fcx. tcx ;
952+
963953 ty. fold_with ( & mut ty:: fold:: BottomUpFolder {
964- tcx : fcx . tcx ,
954+ tcx,
965955 ty_op : |ty| {
966956 if let ty:: Opaque ( def_id, substs) = * ty. kind ( ) {
967957 trace ! ( "check_opaque_types: opaque_ty, {:?}, {:?}" , def_id, substs) ;
0 commit comments