litcheck_core/
lib.rs

1/// This is an implementation of `std::assert_matches::assert_matches`
2/// so it can be removed when that feature stabilizes upstream
3#[macro_export]
4macro_rules! assert_matches {
5    ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => {
6        match $left {
7            $( $pattern )|+ $( if $guard )? => {}
8            ref left_val => {
9                panic!(r#"
10assertion failed: `(left matches right)`
11    left: `{:?}`,
12    right: `{}`"#, left_val, stringify!($($pattern)|+ $(if $guard)?));
13            }
14        }
15    };
16
17    ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )?, $msg:literal $(,)?) => {
18        match $left {
19            $( $pattern )|+ $( if $guard )? => {}
20            ref left_val => {
21                panic!(concat!(r#"
22assertion failed: `(left matches right)`
23    left: `{:?}`,
24    right: `{}`
25"#, $msg), left_val, stringify!($($pattern)|+ $(if $guard)?));
26            }
27        }
28    };
29
30    ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )?, $msg:literal, $($arg:tt)+) => {
31        match $left {
32            $( $pattern )|+ $( if $guard )? => {}
33            ref left_val => {
34                panic!(concat!(r#"
35assertion failed: `(left matches right)`
36    left: `{:?}`,
37    right: `{}`
38"#, $msg), left_val, stringify!($($pattern)|+ $(if $guard)?), $($arg)+);
39            }
40        }
41    }
42}
43
44pub mod diagnostics;
45pub mod fs;
46mod input;
47pub mod range;
48pub mod text;
49pub mod variables;
50
51pub use self::input::Input;
52
53pub type StaticCow<T> = std::borrow::Cow<'static, T>;
54
55pub type Symbol = string_interner::DefaultSymbol;
56
57pub struct StringInterner(
58    string_interner::StringInterner<
59        string_interner::backend::StringBackend<Symbol>,
60        core::hash::BuildHasherDefault<rustc_hash::FxHasher>,
61    >,
62);
63impl Default for StringInterner {
64    fn default() -> Self {
65        Self(string_interner::StringInterner::new())
66    }
67}
68impl StringInterner {
69    #[inline]
70    pub fn new() -> Self {
71        Self::default()
72    }
73
74    #[inline]
75    pub fn get_or_intern(&mut self, s: impl AsRef<str>) -> Symbol {
76        self.0.get_or_intern(s)
77    }
78
79    #[track_caller]
80    pub fn resolve(&self, symbol: Symbol) -> &str {
81        self.0.resolve(symbol).expect("invalid symbol")
82    }
83}