Skip to content

Commit e17ca31

Browse files
committed
rustc_borrowck: Make suggest_ampmut() return type match its use
So that it becomes easy for a later commit to return `None`.
1 parent 1f3bf23 commit e17ca31

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11501150
None
11511151
}
11521152
None => {
1153-
let (has_sugg, decl_span, sugg) = if name != kw::SelfLower {
1153+
if name != kw::SelfLower {
11541154
suggest_ampmut(
11551155
self.infcx.tcx,
11561156
local_decl.ty,
@@ -1165,7 +1165,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11651165
..
11661166
})) => {
11671167
let sugg = suggest_ampmut_self(self.infcx.tcx, decl_span);
1168-
(true, decl_span, sugg)
1168+
Some((true, decl_span, sugg, None))
11691169
}
11701170
// explicit self (eg `self: &'a Self`)
11711171
_ => suggest_ampmut(
@@ -1176,8 +1176,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11761176
opt_ty_info,
11771177
),
11781178
}
1179-
};
1180-
Some((has_sugg, decl_span, sugg, None))
1179+
}
11811180
}
11821181
}
11831182
}
@@ -1443,7 +1442,7 @@ fn suggest_ampmut<'tcx>(
14431442
decl_span: Span,
14441443
opt_assignment_rhs_span: Option<Span>,
14451444
opt_ty_info: Option<Span>,
1446-
) -> (bool, Span, String) {
1445+
) -> Option<(bool, Span, String, Option<(Span, String)>)> {
14471446
// if there is a RHS and it starts with a `&` from it, then check if it is
14481447
// mutable, and if not, put suggest putting `mut ` to make it mutable.
14491448
// we don't have to worry about lifetime annotations here because they are
@@ -1479,7 +1478,7 @@ fn suggest_ampmut<'tcx>(
14791478

14801479
// FIXME(Ezrashaw): returning is bad because we still might want to
14811480
// update the annotated type, see #106857.
1482-
return (true, span, "mut ".to_owned());
1481+
return Some((true, span, "mut ".to_owned(), None));
14831482
}
14841483
}
14851484

@@ -1504,18 +1503,18 @@ fn suggest_ampmut<'tcx>(
15041503
&& let Some(ws_pos) = src.find(char::is_whitespace)
15051504
{
15061505
let span = span.with_lo(span.lo() + BytePos(ws_pos as u32)).shrink_to_lo();
1507-
(true, span, " mut".to_owned())
1506+
Some((true, span, " mut".to_owned(), None))
15081507
// if there is already a binding, we modify it to be `mut`
15091508
} else if binding_exists {
15101509
// shrink the span to just after the `&` in `&variable`
15111510
let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();
1512-
(true, span, "mut ".to_owned())
1511+
Some((true, span, "mut ".to_owned(), None))
15131512
} else {
15141513
// otherwise, suggest that the user annotates the binding; we provide the
15151514
// type of the local.
15161515
let ty = decl_ty.builtin_deref(true).unwrap();
15171516

1518-
(false, span, format!("{}mut {}", if decl_ty.is_ref() { "&" } else { "*" }, ty))
1517+
Some((false, span, format!("{}mut {}", if decl_ty.is_ref() { "&" } else { "*" }, ty), None))
15191518
}
15201519
}
15211520

0 commit comments

Comments
 (0)