-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Preserve brackets around if-lets and skip while-lets #131035
Preserve brackets around if-lets and skip while-lets #131035
Conversation
On a side note, I think the migration suggestions on unsafe attributes are broken. If we run edition migration, the |
@rustbot labels +A-edition-2024 |
Yes, I believe in general we want to check all spans (incl. their subspans) for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this LGTM in general, I have some cases that we may want to add a test or two for (trying really hard to come up with something that might break this logic).
@rustbot author |
@rustbot ready
|
Now we are checking all the span. We bail out of emitting a suggestion because I think the fix will not be successful if any of them is not a part of a continuous user source span. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, you can r=me after PR CI is green.
@bors delegate+ |
✌️ @dingxiangfei2009, you can now approve this pull request! If @jieyouxu told you to " |
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#131023 (Copy correct path to clipboard for modules/keywords/primitives) - rust-lang#131035 (Preserve brackets around if-lets and skip while-lets) - rust-lang#131038 (Fix `adt_const_params` leaking `{type error}` in error msg) - rust-lang#131053 (Improve `--print=check-cfg` documentation) - rust-lang#131056 (enable compiler fingerprint logs in verbose mode) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#131035 - dingxiangfei2009:tweak-if-let-rescope-lint, r=jieyouxu Preserve brackets around if-lets and skip while-lets r? `@jieyouxu` Tracked by rust-lang#124085 Fresh out of rust-lang#129466, we have discovered 9 crates that the lint did not successfully migrate because the span of `if let` includes the surrounding brackets `(..)` like the following, which surprised me a bit. ```rust if (if let .. { .. } else { .. }) { // ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // the span somehow includes the surrounding brackets } ``` There is one crate that failed the migration because some suggestion spans cross the macro expansion boundaries. Surely there is no way to patch them with `match` rewrite. To handle this case, we will instead require all spans to be tested for admissibility as suggestion spans. Besides, there are 4 false negative cases discovered with desugared-`while let`. We don't need to lint them, because the `else` branch surely contains exactly one statement because the drop order is not changed whatsoever in this case. ```rust while let Some(value) = droppy().get() { .. } // is desugared into loop { if let Some(value) = droppy().get() { .. } else { break; // here can be nothing observable in this block } } ``` I believe this is the one and only false positive that I have found. I think we have finally nailed all the corner cases this time.
r? @jieyouxu
Tracked by #124085
Fresh out of #129466, we have discovered 9 crates that the lint did not successfully migrate because the span of
if let
includes the surrounding brackets(..)
like the following, which surprised me a bit.There is one crate that failed the migration because some suggestion spans cross the macro expansion boundaries. Surely there is no way to patch them with
match
rewrite. To handle this case, we will instead require all spans to be tested for admissibility as suggestion spans.Besides, there are 4 false negative cases discovered with desugared-
while let
. We don't need to lint them, because theelse
branch surely contains exactly one statement because the drop order is not changed whatsoever in this case.I believe this is the one and only false positive that I have found. I think we have finally nailed all the corner cases this time.