Skip to content

Commit d11a970

Browse files
committed
Add doc(plugins), doc(passes), etc. to INVALID_DOC_ATTRIBUTES
1 parent 785c830 commit d11a970

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
@@ -1187,15 +1187,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11871187

11881188
sym::masked => self.check_doc_masked(attr, meta, hir_id, target),
11891189

1190-
// no_default_passes: deprecated
1191-
// passes: deprecated
1192-
// plugins: removed, but rustdoc warns about it itself
1193-
sym::cfg
1194-
| sym::hidden
1195-
| sym::no_default_passes
1196-
| sym::notable_trait
1197-
| sym::passes
1198-
| sym::plugins => {}
1190+
sym::cfg | sym::hidden | sym::notable_trait => {}
11991191

12001192
sym::rust_logo => {
12011193
if self.check_attr_crate_level(attr, meta, hir_id)
@@ -1244,6 +1236,22 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12441236
sugg: (attr.meta().unwrap().span, applicability),
12451237
},
12461238
);
1239+
} else if i_meta.has_name(sym::passes)
1240+
|| i_meta.has_name(sym::no_default_passes)
1241+
{
1242+
self.tcx.emit_node_span_lint(
1243+
INVALID_DOC_ATTRIBUTES,
1244+
hir_id,
1245+
i_meta.span,
1246+
errors::DocTestUnknownPasses { path, span: i_meta.span },
1247+
);
1248+
} else if i_meta.has_name(sym::plugins) {
1249+
self.tcx.emit_node_span_lint(
1250+
INVALID_DOC_ATTRIBUTES,
1251+
hir_id,
1252+
i_meta.span,
1253+
errors::DocTestUnknownPlugins { path, span: i_meta.span },
1254+
);
12471255
} else {
12481256
self.tcx.emit_node_span_lint(
12491257
INVALID_DOC_ATTRIBUTES,

compiler/rustc_passes/src/errors.rs

+21
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,27 @@ pub(crate) struct DocTestUnknownSpotlight {
317317
pub span: Span,
318318
}
319319

320+
#[derive(LintDiagnostic)]
321+
#[diag(passes_doc_test_unknown_passes)]
322+
#[note]
323+
#[help]
324+
#[note(passes_no_op_note)]
325+
pub(crate) struct DocTestUnknownPasses {
326+
pub path: String,
327+
#[label]
328+
pub span: Span,
329+
}
330+
331+
#[derive(LintDiagnostic)]
332+
#[diag(passes_doc_test_unknown_plugins)]
333+
#[note]
334+
#[note(passes_no_op_note)]
335+
pub(crate) struct DocTestUnknownPlugins {
336+
pub path: String,
337+
#[label]
338+
pub span: Span,
339+
}
340+
320341
#[derive(LintDiagnostic)]
321342
#[diag(passes_doc_test_unknown_include)]
322343
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;
@@ -380,45 +380,10 @@ pub(crate) fn run_global_ctxt(
380380
);
381381
}
382382

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

423388
if attr.is_word() && name == sym::document_private_items {
424389
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)