-
Notifications
You must be signed in to change notification settings - Fork 13.4k
resolve: collect trait aliases along with traits #59166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.