Skip to content

Commit 2d6be4b

Browse files
committed
Fix scalar, tuple tests to properly assert
1 parent 9a96759 commit 2d6be4b

File tree

5 files changed

+125
-82
lines changed

5 files changed

+125
-82
lines changed

chalk-integration/src/lowering.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,6 @@ impl LowerTy for Ty {
10851085

10861086
Ty::Scalar { ty } => Ok(chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
10871087
name: chalk_ir::TypeName::Scalar(ast_scalar_to_chalk_scalar(ty)),
1088-
// substitution: chalk_ir::Substitution::from_fallible(interner, ty.lower(env)?)?,
10891088
substitution: chalk_ir::Substitution::empty(interner),
10901089
})
10911090
.intern(interner)),

tests/lowering/mod.rs

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -475,84 +475,3 @@ fn scalars() {
475475
}
476476
}
477477
}
478-
479-
#[test]
480-
fn tuple_trait_impl() {
481-
let db = ChalkDatabase::with(
482-
"
483-
trait Foo { }
484-
struct S1 { }
485-
impl Foo for (S1, S1) { }
486-
",
487-
SolverChoice::default(),
488-
);
489-
let goal = db.parse_and_lower_goal("(S1, S1): Foo").unwrap();
490-
db.with_program(|_| {
491-
assert_eq!(format!("{:?}", goal), "Implemented(2<S1, S1>: Foo)");
492-
});
493-
let db = ChalkDatabase::with(
494-
"
495-
trait Foo { }
496-
impl Foo for (i32, i32, (i32,)) { }
497-
",
498-
SolverChoice::default(),
499-
);
500-
let goal = db.parse_and_lower_goal("(i32, i32, (i32,)): Foo").unwrap();
501-
db.with_program(|_| {
502-
assert_eq!(
503-
format!("{:?}", goal),
504-
"Implemented(3<Int(I32), Int(I32), 1<Int(I32)>>: Foo)"
505-
);
506-
});
507-
}
508-
509-
#[test]
510-
fn scalar_trait_impl() {
511-
let db = ChalkDatabase::with(
512-
"
513-
trait Foo { }
514-
impl Foo for usize { }
515-
impl Foo for isize { }
516-
impl<T1, T2> Foo for (T1, T2) where T1: Foo, T2: Foo { }
517-
impl<T> Foo for (T,T,T) where T: Foo { }
518-
",
519-
SolverChoice::default(),
520-
);
521-
let goal = db.parse_and_lower_goal("(usize, usize): Foo").unwrap();
522-
db.with_program(|_| {
523-
assert_eq!(
524-
format!("{:?}", goal),
525-
"Implemented(2<Uint(Usize), Uint(Usize)>: Foo)"
526-
);
527-
});
528-
let goal = db.parse_and_lower_goal("(usize, isize): Foo").unwrap();
529-
db.with_program(|_| {
530-
assert_eq!(
531-
format!("{:?}", goal),
532-
"Implemented(2<Uint(Usize), Int(Isize)>: Foo)"
533-
);
534-
});
535-
let goal = db.parse_and_lower_goal("(usize, bool): Foo").unwrap();
536-
db.with_program(|_| {
537-
// TODO: This should fail (Foo is not implemented for bool)
538-
assert_eq!(
539-
format!("{:?}", goal),
540-
"Implemented(2<Uint(Usize), Bool>: Foo)"
541-
);
542-
});
543-
let goal = db.parse_and_lower_goal("(usize,usize,usize): Foo").unwrap();
544-
db.with_program(|_| {
545-
assert_eq!(
546-
format!("{:?}", goal),
547-
"Implemented(3<Uint(Usize), Uint(Usize), Uint(Usize)>: Foo)"
548-
);
549-
});
550-
let goal = db.parse_and_lower_goal("(char,u8,i8): Foo").unwrap();
551-
db.with_program(|_| {
552-
// TODO: This should fail (the three types are not the same)
553-
assert_eq!(
554-
format!("{:?}", goal),
555-
"Implemented(3<Char, Uint(U8), Int(I8)>: Foo)"
556-
);
557-
});
558-
}

tests/test/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,5 +270,7 @@ mod impls;
270270
mod misc;
271271
mod negation;
272272
mod projection;
273+
mod scalars;
274+
mod tuples;
273275
mod unify;
274276
mod wf_goals;

tests/test/scalars.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
use super::*;
2+
3+
#[test]
4+
fn scalar_in_tuple_trait_impl() {
5+
test! {
6+
program {
7+
trait Foo { }
8+
impl Foo for usize { }
9+
impl Foo for isize { }
10+
impl<T1, T2> Foo for (T1, T2) where T1: Foo, T2: Foo { }
11+
impl<T> Foo for (T,T,T) where T: Foo { }
12+
}
13+
14+
goal {
15+
(usize, usize): Foo
16+
} yields {
17+
"Unique"
18+
}
19+
20+
goal {
21+
(usize, isize): Foo
22+
} yields {
23+
"Unique"
24+
}
25+
26+
goal {
27+
(usize, bool): Foo
28+
} yields {
29+
"No possible solution"
30+
}
31+
32+
goal {
33+
(usize, usize, usize): Foo
34+
} yields {
35+
"Unique"
36+
}
37+
38+
goal {
39+
(char, u8, i8): Foo
40+
} yields {
41+
"No possible solution"
42+
}
43+
}
44+
}
45+
46+
#[test]
47+
fn scalar_trait_impl() {
48+
test! {
49+
program {
50+
trait Foo { }
51+
52+
impl Foo for i8 { }
53+
impl Foo for i16 { }
54+
impl Foo for i32 { }
55+
impl Foo for i64 { }
56+
impl Foo for i128 { }
57+
impl Foo for isize { }
58+
impl Foo for u8 { }
59+
impl Foo for u16 { }
60+
impl Foo for u32 { }
61+
impl Foo for u64 { }
62+
impl Foo for u128 { }
63+
impl Foo for usize { }
64+
impl Foo for f32 { }
65+
impl Foo for f64 { }
66+
impl Foo for bool { }
67+
impl Foo for char { }
68+
}
69+
70+
goal { i8: Foo } yields { "Unique" }
71+
goal { i16: Foo } yields { "Unique" }
72+
goal { i32: Foo } yields { "Unique" }
73+
goal { i64: Foo } yields { "Unique" }
74+
goal { i128: Foo } yields { "Unique" }
75+
goal { isize: Foo } yields { "Unique" }
76+
goal { u8: Foo } yields { "Unique" }
77+
goal { u16: Foo } yields { "Unique" }
78+
goal { u32: Foo } yields { "Unique" }
79+
goal { u64: Foo } yields { "Unique" }
80+
goal { u128: Foo } yields { "Unique" }
81+
goal { usize: Foo } yields { "Unique" }
82+
goal { f32: Foo } yields { "Unique" }
83+
goal { f64: Foo } yields { "Unique" }
84+
goal { bool: Foo } yields { "Unique" }
85+
goal { char: Foo } yields { "Unique" }
86+
}
87+
}

tests/test/tuples.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use super::*;
2+
3+
#[test]
4+
fn tuple_trait_impl() {
5+
test! {
6+
program {
7+
trait Foo { }
8+
struct S1 { }
9+
impl Foo for (S1, S1) { }
10+
impl Foo for () { }
11+
}
12+
goal {
13+
(S1, S1): Foo
14+
} yields {
15+
"Unique"
16+
}
17+
18+
goal {
19+
(): Foo
20+
} yields {
21+
"Unique"
22+
}
23+
}
24+
test! {
25+
program {
26+
trait Foo { }
27+
impl Foo for (i32, i32, (i32,)) { }
28+
}
29+
30+
goal {
31+
(i32, i32, (i32, )): Foo
32+
} yields {
33+
"Unique"
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)