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 into() cast paren check precedence #47702

Merged
merged 1 commit into from
Jan 25, 2018
Merged

Fix into() cast paren check precedence #47702

merged 1 commit into from
Jan 25, 2018

Conversation

etaoins
Copy link
Contributor

@etaoins etaoins commented Jan 24, 2018

As discussed in #47699 the logic for determining if an expression needs parenthesis when suggesting an .into() cast is incorrect. Two broken examples from nightly are:

error[E0308]: mismatched types
 --> main.rs:4:10
  |
4 |     test(foo as i8);
  |          ^^^^^^^^^ expected i32, found i8
help: you can cast an `i8` to `i32`, which will sign-extend the source value
  |
4 |     test(foo as i8.into());
  |
error[E0308]: mismatched types
 --> main.rs:4:10
  |
4 |     test(*foo);
  |          ^^^^ expected i32, found i8
help: you can cast an `i8` to `i32`, which will sign-extend the source value
  |
4 |     test(*foo.into());
  |

As suggested by @petrochenkov switch the precedence check to PREC_POSTFIX. This catches both as and unary operators. Fixes #47699.

r? @petrochenkov

As discussed in #47699 the logic for determining if an expression needs
parenthesis when suggesting an `.into()` cast is incorrect. Two broken
examples from nightly are:

```
error[E0308]: mismatched types
 --> main.rs:4:10
  |
4 |     test(foo as i8);
  |          ^^^^^^^^^ expected i32, found i8
help: you can cast an `i8` to `i32`, which will sign-extend the source value
  |
4 |     test(foo as i8.into());
  |
```

```
error[E0308]: mismatched types
 --> main.rs:4:10
  |
4 |     test(*foo);
  |          ^^^^ expected i32, found i8
help: you can cast an `i8` to `i32`, which will sign-extend the source value
  |
4 |     test(*foo.into());
  |
```

As suggested by @petrochenkov switch the precedence check to
PREC_POSTFIX. This catches both `as` and unary operators. Fixes #47699.
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@petrochenkov
Copy link
Contributor

@bore r+ rollup

@kennytm
Copy link
Member

kennytm commented Jan 24, 2018

@bors r=petrochenkov rollup

@bors
Copy link
Contributor

bors commented Jan 24, 2018

📌 Commit 65b1e86 has been approved by petrochenkov

@kennytm kennytm added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 24, 2018
@petrochenkov
Copy link
Contributor

@etaoins

As suggested by @petrochenkov switch the precedence check to
PREC_POSTFIX

A small remark - it's better to avoid @mentioning people in commit descriptions because it will may generate quite a few unwanted email notification while the commit passes through CI, especially with rollups.

@kennytm
Copy link
Member

kennytm commented Jan 25, 2018

@petrochenkov That's the PR description copied to the commit message by bors though...

@petrochenkov
Copy link
Contributor

@kennytm
Hmm, maybe bors should remove @s before copying the message?
I often manually remove "r? me"s from PR descriptions assigned to me (but often forget) because they generate unwanted notifications too.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jan 25, 2018
…nce, r=petrochenkov

Fix into() cast paren check precedence

As discussed in rust-lang#47699 the logic for determining if an expression needs parenthesis when suggesting an `.into()` cast is incorrect. Two broken examples from nightly are:

```
error[E0308]: mismatched types
 --> main.rs:4:10
  |
4 |     test(foo as i8);
  |          ^^^^^^^^^ expected i32, found i8
help: you can cast an `i8` to `i32`, which will sign-extend the source value
  |
4 |     test(foo as i8.into());
  |
```

```
error[E0308]: mismatched types
 --> main.rs:4:10
  |
4 |     test(*foo);
  |          ^^^^ expected i32, found i8
help: you can cast an `i8` to `i32`, which will sign-extend the source value
  |
4 |     test(*foo.into());
  |
```

As suggested by @petrochenkov switch the precedence check to `PREC_POSTFIX`. This catches both `as` and unary operators. Fixes rust-lang#47699.

r? @petrochenkov
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jan 25, 2018
…nce, r=petrochenkov

Fix into() cast paren check precedence

As discussed in rust-lang#47699 the logic for determining if an expression needs parenthesis when suggesting an `.into()` cast is incorrect. Two broken examples from nightly are:

```
error[E0308]: mismatched types
 --> main.rs:4:10
  |
4 |     test(foo as i8);
  |          ^^^^^^^^^ expected i32, found i8
help: you can cast an `i8` to `i32`, which will sign-extend the source value
  |
4 |     test(foo as i8.into());
  |
```

```
error[E0308]: mismatched types
 --> main.rs:4:10
  |
4 |     test(*foo);
  |          ^^^^ expected i32, found i8
help: you can cast an `i8` to `i32`, which will sign-extend the source value
  |
4 |     test(*foo.into());
  |
```

As suggested by @petrochenkov switch the precedence check to `PREC_POSTFIX`. This catches both `as` and unary operators. Fixes rust-lang#47699.

r? @petrochenkov
bors added a commit that referenced this pull request Jan 25, 2018
Rollup of 10 pull requests

- Successful merges: #47534, #47609, #47679, #47691, #47700, #47702, #47717, #47721, #47726, #47729
- Failed merges:
@bors bors merged commit 65b1e86 into rust-lang:master Jan 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants