compiletest/directives/
line_number.rs

1/// A line number in a file. Internally the first line has index 1.
2/// If it is 0 it means "no specific line" (used e.g. for implied directives).
3/// When `Display`:ed, the first line is `1`.
4#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
5pub(crate) struct LineNumber(usize);
6
7impl LineNumber {
8    /// This represents "no specific line" (used e.g. for implied directives).
9    pub(crate) const ZERO: Self = Self(0);
10
11    /// A never ending iterator over line numbers starting from the first line.
12    pub(crate) fn enumerate() -> impl Iterator<Item = LineNumber> {
13        (1..).map(LineNumber)
14    }
15}
16
17impl std::fmt::Display for LineNumber {
18    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        write!(f, "{}", self.0)
20    }
21}