Debian Codegraph @

src/term/views.rs

raw symbols SCIP
1 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::{
2 stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::{Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, ToStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/ToString#},
3 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/,
4 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#,
5 };
6 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#;
7
8 use craterust-analyzer cargo codespan-reporting 0.12.0 crate/::diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/::{Diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#, LabelStylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/LabelStyle#};
9 use craterust-analyzer cargo codespan-reporting 0.12.0 crate/::filesrust-analyzer cargo codespan-reporting 0.12.0 files/::{Errorrust-analyzer cargo codespan-reporting 0.12.0 files/Error#, Filesrust-analyzer cargo codespan-reporting 0.12.0 files/Files#, Locationrust-analyzer cargo codespan-reporting 0.12.0 files/Location#};
10 use craterust-analyzer cargo codespan-reporting 0.12.0 crate/::termrust-analyzer cargo codespan-reporting 0.12.0 term/::rendererrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/::{Locusrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/Locus#, MultiLabelrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/MultiLabel#, Rendererrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/Renderer#, SingleLabelrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/SingleLabel#};
11 use craterust-analyzer cargo codespan-reporting 0.12.0 crate/::termrust-analyzer cargo codespan-reporting 0.12.0 term/::Configrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#;
12
13 /// Calculate the number of decimal digits in `n`.
14 fn count_digitsrust-analyzer cargo codespan-reporting 0.12.0 term/views/count_digits().(n: usize) -> usize {
15 n.ilog10rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]ilog10().() as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1
16 }
17
18 /// Output a richly formatted diagnostic, with source code previews.
19 pub struct RichDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#<'diagnostic, 'config, FileId> {
20 diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic.: &'diagnostic Diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#<FileId>,
21 configrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#config.: &'config Configrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#,
22 }
23
24 impl<'diagnostic, 'config, FileId> RichDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#<'diagnostic, 'config, FileId>
25 where
26 FileId: Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#,
27 {
28 pub fn newrust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`RichDiagnostic<'diagnostic, 'config, FileId>`]new().(
29 diagnostic: &'diagnostic Diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#<FileId>,
30 config: &'config Configrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#,
31 ) -> RichDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#<'diagnostic, 'config, FileId> {
32 RichDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic# { diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic., configrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#config. }
33 }
34
35 pub fn renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`RichDiagnostic<'diagnostic, 'config, FileId>`]render().<'files>(
36 &self,
37 files: &'files (impl Filesrust-analyzer cargo codespan-reporting 0.12.0 files/Files#<'files, FileIdrust-analyzer cargo codespan-reporting 0.12.0 files/Files#FileId# = FileId> + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#),
38 renderer: &mut Rendererrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/Renderer#<'_, '_>,
39 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo codespan-reporting 0.12.0 files/Error#>
40 where
41 FileId: 'files,
42 {
43 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::collectionsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#;
44
45 struct LabeledFilerust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#<'diagnostic, FileId> {
46 file_idrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#file_id.: FileId,
47 startrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#start.: usize,
48 namerust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
49 locationrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#location.: Locationrust-analyzer cargo codespan-reporting 0.12.0 files/Location#,
50 num_multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#num_multi_labels.: usize,
51 linesrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#lines.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<usize, Linerust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#<'diagnostic>>,
52 max_label_stylerust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#max_label_style.: LabelStylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/LabelStyle#,
53 }
54
55 impl<'diagnostic, FileId> LabeledFilerust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#<'diagnostic, FileId> {
56 fn get_or_insert_linerust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`LabeledFile<'diagnostic, FileId>`]get_or_insert_line().(
57 &mut self,
58 line_index: usize,
59 line_range: Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize>,
60 line_number: usize,
61 ) -> &mut Linerust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#<'diagnostic> {
62 self.linesrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#lines..entryrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]entry().(line_index).or_insert_withrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/entry/impl#[`Entry<'a, K, V, A>`]or_insert_with().(|| Linerust-analyzer cargo codespan-reporting 0.12.0 term/views/Line# {
63 rangerust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#range.: line_range,
64 numberrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#number.: line_number,
65 single_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#single_labels.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![],
66 multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#multi_labels.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![],
67 // This has to be false by default so we know if it must be rendered by another condition already.
68 must_renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#must_render.: false,
69 })
70 }
71 }
72
73 struct Linerust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#<'diagnostic> {
74 numberrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#number.: usize,
75 rangerust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#range.: corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize>,
76 // TODO: How do we reuse these allocations?
77 single_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#single_labels.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<SingleLabelrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/SingleLabel#<'diagnostic>>,
78 multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#multi_labels.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(usize, LabelStylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/LabelStyle#, MultiLabelrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/MultiLabel#<'diagnostic>)>,
79 must_renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#must_render.: bool,
80 }
81
82 // TODO: Make this data structure external, to allow for allocation reuse
83 let mut labeled_files = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<LabeledFilerust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#<'_, _>>::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
84 // Keep track of the outer padding to use when rendering the
85 // snippets of source code.
86 let mut outer_padding = 0;
87
88 // Group labels by file
89 for label in &self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic..labelsrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#labels. {
90 let start_line_index = files.line_indexrust-analyzer cargo codespan-reporting 0.12.0 files/Files#line_index().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., label.rangerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#range..startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
91 let start_line_number = files.line_numberrust-analyzer cargo codespan-reporting 0.12.0 files/Files#line_number().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., start_line_index)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
92 let start_line_range = files.line_rangerust-analyzer cargo codespan-reporting 0.12.0 files/Files#line_range().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., start_line_index)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
93 let end_line_index = files.line_indexrust-analyzer cargo codespan-reporting 0.12.0 files/Files#line_index().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., label.rangerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#range..endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
94 let end_line_number = files.line_numberrust-analyzer cargo codespan-reporting 0.12.0 files/Files#line_number().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., end_line_index)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
95 let end_line_range = files.line_rangerust-analyzer cargo codespan-reporting 0.12.0 files/Files#line_range().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., end_line_index)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
96
97 outer_padding = corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(outer_padding, count_digitsrust-analyzer cargo codespan-reporting 0.12.0 term/views/count_digits().(start_line_number));
98 outer_padding = corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(outer_padding, count_digitsrust-analyzer cargo codespan-reporting 0.12.0 term/views/count_digits().(end_line_number));
99
100 // NOTE: This could be made more efficient by using an associative
101 // data structure like a hashmap or B-tree, but we use a vector to
102 // preserve the order that unique files appear in the list of labels.
103 let labeled_file = match labeled_files
104 .iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().()
105 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`IterMut<'a, T>`][Iterator]find().(|labeled_file| label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().labeled_file.file_idrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#file_id.)
106 {
107 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(labeled_file) => {
108 // another diagnostic also referenced this file
109 if labeled_file.max_label_stylerust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#max_label_style. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#gt().label.stylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#style.
110 || (labeled_file.max_label_stylerust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#max_label_style. rust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[LabelStyle][`PartialEq<Self>`]eq().==rust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[LabelStyle][`PartialEq<Self>`]eq(). rust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[LabelStyle][`PartialEq<Self>`]eq().label.stylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#style.
111 && labeled_file.startrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#start. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().label.rangerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#range..startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.)
112 {
113 // this label has a higher style or has the same style but starts earlier
114 labeled_file.startrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#start. = label.rangerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#range..startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.;
115 labeled_file.locationrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#location. = files.locationrust-analyzer cargo codespan-reporting 0.12.0 files/Files#location().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., label.rangerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#range..startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
116 labeled_file.max_label_stylerust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#max_label_style. = label.stylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#style.;
117 }
118 labeled_file
119 }
120 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
121 // no other diagnostic referenced this file yet
122 labeled_files.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LabeledFilerust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile# {
123 file_idrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#file_id.: label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id.,
124 startrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#start.: label.rangerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#range..startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.,
125 namerust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#name.: files.namerust-analyzer cargo codespan-reporting 0.12.0 files/Files#name().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
126 locationrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#location.: files.locationrust-analyzer cargo codespan-reporting 0.12.0 files/Files#location().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., label.rangerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#range..startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
127 num_multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#num_multi_labels.: 0,
128 linesrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#lines.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().(),
129 max_label_stylerust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#max_label_style.: label.stylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#style.,
130 });
131 // this unwrap should never fail because we just pushed an element
132 labeled_files
133 .last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().()
134 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("just pushed an element that disappeared")
135 }
136 };
137
138 // insert context lines before label
139 // start from 1 because 0 would be the start of the label itself
140 for offset in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.configrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#config..before_label_linesrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#before_label_lines. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 {
141 let index = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(index) = start_line_index.checked_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_sub().(offset) {
142 index
143 } else {
144 // we are going from smallest to largest offset, so if
145 // the offset can not be subtracted from the start we
146 // reached the first line
147 break;
148 };
149
150 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(range) = files.line_rangerust-analyzer cargo codespan-reporting 0.12.0 files/Files#line_range().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., index) {
151 let line =
152 labeled_file.get_or_insert_linerust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`LabeledFile<'diagnostic, FileId>`]get_or_insert_line().(index, range, start_line_number 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().offset);
153 line.must_renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#must_render. = true;
154 } else {
155 break;
156 }
157 }
158
159 // insert context lines after label
160 // start from 1 because 0 would be the end of the label itself
161 for offset in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.configrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#config..after_label_linesrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#after_label_lines. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 {
162 let index = end_line_index
163 .checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(offset)
164 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("line index too big");
165
166 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(range) = files.line_rangerust-analyzer cargo codespan-reporting 0.12.0 files/Files#line_range().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., index) {
167 let line =
168 labeled_file.get_or_insert_linerust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`LabeledFile<'diagnostic, FileId>`]get_or_insert_line().(index, range, end_line_number rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().offset);
169 line.must_renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#must_render. = true;
170 } else {
171 break;
172 }
173 }
174
175 if start_line_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().end_line_index {
176 // Single line
177 //
178 // ```text
179 // 2 │ (+ test "")
180 // │ ^^ expected `Int` but found `String`
181 // ```
182 let label_start = label.rangerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#range..startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start. 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().start_line_range.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.;
183 // Ensure that we print at least one caret, even when we
184 // have a zero-length source range.
185 let label_end =
186 usize::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(label.rangerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#range..endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end. 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().start_line_range.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start., label_start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1);
187
188 let line = labeled_file.get_or_insert_linerust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`LabeledFile<'diagnostic, FileId>`]get_or_insert_line().(
189 start_line_index,
190 start_line_range,
191 start_line_number,
192 );
193
194 // Ensure that the single line labels are lexicographically
195 // sorted by the range of source code that they cover.
196 let index = match line.single_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#single_labels..binary_search_byrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]binary_search_by().(|(_, range, _)| {
197 // `Range<usize>` doesn't implement `Ord`, so convert to `(usize, usize)`
198 // to piggyback off its lexicographic comparison implementation.
199 (range.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start., range.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end.).cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core tuple/impl#[`(U, T)`][Ord]cmp().(&(label_start, label_end))
200 }) {
201 // If the ranges are the same, order the labels in reverse
202 // to how they were originally specified in the diagnostic.
203 // This helps with printing in the renderer.
204 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(index) | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(index) => index,
205 };
206
207 line.single_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#single_labels.
208 .insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(index, (label.stylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#style., label_start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#label_end, &label.messagerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#message.));
209
210 // If this line is not rendered, the SingleLabel is not visible.
211 line.must_renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#must_render. = true;
212 } else {
213 // Multiple lines
214 //
215 // ```text
216 // 4 │ fizz₁ num = case (mod num 5) (mod num 3) of
217 // │ ╭─────────────^
218 // 5 │ │ 0 0 => "FizzBuzz"
219 // 6 │ │ 0 _ => "Fizz"
220 // 7 │ │ _ 0 => "Buzz"
221 // 8 │ │ _ _ => num
222 // │ ╰──────────────^ `case` clauses have incompatible types
223 // ```
224
225 let label_index = labeled_file.num_multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#num_multi_labels.;
226 labeled_file.num_multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#num_multi_labels. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
227
228 // First labeled line
229 let label_start = label.rangerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#range..startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start. 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().start_line_range.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.;
230
231 let start_line = labeled_file.get_or_insert_linerust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`LabeledFile<'diagnostic, FileId>`]get_or_insert_line().(
232 start_line_index,
233 start_line_range.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`][Clone]clone().(),
234 start_line_number,
235 );
236
237 start_line.multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#multi_labels..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((
238 label_index,
239 label.stylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#style.,
240 MultiLabelrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/MultiLabel#::Toprust-analyzer cargo codespan-reporting 0.12.0 term/renderer/MultiLabel#Top#(label_start),
241 ));
242
243 // The first line has to be rendered so the start of the label is visible.
244 start_line.must_renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#must_render. = true;
245
246 // Marked lines
247 //
248 // ```text
249 // 5 │ │ 0 0 => "FizzBuzz"
250 // 6 │ │ 0 _ => "Fizz"
251 // 7 │ │ _ 0 => "Buzz"
252 // ```
253 for line_index in (start_line_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1)..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end_line_index {
254 let line_range = files.line_rangerust-analyzer cargo codespan-reporting 0.12.0 files/Files#line_range().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., line_index)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
255 let line_number = files.line_numberrust-analyzer cargo codespan-reporting 0.12.0 files/Files#line_number().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., line_index)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
256
257 outer_padding = corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(outer_padding, count_digitsrust-analyzer cargo codespan-reporting 0.12.0 term/views/count_digits().(line_number));
258
259 let line = labeled_file.get_or_insert_linerust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`LabeledFile<'diagnostic, FileId>`]get_or_insert_line().(line_index, line_range, line_number);
260
261 line.multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#multi_labels.
262 .pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((label_index, label.stylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#style., MultiLabelrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/MultiLabel#::Leftrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/MultiLabel#Left#));
263
264 // The line should be rendered to match the configuration of how much context to show.
265 line.must_renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#must_render. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitOrAssign<Self>`]bitor_assign().
266 // Is this line part of the context after the start of the label?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitOrAssign<Self>`]bitor_assign().
267 line_index 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().start_line_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().self.configrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#config..start_context_linesrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#start_context_lines.
268 ||
269 // Is this line part of the context before the end of the label?
270 end_line_index 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().line_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().self.configrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#config..end_context_linesrust-analyzer cargo codespan-reporting 0.12.0 term/config/Config#end_context_lines.;
271 }
272
273 // Last labeled line
274 //
275 // ```text
276 // 8 │ │ _ _ => num
277 // │ ╰──────────────^ `case` clauses have incompatible types
278 // ```
279 let label_end = label.rangerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#range..endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end. 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().end_line_range.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.;
280
281 let end_line = labeled_file.get_or_insert_linerust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`LabeledFile<'diagnostic, FileId>`]get_or_insert_line().(
282 end_line_index,
283 end_line_range,
284 end_line_number,
285 );
286
287 end_line.multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#multi_labels..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((
288 label_index,
289 label.stylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#style.,
290 MultiLabelrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/MultiLabel#::Bottomrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/MultiLabel#Bottom#(label_end, &label.messagerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#message.),
291 ));
292
293 // The last line has to be rendered so the end of the label is visible.
294 end_line.must_renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#must_render. = true;
295 }
296 }
297
298 // Header and message
299 //
300 // ```text
301 // error[E0001]: unexpected type in `+` application
302 // ```
303 renderer.render_headerrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]render_header().(
304 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
305 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic..severityrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#severity.,
306 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic..coderust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#code..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().(),
307 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic..messagerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#message..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().(),
308 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
309
310 // Source snippets
311 //
312 // ```text
313 // ┌─ test:2:9
314 // │
315 // 2 │ (+ test "")
316 // │ ^^ expected `Int` but found `String`
317 // │
318 // ```
319 let mut labeled_files = labeled_files.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
320 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(labeled_file) = labeled_files.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().() {
321 let source = files.sourcerust-analyzer cargo codespan-reporting 0.12.0 files/Files#source().(labeled_file.file_idrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#file_id.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
322 let source = source.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().();
323
324 // Top left border and locus.
325 //
326 // ```text
327 // ┌─ test:2:9
328 // ```
329 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().labeled_file.linesrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#lines..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]is_empty().() {
330 renderer.render_snippet_startrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]render_snippet_start().(
331 outer_padding,
332 &Locusrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/Locus# {
333 namerust-analyzer cargo codespan-reporting 0.12.0 term/renderer/Locus#name.: labeled_file.namerust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#name.,
334 locationrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/Locus#location.: labeled_file.locationrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#location.,
335 },
336 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
337 renderer.render_snippet_emptyrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]render_snippet_empty().(
338 outer_padding,
339 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic..severityrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#severity.,
340 labeled_file.num_multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#num_multi_labels.,
341 &[],
342 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
343 }
344
345 let mut lines = labeled_file
346 .linesrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#lines.
347 .iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]iter().()
348 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|(_, line)| line.must_renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#must_render.)
349 .peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
350
351 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((line_index, line)) = lines.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().() {
352 renderer.render_snippet_sourcerust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]render_snippet_source().(
353 outer_padding,
354 line.numberrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#number.,
355 &source[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().line.rangerust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#range..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`Range<Idx>`][Clone]clone().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
356 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic..severityrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#severity.,
357 &line.single_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#single_labels.,
358 labeled_file.num_multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#num_multi_labels.,
359 &line.multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#multi_labels.,
360 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
361
362 // Check to see if we need to render any intermediate stuff
363 // before rendering the next line.
364 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((next_line_index, next_line)) = lines.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() {
365 match next_line_index.checked_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_sub().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().line_index) {
366 // Consecutive lines
367 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1) => {}
368 // One line between the current line and the next line
369 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2) => {
370 // Write a source line
371 let file_id = labeled_file.file_idrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#file_id.;
372
373 // This line was not intended to be rendered initially.
374 // To render the line right, we have to get back the original labels.
375 let labels = labeled_file
376 .linesrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#lines.
377 .getrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]get().(&(line_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Add<usize>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Add<usize>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Add<usize>`]add().1))
378 .map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(&[][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()., |line| &line.multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#multi_labels.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
379
380 renderer.render_snippet_sourcerust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]render_snippet_source().(
381 outer_padding,
382 files.line_numberrust-analyzer cargo codespan-reporting 0.12.0 files/Files#line_number().(file_id, line_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Add<usize>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Add<usize>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Add<usize>`]add().1)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
383 &source[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().files.line_rangerust-analyzer cargo codespan-reporting 0.12.0 files/Files#line_range().(file_id, line_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Add<usize>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Add<usize>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&usize`][`Add<usize>`]add().1)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
384 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic..severityrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#severity.,
385 &[],
386 labeled_file.num_multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#num_multi_labels.,
387 labels,
388 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
389 }
390 // More than one line between the current line and the next line.
391 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
392 // Source break
393 //
394 // ```text
395 // ·
396 // ```
397 renderer.render_snippet_breakrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]render_snippet_break().(
398 outer_padding,
399 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic..severityrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#severity.,
400 labeled_file.num_multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#num_multi_labels.,
401 &next_line.multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/Line#multi_labels.,
402 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
403 }
404 }
405 }
406 }
407
408 // Check to see if we should render a trailing border after the
409 // final line of the snippet.
410 if labeled_files.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() && self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic..notesrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#notes..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
411 // We don't render a border if we are at the final newline
412 // without trailing notes, because it would end up looking too
413 // spaced-out in combination with the final new line.
414 } else {
415 // Render the trailing snippet border.
416 renderer.render_snippet_emptyrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]render_snippet_empty().(
417 outer_padding,
418 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic..severityrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#severity.,
419 labeled_file.num_multi_labelsrust-analyzer cargo codespan-reporting 0.12.0 term/views/LabeledFile#num_multi_labels.,
420 &[],
421 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
422 }
423 }
424
425 // Additional notes
426 //
427 // ```text
428 // = expected type `Int`
429 // found type `String`
430 // ```
431 for note in &self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/RichDiagnostic#diagnostic..notesrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#notes. {
432 renderer.render_snippet_noterust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]render_snippet_note().(outer_padding, note)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
433 }
434 renderer.render_emptyrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]render_empty().()
435 }
436 }
437
438 /// Output a short diagnostic, with a line number, severity, and message.
439 pub struct ShortDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#<'diagnostic, FileId> {
440 diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#diagnostic.: &'diagnostic Diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#<FileId>,
441 show_notesrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#show_notes.: bool,
442 }
443
444 impl<'diagnostic, FileId> ShortDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#<'diagnostic, FileId>
445 where
446 FileId: Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#,
447 {
448 pub fn newrust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`ShortDiagnostic<'diagnostic, FileId>`]new().(
449 diagnostic: &'diagnostic Diagnosticrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#<FileId>,
450 show_notes: bool,
451 ) -> ShortDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#<'diagnostic, FileId> {
452 ShortDiagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic# {
453 diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#diagnostic.,
454 show_notesrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#show_notes.,
455 }
456 }
457
458 pub fn renderrust-analyzer cargo codespan-reporting 0.12.0 term/views/impl#[`ShortDiagnostic<'diagnostic, FileId>`]render().<'files>(
459 &self,
460 files: &'files (impl Filesrust-analyzer cargo codespan-reporting 0.12.0 files/Files#<'files, FileIdrust-analyzer cargo codespan-reporting 0.12.0 files/Files#FileId# = FileId> + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#),
461 renderer: &mut Rendererrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/Renderer#<'_, '_>,
462 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo codespan-reporting 0.12.0 files/Error#>
463 where
464 FileId: 'files,
465 {
466 // Located headers
467 //
468 // ```text
469 // test:2:9: error[E0001]: unexpected type in `+` application
470 // ```
471 let mut primary_labels_encountered = 0;
472 let labels = self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#diagnostic..labelsrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#labels..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().();
473 for label in labels.filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|label| label.stylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#style. rust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[LabelStyle][`PartialEq<Self>`]eq().==rust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[LabelStyle][`PartialEq<Self>`]eq(). rust-analyzer cargo codespan-reporting 0.12.0 diagnostic/impl#[LabelStyle][`PartialEq<Self>`]eq().LabelStylerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/LabelStyle#::Primaryrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/LabelStyle#Primary#) {
474 primary_labels_encountered rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1;
475
476 renderer.render_headerrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]render_header().(
477 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&Locusrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/Locus# {
478 namerust-analyzer cargo codespan-reporting 0.12.0 term/renderer/Locus#name.: files.namerust-analyzer cargo codespan-reporting 0.12.0 files/Files#name().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
479 locationrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/Locus#location.: files.locationrust-analyzer cargo codespan-reporting 0.12.0 files/Files#location().(label.file_idrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#file_id., label.rangerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Label#range..startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
480 }),
481 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#diagnostic..severityrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#severity.,
482 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#diagnostic..coderust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#code..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().(),
483 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#diagnostic..messagerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#message..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().(),
484 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
485 }
486
487 // Fallback to printing a non-located header if no primary labels were encountered
488 //
489 // ```text
490 // error[E0002]: Bad config found
491 // ```
492 if primary_labels_encountered rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 {
493 renderer.render_headerrust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]render_header().(
494 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
495 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#diagnostic..severityrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#severity.,
496 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#diagnostic..coderust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#code..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().(),
497 self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#diagnostic..messagerust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#message..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().(),
498 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
499 }
500
501 if self.show_notesrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#show_notes. {
502 // Additional notes
503 //
504 // ```text
505 // = expected type `Int`
506 // found type `String`
507 // ```
508 for note in &self.diagnosticrust-analyzer cargo codespan-reporting 0.12.0 term/views/ShortDiagnostic#diagnostic..notesrust-analyzer cargo codespan-reporting 0.12.0 diagnostic/Diagnostic#notes. {
509 renderer.render_snippet_noterust-analyzer cargo codespan-reporting 0.12.0 term/renderer/impl#[`Renderer<'writer, 'config>`]render_snippet_note().(0, note)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
510 }
511 }
512
513 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
514 }
515 }