Skip to content

Commit 8841a3d

Browse files
committedOct 7, 2024
Auto merge of #131226 - nnethercote:rustc_infer-cleanups, r=lcnr
`rustc_infer` cleanups Various small improvements I found while reading over this code. r? `@lcnr`
2 parents a964a92 + 3fdcde7 commit 8841a3d

File tree

17 files changed

+90
-195
lines changed

17 files changed

+90
-195
lines changed
 

‎compiler/rustc_errors/src/lib.rs

-12
Original file line numberDiff line numberDiff line change
@@ -925,18 +925,6 @@ impl<'a> DiagCtxtHandle<'a> {
925925
self.inner.borrow_mut().emit_stashed_diagnostics()
926926
}
927927

928-
/// This excludes lint errors, and delayed bugs.
929-
#[inline]
930-
pub fn err_count_excluding_lint_errs(&self) -> usize {
931-
let inner = self.inner.borrow();
932-
inner.err_guars.len()
933-
+ inner
934-
.stashed_diagnostics
935-
.values()
936-
.filter(|(diag, guar)| guar.is_some() && diag.is_lint.is_none())
937-
.count()
938-
}
939-
940928
/// This excludes delayed bugs.
941929
#[inline]
942930
pub fn err_count(&self) -> usize {

‎compiler/rustc_infer/src/infer/at.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ impl<'tcx> InferCtxt<'tcx> {
8282
reported_trait_errors: self.reported_trait_errors.clone(),
8383
reported_signature_mismatch: self.reported_signature_mismatch.clone(),
8484
tainted_by_errors: self.tainted_by_errors.clone(),
85-
err_count_on_creation: self.err_count_on_creation,
8685
universe: self.universe.clone(),
8786
intercrate,
8887
next_trait_solver: self.next_trait_solver,
@@ -382,21 +381,7 @@ impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
382381
(GenericArgKind::Const(a), GenericArgKind::Const(b)) => {
383382
ValuePairs::Terms(ExpectedFound::new(true, a.into(), b.into()))
384383
}
385-
386-
(
387-
GenericArgKind::Lifetime(_),
388-
GenericArgKind::Type(_) | GenericArgKind::Const(_),
389-
)
390-
| (
391-
GenericArgKind::Type(_),
392-
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_),
393-
)
394-
| (
395-
GenericArgKind::Const(_),
396-
GenericArgKind::Lifetime(_) | GenericArgKind::Type(_),
397-
) => {
398-
bug!("relating different kinds: {a:?} {b:?}")
399-
}
384+
_ => bug!("relating different kinds: {a:?} {b:?}"),
400385
},
401386
}
402387
}

‎compiler/rustc_infer/src/infer/mod.rs

+37-76
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use region_constraints::{
1414
GenericKind, RegionConstraintCollector, RegionConstraintStorage, VarInfos, VerifyBound,
1515
};
1616
pub use relate::StructurallyRelateAliases;
17-
pub use relate::combine::{CombineFields, PredicateEmittingRelation};
17+
use relate::combine::CombineFields;
18+
pub use relate::combine::PredicateEmittingRelation;
1819
use rustc_data_structures::captures::Captures;
1920
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
2021
use rustc_data_structures::sync::Lrc;
@@ -50,23 +51,22 @@ use snapshot::undo_log::InferCtxtUndoLogs;
5051
use tracing::{debug, instrument};
5152
use type_variable::TypeVariableOrigin;
5253

53-
use crate::infer::relate::RelateResult;
5454
use crate::traits::{self, ObligationCause, ObligationInspector, PredicateObligation, TraitEngine};
5555

5656
pub mod at;
5757
pub mod canonical;
5858
mod context;
59-
pub mod free_regions;
59+
mod free_regions;
6060
mod freshen;
6161
mod lexical_region_resolve;
62-
pub mod opaque_types;
62+
mod opaque_types;
6363
pub mod outlives;
6464
mod projection;
6565
pub mod region_constraints;
6666
pub mod relate;
6767
pub mod resolve;
6868
pub(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
}
7777
pub 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

