Skip to content

Allow unused_must_use on result with never type #65861

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

Open
TheZoq2 opened this issue Oct 27, 2019 · 2 comments
Open

Allow unused_must_use on result with never type #65861

TheZoq2 opened this issue Oct 27, 2019 · 2 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. F-never_type `#![feature(never_type)]` T-lang Relevant to the language team

Comments

@TheZoq2
Copy link
Contributor

TheZoq2 commented Oct 27, 2019

#![feature(never_type)]

fn will_not_fail() -> Result<i32, !> {
    Ok(5)
}

pub fn main() {
    will_not_fail();
}

This code yields a warning:

warning: unused `std::result::Result` that must be used
 --> main.rs:8:5
  |
8 |     will_not_fail();
  |     ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_must_use)]` on by default
  = note: this `Result` may be an `Err` variant, which should be handled

However since a Result<T, !> can never have the Err branch, having to handle the resulting error seems kind of pointless. Would it be possible to disable the unused_must_use lint for this particular case?

@TeXitoi
Copy link
Contributor

TeXitoi commented Oct 27, 2019

I'd prefer to have a get method:

impl<T> Result<T, !> {
    pub fn get(self) -> T {
        // can't panic
        self.unwrap()
    }
}

@jonas-schievink jonas-schievink added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-lang Relevant to the language team F-never_type `#![feature(never_type)]` labels Oct 27, 2019
@RustyYato
Copy link
Contributor

RustyYato commented Oct 30, 2019

@TeXitoi to be more explicit about what we are doing, we can do

impl<T> Result<T, !> {
    pub fn get(self) -> T {
        match self {
            Ok(value) => value,
            Err(never) => never
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. F-never_type `#![feature(never_type)]` T-lang Relevant to the language team
Projects
None yet
Development

No branches or pull requests

4 participants