Skip to content

Commit d218b23

Browse files
committed
collapse some nested blocks
1 parent 95fc3ba commit d218b23

File tree

10 files changed

+63
-79
lines changed

10 files changed

+63
-79
lines changed

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

+16-18
Original file line numberDiff line numberDiff line change
@@ -1136,18 +1136,16 @@ impl<'a> InferenceContext<'a> {
11361136
if self.diverges.is_always() {
11371137
// we don't even make an attempt at coercion
11381138
self.table.new_maybe_never_var()
1139-
} else {
1140-
if let Some(t) = expected.only_has_type(&mut self.table) {
1141-
if self.coerce(Some(expr), &TyBuilder::unit(), &t).is_err() {
1142-
self.result.type_mismatches.insert(
1143-
expr.into(),
1144-
TypeMismatch { expected: t.clone(), actual: TyBuilder::unit() },
1145-
);
1146-
}
1147-
t
1148-
} else {
1149-
TyBuilder::unit()
1139+
} else if let Some(t) = expected.only_has_type(&mut self.table) {
1140+
if self.coerce(Some(expr), &TyBuilder::unit(), &t).is_err() {
1141+
self.result.type_mismatches.insert(
1142+
expr.into(),
1143+
TypeMismatch { expected: t.clone(), actual: TyBuilder::unit() },
1144+
);
11501145
}
1146+
t
1147+
} else {
1148+
TyBuilder::unit()
11511149
}
11521150
}
11531151
}
@@ -1314,13 +1312,13 @@ impl<'a> InferenceContext<'a> {
13141312
} else {
13151313
param_ty
13161314
};
1317-
if !coercion_target.is_unknown() {
1318-
if self.coerce(Some(arg), &ty, &coercion_target).is_err() {
1319-
self.result.type_mismatches.insert(
1320-
arg.into(),
1321-
TypeMismatch { expected: coercion_target, actual: ty.clone() },
1322-
);
1323-
}
1315+
if !coercion_target.is_unknown()
1316+
&& self.coerce(Some(arg), &ty, &coercion_target).is_err()
1317+
{
1318+
self.result.type_mismatches.insert(
1319+
arg.into(),
1320+
TypeMismatch { expected: coercion_target, actual: ty.clone() },
1321+
);
13241322
}
13251323
}
13261324
}

