-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Account for impl Trait {
when impl Trait for Type {
was intended
#131273
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
warning: trait objects without an explicit `dyn` are deprecated | ||
--> $DIR/missing-for-type-in-impl.rs:8:6 | ||
| | ||
LL | impl Foo<i64> { | ||
| ^^^^^^^^ | ||
| | ||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> | ||
= note: `#[warn(bare_trait_objects)]` on by default | ||
help: if this is a dyn-compatible trait, use `dyn` | ||
| | ||
LL | impl dyn Foo<i64> { | ||
| +++ | ||
help: you might have intended to implement this trait for a given type | ||
| | ||
LL | impl Foo<i64> for /* Type */ { | ||
| ++++++++++++++ | ||
|
||
warning: trait objects without an explicit `dyn` are deprecated | ||
--> $DIR/missing-for-type-in-impl.rs:8:6 | ||
| | ||
LL | impl Foo<i64> { | ||
| ^^^^^^^^ | ||
| | ||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
help: if this is a dyn-compatible trait, use `dyn` | ||
| | ||
LL | impl dyn Foo<i64> { | ||
| +++ | ||
help: you might have intended to implement this trait for a given type | ||
| | ||
LL | impl Foo<i64> for /* Type */ { | ||
| ++++++++++++++ | ||
|
||
error[E0038]: the trait `Foo` cannot be made into an object | ||
--> $DIR/missing-for-type-in-impl.rs:8:6 | ||
| | ||
LL | impl Foo<i64> { | ||
| ^^^^^^^^ `Foo` cannot be made into an object | ||
| | ||
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> | ||
--> $DIR/missing-for-type-in-impl.rs:4:8 | ||
| | ||
LL | trait Foo<T> { | ||
| --- this trait cannot be made into an object... | ||
LL | fn id(me: T) -> T; | ||
| ^^ ...because associated function `id` has no `self` parameter | ||
help: consider turning `id` into a method by giving it a `&self` argument | ||
| | ||
LL | fn id(&self, me: T) -> T; | ||
| ++++++ | ||
help: alternatively, consider constraining `id` so it does not apply to trait objects | ||
| | ||
LL | fn id(me: T) -> T where Self: Sized; | ||
| +++++++++++++++++ | ||
|
||
error[E0277]: the trait bound `i64: Foo<i64>` is not satisfied | ||
--> $DIR/missing-for-type-in-impl.rs:19:19 | ||
| | ||
LL | let x: i64 = <i64 as Foo<i64>>::id(10); | ||
| ^^^ the trait `Foo<i64>` is not implemented for `i64` | ||
| | ||
help: this trait has no implementations, consider adding one | ||
--> $DIR/missing-for-type-in-impl.rs:3:1 | ||
| | ||
LL | trait Foo<T> { | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors; 2 warnings emitted | ||
|
||
Some errors have detailed explanations: E0038, E0277. | ||
For more information about an error, try `rustc --explain E0038`. |
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,31 @@ | ||
error[E0277]: the trait bound `i64: Foo<i64>` is not satisfied | ||
--> $DIR/missing-for-type-in-impl.rs:19:19 | ||
| | ||
LL | let x: i64 = <i64 as Foo<i64>>::id(10); | ||
| ^^^ the trait `Foo<i64>` is not implemented for `i64` | ||
| | ||
help: this trait has no implementations, consider adding one | ||
--> $DIR/missing-for-type-in-impl.rs:3:1 | ||
| | ||
LL | trait Foo<T> { | ||
| ^^^^^^^^^^^^ | ||
|
||
error[E0782]: trait objects must include the `dyn` keyword | ||
--> $DIR/missing-for-type-in-impl.rs:8:6 | ||
| | ||
LL | impl Foo<i64> { | ||
| ^^^^^^^^ | ||
| | ||
help: add `dyn` keyword before this trait | ||
| | ||
LL | impl dyn Foo<i64> { | ||
| +++ | ||
help: you might have intended to implement this trait for a given type | ||
| | ||
LL | impl Foo<i64> for /* Type */ { | ||
| ++++++++++++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0277, E0782. | ||
For more information about an error, try `rustc --explain E0277`. |
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,22 @@ | ||
//@revisions: e2021 e2015 | ||
//@[e2021]edition: 2021 | ||
trait Foo<T> { | ||
fn id(me: T) -> T; | ||
} | ||
|
||
/* note the "missing" for ... (in this case for i64, in order for this to compile) */ | ||
impl Foo<i64> { | ||
//[e2021]~^ ERROR trait objects must include the `dyn` keyword | ||
//[e2015]~^^ WARNING trait objects without an explicit `dyn` are deprecated | ||
//[e2015]~| WARNING trait objects without an explicit `dyn` are deprecated | ||
//[e2015]~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! | ||
//[e2015]~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! | ||
//[e2015]~| ERROR the trait `Foo` cannot be made into an object | ||
fn id(me: i64) -> i64 {me} | ||
} | ||
|
||
fn main() { | ||
let x: i64 = <i64 as Foo<i64>>::id(10); | ||
//~^ ERROR the trait bound `i64: Foo<i64>` is not satisfied | ||
println!("{}", x); | ||
} |
Oops, something went wrong.
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.