Skip to content
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

Idea: let _ = vs _ = #77

Open
ChayimFriedman2 opened this issue Jun 1, 2023 · 0 comments · May be fixed by #82
Open

Idea: let _ = vs _ = #77

ChayimFriedman2 opened this issue Jun 1, 2023 · 0 comments · May be fixed by #82

Comments

@ChayimFriedman2
Copy link

Discovered today: both let _ = and _ = (destructuring assignment) can be used to ignore #[must_use], however because the former is a statement while the latter is an expression they have a difference with temporary lifetime extension:

struct NoisyDrop;
impl Drop for NoisyDrop {
    fn drop(&mut self) {
        println!("NoisyDrop drop");
    }
}

fn main() {
    let _ = &NoisyDrop;
    println!("after");
}

Prints:

after
NoisyDrop drop

While:

struct NoisyDrop;
impl Drop for NoisyDrop {
    fn drop(&mut self) {
        println!("NoisyDrop drop");
    }
}

fn main() {
    _ = &NoisyDrop;
    println!("after");
}

Prints:

NoisyDrop drop
after
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant