@@ -185,16 +185,17 @@ impl CodeSuggestion {
185
185
!invalid
186
186
} )
187
187
. cloned ( )
188
- . map ( |mut substitution| {
188
+ . filter_map ( |mut substitution| {
189
189
// Assumption: all spans are in the same file, and all spans
190
190
// are disjoint. Sort in ascending order.
191
191
substitution. parts . sort_by_key ( |part| part. span . lo ( ) ) ;
192
192
193
193
// Find the bounding span.
194
- let lo = substitution. parts . iter ( ) . map ( |part| part. span . lo ( ) ) . min ( ) . unwrap ( ) ;
195
- let hi = substitution. parts . iter ( ) . map ( |part| part. span . hi ( ) ) . max ( ) . unwrap ( ) ;
194
+ let lo = substitution. parts . iter ( ) . map ( |part| part. span . lo ( ) ) . min ( ) ? ;
195
+ let hi = substitution. parts . iter ( ) . map ( |part| part. span . hi ( ) ) . max ( ) ? ;
196
196
let bounding_span = Span :: with_root_ctxt ( lo, hi) ;
197
- let lines = cm. span_to_lines ( bounding_span) . unwrap ( ) ;
197
+ // The different spans might belong to different contexts, if so ignore suggestion.
198
+ let lines = cm. span_to_lines ( bounding_span) . ok ( ) ?;
198
199
assert ! ( !lines. lines. is_empty( ) ) ;
199
200
200
201
// To build up the result, we do this for each span:
@@ -244,7 +245,7 @@ impl CodeSuggestion {
244
245
while buf. ends_with ( '\n' ) {
245
246
buf. pop ( ) ;
246
247
}
247
- ( buf, substitution. parts , only_capitalization)
248
+ Some ( ( buf, substitution. parts , only_capitalization) )
248
249
} )
249
250
. collect ( )
250
251
}
0 commit comments