Skip to content

Commit 83085b9

Browse files
authored
Rollup merge of #131732 - m4tx:fix-82824, r=davidtwco
Add doc(plugins), doc(passes), etc. to INVALID_DOC_ATTRIBUTES This fixes #82824.
2 parents cbb85f1 + d11a970 commit 83085b9

File tree

6 files changed

+84
-69
lines changed

6 files changed

+84
-69
lines changed

compiler/rustc_passes/messages.ftl

+13
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,19 @@ passes_doc_test_unknown_include =
245245
unknown `doc` attribute `{$path}`
246246
.suggestion = use `doc = include_str!` instead
247247
248+
passes_doc_test_unknown_passes =
249+
unknown `doc` attribute `{$path}`
250+
.note = `doc` attribute `{$path}` no longer functions; see issue #44136 <https://github.com/rust-lang/rust/issues/44136>
251+
.label = no longer functions
252+
.help = you may want to use `doc(document_private_items)`
253+
.no_op_note = `doc({$path})` is now a no-op
254+
255+
passes_doc_test_unknown_plugins =
256+
unknown `doc` attribute `{$path}`
257+
.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>
258+
.label = no longer functions
259+
.no_op_note = `doc({$path})` is now a no-op
260+
248261
passes_doc_test_unknown_spotlight =
249262
unknown `doc` attribute `{$path}`
250263
.note = `doc(spotlight)` was renamed to `doc(notable_trait)`

compiler/rustc_passes/src/check_attr.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -1183,15 +1183,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11831183

11841184
sym::masked => self.check_doc_masked(attr, meta, hir_id, target),
11851185

1186-
// no_default_passes: deprecated
1187-
// passes: deprecated
1188-
// plugins: removed, but rustdoc warns about it itself
1189-
sym::cfg
1190-
| sym::hidden
1191-
| sym::no_default_passes
1192-
| sym::notable_trait
1193-
| sym::passes
1194-
| sym::plugins => {}
1186+
sym::cfg | sym::hidden | sym::notable_trait => {}
11951187

11961188
sym::rust_logo => {
11971189
if self.check_attr_crate_level(attr, meta, hir_id)
@@ -1240,6 +1232,22 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12401232
sugg: (attr.meta().unwrap().span, applicability),
12411233
},
12421234
);
1235+
} else if i_meta.has_name(sym::passes)
1236+
|| i_meta.has_name(sym::no_default_passes)
1237+
{
1238+
self.tcx.emit_node_span_lint(
1239+
INVALID_DOC_ATTRIBUTES,
1240+
hir_id,
1241+
i_meta.span,
1242+
errors::DocTestUnknownPasses { path, span: i_meta.span },
1243+
);
1244+
} else if i_meta.has_name(sym::plugins) {
1245+
self.tcx.emit_node_span_lint(
1246+
INVALID_DOC_ATTRIBUTES,
1247+
hir_id,
1248+
i_meta.span,
1249+
errors::DocTestUnknownPlugins { path, span: i_meta.span },
1250+
);
12431251
} else {
12441252
self.tcx.emit_node_span_lint(
12451253
INVALID_DOC_ATTRIBUTES,

compiler/rustc_passes/src/errors.rs

+21
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,27 @@ pub(crate) struct DocTestUnknownSpotlight {
323323
pub span: Span,
324324
}
325325

326+
#[derive(LintDiagnostic)]
327+
#[diag(passes_doc_test_unknown_passes)]
328+
#[note]
329+
#[help]
330+
#[note(passes_no_op_note)]
331+
pub(crate) struct DocTestUnknownPasses {
332+
pub path: String,
333+
#[label]
334+
pub span: Span,
335+
}
336+
337+
#[derive(LintDiagnostic)]
338+
#[diag(passes_doc_test_unknown_plugins)]
339+
#[note]
340+
#[note(passes_no_op_note)]
341+
pub(crate) struct DocTestUnknownPlugins {
342+
pub path: String,
343+
#[label]
344+
pub span: Span,
345+
}
346+
326347
#[derive(LintDiagnostic)]
327348
#[diag(passes_doc_test_unknown_include)]
328349
pub(crate) struct DocTestUnknownInclude {

src/librustdoc/core.rs

+2-37
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_data_structures::unord::UnordSet;
88
use rustc_errors::codes::*;
99
use rustc_errors::emitter::{DynEmitter, HumanEmitter, stderr_destination};
1010
use rustc_errors::json::JsonEmitter;
11-
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, TerminalUrl};
11+
use rustc_errors::{ErrorGuaranteed, TerminalUrl};
1212
use rustc_feature::UnstableFeatures;
1313
use rustc_hir::def::Res;
1414
use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LocalDefId};
@@ -21,8 +21,8 @@ use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
2121
use rustc_session::config::{self, CrateType, ErrorOutputType, Input, ResolveDocLinks};
2222
pub(crate) use rustc_session::config::{Options, UnstableOptions};
2323
use rustc_session::{Session, lint};
24+
use rustc_span::source_map;
2425
use rustc_span::symbol::sym;
25-
use rustc_span::{Span, source_map};
2626
use tracing::{debug, info};
2727

2828
use crate::clean::inline::build_external_trait;
@@ -381,45 +381,10 @@ pub(crate) fn run_global_ctxt(
381381
);
382382
}
383383

