forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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#120275 - estebank:issue-120241, r=fmease
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 rust-lang#120241.
- Loading branch information
Showing
16 changed files
with
222 additions
and
126 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`. |
Oops, something went wrong.