Skip to content

Commit c0c2d39

Browse files
Don't call a type uncallable if its signature has errors in it
1 parent 8164cdb commit c0c2d39

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)