Skip to content

some small doc improvements #1951

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

Merged
merged 1 commit into from
Aug 13, 2017
Merged

some small doc improvements #1951

merged 1 commit into from
Aug 13, 2017

Conversation

llogiq
Copy link
Contributor

@llogiq llogiq commented Aug 12, 2017

No description provided.

@oli-obk oli-obk merged commit adae2bb into master Aug 13, 2017
@oli-obk oli-obk deleted the doc_improvements branch August 13, 2017 19:02
@llogiq llogiq restored the doc_improvements branch September 1, 2017 19:42
@moxian
Copy link

moxian commented Aug 1, 2020

Hi, @llogiq , do you remember in what situations removing the return may run afoul of the borrow checker? Was there an issue to rust-lang/rust repo to get it fixed?
This PR was filed 3 years ago, is it possible that the issue was fixed once NLL landed?

Thanks!

@ebroto
Copy link
Member

ebroto commented Aug 1, 2020

@moxian for example this code:

#![allow(unused)]

fn read_line() -> String {
    use std::io::BufRead;
    let stdin = ::std::io::stdin();
    return stdin.lock().lines().next().unwrap().unwrap();
}

(playground)

triggers the lint, but applying the suggestion causes this error

error[E0597]: `stdin` does not live long enough

(playground)

This happens because usually temporaries are dropped at the end of the statement, but in a block tail expression they are dropped after the locals of the block have been destroyed, triggering the lifetime error.

I recall seeing multiple issues on the rust-lang repo of users confused by this, but AFAIK this is well-known behavior, not solved by NLL.

BTW you make me think this was fixed in #5680 for the let_and_return lint and I think the same fix can be applied for needless_return. I'll open an issue soon.

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 this pull request may close these issues.

4 participants