@@ -14,7 +14,8 @@ use region_constraints::{
1414GenericKind , RegionConstraintCollector , RegionConstraintStorage , VarInfos , VerifyBound ,
1515} ;
1616pub use relate:: StructurallyRelateAliases ;
17- pub use relate:: combine:: { CombineFields , PredicateEmittingRelation } ;
17+ use relate:: combine:: CombineFields ;
18+ pub use relate:: combine:: PredicateEmittingRelation ;
1819use rustc_data_structures:: captures:: Captures ;
1920use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap } ;
2021use rustc_data_structures:: sync:: Lrc ;
@@ -50,23 +51,22 @@ use snapshot::undo_log::InferCtxtUndoLogs;
5051use tracing:: { debug, instrument} ;
5152use type_variable:: TypeVariableOrigin ;
5253
53- use crate :: infer:: relate:: RelateResult ;
5454use crate :: traits:: { self , ObligationCause , ObligationInspector , PredicateObligation , TraitEngine } ;
5555
5656pub mod at;
5757pub mod canonical;
5858mod context;
59- pub mod free_regions;
59+ mod free_regions;
6060mod freshen;
6161mod lexical_region_resolve;
62- pub mod opaque_types;
62+ mod opaque_types;
6363pub mod outlives;
6464mod projection;
6565pub mod region_constraints;
6666pub mod relate;
6767pub mod resolve;
6868pub ( crate ) mod snapshot;
69- pub mod type_variable;
69+ mod type_variable;
7070
7171#[ must_use]
7272#[ derive( Debug ) ]
@@ -76,8 +76,7 @@ pub struct InferOk<'tcx, T> {
7676}
7777pub type InferResult < ' tcx , T > = Result < InferOk < ' tcx , T > , TypeError < ' tcx > > ;
7878
79- pub type UnitResult < ' tcx > = RelateResult < ' tcx , ( ) > ; // "unify result"
80- pub type FixupResult < T > = Result < T , FixupError > ; // "fixup result"
79+ pub ( crate ) type FixupResult < T > = Result < T , FixupError > ; // "fixup result"
8180
8281pub ( crate ) type UnificationTable < ' a , ' tcx , T > = ut:: UnificationTable <
8382 ut:: InPlace < T , & ' a mut ut:: UnificationStorage < T > , & ' a mut InferCtxtUndoLogs < ' tcx > > ,
@@ -202,7 +201,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
202201}
203202
204203#[ inline]
205- pub fn opaque_types ( & mut self ) -> opaque_types:: OpaqueTypeTable < ' _ , ' tcx > {
204+ fn opaque_types ( & mut self ) -> opaque_types:: OpaqueTypeTable < ' _ , ' tcx > {
206205self . opaque_type_storage . with_log ( & mut self . undo_log )
207206}
208207
@@ -280,27 +279,14 @@ pub struct InferCtxt<'tcx> {
280279pub reported_signature_mismatch : RefCell < FxHashSet < ( Span , Option < Span > ) > > ,
281280
282281/// When an error occurs, we want to avoid reporting "derived"
283- /// errors that are due to this original failure. Normally, we
284- /// handle this with the `err_count_on_creation` count, which
285- /// basically just tracks how many errors were reported when we
286- /// started type-checking a fn and checks to see if any new errors
287- /// have been reported since then. Not great, but it works.
288- ///
289- /// However, when errors originated in other passes -- notably
290- /// resolve -- this heuristic breaks down. Therefore, we have this
291- /// auxiliary flag that one can set whenever one creates a
292- /// type-error that is due to an error in a prior pass.
282+ /// errors that are due to this original failure. We have this
283+ /// flag that one can set whenever one creates a type-error that
284+ /// is due to an error in a prior pass.
293285///
294286/// Don't read this flag directly, call `is_tainted_by_errors()`
295287/// and `set_tainted_by_errors()`.
296288tainted_by_errors : Cell < Option < ErrorGuaranteed > > ,
297289
298- /// Track how many errors were reported when this infcx is created.
299- /// If the number of errors increases, that's also a sign (like
300- /// `tainted_by_errors`) to avoid reporting certain kinds of errors.
301- // FIXME(matthewjasper) Merge into `tainted_by_errors`
302- err_count_on_creation : usize ,
303-
304290/// What is the innermost universe we have created? Starts out as
305291/// `UniverseIndex::root()` but grows from there as we enter
306292/// universal quantifiers.
@@ -509,46 +495,41 @@ pub enum NllRegionVariableOrigin {
509495} ,
510496}
511497
512- // FIXME(eddyb) investigate overlap between this and `TyOrConstInferVar`.
513498#[ derive( Copy , Clone , Debug ) ]
514- pub enum FixupError {
515- UnresolvedIntTy ( IntVid ) ,
516- UnresolvedFloatTy ( FloatVid ) ,
517- UnresolvedTy ( TyVid ) ,
518- UnresolvedConst ( ConstVid ) ,
519- UnresolvedEffect ( EffectVid ) ,
520- }
521-
522- /// See the `region_obligations` field for more information.
523- #[ derive( Clone , Debug ) ]
524- pub struct RegionObligation < ' tcx > {
525- pub sub_region : ty:: Region < ' tcx > ,
526- pub sup_type : Ty < ' tcx > ,
527- pub origin : SubregionOrigin < ' tcx > ,
499+ pub struct FixupError {
500+ unresolved : TyOrConstInferVar ,
528501}
529502
530503impl fmt:: Display for FixupError {
531504fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
532- use self :: FixupError :: * ;
505+ use TyOrConstInferVar :: * ;
533506
534- match * self {
535- UnresolvedIntTy ( _) => write ! (
507+ match self . unresolved {
508+ TyInt ( _) => write ! (
536509 f,
537510"cannot determine the type of this integer; \
538511 add a suffix to specify the type explicitly"
539512) ,
540- UnresolvedFloatTy ( _) => write ! (
513+ TyFloat ( _) => write ! (
541514 f,
542515"cannot determine the type of this number; \
543516 add a suffix to specify the type explicitly"
544517) ,
545- UnresolvedTy ( _) => write ! ( f, "unconstrained type" ) ,
546- UnresolvedConst ( _) => write ! ( f, "unconstrained const value" ) ,
547- UnresolvedEffect ( _) => write ! ( f, "unconstrained effect value" ) ,
518+ Ty ( _) => write ! ( f, "unconstrained type" ) ,
519+ Const ( _) => write ! ( f, "unconstrained const value" ) ,
520+ Effect ( _) => write ! ( f, "unconstrained effect value" ) ,
548521}
549522}
550523}
551524
525+ /// See the `region_obligations` field for more information.
526+ #[ derive( Clone , Debug ) ]
527+ pub struct RegionObligation < ' tcx > {
528+ pub sub_region : ty:: Region < ' tcx > ,
529+ pub sup_type : Ty < ' tcx > ,
530+ pub origin : SubregionOrigin < ' tcx > ,
531+ }
532+
552533/// Used to configure inference contexts before their creation.
553534pub struct InferCtxtBuilder < ' tcx > {
554535tcx : TyCtxt < ' tcx > ,
@@ -588,14 +569,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
588569self
589570}
590571
591- pub fn with_defining_opaque_types (
592- mut self ,
593- defining_opaque_types : & ' tcx ty:: List < LocalDefId > ,
594- ) -> Self {
595- self . defining_opaque_types = defining_opaque_types;
596- self
597- }
598-
599572pub fn with_next_trait_solver ( mut self , next_trait_solver : bool ) -> Self {
600573self . next_trait_solver = next_trait_solver;
601574self
@@ -624,14 +597,15 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
624597/// the bound values in `C` to their instantiated values in `V`
625598/// (in other words, `S(C) = V`).
626599pub fn build_with_canonical < T > (
627- self ,
600+ mut self ,
628601span : Span ,
629602canonical : & Canonical < ' tcx , T > ,
630603) -> ( InferCtxt < ' tcx > , T , CanonicalVarValues < ' tcx > )
631604where
632605T : TypeFoldable < TyCtxt < ' tcx > > ,
633606{
634- let infcx = self . with_defining_opaque_types ( canonical. defining_opaque_types ) . build ( ) ;
607+ self . defining_opaque_types = canonical. defining_opaque_types ;
608+ let infcx = self . build ( ) ;
635609let ( value, args) = infcx. instantiate_canonical ( span, canonical) ;
636610( infcx, value, args)
637611}
@@ -657,7 +631,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
657631reported_trait_errors : Default :: default ( ) ,
658632reported_signature_mismatch : Default :: default ( ) ,
659633tainted_by_errors : Cell :: new ( None ) ,
660- err_count_on_creation : tcx. dcx ( ) . err_count_excluding_lint_errs ( ) ,
661634universe : Cell :: new ( ty:: UniverseIndex :: ROOT ) ,
662635 intercrate,
663636 next_trait_solver,
@@ -919,28 +892,16 @@ impl<'tcx> InferCtxt<'tcx> {
919892 ty:: Const :: new_var ( self . tcx , vid)
920893}
921894
922- pub fn next_const_var_id ( & self , origin : ConstVariableOrigin ) -> ConstVid {
923- self . inner
924- . borrow_mut ( )
925- . const_unification_table ( )
926- . new_key ( ConstVariableValue :: Unknown { origin, universe : self . universe ( ) } )
927- . vid
928- }
929-
930- fn next_int_var_id ( & self ) -> IntVid {
931- self . inner . borrow_mut ( ) . int_unification_table ( ) . new_key ( ty:: IntVarValue :: Unknown )
932- }
933-
934895pub fn next_int_var ( & self ) -> Ty < ' tcx > {
935- Ty :: new_int_var ( self . tcx , self . next_int_var_id ( ) )
936- }
937-
938- fn next_float_var_id ( & self ) -> FloatVid {
939- self . inner . borrow_mut ( ) . float_unification_table ( ) . new_key ( ty:: FloatVarValue :: Unknown )
896+ let next_int_var_id =
897+ self . inner . borrow_mut ( ) . int_unification_table ( ) . new_key ( ty:: IntVarValue :: Unknown ) ;
898+ Ty :: new_int_var ( self . tcx , next_int_var_id)
940899}
941900
942901pub fn next_float_var ( & self ) -> Ty < ' tcx > {
943- Ty :: new_float_var ( self . tcx , self . next_float_var_id ( ) )
902+ let next_float_var_id =
903+ self . inner . borrow_mut ( ) . float_unification_table ( ) . new_key ( ty:: FloatVarValue :: Unknown ) ;
904+ Ty :: new_float_var ( self . tcx , next_float_var_id)
944905}
945906
946907/// Creates a fresh region variable with the next available index.
@@ -1353,7 +1314,7 @@ impl<'tcx> InferCtxt<'tcx> {
13531314}
13541315
13551316/// See the [`region_constraints::RegionConstraintCollector::verify_generic_bound`] method.
1356- pub fn verify_generic_bound (
1317+ pub ( crate ) fn verify_generic_bound (
13571318& self ,
13581319origin : SubregionOrigin < ' tcx > ,
13591320kind : GenericKind < ' tcx > ,
0 commit comments