Skip to content

rustsym can give wrong results because it doesn't run macros #13

@mcclure

Description

@mcclure

The problem

So I've got this small project (can provide you a git repo if it helps) that uses the "mlua" crate. I have a file with this code:

use mlua::Lua;
use mlua::prelude::{LuaResult, LuaTable};

fn func1(_: &Lua, _: ()) -> LuaResult<()> {
    Ok(())
}

fn func2(_: &Lua, _: ()) -> LuaResult<()> {
    Ok(())
}

#[mlua::lua_module]
pub fn module(lua: &Lua) -> LuaResult<LuaTable> {
    lua.create_table_from(vec![
        ("func1", lua.create_function(func1)?),
        ("func2", lua.create_function(func2)?),
    ])
}

Now, I have a problem: I want to use this "module" function in another file. But see that #[mlua::lua_module]? That's a macro the mlua crate publishes, and it actually changes the name (and visibility) of the function it is attached to. It turns out it changes it to luaopen_module. But I didn't know that, so I installed rustsym.

So I run rustsym and:

Screen Shot 2021-02-21 at 12 59 26 AM

Cool, so there's an exported function named "module".

Except no:

Screen Shot 2021-02-20 at 7 59 13 PM

Eventually I figure out I can also use cargo doc --open for this purpose. Here's what it says exists:

Screen Shot 2021-02-21 at 12 42 34 AM

Screen Shot 2021-02-21 at 12 42 38 AM

Expected behavior

I think rustsym gave the incorrect name for luaopen_module because it doesn't run macros, whereas cargo doc --open gave the correct name because it did. Ideally rustsym should run macros.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions