Skip to content

Commit ed9d6c5

Browse files
committed
Do not merge: check if sometimes we can't get snippets
1 parent a8b1782 commit ed9d6c5

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

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

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

0 commit comments

Comments
 (0)