aboutsummaryrefslogtreecommitdiff
path: root/macros/src
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2018-11-04 19:46:49 +0100
committerGravatar Jorge Aparicio <jorge@japaric.io> 2018-11-04 19:46:49 +0100
commit22d758ddacddda429c9aaeaa0e132ae1c1fd4a2f (patch)
treeed877bafbc9b926972091c91521cf5a1bdb35529 /macros/src
parent37a0692a0fe5d9b41b65728d496b6856a1152dcc (diff)
downloadrtic-22d758ddacddda429c9aaeaa0e132ae1c1fd4a2f.tar.gz
rtic-22d758ddacddda429c9aaeaa0e132ae1c1fd4a2f.tar.zst
rtic-22d758ddacddda429c9aaeaa0e132ae1c1fd4a2f.zip
fix codegen
Diffstat (limited to 'macros/src')
-rw-r--r--macros/src/codegen.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs
index 6d01d32d..416b0070 100644
--- a/macros/src/codegen.rs
+++ b/macros/src/codegen.rs
@@ -711,18 +711,26 @@ fn prelude(
exprs.push(quote!(#name: <#name as owned_singleton::Singleton>::new()));
} else {
needs_unsafe = true;
- if ownership.is_owned() {
- defs.push(quote!(pub #name: &'a mut #name));
- exprs.push(quote!(
- #name: &mut <#name as owned_singleton::Singleton>::new()
+ if ownership.is_owned() || mut_.is_none() {
+ defs.push(quote!(pub #name: &'a #mut_ #name));
+ let alias = mk_ident();
+ items.push(quote!(
+ let #mut_ #alias = unsafe {
+ <#name as owned_singleton::Singleton>::new()
+ };
));
+ exprs.push(quote!(#name: &#mut_ #alias));
} else {
may_call_lock = true;
defs.push(quote!(pub #name: rtfm::Exclusive<'a, #name>));
+ let alias = mk_ident();
+ items.push(quote!(
+ let #mut_ #alias = unsafe {
+ <#name as owned_singleton::Singleton>::new()
+ };
+ ));
exprs.push(quote!(
- #name: rtfm::Exclusive(
- &mut <#name as owned_singleton::Singleton>::new()
- )
+ #name: rtfm::Exclusive(&mut #alias)
));
}
}