|
2 | 2 |
|
3 | 3 | use crate::rules::Rules; |
4 | 4 | use anyhow::{Context, Result, bail}; |
5 | | -use mdbook_preprocessor::book::BookItem; |
6 | | -use mdbook_preprocessor::book::{Book, Chapter}; |
7 | | -use mdbook_preprocessor::errors::Error; |
8 | | -use mdbook_preprocessor::{Preprocessor, PreprocessorContext}; |
| 5 | +use diagnostics::{Diagnostics, warn_or_err}; |
9 | 6 | use once_cell::sync::Lazy; |
10 | 7 | use regex::{Captures, Regex}; |
11 | 8 | use semver::{Version, VersionReq}; |
12 | | -use std::fmt; |
13 | 9 | use std::io; |
14 | 10 | use std::ops::Range; |
15 | 11 | use std::path::PathBuf; |
@@ -47,54 +43,6 @@ pub fn handle_preprocessing() -> Result<(), Error> { |
47 | 43 | Ok(()) |
48 | 44 | } |
49 | 45 |
|
50 | | -/// Handler for errors and warnings. |
51 | | -pub struct Diagnostics { |
52 | | - /// Whether or not warnings should be errors (set by SPEC_DENY_WARNINGS |
53 | | - /// environment variable). |
54 | | - deny_warnings: bool, |
55 | | - /// Number of messages generated. |
56 | | - count: u32, |
57 | | -} |
58 | | - |
59 | | -impl Diagnostics { |
60 | | - fn new() -> Diagnostics { |
61 | | - let deny_warnings = std::env::var("SPEC_DENY_WARNINGS").as_deref() == Ok("1"); |
62 | | - Diagnostics { |
63 | | - deny_warnings, |
64 | | - count: 0, |
65 | | - } |
66 | | - } |
67 | | - |
68 | | - /// Displays a warning or error (depending on whether warnings are denied). |
69 | | - /// |
70 | | - /// Usually you want the [`warn_or_err!`] macro. |
71 | | - fn warn_or_err(&mut self, args: fmt::Arguments<'_>) { |
72 | | - if self.deny_warnings { |
73 | | - eprintln!("error: {args}"); |
74 | | - } else { |
75 | | - eprintln!("warning: {args}"); |
76 | | - } |
77 | | - self.count += 1; |
78 | | - } |
79 | | -} |
80 | | - |
81 | | -/// Displays a warning or error (depending on whether warnings are denied). |
82 | | -#[macro_export] |
83 | | -macro_rules! warn_or_err { |
84 | | - ($diag:expr, $($arg:tt)*) => { |
85 | | - $diag.warn_or_err(format_args!($($arg)*)); |
86 | | - }; |
87 | | -} |
88 | | - |
89 | | -/// Displays a message for an internal error, and immediately exits. |
90 | | -#[macro_export] |
91 | | -macro_rules! bug { |
92 | | - ($($arg:tt)*) => { |
93 | | - eprintln!("mdbook-spec internal error: {}", format_args!($($arg)*)); |
94 | | - std::process::exit(1); |
95 | | - }; |
96 | | -} |
97 | | - |
98 | 46 | pub struct Spec { |
99 | 47 | /// Path to the rust-lang/rust git repository (set by SPEC_RUST_ROOT |
100 | 48 | /// environment variable). |
|
0 commit comments