Type check unnanotated constant items with NLL
This commit is contained in:
parent
65fe251634
commit
c76e55747b
3 changed files with 128 additions and 62 deletions
|
|
@ -0,0 +1,29 @@
|
|||
// Test that we still check constants are well-formed, even when we there's no
|
||||
// type annotation to check.
|
||||
|
||||
#![feature(nll)]
|
||||
|
||||
const FUN: fn(&'static ()) = |_| {};
|
||||
struct A;
|
||||
impl A {
|
||||
const ASSOCIATED_FUN: fn(&'static ()) = |_| {};
|
||||
}
|
||||
|
||||
struct B<'a>(&'a ());
|
||||
impl B<'static> {
|
||||
const ALSO_ASSOCIATED_FUN: fn(&'static ()) = |_| {};
|
||||
}
|
||||
|
||||
trait Z: 'static {
|
||||
const TRAIT_ASSOCIATED_FUN: fn(&'static Self) = |_| ();
|
||||
}
|
||||
|
||||
impl Z for () {}
|
||||
|
||||
fn main() {
|
||||
let x = ();
|
||||
FUN(&x); //~ ERROR `x` does not live long enough
|
||||
A::ASSOCIATED_FUN(&x); //~ ERROR `x` does not live long enough
|
||||
B::ALSO_ASSOCIATED_FUN(&x); //~ ERROR `x` does not live long enough
|
||||
<_>::TRAIT_ASSOCIATED_FUN(&x); //~ ERROR `x` does not live long enough
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/constant-in-expr-inherent-2.rs:25:9
|
||||
|
|
||||
LL | FUN(&x); //~ ERROR `x` does not live long enough
|
||||
| ----^^-
|
||||
| | |
|
||||
| | borrowed value does not live long enough
|
||||
| argument requires that `x` is borrowed for `'static`
|
||||
...
|
||||
LL | }
|
||||
| - `x` dropped here while still borrowed
|
||||
|
||||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/constant-in-expr-inherent-2.rs:26:23
|
||||
|
|
||||
LL | A::ASSOCIATED_FUN(&x); //~ ERROR `x` does not live long enough
|
||||
| ------------------^^-
|
||||
| | |
|
||||
| | borrowed value does not live long enough
|
||||
| argument requires that `x` is borrowed for `'static`
|
||||
...
|
||||
LL | }
|
||||
| - `x` dropped here while still borrowed
|
||||
|
||||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/constant-in-expr-inherent-2.rs:27:28
|
||||
|
|
||||
LL | B::ALSO_ASSOCIATED_FUN(&x); //~ ERROR `x` does not live long enough
|
||||
| -----------------------^^-
|
||||
| | |
|
||||
| | borrowed value does not live long enough
|
||||
| argument requires that `x` is borrowed for `'static`
|
||||
LL | <_>::TRAIT_ASSOCIATED_FUN(&x); //~ ERROR `x` does not live long enough
|
||||
LL | }
|
||||
| - `x` dropped here while still borrowed
|
||||
|
||||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/constant-in-expr-inherent-2.rs:28:31
|
||||
|
|
||||
LL | <_>::TRAIT_ASSOCIATED_FUN(&x); //~ ERROR `x` does not live long enough
|
||||
| --------------------------^^-
|
||||
| | |
|
||||
| | borrowed value does not live long enough
|
||||
| argument requires that `x` is borrowed for `'static`
|
||||
LL | }
|
||||
| - `x` dropped here while still borrowed
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0597`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue