rust/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const-bound-on-not-const-associated-fn.rs
Raekye 884af362f2 Validate ~const trait bounds on associated fns.
Previously, any associated function could have `~const` trait bounds on
generic parameters, which could lead to ICEs when these bounds were used
on associated functions of non-`#[const_trait] trait` or
non-`impl const` blocks.

Includes changes as per @fee1-dead's comments in #116210.
2023-09-30 19:00:45 -04:00

29 lines
507 B
Rust

#![feature(const_trait_impl, effects)]
#[const_trait]
trait MyTrait {
fn do_something(&self);
}
trait OtherTrait {
fn do_something_else() where Self: ~const MyTrait;
//~^ ERROR `~const` is not allowed here
}
struct MyStruct<T>(T);
impl const MyTrait for u32 {
fn do_something(&self) {}
}
impl<T> MyStruct<T> {
pub fn foo(&self) where T: ~const MyTrait {
//~^ ERROR `~const` is not allowed here
self.0.do_something();
}
}
fn main() {
MyStruct(0u32).foo();
}