From f481879d2ae82a6f6ebe33202d4a1cfa8aece5ed Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Tue, 12 Jul 2016 12:37:57 -0400 Subject: [PATCH] Fix a couple UI test failures --- src/librustc_errors/emitter.rs | 27 +++++++++++-------- .../ui/mismatched_types/issue-26480.stderr | 19 ++++++------- src/test/ui/mismatched_types/main.stderr | 14 +++++----- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 037d64ba128..5147318d4a6 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -187,23 +187,24 @@ impl EmitterWriter { if let Some(ref cm) = self.cm { for span_label in msp.span_labels() { - let lo = cm.lookup_char_pos(span_label.span.lo); - let hi = cm.lookup_char_pos(span_label.span.hi); + let mut lo = cm.lookup_char_pos(span_label.span.lo); + let mut hi = cm.lookup_char_pos(span_label.span.hi); + let mut is_minimized = false; // If the span is multi-line, simplify down to the span of one character - let (start_col, mut end_col, is_minimized) = if lo.line != hi.line { - (lo.col, CharPos(lo.col.0 + 1), true) - } else { - (lo.col, hi.col, false) - }; + if lo.line != hi.line { + hi.line = lo.line; + hi.col = CharPos(lo.col.0 + 1); + is_minimized = true; + } // 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 // 6..7. This is degenerate input, but it's best to degrade // gracefully -- and the parser likes to supply a span like // that for EOF, in particular. - if start_col == end_col { - end_col.0 += 1; + if lo.col == hi.col { + hi.col = CharPos(lo.col.0 + 1); } add_annotation_to_file(&mut output, @@ -530,7 +531,7 @@ impl EmitterWriter { buffer.prepend(buffer_msg_line_offset, "--> ", Style::LineNumber); let loc = primary_lo.clone(); buffer.append(buffer_msg_line_offset, - &format!("{}:{}:{}", loc.file.name, loc.line, loc.col.0), + &format!("{}:{}:{}", loc.file.name, loc.line, loc.col.0 + 1), Style::LineAndColumn); for i in 0..max_line_num_len { buffer.prepend(buffer_msg_line_offset, " ", Style::NoStyle); @@ -593,6 +594,10 @@ impl EmitterWriter { } } + if let Some(ref primary_span) = msp.primary_span().as_ref() { + self.render_macro_backtrace_old_school(primary_span, &mut buffer)?; + } + // final step: take our styled buffer, render it, then output it emit_to_destination(&buffer.render(), level, &mut self.dst); @@ -1180,7 +1185,7 @@ impl EmitterWriter { } let snippet = cm.span_to_string(trace.call_site); buffer.append(line_offset, &format!("{} ", snippet), Style::NoStyle); - buffer.append(line_offset, "Note", Style::Level(Level::Note)); + buffer.append(line_offset, "note", Style::Level(Level::Note)); buffer.append(line_offset, ": ", Style::NoStyle); buffer.append(line_offset, &diag_string, Style::OldSchoolNoteText); } diff --git a/src/test/ui/mismatched_types/issue-26480.stderr b/src/test/ui/mismatched_types/issue-26480.stderr index c00594a59c1..63f2ab4d7c6 100644 --- a/src/test/ui/mismatched_types/issue-26480.stderr +++ b/src/test/ui/mismatched_types/issue-26480.stderr @@ -1,15 +1,16 @@ -error: mismatched types [--explain E0308] +error[E0308]: mismatched types --> $DIR/issue-26480.rs:27:19 - |> -27 |> $arr.len() * size_of($arr[0])); - |> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u64, found usize -$DIR/issue-26480.rs:38:5: 38:19: note: in this expansion of write! (defined in $DIR/issue-26480.rs) + | +27 | $arr.len() * size_of($arr[0])); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u64, found usize +$DIR/issue-26480.rs:38:5: 38:19 note: in this expansion of write! (defined in $DIR/issue-26480.rs) error: non-scalar cast: `_` as `()` --> $DIR/issue-26480.rs:33:19 - |> -33 |> ($x:expr) => ($x as ()) - |> ^^^^^^^^ -$DIR/issue-26480.rs:39:5: 39:14: note: in this expansion of cast! (defined in $DIR/issue-26480.rs) + | +33 | ($x:expr) => ($x as ()) + | ^^^^^^^^ +$DIR/issue-26480.rs:39:5: 39:14 note: in this expansion of cast! (defined in $DIR/issue-26480.rs) error: aborting due to 2 previous errors + diff --git a/src/test/ui/mismatched_types/main.stderr b/src/test/ui/mismatched_types/main.stderr index 1af332ee5be..ae1d417eca9 100644 --- a/src/test/ui/mismatched_types/main.stderr +++ b/src/test/ui/mismatched_types/main.stderr @@ -1,9 +1,11 @@ -error: mismatched types [--explain E0308] +error[E0308]: mismatched types --> $DIR/main.rs:14:18 - |> -14 |> let x: u32 = ( - |> ^ expected u32, found () -note: expected type `u32` -note: found type `()` + | +14 | let x: u32 = ( + | ^ expected u32, found () + | + = note: expected type `u32` + = note: found type `()` error: aborting due to previous error +