Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3bb89e2

Browse files
committed
(main) ref: remove unnecessary dbg_assert
1 parent 03d9bd0 commit 3bb89e2

17 files changed

Lines changed: 35 additions & 78 deletions

File tree

src/errors/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,3 @@ mod debug;
2222
mod display;
2323
mod location;
2424
mod result;
25-
26-
/// Wrapper to turn off the coverage checks on [`debug_assert!`]
27-
///
28-
/// This functions still is replaced by void in `--release` mod, thanks to the
29-
/// `#[inline(always)]` flag, that tells the compiler to inline with an empty
30-
/// body.
31-
#[coverage(off)]
32-
#[inline(always)]
33-
#[expect(clippy::inline_always)]
34-
pub fn dbg_assert(cond: bool, msg: &str) {
35-
debug_assert!(cond, "{msg}");
36-
}

src/lexer/numbers/base/binary.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Module to parse binary-represented number constants
22
33
use crate::errors::api::Location;
4-
use crate::errors::dbg_assert;
54
use crate::lexer::numbers::macros::parse_int_from_radix;
65
use crate::lexer::numbers::parse::OverParseRes;
76
use crate::lexer::numbers::types::arch_types::{Int, Long, LongLong, UInt, ULong, ULongLong};
@@ -48,9 +47,9 @@ pub fn to_bin_value(
4847
nb_type: NumberType,
4948
location: &Location,
5049
) -> OverParseRes<Number> {
51-
dbg_assert(
50+
debug_assert!(
5251
literal.chars().all(|ch| matches!(ch, '0' | '1')),
53-
"checked for invalid characters when finding base.",
52+
"checked for invalid characters when finding base."
5453
);
5554
parse_int_from_radix!(location,
5655
nb_type, literal, "a binary must be an integer", 2, Int Long LongLong UInt ULong ULongLong

src/lexer/numbers/base/hexadecimal.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use core::num::{IntErrorKind, ParseIntError};
66

77
use crate::errors::api::{CompileRes, Location};
8-
use crate::errors::dbg_assert;
98
use crate::lexer::numbers::macros::parse_int_from_radix;
109
use crate::lexer::numbers::parse::OverParseRes;
1110
use crate::lexer::numbers::types::arch_types::{
@@ -129,14 +128,14 @@ impl HexFloatData {
129128

130129
/// Returns the exponent of the number constant.
131130
fn get_exp(&self) -> Result<u32, &'static str> {
132-
dbg_assert(
131+
debug_assert!(
133132
!self.exponent.is_empty(),
134-
"Exponent not empty because exponent compulsory for float hexadecimals",
133+
"Exponent not empty because exponent compulsory for float hexadecimals"
135134
);
136135
self.exponent.parse().map_err(|err: ParseIntError| {
137-
dbg_assert(
136+
debug_assert!(
138137
matches!(err.kind(), IntErrorKind::PosOverflow),
139-
"none others possible",
138+
"none others possible"
140139
);
141140
"Failed to parse exponent: too large"
142141
})
@@ -210,9 +209,9 @@ enum HexFloatParseState {
210209
fn get_hex_float_data(literal: &str, location: &Location) -> CompileRes<HexFloatData> {
211210
let mut float_parse = HexFloatData::default();
212211
for ch in literal.chars() {
213-
dbg_assert(
212+
debug_assert!(
214213
!matches!(ch, '+' | '-') || float_parse.state == HexFloatParseState::Exponent,
215-
"+ or - always are after a p character in hex literal",
214+
"+ or - always are after a p character in hex literal"
216215
);
217216
match ch {
218217
'-' => float_parse.exponent_neg = Some(true),

src/lexer/numbers/base/octal.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Module to parse octal-represented number constants
22
33
use crate::errors::api::Location;
4-
use crate::errors::dbg_assert;
54
use crate::lexer::numbers::macros::parse_int_from_radix;
65
use crate::lexer::numbers::parse::OverParseRes;
76
use crate::lexer::numbers::types::arch_types::{Int, Long, LongLong, UInt, ULong, ULongLong};
@@ -48,9 +47,9 @@ pub fn to_oct_value(
4847
nb_type: NumberType,
4948
location: &Location,
5049
) -> OverParseRes<Number> {
51-
dbg_assert(
50+
debug_assert!(
5251
literal.chars().all(|ch| matches!(ch, '0'..='7')),
53-
"checked when creating base",
52+
"checked when creating base"
5453
);
5554
parse_int_from_radix!(
5655
location,

src/lexer/state/end_state.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use core::mem;
88

99
use crate::errors::api::Location;
10-
use crate::errors::dbg_assert;
1110
use crate::lexer::numbers::api::literal_to_number;
1211
use crate::lexer::state::api::{LexingState, SymbolState};
1312
use crate::lexer::types::api::{Ident, LexingData, Token};
@@ -43,7 +42,7 @@ pub fn end_current(lex_state: &mut LexingState, lex_data: &mut LexingData, locat
4342
/// constant and pushes the corresponding token. If it is a number, it is parsed
4443
/// into its value.
4544
fn end_ident(literal: &mut Ident, lex_data: &mut LexingData, location: &Location) {
46-
dbg_assert(!literal.is_empty(), "initialised with one");
45+
debug_assert!(!literal.is_empty(), "initialised with one");
4746
let possible_number = literal_to_number(lex_data, literal, location);
4847
match possible_number {
4948
None => {

src/lexer/state/escape.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
44
use super::api::LexingState;
55
use crate::errors::api::Location;
6-
use crate::errors::dbg_assert;
76
use crate::lexer::types::api::{EscapeSequence, LexingData};
87

98
/// Used to describe the return status after lexing an [`EscapeSequence`];
@@ -69,7 +68,7 @@ fn end_escape_sequence(
6968
EscapeSequence::ShortUnicode(value) => {
7069
expect_max_length(4, value);
7170
expect_min_length(lex_data, 4, value, location, sequence)?;
72-
dbg_assert(last, "len = 4");
71+
debug_assert!(last, "len = 4");
7372
char::from_u32(u32::from_str_radix(value, 16).expect("max 8 chars and radix valid"))
7473
.ok_or_else(|| {
7574
lex_data.push_err(
@@ -93,7 +92,7 @@ fn end_escape_sequence(
9392
}
9493
expect_max_length(8, value);
9594
expect_min_length(lex_data, 8, value, location, sequence)?;
96-
dbg_assert(last, "len = 4");
95+
debug_assert!(last, "len = 4");
9796
char::from_u32(u32::from_str_radix(value, 16).expect("max 4 chars and radix valid"))
9897
.ok_or_else(|| {
9998
lex_data.push_err(
@@ -113,10 +112,10 @@ fn end_escape_sequence(
113112
}
114113
EscapeSequence::Octal(value) => {
115114
expect_max_length(3, value);
116-
dbg_assert(!value.is_empty(), "initialise with len 1");
115+
debug_assert!(!value.is_empty(), "initialise with len 1");
117116
let int =
118117
u32::from_str_radix(value, 8).expect("Max 3 digits, so value <= 0777 & radix < 32");
119-
dbg_assert(int <= 0o377, "unreachable: should never have pushed");
118+
debug_assert!(int <= 0o377, "unreachable: should never have pushed");
120119
#[expect(clippy::as_conversions, clippy::cast_possible_truncation)]
121120
Ok(char::from(int as u8))
122121
}
@@ -128,7 +127,7 @@ fn end_escape_sequence(
128127
#[inline(always)]
129128
#[expect(clippy::inline_always)]
130129
fn expect_max_length(size: usize, value: &str) {
131-
dbg_assert(value.len() <= size, "Never should have pushed here");
130+
debug_assert!(value.len() <= size, "Never should have pushed here");
132131
}
133132

134133
/// Returns the minimum number of characters expected after the escape sequence
@@ -170,9 +169,9 @@ pub fn handle_escape(
170169
escape_state: &mut EscapeState,
171170
location: &Location,
172171
) {
173-
dbg_assert(
172+
debug_assert!(
174173
matches!(lex_state, LexingState::Char(None) | LexingState::Str(_)),
175-
"Can't happen because error raised on escape creation if wrong state.",
174+
"Can't happen because error raised on escape creation if wrong state."
176175
);
177176
let escape_return = push_char_in_escape(ch, lex_data, escape_state, location);
178177
if matches!(escape_return, EscapeSequenceReturnState::Error) {

src/lexer/state/symbol.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Module to define the symbol-handling-state
22
33
use crate::errors::api::Location;
4-
use crate::errors::dbg_assert;
54
use crate::lexer::api::Symbol;
65
use crate::lexer::types::api::LexingData;
76

@@ -102,7 +101,7 @@ impl SymbolState {
102101
/// Returns the last element of the state by copying it: it is not removed
103102
/// from the state.
104103
pub fn last(&self) -> char {
105-
dbg_assert(self.first != NULL, "initialised with one");
104+
debug_assert!(self.first != NULL, "initialised with one");
106105
if self.second == NULL {
107106
self.first
108107
} else if self.third == NULL {
@@ -114,7 +113,7 @@ impl SymbolState {
114113

115114
/// Returns the number of [`Symbol`] in [`SymbolState`]
116115
pub fn len(&self) -> usize {
117-
dbg_assert(self.first != NULL, "initialised with one");
116+
debug_assert!(self.first != NULL, "initialised with one");
118117
if self.third == NULL {
119118
if self.second == NULL {
120119
return 1;
@@ -166,7 +165,7 @@ impl SymbolState {
166165
lex_data: &mut LexingData,
167166
location: &Location,
168167
) -> Option<(usize, Symbol)> {
169-
dbg_assert(!self.is_empty(), "initialised with one");
168+
debug_assert!(!self.is_empty(), "initialised with one");
170169
let initial_len = self.len();
171170
if let Some((msg, len, error)) = self.handle_digraphs_trigraphs() {
172171
let new_location = location.to_past(len, initial_len);

src/parser/keyword/attributes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ macro_rules! define_attribute_keywords {
2626
}
2727

2828
impl From<UnsortedAttributeKeyword> for AttributeKeyword {
29+
#[coverage(off)]
2930
fn from(value: UnsortedAttributeKeyword) -> Self {
3031
match value {
3132
$($(UnsortedAttributeKeyword::$variant => Self::$name($name::$variant),)*)*

src/parser/keyword/control_flow/node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ impl Push for ControlFlowNode {
166166
#[cfg(feature = "debug")]
167167
crate::errors::api::Print::push_op(&op, self, "ctrl node");
168168
if self.is_full() {
169+
//TODO: This doesn't display because is caught
169170
Err("Tried to push operator in full control flow".to_owned())
170171
} else {
171172
derive_method!(self, push_op, op)

src/parser/modifiers/functions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::parser::types::binary::Binary;
77
use crate::parser::types::braced_blocks::BracedBlock;
88
use crate::parser::types::ternary::Ternary;
99
use crate::parser::types::unary::Unary;
10-
use crate::parser::types::{Ast, FunctionCall, FunctionOperator, ListInitialiser};
10+
use crate::parser::types::{Ast, FunctionCall, ListInitialiser};
1111

1212
/// Checks if it is possible to create a function from the last
1313
/// [`Variable`](crate::parser::types::variable::Variable).
@@ -56,7 +56,6 @@ pub fn make_function(current: &mut Ast, arguments: Vec<Ast>) {
5656
if let Ast::Variable(variable) = mem::take(ast) {
5757
*ast = Ast::FunctionCall(FunctionCall {
5858
variable,
59-
op: FunctionOperator,
6059
args: arguments,
6160
});
6261
} else {

0 commit comments

Comments
 (0)