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

new lint: double reverse #3416

Open
matthiaskrgr opened this issue Nov 6, 2018 · 2 comments
Open

new lint: double reverse #3416

matthiaskrgr opened this issue Nov 6, 2018 · 2 comments

Comments

@matthiaskrgr
Copy link
Member

simple example:

let v: Vec<i32> = vec![4, 1, 4,3,5,6];
v.reverse();
v.reverse();
prinln!("{:?}", v);

example involving function:

pub fn main() {
   let mut v: Vec<i32> = vec![4, 1, 4,3,5,6];
   v.sort();
   let mut v2 = foo(v);
   v2.reverse();
   println!("{:?}", v2);
}

pub fn foo(a: Vec<i32>) -> Vec<i32> {
    let mut b = a;
    b.reverse();
    b
}
@oli-obk
Copy link
Contributor

oli-obk commented Nov 7, 2018

idk, feels a little contrived. Also, is it guaranteed to be idempotent? For fancy impls of PartialOrd we might not actually get back the same result and users might be using it for that.

@matthiaskrgr
Copy link
Member Author

Imo double reverse is still worth investigating, so this lint is not meant as "look, this is wrong!" but rather as "hey, this is suspicious, maybe check it out?".
Could be a pedantic or nursery lint.

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

No branches or pull requests

2 participants