elem: ProjectionElem::Deref,
}) if self.mir.local_decls[*local].is_user_variable.is_some() => {
let local_decl = &self.mir.local_decls[*local];
- let (err_help_span, suggested_code) = match local_decl.is_user_variable {
+ let suggestion = match local_decl.is_user_variable {
Some(ClearCrossCrate::Set(mir::BindingForm::ImplicitSelf)) => {
- suggest_ampmut_self(local_decl)
+ Some(suggest_ampmut_self(local_decl))
},
Some(ClearCrossCrate::Set(mir::BindingForm::Var(mir::VarBindingForm {
if let Some(x) = try_suggest_ampmut_rhs(
self.tcx, self.mir, *local,
) {
- x
+ Some(x)
} else {
- suggest_ampmut_type(local_decl, opt_ty_info)
+ Some(suggest_ampmut_type(local_decl, opt_ty_info))
}
},
None => bug!(),
};
- 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,
+ );
+ }
if let Some(name) = local_decl.name {
err.span_label(
fn suggest_ref_mut<'cx, 'gcx, 'tcx>(
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
local_decl: &mir::LocalDecl<'tcx>,
- ) -> (Span, String) {
+ ) -> Option<(Span, String)> {
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
+ }
}
}
--> $DIR/enum.rs:19:5
|
LL | *x += 1; //~ ERROR cannot assign to immutable
- | ^^^^^^^ cannot assign
+ | ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written
error[E0594]: cannot assign to `*x` which is behind a `&` reference
--> $DIR/enum.rs:23:9
|
LL | *x += 1; //~ ERROR cannot assign to immutable
- | ^^^^^^^ cannot assign
+ | ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written
error[E0594]: cannot assign to `*x` which is behind a `&` reference
--> $DIR/enum.rs:29:9
|
LL | *x += 1; //~ ERROR cannot assign to immutable
- | ^^^^^^^ cannot assign
+ | ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written
error: aborting due to 3 previous errors
--> $DIR/explicit-mut.rs:17:13
|
LL | *n += 1; //~ ERROR cannot assign to immutable
- | ^^^^^^^ cannot assign
+ | ^^^^^^^ `n` is a `&` reference, so the data it refers to cannot be written
error[E0594]: cannot assign to `*n` which is behind a `&` reference
--> $DIR/explicit-mut.rs:25:13
|
LL | *n += 1; //~ ERROR cannot assign to immutable
- | ^^^^^^^ cannot assign
+ | ^^^^^^^ `n` is a `&` reference, so the data it refers to cannot be written
error[E0594]: cannot assign to `*n` which is behind a `&` reference
--> $DIR/explicit-mut.rs:33:13
|
LL | *n += 1; //~ ERROR cannot assign to immutable
- | ^^^^^^^ cannot assign
+ | ^^^^^^^ `n` is a `&` reference, so the data it refers to cannot be written
error: aborting due to 3 previous errors