- if an == BindingAnnotation::Ref || an == BindingAnnotation::RefMut {
- // use the macro callsite when the init span (but not the whole local span)
- // comes from an expansion like `vec![1, 2, 3]` in `let ref _ = vec![1, 2, 3];`
- let sugg_init = if init.span.from_expansion() && !local.span.from_expansion() {
- Sugg::hir_with_macro_callsite(cx, init, "..")
- } else {
- Sugg::hir(cx, init, "..")
- };
- let (mutopt, initref) = if an == BindingAnnotation::RefMut {
- ("mut ", sugg_init.mut_addr())
- } else {
- ("", sugg_init.addr())
- };
- let tyopt = if let Some(ref ty) = local.ty {
- format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, ".."))
- } else {
- String::new()
- };
- span_lint_hir_and_then(
- cx,
- TOPLEVEL_REF_ARG,
- init.hir_id,
- local.pat.span,
- "`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead",
- |diag| {
- diag.span_suggestion(
- stmt.span,
- "try",
- format!(
- "let {name}{tyopt} = {initref};",
- name=snippet(cx, name.span, ".."),
- tyopt=tyopt,
- initref=initref,
- ),
- Applicability::MachineApplicable,
- );
- }
- );
- }
+ // use the macro callsite when the init span (but not the whole local span)
+ // comes from an expansion like `vec![1, 2, 3]` in `let ref _ = vec![1, 2, 3];`
+ let sugg_init = if init.span.from_expansion() && !local.span.from_expansion() {
+ Sugg::hir_with_macro_callsite(cx, init, "..")
+ } else {
+ Sugg::hir(cx, init, "..")
+ };
+ let (mutopt, initref) = if an == BindingAnnotation::RefMut {
+ ("mut ", sugg_init.mut_addr())
+ } else {
+ ("", sugg_init.addr())
+ };
+ let tyopt = if let Some(ty) = local.ty {
+ format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, ".."))
+ } else {
+ String::new()
+ };
+ span_lint_hir_and_then(
+ cx,
+ TOPLEVEL_REF_ARG,
+ init.hir_id,
+ local.pat.span,
+ "`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead",
+ |diag| {
+ diag.span_suggestion(
+ stmt.span,
+ "try",
+ format!(
+ "let {name}{tyopt} = {initref};",
+ name=snippet(cx, name.span, ".."),
+ tyopt=tyopt,
+ initref=initref,
+ ),
+ Applicability::MachineApplicable,
+ );
+ }
+ );