Closed
Description
Using rustc_driver::run_compiler(["empty_file.rs"], ...)
, the compilation is stopped after parsing.
The codemap is retrieved, and the call to lookup_char_pos
panics when we visit the AST:
impl visit::Visitor for FmtVisitor {
fn visit_mod(&mut self, m: &'v ast::Mod, s: Span, _: ast::NodeId) {
if self codemap.lookup_char_pos(s.lo).file.name
[...]
I'm wondering if it's an unexpected behavior or if this situation violates an invariant of codemap.
Backtrace:
thread '<main>' panicked at 'position 0 does not resolve to a source location', ../src/libsyntax/codemap.rs:908
stack backtrace:
1: 0x7fb91319f92e - sys::backtrace::write::he24e072826f78dbbpqs
2: 0x7fb9131a79ec - panicking::on_panic::hfe8dee88ad5f1f8f69w
3: 0x7fb91316a53e - rt::unwind::begin_unwind_inner::h30a8282e6074626cKPw
4: 0x7fb91316b26c - rt::unwind::begin_unwind_fmt::h0d67ce05a74a7ba4QOw
5: 0x7fb913987313 - codemap::CodeMap::lookup_filemap_idx::hdb5a6d4b9a382f2by4z
6: 0x7fb913986e11 - codemap::CodeMap::lookup_char_pos::hcfccdd83504b914fJJz
7: 0x7fb9152b24c8 - visitor::FmtVisitor<'a>.visit..Visitor<'v>::visit_mod::hb8cb15535f0f5ffbZUa
at /home/cassiersg/rustfmt/src/visitor.rs:249
8: 0x7fb9152f174b - visit::walk_crate::h11272277405317629321
at ../src/libsyntax/visit.rs:152
9: 0x7fb9152f1489 - fmt_ast::h0042e145cf43e2281Jd
at /home/cassiersg/rustfmt/src/lib.rs:165
10: 0x7fb9152fbc3d - RustFmtCalls.CompilerCalls<'a>::build_controller::closure.12943
at /home/cassiersg/rustfmt/src/lib.rs:309
11: 0x7fb914ce8a88 - driver::compile_input::hc2338ec138000972Tba
12: 0x7fb914dc67d3 - run_compiler::h64b107044b742926x7b
13: 0x7fb9152fc5d2 - run::h1118ec9f2f6cbfc82Wd
at /home/cassiersg/rustfmt/src/lib.rs:340
14: 0x7fb91525a5c3 - main::h78aa2f0fe725515fkaa
at bin/rustfmt.rs:27
15: 0x7fb91321f758 - rust_try_inner
16: 0x7fb91321f745 - rust_try
17: 0x7fb9131a9527 - rt::lang_start::hdadb5fc58c5eeff334w
18: 0x7fb91526159b - main
19: 0x7fb91282078f - __libc_start_main
20: 0x7fb91525a2a8 - _start
21: 0x0 - <unknown>
rustc:
$ rustc --version --verbose
rustc 1.2.0-nightly (9ad0063a1 2015-06-20)
binary: rustc
commit-hash: 9ad0063a1772edca3299e2dc76187bbfa74e8b16
commit-date: 2015-06-20
host: x86_64-unknown-linux-gnu
release: 1.2.0-nightly
cc nrc/rustfmt#115