From d30bdcb096774c1f56d9823fb2fbb78bf5cd3584 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 9 Dec 2017 17:14:51 +0100 Subject: safe `&'static mut` references via init.resources --- macros/src/check.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'macros/src/check.rs') diff --git a/macros/src/check.rs b/macros/src/check.rs index 63cac1f..f6fd9cc 100644 --- a/macros/src/check.rs +++ b/macros/src/check.rs @@ -77,7 +77,38 @@ pub fn app(app: check::App) -> Result { } fn resources(app: &App) -> Result<()> { + for name in &app.init.resources { + if let Some(resource) = app.resources.get(name) { + ensure!( + resource.expr.is_some(), + "resource `{}`, allocated to `init`, must have an initial value", + name + ); + } else { + bail!( + "resource `{}`, allocated to `init`, must be a data resource", + name + ); + } + + ensure!( + !app.idle.resources.contains(name), + "resources assigned to `init` can't be shared with `idle`" + ); + + ensure!( + app.tasks + .iter() + .all(|(_, task)| !task.resources.contains(name)), + "resources assigned to `init` can't be shared with tasks" + ) + } + for resource in app.resources.keys() { + if app.init.resources.contains(resource) { + continue; + } + if app.idle.resources.contains(resource) { continue; } -- cgit v1.2.3