Skip to content

Commit de3ae31

Browse files
committed
add parsing for well known trait Sized
1 parent bdd8992 commit de3ae31

File tree

6 files changed

+28
-3
lines changed

6 files changed

+28
-3
lines changed

chalk-integration/src/lowering.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ impl LowerTrait for TraitDefn {
12411241
binders: binders,
12421242
flags: self.flags.lower(),
12431243
associated_ty_ids,
1244-
well_known: None,
1244+
well_known: self.well_known.as_ref().map(|t| t.lower()),
12451245
})
12461246
}
12471247
}
@@ -1343,6 +1343,18 @@ impl LowerQuantifiedGoal for Goal {
13431343
}
13441344
}
13451345

1346+
trait LowerWellKnownTrait {
1347+
fn lower(&self) -> rust_ir::WellKnownTrait;
1348+
}
1349+
1350+
impl LowerWellKnownTrait for WellKnownTrait {
1351+
fn lower(&self) -> rust_ir::WellKnownTrait {
1352+
match self {
1353+
Self::SizedTrait => rust_ir::WellKnownTrait::SizedTrait,
1354+
}
1355+
}
1356+
}
1357+
13461358
/// Lowers LowerResult<Vec<T>> -> Vec<LowerResult<T>>.
13471359
trait ApplyResult {
13481360
type Output;

chalk-parse/src/ast.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ pub struct TraitDefn {
4848
pub where_clauses: Vec<QuantifiedWhereClause>,
4949
pub assoc_ty_defns: Vec<AssocTyDefn>,
5050
pub flags: TraitFlags,
51+
pub well_known: Option<WellKnownTrait>,
52+
}
53+
54+
#[derive(Clone, PartialEq, Eq, Debug)]
55+
pub enum WellKnownTrait {
56+
SizedTrait,
5157
}
5258

5359
#[derive(Clone, PartialEq, Eq, Debug)]

chalk-parse/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![recursion_limit = "1024"]
2+
#![allow(unused_parens)]
23

34
#[macro_use]
45
extern crate lalrpop_util;

chalk-parse/src/parser.lalrpop

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ FundamentalKeyword: () = "#" "[" "fundamental" "]";
4343
NonEnumerableKeyword: () = "#" "[" "non_enumerable" "]";
4444
CoinductiveKeyword: () = "#" "[" "coinductive" "]";
4545

46+
WellKnownTrait: WellKnownTrait = {
47+
"#" "[" "lang" "(" "sized" ")" "]" => WellKnownTrait::SizedTrait,
48+
};
49+
4650
StructDefn: StructDefn = {
4751
<upstream:UpstreamKeyword?> <fundamental:FundamentalKeyword?> "struct" <n:Id><p:Angle<ParameterKind>>
4852
<w:QuantifiedWhereClauses> "{" <f:Fields> "}" => StructDefn
@@ -59,13 +63,14 @@ StructDefn: StructDefn = {
5963
};
6064

6165
TraitDefn: TraitDefn = {
62-
<auto:AutoKeyword?> <marker:MarkerKeyword?> <upstream:UpstreamKeyword?> <fundamental:FundamentalKeyword?> <non_enumerable:NonEnumerableKeyword?> <coinductive:CoinductiveKeyword?> "trait" <n:Id><p:Angle<ParameterKind>>
66+
<auto:AutoKeyword?> <marker:MarkerKeyword?> <upstream:UpstreamKeyword?> <fundamental:FundamentalKeyword?> <non_enumerable:NonEnumerableKeyword?> <coinductive:CoinductiveKeyword?> <well_known:WellKnownTrait?> "trait" <n:Id><p:Angle<ParameterKind>>
6367
<w:QuantifiedWhereClauses> "{" <a:AssocTyDefn*> "}" => TraitDefn
6468
{
6569
name: n,
6670
parameter_kinds: p,
6771
where_clauses: w,
6872
assoc_ty_defns: a,
73+
well_known,
6974
flags: TraitFlags {
7075
auto: auto.is_some(),
7176
marker: marker.is_some(),

chalk-solve/src/clauses.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use chalk_ir::*;
1010
use rustc_hash::FxHashSet;
1111

1212
pub mod builder;
13+
mod builtin_traits;
1314
mod env_elaborator;
1415
pub mod program_clauses;
15-
mod builtin_traits;
1616

1717
/// For auto-traits, we generate a default rule for every struct,
1818
/// unless there is a manual impl for that struct given explicitly.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)