Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync all unstable features with Unstable Book; add tidy lint. #40694

Merged
merged 1 commit into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/doc/unstable-book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
- [proc_macro](proc-macro.md)
- [proc_macro_internals](proc-macro-internals.md)
- [process_try_wait](process-try-wait.md)
- [pub_restricted](pub-restricted.md)
- [question_mark_carrier](question-mark-carrier.md)
- [quote](quote.md)
- [rand](rand.md)
Expand All @@ -156,11 +155,11 @@
- [relaxed_adts](relaxed-adts.md)
- [repr_simd](repr-simd.md)
- [retain_hash_collection](retain-hash-collection.md)
- [reverse_cmp_key](reverse-cmp-key.md)
- [rt](rt.md)
- [rustc_attrs](rustc-attrs.md)
- [rustc_diagnostic_macros](rustc-diagnostic-macros.md)
- [rustc_private](rustc-private.md)
- [rustdoc](rustdoc.md)
- [rvalue_static_promotion](rvalue-static-promotion.md)
- [sanitizer_runtime](sanitizer-runtime.md)
- [sanitizer_runtime_lib](sanitizer-runtime-lib.md)
Expand All @@ -181,6 +180,7 @@
- [step_by](step-by.md)
- [step_trait](step-trait.md)
- [stmt_expr_attributes](stmt-expr-attributes.md)
- [str_checked_slicing](str-checked-slicing.md)
- [str_escape](str-escape.md)
- [str_internals](str-internals.md)
- [struct_field_attributes](struct-field-attributes.md)
Expand Down
7 changes: 0 additions & 7 deletions src/doc/unstable-book/src/pub-restricted.md

This file was deleted.

7 changes: 7 additions & 0 deletions src/doc/unstable-book/src/reverse-cmp-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# `reverse_cmp_key`

The tracking issue for this feature is: [#40893]

[#40893]: https://github.com/rust-lang/rust/issues/40893

------------------------
7 changes: 0 additions & 7 deletions src/doc/unstable-book/src/rustdoc.md

This file was deleted.

7 changes: 7 additions & 0 deletions src/doc/unstable-book/src/str-checked-slicing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# `str_checked_slicing`

The tracking issue for this feature is: [#39932]

[#39932]: https://github.com/rust-lang/rust/issues/39932

------------------------
1 change: 1 addition & 0 deletions src/tools/tidy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ version = "0.1.0"
authors = ["Alex Crichton <alex@alexcrichton.com>"]

[dependencies]
regex = "0.2"
150 changes: 81 additions & 69 deletions src/tools/tidy/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use std::fs::File;
use std::io::prelude::*;
use std::path::Path;

#[derive(PartialEq)]
enum Status {
#[derive(Debug, PartialEq)]
pub enum Status {
Stable,
Removed,
Unstable,
Expand All @@ -42,78 +42,21 @@ impl fmt::Display for Status {
}
}

struct Feature {
level: Status,
since: String,
has_gate_test: bool,
#[derive(Debug)]
pub struct Feature {
pub level: Status,
pub since: String,
pub has_gate_test: bool,
}

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

let mut contents = String::new();
super::walk(path,
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
&mut |file| {
let filename = file.file_name().unwrap().to_string_lossy();
if !filename.ends_with(".rs") || filename == "features.rs" ||
filename == "diagnostic_list.rs" {
return;
}

contents.truncate(0);
t!(t!(File::open(&file), &file).read_to_string(&mut contents));

for (i, line) in contents.lines().enumerate() {
let mut err = |msg: &str| {
println!("{}:{}: {}", file.display(), i + 1, msg);
*bad = true;
};
let level = if line.contains("[unstable(") {
Status::Unstable
} else if line.contains("[stable(") {
Status::Stable
} else {
continue;
};
let feature_name = match find_attr_val(line, "feature") {
Some(name) => name,
None => {
err("malformed stability attribute");
continue;
}
};
let since = match find_attr_val(line, "since") {
Some(name) => name,
None if level == Status::Stable => {
err("malformed stability attribute");
continue;
}
None => "None",
};
let lib_features = collect_lib_features(path, bad, &features);
assert!(!lib_features.is_empty());

if features.contains_key(feature_name) {
err("duplicating a lang feature");
}
if let Some(ref s) = lib_features.get(feature_name) {
if s.level != level {
err("different stability level than before");
}
if s.since != since {
err("different `since` than before");
}
continue;
}
lib_features.insert(feature_name.to_owned(),
Feature {
level: level,
since: since.to_owned(),
has_gate_test: false,
});
}
});
let mut contents = String::new();

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

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

contents.lines()
Expand All @@ -257,3 +201,71 @@ fn collect_lang_features(path: &Path) -> HashMap<String, Feature> {
})
.collect()
}

pub fn collect_lib_features(base_src_path: &Path,
bad: &mut bool,
features: &HashMap<String, Feature>) -> HashMap<String, Feature> {
let mut lib_features = HashMap::<String, Feature>::new();
let mut contents = String::new();
super::walk(base_src_path,
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
&mut |file| {
let filename = file.file_name().unwrap().to_string_lossy();
if !filename.ends_with(".rs") || filename == "features.rs" ||
filename == "diagnostic_list.rs" {
return;
}

contents.truncate(0);
t!(t!(File::open(&file), &file).read_to_string(&mut contents));

for (i, line) in contents.lines().enumerate() {
let mut err = |msg: &str| {
println!("{}:{}: {}", file.display(), i + 1, msg);
*bad = true;
};
let level = if line.contains("[unstable(") {
Status::Unstable
} else if line.contains("[stable(") {
Status::Stable
} else {
continue;
};
let feature_name = match find_attr_val(line, "feature") {
Some(name) => name,
None => {
err("malformed stability attribute");
continue;
}
};
let since = match find_attr_val(line, "since") {
Some(name) => name,
None if level == Status::Stable => {
err("malformed stability attribute");
continue;
}
None => "None",
};

if features.contains_key(feature_name) {
err("duplicating a lang feature");
}
if let Some(ref s) = lib_features.get(feature_name) {
if s.level != level {
err("different stability level than before");
}
if s.since != since {
err("different `since` than before");
}
continue;
}
lib_features.insert(feature_name.to_owned(),
Feature {
level: level,
since: since.to_owned(),
has_gate_test: false,
});
}
});
lib_features
}
4 changes: 4 additions & 0 deletions src/tools/tidy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
//! etc. This is run by default on `make check` and as part of the auto
//! builders.

extern crate regex;

use std::fs;
use std::path::{PathBuf, Path};
use std::env;
Expand All @@ -37,6 +39,7 @@ mod features;
mod cargo;
mod pal;
mod deps;
mod unstable_book;

fn main() {
let path = env::args_os().skip(1).next().expect("need an argument");
Expand All @@ -51,6 +54,7 @@ fn main() {
cargo::check(&path, &mut bad);
features::check(&path, &mut bad);
pal::check(&path, &mut bad);
unstable_book::check(&path, &mut bad);
if !args.iter().any(|s| *s == "--no-vendor") {
deps::check(&path, &mut bad);
}
Expand Down
Loading