2024-06-30 17:08:45 +00:00
//@ compile-flags: -Znext-solver
2024-12-09 19:34:43 +00:00
#![ cfg_attr(any(yyy, yyn, yny, ynn), feature(const_trait_impl)) ]
2022-10-03 17:08:42 +00:00
2024-12-09 19:34:43 +00:00
//@ revisions: yyy yyn yny ynn nyy nyn nny nnn
//@[yyy] check-pass
/// yyy: feature enabled, Foo is const, Bar is const
/// yyn: feature enabled, Foo is const, Bar is not const
/// yny: feature enabled, Foo is not const, Bar is const
/// ynn: feature enabled, Foo is not const, Bar is not const
/// nyy: feature not enabled, Foo is const, Bar is const
/// nyn: feature not enabled, Foo is const, Bar is not const
/// nny: feature not enabled, Foo is not const, Bar is const
/// nnn: feature not enabled, Foo is not const, Bar is not const
2022-10-03 17:08:42 +00:00
2024-12-09 19:34:43 +00:00
#[ cfg_attr(any(yyy, yyn, nyy, nyn), const_trait) ]
//[nyy,nyn]~^ ERROR: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future
2022-10-03 17:08:42 +00:00
trait Foo {
fn a ( & self ) ;
}
2024-12-09 19:34:43 +00:00
#[ cfg_attr(any(yyy, yny, nyy, nyn), const_trait) ]
//[nyy,nyn]~^ ERROR: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future
2022-10-03 17:08:42 +00:00
trait Bar : ~ const Foo { }
2024-12-09 19:34:43 +00:00
//[yny,ynn,nny,nnn]~^ ERROR: `~const` can only be applied to `#[const_trait]`
//[yny,ynn,nny,nnn]~| ERROR: `~const` can only be applied to `#[const_trait]`
//[yny,ynn,nny,nnn]~| ERROR: `~const` can only be applied to `#[const_trait]`
//[yny]~^^^^ ERROR: `~const` can only be applied to `#[const_trait]`
//[yny]~| ERROR: `~const` can only be applied to `#[const_trait]`
//[yyn,ynn,nny,nnn]~^^^^^^ ERROR: `~const` is not allowed here
//[nyy,nyn,nny,nnn]~^^^^^^^ ERROR: const trait impls are experimental
2022-10-03 17:08:42 +00:00
const fn foo < T : ~ const Bar > ( x : & T ) {
2024-12-09 19:34:43 +00:00
//[yyn,ynn,nny,nnn]~^ ERROR: `~const` can only be applied to `#[const_trait]`
//[yyn,ynn,nny,nnn]~| ERROR: `~const` can only be applied to `#[const_trait]`
//[nyy,nyn,nny,nnn]~^^^ ERROR: const trait impls are experimental
2022-10-03 17:08:42 +00:00
x . a ( ) ;
2024-12-09 19:34:43 +00:00
//[yyn]~^ ERROR: the trait bound `T: ~const Foo` is not satisfied
2024-12-23 21:49:48 +00:00
//[ynn,yny,nny,nnn]~^^ ERROR: cannot call non-const method `<T as Foo>::a` in constant functions
2024-12-09 19:34:43 +00:00
//[nyy,nyn]~^^^ ERROR: cannot call conditionally-const method `<T as Foo>::a` in constant functions
2022-10-03 17:08:42 +00:00
}
fn main ( ) { }