-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Description
TL;DR: EmitterWriter::get_max_line_num unconditionally returns self.get_multispan_max_line_num(span) no matter what is contained in children.
Longer explanation: let's take a look at the code of method (it's rather short):
fn get_max_line_num(&mut self, span: &MultiSpan, children: &[SubDiagnostic]) -> usize {
let mut max = 0;
let primary = self.get_multispan_max_line_num(span);
max = if primary > max { primary } else { max };
for sub in children {
let sub_result = self.get_multispan_max_line_num(&sub.span);
max = if sub_result > max { primary } else { max };
}
max
}Here self.get_multispan_max_line_num(span) returns a plain usize. Firstly, since 0 is the smallest possible value of usize, the first three lines can be rewritten without changing the meaning as
let primary = self.get_multispan_max_line_num(span);
let mut max = primary;So after executing these lines max == primary. Secondly, in the loop if compares sub_result with max but assigns either max or primary. If max == primary in the beginning of iteration, then this also holds in the end of iteration. Since this preposition holds before executing the loop, it also holds after executing the loop, so the whole method just returns primary, QED.
Erroneous code was introduced in 71ec286.
Unfortunately, I'm not familliar enough with the code to propose the correct fix.