about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src/diagnostics
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-10-04 10:24:34 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2024-11-04 17:36:25 +1100
commitbf1a5c2b7f1f54c94ab2dfdcf4cb7d4fb220b0b3 (patch)
tree18cd9fb581f13929a55534af2d305cd6dab7b249 /compiler/rustc_borrowck/src/diagnostics
parentad875529bf792069350ae3899daa2102f247837b (diff)
downloadrust-bf1a5c2b7f1f54c94ab2dfdcf4cb7d4fb220b0b3.tar.gz
rust-bf1a5c2b7f1f54c94ab2dfdcf4cb7d4fb220b0b3.zip
Tidy up comments and some formatting.
Mostly by wrapping overly long comment lines, plus a few other things.
Diffstat (limited to 'compiler/rustc_borrowck/src/diagnostics')
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs4
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs45
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs20
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/mod.rs2
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs7
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/region_name.rs8
6 files changed, 48 insertions, 38 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs
index 2fa752384a1..ab50e5a6a45 100644
--- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs
@@ -289,8 +289,8 @@ where
         // `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
         // `ObligationCause`. The normalization results are currently different between
         // `QueryNormalizeExt::query_normalize` used in the query and `normalize` called below:
-        // the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test.
-        // Check after #85499 lands to see if its fixes have erased this difference.
+        // the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs`
+        // test. Check after #85499 lands to see if its fixes have erased this difference.
         let (param_env, value) = key.into_parts();
         let _ = ocx.normalize(&cause, param_env, value.value);
 
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
index 4e026767636..e5b28289faa 100644
--- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
@@ -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;
diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
index 31a5d451ff6..45a8ef0adb6 100644
--- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
@@ -130,7 +130,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
                 {
                     suggest_rewrite_if_let(tcx, expr, &pat, init, conseq, alt, err);
                 } else if path_span.map_or(true, |path_span| path_span == var_or_use_span) {
-                    // We can use `var_or_use_span` if either `path_span` is not present, or both spans are the same
+                    // We can use `var_or_use_span` if either `path_span` is not present, or both
+                    // spans are the same.
                     if borrow_span.map_or(true, |sp| !sp.overlaps(var_or_use_span)) {
                         err.span_label(
                             var_or_use_span,
@@ -165,7 +166,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
                     LaterUseKind::FakeLetRead => "borrow later stored here",
                     LaterUseKind::Other => "borrow used here, in later iteration of loop",
                 };
-                // We can use `var_or_use_span` if either `path_span` is not present, or both spans are the same
+                // We can use `var_or_use_span` if either `path_span` is not present, or both spans
+                // are the same.
                 if path_span.map(|path_span| path_span == var_or_use_span).unwrap_or(true) {
                     err.span_label(var_or_use_span, format!("{borrow_desc}{message}"));
                 } else {
@@ -285,7 +287,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
                                 span: _,
                                 pat,
                                 init,
-                                // FIXME(#101728): enable rewrite when type ascription is stabilized again
+                                // FIXME(#101728): enable rewrite when type ascription is
+                                // stabilized again.
                                 ty: None,
                                 recovered: _,
                             }) = cond.kind
@@ -353,8 +356,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
         unsize_ty: Ty<'tcx>,
     ) {
         if let ty::Adt(def, args) = unsize_ty.kind() {
-            // We try to elaborate the object lifetime defaults and present those to the user. This should
-            // make it clear where the region constraint is coming from.
+            // We try to elaborate the object lifetime defaults and present those to the user. This
+            // should make it clear where the region constraint is coming from.
             let generics = tcx.generics_of(def.did());
 
             let mut has_dyn = false;
@@ -531,9 +534,10 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
         let mut use_in_later_iteration_of_loop = false;
 
         if region_sub == borrow_region_vid {
-            // When `region_sub` is the same as `borrow_region_vid` (the location where the borrow is
-            // issued is the same location that invalidates the reference), this is likely a loop iteration
-            // - in this case, try using the loop terminator location in `find_sub_region_live_at`.
+            // When `region_sub` is the same as `borrow_region_vid` (the location where the borrow
+            // is issued is the same location that invalidates the reference), this is likely a
+            // loop iteration. In this case, try using the loop terminator location in
+            // `find_sub_region_live_at`.
             if let Some(loop_terminator_location) =
                 regioncx.find_loop_terminator_location(borrow.region, body)
             {
diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs
index 07b3c295eaa..0797bb49bf9 100644
--- a/compiler/rustc_borrowck/src/diagnostics/mod.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs
@@ -763,7 +763,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
     }
 }
 
-///helper struct for explain_captures()
+/// Helper struct for `explain_captures`.
 struct CapturedMessageOpt {
     is_partial_move: bool,
     is_loop_message: bool,
diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
index 33bd4f37b7f..a2194a1cf2a 100644
--- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
@@ -793,7 +793,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
             let reason = if let PlaceBase::Upvar(upvar_id) = closure_kind_origin.base {
                 let upvar = ty::place_to_string_for_capture(tcx, closure_kind_origin);
                 let root_hir_id = upvar_id.var_path.hir_id;
-                // we have an origin for this closure kind starting at this root variable so it's safe to unwrap here
+                // We have an origin for this closure kind starting at this root variable so it's
+                // safe to unwrap here.
                 let captured_places =
                     tables.closure_min_captures[&closure_local_def_id].get(&root_hir_id).unwrap();
 
@@ -966,8 +967,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
             }
         };
 
-        // If we can detect the expression to be an function or method call where the closure was an argument,
-        // we point at the function or method definition argument...
+        // If we can detect the expression to be an function or method call where the closure was
+        // an argument, we point at the function or method definition argument...
         if let Some((callee_def_id, call_span, call_args)) = get_call_details() {
             let arg_pos = call_args
                 .iter()
diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs
index 6ca7251295d..8a2987b6d4a 100644
--- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs
@@ -30,8 +30,8 @@ pub(crate) struct RegionName {
 }
 
 /// Denotes the source of a region that is named by a `RegionName`. For example, a free region that
-/// was named by the user would get `NamedLateParamRegion` and `'static` lifetime would get `Static`.
-/// This helps to print the right kinds of diagnostics.
+/// was named by the user would get `NamedLateParamRegion` and `'static` lifetime would get
+/// `Static`. This helps to print the right kinds of diagnostics.
 #[derive(Debug, Clone, Copy)]
 pub(crate) enum RegionNameSource {
     /// A bound (not free) region that was instantiated at the def site (not an HRTB).
@@ -825,8 +825,8 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
     /// async fn foo() -> i32 { 2 }
     /// ```
     ///
-    /// this function, given the lowered return type of `foo`, an [`OpaqueDef`] that implements `Future<Output=i32>`,
-    /// returns the `i32`.
+    /// this function, given the lowered return type of `foo`, an [`OpaqueDef`] that implements
+    /// `Future<Output=i32>`, returns the `i32`.
     ///
     /// [`OpaqueDef`]: hir::TyKind::OpaqueDef
     fn get_future_inner_return_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> {