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

Rescope temp lifetime in let-chain into IfElse #107251

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dingxiangfei2009
Copy link
Contributor

@dingxiangfei2009 dingxiangfei2009 commented Jan 24, 2023

This is a proposal born out of #103108 as a potential answer to #104843.

Three tests are failing from this.

  • tests/ui/drop/drop_order.rs
  • tests/ui/mir/mir_let_chains_drop_order.rs
  • tests/ui/nll/issue-54556-niconii.rs

The first two tests fail because of the change of drop order as intended by this PR. The third test is because the program compiles instead.

@rustbot
Copy link
Collaborator

rustbot commented Jan 24, 2023

r? @oli-obk

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 24, 2023
@rust-log-analyzer

This comment has been minimized.

@dingxiangfei2009
Copy link
Contributor Author

cc @est31

I have tested this branch on several of my repositories that I am working on and nothing obvious has broken. Shall we have a crater run?

@est31
Copy link
Member

est31 commented Jan 29, 2023

@bors try

@bors
Copy link
Contributor

bors commented Jan 29, 2023

⌛ Trying commit 003f3cd8d3cecb9b20f5105400499741c936e92a with merge ece70b22820429ebf0c6d388c32356a14c58fc2f...

@bors
Copy link
Contributor

bors commented Jan 29, 2023

☀️ Try build successful - checks-actions
Build commit: ece70b22820429ebf0c6d388c32356a14c58fc2f (ece70b22820429ebf0c6d388c32356a14c58fc2f)

@dingxiangfei2009
Copy link
Contributor Author

I have updated the failing tests to show the effect of this change.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@oli-obk

This comment was marked as resolved.

@craterbot

This comment was marked as resolved.

@dingxiangfei2009

This comment was marked as resolved.

@craterbot

This comment was marked as resolved.

@oli-obk

This comment was marked as resolved.

@craterbot

This comment was marked as resolved.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 30, 2023

@craterbot run mode=build-and-test

@craterbot
Copy link
Collaborator

👌 Experiment pr-107251 created and queued.
🤖 Automatically detected try build ece70b22820429ebf0c6d388c32356a14c58fc2f
⚠️ Try build based on commit 003f3cd8d3cecb9b20f5105400499741c936e92a, but latest commit is 92550dd. Did you forget to make a new try build?
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 30, 2023
@craterbot
Copy link
Collaborator

🚧 Experiment pr-107251 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-107251 is completed!
📊 128 regressed and 99 fixed (253904 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jan 31, 2023
@traviscross
Copy link
Contributor

@rustbot labels +S-waiting-on-author

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 25, 2023
@est31
Copy link
Member

est31 commented Oct 28, 2023

@nikomatsakis thanks for the response and thanks for the discussion in the lang team.

I will try to make a writeup the next rainy weekend I encounter (I'm sure there will be one soon, this is the season for the rains in my area ☔).

Some preliminary comments: I think it's great to have an RFC about a general effort to limit lifetimes, as I'm sure there is more potential about too long lifetimes. But I don't think we should block let chains on this greater effort. I regularly encounter cases where I'm writing nested if's where let chains would have allowed me to collapse a level.

Given that this change is smaller in scope than the RFC, we might get away way more easily with not doing this in an edition bump.


Side note: regarding your blog post, I recently touched Go, and wanted to to specify an *int via a literal. It was weird to me that Go complained about &42 but was fine with v := 42 followed by &v. Keeping &42 working in Rust would be nice.

@bors
Copy link
Contributor

bors commented Nov 1, 2023

☔ The latest upstream changes (presumably #113970) made this pull request unmergeable. Please resolve the merge conflicts.

@bstrie bstrie added the A-edition-2024 Area: The 2024 edition label Nov 27, 2023
@oli-obk oli-obk assigned est31 and unassigned oli-obk Jan 10, 2024
@Dylan-DPC Dylan-DPC removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 6, 2024
@traviscross
Copy link
Contributor

@rustbot labels +I-lang-nominated

Let's discuss to confirm that we do not want to use Rust 2024 for this, as had been discussed above.

@rustbot rustbot added the I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. label Apr 10, 2024
@traviscross
Copy link
Contributor

@rustbot labels -I-lang-nominated

We discussed this in the lang meeting today. The consensus was that we'd like this to land in nightly with a feature gate. After that, we'd like to see the result of crater runs and some analysis of the migration story so we can consider landing this in an edition. This may also call for an RFC.

@rustbot rustbot removed the I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. label Apr 17, 2024
@dingxiangfei2009
Copy link
Contributor Author

I am going to propose if_let_rescope as the feature gate in front of this change.

@rust-log-analyzer

This comment has been minimized.

@dingxiangfei2009
Copy link
Contributor Author

dingxiangfei2009 commented May 11, 2024

I am thinking of running a crater experiment with +rustflags=... or something to force rustc to assume if_let_rescope feature. I am unaware of such an option so far.

@est31
Copy link
Member

est31 commented May 12, 2024

I don't think a crater experiment would be helpful here if the code is just for edition 2024. There is practically no crate out there with edition 2024. Forcing code onto edition 2024 will give problems as well because 2018 code will then also have the 2021 warnings and even more different for 2015 code.

@ehuss
Copy link
Contributor

ehuss commented May 14, 2024

I am thinking of running a crater experiment with +rustflags=... or something to force rustc to assume if_let_rescope feature. I am unaware of such an option so far.

If your goal is to see what would fail with the feature enabled, the best thing to do is to temporarily modify your PR to make it always enabled. Essentially change it to something like let mut rvalue_scopes = RvalueScopes::new(true);.

@dingxiangfei2009 dingxiangfei2009 force-pushed the let-chain-rescope branch 2 times, most recently from 25a9024 to c13eb60 Compare May 15, 2024 16:12
bors added a commit to rust-lang-ci/rust that referenced this pull request May 16, 2024
…rater-runner, r=<try>

[Crater run experiment] let-chain rescoping

Please do not merge this PR. This is only for crater run experimentation.

I would like to nominate a crater run for rust-lang#107251 assuming that the feature gate is always on. Through this experiment, we hope to collect breakage in the wild. We would focus on both compilation errors and test errors that this edition change can lead to, if users are targeting Edition 2024 and writing code assuming the old semantics unknowingly.

I realise that some tests may not work well if an edition switch happens. I am fixing them in the main PR.
@traviscross
Copy link
Contributor

@rustbot labels +I-lang-nominated

This PR is about shortening, over an edition, the scope of temporary lifetimes in if-let scrutinees so that they end before the else block. The current rules are a particular problem for let-chains which we hope to stabilize.

We last discussed this on 2023-10-25. We had some questions about the migration story here and specific asks for further analysis.

Since then, Ding has done a crater run:

And on the basis of that, has assembled a report analyzing the results and discussing the migration strategy:

Let's nominate to discuss.

@rustbot rustbot added the I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. label Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2024 Area: The 2024 edition I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet