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

expected _, found () in format_args macro #15309

Closed
y21 opened this issue Jul 19, 2023 · 1 comment
Closed

expected _, found () in format_args macro #15309

y21 opened this issue Jul 19, 2023 · 1 comment
Labels
A-macro macro expansion A-nameres name, path and module resolution C-bug Category: bug

Comments

@y21
Copy link
Member

y21 commented Jul 19, 2023

This code:

fn main() {
  format_args!(
      "{}",
      match "" {
          "" => 1,
          _ => panic!(""),
      },
  );
}

has r-a report the error "expected i32, found ()" (the i32 is the type in the match arm, changing the arm to e.g. "" changes the error to "expected &str, found ()"):

image

But it compiles just fine.

Possibly a duplicate of #15082? I don't know what that issue implies

rust-analyzer version: rust-analyzer version: 0.3.1591-standalone

rustc version: rustc 1.73.0-nightly (da6b55cc5 2023-07-17)

relevant settings: nothing particularly worthy of mention I think

@y21 y21 added the C-bug Category: bug label Jul 19, 2023
@lowr lowr added A-macro macro expansion A-nameres name, path and module resolution labels Jul 19, 2023
@lowr
Copy link
Contributor

lowr commented Jul 19, 2023

This is a consequence of #15248. The gist of the problem is explained by this comment. Basically, panic! expands to $crate::panicking::panic_fmt() but we're now unable to resolve $crate, because our name resolver (or anything but eager expander) cannot see that the $crate originates from the panic! macro.

An obvious workaround is not to use any macro inside format_args! or any other macros that use it internally (e.g. println!). I'm thinking of introducing a hack so that the users won't need to deal with this themselves, but it may take a while (or forever -- it's fairly hard to get eager expansions right under our incremental architecture). Sorry for the inconvenience.

@Veykril Veykril closed this as completed Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion A-nameres name, path and module resolution C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants