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:
|
|
|
|
// 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
|
|
|
|
|
|
|
extern crate rustc_macros;
|
2022-09-18 10:47:31 -05:00
|
|
|
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-07-11 11:15:31 -05:00
|
|
|
use rustc_errors::{Applicability, MultiSpan};
|
2020-08-27 05:00:21 -05:00
|
|
|
|
|
|
|
extern crate rustc_session;
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-08-19 08:40:48 -05:00
|
|
|
#[diag = "E0123"]
|
|
|
|
//~^ ERROR `#[diag = ...]` is not a valid attribute
|
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-22 04:08:09 -05:00
|
|
|
#[nonsense(compiletest_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")]
|
|
|
|
//~^ ERROR `#[diag("...")]` is not a valid attribute
|
2022-06-23 08:51:44 -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-06-23 08:51:44 -05:00
|
|
|
//~^ ERROR cannot find value `nonsense` in module `rustc_errors::fluent`
|
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")]
|
|
|
|
//~^ ERROR `#[diag(nonsense(...))]` is not a valid attribute
|
2022-06-23 08:51:44 -05:00
|
|
|
//~^^ 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")]
|
|
|
|
//~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute
|
2022-09-14 10:19:40 -05:00
|
|
|
//~| ERROR `#[diag(slug = ...)]` is not a valid attribute
|
|
|
|
//~| 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")]
|
|
|
|
//~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute
|
2022-09-14 10:19:40 -05:00
|
|
|
//~| ERROR `#[diag(slug = ...)]` is not a valid attribute
|
|
|
|
//~| 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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123", slug = "foo")]
|
2022-08-19 08:40:48 -05:00
|
|
|
//~^ ERROR `#[diag(slug = ...)]` is not a valid attribute
|
2022-06-23 08:51:44 -05:00
|
|
|
struct InvalidNestedStructAttr4 {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, compiletest_example, code = "E0456")]
|
|
|
|
//~^ ERROR `#[diag(compiletest_example)]` is not a valid attribute
|
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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example)]
|
2022-03-31 02:35:17 -05:00
|
|
|
struct CodeNotProvided {}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct ErrorWithField {
|
|
|
|
name: String,
|
2022-10-22 04:08:09 -05:00
|
|
|
#[label(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct ErrorWithMessageAppliedToField {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[label(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct ErrorWithNonexistentField {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct ErrorMissingClosingBrace {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct ErrorMissingOpeningBrace {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct LabelOnSpan {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[label(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct LabelOnNonSpan {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[label(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct Suggest {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(suggestion, code = "This is the suggested code")]
|
2022-10-22 10:21:11 -05:00
|
|
|
#[suggestion(suggestion, code = "This is the suggested code", style = "normal")]
|
|
|
|
#[suggestion(suggestion, code = "This is the suggested code", style = "short")]
|
|
|
|
#[suggestion(suggestion, code = "This is the suggested code", style = "hidden")]
|
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithoutCode {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithBadKey {
|
2022-03-31 07:10:13 -05:00
|
|
|
#[suggestion(nonsense = "bar")]
|
2022-04-26 22:06:13 -05:00
|
|
|
//~^ ERROR `#[suggestion(nonsense = ...)]` is not a valid 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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithShorthandMsg {
|
2022-03-31 07:10:13 -05:00
|
|
|
#[suggestion(msg = "bar")]
|
2022-04-26 22:06:13 -05:00
|
|
|
//~^ ERROR `#[suggestion(msg = ...)]` is not a valid 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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithTypesSwapped {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithWrongTypeApplicabilityOnly {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-03-30 04:04:03 -05:00
|
|
|
struct SuggestWithSpanOnly {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithDuplicateSpanAndApplicability {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct SuggestWithDuplicateApplicabilityAndSpan {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct OptionsInErrors {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[label(label)]
|
2020-08-27 05:00:21 -05:00
|
|
|
label: Option<Span>,
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[label(label)]
|
2020-08-27 05:00:21 -05:00
|
|
|
span: Span,
|
2022-10-22 04:08:09 -05:00
|
|
|
#[label(label)]
|
2020-08-27 05:00:21 -05:00
|
|
|
other_span: Span,
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2020-08-27 05:00:21 -05:00
|
|
|
struct ErrorWithLifetime<'a> {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[label(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-05-07 01:26:03 -05:00
|
|
|
//~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-03-31 03:02:31 -05:00
|
|
|
struct ArgFieldWithoutSkip {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
other: Hello,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-03-31 06:10:00 -05:00
|
|
|
struct ErrorWithSpannedNoteCustom {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[note(note)]
|
2022-03-31 06:10:00 -05:00
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
|
|
|
#[note(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-03-31 06:10:00 -05:00
|
|
|
struct ErrorWithSpannedHelpCustom {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[help(help)]
|
2022-03-31 06:10:00 -05:00
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
|
|
|
#[help(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[help(help)]
|
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[note(note)]
|
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-04-26 23:43:36 -05:00
|
|
|
struct ApplicabilityInBoth {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-04-26 23:43:36 -05:00
|
|
|
struct InvalidApplicability {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-04-26 23:43:36 -05:00
|
|
|
struct ValidApplicability {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-04-26 23:43:36 -05:00
|
|
|
struct NoApplicability {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-11-07 17:42:00 -06:00
|
|
|
#[note(parse_add_paren)]
|
2022-04-26 23:59:48 -05:00
|
|
|
struct Note;
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-05-07 00:02:11 -05:00
|
|
|
struct UnitField {
|
|
|
|
#[primary_span]
|
|
|
|
spans: Span,
|
|
|
|
#[help]
|
|
|
|
foo: (),
|
2022-10-22 04:08:09 -05:00
|
|
|
#[help(help)]
|
2022-05-07 00:02:11 -05:00
|
|
|
bar: (),
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-05-07 00:02:11 -05:00
|
|
|
struct OptUnitField {
|
|
|
|
#[primary_span]
|
|
|
|
spans: Span,
|
|
|
|
#[help]
|
|
|
|
foo: Option<()>,
|
2022-10-22 04:08:09 -05:00
|
|
|
#[help(help)]
|
2022-05-07 00:02:11 -05:00
|
|
|
bar: Option<()>,
|
|
|
|
}
|
2022-06-23 08:51:44 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-06-23 08:51:44 -05:00
|
|
|
struct LabelWithTrailingPath {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[label(label, foo)]
|
2022-09-14 10:19:40 -05:00
|
|
|
//~^ ERROR `#[label(foo)]` is not a valid attribute
|
2022-06-23 08:51:44 -05:00
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-06-23 08:51:44 -05:00
|
|
|
struct LabelWithTrailingNameValue {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[label(label, foo = "...")]
|
2022-09-14 10:19:40 -05:00
|
|
|
//~^ ERROR `#[label(foo = ...)]` is not a valid attribute
|
2022-06-23 08:51:44 -05:00
|
|
|
span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-06-23 08:51:44 -05:00
|
|
|
struct LabelWithTrailingList {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[label(label, foo("..."))]
|
2022-09-14 10:19:40 -05:00
|
|
|
//~^ ERROR `#[label(foo(...))]` is not a valid attribute
|
2022-06-23 08:51:44 -05:00
|
|
|
span: Span,
|
|
|
|
}
|
2022-06-30 02:57:45 -05:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example)]
|
2022-10-20 14:09:54 -05:00
|
|
|
struct LintsGood {}
|
2022-06-30 02:57:45 -05:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[error(compiletest_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-22 04:08:09 -05:00
|
|
|
#[warn_(compiletest_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-22 04:08:09 -05:00
|
|
|
#[lint(compiletest_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-22 04:08:09 -05:00
|
|
|
#[lint(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-09-10 07:28:12 -05:00
|
|
|
struct DuplicatedSuggestionCode {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-09-10 07:43:07 -05:00
|
|
|
struct InvalidTypeInSuggestionTuple {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(suggestion, code = "...")]
|
2022-09-10 07:43:07 -05:00
|
|
|
suggestion: (Span, usize),
|
|
|
|
//~^ ERROR wrong types for suggestion
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-09-10 07:43:07 -05:00
|
|
|
struct MissingApplicabilityInSuggestionTuple {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
2022-09-14 10:19:40 -05:00
|
|
|
struct MissingCodeInSuggestion {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[suggestion(suggestion)]
|
2022-09-14 10:19:40 -05:00
|
|
|
//~^ ERROR suggestion without `code = "..."`
|
|
|
|
suggestion: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
|
|
|
#[multipart_suggestion(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()]
|
|
|
|
//~^ ERROR `#[multipart_suggestion(...)]` is not a valid attribute
|
|
|
|
//~| ERROR cannot find attribute `multipart_suggestion` in this scope
|
|
|
|
struct MultipartSuggestion {
|
2022-10-22 04:08:09 -05:00
|
|
|
#[multipart_suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example, code = "E0123")]
|
|
|
|
#[suggestion(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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example)]
|
2022-09-23 06:49:02 -05:00
|
|
|
Foo {
|
|
|
|
#[primary_span]
|
|
|
|
sp: Span,
|
|
|
|
#[note]
|
|
|
|
note_sp: Span,
|
|
|
|
},
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example)]
|
2022-09-23 06:49:02 -05:00
|
|
|
Bar {
|
|
|
|
#[primary_span]
|
|
|
|
sp: Span,
|
|
|
|
},
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example)]
|
2022-09-23 06:49:02 -05:00
|
|
|
Baz,
|
|
|
|
}
|
2022-09-14 13:12:22 -05:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example)]
|
2022-10-03 08:24:17 -05:00
|
|
|
struct SubdiagnosticBad {
|
|
|
|
#[subdiagnostic(bad)]
|
2022-12-03 18:13:21 -06:00
|
|
|
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
|
2022-10-03 08:24:17 -05:00
|
|
|
note: Note,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example)]
|
2022-10-03 08:24:17 -05:00
|
|
|
struct SubdiagnosticBadTwice {
|
|
|
|
#[subdiagnostic(bad, 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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_example)]
|
2022-10-03 08:24:17 -05:00
|
|
|
struct SubdiagnosticBadLitStr {
|
|
|
|
#[subdiagnostic("bad")]
|
2022-12-03 18:13:21 -06:00
|
|
|
//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
|
2022-10-03 08:24:17 -05:00
|
|
|
note: Note,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 10:21:11 -05:00
|
|
|
#[suggestion(use_instead, 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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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-22 04:08:09 -05:00
|
|
|
#[diag(compiletest_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)]
|
|
|
|
#[diag(compiletest_example)]
|
|
|
|
struct SuggestionsGood {
|
|
|
|
#[suggestion(code("foo", "bar"))]
|
|
|
|
sub: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(compiletest_example)]
|
|
|
|
struct SuggestionsSingleItem {
|
|
|
|
#[suggestion(code("foo"))]
|
|
|
|
sub: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(compiletest_example)]
|
|
|
|
struct SuggestionsNoItem {
|
|
|
|
#[suggestion(code())]
|
|
|
|
//~^ ERROR expected at least one string literal for `code(...)`
|
|
|
|
sub: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(compiletest_example)]
|
|
|
|
struct SuggestionsInvalidItem {
|
|
|
|
#[suggestion(code(foo))]
|
|
|
|
//~^ ERROR `code(...)` must contain only string literals
|
|
|
|
sub: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(compiletest_example)]
|
|
|
|
struct SuggestionsInvalidLiteral {
|
|
|
|
#[suggestion(code = 3)]
|
|
|
|
//~^ ERROR `code = "..."`/`code(...)` must contain only string literals
|
|
|
|
sub: Span,
|
|
|
|
}
|
2022-10-20 13:28:24 -05:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(compiletest_example)]
|
|
|
|
struct SuggestionStyleGood {
|
|
|
|
#[suggestion(code = "", style = "hidden")]
|
|
|
|
sub: Span,
|
|
|
|
}
|
2022-10-16 09:15:39 -05:00
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(compiletest_example)]
|
|
|
|
struct SuggestionOnVec {
|
|
|
|
#[suggestion(suggestion, code = "")]
|
|
|
|
//~^ ERROR `#[suggestion(...)]` is not a valid attribute
|
|
|
|
sub: Vec<Span>,
|
|
|
|
}
|