Skip to content
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

Merged
merged 1 commit into from
Oct 21, 2022

Conversation

kper
Copy link
Contributor

@kper kper commented Oct 11, 2022

According to the issue #102902, we shouldn't emit spans which have an empty span and no suggested replacement.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 11, 2022
@rust-highfive
Copy link
Collaborator

r? @oli-obk

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 11, 2022
@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented Oct 11, 2022

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 span_suggestion and either don't register anything (in release mode) or panic (in debug mode).

@kper
Copy link
Contributor Author

kper commented Oct 11, 2022

@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())),
Copy link
Member

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

@rust-log-analyzer

This comment has been minimized.

@jyn514
Copy link
Member

jyn514 commented Oct 12, 2022

Why only a debug assert? Performance doesn't matter for diagnostics.

@oli-obk
Copy link
Contributor

oli-obk commented Oct 12, 2022

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.

@oli-obk
Copy link
Contributor

oli-obk commented Oct 12, 2022

CI seems to have found more cases of such suggestions

@kper kper force-pushed the bugfix/102902-filtering-json branch from 46e051b to 4f48fc1 Compare October 13, 2022 16:05
@kper
Copy link
Contributor Author

kper commented Oct 13, 2022

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.

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);
Copy link
Contributor

@oli-obk oli-obk Oct 15, 2022

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

Copy link
Contributor Author

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()));
}

@kper kper force-pushed the bugfix/102902-filtering-json branch from 4f48fc1 to 9e2c2a5 Compare October 15, 2022 14:07
@jruderman
Copy link
Contributor

Could this check be expanded from "don't replace empty with empty" to "don't replace any string with the same string"?

@oli-obk
Copy link
Contributor

oli-obk commented Oct 18, 2022

I am not quite sure how to do this. I

That's ok I think we should just stick with the debug assert for now

@oli-obk
Copy link
Contributor

oli-obk commented Oct 18, 2022

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

@bors
Copy link
Contributor

bors commented Oct 18, 2022

📌 Commit 9e2c2a5 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 18, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 18, 2022
… 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.
@JohnTitor
Copy link
Member

Failed in rollup: #103184 (comment)
@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 18, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Oct 18, 2022

Ah looks like clippy also has such suggestions. You can run the clippy tests with ./x.py test src/tools/clippy

@kper kper force-pushed the bugfix/102902-filtering-json branch from 9e2c2a5 to 2b495d2 Compare October 20, 2022 06:13
@rustbot
Copy link
Collaborator

rustbot commented Oct 20, 2022

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@oli-obk
Copy link
Contributor

oli-obk commented Oct 20, 2022

Thanks this lgtm now.

Please squash your commits as they contain a lot of back and forth now.

@kper kper force-pushed the bugfix/102902-filtering-json branch from 3e6f1fb to 28d0312 Compare October 20, 2022 08:58
@kper
Copy link
Contributor Author

kper commented Oct 21, 2022

@oli-obk thank you for your quick reviews! I have rebased it.

@oli-obk
Copy link
Contributor

oli-obk commented Oct 21, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Oct 21, 2022

📌 Commit 28d0312 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 21, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 21, 2022
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
@bors bors merged commit 0a0e9f7 into rust-lang:master Oct 21, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 21, 2022
flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 21, 2022
… 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.
flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 21, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants