Refactor confirm_builtin_call, remove partial if
Pass callee expr to `confirm_builtin_call`. This removes a partial pattern match in `confirm_builtin_call` and the `panic` in the `else` branch. The diff is large because of indentation changes caused by removing the if-let.
This commit is contained in:
parent
6f7673d077
commit
c8a0e8d61b
1 changed files with 103 additions and 102 deletions
|
@ -77,11 +77,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let output = match result {
|
let output = match result {
|
||||||
None => {
|
None => {
|
||||||
// this will report an error since original_callee_ty is not a fn
|
// this will report an error since original_callee_ty is not a fn
|
||||||
self.confirm_builtin_call(call_expr, original_callee_ty, arg_exprs, expected)
|
self.confirm_builtin_call(
|
||||||
|
call_expr,
|
||||||
|
callee_expr,
|
||||||
|
original_callee_ty,
|
||||||
|
arg_exprs,
|
||||||
|
expected,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(CallStep::Builtin(callee_ty)) => {
|
Some(CallStep::Builtin(callee_ty)) => {
|
||||||
self.confirm_builtin_call(call_expr, callee_ty, arg_exprs, expected)
|
self.confirm_builtin_call(call_expr, callee_expr, callee_ty, arg_exprs, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(CallStep::DeferredClosure(fn_sig)) => {
|
Some(CallStep::DeferredClosure(fn_sig)) => {
|
||||||
|
@ -281,6 +287,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
fn confirm_builtin_call(
|
fn confirm_builtin_call(
|
||||||
&self,
|
&self,
|
||||||
call_expr: &'tcx hir::Expr<'tcx>,
|
call_expr: &'tcx hir::Expr<'tcx>,
|
||||||
|
callee_expr: &'tcx hir::Expr<'tcx>,
|
||||||
callee_ty: Ty<'tcx>,
|
callee_ty: Ty<'tcx>,
|
||||||
arg_exprs: &'tcx [hir::Expr<'tcx>],
|
arg_exprs: &'tcx [hir::Expr<'tcx>],
|
||||||
expected: Expectation<'tcx>,
|
expected: Expectation<'tcx>,
|
||||||
|
@ -299,10 +306,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let hir::ExprKind::Call(callee, _) = call_expr.kind {
|
|
||||||
let mut err = type_error_struct!(
|
let mut err = type_error_struct!(
|
||||||
self.tcx.sess,
|
self.tcx.sess,
|
||||||
callee.span,
|
callee_expr.span,
|
||||||
callee_ty,
|
callee_ty,
|
||||||
E0618,
|
E0618,
|
||||||
"expected function, found {}",
|
"expected function, found {}",
|
||||||
|
@ -315,8 +321,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.identify_bad_closure_def_and_call(
|
self.identify_bad_closure_def_and_call(
|
||||||
&mut err,
|
&mut err,
|
||||||
call_expr.hir_id,
|
call_expr.hir_id,
|
||||||
&callee.kind,
|
&callee_expr.kind,
|
||||||
callee.span,
|
callee_expr.span,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(ref path) = unit_variant {
|
if let Some(ref path) = unit_variant {
|
||||||
|
@ -333,9 +339,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut inner_callee_path = None;
|
let mut inner_callee_path = None;
|
||||||
let def = match callee.kind {
|
let def = match callee_expr.kind {
|
||||||
hir::ExprKind::Path(ref qpath) => {
|
hir::ExprKind::Path(ref qpath) => {
|
||||||
self.typeck_results.borrow().qpath_res(qpath, callee.hir_id)
|
self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
|
||||||
}
|
}
|
||||||
hir::ExprKind::Call(ref inner_callee, _) => {
|
hir::ExprKind::Call(ref inner_callee, _) => {
|
||||||
// If the call spans more than one line and the callee kind is
|
// If the call spans more than one line and the callee kind is
|
||||||
|
@ -345,7 +351,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.tcx.sess.source_map().is_multiline(call_expr.span);
|
self.tcx.sess.source_map().is_multiline(call_expr.span);
|
||||||
if call_is_multiline {
|
if call_is_multiline {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
callee.span.shrink_to_hi(),
|
callee_expr.span.shrink_to_hi(),
|
||||||
"consider using a semicolon here",
|
"consider using a semicolon here",
|
||||||
";".to_owned(),
|
";".to_owned(),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
|
@ -353,9 +359,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
if let hir::ExprKind::Path(ref inner_qpath) = inner_callee.kind {
|
if let hir::ExprKind::Path(ref inner_qpath) = inner_callee.kind {
|
||||||
inner_callee_path = Some(inner_qpath);
|
inner_callee_path = Some(inner_qpath);
|
||||||
self.typeck_results
|
self.typeck_results.borrow().qpath_res(inner_qpath, inner_callee.hir_id)
|
||||||
.borrow()
|
|
||||||
.qpath_res(inner_qpath, inner_callee.hir_id)
|
|
||||||
} else {
|
} else {
|
||||||
Res::Err
|
Res::Err
|
||||||
}
|
}
|
||||||
|
@ -369,11 +373,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let callee_ty = callee_ty.to_string();
|
let callee_ty = callee_ty.to_string();
|
||||||
let label = match (unit_variant, inner_callee_path) {
|
let label = match (unit_variant, inner_callee_path) {
|
||||||
(Some(path), _) => Some(format!("`{}` defined here", path)),
|
(Some(path), _) => Some(format!("`{}` defined here", path)),
|
||||||
(_, Some(hir::QPath::Resolved(_, path))) => {
|
(_, Some(hir::QPath::Resolved(_, path))) => self
|
||||||
self.tcx.sess.source_map().span_to_snippet(path.span).ok().map(
|
.tcx
|
||||||
|p| format!("`{}` defined here returns `{}`", p, callee_ty),
|
.sess
|
||||||
)
|
.source_map()
|
||||||
}
|
.span_to_snippet(path.span)
|
||||||
|
.ok()
|
||||||
|
.map(|p| format!("`{}` defined here returns `{}`", p, callee_ty)),
|
||||||
_ => {
|
_ => {
|
||||||
match def {
|
match def {
|
||||||
// Emit a different diagnostic for local variables, as they are not
|
// Emit a different diagnostic for local variables, as they are not
|
||||||
|
@ -383,9 +389,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.tcx.hir().name(hir_id),
|
self.tcx.hir().name(hir_id),
|
||||||
callee_ty
|
callee_ty
|
||||||
)),
|
)),
|
||||||
Res::Def(kind, def_id)
|
Res::Def(kind, def_id) if kind.ns() == Some(Namespace::ValueNS) => {
|
||||||
if kind.ns() == Some(Namespace::ValueNS) =>
|
|
||||||
{
|
|
||||||
Some(format!(
|
Some(format!(
|
||||||
"`{}` defined here",
|
"`{}` defined here",
|
||||||
self.tcx.def_path_str(def_id),
|
self.tcx.def_path_str(def_id),
|
||||||
|
@ -400,9 +404,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err.emit();
|
err.emit();
|
||||||
} else {
|
|
||||||
bug!("call_expr.kind should be an ExprKind::Call, got {:?}", call_expr.kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is the "default" function signature, used in case of error.
|
// This is the "default" function signature, used in case of error.
|
||||||
// In that case, we check each argument against "error" in order to
|
// In that case, we check each argument against "error" in order to
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue