Skip to content
Open
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
16 changes: 6 additions & 10 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::diagnostics::{
DocAutoCfgHideShowUnexpectedItem, DocAutoCfgHideShowUnexpectedItemAfterValues,
DocAutoCfgHideShowValuesMix, DocAutoCfgWrongLiteral, DocInlineConflict, DocInlineOnlyUse,
DocKeywordNotKeyword, DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny,
DocUnknownInclude, DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, ExpectedNameValue,
ExpectedNoArgs, IllFormedAttributeInput, MalformedDoc, UnusedDuplicate,
DocUnknownInclude, DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, ExpectedNoArgs,
IllFormedAttributeInput, MalformedDoc, UnusedDuplicate,
};
use crate::parser::{
ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser,
Expand Down Expand Up @@ -64,11 +64,6 @@ fn check_attr_not_crate_level(
true
}

// FIXME: To be removed once merged and replace with `cx.expected_name_value(span, _name)`.
fn expected_name_value(cx: &mut AcceptContext<'_, '_>, span: Span, _name: Option<Symbol>) {
cx.emit_lint(INVALID_DOC_ATTRIBUTES, ExpectedNameValue, span);
}

// FIXME: remove this method once merged and use `cx.expected_no_args(span)` instead.
fn expected_no_args(cx: &mut AcceptContext<'_, '_>, span: Span) {
cx.emit_lint(INVALID_DOC_ATTRIBUTES, ExpectedNoArgs, span);
Expand All @@ -92,7 +87,7 @@ fn parse_keyword_and_attribute(
attr_name: Symbol,
) {
let Some(nv) = args.as_name_value() else {
expected_name_value(cx, args.span().unwrap_or(path.span()), path.word_sym());
cx.adcx().expected_name_value(args.span().unwrap_or(path.span()), path.word_sym());
return;
};

Expand Down Expand Up @@ -555,7 +550,8 @@ impl DocParser {
macro_rules! string_arg_and_crate_level {
($ident: ident) => {{
let Some(nv) = args.as_name_value() else {
expected_name_value(cx, args.span().unwrap_or(path.span()), path.word_sym());
cx.adcx()
.expected_name_value(args.span().unwrap_or(path.span()), path.word_sym());
return;
};

Expand Down Expand Up @@ -733,7 +729,7 @@ impl DocParser {
self.parse_single_doc_attr_item(cx, mip);
}
MetaItemOrLitParser::Lit(lit) => {
expected_name_value(cx, lit.span, None);
cx.adcx().expected_name_value(lit.span, None);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,11 @@ impl<'a, 'f, 'sess: 'f> AttributeDiagnosticContext<'a, 'f, 'sess> {
/// Emit an error that a `name = value` pair was expected at this span. The symbol can be given for
/// a nicer error message talking about the specific name that was found lacking a value.
#[track_caller]
fn expected_name_value(&mut self, span: Span, name: Option<Symbol>) -> ErrorGuaranteed {
pub(crate) fn expected_name_value(
&mut self,
span: Span,
name: Option<Symbol>,
) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedNameValue(name))
}

Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_attr_parsing/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,6 @@ pub(crate) struct MalformedDoc;
)]
pub(crate) struct ExpectedNoArgs;

#[derive(Diagnostic)]
#[diag("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!"
)]
pub(crate) struct ExpectedNameValue;

#[derive(Diagnostic)]
#[diag("malformed `{$attribute}` attribute")]
#[help("{$options}")]
Expand Down
9 changes: 5 additions & 4 deletions tests/rustdoc-ui/bad-render-options.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// regression test for https://github.com/rust-lang/rust/issues/149187
#![deny(invalid_doc_attributes)]
//~^ NOTE

#![doc(html_favicon_url)]
//~^ ERROR
//~| WARN
//~| NOTE expected this to be of the form
#![doc(html_logo_url)]
//~^ ERROR
//~| WARN
//~| NOTE expected this to be of the form
#![doc(html_playground_url)]
//~^ ERROR
//~| WARN
//~| NOTE expected this to be of the form
#![doc(issue_tracker_base_url)]
//~^ ERROR
//~| WARN
//~| NOTE expected this to be of the form
#![doc(html_favicon_url = 1)]
//~^ ERROR
//~| WARN
Expand Down
61 changes: 31 additions & 30 deletions tests/rustdoc-ui/bad-render-options.stderr
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
error: expected this to be of the form `... = "..."`
--> $DIR/bad-render-options.rs:4:8
error[E0539]: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:5:4
|
LL | #![doc(html_favicon_url)]
| ^^^^^^^^^^^^^^^^
|
= 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/bad-render-options.rs:2:9
|
LL | #![deny(invalid_doc_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^
| ^^^^----------------^
| |
| expected this to be of the form `html_favicon_url = "..."`

error: expected this to be of the form `... = "..."`
--> $DIR/bad-render-options.rs:7:8
error[E0539]: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:8:4
|
LL | #![doc(html_logo_url)]
| ^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
| ^^^^-------------^
| |
| expected this to be of the form `html_logo_url = "..."`

error: expected this to be of the form `... = "..."`
--> $DIR/bad-render-options.rs:10:8
error[E0539]: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:11:4
|
LL | #![doc(html_playground_url)]
| ^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
| ^^^^-------------------^
| |
| expected this to be of the form `html_playground_url = "..."`

error: expected this to be of the form `... = "..."`
--> $DIR/bad-render-options.rs:13:8
error[E0539]: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:14:4
|
LL | #![doc(issue_tracker_base_url)]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
| ^^^^----------------------^
| |
| expected this to be of the form `issue_tracker_base_url = "..."`

error: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:16:27
--> $DIR/bad-render-options.rs:17:27
|
LL | #![doc(html_favicon_url = 1)]
| ^
|
= 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/bad-render-options.rs:2:9
|
LL | #![deny(invalid_doc_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^

error: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:19:24
--> $DIR/bad-render-options.rs:20:24
|
LL | #![doc(html_logo_url = 2)]
| ^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

error: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:22:30
--> $DIR/bad-render-options.rs:23:30
|
LL | #![doc(html_playground_url = 3)]
| ^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

error: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:25:33
--> $DIR/bad-render-options.rs:26:33
|
LL | #![doc(issue_tracker_base_url = 4)]
| ^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

error: didn't expect any arguments here
--> $DIR/bad-render-options.rs:28:23
--> $DIR/bad-render-options.rs:29:23
|
LL | #![doc(html_no_source = "asdf")]
| ^^^^^^^^
Expand All @@ -77,3 +77,4 @@ LL | #![doc(html_no_source = "asdf")]

error: aborting due to 9 previous errors

For more information about this error, try `rustc --explain E0539`.
3 changes: 0 additions & 3 deletions tests/rustdoc-ui/lints/doc-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

#[doc(123)]
//~^ ERROR
//~| WARN
#[doc("hello", "bar")]
//~^ ERROR
//~| ERROR
//~| WARN
//~| WARN
fn bar() {}
36 changes: 16 additions & 20 deletions tests/rustdoc-ui/lints/doc-attr.stderr
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
error: expected this to be of the form `... = "..."`
--> $DIR/doc-attr.rs:4:7
error[E0539]: malformed `doc` attribute input
--> $DIR/doc-attr.rs:4:3
|
LL | #[doc(123)]
| ^^^
|
= 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)]
| ^^^^^^^^^^^^^^^^^^^^^^
| ^^^^---^
| |
| expected this to be of the form `... = "..."`

error: expected this to be of the form `... = "..."`
--> $DIR/doc-attr.rs:7:7
error[E0539]: malformed `doc` attribute input
--> $DIR/doc-attr.rs:6:3
|
LL | #[doc("hello", "bar")]
| ^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
| ^^^^-------^^^^^^^^
| |
| expected this to be of the form `... = "..."`

error: expected this to be of the form `... = "..."`
--> $DIR/doc-attr.rs:7:16
error[E0539]: malformed `doc` attribute input
--> $DIR/doc-attr.rs:6:3
|
LL | #[doc("hello", "bar")]
| ^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
| ^^^^^^^^^^^^^-----^
| |
| expected this to be of the form `... = "..."`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0539`.
1 change: 0 additions & 1 deletion tests/rustdoc-ui/lints/invalid-doc-attr-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

#![doc("other attribute")]
//~^ ERROR
//~| WARN
#![doc]
//~^ ERROR
22 changes: 12 additions & 10 deletions tests/rustdoc-ui/lints/invalid-doc-attr-2.stderr
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
error: expected this to be of the form `... = "..."`
--> $DIR/invalid-doc-attr-2.rs:3:8
error[E0539]: malformed `doc` attribute input
--> $DIR/invalid-doc-attr-2.rs:3:4
|
LL | #![doc("other attribute")]
| ^^^^^^^^^^^^^^^^^
| ^^^^-----------------^
| |
| expected this to be of the form `... = "..."`

error: valid forms for the attribute are `doc = "doc comment"`, `doc(alias)`, `doc(auto_cfg)`, `doc(cfg)`, `doc(hidden)`, `doc(html_favicon_url)`, `doc(html_logo_url)`, `doc(html_no_source)`, `doc(html_playground_url)`, `doc(html_root_url)`, `doc(inline)`, `doc(issue_tracker_base_url)`, `doc(masked)`, `doc(no_inline)`, `doc(notable_trait)`, and `doc(test)`
--> $DIR/invalid-doc-attr-2.rs:5:4
|
LL | #![doc]
| ^^^
|
= 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 = "doc comment"`, `doc(alias)`, `doc(auto_cfg)`, `doc(cfg)`, `doc(hidden)`, `doc(html_favicon_url)`, `doc(html_logo_url)`, `doc(html_no_source)`, `doc(html_playground_url)`, `doc(html_root_url)`, `doc(inline)`, `doc(issue_tracker_base_url)`, `doc(masked)`, `doc(no_inline)`, `doc(notable_trait)`, and `doc(test)`
--> $DIR/invalid-doc-attr-2.rs:6:4
|
LL | #![doc]
| ^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0539`.
Loading