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

False negative for trivial_casts with pointer #117187

Open
Nilstrieb opened this issue Oct 25, 2023 · 3 comments
Open

False negative for trivial_casts with pointer #117187

Nilstrieb opened this issue Oct 25, 2023 · 3 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-raw-pointers Area: raw pointers, MaybeUninit, NonNull C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Nilstrieb
Copy link
Member

Nilstrieb commented Oct 25, 2023

After #113262, this will no longer fail to compile:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8ee721b21617d98d18c5256778b57efe

#[deny(trivial_casts)]
fn main() {
    let a = std::ptr::null::<()>();
    let _b = a as *const ();
}

The cast is trivial, but we miss it because we have to conservatively assume that raw pointer casts are not trivial. A possible fix would be to check for trivial raw pointer casts in MIR (but correctly considering lifetimes is still not quite easy there I think).

@Nilstrieb Nilstrieb added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-raw-pointers Area: raw pointers, MaybeUninit, NonNull labels Oct 25, 2023
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 25, 2023
@Nilstrieb Nilstrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 25, 2023
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Oct 26, 2023
@apiraino
Copy link
Contributor

apiraino commented Apr 3, 2024

while randomly checking other things I've tried compiling the snippet in the first comment with the current stable 1.76.0: it compiles (since 1.75)

@Nilstrieb wdyt? could this issue been fixed at some point since opening this issue? Don't have time rn to bisect the fix 🙃 but if yes, I'd add the e-need-test to remind us to add a test case

@Nilstrieb
Copy link
Member Author

Nilstrieb commented Apr 4, 2024

The issue is that it does compile it shouldn't compile. I regressed this, it used to error with the lint, but now it doesn't anymore. I checked latest nightly and it still passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-raw-pointers Area: raw pointers, MaybeUninit, NonNull C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants