Skip to content

Commit f0de7df

Browse files
committed
macros: update session diagnostic errors
Small commit adding backticks around types and annotations in the error messages from the session diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
1 parent a52b507 commit f0de7df

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

compiler/rustc_macros/src/session_diagnostic.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
224224
match builder.kind {
225225
None => {
226226
span_err(ast.span().unwrap(), "`code` not specified")
227-
.help("use the [code = \"...\"] attribute to set this diagnostic's error code ")
227+
.help("use the `#[code = \"...\"]` attribute to set this diagnostic's error code ")
228228
.emit();
229229
SessionDiagnosticDeriveError::ErrorHandled.to_compile_error()
230230
}
@@ -338,7 +338,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
338338
other => throw_span_err!(
339339
attr.span().unwrap(),
340340
&format!(
341-
"`#[{} = ...]` is not a valid SessionDiagnostic struct attribute",
341+
"`#[{} = ...]` is not a valid `SessionDiagnostic` struct attribute",
342342
other
343343
)
344344
),
@@ -429,7 +429,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
429429
} else {
430430
throw_span_err!(
431431
attr.span().unwrap(),
432-
"the `#[message = \"...\"]` attribute can only be applied to fields of type Span"
432+
"the `#[message = \"...\"]` attribute can only be applied to fields of type `Span`"
433433
);
434434
}
435435
}
@@ -441,14 +441,14 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
441441
} else {
442442
throw_span_err!(
443443
attr.span().unwrap(),
444-
"The `#[label = ...]` attribute can only be applied to fields of type Span"
444+
"The `#[label = ...]` attribute can only be applied to fields of type `Span`"
445445
);
446446
}
447447
}
448448
other => throw_span_err!(
449449
attr.span().unwrap(),
450450
&format!(
451-
"`#[{} = ...]` is not a valid SessionDiagnostic field attribute",
451+
"`#[{} = ...]` is not a valid `SessionDiagnostic` field attribute",
452452
other
453453
)
454454
),
@@ -505,7 +505,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
505505
list.span().unwrap(),
506506
"missing suggestion message",
507507
|diag| {
508-
diag.help("provide a suggestion message using #[suggestion(message = \"...\")]")
508+
diag.help("provide a suggestion message using `#[suggestion(message = \"...\")]`")
509509
}
510510
);
511511
};
@@ -549,7 +549,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
549549
} else {
550550
throw_span_err!(
551551
info.span.unwrap(),
552-
"type of field annotated with `#[suggestion(...)]` contains more than one Span"
552+
"type of field annotated with `#[suggestion(...)]` contains more than one `Span`"
553553
);
554554
}
555555
} else if type_matches_path(elem, &["rustc_errors", "Applicability"]) {
@@ -575,12 +575,12 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
575575
}
576576

577577
throw_span_err!(info.span.unwrap(), "wrong types for suggestion", |diag| {
578-
diag.help("#[suggestion(...)] on a tuple field must be applied to fields of type `(Span, Applicability)`")
578+
diag.help("`#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)`")
579579
});
580580
}
581581
// If `ty` isn't a `Span` or `(Span, Applicability)` then emit an error.
582582
_ => throw_span_err!(info.span.unwrap(), "wrong field type for suggestion", |diag| {
583-
diag.help("#[suggestion(...)] should be applied to fields of type `Span` or `(Span, Applicability)`")
583+
diag.help("`#[suggestion(...)]` should be applied to fields of type `Span` or `(Span, Applicability)`")
584584
}),
585585
}
586586
}

