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

Borrowck doesn't correctly handle lifetime of ~rvalue #2977

Closed
varnie opened this issue Jul 20, 2012 · 4 comments
Closed

Borrowck doesn't correctly handle lifetime of ~rvalue #2977

varnie opened this issue Jul 20, 2012 · 4 comments
Assignees
Labels
A-lifetimes Area: Lifetimes / regions I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Milestone

Comments

@varnie
Copy link

varnie commented Jul 20, 2012

good day. the following intentionally buggy program crashes rustc:

//buggy.rs
use std;
import std::map::hashmap;
import std::map;

fn main() {
    let buggy_map :hashmap<uint, &uint> = hashmap::<uint, &uint>(uint::hash, uint::eq);
    buggy_map.insert(42, ~1);
    buggy_map.insert(43, ~2);
}

here is the result of "rustc buggy.rs":

rustc: /home/varnie/rust/src/llvm/lib/VMCore/Instructions.cpp:1056: void llvm::StoreInst::AssertOK(): Assertion `getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"' failed.
Aborted (core dumped)

rustc version is:
rustc 0.3 (6081eb7 2012-07-15 05:41:24 -0700)
host: i686-unknown-linux-gnu

@ghost ghost assigned nikomatsakis Jul 26, 2012
@graydon
Copy link
Contributor

graydon commented Jul 26, 2012

IMO this should not make it past borrow checking. Niko?

@nikomatsakis
Copy link
Contributor

Indeed, it should not! I can see why it's happening though. Interesting problem.

@nikomatsakis
Copy link
Contributor

I updated the title to more accurately reflect the problem. Or at least a problem, I would expect a failure at runtime, not in LLVM. So in fact I think there are two bugs here. I will file some follow-up issues.

nikomatsakis added a commit that referenced this issue Jul 30, 2012
What we now do is to create a region variable for each &
expression (and also each borrow).  The lifetime of this
variable will be checked by borrowck to ensure it is not greater
than the lifetime of the underlying data.  This both leads to
shorter lifetimes in some cases but also longer in others,
such as taking the address to the interior of unique boxes
tht are rooted in region pointers (e.g., returning a pointer
to the interior of a sendable map).

This may lead to issue #2977 if the rvalue is not POD, because
we may drop the data in trans sooner than borrowck expects us
to.  Need to work out precisely where that fix ought to occur.
nikomatsakis added a commit that referenced this issue Aug 17, 2012
this will require more temporaries, but is probably less magical.
also, it means that borrowck matches trans better, so fewer crashes.
bonus.

Finally, stop warning about implicit copies when we are actually borrowing.

Also, one test (vec-res-add) stopped failing due to #2587, and hence I
added an xfail-test.

Fixes #3217, #2977, #3067
@nikomatsakis
Copy link
Contributor

Fixed in the above commit.

nikomatsakis added a commit that referenced this issue Aug 18, 2012
RalfJung pushed a commit to RalfJung/rust that referenced this issue Jul 14, 2023
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
logging is required when handling errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

3 participants