Skip to content

Commit 8a45938

Browse files
committed
Revert crate_types change, add new bin_crate field
1 parent 0709e53 commit 8a45938

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

src/librustdoc/config.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ pub(crate) struct Options {
6969
pub(crate) input: PathBuf,
7070
/// The name of the crate being documented.
7171
pub(crate) crate_name: Option<String>,
72-
/// The types of the crate being documented.
73-
pub(crate) crate_types: Vec<CrateType>,
72+
/// Whether or not this is a bin crate
73+
pub(crate) bin_crate: bool,
74+
/// Whether or not this is a proc-macro crate
75+
pub(crate) proc_macro_crate: bool,
7476
/// How to format errors and warnings.
7577
pub(crate) error_format: ErrorOutputType,
7678
/// Width of output buffer to truncate errors appropriately.
@@ -176,7 +178,8 @@ impl fmt::Debug for Options {
176178
f.debug_struct("Options")
177179
.field("input", &self.input)
178180
.field("crate_name", &self.crate_name)
179-
.field("crate_types", &self.crate_types)
181+
.field("bin_crate", &self.bin_crate)
182+
.field("proc_macro_crate", &self.proc_macro_crate)
180183
.field("error_format", &self.error_format)
181184
.field("libs", &self.libs)
182185
.field("externs", &FmtExterns(&self.externs))
@@ -667,6 +670,8 @@ impl Options {
667670
None => OutputFormat::default(),
668671
};
669672
let crate_name = matches.opt_str("crate-name");
673+
let bin_crate = crate_types.contains(&CrateType::Executable);
674+
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
670675
let playground_url = matches.opt_str("playground-url");
671676
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
672677
let module_sorting = if matches.opt_present("sort-modules-by-appearance") {
@@ -717,7 +722,8 @@ impl Options {
717722
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
718723
let options = Options {
719724
input,
720-
crate_types,
725+
bin_crate,
726+
proc_macro_crate,
721727
error_format,
722728
diagnostic_width,
723729
libs,

src/librustdoc/core.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub(crate) fn create_config(
203203
RustdocOptions {
204204
input,
205205
crate_name,
206-
crate_types,
206+
proc_macro_crate,
207207
error_format,
208208
diagnostic_width,
209209
libs,
@@ -247,7 +247,8 @@ pub(crate) fn create_config(
247247
Some((lint.name_lower(), lint::Allow))
248248
});
249249

250-
let crate_types = if crate_types.is_empty() { vec![CrateType::Rlib] } else { crate_types };
250+
let crate_types =
251+
if proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] };
251252
let test = scrape_examples_options.map(|opts| opts.scrape_tests).unwrap_or(false);
252253
// plays with error output here!
253254
let sessopts = config::Options {

src/librustdoc/doctest.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,8 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
6868

6969
debug!(?lint_opts);
7070

71-
let crate_types = if options.crate_types.is_empty() {
72-
vec![CrateType::Rlib]
73-
} else {
74-
options.crate_types.clone()
75-
};
71+
let crate_types =
72+
if options.proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] };
7673

7774
let sessopts = config::Options {
7875
maybe_sysroot: options.maybe_sysroot.clone(),

src/librustdoc/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ fn main_args(at_args: &[String]) -> MainResult {
774774
let output_format = options.output_format;
775775
let externs = options.externs.clone();
776776
let scrape_examples_options = options.scrape_examples_options.clone();
777-
let crate_types = options.crate_types.clone();
777+
let bin_crate = options.bin_crate;
778778

779779
let config = core::create_config(options);
780780

@@ -839,7 +839,7 @@ fn main_args(at_args: &[String]) -> MainResult {
839839
cache,
840840
tcx,
841841
options,
842-
crate_types,
842+
bin_crate,
843843
);
844844
}
845845

src/librustdoc/scrape_examples.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_serialize::{
2020
opaque::{FileEncoder, MemDecoder},
2121
Decodable, Encodable,
2222
};
23-
use rustc_session::{config::CrateType, getopts};
23+
use rustc_session::getopts;
2424
use rustc_span::{
2525
def_id::{CrateNum, DefPathHash, LOCAL_CRATE},
2626
edition::Edition,
@@ -123,7 +123,7 @@ struct FindCalls<'a, 'tcx> {
123123
cx: Context<'tcx>,
124124
target_crates: Vec<CrateNum>,
125125
calls: &'a mut AllCallLocations,
126-
crate_types: Vec<CrateType>,
126+
bin_crate: bool,
127127
}
128128

129129
impl<'a, 'tcx> Visitor<'tcx> for FindCalls<'a, 'tcx>
@@ -247,7 +247,7 @@ where
247247
let mk_call_data = || {
248248
let display_name = file_path.display().to_string();
249249
let edition = call_span.edition();
250-
let is_bin = self.crate_types.contains(&CrateType::Executable);
250+
let is_bin = self.bin_crate;
251251

252252
CallData { locations: Vec::new(), url, display_name, edition, is_bin }
253253
};
@@ -278,7 +278,7 @@ pub(crate) fn run(
278278
cache: formats::cache::Cache,
279279
tcx: TyCtxt<'_>,
280280
options: ScrapeExamplesOptions,
281-
crate_types: Vec<CrateType>,
281+
bin_crate: bool,
282282
) -> interface::Result<()> {
283283
let inner = move || -> Result<(), String> {
284284
// Generates source files for examples
@@ -306,7 +306,7 @@ pub(crate) fn run(
306306
// Run call-finder on all items
307307
let mut calls = FxHashMap::default();
308308
let mut finder =
309-
FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates, crate_types };
309+
FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates, bin_crate };
310310
tcx.hir().visit_all_item_likes_in_crate(&mut finder);
311311

312312
// The visitor might have found a type error, which we need to

0 commit comments

Comments
 (0)