-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
#[no_mangle] is silently ignored on generic functions #26753
Comments
extern {
fn decide_action<T: Game>(g: &T);
} /cc @nikomatsakis you cared about this. |
It's not about the trait bound but the type parameter of course. Rustc only instantiates those versions of the function that are actually used. Your workaround -- using |
pub extern fn
s vanish if a trait bound is present
|
Dupe of #15844. Thanks for filing! |
A grossly simplified illustrative example.
Assume we're in a library crate (I want to get a shared object out of this so I'm using
--crate-type dylib
but this appears to be a problem for the general case), and we have the following items defined.If we now wish to expose a function that uses a
Game
implementor across the library boundary (if, for example, you wish todlopen(3)
thendlsym(3)
it), one might expect that they could define a trait bound:(There's a reason I stuffed a
println!
in there.)Compile:
rustc testlib.rs --crate-type dylib -g --out-dir target/debug
, then:Which is, of course, the
println!
format string. Note a lack of any symbol matching the exact namedecide_action
.OK, but if we put the
Game
impl in aBox
:Suddenly, it comes back!
gah!
This presents on stable, beta, and nightly.
This strikes me as a bug, although I'm not sure what in. I suppose you cannot really enforce traits across the
extern
boundary (although that would be Nice To Have if there's Rust on the other side). On the other hand, how does a box of trait somehow manage to subvert this? I supose this is a compiler error, but I'm a bit fuzzy about what the error is (I guess that ifextern fn
, then if trait bound, then fail, else do theextern fn
).(As a general note, "FFI" from Rust to Rust, where you explicitly want to plug dylibs, is substantially more uncomfortable than expected.)
The text was updated successfully, but these errors were encountered: