From c4383adbfd0b0ce62c44a14f73c7318fdb9b94de Mon Sep 17 00:00:00 2001 From: Xavier L'Heureux <xavier.lheureux@icloud.com> Date: Sun, 17 Feb 2019 22:31:26 -0500 Subject: [PATCH] Switch to Rust 1.30.0 This is one step closer toward 1.32.0, where the 2018 edition is stable. Mostly refactoring the imports and giving function parameters name in traits --- .gitlab-ci.yml | 2 +- Makefile | 2 +- README.md | 6 +++--- src/lib/builtins/command_info.rs | 9 +++++---- src/lib/builtins/exec.rs | 8 +++++--- src/lib/builtins/exists.rs | 12 ++++++----- src/lib/builtins/functions.rs | 2 +- src/lib/builtins/is.rs | 5 ++--- src/lib/builtins/job_control.rs | 2 +- src/lib/builtins/mod.rs | 19 +++++++++--------- src/lib/builtins/set.rs | 6 ++++-- src/lib/builtins/source.rs | 2 +- src/lib/builtins/status.rs | 3 +-- src/lib/builtins/variables.rs | 14 ++++++++----- src/lib/lib.rs | 2 +- src/lib/parser/assignments/actions.rs | 4 ++-- src/lib/parser/assignments/checker.rs | 10 ++++++---- src/lib/parser/loops.rs | 8 +++++--- src/lib/parser/pipelines/collector.rs | 18 ++++++++++------- src/lib/parser/pipelines/mod.rs | 2 +- src/lib/parser/shell_expand/mod.rs | 20 ++++++++++--------- .../shell_expand/words/methods/arrays.rs | 9 +++++---- .../parser/shell_expand/words/methods/mod.rs | 2 +- .../shell_expand/words/methods/strings.rs | 4 ++-- src/lib/parser/shell_expand/words/mod.rs | 5 ++--- src/lib/parser/shell_expand/words/tests.rs | 6 ++++-- src/lib/parser/statement/case.rs | 2 +- src/lib/parser/statement/functions.rs | 8 +++++--- src/lib/parser/statement/mod.rs | 2 +- src/lib/parser/statement/parse.rs | 16 +++++++++------ src/lib/shell/assignments.rs | 14 +++++++------ src/lib/shell/binary/designators.rs | 6 ++++-- src/lib/shell/binary/mod.rs | 2 +- src/lib/shell/binary/prompt.rs | 8 +++++--- src/lib/shell/binary/readln.rs | 3 +-- src/lib/shell/binary/terminate.rs | 6 ++++-- src/lib/shell/directory_stack.rs | 2 +- src/lib/shell/flow.rs | 18 +++++++++-------- src/lib/shell/flow_control.rs | 10 ++++++---- src/lib/shell/fork.rs | 2 +- src/lib/shell/fork_function.rs | 6 ++++-- src/lib/shell/history.rs | 4 ++-- src/lib/shell/job.rs | 10 ++++++---- src/lib/shell/mod.rs | 16 ++++++++------- src/lib/shell/pipe_exec/fork.rs | 2 +- src/lib/shell/pipe_exec/job_control.rs | 4 ++-- src/lib/shell/pipe_exec/mod.rs | 8 +++++--- src/lib/shell/pipe_exec/pipes.rs | 2 +- src/lib/shell/pipe_exec/streams.rs | 2 +- src/lib/shell/signals.rs | 4 ++-- src/lib/shell/variables/mod.rs | 10 ++++++---- src/lib/types.rs | 2 +- 52 files changed, 200 insertions(+), 151 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 73d4c8e6..350d22c5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,7 @@ cache: - target/ linux: - image: 'rust:1.28.0' + image: 'rust:1.30.0' script: - cargo build - make tests diff --git a/Makefile b/Makefile index 5229439e..880eb573 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ RELEASE = debug DEBUG ?= 0 VENDORED = 0 REDOX ?= 0 -TOOLCHAIN ?= 1.28.0 +TOOLCHAIN ?= 1.30.0 GIT_REVISION=git_revision.txt SRC=Cargo.toml src/* src/*/* members/* members/*/* diff --git a/README.md b/README.md index 29a282da..b0709aba 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ with **mdbook**. ## Pop!\_OS / Ubuntu -The following PPA supports the 18.04 (bionic) and 18.10 (cosmic) releases. Bionic builds were made using the Pop\_OS PPA's rustc 1.28.0 package. +The following PPA supports the 18.04 (bionic) and 18.10 (cosmic) releases. Bionic builds were made using the Pop\_OS PPA's rustc 1.30.0 package. ``` sudo add-apt-repository ppa:mmstick76/ion-shell @@ -41,11 +41,11 @@ sudo add-apt-repository ppa:mmstick76/ion-shell # Build dependencies Those who are developing software with Rust should install the [Rustup toolchain manager](https://rustup.rs/). -After installing rustup, run `rustup default 1.28.0` to set your Rust toolchain to the version that Ion is +After installing rustup, run `rustup default 1.30.0` to set your Rust toolchain to the version that Ion is targeting at the moment. To build for Redox OS, `rustup default nightly` is required to build the Redox dependencies. -> Distribution packagers must ensure that their distribution has packaged both cargo and rustc 1.28.0. +> Distribution packagers must ensure that their distribution has packaged both cargo and rustc 1.30.0. > Distribution packagers should also currently build Ion from git. Release tarballs have not been made yet > due to the shell being incomplete in a few remaining areas. diff --git a/src/lib/builtins/command_info.rs b/src/lib/builtins/command_info.rs index 992c12b6..e5237d47 100644 --- a/src/lib/builtins/command_info.rs +++ b/src/lib/builtins/command_info.rs @@ -1,8 +1,9 @@ -use builtins::man_pages::*; -use shell::{flow_control::Function, status::*, Shell}; +use crate::{ + builtins::man_pages::*, + shell::{flow_control::Function, status::*, Shell}, + sys, types, +}; use small; -use sys; -use types; use std::{borrow::Cow, env, path::Path}; diff --git a/src/lib/builtins/exec.rs b/src/lib/builtins/exec.rs index 100c9d8a..c813b985 100644 --- a/src/lib/builtins/exec.rs +++ b/src/lib/builtins/exec.rs @@ -1,8 +1,10 @@ -use builtins::man_pages::{check_help, MAN_EXEC}; -use shell::Shell; +use crate::{ + builtins::man_pages::{check_help, MAN_EXEC}, + shell::Shell, + sys::execve, +}; use small; use std::error::Error; -use sys::execve; /// Executes the givent commmand. pub(crate) fn exec(shell: &mut Shell, args: &[small::String]) -> Result<(), small::String> { diff --git a/src/lib/builtins/exists.rs b/src/lib/builtins/exists.rs index e3b82572..1f21ea34 100644 --- a/src/lib/builtins/exists.rs +++ b/src/lib/builtins/exists.rs @@ -1,10 +1,12 @@ use std::{fs, os::unix::fs::PermissionsExt}; #[cfg(test)] -use shell::{self, flow_control::Statement}; -use shell::{flow_control::Function, Shell}; +use crate::shell::{self, flow_control::Statement}; +use crate::{ + shell::{flow_control::Function, Shell}, + types, +}; use small; -use types; pub(crate) fn exists(args: &[small::String], shell: &Shell) -> Result<bool, small::String> { let arguments = &args[1..]; @@ -138,7 +140,7 @@ fn function_is_defined(function: &str, shell: &Shell) -> bool { #[test] fn test_evaluate_arguments() { - use lexers::assignments::{KeyBuf, Primitive}; + use crate::lexers::assignments::{KeyBuf, Primitive}; let mut shell = shell::ShellBuilder::new().as_library(); // assert_eq!(evaluate_arguments(&[], &mut sink, &shell), Ok(false)); @@ -348,7 +350,7 @@ fn test_string_var_is_not_empty() { #[test] fn test_function_is_defined() { - use lexers::assignments::{KeyBuf, Primitive}; + use crate::lexers::assignments::{KeyBuf, Primitive}; let mut shell = shell::ShellBuilder::new().as_library(); // create a simple dummy function diff --git a/src/lib/builtins/functions.rs b/src/lib/builtins/functions.rs index 63a832e2..7b59e435 100644 --- a/src/lib/builtins/functions.rs +++ b/src/lib/builtins/functions.rs @@ -1,4 +1,4 @@ -use shell::{status::*, variables::Variables}; +use crate::shell::{status::*, variables::Variables}; use std::io::{self, Write}; fn print_functions(vars: &Variables) { diff --git a/src/lib/builtins/is.rs b/src/lib/builtins/is.rs index 680826fa..fae2ea4e 100644 --- a/src/lib/builtins/is.rs +++ b/src/lib/builtins/is.rs @@ -1,6 +1,5 @@ -use shell::Shell; +use crate::{shell::Shell, types}; use small; -use types; pub(crate) fn is(args: &[small::String], shell: &mut Shell) -> Result<(), String> { match args.len() { @@ -47,7 +46,7 @@ fn test_is() { fn vec_string(args: &[&str]) -> Vec<small::String> { args.iter().map(|s| (*s).into()).collect() } - use shell::ShellBuilder; + use crate::shell::ShellBuilder; let mut shell = ShellBuilder::new().as_library(); shell.set("x", "value"); shell.set("y", "0"); diff --git a/src/lib/builtins/job_control.rs b/src/lib/builtins/job_control.rs index 0fa7425c..8f9768de 100644 --- a/src/lib/builtins/job_control.rs +++ b/src/lib/builtins/job_control.rs @@ -1,7 +1,7 @@ //! Contains the `jobs`, `disown`, `bg`, and `fg` commands that manage job //! control in the shell. -use shell::{ +use crate::shell::{ job_control::{JobControl, ProcessState}, signals, status::*, diff --git a/src/lib/builtins/mod.rs b/src/lib/builtins/mod.rs index 1989df67..09d9748d 100644 --- a/src/lib/builtins/mod.rs +++ b/src/lib/builtins/mod.rs @@ -32,17 +32,18 @@ use std::{ io::{self, Write}, }; -use parser::Terminator; -use shell::{ - self, - fork_function::fork_function, - job_control::{JobControl, ProcessState}, - status::*, - FlowLogic, Shell, ShellHistory, +use crate::{ + parser::Terminator, + shell::{ + self, + fork_function::fork_function, + job_control::{JobControl, ProcessState}, + status::*, + FlowLogic, Shell, ShellHistory, + }, + sys, types, }; use small; -use sys; -use types; const HELP_DESC: &str = "Display helpful information about a given command or list commands if \ none specified\n help <command>"; diff --git a/src/lib/builtins/set.rs b/src/lib/builtins/set.rs index 6ffdb735..36faf6aa 100644 --- a/src/lib/builtins/set.rs +++ b/src/lib/builtins/set.rs @@ -1,8 +1,10 @@ +use crate::{ + shell::{flags::*, Shell}, + types, +}; use liner::KeyBindings; -use shell::{flags::*, Shell}; use small; use std::iter; -use types; enum PositionalArgs { UnsetIfNone, diff --git a/src/lib/builtins/source.rs b/src/lib/builtins/source.rs index 650e8c18..a77388db 100644 --- a/src/lib/builtins/source.rs +++ b/src/lib/builtins/source.rs @@ -1,4 +1,4 @@ -use shell::{FlowLogic, Shell}; +use crate::shell::{FlowLogic, Shell}; use small; use std::{fs::File, io::Read}; diff --git a/src/lib/builtins/status.rs b/src/lib/builtins/status.rs index ba4b6834..11879d3a 100644 --- a/src/lib/builtins/status.rs +++ b/src/lib/builtins/status.rs @@ -1,5 +1,4 @@ -use builtins::man_pages::MAN_STATUS; -use shell::Shell; +use crate::{builtins::man_pages::MAN_STATUS, shell::Shell}; use small; use std::env; diff --git a/src/lib/builtins/variables.rs b/src/lib/builtins/variables.rs index 7018ff7f..77d9c7b3 100644 --- a/src/lib/builtins/variables.rs +++ b/src/lib/builtins/variables.rs @@ -2,8 +2,10 @@ use std::io::{self, Write}; -use shell::{status::*, variables::Variables}; -use types; +use crate::{ + shell::{status::*, variables::Variables}, + types, +}; fn print_list(vars: &Variables) { let stdout = io::stdout(); @@ -141,9 +143,11 @@ pub(crate) fn drop_variable<S: AsRef<str>>(vars: &mut Variables, args: &[S]) -> #[cfg(test)] mod test { use super::*; - use parser::{expand_string, Expander}; - use shell::status::{FAILURE, SUCCESS}; - use types::Array; + use crate::{ + parser::{expand_string, Expander}, + shell::status::{FAILURE, SUCCESS}, + types::Array, + }; struct VariableExpander(pub Variables); diff --git a/src/lib/lib.rs b/src/lib/lib.rs index 1d63a2ad..509d25d5 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -33,7 +33,7 @@ mod ascii_helpers; mod builtins; pub mod shell; -pub use shell::{ +pub use crate::shell::{ binary::MAN_ION, flags, pipe_exec::job_control::JobControl, status, Binary, Capture, Fork, IonError, IonResult, Shell, ShellBuilder, }; diff --git a/src/lib/parser/assignments/actions.rs b/src/lib/parser/assignments/actions.rs index 5c386413..88ab7b69 100644 --- a/src/lib/parser/assignments/actions.rs +++ b/src/lib/parser/assignments/actions.rs @@ -1,5 +1,5 @@ use super::checker::*; -use lexers::{ +use crate::lexers::{ assignments::{Key, KeyIterator, Operator, Primitive, TypeError}, ArgumentSplitter, }; @@ -152,7 +152,7 @@ impl<'a> Action<'a> { #[cfg(test)] mod tests { use super::*; - use lexers::assignments::*; + use crate::lexers::assignments::*; fn split(input: &str) -> (String, Operator, String) { let (keys, op, vals) = assignment_lexer(input); diff --git a/src/lib/parser/assignments/checker.rs b/src/lib/parser/assignments/checker.rs index 7165bb18..682914f4 100644 --- a/src/lib/parser/assignments/checker.rs +++ b/src/lib/parser/assignments/checker.rs @@ -1,8 +1,10 @@ use super::super::{expand_string, Expander}; -use lexers::assignments::{Primitive, TypeError}; -use shell::variables::VariableType; +use crate::{ + lexers::assignments::{Primitive, TypeError}, + shell::variables::VariableType, + types, +}; use std::iter::Iterator; -use types; #[derive(PartialEq, Clone, Copy, Debug)] enum IsArrayHelper { @@ -280,7 +282,7 @@ pub(crate) fn value_check<E: Expander>( #[cfg(test)] mod test { use super::*; - use types::Array; + use crate::types::Array; #[test] fn is_array_() { diff --git a/src/lib/parser/loops.rs b/src/lib/parser/loops.rs index a2f06884..2357e3b7 100644 --- a/src/lib/parser/loops.rs +++ b/src/lib/parser/loops.rs @@ -1,5 +1,7 @@ -use parser::{expand_string, Expander}; -use types; +use crate::{ + parser::{expand_string, Expander}, + types, +}; /// The expression given to a for loop as the value to iterate upon. pub(crate) enum ForValueExpression { @@ -17,7 +19,7 @@ impl ForValueExpression { if output.len() == 1 { let output = output.into_iter().next().unwrap(); - if let Some(range) = ::ranges::parse_range(&output) { + if let Some(range) = crate::ranges::parse_range(&output) { return ForValueExpression::Range(range); } diff --git a/src/lib/parser/pipelines/collector.rs b/src/lib/parser/pipelines/collector.rs index a1c28c6f..bc020a4f 100644 --- a/src/lib/parser/pipelines/collector.rs +++ b/src/lib/parser/pipelines/collector.rs @@ -1,8 +1,10 @@ use std::{collections::HashSet, iter::Peekable}; use super::{Input, PipeItem, Pipeline, RedirectFrom, Redirection}; -use shell::{Job, JobKind}; -use types::*; +use crate::{ + shell::{Job, JobKind}, + types::*, +}; trait AddItem { fn add_item( @@ -453,12 +455,14 @@ impl<'a> Collector<'a> { #[cfg(test)] mod tests { - use parser::{ - pipelines::{Input, PipeItem, Pipeline, RedirectFrom, Redirection}, - statement::parse, + use crate::{ + parser::{ + pipelines::{Input, PipeItem, Pipeline, RedirectFrom, Redirection}, + statement::parse, + }, + shell::{flow_control::Statement, Job, JobKind}, + types::Array, }; - use shell::{flow_control::Statement, Job, JobKind}; - use types::Array; #[test] fn stderr_redirection() { diff --git a/src/lib/parser/pipelines/mod.rs b/src/lib/parser/pipelines/mod.rs index 72f0aec0..921e14d9 100644 --- a/src/lib/parser/pipelines/mod.rs +++ b/src/lib/parser/pipelines/mod.rs @@ -3,7 +3,7 @@ mod collector; pub(crate) use self::collector::*; use super::expand_string; -use shell::{pipe_exec::stdin_of, Job, JobKind, Shell}; +use crate::shell::{pipe_exec::stdin_of, Job, JobKind, Shell}; use small; use std::{fmt, fs::File, os::unix::io::FromRawFd}; diff --git a/src/lib/parser/shell_expand/mod.rs b/src/lib/parser/shell_expand/mod.rs index 1ed5af95..374d9ca8 100644 --- a/src/lib/parser/shell_expand/mod.rs +++ b/src/lib/parser/shell_expand/mod.rs @@ -4,12 +4,14 @@ extern crate calc; mod words; pub(crate) use self::words::{Select, WordIterator, WordToken}; -use braces::{self, BraceToken}; +use crate::{ + braces::{self, BraceToken}, + ranges::{parse_range, Index, Range}, + types::{self, Array}, +}; use glob::glob; -use ranges::{parse_range, Index, Range}; use small; use std::{ptr, str}; -use types::{self, Array}; use unicode_segmentation::UnicodeSegmentation; /// Determines whether an input string is expression-like as compared to a @@ -31,17 +33,17 @@ pub type MapValueIter<'a> = Box<dyn Iterator<Item = types::Str> + 'a>; /// Trait representing different elements of string expansion pub(crate) trait Expander { /// Expand a tilde form to the correct directory. - fn tilde(&self, &str) -> Option<String> { None } + fn tilde(&self, _input: &str) -> Option<String> { None } /// Expand an array variable with some selection. - fn array(&self, &str, Select) -> Option<types::Array> { None } + fn array(&self, _name: &str, _selection: Select) -> Option<types::Array> { None } /// Expand a string variable given if it's quoted / unquoted - fn string(&self, &str, bool) -> Option<types::Str> { None } + fn string(&self, _name: &str, _quoted: bool) -> Option<types::Str> { None } /// Expand a subshell expression. - fn command(&self, &str) -> Option<types::Str> { None } + fn command(&self, _command: &str) -> Option<types::Str> { None } /// Iterating upon key-value maps. - fn map_keys<'a>(&'a self, &str, Select) -> Option<MapKeyIter> { None } + fn map_keys<'a>(&'a self, _name: &str, _select: Select) -> Option<MapKeyIter> { None } /// Iterating upon key-value maps. - fn map_values<'a>(&'a self, &str, Select) -> Option<MapValueIter> { None } + fn map_values<'a>(&'a self, _name: &str, _select: Select) -> Option<MapValueIter> { None } } fn expand_process<E: Expander>( diff --git a/src/lib/parser/shell_expand/words/methods/arrays.rs b/src/lib/parser/shell_expand/words/methods/arrays.rs index e86bc577..6eb54cc8 100644 --- a/src/lib/parser/shell_expand/words/methods/arrays.rs +++ b/src/lib/parser/shell_expand/words/methods/arrays.rs @@ -6,10 +6,12 @@ use super::{ strings::unescape, Pattern, }; -use ranges::Index; +use crate::{ + ranges::Index, + types::{self, Array}, +}; use small; use std::char; -use types::{self, Array}; use unicode_segmentation::UnicodeSegmentation; #[derive(Debug, PartialEq, Clone)] @@ -217,8 +219,7 @@ impl<'a> ArrayMethod<'a> { #[cfg(test)] mod test { use super::*; - use ranges::Range; - use types; + use crate::{ranges::Range, types}; struct VariableExpander; diff --git a/src/lib/parser/shell_expand/words/methods/mod.rs b/src/lib/parser/shell_expand/words/methods/mod.rs index fb36e8cf..407d1f08 100644 --- a/src/lib/parser/shell_expand/words/methods/mod.rs +++ b/src/lib/parser/shell_expand/words/methods/mod.rs @@ -5,7 +5,7 @@ use self::strings::unescape; pub(crate) use self::{arrays::ArrayMethod, strings::StringMethod}; use super::{expand_string, Expander}; -use lexers::ArgumentSplitter; +use crate::lexers::ArgumentSplitter; use small; #[derive(Debug, PartialEq, Clone)] diff --git a/src/lib/parser/shell_expand/words/methods/strings.rs b/src/lib/parser/shell_expand/words/methods/strings.rs index 48b30fe3..986f5e92 100644 --- a/src/lib/parser/shell_expand/words/methods/strings.rs +++ b/src/lib/parser/shell_expand/words/methods/strings.rs @@ -5,7 +5,7 @@ use super::{ }, MethodArgs, }; -use parser::assignments::is_array; +use crate::parser::assignments::is_array; use regex::Regex; use small; use std::path::Path; @@ -359,7 +359,7 @@ impl<'a> StringMethod<'a> { #[cfg(test)] mod test { use super::*; - use types; + use crate::types; struct VariableExpander; diff --git a/src/lib/parser/shell_expand/words/mod.rs b/src/lib/parser/shell_expand/words/mod.rs index a3e37fc0..da665863 100644 --- a/src/lib/parser/shell_expand/words/mod.rs +++ b/src/lib/parser/shell_expand/words/mod.rs @@ -4,9 +4,8 @@ mod tests; pub(crate) use self::methods::{ArrayMethod, Pattern, StringMethod}; use super::{expand_string, Expander}; -use lexers::ArgumentSplitter; -pub use ranges::{Select, SelectWithSize}; -use shell::escape::unescape; +pub use crate::ranges::{Select, SelectWithSize}; +use crate::{lexers::ArgumentSplitter, shell::escape::unescape}; use std::borrow::Cow; // Bit Twiddling Guide: diff --git a/src/lib/parser/shell_expand/words/tests.rs b/src/lib/parser/shell_expand/words/tests.rs index d5ffbd21..f79966d8 100644 --- a/src/lib/parser/shell_expand/words/tests.rs +++ b/src/lib/parser/shell_expand/words/tests.rs @@ -1,6 +1,8 @@ use super::*; -use ranges::{Index, Range}; -use types::{self, Array}; +use crate::{ + ranges::{Index, Range}, + types::{self, Array}, +}; struct Empty; diff --git a/src/lib/parser/statement/case.rs b/src/lib/parser/statement/case.rs index dbbe4b8f..e0daf2f6 100644 --- a/src/lib/parser/statement/case.rs +++ b/src/lib/parser/statement/case.rs @@ -1,4 +1,4 @@ -use lexers::ArgumentSplitter; +use crate::lexers::ArgumentSplitter; use std::fmt::{self, Display, Formatter}; #[derive(Debug, PartialEq)] diff --git a/src/lib/parser/statement/functions.rs b/src/lib/parser/statement/functions.rs index cdf3fac8..66ecb127 100644 --- a/src/lib/parser/statement/functions.rs +++ b/src/lib/parser/statement/functions.rs @@ -1,5 +1,5 @@ use super::split_pattern; -use lexers::assignments::{KeyBuf, KeyIterator, TypeError}; +use crate::lexers::assignments::{KeyBuf, KeyIterator, TypeError}; use std::fmt::{self, Display, Formatter}; #[derive(Debug, PartialEq)] @@ -51,8 +51,10 @@ pub(crate) fn collect_arguments(args: KeyIterator) -> Result<Vec<KeyBuf>, Functi #[cfg(test)] mod tests { - use lexers::assignments::{KeyBuf, Primitive}; - use parser::statement::functions::{collect_arguments, parse_function, FunctionParseError}; + use crate::{ + lexers::assignments::{KeyBuf, Primitive}, + parser::statement::functions::{collect_arguments, parse_function, FunctionParseError}, + }; #[test] fn function_parsing() { diff --git a/src/lib/parser/statement/mod.rs b/src/lib/parser/statement/mod.rs index 5113e11a..956fb4b9 100644 --- a/src/lib/parser/statement/mod.rs +++ b/src/lib/parser/statement/mod.rs @@ -10,7 +10,7 @@ pub(crate) use self::{ parse::parse, splitter::{StatementError, StatementSplitter, StatementVariant}, }; -use shell::flow_control::Statement; +use crate::shell::flow_control::Statement; /// Parses a given statement string and return's the corresponding mapped /// `Statement` diff --git a/src/lib/parser/statement/parse.rs b/src/lib/parser/statement/parse.rs index 59b1fa42..b6eb46a4 100644 --- a/src/lib/parser/statement/parse.rs +++ b/src/lib/parser/statement/parse.rs @@ -3,10 +3,12 @@ use super::{ case, functions::{collect_arguments, parse_function}, }; -use lexers::{assignment_lexer, ArgumentSplitter}; -use shell::{ - flow_control::{Case, ElseIf, ExportAction, LocalAction, Statement}, - status::FAILURE, +use crate::{ + lexers::{assignment_lexer, ArgumentSplitter}, + shell::{ + flow_control::{Case, ElseIf, ExportAction, LocalAction, Statement}, + status::FAILURE, + }, }; use small; use std::char; @@ -235,8 +237,10 @@ pub(crate) fn parse(code: &str) -> Statement { mod tests { use self::pipelines::PipeItem; use super::*; - use lexers::assignments::{KeyBuf, Primitive}; - use shell::{flow_control::Statement, Job, JobKind}; + use crate::{ + lexers::assignments::{KeyBuf, Primitive}, + shell::{flow_control::Statement, Job, JobKind}, + }; #[test] fn parsing_for() { diff --git a/src/lib/shell/assignments.rs b/src/lib/shell/assignments.rs index d1972786..6f46bdcf 100644 --- a/src/lib/shell/assignments.rs +++ b/src/lib/shell/assignments.rs @@ -3,11 +3,14 @@ use super::{ status::*, Shell, }; +use crate::{ + lexers::assignments::{Operator, Primitive}, + parser::assignments::*, + shell::{history::ShellHistory, variables::VariableType}, + types, +}; use hashbrown::HashMap; use itoa; -use lexers::assignments::{Operator, Primitive}; -use parser::assignments::*; -use shell::{history::ShellHistory, variables::VariableType}; use std::{ env, ffi::OsStr, @@ -18,7 +21,6 @@ use std::{ result::Result, str, }; -use types; fn list_vars(shell: &Shell) -> Result<(), io::Error> { let stdout = io::stdout(); @@ -58,9 +60,9 @@ fn arithmetic_op(operator: Operator, value: f64) -> Result<Box<dyn Fn(f64) -> f6 /// exporting variables to some global environment pub(crate) trait VariableStore { /// Set a local variable given a binding - fn local(&mut self, LocalAction) -> i32; + fn local(&mut self, action: LocalAction) -> i32; /// Export a variable to the process environment given a binding - fn export(&mut self, ExportAction) -> i32; + fn export(&mut self, action: ExportAction) -> i32; } impl VariableStore for Shell { diff --git a/src/lib/shell/binary/designators.rs b/src/lib/shell/binary/designators.rs index be01ed22..aff6ebd5 100644 --- a/src/lib/shell/binary/designators.rs +++ b/src/lib/shell/binary/designators.rs @@ -1,5 +1,7 @@ -use lexers::{ArgumentSplitter, DesignatorLexer, DesignatorToken}; -use shell::Shell; +use crate::{ + lexers::{ArgumentSplitter, DesignatorLexer, DesignatorToken}, + shell::Shell, +}; use std::{borrow::Cow, str}; pub(crate) fn expand_designators<'a>(shell: &Shell, cmd: &'a str) -> Cow<'a, str> { diff --git a/src/lib/shell/binary/mod.rs b/src/lib/shell/binary/mod.rs index 41370c47..23e59e7f 100644 --- a/src/lib/shell/binary/mod.rs +++ b/src/lib/shell/binary/mod.rs @@ -10,9 +10,9 @@ use self::{ terminate::{terminate_quotes, terminate_script_quotes}, }; use super::{status::*, FlowLogic, Shell, ShellHistory}; +use crate::types; use liner::{Buffer, Context}; use std::{env, iter, path::Path, process}; -use types; pub const MAN_ION: &str = r#"NAME ion - ion shell diff --git a/src/lib/shell/binary/prompt.rs b/src/lib/shell/binary/prompt.rs index f8e1023b..71b342df 100644 --- a/src/lib/shell/binary/prompt.rs +++ b/src/lib/shell/binary/prompt.rs @@ -1,7 +1,9 @@ -use parser::shell_expand::expand_string; -use shell::{flags::UNTERMINATED, Capture, Function, Shell}; +use crate::{ + parser::shell_expand::expand_string, + shell::{flags::UNTERMINATED, Capture, Function, Shell}, + sys, +}; use std::{io::Read, process}; -use sys; pub(crate) fn prompt(shell: &mut Shell) -> String { let blocks = diff --git a/src/lib/shell/binary/readln.rs b/src/lib/shell/binary/readln.rs index 29f0c24c..c184c6ce 100644 --- a/src/lib/shell/binary/readln.rs +++ b/src/lib/shell/binary/readln.rs @@ -1,8 +1,7 @@ use super::super::{completer::*, Binary, DirectoryStack, Shell, Variables}; +use crate::{sys, types}; use liner::{BasicCompleter, CursorPosition, Event, EventKind}; use std::{env, io::ErrorKind, mem, path::PathBuf}; -use sys; -use types; pub(crate) fn readln(shell: &mut Shell) -> Option<String> { { diff --git a/src/lib/shell/binary/terminate.rs b/src/lib/shell/binary/terminate.rs index 6e527253..bc295ad4 100644 --- a/src/lib/shell/binary/terminate.rs +++ b/src/lib/shell/binary/terminate.rs @@ -1,5 +1,7 @@ -use parser::Terminator; -use shell::{flags::UNTERMINATED, status::*, Binary, FlowLogic, Shell}; +use crate::{ + parser::Terminator, + shell::{flags::UNTERMINATED, status::*, Binary, FlowLogic, Shell}, +}; pub(crate) fn terminate_script_quotes<I: Iterator<Item = String>>( shell: &mut Shell, diff --git a/src/lib/shell/directory_stack.rs b/src/lib/shell/directory_stack.rs index e64ae506..e74e4eb8 100644 --- a/src/lib/shell/directory_stack.rs +++ b/src/lib/shell/directory_stack.rs @@ -2,13 +2,13 @@ use super::{ status::{FAILURE, SUCCESS}, variables::Variables, }; +use crate::sys::env as sys_env; use std::{ borrow::Cow, collections::VecDeque, env::{self, set_current_dir}, path::{Component, Path, PathBuf}, }; -use sys::env as sys_env; fn set_current_dir_ion(dir: &Path) -> Result<(), Cow<'static, str>> { set_current_dir(dir).map_err(|why| Cow::Owned(format!("{}", why)))?; diff --git a/src/lib/shell/flow.rs b/src/lib/shell/flow.rs index b9d0c4de..d1df5fdc 100644 --- a/src/lib/shell/flow.rs +++ b/src/lib/shell/flow.rs @@ -5,17 +5,19 @@ use super::{ status::*, Shell, }; -use itertools::Itertools; -use parser::{ - assignments::is_array, - expand_string, parse_and_validate, - pipelines::{PipeItem, Pipeline}, - ForValueExpression, StatementSplitter, +use crate::{ + parser::{ + assignments::is_array, + expand_string, parse_and_validate, + pipelines::{PipeItem, Pipeline}, + ForValueExpression, StatementSplitter, + }, + shell::{assignments::VariableStore, variables::VariableType}, + types, }; -use shell::{assignments::VariableStore, variables::VariableType}; +use itertools::Itertools; use small; use std::io::{stdout, Write}; -use types; macro_rules! handle_signal { ($signal:expr) => { diff --git a/src/lib/shell/flow_control.rs b/src/lib/shell/flow_control.rs index e114555c..21548ca1 100644 --- a/src/lib/shell/flow_control.rs +++ b/src/lib/shell/flow_control.rs @@ -1,10 +1,12 @@ -use lexers::assignments::{KeyBuf, Operator, Primitive}; -use parser::{assignments::*, pipelines::Pipeline}; -use shell::{flow::FlowLogic, Shell}; +use crate::{ + lexers::assignments::{KeyBuf, Operator, Primitive}, + parser::{assignments::*, pipelines::Pipeline}, + shell::{flow::FlowLogic, Shell}, + types, +}; use small; use smallvec::SmallVec; use std::fmt::{self, Display, Formatter}; -use types; #[derive(Debug, PartialEq, Clone)] pub(crate) struct ElseIf { diff --git a/src/lib/shell/fork.rs b/src/lib/shell/fork.rs index 82670a33..abc39ca2 100644 --- a/src/lib/shell/fork.rs +++ b/src/lib/shell/fork.rs @@ -1,10 +1,10 @@ use super::{IonError, Shell}; +use crate::sys; use std::{ fs::File, io, os::unix::io::{AsRawFd, FromRawFd}, }; -use sys; pub fn wait_for_child(pid: u32) -> io::Result<u8> { let mut status; diff --git a/src/lib/shell/fork_function.rs b/src/lib/shell/fork_function.rs index 4b6b6d50..cac2488b 100644 --- a/src/lib/shell/fork_function.rs +++ b/src/lib/shell/fork_function.rs @@ -1,6 +1,8 @@ -use shell::{Capture, Function, Shell}; +use crate::{ + shell::{Capture, Function, Shell}, + sys, +}; use std::process; -use sys; pub(crate) fn command_not_found(shell: &mut Shell, command: &str) -> bool { fork_function(shell, "COMMAND_NOT_FOUND", &["ion", command]) diff --git a/src/lib/shell/history.rs b/src/lib/shell/history.rs index 7f39d003..47423e1d 100644 --- a/src/lib/shell/history.rs +++ b/src/lib/shell/history.rs @@ -1,12 +1,12 @@ -use shell::{status::*, Shell}; +use crate::shell::{status::*, Shell}; +use crate::types; use regex::Regex; use small; use std::{ io::{self, Write}, time::{SystemTime, UNIX_EPOCH}, }; -use types; bitflags! { struct IgnoreFlags: u8 { diff --git a/src/lib/shell/job.rs b/src/lib/shell/job.rs index 7ba29f7b..5a27a64e 100644 --- a/src/lib/shell/job.rs +++ b/src/lib/shell/job.rs @@ -1,9 +1,11 @@ use super::Shell; -use builtins::{BuiltinFunction, BUILTINS}; -use parser::{expand_string, pipelines::RedirectFrom}; -use shell::pipe_exec::PipelineExecution; +use crate::{ + builtins::{BuiltinFunction, BUILTINS}, + parser::{expand_string, pipelines::RedirectFrom}, + shell::pipe_exec::PipelineExecution, + types::{self, Array}, +}; use std::{fmt, fs::File, str}; -use types::{self, Array}; #[derive(Debug, PartialEq, Clone, Copy)] pub(crate) enum JobKind { diff --git a/src/lib/shell/mod.rs b/src/lib/shell/mod.rs index 0f9a36db..673cbf07 100644 --- a/src/lib/shell/mod.rs +++ b/src/lib/shell/mod.rs @@ -49,9 +49,13 @@ use self::{ status::*, variables::{GetVariable, VariableType, Variables}, }; -use builtins::{BuiltinMap, BUILTINS}; +use crate::{ + builtins::{BuiltinMap, BUILTINS}, + parser::{pipelines::Pipeline, Expander, MapKeyIter, MapValueIter, Select, Terminator}, + sys, + types::{self, Array}, +}; use liner::Context; -use parser::{pipelines::Pipeline, Expander, MapKeyIter, MapValueIter, Select, Terminator}; use std::{ fs::File, io::{self, Read, Write}, @@ -62,8 +66,6 @@ use std::{ sync::{atomic::Ordering, Arc, Mutex}, time::SystemTime, }; -use sys; -use types::{self, Array}; use xdg::BaseDirectories; #[derive(Debug, Fail)] @@ -437,7 +439,7 @@ impl<'a> Expander for Shell { /// Expand a string variable given if its quoted / unquoted fn string(&self, name: &str, quoted: bool) -> Option<types::Str> { - use ascii_helpers::AsciiReplace; + use crate::ascii_helpers::AsciiReplace; if name == "?" { Some(types::Str::from(self.previous_status.to_string())) } else if quoted { @@ -502,7 +504,7 @@ impl<'a> Expander for Shell { )]); } Select::Index(index) => { - use ranges::Index; + use crate::ranges::Index; return Some(array![format!( "{}", hmap.get(&types::Str::from( @@ -545,7 +547,7 @@ impl<'a> Expander for Shell { )]); } Select::Index(index) => { - use ranges::Index; + use crate::ranges::Index; return Some(array![format!( "{}", bmap.get(&types::Str::from( diff --git a/src/lib/shell/pipe_exec/fork.rs b/src/lib/shell/pipe_exec/fork.rs index b91970ea..8d6569e5 100644 --- a/src/lib/shell/pipe_exec/fork.rs +++ b/src/lib/shell/pipe_exec/fork.rs @@ -1,5 +1,5 @@ +use crate::sys; use smallvec::SmallVec; -use sys; /// Ensures that the forked child is given a unique process ID. pub(crate) fn create_process_group(pgid: u32) { let _ = sys::setpgid(0, pgid); } diff --git a/src/lib/shell/pipe_exec/job_control.rs b/src/lib/shell/pipe_exec/job_control.rs index 016d9cca..5bd4e2bd 100644 --- a/src/lib/shell/pipe_exec/job_control.rs +++ b/src/lib/shell/pipe_exec/job_control.rs @@ -2,13 +2,13 @@ use super::{ super::{signals, status::*, Shell}, foreground::{BackgroundResult, ForegroundSignals}, }; +use crate::sys; use std::{ fmt, process, sync::{Arc, Mutex}, thread::{sleep, spawn}, time::Duration, }; -use sys; /// When given a process ID, that process's group will be assigned as the /// foreground process group. @@ -250,7 +250,7 @@ impl JobControl for Shell { } } -use sys::{ +use crate::sys::{ kill, strerror, waitpid, wcoredump, wexitstatus, wifcontinued, wifexited, wifsignaled, wifstopped, wstopsig, wtermsig, ECHILD, SIGINT, SIGPIPE, WCONTINUED, WNOHANG, WUNTRACED, }; diff --git a/src/lib/shell/pipe_exec/mod.rs b/src/lib/shell/pipe_exec/mod.rs index 8f4a7103..972d7566 100644 --- a/src/lib/shell/pipe_exec/mod.rs +++ b/src/lib/shell/pipe_exec/mod.rs @@ -26,8 +26,11 @@ use super::{ status::*, JobKind, Shell, }; -use builtins::{self, BuiltinFunction}; -use parser::pipelines::{Input, PipeItem, Pipeline, RedirectFrom, Redirection}; +use crate::{ + builtins::{self, BuiltinFunction}, + parser::pipelines::{Input, PipeItem, Pipeline, RedirectFrom, Redirection}, + sys, +}; use small; use smallvec::SmallVec; use std::{ @@ -38,7 +41,6 @@ use std::{ path::Path, process::{self, exit}, }; -use sys; type RefinedItem = (RefinedJob, JobKind, Vec<Redirection>, Vec<Input>); diff --git a/src/lib/shell/pipe_exec/pipes.rs b/src/lib/shell/pipe_exec/pipes.rs index fecc3a8f..9fc16552 100644 --- a/src/lib/shell/pipe_exec/pipes.rs +++ b/src/lib/shell/pipe_exec/pipes.rs @@ -3,8 +3,8 @@ use super::{ append_external_stdio_pipe, pipe_fail, }; +use crate::sys; use std::{fs::File, os::unix::io::FromRawFd}; -use sys; pub(crate) struct TeePipe<'a> { parent: &'a mut RefinedJob, diff --git a/src/lib/shell/pipe_exec/streams.rs b/src/lib/shell/pipe_exec/streams.rs index 43a16795..9b5e6b8f 100644 --- a/src/lib/shell/pipe_exec/streams.rs +++ b/src/lib/shell/pipe_exec/streams.rs @@ -1,9 +1,9 @@ +use crate::sys; use std::{ fs::File, io, os::unix::io::{AsRawFd, FromRawFd, RawFd}, }; -use sys; /// Use dup2 to replace `old` with `new` using `old`s file descriptor ID pub(crate) fn redir(old: RawFd, new: RawFd) { diff --git a/src/lib/shell/signals.rs b/src/lib/shell/signals.rs index c5a44ac0..76fde144 100644 --- a/src/lib/shell/signals.rs +++ b/src/lib/shell/signals.rs @@ -6,9 +6,9 @@ // use std::sync::atomic::{ATOMIC_U8_INIT, AtomicU8}; use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT}; -use sys; +use crate::sys; -pub(crate) use sys::signals::{block, unblock}; +pub(crate) use crate::sys::signals::{block, unblock}; pub static PENDING: AtomicUsize = ATOMIC_USIZE_INIT; pub const SIGINT: u8 = 1; diff --git a/src/lib/shell/variables/mod.rs b/src/lib/shell/variables/mod.rs index 2f3a2a85..6690185c 100644 --- a/src/lib/shell/variables/mod.rs +++ b/src/lib/shell/variables/mod.rs @@ -4,6 +4,10 @@ use super::{ flow_control::Function, status::{FAILURE, SUCCESS}, }; +use crate::{ + sys::{self, env as sys_env, geteuid, getpid, getuid, variables as self_sys}, + types::{self, Array}, +}; use hashbrown::HashMap; use liner::Context; use std::{ @@ -12,8 +16,6 @@ use std::{ mem, ops::{Deref, DerefMut}, }; -use sys::{self, env as sys_env, geteuid, getpid, getuid, variables as self_sys}; -use types::{self, Array}; use unicode_segmentation::UnicodeSegmentation; use xdg::BaseDirectories; @@ -625,7 +627,7 @@ pub trait GetVariable<T> { impl GetVariable<types::Str> for Variables { fn get(&self, name: &str) -> Option<types::Str> { - use types::Str; + use crate::types::Str; match name { "MWD" => return Some(Str::from(VariableType::Str(self.get_minimal_directory()))), @@ -689,7 +691,7 @@ get_var!(Function, Function(func) => func); #[cfg(test)] mod tests { use super::*; - use parser::{expand_string, Expander}; + use crate::parser::{expand_string, Expander}; struct VariableExpander(pub Variables); diff --git a/src/lib/types.rs b/src/lib/types.rs index 09eb7229..97db4339 100644 --- a/src/lib/types.rs +++ b/src/lib/types.rs @@ -1,5 +1,5 @@ +use crate::shell::variables::VariableType; use hashbrown::HashMap as HashbrownMap; -use shell::variables::VariableType; use small; use smallvec::SmallVec; use std::{ -- GitLab