src/test/ui-fulldeps/session-derive-errors.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ enum SessionDiagnosticOnEnum {
4141
#[derive(SessionDiagnostic)]
4242
#[error = "E0123"]
4343
#[label = "This is in the wrong place"]
44-
//~^ ERROR `#[label = ...]` is not a valid SessionDiagnostic struct attribute
44+
//~^ ERROR `#[label = ...]` is not a valid `SessionDiagnostic` struct attribute
4545
struct WrongPlace {}
4646

4747
#[derive(SessionDiagnostic)]
4848
#[error = "E0123"]
4949
struct WrongPlaceField {
5050
#[suggestion = "this is the wrong kind of attribute"]
51-
//~^ ERROR `#[suggestion = ...]` is not a valid SessionDiagnostic field attribute
51+
//~^ ERROR `#[suggestion = ...]` is not a valid `SessionDiagnostic` field attribute
5252
sp: Span,
5353
}
5454

@@ -92,14 +92,14 @@ struct ErrorSpecifiedAfterLint {}
9292
struct ErrorWithField {
9393
name: String,
9494
#[message = "This error has a field, and references {name}"]
95-
span: Span
95+
span: Span,
9696
}
9797

9898
#[derive(SessionDiagnostic)]
9999
#[error = "E0123"]
100100
struct ErrorWithMessageAppliedToField {
101101
#[message = "this message is applied to a String field"]
102-
//~^ ERROR the `#[message = "..."]` attribute can only be applied to fields of type Span
102+
//~^ ERROR the `#[message = "..."]` attribute can only be applied to fields of type `Span`
103103
name: String,
104104
}
105105

@@ -134,15 +134,15 @@ struct ErrorMissingOpeningBrace {
134134
#[message = "Something something"]
135135
struct LabelOnSpan {
136136
#[label = "See here"]
137-
sp: Span
137+
sp: Span,
138138
}
139139

140140
#[derive(SessionDiagnostic)]
141141
#[error = "E0123"]
142142
#[message = "Something something"]
143143
struct LabelOnNonSpan {
144144
#[label = "See here"]
145-
//~^ ERROR The `#[label = ...]` attribute can only be applied to fields of type Span
145+
//~^ ERROR The `#[label = ...]` attribute can only be applied to fields of type `Span`
146146
id: u32,
147147
}
148148

@@ -204,7 +204,7 @@ struct SuggestWithWrongTypeApplicabilityOnly {
204204

205205
#[derive(SessionDiagnostic)]
206206
#[error = "E0123"]
207-
struct SuggestWithSpanOnly{
207+
struct SuggestWithSpanOnly {
208208
#[suggestion(message = "This is a message", code = "This is suggested code")]
209209
suggestion: Span,
210210
}
@@ -213,7 +213,7 @@ struct SuggestWithSpanOnly{
213213
#[error = "E0123"]
214214
struct SuggestWithDuplicateSpanAndApplicability {
215215
#[suggestion(message = "This is a message", code = "This is suggested code")]
216-
//~^ ERROR type of field annotated with `#[suggestion(...)]` contains more than one Span
216+
//~^ ERROR type of field annotated with `#[suggestion(...)]` contains more than one `Span`
217217
suggestion: (Span, Span, Applicability),
218218
}
219219

src/test/ui-fulldeps/session-derive-errors.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ LL | | Bar,
99
LL | | }
1010
| |_^
1111

12-
error: `#[label = ...]` is not a valid SessionDiagnostic struct attribute
12+
error: `#[label = ...]` is not a valid `SessionDiagnostic` struct attribute
1313
--> $DIR/session-derive-errors.rs:43:1
1414
|
1515
LL | #[label = "This is in the wrong place"]
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717

18-
error: `#[suggestion = ...]` is not a valid SessionDiagnostic field attribute
18+
error: `#[suggestion = ...]` is not a valid `SessionDiagnostic` field attribute
1919
--> $DIR/session-derive-errors.rs:50:5
2020
|
2121
LL | #[suggestion = "this is the wrong kind of attribute"]
@@ -39,9 +39,9 @@ error: `code` not specified
3939
LL | struct ErrorCodeNotProvided {}
4040
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4141
|
42-
= help: use the [code = "..."] attribute to set this diagnostic's error code
42+
= help: use the `#[code = "..."]` attribute to set this diagnostic's error code
4343

44-
error: the `#[message = "..."]` attribute can only be applied to fields of type Span
44+
error: the `#[message = "..."]` attribute can only be applied to fields of type `Span`
4545
--> $DIR/session-derive-errors.rs:101:5
4646
|
4747
LL | #[message = "this message is applied to a String field"]
@@ -78,7 +78,7 @@ LL | #[message = "This is missing an opening brace: name}"]
7878
= note: if you intended to print `}`, you can escape it using `}}`
7979
= note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
8080

81-
error: The `#[label = ...]` attribute can only be applied to fields of type Span
81+
error: The `#[label = ...]` attribute can only be applied to fields of type `Span`
8282
--> $DIR/session-derive-errors.rs:144:5
8383
|
8484
LL | #[label = "See here"]
@@ -102,7 +102,7 @@ error: missing suggestion message
102102
LL | #[suggestion(code = "This is suggested code")]
103103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104104
|
105-
= help: provide a suggestion message using #[suggestion(message = "...")]
105+
= help: provide a suggestion message using `#[suggestion(message = "...")]`
106106

107107
error: wrong field type for suggestion
108108
--> $DIR/session-derive-errors.rs:200:5
@@ -112,9 +112,9 @@ LL | |
112112
LL | | suggestion: Applicability,
113113
| |_____________________________^
114114
|
115-
= help: #[suggestion(...)] should be applied to fields of type Span or (Span, Applicability)
115+
= help: `#[suggestion(...)]` should be applied to fields of type `Span` or `(Span, Applicability)`
116116

117-
error: type of field annotated with `#[suggestion(...)]` contains more than one Span
117+
error: type of field annotated with `#[suggestion(...)]` contains more than one `Span`
118118
--> $DIR/session-derive-errors.rs:215:5
119119
|
120120
LL | / #[suggestion(message = "This is a message", code = "This is suggested code")]

0 commit comments

Comments
 (0)