@@ -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 bounder 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) ;
@@ -728,13 +749,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
728
749
729
750
// Specify type to assert that error was already reported in `Err` case.
730
751
let _: Result < _ , ErrorGuaranteed > = self . add_predicates_for_ast_type_binding (
731
- hir_id ,
752
+ trait_ref . hir_ref_id ,
732
753
poly_trait_ref,
733
754
binding,
734
755
bounds,
735
756
speculative,
736
757
& mut dup_bindings,
737
- binding_span . unwrap_or ( binding. span ) ,
758
+ binding. span ,
738
759
constness,
739
760
only_self_bounds,
740
761
polarity,
@@ -745,67 +766,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
745
766
arg_count
746
767
}
747
768
748
- /// Given a trait bound like `Debug`, applies that trait bound the given self-type to construct
749
- /// a full trait reference. The resulting trait reference is returned. This may also generate
750
- /// auxiliary bounds, which are added to `bounds`.
751
- ///
752
- /// Example:
753
- ///
754
- /// ```ignore (illustrative)
755
- /// poly_trait_ref = Iterator<Item = u32>
756
- /// self_ty = Foo
757
- /// ```
758
- ///
759
- /// this would return `Foo: Iterator` and add `<Foo as Iterator>::Item = u32` into `bounds`.
760
- ///
761
- /// **A note on binders:** against our usual convention, there is an implied bounder around
762
- /// the `self_ty` and `poly_trait_ref` parameters here. So they may reference bound regions.
763
- /// If for example you had `for<'a> Foo<'a>: Bar<'a>`, then the `self_ty` would be `Foo<'a>`
764
- /// where `'a` is a bound region at depth 0. Similarly, the `poly_trait_ref` would be
765
- /// `Bar<'a>`. The returned poly-trait-ref will have this binder instantiated explicitly,
766
- /// however.
767
- #[ instrument( level = "debug" , skip( self , span, constness, bounds, speculative) ) ]
768
- pub ( crate ) fn instantiate_poly_trait_ref (
769
- & self ,
770
- trait_ref : & hir:: TraitRef < ' _ > ,
771
- span : Span ,
772
- constness : ty:: BoundConstness ,
773
- polarity : ty:: ImplPolarity ,
774
- self_ty : Ty < ' tcx > ,
775
- bounds : & mut Bounds < ' tcx > ,
776
- speculative : bool ,
777
- only_self_bounds : OnlySelfBounds ,
778
- ) -> GenericArgCountResult {
779
- let hir_id = trait_ref. hir_ref_id ;
780
- let binding_span = None ;
781
- let trait_ref_span = trait_ref. path . span ;
782
- let trait_def_id = trait_ref. trait_def_id ( ) . unwrap_or_else ( || FatalError . raise ( ) ) ;
783
- let trait_segment = trait_ref. path . segments . last ( ) . unwrap ( ) ;
784
- let args = trait_segment. args ( ) ;
785
- let infer_args = trait_segment. infer_args ;
786
-
787
- self . prohibit_generics ( trait_ref. path . segments . split_last ( ) . unwrap ( ) . 1 . iter ( ) , |_| { } ) ;
788
- self . complain_about_internal_fn_trait ( span, trait_def_id, trait_segment, false ) ;
789
-
790
- // TODO: inline
791
- self . instantiate_poly_trait_ref_inner (
792
- hir_id,
793
- span,
794
- binding_span,
795
- constness,
796
- polarity,
797
- bounds,
798
- speculative,
799
- trait_ref_span,
800
- trait_def_id,
801
- trait_segment,
802
- args,
803
- infer_args,
804
- self_ty,
805
- only_self_bounds,
806
- )
807
- }
808
-
809
769
fn ast_path_to_mono_trait_ref (
810
770
& self ,
811
771
span : Span ,
0 commit comments