diff options
| author | bors <bors@rust-lang.org> | 2017-08-30 11:08:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-08-30 11:08:26 +0000 |
| commit | ca9cf3594ab25d2809ac576dfc9defb8e87b45b8 (patch) | |
| tree | c9445d8732ffdea1b395e9e2c0da993574db2e0a /src/librustc_errors | |
| parent | c66e7fa8dee0b6b2b5439e2bd527ab66c9fbde13 (diff) | |
| parent | a0c32641fd8bff11b657bfb87d9ade5487d336ae (diff) | |
| download | rust-ca9cf3594ab25d2809ac576dfc9defb8e87b45b8.tar.gz rust-ca9cf3594ab25d2809ac576dfc9defb8e87b45b8.zip | |
Auto merge of #43968 - petrochenkov:span2, r=michaelwoerister
Make fields of `Span` private I actually tried to intern spans and benchmark the result<sup>*</sup>, and this was a prerequisite. This kind of encapsulation will be a prerequisite for any other attempt to compress span's representation, so I decided to submit this change alone. The issue https://github.com/rust-lang/rust/issues/43088 seems relevant, but it looks like `SpanId` won't be able to reuse this interface, unless the tables are global (like interner that I tried) and are not a part of HIR. r? @michaelwoerister anyway <sup>*</sup> Interning means 2-3 times more space is required for a single span, but duplicates are free. In practice it turned out that duplicates are not *that* common, so more memory was wasted by interning rather than saved.
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/emitter.rs | 12 | ||||
| -rw-r--r-- | src/librustc_errors/lib.rs | 18 |
2 files changed, 13 insertions, 17 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 53d90531cc9..daa132dbf62 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -183,8 +183,8 @@ impl EmitterWriter { continue; } - let lo = cm.lookup_char_pos(span_label.span.lo); - let mut hi = cm.lookup_char_pos(span_label.span.hi); + let lo = cm.lookup_char_pos(span_label.span.lo()); + let mut hi = cm.lookup_char_pos(span_label.span.hi()); // Watch out for "empty spans". If we get a span like 6..6, we // want to just display a `^` at 6, so convert that to @@ -683,7 +683,7 @@ impl EmitterWriter { if let Some(ref cm) = self.cm { for primary_span in msp.primary_spans() { if primary_span != &DUMMY_SP { - let hi = cm.lookup_char_pos(primary_span.hi); + let hi = cm.lookup_char_pos(primary_span.hi()); if hi.line > max { max = hi.line; } @@ -691,7 +691,7 @@ impl EmitterWriter { } for span_label in msp.span_labels() { if span_label.span != DUMMY_SP { - let hi = cm.lookup_char_pos(span_label.span.hi); + let hi = cm.lookup_char_pos(span_label.span.hi()); if hi.line > max { max = hi.line; } @@ -914,7 +914,7 @@ impl EmitterWriter { let (primary_lo, cm) = if let (Some(cm), Some(ref primary_span)) = (self.cm.as_ref(), msp.primary_span().as_ref()) { if primary_span != &&DUMMY_SP { - (cm.lookup_char_pos(primary_span.lo), cm) + (cm.lookup_char_pos(primary_span.lo()), cm) } else { emit_to_destination(&buffer.render(), level, &mut self.dst)?; return Ok(()); @@ -1091,7 +1091,7 @@ impl EmitterWriter { Some(Style::HeaderMsg)); let suggestions = suggestion.splice_lines(cm.borrow()); - let span_start_pos = cm.lookup_char_pos(primary_sub.span.lo); + let span_start_pos = cm.lookup_char_pos(primary_sub.span.lo()); let line_start = span_start_pos.line; draw_col_separator_no_space(&mut buffer, 1, max_line_num_len + 1); let mut row_num = 2; diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 2c756be02f1..d9b0f4ac8a6 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -148,16 +148,12 @@ impl CodeSuggestion { // Assumption: all spans are in the same file, and all spans // are disjoint. Sort in ascending order. - primary_spans.sort_by_key(|sp| sp.0.lo); + primary_spans.sort_by_key(|sp| sp.0.lo()); // Find the bounding span. - let lo = primary_spans.iter().map(|sp| sp.0.lo).min().unwrap(); - let hi = primary_spans.iter().map(|sp| sp.0.hi).min().unwrap(); - let bounding_span = Span { - lo, - hi, - ctxt: NO_EXPANSION, - }; + let lo = primary_spans.iter().map(|sp| sp.0.lo()).min().unwrap(); + let hi = primary_spans.iter().map(|sp| sp.0.hi()).min().unwrap(); + let bounding_span = Span::new(lo, hi, NO_EXPANSION); let lines = cm.span_to_lines(bounding_span).unwrap(); assert!(!lines.lines.is_empty()); @@ -171,14 +167,14 @@ impl CodeSuggestion { // // Finally push the trailing line segment of the last span let fm = &lines.file; - let mut prev_hi = cm.lookup_char_pos(bounding_span.lo); + let mut prev_hi = cm.lookup_char_pos(bounding_span.lo()); prev_hi.col = CharPos::from_usize(0); let mut prev_line = fm.get_line(lines.lines[0].line_index); let mut bufs = vec![(String::new(), false); self.substitutions()]; for (sp, substitutes) in primary_spans { - let cur_lo = cm.lookup_char_pos(sp.lo); + let cur_lo = cm.lookup_char_pos(sp.lo()); for (&mut (ref mut buf, ref mut underline), substitute) in bufs.iter_mut() .zip(substitutes) { if prev_hi.line == cur_lo.line { @@ -208,7 +204,7 @@ impl CodeSuggestion { } buf.push_str(substitute); } - prev_hi = cm.lookup_char_pos(sp.hi); + prev_hi = cm.lookup_char_pos(sp.hi()); prev_line = fm.get_line(prev_hi.line - 1); } for &mut (ref mut buf, _) in &mut bufs { |
