Skip to content

Commit ce57d07

Browse files
author
Oliver Schneider
committed
---
yaml --- r: 235047 b: refs/heads/stable c: c5dfd34 h: refs/heads/master i: 235045: 496db8e 235043: e5635ef 235039: 36a88c3 v: v3
1 parent 902697c commit ce57d07

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 599bf45ac9afc309332388fe4bc42a100e3d1586
32+
refs/heads/stable: c5dfd34c615b0586a101e9e66770a5c4fd31c852
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/libsyntax/diagnostic.rs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,11 @@ fn highlight_lines(err: &mut EmitterWriter,
598598
assert!(display_line_infos.len() > 0);
599599
let mut max_line_num = display_line_infos[display_line_infos.len() - 1].line_index + 1;
600600
let mut digits = 0;
601-
while max_line_num > 0 { max_line_num /= 10; digits += 1; }
601+
while max_line_num > 0 {
602+
max_line_num /= 10;
603+
digits += 1;
604+
}
605+
602606
// Print the offending lines
603607
for (line_info, line) in display_line_infos.iter().zip(display_line_strings) {
604608
try!(write!(&mut err.dst, "{}:{:>width$} {}\n",
@@ -801,3 +805,64 @@ pub fn expect<T, M>(diag: &SpanHandler, opt: Option<T>, msg: M) -> T where
801805
None => diag.handler().bug(&msg()),
802806
}
803807
}
808+
809+
#[cfg(test)]
810+
mod test {
811+
use super::{EmitterWriter, highlight_lines, Level};
812+
use codemap::{mk_sp, CodeMap, BytePos};
813+
use std::sync::{Arc, Mutex};
814+
use std::io::{self, Write};
815+
use std::str::from_utf8;
816+
817+
// Diagnostic doesn't align properly in span where line number increases by one digit
818+
#[test]
819+
fn test_hilight_suggestion_issue_11715() {
820+
struct Sink(Arc<Mutex<Vec<u8>>>);
821+
impl Write for Sink {
822+
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
823+
Write::write(&mut *self.0.lock().unwrap(), data)
824+
}
825+
fn flush(&mut self) -> io::Result<()> { Ok(()) }
826+
}
827+
let data = Arc::new(Mutex::new(Vec::new()));
828+
let mut ew = EmitterWriter::new(Box::new(Sink(data.clone())), None);
829+
let cm = CodeMap::new();
830+
let content = "abcdefg
831+
koksi
832+
line3
833+
line4
834+
cinq
835+
line6
836+
line7
837+
line8
838+
line9
839+
line10
840+
e-lä-vän
841+
tolv
842+
dreizehn
843+
";
844+
let file = cm.new_filemap("dummy.txt".to_string(), content.to_string());
845+
for (i, b) in content.bytes().enumerate() {
846+
if b == b'\n' {
847+
file.next_line(BytePos(i as u32));
848+
}
849+
}
850+
let start = file.lines.borrow()[7];
851+
let end = file.lines.borrow()[11];
852+
let sp = mk_sp(start, end);
853+
let lvl = Level::Error;
854+
println!("span_to_lines");
855+
let lines = cm.span_to_lines(sp);
856+
println!("highlight_lines");
857+
highlight_lines(&mut ew, &cm, sp, lvl, lines).unwrap();
858+
println!("done");
859+
let vec = data.lock().unwrap().clone();
860+
let vec: &[u8] = &vec;
861+
println!("{}", from_utf8(vec).unwrap());
862+
assert_eq!(vec, "dummy.txt: 8 \n\
863+
dummy.txt: 9 \n\
864+
dummy.txt:10 \n\
865+
dummy.txt:11 \n\
866+
dummy.txt:12 \n".as_bytes());
867+
}
868+
}

0 commit comments

Comments
 (0)