Skip to content

Commit 1181587

Browse files
committed
Work around #8256, do not fail the task, just return None
1 parent 8ce9533 commit 1181587

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/librustc/middle/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3097,7 +3097,7 @@ impl Resolver {
30973097
let imports: &mut ~[@ImportDirective] = &mut *module_.imports;
30983098
let import_count = imports.len();
30993099
if index != import_count {
3100-
let sn = self.session.codemap.span_to_snippet(imports[index].span);
3100+
let sn = self.session.codemap.span_to_snippet(imports[index].span).unwrap();
31013101
if sn.contains("::") {
31023102
self.session.span_err(imports[index].span, "unresolved import");
31033103
} else {

src/libsyntax/codemap.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,19 @@ impl CodeMap {
369369
return @FileLines {file: lo.file, lines: lines};
370370
}
371371

372-
pub fn span_to_snippet(&self, sp: span) -> ~str {
372+
pub fn span_to_snippet(&self, sp: span) -> Option<~str> {
373373
let begin = self.lookup_byte_offset(sp.lo);
374374
let end = self.lookup_byte_offset(sp.hi);
375-
assert_eq!(begin.fm.start_pos, end.fm.start_pos);
376-
return begin.fm.src.slice(
377-
begin.pos.to_uint(), end.pos.to_uint()).to_owned();
375+
376+
// FIXME #8256: this used to be an assert but whatever precondition
377+
// it's testing isn't true for all spans in the AST, so to allow the
378+
// caller to not have to fail (and it can't catch it since the CodeMap
379+
// isn't sendable), return None
380+
if begin.fm.start_pos != end.fm.start_pos {
381+
None
382+
} else {
383+
Some(begin.fm.src.slice( begin.pos.to_uint(), end.pos.to_uint()).to_owned())
384+
}
378385
}
379386

380387
pub fn get_filemap(&self, filename: &str) -> @FileMap {

0 commit comments

Comments
 (0)