Split impl_(opt_)trait_ref
This commit is contained in:
@@ -210,8 +210,7 @@ fn ensure_impl_predicates_are_implied_by_item_defn<'tcx>(
|
||||
ty::EarlyBinder::bind(tcx.param_env(adt_def_id)).instantiate(tcx, adt_to_impl_args);
|
||||
|
||||
let fresh_impl_args = infcx.fresh_args_for_item(impl_span, impl_def_id.to_def_id());
|
||||
let fresh_adt_ty =
|
||||
tcx.impl_trait_ref(impl_def_id).unwrap().instantiate(tcx, fresh_impl_args).self_ty();
|
||||
let fresh_adt_ty = tcx.impl_trait_ref(impl_def_id).instantiate(tcx, fresh_impl_args).self_ty();
|
||||
|
||||
ocx.eq(&ObligationCause::dummy_with_span(impl_span), adt_env, fresh_adt_ty, impl_adt_ty)
|
||||
.expect("equating fully generic trait ref should never fail");
|
||||
|
||||
@@ -1191,9 +1191,7 @@ fn check_impl_items_against_trait<'tcx>(
|
||||
tcx,
|
||||
ty_impl_item,
|
||||
ty_trait_item,
|
||||
tcx.impl_trait_ref(ty_impl_item.container_id(tcx))
|
||||
.unwrap()
|
||||
.instantiate_identity(),
|
||||
tcx.impl_trait_ref(ty_impl_item.container_id(tcx)).instantiate_identity(),
|
||||
);
|
||||
}
|
||||
ty::AssocKind::Const { .. } => {}
|
||||
|
||||
@@ -38,8 +38,7 @@ pub(super) fn compare_impl_item(
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let impl_item = tcx.associated_item(impl_item_def_id);
|
||||
let trait_item = tcx.associated_item(impl_item.expect_trait_impl()?);
|
||||
let impl_trait_ref =
|
||||
tcx.impl_trait_ref(impl_item.container_id(tcx)).unwrap().instantiate_identity();
|
||||
let impl_trait_ref = tcx.impl_trait_ref(impl_item.container_id(tcx)).instantiate_identity();
|
||||
debug!(?impl_trait_ref);
|
||||
|
||||
match impl_item.kind {
|
||||
@@ -443,7 +442,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
||||
let impl_m = tcx.associated_item(impl_m_def_id.to_def_id());
|
||||
let trait_m = tcx.associated_item(impl_m.expect_trait_impl()?);
|
||||
let impl_trait_ref =
|
||||
tcx.impl_trait_ref(tcx.parent(impl_m_def_id.to_def_id())).unwrap().instantiate_identity();
|
||||
tcx.impl_trait_ref(tcx.parent(impl_m_def_id.to_def_id())).instantiate_identity();
|
||||
// First, check a few of the same things as `compare_impl_method`,
|
||||
// just so we don't ICE during instantiation later.
|
||||
check_method_is_structurally_compatible(tcx, impl_m, trait_m, impl_trait_ref, true)?;
|
||||
|
||||
@@ -244,7 +244,7 @@ fn missing_items_err(
|
||||
let snippet = with_types_for_signature!(suggestion_signature(
|
||||
tcx,
|
||||
trait_item,
|
||||
tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity(),
|
||||
tcx.impl_trait_ref(impl_def_id).instantiate_identity(),
|
||||
));
|
||||
let code = format!("{padding}{snippet}\n{padding}");
|
||||
if let Some(span) = tcx.hir_span_if_local(trait_item.def_id) {
|
||||
|
||||
@@ -1258,7 +1258,7 @@ 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().instantiate_identity();
|
||||
let trait_ref = tcx.impl_trait_ref(item.owner_id).instantiate_identity();
|
||||
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
|
||||
// other `Foo` impls are incoherent.
|
||||
tcx.ensure_ok().coherent_trait(trait_ref.def_id)?;
|
||||
|
||||
@@ -377,7 +377,7 @@ pub(crate) fn coerce_unsized_info<'tcx>(
|
||||
let unsize_trait = tcx.require_lang_item(LangItem::Unsize, span);
|
||||
|
||||
let source = tcx.type_of(impl_did).instantiate_identity();
|
||||
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().instantiate_identity();
|
||||
let trait_ref = tcx.impl_trait_ref(impl_did).instantiate_identity();
|
||||
|
||||
assert_eq!(trait_ref.def_id, coerce_unsized_trait);
|
||||
let target = trait_ref.args.type_at(1);
|
||||
@@ -707,7 +707,7 @@ fn visit_implementation_of_coerce_pointee_validity(
|
||||
checker: &Checker<'_>,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let tcx = checker.tcx;
|
||||
let self_ty = tcx.impl_trait_ref(checker.impl_def_id).unwrap().instantiate_identity().self_ty();
|
||||
let self_ty = tcx.impl_trait_ref(checker.impl_def_id).instantiate_identity().self_ty();
|
||||
let span = tcx.def_span(checker.impl_def_id);
|
||||
if !tcx.is_builtin_derived(checker.impl_def_id.into()) {
|
||||
return Err(tcx.dcx().emit_err(errors::CoercePointeeNoUserValidityAssertion { span }));
|
||||
|
||||
@@ -22,7 +22,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().instantiate_identity();
|
||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).instantiate_identity();
|
||||
trait_ref.error_reported()?;
|
||||
|
||||
match orphan_check(tcx, impl_def_id, OrphanCheckMode::Proper) {
|
||||
@@ -294,7 +294,7 @@ fn orphan_check<'tcx>(
|
||||
) -> Result<(), OrphanCheckErr<TyCtxt<'tcx>, FxIndexSet<DefId>>> {
|
||||
// We only accept 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.impl_trait_ref(impl_def_id);
|
||||
debug!(trait_ref = ?trait_ref.skip_binder());
|
||||
|
||||
// If the *trait* is local to the crate, ok.
|
||||
|
||||
@@ -108,7 +108,7 @@ pub(crate) fn vtables<'tcx>(tcx: TyCtxt<'tcx>) {
|
||||
|
||||
let vtable_entries = match tcx.hir_item(id).kind {
|
||||
hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) => {
|
||||
let trait_ref = tcx.impl_trait_ref(def_id).unwrap().instantiate_identity();
|
||||
let trait_ref = tcx.impl_trait_ref(def_id).instantiate_identity();
|
||||
if trait_ref.has_non_region_param() {
|
||||
tcx.dcx().span_err(
|
||||
attr.span(),
|
||||
|
||||
@@ -118,8 +118,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||
|
||||
let impl_assoc_identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
|
||||
let impl_def_id = tcx.parent(fn_def_id);
|
||||
let impl_trait_ref_args =
|
||||
tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity().args;
|
||||
let impl_trait_ref_args = tcx.impl_trait_ref(impl_def_id).instantiate_identity().args;
|
||||
|
||||
let impl_assoc_args =
|
||||
impl_assoc_identity_args.rebase_onto(tcx, impl_def_id, impl_trait_ref_args);
|
||||
@@ -162,9 +161,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||
if let Some(of_trait) = impl_.of_trait
|
||||
&& of_trait.defaultness.is_default()
|
||||
{
|
||||
is_default_impl_trait = tcx
|
||||
.impl_trait_ref(def_id)
|
||||
.map(|t| ty::Binder::dummy(t.instantiate_identity()));
|
||||
is_default_impl_trait =
|
||||
Some(ty::Binder::dummy(tcx.impl_trait_ref(def_id).instantiate_identity()));
|
||||
}
|
||||
}
|
||||
ItemKind::Trait(_, _, _, _, _, self_bounds, ..)
|
||||
@@ -352,10 +350,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||
// for details.
|
||||
if let Node::Item(&Item { kind: ItemKind::Impl(impl_), .. }) = node {
|
||||
let self_ty = tcx.type_of(def_id).instantiate_identity();
|
||||
let trait_ref = impl_
|
||||
.of_trait
|
||||
.is_some()
|
||||
.then(|| tcx.impl_trait_ref(def_id).unwrap().instantiate_identity());
|
||||
let trait_ref =
|
||||
impl_.of_trait.is_some().then(|| tcx.impl_trait_ref(def_id).instantiate_identity());
|
||||
cgp::setup_constraining_predicates(
|
||||
tcx,
|
||||
&mut predicates,
|
||||
@@ -467,7 +463,7 @@ fn const_evaluatable_predicates_of<'tcx>(
|
||||
{
|
||||
if impl_.of_trait.is_some() {
|
||||
debug!("visit impl trait_ref");
|
||||
let trait_ref = tcx.impl_trait_ref(def_id).unwrap();
|
||||
let trait_ref = tcx.impl_trait_ref(def_id);
|
||||
trait_ref.instantiate_identity().visit_with(&mut collector);
|
||||
}
|
||||
|
||||
|
||||
@@ -1387,10 +1387,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||
(_, 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 {
|
||||
// A cycle error occurred, most likely.
|
||||
self.dcx().span_bug(span, "expected cycle error");
|
||||
};
|
||||
let trait_ref = tcx.impl_trait_ref(impl_def_id);
|
||||
|
||||
self.probe_single_bound_for_assoc_item(
|
||||
|| {
|
||||
|
||||
@@ -85,8 +85,7 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained(
|
||||
|
||||
let impl_generics = tcx.generics_of(impl_def_id);
|
||||
let impl_predicates = tcx.predicates_of(impl_def_id);
|
||||
let impl_trait_ref =
|
||||
of_trait.then(|| tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity());
|
||||
let impl_trait_ref = of_trait.then(|| tcx.impl_trait_ref(impl_def_id).instantiate_identity());
|
||||
|
||||
impl_trait_ref.error_reported()?;
|
||||
|
||||
@@ -174,7 +173,8 @@ pub(crate) fn enforce_impl_non_lifetime_params_are_constrained(
|
||||
|
||||
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).map(ty::EarlyBinder::instantiate_identity);
|
||||
let impl_trait_ref =
|
||||
tcx.impl_opt_trait_ref(impl_def_id).map(ty::EarlyBinder::instantiate_identity);
|
||||
|
||||
impl_trait_ref.error_reported()?;
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ pub(super) fn check_min_specialization(
|
||||
}
|
||||
|
||||
fn parent_specialization_node(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId) -> Option<Node> {
|
||||
let trait_ref = tcx.impl_trait_ref(impl1_def_id).unwrap();
|
||||
let trait_ref = tcx.impl_trait_ref(impl1_def_id);
|
||||
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)?;
|
||||
@@ -215,7 +215,7 @@ fn unconstrained_parent_impl_args<'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).map(ty::EarlyBinder::instantiate_identity);
|
||||
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).instantiate_identity();
|
||||
|
||||
// Unfortunately the functions in `constrained_generic_parameters` don't do
|
||||
// what we want here. We want only a list of constrained parameters while
|
||||
@@ -224,7 +224,7 @@ fn unconstrained_parent_impl_args<'tcx>(
|
||||
for (clause, _) in impl_generic_predicates.predicates.iter() {
|
||||
if let ty::ClauseKind::Projection(proj) = clause.kind().skip_binder() {
|
||||
let unbound_trait_ref = proj.projection_term.trait_ref(tcx);
|
||||
if Some(unbound_trait_ref) == impl_trait_ref {
|
||||
if unbound_trait_ref == impl_trait_ref {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -373,7 +373,7 @@ fn check_predicates<'tcx>(
|
||||
.map(|(c, _span)| c.as_predicate());
|
||||
|
||||
// Include the well-formed predicates of the type parameters of the impl.
|
||||
for arg in tcx.impl_trait_ref(impl1_def_id).unwrap().instantiate_identity().args {
|
||||
for arg in tcx.impl_trait_ref(impl1_def_id).instantiate_identity().args {
|
||||
let Some(term) = arg.as_term() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user