diff options
| author | Urgau <urgau@numericable.fr> | 2024-03-14 23:31:10 +0100 |
|---|---|---|
| committer | Urgau <urgau@numericable.fr> | 2024-04-05 18:39:37 +0200 |
| commit | 617324095be2be7c00a872351951297f241a60d6 (patch) | |
| tree | b0b9311927a8cdcd72411d00e649a0abf7c00bfa | |
| parent | 524f3c9c44b190c92c74bc3ac26443de7076b7ef (diff) | |
| download | rust-617324095be2be7c00a872351951297f241a60d6.tar.gz rust-617324095be2be7c00a872351951297f241a60d6.zip | |
Expose rustc_trait_selection::error_reporting::ambiguity module
3 files changed, 13 insertions, 12 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs index 68560b1378a..ddb582ffab0 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs @@ -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)) } } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 0515b09ae46..10c03387a5b 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1,6 +1,6 @@ // ignore-tidy-filelength :( -mod ambiguity; +pub mod ambiguity; mod infer_ctxt_ext; pub mod on_unimplemented; pub mod suggestions; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index aef98dbad5f..144971b63c0 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -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); } |
