@@ -402,7 +402,7 @@ pub(crate) enum AliasPossibility {
402
402
}
403
403
404
404
#[ derive( Copy , Clone , Debug ) ]
405
- pub ( crate ) enum PathSource < ' a > {
405
+ pub ( crate ) enum PathSource < ' a , ' c > {
406
406
/// Type paths `Path`.
407
407
Type ,
408
408
/// Trait paths in bounds or impls.
@@ -416,7 +416,10 @@ pub(crate) enum PathSource<'a> {
416
416
/// Paths in tuple struct patterns `Path(..)`.
417
417
TupleStruct ( Span , & ' a [ Span ] ) ,
418
418
/// `m::A::B` in `<T as m::A>::B::C`.
419
- TraitItem ( Namespace ) ,
419
+ ///
420
+ /// Second field holds the "cause" of this one, i.e. the context within
421
+ /// which the trait item is resolved. Used for diagnostics.
422
+ TraitItem ( Namespace , & ' c PathSource < ' a , ' c > ) ,
420
423
/// Paths in delegation item
421
424
Delegation ,
422
425
/// An arg in a `use<'a, N>` precise-capturing bound.
@@ -427,7 +430,7 @@ pub(crate) enum PathSource<'a> {
427
430
DefineOpaques ,
428
431
}
429
432
430
- impl < ' a > PathSource < ' a > {
433
+ impl < ' a > PathSource < ' a , ' _ > {
431
434
fn namespace ( self ) -> Namespace {
432
435
match self {
433
436
PathSource :: Type
@@ -439,7 +442,7 @@ impl<'a> PathSource<'a> {
439
442
| PathSource :: TupleStruct ( ..)
440
443
| PathSource :: Delegation
441
444
| PathSource :: ReturnTypeNotation => ValueNS ,
442
- PathSource :: TraitItem ( ns) => ns,
445
+ PathSource :: TraitItem ( ns, _ ) => ns,
443
446
PathSource :: PreciseCapturingArg ( ns) => ns,
444
447
}
445
448
}
@@ -467,8 +470,9 @@ impl<'a> PathSource<'a> {
467
470
PathSource :: Trait ( _) => "trait" ,
468
471
PathSource :: Pat => "unit struct, unit variant or constant" ,
469
472
PathSource :: Struct => "struct, variant or union type" ,
470
- PathSource :: TupleStruct ( ..) => "tuple struct or tuple variant" ,
471
- PathSource :: TraitItem ( ns) => match ns {
473
+ PathSource :: TraitItem ( ValueNS , PathSource :: TupleStruct ( ..) )
474
+ | PathSource :: TupleStruct ( ..) => "tuple struct or tuple variant" ,
475
+ PathSource :: TraitItem ( ns, _) => match ns {
472
476
TypeNS => "associated type" ,
473
477
ValueNS => "method or associated constant" ,
474
478
MacroNS => bug ! ( "associated macro" ) ,
@@ -572,7 +576,7 @@ impl<'a> PathSource<'a> {
572
576
) | Res :: SelfTyParam { .. }
573
577
| Res :: SelfTyAlias { .. }
574
578
) ,
575
- PathSource :: TraitItem ( ns) => match res {
579
+ PathSource :: TraitItem ( ns, _ ) => match res {
576
580
Res :: Def ( DefKind :: AssocConst | DefKind :: AssocFn , _) if ns == ValueNS => true ,
577
581
Res :: Def ( DefKind :: AssocTy , _) if ns == TypeNS => true ,
578
582
_ => false ,
@@ -1983,7 +1987,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1983
1987
& mut self ,
1984
1988
partial_res : PartialRes ,
1985
1989
path : & [ Segment ] ,
1986
- source : PathSource < ' _ > ,
1990
+ source : PathSource < ' _ , ' _ > ,
1987
1991
path_span : Span ,
1988
1992
) {
1989
1993
let proj_start = path. len ( ) - partial_res. unresolved_segments ( ) ;
@@ -4135,7 +4139,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4135
4139
id : NodeId ,
4136
4140
qself : & Option < P < QSelf > > ,
4137
4141
path : & Path ,
4138
- source : PathSource < ' ast > ,
4142
+ source : PathSource < ' ast , ' _ > ,
4139
4143
) {
4140
4144
self . smart_resolve_path_fragment (
4141
4145
qself,
@@ -4152,7 +4156,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4152
4156
& mut self ,
4153
4157
qself : & Option < P < QSelf > > ,
4154
4158
path : & [ Segment ] ,
4155
- source : PathSource < ' ast > ,
4159
+ source : PathSource < ' ast , ' _ > ,
4156
4160
finalize : Finalize ,
4157
4161
record_partial_res : RecordPartialRes ,
4158
4162
parent_qself : Option < & QSelf > ,
@@ -4333,6 +4337,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4333
4337
path_span,
4334
4338
source. defer_to_typeck ( ) ,
4335
4339
finalize,
4340
+ source,
4336
4341
) {
4337
4342
Ok ( Some ( partial_res) ) if let Some ( res) = partial_res. full_res ( ) => {
4338
4343
// if we also have an associated type that matches the ident, stash a suggestion
@@ -4455,12 +4460,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4455
4460
span : Span ,
4456
4461
defer_to_typeck : bool ,
4457
4462
finalize : Finalize ,
4463
+ source : PathSource < ' ast , ' _ > ,
4458
4464
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4459
4465
let mut fin_res = None ;
4460
4466
4461
4467
for ( i, & ns) in [ primary_ns, TypeNS , ValueNS ] . iter ( ) . enumerate ( ) {
4462
4468
if i == 0 || ns != primary_ns {
4463
- match self . resolve_qpath ( qself, path, ns, finalize) ? {
4469
+ match self . resolve_qpath ( qself, path, ns, finalize, source ) ? {
4464
4470
Some ( partial_res)
4465
4471
if partial_res. unresolved_segments ( ) == 0 || defer_to_typeck =>
4466
4472
{
@@ -4497,6 +4503,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4497
4503
path : & [ Segment ] ,
4498
4504
ns : Namespace ,
4499
4505
finalize : Finalize ,
4506
+ source : PathSource < ' ast , ' _ > ,
4500
4507
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' ra > > > {
4501
4508
debug ! (
4502
4509
"resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})" ,
@@ -4544,7 +4551,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4544
4551
let partial_res = self . smart_resolve_path_fragment (
4545
4552
& None ,
4546
4553
& path[ ..=qself. position ] ,
4547
- PathSource :: TraitItem ( ns) ,
4554
+ PathSource :: TraitItem ( ns, & source ) ,
4548
4555
Finalize :: with_root_span ( finalize. node_id , finalize. path_span , qself. path_span ) ,
4549
4556
RecordPartialRes :: No ,
4550
4557
Some ( & qself) ,
0 commit comments