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

Section on temporary order unclear #985

Open
Manishearth opened this issue Mar 19, 2021 · 1 comment
Open

Section on temporary order unclear #985

Manishearth opened this issue Mar 19, 2021 · 1 comment

Comments

@Manishearth
Copy link
Member

Apart from lifetime extension, the temporary scope of an expression is the smallest scope that contains the expression and is for one of the following:

  • The entire function body.
  • A statement.
  • The body of a if, while or loop expression.
    ...

https://doc.rust-lang.org/reference/destructors.html#temporary-scopes

I'm ... not really sure what "is for one of the following" means here? I can make an educated guess, but this section reads really weirdly. Perhaps it could be clarified?

cc @eddyb @oli-obk you probably know what this should say at a technical level

@Manishearth
Copy link
Member Author

A relevant example for this is https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=08b6246faa0dea1ad815e1f6e6fd52b8

if PrintOnDrop("a").0 != "a" || PrintOnDrop("b").0 != "b" || PrintOnDrop("c").0 == "c" {
 // body
}

// prints b c a

What's going on here, as far as I can tell, is that a's scope gets "extended" twice, once to cover its lazy boolean expressions, and once to cover the if. But the reference text as written is not sufficient to explain this

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

1 participant