Skip to content

Commit bd40a05

Browse files
committed
Remove visitor use
1 parent 6add192 commit bd40a05

File tree

1 file changed

+20
-41
lines changed

1 file changed

+20
-41
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+20-41
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::FnCtxt;
22

3-
use crate::coercion::CollectRetsVisitor;
43
use crate::errors;
54
use crate::fluent_generated as fluent;
65
use crate::fn_ctxt::rustc_span::BytePos;
@@ -17,7 +16,6 @@ use rustc_errors::{Applicability, Diagnostic, MultiSpan};
1716
use rustc_hir as hir;
1817
use rustc_hir::def::Res;
1918
use rustc_hir::def::{CtorKind, CtorOf, DefKind};
20-
use rustc_hir::intravisit::{Map, Visitor};
2119
use rustc_hir::lang_items::LangItem;
2220
use rustc_hir::{
2321
CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, GenericBound, HirId, Node,
@@ -1040,22 +1038,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10401038
return;
10411039
}
10421040

1043-
let in_closure = matches!(
1044-
self.tcx
1045-
.hir()
1046-
.parent_iter(id)
1047-
.filter(|(_, node)| {
1048-
matches!(
1049-
node,
1050-
Node::Expr(Expr { kind: ExprKind::Closure(..), .. })
1051-
| Node::Item(_)
1052-
| Node::TraitItem(_)
1053-
| Node::ImplItem(_)
1054-
)
1055-
})
1056-
.next(),
1057-
Some((_, Node::Expr(Expr { kind: ExprKind::Closure(..), .. })))
1058-
);
1041+
let scope = self
1042+
.tcx
1043+
.hir()
1044+
.parent_iter(id)
1045+
.filter(|(_, node)| {
1046+
matches!(
1047+
node,
1048+
Node::Expr(Expr { kind: ExprKind::Closure(..), .. })
1049+
| Node::Item(_)
1050+
| Node::TraitItem(_)
1051+
| Node::ImplItem(_)
1052+
)
1053+
})
1054+
.next();
1055+
let in_closure =
1056+
matches!(scope, Some((_, Node::Expr(Expr { kind: ExprKind::Closure(..), .. }))));
10591057

10601058
let can_return = match fn_decl.output {
10611059
hir::FnRetTy::Return(ty) => {
@@ -1077,29 +1075,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10771075
self.can_coerce(found, ty)
10781076
}
10791077
hir::FnRetTy::DefaultReturn(_) if in_closure => {
1080-
let mut rets = vec![];
1081-
if let Some(ret_coercion) = self.ret_coercion.as_ref() {
1082-
let ret_ty = ret_coercion.borrow().expected_ty();
1083-
rets.push(ret_ty);
1084-
}
1085-
let mut visitor = CollectRetsVisitor { ret_exprs: vec![] };
1086-
if let Some(item) = self.tcx.hir().find(id)
1087-
&& let Node::Expr(expr) = item
1088-
{
1089-
visitor.visit_expr(expr);
1090-
for expr in visitor.ret_exprs {
1091-
if let Some(ty) = self.typeck_results.borrow().node_type_opt(expr.hir_id) {
1092-
rets.push(ty);
1093-
}
1094-
}
1095-
if let hir::ExprKind::Block(hir::Block { expr: Some(expr), .. }, _) = expr.kind
1096-
{
1097-
if let Some(ty) = self.typeck_results.borrow().node_type_opt(expr.hir_id) {
1098-
rets.push(ty);
1099-
}
1100-
}
1101-
}
1102-
rets.into_iter().all(|ty| self.can_coerce(found, ty))
1078+
self.ret_coercion.as_ref().map_or(false, |ret| {
1079+
let ret_ty = ret.borrow().expected_ty();
1080+
self.can_coerce(found, ret_ty)
1081+
})
11031082
}
11041083
_ => false,
11051084
};

0 commit comments

Comments
 (0)