-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Description
This issue tracks the release notes text for #147382.
cc @joshtriplett, @fmease -- original issue/PR authors and assignees for drafting text
See the forge.rust-lang.org chapter about release notes for an overview of how the release team makes use of these tracking issues.
Release notes text
This section should be edited to specify the correct category(s) for the change, with succinct description(s) of what changed. Some things worth considering:
- Does this need an additional compat notes section?
- Was this a libs stabilization that should have additional headers to list new APIs under
Stabilized APIs
andConst Stabilized APIs
?
# Language
- The `unused_must_use` lint no longer warns on `Result<(), Uninhabited>` (for instance, `Result<(), !>`), or `ControlFlow<Uninhabited, ()>`. This avoids having to check for an error that can never happen. [unused_must_use: Don't warn on `Result<(), Uninhabited>` or `ControlFlow<Uninhabited, ()>`](https://github.com/rust-lang/rust/pull/147382)
Tip
Use the previous releases for inspiration on how to write the release notes text and which categories to pick.
Release blog section
If this change is notable enough for inclusion in the blog post then this section should be edited to contain a draft for the blog post. Otherwise leave it empty.
### `unused_must_use` no longer warns about `Result<(), UninhabitedType>`
Rust's `unused_must_use` lint warns when ignoring the return value of a function, if the function or its return type is annotated with `#[must_use]`. For instance, this warns if ignoring a return type of `Result`, to remind you to use `?`, or something like `.expect("...")`.
However, some functions return `Result`, but the error type they use is not actually "inhabited", meaning it can never exist in real code (e.g. the [`!`](https://doc.rust-lang.org/std/primitive.never.html) or [`Infallible`](https://doc.rust-lang.org/std/convert/enum.Infallible.html) types).
The `unused_must_use` lint now no longer warns on `Result<(), UninhabitedType>`, or on `ControlFlow<UninhabitedType, ()>`. For instance, it will not warn on `Result<(), !>`. This avoids having to check for an error that can never happen.
```rust
fn can_never_fail() -> Result<(), !> {
// ...
Ok(())
}
fn main() {
can_never_fail()
}
```
This is particularly useful with the common pattern of a trait with an associated error type, where the error type may *sometimes* be infallible:
```rust
trait UsesAssocErrorType {
type Error;
fn method(&self) -> Result<(), Self::Error>;
}
struct CannotFail;
impl UsesAssocErrorType for CannotFail {
type Error = !;
fn method(&self) -> Result<(), Self::Error> {
Ok(())
}
}
struct CanFail;
impl UsesAssocErrorType for CanFail {
type Error = std::io::Error;
fn method(&self) -> Result<(), Self::Error> {
Err(std::io::Error::other("something went wrong"))
}
}
fn main() {
CannotFail.method(); // No error
CanFail.method(); // Error: unused `Result` that must be used
}
```
Note
If a blog post section is required the release-blog-post
label should be added (@rustbot label +release-blog-post
) to this issue as otherwise it may be missed by the release team.