mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 10:33:34 +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;
|
||||
|
||||
pub enum Ambiguity {
|
||||
#[derive(Debug)]
|
||||
pub enum CandidateSource {
|
||||
DefId(DefId),
|
||||
ParamEnv(Span),
|
||||
}
|
||||
|
||||
pub fn recompute_applicable_impls<'tcx>(
|
||||
pub fn compute_applicable_impls_for_diagnostics<'tcx>(
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
obligation: &PolyTraitObligation<'tcx>,
|
||||
) -> Vec<Ambiguity> {
|
||||
) -> Vec<CandidateSource> {
|
||||
let tcx = infcx.tcx;
|
||||
let param_env = obligation.param_env;
|
||||
|
||||
@ -97,7 +98,7 @@ pub fn recompute_applicable_impls<'tcx>(
|
||||
obligation.predicate.skip_binder().trait_ref.self_ty(),
|
||||
|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)
|
||||
== 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 {
|
||||
ambiguities.push(Ambiguity::ParamEnv(span))
|
||||
ambiguities.push(CandidateSource::ParamEnv(span))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// ignore-tidy-filelength :(
|
||||
|
||||
mod ambiguity;
|
||||
pub mod ambiguity;
|
||||
mod infer_ctxt_ext;
|
||||
pub mod on_unimplemented;
|
||||
pub mod suggestions;
|
||||
|
@ -10,7 +10,7 @@ use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use crate::infer::InferCtxtExt as _;
|
||||
use crate::infer::{self, InferCtxt};
|
||||
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::specialize::to_pretty_impl_header;
|
||||
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,
|
||||
&obligation.with(self.tcx, trait_ref),
|
||||
);
|
||||
@ -2702,7 +2702,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
fn annotate_source_of_ambiguity(
|
||||
&self,
|
||||
err: &mut Diag<'_>,
|
||||
ambiguities: &[ambiguity::Ambiguity],
|
||||
ambiguities: &[ambiguity::CandidateSource],
|
||||
predicate: ty::Predicate<'tcx>,
|
||||
) {
|
||||
let mut spans = vec![];
|
||||
@ -2711,7 +2711,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
let mut has_param_env = false;
|
||||
for ambiguity in ambiguities {
|
||||
match ambiguity {
|
||||
ambiguity::Ambiguity::DefId(impl_def_id) => {
|
||||
ambiguity::CandidateSource::DefId(impl_def_id) => {
|
||||
match self.tcx.span_of_impl(*impl_def_id) {
|
||||
Ok(span) => spans.push(span),
|
||||
Err(name) => {
|
||||
@ -2722,7 +2722,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
ambiguity::Ambiguity::ParamEnv(span) => {
|
||||
ambiguity::CandidateSource::ParamEnv(span) => {
|
||||
has_param_env = true;
|
||||
spans.push(*span);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user