Skip to content

Commit 9407a97

Browse files
committed
Address review feedback for tests
1 parent b7715df commit 9407a97

24 files changed

Lines changed: 744 additions & 114 deletions

tests/ui/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,10 @@ Generic collection of tests for suggestions, when no more specific directories a
13411341

13421342
**FIXME**: Some overlap with `tests/ui/did_you_mean/`, that directory should probably be moved under here.
13431343

1344+
## `tests/ui/supertrait-shadowing/`
1345+
1346+
Tests for supertrait item shadowing (RFC 3624).
1347+
13441348
## `tests/ui/svh/`: Strict Version Hash
13451349

13461350
Tests on the *Strict Version Hash* (SVH, also known as the "crate hash").
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//@ run-pass
22

33
#![feature(supertrait_item_shadowing)]
4+
#![feature(min_generic_const_args)]
45
#![allow(dead_code)]
56

67
trait A {
@@ -11,12 +12,20 @@ impl<T> A for T {
1112
}
1213

1314
trait B: A {
14-
const CONST: i32;
15+
type const CONST: i32;
1516
}
1617
impl<T> B for T {
17-
const CONST: i32 = 2;
18+
type const CONST: i32 = 2;
1819
}
1920

21+
trait C: B {}
22+
impl<T> C for T {}
23+
2024
fn main() {
21-
assert_eq!(i32::CONST, 2)
25+
assert_eq!(i32::CONST, 2);
26+
generic::<u32>();
27+
}
28+
29+
fn generic<T: C<CONST = 2>>() {
30+
assert_eq!(T::CONST, 2);
2231
}

tests/ui/supertrait-shadowing/assoc-const2.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/ui/supertrait-shadowing/assoc-const2.run.stdout

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#![feature(supertrait_item_shadowing)]
2+
#![allow(dead_code)]
3+
4+
use std::mem::size_of;
5+
6+
trait A {
7+
type Assoc;
8+
}
9+
impl<X> A for X {
10+
type Assoc = i8;
11+
}
12+
13+
trait B: A {
14+
type Assoc;
15+
}
16+
impl<X> B for X {
17+
type Assoc = i16;
18+
}
19+
20+
trait C: B {}
21+
impl<X> C for X {}
22+
23+
fn main() {
24+
b_unbound::<u32>();
25+
c_unbound::<u32>();
26+
27+
b_assoc_is_a::<u32>();
28+
//~^ ERROR type mismatch resolving `<u32 as B>::Assoc == i8`
29+
c_assoc_is_a::<u32>();
30+
//~^ ERROR type mismatch resolving `<u32 as B>::Assoc == i8`
31+
}
32+
33+
fn b_unbound<U: B>() {
34+
let _ = size_of::<U::Assoc>();
35+
}
36+
37+
fn c_unbound<U: C>() {
38+
let _ = size_of::<U::Assoc>();
39+
}
40+
41+
fn b_assoc_is_a<U: B<Assoc = i8>>() {
42+
let _ = size_of::<U::Assoc>();
43+
}
44+
45+
fn c_assoc_is_a<U: C<Assoc = i8>>() {
46+
let _ = size_of::<U::Assoc>();
47+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error[E0271]: type mismatch resolving `<u32 as B>::Assoc == i8`
2+
--> $DIR/assoc-type-fail.rs:27:20
3+
|
4+
LL | b_assoc_is_a::<u32>();
5+
| ^^^ type mismatch resolving `<u32 as B>::Assoc == i8`
6+
|
7+
note: expected this to be `i8`
8+
--> $DIR/assoc-type-fail.rs:17:18
9+
|
10+
LL | type Assoc = i16;
11+
| ^^^
12+
note: required by a bound in `b_assoc_is_a`
13+
--> $DIR/assoc-type-fail.rs:41:22
14+
|
15+
LL | fn b_assoc_is_a<U: B<Assoc = i8>>() {
16+
| ^^^^^^^^^^ required by this bound in `b_assoc_is_a`
17+
18+
error[E0271]: type mismatch resolving `<u32 as B>::Assoc == i8`
19+
--> $DIR/assoc-type-fail.rs:29:20
20+
|
21+
LL | c_assoc_is_a::<u32>();
22+
| ^^^ type mismatch resolving `<u32 as B>::Assoc == i8`
23+
|
24+
note: expected this to be `i8`
25+
--> $DIR/assoc-type-fail.rs:17:18
26+
|
27+
LL | type Assoc = i16;
28+
| ^^^
29+
note: required by a bound in `c_assoc_is_a`
30+
--> $DIR/assoc-type-fail.rs:45:22
31+
|
32+
LL | fn c_assoc_is_a<U: C<Assoc = i8>>() {
33+
| ^^^^^^^^^^ required by this bound in `c_assoc_is_a`
34+
35+
error: aborting due to 2 previous errors
36+
37+
For more information about this error, try `rustc --explain E0271`.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//@ normalize-stderr: "assoc_type_predicates\[[^\]]+\]" -> "assoc_type_predicates[HASH]"
2+
3+
#![feature(rustc_attrs)]
4+
#![feature(supertrait_item_shadowing)]
5+
#![allow(dead_code)]
6+
7+
trait A {
8+
type Assoc;
9+
}
10+
impl<T> A for T {
11+
type Assoc = i8;
12+
}
13+
14+
trait B: A {
15+
type Assoc;
16+
}
17+
impl<T> B for T {
18+
type Assoc = i16;
19+
}
20+
21+
trait C: B {}
22+
impl<T> C for T {}
23+
24+
#[rustc_dump_predicates]
25+
fn a_bound<T: A<Assoc = i8>>() {}
26+
//~^ ERROR rustc_dump_predicates
27+
//~| NOTE TraitPredicate(<T as std::marker::Sized>
28+
//~| NOTE TraitPredicate(<T as A>
29+
//~| NOTE A::Assoc
30+
31+
#[rustc_dump_predicates]
32+
fn b_bound<T: B<Assoc = i16>>() {}
33+
//~^ ERROR rustc_dump_predicates
34+
//~| NOTE TraitPredicate(<T as std::marker::Sized>
35+
//~| NOTE TraitPredicate(<T as B>
36+
//~| NOTE B::Assoc
37+
38+
#[rustc_dump_predicates]
39+
fn c_bound<T: C<Assoc = i16>>() {}
40+
//~^ ERROR rustc_dump_predicates
41+
//~| NOTE TraitPredicate(<T as std::marker::Sized>
42+
//~| NOTE TraitPredicate(<T as C>
43+
//~| NOTE B::Assoc
44+
45+
fn main() {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: rustc_dump_predicates
2+
--> $DIR/assoc-type-predicates.rs:25:1
3+
|
4+
LL | fn a_bound<T: A<Assoc = i8>>() {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }
8+
= note: Binder { value: TraitPredicate(<T as A>, polarity:Positive), bound_vars: [] }
9+
= note: Binder { value: ProjectionPredicate(AliasTerm { args: [T/#0], kind: ProjectionTy { def_id: DefId(0:4 ~ assoc_type_predicates[HASH]::A::Assoc) }, .. }, Term::Ty(i8)), bound_vars: [] }
10+
11+
error: rustc_dump_predicates
12+
--> $DIR/assoc-type-predicates.rs:32:1
13+
|
14+
LL | fn b_bound<T: B<Assoc = i16>>() {}
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
|
17+
= note: Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }
18+
= note: Binder { value: TraitPredicate(<T as B>, polarity:Positive), bound_vars: [] }
19+
= note: Binder { value: ProjectionPredicate(AliasTerm { args: [T/#0], kind: ProjectionTy { def_id: DefId(0:9 ~ assoc_type_predicates[HASH]::B::Assoc) }, .. }, Term::Ty(i16)), bound_vars: [] }
20+
21+
error: rustc_dump_predicates
22+
--> $DIR/assoc-type-predicates.rs:39:1
23+
|
24+
LL | fn c_bound<T: C<Assoc = i16>>() {}
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
|
27+
= note: Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }
28+
= note: Binder { value: TraitPredicate(<T as C>, polarity:Positive), bound_vars: [] }
29+
= note: Binder { value: ProjectionPredicate(AliasTerm { args: [T/#0], kind: ProjectionTy { def_id: DefId(0:9 ~ assoc_type_predicates[HASH]::B::Assoc) }, .. }, Term::Ty(i16)), bound_vars: [] }
30+
31+
error: aborting due to 3 previous errors
32+

tests/ui/supertrait-shadowing/assoc-type.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
use std::mem::size_of;
88

99
trait A {
10-
type T;
10+
type Assoc;
1111
}
1212
impl<T> A for T {
13-
type T = i8;
13+
type Assoc = i8;
1414
}
1515

1616
trait B: A {
17-
type T;
17+
type Assoc;
1818
}
1919
impl<T> B for T {
20-
type T = i16;
20+
type Assoc = i16;
2121
}
2222

2323
trait C: B {}
@@ -28,20 +28,26 @@ fn main() {
2828
generic2::<u32>();
2929
generic3::<u32>();
3030
generic4::<u32>();
31+
generic5::<u32>();
3132
}
3233

33-
fn generic<U: B>() {
34-
println!("{}", size_of::<U::T>());
34+
fn generic<T: B>() {
35+
assert_eq!(size_of::<T::Assoc>(), 2);
3536
}
3637

37-
fn generic2<U: A<T = i8>>() {
38-
println!("{}", size_of::<U::T>());
38+
fn generic2<T: A<Assoc = i8>>() {
39+
assert_eq!(size_of::<T::Assoc>(), 1);
3940
}
4041

41-
fn generic3<U: B<T = i16>>() {
42-
println!("{}", size_of::<U::T>());
42+
fn generic3<T: B<Assoc = i16>>() {
43+
assert_eq!(size_of::<T::Assoc>(), 2);
4344
}
4445

45-
fn generic4<U: C<T = i16>>() {
46-
println!("{}", size_of::<U::T>());
46+
fn generic4<T: C<Assoc = i16>>() {
47+
assert_eq!(size_of::<T::Assoc>(), 2);
48+
}
49+
50+
fn generic5<T: B>() {
51+
assert_eq!(size_of::<<T as A>::Assoc>(), 1);
52+
assert_eq!(size_of::<<T as B>::Assoc>(), 2);
4753
}

tests/ui/supertrait-shadowing/assoc-type.run.stdout

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)