aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs2
-rw-r--r--src/parse_assoc_type.rs4
-rw-r--r--src/transform.rs28
3 files changed, 15 insertions, 19 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6a1708f..a5253d3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -362,7 +362,7 @@ fn generate_blanket_impl(
}
fn path_is_assoc_type(path: &Path) -> bool {
- path.segments.first().unwrap().ident == "Self"
+ path.segments[0].ident == "Self"
}
fn match_assoc_type(item: TypeOrPath) -> bool {
diff --git a/src/parse_assoc_type.rs b/src/parse_assoc_type.rs
index 856735d..5bc86cb 100644
--- a/src/parse_assoc_type.rs
+++ b/src/parse_assoc_type.rs
@@ -58,10 +58,10 @@ pub fn parse_assoc_type(
if let PathSegment {
ident,
arguments: PathArguments::AngleBracketed(args),
- } = bound.path.segments.first().unwrap()
+ } = &bound.path.segments[0]
{
if ident == "Into" && args.args.len() == 1 {
- if let GenericArgument::Type(into_type) = args.args.first().unwrap() {
+ if let GenericArgument::Type(into_type) = &args.args[0] {
// provide a better error message for type A: Into<Self::B>
if iter_type(into_type).any(match_assoc_type) {
return Err((into_type.span(), AssocTypeParseError::AssocTypeInBound));
diff --git a/src/transform.rs b/src/transform.rs
index e9da115..0fee2e6 100644
--- a/src/transform.rs
+++ b/src/transform.rs
@@ -52,14 +52,13 @@ impl AssocTypeConversions<'_> {
}) = elem.as_mut()
{
if bounds.len() == 1 {
- if let TypeParamBound::Trait(bound) = bounds.first_mut().unwrap() {
+ if let TypeParamBound::Trait(bound) = &mut bounds[0] {
if bound.path.segments.len() == 1 {
- let first = bound.path.segments.first_mut().unwrap();
+ let first = &mut bound.path.segments[0];
if first.ident == "Iterator" {
if let PathArguments::AngleBracketed(args) = &mut first.arguments {
if args.args.len() == 1 {
- if let GenericArgument::Binding(binding) =
- args.args.first_mut().unwrap()
+ if let GenericArgument::Binding(binding) = &mut args.args[0]
{
if binding.ident == "Item"
&& iter_type(&binding.ty).any(match_assoc_type)
@@ -87,7 +86,7 @@ impl AssocTypeConversions<'_> {
}
if let Type::Path(TypePath { path, qself: None }) = type_ {
- let ident = &path.segments.first().unwrap().ident;
+ let ident = &path.segments[0].ident;
if ident == "Self" && path.segments.len() == 2 {
let ident = &path.segments.last().unwrap().ident;
@@ -98,12 +97,11 @@ impl AssocTypeConversions<'_> {
*type_ = dest_type.get_dest();
return Ok(dest_type.type_transformation());
} else if ident == "Option" && path.segments.len() == 1 {
- let first_seg = path.segments.first_mut().unwrap();
+ let first_seg = &mut path.segments[0];
if let PathArguments::AngleBracketed(args) = &mut first_seg.arguments {
if args.args.len() == 1 {
- if let GenericArgument::Type(generic_type) = args.args.first_mut().unwrap()
- {
+ if let GenericArgument::Type(generic_type) = &mut args.args[0] {
if iter_type(generic_type).any(match_assoc_type) {
return Ok(TypeTransform::Map(
self.parse_type_path(generic_type)?.into(),
@@ -113,7 +111,8 @@ impl AssocTypeConversions<'_> {
}
}
} else if ident == "Result" && path.segments.len() == 1 {
- let first_seg = path.segments.first_mut().unwrap();
+ let first_seg = &mut path.segments[0];
+
if let PathArguments::AngleBracketed(args) = &mut first_seg.arguments {
if args.args.len() == 2 {
let mut args_iter = args.args.iter_mut();
@@ -132,12 +131,11 @@ impl AssocTypeConversions<'_> {
}
}
} else if is_supported_collection(ident) && path.segments.len() == 1 {
- let first_seg = path.segments.first_mut().unwrap();
+ let first_seg = &mut path.segments[0];
if let PathArguments::AngleBracketed(args) = &mut first_seg.arguments {
if args.args.len() == 1 {
- if let GenericArgument::Type(generic_type) = args.args.first_mut().unwrap()
- {
+ if let GenericArgument::Type(generic_type) = &mut args.args[0] {
if iter_type(generic_type).any(match_assoc_type) {
return Ok(TypeTransform::Collection(
self.parse_type_path(generic_type)?.into(),
@@ -152,9 +150,7 @@ impl AssocTypeConversions<'_> {
let last_seg = path.segments.last_mut().unwrap();
if let PathArguments::AngleBracketed(args) = &mut last_seg.arguments {
if args.args.len() == 1 {
- if let GenericArgument::Type(generic_type) =
- args.args.first_mut().unwrap()
- {
+ if let GenericArgument::Type(generic_type) = &mut args.args[0] {
if iter_type(generic_type).any(match_assoc_type) {
return Ok(TypeTransform::Map(
self.parse_type_path(generic_type)?.into(),
@@ -248,7 +244,7 @@ fn dynamize_trait_bound(
type_param_transforms: &mut HashMap<Ident, Vec<TypeTransform>>,
) -> Result<(), (Span, MethodParseError)> {
if bound.path.segments.len() == 1 {
- let segment = bound.path.segments.first_mut().unwrap();
+ let segment = &mut bound.path.segments[0];
if let PathArguments::Parenthesized(args) = &mut segment.arguments {
if segment.ident == "Fn" || segment.ident == "FnOnce" || segment.ident == "FnMut" {