Deduplicate check_expr in builtin calls with error

This commit is contained in:
Michael Goulet 2022-12-05 01:42:22 +00:00
parent e5e4eef02d
commit e5b278b702
3 changed files with 61 additions and 1 deletions

View file

@ -399,6 +399,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
ty::FnPtr(sig) => (sig, None),
_ => {
let mut skip_first_expr = false;
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &callee_expr.kind
&& let [segment] = path.segments
&& let Some(mut diag) = self
@ -421,11 +422,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return ty;
} else {
diag.emit();
skip_first_expr = true;
}
}
let err = self.report_invalid_callee(call_expr, callee_expr, callee_ty, arg_exprs);
for arg in arg_exprs.iter().skip(skip_first_expr as usize) {
self.check_expr(arg);
}
return self.tcx.ty_error_with_guaranteed(err);
}
};
@ -486,7 +492,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected: Expectation<'tcx>,
) -> Option<Ty<'tcx>> {
if let [callee_expr, rest @ ..] = arg_exprs {
let callee_ty = self.check_expr(callee_expr);
// This may happen recursively -- if so, avoid repeatedly checking the expr.
let callee_ty = self.typeck_results.borrow().expr_ty_adjusted_opt(callee_expr);
let callee_ty = callee_ty.unwrap_or_else(|| self.check_expr(callee_expr));
// First, do a probe with `IsSuggestion(true)` to avoid emitting
// any strange errors. If it's successful, then we'll do a true
// method lookup.

View file

@ -0,0 +1,13 @@
fn main() -> Result<(), ()> {
a(b(c(d(e(
//~^ ERROR cannot find function `a` in this scope
//~| ERROR cannot find function `b` in this scope
//~| ERROR cannot find function `c` in this scope
//~| ERROR cannot find function `d` in this scope
//~| ERROR cannot find function `e` in this scope
z????????????????????????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????
//~^^^ ERROR cannot find value `z` in this scope
)))))
}

View file

@ -0,0 +1,39 @@
error[E0425]: cannot find value `z` in this scope
--> $DIR/fn-to-method-deeply-nested.rs:8:9
|
LL | z????????????????????????????????????????????????????????????????????????????????????????
| ^ not found in this scope
error[E0425]: cannot find function `e` in this scope
--> $DIR/fn-to-method-deeply-nested.rs:2:13
|
LL | a(b(c(d(e(
| ^ not found in this scope
error[E0425]: cannot find function `d` in this scope
--> $DIR/fn-to-method-deeply-nested.rs:2:11
|
LL | a(b(c(d(e(
| ^ not found in this scope
error[E0425]: cannot find function `c` in this scope
--> $DIR/fn-to-method-deeply-nested.rs:2:9
|
LL | a(b(c(d(e(
| ^ not found in this scope
error[E0425]: cannot find function `b` in this scope
--> $DIR/fn-to-method-deeply-nested.rs:2:7
|
LL | a(b(c(d(e(
| ^ not found in this scope
error[E0425]: cannot find function `a` in this scope
--> $DIR/fn-to-method-deeply-nested.rs:2:5
|
LL | a(b(c(d(e(
| ^ not found in this scope
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0425`.