mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00

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 which was needed to restabilize trait upcasting. We considered just making this a hard error at the time, but opted against it 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 now make a hard error of this.
21 lines
707 B
Rust
21 lines
707 B
Rust
trait Trait<'a> {}
|
|
|
|
fn add_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send) {
|
|
x as _
|
|
//~^ ERROR cannot add auto trait `Send` to dyn bound via pointer cast
|
|
//~| NOTE unsupported cast
|
|
//~| NOTE this could allow UB elsewhere
|
|
//~| HELP use `transmute` if you're sure this is sound
|
|
}
|
|
|
|
// (to test diagnostic list formatting)
|
|
fn add_multiple_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send + Sync + Unpin) {
|
|
x as _
|
|
//~^ ERROR cannot add auto traits `Send`, `Sync`, and `Unpin` to dyn bound via pointer cast
|
|
//~| NOTE unsupported cast
|
|
//~| NOTE this could allow UB elsewhere
|
|
//~| HELP use `transmute` if you're sure this is sound
|
|
}
|
|
|
|
fn main() {}
|