mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-15 12:39:31 +03:00
c3205f98dd
Removes the attribute from `MetaSized` and `PointeeSized`, with a special case in the trait solvers for `MetaSized`. `dyn MetaSized` is a perfectly cromulent type, and seems to only have had #[rustc_do_not_implement_via_object] so the builtin object candidate does not overlap with the builtin MetaSized impl that all `dyn` types get. Resolves this with a special case by checking `is_sizedness_trait` where the trait solvers previously checked `implement_via_object`. `dyn PointeeSized` alone is rejected for other reasons (since `dyn PointeeSized` is considered to have no principal trait because `PointeeSized` is removed at an earlier stage of the compiler), but `(dyn PointeeSized + Send)` is valid and equivalent to `dyn Send`. Add suggestions from code review Update compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs and tests Co-authored-by: lcnr <rust@lcnr.de>
30 lines
974 B
Rust
30 lines
974 B
Rust
//! This test and `metasized.rs` and `pointeesized.rs` test that dyn-compatibility correctly
|
|
//! handles the different sizedness traits, which are special in several parts of the compiler.
|
|
|
|
trait Foo: std::fmt::Debug + Sized {}
|
|
|
|
impl<T: std::fmt::Debug + Sized> Foo for T {}
|
|
|
|
fn unsize_sized<T: 'static>(x: Box<T>) -> Box<dyn Sized> {
|
|
//~^ ERROR the trait `Sized` is not dyn compatible
|
|
x
|
|
}
|
|
|
|
fn unsize_subtrait(x: Box<dyn Foo>) -> Box<dyn Sized> {
|
|
//~^ ERROR the trait `Foo` is not dyn compatible
|
|
//~| ERROR the trait `Sized` is not dyn compatible
|
|
x
|
|
}
|
|
|
|
fn main() {
|
|
let _bx = unsize_sized(Box::new(vec![1, 2, 3]));
|
|
//~^ ERROR the trait `Sized` is not dyn compatible
|
|
|
|
let bx: Box<dyn Foo> = Box::new(vec![1, 2, 3]);
|
|
//~^ ERROR the trait `Foo` is not dyn compatible
|
|
let _ = format!("{bx:?}");
|
|
let _bx = unsize_subtrait(bx);
|
|
//~^ ERROR the trait `Foo` is not dyn compatible
|
|
//~| ERROR the trait `Sized` is not dyn compatible
|
|
}
|