mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
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>
This commit is contained in:
parent
a52b5072ac
commit
f0de7df204
@ -224,7 +224,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
|
||||
match builder.kind {
|
||||
None => {
|
||||
span_err(ast.span().unwrap(), "`code` not specified")
|
||||
.help("use the [code = \"...\"] attribute to set this diagnostic's error code ")
|
||||
.help("use the `#[code = \"...\"]` attribute to set this diagnostic's error code ")
|
||||
.emit();
|
||||
SessionDiagnosticDeriveError::ErrorHandled.to_compile_error()
|
||||
}
|
||||
@ -338,7 +338,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
|
||||
other => throw_span_err!(
|
||||
attr.span().unwrap(),
|
||||
&format!(
|
||||
"`#[{} = ...]` is not a valid SessionDiagnostic struct attribute",
|
||||
"`#[{} = ...]` is not a valid `SessionDiagnostic` struct attribute",
|
||||
other
|
||||
)
|
||||
),
|
||||
@ -429,7 +429,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
|
||||
} else {
|
||||
throw_span_err!(
|
||||
attr.span().unwrap(),
|
||||
"the `#[message = \"...\"]` attribute can only be applied to fields of type Span"
|
||||
"the `#[message = \"...\"]` attribute can only be applied to fields of type `Span`"
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -441,14 +441,14 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
|
||||
} else {
|
||||
throw_span_err!(
|
||||
attr.span().unwrap(),
|
||||
"The `#[label = ...]` attribute can only be applied to fields of type Span"
|
||||
"The `#[label = ...]` attribute can only be applied to fields of type `Span`"
|
||||
);
|
||||
}
|
||||
}
|
||||
other => throw_span_err!(
|
||||
attr.span().unwrap(),
|
||||
&format!(
|
||||
"`#[{} = ...]` is not a valid SessionDiagnostic field attribute",
|
||||
"`#[{} = ...]` is not a valid `SessionDiagnostic` field attribute",
|
||||
other
|
||||
)
|
||||
),
|
||||
@ -505,7 +505,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
|
||||
list.span().unwrap(),
|
||||
"missing suggestion message",
|
||||
|diag| {
|
||||
diag.help("provide a suggestion message using #[suggestion(message = \"...\")]")
|
||||
diag.help("provide a suggestion message using `#[suggestion(message = \"...\")]`")
|
||||
}
|
||||
);
|
||||
};
|
||||
@ -549,7 +549,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
|
||||
} else {
|
||||
throw_span_err!(
|
||||
info.span.unwrap(),
|
||||
"type of field annotated with `#[suggestion(...)]` contains more than one Span"
|
||||
"type of field annotated with `#[suggestion(...)]` contains more than one `Span`"
|
||||
);
|
||||
}
|
||||
} else if type_matches_path(elem, &["rustc_errors", "Applicability"]) {
|
||||
@ -575,12 +575,12 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
|
||||
}
|
||||
|
||||
throw_span_err!(info.span.unwrap(), "wrong types for suggestion", |diag| {
|
||||
diag.help("#[suggestion(...)] on a tuple field must be applied to fields of type `(Span, Applicability)`")
|
||||
diag.help("`#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)`")
|
||||
});
|
||||
}
|
||||
// If `ty` isn't a `Span` or `(Span, Applicability)` then emit an error.
|
||||
_ => throw_span_err!(info.span.unwrap(), "wrong field type for suggestion", |diag| {
|
||||
diag.help("#[suggestion(...)] should be applied to fields of type `Span` or `(Span, Applicability)`")
|
||||
diag.help("`#[suggestion(...)]` should be applied to fields of type `Span` or `(Span, Applicability)`")
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -41,14 +41,14 @@ enum SessionDiagnosticOnEnum {
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error = "E0123"]
|
||||
#[label = "This is in the wrong place"]
|
||||
//~^ ERROR `#[label = ...]` is not a valid SessionDiagnostic struct attribute
|
||||
//~^ ERROR `#[label = ...]` is not a valid `SessionDiagnostic` struct attribute
|
||||
struct WrongPlace {}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error = "E0123"]
|
||||
struct WrongPlaceField {
|
||||
#[suggestion = "this is the wrong kind of attribute"]
|
||||
//~^ ERROR `#[suggestion = ...]` is not a valid SessionDiagnostic field attribute
|
||||
//~^ ERROR `#[suggestion = ...]` is not a valid `SessionDiagnostic` field attribute
|
||||
sp: Span,
|
||||
}
|
||||
|
||||
@ -92,14 +92,14 @@ struct ErrorSpecifiedAfterLint {}
|
||||
struct ErrorWithField {
|
||||
name: String,
|
||||
#[message = "This error has a field, and references {name}"]
|
||||
span: Span
|
||||
span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error = "E0123"]
|
||||
struct ErrorWithMessageAppliedToField {
|
||||
#[message = "this message is applied to a String field"]
|
||||
//~^ ERROR the `#[message = "..."]` attribute can only be applied to fields of type Span
|
||||
//~^ ERROR the `#[message = "..."]` attribute can only be applied to fields of type `Span`
|
||||
name: String,
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ struct ErrorMissingOpeningBrace {
|
||||
#[message = "Something something"]
|
||||
struct LabelOnSpan {
|
||||
#[label = "See here"]
|
||||
sp: Span
|
||||
sp: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
@ -142,7 +142,7 @@ struct LabelOnSpan {
|
||||
#[message = "Something something"]
|
||||
struct LabelOnNonSpan {
|
||||
#[label = "See here"]
|
||||
//~^ ERROR The `#[label = ...]` attribute can only be applied to fields of type Span
|
||||
//~^ ERROR The `#[label = ...]` attribute can only be applied to fields of type `Span`
|
||||
id: u32,
|
||||
}
|
||||
|
||||
@ -204,7 +204,7 @@ struct SuggestWithWrongTypeApplicabilityOnly {
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error = "E0123"]
|
||||
struct SuggestWithSpanOnly{
|
||||
struct SuggestWithSpanOnly {
|
||||
#[suggestion(message = "This is a message", code = "This is suggested code")]
|
||||
suggestion: Span,
|
||||
}
|
||||
@ -213,7 +213,7 @@ struct SuggestWithSpanOnly{
|
||||
#[error = "E0123"]
|
||||
struct SuggestWithDuplicateSpanAndApplicability {
|
||||
#[suggestion(message = "This is a message", code = "This is suggested code")]
|
||||
//~^ ERROR type of field annotated with `#[suggestion(...)]` contains more than one Span
|
||||
//~^ ERROR type of field annotated with `#[suggestion(...)]` contains more than one `Span`
|
||||
suggestion: (Span, Span, Applicability),
|
||||
}
|
||||
|
||||
|
@ -9,13 +9,13 @@ LL | | Bar,
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: `#[label = ...]` is not a valid SessionDiagnostic struct attribute
|
||||
error: `#[label = ...]` is not a valid `SessionDiagnostic` struct attribute
|
||||
--> $DIR/session-derive-errors.rs:43:1
|
||||
|
|
||||
LL | #[label = "This is in the wrong place"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `#[suggestion = ...]` is not a valid SessionDiagnostic field attribute
|
||||
error: `#[suggestion = ...]` is not a valid `SessionDiagnostic` field attribute
|
||||
--> $DIR/session-derive-errors.rs:50:5
|
||||
|
|
||||
LL | #[suggestion = "this is the wrong kind of attribute"]
|
||||
@ -39,9 +39,9 @@ error: `code` not specified
|
||||
LL | struct ErrorCodeNotProvided {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: use the [code = "..."] attribute to set this diagnostic's error code
|
||||
= help: use the `#[code = "..."]` attribute to set this diagnostic's error code
|
||||
|
||||
error: the `#[message = "..."]` attribute can only be applied to fields of type Span
|
||||
error: the `#[message = "..."]` attribute can only be applied to fields of type `Span`
|
||||
--> $DIR/session-derive-errors.rs:101:5
|
||||
|
|
||||
LL | #[message = "this message is applied to a String field"]
|
||||
@ -78,7 +78,7 @@ LL | #[message = "This is missing an opening brace: name}"]
|
||||
= note: if you intended to print `}`, you can escape it using `}}`
|
||||
= note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: The `#[label = ...]` attribute can only be applied to fields of type Span
|
||||
error: The `#[label = ...]` attribute can only be applied to fields of type `Span`
|
||||
--> $DIR/session-derive-errors.rs:144:5
|
||||
|
|
||||
LL | #[label = "See here"]
|
||||
@ -102,7 +102,7 @@ error: missing suggestion message
|
||||
LL | #[suggestion(code = "This is suggested code")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: provide a suggestion message using #[suggestion(message = "...")]
|
||||
= help: provide a suggestion message using `#[suggestion(message = "...")]`
|
||||
|
||||
error: wrong field type for suggestion
|
||||
--> $DIR/session-derive-errors.rs:200:5
|
||||
@ -112,9 +112,9 @@ LL | |
|
||||
LL | | suggestion: Applicability,
|
||||
| |_____________________________^
|
||||
|
|
||||
= help: #[suggestion(...)] should be applied to fields of type Span or (Span, Applicability)
|
||||
= help: `#[suggestion(...)]` should be applied to fields of type `Span` or `(Span, Applicability)`
|
||||
|
||||
error: type of field annotated with `#[suggestion(...)]` contains more than one Span
|
||||
error: type of field annotated with `#[suggestion(...)]` contains more than one `Span`
|
||||
--> $DIR/session-derive-errors.rs:215:5
|
||||
|
|
||||
LL | / #[suggestion(message = "This is a message", code = "This is suggested code")]
|
||||
|
Loading…
Reference in New Issue
Block a user