@@ -642,37 +642,57 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
642
642
)
643
643
}
644
644
645
- fn instantiate_poly_trait_ref_inner (
645
+ /// Given a trait bound like `Debug`, applies that trait bound the given self-type to construct
646
+ /// a full trait reference. The resulting trait reference is returned. This may also generate
647
+ /// auxiliary bounds, which are added to `bounds`.
648
+ ///
649
+ /// Example:
650
+ ///
651
+ /// ```ignore (illustrative)
652
+ /// poly_trait_ref = Iterator<Item = u32>
653
+ /// self_ty = Foo
654
+ /// ```
655
+ ///
656
+ /// this would return `Foo: Iterator` and add `<Foo as Iterator>::Item = u32` into `bounds`.
657
+ ///
658
+ /// **A note on binders:** against our usual convention, there is an implied bounder around
659
+ /// the `self_ty` and `poly_trait_ref` parameters here. So they may reference bound regions.
660
+ /// If for example you had `for<'a> Foo<'a>: Bar<'a>`, then the `self_ty` would be `Foo<'a>`
661
+ /// where `'a` is a bound region at depth 0. Similarly, the `poly_trait_ref` would be
662
+ /// `Bar<'a>`. The returned poly-trait-ref will have this binder instantiated explicitly,
663
+ /// however.
664
+ #[ instrument( level = "debug" , skip( self , span, constness, bounds, speculative) ) ]
665
+ pub ( crate ) fn instantiate_poly_trait_ref (
646
666
& self ,
647
- hir_id : hir:: HirId ,
667
+ trait_ref : & hir:: TraitRef < ' _ > ,
648
668
span : Span ,
649
- binding_span : Option < Span > ,
650
669
constness : ty:: BoundConstness ,
670
+ self_ty : Ty < ' tcx > ,
651
671
bounds : & mut Bounds < ' tcx > ,
652
672
speculative : bool ,
653
- trait_ref_span : Span ,
654
- trait_def_id : DefId ,
655
- trait_segment : & hir:: PathSegment < ' _ > ,
656
- args : & GenericArgs < ' _ > ,
657
- infer_args : bool ,
658
- self_ty : Ty < ' tcx > ,
659
673
) -> GenericArgCountResult {
674
+ let trait_def_id = trait_ref. trait_def_id ( ) . unwrap_or_else ( || FatalError . raise ( ) ) ;
675
+ let trait_segment = trait_ref. path . segments . last ( ) . unwrap ( ) ;
676
+
677
+ self . prohibit_generics ( trait_ref. path . segments . split_last ( ) . unwrap ( ) . 1 . iter ( ) , |_| { } ) ;
678
+ self . complain_about_internal_fn_trait ( span, trait_def_id, trait_segment, false ) ;
679
+
660
680
let ( substs, arg_count) = self . create_substs_for_ast_path (
661
- trait_ref_span ,
681
+ trait_ref . path . span ,
662
682
trait_def_id,
663
683
& [ ] ,
664
684
trait_segment,
665
- args,
666
- infer_args,
685
+ trait_segment . args ( ) ,
686
+ trait_segment . infer_args ,
667
687
Some ( self_ty) ,
668
688
Some ( constness) ,
669
689
) ;
670
690
671
691
let tcx = self . tcx ( ) ;
672
- let bound_vars = tcx. late_bound_vars ( hir_id ) ;
692
+ let bound_vars = tcx. late_bound_vars ( trait_ref . hir_ref_id ) ;
673
693
debug ! ( ?bound_vars) ;
674
694
675
- let assoc_bindings = self . create_assoc_bindings_for_generic_args ( args) ;
695
+ let assoc_bindings = self . create_assoc_bindings_for_generic_args ( trait_segment . args ( ) ) ;
676
696
677
697
let poly_trait_ref =
678
698
ty:: Binder :: bind_with_vars ( ty:: TraitRef :: new ( trait_def_id, substs) , bound_vars) ;
@@ -684,13 +704,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
684
704
for binding in & assoc_bindings {
685
705
// Specify type to assert that error was already reported in `Err` case.
686
706
let _: Result < _ , ErrorGuaranteed > = self . add_predicates_for_ast_type_binding (
687
- hir_id ,
707
+ trait_ref . hir_ref_id ,
688
708
poly_trait_ref,
689
709
binding,
690
710
bounds,
691
711
speculative,
692
712
& mut dup_bindings,
693
- binding_span . unwrap_or ( binding. span ) ,
713
+ binding. span ,
694
714
constness,
695
715
) ;
696
716
// Okay to ignore `Err` because of `ErrorGuaranteed` (see above).
@@ -699,95 +719,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
699
719
arg_count
700
720
}
701
721
702
- /// Given a trait bound like `Debug`, applies that trait bound the given self-type to construct
703
- /// a full trait reference. The resulting trait reference is returned. This may also generate
704
- /// auxiliary bounds, which are added to `bounds`.
705
- ///
706
- /// Example:
707
- ///
708
- /// ```ignore (illustrative)
709
- /// poly_trait_ref = Iterator<Item = u32>
710
- /// self_ty = Foo
711
- /// ```
712
- ///
713
- /// this would return `Foo: Iterator` and add `<Foo as Iterator>::Item = u32` into `bounds`.
714
- ///
715
- /// **A note on binders:** against our usual convention, there is an implied bounder around
716
- /// the `self_ty` and `poly_trait_ref` parameters here. So they may reference bound regions.
717
- /// If for example you had `for<'a> Foo<'a>: Bar<'a>`, then the `self_ty` would be `Foo<'a>`
718
- /// where `'a` is a bound region at depth 0. Similarly, the `poly_trait_ref` would be
719
- /// `Bar<'a>`. The returned poly-trait-ref will have this binder instantiated explicitly,
720
- /// however.
721
- #[ instrument( level = "debug" , skip( self , span, constness, bounds, speculative) ) ]
722
- pub ( crate ) fn instantiate_poly_trait_ref (
723
- & self ,
724
- trait_ref : & hir:: TraitRef < ' _ > ,
725
- span : Span ,
726
- constness : ty:: BoundConstness ,
727
- self_ty : Ty < ' tcx > ,
728
- bounds : & mut Bounds < ' tcx > ,
729
- speculative : bool ,
730
- ) -> GenericArgCountResult {
731
- let hir_id = trait_ref. hir_ref_id ;
732
- let binding_span = None ;
733
- let trait_ref_span = trait_ref. path . span ;
734
- let trait_def_id = trait_ref. trait_def_id ( ) . unwrap_or_else ( || FatalError . raise ( ) ) ;
735
- let trait_segment = trait_ref. path . segments . last ( ) . unwrap ( ) ;
736
- let args = trait_segment. args ( ) ;
737
- let infer_args = trait_segment. infer_args ;
738
-
739
- self . prohibit_generics ( trait_ref. path . segments . split_last ( ) . unwrap ( ) . 1 . iter ( ) , |_| { } ) ;
740
- self . complain_about_internal_fn_trait ( span, trait_def_id, trait_segment, false ) ;
741
-
742
- self . instantiate_poly_trait_ref_inner (
743
- hir_id,
744
- span,
745
- binding_span,
746
- constness,
747
- bounds,
748
- speculative,
749
- trait_ref_span,
750
- trait_def_id,
751
- trait_segment,
752
- args,
753
- infer_args,
754
- self_ty,
755
- )
756
- }
757
-
758
- pub ( crate ) fn instantiate_lang_item_trait_ref (
759
- & self ,
760
- lang_item : hir:: LangItem ,
761
- span : Span ,
762
- hir_id : hir:: HirId ,
763
- args : & GenericArgs < ' _ > ,
764
- self_ty : Ty < ' tcx > ,
765
- bounds : & mut Bounds < ' tcx > ,
766
- ) {
767
- let binding_span = Some ( span) ;
768
- let constness = ty:: BoundConstness :: NotConst ;
769
- let speculative = false ;
770
- let trait_ref_span = span;
771
- let trait_def_id = self . tcx ( ) . require_lang_item ( lang_item, Some ( span) ) ;
772
- let trait_segment = & hir:: PathSegment :: invalid ( ) ;
773
- let infer_args = false ;
774
-
775
- self . instantiate_poly_trait_ref_inner (
776
- hir_id,
777
- span,
778
- binding_span,
779
- constness,
780
- bounds,
781
- speculative,
782
- trait_ref_span,
783
- trait_def_id,
784
- trait_segment,
785
- args,
786
- infer_args,
787
- self_ty,
788
- ) ;
789
- }
790
-
791
722
fn ast_path_to_mono_trait_ref (
792
723
& self ,
793
724
span : Span ,
@@ -953,11 +884,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
953
884
false ,
954
885
) ;
955
886
}
956
- & hir:: GenericBound :: LangItemTrait ( lang_item, span, hir_id, args) => {
957
- self . instantiate_lang_item_trait_ref (
958
- lang_item, span, hir_id, args, param_ty, bounds,
959
- ) ;
960
- }
961
887
hir:: GenericBound :: Outlives ( lifetime) => {
962
888
let region = self . ast_region_to_region ( lifetime, None ) ;
963
889
bounds
0 commit comments