Skip to content

Commit 2189908

Browse files
Add more tests
1 parent 18a3cc5 commit 2189908

9 files changed

+172
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ run-pass
2+
//@ check-run-results
3+
4+
#![feature(supertrait_item_shadowing)]
5+
#![allow(dead_code)]
6+
7+
trait A {
8+
const CONST: i32;
9+
}
10+
impl<T> A for T {
11+
const CONST: i32 = 1;
12+
}
13+
14+
trait B: A {
15+
const CONST: i32;
16+
}
17+
impl<T> B for T {
18+
const CONST: i32 = 2;
19+
}
20+
21+
fn main() {
22+
println!("{}", i32::CONST);
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![feature(supertrait_item_shadowing)]
2+
#![warn(supertrait_item_shadowing_usage)]
3+
4+
struct W<T>(T);
5+
6+
trait Upstream {
7+
fn hello(&self) {}
8+
}
9+
impl<T> Upstream for T {}
10+
11+
trait Downstream: Upstream {
12+
fn hello(&self) {}
13+
}
14+
impl<T> Downstream for W<T> where T: Foo {}
15+
16+
trait Foo {}
17+
18+
fn main() {
19+
let x = W(Default::default());
20+
x.hello();
21+
//~^ ERROR the trait bound `i32: Foo` is not satisfied
22+
//~| WARN trait item `hello` from `Downstream` shadows identically named item from supertrait
23+
let _: i32 = x.0;
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
warning: trait item `hello` from `Downstream` shadows identically named item from supertrait
2+
--> $DIR/false-subtrait-after-inference.rs:20:7
3+
|
4+
LL | x.hello();
5+
| ^^^^^
6+
|
7+
note: item from `Downstream` shadows a supertrait item
8+
--> $DIR/false-subtrait-after-inference.rs:12:5
9+
|
10+
LL | fn hello(&self) {}
11+
| ^^^^^^^^^^^^^^^
12+
note: item from `Upstream` is shadowed by a subtrait item
13+
--> $DIR/false-subtrait-after-inference.rs:7:5
14+
|
15+
LL | fn hello(&self) {}
16+
| ^^^^^^^^^^^^^^^
17+
note: the lint level is defined here
18+
--> $DIR/false-subtrait-after-inference.rs:2:9
19+
|
20+
LL | #![warn(supertrait_item_shadowing_usage)]
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
23+
error[E0277]: the trait bound `i32: Foo` is not satisfied
24+
--> $DIR/false-subtrait-after-inference.rs:20:7
25+
|
26+
LL | x.hello();
27+
| ^^^^^ the trait `Foo` is not implemented for `i32`
28+
|
29+
help: this trait has no implementations, consider adding one
30+
--> $DIR/false-subtrait-after-inference.rs:16:1
31+
|
32+
LL | trait Foo {}
33+
| ^^^^^^^^^
34+
note: required for `W<i32>` to implement `Downstream`
35+
--> $DIR/false-subtrait-after-inference.rs:14:9
36+
|
37+
LL | impl<T> Downstream for W<T> where T: Foo {}
38+
| ^^^^^^^^^^ ^^^^ --- unsatisfied trait bound introduced here
39+
40+
error: aborting due to 1 previous error; 1 warning emitted
41+
42+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ run-pass
2+
//@ check-run-results
3+
4+
#![feature(supertrait_item_shadowing)]
5+
#![allow(dead_code)]
6+
7+
mod out_of_scope {
8+
pub trait Subtrait: super::Supertrait {
9+
fn hello(&self) {
10+
println!("subtrait");
11+
}
12+
}
13+
impl<T> Subtrait for T {}
14+
}
15+
16+
trait Supertrait {
17+
fn hello(&self) {
18+
println!("supertrait");
19+
}
20+
}
21+
impl<T> Supertrait for T {}
22+
23+
fn main() {
24+
().hello();
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
supertrait
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//@ check-pass
2+
3+
// Make sure we don't prefer a subtrait that we would've otherwise eliminated
4+
// in `consider_probe` during method probing.
5+
6+
#![feature(supertrait_item_shadowing)]
7+
#![allow(dead_code)]
8+
9+
struct W<T>(T);
10+
11+
trait Upstream {
12+
fn hello(&self) {}
13+
}
14+
impl<T> Upstream for T {}
15+
16+
trait Downstream: Upstream {
17+
fn hello(&self) {}
18+
}
19+
impl<T> Downstream for W<T> where T: Foo {}
20+
21+
trait Foo {}
22+
23+
fn main() {
24+
let x = W(1i32);
25+
x.hello();
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ run-pass
2+
//@ check-run-results
3+
4+
// Makes sure we can shadow with type-dependent method syntax.
5+
6+
#![feature(supertrait_item_shadowing)]
7+
#![allow(dead_code)]
8+
9+
trait A {
10+
fn hello() {
11+
println!("A");
12+
}
13+
}
14+
impl<T> A for T {}
15+
16+
trait B: A {
17+
fn hello() {
18+
println!("B");
19+
}
20+
}
21+
impl<T> B for T {}
22+
23+
fn foo<T>() {
24+
T::hello();
25+
}
26+
27+
fn main() {
28+
foo::<()>();
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
B

0 commit comments

Comments
 (0)