Auto merge of #14092 - Veykril:inlay-hint-panic, r=Veykril

fix: Don't panic on broken syntax trees in adjustment inlay hints

These should be unreachable, but apparently with broken enough syntax trees (I assume mismatched parens), we do reach these unreachable calls. Haven't quite figured out when this happens though.
This commit is contained in:
bors 2023-02-06 11:39:47 +00:00
commit e9d0bfc799

View File

@ -6,6 +6,7 @@
use hir::{Adjust, Adjustment, AutoBorrow, HirDisplay, Mutability, PointerCast, Safety, Semantics};
use ide_db::RootDatabase;
use stdx::never;
use syntax::{
ast::{self, make, AstNode},
ted,
@ -210,16 +211,21 @@ fn needs_parens_for_adjustment_hints(expr: &ast::Expr, postfix: bool) -> (bool,
ted::replace(expr.syntax(), dummy_expr.syntax());
let parent = dummy_expr.syntax().parent();
let expr = if postfix {
let ast::Expr::TryExpr(e) = &dummy_expr else { unreachable!() };
let Some(ast::Expr::ParenExpr(e)) = e.expr() else { unreachable!() };
let Some(expr) = (|| {
if postfix {
let ast::Expr::TryExpr(e) = &dummy_expr else { return None };
let Some(ast::Expr::ParenExpr(e)) = e.expr() else { return None };
e.expr().unwrap()
} else {
let ast::Expr::RefExpr(e) = &dummy_expr else { unreachable!() };
let Some(ast::Expr::ParenExpr(e)) = e.expr() else { unreachable!() };
e.expr()
} else {
let ast::Expr::RefExpr(e) = &dummy_expr else { return None };
let Some(ast::Expr::ParenExpr(e)) = e.expr() else { return None };
e.expr().unwrap()
e.expr()
}
})() else {
never!("broken syntax tree?\n{:?}\n{:?}", expr, dummy_expr);
return (true, true)
};
// At this point