Skip to content

Commit

Permalink
Leave lint priorities to rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
detrumi committed Sep 21, 2018
1 parent f4408a1 commit 54ffb7d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 40 deletions.
5 changes: 4 additions & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,10 @@ fn build_base_args<'a, 'cfg>(
cmd.args(args);
}

bcx.ws.lints().set_flags(cmd, unit.pkg.manifest().lints());
unit.pkg.manifest().lints().set_flags(cmd);
if let Some(virtual_lints) = bcx.ws.virtual_lints() {
virtual_lints.set_flags(cmd);
}

// -C overflow-checks is implied by the setting of -C debug-assertions,
// so we only need to provide -C overflow-checks if it differs from
Expand Down
67 changes: 31 additions & 36 deletions src/cargo/core/lints.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::BTreeMap;
use std::collections::HashMap;

use util::{CargoResult, ProcessBuilder};

Expand All @@ -11,60 +10,56 @@ enum LintKind {
Forbid,
}

impl LintKind {
pub fn try_from_string(lint_state: &str) -> Option<LintKind> {
match lint_state.as_ref() {
"allow" => Some(LintKind::Allow),
"warn" => Some(LintKind::Warn),
"deny" => Some(LintKind::Deny),
"forbid" => Some(LintKind::Forbid),
_ => None,
}
}

pub fn flag(&self) -> char {
match self {
LintKind::Allow => 'A',
LintKind::Warn => 'W',
LintKind::Deny => 'D',
LintKind::Forbid => 'F',
}
}
}

#[derive(Clone, Debug)]
pub struct Lints {
lints: HashMap<String, LintKind>,
lints: Vec<(String, LintKind)>,
}

impl Lints {
pub fn new(
manifest_lints: Option<&BTreeMap<String, String>>,
warnings: &mut Vec<String>,
) -> CargoResult<Lints> {
let mut lints = HashMap::new();
let mut lints = vec![];
if let Some(lint_section) = manifest_lints {
for (lint_name, lint_state) in lint_section.iter() {
match lint_state.as_ref() {
"allow" => { lints.insert(lint_name.to_string(), LintKind::Allow); },
"warn" => { lints.insert(lint_name.to_string(), LintKind::Warn); },
"deny" => { lints.insert(lint_name.to_string(), LintKind::Deny); },
"forbid" => { lints.insert(lint_name.to_string(), LintKind::Forbid); },
_ => warnings.push(format!(
if let Some(state) = LintKind::try_from_string(lint_state) {
lints.push((lint_name.to_string(), state));
} else {
warnings.push(format!(
"invalid lint state for `{}` (expected `warn`, `allow`, `deny` or `forbid`)",
lint_name
)),
));
}
}
}
Ok(Lints { lints })
}

pub fn set_flags(&self, cmd: &mut ProcessBuilder, package_lints: &Lints) {
let get_kind = |kind: LintKind| {
self.lints.iter()
.filter(|l| *l.1 == kind)
.chain(package_lints.lints.iter()
.filter(|l| *l.1 == kind && !self.lints.contains_key(l.0)))
.map(|l| l.0.to_string())
.collect::<Vec<String>>()
.join(",")
};

let allow = get_kind(LintKind::Allow);
if !allow.is_empty() {
cmd.arg("-A").arg(allow);
}
let warn = get_kind(LintKind::Warn);
if !warn.is_empty() {
cmd.arg("-W").arg(warn);
}
let deny = get_kind(LintKind::Deny);
if !deny.is_empty() {
cmd.arg("-D").arg(deny);
}
let forbid = get_kind(LintKind::Forbid);
if !forbid.is_empty() {
cmd.arg("-F").arg(forbid);
pub fn set_flags(&self, cmd: &mut ProcessBuilder) {
for (lint_name, state) in self.lints.iter() {
cmd.arg(format!("-{}", state.flag())).arg(lint_name);
}
}
}
6 changes: 3 additions & 3 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ impl<'cfg> Workspace<'cfg> {
}
}

pub fn lints(&self) -> &Lints {
pub fn virtual_lints(&self) -> Option<&Lints> {
let root = self.root_manifest
.as_ref()
.unwrap_or(&self.current_manifest);
match *self.packages.get(root) {
MaybePackage::Package(ref p) => p.manifest().lints(),
MaybePackage::Virtual(ref vm) => vm.lints(),
MaybePackage::Virtual(ref vm) => Some(vm.lints()),
_ => None,
}
}

Expand Down

0 comments on commit 54ffb7d

Please sign in to comment.