mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
collapsible_match
This commit is contained in:
parent
657376858f
commit
4184c6af0d
6 changed files with 50 additions and 65 deletions
|
@ -169,7 +169,6 @@ new_ret_no_self = "allow"
|
||||||
## Following lints should be tackled at some point
|
## Following lints should be tackled at some point
|
||||||
borrowed_box = "allow"
|
borrowed_box = "allow"
|
||||||
borrow_deref_ref = "allow"
|
borrow_deref_ref = "allow"
|
||||||
collapsible_match = "allow"
|
|
||||||
clone_on_copy = "allow"
|
clone_on_copy = "allow"
|
||||||
derivable_impls = "allow"
|
derivable_impls = "allow"
|
||||||
derived_hash_with_manual_eq = "allow"
|
derived_hash_with_manual_eq = "allow"
|
||||||
|
|
|
@ -334,12 +334,10 @@ impl InferenceContext<'_> {
|
||||||
match &self.body[tgt_expr] {
|
match &self.body[tgt_expr] {
|
||||||
Expr::Path(p) => {
|
Expr::Path(p) => {
|
||||||
let resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr);
|
let resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr);
|
||||||
if let Some(r) = resolver.resolve_path_in_value_ns(self.db.upcast(), p) {
|
if let Some(ResolveValueResult::ValueNs(ValueNs::LocalBinding(b), _)) =
|
||||||
if let ResolveValueResult::ValueNs(v, _) = r {
|
resolver.resolve_path_in_value_ns(self.db.upcast(), p)
|
||||||
if let ValueNs::LocalBinding(b) = v {
|
{
|
||||||
return Some(HirPlace { local: b, projections: vec![] });
|
return Some(HirPlace { local: b, projections: vec![] });
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr::Field { expr, name: _ } => {
|
Expr::Field { expr, name: _ } => {
|
||||||
|
|
|
@ -1387,10 +1387,7 @@ impl Evaluator<'_> {
|
||||||
| CastKind::PointerFromExposedAddress => {
|
| CastKind::PointerFromExposedAddress => {
|
||||||
let current_ty = self.operand_ty(operand, locals)?;
|
let current_ty = self.operand_ty(operand, locals)?;
|
||||||
let is_signed = match current_ty.kind(Interner) {
|
let is_signed = match current_ty.kind(Interner) {
|
||||||
TyKind::Scalar(s) => match s {
|
TyKind::Scalar(chalk_ir::Scalar::Int(_)) => true,
|
||||||
chalk_ir::Scalar::Int(_) => true,
|
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
let current = pad16(self.eval_operand(operand, locals)?.get(self)?, is_signed);
|
let current = pad16(self.eval_operand(operand, locals)?.get(self)?, is_signed);
|
||||||
|
|
|
@ -160,57 +160,53 @@ impl MirLowerCtx<'_> {
|
||||||
_ => try_rvalue(self),
|
_ => try_rvalue(self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr::UnaryOp { expr, op } => match op {
|
Expr::UnaryOp { expr, op: hir_def::hir::UnaryOp::Deref } => {
|
||||||
hir_def::hir::UnaryOp::Deref => {
|
let is_builtin = match self.expr_ty_without_adjust(*expr).kind(Interner) {
|
||||||
let is_builtin = match self.expr_ty_without_adjust(*expr).kind(Interner) {
|
TyKind::Ref(..) | TyKind::Raw(..) => true,
|
||||||
TyKind::Ref(..) | TyKind::Raw(..) => true,
|
TyKind::Adt(id, _) => {
|
||||||
TyKind::Adt(id, _) => {
|
if let Some(lang_item) = self.db.lang_attr(id.0.into()) {
|
||||||
if let Some(lang_item) = self.db.lang_attr(id.0.into()) {
|
lang_item == LangItem::OwnedBox
|
||||||
lang_item == LangItem::OwnedBox
|
} else {
|
||||||
} else {
|
false
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
if !is_builtin {
|
|
||||||
let Some((p, current)) = self.lower_expr_as_place(current, *expr, true)?
|
|
||||||
else {
|
|
||||||
return Ok(None);
|
|
||||||
};
|
|
||||||
return self.lower_overloaded_deref(
|
|
||||||
current,
|
|
||||||
p,
|
|
||||||
self.expr_ty_after_adjustments(*expr),
|
|
||||||
self.expr_ty_without_adjust(expr_id),
|
|
||||||
expr_id.into(),
|
|
||||||
'b: {
|
|
||||||
if let Some((f, _)) = self.infer.method_resolution(expr_id) {
|
|
||||||
if let Some(deref_trait) =
|
|
||||||
self.resolve_lang_item(LangItem::DerefMut)?.as_trait()
|
|
||||||
{
|
|
||||||
if let Some(deref_fn) = self
|
|
||||||
.db
|
|
||||||
.trait_data(deref_trait)
|
|
||||||
.method_by_name(&name![deref_mut])
|
|
||||||
{
|
|
||||||
break 'b deref_fn == f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
let Some((mut r, current)) = self.lower_expr_as_place(current, *expr, true)?
|
_ => false,
|
||||||
else {
|
};
|
||||||
|
if !is_builtin {
|
||||||
|
let Some((p, current)) = self.lower_expr_as_place(current, *expr, true)? else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
r = r.project(ProjectionElem::Deref, &mut self.result.projection_store);
|
return self.lower_overloaded_deref(
|
||||||
Ok(Some((r, current)))
|
current,
|
||||||
|
p,
|
||||||
|
self.expr_ty_after_adjustments(*expr),
|
||||||
|
self.expr_ty_without_adjust(expr_id),
|
||||||
|
expr_id.into(),
|
||||||
|
'b: {
|
||||||
|
if let Some((f, _)) = self.infer.method_resolution(expr_id) {
|
||||||
|
if let Some(deref_trait) =
|
||||||
|
self.resolve_lang_item(LangItem::DerefMut)?.as_trait()
|
||||||
|
{
|
||||||
|
if let Some(deref_fn) = self
|
||||||
|
.db
|
||||||
|
.trait_data(deref_trait)
|
||||||
|
.method_by_name(&name![deref_mut])
|
||||||
|
{
|
||||||
|
break 'b deref_fn == f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_ => try_rvalue(self),
|
let Some((mut r, current)) = self.lower_expr_as_place(current, *expr, true)? else {
|
||||||
},
|
return Ok(None);
|
||||||
|
};
|
||||||
|
r = r.project(ProjectionElem::Deref, &mut self.result.projection_store);
|
||||||
|
Ok(Some((r, current)))
|
||||||
|
}
|
||||||
|
Expr::UnaryOp { .. } => try_rvalue(self),
|
||||||
Expr::Field { expr, .. } => {
|
Expr::Field { expr, .. } => {
|
||||||
let Some((mut r, current)) = self.lower_expr_as_place(current, *expr, true)? else {
|
let Some((mut r, current)) = self.lower_expr_as_place(current, *expr, true)? else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
|
|
|
@ -331,10 +331,8 @@ impl MirLowerCtx<'_> {
|
||||||
break 'b (c, x.1);
|
break 'b (c, x.1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let ResolveValueResult::ValueNs(v, _) = pr {
|
if let ResolveValueResult::ValueNs(ValueNs::ConstId(c), _) = pr {
|
||||||
if let ValueNs::ConstId(c) = v {
|
break 'b (c, Substitution::empty(Interner));
|
||||||
break 'b (c, Substitution::empty(Interner));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
not_supported!("path in pattern position that is not const or variant")
|
not_supported!("path in pattern position that is not const or variant")
|
||||||
};
|
};
|
||||||
|
|
|
@ -796,8 +796,7 @@ fn classify_name_ref(
|
||||||
ast::AssocTypeArg(arg) => {
|
ast::AssocTypeArg(arg) => {
|
||||||
let trait_ = ast::PathSegment::cast(arg.syntax().parent()?.parent()?)?;
|
let trait_ = ast::PathSegment::cast(arg.syntax().parent()?.parent()?)?;
|
||||||
match sema.resolve_path(&trait_.parent_path().top_path())? {
|
match sema.resolve_path(&trait_.parent_path().top_path())? {
|
||||||
hir::PathResolution::Def(def) => match def {
|
hir::PathResolution::Def(hir::ModuleDef::Trait(trait_)) => {
|
||||||
hir::ModuleDef::Trait(trait_) => {
|
|
||||||
let arg_name = arg.name_ref()?;
|
let arg_name = arg.name_ref()?;
|
||||||
let arg_name = arg_name.text();
|
let arg_name = arg_name.text();
|
||||||
let trait_items = trait_.items_with_supertraits(sema.db);
|
let trait_items = trait_.items_with_supertraits(sema.db);
|
||||||
|
@ -810,8 +809,6 @@ fn classify_name_ref(
|
||||||
})?;
|
})?;
|
||||||
sema.source(*assoc_ty)?.value.generic_param_list()
|
sema.source(*assoc_ty)?.value.generic_param_list()
|
||||||
}
|
}
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue