Skip to content

Commit b855400

Browse files
authored
Cleanup (#2026)
1 parent c796a25 commit b855400

23 files changed

+171
-181
lines changed

src/analyzer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<'src> Analyzer<'src> {
1414
asts: &HashMap<PathBuf, Ast<'src>>,
1515
root: &Path,
1616
) -> CompileResult<'src, Justfile<'src>> {
17-
Analyzer::default().justfile(loaded, paths, asts, root)
17+
Self::default().justfile(loaded, paths, asts, root)
1818
}
1919

2020
fn justfile(

src/color.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ impl Color {
3434
pub(crate) fn auto() -> Self {
3535
Self {
3636
use_color: UseColor::Auto,
37-
..Color::default()
37+
..Self::default()
3838
}
3939
}
4040

4141
pub(crate) fn always() -> Self {
4242
Self {
4343
use_color: UseColor::Always,
44-
..Color::default()
44+
..Self::default()
4545
}
4646
}
4747

4848
pub(crate) fn never() -> Self {
4949
Self {
5050
use_color: UseColor::Never,
51-
..Color::default()
51+
..Self::default()
5252
}
5353
}
5454

src/compile_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<'src> CompileError<'src> {
1414
pub(crate) fn new(token: Token<'src>, kind: CompileErrorKind<'src>) -> CompileError<'src> {
1515
Self {
1616
token,
17-
kind: Box::new(kind),
17+
kind: kind.into(),
1818
}
1919
}
2020
}

src/compiler.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ impl Compiler {
88
loader: &'src Loader,
99
root: &Path,
1010
) -> RunResult<'src, Compilation<'src>> {
11-
let mut asts: HashMap<PathBuf, Ast> = HashMap::new();
12-
let mut paths: HashMap<PathBuf, PathBuf> = HashMap::new();
13-
let mut srcs: HashMap<PathBuf, &str> = HashMap::new();
11+
let mut asts = HashMap::<PathBuf, Ast>::new();
12+
let mut paths = HashMap::<PathBuf, PathBuf>::new();
13+
let mut srcs = HashMap::<PathBuf, &str>::new();
1414
let mut loaded = Vec::new();
1515

1616
let mut stack = Vec::new();

src/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ mod tests {
12901290
test! {
12911291
name: shell_args_clear,
12921292
args: ["--clear-shell-args"],
1293-
shell_args: Some(vec![]),
1293+
shell_args: Some(Vec::new()),
12941294

12951295
}
12961296

@@ -1304,14 +1304,14 @@ mod tests {
13041304
test! {
13051305
name: shell_args_set_and_clear,
13061306
args: ["--shell-arg", "bar", "--clear-shell-args"],
1307-
shell_args: Some(vec![]),
1307+
shell_args: Some(Vec::new()),
13081308

13091309
}
13101310

13111311
test! {
13121312
name: shell_args_set_multiple_and_clear,
13131313
args: ["--shell-arg", "bar", "--shell-arg", "baz", "--clear-shell-args"],
1314-
shell_args: Some(vec![]),
1314+
shell_args: Some(Vec::new()),
13151315

13161316
}
13171317

src/expression.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,23 @@ impl<'src> Expression<'src> {
5353
impl<'src> Display for Expression<'src> {
5454
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
5555
match self {
56-
Expression::Assert { condition, error } => write!(f, "assert({condition}, {error})"),
57-
Expression::Backtick { token, .. } => write!(f, "{}", token.lexeme()),
58-
Expression::Join { lhs: None, rhs } => write!(f, "/ {rhs}"),
59-
Expression::Join {
56+
Self::Assert { condition, error } => write!(f, "assert({condition}, {error})"),
57+
Self::Backtick { token, .. } => write!(f, "{}", token.lexeme()),
58+
Self::Join { lhs: None, rhs } => write!(f, "/ {rhs}"),
59+
Self::Join {
6060
lhs: Some(lhs),
6161
rhs,
6262
} => write!(f, "{lhs} / {rhs}"),
63-
Expression::Concatenation { lhs, rhs } => write!(f, "{lhs} + {rhs}"),
64-
Expression::Conditional {
63+
Self::Concatenation { lhs, rhs } => write!(f, "{lhs} + {rhs}"),
64+
Self::Conditional {
6565
condition,
6666
then,
6767
otherwise,
6868
} => write!(f, "if {condition} {{ {then} }} else {{ {otherwise} }}"),
69-
Expression::StringLiteral { string_literal } => write!(f, "{string_literal}"),
70-
Expression::Variable { name } => write!(f, "{}", name.lexeme()),
71-
Expression::Call { thunk } => write!(f, "{thunk}"),
72-
Expression::Group { contents } => write!(f, "({contents})"),
69+
Self::StringLiteral { string_literal } => write!(f, "{string_literal}"),
70+
Self::Variable { name } => write!(f, "{}", name.lexeme()),
71+
Self::Call { thunk } => write!(f, "{thunk}"),
72+
Self::Group { contents } => write!(f, "({contents})"),
7373
}
7474
}
7575
}

src/item.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ pub(crate) enum Item<'src> {
2525
impl<'src> Display for Item<'src> {
2626
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
2727
match self {
28-
Item::Alias(alias) => write!(f, "{alias}"),
29-
Item::Assignment(assignment) => write!(f, "{assignment}"),
30-
Item::Comment(comment) => write!(f, "{comment}"),
31-
Item::Import {
28+
Self::Alias(alias) => write!(f, "{alias}"),
29+
Self::Assignment(assignment) => write!(f, "{assignment}"),
30+
Self::Comment(comment) => write!(f, "{comment}"),
31+
Self::Import {
3232
relative, optional, ..
3333
} => {
3434
write!(f, "import")?;
@@ -39,7 +39,7 @@ impl<'src> Display for Item<'src> {
3939

4040
write!(f, " {relative}")
4141
}
42-
Item::Module {
42+
Self::Module {
4343
name,
4444
relative,
4545
optional,
@@ -59,8 +59,8 @@ impl<'src> Display for Item<'src> {
5959

6060
Ok(())
6161
}
62-
Item::Recipe(recipe) => write!(f, "{}", recipe.color_display(Color::never())),
63-
Item::Set(set) => write!(f, "{set}"),
62+
Self::Recipe(recipe) => write!(f, "{}", recipe.color_display(Color::never())),
63+
Self::Set(set) => write!(f, "{set}"),
6464
}
6565
}
6666
}

src/lexer.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ pub(crate) struct Lexer<'src> {
3838
impl<'src> Lexer<'src> {
3939
/// Lex `src`
4040
pub(crate) fn lex(path: &'src Path, src: &'src str) -> CompileResult<'src, Vec<Token<'src>>> {
41-
Lexer::new(path, src).tokenize()
41+
Self::new(path, src).tokenize()
4242
}
4343

4444
#[cfg(test)]
4545
pub(crate) fn test_lex(src: &'src str) -> CompileResult<'src, Vec<Token<'src>>> {
46-
Lexer::new("justfile".as_ref(), src).tokenize()
46+
Self::new("justfile".as_ref(), src).tokenize()
4747
}
4848

4949
/// Create a new Lexer to lex `src`
50-
fn new(path: &'src Path, src: &'src str) -> Lexer<'src> {
50+
fn new(path: &'src Path, src: &'src str) -> Self {
5151
let mut chars = src.chars();
5252
let next = chars.next();
5353

@@ -57,7 +57,7 @@ impl<'src> Lexer<'src> {
5757
line: 0,
5858
};
5959

60-
Lexer {
60+
Self {
6161
indentation: vec![""],
6262
tokens: Vec::new(),
6363
token_start: start,
@@ -282,11 +282,7 @@ impl<'src> Lexer<'src> {
282282

283283
/// True if `c` can be a continuation character of an identifier
284284
fn is_identifier_continue(c: char) -> bool {
285-
if Self::is_identifier_start(c) {
286-
return true;
287-
}
288-
289-
matches!(c, '0'..='9' | '-')
285+
Self::is_identifier_start(c) || matches!(c, '0'..='9' | '-')
290286
}
291287

292288
/// Consume the text and produce a series of tokens
@@ -1028,7 +1024,7 @@ mod tests {
10281024
length,
10291025
path: "justfile".as_ref(),
10301026
},
1031-
kind: Box::new(kind),
1027+
kind: kind.into(),
10321028
};
10331029
assert_eq!(have, want);
10341030
}

src/list.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ pub struct List<T: Display, I: Iterator<Item = T> + Clone> {
66
}
77

88
impl<T: Display, I: Iterator<Item = T> + Clone> List<T, I> {
9-
pub fn or<II: IntoIterator<Item = T, IntoIter = I>>(values: II) -> List<T, I> {
10-
List {
9+
pub fn or<II: IntoIterator<Item = T, IntoIter = I>>(values: II) -> Self {
10+
Self {
1111
conjunction: "or",
1212
values: values.into_iter(),
1313
}
1414
}
1515

16-
pub fn and<II: IntoIterator<Item = T, IntoIter = I>>(values: II) -> List<T, I> {
17-
List {
16+
pub fn and<II: IntoIterator<Item = T, IntoIter = I>>(values: II) -> Self {
17+
Self {
1818
conjunction: "and",
1919
values: values.into_iter(),
2020
}

src/loader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) struct Loader {
77

88
impl Loader {
99
pub(crate) fn new() -> Self {
10-
Loader {
10+
Self {
1111
srcs: Arena::new(),
1212
paths: Arena::new(),
1313
}

src/node.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ impl<'src> Node<'src> for Ast<'src> {
1818
impl<'src> Node<'src> for Item<'src> {
1919
fn tree(&self) -> Tree<'src> {
2020
match self {
21-
Item::Alias(alias) => alias.tree(),
22-
Item::Assignment(assignment) => assignment.tree(),
23-
Item::Comment(comment) => comment.tree(),
24-
Item::Import {
21+
Self::Alias(alias) => alias.tree(),
22+
Self::Assignment(assignment) => assignment.tree(),
23+
Self::Comment(comment) => comment.tree(),
24+
Self::Import {
2525
relative, optional, ..
2626
} => {
2727
let mut tree = Tree::atom("import");
@@ -32,7 +32,7 @@ impl<'src> Node<'src> for Item<'src> {
3232

3333
tree.push(format!("{relative}"))
3434
}
35-
Item::Module {
35+
Self::Module {
3636
name,
3737
optional,
3838
relative,
@@ -52,8 +52,8 @@ impl<'src> Node<'src> for Item<'src> {
5252

5353
tree
5454
}
55-
Item::Recipe(recipe) => recipe.tree(),
56-
Item::Set(set) => set.tree(),
55+
Self::Recipe(recipe) => recipe.tree(),
56+
Self::Set(set) => set.tree(),
5757
}
5858
}
5959
}
@@ -83,16 +83,16 @@ impl<'src> Node<'src> for Assignment<'src> {
8383
impl<'src> Node<'src> for Expression<'src> {
8484
fn tree(&self) -> Tree<'src> {
8585
match self {
86-
Expression::Assert {
86+
Self::Assert {
8787
condition: Condition { lhs, rhs, operator },
8888
error,
8989
} => Tree::atom(Keyword::Assert.lexeme())
9090
.push(lhs.tree())
9191
.push(operator.to_string())
9292
.push(rhs.tree())
9393
.push(error.tree()),
94-
Expression::Concatenation { lhs, rhs } => Tree::atom("+").push(lhs.tree()).push(rhs.tree()),
95-
Expression::Conditional {
94+
Self::Concatenation { lhs, rhs } => Tree::atom("+").push(lhs.tree()).push(rhs.tree()),
95+
Self::Conditional {
9696
condition: Condition { lhs, rhs, operator },
9797
then,
9898
otherwise,
@@ -105,7 +105,7 @@ impl<'src> Node<'src> for Expression<'src> {
105105
tree.push_mut(otherwise.tree());
106106
tree
107107
}
108-
Expression::Call { thunk } => {
108+
Self::Call { thunk } => {
109109
use Thunk::*;
110110

111111
let mut tree = Tree::atom("call");
@@ -158,14 +158,14 @@ impl<'src> Node<'src> for Expression<'src> {
158158

159159
tree
160160
}
161-
Expression::Variable { name } => Tree::atom(name.lexeme()),
162-
Expression::StringLiteral {
161+
Self::Variable { name } => Tree::atom(name.lexeme()),
162+
Self::StringLiteral {
163163
string_literal: StringLiteral { cooked, .. },
164164
} => Tree::string(cooked),
165-
Expression::Backtick { contents, .. } => Tree::atom("backtick").push(Tree::string(contents)),
166-
Expression::Group { contents } => Tree::List(vec![contents.tree()]),
167-
Expression::Join { lhs: None, rhs } => Tree::atom("/").push(rhs.tree()),
168-
Expression::Join {
165+
Self::Backtick { contents, .. } => Tree::atom("backtick").push(Tree::string(contents)),
166+
Self::Group { contents } => Tree::List(vec![contents.tree()]),
167+
Self::Join { lhs: None, rhs } => Tree::atom("/").push(rhs.tree()),
168+
Self::Join {
169169
lhs: Some(lhs),
170170
rhs,
171171
} => Tree::atom("/").push(lhs.tree()).push(rhs.tree()),
@@ -258,8 +258,8 @@ impl<'src> Node<'src> for Line<'src> {
258258
impl<'src> Node<'src> for Fragment<'src> {
259259
fn tree(&self) -> Tree<'src> {
260260
match self {
261-
Fragment::Text { token } => Tree::string(token.lexeme()),
262-
Fragment::Interpolation { expression } => Tree::List(vec![expression.tree()]),
261+
Self::Text { token } => Tree::string(token.lexeme()),
262+
Self::Interpolation { expression } => Tree::List(vec![expression.tree()]),
263263
}
264264
}
265265
}

src/parser.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -479,18 +479,18 @@ impl<'run, 'src> Parser<'run, 'src> {
479479
self.parse_conditional()?
480480
} else if self.accepted(Slash)? {
481481
let lhs = None;
482-
let rhs = Box::new(self.parse_expression()?);
482+
let rhs = self.parse_expression()?.into();
483483
Expression::Join { lhs, rhs }
484484
} else {
485485
let value = self.parse_value()?;
486486

487487
if self.accepted(Slash)? {
488488
let lhs = Some(Box::new(value));
489-
let rhs = Box::new(self.parse_expression()?);
489+
let rhs = self.parse_expression()?.into();
490490
Expression::Join { lhs, rhs }
491491
} else if self.accepted(Plus)? {
492-
let lhs = Box::new(value);
493-
let rhs = Box::new(self.parse_expression()?);
492+
let lhs = value.into();
493+
let rhs = self.parse_expression()?.into();
494494
Expression::Concatenation { lhs, rhs }
495495
} else {
496496
value
@@ -525,8 +525,8 @@ impl<'run, 'src> Parser<'run, 'src> {
525525

526526
Ok(Expression::Conditional {
527527
condition,
528-
then: Box::new(then),
529-
otherwise: Box::new(otherwise),
528+
then: then.into(),
529+
otherwise: otherwise.into(),
530530
})
531531
}
532532

@@ -542,8 +542,8 @@ impl<'run, 'src> Parser<'run, 'src> {
542542
};
543543
let rhs = self.parse_expression()?;
544544
Ok(Condition {
545-
lhs: Box::new(lhs),
546-
rhs: Box::new(rhs),
545+
lhs: lhs.into(),
546+
rhs: rhs.into(),
547547
operator,
548548
})
549549
}
@@ -592,7 +592,7 @@ impl<'run, 'src> Parser<'run, 'src> {
592592
}
593593
} else if self.next_is(ParenL) {
594594
self.presume(ParenL)?;
595-
let contents = Box::new(self.parse_expression()?);
595+
let contents = self.parse_expression()?.into();
596596
self.expect(ParenR)?;
597597
Ok(Expression::Group { contents })
598598
} else {
@@ -1055,7 +1055,7 @@ mod tests {
10551055
length,
10561056
path: "justfile".as_ref(),
10571057
},
1058-
kind: Box::new(kind),
1058+
kind: kind.into(),
10591059
};
10601060
assert_eq!(have, want);
10611061
}

0 commit comments

Comments
 (0)