Skip to content

use uX::from instead of _ as uX in non - const contexts #140435

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

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

Conversation

bend-n
Copy link
Contributor

@bend-n bend-n commented Apr 29, 2025

changes transmute(bool) -> integer to integer::from as opposed to bool as integer.
#136083 (comment)

@rustbot label L-unnecessary_transmutes

@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2025

r? @estebank

rustbot has assigned @estebank.
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 Apr 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added the L-unnecessary_transmutes Lint: unnecessary_transmutes label Apr 29, 2025
func,
snippet,
span,
self.tcx.is_const_fn(def_id)
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe this heuristic is complete. This leaves out const items and statics, for example.

Copy link
Member

Choose a reason for hiding this comment

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

could you add some tests for statics, consts, and in const blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

im not sure the heuristic is complete, but i added those tests and changed it a little.

@bend-n bend-n force-pushed the use_ux_from_instead_of_bool_as_ux_unnecessary_transmutes branch 3 times, most recently from 5f5d1c6 to 17737d6 Compare April 30, 2025 07:18
@bend-n bend-n requested a review from compiler-errors May 4, 2025 19:05
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

Just some nits, then I can approve.

func,
snippet,
span,
self.tcx.is_const_fn(def_id)
Copy link
Member

Choose a reason for hiding this comment

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

Can you use tcx.hir_body_const_context(def_id.expect_local()).is_some()? That's actually probably the most correct way to do it.

@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 May 21, 2025
@bend-n bend-n force-pushed the use_ux_from_instead_of_bool_as_ux_unnecessary_transmutes branch from 17737d6 to a57f326 Compare May 22, 2025 02:50
@rustbot

This comment has been minimized.

@bend-n bend-n force-pushed the use_ux_from_instead_of_bool_as_ux_unnecessary_transmutes branch from a57f326 to c0b365d Compare May 22, 2025 02:54
@bend-n
Copy link
Contributor Author

bend-n commented May 22, 2025

@rustbot ready

@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 May 22, 2025
@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 22, 2025

📌 Commit c0b365d has been approved by compiler-errors

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 May 22, 2025
@bors
Copy link
Collaborator

bors commented May 22, 2025

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

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 22, 2025
@bend-n bend-n force-pushed the use_ux_from_instead_of_bool_as_ux_unnecessary_transmutes branch from c0b365d to 8373bb1 Compare May 22, 2025 10:08
@bend-n
Copy link
Contributor Author

bend-n commented May 22, 2025

@bors r=@compiler-errors

@bors
Copy link
Collaborator

bors commented May 22, 2025

@bend-n: 🔑 Insufficient privileges: Not in reviewers

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented May 22, 2025

📌 Commit 8373bb1 has been approved by compiler-errors

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 22, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 22, 2025
…_as_ux_unnecessary_transmutes, r=compiler-errors

use uX::from instead of _ as uX in non - const contexts

changes `transmute(bool) -> integer` to `integer::from` as opposed to `bool as integer`.
rust-lang#136083 (comment)

`@rustbot` label L-unnecessary_transmutes
bors added a commit to rust-lang-ci/rust that referenced this pull request May 22, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#135562 (Add ignore value suggestion in closure body)
 - rust-lang#139635 (Finalize repeat expr inference behaviour with inferred repeat counts)
 - rust-lang#139668 (Handle regions equivalent to 'static in non_local_bounds)
 - rust-lang#140218 (HIR ty lowering: Clean up & refactor the lowering of type-relative paths)
 - rust-lang#140435 (use uX::from instead of _ as uX in non - const contexts)
 - rust-lang#141130 (rustc_on_unimplemented cleanups)
 - rust-lang#141286 (Querify `coroutine_hidden_types`)

Failed merges:

 - rust-lang#140247 (Don't build `ParamEnv` and do trait solving in `ItemCtxt`s when lowering IATs)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L-unnecessary_transmutes Lint: unnecessary_transmutes 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants