Skip to content

Commit d2692ae

Browse files
committed
Enable to type unit via ZeroSized
1 parent ae1e226 commit d2692ae

5 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/analyze/basic_block.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
213213
chc::Term::bool(val.try_to_bool().unwrap()),
214214
)
215215
}
216+
(mir_ty::TyKind::Tuple(tys), _) if tys.is_empty() => {
217+
PlaceType::with_ty_and_term(rty::Type::unit(), chc::Term::tuple(vec![]))
218+
}
219+
(mir_ty::TyKind::Closure(_, args), _) if args.as_closure().upvar_tys().is_empty() => {
220+
PlaceType::with_ty_and_term(rty::Type::unit(), chc::Term::tuple(vec![]))
221+
}
216222
(
217223
mir_ty::TyKind::Ref(_, elem, Mutability::Not),
218224
ConstValue::Scalar(Scalar::Ptr(ptr, _)),

tests/ui/fail/closure_mut_0.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@error-in-other-file: Unsat
2+
//@compile-flags: -C debug-assertions=off
3+
4+
fn main() {
5+
let mut x = 1;
6+
x += 1;
7+
let mut incr = || {
8+
x += 1;
9+
};
10+
incr();
11+
assert!(x == 2);
12+
}

tests/ui/fail/closure_param.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@error-in-other-file: Unsat
2+
//@compile-flags: -C debug-assertions=off
3+
4+
fn take_fn<T, F: Fn(i32) -> T>(f: F) -> T {
5+
f(42)
6+
}
7+
8+
fn main() {
9+
let y = take_fn(|x| {
10+
assert!(x == 41);
11+
x + 1
12+
});
13+
assert!(y == 42);
14+
}

tests/ui/pass/closure_mut_0.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@check-pass
2+
//@compile-flags: -C debug-assertions=off
3+
4+
fn main() {
5+
let mut x = 1;
6+
let mut incr = || {
7+
x += 1;
8+
};
9+
incr();
10+
assert!(x == 2);
11+
}

tests/ui/pass/closure_param.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@check-pass
2+
//@compile-flags: -C debug-assertions=off
3+
4+
fn take_fn<T, F: Fn(i32) -> T>(f: F) -> T {
5+
f(41)
6+
}
7+
8+
fn main() {
9+
let y = take_fn(|x| {
10+
assert!(x == 41);
11+
x + 1
12+
});
13+
assert!(y == 42);
14+
}

0 commit comments

Comments
 (0)