Skip to content

Commit

Permalink
Support Pointee trait
Browse files Browse the repository at this point in the history
  • Loading branch information
HKalbasi committed Apr 30, 2023
1 parent 8f06f99 commit d533079
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 22 deletions.
47 changes: 29 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions crates/hir-ty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ either = "1.7.0"
tracing = "0.1.35"
rustc-hash = "1.1.0"
scoped-tls = "1.0.0"
chalk-solve = { version = "0.89.0", default-features = false }
chalk-ir = "0.89.0"
chalk-recursive = { version = "0.89.0", default-features = false }
chalk-derive = "0.89.0"
chalk-solve = { version = "0.91.0", default-features = false }
chalk-ir = "0.91.0"
chalk-recursive = { version = "0.91.0", default-features = false }
chalk-derive = "0.91.0"
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
once_cell = "1.17.0"
typed-arena = "2.0.1"
Expand Down
2 changes: 2 additions & 0 deletions crates/hir-ty/src/chalk_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ fn well_known_trait_from_lang_item(item: LangItem) -> Option<WellKnownTrait> {
LangItem::Unpin => WellKnownTrait::Unpin,
LangItem::Unsize => WellKnownTrait::Unsize,
LangItem::Tuple => WellKnownTrait::Tuple,
LangItem::PointeeTrait => WellKnownTrait::Pointee,
_ => return None,
})
}
Expand All @@ -604,6 +605,7 @@ fn lang_item_from_well_known_trait(trait_: WellKnownTrait) -> LangItem {
WellKnownTrait::Tuple => LangItem::Tuple,
WellKnownTrait::Unpin => LangItem::Unpin,
WellKnownTrait::Unsize => LangItem::Unsize,
WellKnownTrait::Pointee => LangItem::PointeeTrait,
}
}

Expand Down
16 changes: 16 additions & 0 deletions crates/hir-ty/src/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3400,6 +3400,22 @@ fn func() {
);
}

#[test]
fn pointee_trait() {
check_types(
r#"
//- minicore: pointee
use core::ptr::Pointee;
fn func() {
let x: <u8 as Pointee>::Metadata;
//^ ()
let x: <[u8] as Pointee>::Metadata;
//^ usize
}
"#,
);
}

// FIXME
#[test]
fn castable_to() {
Expand Down
4 changes: 4 additions & 0 deletions crates/test-utils/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ impl MiniCore {
}
}

if !active_regions.is_empty() {
panic!("unclosed regions: {:?} Add an `endregion` comment", active_regions);
}

for flag in &self.valid_flags {
if !seen_regions.iter().any(|it| it == flag) {
panic!("unused minicore flag: {flag:?}");
Expand Down
11 changes: 11 additions & 0 deletions crates/test-utils/src/minicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
//! ord: eq, option
//! panic:
//! pin:
//! pointee:
//! range:
//! result:
//! send: sized
Expand Down Expand Up @@ -752,6 +753,16 @@ pub mod result {
}
// endregion:result

// region:pointee
pub mod ptr {
#[lang = "pointee_trait"]
pub trait Pointee {
#[lang = "metadata_type"]
type Metadata;
}
}
// endregion:pointee

// region:pin
pub mod pin {
#[lang = "pin"]
Expand Down

0 comments on commit d533079

Please sign in to comment.