mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-09 00:00:12 +02:00
Improve the error message for state type inference failure in FromRequest(Parts) derive macro (#1432)
* Add a dedicated error message for state type inference issues * Generate valid code even if state type can't be inferred * Also error on state type inference for debug_handler
This commit is contained in:
+4
-12
@@ -43,8 +43,6 @@
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![cfg_attr(test, allow(clippy::float_cmp))]
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::{quote, ToTokens};
|
||||
use syn::{parse::Parse, Type};
|
||||
@@ -615,11 +613,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn infer_state_type<'a, I>(types: I) -> Option<Type>
|
||||
fn infer_state_types<'a, I>(types: I) -> impl Iterator<Item = Type> + 'a
|
||||
where
|
||||
I: Iterator<Item = &'a Type>,
|
||||
I: Iterator<Item = &'a Type> + 'a,
|
||||
{
|
||||
let state_inputs = types
|
||||
types
|
||||
.filter_map(|ty| {
|
||||
if let Type::Path(path) = ty {
|
||||
Some(&path.path)
|
||||
@@ -650,13 +648,7 @@ where
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<HashSet<_>>();
|
||||
|
||||
if state_inputs.len() == 1 {
|
||||
state_inputs.iter().next().map(|&ty| ty.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
.cloned()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user