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

introing one-time diagnostics: only emit "lint level defined here" once #37191

Merged
merged 4 commits into from
Oct 31, 2016

Conversation

zackmdavis
Copy link
Member

This is a revised resubmission of PR #34084 (which was closed due to inactivity on account of time constraints on the author's part).


We introduce a new one_time_diagnostics field on
rustc::session::Session to hold a hashset of diagnostic messages we've
set once but don't want to see again (as uniquified by span and message
text), "lint level defined here" being the motivating example dealt with
here.

This is in the matter of #24690.


r? @nikomatsakis

We introduce a new `one_time_diagnostics` field on
`rustc::session::Session` to hold a hashset of diagnostic messages we've
set once but don't want to see again (as uniquified by span and message
text), "lint level defined here" being the motivating example dealt with
here.

This is in the matter of rust-lang#24690.
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good -- my main question is whether we want one message per span or one per lint-kind.

let span_message = (span, message.to_owned());
let already_noted: bool = self.one_time_diagnostics.borrow()
.contains(&span_message);
if !already_noted {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you can write

let fresh = self.one_time_diagnostics.borrow_mut().insert(&span_message);
if fresh {
    diag_builder.span_note(span, &message);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -452,8 +452,7 @@ pub fn raw_struct_lint<'a>(sess: &'a Session,
}

if let Some(span) = def {
let explanation = "lint level defined here";
err.span_note(span, &explanation);
sess.diag_span_note_once(&mut err, span, "lint level defined here");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. So the key is the span+message, but it's possible that the level for many lints is set at one point (e.g., #[allow(warnings)]). Do we want to issue one note per kind of lint, or just one per span? I'm actually not sure =)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning towards one-per-lint (ef6a072).

@nikomatsakis
Copy link
Contributor

@zackmdavis another point, raised by @jonathandturner, is that if we are emitting in json mode, we probably want to include the duplicates

Thanks to Niko Matsakis's review for the suggestion.
Jonathan D. Turner pointed out that we don't want to dedup in JSON
mode. Since the compile-test runner uses JSON output, we regrettably
need to revert the edits to existing tests; one imagines that testing
for one-time diagnosticity for humans will have to be added as a UI
test.

This remains in the matter of rust-lang#24690.
Some lint-level attributes (like `bad-style`, or, more dramatically,
`warnings`) can affect more than one lint; it seems fairer to point out
the attribute once for each distinct lint affected. Also, a UI test is
added. This remains in the matter of rust-lang#24690.
@zackmdavis
Copy link
Member Author

@nikomatsakis Not-deduping in JSON mode is implemented in 8d1da84; unfortunately, this means the change in behavior can no longer be detected by the compile-fail tests, but ef6a072 adds a UI test to compensate.

@nikomatsakis
Copy link
Contributor

@zackmdavis looks great! thanks =)

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Oct 31, 2016

📌 Commit ef6a072 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Oct 31, 2016

⌛ Testing commit ef6a072 with merge 349394e...

@alexcrichton
Copy link
Member

@bors: retry force clean

  • restarted buildbot

@bors
Copy link
Contributor

bors commented Oct 31, 2016

⌛ Testing commit ef6a072 with merge f26eedb...

bors added a commit that referenced this pull request Oct 31, 2016
… r=nikomatsakis

introing one-time diagnostics: only emit "lint level defined here" once

This is a revised resubmission of PR #34084 (which was closed due to inactivity on account of time constraints on the author's part).
---

We introduce a new `one_time_diagnostics` field on
`rustc::session::Session` to hold a hashset of diagnostic messages we've
set once but don't want to see again (as uniquified by span and message
text), "lint level defined here" being the motivating example dealt with
here.

This is in the matter of #24690.
---

r? @nikomatsakis
@bors bors merged commit ef6a072 into rust-lang:master Oct 31, 2016
@zackmdavis zackmdavis deleted the we_heard_you_the_first_time_really branch January 13, 2018 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants