From 25c4760b5db54d55f9512d69edbb214cbca20372 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 17 Nov 2022 13:28:32 +0000 Subject: [PATCH] Some cleanup around trait_method lookup --- compiler/rustc_mir_build/src/build/matches/test.rs | 13 ++++++------- compiler/rustc_mir_build/src/lib.rs | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index 0a6a8859d2f..8ff7296c7b6 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -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 = self.temp(ref_str_ty, test.span); 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(); self.cfg.push_assign(block, source_info, ref_string, Rvalue::Ref(re_erased, BorrowKind::Shared, place)); self.cfg.terminate( @@ -444,8 +444,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { bug!("non_scalar_compare called on non-reference type: {}", ty); }; - let eq_def_id = self.tcx.require_lang_item(LangItem::PartialEq, None); - let method = trait_method(self.tcx, eq_def_id, sym::eq, deref_ty, &[deref_ty.into()]); + 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 bool_ty = self.tcx.types.bool; let eq_result = self.temp(bool_ty, source_info.span); @@ -838,9 +838,9 @@ fn trait_method<'tcx>( trait_def_id: DefId, method_name: Symbol, self_ty: Ty<'tcx>, - params: &[GenericArg<'tcx>], + params: impl IntoIterator, IntoIter: ExactSizeIterator>, ) -> 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 // used on known traits. @@ -850,8 +850,7 @@ fn trait_method<'tcx>( .find(|item| item.kind == ty::AssocKind::Fn) .expect("trait method not found"); - let method_ty = tcx.bound_type_of(item.def_id); - let method_ty = method_ty.subst(tcx, substs); + let method_ty = tcx.mk_fn_def(item.def_id, substs); ConstantKind::zero_sized(method_ty) } diff --git a/compiler/rustc_mir_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs index b53bd3d0710..87975294595 100644 --- a/compiler/rustc_mir_build/src/lib.rs +++ b/compiler/rustc_mir_build/src/lib.rs @@ -3,6 +3,7 @@ //! This crate also contains the match exhaustiveness and usefulness checking. #![allow(rustc::potential_query_instability)] #![feature(assert_matches)] +#![feature(associated_type_bounds)] #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(if_let_guard)]