Skip to content

Commit f3218df

Browse files
authored
Rollup merge of rust-lang#82651 - jyn514:rustdoc-warnings, r=GuillaumeGomez
Cleanup rustdoc warnings ## Clean up error reporting for deprecated passes Using `error!` here goes all the way back to the original commit, rust-lang#8540. I don't see any reason to use logging; rustdoc should use diagnostics wherever possible. See rust-lang#81932 (comment) for further context. - Use spans for deprecated attributes - Use a proper diagnostic for unknown passes, instead of error logging - Add tests for unknown passes - Improve some wording in diagnostics ## Report that `doc(plugins)` doesn't work using diagnostics instead of `eprintln!` This also adds a test for the output. This was added in rust-lang#52194. I don't see any particular reason not to use diagnostics here, I think it was just missed in rust-lang#50541.
2 parents 817e58f + d5c300b commit f3218df

File tree

5 files changed

+91
-41
lines changed

5 files changed

+91
-41
lines changed

compiler/rustc_passes/src/check_attr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ impl CheckAttrVisitor<'tcx> {
576576
sym::masked,
577577
sym::no_default_passes, // deprecated
578578
sym::no_inline,
579-
sym::passes, // deprecated
579+
sym::passes, // deprecated
580+
sym::plugins, // removed, but rustdoc warns about it itself
580581
sym::primitive,
581582
sym::spotlight,
582583
sym::test,

