Skip to content

Derive TypedPath not work when OptionalFromRequestParts in scope #3644

@azureqaq

Description

@azureqaq
  • I have looked for existing issues (including closed) about this

Bug Report

Version

  • rustc 1.93.0 (254b59607 2026-01-19)
  • axum v0.8.8
  • axum-extra v0.12.5
  • axum-macros v0.5.0 (proc-macro)

Platform

macOS arm64 26.2 Apple M1

Crates

  • axum-extra v0.12.5

Description

Importing OptionalFromRequestParts while using #[derive(TypedPath, Deserialize)] will cause a compilation error.

I tried this code:

use axum::extract::OptionalFromRequestParts; // If you comment out this line, it will compile normally.
use axum_extra::routing::TypedPath;
use serde::Deserialize;

#[derive(Debug, Deserialize, TypedPath)]
#[typed_path("/mypath/{inner}")]
pub struct MyPath {
    inner: String,
}

Error message:

error[E0034]: multiple applicable items in scope
 --> src/lib.rs:5:30
  |
5 | #[derive(Debug, Deserialize, TypedPath)]
  |                              ^^^^^^^^^ multiple `from_request_parts` found
  |
  = note: candidate #1 is defined in an impl of the trait `FromRequestParts` for the type `axum::extract::Path<T>`
  = note: candidate #2 is defined in an impl of the trait `OptionalFromRequestParts` for the type `axum::extract::Path<T>`
  = note: this error originates in the derive macro `TypedPath` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0282]: type annotations needed
 --> src/lib.rs:5:30
  |
5 | #[derive(Debug, Deserialize, TypedPath)]
  |                              ^^^^^^^^^ cannot infer type
  |
  = note: this error originates in the derive macro `TypedPath` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0034, E0282.
For more information about an error, try `rustc --explain E0034`.
error: could not compile `ttt` (lib) due to 2 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions