Fix position of mut in toplevel-ref-arg (fixes #1100, again)

This commit is contained in:
Manish Goregaokar
2016-07-15 19:02:41 +05:30
parent 6a20d6a5f6
commit b8c5e5a89c
2 changed files with 12 additions and 13 deletions

View File

@@ -62,29 +62,28 @@ impl LateLintPass for TopLevelRefPass {
let PatKind::Binding(BindByRef(mt), i, None) = l.pat.node,
let Some(ref init) = l.init
], {
let init = Sugg::hir(cx, init, "..");
let (mutopt,initref) = if mt == Mutability::MutMutable {
("mut ", init.mut_addr())
} else {
("", init.addr())
};
let tyopt = if let Some(ref ty) = l.ty {
format!(": &{}", snippet(cx, ty.span, "_"))
format!(": &{mutopt}{ty}", mutopt=mutopt, ty=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,
"`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead",
|db| {
let init = Sugg::hir(cx, init, "..");
db.span_suggestion(s.span,
"try",
format!("let {}{}{} = {};",
mutopt,
snippet(cx, i.span, "_"),
tyopt,
init.addr()));
format!("let {name}{tyopt} = {initref};",
name=snippet(cx, i.span, "_"),
tyopt=tyopt,
initref=initref));
}
);
}}