From 17957d5190eb4b9a87c4ccb1cf68ef48c9c05893 Mon Sep 17 00:00:00 2001 From: Mikhail Babenko Date: Tue, 9 Jun 2020 13:21:23 +0300 Subject: [PATCH] add phantom_data adt flag --- chalk-integration/src/lowering.rs | 1 + chalk-parse/src/ast.rs | 1 + chalk-parse/src/parser.lalrpop | 5 ++++- chalk-solve/src/rust_ir.rs | 1 + tests/lowering/mod.rs | 10 ++++++++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/chalk-integration/src/lowering.rs b/chalk-integration/src/lowering.rs index 424bdd9f3ea..f470c40b0ca 100644 --- a/chalk-integration/src/lowering.rs +++ b/chalk-integration/src/lowering.rs @@ -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 { diff --git a/chalk-parse/src/ast.rs b/chalk-parse/src/ast.rs index c806b7a1f1e..f1d06c7c053 100644 --- a/chalk-parse/src/ast.rs +++ b/chalk-parse/src/ast.rs @@ -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)] diff --git a/chalk-parse/src/parser.lalrpop b/chalk-parse/src/parser.lalrpop index 944f4733261..ea052d591b3 100644 --- a/chalk-parse/src/parser.lalrpop +++ b/chalk-parse/src/parser.lalrpop @@ -45,6 +45,7 @@ FundamentalKeyword: () = "#" "[" "fundamental" "]"; NonEnumerableKeyword: () = "#" "[" "non_enumerable" "]"; CoinductiveKeyword: () = "#" "[" "coinductive" "]"; ObjectSafeKeyword: () = "#" "[" "object_safe" "]"; +PhantomDataKeyword: () = "#" "[" "phantom_data" "]"; WellKnownTrait: WellKnownTrait = { "#" "[" "lang" "(" "sized" ")" "]" => WellKnownTrait::Sized, @@ -54,7 +55,8 @@ WellKnownTrait: WellKnownTrait = { }; StructDefn: StructDefn = { - "struct" > + + "struct" > "{" "}" => StructDefn { name: n, @@ -64,6 +66,7 @@ StructDefn: StructDefn = { flags: StructFlags { upstream: upstream.is_some(), fundamental: fundamental.is_some(), + phantom_data: phantom_data.is_some(), }, } }; diff --git a/chalk-solve/src/rust_ir.rs b/chalk-solve/src/rust_ir.rs index d0c57919e52..5821b7c3560 100644 --- a/chalk-solve/src/rust_ir.rs +++ b/chalk-solve/src/rust_ir.rs @@ -101,6 +101,7 @@ pub struct AdtDatumBound { pub struct AdtFlags { pub upstream: bool, pub fundamental: bool, + pub phantom_data: bool, } #[derive(Clone, Debug, PartialEq, Eq, Hash)] diff --git a/tests/lowering/mod.rs b/tests/lowering/mod.rs index 408fa851453..a903625a4ff 100644 --- a/tests/lowering/mod.rs +++ b/tests/lowering/mod.rs @@ -686,3 +686,13 @@ fn lifetime_outlives() { } } } + +#[test] +fn phantom_data() { + lowering_success! { + program { + #[phantom_data] + struct PhantomData {} + } + } +}