Skip to content

Commit 94afdba

Browse files
author
Ben Stern
committed
Eliminate most of the clippy warnings
1 parent 5ec95d0 commit 94afdba

File tree

7 files changed

+30
-52
lines changed

7 files changed

+30
-52
lines changed

src/builder.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl MapBuilder {
3737
let MapBuilder { mut data } = self;
3838
let value = to_data(value)?;
3939
data.insert(key.into(), value);
40-
Ok(MapBuilder { data: data })
40+
Ok(MapBuilder { data })
4141
}
4242

4343
/// Add a `String` to the `MapBuilder`.
@@ -56,7 +56,7 @@ impl MapBuilder {
5656
{
5757
let MapBuilder { mut data } = self;
5858
data.insert(key.into(), Data::String(value.into()));
59-
MapBuilder { data: data }
59+
MapBuilder { data }
6060
}
6161

6262
/// Add a `bool` to the `MapBuilder`.
@@ -74,7 +74,7 @@ impl MapBuilder {
7474
{
7575
let MapBuilder { mut data } = self;
7676
data.insert(key.into(), Data::Bool(value));
77-
MapBuilder { data: data }
77+
MapBuilder { data }
7878
}
7979

8080
/// Add a `Vec` to the `MapBuilder`.
@@ -97,7 +97,7 @@ impl MapBuilder {
9797
let MapBuilder { mut data } = self;
9898
let builder = f(VecBuilder::new());
9999
data.insert(key.into(), builder.build());
100-
MapBuilder { data: data }
100+
MapBuilder { data }
101101
}
102102

103103
/// Add a `Map` to the `MapBuilder`.
@@ -126,7 +126,7 @@ impl MapBuilder {
126126
let MapBuilder { mut data } = self;
127127
let builder = f(MapBuilder::new());
128128
data.insert(key.into(), builder.build());
129-
MapBuilder { data: data }
129+
MapBuilder { data }
130130
}
131131

132132
/// Add a function to the `MapBuilder`.
@@ -147,7 +147,7 @@ impl MapBuilder {
147147
{
148148
let MapBuilder { mut data } = self;
149149
data.insert(key.to_string(), Data::Fun(RefCell::new(Box::new(f))));
150-
MapBuilder { data: data }
150+
MapBuilder { data }
151151
}
152152

153153
/// Return the built `Data`.
@@ -183,7 +183,7 @@ impl VecBuilder {
183183
let VecBuilder { mut data } = self;
184184
let value = to_data(value)?;
185185
data.push(value);
186-
Ok(VecBuilder { data: data })
186+
Ok(VecBuilder { data })
187187
}
188188

189189
/// Add a `String` to the `VecBuilder`.
@@ -199,7 +199,7 @@ impl VecBuilder {
199199
pub fn push_str<T: ToString>(self, value: T) -> VecBuilder {
200200
let VecBuilder { mut data } = self;
201201
data.push(Data::String(value.to_string()));
202-
VecBuilder { data: data }
202+
VecBuilder { data }
203203
}
204204

205205
/// Add a `bool` to the `VecBuilder`.
@@ -215,7 +215,7 @@ impl VecBuilder {
215215
pub fn push_bool(self, value: bool) -> VecBuilder {
216216
let VecBuilder { mut data } = self;
217217
data.push(Data::Bool(value));
218-
VecBuilder { data: data }
218+
VecBuilder { data }
219219
}
220220

221221
/// Add a `Vec` to the `MapBuilder`.
@@ -237,7 +237,7 @@ impl VecBuilder {
237237
let VecBuilder { mut data } = self;
238238
let builder = f(VecBuilder::new());
239239
data.push(builder.build());
240-
VecBuilder { data: data }
240+
VecBuilder { data }
241241
}
242242

243243
/// Add a `Map` to the `VecBuilder`.
@@ -264,7 +264,7 @@ impl VecBuilder {
264264
let VecBuilder { mut data } = self;
265265
let builder = f(MapBuilder::new());
266266
data.push(builder.build());
267-
VecBuilder { data: data }
267+
VecBuilder { data }
268268
}
269269

270270
/// Add a function to the `VecBuilder`.
@@ -285,7 +285,7 @@ impl VecBuilder {
285285
{
286286
let VecBuilder { mut data } = self;
287287
data.push(Data::Fun(RefCell::new(Box::new(f))));
288-
VecBuilder { data: data }
288+
VecBuilder { data }
289289
}
290290

291291
#[inline]

src/compiler.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ impl<T: Iterator<Item = char>> Compiler<T> {
2323
/// Construct a default compiler.
2424
pub fn new(ctx: Context, reader: T) -> Compiler<T> {
2525
Compiler {
26-
ctx: ctx,
27-
reader: reader,
26+
ctx,
27+
reader,
2828
partials: HashMap::new(),
2929
otag: "{{".to_string(),
3030
ctag: "}}".to_string(),
@@ -38,13 +38,7 @@ impl<T: Iterator<Item = char>> Compiler<T> {
3838
otag: String,
3939
ctag: String)
4040
-> Compiler<T> {
41-
Compiler {
42-
ctx: ctx,
43-
reader: reader,
44-
partials: partials,
45-
otag: otag,
46-
ctag: ctag,
47-
}
41+
Compiler { ctx, reader, partials, otag, ctag }
4842
}
4943

5044
/// Compiles a template into a series of tokens.

src/encoder.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ use super::{Data, to_data};
1212
/// This type is not intended to be matched exhaustively as new variants
1313
/// may be added in future without a version bump.
1414
#[derive(Debug)]
15+
#[non_exhaustive]
1516
pub enum Error {
1617
NestedOptions,
1718
UnsupportedType,
1819
MissingElements,
1920
KeyIsNotString,
2021
NoDataToEncode,
2122
Message(String),
22-
23-
#[doc(hidden)]
24-
__Nonexhaustive,
2523
}
2624

2725
impl serde::ser::Error for Error {
@@ -42,7 +40,6 @@ impl fmt::Display for Error {
4240
Error::KeyIsNotString => "key is not a string",
4341
Error::NoDataToEncode => "the encodable type created no data",
4442
Error::Message(ref s) => s,
45-
Error::__Nonexhaustive => unreachable!(),
4643
})
4744
}
4845
}

src/error.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ use encoder;
1010
/// This type is not intended to be matched exhaustively as new variants
1111
/// may be added in future without a version bump.
1212
#[derive(Debug)]
13+
#[non_exhaustive]
1314
pub enum Error {
1415
InvalidStr,
1516
NoFilename,
1617
IncompleteSection,
1718
Io(StdIoError),
1819
Parser(parser::Error),
1920
Encoder(encoder::Error),
20-
21-
#[doc(hidden)]
22-
__Nonexhaustive,
2321
}
2422

2523
pub type Result<T> = StdResult<T, Error>;
@@ -33,7 +31,6 @@ impl fmt::Display for Error {
3331
Error::Io(ref err) => err.to_string(),
3432
Error::Parser(ref err) => err.to_string(),
3533
Error::Encoder(ref err) => err.to_string(),
36-
Error::__Nonexhaustive => unreachable!(),
3734
})
3835
}
3936
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn compile_path<U: AsRef<Path>>(path: U) -> Result<Template> {
4949

5050
match path.file_name() {
5151
Some(filename) => {
52-
let template_dir = path.parent().unwrap_or(Path::new("."));
52+
let template_dir = path.parent().unwrap_or_else(|| Path::new("."));
5353
// FIXME: Should work with OsStrings, this will not use provided extension if
5454
// the extension is not utf8 :(
5555
let extension = path.extension().and_then(|ext| ext.to_str()).unwrap_or("mustache");

src/parser.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub enum Token {
2121
/// This type is not intended to be matched exhaustively as new variants
2222
/// may be added in future without a version bump.
2323
#[derive(Debug, PartialEq)]
24+
#[non_exhaustive]
2425
pub enum Error {
2526
BadClosingTag(char, char),
2627
UnclosedTag,
@@ -30,9 +31,6 @@ pub enum Error {
3031
EarlySectionClose(String),
3132
MissingSetDelimeterClosingTag,
3233
InvalidSetDelimeterSyntax,
33-
34-
#[doc(hidden)]
35-
__Nonexhaustive,
3634
}
3735

3836
impl StdError for Error { }
@@ -49,7 +47,6 @@ impl fmt::Display for Error {
4947
Error::EmptyTag => write!(f, "found an empty tag",),
5048
Error::MissingSetDelimeterClosingTag => write!(f, "missing the new closing tag in set delimeter tag"),
5149
Error::InvalidSetDelimeterSyntax => write!(f, "invalid set delimeter tag syntax"),
52-
Error::__Nonexhaustive => unreachable!(),
5350
}
5451
}
5552
}
@@ -88,7 +85,7 @@ enum ParserState {
8885
impl<'a, T: Iterator<Item = char>> Parser<'a, T> {
8986
pub fn new(reader: &'a mut T, opening_tag: &str, closing_tag: &str) -> Parser<'a, T> {
9087
let mut parser = Parser {
91-
reader: reader,
88+
reader,
9289
ch: None,
9390
lookahead: None,
9491
line: 1,
@@ -172,7 +169,7 @@ impl<'a, T: Iterator<Item = char>> Parser<'a, T> {
172169
curly_brace_tag = false;
173170
self.state = ParserState::Tag;
174171
} else {
175-
self.tag_position = self.tag_position + 1;
172+
self.tag_position += 1;
176173
}
177174
} else {
178175
// We don't have a tag, so add all the tag parts we've seen
@@ -523,7 +520,7 @@ impl<'a, T: Iterator<Item = char>> Parser<'a, T> {
523520

524521
fn not_otag(&mut self) {
525522
for (i, ch) in self.opening_tag_chars.iter().enumerate() {
526-
if !(i < self.tag_position) {
523+
if i >= self.tag_position {
527524
break;
528525
}
529526
self.content.push(*ch);
@@ -532,7 +529,7 @@ impl<'a, T: Iterator<Item = char>> Parser<'a, T> {
532529

533530
fn not_ctag(&mut self) {
534531
for (i, ch) in self.closing_tag_chars.iter().enumerate() {
535-
if !(i < self.tag_position) {
532+
if i >= self.tag_position {
536533
break;
537534
}
538535
self.content.push(*ch);

src/template.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ pub struct Template {
2222
/// Construct a `Template`. This is not part of the impl of Template so it is
2323
/// not exported outside of mustache.
2424
pub fn new(ctx: Context, tokens: Vec<Token>, partials: HashMap<String, Vec<Token>>) -> Template {
25-
Template {
26-
ctx: ctx,
27-
tokens: tokens,
28-
partials: partials,
29-
}
25+
Template { ctx, tokens, partials }
3026
}
3127

3228
impl Template {
@@ -71,8 +67,8 @@ struct RenderContext<'a> {
7167
impl<'a> RenderContext<'a> {
7268
fn new(template: &'a Template) -> RenderContext<'a> {
7369
RenderContext {
74-
template: template,
75-
indent: "".to_string(),
70+
template,
71+
indent: String::new(),
7672
line_start: true,
7773
}
7874
}
@@ -340,14 +336,11 @@ impl<'a> RenderContext<'a> {
340336
let mut value = None;
341337

342338
for data in stack.iter().rev() {
343-
match **data {
344-
Data::Map(ref m) => {
345-
if let Some(v) = m.get(&path[0]) {
346-
value = Some(v);
347-
break;
348-
}
339+
if let Data::Map(m) = *data {
340+
if let Some(v) = m.get(&path[0]) {
341+
value = Some(v);
342+
break;
349343
}
350-
_ => { /* continue searching the stack */ },
351344
}
352345
}
353346

0 commit comments

Comments
 (0)