Skip to content

Commit 1bdf820

Browse files
Rollup merge of rust-lang#149917 - GuillaumeGomez:malformed-attribute-suggestions, r=JonathanBrouwer
If there are too many suggestions for malformed attribute, do not suggest them Part of rust-lang#149865. This not only covers for doc attributes but for all attributes, so don't hesitate to tell me if you want it to be limited to only doc attributes (although I think it's actually a nice improvement overall). Also, I picked 3 as the maximum number of suggestions before it becomes noise, but it's very much open to debate. r? `@JonathanBrouwer`
2 parents 7c778ca + d025cde commit 1bdf820

32 files changed

+19
-1425
lines changed

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -709,16 +709,20 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError<'_> {
709709
diag.note(format!("for more information, visit <{link}>"));
710710
}
711711

712-
diag.span_suggestions(
713-
self.attr_span,
714-
if self.suggestions.len() == 1 {
715-
"must be of the form".to_string()
716-
} else {
717-
format!("try changing it to one of the following valid forms of the {description}")
718-
},
719-
self.suggestions,
720-
Applicability::HasPlaceholders,
721-
);
712+
if self.suggestions.len() < 4 {
713+
diag.span_suggestions(
714+
self.attr_span,
715+
if self.suggestions.len() == 1 {
716+
"must be of the form".to_string()
717+
} else {
718+
format!(
719+
"try changing it to one of the following valid forms of the {description}"
720+
)
721+
},
722+
self.suggestions,
723+
Applicability::HasPlaceholders,
724+
);
725+
}
722726

723727
diag
724728
}

