about summary refs log tree commit diff
path: root/compiler/rustc_incremental/src/persist/file_format.rs
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2020-10-10 14:27:52 -0400
committerJoshua Nelson <jyn514@gmail.com>2020-11-07 13:45:11 -0500
commit622c48e4f1a5bc3727f8ead89767c8a9e367a77e (patch)
tree559b4777071477577cca6b704a6e5f70deca06e7 /compiler/rustc_incremental/src/persist/file_format.rs
parentdc06a36074f04c6a77b5834f2950011d49607898 (diff)
downloadrust-622c48e4f1a5bc3727f8ead89767c8a9e367a77e.tar.gz
rust-622c48e4f1a5bc3727f8ead89767c8a9e367a77e.zip
Allow making `RUSTC_BOOTSTRAP` conditional on the crate name
The main change is that `UnstableOptions::from_environment` now requires
an (optional) crate name. If the crate name is unknown (`None`), then the new feature is not available and you still have to use `RUSTC_BOOTSTRAP=1`. In practice this means the feature is only available for `--crate-name`, not for `#![crate_name]`; I'm interested in supporting the second but I'm not sure how.

Other major changes:

- Added `Session::is_nightly_build()`, which uses the `crate_name` of
the session
- Added `nightly_options::match_is_nightly_build`, a convenience method
for looking up `--crate-name` from CLI arguments.
`Session::is_nightly_build()`should be preferred where possible, since
it will take into account `#![crate_name]` (I think).
- Added `unstable_features` to `rustdoc::RenderOptions`

  There is a user-facing change here: things like `RUSTC_BOOTSTRAP=0` no
  longer active nightly features. In practice this shouldn't be a big
  deal, since `RUSTC_BOOTSTRAP` is the opposite of stable and everyone
  uses `RUSTC_BOOTSTRAP=1` anyway.

- Add tests

  Check against `Cheat`, not whether nightly features are allowed.
  Nightly features are always allowed on the nightly channel.

- Only call `is_nightly_build()` once within a function

- Use booleans consistently for rustc_incremental

  Sessions can't be passed through threads, so `read_file` couldn't take a
  session. To be consistent, also take a boolean in `write_file_header`.
Diffstat (limited to 'compiler/rustc_incremental/src/persist/file_format.rs')
-rw-r--r--compiler/rustc_incremental/src/persist/file_format.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/compiler/rustc_incremental/src/persist/file_format.rs b/compiler/rustc_incremental/src/persist/file_format.rs
index 048a81b81ba..e185ee24d17 100644
--- a/compiler/rustc_incremental/src/persist/file_format.rs
+++ b/compiler/rustc_incremental/src/persist/file_format.rs
@@ -15,7 +15,6 @@ use std::io::{self, Read};
 use std::path::Path;
 
 use rustc_serialize::opaque::Encoder;
-use rustc_session::config::nightly_options;
 
 /// The first few bytes of files generated by incremental compilation.
 const FILE_MAGIC: &[u8] = b"RSIC";
@@ -28,12 +27,12 @@ const HEADER_FORMAT_VERSION: u16 = 0;
 /// the Git commit hash.
 const RUSTC_VERSION: Option<&str> = option_env!("CFG_VERSION");
 
-pub fn write_file_header(stream: &mut Encoder) {
+pub fn write_file_header(stream: &mut Encoder, nightly_build: bool) {
     stream.emit_raw_bytes(FILE_MAGIC);
     stream
         .emit_raw_bytes(&[(HEADER_FORMAT_VERSION >> 0) as u8, (HEADER_FORMAT_VERSION >> 8) as u8]);
 
-    let rustc_version = rustc_version();
+    let rustc_version = rustc_version(nightly_build);
     assert_eq!(rustc_version.len(), (rustc_version.len() as u8) as usize);
     stream.emit_raw_bytes(&[rustc_version.len() as u8]);
     stream.emit_raw_bytes(rustc_version.as_bytes());
@@ -51,6 +50,7 @@ pub fn write_file_header(stream: &mut Encoder) {
 pub fn read_file(
     report_incremental_info: bool,
     path: &Path,
+    nightly_build: bool,
 ) -> io::Result<Option<(Vec<u8>, usize)>> {
     if !path.exists() {
         return Ok(None);
@@ -93,7 +93,7 @@ pub fn read_file(
         let mut buffer = vec![0; rustc_version_str_len];
         file.read_exact(&mut buffer)?;
 
-        if buffer != rustc_version().as_bytes() {
+        if buffer != rustc_version(nightly_build).as_bytes() {
             report_format_mismatch(report_incremental_info, path, "Different compiler version");
             return Ok(None);
         }
@@ -115,8 +115,8 @@ fn report_format_mismatch(report_incremental_info: bool, file: &Path, message: &
     }
 }
 
-fn rustc_version() -> String {
-    if nightly_options::is_nightly_build() {
+fn rustc_version(nightly_build: bool) -> String {
+    if nightly_build {
         if let Some(val) = env::var_os("RUSTC_FORCE_INCR_COMP_ARTIFACT_HEADER") {
             return val.to_string_lossy().into_owned();
         }