-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Suggest .cast
/.cast_const
/.cast_mut
in transmute_ptr_as_ptr
#13143
Suggest .cast
/.cast_const
/.cast_mut
in transmute_ptr_as_ptr
#13143
Conversation
format!("{}.cast::<{to_pointee_ty}>()", arg.maybe_par()), | ||
Applicability::MaybeIncorrect, | ||
); | ||
} else if from_pointee_ty == to_pointee_ty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could end up as a wrong suggestion for lifetime transmutes (*mut Lt<'a>
to *const Lt<'static>
). Maybe we can add a check if the from- or to type has TypeFlags::RE_ERASED
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, is there a good example? I assume this would also effect ptr_as_ptr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't think of a good (practical) example, but I was thinking of something like:
struct Lt<'a>(&'a ());
unsafe fn f(v: *mut Lt<'_>) -> *const Lt<'static> {
std::mem::transmute(v)
}
This looks like it has .cast_const() for the suggestion, but that doesn't change the lifetime
Basically just this test case but with raw pointers and with differing mutability (so it doesn't go into the first if
for pointer::cast):
unsafe fn transmute_lifetime_to_static<'a, T>(t: &'a T) -> &'static T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, unrealistic is fine I just can never remember which lifetimes are erased or early/late or any of that stuff 😅
Fixed it for ptr_cast_constness
too
Looks good to me now! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Essentially pre-applies
ptr_as_ptr
- #6372 (comment)changelog: none