tower-rs / tower

async fn(Request) -> Result<Response, Error>
https://docs.rs/tower
MIT License
3.49k stars 276 forks source link

error[E0015]: cannot call non-const fn `Identity::new` in constant functions #784

Closed RemiBardon closed 1 month ago

RemiBardon commented 1 month ago

I just added tower to my project, so I naturally chose version v0.5.0 (just-released). Unfortunately it doesn't build:

   Compiling tower v0.5.0
error[E0015]: cannot call non-const fn `Identity::new` in constant functions
   --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tower-0.5.0/src/builder/mod.rs:120:20
    |
120 |             layer: Identity::new(),
    |                    ^^^^^^^^^^^^^^^
    |
    = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

v0.4.13 builds successfully so I switched to it for the time being.

I'm running:

rustup 1.27.1 (54dd3d00f 2024-04-24)
rustc 1.82.0-nightly (91376f416 2024-08-12)
seanmonstar commented 1 month ago

I see that tower-layer also released a new version making that function const. So you'd need to make sure to cargo update both tower and tower-layer to get them.

Within tower, we could bump the minimal version to make sure it's always picked up...

RemiBardon commented 1 month ago

Ok so I added the two dependencies at the worse timing then 😅 I added tower-http a few hours ago, before tower v0.5.0 was released

RemiBardon commented 1 month ago

That was it, sorry for bothering

agourlay commented 1 month ago

Ran into the same issue, decided to implement the proper fix in https://github.com/tower-rs/tower/pull/787

praseodym commented 1 month ago

We hit this issue too with a Dependabot upgrade from Tower 0.4.13 to 0.5.0. Maybe a 0.5.1 release with the fix from #787 could prevent more people from running into this?