-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
069e9d2
commit 1ab7845
Showing
9 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//@ run-pass | ||
//@ check-run-results | ||
|
||
#![feature(supertrait_item_shadowing)] | ||
#![allow(dead_code)] | ||
|
||
trait A { | ||
const CONST: i32; | ||
} | ||
impl<T> A for T { | ||
const CONST: i32 = 1; | ||
} | ||
|
||
trait B: A { | ||
const CONST: i32; | ||
} | ||
impl<T> B for T { | ||
const CONST: i32 = 2; | ||
} | ||
|
||
fn main() { | ||
println!("{}", i32::CONST); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2 |
23 changes: 23 additions & 0 deletions
23
tests/ui/methods/supertrait-shadowing/false-subtrait-after-inference.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#![feature(supertrait_item_shadowing)] | ||
|
||
struct W<T>(T); | ||
|
||
trait Upstream { | ||
fn hello(&self) {} | ||
} | ||
impl<T> Upstream for T {} | ||
|
||
trait Downstream: Upstream { | ||
fn hello(&self) {} | ||
} | ||
impl<T> Downstream for W<T> where T: Foo {} | ||
|
||
trait Foo {} | ||
|
||
fn main() { | ||
let x = W(Default::default()); | ||
x.hello(); | ||
//~^ ERROR the trait bound `i32: Foo` is not satisfied | ||
//~| WARN trait method `hello` from `Downstream` shadows identically named method from supertrait | ||
let _: i32 = x.0; | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/ui/methods/supertrait-shadowing/false-subtrait-after-inference.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
warning: trait method `hello` from `Downstream` shadows identically named method from supertrait | ||
--> $DIR/false-subtrait-after-inference.rs:19:7 | ||
| | ||
LL | x.hello(); | ||
| ^^^^^ | ||
| | ||
note: method from `Downstream` shadows a supertrait method | ||
--> $DIR/false-subtrait-after-inference.rs:11:5 | ||
| | ||
LL | fn hello(&self) {} | ||
| ^^^^^^^^^^^^^^^ | ||
note: method from `Upstream` is shadowed by a subtrait method | ||
--> $DIR/false-subtrait-after-inference.rs:6:5 | ||
| | ||
LL | fn hello(&self) {} | ||
| ^^^^^^^^^^^^^^^ | ||
= note: `#[warn(supertrait_item_shadowing)]` on by default | ||
|
||
error[E0277]: the trait bound `i32: Foo` is not satisfied | ||
--> $DIR/false-subtrait-after-inference.rs:19:7 | ||
| | ||
LL | x.hello(); | ||
| ^^^^^ the trait `Foo` is not implemented for `i32`, which is required by `W<_>: Downstream` | ||
| | ||
help: this trait has no implementations, consider adding one | ||
--> $DIR/false-subtrait-after-inference.rs:15:1 | ||
| | ||
LL | trait Foo {} | ||
| ^^^^^^^^^ | ||
note: required for `W<i32>` to implement `Downstream` | ||
--> $DIR/false-subtrait-after-inference.rs:13:9 | ||
| | ||
LL | impl<T> Downstream for W<T> where T: Foo {} | ||
| ^^^^^^^^^^ ^^^^ --- unsatisfied trait bound introduced here | ||
|
||
error: aborting due to 1 previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//@ run-pass | ||
//@ check-run-results | ||
|
||
#![feature(supertrait_item_shadowing)] | ||
#![allow(dead_code)] | ||
|
||
mod out_of_scope { | ||
pub trait Subtrait: super::Supertrait { | ||
fn hello(&self) { | ||
println!("subtrait"); | ||
} | ||
} | ||
impl<T> Subtrait for T {} | ||
} | ||
|
||
trait Supertrait { | ||
fn hello(&self) { | ||
println!("supertrait"); | ||
} | ||
} | ||
impl<T> Supertrait for T {} | ||
|
||
fn main() { | ||
().hello(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
supertrait |
26 changes: 26 additions & 0 deletions
26
tests/ui/methods/supertrait-shadowing/trivially-false-subtrait.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//@ check-pass | ||
|
||
// Make sure we don't prefer a subtrait that we would've otherwise eliminated | ||
// in `consider_probe` during method probing. | ||
|
||
#![feature(supertrait_item_shadowing)] | ||
#![allow(dead_code)] | ||
|
||
struct W<T>(T); | ||
|
||
trait Upstream { | ||
fn hello(&self) {} | ||
} | ||
impl<T> Upstream for T {} | ||
|
||
trait Downstream: Upstream { | ||
fn hello(&self) {} | ||
} | ||
impl<T> Downstream for W<T> where T: Foo {} | ||
|
||
trait Foo {} | ||
|
||
fn main() { | ||
let x = W(1i32); | ||
x.hello(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//@ run-pass | ||
//@ check-run-results | ||
|
||
// Makes sure we can shadow with type-dependent method syntax. | ||
|
||
#![feature(supertrait_item_shadowing)] | ||
#![allow(dead_code)] | ||
|
||
trait A { | ||
fn hello() { | ||
println!("A"); | ||
} | ||
} | ||
impl<T> A for T {} | ||
|
||
trait B: A { | ||
fn hello() { | ||
println!("B"); | ||
} | ||
} | ||
impl<T> B for T {} | ||
|
||
fn foo<T>() { | ||
T::hello(); | ||
} | ||
|
||
fn main() { | ||
foo::<()>(); | ||
} |
1 change: 1 addition & 0 deletions
1
tests/ui/methods/supertrait-shadowing/type-dependent.run.stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
B |