-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Tracking issue for future-incompatibility lint ptr_cast_add_auto_to_object
#127323
Comments
Future compatibility warnings are generally made hard errors after a while, right? I don't think we should suggest suppressing a future compatibility warning. |
@bjorn3 we only will make cases with the warning into errors. |
There's a new future incompatibility warning that recently started firing on the code in CloneToAny (see [1]). It's triggering on code that does a pointer cast from *mut dyn Trait to *mut dyn Trait + Send (or other auto trait) which is an exact match for what this crate is doing. The lint doesn't actually apply here though so it is safe to suppress it. The recommended way to suppress it is to replace the pointer cast with a transmute and that's what I have done here. See the new safety comment for a more detailed explanation of why it is safe. [1]: rust-lang/rust#127323
ptr_cast_add_auto_to_object
future compatibility warningptr_cast_add_auto_to_object
future-incompatibility warning
ptr_cast_add_auto_to_object
future-incompatibility warningptr_cast_add_auto_to_object
There's a new future incompatibility warning that recently started firing on the code in CloneToAny (see [1]). It's triggering on code that does a pointer cast from *mut dyn Trait to *mut dyn Trait + Send (or other auto trait) which is an exact match for what this crate is doing. The lint doesn't actually apply here though so it is safe to suppress it. The recommended way to suppress it is to replace the pointer cast with a transmute and that's what I have done here. See the new safety comment for a more detailed explanation of why it is safe. [1]: rust-lang/rust#127323
The example in the description now needs #![feature(arbitrary_self_types, derive_coerce_pointee)]
use std::marker::CoercePointee;
#[derive(CoercePointee)]
#[repr(transparent)]
struct MyPtr<T: ?Sized>(*const T);
use std::ops::Receiver;
impl<T: ?Sized> Receiver for MyPtr<T> {
type Target = T;
}
trait Trait {
fn foo(self: MyPtr<Self>)
where
Self: Send;
}
impl Trait for *mut () {
fn foo(self: MyPtr<Self>) {
unreachable!()
}
}
fn main() {
let a = 0x1 as *const *mut ();
let a = a as *const dyn Trait as *const (dyn Trait + Send);
MyPtr(a).foo();
} This does currently ICE due to #135179 not having been merged yet but once it's in this segfaults for me locally |
We already have a safety invariant of requiring a valid vtable for raw pointers; dyn upcasting relies on that. I guess the cast above is accepted because "marker traits don't change the vtable", or so? |
@BoxyUwU that does not trigger the lint that this issue tracks... so it should probably get a separate issue? |
The ICE gets hit before the lint is triggered but once the ICE is fixed the lint triggers + there's a segfault when the program is run |
If anyone is curious this is the output I get locally on that example when using a stage1 compiler from errs' branch |
Ah okay. So this one "just" needs the lint to be turned into a hard error then. I agree with your statement elsewhere that that should happen before this example works on stable. |
…o_to_object-hard-error, r=<try> Make `ptr_cast_add_auto_to_object` lint into hard error In Rust 1.81, we added a FCW lint (including linting in dependencies) against pointer casts that add an auto trait to dyn bounds. This was part of work making casts of pointers involving trait objects stricter, and was part of the work needed to restabilize trait upcasting. We considered just making this a hard error, but opted against it at that time due to breakage found by crater. This breakage was mostly due to the `anymap` crate which has been a persistent problem for us. It's now a year later, and the fact that this is not yet a hard error is giving us pause about stabilizing arbitrary self types and `derive(CoercePointee)`. So let's see about making a hard error of this. r? ghost cc `@adetaylor` `@Darksonn` `@BoxyUwU` `@RalfJung` `@compiler-errors` `@oli-obk` `@WaffleLapkin` Related: - rust-lang#135881 - rust-lang#136702 Tracking: - rust-lang#127323 - rust-lang#44874 - rust-lang#123430
This is a tracking issue for the
ptr_cast_add_auto_to_object
lint, which was added in #120248.This lint detects casts of raw pointers to trait objects, which add auto traits. Adding auto traits to trait objects may cause UB when
#![feature(arbitrary_self_types)]
is used.Example
In case your usage is sound (e.g. because the trait doesn't have auto trait bounds), you can replace cast with a transmute to suppress the warning:
The text was updated successfully, but these errors were encountered: