@@ -3370,3 +3370,78 @@ note: the traits `Iterator` and `ToTokens` must be implemented
3370
3370
let renderer = renderer. theme ( OutputTheme :: Unicode ) ;
3371
3371
assert_data_eq ! ( renderer. render( input) , expected_unicode) ;
3372
3372
}
3373
+
3374
+ #[ test]
3375
+ fn not_found_self_type_differs_shadowing_trait_item ( ) {
3376
+ // tests/ui/associated-inherent-types/not-found-self-type-differs-shadowing-trait-item.rs
3377
+
3378
+ let source = r#"#![feature(inherent_associated_types)]
3379
+ #![allow(incomplete_features)]
3380
+
3381
+ // Check that it's okay to report “[inherent] associated type […] not found” for inherent associated
3382
+ // type candidates that are not applicable (due to unsuitable Self type) even if there exists a
3383
+ // “shadowed” associated type from a trait with the same name since its use would be ambiguous
3384
+ // anyway if the IAT didn't exist.
3385
+ // FIXME(inherent_associated_types): Figure out which error would be more helpful here.
3386
+
3387
+ //@ revisions: shadowed uncovered
3388
+
3389
+ struct S<T>(T);
3390
+
3391
+ trait Tr {
3392
+ type Pr;
3393
+ }
3394
+
3395
+ impl<T> Tr for S<T> {
3396
+ type Pr = ();
3397
+ }
3398
+
3399
+ #[cfg(shadowed)]
3400
+ impl S<()> {
3401
+ type Pr = i32;
3402
+ }
3403
+
3404
+ fn main() {
3405
+ let _: S::<bool>::Pr = ();
3406
+ //[shadowed]~^ ERROR associated type `Pr` not found
3407
+ //[uncovered]~^^ ERROR associated type `Pr` not found
3408
+ }
3409
+ "# ;
3410
+
3411
+ let input = & [ Group :: with_title (
3412
+ Level :: ERROR
3413
+ . title ( "associated type `Pr` not found for `S<bool>` in the current scope" )
3414
+ . id ( "E0220" ) ,
3415
+ )
3416
+ . element (
3417
+ Snippet :: source ( source)
3418
+ . path ( "$DIR/not-found-self-type-differs-shadowing-trait-item.rs" )
3419
+ . annotation (
3420
+ AnnotationKind :: Primary
3421
+ . span ( 705 ..707 )
3422
+ . label ( "associated item not found in `S<bool>`" ) ,
3423
+ )
3424
+ . annotation (
3425
+ AnnotationKind :: Context
3426
+ . span ( 532 ..543 )
3427
+ . label ( "associated type `Pr` not found for this struct" ) ,
3428
+ ) ,
3429
+ )
3430
+ . element ( Level :: NOTE . title ( "the associated type was found for\n " ) ) ] ;
3431
+
3432
+ let expected = str![ [ r#"
3433
+ error[E0220]: associated type `Pr` not found for `S<bool>` in the current scope
3434
+ --> $DIR/not-found-self-type-differs-shadowing-trait-item.rs:28:23
3435
+ |
3436
+ LL | struct S<T>(T);
3437
+ | ----------- associated type `Pr` not found for this struct
3438
+ ...
3439
+ LL | let _: S::<bool>::Pr = ();
3440
+ | ^^ associated item not found in `S<bool>`
3441
+ |
3442
+ = note: the associated type was found for
3443
+
3444
+ "# ] ] ;
3445
+ let renderer = Renderer :: plain ( ) . anonymized_line_numbers ( true ) ;
3446
+ assert_data_eq ! ( renderer. render( input) , expected) ;
3447
+ }
0 commit comments