Change:
I got this error message recently: will work, but just removing completely from the pattern would be better. E.g. the suggestion could be . The particular example was within rustc, but it should be very easy to replicate in a self-contained example. <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOT_END --
Is this ? Where does this suggestion come from? Can I please get the path for it!
claim
It's been 3 months - are you still working on this? If not, I'd like to claim it instead.
There was no activity for a while, so I took a liberty of implementing this. claim

Discussion:
use rustc_middle::ty::{self, DefIdTree, RootVariableMinCaptureList, Ty, TyCtxt}; use rustc_session::lint; use rustc_span::symbol::{kw, sym, Symbol}; <del> use rustc_span::Span; </del> <ins> use rustc_span::{BytePos, Span}; </ins> use std::collections::VecDeque; use std::io;

.or_insert_with(|| (ln, var, vec![id_and_sp])); }); <ins> let can_remove = matches!(&pat.kind, hir::PatKind::Struct(_, _, true)); </ins> for (_, (ln, var, hir_ids_and_spans)) in vars { if self.used_on_entry(ln, var) { let id = hir_ids_and_spans[0].0;

hir_ids_and_spans.into_iter().map(|(_, _, ident_span)| ident_span).collect(); on_used_on_entry(spans, id, ln, var); } else { <del> self.report_unused(hir_ids_and_spans, ln, var); </del> <ins> self.report_unused(hir_ids_and_spans, ln, var, can_remove); </ins> } } } <ins> #[tracing::instrument(skip(self), level = "INFO")] </ins> fn report_unused( &self, hir_ids_and_spans: Vec<(HirId, Span, Span)>, ln: LiveNode, var: Variable, <ins> can_remove: bool, </ins> ) { let first_hir_id = hir_ids_and_spans[0].0;

.emit(); }, ) <ins> } else if can_remove { self.ir.tcx.struct_span_lint_hir( lint::builtin::UNUSED_VARIABLES, first_hir_id, hir_ids_and_spans.iter().map(|(_, pat_span, _)| *pat_span).collect::<Vec<_>>(), |lint| { let mut err = lint.build(&format!("unused variable: `{}`", name)); err.multipart_suggestion( "try removing the field", hir_ids_and_spans .iter() .map(|(_, pat_span, _)| { let span = self .ir .tcx .sess .source_map() .span_extend_to_next_char(*pat_span, ',', true); (span.with_hi(BytePos(span.hi().0 + 1)), String::new()) }) .collect(), Applicability::MachineApplicable, ); err.emit(); }, ); </ins> } else { let (shorthands, non_shorthands): (Vec<_>, Vec<_>) = hir_ids_and_spans.iter().copied().partition(|(hir_id, _, ident_span)| {

}) } <del> /// Extends the given `Span` to just after the next occurrence of `c`. </del> <ins> /// Extends the given `Span` to just before the next occurrence of `c`. </ins> pub fn span_extend_to_next_char(&self, sp: Span, c: char, accept_newlines: bool) -> Span { if let Ok(next_source) = self.span_to_next_source(sp) { let next_source = next_source.split(c).next().unwrap_or("");

<ins> // run-pass #![allow(dead_code)] struct Foo { foo: i32, bar: i32, baz: (), } fn use_foo(x: Foo) -> (i32, i32) { let Foo { foo, bar, baz } = x; //~ WARNING unused variable: `baz` //~| help: try ignoring the field return (foo, bar); } fn main() {} </ins>

<ins> warning: unused variable: `baz` --> $DIR/dont-try-removing-the-field.rs:12:25 | LL |     let Foo { foo, bar, baz } = x; |                         ^^^ help: try ignoring the field: `baz: _` | = note: `#[warn(unused_variables)]` on by default warning: 1 warning emitted </ins>

<ins> // run-pass #![allow(dead_code)] struct Foo { foo: i32, bar: (), baz: (), } fn use_foo(x: Foo) -> i32 { let Foo { foo, bar, .. } = x; //~ WARNING unused variable: `bar` //~| help: try removing the field return foo; } fn main() {} </ins>

<ins> warning: unused variable: `bar` --> $DIR/try-removing-the-field.rs:12:20 | LL |     let Foo { foo, bar, .. } = x; |                    ^^^- |                    | |                    help: try removing the field | = note: `#[warn(unused_variables)]` on by default warning: 1 warning emitted </ins>