Skip to content

Commit e650c1d

Browse files
Move the error handling out of confirm_builtin_call
1 parent bd2c653 commit e650c1d

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8787

8888
let output = match result {
8989
None => {
90-
// this will report an error since original_callee_ty is not a fn
91-
self.confirm_builtin_call(
92-
call_expr,
93-
callee_expr,
94-
original_callee_ty,
95-
arg_exprs,
96-
expected,
97-
)
90+
// Check all of the arg expressions, but with no expectations
91+
// since we don't have a signature to compare them to.
92+
for arg in arg_exprs {
93+
self.check_expr(arg);
94+
}
95+
96+
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &callee_expr.kind
97+
&& let [segment] = path.segments
98+
{
99+
self.dcx().try_steal_modify_and_emit_err(
100+
segment.ident.span,
101+
StashKey::CallIntoMethod,
102+
|err| {
103+
// Try suggesting `foo(a)` -> `a.foo()` if possible.
104+
self.suggest_call_as_method(
105+
err, segment, arg_exprs, call_expr, expected,
106+
);
107+
},
108+
);
109+
}
110+
111+
let guar = self.report_invalid_callee(call_expr, callee_expr, expr_ty, arg_exprs);
112+
Ty::new_error(self.tcx, guar)
98113
}
99114

100115
Some(CallStep::Builtin(callee_ty)) => {
@@ -461,32 +476,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
461476
}
462477
(fn_sig, Some(def_id))
463478
}
479+
464480
// FIXME(const_trait_impl): these arms should error because we can't enforce them
465481
ty::FnPtr(sig_tys, hdr) => (sig_tys.with(hdr), None),
466-
_ => {
467-
for arg in arg_exprs {
468-
self.check_expr(arg);
469-
}
470482

471-
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &callee_expr.kind
472-
&& let [segment] = path.segments
473-
{
474-
self.dcx().try_steal_modify_and_emit_err(
475-
segment.ident.span,
476-
StashKey::CallIntoMethod,
477-
|err| {
478-
// Try suggesting `foo(a)` -> `a.foo()` if possible.
479-
self.suggest_call_as_method(
480-
err, segment, arg_exprs, call_expr, expected,
481-
);
482-
},
483-
);
484-
}
485-
486-
let err = self.report_invalid_callee(call_expr, callee_expr, callee_ty, arg_exprs);
487-
488-
return Ty::new_error(self.tcx, err);
489-
}
483+
_ => unreachable!(),
490484
};
491485

492486
// Replace any late-bound regions that appear in the function

0 commit comments

Comments
 (0)