Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2f2c3e1

Browse files
author
Jonathan Turner
committedJul 14, 2016
DCE and fixing some internal tests
1 parent f481879 commit 2f2c3e1

File tree

4 files changed

+132
-1213
lines changed

4 files changed

+132
-1213
lines changed
 

‎src/librustc_errors/emitter.rs

Lines changed: 32 additions & 374 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ use syntax_pos::{COMMAND_LINE_SP, DUMMY_SP, FileMap, Span, MultiSpan, LineInfo,
1414
use registry;
1515

1616
use check_old_skool;
17-
use {Level, RenderSpan, CodeSuggestion, DiagnosticBuilder, CodeMapper};
17+
use {Level, CodeSuggestion, DiagnosticBuilder, CodeMapper};
1818
use RenderSpan::*;
19-
use Level::*;
20-
use snippet::{SnippetData, StyledString, Style, FormatMode, Annotation, Line};
19+
use snippet::{StyledString, Style, FormatMode, Annotation, Line};
2120
use styled_buffer::StyledBuffer;
2221

23-
use std::{cmp, fmt};
22+
use std::cmp;
2423
use std::io::prelude::*;
2524
use std::io;
2625
use std::rc::Rc;
@@ -73,10 +72,6 @@ pub struct EmitterWriter {
7372
registry: Option<registry::Registry>,
7473
cm: Option<Rc<CodeMapper>>,
7574

76-
/// Is this the first error emitted thus far? If not, we emit a
77-
/// `\n` before the top-level errors.
78-
first: bool,
79-
8075
// For now, allow an old-school mode while we transition
8176
format_mode: FormatMode
8277
}
@@ -112,13 +107,11 @@ impl EmitterWriter {
112107
EmitterWriter { dst: dst,
113108
registry: registry,
114109
cm: code_map,
115-
first: true,
116110
format_mode: format_mode.clone() }
117111
} else {
118112
EmitterWriter { dst: Raw(Box::new(io::stderr())),
119113
registry: registry,
120114
cm: code_map,
121-
first: true,
122115
format_mode: format_mode.clone() }
123116
}
124117
}
@@ -131,23 +124,9 @@ impl EmitterWriter {
131124
EmitterWriter { dst: Raw(dst),
132125
registry: registry,
133126
cm: code_map,
134-
first: true,
135127
format_mode: format_mode.clone() }
136128
}
137129

138-
fn emit_message(&mut self,
139-
rsp: &RenderSpan,
140-
msg: &str,
141-
code: Option<&str>,
142-
lvl: Level,
143-
is_header: bool,
144-
show_snippet: bool) {
145-
match self.emit_message_(rsp, msg, code, lvl, is_header, show_snippet) {
146-
Ok(()) => { }
147-
Err(e) => panic!("failed to emit error: {}", e)
148-
}
149-
}
150-
151130
fn preprocess_annotations(&self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
152131
fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
153132
file: Rc<FileMap>,
@@ -187,7 +166,7 @@ impl EmitterWriter {
187166

188167
if let Some(ref cm) = self.cm {
189168
for span_label in msp.span_labels() {
190-
let mut lo = cm.lookup_char_pos(span_label.span.lo);
169+
let lo = cm.lookup_char_pos(span_label.span.lo);
191170
let mut hi = cm.lookup_char_pos(span_label.span.hi);
192171
let mut is_minimized = false;
193172

@@ -478,7 +457,7 @@ impl EmitterWriter {
478457

479458
if msp.primary_spans().is_empty() && msp.span_labels().is_empty() && is_secondary {
480459
// This is a secondary message with no span info
481-
for i in 0..max_line_num_len {
460+
for _ in 0..max_line_num_len {
482461
buffer.prepend(0, " ", Style::NoStyle);
483462
}
484463
draw_note_separator(&mut buffer, 0, max_line_num_len + 1);
@@ -511,7 +490,7 @@ impl EmitterWriter {
511490
cm.lookup_char_pos(primary_span.lo)
512491
} else {
513492
// If we don't have span information, emit and exit
514-
emit_to_destination(&buffer.render(), level, &mut self.dst);
493+
emit_to_destination(&buffer.render(), level, &mut self.dst)?;
515494
return Ok(());
516495
};
517496
if let Ok(pos) =
@@ -526,19 +505,19 @@ impl EmitterWriter {
526505
let is_primary = primary_lo.file.name == annotated_file.file.name;
527506
if is_primary {
528507
// remember where we are in the output buffer for easy reference
529-
let mut buffer_msg_line_offset = buffer.num_lines();
508+
let buffer_msg_line_offset = buffer.num_lines();
530509

531510
buffer.prepend(buffer_msg_line_offset, "--> ", Style::LineNumber);
532511
let loc = primary_lo.clone();
533512
buffer.append(buffer_msg_line_offset,
534513
&format!("{}:{}:{}", loc.file.name, loc.line, loc.col.0 + 1),
535514
Style::LineAndColumn);
536-
for i in 0..max_line_num_len {
515+
for _ in 0..max_line_num_len {
537516
buffer.prepend(buffer_msg_line_offset, " ", Style::NoStyle);
538517
}
539518
} else {
540519
// remember where we are in the output buffer for easy reference
541-
let mut buffer_msg_line_offset = buffer.num_lines();
520+
let buffer_msg_line_offset = buffer.num_lines();
542521

543522
// Add spacing line
544523
draw_col_separator(&mut buffer, buffer_msg_line_offset, max_line_num_len + 1);
@@ -548,13 +527,13 @@ impl EmitterWriter {
548527
buffer.append(buffer_msg_line_offset + 1,
549528
&annotated_file.file.name,
550529
Style::LineAndColumn);
551-
for i in 0..max_line_num_len {
530+
for _ in 0..max_line_num_len {
552531
buffer.prepend(buffer_msg_line_offset + 1, " ", Style::NoStyle);
553532
}
554533
}
555534

556535
// Put in the spacer between the location and annotated source
557-
let mut buffer_msg_line_offset = buffer.num_lines();
536+
let buffer_msg_line_offset = buffer.num_lines();
558537
draw_col_separator(&mut buffer, buffer_msg_line_offset, max_line_num_len + 1);
559538

560539
// Next, output the annotate source for this file
@@ -599,7 +578,7 @@ impl EmitterWriter {
599578
}
600579

601580
// final step: take our styled buffer, render it, then output it
602-
emit_to_destination(&buffer.render(), level, &mut self.dst);
581+
emit_to_destination(&buffer.render(), level, &mut self.dst)?;
603582

604583
Ok(())
605584
}
@@ -624,12 +603,6 @@ impl EmitterWriter {
624603
assert!(!lines.lines.is_empty());
625604

626605
let complete = suggestion.splice_lines(cm.borrow());
627-
let line_count = cmp::min(lines.lines.len(), MAX_HIGHLIGHT_LINES);
628-
let display_lines = &lines.lines[..line_count];
629-
630-
let fm = &*lines.file;
631-
// Calculate the widest number to format evenly
632-
let max_digits = line_num_max_digits(display_lines.last().unwrap());
633606

634607
// print the suggestion without any line numbers, but leave
635608
// space for them. This helps with lining up with previous
@@ -646,7 +619,7 @@ impl EmitterWriter {
646619
if let Some(_) = lines.next() {
647620
buffer.append(row_num, "...", Style::NoStyle);
648621
}
649-
emit_to_destination(&buffer.render(), level, &mut self.dst);
622+
emit_to_destination(&buffer.render(), level, &mut self.dst)?;
650623
}
651624
Ok(())
652625
}
@@ -664,7 +637,10 @@ impl EmitterWriter {
664637
if !db.children.is_empty() {
665638
let mut buffer = StyledBuffer::new();
666639
draw_col_separator(&mut buffer, 0, max_line_num_len + 1);
667-
emit_to_destination(&buffer.render(), &db.level, &mut self.dst);
640+
match emit_to_destination(&buffer.render(), &db.level, &mut self.dst) {
641+
Ok(()) => (),
642+
Err(e) => panic!("failed to emit error: {}", e)
643+
}
668644
}
669645
for child in &db.children {
670646
match child.render_span {
@@ -704,7 +680,10 @@ impl EmitterWriter {
704680
}
705681
Err(e) => panic!("failed to emit error: {}", e)
706682
}
707-
write!(&mut self.dst, "\n");
683+
match write!(&mut self.dst, "\n") {
684+
Err(e) => panic!("failed to emit error: {}", e),
685+
_ => ()
686+
}
708687
}
709688
fn emit_message_old_school(&mut self,
710689
msp: &MultiSpan,
@@ -744,21 +723,21 @@ impl EmitterWriter {
744723
}
745724

746725
if !show_snippet {
747-
emit_to_destination(&buffer.render(), level, &mut self.dst);
726+
emit_to_destination(&buffer.render(), level, &mut self.dst)?;
748727
return Ok(());
749728
}
750729

751730
// Watch out for various nasty special spans; don't try to
752731
// print any filename or anything for those.
753732
match msp.primary_span() {
754733
Some(COMMAND_LINE_SP) | Some(DUMMY_SP) => {
755-
emit_to_destination(&buffer.render(), level, &mut self.dst);
734+
emit_to_destination(&buffer.render(), level, &mut self.dst)?;
756735
return Ok(());
757736
}
758737
_ => { }
759738
}
760739

761-
let mut annotated_files = self.preprocess_annotations(msp);
740+
let annotated_files = self.preprocess_annotations(msp);
762741

763742
if let (Some(ref cm), Some(ann_file), Some(ref primary_span)) =
764743
(self.cm.as_ref(), annotated_files.first(), msp.primary_span().as_ref()) {
@@ -781,7 +760,7 @@ impl EmitterWriter {
781760
buffer.puts(line_offset, 0, &file_pos, Style::FileNameStyle);
782761
buffer.puts(line_offset, file_pos_len, &source_string, Style::Quotation);
783762
// Sort the annotations by (start, end col)
784-
let mut annotations = ann_file.lines[0].annotations.clone();
763+
let annotations = ann_file.lines[0].annotations.clone();
785764

786765
// Next, create the highlight line.
787766
for annotation in &annotations {
@@ -830,7 +809,7 @@ impl EmitterWriter {
830809
}
831810

832811
// final step: take our styled buffer, render it, then output it
833-
emit_to_destination(&buffer.render(), level, &mut self.dst);
812+
emit_to_destination(&buffer.render(), level, &mut self.dst)?;
834813
Ok(())
835814
}
836815
fn emit_suggestion_old_school(&mut self,
@@ -874,7 +853,7 @@ impl EmitterWriter {
874853
let mut row_num = 1;
875854
for line in lines.by_ref().take(MAX_HIGHLIGHT_LINES) {
876855
buffer.append(row_num, &fm.name, Style::FileNameStyle);
877-
for i in 0..max_digits+2 {
856+
for _ in 0..max_digits+2 {
878857
buffer.append(row_num, &" ", Style::NoStyle);
879858
}
880859
buffer.append(row_num, line, Style::NoStyle);
@@ -885,7 +864,7 @@ impl EmitterWriter {
885864
if let Some(_) = lines.next() {
886865
buffer.append(row_num, "...", Style::NoStyle);
887866
}
888-
emit_to_destination(&buffer.render(), level, &mut self.dst);
867+
emit_to_destination(&buffer.render(), level, &mut self.dst)?;
889868
}
890869
Ok(())
891870
}
@@ -905,7 +884,7 @@ impl EmitterWriter {
905884
};
906885

907886
match child.render_span {
908-
Some(FullSpan(ref msp)) => {
887+
Some(FullSpan(_)) => {
909888
match self.emit_message_old_school(&span,
910889
&child.message,
911890
&None,
@@ -940,235 +919,6 @@ impl EmitterWriter {
940919
}
941920
}
942921

943-
fn emit_message_(&mut self,
944-
rsp: &RenderSpan,
945-
msg: &str,
946-
code: Option<&str>,
947-
lvl: Level,
948-
is_header: bool,
949-
show_snippet: bool)
950-
-> io::Result<()> {
951-
let old_school = match self.format_mode {
952-
FormatMode::NewErrorFormat => false,
953-
FormatMode::OriginalErrorFormat => true,
954-
FormatMode::EnvironmentSelected => check_old_skool()
955-
};
956-
957-
if is_header {
958-
if self.first {
959-
self.first = false;
960-
} else {
961-
if !old_school {
962-
write!(self.dst, "\n")?;
963-
}
964-
}
965-
}
966-
967-
match code {
968-
Some(code) if self.registry.as_ref()
969-
.and_then(|registry| registry.find_description(code))
970-
.is_some() => {
971-
let code_with_explain = String::from("--explain ") + code;
972-
if old_school {
973-
let loc = match rsp.span().primary_span() {
974-
Some(COMMAND_LINE_SP) | Some(DUMMY_SP) => "".to_string(),
975-
Some(ps) => if let Some(ref cm) = self.cm {
976-
cm.span_to_string(ps)
977-
} else {
978-
"".to_string()
979-
},
980-
None => "".to_string()
981-
};
982-
print_diagnostic(&mut self.dst, &loc, lvl, msg, Some(code))?
983-
}
984-
else {
985-
print_diagnostic(&mut self.dst, "", lvl, msg, Some(&code_with_explain))?
986-
}
987-
}
988-
_ => {
989-
if old_school {
990-
let loc = match rsp.span().primary_span() {
991-
Some(COMMAND_LINE_SP) | Some(DUMMY_SP) => "".to_string(),
992-
Some(ps) => if let Some(ref cm) = self.cm {
993-
cm.span_to_string(ps)
994-
} else {
995-
"".to_string()
996-
},
997-
None => "".to_string()
998-
};
999-
print_diagnostic(&mut self.dst, &loc, lvl, msg, code)?
1000-
}
1001-
else {
1002-
print_diagnostic(&mut self.dst, "", lvl, msg, code)?
1003-
}
1004-
}
1005-
}
1006-
1007-
if !show_snippet {
1008-
return Ok(());
1009-
}
1010-
1011-
// Watch out for various nasty special spans; don't try to
1012-
// print any filename or anything for those.
1013-
match rsp.span().primary_span() {
1014-
Some(COMMAND_LINE_SP) | Some(DUMMY_SP) => {
1015-
return Ok(());
1016-
}
1017-
_ => { }
1018-
}
1019-
1020-
// Otherwise, print out the snippet etc as needed.
1021-
match *rsp {
1022-
FullSpan(ref msp) => {
1023-
self.highlight_lines(msp, lvl)?;
1024-
if let Some(primary_span) = msp.primary_span() {
1025-
self.print_macro_backtrace(primary_span)?;
1026-
}
1027-
}
1028-
Suggestion(ref suggestion) => {
1029-
self.highlight_suggestion(suggestion)?;
1030-
if let Some(primary_span) = rsp.span().primary_span() {
1031-
self.print_macro_backtrace(primary_span)?;
1032-
}
1033-
}
1034-
}
1035-
if old_school {
1036-
match code {
1037-
Some(code) if self.registry.as_ref()
1038-
.and_then(|registry| registry.find_description(code))
1039-
.is_some() => {
1040-
let loc = match rsp.span().primary_span() {
1041-
Some(COMMAND_LINE_SP) | Some(DUMMY_SP) => "".to_string(),
1042-
Some(ps) => if let Some(ref cm) = self.cm {
1043-
cm.span_to_string(ps)
1044-
} else {
1045-
"".to_string()
1046-
},
1047-
None => "".to_string()
1048-
};
1049-
let msg = "run `rustc --explain ".to_string() + &code.to_string() +
1050-
"` to see a detailed explanation";
1051-
print_diagnostic(&mut self.dst, &loc, Level::Help, &msg,
1052-
None)?
1053-
}
1054-
_ => ()
1055-
}
1056-
}
1057-
Ok(())
1058-
}
1059-
1060-
fn highlight_suggestion(&mut self, suggestion: &CodeSuggestion) -> io::Result<()>
1061-
{
1062-
use std::borrow::Borrow;
1063-
1064-
let primary_span = suggestion.msp.primary_span().unwrap();
1065-
if let Some(ref cm) = self.cm {
1066-
let lines = cm.span_to_lines(primary_span).unwrap();
1067-
1068-
assert!(!lines.lines.is_empty());
1069-
1070-
let complete = suggestion.splice_lines(cm.borrow());
1071-
let line_count = cmp::min(lines.lines.len(), MAX_HIGHLIGHT_LINES);
1072-
let display_lines = &lines.lines[..line_count];
1073-
1074-
let fm = &*lines.file;
1075-
// Calculate the widest number to format evenly
1076-
let max_digits = line_num_max_digits(display_lines.last().unwrap());
1077-
1078-
// print the suggestion without any line numbers, but leave
1079-
// space for them. This helps with lining up with previous
1080-
// snippets from the actual error being reported.
1081-
let mut lines = complete.lines();
1082-
for line in lines.by_ref().take(MAX_HIGHLIGHT_LINES) {
1083-
write!(&mut self.dst, "{0}:{1:2$} {3}\n",
1084-
fm.name, "", max_digits, line)?;
1085-
}
1086-
1087-
// if we elided some lines, add an ellipsis
1088-
if let Some(_) = lines.next() {
1089-
write!(&mut self.dst, "{0:1$} {0:2$} ...\n",
1090-
"", fm.name.len(), max_digits)?;
1091-
}
1092-
}
1093-
Ok(())
1094-
}
1095-
1096-
pub fn highlight_lines(&mut self,
1097-
msp: &MultiSpan,
1098-
lvl: Level)
1099-
-> io::Result<()>
1100-
{
1101-
// Check to see if we have any lines to highlight, exit early if not
1102-
match self.cm {
1103-
None => return Ok(()),
1104-
_ => ()
1105-
}
1106-
1107-
let old_school = match self.format_mode {
1108-
FormatMode::NewErrorFormat => false,
1109-
FormatMode::OriginalErrorFormat => true,
1110-
FormatMode::EnvironmentSelected => check_old_skool()
1111-
};
1112-
1113-
let mut snippet_data = SnippetData::new(self.cm.as_ref().unwrap().clone(),
1114-
msp.primary_span(),
1115-
self.format_mode.clone());
1116-
if old_school {
1117-
let mut output_vec = vec![];
1118-
1119-
for span_label in msp.span_labels() {
1120-
let mut snippet_data = SnippetData::new(self.cm.as_ref().unwrap().clone(),
1121-
Some(span_label.span),
1122-
self.format_mode.clone());
1123-
1124-
snippet_data.push(span_label.span,
1125-
span_label.is_primary,
1126-
span_label.label);
1127-
if span_label.is_primary {
1128-
output_vec.insert(0, snippet_data);
1129-
}
1130-
else {
1131-
output_vec.push(snippet_data);
1132-
}
1133-
}
1134-
1135-
for snippet_data in output_vec.iter() {
1136-
/*
1137-
let rendered_lines = snippet_data.render_lines();
1138-
for rendered_line in &rendered_lines {
1139-
for styled_string in &rendered_line.text {
1140-
self.dst.apply_style(lvl, &rendered_line.kind, styled_string.style)?;
1141-
write!(&mut self.dst, "{}", styled_string.text)?;
1142-
self.dst.reset_attrs()?;
1143-
}
1144-
write!(&mut self.dst, "\n")?;
1145-
}
1146-
*/
1147-
emit_to_destination(&snippet_data.render_lines(), &lvl, &mut self.dst);
1148-
}
1149-
}
1150-
else {
1151-
for span_label in msp.span_labels() {
1152-
snippet_data.push(span_label.span,
1153-
span_label.is_primary,
1154-
span_label.label);
1155-
}
1156-
emit_to_destination(&snippet_data.render_lines(), &lvl, &mut self.dst);
1157-
/*
1158-
let rendered_lines = snippet_data.render_lines();
1159-
for rendered_line in &rendered_lines {
1160-
for styled_string in &rendered_line.text {
1161-
self.dst.apply_style(lvl, &rendered_line.kind, styled_string.style)?;
1162-
write!(&mut self.dst, "{}", styled_string.text)?;
1163-
self.dst.reset_attrs()?;
1164-
}
1165-
write!(&mut self.dst, "\n")?;
1166-
}
1167-
*/
1168-
}
1169-
Ok(())
1170-
}
1171-
1172922
fn render_macro_backtrace_old_school(&mut self,
1173923
sp: &Span,
1174924
buffer: &mut StyledBuffer) -> io::Result<()> {
@@ -1192,24 +942,6 @@ impl EmitterWriter {
1192942
}
1193943
Ok(())
1194944
}
1195-
fn print_macro_backtrace(&mut self,
1196-
sp: Span)
1197-
-> io::Result<()> {
1198-
if let Some(ref cm) = self.cm {
1199-
for trace in cm.macro_backtrace(sp) {
1200-
let mut diag_string =
1201-
format!("in this expansion of {}", trace.macro_decl_name);
1202-
if let Some(def_site_span) = trace.def_site_span {
1203-
diag_string.push_str(
1204-
&format!(" (defined in {})",
1205-
cm.span_to_filename(def_site_span)));
1206-
}
1207-
let snippet = cm.span_to_string(trace.call_site);
1208-
print_diagnostic(&mut self.dst, &snippet, Note, &diag_string, None)?;
1209-
}
1210-
}
1211-
Ok(())
1212-
}
1213945
}
1214946

1215947
fn draw_col_separator(buffer: &mut StyledBuffer, line: usize, col: usize) {
@@ -1230,11 +962,11 @@ fn emit_to_destination(rendered_buffer: &Vec<Vec<StyledString>>,
1230962
dst: &mut Destination) -> io::Result<()> {
1231963
for line in rendered_buffer {
1232964
for part in line {
1233-
dst.apply_style(lvl.clone(), part.style);
1234-
write!(dst, "{}", part.text);
965+
dst.apply_style(lvl.clone(), part.style)?;
966+
write!(dst, "{}", part.text)?;
1235967
dst.reset_attrs()?;
1236968
}
1237-
write!(dst, "\n");
969+
write!(dst, "\n")?;
1238970
}
1239971
Ok(())
1240972
}
@@ -1249,40 +981,6 @@ fn line_num_max_digits(line: &LineInfo) -> usize {
1249981
digits
1250982
}
1251983

1252-
fn print_diagnostic(dst: &mut Destination,
1253-
topic: &str,
1254-
lvl: Level,
1255-
msg: &str,
1256-
code: Option<&str>)
1257-
-> io::Result<()> {
1258-
if !topic.is_empty() {
1259-
let old_school = check_old_skool();
1260-
if !old_school {
1261-
write!(dst, "{}: ", topic)?;
1262-
}
1263-
else {
1264-
write!(dst, "{} ", topic)?;
1265-
}
1266-
dst.reset_attrs()?;
1267-
}
1268-
dst.start_attr(term::Attr::Bold)?;
1269-
dst.start_attr(term::Attr::ForegroundColor(lvl.color()))?;
1270-
write!(dst, "{}", lvl.to_string())?;
1271-
dst.reset_attrs()?;
1272-
write!(dst, ": ")?;
1273-
dst.start_attr(term::Attr::Bold)?;
1274-
write!(dst, "{}", msg)?;
1275-
1276-
if let Some(code) = code {
1277-
let style = term::Attr::ForegroundColor(term::color::BRIGHT_MAGENTA);
1278-
print_maybe_styled!(dst, style, " [{}]", code.clone())?;
1279-
}
1280-
1281-
dst.reset_attrs()?;
1282-
write!(dst, "\n")?;
1283-
Ok(())
1284-
}
1285-
1286984
#[cfg(unix)]
1287985
fn stderr_isatty() -> bool {
1288986
use libc;
@@ -1374,46 +1072,6 @@ impl Destination {
13741072
}
13751073
Ok(())
13761074
}
1377-
1378-
fn print_maybe_styled(&mut self,
1379-
args: fmt::Arguments,
1380-
color: term::Attr,
1381-
print_newline_at_end: bool)
1382-
-> io::Result<()> {
1383-
match *self {
1384-
Terminal(ref mut t) => {
1385-
t.attr(color)?;
1386-
// If `msg` ends in a newline, we need to reset the color before
1387-
// the newline. We're making the assumption that we end up writing
1388-
// to a `LineBufferedWriter`, which means that emitting the reset
1389-
// after the newline ends up buffering the reset until we print
1390-
// another line or exit. Buffering the reset is a problem if we're
1391-
// sharing the terminal with any other programs (e.g. other rustc
1392-
// instances via `make -jN`).
1393-
//
1394-
// Note that if `msg` contains any internal newlines, this will
1395-
// result in the `LineBufferedWriter` flushing twice instead of
1396-
// once, which still leaves the opportunity for interleaved output
1397-
// to be miscolored. We assume this is rare enough that we don't
1398-
// have to worry about it.
1399-
t.write_fmt(args)?;
1400-
t.reset()?;
1401-
if print_newline_at_end {
1402-
t.write_all(b"\n")
1403-
} else {
1404-
Ok(())
1405-
}
1406-
}
1407-
Raw(ref mut w) => {
1408-
w.write_fmt(args)?;
1409-
if print_newline_at_end {
1410-
w.write_all(b"\n")
1411-
} else {
1412-
Ok(())
1413-
}
1414-
}
1415-
}
1416-
}
14171075
}
14181076

14191077
impl Write for Destination {

‎src/librustc_errors/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,6 @@ pub trait CodeMapper {
8282
fn macro_backtrace(&self, span: Span) -> Vec<MacroBacktrace>;
8383
}
8484

85-
impl RenderSpan {
86-
fn span(&self) -> &MultiSpan {
87-
match *self {
88-
FullSpan(ref msp) |
89-
Suggestion(CodeSuggestion { ref msp, .. }) =>
90-
msp
91-
}
92-
}
93-
}
94-
9585
impl CodeSuggestion {
9686
/// Returns the assembled code suggestion.
9787
pub fn splice_lines(&self, cm: &CodeMapper) -> String {

‎src/librustc_errors/snippet.rs

Lines changed: 2 additions & 731 deletions
Large diffs are not rendered by default.

‎src/libsyntax/codemap.rs

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,9 +1265,9 @@ r"blork2.rs:2:1: 2:12
12651265
println!("r#\"\n{}\"#", str);
12661266
assert_eq!(str, &r#"
12671267
--> dummy.txt:11:1
1268-
|>
1269-
11 |> e-lä-vän
1270-
|> ^
1268+
|
1269+
11 | e-lä-vän
1270+
| ^
12711271
"#[1..]);
12721272
}
12731273

@@ -1333,9 +1333,9 @@ r"blork2.rs:2:1: 2:12
13331333

13341334
let expect_start = &r#"
13351335
--> dummy.txt:1:6
1336-
|>
1337-
1 |> _____aaaaaa____bbbbbb__cccccdd_
1338-
|> ^^^^^^ ^^^^^^ ^^^^^^^
1336+
|
1337+
1 | _____aaaaaa____bbbbbb__cccccdd_
1338+
| ^^^^^^ ^^^^^^ ^^^^^^^
13391339
"#[1..];
13401340

13411341
let span = |sp, expected| {
@@ -1409,28 +1409,28 @@ r"blork2.rs:2:1: 2:12
14091409

14101410
let expect0 = &r#"
14111411
--> dummy.txt:5:1
1412-
|>
1413-
5 |> ccccc
1414-
|> ^
1412+
|
1413+
5 | ccccc
1414+
| ^
14151415
...
1416-
9 |> ddd__eee_
1417-
|> ^^^ ^^^
1418-
10 |> elided
1419-
11 |> __f_gg
1420-
|> ^ ^^
1416+
9 | ddd__eee_
1417+
| ^^^ ^^^
1418+
10 | elided
1419+
11 | __f_gg
1420+
| ^ ^^
14211421
"#[1..];
14221422

14231423
let expect = &r#"
14241424
--> dummy.txt:1:1
1425-
|>
1426-
1 |> aaaaa
1427-
|> ^
1425+
|
1426+
1 | aaaaa
1427+
| ^
14281428
...
1429-
9 |> ddd__eee_
1430-
|> ^^^ ^^^
1431-
10 |> elided
1432-
11 |> __f_gg
1433-
|> ^ ^^
1429+
9 | ddd__eee_
1430+
| ^^^ ^^^
1431+
10 | elided
1432+
11 | __f_gg
1433+
| ^ ^^
14341434
"#[1..];
14351435

14361436
macro_rules! test {
@@ -1477,9 +1477,9 @@ fn foo() {
14771477
let text = make_string(&lines);
14781478
assert_eq!(&text[..], &"
14791479
--> foo.rs:3:2
1480-
|>
1481-
3 |> \tbar;
1482-
|> \t^^^
1480+
|
1481+
3 | \tbar;
1482+
| \t^^^
14831483
"[1..]);
14841484
}
14851485

@@ -1510,12 +1510,12 @@ fn foo() {
15101510
println!("text=\n{}", text);
15111511
assert_eq!(&text[..], &r#"
15121512
::: foo.rs
1513-
|>
1514-
3 |> vec.push(vec.pop().unwrap());
1515-
|> --- --- - previous borrow ends here
1516-
|> | |
1517-
|> | error occurs here
1518-
|> previous borrow of `vec` occurs here
1513+
|
1514+
3 | vec.push(vec.pop().unwrap());
1515+
| --- --- - previous borrow ends here
1516+
| | |
1517+
| | error occurs here
1518+
| previous borrow of `vec` occurs here
15191519
"#[1..]);
15201520
}
15211521

@@ -1577,24 +1577,24 @@ fn bar() {
15771577

15781578
println!("text=\n{}", text);
15791579

1580-
// Note that the `|>` remain aligned across both files:
1580+
// Note that the `|` remain aligned across both files:
15811581
assert_eq!(&text[..], &r#"
15821582
--> foo.rs:3:14
1583-
|>
1584-
3 |> vec.push(vec.pop().unwrap());
1585-
|> --- ^^^ - c
1586-
|> | |
1587-
|> | b
1588-
|> a
1583+
|
1584+
3 | vec.push(vec.pop().unwrap());
1585+
| --- ^^^ - c
1586+
| | |
1587+
| | b
1588+
| a
15891589
::: bar.rs
1590-
|>
1591-
17 |> vec.push();
1592-
|> --- - f
1593-
|> |
1594-
|> d
1590+
|
1591+
17 | vec.push();
1592+
| --- - f
1593+
| |
1594+
| d
15951595
...
1596-
21 |> vec.pop().unwrap());
1597-
|> --- e
1596+
21 | vec.pop().unwrap());
1597+
| --- e
15981598
"#[1..]);
15991599
}
16001600

@@ -1632,15 +1632,15 @@ fn foo() {
16321632
println!("text=\n{}", text);
16331633
assert_eq!(&text[..], &r#"
16341634
::: foo.rs
1635-
|>
1636-
3 |> let name = find_id(&data, 22).unwrap();
1637-
|> ---- immutable borrow begins here
1635+
|
1636+
3 | let name = find_id(&data, 22).unwrap();
1637+
| ---- immutable borrow begins here
16381638
...
1639-
6 |> data.push(Data { name: format!("Hera"), id: 66 });
1640-
|> ---- mutable borrow occurs here
1639+
6 | data.push(Data { name: format!("Hera"), id: 66 });
1640+
| ---- mutable borrow occurs here
16411641
...
1642-
11 |> }
1643-
|> - immutable borrow ends here
1642+
11 | }
1643+
| - immutable borrow ends here
16441644
"#[1..]);
16451645
}
16461646

@@ -1672,13 +1672,13 @@ fn foo() {
16721672
println!("text=r#\"\n{}\".trim_left()", text);
16731673
assert_eq!(&text[..], &r#"
16741674
::: foo.rs
1675-
|>
1676-
3 |> vec.push(vec.pop().unwrap());
1677-
|> -------- ------ D
1678-
|> ||
1679-
|> |C
1680-
|> A
1681-
|> B
1675+
|
1676+
3 | vec.push(vec.pop().unwrap());
1677+
| -------- ------ D
1678+
| ||
1679+
| |C
1680+
| A
1681+
| B
16821682
"#[1..]);
16831683
}
16841684

@@ -1709,12 +1709,12 @@ fn foo() {
17091709
println!("text=r#\"\n{}\".trim_left()", text);
17101710
assert_eq!(&text[..], &r#"
17111711
::: foo.rs
1712-
|>
1713-
3 |> vec.push(vec.pop().unwrap());
1714-
|> --- --- - previous borrow ends here
1715-
|> | |
1716-
|> | error occurs here
1717-
|> previous borrow of `vec` occurs here
1712+
|
1713+
3 | vec.push(vec.pop().unwrap());
1714+
| --- --- - previous borrow ends here
1715+
| | |
1716+
| | error occurs here
1717+
| previous borrow of `vec` occurs here
17181718
"#[1..]);
17191719
}
17201720

@@ -1748,12 +1748,12 @@ fn foo() {
17481748
println!("text=r#\"\n{}\".trim_left()", text);
17491749
assert_eq!(&text[..], &r#"
17501750
::: foo.rs
1751-
|>
1752-
4 |> let mut vec2 = vec;
1753-
|> --- `vec` moved here because it has type `collections::vec::Vec<i32>`
1751+
|
1752+
4 | let mut vec2 = vec;
1753+
| --- `vec` moved here because it has type `collections::vec::Vec<i32>`
17541754
...
1755-
9 |> vec.push(7);
1756-
|> --- use of moved value: `vec`
1755+
9 | vec.push(7);
1756+
| --- use of moved value: `vec`
17571757
"#[1..]);
17581758
}
17591759

@@ -1785,11 +1785,11 @@ fn foo() {
17851785
println!("text=&r#\"\n{}\n\"#[1..]", text);
17861786
assert_eq!(text, &r#"
17871787
::: foo.rs
1788-
|>
1789-
3 |> let mut vec = vec![0, 1, 2];
1790-
|> --- ---
1791-
4 |> let mut vec2 = vec;
1792-
|> --- ---
1788+
|
1789+
3 | let mut vec = vec![0, 1, 2];
1790+
| --- ---
1791+
4 | let mut vec2 = vec;
1792+
| --- ---
17931793
"#[1..]);
17941794
}
17951795

@@ -1817,9 +1817,9 @@ impl SomeTrait for () {
18171817
println!("r#\"\n{}\"", text);
18181818
assert_eq!(text, &r#"
18191819
::: foo.rs
1820-
|>
1821-
3 |> fn foo(x: u32) {
1822-
|> -
1820+
|
1821+
3 | fn foo(x: u32) {
1822+
| -
18231823
"#[1..]);
18241824
}
18251825

@@ -1847,12 +1847,12 @@ impl SomeTrait for () {
18471847
println!("r#\"\n{}\"", text);
18481848
assert_eq!(text, &r#"
18491849
::: foo.rs
1850-
|>
1851-
2 |> fn foo(x: u32) {
1852-
|> --------------
1853-
|> | |
1854-
|> | x_span
1855-
|> fn_span
1850+
|
1851+
2 | fn foo(x: u32) {
1852+
| --------------
1853+
| | |
1854+
| | x_span
1855+
| fn_span
18561856
"#[1..]);
18571857
}
18581858

@@ -1882,12 +1882,12 @@ impl SomeTrait for () {
18821882
println!("r#\"\n{}\"", text);
18831883
assert_eq!(text, &r#"
18841884
::: foo.rs
1885-
|>
1886-
2 |> fn foo(x: u32) {
1887-
|> --------------
1888-
|> | |
1889-
|> | x_span
1890-
|> fn_span
1885+
|
1886+
2 | fn foo(x: u32) {
1887+
| --------------
1888+
| | |
1889+
| | x_span
1890+
| fn_span
18911891
"#[1..]);
18921892
}
18931893

@@ -1928,11 +1928,11 @@ impl SomeTrait for () {
19281928
println!("r#\"\n{}\"", text);
19291929
assert_eq!(text, &r#"
19301930
::: foo.rs
1931-
|>
1932-
3 |> let closure = || {
1933-
|> - foo
1934-
4 |> inner
1935-
|> ----- bar
1931+
|
1932+
3 | let closure = || {
1933+
| - foo
1934+
4 | inner
1935+
| ----- bar
19361936
"#[1..]);
19371937
}
19381938

@@ -1971,9 +1971,9 @@ fn main() {
19711971
println!("r#\"\n{}\"", text);
19721972
assert_eq!(text, &r#"
19731973
--> foo.rs:11:2
1974-
|>
1975-
11 |> }
1976-
|> -
1974+
|
1975+
11 | }
1976+
| -
19771977
"#[1..]);
19781978
}
19791979
}

0 commit comments

Comments
 (0)
Please sign in to comment.