From 8a459384ad02d120f1d1cc81166f95262c1d4fac Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Tue, 6 Dec 2022 12:56:02 -0800 Subject: [PATCH] Revert crate_types change, add new bin_crate field --- src/librustdoc/config.rs | 14 ++++++++++---- src/librustdoc/core.rs | 5 +++-- src/librustdoc/doctest.rs | 7 ++----- src/librustdoc/lib.rs | 4 ++-- src/librustdoc/scrape_examples.rs | 10 +++++----- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 41af4f9561b..56b40d8c66b 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -69,8 +69,10 @@ pub(crate) struct Options { pub(crate) input: PathBuf, /// The name of the crate being documented. pub(crate) crate_name: Option, - /// The types of the crate being documented. - pub(crate) crate_types: Vec, + /// Whether or not this is a bin crate + pub(crate) bin_crate: bool, + /// Whether or not this is a proc-macro crate + pub(crate) proc_macro_crate: bool, /// How to format errors and warnings. pub(crate) error_format: ErrorOutputType, /// Width of output buffer to truncate errors appropriately. @@ -176,7 +178,8 @@ impl fmt::Debug for Options { f.debug_struct("Options") .field("input", &self.input) .field("crate_name", &self.crate_name) - .field("crate_types", &self.crate_types) + .field("bin_crate", &self.bin_crate) + .field("proc_macro_crate", &self.proc_macro_crate) .field("error_format", &self.error_format) .field("libs", &self.libs) .field("externs", &FmtExterns(&self.externs)) @@ -667,6 +670,8 @@ impl Options { None => OutputFormat::default(), }; let crate_name = matches.opt_str("crate-name"); + let bin_crate = crate_types.contains(&CrateType::Executable); + let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro); let playground_url = matches.opt_str("playground-url"); let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from); let module_sorting = if matches.opt_present("sort-modules-by-appearance") { @@ -717,7 +722,8 @@ impl Options { rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref()); let options = Options { input, - crate_types, + bin_crate, + proc_macro_crate, error_format, diagnostic_width, libs, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 58954ecc73f..da0df596c41 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -203,7 +203,7 @@ pub(crate) fn create_config( RustdocOptions { input, crate_name, - crate_types, + proc_macro_crate, error_format, diagnostic_width, libs, @@ -247,7 +247,8 @@ pub(crate) fn create_config( Some((lint.name_lower(), lint::Allow)) }); - let crate_types = if crate_types.is_empty() { vec![CrateType::Rlib] } else { crate_types }; + let crate_types = + if proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] }; let test = scrape_examples_options.map(|opts| opts.scrape_tests).unwrap_or(false); // plays with error output here! let sessopts = config::Options { diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 30bc2f90d2c..81d9c46447a 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -68,11 +68,8 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> { debug!(?lint_opts); - let crate_types = if options.crate_types.is_empty() { - vec![CrateType::Rlib] - } else { - options.crate_types.clone() - }; + let crate_types = + if options.proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] }; let sessopts = config::Options { maybe_sysroot: options.maybe_sysroot.clone(), diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index e27af61051c..3f84eb0b4c6 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -774,7 +774,7 @@ fn main_args(at_args: &[String]) -> MainResult { let output_format = options.output_format; let externs = options.externs.clone(); let scrape_examples_options = options.scrape_examples_options.clone(); - let crate_types = options.crate_types.clone(); + let bin_crate = options.bin_crate; let config = core::create_config(options); @@ -839,7 +839,7 @@ fn main_args(at_args: &[String]) -> MainResult { cache, tcx, options, - crate_types, + bin_crate, ); } diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs index 9adccda0e72..f2ee99cd9d4 100644 --- a/src/librustdoc/scrape_examples.rs +++ b/src/librustdoc/scrape_examples.rs @@ -20,7 +20,7 @@ use rustc_serialize::{ opaque::{FileEncoder, MemDecoder}, Decodable, Encodable, }; -use rustc_session::{config::CrateType, getopts}; +use rustc_session::getopts; use rustc_span::{ def_id::{CrateNum, DefPathHash, LOCAL_CRATE}, edition::Edition, @@ -123,7 +123,7 @@ struct FindCalls<'a, 'tcx> { cx: Context<'tcx>, target_crates: Vec, calls: &'a mut AllCallLocations, - crate_types: Vec, + bin_crate: bool, } impl<'a, 'tcx> Visitor<'tcx> for FindCalls<'a, 'tcx> @@ -247,7 +247,7 @@ where let mk_call_data = || { let display_name = file_path.display().to_string(); let edition = call_span.edition(); - let is_bin = self.crate_types.contains(&CrateType::Executable); + let is_bin = self.bin_crate; CallData { locations: Vec::new(), url, display_name, edition, is_bin } }; @@ -278,7 +278,7 @@ pub(crate) fn run( cache: formats::cache::Cache, tcx: TyCtxt<'_>, options: ScrapeExamplesOptions, - crate_types: Vec, + bin_crate: bool, ) -> interface::Result<()> { let inner = move || -> Result<(), String> { // Generates source files for examples @@ -306,7 +306,7 @@ pub(crate) fn run( // Run call-finder on all items let mut calls = FxHashMap::default(); let mut finder = - FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates, crate_types }; + FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates, bin_crate }; tcx.hir().visit_all_item_likes_in_crate(&mut finder); // The visitor might have found a type error, which we need to