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

+7
-32
lines changed

2 files changed

+7
-32
lines changed

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,33 +1133,26 @@ 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
};
1141+
let hir_id = self.infcx.tcx.hir.node_to_hir_id(node_id);
11421142

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() {
1143+
if let Some((
1144+
span, name
1145+
)) = self.infcx.tcx.typeck_tables_of(did).closure_kind_origins().get(hir_id) {
11511146
diag.span_note(
1152-
freevar.span,
1147+
*span,
11531148
&format!(
11541149
"closure cannot be invoked more than once because it \
11551150
moves the variable `{}` out of its environment",
1156-
self.infcx.tcx.hir.name(freevar.var_id()),
1151+
name,
11571152
),
11581153
);
11591154
}
11601155
}
1161-
});
1162-
}
11631156
}
11641157
}
11651158
}

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

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)