Cannot compile simple tokio example

This very simply code example doesn't build:

Cargo.toml

[package]
name = "tokio_example"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1.37.0", features=["full"] }

main.rs

#![feature(proc_macro_byte_character)]
#![feature(proc_macro_c_str_literals)]
fn main() {
    println!("Hello, world!");
}

Error:

error[E0658]: use of unstable library feature 'proc_macro_byte_character'
--> /home/user/.cargo/registry/src/proc-macro2-1.0.80/src/wrapper.rs:871:21
|
871 | proc_macro::Literal::byte_character(byte)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #115268 https://github.com/rust-lang/rust/issues/115268 for more information
= help: add #![feature(proc_macro_byte_character)] to the crate attributes to enable
= note: this compiler was built on 2024-03-19; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature 'proc_macro_c_str_literals'
--> /home/user/.cargo/registry/src/proc-macro2-1.0.80/src/wrapper.rs:898:21
|
898 | proc_macro::Literal::c_string(string)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #119750 https://github.com/rust-lang/rust/issues/119750 for more information
= help: add #![feature(proc_macro_c_str_literals)] to the crate attributes to enable
= note: this compiler was built on 2024-03-19; consider upgrading it if it is out of date

Any help appreciated.

Why are these in your main.rs file?

Which version of the compiler are you using?

nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.79.0-nightly (a7e4de13c 2024-03-19)

Those #![...] are there because the info below error suggested to add them

Try using stable Rust (or a different nightly).

The error is from the proc-macro2 crate, not your code, so adding them to your main.rs has no effect. Remove them.

It's because of this recent change in proc-macro2. It looks at the compiler version to detect whether the two features you mentioned are stabilized yet. It's check looks like this:

if rustc < 79 {
    println!("cargo:rustc-cfg=no_literal_byte_character");
}

They were stabilized in 1.79, so this check would normally work. However, you are using a nightly release which is:

  1. From before the feature was stabilized.
  2. But still has version number 1.79 because it is a nightly created between 1.78 and 1.79.

So proc-macro2 thinks the feature has been stabilized, but the compiler thinks it hasn't. This causes the error. The check works on all stable versions of Rust, but is broken on your specific nightly release. To fix it, use a different compiler version.

1 Like

Thank you for your help. Funny enough it worked this morning with nightly :slight_smile:

Set its version to 1.0.79 in Cargo.toml can also solve it, if the rustc version is not upgradable in some cases.

[dependencies]
# TODO: Delete this after rustc upgraded.
proc-macro2 = "=1.0.79"

Thanks, good to know

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.