Skip to content

Extern fn declarations can have dangling lifetimes #35851

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
Manishearth opened this issue Aug 20, 2016 · 15 comments
Closed

Extern fn declarations can have dangling lifetimes #35851

Manishearth opened this issue Aug 20, 2016 · 15 comments
Labels
A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness P-medium Medium priority T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@Manishearth
Copy link
Member

extern {
    fn foo() -> &u8;
}

(playpen)

compiles fine. The &u8 has a dangling lifetime, which doesn't compile for functions that have bodies.

This probably should throw an error.

@Manishearth Manishearth added A-lifetimes Area: Lifetimes / regions I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness labels Aug 20, 2016
@Manishearth
Copy link
Member Author

Probably would be a breaking change to fix. But soundness.

@eddyb
Copy link
Member

eddyb commented Aug 20, 2016

Elision was never added to them. cc @rust-lang/lang

@eddyb eddyb added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Aug 20, 2016
@nagisa
Copy link
Member

nagisa commented Aug 20, 2016

Seems fine to break to me. References in extern blocks is very likely not what you want anyway for non-Rust ABIs (i.e. is a bug).

@Manishearth
Copy link
Member Author

Manishearth commented Aug 20, 2016

Well, it also happens with lifetime parameter elision. For the servo-gecko stuff we've managed to configure bindgen to return typedefs to types with lifetimes for things which are conceptually borrows. So we're using lifetime params in ffi today 😄

(thats how I discovered this, someone else added a dangling lifetime and I was bewildered by it. We're going to merge it for now because my safer bindings glue isn't complete yet, so the input lifetime for that function can't exist yet, but it will soon)

@nikomatsakis
Copy link
Contributor

Discussed in @rust-lang/lang meeting. This is definitely a bug; we should "just fix it". We should measure the impact, of course.

@nikomatsakis
Copy link
Contributor

triage: P-medium

@rust-highfive rust-highfive added P-medium Medium priority and removed I-nominated labels Aug 25, 2016
@eddyb
Copy link
Member

eddyb commented Oct 24, 2016

I accidentally unified the two codepaths in my lazy-start branch so consider the impact measured:

@Mark-Simulacrum
Copy link
Member

@eddyb So I presume that we don't currently have the lazy-start branch in tree, since this hasn't been fixed. Perhaps the two codepaths were un-unified?

@eddyb
Copy link
Member

eddyb commented May 15, 2017

Yeah, I redid some things, and tried to avoid regressing anything at all.

@nikomatsakis
Copy link
Contributor

It would probably be good to deprecate (future compat warning?) code using this pattern.

@nikomatsakis
Copy link
Contributor

Well, for sure we should deprecate. It doesn't necessarily have to be a future-compat warning. i.e., we could live with this.

@Centril
Copy link
Contributor

Centril commented Nov 20, 2018

@eddyb @nagisa The snippet in the OP does not compile today... is there anything left to do here?

@Centril Centril added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Feb 18, 2019
@kenta7777
Copy link
Contributor

I'd like to tackle this issue. How shall we begin?

@iluuu1994
Copy link
Contributor

Seems fixed, there's a test for it here.

@Centril
Copy link
Contributor

Centril commented Jul 24, 2019

Indeed it seems so; closing therefore.

@Centril Centril closed this as completed Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness P-medium Medium priority T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants