2 use std::path::PathBuf;
5 if let Err(e) = doit() {
6 eprintln!("error: {}", e);
9 This error was generated by the lint-docs tool.
10 This tool extracts documentation for lints from the source code and places
11 them in the rustc book. See the declare_lint! documentation
12 https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/macro.declare_lint.html
13 for an example of the format of documentation this tool expects.
15 To re-run these tests, run: ./x.py test --keep-stage=0 src/tools/lint-docs
16 The --keep-stage flag should be used if you have already built the compiler
17 and are only modifying the doc comments to avoid rebuilding the compiler.
20 std::process::exit(1);
24 fn doit() -> Result<(), Box<dyn Error>> {
25 let mut args = std::env::args().skip(1);
26 let mut src_path = None;
27 let mut out_path = None;
28 let mut rustc_path = None;
29 let mut rustc_target = None;
30 let mut verbose = false;
31 let mut validate = false;
32 while let Some(arg) = args.next() {
35 src_path = match args.next() {
36 Some(s) => Some(PathBuf::from(s)),
37 None => return Err("--src requires a value".into()),
41 out_path = match args.next() {
42 Some(s) => Some(PathBuf::from(s)),
43 None => return Err("--out requires a value".into()),
47 rustc_path = match args.next() {
48 Some(s) => Some(PathBuf::from(s)),
49 None => return Err("--rustc requires a value".into()),
53 rustc_target = match args.next() {
55 None => return Err("--rustc-target requires a value".into()),
58 "-v" | "--verbose" => verbose = true,
59 "--validate" => validate = true,
60 s => return Err(format!("unexpected argument `{}`", s).into()),
63 if src_path.is_none() {
64 return Err("--src must be specified to the directory with the compiler source".into());
66 if out_path.is_none() {
67 return Err("--out must be specified to the directory with the lint listing docs".into());
69 if rustc_path.is_none() {
70 return Err("--rustc must be specified to the path of rustc".into());
72 if rustc_target.is_none() {
73 return Err("--rustc-target must be specified to the rustc target".into());
75 let le = lint_docs::LintExtractor {
76 src_path: &src_path.unwrap(),
77 out_path: &out_path.unwrap(),
78 rustc_path: &rustc_path.unwrap(),
79 rustc_target: &rustc_target.unwrap(),
83 le.extract_lint_docs()