Skip to content

Commit aa20154

Browse files
authored
Merge pull request #42 from coord-e/coord-e/fix-closure-field-1
Allow non-return ZST places to appear without proceding defs in BB
2 parents 9e92551 + e00fe7f commit aa20154

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

src/analyze/local_def.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,8 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
720720
let mut subst = HashMap::new();
721721
for (param_idx, param_ty) in bb_ty.as_ref().params.iter_enumerated() {
722722
if let Some(param_local) = bb_ty.local_of_param(param_idx) {
723-
// unit return may use _0 without preceeding def
724-
if param_local == mir::RETURN_PLACE {
723+
// BBs may use locals without preceding def when they're ZST
724+
if param_local == mir::RETURN_PLACE || param_local > self.body.arg_count.into() {
725725
subst.extend(
726726
bb_ty
727727
.as_ref()
@@ -730,7 +730,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
730730
.skip_while(|idx| idx.index() <= param_idx.index())
731731
.map(|idx| (idx, idx + 1)),
732732
);
733-
if bb_ty.as_ref().params.len() == 1 {
733+
if bb_ty.as_ref().params.len() - 1 == param_idx.index() {
734734
params.push(rty::RefinedType::new(
735735
rty::Type::unit(),
736736
param_ty.refinement.clone(),

tests/ui/fail/closure_field_1.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+
struct S<F> {
5+
f: F,
6+
}
7+
8+
fn main() {
9+
let s = S {
10+
f: |x: i32| x + 1,
11+
};
12+
let x = (s.f)(1);
13+
assert!(x == 1);
14+
}

tests/ui/pass/closure_field_1.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+
struct S<F> {
5+
f: F,
6+
}
7+
8+
fn main() {
9+
let s = S {
10+
f: |x: i32| x + 1,
11+
};
12+
let x = (s.f)(1);
13+
assert!(x == 2);
14+
}

0 commit comments

Comments
 (0)