Skip to content

Commit b9312d5

Browse files
committed
merge parse_preconditions and parse_postconditions into parse_conditions
1 parent 8ca73da commit b9312d5

1 file changed

Lines changed: 10 additions & 31 deletions

File tree

crates/anodized-core/src/annotate.rs

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ impl Parse for Spec {
8787
}
8888
}
8989
Keyword::Requires => {
90-
if let Err(error) = arg.parse_preconditions(&mut requires) {
90+
if let Err(error) = arg.parse_conditions(&mut requires) {
9191
errors.add(error);
9292
}
9393
}
9494
Keyword::Maintains => {
95-
if let Err(error) = arg.parse_preconditions(&mut maintains) {
95+
if let Err(error) = arg.parse_conditions(&mut maintains) {
9696
errors.add(error);
9797
}
9898
}
@@ -119,7 +119,7 @@ impl Parse for Spec {
119119
}
120120
}
121121
Keyword::Ensures => {
122-
if let Err(error) = arg.parse_postconditions(&mut ensures) {
122+
if let Err(error) = arg.parse_conditions(&mut ensures) {
123123
errors.add(error);
124124
}
125125
}
@@ -174,7 +174,7 @@ impl Parse for DataSpec {
174174
));
175175
}
176176
Keyword::Maintains => {
177-
if let Err(error) = arg.parse_preconditions(&mut maintains) {
177+
if let Err(error) = arg.parse_conditions(&mut maintains) {
178178
errors.add(error);
179179
}
180180
}
@@ -217,7 +217,7 @@ impl Parse for LoopSpec {
217217
));
218218
}
219219
Keyword::Maintains => {
220-
if let Err(error) = arg.parse_preconditions(&mut maintains) {
220+
if let Err(error) = arg.parse_conditions(&mut maintains) {
221221
errors.add(error);
222222
}
223223
}
@@ -284,23 +284,23 @@ impl SpecArg {
284284
Ok(())
285285
}
286286

287-
fn parse_preconditions(self, preconditions: &mut Vec<Condition>) -> Result<()> {
287+
fn parse_conditions(self, conditions: &mut Vec<Condition>) -> Result<()> {
288288
let cfg_attr = find_cfg_attribute(&self.attrs)?;
289289
let cfg: Option<Meta> = if let Some(attr) = cfg_attr {
290290
Some(attr.parse_args()?)
291291
} else {
292292
None
293293
};
294294
let expr = self.value.try_into_expr()?;
295-
if let Expr::Array(conditions) = expr {
296-
for expr in conditions.elems {
297-
preconditions.push(Condition {
295+
if let Expr::Array(items) = expr {
296+
for expr in items.elems {
297+
conditions.push(Condition {
298298
expr,
299299
cfg: cfg.clone(),
300300
});
301301
}
302302
} else {
303-
preconditions.push(Condition { expr, cfg });
303+
conditions.push(Condition { expr, cfg });
304304
}
305305
Ok(())
306306
}
@@ -340,27 +340,6 @@ impl SpecArg {
340340
Ok(())
341341
}
342342

343-
fn parse_postconditions(self, postconditions: &mut Vec<Condition>) -> Result<()> {
344-
let cfg_attr = find_cfg_attribute(&self.attrs)?;
345-
let cfg: Option<Meta> = if let Some(attr) = cfg_attr {
346-
Some(attr.parse_args()?)
347-
} else {
348-
None
349-
};
350-
let expr = self.value.try_into_expr()?;
351-
if let Expr::Array(conditions) = expr {
352-
for expr in conditions.elems {
353-
postconditions.push(Condition {
354-
expr,
355-
cfg: cfg.clone(),
356-
});
357-
}
358-
} else {
359-
postconditions.push(Condition { expr, cfg });
360-
}
361-
Ok(())
362-
}
363-
364343
fn parse_decreases(self, decreases: &mut Option<LoopVariant>) -> Result<()> {
365344
let cfg_attr = find_cfg_attribute(&self.attrs)?;
366345
let cfg: Option<Meta> = if let Some(attr) = cfg_attr {

0 commit comments

Comments
 (0)