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

Use only the appropriate trait when looking up operator overloads #12402 #12493

Merged
merged 4 commits into from
Feb 25, 2014

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Feb 23, 2014

Fixes #12402.

@alexcrichton
Copy link
Member

This appears to have caused many travis failures, did you run tests before opening this PR?

@nikomatsakis
Copy link
Contributor

I'll review

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
bors added a commit that referenced this pull request Feb 25, 2014
@bors bors closed this Feb 25, 2014
@bors bors merged commit 3950471 into rust-lang:master Feb 25, 2014
@eddyb eddyb deleted the saner-overloads branch February 25, 2014 23:15
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
Fix a couple of weak warnings found by rust-analyzer itself
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this pull request Mar 21, 2024
fix span calculation for non-ascii in `needless_return`

Fixes rust-lang#12491

Probably fixes rust-lang#12328 as well, but that one has no reproducer, so 🤷

The bug was that the lint used `rfind()` for finding the byte index of the start of the previous non-whitespace character:
```
// abc\n     return;
     ^
```
... then subtracting one to get the byte index of the actual whitespace (the `\n` here).
(Subtracting instead of adding because it treats this as the length from the `return` token to the `\n`)

That's correct for ascii, like here, and will get us to the `\n`, however for non ascii, the `c` could be multiple bytes wide, which would put us in the middle of a codepoint if we simply subtract 1 and is what caused the ICE.

There's probably a lot of ways we could fix this.
This PR changes it to iterate backwards using bytes instead of characters, so that when `rposition()` finally finds a non-whitespace byte, we *know* that we've skipped exactly 1 byte. This was *probably*(?) what the code was intending to do

changelog: Fix ICE in [`needless_return`] when previous line end in a non-ascii character
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Operator overloading only considers the method name, not which trait is implemented
4 participants