-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 #130911 - notriddle:notriddle/suggest-wrap-parens-fn-…
…pointer, r=compiler-errors diagnostics: wrap fn cast suggestions in parens when needed Fixes #121632
- Loading branch information
Showing
12 changed files
with
115 additions
and
11 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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
tests/ui/traits/fn-pointer/suggest-wrap-parens-method.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,15 @@ | ||
//@ run-rustfix | ||
|
||
trait Foo {} | ||
|
||
impl Foo for fn() {} | ||
|
||
trait Bar { | ||
fn do_stuff(&self) where Self: Foo {} | ||
} | ||
impl<T> Bar for T {} | ||
|
||
fn main() { | ||
(main as fn()).do_stuff(); | ||
//~^ ERROR the trait bound | ||
} |
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 @@ | ||
//@ run-rustfix | ||
|
||
trait Foo {} | ||
|
||
impl Foo for fn() {} | ||
|
||
trait Bar { | ||
fn do_stuff(&self) where Self: Foo {} | ||
} | ||
impl<T> Bar for T {} | ||
|
||
fn main() { | ||
main.do_stuff(); | ||
//~^ ERROR the trait bound | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/ui/traits/fn-pointer/suggest-wrap-parens-method.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,19 @@ | ||
error[E0277]: the trait bound `fn() {main}: Foo` is not satisfied | ||
--> $DIR/suggest-wrap-parens-method.rs:13:10 | ||
| | ||
LL | main.do_stuff(); | ||
| ^^^^^^^^ the trait `Foo` is not implemented for fn item `fn() {main}` | ||
| | ||
note: required by a bound in `Bar::do_stuff` | ||
--> $DIR/suggest-wrap-parens-method.rs:8:36 | ||
| | ||
LL | fn do_stuff(&self) where Self: Foo {} | ||
| ^^^ required by this bound in `Bar::do_stuff` | ||
help: the trait `Foo` is implemented for fn pointer `fn()`, try casting using `as` | ||
| | ||
LL | (main as fn()).do_stuff(); | ||
| + ++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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,10 @@ | ||
//@ run-rustfix | ||
|
||
trait Foo {} | ||
|
||
impl Foo for fn() {} | ||
|
||
fn main() { | ||
let _x: &dyn Foo = &(main as fn()); | ||
//~^ ERROR the trait bound | ||
} |
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,10 @@ | ||
//@ run-rustfix | ||
|
||
trait Foo {} | ||
|
||
impl Foo for fn() {} | ||
|
||
fn main() { | ||
let _x: &dyn Foo = &main; | ||
//~^ ERROR the trait bound | ||
} |
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[E0277]: the trait bound `fn() {main}: Foo` is not satisfied | ||
--> $DIR/suggest-wrap-parens.rs:8:24 | ||
| | ||
LL | let _x: &dyn Foo = &main; | ||
| ^^^^^ the trait `Foo` is not implemented for fn item `fn() {main}` | ||
| | ||
= note: required for the cast from `&fn() {main}` to `&dyn Foo` | ||
help: the trait `Foo` is implemented for fn pointer `fn()`, try casting using `as` | ||
| | ||
LL | let _x: &dyn Foo = &(main as fn()); | ||
| + ++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |