#source #position #compiler #source-map #rustc #file-line #error-reporting


A data structure for efficiently storing source code position and span information (e.g. in a compiler AST), and mapping it back to file/line/column locations for error reporting and suggestions.

4 releases

Uses old Rust 2015

0.1.3 Apr 12, 2020
0.1.2 Jun 30, 2019
0.1.1 Mar 3, 2018
0.1.0 May 29, 2017

#542 in Data structures

Download history 7571/week @ 2023-12-08 7286/week @ 2023-12-15 4925/week @ 2023-12-22 6775/week @ 2023-12-29 8809/week @ 2024-01-05 9643/week @ 2024-01-12 8565/week @ 2024-01-19 10461/week @ 2024-01-26 9516/week @ 2024-02-02 9588/week @ 2024-02-09 9693/week @ 2024-02-16 8743/week @ 2024-02-23 9318/week @ 2024-03-01 9110/week @ 2024-03-08 8977/week @ 2024-03-15 7998/week @ 2024-03-22

36,732 downloads per month
Used in 87 crates (19 directly)


332 lines



Build Status

A data structure for tracking source positions in language implementations, inspired by the SourceMap (formerly CodeMap) type in rustc's libsyntax.

The CodeMap tracks all source files and maps positions within them to linear indexes as if all source files were concatenated. This allows a source position to be represented by a small 32-bit Pos indexing into the CodeMap, under the assumption that the total amount of parsed source code will not exceed 4GiB. The CodeMap can look up the source file, line, and column of a Pos or Span, as well as provide source code snippets for error reporting.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps