-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Forgetting to call a variant constructor causes a confusing error message #35241
Comments
The error message mentions function items, which is confusing to new users. |
Changed error message for enum variants Fixes #35241 r? @jonathandturner
Changed error message for enum variants Fixes #35241 r? @jonathandturner
non-fn-like structs have better output, we should perform the same for fn-like structs:
|
Mentoring instructions:In |
Has anyone worked on this recently? I might take a crack at it. New to Rust but I'd like to learn, and start getting involved with OSS. Let me know if there are any conflicts, or if anyone is able to give me some guidance. Thanks! :) |
@colinmarsh19 go ahead! The terse explanation above should give enough context for someone slightly familiar with the compiler, but if you need more help you can always reach out with a comment in this ticket, on gitter or by creating a PR for us to comment on your code directly. |
@colinmarsh19 are you currently working on this? If not I would like to give it a go :) |
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 ```
I believe this issue has been fixed in #45630. |
Tweak mismatched types error - Change expected/found for type mismatches in `break` - Be more accurate when talking about diverging match arms - Tweak wording of function without a return value - Suggest calling bare functions when their return value can be coerced to the expected type - Give more parsing errors when encountering `foo(_, _, _)` Fix rust-lang#51767, fix rust-lang#62677, fix rust-lang#63136, cc rust-lang#37384, cc rust-lang#35241.
Tweak mismatched types error - Change expected/found for type mismatches in `break` - Be more accurate when talking about diverging match arms - Tweak wording of function without a return value - Suggest calling bare functions when their return value can be coerced to the expected type - Give more parsing errors when encountering `foo(_, _, _)` Fix rust-lang#51767, fix rust-lang#62677, fix rust-lang#63136, cc rust-lang#37384, cc rust-lang#35241.
Tweak mismatched types error - Change expected/found for type mismatches in `break` - Be more accurate when talking about diverging match arms - Tweak wording of function without a return value - Suggest calling bare functions when their return value can be coerced to the expected type - Give more parsing errors when encountering `foo(_, _, _)` Fix rust-lang#51767, fix rust-lang#62677, fix rust-lang#63136, cc rust-lang#37384, cc rust-lang#35241, cc rust-lang#51669.
Tweak mismatched types error - Change expected/found for type mismatches in `break` - Be more accurate when talking about diverging match arms - Tweak wording of function without a return value - Suggest calling bare functions when their return value can be coerced to the expected type - Give more parsing errors when encountering `foo(_, _, _)` Fix rust-lang#51767, fix rust-lang#62677, fix rust-lang#63136, cc rust-lang#37384, cc rust-lang#35241, cc rust-lang#51669.
Tweak mismatched types error - Change expected/found for type mismatches in `break` - Be more accurate when talking about diverging match arms - Tweak wording of function without a return value - Suggest calling bare functions when their return value can be coerced to the expected type - Give more parsing errors when encountering `foo(_, _, _)` Fix rust-lang#51767, fix rust-lang#62677, fix rust-lang#63136, cc rust-lang#37384, cc rust-lang#35241, cc rust-lang#51669.
STR
Confusing result
The text was updated successfully, but these errors were encountered: