Skip to content

Make two transmute-related MIR lints into HIR lint #141551

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 3 commits into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented May 25, 2025

Make PTR_TO_INTEGER_TRANSMUTE_IN_CONSTS (#130540) and UNNECESSARY_TRANSMUTES (#136083) into "normal" HIR-based lints.

Funny enough this came up in the review of the latter (#136083 (comment)), but I guess it just was overlooked.

But anywyas, there's no reason for these to be MIR lints; in fact, it makes the suggestions for them a bit more complicated than necessary.

Note that there's probably a few more simplifications and improvements to be done here. Follow-ups can be done in a separate PR, especially if they're about the messaging and suggestions themselves, which I didn't write.

@rustbot
Copy link
Collaborator

rustbot commented May 25, 2025

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
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 May 25, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 25, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@@ -1,7 +1,9 @@
#![deny(ptr_to_integer_transmute_in_consts)]
Copy link
Member Author

Choose a reason for hiding this comment

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

I made this test into a hard error for the lint, and removed the //~^ ERROR annotation in fn main, since we can't mix normal errors and lints since they happen after normal checking has happened.

_ => return,
};

cx.tcx.node_span_lint(UNNECESSARY_TRANSMUTES, expr.hir_id, expr.span, |diag| {
Copy link
Member Author

Choose a reason for hiding this comment

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

I chose to be lazy and use the old diagnostic machinery for the UNNECESSARY_TRANSMUTES lint, since it's kind of a pain in the ass to make it work "correctly" w/ the new machinery.

@BoxyUwU
Copy link
Member

BoxyUwU commented May 27, 2025

gamer+

@bors
Copy link
Collaborator

bors commented May 27, 2025

📌 Commit 295a8d5 has been approved by BoxyUwU

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

@bors rollup

tgross35 added a commit to tgross35/rust that referenced this pull request May 28, 2025
Make two transmute-related MIR lints into HIR lint

Make `PTR_TO_INTEGER_TRANSMUTE_IN_CONSTS` (rust-lang#130540) and `UNNECESSARY_TRANSMUTES` (rust-lang#136083) into "normal" HIR-based lints.

Funny enough this came up in the review of the latter (rust-lang#136083 (comment)), but I guess it just was overlooked.

But anywyas, there's no reason for these to be MIR lints; in fact, it makes the suggestions for them a bit more complicated than necessary.

Note that there's probably a few more simplifications and improvements to be done here. Follow-ups can be done in a separate PR, especially if they're about the messaging and suggestions themselves, which I didn't write.
bors added a commit that referenced this pull request May 28, 2025
Rollup of 8 pull requests

Successful merges:

 - #140367 (add `asm_cfg`: `#[cfg(...)]` within `asm!`)
 - #140894 (Make check-cfg diagnostics work in `#[doc(cfg(..))]`)
 - #141252 (gvn: bail out unavoidable non-ssa locals in repeat)
 - #141517 (rustdoc: use descriptive tooltip if doctest is conditionally ignored)
 - #141551 (Make two transmute-related MIR lints into HIR lint)
 - #141591 (ci: fix llvm test coverage)
 - #141647 (Bump master `stage0` compiler)
 - #141659 (Add `Result::map_or_default` and `Option::map_or_default`)

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
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.

4 participants