Skip to content

Commit 59961db

Browse files
authored
Enable a few more clippy lints by default (bytecodealliance#9038)
Also set their default levels to `warn` instead of `deny` to assist with using clippy locally to avoid compilation failures and collecting as many as possible in one run. Note that CI will still deny-by-default through `-Dwarnings`.
1 parent 169b97f commit 59961db

File tree

11 files changed

+25
-26
lines changed

11 files changed

+25
-26
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ unused-lifetimes = 'warn'
176176
# they're all turned off by default. Selective lints are then enabled below as
177177
# necessary.
178178
all = { level = 'allow', priority = -1 }
179-
clone_on_copy = 'deny'
179+
clone_on_copy = 'warn'
180+
map_clone = 'warn'
181+
unnecessary_to_owned = 'warn'
182+
manual_strip = 'warn'
180183

181184
[workspace.dependencies]
182185
arbitrary = { version = "1.3.1" }

cranelift/codegen/src/ir/immediates.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ fn parse_u64(s: &str) -> Result<u64, &'static str> {
218218

219219
if s.starts_with("-0x") {
220220
return Err("Invalid character in hexadecimal number");
221-
} else if s.starts_with("0x") {
221+
} else if let Some(num) = s.strip_prefix("0x") {
222222
// Hexadecimal.
223-
for ch in s[2..].chars() {
223+
for ch in num.chars() {
224224
match ch.to_digit(16) {
225225
Some(digit) => {
226226
digits += 1;
@@ -934,10 +934,10 @@ fn parse_float(s: &str, w: u8, t: u8) -> Result<u128, &'static str> {
934934
debug_assert!(1 + w + t <= 128, "Too large IEEE format for u128");
935935
debug_assert!((t + w + 1).is_power_of_two(), "Unexpected IEEE format size");
936936

937-
let (sign_bit, s2) = if s.starts_with('-') {
938-
(1u128 << (t + w), &s[1..])
939-
} else if s.starts_with('+') {
940-
(0, &s[1..])
937+
let (sign_bit, s2) = if let Some(num) = s.strip_prefix('-') {
938+
(1u128 << (t + w), num)
939+
} else if let Some(num) = s.strip_prefix('+') {
940+
(0, num)
941941
} else {
942942
(0, s)
943943
};
@@ -959,18 +959,18 @@ fn parse_float(s: &str, w: u8, t: u8) -> Result<u128, &'static str> {
959959
// Canonical quiet NaN: e = max, t = quiet.
960960
return Ok(sign_bit | max_e_bits | quiet_bit);
961961
}
962-
if s2.starts_with("NaN:0x") {
962+
if let Some(nan) = s2.strip_prefix("NaN:0x") {
963963
// Quiet NaN with payload.
964-
return match u128::from_str_radix(&s2[6..], 16) {
964+
return match u128::from_str_radix(nan, 16) {
965965
Ok(payload) if payload < quiet_bit => {
966966
Ok(sign_bit | max_e_bits | quiet_bit | payload)
967967
}
968968
_ => Err("Invalid NaN payload"),
969969
};
970970
}
971-
if s2.starts_with("sNaN:0x") {
971+
if let Some(nan) = s2.strip_prefix("sNaN:0x") {
972972
// Signaling NaN with payload.
973-
return match u128::from_str_radix(&s2[7..], 16) {
973+
return match u128::from_str_radix(nan, 16) {
974974
Ok(payload) if 0 < payload && payload < quiet_bit => {
975975
Ok(sign_bit | max_e_bits | payload)
976976
}

cranelift/codegen/src/isa/aarch64/lower/isle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub(crate) fn lower_branch(
6363
// TODO: reuse the ISLE context across lowerings so we can reuse its
6464
// internal heap allocations.
6565
let mut isle_ctx = IsleContext { lower_ctx, backend };
66-
generated_code::constructor_lower_branch(&mut isle_ctx, branch, &targets.to_vec())
66+
generated_code::constructor_lower_branch(&mut isle_ctx, branch, targets)
6767
}
6868

6969
pub struct ExtendedValue {

cranelift/codegen/src/isa/riscv64/lower/isle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,5 +647,5 @@ pub(crate) fn lower_branch(
647647
// TODO: reuse the ISLE context across lowerings so we can reuse its
648648
// internal heap allocations.
649649
let mut isle_ctx = RV64IsleContext::new(lower_ctx, backend);
650-
generated_code::constructor_lower_branch(&mut isle_ctx, branch, &targets.to_vec())
650+
generated_code::constructor_lower_branch(&mut isle_ctx, branch, targets)
651651
}

cranelift/codegen/src/isa/s390x/lower/isle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub(crate) fn lower_branch(
7474
// TODO: reuse the ISLE context across lowerings so we can reuse its
7575
// internal heap allocations.
7676
let mut isle_ctx = IsleContext { lower_ctx, backend };
77-
generated_code::constructor_lower_branch(&mut isle_ctx, branch, &targets.to_vec())
77+
generated_code::constructor_lower_branch(&mut isle_ctx, branch, targets)
7878
}
7979

8080
impl generated_code::Context for IsleContext<'_, '_, MInst, S390xBackend> {

cranelift/codegen/src/isa/x64/lower/isle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(crate) fn lower_branch(
6565
// TODO: reuse the ISLE context across lowerings so we can reuse its
6666
// internal heap allocations.
6767
let mut isle_ctx = IsleContext { lower_ctx, backend };
68-
generated_code::constructor_lower_branch(&mut isle_ctx, branch, &targets.to_vec())
68+
generated_code::constructor_lower_branch(&mut isle_ctx, branch, &targets)
6969
}
7070

7171
impl Context for IsleContext<'_, '_, MInst, X64Backend> {

cranelift/codegen/src/machinst/pcc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(crate) fn get_fact_or_default<I: VCodeInst>(vcode: &VCode<I>, reg: Reg, widt
1111
);
1212
vcode
1313
.vreg_fact(reg.into())
14-
.map(|f| f.clone())
14+
.cloned()
1515
.unwrap_or_else(|| Fact::max_range_for_width(width))
1616
}
1717

cranelift/filetests/src/match_directive.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ pub fn match_directive<'a>(comment: &'a str, directive: &str) -> Option<&'a str>
1010
"Directive must include trailing colon"
1111
);
1212
let text = comment.trim_start_matches(';').trim_start();
13-
if text.starts_with(directive) {
14-
Some(text[directive.len()..].trim())
15-
} else {
16-
None
17-
}
13+
text.strip_prefix(directive).map(|s| s.trim())
1814
}
1915

2016
#[test]

cranelift/reader/src/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,9 @@ impl<'a> Parser<'a> {
788788
if let Some(Token::Integer(text)) = self.token() {
789789
self.consume();
790790
// Lexer just gives us raw text that looks like an integer.
791-
if text.starts_with("0x") {
791+
if let Some(num) = text.strip_prefix("0x") {
792792
// Parse it as a u8 in hexadecimal form.
793-
u8::from_str_radix(&text[2..], 16)
793+
u8::from_str_radix(num, 16)
794794
.map_err(|_| self.error("unable to parse u8 as a hexadecimal immediate"))
795795
} else {
796796
// Parse it as a u8 to check for overflow and other issues.

crates/environ/src/fact/signature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl ComponentTypesBuilder {
4040
let results = match self.flatten_types(
4141
&options.options,
4242
MAX_FLAT_RESULTS,
43-
self[ty.results].types.iter().map(|ty| *ty),
43+
self[ty.results].types.iter().copied(),
4444
) {
4545
Some(list) => list,
4646
None => {

0 commit comments

Comments
 (0)