Improve extern fn with body error message
diff --git a/syntax/parse.rs b/syntax/parse.rs
index d053bb3..fbb24e2 100644
--- a/syntax/parse.rs
+++ b/syntax/parse.rs
@@ -16,9 +16,9 @@
use syn::{
Abi, Attribute, Error, Expr, Fields, FnArg, ForeignItem, ForeignItemFn, ForeignItemType,
GenericArgument, GenericParam, Generics, Ident, ItemEnum, ItemImpl, ItemStruct, Lit, LitStr,
- Pat, PathArguments, Result, ReturnType, Token, TraitBound, TraitBoundModifier,
- Type as RustType, TypeArray, TypeBareFn, TypeParamBound, TypePath, TypeReference,
- Variant as RustVariant, Visibility,
+ Pat, PathArguments, Result, ReturnType, Signature as RustSignature, Token, TraitBound,
+ TraitBoundModifier, Type as RustType, TypeArray, TypeBareFn, TypeParamBound, TypePath,
+ TypeReference, Variant as RustVariant, Visibility,
};
pub mod kw {
@@ -664,9 +664,14 @@
let visibility: Visibility = input.parse()?;
if input.peek(Token![type]) {
parse_extern_verbatim_type(cx, attrs, visibility, input, lang, trusted, namespace)
+ } else if input.peek(Token![fn]) {
+ parse_extern_verbatim_fn(input)
} else {
let span = input.cursor().token_stream();
- Err(Error::new_spanned(span, "unsupported foreign item"))
+ Err(Error::new_spanned(
+ span,
+ "unsupported foreign item, expected `type` or `fn`",
+ ))
}
}
.parse2(tokens)
@@ -737,6 +742,12 @@
}
}
+fn parse_extern_verbatim_fn(input: ParseStream) -> Result<Api> {
+ input.parse::<RustSignature>()?;
+ input.parse::<Token![;]>()?;
+ unreachable!()
+}
+
fn parse_type_alias(
cx: &mut Errors,
attrs: Vec<Attribute>,