2020-08-27 05:00:21 -05:00
|
|
|
// check-fail
|
2022-09-18 10:46:56 -05:00
|
|
|
// Tests error conditions for specifying diagnostics using #[derive(Diagnostic)]
|
2020-08-27 05:00:21 -05:00
|
|
|
|
2022-06-29 03:21:44 -05:00
|
|
|
// normalize-stderr-test "the following other types implement trait `IntoDiagnosticArg`:(?:.*\n){0,9}\s+and \d+ others" -> "normalized in stderr"
|
2022-08-31 09:46:51 -05:00
|
|
|
// normalize-stderr-test "diagnostic_builder\.rs:[0-9]+:[0-9]+" -> "diagnostic_builder.rs:LL:CC"
|
2021-06-07 10:08:13 -05:00
|
|
|
// The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly,
|
2022-09-18 10:46:56 -05:00
|
|
|
// changing the output of this test. Since Diagnostic is strictly internal to the compiler
|
2021-06-07 10:08:13 -05:00
|
|
|
// the test is just ignored on stable and beta:
|
Support `x test --stage 1 ui-fulldeps`
Nils had an excellent idea the other day: the same way that rustdoc is
able to load `rustc_driver` from the sysroot, ui-fulldeps tests should
also be able to load it from the sysroot. That allows us to run fulldeps
tests with stage1, without having to fully rebuild the compiler twice.
It does unfortunately have the downside that we're running the tests on
the *bootstrap* compiler, not the in-tree sources, but since most of the
fulldeps tests are for the *API* of the compiler, that seems ok.
I think it's possible to extend this to `run-make-fulldeps`, but I've
run out of energy for tonight.
- Move `plugin` tests into a subdirectory.
Plugins are loaded at runtime with `dlopen` and so require the ABI of
the running compile to match the ABI of the compiler linked with
`rustc_driver`. As a result they can't be supported in stage 1 and have
to use `// ignore-stage1`.
- Remove `ignore-stage1` from most non-plugin tests
- Ignore diagnostic tests in stage 1. Even though this requires a stage
2 build to load rustc_driver, it's primarily testing the error message
that the *running* compiler emits when the diagnostic struct is malformed.
- Pass `-Zforce-unstable-if-unmarked` in stage1, not just stage2. That
allows running `hash-stable-is-unstable` in stage1, since it now
suggests adding `rustc_private` to enable loading the crates.
- Add libLLVM.so to the stage0 target sysroot, to allow fulldeps tests
that act as custom drivers to load it at runtime.
- Pass `--sysroot stage0-sysroot` in compiletest so that we use the
correct version of std.
2023-04-17 20:00:36 -05:00
|
|
|
// ignore-stage1
|
2021-06-07 10:08:13 -05:00
|
|
|
// ignore-beta
|
|
|
|
// ignore-stable
|
|
|
|
|
2020-08-27 05:00:21 -05:00
|
|
|
#![feature(rustc_private)]
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
|
|
|
extern crate rustc_span;
|
|
|
|
use rustc_span::symbol::Ident;
|
2022-03-30 03:45:36 -05:00
|
|
|
use rustc_span::Span;
|
2020-08-27 05:00:21 -05:00
|
|
|
|
2023-04-16 07:33:00 -05:00
|
|
|
extern crate rustc_fluent_macro;
|
2020-08-27 05:00:21 -05:00
|
|
|
extern crate rustc_macros;
|
2023-04-16 07:33:00 -05:00
|
|
|
use rustc_fluent_macro::fluent_messages;
|
|
|
|
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
2020-08-27 05:00:21 -05:00
|
|
|
|
|
|
|
extern crate rustc_middle;
|
|
|
|
use rustc_middle::ty::Ty;
|
|
|
|
|
|
|
|
extern crate rustc_errors;
|
2022-10-13 04:13:02 -05:00
|
|
|
use rustc_errors::{Applicability, DiagnosticMessage, MultiSpan, SubdiagnosticMessage};
|
2020-08-27 05:00:21 -05:00
|
|
|
|
|
|
|
extern crate rustc_session;
|
|
|
|
|
2022-10-13 04:13:02 -05:00
|
|
|
fluent_messages! { "./example.ftl" }
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct Hello {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 02:35:17 -05:00
|
|
|
struct HelloWarn {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-09-23 06:49:02 -05:00
|
|
|
//~^ ERROR unsupported type attribute for diagnostic derive enum
|
2022-09-18 10:46:56 -05:00
|
|
|
enum DiagnosticOnEnum {
|
2020-08-27 05:00:21 -05:00
|
|
|
Foo,
|
2022-10-20 14:09:54 -05:00
|
|
|
//~^ ERROR diagnostic slug not specified
|
2020-08-27 05:00:21 -05:00
|
|
|
Bar,
|
2022-10-20 14:09:54 -05:00
|
|
|
//~^ ERROR diagnostic slug not specified
|
2020-08-27 05:00:21 -05:00
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-08-19 08:40:48 -05:00
|
|
|
#[diag = "E0123"]
|
2023-07-26 03:42:40 -05:00
|
|
|
//~^ ERROR failed to resolve: maybe a missing crate `core`
|
2022-03-31 02:35:17 -05:00
|
|
|
struct WrongStructAttrStyle {}
|
2020-08-27 05:00:21 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[nonsense(no_crate_example, code = "E0123")]
|
2022-04-26 22:06:13 -05:00
|
|
|
//~^ ERROR `#[nonsense(...)]` is not a valid attribute
|
2022-08-19 08:02:10 -05:00
|
|
|
//~^^ ERROR diagnostic slug not specified
|
2022-03-31 02:35:17 -05:00
|
|
|
//~^^^ ERROR cannot find attribute `nonsense` in this scope
|
|
|
|
struct InvalidStructAttr {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-08-19 08:40:48 -05:00
|
|
|
#[diag("E0123")]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR diagnostic slug not specified
|
2022-03-31 02:35:17 -05:00
|
|
|
struct InvalidLitNestedAttr {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-08-19 08:40:48 -05:00
|
|
|
#[diag(nonsense, code = "E0123")]
|
2022-10-13 04:13:02 -05:00
|
|
|
//~^ ERROR cannot find value `nonsense` in module `crate::fluent_generated`
|
2022-03-31 02:35:17 -05:00
|
|
|
struct InvalidNestedStructAttr {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-08-19 08:40:48 -05:00
|
|
|
#[diag(nonsense("foo"), code = "E0123", slug = "foo")]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR diagnostic slug must be the first argument
|
|
|
|
//~| ERROR diagnostic slug not specified
|
2022-03-31 02:35:17 -05:00
|
|
|
struct InvalidNestedStructAttr1 {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-08-19 08:40:48 -05:00
|
|
|
#[diag(nonsense = "...", code = "E0123", slug = "foo")]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR unknown argument
|
2022-09-14 10:19:40 -05:00
|
|
|
//~| ERROR diagnostic slug not specified
|
2022-03-31 02:35:17 -05:00
|
|
|
struct InvalidNestedStructAttr2 {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-08-19 08:40:48 -05:00
|
|
|
#[diag(nonsense = 4, code = "E0123", slug = "foo")]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR unknown argument
|
2022-09-14 10:19:40 -05:00
|
|
|
//~| ERROR diagnostic slug not specified
|
2022-03-31 02:35:17 -05:00
|
|
|
struct InvalidNestedStructAttr3 {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123", slug = "foo")]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR unknown argument
|
2022-06-23 08:51:44 -05:00
|
|
|
struct InvalidNestedStructAttr4 {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct WrongPlaceField {
|
2022-03-31 07:10:13 -05:00
|
|
|
#[suggestion = "bar"]
|
2022-04-26 22:06:13 -05:00
|
|
|
//~^ ERROR `#[suggestion = ...]` is not a valid attribute
|
2020-08-27 05:00:21 -05:00
|
|
|
sp: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
|
|
|
#[diag(no_crate_example, code = "E0456")]
|
2022-04-26 22:28:21 -05:00
|
|
|
//~^ ERROR specified multiple times
|
|
|
|
//~^^ ERROR specified multiple times
|
2022-08-19 08:40:48 -05:00
|
|
|
struct DiagSpecifiedTwice {}
|
2020-08-27 05:00:21 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0456", code = "E0457")]
|
2022-04-26 22:28:21 -05:00
|
|
|
//~^ ERROR specified multiple times
|
2022-03-31 02:35:17 -05:00
|
|
|
struct CodeSpecifiedTwice {}
|
2020-08-27 05:00:21 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, no_crate::example, code = "E0456")]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR diagnostic slug must be the first argument
|
2022-03-31 02:35:17 -05:00
|
|
|
struct SlugSpecifiedTwice {}
|
2020-08-27 05:00:21 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-08-19 08:02:10 -05:00
|
|
|
struct KindNotProvided {} //~ ERROR diagnostic slug not specified
|
2020-08-27 05:00:21 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-08-19 08:40:48 -05:00
|
|
|
#[diag(code = "E0456")]
|
2022-06-23 08:51:44 -05:00
|
|
|
//~^ ERROR diagnostic slug not specified
|
2022-03-31 02:35:17 -05:00
|
|
|
struct SlugNotProvided {}
|
2020-08-27 05:00:21 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-03-31 02:35:17 -05:00
|
|
|
struct CodeNotProvided {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 02:35:17 -05:00
|
|
|
struct MessageWrongType {
|
2022-03-31 02:50:45 -05:00
|
|
|
#[primary_span]
|
2022-07-11 11:15:31 -05:00
|
|
|
//~^ ERROR `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan`
|
2022-03-31 02:35:17 -05:00
|
|
|
foo: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 02:35:17 -05:00
|
|
|
struct InvalidPathFieldAttr {
|
|
|
|
#[nonsense]
|
2022-04-26 22:06:13 -05:00
|
|
|
//~^ ERROR `#[nonsense]` is not a valid attribute
|
2022-03-31 02:35:17 -05:00
|
|
|
//~^^ ERROR cannot find attribute `nonsense` in this scope
|
|
|
|
foo: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct ErrorWithField {
|
|
|
|
name: String,
|
2022-10-13 04:13:02 -05:00
|
|
|
#[label(no_crate_label)]
|
2022-03-30 04:04:03 -05:00
|
|
|
span: Span,
|
2020-08-27 05:00:21 -05:00
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct ErrorWithMessageAppliedToField {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[label(no_crate_label)]
|
2022-07-11 11:15:31 -05:00
|
|
|
//~^ ERROR the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
|
2020-08-27 05:00:21 -05:00
|
|
|
name: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct ErrorWithNonexistentField {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "{name}")]
|
2022-03-31 02:35:17 -05:00
|
|
|
//~^ ERROR `name` doesn't refer to a field on this type
|
2022-03-31 04:24:46 -05:00
|
|
|
suggestion: (Span, Applicability),
|
2020-08-27 05:00:21 -05:00
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2020-08-27 05:00:21 -05:00
|
|
|
//~^ ERROR invalid format string: expected `'}'`
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct ErrorMissingClosingBrace {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "{name")]
|
2022-03-31 04:24:46 -05:00
|
|
|
suggestion: (Span, Applicability),
|
2020-08-27 05:00:21 -05:00
|
|
|
name: String,
|
2022-03-30 03:45:36 -05:00
|
|
|
val: usize,
|
2020-08-27 05:00:21 -05:00
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2020-08-27 05:00:21 -05:00
|
|
|
//~^ ERROR invalid format string: unmatched `}`
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct ErrorMissingOpeningBrace {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "name}")]
|
2022-03-31 04:24:46 -05:00
|
|
|
suggestion: (Span, Applicability),
|
2020-08-27 05:00:21 -05:00
|
|
|
name: String,
|
2022-03-30 03:45:36 -05:00
|
|
|
val: usize,
|
2020-08-27 05:00:21 -05:00
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct LabelOnSpan {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[label(no_crate_label)]
|
2022-03-30 04:04:03 -05:00
|
|
|
sp: Span,
|
2020-08-27 05:00:21 -05:00
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct LabelOnNonSpan {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[label(no_crate_label)]
|
2022-07-11 11:15:31 -05:00
|
|
|
//~^ ERROR the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
|
2020-08-27 05:00:21 -05:00
|
|
|
id: u32,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct Suggest {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "This is the suggested code")]
|
|
|
|
#[suggestion(no_crate_suggestion, code = "This is the suggested code", style = "normal")]
|
|
|
|
#[suggestion(no_crate_suggestion, code = "This is the suggested code", style = "short")]
|
|
|
|
#[suggestion(no_crate_suggestion, code = "This is the suggested code", style = "hidden")]
|
|
|
|
#[suggestion(no_crate_suggestion, code = "This is the suggested code", style = "verbose")]
|
2020-08-27 05:00:21 -05:00
|
|
|
suggestion: (Span, Applicability),
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithoutCode {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion)]
|
2022-09-14 10:19:40 -05:00
|
|
|
//~^ ERROR suggestion without `code = "..."`
|
2020-08-27 05:00:21 -05:00
|
|
|
suggestion: (Span, Applicability),
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithBadKey {
|
2022-03-31 07:10:13 -05:00
|
|
|
#[suggestion(nonsense = "bar")]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR invalid nested attribute
|
2022-09-14 10:19:40 -05:00
|
|
|
//~| ERROR suggestion without `code = "..."`
|
2020-08-27 05:00:21 -05:00
|
|
|
suggestion: (Span, Applicability),
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithShorthandMsg {
|
2022-03-31 07:10:13 -05:00
|
|
|
#[suggestion(msg = "bar")]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR invalid nested attribute
|
2022-09-14 10:19:40 -05:00
|
|
|
//~| ERROR suggestion without `code = "..."`
|
2020-08-27 05:00:21 -05:00
|
|
|
suggestion: (Span, Applicability),
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithoutMsg {
|
2022-03-31 07:10:13 -05:00
|
|
|
#[suggestion(code = "bar")]
|
2020-08-27 05:00:21 -05:00
|
|
|
suggestion: (Span, Applicability),
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithTypesSwapped {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "This is suggested code")]
|
2020-08-27 05:00:21 -05:00
|
|
|
suggestion: (Applicability, Span),
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithWrongTypeApplicabilityOnly {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "This is suggested code")]
|
2020-08-27 05:00:21 -05:00
|
|
|
//~^ ERROR wrong field type for suggestion
|
|
|
|
suggestion: Applicability,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-30 04:04:03 -05:00
|
|
|
struct SuggestWithSpanOnly {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "This is suggested code")]
|
2020-08-27 05:00:21 -05:00
|
|
|
suggestion: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithDuplicateSpanAndApplicability {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "This is suggested code")]
|
2020-08-27 05:00:21 -05:00
|
|
|
suggestion: (Span, Span, Applicability),
|
2022-09-10 07:43:07 -05:00
|
|
|
//~^ ERROR specified multiple times
|
2020-08-27 05:00:21 -05:00
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithDuplicateApplicabilityAndSpan {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "This is suggested code")]
|
2020-08-27 05:00:21 -05:00
|
|
|
suggestion: (Applicability, Applicability, Span),
|
2022-09-10 07:43:07 -05:00
|
|
|
//~^ ERROR specified multiple times
|
2020-08-27 05:00:21 -05:00
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct WrongKindOfAnnotation {
|
2022-06-23 08:51:44 -05:00
|
|
|
#[label = "bar"]
|
|
|
|
//~^ ERROR `#[label = ...]` is not a valid attribute
|
2020-08-27 05:00:21 -05:00
|
|
|
z: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct OptionsInErrors {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[label(no_crate_label)]
|
2020-08-27 05:00:21 -05:00
|
|
|
label: Option<Span>,
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "...")]
|
2020-08-27 05:00:21 -05:00
|
|
|
opt_sugg: Option<(Span, Applicability)>,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0456")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct MoveOutOfBorrowError<'tcx> {
|
|
|
|
name: Ident,
|
|
|
|
ty: Ty<'tcx>,
|
2022-03-31 02:50:45 -05:00
|
|
|
#[primary_span]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[label(no_crate_label)]
|
2020-08-27 05:00:21 -05:00
|
|
|
span: Span,
|
2022-10-13 04:13:02 -05:00
|
|
|
#[label(no_crate_label)]
|
2020-08-27 05:00:21 -05:00
|
|
|
other_span: Span,
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "{name}.clone()")]
|
2020-08-27 05:00:21 -05:00
|
|
|
opt_sugg: Option<(Span, Applicability)>,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct ErrorWithLifetime<'a> {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[label(no_crate_label)]
|
2022-03-31 04:24:46 -05:00
|
|
|
span: Span,
|
|
|
|
name: &'a str,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 04:24:46 -05:00
|
|
|
struct ErrorWithDefaultLabelAttr<'a> {
|
|
|
|
#[label]
|
2020-08-27 05:00:21 -05:00
|
|
|
span: Span,
|
|
|
|
name: &'a str,
|
|
|
|
}
|
2022-03-31 03:02:31 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 03:02:31 -05:00
|
|
|
struct ArgFieldWithoutSkip {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
other: Hello,
|
2023-05-03 18:53:44 -05:00
|
|
|
//~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied
|
2022-03-31 03:02:31 -05:00
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 03:02:31 -05:00
|
|
|
struct ArgFieldWithSkip {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
// `Hello` does not implement `IntoDiagnosticArg` so this would result in an error if
|
|
|
|
// not for `#[skip_arg]`.
|
|
|
|
#[skip_arg]
|
|
|
|
other: Hello,
|
|
|
|
}
|
2022-03-31 06:10:00 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 06:10:00 -05:00
|
|
|
struct ErrorWithSpannedNote {
|
|
|
|
#[note]
|
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 06:10:00 -05:00
|
|
|
struct ErrorWithSpannedNoteCustom {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[note(no_crate_note)]
|
2022-03-31 06:10:00 -05:00
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 06:10:00 -05:00
|
|
|
#[note]
|
|
|
|
struct ErrorWithNote {
|
|
|
|
val: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
|
|
|
#[note(no_crate_note)]
|
2022-03-31 06:10:00 -05:00
|
|
|
struct ErrorWithNoteCustom {
|
|
|
|
val: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 06:10:00 -05:00
|
|
|
struct ErrorWithSpannedHelp {
|
|
|
|
#[help]
|
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 06:10:00 -05:00
|
|
|
struct ErrorWithSpannedHelpCustom {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[help(no_crate_help)]
|
2022-03-31 06:10:00 -05:00
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 06:10:00 -05:00
|
|
|
#[help]
|
|
|
|
struct ErrorWithHelp {
|
|
|
|
val: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
|
|
|
#[help(no_crate_help)]
|
2022-03-31 06:10:00 -05:00
|
|
|
struct ErrorWithHelpCustom {
|
|
|
|
val: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-03-31 06:10:00 -05:00
|
|
|
#[help]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 06:10:00 -05:00
|
|
|
struct ErrorWithHelpWrongOrder {
|
|
|
|
val: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[help(no_crate_help)]
|
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 06:10:00 -05:00
|
|
|
struct ErrorWithHelpCustomWrongOrder {
|
|
|
|
val: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-03-31 06:10:00 -05:00
|
|
|
#[note]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 06:10:00 -05:00
|
|
|
struct ErrorWithNoteWrongOrder {
|
|
|
|
val: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[note(no_crate_note)]
|
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-03-31 06:10:00 -05:00
|
|
|
struct ErrorWithNoteCustomWrongOrder {
|
|
|
|
val: String,
|
|
|
|
}
|
2022-04-26 23:43:36 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-04-26 23:43:36 -05:00
|
|
|
struct ApplicabilityInBoth {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "...", applicability = "maybe-incorrect")]
|
2022-09-10 07:48:01 -05:00
|
|
|
//~^ ERROR specified multiple times
|
2022-04-26 23:43:36 -05:00
|
|
|
suggestion: (Span, Applicability),
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-04-26 23:43:36 -05:00
|
|
|
struct InvalidApplicability {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "...", applicability = "batman")]
|
2022-04-26 23:43:36 -05:00
|
|
|
//~^ ERROR invalid applicability
|
|
|
|
suggestion: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-04-26 23:43:36 -05:00
|
|
|
struct ValidApplicability {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "...", applicability = "maybe-incorrect")]
|
2022-04-26 23:43:36 -05:00
|
|
|
suggestion: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-04-26 23:43:36 -05:00
|
|
|
struct NoApplicability {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "...")]
|
2022-04-26 23:43:36 -05:00
|
|
|
suggestion: Span,
|
|
|
|
}
|
2022-04-26 23:59:48 -05:00
|
|
|
|
2022-09-18 10:47:31 -05:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[note(no_crate_example)]
|
2022-04-26 23:59:48 -05:00
|
|
|
struct Note;
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-04-26 23:59:48 -05:00
|
|
|
struct Subdiagnostic {
|
|
|
|
#[subdiagnostic]
|
|
|
|
note: Note,
|
|
|
|
}
|
2022-05-05 21:43:30 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-05-05 21:43:30 -05:00
|
|
|
struct VecField {
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
spans: Vec<Span>,
|
|
|
|
}
|
2022-05-07 00:02:11 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-05-07 00:02:11 -05:00
|
|
|
struct UnitField {
|
|
|
|
#[primary_span]
|
|
|
|
spans: Span,
|
|
|
|
#[help]
|
|
|
|
foo: (),
|
2022-10-13 04:13:02 -05:00
|
|
|
#[help(no_crate_help)]
|
2022-05-07 00:02:11 -05:00
|
|
|
bar: (),
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-05-07 00:02:11 -05:00
|
|
|
struct OptUnitField {
|
|
|
|
#[primary_span]
|
|
|
|
spans: Span,
|
|
|
|
#[help]
|
|
|
|
foo: Option<()>,
|
2022-10-13 04:13:02 -05:00
|
|
|
#[help(no_crate_help)]
|
2022-05-07 00:02:11 -05:00
|
|
|
bar: Option<()>,
|
|
|
|
}
|
2022-06-23 08:51:44 -05:00
|
|
|
|
2023-02-27 06:54:11 -06:00
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(no_crate_example)]
|
|
|
|
struct BoolField {
|
|
|
|
#[primary_span]
|
|
|
|
spans: Span,
|
|
|
|
#[help]
|
|
|
|
foo: bool,
|
|
|
|
#[help(no_crate_help)]
|
2023-04-08 14:37:41 -05:00
|
|
|
//~^ ERROR the `#[help(...)]` attribute can only be applied to fields of type
|
2023-02-27 06:54:11 -06:00
|
|
|
// only allow plain 'bool' fields
|
|
|
|
bar: Option<bool>,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-06-23 08:51:44 -05:00
|
|
|
struct LabelWithTrailingPath {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[label(no_crate_label, foo)]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR a diagnostic slug must be the first argument to the attribute
|
2022-06-23 08:51:44 -05:00
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-06-23 08:51:44 -05:00
|
|
|
struct LabelWithTrailingNameValue {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[label(no_crate_label, foo = "...")]
|
2023-05-17 05:30:14 -05:00
|
|
|
//~^ ERROR only `no_span` is a valid nested attribute
|
2022-06-23 08:51:44 -05:00
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-06-23 08:51:44 -05:00
|
|
|
struct LabelWithTrailingList {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[label(no_crate_label, foo("..."))]
|
2023-05-17 05:30:14 -05:00
|
|
|
//~^ ERROR only `no_span` is a valid nested attribute
|
2022-06-23 08:51:44 -05:00
|
|
|
span: Span,
|
|
|
|
}
|
2022-06-30 02:57:45 -05:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-20 14:09:54 -05:00
|
|
|
struct LintsGood {}
|
2022-06-30 02:57:45 -05:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-08-19 08:04:34 -05:00
|
|
|
struct PrimarySpanOnLint {
|
|
|
|
#[primary_span]
|
|
|
|
//~^ ERROR `#[primary_span]` is not a valid attribute
|
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-07-11 11:15:31 -05:00
|
|
|
struct ErrorWithMultiSpan {
|
|
|
|
#[primary_span]
|
|
|
|
span: MultiSpan,
|
|
|
|
}
|
2022-07-11 12:46:24 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-08-24 10:57:10 -05:00
|
|
|
#[warning]
|
2022-07-11 12:46:24 -05:00
|
|
|
struct ErrorWithWarn {
|
|
|
|
val: String,
|
|
|
|
}
|
2022-08-19 08:40:48 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[error(no_crate_example, code = "E0123")]
|
2022-08-19 08:40:48 -05:00
|
|
|
//~^ ERROR `#[error(...)]` is not a valid attribute
|
|
|
|
//~| ERROR diagnostic slug not specified
|
|
|
|
//~| ERROR cannot find attribute `error` in this scope
|
|
|
|
struct ErrorAttribute {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[warn_(no_crate_example, code = "E0123")]
|
2022-08-24 10:57:10 -05:00
|
|
|
//~^ ERROR `#[warn_(...)]` is not a valid attribute
|
2022-08-19 08:40:48 -05:00
|
|
|
//~| ERROR diagnostic slug not specified
|
2022-08-24 10:57:10 -05:00
|
|
|
//~| ERROR cannot find attribute `warn_` in this scope
|
|
|
|
struct WarnAttribute {}
|
2022-08-19 08:40:48 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[lint(no_crate_example, code = "E0123")]
|
2022-08-19 08:40:48 -05:00
|
|
|
//~^ ERROR `#[lint(...)]` is not a valid attribute
|
|
|
|
//~| ERROR diagnostic slug not specified
|
|
|
|
//~| ERROR cannot find attribute `lint` in this scope
|
|
|
|
struct LintAttributeOnSessionDiag {}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[lint(no_crate_example, code = "E0123")]
|
2022-08-19 08:40:48 -05:00
|
|
|
//~^ ERROR `#[lint(...)]` is not a valid attribute
|
2022-09-22 09:25:05 -05:00
|
|
|
//~| ERROR `#[lint(...)]` is not a valid attribute
|
2022-08-19 08:40:48 -05:00
|
|
|
//~| ERROR diagnostic slug not specified
|
|
|
|
//~| ERROR cannot find attribute `lint` in this scope
|
|
|
|
struct LintAttributeOnLintDiag {}
|
2022-09-10 07:28:12 -05:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-09-10 07:28:12 -05:00
|
|
|
struct DuplicatedSuggestionCode {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "...", code = ",,,")]
|
2022-09-10 07:28:12 -05:00
|
|
|
//~^ ERROR specified multiple times
|
|
|
|
suggestion: Span,
|
|
|
|
}
|
2022-09-10 07:43:07 -05:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-09-10 07:43:07 -05:00
|
|
|
struct InvalidTypeInSuggestionTuple {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "...")]
|
2022-09-10 07:43:07 -05:00
|
|
|
suggestion: (Span, usize),
|
|
|
|
//~^ ERROR wrong types for suggestion
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-09-10 07:43:07 -05:00
|
|
|
struct MissingApplicabilityInSuggestionTuple {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "...")]
|
2022-09-10 07:43:07 -05:00
|
|
|
suggestion: (Span,),
|
|
|
|
//~^ ERROR wrong types for suggestion
|
|
|
|
}
|
2022-09-14 10:19:40 -05:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-09-14 10:19:40 -05:00
|
|
|
struct MissingCodeInSuggestion {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion)]
|
2022-09-14 10:19:40 -05:00
|
|
|
//~^ ERROR suggestion without `code = "..."`
|
|
|
|
suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
|
|
|
#[multipart_suggestion(no_crate_suggestion)]
|
2022-09-14 10:19:40 -05:00
|
|
|
//~^ ERROR `#[multipart_suggestion(...)]` is not a valid attribute
|
|
|
|
//~| ERROR cannot find attribute `multipart_suggestion` in this scope
|
|
|
|
#[multipart_suggestion()]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR cannot find attribute `multipart_suggestion` in this scope
|
2023-07-26 03:42:40 -05:00
|
|
|
//~| ERROR `#[multipart_suggestion(...)]` is not a valid attribute
|
2022-09-14 10:19:40 -05:00
|
|
|
struct MultipartSuggestion {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[multipart_suggestion(no_crate_suggestion)]
|
2022-09-14 10:19:40 -05:00
|
|
|
//~^ ERROR `#[multipart_suggestion(...)]` is not a valid attribute
|
|
|
|
//~| ERROR cannot find attribute `multipart_suggestion` in this scope
|
|
|
|
suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
|
|
|
#[suggestion(no_crate_suggestion, code = "...")]
|
2022-09-14 10:19:40 -05:00
|
|
|
//~^ ERROR `#[suggestion(...)]` is not a valid attribute
|
|
|
|
struct SuggestionOnStruct {
|
|
|
|
#[primary_span]
|
|
|
|
suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-09-14 10:19:40 -05:00
|
|
|
#[label]
|
|
|
|
//~^ ERROR `#[label]` is not a valid attribute
|
|
|
|
struct LabelOnStruct {
|
|
|
|
#[primary_span]
|
|
|
|
suggestion: Span,
|
|
|
|
}
|
2022-09-23 06:49:02 -05:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
enum ExampleEnum {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-09-23 06:49:02 -05:00
|
|
|
Foo {
|
|
|
|
#[primary_span]
|
|
|
|
sp: Span,
|
|
|
|
#[note]
|
|
|
|
note_sp: Span,
|
|
|
|
},
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-09-23 06:49:02 -05:00
|
|
|
Bar {
|
|
|
|
#[primary_span]
|
|
|
|
sp: Span,
|
|
|
|
},
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-09-23 06:49:02 -05:00
|
|
|
Baz,
|
|
|
|
}
|
2022-09-14 13:12:22 -05:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-09-14 13:12:22 -05:00
|
|
|
struct RawIdentDiagnosticArg {
|
|
|
|
pub r#type: String,
|
|
|
|
}
|
2022-10-03 08:24:17 -05:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-03 08:24:17 -05:00
|
|
|
struct SubdiagnosticBad {
|
|
|
|
#[subdiagnostic(bad)]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR `eager` is the only supported nested attribute for `subdiagnostic`
|
2022-10-03 08:24:17 -05:00
|
|
|
note: Note,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-03 08:24:17 -05:00
|
|
|
struct SubdiagnosticBadStr {
|
|
|
|
#[subdiagnostic = "bad"]
|
2022-10-20 14:09:54 -05:00
|
|
|
//~^ ERROR `#[subdiagnostic = ...]` is not a valid attribute
|
2022-10-03 08:24:17 -05:00
|
|
|
note: Note,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-03 08:24:17 -05:00
|
|
|
struct SubdiagnosticBadTwice {
|
|
|
|
#[subdiagnostic(bad, bad)]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR `eager` is the only supported nested attribute for `subdiagnostic`
|
2022-10-03 08:24:17 -05:00
|
|
|
note: Note,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-03 08:24:17 -05:00
|
|
|
struct SubdiagnosticBadLitStr {
|
|
|
|
#[subdiagnostic("bad")]
|
2023-04-03 09:36:50 -05:00
|
|
|
//~^ ERROR `eager` is the only supported nested attribute for `subdiagnostic`
|
2022-10-03 08:24:17 -05:00
|
|
|
note: Note,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-03 08:24:17 -05:00
|
|
|
struct SubdiagnosticEagerLint {
|
|
|
|
#[subdiagnostic(eager)]
|
2022-10-20 14:09:54 -05:00
|
|
|
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
|
2022-10-03 08:24:17 -05:00
|
|
|
note: Note,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-03 08:24:17 -05:00
|
|
|
struct SubdiagnosticEagerCorrect {
|
|
|
|
#[subdiagnostic(eager)]
|
|
|
|
note: Note,
|
|
|
|
}
|
macros: separate suggestion fmt'ing and emission
Diagnostic derives have previously had to take special care when
ordering the generated code so that fields were not used after a move.
This is unlikely for most fields because a field is either annotated
with a subdiagnostic attribute and is thus likely a `Span` and copiable,
or is a argument, in which case it is only used once by `set_arg`
anyway.
However, format strings for code in suggestions can result in fields
being used after being moved if not ordered carefully. As a result, the
derive currently puts `set_arg` calls last (just before emission), such
as:
```rust
let diag = { /* create diagnostic */ };
diag.span_suggestion_with_style(
span,
fluent::crate::slug,
format!("{}", __binding_0),
Applicability::Unknown,
SuggestionStyle::ShowAlways
);
/* + other subdiagnostic additions */
diag.set_arg("foo", __binding_0);
/* + other `set_arg` calls */
diag.emit();
```
For eager translation, this doesn't work, as the message being
translated eagerly can assume that all arguments are available - so
arguments _must_ be set first.
Format strings for suggestion code are now separated into two parts - an
initialization line that performs the formatting into a variable, and a
usage in the subdiagnostic addition.
By separating these parts, the initialization can happen before
arguments are set, preserving the desired order so that code compiles,
while still enabling arguments to be set before subdiagnostics are
added.
```rust
let diag = { /* create diagnostic */ };
let __code_0 = format!("{}", __binding_0);
/* + other formatting */
diag.set_arg("foo", __binding_0);
/* + other `set_arg` calls */
diag.span_suggestion_with_style(
span,
fluent::crate::slug,
__code_0,
Applicability::Unknown,
SuggestionStyle::ShowAlways
);
/* + other subdiagnostic additions */
diag.emit();
```
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-03 08:28:02 -05:00
|
|
|
|
|
|
|
// Check that formatting of `correct` in suggestion doesn't move the binding for that field, making
|
|
|
|
// the `set_arg` call a compile error; and that isn't worked around by moving the `set_arg` call
|
|
|
|
// after the `span_suggestion` call - which breaks eager translation.
|
|
|
|
|
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_example, applicability = "machine-applicable", code = "{correct}")]
|
macros: separate suggestion fmt'ing and emission
Diagnostic derives have previously had to take special care when
ordering the generated code so that fields were not used after a move.
This is unlikely for most fields because a field is either annotated
with a subdiagnostic attribute and is thus likely a `Span` and copiable,
or is a argument, in which case it is only used once by `set_arg`
anyway.
However, format strings for code in suggestions can result in fields
being used after being moved if not ordered carefully. As a result, the
derive currently puts `set_arg` calls last (just before emission), such
as:
```rust
let diag = { /* create diagnostic */ };
diag.span_suggestion_with_style(
span,
fluent::crate::slug,
format!("{}", __binding_0),
Applicability::Unknown,
SuggestionStyle::ShowAlways
);
/* + other subdiagnostic additions */
diag.set_arg("foo", __binding_0);
/* + other `set_arg` calls */
diag.emit();
```
For eager translation, this doesn't work, as the message being
translated eagerly can assume that all arguments are available - so
arguments _must_ be set first.
Format strings for suggestion code are now separated into two parts - an
initialization line that performs the formatting into a variable, and a
usage in the subdiagnostic addition.
By separating these parts, the initialization can happen before
arguments are set, preserving the desired order so that code compiles,
while still enabling arguments to be set before subdiagnostics are
added.
```rust
let diag = { /* create diagnostic */ };
let __code_0 = format!("{}", __binding_0);
/* + other formatting */
diag.set_arg("foo", __binding_0);
/* + other `set_arg` calls */
diag.span_suggestion_with_style(
span,
fluent::crate::slug,
__code_0,
Applicability::Unknown,
SuggestionStyle::ShowAlways
);
/* + other subdiagnostic additions */
diag.emit();
```
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-03 08:28:02 -05:00
|
|
|
pub(crate) struct SubdiagnosticWithSuggestion {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
invalid: String,
|
|
|
|
correct: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
macros: separate suggestion fmt'ing and emission
Diagnostic derives have previously had to take special care when
ordering the generated code so that fields were not used after a move.
This is unlikely for most fields because a field is either annotated
with a subdiagnostic attribute and is thus likely a `Span` and copiable,
or is a argument, in which case it is only used once by `set_arg`
anyway.
However, format strings for code in suggestions can result in fields
being used after being moved if not ordered carefully. As a result, the
derive currently puts `set_arg` calls last (just before emission), such
as:
```rust
let diag = { /* create diagnostic */ };
diag.span_suggestion_with_style(
span,
fluent::crate::slug,
format!("{}", __binding_0),
Applicability::Unknown,
SuggestionStyle::ShowAlways
);
/* + other subdiagnostic additions */
diag.set_arg("foo", __binding_0);
/* + other `set_arg` calls */
diag.emit();
```
For eager translation, this doesn't work, as the message being
translated eagerly can assume that all arguments are available - so
arguments _must_ be set first.
Format strings for suggestion code are now separated into two parts - an
initialization line that performs the formatting into a variable, and a
usage in the subdiagnostic addition.
By separating these parts, the initialization can happen before
arguments are set, preserving the desired order so that code compiles,
while still enabling arguments to be set before subdiagnostics are
added.
```rust
let diag = { /* create diagnostic */ };
let __code_0 = format!("{}", __binding_0);
/* + other formatting */
diag.set_arg("foo", __binding_0);
/* + other `set_arg` calls */
diag.span_suggestion_with_style(
span,
fluent::crate::slug,
__code_0,
Applicability::Unknown,
SuggestionStyle::ShowAlways
);
/* + other subdiagnostic additions */
diag.emit();
```
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-03 08:28:02 -05:00
|
|
|
struct SubdiagnosticEagerSuggestion {
|
|
|
|
#[subdiagnostic(eager)]
|
|
|
|
sub: SubdiagnosticWithSuggestion,
|
|
|
|
}
|
2022-10-14 05:00:46 -05:00
|
|
|
|
|
|
|
/// with a doc comment on the type..
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example, code = "E0123")]
|
2022-10-14 05:00:46 -05:00
|
|
|
struct WithDocComment {
|
|
|
|
/// ..and the field
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
}
|
2022-10-17 12:41:49 -05:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-17 12:41:49 -05:00
|
|
|
struct SuggestionsGood {
|
|
|
|
#[suggestion(code("foo", "bar"))]
|
|
|
|
sub: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-17 12:41:49 -05:00
|
|
|
struct SuggestionsSingleItem {
|
|
|
|
#[suggestion(code("foo"))]
|
|
|
|
sub: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-17 12:41:49 -05:00
|
|
|
struct SuggestionsNoItem {
|
|
|
|
#[suggestion(code())]
|
|
|
|
//~^ ERROR expected at least one string literal for `code(...)`
|
|
|
|
sub: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-17 12:41:49 -05:00
|
|
|
struct SuggestionsInvalidItem {
|
|
|
|
#[suggestion(code(foo))]
|
|
|
|
//~^ ERROR `code(...)` must contain only string literals
|
2023-07-26 03:42:40 -05:00
|
|
|
//~| ERROR failed to resolve: maybe a missing crate `core`
|
2022-10-17 12:41:49 -05:00
|
|
|
sub: Span,
|
|
|
|
}
|
|
|
|
|
2023-04-03 09:36:50 -05:00
|
|
|
#[derive(Diagnostic)] //~ ERROR cannot find value `__code_34` in this scope
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-17 12:41:49 -05:00
|
|
|
struct SuggestionsInvalidLiteral {
|
|
|
|
#[suggestion(code = 3)]
|
2023-07-26 03:42:40 -05:00
|
|
|
//~^ ERROR failed to resolve: maybe a missing crate `core`
|
2022-10-17 12:41:49 -05:00
|
|
|
sub: Span,
|
|
|
|
}
|
2022-10-20 13:28:24 -05:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-20 13:28:24 -05:00
|
|
|
struct SuggestionStyleGood {
|
|
|
|
#[suggestion(code = "", style = "hidden")]
|
|
|
|
sub: Span,
|
|
|
|
}
|
2022-10-16 09:15:39 -05:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-13 04:13:02 -05:00
|
|
|
#[diag(no_crate_example)]
|
2022-10-16 09:15:39 -05:00
|
|
|
struct SuggestionOnVec {
|
2022-10-13 04:13:02 -05:00
|
|
|
#[suggestion(no_crate_suggestion, code = "")]
|
2022-10-16 09:15:39 -05:00
|
|
|
//~^ ERROR `#[suggestion(...)]` is not a valid attribute
|
|
|
|
sub: Vec<Span>,
|
|
|
|
}
|