#1139·warp

Can't spawn with statically borrowed data anymore

Author: TheDan64Created Sep 25, 2025Updated Sep 25, 2025
Labelsbug

Version 0.4.2

Platform Linux, Ubuntu 22.04.1

Description Routes with borrowed data (even statically) can no longer be spawned into a new task.

The simplest example I can give is this:

rust
async fn test() {
    warp::serve(warp::path("hello").and(warp::get()).map(|| "Hello, World!"))
        .run(([0, 0, 0, 0], 1234))
        .await;
}

fn test2() {
    spawn(test());
}

You get two different, confusing, and ambiguous (which route is it??) errors (note, not from test fn, but from spawn!):

rust
error: implementation of `Reply` is not general enough
  --> src/endpoints.rs:87:5
   |
87 |     spawn(test());
   |     ^^^^^^^^^^^^^ implementation of `Reply` is not general enough
   |
   = note: `&'0 str` must implement `Reply`, for any lifetime `'0`...
   = note: ...but `Reply` is actually implemented for the type `&'static str`

error: implementation of `AsRef` is not general enough
  --> src/endpoints.rs:87:5
   |
87 |     spawn(test());
   |     ^^^^^^^^^^^^^ implementation of `AsRef` is not general enough
   |
   = note: `AsRef<str>` would have to be implemented for the type `&'0 str`, for any lifetime `'0`...
   = note: ...but `AsRef<str>` is actually implemented for the type `&'1 str`, for some specific lifetime `'1`

This use to work in warp 0.3 and I encountered it while upgrading to 0.4. The fix is to add .to_owned() to both strings ("hello", "Hello, World!").

I think what's most confusing is that the function that the warp::serve is in itself compiles fine, but the caller wrapping it in spawn gets this mysterious error that's very hard to debug. I'd also expect borrowed data to work, at minimum &'static references, but they do not? I'm using tokio with "full" feature for reference