Skip to content

Commit 25fdea0

Browse files
committed
fix errors
1 parent fc01b4b commit 25fdea0

File tree

5 files changed

+113
-105
lines changed

5 files changed

+113
-105
lines changed

compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
422422
list.parse_nested_meta(|nested| {
423423
if nested.path.is_ident("code") {
424424
let code_field = new_code_ident();
425+
let span = nested.path.span().unwrap();
425426
let formatting_init = build_suggestion_code(
426427
&code_field,
427428
nested,

compiler/rustc_macros/src/diagnostics/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ impl SubdiagnosticKind {
727727
fields,
728728
AllowMultipleAlternatives::Yes,
729729
);
730-
code.set_once(code_init, span);
730+
code.set_once(code_init, path_span);
731731
}
732732
(
733733
"applicability",

tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,16 @@ LL | | struct LintAttributeOnLintDiag {}
435435
= help: specify the slug as the first argument to the attribute, such as `#[diag(compiletest_example)]`
436436

437437
error: specified multiple times
438-
--> $DIR/diagnostic-derive.rs:608:5
438+
--> $DIR/diagnostic-derive.rs:608:53
439439
|
440440
LL | #[suggestion(no_crate_suggestion, code = "...", code = ",,,")]
441-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
441+
| ^^^^
442442
|
443443
note: previously specified here
444-
--> $DIR/diagnostic-derive.rs:608:5
444+
--> $DIR/diagnostic-derive.rs:608:39
445445
|
446446
LL | #[suggestion(no_crate_suggestion, code = "...", code = ",,,")]
447-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
447+
| ^^^^
448448

449449
error: wrong types for suggestion
450450
--> $DIR/diagnostic-derive.rs:617:24

tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs

+25-18
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct F {
8282

8383
#[derive(Subdiagnostic)]
8484
#[label(bug = "...")]
85-
//~^ ERROR `#[label(bug = ...)]` is not a valid attribute
85+
//~^ ERROR invalid nested attribute
8686
//~| ERROR diagnostic slug must be first argument
8787
struct G {
8888
#[primary_span]
@@ -92,8 +92,7 @@ struct G {
9292

9393
#[derive(Subdiagnostic)]
9494
#[label("...")]
95-
//~^ ERROR `#[label("...")]` is not a valid attribute
96-
//~| ERROR diagnostic slug must be first argument
95+
//~^ ERROR unexpected literal in nested attribute, expected ident
9796
struct H {
9897
#[primary_span]
9998
span: Span,
@@ -102,7 +101,7 @@ struct H {
102101

103102
#[derive(Subdiagnostic)]
104103
#[label(slug = 4)]
105-
//~^ ERROR `#[label(slug = ...)]` is not a valid attribute
104+
//~^ ERROR invalid nested attribute
106105
//~| ERROR diagnostic slug must be first argument
107106
struct J {
108107
#[primary_span]
@@ -112,7 +111,7 @@ struct J {
112111

113112
#[derive(Subdiagnostic)]
114113
#[label(slug("..."))]
115-
//~^ ERROR `#[label(slug(...))]` is not a valid attribute
114+
//~^ ERROR invalid nested attribute
116115
//~| ERROR diagnostic slug must be first argument
117116
struct K {
118117
#[primary_span]
@@ -132,7 +131,7 @@ struct L {
132131

133132
#[derive(Subdiagnostic)]
134133
#[label()]
135-
//~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
134+
//~^ ERROR unexpected end of input, unexpected token in nested attribute, expected ident
136135
struct M {
137136
#[primary_span]
138137
span: Span,
@@ -141,7 +140,7 @@ struct M {
141140

142141
#[derive(Subdiagnostic)]
143142
#[label(no_crate_example, code = "...")]
144-
//~^ ERROR `#[label(code = ...)]` is not a valid attribute
143+
//~^ ERROR invalid nested attribute
145144
struct N {
146145
#[primary_span]
147146
span: Span,
@@ -150,7 +149,7 @@ struct N {
150149

151150
#[derive(Subdiagnostic)]
152151
#[label(no_crate_example, applicability = "machine-applicable")]
153-
//~^ ERROR `#[label(applicability = ...)]` is not a valid attribute
152+
//~^ ERROR invalid nested attribute
154153
struct O {
155154
#[primary_span]
156155
span: Span,
@@ -222,7 +221,7 @@ enum T {
222221
enum U {
223222
#[label(code = "...")]
224223
//~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
225-
//~| ERROR `#[label(code = ...)]` is not a valid attribute
224+
//~| ERROR invalid nested attribute
226225
A {
227226
#[primary_span]
228227
span: Span,
@@ -323,7 +322,7 @@ struct AD {
323322

324323
#[derive(Subdiagnostic)]
325324
#[label(no_crate_example, no_crate::example)]
326-
//~^ ERROR `#[label(no_crate::example)]` is not a valid attribute
325+
//~^ ERROR a diagnostic slug must be the first argument to the attribute
327326
struct AE {
328327
#[primary_span]
329328
span: Span,
@@ -537,7 +536,7 @@ struct BA {
537536
#[derive(Subdiagnostic)]
538537
#[multipart_suggestion(no_crate_example, code = "...", applicability = "machine-applicable")]
539538
//~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields
540-
//~| ERROR `#[multipart_suggestion(code = ...)]` is not a valid attribute
539+
//~| ERROR invalid nested attribute
541540
struct BBa {
542541
var: String,
543542
}
@@ -554,7 +553,7 @@ struct BBb {
554553
#[multipart_suggestion(no_crate_example, applicability = "machine-applicable")]
555554
struct BBc {
556555
#[suggestion_part()]
557-
//~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
556+
//~^ ERROR unexpected end of input, unexpected token in nested attribute, expected ident
558557
span1: Span,
559558
}
560559

@@ -574,10 +573,11 @@ struct BD {
574573
//~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
575574
span1: Span,
576575
#[suggestion_part()]
577-
//~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
576+
//~^ ERROR unexpected end of input, unexpected token in nested attribute, expected ident
578577
span2: Span,
579578
#[suggestion_part(foo = "bar")]
580-
//~^ ERROR `#[suggestion_part(foo = ...)]` is not a valid attribute
579+
//~^ ERROR `code` is the only valid nested attribute
580+
//~| ERROR expected `,`
581581
span4: Span,
582582
#[suggestion_part(code = "...")]
583583
//~^ ERROR the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
@@ -669,6 +669,7 @@ enum BL {
669669
struct BM {
670670
#[suggestion_part(code("foo"))]
671671
//~^ ERROR expected exactly one string literal for `code = ...`
672+
//~| ERROR unexpected token
672673
span: Span,
673674
r#type: String,
674675
}
@@ -678,6 +679,7 @@ struct BM {
678679
struct BN {
679680
#[suggestion_part(code("foo", "bar"))]
680681
//~^ ERROR expected exactly one string literal for `code = ...`
682+
//~| ERROR unexpected token
681683
span: Span,
682684
r#type: String,
683685
}
@@ -687,6 +689,7 @@ struct BN {
687689
struct BO {
688690
#[suggestion_part(code(3))]
689691
//~^ ERROR expected exactly one string literal for `code = ...`
692+
//~| ERROR unexpected token
690693
span: Span,
691694
r#type: String,
692695
}
@@ -701,10 +704,13 @@ struct BP {
701704
}
702705

703706
#[derive(Subdiagnostic)]
707+
//~^ ERROR cannot find value `__code_29` in this scope
708+
//~| NOTE in this expansion
709+
//~| NOTE not found in this scope
704710
#[multipart_suggestion(no_crate_example)]
705711
struct BQ {
706712
#[suggestion_part(code = 3)]
707-
//~^ ERROR `code = "..."`/`code(...)` must contain only string literals
713+
//~^ ERROR expected string literal
708714
span: Span,
709715
r#type: String,
710716
}
@@ -779,23 +785,24 @@ struct SuggestionStyleInvalid1 {
779785

780786
#[derive(Subdiagnostic)]
781787
#[suggestion(no_crate_example, code = "", style = 42)]
782-
//~^ ERROR `#[suggestion(style = ...)]` is not a valid attribute
788+
//~^ ERROR expected `= "xxx"`
783789
struct SuggestionStyleInvalid2 {
784790
#[primary_span]
785791
sub: Span,
786792
}
787793

788794
#[derive(Subdiagnostic)]
789795
#[suggestion(no_crate_example, code = "", style)]
790-
//~^ ERROR `#[suggestion(style)]` is not a valid attribute
796+
//~^ ERROR a diagnostic slug must be the first argument to the attribute
791797
struct SuggestionStyleInvalid3 {
792798
#[primary_span]
793799
sub: Span,
794800
}
795801

796802
#[derive(Subdiagnostic)]
797803
#[suggestion(no_crate_example, code = "", style("foo"))]
798-
//~^ ERROR `#[suggestion(style(...))]` is not a valid attribute
804+
//~^ ERROR expected `= "xxx"`
805+
//~| ERROr expected `,`
799806
struct SuggestionStyleInvalid4 {
800807
#[primary_span]
801808
sub: Span,

0 commit comments

Comments
 (0)