-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type check unnanotated constant items with NLL
- Loading branch information
1 parent
65fe251
commit c76e557
Showing
3 changed files
with
128 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/test/ui/nll/user-annotations/constant-in-expr-inherent-2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
50 changes: 50 additions & 0 deletions
50
src/test/ui/nll/user-annotations/constant-in-expr-inherent-2.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |