Patchwork D6769: another way of implementing the parent

login
register
mail settings
Submitter phabricator
Date Aug. 28, 2019, 11:37 a.m.
Message ID <differential-rev-PHID-DREV-235ofoktnrggnizxnn3m-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41420/
State Superseded
Headers show

Comments

phabricator - Aug. 28, 2019, 11:37 a.m.
valentin.gatienbaron created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  I would drop this or fold it into the parent depending on reviewers' opinion.
  
  The problem is that byte literals can converted to slices implicitely,
  and concat can work on slices and other things, and it's too much for
  the typer to try to do both at the time. Providing a monomorphic version
  of the concat method avoids having to write &byteliteral[..].

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6769

AFFECTED FILES
  rust/hg-core/src/filepatterns.rs
  rust/hg-core/src/utils.rs

CHANGE DETAILS




To: valentin.gatienbaron, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel

Patch

diff --git a/rust/hg-core/src/utils.rs b/rust/hg-core/src/utils.rs
--- a/rust/hg-core/src/utils.rs
+++ b/rust/hg-core/src/utils.rs
@@ -37,6 +37,10 @@ 
     }
 }
 
+pub fn concat(slices: &[&[u8]]) -> Vec<u8> {
+    slices.concat()
+}
+
 pub trait SliceExt {
     fn trim_end(&self) -> &Self;
     fn trim_start(&self) -> &Self;
diff --git a/rust/hg-core/src/filepatterns.rs b/rust/hg-core/src/filepatterns.rs
--- a/rust/hg-core/src/filepatterns.rs
+++ b/rust/hg-core/src/filepatterns.rs
@@ -8,7 +8,7 @@ 
 //! Handling of Mercurial-specific patterns.
 
 use crate::{
-    utils::{files::get_path_from_bytes, SliceExt},
+    utils::{concat, files::get_path_from_bytes, SliceExt},
     LineNumber, PatternError, PatternFileError,
 };
 use lazy_static::lazy_static;
@@ -158,20 +158,20 @@ 
             if pattern[0] == b'^' {
                 return pattern.to_owned();
             }
-            [&b".*"[..], pattern].concat()
+            concat(&[b".*", pattern])
         }
         PatternSyntax::Path | PatternSyntax::RelPath => {
             if pattern == b"." {
                 return vec![];
             }
-            [&escape_pattern(pattern), &b"(?:/|$)"[..]].concat()
+            concat(&[&escape_pattern(pattern), b"(?:/|$)"])
         }
         PatternSyntax::RootFiles => {
             let mut res = if pattern == b"." {
                 vec![]
             } else {
                 // Pattern is a directory name.
-                [&escape_pattern(pattern), &b"/"[..]].concat()
+                concat(&[&escape_pattern(pattern), b"/"])
             };
 
             // Anything after the pattern must be a non-directory.
@@ -181,14 +181,14 @@ 
         PatternSyntax::RelGlob => {
             let glob_re = glob_to_re(pattern);
             if let Some(rest) = glob_re.drop_prefix(b"[^/]*") {
-                [&b".*"[..], rest, globsuffix].concat()
+                concat(&[b".*", rest, globsuffix])
             } else {
-                [&b"(?:|.*/)"[..], &glob_re, globsuffix].concat()
+                concat(&[b"(?:|.*/)", &glob_re, globsuffix])
             }
         }
         PatternSyntax::Glob
         | PatternSyntax::RootGlob => {
-            [&glob_to_re(pattern), globsuffix].concat()
+            concat(&[&glob_to_re(pattern), globsuffix])
         }
     }
 }