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 Python-like slicing and suggest how to fix #111133

Merged
merged 4 commits into from
Nov 28, 2023

Conversation

hkmatsumoto
Copy link
Member

Fix #108215

@rustbot
Copy link
Collaborator

rustbot commented May 3, 2023

r? @wesleywiser

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 3, 2023
| ~~
help: maybe write a path separator here
|
LL | &[1, 2, 3][1::2];
Copy link
Member

Choose a reason for hiding this comment

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

it would be nice if we could get rid of this suggestion

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds fair, enclosing the code that triggers this suggestion with else-block should get the job done

// if a previous and next token of the current one is
// integer literal (e.g. `1:42`), it's likely a range
// expression for Pythonistas and we can suggest so.
if self.prev_token.is_integer_lit()
Copy link
Member

Choose a reason for hiding this comment

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

can you add a call to self.may_recover() just to be safe?

@wesleywiser wesleywiser 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 May 8, 2023
@hkmatsumoto hkmatsumoto 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 May 16, 2023
"maybe write a path separator here",
"::",
self.token.span,
"you might have meant to make a slice with range index",
Copy link
Member

@Noratrieb Noratrieb Jun 6, 2023

Choose a reason for hiding this comment

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

the error message is too specific for the help being generic. It's sadly not easy to only trigger this only inside indexing expressions, so we should make the message less specific (while still being useful). Maybe you might have meant a range expression? I think that within the context of indexing, that message should still be useful enough. If you don't think so, you could also add , which can be used for indexing at the end, that should really cover it (but being a little verbose).

other than that, I like that change and would be happy to merge it after you improve the message

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point. As of now that the diagnostic will be triggered in a broader context than indexing, your suggestion feels just right

@compiler-errors
Copy link
Member

@rustbot author

@rustbot rustbot 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 Jun 22, 2023
@Dylan-DPC
Copy link
Member

@hkmatsumoto any updates on this?

@Noratrieb
Copy link
Member

r? compiler

@rustbot rustbot assigned TaKO8Ki and unassigned Noratrieb Aug 17, 2023
@hkmatsumoto
Copy link
Member Author

Oops, so sorry for taking long to respond. This was buried under a pile of notifications I got during AFK for exams...

Also addressed merge conflicts upon rebasing.
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Nov 27, 2023

@rustbot review

@rustbot rustbot 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 Nov 27, 2023
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Nov 27, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 27, 2023

📌 Commit acec70d has been approved by TaKO8Ki

It is now in the queue for this repository.

@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-review Status: Awaiting review from the assignee but also interested parties. labels Nov 27, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 27, 2023
… r=TaKO8Ki

Detect Python-like slicing and suggest how to fix

Fix rust-lang#108215
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 27, 2023
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#111133 (Detect Python-like slicing and suggest how to fix)
 - rust-lang#114708 (Allow setting `rla` labels via `rustbot`)
 - rust-lang#117526 (Account for `!` arm in tail `match` expr)
 - rust-lang#118282 (effects: Run `enforce_context_effects` for all method calls)
 - rust-lang#118366 (Detect and reject malformed `repr(Rust)` hints)
 - rust-lang#118375 (Add -Zunpretty=stable-mir output test)

r? `@ghost`
`@rustbot` modify labels: rollup
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Nov 27, 2023
… r=TaKO8Ki

Detect Python-like slicing and suggest how to fix

Fix rust-lang#108215
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 27, 2023
…llaumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#111133 (Detect Python-like slicing and suggest how to fix)
 - rust-lang#114708 (Allow setting `rla` labels via `rustbot`)
 - rust-lang#117526 (Account for `!` arm in tail `match` expr)
 - rust-lang#118341 (Simplify indenting in THIR printing)
 - rust-lang#118366 (Detect and reject malformed `repr(Rust)` hints)
 - rust-lang#118375 (Add -Zunpretty=stable-mir output test)
 - rust-lang#118381 (rustc_span: Use correct edit distance start length for suggestions)
 - rust-lang#118384 (Address unused tuple struct fields in rustdoc)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 28, 2023
…mpiler-errors

Rollup of 9 pull requests

Successful merges:

 - rust-lang#111133 (Detect Python-like slicing and suggest how to fix)
 - rust-lang#114708 (Allow setting `rla` labels via `rustbot`)
 - rust-lang#117526 (Account for `!` arm in tail `match` expr)
 - rust-lang#118172 (Add `pretty_terminator` to pretty stable-mir)
 - rust-lang#118202 (Added linker_arg(s) Linker trait methods for link-arg to be prefixed "-Wl," for cc-like linker args and not verbatim)
 - rust-lang#118374 (QueryContext: rename try_collect_active_jobs -> collect_active_jobs, change return type from Option<QueryMap> to QueryMap)
 - rust-lang#118381 (rustc_span: Use correct edit distance start length for suggestions)
 - rust-lang#118382 (Address unused tuple struct fields in the compiler)
 - rust-lang#118384 (Address unused tuple struct fields in rustdoc)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 203aaf6 into rust-lang:master Nov 28, 2023
11 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 28, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 28, 2023
Rollup merge of rust-lang#111133 - hkmatsumoto:handle-python-slicing, r=TaKO8Ki

Detect Python-like slicing and suggest how to fix

Fix rust-lang#108215
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gracefully handle python-esque sequence slicing
8 participants