Skip to content

Commit

Permalink
Auto merge of rust-lang#133897 - oli-obk:push-lsxrqtqqwmpt, r=jieyouxu
Browse files Browse the repository at this point in the history
Remove a lit_to_const call

We have so many special cases of `match expr.kind { Lit() => {}, Unary(Neg, Lit()) => {} }`... I'm trying to figure out how to get these all unified, but outright removing some is good, too. So let's try it.

Tho we don't have many `const {}` blocks in the perf test suite... But I also don't know how common `const { 42 }` blocks are, I'd expect these to occur mostly from macros (like `thread_local!`)
  • Loading branch information
bors committed Dec 7, 2024
2 parents ca13e91 + 44019ee commit cdb89d6
Showing 1 changed file with 0 additions and 24 deletions.
24 changes: 0 additions & 24 deletions compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,32 +626,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
) -> PatKind<'tcx> {
let tcx = self.tcx;
let def_id = block.def_id;
let body_id = block.body;
let expr = &tcx.hir().body(body_id).value;
let ty = tcx.typeck(def_id).node_type(block.hir_id);

// Special case inline consts that are just literals. This is solely
// a performance optimization, as we could also just go through the regular
// const eval path below.
// FIXME: investigate the performance impact of removing this.
let lit_input = match expr.kind {
hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
hir::ExprKind::Unary(hir::UnOp::Neg, expr) => match expr.kind {
hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: true }),
_ => None,
},
_ => None,
};
if let Some(lit_input) = lit_input {
match tcx.at(expr.span).lit_to_const(lit_input) {
Ok(c) => return self.const_to_pat(c, ty, id, span).kind,
// If an error occurred, ignore that it's a literal
// and leave reporting the error up to const eval of
// the unevaluated constant below.
Err(_) => {}
}
}

let typeck_root_def_id = tcx.typeck_root_def_id(def_id.to_def_id());
let parent_args =
tcx.erase_regions(ty::GenericArgs::identity_for_item(tcx, typeck_root_def_id));
Expand Down

0 comments on commit cdb89d6

Please sign in to comment.