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

Route codegen error includes literal escape codes #2901

Open
4 tasks done
robjwells opened this issue Jan 13, 2025 · 1 comment
Open
4 tasks done

Route codegen error includes literal escape codes #2901

robjwells opened this issue Jan 13, 2025 · 1 comment
Labels
upstream An unresolvable issue: an upstream dependency bug

Comments

@robjwells
Copy link

Rocket Version

0.5.1

Operating System

macOS 12.7.6

Rust Toolchain Version

rustc 1.84.0 (9fc6b4312 2025-01-07)

What happened?

When encountering an (expected) error in route codegen with a mismatched path variable and function argument, the compiler error mesage includes terminal color escape codes as literal text, making the error message difficult to read.

Test Case

use rocket::{get, routes};

#[get("/hello/<name>")]
fn hello(other: &str) -> String {
    format!("Hello, {other}!")
}

#[rocket::launch]
fn rocket() -> rocket::Rocket<rocket::Build> {
    rocket::build().mount("/", routes![hello])
}

Log Output

❯ ROCKET_LOG_LEVEL=debug cargo build
   Compiling rocketroutetest v0.1.0 (/Users/robjwells/Desktop/rocketroutetest)
error: unused parameter
 --> src/main.rs:3:7
  |
3 | #[get("/hello/<name>")]
  |       ^^^^^^^^^^^^^^^

error: ␛[1;34m[␛[0m␛[1;32mnote␛[0m␛[1;34m] ␛[0m␛[1;39mexpected argument named `name` here␛[0m
 --> src/main.rs:4:9
  |
4 | fn hello(other: &str) -> String {
  |         ^^^^^^^^^^^^^

error[E0422]: cannot find struct, variant or union type `hello` in this scope
  --> src/main.rs:10:40
   |
10 |     rocket::build().mount("/", routes![hello])
   |                                        ^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0422`.
error: could not compile `rocketroutetest` (bin "rocketroutetest") due to 3 previous errors

Additional Context

The source of the message is here:

let msg = format!("expected argument named `{}` here", param.name);
let diag = param.span().error("unused parameter").span_note(args.span, msg);

This isn't affected by ROCKET_CLI_COLORS. There is no rocket.toml in the project. I don't have RUST_LOG or anything similar set in my shell env.

System Checks

  • My bug report relates to functionality.
  • I have tested against the latest Rocket release or a recent git commit.
  • I have tested against the latest stable rustc toolchain.
  • I was unable to find this issue previously reported.
@robjwells robjwells added the triage A bug report being investigated label Jan 13, 2025
@the10thWiz the10thWiz added bug Deviation from the specification or expected behavior deficiency Something doesn't work as well as it could upstream An unresolvable issue: an upstream dependency bug and removed triage A bug report being investigated bug Deviation from the specification or expected behavior deficiency Something doesn't work as well as it could labels Jan 20, 2025
@the10thWiz
Copy link
Collaborator

This looks like a fairly straight forward issue with proc-macro2-diagnostics. It's using yansi internally (outside of rocket) to add color the compile timeout output.

This appears to be related to the compiler version, since running on nightly solves this issue. I've reported this issue upstream (SergioBenitez/proc-macro2-diagnostics#11).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream An unresolvable issue: an upstream dependency bug
Projects
None yet
Development

No branches or pull requests

2 participants