Skip to content

Commit 2907a76

Browse files
authored
Update to rust 2018 edition (carllerche#30)
* migrate to rust 2018 edition * remove deny(warnings) (anti-pattern) see https://www.reddit.com/r/rust/comments/f5xpib/psa_denywarnings_is_actively_harmful/
1 parent 899501d commit 2907a76

24 files changed

+184
-205
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# <future version>
2+
3+
### Changed
4+
- updated the crate to rust 2018 edition
5+
16
# 0.1.3 (May 9, 2020)
27

38
### Added

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ documentation = "https://docs.rs/codegen/0.1.3/codegen"
1313
homepage = "https://github.com/carllerche/codegen"
1414
repository = "https://github.com/carllerche/codegen"
1515
readme = "README.md"
16+
edition = "2018"
1617

1718
[dependencies]
1819
indexmap = "1.0.2"

src/associated_type.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
use bound::Bound;
2-
3-
use r#type::Type;
4-
1+
use crate::bound::Bound;
2+
use crate::r#type::Type;
53

64
/// Defines an associated type.
75
#[derive(Debug, Clone)]
86
pub struct AssociatedType(pub Bound);
97

10-
118
impl AssociatedType {
129
/// Add a bound to the associated type.
1310
pub fn bound<T>(&mut self, ty: T) -> &mut Self

src/block.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::fmt::{self, Write};
22

3-
use body::Body;
4-
use formatter::Formatter;
5-
3+
use crate::body::Body;
4+
use crate::formatter::Formatter;
65

76
/// Defines a code block. This is used to define a function body.
87
#[derive(Debug, Clone)]
@@ -12,7 +11,6 @@ pub struct Block {
1211
body: Vec<Body>,
1312
}
1413

15-
1614
impl Block {
1715
/// Returns an empty code block.
1816
pub fn new(before: &str) -> Self {
@@ -45,7 +43,7 @@ impl Block {
4543
}
4644

4745
/// Formats the block using the given formatter.
48-
pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
46+
pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
4947
if let Some(ref before) = self.before {
5048
write!(fmt, "{}", before)?;
5149
}

src/body.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
use std::fmt::{self, Write};
22

3-
use block::Block;
4-
use formatter::Formatter;
5-
3+
use crate::block::Block;
4+
use crate::formatter::Formatter;
65

76
#[derive(Debug, Clone)]
87
pub enum Body {
98
String(String),
109
Block(Block),
1110
}
1211

13-
1412
impl Body {
15-
pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
16-
match *self {
17-
Body::String(ref s) => write!(fmt, "{}\n", s),
18-
Body::Block(ref b) => b.fmt(fmt),
13+
pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
14+
match &self {
15+
Body::String(s) => write!(fmt, "{}\n", s),
16+
Body::Block(b) => b.fmt(fmt),
1917
}
2018
}
2119
}

src/bound.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use r#type::Type;
2-
1+
use crate::r#type::Type;
32

43
#[derive(Debug, Clone)]
54
pub struct Bound {

src/docs.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
use std::fmt::{self, Write};
22

3-
use formatter::Formatter;
4-
3+
use crate::formatter::Formatter;
54

65
#[derive(Debug, Clone)]
76
pub struct Docs {
87
docs: String,
98
}
109

11-
1210
impl Docs {
1311
pub fn new(docs: &str) -> Self {
1412
Docs {
1513
docs: docs.to_string(),
1614
}
1715
}
1816

19-
pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
17+
pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
2018
for line in self.docs.lines() {
2119
write!(fmt, "/// {}\n", line)?;
2220
}

src/enum.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use std::fmt;
22

3-
use formatter::Formatter;
4-
use type_def::TypeDef;
5-
use variant::Variant;
6-
7-
use r#type::Type;
3+
use crate::formatter::Formatter;
4+
use crate::type_def::TypeDef;
5+
use crate::variant::Variant;
86

7+
use crate::r#type::Type;
98

109
/// Defines an enumeration.
1110
#[derive(Debug, Clone)]
@@ -14,7 +13,6 @@ pub struct Enum {
1413
variants: Vec<Variant>,
1514
}
1615

17-
1816
impl Enum {
1917
/// Return a enum definition with the provided name.
2018
pub fn new(name: &str) -> Self {
@@ -87,7 +85,7 @@ impl Enum {
8785
}
8886

8987
/// Formats the enum using the given formatter.
90-
pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
88+
pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
9189
self.type_def.fmt_head("enum", &[], fmt)?;
9290

9391
fmt.block(|fmt| {

src/field.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use r#type::Type;
2-
1+
use crate::r#type::Type;
32

43
/// Defines a struct field.
54
#[derive(Debug, Clone)]
@@ -17,11 +16,11 @@ pub struct Field {
1716
pub annotation: Vec<String>,
1817
}
1918

20-
2119
impl Field {
2220
/// Return a field definition with the provided name and type
2321
pub fn new<T>(name: &str, ty: T) -> Self
24-
where T: Into<Type>,
22+
where
23+
T: Into<Type>,
2524
{
2625
Field {
2726
name: name.into(),

src/fields.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::fmt::{self, Write};
22

3-
use field::Field;
4-
use formatter::Formatter;
5-
6-
use r#type::Type;
3+
use crate::field::Field;
4+
use crate::formatter::Formatter;
75

6+
use crate::r#type::Type;
87

98
/// Defines a set of fields.
109
#[derive(Debug, Clone)]
@@ -14,10 +13,8 @@ pub enum Fields {
1413
Named(Vec<Field>),
1514
}
1615

17-
1816
impl Fields {
19-
pub fn push_named(&mut self, field: Field) -> &mut Self
20-
{
17+
pub fn push_named(&mut self, field: Field) -> &mut Self {
2118
match *self {
2219
Fields::Empty => {
2320
*self = Fields::Named(vec![field]);
@@ -32,7 +29,8 @@ impl Fields {
3229
}
3330

3431
pub fn named<T>(&mut self, name: &str, ty: T) -> &mut Self
35-
where T: Into<Type>,
32+
where
33+
T: Into<Type>,
3634
{
3735
self.push_named(Field {
3836
name: name.to_string(),
@@ -59,7 +57,7 @@ impl Fields {
5957
self
6058
}
6159

62-
pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
60+
pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
6361
match *self {
6462
Fields::Named(ref fields) => {
6563
assert!(!fields.is_empty());

src/formatter.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use std::fmt::{self, Write};
22

3-
use bound::Bound;
4-
5-
use r#type::Type;
3+
use crate::bound::Bound;
64

5+
use crate::r#type::Type;
76

87
const DEFAULT_INDENT: usize = 4;
98

10-
119
/// Configures how a scope is formatted.
1210
#[derive(Debug)]
1311
pub struct Formatter<'a> {
@@ -21,7 +19,6 @@ pub struct Formatter<'a> {
2119
indent: usize,
2220
}
2321

24-
2522
impl<'a> Formatter<'a> {
2623
/// Return a new formatter that writes to the given string.
2724
pub fn new(dst: &'a mut String) -> Self {
@@ -102,9 +99,8 @@ impl<'a> fmt::Write for Formatter<'a> {
10299
}
103100
}
104101

105-
106102
/// Format generics.
107-
pub fn fmt_generics(generics: &[String], fmt: &mut Formatter) -> fmt::Result {
103+
pub fn fmt_generics(generics: &[String], fmt: &mut Formatter<'_>) -> fmt::Result {
108104
if !generics.is_empty() {
109105
write!(fmt, "<")?;
110106

@@ -122,7 +118,7 @@ pub fn fmt_generics(generics: &[String], fmt: &mut Formatter) -> fmt::Result {
122118
}
123119

124120
/// Format generic bounds.
125-
pub fn fmt_bounds(bounds: &[Bound], fmt: &mut Formatter) -> fmt::Result {
121+
pub fn fmt_bounds(bounds: &[Bound], fmt: &mut Formatter<'_>) -> fmt::Result {
126122
if !bounds.is_empty() {
127123
write!(fmt, "\n")?;
128124

@@ -142,7 +138,7 @@ pub fn fmt_bounds(bounds: &[Bound], fmt: &mut Formatter) -> fmt::Result {
142138
}
143139

144140
/// Format multiple generic bounds.
145-
pub fn fmt_bound_rhs(tys: &[Type], fmt: &mut Formatter) -> fmt::Result {
141+
pub fn fmt_bound_rhs(tys: &[Type], fmt: &mut Formatter<'_>) -> fmt::Result {
146142
for (i, ty) in tys.iter().enumerate() {
147143
if i != 0 {
148144
write!(fmt, " + ")?

src/function.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use std::fmt::{self, Write};
22

3-
use block::Block;
4-
use body::Body;
5-
use bound::Bound;
6-
use docs::Docs;
7-
use field::Field;
8-
use formatter::{fmt_bounds, fmt_generics};
9-
use formatter::Formatter;
10-
11-
use r#type::Type;
3+
use crate::block::Block;
4+
use crate::body::Body;
5+
use crate::bound::Bound;
6+
use crate::docs::Docs;
7+
use crate::field::Field;
8+
use crate::formatter::Formatter;
9+
use crate::formatter::{fmt_bounds, fmt_generics};
1210

11+
use crate::r#type::Type;
1312

1413
/// Defines a function.
1514
#[derive(Debug, Clone)]
@@ -54,7 +53,6 @@ pub struct Function {
5453
r#async: bool,
5554
}
5655

57-
5856
impl Function {
5957
/// Return a new function definition.
6058
pub fn new(name: &str) -> Self {
@@ -211,7 +209,7 @@ impl Function {
211209
}
212210

213211
/// Formats the function using the given formatter.
214-
pub fn fmt(&self, is_trait: bool, fmt: &mut Formatter) -> fmt::Result {
212+
pub fn fmt(&self, is_trait: bool, fmt: &mut Formatter<'_>) -> fmt::Result {
215213
if let Some(ref docs) = self.docs {
216214
docs.fmt(fmt)?;
217215
}

src/impl.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::fmt::{self, Write};
22

3-
use bound::Bound;
4-
use field::Field;
5-
use formatter::{Formatter, fmt_bounds, fmt_generics};
6-
use function::Function;
7-
8-
use r#type::Type;
3+
use crate::bound::Bound;
4+
use crate::field::Field;
5+
use crate::formatter::{fmt_bounds, fmt_generics, Formatter};
6+
use crate::function::Function;
97

8+
use crate::r#type::Type;
109

1110
/// Defines an impl block.
1211
#[derive(Debug, Clone)]
@@ -31,7 +30,6 @@ pub struct Impl {
3130
macros: Vec<String>,
3231
}
3332

34-
3533
impl Impl {
3634
/// Return a new impl definition
3735
pub fn new<T>(target: T) -> Self
@@ -121,7 +119,7 @@ impl Impl {
121119
}
122120

123121
/// Formats the impl block using the given formatter.
124-
pub fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
122+
pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
125123
for m in self.macros.iter() {
126124
write!(fmt, "{}\n", m)?;
127125
}

src/import.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub struct Import {
77
pub vis: Option<String>,
88
}
99

10-
1110
impl Import {
1211
/// Return a new import.
1312
pub fn new(path: &str, ty: &str) -> Self {

src/item.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use function::Function;
2-
use module::Module;
3-
4-
use r#enum::Enum;
5-
use r#impl::Impl;
6-
use r#struct::Struct;
7-
use r#trait::Trait;
1+
use crate::function::Function;
2+
use crate::module::Module;
83

4+
use crate::r#enum::Enum;
5+
use crate::r#impl::Impl;
6+
use crate::r#struct::Struct;
7+
use crate::r#trait::Trait;
98

109
#[derive(Debug, Clone)]
1110
pub enum Item {

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![deny(warnings, missing_debug_implementations, missing_docs)]
1+
#![deny(missing_debug_implementations, missing_docs)]
22
#![doc(html_root_url = "https://docs.rs/codegen/0.1.1")]
3+
#![warn(rust_2018_idioms)]
34

45
//! Provides a builder API for generating Rust code.
56
//!

0 commit comments

Comments
 (0)