Run linter

This commit is contained in:
ayazhafiz 2022-01-31 18:18:14 -05:00
parent f7a055fc78
commit 9f72b2710f
9 changed files with 66 additions and 32 deletions

View File

@ -188,6 +188,17 @@ pub fn to_pattern2<'a>(
ptype => unsupported_pattern(env, ptype, region),
},
IntLiteral(string, _bound) => match pattern_type {
WhenBranch => match finish_parsing_int(string) {
Err(_error) => {
let problem = MalformedPatternProblem::MalformedInt;
malformed_pattern(env, problem, region)
}
Ok(int) => Pattern2::NumLiteral(env.var_store.fresh(), int),
},
ptype => unsupported_pattern(env, ptype, region),
},
NumLiteral(string, _bound) => match pattern_type {
WhenBranch => match finish_parsing_int(string) {
Err(_error) => {

View File

@ -486,6 +486,7 @@ impl<'a> RemoveSpaces<'a> for Expr<'a> {
match *self {
Expr::Float(a, bound) => Expr::Float(a, bound),
Expr::Num(a, bound) => Expr::Num(a, bound),
Expr::Int(a, bound) => Expr::Int(a, bound),
Expr::NonBase10Int {
string,
base,
@ -584,6 +585,7 @@ impl<'a> RemoveSpaces<'a> for Pattern<'a> {
bound,
},
Pattern::FloatLiteral(a, bound) => Pattern::FloatLiteral(a, bound),
Pattern::IntLiteral(a, bound) => Pattern::IntLiteral(a, bound),
Pattern::StrLiteral(a) => Pattern::StrLiteral(a),
Pattern::Underscore(a) => Pattern::Underscore(a),
Pattern::Malformed(a) => Pattern::Malformed(a),

View File

@ -338,10 +338,10 @@ impl TypedNumericBound for NumericBound<FloatWidth> {
impl TypedNumericBound for NumericBound<NumWidth> {
fn num_type(&self) -> Type {
match self {
&NumericBound::None { width_variable } => num_num(Type::Variable(width_variable)),
&NumericBound::Exact(NumWidth::Int(iw)) => NumericBound::Exact(iw).num_type(),
&NumericBound::Exact(NumWidth::Float(fw)) => NumericBound::Exact(fw).num_type(),
match *self {
NumericBound::None { width_variable } => num_num(Type::Variable(width_variable)),
NumericBound::Exact(NumWidth::Int(iw)) => NumericBound::Exact(iw).num_type(),
NumericBound::Exact(NumWidth::Float(fw)) => NumericBound::Exact(fw).num_type(),
}
}

View File

@ -30,6 +30,7 @@ impl<'a> Formattable for Expr<'a> {
// These expressions never have newlines
Float(..)
| Num(..)
| Int(..)
| NonBase10Int { .. }
| Access(_, _)
| AccessorFunction(_)
@ -197,19 +198,27 @@ impl<'a> Formattable for Expr<'a> {
buf.push(')');
}
}
Num(string, bound) => {
&Num(string, bound) => {
buf.indent(indent);
buf.push_str(string);
if let &NumericBound::Exact(width) = bound {
if let NumericBound::Exact(width) = bound {
buf.push_str(&width.to_string());
}
}
Float(string, bound) => {
&Float(string, bound) => {
buf.indent(indent);
buf.push_str(string);
if let &NumericBound::Exact(width) = bound {
if let NumericBound::Exact(width) = bound {
buf.push_str(&width.to_string());
}
}
&Int(string, bound) => {
buf.indent(indent);
buf.push_str(string);
if let NumericBound::Exact(width) = bound {
buf.push_str(&width.to_string());
}
}
@ -217,14 +226,14 @@ impl<'a> Formattable for Expr<'a> {
buf.indent(indent);
buf.push_str(string)
}
NonBase10Int {
&NonBase10Int {
base,
string,
is_negative,
bound,
} => {
buf.indent(indent);
if *is_negative {
if is_negative {
buf.push('-');
}
@ -237,7 +246,7 @@ impl<'a> Formattable for Expr<'a> {
buf.push_str(string);
if let &NumericBound::Exact(width) = bound {
if let NumericBound::Exact(width) = bound {
buf.push_str(&width.to_string());
}
}

View File

@ -32,6 +32,7 @@ impl<'a> Formattable for Pattern<'a> {
| Pattern::PrivateTag(_)
| Pattern::Apply(_, _)
| Pattern::NumLiteral(..)
| Pattern::IntLiteral(..)
| Pattern::NonBase10Literal { .. }
| Pattern::FloatLiteral(..)
| Pattern::StrLiteral(_)
@ -116,21 +117,28 @@ impl<'a> Formattable for Pattern<'a> {
loc_pattern.format(buf, indent);
}
NumLiteral(string, bound) => {
&NumLiteral(string, bound) => {
buf.indent(indent);
buf.push_str(string);
if let &NumericBound::Exact(width) = bound {
if let NumericBound::Exact(width) = bound {
buf.push_str(&width.to_string());
}
}
NonBase10Literal {
&IntLiteral(string, bound) => {
buf.indent(indent);
buf.push_str(string);
if let NumericBound::Exact(width) = bound {
buf.push_str(&width.to_string());
}
}
&NonBase10Literal {
base,
string,
is_negative,
bound,
} => {
buf.indent(indent);
if *is_negative {
if is_negative {
buf.push('-');
}
@ -143,14 +151,14 @@ impl<'a> Formattable for Pattern<'a> {
buf.push_str(string);
if let &NumericBound::Exact(width) = bound {
if let NumericBound::Exact(width) = bound {
buf.push_str(&width.to_string());
}
}
FloatLiteral(string, bound) => {
&FloatLiteral(string, bound) => {
buf.indent(indent);
buf.push_str(string);
if let &NumericBound::Exact(width) = bound {
if let NumericBound::Exact(width) = bound {
buf.push_str(&width.to_string());
}
}

View File

@ -515,20 +515,20 @@ fn numeric_negate_expression<'a, T>(
let start = state.pos();
let region = Region::new(start, expr.region.end());
let new_expr = match &expr.value {
&Expr::Num(string, bound) => {
let new_expr = match expr.value {
Expr::Num(string, bound) => {
let new_string =
unsafe { std::str::from_utf8_unchecked(&state.bytes()[..string.len() + 1]) };
Expr::Num(new_string, bound)
}
&Expr::Float(string, bound) => {
Expr::Float(string, bound) => {
let new_string =
unsafe { std::str::from_utf8_unchecked(&state.bytes()[..string.len() + 1]) };
Expr::Float(new_string, bound)
}
&Expr::NonBase10Int {
Expr::NonBase10Int {
string,
base,
is_negative,

View File

@ -79,7 +79,7 @@ macro_rules! parse_num_suffix {
}
}
fn get_int_suffix<'a>(bytes: &'a [u8]) -> Option<(IntWidth, usize)> {
fn get_int_suffix(bytes: &[u8]) -> Option<(IntWidth, usize)> {
parse_num_suffix! {
bytes,
b"u8", IntWidth::U8
@ -97,7 +97,7 @@ fn get_int_suffix<'a>(bytes: &'a [u8]) -> Option<(IntWidth, usize)> {
None
}
fn get_float_suffix<'a>(bytes: &'a [u8]) -> Option<(FloatWidth, usize)> {
fn get_float_suffix(bytes: &[u8]) -> Option<(FloatWidth, usize)> {
parse_num_suffix! {
bytes,
b"dec", FloatWidth::Dec
@ -107,7 +107,7 @@ fn get_float_suffix<'a>(bytes: &'a [u8]) -> Option<(FloatWidth, usize)> {
None
}
fn get_num_suffix<'a>(bytes: &'a [u8]) -> Option<(NumWidth, usize)> {
fn get_num_suffix(bytes: &[u8]) -> Option<(NumWidth, usize)> {
(get_int_suffix(bytes).map(|(iw, l)| (NumWidth::Int(iw), l)))
.or_else(|| get_float_suffix(bytes).map(|(fw, l)| (NumWidth::Float(fw), l)))
}
@ -205,6 +205,7 @@ fn chomp_number_dec<'a>(
}
}
#[allow(clippy::type_complexity)]
fn chomp_number<'a>(
mut bytes: &'a [u8],
state: State<'a>,

View File

@ -318,8 +318,8 @@ fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, pa
match *symbol {
Symbol::NUM_NUM => {
let content = get_single_arg(subs, args);
match content {
&Alias(nested, args, _actual) => match nested {
match *content {
Alias(nested, args, _actual) => match nested {
Symbol::NUM_INTEGER => {
write_integer(
env,
@ -361,9 +361,9 @@ fn write_content(env: &Env, content: &Content, subs: &Subs, buf: &mut String, pa
let arg_var = subs[arg_var_index];
let content = subs.get_content_without_compacting(arg_var);
match content {
&Alias(Symbol::NUM_BINARY32, _, _) => buf.push_str("F32"),
&Alias(Symbol::NUM_BINARY64, _, _) => buf.push_str("F64"),
match *content {
Alias(Symbol::NUM_BINARY32, _, _) => buf.push_str("F32"),
Alias(Symbol::NUM_BINARY64, _, _) => buf.push_str("F64"),
_ => write_parens!(write_parens, buf, {
buf.push_str("Float ");
write_content(env, content, subs, buf, parens);

View File

@ -1043,7 +1043,7 @@ fn byte_to_ast<'a, M: AppMemory>(env: &Env<'a, '_, M>, value: u8, content: &Cont
if let TagName::Private(Symbol::NUM_AT_NUM) = &tag_name {
return Expr::Num(
env.arena.alloc_str(&value.to_string()),
NumericBound::None,
NumericBound::None { width_variable: () },
);
}
@ -1198,7 +1198,10 @@ fn num_to_ast<'a, M: AppMemory>(
/// This is centralized in case we want to format it differently later,
/// e.g. adding underscores for large numbers
fn number_literal_to_ast<T: std::fmt::Display>(arena: &Bump, num: T) -> Expr<'_> {
Expr::Num(arena.alloc(format!("{}", num)), NumericBound::None)
Expr::Num(
arena.alloc(format!("{}", num)),
NumericBound::None { width_variable: () },
)
}
#[cfg(target_endian = "little")]