@@ -2014,12 +2014,52 @@ impl HumanEmitter {
2014
2014
debug ! ( ?suggestions) ;
2015
2015
2016
2016
if suggestions. is_empty ( ) {
2017
- // Here we check if there are suggestions that have actual code changes. We sometimes
2018
- // suggest the same code that is already there, instead of changing how we produce the
2019
- // suggestions and filtering there, we just don't emit the suggestion.
2020
- // Suggestions coming from macros can also have malformed spans. This is a heavy handed
2021
- // approach to avoid ICEs by ignoring the suggestion outright.
2022
- return Ok ( ( ) ) ;
2017
+ // Check if this is because source file is unavailable
2018
+ let has_unavailable_source =
2019
+ suggestion. substitutions . iter ( ) . flat_map ( |sub| & sub. parts ) . any ( |part| {
2020
+ if let Ok ( lines) = sm. span_to_lines ( part. span ) {
2021
+ !sm. ensure_source_file_source_present ( & lines. file )
2022
+ } else {
2023
+ false
2024
+ }
2025
+ } ) ;
2026
+ // Only when source unavailable, use the original suggestion spans for proper location display
2027
+ if has_unavailable_source {
2028
+ // When source is unavailable, use the original suggestion spans for proper location display
2029
+ let suggestion_span = if !suggestion. substitutions . is_empty ( ) {
2030
+ // Use the span from the first substitution part
2031
+ let parts: Vec < _ > = suggestion
2032
+ . substitutions
2033
+ . iter ( )
2034
+ . flat_map ( |sub| & sub. parts )
2035
+ . map ( |part| part. span )
2036
+ . collect ( ) ;
2037
+ if !parts. is_empty ( ) { MultiSpan :: from_spans ( parts) } else { span. clone ( ) }
2038
+ } else {
2039
+ span. clone ( )
2040
+ } ;
2041
+
2042
+ return self . emit_messages_default_inner (
2043
+ & suggestion_span,
2044
+ & [ ( suggestion. msg . to_owned ( ) , Style :: HeaderMsg ) ] ,
2045
+ args,
2046
+ & None ,
2047
+ level,
2048
+ max_line_num_len,
2049
+ true ,
2050
+ false ,
2051
+ ) ;
2052
+ } else {
2053
+ // If source is available but suggestions are empty
2054
+ // this is because of some reason in `splice_lines`, skip
2055
+ //
2056
+ // Here we check if there are suggestions that have actual code changes.
2057
+ // We sometimes suggest the same code that is already there, instead of changing how we produce the
2058
+ // suggestions and filtering there, we just don't emit the suggestion.
2059
+ // Suggestions coming from macros can also have malformed spans. This is a heavy handed
2060
+ // approach to avoid ICEs by ignoring the suggestion outright.
2061
+ return Ok ( ( ) ) ;
2062
+ }
2023
2063
}
2024
2064
2025
2065
let mut buffer = StyledBuffer :: new ( ) ;
0 commit comments