Skip to content

fix Expr::can_have_side_effects for [x; N] style array literal and binary expressions - #150385

Merged
rust-bors[bot] merged 8 commits into
rust-lang:mainfrom
andjsrk:fix-expr-can-have-side-effects
Jan 9, 2026
Merged

fix Expr::can_have_side_effects for [x; N] style array literal and binary expressions#150385
rust-bors[bot] merged 8 commits into
rust-lang:mainfrom
andjsrk:fix-expr-can-have-side-effects

Conversation

@andjsrk

@andjsrkandjsrk commented Dec 26, 2025

Copy link
Copy Markdown
Contributor

AFAIK [0; 3] is basically a syntax sugar for [0, 0, 0] so it should return whether the repeat's element can have side effects, like what it does on arrays.
And it seems that the rule for unary operators and indexings can be applied to binary operators as well.

@rustbotrustbot 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 Dec 26, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
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

@rust-log-analyzer

This comment has been minimized.

@Kivooeo

Copy link
Copy Markdown
Member

Would you like to add a test for this, to reflect new behaviour you changed here

Because on a first glance it's not obvious (at least to me)

@andjsrk

andjsrk commented Dec 27, 2025

Copy link
Copy Markdown
ContributorAuthor

I'm not sure where should I add a test:

  • tests/ui/expr.rs - Expr::can_have_side_effects is used in a few minor(in my opinion) places and is used widely in Clippy rather than rustc. If I decide to add a test in there, I guess testing code would look pretty unintuitive (could be improved by comments though).
  • compiler/rustc_hir/src/hir/tests.rs - maybe I should add tests here, but I guess runtime test is needed (not just checking successful compilation) and I have no idea about how to create an Expr...

@jdonszelmann

Copy link
Copy Markdown
Contributor

I agree with @Kivooeo here: something has to be tested. A ui test will show a piece of rust code now compiling (or warning) differently. I think this is supposed to change something about the diagnostics of binop expressions and array expressions. So ideally, I'd see a uitest showing a diagnostic that is different. In fact, I see some tests that failed in CI, likely because of this diagnostics change. If you run x test tests/ui/<specific-test> --bless it will update the expected output, which you can commit, to show what diagnostics changed from this change. Maybe you want to also add a specific test for the exact changed diagnostics behavior after this PR. Let me know if that makes sense!

@rustbot author

@rustbotrustbot 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 Jan 6, 2026
@rustbot

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rustbotrustbot added the T-clippy Relevant to the Clippy team. label Jan 6, 2026
@andjsrk

Copy link
Copy Markdown
ContributorAuthor

Maybe you want to also add a specific test for the exact changed diagnostics behavior after this PR.

@jdonszelmann I'm going to add a test for repeats([x; N]) as it seems no test checks Expr::can_have_side_effects on repeats, but as I asked above I have no idea about where should I add a test, could you let me know?

@Kivooeo

Copy link
Copy Markdown
Member

Add please this test to tests/ui/repeat-expr/

And I'm not sure why this changes to clippy were made?

@andjsrk

andjsrk commented Jan 6, 2026

Copy link
Copy Markdown
ContributorAuthor
  • clippy::needless_match relies on Expr::can_have_side_effects and it warns some code in the UI test for clippy::manual_clamp.
  • clippy::needless_bitwise_bool has test cases that require improvement of Expr::can_have_side_effects and some of them are resolved now.

These are the cause of test failures in CI and so I fixed them, did I something wrong?

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@andjsrk

Copy link
Copy Markdown
ContributorAuthor

@rustbot ready

@rustbotrustbot 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 Jan 6, 2026
@samueltardieu

Copy link
Copy Markdown
Member

The Clippy part looks ok.

@jdonszelmann

Copy link
Copy Markdown
Contributor

yea, I think this looks reasonable. @bors r=jdonszelmann,samueltardieu rollup

@jdonszelmann

Copy link
Copy Markdown
Contributor

actually, stop, @bors r-

@rust-borsrust-borsBot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 8, 2026
@rust-bors

rust-borsBot commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Commit d848437 has been unapproved.

@rust-borsrust-borsBot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 8, 2026
@jdonszelmann

Copy link
Copy Markdown
Contributor

I realised that I would also quite like to see a test for the binary operator change here. After that r=me

@jdonszelmann

Copy link
Copy Markdown
Contributor

@rustbot author

@andjsrk

Copy link
Copy Markdown
ContributorAuthor

@bors r=jdonszelmann

@rust-bors

rust-borsBot commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

@andjsrk: 🔑 Insufficient privileges: not in review users

@andjsrk

Copy link
Copy Markdown
ContributorAuthor

