X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_errors%2Femitter.rs;h=ad2562e28fa4f5b001d88200144f0de85e01d455;hb=1edbc3df0d051902916ead8e81db16a6f546f973;hp=2aea6d125f201e3cf381a5c81e661cdb6d11da2f;hpb=79f5c4eb589575ead8c722710af850425b8936db;p=rust.git diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 2aea6d125f2..ad2562e28fa 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -51,7 +51,7 @@ fn emit(&mut self, db: &DiagnosticBuilder) { // This substitution is only removal, don't show it format!("help: {}", sugg.msg) } else { - format!("help: {} `{}`", sugg.msg, substitution) + format!("help: {}: `{}`", sugg.msg, substitution) }; primary_span.push_span_label(sugg.substitution_spans().next().unwrap(), msg); } else { @@ -346,9 +346,20 @@ fn render_source_line(&self, // and "annotations lines", where the highlight lines have the `^`. // Sort the annotations by (start, end col) + // The labels are reversed, sort and then reversed again. + // Consider a list of annotations (A1, A2, C1, C2, B1, B2) where + // the letter signifies the span. Here we are only sorting by the + // span and hence, the order of the elements with the same span will + // not change. On reversing the ordering (|a, b| but b.cmp(a)), you get + // (C1, C2, B1, B2, A1, A2). All the elements with the same span are + // still ordered first to last, but all the elements with different + // spans are ordered by their spans in last to first order. Last to + // first order is important, because the jiggly lines and | are on + // the left, so the rightmost span needs to be rendered first, + // otherwise the lines would end up needing to go over a message. + let mut annotations = line.annotations.clone(); - annotations.sort(); - annotations.reverse(); + annotations.sort_by(|a,b| b.start_col.cmp(&a.start_col)); // First, figure out where each label will be positioned. //