Skip to content

Commit a134cd4

Browse files
committed
SessionSubdiagnostic: make #[applicability] optional
1 parent 4c27952 commit a134cd4

File tree

3 files changed

+13
-55
lines changed

3 files changed

+13
-55
lines changed

compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,10 @@ impl<'a> SessionSubdiagnosticDeriveBuilder<'a> {
469469
};
470470

471471
let span_field = self.span_field.as_ref().map(|(span, _)| span);
472-
let applicability = match self.applicability.clone() {
473-
Some((applicability, _)) => Some(applicability),
474-
None if is_suggestion => {
475-
span_err(self.span, "suggestion without `applicability`").emit();
476-
Some(quote! { rustc_errors::Applicability::Unspecified })
477-
}
478-
None => None,
479-
};
472+
let applicability = self.applicability.take().map_or_else(
473+
|| quote! { rustc_errors::Applicability::Unspecified },
474+
|(applicability, _)| applicability,
475+
);
480476

481477
let diag = &self.diag;
482478
let name = format_ident!("{}{}", if span_field.is_some() { "span_" } else { "" }, kind);

src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ struct AK {
401401

402402
#[derive(SessionSubdiagnostic)]
403403
#[suggestion(parser::add_paren, code = "...")]
404-
//~^ ERROR suggestion without `applicability`
405404
struct AL {
406405
#[primary_span]
407406
span: Span,
@@ -412,7 +411,6 @@ struct AL {
412411

413412
#[derive(SessionSubdiagnostic)]
414413
#[suggestion(parser::add_paren, code = "...")]
415-
//~^ ERROR suggestion without `applicability`
416414
struct AM {
417415
#[primary_span]
418416
span: Span,
@@ -448,8 +446,7 @@ struct AQ;
448446

449447
#[derive(SessionSubdiagnostic)]
450448
#[suggestion(parser::add_paren, code = "...")]
451-
//~^ ERROR suggestion without `applicability`
452-
//~^^ ERROR suggestion without `#[primary_span]` field
449+
//~^ ERROR suggestion without `#[primary_span]` field
453450
struct AR {
454451
var: String,
455452
}

src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -249,36 +249,13 @@ LL | #[applicability]
249249
| ^^^^^^^^^^^^^^^^
250250

251251
error: the `#[applicability]` attribute can only be applied to fields of type `Applicability`
252-
--> $DIR/subdiagnostic-derive.rs:408:5
252+
--> $DIR/subdiagnostic-derive.rs:407:5
253253
|
254254
LL | #[applicability]
255255
| ^^^^^^^^^^^^^^^^
256256

257-
error: suggestion without `applicability`
258-
--> $DIR/subdiagnostic-derive.rs:403:1
259-
|
260-
LL | / #[suggestion(parser::add_paren, code = "...")]
261-
LL | |
262-
LL | | struct AL {
263-
LL | | #[primary_span]
264-
... |
265-
LL | | applicability: Span,
266-
LL | | }
267-
| |_^
268-
269-
error: suggestion without `applicability`
270-
--> $DIR/subdiagnostic-derive.rs:414:1
271-
|
272-
LL | / #[suggestion(parser::add_paren, code = "...")]
273-
LL | |
274-
LL | | struct AM {
275-
LL | | #[primary_span]
276-
LL | | span: Span,
277-
LL | | }
278-
| |_^
279-
280257
error: suggestion without `code = "..."`
281-
--> $DIR/subdiagnostic-derive.rs:422:1
258+
--> $DIR/subdiagnostic-derive.rs:420:1
282259
|
283260
LL | / #[suggestion(parser::add_paren)]
284261
LL | |
@@ -290,47 +267,35 @@ LL | | }
290267
| |_^
291268

292269
error: invalid applicability
293-
--> $DIR/subdiagnostic-derive.rs:432:46
270+
--> $DIR/subdiagnostic-derive.rs:430:46
294271
|
295272
LL | #[suggestion(parser::add_paren, code ="...", applicability = "foo")]
296273
| ^^^^^^^^^^^^^^^^^^^^^
297274

298-
error: suggestion without `applicability`
299-
--> $DIR/subdiagnostic-derive.rs:450:1
300-
|
301-
LL | / #[suggestion(parser::add_paren, code = "...")]
302-
LL | |
303-
LL | |
304-
LL | | struct AR {
305-
LL | | var: String,
306-
LL | | }
307-
| |_^
308-
309275
error: suggestion without `#[primary_span]` field
310-
--> $DIR/subdiagnostic-derive.rs:450:1
276+
--> $DIR/subdiagnostic-derive.rs:448:1
311277
|
312278
LL | / #[suggestion(parser::add_paren, code = "...")]
313279
LL | |
314-
LL | |
315280
LL | | struct AR {
316281
LL | | var: String,
317282
LL | | }
318283
| |_^
319284

320285
error: unsupported type attribute for subdiagnostic enum
321-
--> $DIR/subdiagnostic-derive.rs:465:1
286+
--> $DIR/subdiagnostic-derive.rs:462:1
322287
|
323288
LL | #[label]
324289
| ^^^^^^^^
325290

326291
error: `var` doesn't refer to a field on this type
327-
--> $DIR/subdiagnostic-derive.rs:485:39
292+
--> $DIR/subdiagnostic-derive.rs:482:39
328293
|
329294
LL | #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
330295
| ^^^^^^^
331296

332297
error: `var` doesn't refer to a field on this type
333-
--> $DIR/subdiagnostic-derive.rs:504:43
298+
--> $DIR/subdiagnostic-derive.rs:501:43
334299
|
335300
LL | #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
336301
| ^^^^^^^
@@ -395,6 +360,6 @@ error[E0425]: cannot find value `slug` in module `rustc_errors::fluent`
395360
LL | #[label(slug)]
396361
| ^^^^ not found in `rustc_errors::fluent`
397362

398-
error: aborting due to 52 previous errors
363+
error: aborting due to 49 previous errors
399364

400365
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)