Skip to content

Commit 54ffb7d

Browse files
committed
Leave lint priorities to rustc
1 parent f4408a1 commit 54ffb7d

File tree

3 files changed

+38
-40
lines changed

3 files changed

+38
-40
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,10 @@ fn build_base_args<'a, 'cfg>(
809809
cmd.args(args);
810810
}
811811

812-
bcx.ws.lints().set_flags(cmd, unit.pkg.manifest().lints());
812+
unit.pkg.manifest().lints().set_flags(cmd);
813+
if let Some(virtual_lints) = bcx.ws.virtual_lints() {
814+
virtual_lints.set_flags(cmd);
815+
}
813816

814817
// -C overflow-checks is implied by the setting of -C debug-assertions,
815818
// so we only need to provide -C overflow-checks if it differs from

src/cargo/core/lints.rs

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::BTreeMap;
2-
use std::collections::HashMap;
32

43
use util::{CargoResult, ProcessBuilder};
54

@@ -11,60 +10,56 @@ enum LintKind {
1110
Forbid,
1211
}
1312

13+
impl LintKind {
14+
pub fn try_from_string(lint_state: &str) -> Option<LintKind> {
15+
match lint_state.as_ref() {
16+
"allow" => Some(LintKind::Allow),
17+
"warn" => Some(LintKind::Warn),
18+
"deny" => Some(LintKind::Deny),
19+
"forbid" => Some(LintKind::Forbid),
20+
_ => None,
21+
}
22+
}
23+
24+
pub fn flag(&self) -> char {
25+
match self {
26+
LintKind::Allow => 'A',
27+
LintKind::Warn => 'W',
28+
LintKind::Deny => 'D',
29+
LintKind::Forbid => 'F',
30+
}
31+
}
32+
}
33+
1434
#[derive(Clone, Debug)]
1535
pub struct Lints {
16-
lints: HashMap<String, LintKind>,
36+
lints: Vec<(String, LintKind)>,
1737
}
1838

1939
impl Lints {
2040
pub fn new(
2141
manifest_lints: Option<&BTreeMap<String, String>>,
2242
warnings: &mut Vec<String>,
2343
) -> CargoResult<Lints> {
24-
let mut lints = HashMap::new();
44+
let mut lints = vec![];
2545
if let Some(lint_section) = manifest_lints {
2646
for (lint_name, lint_state) in lint_section.iter() {
27-
match lint_state.as_ref() {
28-
"allow" => { lints.insert(lint_name.to_string(), LintKind::Allow); },
29-
"warn" => { lints.insert(lint_name.to_string(), LintKind::Warn); },
30-
"deny" => { lints.insert(lint_name.to_string(), LintKind::Deny); },
31-
"forbid" => { lints.insert(lint_name.to_string(), LintKind::Forbid); },
32-
_ => warnings.push(format!(
47+
if let Some(state) = LintKind::try_from_string(lint_state) {
48+
lints.push((lint_name.to_string(), state));
49+
} else {
50+
warnings.push(format!(
3351
"invalid lint state for `{}` (expected `warn`, `allow`, `deny` or `forbid`)",
3452
lint_name
35-
)),
53+
));
3654
}
3755
}
3856
}
3957
Ok(Lints { lints })
4058
}
4159

42-
pub fn set_flags(&self, cmd: &mut ProcessBuilder, package_lints: &Lints) {
43-
let get_kind = |kind: LintKind| {
44-
self.lints.iter()
45-
.filter(|l| *l.1 == kind)
46-
.chain(package_lints.lints.iter()
47-
.filter(|l| *l.1 == kind && !self.lints.contains_key(l.0)))
48-
.map(|l| l.0.to_string())
49-
.collect::<Vec<String>>()
50-
.join(",")
51-
};
52-
53-
let allow = get_kind(LintKind::Allow);
54-
if !allow.is_empty() {
55-
cmd.arg("-A").arg(allow);
56-
}
57-
let warn = get_kind(LintKind::Warn);
58-
if !warn.is_empty() {
59-
cmd.arg("-W").arg(warn);
60-
}
61-
let deny = get_kind(LintKind::Deny);
62-
if !deny.is_empty() {
63-
cmd.arg("-D").arg(deny);
64-
}
65-
let forbid = get_kind(LintKind::Forbid);
66-
if !forbid.is_empty() {
67-
cmd.arg("-F").arg(forbid);
60+
pub fn set_flags(&self, cmd: &mut ProcessBuilder) {
61+
for (lint_name, state) in self.lints.iter() {
62+
cmd.arg(format!("-{}", state.flag())).arg(lint_name);
6863
}
6964
}
7065
}

src/cargo/core/workspace.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,13 @@ impl<'cfg> Workspace<'cfg> {
246246
}
247247
}
248248

249-
pub fn lints(&self) -> &Lints {
249+
pub fn virtual_lints(&self) -> Option<&Lints> {
250250
let root = self.root_manifest
251251
.as_ref()
252252
.unwrap_or(&self.current_manifest);
253253
match *self.packages.get(root) {
254-
MaybePackage::Package(ref p) => p.manifest().lints(),
255-
MaybePackage::Virtual(ref vm) => vm.lints(),
254+
MaybePackage::Virtual(ref vm) => Some(vm.lints()),
255+
_ => None,
256256
}
257257
}
258258

0 commit comments

Comments
 (0)