Skip to content

Commit 2d0df23

Browse files
committed
Reorder array parsing near slice
1 parent c351dc4 commit 2d0df23

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

syntax/parse.rs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -639,52 +639,13 @@ fn parse_type(ty: &RustType, namespace: &Namespace) -> Result<Type> {
639639
RustType::Reference(ty) => parse_type_reference(ty, namespace),
640640
RustType::Path(ty) => parse_type_path(ty, namespace),
641641
RustType::Slice(ty) => parse_type_slice(ty, namespace),
642+
RustType::Array(ty) => parse_type_array(ty, namespace),
642643
RustType::BareFn(ty) => parse_type_fn(ty, namespace),
643644
RustType::Tuple(ty) if ty.elems.is_empty() => Ok(Type::Void(ty.paren_token.span)),
644-
RustType::Array(ty) => parse_type_array(ty, namespace),
645645
_ => Err(Error::new_spanned(ty, "unsupported type")),
646646
}
647647
}
648648

649-
fn parse_type_array(ty: &TypeArray, namespace: &Namespace) -> Result<Type> {
650-
let inner = parse_type(&ty.elem, namespace)?;
651-
match &ty.len {
652-
Expr::Lit(lit) => {
653-
if !lit.attrs.is_empty() {
654-
return Err(Error::new_spanned(
655-
ty,
656-
"attribute not allowed in length field",
657-
));
658-
}
659-
match &lit.lit {
660-
Lit::Int(len_token) => {
661-
let v = match len_token.base10_parse::<usize>() {
662-
Ok(n_v) => n_v,
663-
Err(_) => {
664-
return Err(Error::new_spanned(
665-
ty,
666-
"Cannot parse integer literal to base10",
667-
))
668-
}
669-
};
670-
Ok(Type::Array(Box::new(Array {
671-
bracket: ty.bracket_token,
672-
inner,
673-
semi_token: ty.semi_token,
674-
len: v,
675-
len_token: len_token.clone(),
676-
})))
677-
}
678-
_ => Err(Error::new_spanned(ty, "length literal must be a integer")),
679-
}
680-
}
681-
_ => Err(Error::new_spanned(
682-
ty,
683-
"only literal is currently supported in len field",
684-
)),
685-
}
686-
}
687-
688649
fn parse_type_reference(ty: &TypeReference, namespace: &Namespace) -> Result<Type> {
689650
let inner = parse_type(&ty.elem, namespace)?;
690651
let which = match &inner {
@@ -787,6 +748,45 @@ fn parse_type_slice(ty: &TypeSlice, namespace: &Namespace) -> Result<Type> {
787748
})))
788749
}
789750

751+
fn parse_type_array(ty: &TypeArray, namespace: &Namespace) -> Result<Type> {
752+
let inner = parse_type(&ty.elem, namespace)?;
753+
match &ty.len {
754+
Expr::Lit(lit) => {
755+
if !lit.attrs.is_empty() {
756+
return Err(Error::new_spanned(
757+
ty,
758+
"attribute not allowed in length field",
759+
));
760+
}
761+
match &lit.lit {
762+
Lit::Int(len_token) => {
763+
let v = match len_token.base10_parse::<usize>() {
764+
Ok(n_v) => n_v,
765+
Err(_) => {
766+
return Err(Error::new_spanned(
767+
ty,
768+
"Cannot parse integer literal to base10",
769+
))
770+
}
771+
};
772+
Ok(Type::Array(Box::new(Array {
773+
bracket: ty.bracket_token,
774+
inner,
775+
semi_token: ty.semi_token,
776+
len: v,
777+
len_token: len_token.clone(),
778+
})))
779+
}
780+
_ => Err(Error::new_spanned(ty, "length literal must be a integer")),
781+
}
782+
}
783+
_ => Err(Error::new_spanned(
784+
ty,
785+
"only literal is currently supported in len field",
786+
)),
787+
}
788+
}
789+
790790
fn parse_type_fn(ty: &TypeBareFn, namespace: &Namespace) -> Result<Type> {
791791
if ty.lifetimes.is_some() {
792792
return Err(Error::new_spanned(

0 commit comments

Comments
 (0)