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 class construction fails #3012

Closed
jesse99 opened this issue Jul 25, 2012 · 5 comments
Closed

cross-crate class construction fails #3012

jesse99 opened this issue Jul 25, 2012 · 5 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries A-resolve Area: Path resolution
Milestone

Comments

@jesse99
Copy link
Contributor

jesse99 commented Jul 25, 2012

In https://github.com/jdm/rust-socket there is code like this:

export socket_handle;

class socket_handle {
    let sockfd: libc::c_int;
    new(x: libc::c_int) {self.sockfd = x;}
    drop {c::close(self.sockfd);}
}

From a different crate I do:

import socket;
let sock = @socket::socket_handle(fd);

And I get:

src/connection.rs:37:13: 37:39 error: mismatched types: expected function or foreign function but found socket::socket_handle
src/connection.rs:37    let sock = @socket::socket_handle(fd);

This is with rust f676547

Work around for now is to export a function that calls the ctor for me.

(I know instance construction is being actively worked on atm, but it seems like there may be a missing unit test for this case).

@ghost ghost assigned catamorphism Jul 26, 2012
@catamorphism
Copy link
Contributor

I'll look at this. I'm suspecting that the problem is that export socket_handle only exports the socket_handle type, and if you deleted the export statement (exporting everything), that would allow you to use the socket_handle constructor from another crate. But that's just a guess.

@brson
Copy link
Contributor

brson commented Aug 15, 2012

structs also have this problem using the field initialization syntax

catamorphism added a commit that referenced this issue Aug 16, 2012
@catamorphism
Copy link
Contributor

Couldn't reproduce with 0d7bef4 (I couldn't get rust-socket to compile with the current version of rustc, but I made a self-contained example), so I added the test case.

@pcwalton
Copy link
Contributor

@brson, do you have a test case? I would like to fix this ASAP if it is still a bug.

@pcwalton pcwalton reopened this Aug 16, 2012
@pcwalton
Copy link
Contributor

You can't construct cross-crate structs. Embarrassing. Fix underway.

bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
RalfJung pushed a commit to RalfJung/rust that referenced this issue Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-resolve Area: Path resolution
Projects
None yet
Development

No branches or pull requests

4 participants