diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index e5a14f6a156..cd866edaabd 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -245,6 +245,19 @@ passes_doc_test_unknown_include = unknown `doc` attribute `{$path}` .suggestion = use `doc = include_str!` instead +passes_doc_test_unknown_passes = + unknown `doc` attribute `{$path}` + .note = `doc` attribute `{$path}` no longer functions; see issue #44136 + .label = no longer functions + .help = you may want to use `doc(document_private_items)` + .no_op_note = `doc({$path})` is now a no-op + +passes_doc_test_unknown_plugins = + unknown `doc` attribute `{$path}` + .note = `doc` attribute `{$path}` no longer functions; see issue #44136 and CVE-2018-1000622 + .label = no longer functions + .no_op_note = `doc({$path})` is now a no-op + passes_doc_test_unknown_spotlight = unknown `doc` attribute `{$path}` .note = `doc(spotlight)` was renamed to `doc(notable_trait)` diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 7ce29260e36..f8cb34f791b 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1187,15 +1187,7 @@ fn check_doc_attrs( sym::masked => self.check_doc_masked(attr, meta, hir_id, target), - // no_default_passes: deprecated - // passes: deprecated - // plugins: removed, but rustdoc warns about it itself - sym::cfg - | sym::hidden - | sym::no_default_passes - | sym::notable_trait - | sym::passes - | sym::plugins => {} + sym::cfg | sym::hidden | sym::notable_trait => {} sym::rust_logo => { if self.check_attr_crate_level(attr, meta, hir_id) @@ -1244,6 +1236,22 @@ fn check_doc_attrs( sugg: (attr.meta().unwrap().span, applicability), }, ); + } else if i_meta.has_name(sym::passes) + || i_meta.has_name(sym::no_default_passes) + { + self.tcx.emit_node_span_lint( + INVALID_DOC_ATTRIBUTES, + hir_id, + i_meta.span, + errors::DocTestUnknownPasses { path, span: i_meta.span }, + ); + } else if i_meta.has_name(sym::plugins) { + self.tcx.emit_node_span_lint( + INVALID_DOC_ATTRIBUTES, + hir_id, + i_meta.span, + errors::DocTestUnknownPlugins { path, span: i_meta.span }, + ); } else { self.tcx.emit_node_span_lint( INVALID_DOC_ATTRIBUTES, diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 6dc3dfba58f..630fb80bb7f 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -317,6 +317,27 @@ pub(crate) struct DocTestUnknownSpotlight { pub span: Span, } +#[derive(LintDiagnostic)] +#[diag(passes_doc_test_unknown_passes)] +#[note] +#[help] +#[note(passes_no_op_note)] +pub(crate) struct DocTestUnknownPasses { + pub path: String, + #[label] + pub span: Span, +} + +#[derive(LintDiagnostic)] +#[diag(passes_doc_test_unknown_plugins)] +#[note] +#[note(passes_no_op_note)] +pub(crate) struct DocTestUnknownPlugins { + pub path: String, + #[label] + pub span: Span, +} + #[derive(LintDiagnostic)] #[diag(passes_doc_test_unknown_include)] pub(crate) struct DocTestUnknownInclude { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index aaf4c80f997..63cd055796b 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -8,7 +8,7 @@ use rustc_errors::codes::*; use rustc_errors::emitter::{DynEmitter, HumanEmitter, stderr_destination}; use rustc_errors::json::JsonEmitter; -use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, TerminalUrl}; +use rustc_errors::{ErrorGuaranteed, TerminalUrl}; use rustc_feature::UnstableFeatures; use rustc_hir::def::Res; use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LocalDefId}; @@ -21,8 +21,8 @@ use rustc_session::config::{self, CrateType, ErrorOutputType, Input, ResolveDocLinks}; pub(crate) use rustc_session::config::{Options, UnstableOptions}; use rustc_session::{Session, lint}; +use rustc_span::source_map; use rustc_span::symbol::sym; -use rustc_span::{Span, source_map}; use tracing::{debug, info}; use crate::clean::inline::build_external_trait; @@ -380,45 +380,10 @@ pub(crate) fn run_global_ctxt( ); } - fn report_deprecated_attr(name: &str, dcx: DiagCtxtHandle<'_>, sp: Span) { - let mut msg = - dcx.struct_span_warn(sp, format!("the `#![doc({name})]` attribute is deprecated")); - msg.note( - "see issue #44136 \ - for more information", - ); - - if name == "no_default_passes" { - msg.help("`#![doc(no_default_passes)]` no longer functions; you may want to use `#![doc(document_private_items)]`"); - } else if name.starts_with("passes") { - msg.help("`#![doc(passes = \"...\")]` no longer functions; 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(); - } - // Process all of the crate attributes, extracting plugin metadata along // with the passes which we are supposed to run. for attr in krate.module.attrs.lists(sym::doc) { - let dcx = ctxt.sess().dcx(); - let name = attr.name_or_empty(); - // `plugins = "..."`, `no_default_passes`, and `passes = "..."` have no effect - if attr.is_word() && name == sym::no_default_passes { - report_deprecated_attr("no_default_passes", dcx, attr.span()); - } else if attr.value_str().is_some() { - match name { - sym::passes => { - report_deprecated_attr("passes = \"...\"", dcx, attr.span()); - } - sym::plugins => { - report_deprecated_attr("plugins = \"...\"", dcx, attr.span()); - } - _ => (), - } - } if attr.is_word() && name == sym::document_private_items { ctxt.render_options.document_private = true; diff --git a/tests/rustdoc-ui/deprecated-attrs.rs b/tests/rustdoc-ui/deprecated-attrs.rs index e4802ee2518..3b59e05a012 100644 --- a/tests/rustdoc-ui/deprecated-attrs.rs +++ b/tests/rustdoc-ui/deprecated-attrs.rs @@ -1,16 +1,21 @@ -//@ check-pass //@ compile-flags: --passes unknown-pass //@ error-pattern: the `passes` flag no longer functions #![doc(no_default_passes)] -//~^ WARNING attribute is deprecated +//~^ ERROR unknown `doc` attribute `no_default_passes` +//~| NOTE no longer functions //~| NOTE see issue #44136 -//~| HELP no longer functions; you may want to use `#![doc(document_private_items)]` +//~| HELP you may want to use `doc(document_private_items)` +//~| NOTE `doc(no_default_passes)` is now a no-op +//~| NOTE `#[deny(invalid_doc_attributes)]` on by default #![doc(passes = "collapse-docs unindent-comments")] -//~^ WARNING attribute is deprecated +//~^ ERROR unknown `doc` attribute `passes` +//~| NOTE no longer functions //~| NOTE see issue #44136 -//~| HELP no longer functions; you may want to use `#![doc(document_private_items)]` +//~| HELP you may want to use `doc(document_private_items)` +//~| NOTE `doc(passes)` is now a no-op #![doc(plugins = "xxx")] -//~^ WARNING attribute is deprecated +//~^ ERROR unknown `doc` attribute `plugins` //~| NOTE see issue #44136 -//~| WARNING no longer functions; see CVE +//~| NOTE no longer functions +//~| NOTE `doc(plugins)` is now a no-op diff --git a/tests/rustdoc-ui/deprecated-attrs.stderr b/tests/rustdoc-ui/deprecated-attrs.stderr index 45b20ce70ef..a30523e7329 100644 --- a/tests/rustdoc-ui/deprecated-attrs.stderr +++ b/tests/rustdoc-ui/deprecated-attrs.stderr @@ -3,32 +3,35 @@ warning: the `passes` flag no longer functions = note: see issue #44136 for more information = help: you may want to use --document-private-items -warning: the `#![doc(no_default_passes)]` attribute is deprecated - --> $DIR/deprecated-attrs.rs:5:8 +error: unknown `doc` attribute `no_default_passes` + --> $DIR/deprecated-attrs.rs:4:8 | LL | #![doc(no_default_passes)] - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ no longer functions | - = note: see issue #44136 for more information - = help: `#![doc(no_default_passes)]` no longer functions; you may want to use `#![doc(document_private_items)]` + = note: `doc` attribute `no_default_passes` no longer functions; see issue #44136 + = help: you may want to use `doc(document_private_items)` + = note: `doc(no_default_passes)` is now a no-op + = note: `#[deny(invalid_doc_attributes)]` on by default -warning: the `#![doc(passes = "...")]` attribute is deprecated - --> $DIR/deprecated-attrs.rs:9:8 +error: unknown `doc` attribute `passes` + --> $DIR/deprecated-attrs.rs:11:8 | LL | #![doc(passes = "collapse-docs unindent-comments")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no longer functions | - = note: see issue #44136 for more information - = help: `#![doc(passes = "...")]` no longer functions; you may want to use `#![doc(document_private_items)]` + = note: `doc` attribute `passes` no longer functions; see issue #44136 + = help: you may want to use `doc(document_private_items)` + = note: `doc(passes)` is now a no-op -warning: the `#![doc(plugins = "...")]` attribute is deprecated - --> $DIR/deprecated-attrs.rs:13:8 +error: unknown `doc` attribute `plugins` + --> $DIR/deprecated-attrs.rs:17:8 | LL | #![doc(plugins = "xxx")] - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ no longer functions | - = note: see issue #44136 for more information - = warning: `#![doc(plugins = "...")]` no longer functions; see CVE-2018-1000622 + = note: `doc` attribute `plugins` no longer functions; see issue #44136 and CVE-2018-1000622 + = note: `doc(plugins)` is now a no-op -warning: 3 warnings emitted +error: aborting due to 3 previous errors