8281
pub(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> {
206205
self.opaque_type_storage.with_log(&mut self.undo_log)
207206
}
208207

@@ -280,27 +279,14 @@ pub struct InferCtxt<'tcx> {
280279
pub 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()`.
296288
tainted_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

530503
impl fmt::Display for FixupError {
531504
fn 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.
553534
pub struct InferCtxtBuilder<'tcx> {
554535
tcx: TyCtxt<'tcx>,
@@ -588,14 +569,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
588569
self
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-
599572
pub fn with_next_trait_solver(mut self, next_trait_solver: bool) -> Self {
600573
self.next_trait_solver = next_trait_solver;
601574
self
@@ -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`).
626599
pub fn build_with_canonical<T>(
627-
self,
600+
mut self,
628601
span: Span,
629602
canonical: &Canonical<'tcx, T>,
630603
) -> (InferCtxt<'tcx>, T, CanonicalVarValues<'tcx>)
631604
where
632605
T: 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();
635609
let (value, args) = infcx.instantiate_canonical(span, canonical);
636610
(infcx, value, args)
637611
}
@@ -657,7 +631,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
657631
reported_trait_errors: Default::default(),
658632
reported_signature_mismatch: Default::default(),
659633
tainted_by_errors: Cell::new(None),
660-
err_count_on_creation: tcx.dcx().err_count_excluding_lint_errs(),
661634
universe: 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-
934895
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)
940899
}
941900

942901
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)
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,
13581319
origin: SubregionOrigin<'tcx>,
13591320
kind: GenericKind<'tcx>,

‎compiler/rustc_infer/src/infer/opaque_types/mod.rs

+6-21
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ use rustc_middle::ty::{
1313
use rustc_span::Span;
1414
use tracing::{debug, instrument};
1515

16+
use super::DefineOpaqueTypes;
1617
use crate::errors::OpaqueHiddenTypeDiag;
1718
use crate::infer::{InferCtxt, InferOk};
1819
use crate::traits::{self, Obligation};
1920

2021
mod table;
2122

22-
pub type OpaqueTypeMap<'tcx> = FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
23-
pub use table::{OpaqueTypeStorage, OpaqueTypeTable};
24-
25-
use super::DefineOpaqueTypes;
23+
pub(crate) type OpaqueTypeMap<'tcx> = FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
24+
pub(crate) use table::{OpaqueTypeStorage, OpaqueTypeTable};
2625

2726
/// Information about the opaque types whose values we
2827
/// are inferring in this function (these are the `impl Trait` that
@@ -377,9 +376,9 @@ impl<'tcx> InferCtxt<'tcx> {
377376
///
378377
/// We ignore any type parameters because impl trait values are assumed to
379378
/// capture all the in-scope type parameters.
380-
pub struct ConstrainOpaqueTypeRegionVisitor<'tcx, OP: FnMut(ty::Region<'tcx>)> {
381-
pub tcx: TyCtxt<'tcx>,
382-
pub op: OP,
379+
struct ConstrainOpaqueTypeRegionVisitor<'tcx, OP: FnMut(ty::Region<'tcx>)> {
380+
tcx: TyCtxt<'tcx>,
381+
op: OP,
383382
}
384383

385384
impl<'tcx, OP> TypeVisitor<TyCtxt<'tcx>> for ConstrainOpaqueTypeRegionVisitor<'tcx, OP>
@@ -455,20 +454,6 @@ where
455454
}
456455
}
457456

458-
pub enum UseKind {
459-
DefiningUse,
460-
OpaqueUse,
461-
}
462-
463-
impl UseKind {
464-
pub fn is_defining(self) -> bool {
465-
match self {
466-
UseKind::DefiningUse => true,
467-
UseKind::OpaqueUse => false,
468-
}
469-
}
470-
}
471-
472457
impl<'tcx> InferCtxt<'tcx> {
473458
#[instrument(skip(self), level = "debug")]
474459
fn register_hidden_type(

‎compiler/rustc_infer/src/infer/opaque_types/table.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::{OpaqueTypeDecl, OpaqueTypeMap};
77
use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, UndoLog};
88

99
#[derive(Default, Debug, Clone)]
10-
pub struct OpaqueTypeStorage<'tcx> {
10+
pub(crate) struct OpaqueTypeStorage<'tcx> {
1111
/// Opaque types found in explicit return types and their
1212
/// associated fresh inference variable. Writeback resolves these
1313
/// variables to get the concrete type, which can be used to
@@ -46,7 +46,7 @@ impl<'tcx> Drop for OpaqueTypeStorage<'tcx> {
4646
}
4747
}
4848

