@@ -415,7 +415,7 @@ pub(crate) enum AliasPossibility {
415
415
}
416
416
417
417
#[ derive( Copy , Clone , Debug ) ]
418
- pub ( crate ) enum PathSource < ' a > {
418
+ pub ( crate ) enum PathSource < ' a , ' c > {
419
419
/// Type paths `Path`.
420
420
Type ,
421
421
/// Trait paths in bounds or impls.
@@ -429,7 +429,10 @@ pub(crate) enum PathSource<'a> {
429
429
/// Paths in tuple struct patterns `Path(..)`.
430
430
TupleStruct ( Span , & ' a [ Span ] ) ,
431
431
/// `m::A::B` in `<T as m::A>::B::C`.
432
- TraitItem ( Namespace ) ,
432
+ ///
433
+ /// Second field holds the "cause" of this one, i.e. the context within
434
+ /// which the trait item is resolved. Used for diagnostics.
435
+ TraitItem ( Namespace , & ' c PathSource < ' a , ' c > ) ,
433
436
/// Paths in delegation item
434
437
Delegation ,
435
438
/// An arg in a `use<'a, N>` precise-capturing bound.
@@ -440,7 +443,7 @@ pub(crate) enum PathSource<'a> {
440
443
DefineOpaques ,
441
444
}
442
445
443
- impl < ' a > PathSource < ' a > {
446
+ impl < ' a > PathSource < ' a , ' _ > {
444
447
fn namespace ( self ) -> Namespace {
445
448
match self {
446
449
PathSource :: Type
@@ -452,7 +455,7 @@ impl<'a> PathSource<'a> {
452
455
| PathSource :: TupleStruct ( ..)
453
456
| PathSource :: Delegation
454
457
| PathSource :: ReturnTypeNotation => ValueNS ,
455
- PathSource :: TraitItem ( ns) => ns,
458
+ PathSource :: TraitItem ( ns, _ ) => ns,
456
459
PathSource :: PreciseCapturingArg ( ns) => ns,
457
460
}
458
461
}
@@ -480,8 +483,9 @@ impl<'a> PathSource<'a> {
480
483
PathSource :: Trait ( _) => "trait" ,
481
484
PathSource :: Pat => "unit struct, unit variant or constant" ,
482
485
PathSource :: Struct => "struct, variant or union type" ,
483
- PathSource :: TupleStruct ( ..) => "tuple struct or tuple variant" ,
484
- PathSource :: TraitItem ( ns) => match ns {
486
+ PathSource :: TraitItem ( ValueNS , PathSource :: TupleStruct ( ..) )
487
+ | PathSource :: TupleStruct ( ..) => "tuple struct or tuple variant" ,
488
+ PathSource :: TraitItem ( ns, _) => match ns {
485
489
TypeNS => "associated type" ,
486
490
ValueNS => "method or associated constant" ,
487
491
MacroNS => bug ! ( "associated macro" ) ,
@@ -585,7 +589,7 @@ impl<'a> PathSource<'a> {
585
589
) | Res :: SelfTyParam { .. }
586
590
| Res :: SelfTyAlias { .. }
587
591
) ,
588
- PathSource :: TraitItem ( ns) => match res {
592
+ PathSource :: TraitItem ( ns, _ ) => match res {
589
593
Res :: Def ( DefKind :: AssocConst | DefKind :: AssocFn , _) if ns == ValueNS => true ,
590
594
Res :: Def ( DefKind :: AssocTy , _) if ns == TypeNS => true ,
591
595
_ => false ,
@@ -2007,7 +2011,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2007
2011
& mut self ,
2008
2012
partial_res : PartialRes ,
2009
2013
path : & [ Segment ] ,
2010
- source : PathSource < ' _ > ,
2014
+ source : PathSource < ' _ , ' _ > ,
2011
2015
path_span : Span ,
2012
2016
) {
2013
2017
let proj_start = path. len ( ) - partial_res. unresolved_segments ( ) ;
@@ -4206,7 +4210,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4206
4210
id : NodeId ,
4207
4211
qself : & Option < P < QSelf > > ,
4208
4212
path : & Path ,
4209
- source : PathSource < ' ast > ,
4213
+ source : PathSource < ' ast , ' _ > ,
4210
4214
) {
4211
4215
self . smart_resolve_path_fragment (
4212
4216
qself,
@@ -4223,7 +4227,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4223
4227
& mut self ,
4224
4228
qself : & Option < P < QSelf > > ,
4225
4229
path : & [ Segment ] ,
4226
- source : PathSource < ' ast > ,
4230
+ source : PathSource < ' ast , ' _ > ,
4227
4231
finalize : Finalize ,
4228
4232
record_partial_res : RecordPartialRes ,
4229
4233
parent_qself : Option < & QSelf > ,
@@ -4404,6 +4408,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4404
4408
path_span,
4405
4409
source. defer_to_typeck ( ) ,
4406
4410
finalize,
4411
+ source,
4407
4412
) {
4408
4413
Ok ( Some ( partial_res) ) if let Some ( res) = partial_res. full_res ( ) => {
4409
4414
// if we also have an associated type that matches the ident, stash a suggestion
@@ -4526,12 +4531,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4526
4531
span : Span ,
4527
4532
defer_to_typeck : bool ,
4528
4533
finalize : Finalize ,
4534
+ source : PathSource < ' ast , ' _ > ,
4529
4535
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4530
4536
let mut fin_res = None ;
4531
4537
4532
4538
for ( i, & ns) in [ primary_ns, TypeNS , ValueNS ] . iter ( ) . enumerate ( ) {
4533
4539
if i == 0 || ns != primary_ns {
4534
- match self . resolve_qpath ( qself, path, ns, finalize) ? {
4540
+ match self . resolve_qpath ( qself, path, ns, finalize, source ) ? {
4535
4541
Some ( partial_res)
4536
4542
if partial_res. unresolved_segments ( ) == 0 || defer_to_typeck =>
4537
4543
{
@@ -4568,6 +4574,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4568
4574
path : & [ Segment ] ,
4569
4575
ns : Namespace ,
4570
4576
finalize : Finalize ,
4577
+ source : PathSource < ' ast , ' _ > ,
4571
4578
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4572
4579
debug ! (
4573
4580
"resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})" ,
@@ -4615,7 +4622,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4615
4622
let partial_res = self . smart_resolve_path_fragment (
4616
4623
& None ,
4617
4624
& path[ ..=qself. position ] ,
4618
- PathSource :: TraitItem ( ns) ,
4625
+ PathSource :: TraitItem ( ns, & source ) ,
4619
4626
Finalize :: with_root_span ( finalize. node_id , finalize. path_span , qself. path_span ) ,
4620
4627
RecordPartialRes :: No ,
4621
4628
Some ( & qself) ,
0 commit comments