]> git.proxmox.com Git - rustc.git/blob - src/tools/lint-docs/src/main.rs
New upstream version 1.50.0+dfsg1
[rustc.git] / src / tools / lint-docs / src / main.rs
1 use std::error::Error;
2 use std::path::PathBuf;
3
4 fn main() {
5 if let Err(e) = doit() {
6 eprintln!("error: {}", e);
7 eprintln!(
8 "
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.
14
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.
18 "
19 );
20 std::process::exit(1);
21 }
22 }
23
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() {
33 match arg.as_str() {
34 "--src" => {
35 src_path = match args.next() {
36 Some(s) => Some(PathBuf::from(s)),
37 None => return Err("--src requires a value".into()),
38 };
39 }
40 "--out" => {
41 out_path = match args.next() {
42 Some(s) => Some(PathBuf::from(s)),
43 None => return Err("--out requires a value".into()),
44 };
45 }
46 "--rustc" => {
47 rustc_path = match args.next() {
48 Some(s) => Some(PathBuf::from(s)),
49 None => return Err("--rustc requires a value".into()),
50 };
51 }
52 "--rustc-target" => {
53 rustc_target = match args.next() {
54 Some(s) => Some(s),
55 None => return Err("--rustc-target requires a value".into()),
56 };
57 }
58 "-v" | "--verbose" => verbose = true,
59 "--validate" => validate = true,
60 s => return Err(format!("unexpected argument `{}`", s).into()),
61 }
62 }
63 if src_path.is_none() {
64 return Err("--src must be specified to the directory with the compiler source".into());
65 }
66 if out_path.is_none() {
67 return Err("--out must be specified to the directory with the lint listing docs".into());
68 }
69 if rustc_path.is_none() {
70 return Err("--rustc must be specified to the path of rustc".into());
71 }
72 if rustc_target.is_none() {
73 return Err("--rustc-target must be specified to the rustc target".into());
74 }
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(),
80 verbose,
81 validate,
82 };
83 le.extract_lint_docs()
84 }