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

Cross-crate regions in statics ICE #8259

Closed
alexcrichton opened this issue Aug 3, 2013 · 6 comments · Fixed by #11012
Closed

Cross-crate regions in statics ICE #8259

alexcrichton opened this issue Aug 3, 2013 · 6 comments · Fixed by #11012
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@alexcrichton
Copy link
Member

This code:

// test.rs
extern mod other;
static a: other::Foo<'static> = other::A;

fn main() {}

// other.rs
pub enum Foo<'self> {
    A,
    B(&'self str),
}

Causes the ICE

test.rs:2:32: 2:40 error: internal compiler error: Cannot relate bound region as superregion: br_self
test.rs:2 static a: other::Foo<'static> = other::A;
                                          ^~~~~~~~

cc @nikomatsakis

@alexcrichton
Copy link
Member Author

Also a similar, but different error:

// test.rs
extern mod other;
static a: other::Bar<'static> = other::C(&other::A);

fn main() {}

// other.rs
pub enum Foo<'self> {
    A,
    B(&'self str),
}
pub enum Bar<'self> {
    C(&'self Foo<'self>),
}
test.rs:2:32: 2:52 error: cannot infer an appropriate lifetime due to conflicting requirements
test.rs:2 static a: other::Bar<'static> = other::C(&other::A);
                                          ^~~~~~~~~~~~~~~~~~~~
note: first, the lifetime cannot outlive lifetime re_bound(br_self)...
test.rs:2:41: 2:50 note: ...due to the following expression
test.rs:2 static a: other::Bar<'static> = other::C(&other::A);
                                                   ^~~~~~~~~
note: but, the lifetime must be valid for the static lifetime...
test.rs:2:32: 2:52 note: ...due to the following expression
test.rs:2 static a: other::Bar<'static> = other::C(&other::A);
                                          ^~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

@alexcrichton
Copy link
Member Author

I've also confirmed that if everything is defined in the same crate, it all compiles just fine.

@alexcrichton
Copy link
Member Author

This may be related to #7634, although it's a different error message so I'm not sure of it.

@alexcrichton
Copy link
Member Author

This is not related to #7634

@erickt
Copy link
Contributor

erickt commented Aug 17, 2013

I just ran into this myself. One interesting thing I found is that the error happens due to the empty variant. This compiles fine for me:

// test.rs
extern mod other;
static a: other::Foo<'static> = other::A(());

fn main() {}

// other.rs
pub enum Foo<'self> {
    A(()),
    B(&'self str),
}

@alexcrichton
Copy link
Member Author

Appears to be fixed now, flagging as needstest.

bors added a commit that referenced this issue Dec 18, 2013
alexcrichton added a commit that referenced this issue Dec 19, 2013
Closes #5806
Closes #5950
Closes #7178
Closes #8259
Closes #8578
Closes #8851
Closes #9129
Closes #10412
flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 13, 2022
Fix `deref_addrof`

fixes rust-lang#8247

This would supersede rust-lang#8259

changelog: Don't lint `deref_addrof` when the dereference and the borrow occur in different contexts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants