Skip to content

Fix ICE when nameless borrowed binding is dropped #47869

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

Closed
wants to merge 1 commit into from
Closed

Fix ICE when nameless borrowed binding is dropped #47869

wants to merge 1 commit into from

Conversation

slashnick
Copy link

With -Znll-dump-cause, when a borrow check fails because of a DropVar, the LocalDecl for that variable may not have a name.

Fixes #47646

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (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.

@kennytm
Copy link
Member

kennytm commented Jan 31, 2018

Thanks for the PR! We’ll periodically check in on it to make sure that @michaelwoerister or someone else from the team reviews it soon.

@kennytm kennytm added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 31, 2018
@pietroalbini
Copy link
Member

@michaelwoerister ping from triage! This PR needs a review.

@shepmaster
Copy link
Member

r? @Zoxc

@Zoxc
Copy link
Contributor

Zoxc commented Feb 9, 2018

r? @nikomatsakis

@rust-highfive rust-highfive assigned nikomatsakis and unassigned Zoxc Feb 9, 2018
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

So, the PR seems fine, but I wonder if we can do better with the error message. I had to resort to reading the MIR to better understand what is happening here.

For those curious: the variableborrow is being moved into the tuple, and the tuple is then dropped (not borrow).

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Feb 12, 2018

I think what I would want is maybe something like:

error[E0502]: cannot borrow `heap` as immutable because it is also borrowed as mutable
  --> $DIR/issue-47646.rs:25:30
   |
21 |     let borrow = heap.peek_mut();
   |                  ---- mutable borrow occurs here
...
24 |         match (borrow, ()) {
   |               ------------ borrow may end up in a temporary, created here
25 |             println!("{:?}", heap); //~ ERROR cannot borrow `heap` as immutable
   |                              ^^^^ immutable borrow occurs here
...
28 |     };
   |      - temporary later dropped here, potentially using the reference

error: aborting due to previous error

@nikomatsakis
Copy link
Contributor

We could produce that, I suppose, by

  • finding the temporary being dropped
  • searching for the span of where it is assigned
    • hopefully it is assigned only once =)
  • and using that span for the "borrow may end up in a temporary, created here"

If there are multiple assignments, maybe we give up, and just say "borrow may be used when a temporary value is dropped here" or something.

@nikomatsakis
Copy link
Contributor

@nickfrostatx what do you think? =) You be up for that?

@slashnick
Copy link
Author

@nikomatsakis Sure, that would be a much more helpful message. I'll try to get that working.

@nikomatsakis nikomatsakis 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 Feb 13, 2018
@pietroalbini
Copy link
Member

Hi @nickfrostatx, did you get that working so this PR can be merged?

@pietroalbini
Copy link
Member

@nickfrostatx thank you for taking the time to send this PR! Unfortunately, there was no activity in it for more than two weeks, so I'm closing this. If you have time to work on it again in the future feel free to open another one, we'll be happy to review and merge it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

8 participants