Skip to content

only emit "lint level defined here" the first time #34084

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,13 @@ 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);
let span_explanation = (span, explanation.to_owned());
let already_noted: bool = sess.one_time_diagnostics.borrow()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'd be nice to offer a method that encapsulates this "check-and-add" pattern rather than modifying the field directly (in general, I think it's best practice to hide a RefCell behind methods in any case, but in particular here).

For example, this code might look like:

err.span_note_once(span, explanation);

and then this method would do the check.

.contains(&span_explanation);
if !already_noted {
err.span_note(span, explanation);
sess.one_time_diagnostics.borrow_mut().insert(span_explanation);
}
}

err
Expand Down
7 changes: 6 additions & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use middle::dependency_format;
use session::search_paths::PathKind;
use session::config::{DebugInfoLevel, PanicStrategy};
use ty::tls;
use util::nodemap::{NodeMap, FnvHashMap};
use util::nodemap::{NodeMap, FnvHashMap, FnvHashSet};
use mir::transform as mir_pass;

use syntax::ast::{NodeId, NodeIdAssigner, Name};
Expand Down Expand Up @@ -70,6 +70,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.
Copy link
Contributor

Choose a reason for hiding this comment

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

not super important, but seems like a case where you could link to the issue

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)>>,
Expand Down Expand Up @@ -523,6 +527,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()),
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/lint-group-style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod test {

#[forbid(bad_style)]
//~^ NOTE lint level defined here
//~^^ NOTE lint level defined here
mod bad {
fn CamelCase() {} //~ ERROR function `CamelCase` should have a snake case name

Expand All @@ -30,7 +29,6 @@ mod test {
mod warn {
#![warn(bad_style)]
//~^ NOTE lint level defined here
//~| NOTE lint level defined here

fn CamelCase() {} //~ WARN function `CamelCase` should have a snake case name

Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/lint-no-drop-on-repr-extern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#![feature(unsafe_no_drop_flag)]
#![deny(drop_with_repr_extern)]
//~^ NOTE lint level defined here
//~| NOTE lint level defined here

#[repr(C)] struct As { x: Box<i8> }
#[repr(C)] enum Ae { Ae(Box<i8>), _None }
Expand Down
14 changes: 1 addition & 13 deletions src/test/compile-fail/lint-unconditional-recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,7 @@

#![deny(unconditional_recursion)]
//~^ NOTE lint level defined here
//~| NOTE lint level defined here
//~| NOTE lint level defined here
//~| NOTE lint level defined here
//~| NOTE lint level defined here
//~| NOTE lint level defined here
//~| NOTE lint level defined here
//~| NOTE lint level defined here
//~| NOTE lint level defined here
//~| NOTE lint level defined here
//~| NOTE lint level defined here
//~| NOTE lint level defined here
//~| NOTE lint level defined here
//~| NOTE lint level defined here

#![allow(dead_code)]
fn foo() { //~ ERROR function cannot return without recurring
foo(); //~ NOTE recursive call site
Expand Down