@@ -122,6 +122,12 @@ pub(crate) enum ConstantItemKind {
122
122
Static ,
123
123
}
124
124
125
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
126
+ enum RecordPartialRes {
127
+ Yes ,
128
+ No ,
129
+ }
130
+
125
131
/// The rib kind restricts certain accesses,
126
132
/// e.g. to a `Res::Local` of an outer item.
127
133
#[ derive( Copy , Clone , Debug ) ]
@@ -2682,6 +2688,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2682
2688
& path,
2683
2689
PathSource :: Trait ( AliasPossibility :: No ) ,
2684
2690
Finalize :: new ( trait_ref. ref_id , trait_ref. path . span ) ,
2691
+ RecordPartialRes :: Yes ,
2685
2692
) ;
2686
2693
self . diagnostic_metadata . currently_processing_impl_trait = None ;
2687
2694
if let Some ( def_id) = res. expect_full_res ( ) . opt_def_id ( ) {
@@ -3420,6 +3427,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3420
3427
& Segment :: from_path ( path) ,
3421
3428
source,
3422
3429
Finalize :: new ( id, path. span ) ,
3430
+ RecordPartialRes :: Yes ,
3423
3431
) ;
3424
3432
}
3425
3433
@@ -3430,6 +3438,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3430
3438
path : & [ Segment ] ,
3431
3439
source : PathSource < ' ast > ,
3432
3440
finalize : Finalize ,
3441
+ record_partial_res : RecordPartialRes ,
3433
3442
) -> PartialRes {
3434
3443
let ns = source. namespace ( ) ;
3435
3444
@@ -3636,7 +3645,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3636
3645
_ => report_errors ( self , None ) ,
3637
3646
} ;
3638
3647
3639
- if ! matches ! ( source , PathSource :: TraitItem ( .. ) ) {
3648
+ if record_partial_res == RecordPartialRes :: Yes {
3640
3649
// Avoid recording definition of `A::B` in `<T as A>::B::C`.
3641
3650
self . r . record_partial_res ( node_id, partial_res) ;
3642
3651
self . resolve_elided_lifetimes_in_path ( node_id, partial_res, path, source, path_span) ;
@@ -3740,7 +3749,25 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3740
3749
) ) ) ;
3741
3750
}
3742
3751
3743
- // Make sure `A::B` in `<T as A::B>::C` is a trait item.
3752
+ let num_privacy_errors = self . r . privacy_errors . len ( ) ;
3753
+ // Make sure that `A` in `<T as A>::B::C` is a trait.
3754
+ let trait_res = self . smart_resolve_path_fragment (
3755
+ & None ,
3756
+ & path[ ..qself. position ] ,
3757
+ PathSource :: Trait ( AliasPossibility :: No ) ,
3758
+ Finalize :: new ( finalize. node_id , qself. path_span ) ,
3759
+ RecordPartialRes :: No ,
3760
+ ) ;
3761
+
3762
+ if trait_res. expect_full_res ( ) == Res :: Err {
3763
+ return Ok ( Some ( trait_res) ) ;
3764
+ }
3765
+
3766
+ // Truncate additional privacy errors reported above,
3767
+ // because they'll be recomputed below.
3768
+ self . r . privacy_errors . truncate ( num_privacy_errors) ;
3769
+
3770
+ // Make sure `A::B` in `<T as A>::B::C` is a trait item.
3744
3771
//
3745
3772
// Currently, `path` names the full item (`A::B::C`, in
3746
3773
// our example). so we extract the prefix of that that is
@@ -3753,6 +3780,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3753
3780
& path[ ..=qself. position ] ,
3754
3781
PathSource :: TraitItem ( ns) ,
3755
3782
Finalize :: with_root_span ( finalize. node_id , finalize. path_span , qself. path_span ) ,
3783
+ RecordPartialRes :: No ,
3756
3784
) ;
3757
3785
3758
3786
// The remaining segments (the `C` in our example) will
0 commit comments