Skip to content

Commit 5655583

Browse files
MahadMuhammadCohenArthur
authored andcommitted
Refactor dg-formating using temp variables
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
1 parent 016e13c commit 5655583

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/errors.rs

+25-21
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,34 @@ pub struct Error {
6666

6767
impl fmt::Display for Error {
6868
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69+
use RustcErrorKind::*;
70+
6971
let error_code = self.error_code.as_ref().map_or("", |code| &code[..]);
72+
73+
let error_type = match &self.kind {
74+
Some(Help) => "help",
75+
Some(Error) => "dg-error",
76+
Some(Note) => "dg-note",
77+
Some(Suggestion) => "suggestion",
78+
Some(Warning) => "dg-warning",
79+
None => "dg-error",
80+
};
81+
82+
let error_code = if error_code.is_empty() {
83+
error_code.to_owned()
84+
} else {
85+
format!(".{}.", error_code)
86+
};
87+
88+
let rel_line_number = if self.relative_line_num == 0 {
89+
"".to_owned()
90+
} else {
91+
format!(".{} ", self.relative_line_num)
92+
};
93+
7094
write!(
7195
f,
72-
"// {{ {} \"{}\" \"\" {{ target *-*-* }} {}}}",
73-
match &self.kind {
74-
Some(kind) => match kind {
75-
RustcErrorKind::Help => "help",
76-
RustcErrorKind::Error => "dg-error",
77-
RustcErrorKind::Note => "dg-note",
78-
RustcErrorKind::Suggestion => "suggestion",
79-
RustcErrorKind::Warning => "dg-warning",
80-
},
81-
None => "dg-error",
82-
},
83-
if !error_code.is_empty() {
84-
format!(".{}.", error_code)
85-
} else {
86-
error_code.to_owned()
87-
},
88-
if self.relative_line_num == 0 {
89-
"".to_owned()
90-
} else {
91-
format!(".{} ", self.relative_line_num)
92-
},
96+
"// {{ {error_type} \"{error_code}\" \"\" {{ target *-*-* }} {rel_line_number}}}"
9397
)
9498
}
9599
}

0 commit comments

Comments
 (0)