Skip to content

Commit f6b0d18

Browse files
committed
Improve RTIC doc handling
Enable use of ``` #![deny(missing_docs)] ```
1 parent 1237f5b commit f6b0d18

File tree

8 files changed

+48
-11
lines changed

8 files changed

+48
-11
lines changed

macros/src/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
187187

188188
#(#root_software_tasks)*
189189

190-
/// app module
190+
/// App module
191191
#(#mod_app)*
192192

193193
#(#mod_app_shared_resources)*

macros/src/codegen/hardware_tasks.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ pub fn codegen(
3333
let priority = task.args.priority;
3434
let cfgs = &task.cfgs;
3535
let attrs = &task.attrs;
36+
let user_hardware_task_isr_doc = &format!(" User HW task ISR trampoline for {name}");
3637

3738
mod_app.push(quote!(
3839
#[allow(non_snake_case)]
3940
#[no_mangle]
41+
#[doc = #user_hardware_task_isr_doc]
4042
#(#attrs)*
4143
#(#cfgs)*
4244
unsafe fn #symbol() {
@@ -88,11 +90,13 @@ pub fn codegen(
8890
extra,
8991
));
9092

93+
let user_hardware_task_doc = &format!(" User HW task: {name}");
9194
if !task.is_extern {
9295
let attrs = &task.attrs;
9396
let context = &task.context;
9497
let stmts = &task.stmts;
9598
user_tasks.push(quote!(
99+
#[doc = #user_hardware_task_doc]
96100
#(#attrs)*
97101
#[allow(non_snake_case)]
98102
fn #name(#context: #name::Context) {

macros/src/codegen/idle.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ pub fn codegen(
5959
analysis,
6060
extra,
6161
));
62+
let idle_doc = &format!(" User provided idle function");
6263

6364
let attrs = &idle.attrs;
6465
let context = &idle.context;
6566
let stmts = &idle.stmts;
6667
let user_idle = Some(quote!(
6768
#(#attrs)*
69+
#[doc = #idle_doc]
6870
#[allow(non_snake_case)]
6971
fn #name(#context: #name::Context) -> ! {
7072
use rtic::Mutex as _;

macros/src/codegen/init.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,27 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult {
6565
)
6666
})
6767
.collect();
68+
69+
let shared_resources_doc = &format!(" RTIC shared resource struct");
70+
let local_resources_doc = &format!(" RTIC local resource struct");
6871
root_init.push(quote! {
72+
#[doc = #shared_resources_doc]
6973
struct #shared {
7074
#(#shared_resources)*
7175
}
7276

77+
#[doc = #local_resources_doc]
7378
struct #local {
7479
#(#local_resources)*
7580
}
7681
});
7782

78-
// let locals_pat = locals_pat.iter();
79-
8083
let user_init_return = quote! {#shared, #local, #name::Monotonics};
84+
let user_init_doc = &format!(" User provided init function");
8185

8286
let user_init = quote!(
8387
#(#attrs)*
88+
#[doc = #user_init_doc]
8489
#[inline(always)]
8590
#[allow(non_snake_case)]
8691
fn #name(#context: #name::Context) -> (#user_init_return) {
@@ -100,7 +105,6 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult {
100105
mod_app = Some(constructor);
101106
}
102107

103-
// let locals_new = locals_new.iter();
104108
let call_init = quote! {
105109
let (shared_resources, local_resources, mut monotonics) = #name(#name::Context::new(core.into()));
106110
};

macros/src/codegen/local_resources_struct.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
4949
util::declared_static_local_resource_ident(name, &task_name)
5050
};
5151

52+
let local_resource_doc = format!(" Local resource `{name}`");
5253
fields.push(quote!(
54+
#[doc = #local_resource_doc]
5355
#(#cfgs)*
5456
pub #name: &#lt mut #ty
5557
));
@@ -82,7 +84,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
8284
}
8385
}
8486

85-
let doc = format!("Local resources `{}` has access to", ctxt.ident(app));
87+
let doc = format!(" Local resources `{}` has access to", ctxt.ident(app));
8688
let ident = util::local_resources_ident(ctxt, app);
8789
let item = quote!(
8890
#[allow(non_snake_case)]
@@ -96,6 +98,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
9698
let constructor = quote!(
9799
impl<#lt> #ident<#lt> {
98100
#[inline(always)]
101+
#[doc(hidden)]
99102
pub unsafe fn new() -> Self {
100103
#ident {
101104
#(#values,)*

macros/src/codegen/module.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,16 @@ pub fn codegen(
133133
));
134134

135135
module_items.push(quote!(
136+
#[doc(inline)]
136137
pub use super::#internal_monotonics_ident as Monotonics;
137138
));
138139
}
139140

140141
let doc = match ctxt {
141-
Context::Idle => "Idle loop",
142-
Context::Init => "Initialization function",
143-
Context::HardwareTask(_) => "Hardware task",
144-
Context::SoftwareTask(_) => "Software task",
142+
Context::Idle => " Idle loop",
143+
Context::Init => " Initialization function",
144+
Context::HardwareTask(_) => " Hardware task",
145+
Context::SoftwareTask(_) => " Software task",
145146
};
146147

147148
let v = Vec::new();
@@ -172,8 +173,8 @@ pub fn codegen(
172173
let internal_context_name = util::internal_task_ident(name, "Context");
173174

174175
items.push(quote!(
175-
#(#cfgs)*
176176
/// Execution context
177+
#(#cfgs)*
177178
#[allow(non_snake_case)]
178179
#[allow(non_camel_case_types)]
179180
pub struct #internal_context_name<#lt> {
@@ -182,6 +183,7 @@ pub fn codegen(
182183

183184
#(#cfgs)*
184185
impl<#lt> #internal_context_name<#lt> {
186+
#[doc(hidden)]
185187
#[inline(always)]
186188
pub unsafe fn new(#core #priority) -> Self {
187189
#internal_context_name {
@@ -192,6 +194,7 @@ pub fn codegen(
192194
));
193195

194196
module_items.push(quote!(
197+
#[doc(inline)]
195198
#(#cfgs)*
196199
pub use super::#internal_context_name as Context;
197200
));
@@ -251,6 +254,7 @@ pub fn codegen(
251254
}));
252255

253256
module_items.push(quote!(
257+
#[doc(inline)]
254258
#(#cfgs)*
255259
pub use super::#internal_spawn_ident as spawn;
256260
));
@@ -300,6 +304,7 @@ pub fn codegen(
300304
));
301305
}
302306
module_items.push(quote!(
307+
#[doc(hidden)]
303308
pub mod #m {
304309
pub use super::super::#internal_spawn_after_ident as spawn_after;
305310
pub use super::super::#internal_spawn_at_ident as spawn_at;
@@ -308,6 +313,7 @@ pub fn codegen(
308313
));
309314

310315
items.push(quote!(
316+
#[doc(hidden)]
311317
#(#cfgs)*
312318
#[allow(non_snake_case)]
313319
#[allow(non_camel_case_types)]
@@ -317,6 +323,7 @@ pub fn codegen(
317323
}
318324

319325
impl core::fmt::Debug for #internal_spawn_handle_ident {
326+
#[doc(hidden)]
320327
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
321328
f.debug_struct(#spawn_handle_string).finish()
322329
}
@@ -344,6 +351,7 @@ pub fn codegen(
344351
})
345352
}
346353

354+
/// Reschedule after
347355
#[inline]
348356
pub fn reschedule_after(
349357
self,
@@ -352,6 +360,7 @@ pub fn codegen(
352360
self.reschedule_at(monotonics::#m::now() + duration)
353361
}
354362

363+
/// Reschedule at
355364
pub fn reschedule_at(
356365
self,
357366
instant: <#m as rtic::Monotonic>::Instant

macros/src/codegen/shared_resources_struct.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,35 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
4444
quote!('a)
4545
};
4646

47+
let lock_free_resource_doc = format!(" Lock free resource `{name}`");
4748
fields.push(quote!(
49+
#[doc = #lock_free_resource_doc]
4850
#(#cfgs)*
4951
pub #name: &#lt #mut_ #ty
5052
));
5153
} else if access.is_shared() {
5254
lt = Some(quote!('a));
5355

56+
let shared_resource_doc = format!(" Shared resource `{name}`");
5457
fields.push(quote!(
58+
#[doc = #shared_resource_doc]
5559
#(#cfgs)*
5660
pub #name: &'a #ty
5761
));
5862
} else {
5963
// Resource proxy
6064
lt = Some(quote!('a));
6165

66+
let resource_doc =
67+
format!(" Resource proxy resource `{name}`. Use method `.lock()` to gain access");
6268
fields.push(quote!(
69+
#[doc = #resource_doc]
6370
#(#cfgs)*
6471
pub #name: shared_resources::#shared_name<'a>
6572
));
6673

6774
values.push(quote!(
75+
#[doc(hidden)]
6876
#(#cfgs)*
6977
#name: shared_resources::#shared_name::new(priority)
7078

@@ -74,13 +82,17 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
7482
continue;
7583
}
7684

85+
let resource_doc;
7786
let expr = if access.is_exclusive() {
87+
resource_doc = format!(" Exclusive access resource `{name}`");
7888
quote!(&mut *(&mut *#mangled_name.get_mut()).as_mut_ptr())
7989
} else {
90+
resource_doc = format!(" Non-exclusive access resource `{name}`");
8091
quote!(&*(&*#mangled_name.get()).as_ptr())
8192
};
8293

8394
values.push(quote!(
95+
#[doc = #resource_doc]
8496
#(#cfgs)*
8597
#name: #expr
8698
));
@@ -100,7 +112,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
100112
}
101113
}
102114

103-
let doc = format!("Shared resources `{}` has access to", ctxt.ident(app));
115+
let doc = format!(" Shared resources `{}` has access to", ctxt.ident(app));
104116
let ident = util::shared_resources_ident(ctxt, app);
105117
let item = quote!(
106118
#[allow(non_snake_case)]
@@ -118,6 +130,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
118130
};
119131
let constructor = quote!(
120132
impl<#lt> #ident<#lt> {
133+
#[doc(hidden)]
121134
#[inline(always)]
122135
pub unsafe fn new(#arg) -> Self {
123136
#ident {

macros/src/codegen/software_tasks.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ pub fn codegen(
125125
let attrs = &task.attrs;
126126
let cfgs = &task.cfgs;
127127
let stmts = &task.stmts;
128+
let user_task_doc = format!(" User SW task {name}");
128129
user_tasks.push(quote!(
130+
#[doc = #user_task_doc]
129131
#(#attrs)*
130132
#(#cfgs)*
131133
#[allow(non_snake_case)]

0 commit comments

Comments
 (0)