Skip to content

Commit 940a97a

Browse files
committed
Auto merge of rust-lang#91900 - pitaj:fix-91714, r=jyn514
rustdoc: make `--passes` and `--no-defaults` have no effect Fixes rust-lang#91714 One potential issue is that currently there is no stable way to achieve `--document-hidden-items`. This affects test `issue-15347`. I also had to modify the tests `issue-42875` and `no-compiler-export`. Regardless of combinations of `--document-hidden-items` and `--document-private-items`, I was unable to get these to pass without the modifications. I left behind a comment noting the change.
2 parents ed7a206 + 02b94b7 commit 940a97a

13 files changed

+99
-157
lines changed

Diff for: src/librustdoc/config.rs

+21-37
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::html::markdown::IdMap;
2424
use crate::html::render::StylePath;
2525
use crate::html::static_files;
2626
use crate::opts;
27-
use crate::passes::{self, Condition, DefaultPassOption};
27+
use crate::passes::{self, Condition};
2828
use crate::scrape_examples::{AllCallLocations, ScrapeExamplesOptions};
2929
use crate::theme;
3030

@@ -128,14 +128,6 @@ crate struct Options {
128128
crate test_builder: Option<PathBuf>,
129129

130130
// Options that affect the documentation process
131-
/// The selected default set of passes to use.
132-
///
133-
/// Be aware: This option can come both from the CLI and from crate attributes!
134-
crate default_passes: DefaultPassOption,
135-
/// Any passes manually selected by the user.
136-
///
137-
/// Be aware: This option can come both from the CLI and from crate attributes!
138-
crate manual_passes: Vec<String>,
139131
/// Whether to run the `calculate-doc-coverage` pass, which counts the number of public items
140132
/// with and without documentation.
141133
crate show_coverage: bool,
@@ -192,8 +184,6 @@ impl fmt::Debug for Options {
192184
.field("test_args", &self.test_args)
193185
.field("test_run_directory", &self.test_run_directory)
194186
.field("persist_doctests", &self.persist_doctests)
195-
.field("default_passes", &self.default_passes)
196-
.field("manual_passes", &self.manual_passes)
197187
.field("show_coverage", &self.show_coverage)
198188
.field("crate_version", &self.crate_version)
199189
.field("render_options", &self.render_options)
@@ -605,15 +595,6 @@ impl Options {
605595

606596
let show_coverage = matches.opt_present("show-coverage");
607597

608-
let default_passes = if matches.opt_present("no-defaults") {
609-
passes::DefaultPassOption::None
610-
} else if show_coverage {
611-
passes::DefaultPassOption::Coverage
612-
} else {
613-
passes::DefaultPassOption::Default
614-
};
615-
let manual_passes = matches.opt_strs("passes");
616-
617598
let crate_types = match parse_crate_types_from_list(matches.opt_strs("crate-type")) {
618599
Ok(types) => types,
619600
Err(e) => {
@@ -710,8 +691,6 @@ impl Options {
710691
lint_cap,
711692
should_test,
712693
test_args,
713-
default_passes,
714-
manual_passes,
715694
show_coverage,
716695
crate_version,
717696
test_run_directory,
@@ -769,33 +748,38 @@ impl Options {
769748

770749
/// Prints deprecation warnings for deprecated options
771750
fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Handler) {
772-
let deprecated_flags = ["input-format", "no-defaults", "passes"];
751+
let deprecated_flags = [];
752+
753+
for &flag in deprecated_flags.iter() {
754+
if matches.opt_present(flag) {
755+
diag.struct_warn(&format!("the `{}` flag is deprecated", flag))
756+
.note(
757+
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
758+
for more information",
759+
)
760+
.emit();
761+
}
762+
}
763+
764+
let removed_flags = ["plugins", "plugin-path", "no-defaults", "passes", "input-format"];
773765

774-
for flag in deprecated_flags.iter() {
766+
for &flag in removed_flags.iter() {
775767
if matches.opt_present(flag) {
776-
let mut err = diag.struct_warn(&format!("the `{}` flag is deprecated", flag));
768+
let mut err = diag.struct_warn(&format!("the `{}` flag no longer functions", flag));
777769
err.note(
778770
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
779-
for more information",
771+
for more information",
780772
);
781773

782-
if *flag == "no-defaults" {
774+
if flag == "no-defaults" || flag == "passes" {
783775
err.help("you may want to use --document-private-items");
776+
} else if flag == "plugins" || flag == "plugin-path" {
777+
err.warn("see CVE-2018-1000622");
784778
}
785779

786780
err.emit();
787781
}
788782
}
789-
790-
let removed_flags = ["plugins", "plugin-path"];
791-
792-
for &flag in removed_flags.iter() {
793-
if matches.opt_present(flag) {
794-
diag.struct_warn(&format!("the '{}' flag no longer functions", flag))
795-
.warn("see CVE-2018-1000622")
796-
.emit();
797-
}
798-
}
799783
}
800784

801785
/// Extracts `--extern-html-root-url` arguments from `matches` and returns a map of crate names to

Diff for: src/librustdoc/core.rs

+12-42
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::clean::inline::build_external_trait;
3535
use crate::clean::{self, ItemId, TraitWithExtraInfo};
3636
use crate::config::{Options as RustdocOptions, OutputFormat, RenderOptions};
3737
use crate::formats::cache::Cache;
38-
use crate::passes::{self, Condition::*, ConditionalPass};
38+
use crate::passes::{self, Condition::*};
3939

4040
crate use rustc_session::config::{DebuggingOptions, Input, Options};
4141

@@ -327,8 +327,7 @@ crate fn create_resolver<'a>(
327327
crate fn run_global_ctxt(
328328
tcx: TyCtxt<'_>,
329329
resolver: Rc<RefCell<interface::BoxedResolver>>,
330-
mut default_passes: passes::DefaultPassOption,
331-
manual_passes: Vec<String>,
330+
show_coverage: bool,
332331
render_options: RenderOptions,
333332
output_format: OutputFormat,
334333
) -> (clean::Crate, RenderOptions, Cache) {
@@ -420,66 +419,38 @@ crate fn run_global_ctxt(
420419
diag.struct_span_warn(sp, &format!("the `#![doc({})]` attribute is deprecated", name));
421420
msg.note(
422421
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
423-
for more information",
422+
for more information",
424423
);
425424

426425
if name == "no_default_passes" {
427-
msg.help("you may want to use `#![doc(document_private_items)]`");
426+
msg.help("`#![doc(no_default_passes)]` no longer functions; you may want to use `#![doc(document_private_items)]`");
427+
} else if name.starts_with("passes") {
428+
msg.help("`#![doc(passes = \"...\")]` no longer functions; you may want to use `#![doc(document_private_items)]`");
428429
} else if name.starts_with("plugins") {
429430
msg.warn("`#![doc(plugins = \"...\")]` no longer functions; see CVE-2018-1000622 <https://nvd.nist.gov/vuln/detail/CVE-2018-1000622>");
430431
}
431432

432433
msg.emit();
433434
}
434435

435-
let parse_pass = |name: &str, sp: Option<Span>| {
436-
if let Some(pass) = passes::find_pass(name) {
437-
Some(ConditionalPass::always(pass))
438-
} else {
439-
let msg = &format!("ignoring unknown pass `{}`", name);
440-
let mut warning = if let Some(sp) = sp {
441-
tcx.sess.struct_span_warn(sp, msg)
442-
} else {
443-
tcx.sess.struct_warn(msg)
444-
};
445-
if name == "collapse-docs" {
446-
warning.note("the `collapse-docs` pass was removed in #80261 <https://github.com/rust-lang/rust/pull/80261>");
447-
}
448-
warning.emit();
449-
None
450-
}
451-
};
452-
453-
let mut manual_passes: Vec<_> =
454-
manual_passes.into_iter().flat_map(|name| parse_pass(&name, None)).collect();
455-
456436
// Process all of the crate attributes, extracting plugin metadata along
457437
// with the passes which we are supposed to run.
458438
for attr in krate.module.attrs.lists(sym::doc) {
459439
let diag = ctxt.sess().diagnostic();
460440

461441
let name = attr.name_or_empty();
462-
if attr.is_word() {
463-
if name == sym::no_default_passes {
464-
report_deprecated_attr("no_default_passes", diag, attr.span());
465-
if default_passes == passes::DefaultPassOption::Default {
466-
default_passes = passes::DefaultPassOption::None;
467-
}
468-
}
469-
} else if let Some(value) = attr.value_str() {
442+
// `plugins = "..."`, `no_default_passes`, and `passes = "..."` have no effect
443+
if attr.is_word() && name == sym::no_default_passes {
444+
report_deprecated_attr("no_default_passes", diag, attr.span());
445+
} else if attr.value_str().is_some() {
470446
match name {
471447
sym::passes => {
472448
report_deprecated_attr("passes = \"...\"", diag, attr.span());
473449
}
474450
sym::plugins => {
475451
report_deprecated_attr("plugins = \"...\"", diag, attr.span());
476-
continue;
477452
}
478-
_ => continue,
479-
};
480-
for name in value.as_str().split_whitespace() {
481-
let span = attr.name_value_literal_span().unwrap_or_else(|| attr.span());
482-
manual_passes.extend(parse_pass(name, Some(span)));
453+
_ => (),
483454
}
484455
}
485456

@@ -488,10 +459,9 @@ crate fn run_global_ctxt(
488459
}
489460
}
490461

491-
let passes = passes::defaults(default_passes).iter().copied().chain(manual_passes);
492462
info!("Executing passes");
493463

494-
for p in passes {
464+
for p in passes::defaults(show_coverage) {
495465
let run = match p.condition {
496466
Always => true,
497467
WhenDocumentPrivate => ctxt.render_options.document_private,

Diff for: src/librustdoc/lib.rs

+46-19
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,6 @@ fn opts() -> Vec<RustcOptGroup> {
274274
stable("h", |o| o.optflagmulti("h", "help", "show this help message")),
275275
stable("V", |o| o.optflagmulti("V", "version", "print rustdoc's version")),
276276
stable("v", |o| o.optflagmulti("v", "verbose", "use verbose output")),
277-
stable("r", |o| {
278-
o.optopt("r", "input-format", "the input type of the specified file", "[rust]")
279-
}),
280277
stable("w", |o| o.optopt("w", "output-format", "the output type to write", "[html]")),
281278
stable("output", |o| {
282279
o.optopt(
@@ -313,21 +310,9 @@ fn opts() -> Vec<RustcOptGroup> {
313310
"give precedence to `--extern-html-root-url`, not `html_root_url`",
314311
)
315312
}),
316-
stable("plugin-path", |o| o.optmulti("", "plugin-path", "removed", "DIR")),
317313
stable("C", |o| {
318314
o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]")
319315
}),
320-
stable("passes", |o| {
321-
o.optmulti(
322-
"",
323-
"passes",
324-
"list of passes to also run, you might want to pass it multiple times; a value of \
325-
`list` will print available passes",
326-
"PASSES",
327-
)
328-
}),
329-
stable("plugins", |o| o.optmulti("", "plugins", "removed", "PLUGINS")),
330-
stable("no-default", |o| o.optflagmulti("", "no-defaults", "don't run the default passes")),
331316
stable("document-private-items", |o| {
332317
o.optflagmulti("", "document-private-items", "document private items")
333318
}),
@@ -653,6 +638,51 @@ fn opts() -> Vec<RustcOptGroup> {
653638
"path to function call information (for displaying examples in the documentation)",
654639
)
655640
}),
641+
// deprecated / removed options
642+
stable("plugin-path", |o| {
643+
o.optmulti(
644+
"",
645+
"plugin-path",
646+
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
647+
for more information",
648+
"DIR",
649+
)
650+
}),
651+
stable("passes", |o| {
652+
o.optmulti(
653+
"",
654+
"passes",
655+
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
656+
for more information",
657+
"PASSES",
658+
)
659+
}),
660+
stable("plugins", |o| {
661+
o.optmulti(
662+
"",
663+
"plugins",
664+
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
665+
for more information",
666+
"PLUGINS",
667+
)
668+
}),
669+
stable("no-default", |o| {
670+
o.optflagmulti(
671+
"",
672+
"no-defaults",
673+
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
674+
for more information",
675+
)
676+
}),
677+
stable("r", |o| {
678+
o.optopt(
679+
"r",
680+
"input-format",
681+
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
682+
for more information",
683+
"[rust]",
684+
)
685+
}),
656686
]
657687
}
658688

@@ -761,11 +791,9 @@ fn main_options(options: config::Options) -> MainResult {
761791
// plug/cleaning passes.
762792
let crate_version = options.crate_version.clone();
763793

764-
let default_passes = options.default_passes;
765794
let output_format = options.output_format;
766795
// FIXME: fix this clone (especially render_options)
767796
let externs = options.externs.clone();
768-
let manual_passes = options.manual_passes.clone();
769797
let render_options = options.render_options.clone();
770798
let scrape_examples_options = options.scrape_examples_options.clone();
771799
let config = core::create_config(options);
@@ -796,8 +824,7 @@ fn main_options(options: config::Options) -> MainResult {
796824
core::run_global_ctxt(
797825
tcx,
798826
resolver,
799-
default_passes,
800-
manual_passes,
827+
show_coverage,
801828
render_options,
802829
output_format,
803830
)

Diff for: src/librustdoc/passes/mod.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -125,27 +125,9 @@ impl ConditionalPass {
125125
}
126126
}
127127

128-
/// A shorthand way to refer to which set of passes to use, based on the presence of
129-
/// `--no-defaults` and `--show-coverage`.
130-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
131-
crate enum DefaultPassOption {
132-
Default,
133-
Coverage,
134-
None,
135-
}
136-
137128
/// Returns the given default set of passes.
138-
crate fn defaults(default_set: DefaultPassOption) -> &'static [ConditionalPass] {
139-
match default_set {
140-
DefaultPassOption::Default => DEFAULT_PASSES,
141-
DefaultPassOption::Coverage => COVERAGE_PASSES,
142-
DefaultPassOption::None => &[],
143-
}
144-
}
145-
146-
/// If the given name matches a known pass, returns its information.
147-
crate fn find_pass(pass_name: &str) -> Option<Pass> {
148-
PASSES.iter().find(|p| p.name == pass_name).copied()
129+
crate fn defaults(show_coverage: bool) -> &'static [ConditionalPass] {
130+
if show_coverage { COVERAGE_PASSES } else { DEFAULT_PASSES }
149131
}
150132

151133
/// Returns a span encompassing all the given attributes.

Diff for: src/test/rustdoc-ui/deprecated-attrs.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// check-pass
22
// compile-flags: --passes unknown-pass
3-
// error-pattern: ignoring unknown pass `unknown-pass`
3+
// error-pattern: the `passes` flag no longer functions
44

55
#![doc(no_default_passes)]
66
//~^ WARNING attribute is deprecated
77
//~| NOTE see issue #44136
8-
//~| HELP use `#![doc(document_private_items)]`
8+
//~| HELP no longer functions; you may want to use `#![doc(document_private_items)]`
99
#![doc(passes = "collapse-docs unindent-comments")]
1010
//~^ WARNING attribute is deprecated
1111
//~| NOTE see issue #44136
12-
//~| WARNING ignoring unknown pass
13-
//~| NOTE `collapse-docs` pass was removed
12+
//~| HELP no longer functions; you may want to use `#![doc(document_private_items)]`
1413
#![doc(plugins = "xxx")]
1514
//~^ WARNING attribute is deprecated
1615
//~| NOTE see issue #44136

0 commit comments

Comments
 (0)