Split impl_(opt_)trait_ref
This commit is contained in:
@@ -574,7 +574,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
let Some(impl_def_id) = self.tcx.trait_impl_of_assoc(impl_item_def_id.to_def_id()) else {
|
||||
return;
|
||||
};
|
||||
let trait_ref = self.tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||
let trait_ref = self.tcx.impl_trait_ref(impl_def_id);
|
||||
let trait_args = trait_ref
|
||||
.instantiate_identity()
|
||||
// Replace the explicit self type with `Self` for better suggestion rendering
|
||||
|
||||
@@ -47,8 +47,7 @@ pub fn compute_applicable_impls_for_diagnostics<'tcx>(
|
||||
);
|
||||
|
||||
let impl_args = infcx.fresh_args_for_item(DUMMY_SP, impl_def_id);
|
||||
let impl_trait_ref =
|
||||
tcx.impl_trait_ref(impl_def_id).unwrap().instantiate(tcx, impl_args);
|
||||
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).instantiate(tcx, impl_args);
|
||||
let impl_trait_ref =
|
||||
ocx.normalize(&ObligationCause::dummy(), param_env, impl_trait_ref);
|
||||
|
||||
|
||||
@@ -354,7 +354,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, '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)?.instantiate_identity();
|
||||
let trait_ref = tcx.impl_opt_trait_ref(impl_def_id)?.instantiate_identity();
|
||||
let mut w = "impl".to_owned();
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
||||
@@ -44,8 +44,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
|
||||
self.tcx.for_each_relevant_impl(trait_pred.def_id(), trait_self_ty, |def_id| {
|
||||
let impl_args = self.fresh_args_for_item(obligation.cause.span, def_id);
|
||||
let impl_trait_ref =
|
||||
tcx.impl_trait_ref(def_id).unwrap().instantiate(tcx, impl_args);
|
||||
let impl_trait_ref = tcx.impl_trait_ref(def_id).instantiate(tcx, impl_args);
|
||||
|
||||
let impl_self_ty = impl_trait_ref.self_ty();
|
||||
|
||||
|
||||
@@ -137,8 +137,8 @@ pub fn overlapping_trait_impls(
|
||||
// Before doing expensive operations like entering an inference context, do
|
||||
// a quick check via fast_reject to tell if the impl headers could possibly
|
||||
// unify.
|
||||
let impl1_args = tcx.impl_trait_ref(impl1_def_id).unwrap().skip_binder().args;
|
||||
let impl2_args = tcx.impl_trait_ref(impl2_def_id).unwrap().skip_binder().args;
|
||||
let impl1_args = tcx.impl_trait_ref(impl1_def_id).skip_binder().args;
|
||||
let impl2_args = tcx.impl_trait_ref(impl2_def_id).skip_binder().args;
|
||||
let may_overlap =
|
||||
DeepRejectCtxt::relate_infer_infer(tcx).args_may_unify(impl1_args, impl2_args);
|
||||
|
||||
@@ -209,8 +209,7 @@ fn fresh_impl_header<'tcx>(
|
||||
impl_def_id,
|
||||
impl_args,
|
||||
self_ty: tcx.type_of(impl_def_id).instantiate(tcx, impl_args),
|
||||
trait_ref: is_of_trait
|
||||
.then(|| tcx.impl_trait_ref(impl_def_id).unwrap().instantiate(tcx, impl_args)),
|
||||
trait_ref: is_of_trait.then(|| tcx.impl_trait_ref(impl_def_id).instantiate(tcx, impl_args)),
|
||||
predicates: tcx
|
||||
.predicates_of(impl_def_id)
|
||||
.instantiate(tcx, impl_args)
|
||||
|
||||
@@ -835,10 +835,7 @@ fn is_impossible_associated_item(
|
||||
let param_env = ty::ParamEnv::empty();
|
||||
let fresh_args = infcx.fresh_args_for_item(tcx.def_span(impl_def_id), impl_def_id);
|
||||
|
||||
let impl_trait_ref = tcx
|
||||
.impl_trait_ref(impl_def_id)
|
||||
.expect("expected impl to correspond to trait")
|
||||
.instantiate(tcx, fresh_args);
|
||||
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).instantiate(tcx, fresh_args);
|
||||
|
||||
let mut visitor = ReferencesOnlyParentGenerics { tcx, generics, trait_item_def_id };
|
||||
let predicates_for_trait = predicates.predicates.iter().filter_map(|(pred, span)| {
|
||||
|
||||
@@ -117,7 +117,7 @@ pub fn translate_args_with_cause<'tcx>(
|
||||
param_env, source_impl, source_args, target_node
|
||||
);
|
||||
let source_trait_ref =
|
||||
infcx.tcx.impl_trait_ref(source_impl).unwrap().instantiate(infcx.tcx, source_args);
|
||||
infcx.tcx.impl_trait_ref(source_impl).instantiate(infcx.tcx, source_args);
|
||||
|
||||
// translate the Self and Param parts of the generic parameters, since those
|
||||
// vary across impls
|
||||
@@ -176,11 +176,7 @@ fn fulfill_implication<'tcx>(
|
||||
let target_trait_ref = ocx.normalize(
|
||||
cause,
|
||||
param_env,
|
||||
infcx
|
||||
.tcx
|
||||
.impl_trait_ref(target_impl)
|
||||
.expect("expected source impl to be a trait impl")
|
||||
.instantiate(infcx.tcx, target_args),
|
||||
infcx.tcx.impl_trait_ref(target_impl).instantiate(infcx.tcx, target_args),
|
||||
);
|
||||
|
||||
// do the impls unify? If not, no specialization.
|
||||
@@ -307,11 +303,7 @@ pub(super) fn specializes(
|
||||
let parent_impl_trait_ref = ocx.normalize(
|
||||
cause,
|
||||
param_env,
|
||||
infcx
|
||||
.tcx
|
||||
.impl_trait_ref(parent_impl_def_id)
|
||||
.expect("expected source impl to be a trait impl")
|
||||
.instantiate(infcx.tcx, parent_args),
|
||||
infcx.tcx.impl_trait_ref(parent_impl_def_id).instantiate(infcx.tcx, parent_args),
|
||||
);
|
||||
|
||||
// do the impls unify? If not, no specialization.
|
||||
|
||||
@@ -38,7 +38,7 @@ enum Inserted<'tcx> {
|
||||
impl<'tcx> 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().skip_binder();
|
||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).skip_binder();
|
||||
if let Some(st) =
|
||||
fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::InstantiateWithInfer)
|
||||
{
|
||||
@@ -54,7 +54,7 @@ impl<'tcx> 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().skip_binder();
|
||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).skip_binder();
|
||||
let vec: &mut Vec<DefId>;
|
||||
if let Some(st) =
|
||||
fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::InstantiateWithInfer)
|
||||
@@ -164,7 +164,7 @@ impl<'tcx> Children {
|
||||
if le && !ge {
|
||||
debug!(
|
||||
"descending as child of TraitRef {:?}",
|
||||
tcx.impl_trait_ref(possible_sibling).unwrap().instantiate_identity()
|
||||
tcx.impl_trait_ref(possible_sibling).instantiate_identity()
|
||||
);
|
||||
|
||||
// The impl specializes `possible_sibling`.
|
||||
@@ -172,7 +172,7 @@ impl<'tcx> Children {
|
||||
} else if ge && !le {
|
||||
debug!(
|
||||
"placing as parent of TraitRef {:?}",
|
||||
tcx.impl_trait_ref(possible_sibling).unwrap().instantiate_identity()
|
||||
tcx.impl_trait_ref(possible_sibling).instantiate_identity()
|
||||
);
|
||||
|
||||
replace_children.push(possible_sibling);
|
||||
@@ -242,7 +242,7 @@ impl<'tcx> Graph {
|
||||
assert!(impl_def_id.is_local());
|
||||
|
||||
// FIXME: use `EarlyBinder` in `self.children`
|
||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder();
|
||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).skip_binder();
|
||||
let trait_def_id = trait_ref.def_id;
|
||||
|
||||
debug!(
|
||||
|
||||
Reference in New Issue
Block a user