Skip to content

Commit d088edc

Browse files
committed
Improve check to consider how value is used.
1 parent 375645a commit d088edc

File tree

2 files changed

+15
-40
lines changed

2 files changed

+15
-40
lines changed

src/librustc_mir/borrow_check/error_reporting.rs

+15-22
Original file line numberDiff line numberDiff line change
@@ -1133,32 +1133,25 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
11331133
closure,
11341134
);
11351135

1136-
if let ty::TyKind::Closure(did, substs) = self.mir.local_decls[closure].ty.sty {
1137-
let upvar_tys = substs.upvar_tys(did, self.infcx.tcx);
1136+
if let ty::TyKind::Closure(did, _substs) = self.mir.local_decls[closure].ty.sty {
11381137
let node_id = match self.infcx.tcx.hir.as_local_node_id(did) {
11391138
Some(node_id) => node_id,
11401139
_ => return,
11411140
};
1142-
1143-
self.infcx.tcx.with_freevars(node_id, |freevars| {
1144-
for (freevar, upvar_ty) in freevars.iter().zip(upvar_tys) {
1145-
debug!(
1146-
"add_closure_invoked_twice_with_moved_variable_suggestion: \
1147-
freevar={:?} upvar_ty={:?}",
1148-
freevar, upvar_ty,
1149-
);
1150-
if !upvar_ty.is_region_ptr() {
1151-
diag.span_note(
1152-
freevar.span,
1153-
&format!(
1154-
"closure cannot be invoked more than once because it \
1155-
moves the variable `{}` out of its environment",
1156-
self.infcx.tcx.hir.name(freevar.var_id()),
1157-
),
1158-
);
1159-
}
1160-
}
1161-
});
1141+
let hir_id = self.infcx.tcx.hir.node_to_hir_id(node_id);
1142+
1143+
if let Some((
1144+
span, name
1145+
)) = self.infcx.tcx.typeck_tables_of(did).closure_kind_origins().get(hir_id) {
1146+
diag.span_note(
1147+
*span,
1148+
&format!(
1149+
"closure cannot be invoked more than once because it \
1150+
moves the variable `{}` out of its environment",
1151+
name,
1152+
),
1153+
);
1154+
}
11621155
}
11631156
}
11641157
}

src/test/ui/issues/issue-12127.nll.stderr

-18
This file was deleted.

0 commit comments

Comments
 (0)