Deduplicate check_expr in builtin calls with error
This commit is contained in:
parent
e5e4eef02d
commit
e5b278b702
3 changed files with 61 additions and 1 deletions
|
@ -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.
|
||||
|
|
13
src/test/ui/suggestions/fn-to-method-deeply-nested.rs
Normal file
13
src/test/ui/suggestions/fn-to-method-deeply-nested.rs
Normal 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
|
||||
)))))
|
||||
}
|
39
src/test/ui/suggestions/fn-to-method-deeply-nested.stderr
Normal file
39
src/test/ui/suggestions/fn-to-method-deeply-nested.stderr
Normal 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`.
|
Loading…
Add table
Reference in a new issue