Skip to content

Commit

Permalink
Merge pull request #502 from Areredify/phantom_data
Browse files Browse the repository at this point in the history
add phantom_data adt flag
  • Loading branch information
nikomatsakis authored Jun 9, 2020
2 parents 13aa9d3 + 17957d5 commit ed5b8a2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions chalk-integration/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ impl LowerAdtDefn for StructDefn {
let flags = rust_ir::AdtFlags {
upstream: self.flags.upstream,
fundamental: self.flags.fundamental,
phantom_data: self.flags.phantom_data,
};

Ok(rust_ir::AdtDatum {
Expand Down
1 change: 1 addition & 0 deletions chalk-parse/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct StructDefn {
pub struct StructFlags {
pub upstream: bool,
pub fundamental: bool,
pub phantom_data: bool,
}

#[derive(Clone, PartialEq, Eq, Debug)]
Expand Down
5 changes: 4 additions & 1 deletion chalk-parse/src/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ FundamentalKeyword: () = "#" "[" "fundamental" "]";
NonEnumerableKeyword: () = "#" "[" "non_enumerable" "]";
CoinductiveKeyword: () = "#" "[" "coinductive" "]";
ObjectSafeKeyword: () = "#" "[" "object_safe" "]";
PhantomDataKeyword: () = "#" "[" "phantom_data" "]";

WellKnownTrait: WellKnownTrait = {
"#" "[" "lang" "(" "sized" ")" "]" => WellKnownTrait::Sized,
Expand All @@ -57,7 +58,8 @@ WellKnownTrait: WellKnownTrait = {
};

StructDefn: StructDefn = {
<upstream:UpstreamKeyword?> <fundamental:FundamentalKeyword?> "struct" <n:Id><p:Angle<VariableKind>>
<upstream:UpstreamKeyword?> <fundamental:FundamentalKeyword?> <phantom_data:PhantomDataKeyword?>
"struct" <n:Id><p:Angle<VariableKind>>
<w:QuantifiedWhereClauses> "{" <f:Fields> "}" => StructDefn
{
name: n,
Expand All @@ -67,6 +69,7 @@ StructDefn: StructDefn = {
flags: StructFlags {
upstream: upstream.is_some(),
fundamental: fundamental.is_some(),
phantom_data: phantom_data.is_some(),
},
}
};
Expand Down
1 change: 1 addition & 0 deletions chalk-solve/src/rust_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub struct AdtDatumBound<I: Interner> {
pub struct AdtFlags {
pub upstream: bool,
pub fundamental: bool,
pub phantom_data: bool,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
Expand Down
10 changes: 10 additions & 0 deletions tests/lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,3 +686,13 @@ fn lifetime_outlives() {
}
}
}

#[test]
fn phantom_data() {
lowering_success! {
program {
#[phantom_data]
struct PhantomData<T> {}
}
}
}

0 comments on commit ed5b8a2

Please sign in to comment.