Skip to content

Commit 45f064e

Browse files
eduardosmAmanieu
authored andcommitted
Use char constants for single-character patterns
1 parent 5c7ec3a commit 45f064e

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

crates/stdarch-gen/src/main.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const FLOAT_TYPES_64: [&str; 2] = [
5252
];
5353

5454
fn type_len(t: &str) -> usize {
55-
let s: Vec<_> = t.split("x").collect();
55+
let s: Vec<_> = t.split('x').collect();
5656
if s.len() == 2 {
5757
match &s[1][0..2] {
5858
"1_" => 1,
@@ -333,15 +333,15 @@ fn type_to_noq_n_suffix(t: &str) -> &str {
333333
fn type_to_lane_suffixes<'a>(out_t: &'a str, in_t: &'a str, re_to_out: bool) -> String {
334334
let mut str = String::new();
335335
let suf = type_to_suffix(out_t);
336-
if !suf.starts_with("_") {
336+
if !suf.starts_with('_') {
337337
str.push_str(&suf[0..1]);
338338
}
339339
str.push_str("_lane");
340340
if !re_to_out {
341341
str.push_str(type_to_suffix(in_t));
342342
} else {
343-
if type_to_suffix(in_t).starts_with("q") {
344-
str.push_str("q");
343+
if type_to_suffix(in_t).starts_with('q') {
344+
str.push('q');
345345
};
346346
let suf2 = type_to_noq_suffix(out_t);
347347
str.push_str(suf2);
@@ -352,7 +352,7 @@ fn type_to_lane_suffixes<'a>(out_t: &'a str, in_t: &'a str, re_to_out: bool) ->
352352
fn type_to_rot_suffix(c_name: &str, suf: &str) -> String {
353353
let ns: Vec<_> = c_name.split('_').collect();
354354
assert_eq!(ns.len(), 2);
355-
if let Some(suf) = suf.strip_prefix("q") {
355+
if let Some(suf) = suf.strip_prefix('q') {
356356
format!("{}q_{}{}", ns[0], ns[1], suf)
357357
} else {
358358
format!("{c_name}{suf}")
@@ -377,10 +377,10 @@ fn type_to_unsigned(t: &str) -> String {
377377
fn type_to_double_suffixes<'a>(out_t: &'a str, in_t: &'a str) -> String {
378378
let mut str = String::new();
379379
let suf = type_to_suffix(in_t);
380-
if suf.starts_with("q") && type_to_suffix(out_t).starts_with("q") {
381-
str.push_str("q");
380+
if suf.starts_with('q') && type_to_suffix(out_t).starts_with('q') {
381+
str.push('q');
382382
}
383-
if !suf.starts_with("_") && !suf.starts_with("q") {
383+
if !suf.starts_with('_') && !suf.starts_with('q') {
384384
str.push_str(&suf[0..1]);
385385
}
386386
str.push_str(type_to_noq_suffix(out_t));
@@ -391,10 +391,10 @@ fn type_to_double_suffixes<'a>(out_t: &'a str, in_t: &'a str) -> String {
391391
fn type_to_double_n_suffixes<'a>(out_t: &'a str, in_t: &'a str) -> String {
392392
let mut str = String::new();
393393
let suf = type_to_suffix(in_t);
394-
if suf.starts_with("q") && type_to_suffix(out_t).starts_with("q") {
395-
str.push_str("q");
394+
if suf.starts_with('q') && type_to_suffix(out_t).starts_with('q') {
395+
str.push('q');
396396
}
397-
if !suf.starts_with("_") && !suf.starts_with("q") {
397+
if !suf.starts_with('_') && !suf.starts_with('q') {
398398
str.push_str(&suf[0..1]);
399399
}
400400
str.push_str("_n");
@@ -579,8 +579,8 @@ impl TargetFeature {
579579

580580
/// Generate target_feature attributes for a test that will compile for both "arm" and "aarch64".
581581
fn to_target_feature_attr_shared(&self) -> Lines {
582-
let arm = self.as_target_feature_arg_arm().split(",");
583-
let aarch64 = self.as_target_feature_arg_aarch64().split(",");
582+
let arm = self.as_target_feature_arg_arm().split(',');
583+
let aarch64 = self.as_target_feature_arg_aarch64().split(',');
584584

585585
// Combine common features into an unconditional `target_feature` annotation, but guard
586586
// others behind `cfg_attr`.
@@ -1170,7 +1170,7 @@ fn map_val<'v>(t: &str, v: &'v str) -> &'v str {
11701170

11711171
fn type_to_ext(t: &str, v: bool, r: bool, pi8: bool) -> String {
11721172
if !t.contains('x') {
1173-
return t.replace("u", "i");
1173+
return t.replace('u', "i");
11741174
}
11751175
let native = type_to_native_type(t);
11761176
let sub_ext = match type_sub_len(t) {
@@ -1185,7 +1185,7 @@ fn type_to_ext(t: &str, v: bool, r: bool, pi8: bool) -> String {
11851185
};
11861186
let sub_type = match &native[0..1] {
11871187
"i" | "f" => native,
1188-
"u" => native.replace("u", "i"),
1188+
"u" => native.replace('u', "i"),
11891189
_ => panic!("unknown type: {t}"),
11901190
};
11911191
let ext = format!(
@@ -1222,15 +1222,15 @@ fn is_vldx(name: &str) -> bool {
12221222
let s: Vec<_> = name.split('_').collect();
12231223
&name[0..3] == "vld"
12241224
&& name[3..4].parse::<i32>().unwrap() > 1
1225-
&& (s.last().unwrap().starts_with("s") || s.last().unwrap().starts_with("f"))
1225+
&& (s.last().unwrap().starts_with('s') || s.last().unwrap().starts_with('f'))
12261226
}
12271227

12281228
fn is_vstx(name: &str) -> bool {
12291229
let s: Vec<_> = name.split('_').collect();
12301230
s.len() == 2
12311231
&& &name[0..3] == "vst"
12321232
&& name[3..4].parse::<i32>().unwrap() > 1
1233-
&& (s[1].starts_with("s") || s[1].starts_with("f"))
1233+
&& (s[1].starts_with('s') || s[1].starts_with('f'))
12341234
}
12351235

12361236
fn create_doc_string(comment_string: &str, fn_name: &str) -> String {
@@ -1358,7 +1358,7 @@ fn gen_aarch64(
13581358
];
13591359
let mut ext_c = String::new();
13601360
if let Some(mut link_aarch64) = link_aarch64.clone() {
1361-
if link_aarch64.contains(":") {
1361+
if link_aarch64.contains(':') {
13621362
let links: Vec<_> = link_aarch64.split(':').map(|v| v.to_string()).collect();
13631363
assert_eq!(links.len(), 5);
13641364
link_aarch64 = links[0].to_string();
@@ -1461,7 +1461,7 @@ fn gen_aarch64(
14611461
);
14621462
};
14631463
let const_declare = if let Some(constn) = constn {
1464-
if constn.contains(":") {
1464+
if constn.contains(':') {
14651465
let constns: Vec<_> = constn.split(':').map(|v| v.to_string()).collect();
14661466
assert_eq!(constns.len(), 2);
14671467
format!(r#"<const {}: i32, const {}: i32>"#, constns[0], constns[1])
@@ -1492,7 +1492,7 @@ fn gen_aarch64(
14921492
String::new()
14931493
};
14941494
let const_assert = if let Some(constn) = constn {
1495-
if constn.contains(":") {
1495+
if constn.contains(':') {
14961496
let constns: Vec<_> = constn.split(':').map(|v| v.to_string()).collect();
14971497
let const_test = current_tests[0].3.as_ref().unwrap();
14981498
let const_tests: Vec<_> = const_test.split(':').map(|v| v.to_string()).collect();
@@ -1516,7 +1516,7 @@ fn gen_aarch64(
15161516
String::new()
15171517
};
15181518
let const_legacy = if let Some(constn) = constn {
1519-
if constn.contains(":") {
1519+
if constn.contains(':') {
15201520
format!(
15211521
"\n#[rustc_legacy_const_generics({}, {})]",
15221522
para_num - 1,
@@ -1839,7 +1839,7 @@ fn gen_test(
18391839
let c: Vec<String> = c.iter().take(len_in[2]).cloned().collect();
18401840
let e: Vec<String> = e.iter().take(len_out).cloned().collect();
18411841
let const_value = if let Some(constn) = n {
1842-
if constn.contains(":") {
1842+
if constn.contains(':') {
18431843
let constns: Vec<_> = constn.split(':').map(|v| v.to_string()).collect();
18441844
format!(
18451845
r#"::<{}, {}>"#,
@@ -2046,7 +2046,7 @@ fn gen_arm(
20462046
out_t.to_string(),
20472047
];
20482048
if let (Some(mut link_arm), Some(mut link_aarch64)) = (link_arm.clone(), link_aarch64.clone()) {
2049-
if link_arm.contains(":") {
2049+
if link_arm.contains(':') {
20502050
let links: Vec<_> = link_arm.split(':').map(|v| v.to_string()).collect();
20512051
assert_eq!(links.len(), 5);
20522052
link_arm = links[0].to_string();
@@ -2057,7 +2057,7 @@ fn gen_arm(
20572057
links[4].clone(),
20582058
];
20592059
}
2060-
if link_aarch64.contains(":") {
2060+
if link_aarch64.contains(':') {
20612061
let links: Vec<_> = link_aarch64.split(':').map(|v| v.to_string()).collect();
20622062
assert_eq!(links.len(), 5);
20632063
link_aarch64 = links[0].to_string();
@@ -2129,7 +2129,7 @@ fn gen_arm(
21292129
};
21302130
(format!("ptr: {ptr_type}, {inputs}, n: i32, size: i32"), out)
21312131
} else {
2132-
let (_, const_type) = if const_arm.contains(":") {
2132+
let (_, const_type) = if const_arm.contains(':') {
21332133
let consts: Vec<_> =
21342134
const_arm.split(':').map(|v| v.trim().to_string()).collect();
21352135
(consts[0].clone(), consts[1].clone())
@@ -3142,8 +3142,8 @@ fn get_call(
31423142
if fn_format[2] == "ext" {
31433143
fn_name.push_str("_");
31443144
} else if fn_format[2] == "noext" {
3145-
} else if fn_format[2].starts_with("<") {
3146-
assert!(fn_format[2].ends_with(">"));
3145+
} else if fn_format[2].starts_with('<') {
3146+
assert!(fn_format[2].ends_with('>'));
31473147
let types: Vec<_> = fn_format[2][1..fn_format[2].len() - 1]
31483148
.split(' ')
31493149
.map(|v| v.to_string())
@@ -3172,7 +3172,7 @@ fn get_call(
31723172
r#"let {}: {} = {}({});"#,
31733173
re_name, re_type, fn_name, param_str
31743174
)
3175-
} else if fn_name.starts_with("*") {
3175+
} else if fn_name.starts_with('*') {
31763176
format!(r#"{fn_name} = {param_str};"#)
31773177
} else {
31783178
format!(r#"{fn_name}({param_str})"#)

crates/stdarch-verify/tests/mips.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ fn matches(rust: &Function, mips: &MsaIntrinsic) -> Result<(), String> {
345345

346346
if !rust.instrs.is_empty() {
347347
// Normalize slightly to get rid of assembler differences
348-
let actual = rust.instrs[0].replace(".", "_");
349-
let expected = mips.instruction.replace(".", "_");
348+
let actual = rust.instrs[0].replace('.', "_");
349+
let expected = mips.instruction.replace('.', "_");
350350
if actual != expected {
351351
bail!(
352352
"wrong instruction: \"{}\" != \"{}\"",

crates/stdarch-verify/tests/x86-intel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ fn equate(
694694
// const float* foo => float const*
695695
if intel.starts_with("const") && intel.ends_with('*') {
696696
intel = intel.replace("const ", "");
697-
intel = intel.replace("*", " const*");
697+
intel = intel.replace('*', " const*");
698698
}
699699
if etype == "IMM" {
700700
// The _bittest intrinsics claim to only accept immediates but actually

0 commit comments

Comments
 (0)