forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#59166 - seanmonstar:trait-alias-import, r=a…
…lexreg resolve: collect trait aliases along with traits It seems trait aliases weren't being collected as `TraitCandidates` in resolve, this should change that. (I can't compile the full compiler locally, so relying on CI...) Fixes rust-lang#56485 r? @alexreg
- Loading branch information
Showing
9 changed files
with
192 additions
and
37 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
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
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
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
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,13 @@ | ||
#![feature(trait_alias)] | ||
|
||
pub trait Hello { | ||
fn hello(&self); | ||
} | ||
|
||
pub struct Hi; | ||
|
||
impl Hello for Hi { | ||
fn hello(&self) {} | ||
} | ||
|
||
pub trait Greet = Hello; |
14 changes: 14 additions & 0 deletions
14
src/test/run-pass/traits/trait-alias-import-cross-crate.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,14 @@ | ||
// run-pass | ||
// aux-build:trait_alias.rs | ||
|
||
#![feature(trait_alias)] | ||
|
||
extern crate trait_alias; | ||
|
||
// Import only the alias, not the real trait. | ||
use trait_alias::{Greet, Hi}; | ||
|
||
fn main() { | ||
let hi = Hi; | ||
hi.hello(); // From `Hello`, via `Greet` alias. | ||
} |
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 @@ | ||
#![feature(trait_alias)] | ||
|
||
mod inner { | ||
pub trait Foo { | ||
fn foo(&self); | ||
} | ||
|
||
pub struct Qux; | ||
|
||
impl Foo for Qux { | ||
fn foo(&self) {} | ||
} | ||
|
||
pub trait Bar = Foo; | ||
} | ||
|
||
mod two { | ||
pub trait A { | ||
fn foo(); | ||
} | ||
|
||
impl A for u8 { | ||
fn foo() {} | ||
} | ||
} | ||
|
||
// Import only the alias, not the `Foo` trait. | ||
use inner::{Bar, Qux}; | ||
|
||
// Declaring an alias also brings in aliased methods. | ||
trait Two = two::A; | ||
|
||
fn main() { | ||
let q = Qux; | ||
q.foo(); // From Bar. | ||
|
||
u8::foo(); // From A. | ||
} |
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,24 @@ | ||
#![feature(trait_alias)] | ||
|
||
mod inner { | ||
pub trait A { fn foo(&self); } | ||
pub trait B { fn foo(&self); } | ||
|
||
impl A for u8 { | ||
fn foo(&self) {} | ||
} | ||
impl B for u8 { | ||
fn foo(&self) {} | ||
} | ||
|
||
pub trait C = A + B; | ||
} | ||
|
||
use inner::C; | ||
|
||
fn main() { | ||
let t = 1u8; | ||
t.foo(); //~ ERROR E0034 | ||
|
||
inner::A::foo(&t); // ok | ||
} |
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,20 @@ | ||
error[E0034]: multiple applicable items in scope | ||
--> $DIR/trait-alias-ambiguous.rs:21:7 | ||
| | ||
LL | t.foo(); | ||
| ^^^ multiple `foo` found | ||
| | ||
note: candidate #1 is defined in an impl of the trait `inner::A` for the type `u8` | ||
--> $DIR/trait-alias-ambiguous.rs:8:9 | ||
| | ||
LL | fn foo(&self) {} | ||
| ^^^^^^^^^^^^^ | ||
note: candidate #2 is defined in an impl of the trait `inner::B` for the type `u8` | ||
--> $DIR/trait-alias-ambiguous.rs:11:9 | ||
| | ||
LL | fn foo(&self) {} | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0034`. |