Skip to content

Commit ff4efd0

Browse files
committed
Fix unnessessary borrow
1 parent 0e360f5 commit ff4efd0

40 files changed

+132
-132
lines changed

common/src/borrow.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ impl<T: ?Sized> Deref for BorrowedValue<'_, T> {
3737
fn deref(&self) -> &T {
3838
match self {
3939
Self::Ref(r) => r,
40-
Self::MuLock(m) => &m,
41-
Self::MappedMuLock(m) => &m,
42-
Self::ReadLock(r) => &r,
43-
Self::MappedReadLock(m) => &m,
40+
Self::MuLock(m) => m,
41+
Self::MappedMuLock(m) => m,
42+
Self::ReadLock(r) => r,
43+
Self::MappedReadLock(m) => m,
4444
}
4545
}
4646
}
@@ -76,10 +76,10 @@ impl<T: ?Sized> Deref for BorrowedValueMut<'_, T> {
7676
fn deref(&self) -> &T {
7777
match self {
7878
Self::RefMut(r) => r,
79-
Self::MuLock(m) => &m,
80-
Self::MappedMuLock(m) => &m,
81-
Self::WriteLock(w) => &w,
82-
Self::MappedWriteLock(w) => &w,
79+
Self::MuLock(m) => m,
80+
Self::MappedMuLock(m) => m,
81+
Self::WriteLock(w) => w,
82+
Self::MappedWriteLock(w) => w,
8383
}
8484
}
8585
}

compiler/src/compile.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl Compiler {
348348
self.emit(Instruction::PrintExpr);
349349
}
350350
} else {
351-
self.compile_statement(&statement)?;
351+
self.compile_statement(statement)?;
352352
}
353353
}
354354

