Skip to content

Commit 5cb9065

Browse files
committed
Improve array parse error messages
1 parent 2d0df23 commit 5cb9065

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

syntax/parse.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -752,22 +752,11 @@ fn parse_type_array(ty: &TypeArray, namespace: &Namespace) -> Result<Type> {
752752
let inner = parse_type(&ty.elem, namespace)?;
753753
match &ty.len {
754754
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-
}
761755
match &lit.lit {
762756
Lit::Int(len_token) => {
763757
let v = match len_token.base10_parse::<usize>() {
764758
Ok(n_v) => n_v,
765-
Err(_) => {
766-
return Err(Error::new_spanned(
767-
ty,
768-
"Cannot parse integer literal to base10",
769-
))
770-
}
759+
Err(err) => return Err(Error::new_spanned(len_token, err)),
771760
};
772761
Ok(Type::Array(Box::new(Array {
773762
bracket: ty.bracket_token,
@@ -777,12 +766,12 @@ fn parse_type_array(ty: &TypeArray, namespace: &Namespace) -> Result<Type> {
777766
len_token: len_token.clone(),
778767
})))
779768
}
780-
_ => Err(Error::new_spanned(ty, "length literal must be a integer")),
769+
_ => Err(Error::new_spanned(lit, "array length must be an integer literal")),
781770
}
782771
}
783772
_ => Err(Error::new_spanned(
784-
ty,
785-
"only literal is currently supported in len field",
773+
&ty.len,
774+
"unsupported expression, array length must be an integer literal",
786775
)),
787776
}
788777
}

0 commit comments

Comments
 (0)