Reword diagnostic
This commit is contained in:
parent
846042161c
commit
c31c60cbb9
2 changed files with 9 additions and 13 deletions
|
|
@ -1071,7 +1071,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
// #45983: when trying to assign the contents of an argument to a binding outside of a
|
||||
// closure, provide a specific message pointing this out.
|
||||
if let (&SubregionOrigin::BindingTypeIsNotValidAtDecl(ref external_span),
|
||||
&SubregionOrigin::Subtype(TypeTrace { ref cause, .. }),
|
||||
&SubregionOrigin::Subtype(_),
|
||||
&RegionKind::ReFree(ref free_region)) = (&sub_origin, &sup_origin, sup_region) {
|
||||
let hir = &self.tcx.hir;
|
||||
if let Some(node_id) = hir.as_local_node_id(free_region.scope) {
|
||||
|
|
@ -1084,15 +1084,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
let mut err = self.tcx.sess.struct_span_err(
|
||||
sp,
|
||||
"borrowed data cannot be moved outside of its closure");
|
||||
let label = match cause.code {
|
||||
ObligationCauseCode::ExprAssignable => {
|
||||
"cannot be assigned to binding outside of its closure"
|
||||
}
|
||||
_ => "cannot be moved outside of its closure",
|
||||
};
|
||||
err.span_label(sp, label);
|
||||
err.span_label(*closure_span, "closure you can't escape");
|
||||
err.span_label(*external_span, "binding declared outside of closure");
|
||||
err.span_label(sp, "cannot be moved outside of its closure");
|
||||
err.span_label(*external_span,
|
||||
"borrowed data cannot be moved into here...");
|
||||
err.span_label(*closure_span,
|
||||
"...because it cannot outlive this closure");
|
||||
err.emit();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ error: borrowed data cannot be moved outside of its closure
|
|||
--> $DIR/issue-45983.rs:17:27
|
||||
|
|
||||
16 | let x = None;
|
||||
| - binding declared outside of closure
|
||||
| - borrowed data cannot be moved into here...
|
||||
17 | give_any(|y| x = Some(y));
|
||||
| --- ^ cannot be assigned to binding outside of its closure
|
||||
| --- ^ cannot be moved outside of its closure
|
||||
| |
|
||||
| closure you can't escape
|
||||
| ...because it cannot outlive this closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue