Skip to content

Commit e8b6d3c

Browse files
committed
Use only one feature struct, and use hash maps in both occasions
1 parent e357178 commit e8b6d3c

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/tools/tidy/src/features.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,15 @@ impl fmt::Display for Status {
3939
}
4040
}
4141

42-
4342
struct Feature {
44-
name: String,
45-
level: Status,
46-
since: String,
47-
}
48-
49-
struct LibFeature {
5043
level: Status,
5144
since: String,
5245
}
5346

5447
pub fn check(path: &Path, bad: &mut bool) {
5548
let features = collect_lang_features(&path.join("libsyntax/feature_gate.rs"));
5649
assert!(!features.is_empty());
57-
let mut lib_features = HashMap::<String, LibFeature>::new();
50+
let mut lib_features = HashMap::<String, Feature>::new();
5851

5952
let mut contents = String::new();
6053
super::walk(path,
@@ -97,7 +90,7 @@ pub fn check(path: &Path, bad: &mut bool) {
9790
None => "None",
9891
};
9992

100-
if features.iter().any(|f| f.name == feature_name) {
93+
if features.contains_key(feature_name) {
10194
err("duplicating a lang feature");
10295
}
10396
if let Some(ref s) = lib_features.get(feature_name) {
@@ -110,7 +103,7 @@ pub fn check(path: &Path, bad: &mut bool) {
110103
continue;
111104
}
112105
lib_features.insert(feature_name.to_owned(),
113-
LibFeature {
106+
Feature {
114107
level: level,
115108
since: since.to_owned(),
116109
});
@@ -122,9 +115,9 @@ pub fn check(path: &Path, bad: &mut bool) {
122115
}
123116

124117
let mut lines = Vec::new();
125-
for feature in features {
118+
for (name, feature) in features {
126119
lines.push(format!("{:<32} {:<8} {:<12} {:<8}",
127-
feature.name,
120+
name,
128121
"lang",
129122
feature.level,
130123
feature.since));
@@ -150,7 +143,7 @@ fn find_attr_val<'a>(line: &'a str, attr: &str) -> Option<&'a str> {
150143
.map(|(i, j)| &line[i..j])
151144
}
152145

153-
fn collect_lang_features(path: &Path) -> Vec<Feature> {
146+
fn collect_lang_features(path: &Path) -> HashMap<String, Feature> {
154147
let mut contents = String::new();
155148
t!(t!(File::open(path)).read_to_string(&mut contents));
156149

@@ -165,11 +158,11 @@ fn collect_lang_features(path: &Path) -> Vec<Feature> {
165158
};
166159
let name = parts.next().unwrap().trim();
167160
let since = parts.next().unwrap().trim().trim_matches('"');
168-
Some(Feature {
169-
name: name.to_owned(),
170-
level: level,
171-
since: since.to_owned(),
172-
})
161+
Some((name.to_owned(),
162+
Feature {
163+
level: level,
164+
since: since.to_owned(),
165+
}))
173166
})
174167
.collect()
175168
}

0 commit comments

Comments
 (0)