Use utils::sugg
in TOPLEVEL_REF_ARG
This commit is contained in:
parent
a3c505551f
commit
7023988020
3 changed files with 14 additions and 3 deletions
|
@ -72,12 +72,13 @@ impl LateLintPass for TopLevelRefPass {
|
|||
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 {}{} = &{};",
|
||||
format!("let {}{} = {};",
|
||||
snippet(cx, i.span, "_"),
|
||||
tyopt,
|
||||
snippet(cx, init.span, "_")));
|
||||
init.addr()));
|
||||
}
|
||||
);
|
||||
}}
|
||||
|
|
|
@ -114,6 +114,11 @@ impl<'a> Sugg<'a> {
|
|||
pub fn and(&self, rhs: &Self) -> Sugg<'static> {
|
||||
make_binop(ast::BinOpKind::And, self, rhs)
|
||||
}
|
||||
|
||||
/// Convenience method to create the `&<expr>` suggestion.
|
||||
pub fn addr(&self) -> Sugg<'static> {
|
||||
make_unop("&", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> std::ops::Sub<&'b Sugg<'b>> for &'a Sugg<'a> {
|
||||
|
|
|
@ -20,11 +20,16 @@ fn main() {
|
|||
//~| HELP try
|
||||
//~| SUGGESTION let x = &1;
|
||||
|
||||
let ref y : (&_, u8) = (&1, 2);
|
||||
let ref y: (&_, u8) = (&1, 2);
|
||||
//~^ ERROR `ref` on an entire `let` pattern is discouraged
|
||||
//~| HELP try
|
||||
//~| 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 x, _) = (1,2); // okay, not top level
|
||||
println!("The answer is {}.", x);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue