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