Skip to content

Commit de99a87

Browse files
authored
Rollup merge of rust-lang#106055 - compiler-errors:too-many-calls, r=estebank
Check arg expressions properly on error in `confirm_builtin_call` Makes sure we don't regress diagnostic output when we have an expr error nested inside of a bad fn call: rust-lang#105973 (comment) Fixes rust-lang#106030 Fixes rust-lang#105244
2 parents 9192874 + 69abe44 commit de99a87

7 files changed

+101
-1
lines changed

compiler/rustc_hir_typeck/src/callee.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
399399
}
400400
ty::FnPtr(sig) => (sig, None),
401401
_ => {
402+
for arg in arg_exprs {
403+
self.check_expr(arg);
404+
}
405+
402406
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &callee_expr.kind
403407
&& let [segment] = path.segments
404408
&& let Some(mut diag) = self
@@ -486,7 +490,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
486490
expected: Expectation<'tcx>,
487491
) -> Option<Ty<'tcx>> {
488492
if let [callee_expr, rest @ ..] = arg_exprs {
489-
let callee_ty = self.check_expr(callee_expr);
493+
let callee_ty = self.typeck_results.borrow().expr_ty_adjusted_opt(callee_expr)?;
494+
490495
// First, do a probe with `IsSuggestion(true)` to avoid emitting
491496
// any strange errors. If it's successful, then we'll do a true
492497
// method lookup.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn main() -> Result<(), ()> {
2+
a(b(c(d(e(
3+
//~^ ERROR cannot find function `a` in this scope
4+
//~| ERROR cannot find function `b` in this scope
5+
//~| ERROR cannot find function `c` in this scope
6+
//~| ERROR cannot find function `d` in this scope
7+
//~| ERROR cannot find function `e` in this scope
8+
z????????????????????????????????????????????????????????????????????????????????????????
9+
?????????????????????????????????????????????????????????????????????????????????????????
10+
??????????????????????????????????????????????????????????????????
11+
//~^^^ ERROR cannot find value `z` in this scope
12+
)))))
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0425]: cannot find value `z` in this scope
2+
--> $DIR/fn-to-method-deeply-nested.rs:8:9
3+
|
4+
LL | z????????????????????????????????????????????????????????????????????????????????????????
5+
| ^ not found in this scope
6+
7+
error[E0425]: cannot find function `e` in this scope
8+
--> $DIR/fn-to-method-deeply-nested.rs:2:13
9+
|
10+
LL | a(b(c(d(e(
11+
| ^ not found in this scope
12+
13+
error[E0425]: cannot find function `d` in this scope
14+
--> $DIR/fn-to-method-deeply-nested.rs:2:11
15+
|
16+
LL | a(b(c(d(e(
17+
| ^ not found in this scope
18+
19+
error[E0425]: cannot find function `c` in this scope
20+
--> $DIR/fn-to-method-deeply-nested.rs:2:9
21+
|
22+
LL | a(b(c(d(e(
23+
| ^ not found in this scope
24+
25+
error[E0425]: cannot find function `b` in this scope
26+
--> $DIR/fn-to-method-deeply-nested.rs:2:7
27+
|
28+
LL | a(b(c(d(e(
29+
| ^ not found in this scope
30+
31+
error[E0425]: cannot find function `a` in this scope
32+
--> $DIR/fn-to-method-deeply-nested.rs:2:5
33+
|
34+
LL | a(b(c(d(e(
35+
| ^ not found in this scope
36+
37+
error: aborting due to 6 previous errors
38+
39+
For more information about this error, try `rustc --explain E0425`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
a((), 1i32 == 2u32);
3+
//~^ ERROR cannot find function `a` in this scope
4+
//~| ERROR mismatched types
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/check-args-on-fn-err-2.rs:2:19
3+
|
4+
LL | a((), 1i32 == 2u32);
5+
| ---- ^^^^ expected `i32`, found `u32`
6+
| |
7+
| expected because this is `i32`
8+
|
9+
help: change the type of the numeric literal from `u32` to `i32`
10+
|
11+
LL | a((), 1i32 == 2i32);
12+
| ~~~
13+
14+
error[E0425]: cannot find function `a` in this scope
15+
--> $DIR/check-args-on-fn-err-2.rs:2:5
16+
|
17+
LL | a((), 1i32 == 2u32);
18+
| ^ not found in this scope
19+
20+
error: aborting due to 2 previous errors
21+
22+
Some errors have detailed explanations: E0308, E0425.
23+
For more information about an error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
unknown(1, |glyf| {
3+
//~^ ERROR: cannot find function `unknown` in this scope
4+
let actual = glyf;
5+
});
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find function `unknown` in this scope
2+
--> $DIR/check-args-on-fn-err.rs:2:5
3+
|
4+
LL | unknown(1, |glyf| {
5+
| ^^^^^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)