Skip to content

Unhelpful help text E0435 for error hidden in macro #100235

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
algesten opened this issue Aug 7, 2022 · 2 comments
Open

Unhelpful help text E0435 for error hidden in macro #100235

algesten opened this issue Aug 7, 2022 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@algesten
Copy link
Contributor

algesten commented Aug 7, 2022

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=dadc51025c06cf1f6d7dd68f793bb2c0

use tracing::{info_span, Span};

pub struct Blah {
    pub span: Span,
}

impl Blah {
    pub fn new(name: &str) -> Self {
        Blah {
            span: info_span!(name),
        }
    }
}

The current output is:

error[E0435]: attempt to use a non-constant value in a constant
  --> ice/tests/blah.rs:10:30
   |
10 |             span: info_span!(name),
   |                   -----------^^^^-
   |                   |          |
   |                   |          non-constant value
   |                   help: consider using `let` instead of `static`: `let CALLSITE`

For more information about this error, try `rustc --explain E0435`

The help text is in this case not very helpful, potentially leading a user to try solutions that won't work. In this specific case, it would maybe be better to omit the help: section. Or, if possible maybe something like help: This error happens inside the info_span macro, which might indicate you are using the macro in a way it wasn't intended to be used.

@algesten algesten added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 7, 2022
@chenyukang
Copy link
Member

@rustbot claim

@chenyukang
Copy link
Member

chenyukang commented Aug 9, 2022

I found another issue when trying to reproduce the issue, why the comment line // This is a comment !!!! is moved to another place after macro is expand?

fn main() {
    println!("hello world");    
}

// This is a comment !!!!

Run cargo with command cargo rustc -- -Zunpretty=expanded, the result is:

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;

fn main() {

    // This is a comment !!!!
    {
        ::std::io::_print(::core::fmt::Arguments::new_v1(&["hello world\n"],
                &[]));
    };
}

Interesting... there is maybe another issue.

About the unhelpful text, it's generated because macro is expanded before parser, @gimbles do you know how we know a span wheter is from macro? Seems it's a general issue for using macro in code, if we don't store whether the tokens is generated from macro.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants