Rollup merge of #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, https://github.com/rust-lang/rust/pull/8540. I don't see any reason to use logging; rustdoc should use diagnostics wherever possible. See https://github.com/rust-lang/rust/pull/81932#issuecomment-785291244 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 https://github.com/rust-lang/rust/pull/52194. I don't see any particular reason not to use diagnostics here, I think it was just missed in https://github.com/rust-lang/rust/pull/50541.
This commit is contained in:
commit
f3218dfa57
5 changed files with 91 additions and 41 deletions
|
@ -576,7 +576,8 @@ impl CheckAttrVisitor<'tcx> {
|
||||||
sym::masked,
|
sym::masked,
|
||||||
sym::no_default_passes, // deprecated
|
sym::no_default_passes, // deprecated
|
||||||
sym::no_inline,
|
sym::no_inline,
|
||||||
sym::passes, // deprecated
|
sym::passes, // deprecated
|
||||||
|
sym::plugins, // removed, but rustdoc warns about it itself
|
||||||
sym::primitive,
|
sym::primitive,
|
||||||
sym::spotlight,
|
sym::spotlight,
|
||||||
sym::test,
|
sym::test,
|
||||||
|
|
|
@ -658,9 +658,8 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Han
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let mut err =
|
let mut err = diag.struct_warn(&format!("the `{}` flag is deprecated", flag));
|
||||||
diag.struct_warn(&format!("the '{}' flag is considered deprecated", flag));
|
err.note(
|
||||||
err.warn(
|
|
||||||
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
|
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
|
||||||
for more information",
|
for more information",
|
||||||
);
|
);
|
||||||
|
|
|
@ -22,7 +22,7 @@ use rustc_session::DiagnosticOutput;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::source_map;
|
use rustc_span::source_map;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
@ -389,7 +389,7 @@ crate fn run_global_ctxt(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
resolver: Rc<RefCell<interface::BoxedResolver>>,
|
resolver: Rc<RefCell<interface::BoxedResolver>>,
|
||||||
mut default_passes: passes::DefaultPassOption,
|
mut default_passes: passes::DefaultPassOption,
|
||||||
mut manual_passes: Vec<String>,
|
manual_passes: Vec<String>,
|
||||||
render_options: RenderOptions,
|
render_options: RenderOptions,
|
||||||
output_format: OutputFormat,
|
output_format: OutputFormat,
|
||||||
) -> (clean::Crate, RenderOptions, Cache) {
|
) -> (clean::Crate, RenderOptions, Cache) {
|
||||||
|
@ -490,21 +490,44 @@ crate fn run_global_ctxt(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn report_deprecated_attr(name: &str, diag: &rustc_errors::Handler) {
|
fn report_deprecated_attr(name: &str, diag: &rustc_errors::Handler, sp: Span) {
|
||||||
let mut msg = diag
|
let mut msg =
|
||||||
.struct_warn(&format!("the `#![doc({})]` attribute is considered deprecated", name));
|
diag.struct_span_warn(sp, &format!("the `#![doc({})]` attribute is deprecated", name));
|
||||||
msg.warn(
|
msg.note(
|
||||||
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
|
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
|
||||||
for more information",
|
for more information",
|
||||||
);
|
);
|
||||||
|
|
||||||
if name == "no_default_passes" {
|
if name == "no_default_passes" {
|
||||||
msg.help("you may want to use `#![doc(document_private_items)]`");
|
msg.help("you may want to use `#![doc(document_private_items)]`");
|
||||||
|
} else if name.starts_with("plugins") {
|
||||||
|
msg.warn("`#![doc(plugins = \"...\")]` no longer functions; see CVE-2018-1000622 <https://nvd.nist.gov/vuln/detail/CVE-2018-1000622>");
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.emit();
|
msg.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let parse_pass = |name: &str, sp: Option<Span>| {
|
||||||
|
if let Some(pass) = passes::find_pass(name) {
|
||||||
|
Some(ConditionalPass::always(pass))
|
||||||
|
} else {
|
||||||
|
let msg = &format!("ignoring unknown pass `{}`", name);
|
||||||
|
let mut warning = if let Some(sp) = sp {
|
||||||
|
tcx.sess.struct_span_warn(sp, msg)
|
||||||
|
} else {
|
||||||
|
tcx.sess.struct_warn(msg)
|
||||||
|
};
|
||||||
|
if name == "collapse-docs" {
|
||||||
|
warning.note("the `collapse-docs` pass was removed in #80261 <https://github.com/rust-lang/rust/pull/80261>");
|
||||||
|
}
|
||||||
|
warning.emit();
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut manual_passes: Vec<_> =
|
||||||
|
manual_passes.into_iter().flat_map(|name| parse_pass(&name, None)).collect();
|
||||||
|
|
||||||
// Process all of the crate attributes, extracting plugin metadata along
|
// Process all of the crate attributes, extracting plugin metadata along
|
||||||
// with the passes which we are supposed to run.
|
// with the passes which we are supposed to run.
|
||||||
for attr in krate.module.as_ref().unwrap().attrs.lists(sym::doc) {
|
for attr in krate.module.as_ref().unwrap().attrs.lists(sym::doc) {
|
||||||
|
@ -513,29 +536,25 @@ crate fn run_global_ctxt(
|
||||||
let name = attr.name_or_empty();
|
let name = attr.name_or_empty();
|
||||||
if attr.is_word() {
|
if attr.is_word() {
|
||||||
if name == sym::no_default_passes {
|
if name == sym::no_default_passes {
|
||||||
report_deprecated_attr("no_default_passes", diag);
|
report_deprecated_attr("no_default_passes", diag, attr.span());
|
||||||
if default_passes == passes::DefaultPassOption::Default {
|
if default_passes == passes::DefaultPassOption::Default {
|
||||||
default_passes = passes::DefaultPassOption::None;
|
default_passes = passes::DefaultPassOption::None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Some(value) = attr.value_str() {
|
} else if let Some(value) = attr.value_str() {
|
||||||
let sink = match name {
|
match name {
|
||||||
sym::passes => {
|
sym::passes => {
|
||||||
report_deprecated_attr("passes = \"...\"", diag);
|
report_deprecated_attr("passes = \"...\"", diag, attr.span());
|
||||||
&mut manual_passes
|
|
||||||
}
|
}
|
||||||
sym::plugins => {
|
sym::plugins => {
|
||||||
report_deprecated_attr("plugins = \"...\"", diag);
|
report_deprecated_attr("plugins = \"...\"", diag, attr.span());
|
||||||
eprintln!(
|
|
||||||
"WARNING: `#![doc(plugins = \"...\")]` \
|
|
||||||
no longer functions; see CVE-2018-1000622"
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
for name in value.as_str().split_whitespace() {
|
for name in value.as_str().split_whitespace() {
|
||||||
sink.push(name.to_string());
|
let span = attr.name_value_literal_span().unwrap_or(attr.span());
|
||||||
|
manual_passes.extend(parse_pass(name, Some(span)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,17 +563,7 @@ crate fn run_global_ctxt(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let passes = passes::defaults(default_passes).iter().copied().chain(
|
let passes = passes::defaults(default_passes).iter().copied().chain(manual_passes);
|
||||||
manual_passes.into_iter().flat_map(|name| {
|
|
||||||
if let Some(pass) = passes::find_pass(&name) {
|
|
||||||
Some(ConditionalPass::always(pass))
|
|
||||||
} else {
|
|
||||||
error!("unknown pass {}, skipping", name);
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
info!("Executing passes");
|
info!("Executing passes");
|
||||||
|
|
||||||
for p in passes {
|
for p in passes {
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
// check-pass
|
// check-pass
|
||||||
|
// compile-flags: --passes unknown-pass
|
||||||
|
// error-pattern: ignoring unknown pass `unknown-pass`
|
||||||
|
|
||||||
#![doc(no_default_passes, passes = "unindent-comments")]
|
#![doc(no_default_passes)]
|
||||||
|
//~^ WARNING attribute is deprecated
|
||||||
struct SomeStruct;
|
//~| NOTE see issue #44136
|
||||||
|
//~| HELP use `#![doc(document_private_items)]`
|
||||||
pub struct OtherStruct;
|
#![doc(passes = "collapse-docs unindent-comments")]
|
||||||
|
//~^ WARNING attribute is deprecated
|
||||||
|
//~| NOTE see issue #44136
|
||||||
|
//~| WARNING ignoring unknown pass
|
||||||
|
//~| NOTE `collapse-docs` pass was removed
|
||||||
|
#![doc(plugins = "xxx")]
|
||||||
|
//~^ WARNING attribute is deprecated
|
||||||
|
//~| NOTE see issue #44136
|
||||||
|
//~| WARNING no longer functions; see CVE
|
||||||
|
|
|
@ -1,11 +1,42 @@
|
||||||
warning: the `#![doc(no_default_passes)]` attribute is considered deprecated
|
warning: the `passes` flag is deprecated
|
||||||
|
|
|
|
||||||
= warning: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
|
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
|
||||||
|
|
||||||
|
warning: ignoring unknown pass `unknown-pass`
|
||||||
|
|
||||||
|
warning: the `#![doc(no_default_passes)]` attribute is deprecated
|
||||||
|
--> $DIR/deprecated-attrs.rs:5:8
|
||||||
|
|
|
||||||
|
LL | #![doc(no_default_passes)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
|
||||||
= help: you may want to use `#![doc(document_private_items)]`
|
= help: you may want to use `#![doc(document_private_items)]`
|
||||||
|
|
||||||
warning: the `#![doc(passes = "...")]` attribute is considered deprecated
|
warning: the `#![doc(passes = "...")]` attribute is deprecated
|
||||||
|
--> $DIR/deprecated-attrs.rs:9:8
|
||||||
|
|
|
|
||||||
= warning: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
|
LL | #![doc(passes = "collapse-docs unindent-comments")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
|
||||||
|
|
||||||
warning: 2 warnings emitted
|
warning: ignoring unknown pass `collapse-docs`
|
||||||
|
--> $DIR/deprecated-attrs.rs:9:17
|
||||||
|
|
|
||||||
|
LL | #![doc(passes = "collapse-docs unindent-comments")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: the `collapse-docs` pass was removed in #80261 <https://github.com/rust-lang/rust/pull/80261>
|
||||||
|
|
||||||
|
warning: the `#![doc(plugins = "...")]` attribute is deprecated
|
||||||
|
--> $DIR/deprecated-attrs.rs:14:8
|
||||||
|
|
|
||||||
|
LL | #![doc(plugins = "xxx")]
|
||||||
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
|
||||||
|
= warning: `#![doc(plugins = "...")]` no longer functions; see CVE-2018-1000622 <https://nvd.nist.gov/vuln/detail/CVE-2018-1000622>
|
||||||
|
|
||||||
|
warning: 5 warnings emitted
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue