]> git.proxmox.com Git - rustc.git/blob - src/doc/reference/stable-check/src/main.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / doc / reference / stable-check / src / main.rs
1 use std::error::Error;
2 use std::env;
3 use std::fs;
4 use std::fs::File;
5 use std::io::prelude::*;
6 use std::path::Path;
7
8 fn main() {
9 let arg = env::args().nth(1).unwrap_or_else(|| {
10 println!("Please pass a src directory as the first argument");
11 std::process::exit(1);
12 });
13
14 match check_directory(&Path::new(&arg)) {
15 Ok(()) => println!("passed!"),
16 Err(e) => {
17 println!("Error: {}", e);
18 std::process::exit(1);
19 }
20 }
21 }
22
23 fn check_directory(dir: &Path) -> Result<(), Box<dyn Error>> {
24 for entry in fs::read_dir(dir)? {
25 let entry = entry?;
26 let path = entry.path();
27
28 if path.is_dir() {
29 return check_directory(&path);
30 }
31
32 let mut file = File::open(&path)?;
33 let mut contents = String::new();
34 file.read_to_string(&mut contents)?;
35
36 if contents.contains("#![feature") {
37 return Err(From::from(format!("Feature flag found in {:?}", path)));
38 }
39 }
40
41 Ok(())
42 }