Skip to content

Commit

Permalink
Rollup merge of rust-lang#106055 - compiler-errors:too-many-calls, r=…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Noratrieb committed Dec 23, 2022
2 parents caded18 + 69abe44 commit f6d8ba2
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
ty::FnPtr(sig) => (sig, None),
_ => {
for arg in arg_exprs {
self.check_expr(arg);
}

if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &callee_expr.kind
&& let [segment] = path.segments
&& let Some(mut diag) = self
Expand Down Expand Up @@ -486,7 +490,8 @@ 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);
let callee_ty = self.typeck_results.borrow().expr_ty_adjusted_opt(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.
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/suggestions/fn-to-method-deeply-nested.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 39 additions & 0 deletions src/test/ui/suggestions/fn-to-method-deeply-nested.stderr
Original file line number Diff line number Diff line change
@@ -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`.
5 changes: 5 additions & 0 deletions src/test/ui/typeck/check-args-on-fn-err-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
a((), 1i32 == 2u32);
//~^ ERROR cannot find function `a` in this scope
//~| ERROR mismatched types
}
23 changes: 23 additions & 0 deletions src/test/ui/typeck/check-args-on-fn-err-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0308]: mismatched types
--> $DIR/check-args-on-fn-err-2.rs:2:19
|
LL | a((), 1i32 == 2u32);
| ---- ^^^^ expected `i32`, found `u32`
| |
| expected because this is `i32`
|
help: change the type of the numeric literal from `u32` to `i32`
|
LL | a((), 1i32 == 2i32);
| ~~~

error[E0425]: cannot find function `a` in this scope
--> $DIR/check-args-on-fn-err-2.rs:2:5
|
LL | a((), 1i32 == 2u32);
| ^ not found in this scope

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.
6 changes: 6 additions & 0 deletions src/test/ui/typeck/check-args-on-fn-err.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
unknown(1, |glyf| {
//~^ ERROR: cannot find function `unknown` in this scope
let actual = glyf;
});
}
9 changes: 9 additions & 0 deletions src/test/ui/typeck/check-args-on-fn-err.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0425]: cannot find function `unknown` in this scope
--> $DIR/check-args-on-fn-err.rs:2:5
|
LL | unknown(1, |glyf| {
| ^^^^^^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.

0 comments on commit f6d8ba2

Please sign in to comment.