@@ -43,7 +43,7 @@ struct CheckWfFcxBuilder<'tcx> {
43
43
impl < ' tcx > CheckWfFcxBuilder < ' tcx > {
44
44
fn with_fcx < F > ( & mut self , f : F )
45
45
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 > > ,
47
47
{
48
48
let id = self . id ;
49
49
let span = self . span ;
@@ -56,7 +56,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> {
56
56
// empty `param_env`.
57
57
check_false_global_bounds ( & fcx, span, id) ;
58
58
}
59
- let wf_tys = f ( & fcx, fcx . tcx ) ;
59
+ let wf_tys = f ( & fcx) ;
60
60
fcx. select_all_obligations_or_error ( ) ;
61
61
fcx. regionck_item ( id, span, & wf_tys) ;
62
62
} ) ;
@@ -388,7 +388,7 @@ fn check_associated_item(
388
388
debug ! ( "check_associated_item: {:?}" , item_id) ;
389
389
390
390
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| {
392
392
let item = fcx. tcx . associated_item ( fcx. tcx . hir ( ) . local_def_id ( item_id) ) ;
393
393
394
394
let ( mut implied_bounds, self_ty) = match item. container {
@@ -409,7 +409,6 @@ fn check_associated_item(
409
409
let sig = fcx. normalize_associated_types_in ( span, sig) ;
410
410
let hir_sig = sig_if_method. expect ( "bad signature for method" ) ;
411
411
check_fn_or_method (
412
- tcx,
413
412
fcx,
414
413
item. ident . span ,
415
414
sig,
@@ -467,25 +466,24 @@ fn check_type_defn<'tcx, F>(
467
466
) where
468
467
F : for < ' fcx > FnMut ( & FnCtxt < ' fcx , ' tcx > ) -> Vec < AdtVariant < ' tcx > > ,
469
468
{
470
- for_item ( tcx, item) . with_fcx ( |fcx, fcx_tcx | {
469
+ for_item ( tcx, item) . with_fcx ( |fcx| {
471
470
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 ( ) ;
473
472
474
473
for variant in & variants {
475
474
// For DST, or when drop needs to copy things around, all
476
475
// intermediate types must be sized.
477
476
let needs_drop_copy = || {
478
477
packed && {
479
478
let ty = variant. fields . last ( ) . unwrap ( ) . ty ;
480
- let ty = fcx . tcx . erase_regions ( ty) ;
479
+ let ty = tcx. erase_regions ( ty) ;
481
480
if ty. needs_infer ( ) {
482
- fcx_tcx
483
- . sess
481
+ tcx. sess
484
482
. delay_span_bug ( item. span , & format ! ( "inference variables in {:?}" , ty) ) ;
485
483
// Just treat unresolved type expression as if it needs drop.
486
484
true
487
485
} 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 ) )
489
487
}
490
488
}
491
489
} ;
@@ -497,7 +495,7 @@ fn check_type_defn<'tcx, F>(
497
495
let last = idx == variant. fields . len ( ) - 1 ;
498
496
fcx. register_bound (
499
497
field. ty ,
500
- fcx . tcx . require_lang_item ( LangItem :: Sized , None ) ,
498
+ tcx. require_lang_item ( LangItem :: Sized , None ) ,
501
499
traits:: ObligationCause :: new (
502
500
field. span ,
503
501
fcx. body_id ,
@@ -524,11 +522,10 @@ fn check_type_defn<'tcx, F>(
524
522
525
523
// Explicit `enum` discriminant values must const-evaluate successfully.
526
524
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 ( ) ) ;
529
526
530
527
let cause = traits:: ObligationCause :: new (
531
- fcx . tcx . def_span ( discr_def_id) ,
528
+ tcx. def_span ( discr_def_id) ,
532
529
fcx. body_id ,
533
530
traits:: MiscObligation ,
534
531
) ;
@@ -539,12 +536,12 @@ fn check_type_defn<'tcx, F>(
539
536
ty:: WithOptConstParam :: unknown ( discr_def_id. to_def_id ( ) ) ,
540
537
discr_substs,
541
538
)
542
- . to_predicate ( fcx . tcx ) ,
539
+ . to_predicate ( tcx) ,
543
540
) ) ;
544
541
}
545
542
}
546
543
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 ) ;
548
545
549
546
// No implied bounds in a struct definition.
550
547
vec ! [ ]
@@ -569,8 +566,9 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
569
566
}
570
567
}
571
568
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 ) ;
574
572
575
573
vec ! [ ]
576
574
} ) ;
@@ -610,28 +608,20 @@ fn check_item_fn(
610
608
span : Span ,
611
609
decl : & hir:: FnDecl < ' _ > ,
612
610
) {
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) ;
616
614
let sig = fcx. normalize_associated_types_in ( span, sig) ;
617
615
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) ;
627
617
implied_bounds
628
618
} )
629
619
}
630
620
631
621
fn check_item_type ( tcx : TyCtxt < ' _ > , item_id : hir:: HirId , ty_span : Span , allow_foreign_ty : bool ) {
632
622
debug ! ( "check_item_type: {:?}" , item_id) ;
633
623
634
- for_id ( tcx, item_id, ty_span) . with_fcx ( |fcx, tcx | {
624
+ for_id ( tcx, item_id, ty_span) . with_fcx ( |fcx| {
635
625
let ty = tcx. type_of ( tcx. hir ( ) . local_def_id ( item_id) ) ;
636
626
let item_ty = fcx. normalize_associated_types_in ( ty_span, ty) ;
637
627
@@ -647,7 +637,7 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: hir::HirId, ty_span: Span, allow_fo
647
637
if forbid_unsized {
648
638
fcx. register_bound (
649
639
item_ty,
650
- fcx . tcx . require_lang_item ( LangItem :: Sized , None ) ,
640
+ tcx. require_lang_item ( LangItem :: Sized , None ) ,
651
641
traits:: ObligationCause :: new ( ty_span, fcx. body_id , traits:: MiscObligation ) ,
652
642
) ;
653
643
}
@@ -665,13 +655,13 @@ fn check_impl<'tcx>(
665
655
) {
666
656
debug ! ( "check_impl: {:?}" , item) ;
667
657
668
- for_item ( tcx, item) . with_fcx ( |fcx, tcx | {
658
+ for_item ( tcx, item) . with_fcx ( |fcx| {
669
659
match * ast_trait_ref {
670
660
Some ( ref ast_trait_ref) => {
671
661
// `#[rustc_reservation_impl]` impls are not real impls and
672
662
// therefore don't need to be WF (the trait's `Self: Trait` predicate
673
663
// 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 ( ) ;
675
665
let trait_ref =
676
666
fcx. normalize_associated_types_in ( ast_trait_ref. path . span , trait_ref) ;
677
667
let obligations = traits:: wf:: trait_obligations (
@@ -687,7 +677,7 @@ fn check_impl<'tcx>(
687
677
}
688
678
}
689
679
None => {
690
- let self_ty = fcx . tcx . type_of ( item. def_id ) ;
680
+ let self_ty = tcx. type_of ( item. def_id ) ;
691
681
let self_ty = fcx. normalize_associated_types_in ( item. span , self_ty) ;
692
682
fcx. register_wf_obligation (
693
683
self_ty. into ( ) ,
@@ -697,23 +687,23 @@ fn check_impl<'tcx>(
697
687
}
698
688
}
699
689
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 ) ;
701
691
702
692
fcx. impl_implied_bounds ( item. def_id . to_def_id ( ) , item. span )
703
693
} ) ;
704
694
}
705
695
706
696
/// Checks where-clauses and inline bounds that are declared on `def_id`.
707
697
fn check_where_clauses < ' tcx , ' fcx > (
708
- tcx : TyCtxt < ' tcx > ,
709
698
fcx : & FnCtxt < ' fcx , ' tcx > ,
710
699
span : Span ,
711
700
def_id : DefId ,
712
701
return_ty : Option < ( Ty < ' tcx > , Span ) > ,
713
702
) {
714
703
debug ! ( "check_where_clauses(def_id={:?}, return_ty={:?})" , def_id, return_ty) ;
704
+ let tcx = fcx. tcx ;
715
705
716
- let predicates = fcx . tcx . predicates_of ( def_id) ;
706
+ let predicates = tcx. predicates_of ( def_id) ;
717
707
let generics = tcx. generics_of ( def_id) ;
718
708
719
709
let is_our_default = |def : & ty:: GenericParamDef | match def. kind {
@@ -734,14 +724,14 @@ fn check_where_clauses<'tcx, 'fcx>(
734
724
match param. kind {
735
725
GenericParamDefKind :: Type { .. } => {
736
726
if is_our_default ( & param) {
737
- let ty = fcx . tcx . type_of ( param. def_id ) ;
727
+ let ty = tcx. type_of ( param. def_id ) ;
738
728
// Ignore dependent defaults -- that is, where the default of one type
739
729
// parameter includes another (e.g., `<T, U = T>`). In those cases, we can't
740
730
// be sure if it will error or not as user might always specify the other.
741
731
if !ty. needs_subst ( ) {
742
732
fcx. register_wf_obligation (
743
733
ty. into ( ) ,
744
- fcx . tcx . def_span ( param. def_id ) ,
734
+ tcx. def_span ( param. def_id ) ,
745
735
ObligationCauseCode :: MiscObligation ,
746
736
) ;
747
737
}
@@ -754,7 +744,7 @@ fn check_where_clauses<'tcx, 'fcx>(
754
744
let default_ct = tcx. const_param_default ( param. def_id ) ;
755
745
fcx. register_wf_obligation (
756
746
default_ct. into ( ) ,
757
- fcx . tcx . def_span ( param. def_id ) ,
747
+ tcx. def_span ( param. def_id ) ,
758
748
ObligationCauseCode :: MiscObligation ,
759
749
) ;
760
750
}
@@ -772,25 +762,25 @@ fn check_where_clauses<'tcx, 'fcx>(
772
762
// For more examples see tests `defaults-well-formedness.rs` and `type-check-defaults.rs`.
773
763
//
774
764
// 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, _| {
776
766
match param. kind {
777
767
GenericParamDefKind :: Lifetime => {
778
768
// All regions are identity.
779
- fcx . tcx . mk_param_from_def ( param)
769
+ tcx. mk_param_from_def ( param)
780
770
}
781
771
782
772
GenericParamDefKind :: Type { .. } => {
783
773
// If the param has a default, ...
784
774
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 ) ;
786
776
// ... and it's not a dependent default, ...
787
777
if !default_ty. needs_subst ( ) {
788
778
// ... then substitute it with the default.
789
779
return default_ty. into ( ) ;
790
780
}
791
781
}
792
782
793
- fcx . tcx . mk_param_from_def ( param)
783
+ tcx. mk_param_from_def ( param)
794
784
}
795
785
GenericParamDefKind :: Const { .. } => {
796
786
// FIXME(const_generics_defaults): I(@lcnr) feel like always
@@ -811,7 +801,7 @@ fn check_where_clauses<'tcx, 'fcx>(
811
801
}
812
802
}
813
803
814
- fcx . tcx . mk_param_from_def ( param)
804
+ tcx. mk_param_from_def ( param)
815
805
}
816
806
}
817
807
} ) ;
@@ -848,7 +838,7 @@ fn check_where_clauses<'tcx, 'fcx>(
848
838
}
849
839
let mut param_count = CountParams :: default ( ) ;
850
840
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) ;
852
842
// Don't check non-defaulted params, dependent defaults (including lifetimes)
853
843
// or preds with multiple params.
854
844
if substituted_pred. has_param_types_or_consts ( )
@@ -879,14 +869,14 @@ fn check_where_clauses<'tcx, 'fcx>(
879
869
traits:: Obligation :: new ( cause, fcx. param_env , pred)
880
870
} ) ;
881
871
882
- let predicates = predicates. instantiate_identity ( fcx . tcx ) ;
872
+ let predicates = predicates. instantiate_identity ( tcx) ;
883
873
884
874
if let Some ( ( mut return_ty, span) ) = return_ty {
885
875
if return_ty. has_infer_types_or_consts ( ) {
886
876
fcx. select_obligations_where_possible ( false , |_| { } ) ;
887
877
return_ty = fcx. resolve_vars_if_possible ( return_ty) ;
888
878
}
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) ;
890
880
}
891
881
892
882
let predicates = fcx. normalize_associated_types_in ( span, predicates) ;
@@ -905,7 +895,6 @@ fn check_where_clauses<'tcx, 'fcx>(
905
895
}
906
896
907
897
fn check_fn_or_method < ' fcx , ' tcx > (
908
- tcx : TyCtxt < ' tcx > ,
909
898
fcx : & FnCtxt < ' fcx , ' tcx > ,
910
899
span : Span ,
911
900
sig : ty:: PolyFnSig < ' tcx > ,
@@ -930,7 +919,7 @@ fn check_fn_or_method<'fcx, 'tcx>(
930
919
// FIXME(#25759) return types should not be implied bounds
931
920
implied_bounds. push ( sig. output ( ) ) ;
932
921
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 ( ) ) ) ) ;
934
923
}
935
924
936
925
/// 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>(
953
942
/// ```
954
943
///
955
944
fn check_opaque_types < ' fcx , ' tcx > (
956
- tcx : TyCtxt < ' tcx > ,
957
945
fcx : & FnCtxt < ' fcx , ' tcx > ,
958
946
fn_def_id : LocalDefId ,
959
947
span : Span ,
960
948
ty : Ty < ' tcx > ,
961
949
) {
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
+
963
953
ty. fold_with ( & mut ty:: fold:: BottomUpFolder {
964
- tcx : fcx . tcx ,
954
+ tcx,
965
955
ty_op : |ty| {
966
956
if let ty:: Opaque ( def_id, substs) = * ty. kind ( ) {
967
957
trace ! ( "check_opaque_types: opaque_ty, {:?}, {:?}" , def_id, substs) ;
0 commit comments