Open flip1995 opened 5 years ago
@flip1995 does the suggestion appear in the json output? The only situation where we hide suggestions implicitly is when span == DUMMY_SP
. There's suggestion hiding logic, but it is gated behind the API in a backwards compatible way.
Minimal example: (with rust-lang/rust-clippy#4119)
#[warn(clippy::non_ascii_literal)]
fn main() {
let _ = "Üben!";
print!("Üben!");
}
Output:
warning: literal non-ASCII character detected
--> src/main.rs:3:13
|
3 | let _ = "Üben!";
| ^^^^^^^ help: consider replacing the string with: `"\u{dc}ben!"`
|
note: lint level defined here
--> src/main.rs:1:8
|
1 | #[warn(clippy::non_ascii_literal)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_ascii_literal
warning: literal non-ASCII character detected
--> src/main.rs:4:12
|
4 | print!("Üben!");
| ^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_ascii_literal
On the non-expanded code with the &str
literal the suggestion is emitted. But when the code comes from an expansion (macro or desugaring), the suggestion is not emitted. Neither in human-readable
, nor in json
output.
In the Clippy convenience functions the span
for struct_span_lint
and span_suggestion
are exactly the same. That means, that span != DUMMY_SP
, otherwise the error message would already be empty and not only the suggestion. (?)
I think this is on purpose. We've faced multiple bugs when pointing at a span that corresponds to macros. In this case the second span points at the inside of the print
macro, so rustc
avoids showing suggestions for it. There are other recent tickets with problems caused by this. We can remove the compiler desugaring from the span and that would cause the suggestion to be emitted, but this is a situation that no matter where we settle we'll likely end up with either too few suggestions or incorrect suggestions.
In Clippy we have a convenience function for
DiagnosticBuilder::span_suggestion
: https://github.com/rust-lang/rust-clippy/blob/fd563810158425c20f27768da4ef54c54230bbbf/clippy_lints/src/utils/diagnostics.rs#L169-L177Until now we had 3 cases where the suggestion wasn't emitted: rust-lang/rust-clippy#4119, https://github.com/rust-lang/rust-clippy/pull/3582#discussion_r246656947, rust-lang/rust-clippy#3913
This issue still occurs, when replacing the convenience functions with the normal
DiagnosticBuilder
methods.Until now I couldn't figure out a pattern when or why this happens.