//@ compile-flags: -Zexperimental-default-bounds #![feature( auto_traits, associated_type_defaults, generic_const_items, lang_items, more_maybe_bounds, negative_impls, no_core, rustc_attrs )] #![allow(incomplete_features)] #![no_std] #![no_core] #[lang = "sized"] trait Sized {} #[lang = "legacy_receiver"] trait LegacyReceiver {} impl LegacyReceiver for &T {} impl LegacyReceiver for &mut T {} #[lang = "default_trait1"] auto trait Leak {} struct NonLeakS; impl !Leak for NonLeakS {} struct LeakS; mod supertraits { use crate::*; trait MaybeLeakT1: ?Leak {} trait MaybeLeakT2 where Self: ?Leak {} impl MaybeLeakT1 for NonLeakS {} impl MaybeLeakT2 for NonLeakS {} } mod maybe_self_assoc_type { use crate::*; trait TestBase1 {} trait TestBase2 {} trait Test1 { type MaybeLeakSelf: TestBase1 where Self: ?Leak; //~^ ERROR the trait bound `Self: Leak` is not satisfied type LeakSelf: TestBase1; } trait Test2 { type MaybeLeakSelf: TestBase2 where Self: ?Leak; type LeakSelf: TestBase2; } trait Test3 { type Leak1 = LeakS; type Leak2 = NonLeakS; //~^ ERROR the trait bound `NonLeakS: Leak` is not satisfied } trait Test4 { type MaybeLeak1: ?Leak = LeakS; type MaybeLeak2: ?Leak = NonLeakS; } trait Test5: ?Leak { // ok, because assoc types have implicit where Self: Leak type MaybeLeakSelf1: TestBase1; type MaybeLeakSelf2: TestBase2; } } mod maybe_self_assoc_const { use crate::*; const fn size_of() -> usize { 0 } trait Trait { const CLeak: usize = size_of::(); const CNonLeak: usize = size_of::() where Self: ?Leak; //~^ ERROR the trait bound `Self: Leak` is not satisfied } } mod methods { use crate::*; trait Trait { fn leak_foo(&self) {} fn maybe_leak_foo(&self) where Self: ?Leak {} fn mut_leak_foo(&mut self) {} // there is no relax bound on corresponding Receiver impl fn mut_maybe_leak_foo(&mut self) where Self: ?Leak {} //~^ `&mut Self` cannot be used as the type of `self` without the `arbitrary_self_types` } impl Trait for NonLeakS {} impl Trait for LeakS {} fn foo() { LeakS.leak_foo(); LeakS.maybe_leak_foo(); NonLeakS.leak_foo(); //~^ ERROR the trait bound `NonLeakS: Leak` is not satisfied NonLeakS.maybe_leak_foo(); } } fn main() {}