@@ -675,36 +675,57 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
675
675
)
676
676
}
677
677
678
- fn instantiate_poly_trait_ref_inner (
678
+ /// Given a trait bound like `Debug`, applies that trait bound the given self-type to construct
679
+ /// a full trait reference. The resulting trait reference is returned. This may also generate
680
+ /// auxiliary bounds, which are added to `bounds`.
681
+ ///
682
+ /// Example:
683
+ ///
684
+ /// ```ignore (illustrative)
685
+ /// poly_trait_ref = Iterator<Item = u32>
686
+ /// self_ty = Foo
687
+ /// ```
688
+ ///
689
+ /// this would return `Foo: Iterator` and add `<Foo as Iterator>::Item = u32` into `bounds`.
690
+ ///
691
+ /// **A note on binders:** against our usual convention, there is an implied binder around
692
+ /// the `self_ty` and `poly_trait_ref` parameters here. So they may reference bound regions.
693
+ /// If for example you had `for<'a> Foo<'a>: Bar<'a>`, then the `self_ty` would be `Foo<'a>`
694
+ /// where `'a` is a bound region at depth 0. Similarly, the `poly_trait_ref` would be
695
+ /// `Bar<'a>`. The returned poly-trait-ref will have this binder instantiated explicitly,
696
+ /// however.
697
+ #[ instrument( level = "debug" , skip( self , span, constness, bounds, speculative) ) ]
698
+ pub ( crate ) fn instantiate_poly_trait_ref (
679
699
& self ,
680
- hir_id : hir:: HirId ,
700
+ trait_ref : & hir:: TraitRef < ' _ > ,
681
701
span : Span ,
682
- binding_span : Option < Span > ,
683
702
constness : ty:: BoundConstness ,
684
703
polarity : ty:: ImplPolarity ,
704
+ self_ty : Ty < ' tcx > ,
685
705
bounds : & mut Bounds < ' tcx > ,
686
706
speculative : bool ,
687
- trait_ref_span : Span ,
688
- trait_def_id : DefId ,
689
- trait_segment : & hir:: PathSegment < ' _ > ,
690
- args : & GenericArgs < ' _ > ,
691
- infer_args : bool ,
692
- self_ty : Ty < ' tcx > ,
693
707
only_self_bounds : OnlySelfBounds ,
694
708
) -> GenericArgCountResult {
709
+ let trait_def_id = trait_ref. trait_def_id ( ) . unwrap_or_else ( || FatalError . raise ( ) ) ;
710
+ let trait_segment = trait_ref. path . segments . last ( ) . unwrap ( ) ;
711
+ let args = trait_segment. args ( ) ;
712
+
713
+ self . prohibit_generics ( trait_ref. path . segments . split_last ( ) . unwrap ( ) . 1 . iter ( ) , |_| { } ) ;
714
+ self . complain_about_internal_fn_trait ( span, trait_def_id, trait_segment, false ) ;
715
+
695
716
let ( generic_args, arg_count) = self . create_args_for_ast_path (
696
- trait_ref_span ,
717
+ trait_ref . path . span ,
697
718
trait_def_id,
698
719
& [ ] ,
699
720
trait_segment,
700
721
args,
701
- infer_args,
722
+ trait_segment . infer_args ,
702
723
Some ( self_ty) ,
703
724
constness,
704
725
) ;
705
726
706
727
let tcx = self . tcx ( ) ;
707
- let bound_vars = tcx. late_bound_vars ( hir_id ) ;
728
+ let bound_vars = tcx. late_bound_vars ( trait_ref . hir_ref_id ) ;
708
729
debug ! ( ?bound_vars) ;
709
730
710
731
let assoc_bindings = self . create_assoc_bindings_for_generic_args ( args) ;
@@ -732,13 +753,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
732
753
733
754
// Specify type to assert that error was already reported in `Err` case.
734
755
let _: Result < _ , ErrorGuaranteed > = self . add_predicates_for_ast_type_binding (
735
- hir_id ,
756
+ trait_ref . hir_ref_id ,
736
757
poly_trait_ref,
737
758
binding,
738
759
bounds,
739
760
speculative,
740
761
& mut dup_bindings,
741
- binding_span . unwrap_or ( binding. span ) ,
762
+ binding. span ,
742
763
constness,
743
764
only_self_bounds,
744
765
polarity,
@@ -749,67 +770,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
749
770
arg_count
750
771
}
751
772
752
- /// Given a trait bound like `Debug`, applies that trait bound the given self-type to construct
753
- /// a full trait reference. The resulting trait reference is returned. This may also generate
754
- /// auxiliary bounds, which are added to `bounds`.
755
- ///
756
- /// Example:
757
- ///
758
- /// ```ignore (illustrative)
759
- /// poly_trait_ref = Iterator<Item = u32>
760
- /// self_ty = Foo
761
- /// ```
762
- ///
763
- /// this would return `Foo: Iterator` and add `<Foo as Iterator>::Item = u32` into `bounds`.
764
- ///
765
- /// **A note on binders:** against our usual convention, there is an implied bounder around
766
- /// the `self_ty` and `poly_trait_ref` parameters here. So they may reference bound regions.
767
- /// If for example you had `for<'a> Foo<'a>: Bar<'a>`, then the `self_ty` would be `Foo<'a>`
768
- /// where `'a` is a bound region at depth 0. Similarly, the `poly_trait_ref` would be
769
- /// `Bar<'a>`. The returned poly-trait-ref will have this binder instantiated explicitly,
770
- /// however.
771
- #[ instrument( level = "debug" , skip( self , span, constness, bounds, speculative) ) ]
772
- pub ( crate ) fn instantiate_poly_trait_ref (
773
- & self ,
774
- trait_ref : & hir:: TraitRef < ' _ > ,
775
- span : Span ,
776
- constness : ty:: BoundConstness ,
777
- polarity : ty:: ImplPolarity ,
778
- self_ty : Ty < ' tcx > ,
779
- bounds : & mut Bounds < ' tcx > ,
780
- speculative : bool ,
781
- only_self_bounds : OnlySelfBounds ,
782
- ) -> GenericArgCountResult {
783
- let hir_id = trait_ref. hir_ref_id ;
784
- let binding_span = None ;
785
- let trait_ref_span = trait_ref. path . span ;
786
- let trait_def_id = trait_ref. trait_def_id ( ) . unwrap_or_else ( || FatalError . raise ( ) ) ;
787
- let trait_segment = trait_ref. path . segments . last ( ) . unwrap ( ) ;
788
- let args = trait_segment. args ( ) ;
789
- let infer_args = trait_segment. infer_args ;
790
-
791
- self . prohibit_generics ( trait_ref. path . segments . split_last ( ) . unwrap ( ) . 1 . iter ( ) , |_| { } ) ;
792
- self . complain_about_internal_fn_trait ( span, trait_def_id, trait_segment, false ) ;
793
-
794
- // TODO: inline
795
- self . instantiate_poly_trait_ref_inner (
796
- hir_id,
797
- span,
798
- binding_span,
799
- constness,
800
- polarity,
801
- bounds,
802
- speculative,
803
- trait_ref_span,
804
- trait_def_id,
805
- trait_segment,
806
- args,
807
- infer_args,
808
- self_ty,
809
- only_self_bounds,
810
- )
811
- }
812
-
813
773
fn ast_path_to_mono_trait_ref (
814
774
& self ,
815
775
span : Span ,
0 commit comments