Skip to content

Commit fa5440a

Browse files
committed
forbid ptr_arg
1 parent 1798068 commit fa5440a

22 files changed

Lines changed: 68 additions & 98 deletions

File tree

Cargo.toml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,24 @@ perf = { level = "forbid", priority = 1 }
5757

5858
complexity = { level = "deny", priority = -1 }
5959

60-
style = { level = "allow", priority = -1 }
60+
style = { level = "deny", priority = -1 }
6161
pedantic = { level = "allow", priority = -1 }
62+
restriction = { level = "allow", priority = -1 }
6263

6364
too_many_arguments = "allow"
6465
identity_op = "allow"
6566

66-
unwrap_or_default = "forbid"
6767
ptr_arg = "deny"
68+
ref_option = "forbid"
69+
inefficient_to_string = "forbid"
70+
from_over_into = "forbid"
71+
unwrap_or_default = "forbid"
72+
redundant_static_lifetimes = "forbid"
73+
match_like_matches_macro = "forbid"
74+
field_reassign_with_default = "forbid"
75+
inherent_to_string = "forbid"
76+
owned_cow = "forbid"
77+
redundant_clone = "forbid"
78+
str_to_string = "forbid"
79+
single_char_pattern = "forbid"
80+
single_char_add_str = "forbid"

yjit/src/asm/arm64/opnd.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ impl A64Opnd {
7979

8080
/// Convenience function to check if this operand is a register.
8181
pub fn is_reg(&self) -> bool {
82-
match self {
83-
A64Opnd::Reg(_) => true,
84-
_ => false
85-
}
82+
matches!(self, A64Opnd::Reg(_))
8683
}
8784

8885
/// Unwrap a register from an operand.

yjit/src/asm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl CodeBlock {
378378

379379
// Unless this comment is the same as the last one at this same line, add it.
380380
if this_line_comments.last().map(String::as_str) != Some(comment) {
381-
this_line_comments.push(comment.to_string());
381+
this_line_comments.push(comment.into());
382382
}
383383
}
384384

yjit/src/asm/x86_64/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,7 @@ impl X86Opnd {
163163
}
164164

165165
pub fn is_some(&self) -> bool {
166-
match self {
167-
X86Opnd::None => false,
168-
_ => true
169-
}
166+
!matches!(self, X86Opnd::None)
170167
}
171168

172169
}

yjit/src/backend/arm64/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ impl Assembler
12431243
emit_cmp_zero_jump(cb, opnd.into(), false, compile_side_exit(*target, self, ocb)?);
12441244
},
12451245
Insn::IncrCounter { mem, value } => {
1246-
let label = cb.new_label("incr_counter_loop".to_string());
1246+
let label = cb.new_label("incr_counter_loop".into());
12471247
cb.write_label(label);
12481248

12491249
ldaxr(cb, Self::SCRATCH0, mem.into());

yjit/src/backend/ir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ impl Assembler
11861186
assert!(!name.contains(' '), "use underscores in label names, not spaces");
11871187

11881188
let label_idx = self.label_names.len();
1189-
self.label_names.push(name.to_string());
1189+
self.label_names.push(name.into());
11901190
Target::Label(label_idx)
11911191
}
11921192

@@ -1753,7 +1753,7 @@ impl Assembler {
17531753
}
17541754

17551755
pub fn bake_string(&mut self, text: &str) {
1756-
self.push_insn(Insn::BakeString(text.to_string()));
1756+
self.push_insn(Insn::BakeString(text.into()));
17571757
}
17581758

17591759
#[allow(dead_code)]

yjit/src/codegen.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl<'a> JITState<'a> {
404404
if !self.perf_stack.is_empty() {
405405
self.perf_symbol_range_end(asm);
406406
}
407-
self.perf_stack.push(symbol_name.to_string());
407+
self.perf_stack.push(symbol_name.into());
408408
self.perf_symbol_range_start(asm, symbol_name);
409409
}
410410

