mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-04 19:28:29 +00:00

Opting-out of `Sized` with `?Sized` is now equivalent to adding a `MetaSized` bound, and adding a `MetaSized` or `PointeeSized` bound is equivalent to removing the default `Sized` bound - this commit implements this change in `rustc_hir_analysis::hir_ty_lowering`. `MetaSized` is also added as a supertrait of all traits, as this is necessary to preserve backwards compatibility. Unfortunately, non-global where clauses being preferred over item bounds (where `PointeeSized` bounds would be proven) - which can result in errors when a `PointeeSized` supertrait/bound/predicate is added to some items. Rather than `PointeeSized` being a bound on everything, it can be the absence of a bound on everything, as `?Sized` was.
50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
//@ check-fail
|
|
#![feature(extern_types, sized_hierarchy)]
|
|
|
|
use std::marker::{MetaSized, PointeeSized};
|
|
|
|
fn bare<T>() {}
|
|
|
|
|
|
fn sized<T: Sized>() {}
|
|
|
|
fn neg_sized<T: ?Sized>() {}
|
|
|
|
|
|
fn metasized<T: MetaSized>() {}
|
|
|
|
fn neg_metasized<T: ?MetaSized>() {}
|
|
//~^ ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
|
|
|
|
|
fn pointeesized<T: PointeeSized>() { }
|
|
|
|
fn neg_pointeesized<T: ?PointeeSized>() { }
|
|
//~^ ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
|
|
|
|
|
fn main() {
|
|
// Functions which should have a `T: Sized` bound - check for an error given a non-Sized type:
|
|
|
|
bare::<[u8]>();
|
|
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
|
|
sized::<[u8]>();
|
|
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
|
|
metasized::<[u8]>();
|
|
pointeesized::<[u8]>();
|
|
|
|
// Functions which should have a `T: MetaSized` bound - check for an error given a
|
|
// non-MetaSized type:
|
|
unsafe extern "C" {
|
|
type Foo;
|
|
}
|
|
|
|
bare::<Foo>();
|
|
//~^ ERROR the size for values of type `main::Foo` cannot be known
|
|
sized::<Foo>();
|
|
//~^ ERROR the size for values of type `main::Foo` cannot be known
|
|
metasized::<Foo>();
|
|
//~^ ERROR the size for values of type `main::Foo` cannot be known
|
|
pointeesized::<Foo>();
|
|
}
|