Auto merge of #108504 - cjgillot:thir-pattern, r=compiler-errors,Nilstrieb
Check pattern refutability on THIR The current `check_match` query is based on HIR, but partially re-lowers HIR into THIR. This PR proposed to use the results of the `thir_body` query to check matches, instead of re-building THIR. Most of the diagnostic changes are spans getting shorter, or commas/semicolons not getting removed. This PR degrades the diagnostic for confusing constants in patterns (`let A = foo()` where `A` resolves to a `const A` somewhere): it does not point ot the definition of `const A` any more.
This commit is contained in:
@@ -115,6 +115,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
initializer: Some(initializer),
|
||||
lint_level,
|
||||
else_block: Some(else_block),
|
||||
span: _,
|
||||
} => {
|
||||
// When lowering the statement `let <pat> = <expr> else { <else> };`,
|
||||
// the `<else>` block is nested in the parent scope enclosing this statement.
|
||||
@@ -278,6 +279,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
initializer,
|
||||
lint_level,
|
||||
else_block: None,
|
||||
span: _,
|
||||
} => {
|
||||
let ignores_expr_result = matches!(pattern.kind, PatKind::Wild);
|
||||
this.block_context.push(BlockFrame::Statement { ignores_expr_result });
|
||||
|
||||
@@ -58,6 +58,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
|
||||
ty::WithOptConstParam { did, const_param_did: None } => {
|
||||
tcx.ensure_with_value().thir_check_unsafety(did);
|
||||
tcx.ensure_with_value().thir_abstract_const(did);
|
||||
tcx.ensure_with_value().check_match(did);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user