Skip to content

Conversation

@JOT85
Copy link

@JOT85 JOT85 commented Mar 12, 2025

Previously, identifiers such as __req were output with inconsistent spans. For example, in query_decls, it was defined with Span::call_site(), but in request_guard_decl as guard.ty.span(). The problem is, when used with macros, these spans can be different and cause the identifiers to fail to resolve.

A simple failure example is:

macro_rules! empty_get {
    ($name:ident) => {
        #[get("/")]
        async fn $name() {}
    }
}

empty_get!(test);

In this case, the inconsistency arises because:

  • In codegen_route, no span for __req is specified, which I believe means it defaults to Span::call_site(), so inside macro_rules!, then
  • in responder_outcome_expr, the span used is from the identifier of the function, which is outside of macro_rules!.

This causes the __req in responder_outcome not to resolve to the __req defined in the monomorphized_function arguments.

The span is now always Span::call_site(), which resolves these issues.

I believe call_site is acceptable, since it was already used as the span for these variables elsewhere. In addition, I didn't spot anywhere in the code where this could cause a problem.

JOT85 and others added 2 commits March 12, 2025 23:44
Previously, identifiers such as `__req` were output with inconsistent
spans. For example, in
[`query_decls`](https://github.com/rwf2/Rocket/blob/28891e8072136f4641a33fb8c3f2aafce9d88d5b/core/codegen/src/attribute/route/mod.rs#L43),
it was defined with `Span::call_site()`, but in
[`request_guard_decl`](https://github.com/rwf2/Rocket/blob/28891e8072136f4641a33fb8c3f2aafce9d88d5b/core/codegen/src/attribute/route/mod.rs#L127)
as `guard.ty.span()`. The problem is, when used with macros, these spans
can be different and cause the identifiers to fail to resolve.

A simple failure example is:

```rust
macro_rules! empty_get {
    ($name:ident) => {
        #[get("/")]
        async fn $name() {}
    }
}

empty_get!(test);
```

In this case, the inconsistency arises because:

- In
  [`codegen_route`](https://github.com/rwf2/Rocket/blob/28891e8072136f4641a33fb8c3f2aafce9d88d5b/core/codegen/src/attribute/route/mod.rs#L380),
  no span for `__req` is specified, which I believe means it defaults to
  `Span::call_site()`, so inside `macro_rules!`, then
- in
  [`responder_outcome_expr`](https://github.com/rwf2/Rocket/blob/28891e8072136f4641a33fb8c3f2aafce9d88d5b/core/codegen/src/attribute/route/mod.rs#L299),
  the span used is from the identifier of the function, which is outside
  of `macro_rules!`.

This causes the `__req` in `responder_outcome` not to resolve to the
`__req` defined in the `monomorphized_function` arguments.

The span is now always `Span::call_site()`, which resolves these issues.

I believe `call_site` is acceptable, since it was already used as the
span for these variables elsewhere. In addition, I didn't spot anywhere
in the code where this could cause a problem.
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 this pull request may close these issues.

1 participant