Improving Pair construction.
diff --git a/syntax/impls.rs b/syntax/impls.rs
index 92c804a..f4c5b05 100644
--- a/syntax/impls.rs
+++ b/syntax/impls.rs
@@ -300,14 +300,22 @@
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 {
diff --git a/syntax/parse.rs b/syntax/parse.rs
index 484b101..1927554 100644
--- a/syntax/parse.rs
+++ b/syntax/parse.rs
@@ -3,7 +3,7 @@
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 @@
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 {