Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new clippy warnings #107

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lexpr-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use quote::quote;
pub fn sexp(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let output = match expand(TokenStream::from(input)) {
Err(e) => {
let msg = format!("could not parse s-expression: {:?}", e);
let msg = format!("could not parse s-expression: {}", e);
quote! { compile_error!(#msg) }
}
Ok(output) => output,
Expand Down
24 changes: 24 additions & 0 deletions lexpr-macros/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt;

use crate::value::Value;

use proc_macro2::{Delimiter, Literal, Spacing, TokenStream, TokenTree};
Expand All @@ -17,6 +19,28 @@ pub enum ParseError {
UnexpectedEnd,
}

impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ExpectedStringLiteral(literal) => {
write!(f, "expected string literal `{}`", literal)
}
Self::UnexpectedToken(tt) => write!(f, "unexpected token `{}`", tt),
Self::UnexpectedChar(c) => write!(f, "unexpected character `{}`", c),
Self::UnexpectedDelimiter(delim) => {
let delim = match delim {
Delimiter::Brace => "brace",
Delimiter::Bracket => "bracket",
Delimiter::Parenthesis => "parenthesis",
Delimiter::None => "non",
};
write!(f, "unexpected {}-delimited expression", delim)
}
Self::UnexpectedEnd => write!(f, "unexpected end of input"),
}
}
}

impl Parser {
fn new(tokens: Vec<TokenTree>) -> Self {
Parser { tokens, index: 0 }
Expand Down
3 changes: 3 additions & 0 deletions lexpr/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Changes:
octothorpe, as in Emacs Lisp and Common Lisp, allowing for a
less-noisy spelling; e.g.: `:foo` instead of `#:foo`. Feature
request (#99) and initial implementation (#96) by @samuel-jimenez.
- The errors produced by the `sexp!` macro now are a bit more
human-oriented, as the `lexpr-macros` `ParseError` type gained a
`Display` implementation.

Maintenance-related changes:

Expand Down
4 changes: 2 additions & 2 deletions lexpr/src/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Number {
#[inline]
pub fn is_i64(&self) -> bool {
match self.n {
N::PosInt(v) => v <= i64::max_value() as u64,
N::PosInt(v) => v <= i64::MAX as u64,
N::NegInt(_) => true,
N::Float(_) => false,
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl Number {
pub fn as_i64(&self) -> Option<i64> {
match self.n {
N::PosInt(n) => {
if n <= i64::max_value() as u64 {
if n <= i64::MAX as u64 {
Some(n as i64)
} else {
None
Expand Down
3 changes: 1 addition & 2 deletions lexpr/src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use std::borrow::Borrow;
use std::io;
use std::str;
use std::u64;

use error::ErrorCode;
use read::{ElispStr, Reference};
Expand Down Expand Up @@ -1209,7 +1208,7 @@ impl<'de, R: Read<'de>> Parser<R> {
self.eat_char();
let digit = i32::from(c - b'0');

if overflow!(exp * 10 + digit, i32::max_value()) {
if overflow!(exp * 10 + digit, i32::MAX) {
return self.parse_exponent_overflow(positive, significand, positive_exp);
}

Expand Down
2 changes: 1 addition & 1 deletion lexpr/src/parse/read.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::ops::Deref;
use std::{char, cmp, io, str, u32};
use std::{char, cmp, io, str};

use super::error::{Error, ErrorCode, Result};
use super::iter::LineColIterator;
Expand Down
2 changes: 1 addition & 1 deletion lexpr/tests/sexp-macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn test_unquote() {
assert_eq!(sexp!((1 2 ,three)), Value::list(vec![1, 2, 3]));
assert_eq!(sexp!((1 2 . ,three)), Value::append(vec![1, 2], 3));

let big = i64::max_value();
let big = i64::MAX;
assert_eq!(
sexp!((b . ,big)),
Value::cons(Value::symbol("b"), Value::from(big))
Expand Down
Loading