Skip to content

Fix a byte/char confusion issue in the error emitter #44081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ impl EmitterWriter {
if line.annotations.len() == 1 {
if let Some(ref ann) = line.annotations.get(0) {
if let AnnotationType::MultilineStart(depth) = ann.annotation_type {
if source_string[0..ann.start_col].trim() == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the byte offset unavailable here? Converting to column should be delayed until the last moment IMO (and should take into account unicode grapheme width).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddyb I'm not sure what you mean but the start_col is given as columns, as per this comment:

/// Start column, 0-based indexing -- counting *characters*, not
/// utf-8 bytes. Note that it is important that this field goes

if source_string.chars()
.take(ann.start_col)
.all(|c| c.is_whitespace()) {
let style = if ann.is_primary {
Style::UnderlinePrimary
} else {
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/issue-44023.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(non_ascii_idents)]

pub fn main () {}

fn საჭმელად_გემრიელი_სადილი ( ) -> isize {
}
13 changes: 13 additions & 0 deletions src/test/ui/issue-44023.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0308]: mismatched types
--> $DIR/issue-44023.rs:15:42
|
15 | fn საჭმელად_გემრიელი_სადილი ( ) -> isize {
| __________________________________________^
16 | | }
| |_^ expected isize, found ()
|
= note: expected type `isize`
found type `()`

error: aborting due to previous error

13 changes: 13 additions & 0 deletions src/test/ui/issue-44078.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
"😊"";
}
10 changes: 10 additions & 0 deletions src/test/ui/issue-44078.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: unterminated double quote string
--> $DIR/issue-44078.rs:12:8
|
12 | "😊"";
| ________^
13 | | }
| |__^

error: aborting due to previous error