384-
fn report_deprecated_attr(name: &str, dcx: DiagCtxtHandle<'_>, sp: Span) {
385-
let mut msg =
386-
dcx.struct_span_warn(sp, format!("the `#![doc({name})]` attribute is deprecated"));
387-
msg.note(
388-
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
389-
for more information",
390-
);
391-
392-
if name == "no_default_passes" {
393-
msg.help("`#![doc(no_default_passes)]` no longer functions; you may want to use `#![doc(document_private_items)]`");
394-
} else if name.starts_with("passes") {
395-
msg.help("`#![doc(passes = \"...\")]` no longer functions; you may want to use `#![doc(document_private_items)]`");
396-
} else if name.starts_with("plugins") {
397-
msg.warn("`#![doc(plugins = \"...\")]` no longer functions; see CVE-2018-1000622 <https://nvd.nist.gov/vuln/detail/CVE-2018-1000622>");
398-
}
399-
400-
msg.emit();
401-
}
402-
403384
// Process all of the crate attributes, extracting plugin metadata along
404385
// with the passes which we are supposed to run.
405386
for attr in krate.module.attrs.lists(sym::doc) {
406-
let dcx = ctxt.sess().dcx();
407-
408387
let name = attr.name_or_empty();
409-
// `plugins = "..."`, `no_default_passes`, and `passes = "..."` have no effect
410-
if attr.is_word() && name == sym::no_default_passes {
411-
report_deprecated_attr("no_default_passes", dcx, attr.span());
412-
} else if attr.value_str().is_some() {
413-
match name {
414-
sym::passes => {
415-
report_deprecated_attr("passes = \"...\"", dcx, attr.span());
416-
}
417-
sym::plugins => {
418-
report_deprecated_attr("plugins = \"...\"", dcx, attr.span());
419-
}
420-
_ => (),
421-
}
422-
}
423388

424389
if attr.is_word() && name == sym::document_private_items {
425390
ctxt.render_options.document_private = true;

tests/rustdoc-ui/deprecated-attrs.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
//@ check-pass
21
//@ compile-flags: --passes unknown-pass
32
//@ error-pattern: the `passes` flag no longer functions
43

54
#![doc(no_default_passes)]
6-
//~^ WARNING attribute is deprecated
5+
//~^ ERROR unknown `doc` attribute `no_default_passes`
6+
//~| NOTE no longer functions
77
//~| NOTE see issue #44136
8-
//~| HELP no longer functions; you may want to use `#![doc(document_private_items)]`
8+
//~| HELP you may want to use `doc(document_private_items)`
9+
//~| NOTE `doc(no_default_passes)` is now a no-op
10+
//~| NOTE `#[deny(invalid_doc_attributes)]` on by default
911
#![doc(passes = "collapse-docs unindent-comments")]
10-
//~^ WARNING attribute is deprecated
12+
//~^ ERROR unknown `doc` attribute `passes`
13+
//~| NOTE no longer functions
1114
//~| NOTE see issue #44136
12-
//~| HELP no longer functions; you may want to use `#![doc(document_private_items)]`
15+
//~| HELP you may want to use `doc(document_private_items)`
16+
//~| NOTE `doc(passes)` is now a no-op
1317
#![doc(plugins = "xxx")]
14-
//~^ WARNING attribute is deprecated
18+
//~^ ERROR unknown `doc` attribute `plugins`
1519
//~| NOTE see issue #44136
16-
//~| WARNING no longer functions; see CVE
20+
//~| NOTE no longer functions
21+
//~| NOTE `doc(plugins)` is now a no-op

tests/rustdoc-ui/deprecated-attrs.stderr

+19-16
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,35 @@ warning: the `passes` flag no longer functions
33
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
44
= help: you may want to use --document-private-items
55

6-
warning: the `#![doc(no_default_passes)]` attribute is deprecated
7-
--> $DIR/deprecated-attrs.rs:5:8
6+
error: unknown `doc` attribute `no_default_passes`
7+
--> $DIR/deprecated-attrs.rs:4:8
88
|
99
LL | #![doc(no_default_passes)]
10-
| ^^^^^^^^^^^^^^^^^
10+
| ^^^^^^^^^^^^^^^^^ no longer functions
1111
|
12-
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
13-
= help: `#![doc(no_default_passes)]` no longer functions; you may want to use `#![doc(document_private_items)]`
12+
= note: `doc` attribute `no_default_passes` no longer functions; see issue #44136 <https://github.com/rust-lang/rust/issues/44136>
13+
= help: you may want to use `doc(document_private_items)`
14+
= note: `doc(no_default_passes)` is now a no-op
15+
= note: `#[deny(invalid_doc_attributes)]` on by default
1416

15-
warning: the `#![doc(passes = "...")]` attribute is deprecated
16-
--> $DIR/deprecated-attrs.rs:9:8
17+
error: unknown `doc` attribute `passes`
18+
--> $DIR/deprecated-attrs.rs:11:8
1719
|
1820
LL | #![doc(passes = "collapse-docs unindent-comments")]
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no longer functions
2022
|
21-
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
22-
= help: `#![doc(passes = "...")]` no longer functions; you may want to use `#![doc(document_private_items)]`
23+
= note: `doc` attribute `passes` no longer functions; see issue #44136 <https://github.com/rust-lang/rust/issues/44136>
24+
= help: you may want to use `doc(document_private_items)`
25+
= note: `doc(passes)` is now a no-op
2326

24-
warning: the `#![doc(plugins = "...")]` attribute is deprecated
25-
--> $DIR/deprecated-attrs.rs:13:8
27+
error: unknown `doc` attribute `plugins`
28+
--> $DIR/deprecated-attrs.rs:17:8
2629
|
2730
LL | #![doc(plugins = "xxx")]
28-
| ^^^^^^^^^^^^^^^
31+
| ^^^^^^^^^^^^^^^ no longer functions
2932
|
30-
= note: see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information
31-
= warning: `#![doc(plugins = "...")]` no longer functions; see CVE-2018-1000622 <https://nvd.nist.gov/vuln/detail/CVE-2018-1000622>
33+
= 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>
34+
= note: `doc(plugins)` is now a no-op
3235

33-
warning: 3 warnings emitted
36+
error: aborting due to 3 previous errors
3437

0 commit comments

Comments
 (0)