compiler/rustc_attr_parsing/src/validate_attr.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ fn emit_malformed_attribute(
198198
suggestions.push(format!("#{inner}[{name} = \"{descr}\"]"));
199199
}
200200
}
201+
// If there are too many suggestions, better remove all of them as it's just noise at this
202+
// point.
203+
if suggestions.len() > 3 {
204+
suggestions.clear();
205+
}
201206
if should_warn(name) {
202207
psess.buffer_lint(
203208
ILL_FORMED_ATTRIBUTE_INPUT,

tests/rustdoc-ui/bad-render-options.stderr

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,6 @@ LL | #![doc(html_favicon_url)]
55
| ^^^^^^^----------------^^
66
| |
77
| expected this to be of the form `html_favicon_url = "..."`
8-
|
9-
help: try changing it to one of the following valid forms of the attribute
10-
|
11-
LL - #![doc(html_favicon_url)]
12-
LL + #![doc = "string"]
13-
|
14-
LL - #![doc(html_favicon_url)]
15-
LL + #![doc(alias)]
16-
|
17-
LL - #![doc(html_favicon_url)]
18-
LL + #![doc(attribute)]
19-
|
20-
LL - #![doc(html_favicon_url)]
21-
LL + #![doc(auto_cfg)]
22-
|
23-
= and 21 other candidates
248

259
error[E0539]: malformed `doc` attribute input
2610
--> $DIR/bad-render-options.rs:6:1
@@ -29,22 +13,6 @@ LL | #![doc(html_logo_url)]
2913
| ^^^^^^^-------------^^
3014
| |
3115
| expected this to be of the form `html_logo_url = "..."`
32-
|
33-
help: try changing it to one of the following valid forms of the attribute
34-
|
35-
LL - #![doc(html_logo_url)]
36-
LL + #![doc = "string"]
37-
|
38-
LL - #![doc(html_logo_url)]
39-
LL + #![doc(alias)]
40-
|
41-
LL - #![doc(html_logo_url)]
42-
LL + #![doc(attribute)]
43-
|
44-
LL - #![doc(html_logo_url)]
45-
LL + #![doc(auto_cfg)]
46-
|
47-
= and 21 other candidates
4816

4917
error[E0539]: malformed `doc` attribute input
5018
--> $DIR/bad-render-options.rs:9:1
@@ -53,22 +21,6 @@ LL | #![doc(html_playground_url)]
5321
| ^^^^^^^-------------------^^
5422
| |
5523
| expected this to be of the form `html_playground_url = "..."`
56-
|
57-
help: try changing it to one of the following valid forms of the attribute
58-
|
59-
LL - #![doc(html_playground_url)]
60-
LL + #![doc = "string"]
61-
|
62-
LL - #![doc(html_playground_url)]
63-
LL + #![doc(alias)]
64-
|
65-
LL - #![doc(html_playground_url)]
66-
LL + #![doc(attribute)]
67-
|
68-
LL - #![doc(html_playground_url)]
69-
LL + #![doc(auto_cfg)]
70-
|
71-
= and 21 other candidates
7224

7325
error[E0539]: malformed `doc` attribute input
7426
--> $DIR/bad-render-options.rs:12:1
@@ -77,22 +29,6 @@ LL | #![doc(issue_tracker_base_url)]
7729
| ^^^^^^^----------------------^^
7830
| |
7931
| expected this to be of the form `issue_tracker_base_url = "..."`
80-
|
81-
help: try changing it to one of the following valid forms of the attribute
82-
|
83-
LL - #![doc(issue_tracker_base_url)]
84-
LL + #![doc = "string"]
85-
|
86-
LL - #![doc(issue_tracker_base_url)]
87-
LL + #![doc(alias)]
88-
|
89-
LL - #![doc(issue_tracker_base_url)]
90-
LL + #![doc(attribute)]
91-
|
92-
LL - #![doc(issue_tracker_base_url)]
93-
LL + #![doc(auto_cfg)]
94-
|
95-
= and 21 other candidates
9632

9733
error[E0539]: malformed `doc` attribute input
9834
--> $DIR/bad-render-options.rs:15:1
@@ -101,22 +37,6 @@ LL | #![doc(html_favicon_url = 1)]
10137
| ^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
10238
| |
10339
| expected a string literal here
104-
|
105-
help: try changing it to one of the following valid forms of the attribute
106-
|
107-
LL - #![doc(html_favicon_url = 1)]
108-
LL + #![doc = "string"]
109-
|
110-
LL - #![doc(html_favicon_url = 1)]
111-
LL + #![doc(alias)]
112-
|
113-
LL - #![doc(html_favicon_url = 1)]
114-
LL + #![doc(attribute)]
115-
|
116-
LL - #![doc(html_favicon_url = 1)]
117-
LL + #![doc(auto_cfg)]
118-
|
119-
= and 22 other candidates
12040

12141
error[E0539]: malformed `doc` attribute input
12242
--> $DIR/bad-render-options.rs:18:1
@@ -125,22 +45,6 @@ LL | #![doc(html_logo_url = 2)]
12545
| ^^^^^^^^^^^^^^^^^^^^^^^-^^
12646
| |
12747
| expected a string literal here
128-
|
129-
help: try changing it to one of the following valid forms of the attribute
130-
|
131-
LL - #![doc(html_logo_url = 2)]
132-
LL + #![doc = "string"]
133-
|
134-
LL - #![doc(html_logo_url = 2)]
135-
LL + #![doc(alias)]
136-
|
137-
LL - #![doc(html_logo_url = 2)]
138-
LL + #![doc(attribute)]
139-
|
140-
LL - #![doc(html_logo_url = 2)]
141-
LL + #![doc(auto_cfg)]
142-
|
143-
= and 22 other candidates
14448

14549
error[E0539]: malformed `doc` attribute input
14650
--> $DIR/bad-render-options.rs:21:1
@@ -149,22 +53,6 @@ LL | #![doc(html_playground_url = 3)]
14953
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
15054
| |
15155
| expected a string literal here
152-
|
153-
help: try changing it to one of the following valid forms of the attribute
154-
|
155-
LL - #![doc(html_playground_url = 3)]
156-
LL + #![doc = "string"]
157-
|
158-
LL - #![doc(html_playground_url = 3)]
159-
LL + #![doc(alias)]
160-
|
161-
LL - #![doc(html_playground_url = 3)]
162-
LL + #![doc(attribute)]
163-
|
164-
LL - #![doc(html_playground_url = 3)]
165-
LL + #![doc(auto_cfg)]
166-
|
167-
= and 22 other candidates
16856

16957
error[E0539]: malformed `doc` attribute input
17058
--> $DIR/bad-render-options.rs:24:1
@@ -173,22 +61,6 @@ LL | #![doc(issue_tracker_base_url = 4)]
17361
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
17462
| |
17563
| expected a string literal here
176-
|
177-
help: try changing it to one of the following valid forms of the attribute
178-
|
179-
LL - #![doc(issue_tracker_base_url = 4)]
180-
LL + #![doc = "string"]
181-
|
182-
LL - #![doc(issue_tracker_base_url = 4)]
183-
LL + #![doc(alias)]
184-
|
185-
LL - #![doc(issue_tracker_base_url = 4)]
186-
LL + #![doc(attribute)]
187-
|
188-
LL - #![doc(issue_tracker_base_url = 4)]
189-
LL + #![doc(auto_cfg)]
190-
|
191-
= and 22 other candidates
19264

19365
error[E0565]: malformed `doc` attribute input
19466
--> $DIR/bad-render-options.rs:27:1
@@ -197,22 +69,6 @@ LL | #![doc(html_no_source = "asdf")]
19769
| ^^^^^^^^^^^^^^^^^^^^^^--------^^
19870
| |
19971
| didn't expect any arguments here
200-
|
201-
help: try changing it to one of the following valid forms of the attribute
202-
|
203-
LL - #![doc(html_no_source = "asdf")]
204-
LL + #![doc = "string"]
205-
|
206-
LL - #![doc(html_no_source = "asdf")]
207-
LL + #![doc(alias)]
208-
|
209-
LL - #![doc(html_no_source = "asdf")]
210-
LL + #![doc(attribute)]
211-
|
212-
LL - #![doc(html_no_source = "asdf")]
213-
LL + #![doc(auto_cfg)]
214-
|
215-
= and 22 other candidates
21672

21773
error: aborting due to 9 previous errors
21874

tests/rustdoc-ui/check-doc-alias-attr.stderr

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@ LL | #[doc(alias = 0)]
1111
| ^^^^^^^^^^^^^^-^^
1212
| |
1313
| expected a string literal here
14-
|
15-
help: try changing it to one of the following valid forms of the attribute
16-
|
17-
LL - #[doc(alias = 0)]
18-
LL + #[doc = "string"]
19-
|
20-
LL - #[doc(alias = 0)]
21-
LL + #[doc(alias)]
22-
|
23-
LL - #[doc(alias = 0)]
24-
LL + #[doc(attribute)]
25-
|
26-
LL - #[doc(alias = 0)]
27-
LL + #[doc(auto_cfg)]
28-
|
29-
= and 22 other candidates
3014

3115
error: '"' character isn't allowed in `#[doc(alias = "...")]`
3216
--> $DIR/check-doc-alias-attr.rs:9:15
@@ -79,22 +63,6 @@ LL | #[doc(alias(0))]
7963
| ^^^^^^^^^^^^-^^^
8064
| |
8165
| expected a string literal here
82-
|
83-
help: try changing it to one of the following valid forms of the attribute
84-
|
85-
LL - #[doc(alias(0))]
86-
LL + #[doc = "string"]
87-
|
88-
LL - #[doc(alias(0))]
89-
LL + #[doc(alias)]
90-
|
91-
LL - #[doc(alias(0))]
92-
LL + #[doc(attribute)]
93-
|
94-
LL - #[doc(alias(0))]
95-
LL + #[doc(auto_cfg)]
96-
|
97-
= and 22 other candidates
9866

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

0 commit comments

Comments
 (0)