Rollup merge of #112867 - compiler-errors:more-impl-source-nits, r=lcnr
More `ImplSource` nits Even more clean-ups, I'll put this up in parallel with the `select_in_new_trait_solver` PR. r? ``@lcnr``
This commit is contained in:
commit
fc2c587cd0
8 changed files with 47 additions and 106 deletions
|
@ -5,7 +5,7 @@ pub mod suggestions;
|
|||
use super::{
|
||||
FulfillmentError, FulfillmentErrorCode, MismatchedProjectionTypes, Obligation, ObligationCause,
|
||||
ObligationCauseCode, ObligationCtxt, OutputTypeParameterMismatch, Overflow,
|
||||
PredicateObligation, SelectionContext, SelectionError, TraitNotObjectSafe,
|
||||
PredicateObligation, SelectionError, TraitNotObjectSafe,
|
||||
};
|
||||
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
|
||||
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
|
@ -2272,55 +2272,40 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
)
|
||||
};
|
||||
|
||||
let obligation = obligation.with(self.tcx, trait_ref);
|
||||
let mut selcx = SelectionContext::new(&self);
|
||||
match selcx.select_from_obligation(&obligation) {
|
||||
Ok(None) => {
|
||||
let ambiguities =
|
||||
ambiguity::recompute_applicable_impls(self.infcx, &obligation);
|
||||
let has_non_region_infer = trait_ref
|
||||
.skip_binder()
|
||||
.substs
|
||||
.types()
|
||||
.any(|t| !t.is_ty_or_numeric_infer());
|
||||
// It doesn't make sense to talk about applicable impls if there are more
|
||||
// than a handful of them.
|
||||
if ambiguities.len() > 1 && ambiguities.len() < 10 && has_non_region_infer {
|
||||
if self.tainted_by_errors().is_some() && subst.is_none() {
|
||||
// If `subst.is_none()`, then this is probably two param-env
|
||||
// candidates or impl candidates that are equal modulo lifetimes.
|
||||
// Therefore, if we've already emitted an error, just skip this
|
||||
// one, since it's not particularly actionable.
|
||||
err.cancel();
|
||||
return;
|
||||
}
|
||||
self.annotate_source_of_ambiguity(&mut err, &ambiguities, predicate);
|
||||
} else {
|
||||
if self.tainted_by_errors().is_some() {
|
||||
err.cancel();
|
||||
return;
|
||||
}
|
||||
err.note(format!("cannot satisfy `{}`", predicate));
|
||||
let impl_candidates = self.find_similar_impl_candidates(
|
||||
predicate.to_opt_poly_trait_pred().unwrap(),
|
||||
);
|
||||
if impl_candidates.len() < 10 {
|
||||
self.report_similar_impl_candidates(
|
||||
impl_candidates.as_slice(),
|
||||
trait_ref,
|
||||
obligation.cause.body_id,
|
||||
&mut err,
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
let ambiguities = ambiguity::recompute_applicable_impls(
|
||||
self.infcx,
|
||||
&obligation.with(self.tcx, trait_ref),
|
||||
);
|
||||
let has_non_region_infer =
|
||||
trait_ref.skip_binder().substs.types().any(|t| !t.is_ty_or_numeric_infer());
|
||||
// It doesn't make sense to talk about applicable impls if there are more
|
||||
// than a handful of them.
|
||||
if ambiguities.len() > 1 && ambiguities.len() < 10 && has_non_region_infer {
|
||||
if self.tainted_by_errors().is_some() && subst.is_none() {
|
||||
// If `subst.is_none()`, then this is probably two param-env
|
||||
// candidates or impl candidates that are equal modulo lifetimes.
|
||||
// Therefore, if we've already emitted an error, just skip this
|
||||
// one, since it's not particularly actionable.
|
||||
err.cancel();
|
||||
return;
|
||||
}
|
||||
_ => {
|
||||
if self.tainted_by_errors().is_some() {
|
||||
err.cancel();
|
||||
return;
|
||||
}
|
||||
err.note(format!("cannot satisfy `{}`", predicate));
|
||||
self.annotate_source_of_ambiguity(&mut err, &ambiguities, predicate);
|
||||
} else {
|
||||
if self.tainted_by_errors().is_some() {
|
||||
err.cancel();
|
||||
return;
|
||||
}
|
||||
err.note(format!("cannot satisfy `{}`", predicate));
|
||||
let impl_candidates = self
|
||||
.find_similar_impl_candidates(predicate.to_opt_poly_trait_pred().unwrap());
|
||||
if impl_candidates.len() < 10 {
|
||||
self.report_similar_impl_candidates(
|
||||
impl_candidates.as_slice(),
|
||||
trait_ref,
|
||||
obligation.cause.body_id,
|
||||
&mut err,
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1720,7 +1720,6 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
|||
};
|
||||
|
||||
let eligible = match &impl_source {
|
||||
super::ImplSource::TraitAlias(_) => true,
|
||||
super::ImplSource::UserDefined(impl_data) => {
|
||||
// We have to be careful when projecting out of an
|
||||
// impl because of specialization. If we are not in
|
||||
|
@ -2012,8 +2011,7 @@ fn confirm_select_candidate<'cx, 'tcx>(
|
|||
}
|
||||
super::ImplSource::Object(_)
|
||||
| super::ImplSource::Param(..)
|
||||
| super::ImplSource::TraitUpcasting(_)
|
||||
| super::ImplSource::TraitAlias(..) => {
|
||||
| super::ImplSource::TraitUpcasting(_) => {
|
||||
// we don't create Select candidates with this kind of resolution
|
||||
span_bug!(
|
||||
obligation.cause.span,
|
||||
|
|
|
@ -27,10 +27,9 @@ use crate::traits::vtable::{
|
|||
};
|
||||
use crate::traits::{
|
||||
BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource,
|
||||
ImplSourceObjectData, ImplSourceTraitAliasData, ImplSourceTraitUpcastingData,
|
||||
ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause,
|
||||
OutputTypeParameterMismatch, PredicateObligation, Selection, SelectionError,
|
||||
TraitNotObjectSafe, TraitObligation, Unimplemented,
|
||||
ImplSourceObjectData, ImplSourceTraitUpcastingData, ImplSourceUserDefinedData, Normalized,
|
||||
Obligation, ObligationCause, OutputTypeParameterMismatch, PredicateObligation, Selection,
|
||||
SelectionError, TraitNotObjectSafe, TraitObligation, Unimplemented,
|
||||
};
|
||||
|
||||
use super::BuiltinImplConditions;
|
||||
|
@ -105,7 +104,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
TraitAliasCandidate => {
|
||||
let data = self.confirm_trait_alias_candidate(obligation);
|
||||
ImplSource::TraitAlias(data)
|
||||
ImplSource::Builtin(data)
|
||||
}
|
||||
|
||||
BuiltinObjectCandidate => {
|
||||
|
@ -652,11 +651,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
(unnormalized_upcast_trait_ref, ty::Binder::dummy(object_trait_ref)),
|
||||
);
|
||||
|
||||
Ok(ImplSourceObjectData {
|
||||
upcast_trait_def_id: upcast_trait_ref.def_id(),
|
||||
vtable_base,
|
||||
nested,
|
||||
})
|
||||
Ok(ImplSourceObjectData { vtable_base, nested })
|
||||
}
|
||||
|
||||
fn confirm_fn_pointer_candidate(
|
||||
|
@ -721,10 +716,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
fn confirm_trait_alias_candidate(
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
) -> ImplSourceTraitAliasData<'tcx, PredicateObligation<'tcx>> {
|
||||
) -> Vec<PredicateObligation<'tcx>> {
|
||||
debug!(?obligation, "confirm_trait_alias_candidate");
|
||||
|
||||
let alias_def_id = obligation.predicate.def_id();
|
||||
let predicate = self.infcx.instantiate_binder_with_placeholders(obligation.predicate);
|
||||
let trait_ref = predicate.trait_ref;
|
||||
let trait_def_id = trait_ref.def_id;
|
||||
|
@ -741,7 +735,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
debug!(?trait_def_id, ?trait_obligations, "trait alias obligations");
|
||||
|
||||
ImplSourceTraitAliasData { alias_def_id, substs, nested: trait_obligations }
|
||||
trait_obligations
|
||||
}
|
||||
|
||||
fn confirm_generator_candidate(
|
||||
|
|
|
@ -248,7 +248,7 @@ pub fn get_vtable_index_of_object_method<'tcx, N>(
|
|||
) -> Option<usize> {
|
||||
// Count number of methods preceding the one we are selecting and
|
||||
// add them to the total offset.
|
||||
tcx.own_existential_vtable_entries(object.upcast_trait_def_id)
|
||||
tcx.own_existential_vtable_entries(tcx.parent(method_def_id))
|
||||
.iter()
|
||||
.copied()
|
||||
.position(|def_id| def_id == method_def_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue