Skip to content

Commit fce58e2

Browse files
authored
refactor: rust 1.89 and remove os_pipe dependency (#159)
1 parent 713b75a commit fce58e2

File tree

12 files changed

+134
-120
lines changed

12 files changed

+134
-120
lines changed

Cargo.lock

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ description = "Cross platform scripting for deno task"
1111

1212
[features]
1313
default = ["shell"]
14-
shell = ["deno_path_util", "futures", "glob", "nix", "os_pipe", "path-dedot", "tokio", "windows-sys", "sys_traits", "which"]
14+
shell = ["deno_path_util", "futures", "glob", "nix", "path-dedot", "tokio", "windows-sys", "sys_traits", "which"]
1515
serialization = ["serde"]
1616

1717
[dependencies]
1818
anyhow = "1.0.75"
1919
futures = { version = "0.3.29", optional = true }
2020
glob = { version = "0.3.1", optional = true }
2121
path-dedot = { version = "3.1.1", optional = true }
22-
os_pipe = { version = "1.1.4", optional = true }
2322
serde = { version = "1", features = ["derive"], optional = true }
2423
monch = "0.5.0"
2524
thiserror = "2.0.9"

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.85.0"
2+
channel = "1.89.0"
33
components = ["clippy", "rustfmt"]

src/parser.rs

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ pub fn parse(input: &str) -> Result<SequentialList> {
340340
}
341341
}
342342

343-
fn parse_sequential_list(input: &str) -> ParseResult<SequentialList> {
343+
fn parse_sequential_list(input: &str) -> ParseResult<'_, SequentialList> {
344344
let (input, items) = separated_list(
345345
terminated(parse_sequential_list_item, skip_whitespace),
346346
terminated(
@@ -354,7 +354,9 @@ fn parse_sequential_list(input: &str) -> ParseResult<SequentialList> {
354354
Ok((input, SequentialList { items }))
355355
}
356356

357-
fn parse_sequential_list_item(input: &str) -> ParseResult<SequentialListItem> {
357+
fn parse_sequential_list_item(
358+
input: &str,
359+
) -> ParseResult<'_, SequentialListItem> {
358360
let (input, sequence) = parse_sequence(input)?;
359361
Ok((
360362
input,
@@ -365,7 +367,7 @@ fn parse_sequential_list_item(input: &str) -> ParseResult<SequentialListItem> {
365367
))
366368
}
367369

368-
fn parse_sequence(input: &str) -> ParseResult<Sequence> {
370+
fn parse_sequence(input: &str) -> ParseResult<'_, Sequence> {
369371
let (input, current) = terminated(
370372
or(
371373
parse_shell_var_command,
@@ -394,7 +396,7 @@ fn parse_sequence(input: &str) -> ParseResult<Sequence> {
394396
})
395397
}
396398

397-
fn parse_shell_var_command(input: &str) -> ParseResult<Sequence> {
399+
fn parse_shell_var_command(input: &str) -> ParseResult<'_, Sequence> {
398400
let env_vars_input = input;
399401
let (input, mut env_vars) = if_not_empty(parse_env_vars)(input)?;
400402
let (input, args) = parse_command_args(input)?;
@@ -413,7 +415,7 @@ fn parse_shell_var_command(input: &str) -> ParseResult<Sequence> {
413415

414416
/// Parses a pipeline, which is a sequence of one or more commands.
415417
/// https://www.gnu.org/software/bash/manual/html_node/Pipelines.html
416-
fn parse_pipeline(input: &str) -> ParseResult<Pipeline> {
418+
fn parse_pipeline(input: &str) -> ParseResult<'_, Pipeline> {
417419
let (input, maybe_negated) = maybe(parse_negated_op)(input)?;
418420
let (input, inner) = parse_pipeline_inner(input)?;
419421

@@ -425,7 +427,7 @@ fn parse_pipeline(input: &str) -> ParseResult<Pipeline> {
425427
Ok((input, pipeline))
426428
}
427429

428-
fn parse_pipeline_inner(input: &str) -> ParseResult<PipelineInner> {
430+
fn parse_pipeline_inner(input: &str) -> ParseResult<'_, PipelineInner> {
429431
let original_input = input;
430432
let (input, command) = parse_command(input)?;
431433

@@ -459,7 +461,7 @@ fn parse_pipeline_inner(input: &str) -> ParseResult<PipelineInner> {
459461
Ok((input, inner))
460462
}
461463

462-
fn parse_command(input: &str) -> ParseResult<Command> {
464+
fn parse_command(input: &str) -> ParseResult<'_, Command> {
463465
let (input, inner) = terminated(
464466
or(
465467
map(parse_subshell, |l| CommandInner::Subshell(Box::new(l))),
@@ -487,13 +489,13 @@ fn parse_command(input: &str) -> ParseResult<Command> {
487489
Ok((input, command))
488490
}
489491

490-
fn parse_simple_command(input: &str) -> ParseResult<SimpleCommand> {
492+
fn parse_simple_command(input: &str) -> ParseResult<'_, SimpleCommand> {
491493
let (input, env_vars) = parse_env_vars(input)?;
492494
let (input, args) = if_not_empty(parse_command_args)(input)?;
493495
ParseResult::Ok((input, SimpleCommand { env_vars, args }))
494496
}
495497

496-
fn parse_command_args(input: &str) -> ParseResult<Vec<Word>> {
498+
fn parse_command_args(input: &str) -> ParseResult<'_, Vec<Word>> {
497499
many_till(
498500
terminated(parse_shell_arg, assert_whitespace_or_end_and_skip),
499501
or4(
@@ -505,7 +507,7 @@ fn parse_command_args(input: &str) -> ParseResult<Vec<Word>> {
505507
)(input)
506508
}
507509

508-
fn parse_shell_arg(input: &str) -> ParseResult<Word> {
510+
fn parse_shell_arg(input: &str) -> ParseResult<'_, Word> {
509511
let (input, value) = parse_word(input)?;
510512
if value.parts().is_empty() {
511513
ParseError::backtrace()
@@ -514,14 +516,14 @@ fn parse_shell_arg(input: &str) -> ParseResult<Word> {
514516
}
515517
}
516518

517-
fn parse_list_op(input: &str) -> ParseResult<()> {
519+
fn parse_list_op(input: &str) -> ParseResult<'_, ()> {
518520
or(
519521
map(parse_boolean_list_op, |_| ()),
520522
map(or(parse_sequential_list_op, parse_async_list_op), |_| ()),
521523
)(input)
522524
}
523525

524-
fn parse_boolean_list_op(input: &str) -> ParseResult<BooleanListOperator> {
526+
fn parse_boolean_list_op(input: &str) -> ParseResult<'_, BooleanListOperator> {
525527
or(
526528
map(parse_op_str(BooleanListOperator::And.as_str()), |_| {
527529
BooleanListOperator::And
@@ -532,15 +534,15 @@ fn parse_boolean_list_op(input: &str) -> ParseResult<BooleanListOperator> {
532534
)(input)
533535
}
534536

535-
fn parse_sequential_list_op(input: &str) -> ParseResult<&str> {
537+
fn parse_sequential_list_op(input: &str) -> ParseResult<'_, &str> {
536538
terminated(tag(";"), skip_whitespace)(input)
537539
}
538540

539-
fn parse_async_list_op(input: &str) -> ParseResult<&str> {
541+
fn parse_async_list_op(input: &str) -> ParseResult<'_, &str> {
540542
parse_op_str("&")(input)
541543
}
542544

543-
fn parse_negated_op(input: &str) -> ParseResult<&str> {
545+
fn parse_negated_op(input: &str) -> ParseResult<'_, &str> {
544546
terminated(
545547
tag("!"),
546548
// must have whitespace following
@@ -559,7 +561,9 @@ fn parse_op_str<'a>(
559561
)
560562
}
561563

562-
fn parse_pipe_sequence_op(input: &str) -> ParseResult<PipeSequenceOperator> {
564+
fn parse_pipe_sequence_op(
565+
input: &str,
566+
) -> ParseResult<'_, PipeSequenceOperator> {
563567
terminated(
564568
or(
565569
map(tag("|&"), |_| PipeSequenceOperator::StdoutStderr),
@@ -569,7 +573,7 @@ fn parse_pipe_sequence_op(input: &str) -> ParseResult<PipeSequenceOperator> {
569573
)(input)
570574
}
571575

572-
fn parse_redirect(input: &str) -> ParseResult<Redirect> {
576+
fn parse_redirect(input: &str) -> ParseResult<'_, Redirect> {
573577
// https://pubs.opengroup.org/onlinepubs/009604499/utilities/xcu_chap02.html#tag_02_07
574578
let (input, maybe_fd) = maybe(parse_u32)(input)?;
575579
let (input, maybe_ampersand) = if maybe_fd.is_none() {
@@ -607,11 +611,11 @@ fn parse_redirect(input: &str) -> ParseResult<Redirect> {
607611
))
608612
}
609613

610-
fn parse_env_vars(input: &str) -> ParseResult<Vec<EnvVar>> {
614+
fn parse_env_vars(input: &str) -> ParseResult<'_, Vec<EnvVar>> {
611615
many0(terminated(parse_env_var, skip_whitespace))(input)
612616
}
613617

614-
fn parse_env_var(input: &str) -> ParseResult<EnvVar> {
618+
fn parse_env_var(input: &str) -> ParseResult<'_, EnvVar> {
615619
let (input, name) = parse_env_var_name(input)?;
616620
let (input, _) = ch('=')(input)?;
617621
let (input, value) = with_error_context(
@@ -621,15 +625,15 @@ fn parse_env_var(input: &str) -> ParseResult<EnvVar> {
621625
Ok((input, EnvVar::new(name.to_string(), value)))
622626
}
623627

624-
fn parse_env_var_name(input: &str) -> ParseResult<&str> {
628+
fn parse_env_var_name(input: &str) -> ParseResult<'_, &str> {
625629
if_not_empty(take_while(is_valid_env_var_char))(input)
626630
}
627631

628-
fn parse_env_var_value(input: &str) -> ParseResult<Word> {
632+
fn parse_env_var_value(input: &str) -> ParseResult<'_, Word> {
629633
parse_word(input)
630634
}
631635

632-
fn parse_word(input: &str) -> ParseResult<Word> {
636+
fn parse_word(input: &str) -> ParseResult<'_, Word> {
633637
let parse_quoted_or_unquoted = or(
634638
map(parse_quoted_string, |parts| vec![WordPart::Quoted(parts)]),
635639
parse_unquoted_word,
@@ -644,17 +648,17 @@ fn parse_word(input: &str) -> ParseResult<Word> {
644648
}
645649
}
646650

647-
fn parse_unquoted_word(input: &str) -> ParseResult<Vec<WordPart>> {
651+
fn parse_unquoted_word(input: &str) -> ParseResult<'_, Vec<WordPart>> {
648652
assert(
649653
parse_word_parts(ParseWordPartsMode::Unquoted),
650654
|result| {
651655
result
652656
.ok()
653657
.map(|(_, parts)| {
654-
if parts.len() == 1 {
655-
if let WordPart::Text(text) = &parts[0] {
656-
return !is_reserved_word(text);
657-
}
658+
if parts.len() == 1
659+
&& let WordPart::Text(text) = &parts[0]
660+
{
661+
return !is_reserved_word(text);
658662
}
659663
true
660664
})
@@ -664,7 +668,7 @@ fn parse_unquoted_word(input: &str) -> ParseResult<Vec<WordPart>> {
664668
)(input)
665669
}
666670

667-
fn parse_quoted_string(input: &str) -> ParseResult<Vec<WordPart>> {
671+
fn parse_quoted_string(input: &str) -> ParseResult<'_, Vec<WordPart>> {
668672
// Strings may be up beside each other, and if they are they
669673
// should be categorized as the same argument.
670674
map(
@@ -678,7 +682,7 @@ fn parse_quoted_string(input: &str) -> ParseResult<Vec<WordPart>> {
678682
)(input)
679683
}
680684

681-
fn parse_single_quoted_string(input: &str) -> ParseResult<&str> {
685+
fn parse_single_quoted_string(input: &str) -> ParseResult<'_, &str> {
682686
// single quoted strings cannot contain a single quote
683687
// https://pubs.opengroup.org/onlinepubs/009604499/utilities/xcu_chap02.html#tag_02_02_02
684688
delimited(
@@ -691,8 +695,8 @@ fn parse_single_quoted_string(input: &str) -> ParseResult<&str> {
691695
)(input)
692696
}
693697

694-
fn parse_double_quoted_string(input: &str) -> ParseResult<Vec<WordPart>> {
695-
fn parse_words_within(input: &str) -> ParseResult<Vec<WordPart>> {
698+
fn parse_double_quoted_string(input: &str) -> ParseResult<'_, Vec<WordPart>> {
699+
fn parse_words_within(input: &str) -> ParseResult<'_, Vec<WordPart>> {
696700
match parse_word_parts(ParseWordPartsMode::DoubleQuotes)(input) {
697701
Ok((result_input, parts)) => {
698702
if !result_input.is_empty() {
@@ -788,8 +792,8 @@ enum ParseWordPartsMode {
788792

789793
fn parse_word_parts(
790794
mode: ParseWordPartsMode,
791-
) -> impl Fn(&str) -> ParseResult<Vec<WordPart>> {
792-
fn parse_escaped_dollar_sign(input: &str) -> ParseResult<char> {
795+
) -> impl Fn(&str) -> ParseResult<'_, Vec<WordPart>> {
796+
fn parse_escaped_dollar_sign(input: &str) -> ParseResult<'_, char> {
793797
or(
794798
parse_escaped_char('$'),
795799
terminated(
@@ -799,7 +803,7 @@ fn parse_word_parts(
799803
)(input)
800804
}
801805

802-
fn parse_special_shell_var(input: &str) -> ParseResult<char> {
806+
fn parse_special_shell_var(input: &str) -> ParseResult<'_, char> {
803807
// for now, these hard error
804808
preceded(ch('$'), |input| {
805809
if let Some(char) = input.chars().next() {
@@ -931,7 +935,7 @@ fn parse_word_parts(
931935
}
932936
}
933937

934-
fn parse_command_substitution(input: &str) -> ParseResult<SequentialList> {
938+
fn parse_command_substitution(input: &str) -> ParseResult<'_, SequentialList> {
935939
delimited(
936940
tag("$("),
937941
parse_sequential_list,
@@ -947,7 +951,7 @@ fn parse_command_substitution(input: &str) -> ParseResult<SequentialList> {
947951

948952
fn parse_backticks_command_substitution(
949953
input: &str,
950-
) -> ParseResult<SequentialList> {
954+
) -> ParseResult<'_, SequentialList> {
951955
let start_input = input;
952956
let (input, _) = ch('`')(input)?;
953957
let mut was_escape = false;
@@ -1002,7 +1006,7 @@ fn parse_backticks_command_substitution(
10021006
ParseError::fail(start_input, "Expected closing backtick.")
10031007
}
10041008

1005-
fn parse_subshell(input: &str) -> ParseResult<SequentialList> {
1009+
fn parse_subshell(input: &str) -> ParseResult<'_, SequentialList> {
10061010
delimited(
10071011
terminated(ch('('), skip_whitespace),
10081012
parse_sequential_list,
@@ -1013,7 +1017,7 @@ fn parse_subshell(input: &str) -> ParseResult<SequentialList> {
10131017
)(input)
10141018
}
10151019

1016-
fn parse_u32(input: &str) -> ParseResult<u32> {
1020+
fn parse_u32(input: &str) -> ParseResult<'_, u32> {
10171021
let mut value: u32 = 0;
10181022
let mut byte_index = 0;
10191023
for c in input.chars() {
@@ -1036,17 +1040,16 @@ fn parse_u32(input: &str) -> ParseResult<u32> {
10361040
Ok((&input[byte_index..], value))
10371041
}
10381042

1039-
fn assert_whitespace_or_end_and_skip(input: &str) -> ParseResult<()> {
1043+
fn assert_whitespace_or_end_and_skip(input: &str) -> ParseResult<'_, ()> {
10401044
terminated(assert_whitespace_or_end, skip_whitespace)(input)
10411045
}
10421046

1043-
fn assert_whitespace_or_end(input: &str) -> ParseResult<()> {
1044-
if let Some(next_char) = input.chars().next() {
1045-
if !next_char.is_whitespace()
1046-
&& !matches!(next_char, ';' | '&' | '|' | '(' | ')')
1047-
{
1048-
return Err(ParseError::Failure(fail_for_trailing_input(input)));
1049-
}
1047+
fn assert_whitespace_or_end(input: &str) -> ParseResult<'_, ()> {
1048+
if let Some(next_char) = input.chars().next()
1049+
&& !next_char.is_whitespace()
1050+
&& !matches!(next_char, ';' | '&' | '|' | '(' | ')')
1051+
{
1052+
return Err(ParseError::Failure(fail_for_trailing_input(input)));
10501053
}
10511054
Ok((input, ()))
10521055
}
@@ -1075,7 +1078,7 @@ fn is_reserved_word(text: &str) -> bool {
10751078
)
10761079
}
10771080

1078-
fn fail_for_trailing_input(input: &str) -> ParseErrorFailure {
1081+
fn fail_for_trailing_input(input: &str) -> ParseErrorFailure<'_> {
10791082
ParseErrorFailure::new(input, "Unexpected character.")
10801083
}
10811084

src/shell/child_process_tracker.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ impl ChildProcessTracker {
3939
}
4040

4141
pub fn track(&self, child: &Child) {
42-
if let Err(err) = self.0.track(child) {
43-
if cfg!(debug_assertions) && child.id().is_some() {
44-
panic!("Could not track process: {:#}", err);
45-
}
42+
if let Err(err) = self.0.track(child)
43+
&& cfg!(debug_assertions)
44+
&& child.id().is_some()
45+
{
46+
panic!("Could not track process: {:#}", err);
4647
}
4748
}
4849
}

0 commit comments

Comments
 (0)