Numeric fields in struct expressions are unstable

#1

I am using rust version rustc 1.17.0-nightly. The unstable numeric fields was solved in rust 1.19. updating is not an option. the flatbuffer version is also the oldest. I am thinking about modifying the code in follow.rs and other libraries. How can i revert it to older version as in how do i make it stable?

error: numeric fields in struct expressions are unstable (see issue #35626)
–> flatbuffers/rust/flatbuffers/src/follow.rs:49:16
|
49 | Self { 0: PhantomData }

0 Likes

#2

You have to add #![feature(…name of the unstable feature…)] to the crate that uses this feature.

You can clone flatbuffers and then use flatbuffers = { path = "../path-to-your-copy" } as the dependency, or use [patch] section if your cargo is new enough to support it.

BUT I strongly recommend finding a way to update Rust instead. The ecosystem doesn’t support old versions of Rust, especially as old as yours. If you can’t update the compiler on some system, even try cross-compiling from another computer.

0 Likes

#3

Yes you are very right. It is a major pain. I added this feature to root crate as well as the libraries that use this feature. I also added the flatbuffers as path. Still the error persists which tells me that the #feature is not added in the right file.

Can you plx help?

0 Likes

#4

When Cargo builds dependencies, it displays their paths. If it displays flatbuffers with just a version, not a local file path, it means the replacement didn’t work and some other crate is pulling an unwanted version.

Note that feature has to use the attribute syntax with #!, and has to be at the top of lib.rs of the flatbuffers crate (not crates that use flatbuffers).

0 Likes

#5

Thank you this works !

0 Likes

#6

@kornel, Can you tell me how do i make sure that a feature is successfully added. The reason i am asking is that while creating new small applications and using it in my bigger integrated applications, i add the features in the main.rs in the small applications. However, the feature enabling error still persists. Should i use these small applications as libraries and add lib.rs in their source? I tried that and it still doesnot work.

0 Likes

#7

Unstable feature flags don’t apply globally to projects/applications. They are totally different and unrelated to Cargo features.

It has to be individually enabled in for every crate that directly uses the feature in its own source code.

Feature flags don’t need to be enabled in your crate when you just use a crate with an unstable feature.

0 Likes