Skip to content

Commit cd049ef

Browse files
Remove useless references/dereferences
1 parent c2c4322 commit cd049ef

File tree

12 files changed

+148
-168
lines changed

12 files changed

+148
-168
lines changed

compiler/rustc_mir_build/src/build/block.rs

+16-23
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2323
expr,
2424
targeted_by_break,
2525
safety_mode,
26-
} = ast_block;
26+
} = *ast_block;
2727
self.in_opt_scope(opt_destruction_scope.map(|de| (de, source_info)), move |this| {
28-
this.in_scope((*region_scope, source_info), LintLevel::Inherited, move |this| {
29-
if *targeted_by_break {
30-
this.in_breakable_scope(None, destination, *span, |this| {
28+
this.in_scope((region_scope, source_info), LintLevel::Inherited, move |this| {
29+
if targeted_by_break {
30+
this.in_breakable_scope(None, destination, span, |this| {
3131
Some(this.ast_block_stmts(
3232
destination,
3333
block,
34-
*span,
35-
&stmts,
36-
expr.as_deref(),
37-
*safety_mode,
34+
span,
35+
stmts,
36+
expr,
37+
safety_mode,
3838
))
3939
})
4040
} else {
41-
this.ast_block_stmts(
42-
destination,
43-
block,
44-
*span,
45-
&stmts,
46-
expr.as_deref(),
47-
*safety_mode,
48-
)
41+
this.ast_block_stmts(destination, block, span, stmts, expr, safety_mode)
4942
}
5043
})
5144
})
@@ -87,15 +80,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8780
let source_info = this.source_info(span);
8881
for Stmt { kind, opt_destruction_scope } in stmts {
8982
match kind {
90-
StmtKind::Expr { scope, expr } => {
83+
&StmtKind::Expr { scope, expr } => {
9184
this.block_context.push(BlockFrame::Statement { ignores_expr_result: true });
9285
unpack!(
9386
block = this.in_opt_scope(
9487
opt_destruction_scope.map(|de| (de, source_info)),
9588
|this| {
96-
let si = (*scope, source_info);
89+
let si = (scope, source_info);
9790
this.in_scope(si, LintLevel::Inherited, |this| {
98-
this.stmt_expr(block, &expr, Some(*scope))
91+
this.stmt_expr(block, expr, Some(scope))
9992
})
10093
}
10194
)
@@ -110,7 +103,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
110103
let_scope_stack.push(remainder_scope);
111104

112105
// Declare the bindings, which may create a source scope.
113-
let remainder_span = remainder_scope.span(this.tcx, &this.region_scope_tree);
106+
let remainder_span = remainder_scope.span(this.tcx, this.region_scope_tree);
114107

115108
let visibility_scope =
116109
Some(this.new_source_scope(remainder_span, LintLevel::Inherited, None));
@@ -128,11 +121,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
128121
this.declare_bindings(
129122
visibility_scope,
130123
remainder_span,
131-
&pattern,
124+
pattern,
132125
ArmHasGuard(false),
133126
Some((None, initializer_span)),
134127
);
135-
this.expr_into_pattern(block, pattern.clone(), &init)
128+
this.expr_into_pattern(block, pattern.clone(), init)
136129
})
137130
}
138131
)
@@ -143,7 +136,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
143136
this.declare_bindings(
144137
visibility_scope,
145138
remainder_span,
146-
&pattern,
139+
pattern,
147140
ArmHasGuard(false),
148141
None,
149142
);

compiler/rustc_mir_build/src/build/expr/as_constant.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1010
/// `expr` is a valid compile-time constant!
1111
crate fn as_constant(&mut self, expr: &Expr<'_, 'tcx>) -> Constant<'tcx> {
1212
let this = self;
13-
let Expr { ty, temp_lifetime: _, span, kind } = expr;
13+
let Expr { ty, temp_lifetime: _, span, ref kind } = *expr;
1414
match kind {
15-
ExprKind::Scope { region_scope: _, lint_level: _, value } => this.as_constant(&value),
15+
ExprKind::Scope { region_scope: _, lint_level: _, value } => this.as_constant(value),
1616
ExprKind::Literal { literal, user_ty, const_id: _ } => {
1717
let user_ty = user_ty.map(|user_ty| {
1818
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
19-
span: *span,
19+
span,
2020
user_ty,
2121
inferred_ty: ty,
2222
})
2323
});
24-
assert_eq!(literal.ty, *ty);
25-
Constant { span: *span, user_ty, literal }
24+
assert_eq!(literal.ty, ty);
25+
Constant { span, user_ty, literal }
2626
}
27-
ExprKind::StaticRef { literal, .. } => Constant { span: *span, user_ty: None, literal },
27+
ExprKind::StaticRef { literal, .. } => Constant { span, user_ty: None, literal },
2828
ExprKind::ConstBlock { value } => {
29-
Constant { span: *span, user_ty: None, literal: value }
29+
Constant { span: span, user_ty: None, literal: value }
3030
}
31-
_ => span_bug!(*span, "expression is not a valid constant {:?}", kind),
31+
_ => span_bug!(span, "expression is not a valid constant {:?}", kind),
3232
}
3333
}
3434
}

compiler/rustc_mir_build/src/build/expr/as_operand.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9898
debug!("as_operand(block={:?}, expr={:?})", block, expr);
9999
let this = self;
100100

101-
if let ExprKind::Scope { region_scope, lint_level, value } = &expr.kind {
101+
if let ExprKind::Scope { region_scope, lint_level, value } = expr.kind {
102102
let source_info = this.source_info(expr.span);
103-
let region_scope = (*region_scope, source_info);
103+
let region_scope = (region_scope, source_info);
104104
return this
105-
.in_scope(region_scope, *lint_level, |this| this.as_operand(block, scope, &value));
105+
.in_scope(region_scope, lint_level, |this| this.as_operand(block, scope, value));
106106
}
107107

108108
let category = Category::of(&expr.kind).unwrap();
@@ -128,11 +128,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
128128
debug!("as_call_operand(block={:?}, expr={:?})", block, expr);
129129
let this = self;
130130

131-
if let ExprKind::Scope { region_scope, lint_level, value } = &expr.kind {
131+
if let ExprKind::Scope { region_scope, lint_level, value } = expr.kind {
132132
let source_info = this.source_info(expr.span);
133-
let region_scope = (*region_scope, source_info);
134-
return this.in_scope(region_scope, *lint_level, |this| {
135-
this.as_call_operand(block, scope, &value)
133+
let region_scope = (region_scope, source_info);
134+
return this.in_scope(region_scope, lint_level, |this| {
135+
this.as_call_operand(block, scope, value)
136136
});
137137
}
138138

@@ -149,7 +149,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
149149

150150
// As described above, detect the case where we are passing a value of unsized
151151
// type, and that value is coming from the deref of a box.
152-
if let ExprKind::Deref { ref arg } = expr.kind {
152+
if let ExprKind::Deref { arg } = expr.kind {
153153
// Generate let tmp0 = arg0
154154
let operand = unpack!(block = this.as_temp(block, scope, arg, Mutability::Mut));
155155

compiler/rustc_mir_build/src/build/expr/as_place.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -406,59 +406,57 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
406406
let this = self;
407407
let expr_span = expr.span;
408408
let source_info = this.source_info(expr_span);
409-
match &expr.kind {
409+
match expr.kind {
410410
ExprKind::Scope { region_scope, lint_level, value } => {
411-
this.in_scope((*region_scope, source_info), *lint_level, |this| {
412-
this.expr_as_place(block, &value, mutability, fake_borrow_temps)
411+
this.in_scope((region_scope, source_info), lint_level, |this| {
412+
this.expr_as_place(block, value, mutability, fake_borrow_temps)
413413
})
414414
}
415415
ExprKind::Field { lhs, name } => {
416-
let place_builder = unpack!(
417-
block = this.expr_as_place(block, &lhs, mutability, fake_borrow_temps,)
418-
);
419-
block.and(place_builder.field(*name, expr.ty))
416+
let place_builder =
417+
unpack!(block = this.expr_as_place(block, lhs, mutability, fake_borrow_temps,));
418+
block.and(place_builder.field(name, expr.ty))
420419
}
421420
ExprKind::Deref { arg } => {
422-
let place_builder = unpack!(
423-
block = this.expr_as_place(block, &arg, mutability, fake_borrow_temps,)
424-
);
421+
let place_builder =
422+
unpack!(block = this.expr_as_place(block, arg, mutability, fake_borrow_temps,));
425423
block.and(place_builder.deref())
426424
}
427425
ExprKind::Index { lhs, index } => this.lower_index_expression(
428426
block,
429-
&lhs,
430-
&index,
427+
lhs,
428+
index,
431429
mutability,
432430
fake_borrow_temps,
433431
expr.temp_lifetime,
434432
expr_span,
435433
source_info,
436434
),
437435
ExprKind::UpvarRef { closure_def_id, var_hir_id } => {
438-
let upvar_id = ty::UpvarId::new(*var_hir_id, closure_def_id.expect_local());
436+
let upvar_id = ty::UpvarId::new(var_hir_id, closure_def_id.expect_local());
439437
this.lower_captured_upvar(block, upvar_id)
440438
}
441439

442440
ExprKind::VarRef { id } => {
443-
let place_builder = if this.is_bound_var_in_guard(*id) {
444-
let index = this.var_local_id(*id, RefWithinGuard);
441+
let place_builder = if this.is_bound_var_in_guard(id) {
442+
let index = this.var_local_id(id, RefWithinGuard);
445443
PlaceBuilder::from(index).deref()
446444
} else {
447-
let index = this.var_local_id(*id, OutsideGuard);
445+
let index = this.var_local_id(id, OutsideGuard);
448446
PlaceBuilder::from(index)
449447
};
450448
block.and(place_builder)
451449
}
452450

453451
ExprKind::PlaceTypeAscription { source, user_ty } => {
454452
let place_builder = unpack!(
455-
block = this.expr_as_place(block, &source, mutability, fake_borrow_temps,)
453+
block = this.expr_as_place(block, source, mutability, fake_borrow_temps,)
456454
);
457455
if let Some(user_ty) = user_ty {
458456
let annotation_index =
459457
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
460458
span: source_info.span,
461-
user_ty: *user_ty,
459+
user_ty,
462460
inferred_ty: expr.ty,
463461
});
464462

@@ -481,12 +479,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
481479
}
482480
ExprKind::ValueTypeAscription { source, user_ty } => {
483481
let temp =
484-
unpack!(block = this.as_temp(block, source.temp_lifetime, &source, mutability));
482+
unpack!(block = this.as_temp(block, source.temp_lifetime, source, mutability));
485483
if let Some(user_ty) = user_ty {
486484
let annotation_index =
487485
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
488486
span: source_info.span,
489-
user_ty: *user_ty,
487+
user_ty,
490488
inferred_ty: expr.ty,
491489
});
492490
this.cfg.push(

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+23-25
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4141
let expr_span = expr.span;
4242
let source_info = this.source_info(expr_span);
4343

44-
match &expr.kind {
45-
ExprKind::ThreadLocalRef(did) => block.and(Rvalue::ThreadLocalRef(*did)),
44+
match expr.kind {
45+
ExprKind::ThreadLocalRef(did) => block.and(Rvalue::ThreadLocalRef(did)),
4646
ExprKind::Scope { region_scope, lint_level, value } => {
47-
let region_scope = (*region_scope, source_info);
48-
this.in_scope(region_scope, *lint_level, |this| {
49-
this.as_rvalue(block, scope, &value)
50-
})
47+
let region_scope = (region_scope, source_info);
48+
this.in_scope(region_scope, lint_level, |this| this.as_rvalue(block, scope, value))
5149
}
5250
ExprKind::Repeat { value, count } => {
53-
let value_operand = unpack!(block = this.as_operand(block, scope, &value));
51+
let value_operand = unpack!(block = this.as_operand(block, scope, value));
5452
block.and(Rvalue::Repeat(value_operand, count))
5553
}
5654
ExprKind::Binary { op, lhs, rhs } => {
57-
let lhs = unpack!(block = this.as_operand(block, scope, &lhs));
58-
let rhs = unpack!(block = this.as_operand(block, scope, &rhs));
59-
this.build_binary_op(block, *op, expr_span, expr.ty, lhs, rhs)
55+
let lhs = unpack!(block = this.as_operand(block, scope, lhs));
56+
let rhs = unpack!(block = this.as_operand(block, scope, rhs));
57+
this.build_binary_op(block, op, expr_span, expr.ty, lhs, rhs)
6058
}
6159
ExprKind::Unary { op, arg } => {
62-
let arg = unpack!(block = this.as_operand(block, scope, &arg));
60+
let arg = unpack!(block = this.as_operand(block, scope, arg));
6361
// Check for -MIN on signed integers
64-
if this.check_overflow && *op == UnOp::Neg && expr.ty.is_signed() {
62+
if this.check_overflow && op == UnOp::Neg && expr.ty.is_signed() {
6563
let bool_ty = this.tcx.types.bool;
6664

6765
let minval = this.minval_literal(expr_span, expr.ty);
@@ -82,7 +80,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8280
expr_span,
8381
);
8482
}
85-
block.and(Rvalue::UnaryOp(*op, arg))
83+
block.and(Rvalue::UnaryOp(op, arg))
8684
}
8785
ExprKind::Box { value } => {
8886
// The `Box<T>` temporary created here is not a part of the HIR,
@@ -107,18 +105,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
107105
block = this.expr_into_dest(
108106
this.tcx.mk_place_deref(Place::from(result)),
109107
block,
110-
&value
108+
value
111109
)
112110
);
113111
block.and(Rvalue::Use(Operand::Move(Place::from(result))))
114112
}
115113
ExprKind::Cast { source } => {
116-
let source = unpack!(block = this.as_operand(block, scope, &source));
114+
let source = unpack!(block = this.as_operand(block, scope, source));
117115
block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty))
118116
}
119117
ExprKind::Pointer { cast, source } => {
120-
let source = unpack!(block = this.as_operand(block, scope, &source));
121-
block.and(Rvalue::Cast(CastKind::Pointer(*cast), source, expr.ty))
118+
let source = unpack!(block = this.as_operand(block, scope, source));
119+
block.and(Rvalue::Cast(CastKind::Pointer(cast), source, expr.ty))
122120
}
123121
ExprKind::Array { fields } => {
124122
// (*) We would (maybe) be closer to codegen if we
@@ -151,7 +149,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
151149
let el_ty = expr.ty.sequence_element_type(this.tcx);
152150
let fields: Vec<_> = fields
153151
.into_iter()
154-
.map(|f| unpack!(block = this.as_operand(block, scope, &f)))
152+
.map(|f| unpack!(block = this.as_operand(block, scope, f)))
155153
.collect();
156154

157155
block.and(Rvalue::Aggregate(box AggregateKind::Array(el_ty), fields))
@@ -161,7 +159,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
161159
// first process the set of fields
162160
let fields: Vec<_> = fields
163161
.into_iter()
164-
.map(|f| unpack!(block = this.as_operand(block, scope, &f)))
162+
.map(|f| unpack!(block = this.as_operand(block, scope, f)))
165163
.collect();
166164

167165
block.and(Rvalue::Aggregate(box AggregateKind::Tuple, fields))
@@ -181,25 +179,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
181179
// This occurs when capturing by copy/move, while
182180
// by reference captures use as_operand
183181
Some(Category::Place) => {
184-
let place = unpack!(block = this.as_place(block, &upvar));
182+
let place = unpack!(block = this.as_place(block, upvar));
185183
this.consume_by_copy_or_move(place)
186184
}
187185
_ => {
188186
// Turn mutable borrow captures into unique
189187
// borrow captures when capturing an immutable
190188
// variable. This is sound because the mutation
191189
// that caused the capture will cause an error.
192-
match &upvar.kind {
190+
match upvar.kind {
193191
ExprKind::Borrow {
194192
borrow_kind:
195193
BorrowKind::Mut { allow_two_phase_borrow: false },
196194
arg,
197195
} => unpack!(
198196
block = this.limit_capture_mutability(
199-
upvar.span, upvar.ty, scope, block, &arg,
197+
upvar.span, upvar.ty, scope, block, arg,
200198
)
201199
),
202-
_ => unpack!(block = this.as_operand(block, scope, &upvar)),
200+
_ => unpack!(block = this.as_operand(block, scope, upvar)),
203201
}
204202
}
205203
}
@@ -210,9 +208,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
210208
// We implicitly set the discriminant to 0. See
211209
// librustc_mir/transform/deaggregator.rs for details.
212210
let movability = movability.unwrap();
213-
box AggregateKind::Generator(*closure_id, substs, movability)
211+
box AggregateKind::Generator(closure_id, substs, movability)
214212
}
215-
UpvarSubsts::Closure(substs) => box AggregateKind::Closure(*closure_id, substs),
213+
UpvarSubsts::Closure(substs) => box AggregateKind::Closure(closure_id, substs),
216214
};
217215
block.and(Rvalue::Aggregate(result, operands))
218216
}

0 commit comments

Comments
 (0)