Skip to content

Commit e1d2999

Browse files
authored
Rollup merge of #37257 - srinivasreddy:librustc_errors, r=eddyb
run rustfmt on librustc_errors folder
2 parents 91487db + b260617 commit e1d2999

File tree

6 files changed

+173
-181
lines changed

6 files changed

+173
-181
lines changed

src/librustc_errors/emitter.rs

+84-90
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ impl ColorConfig {
5151
fn use_color(&self) -> bool {
5252
match *self {
5353
ColorConfig::Always => true,
54-
ColorConfig::Never => false,
55-
ColorConfig::Auto => stderr_isatty(),
54+
ColorConfig::Never => false,
55+
ColorConfig::Auto => stderr_isatty(),
5656
}
5757
}
5858
}
@@ -83,22 +83,22 @@ macro_rules! println_maybe_styled {
8383
}
8484

8585
impl EmitterWriter {
86-
pub fn stderr(color_config: ColorConfig,
87-
code_map: Option<Rc<CodeMapper>>)
88-
-> EmitterWriter {
86+
pub fn stderr(color_config: ColorConfig, code_map: Option<Rc<CodeMapper>>) -> EmitterWriter {
8987
if color_config.use_color() {
9088
let dst = Destination::from_stderr();
91-
EmitterWriter { dst: dst,
92-
cm: code_map}
89+
EmitterWriter {
90+
dst: dst,
91+
cm: code_map,
92+
}
9393
} else {
94-
EmitterWriter { dst: Raw(Box::new(io::stderr())),
95-
cm: code_map}
94+
EmitterWriter {
95+
dst: Raw(Box::new(io::stderr())),
96+
cm: code_map,
97+
}
9698
}
9799
}
98100

99-
pub fn new(dst: Box<Write + Send>,
100-
code_map: Option<Rc<CodeMapper>>)
101-
-> EmitterWriter {
101+
pub fn new(dst: Box<Write + Send>, code_map: Option<Rc<CodeMapper>>) -> EmitterWriter {
102102
EmitterWriter {
103103
dst: Raw(dst),
104104
cm: code_map,
@@ -107,9 +107,9 @@ impl EmitterWriter {
107107

108108
fn preprocess_annotations(&self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
109109
fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
110-
file: Rc<FileMap>,
111-
line_index: usize,
112-
ann: Annotation) {
110+
file: Rc<FileMap>,
111+
line_index: usize,
112+
ann: Annotation) {
113113

114114
for slot in file_vec.iter_mut() {
115115
// Look through each of our files for the one we're adding to
@@ -168,15 +168,15 @@ impl EmitterWriter {
168168
}
169169

170170
add_annotation_to_file(&mut output,
171-
lo.file,
172-
lo.line,
173-
Annotation {
174-
start_col: lo.col.0,
175-
end_col: hi.col.0,
176-
is_primary: span_label.is_primary,
177-
is_minimized: is_minimized,
178-
label: span_label.label.clone(),
179-
});
171+
lo.file,
172+
lo.line,
173+
Annotation {
174+
start_col: lo.col.0,
175+
end_col: hi.col.0,
176+
is_primary: span_label.is_primary,
177+
is_minimized: is_minimized,
178+
label: span_label.label.clone(),
179+
});
180180
}
181181
}
182182
output
@@ -237,19 +237,15 @@ impl EmitterWriter {
237237
'^',
238238
Style::UnderlinePrimary);
239239
if !annotation.is_minimized {
240-
buffer.set_style(line_offset,
241-
width_offset + p,
242-
Style::UnderlinePrimary);
240+
buffer.set_style(line_offset, width_offset + p, Style::UnderlinePrimary);
243241
}
244242
} else {
245243
buffer.putc(line_offset + 1,
246244
width_offset + p,
247245
'-',
248246
Style::UnderlineSecondary);
249247
if !annotation.is_minimized {
250-
buffer.set_style(line_offset,
251-
width_offset + p,
252-
Style::UnderlineSecondary);
248+
buffer.set_style(line_offset, width_offset + p, Style::UnderlineSecondary);
253249
}
254250
}
255251
}
@@ -429,8 +425,7 @@ impl EmitterWriter {
429425
}
430426
// Check to make sure we're not in any <*macros>
431427
if !cm.span_to_filename(def_site).contains("macros>") &&
432-
!trace.macro_decl_name.starts_with("#[")
433-
{
428+
!trace.macro_decl_name.starts_with("#[") {
434429
new_labels.push((trace.call_site,
435430
"in this macro invocation".to_string()));
436431
break;
@@ -475,10 +470,10 @@ impl EmitterWriter {
475470
if spans_updated {
476471
children.push(SubDiagnostic {
477472
level: Level::Note,
478-
message:"this error originates in a macro outside of the current \
479-
crate".to_string(),
473+
message: "this error originates in a macro outside of the current crate"
474+
.to_string(),
480475
span: MultiSpan::new(),
481-
render_span: None
476+
render_span: None,
482477
});
483478
}
484479
}
@@ -502,8 +497,7 @@ impl EmitterWriter {
502497
buffer.append(0, &level.to_string(), Style::HeaderMsg);
503498
buffer.append(0, ": ", Style::NoStyle);
504499
buffer.append(0, msg, Style::NoStyle);
505-
}
506-
else {
500+
} else {
507501
buffer.append(0, &level.to_string(), Style::Level(level.clone()));
508502
match code {
509503
&Some(ref code) => {
@@ -522,23 +516,21 @@ impl EmitterWriter {
522516
let mut annotated_files = self.preprocess_annotations(msp);
523517

524518
// Make sure our primary file comes first
525-
let primary_lo =
526-
if let (Some(ref cm), Some(ref primary_span)) = (self.cm.as_ref(),
527-
msp.primary_span().as_ref()) {
528-
if primary_span != &&DUMMY_SP && primary_span != &&COMMAND_LINE_SP {
529-
cm.lookup_char_pos(primary_span.lo)
530-
}
531-
else {
532-
emit_to_destination(&buffer.render(), level, &mut self.dst)?;
533-
return Ok(());
534-
}
519+
let primary_lo = if let (Some(ref cm), Some(ref primary_span)) =
520+
(self.cm.as_ref(), msp.primary_span().as_ref()) {
521+
if primary_span != &&DUMMY_SP && primary_span != &&COMMAND_LINE_SP {
522+
cm.lookup_char_pos(primary_span.lo)
535523
} else {
536-
// If we don't have span information, emit and exit
537524
emit_to_destination(&buffer.render(), level, &mut self.dst)?;
538525
return Ok(());
539-
};
526+
}
527+
} else {
528+
// If we don't have span information, emit and exit
529+
emit_to_destination(&buffer.render(), level, &mut self.dst)?;
530+
return Ok(());
531+
};
540532
if let Ok(pos) =
541-
annotated_files.binary_search_by(|x| x.file.name.cmp(&primary_lo.file.name)) {
533+
annotated_files.binary_search_by(|x| x.file.name.cmp(&primary_lo.file.name)) {
542534
annotated_files.swap(0, pos);
543535
}
544536

@@ -554,8 +546,8 @@ impl EmitterWriter {
554546
buffer.prepend(buffer_msg_line_offset, "--> ", Style::LineNumber);
555547
let loc = primary_lo.clone();
556548
buffer.append(buffer_msg_line_offset,
557-
&format!("{}:{}:{}", loc.file.name, loc.line, loc.col.0 + 1),
558-
Style::LineAndColumn);
549+
&format!("{}:{}:{}", loc.file.name, loc.line, loc.col.0 + 1),
550+
Style::LineAndColumn);
559551
for _ in 0..max_line_num_len {
560552
buffer.prepend(buffer_msg_line_offset, " ", Style::NoStyle);
561553
}
@@ -569,8 +561,8 @@ impl EmitterWriter {
569561
// Then, the secondary file indicator
570562
buffer.prepend(buffer_msg_line_offset + 1, "::: ", Style::LineNumber);
571563
buffer.append(buffer_msg_line_offset + 1,
572-
&annotated_file.file.name,
573-
Style::LineAndColumn);
564+
&annotated_file.file.name,
565+
Style::LineAndColumn);
574566
for _ in 0..max_line_num_len {
575567
buffer.prepend(buffer_msg_line_offset + 1, " ", Style::NoStyle);
576568
}
@@ -591,7 +583,7 @@ impl EmitterWriter {
591583
// this annotated line and the next one
592584
if line_idx < (annotated_file.lines.len() - 1) {
593585
let line_idx_delta = annotated_file.lines[line_idx + 1].line_index -
594-
annotated_file.lines[line_idx].line_index;
586+
annotated_file.lines[line_idx].line_index;
595587
if line_idx_delta > 2 {
596588
let last_buffer_line_num = buffer.num_lines();
597589
buffer.puts(last_buffer_line_num, 0, "...", Style::LineNumber);
@@ -672,12 +664,7 @@ impl EmitterWriter {
672664
let max_line_num = self.get_max_line_num(span, children);
673665
let max_line_num_len = max_line_num.to_string().len();
674666

675-
match self.emit_message_default(span,
676-
message,
677-
code,
678-
level,
679-
max_line_num_len,
680-
false) {
667+
match self.emit_message_default(span, message, code, level, max_line_num_len, false) {
681668
Ok(()) => {
682669
if !children.is_empty() {
683670
let mut buffer = StyledBuffer::new();
@@ -723,13 +710,15 @@ impl EmitterWriter {
723710
}
724711
}
725712
}
726-
Err(e) => panic!("failed to emit error: {}", e)
713+
Err(e) => panic!("failed to emit error: {}", e),
727714
}
728715
match write!(&mut self.dst, "\n") {
729716
Err(e) => panic!("failed to emit error: {}", e),
730-
_ => match self.dst.flush() {
731-
Err(e) => panic!("failed to emit error: {}", e),
732-
_ => ()
717+
_ => {
718+
match self.dst.flush() {
719+
Err(e) => panic!("failed to emit error: {}", e),
720+
_ => (),
721+
}
733722
}
734723
}
735724
}
@@ -753,8 +742,9 @@ fn overlaps(a1: &Annotation, a2: &Annotation) -> bool {
753742
}
754743

755744
fn emit_to_destination(rendered_buffer: &Vec<Vec<StyledString>>,
756-
lvl: &Level,
757-
dst: &mut Destination) -> io::Result<()> {
745+
lvl: &Level,
746+
dst: &mut Destination)
747+
-> io::Result<()> {
758748
use lock;
759749

760750
// In order to prevent error message interleaving, where multiple error lines get intermixed
@@ -795,8 +785,7 @@ fn stderr_isatty() -> bool {
795785
const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
796786
extern "system" {
797787
fn GetStdHandle(which: DWORD) -> HANDLE;
798-
fn GetConsoleMode(hConsoleHandle: HANDLE,
799-
lpMode: *mut DWORD) -> BOOL;
788+
fn GetConsoleMode(hConsoleHandle: HANDLE, lpMode: *mut DWORD) -> BOOL;
800789
}
801790
unsafe {
802791
let handle = GetStdHandle(STD_ERROR_HANDLE);
@@ -824,9 +813,7 @@ impl BufferedWriter {
824813
// note: we use _new because the conditional compilation at its use site may make this
825814
// this function unused on some platforms
826815
fn _new() -> BufferedWriter {
827-
BufferedWriter {
828-
buffer: vec![]
829-
}
816+
BufferedWriter { buffer: vec![] }
830817
}
831818
}
832819

@@ -853,35 +840,34 @@ impl Destination {
853840
/// When not on Windows, prefer the buffered terminal so that we can buffer an entire error
854841
/// to be emitted at one time.
855842
fn from_stderr() -> Destination {
856-
let stderr: Option<Box<BufferedStderr>> =
843+
let stderr: Option<Box<BufferedStderr>> =
857844
term::TerminfoTerminal::new(BufferedWriter::_new())
858845
.map(|t| Box::new(t) as Box<BufferedStderr>);
859846

860847
match stderr {
861848
Some(t) => BufferedTerminal(t),
862-
None => Raw(Box::new(io::stderr())),
849+
None => Raw(Box::new(io::stderr())),
863850
}
864851
}
865852

866853
#[cfg(windows)]
867854
/// Return a normal, unbuffered terminal when on Windows.
868855
fn from_stderr() -> Destination {
869-
let stderr: Option<Box<term::StderrTerminal>> =
870-
term::TerminfoTerminal::new(io::stderr())
871-
.map(|t| Box::new(t) as Box<term::StderrTerminal>)
872-
.or_else(|| term::WinConsole::new(io::stderr()).ok()
873-
.map(|t| Box::new(t) as Box<term::StderrTerminal>));
856+
let stderr: Option<Box<term::StderrTerminal>> = term::TerminfoTerminal::new(io::stderr())
857+
.map(|t| Box::new(t) as Box<term::StderrTerminal>)
858+
.or_else(|| {
859+
term::WinConsole::new(io::stderr())
860+
.ok()
861+
.map(|t| Box::new(t) as Box<term::StderrTerminal>)
862+
});
874863

875864
match stderr {
876865
Some(t) => Terminal(t),
877-
None => Raw(Box::new(io::stderr())),
866+
None => Raw(Box::new(io::stderr())),
878867
}
879868
}
880869

881-
fn apply_style(&mut self,
882-
lvl: Level,
883-
style: Style)
884-
-> io::Result<()> {
870+
fn apply_style(&mut self, lvl: Level, style: Style) -> io::Result<()> {
885871
match style {
886872
Style::FileNameStyle | Style::LineAndColumn => {}
887873
Style::LineNumber => {
@@ -931,18 +917,26 @@ impl Destination {
931917

932918
fn start_attr(&mut self, attr: term::Attr) -> io::Result<()> {
933919
match *self {
934-
Terminal(ref mut t) => { t.attr(attr)?; }
935-
BufferedTerminal(ref mut t) => { t.attr(attr)?; }
936-
Raw(_) => { }
920+
Terminal(ref mut t) => {
921+
t.attr(attr)?;
922+
}
923+
BufferedTerminal(ref mut t) => {
924+
t.attr(attr)?;
925+
}
926+
Raw(_) => {}
937927
}
938928
Ok(())
939929
}
940930

941931
fn reset_attrs(&mut self) -> io::Result<()> {
942932
match *self {
943-
Terminal(ref mut t) => { t.reset()?; }
944-
BufferedTerminal(ref mut t) => { t.reset()?; }
945-
Raw(_) => { }
933+
Terminal(ref mut t) => {
934+
t.reset()?;
935+
}
936+
BufferedTerminal(ref mut t) => {
937+
t.reset()?;
938+
}
939+
Raw(_) => {}
946940
}
947941
Ok(())
948942
}

0 commit comments

Comments
 (0)