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
24 changes: 22 additions & 2 deletions src/analyze/local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,19 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
.iterate_to_fixpoint()
.into_results_cursor(&tmp_body);

let mut zst_locals = BitSet::new_empty(self.body.local_decls.len());
for (local, local_decl) in self.body.local_decls.iter_enumerated() {
let ty = local_decl.ty;
if self
.tcx
.layout_of(mir_ty::ParamEnv::reveal_all().and(ty))
.map(|l| l.is_zst())
.unwrap_or(false)
{
zst_locals.insert(local);
}
}

for (block, data) in mir::traversal::preorder(&tmp_body) {
for statement_index in 0..=data.statements.len() {
let loc = mir::Location {
Expand All @@ -590,9 +603,16 @@ impl<'tcx, 'ctx> Analyzer<'tcx, 'ctx> {
.map(|p| results.analysis().move_data().move_paths[p].place.local)
.collect();
let mut_locals = self.mut_locals(data.visitable(statement_index));
tracing::info!(?init_locals, ?mut_locals, ?statement_index, ?block, stmt = ?data.statements.get(statement_index));
tracing::info!(
?init_locals,
?mut_locals,
?zst_locals,
?statement_index,
?block,
stmt = ?data.statements.get(statement_index),
);
for mut_local in mut_locals.iter() {
if init_locals.contains(&mut_local) {
if init_locals.contains(&mut_local) || zst_locals.contains(mut_local) {
self.body.local_decls[mut_local].mutability = mir::Mutability::Mut;
tracing::info!(?mut_local, ?statement_index, ?block, "marking mut");
}
Expand Down
11 changes: 5 additions & 6 deletions src/refine/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,13 @@ where
// TODO: consider cloning here again
self.locals
.iter()
.map(|(local, rty)| (Var::Local(*local), &rty.ty))
.map(|(local, rty)| (Var::Local(*local), rty.ty.to_sort()))
.filter(|(_, s)| !s.is_singleton())
.chain(
self.temp_vars
.iter_enumerated()
.filter_map(|(idx, b)| b.as_type().map(|rty| (Var::Temp(idx), &rty.ty))),
self.temp_vars.iter_enumerated().filter_map(|(idx, b)| {
b.as_type().map(|rty| (Var::Temp(idx), rty.ty.to_sort()))
}),
)
.map(|(v, ty)| (v, ty.to_sort()))
.filter(|(_, s)| !s.is_singleton())
}

fn vars(&self) -> impl Iterator<Item = (Var, &rty::RefinedType<Var>)> + '_ {
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/fail/closure_mut_param.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@error-in-other-file: Unsat

fn next<F>(f: &mut F) where F: Fn() {
f();
}

fn main() {
let mut f = || { assert!(false); };
next(&mut f);
}
10 changes: 10 additions & 0 deletions tests/ui/fail/mut_empty_tuple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@error-in-other-file: Unsat

fn next(_x: &mut ()) {
assert!(false);
}

fn main() {
let mut s = ();
next(&mut s);
}
10 changes: 10 additions & 0 deletions tests/ui/pass/closure_mut_param.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@check-pass

fn next<F>(f: &mut F) where F: Fn() {
f();
}

fn main() {
let mut f = || { assert!(true); };
next(&mut f);
}
10 changes: 10 additions & 0 deletions tests/ui/pass/mut_empty_tuple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@check-pass

fn next(_x: &mut ()) {
assert!(true);
}

fn main() {
let mut s = ();
next(&mut s);
}