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

needless borrow does not trigger on block trailing expression #1726

Closed
oli-obk opened this issue May 5, 2017 · 1 comment · Fixed by #7977
Closed

needless borrow does not trigger on block trailing expression #1726

oli-obk opened this issue May 5, 2017 · 1 comment · Fixed by #7977
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-negative Issue: The lint should have been triggered on code, but wasn't T-middle Type: Probably requires verifiying types

Comments

@oli-obk
Copy link
Contributor

oli-obk commented May 5, 2017

    let x = 5;
    let foo = match 42 {
        44 => &x,
        45 => {
            println!("foo");
            &&x // does not trigger needless_borrow
        },
        46 => &&x, // triggers needless_borrow
        _ => panic!(),
    };
@oli-obk oli-obk added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages T-middle Type: Probably requires verifiying types labels May 5, 2017
@oli-obk
Copy link
Contributor Author

oli-obk commented May 5, 2017

Ok... so this doesn't trigger on any expression where the location of the autoderef is disconnected from the location of the address-taking. In the match example, the issue is probably in the expansion of match arms.

e.g.

    let intermediate = &&5;
    let b: &i32 = intermediate; // doesn't lint
    let c: &i32 = &&5; // lints

This just became much harder to solve.

Any complaints about a lint on locals with &&T type which are only ever used by (auto-)derefing? The suggestion would be to deref at the initialization site instead of at each use site.

@camsteffen camsteffen added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Nov 13, 2021
@bors bors closed this as completed in 2776076 Nov 18, 2021
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 C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-negative Issue: The lint should have been triggered on code, but wasn't T-middle Type: Probably requires verifiying types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants