Upgrade clap_derive to 4.1.8 am: c8731374ee am: 5978a27f64 am: 0dc9663657 am: 22025c897e

Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/clap_derive/+/2465913

Change-Id: Ib3132f2426a632ac45359918982ba20ba416761a
Signed-off-by: Automerger Merge Worker <[email protected]>
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index faf15b2..447f5f0 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
 {
   "git": {
-    "sha1": "bc457b179f4e4145d1bd4c61c1fddd871f8839b8"
+    "sha1": "f931de694a5478d7e4bd424613e6699f7d4f4e9f"
   },
   "path_in_vcs": "clap_derive"
 }
\ No newline at end of file
diff --git a/Android.bp b/Android.bp
index e9ae34e..ef1cb66 100644
--- a/Android.bp
+++ b/Android.bp
@@ -41,7 +41,7 @@
     name: "libclap_derive",
     crate_name: "clap_derive",
     cargo_env_compat: true,
-    cargo_pkg_version: "4.0.21",
+    cargo_pkg_version: "4.1.8",
     srcs: ["src/lib.rs"],
     edition: "2021",
     features: ["default"],
diff --git a/Cargo.toml b/Cargo.toml
index f63c7f0..be05b33 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,9 +11,9 @@
 
 [package]
 edition = "2021"
-rust-version = "1.60.0"
+rust-version = "1.64.0"
 name = "clap_derive"
-version = "4.0.21"
+version = "4.1.8"
 include = [
     "build.rs",
     "src/**/*",
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 27bf1e5..a32d823 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
 [package]
 name = "clap_derive"
-version = "4.0.21"
+version = "4.1.8"
 description = "Parse command line argument by defining a struct, derive crate."
 repository = "https://github.com/clap-rs/clap/tree/master/clap_derive"
 categories = ["command-line-interface", "development-tools::procedural-macro-helpers"]
@@ -11,18 +11,10 @@
   "derive",
   "proc_macro"
 ]
-license = "MIT OR Apache-2.0"
-edition = "2021"
-rust-version = "1.60.0"  # MSRV
-include = [
-  "build.rs",
-  "src/**/*",
-  "Cargo.toml",
-  "LICENSE*",
-  "README.md",
-  "benches/**/*",
-  "examples/**/*"
-]
+license.workspace = true
+edition.workspace = true
+rust-version.workspace = true
+include.workspace = true
 
 [package.metadata.docs.rs]
 targets = ["x86_64-unknown-linux-gnu"]
diff --git a/METADATA b/METADATA
index d3d0aa2..d2ca19f 100644
--- a/METADATA
+++ b/METADATA
@@ -11,13 +11,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/clap_derive/clap_derive-4.0.21.crate"
+    value: "https://static.crates.io/crates/clap_derive/clap_derive-4.1.8.crate"
   }
-  version: "4.0.21"
+  version: "4.1.8"
   license_type: NOTICE
   last_upgrade_date {
-    year: 2022
-    month: 11
-    day: 30
+    year: 2023
+    month: 3
+    day: 2
   }
 }
diff --git a/src/attr.rs b/src/attr.rs
index 5ea49a1..e282a8f 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -70,7 +70,7 @@
             AttrValue::Expr(_) | AttrValue::Call(_) => {
                 abort!(
                     self.name,
-                    "attribute `{}` can only accept string litersl",
+                    "attribute `{}` can only accept string literals",
                     self.name
                 )
             }
diff --git a/src/derives/args.rs b/src/derives/args.rs
index ad2a646..d3b3692 100644
--- a/src/derives/args.rs
+++ b/src/derives/args.rs
@@ -109,8 +109,8 @@
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
-        #[deny(clippy::correctness)]
         impl #impl_generics clap::FromArgMatches for #item_name #ty_generics #where_clause {
             fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
                 Self::from_arg_matches_mut(&mut __clap_arg_matches.clone())
@@ -144,8 +144,8 @@
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
-        #[deny(clippy::correctness)]
         impl #impl_generics clap::Args for #item_name #ty_generics #where_clause {
             fn group_id() -> Option<clap::Id> {
                 #group_id
@@ -187,7 +187,7 @@
                     (Ty::Option, Some(sub_type)) => sub_type,
                     _ => &field.ty,
                 };
-                let implicit_methods = if **ty == Ty::Option || override_required {
+                let implicit_methods = if **ty == Ty::Option {
                     quote!()
                 } else {
                     quote_spanned! { kind.span()=>
@@ -196,10 +196,20 @@
                     }
                 };
 
+                let override_methods = if override_required {
+                    quote_spanned! { kind.span()=>
+                        .subcommand_required(false)
+                        .arg_required_else_help(false)
+                    }
+                } else {
+                    quote!()
+                };
+
                 Some(quote! {
                     let #app_var = <#subcmd_type as clap::Subcommand>::augment_subcommands( #app_var );
                     let #app_var = #app_var
-                        #implicit_methods;
+                        #implicit_methods
+                        #override_methods;
                 })
             }
             Kind::Flatten(ty) => {
@@ -288,8 +298,16 @@
                         }
                     }
 
+                    Ty::VecVec | Ty::OptionVecVec => {
+                        quote_spanned! { ty.span() =>
+                            .value_name(#value_name)
+                            #value_parser
+                            #action
+                        }
+                    }
+
                     Ty::Other => {
-                        let required = item.find_default_method().is_none() && !override_required;
+                        let required = item.find_default_method().is_none();
                         // `ArgAction::takes_values` is assuming `ArgAction::default_value` will be
                         // set though that won't always be true but this should be good enough,
                         // otherwise we'll report an "arg required" error when unwrapping.
@@ -310,6 +328,13 @@
                 } else {
                     quote!()
                 };
+                let override_methods = if override_required {
+                    quote_spanned! { kind.span()=>
+                        .required(false)
+                    }
+                } else {
+                    quote!()
+                };
 
                 Some(quote_spanned! { field.span()=>
                     let #app_var = #app_var.arg({
@@ -321,6 +346,10 @@
 
                         let arg = arg
                             #explicit_methods;
+
+                        let arg = arg
+                            #override_methods;
+
                         arg
                     });
                 })
@@ -431,7 +460,9 @@
                     Ty::Unit |
                     Ty::Vec |
                     Ty::OptionOption |
