collapsible_match

This commit is contained in:
Johann Hemmann 2024-01-19 13:36:56 +01:00
parent 657376858f
commit 4184c6af0d
6 changed files with 50 additions and 65 deletions

View file

@ -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"

View file

@ -334,14 +334,12 @@ 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: _ } => {
let mut place = self.place_of_expr(*expr)?; let mut place = self.place_of_expr(*expr)?;
let field = self.result.field_resolution(tgt_expr)?; let field = self.result.field_resolution(tgt_expr)?;

View file

@ -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);

View file

@ -160,8 +160,7 @@ 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, _) => {
@ -174,8 +173,7 @@ impl MirLowerCtx<'_> {
_ => false, _ => false,
}; };
if !is_builtin { if !is_builtin {
let Some((p, current)) = self.lower_expr_as_place(current, *expr, true)? let Some((p, current)) = self.lower_expr_as_place(current, *expr, true)? else {
else {
return Ok(None); return Ok(None);
}; };
return self.lower_overloaded_deref( return self.lower_overloaded_deref(
@ -202,15 +200,13 @@ impl MirLowerCtx<'_> {
}, },
); );
} }
let Some((mut r, current)) = self.lower_expr_as_place(current, *expr, true)? let Some((mut r, current)) = self.lower_expr_as_place(current, *expr, true)? else {
else {
return Ok(None); return Ok(None);
}; };
r = r.project(ProjectionElem::Deref, &mut self.result.projection_store); r = r.project(ProjectionElem::Deref, &mut self.result.projection_store);
Ok(Some((r, current))) Ok(Some((r, current)))
} }
_ => try_rvalue(self), 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);

View file

@ -331,11 +331,9 @@ 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")
}; };
let tmp: Place = let tmp: Place =

View file

@ -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);
@ -811,8 +810,6 @@ fn classify_name_ref(
sema.source(*assoc_ty)?.value.generic_param_list() sema.source(*assoc_ty)?.value.generic_param_list()
} }
_ => None, _ => None,
},
_ => None,
} }
}, },
_ => None, _ => None,