diff options
| author | David Wood <david.wood@huawei.com> | 2022-03-31 10:24:46 +0100 |
|---|---|---|
| committer | David Wood <david.wood@huawei.com> | 2022-04-05 07:01:03 +0100 |
| commit | a88717cef051b8ebbed0e74c57fc0a714bd893dc (patch) | |
| tree | da04f2a5e842261b84379a6b240700367f6127e5 /src/test/ui-fulldeps | |
| parent | 72dec56028d848ba18a7e1a9bf9da0b6faf5f7da (diff) | |
| download | rust-a88717cef051b8ebbed0e74c57fc0a714bd893dc.tar.gz rust-a88717cef051b8ebbed0e74c57fc0a714bd893dc.zip | |
macros: support translatable labels
Extends support for generating `DiagnosticMessage::FluentIdentifier` messages from `SessionDiagnostic` derive to `#[label]`. Signed-off-by: David Wood <david.wood@huawei.com>
Diffstat (limited to 'src/test/ui-fulldeps')
| -rw-r--r-- | src/test/ui-fulldeps/session-derive-errors.rs | 42 | ||||
| -rw-r--r-- | src/test/ui-fulldeps/session-derive-errors.stderr | 36 |
2 files changed, 41 insertions, 37 deletions
diff --git a/src/test/ui-fulldeps/session-derive-errors.rs b/src/test/ui-fulldeps/session-derive-errors.rs index 63912f0ad13..68f24f1f685 100644 --- a/src/test/ui-fulldeps/session-derive-errors.rs +++ b/src/test/ui-fulldeps/session-derive-errors.rs @@ -139,14 +139,14 @@ struct InvalidPathFieldAttr { #[error(code = "E0123", slug = "foo")] struct ErrorWithField { name: String, - #[label = "This error has a field, and references {name}"] + #[label = "bar"] span: Span, } #[derive(SessionDiagnostic)] #[error(code = "E0123", slug = "foo")] struct ErrorWithMessageAppliedToField { - #[label = "this message is applied to a String field"] + #[label = "bar"] //~^ ERROR the `#[label = ...]` attribute can only be applied to fields of type `Span` name: String, } @@ -154,27 +154,27 @@ struct ErrorWithMessageAppliedToField { #[derive(SessionDiagnostic)] #[error(code = "E0123", slug = "foo")] struct ErrorWithNonexistentField { - #[label = "This error has a field, and references {name}"] + #[suggestion(message = "This is a suggestion", code = "{name}")] //~^ ERROR `name` doesn't refer to a field on this type - foo: Span, + suggestion: (Span, Applicability), } #[derive(SessionDiagnostic)] -#[error(code = "E0123", slug = "foo")] //~^ ERROR invalid format string: expected `'}'` +#[error(code = "E0123", slug = "foo")] struct ErrorMissingClosingBrace { - #[label = "This is missing a closing brace: {name"] - foo: Span, + #[suggestion(message = "This is a suggestion", code = "{name")] + suggestion: (Span, Applicability), name: String, val: usize, } #[derive(SessionDiagnostic)] -#[error(code = "E0123", slug = "foo")] //~^ ERROR invalid format string: unmatched `}` +#[error(code = "E0123", slug = "foo")] struct ErrorMissingOpeningBrace { - #[label = "This is missing an opening brace: name}"] - foo: Span, + #[suggestion(message = "This is a suggestion", code = "name}")] + suggestion: (Span, Applicability), name: String, val: usize, } @@ -182,14 +182,14 @@ struct ErrorMissingOpeningBrace { #[derive(SessionDiagnostic)] #[error(code = "E0123", slug = "foo")] struct LabelOnSpan { - #[label = "See here"] + #[label = "bar"] sp: Span, } #[derive(SessionDiagnostic)] #[error(code = "E0123", slug = "foo")] struct LabelOnNonSpan { - #[label = "See here"] + #[label = "bar"] //~^ ERROR the `#[label = ...]` attribute can only be applied to fields of type `Span` id: u32, } @@ -276,7 +276,7 @@ struct SuggestWithDuplicateApplicabilityAndSpan { #[derive(SessionDiagnostic)] #[error(code = "E0123", slug = "foo")] struct WrongKindOfAnnotation { - #[label("wrong kind of annotation for label")] + #[label("bar")] //~^ ERROR invalid annotation list `#[label(...)]` z: Span, } @@ -284,7 +284,7 @@ struct WrongKindOfAnnotation { #[derive(SessionDiagnostic)] #[error(code = "E0123", slug = "foo")] struct OptionsInErrors { - #[label = "Label message"] + #[label = "bar"] label: Option<Span>, #[suggestion(message = "suggestion message")] opt_sugg: Option<(Span, Applicability)>, @@ -296,9 +296,9 @@ struct MoveOutOfBorrowError<'tcx> { name: Ident, ty: Ty<'tcx>, #[primary_span] - #[label = "cannot move out of borrow"] + #[label = "bar"] span: Span, - #[label = "`{ty}` first borrowed here"] + #[label = "qux"] other_span: Span, #[suggestion(message = "consider cloning here", code = "{name}.clone()")] opt_sugg: Option<(Span, Applicability)>, @@ -307,7 +307,15 @@ struct MoveOutOfBorrowError<'tcx> { #[derive(SessionDiagnostic)] #[error(code = "E0123", slug = "foo")] struct ErrorWithLifetime<'a> { - #[label = "Some message that references {name}"] + #[label = "bar"] + span: Span, + name: &'a str, +} + +#[derive(SessionDiagnostic)] +#[error(code = "E0123", slug = "foo")] +struct ErrorWithDefaultLabelAttr<'a> { + #[label] span: Span, name: &'a str, } diff --git a/src/test/ui-fulldeps/session-derive-errors.stderr b/src/test/ui-fulldeps/session-derive-errors.stderr index 09b8050bf51..902bc785ce7 100644 --- a/src/test/ui-fulldeps/session-derive-errors.stderr +++ b/src/test/ui-fulldeps/session-derive-errors.stderr @@ -162,35 +162,31 @@ LL | #[nonsense] error: the `#[label = ...]` attribute can only be applied to fields of type `Span` --> $DIR/session-derive-errors.rs:149:5 | -LL | #[label = "this message is applied to a String field"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[label = "bar"] + | ^^^^^^^^^^^^^^^^ error: `name` doesn't refer to a field on this type - --> $DIR/session-derive-errors.rs:157:5 + --> $DIR/session-derive-errors.rs:157:52 | -LL | #[label = "This error has a field, and references {name}"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[suggestion(message = "This is a suggestion", code = "{name}")] + | ^^^^^^^^^^^^^^^ error: invalid format string: expected `'}'` but string was terminated - --> $DIR/session-derive-errors.rs:163:20 + --> $DIR/session-derive-errors.rs:162:16 | LL | #[derive(SessionDiagnostic)] - | ----------------- in this derive macro expansion -LL | #[error(code = "E0123", slug = "foo")] - | - ^ expected `'}'` in format string - | | - | because of this opening brace + | - ^ expected `'}'` in format string + | | + | because of this opening brace | = 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: invalid format string: unmatched `}` found - --> $DIR/session-derive-errors.rs:173:20 + --> $DIR/session-derive-errors.rs:172:15 | LL | #[derive(SessionDiagnostic)] - | ----------------- in this derive macro expansion -LL | #[error(code = "E0123", slug = "foo")] - | ^ unmatched `}` in format string + | ^ unmatched `}` in format string | = 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) @@ -198,8 +194,8 @@ LL | #[error(code = "E0123", slug = "foo")] error: the `#[label = ...]` attribute can only be applied to fields of type `Span` --> $DIR/session-derive-errors.rs:192:5 | -LL | #[label = "See here"] - | ^^^^^^^^^^^^^^^^^^^^^ +LL | #[label = "bar"] + | ^^^^^^^^^^^^^^^^ error: `nonsense` is not a valid key for `#[suggestion(...)]` --> $DIR/session-derive-errors.rs:217:18 @@ -250,8 +246,8 @@ LL | | suggestion: (Applicability, Applicability, Span), error: invalid annotation list `#[label(...)]` --> $DIR/session-derive-errors.rs:279:7 | -LL | #[label("wrong kind of annotation for label")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[label("bar")] + | ^^^^^^^^^^^^ error: cannot find attribute `nonsense` in this scope --> $DIR/session-derive-errors.rs:51:3 @@ -266,7 +262,7 @@ LL | #[nonsense] | ^^^^^^^^ error[E0599]: no method named `into_diagnostic_arg` found for struct `Hello` in the current scope - --> $DIR/session-derive-errors.rs:315:10 + --> $DIR/session-derive-errors.rs:323:10 | LL | struct Hello {} | ------------ method `into_diagnostic_arg` not found for this |
