From c837ee102fb8b27426f90b7b1908f8e9a86d02b5 Mon Sep 17 00:00:00 2001 From: Luro02 <24826124+Luro02@users.noreply.github.com> Date: Tue, 1 Sep 2020 13:19:44 +0200 Subject: [PATCH 1/2] migrate to rust 2018 edition --- CHANGELOG.md | 5 ++ Cargo.toml | 1 + src/associated_type.rs | 7 +-- src/block.rs | 8 ++-- src/body.rs | 14 +++--- src/bound.rs | 3 +- src/docs.rs | 6 +-- src/enum.rs | 12 ++--- src/field.rs | 7 ++- src/fields.rs | 16 +++---- src/formatter.rs | 14 ++---- src/function.rs | 20 ++++---- src/impl.rs | 14 +++--- src/import.rs | 1 - src/item.rs | 13 +++--- src/lib.rs | 1 + src/module.rs | 20 ++++---- src/scope.rs | 31 ++++++------- src/struct.rs | 17 +++---- src/trait.rs | 16 +++---- src/type.rs | 24 +++++----- src/type_def.rs | 25 +++++----- src/variant.rs | 10 ++-- tests/codegen.rs | 102 ++++++++++++++++++++++------------------- 24 files changed, 183 insertions(+), 204 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85cf789..5dea49f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# + +### Changed +- updated the crate to rust 2018 edition + # 0.1.3 (May 9, 2020) ### Added diff --git a/Cargo.toml b/Cargo.toml index c06bef1..dde02aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ documentation = "https://docs.rs/codegen/0.1.3/codegen" homepage = "https://github.com/carllerche/codegen" repository = "https://github.com/carllerche/codegen" readme = "README.md" +edition = "2018" [dependencies] indexmap = "1.0.2" diff --git a/src/associated_type.rs b/src/associated_type.rs index a9d91f5..c4d26dc 100644 --- a/src/associated_type.rs +++ b/src/associated_type.rs @@ -1,13 +1,10 @@ -use bound::Bound; - -use r#type::Type; - +use crate::bound::Bound; +use crate::r#type::Type; /// Defines an associated type. #[derive(Debug, Clone)] pub struct AssociatedType(pub Bound); - impl AssociatedType { /// Add a bound to the associated type. pub fn bound(&mut self, ty: T) -> &mut Self diff --git a/src/block.rs b/src/block.rs index 57d720e..6bb321e 100644 --- a/src/block.rs +++ b/src/block.rs @@ -1,8 +1,7 @@ use std::fmt::{self, Write}; -use body::Body; -use formatter::Formatter; - +use crate::body::Body; +use crate::formatter::Formatter; /// Defines a code block. This is used to define a function body. #[derive(Debug, Clone)] @@ -12,7 +11,6 @@ pub struct Block { body: Vec, } - impl Block { /// Returns an empty code block. pub fn new(before: &str) -> Self { @@ -45,7 +43,7 @@ impl Block { } /// Formats the block using the given formatter. - pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { if let Some(ref before) = self.before { write!(fmt, "{}", before)?; } diff --git a/src/body.rs b/src/body.rs index b8d27a8..4c6efbe 100644 --- a/src/body.rs +++ b/src/body.rs @@ -1,8 +1,7 @@ use std::fmt::{self, Write}; -use block::Block; -use formatter::Formatter; - +use crate::block::Block; +use crate::formatter::Formatter; #[derive(Debug, Clone)] pub enum Body { @@ -10,12 +9,11 @@ pub enum Body { Block(Block), } - impl Body { - pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { - match *self { - Body::String(ref s) => write!(fmt, "{}\n", s), - Body::Block(ref b) => b.fmt(fmt), + pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { + match &self { + Body::String(s) => write!(fmt, "{}\n", s), + Body::Block(b) => b.fmt(fmt), } } } diff --git a/src/bound.rs b/src/bound.rs index 3904638..94da046 100644 --- a/src/bound.rs +++ b/src/bound.rs @@ -1,5 +1,4 @@ -use r#type::Type; - +use crate::r#type::Type; #[derive(Debug, Clone)] pub struct Bound { diff --git a/src/docs.rs b/src/docs.rs index 0fcbe21..d03dc3a 100644 --- a/src/docs.rs +++ b/src/docs.rs @@ -1,14 +1,12 @@ use std::fmt::{self, Write}; -use formatter::Formatter; - +use crate::formatter::Formatter; #[derive(Debug, Clone)] pub struct Docs { docs: String, } - impl Docs { pub fn new(docs: &str) -> Self { Docs { @@ -16,7 +14,7 @@ impl Docs { } } - pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { for line in self.docs.lines() { write!(fmt, "/// {}\n", line)?; } diff --git a/src/enum.rs b/src/enum.rs index 6e08906..2636f62 100644 --- a/src/enum.rs +++ b/src/enum.rs @@ -1,11 +1,10 @@ use std::fmt; -use formatter::Formatter; -use type_def::TypeDef; -use variant::Variant; - -use r#type::Type; +use crate::formatter::Formatter; +use crate::type_def::TypeDef; +use crate::variant::Variant; +use crate::r#type::Type; /// Defines an enumeration. #[derive(Debug, Clone)] @@ -14,7 +13,6 @@ pub struct Enum { variants: Vec, } - impl Enum { /// Return a enum definition with the provided name. pub fn new(name: &str) -> Self { @@ -87,7 +85,7 @@ impl Enum { } /// Formats the enum using the given formatter. - pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { self.type_def.fmt_head("enum", &[], fmt)?; fmt.block(|fmt| { diff --git a/src/field.rs b/src/field.rs index 6077f12..769158f 100644 --- a/src/field.rs +++ b/src/field.rs @@ -1,5 +1,4 @@ -use r#type::Type; - +use crate::r#type::Type; /// Defines a struct field. #[derive(Debug, Clone)] @@ -17,11 +16,11 @@ pub struct Field { pub annotation: Vec, } - impl Field { /// Return a field definition with the provided name and type pub fn new(name: &str, ty: T) -> Self - where T: Into, + where + T: Into, { Field { name: name.into(), diff --git a/src/fields.rs b/src/fields.rs index f3d6465..6878818 100644 --- a/src/fields.rs +++ b/src/fields.rs @@ -1,10 +1,9 @@ use std::fmt::{self, Write}; -use field::Field; -use formatter::Formatter; - -use r#type::Type; +use crate::field::Field; +use crate::formatter::Formatter; +use crate::r#type::Type; /// Defines a set of fields. #[derive(Debug, Clone)] @@ -14,10 +13,8 @@ pub enum Fields { Named(Vec), } - impl Fields { - pub fn push_named(&mut self, field: Field) -> &mut Self - { + pub fn push_named(&mut self, field: Field) -> &mut Self { match *self { Fields::Empty => { *self = Fields::Named(vec![field]); @@ -32,7 +29,8 @@ impl Fields { } pub fn named(&mut self, name: &str, ty: T) -> &mut Self - where T: Into, + where + T: Into, { self.push_named(Field { name: name.to_string(), @@ -59,7 +57,7 @@ impl Fields { self } - pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { match *self { Fields::Named(ref fields) => { assert!(!fields.is_empty()); diff --git a/src/formatter.rs b/src/formatter.rs index aa06354..447a6f6 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -1,13 +1,11 @@ use std::fmt::{self, Write}; -use bound::Bound; - -use r#type::Type; +use crate::bound::Bound; +use crate::r#type::Type; const DEFAULT_INDENT: usize = 4; - /// Configures how a scope is formatted. #[derive(Debug)] pub struct Formatter<'a> { @@ -21,7 +19,6 @@ pub struct Formatter<'a> { indent: usize, } - impl<'a> Formatter<'a> { /// Return a new formatter that writes to the given string. pub fn new(dst: &'a mut String) -> Self { @@ -102,9 +99,8 @@ impl<'a> fmt::Write for Formatter<'a> { } } - /// Format generics. -pub fn fmt_generics(generics: &[String], fmt: &mut Formatter) -> fmt::Result { +pub fn fmt_generics(generics: &[String], fmt: &mut Formatter<'_>) -> fmt::Result { if !generics.is_empty() { write!(fmt, "<")?; @@ -122,7 +118,7 @@ pub fn fmt_generics(generics: &[String], fmt: &mut Formatter) -> fmt::Result { } /// Format generic bounds. -pub fn fmt_bounds(bounds: &[Bound], fmt: &mut Formatter) -> fmt::Result { +pub fn fmt_bounds(bounds: &[Bound], fmt: &mut Formatter<'_>) -> fmt::Result { if !bounds.is_empty() { write!(fmt, "\n")?; @@ -142,7 +138,7 @@ pub fn fmt_bounds(bounds: &[Bound], fmt: &mut Formatter) -> fmt::Result { } /// Format multiple generic bounds. -pub fn fmt_bound_rhs(tys: &[Type], fmt: &mut Formatter) -> fmt::Result { +pub fn fmt_bound_rhs(tys: &[Type], fmt: &mut Formatter<'_>) -> fmt::Result { for (i, ty) in tys.iter().enumerate() { if i != 0 { write!(fmt, " + ")? diff --git a/src/function.rs b/src/function.rs index e89fc66..827ec6c 100644 --- a/src/function.rs +++ b/src/function.rs @@ -1,15 +1,14 @@ use std::fmt::{self, Write}; -use block::Block; -use body::Body; -use bound::Bound; -use docs::Docs; -use field::Field; -use formatter::{fmt_bounds, fmt_generics}; -use formatter::Formatter; - -use r#type::Type; +use crate::block::Block; +use crate::body::Body; +use crate::bound::Bound; +use crate::docs::Docs; +use crate::field::Field; +use crate::formatter::Formatter; +use crate::formatter::{fmt_bounds, fmt_generics}; +use crate::r#type::Type; /// Defines a function. #[derive(Debug, Clone)] @@ -54,7 +53,6 @@ pub struct Function { r#async: bool, } - impl Function { /// Return a new function definition. pub fn new(name: &str) -> Self { @@ -211,7 +209,7 @@ impl Function { } /// Formats the function using the given formatter. - pub fn fmt(&self, is_trait: bool, fmt: &mut Formatter) -> fmt::Result { + pub fn fmt(&self, is_trait: bool, fmt: &mut Formatter<'_>) -> fmt::Result { if let Some(ref docs) = self.docs { docs.fmt(fmt)?; } diff --git a/src/impl.rs b/src/impl.rs index 1aef190..6e411b5 100644 --- a/src/impl.rs +++ b/src/impl.rs @@ -1,12 +1,11 @@ use std::fmt::{self, Write}; -use bound::Bound; -use field::Field; -use formatter::{Formatter, fmt_bounds, fmt_generics}; -use function::Function; - -use r#type::Type; +use crate::bound::Bound; +use crate::field::Field; +use crate::formatter::{fmt_bounds, fmt_generics, Formatter}; +use crate::function::Function; +use crate::r#type::Type; /// Defines an impl block. #[derive(Debug, Clone)] @@ -31,7 +30,6 @@ pub struct Impl { macros: Vec, } - impl Impl { /// Return a new impl definition pub fn new(target: T) -> Self @@ -121,7 +119,7 @@ impl Impl { } /// Formats the impl block using the given formatter. - pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { for m in self.macros.iter() { write!(fmt, "{}\n", m)?; } diff --git a/src/import.rs b/src/import.rs index 0cc1209..6d44bd0 100644 --- a/src/import.rs +++ b/src/import.rs @@ -7,7 +7,6 @@ pub struct Import { pub vis: Option, } - impl Import { /// Return a new import. pub fn new(path: &str, ty: &str) -> Self { diff --git a/src/item.rs b/src/item.rs index 56d3c96..5f6fb62 100644 --- a/src/item.rs +++ b/src/item.rs @@ -1,11 +1,10 @@ -use function::Function; -use module::Module; - -use r#enum::Enum; -use r#impl::Impl; -use r#struct::Struct; -use r#trait::Trait; +use crate::function::Function; +use crate::module::Module; +use crate::r#enum::Enum; +use crate::r#impl::Impl; +use crate::r#struct::Struct; +use crate::r#trait::Trait; #[derive(Debug, Clone)] pub enum Item { diff --git a/src/lib.rs b/src/lib.rs index b722f4b..af7cdb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![deny(warnings, missing_debug_implementations, missing_docs)] #![doc(html_root_url = "https://docs.rs/codegen/0.1.1")] +#![warn(rust_2018_idioms)] //! Provides a builder API for generating Rust code. //! diff --git a/src/module.rs b/src/module.rs index da42968..4846a61 100644 --- a/src/module.rs +++ b/src/module.rs @@ -1,15 +1,14 @@ use std::fmt::{self, Write}; -use docs::Docs; -use formatter::Formatter; -use function::Function; -use scope::Scope; - -use r#enum::Enum; -use r#impl::Impl; -use r#struct::Struct; -use r#trait::Trait; +use crate::docs::Docs; +use crate::formatter::Formatter; +use crate::function::Function; +use crate::scope::Scope; +use crate::r#enum::Enum; +use crate::r#impl::Impl; +use crate::r#struct::Struct; +use crate::r#trait::Trait; /// Defines a module. #[derive(Debug, Clone)] @@ -27,7 +26,6 @@ pub struct Module { scope: Scope, } - impl Module { /// Return a new, blank module pub fn new(name: &str) -> Self { @@ -165,7 +163,7 @@ impl Module { } /// Formats the module using the given formatter. - pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { if let Some(ref vis) = self.vis { write!(fmt, "{} ", vis)?; } diff --git a/src/scope.rs b/src/scope.rs index aa7bd25..1312139 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -1,22 +1,18 @@ -extern crate indexmap; - - use std::fmt::{self, Write}; -use self::indexmap::IndexMap; +use indexmap::IndexMap; -use docs::Docs; -use formatter::Formatter; -use function::Function; -use import::Import; -use item::Item; -use module::Module; - -use r#enum::Enum; -use r#impl::Impl; -use r#struct::Struct; -use r#trait::Trait; +use crate::docs::Docs; +use crate::formatter::Formatter; +use crate::function::Function; +use crate::import::Import; +use crate::item::Item; +use crate::module::Module; +use crate::r#enum::Enum; +use crate::r#impl::Impl; +use crate::r#struct::Struct; +use crate::r#trait::Trait; /// Defines a scope. /// @@ -33,7 +29,6 @@ pub struct Scope { items: Vec, } - impl Scope { /// Returns a new scope pub fn new() -> Self { @@ -239,7 +234,7 @@ impl Scope { } /// Formats the scope using the given formatter. - pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { self.fmt_imports(fmt)?; if !self.imports.is_empty() { @@ -267,7 +262,7 @@ impl Scope { Ok(()) } - fn fmt_imports(&self, fmt: &mut Formatter) -> fmt::Result { + fn fmt_imports(&self, fmt: &mut Formatter<'_>) -> fmt::Result { // First, collect all visibilities let mut visibilities = vec![]; diff --git a/src/struct.rs b/src/struct.rs index ea50916..8feae8a 100644 --- a/src/struct.rs +++ b/src/struct.rs @@ -1,12 +1,11 @@ use std::fmt::{self, Write}; -use field::Field; -use fields::Fields; -use formatter::Formatter; -use type_def::TypeDef; - -use r#type::Type; +use crate::field::Field; +use crate::fields::Fields; +use crate::formatter::Formatter; +use crate::type_def::TypeDef; +use crate::r#type::Type; /// Defines a struct. #[derive(Debug, Clone)] @@ -17,7 +16,6 @@ pub struct Struct { fields: Fields, } - impl Struct { /// Return a structure definition with the provided name pub fn new(name: &str) -> Self { @@ -81,8 +79,7 @@ impl Struct { /// /// A struct can either set named fields with this function or tuple fields /// with `push_tuple_field`, but not both. - pub fn push_field(&mut self, field: Field) -> &mut Self - { + pub fn push_field(&mut self, field: Field) -> &mut Self { self.fields.push_named(field); self } @@ -112,7 +109,7 @@ impl Struct { } /// Formats the struct using the given formatter. - pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { self.type_def.fmt_head("struct", &[], fmt)?; self.fields.fmt(fmt)?; diff --git a/src/trait.rs b/src/trait.rs index 1a100b1..7a8c069 100644 --- a/src/trait.rs +++ b/src/trait.rs @@ -1,13 +1,12 @@ use std::fmt::{self, Write}; -use associated_type::AssociatedType; -use bound::Bound; -use formatter::{Formatter, fmt_bound_rhs}; -use function::Function; -use type_def::TypeDef; - -use r#type::Type; +use crate::associated_type::AssociatedType; +use crate::bound::Bound; +use crate::formatter::{fmt_bound_rhs, Formatter}; +use crate::function::Function; +use crate::type_def::TypeDef; +use crate::r#type::Type; /// Define a trait. #[derive(Debug, Clone)] @@ -19,7 +18,6 @@ pub struct Trait { macros: Vec, } - impl Trait { /// Return a trait definition with the provided name pub fn new(name: &str) -> Self { @@ -106,7 +104,7 @@ impl Trait { } /// Formats the scope using the given formatter. - pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { self.type_def.fmt_head("trait", &self.parents, fmt)?; fmt.block(|fmt| { diff --git a/src/type.rs b/src/type.rs index 61c4637..4a46eca 100644 --- a/src/type.rs +++ b/src/type.rs @@ -1,7 +1,6 @@ use std::fmt::{self, Write}; -use formatter::Formatter; - +use crate::formatter::Formatter; /// Defines a type. #[derive(Debug, Clone)] @@ -10,7 +9,6 @@ pub struct Type { generics: Vec, } - impl Type { /// Return a new type with the given name. pub fn new(name: &str) -> Self { @@ -53,12 +51,12 @@ impl Type { } /// Formats the struct using the given formatter. - pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { write!(fmt, "{}", self.name)?; Type::fmt_slice(&self.generics, fmt) } - fn fmt_slice(generics: &[Type], fmt: &mut Formatter) -> fmt::Result { + fn fmt_slice(generics: &[Type], fmt: &mut Formatter<'_>) -> fmt::Result { if !generics.is_empty() { write!(fmt, "<")?; @@ -74,30 +72,30 @@ impl Type { Ok(()) } - } +} - impl<'a> From<&'a str> for Type { +impl<'a> From<&'a str> for Type { fn from(src: &'a str) -> Self { Type::new(src) } - } +} - impl From for Type { +impl From for Type { fn from(src: String) -> Self { Type { name: src, generics: vec![], } } - } +} - impl<'a> From<&'a String> for Type { +impl<'a> From<&'a String> for Type { fn from(src: &'a String) -> Self { Type::new(src) } - } +} - impl<'a> From<&'a Type> for Type { +impl<'a> From<&'a Type> for Type { fn from(src: &'a Type) -> Self { src.clone() } diff --git a/src/type_def.rs b/src/type_def.rs index c196cd1..a5fad01 100644 --- a/src/type_def.rs +++ b/src/type_def.rs @@ -1,11 +1,10 @@ use std::fmt::{self, Write}; -use bound::Bound; -use docs::Docs; -use formatter::{Formatter, fmt_bounds}; - -use r#type::Type; +use crate::bound::Bound; +use crate::docs::Docs; +use crate::formatter::{fmt_bounds, Formatter}; +use crate::r#type::Type; /// Defines a type definition. #[derive(Debug, Clone)] @@ -20,7 +19,6 @@ pub struct TypeDef { macros: Vec, } - impl TypeDef { /// Return a structure definition with the provided name pub fn new(name: &str) -> Self { @@ -70,7 +68,12 @@ impl TypeDef { self.repr = Some(repr.to_string()); } - pub fn fmt_head(&self, keyword: &str, parents: &[Type], fmt: &mut Formatter) -> fmt::Result { + pub fn fmt_head( + &self, + keyword: &str, + parents: &[Type], + fmt: &mut Formatter<'_>, + ) -> fmt::Result { if let Some(ref docs) = self.docs { docs.fmt(fmt)?; } @@ -104,7 +107,7 @@ impl TypeDef { Ok(()) } - fn fmt_allow(&self, fmt: &mut Formatter) -> fmt::Result { + fn fmt_allow(&self, fmt: &mut Formatter<'_>) -> fmt::Result { if let Some(ref allow) = self.allow { write!(fmt, "#[allow({})]\n", allow)?; } @@ -112,7 +115,7 @@ impl TypeDef { Ok(()) } - fn fmt_repr(&self, fmt: &mut Formatter) -> fmt::Result { + fn fmt_repr(&self, fmt: &mut Formatter<'_>) -> fmt::Result { if let Some(ref repr) = self.repr { write!(fmt, "#[repr({})]\n", repr)?; } @@ -120,7 +123,7 @@ impl TypeDef { Ok(()) } - fn fmt_derive(&self, fmt: &mut Formatter) -> fmt::Result { + fn fmt_derive(&self, fmt: &mut Formatter<'_>) -> fmt::Result { if !self.derive.is_empty() { write!(fmt, "#[derive(")?; @@ -137,7 +140,7 @@ impl TypeDef { Ok(()) } - fn fmt_macros(&self, fmt: &mut Formatter) -> fmt::Result { + fn fmt_macros(&self, fmt: &mut Formatter<'_>) -> fmt::Result { for m in self.macros.iter() { write!(fmt, "{}\n", m)?; } diff --git a/src/variant.rs b/src/variant.rs index b522a55..164f2e4 100644 --- a/src/variant.rs +++ b/src/variant.rs @@ -1,10 +1,9 @@ use std::fmt::{self, Write}; -use fields::Fields; -use formatter::Formatter; - -use r#type::Type; +use crate::fields::Fields; +use crate::formatter::Formatter; +use crate::r#type::Type; /// Defines an enum variant. #[derive(Debug, Clone)] @@ -13,7 +12,6 @@ pub struct Variant { fields: Fields, } - impl Variant { /// Return a new enum variant with the given name. pub fn new(name: &str) -> Self { @@ -39,7 +37,7 @@ impl Variant { } /// Formats the variant using the given formatter. - pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { write!(fmt, "{}", self.name)?; self.fields.fmt(fmt)?; write!(fmt, ",\n")?; diff --git a/tests/codegen.rs b/tests/codegen.rs index c8c0306..b48bd1c 100644 --- a/tests/codegen.rs +++ b/tests/codegen.rs @@ -1,6 +1,5 @@ -extern crate codegen; - use codegen::*; + #[test] fn empty_scope() { let scope = Scope::new(); @@ -12,7 +11,8 @@ fn empty_scope() { fn single_struct() { let mut scope = Scope::new(); - scope.new_struct("Foo") + scope + .new_struct("Foo") .field("one", "usize") .field("two", "String"); @@ -86,7 +86,8 @@ struct Foo { #[test] fn single_fn() { let mut scope = Scope::new(); - scope.new_fn("my_fn") + scope + .new_fn("my_fn") .vis("pub") .arg("foo", Type::new("uint")) .ret(Type::new("uint")) @@ -118,12 +119,12 @@ struct Foo;"#; fn two_structs() { let mut scope = Scope::new(); - scope.new_struct("Foo") + scope + .new_struct("Foo") .field("one", "usize") .field("two", "String"); - scope.new_struct("Bar") - .field("hello", "World"); + scope.new_struct("Bar").field("hello", "World"); let expect = r#" struct Foo { @@ -142,8 +143,10 @@ struct Bar { fn struct_with_derive() { let mut scope = Scope::new(); - scope.new_struct("Foo") - .derive("Debug").derive("Clone") + scope + .new_struct("Foo") + .derive("Debug") + .derive("Clone") .field("one", "usize") .field("two", "String"); @@ -161,7 +164,8 @@ struct Foo { fn struct_with_repr() { let mut scope = Scope::new(); - scope.new_struct("Foo") + scope + .new_struct("Foo") .repr("C") .field("one", "u8") .field("two", "u8"); @@ -180,7 +184,8 @@ struct Foo { fn struct_with_allow() { let mut scope = Scope::new(); - scope.new_struct("Foo") + scope + .new_struct("Foo") .allow("dead_code") .field("one", "u8") .field("two", "u8"); @@ -199,7 +204,8 @@ struct Foo { fn struct_with_generics_1() { let mut scope = Scope::new(); - scope.new_struct("Foo") + scope + .new_struct("Foo") .generic("T") .generic("U") .field("one", "T") @@ -218,7 +224,8 @@ struct Foo { fn struct_with_generics_2() { let mut scope = Scope::new(); - scope.new_struct("Foo") + scope + .new_struct("Foo") .generic("T, U") .field("one", "T") .field("two", "U"); @@ -236,7 +243,8 @@ struct Foo { fn struct_with_generics_3() { let mut scope = Scope::new(); - scope.new_struct("Foo") + scope + .new_struct("Foo") .generic("T: Win, U") .field("one", "T") .field("two", "U"); @@ -254,7 +262,8 @@ struct Foo { fn struct_where_clause_1() { let mut scope = Scope::new(); - scope.new_struct("Foo") + scope + .new_struct("Foo") .generic("T") .bound("T", "Foo") .field("one", "T"); @@ -273,7 +282,8 @@ where T: Foo, fn struct_where_clause_2() { let mut scope = Scope::new(); - scope.new_struct("Foo") + scope + .new_struct("Foo") .generic("T, U") .bound("T", "Foo") .bound("U", "Baz") @@ -296,9 +306,12 @@ where T: Foo, fn struct_doc() { let mut scope = Scope::new(); - scope.new_struct("Foo") - .doc("Hello, this is a doc string\n\ - that continues on another line.") + scope + .new_struct("Foo") + .doc( + "Hello, this is a doc string\n\ + that continues on another line.", + ) .field("one", "T"); let expect = r#" @@ -317,15 +330,15 @@ fn struct_in_mod() { { let module = scope.new_module("foo"); - module.new_struct("Foo") + module + .new_struct("Foo") .doc("Hello some docs") .derive("Debug") .generic("T, U") .bound("T", "SomeBound") .bound("U", "SomeOtherBound") .field("one", "T") - .field("two", "U") - ; + .field("two", "U"); } let expect = r#" @@ -347,11 +360,11 @@ mod foo { #[test] fn struct_mod_import() { let mut scope = Scope::new(); - scope.new_module("foo") + scope + .new_module("foo") .import("bar", "Bar") .new_struct("Foo") - .field("bar", "Bar") - ; + .field("bar", "Bar"); let expect = r#" mod foo { @@ -369,11 +382,11 @@ mod foo { fn enum_with_repr() { let mut scope = Scope::new(); - scope.new_enum("IpAddrKind") + scope + .new_enum("IpAddrKind") .repr("u8") .push_variant(Variant::new("V4")) - .push_variant(Variant::new("V6")) - ; + .push_variant(Variant::new("V6")); let expect = r#" #[repr(u8)] @@ -389,11 +402,11 @@ enum IpAddrKind { fn enum_with_allow() { let mut scope = Scope::new(); - scope.new_enum("IpAddrKind") + scope + .new_enum("IpAddrKind") .allow("dead_code") .push_variant(Variant::new("V4")) - .push_variant(Variant::new("V6")) - ; + .push_variant(Variant::new("V6")); let expect = r#" #[allow(dead_code)] @@ -408,15 +421,15 @@ enum IpAddrKind { #[test] fn scoped_imports() { let mut scope = Scope::new(); - scope.new_module("foo") + scope + .new_module("foo") .import("bar", "Bar") .import("bar", "baz::Baz") .import("bar::quux", "quuux::Quuuux") .new_struct("Foo") .field("bar", "Bar") .field("baz", "baz::Baz") - .field("quuuux", "quuux::Quuuux") - ; + .field("quuuux", "quuux::Quuuux"); let expect = r#" mod foo { @@ -436,14 +449,13 @@ mod foo { #[test] fn module_mut() { let mut scope = Scope::new(); - scope.new_module("foo") - .import("bar", "Bar") - ; + scope.new_module("foo").import("bar", "Bar"); - scope.get_module_mut("foo").expect("module_mut") + scope + .get_module_mut("foo") + .expect("module_mut") .new_struct("Foo") - .field("bar", "Bar") - ; + .field("bar", "Bar"); let expect = r#" mod foo { @@ -462,14 +474,12 @@ fn get_or_new_module() { let mut scope = Scope::new(); assert!(scope.get_module("foo").is_none()); - scope.get_or_new_module("foo") - .import("bar", "Bar") - ; + scope.get_or_new_module("foo").import("bar", "Bar"); - scope.get_or_new_module("foo") + scope + .get_or_new_module("foo") .new_struct("Foo") - .field("bar", "Bar") - ; + .field("bar", "Bar"); let expect = r#" mod foo { From 6275642359938f6fa3dcebaaaad9edbafc5cb00f Mon Sep 17 00:00:00 2001 From: Luro02 <24826124+Luro02@users.noreply.github.com> Date: Tue, 1 Sep 2020 13:22:20 +0200 Subject: [PATCH 2/2] remove deny(warnings) (anti-pattern) see https://www.reddit.com/r/rust/comments/f5xpib/psa_denywarnings_is_actively_harmful/ --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index af7cdb6..70b8675 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![deny(warnings, missing_debug_implementations, missing_docs)] +#![deny(missing_debug_implementations, missing_docs)] #![doc(html_root_url = "https://docs.rs/codegen/0.1.1")] #![warn(rust_2018_idioms)]