Fix clippy::needless_borrow
in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
This commit is contained in:
parent
0ff8610964
commit
21a870515b
304 changed files with 1101 additions and 1174 deletions
|
@ -31,7 +31,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
destination,
|
||||
block,
|
||||
span,
|
||||
&stmts,
|
||||
stmts,
|
||||
expr,
|
||||
safety_mode,
|
||||
region_scope,
|
||||
|
@ -42,7 +42,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
destination,
|
||||
block,
|
||||
span,
|
||||
&stmts,
|
||||
stmts,
|
||||
expr,
|
||||
safety_mode,
|
||||
region_scope,
|
||||
|
@ -312,7 +312,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
None,
|
||||
Some((None, initializer_span)),
|
||||
);
|
||||
this.expr_into_pattern(block, &pattern, init)
|
||||
this.expr_into_pattern(block, pattern, init)
|
||||
// irrefutable pattern
|
||||
})
|
||||
},
|
||||
|
|
|
@ -88,7 +88,7 @@ pub(super) fn build_custom_mir<'tcx>(
|
|||
};
|
||||
|
||||
let res: PResult<_> = try {
|
||||
pctxt.parse_args(¶ms)?;
|
||||
pctxt.parse_args(params)?;
|
||||
pctxt.parse_body(expr)?;
|
||||
};
|
||||
if let Err(err) = res {
|
||||
|
|
|
@ -175,7 +175,7 @@ fn to_upvars_resolved_place_builder<'tcx>(
|
|||
projection: &[PlaceElem<'tcx>],
|
||||
) -> Option<PlaceBuilder<'tcx>> {
|
||||
let Some((capture_index, capture)) =
|
||||
find_capture_matching_projections(&cx.upvars, var_hir_id, &projection)
|
||||
find_capture_matching_projections(&cx.upvars, var_hir_id, projection)
|
||||
else {
|
||||
let closure_span = cx.tcx.def_span(closure_def_id);
|
||||
if !enable_precise_capture(closure_span) {
|
||||
|
@ -683,7 +683,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, fake_borrow_deref_ty);
|
||||
let fake_borrow_temp =
|
||||
self.local_decls.push(LocalDecl::new(fake_borrow_ty, expr_span));
|
||||
let projection = tcx.mk_place_elems(&base_place.projection);
|
||||
let projection = tcx.mk_place_elems(base_place.projection);
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
|
|
|
@ -212,7 +212,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let scrutinee_place =
|
||||
unpack!(block = self.lower_scrutinee(block, scrutinee, scrutinee_span,));
|
||||
|
||||
let mut arm_candidates = self.create_match_candidates(&scrutinee_place, &arms);
|
||||
let mut arm_candidates = self.create_match_candidates(&scrutinee_place, arms);
|
||||
|
||||
let match_has_guard = arm_candidates.iter().any(|(_, candidate)| candidate.has_guard);
|
||||
let mut candidates =
|
||||
|
@ -424,7 +424,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
this.source_scope = source_scope;
|
||||
}
|
||||
|
||||
this.expr_into_dest(destination, arm_block, &&this.thir[arm.body])
|
||||
this.expr_into_dest(destination, arm_block, &this.thir[arm.body])
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
@ -505,7 +505,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let binding_end = self.bind_and_guard_matched_candidate(
|
||||
leaf_candidate,
|
||||
parent_bindings,
|
||||
&fake_borrow_temps,
|
||||
fake_borrow_temps,
|
||||
scrutinee_span,
|
||||
arm_match_scope,
|
||||
schedule_drops,
|
||||
|
@ -613,7 +613,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
_ => {
|
||||
let place_builder =
|
||||
unpack!(block = self.lower_scrutinee(block, initializer, initializer.span));
|
||||
self.place_into_pattern(block, &irrefutable_pat, place_builder, true)
|
||||
self.place_into_pattern(block, irrefutable_pat, place_builder, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -625,7 +625,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
initializer: PlaceBuilder<'tcx>,
|
||||
set_match_place: bool,
|
||||
) -> BlockAnd<()> {
|
||||
let mut candidate = Candidate::new(initializer.clone(), &irrefutable_pat, false, self);
|
||||
let mut candidate = Candidate::new(initializer.clone(), irrefutable_pat, false, self);
|
||||
let fake_borrow_temps = self.lower_match_tree(
|
||||
block,
|
||||
irrefutable_pat.span,
|
||||
|
@ -700,7 +700,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
opt_match_place: Option<(Option<&Place<'tcx>>, Span)>,
|
||||
) -> Option<SourceScope> {
|
||||
self.visit_primary_bindings(
|
||||
&pattern,
|
||||
pattern,
|
||||
UserTypeProjections::none(),
|
||||
&mut |this, mutability, name, mode, var, span, ty, user_ty| {
|
||||
if visibility_scope.is_none() {
|
||||
|
@ -1843,7 +1843,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let expr_span = expr.span;
|
||||
let expr_place_builder = unpack!(block = self.lower_scrutinee(block, expr, expr_span));
|
||||
let wildcard = Pat::wildcard_from_ty(pat.ty);
|
||||
let mut guard_candidate = Candidate::new(expr_place_builder.clone(), &pat, false, self);
|
||||
let mut guard_candidate = Candidate::new(expr_place_builder.clone(), pat, false, self);
|
||||
let mut otherwise_candidate =
|
||||
Candidate::new(expr_place_builder.clone(), &wildcard, false, self);
|
||||
let fake_borrow_temps = self.lower_match_tree(
|
||||
|
|
|
@ -69,7 +69,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
{
|
||||
existing_bindings.extend_from_slice(&new_bindings);
|
||||
mem::swap(&mut candidate.bindings, &mut existing_bindings);
|
||||
candidate.subcandidates = self.create_or_subcandidates(candidate, &place, pats);
|
||||
candidate.subcandidates = self.create_or_subcandidates(candidate, place, pats);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -736,7 +736,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
// These are all binary tests.
|
||||
//
|
||||
// FIXME(#29623) we can be more clever here
|
||||
let pattern_test = self.test(&match_pair);
|
||||
let pattern_test = self.test(match_pair);
|
||||
if pattern_test.kind == test.kind {
|
||||
self.candidate_without_match_pair(match_pair_index, candidate);
|
||||
Some(0)
|
||||
|
|
|
@ -938,12 +938,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
scope = self.declare_bindings(
|
||||
scope,
|
||||
expr.span,
|
||||
&pat,
|
||||
pat,
|
||||
None,
|
||||
Some((Some(&place), span)),
|
||||
);
|
||||
let place_builder = PlaceBuilder::from(local);
|
||||
unpack!(block = self.place_into_pattern(block, &pat, place_builder, false));
|
||||
unpack!(block = self.place_into_pattern(block, pat, place_builder, false));
|
||||
}
|
||||
}
|
||||
self.source_scope = original_source_scope;
|
||||
|
@ -954,7 +954,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
self.source_scope = source_scope;
|
||||
}
|
||||
|
||||
self.expr_into_dest(Place::return_place(), block, &expr)
|
||||
self.expr_into_dest(Place::return_place(), block, expr)
|
||||
}
|
||||
|
||||
fn set_correct_source_scope_for_arg(
|
||||
|
|
|
@ -995,7 +995,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
}
|
||||
|
||||
if scope.region_scope == region_scope {
|
||||
let region_scope_span = region_scope.span(self.tcx, &self.region_scope_tree);
|
||||
let region_scope_span = region_scope.span(self.tcx, self.region_scope_tree);
|
||||
// Attribute scope exit drops to scope's closing brace.
|
||||
let scope_end = self.tcx.sess.source_map().end_point(region_scope_span);
|
||||
|
||||
|
|
|
@ -200,7 +200,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for LayoutConstrainedPlaceVisitor<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
||||
fn thir(&self) -> &'a Thir<'tcx> {
|
||||
&self.thir
|
||||
self.thir
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, block: &Block) {
|
||||
|
|
|
@ -51,7 +51,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
let hir_id = stmt.hir_id;
|
||||
let opt_dxn_ext = self.region_scope_tree.opt_destruction_scope(hir_id.local_id);
|
||||
match stmt.kind {
|
||||
hir::StmtKind::Expr(ref expr) | hir::StmtKind::Semi(ref expr) => {
|
||||
hir::StmtKind::Expr(expr) | hir::StmtKind::Semi(expr) => {
|
||||
let stmt = Stmt {
|
||||
kind: StmtKind::Expr {
|
||||
scope: region::Scope {
|
||||
|
@ -68,7 +68,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
// ignore for purposes of the MIR
|
||||
None
|
||||
}
|
||||
hir::StmtKind::Local(ref local) => {
|
||||
hir::StmtKind::Local(local) => {
|
||||
let remainder_scope = region::Scope {
|
||||
id: block_id,
|
||||
data: region::ScopeData::Remainder(region::FirstStatementIndex::new(
|
||||
|
|
|
@ -261,7 +261,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
|
||||
let kind = match expr.kind {
|
||||
// Here comes the interesting stuff:
|
||||
hir::ExprKind::MethodCall(segment, receiver, ref args, fn_span) => {
|
||||
hir::ExprKind::MethodCall(segment, receiver, args, fn_span) => {
|
||||
// Rewrite a.b(c) into UFCS form like Trait::b(a, c)
|
||||
let expr = self.method_callee(expr, segment.ident.span, None);
|
||||
info!("Using method span: {:?}", expr.span);
|
||||
|
@ -278,7 +278,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
hir::ExprKind::Call(ref fun, ref args) => {
|
||||
hir::ExprKind::Call(fun, ref args) => {
|
||||
if self.typeck_results().is_method_call(expr) {
|
||||
// The callee is something implementing Fn, FnMut, or FnOnce.
|
||||
// Find the actual method implementation being called and
|
||||
|
@ -346,7 +346,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
&& let Some(adt_def) = expr_ty.ty_adt_def()
|
||||
{
|
||||
match qpath {
|
||||
hir::QPath::Resolved(_, ref path) => match path.res {
|
||||
hir::QPath::Resolved(_, path) => match path.res {
|
||||
Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
|
||||
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
|
||||
}
|
||||
|
@ -407,21 +407,21 @@ impl<'tcx> Cx<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, mutbl, ref arg) => {
|
||||
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, mutbl, arg) => {
|
||||
ExprKind::Borrow { borrow_kind: mutbl.to_borrow_kind(), arg: self.mirror_expr(arg) }
|
||||
}
|
||||
|
||||
hir::ExprKind::AddrOf(hir::BorrowKind::Raw, mutability, ref arg) => {
|
||||
hir::ExprKind::AddrOf(hir::BorrowKind::Raw, mutability, arg) => {
|
||||
ExprKind::AddressOf { mutability, arg: self.mirror_expr(arg) }
|
||||
}
|
||||
|
||||
hir::ExprKind::Block(ref blk, _) => ExprKind::Block { block: self.mirror_block(blk) },
|
||||
hir::ExprKind::Block(blk, _) => ExprKind::Block { block: self.mirror_block(blk) },
|
||||
|
||||
hir::ExprKind::Assign(ref lhs, ref rhs, _) => {
|
||||
hir::ExprKind::Assign(lhs, rhs, _) => {
|
||||
ExprKind::Assign { lhs: self.mirror_expr(lhs), rhs: self.mirror_expr(rhs) }
|
||||
}
|
||||
|
||||
hir::ExprKind::AssignOp(op, ref lhs, ref rhs) => {
|
||||
hir::ExprKind::AssignOp(op, lhs, rhs) => {
|
||||
if self.typeck_results().is_method_call(expr) {
|
||||
let lhs = self.mirror_expr(lhs);
|
||||
let rhs = self.mirror_expr(rhs);
|
||||
|
@ -435,9 +435,9 @@ impl<'tcx> Cx<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
hir::ExprKind::Lit(ref lit) => ExprKind::Literal { lit, neg: false },
|
||||
hir::ExprKind::Lit(lit) => ExprKind::Literal { lit, neg: false },
|
||||
|
||||
hir::ExprKind::Binary(op, ref lhs, ref rhs) => {
|
||||
hir::ExprKind::Binary(op, lhs, rhs) => {
|
||||
if self.typeck_results().is_method_call(expr) {
|
||||
let lhs = self.mirror_expr(lhs);
|
||||
let rhs = self.mirror_expr(rhs);
|
||||
|
@ -466,7 +466,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
hir::ExprKind::Index(ref lhs, ref index, brackets_span) => {
|
||||
hir::ExprKind::Index(lhs, index, brackets_span) => {
|
||||
if self.typeck_results().is_method_call(expr) {
|
||||
let lhs = self.mirror_expr(lhs);
|
||||
let index = self.mirror_expr(index);
|
||||
|
@ -482,7 +482,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
hir::ExprKind::Unary(hir::UnOp::Deref, ref arg) => {
|
||||
hir::ExprKind::Unary(hir::UnOp::Deref, arg) => {
|
||||
if self.typeck_results().is_method_call(expr) {
|
||||
let arg = self.mirror_expr(arg);
|
||||
self.overloaded_place(expr, expr_ty, None, Box::new([arg]), expr.span)
|
||||
|
@ -491,7 +491,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
hir::ExprKind::Unary(hir::UnOp::Not, ref arg) => {
|
||||
hir::ExprKind::Unary(hir::UnOp::Not, arg) => {
|
||||
if self.typeck_results().is_method_call(expr) {
|
||||
let arg = self.mirror_expr(arg);
|
||||
self.overloaded_operator(expr, Box::new([arg]))
|
||||
|
@ -500,18 +500,18 @@ impl<'tcx> Cx<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
hir::ExprKind::Unary(hir::UnOp::Neg, ref arg) => {
|
||||
hir::ExprKind::Unary(hir::UnOp::Neg, arg) => {
|
||||
if self.typeck_results().is_method_call(expr) {
|
||||
let arg = self.mirror_expr(arg);
|
||||
self.overloaded_operator(expr, Box::new([arg]))
|
||||
} else if let hir::ExprKind::Lit(ref lit) = arg.kind {
|
||||
} else if let hir::ExprKind::Lit(lit) = arg.kind {
|
||||
ExprKind::Literal { lit, neg: true }
|
||||
} else {
|
||||
ExprKind::Unary { op: UnOp::Neg, arg: self.mirror_expr(arg) }
|
||||
}
|
||||
}
|
||||
|
||||
hir::ExprKind::Struct(ref qpath, ref fields, ref base) => match expr_ty.kind() {
|
||||
hir::ExprKind::Struct(qpath, fields, ref base) => match expr_ty.kind() {
|
||||
ty::Adt(adt, args) => match adt.adt_kind() {
|
||||
AdtKind::Struct | AdtKind::Union => {
|
||||
let user_provided_types = self.typeck_results().user_provided_types();
|
||||
|
@ -614,13 +614,13 @@ impl<'tcx> Cx<'tcx> {
|
|||
self.convert_path_expr(expr, res)
|
||||
}
|
||||
|
||||
hir::ExprKind::InlineAsm(ref asm) => ExprKind::InlineAsm(Box::new(InlineAsmExpr {
|
||||
hir::ExprKind::InlineAsm(asm) => ExprKind::InlineAsm(Box::new(InlineAsmExpr {
|
||||
template: asm.template,
|
||||
operands: asm
|
||||
.operands
|
||||
.iter()
|
||||
.map(|(op, _op_sp)| match *op {
|
||||
hir::InlineAsmOperand::In { reg, ref expr } => {
|
||||
hir::InlineAsmOperand::In { reg, expr } => {
|
||||
InlineAsmOperand::In { reg, expr: self.mirror_expr(expr) }
|
||||
}
|
||||
hir::InlineAsmOperand::Out { reg, late, ref expr } => {
|
||||
|
@ -630,20 +630,17 @@ impl<'tcx> Cx<'tcx> {
|
|||
expr: expr.map(|expr| self.mirror_expr(expr)),
|
||||
}
|
||||
}
|
||||
hir::InlineAsmOperand::InOut { reg, late, ref expr } => {
|
||||
hir::InlineAsmOperand::InOut { reg, late, expr } => {
|
||||
InlineAsmOperand::InOut { reg, late, expr: self.mirror_expr(expr) }
|
||||
}
|
||||
hir::InlineAsmOperand::SplitInOut {
|
||||
reg,
|
||||
late,
|
||||
ref in_expr,
|
||||
ref out_expr,
|
||||
} => InlineAsmOperand::SplitInOut {
|
||||
reg,
|
||||
late,
|
||||
in_expr: self.mirror_expr(in_expr),
|
||||
out_expr: out_expr.map(|expr| self.mirror_expr(expr)),
|
||||
},
|
||||
hir::InlineAsmOperand::SplitInOut { reg, late, in_expr, ref out_expr } => {
|
||||
InlineAsmOperand::SplitInOut {
|
||||
reg,
|
||||
late,
|
||||
in_expr: self.mirror_expr(in_expr),
|
||||
out_expr: out_expr.map(|expr| self.mirror_expr(expr)),
|
||||
}
|
||||
}
|
||||
hir::InlineAsmOperand::Const { ref anon_const } => {
|
||||
let value =
|
||||
mir::Const::from_anon_const(tcx, anon_const.def_id, self.param_env);
|
||||
|
@ -686,7 +683,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
ExprKind::ConstBlock { did, args }
|
||||
}
|
||||
// Now comes the rote stuff:
|
||||
hir::ExprKind::Repeat(ref v, _) => {
|
||||
hir::ExprKind::Repeat(v, _) => {
|
||||
let ty = self.typeck_results().expr_ty(expr);
|
||||
let ty::Array(_, count) = ty.kind() else {
|
||||
span_bug!(expr.span, "unexpected repeat expr ty: {:?}", ty);
|
||||
|
@ -722,12 +719,12 @@ impl<'tcx> Cx<'tcx> {
|
|||
then: self.mirror_expr(then),
|
||||
else_opt: else_opt.map(|el| self.mirror_expr(el)),
|
||||
},
|
||||
hir::ExprKind::Match(ref discr, ref arms, _) => ExprKind::Match {
|
||||
hir::ExprKind::Match(discr, arms, _) => ExprKind::Match {
|
||||
scrutinee: self.mirror_expr(discr),
|
||||
scrutinee_hir_id: discr.hir_id,
|
||||
arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
|
||||
},
|
||||
hir::ExprKind::Loop(ref body, ..) => {
|
||||
hir::ExprKind::Loop(body, ..) => {
|
||||
let block_ty = self.typeck_results().node_type(body.hir_id);
|
||||
let temp_lifetime = self
|
||||
.rvalue_scopes
|
||||
|
@ -741,12 +738,12 @@ impl<'tcx> Cx<'tcx> {
|
|||
});
|
||||
ExprKind::Loop { body }
|
||||
}
|
||||
hir::ExprKind::Field(ref source, ..) => ExprKind::Field {
|
||||
hir::ExprKind::Field(source, ..) => ExprKind::Field {
|
||||
lhs: self.mirror_expr(source),
|
||||
variant_index: FIRST_VARIANT,
|
||||
name: self.typeck_results.field_index(expr.hir_id),
|
||||
},
|
||||
hir::ExprKind::Cast(ref source, ref cast_ty) => {
|
||||
hir::ExprKind::Cast(source, cast_ty) => {
|
||||
// Check for a user-given type annotation on this `cast`
|
||||
let user_provided_types = self.typeck_results.user_provided_types();
|
||||
let user_ty = user_provided_types.get(cast_ty.hir_id);
|
||||
|
@ -756,7 +753,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
expr, cast_ty.hir_id, user_ty,
|
||||
);
|
||||
|
||||
let cast = self.mirror_expr_cast(*source, temp_lifetime, expr.span);
|
||||
let cast = self.mirror_expr_cast(source, temp_lifetime, expr.span);
|
||||
|
||||
if let Some(user_ty) = user_ty {
|
||||
// NOTE: Creating a new Expr and wrapping a Cast inside of it may be
|
||||
|
@ -777,7 +774,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
cast
|
||||
}
|
||||
}
|
||||
hir::ExprKind::Type(ref source, ref ty) => {
|
||||
hir::ExprKind::Type(source, ty) => {
|
||||
let user_provided_types = self.typeck_results.user_provided_types();
|
||||
let user_ty = user_provided_types.get(ty.hir_id).copied().map(Box::new);
|
||||
debug!("make_mirror_unadjusted: (type) user_ty={:?}", user_ty);
|
||||
|
@ -788,15 +785,11 @@ impl<'tcx> Cx<'tcx> {
|
|||
ExprKind::ValueTypeAscription { source: mirrored, user_ty }
|
||||
}
|
||||
}
|
||||
hir::ExprKind::DropTemps(ref source) => {
|
||||
ExprKind::Use { source: self.mirror_expr(source) }
|
||||
}
|
||||
hir::ExprKind::Array(ref fields) => {
|
||||
ExprKind::Array { fields: self.mirror_exprs(fields) }
|
||||
}
|
||||
hir::ExprKind::Tup(ref fields) => ExprKind::Tuple { fields: self.mirror_exprs(fields) },
|
||||
hir::ExprKind::DropTemps(source) => ExprKind::Use { source: self.mirror_expr(source) },
|
||||
hir::ExprKind::Array(fields) => ExprKind::Array { fields: self.mirror_exprs(fields) },
|
||||
hir::ExprKind::Tup(fields) => ExprKind::Tuple { fields: self.mirror_exprs(fields) },
|
||||
|
||||
hir::ExprKind::Yield(ref v, _) => ExprKind::Yield { value: self.mirror_expr(v) },
|
||||
hir::ExprKind::Yield(v, _) => ExprKind::Yield { value: self.mirror_expr(v) },
|
||||
hir::ExprKind::Err(_) => unreachable!(),
|
||||
};
|
||||
|
||||
|
@ -870,10 +863,10 @@ impl<'tcx> Cx<'tcx> {
|
|||
|
||||
fn convert_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) -> ArmId {
|
||||
let arm = Arm {
|
||||
pattern: self.pattern_from_hir(&arm.pat),
|
||||
pattern: self.pattern_from_hir(arm.pat),
|
||||
guard: arm.guard.as_ref().map(|g| match g {
|
||||
hir::Guard::If(ref e) => Guard::If(self.mirror_expr(e)),
|
||||
hir::Guard::IfLet(ref l) => {
|
||||
hir::Guard::If(e) => Guard::If(self.mirror_expr(e)),
|
||||
hir::Guard::IfLet(l) => {
|
||||
Guard::IfLet(self.pattern_from_hir(l.pat), self.mirror_expr(l.init))
|
||||
}
|
||||
}),
|
||||
|
|
|
@ -27,10 +27,10 @@ pub(crate) fn thir_body(
|
|||
if let Some(reported) = cx.typeck_results.tainted_by_errors {
|
||||
return Err(reported);
|
||||
}
|
||||
let expr = cx.mirror_expr(&body.value);
|
||||
let expr = cx.mirror_expr(body.value);
|
||||
|
||||
let owner_id = hir.local_def_id_to_hir_id(owner_def);
|
||||
if let Some(ref fn_decl) = hir.fn_decl_by_hir_id(owner_id) {
|
||||
if let Some(fn_decl) = hir.fn_decl_by_hir_id(owner_id) {
|
||||
let closure_env_param = cx.closure_env_param(owner_def, owner_id);
|
||||
let explicit_params = cx.explicit_params(owner_id, fn_decl, body);
|
||||
cx.thir.params = closure_env_param.into_iter().chain(explicit_params).collect();
|
||||
|
|
|
@ -298,7 +298,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
|||
tcx: self.tcx,
|
||||
param_env: self.param_env,
|
||||
module: self.tcx.parent_module(self.lint_level).to_def_id(),
|
||||
pattern_arena: &self.pattern_arena,
|
||||
pattern_arena: self.pattern_arena,
|
||||
match_span,
|
||||
refutable,
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ fn expand_or_pat<'p, 'tcx>(pat: &'p Pat<'tcx>) -> Vec<&'p Pat<'tcx>> {
|
|||
fn expand<'p, 'tcx>(pat: &'p Pat<'tcx>, vec: &mut Vec<&'p Pat<'tcx>>) {
|
||||
if let PatKind::Or { pats } = &pat.kind {
|
||||
for pat in pats.iter() {
|
||||
expand(&pat, vec);
|
||||
expand(pat, vec);
|
||||
}
|
||||
} else {
|
||||
vec.push(pat)
|
||||
|
@ -1099,7 +1099,7 @@ impl ConstructorSet {
|
|||
|
||||
for variant in visible_variants {
|
||||
let ctor = Variant(*variant);
|
||||
if seen_set.contains(&variant) {
|
||||
if seen_set.contains(variant) {
|
||||
present.push(ctor);
|
||||
} else {
|
||||
missing.push(ctor);
|
||||
|
@ -1108,7 +1108,7 @@ impl ConstructorSet {
|
|||
|
||||
for variant in hidden_variants {
|
||||
let ctor = Variant(*variant);
|
||||
if seen_set.contains(&variant) {
|
||||
if seen_set.contains(variant) {
|
||||
present.push(ctor);
|
||||
} else {
|
||||
skipped_a_hidden_variant = true;
|
||||
|
|
|
@ -266,16 +266,16 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
return self.lower_path(qpath, pat.hir_id, pat.span);
|
||||
}
|
||||
|
||||
hir::PatKind::Ref(ref subpattern, _) | hir::PatKind::Box(ref subpattern) => {
|
||||
hir::PatKind::Ref(subpattern, _) | hir::PatKind::Box(subpattern) => {
|
||||
PatKind::Deref { subpattern: self.lower_pattern(subpattern) }
|
||||
}
|
||||
|
||||
hir::PatKind::Slice(ref prefix, ref slice, ref suffix) => {
|
||||
hir::PatKind::Slice(prefix, ref slice, suffix) => {
|
||||
self.slice_or_array_pattern(pat.span, ty, prefix, slice, suffix)
|
||||
}
|
||||
|
||||
hir::PatKind::Tuple(ref pats, ddpos) => {
|
||||
let ty::Tuple(ref tys) = ty.kind() else {
|
||||
hir::PatKind::Tuple(pats, ddpos) => {
|
||||
let ty::Tuple(tys) = ty.kind() else {
|
||||
span_bug!(pat.span, "unexpected type for tuple pattern: {:?}", ty);
|
||||
};
|
||||
let subpatterns = self.lower_tuple_subpats(pats, tys.len(), ddpos);
|
||||
|
@ -325,7 +325,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
hir::PatKind::TupleStruct(ref qpath, ref pats, ddpos) => {
|
||||
hir::PatKind::TupleStruct(ref qpath, pats, ddpos) => {
|
||||
let res = self.typeck_results.qpath_res(qpath, pat.hir_id);
|
||||
let ty::Adt(adt_def, _) = ty.kind() else {
|
||||
span_bug!(pat.span, "tuple struct pattern not applied to an ADT {:?}", ty);
|
||||
|
@ -335,20 +335,20 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
self.lower_variant_or_leaf(res, pat.hir_id, pat.span, ty, subpatterns)
|
||||
}
|
||||
|
||||
hir::PatKind::Struct(ref qpath, ref fields, _) => {
|
||||
hir::PatKind::Struct(ref qpath, fields, _) => {
|
||||
let res = self.typeck_results.qpath_res(qpath, pat.hir_id);
|
||||
let subpatterns = fields
|
||||
.iter()
|
||||
.map(|field| FieldPat {
|
||||
field: self.typeck_results.field_index(field.hir_id),
|
||||
pattern: self.lower_pattern(&field.pat),
|
||||
pattern: self.lower_pattern(field.pat),
|
||||
})
|
||||
.collect();
|
||||
|
||||
self.lower_variant_or_leaf(res, pat.hir_id, pat.span, ty, subpatterns)
|
||||
}
|
||||
|
||||
hir::PatKind::Or(ref pats) => PatKind::Or { pats: self.lower_patterns(pats) },
|
||||
hir::PatKind::Or(pats) => PatKind::Or { pats: self.lower_patterns(pats) },
|
||||
};
|
||||
|
||||
Box::new(Pat { span, ty, kind })
|
||||
|
|
|
@ -648,7 +648,7 @@ impl<'tcx> Usefulness<'tcx> {
|
|||
} else {
|
||||
witnesses
|
||||
.into_iter()
|
||||
.map(|witness| witness.apply_constructor(pcx, &ctor))
|
||||
.map(|witness| witness.apply_constructor(pcx, ctor))
|
||||
.collect()
|
||||
};
|
||||
WithWitnesses(new_witnesses)
|
||||
|
@ -934,7 +934,7 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
|
|||
let relevant_patterns =
|
||||
self.patterns.iter().filter(|pat| ctor.is_covered_by(pcx, pat.ctor()));
|
||||
for pat in relevant_patterns {
|
||||
let specialized = pat.specialize(pcx, &ctor);
|
||||
let specialized = pat.specialize(pcx, ctor);
|
||||
for (subpat, column) in specialized.iter().zip(&mut specialized_columns) {
|
||||
if subpat.is_or_pat() {
|
||||
column.patterns.extend(subpat.flatten_or_pat())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue