-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Terse diagnostic for never type fallback lint warning involving try operator and placeholder in path #132358
Comments
Triage: Works as intended. Edit: Let me explain. |
The "culprit" is the
The try operator match x { Ok(x) => x, Err(e) => return Err(e.into()), } Notice the So Rust <=2021 the aforementioned In Rust >=2024 we want to fall back to Footnotes |
Instead of adding - .collect::<std::io::Result<_>>()?;
+ .collect::<std::io::Result<()>>()?; |
Thanks for the detailed explanation and a nicer workaround. I cannot help but get an impression that, when this decision was being made, insufficient weight was given to the fact that a frequent and useful construct was now becoming an error. But I suppose that ship has sailed. The proposed change is indeed much better than the Finally, I'd like to point out that the diagnostic is really inadequate. I am very far from being a Rust beginner, and I was totally stumped by it. Speaking of "never type fallbacking to ()" seemed like a bug because the never type is usually associated with panicking and aborting, neither of which is not present here. A new or intermediate user will probably have no idea how to proceed given this diagnostic. If there is no such issue already, I'd like to seriously suggest that the compiler detect this issue in |
Here's a more minimal example:
I believe we can probably get a machine-applicable suggestion to change |
…k-sugg, r=WaffleLapkin Implement suggestion for never type fallback lints r? `@WaffleLapkin` Just opening this up for vibes; it's not done yet. I'd still like to make this suggestable in a few more cases before merge: - [x] Try to annotate `_` -> `()` - [x] Try to annotate local variables if they're un-annotated: `let x = ...` -> `let x: () = ...` - [x] Try to annotate the self type of a `Trait::method()` -> `<() as Trait>::method()`. The only other case we may want to suggest is a missing turbofish, like `f()` -> `f::<()>()`. That may be possible, but seems overly annoying. This partly addresses rust-lang#132358; the other half of fixing that would be to make the error message a bit better, perhaps just special casing the `?` operator 🤔 I don't think I'll do that part.
…k-sugg, r=WaffleLapkin Implement suggestion for never type fallback lints r? ``@WaffleLapkin`` Just opening this up for vibes; it's not done yet. I'd still like to make this suggestable in a few more cases before merge: - [x] Try to annotate `_` -> `()` - [x] Try to annotate local variables if they're un-annotated: `let x = ...` -> `let x: () = ...` - [x] Try to annotate the self type of a `Trait::method()` -> `<() as Trait>::method()`. The only other case we may want to suggest is a missing turbofish, like `f()` -> `f::<()>()`. That may be possible, but seems overly annoying. This partly addresses rust-lang#132358; the other half of fixing that would be to make the error message a bit better, perhaps just special casing the `?` operator 🤔 I don't think I'll do that part.
…k-sugg, r=WaffleLapkin Implement suggestion for never type fallback lints r? ```@WaffleLapkin``` Just opening this up for vibes; it's not done yet. I'd still like to make this suggestable in a few more cases before merge: - [x] Try to annotate `_` -> `()` - [x] Try to annotate local variables if they're un-annotated: `let x = ...` -> `let x: () = ...` - [x] Try to annotate the self type of a `Trait::method()` -> `<() as Trait>::method()`. The only other case we may want to suggest is a missing turbofish, like `f()` -> `f::<()>()`. That may be possible, but seems overly annoying. This partly addresses rust-lang#132358; the other half of fixing that would be to make the error message a bit better, perhaps just special casing the `?` operator 🤔 I don't think I'll do that part.
Rollup merge of rust-lang#132383 - compiler-errors:never-type-fallback-sugg, r=WaffleLapkin Implement suggestion for never type fallback lints r? ```@WaffleLapkin``` Just opening this up for vibes; it's not done yet. I'd still like to make this suggestable in a few more cases before merge: - [x] Try to annotate `_` -> `()` - [x] Try to annotate local variables if they're un-annotated: `let x = ...` -> `let x: () = ...` - [x] Try to annotate the self type of a `Trait::method()` -> `<() as Trait>::method()`. The only other case we may want to suggest is a missing turbofish, like `f()` -> `f::<()>()`. That may be possible, but seems overly annoying. This partly addresses rust-lang#132358; the other half of fixing that would be to make the error message a bit better, perhaps just special casing the `?` operator 🤔 I don't think I'll do that part.
Compiling the following function warns in Rust 1.81 and later:
I expected it to compile without warnings, as it did with previous Rust versions. It currently produces this warning:
Playground
What is particularly perplexing about this warning is that I don't understand how the never type is even involved, as nothing in the code appears to diverge.
The current workaround is to add
let () = ...
before the iteration, which compiles without warnings:While this workaround works, it feels unnecessary and it's hard to explain and justify.
The text was updated successfully, but these errors were encountered: