mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
collapse some nested blocks
This commit is contained in:
parent
95fc3ba41c
commit
d218b237fd
@ -1136,8 +1136,7 @@ impl<'a> InferenceContext<'a> {
|
|||||||
if self.diverges.is_always() {
|
if self.diverges.is_always() {
|
||||||
// we don't even make an attempt at coercion
|
// we don't even make an attempt at coercion
|
||||||
self.table.new_maybe_never_var()
|
self.table.new_maybe_never_var()
|
||||||
} else {
|
} else if let Some(t) = expected.only_has_type(&mut self.table) {
|
||||||
if let Some(t) = expected.only_has_type(&mut self.table) {
|
|
||||||
if self.coerce(Some(expr), &TyBuilder::unit(), &t).is_err() {
|
if self.coerce(Some(expr), &TyBuilder::unit(), &t).is_err() {
|
||||||
self.result.type_mismatches.insert(
|
self.result.type_mismatches.insert(
|
||||||
expr.into(),
|
expr.into(),
|
||||||
@ -1150,7 +1149,6 @@ impl<'a> InferenceContext<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn infer_method_call(
|
fn infer_method_call(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -1314,8 +1312,9 @@ impl<'a> InferenceContext<'a> {
|
|||||||
} else {
|
} else {
|
||||||
param_ty
|
param_ty
|
||||||
};
|
};
|
||||||
if !coercion_target.is_unknown() {
|
if !coercion_target.is_unknown()
|
||||||
if self.coerce(Some(arg), &ty, &coercion_target).is_err() {
|
&& self.coerce(Some(arg), &ty, &coercion_target).is_err()
|
||||||
|
{
|
||||||
self.result.type_mismatches.insert(
|
self.result.type_mismatches.insert(
|
||||||
arg.into(),
|
arg.into(),
|
||||||
TypeMismatch { expected: coercion_target, actual: ty.clone() },
|
TypeMismatch { expected: coercion_target, actual: ty.clone() },
|
||||||
@ -1324,7 +1323,6 @@ impl<'a> InferenceContext<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn substs_for_method_call(
|
fn substs_for_method_call(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -251,18 +251,15 @@ fn layout_of_unit(cx: &LayoutCx<'_>, dl: &TargetDataLayout) -> Result<Layout, La
|
|||||||
|
|
||||||
fn struct_tail_erasing_lifetimes(db: &dyn HirDatabase, pointee: Ty) -> Ty {
|
fn struct_tail_erasing_lifetimes(db: &dyn HirDatabase, pointee: Ty) -> Ty {
|
||||||
match pointee.kind(Interner) {
|
match pointee.kind(Interner) {
|
||||||
TyKind::Adt(AdtId(adt), subst) => match adt {
|
TyKind::Adt(AdtId(hir_def::AdtId::StructId(i)), subst) => {
|
||||||
&hir_def::AdtId::StructId(i) => {
|
let data = db.struct_data(*i);
|
||||||
let data = db.struct_data(i);
|
|
||||||
let mut it = data.variant_data.fields().iter().rev();
|
let mut it = data.variant_data.fields().iter().rev();
|
||||||
match it.next() {
|
match it.next() {
|
||||||
Some((f, _)) => field_ty(db, i.into(), f, subst),
|
Some((f, _)) => field_ty(db, (*i).into(), f, subst),
|
||||||
None => pointee,
|
None => pointee,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => pointee,
|
_ => pointee,
|
||||||
},
|
|
||||||
_ => pointee,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,8 +161,7 @@ fn collect_used_generics<'gp>(
|
|||||||
.and_then(|lt| known_generics.iter().find(find_lifetime(<.text()))),
|
.and_then(|lt| known_generics.iter().find(find_lifetime(<.text()))),
|
||||||
),
|
),
|
||||||
ast::Type::ArrayType(ar) => {
|
ast::Type::ArrayType(ar) => {
|
||||||
if let Some(expr) = ar.expr() {
|
if let Some(ast::Expr::PathExpr(p)) = ar.expr() {
|
||||||
if let ast::Expr::PathExpr(p) = expr {
|
|
||||||
if let Some(path) = p.path() {
|
if let Some(path) = p.path() {
|
||||||
if let Some(name_ref) = path.as_single_name_ref() {
|
if let Some(name_ref) = path.as_single_name_ref() {
|
||||||
if let Some(param) = known_generics.iter().find(|gp| {
|
if let Some(param) = known_generics.iter().find(|gp| {
|
||||||
@ -178,7 +177,6 @@ fn collect_used_generics<'gp>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_ => (),
|
_ => (),
|
||||||
};
|
};
|
||||||
false
|
false
|
||||||
|
@ -389,8 +389,7 @@ fn source_edit_from_name_ref(
|
|||||||
edit.delete(TextRange::new(s, e));
|
edit.delete(TextRange::new(s, e));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if init == name_ref {
|
} else if init == name_ref && field_name.text() == new_name {
|
||||||
if field_name.text() == new_name {
|
|
||||||
cov_mark::hit!(test_rename_local_put_init_shorthand);
|
cov_mark::hit!(test_rename_local_put_init_shorthand);
|
||||||
// Foo { field: local } -> Foo { field }
|
// Foo { field: local } -> Foo { field }
|
||||||
// ^^^^^^^ delete this
|
// ^^^^^^^ delete this
|
||||||
@ -403,7 +402,6 @@ fn source_edit_from_name_ref(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// init shorthand
|
// init shorthand
|
||||||
(None, Some(_)) if matches!(def, Definition::Field(_)) => {
|
(None, Some(_)) if matches!(def, Definition::Field(_)) => {
|
||||||
cov_mark::hit!(test_rename_field_in_field_shorthand);
|
cov_mark::hit!(test_rename_field_in_field_shorthand);
|
||||||
|
@ -323,11 +323,11 @@ impl Query {
|
|||||||
if symbol.name != self.query {
|
if symbol.name != self.query {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if self.case_sensitive {
|
} else if self.case_sensitive
|
||||||
if self.query.chars().any(|c| !symbol.name.contains(c)) {
|
&& self.query.chars().any(|c| !symbol.name.contains(c))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
res.push(symbol.clone());
|
res.push(symbol.clone());
|
||||||
if res.len() >= self.limit {
|
if res.len() >= self.limit {
|
||||||
|
@ -64,12 +64,10 @@ pub(super) fn type_info(
|
|||||||
bt_end = if config.markdown() { "```\n" } else { "" }
|
bt_end = if config.markdown() { "```\n" } else { "" }
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
} else {
|
} else if config.markdown() {
|
||||||
if config.markdown() {
|
|
||||||
Markup::fenced_block(&original.display(sema.db))
|
Markup::fenced_block(&original.display(sema.db))
|
||||||
} else {
|
} else {
|
||||||
original.display(sema.db).to_string().into()
|
original.display(sema.db).to_string().into()
|
||||||
}
|
|
||||||
};
|
};
|
||||||
res.actions.push(HoverAction::goto_type_from_targets(sema.db, targets));
|
res.actions.push(HoverAction::goto_type_from_targets(sema.db, targets));
|
||||||
Some(res)
|
Some(res)
|
||||||
|
@ -161,11 +161,9 @@ fn remove_newline(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.join_assignments {
|
if config.join_assignments && join_assignments(edit, &prev, &next).is_some() {
|
||||||
if join_assignments(edit, &prev, &next).is_some() {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if config.unwrap_trivial_blocks {
|
if config.unwrap_trivial_blocks {
|
||||||
// Special case that turns something like:
|
// Special case that turns something like:
|
||||||
|
@ -413,12 +413,11 @@ fn traverse(
|
|||||||
let string = ast::String::cast(token);
|
let string = ast::String::cast(token);
|
||||||
let string_to_highlight = ast::String::cast(descended_token.clone());
|
let string_to_highlight = ast::String::cast(descended_token.clone());
|
||||||
if let Some((string, expanded_string)) = string.zip(string_to_highlight) {
|
if let Some((string, expanded_string)) = string.zip(string_to_highlight) {
|
||||||
if string.is_raw() {
|
if string.is_raw()
|
||||||
if inject::ra_fixture(hl, sema, config, &string, &expanded_string).is_some()
|
&& inject::ra_fixture(hl, sema, config, &string, &expanded_string).is_some()
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
highlight_format_string(hl, &string, &expanded_string, range);
|
highlight_format_string(hl, &string, &expanded_string, range);
|
||||||
highlight_escape_string(hl, &string, range.start());
|
highlight_escape_string(hl, &string, range.start());
|
||||||
}
|
}
|
||||||
|
@ -205,11 +205,9 @@ fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
|
|||||||
if expr_stmt.semicolon_token().is_some() {
|
if expr_stmt.semicolon_token().is_some() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
} else {
|
} else if !ast::StmtList::can_cast(binop.syntax().parent()?.kind()) {
|
||||||
if !ast::StmtList::can_cast(binop.syntax().parent()?.kind()) {
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let expr = binop.rhs()?;
|
let expr = binop.rhs()?;
|
||||||
let expr_range = expr.syntax().text_range();
|
let expr_range = expr.syntax().text_range();
|
||||||
|
@ -307,12 +307,12 @@ impl GlobalState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !was_quiescent || state_changed || memdocs_added_or_removed {
|
if (!was_quiescent || state_changed || memdocs_added_or_removed)
|
||||||
if self.config.publish_diagnostics() {
|
&& self.config.publish_diagnostics()
|
||||||
|
{
|
||||||
self.update_diagnostics()
|
self.update_diagnostics()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(diagnostic_changes) = self.diagnostics.take_changes() {
|
if let Some(diagnostic_changes) = self.diagnostics.take_changes() {
|
||||||
for file_id in diagnostic_changes {
|
for file_id in diagnostic_changes {
|
||||||
|
Loading…
Reference in New Issue
Block a user