crates/hir-ty/src/layout.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,14 @@ fn layout_of_unit(cx: &LayoutCx<'_>, dl: &TargetDataLayout) -> Result<Layout, La
251251

252252
fn struct_tail_erasing_lifetimes(db: &dyn HirDatabase, pointee: Ty) -> Ty {
253253
match pointee.kind(Interner) {
254-
TyKind::Adt(AdtId(adt), subst) => match adt {
255-
&hir_def::AdtId::StructId(i) => {
256-
let data = db.struct_data(i);
257-
let mut it = data.variant_data.fields().iter().rev();
258-
match it.next() {
259-
Some((f, _)) => field_ty(db, i.into(), f, subst),
260-
None => pointee,
261-
}
254+
TyKind::Adt(AdtId(hir_def::AdtId::StructId(i)), subst) => {
255+
let data = db.struct_data(*i);
256+
let mut it = data.variant_data.fields().iter().rev();
257+
match it.next() {
258+
Some((f, _)) => field_ty(db, (*i).into(), f, subst),
259+
None => pointee,
262260
}
263-
_ => pointee,
264-
},
261+
}
265262
_ => pointee,
266263
}
267264
}

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

+10-12
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,17 @@ fn collect_used_generics<'gp>(
161161
.and_then(|lt| known_generics.iter().find(find_lifetime(&lt.text()))),
162162
),
163163
ast::Type::ArrayType(ar) => {
164-
if let Some(expr) = ar.expr() {
165-
if let ast::Expr::PathExpr(p) = expr {
166-
if let Some(path) = p.path() {
167-
if let Some(name_ref) = path.as_single_name_ref() {
168-
if let Some(param) = known_generics.iter().find(|gp| {
169-
if let ast::GenericParam::ConstParam(cp) = gp {
170-
cp.name().map_or(false, |n| n.text() == name_ref.text())
171-
} else {
172-
false
173-
}
174-
}) {
175-
generics.push(param);
164+
if let Some(ast::Expr::PathExpr(p)) = ar.expr() {
165+
if let Some(path) = p.path() {
166+
if let Some(name_ref) = path.as_single_name_ref() {
167+
if let Some(param) = known_generics.iter().find(|gp| {
168+
if let ast::GenericParam::ConstParam(cp) = gp {
169+
cp.name().map_or(false, |n| n.text() == name_ref.text())
170+
} else {
171+
false
176172
}
173+
}) {
174+
generics.push(param);
177175
}
178176
}
179177
}

crates/ide-db/src/rename.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -389,19 +389,17 @@ fn source_edit_from_name_ref(
389389
edit.delete(TextRange::new(s, e));
390390
return true;
391391
}
392-
} else if init == name_ref {
393-
if field_name.text() == new_name {
394-
cov_mark::hit!(test_rename_local_put_init_shorthand);
395-
// Foo { field: local } -> Foo { field }
396-
// ^^^^^^^ delete this
397-
398-
// same names, we can use a shorthand here instead.
399-
// we do not want to erase attributes hence this range start
400-
let s = field_name.syntax().text_range().end();
401-
let e = init.syntax().text_range().end();
402-
edit.delete(TextRange::new(s, e));
403-
return true;
404-
}
392+
} else if init == name_ref && field_name.text() == new_name {
393+
cov_mark::hit!(test_rename_local_put_init_shorthand);
394+
// Foo { field: local } -> Foo { field }
395+
// ^^^^^^^ delete this
396+
397+
// same names, we can use a shorthand here instead.
398+
// we do not want to erase attributes hence this range start
399+
let s = field_name.syntax().text_range().end();
400+
let e = init.syntax().text_range().end();
401+
edit.delete(TextRange::new(s, e));
402+
return true;
405403
}
406404
}
407405
// init shorthand

crates/ide-db/src/symbol_index.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ impl Query {
323323
if symbol.name != self.query {
324324
continue;
325325
}
326-
} else if self.case_sensitive {
327-
if self.query.chars().any(|c| !symbol.name.contains(c)) {
328-
continue;
329-
}
326+
} else if self.case_sensitive
327+
&& self.query.chars().any(|c| !symbol.name.contains(c))
328+
{
329+
continue;
330330
}
331331

332332
res.push(symbol.clone());

crates/ide/src/hover/render.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ pub(super) fn type_info(
6464
bt_end = if config.markdown() { "```\n" } else { "" }
6565
)
6666
.into()
67+
} else if config.markdown() {
68+
Markup::fenced_block(&original.display(sema.db))
6769
} else {
68-
if config.markdown() {
69-
Markup::fenced_block(&original.display(sema.db))
70-
} else {
71-
original.display(sema.db).to_string().into()
72-
}
70+
original.display(sema.db).to_string().into()
7371
};
7472
res.actions.push(HoverAction::goto_type_from_targets(sema.db, targets));
7573
Some(res)

crates/ide/src/join_lines.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,8 @@ fn remove_newline(
161161
}
162162
}
163163

164-
if config.join_assignments {
165-
if join_assignments(edit, &prev, &next).is_some() {
166-
return;
167-
}
164+
if config.join_assignments && join_assignments(edit, &prev, &next).is_some() {
165+
return;
168166
}
169167

170168
if config.unwrap_trivial_blocks {

crates/ide/src/syntax_highlighting.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,10 @@ fn traverse(
413413
let string = ast::String::cast(token);
414414
let string_to_highlight = ast::String::cast(descended_token.clone());
415415
if let Some((string, expanded_string)) = string.zip(string_to_highlight) {
416-
if string.is_raw() {
417-
if inject::ra_fixture(hl, sema, config, &string, &expanded_string).is_some()
418-
{
419-
continue;
420-
}
416+
if string.is_raw()
417+
&& inject::ra_fixture(hl, sema, config, &string, &expanded_string).is_some()
418+
{
419+
continue;
421420
}
422421
highlight_format_string(hl, &string, &expanded_string, range);
423422
highlight_escape_string(hl, &string, range.start());

crates/ide/src/typing.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,8 @@ fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
205205
if expr_stmt.semicolon_token().is_some() {
206206
return None;
207207
}
208-
} else {
209-
if !ast::StmtList::can_cast(binop.syntax().parent()?.kind()) {
210-
return None;
211-
}
208+
} else if !ast::StmtList::can_cast(binop.syntax().parent()?.kind()) {
209+
return None;
212210
}
213211

214212
let expr = binop.rhs()?;

crates/rust-analyzer/src/main_loop.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ impl GlobalState {
307307
}
308308
}
309309

310-
if !was_quiescent || state_changed || memdocs_added_or_removed {
311-
if self.config.publish_diagnostics() {
312-
self.update_diagnostics()
313-
}
310+
if (!was_quiescent || state_changed || memdocs_added_or_removed)
311+
&& self.config.publish_diagnostics()
312+
{
313+
self.update_diagnostics()
314314
}
315315
}
316316

0 commit comments

Comments
 (0)