Remove ConstVariableOriginKind

This commit is contained in:
Michael Goulet 2024-03-24 18:52:03 -04:00
parent 34bce07e8e
commit eb6f856169
10 changed files with 26 additions and 63 deletions

View file

@ -354,10 +354,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let ty::ConstKind::Infer(_) = ct.kind() {
self.next_const_var(
ct.ty(),
ConstVariableOrigin {
kind: ConstVariableOriginKind::MiscVariable,
span: DUMMY_SP,
},
ConstVariableOrigin { param_def_id: None, span: DUMMY_SP },
)
} else {
ct

View file

@ -17,7 +17,7 @@ use rustc_infer::infer;
use rustc_infer::infer::error_reporting::sub_relations::SubRelations;
use rustc_infer::infer::error_reporting::TypeErrCtxt;
use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
use rustc_middle::infer::unify_key::ConstVariableOrigin;
use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt};
use rustc_session::Session;
use rustc_span::symbol::Ident;
@ -255,10 +255,7 @@ impl<'a, 'tcx> HirTyLowerer<'tcx> for FnCtxt<'a, 'tcx> {
},
) => self.var_for_effect(param).as_const().unwrap(),
Some(param) => self.var_for_def(span, param).as_const().unwrap(),
None => self.next_const_var(
ty,
ConstVariableOrigin { kind: ConstVariableOriginKind::ConstInference, span },
),
None => self.next_const_var(ty, ConstVariableOrigin { span, param_def_id: None }),
}
}

View file

@ -23,7 +23,7 @@ use rustc_hir::PatKind::Binding;
use rustc_hir::PathSegment;
use rustc_hir::{ExprKind, Node, QPath};
use rustc_infer::infer::{self, type_variable::TypeVariableOrigin, RegionVariableOrigin};
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
use rustc_middle::infer::unify_key::ConstVariableOrigin;
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths};
@ -1859,7 +1859,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
arg.ty(),
ConstVariableOrigin {
span: rustc_span::DUMMY_SP,
kind: ConstVariableOriginKind::MiscVariable,
param_def_id: None,
},
)
.into(),

View file

@ -21,7 +21,7 @@
//!
//! [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html
use crate::infer::{ConstVariableOrigin, ConstVariableOriginKind};
use crate::infer::ConstVariableOrigin;
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin};
use rustc_index::IndexVec;
use rustc_middle::infer::unify_key::EffectVarValue;
@ -148,7 +148,7 @@ impl<'tcx> InferCtxt<'tcx> {
CanonicalVarKind::Const(ui, ty) => self
.next_const_var_in_universe(
ty,
ConstVariableOrigin { kind: ConstVariableOriginKind::MiscVariable, span },
ConstVariableOrigin { param_def_id: None, span },
universe_map(ui),
)
.into(),

View file

@ -13,9 +13,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource};
use rustc_middle::hir::nested_filter;
use rustc_middle::infer::unify_key::{
ConstVariableOrigin, ConstVariableOriginKind, ConstVariableValue,
};
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableValue};
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
use rustc_middle::ty::{
@ -217,8 +215,8 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
None
}
ConstVariableValue::Unknown { origin, universe: _ } => {
if let ConstVariableOriginKind::ConstParameterDefinition(name, _) = origin.kind {
return Some(name);
if let Some(def_id) = origin.param_def_id {
Some(infcx.tcx.item_name(def_id))
} else {
None
}
@ -341,11 +339,9 @@ impl<'tcx> InferCtxt<'tcx> {
}
ConstVariableValue::Unknown { origin, universe: _ } => origin,
};
if let ConstVariableOriginKind::ConstParameterDefinition(name, def_id) =
origin.kind
{
if let Some(def_id) = origin.param_def_id {
return InferenceDiagnosticsData {
name: name.to_string(),
name: self.tcx.item_name(def_id).to_string(),
span: Some(origin.span),
kind: UnderspecifiedArgKind::Const { is_parameter: true },
parent: InferenceDiagnosticsParentData::for_def_id(self.tcx, def_id),
@ -555,10 +551,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
GenericArgKind::Const(arg) => self
.next_const_var(
arg.ty(),
ConstVariableOrigin {
span: DUMMY_SP,
kind: ConstVariableOriginKind::MiscVariable,
},
ConstVariableOrigin { span: DUMMY_SP, param_def_id: None },
)
.into(),
}

View file

@ -30,7 +30,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
use rustc_middle::infer::unify_key::ConstVariableValue;
use rustc_middle::infer::unify_key::EffectVarValue;
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ToType};
use rustc_middle::infer::unify_key::{ConstVidKey, EffectVidKey};
use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult};
use rustc_middle::mir::ConstraintCategory;
@ -1120,13 +1120,7 @@ impl<'tcx> InferCtxt<'tcx> {
if is_host_effect {
return self.var_for_effect(param);
}
let origin = ConstVariableOrigin {
kind: ConstVariableOriginKind::ConstParameterDefinition(
param.name,
param.def_id,
),
span,
};
let origin = ConstVariableOrigin { param_def_id: Some(param.def_id), span };
let const_var_id = self
.inner
.borrow_mut()
@ -1417,10 +1411,7 @@ impl<'tcx> InferCtxt<'tcx> {
self.infcx
.next_const_var(
ty,
ConstVariableOrigin {
kind: ConstVariableOriginKind::MiscVariable,
span: self.span,
},
ConstVariableOrigin { param_def_id: None, span: self.span },
)
.into()
})

View file

@ -1,4 +1,4 @@
use rustc_middle::infer::unify_key::{ConstVariableOriginKind, ConstVariableValue, ConstVidKey};
use rustc_middle::infer::unify_key::{ConstVariableValue, ConstVidKey};
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
use rustc_middle::ty::{self, ConstVid, FloatVid, IntVid, RegionVid, Ty, TyCtxt, TyVid};
@ -33,10 +33,9 @@ fn const_vars_since_snapshot<'tcx>(
range.start.vid..range.end.vid,
(range.start.index()..range.end.index())
.map(|index| match table.probe_value(ConstVid::from_u32(index)) {
ConstVariableValue::Known { value: _ } => ConstVariableOrigin {
kind: ConstVariableOriginKind::MiscVariable,
span: rustc_span::DUMMY_SP,
},
ConstVariableValue::Known { value: _ } => {
ConstVariableOrigin { param_def_id: None, span: rustc_span::DUMMY_SP }
}
ConstVariableValue::Unknown { origin, universe: _ } => origin,
})
.collect(),

View file

@ -1,7 +1,6 @@
use crate::ty::{self, Ty, TyCtxt};
use rustc_data_structures::unify::{NoError, UnifyKey, UnifyValue};
use rustc_span::def_id::DefId;
use rustc_span::symbol::Symbol;
use rustc_span::Span;
use std::cmp;
use std::marker::PhantomData;
@ -106,16 +105,9 @@ impl ToType for ty::FloatVarValue {
#[derive(Copy, Clone, Debug)]
pub struct ConstVariableOrigin {
pub kind: ConstVariableOriginKind,
pub span: Span,
}
/// Reasons to create a const inference variable
#[derive(Copy, Clone, Debug)]
pub enum ConstVariableOriginKind {
MiscVariable,
ConstInference,
ConstParameterDefinition(Symbol, DefId),
// `DefId` of the const parameter this was instantiated for, if any.
pub param_def_id: Option<DefId>,
}
#[derive(Copy, Clone, Debug)]

View file

@ -10,7 +10,7 @@ use rustc_infer::traits::query::NoSolution;
use rustc_infer::traits::solve::{MaybeCause, NestedNormalizationGoals};
use rustc_infer::traits::ObligationCause;
use rustc_middle::infer::canonical::CanonicalVarInfos;
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
use rustc_middle::infer::unify_key::ConstVariableOrigin;
use rustc_middle::traits::solve::inspect;
use rustc_middle::traits::solve::{
CanonicalInput, CanonicalResponse, Certainty, PredefinedOpaques, PredefinedOpaquesData,
@ -591,10 +591,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
}
pub(super) fn next_const_infer(&self, ty: Ty<'tcx>) -> ty::Const<'tcx> {
self.infcx.next_const_var(
ty,
ConstVariableOrigin { kind: ConstVariableOriginKind::MiscVariable, span: DUMMY_SP },
)
self.infcx.next_const_var(ty, ConstVariableOrigin { param_def_id: None, span: DUMMY_SP })
}
/// Returns a ty infer or a const infer depending on whether `kind` is a `Ty` or `Const`.

View file

@ -7,7 +7,7 @@ use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_infer::infer::InferCtxt;
use rustc_infer::traits::TraitEngineExt;
use rustc_infer::traits::{FulfillmentError, Obligation, TraitEngine};
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
use rustc_middle::infer::unify_key::ConstVariableOrigin;
use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::{self, AliasTy, Ty, TyCtxt, UniverseIndex};
use rustc_middle::ty::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable};
@ -122,10 +122,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
let new_infer_ct = infcx.next_const_var(
ty,
ConstVariableOrigin {
kind: ConstVariableOriginKind::MiscVariable,
span: self.at.cause.span,
},
ConstVariableOrigin { param_def_id: None, span: self.at.cause.span },
);
let obligation = Obligation::new(
tcx,