mirror of
https://github.com/OMGeeky/tarpc.git
synced 2025-12-30 16:18:56 +01:00
Add nice error message for ident collisions
This commit is contained in:
@@ -46,10 +46,24 @@ impl Parse for Service {
|
||||
let ident = input.parse()?;
|
||||
let content;
|
||||
braced!(content in input);
|
||||
let mut rpcs = Vec::new();
|
||||
let mut rpcs = Vec::<RpcMethod>::new();
|
||||
while !content.is_empty() {
|
||||
rpcs.push(content.parse()?);
|
||||
}
|
||||
for rpc in &rpcs {
|
||||
if rpc.ident == "new" {
|
||||
return Err(syn::Error::new(
|
||||
rpc.ident.span(),
|
||||
format!("method name conflicts with generated fn `{}Client::new`", ident)
|
||||
))
|
||||
}
|
||||
if rpc.ident == "serve" {
|
||||
return Err(syn::Error::new(
|
||||
rpc.ident.span(),
|
||||
format!("method name conflicts with generated fn `{}::serve`", ident)
|
||||
))
|
||||
}
|
||||
}
|
||||
Ok(Service {
|
||||
attrs,
|
||||
vis,
|
||||
@@ -83,19 +97,19 @@ impl Parse for RpcMethod {
|
||||
FnArg::SelfRef(self_ref) => {
|
||||
return Err(syn::Error::new(
|
||||
self_ref.span(),
|
||||
"RPC args cannot start with self",
|
||||
"method args cannot start with self",
|
||||
))
|
||||
}
|
||||
FnArg::SelfValue(self_val) => {
|
||||
return Err(syn::Error::new(
|
||||
self_val.span(),
|
||||
"RPC args cannot start with self",
|
||||
"method args cannot start with self",
|
||||
))
|
||||
}
|
||||
arg => {
|
||||
return Err(syn::Error::new(
|
||||
arg.span(),
|
||||
"RPC args must be explicitly typed patterns",
|
||||
"method args must be explicitly typed patterns",
|
||||
))
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user