Skip to content

Commit f758a6b

Browse files
committed
Do not merge: check if sometimes we can't get snippets
1 parent 5b23bd4 commit f758a6b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

clippy_utils/src/source.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,13 @@ fn snippet_with_applicability_sess<'a>(
573573
}
574574

575575
/// Converts a span to a code snippet. Returns `None` if not available.
576+
#[allow(clippy::unnecessary_wraps)]
576577
pub fn snippet_opt(sess: &impl HasSession, span: Span) -> Option<String> {
577-
sess.sess().source_map().span_to_snippet(span).ok()
578+
// Experiment: fail loudly if the snippet cannot be obtained
579+
match sess.sess().source_map().span_to_snippet(span) {
580+
Ok(v) => Some(v),
581+
Err(e) => panic!("Error when getting snippet for {span:?}: {e:?}"),
582+
}
578583
}
579584

580585
/// Converts a span (from a block) to a code snippet if available, otherwise use default.

0 commit comments

Comments
 (0)