From 44c2794976986677c4f5524f63562d02e0e53d57 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 28 Feb 2021 22:41:05 -0500 Subject: [PATCH 1/2] 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 --- src/librustdoc/config.rs | 5 +- src/librustdoc/core.rs | 57 ++++++++++++--------- src/test/rustdoc-ui/deprecated-attrs.rs | 16 ++++-- src/test/rustdoc-ui/deprecated-attrs.stderr | 32 ++++++++++-- 4 files changed, 74 insertions(+), 36 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index d9f5b5bfa3ae2..6a62cacd34d18 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -654,9 +654,8 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Han { continue; } - let mut err = - diag.struct_warn(&format!("the '{}' flag is considered deprecated", flag)); - err.warn( + let mut err = diag.struct_warn(&format!("the `{}` flag is deprecated", flag)); + err.note( "see issue #44136 \ for more information", ); diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 6218aaf8276d5..a935bd6b456d5 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -22,7 +22,7 @@ use rustc_session::DiagnosticOutput; use rustc_session::Session; use rustc_span::source_map; use rustc_span::symbol::sym; -use rustc_span::DUMMY_SP; +use rustc_span::{Span, DUMMY_SP}; use std::mem; use std::rc::Rc; @@ -461,7 +461,7 @@ crate fn run_global_ctxt( tcx: TyCtxt<'_>, resolver: Rc>, mut default_passes: passes::DefaultPassOption, - mut manual_passes: Vec, + manual_passes: Vec, render_options: RenderOptions, output_format: OutputFormat, ) -> (clean::Crate, RenderOptions, Cache) { @@ -562,10 +562,10 @@ crate fn run_global_ctxt( } } - fn report_deprecated_attr(name: &str, diag: &rustc_errors::Handler) { - let mut msg = diag - .struct_warn(&format!("the `#![doc({})]` attribute is considered deprecated", name)); - msg.warn( + fn report_deprecated_attr(name: &str, diag: &rustc_errors::Handler, sp: Span) { + let mut msg = + diag.struct_span_warn(sp, &format!("the `#![doc({})]` attribute is deprecated", name)); + msg.note( "see issue #44136 \ for more information", ); @@ -577,6 +577,27 @@ crate fn run_global_ctxt( msg.emit(); } + let parse_pass = |name: &str, sp: Option| { + 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 "); + } + 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 // with the passes which we are supposed to run. for attr in krate.module.as_ref().unwrap().attrs.lists(sym::doc) { @@ -585,19 +606,18 @@ crate fn run_global_ctxt( let name = attr.name_or_empty(); if attr.is_word() { 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 { default_passes = passes::DefaultPassOption::None; } } } else if let Some(value) = attr.value_str() { - let sink = match name { + match name { sym::passes => { - report_deprecated_attr("passes = \"...\"", diag); - &mut manual_passes + report_deprecated_attr("passes = \"...\"", diag, attr.span()); } 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" @@ -607,7 +627,8 @@ crate fn run_global_ctxt( _ => continue, }; 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))); } } @@ -616,17 +637,7 @@ crate fn run_global_ctxt( } } - let passes = passes::defaults(default_passes).iter().copied().chain( - 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 - } - }), - ); - + let passes = passes::defaults(default_passes).iter().copied().chain(manual_passes); info!("Executing passes"); for p in passes { diff --git a/src/test/rustdoc-ui/deprecated-attrs.rs b/src/test/rustdoc-ui/deprecated-attrs.rs index ca626afbe5359..a0439acc0240c 100644 --- a/src/test/rustdoc-ui/deprecated-attrs.rs +++ b/src/test/rustdoc-ui/deprecated-attrs.rs @@ -1,7 +1,13 @@ // check-pass +// compile-flags: --passes unknown-pass +// error-pattern: ignoring unknown pass `unknown-pass` -#![doc(no_default_passes, passes = "unindent-comments")] - -struct SomeStruct; - -pub struct OtherStruct; +#![doc(no_default_passes)] +//~^ WARNING attribute is deprecated +//~| NOTE see issue #44136 +//~| HELP use `#![doc(document_private_items)]` +#![doc(passes = "collapse-docs unindent-comments")] +//~^ WARNING attribute is deprecated +//~| NOTE see issue #44136 +//~| WARNING ignoring unknown pass +//~| NOTE `collapse-docs` pass was removed diff --git a/src/test/rustdoc-ui/deprecated-attrs.stderr b/src/test/rustdoc-ui/deprecated-attrs.stderr index f68fb46744805..42a229abf58e8 100644 --- a/src/test/rustdoc-ui/deprecated-attrs.stderr +++ b/src/test/rustdoc-ui/deprecated-attrs.stderr @@ -1,11 +1,33 @@ -warning: the `#![doc(no_default_passes)]` attribute is considered deprecated +warning: the `passes` flag is deprecated | - = warning: see issue #44136 for more information + = note: see issue #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 for more information = 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 + | +LL | #![doc(passes = "collapse-docs unindent-comments")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #44136 for more information + +warning: ignoring unknown pass `collapse-docs` + --> $DIR/deprecated-attrs.rs:9:17 + | +LL | #![doc(passes = "collapse-docs unindent-comments")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = warning: see issue #44136 for more information + = note: the `collapse-docs` pass was removed in #80261 -warning: 2 warnings emitted +warning: 4 warnings emitted From d5c300b1f2e9a6f7f05b2fa51ca2b4d011d289f4 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 28 Feb 2021 22:51:35 -0500 Subject: [PATCH 2/2] Report that `doc(plugins)` doesn't work using diagnostics instead of `println!` This also adds a test for the output and fixes `rustc_attr` to properly know that `plugins` is a valid attribute. --- compiler/rustc_passes/src/check_attr.rs | 3 ++- src/librustdoc/core.rs | 6 ++---- src/test/rustdoc-ui/deprecated-attrs.rs | 4 ++++ src/test/rustdoc-ui/deprecated-attrs.stderr | 11 ++++++++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index afd1642bbd57c..d0ab0d657d9e5 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -559,7 +559,8 @@ impl CheckAttrVisitor<'tcx> { sym::masked, sym::no_default_passes, // deprecated sym::no_inline, - sym::passes, // deprecated + sym::passes, // deprecated + sym::plugins, // removed, but rustdoc warns about it itself sym::primitive, sym::spotlight, sym::test, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index a935bd6b456d5..19821c3ccefd2 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -572,6 +572,8 @@ crate fn run_global_ctxt( if name == "no_default_passes" { 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 "); } msg.emit(); @@ -618,10 +620,6 @@ crate fn run_global_ctxt( } sym::plugins => { report_deprecated_attr("plugins = \"...\"", diag, attr.span()); - eprintln!( - "WARNING: `#![doc(plugins = \"...\")]` \ - no longer functions; see CVE-2018-1000622" - ); continue; } _ => continue, diff --git a/src/test/rustdoc-ui/deprecated-attrs.rs b/src/test/rustdoc-ui/deprecated-attrs.rs index a0439acc0240c..5febc5eb9cd54 100644 --- a/src/test/rustdoc-ui/deprecated-attrs.rs +++ b/src/test/rustdoc-ui/deprecated-attrs.rs @@ -11,3 +11,7 @@ //~| 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 diff --git a/src/test/rustdoc-ui/deprecated-attrs.stderr b/src/test/rustdoc-ui/deprecated-attrs.stderr index 42a229abf58e8..b855cedf5223e 100644 --- a/src/test/rustdoc-ui/deprecated-attrs.stderr +++ b/src/test/rustdoc-ui/deprecated-attrs.stderr @@ -29,5 +29,14 @@ LL | #![doc(passes = "collapse-docs unindent-comments")] | = note: the `collapse-docs` pass was removed in #80261 -warning: 4 warnings emitted +warning: the `#![doc(plugins = "...")]` attribute is deprecated + --> $DIR/deprecated-attrs.rs:14:8 + | +LL | #![doc(plugins = "xxx")] + | ^^^^^^^^^^^^^^^ + | + = note: see issue #44136 for more information + = warning: `#![doc(plugins = "...")]` no longer functions; see CVE-2018-1000622 + +warning: 5 warnings emitted