Skip to content

bindgen: Generates names which may have Rust keywords #7784

@jcbhmr

Description

@jcbhmr

Thanks for filing a bug report! Please fill out the TODOs below.

Note: if you want to report a security issue, please read our security policy!

Test Case

TODO: upload Wasm file here

Steps to Reproduce

  • TODO: first, ...
  • TODO: second, ...
  • Etc...
  • copy-paste the wit below into wit/world
  • use the bindgen!() macro to create the bindings modules
  • see error
package typst-community:unicode-math-class;

/// ROOT [Crate unicode_math_class](https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/)
interface crate {
    // [Enum unicode_math_class::MathClass](https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/enum.MathClass.html)
    enum math-class {
        normal,
        alphabetic,
        binary,
        closing,
        diacritic,
        fence,
        glyph-part,
        large,
        opening,
        punctuation,
        relation,
        space,
        unary,
        vary,
        special,
    }

    /// [Constant unicode_math_class::REVISION](https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/constant.REVISION.html)
    revision: func() -> u8;

    /// [Function unicode_math_class::class](https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/fn.class.html)
    class: func(c: string) -> option<math-class>;
}

/// [Crate unicode_math_class](https://docs.rs/unicode-math-class/0.1.0/unicode_math_class/)
world unicode-math-class {
    export crate;
}

Expected Results

TODO: What do you expect to happen?

Similar to wit-bindgen, I expected the "crate" to become "crate_"

cargo_component_bindings::generate!();
use bindings::exports::typst_community::unicode_math_class::crate_ as wit;
use unicode_math_class as rs;

mod math_class;

pub struct Component;

impl wit::Guest for Component {
    fn revision() -> u8 {
        rs::REVISION
    }
    fn class(c: String) -> Option<wit::MathClass> {
        let c = c.chars().next().unwrap();
        rs::class(c).map(|x| x.into())
    }
}

Actual Results

TODO: What actually happens? Panic? Segfault? Incorrect result?

jcbhmr@PIG-2016:~/Documents/unicode-math-class.wasm$ make test-rs
cargo test -p tests-rs
   Compiling tests-rs v0.0.0 (/home/jcbhmr/Documents/unicode-math-class.wasm/tests/rs)
error: expected identifier, found keyword `crate`
 --> tests/rs/tests/common/mod.rs:6:5
  |
6 |     bindgen!(in "../../wit");
  |     ^^^^^^^^^^^^^^^^^^^^^^^^ expected identifier, found keyword
  |
  = note: this error originates in the macro `bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

Versions and Environment

Wasmtime version or commit: 16.0.0

Operating system: Windows 10 using WSL

Architecture: x86_64

Extra Info

Anything else you'd like to add?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior in the current implementation that needs fixinggood first issueIssues that are good for new contributors to tackle!wasm-proposal:component-modelIssues related to the WebAssembly Component Model proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions