Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/analyze/local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,8 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
let mut subst = HashMap::new();
for (param_idx, param_ty) in bb_ty.as_ref().params.iter_enumerated() {
if let Some(param_local) = bb_ty.local_of_param(param_idx) {
// unit return may use _0 without preceeding def
if param_local == mir::RETURN_PLACE {
// BBs may use locals without preceding def when they're ZST
if param_local == mir::RETURN_PLACE || param_local > self.body.arg_count.into() {
subst.extend(
bb_ty
.as_ref()
Expand All @@ -730,7 +730,7 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
.skip_while(|idx| idx.index() <= param_idx.index())
.map(|idx| (idx, idx + 1)),
);
if bb_ty.as_ref().params.len() == 1 {
if bb_ty.as_ref().params.len() - 1 == param_idx.index() {
params.push(rty::RefinedType::new(
rty::Type::unit(),
param_ty.refinement.clone(),
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/fail/closure_field_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@error-in-other-file: Unsat
//@compile-flags: -C debug-assertions=off

struct S<F> {
f: F,
}

fn main() {
let s = S {
f: |x: i32| x + 1,
};
let x = (s.f)(1);
assert!(x == 1);
}
14 changes: 14 additions & 0 deletions tests/ui/pass/closure_field_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@check-pass
//@compile-flags: -C debug-assertions=off

struct S<F> {
f: F,
}

fn main() {
let s = S {
f: |x: i32| x + 1,
};
let x = (s.f)(1);
assert!(x == 2);
}