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

Unqualified line! macro usage inside info! causes issues with ratatui_macros #3023

Closed
kdheepak opened this issue Jun 30, 2024 · 1 comment · Fixed by #3024
Closed

Unqualified line! macro usage inside info! causes issues with ratatui_macros #3023

kdheepak opened this issue Jun 30, 2024 · 1 comment · Fixed by #3024

Comments

@kdheepak
Copy link

Just importing ratatui_macros::line causes tracing::info to compile error:

use ratatui_macros::line;
use tracing::info;

fn main() {
    info!("Hello, world!");
}

Here's the error:

error: expected a literal
 --> src/main.rs:5:5
  |
5 |     info!("Hello, world!");
  |     ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: only literals (like `"foo"`, `-42` and `3.14`) can be passed to `concat!()`
  = note: this error originates in the macro `line` which comes from the expansion of the macro `info` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
   --> src/main.rs:5:5
    |
5   |     info!("Hello, world!");
    |     ^^^^^^^^^^^^^^^^^^^^^^
    |     |
    |     expected `u32`, found `Line<'_>`
    |     arguments to this enum variant are incorrect
    |

with this Cargo.toml

[package]
name = "test-ratatui-macros"
version = "0.1.0"
edition = "2021"

[dependencies]
log = "0.4.22"
ratatui = "0.27.0"
ratatui-macros = "0.4.2"
tracing = "0.1.40"

I get similar errors with other macros from tracing, but I don't get any errors with log::info! or other macros from log.

Here's the diff of cargo expand without and with use ratatui_macros::line;

--- without_ratatui_macros.txt  2024-06-30 00:19:44
+++ with_ratatui_macros.txt     2024-06-30 00:19:54
@@ -3,6 +3,7 @@
 use std::prelude::rust_2021::*;
 #[macro_use]
 extern crate std;
+use ratatui_macros::line;
 use tracing::info;
 fn main() {
     {
@@ -10,11 +11,11 @@
         static __CALLSITE: ::tracing::callsite::DefaultCallsite = {
             static META: ::tracing::Metadata<'static> = {
                 ::tracing_core::metadata::Metadata::new(
-                    "event src/main.rs:5",
+                    (/*ERROR*/),
                     "test_ratatui_macros",
                     ::tracing::Level::INFO,
                     ::core::option::Option::Some("src/main.rs"),
-                    ::core::option::Option::Some(5u32),
+                    ::core::option::Option::Some(::ratatui::text::Line::default()),
                     ::core::option::Option::Some("test_ratatui_macros"),
                     ::tracing_core::field::FieldSet::new(
                         &["message"],

tracing seems to be adding a line like this ::core::option::Option::Some(::ratatui::text::Line::default()), when use ratatui_macros::line is in the file.

The issue stems from unqualified usages of line! like these:

line!()

Making them std::line!() should resolve this issue.

Thanks to @joshka for helping figure out the issue.

@joshka
Copy link
Contributor

joshka commented Jun 30, 2024

It's also a problem in the metadata! macro in tracing-core.

joshka added a commit to joshka/tracing that referenced this issue Jun 30, 2024
This commit fixes a bug where a macro call to macros defined in the
standard lib from the `tracing` and `tracing-core` crates could be
resolved to a local macro with the same name, causing a compilation
error. This commit prefixes these calls with `::core::` to ensure that
they are resolved to the standard library macros.

Fixes: <tokio-rs#3023>
davidbarsky pushed a commit that referenced this issue Jul 24, 2024
…os (#3024)

fix: prefix macro calls with `__macro_support ` to avoid clashes with local macros

Fixes: <#3023>

This ensures that the tracing lib correctly builds when a crate is named
`core`. See #2761 and
#2762 for more info.
hds pushed a commit that referenced this issue Nov 22, 2024
…os (#3024)

fix: prefix macro calls with `__macro_support ` to avoid clashes with local macros

Fixes: <#3023>

This ensures that the tracing lib correctly builds when a crate is named
`core`. See #2761 and
#2762 for more info.
hds pushed a commit that referenced this issue Nov 22, 2024
…os (#3024)

fix: prefix macro calls with `__macro_support ` to avoid clashes with local macros

Fixes: <#3023>

This ensures that the tracing lib correctly builds when a crate is named
`core`. See #2761 and
#2762 for more info.
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 a pull request may close this issue.

2 participants