Skip to content

Commit 80725b8

Browse files
committed
Update Rust imports to match style guide
1 parent 424dc63 commit 80725b8

13 files changed

Lines changed: 236 additions & 286 deletions

src/assertions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ macro_rules! assert_same {
5858

5959
#[cfg(test)]
6060
mod tests {
61-
use {crate::error::Error, std::fmt::Write};
61+
use crate::error::Error;
62+
use std::fmt::Write;
6263

6364
#[test]
6465
#[should_panic(expected = "The expression was supposed to fail, but it succeeded.")]

src/de_bruijn.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
use {
2-
crate::term::{
3-
Term,
4-
Variant::{
5-
Application, Boolean, Difference, EqualTo, False, GreaterThan, GreaterThanOrEqualTo,
6-
If, Integer, IntegerLiteral, Lambda, LessThan, LessThanOrEqualTo, Let, Negation, Pi,
7-
Product, Quotient, Sum, True, Type, Unifier, Variable,
8-
},
1+
use crate::term::{
2+
Term,
3+
Variant::{
4+
Application, Boolean, Difference, EqualTo, False, GreaterThan, GreaterThanOrEqualTo, If,
5+
Integer, IntegerLiteral, Lambda, LessThan, LessThanOrEqualTo, Let, Negation, Pi, Product,
6+
Quotient, Sum, True, Type, Unifier, Variable,
97
},
10-
std::{cell::RefCell, convert::TryFrom, rc::Rc},
118
};
9+
use std::{cell::RefCell, convert::TryFrom, rc::Rc};
1210

1311
// Shifting refers to adjusting the De Bruijn indices of free variables. A cutoff determines which
1412
// variables are considered free. This function is used to raise or lower a term into a different
@@ -429,23 +427,21 @@ pub fn open<'a>(
429427

430428
#[cfg(test)]
431429
mod tests {
432-
use {
433-
crate::{
434-
assert_same,
435-
de_bruijn::{open, signed_shift, unsigned_shift},
436-
term::{
437-
Term,
438-
Variant::{
439-
Application, Boolean, Difference, EqualTo, False, GreaterThan,
440-
GreaterThanOrEqualTo, If, Integer, IntegerLiteral, Lambda, LessThan,
441-
LessThanOrEqualTo, Let, Negation, Pi, Product, Quotient, Sum, True, Type,
442-
Unifier, Variable,
443-
},
430+
use crate::{
431+
assert_same,
432+
de_bruijn::{open, signed_shift, unsigned_shift},
433+
term::{
434+
Term,
435+
Variant::{
436+
Application, Boolean, Difference, EqualTo, False, GreaterThan,
437+
GreaterThanOrEqualTo, If, Integer, IntegerLiteral, Lambda, LessThan,
438+
LessThanOrEqualTo, Let, Negation, Pi, Product, Quotient, Sum, True, Type, Unifier,
439+
Variable,
444440
},
445441
},
446-
num_bigint::ToBigInt,
447-
std::{cell::RefCell, rc::Rc},
448442
};
443+
use num_bigint::ToBigInt;
444+
use std::{cell::RefCell, rc::Rc};
449445

450446
#[test]
451447
fn signed_shift_unifier_none_valid() {

src/equality.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
use {
2-
crate::{
3-
de_bruijn::unsigned_shift,
4-
term::{
5-
Term,
6-
Variant::{
7-
Application, Boolean, Difference, EqualTo, False, GreaterThan,
8-
GreaterThanOrEqualTo, If, Integer, IntegerLiteral, Lambda, LessThan,
9-
LessThanOrEqualTo, Let, Negation, Pi, Product, Quotient, Sum, True, Type, Unifier,
10-
Variable,
11-
},
1+
use crate::{
2+
de_bruijn::unsigned_shift,
3+
term::{
4+
Term,
5+
Variant::{
6+
Application, Boolean, Difference, EqualTo, False, GreaterThan, GreaterThanOrEqualTo,
7+
If, Integer, IntegerLiteral, Lambda, LessThan, LessThanOrEqualTo, Let, Negation, Pi,
8+
Product, Quotient, Sum, True, Type, Unifier, Variable,
129
},
1310
},
14-
std::rc::Rc,
1511
};
12+
use std::rc::Rc;
1613

1714
// Check if two terms are equal up to alpha conversion. Type annotations are not checked.
1815
#[allow(clippy::similar_names)]
@@ -154,18 +151,16 @@ pub fn syntactically_equal<'a>(term1: &Term<'a>, term2: &Term<'a>) -> bool {
154151

155152
#[cfg(test)]
156153
mod tests {
157-
use {
158-
crate::{
159-
equality::syntactically_equal,
160-
parser::parse,
161-
term::{
162-
Term,
163-
Variant::{Unifier, Variable},
164-
},
165-
tokenizer::tokenize,
154+
use crate::{
155+
equality::syntactically_equal,
156+
parser::parse,
157+
term::{
158+
Term,
159+
Variant::{Unifier, Variable},
166160
},
167-
std::{cell::RefCell, rc::Rc},
161+
tokenizer::tokenize,
168162
};
163+
use std::{cell::RefCell, rc::Rc};
169164

170165
#[test]
171166
fn syntactically_equal_unifier_left() {

src/error.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
use {
2-
crate::format::CodeStr,
3-
colored::{Colorize, control::SHOULD_COLORIZE},
4-
pad::{Alignment, PadStr},
5-
std::{
6-
cmp::{max, min},
7-
error, fmt,
8-
path::Path,
9-
rc::Rc,
10-
},
1+
use crate::format::CodeStr;
2+
use colored::{Colorize, control::SHOULD_COLORIZE};
3+
use pad::{Alignment, PadStr};
4+
use std::{
5+
cmp::{max, min},
6+
error, fmt,
7+
path::Path,
8+
rc::Rc,
119
};
1210

1311
// This is the primary error type we'll be using everywhere.
@@ -207,13 +205,11 @@ pub fn listing(source_contents: &str, source_range: SourceRange) -> String {
207205

208206
#[cfg(test)]
209207
mod tests {
210-
use {
211-
crate::{
212-
assert_same,
213-
error::{Error, SourceRange, listing, throw},
214-
},
215-
std::{path::Path, rc::Rc},
208+
use crate::{
209+
assert_same,
210+
error::{Error, SourceRange, listing, throw},
216211
};
212+
use std::{path::Path, rc::Rc};
217213

218214
#[test]
219215
fn error_no_reason_display() {

src/evaluator.rs

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
use {
2-
crate::{
3-
de_bruijn::{open, unsigned_shift},
4-
error::Error,
5-
format::CodeStr,
6-
term::{
7-
Term,
8-
Variant::{
9-
Application, Boolean, Difference, EqualTo, False, GreaterThan,
10-
GreaterThanOrEqualTo, If, Integer, IntegerLiteral, Lambda, LessThan,
11-
LessThanOrEqualTo, Let, Negation, Pi, Product, Quotient, Sum, True, Type, Unifier,
12-
Variable,
13-
},
1+
use crate::{
2+
de_bruijn::{open, unsigned_shift},
3+
error::Error,
4+
format::CodeStr,
5+
term::{
6+
Term,
7+
Variant::{
8+
Application, Boolean, Difference, EqualTo, False, GreaterThan, GreaterThanOrEqualTo,
9+
If, Integer, IntegerLiteral, Lambda, LessThan, LessThanOrEqualTo, Let, Negation, Pi,
10+
Product, Quotient, Sum, True, Type, Unifier, Variable,
1411
},
1512
},
16-
std::{iter::once, rc::Rc},
1713
};
14+
use std::{iter::once, rc::Rc};
1815

1916
// This function evaluates a term using a call-by-value strategy.
2017
pub fn evaluate<'a>(term: &Term<'a>) -> Result<Term<'a>, Error> {
@@ -636,24 +633,22 @@ pub fn is_value(term: &Term) -> bool {
636633

637634
#[cfg(test)]
638635
mod tests {
639-
use {
640-
crate::{
641-
assert_same,
642-
error::SourceRange,
643-
evaluator::evaluate,
644-
parser::parse,
645-
term::{
646-
Term,
647-
Variant::{
648-
Application, Boolean, False, Integer, IntegerLiteral, Lambda, Pi, True, Type,
649-
Variable,
650-
},
636+
use crate::{
637+
assert_same,
638+
error::SourceRange,
639+
evaluator::evaluate,
640+
parser::parse,
641+
term::{
642+
Term,
643+
Variant::{
644+
Application, Boolean, False, Integer, IntegerLiteral, Lambda, Pi, True, Type,
645+
Variable,
651646
},
652-
tokenizer::tokenize,
653647
},
654-
num_bigint::ToBigInt,
655-
std::rc::Rc,
648+
tokenizer::tokenize,
656649
};
650+
use num_bigint::ToBigInt;
651+
use std::rc::Rc;
657652

658653
#[test]
659654
fn evaluate_type() {

src/main.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@ mod tokenizer;
1212
mod type_checker;
1313
mod unifier;
1414

15-
use {
16-
crate::{
17-
error::{Error, throw},
18-
evaluator::evaluate,
19-
format::CodeStr,
20-
parser::parse,
21-
tokenizer::tokenize,
22-
type_checker::type_check,
23-
},
24-
clap::{ArgAction, Args, CommandFactory, Parser, Subcommand as ClapSubcommand},
25-
clap_complete::{Shell, generate},
26-
std::{fs::read_to_string, io::stdout, path::Path, process::exit, thread},
15+
use crate::{
16+
error::{Error, throw},
17+
evaluator::evaluate,
18+
format::CodeStr,
19+
parser::parse,
20+
tokenizer::tokenize,
21+
type_checker::type_check,
2722
};
23+
use clap::{ArgAction, Args, CommandFactory, Parser, Subcommand as ClapSubcommand};
24+
use clap_complete::{Shell, generate};
25+
use std::{fs::read_to_string, io::stdout, path::Path, process::exit, thread};
2826

2927
// The name of the program binary
3028
const BIN_NAME: &str = "gram";

src/normalizer.rs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
use {
2-
crate::{
3-
de_bruijn::{open, unsigned_shift},
4-
term::{
5-
Term,
6-
Variant::{
7-
Application, Boolean, Difference, EqualTo, False, GreaterThan,
8-
GreaterThanOrEqualTo, If, Integer, IntegerLiteral, Lambda, LessThan,
9-
LessThanOrEqualTo, Let, Negation, Pi, Product, Quotient, Sum, True, Type, Unifier,
10-
Variable,
11-
},
1+
use crate::{
2+
de_bruijn::{open, unsigned_shift},
3+
term::{
4+
Term,
5+
Variant::{
6+
Application, Boolean, Difference, EqualTo, False, GreaterThan, GreaterThanOrEqualTo,
7+
If, Integer, IntegerLiteral, Lambda, LessThan, LessThanOrEqualTo, Let, Negation, Pi,
8+
Product, Quotient, Sum, True, Type, Unifier, Variable,
129
},
1310
},
14-
std::rc::Rc,
1511
};
12+
use std::rc::Rc;
1613

1714
// This function reduces a term to weak head normal form using normal order reduction. Invariant:
1815
// when this function is finished, the context is left unmodified.
@@ -412,24 +409,22 @@ pub fn normalize_weak_head<'a>(
412409

413410
#[cfg(test)]
414411
mod tests {
415-
use {
416-
crate::{
417-
assert_same,
418-
error::SourceRange,
419-
normalizer::normalize_weak_head,
420-
parser::parse,
421-
term::{
422-
Term,
423-
Variant::{
424-
Application, Boolean, False, Integer, IntegerLiteral, Lambda, Pi, True, Type,
425-
Variable,
426-
},
412+
use crate::{
413+
assert_same,
414+
error::SourceRange,
415+
normalizer::normalize_weak_head,
416+
parser::parse,
417+
term::{
418+
Term,
419+
Variant::{
420+
Application, Boolean, False, Integer, IntegerLiteral, Lambda, Pi, True, Type,
421+
Variable,
427422
},
428-
tokenizer::tokenize,
429423
},
430-
num_bigint::ToBigInt,
431-
std::rc::Rc,
424+
tokenizer::tokenize,
432425
};
426+
use num_bigint::ToBigInt;
427+
use std::rc::Rc;
433428

434429
#[test]
435430
fn normalize_weak_head_type() {

0 commit comments

Comments
 (0)