@rustbot ready

@rustbotrustbot 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 Jan 9, 2026
@andjsrk

Copy link
Copy Markdown
ContributorAuthor

@jdonszelmann I have no permission, please take action on this

@samueltardieu

Copy link
Copy Markdown
Member

@bors r=jdonszelmann,samueltardieu rollup

@rust-borsrust-borsBot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 9, 2026
@rust-bors

rust-borsBot commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 561b592 has been approved by jdonszelmann,samueltardieu

It is now in the queue for this repository.

@rust-borsrust-borsBot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 9, 2026
@jdonszelmann

Copy link
Copy Markdown
Contributor

Thanks @samueltardieu :3

rust-borsBot added a commit that referenced this pull request Jan 9, 2026
Rollup of 11 pull requests
Successful merges:
- #150272 (docs(core): update `find()` and `rfind()` examples)
- #150385 (fix `Expr::can_have_side_effects` for `[x; N]` style array literal and binary expressions)
- #150561 (Finish transition from `semitransparent` to `semiopaque` for `rustc_macro_transparency`)
- #150574 (Clarify `MoveData::init_loc_map`.)
- #150762 (Use functions more in rustdoc GUI tests)
- #150808 (rename the `derive_{eq, clone_copy}` features to `*_internals`)
- #150816 (Fix trait method anchor disappearing before user can click on it)
- #150821 (tests/ui/borrowck/issue-92157.rs: Remove (bug not fixed))
- #150829 (make attrs actually use `Target::GenericParam`)
- #150834 (Add tracking issue for `feature(multiple_supertrait_upcastable)`)
- #150864 (The aarch64-unknown-none target requires NEON, so the docs were wrong.)
r? @ghost
@rust-bors
rust-borsBot merged commit 09575ec into rust-lang:mainJan 9, 2026
11 checks passed
@rustbotrustbot added this to the 1.94.0 milestone Jan 9, 2026
rust-timer added a commit that referenced this pull request Jan 9, 2026
Rollup merge of #150385 - fix-expr-can-have-side-effects, r=jdonszelmann,samueltardieu
fix `Expr::can_have_side_effects` for `[x; N]` style array literal and binary expressions
AFAIK `[0; 3]` is basically a syntax sugar for `[0, 0, 0]` so it should return whether the repeat's element can have side effects, like what it does on arrays.
And it seems that the rule for unary operators and indexings can be applied to binary operators as well.
github-actionsBot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Jan 12, 2026
Rollup of 11 pull requests
Successful merges:
- rust-lang/rust#150272 (docs(core): update `find()` and `rfind()` examples)
- rust-lang/rust#150385 (fix `Expr::can_have_side_effects` for `[x; N]` style array literal and binary expressions)
- rust-lang/rust#150561 (Finish transition from `semitransparent` to `semiopaque` for `rustc_macro_transparency`)
- rust-lang/rust#150574 (Clarify `MoveData::init_loc_map`.)
- rust-lang/rust#150762 (Use functions more in rustdoc GUI tests)
- rust-lang/rust#150808 (rename the `derive_{eq, clone_copy}` features to `*_internals`)
- rust-lang/rust#150816 (Fix trait method anchor disappearing before user can click on it)
- rust-lang/rust#150821 (tests/ui/borrowck/issue-92157.rs: Remove (bug not fixed))
- rust-lang/rust#150829 (make attrs actually use `Target::GenericParam`)
- rust-lang/rust#150834 (Add tracking issue for `feature(multiple_supertrait_upcastable)`)
- rust-lang/rust#150864 (The aarch64-unknown-none target requires NEON, so the docs were wrong.)
r? @ghost
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jan 22, 2026
…jdonszelmann,samueltardieu
fix `Expr::can_have_side_effects` for `[x; N]` style array literal and binary expressions
AFAIK `[0; 3]` is basically a syntax sugar for `[0, 0, 0]` so it should return whether the repeat's element can have side effects, like what it does on arrays.
And it seems that the rule for unary operators and indexings can be applied to binary operators as well.
christian-schilling pushed a commit to christian-schilling/rustc_codegen_cranelift that referenced this pull request Jan 27, 2026
Rollup of 11 pull requests
Successful merges:
- rust-lang/rust#150272 (docs(core): update `find()` and `rfind()` examples)
- rust-lang/rust#150385 (fix `Expr::can_have_side_effects` for `[x; N]` style array literal and binary expressions)
- rust-lang/rust#150561 (Finish transition from `semitransparent` to `semiopaque` for `rustc_macro_transparency`)
- rust-lang/rust#150574 (Clarify `MoveData::init_loc_map`.)
- rust-lang/rust#150762 (Use functions more in rustdoc GUI tests)
- rust-lang/rust#150808 (rename the `derive_{eq, clone_copy}` features to `*_internals`)
- rust-lang/rust#150816 (Fix trait method anchor disappearing before user can click on it)
- rust-lang/rust#150821 (tests/ui/borrowck/issue-92157.rs: Remove (bug not fixed))
- rust-lang/rust#150829 (make attrs actually use `Target::GenericParam`)
- rust-lang/rust#150834 (Add tracking issue for `feature(multiple_supertrait_upcastable)`)
- rust-lang/rust#150864 (The aarch64-unknown-none target requires NEON, so the docs were wrong.)
r? @ghost
christian-schilling pushed a commit to christian-schilling/rustc_codegen_cranelift that referenced this pull request Jan 27, 2026
Rollup of 11 pull requests
Successful merges:
- rust-lang/rust#150272 (docs(core): update `find()` and `rfind()` examples)
- rust-lang/rust#150385 (fix `Expr::can_have_side_effects` for `[x; N]` style array literal and binary expressions)
- rust-lang/rust#150561 (Finish transition from `semitransparent` to `semiopaque` for `rustc_macro_transparency`)
- rust-lang/rust#150574 (Clarify `MoveData::init_loc_map`.)
- rust-lang/rust#150762 (Use functions more in rustdoc GUI tests)
- rust-lang/rust#150808 (rename the `derive_{eq, clone_copy}` features to `*_internals`)
- rust-lang/rust#150816 (Fix trait method anchor disappearing before user can click on it)
- rust-lang/rust#150821 (tests/ui/borrowck/issue-92157.rs: Remove (bug not fixed))
- rust-lang/rust#150829 (make attrs actually use `Target::GenericParam`)
- rust-lang/rust#150834 (Add tracking issue for `feature(multiple_supertrait_upcastable)`)
- rust-lang/rust#150864 (The aarch64-unknown-none target requires NEON, so the docs were wrong.)
r? @ghost
ghaaj pushed a commit to ghaaj/polygrammar that referenced this pull request Aug 7, 2026
Rollup of 11 pull requests
Successful merges:
- rust-lang/rust#150272 (docs(core): update `find()` and `rfind()` examples)
- rust-lang/rust#150385 (fix `Expr::can_have_side_effects` for `[x; N]` style array literal and binary expressions)
- rust-lang/rust#150561 (Finish transition from `semitransparent` to `semiopaque` for `rustc_macro_transparency`)
- rust-lang/rust#150574 (Clarify `MoveData::init_loc_map`.)
- rust-lang/rust#150762 (Use functions more in rustdoc GUI tests)
- rust-lang/rust#150808 (rename the `derive_{eq, clone_copy}` features to `*_internals`)
- rust-lang/rust#150816 (Fix trait method anchor disappearing before user can click on it)
- rust-lang/rust#150821 (tests/ui/borrowck/issue-92157.rs: Remove (bug not fixed))
- rust-lang/rust#150829 (make attrs actually use `Target::GenericParam`)
- rust-lang/rust#150834 (Add tracking issue for `feature(multiple_supertrait_upcastable)`)
- rust-lang/rust#150864 (The aarch64-unknown-none target requires NEON, so the docs were wrong.)
r? @ghost
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Aug 17, 2026
Rollup of 11 pull requests
Successful merges:
- rust-lang/rust#150272 (docs(core): update `find()` and `rfind()` examples)
- rust-lang/rust#150385 (fix `Expr::can_have_side_effects` for `[x; N]` style array literal and binary expressions)
- rust-lang/rust#150561 (Finish transition from `semitransparent` to `semiopaque` for `rustc_macro_transparency`)
- rust-lang/rust#150574 (Clarify `MoveData::init_loc_map`.)
- rust-lang/rust#150762 (Use functions more in rustdoc GUI tests)
- rust-lang/rust#150808 (rename the `derive_{eq, clone_copy}` features to `*_internals`)
- rust-lang/rust#150816 (Fix trait method anchor disappearing before user can click on it)
- rust-lang/rust#150821 (tests/ui/borrowck/issue-92157.rs: Remove (bug not fixed))
- rust-lang/rust#150829 (make attrs actually use `Target::GenericParam`)
- rust-lang/rust#150834 (Add tracking issue for `feature(multiple_supertrait_upcastable)`)
- rust-lang/rust#150864 (The aarch64-unknown-none target requires NEON, so the docs were wrong.)
r? @ghost
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-clippyRelevant to the Clippy team.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@andjsrk@rustbot@rust-log-analyzer@Kivooeo@jdonszelmann@samueltardieu