Skip to content

Commit 256f41e

Browse files
committed
Warn about unused whitelist options
1 parent 7b3038e commit 256f41e

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/ir/context.rs

+12
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,18 @@ If you encounter an error missing from this list, please file an issue or a PR!"
23852385

23862386
self.whitelisted = Some(whitelisted);
23872387
self.codegen_items = Some(codegen_items);
2388+
2389+
for item in self.options().whitelisted_functions.unmatched_items() {
2390+
error!("unused option: --whitelist-function {}", item);
2391+
}
2392+
2393+
for item in self.options().whitelisted_vars.unmatched_items() {
2394+
error!("unused option: --whitelist-var {}", item);
2395+
}
2396+
2397+
for item in self.options().whitelisted_types.unmatched_items() {
2398+
error!("unused option: --whitelist-type {}", item);
2399+
}
23882400
}
23892401

23902402
/// Convenient method for getting the prefix to use for most traits in

src/regex_set.rs

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
//! A type that represents the union of a set of regular expressions.
22
33
use regex::RegexSet as RxSet;
4+
use std::cell::Cell;
45

56
/// A dynamic set of regular expressions.
67
#[derive(Debug)]
78
pub struct RegexSet {
89
items: Vec<String>,
10+
matched: Vec<Cell<bool>>,
911
set: Option<RxSet>,
1012
}
1113

@@ -21,6 +23,7 @@ impl RegexSet {
2123
S: AsRef<str>,
2224
{
2325
self.items.push(string.as_ref().to_owned());
26+
self.matched.push(Cell::new(false));
2427
self.set = None;
2528
}
2629

@@ -29,6 +32,17 @@ impl RegexSet {
2932
&self.items[..]
3033
}
3134

35+
/// Returns regexes in the set which didn't match any strings yet
36+
pub fn unmatched_items(&self) -> Vec<String> {
37+
let mut items = vec![];
38+
for (i, item) in self.items.iter().enumerate() {
39+
if !self.matched[i].get() {
40+
items.push(item.clone());
41+
}
42+
}
43+
items
44+
}
45+
3246
/// Construct a RegexSet from the set of entries we've accumulated.
3347
///
3448
/// Must be called before calling `matches()`, or it will always return
@@ -50,16 +64,24 @@ impl RegexSet {
5064
S: AsRef<str>,
5165
{
5266
let s = string.as_ref();
53-
self.set.as_ref().map(|set| set.is_match(s)).unwrap_or(
54-
false,
55-
)
67+
if let Some(set) = self.set.as_ref() {
68+
let matches = set.matches(s);
69+
if matches.matched_any() {
70+
for i in matches.iter() {
71+
self.matched[i].set(true);
72+
}
73+
return true;
74+
}
75+
}
76+
false
5677
}
5778
}
5879

5980
impl Default for RegexSet {
6081
fn default() -> Self {
6182
RegexSet {
6283
items: vec![],
84+
matched: vec![],
6385
set: None,
6486
}
6587
}

0 commit comments

Comments
 (0)