From 878cfb5a4abe70f6f813ae68216efe935ea40f5d Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 30 Nov 2020 22:54:20 -0500 Subject: [PATCH] Fix `unknown-crate` when using self-profile with rustdoc ... by removing a duplicate `crate_name` field in `interface::Config`, making it clear that rustdoc should be passing it to `config::Options` instead. --- compiler/rustc_driver/src/lib.rs | 2 -- compiler/rustc_interface/src/interface.rs | 3 --- compiler/rustc_interface/src/queries.rs | 12 +++++------- compiler/rustc_session/src/session.rs | 2 +- src/librustdoc/core.rs | 2 +- src/librustdoc/doctest.rs | 2 +- src/test/run-make-fulldeps/issue-19371/foo.rs | 1 - 7 files changed, 8 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index c1741bfaaba..b3466f49b9f 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -223,7 +223,6 @@ fn run_compiler( file_loader: None, diagnostic_output, stderr: None, - crate_name: None, lint_caps: Default::default(), register_lints: None, override_queries: None, @@ -307,7 +306,6 @@ fn run_compiler( file_loader, diagnostic_output, stderr: None, - crate_name: None, lint_caps: Default::default(), register_lints: None, override_queries: None, diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 11dd6ec32c0..acd49d86c2c 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -34,7 +34,6 @@ pub struct Compiler { pub(crate) input_path: Option, pub(crate) output_dir: Option, pub(crate) output_file: Option, - pub(crate) crate_name: Option, pub(crate) register_lints: Option>, pub(crate) override_queries: Option, @@ -140,7 +139,6 @@ pub struct Config { /// Set to capture stderr output during compiler execution pub stderr: Option>>>, - pub crate_name: Option, pub lint_caps: FxHashMap, /// This is a callback from the driver that is called when we're registering lints; @@ -185,7 +183,6 @@ pub fn create_compiler_and_run(config: Config, f: impl FnOnce(&Compiler) -> R input_path: config.input_path, output_dir: config.output_dir, output_file: config.output_file, - crate_name: config.crate_name, register_lints: config.register_lints, override_queries: config.override_queries, }; diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index a2704c3adbf..4c340b3fc1f 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -156,13 +156,11 @@ impl<'tcx> Queries<'tcx> { pub fn crate_name(&self) -> Result<&Query> { self.crate_name.compute(|| { - Ok(match self.compiler.crate_name { - Some(ref crate_name) => crate_name.clone(), - None => { - let parse_result = self.parse()?; - let krate = parse_result.peek(); - find_crate_name(self.session(), &krate.attrs, &self.compiler.input) - } + Ok({ + let parse_result = self.parse()?; + let krate = parse_result.peek(); + // parse `#[crate_name]` even if `--crate-name` was passed, to make sure it matches. + find_crate_name(self.session(), &krate.attrs, &self.compiler.input) }) }) } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 5dddf0eb72e..1352ab53cab 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1338,7 +1338,7 @@ pub fn build_session( let profiler = SelfProfiler::new( directory, - sopts.crate_name.as_ref().map(|s| &s[..]), + sopts.crate_name.as_deref(), &sopts.debugging_opts.self_profile_events, ); match profiler { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index b63acdc114e..eecdc929ab6 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -371,6 +371,7 @@ crate fn run_core( error_format, edition, describe_lints, + crate_name, ..Options::default() }; @@ -384,7 +385,6 @@ crate fn run_core( file_loader: None, diagnostic_output: DiagnosticOutput::Default, stderr: None, - crate_name, lint_caps, register_lints: None, override_queries: Some(|_sess, providers, _external_providers| { diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index a615701f253..37fe13c32ce 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -74,6 +74,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { debugging_opts: config::DebuggingOptions { ..config::basic_debugging_options() }, edition: options.edition, target_triple: options.target.clone(), + crate_name: options.crate_name.clone(), ..config::Options::default() }; @@ -90,7 +91,6 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { file_loader: None, diagnostic_output: DiagnosticOutput::Default, stderr: None, - crate_name: options.crate_name.clone(), lint_caps, register_lints: None, override_queries: None, diff --git a/src/test/run-make-fulldeps/issue-19371/foo.rs b/src/test/run-make-fulldeps/issue-19371/foo.rs index 2636423c1a4..fdd7e8b24c5 100644 --- a/src/test/run-make-fulldeps/issue-19371/foo.rs +++ b/src/test/run-make-fulldeps/issue-19371/foo.rs @@ -56,7 +56,6 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) { file_loader: None, diagnostic_output: DiagnosticOutput::Default, stderr: None, - crate_name: None, lint_caps: Default::default(), register_lints: None, override_queries: None,