Make tcx.mk_const
more permissive wrt kind
argument
- Accept `impl Into` - Implement `From<>` for `ConstKind` Note: this adds a dependency on `derive_more` (MIT license). It allows to derive a lot of traits (like `From` here) that would be otherwise tedious to implement.
This commit is contained in:
parent
8a09420ac4
commit
e20e506f7d
4 changed files with 31 additions and 2 deletions
20
Cargo.lock
20
Cargo.lock
|
@ -870,6 +870,12 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "convert_case"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core"
|
name = "core"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
@ -1060,6 +1066,19 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_more"
|
||||||
|
version = "0.99.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
|
||||||
|
dependencies = [
|
||||||
|
"convert_case",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"rustc_version",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "diff"
|
name = "diff"
|
||||||
version = "0.1.13"
|
version = "0.1.13"
|
||||||
|
@ -3979,6 +3998,7 @@ version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"chalk-ir",
|
"chalk-ir",
|
||||||
|
"derive_more",
|
||||||
"either",
|
"either",
|
||||||
"gsgdt",
|
"gsgdt",
|
||||||
"polonius-engine",
|
"polonius-engine",
|
||||||
|
|
|
@ -8,6 +8,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
chalk-ir = "0.87.0"
|
chalk-ir = "0.87.0"
|
||||||
|
derive_more = "0.99.17"
|
||||||
either = "1.5.0"
|
either = "1.5.0"
|
||||||
gsgdt = "0.1.2"
|
gsgdt = "0.1.2"
|
||||||
polonius-engine = "0.13.0"
|
polonius-engine = "0.13.0"
|
||||||
|
|
|
@ -49,6 +49,7 @@ impl<'tcx> UnevaluatedConst<'tcx> {
|
||||||
/// Represents a constant in Rust.
|
/// Represents a constant in Rust.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)]
|
||||||
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable)]
|
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||||
|
#[derive(derive_more::From)]
|
||||||
pub enum ConstKind<'tcx> {
|
pub enum ConstKind<'tcx> {
|
||||||
/// A const generic parameter.
|
/// A const generic parameter.
|
||||||
Param(ty::ParamConst),
|
Param(ty::ParamConst),
|
||||||
|
@ -71,12 +72,19 @@ pub enum ConstKind<'tcx> {
|
||||||
|
|
||||||
/// A placeholder for a const which could not be computed; this is
|
/// A placeholder for a const which could not be computed; this is
|
||||||
/// propagated to avoid useless error messages.
|
/// propagated to avoid useless error messages.
|
||||||
|
#[from(ignore)]
|
||||||
Error(ErrorGuaranteed),
|
Error(ErrorGuaranteed),
|
||||||
|
|
||||||
/// Expr which contains an expression which has partially evaluated items.
|
/// Expr which contains an expression which has partially evaluated items.
|
||||||
Expr(Expr<'tcx>),
|
Expr(Expr<'tcx>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> From<ty::ConstVid<'tcx>> for ConstKind<'tcx> {
|
||||||
|
fn from(const_vid: ty::ConstVid<'tcx>) -> Self {
|
||||||
|
InferConst::Var(const_vid).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
||||||
#[derive(HashStable, TyEncodable, TyDecodable, TypeVisitable, TypeFoldable)]
|
#[derive(HashStable, TyEncodable, TyDecodable, TypeVisitable, TypeFoldable)]
|
||||||
pub enum Expr<'tcx> {
|
pub enum Expr<'tcx> {
|
||||||
|
|
|
@ -2598,8 +2598,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_const(self, kind: ty::ConstKind<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> {
|
pub fn mk_const(self, kind: impl Into<ty::ConstKind<'tcx>>, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
self.mk_const_internal(ty::ConstS { kind, ty })
|
self.mk_const_internal(ty::ConstS { kind: kind.into(), ty })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Reference in a new issue