chore: clippy warnings
This commit is contained in:
parent
ac14512706
commit
b3266fb837
|
@ -135,7 +135,7 @@ Find more on the [Aiken's user manual](https://aiken-lang.org).
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(path: PathBuf, contents: &str) -> miette::Result<()> {
|
fn write(path: PathBuf, contents: &str) -> miette::Result<()> {
|
||||||
let mut f = fs::File::create(&path).into_diagnostic()?;
|
let mut f = fs::File::create(path).into_diagnostic()?;
|
||||||
|
|
||||||
f.write_all(contents.as_bytes()).into_diagnostic()?;
|
f.write_all(contents.as_bytes()).into_diagnostic()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub fn exec(
|
||||||
let mut program = if cbor {
|
let mut program = if cbor {
|
||||||
let cbor_hex = std::fs::read_to_string(&script).into_diagnostic()?;
|
let cbor_hex = std::fs::read_to_string(&script).into_diagnostic()?;
|
||||||
|
|
||||||
let raw_cbor = hex::decode(&cbor_hex).into_diagnostic()?;
|
let raw_cbor = hex::decode(cbor_hex).into_diagnostic()?;
|
||||||
|
|
||||||
let prog = Program::<FakeNamedDeBruijn>::from_cbor(&raw_cbor, &mut Vec::new())
|
let prog = Program::<FakeNamedDeBruijn>::from_cbor(&raw_cbor, &mut Vec::new())
|
||||||
.into_diagnostic()?;
|
.into_diagnostic()?;
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub fn exec(
|
||||||
format!("{}.flat", input.file_stem().unwrap().to_str().unwrap())
|
format!("{}.flat", input.file_stem().unwrap().to_str().unwrap())
|
||||||
};
|
};
|
||||||
|
|
||||||
fs::write(&out_name, &bytes).into_diagnostic()?;
|
fs::write(out_name, &bytes).into_diagnostic()?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let cbor = program.to_hex().into_diagnostic()?;
|
let cbor = program.to_hex().into_diagnostic()?;
|
||||||
|
@ -75,7 +75,7 @@ pub fn exec(
|
||||||
format!("{}.cbor", input.file_stem().unwrap().to_str().unwrap())
|
format!("{}.cbor", input.file_stem().unwrap().to_str().unwrap())
|
||||||
};
|
};
|
||||||
|
|
||||||
fs::write(&out_name, &cbor).into_diagnostic()?;
|
fs::write(out_name, &cbor).into_diagnostic()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub fn exec(
|
||||||
format!("{}.uplc", input.file_stem().unwrap().to_str().unwrap())
|
format!("{}.uplc", input.file_stem().unwrap().to_str().unwrap())
|
||||||
};
|
};
|
||||||
|
|
||||||
fs::write(&out_name, pretty).into_diagnostic()?;
|
fs::write(out_name, pretty).into_diagnostic()?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,9 @@ impl telemetry::EventListener for Terminal {
|
||||||
telemetry::Event::ParsingProjectFiles => {
|
telemetry::Event::ParsingProjectFiles => {
|
||||||
println!("{}", "...Parsing project files".bold().purple());
|
println!("{}", "...Parsing project files".bold().purple());
|
||||||
}
|
}
|
||||||
|
telemetry::Event::WaitingForBuildDirLock => {
|
||||||
|
println!("{}", "...Waiting for build directory lock".bold().purple());
|
||||||
|
}
|
||||||
telemetry::Event::TypeChecking => {
|
telemetry::Event::TypeChecking => {
|
||||||
println!("{}", "...Type-checking project".bold().purple());
|
println!("{}", "...Type-checking project".bold().purple());
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,10 @@ pub struct Comment<'a> {
|
||||||
impl<'a> From<(&Span, &'a str)> for Comment<'a> {
|
impl<'a> From<(&Span, &'a str)> for Comment<'a> {
|
||||||
fn from(src: (&Span, &'a str)) -> Comment<'a> {
|
fn from(src: (&Span, &'a str)) -> Comment<'a> {
|
||||||
let start = src.0.start;
|
let start = src.0.start;
|
||||||
let end = src.0.end as usize;
|
let end = src.0.end;
|
||||||
Comment {
|
Comment {
|
||||||
start,
|
start,
|
||||||
content: src
|
content: src.1.get(start..end).expect("From span to comment"),
|
||||||
.1
|
|
||||||
.get(start as usize..end)
|
|
||||||
.expect("From span to comment"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -509,7 +509,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||||
.push(Warning::NoFieldsRecordUpdate { location });
|
.push(Warning::NoFieldsRecordUpdate { location });
|
||||||
}
|
}
|
||||||
|
|
||||||
if arguments.len() == field_map.arity as usize {
|
if arguments.len() == field_map.arity {
|
||||||
self.environment
|
self.environment
|
||||||
.warnings
|
.warnings
|
||||||
.push(Warning::AllFieldsRecordUpdate { location });
|
.push(Warning::AllFieldsRecordUpdate { location });
|
||||||
|
|
|
@ -44,11 +44,11 @@ impl FieldMap {
|
||||||
let mut seen_labels = std::collections::HashSet::new();
|
let mut seen_labels = std::collections::HashSet::new();
|
||||||
let mut unknown_labels = Vec::new();
|
let mut unknown_labels = Vec::new();
|
||||||
|
|
||||||
if self.arity as usize != args.len() {
|
if self.arity != args.len() {
|
||||||
return Err(Error::IncorrectArity {
|
return Err(Error::IncorrectArity {
|
||||||
labels: self.incorrect_arity_labels(args),
|
labels: self.incorrect_arity_labels(args),
|
||||||
location,
|
location,
|
||||||
expected: self.arity as usize,
|
expected: self.arity,
|
||||||
given: args.len(),
|
given: args.len(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ impl FieldMap {
|
||||||
};
|
};
|
||||||
|
|
||||||
// If the argument is already in the right place
|
// If the argument is already in the right place
|
||||||
if position as usize == i {
|
if position == i {
|
||||||
seen_labels.insert(label.clone());
|
seen_labels.insert(label.clone());
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
|
@ -117,7 +117,7 @@ impl FieldMap {
|
||||||
|
|
||||||
seen_labels.insert(label.clone());
|
seen_labels.insert(label.clone());
|
||||||
|
|
||||||
args.swap(position as usize, i);
|
args.swap(position, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -438,13 +438,13 @@ impl<'a, 'b> PatternTyper<'a, 'b> {
|
||||||
if with_spread {
|
if with_spread {
|
||||||
// Using the spread operator when you have already provided variables for all of the
|
// Using the spread operator when you have already provided variables for all of the
|
||||||
// record's fields throws an error
|
// record's fields throws an error
|
||||||
if pattern_args.len() == field_map.arity as usize {
|
if pattern_args.len() == field_map.arity {
|
||||||
return Err(Error::UnnecessarySpreadOperator {
|
return Err(Error::UnnecessarySpreadOperator {
|
||||||
location: Span {
|
location: Span {
|
||||||
start: location.end - 3,
|
start: location.end - 3,
|
||||||
end: location.end - 1,
|
end: location.end - 1,
|
||||||
},
|
},
|
||||||
arity: field_map.arity as usize,
|
arity: field_map.arity,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,7 +465,7 @@ impl<'a, 'b> PatternTyper<'a, 'b> {
|
||||||
.position(|a| a.label.is_some())
|
.position(|a| a.label.is_some())
|
||||||
.unwrap_or(pattern_args.len());
|
.unwrap_or(pattern_args.len());
|
||||||
|
|
||||||
while pattern_args.len() < field_map.arity as usize {
|
while pattern_args.len() < field_map.arity {
|
||||||
let new_call_arg = CallArg {
|
let new_call_arg = CallArg {
|
||||||
value: Pattern::Discard {
|
value: Pattern::Discard {
|
||||||
name: "_".to_string(),
|
name: "_".to_string(),
|
||||||
|
|
|
@ -8,7 +8,7 @@ pub struct LineNumbers {
|
||||||
impl LineNumbers {
|
impl LineNumbers {
|
||||||
pub fn new(src: &str) -> Self {
|
pub fn new(src: &str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
length: src.len() as usize,
|
length: src.len(),
|
||||||
line_starts: std::iter::once(0)
|
line_starts: std::iter::once(0)
|
||||||
.chain(src.match_indices('\n').map(|(i, _)| i + 1))
|
.chain(src.match_indices('\n').map(|(i, _)| i + 1))
|
||||||
.collect(),
|
.collect(),
|
||||||
|
@ -19,20 +19,14 @@ impl LineNumbers {
|
||||||
pub fn line_number(&self, byte_index: usize) -> usize {
|
pub fn line_number(&self, byte_index: usize) -> usize {
|
||||||
self.line_starts
|
self.line_starts
|
||||||
.binary_search(&byte_index)
|
.binary_search(&byte_index)
|
||||||
.unwrap_or_else(|next_line| next_line - 1) as usize
|
.unwrap_or_else(|next_line| next_line - 1)
|
||||||
+ 1
|
+ 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: handle unicode characters that may be more than 1 byte in width
|
// TODO: handle unicode characters that may be more than 1 byte in width
|
||||||
pub fn line_and_column_number(&self, byte_index: usize) -> LineColumn {
|
pub fn line_and_column_number(&self, byte_index: usize) -> LineColumn {
|
||||||
let line = self.line_number(byte_index);
|
let line = self.line_number(byte_index);
|
||||||
let column = byte_index
|
let column = byte_index - self.line_starts.get(line - 1).copied().unwrap_or_default() + 1;
|
||||||
- self
|
|
||||||
.line_starts
|
|
||||||
.get(line as usize - 1)
|
|
||||||
.copied()
|
|
||||||
.unwrap_or_default()
|
|
||||||
+ 1;
|
|
||||||
LineColumn { line, column }
|
LineColumn { line, column }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +34,7 @@ impl LineNumbers {
|
||||||
/// 0 indexed line and character to byte index
|
/// 0 indexed line and character to byte index
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn byte_index(&self, line: usize, character: usize) -> usize {
|
pub fn byte_index(&self, line: usize, character: usize) -> usize {
|
||||||
match self.line_starts.get((line) as usize) {
|
match self.line_starts.get(line) {
|
||||||
Some(line_index) => *line_index + character,
|
Some(line_index) => *line_index + character,
|
||||||
None => self.length,
|
None => self.length,
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ where
|
||||||
pub fn to_hex(&self) -> Result<String, en::Error> {
|
pub fn to_hex(&self) -> Result<String, en::Error> {
|
||||||
let bytes = self.to_cbor()?;
|
let bytes = self.to_cbor()?;
|
||||||
|
|
||||||
let hex = hex::encode(&bytes);
|
let hex = hex::encode(bytes);
|
||||||
|
|
||||||
Ok(hex)
|
Ok(hex)
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ peg::parser! {
|
||||||
= "(" _* "error" _* ")" { Term::Error }
|
= "(" _* "error" _* ")" { Term::Error }
|
||||||
|
|
||||||
rule constant_integer() -> Constant
|
rule constant_integer() -> Constant
|
||||||
= "integer" _+ i:big_number() { Constant::Integer(i as i128) }
|
= "integer" _+ i:big_number() { Constant::Integer(i) }
|
||||||
|
|
||||||
rule constant_bytestring() -> Constant
|
rule constant_bytestring() -> Constant
|
||||||
= "bytestring" _+ bs:bytestring() { Constant::ByteString(bs) }
|
= "bytestring" _+ bs:bytestring() { Constant::ByteString(bs) }
|
||||||
|
|
Loading…
Reference in New Issue