fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.29k stars 301 forks source link

mirrored struct field r#type generates invalid static checks #2416

Open SilverMira opened 21 hours ago

SilverMira commented 21 hours ago

Describe the bug

Given a third party simple struct like this

// third_party

pub struct MyStruct {
  pub r#type: u32
}

and a mirror to it within frb crate

pub use third_party::MyStruct;

#[flutter_rust_bridge::frb(mirror(MyStruct))]
pub struct _MyStruct {
  pub r#type: u32
}

The generated code to type check the mirror doesn't include the r#

// frb_generated.rs
// Section: static_checks

#[allow(clippy::unnecessary_literal_unwrap)]
const _: fn() = || {
{ let MyStruct = None::<crate::api::simple::TestMirror>.unwrap(); let _: u32 = MyStruct.type;
                                                                                        ^^^^
 } 
};

Since type is a keyword, rust won't compile unless it's prefixed with r# and will complain syntax error.

Steps to reproduce

N/A

Logs

N/A

Expected behavior

The generated static check should respect r# if any in the mirror definition

Generated binding code

No response

OS

Windows

Version of flutter_rust_bridge_codegen

2.6.0

Flutter info

No response

Version of clang++

No response

Additional context

No response

fzyzcjy commented 20 hours ago

Looks like a bug, feel free to PR to fix it! Alternative I will work on it later, but since this has easy workaround (do not use r#keyword style) may not be within days.