Skip to content

Macros from the "log" crate conflict with #[wasm_bindgen] #158

Closed
@jsheard

Description

@jsheard

This program:

#![feature(proc_macro, wasm_custom_section, wasm_import_module)]

extern crate wasm_bindgen;
#[macro_use] extern crate log;

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub struct ArbitraryStruct {
    x: u32,
}

#[wasm_bindgen]
pub fn info_print(message: &str) -> ArbitraryStruct {
    info!("{}", message);

    ArbitraryStruct { x: 42 }
}

Fails to compile:

error[E0425]: cannot find value `message` in this scope
 --> <info macros>:3:60
  |
3 | $ ( $ arg : tt ) * ) => ( log ! ( $ crate :: Level :: Info , $ ( $ arg ) * ) ;
  |                                                            ^ not found in this scope

The log macros are unable to see any of the surrounding variables, but as far as I can tell this only happens inside a #[wasm_bindgen] annotated function that returns a #[wasm_bindgen] annotated struct. If the function returns nothing or u32 or even String then it compiles successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions