Skip to content

Commit bf1a5c2

Browse files
committed
Tidy up comments and some formatting.
Mostly by wrapping overly long comment lines, plus a few other things.
1 parent ad87552 commit bf1a5c2

File tree

13 files changed

+92
-78
lines changed

13 files changed

+92
-78
lines changed

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> {
254254
let sccs = self.regioncx.constraint_sccs();
255255
let universal_regions = self.regioncx.universal_regions();
256256

257-
// We first handle the cases where the loan doesn't go out of scope, depending on the issuing
258-
// region's successors.
257+
// We first handle the cases where the loan doesn't go out of scope, depending on the
258+
// issuing region's successors.
259259
for successor in graph::depth_first_search(&self.regioncx.region_graph(), issuing_region) {
260260
// 1. Via applied member constraints
261261
//

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ where
289289
// `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
290290
// `ObligationCause`. The normalization results are currently different between
291291
// `QueryNormalizeExt::query_normalize` used in the query and `normalize` called below:
292-
// the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test.
293-
// Check after #85499 lands to see if its fixes have erased this difference.
292+
// the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs`
293+
// test. Check after #85499 lands to see if its fixes have erased this difference.
294294
let (param_env, value) = key.into_parts();
295295
let _ = ocx.normalize(&cause, param_env, value.value);
296296

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,11 +1345,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13451345
// See `tests/ui/moves/needs-clone-through-deref.rs`
13461346
return false;
13471347
}
1348-
// We don't want to suggest `.clone()` in a move closure, since the value has already been captured.
1348+
// We don't want to suggest `.clone()` in a move closure, since the value has already been
1349+
// captured.
13491350
if self.in_move_closure(expr) {
13501351
return false;
13511352
}
1352-
// We also don't want to suggest cloning a closure itself, since the value has already been captured.
1353+
// We also don't want to suggest cloning a closure itself, since the value has already been
1354+
// captured.
13531355
if let hir::ExprKind::Closure(_) = expr.kind {
13541356
return false;
13551357
}
@@ -1381,7 +1383,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13811383
}
13821384
}
13831385
}
1384-
// Cloning the raw pointer doesn't make sense in some cases and would cause a type mismatch error. (see #126863)
1386+
// Cloning the raw pointer doesn't make sense in some cases and would cause a type mismatch
1387+
// error. (see #126863)
13851388
if inner_expr.span.lo() != expr.span.lo() && !is_raw_ptr {
13861389
// Remove "(*" or "(&"
13871390
sugg.push((expr.span.with_hi(inner_expr.span.lo()), String::new()));
@@ -1553,8 +1556,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
15531556
let use_spans = self.move_spans(place.as_ref(), location);
15541557
let span = use_spans.var_or_use();
15551558

1556-
// 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
1557-
// we call `var_span_label` on `borrow_spans` to annotate if the existing borrow was in a closure
1559+
// If the attempted use is in a closure then we do not care about the path span of the
1560+
// place we are currently trying to use we call `var_span_label` on `borrow_spans` to
1561+
// annotate if the existing borrow was in a closure.
15581562
let mut err = self.cannot_use_when_mutably_borrowed(
15591563
span,
15601564
&self.describe_any_place(place.as_ref()),
@@ -2480,7 +2484,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
24802484
if let hir::ExprKind::Closure(closure) = ex.kind
24812485
&& ex.span.contains(self.borrow_span)
24822486
// To support cases like `|| { v.call(|this| v.get()) }`
2483-
// FIXME: actually support such cases (need to figure out how to move from the capture place to original local)
2487+
// FIXME: actually support such cases (need to figure out how to move from the
2488+
// capture place to original local).
24842489
&& self.res.as_ref().map_or(true, |(prev_res, _)| prev_res.span.contains(ex.span))
24852490
{
24862491
self.res = Some((ex, closure));
@@ -3188,8 +3193,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
31883193
/// misleading users in cases like `tests/ui/nll/borrowed-temporary-error.rs`.
31893194
/// We could expand the analysis to suggest hoising all of the relevant parts of
31903195
/// the users' code to make the code compile, but that could be too much.
3191-
/// We found the `prop_expr` by the way to check whether the expression is a `FormatArguments`,
3192-
/// which is a special case since it's generated by the compiler.
3196+
/// We found the `prop_expr` by the way to check whether the expression is a
3197+
/// `FormatArguments`, which is a special case since it's generated by the
3198+
/// compiler.
31933199
struct NestedStatementVisitor<'tcx> {
31943200
span: Span,
31953201
current: usize,
@@ -3420,7 +3426,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
34203426
let (sugg_span, suggestion) = match tcx.sess.source_map().span_to_snippet(args_span) {
34213427
Ok(string) => {
34223428
let coro_prefix = if string.starts_with("async") {
3423-
// `async` is 5 chars long. Not using `.len()` to avoid the cast from `usize` to `u32`
3429+
// `async` is 5 chars long. Not using `.len()` to avoid the cast from `usize`
3430+
// to `u32`.
34243431
Some(5)
34253432
} else if string.starts_with("gen") {
34263433
// `gen` is 3 chars long
@@ -3618,10 +3625,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
36183625
let stmt_kind =
36193626
self.body[location.block].statements.get(location.statement_index).map(|s| &s.kind);
36203627
if let Some(StatementKind::StorageDead(..)) = stmt_kind {
3621-
// this analysis only tries to find moves explicitly
3622-
// written by the user, so we ignore the move-outs
3623-
// created by `StorageDead` and at the beginning
3624-
// of a function.
3628+
// This analysis only tries to find moves explicitly written by the user, so we
3629+
// ignore the move-outs created by `StorageDead` and at the beginning of a
3630+
// function.
36253631
} else {
36263632
// If we are found a use of a.b.c which was in error, then we want to look for
36273633
// moves not only of a.b.c but also a.b and a.
@@ -3706,13 +3712,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
37063712
}
37073713
}
37083714
if (is_argument || !reached_start) && result.is_empty() {
3709-
/* Process back edges (moves in future loop iterations) only if
3710-
the move path is definitely initialized upon loop entry,
3711-
to avoid spurious "in previous iteration" errors.
3712-
During DFS, if there's a path from the error back to the start
3713-
of the function with no intervening init or move, then the
3714-
move path may be uninitialized at loop entry.
3715-
*/
3715+
// Process back edges (moves in future loop iterations) only if
3716+
// the move path is definitely initialized upon loop entry,
3717+
// to avoid spurious "in previous iteration" errors.
3718+
// During DFS, if there's a path from the error back to the start
3719+
// of the function with no intervening init or move, then the
3720+
// move path may be uninitialized at loop entry.
37163721
while let Some(location) = back_edge_stack.pop() {
37173722
if dfs_iter(&mut result, location, true) {
37183723
continue;

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
130130
{
131131
suggest_rewrite_if_let(tcx, expr, &pat, init, conseq, alt, err);
132132
} else if path_span.map_or(true, |path_span| path_span == var_or_use_span) {
133-
// We can use `var_or_use_span` if either `path_span` is not present, or both spans are the same
133+
// We can use `var_or_use_span` if either `path_span` is not present, or both
134+
// spans are the same.
134135
if borrow_span.map_or(true, |sp| !sp.overlaps(var_or_use_span)) {
135136
err.span_label(
136137
var_or_use_span,
@@ -165,7 +166,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
165166
LaterUseKind::FakeLetRead => "borrow later stored here",
166167
LaterUseKind::Other => "borrow used here, in later iteration of loop",
167168
};
168-
// We can use `var_or_use_span` if either `path_span` is not present, or both spans are the same
169+
// We can use `var_or_use_span` if either `path_span` is not present, or both spans
170+
// are the same.
169171
if path_span.map(|path_span| path_span == var_or_use_span).unwrap_or(true) {
170172
err.span_label(var_or_use_span, format!("{borrow_desc}{message}"));
171173
} else {
@@ -285,7 +287,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
285287
span: _,
286288
pat,
287289
init,
288-
// FIXME(#101728): enable rewrite when type ascription is stabilized again
290+
// FIXME(#101728): enable rewrite when type ascription is
291+
// stabilized again.
289292
ty: None,
290293
recovered: _,
291294
}) = cond.kind
@@ -353,8 +356,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
353356
unsize_ty: Ty<'tcx>,
354357
) {
355358
if let ty::Adt(def, args) = unsize_ty.kind() {
356-
// We try to elaborate the object lifetime defaults and present those to the user. This should
357-
// make it clear where the region constraint is coming from.
359+
// We try to elaborate the object lifetime defaults and present those to the user. This
360+
// should make it clear where the region constraint is coming from.
358361
let generics = tcx.generics_of(def.did());
359362

360363
let mut has_dyn = false;
@@ -531,9 +534,10 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
531534
let mut use_in_later_iteration_of_loop = false;
532535

533536
if region_sub == borrow_region_vid {
534-
// When `region_sub` is the same as `borrow_region_vid` (the location where the borrow is
535-
// issued is the same location that invalidates the reference), this is likely a loop iteration
536-
// - in this case, try using the loop terminator location in `find_sub_region_live_at`.
537+
// When `region_sub` is the same as `borrow_region_vid` (the location where the borrow
538+
// is issued is the same location that invalidates the reference), this is likely a
539+
// loop iteration. In this case, try using the loop terminator location in
540+
// `find_sub_region_live_at`.
537541
if let Some(loop_terminator_location) =
538542
regioncx.find_loop_terminator_location(borrow.region, body)
539543
{

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
763763
}
764764
}
765765

766-
///helper struct for explain_captures()
766+
/// Helper struct for `explain_captures`.
767767
struct CapturedMessageOpt {
768768
is_partial_move: bool,
769769
is_loop_message: bool,

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
793793
let reason = if let PlaceBase::Upvar(upvar_id) = closure_kind_origin.base {
794794
let upvar = ty::place_to_string_for_capture(tcx, closure_kind_origin);
795795
let root_hir_id = upvar_id.var_path.hir_id;
796-
// we have an origin for this closure kind starting at this root variable so it's safe to unwrap here
796+
// We have an origin for this closure kind starting at this root variable so it's
797+
// safe to unwrap here.
797798
let captured_places =
798799
tables.closure_min_captures[&closure_local_def_id].get(&root_hir_id).unwrap();
799800

@@ -966,8 +967,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
966967
}
967968
};
968969

969-
// If we can detect the expression to be an function or method call where the closure was an argument,
970-
// we point at the function or method definition argument...
970+
// If we can detect the expression to be an function or method call where the closure was
971+
// an argument, we point at the function or method definition argument...
971972
if let Some((callee_def_id, call_span, call_args)) = get_call_details() {
972973
let arg_pos = call_args
973974
.iter()

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ pub(crate) struct RegionName {
3030
}
3131

3232
/// Denotes the source of a region that is named by a `RegionName`. For example, a free region that
33-
/// was named by the user would get `NamedLateParamRegion` and `'static` lifetime would get `Static`.
34-
/// This helps to print the right kinds of diagnostics.
33+
/// was named by the user would get `NamedLateParamRegion` and `'static` lifetime would get
34+
/// `Static`. This helps to print the right kinds of diagnostics.
3535
#[derive(Debug, Clone, Copy)]
3636
pub(crate) enum RegionNameSource {
3737
/// A bound (not free) region that was instantiated at the def site (not an HRTB).
@@ -825,8 +825,8 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
825825
/// async fn foo() -> i32 { 2 }
826826
/// ```
827827
///
828-
/// this function, given the lowered return type of `foo`, an [`OpaqueDef`] that implements `Future<Output=i32>`,
829-
/// returns the `i32`.
828+
/// this function, given the lowered return type of `foo`, an [`OpaqueDef`] that implements
829+
/// `Future<Output=i32>`, returns the `i32`.
830830
///
831831
/// [`OpaqueDef`]: hir::TyKind::OpaqueDef
832832
fn get_future_inner_return_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> {

compiler/rustc_borrowck/src/lib.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
9292

9393
/// Associate some local constants with the `'tcx` lifetime
9494
struct TyCtxtConsts<'tcx>(PhantomData<&'tcx ()>);
95+
9596
impl<'tcx> TyCtxtConsts<'tcx> {
9697
const DEREF_PROJECTION: &'tcx [PlaceElem<'tcx>; 1] = &[ProjectionElem::Deref];
9798
}
@@ -637,7 +638,9 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
637638
);
638639
}
639640
StatementKind::Intrinsic(box kind) => match kind {
640-
NonDivergingIntrinsic::Assume(op) => self.consume_operand(location, (op, span), state),
641+
NonDivergingIntrinsic::Assume(op) => {
642+
self.consume_operand(location, (op, span), state);
643+
}
641644
NonDivergingIntrinsic::CopyNonOverlapping(..) => span_bug!(
642645
span,
643646
"Unexpected CopyNonOverlapping, should only appear after lower_intrinsics",
@@ -2104,7 +2107,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
21042107
| Write(WriteKind::MutableBorrow(BorrowKind::Mut { kind: mut_borrow_kind })) => {
21052108
let is_local_mutation_allowed = match mut_borrow_kind {
21062109
// `ClosureCapture` is used for mutable variable with an immutable binding.
2107-
// This is only behaviour difference between `ClosureCapture` and mutable borrows.
2110+
// This is only behaviour difference between `ClosureCapture` and mutable
2111+
// borrows.
21082112
MutBorrowKind::ClosureCapture => LocalMutationIsAllowed::Yes,
21092113
MutBorrowKind::Default | MutBorrowKind::TwoPhaseBorrow => {
21102114
is_local_mutation_allowed
@@ -2349,23 +2353,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
23492353
) => Err(place),
23502354
(Mutability::Not, LocalMutationIsAllowed::Yes)
23512355
| (Mutability::Mut, _) => {
2352-
// Subtle: this is an upvar
2353-
// reference, so it looks like
2354-
// `self.foo` -- we want to double
2355-
// check that the location `*self`
2356-
// is mutable (i.e., this is not a
2357-
// `Fn` closure). But if that
2358-
// check succeeds, we want to
2359-
// *blame* the mutability on
2360-
// `place` (that is,
2361-
// `self.foo`). This is used to
2362-
// propagate the info about
2363-
// whether mutability declarations
2364-
// are used outwards, so that we register
2365-
// the outer variable as mutable. Otherwise a
2366-
// test like this fails to record the `mut`
2367-
// as needed:
2368-
//
2356+
// Subtle: this is an upvar reference, so it looks like
2357+
// `self.foo` -- we want to double check that the location
2358+
// `*self` is mutable (i.e., this is not a `Fn` closure). But
2359+
// if that check succeeds, we want to *blame* the mutability on
2360+
// `place` (that is, `self.foo`). This is used to propagate the
2361+
// info about whether mutability declarations are used
2362+
// outwards, so that we register the outer variable as mutable.
2363+
// Otherwise a test like this fails to record the `mut` as
2364+
// needed:
23692365
// ```
23702366
// fn foo<F: FnOnce()>(_f: F) { }
23712367
// fn main() {

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
14971497
fn scc_universe(&self, scc: ConstraintSccIndex) -> UniverseIndex {
14981498
self.constraint_sccs().annotation(scc).min_universe()
14991499
}
1500+
15001501
/// Checks the final value for the free region `fr` to see if it
15011502
/// grew too large. In particular, examine what `end(X)` points
15021503
/// wound up in `fr`'s final value; for each `end(X)` where `X !=
@@ -1669,7 +1670,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
16691670
placeholder,
16701671
});
16711672

1672-
// Stop after the first error, it gets too noisy otherwise, and does not provide more information.
1673+
// Stop after the first error, it gets too noisy otherwise, and does not provide more
1674+
// information.
16731675
break;
16741676
}
16751677
debug!("check_bound_universal_region: all bounds satisfied");
@@ -2002,8 +2004,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20022004

20032005
// We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint.
20042006
// Instead, we use it to produce an improved `ObligationCauseCode`.
2005-
// FIXME - determine what we should do if we encounter multiple `ConstraintCategory::Predicate`
2006-
// constraints. Currently, we just pick the first one.
2007+
// FIXME - determine what we should do if we encounter multiple
2008+
// `ConstraintCategory::Predicate` constraints. Currently, we just pick the first one.
20072009
let cause_code = path
20082010
.iter()
20092011
.find_map(|constraint| {

0 commit comments

Comments
 (0)