Skip to content

Commit 5b5bb7a

Browse files
committed
fix: init: macro hygiene bug
Signed-off-by: Mirko Adzic <adzicmirko97@gmail.com>
1 parent e6e742b commit 5b5bb7a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

internal/src/init.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,23 @@ fn init_fields(
240240
};
241241
let init = match kind {
242242
InitializerKind::Value { ident, value } => {
243-
let (value_ident, value_prep) = match value.as_ref() {
243+
let (value_prep, value_ident) = match value.as_ref() {
244244
None => {
245245
// This is of short-hand syntax, so just use the identifier directly.
246-
(ident.clone(), None)
246+
(None, ident.clone())
247247
}
248248
Some((_, value)) => {
249249
// We have an expression. Evaluate it to a local variable first, outside
250250
// `unsafe {}` block.
251251
//
252252
// Setting the span of `value_ident` to `value`'s span improves error messages
253253
// when the type of `value` is wrong.
254+
let value_ident = format_ident!("value", span = value.span());
254255
(
255-
format_ident!("value", span = value.span()),
256256
Some(quote! {
257-
let value = #value;
257+
let #value_ident = #value;
258258
}),
259+
value_ident,
259260
)
260261
}
261262
};

0 commit comments

Comments
 (0)