Skip to content

Commit 182d959

Browse files
committed
Do not merge: check if sometimes we can't get snippets
1 parent 38458c4 commit 182d959

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
@@ -514,8 +514,13 @@ fn snippet_with_applicability_sess<'a>(
514514
}
515515

516516
/// Converts a span to a code snippet. Returns `None` if not available.
517+
#[allow(clippy::unnecessary_wraps)]
517518
pub fn snippet_opt(sess: &impl HasSession, span: Span) -> Option<String> {
518-
sess.sess().source_map().span_to_snippet(span).ok()
519+
// Experiment: fail loudly if the snippet could not be obtained
520+
match sess.sess().source_map().span_to_snippet(span) {
521+
Ok(v) => Some(v),
522+
Err(e) => panic!("Error when getting snippet for {span:?}: {e:?}"),
523+
}
519524
}
520525

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

0 commit comments

Comments
 (0)