From bfb027a50da1cd398159f09a7ce0acbf87b33eac Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Mon, 16 Dec 2024 20:24:34 +0100 Subject: [PATCH] rustc_borrowck: suggest_ampmut(): Just rename some variables By making the variable names more descriptive it becomes easier to understand the code. Especially with the more complicated code in the next commit. --- .../src/diagnostics/mutability_errors.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 4fb7b22f289..ed249555ae4 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -1474,16 +1474,16 @@ fn suggest_ampmut<'tcx>( // let x: &i32 = &'a 5; // ^^ lifetime annotation not allowed // - if let Some(assignment_rhs_span) = opt_assignment_rhs_span - && let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span) - && let Some(stripped) = src.strip_prefix('&') + if let Some(rhs_span) = opt_assignment_rhs_span + && let Ok(rhs_str) = tcx.sess.source_map().span_to_snippet(rhs_span) + && let Some(rhs_str_no_amp) = rhs_str.strip_prefix('&') { - let is_raw_ref = stripped.trim_start().starts_with("raw "); + let is_raw_ref = rhs_str_no_amp.trim_start().starts_with("raw "); // We don't support raw refs yet if is_raw_ref { return None; } - let is_mut = if let Some(rest) = stripped.trim_start().strip_prefix("mut") { + let is_mut = if let Some(rest) = rhs_str_no_amp.trim_start().strip_prefix("mut") { match rest.chars().next() { // e.g. `&mut x` Some(c) if c.is_whitespace() => true, @@ -1500,7 +1500,7 @@ fn suggest_ampmut<'tcx>( // if the reference is already mutable then there is nothing we can do // here. if !is_mut { - let span = assignment_rhs_span; + let span = rhs_span; // shrink the span to just after the `&` in `&variable` let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();