- self.ir.tcx.struct_span_lint_hir(
- lint::builtin::UNUSED_VARIABLES,
- first_hir_id,
- hir_ids_and_spans.iter().map(|(_, sp)| *sp).collect::<Vec<_>>(),
- |lint| {
- let mut err = lint.build(&format!("unused variable: `{}`", name));
-
- let (shorthands, non_shorthands): (Vec<_>, Vec<_>) =
- hir_ids_and_spans.into_iter().partition(|(hir_id, span)| {
- let var = self.variable(*hir_id, *span);
- self.ir.variable_is_shorthand(var)
- });
-
- let mut shorthands = shorthands
- .into_iter()
- .map(|(_, span)| (span, format!("{}: _", name)))
- .collect::<Vec<_>>();
-
- // If we have both shorthand and non-shorthand, prefer the "try ignoring
- // the field" message, and suggest `_` for the non-shorthands. If we only
- // have non-shorthand, then prefix with an underscore instead.
- if !shorthands.is_empty() {
- shorthands.extend(
- non_shorthands
- .into_iter()
- .map(|(_, span)| (span, "_".to_string()))
- .collect::<Vec<_>>(),
- );
+ let (shorthands, non_shorthands): (Vec<_>, Vec<_>) =
+ hir_ids_and_spans.iter().copied().partition(|(hir_id, _, ident_span)| {
+ let var = self.variable(*hir_id, *ident_span);
+ self.ir.variable_is_shorthand(var)
+ });