Move FulfillmentErrorCode to rustc_trait_selection too

This commit is contained in:
Michael Goulet 2024-06-01 15:08:44 -04:00
parent 94a524ed11
commit 27f5eccd1f
8 changed files with 51 additions and 52 deletions

View File

@ -11,7 +11,7 @@ use rustc_hir::def::{CtorKind, Namespace};
use rustc_hir::CoroutineKind; use rustc_hir::CoroutineKind;
use rustc_index::IndexSlice; use rustc_index::IndexSlice;
use rustc_infer::infer::BoundRegionConversionTime; use rustc_infer::infer::BoundRegionConversionTime;
use rustc_infer::traits::{FulfillmentErrorCode, SelectionError}; use rustc_infer::traits::SelectionError;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::mir::tcx::PlaceTy; use rustc_middle::mir::tcx::PlaceTy;
use rustc_middle::mir::{ use rustc_middle::mir::{
@ -29,7 +29,9 @@ use rustc_span::{symbol::sym, Span, Symbol, DUMMY_SP};
use rustc_target::abi::{FieldIdx, VariantIdx}; use rustc_target::abi::{FieldIdx, VariantIdx};
use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt as _; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt as _;
use rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions; use rustc_trait_selection::traits::{
type_known_to_meet_bound_modulo_regions, FulfillmentErrorCode,
};
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;

View File

@ -6,7 +6,6 @@ use hir::{ExprKind, Param};
use rustc_errors::{Applicability, Diag}; use rustc_errors::{Applicability, Diag};
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_hir::{self as hir, BindingMode, ByRef, Node}; use rustc_hir::{self as hir, BindingMode, ByRef, Node};
use rustc_infer::traits;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem}; use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt, Upcast}; use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt, Upcast};
@ -18,6 +17,7 @@ use rustc_span::symbol::{kw, Symbol};
use rustc_span::{sym, BytePos, DesugaringKind, Span}; use rustc_span::{sym, BytePos, DesugaringKind, Span};
use rustc_target::abi::FieldIdx; use rustc_target::abi::FieldIdx;
use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits;
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
use crate::diagnostics::BorrowedContentSource; use crate::diagnostics::BorrowedContentSource;

View File

@ -22,7 +22,6 @@ use rustc_hir::{
}; };
use rustc_hir_analysis::collect::suggest_impl_trait; use rustc_hir_analysis::collect::suggest_impl_trait;
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
use rustc_infer::traits;
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
use rustc_middle::middle::stability::EvalResult; use rustc_middle::middle::stability::EvalResult;
use rustc_middle::span_bug; use rustc_middle::span_bug;
@ -36,6 +35,7 @@ use rustc_span::source_map::Spanned;
use rustc_span::symbol::{sym, Ident}; use rustc_span::symbol::{sym, Ident};
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits;
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
use rustc_trait_selection::traits::error_reporting::DefIdOrName; use rustc_trait_selection::traits::error_reporting::DefIdOrName;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;

View File

@ -15,8 +15,7 @@ use hir::def_id::LocalDefId;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::query::NoSolution;
use rustc_middle::traits::solve::Certainty; use rustc_middle::traits::solve::Certainty;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
use rustc_middle::ty::{self, Const, Ty, TyCtxt, Upcast};
use rustc_span::Span; use rustc_span::Span;
pub use self::ImplSource::*; pub use self::ImplSource::*;
@ -124,24 +123,6 @@ pub type Selection<'tcx> = ImplSource<'tcx, PredicateObligation<'tcx>>;
pub type ObligationInspector<'tcx> = pub type ObligationInspector<'tcx> =
fn(&InferCtxt<'tcx>, &PredicateObligation<'tcx>, Result<Certainty, NoSolution>); fn(&InferCtxt<'tcx>, &PredicateObligation<'tcx>, Result<Certainty, NoSolution>);
// TODO: Pull this down too
#[derive(Clone)]
pub enum FulfillmentErrorCode<'tcx> {
/// Inherently impossible to fulfill; this trait is implemented if and only
/// if it is already implemented.
Cycle(Vec<PredicateObligation<'tcx>>),
Select(SelectionError<'tcx>),
Project(MismatchedProjectionTypes<'tcx>),
Subtype(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
ConstEquate(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
Ambiguity {
/// Overflow is only `Some(suggest_recursion_limit)` when using the next generation
/// trait solver `-Znext-solver`. With the old solver overflow is eagerly handled by
/// emitting a fatal error instead.
overflow: Option<bool>,
},
}
impl<'tcx, O> Obligation<'tcx, O> { impl<'tcx, O> Obligation<'tcx, O> {
pub fn new( pub fn new(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,

View File

@ -29,27 +29,6 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> {
} }
} }
impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use traits::FulfillmentErrorCode::*;
match *self {
Select(ref e) => write!(f, "{e:?}"),
Project(ref e) => write!(f, "{e:?}"),
Subtype(ref a, ref b) => {
write!(f, "CodeSubtypeError({a:?}, {b:?})")
}
ConstEquate(ref a, ref b) => {
write!(f, "CodeConstEquateError({a:?}, {b:?})")
}
Ambiguity { overflow: None } => write!(f, "Ambiguity"),
Ambiguity { overflow: Some(suggest_increasing_limit) } => {
write!(f, "Overflow({suggest_increasing_limit})")
}
Cycle(ref cycle) => write!(f, "Cycle({cycle:?})"),
}
}
}
impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> { impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "MismatchedProjectionTypes({:?})", self.err) write!(f, "MismatchedProjectionTypes({:?})", self.err)

View File

@ -6,16 +6,15 @@ use rustc_infer::infer::InferCtxt;
use rustc_infer::traits::query::NoSolution; use rustc_infer::traits::query::NoSolution;
use rustc_infer::traits::solve::{CandidateSource, GoalSource, MaybeCause}; use rustc_infer::traits::solve::{CandidateSource, GoalSource, MaybeCause};
use rustc_infer::traits::{ use rustc_infer::traits::{
self, FromSolverError, FulfillmentErrorCode, FulfillmentErrorLike, MismatchedProjectionTypes, self, FromSolverError, FulfillmentErrorLike, MismatchedProjectionTypes, Obligation,
Obligation, ObligationCause, ObligationCauseCode, PredicateObligation, SelectionError, ObligationCause, ObligationCauseCode, PredicateObligation, SelectionError, TraitEngine,
TraitEngine,
}; };
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use crate::traits::{FulfillmentError, ScrubbedTraitError}; use crate::traits::{FulfillmentError, FulfillmentErrorCode, ScrubbedTraitError};
use super::eval_ctxt::GenerateProofTree; use super::eval_ctxt::GenerateProofTree;
use super::inspect::{self, ProofTreeInferCtxtExt, ProofTreeVisitor}; use super::inspect::{self, ProofTreeInferCtxtExt, ProofTreeVisitor};

View File

@ -32,6 +32,7 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt}; use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFolder, TypeSuperVisitable, Upcast}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFolder, TypeSuperVisitable, Upcast};
@ -70,7 +71,7 @@ pub use self::util::{with_replaced_escaping_bound_vars, BoundVarReplacer, Placeh
pub use rustc_infer::traits::*; pub use rustc_infer::traits::*;
/// A trait error without most of its information removed. This is the error /// A trait error with most of its information removed. This is the error
/// returned by an [`ObligationCtxt`] by default, and suitable if you just /// returned by an [`ObligationCtxt`] by default, and suitable if you just
/// want to see if a predicate holds, and don't particularly care about the /// want to see if a predicate holds, and don't particularly care about the
/// error itself (except for if it's an ambiguity or true error). /// error itself (except for if it's an ambiguity or true error).
@ -142,6 +143,43 @@ impl<'tcx> Debug for FulfillmentError<'tcx> {
} }
} }
#[derive(Clone)]
pub enum FulfillmentErrorCode<'tcx> {
/// Inherently impossible to fulfill; this trait is implemented if and only
/// if it is already implemented.
Cycle(Vec<PredicateObligation<'tcx>>),
Select(SelectionError<'tcx>),
Project(MismatchedProjectionTypes<'tcx>),
Subtype(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
ConstEquate(ExpectedFound<ty::Const<'tcx>>, TypeError<'tcx>),
Ambiguity {
/// Overflow is only `Some(suggest_recursion_limit)` when using the next generation
/// trait solver `-Znext-solver`. With the old solver overflow is eagerly handled by
/// emitting a fatal error instead.
overflow: Option<bool>,
},
}
impl<'tcx> Debug for FulfillmentErrorCode<'tcx> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
FulfillmentErrorCode::Select(ref e) => write!(f, "{e:?}"),
FulfillmentErrorCode::Project(ref e) => write!(f, "{e:?}"),
FulfillmentErrorCode::Subtype(ref a, ref b) => {
write!(f, "CodeSubtypeError({a:?}, {b:?})")
}
FulfillmentErrorCode::ConstEquate(ref a, ref b) => {
write!(f, "CodeConstEquateError({a:?}, {b:?})")
}
FulfillmentErrorCode::Ambiguity { overflow: None } => write!(f, "Ambiguity"),
FulfillmentErrorCode::Ambiguity { overflow: Some(suggest_increasing_limit) } => {
write!(f, "Overflow({suggest_increasing_limit})")
}
FulfillmentErrorCode::Cycle(ref cycle) => write!(f, "Cycle({cycle:?})"),
}
}
}
/// Whether to skip the leak check, as part of a future compatibility warning step. /// Whether to skip the leak check, as part of a future compatibility warning step.
/// ///
/// The "default" for skip-leak-check corresponds to the current /// The "default" for skip-leak-check corresponds to the current

View File

@ -4,13 +4,13 @@
// general routines. // general routines.
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::FulfillmentErrorCode;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::traits::CodegenObligationError; use rustc_middle::traits::CodegenObligationError;
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt; use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
use rustc_trait_selection::traits::{ use rustc_trait_selection::traits::{
ImplSource, Obligation, ObligationCause, ObligationCtxt, SelectionContext, Unimplemented, FulfillmentErrorCode, ImplSource, Obligation, ObligationCause, ObligationCtxt,
SelectionContext, Unimplemented,
}; };
use tracing::debug; use tracing::debug;