554: Better errors on when missing to lock shared resources r=perlindgren a=korken89

Old error:

```
error[E0614]: type `value<'_>` cannot be dereferenced
  --> examples/lock_minimal.rs:33:9
   |
33 |         *c.shared.value += 1;
   |         ^^^^^^^^^^^^^^^

```

New error:

```
error[E0614]: type `value_that_needs_to_be_locked<'_>` cannot be dereferenced
  --> examples/lock_minimal.rs:33:9
   |
33 |         *c.shared.value += 1;
   |         ^^^^^^^^^^^^^^^

```

Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
This commit is contained in:
bors[bot] 2021-11-11 13:32:35 +00:00 committed by GitHub
commit 4f2dd875ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View file

@ -43,21 +43,23 @@ pub fn codegen(
// For future use // For future use
// let doc = format!(" RTIC internal: {}:{}", file!(), line!()); // let doc = format!(" RTIC internal: {}:{}", file!(), line!());
let shared_name = util::need_to_lock_ident(name);
if !res.properties.lock_free { if !res.properties.lock_free {
mod_resources.push(quote!( mod_resources.push(quote!(
// #[doc = #doc] // #[doc = #doc]
#[doc(hidden)] #[doc(hidden)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
#(#cfgs)* #(#cfgs)*
pub struct #name<'a> { pub struct #shared_name<'a> {
priority: &'a Priority, priority: &'a Priority,
} }
#(#cfgs)* #(#cfgs)*
impl<'a> #name<'a> { impl<'a> #shared_name<'a> {
#[inline(always)] #[inline(always)]
pub unsafe fn new(priority: &'a Priority) -> Self { pub unsafe fn new(priority: &'a Priority) -> Self {
#name { priority } #shared_name { priority }
} }
#[inline(always)] #[inline(always)]
@ -86,7 +88,7 @@ pub fn codegen(
extra, extra,
cfgs, cfgs,
true, true,
&name, &shared_name,
quote!(#ty), quote!(#ty),
ceiling, ceiling,
ptr, ptr,

View file

@ -33,6 +33,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
}; };
let ty = &res.ty; let ty = &res.ty;
let mangled_name = util::static_shared_resource_ident(&name); let mangled_name = util::static_shared_resource_ident(&name);
let shared_name = util::need_to_lock_ident(name);
if !res.properties.lock_free { if !res.properties.lock_free {
if access.is_shared() { if access.is_shared() {
@ -48,12 +49,12 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
fields.push(quote!( fields.push(quote!(
#(#cfgs)* #(#cfgs)*
pub #name: shared_resources::#name<'a> pub #name: shared_resources::#shared_name<'a>
)); ));
values.push(quote!( values.push(quote!(
#(#cfgs)* #(#cfgs)*
#name: shared_resources::#name::new(priority) #name: shared_resources::#shared_name::new(priority)
)); ));

View file

@ -268,6 +268,13 @@ pub fn declared_static_local_resource_ident(name: &Ident, task_name: &Ident) ->
)) ))
} }
pub fn need_to_lock_ident(name: &Ident) -> Ident {
Ident::new(
&format!("{}_that_needs_to_be_locked", name.to_string()),
name.span(),
)
}
/// The name to get better RT flag errors /// The name to get better RT flag errors
pub fn rt_err_ident() -> Ident { pub fn rt_err_ident() -> Ident {
Ident::new( Ident::new(