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 mispositioned span in suggestions with wide characters #47407

Merged
merged 6 commits into from
Jan 17, 2018

Conversation

gaurikholkar-zz
Copy link

@gaurikholkar-zz gaurikholkar-zz commented Jan 13, 2018

This fixes #47377 and #47380.

The output now looks like this

error[E0369]: binary operation `+` cannot be applied to type `&str`
 --> h.rs:3:11
  |
3 |     let _a = b + ", World!";
  |              ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings
help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
  |
3 |     let _a = b.to_owned() + ", World!";
  |              ^^^^^^^^^

error: aborting due to previous error

For the case when emojis are involved, it gives the new output for proper indentation.
But for an indentation as follows,

fn main() {
let b = "hello";
    let _a = b + ", World!";
}

it still mispositions the span

3 |     println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!";
  |                                           ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings
  |
3 |     println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!";
  |                                           ^^^^^^^
error: aborting due to previous erro

cc @estebank @est31

@rust-highfive
Copy link
Collaborator

r? @estebank

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

@kennytm kennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 13, 2018
# fn main() {} // don't insert it for us; that'll break imports
```
"
"explanation": null
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 explanation deleted?

Copy link
Author

@gaurikholkar-zz gaurikholkar-zz Jan 13, 2018

Choose a reason for hiding this comment

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

@kennytm it was failing locally. Just thought I'll push and see what happens

@@ -1187,7 +1187,7 @@ impl EmitterWriter {
let sub_len = parts[0].snippet.trim().chars().fold(0, |acc, ch| {
acc + unicode_width::UnicodeWidthChar::width(ch).unwrap_or(0)
});
let underline_start = span_start_pos.col.0 + start;
let underline_start = span_start_pos.col_display + start;
let underline_end = span_start_pos.col.0 + start + sub_len;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need to change this line too to use col_display.

@estebank
Copy link
Contributor

Please add an ui test with both the tab and emoji cases.

@gaurikholkar-zz
Copy link
Author

Have made the suggested changes. Investigating why it is not working for the emoji example.

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

Some tidy check errors to fix:

[00:03:36] tidy error: /checkout/src/test/ui/issue-47377-1.rs:13: line longer than 100 chars
[00:03:36] tidy error: /checkout/src/test/ui/issue-47377-1.rs: missing trailing newline
[00:03:36] tidy error: /checkout/src/test/ui/issue-47377.rs:13: line longer than 100 chars
[00:03:36] tidy error: /checkout/src/test/ui/issue-47377.rs: missing trailing newline
[00:03:37] some tidy checks failed


fn main(){
let b = "hello";
println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; //~ERROR 13:37: 13:51: binary operation `+` cannot be applied to type `&str` [E0369]
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the error check to the line below

Copy link
Member

Choose a reason for hiding this comment

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

Also you should probably use 4 spaces of indentation here, as well as rename the file to issue-47380.rs.


fn main(){
let b = "hello";
let _a = b + ", World!"; //~ERROR 13:14: 13:28: binary operation `+` cannot be applied to type `&str` [E0369]
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the error check to the line below (//~^ ERROR binary operation...)

fn main(){
let b = "hello";
let _a = b + ", World!"; //~ERROR 13:14: 13:28: binary operation `+` cannot be applied to type `&str` [E0369]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add new line (your editor should be doing this by default).

// except according to those terms.

fn main(){
let b = "hello";
Copy link
Member

Choose a reason for hiding this comment

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

This file doesn't use tabs. You need to change the indentation of these two lines to use tabs and then add a line // ignore-tidy-tab to get tidy passing, like done in src/test/ui/codemap_tests/tab_2.rs.

Copy link
Author

Choose a reason for hiding this comment

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

@est31 I changed it to ~^ ERROR E0369 }. Do I still need //ignore-tidy-tab?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think ignore-tidy-tab is so that the tidy check for the project doesn't block the merge of the PR, while keeping the tabs in the code so that we avoid regressions in the handling of them. I believe your editor might be "helpfully" replacing tabs with spaces.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah it was. Can you have a look now?

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 14, 2018
// except according to those terms.

fn main(){
let b = "hello";
Copy link
Contributor

Choose a reason for hiding this comment

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

I think ignore-tidy-tab is so that the tidy check for the project doesn't block the merge of the PR, while keeping the tabs in the code so that we avoid regressions in the handling of them. I believe your editor might be "helpfully" replacing tabs with spaces.

| ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings
help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
|
13 | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!";
Copy link
Contributor

Choose a reason for hiding this comment

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

Note for reviewers: this looks misaligned on the browser, but not in terminals that handle emojis correctly.

Copy link
Author

Choose a reason for hiding this comment

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

@estebank the output is misaligned in iTerm though

// except according to those terms.
fn main(){
let b = "hello";
let _a = b + ", World!";
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still using spaces instead of tabs.

// <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.
// ignore-tidy-tab
Copy link
Member

Choose a reason for hiding this comment

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

This is not the file that should get this line, the other one should get it with the tabs. Here we are testing for emojis.

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 16, 2018
@estebank
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 17, 2018

📌 Commit efe3d69 has been approved by estebank

@estebank estebank changed the title fix mispositioned span Fix mispositioned span in suggestions with wide characters Jan 17, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Jan 17, 2018
fix mispositioned span

This fixes rust-lang#47377

The output now looks like this
```
error[E0369]: binary operation `+` cannot be applied to type `&str`
 --> h.rs:3:11
  |
3 |     let _a = b + ", World!";
  |              ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings
help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
  |
3 |     let _a = b.to_owned() + ", World!";
  |              ^^^^^^^^^

error: aborting due to previous error
```
For the case when emojis are involved,  it gives the new output for proper indentation.
But for an indentation as follows,
```
fn main() {
let b = "hello";
    let _a = b + ", World!";
}
```
it still mispositions the span
```
3 |     println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!";
  |                                           ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings
  |
3 |     println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!";
  |                                           ^^^^^^^
error: aborting due to previous erro
```

cc @estebank  @est31
kennytm added a commit to kennytm/rust that referenced this pull request Jan 17, 2018
fix mispositioned span

This fixes rust-lang#47377

The output now looks like this
```
error[E0369]: binary operation `+` cannot be applied to type `&str`
 --> h.rs:3:11
  |
3 |     let _a = b + ", World!";
  |              ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings
help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
  |
3 |     let _a = b.to_owned() + ", World!";
  |              ^^^^^^^^^

error: aborting due to previous error
```
For the case when emojis are involved,  it gives the new output for proper indentation.
But for an indentation as follows,
```
fn main() {
let b = "hello";
    let _a = b + ", World!";
}
```
it still mispositions the span
```
3 |     println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!";
  |                                           ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings
  |
3 |     println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!";
  |                                           ^^^^^^^
error: aborting due to previous erro
```

cc @estebank  @est31
bors added a commit that referenced this pull request Jan 17, 2018
@bors bors merged commit efe3d69 into rust-lang:master Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Beta regression in span printing with tabs involved
7 participants