mirror of
				https://github.com/rust-lang/rust.git
				synced 2025-10-31 04:57:19 +00:00 
			
		
		
		
	 86ab2b60cd
			
		
	
	
		86ab2b60cd
		
			
		
	
	
	
	
		
			
			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.
		
			
				
	
	
		
			62 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| //@ check-fail
 | |
| #![feature(sized_hierarchy)]
 | |
| 
 | |
| use std::marker::{MetaSized, PointeeSized};
 | |
| 
 | |
| trait Sized_: Sized { }
 | |
| 
 | |
| trait NegSized: ?Sized { }
 | |
| //~^ ERROR `?Trait` is not permitted in supertraits
 | |
| 
 | |
| trait MetaSized_: MetaSized { }
 | |
| 
 | |
| trait NegMetaSized: ?MetaSized { }
 | |
| //~^ ERROR `?Trait` is not permitted in supertraits
 | |
| 
 | |
| 
 | |
| trait PointeeSized_: PointeeSized { }
 | |
| 
 | |
| trait NegPointeeSized: ?PointeeSized { }
 | |
| //~^ ERROR `?Trait` is not permitted in supertraits
 | |
| 
 | |
| trait Bare {}
 | |
| 
 | |
| fn requires_sized<T: Sized>() {}
 | |
| fn requires_metasized<T: MetaSized>() {}
 | |
| fn requires_pointeesized<T: PointeeSized>() {}
 | |
| 
 | |
| fn with_sized_supertrait<T: PointeeSized + Sized_>() {
 | |
|     requires_sized::<T>();
 | |
|     requires_metasized::<T>();
 | |
|     requires_pointeesized::<T>();
 | |
| }
 | |
| 
 | |
| fn with_metasized_supertrait<T: PointeeSized + MetaSized_>() {
 | |
|     requires_sized::<T>();
 | |
|     //~^ ERROR the size for values of type `T` cannot be known at compilation time
 | |
|     requires_metasized::<T>();
 | |
|     requires_pointeesized::<T>();
 | |
| }
 | |
| 
 | |
| // It isn't really possible to write this one..
 | |
| fn with_pointeesized_supertrait<T: PointeeSized + PointeeSized_>() {
 | |
|     requires_sized::<T>();
 | |
|     //~^ ERROR the size for values of type `T` cannot be known
 | |
|     requires_metasized::<T>();
 | |
|     //~^ ERROR the size for values of type `T` cannot be known
 | |
|     requires_pointeesized::<T>();
 | |
| }
 | |
| 
 | |
| // `T` won't inherit the `const MetaSized` implicit supertrait of `Bare`, so there is an error on
 | |
| // the bound, which is expected.
 | |
| fn with_bare_trait<T: PointeeSized + Bare>() {
 | |
| //~^ ERROR the size for values of type `T` cannot be known
 | |
|     requires_sized::<T>();
 | |
|     //~^ ERROR the size for values of type `T` cannot be known
 | |
|     requires_metasized::<T>();
 | |
|     //~^ ERROR the size for values of type `T` cannot be known
 | |
|     requires_pointeesized::<T>();
 | |
| }
 | |
| 
 | |
| fn main() { }
 |