if_let_chain! {[
let StmtDecl(ref d, _) = s.node,
let DeclLocal(ref l) = d.node,
- let PatKind::Binding(BindByRef(_), i, None) = l.pat.node,
+ let PatKind::Binding(BindByRef(mt), i, None) = l.pat.node,
let Some(ref init) = l.init
], {
let tyopt = if let Some(ref ty) = l.ty {
- format!(": {}", snippet(cx, ty.span, "_"))
+ format!(": &{}", snippet(cx, ty.span, "_"))
} else {
"".to_owned()
};
+ let mutopt = if mt == Mutability::MutMutable {
+ "mut "
+ } else {
+ ""
+ };
span_lint_and_then(cx,
TOPLEVEL_REF_ARG,
l.pat.span,
let init = Sugg::hir(cx, init, "..");
db.span_suggestion(s.span,
"try",
- format!("let {}{} = {};",
+ format!("let {}{}{} = {};",
+ mutopt,
snippet(cx, i.span, "_"),
tyopt,
init.addr()));
let ref y: (&_, u8) = (&1, 2);
//~^ ERROR `ref` on an entire `let` pattern is discouraged
//~| HELP try
- //~| SUGGESTION let y: (&_, u8) = &(&1, 2);
+ //~| SUGGESTION let y: &(&_, u8) = &(&1, 2);
let ref z = 1 + 2;
//~^ ERROR `ref` on an entire `let` pattern is discouraged
//~| HELP try
//~| SUGGESTION let z = &(1 + 2);
+ let ref mut z = 1 + 2;
+ //~^ ERROR `ref` on an entire `let` pattern is discouraged
+ //~| HELP try
+ //~| SUGGESTION let mut z = &(1 + 2);
+
let (ref x, _) = (1,2); // okay, not top level
println!("The answer is {}.", x);
}