Commit bc26718d authored by Alex Crichton's avatar Alex Crichton
Browse files

Fix all "edition idiom" warnings for 2018

* No longer necessary to `extern crate`
* Add `<'_>` where idiomatic
parent 3e982566
......@@ -4,7 +4,7 @@ use proc_macro2::Ident;
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::token;
use syn::{Attribute, Lit};
use syn::{Attribute, Lit, Token};
use syn::{Block, FieldsNamed, FnArg, ImplItemType, Path, ReturnType, Type};
pub struct Program {
......
......@@ -91,7 +91,7 @@ impl<T> ErrorAppend for Result<T> {
}
}
impl ToError for Spanned {
impl ToError for dyn Spanned {
fn to_error<E: Display>(&self, input: E) -> Error {
Error::new(self.span(), input)
}
......
use crate::hir::names::ParentNames;
use proc_macro2::TokenStream;
use quote::ToTokens;
use quote::{quote, ToTokens};
pub trait AncestorRefExt {
type GlibWrapperTokens: ToTokens;
......
......@@ -8,10 +8,10 @@ pub trait Boilerplate<'ast> {
fn parent_names(&self) -> &ParentNames;
fn ancestors(&self) -> &[ParentNames];
fn reserved_slot_declarations(&self) -> ReservedSlotDeclarations;
fn slot_declarations(&self) -> SlotDeclarations;
fn slot_declarations(&self) -> SlotDeclarations<'_>;
fn slots(&self) -> &[Slot<'ast>];
fn fundamental_type(&self) -> ::glib::Type;
fn properties(&self) -> &[Property];
fn properties(&self) -> &[Property<'_>];
fn overrides(&self) -> Option<&[OverrideItem<'ast>]>;
fn has_private(&self) -> bool;
fn private_fields(&self) -> Option<&[&'ast Field]>;
......
......@@ -3,7 +3,7 @@ use crate::gen::ancestorext::AncestorRefExt;
use crate::hir::Property;
use crate::hir::{Method, Signal, Slot, VirtualMethod};
use proc_macro2::TokenStream;
use quote::ToTokens;
use quote::{quote, ToTokens};
use std::iter::FilterMap;
use std::slice::Iter;
......
......@@ -29,7 +29,7 @@ impl<'ast> Boilerplate<'ast> for Class<'ast> {
ReservedSlotDeclarations(self.class.n_reserved_slots)
}
fn slot_declarations(&self) -> SlotDeclarations {
fn slot_declarations(&self) -> SlotDeclarations<'_> {
SlotDeclarations {
InstanceNameFfi: self.class.names.instance_ffi().clone(),
slots: &self.class.slots,
......@@ -44,7 +44,7 @@ impl<'ast> Boilerplate<'ast> for Class<'ast> {
::glib::Type::BaseObject
}
fn properties(&self) -> &[Property] {
fn properties(&self) -> &[Property<'_>] {
&self.class.properties
}
......@@ -67,7 +67,7 @@ impl<'ast> Boilerplate<'ast> for Class<'ast> {
impl<'ast> Class<'ast> {
#[cfg_attr(rustfmt, rustfmt_skip)]
pub fn new(program: &'ast Program, class: &'ast hir::Class) -> Self {
pub fn new(program: &'ast Program<'_>, class: &'ast hir::Class<'_>) -> Self {
// This function creates a Class by generating the
// commonly-used symbol names for the class in question, for
// example, "FooClass" out of "Foo".
......
use proc_macro2::{Literal, TokenStream, TokenTree};
use quote::{ToTokens, TokenStreamExt};
use quote::{quote, ToTokens, TokenStreamExt};
/// Wraps a `&str` so it can be tokenized as a C-friendly string literal.
///
......
......@@ -11,7 +11,7 @@ use crate::errors::*;
use xml::writer::Result as EmitterResult;
pub fn generate(program: &Program) -> Result<()> {
pub fn generate(program: &Program<'_>) -> Result<()> {
for class in program.classes.iter() {
generate_gir(class)?;
}
......@@ -19,13 +19,13 @@ pub fn generate(program: &Program) -> Result<()> {
Ok(())
}
pub fn generate_gir(class: &Class) -> Result<()> {
pub fn generate_gir(class: &Class<'_>) -> Result<()> {
let mut writer = GeneratorWrite::from(&class.attrs.gir);
generate_gir_xml(class, &mut writer).map_err(|err| class.names.span().to_errors(err))?;
writer.collect_output()
}
fn generate_gir_xml(class: &Class, f: &mut GeneratorWrite) -> EmitterResult<()> {
fn generate_gir_xml(class: &Class<'_>, f: &mut GeneratorWrite) -> EmitterResult<()> {
let mut w = EmitterConfig::new().perform_indent(true).create_writer(f);
let name = class.names.instance().to_string();
......@@ -103,7 +103,7 @@ fn generate_gir_xml(class: &Class, f: &mut GeneratorWrite) -> EmitterResult<()>
fn gen_slot_xml(
w: &mut EventWriter<&mut GeneratorWrite>,
names: &Names,
slot: &Slot,
slot: &Slot<'_>,
) -> EmitterResult<()> {
// <method name="add" c:identifier="counter_add">
// <return-value transfer-ownership="none">
......@@ -220,7 +220,7 @@ fn gen_constructor_xml(
Ok(())
}
fn type_to_ctype(type_: &Ty) -> String {
fn type_to_ctype(type_: &Ty<'_>) -> String {
match *type_ {
Ty::Integer(_) => "gint".to_string(),
Ty::Unit => "void".to_string(),
......
use proc_macro2::{Ident, TokenStream};
use quote::quote;
use syn::Block;
use crate::glib_utils::*;
use crate::hir::{FnSig, Method, Override, OverrideItem, Signal, Slot, VirtualMethod};
use crate::hir::names::{Names, ParentNames};
use crate::hir::{FnSig, Method, Override, OverrideItem, Signal, Slot, VirtualMethod};
pub fn slot_assignments<'ast>(names: &Names, slots: &[Slot<'ast>]) -> Vec<TokenStream> {
let InstanceNameFfi = names.instance_ffi();
......@@ -45,7 +45,7 @@ pub fn instance_slot_trampolines<'this, 'ast: 'this>(
let callback_guard = glib_callback_guard();
let InstanceName = names.instance();
let InstanceNameFfi = names.instance_ffi();
let tokens = |sig: &FnSig, parent_names: Option<&ParentNames>| {
let tokens = |sig: &FnSig<'_>, parent_names: Option<&ParentNames>| {
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();
......@@ -117,7 +117,7 @@ pub fn slot_default_handlers<'this, 'ast: 'this>(
slots: &'this [Slot<'ast>],
overrides: impl Iterator<Item = &'this OverrideItem<'ast>>,
) -> Vec<TokenStream> {
let method = |sig: &FnSig, body: &Block, name: Option<&Ident>| {
let method = |sig: &FnSig<'_>, body: &Block, name: Option<&Ident>| {
let name = if let Some(name) = name {
name.clone()
} else {
......
use super::boilerplate;
use crate::gen::boilerplateext::BoilerplateExt;
use proc_macro2::TokenStream;
use quote::ToTokens;
use quote::{quote, ToTokens};
use std::marker::PhantomData;
pub struct Instance<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast> + 'lt> {
pub struct Instance<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> {
boilerplate: &'lt Boilerplate,
phantom: PhantomData<&'ast ()>,
}
......
use proc_macro2::TokenStream;
use quote::ToTokens;
use quote::{quote, ToTokens};
use crate::hir::{Method, Slot, Ty, VirtualMethod};
......
......@@ -31,7 +31,7 @@ impl<'ast> Boilerplate<'ast> for Interface<'ast> {
ReservedSlotDeclarations(0)
}
fn slot_declarations(&self) -> SlotDeclarations {
fn slot_declarations(&self) -> SlotDeclarations<'_> {
SlotDeclarations {
InstanceNameFfi: self.iface.names.instance_ffi(),
slots: &self.iface.slots,
......@@ -46,7 +46,7 @@ impl<'ast> Boilerplate<'ast> for Interface<'ast> {
::glib::Type::BaseInterface
}
fn properties(&self) -> &[Property] {
fn properties(&self) -> &[Property<'_>] {
&self.iface.properties
}
......@@ -68,7 +68,7 @@ impl<'ast> Boilerplate<'ast> for Interface<'ast> {
}
impl<'ast> Interface<'ast> {
pub fn new(program: &'ast Program, iface: &'ast hir::Interface) -> Self {
pub fn new(program: &'ast Program<'_>, iface: &'ast hir::Interface<'_>) -> Self {
let parent_names = ParentNames::new_from_glib(::glib::Type::BaseInterface);
Interface {
......
......@@ -33,7 +33,7 @@ use crate::hir::Program;
pub use self::ancestorext::AncestorRefExt;
pub fn codegen(program: &Program) -> TokenStream {
pub fn codegen(program: &Program<'_>) -> TokenStream {
let mut writer = RustWriter::new();
program.classes.iter().for_each(|class| {
......
//! This file contains the instantion of all the data that is instantiated once
//! and stored in a static variable
use crate::gen::boilerplate;
use crate::gen::boilerplateext::BoilerplateExt;
use crate::hir::{Override, OverrideItem};
/// ! This file contains the instantion of all the data that is instantiated once
/// ! and stored in a static variable
use proc_macro2::TokenStream;
use quote::ToTokens;
use quote::{quote, ToTokens};
use std::marker::PhantomData;
pub struct PrivateStatic<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast> + 'lt> {
pub struct PrivateStatic<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> {
boilerplate: &'lt Boilerplate,
phantom: PhantomData<&'ast ()>,
}
......
use proc_macro2::{Ident, TokenStream};
use quote::quote;
use crate::gen::PropertyGenExt;
use crate::hir::{Property, Ty};
......
use crate::hir::{Property, Ty};
use crate::ident_ext::IdentExt;
use proc_macro2::TokenStream;
use quote::quote;
use syn::Lit;
pub trait PropertyGenExt<'ast> {
......
......@@ -3,18 +3,18 @@ use super::instance_ext;
use super::properties;
use crate::gen::boilerplateext::BoilerplateExt;
use proc_macro2::TokenStream;
use quote::ToTokens;
use quote::{quote, ToTokens};
use std::marker::PhantomData;
/// This class can generate the public part of the boilerplate code for objects
pub struct Public<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast> + 'lt> {
pub struct Public<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> {
boilerplate: &'lt Boilerplate,
phantom: PhantomData<&'ast ()>,
}
/// This class can generate the public part of the boilerplate code for objects
/// The code is expected to be inserted into the "imp"-mod
pub struct PublicImp<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast> + 'lt> {
pub struct PublicImp<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> {
boilerplate: &'lt Boilerplate,
phantom: PhantomData<&'ast ()>,
}
......
use proc_macro2::{Ident, TokenStream};
use quote::quote;
use std::char;
use syn::Path;
use crate::glib_utils::*;
use crate::hir::{FnArg, Signal, Ty};
use super::super::ident_ext::IdentExt;
use super::cstringliteral::CStringLiteral;
use crate::glib_utils::*;
use crate::hir::names::Names;
use crate::hir::{FnArg, Signal, Ty};
pub fn signal_emit_methods<'ast>(
signals: impl Iterator<Item = &'ast Signal<'ast>>,
......@@ -176,25 +175,25 @@ pub fn signal_trampolines<'ast>(
/// From a signal called `foo`, generate `foo_signal_id`. This is used to
/// store the signal ids from g_signal_newv() in the Class structure.
fn signal_id_name<'ast>(signal: &'ast Signal) -> Ident {
fn signal_id_name<'ast>(signal: &'ast Signal<'_>) -> Ident {
Ident::from_str(format!("{}_signal_id", signal.sig.name))
}
/// From a signal called `foo` generate a `foo_trampoline` identifier. This is used
/// for the functions that get passed to g_signal_connect().
pub fn signal_trampoline_name(signal: &Signal) -> Ident {
pub fn signal_trampoline_name(signal: &Signal<'_>) -> Ident {
Ident::from_str(format!("{}_signal_handler_trampoline", signal.sig.name))
}
/// From a signal called `foo` generate a `connect_foo` identifier. This is used
/// for the public methods in the InstanceExt trait.
pub fn connect_signalname(signal: &Signal) -> Ident {
pub fn connect_signalname(signal: &Signal<'_>) -> Ident {
Ident::from_str(format!("connect_{}", signal.sig.name))
}
/// From a signal called `foo` generate a `emit_foo` identifier. This is used
/// for the user's implementations of methods.
fn emit_signalname(signal: &Signal) -> Ident {
fn emit_signalname(signal: &Signal<'_>) -> Ident {
Ident::from_str(format!("emit_{}", signal.sig.name))
}
......@@ -217,8 +216,8 @@ pub fn canonicalize_signal_name(name: &str) -> Result<String, ()> {
for c in name.chars() {
canon.push(match c {
'a'...'z' => c,
'A'...'Z' => char::from_u32(u32::from(c) + u32::from('a') - u32::from('A')).unwrap(),
'a'..='z' => c,
'A'..='Z' => char::from_u32(u32::from(c) + u32::from('a') - u32::from('A')).unwrap(),
_ => return Err(()),
});
......@@ -227,9 +226,9 @@ pub fn canonicalize_signal_name(name: &str) -> Result<String, ()> {
for c in name.chars().skip(1) {
canon.push(match c {
'0'...'9' => c,
'a'...'z' => c,
'A'...'Z' => char::from_u32(u32::from(c) + u32::from('a') - u32::from('A')).unwrap(),
'0'..='9' => c,
'a'..='z' => c,
'A'..='Z' => char::from_u32(u32::from(c) + u32::from('a') - u32::from('A')).unwrap(),
'_' | '-' => '-',
_ => return Err(()),
});
......
use proc_macro2::{Span, TokenStream};
use quote::ToTokens;
use quote::{quote, ToTokens};
use syn::Token;
use crate::hir::{FnArg, FnSig, Ty};
......
use proc_macro2::{Ident, TokenStream};
use quote::ToTokens;
use quote::{quote, ToTokens};
use crate::hir::{Slot, VirtualMethod};
......
......@@ -2,7 +2,7 @@
use crate::ast;
use proc_macro2::TokenStream;
use quote::ToTokens;
use quote::{quote, ToTokens};
pub fn tokens_GObject() -> TokenStream {
quote! { glib::Object }
......
......@@ -46,7 +46,7 @@ impl<'ast> Classes<'ast> {
self.items.len()
}
pub fn get(&self, name: &str) -> &Class {
pub fn get(&self, name: &str) -> &Class<'_> {
self.items.iter().find(|c| c.1.names == name).unwrap().1
}
......@@ -77,7 +77,7 @@ impl<'ast> Classes<'ast> {
Ok(())
}
fn add_impl_method(item: &'ast ast::ImplItemMethod) -> Result<Method> {
fn add_impl_method(item: &'ast ast::ImplItemMethod) -> Result<Method<'_>> {
if let Some(spanned) = &item.signal {
return spanned
.span()
......@@ -203,7 +203,7 @@ impl<'ast> Classes<'ast> {
res
}
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a Class> + 'a {
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a Class<'_>> + 'a {
self.items.values()
}
}
......
......@@ -17,14 +17,14 @@ use std::collections::HashMap;
use std::rc::Rc;
use proc_macro2::{Ident, Span, TokenStream};
use quote::quote;
use quote::ToTokens;
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::{self, parse_str, Block, LitStr, Path, ReturnType};
use self::names::{Names, ParentNames};
use syn::{self, parse_str, Block, LitStr, Path, ReturnType, Token};
use self::generatorattrs::GeneratorAttributes;
use self::names::{Names, ParentNames};
use super::ast;
use super::checking::*;
use super::errors::*;
......@@ -517,7 +517,7 @@ impl<'ast> Interfaces<'ast> {
self.items.len()
}
pub fn get(&self, name: &str) -> &Interface {
pub fn get(&self, name: &str) -> &Interface<'_> {
self.items.iter().find(|c| c.1.names == name).unwrap().1
}
......@@ -578,7 +578,7 @@ impl<'ast> Interfaces<'ast> {
Ok(properties)
}
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a Interface> + 'a {
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a Interface<'_>> + 'a {
self.items.values()
}
}
......
......@@ -2,6 +2,7 @@ use crate::ast;
use crate::errors::*;
use gobject_sys::GParamFlags;
use proc_macro2::{Ident, TokenStream};
use quote::quote;
use syn::Block;
use syn::Type;
use syn::{Attribute, Lit, Meta, MetaList, NestedMeta};
......
......@@ -234,21 +234,8 @@
//! a bug][bugs] if gnome-class is generating incorrect code for you!
//!
//! [bugs]: https://gitlab.gnome.org/federico/gnome-class/issues
#[macro_use]
extern crate quote;
extern crate difference;
extern crate proc_macro;
extern crate proc_macro2;
extern crate rustfmt;
extern crate unicode_xid;
extern crate xml;
#[macro_use]
extern crate syn;
extern crate glib;
extern crate glib_sys;
extern crate gobject_sys;
extern crate proc_macro;
use crate::errors::*;
......
use proc_macro;
use proc_macro2::TokenStream;
use syn;
use syn::parse::{Parse, ParseStream, Result};
use syn::{self, braced, parenthesized, Token};
use crate::ast;
pub mod keywords {
use syn::custom_keyword;
custom_keyword!(class);
custom_keyword!(interface);
custom_keyword!(property);
......@@ -21,7 +23,7 @@ pub fn parse_program(token_stream: proc_macro::TokenStream) -> Result<ast::Progr
}
impl Parse for ast::Program {
fn parse(input: ParseStream) -> Result<Self> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
Ok(ast::Program {
items: ast::Item::parse_outer(input)?,
})
......@@ -29,7 +31,7 @@ impl Parse for ast::Program {
}
impl Parse for ast::Item {
fn parse(input: ParseStream) -> Result<Self> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let attrs = syn::Attribute::parse_outer(input)?;
let lookahead = input.lookahead1();
if lookahead.peek(keywords::class) {
......@@ -51,7 +53,7 @@ impl Parse for ast::Item {
}
impl ast::Item {
fn parse_outer(input: ParseStream) -> Result<Vec<Self>> {
fn parse_outer(input: ParseStream<'_>) -> Result<Vec<Self>> {
let mut res = Vec::new();
while !input.is_empty() {
res.push(input.parse()?);
......@@ -61,7 +63,7 @@ impl ast::Item {
}
impl Parse for ast::Class {
fn parse(input: ParseStream) -> Result<Self> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let class = input.parse()?;
let name = input.parse()?;
let colon: Option<Token![:]> = input.parse()?;
......@@ -83,7 +85,7 @@ impl Parse for ast::Class {
}
impl Parse for ast::Interface {
fn parse(input: ParseStream) -> Result<Self> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let content;
Ok(ast::Interface {
attrs: Vec::new(),
......@@ -96,7 +98,7 @@ impl Parse for ast::Interface {
}
impl Parse for ast::Impl {
fn parse(input: ParseStream) -> Result<Self> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
input.parse::<Token![impl ]>()?;
let trait_ = if input.peek2(Token![for]) {
let trait_ = input.parse()?;
......@@ -122,7 +124,7 @@ impl Parse for ast::Impl {
}
impl Parse for ast::ImplItem {
fn parse(input: ParseStream) -> Result<Self> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
Ok(ast::ImplItem {
attrs: input.call(syn::Attribute::parse_outer)?,
node: input.parse()?,
......@@ -131,7 +133,7 @@ impl Parse for ast::ImplItem {
}
impl ast::ImplItem {
fn parse_outer(input: ParseStream) -> Result<Vec<Self>> {
fn parse_outer(input: ParseStream<'_>) -> Result<Vec<Self>> {
let mut res = Vec::new();
while !input.is_empty() {
res.push(input.parse()?);
......@@ -141,7 +143,7 @@ impl ast::ImplItem {
}
impl Parse for ast::ImplItemKind {
fn parse(input: ParseStream) -> Result<Self> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let lookahead = input.lookahead1();
if lookahead.peek(keywords::property) {
input.parse().map(ast::ImplItemKind::Prop)
......@@ -159,7 +161,7 @@ impl Parse for ast::ImplItemKind {
}
impl Parse for ast::ImplItemMethodBlock {
fn parse(input: ParseStream) -> Result<Self> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
if input.peek(Token![;]) {
input.parse().map(ast::ImplItemMethodBlock::Empty)
} else {
......@@ -169,7 +171,7 @@ impl Parse for ast::ImplItemMethodBlock {
}
impl Parse for ast::ImplItemMethod {
fn parse(input: ParseStream) -> Result<Self> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let content;
let public: Option<Token![pub]> = input.parse()?;
let virtual_ = input.parse()?;
......@@ -195,7 +197,7 @@ impl Parse for ast::ImplItemMethod {
}
impl Parse for ast::ImplProp {
fn parse(input: ParseStream) -> Result<Self> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let content;
Ok(ast::ImplProp {
attributes: input.call(syn::Attribute::parse_inner)?,
......@@ -214,7 +216,7 @@ impl Parse for ast::ImplProp {
}
impl Parse for ast::ImplPropBlock {
fn parse(input: ParseStream) -> Result<Self> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let lookahead = input.lookahead1();
if lookahead.peek(keywords::get) {
input.parse().map(ast::ImplPropBlock::Getter)
......@@ -229,7 +231,7 @@ impl Parse for ast::ImplPropBlock {
}
impl ast::ImplPropBlock {
fn parse_outer(input: ParseStream) -> Result<Vec<Self>> {
fn parse_outer(input: ParseStream<'_>) -> Result<Vec<Self>> {
let mut res = Vec::new();
while !input.is_empty() {