Revert crate_types change, add new bin_crate field

This commit is contained in:
Will Crichton 2022-12-06 12:56:02 -08:00
parent 0709e534df
commit 8a459384ad
5 changed files with 22 additions and 18 deletions

View File

@ -69,8 +69,10 @@ pub(crate) struct Options {
pub(crate) input: PathBuf, pub(crate) input: PathBuf,
/// The name of the crate being documented. /// The name of the crate being documented.
pub(crate) crate_name: Option<String>, pub(crate) crate_name: Option<String>,
/// The types of the crate being documented. /// Whether or not this is a bin crate
pub(crate) crate_types: Vec<CrateType>, 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. /// How to format errors and warnings.
pub(crate) error_format: ErrorOutputType, pub(crate) error_format: ErrorOutputType,
/// Width of output buffer to truncate errors appropriately. /// Width of output buffer to truncate errors appropriately.
@ -176,7 +178,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Options") f.debug_struct("Options")
.field("input", &self.input) .field("input", &self.input)
.field("crate_name", &self.crate_name) .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("error_format", &self.error_format)
.field("libs", &self.libs) .field("libs", &self.libs)
.field("externs", &FmtExterns(&self.externs)) .field("externs", &FmtExterns(&self.externs))
@ -667,6 +670,8 @@ fn println_condition(condition: Condition) {
None => OutputFormat::default(), None => OutputFormat::default(),
}; };
let crate_name = matches.opt_str("crate-name"); 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 playground_url = matches.opt_str("playground-url");
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from); let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
let module_sorting = if matches.opt_present("sort-modules-by-appearance") { let module_sorting = if matches.opt_present("sort-modules-by-appearance") {
@ -717,7 +722,8 @@ fn println_condition(condition: Condition) {
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref()); rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
let options = Options { let options = Options {
input, input,
crate_types, bin_crate,
proc_macro_crate,
error_format, error_format,
diagnostic_width, diagnostic_width,
libs, libs,

View File

@ -203,7 +203,7 @@ pub(crate) fn create_config(
RustdocOptions { RustdocOptions {
input, input,
crate_name, crate_name,
crate_types, proc_macro_crate,
error_format, error_format,
diagnostic_width, diagnostic_width,
libs, libs,
@ -247,7 +247,8 @@ pub(crate) fn create_config(
Some((lint.name_lower(), lint::Allow)) 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); let test = scrape_examples_options.map(|opts| opts.scrape_tests).unwrap_or(false);
// plays with error output here! // plays with error output here!
let sessopts = config::Options { let sessopts = config::Options {

View File

@ -68,11 +68,8 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
debug!(?lint_opts); debug!(?lint_opts);
let crate_types = if options.crate_types.is_empty() { let crate_types =
vec![CrateType::Rlib] if options.proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] };
} else {
options.crate_types.clone()
};
let sessopts = config::Options { let sessopts = config::Options {
maybe_sysroot: options.maybe_sysroot.clone(), maybe_sysroot: options.maybe_sysroot.clone(),

View File

@ -774,7 +774,7 @@ fn main_args(at_args: &[String]) -> MainResult {
let output_format = options.output_format; let output_format = options.output_format;
let externs = options.externs.clone(); let externs = options.externs.clone();
let scrape_examples_options = options.scrape_examples_options.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); let config = core::create_config(options);
@ -839,7 +839,7 @@ fn main_args(at_args: &[String]) -> MainResult {
cache, cache,
tcx, tcx,
options, options,
crate_types, bin_crate,
); );
} }

View File

@ -20,7 +20,7 @@
opaque::{FileEncoder, MemDecoder}, opaque::{FileEncoder, MemDecoder},
Decodable, Encodable, Decodable, Encodable,
}; };
use rustc_session::{config::CrateType, getopts}; use rustc_session::getopts;
use rustc_span::{ use rustc_span::{
def_id::{CrateNum, DefPathHash, LOCAL_CRATE}, def_id::{CrateNum, DefPathHash, LOCAL_CRATE},
edition::Edition, edition::Edition,
@ -123,7 +123,7 @@ struct FindCalls<'a, 'tcx> {
cx: Context<'tcx>, cx: Context<'tcx>,
target_crates: Vec<CrateNum>, target_crates: Vec<CrateNum>,
calls: &'a mut AllCallLocations, calls: &'a mut AllCallLocations,
crate_types: Vec<CrateType>, bin_crate: bool,
} }
impl<'a, 'tcx> Visitor<'tcx> for FindCalls<'a, 'tcx> impl<'a, 'tcx> Visitor<'tcx> for FindCalls<'a, 'tcx>
@ -247,7 +247,7 @@ fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
let mk_call_data = || { let mk_call_data = || {
let display_name = file_path.display().to_string(); let display_name = file_path.display().to_string();
let edition = call_span.edition(); 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 } CallData { locations: Vec::new(), url, display_name, edition, is_bin }
}; };
@ -278,7 +278,7 @@ pub(crate) fn run(
cache: formats::cache::Cache, cache: formats::cache::Cache,
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
options: ScrapeExamplesOptions, options: ScrapeExamplesOptions,
crate_types: Vec<CrateType>, bin_crate: bool,
) -> interface::Result<()> { ) -> interface::Result<()> {
let inner = move || -> Result<(), String> { let inner = move || -> Result<(), String> {
// Generates source files for examples // Generates source files for examples
@ -306,7 +306,7 @@ pub(crate) fn run(
// Run call-finder on all items // Run call-finder on all items
let mut calls = FxHashMap::default(); let mut calls = FxHashMap::default();
let mut finder = 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); tcx.hir().visit_all_item_likes_in_crate(&mut finder);
// The visitor might have found a type error, which we need to // The visitor might have found a type error, which we need to