Skip to content

Commit a0442ea

Browse files
authored
Enforce uninlined_format_args for the workspace (bytecodealliance#9065)
* Enforce `uninlined_format_args` for the workspace * fix: failing `Monolith Checks` job * fix: formatting
1 parent bfc10d9 commit a0442ea

File tree

270 files changed

+1082
-1278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

270 files changed

+1082
-1278
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ unused-lifetimes = 'warn'
178178
all = { level = 'allow', priority = -1 }
179179
clone_on_copy = 'warn'
180180
map_clone = 'warn'
181+
uninlined_format_args = 'warn'
181182
unnecessary_to_owned = 'warn'
182183
manual_strip = 'warn'
183184

cranelift/bforest/src/node.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl<F: Forest> NodeData<F> {
174174
} => {
175175
let sz = usize::from(*size);
176176
debug_assert!(sz <= keys.len());
177-
debug_assert!(index <= sz, "Can't insert at {} with {} keys", index, sz);
177+
debug_assert!(index <= sz, "Can't insert at {index} with {sz} keys");
178178

179179
if let Some(ks) = keys.get_mut(0..=sz) {
180180
*size = (sz + 1) as u8;
@@ -547,7 +547,7 @@ impl ValDisp for SetValue {
547547

548548
impl<T: fmt::Display> ValDisp for T {
549549
fn valfmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
550-
write!(f, ":{}", self)
550+
write!(f, ":{self}")
551551
}
552552
}
553553

@@ -576,7 +576,7 @@ where
576576
}
577577
write!(f, " ]")
578578
}
579-
Self::Free { next: Some(n) } => write!(f, "[ free -> {} ]", n),
579+
Self::Free { next: Some(n) } => write!(f, "[ free -> {n} ]"),
580580
Self::Free { next: None } => write!(f, "[ free ]"),
581581
}
582582
}
@@ -641,7 +641,7 @@ mod tests {
641641

642642
// Splitting should be independent of the hint because we have an even number of node
643643
// references.
644-
let saved = inner.clone();
644+
let saved = inner;
645645
let sp = inner.split(1);
646646
assert_eq!(sp.lhs_entries, 4);
647647
assert_eq!(sp.rhs_entries, 4);
@@ -691,7 +691,7 @@ mod tests {
691691
assert!(!leaf.try_leaf_insert(15, 'x', SetValue()));
692692

693693
// The index given to `split` is not the split position, it's a hint for balancing the node.
694-
let saved = leaf.clone();
694+
let saved = leaf;
695695
let sp = leaf.split(12);
696696
assert_eq!(sp.lhs_entries, 8);
697697
assert_eq!(sp.rhs_entries, 7);

cranelift/bforest/src/path.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,7 @@ impl<F: Forest> Path<F> {
651651
for level in 0..self.size {
652652
match pool[self.node[level]] {
653653
NodeData::Inner { size, tree, .. } => {
654-
assert!(
655-
level < self.size - 1,
656-
"Expected leaf node at level {}",
657-
level
658-
);
654+
assert!(level < self.size - 1, "Expected leaf node at level {level}");
659655
assert!(
660656
self.entry[level] <= size,
661657
"OOB inner entry {}/{} at level {}",
@@ -666,8 +662,7 @@ impl<F: Forest> Path<F> {
666662
assert_eq!(
667663
self.node[level + 1],
668664
tree[usize::from(self.entry[level])],
669-
"Node mismatch at level {}",
670-
level
665+
"Node mismatch at level {level}"
671666
);
672667
}
673668
NodeData::Leaf { size, .. } => {

cranelift/bforest/src/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<F: Forest> NodePool<F> {
5252
/// Free a node.
5353
pub fn free_node(&mut self, node: Node) {
5454
// Quick check for a double free.
55-
debug_assert!(!self.nodes[node].is_free(), "{} is already free", node);
55+
debug_assert!(!self.nodes[node].is_free(), "{node} is already free");
5656
self.nodes[node] = NodeData::Free {
5757
next: self.freelist,
5858
};
@@ -162,7 +162,7 @@ impl<F: Forest> NodePool<F> {
162162

163163
// Verify occupancy.
164164
// Right-most nodes can be small, but others must be at least half full.
165-
assert!(size > 0, "Leaf {} is empty", node);
165+
assert!(size > 0, "Leaf {node} is empty");
166166
assert!(
167167
rkey.is_none() || size * 2 >= capacity,
168168
"Only {}/{} entries in {}:{}, upper={}",

cranelift/codegen/build.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn main() {
4848
// Try to match native target.
4949
let target_name = target_triple.split('-').next().unwrap();
5050
let isa = meta::isa_from_arch(&target_name).expect("error when identifying target");
51-
println!("cargo:rustc-cfg=feature=\"{}\"", isa);
51+
println!("cargo:rustc-cfg=feature=\"{isa}\"");
5252
isas.push(isa);
5353
}
5454

@@ -82,13 +82,13 @@ fn main() {
8282
}
8383

8484
if let Err(err) = meta::generate(&isas, &out_dir, isle_dir) {
85-
eprintln!("Error: {}", err);
85+
eprintln!("Error: {err}");
8686
process::exit(1);
8787
}
8888

8989
if &std::env::var("SKIP_ISLE").unwrap_or("0".to_string()) != "1" {
9090
if let Err(err) = build_isle(crate_dir, isle_dir) {
91-
eprintln!("Error: {}", err);
91+
eprintln!("Error: {err}");
9292
process::exit(1);
9393
}
9494
}
@@ -121,7 +121,7 @@ fn main() {
121121
let status = child.wait().unwrap();
122122
if status.success() {
123123
let git_rev = git_rev.trim().chars().take(9).collect::<String>();
124-
format!("{}-{}", pkg_version, git_rev)
124+
format!("{pkg_version}-{git_rev}")
125125
} else {
126126
// not a git repo
127127
pkg_version
@@ -134,8 +134,7 @@ fn main() {
134134
std::path::Path::new(&out_dir).join("version.rs"),
135135
format!(
136136
"/// Version number of this crate. \n\
137-
pub const VERSION: &str = \"{}\";",
138-
version
137+
pub const VERSION: &str = \"{version}\";"
139138
),
140139
)
141140
.unwrap();
@@ -174,7 +173,7 @@ fn build_isle(
174173
if let Err(e) = run_compilation(compilation) {
175174
had_error = true;
176175
eprintln!("Error building ISLE files:");
177-
eprintln!("{:?}", e);
176+
eprintln!("{e:?}");
178177
#[cfg(not(feature = "isle-errors"))]
179178
{
180179
eprintln!("To see a more detailed error report, run: ");
@@ -221,10 +220,7 @@ fn run_compilation(compilation: &IsleCompilation) -> Result<(), Errors> {
221220
};
222221

223222
let code = rustfmt(&code).unwrap_or_else(|e| {
224-
println!(
225-
"cargo:warning=Failed to run `rustfmt` on ISLE-generated code: {:?}",
226-
e
227-
);
223+
println!("cargo:warning=Failed to run `rustfmt` on ISLE-generated code: {e:?}");
228224
code
229225
});
230226

@@ -258,7 +254,7 @@ fn rustfmt(code: &str) -> std::io::Result<String> {
258254
if !status.success() {
259255
return Err(std::io::Error::new(
260256
std::io::ErrorKind::Other,
261-
format!("`rustfmt` exited with status {}", status),
257+
format!("`rustfmt` exited with status {status}"),
262258
));
263259
}
264260

cranelift/codegen/meta/src/cdsl/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl PredicateNode {
189189
group.name, group.settings[bool_setting_index.0].name
190190
),
191191
PredicateNode::SharedBool(ref group_name, ref bool_name) => {
192-
format!("{}.{}()", group_name, bool_name)
192+
format!("{group_name}.{bool_name}()")
193193
}
194194
PredicateNode::And(ref lhs, ref rhs) => {
195195
format!("{} && {}", lhs.render(group), rhs.render(group))

cranelift/codegen/meta/src/cdsl/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ impl fmt::Debug for LaneType {
242242
f,
243243
"{}",
244244
match *self {
245-
LaneType::Float(_) => format!("FloatType({})", inner_msg),
246-
LaneType::Int(_) => format!("IntType({})", inner_msg),
245+
LaneType::Float(_) => format!("FloatType({inner_msg})"),
246+
LaneType::Int(_) => format!("IntType({inner_msg})"),
247247
}
248248
)
249249
}

cranelift/codegen/meta/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ enum ErrorInner {
4141
impl fmt::Display for ErrorInner {
4242
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4343
match *self {
44-
ErrorInner::Msg(ref s) => write!(f, "{}", s),
45-
ErrorInner::IoError(ref e) => write!(f, "{}", e),
44+
ErrorInner::Msg(ref s) => write!(f, "{s}"),
45+
ErrorInner::IoError(ref e) => write!(f, "{e}"),
4646
}
4747
}
4848
}

cranelift/codegen/meta/src/gen_inst.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn gen_instruction_data(formats: &[Rc<InstructionFormat>], fmt: &mut Formatter)
9292
"blocks: [ir::BlockCall; {}],",
9393
format.num_block_operands
9494
),
95-
n => panic!("Too many block operands in instruction: {}", n),
95+
n => panic!("Too many block operands in instruction: {n}"),
9696
}
9797

9898
for field in &format.imm_fields {
@@ -137,21 +137,21 @@ fn gen_arguments_method(formats: &[Rc<InstructionFormat>], fmt: &mut Formatter,
137137
m.arm(
138138
name,
139139
vec![format!("ref {}args", mut_), "..".to_string()],
140-
format!("args.{}(pool)", as_slice),
140+
format!("args.{as_slice}(pool)"),
141141
);
142142
continue;
143143
}
144144

145145
// Fixed args.
146146
let mut fields = Vec::new();
147147
let arg = if format.num_value_operands == 0 {
148-
format!("&{}[]", mut_)
148+
format!("&{mut_}[]")
149149
} else if format.num_value_operands == 1 {
150-
fields.push(format!("ref {}arg", mut_));
151-
format!("{}(arg)", rslice)
150+
fields.push(format!("ref {mut_}arg"));
151+
format!("{rslice}(arg)")
152152
} else {
153153
let arg = format!("args_arity{}", format.num_value_operands);
154-
fields.push(format!("args: ref {}{}", mut_, arg));
154+
fields.push(format!("args: ref {mut_}{arg}"));
155155
arg
156156
};
157157
fields.push("..".into());
@@ -277,8 +277,8 @@ fn gen_instruction_data_impl(formats: &[Rc<InstructionFormat>], fmt: &mut Format
277277
members.push(field.member);
278278
}
279279

280-
let pat1 = members.iter().map(|x| format!("{}: ref {}1", x, x)).collect::<Vec<_>>().join(", ");
281-
let pat2 = members.iter().map(|x| format!("{}: ref {}2", x, x)).collect::<Vec<_>>().join(", ");
280+
let pat1 = members.iter().map(|x| format!("{x}: ref {x}1")).collect::<Vec<_>>().join(", ");
281+
let pat2 = members.iter().map(|x| format!("{x}: ref {x}2")).collect::<Vec<_>>().join(", ");
282282
fmtln!(fmt, "({} {{ {} }}, {} {{ {} }}) => {{", name, pat1, name, pat2);
283283
fmt.indent(|fmt| {
284284
fmt.line("opcode1 == opcode2");
@@ -734,7 +734,7 @@ fn iterable_to_string<I: fmt::Display, T: IntoIterator<Item = I>>(iterable: T) -
734734
.map(|x| x.to_string())
735735
.collect::<Vec<_>>()
736736
.join(", ");
737-
format!("{{{}}}", elems)
737+
format!("{{{elems}}}")
738738
}
739739

740740
fn typeset_to_string(ts: &TypeSet) -> String {
@@ -853,7 +853,7 @@ fn gen_type_constraints(all_inst: &AllInstructions, fmt: &mut Formatter) {
853853
);
854854
fmt.comment(format!("Constraints=[{}]", constraints
855855
.iter()
856-
.map(|x| format!("'{}'", x))
856+
.map(|x| format!("'{x}'"))
857857
.collect::<Vec<_>>()
858858
.join(", ")));
859859
if let Some(poly) = &inst.polymorphic_info {
@@ -916,7 +916,7 @@ fn gen_member_inits(format: &InstructionFormat, fmt: &mut Formatter) {
916916
} else if format.num_value_operands > 1 {
917917
let mut args = Vec::new();
918918
for i in 0..format.num_value_operands {
919-
args.push(format!("arg{}", i));
919+
args.push(format!("arg{i}"));
920920
}
921921
fmtln!(fmt, "args: [{}],", args.join(", "));
922922
}
@@ -928,7 +928,7 @@ fn gen_member_inits(format: &InstructionFormat, fmt: &mut Formatter) {
928928
n => {
929929
let mut blocks = Vec::new();
930930
for i in 0..n {
931-
blocks.push(format!("block{}", i));
931+
blocks.push(format!("block{i}"));
932932
}
933933
fmtln!(fmt, "blocks: [{}],", blocks.join(", "));
934934
}
@@ -953,7 +953,7 @@ fn gen_format_constructor(format: &InstructionFormat, fmt: &mut Formatter) {
953953
}
954954

955955
// Then the block operands.
956-
args.extend((0..format.num_block_operands).map(|i| format!("block{}: ir::BlockCall", i)));
956+
args.extend((0..format.num_block_operands).map(|i| format!("block{i}: ir::BlockCall")));
957957

958958
// Then the value operands.
959959
if format.has_value_list {
@@ -963,7 +963,7 @@ fn gen_format_constructor(format: &InstructionFormat, fmt: &mut Formatter) {
963963
} else {
964964
// Take a fixed number of value operands.
965965
for i in 0..format.num_value_operands {
966-
args.push(format!("arg{}: Value", i));
966+
args.push(format!("arg{i}: Value"));
967967
}
968968
}
969969

@@ -1000,7 +1000,7 @@ fn gen_format_constructor(format: &InstructionFormat, fmt: &mut Formatter) {
10001000
}
10011001

10021002
// Assert that this opcode belongs to this format
1003-
fmtln!(fmt, "debug_assert_eq!(opcode.format(), InstructionFormat::from(&data), \"Wrong InstructionFormat for Opcode: {}\", opcode);");
1003+
fmtln!(fmt, "debug_assert_eq!(opcode.format(), InstructionFormat::from(&data), \"Wrong InstructionFormat for Opcode: {opcode}\");");
10041004

10051005
fmt.line("self.build(data, ctrl_typevar)");
10061006
});
@@ -1202,7 +1202,7 @@ fn gen_inst_builder(inst: &Instruction, format: &InstructionFormat, fmt: &mut Fo
12021202
inst.value_results
12031203
.iter()
12041204
.enumerate()
1205-
.map(|(i, _)| format!("results[{}]", i))
1205+
.map(|(i, _)| format!("results[{i}]"))
12061206
.collect::<Vec<_>>()
12071207
.join(", ")
12081208
);

cranelift/codegen/meta/src/gen_isle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn gen_common_isle(
182182
match format.num_block_operands {
183183
0 => (),
184184
1 => write!(&mut s, " (destination BlockCall)").unwrap(),
185-
n => write!(&mut s, " (blocks BlockArray{})", n).unwrap(),
185+
n => write!(&mut s, " (blocks BlockArray{n})").unwrap(),
186186
}
187187

188188
for field in &format.imm_fields {
@@ -289,7 +289,7 @@ fn gen_common_isle(
289289
.unwrap()
290290
.name;
291291
if values.is_empty() {
292-
write!(&mut s, " (value_list_slice {})", varargs).unwrap();
292+
write!(&mut s, " (value_list_slice {varargs})").unwrap();
293293
} else {
294294
write!(
295295
&mut s,
@@ -481,7 +481,7 @@ fn gen_lower_isle(
481481
/// Generate an `enum` immediate in ISLE.
482482
fn gen_isle_enum(name: &str, mut variants: Vec<&str>, fmt: &mut Formatter) {
483483
variants.sort();
484-
let prefix = format!(";;;; Enumerated Immediate: {} ", name);
484+
let prefix = format!(";;;; Enumerated Immediate: {name} ");
485485
fmtln!(fmt, "{:;<80}", prefix);
486486
fmt.empty_line();
487487
fmtln!(fmt, "(type {} extern", name);

0 commit comments

Comments
 (0)