-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filtering spans when emitting json #102922
Conversation
r? @oli-obk (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
Could we solve this at the time of registering the suggestion? I would hope we could just add a debug assertion and avoid ever having these suggestions at all. Basically check this in |
@oli-obk I have added the assertions for the debug build. I also changed the condition to avoid the emitting of the second suggestion. |
@@ -699,6 +699,11 @@ impl Diagnostic { | |||
style: SuggestionStyle, | |||
) -> &mut Self { | |||
assert!(!suggestion.is_empty()); | |||
debug_assert!( | |||
!(suggestion.iter().any(|(sp, text)| sp.lo() == sp.hi() && text.is_empty())), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's Span::is_empty
I think
This comment has been minimized.
This comment has been minimized.
Why only a debug assert? Performance doesn't matter for diagnostics. |
because I don't want to start crashing people's compiler. Maybe we could make it a full assert on nightly or sth. |
CI seems to have found more cases of such suggestions |
46e051b
to
4f48fc1
Compare
I am not quite sure how to do this. Is there already something for that or should I create a new macro? |
UnaryFixity::Pre => self.prefix_inc_dec_suggest(base_src, kind, spans), | ||
UnaryFixity::Post => self.postfix_inc_dec_suggest(base_src, kind, spans), | ||
}; | ||
let sugg2 = self.inc_dec_standalone_suggest(kind, spans); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some useful suggestions are now missing. Maybe check here for emptyness and avoid adding it only then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am checking the pre_span
which might have the empty span before adding it in inc_dec_standalone_suggest
.
if !pre_span.is_empty() {
patches.push((pre_span, String::new()));
}
4f48fc1
to
9e2c2a5
Compare
Could this check be expanded from "don't replace empty with empty" to "don't replace any string with the same string"? |
That's ok I think we should just stick with the debug assert for now |
That may be annoying to thread through. We don't always have access to the source map. But definitely something to explore. @bors r+ rollup |
… r=oli-obk Filtering spans when emitting json According to the issue rust-lang#102902, we shouldn't emit spans which have an empty span and no suggested replacement.
Failed in rollup: #103184 (comment) |
Ah looks like clippy also has such suggestions. You can run the clippy tests with |
9e2c2a5
to
2b495d2
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
Thanks this lgtm now. Please squash your commits as they contain a lot of back and forth now. |
3e6f1fb
to
28d0312
Compare
@oli-obk thank you for your quick reviews! I have rebased it. |
@bors r+ rollup |
Rollup of 6 pull requests Successful merges: - rust-lang#102287 (Elaborate supertrait bounds when triggering `unused_must_use` on `impl Trait`) - rust-lang#102922 (Filtering spans when emitting json) - rust-lang#103051 (translation: doc comments with derives, subdiagnostic-less enum variants, more derive use) - rust-lang#103111 (Account for hygiene in typo suggestions, and use them to point to shadowed names) - rust-lang#103260 (Fixup a few tests needing asm support) - rust-lang#103321 (rustdoc: improve appearance of source page navigation bar) Failed merges: - rust-lang#103209 (Diagnostic derives: allow specifying multiple alternative suggestions) r? `@ghost` `@rustbot` modify labels: rollup
… r=oli-obk Filtering spans when emitting json According to the issue rust-lang#102902, we shouldn't emit spans which have an empty span and no suggested replacement.
Rollup of 6 pull requests Successful merges: - rust-lang#102287 (Elaborate supertrait bounds when triggering `unused_must_use` on `impl Trait`) - rust-lang#102922 (Filtering spans when emitting json) - rust-lang#103051 (translation: doc comments with derives, subdiagnostic-less enum variants, more derive use) - rust-lang#103111 (Account for hygiene in typo suggestions, and use them to point to shadowed names) - rust-lang#103260 (Fixup a few tests needing asm support) - rust-lang#103321 (rustdoc: improve appearance of source page navigation bar) Failed merges: - rust-lang#103209 (Diagnostic derives: allow specifying multiple alternative suggestions) r? `@ghost` `@rustbot` modify labels: rollup
According to the issue #102902, we shouldn't emit spans which have an empty span and no suggested replacement.