Skip to content

Add doc(plugins), doc(passes), etc. to INVALID_DOC_ATTRIBUTES #131732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/44136> and CVE-2018-1000622 <https://nvd.nist.gov/vuln/detail/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)`
Expand Down
26 changes: 17 additions & 9 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,15 +1187,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {

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)
Expand Down Expand Up @@ -1244,6 +1236,22 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
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,
Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 2 additions & 37 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_data_structures::unord::UnordSet;
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};
Expand All @@ -21,8 +21,8 @@ use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
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;
Expand Down Expand Up @@ -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 <https://github.com/rust-lang/rust/issues/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 <https://nvd.nist.gov/vuln/detail/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;
Expand Down
19 changes: 12 additions & 7 deletions tests/rustdoc-ui/deprecated-attrs.rs
Original file line number Diff line number Diff line change
@@ -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
35 changes: 19 additions & 16 deletions tests/rustdoc-ui/deprecated-attrs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,35 @@ warning: the `passes` flag no longer functions
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <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>
= note: `doc` attribute `plugins` no longer functions; see issue #44136 <https://github.com/rust-lang/rust/issues/44136> and CVE-2018-1000622 <https://nvd.nist.gov/vuln/detail/CVE-2018-1000622>
= note: `doc(plugins)` is now a no-op

warning: 3 warnings emitted
error: aborting due to 3 previous errors

Loading