Skip to content
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

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

Merged
merged 1 commit into from
Aug 26, 2017

Conversation

est31
Copy link
Member

@est31 est31 commented Aug 25, 2017

Fixes #44078. Fixes #44023.

The start_col member is given in chars, while the code previously assumed it was given in bytes.

The more basic issue #44080 doesn't get fixed.

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@est31 est31 force-pushed the master branch 2 times, most recently from 0854250 to b4b0d3e Compare August 25, 2017 10:45
if source_string.chars()
.enumerate()
.filter(|&(i, _)| i < ann.start_col)
.map(|(_, v)|v)
Copy link
Contributor

Choose a reason for hiding this comment

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

.chars().take(ann.start_col)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right, that's better. Not very familiar with iterator APIs.

@est31
Copy link
Member Author

est31 commented Aug 25, 2017

r? @rkruppe

@eddyb
Copy link
Member

eddyb commented Aug 25, 2017

I don't think @rkruppe can r+? Let me know when this is ready.

if source_string[0..ann.start_col].trim() == "" {
if source_string.chars()
.take(ann.start_col)
.collect::<String>()
Copy link
Member

Choose a reason for hiding this comment

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

Wait, why is this collecting to a string?

Copy link
Member

Choose a reason for hiding this comment

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

You can do the same btw with .all(|c| c.is_whitespace()).

@@ -311,7 +311,11 @@ 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

@hanna-kruppe
Copy link
Contributor

@eddyb You're right, I can't r+, and I'm not particularly qualified to review this either. I told @est31 as much on IRC, should have mentioned it here as well. Someone else should review.

@shepmaster shepmaster added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 25, 2017
Fixes rust-lang#44078. Fixes rust-lang#44023.

The start_col member is given in chars,
while the code previously assumed it was given in bytes.

The more basic issue rust-lang#44080 doesn't get fixed.
@est31
Copy link
Member Author

est31 commented Aug 25, 2017

@eddyb sorry I didn't know that @rkruppe didn't have r+ privileges. I just r?'d because he seemed to show interest and I didn't want to burden you...

@est31
Copy link
Member Author

est31 commented Aug 25, 2017

r? @eddyb

@eddyb
Copy link
Member

eddyb commented Aug 25, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Aug 25, 2017

📌 Commit 5a71e12 has been approved by eddyb

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Aug 26, 2017
Fix a byte/char confusion issue in the error emitter

Fixes rust-lang#44078. Fixes rust-lang#44023.

The start_col member is given in chars, while the code previously assumed it was given in bytes.

The more basic issue rust-lang#44080 doesn't get fixed.
@bors
Copy link
Contributor

bors commented Aug 26, 2017

⌛ Testing commit 5a71e12 with merge 669d477...

bors added a commit that referenced this pull request Aug 26, 2017
Fix a byte/char confusion issue in the error emitter

Fixes #44078. Fixes #44023.

The start_col member is given in chars, while the code previously assumed it was given in bytes.

The more basic issue #44080 doesn't get fixed.
@bors
Copy link
Contributor

bors commented Aug 26, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing 669d477 to master...

@bors bors merged commit 5a71e12 into rust-lang:master Aug 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
6 participants