]> git.lizzy.rs Git - rust.git/blob - tests/ui/const-generics/invariant.rs
Auto merge of #106458 - albertlarsan68:move-tests, r=jyn514
[rust.git] / tests / ui / const-generics / invariant.rs
1 #![feature(generic_const_exprs)]
2 #![allow(incomplete_features)]
3 use std::marker::PhantomData;
4
5 trait SadBee {
6     const ASSOC: usize;
7 }
8 // fn(&'static ())` is a supertype of `for<'a> fn(&'a ())` while
9 // we allow two different impls for these types, leading
10 // to different const eval results.
11 impl SadBee for for<'a> fn(&'a ()) {
12     const ASSOC: usize = 0;
13 }
14 impl SadBee for fn(&'static ()) {
15     //~^ WARNING conflicting implementations of trait
16     //~| WARNING this was previously accepted
17     const ASSOC: usize = 100;
18 }
19
20 struct Foo<T: SadBee>([u8; <T as SadBee>::ASSOC], PhantomData<T>)
21 where
22     [(); <T as SadBee>::ASSOC]: ;
23
24 fn covariant(
25     v: &'static Foo<for<'a> fn(&'a ())>
26 ) -> &'static Foo<fn(&'static ())> {
27     v
28     //~^ ERROR mismatched types
29 }
30
31 fn main() {
32     let y = covariant(&Foo([], PhantomData));
33     println!("{:?}", y.0);
34 }