diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-07-25 23:34:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-25 23:34:07 +0200 |
| commit | a6bf68d8d013f097ea188878963684853c2fa634 (patch) | |
| tree | a0ecc9d615138731704bb0d64f7c91d6cf3aa3b9 | |
| parent | c5c0aa143c1124888b11298a79ce443ae9636bef (diff) | |
| parent | c0c2d39668be6d0633dbcb7fa19bd54ed7122587 (diff) | |
| download | rust-a6bf68d8d013f097ea188878963684853c2fa634.tar.gz rust-a6bf68d8d013f097ea188878963684853c2fa634.zip | |
Rollup merge of #113578 - compiler-errors:uncallable-sig, r=b-naber
Don't say that a type is uncallable if its fn signature has errors in it This is fallout from #106309, where we don't consider param-env candidates that reference errors because they unify with everything. This means, however, that we don't consider an APIT like `impl Fn(MissingType)` isn't considered to implement `Fn`, for example. We can double-check that with a weaker heuristic [`extract_callable_info`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/fn_ctxt/struct.FnCtxt.html#method.extract_callable_info), and suppress the knock-down error using that. Fixes #113566
| -rw-r--r-- | compiler/rustc_hir_typeck/src/callee.rs | 8 | ||||
| -rw-r--r-- | tests/ui/typeck/apit-with-error-type-in-sig.rs | 8 | ||||
| -rw-r--r-- | tests/ui/typeck/apit-with-error-type-in-sig.stderr | 9 |
3 files changed, 25 insertions, 0 deletions
diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index a24d1ff077f..a1fd09d4050 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -581,6 +581,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { callee_ty: Ty<'tcx>, arg_exprs: &'tcx [hir::Expr<'tcx>], ) -> ErrorGuaranteed { + // Callee probe fails when APIT references errors, so suppress those + // errors here. + if let Some((_, _, args)) = self.extract_callable_info(callee_ty) + && let Err(err) = args.error_reported() + { + return err; + } + let mut unit_variant = None; if let hir::ExprKind::Path(qpath) = &callee_expr.kind && let Res::Def(def::DefKind::Ctor(kind, CtorKind::Const), _) diff --git a/tests/ui/typeck/apit-with-error-type-in-sig.rs b/tests/ui/typeck/apit-with-error-type-in-sig.rs new file mode 100644 index 00000000000..35990fc16c8 --- /dev/null +++ b/tests/ui/typeck/apit-with-error-type-in-sig.rs @@ -0,0 +1,8 @@ +type Foo = Bar; +//~^ ERROR cannot find type `Bar` in this scope + +fn check(f: impl FnOnce(Foo), val: Foo) { + f(val); +} + +fn main() {} diff --git a/tests/ui/typeck/apit-with-error-type-in-sig.stderr b/tests/ui/typeck/apit-with-error-type-in-sig.stderr new file mode 100644 index 00000000000..49b2eac1b65 --- /dev/null +++ b/tests/ui/typeck/apit-with-error-type-in-sig.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `Bar` in this scope + --> $DIR/apit-with-error-type-in-sig.rs:1:12 + | +LL | type Foo = Bar; + | ^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`. |
