Debian Codegraph @

src/sudo/diagnostic.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#, BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#};
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#;
4
5 use craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/::Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#;
6
7 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) fn cited_errorrust-analyzer cargo sudo-rs 0.2.14 sudo/diagnostic/cited_error().(message: &str, span: Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#, path: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>) {
8 let path_str = path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().();
9 let Spanrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span# {
10 startrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#start.: (line, col),
11 endrust-analyzer cargo sudo-rs 0.2.14 sudoers/basic_parser/Span#end.: (end_line, mut end_col),
12 } = span;
13 eprintln_ignore_io_errorrust-analyzer cargo sudo-rs 0.2.14 macros/eprintln_ignore_io_error!!("{path_str}:{line}:{col}: {message}");
14
15 // we won't try to "span" errors across multiple lines
16 if line rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().end_line {
17 end_col = col;
18 }
19
20 let citation = || {
21 let inp = BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(path).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().);
22 let line = inp.linesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#lines().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(line rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
23 let padding = line
24 .charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().()
25 .takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(col rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1)
26 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|c| if c.is_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_whitespace().() { c } else { ' ' })
27 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>();
28 let lineunder = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::repeat_nrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/repeat_n/repeat_n().('~', end_col rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().col)
29 .skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1)
30 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>();
31 eprintln_ignore_io_errorrust-analyzer cargo sudo-rs 0.2.14 macros/eprintln_ignore_io_error!!("{line}");
32 eprintln_ignore_io_errorrust-analyzer cargo sudo-rs 0.2.14 macros/eprintln_ignore_io_error!!("{padding}^{lineunder}");
33 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(())
34 };
35
36 // we ignore any errors in displaying an error
37 let _ = citation();
38 }
39
40 macro_rules! diagnosticrust-analyzer cargo sudo-rs 0.2.14 sudo/diagnostic/diagnostic! {
41 ($str:expr, $path:tt @ $pos:ident) => {
42 if let Some(range) = $pos {
43 $crate::sudo::diagnostic::cited_error(&format!($str), range, $path);
44 } else {
45 for line in format!($str).split('\n') {
46 eprintln_ignore_io_error!("sudo: {}", line);
47 }
48 }
49 };
50 ($str:expr) => {{
51 for line in format!($str).split('\n') {
52 eprintln_ignore_io_error!("sudo: {}", line);
53 }
54 }};
55 }
56
57 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) use diagnosticrust-analyzer cargo sudo-rs 0.2.14 sudo/diagnostic/diagnostic!;