@@ -122,6 +122,12 @@ pub(crate) enum ConstantItemKind {
122122 Static ,
123123}
124124
125+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
126+ enum RecordPartialRes {
127+ Yes ,
128+ No ,
129+ }
130+
125131/// The rib kind restricts certain accesses,
126132/// e.g. to a `Res::Local` of an outer item.
127133#[ derive( Copy , Clone , Debug ) ]
@@ -2682,6 +2688,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26822688 & path,
26832689 PathSource :: Trait ( AliasPossibility :: No ) ,
26842690 Finalize :: new ( trait_ref. ref_id , trait_ref. path . span ) ,
2691+ RecordPartialRes :: Yes ,
26852692 ) ;
26862693 self . diagnostic_metadata . currently_processing_impl_trait = None ;
26872694 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> {
34203427 & Segment :: from_path ( path) ,
34213428 source,
34223429 Finalize :: new ( id, path. span ) ,
3430+ RecordPartialRes :: Yes ,
34233431 ) ;
34243432 }
34253433
@@ -3430,6 +3438,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
34303438 path : & [ Segment ] ,
34313439 source : PathSource < ' ast > ,
34323440 finalize : Finalize ,
3441+ record_partial_res : RecordPartialRes ,
34333442 ) -> PartialRes {
34343443 let ns = source. namespace ( ) ;
34353444
@@ -3636,7 +3645,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
36363645 _ => report_errors ( self , None ) ,
36373646 } ;
36383647
3639- if ! matches ! ( source , PathSource :: TraitItem ( .. ) ) {
3648+ if record_partial_res == RecordPartialRes :: Yes {
36403649 // Avoid recording definition of `A::B` in `<T as A>::B::C`.
36413650 self . r . record_partial_res ( node_id, partial_res) ;
36423651 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> {
37403749 ) ) ) ;
37413750 }
37423751
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.
37443771 //
37453772 // Currently, `path` names the full item (`A::B::C`, in
37463773 // 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> {
37533780 & path[ ..=qself. position ] ,
37543781 PathSource :: TraitItem ( ns) ,
37553782 Finalize :: with_root_span ( finalize. node_id , finalize. path_span , qself. path_span ) ,
3783+ RecordPartialRes :: No ,
37563784 ) ;
37573785
37583786 // The remaining segments (the `C` in our example) will
0 commit comments