change usages of impl_trait_ref to bound_impl_trait_ref

This commit is contained in:
Kyle Matsuda 2023-01-10 14:22:52 -07:00
parent ef58baf8b8
commit be130b57d4
47 changed files with 134 additions and 100 deletions

View File

@ -2059,14 +2059,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
(_, Res::SelfTyAlias { alias_to: impl_def_id, is_trait_impl: true, .. }) => {
// `Self` in an impl of a trait -- we have a concrete self type and a
// trait reference.
let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else {
let Some(trait_ref) = tcx.bound_impl_trait_ref(impl_def_id) else {
// A cycle error occurred, most likely.
let guar = tcx.sess.delay_span_bug(span, "expected cycle error");
return Err(guar);
};
self.one_bound_for_assoc_type(
|| traits::supertraits(tcx, ty::Binder::dummy(trait_ref)),
|| traits::supertraits(tcx, ty::Binder::dummy(trait_ref.skip_binder())),
|| "Self".to_string(),
assoc_ident,
span,

View File

@ -535,12 +535,12 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
return;
};
debug!("ItemKind::Impl {} with id {:?}", it.ident, it.owner_id);
if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.owner_id) {
if let Some(impl_trait_ref) = tcx.bound_impl_trait_ref(it.owner_id.to_def_id()) {
check_impl_items_against_trait(
tcx,
it.span,
it.owner_id.def_id,
impl_trait_ref,
impl_trait_ref.skip_binder(),
&impl_.items,
);
check_on_unimplemented(tcx, it);

View File

@ -616,7 +616,8 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
) -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed> {
let impl_m = tcx.opt_associated_item(def_id).unwrap();
let trait_m = tcx.opt_associated_item(impl_m.trait_item_def_id.unwrap()).unwrap();
let impl_trait_ref = tcx.impl_trait_ref(impl_m.impl_container(tcx).unwrap()).unwrap();
let impl_trait_ref =
tcx.bound_impl_trait_ref(impl_m.impl_container(tcx).unwrap()).unwrap().subst_identity();
let param_env = tcx.param_env(def_id);
// First, check a few of the same things as `compare_impl_method`,
@ -1684,7 +1685,8 @@ pub(super) fn compare_impl_const_raw(
) -> Result<(), ErrorGuaranteed> {
let impl_const_item = tcx.associated_item(impl_const_item_def);
let trait_const_item = tcx.associated_item(trait_const_item_def);
let impl_trait_ref = tcx.impl_trait_ref(impl_const_item.container_id(tcx)).unwrap();
let impl_trait_ref =
tcx.bound_impl_trait_ref(impl_const_item.container_id(tcx)).unwrap().subst_identity();
debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref);
let impl_c_span = tcx.def_span(impl_const_item_def.to_def_id());

View File

@ -181,8 +181,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
// for `T`
hir::ItemKind::Impl(ref impl_) => {
let is_auto = tcx
.impl_trait_ref(def_id)
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id));
.bound_impl_trait_ref(def_id.into())
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.skip_binder().def_id));
if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) {
let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span);
let mut err =
@ -1253,7 +1253,8 @@ fn check_impl<'tcx>(
// `#[rustc_reservation_impl]` impls are not real impls and
// therefore don't need to be WF (the trait's `Self: Trait` predicate
// won't hold).
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap();
let trait_ref =
tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).unwrap().subst_identity();
let trait_ref = wfcx.normalize(
ast_trait_ref.path.span,
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),

View File

@ -192,7 +192,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
let source = tcx.type_of(impl_did);
assert!(!source.has_escaping_bound_vars());
let target = {
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap();
let trait_ref = tcx.bound_impl_trait_ref(impl_did.into()).unwrap().subst_identity();
assert_eq!(trait_ref.def_id, dispatch_from_dyn_trait);
trait_ref.substs.type_at(1)
@ -354,7 +354,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
});
let source = tcx.type_of(impl_did);
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap();
let trait_ref = tcx.bound_impl_trait_ref(impl_did.into()).unwrap().subst_identity();
assert_eq!(trait_ref.def_id, coerce_unsized_trait);
let target = trait_ref.substs.type_at(1);
debug!("visit_implementation_of_coerce_unsized: {:?} -> {:?} (bound)", source, target);

View File

