diff --git a/compiler/rustc_borrowck/src/dataflow.rs b/compiler/rustc_borrowck/src/dataflow.rs index 89ff12c1479..d832decc170 100644 --- a/compiler/rustc_borrowck/src/dataflow.rs +++ b/compiler/rustc_borrowck/src/dataflow.rs @@ -254,8 +254,8 @@ fn precompute_loans_out_of_scope( let sccs = self.regioncx.constraint_sccs(); let universal_regions = self.regioncx.universal_regions(); - // We first handle the cases where the loan doesn't go out of scope, depending on the issuing - // region's successors. + // We first handle the cases where the loan doesn't go out of scope, depending on the + // issuing region's successors. for successor in graph::depth_first_search(&self.regioncx.region_graph(), issuing_region) { // 1. Via applied member constraints // 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 @@ fn nice_error<'infcx>( // `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 @@ fn suggest_cloning_inner( // 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 @@ fn suggest_cloning_inner( } } } - // 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 @@ pub(crate) fn report_use_while_mutably_borrowed( 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 @@ fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) { 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 @@ fn report_temporary_value_does_not_live_long_enough( /// 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 @@ fn report_escaping_closure_capture( 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 @@ fn predecessor_locations<'a, '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 @@ fn predecessor_locations<'a, '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 @@ pub(crate) fn add_explanation_to_diagnostic( { 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 @@ pub(crate) fn add_explanation_to_diagnostic( 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 @@ pub(crate) fn add_explanation_to_diagnostic( 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 @@ fn add_object_lifetime_default_note( 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 @@ pub(crate) fn explain_why_borrow_contains_point( 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 @@ fn from_call(func: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Option { } } -///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 @@ fn show_mutating_upvar( 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 @@ fn expected_fn_found_fn_mut_call(&self, err: &mut Diag<'_>, sp: Span, act: &str) } }; - // 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 @@ fn give_name_if_anonymous_region_appears_in_output(&self, fr: RegionVid) -> Opti /// async fn foo() -> i32 { 2 } /// ``` /// - /// this function, given the lowered return type of `foo`, an [`OpaqueDef`] that implements `Future`, - /// returns the `i32`. + /// this function, given the lowered return type of `foo`, an [`OpaqueDef`] that implements + /// `Future`, returns the `i32`. /// /// [`OpaqueDef`]: hir::TyKind::OpaqueDef fn get_future_inner_return_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> { diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 2ef3e108bdb..0d1edd4d383 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -92,6 +92,7 @@ /// Associate some local constants with the `'tcx` lifetime struct TyCtxtConsts<'tcx>(PhantomData<&'tcx ()>); + impl<'tcx> TyCtxtConsts<'tcx> { const DEREF_PROJECTION: &'tcx [PlaceElem<'tcx>; 1] = &[ProjectionElem::Deref]; } @@ -637,7 +638,9 @@ fn visit_statement_before_primary_effect( ); } StatementKind::Intrinsic(box kind) => match kind { - NonDivergingIntrinsic::Assume(op) => self.consume_operand(location, (op, span), state), + NonDivergingIntrinsic::Assume(op) => { + self.consume_operand(location, (op, span), state); + } NonDivergingIntrinsic::CopyNonOverlapping(..) => span_bug!( span, "Unexpected CopyNonOverlapping, should only appear after lower_intrinsics", @@ -2104,7 +2107,8 @@ fn check_access_permissions( | Write(WriteKind::MutableBorrow(BorrowKind::Mut { kind: mut_borrow_kind })) => { let is_local_mutation_allowed = match mut_borrow_kind { // `ClosureCapture` is used for mutable variable with an immutable binding. - // This is only behaviour difference between `ClosureCapture` and mutable borrows. + // This is only behaviour difference between `ClosureCapture` and mutable + // borrows. MutBorrowKind::ClosureCapture => LocalMutationIsAllowed::Yes, MutBorrowKind::Default | MutBorrowKind::TwoPhaseBorrow => { is_local_mutation_allowed @@ -2349,23 +2353,15 @@ fn is_mutable( ) => Err(place), (Mutability::Not, LocalMutationIsAllowed::Yes) | (Mutability::Mut, _) => { - // Subtle: this is an upvar - // reference, so it looks like - // `self.foo` -- we want to double - // check that the location `*self` - // is mutable (i.e., this is not a - // `Fn` closure). But if that - // check succeeds, we want to - // *blame* the mutability on - // `place` (that is, - // `self.foo`). This is used to - // propagate the info about - // whether mutability declarations - // are used outwards, so that we register - // the outer variable as mutable. Otherwise a - // test like this fails to record the `mut` - // as needed: - // + // Subtle: this is an upvar reference, so it looks like + // `self.foo` -- we want to double check that the location + // `*self` is mutable (i.e., this is not a `Fn` closure). But + // if that check succeeds, we want to *blame* the mutability on + // `place` (that is, `self.foo`). This is used to propagate the + // info about whether mutability declarations are used + // outwards, so that we register the outer variable as mutable. + // Otherwise a test like this fails to record the `mut` as + // needed: // ``` // fn foo(_f: F) { } // fn main() { diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 84a01162d76..1c6e323a8fe 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -1497,6 +1497,7 @@ fn check_polonius_subset_errors( fn scc_universe(&self, scc: ConstraintSccIndex) -> UniverseIndex { self.constraint_sccs().annotation(scc).min_universe() } + /// Checks the final value for the free region `fr` to see if it /// grew too large. In particular, examine what `end(X)` points /// wound up in `fr`'s final value; for each `end(X)` where `X != @@ -1669,7 +1670,8 @@ fn check_bound_universal_region( placeholder, }); - // Stop after the first error, it gets too noisy otherwise, and does not provide more information. + // Stop after the first error, it gets too noisy otherwise, and does not provide more + // information. break; } debug!("check_bound_universal_region: all bounds satisfied"); @@ -2002,8 +2004,8 @@ pub(crate) fn best_blame_constraint( // We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint. // Instead, we use it to produce an improved `ObligationCauseCode`. - // FIXME - determine what we should do if we encounter multiple `ConstraintCategory::Predicate` - // constraints. Currently, we just pick the first one. + // FIXME - determine what we should do if we encounter multiple + // `ConstraintCategory::Predicate` constraints. Currently, we just pick the first one. let cause_code = path .iter() .find_map(|constraint| { diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index 3a2f5c35c72..f9dd649ab9f 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -145,9 +145,9 @@ pub(crate) fn infer_opaque_types( continue; } // Sometimes two opaque types are the same only after we remap the generic parameters - // back to the opaque type definition. E.g. we may have `OpaqueType` mapped to `(X, Y)` - // and `OpaqueType` mapped to `(Y, X)`, and those are the same, but we only know that - // once we convert the generic parameters to those of the opaque type. + // back to the opaque type definition. E.g. we may have `OpaqueType` mapped to + // `(X, Y)` and `OpaqueType` mapped to `(Y, X)`, and those are the same, but we + // only know that once we convert the generic parameters to those of the opaque type. if let Some(prev) = result.get_mut(&opaque_type_key.def_id) { if prev.ty != ty { let guar = ty.error_reported().err().unwrap_or_else(|| { diff --git a/compiler/rustc_borrowck/src/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs index 141f251244b..60223807b7c 100644 --- a/compiler/rustc_borrowck/src/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -59,8 +59,8 @@ pub(super) fn check_signature_annotation(&mut self, body: &Body<'tcx>) { )), "this needs to be modified if we're lowering non-async closures" ); - // Make sure to use the args from `DefiningTy` so the right NLL region vids are prepopulated - // into the type. + // Make sure to use the args from `DefiningTy` so the right NLL region vids are + // prepopulated into the type. let args = args.as_coroutine_closure(); let tupled_upvars_ty = ty::CoroutineClosureSignature::tupled_upvars_by_closure_kind( self.tcx(), @@ -195,8 +195,9 @@ fn equate_normalized_input_or_output(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, span: // doing so ends up causing some other trouble. let b = self.normalize(b, Locations::All(span)); - // Note: if we have to introduce new placeholders during normalization above, then we won't have - // added those universes to the universe info, which we would want in `relate_tys`. + // Note: if we have to introduce new placeholders during normalization above, then we + // won't have added those universes to the universe info, which we would want in + // `relate_tys`. if let Err(terr) = self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation) { diff --git a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs index 35963228181..226a01f7c8b 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs @@ -251,7 +251,8 @@ fn add_extra_drop_facts(&mut self, relevant_live_locals: &[Local]) -> Option<()> .collect() }; - // FIXME: these locations seem to have a special meaning (e.g. everywhere, at the end, ...), but I don't know which one. Please help me rename it to something descriptive! + // FIXME: these locations seem to have a special meaning (e.g. everywhere, at the end, + // ...), but I don't know which one. Please help me rename it to something descriptive! // Also, if this IntervalSet is used in many places, it maybe should have a newtype'd // name with a description of what it means for future mortals passing by. let locations = IntervalSet::new(self.cx.elements.num_points()); diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index dffdfb8ac1d..ae403b0f4ad 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1606,9 +1606,9 @@ fn check_call_inputs( let func_ty = func.ty(body, self.infcx.tcx); if let ty::FnDef(def_id, _) = *func_ty.kind() { - // Some of the SIMD intrinsics are special: they need a particular argument to be a constant. - // (Eventually this should use const-generics, but those are not up for the task yet: - // https://github.com/rust-lang/rust/issues/85229.) + // Some of the SIMD intrinsics are special: they need a particular argument to be a + // constant. (Eventually this should use const-generics, but those are not up for the + // task yet: https://github.com/rust-lang/rust/issues/85229.) if let Some(name @ (sym::simd_shuffle | sym::simd_insert | sym::simd_extract)) = self.tcx().intrinsic(def_id).map(|i| i.name) { @@ -1921,7 +1921,8 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L if len.try_to_target_usize(tcx).is_none_or(|len| len > 1) { match operand { Operand::Copy(..) | Operand::Constant(..) => { - // These are always okay: direct use of a const, or a value that can evidently be copied. + // These are always okay: direct use of a const, or a value that can + // evidently be copied. } Operand::Move(place) => { // Make sure that repeated elements implement `Copy`. @@ -2402,9 +2403,11 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L let dst_tail = self.struct_tail(dst.ty, location); // This checks (lifetime part of) vtable validity for pointer casts, - // which is irrelevant when there are aren't principal traits on both sides (aka only auto traits). + // which is irrelevant when there are aren't principal traits on + // both sides (aka only auto traits). // - // Note that other checks (such as denying `dyn Send` -> `dyn Debug`) are in `rustc_hir_typeck`. + // Note that other checks (such as denying `dyn Send` -> `dyn + // Debug`) are in `rustc_hir_typeck`. if let ty::Dynamic(src_tty, ..) = src_tail.kind() && let ty::Dynamic(dst_tty, ..) = dst_tail.kind() && src_tty.principal().is_some() @@ -2427,8 +2430,9 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L ty::Dyn, )); - // Replace trait object lifetimes with fresh vars, to allow casts like - // `*mut dyn FnOnce() + 'a` -> `*mut dyn FnOnce() + 'static`, + // Replace trait object lifetimes with fresh vars, to allow + // casts like + // `*mut dyn FnOnce() + 'a` -> `*mut dyn FnOnce() + 'static` let src_obj = freshen_single_trait_object_lifetime(self.infcx, src_obj); let dst_obj =