@@ -470,7 +470,7 @@ impl Compiler {
470470
// we do this here because `from __future__` still executes that `from` statement at runtime,
471471
// we still need to compile the ImportFrom down below
472472
ImportFrom { module, names, .. } if module.as_deref() == Some("__future__") => {
473-
self.compile_future_features(&names)?
473+
self.compile_future_features(names)?
474474
}
475475
// if we find any other statement, stop accepting future statements
476476
_ => self.done_with_future_stmts = true,
@@ -1068,7 +1068,7 @@ impl Compiler {
10681068
self.emit_constant(ConstantData::Str {
10691069
value: self.mangle(&arg.node.arg).into_owned(),
10701070
});
1071-
self.compile_expression(&annotation)?;
1071+
self.compile_expression(annotation)?;
10721072
num_annotations += 1;
10731073
}
10741074
}
@@ -1159,7 +1159,7 @@ impl Compiler {
11591159
orelse,
11601160
finalbody,
11611161
..
1162-
} => self.find_ann(&body) || self.find_ann(orelse) || self.find_ann(finalbody),
1162+
} => self.find_ann(body) || self.find_ann(orelse) || self.find_ann(finalbody),
11631163
_ => false,
11641164
};
11651165
if res {

compiler/src/symboltable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ impl SymbolTableBuilder {
617617

618618
fn scan_parameter_annotation(&mut self, parameter: &ast::Arg) -> SymbolTableResult {
619619
if let Some(annotation) = &parameter.node.annotation {
620-
self.scan_expression(&annotation, ExpressionContext::Load)?;
620+
self.scan_expression(annotation, ExpressionContext::Load)?;
621621
}
622622
Ok(())
623623
}
@@ -1075,7 +1075,7 @@ impl SymbolTableBuilder {
10751075
// Evaluate eventual default parameters:
10761076
self.scan_expressions(&args.defaults, ExpressionContext::Load)?;
10771077
for expression in args.kw_defaults.iter().flatten() {
1078-
self.scan_expression(&expression, ExpressionContext::Load)?;
1078+
self.scan_expression(expression, ExpressionContext::Load)?;
10791079
}
10801080

10811081
// Annotations are scanned in outer scope:

derive/src/from_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl ArgAttribute {
8181
}
8282
match arg {
8383
NestedMeta::Meta(Meta::Path(path)) => {
84-
if path_eq(&path, "default") || path_eq(&path, "optional") {
84+
if path_eq(path, "default") || path_eq(path, "optional") {
8585
if self.default.is_none() {
8686
self.default = Some(None);
8787
}

derive/src/pyclass.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn extract_items_into_context<'a, Item>(
2828
{
2929
for item in items {
3030
let r = item.try_split_attr_mut(|attrs, item| {
31-
let (pyitems, cfgs) = attrs_to_content_items(&attrs, new_impl_item::<Item>)?;
31+
let (pyitems, cfgs) = attrs_to_content_items(attrs, new_impl_item::<Item>)?;
3232
for pyitem in pyitems.iter().rev() {
3333
let r = pyitem.gen_impl_item(ImplItemArgs::<Item> {
3434
item,
@@ -227,7 +227,7 @@ pub(crate) fn impl_pyclass(
227227
let class_name = class_meta.class_name()?;
228228
let module_name = class_meta.module()?;
229229
let base = class_meta.base()?;
230-
let class_def = generate_class_def(&ident, &class_name, module_name.as_deref(), base, &attrs)?;
230+
let class_def = generate_class_def(ident, &class_name, module_name.as_deref(), base, attrs)?;
231231

232232
let ret = quote! {
233233
#item
@@ -424,7 +424,7 @@ where
424424
};
425425
let (py_name, tokens) = if args.item.is_function_or_method() || args.item.is_const() {
426426
let ident = args.item.get_ident().unwrap();
427-
let py_name = get_py_name(&attr, &ident)?;
427+
let py_name = get_py_name(&attr, ident)?;
428428

429429
let value = if args.item.is_const() {
430430
// TODO: ctx.new_value

derive/src/pymodule.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn impl_pymodule(
3939
// collect to context
4040
for item in items.iter_mut() {
4141
let r = item.try_split_attr_mut(|attrs, item| {
42-
let (pyitems, cfgs) = attrs_to_module_items(&attrs, new_module_item)?;
42+
let (pyitems, cfgs) = attrs_to_module_items(attrs, new_module_item)?;
4343
for pyitem in pyitems.iter().rev() {
4444
let r = pyitem.gen_module_item(ModuleItemArgs {
4545
item,
@@ -283,7 +283,7 @@ impl ModuleItem for FunctionItem {
283283

284284
impl ModuleItem for ClassItem {
285285
fn gen_module_item(&self, args: ModuleItemArgs<'_>) -> Result<()> {
286-
let (ident, _) = pyclass_ident_and_attrs(&args.item)?;
286+
let (ident, _) = pyclass_ident_and_attrs(args.item)?;
287287
let (module_name, class_name) = {
288288
let class_attr = &mut args.attrs[self.inner.index];
289289
if self.pyattrs.is_empty() {
@@ -350,7 +350,7 @@ impl ModuleItem for AttributeItem {
350350
let (py_name, tokens) = match args.item {
351351
Item::Fn(syn::ItemFn { sig, .. }) => {
352352
let ident = &sig.ident;
353-
let py_name = get_py_name(&attr, &ident)?;
353+
let py_name = get_py_name(&attr, ident)?;
354354
(
355355
py_name.clone(),
356356
quote! {
@@ -359,7 +359,7 @@ impl ModuleItem for AttributeItem {
359359
)
360360
}
361361
Item::Const(syn::ItemConst { ident, .. }) => {
362-
let py_name = get_py_name(&attr, &ident)?;
362+
let py_name = get_py_name(&attr, ident)?;
363363
(
364364
py_name.clone(),
365365
quote! {

jit/src/instructions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
138138
continue;
139139
}
140140

141-
self.add_instruction(&instruction, &bytecode.constants)?;
141+
self.add_instruction(instruction, &bytecode.constants)?;
142142
}
143143

144144
Ok(())

src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ where
142142
}
143143
}
144144
Err(err) => {
145-
print_exception(&vm, err);
145+
print_exception(vm, err);
146146
1
147147
}
148148
};
@@ -535,9 +535,9 @@ fn run_rustpython(vm: &VirtualMachine, matches: &ArgMatches) -> PyResult<()> {
535535

536536
// Figure out if a -c option was given:
537537
if let Some(command) = matches.value_of("c") {
538-
run_command(&vm, scope, command.to_owned())?;
538+
run_command(vm, scope, command.to_owned())?;
539539
} else if let Some(module) = matches.value_of("m") {
540-
run_module(&vm, module)?;
540+
run_module(vm, module)?;
541541
} else if matches.is_present("install_pip") {
542542
let get_getpip = rustpython_vm::py_compile!(
543543
source = r#"\
@@ -555,16 +555,16 @@ __import__("io").TextIOWrapper(
555555
eprintln!("running get-pip.py...");
556556
_run_string(vm, scope, getpip_code.as_str(), "get-pip.py".to_owned())?;
557557
} else if let Some(filename) = matches.value_of("script") {
558-
run_script(&vm, scope.clone(), filename)?;
558+
run_script(vm, scope.clone(), filename)?;
559559
if matches.is_present("inspect") {
560-
shell::run_shell(&vm, scope)?;
560+
shell::run_shell(vm, scope)?;
561561
}
562562
} else {
563563
println!(
564564
"Welcome to the magnificent Rust Python {} interpreter \u{1f631} \u{1f596}",
565565
crate_version!()
566566
);
567-
shell::run_shell(&vm, scope)?;
567+
shell::run_shell(vm, scope)?;
568568
}
569569

570570
Ok(())

vm/src/anystr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub trait AnyStr<'s>: 's {
247247
{
248248
if range.is_normal() {
249249
let start = range.start;
250-
let index = find(self.get_chars(range), &needle)?;
250+
let index = find(self.get_chars(range), needle)?;
251251
Some(start + index)
252252
} else {
253253
None
@@ -260,7 +260,7 @@ pub trait AnyStr<'s>: 's {
260260
F: Fn(&Self, &Self) -> usize,
261261
{
262262
if range.is_normal() {
263-
count(self.get_chars(range), &needle)
263+
count(self.get_chars(range), needle)
264264
} else {
265265
0
266266
}
@@ -336,21 +336,21 @@ pub trait AnyStr<'s>: 's {
336336
FC: Fn(&Self, &Self) -> bool,
337337
{
338338
//if self.py_starts_with(prefix) {
339-
if is_prefix(&self, prefix) {
339+
if is_prefix(self, prefix) {
340340
self.get_bytes(prefix_len..self.bytes_len())
341341
} else {
342-
&self
342+
self
343343
}
344344
}
345345

346346
fn py_removesuffix<FC>(&self, suffix: &Self, suffix_len: usize, is_suffix: FC) -> &Self
347347
where
348348
FC: Fn(&Self, &Self) -> bool,
349349
{
350-
if is_suffix(&self, suffix) {
350+
if is_suffix(self, suffix) {
351351
self.get_bytes(0..self.bytes_len() - suffix_len)
352352
} else {
353-
&self
353+
self
354354
}
355355
}
356356

vm/src/builtins/complex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl Comparable for PyComplex {
350350
let result = if let Some(other) = other.payload_if_subclass::<PyComplex>(vm) {
351351
zelf.value == other.value
352352
} else {
353-
match float::to_op_float(&other, vm) {
353+
match float::to_op_float(other, vm) {
354354
Ok(Some(other)) => zelf.value == other.into(),
355355
Err(_) => false,
356356
Ok(None) => return Ok(PyComparisonValue::NotImplemented),

0 commit comments

Comments
 (0)