Skip to content
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

Use Locked constructor instead of into #924

Closed

Conversation

stargazing-dino
Copy link

I don't know why but when I was building this lib for my little micro controller in no_std, I was getting this error:

error[E0277]: the trait bound `RwLock<StringsInterner>: core::convert::From<StringsInterner>` is not satisfied
  --> /Users/katzen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rhai-1.19.0/src/api/mod.rs:66:68
   |
66 |             self.interned_strings = Some(StringsInterner::new(max).into());
   |                                                                    ^^^^ the trait `core::convert::From<StringsInterner>` is not implemented for `RwLock<StringsInterner>`, which is required by `StringsInterner: core::convert::Into<_>`
   |
   = note: required for `StringsInterner` to implement `core::convert::Into<RwLock<StringsInterner>>`

So I tried just pulling in the Locked type and using that instead. Seemed to fix things.

Here is my a snippet of my dependency list if it's interesting:

[dependencies]
# TODO: had to add this because rhai isn't requesting a feature it relies on.
once_cell = { version = "1.19.0", default-features = false, features = [
    "alloc",
] }
# https://rhai.rs/book/start/builds/minimal.html
rhai = { version = "1.19.0", default-features = false, features = [
    "no_std",
    "sync",
    "only_i32",
    "f32_float",
    "no_custom_syntax",
    "no_time",
] }

@schungx
Copy link
Collaborator

schungx commented Oct 24, 2024

It could be that RwLock in no-std has some compatibility issues...

However we have been liberally using .into() everywhere so I wonder why it only trips up here...

BTW which microcontroller are you building for? We don't have many examples of no-std builds and I'd love if you can share some snippets.

Also the need for once_cell/alloc is for your own code, correct? Thats because it doesnt seem to require it in a normal no-std build.

@stargazing-dino
Copy link
Author

Yeah, honestly no clue why it tripped up here. Once I get home I'll try again from scratch and see if anything changes. Might've been a temporary thing. I did make sure to update cargo/rust though and my dependencies to latest.

The once_cell thing came from #869 and I don't think it's actually needed. I removed it yesterday and it didn't have a hiccup but at one point it did fix a similar issue for me.

I am using an nrf52. Not really much code as it's all spaghetti nonsense right now but I could share with you a minimal example perhaps running on a microbit v2 later this week.

@schungx
Copy link
Collaborator

schungx commented Oct 25, 2024

The once_cell thing came from #869 and I don't think it's actually needed. I removed it yesterday and it didn't have a hiccup but at one point it did fix a similar issue for me.

Yeah, I remember there were some changes since then.

BTW, appreciate if you can dig out why it failed to compile on that particular line, because I can't seem to reproduce it.

@stargazing-dino
Copy link
Author

Tried it again with a clean compile and it went through no problem. No idea why this was erroring at first :\

Anyways, I'll close this as I don't think it's needed

@jeromegn
Copy link

jeromegn commented Nov 11, 2024

I'm compiling for the x86_64-unknown-none target and getting a similar issue with sync and no_std enabled when using a once_cell::sync::Lazy:

error[E0277]: the trait bound `RwLock<StringsInterner>: core::convert::From<StringsInterner>` is not satisfied
  --> /home/jerome/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rhai-1.20.0/src/api/mod.rs:66:68
   |
66 |             self.interned_strings = Some(StringsInterner::new(max).into());
   |                                                                    ^^^^ the trait `core::convert::From<StringsInterner>` is not implemented for `RwLock<StringsInterner>`
   |
   = note: required for `StringsInterner` to implement `core::convert::Into<RwLock<StringsInterner>>`

Unfortunately, cargo clean did not fix it :)

Maybe minimal repo:

#![no_std]

use once_cell::sync::Lazy;

static ENGINE: Lazy<rhai::Engine> = Lazy::new(rhai::Engine::new_raw);

fn main() {}
[dependencies]
once_cell = { version = "1.20.2", default-features = false, features = ["critical-section"] }
rhai = { version = "1.20.0", default-features = false, features = ["no_std", "sync"] }

[profile.release]
panic = "abort"
cargo build --target x86_64-unknown-none

I am running rustc 1.84.0-nightly (b91a3a056 2024-11-07)

@schungx
Copy link
Collaborator

schungx commented Nov 12, 2024

This is totally strange... I'm happy to just put in the fiz, but I fear we may be masking a deeper, more subtle bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants