mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-03 02:40:40 +00:00

* The phrasing "only does something for" made sense back when this diagnostic was a (hard) warning. Now however, it's simply a hard error and thus completely rules out "doing something". * The primary message was way too long * The new wording more closely mirrors the wording we use for applying other bound modifiers (like `const` and `async`) to incompatible traits. * "all other traits are not bound by default" is no longer accurate under Sized Hierarchy. E.g., traits and assoc tys are (currently) bounded by `MetaSized` by default but can't be relaxed using `?MetaSized` (instead, you relax it by adding `PointeeSized`). * I've decided against adding any diagnositic notes or suggestions for now like "trait `Trait` can't be relaxed as it's not bound by default" which would be incorrect for `MetaSized` and assoc tys as mentioned above) or "consider changing `?MetaSized` to `PointeeSized`" as the Sized Hierarchy impl is still WIP)
50 lines
1.3 KiB
Rust
50 lines
1.3 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 bound modifier `?` can only be applied to `Sized`
|
|
|
|
|
|
fn pointeesized<T: PointeeSized>() { }
|
|
|
|
fn neg_pointeesized<T: ?PointeeSized>() { }
|
|
//~^ ERROR bound modifier `?` can only be applied to `Sized`
|
|
|
|
|
|
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>();
|
|
}
|