Skip to content

Commit a6bf68d

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#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 rust-lang#113566
2 parents c5c0aa1 + c0c2d39 commit a6bf68d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

compiler/rustc_hir_typeck/src/callee.rs

+8
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
581581
callee_ty: Ty<'tcx>,
582582
arg_exprs: &'tcx [hir::Expr<'tcx>],
583583
) -> ErrorGuaranteed {
584+
// Callee probe fails when APIT references errors, so suppress those
585+
// errors here.
586+
if let Some((_, _, args)) = self.extract_callable_info(callee_ty)
587+
&& let Err(err) = args.error_reported()
588+
{
589+
return err;
590+
}
591+
584592
let mut unit_variant = None;
585593
if let hir::ExprKind::Path(qpath) = &callee_expr.kind
586594
&& let Res::Def(def::DefKind::Ctor(kind, CtorKind::Const), _)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type Foo = Bar;
2+
//~^ ERROR cannot find type `Bar` in this scope
3+
4+
fn check(f: impl FnOnce(Foo), val: Foo) {
5+
f(val);
6+
}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0412]: cannot find type `Bar` in this scope
2+
--> $DIR/apit-with-error-type-in-sig.rs:1:12
3+
|
4+
LL | type Foo = Bar;
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 E0412`.

0 commit comments

Comments
 (0)