Skip to content

Commit a589638

Browse files
committed
(main) rev: upgrade to rust 2024
1 parent 13f9a92 commit a589638

File tree

23 files changed

+96
-86
lines changed

23 files changed

+96
-86
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "c-parser"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
authors = ["Tom Webber"]
66
license-file = "LICENSE"
77
repository = "https://www.github.com/t-webber/c-parser"

src/errors/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<T> Res<T> {
4747
/// ```
4848
/// use std::fs;
4949
///
50-
/// use c_parser::{lex_file, Location};
50+
/// use c_parser::{Location, lex_file};
5151
///
5252
/// let content = "int m@in() { }";
5353
/// let res = lex_file(&content, &mut Location::from("filename.c"));

src/lexer/lex_content.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use LexingState::*;
33

44
use super::state::api::{
5-
end_current, handle_escape, CommentState, EscapeState, LexingState, SymbolState
5+
CommentState, EscapeState, LexingState, SymbolState, end_current, handle_escape
66
};
77
use super::types::api::{LexingData, Token};
88
use crate::errors::api::{Location, Res};

src/lexer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod api {
33

44
pub use super::lex_content::lex_file;
55
pub use super::numbers::api::Number;
6-
pub use super::types::api::{display_tokens, Keyword, Symbol, Token, TokenValue};
6+
pub use super::types::api::{Keyword, Symbol, Token, TokenValue, display_tokens};
77
}
88

99
mod lex_content;

src/lexer/numbers/base/binary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::super::macros::parse_int_from_radix;
22
use super::super::parse::OverParseRes;
33
#[allow(clippy::wildcard_imports)]
44
use super::super::types::arch_types::*;
5-
use super::super::types::{Number, NumberType, ERR_PREFIX};
5+
use super::super::types::{ERR_PREFIX, Number, NumberType};
66
use crate::errors::api::Location;
77

88
/// Parses a binary value.

src/lexer/numbers/base/decimal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::str::FromStr;
44
use super::super::parse::OverParseRes;
55
#[allow(clippy::wildcard_imports)]
66
use super::super::types::arch_types::*;
7-
use super::super::types::{Number, NumberType, ERR_PREFIX};
7+
use super::super::types::{ERR_PREFIX, Number, NumberType};
88
use crate::errors::api::{CompileError, Location};
99

1010
macro_rules! parse_number {

src/lexer/numbers/base/hexadecimal.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::super::macros::parse_int_from_radix;
44
use super::super::parse::OverParseRes;
55
#[allow(clippy::wildcard_imports)]
66
use super::super::types::arch_types::*;
7-
use super::super::types::{Number, NumberType, ERR_PREFIX};
7+
use super::super::types::{ERR_PREFIX, Number, NumberType};
88
use crate::errors::api::{CompileError, Location};
99

1010
macro_rules! impl_floating_point {
@@ -306,10 +306,6 @@ pub fn to_hex_value(
306306
#[expect(clippy::float_arithmetic)]
307307
let res =
308308
parse_hexadecimal_float!(&mut overflow, nb_type, float_data, Float Double LongDouble);
309-
if overflow {
310-
res.add_overflow()
311-
} else {
312-
res
313-
}
309+
if overflow { res.add_overflow() } else { res }
314310
}
315311
}

src/lexer/numbers/base/octal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::super::macros::parse_int_from_radix;
22
use super::super::parse::OverParseRes;
33
#[allow(clippy::wildcard_imports)]
44
use super::super::types::arch_types::*;
5-
use super::super::types::{Number, NumberType, ERR_PREFIX};
5+
use super::super::types::{ERR_PREFIX, Number, NumberType};
66
use crate::errors::api::Location;
77

88
/// Parses an octal value.

src/lexer/numbers/from_literal.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::base::{binary, decimal, hexadecimal, octal};
55
use super::parse::ParseRes;
66
#[allow(clippy::wildcard_imports)]
77
use super::types::arch_types::*;
8-
use super::types::{Base, Number, NumberType, ERR_PREFIX};
8+
use super::types::{Base, ERR_PREFIX, Number, NumberType};
99
use crate::errors::api::{CompileError, Location};
1010

1111
/// Finds a invalid character with the base found with the prefix of the
@@ -39,7 +39,6 @@ fn check_with_base(literal: &str, base: &Base) -> Option<char> {
3939
/// - [`Base::Hexadecimal`] if the literal starts with "0x";
4040
/// - [`Base::Octal`] if the literal starts with "0";
4141
/// - [`Base::Decimal`] in every other case.
42-
///
4342
fn get_base(
4443
literal: &str,
4544
nb_type: &NumberType,

src/lexer/numbers/types.rs

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,17 @@ define_nb_types!(Int Long LongLong Float Double LongDouble UInt ULong ULongLong)
9292
impl fmt::Display for Number {
9393
#[inline]
9494
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95-
write!(
96-
f,
97-
"{}",
98-
match self {
99-
Self::Int(x) => x.to_string(),
100-
Self::Long(x) => x.to_string(),
101-
Self::LongLong(x) => x.to_string(),
102-
Self::Float(x) => x.to_string(),
103-
Self::Double(x) => x.to_string(),
104-
Self::LongDouble(x) => format!("'{}'", *x as f64),
105-
Self::UInt(x) => x.to_string(),
106-
Self::ULong(x) => x.to_string(),
107-
Self::ULongLong(x) => x.to_string(),
108-
}
109-
)
95+
write!(f, "{}", match self {
96+
Self::Int(x) => x.to_string(),
97+
Self::Long(x) => x.to_string(),
98+
Self::LongLong(x) => x.to_string(),
99+
Self::Float(x) => x.to_string(),
100+
Self::Double(x) => x.to_string(),
101+
Self::LongDouble(x) => format!("'{}'", *x as f64),
102+
Self::UInt(x) => x.to_string(),
103+
Self::ULong(x) => x.to_string(),
104+
Self::ULongLong(x) => x.to_string(),
105+
})
110106
}
111107
}
112108

@@ -134,7 +130,7 @@ impl NumberType {
134130
Self::UInt => Self::ULong,
135131
Self::ULong => Self::ULongLong,
136132
Self::ULongLong | Self::LongLong | Self::Float | Self::Double | Self::LongDouble => {
137-
return None
133+
return None;
138134
}
139135
})
140136
}
@@ -170,20 +166,16 @@ impl NumberType {
170166
impl fmt::Display for NumberType {
171167
#[inline]
172168
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
173-
write!(
174-
f,
175-
"{}",
176-
match self {
177-
Self::Int => "int",
178-
Self::Long => "long",
179-
Self::LongLong => "long long",
180-
Self::Float => "float",
181-
Self::Double => "double",
182-
Self::LongDouble => "long double",
183-
Self::UInt => "unsigned int",
184-
Self::ULong => "unsigned long",
185-
Self::ULongLong => "unsigned long long",
186-
}
187-
)
169+
write!(f, "{}", match self {
170+
Self::Int => "int",
171+
Self::Long => "long",
172+
Self::LongLong => "long long",
173+
Self::Float => "float",
174+
Self::Double => "double",
175+
Self::LongDouble => "long double",
176+
Self::UInt => "unsigned int",
177+
Self::ULong => "unsigned long",
178+
Self::ULongLong => "unsigned long long",
179+
})
188180
}
189181
}

0 commit comments

Comments
 (0)