Skip to content

Commit

Permalink
Make rustfmt work in match_sharedterm! (#1677)
Browse files Browse the repository at this point in the history
* Make rustfmt work in match_sharedterm!

macros can have syntax that rustfmt doens't know how to deal with, so it
only triggers on macros that
1. are called with `()` or `[]` delimiters (not `{}`)
2. contain only valid rust syntax

our match_sharedterm! failed on both those counts, so this commit fixes
that. we move the `else` clause back inside the match statement as a
wildcard arm, and use the `match` keyword so that rustfmt understands
how we want the code formatted

* Update core/src/term/mod.rs

Co-authored-by: Yann Hamdaoui <[email protected]>

---------

Co-authored-by: Yann Hamdaoui <[email protected]>
  • Loading branch information
Radvendii and yannham authored Oct 13, 2023
1 parent 7e4ecd9 commit 859293a
Show file tree
Hide file tree
Showing 8 changed files with 1,010 additions and 991 deletions.
58 changes: 30 additions & 28 deletions core/src/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,25 +407,23 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
// a definition, we complete the error with the additional information of where
// it was accessed:
let Closure { body, env } = self.cache.get(idx);
let body = match_sharedterm! {body.term, with {
let body = match_sharedterm!(match (body.term) {
Term::RuntimeError(EvalError::MissingFieldDef {
id,
metadata,
pos_record,
pos_access: TermPos::None,
}) => RichTerm::new(
Term::RuntimeError(EvalError::MissingFieldDef {
id,
metadata,
pos_record,
pos_access: TermPos::None,
}) => RichTerm::new(
Term::RuntimeError(EvalError::MissingFieldDef {
id,
metadata,
pos_record,
pos_access: pos,
}),
pos,
),
} else {
body
}
};
pos_access: pos,
}),
pos,
),
_ => body,
});

Closure { body, env }
}
Expand Down Expand Up @@ -910,24 +908,28 @@ pub fn env_add_record<C: Cache>(
env: &mut Environment,
closure: Closure,
) -> Result<(), EnvBuildError> {
match_sharedterm! {closure.body.term, with {
Term::Record(record) | Term::RecRecord(record, ..) => {
let ext = record.fields.into_iter().filter_map(|(id, field)| {
field.value.map(|value|
match_sharedterm!(match (closure.body.term) {
Term::Record(record) | Term::RecRecord(record, ..) => {
let ext = record.fields.into_iter().filter_map(|(id, field)| {
field.value.map(|value| {
(
id.ident(),
cache.add(
Closure { body: value, env: closure.env.clone() },
BindingType::Normal
Closure {
body: value,
env: closure.env.clone(),
},
BindingType::Normal,
),
))
});
)
})
});

env.extend(ext);
Ok(())
},
} else Err(EnvBuildError::NotARecord(closure.body))
}
env.extend(ext);
Ok(())
}
_ => Err(EnvBuildError::NotARecord(closure.body)),
})
}

/// Bind a closure in an environment.
Expand Down
Loading

0 comments on commit 859293a

Please sign in to comment.