Skip to content

Commit 6d71348

Browse files
Make more doc attribute parsing error into future warnings
1 parent 7dbbab6 commit 6d71348

9 files changed

Lines changed: 80 additions & 19 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl DocParser {
591591
let suggestions = cx.suggestions();
592592
let span = cx.attr_span;
593593
cx.emit_lint(
594-
rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT,
594+
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
595595
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
596596
span,
597597
);
@@ -604,14 +604,27 @@ impl DocParser {
604604
self.parse_single_doc_attr_item(cx, mip);
605605
}
606606
MetaItemOrLitParser::Lit(lit) => {
607-
cx.expected_name_value(lit.span, None);
607+
// FIXME: Remove the lint and uncomment line after beta backport is
608+
// done.
609+
// cx.expected_name_value(lit.span, None);
610+
cx.emit_lint(
611+
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
612+
AttributeLintKind::MalformedDoc,
613+
lit.span,
614+
);
608615
}
609616
}
610617
}
611618
}
612619
ArgParser::NameValue(nv) => {
613620
if nv.value_as_str().is_none() {
614-
cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
621+
// FIXME: Remove the lint and uncomment line after beta backport is done.
622+
// cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
623+
cx.emit_lint(
624+
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
625+
AttributeLintKind::MalformedDoc,
626+
nv.value_span,
627+
);
615628
} else {
616629
unreachable!(
617630
"Should have been handled at the same time as sugar-syntaxed doc comments"

compiler/rustc_lint/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,10 @@ lint_macro_expr_fragment_specifier_2024_migration =
558558
559559
lint_malformed_attribute = malformed lint attribute input
560560
561+
lint_malformed_doc =
562+
malformed `doc` attribute input
563+
.warn = {-lint_previously_accepted}
564+
561565
lint_map_unit_fn = `Iterator::map` call that discard the iterator's values
562566
.note = `Iterator::map`, like many of the methods on `Iterator`, gets executed lazily, meaning that its effects won't be visible until it is iterated
563567
.function_label = this function returns `()`, which is likely not what you wanted

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,5 +428,7 @@ pub fn decorate_attribute_lint(
428428
sugg: suggested.map(|s| lints::UnknownCrateTypesSuggestion { span, snippet: s }),
429429
}
430430
.decorate_lint(diag),
431+
432+
&AttributeLintKind::MalformedDoc => lints::MalformedDoc.decorate_lint(diag),
431433
}
432434
}

compiler/rustc_lint/src/lints.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,6 +3185,11 @@ pub(crate) struct UnusedDuplicate {
31853185
pub warning: bool,
31863186
}
31873187

3188+
#[derive(LintDiagnostic)]
3189+
#[diag(lint_malformed_doc)]
3190+
#[warning]
3191+
pub(crate) struct MalformedDoc;
3192+
31883193
#[derive(LintDiagnostic)]
31893194
#[diag(lint_unsafe_attr_outside_unsafe)]
31903195
pub(crate) struct UnsafeAttrOutsideUnsafeLint {

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ pub enum AttributeLintKind {
826826
span: Span,
827827
suggested: Option<Symbol>,
828828
},
829+
MalformedDoc,
829830
}
830831

831832
pub type RegisteredTools = FxIndexSet<Ident>;

tests/rustdoc-ui/lints/doc-attr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#![crate_type = "lib"]
2+
#![deny(invalid_doc_attributes)]
23

34
#[doc(123)]
45
//~^ ERROR malformed `doc` attribute
6+
//~| WARN
57
#[doc("hello", "bar")]
68
//~^ ERROR malformed `doc` attribute
79
//~| ERROR malformed `doc` attribute
10+
//~| WARN
11+
//~| WARN
812
fn bar() {}

tests/rustdoc-ui/lints/doc-attr.stderr

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
error[E0539]: malformed `doc` attribute input
2-
--> $DIR/doc-attr.rs:3:1
1+
error: malformed `doc` attribute input
2+
--> $DIR/doc-attr.rs:4:7
33
|
44
LL | #[doc(123)]
5-
| ^^^^^^---^^
6-
| |
7-
| expected this to be of the form `... = "..."`
5+
| ^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
note: the lint level is defined here
9+
--> $DIR/doc-attr.rs:2:9
10+
|
11+
LL | #![deny(invalid_doc_attributes)]
12+
| ^^^^^^^^^^^^^^^^^^^^^^
813

9-
error[E0539]: malformed `doc` attribute input
10-
--> $DIR/doc-attr.rs:5:1
14+
error: malformed `doc` attribute input
15+
--> $DIR/doc-attr.rs:7:7
1116
|
1217
LL | #[doc("hello", "bar")]
13-
| ^^^^^^-------^^^^^^^^^
14-
| |
15-
| expected this to be of the form `... = "..."`
18+
| ^^^^^^^
19+
|
20+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1621

17-
error[E0539]: malformed `doc` attribute input
18-
--> $DIR/doc-attr.rs:5:1
22+
error: malformed `doc` attribute input
23+
--> $DIR/doc-attr.rs:7:16
1924
|
2025
LL | #[doc("hello", "bar")]
21-
| ^^^^^^^^^^^^^^^-----^^
22-
| |
23-
| expected this to be of the form `... = "..."`
26+
| ^^^^^
27+
|
28+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2429

2530
error: aborting due to 3 previous errors
2631

27-
For more information about this error, try `rustc --explain E0539`.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![deny(invalid_doc_attributes)]
2+
3+
#![doc("other attribute")]
4+
//~^ ERROR
5+
//~| WARN
6+
#![doc]
7+
//~^ ERROR
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: malformed `doc` attribute input
2+
--> $DIR/invalid-doc-attr-2.rs:3:8
3+
|
4+
LL | #![doc("other attribute")]
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
note: the lint level is defined here
9+
--> $DIR/invalid-doc-attr-2.rs:1:9
10+
|
11+
LL | #![deny(invalid_doc_attributes)]
12+
| ^^^^^^^^^^^^^^^^^^^^^^
13+
14+
error: valid forms for the attribute are `#![doc = "string"]`, `#![doc(alias)]`, `#![doc(attribute)]`, `#![doc(auto_cfg)]`, `#![doc(cfg)]`, `#![doc(fake_variadic)]`, `#![doc(hidden)]`, `#![doc(html_favicon_url)]`, `#![doc(html_logo_url)]`, `#![doc(html_no_source)]`, `#![doc(html_playground_url)]`, `#![doc(html_root_url)]`, `#![doc(include)]`, `#![doc(inline)]`, `#![doc(issue_tracker_base_url)]`, `#![doc(keyword)]`, `#![doc(masked)]`, `#![doc(no_default_passes)]`, `#![doc(no_inline)]`, `#![doc(notable_trait)]`, `#![doc(passes)]`, `#![doc(plugins)]`, `#![doc(rust_logo)]`, `#![doc(search_unbox)]`, `#![doc(spotlight)]`, and `#![doc(test)]`
15+
--> $DIR/invalid-doc-attr-2.rs:6:1
16+
|
17+
LL | #![doc]
18+
| ^^^^^^^
19+
20+
error: aborting due to 2 previous errors
21+

0 commit comments

Comments
 (0)