rust/src/test
bors c697a56d01 Auto merge of #51110 - alexreg:new-static-eval-rules, r=eddyb
Loosened rules involving statics mentioning other statics

Before this PR, trying to mention a static in any way other than taking a reference to it caused a compile-time error. So, while

```rust
static A: u32 = 42;
static B: &u32 = &A;
```

compiles successfully,

```rust
static A: u32 = 42;
static B: u32 = A; // error
```

and

```rust
static A: u32 = 42;
static B: u32 = *&A; // error
```

are not possible to express in Rust. On the other hand, introducing an intermediate `const fn` can presently allow one to do just that:

```rust
static A: u32 = 42;
static B: u32 = foo(&A); // success!

const fn foo(a: &u32) -> u32 {
    *a
}
```

Preventing `const fn` from allowing to work around the ban on reading from statics would cripple `const fn` almost into uselessness.
Additionally, the limitation for reading from statics comes from the old const evaluator(s) and is not shared by `miri`.

This PR loosens the rules around use of statics to allow statics to evaluate other statics by value, allowing all of the above examples to compile and run successfully.
Reads from extern (foreign) statics are however still disallowed by miri, because there is no compile-time value to be read.

```rust
extern static A: u32;

static B: u32 = A; // error
```

This opens up a new avenue of potential issues, as a static can now not just refer to other statics or read from other statics, but even contain references that point into itself.
While it might seem like this could cause subtle bugs like allowing a static to be initialized by its own value, this is inherently impossible in miri.
Reading from a static causes the `const_eval` query for that static to be invoked. Calling the `const_eval` query for a static while already inside the `const_eval` query of said static will cause cycle errors.
It is not possible to accidentally create a bug in miri that would enable initializing a static with itself, because the memory of the static *does not exist* while being initialized.
The memory is not uninitialized, it is not there. Thus any change that would accidentally allow reading from a not yet initialized static would cause ICEs.

Tests have been modified according to the new rules, and new tests have been added for writing to `static mut`s within definitions of statics (which needs to fail), and incremental compilation with complex/interlinking static definitions.
Note that incremental compilation did not need to be adjusted, because all of this was already possible before with workarounds (like intermediate `const fn`s) and the encoding/decoding already supports all the possible cases.

r? @eddyb
2018-07-01 23:00:27 +00:00
..
auxiliary
codegen Do not allow LLVM to increase a TLS's alignment on macOS. 2018-06-30 21:36:03 +08:00
codegen-units Rename trans to codegen everywhere. 2018-05-17 15:08:30 +03:00
compile-fail Auto merge of #51110 - alexreg:new-static-eval-rules, r=eddyb 2018-07-01 23:00:27 +00:00
compile-fail-fulldeps proc-macro: Use transparent marks for call-site hygiene 2018-06-30 01:53:32 +03:00
debuginfo Rename trans to codegen everywhere. 2018-05-17 15:08:30 +03:00
incremental Added incremental test for interlinking static references. 2018-06-30 23:53:52 +01:00
incremental-fulldeps
mir-opt Update MIR opt tests 2018-06-27 22:06:21 +01:00
parse-fail structured suggestion and rewording for ... expression syntax error 2018-06-23 22:57:37 -07:00
pretty
run-fail Fix tests 2018-06-05 10:35:44 +02:00
run-fail-fulldeps
run-make turn run-make test into a run-make-fulldeps test 2018-06-03 19:57:49 +02:00
run-make-fulldeps fix tidy 2018-06-21 13:49:03 -05:00
run-pass Auto merge of #51110 - alexreg:new-static-eval-rules, r=eddyb 2018-07-01 23:00:27 +00:00
run-pass-fulldeps proc-macro: Use transparent marks for call-site hygiene 2018-06-30 01:53:32 +03:00
run-pass-valgrind Remove some '#[feature]' attributes for stabilized features 2018-06-11 13:48:57 -07:00
rustdoc Auto merge of #51425 - QuietMisdreavus:thats-def-a-namespace-there, r=petrochenkov 2018-06-17 09:48:10 +00:00
rustdoc-js Make raw_vec perma-unstable and hidden 2018-06-29 14:01:33 +02:00
rustdoc-ui Rename intra-doc lint 2018-06-13 23:30:34 +02:00
rustfix Removed various update-reference and update-all-references scripts 2018-06-13 18:15:50 -04:00
ui Auto merge of #51110 - alexreg:new-static-eval-rules, r=eddyb 2018-07-01 23:00:27 +00:00
ui-fulldeps Removed various update-reference and update-all-references scripts 2018-06-13 18:15:50 -04:00
COMPILER_TESTS.md Update docs and diagnostics 2018-05-17 16:28:36 +02:00