Skip to content

Commit 7a98e24

Browse files
committed
Auto merge of rust-lang#14431 - Veykril:simplify, r=Veykril
minor: Simplify
2 parents 0d1ed56 + 8ea1afc commit 7a98e24

16 files changed

+196
-196
lines changed

crates/hir-ty/src/infer/coerce.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl CoerceMany {
151151
if let Some(id) = expr {
152152
ctx.result.type_mismatches.insert(
153153
id.into(),
154-
TypeMismatch { expected: self.merged_ty().clone(), actual: expr_ty.clone() },
154+
TypeMismatch { expected: self.merged_ty(), actual: expr_ty.clone() },
155155
);
156156
}
157157
cov_mark::hit!(coerce_merge_fail_fallback);

crates/hir-ty/src/infer/expr.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl<'a> InferenceContext<'a> {
333333
let prev_diverges = mem::replace(&mut self.diverges, Diverges::Maybe);
334334
let prev_ret_ty = mem::replace(&mut self.return_ty, ret_ty.clone());
335335
let prev_ret_coercion =
336-
mem::replace(&mut self.return_coercion, Some(CoerceMany::new(ret_ty.clone())));
336+
mem::replace(&mut self.return_coercion, Some(CoerceMany::new(ret_ty)));
337337
let prev_resume_yield_tys =
338338
mem::replace(&mut self.resume_yield_tys, resume_yield_tys);
339339

@@ -404,7 +404,7 @@ impl<'a> InferenceContext<'a> {
404404
.push(callee_ty.clone())
405405
.push(TyBuilder::tuple_with(params.iter().cloned()))
406406
.build();
407-
self.write_method_resolution(tgt_expr, func, subst.clone());
407+
self.write_method_resolution(tgt_expr, func, subst)
408408
}
409409
}
410410
self.write_expr_adj(*callee, adjustments);
@@ -805,7 +805,7 @@ impl<'a> InferenceContext<'a> {
805805
.push(self_ty.clone())
806806
.push(index_ty.clone())
807807
.build();
808-
self.write_method_resolution(tgt_expr, func, substs.clone());
808+
self.write_method_resolution(tgt_expr, func, substs);
809809
}
810810
self.resolve_associated_type_with_params(
811811
self_ty,
@@ -914,7 +914,7 @@ impl<'a> InferenceContext<'a> {
914914
(elem_ty, consteval::usize_const(self.db, Some(0), krate))
915915
}
916916
Array::ElementList { elements, .. } => {
917-
let mut coerce = CoerceMany::new(elem_ty.clone());
917+
let mut coerce = CoerceMany::new(elem_ty);
918918
for &expr in elements.iter() {
919919
let cur_elem_ty = self.infer_expr_inner(expr, &expected);
920920
coerce.coerce(self, Some(expr), &cur_elem_ty);
@@ -1222,7 +1222,7 @@ impl<'a> InferenceContext<'a> {
12221222
});
12231223

12241224
let (break_ty, ty) =
1225-
self.with_breakable_ctx(BreakableKind::Block, Some(coerce_ty.clone()), label, |this| {
1225+
self.with_breakable_ctx(BreakableKind::Block, Some(coerce_ty), label, |this| {
12261226
for stmt in statements {
12271227
match stmt {
12281228
Statement::Let { pat, type_ref, initializer, else_branch } => {

crates/hir-ty/src/interner.rs

+70-70
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ impl chalk_ir::interner::Interner for Interner {
5151
type InternedGoal = Arc<GoalData<Self>>;
5252
type InternedGoals = Vec<Goal<Self>>;
5353
type InternedSubstitution = Interned<InternedWrapper<SmallVec<[GenericArg; 2]>>>;
54-
type InternedProgramClause = chalk_ir::ProgramClauseData<Self>;
5554
type InternedProgramClauses = Interned<InternedWrapper<Vec<chalk_ir::ProgramClause<Self>>>>;
55+
type InternedProgramClause = chalk_ir::ProgramClauseData<Self>;
5656
type InternedQuantifiedWhereClauses =
5757
Interned<InternedWrapper<Vec<chalk_ir::QuantifiedWhereClause<Self>>>>;
5858
type InternedVariableKinds = Interned<InternedWrapper<Vec<chalk_ir::VariableKind<Interner>>>>;
@@ -86,6 +86,27 @@ impl chalk_ir::interner::Interner for Interner {
8686
tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt)))
8787
}
8888

89+
fn debug_opaque_ty_id(
90+
opaque_ty_id: chalk_ir::OpaqueTyId<Self>,
91+
fmt: &mut fmt::Formatter<'_>,
92+
) -> Option<fmt::Result> {
93+
Some(write!(fmt, "OpaqueTy#{}", opaque_ty_id.0))
94+
}
95+
96+
fn debug_fn_def_id(
97+
fn_def_id: chalk_ir::FnDefId<Self>,
98+
fmt: &mut fmt::Formatter<'_>,
99+
) -> Option<fmt::Result> {
100+
tls::with_current_program(|prog| Some(prog?.debug_fn_def_id(fn_def_id, fmt)))
101+
}
102+
103+
fn debug_closure_id(
104+
_fn_def_id: chalk_ir::ClosureId<Self>,
105+
_fmt: &mut fmt::Formatter<'_>,
106+
) -> Option<fmt::Result> {
107+
None
108+
}
109+
89110
fn debug_alias(
90111
alias: &chalk_ir::AliasTy<Interner>,
91112
fmt: &mut fmt::Formatter<'_>,
@@ -113,13 +134,6 @@ impl chalk_ir::interner::Interner for Interner {
113134
Some(write!(fmt, "{:?}", opaque_ty.opaque_ty_id))
114135
}
115136

116-
fn debug_opaque_ty_id(
117-
opaque_ty_id: chalk_ir::OpaqueTyId<Self>,
118-
fmt: &mut fmt::Formatter<'_>,
119-
) -> Option<fmt::Result> {
120-
Some(write!(fmt, "OpaqueTy#{}", opaque_ty_id.0))
121-
}
122-
123137
fn debug_ty(ty: &chalk_ir::Ty<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
124138
Some(write!(fmt, "{:?}", ty.data(Interner)))
125139
}
@@ -131,76 +145,56 @@ impl chalk_ir::interner::Interner for Interner {
131145
Some(write!(fmt, "{:?}", lifetime.data(Interner)))
132146
}
133147

134-
fn debug_generic_arg(
135-
parameter: &GenericArg,
136-
fmt: &mut fmt::Formatter<'_>,
137-
) -> Option<fmt::Result> {
138-
Some(write!(fmt, "{:?}", parameter.data(Interner).inner_debug()))
139-
}
140-
141-
fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
142-
let goal_data = goal.data(Interner);
143-
Some(write!(fmt, "{goal_data:?}"))
144-
}
145-
146-
fn debug_goals(
147-
goals: &chalk_ir::Goals<Interner>,
148-
fmt: &mut fmt::Formatter<'_>,
149-
) -> Option<fmt::Result> {
150-
Some(write!(fmt, "{:?}", goals.debug(Interner)))
151-
}
152-
153-
fn debug_program_clause_implication(
154-
pci: &chalk_ir::ProgramClauseImplication<Interner>,
155-
fmt: &mut fmt::Formatter<'_>,
156-
) -> Option<fmt::Result> {
157-
Some(write!(fmt, "{:?}", pci.debug(Interner)))
158-
}
159-
160-
fn debug_substitution(
161-
substitution: &chalk_ir::Substitution<Interner>,
148+
fn debug_const(
149+
constant: &chalk_ir::Const<Self>,
162150
fmt: &mut fmt::Formatter<'_>,
163151
) -> Option<fmt::Result> {
164-
Some(write!(fmt, "{:?}", substitution.debug(Interner)))
152+
Some(write!(fmt, "{:?}", constant.data(Interner)))
165153
}
166154

167-
fn debug_separator_trait_ref(
168-
separator_trait_ref: &chalk_ir::SeparatorTraitRef<'_, Interner>,
155+
fn debug_generic_arg(
156+
parameter: &GenericArg,
169157
fmt: &mut fmt::Formatter<'_>,
170158
) -> Option<fmt::Result> {
171-
Some(write!(fmt, "{:?}", separator_trait_ref.debug(Interner)))
159+
Some(write!(fmt, "{:?}", parameter.data(Interner).inner_debug()))
172160
}
173161

174-
fn debug_fn_def_id(
175-
fn_def_id: chalk_ir::FnDefId<Self>,
176-
fmt: &mut fmt::Formatter<'_>,
177-
) -> Option<fmt::Result> {
178-
tls::with_current_program(|prog| Some(prog?.debug_fn_def_id(fn_def_id, fmt)))
179-
}
180-
fn debug_const(
181-
constant: &chalk_ir::Const<Self>,
182-
fmt: &mut fmt::Formatter<'_>,
183-
) -> Option<fmt::Result> {
184-
Some(write!(fmt, "{:?}", constant.data(Interner)))
185-
}
186162
fn debug_variable_kinds(
187163
variable_kinds: &chalk_ir::VariableKinds<Self>,
188164
fmt: &mut fmt::Formatter<'_>,
189165
) -> Option<fmt::Result> {
190166
Some(write!(fmt, "{:?}", variable_kinds.as_slice(Interner)))
191167
}
168+
192169
fn debug_variable_kinds_with_angles(
193170
variable_kinds: &chalk_ir::VariableKinds<Self>,
194171
fmt: &mut fmt::Formatter<'_>,
195172
) -> Option<fmt::Result> {
196173
Some(write!(fmt, "{:?}", variable_kinds.inner_debug(Interner)))
197174
}
175+
198176
fn debug_canonical_var_kinds(
199177
canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Self>,
200178
fmt: &mut fmt::Formatter<'_>,
201179
) -> Option<fmt::Result> {
202180
Some(write!(fmt, "{:?}", canonical_var_kinds.as_slice(Interner)))
203181
}
182+
fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
183+
let goal_data = goal.data(Interner);
184+
Some(write!(fmt, "{goal_data:?}"))
185+
}
186+
fn debug_goals(
187+
goals: &chalk_ir::Goals<Interner>,
188+
fmt: &mut fmt::Formatter<'_>,
189+
) -> Option<fmt::Result> {
190+
Some(write!(fmt, "{:?}", goals.debug(Interner)))
191+
}
192+
fn debug_program_clause_implication(
193+
pci: &chalk_ir::ProgramClauseImplication<Interner>,
194+
fmt: &mut fmt::Formatter<'_>,
195+
) -> Option<fmt::Result> {
196+
Some(write!(fmt, "{:?}", pci.debug(Interner)))
197+
}
204198
fn debug_program_clause(
205199
clause: &chalk_ir::ProgramClause<Self>,
206200
fmt: &mut fmt::Formatter<'_>,
@@ -213,13 +207,33 @@ impl chalk_ir::interner::Interner for Interner {
213207
) -> Option<fmt::Result> {
214208
Some(write!(fmt, "{:?}", clauses.as_slice(Interner)))
215209
}
210+
fn debug_substitution(
211+
substitution: &chalk_ir::Substitution<Interner>,
212+
fmt: &mut fmt::Formatter<'_>,
213+
) -> Option<fmt::Result> {
214+
Some(write!(fmt, "{:?}", substitution.debug(Interner)))
215+
}
216+
fn debug_separator_trait_ref(
217+
separator_trait_ref: &chalk_ir::SeparatorTraitRef<'_, Interner>,
218+
fmt: &mut fmt::Formatter<'_>,
219+
) -> Option<fmt::Result> {
220+
Some(write!(fmt, "{:?}", separator_trait_ref.debug(Interner)))
221+
}
222+
216223
fn debug_quantified_where_clauses(
217224
clauses: &chalk_ir::QuantifiedWhereClauses<Self>,
218225
fmt: &mut fmt::Formatter<'_>,
219226
) -> Option<fmt::Result> {
220227
Some(write!(fmt, "{:?}", clauses.as_slice(Interner)))
221228
}
222229

230+
fn debug_constraints(
231+
_clauses: &chalk_ir::Constraints<Self>,
232+
_fmt: &mut fmt::Formatter<'_>,
233+
) -> Option<fmt::Result> {
234+
None
235+
}
236+
223237
fn intern_ty(self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType {
224238
let flags = kind.compute_flags(self);
225239
Interned::new(InternedWrapper(chalk_ir::TyData { kind, flags }))
@@ -272,17 +286,17 @@ impl chalk_ir::interner::Interner for Interner {
272286
Arc::new(goal)
273287
}
274288

289+
fn goal_data(self, goal: &Self::InternedGoal) -> &GoalData<Self> {
290+
goal
291+
}
292+
275293
fn intern_goals<E>(
276294
self,
277295
data: impl IntoIterator<Item = Result<Goal<Self>, E>>,
278296
) -> Result<Self::InternedGoals, E> {
279297
data.into_iter().collect()
280298
}
281299

282-
fn goal_data(self, goal: &Self::InternedGoal) -> &GoalData<Self> {
283-
goal
284-
}
285-
286300
fn goals_data(self, goals: &Self::InternedGoals) -> &[Goal<Interner>] {
287301
goals
288302
}
@@ -367,32 +381,18 @@ impl chalk_ir::interner::Interner for Interner {
367381
) -> &[chalk_ir::CanonicalVarKind<Self>] {
368382
canonical_var_kinds
369383
}
370-
371384
fn intern_constraints<E>(
372385
self,
373386
data: impl IntoIterator<Item = Result<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>, E>>,
374387
) -> Result<Self::InternedConstraints, E> {
375388
data.into_iter().collect()
376389
}
377-
378390
fn constraints_data(
379391
self,
380392
constraints: &Self::InternedConstraints,
381393
) -> &[chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] {
382394
constraints
383395
}
384-
fn debug_closure_id(
385-
_fn_def_id: chalk_ir::ClosureId<Self>,
386-
_fmt: &mut fmt::Formatter<'_>,
387-
) -> Option<fmt::Result> {
388-
None
389-
}
390-
fn debug_constraints(
391-
_clauses: &chalk_ir::Constraints<Self>,
392-
_fmt: &mut fmt::Formatter<'_>,
393-
) -> Option<fmt::Result> {
394-
None
395-
}
396396

397397
fn intern_variances<E>(
398398
self,

crates/hir-ty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ pub fn callable_sig_from_fnonce(
587587
let fn_once_trait = FnTrait::FnOnce.get_id(db, krate)?;
588588
let output_assoc_type = db.trait_data(fn_once_trait).associated_type_by_name(&name![Output])?;
589589

590-
let mut table = InferenceTable::new(db, env.clone());
590+
let mut table = InferenceTable::new(db, env);
591591
let b = TyBuilder::trait_ref(db, fn_once_trait);
592592
if b.remaining() != 2 {
593593
return None;

crates/hir-ty/src/mir/eval.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ impl Evaluator<'_> {
14141414
}
14151415
CallableDefId::StructId(id) => {
14161416
let (size, variant_layout, tag) =
1417-
self.layout_of_variant(id.into(), generic_args.clone(), &locals)?;
1417+
self.layout_of_variant(id.into(), generic_args, &locals)?;
14181418
let result = self.make_by_layout(
14191419
size,
14201420
&variant_layout,
@@ -1425,7 +1425,7 @@ impl Evaluator<'_> {
14251425
}
14261426
CallableDefId::EnumVariantId(id) => {
14271427
let (size, variant_layout, tag) =
1428-
self.layout_of_variant(id.into(), generic_args.clone(), &locals)?;
1428+
self.layout_of_variant(id.into(), generic_args, &locals)?;
14291429
let result = self.make_by_layout(
14301430
size,
14311431
&variant_layout,
@@ -1507,7 +1507,7 @@ impl Evaluator<'_> {
15071507
);
15081508
}
15091509
let (imp, generic_args) =
1510-
lookup_impl_method(self.db, self.trait_env.clone(), def, generic_args.clone());
1510+
lookup_impl_method(self.db, self.trait_env.clone(), def, generic_args);
15111511
let generic_args = self.subst_filler(&generic_args, &locals);
15121512
let def = imp.into();
15131513
let mir_body =

crates/hir-ty/src/utils.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ pub(super) fn all_super_trait_refs<T>(
6969
cb: impl FnMut(TraitRef) -> Option<T>,
7070
) -> Option<T> {
7171
let seen = iter::once(trait_ref.trait_id).collect();
72-
let mut stack = Vec::new();
73-
stack.push(trait_ref);
74-
SuperTraits { db, seen, stack }.find_map(cb)
72+
SuperTraits { db, seen, stack: vec![trait_ref] }.find_map(cb)
7573
}
7674

7775
struct SuperTraits<'a> {

crates/ide-assists/src/handlers/add_missing_match_arms.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
148148
return None;
149149
}
150150

151-
let variants_of_enums = vec![variants.clone(); len];
151+
let variants_of_enums = vec![variants; len];
152152

153153
let missing_pats = variants_of_enums
154154
.into_iter()

0 commit comments

Comments
 (0)