@@ -1850,22 +1850,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1850
1850
binding_mode : ty:: BindingMode :: BindByValue ( _) ,
1851
1851
opt_ty_info,
1852
1852
..
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
+ ) ) ,
1862
1860
1863
1861
Some ( ClearCrossCrate :: Set ( mir:: BindingForm :: Var ( mir:: VarBindingForm {
1864
1862
binding_mode : ty:: BindingMode :: BindByReference ( _) ,
1865
1863
..
1866
- } ) ) ) => {
1867
- suggest_ref_mut ( self . tcx , local_decl)
1868
- } ,
1864
+ } ) ) ) => suggest_ref_mut ( self . tcx , local_decl) ,
1869
1865
1870
1866
Some ( ClearCrossCrate :: Clear ) => bug ! ( "saw cleared local state" ) ,
1871
1867
@@ -1927,30 +1923,28 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1927
1923
//
1928
1924
// This implementation attempts to emulate AST-borrowck prioritization
1929
1925
// 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 > (
1932
1927
tcx : TyCtxt < ' cx , ' gcx , ' tcx > ,
1933
1928
mir : & Mir < ' tcx > ,
1934
1929
local : Local ,
1935
- ) -> Option < ( Span , String ) > {
1930
+ local_decl : & mir:: LocalDecl < ' tcx > ,
1931
+ opt_ty_info : Option < Span > ,
1932
+ ) -> ( Span , String ) {
1936
1933
let locations = mir. find_assignments ( local) ;
1937
1934
if locations. len ( ) > 0 {
1938
1935
let assignment_rhs_span = mir. source_info ( locations[ 0 ] ) . span ;
1939
1936
let snippet = tcx. sess . codemap ( ) . span_to_snippet ( assignment_rhs_span) ;
1940
1937
if let Ok ( src) = snippet {
1941
1938
if src. starts_with ( '&' ) {
1942
1939
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
+ ) ;
1944
1944
}
1945
1945
}
1946
1946
}
1947
- None
1948
- }
1949
1947
1950
- fn suggest_ampmut_type < ' tcx > (
1951
- local_decl : & mir:: LocalDecl < ' tcx > ,
1952
- opt_ty_info : Option < Span > ,
1953
- ) -> ( Span , String ) {
1954
1948
let highlight_span = match opt_ty_info {
1955
1949
// if this is a variable binding with an explicit type,
1956
1950
// try to highlight that for the suggestion.
0 commit comments