Skip to content

Commit 8a64cf7

Browse files
committed
Fix suggestion span error with a line containing non-ASCIIs
1 parent 0823077 commit 8a64cf7

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/librustc_errors/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ impl CodeSuggestion {
9090
hi_opt: Option<&Loc>) {
9191
let (lo, hi_opt) = (lo.col.to_usize(), hi_opt.map(|hi| hi.col.to_usize()));
9292
if let Some(line) = line_opt {
93-
if line.len() > lo {
93+
if let Some(lo) = line.char_indices().map(|(i, _)| i).nth(lo) {
94+
let hi_opt = hi_opt.and_then(|hi| line.char_indices().map(|(i, _)| i).nth(hi));
9495
buf.push_str(match hi_opt {
9596
Some(hi) => &line[lo..hi],
9697
None => &line[lo..],
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
fn main() {
13+
let tup = (1,);
14+
println!("☃{}", tup[0]);
15+
}
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: cannot index a value of type `({integer},)`
2+
--> $DIR/suggestion-non-ascii.rs:14:21
3+
|
4+
14 | println!("☃{}", tup[0]);
5+
| ^^^^^^
6+
|
7+
help: to access tuple elements, use tuple indexing syntax as shown
8+
| println!("☃{}", tup.0);
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)