From 1e4de333740690357a8f58883c5c69bf58be1424 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Wed, 21 Dec 2011 19:50:45 +0800 Subject: [PATCH] rustc: Exclude stdin from codemap files when lookup_pos Fixes issue #1362 --- src/comp/syntax/codemap.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index 8cdbcd32caef..f08bec73a3d6 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -35,15 +35,17 @@ type lookup_fn = fn(file_pos) -> uint; fn lookup_pos(map: codemap, pos: uint, lookup: lookup_fn) -> loc { let len = vec::len(map.files); + if len > 1u && map.files[len - 1u].name == "-" { + // the trailing "-" must be the core_macros inserted by expand_crate, + // exclude it from the targets to lookup + len = len - 1u; + } let a = 0u; let b = len; while b - a > 1u { let m = (a + b) / 2u; if lookup(map.files[m].start_pos) > pos { b = m; } else { a = m; } } - if (a >= len) { - ret { filename: "-", line: 0u, col: 0u }; - } let f = map.files[a]; a = 0u; b = vec::len(f.lines);