Skip to content

Commit b8b04f6

Browse files
committed
Put the two halves of suggest_ampmut back together
1 parent 6fd1a9f commit b8b04f6

File tree

1 file changed

+16
-22
lines changed
  • src/librustc_mir/borrow_check

1 file changed

+16
-22
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,22 +1850,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18501850
binding_mode: ty::BindingMode::BindByValue(_),
18511851
opt_ty_info,
18521852
..
1853-
}))) => {
1854-
if let Some(x) = try_suggest_ampmut_rhs(
1855-
self.tcx, self.mir, *local,
1856-
) {
1857-
Some(x)
1858-
} else {
1859-
Some(suggest_ampmut_type(local_decl, opt_ty_info))
1860-
}
1861-
},
1853+
}))) => Some(suggest_ampmut(
1854+
self.tcx,
1855+
self.mir,
1856+
*local,
1857+
local_decl,
1858+
opt_ty_info,
1859+
)),
18621860

18631861
Some(ClearCrossCrate::Set(mir::BindingForm::Var(mir::VarBindingForm {
18641862
binding_mode: ty::BindingMode::BindByReference(_),
18651863
..
1866-
}))) => {
1867-
suggest_ref_mut(self.tcx, local_decl)
1868-
},
1864+
}))) => suggest_ref_mut(self.tcx, local_decl),
18691865

18701866
Some(ClearCrossCrate::Clear) => bug!("saw cleared local state"),
18711867

@@ -1927,30 +1923,28 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
19271923
//
19281924
// This implementation attempts to emulate AST-borrowck prioritization
19291925
// by trying (3.), then (2.) and finally falling back on (1.).
1930-
1931-
fn try_suggest_ampmut_rhs<'cx, 'gcx, 'tcx>(
1926+
fn suggest_ampmut<'cx, 'gcx, 'tcx>(
19321927
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
19331928
mir: &Mir<'tcx>,
19341929
local: Local,
1935-
) -> Option<(Span, String)> {
1930+
local_decl: &mir::LocalDecl<'tcx>,
1931+
opt_ty_info: Option<Span>,
1932+
) -> (Span, String) {
19361933
let locations = mir.find_assignments(local);
19371934
if locations.len() > 0 {
19381935
let assignment_rhs_span = mir.source_info(locations[0]).span;
19391936
let snippet = tcx.sess.codemap().span_to_snippet(assignment_rhs_span);
19401937
if let Ok(src) = snippet {
19411938
if src.starts_with('&') {
19421939
let borrowed_expr = src[1..].to_string();
1943-
return Some((assignment_rhs_span, format!("&mut {}", borrowed_expr)));
1940+
return (
1941+
assignment_rhs_span,
1942+
format!("&mut {}", borrowed_expr),
1943+
);
19441944
}
19451945
}
19461946
}
1947-
None
1948-
}
19491947

1950-
fn suggest_ampmut_type<'tcx>(
1951-
local_decl: &mir::LocalDecl<'tcx>,
1952-
opt_ty_info: Option<Span>,
1953-
) -> (Span, String) {
19541948
let highlight_span = match opt_ty_info {
19551949
// if this is a variable binding with an explicit type,
19561950
// try to highlight that for the suggestion.

0 commit comments

Comments
 (0)