minor: Avoid eprintln on panic
This commit is contained in:
parent
71117e6812
commit
99516bbd67
@ -357,17 +357,20 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||
infer: &infer,
|
||||
db,
|
||||
pattern_arena: &pattern_arena,
|
||||
eprint_panic_context: &|| {
|
||||
panic_context: &|| {
|
||||
use syntax::AstNode;
|
||||
if let Ok(scrutinee_sptr) = source_map.expr_syntax(match_expr) {
|
||||
let root = scrutinee_sptr.file_syntax(db.upcast());
|
||||
if let Some(match_ast) = scrutinee_sptr.value.to_node(&root).syntax().parent() {
|
||||
eprintln!(
|
||||
"Match checking is about to panic on this expression:\n{}",
|
||||
match_ast.to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
let match_expr_text = source_map
|
||||
.expr_syntax(match_expr)
|
||||
.ok()
|
||||
.and_then(|scrutinee_sptr| {
|
||||
let root = scrutinee_sptr.file_syntax(db.upcast());
|
||||
scrutinee_sptr.value.to_node(&root).syntax().parent()
|
||||
})
|
||||
.map(|node| node.to_string());
|
||||
format!(
|
||||
"expression:\n{}",
|
||||
match_expr_text.as_deref().unwrap_or("<synthesized expr>")
|
||||
)
|
||||
},
|
||||
};
|
||||
let report = compute_match_usefulness(&cx, &m_arms);
|
||||
|
@ -295,7 +295,7 @@ pub(crate) struct MatchCheckCtx<'a> {
|
||||
pub(crate) db: &'a dyn HirDatabase,
|
||||
/// Lowered patterns from arms plus generated by the check.
|
||||
pub(crate) pattern_arena: &'a RefCell<PatternArena>,
|
||||
pub(crate) eprint_panic_context: &'a dyn Fn(),
|
||||
pub(crate) panic_context: &'a dyn Fn() -> String,
|
||||
}
|
||||
|
||||
impl<'a> MatchCheckCtx<'a> {
|
||||
@ -331,8 +331,7 @@ impl<'a> MatchCheckCtx<'a> {
|
||||
|
||||
#[track_caller]
|
||||
pub(super) fn bug(&self, info: &str) -> ! {
|
||||
(self.eprint_panic_context)();
|
||||
panic!("bug: {}", info);
|
||||
panic!("bug: {}\n{}", info, (self.panic_context)());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user