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

FP transmutes_expressible_as_ptr_casts: type fn() cannot be dereferenced #10449

Closed
matthiaskrgr opened this issue Mar 4, 2023 · 0 comments · Fixed by #10454
Closed

FP transmutes_expressible_as_ptr_casts: type fn() cannot be dereferenced #10449

matthiaskrgr opened this issue Mar 4, 2023 · 0 comments · Fixed by #10454
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@matthiaskrgr
Copy link
Member

Summary

.

Lint Name

transmutes_expressible_as_ptr_casts

Reproducer

I tried this code:

fn main() {
    fn f() {}

    let _x: u8 = unsafe {
        *std::mem::transmute::<fn(), *const u8>(f)
    };
}

I saw this happen:

warning: transmute from `fn()` to `*const u8` which could be expressed as a pointer cast instead
 --> src/main.rs:5:10
  |
5 |         *std::mem::transmute::<fn(), *const u8>(f)
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `f as *const u8`
  |

Suggestion does not compile:

The following errors were reported:
error[E0614]: type `fn() {main::f}` cannot be dereferenced
 --> src/main.rs:5:9
  |
5 |         *f as *const u8
  |         ^^

error: aborting due to previous error

Version

rustc 1.69.0-nightly (44cfafe2f 2023-03-03)
binary: rustc
commit-hash: 44cfafe2fafe816395d3acc434663a45d5178c41
commit-date: 2023-03-03
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

Additional Labels

No response

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 4, 2023
@bors bors closed this as completed in f1b9105 Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant