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

internal compiler error: no enclosing scope with id XY #3860

Closed
Blub opened this issue Oct 25, 2012 · 6 comments
Closed

internal compiler error: no enclosing scope with id XY #3860

Blub opened this issue Oct 25, 2012 · 6 comments
Labels
A-lifetimes Area: Lifetimes / regions I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Milestone

Comments

@Blub
Copy link

Blub commented Oct 25, 2012

When a method returns an &self/mut Foo, and the caller doesn't store the returned value somewhere, there's an internal compiler error. See the following code. Note how when storing the result of x.stuff() in a variable makes it work.

struct Foo { x: int }

impl Foo {
    fn stuff(&mut self) -> &self/mut Foo {
        return self;
    }
}

fn main() {
    let mut x = @mut Foo { x: 3 };
    x.stuff(); // error: internal compiler error: no enclosing scope with id 49
    // storing the result removes the error, so replacing the above
    // with the following, works:
    // let _y = x.stuff()

    // also making 'stuff()' not return anything fixes it
    // I guess the "dangling &ptr" cuases issues?
}
@timford
Copy link

timford commented Oct 28, 2012

I was asked to add the following, which exhibits the same or a similar problem, encountered using:
rustc 0.5 (07edf90 2012-10-13 05:57:13 -0700)
host: x86_64-unknown-linux-gnu

use std::net_url;
use core::result;

fn main() {
        let urlstr = "test";

        // this works without error or warning
        let r: &result::Result<net_url::Url,~str> = &net_url::from_str(urlstr);
        result::get_ref( r );

        // this gives me:
        // error: illegal borrow: borrowed value does not live long enough
        // note: borrowed pointer must be valid for unknown scope: 59.  Please report a bug....
        result::get_ref( &net_url::from_str(urlstr) );
}

@catamorphism
Copy link
Contributor

Reproduced as of d2ad028

@ghost ghost assigned catamorphism Dec 13, 2012
@catamorphism
Copy link
Contributor

I have a fix; running tests.

catamorphism added a commit to catamorphism/rust that referenced this issue Dec 14, 2012
This is for consistency with borrowck. Changing borrowck would
also be an alternative, but I found it easier to change trans :-)

This eliminates an ICE in trans where the scope for a particular
borrow was a statement ID, but the code in trans that does cleanups
wasn't finding the block with that scope. As per rust-lang#3860
@erickt
Copy link
Contributor

erickt commented Dec 22, 2012

I just ran into a similar error with this code:

struct Parser {
    mut otag: @~str,
}

fn add_tag(self: &Parser) {
    *self.otag + *self.otag;
}

fn main() {}

That resulted in this error:

error: internal compiler error: no enclosing scope with id 21

I haven't been able to reduce it down beyond this.

@catamorphism
Copy link
Contributor

I know what the bug is here, and had a fix in #4192, but the problem was that it degraded performance. I can probably come up with a fix to borrowck instead of trans that won't degrade performance. Just letting you know, @erickt , that the bug is still being worked on (I've been on leave so I didn't get to it sooner).

catamorphism added a commit to catamorphism/rust that referenced this issue Jan 19, 2013
…opes

This eliminates an ICE in trans where the scope for a particular
borrow was a statement ID, but the code in trans that does cleanups
wasn't finding the block with that scope. As per rust-lang#3860

preserve looks at a node ID to see if it's for a statement -- if it
is, it uses the enclosing scope instead when updating the map that
trans looks at later.
catamorphism added a commit that referenced this issue Jan 23, 2013
…opes

This eliminates an ICE in trans where the scope for a particular
borrow was a statement ID, but the code in trans that does cleanups
wasn't finding the block with that scope. As per #3860

preserve looks at a node ID to see if it's for a statement -- if it
is, it uses the enclosing scope instead when updating the map that
trans looks at later.

I added a comment noting that this is not the best fix (since it may
cause boxes to be frozen for longer than necessary) and referring
to #3511.

r=nmatsakis
@catamorphism
Copy link
Contributor

Fixed in 9d67267 -- but see the comments in borrowck::preserve from that commit for a warning.

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

4 participants