Lots of appeasing the borrow checker. How did this work before?

parent 96b4f7b5
Pipeline #14804 failed with stages
in 3 minutes and 34 seconds
......@@ -57,7 +57,7 @@ impl<'ast> ClassContext<'ast> {
for (parent_class, methods) in self.class.overrides.iter() {
for method in methods.iter() {
let name = method.sig.name;
let name = &method.sig.name;
let trampoline_name = self.names.slot_trampoline(&method.sig.name);
ret.push(quote! {
......
......@@ -17,7 +17,7 @@ pub fn slot_assignments<'ast>(names: &Names, slots: &[Slot<'ast>]) -> Vec<TokenS
Slot::Method(_) => None,
Slot::VirtualMethod(VirtualMethod { ref sig, .. }) => {
let name = sig.name;
let name = &sig.name;
let trampoline_name = names.slot_trampoline(&name);
Some(quote! {
......@@ -26,7 +26,7 @@ pub fn slot_assignments<'ast>(names: &Names, slots: &[Slot<'ast>]) -> Vec<TokenS
}
Slot::Signal(ref signal) => {
let signalname = signal.sig.name;
let signalname = &signal.sig.name;
let trampoline_name = names.slot_trampoline(&signalname);
Some(quote! {
......@@ -47,7 +47,7 @@ pub fn instance_slot_trampolines<'ast>(
let callback_guard = glib_callback_guard();
let InstanceName = names.instance();
let InstanceNameFfi = names.instance_ffi();
let tokens = |sig: &FnSig, parent_class: Option<Ident>| {
let tokens = |sig: &FnSig, parent_class: Option<&Ident>| {
let trampoline_name = names.slot_trampoline(&sig.name);
let method_impl_name = names.slot_impl(&sig.name);
let inputs = sig.input_args_with_glib_types();
......@@ -92,7 +92,7 @@ pub fn instance_slot_trampolines<'ast>(
ret.extend(
overrides
.iter()
.flat_map(|(&p, methods)| methods.iter().map(move |m| (p, m)))
.flat_map(|(p, methods)| methods.iter().map(move |m| (p, m)))
.map(|(parent_class, method)| {
// TODO: does the name here need mangling with the parent class?
tokens(&method.sig, Some(parent_class))
......@@ -108,8 +108,13 @@ pub fn slot_default_handlers<'ast>(
slots: &[Slot<'ast>],
overrides: Option<&HashMap<Ident, Vec<Method<'ast>>>>,
) -> Vec<TokenStream> {
let method = |sig: &FnSig, body: &Block, name: Option<Ident>| {
let name = name.unwrap_or_else(|| names.slot_impl(&sig.name));
let method = |sig: &FnSig, body: &Block, name: Option<&Ident>| {
let name = if let Some(name) = name {
name.clone()
} else {
names.slot_impl(&sig.name)
};
let inputs = &sig.inputs;
let output = &sig.output;
quote! {
......@@ -123,7 +128,7 @@ pub fn slot_default_handlers<'ast>(
public: false,
ref sig,
body,
}) => method(sig, body, Some(sig.name)),
}) => method(sig, body, Some(&sig.name)),
Slot::Method(Method { ref sig, body, .. })
| Slot::VirtualMethod(VirtualMethod {
ref sig,
......@@ -220,7 +225,7 @@ pub fn extern_methods<'ast>(names: &Names, slots: &[Slot<'ast>]) -> Vec<TokenStr
}
Slot::VirtualMethod(VirtualMethod { ref sig, .. }) => {
let name = sig.name;
let name = &sig.name;
let ffi_name = names.exported_fn(&sig.name);
let inputs = sig.input_args_with_glib_types();
let args = sig.input_arg_names();
......
......@@ -30,7 +30,7 @@ pub fn slot_trait_fns<'ast>(slots: &[Slot<'ast>]) -> Vec<TokenStream> {
..
})
| Slot::VirtualMethod(VirtualMethod { ref sig, .. }) => {
let name = sig.name;
let name = &sig.name;
let inputs = &sig.inputs;
let output = &sig.output;
Some(quote! {
......@@ -66,7 +66,7 @@ pub fn slot_trait_impls<'ast>(names: &Names, slots: &[Slot<'ast>]) -> Vec<TokenS
..
})
| Slot::VirtualMethod(VirtualMethod { ref sig, .. }) => {
let name = sig.name;
let name = &sig.name;
let ffi_name = names.exported_fn(&name);
let arg_names = sig.input_args_to_glib_types();
let value = quote! {
......
......@@ -12,7 +12,7 @@ pub fn properties_enum<'ast>(properties: &[Property<'ast>]) -> TokenStream {
.iter()
.enumerate()
.map(|(i, prop)| {
let name = prop.name;
let name = &prop.name;
let index = (i as u32) + 1;
quote! { #name = #index }
})
......@@ -32,7 +32,7 @@ pub fn property_setter<'ast>(properties: &[Property<'ast>]) -> TokenStream {
.enumerate()
.map(|(i, prop)| {
let index = (i as u32) + 1;
let param = prop.setter.param;
let param = &prop.setter.param;
let type_ = prop.type_;
let body = prop.setter.body;
......@@ -78,7 +78,7 @@ pub fn property_getter<'ast>(properties: &[Property<'ast>]) -> TokenStream {
#index => {
let ret: #type_ = (|| #body)();
unsafe {
#g_value_set
#g_value_set(value, ret);
}
}
}
......
......@@ -116,7 +116,7 @@ impl<'ast> ToTokens for ToGlibType<'ast> {
fn to_tokens(&self, tokens: &mut TokenStream) {
match *self.0 {
Ty::Unit => self.0.to_tokens(tokens),
Ty::Char(i) | Ty::Bool(i) => {
Ty::Char(ref i) | Ty::Bool(ref i) => {
(quote! {
<#i as ToGlib>::GlibType
}).to_tokens(tokens);
......@@ -126,7 +126,7 @@ impl<'ast> ToTokens for ToGlibType<'ast> {
<#t as GlibPtrDefault>::GlibType
}).to_tokens(tokens);
}
Ty::Integer(i) => i.to_tokens(tokens),
Ty::Integer(ref i) => i.to_tokens(tokens),
Ty::Owned(_) => {
Diagnostic::spanned(
self.0.span().unstable(),
......@@ -150,7 +150,7 @@ impl<'ast, T: ToTokens> ToTokens for ToGlib<'ast, T> {
// no conversion necessary
Ty::Unit | Ty::Integer(_) => self.1.to_tokens(tokens),
Ty::Char(i) | Ty::Bool(i) => {
Ty::Char(ref i) | Ty::Bool(ref i) => {
(quote! {
<#i as ToGlib>::to_glib(&#expr)
}).to_tokens(tokens);
......@@ -180,7 +180,7 @@ impl<'ast> ToTokens for FromGlib<'ast> {
fn to_tokens(&self, tokens: &mut TokenStream) {
let needs_conversion = match *self.0 {
Ty::Unit => false, // no conversion necessary
Ty::Char(i) | Ty::Bool(i) => {
Ty::Char(ref i) | Ty::Bool(ref i) => {
(quote! {
<#i as FromGlib<_>>::from_glib
}).to_tokens(tokens);
......@@ -206,7 +206,7 @@ impl<'ast> ToTokens for FromGlib<'ast> {
if needs_conversion {
tokens.append(TokenTree::Group(Group::new(
Delimiter::Parenthesis,
self.1,
self.1.clone(),
)));
} else {
self.1.to_tokens(tokens);
......@@ -236,7 +236,7 @@ impl<'ast> ToTokens for FnArgsWithGlibTypes<'ast> {
fn to_tokens(&self, tokens: &mut TokenStream) {
for arg in self.0.inputs[1..].iter() {
match *arg {
FnArg::Arg { name, ref ty, .. } => {
FnArg::Arg { ref name, ref ty, .. } => {
name.to_tokens(tokens);
Token!(:)([Span::call_site()]).to_tokens(tokens);
ToGlibType(ty, self.0).to_tokens(tokens);
......@@ -274,7 +274,7 @@ impl<'ast> ToTokens for ArgNamesToGlib<'ast> {
fn to_tokens(&self, tokens: &mut TokenStream) {
for arg in self.0 {
match *arg {
FnArg::Arg { ref ty, name, .. } => {
FnArg::Arg { ref ty, ref name, .. } => {
ToGlib(ty, name).to_tokens(tokens);
Token!(,)([Span::call_site()]).to_tokens(tokens);
}
......@@ -298,7 +298,7 @@ impl<'ast> ToTokens for ArgNamesToGlibValues<'ast> {
code.to_tokens(tokens);
}
FnArg::Arg { name, .. } => {
FnArg::Arg { ref name, .. } => {
let code = quote! {
(&#name as &glib::ToValue).to_value(),
};
......@@ -316,7 +316,7 @@ impl<'ast> ToTokens for ArgNames<'ast> {
fn to_tokens(&self, tokens: &mut TokenStream) {
for arg in self.0 {
match *arg {
FnArg::Arg { name, .. } => {
FnArg::Arg { ref name, .. } => {
name.to_tokens(tokens);
Token!(,)([Span::call_site()]).to_tokens(tokens);
}
......
......@@ -22,7 +22,7 @@ impl<'ast> ToTokens for SlotDeclaration<'ast> {
Slot::VirtualMethod(VirtualMethod { ref sig, .. }) => {
let output = sig.output_glib_type();
let inputs = sig.input_args_with_glib_types();
let name = sig.name;
let name = &sig.name;
(quote! {
pub #name: Option<unsafe extern "C" fn(
this: *mut #InstanceNameFfi,
......@@ -34,7 +34,7 @@ impl<'ast> ToTokens for SlotDeclaration<'ast> {
Slot::Signal(ref signal) => {
let output = signal.sig.output_glib_type();
let inputs = signal.sig.input_args_with_glib_types();
let signalname = signal.sig.name;
let signalname = &signal.sig.name;
(quote! {
pub #signalname: Option<unsafe extern "C" fn(
......
......@@ -177,9 +177,9 @@ impl<'ast> Classes<'ast> {
fn add(&mut self, ast_class: &'ast ast::Class) -> Result<()> {
let prev = self.items.insert(
ast_class.name,
ast_class.name.clone(),
Class {
name: ast_class.name,
name: ast_class.name.clone(),
gobject_parent: ast_class.extends.is_none(),
parent: tokens_ParentInstance(ast_class),
parent_ffi: tokens_ParentInstanceFfi(ast_class),
......@@ -205,7 +205,7 @@ impl<'ast> Classes<'ast> {
match *impl_ {
ast::Impl {
is_interface: false,
trait_: Some(parent_class),
trait_: Some(ref parent_class),
..
} => {
for item in impl_.items.iter() {
......@@ -243,7 +243,7 @@ impl<'ast> Classes<'ast> {
};
class
.overrides
.entry(parent_class)
.entry(parent_class.clone())
.or_insert_with(Vec::new)
.push(method);
}
......@@ -270,7 +270,7 @@ impl<'ast> Classes<'ast> {
ast::Impl {
is_interface: true,
trait_: Some(_parent_class),
trait_: Some(ref _parent_class),
..
} => unimplemented!(),
......@@ -349,7 +349,7 @@ fn extract_sig<'ast>(method: &'ast ast::ImplItemMethod) -> Result<FnSig<'ast>> {
Ok(FnSig {
output: extract_output(&method.output)?,
inputs: extract_inputs(&method.inputs)?,
name: method.name,
name: method.name.clone(),
})
}
......@@ -370,7 +370,7 @@ fn extract_inputs<'ast>(punc: &'ast Punctuated<syn::FnArg, Token!(,)>) -> Result
syn::Pat::Ident(syn::PatIdent {
by_ref: None,
mutability: m,
ident,
ref ident,
subpat: None,
}) => (ident, m),
_ => bail!("only bare identifiers are allowed as argument patterns"),
......@@ -378,7 +378,7 @@ fn extract_inputs<'ast>(punc: &'ast Punctuated<syn::FnArg, Token!(,)>) -> Result
Ok(FnArg::Arg {
mutbl,
name,
name: name.clone(),
ty: Ty::extract_from_type(ty)?,
})
}
......@@ -467,13 +467,13 @@ impl<'ast> Ty<'ast> {
return Ok(Ty::Owned(t));
}
let ident = t.segments.first().unwrap().value().ident;
let ident = &t.segments.first().unwrap().value().ident;
match ident.to_owned_string().as_str() {
"char" => Ok(Ty::Char(ident)),
"bool" => Ok(Ty::Bool(ident)),
"char" => Ok(Ty::Char(ident.clone())),
"bool" => Ok(Ty::Bool(ident.clone())),
"i8" | "i16" | "i32" | "i64" | "isize" | "u8" | "u16" | "u32" | "u64" | "usize" => {
Ok(Ty::Integer(ident))
Ok(Ty::Integer(ident.clone()))
}
_other => Ok(Ty::Owned(t)),
}
......@@ -600,7 +600,7 @@ impl<'ast> Property<'ast> {
fn translate_from_impl_item(item: &'ast ast::ImplItem) -> Result<Property<'ast>> {
assert_eq!(item.attrs.len(), 0); // attributes unimplemented
if let ast::ImplItemKind::Prop(ref prop) = item.node {
let name = prop.name;
let name = &prop.name;
let type_ = &prop.type_;
let getter = match prop.getter() {
......@@ -611,7 +611,7 @@ impl<'ast> Property<'ast> {
let setter = match prop.setter() {
Some(ast::ImplPropBlock::Setter(ref b)) => PropertySetterBlock {
param: b.param,
param: b.param.clone(),
body: &b.block,
},
None => bail!("property without setter: {}", name),
......@@ -619,7 +619,7 @@ impl<'ast> Property<'ast> {
};
return Ok(Property {
name,
name: name.clone(),
type_,
getter,
setter,
......@@ -650,9 +650,9 @@ impl<'ast> Interfaces<'ast> {
let properties = self.translate_properties(ast_iface)?;
let prev = self.items.insert(
ast_iface.name,
ast_iface.name.clone(),
Interface {
name: ast_iface.name,
name: ast_iface.name.clone(),
slots,
properties,
},
......@@ -714,9 +714,9 @@ impl<'a> ToTokens for FnArg<'a> {
self_.to_tokens(tokens);
}
FnArg::Arg {
name,
ref name,
ref ty,
mutbl,
ref mutbl,
} => {
mutbl.to_tokens(tokens);
name.to_tokens(tokens);
......@@ -734,9 +734,9 @@ impl<'a> ToTokens for Ty<'a> {
Delimiter::Parenthesis,
quote!{ () }.into(),
))),
Ty::Char(tok) => tok.to_tokens(tokens),
Ty::Bool(tok) => tok.to_tokens(tokens),
Ty::Integer(t) => t.to_tokens(tokens),
Ty::Char(ref tok) => tok.to_tokens(tokens),
Ty::Bool(ref tok) => tok.to_tokens(tokens),
Ty::Integer(ref t) => t.to_tokens(tokens),
Ty::Borrowed(ref t) => {
Token!(&)([Span::call_site()]).to_tokens(tokens);
t.to_tokens(tokens)
......
......@@ -354,7 +354,7 @@ pub mod tests {
if let ast::Item::Impl(ref impl_) = item {
assert_eq!(impl_.is_interface, is_interface);
if let Some(trait_path) = impl_.trait_ {
if let Some(ref trait_path) = impl_.trait_ {
assert_tokens_equal(&trait_path, trait_name.as_ref().unwrap());
} else {
assert!(trait_name.is_none());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment