Skip to content

Commit 8100541

Browse files
committed
macros: rename #[message] to #[primary_span]
Small commit renaming `#[message]` to `#[primary_span]` as this more accurately reflects what it does now. Signed-off-by: David Wood <david.wood@huawei.com>
1 parent d0fd8d7 commit 8100541

File tree

5 files changed

+31
-34
lines changed

5 files changed

+31
-34
lines changed

compiler/rustc_macros/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,8 @@ decl_derive!(
6666
// struct attributes
6767
warning,
6868
error,
69-
// nested parts of struct attributes
70-
code,
71-
slug,
7269
// field attributes
73-
message,
70+
primary_span,
7471
label,
7572
suggestion,
7673
suggestion_short,

compiler/rustc_macros/src/session_diagnostic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::collections::{BTreeSet, HashMap};
2020
/// pub struct MoveOutOfBorrowError<'tcx> {
2121
/// pub name: Ident,
2222
/// pub ty: Ty<'tcx>,
23-
/// #[message]
23+
/// #[primary_span]
2424
/// #[label = "cannot move out of borrow"]
2525
/// pub span: Span,
2626
/// #[label = "`{ty}` first borrowed here"]
@@ -566,15 +566,15 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
566566
let meta = attr.parse_meta()?;
567567
match meta {
568568
syn::Meta::Path(_) => match name {
569-
"message" => {
569+
"primary_span" => {
570570
if type_matches_path(&info.ty, &["rustc_span", "Span"]) {
571571
return Ok(quote! {
572572
#diag.set_span(*#field_binding);
573573
});
574574
} else {
575575
throw_span_err!(
576576
attr.span().unwrap(),
577-
"the `#[message]` attribute can only be applied to fields of type `Span`"
577+
"the `#[primary_span]` attribute can only be applied to fields of type `Span`"
578578
);
579579
}
580580
}

compiler/rustc_typeck/src/errors.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_span::{symbol::Ident, Span, Symbol};
55
#[derive(SessionDiagnostic)]
66
#[error(code = "E0062", slug = "typeck-field-multiply-specified-in-initializer")]
77
pub struct FieldMultiplySpecifiedInInitializer {
8-
#[message]
8+
#[primary_span]
99
#[label = "used more than once"]
1010
pub span: Span,
1111
#[label = "first use of `{ident}`"]
@@ -16,7 +16,7 @@ pub struct FieldMultiplySpecifiedInInitializer {
1616
#[derive(SessionDiagnostic)]
1717
#[error(code = "E0092", slug = "typeck-unrecognized-atomic-operation")]
1818
pub struct UnrecognizedAtomicOperation<'a> {
19-
#[message]
19+
#[primary_span]
2020
#[label = "unrecognized atomic operation"]
2121
pub span: Span,
2222
pub op: &'a str,
@@ -25,7 +25,7 @@ pub struct UnrecognizedAtomicOperation<'a> {
2525
#[derive(SessionDiagnostic)]
2626
#[error(code = "E0094", slug = "typeck-wrong-number-of-generic-arguments-to-intrinsic")]
2727
pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
28-
#[message]
28+
#[primary_span]
2929
#[label = "expected {expected} {descr} parameter{expected_pluralize}"]
3030
pub span: Span,
3131
pub found: usize,
@@ -37,7 +37,7 @@ pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
3737
#[derive(SessionDiagnostic)]
3838
#[error(code = "E0093", slug = "typeck-unrecognized-intrinsic-function")]
3939
pub struct UnrecognizedIntrinsicFunction {
40-
#[message]
40+
#[primary_span]
4141
#[label = "unrecognized intrinsic"]
4242
pub span: Span,
4343
pub name: Symbol,
@@ -46,7 +46,7 @@ pub struct UnrecognizedIntrinsicFunction {
4646
#[derive(SessionDiagnostic)]
4747
#[error(code = "E0195", slug = "typeck-lifetimes-or-bounds-mismatch-on-trait")]
4848
pub struct LifetimesOrBoundsMismatchOnTrait {
49-
#[message]
49+
#[primary_span]
5050
#[label = "lifetimes do not match {item_kind} in trait"]
5151
pub span: Span,
5252
#[label = "lifetimes in impl do not match this {item_kind} in trait"]
@@ -58,7 +58,7 @@ pub struct LifetimesOrBoundsMismatchOnTrait {
5858
#[derive(SessionDiagnostic)]
5959
#[error(code = "E0120", slug = "typeck-drop-impl-on-wrong-item")]
6060
pub struct DropImplOnWrongItem {
61-
#[message]
61+
#[primary_span]
6262
#[label = "must be a struct, enum, or union"]
6363
pub span: Span,
6464
}
@@ -67,7 +67,7 @@ pub struct DropImplOnWrongItem {
6767
#[error(code = "E0124", slug = "typeck-field-already-declared")]
6868
pub struct FieldAlreadyDeclared {
6969
pub field_name: Ident,
70-
#[message]
70+
#[primary_span]
7171
#[label = "field already declared"]
7272
pub span: Span,
7373
#[label = "`{field_name}` first declared here"]
@@ -77,67 +77,67 @@ pub struct FieldAlreadyDeclared {
7777
#[derive(SessionDiagnostic)]
7878
#[error(code = "E0184", slug = "typeck-copy-impl-on-type-with-dtor")]
7979
pub struct CopyImplOnTypeWithDtor {
80-
#[message]
80+
#[primary_span]
8181
#[label = "Copy not allowed on types with destructors"]
8282
pub span: Span,
8383
}
8484

8585
#[derive(SessionDiagnostic)]
8686
#[error(code = "E0203", slug = "typeck-multiple-relaxed-default-bounds")]
8787
pub struct MultipleRelaxedDefaultBounds {
88-
#[message]
88+
#[primary_span]
8989
pub span: Span,
9090
}
9191

9292
#[derive(SessionDiagnostic)]
9393
#[error(code = "E0206", slug = "typeck-copy-impl-on-non-adt")]
9494
pub struct CopyImplOnNonAdt {
95-
#[message]
95+
#[primary_span]
9696
#[label = "type is not a structure or enumeration"]
9797
pub span: Span,
9898
}
9999

100100
#[derive(SessionDiagnostic)]
101101
#[error(code = "E0224", slug = "typeck-trait-object-declared-with-no-traits")]
102102
pub struct TraitObjectDeclaredWithNoTraits {
103-
#[message]
103+
#[primary_span]
104104
pub span: Span,
105105
}
106106

107107
#[derive(SessionDiagnostic)]
108108
#[error(code = "E0227", slug = "typeck-ambiguous-lifetime-bound")]
109109
pub struct AmbiguousLifetimeBound {
110-
#[message]
110+
#[primary_span]
111111
pub span: Span,
112112
}
113113

114114
#[derive(SessionDiagnostic)]
115115
#[error(code = "E0229", slug = "typeck-assoc-type-binding-not-allowed")]
116116
pub struct AssocTypeBindingNotAllowed {
117-
#[message]
117+
#[primary_span]
118118
#[label = "associated type not allowed here"]
119119
pub span: Span,
120120
}
121121

122122
#[derive(SessionDiagnostic)]
123123
#[error(code = "E0436", slug = "typeck-functional-record-update-on-non-struct")]
124124
pub struct FunctionalRecordUpdateOnNonStruct {
125-
#[message]
125+
#[primary_span]
126126
pub span: Span,
127127
}
128128

129129
#[derive(SessionDiagnostic)]
130130
#[error(code = "E0516", slug = "typeck-typeof-reserved-keyword-used")]
131131
pub struct TypeofReservedKeywordUsed {
132-
#[message]
132+
#[primary_span]
133133
#[label = "reserved keyword"]
134134
pub span: Span,
135135
}
136136

137137
#[derive(SessionDiagnostic)]
138138
#[error(code = "E0572", slug = "typeck-return-stmt-outside-of-fn-body")]
139139
pub struct ReturnStmtOutsideOfFnBody {
140-
#[message]
140+
#[primary_span]
141141
pub span: Span,
142142
#[label = "the return is part of this body..."]
143143
pub encl_body_span: Option<Span>,
@@ -148,29 +148,29 @@ pub struct ReturnStmtOutsideOfFnBody {
148148
#[derive(SessionDiagnostic)]
149149
#[error(code = "E0627", slug = "typeck-yield-expr-outside-of-generator")]
150150
pub struct YieldExprOutsideOfGenerator {
151-
#[message]
151+
#[primary_span]
152152
pub span: Span,
153153
}
154154

155155
#[derive(SessionDiagnostic)]
156156
#[error(code = "E0639", slug = "typeck-struct-expr-non-exhaustive")]
157157
pub struct StructExprNonExhaustive {
158-
#[message]
158+
#[primary_span]
159159
pub span: Span,
160160
pub what: &'static str,
161161
}
162162

163163
#[derive(SessionDiagnostic)]
164164
#[error(code = "E0699", slug = "typeck-method-call-on-unknown-type")]
165165
pub struct MethodCallOnUnknownType {
166-
#[message]
166+
#[primary_span]
167167
pub span: Span,
168168
}
169169

170170
#[derive(SessionDiagnostic)]
171171
#[error(code = "E0719", slug = "typeck-value-of-associated-struct-already-specified")]
172172
pub struct ValueOfAssociatedStructAlreadySpecified {
173-
#[message]
173+
#[primary_span]
174174
#[label = "re-bound here"]
175175
pub span: Span,
176176
#[label = "`{item_name}` bound here first"]
@@ -182,7 +182,7 @@ pub struct ValueOfAssociatedStructAlreadySpecified {
182182
#[derive(SessionDiagnostic)]
183183
#[error(code = "E0745", slug = "typeck-address-of-temporary-taken")]
184184
pub struct AddressOfTemporaryTaken {
185-
#[message]
185+
#[primary_span]
186186
#[label = "temporary value"]
187187
pub span: Span,
188188
}

src/test/ui-fulldeps/session-derive-errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ struct CodeNotProvided {}
121121
#[derive(SessionDiagnostic)]
122122
#[error(code = "E0123", slug = "foo")]
123123
struct MessageWrongType {
124-
#[message]
125-
//~^ ERROR `#[message]` attribute can only be applied to fields of type `Span`
124+
#[primary_span]
125+
//~^ ERROR `#[primary_span]` attribute can only be applied to fields of type `Span`
126126
foo: String,
127127
}
128128

@@ -295,7 +295,7 @@ struct OptionsInErrors {
295295
struct MoveOutOfBorrowError<'tcx> {
296296
name: Ident,
297297
ty: Ty<'tcx>,
298-
#[message]
298+
#[primary_span]
299299
#[label = "cannot move out of borrow"]
300300
span: Span,
301301
#[label = "`{ty}` first borrowed here"]

src/test/ui-fulldeps/session-derive-errors.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ LL | | struct CodeNotProvided {}
156156
|
157157
= help: use the `#[error(code = "...")]` attribute to set this diagnostic's error code
158158

159-
error: the `#[message]` attribute can only be applied to fields of type `Span`
159+
error: the `#[primary_span]` attribute can only be applied to fields of type `Span`
160160
--> $DIR/session-derive-errors.rs:124:5
161161
|
162-
LL | #[message]
163-
| ^^^^^^^^^^
162+
LL | #[primary_span]
163+
| ^^^^^^^^^^^^^^^
164164

165165
error: `#[nonsense]` is not a valid `SessionDiagnostic` field attribute
166166
--> $DIR/session-derive-errors.rs:132:5

0 commit comments

Comments
 (0)