diff options
author | 2018-11-04 19:46:49 +0100 | |
---|---|---|
committer | 2018-11-04 19:46:49 +0100 | |
commit | 22d758ddacddda429c9aaeaa0e132ae1c1fd4a2f (patch) | |
tree | ed877bafbc9b926972091c91521cf5a1bdb35529 /macros/src/codegen.rs | |
parent | 37a0692a0fe5d9b41b65728d496b6856a1152dcc (diff) | |
download | rtic-22d758ddacddda429c9aaeaa0e132ae1c1fd4a2f.tar.gz rtic-22d758ddacddda429c9aaeaa0e132ae1c1fd4a2f.tar.zst rtic-22d758ddacddda429c9aaeaa0e132ae1c1fd4a2f.zip |
fix codegen
Diffstat (limited to 'macros/src/codegen.rs')
-rw-r--r-- | macros/src/codegen.rs | 22 |
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) )); } } |