@@ -454,12 +454,9 @@ impl<'a> JITState<'a> {
454454

455455
/// Return true if we're compiling a send-like instruction, not an opt_* instruction.
456456
pub fn is_sendish(&self) -> bool {
457-
match unsafe { rb_iseq_opcode_at_pc(self.iseq, self.pc) } as u32 {
458-
YARVINSN_send |
457+
matches!(unsafe { rb_iseq_opcode_at_pc(self.iseq, self.pc) } as u32, YARVINSN_send |
459458
YARVINSN_opt_send_without_block |
460-
YARVINSN_invokesuper => true,
461-
_ => false,
462-
}
459+
YARVINSN_invokesuper)
463460
}
464461

465462
/// Return the number of locals in the current ISEQ
@@ -9547,7 +9544,7 @@ fn get_class_name(class: Option<VALUE>) -> String {
95479544
unsafe { RB_TYPE_P(class, RUBY_T_MODULE) || RB_TYPE_P(class, RUBY_T_CLASS) }
95489545
}).and_then(|class| unsafe {
95499546
cstr_to_rust_string(rb_class2name(class))
9550-
}).unwrap_or_else(|| "Unknown".to_string())
9547+
}).unwrap_or_else(|| "Unknown".into())
95519548
}
95529549

95539550
/// Assemble "{class_name}#{method_name}" from a class pointer and a method ID
@@ -9557,15 +9554,15 @@ fn get_method_name(class: Option<VALUE>, mid: u64) -> String {
95579554
unsafe { cstr_to_rust_string(rb_id2name(mid)) }
95589555
} else {
95599556
None
9560-
}.unwrap_or_else(|| "Unknown".to_string());
9557+
}.unwrap_or_else(|| "Unknown".into());
95619558
format!("{}#{}", class_name, method_name)
95629559
}
95639560

95649561
/// Assemble "{label}@{iseq_path}:{lineno}" (iseq_inspect() format) from an ISEQ
95659562
fn get_iseq_name(iseq: IseqPtr) -> String {
95669563
let c_string = unsafe { rb_yjit_iseq_inspect(iseq) };
95679564
let string = unsafe { CStr::from_ptr(c_string) }.to_str()
9568-
.unwrap_or_else(|_| "not UTF-8").to_string();
9565+
.unwrap_or_else(|_| "not UTF-8").into();
95699566
unsafe { ruby_xfree(c_string as *mut c_void); }
95709567
string
95719568
}

