-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
More structured suggestions for boxed trait objects instead of impl Trait on non-coerceable tail expressions #75608
Conversation
r? @lcnr (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🤯 I am amazed at how little this affected perf. Expect a further iteration cleaning this up. |
b3b4a5e
to
df85d0d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Finished benchmarking try commit (de4f59cb4ed414ffb33a797ae2c0832cb68647a9): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
df85d0d
to
d659a4f
Compare
@@ -48,25 +54,38 @@ LL | 1u32 | |||
| | |||
= note: to return `impl Trait`, all returned values must be of the same type | |||
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits> | |||
= help: you can instead return a boxed trait object using `Box<dyn std::fmt::Display>` | |||
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move that note below the changed help message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions always come last. It's been in my backlog for a while to address that.
This comment has been minimized.
This comment has been minimized.
d47903f
to
58678ce
Compare
We still provide two errors for the case where a bare fn qux() -> dyn std::fmt::Display {
if false {
0i32
} else {
1u32 //~ ERROR `if` and `else` have incompatible types
}
}
|
58678ce
to
594f664
Compare
When encountering a `match` or `if` as a tail expression where the different arms do not have the same type *and* the return type of that `fn` is an `impl Trait`, check whether those arms can implement `Trait` and if so, suggest using boxed trait objects.
0dc8826
to
701bb76
Compare
@bors r=lcnr,varkor |
📌 Commit 701bb7651762b229bf9d1c91549168dec037d667 has been approved by |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
701bb76
to
c54b48e
Compare
44b4134
to
c6f2ddf
Compare
@bors r=lcnr,varkor |
📌 Commit c6f2ddf has been approved by |
☀️ Test successful - checks-actions, checks-azure |
…s-instead-of-impl-trait, r=compiler-errors Revive suggestions for boxed trait objects instead of impl Trait The suggestion implemented in rust-lang#75608 was not working properly, so I fixed it.
When encountering a
match
orif
as a tail expression where thedifferent arms do not have the same type and the return type of that
fn
is animpl Trait
, check whether those arms can implementTrait
and if so, suggest using boxed trait objects.
Use structured suggestion for
impl T
toBox<dyn T>
.Fix #69107