-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
bors
merged 4 commits into
rust-lang:master
from
zackmdavis:we_heard_you_the_first_time_really
Oct 31, 2016
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1bfa1d5
introing one-time diagnostics: only emit "lint level defined here" once
zackmdavis 95805ee
save a borrow by using return value of HashSet::insert
zackmdavis 8d1da84
one-time diagnostics are only one-time for humans, not JSON-eating tools
zackmdavis ef6a072
deduplicate one-time diagnostics on lint ID as well as span and message
zackmdavis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ use middle::dependency_format; | |
use session::search_paths::PathKind; | ||
use session::config::DebugInfoLevel; | ||
use ty::tls; | ||
use util::nodemap::{NodeMap, FnvHashMap}; | ||
use util::nodemap::{NodeMap, FnvHashMap, FnvHashSet}; | ||
use util::common::duration_to_secs_str; | ||
use mir::transform as mir_pass; | ||
|
||
|
@@ -75,6 +75,10 @@ pub struct Session { | |
pub working_dir: PathBuf, | ||
pub lint_store: RefCell<lint::LintStore>, | ||
pub lints: RefCell<NodeMap<Vec<(lint::LintId, Span, String)>>>, | ||
/// Set of (span, message) tuples tracking lint (sub)diagnostics that have | ||
/// been set once, but should not be set again, in order to avoid | ||
/// redundantly verbose output (Issue #24690). | ||
pub one_time_diagnostics: RefCell<FnvHashSet<(Span, String)>>, | ||
pub plugin_llvm_passes: RefCell<Vec<String>>, | ||
pub mir_passes: RefCell<mir_pass::Passes>, | ||
pub plugin_attributes: RefCell<Vec<(String, AttributeType)>>, | ||
|
@@ -288,6 +292,26 @@ impl Session { | |
pub fn diagnostic<'a>(&'a self) -> &'a errors::Handler { | ||
&self.parse_sess.span_diagnostic | ||
} | ||
|
||
/// Analogous to calling `.span_note` on the given DiagnosticBuilder, but | ||
/// deduplicates on span and message for this `Session`. | ||
// | ||
// FIXME: if the need arises for one-time diagnostics other than | ||
// `span_note`, we almost certainly want to generalize this "check the | ||
// one-time diagnostics map, then set message if it's not already there" | ||
// code to accomodate all of them | ||
pub fn diag_span_note_once<'a, 'b>(&'a self, | ||
diag_builder: &'b mut DiagnosticBuilder<'a>, | ||
span: Span, message: &str) { | ||
let span_message = (span, message.to_owned()); | ||
let already_noted: bool = self.one_time_diagnostics.borrow() | ||
.contains(&span_message); | ||
if !already_noted { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
diag_builder.span_note(span, &message); | ||
self.one_time_diagnostics.borrow_mut().insert(span_message); | ||
} | ||
} | ||
|
||
pub fn codemap<'a>(&'a self) -> &'a codemap::CodeMap { | ||
self.parse_sess.codemap() | ||
} | ||
|
@@ -561,6 +585,7 @@ pub fn build_session_(sopts: config::Options, | |
working_dir: env::current_dir().unwrap(), | ||
lint_store: RefCell::new(lint::LintStore::new()), | ||
lints: RefCell::new(NodeMap()), | ||
one_time_diagnostics: RefCell::new(FnvHashSet()), | ||
plugin_llvm_passes: RefCell::new(Vec::new()), | ||
mir_passes: RefCell::new(mir_pass::Passes::new()), | ||
plugin_attributes: RefCell::new(Vec::new()), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 =)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'm leaning towards one-per-lint (ef6a072).