Skip to content

Commit 91e6e00

Browse files
committed
Add stable_mir::ty::GenericParamDefKind conversion
1 parent 3baa4be commit 91e6e00

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/formality-smir/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9+
formality-types = { path = "../formality-types" }

crates/formality-smir/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1+
#![feature(rustc_private)]
2+
3+
extern crate rustc_driver;
4+
extern crate rustc_smir;
5+
6+
use rustc_smir::stable_mir;
7+
18
/// Trait used to convert from Stable MIR to Formality types.
29
pub trait ToFormality {
310
/// The formality representation of the stable MIR type implementing ToFormality.
411
type T;
512
/// Converts an object to the equivalent Formality representation.
613
fn formality(&self) -> Self::T;
714
}
15+
16+
impl ToFormality for stable_mir::ty::GenericParamDefKind {
17+
type T = formality_types::derive_links::ParameterKind;
18+
19+
fn formality(&self) -> Self::T {
20+
use formality_types::derive_links::ParameterKind;
21+
22+
match self {
23+
stable_mir::ty::GenericParamDefKind::Lifetime => ParameterKind::Lt,
24+
stable_mir::ty::GenericParamDefKind::Type { .. } => ParameterKind::Ty,
25+
stable_mir::ty::GenericParamDefKind::Const { .. } => ParameterKind::Const,
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)