mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-09 05:23:07 +00:00
Expose rustc_trait_selection::error_reporting::ambiguity module
This commit is contained in:
parent
524f3c9c44
commit
617324095b
@ -7,15 +7,16 @@ use rustc_span::{Span, DUMMY_SP};
|
|||||||
|
|
||||||
use crate::traits::ObligationCtxt;
|
use crate::traits::ObligationCtxt;
|
||||||
|
|
||||||
pub enum Ambiguity {
|
#[derive(Debug)]
|
||||||
|
pub enum CandidateSource {
|
||||||
DefId(DefId),
|
DefId(DefId),
|
||||||
ParamEnv(Span),
|
ParamEnv(Span),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recompute_applicable_impls<'tcx>(
|
pub fn compute_applicable_impls_for_diagnostics<'tcx>(
|
||||||
infcx: &InferCtxt<'tcx>,
|
infcx: &InferCtxt<'tcx>,
|
||||||
obligation: &PolyTraitObligation<'tcx>,
|
obligation: &PolyTraitObligation<'tcx>,
|
||||||
) -> Vec<Ambiguity> {
|
) -> Vec<CandidateSource> {
|
||||||
let tcx = infcx.tcx;
|
let tcx = infcx.tcx;
|
||||||
let param_env = obligation.param_env;
|
let param_env = obligation.param_env;
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ pub fn recompute_applicable_impls<'tcx>(
|
|||||||
obligation.predicate.skip_binder().trait_ref.self_ty(),
|
obligation.predicate.skip_binder().trait_ref.self_ty(),
|
||||||
|impl_def_id| {
|
|impl_def_id| {
|
||||||
if infcx.probe(|_| impl_may_apply(impl_def_id)) {
|
if infcx.probe(|_| impl_may_apply(impl_def_id)) {
|
||||||
ambiguities.push(Ambiguity::DefId(impl_def_id))
|
ambiguities.push(CandidateSource::DefId(impl_def_id))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -112,9 +113,9 @@ pub fn recompute_applicable_impls<'tcx>(
|
|||||||
if kind.rebind(trait_pred.trait_ref)
|
if kind.rebind(trait_pred.trait_ref)
|
||||||
== ty::Binder::dummy(ty::TraitRef::identity(tcx, trait_pred.def_id()))
|
== ty::Binder::dummy(ty::TraitRef::identity(tcx, trait_pred.def_id()))
|
||||||
{
|
{
|
||||||
ambiguities.push(Ambiguity::ParamEnv(tcx.def_span(trait_pred.def_id())))
|
ambiguities.push(CandidateSource::ParamEnv(tcx.def_span(trait_pred.def_id())))
|
||||||
} else {
|
} else {
|
||||||
ambiguities.push(Ambiguity::ParamEnv(span))
|
ambiguities.push(CandidateSource::ParamEnv(span))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// ignore-tidy-filelength :(
|
// ignore-tidy-filelength :(
|
||||||
|
|
||||||
mod ambiguity;
|
pub mod ambiguity;
|
||||||
mod infer_ctxt_ext;
|
mod infer_ctxt_ext;
|
||||||
pub mod on_unimplemented;
|
pub mod on_unimplemented;
|
||||||
pub mod suggestions;
|
pub mod suggestions;
|
||||||
|
@ -10,7 +10,7 @@ use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
|||||||
use crate::infer::InferCtxtExt as _;
|
use crate::infer::InferCtxtExt as _;
|
||||||
use crate::infer::{self, InferCtxt};
|
use crate::infer::{self, InferCtxt};
|
||||||
use crate::traits::error_reporting::infer_ctxt_ext::InferCtxtExt;
|
use crate::traits::error_reporting::infer_ctxt_ext::InferCtxtExt;
|
||||||
use crate::traits::error_reporting::{ambiguity, ambiguity::Ambiguity::*};
|
use crate::traits::error_reporting::{ambiguity, ambiguity::CandidateSource::*};
|
||||||
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
|
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
|
||||||
use crate::traits::specialize::to_pretty_impl_header;
|
use crate::traits::specialize::to_pretty_impl_header;
|
||||||
use crate::traits::NormalizeExt;
|
use crate::traits::NormalizeExt;
|
||||||
@ -2386,7 +2386,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut ambiguities = ambiguity::recompute_applicable_impls(
|
let mut ambiguities = ambiguity::compute_applicable_impls_for_diagnostics(
|
||||||
self.infcx,
|
self.infcx,
|
||||||
&obligation.with(self.tcx, trait_ref),
|
&obligation.with(self.tcx, trait_ref),
|
||||||
);
|
);
|
||||||
@ -2702,7 +2702,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
fn annotate_source_of_ambiguity(
|
fn annotate_source_of_ambiguity(
|
||||||
&self,
|
&self,
|
||||||
err: &mut Diag<'_>,
|
err: &mut Diag<'_>,
|
||||||
ambiguities: &[ambiguity::Ambiguity],
|
ambiguities: &[ambiguity::CandidateSource],
|
||||||
predicate: ty::Predicate<'tcx>,
|
predicate: ty::Predicate<'tcx>,
|
||||||
) {
|
) {
|
||||||
let mut spans = vec![];
|
let mut spans = vec![];
|
||||||
@ -2711,7 +2711,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
let mut has_param_env = false;
|
let mut has_param_env = false;
|
||||||
for ambiguity in ambiguities {
|
for ambiguity in ambiguities {
|
||||||
match ambiguity {
|
match ambiguity {
|
||||||
ambiguity::Ambiguity::DefId(impl_def_id) => {
|
ambiguity::CandidateSource::DefId(impl_def_id) => {
|
||||||
match self.tcx.span_of_impl(*impl_def_id) {
|
match self.tcx.span_of_impl(*impl_def_id) {
|
||||||
Ok(span) => spans.push(span),
|
Ok(span) => spans.push(span),
|
||||||
Err(name) => {
|
Err(name) => {
|
||||||
@ -2722,7 +2722,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ambiguity::Ambiguity::ParamEnv(span) => {
|
ambiguity::CandidateSource::ParamEnv(span) => {
|
||||||
has_param_env = true;
|
has_param_env = true;
|
||||||
spans.push(*span);
|
spans.push(*span);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user