Skip to content

Commit 3c6c8d5

Browse files
committed
rebase, use Ty in CallArgument and re-insert static_assert_size on ConstraintCategory
1 parent 99fa123 commit 3c6c8d5

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
788788

789789
let tcx = self.infcx.tcx;
790790

791-
let instance = if let ConstraintCategory::CallArgument(Some((fn_did, substs))) = category {
791+
let instance = if let ConstraintCategory::CallArgument(Some(func_ty)) = category {
792+
let (fn_did, substs) = match func_ty.kind() {
793+
ty::FnDef(fn_did, substs) => (fn_did, substs),
794+
_ => return,
795+
};
792796
debug!(?fn_did, ?substs);
793797

794798
// Only suggest this on function calls, not closures
@@ -821,13 +825,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
821825
let mut visitor = TraitObjectVisitor(FxHashSet::default());
822826
visitor.visit_ty(param.param_ty);
823827

824-
if let Some((ident, self_ty)) =
825-
self.get_impl_ident_and_self_ty_from_trait(instance.def_id(), &visitor.0)
826-
{
827-
self.suggest_constrain_dyn_trait_in_impl(diag, &visitor.0, ident, self_ty)
828-
} else {
829-
return;
830-
};
828+
let Some((ident, self_ty)) =
829+
self.get_impl_ident_and_self_ty_from_trait(instance.def_id(), &visitor.0) else {return};
830+
831+
self.suggest_constrain_dyn_trait_in_impl(diag, &visitor.0, ident, self_ty);
831832
}
832833

833834
#[instrument(skip(self, err), level = "debug")]

compiler/rustc_borrowck/src/type_check/mod.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14181418
ref args,
14191419
ref destination,
14201420
from_hir_call,
1421-
fn_span,
1421+
target,
14221422
..
14231423
} => {
14241424
self.check_operand(func, term_location);
@@ -1427,9 +1427,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14271427
}
14281428

14291429
let func_ty = func.ty(body, tcx);
1430-
debug!("check_terminator: call, func_ty={:?}", func_ty);
14311430
debug!("func_ty.kind: {:?}", func_ty.kind());
1432-
debug!(?fn_span);
1431+
14331432
let sig = match func_ty.kind() {
14341433
ty::FnDef(..) | ty::FnPtr(_) => func_ty.fn_sig(tcx),
14351434
_ => {
@@ -1444,7 +1443,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14441443
);
14451444
debug!(?sig);
14461445
let sig = self.normalize(sig, term_location);
1447-
self.check_call_dest(body, term, &sig, destination, target, term_location);
1446+
self.check_call_dest(body, term, &sig, *destination, target, term_location);
14481447

14491448
self.prove_predicates(
14501449
sig.inputs_and_output
@@ -1604,24 +1603,19 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16041603
span_mirbug!(self, term, "call to {:?} with wrong # of args", sig);
16051604
}
16061605

1607-
let call_arg = if let TerminatorKind::Call { func, .. } = &term.kind {
1608-
let func_ty = func.ty(body, self.infcx.tcx);
1609-
if let ty::FnDef(fn_did, substs) = func_ty.kind() {
1610-
Some((*fn_did, *substs))
1611-
} else {
1612-
None
1613-
}
1606+
let func_ty = if let TerminatorKind::Call { func, .. } = &term.kind {
1607+
Some(func.ty(body, self.infcx.tcx))
16141608
} else {
16151609
None
16161610
};
1617-
debug!(?call_arg);
1611+
debug!(?func_ty);
16181612

16191613
for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() {
16201614
let op_arg_ty = op_arg.ty(body, self.tcx());
16211615

16221616
let op_arg_ty = self.normalize(op_arg_ty, term_location);
16231617
let category = if from_hir_call {
1624-
ConstraintCategory::CallArgument(call_arg)
1618+
ConstraintCategory::CallArgument(func_ty)
16251619
} else {
16261620
ConstraintCategory::Boring
16271621
};

compiler/rustc_middle/src/mir/query.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Values computed by queries that use MIR.
22
33
use crate::mir::{self, Body, Promoted};
4-
use crate::ty::{self, subst::SubstsRef, OpaqueHiddenType, Ty, TyCtxt};
4+
use crate::ty::{self, OpaqueHiddenType, Ty, TyCtxt};
55
use rustc_data_structures::stable_map::FxHashMap;
66
use rustc_data_structures::vec_map::VecMap;
77
use rustc_errors::ErrorGuaranteed;
@@ -341,6 +341,10 @@ pub struct ClosureOutlivesRequirement<'tcx> {
341341
pub category: ConstraintCategory<'tcx>,
342342
}
343343

344+
// Make sure this enum doesn't unintentionally grow
345+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
346+
rustc_data_structures::static_assert_size!(ConstraintCategory<'_>, 16);
347+
344348
/// Outlives-constraints can be categorized to determine whether and why they
345349
/// are interesting (for error reporting). Order of variants indicates sort
346350
/// order of the category, thereby influencing diagnostic output.
@@ -360,7 +364,9 @@ pub enum ConstraintCategory<'tcx> {
360364
///
361365
/// We try to get the category that the closure used when reporting this.
362366
ClosureBounds,
363-
CallArgument(Option<(DefId, SubstsRef<'tcx>)>),
367+
368+
/// Contains the function type if available.
369+
CallArgument(Option<Ty<'tcx>>),
364370
CopyBound,
365371
SizedBound,
366372
Assignment,

compiler/rustc_middle/src/ty/impls_ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionKind {
135135
ty::RePlaceholder(p) => {
136136
p.hash_stable(hcx, hasher);
137137
}
138-
ty::ReVar(reg_vid) => {
139-
reg_vid.hash_stable(hcx, hasher);
138+
ty::ReVar(reg) => {
139+
reg.hash_stable(hcx, hasher);
140140
}
141141
}
142142
}

0 commit comments

Comments
 (0)