Skip to content

Commit 8d14fa5

Browse files
committed
style: Use strip_prefix instead of manual test and strip
cargo clippy warning: stripping a prefix manually if src.starts_with('-') then (Some(SignToken::Minus), &src[1..]) recommend use strip_prefix if let Some(stripped) = src.strip_prefix('-') for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip Signed-off-by: zu1k <[email protected]>
1 parent a9e5e0a commit 8d14fa5

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

crates/wast/src/ast/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,8 +1287,8 @@ impl<'a> MemArg<'a> {
12871287
return Ok((None, c));
12881288
}
12891289
let num = &kw[1..];
1290-
let num = if num.starts_with("0x") {
1291-
f(c, &num[2..], 16)?
1290+
let num = if let Some(stripped) = num.strip_prefix("0x") {
1291+
f(c, stripped, 16)?
12921292
} else {
12931293
f(c, num, 10)?
12941294
};

crates/wast/src/lexer.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,10 @@ impl<'a> Lexer<'a> {
483483
}
484484

485485
fn number(&self, src: &'a str) -> Option<Token<'a>> {
486-
let (sign, num) = if src.starts_with('+') {
487-
(Some(SignToken::Plus), &src[1..])
488-
} else if src.starts_with('-') {
489-
(Some(SignToken::Minus), &src[1..])
486+
let (sign, num) = if let Some(stripped) = src.strip_prefix('+') {
487+
(Some(SignToken::Plus), stripped)
488+
} else if let Some(stripped) = src.strip_prefix('-') {
489+
(Some(SignToken::Minus), stripped)
490490
} else {
491491
(None, src)
492492
};
@@ -507,8 +507,8 @@ impl<'a> Lexer<'a> {
507507
negative,
508508
},
509509
}))));
510-
} else if num.starts_with("nan:0x") {
511-
let mut it = num[6..].chars();
510+
} else if let Some(stripped) = num.strip_prefix("nan:0x") {
511+
let mut it = stripped.chars();
512512
let to_parse = skip_undescores(&mut it, false, char::is_ascii_hexdigit)?;
513513
if it.next().is_some() {
514514
return None;
@@ -524,9 +524,9 @@ impl<'a> Lexer<'a> {
524524
}
525525

526526
// Figure out if we're a hex number or not
527-
let (mut it, hex, test_valid) = if num.starts_with("0x") {
527+
let (mut it, hex, test_valid) = if let Some(stripped) = num.strip_prefix("0x") {
528528
(
529-
num[2..].chars(),
529+
stripped.chars(),
530530
true,
531531
char::is_ascii_hexdigit as fn(&char) -> bool,
532532
)

0 commit comments

Comments
 (0)