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

Detect when negative literal indices are used and suggest appropriate code #89251

Merged
merged 2 commits into from
Oct 1, 2021

Conversation

estebank
Copy link
Contributor

No description provided.

@rust-highfive
Copy link
Collaborator

r? @davidtwco

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 25, 2021
@meithecatte
Copy link
Contributor

Suggested test case (no error should trigger):

use core::ops::Index;
struct X;
impl Index<i32> for X {
    type Output = ();
    
    fn index(&self, _: i32) -> &() {
        &()
    }
}

fn main() {
    X[-1];
}

@estebank
Copy link
Contributor Author

@NieDzejkob added your case to the test.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

This is looking really good, some minor changes. r=me after fixing.

compiler/rustc_typeck/src/check/place_op.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/check/place_op.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/check/place_op.rs Outdated Show resolved Hide resolved
@davidtwco davidtwco 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 Sep 28, 2021
@estebank
Copy link
Contributor Author

@bors r=davidtwco

@bors
Copy link
Contributor

bors commented Sep 28, 2021

📌 Commit e19d82f has been approved by davidtwco

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 28, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 1, 2021
…arth

Rollup of 7 pull requests

Successful merges:

 - rust-lang#88838 (Do not suggest importing inaccessible items)
 - rust-lang#89251 (Detect when negative literal indices are used and suggest appropriate code)
 - rust-lang#89321 (Rebase resume argument projections during state transform)
 - rust-lang#89327 (Pick one possible lifetime in case there are multiple choices)
 - rust-lang#89344 (Cleanup lower_generics_mut and make span be the bound itself)
 - rust-lang#89397 (Update `llvm` submodule to fix function name mangling on x86 Windows)
 - rust-lang#89412 (Add regression test for issues rust-lang#88969 and rust-lang#89119 )

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e77d163 into rust-lang:master Oct 1, 2021
@rustbot rustbot added this to the 1.57.0 milestone Oct 1, 2021
@estebank estebank deleted the negative-index-literals branch November 9, 2023 05:14
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.

7 participants