Account for common impl Trait/dyn Trait return type errors#68195
Account for common impl Trait/dyn Trait return type errors#68195bors merged 15 commits intorust-lang:masterfrom
impl Trait/dyn Trait return type errors#68195Conversation
|
Some changes occurred in diagnostic error codes |
|
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
|
The changes have reasonable single commit sizes, but the final diff is on the larger side. CC @rust-lang/wg-diagnostics |
9498bc0 to
7f95375
Compare
This comment has been minimized.
This comment has been minimized.
|
r? @oli-obk |
src/test/ui/const-generics/array-impls/into-iter-no-impls-length-33.stderr
Outdated
Show resolved
Hide resolved
6ed3e32 to
8ed4fc8
Compare
This comment has been minimized.
This comment has been minimized.
src/test/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr
Outdated
Show resolved
Hide resolved
|
r? @Centril (reflecting reality here) |
|
I'm looking at addressing the cases where The |
This comment has been minimized.
This comment has been minimized.
e09d187 to
1a686f9
Compare
This comment has been minimized.
This comment has been minimized.
Suggest `impl Trait` when possible, and `Box<dyn Trait>` otherwise.
When a type error involves a `dyn Trait` as the return type, do not emit the type error, as the "return type is not `Sized`" error will provide enough information to the user.
1a686f9 to
00e2626
Compare
|
@bors r+ |
|
📌 Commit 029a9c6 has been approved by |
Account for common `impl Trait`/`dyn Trait` return type errors - When all return paths have the same type, suggest `impl Trait`. - When all return paths implement the expected `trait`, suggest `Box<dyn Trait>` and mention using an `enum`. - When multiple different types are returned and `impl Trait` is expected, extend the explanation. - When return type is `impl Trait` and the return paths do not implement `Trait`, point at the returned values. - Split `src/librustc/traits/error_reporting.rs` into multiple files to keep size under control. Fix rust-lang#68110, cc rust-lang#66523.
Rollup of 6 pull requests Successful merges: - #67956 (Detail transitive containment in E0588 diagnostic) - #68153 (resolve: Point at the private item definitions in privacy errors) - #68195 (Account for common `impl Trait`/`dyn Trait` return type errors) - #68288 (Fix some of the rustfmt fallout in Miri) - #68292 (don't clone types that are copy) - #68301 (Don't propagate __RUST_TEST_INVOKE to subprocess) Failed merges: r? @ghost
|
Do we have an issue for changing the "return type cannot be a bare trait" language to something more |
|
It should be "unboxed trait object". Don't think there's a ticket. |
Further improve `impl Trait`/`dyn Trait` suggestions After reading [_Returning Trait Objects_ by Bryce Fisher-Fleig](https://bryce.fisher-fleig.org/blog/returning-trait-objects/), [I noticed that](https://www.reddit.com/r/rust/comments/esueur/returning_trait_objects/ffczl4k/) rust-lang#68195 had a few bugs due to not ignoring `ty::Error`. - Account for `ty::Error`. - Account for `if`/`else` and `match` blocks when pointing at return types and referencing their types. - Increase the multiline suggestion output from 6 lines to 20.
Further improve `impl Trait`/`dyn Trait` suggestions After reading [_Returning Trait Objects_ by Bryce Fisher-Fleig](https://bryce.fisher-fleig.org/blog/returning-trait-objects/), [I noticed that](https://www.reddit.com/r/rust/comments/esueur/returning_trait_objects/ffczl4k/) #68195 had a few bugs due to not ignoring `ty::Error`. - Account for `ty::Error`. - Account for `if`/`else` and `match` blocks when pointing at return types and referencing their types. - Increase the multiline suggestion output from 6 lines to 20.




impl Trait.trait, suggestBox<dyn Trait>and mention using anenum.impl Traitis expected, extend the explanation.impl Traitand the return paths do not implementTrait, point at the returned values.src/librustc/traits/error_reporting.rsinto multiple files to keep size under control.Fix #68110, cc #66523.