Skip to content

Commit 2203527

Browse files
committed
Auto merge of rust-lang#79586 - jyn514:crate-name, r=davidtwco
Fix `unknown-crate` when using -Z 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. Unblocks rust-lang/rustc-perf#797.
2 parents d015f0d + 878cfb5 commit 2203527

File tree

7 files changed

+8
-16
lines changed

7 files changed

+8
-16
lines changed

compiler/rustc_driver/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ fn run_compiler(
223223
file_loader: None,
224224
diagnostic_output,
225225
stderr: None,
226-
crate_name: None,
227226
lint_caps: Default::default(),
228227
register_lints: None,
229228
override_queries: None,
@@ -307,7 +306,6 @@ fn run_compiler(
307306
file_loader,
308307
diagnostic_output,
309308
stderr: None,
310-
crate_name: None,
311309
lint_caps: Default::default(),
312310
register_lints: None,
313311
override_queries: None,

compiler/rustc_interface/src/interface.rs

-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub struct Compiler {
3434
pub(crate) input_path: Option<PathBuf>,
3535
pub(crate) output_dir: Option<PathBuf>,
3636
pub(crate) output_file: Option<PathBuf>,
37-
pub(crate) crate_name: Option<String>,
3837
pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>,
3938
pub(crate) override_queries:
4039
Option<fn(&Session, &mut ty::query::Providers, &mut ty::query::Providers)>,
@@ -140,7 +139,6 @@ pub struct Config {
140139
/// Set to capture stderr output during compiler execution
141140
pub stderr: Option<Arc<Mutex<Vec<u8>>>>,
142141

143-
pub crate_name: Option<String>,
144142
pub lint_caps: FxHashMap<lint::LintId, lint::Level>,
145143

146144
/// 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<R>(config: Config, f: impl FnOnce(&Compiler) -> R
185183
input_path: config.input_path,
186184
output_dir: config.output_dir,
187185
output_file: config.output_file,
188-
crate_name: config.crate_name,
189186
register_lints: config.register_lints,
190187
override_queries: config.override_queries,
191188
};

compiler/rustc_interface/src/queries.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,11 @@ impl<'tcx> Queries<'tcx> {
156156

157157
pub fn crate_name(&self) -> Result<&Query<String>> {
158158
self.crate_name.compute(|| {
159-
Ok(match self.compiler.crate_name {
160-
Some(ref crate_name) => crate_name.clone(),
161-
None => {
162-
let parse_result = self.parse()?;
163-
let krate = parse_result.peek();
164-
find_crate_name(self.session(), &krate.attrs, &self.compiler.input)
165-
}
159+
Ok({
160+
let parse_result = self.parse()?;
161+
let krate = parse_result.peek();
162+
// parse `#[crate_name]` even if `--crate-name` was passed, to make sure it matches.
163+
find_crate_name(self.session(), &krate.attrs, &self.compiler.input)
166164
})
167165
})
168166
}

compiler/rustc_session/src/session.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ pub fn build_session(
13381338

13391339
let profiler = SelfProfiler::new(
13401340
directory,
1341-
sopts.crate_name.as_ref().map(|s| &s[..]),
1341+
sopts.crate_name.as_deref(),
13421342
&sopts.debugging_opts.self_profile_events,
13431343
);
13441344
match profiler {

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ crate fn run_core(
371371
error_format,
372372
edition,
373373
describe_lints,
374+
crate_name,
374375
..Options::default()
375376
};
376377

@@ -384,7 +385,6 @@ crate fn run_core(
384385
file_loader: None,
385386
diagnostic_output: DiagnosticOutput::Default,
386387
stderr: None,
387-
crate_name,
388388
lint_caps,
389389
register_lints: None,
390390
override_queries: Some(|_sess, providers, _external_providers| {

src/librustdoc/doctest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
7474
debugging_opts: config::DebuggingOptions { ..config::basic_debugging_options() },
7575
edition: options.edition,
7676
target_triple: options.target.clone(),
77+
crate_name: options.crate_name.clone(),
7778
..config::Options::default()
7879
};
7980

@@ -90,7 +91,6 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
9091
file_loader: None,
9192
diagnostic_output: DiagnosticOutput::Default,
9293
stderr: None,
93-
crate_name: options.crate_name.clone(),
9494
lint_caps,
9595
register_lints: None,
9696
override_queries: None,

src/test/run-make-fulldeps/issue-19371/foo.rs

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
5656
file_loader: None,
5757
diagnostic_output: DiagnosticOutput::Default,
5858
stderr: None,
59-
crate_name: None,
6059
lint_caps: Default::default(),
6160
register_lints: None,
6261
override_queries: None,

0 commit comments

Comments
 (0)