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

transmute_ptr_to_ref false positive for types containing differing lifetimes #8924

Closed
Alexendoo opened this issue Jun 1, 2022 · 1 comment · Fixed by #8939
Closed

transmute_ptr_to_ref false positive for types containing differing lifetimes #8924

Alexendoo opened this issue Jun 1, 2022 · 1 comment · Fixed by #8939
Labels
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

Comments

@Alexendoo
Copy link
Member

Summary

There's one last FP in #2906 that wasn't fixed

Lint Name

transmute_ptr_to_ref

Reproducer

I tried this code:

#![allow(clippy::missing_safety_doc)]

use std::mem::transmute;

pub unsafe fn ptr_to_ref<'a, 'b>(ptr: *const &'a ()) -> &&'b () {
    transmute(ptr)
}

I saw this happen:

warning: transmute from a pointer type (`*const &()`) to a reference type (`&&()`)
 --> t.rs:5:5
  |
5 |     std::mem::transmute(ptr)
  |     ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*ptr`
  |

I expected to see this happen:

It shouldn't lint, as &*ptr would fail to compile

Version

No response

Additional Labels

No response

@Alexendoo Alexendoo 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 Jun 1, 2022
@Jarcho
Copy link
Contributor

Jarcho commented Jun 3, 2022

This should lint, but the suggestion should be &*(ptr as *const &'b ())

That used to be the suggestion before lifetimes were removed from type checking.

Edit: A better suggestion would be &*ptr.cast() when msrv >= 1.38.

@Alexendoo Alexendoo removed the I-false-positive Issue: The lint was triggered on code it shouldn't have label Jun 4, 2022
@bors bors closed this as completed in 88da5f2 Jun 27, 2022
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-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.

2 participants