rustc_errors/
snippet.rs

1// Code for annotating snippets.
2
3use rustc_macros::{Decodable, Encodable};
4
5use crate::{Level, Loc};
6
7#[derive(#[automatically_derived]
impl ::core::clone::Clone for Line {
    #[inline]
    fn clone(&self) -> Line {
        Line {
            line_index: ::core::clone::Clone::clone(&self.line_index),
            annotations: ::core::clone::Clone::clone(&self.annotations),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Line {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "Line",
            "line_index", &self.line_index, "annotations", &&self.annotations)
    }
}Debug, #[automatically_derived]
impl ::core::cmp::PartialOrd for Line {
    #[inline]
    fn partial_cmp(&self, other: &Line)
        -> ::core::option::Option<::core::cmp::Ordering> {
        match ::core::cmp::PartialOrd::partial_cmp(&self.line_index,
                &other.line_index) {
            ::core::option::Option::Some(::core::cmp::Ordering::Equal) =>
                ::core::cmp::PartialOrd::partial_cmp(&self.annotations,
                    &other.annotations),
            cmp => cmp,
        }
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for Line {
    #[inline]
    fn cmp(&self, other: &Line) -> ::core::cmp::Ordering {
        match ::core::cmp::Ord::cmp(&self.line_index, &other.line_index) {
            ::core::cmp::Ordering::Equal =>
                ::core::cmp::Ord::cmp(&self.annotations, &other.annotations),
            cmp => cmp,
        }
    }
}Ord, #[automatically_derived]
impl ::core::cmp::PartialEq for Line {
    #[inline]
    fn eq(&self, other: &Line) -> bool {
        self.line_index == other.line_index &&
            self.annotations == other.annotations
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Line {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<usize>;
        let _: ::core::cmp::AssertParamIsEq<Vec<Annotation>>;
    }
}Eq)]
8pub(crate) struct Line {
9    pub line_index: usize,
10    pub annotations: Vec<Annotation>,
11}
12
13#[derive(#[automatically_derived]
impl ::core::clone::Clone for AnnotationColumn {
    #[inline]
    fn clone(&self) -> AnnotationColumn {
        let _: ::core::clone::AssertParamIsClone<usize>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for AnnotationColumn { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for AnnotationColumn {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "AnnotationColumn", "display", &self.display, "file", &&self.file)
    }
}Debug, #[automatically_derived]
impl ::core::cmp::PartialOrd for AnnotationColumn {
    #[inline]
    fn partial_cmp(&self, other: &AnnotationColumn)
        -> ::core::option::Option<::core::cmp::Ordering> {
        match ::core::cmp::PartialOrd::partial_cmp(&self.display,
                &other.display) {
            ::core::option::Option::Some(::core::cmp::Ordering::Equal) =>
                ::core::cmp::PartialOrd::partial_cmp(&self.file, &other.file),
            cmp => cmp,
        }
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for AnnotationColumn {
    #[inline]
    fn cmp(&self, other: &AnnotationColumn) -> ::core::cmp::Ordering {
        match ::core::cmp::Ord::cmp(&self.display, &other.display) {
            ::core::cmp::Ordering::Equal =>
                ::core::cmp::Ord::cmp(&self.file, &other.file),
            cmp => cmp,
        }
    }
}Ord, #[automatically_derived]
impl ::core::cmp::PartialEq for AnnotationColumn {
    #[inline]
    fn eq(&self, other: &AnnotationColumn) -> bool {
        self.display == other.display && self.file == other.file
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for AnnotationColumn {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<usize>;
    }
}Eq, #[automatically_derived]
impl ::core::default::Default for AnnotationColumn {
    #[inline]
    fn default() -> AnnotationColumn {
        AnnotationColumn {
            display: ::core::default::Default::default(),
            file: ::core::default::Default::default(),
        }
    }
}Default)]
14pub(crate) struct AnnotationColumn {
15    /// the (0-indexed) column for *display* purposes, counted in characters, not utf-8 bytes
16    pub display: usize,
17    /// the (0-indexed) column in the file, counted in characters, not utf-8 bytes.
18    ///
19    /// this may be different from `self.display`,
20    /// e.g. if the file contains hard tabs, because we convert tabs to spaces for error messages.
21    ///
22    /// for example:
23    /// ```text
24    /// (hard tab)hello
25    ///           ^ this is display column 4, but file column 1
26    /// ```
27    ///
28    /// we want to keep around the correct file offset so that column numbers in error messages
29    /// are correct. (motivated by <https://github.com/rust-lang/rust/issues/109537>)
30    pub file: usize,
31}
32
33impl AnnotationColumn {
34    pub(crate) fn from_loc(loc: &Loc) -> AnnotationColumn {
35        AnnotationColumn { display: loc.col_display, file: loc.col.0 }
36    }
37}
38
39#[derive(#[automatically_derived]
impl ::core::clone::Clone for MultilineAnnotation {
    #[inline]
    fn clone(&self) -> MultilineAnnotation {
        MultilineAnnotation {
            depth: ::core::clone::Clone::clone(&self.depth),
            line_start: ::core::clone::Clone::clone(&self.line_start),
            line_end: ::core::clone::Clone::clone(&self.line_end),
            start_col: ::core::clone::Clone::clone(&self.start_col),
            end_col: ::core::clone::Clone::clone(&self.end_col),
            is_primary: ::core::clone::Clone::clone(&self.is_primary),
            label: ::core::clone::Clone::clone(&self.label),
            overlaps_exactly: ::core::clone::Clone::clone(&self.overlaps_exactly),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for MultilineAnnotation {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        let names: &'static _ =
            &["depth", "line_start", "line_end", "start_col", "end_col",
                        "is_primary", "label", "overlaps_exactly"];
        let values: &[&dyn ::core::fmt::Debug] =
            &[&self.depth, &self.line_start, &self.line_end, &self.start_col,
                        &self.end_col, &self.is_primary, &self.label,
                        &&self.overlaps_exactly];
        ::core::fmt::Formatter::debug_struct_fields_finish(f,
            "MultilineAnnotation", names, values)
    }
}Debug, #[automatically_derived]
impl ::core::cmp::PartialOrd for MultilineAnnotation {
    #[inline]
    fn partial_cmp(&self, other: &MultilineAnnotation)
        -> ::core::option::Option<::core::cmp::Ordering> {
        match ::core::cmp::PartialOrd::partial_cmp(&self.depth, &other.depth)
            {
            ::core::option::Option::Some(::core::cmp::Ordering::Equal) =>
                match ::core::cmp::PartialOrd::partial_cmp(&self.line_start,
                        &other.line_start) {
                    ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                        =>
                        match ::core::cmp::PartialOrd::partial_cmp(&self.line_end,
                                &other.line_end) {
                            ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                                =>
                                match ::core::cmp::PartialOrd::partial_cmp(&self.start_col,
                                        &other.start_col) {
                                    ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                                        =>
                                        match ::core::cmp::PartialOrd::partial_cmp(&self.end_col,
                                                &other.end_col) {
                                            ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                                                =>
                                                match ::core::cmp::PartialOrd::partial_cmp(&self.is_primary,
                                                        &other.is_primary) {
                                                    ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                                                        =>
                                                        match ::core::cmp::PartialOrd::partial_cmp(&self.label,
                                                                &other.label) {
                                                            ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                                                                =>
                                                                ::core::cmp::PartialOrd::partial_cmp(&self.overlaps_exactly,
                                                                    &other.overlaps_exactly),
                                                            cmp => cmp,
                                                        },
                                                    cmp => cmp,
                                                },
                                            cmp => cmp,
                                        },
                                    cmp => cmp,
                                },
                            cmp => cmp,
                        },
                    cmp => cmp,
                },
            cmp => cmp,
        }
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for MultilineAnnotation {
    #[inline]
    fn cmp(&self, other: &MultilineAnnotation) -> ::core::cmp::Ordering {
        match ::core::cmp::Ord::cmp(&self.depth, &other.depth) {
            ::core::cmp::Ordering::Equal =>
                match ::core::cmp::Ord::cmp(&self.line_start,
                        &other.line_start) {
                    ::core::cmp::Ordering::Equal =>
                        match ::core::cmp::Ord::cmp(&self.line_end, &other.line_end)
                            {
                            ::core::cmp::Ordering::Equal =>
                                match ::core::cmp::Ord::cmp(&self.start_col,
                                        &other.start_col) {
                                    ::core::cmp::Ordering::Equal =>
                                        match ::core::cmp::Ord::cmp(&self.end_col, &other.end_col) {
                                            ::core::cmp::Ordering::Equal =>
                                                match ::core::cmp::Ord::cmp(&self.is_primary,
                                                        &other.is_primary) {
                                                    ::core::cmp::Ordering::Equal =>
                                                        match ::core::cmp::Ord::cmp(&self.label, &other.label) {
                                                            ::core::cmp::Ordering::Equal =>
                                                                ::core::cmp::Ord::cmp(&self.overlaps_exactly,
                                                                    &other.overlaps_exactly),
                                                            cmp => cmp,
                                                        },
                                                    cmp => cmp,
                                                },
                                            cmp => cmp,
                                        },
                                    cmp => cmp,
                                },
                            cmp => cmp,
                        },
                    cmp => cmp,
                },
            cmp => cmp,
        }
    }
}Ord, #[automatically_derived]
impl ::core::cmp::PartialEq for MultilineAnnotation {
    #[inline]
    fn eq(&self, other: &MultilineAnnotation) -> bool {
        self.is_primary == other.is_primary &&
                                    self.overlaps_exactly == other.overlaps_exactly &&
                                self.depth == other.depth &&
                            self.line_start == other.line_start &&
                        self.line_end == other.line_end &&
                    self.start_col == other.start_col &&
                self.end_col == other.end_col && self.label == other.label
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for MultilineAnnotation {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<usize>;
        let _: ::core::cmp::AssertParamIsEq<AnnotationColumn>;
        let _: ::core::cmp::AssertParamIsEq<bool>;
        let _: ::core::cmp::AssertParamIsEq<Option<String>>;
    }
}Eq)]
40pub(crate) struct MultilineAnnotation {
41    pub depth: usize,
42    pub line_start: usize,
43    pub line_end: usize,
44    pub start_col: AnnotationColumn,
45    pub end_col: AnnotationColumn,
46    pub is_primary: bool,
47    pub label: Option<String>,
48    pub overlaps_exactly: bool,
49}
50
51impl MultilineAnnotation {
52    pub(crate) fn increase_depth(&mut self) {
53        self.depth += 1;
54    }
55
56    /// Compare two `MultilineAnnotation`s considering only the `Span` they cover.
57    pub(crate) fn same_span(&self, other: &MultilineAnnotation) -> bool {
58        self.line_start == other.line_start
59            && self.line_end == other.line_end
60            && self.start_col == other.start_col
61            && self.end_col == other.end_col
62    }
63
64    pub(crate) fn as_start(&self) -> Annotation {
65        Annotation {
66            start_col: self.start_col,
67            end_col: AnnotationColumn {
68                // these might not correspond to the same place anymore,
69                // but that's okay for our purposes
70                display: self.start_col.display + 1,
71                file: self.start_col.file + 1,
72            },
73            is_primary: self.is_primary,
74            label: None,
75            annotation_type: AnnotationType::MultilineStart(self.depth),
76        }
77    }
78
79    pub(crate) fn as_end(&self) -> Annotation {
80        Annotation {
81            start_col: AnnotationColumn {
82                // these might not correspond to the same place anymore,
83                // but that's okay for our purposes
84                display: self.end_col.display.saturating_sub(1),
85                file: self.end_col.file.saturating_sub(1),
86            },
87            end_col: self.end_col,
88            is_primary: self.is_primary,
89            label: self.label.clone(),
90            annotation_type: AnnotationType::MultilineEnd(self.depth),
91        }
92    }
93
94    pub(crate) fn as_line(&self) -> Annotation {
95        Annotation {
96            start_col: Default::default(),
97            end_col: Default::default(),
98            is_primary: self.is_primary,
99            label: None,
100            annotation_type: AnnotationType::MultilineLine(self.depth),
101        }
102    }
103}
104
105#[derive(#[automatically_derived]
impl ::core::clone::Clone for AnnotationType {
    #[inline]
    fn clone(&self) -> AnnotationType {
        match self {
            AnnotationType::Singleline => AnnotationType::Singleline,
            AnnotationType::MultilineStart(__self_0) =>
                AnnotationType::MultilineStart(::core::clone::Clone::clone(__self_0)),
            AnnotationType::MultilineEnd(__self_0) =>
                AnnotationType::MultilineEnd(::core::clone::Clone::clone(__self_0)),
            AnnotationType::MultilineLine(__self_0) =>
                AnnotationType::MultilineLine(::core::clone::Clone::clone(__self_0)),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for AnnotationType {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            AnnotationType::Singleline =>
                ::core::fmt::Formatter::write_str(f, "Singleline"),
            AnnotationType::MultilineStart(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "MultilineStart", &__self_0),
            AnnotationType::MultilineEnd(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "MultilineEnd", &__self_0),
            AnnotationType::MultilineLine(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "MultilineLine", &__self_0),
        }
    }
}Debug, #[automatically_derived]
impl ::core::cmp::PartialOrd for AnnotationType {
    #[inline]
    fn partial_cmp(&self, other: &AnnotationType)
        -> ::core::option::Option<::core::cmp::Ordering> {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        match (self, other) {
            (AnnotationType::MultilineStart(__self_0),
                AnnotationType::MultilineStart(__arg1_0)) =>
                ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
            (AnnotationType::MultilineEnd(__self_0),
                AnnotationType::MultilineEnd(__arg1_0)) =>
                ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
            (AnnotationType::MultilineLine(__self_0),
                AnnotationType::MultilineLine(__arg1_0)) =>
                ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
            _ =>
                ::core::cmp::PartialOrd::partial_cmp(&__self_discr,
                    &__arg1_discr),
        }
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for AnnotationType {
    #[inline]
    fn cmp(&self, other: &AnnotationType) -> ::core::cmp::Ordering {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) {
            ::core::cmp::Ordering::Equal =>
                match (self, other) {
                    (AnnotationType::MultilineStart(__self_0),
                        AnnotationType::MultilineStart(__arg1_0)) =>
                        ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    (AnnotationType::MultilineEnd(__self_0),
                        AnnotationType::MultilineEnd(__arg1_0)) =>
                        ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    (AnnotationType::MultilineLine(__self_0),
                        AnnotationType::MultilineLine(__arg1_0)) =>
                        ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    _ => ::core::cmp::Ordering::Equal,
                },
            cmp => cmp,
        }
    }
}Ord, #[automatically_derived]
impl ::core::cmp::PartialEq for AnnotationType {
    #[inline]
    fn eq(&self, other: &AnnotationType) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (AnnotationType::MultilineStart(__self_0),
                    AnnotationType::MultilineStart(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (AnnotationType::MultilineEnd(__self_0),
                    AnnotationType::MultilineEnd(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (AnnotationType::MultilineLine(__self_0),
                    AnnotationType::MultilineLine(__arg1_0)) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for AnnotationType {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<usize>;
    }
}Eq)]
106pub(crate) enum AnnotationType {
107    /// Annotation under a single line of code
108    Singleline,
109
110    // The Multiline type above is replaced with the following three in order
111    // to reuse the current label drawing code.
112    //
113    // Each of these corresponds to one part of the following diagram:
114    //
115    //     x |   foo(1 + bar(x,
116    //       |  _________^              < MultilineStart
117    //     x | |             y),        < MultilineLine
118    //       | |______________^ label   < MultilineEnd
119    //     x |       z);
120    /// Annotation marking the first character of a fully shown multiline span
121    MultilineStart(usize),
122    /// Annotation marking the last character of a fully shown multiline span
123    MultilineEnd(usize),
124    /// Line at the left enclosing the lines of a fully shown multiline span
125    // Just a placeholder for the drawing algorithm, to know that it shouldn't skip the first 4
126    // and last 2 lines of code. The actual line is drawn in `emit_message_default` and not in
127    // `draw_multiline_line`.
128    MultilineLine(usize),
129}
130
131#[derive(#[automatically_derived]
impl ::core::clone::Clone for Annotation {
    #[inline]
    fn clone(&self) -> Annotation {
        Annotation {
            start_col: ::core::clone::Clone::clone(&self.start_col),
            end_col: ::core::clone::Clone::clone(&self.end_col),
            is_primary: ::core::clone::Clone::clone(&self.is_primary),
            label: ::core::clone::Clone::clone(&self.label),
            annotation_type: ::core::clone::Clone::clone(&self.annotation_type),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Annotation {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field5_finish(f, "Annotation",
            "start_col", &self.start_col, "end_col", &self.end_col,
            "is_primary", &self.is_primary, "label", &self.label,
            "annotation_type", &&self.annotation_type)
    }
}Debug, #[automatically_derived]
impl ::core::cmp::PartialOrd for Annotation {
    #[inline]
    fn partial_cmp(&self, other: &Annotation)
        -> ::core::option::Option<::core::cmp::Ordering> {
        match ::core::cmp::PartialOrd::partial_cmp(&self.start_col,
                &other.start_col) {
            ::core::option::Option::Some(::core::cmp::Ordering::Equal) =>
                match ::core::cmp::PartialOrd::partial_cmp(&self.end_col,
                        &other.end_col) {
                    ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                        =>
                        match ::core::cmp::PartialOrd::partial_cmp(&self.is_primary,
                                &other.is_primary) {
                            ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                                =>
                                match ::core::cmp::PartialOrd::partial_cmp(&self.label,
                                        &other.label) {
                                    ::core::option::Option::Some(::core::cmp::Ordering::Equal)
                                        =>
                                        ::core::cmp::PartialOrd::partial_cmp(&self.annotation_type,
                                            &other.annotation_type),
                                    cmp => cmp,
                                },
                            cmp => cmp,
                        },
                    cmp => cmp,
                },
            cmp => cmp,
        }
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for Annotation {
    #[inline]
    fn cmp(&self, other: &Annotation) -> ::core::cmp::Ordering {
        match ::core::cmp::Ord::cmp(&self.start_col, &other.start_col) {
            ::core::cmp::Ordering::Equal =>
                match ::core::cmp::Ord::cmp(&self.end_col, &other.end_col) {
                    ::core::cmp::Ordering::Equal =>
                        match ::core::cmp::Ord::cmp(&self.is_primary,
                                &other.is_primary) {
                            ::core::cmp::Ordering::Equal =>
                                match ::core::cmp::Ord::cmp(&self.label, &other.label) {
                                    ::core::cmp::Ordering::Equal =>
                                        ::core::cmp::Ord::cmp(&self.annotation_type,
                                            &other.annotation_type),
                                    cmp => cmp,
                                },
                            cmp => cmp,
                        },
                    cmp => cmp,
                },
            cmp => cmp,
        }
    }
}Ord, #[automatically_derived]
impl ::core::cmp::PartialEq for Annotation {
    #[inline]
    fn eq(&self, other: &Annotation) -> bool {
        self.is_primary == other.is_primary &&
                        self.start_col == other.start_col &&
                    self.end_col == other.end_col && self.label == other.label
            && self.annotation_type == other.annotation_type
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Annotation {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<AnnotationColumn>;
        let _: ::core::cmp::AssertParamIsEq<bool>;
        let _: ::core::cmp::AssertParamIsEq<Option<String>>;
        let _: ::core::cmp::AssertParamIsEq<AnnotationType>;
    }
}Eq)]
132pub(crate) struct Annotation {
133    /// Start column.
134    /// Note that it is important that this field goes
135    /// first, so that when we sort, we sort orderings by start
136    /// column.
137    pub start_col: AnnotationColumn,
138
139    /// End column within the line (exclusive)
140    pub end_col: AnnotationColumn,
141
142    /// Is this annotation derived from primary span
143    pub is_primary: bool,
144
145    /// Optional label to display adjacent to the annotation.
146    pub label: Option<String>,
147
148    /// Is this a single line, multiline or multiline span minimized down to a
149    /// smaller span.
150    pub annotation_type: AnnotationType,
151}
152
153impl Annotation {
154    /// Whether this annotation is a vertical line placeholder.
155    pub(crate) fn is_line(&self) -> bool {
156        #[allow(non_exhaustive_omitted_patterns)] match self.annotation_type {
    AnnotationType::MultilineLine(_) => true,
    _ => false,
}matches!(self.annotation_type, AnnotationType::MultilineLine(_))
157    }
158
159    /// Length of this annotation as displayed in the stderr output
160    pub(crate) fn len(&self) -> usize {
161        // Account for usize underflows
162        self.end_col.display.abs_diff(self.start_col.display)
163    }
164
165    pub(crate) fn has_label(&self) -> bool {
166        if let Some(ref label) = self.label {
167            // Consider labels with no text as effectively not being there
168            // to avoid weird output with unnecessary vertical lines, like:
169            //
170            //     X | fn foo(x: u32) {
171            //       | -------^------
172            //       | |      |
173            //       | |
174            //       |
175            //
176            // Note that this would be the complete output users would see.
177            !label.is_empty()
178        } else {
179            false
180        }
181    }
182
183    pub(crate) fn takes_space(&self) -> bool {
184        // Multiline annotations always have to keep vertical space.
185        #[allow(non_exhaustive_omitted_patterns)] match self.annotation_type {
    AnnotationType::MultilineStart(_) | AnnotationType::MultilineEnd(_) =>
        true,
    _ => false,
}matches!(
186            self.annotation_type,
187            AnnotationType::MultilineStart(_) | AnnotationType::MultilineEnd(_)
188        )
189    }
190}
191
192#[derive(#[automatically_derived]
impl ::core::fmt::Debug for StyledString {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "StyledString",
            "text", &self.text, "style", &&self.style)
    }
}Debug)]
193pub(crate) struct StyledString {
194    pub text: String,
195    pub style: Style,
196}
197
198#[derive(#[automatically_derived]
impl ::core::marker::Copy for Style { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Style {
    #[inline]
    fn clone(&self) -> Style {
        let _: ::core::clone::AssertParamIsClone<Level>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Style {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Style::MainHeaderMsg =>
                ::core::fmt::Formatter::write_str(f, "MainHeaderMsg"),
            Style::HeaderMsg =>
                ::core::fmt::Formatter::write_str(f, "HeaderMsg"),
            Style::LineAndColumn =>
                ::core::fmt::Formatter::write_str(f, "LineAndColumn"),
            Style::LineNumber =>
                ::core::fmt::Formatter::write_str(f, "LineNumber"),
            Style::Quotation =>
                ::core::fmt::Formatter::write_str(f, "Quotation"),
            Style::UnderlinePrimary =>
                ::core::fmt::Formatter::write_str(f, "UnderlinePrimary"),
            Style::UnderlineSecondary =>
                ::core::fmt::Formatter::write_str(f, "UnderlineSecondary"),
            Style::LabelPrimary =>
                ::core::fmt::Formatter::write_str(f, "LabelPrimary"),
            Style::LabelSecondary =>
                ::core::fmt::Formatter::write_str(f, "LabelSecondary"),
            Style::NoStyle => ::core::fmt::Formatter::write_str(f, "NoStyle"),
            Style::Level(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Level",
                    &__self_0),
            Style::Highlight =>
                ::core::fmt::Formatter::write_str(f, "Highlight"),
            Style::Addition =>
                ::core::fmt::Formatter::write_str(f, "Addition"),
            Style::Removal => ::core::fmt::Formatter::write_str(f, "Removal"),
        }
    }
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for Style {
    #[inline]
    fn eq(&self, other: &Style) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (Style::Level(__self_0), Style::Level(__arg1_0)) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Style {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<Level>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for Style {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            Style::Level(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for Style {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        Style::MainHeaderMsg => { 0usize }
                        Style::HeaderMsg => { 1usize }
                        Style::LineAndColumn => { 2usize }
                        Style::LineNumber => { 3usize }
                        Style::Quotation => { 4usize }
                        Style::UnderlinePrimary => { 5usize }
                        Style::UnderlineSecondary => { 6usize }
                        Style::LabelPrimary => { 7usize }
                        Style::LabelSecondary => { 8usize }
                        Style::NoStyle => { 9usize }
                        Style::Level(ref __binding_0) => { 10usize }
                        Style::Highlight => { 11usize }
                        Style::Addition => { 12usize }
                        Style::Removal => { 13usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    Style::MainHeaderMsg => {}
                    Style::HeaderMsg => {}
                    Style::LineAndColumn => {}
                    Style::LineNumber => {}
                    Style::Quotation => {}
                    Style::UnderlinePrimary => {}
                    Style::UnderlineSecondary => {}
                    Style::LabelPrimary => {}
                    Style::LabelSecondary => {}
                    Style::NoStyle => {}
                    Style::Level(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Style::Highlight => {}
                    Style::Addition => {}
                    Style::Removal => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for Style {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { Style::MainHeaderMsg }
                    1usize => { Style::HeaderMsg }
                    2usize => { Style::LineAndColumn }
                    3usize => { Style::LineNumber }
                    4usize => { Style::Quotation }
                    5usize => { Style::UnderlinePrimary }
                    6usize => { Style::UnderlineSecondary }
                    7usize => { Style::LabelPrimary }
                    8usize => { Style::LabelSecondary }
                    9usize => { Style::NoStyle }
                    10usize => {
                        Style::Level(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    11usize => { Style::Highlight }
                    12usize => { Style::Addition }
                    13usize => { Style::Removal }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Style`, expected 0..14, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable)]
199pub enum Style {
200    MainHeaderMsg,
201    HeaderMsg,
202    LineAndColumn,
203    LineNumber,
204    Quotation,
205    UnderlinePrimary,
206    UnderlineSecondary,
207    LabelPrimary,
208    LabelSecondary,
209    NoStyle,
210    Level(Level),
211    Highlight,
212    Addition,
213    Removal,
214}