rebase, use Ty in CallArgument and re-insert static_assert_size on ConstraintCategory
This commit is contained in:
parent
99fa123f66
commit
3c6c8d5a8d
@ -788,7 +788,11 @@ fn maybe_suggest_constrain_dyn_trait_impl(
|
||||
|
||||
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);
|
||||
|
||||
// Only suggest this on function calls, not closures
|
||||
@ -821,13 +825,10 @@ fn maybe_suggest_constrain_dyn_trait_impl(
|
||||
let mut visitor = TraitObjectVisitor(FxHashSet::default());
|
||||
visitor.visit_ty(param.param_ty);
|
||||
|
||||
if let Some((ident, self_ty)) =
|
||||
self.get_impl_ident_and_self_ty_from_trait(instance.def_id(), &visitor.0)
|
||||
{
|
||||
self.suggest_constrain_dyn_trait_in_impl(diag, &visitor.0, ident, self_ty)
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
let Some((ident, self_ty)) =
|
||||
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);
|
||||
}
|
||||
|
||||
#[instrument(skip(self, err), level = "debug")]
|
||||
|
@ -1418,7 +1418,7 @@ fn check_terminator(
|
||||
ref args,
|
||||
ref destination,
|
||||
from_hir_call,
|
||||
fn_span,
|
||||
target,
|
||||
..
|
||||
} => {
|
||||
self.check_operand(func, term_location);
|
||||
@ -1427,9 +1427,8 @@ fn check_terminator(
|
||||
}
|
||||
|
||||
let func_ty = func.ty(body, tcx);
|
||||
debug!("check_terminator: call, func_ty={:?}", func_ty);
|
||||
debug!("func_ty.kind: {:?}", func_ty.kind());
|
||||
debug!(?fn_span);
|
||||
|
||||
let sig = match func_ty.kind() {
|
||||
ty::FnDef(..) | ty::FnPtr(_) => func_ty.fn_sig(tcx),
|
||||
_ => {
|
||||
@ -1444,7 +1443,7 @@ fn check_terminator(
|
||||
);
|
||||
debug!(?sig);
|
||||
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(
|
||||
sig.inputs_and_output
|
||||
@ -1604,24 +1603,19 @@ fn check_call_inputs(
|
||||
span_mirbug!(self, term, "call to {:?} with wrong # of args", sig);
|
||||
}
|
||||
|
||||
let call_arg = if let TerminatorKind::Call { func, .. } = &term.kind {
|
||||
let func_ty = func.ty(body, self.infcx.tcx);
|
||||
if let ty::FnDef(fn_did, substs) = func_ty.kind() {
|
||||
Some((*fn_did, *substs))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
let func_ty = if let TerminatorKind::Call { func, .. } = &term.kind {
|
||||
Some(func.ty(body, self.infcx.tcx))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
debug!(?call_arg);
|
||||
debug!(?func_ty);
|
||||
|
||||
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 = self.normalize(op_arg_ty, term_location);
|
||||
let category = if from_hir_call {
|
||||
ConstraintCategory::CallArgument(call_arg)
|
||||
ConstraintCategory::CallArgument(func_ty)
|
||||
} else {
|
||||
ConstraintCategory::Boring
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Values computed by queries that use MIR.
|
||||
|
||||
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::vec_map::VecMap;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
@ -341,6 +341,10 @@ pub struct ClosureOutlivesRequirement<'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
|
||||
/// are interesting (for error reporting). Order of variants indicates sort
|
||||
/// 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.
|
||||
ClosureBounds,
|
||||
CallArgument(Option<(DefId, SubstsRef<'tcx>)>),
|
||||
|
||||
/// Contains the function type if available.
|
||||
CallArgument(Option<Ty<'tcx>>),
|
||||
CopyBound,
|
||||
SizedBound,
|
||||
Assignment,
|
||||
|
@ -135,8 +135,8 @@ fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHas
|
||||
ty::RePlaceholder(p) => {
|
||||
p.hash_stable(hcx, hasher);
|
||||
}
|
||||
ty::ReVar(reg_vid) => {
|
||||
reg_vid.hash_stable(hcx, hasher);
|
||||
ty::ReVar(reg) => {
|
||||
reg.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user