Skip to content

Commit 1a64607

Browse files
committed
Fix minor issues
1 parent 0b72867 commit 1a64607

File tree

8 files changed

+43
-16
lines changed

8 files changed

+43
-16
lines changed

core/codegen/src/attribute/catch/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ pub fn _catch(
6161
::rocket::trace::error!(
6262
downcast_to = stringify!(#ty),
6363
error_name = #__error.name(),
64-
"Failed to downcast error. This should never happen, please open an issue with details."
64+
"Failed to downcast error. This should never happen, please \
65+
open an issue with details."
6566
);
6667
return #_Err(#Status::InternalServerError);
6768
},

core/codegen/src/attribute/route/mod.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ fn query_decls(route: &Route) -> Option<TokenStream> {
113113
"{_err}"
114114
); } }
115115
);
116+
::rocket::trace::info!(
117+
name: "forward",
118+
target: concat!("rocket::codegen::route::", module_path!()),
119+
error_name = #TypedError::name(&__e),
120+
"parameter guard forwarding"
121+
);
116122

117123
return #Outcome::Forward((
118124
#__data,
@@ -141,6 +147,7 @@ fn request_guard_decl(guard: &Guard) -> TokenStream {
141147
parameter = stringify!(#ident),
142148
type_name = stringify!(#ty),
143149
status = #TypedError::status(&__e).code,
150+
error_name = #TypedError::name(&__e),
144151
"request guard forwarding"
145152
);
146153

@@ -156,8 +163,8 @@ fn request_guard_decl(guard: &Guard) -> TokenStream {
156163
target: concat!("rocket::codegen::route::", module_path!()),
157164
parameter = stringify!(#ident),
158165
type_name = stringify!(#ty),
166+
status = #TypedError::status(&__c).code,
159167
error_name = #TypedError::name(&__c),
160-
// reason = %#display_hack!(__e),
161168
"request guard failed"
162169
);
163170

@@ -181,8 +188,7 @@ fn param_guard_decl(guard: &Guard) -> TokenStream {
181188
target: concat!("rocket::codegen::route::", module_path!()),
182189
parameter = #name,
183190
type_name = stringify!(#ty),
184-
name = #TypedError::name(&__error),
185-
// reason = %#display_hack!(__error),
191+
error_name = #TypedError::name(&__error),
186192
"path guard forwarding"
187193
);
188194

@@ -248,6 +254,7 @@ fn data_guard_decl(guard: &Guard) -> TokenStream {
248254
parameter = stringify!(#ident),
249255
type_name = stringify!(#ty),
250256
status = #TypedError::status(&__e).code,
257+
error_name = #TypedError::name(&__e),
251258
"data guard forwarding"
252259
);
253260

@@ -263,7 +270,7 @@ fn data_guard_decl(guard: &Guard) -> TokenStream {
263270
target: concat!("rocket::codegen::route::", module_path!()),
264271
parameter = stringify!(#ident),
265272
type_name = stringify!(#ty),
266-
// reason = %#display_hack!(__e),
273+
error_name = #TypedError::name(&__e),
267274
"data guard failed"
268275
);
269276

core/codegen/src/derive/typed_error.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@ pub fn derive_typed_error(input: proc_macro::TokenStream) -> TokenStream {
128128
})
129129
)
130130
.validator(ValidatorBuild::new()
131-
.input_validate(|_, i| match i.generics().lifetimes().count() > 1 {
132-
true => Err(i.generics().span().error("only one lifetime is supported")),
133-
false => Ok(())
131+
.input_validate(|_, i| if i.generics().lifetimes().count() > 1 {
132+
Err(i.generics().span().error("only one lifetime is supported"))
133+
} else if i.generics().const_params().count() > 0 {
134+
Err(i.generics().span().error("const params are not supported"))
135+
} else {
136+
Ok(())
134137
})
135138
)
136139
.inner_mapper(MapperBuild::new()
@@ -146,14 +149,14 @@ pub fn derive_typed_error(input: proc_macro::TokenStream) -> TokenStream {
146149
match g {
147150
syn::GenericParam::Lifetime(_) => quote!{ 'static },
148151
syn::GenericParam::Type(TypeParam { ident, .. }) => quote! { #ident },
149-
syn::GenericParam::Const(ConstParam { .. }) => todo!(),
152+
syn::GenericParam::Const(ConstParam { .. }) => unreachable!(),
150153
}
151154
});
152155
let trans = input.generics()
153156
.lifetimes()
154157
.map(|LifetimeParam { lifetime, .. }| quote!{#_catcher::Inv<#lifetime>});
155158
quote!{
156-
type Static = #name <#(#args)*>;
159+
type Static = #name <#(#args,)*>;
157160
type Transience = (#(#trans,)*);
158161
}
159162
})

core/codegen/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ pub fn derive_responder(input: TokenStream) -> TokenStream {
10351035
/// name: &'r str,
10361036
/// value: &'r str,
10371037
/// }
1038-
///
1038+
///
10391039
/// #[derive(TypedError)]
10401040
/// enum HeaderError {
10411041
/// InvalidValue,

core/codegen/tests/catcher.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@ fn test_basic_params() {
105105
#[catch(default, error = "<e>")]
106106
fn test_io_error(e: &io::Error) -> String { format!("{e:?}") }
107107
#[catch(default, error = "<_e>")]
108-
fn test_parse_int_error(_e: &ParseIntError) -> String { println!("ParseIntError"); format!("ParseIntError") }
108+
fn test_parse_int_error(_e: &ParseIntError) -> String { format!("ParseIntError") }
109109
#[catch(default, error = "<_e>")]
110110
fn test_parse_bool_error(_e: &ParseBoolError) -> String { format!("ParseBoolError") }
111111
#[catch(default, error = "<e>")]
112-
fn test_param_parse_bool_error(e: &FromParamError<'_, ParseBoolError>) -> String { format!("ParseBoolError: {}", e.raw) }
112+
fn test_param_parse_bool_error(e: &FromParamError<'_, ParseBoolError>) -> String {
113+
format!("ParseBoolError: {}", e.raw)
114+
}
113115

114116

115117
#[test]

core/codegen/tests/typed_error.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,14 @@ fn validate_static() {
6767
));
6868
boxed_error(Box::new(val));
6969
}
70+
71+
#[derive(TypedError)]
72+
pub enum Generic<E> {
73+
First(E),
74+
}
75+
76+
#[derive(TypedError)]
77+
pub struct GenericWithLifetime<'r, E> {
78+
s: &'r str,
79+
inner: E,
80+
}

core/lib/src/router/collider.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ impl Catcher {
141141
/// assert!(!a.collides_with(&b));
142142
/// ```
143143
pub fn collides_with(&self, other: &Self) -> bool {
144-
self.code == other.code && self.base().segments().eq(other.base().segments()) && self.type_id == other.type_id
144+
self.code == other.code
145+
&& self.base().segments().eq(other.base().segments())
146+
&& self.type_id == other.type_id
145147
}
146148
}
147149

core/lib/src/router/router.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ mod test {
593593
{
594594
let mut router = Router::new();
595595
for (status, base, ty) in catchers {
596-
let mut catcher = Catcher::new(status.map(|s| s.code), catcher::dummy_handler).rebase(Origin::parse(base).unwrap());
596+
let mut catcher = Catcher::new(status.map(|s| s.code), catcher::dummy_handler)
597+
.rebase(Origin::parse(base).unwrap());
597598
catcher.type_id = ty;
598599
router.catchers.push(catcher);
599600
}
@@ -646,7 +647,7 @@ mod test {
646647
let request = client.req(Method::Get, Origin::parse(uri).unwrap());
647648
router.catch_any(status, ty(&()), &request)
648649
}
649-
650+
650651
#[test]
651652
fn test_catch_vs_catch_any() {
652653
let router = make_router_catches([(None, "/", None)]).unwrap();

0 commit comments

Comments
 (0)