aboutsummaryrefslogtreecommitdiff
path: root/macros/src/check.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2019-02-12 14:53:49 +0100
committerGravatar Jorge Aparicio <jorge@japaric.io> 2019-02-12 14:53:49 +0100
commit88599780e0eba38d9e543b7809f586479f6956bd (patch)
tree13389021e2f0dbddb53ee08c694ce6b26c91803a /macros/src/check.rs
parent8890f10e1c386b5f408f30174f0a83bb45166823 (diff)
downloadrtic-88599780e0eba38d9e543b7809f586479f6956bd.tar.gz
rtic-88599780e0eba38d9e543b7809f586479f6956bd.tar.zst
rtic-88599780e0eba38d9e543b7809f586479f6956bd.zip
accept `init: fn() -> init::LateResources`
Diffstat (limited to 'macros/src/check.rs')
-rw-r--r--macros/src/check.rs39
1 files changed, 25 insertions, 14 deletions
diff --git a/macros/src/check.rs b/macros/src/check.rs
index 0bc31c5f..045d152f 100644
--- a/macros/src/check.rs
+++ b/macros/src/check.rs
@@ -35,17 +35,20 @@ pub fn app(app: &App) -> parse::Result<()> {
}
}
- // Check that all late resources have been initialized in `#[init]`
- for res in app
- .resources
- .iter()
- .filter_map(|(name, res)| if res.expr.is_none() { Some(name) } else { None })
- {
- if app.init.assigns.iter().all(|assign| assign.left != *res) {
- return Err(parse::Error::new(
- res.span(),
- "late resources MUST be initialized at the end of `init`",
- ));
+ // Check that all late resources have been initialized in `#[init]` if `init` has signature
+ // `fn()`
+ if !app.init.returns_late_resources {
+ for res in app
+ .resources
+ .iter()
+ .filter_map(|(name, res)| if res.expr.is_none() { Some(name) } else { None })
+ {
+ if app.init.assigns.iter().all(|assign| assign.left != *res) {
+ return Err(parse::Error::new(
+ res.span(),
+ "late resources MUST be initialized at the end of `init`",
+ ));
+ }
}
}
@@ -112,11 +115,19 @@ pub fn app(app: &App) -> parse::Result<()> {
}
}
- // Check that `init` contains no early returns *if* late resources exist
+ // Check that `init` contains no early returns *if* late resources exist and `init` signature is
+ // `fn()`
if app.resources.values().any(|res| res.expr.is_none()) {
- for stmt in &app.init.stmts {
- noreturn_stmt(stmt)?;
+ if !app.init.returns_late_resources {
+ for stmt in &app.init.stmts {
+ noreturn_stmt(stmt)?;
+ }
}
+ } else if app.init.returns_late_resources {
+ return Err(parse::Error::new(
+ Span::call_site(),
+ "`init` signature must be `[unsafe] fn()` if there are no late resources",
+ ));
}
Ok(())