Improving Pair construction.

This commit is contained in:
Adrian Taylor 2020-10-29 21:31:56 -07:00
parent 0447e96b84
commit 0f8ab22aee
2 changed files with 16 additions and 7 deletions

View File

@ -300,14 +300,22 @@ impl Borrow<Type> for &Impl {
impl Pair {
/// Use this constructor when the item can't have a different
/// name in Rust and C++. For cases where #[rust_name] and similar
/// attributes can be used, construct the object by hand.
/// name in Rust and C++.
pub fn new(ns: Namespace, ident: Ident) -> Self {
Self {
rust: ident.clone(),
cxx: CppName::new(ns, ident),
}
}
/// Use this constructor when attributes such as #[rust_name]
/// can be used to potentially give a different name in Rust vs C++.
pub fn new_from_differing_names(ns: Namespace, cxx_ident: Ident, rust_ident: Ident) -> Self {
Self {
rust: rust_ident,
cxx: CppName::new(ns, cxx_ident),
}
}
}
impl ResolvableName {

View File

@ -3,7 +3,7 @@ use crate::syntax::file::{Item, ItemForeignMod};
use crate::syntax::report::Errors;
use crate::syntax::Atom::*;
use crate::syntax::{
attrs, error, Api, CppName, Doc, Enum, ExternFn, ExternType, Impl, Include, IncludeKind, Lang,
attrs, error, Api, Doc, Enum, ExternFn, ExternType, Impl, Include, IncludeKind, Lang,
Namespace, Pair, Receiver, Ref, ResolvableName, Signature, Slice, Struct, Ty1, Type, TypeAlias,
Var, Variant,
};
@ -398,10 +398,11 @@ fn parse_extern_fn(
let throws = throws_tokens.is_some();
let unsafety = foreign_fn.sig.unsafety;
let fn_token = foreign_fn.sig.fn_token;
let ident = Pair {
cxx: CppName::new(ns, cxx_name.unwrap_or(foreign_fn.sig.ident.clone())),
rust: rust_name.unwrap_or(foreign_fn.sig.ident.clone()),
};
let ident = Pair::new_from_differing_names(
ns,
cxx_name.unwrap_or(foreign_fn.sig.ident.clone()),
rust_name.unwrap_or(foreign_fn.sig.ident.clone()),
);
let paren_token = foreign_fn.sig.paren_token;
let semi_token = foreign_fn.semi_token;
let api_function = match lang {