11use std:: { borrow:: Cow , ops:: Deref } ;
22
33use bitflags:: bitflags;
4- use oxc_allocator :: { Allocator , CloneIn } ;
4+ use oxc_diagnostics :: Fix ;
55use oxc_span:: { GetSpan , SPAN , Span } ;
66
77bitflags ! {
@@ -268,58 +268,6 @@ impl<'a> Deref for RuleFix<'a> {
268268 }
269269}
270270
271- /// A completed, normalized fix ready to be applied to the source code.
272- ///
273- /// Used internally by this module. Lint rules should use [`RuleFix`].
274- #[ derive( Debug , Clone ) ]
275- #[ non_exhaustive]
276- pub struct Fix < ' a > {
277- pub content : Cow < ' a , str > ,
278- /// A brief suggestion message describing the fix. Will be shown in
279- /// editors via code actions.
280- pub message : Option < Cow < ' a , str > > ,
281- pub span : Span ,
282- }
283-
284- impl < ' new > CloneIn < ' new > for Fix < ' _ > {
285- type Cloned = Fix < ' new > ;
286-
287- fn clone_in ( & self , allocator : & ' new Allocator ) -> Self :: Cloned {
288- Fix {
289- content : match & self . content {
290- Cow :: Borrowed ( s) => Cow :: Borrowed ( allocator. alloc_str ( s) ) ,
291- Cow :: Owned ( s) => Cow :: Owned ( s. clone ( ) ) ,
292- } ,
293- span : self . span ,
294- message : self . message . as_ref ( ) . map ( |s| match s {
295- Cow :: Borrowed ( s) => Cow :: Borrowed ( allocator. alloc_str ( s) ) ,
296- Cow :: Owned ( s) => Cow :: Owned ( s. clone ( ) ) ,
297- } ) ,
298- }
299- }
300- }
301-
302- impl Default for Fix < ' _ > {
303- fn default ( ) -> Self {
304- Self :: empty ( )
305- }
306- }
307-
308- impl < ' a > Fix < ' a > {
309- pub const fn delete ( span : Span ) -> Self {
310- Self { content : Cow :: Borrowed ( "" ) , message : None , span }
311- }
312-
313- pub fn new < T : Into < Cow < ' a , str > > > ( content : T , span : Span ) -> Self {
314- Self { content : content. into ( ) , message : None , span }
315- }
316-
317- /// Creates a [`Fix`] that doesn't change the source code.
318- #[ inline]
319- pub const fn empty ( ) -> Self {
320- Self { content : Cow :: Borrowed ( "" ) , message : None , span : SPAN }
321- }
322- }
323271
324272// NOTE (@DonIsaac): having these variants is effectively the same as interning
325273// single or 0-element Vecs. I experimented with using smallvec here, but the
@@ -546,20 +494,14 @@ impl<'a> CompositeFix<'a> {
546494
547495 output. push_str ( after) ;
548496 output. shrink_to_fit ( ) ;
549- Fix :: new ( output, Span :: new ( start, end) )
497+ Fix :: new ( output. into ( ) , Span :: new ( start, end) )
550498 }
551499}
552500
553501#[ cfg( test) ]
554502mod test {
555503 use super :: * ;
556504
557- impl PartialEq for Fix < ' _ > {
558- fn eq ( & self , other : & Self ) -> bool {
559- self . span == other. span && self . content == other. content
560- }
561- }
562-
563505 impl Clone for CompositeFix < ' _ > {
564506 fn clone ( & self ) -> Self {
565507 match self {
@@ -617,7 +559,7 @@ mod test {
617559
618560 #[ test]
619561 fn test_composite_push_on_none ( ) {
620- let f: CompositeFix = Fix :: new ( "foo" , Span :: empty ( 4 ) ) . into ( ) ;
562+ let f: CompositeFix = Fix :: new ( "foo" . into ( ) , Span :: empty ( 4 ) ) . into ( ) ;
621563
622564 let mut none = CompositeFix :: None ;
623565 none. push ( CompositeFix :: None ) ;
@@ -635,9 +577,9 @@ mod test {
635577
636578 #[ test]
637579 fn test_composite_push_on_single ( ) {
638- let f1 = Fix :: new ( "foo" , Span :: empty ( 4 ) ) ;
639- let f2 = Fix :: new ( "bar" , Span :: empty ( 5 ) ) ;
640- let f3 = Fix :: new ( "baz" , Span :: empty ( 6 ) ) ;
580+ let f1 = Fix :: new ( "foo" . into ( ) , Span :: empty ( 4 ) ) ;
581+ let f2 = Fix :: new ( "bar" . into ( ) , Span :: empty ( 5 ) ) ;
582+ let f3 = Fix :: new ( "baz" . into ( ) , Span :: empty ( 6 ) ) ;
641583 let single = || CompositeFix :: Single ( f1. clone ( ) ) ;
642584
643585 // None.push(single) == single
@@ -650,8 +592,8 @@ mod test {
650592 assert_eq ! (
651593 f,
652594 CompositeFix :: Multiple ( vec![
653- Fix :: new( "foo" , Span :: empty( 4 ) ) ,
654- Fix :: new( "bar" , Span :: empty( 5 ) )
595+ Fix :: new( "foo" . into ( ) , Span :: empty( 4 ) ) ,
596+ Fix :: new( "bar" . into ( ) , Span :: empty( 5 ) )
655597 ] )
656598 ) ;
657599
@@ -664,9 +606,9 @@ mod test {
664606
665607 #[ test]
666608 fn test_composite_push_on_multiple ( ) {
667- let f1 = Fix :: new ( "foo" , Span :: empty ( 4 ) ) ;
668- let f2 = Fix :: new ( "bar" , Span :: empty ( 5 ) ) ;
669- let f3 = Fix :: new ( "baz" , Span :: empty ( 6 ) ) ;
609+ let f1 = Fix :: new ( "foo" . into ( ) , Span :: empty ( 4 ) ) ;
610+ let f2 = Fix :: new ( "bar" . into ( ) , Span :: empty ( 5 ) ) ;
611+ let f3 = Fix :: new ( "baz" . into ( ) , Span :: empty ( 6 ) ) ;
670612 let multiple = || CompositeFix :: Multiple ( vec ! [ f1. clone( ) , f2. clone( ) ] ) ;
671613
672614 // None.push(multiple) == multiple
0 commit comments