Make more doc attribute parsing error into future warnings
This commit is contained in:
parent
7dbbab63e2
commit
6d713489d0
9 changed files with 80 additions and 19 deletions
|
|
@ -591,7 +591,7 @@ impl DocParser {
|
|||
let suggestions = cx.suggestions();
|
||||
let span = cx.attr_span;
|
||||
cx.emit_lint(
|
||||
rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT,
|
||||
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
|
||||
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
|
||||
span,
|
||||
);
|
||||
|
|
@ -604,14 +604,27 @@ impl DocParser {
|
|||
self.parse_single_doc_attr_item(cx, mip);
|
||||
}
|
||||
MetaItemOrLitParser::Lit(lit) => {
|
||||
cx.expected_name_value(lit.span, None);
|
||||
// FIXME: Remove the lint and uncomment line after beta backport is
|
||||
// done.
|
||||
// cx.expected_name_value(lit.span, None);
|
||||
cx.emit_lint(
|
||||
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
|
||||
AttributeLintKind::MalformedDoc,
|
||||
lit.span,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ArgParser::NameValue(nv) => {
|
||||
if nv.value_as_str().is_none() {
|
||||
cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
|
||||
// FIXME: Remove the lint and uncomment line after beta backport is done.
|
||||
// cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
|
||||
cx.emit_lint(
|
||||
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
|
||||
AttributeLintKind::MalformedDoc,
|
||||
nv.value_span,
|
||||
);
|
||||
} else {
|
||||
unreachable!(
|
||||
"Should have been handled at the same time as sugar-syntaxed doc comments"
|
||||
|
|
|
|||
|
|
@ -558,6 +558,10 @@ lint_macro_expr_fragment_specifier_2024_migration =
|
|||
|
||||
lint_malformed_attribute = malformed lint attribute input
|
||||
|
||||
lint_malformed_doc =
|
||||
malformed `doc` attribute input
|
||||
.warn = {-lint_previously_accepted}
|
||||
|
||||
lint_map_unit_fn = `Iterator::map` call that discard the iterator's values
|
||||
.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
|
||||
.function_label = this function returns `()`, which is likely not what you wanted
|
||||
|
|
|
|||
|
|
@ -428,5 +428,7 @@ pub fn decorate_attribute_lint(
|
|||
sugg: suggested.map(|s| lints::UnknownCrateTypesSuggestion { span, snippet: s }),
|
||||
}
|
||||
.decorate_lint(diag),
|
||||
|
||||
&AttributeLintKind::MalformedDoc => lints::MalformedDoc.decorate_lint(diag),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3185,6 +3185,11 @@ pub(crate) struct UnusedDuplicate {
|
|||
pub warning: bool,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_malformed_doc)]
|
||||
#[warning]
|
||||
pub(crate) struct MalformedDoc;
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_unsafe_attr_outside_unsafe)]
|
||||
pub(crate) struct UnsafeAttrOutsideUnsafeLint {
|
||||
|
|
|
|||
|
|
@ -826,6 +826,7 @@ pub enum AttributeLintKind {
|
|||
span: Span,
|
||||
suggested: Option<Symbol>,
|
||||
},
|
||||
MalformedDoc,
|
||||
}
|
||||
|
||||
pub type RegisteredTools = FxIndexSet<Ident>;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
#![crate_type = "lib"]
|
||||
#![deny(invalid_doc_attributes)]
|
||||
|
||||
#[doc(123)]
|
||||
//~^ ERROR malformed `doc` attribute
|
||||
//~| WARN
|
||||
#[doc("hello", "bar")]
|
||||
//~^ ERROR malformed `doc` attribute
|
||||
//~| ERROR malformed `doc` attribute
|
||||
//~| WARN
|
||||
//~| WARN
|
||||
fn bar() {}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,31 @@
|
|||
error[E0539]: malformed `doc` attribute input
|
||||
--> $DIR/doc-attr.rs:3:1
|
||||
error: malformed `doc` attribute input
|
||||
--> $DIR/doc-attr.rs:4:7
|
||||
|
|
||||
LL | #[doc(123)]
|
||||
| ^^^^^^---^^
|
||||
| |
|
||||
| expected this to be of the form `... = "..."`
|
||||
| ^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
note: the lint level is defined here
|
||||
--> $DIR/doc-attr.rs:2:9
|
||||
|
|
||||
LL | #![deny(invalid_doc_attributes)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0539]: malformed `doc` attribute input
|
||||
--> $DIR/doc-attr.rs:5:1
|
||||
error: malformed `doc` attribute input
|
||||
--> $DIR/doc-attr.rs:7:7
|
||||
|
|
||||
LL | #[doc("hello", "bar")]
|
||||
| ^^^^^^-------^^^^^^^^^
|
||||
| |
|
||||
| expected this to be of the form `... = "..."`
|
||||
| ^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
|
||||
error[E0539]: malformed `doc` attribute input
|
||||
--> $DIR/doc-attr.rs:5:1
|
||||
error: malformed `doc` attribute input
|
||||
--> $DIR/doc-attr.rs:7:16
|
||||
|
|
||||
LL | #[doc("hello", "bar")]
|
||||
| ^^^^^^^^^^^^^^^-----^^
|
||||
| |
|
||||
| expected this to be of the form `... = "..."`
|
||||
| ^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0539`.
|
||||
|
|
|
|||
7
tests/rustdoc-ui/lints/invalid-doc-attr-2.rs
Normal file
7
tests/rustdoc-ui/lints/invalid-doc-attr-2.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#![deny(invalid_doc_attributes)]
|
||||
|
||||
#![doc("other attribute")]
|
||||
//~^ ERROR
|
||||
//~| WARN
|
||||
#![doc]
|
||||
//~^ ERROR
|
||||
21
tests/rustdoc-ui/lints/invalid-doc-attr-2.stderr
Normal file
21
tests/rustdoc-ui/lints/invalid-doc-attr-2.stderr
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
error: malformed `doc` attribute input
|
||||
--> $DIR/invalid-doc-attr-2.rs:3:8
|
||||
|
|
||||
LL | #![doc("other attribute")]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
note: the lint level is defined here
|
||||
--> $DIR/invalid-doc-attr-2.rs:1:9
|
||||
|
|
||||
LL | #![deny(invalid_doc_attributes)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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)]`
|
||||
--> $DIR/invalid-doc-attr-2.rs:6:1
|
||||
|
|
||||
LL | #![doc]
|
||||
| ^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue