Skip to content

Commit 51021b1

Browse files
committed
rustc_session: allow overriding lint level of individual lints from a group
1 parent 7494250 commit 51021b1

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/librustc_session/config.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,19 +986,26 @@ pub fn get_cmd_lint_options(
986986
matches: &getopts::Matches,
987987
error_format: ErrorOutputType,
988988
) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>) {
989-
let mut lint_opts = vec![];
989+
let mut lint_opts_with_position = vec![];
990990
let mut describe_lints = false;
991991

992992
for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] {
993-
for lint_name in matches.opt_strs(level.as_str()) {
993+
for (arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) {
994994
if lint_name == "help" {
995995
describe_lints = true;
996996
} else {
997-
lint_opts.push((lint_name.replace("-", "_"), level));
997+
lint_opts_with_position.push((arg_pos, lint_name.replace("-", "_"), level));
998998
}
999999
}
10001000
}
10011001

1002+
lint_opts_with_position.sort_by_key(|x| x.0);
1003+
let lint_opts = lint_opts_with_position
1004+
.iter()
1005+
.cloned()
1006+
.map(|(_, lint_name, level)| (lint_name, level))
1007+
.collect();
1008+
10021009
let lint_cap = matches.opt_str("cap-lints").map(|cap| {
10031010
lint::Level::from_str(&cap)
10041011
.unwrap_or_else(|| early_error(error_format, &format!("unknown lint level: `{}`", cap)))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// aux-build:lint-group-plugin-test.rs
2+
// check-pass
3+
// compile-flags: -D unused -A unused-variables
4+
5+
fn main() {
6+
let x = 1;
7+
}

0 commit comments

Comments
 (0)