yjit/src/core.rs

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,12 @@ impl Type {
121121

122122
/// Check if the type is an immediate
123123
pub fn is_imm(&self) -> bool {
124-
match self {
125-
Type::UnknownImm => true,
126-
Type::Nil => true,
127-
Type::True => true,
128-
Type::False => true,
129-
Type::Fixnum => true,
130-
Type::Flonum => true,
131-
Type::ImmSymbol => true,
132-
_ => false,
133-
}
124+
matches!(self, Type::UnknownImm | Type::Nil | Type::True | Type::False | Type::Fixnum | Type::Flonum | Type::ImmSymbol)
134125
}
135126

136127
/// Returns true when the type is not specific.
137128
pub fn is_unknown(&self) -> bool {
138-
match self {
139-
Type::Unknown | Type::UnknownImm | Type::UnknownHeap => true,
140-
_ => false,
141-
}
129+
matches!(self, Type::Unknown | Type::UnknownImm | Type::UnknownHeap)
142130
}
143131

144132
/// Returns true when we know the VALUE is a specific handle type,
@@ -150,17 +138,7 @@ impl Type {
150138

151139
/// Check if the type is a heap object
152140
pub fn is_heap(&self) -> bool {
153-
match self {
154-
Type::UnknownHeap => true,
155-
Type::TArray => true,
156-
Type::CArray => true,
157-
Type::THash => true,
158-
Type::CHash => true,
159-
Type::TString => true,
160-
Type::CString => true,
161-
Type::BlockParamProxy => true,
162-
_ => false,
163-
}
141+
matches!(self, Type::UnknownHeap | Type::TArray | Type::CArray | Type::THash | Type::CHash | Type::TString | Type::CString | Type::BlockParamProxy)
164142
}
165143

166144
/// Check if it's a T_ARRAY object (both TArray and CArray are T_ARRAY)
@@ -2510,10 +2488,12 @@ impl Context {
25102488

25112489
/// Create a new Context that is compatible with self but doesn't have type information.
25122490
pub fn get_generic_ctx(&self) -> Context {
2513-
let mut generic_ctx = Context::default();
2514-
generic_ctx.stack_size = self.stack_size;
2515-
generic_ctx.sp_offset = self.sp_offset;
2516-
generic_ctx.reg_mapping = self.reg_mapping;
2491+
let mut generic_ctx = Context {
2492+
stack_size: self.stack_size,
2493+
sp_offset: self.sp_offset,
2494+
reg_mapping: self. reg_mapping,
2495+
..Default::default()
2496+
};
25172497
if self.is_return_landing() {
25182498
generic_ctx.set_as_return_landing();
25192499
}
@@ -3233,9 +3213,7 @@ fn gen_entry_point_body(blockid: BlockId, stack_size: u8, ec: EcPtr, jit_excepti
32333213
let (code_ptr, reg_mapping) = gen_entry_prologue(cb, ocb, blockid, stack_size, jit_exception)?;
32343214

32353215
// Find or compile a block version
3236-
let mut ctx = Context::default();
3237-
ctx.stack_size = stack_size;
3238-
ctx.reg_mapping = reg_mapping;
3216+
let ctx = Context { stack_size, reg_mapping, ..Default::default()};
32393217
let block = match find_block_version(blockid, &ctx) {
32403218
// If an existing block is found, generate a jump to the block.
32413219
Some(blockref) => {
@@ -3359,9 +3337,7 @@ fn entry_stub_hit_body(
33593337
asm.compile(cb, Some(ocb))?;
33603338

33613339
// Find or compile a block version
3362-
let mut ctx = Context::default();
3363-
ctx.stack_size = stack_size;
3364-
ctx.reg_mapping = reg_mapping;
3340+
let ctx = Context { stack_size, reg_mapping, ..Default::default()};
33653341
let blockref = match find_block_version(blockid, &ctx) {
33663342
// If an existing block is found, generate a jump to the block.
33673343
Some(blockref) => {

yjit/src/cruby.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub fn insn_name(opcode: usize) -> String {
223223
let op_name = CStr::from_ptr(op_name).to_str().unwrap();
224224

225225
// Convert into an owned string
226-
op_name.to_string()
226+
op_name.into()
227227
}
228228
}
229229

@@ -619,7 +619,7 @@ pub fn cstr_to_rust_string(c_char_ptr: *const c_char) -> Option<String> {
619619
let c_str: &CStr = unsafe { CStr::from_ptr(c_char_ptr) };
620620

621621
match c_str.to_str() {
622-
Ok(rust_str) => Some(rust_str.to_string()),
622+
Ok(rust_str) => Some(rust_str.into()),
623623
Err(_) => None
624624
}
625625
}

yjit/src/options.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub static mut OPTIONS: Options = Options {
115115

116116
/// YJIT option descriptions for `ruby --help`.
117117
/// Note that --help allows only 80 characters per line, including indentation. 80-character limit --> |
118-
pub const YJIT_OPTIONS: &'static [(&str, &str)] = &[
118+
pub const YJIT_OPTIONS: &[(&str, &str)] = &[
119119
("--yjit-mem-size=num", "Soft limit on YJIT memory usage in MiB (default: 128)."),
120120
("--yjit-exec-mem-size=num", "Hard limit on executable memory block in MiB."),
121121
("--yjit-call-threshold=num", "Number of calls to trigger JIT."),
@@ -319,7 +319,7 @@ pub fn parse_option(str_ptr: *const std::os::raw::c_char) -> Option<()> {
319319
eprintln!("WARNING: the {} option is only available when YJIT is built in dev mode, i.e. ./configure --enable-yjit=dev", opt_name);
320320
}
321321

322-
OPTIONS.dump_iseq_disasm = Some(opt_val.to_string());
322+
OPTIONS.dump_iseq_disasm = Some(opt_val.into());
323323
},
324324

325325
("no-type-prop", "") => unsafe { OPTIONS.no_type_prop = true },
@@ -346,7 +346,7 @@ pub fn parse_option(str_ptr: *const std::os::raw::c_char) -> Option<()> {
346346
let log_file_path = if std::path::Path::new(arg_value).is_dir() {
347347
format!("{arg_value}/yjit_{}.log", std::process::id())
348348
} else {
349-
arg_value.to_string()
349+
arg_value.into()
350350
};
351351

352352
match File::options().create(true).write(true).truncate(true).open(&log_file_path) {

0 commit comments

Comments
 (0)