Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move span of inherited pub to next consecutive token #710

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions syntax/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn parse_struct(cx: &mut Errors, mut item: ItemStruct, namespace: &Namespace) ->
continue;
}
};
let visibility = visibility_pub(&field.vis, &ident);
let visibility = visibility_pub(&field.vis, ident.span());
let name = pair(Namespace::default(), &ident, cxx_name, rust_name);
fields.push(Var {
doc,
Expand All @@ -155,8 +155,8 @@ fn parse_struct(cx: &mut Errors, mut item: ItemStruct, namespace: &Namespace) ->
});
}

let visibility = visibility_pub(&item.vis, &item.ident);
let struct_token = item.struct_token;
let visibility = visibility_pub(&item.vis, struct_token.span);
let name = pair(namespace, &item.ident, cxx_name, rust_name);
let generics = Lifetimes {
lt_token: item.generics.lt_token,
Expand Down Expand Up @@ -219,8 +219,8 @@ fn parse_enum(cx: &mut Errors, item: ItemEnum, namespace: &Namespace) -> Api {
}
}

let visibility = visibility_pub(&item.vis, &item.ident);
let enum_token = item.enum_token;
let visibility = visibility_pub(&item.vis, enum_token.span);
let brace_token = item.brace_token;

let explicit_repr = repr.is_some();
Expand Down Expand Up @@ -452,8 +452,8 @@ fn parse_extern_type(
},
);

let visibility = visibility_pub(&foreign_type.vis, &foreign_type.ident);
let type_token = foreign_type.type_token;
let visibility = visibility_pub(&foreign_type.vis, type_token.span);
let name = pair(namespace, &foreign_type.ident, cxx_name, rust_name);
let generics = Lifetimes {
lt_token: None,
Expand Down Expand Up @@ -619,9 +619,10 @@ fn parse_extern_fn(
let mut throws_tokens = None;
let ret = parse_return_type(&foreign_fn.sig.output, &mut throws_tokens)?;
let throws = throws_tokens.is_some();
let visibility = visibility_pub(&foreign_fn.vis, &foreign_fn.sig.ident);
let unsafety = foreign_fn.sig.unsafety;
let fn_token = foreign_fn.sig.fn_token;
let inherited_span = unsafety.map_or(fn_token.span, |unsafety| unsafety.span);
let visibility = visibility_pub(&foreign_fn.vis, inherited_span);
let name = pair(namespace, &foreign_fn.sig.ident, cxx_name, rust_name);
let generics = generics.clone();
let paren_token = foreign_fn.sig.paren_token;
Expand Down Expand Up @@ -787,7 +788,7 @@ fn parse_type_alias(
return Err(Error::new_spanned(span, msg));
}

let visibility = visibility_pub(&visibility, &ident);
let visibility = visibility_pub(&visibility, type_token.span);
let name = pair(namespace, &ident, cxx_name, rust_name);

Ok(Api::TypeAlias(TypeAlias {
Expand Down Expand Up @@ -867,7 +868,7 @@ fn parse_extern_type_bounded(
},
);

let visibility = visibility_pub(&visibility, &ident);
let visibility = visibility_pub(&visibility, type_token.span);
let name = pair(namespace, &ident, cxx_name, rust_name);

Ok(match lang {
Expand Down Expand Up @@ -1326,12 +1327,12 @@ fn parse_return_type(
}
}

fn visibility_pub(vis: &Visibility, inherited: &Ident) -> Token![pub] {
fn visibility_pub(vis: &Visibility, inherited: Span) -> Token![pub] {
Token![pub](match vis {
Visibility::Public(vis) => vis.pub_token.span,
Visibility::Crate(vis) => vis.crate_token.span,
Visibility::Restricted(vis) => vis.pub_token.span,
Visibility::Inherited => inherited.span(),
Visibility::Inherited => inherited,
})
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/enum_match_without_wildcard.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0004]: non-exhaustive patterns: `A { repr: 2_u8..=u8::MAX }` not covered
--> $DIR/enum_match_without_wildcard.rs:12:11
|
3 | enum A {
| - `ffi::A` defined here
| ------ `ffi::A` defined here
...
12 | match a {
| ^ pattern `A { repr: 2_u8..=u8::MAX }` not covered
Expand Down