Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unknown-crate when using -Z self-profile with rustdoc #79586

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub struct Compiler {
pub(crate) input_path: Option<PathBuf>,
pub(crate) output_dir: Option<PathBuf>,
pub(crate) output_file: Option<PathBuf>,
pub(crate) crate_name: Option<String>,
pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>,
pub(crate) override_queries:
Option<fn(&Session, &mut ty::query::Providers, &mut ty::query::Providers)>,
Expand Down Expand Up @@ -140,7 +139,6 @@ pub struct Config {
/// Set to capture stderr output during compiler execution
pub stderr: Option<Arc<Mutex<Vec<u8>>>>,

pub crate_name: Option<String>,
pub lint_caps: FxHashMap<lint::LintId, lint::Level>,

/// This is a callback from the driver that is called when we're registering lints;
Expand Down Expand Up @@ -185,7 +183,6 @@ pub fn create_compiler_and_run<R>(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,
};
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,11 @@ impl<'tcx> Queries<'tcx> {

pub fn crate_name(&self) -> Result<&Query<String>> {
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I am a bit worried -- is this a breaking change? It sounds like it would be, since we presumably weren't validating previously?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #79586 (comment) - this is the same behavior as before, just easier to understand. Previously, the crate name would never be Some so this would always run.

})
})
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ crate fn run_core(
error_format,
edition,
describe_lints,
crate_name,
..Options::default()
};

Expand All @@ -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| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};

Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/test/run-make-fulldeps/issue-19371/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down