remove the now-unused multiline error code
This commit is contained in:
parent
37c569627c
commit
712c5cadbb
@ -126,20 +126,14 @@ impl Session {
|
||||
sp: S,
|
||||
msg: &str)
|
||||
-> DiagnosticBuilder<'a> {
|
||||
match split_msg_into_multilines(msg) {
|
||||
Some(ref msg) => self.diagnostic().struct_span_err(sp, msg),
|
||||
None => self.diagnostic().struct_span_err(sp, msg),
|
||||
}
|
||||
self.diagnostic().struct_span_err(sp, msg)
|
||||
}
|
||||
pub fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
code: &str)
|
||||
-> DiagnosticBuilder<'a> {
|
||||
match split_msg_into_multilines(msg) {
|
||||
Some(ref msg) => self.diagnostic().struct_span_err_with_code(sp, msg, code),
|
||||
None => self.diagnostic().struct_span_err_with_code(sp, msg, code),
|
||||
}
|
||||
self.diagnostic().struct_span_err_with_code(sp, msg, code)
|
||||
}
|
||||
pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
|
||||
self.diagnostic().struct_err(msg)
|
||||
@ -178,16 +172,10 @@ impl Session {
|
||||
}
|
||||
}
|
||||
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
||||
match split_msg_into_multilines(msg) {
|
||||
Some(msg) => self.diagnostic().span_err(sp, &msg),
|
||||
None => self.diagnostic().span_err(sp, msg)
|
||||
}
|
||||
self.diagnostic().span_err(sp, msg)
|
||||
}
|
||||
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str) {
|
||||
match split_msg_into_multilines(msg) {
|
||||
Some(msg) => self.diagnostic().span_err_with_code(sp, &msg, code),
|
||||
None => self.diagnostic().span_err_with_code(sp, msg, code)
|
||||
}
|
||||
self.diagnostic().span_err_with_code(sp, &msg, code)
|
||||
}
|
||||
pub fn err(&self, msg: &str) {
|
||||
self.diagnostic().err(msg)
|
||||
@ -343,67 +331,6 @@ impl Session {
|
||||
}
|
||||
}
|
||||
|
||||
fn split_msg_into_multilines(msg: &str) -> Option<String> {
|
||||
// Conditions for enabling multi-line errors:
|
||||
if !msg.contains("mismatched types") &&
|
||||
!msg.contains("type mismatch resolving") &&
|
||||
!msg.contains("if and else have incompatible types") &&
|
||||
!msg.contains("if may be missing an else clause") &&
|
||||
!msg.contains("match arms have incompatible types") &&
|
||||
!msg.contains("structure constructor specifies a structure of type") &&
|
||||
!msg.contains("has an incompatible type for trait") {
|
||||
return None
|
||||
}
|
||||
let first = msg.match_indices("expected").filter(|s| {
|
||||
let last = msg[..s.0].chars().rev().next();
|
||||
last == Some(' ') || last == Some('(')
|
||||
}).map(|(a, b)| (a - 1, a + b.len()));
|
||||
let second = msg.match_indices("found").filter(|s| {
|
||||
msg[..s.0].chars().rev().next() == Some(' ')
|
||||
}).map(|(a, b)| (a - 1, a + b.len()));
|
||||
|
||||
let mut new_msg = String::new();
|
||||
let mut head = 0;
|
||||
|
||||
// Insert `\n` before expected and found.
|
||||
for (pos1, pos2) in first.zip(second) {
|
||||
new_msg = new_msg +
|
||||
// A `(` may be preceded by a space and it should be trimmed
|
||||
msg[head..pos1.0].trim_right() + // prefix
|
||||
"\n" + // insert before first
|
||||
&msg[pos1.0..pos1.1] + // insert what first matched
|
||||
&msg[pos1.1..pos2.0] + // between matches
|
||||
"\n " + // insert before second
|
||||
// 123
|
||||
// `expected` is 3 char longer than `found`. To align the types,
|
||||
// `found` gets 3 spaces prepended.
|
||||
&msg[pos2.0..pos2.1]; // insert what second matched
|
||||
|
||||
head = pos2.1;
|
||||
}
|
||||
|
||||
let mut tail = &msg[head..];
|
||||
let third = tail.find("(values differ")
|
||||
.or(tail.find("(lifetime"))
|
||||
.or(tail.find("(cyclic type of infinite size"));
|
||||
// Insert `\n` before any remaining messages which match.
|
||||
if let Some(pos) = third {
|
||||
// The end of the message may just be wrapped in `()` without
|
||||
// `expected`/`found`. Push this also to a new line and add the
|
||||
// final tail after.
|
||||
new_msg = new_msg +
|
||||
// `(` is usually preceded by a space and should be trimmed.
|
||||
tail[..pos].trim_right() + // prefix
|
||||
"\n" + // insert before paren
|
||||
&tail[pos..]; // append the tail
|
||||
|
||||
tail = "";
|
||||
}
|
||||
|
||||
new_msg.push_str(tail);
|
||||
return Some(new_msg);
|
||||
}
|
||||
|
||||
pub fn build_session(sopts: config::Options,
|
||||
dep_graph: &DepGraph,
|
||||
local_crate_source_file: Option<PathBuf>,
|
||||
|
Loading…
Reference in New Issue
Block a user