2 // Tests error conditions for specifying subdiagnostics using #[derive(SessionSubdiagnostic)]
4 // The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly,
5 // changing the output of this test. Since SessionSubdiagnostic is strictly internal to the compiler
6 // the test is just ignored on stable and beta:
10 #![feature(rustc_private)]
11 #![crate_type = "lib"]
13 extern crate rustc_errors;
14 extern crate rustc_session;
15 extern crate rustc_span;
16 extern crate rustc_macros;
18 use rustc_errors::Applicability;
20 use rustc_macros::SessionSubdiagnostic;
22 #[derive(SessionSubdiagnostic)]
23 #[label(parser::add_paren)]
30 #[derive(SessionSubdiagnostic)]
32 #[label(parser::add_paren)]
38 #[label(parser::add_paren)]
46 #[derive(SessionSubdiagnostic)]
47 #[label(parser::add_paren)]
48 //~^ ERROR label without `#[primary_span]` field
53 #[derive(SessionSubdiagnostic)]
55 //~^ ERROR `#[label]` is not a valid attribute
62 #[derive(SessionSubdiagnostic)]
64 //~^ ERROR `#[foo]` is not a valid attribute
65 //~^^ ERROR cannot find attribute `foo` in this scope
72 #[derive(SessionSubdiagnostic)]
74 //~^ ERROR `#[label = ...]` is not a valid attribute
81 #[derive(SessionSubdiagnostic)]
83 //~^ ERROR `#[label(bug = ...)]` is not a valid attribute
90 #[derive(SessionSubdiagnostic)]
92 //~^ ERROR `#[label("...")]` is not a valid attribute
99 #[derive(SessionSubdiagnostic)]
101 //~^ ERROR `#[label(slug = ...)]` is not a valid attribute
108 #[derive(SessionSubdiagnostic)]
109 #[label(slug("..."))]
110 //~^ ERROR `#[label(slug(...))]` is not a valid attribute
117 #[derive(SessionSubdiagnostic)]
119 //~^ ERROR cannot find value `slug` in module `rustc_errors::fluent`
120 //~^^ NOTE not found in `rustc_errors::fluent`
127 #[derive(SessionSubdiagnostic)]
129 //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
136 #[derive(SessionSubdiagnostic)]
137 #[label(parser::add_paren, code = "...")]
138 //~^ ERROR `code` is not a valid nested attribute of a `label` attribute
145 #[derive(SessionSubdiagnostic)]
146 #[label(parser::add_paren, applicability = "machine-applicable")]
147 //~^ ERROR `applicability` is not a valid nested attribute of a `label` attribute
154 #[derive(SessionSubdiagnostic)]
156 //~^ ERROR cannot find attribute `foo` in this scope
157 //~^^ ERROR unsupported type attribute for subdiagnostic enum
159 #[label(parser::add_paren)]
167 #[derive(SessionSubdiagnostic)]
170 //~^ ERROR `#[bar]` is not a valid attribute
171 //~^^ ERROR cannot find attribute `bar` in this scope
179 #[derive(SessionSubdiagnostic)]
182 //~^ ERROR `#[bar = ...]` is not a valid attribute
183 //~^^ ERROR cannot find attribute `bar` in this scope
191 #[derive(SessionSubdiagnostic)]
194 //~^ ERROR `#[bar = ...]` is not a valid attribute
195 //~^^ ERROR cannot find attribute `bar` in this scope
203 #[derive(SessionSubdiagnostic)]
206 //~^ ERROR `#[bar(...)]` is not a valid attribute
207 //~^^ ERROR cannot find attribute `bar` in this scope
215 #[derive(SessionSubdiagnostic)]
217 #[label(code = "...")]
218 //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
226 #[derive(SessionSubdiagnostic)]
228 #[label(parser::add_paren)]
235 //~^ ERROR subdiagnostic kind not specified
242 #[derive(SessionSubdiagnostic)]
243 #[label(parser::add_paren)]
244 //~^ ERROR label without `#[primary_span]` field
247 //~^ ERROR the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan`
251 #[derive(SessionSubdiagnostic)]
252 #[label(parser::add_paren)]
257 //~^ ERROR `#[applicability]` is only valid on suggestions
258 applicability: Applicability,
261 #[derive(SessionSubdiagnostic)]
262 #[label(parser::add_paren)]
267 //~^ ERROR `#[bar]` is not a valid attribute
268 //~^^ ERROR cannot find attribute `bar` in this scope
272 #[derive(SessionSubdiagnostic)]
273 #[label(parser::add_paren)]
278 //~^ ERROR `#[bar = ...]` is not a valid attribute
279 //~^^ ERROR cannot find attribute `bar` in this scope
283 #[derive(SessionSubdiagnostic)]
284 #[label(parser::add_paren)]
289 //~^ ERROR `#[bar(...)]` is not a valid attribute
290 //~^^ ERROR cannot find attribute `bar` in this scope
294 #[derive(SessionSubdiagnostic)]
295 #[label(parser::add_paren)]
303 #[derive(SessionSubdiagnostic)]
305 //~^ ERROR unexpected unsupported untagged union
310 #[derive(SessionSubdiagnostic)]
311 #[label(parser::add_paren)]
312 //~^ NOTE previously specified here
313 //~^^ NOTE previously specified here
314 #[label(parser::add_paren)]
315 //~^ ERROR specified multiple times
316 //~^^ ERROR specified multiple times
322 #[derive(SessionSubdiagnostic)]
323 #[label(parser::add_paren, parser::add_paren)]
324 //~^ ERROR `#[label(parser::add_paren)]` is not a valid attribute
330 #[derive(SessionSubdiagnostic)]
331 #[label(parser::add_paren)]
334 //~^ NOTE previously specified here
337 //~^ ERROR specified multiple times
341 #[derive(SessionSubdiagnostic)]
343 //~^ ERROR subdiagnostic kind not specified
348 #[derive(SessionSubdiagnostic)]
349 #[suggestion(parser::add_paren, code = "...")]
354 applicability: Applicability,
358 #[derive(SessionSubdiagnostic)]
360 #[suggestion(parser::add_paren, code = "...")]
365 applicability: Applicability,
368 #[suggestion(parser::add_paren, code = "...")]
373 applicability: Applicability,
378 #[derive(SessionSubdiagnostic)]
379 #[suggestion(parser::add_paren, code = "...", code = "...")]
380 //~^ ERROR specified multiple times
381 //~^^ NOTE previously specified here
386 applicability: Applicability,
389 #[derive(SessionSubdiagnostic)]
390 #[suggestion(parser::add_paren, code = "...")]
395 //~^ NOTE previously specified here
396 applicability_a: Applicability,
398 //~^ ERROR specified multiple times
399 applicability_b: Applicability,
402 #[derive(SessionSubdiagnostic)]
403 #[suggestion(parser::add_paren, code = "...")]
408 //~^ ERROR the `#[applicability]` attribute can only be applied to fields of type `Applicability`
412 #[derive(SessionSubdiagnostic)]
413 #[suggestion(parser::add_paren, code = "...")]
419 #[derive(SessionSubdiagnostic)]
420 #[suggestion(parser::add_paren)]
421 //~^ ERROR suggestion without `code = "..."`
426 applicability: Applicability,
429 #[derive(SessionSubdiagnostic)]
430 #[suggestion(parser::add_paren, code ="...", applicability = "foo")]
431 //~^ ERROR invalid applicability
437 #[derive(SessionSubdiagnostic)]
438 #[help(parser::add_paren)]
443 #[derive(SessionSubdiagnostic)]
444 #[note(parser::add_paren)]
447 #[derive(SessionSubdiagnostic)]
448 #[suggestion(parser::add_paren, code = "...")]
449 //~^ ERROR suggestion without `#[primary_span]` field
454 #[derive(SessionSubdiagnostic)]
455 #[suggestion(parser::add_paren, code ="...", applicability = "machine-applicable")]
461 #[derive(SessionSubdiagnostic)]
463 //~^ ERROR unsupported type attribute for subdiagnostic enum
465 #[label(parser::add_paren)]
473 #[derive(SessionSubdiagnostic)]
474 #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
481 #[derive(SessionSubdiagnostic)]
482 #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
483 //~^ ERROR `var` doesn't refer to a field on this type
489 #[derive(SessionSubdiagnostic)]
491 #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
499 #[derive(SessionSubdiagnostic)]
501 #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
502 //~^ ERROR `var` doesn't refer to a field on this type
509 #[derive(SessionSubdiagnostic)]
510 #[warning(parser::add_paren)]
513 #[derive(SessionSubdiagnostic)]
514 #[warning(parser::add_paren)]