Skip to content

Commit

Permalink
fix: use full macro path (#2028)
Browse files Browse the repository at this point in the history
When the `#[sqlx::test]` macro is imported using `#[macro_use]` such as
in the following example:

```rust
extern crate sqlx;

mod tests {
    #[test]
    fn something() {}
}
```

then the `#[test]` generated by the macro will refer to itself instead
of the standard Rust `#[test]` macro. This will cause `rustc` to
recursively expand it and produce the following error message:

```
thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
```

Instead, we can just refer to the standard macro by using its fully
qualified path.

This PR:
* Swaps `#[test]` usages in `#[sqlx::test]` for their hygenic path to
  prevent recursive expansion alongside `#[macro_use]`

Closes #2017.
  • Loading branch information
alexander-jackson authored Aug 10, 2022
1 parent c4f1816 commit 373b121
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sqlx-macros/src/test_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn expand_simple(input: syn::ItemFn) -> TokenStream {
let attrs = &input.attrs;

quote! {
#[test]
#[::core::prelude::v1::test]
#(#attrs)*
fn #name() #ret {
::sqlx::test_block_on(async { #body })
Expand Down Expand Up @@ -105,7 +105,7 @@ fn expand_advanced(args: syn::AttributeArgs, input: syn::ItemFn) -> crate::Resul
};

Ok(quote! {
#[test]
#[::core::prelude::v1::test]
#(#attrs)*
fn #name() #ret {
async fn inner(#inputs) #ret {
Expand Down

0 comments on commit 373b121

Please sign in to comment.