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

Lint on tail expr drop order change in Edition 2024 #128662

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

dingxiangfei2009
Copy link
Contributor

@dingxiangfei2009 dingxiangfei2009 commented Aug 4, 2024

This lint warns users to consider extra discretion on the effect of a transposed drop order arising from Edition 2024, which involves temporaries in tail expression location with significant drop implementation.

cc @traviscross

Tracking:

@rustbot
Copy link
Collaborator

rustbot commented Aug 4, 2024

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Aug 4, 2024
@rust-log-analyzer

This comment has been minimized.

@jieyouxu jieyouxu added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Aug 5, 2024
@dingxiangfei2009 dingxiangfei2009 force-pushed the lint-tail-expr-drop-order branch 2 times, most recently from a7c38d1 to f5043b7 Compare August 5, 2024 21:29
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@traviscross
Copy link
Contributor

r? compiler

This is an edition item.

@rustbot rustbot assigned jieyouxu and unassigned TaKO8Ki Aug 13, 2024
@jieyouxu
Copy link
Member

Thanks for the PR. I'm taking a look at this now, but I'm going to read back some of the context first.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good to me in general. I have some discussions / questions and suggestions (for doc clarity and test coverage).

compiler/rustc_lint/messages.ftl Show resolved Hide resolved
Comment on lines +16 to +21
/// The `tail_expr_drop_order` lint looks for those values generated at the tail expression location, that of type
/// with a significant `Drop` implementation, such as locks.
/// In case there are also local variables of type with significant `Drop` implementation as well,
/// this lint warns you of a potential transposition in the drop order.
/// Your discretion on the new drop order introduced by Edition 2024 is required.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion: this wording is a bit unclear to me. Maybe something to the effect of:

The tail_expr_drop_order lint looks for potential transposition of the drop order before and after Edition 2024 between:

  1. values whose types have significant Drop implementations, which are generated at tail expression positions, and
  2. local variables whose types have significant Drop implementation as well.

The transposition of drop order introduced in Edition 2024 warrants your attention,
as it may change observable behavior and thus your intention.

(Or some better wording to that effect)

I think we also want to clarify or define what "significant Drop implementation" means here as well, does this mean "Drop implementation with side effects", or is there a more technically accurate description that would align with e.g. the reference?

AFAICT, the "significant" terminology comes from the internal has_significant_drop method on Ty (please correct me if this is well-defined elsewhere like in the reference), but it's not super obvious what this means even looking at the impl in rustc_middle, let alone for regular users.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This is not a blocking concern, we can always fine-tune the wording later.)

compiler/rustc_lint/src/tail_expr_drop_order.rs Outdated Show resolved Hide resolved
compiler/rustc_lint/src/tail_expr_drop_order.rs Outdated Show resolved Hide resolved
tests/ui/drop/lint-tail-expr-drop-order.rs Outdated Show resolved Hide resolved
tests/ui/drop/lint-tail-expr-drop-order.rs Show resolved Hide resolved
@jieyouxu
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2024
@rust-log-analyzer

This comment has been minimized.

@dingxiangfei2009
Copy link
Contributor Author

There is some issue with compiletest and I am investigating 👀

@dingxiangfei2009 dingxiangfei2009 force-pushed the lint-tail-expr-drop-order branch 2 times, most recently from 3ec54c4 to 28d804e Compare August 20, 2024 12:07
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 20, 2024
@jieyouxu
Copy link
Member

Thanks, the rest looks good to me now, just the edition/feature double-gating that needs to be addressed.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest looks good to me, but I just realized one thing: we should add an ui test with three revisions for negative gating checks //@ revisions: neither no_feature_gate edition_less_than_2024:

  1. neither: //@[neither] edition: 2021 and #![cfg_attr(neither, shorter_tail_lifetimes)]; check lint does not fire
  2. no_feature_gate: //@[no_feature_gate] edition: 2024; check lint does not fire
  3. edition_less_than_2024: //@[edition_less_than_2024] edition: 2021 and #![cfg_attr(edition_less_than_2024, shorter_tail_lifetimes)]; check lint does not fire

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! Let me double-check if we're missing anything from previous review comments, then we can send this off to the merge queue ^^

@jieyouxu
Copy link
Member

jieyouxu commented Aug 20, 2024

Ok this LGTM now, r=me once PR CI is green.

@jieyouxu
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 20, 2024

📌 Commit ef25fbd has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 20, 2024
@jieyouxu
Copy link
Member

(Not tagging relnotes as I expect this to be announced alongside Edition 2024.)

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 20, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#128662 (Lint on tail expr drop order change in Edition 2024)
 - rust-lang#128932 (skip updating when external binding is existed)
 - rust-lang#129270 (Don't consider locals to shadow inner items' generics)
 - rust-lang#129277 (Update annotate-snippets to 0.11)
 - rust-lang#129294 (Stabilize `iter::repeat_n`)
 - rust-lang#129308 (fix: simple typo in compiler directory)
 - rust-lang#129309 (ctfe: make CompileTimeInterpCx type alias public)
 - rust-lang#129314 (fix a broken link in `mir/mod.rs`)
 - rust-lang#129318 (Remove unneeded conversion to `DefId` for `ExtraInfo`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 21, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#128662 (Lint on tail expr drop order change in Edition 2024)
 - rust-lang#128932 (skip updating when external binding is existed)
 - rust-lang#129270 (Don't consider locals to shadow inner items' generics)
 - rust-lang#129277 (Update annotate-snippets to 0.11)
 - rust-lang#129294 (Stabilize `iter::repeat_n`)
 - rust-lang#129308 (fix: simple typo in compiler directory)
 - rust-lang#129309 (ctfe: make CompileTimeInterpCx type alias public)
 - rust-lang#129314 (fix a broken link in `mir/mod.rs`)
 - rust-lang#129318 (Remove unneeded conversion to `DefId` for `ExtraInfo`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 552b5c7 into rust-lang:master Aug 21, 2024
6 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 21, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 21, 2024
Rollup merge of rust-lang#128662 - dingxiangfei2009:lint-tail-expr-drop-order, r=jieyouxu

Lint on tail expr drop order change in Edition 2024

This lint warns users to consider extra discretion on the effect of a transposed drop order arising from Edition 2024, which involves temporaries in tail expression location with significant drop implementation.

cc `@traviscross`

Tracking:

- rust-lang#123739
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 S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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.

7 participants