diff options
author | Haibo Huang <hhb@google.com> | 2021-02-10 04:52:53 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-02-10 04:52:53 +0000 |
commit | 2d142c33bcdba6f8e069246b7d729fb5cc22e718 (patch) | |
tree | 4aeae6a00a9f0854fbfabdb8eafa9e9d88d9a226 /src/valid.rs | |
parent | 87c70d003aafb4b828edafca2d118b7f4c5fa7e9 (diff) | |
parent | 64431b5d1a76ba08cec709959718f4d528ae72d5 (diff) | |
download | thiserror-impl-2d142c33bcdba6f8e069246b7d729fb5cc22e718.tar.gz |
Upgrade rust/crates/thiserror-impl to 1.0.23 am: 64431b5d1a
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/thiserror-impl/+/1582747
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: If96b85eb336765842f4292d3a4f12b689d234972
Diffstat (limited to 'src/valid.rs')
-rw-r--r-- | src/valid.rs | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/valid.rs b/src/valid.rs index ab20423..cbd9f41 100644 --- a/src/valid.rs +++ b/src/valid.rs @@ -188,10 +188,10 @@ fn check_field_attrs(fields: &[Field]) -> Result<()> { } } if let Some(source_field) = source_field.or(from_field) { - if contains_non_static_lifetime(source_field) { + if contains_non_static_lifetime(&source_field.ty) { return Err(Error::new_spanned( - source_field.original, - "non-static lifetimes are not allowed in the source of an error", + &source_field.original.ty, + "non-static lifetimes are not allowed in the source of an error, because std::error::Error requires the source is dyn Error + 'static", )); } } @@ -206,21 +206,28 @@ fn same_member(one: &Field, two: &Field) -> bool { } } -fn contains_non_static_lifetime(field: &Field) -> bool { - let ty = match field.ty { - Type::Path(ty) => ty, - _ => return false, // maybe implement later if there are common other cases - }; - let bracketed = match &ty.path.segments.last().unwrap().arguments { - PathArguments::AngleBracketed(bracketed) => bracketed, - _ => return false, - }; - for arg in &bracketed.args { - if let GenericArgument::Lifetime(lifetime) = arg { - if lifetime.ident != "static" { - return true; +fn contains_non_static_lifetime(ty: &Type) -> bool { + match ty { + Type::Path(ty) => { + let bracketed = match &ty.path.segments.last().unwrap().arguments { + PathArguments::AngleBracketed(bracketed) => bracketed, + _ => return false, + }; + for arg in &bracketed.args { + match arg { + GenericArgument::Type(ty) if contains_non_static_lifetime(ty) => return true, + GenericArgument::Lifetime(lifetime) if lifetime.ident != "static" => { + return true + } + _ => {} + } } + false } + Type::Reference(ty) => ty + .lifetime + .as_ref() + .map_or(false, |lifetime| lifetime.ident != "static"), + _ => false, // maybe implement later if there are common other cases } - false } |