File tree 4 files changed +32
-10
lines changed
4 files changed +32
-10
lines changed Original file line number Diff line number Diff line change @@ -253,8 +253,19 @@ impl CodeFix {
253
253
254
254
/// Applies multiple `suggestions` to the given `code`.
255
255
pub fn apply_suggestions ( code : & str , suggestions : & [ Suggestion ] ) -> Result < String , Error > {
256
+ let mut already_applied = HashSet :: new ( ) ;
256
257
let mut fix = CodeFix :: new ( code) ;
257
258
for suggestion in suggestions. iter ( ) . rev ( ) {
259
+ // This assumes that if any of the machine applicable fixes in
260
+ // a diagnostic suggestion is a duplicate, we should see the
261
+ // entire suggestion as a duplicate.
262
+ if suggestion
263
+ . solutions
264
+ . iter ( )
265
+ . any ( |sol| !already_applied. insert ( sol) )
266
+ {
267
+ continue ;
268
+ }
258
269
fix. apply ( suggestion) ?;
259
270
}
260
271
fix. finish ( )
Original file line number Diff line number Diff line change 5
5
6
6
macro_rules! foo {
7
7
( $x: ident) => {
8
- pub unsafe fn $x( ) { unsafe { unsafe {
8
+ pub unsafe fn $x( ) { unsafe {
9
9
let _ = String :: new( ) . as_mut_vec( ) ;
10
- } } }
10
+ } }
11
11
} ;
12
12
}
13
13
Original file line number Diff line number Diff line change @@ -735,12 +735,23 @@ fn rustfix_and_fix(
735
735
} ) ;
736
736
let mut fixed = CodeFix :: new ( & code) ;
737
737
738
- // As mentioned above in `rustfix_crate`, we don't immediately warn
739
- // about suggestions that fail to apply here, and instead we save them
740
- // off for later processing.
738
+ let mut already_applied = HashSet :: new ( ) ;
741
739
for suggestion in suggestions. iter ( ) . rev ( ) {
740
+ // This assumes that if any of the machine applicable fixes in
741
+ // a diagnostic suggestion is a duplicate, we should see the
742
+ // entire suggestion as a duplicate.
743
+ if suggestion
744
+ . solutions
745
+ . iter ( )
746
+ . any ( |sol| !already_applied. insert ( sol) )
747
+ {
748
+ continue ;
749
+ }
742
750
match fixed. apply ( suggestion) {
743
751
Ok ( ( ) ) => fixed_file. fixes_applied += 1 ,
752
+ // As mentioned above in `rustfix_crate`, we don't immediately
753
+ // warn about suggestions that fail to apply here, and instead
754
+ // we save them off for later processing.
744
755
Err ( e) => fixed_file. errors_applying_fixes . push ( e. to_string ( ) ) ,
745
756
}
746
757
}
Original file line number Diff line number Diff line change @@ -1924,21 +1924,21 @@ fn fix_only_once_for_duplicates() {
1924
1924
. build ( ) ;
1925
1925
1926
1926
p. cargo ( "fix --allow-no-vcs" )
1927
- . with_stderr_contains (
1927
+ . with_stderr (
1928
1928
"\
1929
1929
[CHECKING] foo v0.0.1 ([CWD])
1930
- [FIXED] src/lib.rs (2 fixes)
1930
+ [FIXED] src/lib.rs (1 fix)
1931
+ [FINISHED] `dev` profile [..]
1931
1932
" ,
1932
1933
)
1933
- . with_stderr_contains ( "[WARNING] unnecessary `unsafe` block[..]" )
1934
1934
. run ( ) ;
1935
1935
1936
1936
assert_eq ! (
1937
1937
p. read_file( "src/lib.rs" ) . matches( "unsafe" ) . count( ) ,
1938
- 5 ,
1938
+ 4 ,
1939
1939
"unsafe keyword in src/lib.rs:\n \
1940
1940
2 in lint name;\n \
1941
1941
1 from original unsafe fn;\n \
1942
- 2 from newly-applied unsafe blocks"
1942
+ 1 from newly-applied unsafe blocks"
1943
1943
) ;
1944
1944
}
You can’t perform that action at this time.
0 commit comments