rebase, use Ty in CallArgument and re-insert static_assert_size on ConstraintCategory

This commit is contained in:
b-naber
2022-05-25 23:32:27 +02:00
parent 99fa123f66
commit 3c6c8d5a8d
4 changed files with 26 additions and 25 deletions

View File

@@ -788,7 +788,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let instance = if let ConstraintCategory::CallArgument(Some((fn_did, substs))) = category { let instance = if let ConstraintCategory::CallArgument(Some(func_ty)) = category {
let (fn_did, substs) = match func_ty.kind() {
ty::FnDef(fn_did, substs) => (fn_did, substs),
_ => return,
};
debug!(?fn_did, ?substs); debug!(?fn_did, ?substs);
// Only suggest this on function calls, not closures // Only suggest this on function calls, not closures
@@ -821,13 +825,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let mut visitor = TraitObjectVisitor(FxHashSet::default()); let mut visitor = TraitObjectVisitor(FxHashSet::default());
visitor.visit_ty(param.param_ty); visitor.visit_ty(param.param_ty);
if let Some((ident, self_ty)) = let Some((ident, self_ty)) =
self.get_impl_ident_and_self_ty_from_trait(instance.def_id(), &visitor.0) self.get_impl_ident_and_self_ty_from_trait(instance.def_id(), &visitor.0) else {return};
{
self.suggest_constrain_dyn_trait_in_impl(diag, &visitor.0, ident, self_ty) self.suggest_constrain_dyn_trait_in_impl(diag, &visitor.0, ident, self_ty);
} else {
return;
};
} }
#[instrument(skip(self, err), level = "debug")] #[instrument(skip(self, err), level = "debug")]

View File

@@ -1418,7 +1418,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
ref args, ref args,
ref destination, ref destination,
from_hir_call, from_hir_call,
fn_span, target,
.. ..
} => { } => {
self.check_operand(func, term_location); self.check_operand(func, term_location);
@@ -1427,9 +1427,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
} }
let func_ty = func.ty(body, tcx); let func_ty = func.ty(body, tcx);
debug!("check_terminator: call, func_ty={:?}", func_ty);
debug!("func_ty.kind: {:?}", func_ty.kind()); debug!("func_ty.kind: {:?}", func_ty.kind());
debug!(?fn_span);
let sig = match func_ty.kind() { let sig = match func_ty.kind() {
ty::FnDef(..) | ty::FnPtr(_) => func_ty.fn_sig(tcx), ty::FnDef(..) | ty::FnPtr(_) => func_ty.fn_sig(tcx),
_ => { _ => {
@@ -1444,7 +1443,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
); );
debug!(?sig); debug!(?sig);
let sig = self.normalize(sig, term_location); let sig = self.normalize(sig, term_location);
self.check_call_dest(body, term, &sig, destination, target, term_location); self.check_call_dest(body, term, &sig, *destination, target, term_location);
self.prove_predicates( self.prove_predicates(
sig.inputs_and_output sig.inputs_and_output
@@ -1604,24 +1603,19 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
span_mirbug!(self, term, "call to {:?} with wrong # of args", sig); span_mirbug!(self, term, "call to {:?} with wrong # of args", sig);
} }
let call_arg = if let TerminatorKind::Call { func, .. } = &term.kind { let func_ty = if let TerminatorKind::Call { func, .. } = &term.kind {
let func_ty = func.ty(body, self.infcx.tcx); Some(func.ty(body, self.infcx.tcx))
if let ty::FnDef(fn_did, substs) = func_ty.kind() {
Some((*fn_did, *substs))
} else {
None
}
} else { } else {
None None
}; };
debug!(?call_arg); debug!(?func_ty);
for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() { for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() {
let op_arg_ty = op_arg.ty(body, self.tcx()); let op_arg_ty = op_arg.ty(body, self.tcx());
let op_arg_ty = self.normalize(op_arg_ty, term_location); let op_arg_ty = self.normalize(op_arg_ty, term_location);
let category = if from_hir_call { let category = if from_hir_call {
ConstraintCategory::CallArgument(call_arg) ConstraintCategory::CallArgument(func_ty)
} else { } else {
ConstraintCategory::Boring ConstraintCategory::Boring
}; };

View File

@@ -1,7 +1,7 @@
//! Values computed by queries that use MIR. //! Values computed by queries that use MIR.
use crate::mir::{self, Body, Promoted}; use crate::mir::{self, Body, Promoted};
use crate::ty::{self, subst::SubstsRef, OpaqueHiddenType, Ty, TyCtxt}; use crate::ty::{self, OpaqueHiddenType, Ty, TyCtxt};
use rustc_data_structures::stable_map::FxHashMap; use rustc_data_structures::stable_map::FxHashMap;
use rustc_data_structures::vec_map::VecMap; use rustc_data_structures::vec_map::VecMap;
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
@@ -341,6 +341,10 @@ pub struct ClosureOutlivesRequirement<'tcx> {
pub category: ConstraintCategory<'tcx>, pub category: ConstraintCategory<'tcx>,
} }
// Make sure this enum doesn't unintentionally grow
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(ConstraintCategory<'_>, 16);
/// Outlives-constraints can be categorized to determine whether and why they /// Outlives-constraints can be categorized to determine whether and why they
/// are interesting (for error reporting). Order of variants indicates sort /// are interesting (for error reporting). Order of variants indicates sort
/// order of the category, thereby influencing diagnostic output. /// order of the category, thereby influencing diagnostic output.
@@ -360,7 +364,9 @@ pub enum ConstraintCategory<'tcx> {
/// ///
/// We try to get the category that the closure used when reporting this. /// We try to get the category that the closure used when reporting this.
ClosureBounds, ClosureBounds,
CallArgument(Option<(DefId, SubstsRef<'tcx>)>),
/// Contains the function type if available.
CallArgument(Option<Ty<'tcx>>),
CopyBound, CopyBound,
SizedBound, SizedBound,
Assignment, Assignment,

View File

@@ -135,8 +135,8 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionKind {
ty::RePlaceholder(p) => { ty::RePlaceholder(p) => {
p.hash_stable(hcx, hasher); p.hash_stable(hcx, hasher);
} }
ty::ReVar(reg_vid) => { ty::ReVar(reg) => {
reg_vid.hash_stable(hcx, hasher); reg.hash_stable(hcx, hasher);
} }
} }
} }