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

Possible false positive with let_and_return #3324

Closed
jeffrey-xiao opened this issue Oct 16, 2018 · 2 comments · Fixed by #5680
Closed

Possible false positive with let_and_return #3324

jeffrey-xiao opened this issue Oct 16, 2018 · 2 comments · Fixed by #5680
Labels
C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@jeffrey-xiao
Copy link

jeffrey-xiao commented Oct 16, 2018

The following code works but returns a clippy lint error: https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=2417f60b483ac63fd3ffd90b66d6db16

warning: returning the result of a let binding from a block. Consider returning the expression directly.
 --> src/main.rs:7:5
  |
7 |     ret
  |     ^^^
  |
  = note: #[warn(clippy::let_and_return)] on by default
note: this expression can be directly returned
 --> src/main.rs:6:15
  |
6 |     let ret = foo.borrow().baz();
  |               ^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#let_and_return

When using the suggestion of clippy to remove the let, it fails to compile: https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=285ab39429037278c362bbb6d7ffddf6

error[E0597]: `foo` does not live long enough
 --> src/main.rs:6:5
  |
6 |     foo.borrow().baz()
  |     ^^^ borrowed value does not live long enough
7 | }
  | - `foo` dropped here while still borrowed
  |
  = note: values in a scope are dropped in the opposite order they are created

error: aborting due to previous error

For more information about this error, try `rustc --explain E0597`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.
@phansch phansch added C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions labels Dec 11, 2018
@jorpic
Copy link
Contributor

jorpic commented Dec 27, 2018

Seems this is a duplicate of #2904

@flip1995
Copy link
Member

Not exactly a duplicate of #2904, since this suggestion also errors with nll enabled, while #2904 works with nll

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 L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants