Skip to content

Commit f23a80a

Browse files
committedDec 17, 2024
Auto merge of #134414 - jhpratt:rollup-4gtfd1h, r=jhpratt
Rollup of 10 pull requests Successful merges: - #134202 (Remove `rustc::existing_doc_keyword` lint) - #134354 (Handle fndef rendering together with signature rendering) - #134365 (Rename `rustc_mir_build::build` to `builder`) - #134368 (Use links to edition guide for edition migrations) - #134397 (rustc_borrowck: Suggest changing `&raw const` to `&raw mut` if applicable) - #134398 (AIX: add alignment info for test) - #134400 (Fix some comments related to upvars handling) - #134406 (Fix `-Z input-stats` ordering) - #134409 (bootstrap: fix a comment) - #134412 (small borrowck cleanup) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 604d669 + cdd71c9 commit f23a80a

File tree

121 files changed

+571
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+571
-621
lines changed
 

‎Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4275,7 +4275,6 @@ dependencies = [
42754275
"rustc_fluent_macro",
42764276
"rustc_hir",
42774277
"rustc_index",
4278-
"rustc_lexer",
42794278
"rustc_macros",
42804279
"rustc_middle",
42814280
"rustc_privacy",

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,16 +1474,27 @@ fn suggest_ampmut<'tcx>(
14741474
// let x: &i32 = &'a 5;
14751475
// ^^ lifetime annotation not allowed
14761476
//
1477-
if let Some(assignment_rhs_span) = opt_assignment_rhs_span
1478-
&& let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span)
1479-
&& let Some(stripped) = src.strip_prefix('&')
1477+
if let Some(rhs_span) = opt_assignment_rhs_span
1478+
&& let Ok(rhs_str) = tcx.sess.source_map().span_to_snippet(rhs_span)
1479+
&& let Some(rhs_str_no_amp) = rhs_str.strip_prefix('&')
14801480
{
1481-
let is_raw_ref = stripped.trim_start().starts_with("raw ");
1482-
// We don't support raw refs yet
1483-
if is_raw_ref {
1484-
return None;
1481+
// Suggest changing `&raw const` to `&raw mut` if applicable.
1482+
if rhs_str_no_amp.trim_start().strip_prefix("raw const").is_some() {
1483+
let const_idx = rhs_str.find("const").unwrap() as u32;
1484+
let const_span = rhs_span
1485+
.with_lo(rhs_span.lo() + BytePos(const_idx))
1486+
.with_hi(rhs_span.lo() + BytePos(const_idx + "const".len() as u32));
1487+
1488+
return Some(AmpMutSugg {
1489+
has_sugg: true,
1490+
span: const_span,
1491+
suggestion: "mut".to_owned(),
1492+
additional: None,
1493+
});
14851494
}
1486-
let is_mut = if let Some(rest) = stripped.trim_start().strip_prefix("mut") {
1495+
1496+
// Figure out if rhs already is `&mut`.
1497+
let is_mut = if let Some(rest) = rhs_str_no_amp.trim_start().strip_prefix("mut") {
14871498
match rest.chars().next() {
14881499
// e.g. `&mut x`
14891500
Some(c) if c.is_whitespace() => true,
@@ -1500,9 +1511,8 @@ fn suggest_ampmut<'tcx>(
15001511
// if the reference is already mutable then there is nothing we can do
15011512
// here.
15021513
if !is_mut {
1503-
let span = assignment_rhs_span;
15041514
// shrink the span to just after the `&` in `&variable`
1505-
let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();
1515+
let span = rhs_span.with_lo(rhs_span.lo() + BytePos(1)).shrink_to_lo();
15061516

15071517
// FIXME(Ezrashaw): returning is bad because we still might want to
15081518
// update the annotated type, see #106857.

0 commit comments

Comments
 (0)