about summary refs log tree commit diff
diff options
context:
space:
mode:
authornils <48135649+Nilstrieb@users.noreply.github.com>2022-12-23 18:02:15 +0100
committerGitHub <noreply@github.com>2022-12-23 18:02:15 +0100
commitde99a879269fa59c496e817eb7918ea405aebd08 (patch)
tree96025ba628bcac770e9f603ff90dc72256562bec
parent9192874b29b2f5738f254d8080f42b2632c920e5 (diff)
parent69abe4458e9c2f348933e8ecf939e9b38ff79625 (diff)
downloadrust-de99a879269fa59c496e817eb7918ea405aebd08.tar.gz
rust-de99a879269fa59c496e817eb7918ea405aebd08.zip
Rollup merge of #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: https://github.com/rust-lang/rust/pull/105973#issuecomment-1363152232

Fixes #106030
Fixes #105244
-rw-r--r--compiler/rustc_hir_typeck/src/callee.rs7
-rw-r--r--src/test/ui/suggestions/fn-to-method-deeply-nested.rs13
-rw-r--r--src/test/ui/suggestions/fn-to-method-deeply-nested.stderr39
-rw-r--r--src/test/ui/typeck/check-args-on-fn-err-2.rs5
-rw-r--r--src/test/ui/typeck/check-args-on-fn-err-2.stderr23
-rw-r--r--src/test/ui/typeck/check-args-on-fn-err.rs6
-rw-r--r--src/test/ui/typeck/check-args-on-fn-err.stderr9
7 files changed, 101 insertions, 1 deletions
diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs
index 4ec71a78a00..af14ee08a99 100644
--- a/compiler/rustc_hir_typeck/src/callee.rs
+++ b/compiler/rustc_hir_typeck/src/callee.rs
@@ -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
@@ -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.
diff --git a/src/test/ui/suggestions/fn-to-method-deeply-nested.rs b/src/test/ui/suggestions/fn-to-method-deeply-nested.rs
new file mode 100644
index 00000000000..58ee3d6409a
--- /dev/null
+++ b/src/test/ui/suggestions/fn-to-method-deeply-nested.rs
@@ -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
+    )))))
+}
diff --git a/src/test/ui/suggestions/fn-to-method-deeply-nested.stderr b/src/test/ui/suggestions/fn-to-method-deeply-nested.stderr
new file mode 100644
index 00000000000..ce813ea7aba
--- /dev/null
+++ b/src/test/ui/suggestions/fn-to-method-deeply-nested.stderr
@@ -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`.
diff --git a/src/test/ui/typeck/check-args-on-fn-err-2.rs b/src/test/ui/typeck/check-args-on-fn-err-2.rs
new file mode 100644
index 00000000000..af57dbe3317
--- /dev/null
+++ b/src/test/ui/typeck/check-args-on-fn-err-2.rs
@@ -0,0 +1,5 @@
+fn main() {
+    a((), 1i32 == 2u32);
+    //~^ ERROR cannot find function `a` in this scope
+    //~| ERROR mismatched types
+}
diff --git a/src/test/ui/typeck/check-args-on-fn-err-2.stderr b/src/test/ui/typeck/check-args-on-fn-err-2.stderr
new file mode 100644
index 00000000000..301bb88dbac
--- /dev/null
+++ b/src/test/ui/typeck/check-args-on-fn-err-2.stderr
@@ -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`.
diff --git a/src/test/ui/typeck/check-args-on-fn-err.rs b/src/test/ui/typeck/check-args-on-fn-err.rs
new file mode 100644
index 00000000000..04b98ddd952
--- /dev/null
+++ b/src/test/ui/typeck/check-args-on-fn-err.rs
@@ -0,0 +1,6 @@
+fn main() {
+    unknown(1, |glyf| {
+        //~^ ERROR: cannot find function `unknown` in this scope
+        let actual = glyf;
+    });
+}
diff --git a/src/test/ui/typeck/check-args-on-fn-err.stderr b/src/test/ui/typeck/check-args-on-fn-err.stderr
new file mode 100644
index 00000000000..864d33e0e93
--- /dev/null
+++ b/src/test/ui/typeck/check-args-on-fn-err.stderr
@@ -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`.