@@ -104,10 +104,10 @@ fn check<'tcx>(
104
104
let mut helper = SigDropHelper :: new ( cx) ;
105
105
let suggestions = helper. find_sig_drop ( scrutinee) ;
106
106
107
- for found in suggestions {
107
+ for ( i , found) in suggestions. iter ( ) . enumerate ( ) {
108
108
span_lint_and_then ( cx, SIGNIFICANT_DROP_IN_SCRUTINEE , found. found_span , message, |diag| {
109
109
match sugg {
110
- Suggestion :: Emit => set_suggestion ( diag, cx, expr, found) ,
110
+ Suggestion :: Emit => set_suggestion ( diag, cx, expr, * found, suggestions . len ( ) , i ) ,
111
111
Suggestion :: DontEmit => ( ) ,
112
112
}
113
113
@@ -121,15 +121,27 @@ fn check<'tcx>(
121
121
}
122
122
}
123
123
124
- fn set_suggestion < ' tcx > ( diag : & mut Diag < ' _ , ( ) > , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > , found : FoundSigDrop ) {
124
+ fn set_suggestion < ' tcx > (
125
+ diag : & mut Diag < ' _ , ( ) > ,
126
+ cx : & LateContext < ' tcx > ,
127
+ expr : & ' tcx Expr < ' tcx > ,
128
+ found : FoundSigDrop ,
129
+ total_sugg : usize ,
130
+ curr_sugg_idx : usize ,
131
+ ) {
125
132
let original = snippet ( cx, found. found_span , ".." ) ;
126
133
let trailing_indent = " " . repeat ( indent_of ( cx, found. found_span ) . unwrap_or ( 0 ) ) ;
127
134
128
135
let replacement = {
129
136
let ( def_part, deref_part) = if found. is_unit_return_val {
130
- ( "" , String :: new ( ) )
137
+ ( String :: new ( ) , String :: new ( ) )
138
+ } else if total_sugg == 1 {
139
+ ( "let value = " . to_string ( ) , "*" . repeat ( found. peel_ref_times ) )
131
140
} else {
132
- ( "let value = " , "*" . repeat ( found. peel_ref_times ) )
141
+ (
142
+ format ! ( "let value{} = " , curr_sugg_idx + 1 ) ,
143
+ "*" . repeat ( found. peel_ref_times ) ,
144
+ )
133
145
} ;
134
146
format ! ( "{def_part}{deref_part}{original};\n {trailing_indent}" )
135
147
} ;
@@ -143,7 +155,11 @@ fn set_suggestion<'tcx>(diag: &mut Diag<'_, ()>, cx: &LateContext<'tcx>, expr: &
143
155
let scrutinee_replacement = if found. is_unit_return_val {
144
156
"()" . to_owned ( )
145
157
} else if found. peel_ref_times == 0 {
146
- "value" . to_owned ( )
158
+ if total_sugg == 1 {
159
+ "value" . to_owned ( )
160
+ } else {
161
+ format ! ( "value{}" , curr_sugg_idx + 1 )
162
+ }
147
163
} else {
148
164
let ref_part = "&" . repeat ( found. peel_ref_times ) ;
149
165
format ! ( "({ref_part}value)" )
@@ -155,7 +171,7 @@ fn set_suggestion<'tcx>(diag: &mut Diag<'_, ()>, cx: &LateContext<'tcx>, expr: &
155
171
( first_line_of_span( cx, expr. span) . shrink_to_lo( ) , replacement) ,
156
172
( found. found_span, scrutinee_replacement) ,
157
173
] ,
158
- Applicability :: MaybeIncorrect ,
174
+ Applicability :: MachineApplicable ,
159
175
) ;
160
176
}
161
177
0 commit comments