Skip to content

Commit d0fd8d7

Browse files
committed
macros: translatable struct attrs and warnings
Signed-off-by: David Wood <david.wood@huawei.com>
1 parent f0de7df commit d0fd8d7

File tree

9 files changed

+727
-274
lines changed

9 files changed

+727
-274
lines changed
Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,87 @@
1-
parser-struct-literal-body-without-path = struct literal body without path
1+
parser-struct-literal-body-without-path =
2+
struct literal body without path
23
.suggestion = you might have forgotten to add the struct literal inside the block
4+
5+
typeck-field-multiply-specified-in-initializer =
6+
field `{$ident}` specified more than once
7+
.label = used more than once
8+
.previous-use-label = first use of `{$ident}`
9+
10+
typeck-unrecognized-atomic-operation =
11+
unrecognized atomic operation function: `{$op}`
12+
.label = unrecognized atomic operation
13+
14+
typeck-wrong-number-of-generic-arguments-to-intrinsic =
15+
intrinsic has wrong number of {$descr} parameters: found {$found}, expected {$expected}
16+
.label = expected {$expected} {$descr} {$expected ->
17+
[one] parameter
18+
*[other] parameters
19+
}
20+
21+
typeck-unrecognized-intrinsic-function =
22+
unrecognized intrinsic function: `{$name}`
23+
.label = unrecognized intrinsic
24+
25+
typeck-lifetimes-or-bounds-mismatch-on-trait =
26+
lifetime parameters or bounds on {$item_kind} `{$ident}` do not match the trait declaration
27+
.label = lifetimes do not match {$item_kind} in trait
28+
.generics-label = lifetimes in impl do not match this {$item_kind} in trait
29+
30+
typeck-drop-impl-on-wrong-item =
31+
the `Drop` trait may only be implemented for structs, enums, and unions
32+
.label = must be a struct, enum, or union
33+
34+
typeck-field-already-declared =
35+
field `{$field_name}` is already declared
36+
.label = field already declared
37+
.previous-decl-label = `{$field_name}` first declared here
38+
39+
typeck-copy-impl-on-type-with-dtor =
40+
the trait `Copy` may not be implemented for this type; the type has a destructor
41+
.label = `Copy` not allowed on types with destructors
42+
43+
typeck-multiple-relaxed-default-bounds =
44+
type parameter has more than one relaxed default bound, only one is supported
45+
46+
typeck-copy-impl-on-non-adt =
47+
the trait `Copy` may not be implemented for this type
48+
.label = type is not a structure or enumeration
49+
50+
typeck-trait-object-declared-with-no-traits =
51+
at least one trait is required for an object type
52+
53+
typeck-ambiguous-lifetime-bound =
54+
ambiguous lifetime bound, explicit lifetime bound required
55+
56+
typeck-assoc-type-binding-not-allowed =
57+
associated type bindings are not allowed here
58+
.label = associated type not allowed here
59+
60+
typeck-functional-record-update-on-non-struct =
61+
functional record update syntax requires a struct
62+
63+
typeck-typeof-reserved-keyword-used =
64+
`typeof` is a reserved keyword but unimplemented
65+
.label = reserved keyword
66+
67+
typeck-return-stmt-outside-of-fn-body =
68+
return statement outside of function body
69+
.encl-body-label = the return is part of this body...
70+
.encl-fn-label = ...not the enclosing function body
71+
72+
typeck-yield-expr-outside-of-generator =
73+
yield expression outside of generator literal
74+
75+
typeck-struct-expr-non-exhaustive =
76+
cannot create non-exhaustive {$what} using struct expression
77+
78+
typeck-method-call-on-unknown-type =
79+
the type of this value must be known to call a method on a raw pointer on it
80+
81+
typeck-value-of-associated-struct-already-specified =
82+
the value of the associated type `{$item_name}` (from trait `{$def_path}`) is already specified
83+
.label = re-bound here
84+
.previous-bound-label = `{$item_name}` bound here first
85+
86+
typeck-address-of-temporary-taken = cannot take address of a temporary
87+
.label = temporary value

compiler/rustc_errors/src/emitter.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ pub trait Emitter {
261261
message: &'a DiagnosticMessage,
262262
args: &'a FluentArgs<'_>,
263263
) -> Cow<'_, str> {
264-
trace!(?message);
264+
trace!(?message, ?args);
265265
let (identifier, attr) = match message {
266266
DiagnosticMessage::Str(msg) => return Cow::Borrowed(&msg),
267267
DiagnosticMessage::FluentIdentifier(identifier, attr) => (identifier, attr),
@@ -283,7 +283,13 @@ pub trait Emitter {
283283
let mut err = vec![];
284284
let translated = bundle.format_pattern(value, Some(&args), &mut err);
285285
trace!(?translated, ?err);
286-
debug_assert!(err.is_empty());
286+
debug_assert!(
287+
err.is_empty(),
288+
"identifier: {:?}, args: {:?}, errors: {:?}",
289+
identifier,
290+
args,
291+
err
292+
);
287293
translated
288294
}
289295

compiler/rustc_errors/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,17 @@ impl Handler {
777777
result
778778
}
779779

780+
/// Construct a builder at the `Warn` level with the `msg` and the `code`.
781+
pub fn struct_warn_with_code(
782+
&self,
783+
msg: impl Into<DiagnosticMessage>,
784+
code: DiagnosticId,
785+
) -> DiagnosticBuilder<'_, ()> {
786+
let mut result = self.struct_warn(msg);
787+
result.code(code);
788+
result
789+
}
790+
780791
/// Construct a builder at the `Fatal` level at the given `span` and with the `msg`.
781792
pub fn struct_span_fatal(
782793
&self,

compiler/rustc_macros/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@ decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_fo
6363
decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
6464
decl_derive!(
6565
[SessionDiagnostic, attributes(
66-
message,
67-
lint,
66+
// struct attributes
67+
warning,
6868
error,
69+
// nested parts of struct attributes
70+
code,
71+
slug,
72+
// field attributes
73+
message,
6974
label,
7075
suggestion,
7176
suggestion_short,

0 commit comments

Comments
 (0)