@@ -18,7 +18,7 @@ pub struct LintFix {
1818 pub anchor : ErasedSegment ,
1919 /// For `replace` and `create` fixes, this holds the iterable of segments to create or replace
2020 /// at the given `anchor` point.
21- pub edit : Option < Vec < ErasedSegment > > ,
21+ pub edit : Vec < ErasedSegment > ,
2222 /// For `replace` and `create` fixes, this holds iterable of segments that provided
2323 /// code. IMPORTANT: The linter uses this to prevent copying material
2424 /// from templated areas.
@@ -29,22 +29,17 @@ impl LintFix {
2929 fn new (
3030 edit_type : EditType ,
3131 anchor : ErasedSegment ,
32- edit : Option < Vec < ErasedSegment > > ,
32+ mut edit : Vec < ErasedSegment > ,
3333 source : Option < Vec < ErasedSegment > > ,
3434 ) -> Self {
3535 // If `edit` is provided, copy all elements and strip position markers.
36- let clean_edit = if let Some ( mut edit) = edit {
37- // Developer Note: Ensure position markers are unset for all edit segments.
38- // We rely on realignment to make position markers later in the process.
39- for seg in & mut edit {
40- if seg. get_position_marker ( ) . is_some ( ) {
41- seg. make_mut ( ) . set_position_marker ( None ) ;
42- } ;
43- }
44- Some ( edit)
45- } else {
46- None
47- } ;
36+ // Developer Note: Ensure position markers are unset for all edit segments.
37+ // We rely on realignment to make position markers later in the process.
38+ for seg in & mut edit {
39+ if seg. get_position_marker ( ) . is_some ( ) {
40+ seg. make_mut ( ) . set_position_marker ( None ) ;
41+ } ;
42+ }
4843
4944 // If `source` is provided, filter segments with position markers.
5045 let clean_source = source. map_or ( Vec :: new ( ) , |source| {
@@ -57,49 +52,40 @@ impl LintFix {
5752 LintFix {
5853 edit_type,
5954 anchor,
60- edit : clean_edit ,
55+ edit,
6156 source : clean_source,
6257 }
6358 }
6459
6560 pub fn create_before ( anchor : ErasedSegment , edit_segments : Vec < ErasedSegment > ) -> Self {
66- Self :: new ( EditType :: CreateBefore , anchor, edit_segments. into ( ) , None )
61+ Self :: new ( EditType :: CreateBefore , anchor, edit_segments, None )
6762 }
6863
6964 pub fn create_after (
7065 anchor : ErasedSegment ,
7166 edit_segments : Vec < ErasedSegment > ,
7267 source : Option < Vec < ErasedSegment > > ,
7368 ) -> Self {
74- Self :: new ( EditType :: CreateAfter , anchor, edit_segments. into ( ) , source)
69+ Self :: new ( EditType :: CreateAfter , anchor, edit_segments, source)
7570 }
7671
7772 pub fn replace (
7873 anchor_segment : ErasedSegment ,
7974 edit_segments : Vec < ErasedSegment > ,
8075 source : Option < Vec < ErasedSegment > > ,
8176 ) -> Self {
82- Self :: new (
83- EditType :: Replace ,
84- anchor_segment,
85- Some ( edit_segments) ,
86- source,
87- )
77+ Self :: new ( EditType :: Replace , anchor_segment, edit_segments, source)
8878 }
8979
9080 pub fn delete ( anchor_segment : ErasedSegment ) -> Self {
91- Self :: new ( EditType :: Delete , anchor_segment, None , None )
81+ Self :: new ( EditType :: Delete , anchor_segment, Vec :: new ( ) , None )
9282 }
9383
9484 /// Return whether this a valid source only edit.
9585 pub fn is_just_source_edit ( & self ) -> bool {
96- if let Some ( edit) = & self . edit {
97- self . edit_type == EditType :: Replace
98- && edit. len ( ) == 1
99- && edit[ 0 ] . raw ( ) == self . anchor . raw ( )
100- } else {
101- false
102- }
86+ self . edit_type == EditType :: Replace
87+ && self . edit . len ( ) == 1
88+ && self . edit [ 0 ] . raw ( ) == self . anchor . raw ( )
10389 }
10490
10591 fn fix_slices (
@@ -127,15 +113,11 @@ impl LintFix {
127113 return AHashSet :: new ( ) ;
128114 } else if self
129115 . edit
130- . as_deref ( )
131- . unwrap_or ( & [ ] )
132116 . iter ( )
133117 . all ( |it| it. segments ( ) . is_empty ( ) && !it. get_source_fixes ( ) . is_empty ( ) )
134118 {
135119 let source_edit_slices: Vec < _ > = self
136120 . edit
137- . as_deref ( )
138- . unwrap_or ( & [ ] )
139121 . iter ( )
140122 . flat_map ( |edit| edit. get_source_fixes ( ) )
141123 . map ( |source_fixe| source_fixe. source_slice . clone ( ) )
@@ -185,11 +167,8 @@ impl LintFix {
185167 }
186168
187169 pub fn has_template_conflicts ( & self , templated_file : & TemplatedFile ) -> bool {
188- if self . edit_type == EditType :: Replace
189- && self . edit . is_none ( )
190- && self . edit . as_ref ( ) . unwrap ( ) . len ( ) == 1
191- {
192- let edit = & self . edit . as_ref ( ) . unwrap ( ) [ 0 ] ;
170+ if self . edit_type == EditType :: Replace && self . edit . len ( ) == 1 {
171+ let edit = & self . edit [ 0 ] ;
193172 if edit. raw ( ) == self . anchor . raw ( ) && !edit. get_source_fixes ( ) . is_empty ( ) {
194173 return false ;
195174 }
@@ -232,29 +211,18 @@ impl PartialEq for LintFix {
232211 if self . anchor . id ( ) != other. anchor . id ( ) {
233212 return false ;
234213 }
235- // Compare edits if they exist
236- if let Some ( self_edit) = & self . edit {
237- if let Some ( other_edit) = & other. edit {
238- // Check lengths
239- if self_edit. len ( ) != other_edit. len ( ) {
240- return false ;
241- }
242- // Compare raw and source_fixes for each corresponding BaseSegment
243- for ( self_base_segment, other_base_segment) in self_edit. iter ( ) . zip ( other_edit) {
244- if self_base_segment. raw ( ) != other_base_segment. raw ( )
245- || self_base_segment. get_source_fixes ( )
246- != other_base_segment. get_source_fixes ( )
247- {
248- return false ;
249- }
250- }
251- } else {
252- // self has edit, other doesn't
214+
215+ // Check lengths
216+ if self . edit . len ( ) != other. edit . len ( ) {
217+ return false ;
218+ }
219+ // Compare raw and source_fixes for each corresponding BaseSegment
220+ for ( self_base_segment, other_base_segment) in self . edit . iter ( ) . zip ( & other. edit ) {
221+ if self_base_segment. raw ( ) != other_base_segment. raw ( )
222+ || self_base_segment. get_source_fixes ( ) != other_base_segment. get_source_fixes ( )
223+ {
253224 return false ;
254225 }
255- } else if other. edit . is_some ( ) {
256- // other has edit, self doesn't
257- return false ;
258226 }
259227 // If none of the above conditions were met, objects are equal
260228 true
0 commit comments