@ -128,7 +128,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
let impls = tcx.hir().trait_impls(def_id);
for &impl_def_id in impls {
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
let trait_ref = tcx.bound_impl_trait_ref(impl_def_id.into()).unwrap().subst_identity();
check_impl(tcx, impl_def_id, trait_ref);
check_object_overlap(tcx, impl_def_id, trait_ref);

View File

@ -21,7 +21,7 @@ pub(crate) fn orphan_check_impl(
tcx: TyCtxt<'_>,
impl_def_id: LocalDefId,
) -> Result<(), ErrorGuaranteed> {
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
let trait_ref = tcx.bound_impl_trait_ref(impl_def_id.into()).unwrap().skip_binder();
trait_ref.error_reported()?;
let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id);

View File

@ -13,7 +13,9 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let item = tcx.hir().expect_item(def_id);
let hir::ItemKind::Impl(ref impl_) = item.kind else { bug!() };
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
if let Some(trait_ref) =
tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(|t| t.subst_identity())
{
let trait_def = tcx.trait_def(trait_ref.def_id);
let unsafe_attr =
impl_.generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle");

View File

@ -87,7 +87,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
Node::Item(item) => match item.kind {
ItemKind::Impl(ref impl_) => {
if impl_.defaultness.is_default() {
is_default_impl_trait = tcx.impl_trait_ref(def_id).map(ty::Binder::dummy);
is_default_impl_trait = tcx
.bound_impl_trait_ref(def_id)
.map(|t| ty::Binder::dummy(t.subst_identity()));
}
&impl_.generics
}
@ -251,7 +253,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
// for details.
if let Node::Item(&Item { kind: ItemKind::Impl { .. }, .. }) = node {
let self_ty = tcx.type_of(def_id);
let trait_ref = tcx.impl_trait_ref(def_id);
let trait_ref = tcx.bound_impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity);
cgp::setup_constraining_predicates(
tcx,
&mut predicates,

View File

@ -286,7 +286,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
}
}
ImplItemKind::Type(ty) => {
if tcx.impl_trait_ref(tcx.hir().get_parent_item(hir_id)).is_none() {
if tcx.bound_impl_trait_ref(tcx.hir().get_parent_item(hir_id).to_def_id()).is_none() {
check_feature_inherent_assoc_ty(tcx, item.span);
}

View File

@ -85,7 +85,8 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
}
let impl_generics = tcx.generics_of(impl_def_id);
let impl_predicates = tcx.predicates_of(impl_def_id);
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id);
let impl_trait_ref =
tcx.bound_impl_trait_ref(impl_def_id.into()).map(ty::EarlyBinder::subst_identity);
let mut input_parameters = cgp::parameters_for_impl(impl_self_ty, impl_trait_ref);
cgp::identify_constrained_generic_params(

View File

@ -89,8 +89,8 @@ pub(super) fn check_min_specialization(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
}
fn parent_specialization_node(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId) -> Option<Node> {
let trait_ref = tcx.impl_trait_ref(impl1_def_id)?;
let trait_def = tcx.trait_def(trait_ref.def_id);
let trait_ref = tcx.bound_impl_trait_ref(impl1_def_id.into())?;
let trait_def = tcx.trait_def(trait_ref.skip_binder().def_id);
let impl2_node = trait_def.ancestors(tcx, impl1_def_id.to_def_id()).ok()?.nth(1)?;
@ -207,7 +207,7 @@ fn unconstrained_parent_impl_substs<'tcx>(
let impl_generic_predicates = tcx.predicates_of(impl_def_id);
let mut unconstrained_parameters = FxHashSet::default();
let mut constrained_params = FxHashSet::default();
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id);
let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).map(ty::EarlyBinder::subst_identity);
// Unfortunately the functions in `constrained_generic_parameters` don't do
// what we want here. We want only a list of constrained parameters while
@ -370,7 +370,7 @@ fn check_predicates<'tcx>(
});
// Include the well-formed predicates of the type parameters of the impl.
for arg in tcx.impl_trait_ref(impl1_def_id).unwrap().substs {
for arg in tcx.bound_impl_trait_ref(impl1_def_id.into()).unwrap().subst_identity().substs {
let infcx = &tcx.infer_ctxt().build();
let obligations = wf::obligations(
infcx,

View File

@ -240,7 +240,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
probe::InherentImplPick => {
let impl_def_id = pick.item.container_id(self.tcx);
assert!(
self.tcx.impl_trait_ref(impl_def_id).is_none(),
self.tcx.bound_impl_trait_ref(impl_def_id).is_none(),
"impl {:?} is not an inherent impl",
impl_def_id
);

View File

@ -1036,8 +1036,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Provide the best span we can. Use the item, if local to crate, else
// the impl, if local to crate (item may be defaulted), else nothing.
let Some(item) = self.associated_value(impl_did, item_name).or_else(|| {
let impl_trait_ref = self.tcx.impl_trait_ref(impl_did)?;
self.associated_value(impl_trait_ref.def_id, item_name)
let impl_trait_ref = self.tcx.bound_impl_trait_ref(impl_did)?;
self.associated_value(impl_trait_ref.skip_binder().def_id, item_name)
}) else {
continue;
};
@ -1052,10 +1052,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let impl_ty = self.tcx.at(span).type_of(impl_did);
let insertion = match self.tcx.impl_trait_ref(impl_did) {
let insertion = match self.tcx.bound_impl_trait_ref(impl_did) {
None => String::new(),
Some(trait_ref) => {
format!(" of the trait `{}`", self.tcx.def_path_str(trait_ref.def_id))
format!(
" of the trait `{}`",
self.tcx.def_path_str(trait_ref.skip_binder().def_id)
)
}
};
@ -1085,8 +1088,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.note(&note_str);
}
if let Some(sugg_span) = sugg_span
&& let Some(trait_ref) = self.tcx.impl_trait_ref(impl_did) {
let path = self.tcx.def_path_str(trait_ref.def_id);
&& let Some(trait_ref) = self.tcx.bound_impl_trait_ref(impl_did) {
let path = self.tcx.def_path_str(trait_ref.skip_binder().def_id);
let ty = match item.kind {
ty::AssocKind::Const | ty::AssocKind::Type => rcvr_ty,
@ -2581,7 +2584,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx.impl_polarity(*imp_did) == ty::ImplPolarity::Negative
})
.any(|imp_did| {
let imp = self.tcx.impl_trait_ref(imp_did).unwrap();
let imp =
self.tcx.bound_impl_trait_ref(imp_did).unwrap().subst_identity();
let imp_simp =
simplify_type(self.tcx, imp.self_ty(), TreatParams::AsPlaceholder);
imp_simp.map_or(false, |s| s == simp_rcvr_ty)

View File

@ -317,9 +317,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
self.tcx.associated_item(impl_item_def_id).impl_container(self.tcx) else { return; };
let Some(trait_ref) = self
.tcx
.impl_trait_ref(impl_def_id)
.bound_impl_trait_ref(impl_def_id)
else { return; };
let trait_substs = trait_ref
.subst_identity()
// Replace the explicit self type with `Self` for better suggestion rendering
.with_self_ty(self.tcx, self.tcx.mk_ty_param(0, kw::SelfUpper))
.substs;

View File

@ -26,7 +26,7 @@ pub fn method_context(cx: &LateContext<'_>, id: hir::HirId) -> MethodLateContext
let item = cx.tcx.associated_item(def_id);
match item.container {
ty::TraitContainer => MethodLateContext::TraitAutoImpl,
ty::ImplContainer => match cx.tcx.impl_trait_ref(item.container_id(cx.tcx)) {
ty::ImplContainer => match cx.tcx.bound_impl_trait_ref(item.container_id(cx.tcx)) {
Some(_) => MethodLateContext::TraitImpl,
None => MethodLateContext::PlainImpl,
},

View File

@ -24,7 +24,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByValue {
match &ty.kind {
TyKind::Ref(_, hir::MutTy { ty: inner_ty, mutbl: hir::Mutability::Not }) => {
if let Some(impl_did) = cx.tcx.impl_of_method(ty.hir_id.owner.to_def_id()) {
if cx.tcx.impl_trait_ref(impl_did).is_some() {
if cx.tcx.bound_impl_trait_ref(impl_did).is_some() {
return;
}
}

View File

@ -1555,7 +1555,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.tables.impl_defaultness.set(def_id.index, *defaultness);
self.tables.constness.set(def_id.index, *constness);
let trait_ref = self.tcx.impl_trait_ref(def_id);
let trait_ref =
self.tcx.bound_impl_trait_ref(def_id).map(ty::EarlyBinder::skip_binder);
if let Some(trait_ref) = trait_ref {
let trait_def = self.tcx.trait_def(trait_ref.def_id);
if let Ok(mut an) = trait_def.ancestors(self.tcx, def_id) {
@ -1632,7 +1633,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
}
if let hir::ItemKind::Impl { .. } = item.kind {
if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) {
if let Some(trait_ref) =
self.tcx.bound_impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity)
{
record!(self.tables.impl_trait_ref[def_id] <- trait_ref);
}
}
@ -1898,7 +1901,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
for id in tcx.hir().items() {
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl) {
if let Some(trait_ref) = tcx.impl_trait_ref(id.owner_id) {
if let Some(trait_ref) = tcx
.bound_impl_trait_ref(id.owner_id.to_def_id())
.map(ty::EarlyBinder::subst_identity)
{
let simplified_self_ty = fast_reject::simplify_type(
self.tcx,
trait_ref.self_ty(),

View File

@ -101,7 +101,8 @@ impl<'tcx> TyCtxt<'tcx> {
}
pub fn impl_subject(self, def_id: DefId) -> ImplSubject<'tcx> {
self.impl_trait_ref(def_id)
self.bound_impl_trait_ref(def_id)
.map(|t| t.subst_identity())
.map(ImplSubject::Trait)
.unwrap_or_else(|| ImplSubject::Inherent(self.type_of(def_id)))
}

View File

@ -1027,7 +1027,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Checks if the bound region is in Impl Item.
pub fn is_bound_region_in_impl_item(self, suitable_region_binding_scope: LocalDefId) -> bool {
let container_id = self.parent(suitable_region_binding_scope.to_def_id());
if self.impl_trait_ref(container_id).is_some() {
if self.bound_impl_trait_ref(container_id).is_some() {
// For now, we do not try to target impls of traits. This is
// because this message is going to suggest that the user
// change the fn signature, but they may not be free to do so,

View File

@ -2187,8 +2187,12 @@ impl<'tcx> TyCtxt<'tcx> {
) -> Option<ImplOverlapKind> {
// If either trait impl references an error, they're allowed to overlap,
// as one of them essentially doesn't exist.
if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.references_error())
|| self.impl_trait_ref(def_id2).map_or(false, |tr| tr.references_error())
if self
.bound_impl_trait_ref(def_id1)
.map_or(false, |tr| tr.skip_binder().references_error())
|| self
.bound_impl_trait_ref(def_id2)
.map_or(false, |tr| tr.skip_binder().references_error())
{
return Some(ImplOverlapKind::Permitted { marker: false });
}
@ -2217,8 +2221,8 @@ impl<'tcx> TyCtxt<'tcx> {
let is_marker_overlap = {
let is_marker_impl = |def_id: DefId| -> bool {
let trait_ref = self.impl_trait_ref(def_id);
trait_ref.map_or(false, |tr| self.trait_def(tr.def_id).is_marker)
let trait_ref = self.bound_impl_trait_ref(def_id);
trait_ref.map_or(false, |tr| self.trait_def(tr.skip_binder().def_id).is_marker)
};
is_marker_impl(def_id1) && is_marker_impl(def_id2)
};
@ -2364,7 +2368,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Given the `DefId` of an impl, returns the `DefId` of the trait it implements.
/// If it implements no trait, returns `None`.
pub fn trait_id_of_impl(self, def_id: DefId) -> Option<DefId> {
self.impl_trait_ref(def_id).map(|tr| tr.def_id)
self.bound_impl_trait_ref(def_id).map(|tr| tr.skip_binder().def_id)
}
/// If the given `DefId` describes an item belonging to a trait,

View File

@ -1351,7 +1351,10 @@ fn create_mono_items_for_default_impls<'tcx>(
tcx.def_path_str(item.owner_id.to_def_id())
);
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
if let Some(trait_ref) = tcx
.bound_impl_trait_ref(item.owner_id.to_def_id())
.map(ty::EarlyBinder::subst_identity)
{
let param_env = ty::ParamEnv::reveal_all();
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
let overridden_methods = tcx.impl_item_implementor_ids(item.owner_id);

View File

@ -266,7 +266,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of)
&& self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads)
{
let trait_ref = self.tcx.impl_trait_ref(impl_of).unwrap();
let trait_ref = self.tcx.bound_impl_trait_ref(impl_of).unwrap().subst_identity();
if let ty::Adt(adt_def, _) = trait_ref.self_ty().kind()
&& let Some(adt_def_id) = adt_def.did().as_local()
{
@ -310,7 +310,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
}
Node::ImplItem(impl_item) => {
let item = self.tcx.local_parent(impl_item.owner_id.def_id);
if self.tcx.impl_trait_ref(item).is_none() {
if self.tcx.bound_impl_trait_ref(item.into()).is_none() {
//// If it's a type whose items are live, then it's live, too.
//// This is done to handle the case where, for example, the static
//// method of a private type is used, but the type itself is never
@ -534,7 +534,7 @@ fn check_item<'tcx>(
}
}
DefKind::Impl => {
let of_trait = tcx.impl_trait_ref(id.owner_id);
let of_trait = tcx.bound_impl_trait_ref(id.owner_id.to_def_id());
if of_trait.is_some() {
worklist.push(id.owner_id.def_id);

View File

@ -593,7 +593,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
let impl_def_id = self.tcx.hir().get_parent_item(ii.hir_id());
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
if self.tcx.bound_impl_trait_ref(impl_def_id.to_def_id()).is_none() {
self.check_missing_stability(ii.owner_id.def_id, ii.span);
self.check_missing_const_stability(ii.owner_id.def_id, ii.span);
}

View File

@ -337,8 +337,8 @@ trait VisibilityLike: Sized {
) -> Self {
let mut find = FindMin { tcx, effective_visibilities, min: Self::MAX };
find.visit(tcx.type_of(def_id));
if let Some(trait_ref) = tcx.impl_trait_ref(def_id) {
find.visit_trait(trait_ref);
if let Some(trait_ref) = tcx.bound_impl_trait_ref(def_id.into()) {
find.visit_trait(trait_ref.subst_identity());
}
find.min
}
@ -857,8 +857,8 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
}
fn trait_ref(&mut self) -> &mut Self {
if let Some(trait_ref) = self.ev.tcx.impl_trait_ref(self.item_def_id) {
self.visit_trait(trait_ref);
if let Some(trait_ref) = self.ev.tcx.bound_impl_trait_ref(self.item_def_id.into()) {
self.visit_trait(trait_ref.subst_identity());
}
self
}

View File

@ -77,8 +77,8 @@ pub fn overlapping_impls(
// a quick check via fast_reject to tell if the impl headers could possibly
// unify.
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer };
let impl1_ref = tcx.impl_trait_ref(impl1_def_id);
let impl2_ref = tcx.impl_trait_ref(impl2_def_id);
let impl1_ref = tcx.bound_impl_trait_ref(impl1_def_id).map(ty::EarlyBinder::subst_identity);
let impl2_ref = tcx.bound_impl_trait_ref(impl2_def_id).map(ty::EarlyBinder::subst_identity);
let may_overlap = match (impl1_ref, impl2_ref) {
(Some(a), Some(b)) => iter::zip(a.substs, b.substs)
.all(|(arg1, arg2)| drcx.generic_args_may_unify(arg1, arg2)),
@ -461,7 +461,7 @@ pub fn orphan_check(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Result<(), OrphanChe
// We only except this routine to be invoked on implementations
// of a trait, not inherent implementations.
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
let trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().skip_binder();
debug!("orphan_check: trait_ref={:?}", trait_ref);
// If the *trait* is local to the crate, ok.

View File

@ -1940,7 +1940,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
return None;
}
let imp = self.tcx.impl_trait_ref(def_id).unwrap();
let imp = self.tcx.bound_impl_trait_ref(def_id).unwrap().subst_identity();
self.fuzzy_match_tys(trait_pred.skip_binder().self_ty(), imp.self_ty(), false)
.map(|similarity| ImplCandidate { trait_ref: imp, similarity })
@ -2039,7 +2039,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
self.tcx.impl_polarity(def_id) != ty::ImplPolarity::Negative
|| self.tcx.is_builtin_derive(def_id)
})
.filter_map(|def_id| self.tcx.impl_trait_ref(def_id))
.filter_map(|def_id| self.tcx.bound_impl_trait_ref(def_id))
.map(ty::EarlyBinder::subst_identity)
.filter(|trait_ref| {
let self_ty = trait_ref.self_ty();
// Avoid mentioning type parameters.

View File

@ -521,8 +521,10 @@ fn is_impossible_method(tcx: TyCtxt<'_>, (impl_def_id, trait_item_def_id): (DefI
let generics = tcx.generics_of(trait_item_def_id);
let predicates = tcx.predicates_of(trait_item_def_id);
let impl_trait_ref =
tcx.impl_trait_ref(impl_def_id).expect("expected impl to correspond to trait");
let impl_trait_ref = tcx
.bound_impl_trait_ref(impl_def_id)
.expect("expected impl to correspond to trait")
.subst_identity();
let param_env = tcx.param_env(impl_def_id);
let mut visitor = ReferencesOnlyParentGenerics { tcx, generics, trait_item_def_id };

View File

@ -148,7 +148,7 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,
// create a parameter environment corresponding to a (placeholder) instantiation of impl1
let penv = tcx.param_env(impl1_def_id);
let impl1_trait_ref = tcx.impl_trait_ref(impl1_def_id).unwrap();
let impl1_trait_ref = tcx.bound_impl_trait_ref(impl1_def_id).unwrap().subst_identity();
// Create an infcx, taking the predicates of impl1 as assumptions:
let infcx = tcx.infer_ctxt().build();
@ -431,7 +431,7 @@ fn report_conflicting_impls<'tcx>(
pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String> {
use std::fmt::Write;
let trait_ref = tcx.impl_trait_ref(impl_def_id)?;
let trait_ref = tcx.bound_impl_trait_ref(impl_def_id)?.skip_binder();
let mut w = "impl".to_owned();
let substs = InternalSubsts::identity_for_item(tcx, impl_def_id);

View File

@ -48,7 +48,7 @@ trait ChildrenExt<'tcx> {
impl<'tcx> ChildrenExt<'tcx> for Children {
/// Insert an impl into this set of children without comparing to any existing impls.
fn insert_blindly(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) {
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
let trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst_identity();
if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer)
{
debug!("insert_blindly: impl_def_id={:?} st={:?}", impl_def_id, st);
@ -63,7 +63,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children {
/// an impl with a parent. The impl must be present in the list of
/// children already.
fn remove_existing(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) {
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
let trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst_identity();
let vec: &mut Vec<DefId>;
if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer)
{
@ -181,7 +181,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children {
if le && !ge {
debug!(
"descending as child of TraitRef {:?}",
tcx.impl_trait_ref(possible_sibling).unwrap()
tcx.bound_impl_trait_ref(possible_sibling).unwrap().subst_identity()
);
// The impl specializes `possible_sibling`.
@ -189,7 +189,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children {
} else if ge && !le {
debug!(
"placing as parent of TraitRef {:?}",
tcx.impl_trait_ref(possible_sibling).unwrap()
tcx.bound_impl_trait_ref(possible_sibling).unwrap().subst_identity()
);
replace_children.push(possible_sibling);
@ -275,7 +275,7 @@ impl<'tcx> GraphExt<'tcx> for Graph {
) -> Result<Option<FutureCompatOverlapError<'tcx>>, OverlapError<'tcx>> {
assert!(impl_def_id.is_local());
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
let trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst_identity();
let trait_def_id = trait_ref.def_id;
debug!(
@ -388,7 +388,7 @@ pub(crate) fn assoc_def(
impl_def_id: DefId,
assoc_def_id: DefId,
) -> Result<LeafDef, ErrorGuaranteed> {
let trait_def_id = tcx.impl_trait_ref(impl_def_id).unwrap().def_id;
let trait_def_id = tcx.bound_impl_trait_ref(impl_def_id).unwrap().skip_binder().def_id;
let trait_def = tcx.trait_def(trait_def_id);
// This function may be called while we are still building the

View File

@ -380,7 +380,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
let trait_def_id = auto_trait_id.0;
let all_impls = self.interner.tcx.all_impls(trait_def_id);
for impl_def_id in all_impls {
let trait_ref = self.interner.tcx.impl_trait_ref(impl_def_id).unwrap();
let trait_ref =
self.interner.tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst_identity();
let self_ty = trait_ref.self_ty();
let provides = match (self_ty.kind(), chalk_ty) {
(&ty::Adt(impl_adt_def, ..), Adt(id, ..)) => impl_adt_def.did() == id.0.did(),

View File

@ -21,14 +21,16 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
assumed_wf_types.extend(liberated_sig.inputs_and_output);
tcx.intern_type_list(&assumed_wf_types)
}
DefKind::Impl => match tcx.impl_trait_ref(def_id) {
Some(trait_ref) => {
let types: Vec<_> = trait_ref.substs.types().collect();
tcx.intern_type_list(&types)
DefKind::Impl => {
match tcx.bound_impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity) {
Some(trait_ref) => {
let types: Vec<_> = trait_ref.substs.types().collect();
tcx.intern_type_list(&types)
}
// Only the impl self type
None => tcx.intern_type_list(&[tcx.type_of(def_id)]),
}
// Only the impl self type
None => tcx.intern_type_list(&[tcx.type_of(def_id)]),
},
}
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)),
DefKind::Mod
| DefKind::Struct

View File

@ -289,7 +289,7 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Predica
// In a trait impl, we assume that the header trait ref and all its
// constituents are well-formed.
NodeKind::TraitImpl => {
let trait_ref = tcx.impl_trait_ref(def_id).expect("not an impl");
let trait_ref = tcx.bound_impl_trait_ref(def_id).expect("not an impl").subst_identity();
// FIXME(chalk): this has problems because of late-bound regions
//inputs.extend(trait_ref.substs.iter().flat_map(|arg| arg.walk()));
@ -359,8 +359,9 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Ty<'_>> {
debug!("issue33140_self_ty({:?})", def_id);
let trait_ref = tcx
.impl_trait_ref(def_id)
.unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id));
.bound_impl_trait_ref(def_id)
.unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id))
.skip_binder();
debug!("issue33140_self_ty({:?}), trait-ref={:?}", def_id, trait_ref);

View File

@ -376,7 +376,7 @@ pub(crate) fn build_impl(
let _prof_timer = cx.tcx.sess.prof.generic_activity("build_impl");
let tcx = cx.tcx;
let associated_trait = tcx.impl_trait_ref(did);
let associated_trait = tcx.bound_impl_trait_ref(did).map(ty::EarlyBinder::skip_binder);
// Only inline impl if the implemented trait is
// reachable in rustdoc generated documentation

View File

@ -734,7 +734,7 @@ impl Item {
ty::ImplContainer => {
// Trait impl items always inherit the impl's visibility --
// we don't want to show `pub`.
tcx.impl_trait_ref(tcx.parent(assoc_item.def_id)).is_some()
tcx.bound_impl_trait_ref(tcx.parent(assoc_item.def_id)).is_some()
}
};
if is_trait_item {

View File

@ -784,9 +784,9 @@ fn trait_impls_for<'a>(
// Look at each trait implementation to see if it's an impl for `did`
tcx.find_map_relevant_impl(trait_, ty, |impl_| {
let trait_ref = tcx.impl_trait_ref(impl_).expect("this is not an inherent impl");
let trait_ref = tcx.bound_impl_trait_ref(impl_).expect("this is not an inherent impl");
// Check if these are the same type.
let impl_type = trait_ref.self_ty();
let impl_type = trait_ref.subst_identity().self_ty();
trace!(
"comparing type {} with kind {:?} against type {:?}",
impl_type,

View File

@ -247,11 +247,11 @@ fn check_hash_peq<'tcx>(
return;
}
let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation");
let trait_ref = cx.tcx.bound_impl_trait_ref(impl_id).expect("must be a trait implementation");
// Only care about `impl PartialEq<Foo> for Foo`
// For `impl PartialEq<B> for A, input_types is [A, B]
if trait_ref.substs.type_at(1) == ty {
if trait_ref.subst_identity().substs.type_at(1) == ty {
span_lint_and_then(
cx,
DERIVED_HASH_WITH_MANUAL_EQ,
@ -295,11 +295,11 @@ fn check_ord_partial_ord<'tcx>(
return;
}
let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation");
let trait_ref = cx.tcx.bound_impl_trait_ref(impl_id).expect("must be a trait implementation");
// Only care about `impl PartialOrd<Foo> for Foo`
// For `impl PartialOrd<B> for A, input_types is [A, B]
if trait_ref.substs.type_at(1) == ty {
if trait_ref.subst_identity().substs.type_at(1) == ty {
let mess = if partial_ord_is_automatically_derived {
"you are implementing `Ord` explicitly but have derived `PartialOrd`"
} else {

View File

@ -55,8 +55,8 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
// check for `impl From<???> for ..`
if_chain! {
if let hir::ItemKind::Impl(impl_) = &item.kind;
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.def_id);
if let Some(impl_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id());
if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.skip_binder().def_id);
then {
lint_impl_body(cx, item.span, impl_.items);
}

View File

@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
&& let Some(into_trait_seg) = hir_trait_ref.path.segments.last()
// `impl Into<target_ty> for self_ty`
&& let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
&& let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
&& let Some(middle_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(ty::EarlyBinder::subst_identity)
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
&& !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _))
{

View File

@ -101,7 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
if name.ident.as_str() == "MIN";
if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id);
if let Some(impl_id) = cx.tcx.impl_of_method(const_id);
if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl
if let None = cx.tcx.bound_impl_trait_ref(impl_id); // An inherent impl
if cx.tcx.type_of(impl_id).is_integral();
then {
print_lint_and_sugg(cx, var_name, expr)
@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
if name.ident.as_str() == "min_value";
if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id);
if let Some(impl_id) = cx.tcx.impl_of_method(func_id);
if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl
if let None = cx.tcx.bound_impl_trait_ref(impl_id); // An inherent impl
if cx.tcx.type_of(impl_id).is_integral();
then {
print_lint_and_sugg(cx, var_name, expr)

View File

@ -53,7 +53,7 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir
"to_vec" => cx
.tcx
.impl_of_method(method_def_id)
.filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none())
.filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.bound_impl_trait_ref(impl_did).is_none())
.is_some(),
_ => false,
}

View File

@ -12,7 +12,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se
if count <= 1;
if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
if let Some(impl_id) = cx.tcx.impl_of_method(call_id);
if cx.tcx.impl_trait_ref(impl_id).is_none();
if cx.tcx.bound_impl_trait_ref(impl_id).is_none();
let self_ty = cx.tcx.type_of(impl_id);
if self_ty.is_slice() || self_ty.is_str();
then {

View File

@ -175,7 +175,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
// If the method is an impl for a trait, don't doc.
if let Some(cid) = cx.tcx.associated_item(impl_item.owner_id).impl_container(cx.tcx) {
if cx.tcx.impl_trait_ref(cid).is_some() {
if cx.tcx.bound_impl_trait_ref(cid).is_some() {
return;
}
} else {

View File

@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
let container_id = assoc_item.container_id(cx.tcx);
let trait_def_id = match assoc_item.container {
TraitContainer => Some(container_id),
ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.def_id),
ImplContainer => cx.tcx.bound_impl_trait_ref(container_id).map(|t| t.skip_binder().def_id),
};
if let Some(trait_def_id) = trait_def_id {

View File

@ -89,8 +89,8 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
if let Some(trait_id) = trait_ref.trait_def_id();
if send_trait == trait_id;
if hir_impl.polarity == ImplPolarity::Positive;
if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
if let self_ty = ty_trait_ref.self_ty();
if let Some(ty_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id());
if let self_ty = ty_trait_ref.subst_identity().self_ty();
if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind();
then {
let mut non_send_fields = Vec::new();

View File

@ -244,7 +244,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
})) => {
#[allow(trivial_casts)]
if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into())
&& let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
&& let Some(trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(|t| t.subst_identity())
&& let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id
{
(

View File

@ -133,11 +133,11 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
ref mut types_to_skip,
..
}) = self.stack.last_mut();
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_id);
if let Some(impl_trait_ref) = cx.tcx.bound_impl_trait_ref(impl_id.to_def_id());
then {
// `self_ty` is the semantic self type of `impl <trait> for <type>`. This cannot be
// `Self`.
let self_ty = impl_trait_ref.self_ty();
let self_ty = impl_trait_ref.subst_identity().self_ty();
// `trait_method_sig` is the signature of the function, how it is declared in the
// trait, not in the impl of the trait.