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`.
This commit is contained in:
Nicholas Nethercote 2024-10-01 17:58:49 +10:00
parent 25d1ef1993
commit 0ca4784c45
2 changed files with 31 additions and 34 deletions

View File

@ -495,14 +495,31 @@ pub enum NllRegionVariableOrigin {
},
}
// FIXME(eddyb) investigate overlap between this and `TyOrConstInferVar`.
#[derive(Copy, Clone, Debug)]
pub enum FixupError {
UnresolvedIntTy(IntVid),
UnresolvedFloatTy(FloatVid),
UnresolvedTy(TyVid),
UnresolvedConst(ConstVid),
UnresolvedEffect(EffectVid),
pub struct FixupError {
unresolved: TyOrConstInferVar,
}
impl fmt::Display for FixupError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use TyOrConstInferVar::*;
match self.unresolved {
TyInt(_) => write!(
f,
"cannot determine the type of this integer; \
add a suffix to specify the type explicitly"
),
TyFloat(_) => write!(
f,
"cannot determine the type of this number; \
add a suffix to specify the type explicitly"
),
Ty(_) => write!(f, "unconstrained type"),
Const(_) => write!(f, "unconstrained const value"),
Effect(_) => write!(f, "unconstrained effect value"),
}
}
}
/// See the `region_obligations` field for more information.
@ -513,28 +530,6 @@ pub struct RegionObligation<'tcx> {
pub origin: SubregionOrigin<'tcx>,
}
impl fmt::Display for FixupError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use self::FixupError::*;
match *self {
UnresolvedIntTy(_) => write!(
f,
"cannot determine the type of this integer; \
add a suffix to specify the type explicitly"
),
UnresolvedFloatTy(_) => write!(
f,
"cannot determine the type of this number; \
add a suffix to specify the type explicitly"
),
UnresolvedTy(_) => write!(f, "unconstrained type"),
UnresolvedConst(_) => write!(f, "unconstrained const value"),
UnresolvedEffect(_) => write!(f, "unconstrained effect value"),
}
}
}
/// Used to configure inference contexts before their creation.
pub struct InferCtxtBuilder<'tcx> {
tcx: TyCtxt<'tcx>,

View File

@ -138,11 +138,13 @@ fn try_fold_ty(&mut self, t: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
if !t.has_infer() {
Ok(t) // micro-optimize -- if there is nothing in this type that this fold affects...
} else {
use super::TyOrConstInferVar::*;
let t = self.infcx.shallow_resolve(t);
match *t.kind() {
ty::Infer(ty::TyVar(vid)) => Err(FixupError::UnresolvedTy(vid)),
ty::Infer(ty::IntVar(vid)) => Err(FixupError::UnresolvedIntTy(vid)),
ty::Infer(ty::FloatVar(vid)) => Err(FixupError::UnresolvedFloatTy(vid)),
ty::Infer(ty::TyVar(vid)) => Err(FixupError { unresolved: Ty(vid) }),
ty::Infer(ty::IntVar(vid)) => Err(FixupError { unresolved: TyInt(vid) }),
ty::Infer(ty::FloatVar(vid)) => Err(FixupError { unresolved: TyFloat(vid) }),
ty::Infer(_) => {
bug!("Unexpected type in full type resolver: {:?}", t);
}
@ -171,13 +173,13 @@ fn try_fold_const(&mut self, c: ty::Const<'tcx>) -> Result<ty::Const<'tcx>, Self
let c = self.infcx.shallow_resolve_const(c);
match c.kind() {
ty::ConstKind::Infer(InferConst::Var(vid)) => {
return Err(FixupError::UnresolvedConst(vid));
return Err(FixupError { unresolved: super::TyOrConstInferVar::Const(vid) });
}
ty::ConstKind::Infer(InferConst::Fresh(_)) => {
bug!("Unexpected const in full const resolver: {:?}", c);
}
ty::ConstKind::Infer(InferConst::EffectVar(evid)) => {
return Err(FixupError::UnresolvedEffect(evid));
return Err(FixupError { unresolved: super::TyOrConstInferVar::Effect(evid) });
}
_ => {}
}