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,
/// The name of the crate being documented.
pub(crate) crate_name: Option<String>,
/// The types of the crate being documented.
pub(crate) crate_types: Vec<CrateType>,
/// 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 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
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 @@ fn println_condition(condition: Condition) {
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 @@ fn println_condition(condition: Condition) {
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,

View File

@ -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 {

View File

@ -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(),

View File

@ -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,
);
}

View File

@ -20,7 +20,7 @@
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<CrateNum>,
calls: &'a mut AllCallLocations,
crate_types: Vec<CrateType>,
bin_crate: bool,
}
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 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<CrateType>,
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