1
- use crate :: rustc_lint:: LintContext as _;
2
1
use clippy_utils:: diagnostics:: span_lint_and_then;
3
2
use clippy_utils:: is_from_proc_macro;
4
3
use itertools:: Itertools ;
@@ -47,7 +46,7 @@ declare_lint_pass!(RestWhenDestructuringStruct => [REST_WHEN_DESTRUCTURING_STRUC
47
46
48
47
impl < ' tcx > LateLintPass < ' tcx > for RestWhenDestructuringStruct {
49
48
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
51
50
&& !pat. span . in_external_macro ( cx. tcx . sess . source_map ( ) )
52
51
&& !is_from_proc_macro ( cx, pat)
53
52
&& let qty = cx. typeck_results ( ) . qpath_res ( & path, pat. hir_id )
@@ -65,22 +64,6 @@ impl<'tcx> LateLintPass<'tcx> for RestWhenDestructuringStruct {
65
64
. map ( |x| format ! ( "{x}: _" ) ) ;
66
65
let fmt_fields = rest_fields. join ( ", " ) ;
67
66
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
-
84
67
span_lint_and_then (
85
68
cx,
86
69
REST_WHEN_DESTRUCTURING_STRUCT ,
0 commit comments