From 1da44451098e9947fa398e7d2858853a8964c200 Mon Sep 17 00:00:00 2001
From: Joshua Nelson <jyn514@gmail.com>
Date: Sat, 1 May 2021 00:06:17 -0400
Subject: [PATCH 1/7] Apply `--cfg parallel_compiler` when documenting

This also reverts commit 9823c2cc700fea541bf2670fcee93af662b63022
working around the bug.
---
 compiler/rustc_middle/src/ty/query/mod.rs |  1 +
 compiler/rustc_query_impl/src/plumbing.rs | 10 ++++------
 src/bootstrap/compile.rs                  |  1 +
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs
index c170858ba85a1..f50c506f169b9 100644
--- a/compiler/rustc_middle/src/ty/query/mod.rs
+++ b/compiler/rustc_middle/src/ty/query/mod.rs
@@ -233,6 +233,7 @@ macro_rules! define_callbacks {
         }
 
         pub trait QueryEngine<'tcx>: rustc_data_structures::sync::Sync {
+            #[cfg(parallel_compiler)]
             unsafe fn deadlock(&'tcx self, tcx: TyCtxt<'tcx>, registry: &rustc_rayon_core::Registry);
 
             fn encode_query_results(
diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs
index ee914fa1ba95c..c789aa2fa596e 100644
--- a/compiler/rustc_query_impl/src/plumbing.rs
+++ b/compiler/rustc_query_impl/src/plumbing.rs
@@ -550,12 +550,10 @@ macro_rules! define_queries_struct {
         }
 
         impl QueryEngine<'tcx> for Queries<'tcx> {
-            unsafe fn deadlock(&'tcx self, _tcx: TyCtxt<'tcx>, _registry: &rustc_rayon_core::Registry) {
-                #[cfg(parallel_compiler)]
-                {
-                    let tcx = QueryCtxt { tcx: _tcx, queries: self };
-                    rustc_query_system::query::deadlock(tcx, _registry)
-                }
+            #[cfg(parallel_compiler)]
+            unsafe fn deadlock(&'tcx self, tcx: TyCtxt<'tcx>, registry: &rustc_rayon_core::Registry) {
+                let tcx = QueryCtxt { tcx, queries: self };
+                rustc_query_system::query::deadlock(tcx, registry)
             }
 
             fn encode_query_results(
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
index 66a88e85fea39..2676b3bf8e005 100644
--- a/src/bootstrap/compile.rs
+++ b/src/bootstrap/compile.rs
@@ -648,6 +648,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
     }
     if builder.config.rustc_parallel {
         cargo.rustflag("--cfg=parallel_compiler");
+        cargo.rustdocflag("--cfg=parallel_compiler");
     }
     if builder.config.rust_verify_llvm_ir {
         cargo.env("RUSTC_VERIFY_LLVM_IR", "1");

From dadcb0550d41c343988310ee1946d8dd8f477008 Mon Sep 17 00:00:00 2001
From: Joshua Nelson <jyn514@gmail.com>
Date: Sat, 1 May 2021 01:56:52 -0400
Subject: [PATCH 2/7] Allow formatting specific subdirectories

---
 src/bootstrap/flags.rs  |  3 ++-
 src/bootstrap/format.rs | 17 ++++++++++++++---
 src/bootstrap/lib.rs    |  4 ++--
 src/bootstrap/test.rs   |  2 +-
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs
index 6044899c237e2..c7034dfeaabd7 100644
--- a/src/bootstrap/flags.rs
+++ b/src/bootstrap/flags.rs
@@ -91,6 +91,7 @@ pub enum Subcommand {
         paths: Vec<PathBuf>,
     },
     Format {
+        paths: Vec<PathBuf>,
         check: bool,
     },
     Doc {
@@ -578,7 +579,7 @@ Arguments:
 
                 Subcommand::Clean { all: matches.opt_present("all") }
             }
-            "fmt" => Subcommand::Format { check: matches.opt_present("check") },
+            "fmt" => Subcommand::Format { check: matches.opt_present("check"), paths },
             "dist" => Subcommand::Dist { paths },
             "install" => Subcommand::Install { paths },
             "run" | "r" => {
diff --git a/src/bootstrap/format.rs b/src/bootstrap/format.rs
index d21e3408144fe..2408344487bb1 100644
--- a/src/bootstrap/format.rs
+++ b/src/bootstrap/format.rs
@@ -42,7 +42,7 @@ struct RustfmtConfig {
     ignore: Vec<String>,
 }
 
-pub fn format(build: &Build, check: bool) {
+pub fn format(build: &Build, check: bool, paths: &[PathBuf]) {
     if build.config.dry_run {
         return;
     }
@@ -118,8 +118,19 @@ pub fn format(build: &Build, check: bool) {
         .to_path_buf();
     let src = build.src.clone();
     let (tx, rx): (SyncSender<PathBuf>, _) = std::sync::mpsc::sync_channel(128);
-    let walker =
-        WalkBuilder::new(src.clone()).types(matcher).overrides(ignore_fmt).build_parallel();
+    let walker = match paths.get(0) {
+        Some(first) => {
+            let mut walker = WalkBuilder::new(first);
+            for path in &paths[1..] {
+                walker.add(path);
+            }
+            walker
+        }
+        None => WalkBuilder::new(src.clone()),
+    }
+    .types(matcher)
+    .overrides(ignore_fmt)
+    .build_parallel();
 
     // there is a lot of blocking involved in spawning a child process and reading files to format.
     // spawn more processes than available concurrency to keep the CPU busy
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index 24da44b933abc..2960dd3df6bf4 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -478,8 +478,8 @@ impl Build {
             job::setup(self);
         }
 
-        if let Subcommand::Format { check } = self.config.cmd {
-            return format::format(self, check);
+        if let Subcommand::Format { check, paths } = &self.config.cmd {
+            return format::format(self, *check, &paths);
         }
 
         if let Subcommand::Clean { all } = self.config.cmd {
diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs
index 965d11621450b..a115ea905aa72 100644
--- a/src/bootstrap/test.rs
+++ b/src/bootstrap/test.rs
@@ -897,7 +897,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
                 );
                 std::process::exit(1);
             }
-            crate::format::format(&builder.build, !builder.config.cmd.bless());
+            crate::format::format(&builder.build, !builder.config.cmd.bless(), &[]);
         }
     }
 

From c016e93d96983b97a29f5e18b4207341599cbf2b Mon Sep 17 00:00:00 2001
From: Joshua Nelson <jyn514@gmail.com>
Date: Thu, 6 May 2021 14:33:05 -0400
Subject: [PATCH 3/7] RELEASES.md: Use broken_intra_doc_links as an example,
 not a nightly lint

`non_autolinks` has since been renamed and also was unstable at the time
this was written.
---
 RELEASES.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/RELEASES.md b/RELEASES.md
index 1f940e6bc2d3b..92312d8d556ee 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -58,7 +58,7 @@ The following previously stable APIs are now `const`.
 Rustdoc
 -------
 - [Rustdoc lints are now treated as a tool lint, meaning that
-  lints are now prefixed with `rustdoc::` (e.g. `#[warn(rustdoc::non_autolinks)]`).][80527]
+  lints are now prefixed with `rustdoc::` (e.g. `#[warn(rustdoc::broken_intra_doc_links)]`).][80527]
   Using the old style is still allowed, and will become a warning in
   a future release.
 - [Rustdoc now supports argument files.][82261]

From e4b57e18849726fd31081811bb8333842fa27480 Mon Sep 17 00:00:00 2001
From: Joshua Nelson <jyn514@gmail.com>
Date: Fri, 7 May 2021 16:06:01 -0400
Subject: [PATCH 4/7] Allow checking miri and RLS with `x.py check
 src/tools/{miri,rls}`

---
 src/bootstrap/builder.rs | 2 ++
 src/bootstrap/check.rs   | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 62a3a87eeb850..f2dcd70d506b9 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -377,6 +377,8 @@ impl<'a> Builder<'a> {
                 check::Rustdoc,
                 check::CodegenBackend,
                 check::Clippy,
+                check::Miri,
+                check::Rls,
                 check::Bootstrap
             ),
             Kind::Test => describe!(
diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs
index 8561a2a39b8ea..3e9d921d0f526 100644
--- a/src/bootstrap/check.rs
+++ b/src/bootstrap/check.rs
@@ -289,7 +289,8 @@ macro_rules! tool_check_step {
         impl Step for $name {
             type Output = ();
             const ONLY_HOSTS: bool = true;
-            const DEFAULT: bool = true $( && $default )?;
+            // don't ever check out-of-tree tools by default, they'll fail when toolstate is broken
+            const DEFAULT: bool = matches!($source_type, SourceType::InTree) $( && $default )?;
 
             fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
                 run.paths(&[ $path, $($alias),* ])
@@ -367,6 +368,8 @@ tool_check_step!(Rustdoc, "src/tools/rustdoc", "src/librustdoc", SourceType::InT
 // behavior, treat it as in-tree so that any new warnings in clippy will be
 // rejected.
 tool_check_step!(Clippy, "src/tools/clippy", SourceType::InTree);
+tool_check_step!(Miri, "src/tools/miri", SourceType::Submodule);
+tool_check_step!(Rls, "src/tools/rls", SourceType::Submodule);
 
 tool_check_step!(Bootstrap, "src/bootstrap", SourceType::InTree, false);
 

From 506031fc78108c403086f620bccd3ba779653f1b Mon Sep 17 00:00:00 2001
From: Joshua Nelson <jyn514@gmail.com>
Date: Sun, 9 May 2021 12:24:59 -0400
Subject: [PATCH 5/7] Remove outdated FIXME for download-rustc

---
 config.toml.example | 2 --
 1 file changed, 2 deletions(-)

diff --git a/config.toml.example b/config.toml.example
index 6e5584797b559..16952a5ced83e 100644
--- a/config.toml.example
+++ b/config.toml.example
@@ -372,8 +372,6 @@ changelog-seen = 2
 # This is mostly useful for tools; if you have changes to `compiler/` they will be ignored.
 #
 # You can set this to "if-unchanged" to only download if `compiler/` has not been modified.
-#
-# FIXME(#82739): currently, this also uses the downloaded compiler for stage0, but that causes unnecessary rebuilds.
 #download-rustc = false
 
 # Number of codegen units to use for each compiler invocation. A value of 0

From 5068cbc90184699eb35507a6d6acd347fc0627be Mon Sep 17 00:00:00 2001
From: Deadbeef <fee1-dead-beef@protonmail.com>
Date: Mon, 10 May 2021 18:46:13 +0800
Subject: [PATCH 6/7] Document Rc::from

---
 library/alloc/src/rc.rs | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs
index 964169a227f64..800952f7a5ece 100644
--- a/library/alloc/src/rc.rs
+++ b/library/alloc/src/rc.rs
@@ -1733,6 +1733,19 @@ impl<T: ?Sized> fmt::Pointer for Rc<T> {
 
 #[stable(feature = "from_for_ptrs", since = "1.6.0")]
 impl<T> From<T> for Rc<T> {
+    /// Converts a generic type `T` into a `Rc<T>`
+    ///
+    /// The conversion allocates on the heap and moves `t`
+    /// from the stack into it.
+    ///
+    /// # Example
+    /// ```rust
+    /// # use std::rc::Rc;
+    /// let x = 5;
+    /// let rc = Rc::new(5);
+    ///
+    /// assert_eq!(Rc::from(x), rc);
+    /// ```
     fn from(t: T) -> Self {
         Rc::new(t)
     }

From a4c0793551326cbe6f205005d1aa0f35410e89da Mon Sep 17 00:00:00 2001
From: Aaron Hill <aa1ronham@gmail.com>
Date: Thu, 6 May 2021 13:44:17 -0400
Subject: [PATCH 7/7] Show nicer error when an 'unstable fingerprints' error
 occurs

---
 .../rustc_query_system/src/query/plumbing.rs  | 20 ++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs
index 68d2d619aabb4..39dfdd78cc4f5 100644
--- a/compiler/rustc_query_system/src/query/plumbing.rs
+++ b/compiler/rustc_query_system/src/query/plumbing.rs
@@ -605,13 +605,19 @@ fn incremental_verify_ich<CTX, K, V: Debug>(
 
     let old_hash = tcx.dep_graph().prev_fingerprint_of(dep_node);
 
-    assert_eq!(
-        Some(new_hash),
-        old_hash,
-        "found unstable fingerprints for {:?}: {:?}",
-        dep_node,
-        result
-    );
+    if Some(new_hash) != old_hash {
+        let run_cmd = if let Some(crate_name) = &tcx.sess().opts.crate_name {
+            format!("`cargo clean -p {}` or `cargo clean`", crate_name)
+        } else {
+            "`cargo clean`".to_string()
+        };
+        tcx.sess().struct_err(&format!("internal compiler error: encountered incremental compilation error with {:?}", dep_node))
+            .help(&format!("This is a known issue with the compiler. Run {} to allow your project to compile", run_cmd))
+            .note(&format!("Please follow the instructions below to create a bug report with the provided information"))
+            .note(&format!("See <https://github.com/rust-lang/rust/issues/84970> for more information"))
+            .emit();
+        panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result);
+    }
 }
 
 fn force_query_with_job<C, CTX>(