Skip to content

Commit

Permalink
Upgrade to 2018 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Apr 8, 2019
1 parent 37639d6 commit f7feec0
Show file tree
Hide file tree
Showing 31 changed files with 133 additions and 99 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors = ["Casey Rodarmor <casey@rodarmor.com>"]
license = "CC0-1.0"
homepage = "https://github.com/casey/just"
readme = "crates-io-readme.md"
edition = "2018"

[dependencies]
ansi_term = "0.11"
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ install-dev-deps:

# everyone's favorite animate paper clip
clippy:
cargo +nightly clippy
cargo clippy

# count non-empty lines of code
sloc:
Expand Down
5 changes: 2 additions & 3 deletions src/assignment_evaluator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

use brev;

Expand Down Expand Up @@ -164,9 +164,8 @@ impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
#[cfg(test)]
mod test {
use super::*;
use crate::testing::parse_success;
use brev::OutputError;
use testing::parse_success;
use Configuration;

fn no_cwd_err() -> Result<PathBuf, String> {
Err(String::from("no cwd in tests"))
Expand Down
4 changes: 2 additions & 2 deletions src/assignment_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use common::*;
use crate::common::*;

use CompilationErrorKind::*;
use crate::CompilationErrorKind::*;

pub struct AssignmentResolver<'a: 'b, 'b> {
assignments: &'b Map<&'a str, Expression<'a>>,
Expand Down
2 changes: 1 addition & 1 deletion src/color.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate ansi_term;
extern crate atty;

use common::*;
use crate::common::*;

use self::ansi_term::Color::*;
use self::ansi_term::{ANSIGenericString, Prefix, Style, Suffix};
Expand Down
2 changes: 1 addition & 1 deletion src/command_ext.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

pub trait CommandExt {
fn export_environment_variables<'a>(
Expand Down
86 changes: 50 additions & 36 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
pub use std::borrow::Cow;
pub use std::collections::{BTreeMap as Map, BTreeSet as Set};
pub use std::fmt::Display;
pub use std::io::prelude::*;
pub use std::ops::Range;
pub use std::path::{Path, PathBuf};
pub use std::process::Command;
pub use std::sync::{Mutex, MutexGuard};
pub use std::{cmp, env, fmt, fs, io, iter, process, usize, vec};
pub(crate) use std::{
borrow::Cow,
cmp,
collections::{BTreeMap as Map, BTreeSet as Set},
env, fmt,
fmt::Display,
fs, io, iter,
ops::{Range, RangeInclusive},
path::{Path, PathBuf},
process,
process::Command,
sync::{Mutex, MutexGuard},
usize, vec,
};

pub use color::Color;
pub use libc::{EXIT_FAILURE, EXIT_SUCCESS};
pub use regex::Regex;
pub use tempdir::TempDir;
pub(crate) use crate::color::Color;
pub(crate) use libc::{EXIT_FAILURE, EXIT_SUCCESS};
pub(crate) use regex::Regex;
pub(crate) use tempdir::TempDir;

pub use assignment_evaluator::AssignmentEvaluator;
pub use assignment_resolver::AssignmentResolver;
pub use command_ext::CommandExt;
pub use compilation_error::{CompilationError, CompilationErrorKind, CompilationResult};
pub use configuration::Configuration;
pub use cooked_string::CookedString;
pub use expression::Expression;
pub use fragment::Fragment;
pub use function::{evaluate_function, resolve_function, FunctionContext};
pub use interrupt_handler::InterruptHandler;
pub use justfile::Justfile;
pub use lexer::Lexer;
pub use load_dotenv::load_dotenv;
pub use misc::{default, empty};
pub use parameter::Parameter;
pub use parser::Parser;
pub use range_ext::RangeExt;
pub use recipe::{Recipe, RecipeContext};
pub use recipe_resolver::RecipeResolver;
pub use runtime_error::{RunResult, RuntimeError};
pub use shebang::Shebang;
pub use token::{Token, TokenKind};
pub use verbosity::Verbosity;
pub(crate) use crate::{
assignment_evaluator::AssignmentEvaluator,
assignment_resolver::AssignmentResolver,
compilation_error::{CompilationError, CompilationErrorKind, CompilationResult},
configuration::Configuration,
cooked_string::CookedString,
expression::Expression,
fragment::Fragment,
function::{evaluate_function, resolve_function, FunctionContext},
interrupt_handler::InterruptHandler,
justfile::Justfile,
lexer::Lexer,
load_dotenv::load_dotenv,
misc::{default, empty},
parameter::Parameter,
parser::Parser,
recipe::{Recipe, RecipeContext},
recipe_resolver::RecipeResolver,
runtime_error::{RunResult, RuntimeError},
shebang::Shebang,
token::{Token, TokenKind},
verbosity::Verbosity,
};

#[allow(unused_imports)]
pub(crate) use std::io::prelude::*;

#[allow(unused_imports)]
pub(crate) use crate::command_ext::CommandExt;

#[allow(unused_imports)]
pub(crate) use crate::range_ext::RangeExt;
6 changes: 3 additions & 3 deletions src/compilation_error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use common::*;
use crate::common::*;

use misc::{maybe_s, show_whitespace, write_error_context, Or};
use crate::misc::{maybe_s, show_whitespace, write_error_context, Or};

pub type CompilationResult<'a, T> = Result<T, CompilationError<'a>>;

Expand Down Expand Up @@ -92,7 +92,7 @@ pub enum CompilationErrorKind<'a> {

impl<'a> Display for CompilationError<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use CompilationErrorKind::*;
use crate::CompilationErrorKind::*;
let error = Color::fmt(f).error();
let message = Color::fmt(f).message();

Expand Down
2 changes: 1 addition & 1 deletion src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

pub const DEFAULT_SHELL: &str = "sh";

Expand Down
2 changes: 1 addition & 1 deletion src/cooked_string.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

#[derive(PartialEq, Debug)]
pub struct CookedString<'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/expression.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

#[derive(PartialEq, Debug)]
pub enum Expression<'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/fragment.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

#[derive(PartialEq, Debug)]
pub enum Fragment<'a> {
Expand Down
4 changes: 2 additions & 2 deletions src/function.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use common::*;
use crate::common::*;

use target;

use platform::{Platform, PlatformInterface};
use crate::platform::{Platform, PlatformInterface};

lazy_static! {
static ref FUNCTIONS: Map<&'static str, Function> = vec![
Expand Down
2 changes: 1 addition & 1 deletion src/interrupt_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

use ctrlc;

Expand Down
6 changes: 3 additions & 3 deletions src/justfile.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

use edit_distance::edit_distance;

Expand Down Expand Up @@ -186,8 +186,8 @@ impl<'a> Display for Justfile<'a> {
#[cfg(test)]
mod test {
use super::*;
use testing::parse_success;
use RuntimeError::*;
use crate::testing::parse_success;
use crate::RuntimeError::*;

fn no_cwd_err() -> Result<PathBuf, String> {
Err(String::from("no cwd in tests"))
Expand Down
10 changes: 5 additions & 5 deletions src/lexer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use common::*;
use crate::common::*;

use CompilationErrorKind::*;
use TokenKind::*;
use crate::CompilationErrorKind::*;
use crate::TokenKind::*;

fn re(pattern: &str) -> Regex {
Regex::new(pattern).unwrap()
Expand Down Expand Up @@ -321,7 +321,7 @@ impl<'a> Lexer<'a> {
if escape || content_end >= self.rest.len() {
return Err(self.error(UnterminatedString));
}
(prefix, &self.rest[start..content_end + 1], StringToken)
(prefix, &self.rest[start..=content_end], StringToken)
} else {
return Err(self.error(UnknownStartOfToken));
};
Expand Down Expand Up @@ -383,7 +383,7 @@ mod test {
fn $name() {
let input = $input;
let expected = $expected;
let tokens = ::Lexer::lex(input).unwrap();
let tokens = crate::Lexer::lex(input).unwrap();
let roundtrip = tokens
.iter()
.map(|t| {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ mod shebang;
mod token;
mod verbosity;

use common::*;
use crate::common::*;

pub use run::run;
pub use crate::run::run;
2 changes: 1 addition & 1 deletion src/load_dotenv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

use dotenv;

Expand Down
2 changes: 1 addition & 1 deletion src/misc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

use unicode_width::UnicodeWidthChar;

Expand Down
2 changes: 1 addition & 1 deletion src/parameter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

#[derive(PartialEq, Debug)]
pub struct Parameter<'a> {
Expand Down
8 changes: 4 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use common::*;
use crate::common::*;

use itertools;
use CompilationErrorKind::*;
use TokenKind::*;
use crate::CompilationErrorKind::*;
use crate::TokenKind::*;

pub struct Parser<'a> {
text: &'a str,
Expand Down Expand Up @@ -449,7 +449,7 @@ impl<'a> Parser<'a> {
mod test {
use super::*;
use brev;
use testing::parse_success;
use crate::testing::parse_success;

macro_rules! summary_test {
($name:ident, $input:expr, $expected:expr $(,)*) => {
Expand Down
2 changes: 1 addition & 1 deletion src/platform.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

use brev;

Expand Down
22 changes: 20 additions & 2 deletions src/range_ext.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use common::*;
use crate::common::*;

pub trait RangeExt<T> {
fn range_contains(&self, i: T) -> bool;
Expand All @@ -13,16 +13,34 @@ where
}
}

impl<T> RangeExt<T> for RangeInclusive<T>
where
T: PartialOrd + Copy,
{
fn range_contains(&self, i: T) -> bool {
i >= *self.start() && i <= *self.end()
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn range() {
fn exclusive() {
assert!((0..1).range_contains(0));
assert!((10..20).range_contains(15));
assert!(!(0..0).range_contains(0));
assert!(!(1..10).range_contains(0));
assert!(!(1..10).range_contains(10));
}

#[test]
fn inclusive() {
assert!((0..=1).range_contains(0));
assert!((10..=20).range_contains(15));
assert!((0..=0).range_contains(0));
assert!(!(1..=10).range_contains(0));
assert!((1..=10).range_contains(10));
}
}
Loading

0 comments on commit f7feec0

Please sign in to comment.