src/librustdoc/config.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,8 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Han
658658
{
659659
continue;
660660
}
661-
let mut err =
662-
diag.struct_warn(&format!("the '{}' flag is considered deprecated", flag));
663-
err.warn(
661+
let mut err = diag.struct_warn(&format!("the `{}` flag is deprecated", flag));
662+
err.note(
664663
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
665664
for more information",
666665
);

src/librustdoc/core.rs

+36-27
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_session::DiagnosticOutput;
2222
use rustc_session::Session;
2323
use rustc_span::source_map;
2424
use rustc_span::symbol::sym;
25-
use rustc_span::DUMMY_SP;
25+
use rustc_span::{Span, DUMMY_SP};
2626

2727
use std::cell::RefCell;
2828
use std::collections::hash_map::Entry;
@@ -389,7 +389,7 @@ crate fn run_global_ctxt(
389389
tcx: TyCtxt<'_>,
390390
resolver: Rc<RefCell<interface::BoxedResolver>>,
391391
mut default_passes: passes::DefaultPassOption,
392-
mut manual_passes: Vec<String>,
392+
manual_passes: Vec<String>,
393393
render_options: RenderOptions,
394394
output_format: OutputFormat,
395395
) -> (clean::Crate, RenderOptions, Cache) {
@@ -490,21 +490,44 @@ crate fn run_global_ctxt(
490490
}
491491
}
492492

493-
fn report_deprecated_attr(name: &str, diag: &rustc_errors::Handler) {
494-
let mut msg = diag
495-
.struct_warn(&format!("the `#![doc({})]` attribute is considered deprecated", name));
496-
msg.warn(
493+
fn report_deprecated_attr(name: &str, diag: &rustc_errors::Handler, sp: Span) {
494+
let mut msg =
495+
diag.struct_span_warn(sp, &format!("the `#![doc({})]` attribute is deprecated", name));
496+
msg.note(
497497
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
498498
for more information",
499499
);
500500

501501
if name == "no_default_passes" {
502502
msg.help("you may want to use `#![doc(document_private_items)]`");
503+
} else if name.starts_with("plugins") {
504+
msg.warn("`#![doc(plugins = \"...\")]` no longer functions; see CVE-2018-1000622 <https://nvd.nist.gov/vuln/detail/CVE-2018-1000622>");
503505
}
504506

505507
msg.emit();
506508
}
507509

510+
let parse_pass = |name: &str, sp: Option<Span>| {
511+
if let Some(pass) = passes::find_pass(name) {
512+
Some(ConditionalPass::always(pass))
513+
} else {
514+
let msg = &format!("ignoring unknown pass `{}`", name);
515+
let mut warning = if let Some(sp) = sp {
516+
tcx.sess.struct_span_warn(sp, msg)
517+
} else {
518+
tcx.sess.struct_warn(msg)
519+
};
520+
if name == "collapse-docs" {
521+
warning.note("the `collapse-docs` pass was removed in #80261 <https://github.com/rust-lang/rust/pull/80261>");
522+
}
523+
warning.emit();
524+
None
525+
}
526+
};
527+
528+
let mut manual_passes: Vec<_> =
529+
manual_passes.into_iter().flat_map(|name| parse_pass(&name, None)).collect();
530+
508531
// Process all of the crate attributes, extracting plugin metadata along
509532
// with the passes which we are supposed to run.
510533
for attr in krate.module.as_ref().unwrap().attrs.lists(sym::doc) {
@@ -513,29 +536,25 @@ crate fn run_global_ctxt(
513536
let name = attr.name_or_empty();
514537
if attr.is_word() {
515538
if name == sym::no_default_passes {
516-
report_deprecated_attr("no_default_passes", diag);
539+
report_deprecated_attr("no_default_passes", diag, attr.span());
517540
if default_passes == passes::DefaultPassOption::Default {
518541
default_passes = passes::DefaultPassOption::None;
519542
}
520543
}
521544
} else if let Some(value) = attr.value_str() {
522-
let sink = match name {
545+
match name {
523546
sym::passes => {
524-
report_deprecated_attr("passes = \"...\"", diag);
525-
&mut manual_passes
547+
report_deprecated_attr("passes = \"...\"", diag, attr.span());
526548
}
527549
sym::plugins => {
528-
report_deprecated_attr("plugins = \"...\"", diag);
529-
eprintln!(
530-
"WARNING: `#![doc(plugins = \"...\")]` \
531-
no longer functions; see CVE-2018-1000622"
532-
);
550+
report_deprecated_attr("plugins = \"...\"", diag, attr.span());
533551
continue;
534552
}
535553
_ => continue,
536554
};
537555
for name in value.as_str().split_whitespace() {
538-
sink.push(name.to_string());
556+
let span = attr.name_value_literal_span().unwrap_or(attr.span());
557+
manual_passes.extend(parse_pass(name, Some(span)));
539558
}
540559
}
541560

@@ -544,17 +563,7 @@ crate fn run_global_ctxt(
544563
}
545564
}
546565

547-
let passes = passes::defaults(default_passes).iter().copied().chain(
548-
manual_passes.into_iter().flat_map(|name| {
549-
if let Some(pass) = passes::find_pass(&name) {
550-
Some(ConditionalPass::always(pass))
551-
} else {
552-
error!("unknown pass {}, skipping", name);
553-
None
554-
}
555-
}),
556-
);
557-
566+
let passes = passes::defaults(default_passes).iter().copied().chain(manual_passes);
558567
info!("Executing passes");
559568

560569
for p in passes {
+15-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
// check-pass
2+
// compile-flags: --passes unknown-pass
3+
// error-pattern: ignoring unknown pass `unknown-pass`
24

3-
#![doc(no_default_passes, passes = "unindent-comments")]
4-
5-
struct SomeStruct;
6-
7-
pub struct OtherStruct;
5+
#![doc(no_default_passes)]
6+
//~^ WARNING attribute is deprecated
7+
//~| NOTE see issue #44136
8+
//~| HELP use `#![doc(document_private_items)]`
9+
#![doc(passes = "collapse-docs unindent-comments")]
10+
//~^ WARNING attribute is deprecated
11+
//~| NOTE see issue #44136
12+
//~| WARNING ignoring unknown pass
13+
//~| NOTE `collapse-docs` pass was removed
14+
#![doc(plugins = "xxx")]
15+
//~^ WARNING attribute is deprecated
16+
//~| NOTE see issue #44136
17+
//~| WARNING no longer functions; see CVE
+36-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,42 @@
1-
warning: the `#![doc(no_default_passes)]` attribute is considered deprecated
1+
warning: the `passes` flag is deprecated
22
|
3-
= warning: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
3+
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
4+
5+
warning: ignoring unknown pass `unknown-pass`
6+
7+
warning: the `#![doc(no_default_passes)]` attribute is deprecated
8+
--> $DIR/deprecated-attrs.rs:5:8
9+
|
10+
LL | #![doc(no_default_passes)]
11+
| ^^^^^^^^^^^^^^^^^
12+
|
13+
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
414
= help: you may want to use `#![doc(document_private_items)]`
515

6-
warning: the `#![doc(passes = "...")]` attribute is considered deprecated
16+
warning: the `#![doc(passes = "...")]` attribute is deprecated
17+
--> $DIR/deprecated-attrs.rs:9:8
18+
|
19+
LL | #![doc(passes = "collapse-docs unindent-comments")]
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
|
22+
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
23+
24+
warning: ignoring unknown pass `collapse-docs`
25+
--> $DIR/deprecated-attrs.rs:9:17
26+
|
27+
LL | #![doc(passes = "collapse-docs unindent-comments")]
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
|
30+
= note: the `collapse-docs` pass was removed in #80261 <https://github.com/rust-lang/rust/pull/80261>
31+
32+
warning: the `#![doc(plugins = "...")]` attribute is deprecated
33+
--> $DIR/deprecated-attrs.rs:14:8
34+
|
35+
LL | #![doc(plugins = "xxx")]
36+
| ^^^^^^^^^^^^^^^
737
|
8-
= warning: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
38+
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
39+
= warning: `#![doc(plugins = "...")]` no longer functions; see CVE-2018-1000622 <https://nvd.nist.gov/vuln/detail/CVE-2018-1000622>
940

10-
warning: 2 warnings emitted
41+
warning: 5 warnings emitted
1142

0 commit comments

Comments
 (0)