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

Don't ICE while suggesting updating item path. #100228

Merged
merged 2 commits into from
Aug 9, 2022

Conversation

luqmana
Copy link
Member

@luqmana luqmana commented Aug 7, 2022

When an item isn't found, we may suggest an appropriate import to use. Along with that, we also suggest updating the path to work with the use. Unfortunately, if the code in question originates from a macro, the span used to indicate which part of the path needs updating may not be suitable and cause an ICE (*). Since, such code is not adjustable directly by the user without modifying the macro, just skip the suggestion in such cases.

(*) The ICE happens because the emitter want to indicate to the user what code to delete by referencing a certain span. But in this case, said span has lo == hi == 0 which means it thinks it's a dummy span. Adding a space before the proc macro attribute is enough to stop it from ICE'ing but even then the suggestion doesn't really make any sense:

help: if you import `DataStore`, refer to it directly
  |
1 -  #[dbstruct::dbstruct]
1 +  #[dbstruct::dbstruct]

Since suggestions are best-effort, I just gated this one on can_be_used_for_suggestions which catches cases like this.

Fixes #100199

When an item isn't found, we may suggest an appropriate import to
`use`. Along with that, we also suggest updating the path to work
with the `use`. Unfortunately, if the code in question originates
from a macro, the span used to indicate which part of the path
needs updating may not be suitable and cause an ICE. Since, such
code is not adjustable directly by the user without modifying the
macro, just skip the suggestion in such cases.
@rust-highfive
Copy link
Collaborator

r? @estebank

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

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 7, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 7, 2022
@compiler-errors
Copy link
Member

Hi @luqmana, can you please provide a UI test that demonstrates this fix?

@estebank
Copy link
Contributor

estebank commented Aug 8, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 8, 2022

📌 Commit 15b1daa has been approved by estebank

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 Aug 8, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 8, 2022
Don't ICE while suggesting updating item path.

When an item isn't found, we may suggest an appropriate import to `use`. Along with that, we also suggest updating the path to work with the `use`. Unfortunately, if the code in question originates from a macro, the span used to indicate which part of the path needs updating may not be suitable and cause an ICE (*). Since, such code is not adjustable directly by the user without modifying the macro, just skip the suggestion in such cases.

(*) The ICE happens because the emitter want to indicate to the user what code to delete by referencing a certain span. But in this case, said span has `lo == hi == 0` which means it thinks it's a dummy span. Adding a space before the proc macro attribute is enough to stop it from ICE'ing but even then the suggestion doesn't really make any sense:
```
help: if you import `DataStore`, refer to it directly
  |
1 -  #[dbstruct::dbstruct]
1 +  #[dbstruct::dbstruct]
```

Since suggestions are best-effort, I just gated this one on `can_be_used_for_suggestions` which catches cases like this.

Fixes rust-lang#100199
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 9, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#96478 (Implement `#[rustc_default_body_unstable]`)
 - rust-lang#99787 (Rustdoc-Json: Document HRTB's on DynTrait)
 - rust-lang#100181 (add method to get the mutability of an AllocId)
 - rust-lang#100221 (Don't document impossible to call default trait items on impls)
 - rust-lang#100228 (Don't ICE while suggesting updating item path.)
 - rust-lang#100301 (Avoid `&str` to `String` conversions)
 - rust-lang#100305 (Suggest adding an appropriate missing pattern excluding comments)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit fac84e8 into rust-lang:master Aug 9, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 9, 2022
@luqmana luqmana deleted the suggestion-ice branch August 10, 2022 23:10
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.

ICE: index out of bounds: the len is 0 but the index is 0 in emitter.rs
6 participants