Skip to content

Commit

Permalink
Revert crate_types change, add new bin_crate field
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Dec 7, 2022
1 parent 0709e53 commit 8a45938
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
14 changes: 10 additions & 4 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub(crate) fn create_config(
RustdocOptions {
input,
crate_name,
crate_types,
proc_macro_crate,
error_format,
diagnostic_width,
libs,
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -839,7 +839,7 @@ fn main_args(at_args: &[String]) -> MainResult {
cache,
tcx,
options,
crate_types,
bin_crate,
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/scrape_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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 }
};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8a45938

Please sign in to comment.