rust/src
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
..
bootstrap Rollup merge of #51922 - japaric:llvm-tools-preview, r=alexcrichton 2018-07-01 21:18:50 +02:00
build_helper
ci Revert "Auto merge of #51662 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum" 2018-06-21 06:53:26 -06:00
dlmalloc@c99638dc2e
doc Auto merge of #49469 - Nokel81:allow-irrefutable-let-patterns, r=nikomatsakis 2018-06-26 09:20:33 +00:00
etc slightly improve rustdoc xml path error 2018-06-04 09:51:41 +02:00
grammar
jemalloc@1f5a28755e
liballoc Auto merge of #51717 - Mark-Simulacrum:snap, r=alexcrichton 2018-06-30 21:01:05 +00:00
liballoc_jemalloc Mark alloc_jemalloc as perma-unstable 2018-06-11 13:48:57 -07:00
liballoc_system Move Unstable Book sections for #[global_allocator] and System to std::alloc docs 2018-06-11 13:48:57 -07:00
libarena Make raw_vec perma-unstable and hidden 2018-06-29 14:01:33 +02:00
libbacktrace@f4d02bbdbf Replace libbacktrace with a submodule 2018-05-30 05:58:23 -07:00
libcompiler_builtins@4cfd7101eb
libcore Rollup merge of #51853 - MajorBreakfast:fix-doc-links, r=cramertj 2018-07-01 21:18:45 +02:00
libfmt_macros
libgraphviz
liblibc@a7e78a78e1
libpanic_abort
libpanic_unwind
libproc_macro Address comments 2018-06-30 01:53:32 +03:00
libprofiler_builtins
librustc Auto merge of #51110 - alexreg:new-static-eval-rules, r=eddyb 2018-07-01 23:00:27 +00:00
librustc_allocator Implement #[macro_export(local_inner_macros)] 2018-06-27 13:10:16 +03:00
librustc_apfloat migrate codebase to ..= inclusive range patterns 2018-06-26 07:53:30 -07:00
librustc_asan Bootstrap from 1.28.0-beta.3 2018-06-30 13:17:49 -07:00
librustc_borrowck Use Idents in a number of structures in HIR 2018-06-28 11:04:50 +03:00
librustc_codegen_llvm Auto merge of #51828 - kennytm:no-simd-swap-for-mac, r=alexcrichton 2018-06-30 14:00:24 +00:00
librustc_codegen_utils migrate codebase to ..= inclusive range patterns 2018-06-26 07:53:30 -07:00
librustc_cratesio_shim
librustc_data_structures Rename IdxSet::clone_from. 2018-06-29 09:57:19 +10:00
librustc_driver Auto merge of #51806 - oli-obk:lowering_cleanups1, r=cramertj 2018-06-30 07:10:18 +00:00
librustc_errors Fortify dummy span checking 2018-06-30 01:53:32 +03:00
librustc_incremental Make opaque::Encoder append-only and make it infallible 2018-06-27 11:43:15 +02:00
librustc_lint Auto merge of #51882 - varkor:check-type_dependent_defs, r=estebank 2018-07-01 08:41:50 +00:00
librustc_llvm
librustc_lsan Bootstrap from 1.28.0-beta.3 2018-06-30 13:17:49 -07:00
librustc_metadata Auto merge of #51717 - Mark-Simulacrum:snap, r=alexcrichton 2018-06-30 21:01:05 +00:00
librustc_mir Auto merge of #51110 - alexreg:new-static-eval-rules, r=eddyb 2018-07-01 23:00:27 +00:00
librustc_msan Bootstrap from 1.28.0-beta.3 2018-06-30 13:17:49 -07:00
librustc_passes Auto merge of #51883 - estebank:placement-suggestion, r=varkor 2018-07-01 13:37:05 +00:00
librustc_platform_intrinsics
librustc_plugin Implement #[macro_export(local_inner_macros)] 2018-06-27 13:10:16 +03:00
librustc_privacy Auto merge of #51882 - varkor:check-type_dependent_defs, r=estebank 2018-07-01 08:41:50 +00:00
librustc_resolve absoluate -> absolute 2018-07-01 17:37:42 +09:00
librustc_save_analysis Auto merge of #51717 - Mark-Simulacrum:snap, r=alexcrichton 2018-06-30 21:01:05 +00:00
librustc_target Auto merge of #51833 - wesleywiser:faster_large_constant_arrays, r=oli-obk 2018-07-01 18:43:41 +00:00
librustc_traits Use Idents for associated item definitions in HIR 2018-06-28 11:04:50 +03:00
librustc_tsan Bootstrap from 1.28.0-beta.3 2018-06-30 13:17:49 -07:00
librustc_typeck Rollup merge of #51920 - euclio:concrete-type-suggestion, r=estebank 2018-07-01 21:18:47 +02:00
librustdoc Fortify dummy span checking 2018-06-30 01:53:32 +03:00
libserialize Make opaque::Encoder append-only and make it infallible 2018-06-27 11:43:15 +02:00
libstd Rollup merge of #51890 - Ixrec:patch-3, r=alexcrichton 2018-07-01 21:18:46 +02:00
libstd_unicode
libsyntax Auto merge of #51883 - estebank:placement-suggestion, r=varkor 2018-07-01 13:37:05 +00:00
libsyntax_ext Implement #[macro_export(local_inner_macros)] 2018-06-27 13:10:16 +03:00
libsyntax_pos Address comments 2018-06-30 01:53:32 +03:00
libterm migrate codebase to ..= inclusive range patterns 2018-06-26 07:53:30 -07:00
libtest
libunwind
llvm@1c817c7a0c Update LLVM to 1c817c7a0c828b8fc8e8e462afbe5db41c7052d1 2018-06-29 13:58:17 +09:00
llvm-emscripten@2717444753
rtstartup
rustc
rustllvm
stdsimd@a19ca1cd91
test Auto merge of #51110 - alexreg:new-static-eval-rules, r=eddyb 2018-07-01 23:00:27 +00:00
tools Rollup merge of #51922 - japaric:llvm-tools-preview, r=alexcrichton 2018-07-01 21:18:50 +02:00
Cargo.lock Bootstrap from 1.28.0-beta.3 2018-06-30 13:17:49 -07:00
Cargo.toml Change the comment on opt-level = 2 to point to https://github.com/rust-lang/rust/issues/50867 2018-05-29 17:38:23 +02:00
README.md rustc: rename ty::maps to ty::query. 2018-06-14 18:05:12 +03:00
stage0.txt Bootstrap from 1.28.0-beta.3 2018-06-30 13:17:49 -07:00

This directory contains the source code of the rust project, including:

  • rustc and its tests
  • libstd
  • Various submodules for tools, like rustdoc, rls, etc.

For more information on how various parts of the compiler work, see the rustc guide.

Their is also useful content in the following READMEs, which are gradually being moved over to the guide: