mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Simplify
This commit is contained in:
parent
284c1741d6
commit
8ea1afce28
16 changed files with 197 additions and 197 deletions
|
@ -151,7 +151,7 @@ impl CoerceMany {
|
|||
if let Some(id) = expr {
|
||||
ctx.result.type_mismatches.insert(
|
||||
id.into(),
|
||||
TypeMismatch { expected: self.merged_ty().clone(), actual: expr_ty.clone() },
|
||||
TypeMismatch { expected: self.merged_ty(), actual: expr_ty.clone() },
|
||||
);
|
||||
}
|
||||
cov_mark::hit!(coerce_merge_fail_fallback);
|
||||
|
|
|
@ -331,7 +331,7 @@ impl<'a> InferenceContext<'a> {
|
|||
let prev_diverges = mem::replace(&mut self.diverges, Diverges::Maybe);
|
||||
let prev_ret_ty = mem::replace(&mut self.return_ty, ret_ty.clone());
|
||||
let prev_ret_coercion =
|
||||
mem::replace(&mut self.return_coercion, Some(CoerceMany::new(ret_ty.clone())));
|
||||
mem::replace(&mut self.return_coercion, Some(CoerceMany::new(ret_ty)));
|
||||
let prev_resume_yield_tys =
|
||||
mem::replace(&mut self.resume_yield_tys, resume_yield_tys);
|
||||
|
||||
|
@ -402,7 +402,7 @@ impl<'a> InferenceContext<'a> {
|
|||
.push(callee_ty.clone())
|
||||
.push(TyBuilder::tuple_with(params.iter().cloned()))
|
||||
.build();
|
||||
self.write_method_resolution(tgt_expr, func, subst.clone());
|
||||
self.write_method_resolution(tgt_expr, func, subst)
|
||||
}
|
||||
}
|
||||
self.write_expr_adj(*callee, adjustments);
|
||||
|
@ -803,7 +803,7 @@ impl<'a> InferenceContext<'a> {
|
|||
.push(self_ty.clone())
|
||||
.push(index_ty.clone())
|
||||
.build();
|
||||
self.write_method_resolution(tgt_expr, func, substs.clone());
|
||||
self.write_method_resolution(tgt_expr, func, substs);
|
||||
}
|
||||
self.resolve_associated_type_with_params(
|
||||
self_ty,
|
||||
|
@ -912,7 +912,7 @@ impl<'a> InferenceContext<'a> {
|
|||
(elem_ty, consteval::usize_const(self.db, Some(0), krate))
|
||||
}
|
||||
Array::ElementList { elements, .. } => {
|
||||
let mut coerce = CoerceMany::new(elem_ty.clone());
|
||||
let mut coerce = CoerceMany::new(elem_ty);
|
||||
for &expr in elements.iter() {
|
||||
let cur_elem_ty = self.infer_expr_inner(expr, &expected);
|
||||
coerce.coerce(self, Some(expr), &cur_elem_ty);
|
||||
|
@ -1214,7 +1214,7 @@ impl<'a> InferenceContext<'a> {
|
|||
let g = self.resolver.update_to_inner_scope(self.db.upcast(), self.owner, expr);
|
||||
|
||||
let (break_ty, ty) =
|
||||
self.with_breakable_ctx(BreakableKind::Block, Some(coerce_ty.clone()), label, |this| {
|
||||
self.with_breakable_ctx(BreakableKind::Block, Some(coerce_ty), label, |this| {
|
||||
for stmt in statements {
|
||||
match stmt {
|
||||
Statement::Let { pat, type_ref, initializer, else_branch } => {
|
||||
|
|
|
@ -51,8 +51,8 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
type InternedGoal = Arc<GoalData<Self>>;
|
||||
type InternedGoals = Vec<Goal<Self>>;
|
||||
type InternedSubstitution = Interned<InternedWrapper<SmallVec<[GenericArg; 2]>>>;
|
||||
type InternedProgramClause = chalk_ir::ProgramClauseData<Self>;
|
||||
type InternedProgramClauses = Interned<InternedWrapper<Vec<chalk_ir::ProgramClause<Self>>>>;
|
||||
type InternedProgramClause = chalk_ir::ProgramClauseData<Self>;
|
||||
type InternedQuantifiedWhereClauses =
|
||||
Interned<InternedWrapper<Vec<chalk_ir::QuantifiedWhereClause<Self>>>>;
|
||||
type InternedVariableKinds = Interned<InternedWrapper<Vec<chalk_ir::VariableKind<Interner>>>>;
|
||||
|
@ -86,6 +86,27 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt)))
|
||||
}
|
||||
|
||||
fn debug_opaque_ty_id(
|
||||
opaque_ty_id: chalk_ir::OpaqueTyId<Self>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "OpaqueTy#{}", opaque_ty_id.0))
|
||||
}
|
||||
|
||||
fn debug_fn_def_id(
|
||||
fn_def_id: chalk_ir::FnDefId<Self>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
tls::with_current_program(|prog| Some(prog?.debug_fn_def_id(fn_def_id, fmt)))
|
||||
}
|
||||
|
||||
fn debug_closure_id(
|
||||
_fn_def_id: chalk_ir::ClosureId<Self>,
|
||||
_fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
None
|
||||
}
|
||||
|
||||
fn debug_alias(
|
||||
alias: &chalk_ir::AliasTy<Interner>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
|
@ -113,13 +134,6 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
Some(write!(fmt, "{:?}", opaque_ty.opaque_ty_id))
|
||||
}
|
||||
|
||||
fn debug_opaque_ty_id(
|
||||
opaque_ty_id: chalk_ir::OpaqueTyId<Self>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "OpaqueTy#{}", opaque_ty_id.0))
|
||||
}
|
||||
|
||||
fn debug_ty(ty: &chalk_ir::Ty<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", ty.data(Interner)))
|
||||
}
|
||||
|
@ -131,6 +145,13 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
Some(write!(fmt, "{:?}", lifetime.data(Interner)))
|
||||
}
|
||||
|
||||
fn debug_const(
|
||||
constant: &chalk_ir::Const<Self>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", constant.data(Interner)))
|
||||
}
|
||||
|
||||
fn debug_generic_arg(
|
||||
parameter: &GenericArg,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
|
@ -138,69 +159,42 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
Some(write!(fmt, "{:?}", parameter.data(Interner).inner_debug()))
|
||||
}
|
||||
|
||||
fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
|
||||
let goal_data = goal.data(Interner);
|
||||
Some(write!(fmt, "{goal_data:?}"))
|
||||
}
|
||||
|
||||
fn debug_goals(
|
||||
goals: &chalk_ir::Goals<Interner>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", goals.debug(Interner)))
|
||||
}
|
||||
|
||||
fn debug_program_clause_implication(
|
||||
pci: &chalk_ir::ProgramClauseImplication<Interner>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", pci.debug(Interner)))
|
||||
}
|
||||
|
||||
fn debug_substitution(
|
||||
substitution: &chalk_ir::Substitution<Interner>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", substitution.debug(Interner)))
|
||||
}
|
||||
|
||||
fn debug_separator_trait_ref(
|
||||
separator_trait_ref: &chalk_ir::SeparatorTraitRef<'_, Interner>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", separator_trait_ref.debug(Interner)))
|
||||
}
|
||||
|
||||
fn debug_fn_def_id(
|
||||
fn_def_id: chalk_ir::FnDefId<Self>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
tls::with_current_program(|prog| Some(prog?.debug_fn_def_id(fn_def_id, fmt)))
|
||||
}
|
||||
fn debug_const(
|
||||
constant: &chalk_ir::Const<Self>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", constant.data(Interner)))
|
||||
}
|
||||
fn debug_variable_kinds(
|
||||
variable_kinds: &chalk_ir::VariableKinds<Self>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", variable_kinds.as_slice(Interner)))
|
||||
}
|
||||
|
||||
fn debug_variable_kinds_with_angles(
|
||||
variable_kinds: &chalk_ir::VariableKinds<Self>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", variable_kinds.inner_debug(Interner)))
|
||||
}
|
||||
|
||||
fn debug_canonical_var_kinds(
|
||||
canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Self>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", canonical_var_kinds.as_slice(Interner)))
|
||||
}
|
||||
fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
|
||||
let goal_data = goal.data(Interner);
|
||||
Some(write!(fmt, "{goal_data:?}"))
|
||||
}
|
||||
fn debug_goals(
|
||||
goals: &chalk_ir::Goals<Interner>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", goals.debug(Interner)))
|
||||
}
|
||||
fn debug_program_clause_implication(
|
||||
pci: &chalk_ir::ProgramClauseImplication<Interner>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", pci.debug(Interner)))
|
||||
}
|
||||
fn debug_program_clause(
|
||||
clause: &chalk_ir::ProgramClause<Self>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
|
@ -213,6 +207,19 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", clauses.as_slice(Interner)))
|
||||
}
|
||||
fn debug_substitution(
|
||||
substitution: &chalk_ir::Substitution<Interner>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", substitution.debug(Interner)))
|
||||
}
|
||||
fn debug_separator_trait_ref(
|
||||
separator_trait_ref: &chalk_ir::SeparatorTraitRef<'_, Interner>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
Some(write!(fmt, "{:?}", separator_trait_ref.debug(Interner)))
|
||||
}
|
||||
|
||||
fn debug_quantified_where_clauses(
|
||||
clauses: &chalk_ir::QuantifiedWhereClauses<Self>,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
|
@ -220,6 +227,13 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
Some(write!(fmt, "{:?}", clauses.as_slice(Interner)))
|
||||
}
|
||||
|
||||
fn debug_constraints(
|
||||
_clauses: &chalk_ir::Constraints<Self>,
|
||||
_fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
None
|
||||
}
|
||||
|
||||
fn intern_ty(self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType {
|
||||
let flags = kind.compute_flags(self);
|
||||
Interned::new(InternedWrapper(chalk_ir::TyData { kind, flags }))
|
||||
|
@ -272,6 +286,10 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
Arc::new(goal)
|
||||
}
|
||||
|
||||
fn goal_data(self, goal: &Self::InternedGoal) -> &GoalData<Self> {
|
||||
goal
|
||||
}
|
||||
|
||||
fn intern_goals<E>(
|
||||
self,
|
||||
data: impl IntoIterator<Item = Result<Goal<Self>, E>>,
|
||||
|
@ -279,10 +297,6 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
data.into_iter().collect()
|
||||
}
|
||||
|
||||
fn goal_data(self, goal: &Self::InternedGoal) -> &GoalData<Self> {
|
||||
goal
|
||||
}
|
||||
|
||||
fn goals_data(self, goals: &Self::InternedGoals) -> &[Goal<Interner>] {
|
||||
goals
|
||||
}
|
||||
|
@ -367,32 +381,18 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
) -> &[chalk_ir::CanonicalVarKind<Self>] {
|
||||
canonical_var_kinds
|
||||
}
|
||||
|
||||
fn intern_constraints<E>(
|
||||
self,
|
||||
data: impl IntoIterator<Item = Result<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>, E>>,
|
||||
) -> Result<Self::InternedConstraints, E> {
|
||||
data.into_iter().collect()
|
||||
}
|
||||
|
||||
fn constraints_data(
|
||||
self,
|
||||
constraints: &Self::InternedConstraints,
|
||||
) -> &[chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] {
|
||||
constraints
|
||||
}
|
||||
fn debug_closure_id(
|
||||
_fn_def_id: chalk_ir::ClosureId<Self>,
|
||||
_fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
None
|
||||
}
|
||||
fn debug_constraints(
|
||||
_clauses: &chalk_ir::Constraints<Self>,
|
||||
_fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Option<fmt::Result> {
|
||||
None
|
||||
}
|
||||
|
||||
fn intern_variances<E>(
|
||||
self,
|
||||
|
|
|
@ -588,7 +588,7 @@ pub fn callable_sig_from_fnonce(
|
|||
let fn_once_trait = FnTrait::FnOnce.get_id(db, krate)?;
|
||||
let output_assoc_type = db.trait_data(fn_once_trait).associated_type_by_name(&name![Output])?;
|
||||
|
||||
let mut table = InferenceTable::new(db, env.clone());
|
||||
let mut table = InferenceTable::new(db, env);
|
||||
let b = TyBuilder::trait_ref(db, fn_once_trait);
|
||||
if b.remaining() != 2 {
|
||||
return None;
|
||||
|
|
|
@ -1414,7 +1414,7 @@ impl Evaluator<'_> {
|
|||
}
|
||||
CallableDefId::StructId(id) => {
|
||||
let (size, variant_layout, tag) =
|
||||
self.layout_of_variant(id.into(), generic_args.clone(), &locals)?;
|
||||
self.layout_of_variant(id.into(), generic_args, &locals)?;
|
||||
let result = self.make_by_layout(
|
||||
size,
|
||||
&variant_layout,
|
||||
|
@ -1425,7 +1425,7 @@ impl Evaluator<'_> {
|
|||
}
|
||||
CallableDefId::EnumVariantId(id) => {
|
||||
let (size, variant_layout, tag) =
|
||||
self.layout_of_variant(id.into(), generic_args.clone(), &locals)?;
|
||||
self.layout_of_variant(id.into(), generic_args, &locals)?;
|
||||
let result = self.make_by_layout(
|
||||
size,
|
||||
&variant_layout,
|
||||
|
@ -1507,7 +1507,7 @@ impl Evaluator<'_> {
|
|||
);
|
||||
}
|
||||
let (imp, generic_args) =
|
||||
lookup_impl_method(self.db, self.trait_env.clone(), def, generic_args.clone());
|
||||
lookup_impl_method(self.db, self.trait_env.clone(), def, generic_args);
|
||||
let generic_args = self.subst_filler(&generic_args, &locals);
|
||||
let def = imp.into();
|
||||
let mir_body =
|
||||
|
|
|
@ -69,9 +69,7 @@ pub(super) fn all_super_trait_refs<T>(
|
|||
cb: impl FnMut(TraitRef) -> Option<T>,
|
||||
) -> Option<T> {
|
||||
let seen = iter::once(trait_ref.trait_id).collect();
|
||||
let mut stack = Vec::new();
|
||||
stack.push(trait_ref);
|
||||
SuperTraits { db, seen, stack }.find_map(cb)
|
||||
SuperTraits { db, seen, stack: vec![trait_ref] }.find_map(cb)
|
||||
}
|
||||
|
||||
struct SuperTraits<'a> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue