diff options
| author | bors <bors@rust-lang.org> | 2020-01-07 04:54:02 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-01-07 04:54:02 +0000 |
| commit | 4f074dea1dbf28d7519bf408b7530e8cba019243 (patch) | |
| tree | 32898820efab3cbd1ab73a44cfdeeb49650880ff /src/librustc_errors | |
| parent | aa0769b92e60f5298f0b6326b8654c9b04351b98 (diff) | |
| parent | 23d97880bc2b5022fb4331cdff90550de7fc5328 (diff) | |
| download | rust-4f074dea1dbf28d7519bf408b7530e8cba019243.tar.gz rust-4f074dea1dbf28d7519bf408b7530e8cba019243.zip | |
Auto merge of #67964 - JohnTitor:rollup-pu5kosl, r=JohnTitor
Rollup of 13 pull requests Successful merges: - #67566 (Add an unstable conversion from thread ID to u64) - #67671 (Account for `type X = impl Trait;` in lifetime suggestion) - #67727 (Stabilise vec::remove_item) - #67877 (Omit underscore constants from rustdoc) - #67880 (Handle multiple error fix suggestions carefuly) - #67898 (Improve hygiene of `newtype_index`) - #67908 (rustdoc: HTML escape const values) - #67909 (Fix ICE in const pretty printing and resolve FIXME) - #67929 (Formatting an example for method Vec.retain) - #67934 (Clean up E0178 explanation) - #67936 (fire "non_camel_case_types" for associated types) - #67943 (Missing module std in example.) - #67962 (Update books) Failed merges: r? @ghost
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/emitter.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 541b89e6fce..526b4e2971b 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -1530,7 +1530,7 @@ impl EmitterWriter { // This offset and the ones below need to be signed to account for replacement code // that is shorter than the original code. - let mut offset: isize = 0; + let mut offsets: Vec<(usize, isize)> = Vec::new(); // Only show an underline in the suggestions if the suggestion is not the // entirety of the code being shown and the displayed code is not multiline. if show_underline { @@ -1550,12 +1550,19 @@ impl EmitterWriter { .map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) .sum(); + let offset: isize = offsets + .iter() + .filter_map( + |(start, v)| if span_start_pos <= *start { None } else { Some(v) }, + ) + .sum(); let underline_start = (span_start_pos + start) as isize + offset; let underline_end = (span_start_pos + start + sub_len) as isize + offset; + assert!(underline_start >= 0 && underline_end >= 0); for p in underline_start..underline_end { buffer.putc( row_num, - max_line_num_len + 3 + p as usize, + ((max_line_num_len + 3) as isize + p) as usize, '^', Style::UnderlinePrimary, ); @@ -1565,7 +1572,7 @@ impl EmitterWriter { for p in underline_start - 1..underline_start + 1 { buffer.putc( row_num, - max_line_num_len + 3 + p as usize, + ((max_line_num_len + 3) as isize + p) as usize, '-', Style::UnderlineSecondary, ); @@ -1582,8 +1589,9 @@ impl EmitterWriter { // length of the code to be substituted let snippet_len = span_end_pos as isize - span_start_pos as isize; // For multiple substitutions, use the position *after* the previous - // substitutions have happened. - offset += full_sub_len - snippet_len; + // substitutions have happened, only when further substitutions are + // located strictly after. + offsets.push((span_end_pos, full_sub_len - snippet_len)); } row_num += 1; } |
