Tidy up comments and some formatting.

Mostly by wrapping overly long comment lines, plus a few other things.
This commit is contained in:
Nicholas Nethercote
2024-10-04 10:24:34 +10:00
parent ad875529bf
commit bf1a5c2b7f
13 changed files with 92 additions and 78 deletions

View File

@@ -1345,11 +1345,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
// See `tests/ui/moves/needs-clone-through-deref.rs`
return false;
}
// We don't want to suggest `.clone()` in a move closure, since the value has already been captured.
// We don't want to suggest `.clone()` in a move closure, since the value has already been
// captured.
if self.in_move_closure(expr) {
return false;
}
// We also don't want to suggest cloning a closure itself, since the value has already been captured.
// We also don't want to suggest cloning a closure itself, since the value has already been
// captured.
if let hir::ExprKind::Closure(_) = expr.kind {
return false;
}
@@ -1381,7 +1383,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
}
}
}
// Cloning the raw pointer doesn't make sense in some cases and would cause a type mismatch error. (see #126863)
// Cloning the raw pointer doesn't make sense in some cases and would cause a type mismatch
// error. (see #126863)
if inner_expr.span.lo() != expr.span.lo() && !is_raw_ptr {
// Remove "(*" or "(&"
sugg.push((expr.span.with_hi(inner_expr.span.lo()), String::new()));
@@ -1553,8 +1556,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let use_spans = self.move_spans(place.as_ref(), location);
let span = use_spans.var_or_use();
// If the attempted use is in a closure then we do not care about the path span of the place we are currently trying to use
// we call `var_span_label` on `borrow_spans` to annotate if the existing borrow was in a closure
// If the attempted use is in a closure then we do not care about the path span of the
// place we are currently trying to use we call `var_span_label` on `borrow_spans` to
// annotate if the existing borrow was in a closure.
let mut err = self.cannot_use_when_mutably_borrowed(
span,
&self.describe_any_place(place.as_ref()),
@@ -2480,7 +2484,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
if let hir::ExprKind::Closure(closure) = ex.kind
&& ex.span.contains(self.borrow_span)
// To support cases like `|| { v.call(|this| v.get()) }`
// FIXME: actually support such cases (need to figure out how to move from the capture place to original local)
// FIXME: actually support such cases (need to figure out how to move from the
// capture place to original local).
&& self.res.as_ref().map_or(true, |(prev_res, _)| prev_res.span.contains(ex.span))
{
self.res = Some((ex, closure));
@@ -3188,8 +3193,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
/// misleading users in cases like `tests/ui/nll/borrowed-temporary-error.rs`.
/// We could expand the analysis to suggest hoising all of the relevant parts of
/// the users' code to make the code compile, but that could be too much.
/// We found the `prop_expr` by the way to check whether the expression is a `FormatArguments`,
/// which is a special case since it's generated by the compiler.
/// We found the `prop_expr` by the way to check whether the expression is a
/// `FormatArguments`, which is a special case since it's generated by the
/// compiler.
struct NestedStatementVisitor<'tcx> {
span: Span,
current: usize,
@@ -3420,7 +3426,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let (sugg_span, suggestion) = match tcx.sess.source_map().span_to_snippet(args_span) {
Ok(string) => {
let coro_prefix = if string.starts_with("async") {
// `async` is 5 chars long. Not using `.len()` to avoid the cast from `usize` to `u32`
// `async` is 5 chars long. Not using `.len()` to avoid the cast from `usize`
// to `u32`.
Some(5)
} else if string.starts_with("gen") {
// `gen` is 3 chars long
@@ -3618,10 +3625,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let stmt_kind =
self.body[location.block].statements.get(location.statement_index).map(|s| &s.kind);
if let Some(StatementKind::StorageDead(..)) = stmt_kind {
// this analysis only tries to find moves explicitly
// written by the user, so we ignore the move-outs
// created by `StorageDead` and at the beginning
// of a function.
// This analysis only tries to find moves explicitly written by the user, so we
// ignore the move-outs created by `StorageDead` and at the beginning of a
// function.
} else {
// If we are found a use of a.b.c which was in error, then we want to look for
// moves not only of a.b.c but also a.b and a.
@@ -3706,13 +3712,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
}
}
if (is_argument || !reached_start) && result.is_empty() {
/* Process back edges (moves in future loop iterations) only if
the move path is definitely initialized upon loop entry,
to avoid spurious "in previous iteration" errors.
During DFS, if there's a path from the error back to the start
of the function with no intervening init or move, then the
move path may be uninitialized at loop entry.
*/
// Process back edges (moves in future loop iterations) only if
// the move path is definitely initialized upon loop entry,
// to avoid spurious "in previous iteration" errors.
// During DFS, if there's a path from the error back to the start
// of the function with no intervening init or move, then the
// move path may be uninitialized at loop entry.
while let Some(location) = back_edge_stack.pop() {
if dfs_iter(&mut result, location, true) {
continue;