add def_id and substs to ConstraintCategory::CallArgument
This commit is contained in:
parent
cbdce42320
commit
99fa572ab1
10 changed files with 77 additions and 45 deletions
|
@ -95,7 +95,7 @@ pub struct OutlivesConstraint<'tcx> {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
|
|
||||||
/// What caused this constraint?
|
/// What caused this constraint?
|
||||||
pub category: ConstraintCategory,
|
pub category: ConstraintCategory<'tcx>,
|
||||||
|
|
||||||
/// Variance diagnostic information
|
/// Variance diagnostic information
|
||||||
pub variance_info: VarianceDiagInfo<'tcx>,
|
pub variance_info: VarianceDiagInfo<'tcx>,
|
||||||
|
|
|
@ -788,7 +788,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
location: Location,
|
location: Location,
|
||||||
issued_borrow: &BorrowData<'tcx>,
|
issued_borrow: &BorrowData<'tcx>,
|
||||||
explanation: BorrowExplanation,
|
explanation: BorrowExplanation<'tcx>,
|
||||||
) {
|
) {
|
||||||
let used_in_call = matches!(
|
let used_in_call = matches!(
|
||||||
explanation,
|
explanation,
|
||||||
|
@ -1088,7 +1088,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
BorrowExplanation::MustBeValidFor {
|
BorrowExplanation::MustBeValidFor {
|
||||||
category:
|
category:
|
||||||
category @ (ConstraintCategory::Return(_)
|
category @ (ConstraintCategory::Return(_)
|
||||||
| ConstraintCategory::CallArgument
|
| ConstraintCategory::CallArgument(_)
|
||||||
| ConstraintCategory::OpaqueType),
|
| ConstraintCategory::OpaqueType),
|
||||||
from_closure: false,
|
from_closure: false,
|
||||||
ref region_name,
|
ref region_name,
|
||||||
|
@ -1147,7 +1147,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
borrow: &BorrowData<'tcx>,
|
borrow: &BorrowData<'tcx>,
|
||||||
drop_span: Span,
|
drop_span: Span,
|
||||||
borrow_spans: UseSpans<'tcx>,
|
borrow_spans: UseSpans<'tcx>,
|
||||||
explanation: BorrowExplanation,
|
explanation: BorrowExplanation<'tcx>,
|
||||||
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
|
||||||
debug!(
|
debug!(
|
||||||
"report_local_value_does_not_live_long_enough(\
|
"report_local_value_does_not_live_long_enough(\
|
||||||
|
@ -1352,7 +1352,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
drop_span: Span,
|
drop_span: Span,
|
||||||
borrow_spans: UseSpans<'tcx>,
|
borrow_spans: UseSpans<'tcx>,
|
||||||
proper_span: Span,
|
proper_span: Span,
|
||||||
explanation: BorrowExplanation,
|
explanation: BorrowExplanation<'tcx>,
|
||||||
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
|
||||||
debug!(
|
debug!(
|
||||||
"report_temporary_value_does_not_live_long_enough(\
|
"report_temporary_value_does_not_live_long_enough(\
|
||||||
|
@ -1410,7 +1410,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
borrow: &BorrowData<'tcx>,
|
borrow: &BorrowData<'tcx>,
|
||||||
borrow_span: Span,
|
borrow_span: Span,
|
||||||
return_span: Span,
|
return_span: Span,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
opt_place_desc: Option<&String>,
|
opt_place_desc: Option<&String>,
|
||||||
) -> Option<DiagnosticBuilder<'cx, ErrorGuaranteed>> {
|
) -> Option<DiagnosticBuilder<'cx, ErrorGuaranteed>> {
|
||||||
let return_kind = match category {
|
let return_kind = match category {
|
||||||
|
@ -1508,7 +1508,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
use_span: UseSpans<'tcx>,
|
use_span: UseSpans<'tcx>,
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
fr_name: &RegionName,
|
fr_name: &RegionName,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
constraint_span: Span,
|
constraint_span: Span,
|
||||||
captured_var: &str,
|
captured_var: &str,
|
||||||
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
|
||||||
|
@ -1559,7 +1559,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
let msg = format!("{} is returned here", kind);
|
let msg = format!("{} is returned here", kind);
|
||||||
err.span_note(constraint_span, &msg);
|
err.span_note(constraint_span, &msg);
|
||||||
}
|
}
|
||||||
ConstraintCategory::CallArgument => {
|
ConstraintCategory::CallArgument(_) => {
|
||||||
fr_name.highlight_region_name(&mut err);
|
fr_name.highlight_region_name(&mut err);
|
||||||
if matches!(use_span.generator_kind(), Some(GeneratorKind::Async(_))) {
|
if matches!(use_span.generator_kind(), Some(GeneratorKind::Async(_))) {
|
||||||
err.note(
|
err.note(
|
||||||
|
|
|
@ -24,7 +24,7 @@ use crate::{
|
||||||
use super::{find_use, RegionName, UseSpans};
|
use super::{find_use, RegionName, UseSpans};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum BorrowExplanation {
|
pub(crate) enum BorrowExplanation<'tcx> {
|
||||||
UsedLater(LaterUseKind, Span, Option<Span>),
|
UsedLater(LaterUseKind, Span, Option<Span>),
|
||||||
UsedLaterInLoop(LaterUseKind, Span, Option<Span>),
|
UsedLaterInLoop(LaterUseKind, Span, Option<Span>),
|
||||||
UsedLaterWhenDropped {
|
UsedLaterWhenDropped {
|
||||||
|
@ -33,7 +33,7 @@ pub(crate) enum BorrowExplanation {
|
||||||
should_note_order: bool,
|
should_note_order: bool,
|
||||||
},
|
},
|
||||||
MustBeValidFor {
|
MustBeValidFor {
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
from_closure: bool,
|
from_closure: bool,
|
||||||
span: Span,
|
span: Span,
|
||||||
region_name: RegionName,
|
region_name: RegionName,
|
||||||
|
@ -51,11 +51,11 @@ pub(crate) enum LaterUseKind {
|
||||||
Other,
|
Other,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BorrowExplanation {
|
impl<'tcx> BorrowExplanation<'tcx> {
|
||||||
pub(crate) fn is_explained(&self) -> bool {
|
pub(crate) fn is_explained(&self) -> bool {
|
||||||
!matches!(self, BorrowExplanation::Unexplained)
|
!matches!(self, BorrowExplanation::Unexplained)
|
||||||
}
|
}
|
||||||
pub(crate) fn add_explanation_to_diagnostic<'tcx>(
|
pub(crate) fn add_explanation_to_diagnostic(
|
||||||
&self,
|
&self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
|
@ -276,7 +276,7 @@ impl BorrowExplanation {
|
||||||
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(
|
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(
|
||||||
&self,
|
&self,
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
category: &ConstraintCategory,
|
category: &ConstraintCategory<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
region_name: &RegionName,
|
region_name: &RegionName,
|
||||||
) {
|
) {
|
||||||
|
@ -305,7 +305,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
borrow_region: RegionVid,
|
borrow_region: RegionVid,
|
||||||
outlived_region: RegionVid,
|
outlived_region: RegionVid,
|
||||||
) -> (ConstraintCategory, bool, Span, Option<RegionName>) {
|
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>) {
|
||||||
let BlameConstraint { category, from_closure, cause, variance_info: _ } =
|
let BlameConstraint { category, from_closure, cause, variance_info: _ } =
|
||||||
self.regioncx.best_blame_constraint(
|
self.regioncx.best_blame_constraint(
|
||||||
&self.body,
|
&self.body,
|
||||||
|
@ -337,7 +337,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
location: Location,
|
location: Location,
|
||||||
borrow: &BorrowData<'tcx>,
|
borrow: &BorrowData<'tcx>,
|
||||||
kind_place: Option<(WriteKind, Place<'tcx>)>,
|
kind_place: Option<(WriteKind, Place<'tcx>)>,
|
||||||
) -> BorrowExplanation {
|
) -> BorrowExplanation<'tcx> {
|
||||||
debug!(
|
debug!(
|
||||||
"explain_why_borrow_contains_point(location={:?}, borrow={:?}, kind_place={:?})",
|
"explain_why_borrow_contains_point(location={:?}, borrow={:?}, kind_place={:?})",
|
||||||
location, borrow, kind_place
|
location, borrow, kind_place
|
||||||
|
|
|
@ -87,7 +87,7 @@ pub struct RegionInferenceContext<'tcx> {
|
||||||
|
|
||||||
/// Map closure bounds to a `Span` that should be used for error reporting.
|
/// Map closure bounds to a `Span` that should be used for error reporting.
|
||||||
closure_bounds_mapping:
|
closure_bounds_mapping:
|
||||||
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
|
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory<'tcx>, Span)>>,
|
||||||
|
|
||||||
/// Map universe indexes to information on why we created it.
|
/// Map universe indexes to information on why we created it.
|
||||||
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
||||||
|
@ -259,7 +259,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
|
member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
|
||||||
closure_bounds_mapping: FxHashMap<
|
closure_bounds_mapping: FxHashMap<
|
||||||
Location,
|
Location,
|
||||||
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
|
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory<'tcx>, Span)>,
|
||||||
>,
|
>,
|
||||||
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
||||||
type_tests: Vec<TypeTest<'tcx>>,
|
type_tests: Vec<TypeTest<'tcx>>,
|
||||||
|
@ -1772,7 +1772,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
fr1: RegionVid,
|
fr1: RegionVid,
|
||||||
fr1_origin: NllRegionVariableOrigin,
|
fr1_origin: NllRegionVariableOrigin,
|
||||||
fr2: RegionVid,
|
fr2: RegionVid,
|
||||||
) -> (ConstraintCategory, ObligationCause<'tcx>) {
|
) -> (ConstraintCategory<'tcx>, ObligationCause<'tcx>) {
|
||||||
let BlameConstraint { category, cause, .. } =
|
let BlameConstraint { category, cause, .. } =
|
||||||
self.best_blame_constraint(body, fr1, fr1_origin, |r| {
|
self.best_blame_constraint(body, fr1, fr1_origin, |r| {
|
||||||
self.provides_universal_region(r, fr1, fr2)
|
self.provides_universal_region(r, fr1, fr2)
|
||||||
|
@ -2270,7 +2270,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct BlameConstraint<'tcx> {
|
pub struct BlameConstraint<'tcx> {
|
||||||
pub category: ConstraintCategory,
|
pub category: ConstraintCategory<'tcx>,
|
||||||
pub from_closure: bool,
|
pub from_closure: bool,
|
||||||
pub cause: ObligationCause<'tcx>,
|
pub cause: ObligationCause<'tcx>,
|
||||||
pub variance_info: ty::VarianceDiagInfo<'tcx>,
|
pub variance_info: ty::VarianceDiagInfo<'tcx>,
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
pub(super) fn fully_perform_op<R, Op>(
|
pub(super) fn fully_perform_op<R, Op>(
|
||||||
&mut self,
|
&mut self,
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
op: Op,
|
op: Op,
|
||||||
) -> Fallible<R>
|
) -> Fallible<R>
|
||||||
where
|
where
|
||||||
|
@ -83,11 +83,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
instantiated
|
instantiated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(self), level = "debug")]
|
||||||
pub(super) fn prove_trait_ref(
|
pub(super) fn prove_trait_ref(
|
||||||
&mut self,
|
&mut self,
|
||||||
trait_ref: ty::TraitRef<'tcx>,
|
trait_ref: ty::TraitRef<'tcx>,
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
) {
|
) {
|
||||||
self.prove_predicates(
|
self.prove_predicates(
|
||||||
Some(ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
|
Some(ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
|
||||||
|
@ -113,6 +114,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(instantiated_predicates.spans.into_iter())
|
.zip(instantiated_predicates.spans.into_iter())
|
||||||
{
|
{
|
||||||
|
debug!(?predicate);
|
||||||
let predicate = self.normalize(predicate, locations);
|
let predicate = self.normalize(predicate, locations);
|
||||||
self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(span));
|
self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(span));
|
||||||
}
|
}
|
||||||
|
@ -122,7 +124,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
predicates: impl IntoIterator<Item = impl ToPredicate<'tcx>>,
|
predicates: impl IntoIterator<Item = impl ToPredicate<'tcx>>,
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
) {
|
) {
|
||||||
for predicate in predicates {
|
for predicate in predicates {
|
||||||
let predicate = predicate.to_predicate(self.tcx());
|
let predicate = predicate.to_predicate(self.tcx());
|
||||||
|
@ -137,7 +139,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
predicate: ty::Predicate<'tcx>,
|
predicate: ty::Predicate<'tcx>,
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
) {
|
) {
|
||||||
let param_env = self.param_env;
|
let param_env = self.param_env;
|
||||||
self.fully_perform_op(
|
self.fully_perform_op(
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub(crate) struct ConstraintConversion<'a, 'tcx> {
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
span: Span,
|
span: Span,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
|
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
span: Span,
|
span: Span,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
|
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
@ -162,6 +162,8 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||||
&mut constraints,
|
&mut constraints,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
debug!(?normalized_inputs_and_output);
|
||||||
|
|
||||||
for u in ty::UniverseIndex::ROOT..infcx.universe() {
|
for u in ty::UniverseIndex::ROOT..infcx.universe() {
|
||||||
let info = UniverseInfo::other();
|
let info = UniverseInfo::other();
|
||||||
constraints.universe_causes.insert(u, info);
|
constraints.universe_causes.insert(u, info);
|
||||||
|
@ -185,6 +187,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||||
implicit_region_bound,
|
implicit_region_bound,
|
||||||
&mut borrowck_context,
|
&mut borrowck_context,
|
||||||
|mut cx| {
|
|mut cx| {
|
||||||
|
debug!("inside extra closure of type_check_internal");
|
||||||
cx.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
|
cx.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
|
||||||
liveness::generate(
|
liveness::generate(
|
||||||
&mut cx,
|
&mut cx,
|
||||||
|
@ -257,6 +260,7 @@ fn type_check_internal<'a, 'tcx, R>(
|
||||||
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
|
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
|
||||||
extra: impl FnOnce(TypeChecker<'a, 'tcx>) -> R,
|
extra: impl FnOnce(TypeChecker<'a, 'tcx>) -> R,
|
||||||
) -> R {
|
) -> R {
|
||||||
|
debug!("body: {:#?}", body);
|
||||||
let mut checker = TypeChecker::new(
|
let mut checker = TypeChecker::new(
|
||||||
infcx,
|
infcx,
|
||||||
body,
|
body,
|
||||||
|
@ -934,8 +938,8 @@ pub(crate) struct MirTypeckRegionConstraints<'tcx> {
|
||||||
|
|
||||||
pub(crate) member_constraints: MemberConstraintSet<'tcx, RegionVid>,
|
pub(crate) member_constraints: MemberConstraintSet<'tcx, RegionVid>,
|
||||||
|
|
||||||
pub(crate) closure_bounds_mapping:
|
crate closure_bounds_mapping:
|
||||||
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
|
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory<'tcx>, Span)>>,
|
||||||
|
|
||||||
pub(crate) universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
pub(crate) universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
||||||
|
|
||||||
|
@ -1125,7 +1129,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
fn push_region_constraints(
|
fn push_region_constraints(
|
||||||
&mut self,
|
&mut self,
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
data: &QueryRegionConstraints<'tcx>,
|
data: &QueryRegionConstraints<'tcx>,
|
||||||
) {
|
) {
|
||||||
debug!("constraints generated: {:#?}", data);
|
debug!("constraints generated: {:#?}", data);
|
||||||
|
@ -1150,7 +1154,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
sub: Ty<'tcx>,
|
sub: Ty<'tcx>,
|
||||||
sup: Ty<'tcx>,
|
sup: Ty<'tcx>,
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
) -> Fallible<()> {
|
) -> Fallible<()> {
|
||||||
// Use this order of parameters because the sup type is usually the
|
// Use this order of parameters because the sup type is usually the
|
||||||
// "expected" type in diagnostics.
|
// "expected" type in diagnostics.
|
||||||
|
@ -1163,7 +1167,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
) -> Fallible<()> {
|
) -> Fallible<()> {
|
||||||
self.relate_types(expected, ty::Variance::Invariant, found, locations, category)
|
self.relate_types(expected, ty::Variance::Invariant, found, locations, category)
|
||||||
}
|
}
|
||||||
|
@ -1175,7 +1179,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
v: ty::Variance,
|
v: ty::Variance,
|
||||||
user_ty: &UserTypeProjection,
|
user_ty: &UserTypeProjection,
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
) -> Fallible<()> {
|
) -> Fallible<()> {
|
||||||
let annotated_type = self.user_type_annotations[user_ty.base].inferred_ty;
|
let annotated_type = self.user_type_annotations[user_ty.base].inferred_ty;
|
||||||
let mut curr_projected_ty = PlaceTy::from_ty(annotated_type);
|
let mut curr_projected_ty = PlaceTy::from_ty(annotated_type);
|
||||||
|
@ -1212,6 +1216,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
#[instrument(skip(self, body, location), level = "debug")]
|
#[instrument(skip(self, body, location), level = "debug")]
|
||||||
fn check_stmt(&mut self, body: &Body<'tcx>, stmt: &Statement<'tcx>, location: Location) {
|
fn check_stmt(&mut self, body: &Body<'tcx>, stmt: &Statement<'tcx>, location: Location) {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
debug!("stmt kind: {:?}", stmt.kind);
|
||||||
match stmt.kind {
|
match stmt.kind {
|
||||||
StatementKind::Assign(box (ref place, ref rv)) => {
|
StatementKind::Assign(box (ref place, ref rv)) => {
|
||||||
// Assignments to temporaries are not "interesting";
|
// Assignments to temporaries are not "interesting";
|
||||||
|
@ -1251,9 +1256,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
|
|
||||||
let place_ty = place.ty(body, tcx).ty;
|
let place_ty = place.ty(body, tcx).ty;
|
||||||
|
debug!(?place_ty);
|
||||||
let place_ty = self.normalize(place_ty, location);
|
let place_ty = self.normalize(place_ty, location);
|
||||||
|
debug!("place_ty normalized: {:?}", place_ty);
|
||||||
let rv_ty = rv.ty(body, tcx);
|
let rv_ty = rv.ty(body, tcx);
|
||||||
|
debug!(?rv_ty);
|
||||||
let rv_ty = self.normalize(rv_ty, location);
|
let rv_ty = self.normalize(rv_ty, location);
|
||||||
|
debug!("normalized rv_ty: {:?}", rv_ty);
|
||||||
if let Err(terr) =
|
if let Err(terr) =
|
||||||
self.sub_types(rv_ty, place_ty, location.to_locations(), category)
|
self.sub_types(rv_ty, place_ty, location.to_locations(), category)
|
||||||
{
|
{
|
||||||
|
@ -1347,6 +1356,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
term_location: Location,
|
term_location: Location,
|
||||||
) {
|
) {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
debug!("terminator kind: {:?}", term.kind);
|
||||||
match term.kind {
|
match term.kind {
|
||||||
TerminatorKind::Goto { .. }
|
TerminatorKind::Goto { .. }
|
||||||
| TerminatorKind::Resume
|
| TerminatorKind::Resume
|
||||||
|
@ -1404,7 +1414,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
// FIXME: check the values
|
// FIXME: check the values
|
||||||
}
|
}
|
||||||
TerminatorKind::Call {
|
TerminatorKind::Call {
|
||||||
ref func, ref args, destination, target, from_hir_call, ..
|
ref func,
|
||||||
|
ref args,
|
||||||
|
ref destination,
|
||||||
|
from_hir_call,
|
||||||
|
fn_span,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
self.check_operand(func, term_location);
|
self.check_operand(func, term_location);
|
||||||
for arg in args {
|
for arg in args {
|
||||||
|
@ -1413,6 +1428,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!("check_terminator: call, func_ty={:?}", func_ty);
|
||||||
|
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),
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -1425,6 +1442,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
LateBoundRegionConversionTime::FnCall,
|
LateBoundRegionConversionTime::FnCall,
|
||||||
sig,
|
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);
|
||||||
|
|
||||||
|
@ -1585,11 +1603,25 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
if args.len() < sig.inputs().len() || (args.len() > sig.inputs().len() && !sig.c_variadic) {
|
if args.len() < sig.inputs().len() || (args.len() > sig.inputs().len() && !sig.c_variadic) {
|
||||||
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 = func.ty(body, self.infcx.tcx);
|
||||||
|
if let ty::FnDef(fn_did, substs) = func_ty.kind() {
|
||||||
|
Some((*fn_did, *substs))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
debug!(?call_arg);
|
||||||
|
|
||||||
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
|
ConstraintCategory::CallArgument(call_arg)
|
||||||
} else {
|
} else {
|
||||||
ConstraintCategory::Boring
|
ConstraintCategory::Boring
|
||||||
};
|
};
|
||||||
|
@ -1841,6 +1873,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip(self, body), level = "debug")]
|
||||||
fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) {
|
fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
v: ty::Variance,
|
v: ty::Variance,
|
||||||
b: Ty<'tcx>,
|
b: Ty<'tcx>,
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
) -> Fallible<()> {
|
) -> Fallible<()> {
|
||||||
TypeRelating::new(
|
TypeRelating::new(
|
||||||
self.infcx,
|
self.infcx,
|
||||||
|
@ -47,7 +47,7 @@ struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
|
|
||||||
/// What category do we assign the resulting `'a: 'b` relationships?
|
/// What category do we assign the resulting `'a: 'b` relationships?
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
|
|
||||||
/// Information so that error reporting knows what types we are relating
|
/// Information so that error reporting knows what types we are relating
|
||||||
/// when reporting a bound region error.
|
/// when reporting a bound region error.
|
||||||
|
@ -58,7 +58,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
|
||||||
fn new(
|
fn new(
|
||||||
type_checker: &'me mut TypeChecker<'bccx, 'tcx>,
|
type_checker: &'me mut TypeChecker<'bccx, 'tcx>,
|
||||||
locations: Locations,
|
locations: Locations,
|
||||||
category: ConstraintCategory,
|
category: ConstraintCategory<'tcx>,
|
||||||
universe_info: UniverseInfo<'tcx>,
|
universe_info: UniverseInfo<'tcx>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { type_checker, locations, category, universe_info }
|
Self { type_checker, locations, category, universe_info }
|
||||||
|
|
|
@ -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, OpaqueHiddenType, Ty, TyCtxt};
|
use crate::ty::{self, subst::SubstsRef, 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;
|
||||||
|
@ -338,12 +338,9 @@ pub struct ClosureOutlivesRequirement<'tcx> {
|
||||||
pub blame_span: Span,
|
pub blame_span: Span,
|
||||||
|
|
||||||
// ... due to this reason.
|
// ... due to this reason.
|
||||||
pub category: ConstraintCategory,
|
pub category: ConstraintCategory<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure this enum doesn't unintentionally grow
|
|
||||||
rustc_data_structures::static_assert_size!(ConstraintCategory, 12);
|
|
||||||
|
|
||||||
/// 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.
|
||||||
|
@ -351,7 +348,7 @@ rustc_data_structures::static_assert_size!(ConstraintCategory, 12);
|
||||||
/// See also `rustc_const_eval::borrow_check::constraints`.
|
/// See also `rustc_const_eval::borrow_check::constraints`.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
||||||
#[derive(TyEncodable, TyDecodable, HashStable)]
|
#[derive(TyEncodable, TyDecodable, HashStable)]
|
||||||
pub enum ConstraintCategory {
|
pub enum ConstraintCategory<'tcx> {
|
||||||
Return(ReturnConstraint),
|
Return(ReturnConstraint),
|
||||||
Yield,
|
Yield,
|
||||||
UseAsConst,
|
UseAsConst,
|
||||||
|
@ -363,7 +360,7 @@ pub enum ConstraintCategory {
|
||||||
///
|
///
|
||||||
/// 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,
|
CallArgument(Option<(DefId, SubstsRef<'tcx>)>),
|
||||||
CopyBound,
|
CopyBound,
|
||||||
SizedBound,
|
SizedBound,
|
||||||
Assignment,
|
Assignment,
|
||||||
|
|
|
@ -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(..) => {
|
ty::ReVar(reg_vid) => {
|
||||||
bug!("StableHasher: unexpected region {:?}", *self)
|
reg_vid.hash_stable(hcx, hasher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue