@@ -516,8 +516,15 @@ pub fn instantiate_poly_trait_ref<'tcx>(
516
516
{
517
517
let mut projections = Vec :: new ( ) ;
518
518
519
+ // the trait reference introduces a binding level here, so
520
+ // we need to shift the `rscope`. It'd be nice if we could
521
+ // do away with this rscope stuff and work this knowledge
522
+ // into resolve_lifetimes, as we do with non-omitted
523
+ // lifetimes. Oh well, not there yet.
524
+ let shifted_rscope = ShiftedRscope :: new ( rscope) ;
525
+
519
526
let trait_ref =
520
- instantiate_trait_ref ( this, rscope , & ast_trait_ref. trait_ref ,
527
+ instantiate_trait_ref ( this, & shifted_rscope , & ast_trait_ref. trait_ref ,
521
528
self_ty, Some ( & mut projections) ) ;
522
529
523
530
for projection in projections. into_iter ( ) {
@@ -561,6 +568,29 @@ pub fn instantiate_trait_ref<'tcx>(
561
568
}
562
569
}
563
570
571
+ fn object_path_to_poly_trait_ref < ' a , ' tcx > (
572
+ this : & AstConv < ' tcx > ,
573
+ rscope : & RegionScope ,
574
+ trait_def_id : ast:: DefId ,
575
+ path : & ast:: Path ,
576
+ mut projections : & mut Vec < ty:: PolyProjectionPredicate < ' tcx > > )
577
+ -> ty:: PolyTraitRef < ' tcx >
578
+ {
579
+ // we are introducing a binder here, so shift the
580
+ // anonymous regions depth to account for that
581
+ let shifted_rscope = ShiftedRscope :: new ( rscope) ;
582
+
583
+ let mut tmp = Vec :: new ( ) ;
584
+ let trait_ref = ty:: Binder ( ast_path_to_trait_ref ( this,
585
+ & shifted_rscope,
586
+ trait_def_id,
587
+ None ,
588
+ path,
589
+ Some ( & mut tmp) ) ) ;
590
+ projections. extend ( tmp. into_iter ( ) . map ( ty:: Binder ) ) ;
591
+ trait_ref
592
+ }
593
+
564
594
fn ast_path_to_trait_ref < ' a , ' tcx > (
565
595
this : & AstConv < ' tcx > ,
566
596
rscope : & RegionScope ,
@@ -573,13 +603,6 @@ fn ast_path_to_trait_ref<'a,'tcx>(
573
603
debug ! ( "ast_path_to_trait_ref {:?}" , path) ;
574
604
let trait_def = this. get_trait_def ( trait_def_id) ;
575
605
576
- // the trait reference introduces a binding level here, so
577
- // we need to shift the `rscope`. It'd be nice if we could
578
- // do away with this rscope stuff and work this knowledge
579
- // into resolve_lifetimes, as we do with non-omitted
580
- // lifetimes. Oh well, not there yet.
581
- let shifted_rscope = ShiftedRscope :: new ( rscope) ;
582
-
583
606
let ( regions, types, assoc_bindings) = match path. segments . last ( ) . unwrap ( ) . parameters {
584
607
ast:: AngleBracketedParameters ( ref data) => {
585
608
// For now, require that parenthetical notation be used
@@ -595,7 +618,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
595
618
the crate attributes to enable") ;
596
619
}
597
620
598
- convert_angle_bracketed_parameters ( this, & shifted_rscope , data)
621
+ convert_angle_bracketed_parameters ( this, rscope , data)
599
622
}
600
623
ast:: ParenthesizedParameters ( ref data) => {
601
624
// For now, require that parenthetical notation be used
@@ -616,7 +639,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
616
639
} ;
617
640
618
641
let substs = create_substs_for_ast_path ( this,
619
- & shifted_rscope ,
642
+ rscope ,
620
643
path. span ,
621
644
& trait_def. generics ,
622
645
self_ty,
@@ -851,15 +874,11 @@ fn ast_ty_to_trait_ref<'tcx>(this: &AstConv<'tcx>,
851
874
match this. tcx ( ) . def_map . borrow ( ) . get ( & id) {
852
875
Some ( & def:: DefTrait ( trait_def_id) ) => {
853
876
let mut projection_bounds = Vec :: new ( ) ;
854
- let trait_ref = ty:: Binder ( ast_path_to_trait_ref ( this,
855
- rscope,
856
- trait_def_id,
857
- None ,
858
- path,
859
- Some ( & mut projection_bounds) ) ) ;
860
- let projection_bounds = projection_bounds. into_iter ( )
861
- . map ( ty:: Binder )
862
- . collect ( ) ;
877
+ let trait_ref = object_path_to_poly_trait_ref ( this,
878
+ rscope,
879
+ trait_def_id,
880
+ path,
881
+ & mut projection_bounds) ;
863
882
Ok ( ( trait_ref, projection_bounds) )
864
883
}
865
884
_ => {
@@ -1095,16 +1114,13 @@ pub fn ast_ty_to_ty<'tcx>(
1095
1114
// N.B. this case overlaps somewhat with
1096
1115
// TyObjectSum, see that fn for details
1097
1116
let mut projection_bounds = Vec :: new ( ) ;
1098
- let trait_ref = ast_path_to_trait_ref ( this,
1099
- rscope,
1100
- trait_def_id,
1101
- None ,
1102
- path,
1103
- Some ( & mut projection_bounds) ) ;
1104
- let trait_ref = ty:: Binder ( trait_ref) ;
1105
- let projection_bounds = projection_bounds. into_iter ( )
1106
- . map ( ty:: Binder )
1107
- . collect ( ) ;
1117
+
1118
+ let trait_ref = object_path_to_poly_trait_ref ( this,
1119
+ rscope,
1120
+ trait_def_id,
1121
+ path,
1122
+ & mut projection_bounds) ;
1123
+
1108
1124
trait_ref_to_object_type ( this, rscope, path. span ,
1109
1125
trait_ref, projection_bounds, & [ ] )
1110
1126
}
0 commit comments