Skip to content

Commit

Permalink
FIXME First draft at better notes explaining the temp and sugggesting…
Browse files Browse the repository at this point in the history
… the semicolon.

fixme 1: niko would like us to say *why* we are making a temp (e.g. a
`&self` method call)

fixme 2: highlighting the source expr for the temp might be a bad idea
overall

fixme 3: might be good to try to avoid suggesting semicolon when the
types would not work out. (doing this completely may be harder than it
sounds; but perhps even simple heurisitcs would sufice.)
  • Loading branch information
pnkfelix committed Sep 21, 2018
1 parent 3e6b2c2 commit 053de39
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
Expand Up @@ -121,7 +121,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
use self::BorrowContainsPointReason::*;

debug!(
"find_why_borrow_contains_point(reason={:?}, kind_place={:?})",
"report_why_borrow_contains_point(reason={:?}, kind_place={:?})",
reason, kind_place,
);

Expand Down Expand Up @@ -170,7 +170,21 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
}
}

None => {}
None => {
debug!("DropLiveness for unnamed local[{:?}]: {:?} experimental explanation",
local, &mir.local_decls[local]);
err.span_label(
mir.source_info(location).span,
format!("borrow later used here, when temporary is dropped"));
err.span_note(
mir.local_decls[local].source_info.span,
"temporary is formed when evaluating this expresion");
if mir.local_decls[local].is_block_tail {
err.note(
"temporary is part of a block-tail expression. \
Consider adding semicolon to drop its temporaries sooner");
}
}
}
OutlivesFreeRegion { outlived_region: Some(region) } => {
self.tcx.note_and_explain_free_region(
Expand All @@ -180,7 +194,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
"...",
);
}
OutlivesFreeRegion { outlived_region: None } => (),
OutlivesFreeRegion { outlived_region: None } => {
debug!("OutlivesFreeRegion for untracked region \
cannot be explained yet :sad face:");
},
}
}

Expand Down

0 comments on commit 053de39

Please sign in to comment.