-
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
Improve display of error E0308 #45630
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
The output when
The help |
"did you mean `{}(/* fields */)`?", | ||
self.tcx.item_path_str(def_id) | ||
); | ||
diag.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.
Last thing and this will be ready for merging (r=me), could you change diag.help(&message)
here for span_label(cause.span, &message)
?
That way the output will be:
error[E0308]: mismatched types
--> $DIR/issue-35241.rs:13:20
|
13 | fn test() -> Foo { Foo }
| --- ^^^
| | |
| | expected struct `Foo`, found fn item
| | did you mean `Foo(/* fields */)`?
| |
| expected `Foo` because of return type
|
= note: expected type `Foo`
found type `fn(u32) -> Foo {Foo::{{constructor}}}`
Also, while you're at it, could you squash your PR into a single commit?
Improve the display of error E0308 for structs by adding a "did you mean" span label.
@bors r+ |
📌 Commit 87c951d has been approved by |
Improve display of error E0308 Ref. Forgetting to call a variant constructor causes a confusing error message #35241. This PR modifies [`note_type_err`](https://github.com/rust-lang/rust/blob/b7041bfab3a83702a8026fb7a18d8ea7d54cc648/src/librustc/infer/error_reporting/mod.rs#L669-L674) to display a `help` message when a `TyFnPtr` or `TyFnDef` are found and the return type, of the function or function pointer, is the same as the type that is expected. The output of compiling ```rust struct Foo(u32); fn test() -> Foo { Foo } fn main() {} ``` is now ```bash $ rustc src/test/ui/issue-35241.rs error[E0308]: mismatched types --> src/test/ui/issue-35241.rs:13:20 | 13 | fn test() -> Foo { Foo } | --- ^^^ expected struct `Foo`, found fn item | | | expected `Foo` because of return type | = help: did you mean `Foo { /* fields */ }`? = note: expected type `Foo` found type `fn(u32) -> Foo {Foo::{{constructor}}}` error: aborting due to previous error ```
☀️ Test successful - status-appveyor, status-travis |
Ref. Forgetting to call a variant constructor causes a confusing error message #35241.
This PR modifies
note_type_err
to display ahelp
message when aTyFnPtr
orTyFnDef
are found and the return type, of the function or function pointer, is the same as the type that is expected.The output of compiling
is now