Skip to content

Commit 44c2794

Browse files
committed
Clean up error reporting for deprecated passes
- 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
1 parent edeee91 commit 44c2794

File tree

4 files changed

+74
-36
lines changed

4 files changed

+74
-36
lines changed

src/librustdoc/config.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,8 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Han
654654
{
655655
continue;
656656
}
657-
let mut err =
658-
diag.struct_warn(&format!("the '{}' flag is considered deprecated", flag));
659-
err.warn(
657+
let mut err = diag.struct_warn(&format!("the `{}` flag is deprecated", flag));
658+
err.note(
660659
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
661660
for more information",
662661
);

src/librustdoc/core.rs

+34-23
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::mem;
2828
use std::rc::Rc;
@@ -461,7 +461,7 @@ crate fn run_global_ctxt(
461461
tcx: TyCtxt<'_>,
462462
resolver: Rc<RefCell<interface::BoxedResolver>>,
463463
mut default_passes: passes::DefaultPassOption,
464-
mut manual_passes: Vec<String>,
464+
manual_passes: Vec<String>,
465465
render_options: RenderOptions,
466466
output_format: OutputFormat,
467467
) -> (clean::Crate, RenderOptions, Cache) {
@@ -562,10 +562,10 @@ crate fn run_global_ctxt(
562562
}
563563
}
564564

565-
fn report_deprecated_attr(name: &str, diag: &rustc_errors::Handler) {
566-
let mut msg = diag
567-
.struct_warn(&format!("the `#![doc({})]` attribute is considered deprecated", name));
568-
msg.warn(
565+
fn report_deprecated_attr(name: &str, diag: &rustc_errors::Handler, sp: Span) {
566+
let mut msg =
567+
diag.struct_span_warn(sp, &format!("the `#![doc({})]` attribute is deprecated", name));
568+
msg.note(
569569
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
570570
for more information",
571571
);
@@ -577,6 +577,27 @@ crate fn run_global_ctxt(
577577
msg.emit();
578578
}
579579

580+
let parse_pass = |name: &str, sp: Option<Span>| {
581+
if let Some(pass) = passes::find_pass(name) {
582+
Some(ConditionalPass::always(pass))
583+
} else {
584+
let msg = &format!("ignoring unknown pass `{}`", name);
585+
let mut warning = if let Some(sp) = sp {
586+
tcx.sess.struct_span_warn(sp, msg)
587+
} else {
588+
tcx.sess.struct_warn(msg)
589+
};
590+
if name == "collapse-docs" {
591+
warning.note("the `collapse-docs` pass was removed in #80261 <https://github.com/rust-lang/rust/pull/80261>");
592+
}
593+
warning.emit();
594+
None
595+
}
596+
};
597+
598+
let mut manual_passes: Vec<_> =
599+
manual_passes.into_iter().flat_map(|name| parse_pass(&name, None)).collect();
600+
580601
// Process all of the crate attributes, extracting plugin metadata along
581602
// with the passes which we are supposed to run.
582603
for attr in krate.module.as_ref().unwrap().attrs.lists(sym::doc) {
@@ -585,19 +606,18 @@ crate fn run_global_ctxt(
585606
let name = attr.name_or_empty();
586607
if attr.is_word() {
587608
if name == sym::no_default_passes {
588-
report_deprecated_attr("no_default_passes", diag);
609+
report_deprecated_attr("no_default_passes", diag, attr.span());
589610
if default_passes == passes::DefaultPassOption::Default {
590611
default_passes = passes::DefaultPassOption::None;
591612
}
592613
}
593614
} else if let Some(value) = attr.value_str() {
594-
let sink = match name {
615+
match name {
595616
sym::passes => {
596-
report_deprecated_attr("passes = \"...\"", diag);
597-
&mut manual_passes
617+
report_deprecated_attr("passes = \"...\"", diag, attr.span());
598618
}
599619
sym::plugins => {
600-
report_deprecated_attr("plugins = \"...\"", diag);
620+
report_deprecated_attr("plugins = \"...\"", diag, attr.span());
601621
eprintln!(
602622
"WARNING: `#![doc(plugins = \"...\")]` \
603623
no longer functions; see CVE-2018-1000622"
@@ -607,7 +627,8 @@ crate fn run_global_ctxt(
607627
_ => continue,
608628
};
609629
for name in value.as_str().split_whitespace() {
610-
sink.push(name.to_string());
630+
let span = attr.name_value_literal_span().unwrap_or(attr.span());
631+
manual_passes.extend(parse_pass(name, Some(span)));
611632
}
612633
}
613634

@@ -616,17 +637,7 @@ crate fn run_global_ctxt(
616637
}
617638
}
618639

619-
let passes = passes::defaults(default_passes).iter().copied().chain(
620-
manual_passes.into_iter().flat_map(|name| {
621-
if let Some(pass) = passes::find_pass(&name) {
622-
Some(ConditionalPass::always(pass))
623-
} else {
624-
error!("unknown pass {}, skipping", name);
625-
None
626-
}
627-
}),
628-
);
629-
640+
let passes = passes::defaults(default_passes).iter().copied().chain(manual_passes);
630641
info!("Executing passes");
631642

632643
for p in passes {
+11-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
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
+27-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
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+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
729
|
8-
= warning: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
30+
= note: the `collapse-docs` pass was removed in #80261 <https://github.com/rust-lang/rust/pull/80261>
931

10-
warning: 2 warnings emitted
32+
warning: 4 warnings emitted
1133

0 commit comments

Comments
 (0)