]> git.lizzy.rs Git - rust.git/blob - tests/ui/nll/user-annotations/constant-in-expr-inherent-2.rs
Rollup merge of #106144 - tgross35:patch-1, r=Mark-Simulacrum
[rust.git] / tests / ui / nll / user-annotations / constant-in-expr-inherent-2.rs
1 // Test that we still check constants are well-formed, even when we there's no
2 // type annotation to check.
3
4 const FUN: fn(&'static ()) = |_| {};
5 struct A;
6 impl A {
7     const ASSOCIATED_FUN: fn(&'static ()) = |_| {};
8 }
9
10 struct B<'a>(&'a ());
11 impl B<'static> {
12     const ALSO_ASSOCIATED_FUN: fn(&'static ()) = |_| {};
13 }
14
15 trait Z: 'static {
16     const TRAIT_ASSOCIATED_FUN: fn(&'static Self) = |_| ();
17 }
18
19 impl Z for () {}
20
21 fn main() {
22     let x = ();
23     FUN(&x);                        //~ ERROR `x` does not live long enough
24     A::ASSOCIATED_FUN(&x);          //~ ERROR `x` does not live long enough
25     B::ALSO_ASSOCIATED_FUN(&x);     //~ ERROR `x` does not live long enough
26     <_>::TRAIT_ASSOCIATED_FUN(&x);  //~ ERROR `x` does not live long enough
27 }