@@ -85,7 +85,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
85
85
// get access to the necessary lines.
86
86
auto rdr = ioivec:: file_reader ( lines. name ) ;
87
87
auto file = str:: unsafe_from_bytes_ivec ( rdr. read_whole_stream ( ) ) ;
88
- auto fm = codemap :: get_filemap ( cm, lines. name ) ;
88
+ auto fm = get_filemap ( cm, lines. name ) ;
89
89
90
90
// arbitrarily only print up to six lines of the error
91
91
auto max_lines = 6 u;
@@ -99,7 +99,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
99
99
for ( uint line in display_lines) {
100
100
ioivec:: stdout ( ) . write_str ( #fmt ( "%s:%u " , fm. name ,
101
101
line + 1 u) ) ;
102
- auto s = codemap :: get_line ( fm, line as int , file) ;
102
+ auto s = get_line ( fm, line as int , file) ;
103
103
if ( !str:: ends_with ( s, "\n " ) ) {
104
104
s += "\n " ;
105
105
}
@@ -119,6 +119,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
119
119
// If there's one line at fault we can easily point to the problem
120
120
if ( ivec:: len ( lines. lines ) == 1 u) {
121
121
auto lo = codemap:: lookup_pos ( cm, option:: get ( sp) . lo ) ;
122
+ auto lo = lookup_pos ( cm, option:: get ( sp) . lo ) ;
122
123
auto digits = 0 u;
123
124
auto num = lines. lines . ( 0 ) / 10 u;
124
125
@@ -131,7 +132,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
131
132
while ( left > 0 u) { str:: push_char ( s, ' ' ) ; left -= 1 u; }
132
133
133
134
s += "^" ;
134
- auto hi = codemap :: lookup_pos ( cm, option:: get ( sp) . hi ) ;
135
+ auto hi = lookup_pos ( cm, option:: get ( sp) . hi ) ;
135
136
if ( hi. col != lo. col ) {
136
137
// the ^ already takes up one space
137
138
auto width = hi. col - lo. col - 1 u;
@@ -170,13 +171,14 @@ fn span_to_lines(span sp, codemap::codemap cm) -> @file_lines {
170
171
}
171
172
172
173
fn get_line ( filemap fm, int line , & str file ) -> str {
174
+ let uint begin = fm. lines . ( line) - fm. lines . ( 0 ) ;
173
175
let uint end;
174
176
if ( ( line as uint ) + 1 u >= ivec:: len ( fm. lines ) ) {
175
177
end = str:: byte_len ( file) ;
176
178
} else {
177
- end = fm. lines . ( line + 1 ) ;
179
+ end = fm. lines . ( line + 1 ) - fm . lines . ( 0 ) ;
178
180
}
179
- ret str:: slice ( file, fm . lines . ( line ) , end) ;
181
+ ret str:: slice ( file, begin , end) ;
180
182
}
181
183
182
184
fn get_filemap ( codemap cm, str filename ) -> filemap {
0 commit comments