Merge pull request #1101 from Manishearth/fix-1100
Suggest mutability and fix type in toplevel-ref-arg
This commit is contained in:
commit
6a20d6a5f6
@ -59,14 +59,19 @@ impl LateLintPass for TopLevelRefPass {
|
||||
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,
|
||||
@ -75,7 +80,8 @@ impl LateLintPass for TopLevelRefPass {
|
||||
let init = Sugg::hir(cx, init, "..");
|
||||
db.span_suggestion(s.span,
|
||||
"try",
|
||||
format!("let {}{} = {};",
|
||||
format!("let {}{}{} = {};",
|
||||
mutopt,
|
||||
snippet(cx, i.span, "_"),
|
||||
tyopt,
|
||||
init.addr()));
|
||||
|
@ -23,13 +23,18 @@ fn main() {
|
||||
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user