Skip to content

Commit

Permalink
fixup! do not use catch_unwind unless panic=unwind
Browse files Browse the repository at this point in the history
  • Loading branch information
MingweiSamuel committed Dec 11, 2024
1 parent 358632e commit a42c30e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
11 changes: 4 additions & 7 deletions hydroflow_lang/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,10 @@ pub struct SerdeSpan {
}
impl From<Span> for SerdeSpan {
fn from(span: Span) -> Self {
#[cfg(all(nightly, panic = "unwind"))]
let path = std::panic::catch_unwind(|| span.unwrap())
.map(|span| span.source_file().path().display().to_string())
.ok();

#[cfg(not(nightly))]
let path = None::<String>;
let path = cfg!(all(nightly, panic = "unwind"))
.then_some(())
.and_then(|()| std::panic::catch_unwind(|| span.unwrap()).ok())
.map(|span| span.source_file().path().display().to_string());

Self {
path: path.map_or(Cow::Borrowed("unknown"), Cow::Owned),
Expand Down
13 changes: 6 additions & 7 deletions hydroflow_lang/src/graph/hydroflow_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,11 +1006,11 @@ impl HydroflowGraph {
subgraph_op_iter_code.push(write_iterator);

if include_type_guards {
#[cfg(not(nightly))]
let source_info = Option::<String>::None;

#[cfg(all(nightly, panic = "unwind"))]
let source_info = std::panic::catch_unwind(|| op_span.unwrap())
let source_info = cfg!(all(nightly, panic = "unwind"))
.then_some(())
.and_then(|()| {
std::panic::catch_unwind(|| op_span.unwrap()).ok()
})
.map(|op_span| {
format!(
"loc_{}_{}_{}_{}_{}",
Expand All @@ -1025,8 +1025,7 @@ impl HydroflowGraph {
op_span.end().line(),
op_span.end().column(),
)
})
.ok();
});

#[cfg_attr(
not(nightly),
Expand Down

0 comments on commit a42c30e

Please sign in to comment.