Skip to content

Commit

Permalink
simplify things using tcx.as_lang_item
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Nov 29, 2024
1 parent c6454dd commit 144d6cc
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions compiler/rustc_mir_build/src/check_tail_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,33 +354,31 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for TailCallCkVisitor<'a, 'tcx> {
}

fn op_trait_as_method_name(tcx: TyCtxt<'_>, trait_did: DefId) -> Option<&'static str> {
let trait_did = Some(trait_did);
let items = tcx.lang_items();
let m = match () {
_ if trait_did == items.get(LangItem::Add) => "add",
_ if trait_did == items.get(LangItem::Sub) => "sub",
_ if trait_did == items.get(LangItem::Mul) => "mul",
_ if trait_did == items.get(LangItem::Div) => "div",
_ if trait_did == items.get(LangItem::Rem) => "rem",
_ if trait_did == items.get(LangItem::Neg) => "neg",
_ if trait_did == items.get(LangItem::Not) => "not",
_ if trait_did == items.get(LangItem::BitXor) => "bitxor",
_ if trait_did == items.get(LangItem::BitAnd) => "bitand",
_ if trait_did == items.get(LangItem::BitOr) => "bitor",
_ if trait_did == items.get(LangItem::Shl) => "shl",
_ if trait_did == items.get(LangItem::Shr) => "shr",
_ if trait_did == items.get(LangItem::AddAssign) => "add_assign",
_ if trait_did == items.get(LangItem::SubAssign) => "sub_assign",
_ if trait_did == items.get(LangItem::MulAssign) => "mul_assign",
_ if trait_did == items.get(LangItem::DivAssign) => "div_assign",
_ if trait_did == items.get(LangItem::RemAssign) => "rem_assign",
_ if trait_did == items.get(LangItem::BitXorAssign) => "bitxor_assign",
_ if trait_did == items.get(LangItem::BitAndAssign) => "bitand_assign",
_ if trait_did == items.get(LangItem::BitOrAssign) => "bitor_assign",
_ if trait_did == items.get(LangItem::ShlAssign) => "shl_assign",
_ if trait_did == items.get(LangItem::ShrAssign) => "shr_assign",
_ if trait_did == items.get(LangItem::Index) => "index",
_ if trait_did == items.get(LangItem::IndexMut) => "index_mut",
let m = match tcx.as_lang_item(trait_did)? {
LangItem::Add => "add",
LangItem::Sub => "sub",
LangItem::Mul => "mul",
LangItem::Div => "div",
LangItem::Rem => "rem",
LangItem::Neg => "neg",
LangItem::Not => "not",
LangItem::BitXor => "bitxor",
LangItem::BitAnd => "bitand",
LangItem::BitOr => "bitor",
LangItem::Shl => "shl",
LangItem::Shr => "shr",
LangItem::AddAssign => "add_assign",
LangItem::SubAssign => "sub_assign",
LangItem::MulAssign => "mul_assign",
LangItem::DivAssign => "div_assign",
LangItem::RemAssign => "rem_assign",
LangItem::BitXorAssign => "bitxor_assign",
LangItem::BitAndAssign => "bitand_assign",
LangItem::BitOrAssign => "bitor_assign",
LangItem::ShlAssign => "shl_assign",
LangItem::ShrAssign => "shr_assign",
LangItem::Index => "index",
LangItem::IndexMut => "index_mut",
_ => return None,
};

Expand Down

0 comments on commit 144d6cc

Please # to comment.