-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Avoid ICE in trait without
dyn
lint
Do not attempt to provide an accurate suggestion for `impl Trait` in bare trait types when linting. Instead, only do the object safety check when an E0782 is already going to be emitted in the 2021 edition. Fix #120241.
Showing
16 changed files
with
221 additions
and
125 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,12 @@ | ||
error[E0038]: the trait `Copy` cannot be made into an object | ||
--> $DIR/avoid-ice-on-warning-2.rs:4:13 | ||
| | ||
LL | fn id<F>(f: Copy) -> usize { | ||
| ^^^^ `Copy` cannot be made into an object | ||
| | ||
= note: the trait cannot be made into an object because it requires `Self: Sized` | ||
= 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> | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0038`. |
28 changes: 9 additions & 19 deletions
28
...ject-safety/avoid-ice-on-warning-2.stderr → ...-safety/avoid-ice-on-warning-2.old.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
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
// revisions: old new | ||
//[old] edition:2015 | ||
//[new] edition:2021 | ||
fn id<F>(f: Copy) -> usize { | ||
//~^ WARN trait objects without an explicit `dyn` are deprecated | ||
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! | ||
//~| WARN trait objects without an explicit `dyn` are deprecated | ||
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! | ||
//~| ERROR the trait `Copy` cannot be made into an object | ||
//~^ ERROR the trait `Copy` cannot be made into an object | ||
//[old]~| WARN trait objects without an explicit `dyn` are deprecated | ||
//[old]~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! | ||
//[old]~| WARN trait objects without an explicit `dyn` are deprecated | ||
//[old]~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! | ||
f() | ||
} | ||
fn main() {} |
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,47 @@ | ||
error[E0038]: the trait `A` cannot be made into an object | ||
--> $DIR/avoid-ice-on-warning-3.rs:4:19 | ||
| | ||
LL | trait B { fn f(a: A) -> A; } | ||
| ^ `A` 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> | ||
--> $DIR/avoid-ice-on-warning-3.rs:12:14 | ||
| | ||
LL | trait A { fn g(b: B) -> B; } | ||
| - ^ ...because associated function `g` has no `self` parameter | ||
| | | ||
| this trait cannot be made into an object... | ||
help: consider turning `g` into a method by giving it a `&self` argument | ||
| | ||
LL | trait A { fn g(&self, b: B) -> B; } | ||
| ++++++ | ||
help: alternatively, consider constraining `g` so it does not apply to trait objects | ||
| | ||
LL | trait A { fn g(b: B) -> B where Self: Sized; } | ||
| +++++++++++++++++ | ||
|
||
error[E0038]: the trait `B` cannot be made into an object | ||
--> $DIR/avoid-ice-on-warning-3.rs:12:19 | ||
| | ||
LL | trait A { fn g(b: B) -> B; } | ||
| ^ `B` 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> | ||
--> $DIR/avoid-ice-on-warning-3.rs:4:14 | ||
| | ||
LL | trait B { fn f(a: A) -> A; } | ||
| - ^ ...because associated function `f` has no `self` parameter | ||
| | | ||
| this trait cannot be made into an object... | ||
help: consider turning `f` into a method by giving it a `&self` argument | ||
| | ||
LL | trait B { fn f(&self, a: A) -> A; } | ||
| ++++++ | ||
help: alternatively, consider constraining `f` so it does not apply to trait objects | ||
| | ||
LL | trait B { fn f(a: A) -> A where Self: Sized; } | ||
| +++++++++++++++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0038`. |
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 |
---|---|---|
@@ -1,17 +1,20 @@ | ||
// revisions: old new | ||
//[old] edition:2015 | ||
//[new] edition:2021 | ||
trait B { fn f(a: A) -> A; } | ||
//~^ WARN trait objects without an explicit `dyn` are deprecated | ||
//~| WARN trait objects without an explicit `dyn` are deprecated | ||
//~| WARN trait objects without an explicit `dyn` are deprecated | ||
//~| WARN this is accepted in the current edition | ||
//~| WARN this is accepted in the current edition | ||
//~| WARN this is accepted in the current edition | ||
//~| ERROR the trait `A` cannot be made into an object | ||
//~^ ERROR the trait `A` cannot be made into an object | ||
//[old]~| WARN trait objects without an explicit `dyn` are deprecated | ||
//[old]~| WARN trait objects without an explicit `dyn` are deprecated | ||
//[old]~| WARN trait objects without an explicit `dyn` are deprecated | ||
//[old]~| WARN this is accepted in the current edition | ||
//[old]~| WARN this is accepted in the current edition | ||
//[old]~| WARN this is accepted in the current edition | ||
trait A { fn g(b: B) -> B; } | ||
//~^ WARN trait objects without an explicit `dyn` are deprecated | ||
//~| WARN trait objects without an explicit `dyn` are deprecated | ||
//~| WARN trait objects without an explicit `dyn` are deprecated | ||
//~| WARN this is accepted in the current edition | ||
//~| WARN this is accepted in the current edition | ||
//~| WARN this is accepted in the current edition | ||
//~| ERROR the trait `B` cannot be made into an object | ||
//~^ ERROR the trait `B` cannot be made into an object | ||
//[old]~| WARN trait objects without an explicit `dyn` are deprecated | ||
//[old]~| WARN trait objects without an explicit `dyn` are deprecated | ||
//[old]~| WARN trait objects without an explicit `dyn` are deprecated | ||
//[old]~| WARN this is accepted in the current edition | ||
//[old]~| WARN this is accepted in the current edition | ||
//[old]~| WARN this is accepted in the current edition | ||
fn main() {} |
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,15 @@ | ||
error: return types are denoted using `->` | ||
--> $DIR/avoid-ice-on-warning.rs:4:23 | ||
| | ||
LL | fn call_this<F>(f: F) : Fn(&str) + call_that {} | ||
| ^ help: use `->` instead | ||
|
||
error[E0405]: cannot find trait `call_that` in this scope | ||
--> $DIR/avoid-ice-on-warning.rs:4:36 | ||
| | ||
LL | fn call_this<F>(f: F) : Fn(&str) + call_that {} | ||
| ^^^^^^^^^ not found in this scope | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0405`. |
12 changes: 6 additions & 6 deletions
12
...object-safety/avoid-ice-on-warning.stderr → ...ct-safety/avoid-ice-on-warning.old.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
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
// revisions: old new | ||
//[old] edition:2015 | ||
//[new] edition:2021 | ||
fn call_this<F>(f: F) : Fn(&str) + call_that {} | ||
//~^ ERROR return types are denoted using `->` | ||
//~| ERROR cannot find trait `call_that` in this scope | ||
//~| WARN trait objects without an explicit `dyn` are deprecated | ||
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! | ||
//[old]~| WARN trait objects without an explicit `dyn` are deprecated | ||
//[old]~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! | ||
fn main() {} |
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
tests/ui/object-safety/bare-trait-dont-suggest-dyn.new.fixed
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,16 @@ | ||
// revisions: old new | ||
//[old] edition:2015 | ||
//[new] edition:2021 | ||
//[new] run-rustfix | ||
// FIXME: the test suite tries to create a crate called `bare_trait_dont_suggest_dyn.new` | ||
#![crate_name="bare_trait_dont_suggest_dyn"] | ||
#![deny(bare_trait_objects)] | ||
fn ord_prefer_dot(s: String) -> impl Ord { | ||
//~^ ERROR the trait `Ord` cannot be made into an object | ||
//[old]~| ERROR trait objects without an explicit `dyn` are deprecated | ||
//[old]~| WARNING this is accepted in the current edition (Rust 2015) | ||
(s.starts_with("."), s) | ||
} | ||
fn main() { | ||
let _ = ord_prefer_dot(String::new()); | ||
} |
2 changes: 1 addition & 1 deletion
2
...safety/bare-trait-dont-suggest-dyn.stderr → ...ty/bare-trait-dont-suggest-dyn.new.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
39 changes: 39 additions & 0 deletions
39
tests/ui/object-safety/bare-trait-dont-suggest-dyn.old.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,39 @@ | ||
error: trait objects without an explicit `dyn` are deprecated | ||
--> $DIR/bare-trait-dont-suggest-dyn.rs:8: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:7:9 | ||
| | ||
LL | #![deny(bare_trait_objects)] | ||
| ^^^^^^^^^^^^^^^^^^ | ||
help: use `dyn` | ||
| | ||
LL | fn ord_prefer_dot(s: String) -> dyn Ord { | ||
| +++ | ||
|
||
error[E0038]: the trait `Ord` cannot be made into an object | ||
--> $DIR/bare-trait-dont-suggest-dyn.rs:8: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 | ||
help: consider using an opaque type instead | ||
| | ||
LL | fn ord_prefer_dot(s: String) -> impl Ord { | ||
| ++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0038`. |
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