elem: ProjectionElem::Deref,
}) if self.mir.local_decls[*local].is_user_variable.is_some() => {
let local_decl = &self.mir.local_decls[*local];
elem: ProjectionElem::Deref,
}) if self.mir.local_decls[*local].is_user_variable.is_some() => {
let local_decl = &self.mir.local_decls[*local];
if let Some(x) = try_suggest_ampmut_rhs(
self.tcx, self.mir, *local,
) {
if let Some(x) = try_suggest_ampmut_rhs(
self.tcx, self.mir, *local,
) {
- err.span_suggestion(
- err_help_span,
- "consider changing this to be a mutable reference",
- suggested_code,
- );
+ if let Some((err_help_span, suggested_code)) = suggestion {
+ err.span_suggestion(
+ err_help_span,
+ "consider changing this to be a mutable reference",
+ suggested_code,
+ );
+ }
fn suggest_ref_mut<'cx, 'gcx, 'tcx>(
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
local_decl: &mir::LocalDecl<'tcx>,
fn suggest_ref_mut<'cx, 'gcx, 'tcx>(
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
local_decl: &mir::LocalDecl<'tcx>,
let hi_span = local_decl.source_info.span;
let hi_src = tcx.sess.codemap().span_to_snippet(hi_span).unwrap();
let hi_span = local_decl.source_info.span;
let hi_src = tcx.sess.codemap().span_to_snippet(hi_span).unwrap();
- assert!(hi_src.starts_with("ref"));
- assert!(hi_src["ref".len()..].starts_with(Pattern_White_Space));
- let suggestion = format!("ref mut{}", &hi_src["ref".len()..]);
- (hi_span, suggestion)
+ if hi_src.starts_with("ref")
+ && hi_src["ref".len()..].starts_with(Pattern_White_Space)
+ {
+ let suggestion = format!("ref mut{}", &hi_src["ref".len()..]);
+ Some((hi_span, suggestion))
+ } else {
+ None
+ }