Fix span placement on type aliases

This commit is contained in:
David Tolnay 2020-12-30 17:31:19 -08:00
parent 524ff68081
commit 291c9350d6
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
4 changed files with 20 additions and 8 deletions

View File

@ -1019,13 +1019,18 @@ fn expand_rust_function_shim_super(
fn expand_type_alias(alias: &TypeAlias) -> TokenStream {
let doc = &alias.doc;
let attrs = &alias.attrs;
let visibility = alias.visibility;
let type_token = alias.type_token;
let ident = &alias.name.rust;
let generics = &alias.generics;
let eq_token = alias.eq_token;
let ty = &alias.ty;
let semi_token = alias.semi_token;
quote! {
#doc
#attrs
pub type #ident #generics = #ty;
#visibility #type_token #ident #generics #eq_token #ty #semi_token
}
}

View File

@ -123,6 +123,7 @@ pub struct TypeAlias {
pub doc: Doc,
pub derives: Vec<Derive>,
pub attrs: OtherAttrs,
pub visibility: Token![pub],
pub type_token: Token![type],
pub name: Pair,
pub generics: Lifetimes,

View File

@ -688,7 +688,7 @@ fn parse_extern_verbatim(
if lookahead.peek(Token![=]) {
// type Alias = crate::path::to::Type;
parse_type_alias(
cx, attrs, type_token, ident, lifetimes, input, lang, namespace,
cx, attrs, visibility, type_token, ident, lifetimes, input, lang, namespace,
)
} else if lookahead.peek(Token![:]) || lookahead.peek(Token![;]) {
// type Opaque: Bound2 + Bound2;
@ -706,6 +706,7 @@ fn parse_extern_verbatim(
fn parse_type_alias(
cx: &mut Errors,
attrs: Vec<Attribute>,
visibility: Visibility,
type_token: Token![type],
ident: Ident,
generics: Lifetimes,
@ -741,12 +742,19 @@ fn parse_type_alias(
return Err(Error::new_spanned(span, msg));
}
let visibility = Token![pub](match visibility {
Visibility::Public(vis) => vis.pub_token.span,
Visibility::Crate(vis) => vis.crate_token.span,
Visibility::Restricted(vis) => vis.pub_token.span,
Visibility::Inherited => ident.span(),
});
let name = pair(namespace, &ident, cxx_name, rust_name);
Ok(Api::TypeAlias(TypeAlias {
doc,
derives,
attrs,
visibility,
type_token,
name,
generics,

View File

@ -35,12 +35,10 @@ error: missing documentation for a struct
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a type alias
--> $DIR/deny_missing_docs.rs:9:1
|
9 | #[cxx::bridge]
| ^^^^^^^^^^^^^^
|
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
--> $DIR/deny_missing_docs.rs:49:9
|
49 | pub type UndocumentedTypeAlias = crate::bindgen::UndocumentedTypeAlias;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
--> $DIR/deny_missing_docs.rs:9:1