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

let_and_return : false positive #1642

Closed
wagnerf42 opened this issue Mar 28, 2017 · 5 comments
Closed

let_and_return : false positive #1642

wagnerf42 opened this issue Mar 28, 2017 · 5 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@wagnerf42
Copy link

wagnerf42 commented Mar 28, 2017

false positive for let and return (possible linked to #848)
commented version works but generate clippy's warning.
given version does not compile:

error: `h` does not live long enough
 --> src/main.rs:9:1
  |
6 |     h.drain().map(|(_, v)| v).collect()
  |     - borrow occurs here
...
9 | }
  | ^ `h` dropped here while still borrowed
  |
  = note: values in a scope are dropped in the opposite order they are created

source code:

use std::collections::HashMap;
fn vecto() -> Vec<u32> {
    let mut h = HashMap::new();
    h.insert(1000, 3);
    h.insert(10000, 4);
    h.drain().map(|(_, v)| v).collect()
    //let r = h.drain().map(|(_, v)| v).collect();
    //r
}

fn main() {
    let v = vecto();
    println!("{:?}", v);
}
@oli-obk oli-obk added the C-bug Category: Clippy is not doing the correct thing label Mar 28, 2017
@tnielens
Copy link
Contributor

tnielens commented Sep 3, 2017

The following block added in let_return.rs compiles and pass clippy tests. Some compiler issue must have been fixed.

use std::collections::HashMap;
fn vecto() -> Vec<u32> {
    #![allow(unreadable_literal)]
    let mut h = HashMap::new();
    h.insert(1000, 3);
    h.insert(10000, 4);
    h.drain().map(|(_, v)| v).collect()
    //let r = h.drain().map(|(_, v)| v).collect();
    //r
}

fn main() {
    let v = vecto();
    println!("{:?}", v);
}

@oli-obk
Copy link
Contributor

oli-obk commented Sep 4, 2017

@montrivo: I cannot confirm this. It is still broken on nightly: https://play.rust-lang.org/?gist=fa10281cc3811a555cda285c819db964&version=nightly

@tnielens
Copy link
Contributor

tnielens commented Sep 4, 2017

Ok. Are the test files somehow not thoroughly compiled?

@oli-obk
Copy link
Contributor

oli-obk commented Sep 4, 2017

If an error happens in the AST, no HIR lints are reported

@ebroto
Copy link
Member

ebroto commented Jun 4, 2020

This issue can be closed as the suggestion builds in current stable, see here

EDIT: invalid link

@flip1995 flip1995 closed this as completed Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

5 participants