Skip to content

Commit

Permalink
Implement WellFormed for scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMcCaskey committed Apr 20, 2020
1 parent fd15068 commit 2fd7fb7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
6 changes: 6 additions & 0 deletions chalk-solve/src/clauses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ fn match_ty<I: Interner>(
) -> Result<(), Floundered> {
let interner = builder.interner();
Ok(match ty.data(interner) {
TyData::Apply(ApplicationTy {
name: TypeName::Scalar(_),
..
}) => {
builder.push_fact(WellFormed::Ty(ty.clone()));
}
TyData::Apply(application_ty) => match_type_name(builder, application_ty.name),
TyData::Placeholder(_) => {
builder.push_clause(WellFormed::Ty(ty.clone()), Some(FromEnv::Ty(ty.clone())));
Expand Down
2 changes: 0 additions & 2 deletions libstd.chalk
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ trait Clone { }
trait Copy where Self: Clone { }
trait Sized { }

struct i32 { }
impl Copy for i32 { }
impl Clone for i32 { }
impl Sized for i32 { }

struct u32 { }
impl Copy for u32 { }
impl Clone for u32 { }
impl Sized for u32 { }
Expand Down
2 changes: 1 addition & 1 deletion tests/lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ fn scalars() {
}

error_msg {
"parse error: UnrecognizedToken { token: (8, Token(45, \"i32\"), 11), expected: [\"r#\\\"([A-Za-z]|_)([A-Za-z0-9]|_)*\\\"#\"] }"
"parse error: UnrecognizedToken { token: (8, Token(49, \"i32\"), 11), expected: [\"r#\\\"([A-Za-z]|_)([A-Za-z0-9]|_)*\\\"#\"] }"
}
}
}
7 changes: 0 additions & 7 deletions tests/test/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ fn projection_equality_priority2() {
type Type;
}

struct u32 {}
struct S1 {}
struct S2 {}
struct S3 {}
Expand Down Expand Up @@ -286,8 +285,6 @@ fn projection_equality_from_env() {
trait Trait1 {
type Type;
}

struct u32 {}
}

goal {
Expand All @@ -314,8 +311,6 @@ fn projection_equality_nested() {
trait Iterator {
type Item;
}

struct u32 {}
}

goal {
Expand Down Expand Up @@ -360,8 +355,6 @@ fn iterator_flatten() {
{
type Item = <U as Iterator>::Item;
}

struct u32 {}
}

goal {
Expand Down
24 changes: 24 additions & 0 deletions tests/test/scalars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,27 @@ fn scalar_trait_impl() {

}
}

#[test]
fn scalars_are_well_formed() {
test! {
program { }

goal { WellFormed(i8) } yields { "Unique" }
goal { WellFormed(i16) } yields { "Unique" }
goal { WellFormed(i32) } yields { "Unique" }
goal { WellFormed(i64) } yields { "Unique" }
goal { WellFormed(i128) } yields { "Unique" }
goal { WellFormed(isize) } yields { "Unique" }
goal { WellFormed(u8) } yields { "Unique" }
goal { WellFormed(u16) } yields { "Unique" }
goal { WellFormed(u32) } yields { "Unique" }
goal { WellFormed(u64) } yields { "Unique" }
goal { WellFormed(u128) } yields { "Unique" }
goal { WellFormed(usize) } yields { "Unique" }
goal { WellFormed(f32) } yields { "Unique" }
goal { WellFormed(f64) } yields { "Unique" }
goal { WellFormed(bool) } yields { "Unique" }
goal { WellFormed(char) } yields { "Unique" }
}
}

0 comments on commit 2fd7fb7

Please sign in to comment.