Skip to content
Merged
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
24 changes: 14 additions & 10 deletions compiler/rustc_attr_parsing/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,16 +769,20 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError<'_> {
diag.note(format!("for more information, visit <{link}>"));
}

diag.span_suggestions(
self.attr_span,
if self.suggestions.len() == 1 {
"must be of the form".to_string()
} else {
format!("try changing it to one of the following valid forms of the {description}")
},
self.suggestions,
Applicability::HasPlaceholders,
);
if self.suggestions.len() < 4 {
diag.span_suggestions(
self.attr_span,
if self.suggestions.len() == 1 {
"must be of the form".to_string()
} else {
format!(
"try changing it to one of the following valid forms of the {description}"
)
},
self.suggestions,
Applicability::HasPlaceholders,
);
}

diag
}
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_attr_parsing/src/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ fn emit_malformed_attribute(
suggestions.push(format!("#{inner}[{name} = \"{descr}\"]"));
}
}
// If there are too many suggestions, better remove all of them as it's just noise at this
// point.
if suggestions.len() > 3 {
suggestions.clear();
}
if should_warn(name) {
psess.buffer_lint(
ILL_FORMED_ATTRIBUTE_INPUT,
Expand Down
144 changes: 0 additions & 144 deletions tests/rustdoc-ui/bad-render-options.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,6 @@ LL | #![doc(html_favicon_url)]
| ^^^^^^^----------------^^
| |
| expected this to be of the form `html_favicon_url = "..."`
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #![doc(html_favicon_url)]
LL + #![doc = "string"]
|
LL - #![doc(html_favicon_url)]
LL + #![doc(alias)]
|
LL - #![doc(html_favicon_url)]
LL + #![doc(attribute)]
|
LL - #![doc(html_favicon_url)]
LL + #![doc(auto_cfg)]
|
= and 21 other candidates

error[E0539]: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:6:1
Expand All @@ -29,22 +13,6 @@ LL | #![doc(html_logo_url)]
| ^^^^^^^-------------^^
| |
| expected this to be of the form `html_logo_url = "..."`
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #![doc(html_logo_url)]
LL + #![doc = "string"]
|
LL - #![doc(html_logo_url)]
LL + #![doc(alias)]
|
LL - #![doc(html_logo_url)]
LL + #![doc(attribute)]
|
LL - #![doc(html_logo_url)]
LL + #![doc(auto_cfg)]
|
= and 21 other candidates

error[E0539]: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:9:1
Expand All @@ -53,22 +21,6 @@ LL | #![doc(html_playground_url)]
| ^^^^^^^-------------------^^
| |
| expected this to be of the form `html_playground_url = "..."`
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #![doc(html_playground_url)]
LL + #![doc = "string"]
|
LL - #![doc(html_playground_url)]
LL + #![doc(alias)]
|
LL - #![doc(html_playground_url)]
LL + #![doc(attribute)]
|
LL - #![doc(html_playground_url)]
LL + #![doc(auto_cfg)]
|
= and 21 other candidates

error[E0539]: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:12:1
Expand All @@ -77,22 +29,6 @@ LL | #![doc(issue_tracker_base_url)]
| ^^^^^^^----------------------^^
| |
| expected this to be of the form `issue_tracker_base_url = "..."`
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #![doc(issue_tracker_base_url)]
LL + #![doc = "string"]
|
LL - #![doc(issue_tracker_base_url)]
LL + #![doc(alias)]
|
LL - #![doc(issue_tracker_base_url)]
LL + #![doc(attribute)]
|
LL - #![doc(issue_tracker_base_url)]
LL + #![doc(auto_cfg)]
|
= and 21 other candidates

error[E0539]: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:15:1
Expand All @@ -101,22 +37,6 @@ LL | #![doc(html_favicon_url = 1)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
| |
| expected a string literal here
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #![doc(html_favicon_url = 1)]
LL + #![doc = "string"]
|
LL - #![doc(html_favicon_url = 1)]
LL + #![doc(alias)]
|
LL - #![doc(html_favicon_url = 1)]
LL + #![doc(attribute)]
|
LL - #![doc(html_favicon_url = 1)]
LL + #![doc(auto_cfg)]
|
= and 22 other candidates

error[E0539]: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:18:1
Expand All @@ -125,22 +45,6 @@ LL | #![doc(html_logo_url = 2)]
| ^^^^^^^^^^^^^^^^^^^^^^^-^^
| |
| expected a string literal here
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #![doc(html_logo_url = 2)]
LL + #![doc = "string"]
|
LL - #![doc(html_logo_url = 2)]
LL + #![doc(alias)]
|
LL - #![doc(html_logo_url = 2)]
LL + #![doc(attribute)]
|
LL - #![doc(html_logo_url = 2)]
LL + #![doc(auto_cfg)]
|
= and 22 other candidates

error[E0539]: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:21:1
Expand All @@ -149,22 +53,6 @@ LL | #![doc(html_playground_url = 3)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
| |
| expected a string literal here
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #![doc(html_playground_url = 3)]
LL + #![doc = "string"]
|
LL - #![doc(html_playground_url = 3)]
LL + #![doc(alias)]
|
LL - #![doc(html_playground_url = 3)]
LL + #![doc(attribute)]
|
LL - #![doc(html_playground_url = 3)]
LL + #![doc(auto_cfg)]
|
= and 22 other candidates

error[E0539]: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:24:1
Expand All @@ -173,22 +61,6 @@ LL | #![doc(issue_tracker_base_url = 4)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
| |
| expected a string literal here
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #![doc(issue_tracker_base_url = 4)]
LL + #![doc = "string"]
|
LL - #![doc(issue_tracker_base_url = 4)]
LL + #![doc(alias)]
|
LL - #![doc(issue_tracker_base_url = 4)]
LL + #![doc(attribute)]
|
LL - #![doc(issue_tracker_base_url = 4)]
LL + #![doc(auto_cfg)]
|
= and 22 other candidates

error[E0565]: malformed `doc` attribute input
--> $DIR/bad-render-options.rs:27:1
Expand All @@ -197,22 +69,6 @@ LL | #![doc(html_no_source = "asdf")]
| ^^^^^^^^^^^^^^^^^^^^^^--------^^
| |
| didn't expect any arguments here
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #![doc(html_no_source = "asdf")]
LL + #![doc = "string"]
|
LL - #![doc(html_no_source = "asdf")]
LL + #![doc(alias)]
|
LL - #![doc(html_no_source = "asdf")]
LL + #![doc(attribute)]
|
LL - #![doc(html_no_source = "asdf")]
LL + #![doc(auto_cfg)]
|
= and 22 other candidates

error: aborting due to 9 previous errors

Expand Down
32 changes: 0 additions & 32 deletions tests/rustdoc-ui/check-doc-alias-attr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,6 @@ LL | #[doc(alias = 0)]
| ^^^^^^^^^^^^^^-^^
| |
| expected a string literal here
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #[doc(alias = 0)]
LL + #[doc = "string"]
|
LL - #[doc(alias = 0)]
LL + #[doc(alias)]
|
LL - #[doc(alias = 0)]
LL + #[doc(attribute)]
|
LL - #[doc(alias = 0)]
LL + #[doc(auto_cfg)]
|
= and 22 other candidates

error: '"' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:9:15
Expand Down Expand Up @@ -79,22 +63,6 @@ LL | #[doc(alias(0))]
| ^^^^^^^^^^^^-^^^
| |
| expected a string literal here
|
help: try changing it to one of the following valid forms of the attribute
|
LL - #[doc(alias(0))]
LL + #[doc = "string"]
|
LL - #[doc(alias(0))]
LL + #[doc(alias)]
|
LL - #[doc(alias(0))]
LL + #[doc(attribute)]
|
LL - #[doc(alias(0))]
LL + #[doc(auto_cfg)]
|
= and 22 other candidates

error: '"' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:20:13
Expand Down
Loading
Loading