49-
pub struct OpaqueTypeTable<'a, 'tcx> {
49+
pub(crate) struct OpaqueTypeTable<'a, 'tcx> {
5050
storage: &'a mut OpaqueTypeStorage<'tcx>,
5151

5252
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,

‎compiler/rustc_infer/src/infer/outlives/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub mod env;
1414
pub mod for_liveness;
1515
pub mod obligations;
1616
pub mod test_type_match;
17-
pub mod verify;
17+
pub(crate) mod verify;
1818

1919
#[instrument(level = "debug", skip(param_env), ret)]
2020
pub fn explicit_outlives_bounds<'tcx>(

‎compiler/rustc_infer/src/infer/outlives/verify.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::infer::{GenericKind, VerifyBound};
1515
/// via a "delegate" of type `D` -- this is usually the `infcx`, which
1616
/// accrues them into the `region_obligations` code, but for NLL we
1717
/// use something else.
18-
pub struct VerifyBoundCx<'cx, 'tcx> {
18+
pub(crate) struct VerifyBoundCx<'cx, 'tcx> {
1919
tcx: TyCtxt<'tcx>,
2020
region_bound_pairs: &'cx RegionBoundPairs<'tcx>,
2121
/// During borrowck, if there are no outlives bounds on a generic
@@ -28,7 +28,7 @@ pub struct VerifyBoundCx<'cx, 'tcx> {
2828
}
2929

3030
impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
31-
pub fn new(
31+
pub(crate) fn new(
3232
tcx: TyCtxt<'tcx>,
3333
region_bound_pairs: &'cx RegionBoundPairs<'tcx>,
3434
implicit_region_bound: Option<ty::Region<'tcx>>,
@@ -38,7 +38,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
3838
}
3939

4040
#[instrument(level = "debug", skip(self))]
41-
pub fn param_or_placeholder_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> {
41+
pub(crate) fn param_or_placeholder_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> {
4242
// Start with anything like `T: 'a` we can scrape from the
4343
// environment. If the environment contains something like
4444
// `for<'a> T: 'a`, then we know that `T` outlives everything.
@@ -92,7 +92,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
9292
/// the clause from the environment only applies if `'0 = 'a`,
9393
/// which we don't know yet. But we would still include `'b` in
9494
/// this list.
95-
pub fn approx_declared_bounds_from_env(
95+
pub(crate) fn approx_declared_bounds_from_env(
9696
&self,
9797
alias_ty: ty::AliasTy<'tcx>,
9898
) -> Vec<ty::PolyTypeOutlivesPredicate<'tcx>> {
@@ -101,7 +101,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
101101
}
102102

103103
#[instrument(level = "debug", skip(self))]
104-
pub fn alias_bound(&self, alias_ty: ty::AliasTy<'tcx>) -> VerifyBound<'tcx> {
104+
pub(crate) fn alias_bound(&self, alias_ty: ty::AliasTy<'tcx>) -> VerifyBound<'tcx> {
105105
let alias_ty_as_ty = alias_ty.to_ty(self.tcx);
106106

107107
// Search the env for where clauses like `P: 'a`.
@@ -285,7 +285,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
285285
///
286286
/// This is for simplicity, and because we are not really smart
287287
/// enough to cope with such bounds anywhere.
288-
pub fn declared_bounds_from_definition(
288+
pub(crate) fn declared_bounds_from_definition(
289289
&self,
290290
alias_ty: ty::AliasTy<'tcx>,
291291
) -> impl Iterator<Item = ty::Region<'tcx>> {

‎compiler/rustc_infer/src/infer/region_constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub struct RegionVariableInfo {
304304
pub universe: ty::UniverseIndex,
305305
}
306306

307-
pub struct RegionSnapshot {
307+
pub(crate) struct RegionSnapshot {
308308
any_unifications: bool,
309309
}
310310

‎compiler/rustc_infer/src/infer/relate/combine.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::infer::{DefineOpaqueTypes, InferCtxt, TypeTrace, relate};
3333
use crate::traits::{Obligation, PredicateObligation};
3434

3535
#[derive(Clone)]
36-
pub struct CombineFields<'infcx, 'tcx> {
36+
pub(crate) struct CombineFields<'infcx, 'tcx> {
3737
pub infcx: &'infcx InferCtxt<'tcx>,
3838
// Immutable fields
3939
pub trace: TypeTrace<'tcx>,
@@ -47,7 +47,7 @@ pub struct CombineFields<'infcx, 'tcx> {
4747
}
4848

4949
impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
50-
pub fn new(
50+
pub(crate) fn new(
5151
infcx: &'infcx InferCtxt<'tcx>,
5252
trace: TypeTrace<'tcx>,
5353
param_env: ty::ParamEnv<'tcx>,
@@ -283,22 +283,22 @@ impl<'tcx> InferCtxt<'tcx> {
283283
}
284284

285285
impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
286-
pub fn tcx(&self) -> TyCtxt<'tcx> {
286+
pub(crate) fn tcx(&self) -> TyCtxt<'tcx> {
287287
self.infcx.tcx
288288
}
289289

290-
pub fn equate<'a>(
290+
pub(crate) fn equate<'a>(
291291
&'a mut self,
292292
structurally_relate_aliases: StructurallyRelateAliases,
293293
) -> TypeRelating<'a, 'infcx, 'tcx> {
294294
TypeRelating::new(self, structurally_relate_aliases, ty::Invariant)
295295
}
296296

297-
pub fn sub<'a>(&'a mut self) -> TypeRelating<'a, 'infcx, 'tcx> {
297+
pub(crate) fn sub<'a>(&'a mut self) -> TypeRelating<'a, 'infcx, 'tcx> {
298298
TypeRelating::new(self, StructurallyRelateAliases::No, ty::Covariant)
299299
}
300300

301-
pub fn sup<'a>(&'a mut self) -> TypeRelating<'a, 'infcx, 'tcx> {
301+
pub(crate) fn sup<'a>(&'a mut self) -> TypeRelating<'a, 'infcx, 'tcx> {
302302
TypeRelating::new(self, StructurallyRelateAliases::No, ty::Contravariant)
303303
}
304304

@@ -310,14 +310,14 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
310310
LatticeOp::new(self, LatticeOpKind::Glb)
311311
}
312312

313-
pub fn register_obligations(
313+
pub(crate) fn register_obligations(
314314
&mut self,
315315
obligations: impl IntoIterator<Item = Goal<'tcx, ty::Predicate<'tcx>>>,
316316
) {
317317
self.goals.extend(obligations);
318318
}
319319

320-
pub fn register_predicates(
320+
pub(crate) fn register_predicates(
321321
&mut self,
322322
obligations: impl IntoIterator<Item: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
323323
) {

‎compiler/rustc_infer/src/infer/relate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
pub use rustc_middle::ty::relate::RelateResult;
66
pub use rustc_next_trait_solver::relate::*;
77

8-
pub use self::combine::{CombineFields, PredicateEmittingRelation};
8+
pub use self::combine::PredicateEmittingRelation;
99

1010
#[allow(hidden_glob_reexports)]
1111
pub(super) mod combine;

‎compiler/rustc_infer/src/infer/relate/type_relating.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::infer::relate::{PredicateEmittingRelation, StructurallyRelateAliases}
1313
use crate::infer::{DefineOpaqueTypes, InferCtxt, SubregionOrigin};
1414

1515
/// Enforce that `a` is equal to or a subtype of `b`.
16-
pub struct TypeRelating<'combine, 'a, 'tcx> {
16+
pub(crate) struct TypeRelating<'combine, 'a, 'tcx> {
1717
// Immutable except for the `InferCtxt` and the
1818
// resulting nested `goals`.
1919
fields: &'combine mut CombineFields<'a, 'tcx>,
@@ -49,7 +49,7 @@ pub struct TypeRelating<'combine, 'a, 'tcx> {
4949
}
5050

5151
impl<'combine, 'infcx, 'tcx> TypeRelating<'combine, 'infcx, 'tcx> {
52-
pub fn new(
52+
pub(crate) fn new(
5353
f: &'combine mut CombineFields<'infcx, 'tcx>,
5454
structurally_relate_aliases: StructurallyRelateAliases,
5555
ambient_variance: ty::Variance,

‎compiler/rustc_infer/src/infer/resolve.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ where
121121
value.try_fold_with(&mut FullTypeResolver { infcx })
122122
}
123123

124-
// N.B. This type is not public because the protocol around checking the
125-
// `err` field is not enforceable otherwise.
126124
struct FullTypeResolver<'a, 'tcx> {
127125
infcx: &'a InferCtxt<'tcx>,
128126
}
@@ -138,11 +136,13 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
138136
if !t.has_infer() {
139137
Ok(t) // micro-optimize -- if there is nothing in this type that this fold affects...
140138
} else {
139+
use super::TyOrConstInferVar::*;
140+
141141
let t = self.infcx.shallow_resolve(t);
142142
match *t.kind() {
143-
ty::Infer(ty::TyVar(vid)) => Err(FixupError::UnresolvedTy(vid)),
144-
ty::Infer(ty::IntVar(vid)) => Err(FixupError::UnresolvedIntTy(vid)),
145-
ty::Infer(ty::FloatVar(vid)) => Err(FixupError::UnresolvedFloatTy(vid)),
143+
ty::Infer(ty::TyVar(vid)) => Err(FixupError { unresolved: Ty(vid) }),
144+
ty::Infer(ty::IntVar(vid)) => Err(FixupError { unresolved: TyInt(vid) }),
145+
ty::Infer(ty::FloatVar(vid)) => Err(FixupError { unresolved: TyFloat(vid) }),
146146
ty::Infer(_) => {
147147
bug!("Unexpected type in full type resolver: {:?}", t);
148148
}
@@ -171,13 +171,13 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
171171
let c = self.infcx.shallow_resolve_const(c);
172172
match c.kind() {
173173
ty::ConstKind::Infer(InferConst::Var(vid)) => {
174-
return Err(FixupError::UnresolvedConst(vid));
174+
return Err(FixupError { unresolved: super::TyOrConstInferVar::Const(vid) });
175175
}
176176
ty::ConstKind::Infer(InferConst::Fresh(_)) => {
177177
bug!("Unexpected const in full const resolver: {:?}", c);
178178
}
179179
ty::ConstKind::Infer(InferConst::EffectVar(evid)) => {
180-
return Err(FixupError::UnresolvedEffect(evid));
180+
return Err(FixupError { unresolved: super::TyOrConstInferVar::Effect(evid) });
181181
}
182182
_ => {}
183183
}

‎compiler/rustc_infer/src/infer/snapshot/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tracing::{debug, instrument};
55
use super::InferCtxt;
66
use super::region_constraints::RegionSnapshot;
77

8-
mod fudge;
8+
pub(crate) mod fudge;
99
pub(crate) mod undo_log;
1010

1111
use undo_log::{Snapshot, UndoLog};

‎compiler/rustc_infer/src/infer/type_variable.rs

+16-29
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<'tcx> Rollback<sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>> for TypeVariabl
2020
}
2121

2222
#[derive(Clone)]
23-
pub struct TypeVariableStorage<'tcx> {
23+
pub(crate) struct TypeVariableStorage<'tcx> {
2424
/// The origins of each type variable.
2525
values: IndexVec<TyVid, TypeVariableData>,
2626
/// Two variables are unified in `eq_relations` when we have a
@@ -29,7 +29,7 @@ pub struct TypeVariableStorage<'tcx> {
2929
eq_relations: ut::UnificationTableStorage<TyVidEqKey<'tcx>>,
3030
}
3131

32-
pub struct TypeVariableTable<'a, 'tcx> {
32+
pub(crate) struct TypeVariableTable<'a, 'tcx> {
3333
storage: &'a mut TypeVariableStorage<'tcx>,
3434

3535
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
@@ -50,22 +50,22 @@ pub(crate) struct TypeVariableData {
5050
}
5151

5252
#[derive(Copy, Clone, Debug)]
53-
pub enum TypeVariableValue<'tcx> {
53+
pub(crate) enum TypeVariableValue<'tcx> {
5454
Known { value: Ty<'tcx> },
5555
Unknown { universe: ty::UniverseIndex },
5656
}
5757

5858
impl<'tcx> TypeVariableValue<'tcx> {
5959
/// If this value is known, returns the type it is known to be.
6060
/// Otherwise, `None`.
61-
pub fn known(&self) -> Option<Ty<'tcx>> {
61+
pub(crate) fn known(&self) -> Option<Ty<'tcx>> {
6262
match *self {
6363
TypeVariableValue::Unknown { .. } => None,
6464
TypeVariableValue::Known { value } => Some(value),
6565
}
6666
}
6767

68-
pub fn is_unknown(&self) -> bool {
68+
pub(crate) fn is_unknown(&self) -> bool {
6969
match *self {
7070
TypeVariableValue::Unknown { .. } => true,
7171
TypeVariableValue::Known { .. } => false,
@@ -74,7 +74,7 @@ impl<'tcx> TypeVariableValue<'tcx> {
7474
}
7575

7676
impl<'tcx> TypeVariableStorage<'tcx> {
77-
pub fn new() -> TypeVariableStorage<'tcx> {
77+
pub(crate) fn new() -> TypeVariableStorage<'tcx> {
7878
TypeVariableStorage {
7979
values: Default::default(),
8080
eq_relations: ut::UnificationTableStorage::new(),
@@ -105,14 +105,14 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
105105
///
106106
/// Note that this function does not return care whether
107107
/// `vid` has been unified with something else or not.
108-
pub fn var_origin(&self, vid: ty::TyVid) -> TypeVariableOrigin {
108+
pub(crate) fn var_origin(&self, vid: ty::TyVid) -> TypeVariableOrigin {
109109
self.storage.values[vid].origin
110110
}
111111

112112
/// Records that `a == b`, depending on `dir`.
113113
///
114114
/// Precondition: neither `a` nor `b` are known.
115-
pub fn equate(&mut self, a: ty::TyVid, b: ty::TyVid) {
115+
pub(crate) fn equate(&mut self, a: ty::TyVid, b: ty::TyVid) {
116116
debug_assert!(self.probe(a).is_unknown());
117117
debug_assert!(self.probe(b).is_unknown());
118118
self.eq_relations().union(a, b);
@@ -121,7 +121,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
121121
/// Instantiates `vid` with the type `ty`.
122122
///
123123
/// Precondition: `vid` must not have been previously instantiated.
124-
pub fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'tcx>) {
124+
pub(crate) fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'tcx>) {
125125
let vid = self.root_var(vid);
126126
debug_assert!(!ty.is_ty_var(), "instantiating ty var with var: {vid:?} {ty:?}");
127127
debug_assert!(self.probe(vid).is_unknown());
@@ -143,7 +143,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
143143
/// - `origin`: indicates *why* the type variable was created.
144144
/// The code in this module doesn't care, but it can be useful
145145
/// for improving error messages.
146-
pub fn new_var(
146+
pub(crate) fn new_var(
147147
&mut self,
148148
universe: ty::UniverseIndex,
149149
origin: TypeVariableOrigin,
@@ -158,7 +158,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
158158
}
159159

160160
/// Returns the number of type variables created thus far.
161-
pub fn num_vars(&self) -> usize {
161+
pub(crate) fn num_vars(&self) -> usize {
162162
self.storage.values.len()
163163
}
164164

@@ -167,42 +167,29 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
167167
/// will yield the same root variable (per the union-find
168168
/// algorithm), so `root_var(a) == root_var(b)` implies that `a ==
169169
/// b` (transitively).
170-
pub fn root_var(&mut self, vid: ty::TyVid) -> ty::TyVid {
170+
pub(crate) fn root_var(&mut self, vid: ty::TyVid) -> ty::TyVid {
171171
self.eq_relations().find(vid).vid
172172
}
173173

174174
/// Retrieves the type to which `vid` has been instantiated, if
175175
/// any.
176-
pub fn probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
176+
pub(crate) fn probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
177177
self.inlined_probe(vid)
178178
}
179179

180180
/// An always-inlined variant of `probe`, for very hot call sites.
181181
#[inline(always)]
182-
pub fn inlined_probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
182+
pub(crate) fn inlined_probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
183183
self.eq_relations().inlined_probe_value(vid)
184184
}
185185

186-
/// If `t` is a type-inference variable, and it has been
187-
/// instantiated, then return the with which it was
188-
/// instantiated. Otherwise, returns `t`.
189-
pub fn replace_if_possible(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
190-
match *t.kind() {
191-
ty::Infer(ty::TyVar(v)) => match self.probe(v) {
192-
TypeVariableValue::Unknown { .. } => t,
193-
TypeVariableValue::Known { value } => value,
194-
},
195-
_ => t,
196-
}
197-
}
198-
199186
#[inline]
200187
fn eq_relations(&mut self) -> super::UnificationTable<'_, 'tcx, TyVidEqKey<'tcx>> {
201188
self.storage.eq_relations.with_log(self.undo_log)
202189
}
203190

204191
/// Returns a range of the type variables created during the snapshot.
205-
pub fn vars_since_snapshot(
192+
pub(crate) fn vars_since_snapshot(
206193
&mut self,
207194
value_count: usize,
208195
) -> (Range<TyVid>, Vec<TypeVariableOrigin>) {
@@ -215,7 +202,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
215202

216203
/// Returns indices of all variables that are not yet
217204
/// instantiated.
218-
pub fn unresolved_variables(&mut self) -> Vec<ty::TyVid> {
205+
pub(crate) fn unresolved_variables(&mut self) -> Vec<ty::TyVid> {
219206
(0..self.num_vars())
220207
.filter_map(|i| {
221208
let vid = ty::TyVid::from_usize(i);

‎compiler/rustc_infer/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2020
#![doc(rust_logo)]
2121
#![feature(assert_matches)]
22-
#![feature(box_patterns)]
2322
#![feature(extend_one)]
24-
#![feature(if_let_guard)]
25-
#![feature(iter_intersperse)]
2623
#![feature(iterator_try_collect)]
2724
#![feature(let_chains)]
2825
#![feature(rustdoc_internals)]

‎compiler/rustc_middle/src/ty/relate.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,7 @@ impl<'tcx> Relate<TyCtxt<'tcx>> for ty::GenericArg<'tcx> {
212212
(ty::GenericArgKind::Const(a_ct), ty::GenericArgKind::Const(b_ct)) => {
213213
Ok(relation.relate(a_ct, b_ct)?.into())
214214
}
215-
(ty::GenericArgKind::Lifetime(unpacked), x) => {
216-
bug!("impossible case reached: can't relate: {:?} with {:?}", unpacked, x)
217-
}
218-
(ty::GenericArgKind::Type(unpacked), x) => {
219-
bug!("impossible case reached: can't relate: {:?} with {:?}", unpacked, x)
220-
}
221-
(ty::GenericArgKind::Const(unpacked), x) => {
222-
bug!("impossible case reached: can't relate: {:?} with {:?}", unpacked, x)
223-
}
215+
_ => bug!("impossible case reached: can't relate: {a:?} with {b:?}"),
224216
}
225217
}
226218
}

0 commit comments

Comments
 (0)
Please sign in to comment.