Skip to content

Commit

Permalink
macros
Browse files Browse the repository at this point in the history
Signed-off-by: Shaobo He <[email protected]>
  • Loading branch information
shaobo-he-aws committed Dec 3, 2024
1 parent 825f41f commit a171b91
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
6 changes: 3 additions & 3 deletions cedar-policy-core/src/error_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ macro_rules! impl_diagnostic_from_source_loc_field {
/// of a field of type `Option<Loc>`
#[macro_export]
macro_rules! impl_diagnostic_from_source_loc_opt_field {
( $i:ident ) => {
( $($id:ident).+ ) => {
fn source_code(&self) -> Option<&dyn miette::SourceCode> {
self.$i
self.$($id).+
.as_ref()
.map(|loc| &loc.src as &dyn miette::SourceCode)
}

fn labels(&self) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + '_>> {
self.$i
self.$($id).+
.as_ref()
.map(|loc| Box::new(std::iter::once(miette::LabeledSpan::underline(loc.span))) as _)
}
Expand Down
11 changes: 1 addition & 10 deletions cedar-policy-core/src/parser/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,7 @@ pub mod parse_errors {
))
}

fn labels(&self) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + '_>> {
self.slot.loc.as_ref().map(|loc| {
let label = miette::LabeledSpan::underline(loc.span);
Box::new(std::iter::once(label)) as Box<dyn Iterator<Item = miette::LabeledSpan>>
})
}

fn source_code(&self) -> Option<&dyn miette::SourceCode> {
self.slot.loc.as_ref().map(|l| l as &dyn miette::SourceCode)
}
impl_diagnostic_from_source_loc_opt_field!(slot.loc);
}

impl From<ast::UnexpectedSlotError> for ExpectedStaticPolicy {
Expand Down

0 comments on commit a171b91

Please sign in to comment.