1- use crate :: rustc_lint:: LintContext as _;
21use clippy_utils:: diagnostics:: span_lint_and_then;
32use clippy_utils:: is_from_proc_macro;
43use itertools:: Itertools ;
@@ -47,7 +46,7 @@ declare_lint_pass!(RestWhenDestructuringStruct => [REST_WHEN_DESTRUCTURING_STRUC
4746
4847impl < ' tcx > LateLintPass < ' tcx > for RestWhenDestructuringStruct {
4948 fn check_pat ( & mut self , cx : & rustc_lint:: LateContext < ' tcx > , pat : & ' tcx rustc_hir:: Pat < ' tcx > ) {
50- if let rustc_hir:: PatKind :: Struct ( path, fields, true ) = pat. kind
49+ if let rustc_hir:: PatKind :: Struct ( path, fields, Some ( dotdot ) ) = pat. kind
5150 && !pat. span . in_external_macro ( cx. tcx . sess . source_map ( ) )
5251 && !is_from_proc_macro ( cx, pat)
5352 && let qty = cx. typeck_results ( ) . qpath_res ( & path, pat. hir_id )
@@ -65,22 +64,6 @@ impl<'tcx> LateLintPass<'tcx> for RestWhenDestructuringStruct {
6564 . map ( |x| format ! ( "{x}: _" ) ) ;
6665 let fmt_fields = rest_fields. join ( ", " ) ;
6766
68- let sm = cx. sess ( ) . source_map ( ) ;
69-
70- // It is not possible to get the span of the et cetera symbol at HIR level
71- // so we have to get it in a bit of a roundabout way:
72-
73- // Find the end of the last field if any.
74- let last_field = fields. iter ( ) . last ( ) . map ( |x| x. span . shrink_to_hi ( ) ) ;
75- // If no last field take the whole pattern.
76- let last_field = last_field. unwrap_or ( pat. span . shrink_to_lo ( ) ) ;
77- // Create a new span starting and ending just before the first .
78- let before_dot = sm. span_extend_to_next_char ( last_field, '.' , true ) . shrink_to_hi ( ) ;
79- // Extend the span to the end of the line
80- let rest_of_line = sm. span_extend_to_next_char ( before_dot, '\n' , true ) ;
81- // Shrink the span so it only contains dots
82- let dotdot = sm. span_take_while ( rest_of_line, |x| * x == '.' ) ;
83-
8467 span_lint_and_then (
8568 cx,
8669 REST_WHEN_DESTRUCTURING_STRUCT ,
0 commit comments