Skip to content

Commit b68e994

Browse files
authored
Rollup merge of #105973 - oli-obk:simplify_callee_checks, r=jackh726
Avoid going through the happy path in case of non-fn builtin calls No functional change, just doing an early return. The removed comment is not applicable anymore, not every node needs type bindings in the error case. At best this would have been needed to avoid ICEs, but afaict this can't happen anymore today, as we do fallible checks.
2 parents b9edcfa + 1c5b53b commit b68e994

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

compiler/rustc_hir_typeck/src/callee.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::{Expectation, FnCtxt, TupleArgumentsFlag};
44

55
use crate::type_error_struct;
66
use rustc_ast::util::parser::PREC_POSTFIX;
7-
use rustc_errors::{struct_span_err, Applicability, Diagnostic, StashKey};
7+
use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorGuaranteed, StashKey};
88
use rustc_hir as hir;
99
use rustc_hir::def::{self, CtorKind, Namespace, Res};
1010
use rustc_hir::def_id::DefId;
@@ -424,21 +424,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
424424
}
425425
}
426426

427-
self.report_invalid_callee(call_expr, callee_expr, callee_ty, arg_exprs);
428-
429-
// This is the "default" function signature, used in case of error.
430-
// In that case, we check each argument against "error" in order to
431-
// set up all the node type bindings.
432-
(
433-
ty::Binder::dummy(self.tcx.mk_fn_sig(
434-
self.err_args(arg_exprs.len()).into_iter(),
435-
self.tcx.ty_error(),
436-
false,
437-
hir::Unsafety::Normal,
438-
abi::Abi::Rust,
439-
)),
440-
None,
441-
)
427+
let err = self.report_invalid_callee(call_expr, callee_expr, callee_ty, arg_exprs);
428+
429+
return self.tcx.ty_error_with_guaranteed(err);
442430
}
443431
};
444432

@@ -591,7 +579,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
591579
callee_expr: &'tcx hir::Expr<'tcx>,
592580
callee_ty: Ty<'tcx>,
593581
arg_exprs: &'tcx [hir::Expr<'tcx>],
594-
) {
582+
) -> ErrorGuaranteed {
595583
let mut unit_variant = None;
596584
if let hir::ExprKind::Path(qpath) = &callee_expr.kind
597585
&& let Res::Def(def::DefKind::Ctor(kind, CtorKind::Const), _)
@@ -720,7 +708,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
720708
err.span_label(span, label);
721709
}
722710
}
723-
err.emit();
711+
err.emit()
724712
}
725713

726714
fn confirm_deferred_closure_call(

compiler/rustc_middle/src/ty/subst.rs

+4
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ impl<'tcx> InternalSubsts<'tcx> {
400400
}
401401

402402
#[inline]
403+
#[track_caller]
403404
pub fn type_at(&self, i: usize) -> Ty<'tcx> {
404405
if let GenericArgKind::Type(ty) = self[i].unpack() {
405406
ty
@@ -409,6 +410,7 @@ impl<'tcx> InternalSubsts<'tcx> {
409410
}
410411

411412
#[inline]
413+
#[track_caller]
412414
pub fn region_at(&self, i: usize) -> ty::Region<'tcx> {
413415
if let GenericArgKind::Lifetime(lt) = self[i].unpack() {
414416
lt
@@ -418,6 +420,7 @@ impl<'tcx> InternalSubsts<'tcx> {
418420
}
419421

420422
#[inline]
423+
#[track_caller]
421424
pub fn const_at(&self, i: usize) -> ty::Const<'tcx> {
422425
if let GenericArgKind::Const(ct) = self[i].unpack() {
423426
ct
@@ -427,6 +430,7 @@ impl<'tcx> InternalSubsts<'tcx> {
427430
}
428431

429432
#[inline]
433+
#[track_caller]
430434
pub fn type_for_def(&self, def: &ty::GenericParamDef) -> GenericArg<'tcx> {
431435
self.type_at(def.index as usize).into()
432436
}

0 commit comments

Comments
 (0)