@@ -14,7 +14,8 @@ use region_constraints::{
14
14
GenericKind, RegionConstraintCollector, RegionConstraintStorage, VarInfos, VerifyBound,
15
15
};
16
16
pub use relate::StructurallyRelateAliases;
17
- pub use relate::combine::{CombineFields, PredicateEmittingRelation};
17
+ use relate::combine::CombineFields;
18
+ pub use relate::combine::PredicateEmittingRelation;
18
19
use rustc_data_structures::captures::Captures;
19
20
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
20
21
use rustc_data_structures::sync::Lrc;
@@ -50,23 +51,22 @@ use snapshot::undo_log::InferCtxtUndoLogs;
50
51
use tracing::{debug, instrument};
51
52
use type_variable::TypeVariableOrigin;
52
53
53
- use crate::infer::relate::RelateResult;
54
54
use crate::traits::{self, ObligationCause, ObligationInspector, PredicateObligation, TraitEngine};
55
55
56
56
pub mod at;
57
57
pub mod canonical;
58
58
mod context;
59
- pub mod free_regions;
59
+ mod free_regions;
60
60
mod freshen;
61
61
mod lexical_region_resolve;
62
- pub mod opaque_types;
62
+ mod opaque_types;
63
63
pub mod outlives;
64
64
mod projection;
65
65
pub mod region_constraints;
66
66
pub mod relate;
67
67
pub mod resolve;
68
68
pub(crate) mod snapshot;
69
- pub mod type_variable;
69
+ mod type_variable;
70
70
71
71
#[must_use]
72
72
#[derive(Debug)]
@@ -76,8 +76,7 @@ pub struct InferOk<'tcx, T> {
76
76
}
77
77
pub type InferResult<'tcx, T> = Result<InferOk<'tcx, T>, TypeError<'tcx>>;
78
78
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"
81
80
82
81
pub(crate) type UnificationTable<'a, 'tcx, T> = ut::UnificationTable<
83
82
ut::InPlace<T, &'a mut ut::UnificationStorage<T>, &'a mut InferCtxtUndoLogs<'tcx>>,
@@ -202,7 +201,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
202
201
}
203
202
204
203
#[inline]
205
- pub fn opaque_types(&mut self) -> opaque_types::OpaqueTypeTable<'_, 'tcx> {
204
+ fn opaque_types(&mut self) -> opaque_types::OpaqueTypeTable<'_, 'tcx> {
206
205
self.opaque_type_storage.with_log(&mut self.undo_log)
207
206
}
208
207
@@ -280,27 +279,14 @@ pub struct InferCtxt<'tcx> {
280
279
pub reported_signature_mismatch: RefCell<FxHashSet<(Span, Option<Span>)>>,
281
280
282
281
/// 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.
293
285
///
294
286
/// Don't read this flag directly, call `is_tainted_by_errors()`
295
287
/// and `set_tainted_by_errors()`.
296
288
tainted_by_errors: Cell<Option<ErrorGuaranteed>>,
297
289
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
-
304
290
/// What is the innermost universe we have created? Starts out as
305
291
/// `UniverseIndex::root()` but grows from there as we enter
306
292
/// universal quantifiers.
@@ -509,46 +495,41 @@ pub enum NllRegionVariableOrigin {
509
495
},
510
496
}
511
497
512
- // FIXME(eddyb) investigate overlap between this and `TyOrConstInferVar`.
513
498
#[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,
528
501
}
529
502
530
503
impl fmt::Display for FixupError {
531
504
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
532
- use self::FixupError ::*;
505
+ use TyOrConstInferVar ::*;
533
506
534
- match * self {
535
- UnresolvedIntTy (_) => write!(
507
+ match self.unresolved {
508
+ TyInt (_) => write!(
536
509
f,
537
510
"cannot determine the type of this integer; \
538
511
add a suffix to specify the type explicitly"
539
512
),
540
- UnresolvedFloatTy (_) => write!(
513
+ TyFloat (_) => write!(
541
514
f,
542
515
"cannot determine the type of this number; \
543
516
add a suffix to specify the type explicitly"
544
517
),
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"),
548
521
}
549
522
}
550
523
}
551
524
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
+
552
533
/// Used to configure inference contexts before their creation.
553
534
pub struct InferCtxtBuilder<'tcx> {
554
535
tcx: TyCtxt<'tcx>,
@@ -588,14 +569,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
588
569
self
589
570
}
590
571
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
-
599
572
pub fn with_next_trait_solver(mut self, next_trait_solver: bool) -> Self {
600
573
self.next_trait_solver = next_trait_solver;
601
574
self
@@ -624,14 +597,15 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
624
597
/// the bound values in `C` to their instantiated values in `V`
625
598
/// (in other words, `S(C) = V`).
626
599
pub fn build_with_canonical<T>(
627
- self,
600
+ mut self,
628
601
span: Span,
629
602
canonical: &Canonical<'tcx, T>,
630
603
) -> (InferCtxt<'tcx>, T, CanonicalVarValues<'tcx>)
631
604
where
632
605
T: TypeFoldable<TyCtxt<'tcx>>,
633
606
{
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();
635
609
let (value, args) = infcx.instantiate_canonical(span, canonical);
636
610
(infcx, value, args)
637
611
}
@@ -657,7 +631,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
657
631
reported_trait_errors: Default::default(),
658
632
reported_signature_mismatch: Default::default(),
659
633
tainted_by_errors: Cell::new(None),
660
- err_count_on_creation: tcx.dcx().err_count_excluding_lint_errs(),
661
634
universe: Cell::new(ty::UniverseIndex::ROOT),
662
635
intercrate,
663
636
next_trait_solver,
@@ -919,28 +892,16 @@ impl<'tcx> InferCtxt<'tcx> {
919
892
ty::Const::new_var(self.tcx, vid)
920
893
}
921
894
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
-
934
895
pub 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)
940
899
}
941
900
942
901
pub 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)
944
905
}
945
906
946
907
/// Creates a fresh region variable with the next available index.
@@ -1353,7 +1314,7 @@ impl<'tcx> InferCtxt<'tcx> {
1353
1314
}
1354
1315
1355
1316
/// See the [`region_constraints::RegionConstraintCollector::verify_generic_bound`] method.
1356
- pub fn verify_generic_bound(
1317
+ pub(crate) fn verify_generic_bound(
1357
1318
&self,
1358
1319
origin: SubregionOrigin<'tcx>,
1359
1320
kind: GenericKind<'tcx>,
0 commit comments