-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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
base: master
Are you sure you want to change the base?
use uX::from instead of _ as uX in non - const contexts #140435
Conversation
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
func, | ||
snippet, | ||
span, | ||
self.tcx.is_const_fn(def_id) |
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.
I don't believe this heuristic is complete. This leaves out const items and statics, for example.
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.
could you add some tests for statics, consts, and in const blocks?
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.
im not sure the heuristic is complete, but i added those tests and changed it a little.
compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs
Outdated
Show resolved
Hide resolved
5f5d1c6
to
17737d6
Compare
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.
Just some nits, then I can approve.
func, | ||
snippet, | ||
span, | ||
self.tcx.is_const_fn(def_id) |
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.
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.
compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs
Outdated
Show resolved
Hide resolved
17737d6
to
a57f326
Compare
This comment has been minimized.
This comment has been minimized.
a57f326
to
c0b365d
Compare
@rustbot ready |
@bors r+ rollup |
☔ The latest upstream changes (presumably #141379) made this pull request unmergeable. Please resolve the merge conflicts. |
c0b365d
to
8373bb1
Compare
@bend-n: 🔑 Insufficient privileges: Not in reviewers |
@bors r+ |
…_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
…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
changes
transmute(bool) -> integer
tointeger::from
as opposed tobool as integer
.#136083 (comment)
@rustbot label L-unnecessary_transmutes