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

extend transmute_ptr_to_ref to detect transmuting newtypes around ptrs #1966

Open
oli-obk opened this issue Aug 18, 2017 · 1 comment
Open
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-style Lint: Belongs in the style lint group T-middle Type: Probably requires verifiying types

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Aug 18, 2017

We just had something like the following code in IRC. It would be nice if clippy suggested to replace the transmute with &*(self.0 as *const i32)

struct Foo(*const i32);
fn foo(foo: &Foo) -> &i32 {
    unsafe { transmute(foo) }
}

This is an extension of the existing lint that complains about transmute<*const T, &T>(raw_ptr). We just need to check whether the transmuted-from type is a struct which has only a single raw pointer field (or all other fields are ZST).

@oli-obk oli-obk added L-style Lint: Belongs in the style lint group good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages T-middle Type: Probably requires verifiying types labels Aug 18, 2017
@Jaic1
Copy link
Contributor

Jaic1 commented Mar 28, 2022

This is an extension of the existing lint that complains about transmute<*const T, &T>(raw_ptr).

Is this lint (transmute_ptr_to_ref) the existing lint you mentioned? Also it seems like currently clippy will not lint for the example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-style Lint: Belongs in the style lint group T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

4 participants