-                    Ty::OptionVec => {
+                    Ty::OptionVec |
+                    Ty::VecVec |
+                    Ty::OptionVecVec => {
                         abort!(
                             ty.span(),
                             "{} types are not supported for subcommand",
@@ -470,7 +501,9 @@
                     Ty::Unit |
                     Ty::Vec |
                     Ty::OptionOption |
-                    Ty::OptionVec => {
+                    Ty::OptionVec |
+                    Ty::VecVec |
+                    Ty::OptionVecVec => {
                         abort!(
                             ty.span(),
                             "{} types are not supported for flatten",
@@ -609,8 +642,7 @@
     let id = item.id();
     let get_one = quote_spanned!(span=> remove_one::<#convert_type>);
     let get_many = quote_spanned!(span=> remove_many::<#convert_type>);
-    let deref = quote!(|s| s);
-    let parse = quote_spanned!(span=> |s| ::std::result::Result::Ok::<_, clap::Error>(s));
+    let get_occurrences = quote_spanned!(span=> remove_occurrences::<#convert_type>);
 
     // Give this identifier the same hygiene
     // as the `arg_matches` parameter definition. This
@@ -627,9 +659,6 @@
         Ty::Option => {
             quote_spanned! { ty.span()=>
                 #arg_matches.#get_one(#id)
-                    .map(#deref)
-                    .map(#parse)
-                    .transpose()?
             }
         }
 
@@ -637,8 +666,6 @@
             if #arg_matches.contains_id(#id) {
                 Some(
                     #arg_matches.#get_one(#id)
-                        .map(#deref)
-                        .map(#parse).transpose()?
                 )
             } else {
                 None
@@ -648,8 +675,7 @@
         Ty::OptionVec => quote_spanned! { ty.span()=>
             if #arg_matches.contains_id(#id) {
                 Some(#arg_matches.#get_many(#id)
-                    .map(|v| v.map(#deref).map::<::std::result::Result<#convert_type, clap::Error>, _>(#parse).collect::<::std::result::Result<Vec<_>, clap::Error>>())
-                    .transpose()?
+                    .map(|v| v.collect::<Vec<_>>())
                     .unwrap_or_else(Vec::new))
             } else {
                 None
@@ -659,18 +685,26 @@
         Ty::Vec => {
             quote_spanned! { ty.span()=>
                 #arg_matches.#get_many(#id)
-                    .map(|v| v.map(#deref).map::<::std::result::Result<#convert_type, clap::Error>, _>(#parse).collect::<::std::result::Result<Vec<_>, clap::Error>>())
-                    .transpose()?
+                    .map(|v| v.collect::<Vec<_>>())
                     .unwrap_or_else(Vec::new)
             }
         }
 
+        Ty::VecVec => quote_spanned! { ty.span()=>
+            #arg_matches.#get_occurrences(#id)
+                .map(|g| g.map(::std::iter::Iterator::collect).collect::<Vec<Vec<_>>>())
+                .unwrap_or_else(Vec::new)
+        },
+
+        Ty::OptionVecVec => quote_spanned! { ty.span()=>
+            #arg_matches.#get_occurrences(#id)
+                .map(|g| g.map(::std::iter::Iterator::collect).collect::<Vec<Vec<_>>>())
+        },
+
         Ty::Other => {
             quote_spanned! { ty.span()=>
                 #arg_matches.#get_one(#id)
-                    .map(#deref)
-                    .ok_or_else(|| clap::Error::raw(clap::error::ErrorKind::MissingRequiredArgument, format!("The following required argument was not provided: {}", #id)))
-                    .and_then(#parse)?
+                    .ok_or_else(|| clap::Error::raw(clap::error::ErrorKind::MissingRequiredArgument, format!("The following required argument was not provided: {}", #id)))?
             }
         }
     };
diff --git a/src/derives/into_app.rs b/src/derives/into_app.rs
index eabdfa3..dfb676a 100644
--- a/src/derives/into_app.rs
+++ b/src/derives/into_app.rs
@@ -36,8 +36,8 @@
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
-        #[deny(clippy::correctness)]
         impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
             fn command<'b>() -> clap::Command {
                 let #app_var = clap::Command::new(#name);
@@ -72,8 +72,8 @@
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
-        #[deny(clippy::correctness)]
         impl #impl_generics clap::CommandFactory for #item_name #ty_generics #where_clause {
             fn command<'b>() -> clap::Command {
                 let #app_var = clap::Command::new(#name)
@@ -85,6 +85,8 @@
             fn command_for_update<'b>() -> clap::Command {
                 let #app_var = clap::Command::new(#name);
                 <Self as clap::Subcommand>::augment_subcommands_for_update(#app_var)
+                    .subcommand_required(false)
+                    .arg_required_else_help(false)
             }
         }
     }
diff --git a/src/derives/subcommand.rs b/src/derives/subcommand.rs
index 009684b..ffe22ec 100644
--- a/src/derives/subcommand.rs
+++ b/src/derives/subcommand.rs
@@ -80,8 +80,8 @@
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
-        #[deny(clippy::correctness)]
         impl #impl_generics clap::FromArgMatches for #item_name #ty_generics #where_clause {
             fn from_arg_matches(__clap_arg_matches: &clap::ArgMatches) -> ::std::result::Result<Self, clap::Error> {
                 Self::from_arg_matches_mut(&mut __clap_arg_matches.clone())
@@ -106,8 +106,8 @@
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
-        #[deny(clippy::correctness)]
         impl #impl_generics clap::Subcommand for #item_name #ty_generics #where_clause {
             fn augment_subcommands <'b>(__clap_app: clap::Command) -> clap::Command {
                 #augmentation
@@ -244,16 +244,24 @@
                     };
                     let initial_app_methods = item.initial_top_level_methods();
                     let final_from_attrs = item.final_top_level_methods();
+                    let override_methods = if override_required {
+                        quote_spanned! { kind.span()=>
+                            .subcommand_required(false)
+                            .arg_required_else_help(false)
+                        }
+                    } else {
+                        quote!()
+                    };
                     let subcommand = quote! {
                         let #app_var = #app_var.subcommand({
                             #deprecations;
                             let #subcommand_var = clap::Command::new(#name);
-                            let #subcommand_var = #subcommand_var #initial_app_methods;
-                            let #subcommand_var = #arg_block;
                             let #subcommand_var = #subcommand_var
                                 .subcommand_required(true)
                                 .arg_required_else_help(true);
-                            #subcommand_var #final_from_attrs
+                            let #subcommand_var = #subcommand_var #initial_app_methods;
+                            let #subcommand_var = #arg_block;
+                            #subcommand_var #final_from_attrs #override_methods
                         });
                     };
                     Some(subcommand)
diff --git a/src/derives/value_enum.rs b/src/derives/value_enum.rs
index a1411d0..7a9d870 100644
--- a/src/derives/value_enum.rs
+++ b/src/derives/value_enum.rs
@@ -65,8 +65,8 @@
             clippy::nursery,
             clippy::cargo,
             clippy::suspicious_else_formatting,
+            clippy::almost_swapped,
         )]
-        #[deny(clippy::correctness)]
         impl clap::ValueEnum for #item_name {
             #value_variants
             #to_possible_value
diff --git a/src/item.rs b/src/item.rs
index a068e36..5e8272a 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -1121,7 +1121,7 @@
 fn default_action(field_type: &Type, span: Span) -> Method {
     let ty = Ty::from_syn_ty(field_type);
     let args = match *ty {
-        Ty::Vec | Ty::OptionVec => {
+        Ty::Vec | Ty::OptionVec | Ty::VecVec | Ty::OptionVecVec => {
             quote_spanned! { span=>
                 clap::ArgAction::Append
             }
diff --git a/src/utils/ty.rs b/src/utils/ty.rs
index 1cf0514..9349bc2 100644
--- a/src/utils/ty.rs
+++ b/src/utils/ty.rs
@@ -11,9 +11,11 @@
 pub enum Ty {
     Unit,
     Vec,
+    VecVec,
     Option,
     OptionOption,
     OptionVec,
+    OptionVecVec,
     Other,
 }
 
@@ -24,13 +26,13 @@
 
         if is_unit_ty(ty) {
             t(Unit)
-        } else if is_generic_ty(ty, "Vec") {
-            t(Vec)
+        } else if let Some(vt) = get_vec_ty(ty, Vec, VecVec) {
+            t(vt)
         } else if let Some(subty) = subty_if_name(ty, "Option") {
             if is_generic_ty(subty, "Option") {
                 t(OptionOption)
-            } else if is_generic_ty(subty, "Vec") {
-                t(OptionVec)
+            } else if let Some(vt) = get_vec_ty(subty, OptionVec, OptionVecVec) {
+                t(vt)
             } else {
                 t(Option)
             }
@@ -46,6 +48,8 @@
             Self::Option => "Option<T>",
             Self::OptionOption => "Option<Option<T>>",
             Self::OptionVec => "Option<Vec<T>>",
+            Self::VecVec => "Vec<Vec<T>>",
+            Self::OptionVecVec => "Option<Vec<Vec<T>>>",
             Self::Other => "...other...",
         }
     }
@@ -55,9 +59,13 @@
     let ty = Ty::from_syn_ty(field_ty);
     match *ty {
         Ty::Vec | Ty::Option => sub_type(field_ty).unwrap_or(field_ty),
-        Ty::OptionOption | Ty::OptionVec => {
+        Ty::OptionOption | Ty::OptionVec | Ty::VecVec => {
             sub_type(field_ty).and_then(sub_type).unwrap_or(field_ty)
         }
+        Ty::OptionVecVec => sub_type(field_ty)
+            .and_then(sub_type)
+            .and_then(sub_type)
+            .unwrap_or(field_ty),
         _ => field_ty,
     }
 }
@@ -139,3 +147,19 @@
 {
     iter.next().filter(|_| iter.next().is_none())
 }
+
+#[cfg(feature = "unstable-v5")]
+fn get_vec_ty(ty: &Type, vec_ty: Ty, vecvec_ty: Ty) -> Option<Ty> {
+    subty_if_name(ty, "Vec").map(|subty| {
+        if is_generic_ty(subty, "Vec") {
+            vecvec_ty
+        } else {
+            vec_ty
+        }
+    })
+}
+
+#[cfg(not(feature = "unstable-v5"))]
+fn get_vec_ty(ty: &Type, vec_ty: Ty, _vecvec_ty: Ty) -> Option<Ty> {
+    is_generic_ty(ty, "Vec").then_some(vec_ty)
+}