Skip to content

Commit b0bd3f6

Browse files
committed
(main) add: rustc lints
1 parent cdcdd8a commit b0bd3f6

File tree

20 files changed

+142
-112
lines changed

20 files changed

+142
-112
lines changed

src/errors/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<T> ops::FromResidual<Result<convert::Infallible, CompileError>> for Res<Opt
140140
#[inline]
141141
fn from_residual(residual: Result<convert::Infallible, CompileError>) -> Self {
142142
match residual {
143-
Ok(_) => unreachable!(/* By definition of Infallible */),
143+
Ok(_) => panic!(/* By definition of Infallible */),
144144
Err(err) => Self::from_err(err),
145145
}
146146
}

src/lexer/lex_content.rs

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,50 @@
22
//!
33
//! See [`lex_file`] for more information.
44
5-
#[allow(clippy::enum_glob_use)]
6-
use LexingState::*;
7-
85
use super::state::api::{
9-
CommentState, EscapeState, LexingState, SymbolState, end_current, handle_escape
6+
CommentState, EscapeState, LexingState as LS, SymbolState, end_current, handle_escape
107
};
118
use super::types::api::{LexingData, Token};
129
use crate::errors::api::{Location, Res};
1310

1411
/// Function to manage one character.
1512
///
16-
/// This function updates the [`LexingState`] automaton, and executes the right
13+
/// This function updates the [`LS`] automaton, and executes the right
1714
/// handlers.
1815
#[expect(clippy::too_many_lines)]
1916
fn lex_char(
2017
ch: char,
2118
location: &Location,
2219
lex_data: &mut LexingData,
23-
lex_state: &mut LexingState,
20+
lex_state: &mut LS,
2421
escape_state: &mut EscapeState,
2522
eol: bool,
2623
) {
2724
match (ch, lex_state, escape_state) {
28-
(_, StartOfLine, _) if ch.is_whitespace() => (),
25+
(_, LS::StartOfLine, _) if ch.is_whitespace() => (),
2926
/* Inside comment */
30-
('/', state @ Comment(CommentState::Star), _) => {
31-
*state = Comment(CommentState::False);
27+
('/', state @ LS::Comment(CommentState::Star), _) => {
28+
*state = LS::Comment(CommentState::False);
3229
}
33-
('*', state @ Comment(CommentState::True), _) => {
34-
*state = Comment(CommentState::Star);
30+
('*', state @ LS::Comment(CommentState::True), _) => {
31+
*state = LS::Comment(CommentState::Star);
3532
}
36-
(_, Comment(CommentState::True), _) => (),
37-
(_, state @ Comment(CommentState::Star), _) => {
38-
*state = Comment(CommentState::True);
33+
(_, LS::Comment(CommentState::True), _) => (),
34+
(_, state @ LS::Comment(CommentState::Star), _) => {
35+
*state = LS::Comment(CommentState::True);
3936
}
4037
/* Escaped character */
4138
(
4239
_,
43-
state @ (Char(None) | Str(_)),
40+
state @ (LS::Char(None) | LS::Str(_)),
4441
escape @ (EscapeState::Single | EscapeState::Sequence(_)),
4542
) => {
4643
if let Some(escaped) = handle_escape(ch, lex_data, escape, location) {
4744
*escape = EscapeState::False;
4845
#[expect(clippy::wildcard_enum_match_arm)]
4946
match state {
50-
Char(None) => *state = Char(Some(escaped)),
51-
Str(val) => val.push(escaped),
47+
LS::Char(None) => *state = LS::Char(Some(escaped)),
48+
LS::Str(val) => val.push(escaped),
5249
_ => panic!("this can't happen, see match above"),
5350
}
5451
}
@@ -61,11 +58,11 @@ fn lex_char(
6158
('*', state, _) if state.symbol().and_then(SymbolState::last) == Some('/') => {
6259
state.clear_last_symbol();
6360
end_current(state, lex_data, location);
64-
*state = Comment(CommentState::True);
61+
*state = LS::Comment(CommentState::True);
6562
}
6663

6764
/* Escape character */
68-
('\\', Char(None) | Str(_), escape) => *escape = EscapeState::Single,
65+
('\\', LS::Char(None) | LS::Str(_), escape) => *escape = EscapeState::Single,
6966
('\\', _, escape) if eol => *escape = EscapeState::Single,
7067
('\\', state, _) => lex_data.push_err(location.to_error(format!(
7168
"Escape characters are only authorised in strings or chars, not in '{}' context.",
@@ -74,39 +71,39 @@ fn lex_char(
7471

7572
/* Static strings and chars */
7673
// open/close
77-
('\'', Symbols(symbol_state), _) if symbol_state.is_trigraph() => {
74+
('\'', LS::Symbols(symbol_state), _) if symbol_state.is_trigraph() => {
7875
if let Some((size, symbol)) = symbol_state.push(ch, lex_data, location) {
7976
lex_data.push_token(Token::from_symbol(symbol, size, location));
8077
}
8178
}
82-
('\'', state @ Char(_), _) => end_current(state, lex_data, location),
83-
('\'', state, _) if !matches!(state, Str(_)) => {
79+
('\'', state @ LS::Char(_), _) => end_current(state, lex_data, location),
80+
('\'', state, _) if !matches!(state, LS::Str(_)) => {
8481
end_current(state, lex_data, location);
85-
*state = LexingState::Char(None);
82+
*state = LS::Char(None);
8683
}
87-
('\"', state @ Str(_), _) => {
84+
('\"', state @ LS::Str(_), _) => {
8885
end_current(state, lex_data, location);
8986
}
90-
('\"', state, _) if !matches!(state, Char(_)) => {
87+
('\"', state, _) if !matches!(state, LS::Char(_)) => {
9188
end_current(state, lex_data, location);
92-
*state = LexingState::Str(String::new());
89+
*state = LS::Str(String::new());
9390
}
9491
// middle
95-
(_, Char(Some(_)), _) => lex_data
92+
(_, LS::Char(Some(_)), _) => lex_data
9693
.push_err(location.to_error("A char must contain only one character.".to_owned())),
97-
(_, state @ Char(None), _) => *state = Char(Some(ch)),
98-
(_, Str(val), _) => val.push(ch),
94+
(_, state @ LS::Char(None), _) => *state = LS::Char(Some(ch)),
95+
(_, LS::Str(val), _) => val.push(ch),
9996

10097
/* Operator symbols */
10198
('/', state, _) if state.symbol().and_then(SymbolState::last) == Some('/') => {
10299
state.clear_last_symbol();
103100
end_current(state, lex_data, location);
104101
lex_data.set_end_line();
105102
}
106-
('.', Ident(ident), _) if !ident.contains('.') && ident.is_number() => {
103+
('.', LS::Ident(ident), _) if !ident.contains('.') && ident.is_number() => {
107104
ident.push('.');
108105
}
109-
('+' | '-', Ident(ident), _)
106+
('+' | '-', LS::Ident(ident), _)
110107
if !ident.contains('-') && !ident.contains('+') && ident.last_is_exp() =>
111108
{
112109
ident.push(ch);
@@ -117,13 +114,13 @@ fn lex_char(
117114
state,
118115
_,
119116
) => {
120-
if let Symbols(symbol_state) = state {
117+
if let LS::Symbols(symbol_state) = state {
121118
if let Some((size, symbol)) = symbol_state.push(ch, lex_data, location) {
122119
lex_data.push_token(Token::from_symbol(symbol, size, location));
123120
}
124121
} else {
125122
end_current(state, lex_data, location);
126-
*state = LexingState::Symbols(SymbolState::from(ch));
123+
*state = LS::Symbols(SymbolState::from(ch));
127124
}
128125
}
129126

@@ -133,13 +130,13 @@ fn lex_char(
133130
}
134131

135132
// Whitespace: end of everyone
136-
(_, Ident(val), _) if ch.is_alphanumeric() || matches!(ch, '_' | '.' | '+' | '-') => {
133+
(_, LS::Ident(val), _) if ch.is_alphanumeric() || matches!(ch, '_' | '.' | '+' | '-') => {
137134
// dbg!("here", &val, ch);
138135
val.push(ch);
139136
// dbg!("there", &val);
140137
}
141138
(_, state, _) if ch.is_alphanumeric() || matches!(ch, '_') => {
142-
if let Symbols(symbol) = state
139+
if let LS::Symbols(symbol) = state
143140
&& symbol.last() == Some('.')
144141
&& ch.is_ascii_digit()
145142
{
@@ -166,7 +163,7 @@ fn lex_char(
166163
#[inline]
167164
pub fn lex_file(content: &str, location: &mut Location) -> Res<Vec<Token>> {
168165
let mut lex_data = LexingData::default();
169-
let mut lex_state = LexingState::default();
166+
let mut lex_state = LS::default();
170167

171168
for line in content.lines() {
172169
lex_line(line, location, &mut lex_data, &mut lex_state);
@@ -180,12 +177,7 @@ pub fn lex_file(content: &str, location: &mut Location) -> Res<Vec<Token>> {
180177
///
181178
/// It stops at the first erroneous character, or at the end of the line if
182179
/// everything was ok.
183-
fn lex_line(
184-
line: &str,
185-
location: &mut Location,
186-
lex_data: &mut LexingData,
187-
lex_state: &mut LexingState,
188-
) {
180+
fn lex_line(line: &str, location: &mut Location, lex_data: &mut LexingData, lex_state: &mut LS) {
189181
lex_data.newline();
190182
let mut escape_state = EscapeState::False;
191183
let trimmed = line.trim_end();
@@ -217,6 +209,6 @@ fn lex_line(
217209
));
218210
}
219211
} else {
220-
*lex_state = LexingState::default();
212+
*lex_state = LS::default();
221213
}
222214
}

src/lexer/numbers/base/binary.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
33
use super::super::macros::parse_int_from_radix;
44
use super::super::parse::OverParseRes;
5-
#[allow(clippy::wildcard_imports)]
6-
use super::super::types::arch_types::*;
5+
use super::super::types::arch_types::{Int, Long, LongLong, UInt, ULong, ULongLong};
76
use super::super::types::{ERR_PREFIX, Number, NumberType};
87
use crate::errors::api::Location;
98

src/lexer/numbers/base/decimal.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use core::num::ParseFloatError;
44
use core::str::FromStr;
55

66
use super::super::parse::OverParseRes;
7-
#[allow(clippy::wildcard_imports)]
8-
use super::super::types::arch_types::*;
7+
use super::super::types::arch_types::{Double, Float, Int, Long, LongLong, UInt, ULong, ULongLong};
98
use super::super::types::{ERR_PREFIX, Number, NumberType};
109
use crate::errors::api::{CompileError, Location};
1110

src/lexer/numbers/base/hexadecimal.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
use super::super::macros::parse_int_from_radix;
66
use super::super::parse::OverParseRes;
7-
#[allow(clippy::wildcard_imports)]
8-
use super::super::types::arch_types::*;
7+
use super::super::types::arch_types::{
8+
Double, DoubleIntPart, Float, FloatIntPart, Int, Long, LongDouble, LongDoubleIntPart, LongLong, UInt, ULong, ULongLong
9+
};
910
use super::super::types::{ERR_PREFIX, Number, NumberType};
1011
use crate::errors::api::{CompileError, Location};
1112

src/lexer/numbers/base/octal.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
33
use super::super::macros::parse_int_from_radix;
44
use super::super::parse::OverParseRes;
5-
#[allow(clippy::wildcard_imports)]
6-
use super::super::types::arch_types::*;
5+
use super::super::types::arch_types::{Int, Long, LongLong, UInt, ULong, ULongLong};
76
use super::super::types::{ERR_PREFIX, Number, NumberType};
87
use crate::errors::api::Location;
98

src/lexer/numbers/from_literal.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use core::str;
66
use super::super::types::api::{Ident, LexingData};
77
use super::base::{binary, decimal, hexadecimal, octal};
88
use super::parse::ParseRes;
9-
#[allow(clippy::wildcard_imports)]
10-
use super::types::arch_types::*;
9+
use super::types::arch_types::Int;
1110
use super::types::{Base, ERR_PREFIX, Number, NumberType};
1211
use crate::errors::api::{CompileError, Location};
1312

src/lexer/numbers/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<T: fmt::Display> From<T> for OverParseRes<T> {
115115
impl ops::FromResidual<Result<convert::Infallible, CompileError>> for OverParseRes<Number> {
116116
fn from_residual(residual: Result<convert::Infallible, CompileError>) -> Self {
117117
match residual {
118-
Ok(_) => unreachable!(/* Infallible = ! */),
118+
Ok(_) => panic!(/* Infallible = ! */),
119119
Err(err) => Self::Err(err),
120120
}
121121
}
@@ -168,7 +168,7 @@ impl<T> ParseRes<T> {
168168
impl<T> ops::FromResidual<Result<convert::Infallible, CompileError>> for ParseRes<T> {
169169
fn from_residual(residual: Result<convert::Infallible, CompileError>) -> Self {
170170
match residual {
171-
Ok(_) => unreachable!(/* Infallible = ! */),
171+
Ok(_) => panic!(/* Infallible = ! */),
172172
Err(err) => Self::Err(err),
173173
}
174174
}

src/lexer/numbers/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ pub mod arch_types {
2929

3030
use core::fmt;
3131

32-
#[allow(clippy::wildcard_imports)]
33-
use arch_types::*;
32+
use arch_types::{Double, Float, Int, Long, LongDouble, LongLong, UInt, ULong, ULongLong};
3433

3534
/// Defines the [`Number`] and [`NumberType`] enums
3635
macro_rules! define_nb_types {

src/lexer/state/escape.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ fn end_escape_sequence(
2727
location: &Location,
2828
sequence: &EscapeSequence,
2929
) -> Result<char, ()> {
30-
match *sequence {
31-
EscapeSequence::ShortUnicode(ref value) => {
30+
match sequence {
31+
EscapeSequence::ShortUnicode(value) => {
3232
expect_max_length(4, value);
3333
expect_min_length(lex_data, 4, value, location, sequence)?;
3434
end_unicode_sequence(lex_data, value, location)
3535
}
36-
EscapeSequence::Unicode(ref value) => {
36+
EscapeSequence::Unicode(value) => {
3737
if value.len() <= 4 {
3838
lex_data.push_err(location.to_error(format!(
3939
"Invalid escaped unicode number: An escaped big unicode must contain 8 hexadecimal digits, found only {}. Did you mean to use lowercase \\u?",
@@ -45,14 +45,14 @@ fn end_escape_sequence(
4545
expect_min_length(lex_data, 8, value, location, sequence)?;
4646
end_unicode_sequence(lex_data, value, location)
4747
}
48-
EscapeSequence::Hexadecimal(ref value) => {
48+
EscapeSequence::Hexadecimal(value) => {
4949
expect_max_length(3, value);
5050
expect_min_length(lex_data, 2, value, location, sequence)?;
5151
let int =
5252
u8::from_str_radix(value, 16).expect("We push only numeric so this doesn't happen");
5353
Ok(int.into())
5454
}
55-
EscapeSequence::Octal(ref value) => {
55+
EscapeSequence::Octal(value) => {
5656
expect_max_length(3, value);
5757
expect_min_length(lex_data, 1, value, location, sequence)?;
5858
let (int, small) = safe_parse_int!(

0 commit comments

Comments
 (0)