Skip to content

Commit 0ca4784

Browse files
committed
Fix FIXME comment on FixupError.
`FixupError` is isomorphic with `TyOrConstInferVar`, so this commit changes it to just be a wrapper around `TyOrConstInferVar`. Also, move the `Display` impl for `FixupError` next to `FixupError`.
1 parent 25d1ef1 commit 0ca4784

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

compiler/rustc_infer/src/infer/mod.rs

+17-22
Original file line numberDiff line numberDiff line change
@@ -495,46 +495,41 @@ pub enum NllRegionVariableOrigin {
495495
},
496496
}
497497

498-
// FIXME(eddyb) investigate overlap between this and `TyOrConstInferVar`.
499498
#[derive(Copy, Clone, Debug)]
500-
pub enum FixupError {
501-
UnresolvedIntTy(IntVid),
502-
UnresolvedFloatTy(FloatVid),
503-
UnresolvedTy(TyVid),
504-
UnresolvedConst(ConstVid),
505-
UnresolvedEffect(EffectVid),
506-
}
507-
508-
/// See the `region_obligations` field for more information.
509-
#[derive(Clone, Debug)]
510-
pub struct RegionObligation<'tcx> {
511-
pub sub_region: ty::Region<'tcx>,
512-
pub sup_type: Ty<'tcx>,
513-
pub origin: SubregionOrigin<'tcx>,
499+
pub struct FixupError {
500+
unresolved: TyOrConstInferVar,
514501
}
515502

516503
impl fmt::Display for FixupError {
517504
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
518-
use self::FixupError::*;
505+
use TyOrConstInferVar::*;
519506

520-
match *self {
521-
UnresolvedIntTy(_) => write!(
507+
match self.unresolved {
508+
TyInt(_) => write!(
522509
f,
523510
"cannot determine the type of this integer; \
524511
add a suffix to specify the type explicitly"
525512
),
526-
UnresolvedFloatTy(_) => write!(
513+
TyFloat(_) => write!(
527514
f,
528515
"cannot determine the type of this number; \
529516
add a suffix to specify the type explicitly"
530517
),
531-
UnresolvedTy(_) => write!(f, "unconstrained type"),
532-
UnresolvedConst(_) => write!(f, "unconstrained const value"),
533-
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"),
534521
}
535522
}
536523
}
537524

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+
538533
/// Used to configure inference contexts before their creation.
539534
pub struct InferCtxtBuilder<'tcx> {
540535
tcx: TyCtxt<'tcx>,

compiler/rustc_infer/src/infer/resolve.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
138138
if !t.has_infer() {
139139
Ok(t) // micro-optimize -- if there is nothing in this type that this fold affects...
140140
} else {
141+
use super::TyOrConstInferVar::*;
142+
141143
let t = self.infcx.shallow_resolve(t);
142144
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)),
145+
ty::Infer(ty::TyVar(vid)) => Err(FixupError { unresolved: Ty(vid) }),
146+
ty::Infer(ty::IntVar(vid)) => Err(FixupError { unresolved: TyInt(vid) }),
147+
ty::Infer(ty::FloatVar(vid)) => Err(FixupError { unresolved: TyFloat(vid) }),
146148
ty::Infer(_) => {
147149
bug!("Unexpected type in full type resolver: {:?}", t);
148150
}
@@ -171,13 +173,13 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
171173
let c = self.infcx.shallow_resolve_const(c);
172174
match c.kind() {
173175
ty::ConstKind::Infer(InferConst::Var(vid)) => {
174-
return Err(FixupError::UnresolvedConst(vid));
176+
return Err(FixupError { unresolved: super::TyOrConstInferVar::Const(vid) });
175177
}
176178
ty::ConstKind::Infer(InferConst::Fresh(_)) => {
177179
bug!("Unexpected const in full const resolver: {:?}", c);
178180
}
179181
ty::ConstKind::Infer(InferConst::EffectVar(evid)) => {
180-
return Err(FixupError::UnresolvedEffect(evid));
182+
return Err(FixupError { unresolved: super::TyOrConstInferVar::Effect(evid) });
181183
}
182184
_ => {}
183185
}

0 commit comments

Comments
 (0)