Skip to content

Implement setting all lints to a given level #7185

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
wants to merge 1 commit into from
Closed
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
23 changes: 23 additions & 0 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub enum lint {

missing_doc,
unreachable_code,
noop,
}

pub fn level_to_str(lv: level) -> &'static str {
Expand Down Expand Up @@ -280,6 +281,13 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
desc: "detects unreachable code",
default: warn
}),

("all",
LintSpec {
lint: noop,
desc: "set all lints to a given level",
default: allow
}),
];

/*
Expand Down Expand Up @@ -326,6 +334,8 @@ struct Context {
// call can used the original visitor's method, although the recursing
// visitor supplied to the method is the item stopping visitor.
visitors: ~[(visit::vt<@mut Context>, visit::vt<@mut Context>)],
// Whether and which level to set all lints to (eg -W all)
all: Option<level>,
}

impl Context {
Expand Down Expand Up @@ -1092,6 +1102,7 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
visitors: ~[],
in_trait_impl: false,
doc_hidden: false,
all: None,
};

// Install defaults.
Expand All @@ -1101,9 +1112,21 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {

// Install command-line options, overriding defaults.
for tcx.sess.opts.lint_opts.each |&(lint, level)| {
// Allow -W all/-A all etc. The last one is the one used
if lint == noop {
cx.all = Some(level);
loop;
}
cx.set_level(lint, level, CommandLine);
}

match cx.all {
None => (),
Some(lev) => for cx.dict.each_value |spec| {
cx.set_level(spec.lint, lev, CommandLine)
}
}

// Register each of the lint passes with the context
cx.add_lint(lint_while_true());
cx.add_lint(lint_path_statement());
Expand Down