Some cleanup around trait_method lookup

This commit is contained in:
Oli Scherer 2022-11-17 13:28:32 +00:00
parent 9e4c3f41c1
commit 25c4760b5d
2 changed files with 7 additions and 7 deletions

View File

@ -250,7 +250,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let ref_str_ty = tcx.mk_imm_ref(re_erased, tcx.types.str_); let ref_str_ty = tcx.mk_imm_ref(re_erased, tcx.types.str_);
let ref_str = self.temp(ref_str_ty, test.span); let ref_str = self.temp(ref_str_ty, test.span);
let deref = tcx.require_lang_item(LangItem::Deref, None); let deref = tcx.require_lang_item(LangItem::Deref, None);
let method = trait_method(tcx, deref, sym::deref, ty, &[]); let method = trait_method(tcx, deref, sym::deref, ty, []);
let eq_block = self.cfg.start_new_block(); let eq_block = self.cfg.start_new_block();
self.cfg.push_assign(block, source_info, ref_string, Rvalue::Ref(re_erased, BorrowKind::Shared, place)); self.cfg.push_assign(block, source_info, ref_string, Rvalue::Ref(re_erased, BorrowKind::Shared, place));
self.cfg.terminate( self.cfg.terminate(
@ -444,8 +444,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
bug!("non_scalar_compare called on non-reference type: {}", ty); bug!("non_scalar_compare called on non-reference type: {}", ty);
}; };
let eq_def_id = self.tcx.require_lang_item(LangItem::PartialEq, None); let eq_def_id = self.tcx.require_lang_item(LangItem::PartialEq, Some(source_info.span));
let method = trait_method(self.tcx, eq_def_id, sym::eq, deref_ty, &[deref_ty.into()]); let method = trait_method(self.tcx, eq_def_id, sym::eq, deref_ty, [deref_ty.into()]);
let bool_ty = self.tcx.types.bool; let bool_ty = self.tcx.types.bool;
let eq_result = self.temp(bool_ty, source_info.span); let eq_result = self.temp(bool_ty, source_info.span);
@ -838,9 +838,9 @@ fn trait_method<'tcx>(
trait_def_id: DefId, trait_def_id: DefId,
method_name: Symbol, method_name: Symbol,
self_ty: Ty<'tcx>, self_ty: Ty<'tcx>,
params: &[GenericArg<'tcx>], params: impl IntoIterator<Item = GenericArg<'tcx>, IntoIter: ExactSizeIterator>,
) -> ConstantKind<'tcx> { ) -> ConstantKind<'tcx> {
let substs = tcx.mk_substs_trait(self_ty, params.iter().copied()); let substs = tcx.mk_substs_trait(self_ty, params);
// The unhygienic comparison here is acceptable because this is only // The unhygienic comparison here is acceptable because this is only
// used on known traits. // used on known traits.
@ -850,8 +850,7 @@ fn trait_method<'tcx>(
.find(|item| item.kind == ty::AssocKind::Fn) .find(|item| item.kind == ty::AssocKind::Fn)
.expect("trait method not found"); .expect("trait method not found");
let method_ty = tcx.bound_type_of(item.def_id); let method_ty = tcx.mk_fn_def(item.def_id, substs);
let method_ty = method_ty.subst(tcx, substs);
ConstantKind::zero_sized(method_ty) ConstantKind::zero_sized(method_ty)
} }

View File

@ -3,6 +3,7 @@
//! This crate also contains the match exhaustiveness and usefulness checking. //! This crate also contains the match exhaustiveness and usefulness checking.
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![feature(assert_matches)] #![feature(assert_matches)]
#![feature(associated_type_bounds)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]
#![feature(if_let_guard)] #![feature(if_let_guard)]