-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #119525.
- Loading branch information
Showing
4 changed files
with
98 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// run-rustfix | ||
#![deny(bare_trait_objects)] | ||
fn ord_prefer_dot(s: String) -> impl Ord { | ||
//~^ ERROR trait objects without an explicit `dyn` are deprecated | ||
//~| ERROR the trait `Ord` cannot be made into an object | ||
//~| WARNING this is accepted in the current edition (Rust 2015) | ||
(s.starts_with("."), s) | ||
} | ||
fn main() { | ||
let _ = ord_prefer_dot(String::new()); | ||
} |
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,11 @@ | ||
// run-rustfix | ||
#![deny(bare_trait_objects)] | ||
fn ord_prefer_dot(s: String) -> Ord { | ||
//~^ ERROR trait objects without an explicit `dyn` are deprecated | ||
//~| ERROR the trait `Ord` cannot be made into an object | ||
//~| WARNING this is accepted in the current edition (Rust 2015) | ||
(s.starts_with("."), s) | ||
} | ||
fn main() { | ||
let _ = ord_prefer_dot(String::new()); | ||
} |
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,35 @@ | ||
error: trait objects without an explicit `dyn` are deprecated | ||
--> $DIR/bare-trait-dont-suggest-dyn.rs:3:33 | ||
| | ||
LL | fn ord_prefer_dot(s: String) -> Ord { | ||
| ^^^ | ||
| | ||
= 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: the lint level is defined here | ||
--> $DIR/bare-trait-dont-suggest-dyn.rs:2:9 | ||
| | ||
LL | #![deny(bare_trait_objects)] | ||
| ^^^^^^^^^^^^^^^^^^ | ||
help: `Ord` is not object safe, use `impl Ord` to return an opaque type, as long as you return a single underlying type | ||
| | ||
LL | fn ord_prefer_dot(s: String) -> impl Ord { | ||
| ++++ | ||
|
||
error[E0038]: the trait `Ord` cannot be made into an object | ||
--> $DIR/bare-trait-dont-suggest-dyn.rs:3:33 | ||
| | ||
LL | fn ord_prefer_dot(s: String) -> Ord { | ||
| ^^^ `Ord` cannot be made into an object | ||
| | ||
note: for a trait to be "object safe" 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> | ||
--> $SRC_DIR/core/src/cmp.rs:LL:COL | ||
| | ||
= note: the trait cannot be made into an object because it uses `Self` as a type parameter | ||
::: $SRC_DIR/core/src/cmp.rs:LL:COL | ||
| | ||
= note: the trait cannot be made into an object because it uses `Self` as a type parameter | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0038`. |