Skip to content

Commit eef2a95

Browse files
committed
Sync all unstable features with Unstable Book; add tidy lint.
Add a tidy lint that checks for... * Unstable Book sections with no corresponding SUMMARY.md links * unstable features that don't have Unstable Book sections * Unstable Book sections that don't have corresponding unstable features
1 parent a9329d3 commit eef2a95

File tree

10 files changed

+243
-85
lines changed

10 files changed

+243
-85
lines changed

src/Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/doc/unstable-book/src/SUMMARY.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@
146146
- [proc_macro](proc-macro.md)
147147
- [proc_macro_internals](proc-macro-internals.md)
148148
- [process_try_wait](process-try-wait.md)
149-
- [pub_restricted](pub-restricted.md)
150149
- [question_mark_carrier](question-mark-carrier.md)
151150
- [quote](quote.md)
152151
- [rand](rand.md)
@@ -156,11 +155,11 @@
156155
- [relaxed_adts](relaxed-adts.md)
157156
- [repr_simd](repr-simd.md)
158157
- [retain_hash_collection](retain-hash-collection.md)
158+
- [reverse_cmp_key](reverse-cmp-key.md)
159159
- [rt](rt.md)
160160
- [rustc_attrs](rustc-attrs.md)
161161
- [rustc_diagnostic_macros](rustc-diagnostic-macros.md)
162162
- [rustc_private](rustc-private.md)
163-
- [rustdoc](rustdoc.md)
164163
- [rvalue_static_promotion](rvalue-static-promotion.md)
165164
- [sanitizer_runtime](sanitizer-runtime.md)
166165
- [sanitizer_runtime_lib](sanitizer-runtime-lib.md)
@@ -181,6 +180,7 @@
181180
- [step_by](step-by.md)
182181
- [step_trait](step-trait.md)
183182
- [stmt_expr_attributes](stmt-expr-attributes.md)
183+
- [str_checked_slicing](str-checked-slicing.md)
184184
- [str_escape](str-escape.md)
185185
- [str_internals](str-internals.md)
186186
- [struct_field_attributes](struct-field-attributes.md)

src/doc/unstable-book/src/pub-restricted.md

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# `reverse_cmp_key`
2+
3+
The tracking issue for this feature is: [#40893]
4+
5+
[#40893]: https://github.com/rust-lang/rust/issues/40893
6+
7+
------------------------

src/doc/unstable-book/src/rustdoc.md

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# `str_checked_slicing`
2+
3+
The tracking issue for this feature is: [#39932]
4+
5+
[#39932]: https://github.com/rust-lang/rust/issues/39932
6+
7+
------------------------

src/tools/tidy/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ version = "0.1.0"
44
authors = ["Alex Crichton <[email protected]>"]
55

66
[dependencies]
7+
regex = "0.2"

src/tools/tidy/src/features.rs

+81-69
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use std::fs::File;
2424
use std::io::prelude::*;
2525
use std::path::Path;
2626

27-
#[derive(PartialEq)]
28-
enum Status {
27+
#[derive(Debug, PartialEq)]
28+
pub enum Status {
2929
Stable,
3030
Removed,
3131
Unstable,
@@ -42,78 +42,21 @@ impl fmt::Display for Status {
4242
}
4343
}
4444

45-
struct Feature {
46-
level: Status,
47-
since: String,
48-
has_gate_test: bool,
45+
#[derive(Debug)]
46+
pub struct Feature {
47+
pub level: Status,
48+
pub since: String,
49+
pub has_gate_test: bool,
4950
}
5051

5152
pub fn check(path: &Path, bad: &mut bool) {
52-
let mut features = collect_lang_features(&path.join("libsyntax/feature_gate.rs"));
53+
let mut features = collect_lang_features(path);
5354
assert!(!features.is_empty());
54-
let mut lib_features = HashMap::<String, Feature>::new();
55-
56-
let mut contents = String::new();
57-
super::walk(path,
58-
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
59-
&mut |file| {
60-
let filename = file.file_name().unwrap().to_string_lossy();
61-
if !filename.ends_with(".rs") || filename == "features.rs" ||
62-
filename == "diagnostic_list.rs" {
63-
return;
64-
}
65-
66-
contents.truncate(0);
67-
t!(t!(File::open(&file), &file).read_to_string(&mut contents));
6855

69-
for (i, line) in contents.lines().enumerate() {
70-
let mut err = |msg: &str| {
71-
println!("{}:{}: {}", file.display(), i + 1, msg);
72-
*bad = true;
73-
};
74-
let level = if line.contains("[unstable(") {
75-
Status::Unstable
76-
} else if line.contains("[stable(") {
77-
Status::Stable
78-
} else {
79-
continue;
80-
};
81-
let feature_name = match find_attr_val(line, "feature") {
82-
Some(name) => name,
83-
None => {
84-
err("malformed stability attribute");
85-
continue;
86-
}
87-
};
88-
let since = match find_attr_val(line, "since") {
89-
Some(name) => name,
90-
None if level == Status::Stable => {
91-
err("malformed stability attribute");
92-
continue;
93-
}
94-
None => "None",
95-
};
56+
let lib_features = collect_lib_features(path, bad, &features);
57+
assert!(!lib_features.is_empty());
9658

97-
if features.contains_key(feature_name) {
98-
err("duplicating a lang feature");
99-
}
100-
if let Some(ref s) = lib_features.get(feature_name) {
101-
if s.level != level {
102-
err("different stability level than before");
103-
}
104-
if s.since != since {
105-
err("different `since` than before");
106-
}
107-
continue;
108-
}
109-
lib_features.insert(feature_name.to_owned(),
110-
Feature {
111-
level: level,
112-
since: since.to_owned(),
113-
has_gate_test: false,
114-
});
115-
}
116-
});
59+
let mut contents = String::new();
11760

11861
super::walk_many(&[&path.join("test/compile-fail"),
11962
&path.join("test/compile-fail-fulldeps"),
@@ -233,8 +176,9 @@ fn test_filen_gate(filen_underscore: &str,
233176
return false;
234177
}
235178

236-
fn collect_lang_features(path: &Path) -> HashMap<String, Feature> {
179+
pub fn collect_lang_features(base_src_path: &Path) -> HashMap<String, Feature> {
237180
let mut contents = String::new();
181+
let path = base_src_path.join("libsyntax/feature_gate.rs");
238182
t!(t!(File::open(path)).read_to_string(&mut contents));
239183

240184
contents.lines()
@@ -257,3 +201,71 @@ fn collect_lang_features(path: &Path) -> HashMap<String, Feature> {
257201
})
258202
.collect()
259203
}
204+
205+
pub fn collect_lib_features(base_src_path: &Path,
206+
bad: &mut bool,
207+
features: &HashMap<String, Feature>) -> HashMap<String, Feature> {
208+
let mut lib_features = HashMap::<String, Feature>::new();
209+
let mut contents = String::new();
210+
super::walk(base_src_path,
211+
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
212+
&mut |file| {
213+
let filename = file.file_name().unwrap().to_string_lossy();
214+
if !filename.ends_with(".rs") || filename == "features.rs" ||
215+
filename == "diagnostic_list.rs" {
216+
return;
217+
}
218+
219+
contents.truncate(0);
220+
t!(t!(File::open(&file), &file).read_to_string(&mut contents));
221+
222+
for (i, line) in contents.lines().enumerate() {
223+
let mut err = |msg: &str| {
224+
println!("{}:{}: {}", file.display(), i + 1, msg);
225+
*bad = true;
226+
};
227+
let level = if line.contains("[unstable(") {
228+
Status::Unstable
229+
} else if line.contains("[stable(") {
230+
Status::Stable
231+
} else {
232+
continue;
233+
};
234+
let feature_name = match find_attr_val(line, "feature") {
235+
Some(name) => name,
236+
None => {
237+
err("malformed stability attribute");
238+
continue;
239+
}
240+
};
241+
let since = match find_attr_val(line, "since") {
242+
Some(name) => name,
243+
None if level == Status::Stable => {
244+
err("malformed stability attribute");
245+
continue;
246+
}
247+
None => "None",
248+
};
249+
250+
if features.contains_key(feature_name) {
251+
err("duplicating a lang feature");
252+
}
253+
if let Some(ref s) = lib_features.get(feature_name) {
254+
if s.level != level {
255+
err("different stability level than before");
256+
}
257+
if s.since != since {
258+
err("different `since` than before");
259+
}
260+
continue;
261+
}
262+
lib_features.insert(feature_name.to_owned(),
263+
Feature {
264+
level: level,
265+
since: since.to_owned(),
266+
has_gate_test: false,
267+
});
268+
}
269+
});
270+
lib_features
271+
}

src/tools/tidy/src/main.rs

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
//! etc. This is run by default on `make check` and as part of the auto
1515
//! builders.
1616
17+
extern crate regex;
18+
1719
use std::fs;
1820
use std::path::{PathBuf, Path};
1921
use std::env;
@@ -37,6 +39,7 @@ mod features;
3739
mod cargo;
3840
mod pal;
3941
mod deps;
42+
mod unstable_book;
4043

4144
fn main() {
4245
let path = env::args_os().skip(1).next().expect("need an argument");
@@ -51,6 +54,7 @@ fn main() {
5154
cargo::check(&path, &mut bad);
5255
features::check(&path, &mut bad);
5356
pal::check(&path, &mut bad);
57+
unstable_book::check(&path, &mut bad);
5458
if !args.iter().any(|s| *s == "--no-vendor") {
5559
deps::check(&path, &mut bad);
5660
}

0 commit comments

Comments
 (0)