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>
17 lines
667 B
Rust
17 lines
667 B
Rust
//@ run-pass
|
|
//! This test and `sized-*.rs` and `metasized.rs` test that dyn-compatibility correctly
|
|
//! handles sizedness traits, which are special in several parts of the compiler.
|
|
#![feature(sized_hierarchy)]
|
|
// PointeeSized is effectively removed before reaching the trait solver,
|
|
// so it's as though it wasn't even mentioned in the trait list.
|
|
use std::marker::PointeeSized;
|
|
|
|
fn main() {
|
|
let dyn_ref: &(dyn PointeeSized + Send) = &42;
|
|
let dyn_ref: &dyn Send = dyn_ref;
|
|
let _dyn_ref: &(dyn PointeeSized + Send) = dyn_ref;
|
|
assert_eq!(
|
|
std::any::TypeId::of::<dyn Send>(),
|
|
std::any::TypeId::of::<dyn PointeeSized + Send>(),
|
|
);
|
|
}
|