mirror of https://github.com/rust-lang/rust.git
Auto merge of #124952 - compiler-errors:no-error, r=lcnr
Rename some `FulfillmentErrorCode`/`ObligationCauseCode` variants to be less redundant 1. Rename some `FulfillmentErrorCode` variants. 2. Always use `ObligationCauseCode::` to prefix a code, rather than using a glob import and naming them through `traits::`. 3. Rename some `ObligationCauseCode` variants -- I wasn't particularly thorough with thinking of a new names for these, so could workshop them if necessary. 4. Misc stuff from renaming. r? lcnr
This commit is contained in:
commit
2cce088584
|
@ -1344,7 +1344,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
for error in errors {
|
for error in errors {
|
||||||
if let FulfillmentErrorCode::SelectionError(
|
if let FulfillmentErrorCode::Select(
|
||||||
SelectionError::Unimplemented,
|
SelectionError::Unimplemented,
|
||||||
) = error.code
|
) = error.code
|
||||||
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(
|
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(
|
||||||
|
|
|
@ -1283,7 +1283,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
// The type doesn't implement Clone because of unmet obligations.
|
// The type doesn't implement Clone because of unmet obligations.
|
||||||
for error in errors {
|
for error in errors {
|
||||||
if let traits::FulfillmentErrorCode::SelectionError(
|
if let traits::FulfillmentErrorCode::Select(
|
||||||
traits::SelectionError::Unimplemented,
|
traits::SelectionError::Unimplemented,
|
||||||
) = error.code
|
) = error.code
|
||||||
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(
|
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(
|
||||||
|
|
|
@ -2059,7 +2059,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
// We currently do not store the `DefId` in the `ConstraintCategory`
|
// We currently do not store the `DefId` in the `ConstraintCategory`
|
||||||
// for performances reasons. The error reporting code used by NLL only
|
// for performances reasons. The error reporting code used by NLL only
|
||||||
// uses the span, so this doesn't cause any problems at the moment.
|
// uses the span, so this doesn't cause any problems at the moment.
|
||||||
Some(ObligationCauseCode::BindingObligation(
|
Some(ObligationCauseCode::SpannedWhereClause(
|
||||||
CRATE_DEF_ID.to_def_id(),
|
CRATE_DEF_ID.to_def_id(),
|
||||||
predicate_span,
|
predicate_span,
|
||||||
))
|
))
|
||||||
|
@ -2067,7 +2067,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| ObligationCauseCode::MiscObligation);
|
.unwrap_or_else(|| ObligationCauseCode::Misc);
|
||||||
|
|
||||||
// Classify each of the constraints along the path.
|
// Classify each of the constraints along the path.
|
||||||
let mut categorized_path: Vec<BlameConstraint<'tcx>> = path
|
let mut categorized_path: Vec<BlameConstraint<'tcx>> = path
|
||||||
|
|
|
@ -738,7 +738,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
let cause = ObligationCause::new(
|
let cause = ObligationCause::new(
|
||||||
terminator.source_info.span,
|
terminator.source_info.span,
|
||||||
self.body.source.def_id().expect_local(),
|
self.body.source.def_id().expect_local(),
|
||||||
ObligationCauseCode::ItemObligation(callee),
|
ObligationCauseCode::WhereClause(callee),
|
||||||
);
|
);
|
||||||
let normalized_predicates = ocx.normalize(&cause, param_env, predicates);
|
let normalized_predicates = ocx.normalize(&cause, param_env, predicates);
|
||||||
ocx.register_obligations(traits::predicates_for_generics(
|
ocx.register_obligations(traits::predicates_for_generics(
|
||||||
|
|
|
@ -175,7 +175,7 @@ fn compare_method_predicate_entailment<'tcx>(
|
||||||
let cause = ObligationCause::new(
|
let cause = ObligationCause::new(
|
||||||
impl_m_span,
|
impl_m_span,
|
||||||
impl_m_def_id,
|
impl_m_def_id,
|
||||||
ObligationCauseCode::CompareImplItemObligation {
|
ObligationCauseCode::CompareImplItem {
|
||||||
impl_item_def_id: impl_m_def_id,
|
impl_item_def_id: impl_m_def_id,
|
||||||
trait_item_def_id: trait_m.def_id,
|
trait_item_def_id: trait_m.def_id,
|
||||||
kind: impl_m.kind,
|
kind: impl_m.kind,
|
||||||
|
@ -236,7 +236,7 @@ fn compare_method_predicate_entailment<'tcx>(
|
||||||
let cause = ObligationCause::new(
|
let cause = ObligationCause::new(
|
||||||
span,
|
span,
|
||||||
impl_m_def_id,
|
impl_m_def_id,
|
||||||
ObligationCauseCode::CompareImplItemObligation {
|
ObligationCauseCode::CompareImplItem {
|
||||||
impl_item_def_id: impl_m_def_id,
|
impl_item_def_id: impl_m_def_id,
|
||||||
trait_item_def_id: trait_m.def_id,
|
trait_item_def_id: trait_m.def_id,
|
||||||
kind: impl_m.kind,
|
kind: impl_m.kind,
|
||||||
|
@ -464,7 +464,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
||||||
let cause = ObligationCause::new(
|
let cause = ObligationCause::new(
|
||||||
return_span,
|
return_span,
|
||||||
impl_m_def_id,
|
impl_m_def_id,
|
||||||
ObligationCauseCode::CompareImplItemObligation {
|
ObligationCauseCode::CompareImplItem {
|
||||||
impl_item_def_id: impl_m_def_id,
|
impl_item_def_id: impl_m_def_id,
|
||||||
trait_item_def_id: trait_m.def_id,
|
trait_item_def_id: trait_m.def_id,
|
||||||
kind: impl_m.kind,
|
kind: impl_m.kind,
|
||||||
|
@ -819,7 +819,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
|
||||||
ObligationCause::new(
|
ObligationCause::new(
|
||||||
self.span,
|
self.span,
|
||||||
self.body_id,
|
self.body_id,
|
||||||
ObligationCauseCode::BindingObligation(proj.def_id, pred_span),
|
ObligationCauseCode::SpannedWhereClause(proj.def_id, pred_span),
|
||||||
),
|
),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
pred,
|
pred,
|
||||||
|
@ -1752,7 +1752,7 @@ fn compare_const_predicate_entailment<'tcx>(
|
||||||
let impl_ty = tcx.type_of(impl_ct_def_id).instantiate_identity();
|
let impl_ty = tcx.type_of(impl_ct_def_id).instantiate_identity();
|
||||||
|
|
||||||
let trait_ty = tcx.type_of(trait_ct.def_id).instantiate(tcx, trait_to_impl_args);
|
let trait_ty = tcx.type_of(trait_ct.def_id).instantiate(tcx, trait_to_impl_args);
|
||||||
let code = ObligationCauseCode::CompareImplItemObligation {
|
let code = ObligationCauseCode::CompareImplItem {
|
||||||
impl_item_def_id: impl_ct_def_id,
|
impl_item_def_id: impl_ct_def_id,
|
||||||
trait_item_def_id: trait_ct.def_id,
|
trait_item_def_id: trait_ct.def_id,
|
||||||
kind: impl_ct.kind,
|
kind: impl_ct.kind,
|
||||||
|
@ -1924,7 +1924,7 @@ fn compare_type_predicate_entailment<'tcx>(
|
||||||
let cause = ObligationCause::new(
|
let cause = ObligationCause::new(
|
||||||
span,
|
span,
|
||||||
impl_ty_def_id,
|
impl_ty_def_id,
|
||||||
ObligationCauseCode::CompareImplItemObligation {
|
ObligationCauseCode::CompareImplItem {
|
||||||
impl_item_def_id: impl_ty.def_id.expect_local(),
|
impl_item_def_id: impl_ty.def_id.expect_local(),
|
||||||
trait_item_def_id: trait_ty.def_id,
|
trait_item_def_id: trait_ty.def_id,
|
||||||
kind: impl_ty.kind,
|
kind: impl_ty.kind,
|
||||||
|
@ -2012,9 +2012,9 @@ pub(super) fn check_type_bounds<'tcx>(
|
||||||
);
|
);
|
||||||
let mk_cause = |span: Span| {
|
let mk_cause = |span: Span| {
|
||||||
let code = if span.is_dummy() {
|
let code = if span.is_dummy() {
|
||||||
traits::ItemObligation(trait_ty.def_id)
|
ObligationCauseCode::WhereClause(trait_ty.def_id)
|
||||||
} else {
|
} else {
|
||||||
traits::BindingObligation(trait_ty.def_id, span)
|
ObligationCauseCode::SpannedWhereClause(trait_ty.def_id, span)
|
||||||
};
|
};
|
||||||
ObligationCause::new(impl_ty_span, impl_ty_def_id, code)
|
ObligationCause::new(impl_ty_span, impl_ty_def_id, code)
|
||||||
};
|
};
|
||||||
|
@ -2251,7 +2251,8 @@ fn try_report_async_mismatch<'tcx>(
|
||||||
};
|
};
|
||||||
|
|
||||||
for error in errors {
|
for error in errors {
|
||||||
if let traits::BindingObligation(def_id, _) = *error.root_obligation.cause.code()
|
if let ObligationCauseCode::SpannedWhereClause(def_id, _) =
|
||||||
|
*error.root_obligation.cause.code()
|
||||||
&& def_id == async_future_def_id
|
&& def_id == async_future_def_id
|
||||||
&& let Some(proj) = error.root_obligation.predicate.to_opt_poly_projection_pred()
|
&& let Some(proj) = error.root_obligation.predicate.to_opt_poly_projection_pred()
|
||||||
&& let Some(proj) = proj.no_bound_vars()
|
&& let Some(proj) = proj.no_bound_vars()
|
||||||
|
|
|
@ -5,6 +5,7 @@ use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{codes::*, struct_span_code_err, ErrorGuaranteed};
|
use rustc_errors::{codes::*, struct_span_code_err, ErrorGuaranteed};
|
||||||
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
||||||
use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
|
use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
|
||||||
|
use rustc_infer::traits::ObligationCauseCode;
|
||||||
use rustc_middle::ty::util::CheckRegions;
|
use rustc_middle::ty::util::CheckRegions;
|
||||||
use rustc_middle::ty::GenericArgsRef;
|
use rustc_middle::ty::GenericArgsRef;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
|
@ -139,7 +140,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
|
||||||
for (pred, span) in tcx.predicates_of(drop_impl_def_id).instantiate_identity(tcx) {
|
for (pred, span) in tcx.predicates_of(drop_impl_def_id).instantiate_identity(tcx) {
|
||||||
let normalize_cause = traits::ObligationCause::misc(span, adt_def_id);
|
let normalize_cause = traits::ObligationCause::misc(span, adt_def_id);
|
||||||
let pred = ocx.normalize(&normalize_cause, param_env, pred);
|
let pred = ocx.normalize(&normalize_cause, param_env, pred);
|
||||||
let cause = traits::ObligationCause::new(span, adt_def_id, traits::DropImpl);
|
let cause = traits::ObligationCause::new(span, adt_def_id, ObligationCauseCode::DropImpl);
|
||||||
ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, pred));
|
ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, pred));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1136,7 +1136,7 @@ fn check_type_defn<'tcx>(
|
||||||
traits::ObligationCause::new(
|
traits::ObligationCause::new(
|
||||||
hir_ty.span,
|
hir_ty.span,
|
||||||
wfcx.body_def_id,
|
wfcx.body_def_id,
|
||||||
traits::FieldSized {
|
ObligationCauseCode::FieldSized {
|
||||||
adt_kind: match &item.kind {
|
adt_kind: match &item.kind {
|
||||||
ItemKind::Struct(..) => AdtKind::Struct,
|
ItemKind::Struct(..) => AdtKind::Struct,
|
||||||
ItemKind::Union(..) => AdtKind::Union,
|
ItemKind::Union(..) => AdtKind::Union,
|
||||||
|
@ -1161,7 +1161,7 @@ fn check_type_defn<'tcx>(
|
||||||
let cause = traits::ObligationCause::new(
|
let cause = traits::ObligationCause::new(
|
||||||
tcx.def_span(discr_def_id),
|
tcx.def_span(discr_def_id),
|
||||||
wfcx.body_def_id,
|
wfcx.body_def_id,
|
||||||
traits::MiscObligation,
|
ObligationCauseCode::Misc,
|
||||||
);
|
);
|
||||||
wfcx.register_obligation(traits::Obligation::new(
|
wfcx.register_obligation(traits::Obligation::new(
|
||||||
tcx,
|
tcx,
|
||||||
|
@ -1278,7 +1278,11 @@ fn check_item_type(
|
||||||
wfcx.register_wf_obligation(ty_span, Some(WellFormedLoc::Ty(item_id)), item_ty.into());
|
wfcx.register_wf_obligation(ty_span, Some(WellFormedLoc::Ty(item_id)), item_ty.into());
|
||||||
if forbid_unsized {
|
if forbid_unsized {
|
||||||
wfcx.register_bound(
|
wfcx.register_bound(
|
||||||
traits::ObligationCause::new(ty_span, wfcx.body_def_id, traits::WellFormed(None)),
|
traits::ObligationCause::new(
|
||||||
|
ty_span,
|
||||||
|
wfcx.body_def_id,
|
||||||
|
ObligationCauseCode::WellFormed(None),
|
||||||
|
),
|
||||||
wfcx.param_env,
|
wfcx.param_env,
|
||||||
item_ty,
|
item_ty,
|
||||||
tcx.require_lang_item(LangItem::Sized, None),
|
tcx.require_lang_item(LangItem::Sized, None),
|
||||||
|
@ -1293,7 +1297,11 @@ fn check_item_type(
|
||||||
|
|
||||||
if should_check_for_sync {
|
if should_check_for_sync {
|
||||||
wfcx.register_bound(
|
wfcx.register_bound(
|
||||||
traits::ObligationCause::new(ty_span, wfcx.body_def_id, traits::SharedStatic),
|
traits::ObligationCause::new(
|
||||||
|
ty_span,
|
||||||
|
wfcx.body_def_id,
|
||||||
|
ObligationCauseCode::SharedStatic,
|
||||||
|
),
|
||||||
wfcx.param_env,
|
wfcx.param_env,
|
||||||
item_ty,
|
item_ty,
|
||||||
tcx.require_lang_item(LangItem::Sync, Some(ty_span)),
|
tcx.require_lang_item(LangItem::Sync, Some(ty_span)),
|
||||||
|
@ -1542,7 +1550,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
|
||||||
let cause = traits::ObligationCause::new(
|
let cause = traits::ObligationCause::new(
|
||||||
sp,
|
sp,
|
||||||
wfcx.body_def_id,
|
wfcx.body_def_id,
|
||||||
traits::ItemObligation(def_id.to_def_id()),
|
ObligationCauseCode::WhereClause(def_id.to_def_id()),
|
||||||
);
|
);
|
||||||
traits::Obligation::new(tcx, cause, wfcx.param_env, pred)
|
traits::Obligation::new(tcx, cause, wfcx.param_env, pred)
|
||||||
});
|
});
|
||||||
|
@ -1982,7 +1990,11 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
|
||||||
|
|
||||||
let obligation = traits::Obligation::new(
|
let obligation = traits::Obligation::new(
|
||||||
tcx,
|
tcx,
|
||||||
traits::ObligationCause::new(span, self.body_def_id, traits::TrivialBound),
|
traits::ObligationCause::new(
|
||||||
|
span,
|
||||||
|
self.body_def_id,
|
||||||
|
ObligationCauseCode::TrivialBound,
|
||||||
|
),
|
||||||
empty_env,
|
empty_env,
|
||||||
pred,
|
pred,
|
||||||
);
|
);
|
||||||
|
|
|
@ -212,7 +212,7 @@ fn get_impl_args(
|
||||||
traits::ObligationCause::new(
|
traits::ObligationCause::new(
|
||||||
impl1_span,
|
impl1_span,
|
||||||
impl1_def_id,
|
impl1_def_id,
|
||||||
traits::ObligationCauseCode::BindingObligation(impl2_node.def_id(), span),
|
traits::ObligationCauseCode::SpannedWhereClause(impl2_node.def_id(), span),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -9,6 +9,7 @@ use rustc_hir as hir;
|
||||||
use rustc_hir::def::{self, CtorKind, Namespace, Res};
|
use rustc_hir::def::{self, CtorKind, Namespace, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir_analysis::autoderef::Autoderef;
|
use rustc_hir_analysis::autoderef::Autoderef;
|
||||||
|
use rustc_infer::traits::ObligationCauseCode;
|
||||||
use rustc_infer::{
|
use rustc_infer::{
|
||||||
infer,
|
infer,
|
||||||
traits::{self, Obligation, ObligationCause},
|
traits::{self, Obligation, ObligationCause},
|
||||||
|
@ -117,7 +118,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// we must check that return type of called functions is WF:
|
// we must check that return type of called functions is WF:
|
||||||
self.register_wf_obligation(output.into(), call_expr.span, traits::WellFormed(None));
|
self.register_wf_obligation(
|
||||||
|
output.into(),
|
||||||
|
call_expr.span,
|
||||||
|
ObligationCauseCode::WellFormed(None),
|
||||||
|
);
|
||||||
|
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
@ -524,9 +529,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.register_bound(
|
self.register_bound(
|
||||||
ty,
|
ty,
|
||||||
self.tcx.require_lang_item(hir::LangItem::Tuple, Some(sp)),
|
self.tcx.require_lang_item(hir::LangItem::Tuple, Some(sp)),
|
||||||
traits::ObligationCause::new(sp, self.body_id, traits::RustCall),
|
traits::ObligationCause::new(sp, self.body_id, ObligationCauseCode::RustCall),
|
||||||
);
|
);
|
||||||
self.require_type_is_sized(ty, sp, traits::RustCall);
|
self.require_type_is_sized(ty, sp, ObligationCauseCode::RustCall);
|
||||||
} else {
|
} else {
|
||||||
self.dcx().emit_err(errors::RustCallIncorrectArgs { span: sp });
|
self.dcx().emit_err(errors::RustCallIncorrectArgs { span: sp });
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ use rustc_middle::ty::{self, Binder, Ty, TyCtxt};
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::LocalDefId;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use rustc_trait_selection::traits;
|
|
||||||
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
|
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
|
||||||
|
|
||||||
/// Helper used for fns and closures. Does the grungy work of checking a function
|
/// Helper used for fns and closures. Does the grungy work of checking a function
|
||||||
|
@ -76,7 +75,7 @@ pub(super) fn check_fn<'a, 'tcx>(
|
||||||
fcx.register_wf_obligation(
|
fcx.register_wf_obligation(
|
||||||
param_ty.into(),
|
param_ty.into(),
|
||||||
param.span,
|
param.span,
|
||||||
traits::WellFormed(Some(WellFormedLoc::Param {
|
ObligationCauseCode::WellFormed(Some(WellFormedLoc::Param {
|
||||||
function: fn_def_id,
|
function: fn_def_id,
|
||||||
param_idx: idx,
|
param_idx: idx,
|
||||||
})),
|
})),
|
||||||
|
@ -101,7 +100,7 @@ pub(super) fn check_fn<'a, 'tcx>(
|
||||||
param.pat.span,
|
param.pat.span,
|
||||||
// ty.span == binding_span iff this is a closure parameter with no type ascription,
|
// ty.span == binding_span iff this is a closure parameter with no type ascription,
|
||||||
// or if it's an implicit `self` parameter
|
// or if it's an implicit `self` parameter
|
||||||
traits::SizedArgumentType(
|
ObligationCauseCode::SizedArgumentType(
|
||||||
if ty_span == Some(param.span) && tcx.is_closure_like(fn_def_id.into()) {
|
if ty_span == Some(param.span) && tcx.is_closure_like(fn_def_id.into()) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -121,10 +120,18 @@ pub(super) fn check_fn<'a, 'tcx>(
|
||||||
hir::FnRetTy::Return(ty) => ty.span,
|
hir::FnRetTy::Return(ty) => ty.span,
|
||||||
};
|
};
|
||||||
|
|
||||||
fcx.require_type_is_sized(declared_ret_ty, return_or_body_span, traits::SizedReturnType);
|
fcx.require_type_is_sized(
|
||||||
|
declared_ret_ty,
|
||||||
|
return_or_body_span,
|
||||||
|
ObligationCauseCode::SizedReturnType,
|
||||||
|
);
|
||||||
// We checked the root's signature during wfcheck, but not the child.
|
// We checked the root's signature during wfcheck, but not the child.
|
||||||
if fcx.tcx.is_typeck_child(fn_def_id.to_def_id()) {
|
if fcx.tcx.is_typeck_child(fn_def_id.to_def_id()) {
|
||||||
fcx.require_type_is_sized(declared_ret_ty, return_or_body_span, traits::WellFormed(None));
|
fcx.require_type_is_sized(
|
||||||
|
declared_ret_ty,
|
||||||
|
return_or_body_span,
|
||||||
|
ObligationCauseCode::WellFormed(None),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fcx.is_whole_body.set(true);
|
fcx.is_whole_body.set(true);
|
||||||
|
|
|
@ -8,6 +8,7 @@ use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
||||||
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
|
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
|
||||||
use rustc_infer::infer::{InferOk, InferResult};
|
use rustc_infer::infer::{InferOk, InferResult};
|
||||||
|
use rustc_infer::traits::ObligationCauseCode;
|
||||||
use rustc_macros::{TypeFoldable, TypeVisitable};
|
use rustc_macros::{TypeFoldable, TypeVisitable};
|
||||||
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
|
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
|
||||||
use rustc_middle::ty::GenericArgs;
|
use rustc_middle::ty::GenericArgs;
|
||||||
|
@ -119,7 +120,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
|
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
|
||||||
| hir::CoroutineKind::Coroutine(_) => {
|
| hir::CoroutineKind::Coroutine(_) => {
|
||||||
let yield_ty = self.next_ty_var(expr_span);
|
let yield_ty = self.next_ty_var(expr_span);
|
||||||
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
|
self.require_type_is_sized(
|
||||||
|
yield_ty,
|
||||||
|
expr_span,
|
||||||
|
ObligationCauseCode::SizedYieldType,
|
||||||
|
);
|
||||||
yield_ty
|
yield_ty
|
||||||
}
|
}
|
||||||
// HACK(-Ztrait-solver=next): In the *old* trait solver, we must eagerly
|
// HACK(-Ztrait-solver=next): In the *old* trait solver, we must eagerly
|
||||||
|
@ -128,7 +133,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// not a problem.
|
// not a problem.
|
||||||
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _) => {
|
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _) => {
|
||||||
let yield_ty = self.next_ty_var(expr_span);
|
let yield_ty = self.next_ty_var(expr_span);
|
||||||
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
|
self.require_type_is_sized(
|
||||||
|
yield_ty,
|
||||||
|
expr_span,
|
||||||
|
ObligationCauseCode::SizedYieldType,
|
||||||
|
);
|
||||||
|
|
||||||
Ty::new_adt(
|
Ty::new_adt(
|
||||||
tcx,
|
tcx,
|
||||||
|
|
|
@ -573,7 +573,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.require_type_is_sized_deferred(
|
self.require_type_is_sized_deferred(
|
||||||
input,
|
input,
|
||||||
span,
|
span,
|
||||||
traits::SizedArgumentType(None),
|
ObligationCauseCode::SizedArgumentType(None),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -591,7 +591,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.require_type_is_sized_deferred(
|
self.require_type_is_sized_deferred(
|
||||||
output,
|
output,
|
||||||
call.map_or(expr.span, |e| e.span),
|
call.map_or(expr.span, |e| e.span),
|
||||||
traits::SizedCallReturnType,
|
ObligationCauseCode::SizedCallReturnType,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1249,7 +1249,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.require_type_is_sized(lhs_ty, lhs.span, traits::AssignmentLhsSized);
|
self.require_type_is_sized(lhs_ty, lhs.span, ObligationCauseCode::AssignmentLhsSized);
|
||||||
|
|
||||||
if let Err(guar) = (lhs_ty, rhs_ty).error_reported() {
|
if let Err(guar) = (lhs_ty, rhs_ty).error_reported() {
|
||||||
Ty::new_error(self.tcx, guar)
|
Ty::new_error(self.tcx, guar)
|
||||||
|
@ -1471,7 +1471,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
crate::GatherLocalsVisitor::new(&fcx).visit_body(body);
|
crate::GatherLocalsVisitor::new(&fcx).visit_body(body);
|
||||||
|
|
||||||
let ty = fcx.check_expr_with_expectation(body.value, expected);
|
let ty = fcx.check_expr_with_expectation(body.value, expected);
|
||||||
fcx.require_type_is_sized(ty, body.value.span, traits::ConstSized);
|
fcx.require_type_is_sized(ty, body.value.span, ObligationCauseCode::ConstSized);
|
||||||
fcx.write_ty(block.hir_id, ty);
|
fcx.write_ty(block.hir_id, ty);
|
||||||
ty
|
ty
|
||||||
}
|
}
|
||||||
|
@ -1517,7 +1517,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
let ty = Ty::new_array_with_const_len(tcx, t, count);
|
let ty = Ty::new_array_with_const_len(tcx, t, count);
|
||||||
|
|
||||||
self.register_wf_obligation(ty.into(), expr.span, traits::WellFormed(None));
|
self.register_wf_obligation(ty.into(), expr.span, ObligationCauseCode::WellFormed(None));
|
||||||
|
|
||||||
ty
|
ty
|
||||||
}
|
}
|
||||||
|
@ -1607,7 +1607,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
if let Err(guar) = tuple.error_reported() {
|
if let Err(guar) = tuple.error_reported() {
|
||||||
Ty::new_error(self.tcx, guar)
|
Ty::new_error(self.tcx, guar)
|
||||||
} else {
|
} else {
|
||||||
self.require_type_is_sized(tuple, expr.span, traits::TupleInitializerSized);
|
self.require_type_is_sized(
|
||||||
|
tuple,
|
||||||
|
expr.span,
|
||||||
|
ObligationCauseCode::TupleInitializerSized,
|
||||||
|
);
|
||||||
tuple
|
tuple
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1646,7 +1650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
base_expr,
|
base_expr,
|
||||||
);
|
);
|
||||||
|
|
||||||
self.require_type_is_sized(adt_ty, expr.span, traits::StructInitializerSized);
|
self.require_type_is_sized(adt_ty, expr.span, ObligationCauseCode::StructInitializerSized);
|
||||||
adt_ty
|
adt_ty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3079,14 +3083,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
polarity: ty::PredicatePolarity::Positive,
|
polarity: ty::PredicatePolarity::Positive,
|
||||||
}),
|
}),
|
||||||
|derived| {
|
|derived| {
|
||||||
traits::ImplDerivedObligation(Box::new(
|
ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedCause {
|
||||||
traits::ImplDerivedObligationCause {
|
|
||||||
derived,
|
derived,
|
||||||
impl_or_alias_def_id: impl_def_id,
|
impl_or_alias_def_id: impl_def_id,
|
||||||
impl_def_predicate_index: Some(idx),
|
impl_def_predicate_index: Some(idx),
|
||||||
span,
|
span,
|
||||||
},
|
}))
|
||||||
))
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -3177,7 +3179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
fn check_expr_asm_operand(&self, expr: &'tcx hir::Expr<'tcx>, is_input: bool) {
|
fn check_expr_asm_operand(&self, expr: &'tcx hir::Expr<'tcx>, is_input: bool) {
|
||||||
let needs = if is_input { Needs::None } else { Needs::MutPlace };
|
let needs = if is_input { Needs::None } else { Needs::MutPlace };
|
||||||
let ty = self.check_expr_with_needs(expr, needs);
|
let ty = self.check_expr_with_needs(expr, needs);
|
||||||
self.require_type_is_sized(ty, expr.span, traits::InlineAsmSized);
|
self.require_type_is_sized(ty, expr.span, ObligationCauseCode::InlineAsmSized);
|
||||||
|
|
||||||
if !is_input && !expr.is_syntactic_place_expr() {
|
if !is_input && !expr.is_syntactic_place_expr() {
|
||||||
self.dcx()
|
self.dcx()
|
||||||
|
@ -3348,7 +3350,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let field_ty = self.field_ty(expr.span, field, args);
|
let field_ty = self.field_ty(expr.span, field, args);
|
||||||
|
|
||||||
// FIXME: DSTs with static alignment should be allowed
|
// FIXME: DSTs with static alignment should be allowed
|
||||||
self.require_type_is_sized(field_ty, expr.span, traits::MiscObligation);
|
self.require_type_is_sized(field_ty, expr.span, ObligationCauseCode::Misc);
|
||||||
|
|
||||||
if field.vis.is_accessible_from(sub_def_scope, self.tcx) {
|
if field.vis.is_accessible_from(sub_def_scope, self.tcx) {
|
||||||
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
|
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
|
||||||
|
@ -3376,7 +3378,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let field_ty = self.field_ty(expr.span, field, args);
|
let field_ty = self.field_ty(expr.span, field, args);
|
||||||
|
|
||||||
// FIXME: DSTs with static alignment should be allowed
|
// FIXME: DSTs with static alignment should be allowed
|
||||||
self.require_type_is_sized(field_ty, expr.span, traits::MiscObligation);
|
self.require_type_is_sized(field_ty, expr.span, ObligationCauseCode::Misc);
|
||||||
|
|
||||||
if field.vis.is_accessible_from(def_scope, self.tcx) {
|
if field.vis.is_accessible_from(def_scope, self.tcx) {
|
||||||
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
|
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
|
||||||
|
@ -3397,7 +3399,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&& field.name == sym::integer(index)
|
&& field.name == sym::integer(index)
|
||||||
{
|
{
|
||||||
for ty in tys.iter().take(index + 1) {
|
for ty in tys.iter().take(index + 1) {
|
||||||
self.require_type_is_sized(ty, expr.span, traits::MiscObligation);
|
self.require_type_is_sized(ty, expr.span, ObligationCauseCode::Misc);
|
||||||
}
|
}
|
||||||
if let Some(&field_ty) = tys.get(index) {
|
if let Some(&field_ty) = tys.get(index) {
|
||||||
field_indices.push((FIRST_VARIANT, index.into()));
|
field_indices.push((FIRST_VARIANT, index.into()));
|
||||||
|
|
|
@ -409,7 +409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
|
pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
|
||||||
let ty = self.lowerer().lower_ty(hir_ty);
|
let ty = self.lowerer().lower_ty(hir_ty);
|
||||||
self.register_wf_obligation(ty.into(), hir_ty.span, traits::WellFormed(None));
|
self.register_wf_obligation(ty.into(), hir_ty.span, ObligationCauseCode::WellFormed(None));
|
||||||
LoweredTy::from_raw(self, hir_ty.span, ty)
|
LoweredTy::from_raw(self, hir_ty.span, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,7 +520,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
for arg in args.iter().filter(|arg| {
|
for arg in args.iter().filter(|arg| {
|
||||||
matches!(arg.unpack(), GenericArgKind::Type(..) | GenericArgKind::Const(..))
|
matches!(arg.unpack(), GenericArgKind::Type(..) | GenericArgKind::Const(..))
|
||||||
}) {
|
}) {
|
||||||
self.register_wf_obligation(arg, expr.span, traits::WellFormed(None));
|
self.register_wf_obligation(arg, expr.span, ObligationCauseCode::WellFormed(None));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -772,7 +772,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
if let Some(&cached_result) = self.typeck_results.borrow().type_dependent_defs().get(hir_id)
|
if let Some(&cached_result) = self.typeck_results.borrow().type_dependent_defs().get(hir_id)
|
||||||
{
|
{
|
||||||
self.register_wf_obligation(ty.raw.into(), qself.span, traits::WellFormed(None));
|
self.register_wf_obligation(
|
||||||
|
ty.raw.into(),
|
||||||
|
qself.span,
|
||||||
|
ObligationCauseCode::WellFormed(None),
|
||||||
|
);
|
||||||
// Return directly on cache hit. This is useful to avoid doubly reporting
|
// Return directly on cache hit. This is useful to avoid doubly reporting
|
||||||
// errors with default match binding modes. See #44614.
|
// errors with default match binding modes. See #44614.
|
||||||
let def = cached_result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id));
|
let def = cached_result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id));
|
||||||
|
@ -811,7 +815,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.register_wf_obligation(
|
self.register_wf_obligation(
|
||||||
ty.raw.into(),
|
ty.raw.into(),
|
||||||
qself.span,
|
qself.span,
|
||||||
traits::WellFormed(None),
|
ObligationCauseCode::WellFormed(None),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -845,7 +849,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
});
|
});
|
||||||
|
|
||||||
if result.is_ok() {
|
if result.is_ok() {
|
||||||
self.register_wf_obligation(ty.raw.into(), qself.span, traits::WellFormed(None));
|
self.register_wf_obligation(
|
||||||
|
ty.raw.into(),
|
||||||
|
qself.span,
|
||||||
|
ObligationCauseCode::WellFormed(None),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write back the new resolution.
|
// Write back the new resolution.
|
||||||
|
@ -1402,9 +1410,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
) {
|
) {
|
||||||
self.add_required_obligations_with_code(span, def_id, args, |idx, span| {
|
self.add_required_obligations_with_code(span, def_id, args, |idx, span| {
|
||||||
if span.is_dummy() {
|
if span.is_dummy() {
|
||||||
ObligationCauseCode::ExprItemObligation(def_id, hir_id, idx)
|
ObligationCauseCode::WhereClauseInExpr(def_id, hir_id, idx)
|
||||||
} else {
|
} else {
|
||||||
ObligationCauseCode::ExprBindingObligation(def_id, span, hir_id, idx)
|
ObligationCauseCode::SpannedWhereClauseInExpr(def_id, span, hir_id, idx)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
error: &mut traits::FulfillmentError<'tcx>,
|
error: &mut traits::FulfillmentError<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let (traits::ExprItemObligation(def_id, hir_id, idx)
|
let (ObligationCauseCode::WhereClauseInExpr(def_id, hir_id, idx)
|
||||||
| traits::ExprBindingObligation(def_id, _, hir_id, idx)) =
|
| ObligationCauseCode::SpannedWhereClauseInExpr(def_id, _, hir_id, idx)) =
|
||||||
*error.obligation.cause.code().peel_derives()
|
*error.obligation.cause.code().peel_derives()
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -167,7 +167,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// the method's turbofish segments but still use `FunctionArgumentObligation`
|
// the method's turbofish segments but still use `FunctionArgumentObligation`
|
||||||
// elsewhere. Hopefully this doesn't break something.
|
// elsewhere. Hopefully this doesn't break something.
|
||||||
error.obligation.cause.map_code(|parent_code| {
|
error.obligation.cause.map_code(|parent_code| {
|
||||||
ObligationCauseCode::FunctionArgumentObligation {
|
ObligationCauseCode::FunctionArg {
|
||||||
arg_hir_id: receiver.hir_id,
|
arg_hir_id: receiver.hir_id,
|
||||||
call_hir_id: hir_id,
|
call_hir_id: hir_id,
|
||||||
parent_code,
|
parent_code,
|
||||||
|
@ -360,12 +360,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
error: &traits::FulfillmentError<'tcx>,
|
error: &traits::FulfillmentError<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let traits::FulfillmentErrorCode::SelectionError(
|
if let traits::FulfillmentErrorCode::Select(traits::SelectionError::SignatureMismatch(
|
||||||
traits::SelectionError::SignatureMismatch(box traits::SignatureMismatchData {
|
box traits::SignatureMismatchData { expected_trait_ref, .. },
|
||||||
expected_trait_ref,
|
)) = error.code
|
||||||
..
|
|
||||||
}),
|
|
||||||
) = error.code
|
|
||||||
&& let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) =
|
&& let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) =
|
||||||
expected_trait_ref.self_ty().kind()
|
expected_trait_ref.self_ty().kind()
|
||||||
&& span.overlaps(self.tcx.def_span(*def_id))
|
&& span.overlaps(self.tcx.def_span(*def_id))
|
||||||
|
@ -459,12 +456,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.blame_specific_expr_if_possible(error, arg_expr)
|
self.blame_specific_expr_if_possible(error, arg_expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
error.obligation.cause.map_code(|parent_code| {
|
error.obligation.cause.map_code(|parent_code| ObligationCauseCode::FunctionArg {
|
||||||
ObligationCauseCode::FunctionArgumentObligation {
|
|
||||||
arg_hir_id: arg.hir_id,
|
arg_hir_id: arg.hir_id,
|
||||||
call_hir_id,
|
call_hir_id,
|
||||||
parent_code,
|
parent_code,
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
} else if args_referencing_param.len() > 0 {
|
} else if args_referencing_param.len() > 0 {
|
||||||
|
@ -517,12 +512,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
) -> Result<&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>> {
|
) -> Result<&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>> {
|
||||||
match obligation_cause_code {
|
match obligation_cause_code {
|
||||||
traits::ObligationCauseCode::ExprBindingObligation(_, _, _, _) => {
|
traits::ObligationCauseCode::SpannedWhereClauseInExpr(_, _, _, _) => {
|
||||||
// This is the "root"; we assume that the `expr` is already pointing here.
|
// This is the "root"; we assume that the `expr` is already pointing here.
|
||||||
// Therefore, we return `Ok` so that this `expr` can be refined further.
|
// Therefore, we return `Ok` so that this `expr` can be refined further.
|
||||||
Ok(expr)
|
Ok(expr)
|
||||||
}
|
}
|
||||||
traits::ObligationCauseCode::ImplDerivedObligation(impl_derived) => self
|
traits::ObligationCauseCode::ImplDerived(impl_derived) => self
|
||||||
.blame_specific_expr_if_possible_for_derived_predicate_obligation(
|
.blame_specific_expr_if_possible_for_derived_predicate_obligation(
|
||||||
impl_derived,
|
impl_derived,
|
||||||
expr,
|
expr,
|
||||||
|
@ -560,7 +555,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// only a partial success - but it cannot be refined even further.
|
/// only a partial success - but it cannot be refined even further.
|
||||||
fn blame_specific_expr_if_possible_for_derived_predicate_obligation(
|
fn blame_specific_expr_if_possible_for_derived_predicate_obligation(
|
||||||
&self,
|
&self,
|
||||||
obligation: &traits::ImplDerivedObligationCause<'tcx>,
|
obligation: &traits::ImplDerivedCause<'tcx>,
|
||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
) -> Result<&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>> {
|
) -> Result<&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>> {
|
||||||
// First, we attempt to refine the `expr` for our span using the parent obligation.
|
// First, we attempt to refine the `expr` for our span using the parent obligation.
|
||||||
|
|
|
@ -33,7 +33,6 @@ use rustc_index::IndexVec;
|
||||||
use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt};
|
use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt};
|
||||||
use rustc_infer::infer::TypeTrace;
|
use rustc_infer::infer::TypeTrace;
|
||||||
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
||||||
use rustc_middle::traits::ObligationCauseCode::ExprBindingObligation;
|
|
||||||
use rustc_middle::ty::adjustment::AllowTwoPhase;
|
use rustc_middle::ty::adjustment::AllowTwoPhase;
|
||||||
use rustc_middle::ty::visit::TypeVisitableExt;
|
use rustc_middle::ty::visit::TypeVisitableExt;
|
||||||
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt};
|
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt};
|
||||||
|
@ -203,7 +202,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// All the input types from the fn signature must outlive the call
|
// All the input types from the fn signature must outlive the call
|
||||||
// so as to validate implied bounds.
|
// so as to validate implied bounds.
|
||||||
for (&fn_input_ty, arg_expr) in iter::zip(formal_input_tys, provided_args) {
|
for (&fn_input_ty, arg_expr) in iter::zip(formal_input_tys, provided_args) {
|
||||||
self.register_wf_obligation(fn_input_ty.into(), arg_expr.span, traits::MiscObligation);
|
self.register_wf_obligation(
|
||||||
|
fn_input_ty.into(),
|
||||||
|
arg_expr.span,
|
||||||
|
ObligationCauseCode::Misc,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut err_code = E0061;
|
let mut err_code = E0061;
|
||||||
|
@ -2010,7 +2013,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
for (span, code) in errors_causecode {
|
for (span, code) in errors_causecode {
|
||||||
self.dcx().try_steal_modify_and_emit_err(span, StashKey::MaybeForgetReturn, |err| {
|
self.dcx().try_steal_modify_and_emit_err(span, StashKey::MaybeForgetReturn, |err| {
|
||||||
if let Some(fn_sig) = self.body_fn_sig()
|
if let Some(fn_sig) = self.body_fn_sig()
|
||||||
&& let ExprBindingObligation(_, _, binding_hir_id, ..) = code
|
&& let ObligationCauseCode::SpannedWhereClauseInExpr(_, _, binding_hir_id, ..) =
|
||||||
|
code
|
||||||
&& !fn_sig.output().is_unit()
|
&& !fn_sig.output().is_unit()
|
||||||
{
|
{
|
||||||
let mut block_num = 0;
|
let mut block_num = 0;
|
||||||
|
@ -2099,7 +2103,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
//
|
//
|
||||||
// This is because due to normalization, we often register duplicate
|
// This is because due to normalization, we often register duplicate
|
||||||
// obligations with misc obligations that are basically impossible to
|
// obligations with misc obligations that are basically impossible to
|
||||||
// line back up with a useful ExprBindingObligation.
|
// line back up with a useful SpannedWhereClauseInExpr.
|
||||||
for error in not_adjusted {
|
for error in not_adjusted {
|
||||||
for (span, predicate, cause) in &remap_cause {
|
for (span, predicate, cause) in &remap_cause {
|
||||||
if *predicate == error.obligation.predicate
|
if *predicate == error.obligation.predicate
|
||||||
|
|
|
@ -154,7 +154,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn misc(&self, span: Span) -> ObligationCause<'tcx> {
|
pub fn misc(&self, span: Span) -> ObligationCause<'tcx> {
|
||||||
self.cause(span, ObligationCauseCode::MiscObligation)
|
self.cause(span, ObligationCauseCode::Misc)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sess(&self) -> &Session {
|
pub fn sess(&self) -> &Session {
|
||||||
|
|
|
@ -1700,7 +1700,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for error in errors {
|
for error in errors {
|
||||||
if let traits::FulfillmentErrorCode::SelectionError(
|
if let traits::FulfillmentErrorCode::Select(
|
||||||
traits::SelectionError::Unimplemented,
|
traits::SelectionError::Unimplemented,
|
||||||
) = error.code
|
) = error.code
|
||||||
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) =
|
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) =
|
||||||
|
|
|
@ -2,11 +2,11 @@ use crate::FnCtxt;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::{HirId, PatKind};
|
use rustc_hir::{HirId, PatKind};
|
||||||
|
use rustc_infer::traits::ObligationCauseCode;
|
||||||
use rustc_middle::ty::Ty;
|
use rustc_middle::ty::Ty;
|
||||||
use rustc_middle::ty::UserType;
|
use rustc_middle::ty::UserType;
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::LocalDefId;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_trait_selection::traits;
|
|
||||||
|
|
||||||
/// Provides context for checking patterns in declarations. More specifically this
|
/// Provides context for checking patterns in declarations. More specifically this
|
||||||
/// allows us to infer array types if the pattern is irrefutable and allows us to infer
|
/// allows us to infer array types if the pattern is irrefutable and allows us to infer
|
||||||
|
@ -146,7 +146,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
|
||||||
p.span,
|
p.span,
|
||||||
// ty_span == ident.span iff this is a closure parameter with no type
|
// ty_span == ident.span iff this is a closure parameter with no type
|
||||||
// ascription, or if it's an implicit `self` parameter
|
// ascription, or if it's an implicit `self` parameter
|
||||||
traits::SizedArgumentType(
|
ObligationCauseCode::SizedArgumentType(
|
||||||
if ty_span == ident.span
|
if ty_span == ident.span
|
||||||
&& self.fcx.tcx.is_closure_like(self.fcx.body_id.into())
|
&& self.fcx.tcx.is_closure_like(self.fcx.body_id.into())
|
||||||
{
|
{
|
||||||
|
@ -159,7 +159,11 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !self.fcx.tcx.features().unsized_locals {
|
if !self.fcx.tcx.features().unsized_locals {
|
||||||
self.fcx.require_type_is_sized(var_ty, p.span, traits::VariableType(p.hir_id));
|
self.fcx.require_type_is_sized(
|
||||||
|
var_ty,
|
||||||
|
p.span,
|
||||||
|
ObligationCauseCode::VariableType(p.hir_id),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,6 @@ use rustc_hir_analysis::check::check_abi;
|
||||||
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
||||||
use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, WellFormedLoc};
|
use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, WellFormedLoc};
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::traits;
|
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_session::config;
|
use rustc_session::config;
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::LocalDefId;
|
||||||
|
@ -170,7 +169,7 @@ fn typeck_with_fallback<'tcx>(
|
||||||
let wf_code = ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(def_id)));
|
let wf_code = ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(def_id)));
|
||||||
fcx.register_wf_obligation(expected_type.into(), body.value.span, wf_code);
|
fcx.register_wf_obligation(expected_type.into(), body.value.span, wf_code);
|
||||||
|
|
||||||
fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized);
|
fcx.require_type_is_sized(expected_type, body.value.span, ObligationCauseCode::ConstSized);
|
||||||
|
|
||||||
// Gather locals in statics (because of block expressions).
|
// Gather locals in statics (because of block expressions).
|
||||||
GatherLocalsVisitor::new(&fcx).visit_body(body);
|
GatherLocalsVisitor::new(&fcx).visit_body(body);
|
||||||
|
|
|
@ -565,9 +565,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||||
for obligation in traits::predicates_for_generics(
|
for obligation in traits::predicates_for_generics(
|
||||||
|idx, span| {
|
|idx, span| {
|
||||||
let code = if span.is_dummy() {
|
let code = if span.is_dummy() {
|
||||||
ObligationCauseCode::ExprItemObligation(def_id, self.call_expr.hir_id, idx)
|
ObligationCauseCode::WhereClauseInExpr(def_id, self.call_expr.hir_id, idx)
|
||||||
} else {
|
} else {
|
||||||
ObligationCauseCode::ExprBindingObligation(
|
ObligationCauseCode::SpannedWhereClauseInExpr(
|
||||||
def_id,
|
def_id,
|
||||||
span,
|
span,
|
||||||
self.call_expr.hir_id,
|
self.call_expr.hir_id,
|
||||||
|
@ -589,7 +589,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||||
// the function type must also be well-formed (this is not
|
// the function type must also be well-formed (this is not
|
||||||
// implied by the args being well-formed because of inherent
|
// implied by the args being well-formed because of inherent
|
||||||
// impls and late-bound regions - see issue #28609).
|
// impls and late-bound regions - see issue #28609).
|
||||||
self.register_wf_obligation(fty.into(), self.span, traits::WellFormed(None));
|
self.register_wf_obligation(fty.into(), self.span, ObligationCauseCode::WellFormed(None));
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -15,6 +15,7 @@ use rustc_infer::infer::canonical::{Canonical, QueryResponse};
|
||||||
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
|
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
|
||||||
use rustc_infer::infer::DefineOpaqueTypes;
|
use rustc_infer::infer::DefineOpaqueTypes;
|
||||||
use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
|
use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
|
||||||
|
use rustc_infer::traits::ObligationCauseCode;
|
||||||
use rustc_middle::middle::stability;
|
use rustc_middle::middle::stability;
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
|
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
|
||||||
|
@ -1401,9 +1402,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
ocx.register_obligations(traits::predicates_for_generics(
|
ocx.register_obligations(traits::predicates_for_generics(
|
||||||
|idx, span| {
|
|idx, span| {
|
||||||
let code = if span.is_dummy() {
|
let code = if span.is_dummy() {
|
||||||
traits::ExprItemObligation(impl_def_id, self.scope_expr_id, idx)
|
ObligationCauseCode::WhereClauseInExpr(
|
||||||
|
impl_def_id,
|
||||||
|
self.scope_expr_id,
|
||||||
|
idx,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
traits::ExprBindingObligation(
|
ObligationCauseCode::SpannedWhereClauseInExpr(
|
||||||
impl_def_id,
|
impl_def_id,
|
||||||
span,
|
span,
|
||||||
self.scope_expr_id,
|
self.scope_expr_id,
|
||||||
|
|
|
@ -146,7 +146,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let trait_ref = ty::TraitRef::new(self.tcx, into_iterator_trait, [ty]);
|
let trait_ref = ty::TraitRef::new(self.tcx, into_iterator_trait, [ty]);
|
||||||
let cause = ObligationCause::new(span, self.body_id, ObligationCauseCode::MiscObligation);
|
let cause = ObligationCause::new(span, self.body_id, ObligationCauseCode::Misc);
|
||||||
let obligation = Obligation::new(self.tcx, cause, self.param_env, trait_ref);
|
let obligation = Obligation::new(self.tcx, cause, self.param_env, trait_ref);
|
||||||
if !self.predicate_must_hold_modulo_regions(&obligation) {
|
if !self.predicate_must_hold_modulo_regions(&obligation) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -826,12 +826,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// Extract the predicate span and parent def id of the cause,
|
// Extract the predicate span and parent def id of the cause,
|
||||||
// if we have one.
|
// if we have one.
|
||||||
let (item_def_id, cause_span) = match cause.as_ref().map(|cause| cause.code()) {
|
let (item_def_id, cause_span) = match cause.as_ref().map(|cause| cause.code()) {
|
||||||
Some(ObligationCauseCode::ImplDerivedObligation(data)) => {
|
Some(ObligationCauseCode::ImplDerived(data)) => {
|
||||||
(data.impl_or_alias_def_id, data.span)
|
(data.impl_or_alias_def_id, data.span)
|
||||||
}
|
}
|
||||||
Some(
|
Some(
|
||||||
ObligationCauseCode::ExprBindingObligation(def_id, span, _, _)
|
ObligationCauseCode::SpannedWhereClauseInExpr(def_id, span, _, _)
|
||||||
| ObligationCauseCode::BindingObligation(def_id, span),
|
| ObligationCauseCode::SpannedWhereClause(def_id, span),
|
||||||
) => (*def_id, *span),
|
) => (*def_id, *span),
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,7 +19,7 @@ use rustc_span::symbol::{sym, Ident};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_trait_selection::infer::InferCtxtExt;
|
use rustc_trait_selection::infer::InferCtxtExt;
|
||||||
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt as _;
|
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt as _;
|
||||||
use rustc_trait_selection::traits::{self, FulfillmentError, ObligationCtxt};
|
use rustc_trait_selection::traits::{FulfillmentError, ObligationCtxt};
|
||||||
use rustc_type_ir::TyKind::*;
|
use rustc_type_ir::TyKind::*;
|
||||||
|
|
||||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
@ -884,7 +884,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let input_types = opt_rhs_ty.as_slice();
|
let input_types = opt_rhs_ty.as_slice();
|
||||||
let cause = self.cause(
|
let cause = self.cause(
|
||||||
span,
|
span,
|
||||||
traits::BinOp {
|
ObligationCauseCode::BinOp {
|
||||||
lhs_hir_id: lhs_expr.hir_id,
|
lhs_hir_id: lhs_expr.hir_id,
|
||||||
rhs_hir_id: opt_rhs_expr.map(|expr| expr.hir_id),
|
rhs_hir_id: opt_rhs_expr.map(|expr| expr.hir_id),
|
||||||
rhs_span: opt_rhs_expr.map(|expr| expr.span),
|
rhs_span: opt_rhs_expr.map(|expr| expr.span),
|
||||||
|
|
|
@ -18,7 +18,7 @@ use rustc_span::source_map::Spanned;
|
||||||
use rustc_span::symbol::{kw, sym, Ident};
|
use rustc_span::symbol::{kw, sym, Ident};
|
||||||
use rustc_span::{BytePos, Span, DUMMY_SP};
|
use rustc_span::{BytePos, Span, DUMMY_SP};
|
||||||
use rustc_target::abi::FieldIdx;
|
use rustc_target::abi::FieldIdx;
|
||||||
use rustc_trait_selection::traits::{ObligationCause, Pattern};
|
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
|
||||||
use ty::VariantDef;
|
use ty::VariantDef;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
@ -88,8 +88,11 @@ struct PatInfo<'tcx, 'a> {
|
||||||
|
|
||||||
impl<'tcx> FnCtxt<'_, 'tcx> {
|
impl<'tcx> FnCtxt<'_, 'tcx> {
|
||||||
fn pattern_cause(&self, ti: TopInfo<'tcx>, cause_span: Span) -> ObligationCause<'tcx> {
|
fn pattern_cause(&self, ti: TopInfo<'tcx>, cause_span: Span) -> ObligationCause<'tcx> {
|
||||||
let code =
|
let code = ObligationCauseCode::Pattern {
|
||||||
Pattern { span: ti.span, root_ty: ti.expected, origin_expr: ti.origin_expr.is_some() };
|
span: ti.span,
|
||||||
|
root_ty: ti.expected,
|
||||||
|
origin_expr: ti.origin_expr.is_some(),
|
||||||
|
};
|
||||||
self.cause(cause_span, code)
|
self.cause(cause_span, code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -883,8 +883,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
err.help("...or use `match` instead of `let...else`");
|
err.help("...or use `match` instead of `let...else`");
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if let ObligationCauseCode::BindingObligation(_, span)
|
if let ObligationCauseCode::SpannedWhereClause(_, span)
|
||||||
| ObligationCauseCode::ExprBindingObligation(_, span, ..) =
|
| ObligationCauseCode::SpannedWhereClauseInExpr(_, span, ..) =
|
||||||
cause.code().peel_derives()
|
cause.code().peel_derives()
|
||||||
&& let TypeError::RegionsPlaceholderMismatch = terr
|
&& let TypeError::RegionsPlaceholderMismatch = terr
|
||||||
{
|
{
|
||||||
|
@ -2012,7 +2012,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
trace: &TypeTrace<'tcx>,
|
trace: &TypeTrace<'tcx>,
|
||||||
terr: TypeError<'tcx>,
|
terr: TypeError<'tcx>,
|
||||||
) -> Vec<TypeErrorAdditionalDiags> {
|
) -> Vec<TypeErrorAdditionalDiags> {
|
||||||
use crate::traits::ObligationCauseCode::{BlockTailExpression, MatchExpressionArm};
|
|
||||||
let mut suggestions = Vec::new();
|
let mut suggestions = Vec::new();
|
||||||
let span = trace.cause.span();
|
let span = trace.cause.span();
|
||||||
let values = self.resolve_vars_if_possible(trace.values);
|
let values = self.resolve_vars_if_possible(trace.values);
|
||||||
|
@ -2079,8 +2078,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let code = trace.cause.code();
|
let code = trace.cause.code();
|
||||||
if let &(MatchExpressionArm(box MatchExpressionArmCause { source, .. })
|
if let &(ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
|
||||||
| BlockTailExpression(.., source)) = code
|
source,
|
||||||
|
..
|
||||||
|
})
|
||||||
|
| ObligationCauseCode::BlockTailExpression(.., source)) = code
|
||||||
&& let hir::MatchSource::TryDesugar(_) = source
|
&& let hir::MatchSource::TryDesugar(_) = source
|
||||||
&& let Some((expected_ty, found_ty, _)) = self.values_str(trace.values)
|
&& let Some((expected_ty, found_ty, _)) = self.values_str(trace.values)
|
||||||
{
|
{
|
||||||
|
@ -2773,19 +2775,17 @@ pub enum FailureCode {
|
||||||
#[extension(pub trait ObligationCauseExt<'tcx>)]
|
#[extension(pub trait ObligationCauseExt<'tcx>)]
|
||||||
impl<'tcx> ObligationCause<'tcx> {
|
impl<'tcx> ObligationCause<'tcx> {
|
||||||
fn as_failure_code(&self, terr: TypeError<'tcx>) -> FailureCode {
|
fn as_failure_code(&self, terr: TypeError<'tcx>) -> FailureCode {
|
||||||
use self::FailureCode::*;
|
|
||||||
use crate::traits::ObligationCauseCode::*;
|
|
||||||
match self.code() {
|
match self.code() {
|
||||||
IfExpressionWithNoElse => Error0317,
|
ObligationCauseCode::IfExpressionWithNoElse => FailureCode::Error0317,
|
||||||
MainFunctionType => Error0580,
|
ObligationCauseCode::MainFunctionType => FailureCode::Error0580,
|
||||||
CompareImplItemObligation { .. }
|
ObligationCauseCode::CompareImplItem { .. }
|
||||||
| MatchExpressionArm(_)
|
| ObligationCauseCode::MatchExpressionArm(_)
|
||||||
| IfExpression { .. }
|
| ObligationCauseCode::IfExpression { .. }
|
||||||
| LetElse
|
| ObligationCauseCode::LetElse
|
||||||
| StartFunctionType
|
| ObligationCauseCode::StartFunctionType
|
||||||
| LangFunctionType(_)
|
| ObligationCauseCode::LangFunctionType(_)
|
||||||
| IntrinsicType
|
| ObligationCauseCode::IntrinsicType
|
||||||
| MethodReceiver => Error0308,
|
| ObligationCauseCode::MethodReceiver => FailureCode::Error0308,
|
||||||
|
|
||||||
// In the case where we have no more specific thing to
|
// In the case where we have no more specific thing to
|
||||||
// say, also take a look at the error code, maybe we can
|
// say, also take a look at the error code, maybe we can
|
||||||
|
@ -2794,10 +2794,10 @@ impl<'tcx> ObligationCause<'tcx> {
|
||||||
TypeError::CyclicTy(ty)
|
TypeError::CyclicTy(ty)
|
||||||
if ty.is_closure() || ty.is_coroutine() || ty.is_coroutine_closure() =>
|
if ty.is_closure() || ty.is_coroutine() || ty.is_coroutine_closure() =>
|
||||||
{
|
{
|
||||||
Error0644
|
FailureCode::Error0644
|
||||||
}
|
}
|
||||||
TypeError::IntrinsicCast => Error0308,
|
TypeError::IntrinsicCast => FailureCode::Error0308,
|
||||||
_ => Error0308,
|
_ => FailureCode::Error0308,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2807,36 +2807,51 @@ impl<'tcx> ObligationCause<'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
subdiags: Vec<TypeErrorAdditionalDiags>,
|
subdiags: Vec<TypeErrorAdditionalDiags>,
|
||||||
) -> ObligationCauseFailureCode {
|
) -> ObligationCauseFailureCode {
|
||||||
use crate::traits::ObligationCauseCode::*;
|
|
||||||
match self.code() {
|
match self.code() {
|
||||||
CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => {
|
||||||
ObligationCauseFailureCode::MethodCompat { span, subdiags }
|
ObligationCauseFailureCode::MethodCompat { span, subdiags }
|
||||||
}
|
}
|
||||||
CompareImplItemObligation { kind: ty::AssocKind::Type, .. } => {
|
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => {
|
||||||
ObligationCauseFailureCode::TypeCompat { span, subdiags }
|
ObligationCauseFailureCode::TypeCompat { span, subdiags }
|
||||||
}
|
}
|
||||||
CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => {
|
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
|
||||||
ObligationCauseFailureCode::ConstCompat { span, subdiags }
|
ObligationCauseFailureCode::ConstCompat { span, subdiags }
|
||||||
}
|
}
|
||||||
BlockTailExpression(.., hir::MatchSource::TryDesugar(_)) => {
|
ObligationCauseCode::BlockTailExpression(.., hir::MatchSource::TryDesugar(_)) => {
|
||||||
ObligationCauseFailureCode::TryCompat { span, subdiags }
|
ObligationCauseFailureCode::TryCompat { span, subdiags }
|
||||||
}
|
}
|
||||||
MatchExpressionArm(box MatchExpressionArmCause { source, .. }) => match source {
|
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
|
||||||
|
source, ..
|
||||||
|
}) => match source {
|
||||||
hir::MatchSource::TryDesugar(_) => {
|
hir::MatchSource::TryDesugar(_) => {
|
||||||
ObligationCauseFailureCode::TryCompat { span, subdiags }
|
ObligationCauseFailureCode::TryCompat { span, subdiags }
|
||||||
}
|
}
|
||||||
_ => ObligationCauseFailureCode::MatchCompat { span, subdiags },
|
_ => ObligationCauseFailureCode::MatchCompat { span, subdiags },
|
||||||
},
|
},
|
||||||
IfExpression { .. } => ObligationCauseFailureCode::IfElseDifferent { span, subdiags },
|
ObligationCauseCode::IfExpression { .. } => {
|
||||||
IfExpressionWithNoElse => ObligationCauseFailureCode::NoElse { span },
|
ObligationCauseFailureCode::IfElseDifferent { span, subdiags }
|
||||||
LetElse => ObligationCauseFailureCode::NoDiverge { span, subdiags },
|
}
|
||||||
MainFunctionType => ObligationCauseFailureCode::FnMainCorrectType { span },
|
ObligationCauseCode::IfExpressionWithNoElse => {
|
||||||
StartFunctionType => ObligationCauseFailureCode::FnStartCorrectType { span, subdiags },
|
ObligationCauseFailureCode::NoElse { span }
|
||||||
&LangFunctionType(lang_item_name) => {
|
}
|
||||||
|
ObligationCauseCode::LetElse => {
|
||||||
|
ObligationCauseFailureCode::NoDiverge { span, subdiags }
|
||||||
|
}
|
||||||
|
ObligationCauseCode::MainFunctionType => {
|
||||||
|
ObligationCauseFailureCode::FnMainCorrectType { span }
|
||||||
|
}
|
||||||
|
ObligationCauseCode::StartFunctionType => {
|
||||||
|
ObligationCauseFailureCode::FnStartCorrectType { span, subdiags }
|
||||||
|
}
|
||||||
|
&ObligationCauseCode::LangFunctionType(lang_item_name) => {
|
||||||
ObligationCauseFailureCode::FnLangCorrectType { span, subdiags, lang_item_name }
|
ObligationCauseFailureCode::FnLangCorrectType { span, subdiags, lang_item_name }
|
||||||
}
|
}
|
||||||
IntrinsicType => ObligationCauseFailureCode::IntrinsicCorrectType { span, subdiags },
|
ObligationCauseCode::IntrinsicType => {
|
||||||
MethodReceiver => ObligationCauseFailureCode::MethodCorrectType { span, subdiags },
|
ObligationCauseFailureCode::IntrinsicCorrectType { span, subdiags }
|
||||||
|
}
|
||||||
|
ObligationCauseCode::MethodReceiver => {
|
||||||
|
ObligationCauseFailureCode::MethodCorrectType { span, subdiags }
|
||||||
|
}
|
||||||
|
|
||||||
// In the case where we have no more specific thing to
|
// In the case where we have no more specific thing to
|
||||||
// say, also take a look at the error code, maybe we can
|
// say, also take a look at the error code, maybe we can
|
||||||
|
@ -2856,22 +2871,21 @@ impl<'tcx> ObligationCause<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_requirement_str(&self) -> &'static str {
|
fn as_requirement_str(&self) -> &'static str {
|
||||||
use crate::traits::ObligationCauseCode::*;
|
|
||||||
match self.code() {
|
match self.code() {
|
||||||
CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => {
|
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => {
|
||||||
"method type is compatible with trait"
|
"method type is compatible with trait"
|
||||||
}
|
}
|
||||||
CompareImplItemObligation { kind: ty::AssocKind::Type, .. } => {
|
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => {
|
||||||
"associated type is compatible with trait"
|
"associated type is compatible with trait"
|
||||||
}
|
}
|
||||||
CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => {
|
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
|
||||||
"const is compatible with trait"
|
"const is compatible with trait"
|
||||||
}
|
}
|
||||||
MainFunctionType => "`main` function has the correct type",
|
ObligationCauseCode::MainFunctionType => "`main` function has the correct type",
|
||||||
StartFunctionType => "`#[start]` function has the correct type",
|
ObligationCauseCode::StartFunctionType => "`#[start]` function has the correct type",
|
||||||
LangFunctionType(_) => "lang item function has the correct type",
|
ObligationCauseCode::LangFunctionType(_) => "lang item function has the correct type",
|
||||||
IntrinsicType => "intrinsic has the correct type",
|
ObligationCauseCode::IntrinsicType => "intrinsic has the correct type",
|
||||||
MethodReceiver => "method receiver has the correct type",
|
ObligationCauseCode::MethodReceiver => "method receiver has the correct type",
|
||||||
_ => "types are compatible",
|
_ => "types are compatible",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2882,16 +2896,17 @@ pub struct ObligationCauseAsDiagArg<'tcx>(pub ObligationCause<'tcx>);
|
||||||
|
|
||||||
impl IntoDiagArg for ObligationCauseAsDiagArg<'_> {
|
impl IntoDiagArg for ObligationCauseAsDiagArg<'_> {
|
||||||
fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
|
fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
|
||||||
use crate::traits::ObligationCauseCode::*;
|
|
||||||
let kind = match self.0.code() {
|
let kind = match self.0.code() {
|
||||||
CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => "method_compat",
|
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => "method_compat",
|
||||||
CompareImplItemObligation { kind: ty::AssocKind::Type, .. } => "type_compat",
|
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => "type_compat",
|
||||||
CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => "const_compat",
|
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
|
||||||
MainFunctionType => "fn_main_correct_type",
|
"const_compat"
|
||||||
StartFunctionType => "fn_start_correct_type",
|
}
|
||||||
LangFunctionType(_) => "fn_lang_correct_type",
|
ObligationCauseCode::MainFunctionType => "fn_main_correct_type",
|
||||||
IntrinsicType => "intrinsic_correct_type",
|
ObligationCauseCode::StartFunctionType => "fn_start_correct_type",
|
||||||
MethodReceiver => "method_correct_type",
|
ObligationCauseCode::LangFunctionType(_) => "fn_lang_correct_type",
|
||||||
|
ObligationCauseCode::IntrinsicType => "intrinsic_correct_type",
|
||||||
|
ObligationCauseCode::MethodReceiver => "method_correct_type",
|
||||||
_ => "other",
|
_ => "other",
|
||||||
}
|
}
|
||||||
.into();
|
.into();
|
||||||
|
|
|
@ -32,14 +32,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
// If we added a "points at argument expression" obligation, we remove it here, we care
|
// If we added a "points at argument expression" obligation, we remove it here, we care
|
||||||
// about the original obligation only.
|
// about the original obligation only.
|
||||||
let code = match cause.code() {
|
let code = match cause.code() {
|
||||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => &*parent_code,
|
ObligationCauseCode::FunctionArg { parent_code, .. } => &*parent_code,
|
||||||
code => code,
|
code => code,
|
||||||
};
|
};
|
||||||
let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else {
|
let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
let (ObligationCauseCode::BindingObligation(_, binding_span)
|
let (ObligationCauseCode::SpannedWhereClause(_, binding_span)
|
||||||
| ObligationCauseCode::ExprBindingObligation(_, binding_span, ..)) = *parent.code()
|
| ObligationCauseCode::SpannedWhereClauseInExpr(_, binding_span, ..)) = *parent.code()
|
||||||
else {
|
else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
|
@ -240,8 +240,8 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||||
let span = cause.span();
|
let span = cause.span();
|
||||||
|
|
||||||
let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) =
|
let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) =
|
||||||
if let ObligationCauseCode::ItemObligation(def_id)
|
if let ObligationCauseCode::WhereClause(def_id)
|
||||||
| ObligationCauseCode::ExprItemObligation(def_id, ..) = *cause.code()
|
| ObligationCauseCode::WhereClauseInExpr(def_id, ..) = *cause.code()
|
||||||
{
|
{
|
||||||
(
|
(
|
||||||
true,
|
true,
|
||||||
|
|
|
@ -214,8 +214,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
_ => cause.code(),
|
_ => cause.code(),
|
||||||
}
|
}
|
||||||
&& let (
|
&& let (
|
||||||
&ObligationCauseCode::ItemObligation(item_def_id)
|
&ObligationCauseCode::WhereClause(item_def_id)
|
||||||
| &ObligationCauseCode::ExprItemObligation(item_def_id, ..),
|
| &ObligationCauseCode::WhereClauseInExpr(item_def_id, ..),
|
||||||
None,
|
None,
|
||||||
) = (code, override_error_code)
|
) = (code, override_error_code)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,13 +4,13 @@ use crate::errors::{ConsiderBorrowingParamHelp, RelationshipHelp, TraitImplDiff}
|
||||||
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
||||||
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||||
use crate::infer::{Subtype, ValuePairs};
|
use crate::infer::{Subtype, ValuePairs};
|
||||||
use crate::traits::ObligationCauseCode::CompareImplItemObligation;
|
|
||||||
use rustc_errors::ErrorGuaranteed;
|
use rustc_errors::ErrorGuaranteed;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::Res;
|
use rustc_hir::def::Res;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
|
use rustc_middle::traits::ObligationCauseCode;
|
||||||
use rustc_middle::ty::error::ExpectedFound;
|
use rustc_middle::ty::error::ExpectedFound;
|
||||||
use rustc_middle::ty::print::RegionHighlightMode;
|
use rustc_middle::ty::print::RegionHighlightMode;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
|
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
|
||||||
|
@ -31,7 +31,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
_,
|
_,
|
||||||
) = error.clone()
|
) = error.clone()
|
||||||
&& let (Subtype(sup_trace), Subtype(sub_trace)) = (&sup_origin, &sub_origin)
|
&& let (Subtype(sup_trace), Subtype(sub_trace)) = (&sup_origin, &sub_origin)
|
||||||
&& let CompareImplItemObligation { trait_item_def_id, .. } = sub_trace.cause.code()
|
&& let ObligationCauseCode::CompareImplItem { trait_item_def_id, .. } =
|
||||||
|
sub_trace.cause.code()
|
||||||
&& sub_trace.values == sup_trace.values
|
&& sub_trace.values == sup_trace.values
|
||||||
&& let ValuePairs::PolySigs(ExpectedFound { expected, found }) = sub_trace.values
|
&& let ValuePairs::PolySigs(ExpectedFound { expected, found }) = sub_trace.values
|
||||||
{
|
{
|
||||||
|
|
|
@ -357,13 +357,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
infer::Subtype(box ref trace)
|
infer::Subtype(box ref trace)
|
||||||
if matches!(
|
if matches!(
|
||||||
&trace.cause.code().peel_derives(),
|
&trace.cause.code().peel_derives(),
|
||||||
ObligationCauseCode::BindingObligation(..)
|
ObligationCauseCode::SpannedWhereClause(..)
|
||||||
| ObligationCauseCode::ExprBindingObligation(..)
|
| ObligationCauseCode::SpannedWhereClauseInExpr(..)
|
||||||
) =>
|
) =>
|
||||||
{
|
{
|
||||||
// Hack to get around the borrow checker because trace.cause has an `Rc`.
|
// Hack to get around the borrow checker because trace.cause has an `Rc`.
|
||||||
if let ObligationCauseCode::BindingObligation(_, span)
|
if let ObligationCauseCode::SpannedWhereClause(_, span)
|
||||||
| ObligationCauseCode::ExprBindingObligation(_, span, ..) =
|
| ObligationCauseCode::SpannedWhereClauseInExpr(_, span, ..) =
|
||||||
&trace.cause.code().peel_derives()
|
&trace.cause.code().peel_derives()
|
||||||
{
|
{
|
||||||
let span = *span;
|
let span = *span;
|
||||||
|
@ -371,7 +371,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
.with_span_note(span, "the lifetime requirement is introduced here")
|
.with_span_note(span, "the lifetime requirement is introduced here")
|
||||||
} else {
|
} else {
|
||||||
unreachable!(
|
unreachable!(
|
||||||
"control flow ensures we have a `BindingObligation` or `ExprBindingObligation` here..."
|
"control flow ensures we have a `BindingObligation` or `SpannedWhereClauseInExpr` here..."
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -629,8 +629,7 @@ impl<T> Trait<T> for X {
|
||||||
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }),
|
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
let impl_comparison =
|
let impl_comparison = matches!(cause_code, ObligationCauseCode::CompareImplItem { .. });
|
||||||
matches!(cause_code, ObligationCauseCode::CompareImplItemObligation { .. });
|
|
||||||
let assoc = tcx.associated_item(proj_ty.def_id);
|
let assoc = tcx.associated_item(proj_ty.def_id);
|
||||||
if impl_comparison {
|
if impl_comparison {
|
||||||
// We do not want to suggest calling functions when the reason of the
|
// We do not want to suggest calling functions when the reason of the
|
||||||
|
|
|
@ -167,7 +167,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
exp_span, exp_found.expected, exp_found.found,
|
exp_span, exp_found.expected, exp_found.found,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let ObligationCauseCode::CompareImplItemObligation { .. } = cause.code() {
|
if let ObligationCauseCode::CompareImplItem { .. } = cause.code() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1876,7 +1876,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
|
||||||
SubregionOrigin::ReferenceOutlivesReferent(ref_type, cause.span)
|
SubregionOrigin::ReferenceOutlivesReferent(ref_type, cause.span)
|
||||||
}
|
}
|
||||||
|
|
||||||
traits::ObligationCauseCode::CompareImplItemObligation {
|
traits::ObligationCauseCode::CompareImplItem {
|
||||||
impl_item_def_id,
|
impl_item_def_id,
|
||||||
trait_item_def_id,
|
trait_item_def_id,
|
||||||
kind: _,
|
kind: _,
|
||||||
|
|
|
@ -103,8 +103,8 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
cause.span,
|
cause.span,
|
||||||
sup_type,
|
sup_type,
|
||||||
match cause.code().peel_derives() {
|
match cause.code().peel_derives() {
|
||||||
ObligationCauseCode::BindingObligation(_, span)
|
ObligationCauseCode::SpannedWhereClause(_, span)
|
||||||
| ObligationCauseCode::ExprBindingObligation(_, span, ..) => Some(*span),
|
| ObligationCauseCode::SpannedWhereClauseInExpr(_, span, ..) => Some(*span),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl<'tcx> PredicateObligation<'tcx> {
|
||||||
impl<'tcx> PolyTraitObligation<'tcx> {
|
impl<'tcx> PolyTraitObligation<'tcx> {
|
||||||
pub fn derived_cause(
|
pub fn derived_cause(
|
||||||
&self,
|
&self,
|
||||||
variant: impl FnOnce(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>,
|
variant: impl FnOnce(DerivedCause<'tcx>) -> ObligationCauseCode<'tcx>,
|
||||||
) -> ObligationCause<'tcx> {
|
) -> ObligationCause<'tcx> {
|
||||||
self.cause.clone().derived_cause(self.predicate, variant)
|
self.cause.clone().derived_cause(self.predicate, variant)
|
||||||
}
|
}
|
||||||
|
@ -138,10 +138,10 @@ pub enum FulfillmentErrorCode<'tcx> {
|
||||||
/// Inherently impossible to fulfill; this trait is implemented if and only
|
/// Inherently impossible to fulfill; this trait is implemented if and only
|
||||||
/// if it is already implemented.
|
/// if it is already implemented.
|
||||||
Cycle(Vec<PredicateObligation<'tcx>>),
|
Cycle(Vec<PredicateObligation<'tcx>>),
|
||||||
SelectionError(SelectionError<'tcx>),
|
Select(SelectionError<'tcx>),
|
||||||
ProjectionError(MismatchedProjectionTypes<'tcx>),
|
Project(MismatchedProjectionTypes<'tcx>),
|
||||||
SubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
|
Subtype(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
|
||||||
ConstEquateError(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
|
ConstEquate(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
|
||||||
Ambiguity {
|
Ambiguity {
|
||||||
/// Overflow is only `Some(suggest_recursion_limit)` when using the next generation
|
/// Overflow is only `Some(suggest_recursion_limit)` when using the next generation
|
||||||
/// trait solver `-Znext-solver`. With the old solver overflow is eagerly handled by
|
/// trait solver `-Znext-solver`. With the old solver overflow is eagerly handled by
|
||||||
|
@ -209,10 +209,10 @@ impl<'tcx> FulfillmentError<'tcx> {
|
||||||
|
|
||||||
pub fn is_true_error(&self) -> bool {
|
pub fn is_true_error(&self) -> bool {
|
||||||
match self.code {
|
match self.code {
|
||||||
FulfillmentErrorCode::SelectionError(_)
|
FulfillmentErrorCode::Select(_)
|
||||||
| FulfillmentErrorCode::ProjectionError(_)
|
| FulfillmentErrorCode::Project(_)
|
||||||
| FulfillmentErrorCode::SubtypeError(_, _)
|
| FulfillmentErrorCode::Subtype(_, _)
|
||||||
| FulfillmentErrorCode::ConstEquateError(_, _) => true,
|
| FulfillmentErrorCode::ConstEquate(_, _) => true,
|
||||||
FulfillmentErrorCode::Cycle(_) | FulfillmentErrorCode::Ambiguity { overflow: _ } => {
|
FulfillmentErrorCode::Cycle(_) | FulfillmentErrorCode::Ambiguity { overflow: _ } => {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,12 +39,12 @@ impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
use traits::FulfillmentErrorCode::*;
|
use traits::FulfillmentErrorCode::*;
|
||||||
match *self {
|
match *self {
|
||||||
SelectionError(ref e) => write!(f, "{e:?}"),
|
Select(ref e) => write!(f, "{e:?}"),
|
||||||
ProjectionError(ref e) => write!(f, "{e:?}"),
|
Project(ref e) => write!(f, "{e:?}"),
|
||||||
SubtypeError(ref a, ref b) => {
|
Subtype(ref a, ref b) => {
|
||||||
write!(f, "CodeSubtypeError({a:?}, {b:?})")
|
write!(f, "CodeSubtypeError({a:?}, {b:?})")
|
||||||
}
|
}
|
||||||
ConstEquateError(ref a, ref b) => {
|
ConstEquate(ref a, ref b) => {
|
||||||
write!(f, "CodeConstEquateError({a:?}, {b:?})")
|
write!(f, "CodeConstEquateError({a:?}, {b:?})")
|
||||||
}
|
}
|
||||||
Ambiguity { overflow: None } => write!(f, "Ambiguity"),
|
Ambiguity { overflow: None } => write!(f, "Ambiguity"),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use smallvec::smallvec;
|
use smallvec::smallvec;
|
||||||
|
|
||||||
use crate::infer::outlives::components::{push_outlives_components, Component};
|
use crate::infer::outlives::components::{push_outlives_components, Component};
|
||||||
use crate::traits::{self, Obligation, PredicateObligation};
|
use crate::traits::{self, Obligation, ObligationCauseCode, PredicateObligation};
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
|
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
|
||||||
use rustc_span::symbol::Ident;
|
use rustc_span::symbol::Ident;
|
||||||
|
@ -129,7 +129,7 @@ impl<'tcx> Elaboratable<'tcx> for PredicateObligation<'tcx> {
|
||||||
index: usize,
|
index: usize,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let cause = self.cause.clone().derived_cause(parent_trait_pred, |derived| {
|
let cause = self.cause.clone().derived_cause(parent_trait_pred, |derived| {
|
||||||
traits::ImplDerivedObligation(Box::new(traits::ImplDerivedObligationCause {
|
ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedCause {
|
||||||
derived,
|
derived,
|
||||||
impl_or_alias_def_id: parent_trait_pred.def_id(),
|
impl_or_alias_def_id: parent_trait_pred.def_id(),
|
||||||
impl_def_predicate_index: Some(index),
|
impl_def_predicate_index: Some(index),
|
||||||
|
|
|
@ -150,11 +150,8 @@ fn suggest_question_mark<'tcx>(
|
||||||
let ocx = ObligationCtxt::new(&infcx);
|
let ocx = ObligationCtxt::new(&infcx);
|
||||||
|
|
||||||
let body_def_id = cx.tcx.hir().body_owner_def_id(body_id);
|
let body_def_id = cx.tcx.hir().body_owner_def_id(body_id);
|
||||||
let cause = ObligationCause::new(
|
let cause =
|
||||||
span,
|
ObligationCause::new(span, body_def_id, rustc_infer::traits::ObligationCauseCode::Misc);
|
||||||
body_def_id,
|
|
||||||
rustc_infer::traits::ObligationCauseCode::MiscObligation,
|
|
||||||
);
|
|
||||||
|
|
||||||
ocx.register_bound(
|
ocx.register_bound(
|
||||||
cause,
|
cause,
|
||||||
|
|
|
@ -33,8 +33,6 @@ use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
|
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
|
||||||
|
|
||||||
pub use self::ObligationCauseCode::*;
|
|
||||||
|
|
||||||
/// Depending on the stage of compilation, we want projection to be
|
/// Depending on the stage of compilation, we want projection to be
|
||||||
/// more or less conservative.
|
/// more or less conservative.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable, Encodable, Decodable)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable, Encodable, Decodable)]
|
||||||
|
@ -129,7 +127,7 @@ impl<'tcx> ObligationCause<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn misc(span: Span, body_id: LocalDefId) -> ObligationCause<'tcx> {
|
pub fn misc(span: Span, body_id: LocalDefId) -> ObligationCause<'tcx> {
|
||||||
ObligationCause::new(span, body_id, MiscObligation)
|
ObligationCause::new(span, body_id, ObligationCauseCode::Misc)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -167,7 +165,7 @@ impl<'tcx> ObligationCause<'tcx> {
|
||||||
pub fn derived_cause(
|
pub fn derived_cause(
|
||||||
mut self,
|
mut self,
|
||||||
parent_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
parent_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
variant: impl FnOnce(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>,
|
variant: impl FnOnce(DerivedCause<'tcx>) -> ObligationCauseCode<'tcx>,
|
||||||
) -> ObligationCause<'tcx> {
|
) -> ObligationCause<'tcx> {
|
||||||
/*!
|
/*!
|
||||||
* Creates a cause for obligations that are derived from
|
* Creates a cause for obligations that are derived from
|
||||||
|
@ -182,15 +180,14 @@ impl<'tcx> ObligationCause<'tcx> {
|
||||||
// NOTE(flaper87): As of now, it keeps track of the whole error
|
// NOTE(flaper87): As of now, it keeps track of the whole error
|
||||||
// chain. Ideally, we should have a way to configure this either
|
// chain. Ideally, we should have a way to configure this either
|
||||||
// by using -Z verbose-internals or just a CLI argument.
|
// by using -Z verbose-internals or just a CLI argument.
|
||||||
self.code =
|
self.code = variant(DerivedCause { parent_trait_pred, parent_code: self.code }).into();
|
||||||
variant(DerivedObligationCause { parent_trait_pred, parent_code: self.code }).into();
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_constraint_category(&self) -> ConstraintCategory<'tcx> {
|
pub fn to_constraint_category(&self) -> ConstraintCategory<'tcx> {
|
||||||
match self.code() {
|
match self.code() {
|
||||||
MatchImpl(cause, _) => cause.to_constraint_category(),
|
ObligationCauseCode::MatchImpl(cause, _) => cause.to_constraint_category(),
|
||||||
AscribeUserTypeProvePredicate(predicate_span) => {
|
ObligationCauseCode::AscribeUserTypeProvePredicate(predicate_span) => {
|
||||||
ConstraintCategory::Predicate(*predicate_span)
|
ConstraintCategory::Predicate(*predicate_span)
|
||||||
}
|
}
|
||||||
_ => ConstraintCategory::BoringNoLocation,
|
_ => ConstraintCategory::BoringNoLocation,
|
||||||
|
@ -209,7 +206,7 @@ pub struct UnifyReceiverContext<'tcx> {
|
||||||
#[derive(Clone, PartialEq, Eq, Default, HashStable)]
|
#[derive(Clone, PartialEq, Eq, Default, HashStable)]
|
||||||
#[derive(TypeVisitable, TypeFoldable, TyEncodable, TyDecodable)]
|
#[derive(TypeVisitable, TypeFoldable, TyEncodable, TyDecodable)]
|
||||||
pub struct InternedObligationCauseCode<'tcx> {
|
pub struct InternedObligationCauseCode<'tcx> {
|
||||||
/// `None` for `ObligationCauseCode::MiscObligation` (a common case, occurs ~60% of
|
/// `None` for `ObligationCauseCode::Misc` (a common case, occurs ~60% of
|
||||||
/// the time). `Some` otherwise.
|
/// the time). `Some` otherwise.
|
||||||
code: Option<Lrc<ObligationCauseCode<'tcx>>>,
|
code: Option<Lrc<ObligationCauseCode<'tcx>>>,
|
||||||
}
|
}
|
||||||
|
@ -225,11 +222,7 @@ impl<'tcx> ObligationCauseCode<'tcx> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn into(self) -> InternedObligationCauseCode<'tcx> {
|
fn into(self) -> InternedObligationCauseCode<'tcx> {
|
||||||
InternedObligationCauseCode {
|
InternedObligationCauseCode {
|
||||||
code: if let ObligationCauseCode::MiscObligation = self {
|
code: if let ObligationCauseCode::Misc = self { None } else { Some(Lrc::new(self)) },
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(Lrc::new(self))
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,7 +231,7 @@ impl<'tcx> std::ops::Deref for InternedObligationCauseCode<'tcx> {
|
||||||
type Target = ObligationCauseCode<'tcx>;
|
type Target = ObligationCauseCode<'tcx>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
self.code.as_deref().unwrap_or(&ObligationCauseCode::MiscObligation)
|
self.code.as_deref().unwrap_or(&ObligationCauseCode::Misc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +239,7 @@ impl<'tcx> std::ops::Deref for InternedObligationCauseCode<'tcx> {
|
||||||
#[derive(TypeVisitable, TypeFoldable)]
|
#[derive(TypeVisitable, TypeFoldable)]
|
||||||
pub enum ObligationCauseCode<'tcx> {
|
pub enum ObligationCauseCode<'tcx> {
|
||||||
/// Not well classified or should be obvious from the span.
|
/// Not well classified or should be obvious from the span.
|
||||||
MiscObligation,
|
Misc,
|
||||||
|
|
||||||
/// A slice or array is WF only if `T: Sized`.
|
/// A slice or array is WF only if `T: Sized`.
|
||||||
SliceOrArrayElem,
|
SliceOrArrayElem,
|
||||||
|
@ -256,20 +249,20 @@ pub enum ObligationCauseCode<'tcx> {
|
||||||
|
|
||||||
/// Must satisfy all of the where-clause predicates of the
|
/// Must satisfy all of the where-clause predicates of the
|
||||||
/// given item.
|
/// given item.
|
||||||
ItemObligation(DefId),
|
WhereClause(DefId),
|
||||||
|
|
||||||
/// Like `ItemObligation`, but carries the span of the
|
/// Like `WhereClause`, but carries the span of the
|
||||||
/// predicate when it can be identified.
|
/// predicate when it can be identified.
|
||||||
BindingObligation(DefId, Span),
|
SpannedWhereClause(DefId, Span),
|
||||||
|
|
||||||
/// Like `ItemObligation`, but carries the `HirId` of the
|
/// Like `WhereClause`, but carries the `HirId` of the
|
||||||
/// expression that caused the obligation, and the `usize`
|
/// expression that caused the obligation, and the `usize`
|
||||||
/// indicates exactly which predicate it is in the list of
|
/// indicates exactly which predicate it is in the list of
|
||||||
/// instantiated predicates.
|
/// instantiated predicates.
|
||||||
ExprItemObligation(DefId, HirId, usize),
|
WhereClauseInExpr(DefId, HirId, usize),
|
||||||
|
|
||||||
/// Combines `ExprItemObligation` and `BindingObligation`.
|
/// Combines `SpannedWhereClause` and `WhereClauseInExpr`.
|
||||||
ExprBindingObligation(DefId, Span, HirId, usize),
|
SpannedWhereClauseInExpr(DefId, Span, HirId, usize),
|
||||||
|
|
||||||
/// A type like `&'a T` is WF only if `T: 'a`.
|
/// A type like `&'a T` is WF only if `T: 'a`.
|
||||||
ReferenceOutlivesReferent(Ty<'tcx>),
|
ReferenceOutlivesReferent(Ty<'tcx>),
|
||||||
|
@ -333,16 +326,18 @@ pub enum ObligationCauseCode<'tcx> {
|
||||||
|
|
||||||
/// Derived obligation (i.e. theoretical `where` clause) on a built-in
|
/// Derived obligation (i.e. theoretical `where` clause) on a built-in
|
||||||
/// implementation like `Copy` or `Sized`.
|
/// implementation like `Copy` or `Sized`.
|
||||||
BuiltinDerivedObligation(DerivedObligationCause<'tcx>),
|
BuiltinDerived(DerivedCause<'tcx>),
|
||||||
|
|
||||||
/// Derived obligation (i.e. `where` clause) on an user-provided impl
|
/// Derived obligation (i.e. `where` clause) on an user-provided impl
|
||||||
/// or a trait alias.
|
/// or a trait alias.
|
||||||
ImplDerivedObligation(Box<ImplDerivedObligationCause<'tcx>>),
|
ImplDerived(Box<ImplDerivedCause<'tcx>>),
|
||||||
|
|
||||||
/// Derived obligation for WF goals.
|
/// Derived obligation for WF goals.
|
||||||
WellFormedDerivedObligation(DerivedObligationCause<'tcx>),
|
WellFormedDerived(DerivedCause<'tcx>),
|
||||||
|
|
||||||
FunctionArgumentObligation {
|
/// Derived obligation refined to point at a specific argument in
|
||||||
|
/// a call or method expression.
|
||||||
|
FunctionArg {
|
||||||
/// The node of the relevant argument in the function call.
|
/// The node of the relevant argument in the function call.
|
||||||
arg_hir_id: HirId,
|
arg_hir_id: HirId,
|
||||||
/// The node of the function call.
|
/// The node of the function call.
|
||||||
|
@ -353,7 +348,7 @@ pub enum ObligationCauseCode<'tcx> {
|
||||||
|
|
||||||
/// Error derived when checking an impl item is compatible with
|
/// Error derived when checking an impl item is compatible with
|
||||||
/// its corresponding trait item's definition
|
/// its corresponding trait item's definition
|
||||||
CompareImplItemObligation {
|
CompareImplItem {
|
||||||
impl_item_def_id: LocalDefId,
|
impl_item_def_id: LocalDefId,
|
||||||
trait_item_def_id: DefId,
|
trait_item_def_id: DefId,
|
||||||
kind: ty::AssocKind,
|
kind: ty::AssocKind,
|
||||||
|
@ -432,8 +427,8 @@ pub enum ObligationCauseCode<'tcx> {
|
||||||
/// then it will be used to perform HIR-based wf checking
|
/// then it will be used to perform HIR-based wf checking
|
||||||
/// after an error occurs, in order to generate a more precise error span.
|
/// after an error occurs, in order to generate a more precise error span.
|
||||||
/// This is purely for diagnostic purposes - it is always
|
/// This is purely for diagnostic purposes - it is always
|
||||||
/// correct to use `MiscObligation` instead, or to specify
|
/// correct to use `Misc` instead, or to specify
|
||||||
/// `WellFormed(None)`
|
/// `WellFormed(None)`.
|
||||||
WellFormed(Option<WellFormedLoc>),
|
WellFormed(Option<WellFormedLoc>),
|
||||||
|
|
||||||
/// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching against.
|
/// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching against.
|
||||||
|
@ -501,8 +496,8 @@ pub enum WellFormedLoc {
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
|
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
|
||||||
#[derive(TypeVisitable, TypeFoldable)]
|
#[derive(TypeVisitable, TypeFoldable)]
|
||||||
pub struct ImplDerivedObligationCause<'tcx> {
|
pub struct ImplDerivedCause<'tcx> {
|
||||||
pub derived: DerivedObligationCause<'tcx>,
|
pub derived: DerivedCause<'tcx>,
|
||||||
/// The `DefId` of the `impl` that gave rise to the `derived` obligation.
|
/// The `DefId` of the `impl` that gave rise to the `derived` obligation.
|
||||||
/// If the `derived` obligation arose from a trait alias, which conceptually has a synthetic impl,
|
/// If the `derived` obligation arose from a trait alias, which conceptually has a synthetic impl,
|
||||||
/// then this will be the `DefId` of that trait alias. Care should therefore be taken to handle
|
/// then this will be the `DefId` of that trait alias. Care should therefore be taken to handle
|
||||||
|
@ -540,10 +535,10 @@ impl<'tcx> ObligationCauseCode<'tcx> {
|
||||||
|
|
||||||
pub fn parent(&self) -> Option<(&Self, Option<ty::PolyTraitPredicate<'tcx>>)> {
|
pub fn parent(&self) -> Option<(&Self, Option<ty::PolyTraitPredicate<'tcx>>)> {
|
||||||
match self {
|
match self {
|
||||||
FunctionArgumentObligation { parent_code, .. } => Some((parent_code, None)),
|
ObligationCauseCode::FunctionArg { parent_code, .. } => Some((parent_code, None)),
|
||||||
BuiltinDerivedObligation(derived)
|
ObligationCauseCode::BuiltinDerived(derived)
|
||||||
| WellFormedDerivedObligation(derived)
|
| ObligationCauseCode::WellFormedDerived(derived)
|
||||||
| ImplDerivedObligation(box ImplDerivedObligationCause { derived, .. }) => {
|
| ObligationCauseCode::ImplDerived(box ImplDerivedCause { derived, .. }) => {
|
||||||
Some((&derived.parent_code, Some(derived.parent_trait_pred)))
|
Some((&derived.parent_code, Some(derived.parent_trait_pred)))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -552,7 +547,7 @@ impl<'tcx> ObligationCauseCode<'tcx> {
|
||||||
|
|
||||||
pub fn peel_match_impls(&self) -> &Self {
|
pub fn peel_match_impls(&self) -> &Self {
|
||||||
match self {
|
match self {
|
||||||
MatchImpl(cause, _) => cause.code(),
|
ObligationCauseCode::MatchImpl(cause, _) => cause.code(),
|
||||||
_ => self,
|
_ => self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -598,7 +593,7 @@ pub struct IfExpressionCause<'tcx> {
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
|
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
|
||||||
#[derive(TypeVisitable, TypeFoldable)]
|
#[derive(TypeVisitable, TypeFoldable)]
|
||||||
pub struct DerivedObligationCause<'tcx> {
|
pub struct DerivedCause<'tcx> {
|
||||||
/// The trait predicate of the parent obligation that led to the
|
/// The trait predicate of the parent obligation that led to the
|
||||||
/// current obligation. Note that only trait obligations lead to
|
/// current obligation. Note that only trait obligations lead to
|
||||||
/// derived obligations, so we just store the trait predicate here
|
/// derived obligations, so we just store the trait predicate here
|
||||||
|
|
|
@ -7,7 +7,7 @@ use rustc_infer::traits::solve::inspect::ProbeKind;
|
||||||
use rustc_infer::traits::solve::{CandidateSource, GoalSource, MaybeCause};
|
use rustc_infer::traits::solve::{CandidateSource, GoalSource, MaybeCause};
|
||||||
use rustc_infer::traits::{
|
use rustc_infer::traits::{
|
||||||
self, FulfillmentError, FulfillmentErrorCode, MismatchedProjectionTypes, Obligation,
|
self, FulfillmentError, FulfillmentErrorCode, MismatchedProjectionTypes, Obligation,
|
||||||
ObligationCause, PredicateObligation, SelectionError, TraitEngine,
|
ObligationCause, ObligationCauseCode, PredicateObligation, SelectionError, TraitEngine,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
|
@ -203,39 +203,35 @@ fn fulfillment_error_for_no_solution<'tcx>(
|
||||||
|
|
||||||
let code = match obligation.predicate.kind().skip_binder() {
|
let code = match obligation.predicate.kind().skip_binder() {
|
||||||
ty::PredicateKind::Clause(ty::ClauseKind::Projection(_)) => {
|
ty::PredicateKind::Clause(ty::ClauseKind::Projection(_)) => {
|
||||||
FulfillmentErrorCode::ProjectionError(
|
FulfillmentErrorCode::Project(
|
||||||
// FIXME: This could be a `Sorts` if the term is a type
|
// FIXME: This could be a `Sorts` if the term is a type
|
||||||
MismatchedProjectionTypes { err: TypeError::Mismatch },
|
MismatchedProjectionTypes { err: TypeError::Mismatch },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ty::PredicateKind::NormalizesTo(..) => {
|
ty::PredicateKind::NormalizesTo(..) => {
|
||||||
FulfillmentErrorCode::ProjectionError(MismatchedProjectionTypes {
|
FulfillmentErrorCode::Project(MismatchedProjectionTypes { err: TypeError::Mismatch })
|
||||||
err: TypeError::Mismatch,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
ty::PredicateKind::AliasRelate(_, _, _) => {
|
ty::PredicateKind::AliasRelate(_, _, _) => {
|
||||||
FulfillmentErrorCode::ProjectionError(MismatchedProjectionTypes {
|
FulfillmentErrorCode::Project(MismatchedProjectionTypes { err: TypeError::Mismatch })
|
||||||
err: TypeError::Mismatch,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
ty::PredicateKind::Subtype(pred) => {
|
ty::PredicateKind::Subtype(pred) => {
|
||||||
let (a, b) = infcx.enter_forall_and_leak_universe(
|
let (a, b) = infcx.enter_forall_and_leak_universe(
|
||||||
obligation.predicate.kind().rebind((pred.a, pred.b)),
|
obligation.predicate.kind().rebind((pred.a, pred.b)),
|
||||||
);
|
);
|
||||||
let expected_found = ExpectedFound::new(true, a, b);
|
let expected_found = ExpectedFound::new(true, a, b);
|
||||||
FulfillmentErrorCode::SubtypeError(expected_found, TypeError::Sorts(expected_found))
|
FulfillmentErrorCode::Subtype(expected_found, TypeError::Sorts(expected_found))
|
||||||
}
|
}
|
||||||
ty::PredicateKind::Coerce(pred) => {
|
ty::PredicateKind::Coerce(pred) => {
|
||||||
let (a, b) = infcx.enter_forall_and_leak_universe(
|
let (a, b) = infcx.enter_forall_and_leak_universe(
|
||||||
obligation.predicate.kind().rebind((pred.a, pred.b)),
|
obligation.predicate.kind().rebind((pred.a, pred.b)),
|
||||||
);
|
);
|
||||||
let expected_found = ExpectedFound::new(false, a, b);
|
let expected_found = ExpectedFound::new(false, a, b);
|
||||||
FulfillmentErrorCode::SubtypeError(expected_found, TypeError::Sorts(expected_found))
|
FulfillmentErrorCode::Subtype(expected_found, TypeError::Sorts(expected_found))
|
||||||
}
|
}
|
||||||
ty::PredicateKind::Clause(_)
|
ty::PredicateKind::Clause(_)
|
||||||
| ty::PredicateKind::ObjectSafe(_)
|
| ty::PredicateKind::ObjectSafe(_)
|
||||||
| ty::PredicateKind::Ambiguous => {
|
| ty::PredicateKind::Ambiguous => {
|
||||||
FulfillmentErrorCode::SelectionError(SelectionError::Unimplemented)
|
FulfillmentErrorCode::Select(SelectionError::Unimplemented)
|
||||||
}
|
}
|
||||||
ty::PredicateKind::ConstEquate(..) => {
|
ty::PredicateKind::ConstEquate(..) => {
|
||||||
bug!("unexpected goal: {obligation:?}")
|
bug!("unexpected goal: {obligation:?}")
|
||||||
|
@ -429,7 +425,7 @@ fn derive_cause<'tcx>(
|
||||||
tcx.predicates_of(impl_def_id).instantiate_identity(tcx).iter().nth(idx)
|
tcx.predicates_of(impl_def_id).instantiate_identity(tcx).iter().nth(idx)
|
||||||
{
|
{
|
||||||
cause = cause.derived_cause(parent_trait_pred, |derived| {
|
cause = cause.derived_cause(parent_trait_pred, |derived| {
|
||||||
traits::ImplDerivedObligation(Box::new(traits::ImplDerivedObligationCause {
|
ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedCause {
|
||||||
derived,
|
derived,
|
||||||
impl_or_alias_def_id: impl_def_id,
|
impl_or_alias_def_id: impl_def_id,
|
||||||
impl_def_predicate_index: Some(idx),
|
impl_def_predicate_index: Some(idx),
|
||||||
|
@ -439,7 +435,7 @@ fn derive_cause<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ProbeKind::TraitCandidate { source: CandidateSource::BuiltinImpl(..), result: _ } => {
|
ProbeKind::TraitCandidate { source: CandidateSource::BuiltinImpl(..), result: _ } => {
|
||||||
cause = cause.derived_cause(parent_trait_pred, traits::BuiltinDerivedObligation);
|
cause = cause.derived_cause(parent_trait_pred, ObligationCauseCode::BuiltinDerived);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -127,9 +127,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
flags.push((sym::ItemContext, enclosure));
|
flags.push((sym::ItemContext, enclosure));
|
||||||
|
|
||||||
match obligation.cause.code() {
|
match obligation.cause.code() {
|
||||||
ObligationCauseCode::BuiltinDerivedObligation(..)
|
ObligationCauseCode::BuiltinDerived(..)
|
||||||
| ObligationCauseCode::ImplDerivedObligation(..)
|
| ObligationCauseCode::ImplDerived(..)
|
||||||
| ObligationCauseCode::WellFormedDerivedObligation(..) => {}
|
| ObligationCauseCode::WellFormedDerived(..) => {}
|
||||||
_ => {
|
_ => {
|
||||||
// this is a "direct", user-specified, rather than derived,
|
// this is a "direct", user-specified, rather than derived,
|
||||||
// obligation.
|
// obligation.
|
||||||
|
|
|
@ -7,7 +7,7 @@ use super::{
|
||||||
|
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
use crate::infer::InferCtxt;
|
use crate::infer::InferCtxt;
|
||||||
use crate::traits::{ImplDerivedObligationCause, NormalizeExt, ObligationCtxt};
|
use crate::traits::{ImplDerivedCause, NormalizeExt, ObligationCtxt};
|
||||||
|
|
||||||
use hir::def::CtorOf;
|
use hir::def::CtorOf;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
|
@ -455,8 +455,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut code = obligation.cause.code();
|
let mut code = obligation.cause.code();
|
||||||
if let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, call_hir_id, .. } =
|
if let ObligationCauseCode::FunctionArg { arg_hir_id, call_hir_id, .. } = code
|
||||||
code
|
|
||||||
&& let Some(typeck_results) = &self.typeck_results
|
&& let Some(typeck_results) = &self.typeck_results
|
||||||
&& let hir::Node::Expr(expr) = self.tcx.hir_node(*arg_hir_id)
|
&& let hir::Node::Expr(expr) = self.tcx.hir_node(*arg_hir_id)
|
||||||
&& let Some(arg_ty) = typeck_results.expr_ty_adjusted_opt(expr)
|
&& let Some(arg_ty) = typeck_results.expr_ty_adjusted_opt(expr)
|
||||||
|
@ -846,7 +845,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
|
|
||||||
if matches!(obligation.cause.code(), ObligationCauseCode::FunctionArgumentObligation { .. })
|
if matches!(obligation.cause.code(), ObligationCauseCode::FunctionArg { .. })
|
||||||
&& obligation.cause.span.can_be_used_for_suggestions()
|
&& obligation.cause.span.can_be_used_for_suggestions()
|
||||||
{
|
{
|
||||||
// When the obligation error has been ensured to have been caused by
|
// When the obligation error has been ensured to have been caused by
|
||||||
|
@ -980,8 +979,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
};
|
};
|
||||||
let ty::Ref(_, inner_ty, hir::Mutability::Not) = ty.kind() else { return false };
|
let ty::Ref(_, inner_ty, hir::Mutability::Not) = ty.kind() else { return false };
|
||||||
let ty::Param(param) = inner_ty.kind() else { return false };
|
let ty::Param(param) = inner_ty.kind() else { return false };
|
||||||
let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } =
|
let ObligationCauseCode::FunctionArg { arg_hir_id, .. } = obligation.cause.code()
|
||||||
obligation.cause.code()
|
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -1204,9 +1202,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
let span = obligation.cause.span;
|
let span = obligation.cause.span;
|
||||||
|
|
||||||
let code = match obligation.cause.code() {
|
let code = match obligation.cause.code() {
|
||||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => parent_code,
|
ObligationCauseCode::FunctionArg { parent_code, .. } => parent_code,
|
||||||
c @ ObligationCauseCode::ItemObligation(_)
|
c @ ObligationCauseCode::WhereClause(_)
|
||||||
| c @ ObligationCauseCode::ExprItemObligation(..) => c,
|
| c @ ObligationCauseCode::WhereClauseInExpr(..) => c,
|
||||||
c if matches!(
|
c if matches!(
|
||||||
span.ctxt().outer_expn_data().kind,
|
span.ctxt().outer_expn_data().kind,
|
||||||
ExpnKind::Desugaring(DesugaringKind::ForLoop)
|
ExpnKind::Desugaring(DesugaringKind::ForLoop)
|
||||||
|
@ -1262,8 +1260,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
let mut_ref_self_ty_satisfies_pred = mk_result(trait_pred_and_mut_ref);
|
let mut_ref_self_ty_satisfies_pred = mk_result(trait_pred_and_mut_ref);
|
||||||
|
|
||||||
let (ref_inner_ty_satisfies_pred, ref_inner_ty_mut) =
|
let (ref_inner_ty_satisfies_pred, ref_inner_ty_mut) =
|
||||||
if let ObligationCauseCode::ItemObligation(_)
|
if let ObligationCauseCode::WhereClause(_)
|
||||||
| ObligationCauseCode::ExprItemObligation(..) = obligation.cause.code()
|
| ObligationCauseCode::WhereClauseInExpr(..) = obligation.cause.code()
|
||||||
&& let ty::Ref(_, ty, mutability) = old_pred.self_ty().skip_binder().kind()
|
&& let ty::Ref(_, ty, mutability) = old_pred.self_ty().skip_binder().kind()
|
||||||
{
|
{
|
||||||
(
|
(
|
||||||
|
@ -1401,12 +1399,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
if let ObligationCauseCode::ImplDerivedObligation(cause) = &*code {
|
if let ObligationCauseCode::ImplDerived(cause) = &*code {
|
||||||
try_borrowing(cause.derived.parent_trait_pred, &[])
|
try_borrowing(cause.derived.parent_trait_pred, &[])
|
||||||
} else if let ObligationCauseCode::BindingObligation(_, _)
|
} else if let ObligationCauseCode::SpannedWhereClause(_, _)
|
||||||
| ObligationCauseCode::ItemObligation(_)
|
| ObligationCauseCode::WhereClause(_)
|
||||||
| ObligationCauseCode::ExprItemObligation(..)
|
| ObligationCauseCode::WhereClauseInExpr(..)
|
||||||
| ObligationCauseCode::ExprBindingObligation(..) = code
|
| ObligationCauseCode::SpannedWhereClauseInExpr(..) = code
|
||||||
{
|
{
|
||||||
try_borrowing(poly_trait_pred, &never_suggest_borrow)
|
try_borrowing(poly_trait_pred, &never_suggest_borrow)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1644,10 +1642,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
err: &mut Diag<'_>,
|
err: &mut Diag<'_>,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) {
|
) {
|
||||||
let points_at_arg = matches!(
|
let points_at_arg =
|
||||||
obligation.cause.code(),
|
matches!(obligation.cause.code(), ObligationCauseCode::FunctionArg { .. },);
|
||||||
ObligationCauseCode::FunctionArgumentObligation { .. },
|
|
||||||
);
|
|
||||||
|
|
||||||
let span = obligation.cause.span;
|
let span = obligation.cause.span;
|
||||||
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
|
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
|
||||||
|
@ -1953,7 +1949,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
) {
|
) {
|
||||||
let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } = cause else {
|
let ObligationCauseCode::FunctionArg { arg_hir_id, .. } = cause else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let ty::FnPtr(expected) = expected.kind() else {
|
let ty::FnPtr(expected) = expected.kind() else {
|
||||||
|
@ -2104,10 +2100,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
cause: &ObligationCauseCode<'tcx>,
|
cause: &ObligationCauseCode<'tcx>,
|
||||||
err: &mut Diag<'tcx>,
|
err: &mut Diag<'tcx>,
|
||||||
) {
|
) {
|
||||||
// First, look for an `ExprBindingObligation`, which means we can get
|
// First, look for an `SpannedWhereClauseInExpr`, which means we can get
|
||||||
// the uninstantiated predicate list of the called function. And check
|
// the uninstantiated predicate list of the called function. And check
|
||||||
// that the predicate that we failed to satisfy is a `Fn`-like trait.
|
// that the predicate that we failed to satisfy is a `Fn`-like trait.
|
||||||
if let ObligationCauseCode::ExprBindingObligation(def_id, _, _, idx) = cause
|
if let ObligationCauseCode::SpannedWhereClauseInExpr(def_id, _, _, idx) = cause
|
||||||
&& let predicates = self.tcx.predicates_of(def_id).instantiate_identity(self.tcx)
|
&& let predicates = self.tcx.predicates_of(def_id).instantiate_identity(self.tcx)
|
||||||
&& let Some(pred) = predicates.predicates.get(*idx)
|
&& let Some(pred) = predicates.predicates.get(*idx)
|
||||||
&& let ty::ClauseKind::Trait(trait_pred) = pred.kind().skip_binder()
|
&& let ty::ClauseKind::Trait(trait_pred) = pred.kind().skip_binder()
|
||||||
|
@ -2261,10 +2257,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
while let Some(code) = next_code {
|
while let Some(code) = next_code {
|
||||||
debug!(?code);
|
debug!(?code);
|
||||||
match code {
|
match code {
|
||||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => {
|
ObligationCauseCode::FunctionArg { parent_code, .. } => {
|
||||||
next_code = Some(parent_code);
|
next_code = Some(parent_code);
|
||||||
}
|
}
|
||||||
ObligationCauseCode::ImplDerivedObligation(cause) => {
|
ObligationCauseCode::ImplDerived(cause) => {
|
||||||
let ty = cause.derived.parent_trait_pred.skip_binder().self_ty();
|
let ty = cause.derived.parent_trait_pred.skip_binder().self_ty();
|
||||||
debug!(
|
debug!(
|
||||||
parent_trait_ref = ?cause.derived.parent_trait_pred,
|
parent_trait_ref = ?cause.derived.parent_trait_pred,
|
||||||
|
@ -2293,8 +2289,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
|
|
||||||
next_code = Some(&cause.derived.parent_code);
|
next_code = Some(&cause.derived.parent_code);
|
||||||
}
|
}
|
||||||
ObligationCauseCode::WellFormedDerivedObligation(derived_obligation)
|
ObligationCauseCode::WellFormedDerived(derived_obligation)
|
||||||
| ObligationCauseCode::BuiltinDerivedObligation(derived_obligation) => {
|
| ObligationCauseCode::BuiltinDerived(derived_obligation) => {
|
||||||
let ty = derived_obligation.parent_trait_pred.skip_binder().self_ty();
|
let ty = derived_obligation.parent_trait_pred.skip_binder().self_ty();
|
||||||
debug!(
|
debug!(
|
||||||
parent_trait_ref = ?derived_obligation.parent_trait_pred,
|
parent_trait_ref = ?derived_obligation.parent_trait_pred,
|
||||||
|
@ -2719,7 +2715,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
| ObligationCauseCode::MethodReceiver
|
| ObligationCauseCode::MethodReceiver
|
||||||
| ObligationCauseCode::ReturnNoExpression
|
| ObligationCauseCode::ReturnNoExpression
|
||||||
| ObligationCauseCode::UnifyReceiver(..)
|
| ObligationCauseCode::UnifyReceiver(..)
|
||||||
| ObligationCauseCode::MiscObligation
|
| ObligationCauseCode::Misc
|
||||||
| ObligationCauseCode::WellFormed(..)
|
| ObligationCauseCode::WellFormed(..)
|
||||||
| ObligationCauseCode::MatchImpl(..)
|
| ObligationCauseCode::MatchImpl(..)
|
||||||
| ObligationCauseCode::ReturnValue(_)
|
| ObligationCauseCode::ReturnValue(_)
|
||||||
|
@ -2748,13 +2744,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
ObligationCauseCode::TupleElem => {
|
ObligationCauseCode::TupleElem => {
|
||||||
err.note("only the last element of a tuple may have a dynamically sized type");
|
err.note("only the last element of a tuple may have a dynamically sized type");
|
||||||
}
|
}
|
||||||
ObligationCauseCode::ItemObligation(_)
|
ObligationCauseCode::WhereClause(_) | ObligationCauseCode::WhereClauseInExpr(..) => {
|
||||||
| ObligationCauseCode::ExprItemObligation(..) => {
|
|
||||||
// We hold the `DefId` of the item introducing the obligation, but displaying it
|
// We hold the `DefId` of the item introducing the obligation, but displaying it
|
||||||
// doesn't add user usable information. It always point at an associated item.
|
// doesn't add user usable information. It always point at an associated item.
|
||||||
}
|
}
|
||||||
ObligationCauseCode::BindingObligation(item_def_id, span)
|
ObligationCauseCode::SpannedWhereClause(item_def_id, span)
|
||||||
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..) => {
|
| ObligationCauseCode::SpannedWhereClauseInExpr(item_def_id, span, ..) => {
|
||||||
let item_name = tcx.def_path_str(item_def_id);
|
let item_name = tcx.def_path_str(item_def_id);
|
||||||
let short_item_name = with_forced_trimmed_paths!(tcx.def_path_str(item_def_id));
|
let short_item_name = with_forced_trimmed_paths!(tcx.def_path_str(item_def_id));
|
||||||
let mut multispan = MultiSpan::from(span);
|
let mut multispan = MultiSpan::from(span);
|
||||||
|
@ -3175,7 +3170,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
ObligationCauseCode::SharedStatic => {
|
ObligationCauseCode::SharedStatic => {
|
||||||
err.note("shared static variables must have a type that implements `Sync`");
|
err.note("shared static variables must have a type that implements `Sync`");
|
||||||
}
|
}
|
||||||
ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
|
ObligationCauseCode::BuiltinDerived(ref data) => {
|
||||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
|
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
|
||||||
let ty = parent_trait_ref.skip_binder().self_ty();
|
let ty = parent_trait_ref.skip_binder().self_ty();
|
||||||
if parent_trait_ref.references_error() {
|
if parent_trait_ref.references_error() {
|
||||||
|
@ -3190,8 +3185,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
let is_upvar_tys_infer_tuple = if !matches!(ty.kind(), ty::Tuple(..)) {
|
let is_upvar_tys_infer_tuple = if !matches!(ty.kind(), ty::Tuple(..)) {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
if let ObligationCauseCode::BuiltinDerivedObligation(data) = &*data.parent_code
|
if let ObligationCauseCode::BuiltinDerived(data) = &*data.parent_code {
|
||||||
{
|
|
||||||
let parent_trait_ref =
|
let parent_trait_ref =
|
||||||
self.resolve_vars_if_possible(data.parent_trait_pred);
|
self.resolve_vars_if_possible(data.parent_trait_pred);
|
||||||
let nested_ty = parent_trait_ref.skip_binder().self_ty();
|
let nested_ty = parent_trait_ref.skip_binder().self_ty();
|
||||||
|
@ -3297,7 +3291,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ObligationCauseCode::ImplDerivedObligation(ref data) => {
|
ObligationCauseCode::ImplDerived(ref data) => {
|
||||||
let mut parent_trait_pred =
|
let mut parent_trait_pred =
|
||||||
self.resolve_vars_if_possible(data.derived.parent_trait_pred);
|
self.resolve_vars_if_possible(data.derived.parent_trait_pred);
|
||||||
let parent_def_id = parent_trait_pred.def_id();
|
let parent_def_id = parent_trait_pred.def_id();
|
||||||
|
@ -3367,9 +3361,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
if is_auto_trait {
|
if is_auto_trait {
|
||||||
// We don't want to point at the ADT saying "required because it appears within
|
// We don't want to point at the ADT saying "required because it appears within
|
||||||
// the type `X`", like we would otherwise do in test `supertrait-auto-trait.rs`.
|
// the type `X`", like we would otherwise do in test `supertrait-auto-trait.rs`.
|
||||||
while let ObligationCauseCode::BuiltinDerivedObligation(derived) =
|
while let ObligationCauseCode::BuiltinDerived(derived) = &*data.parent_code {
|
||||||
&*data.parent_code
|
|
||||||
{
|
|
||||||
let child_trait_ref =
|
let child_trait_ref =
|
||||||
self.resolve_vars_if_possible(derived.parent_trait_pred);
|
self.resolve_vars_if_possible(derived.parent_trait_pred);
|
||||||
let child_def_id = child_trait_ref.def_id();
|
let child_def_id = child_trait_ref.def_id();
|
||||||
|
@ -3381,7 +3373,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
parent_trait_pred = child_trait_ref;
|
parent_trait_pred = child_trait_ref;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while let ObligationCauseCode::ImplDerivedObligation(child) = &*data.parent_code {
|
while let ObligationCauseCode::ImplDerived(child) = &*data.parent_code {
|
||||||
// Skip redundant recursive obligation notes. See `ui/issue-20413.rs`.
|
// Skip redundant recursive obligation notes. See `ui/issue-20413.rs`.
|
||||||
let child_trait_pred =
|
let child_trait_pred =
|
||||||
self.resolve_vars_if_possible(child.derived.parent_trait_pred);
|
self.resolve_vars_if_possible(child.derived.parent_trait_pred);
|
||||||
|
@ -3422,7 +3414,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ObligationCauseCode::WellFormedDerivedObligation(ref data) => {
|
ObligationCauseCode::WellFormedDerived(ref data) => {
|
||||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
|
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
|
||||||
let parent_predicate = parent_trait_ref;
|
let parent_predicate = parent_trait_ref;
|
||||||
// #74711: avoid a stack overflow
|
// #74711: avoid a stack overflow
|
||||||
|
@ -3458,11 +3450,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
format!("required by a bound on the type alias `{}`", tcx.item_name(def_id)),
|
format!("required by a bound on the type alias `{}`", tcx.item_name(def_id)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ObligationCauseCode::FunctionArgumentObligation {
|
ObligationCauseCode::FunctionArg {
|
||||||
arg_hir_id,
|
arg_hir_id, call_hir_id, ref parent_code, ..
|
||||||
call_hir_id,
|
|
||||||
ref parent_code,
|
|
||||||
..
|
|
||||||
} => {
|
} => {
|
||||||
self.note_function_argument_obligation(
|
self.note_function_argument_obligation(
|
||||||
body_id,
|
body_id,
|
||||||
|
@ -3485,7 +3474,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ObligationCauseCode::CompareImplItemObligation { trait_item_def_id, kind, .. } => {
|
ObligationCauseCode::CompareImplItem { trait_item_def_id, kind, .. } => {
|
||||||
let item_name = tcx.item_name(trait_item_def_id);
|
let item_name = tcx.item_name(trait_item_def_id);
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"the requirement `{predicate}` appears on the `impl`'s {kind} \
|
"the requirement `{predicate}` appears on the `impl`'s {kind} \
|
||||||
|
@ -3694,7 +3683,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
err: &mut Diag<'_>,
|
err: &mut Diag<'_>,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) {
|
) {
|
||||||
if let ObligationCauseCode::ImplDerivedObligation(_) = obligation.cause.code()
|
if let ObligationCauseCode::ImplDerived(_) = obligation.cause.code()
|
||||||
&& self
|
&& self
|
||||||
.tcx
|
.tcx
|
||||||
.is_diagnostic_item(sym::SliceIndex, trait_pred.skip_binder().trait_ref.def_id)
|
.is_diagnostic_item(sym::SliceIndex, trait_pred.skip_binder().trait_ref.def_id)
|
||||||
|
@ -3811,7 +3800,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
// to an associated type (as seen from `trait_pred`) in the predicate. Like in
|
// to an associated type (as seen from `trait_pred`) in the predicate. Like in
|
||||||
// trait_pred `S: Sum<<Self as Iterator>::Item>` and predicate `i32: Sum<&()>`
|
// trait_pred `S: Sum<<Self as Iterator>::Item>` and predicate `i32: Sum<&()>`
|
||||||
let mut type_diffs = vec![];
|
let mut type_diffs = vec![];
|
||||||
if let ObligationCauseCode::ExprBindingObligation(def_id, _, _, idx) = parent_code
|
if let ObligationCauseCode::SpannedWhereClauseInExpr(def_id, _, _, idx) = parent_code
|
||||||
&& let Some(node_args) = typeck_results.node_args_opt(call_hir_id)
|
&& let Some(node_args) = typeck_results.node_args_opt(call_hir_id)
|
||||||
&& let where_clauses =
|
&& let where_clauses =
|
||||||
self.tcx.predicates_of(def_id).instantiate(self.tcx, node_args)
|
self.tcx.predicates_of(def_id).instantiate(self.tcx, node_args)
|
||||||
|
@ -4320,8 +4309,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
) {
|
) {
|
||||||
// We can only suggest the slice coersion for function and binary operation arguments,
|
// We can only suggest the slice coersion for function and binary operation arguments,
|
||||||
// since the suggestion would make no sense in turbofish or call
|
// since the suggestion would make no sense in turbofish or call
|
||||||
let (ObligationCauseCode::BinOp { .. }
|
let (ObligationCauseCode::BinOp { .. } | ObligationCauseCode::FunctionArg { .. }) =
|
||||||
| ObligationCauseCode::FunctionArgumentObligation { .. }) = obligation.cause.code()
|
obligation.cause.code()
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -4407,7 +4396,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let ObligationCauseCode::FunctionArgumentObligation {
|
if let ObligationCauseCode::FunctionArg {
|
||||||
call_hir_id,
|
call_hir_id,
|
||||||
arg_hir_id,
|
arg_hir_id,
|
||||||
parent_code: _,
|
parent_code: _,
|
||||||
|
@ -4967,7 +4956,7 @@ fn point_at_assoc_type_restriction<G: EmissionGuarantee>(
|
||||||
trait_name: &str,
|
trait_name: &str,
|
||||||
predicate: ty::Predicate<'_>,
|
predicate: ty::Predicate<'_>,
|
||||||
generics: &hir::Generics<'_>,
|
generics: &hir::Generics<'_>,
|
||||||
data: &ImplDerivedObligationCause<'_>,
|
data: &ImplDerivedCause<'_>,
|
||||||
) {
|
) {
|
||||||
let ty::PredicateKind::Clause(clause) = predicate.kind().skip_binder() else {
|
let ty::PredicateKind::Clause(clause) = predicate.kind().skip_binder() else {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -391,7 +391,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let ObligationCauseCode::CompareImplItemObligation {
|
if let ObligationCauseCode::CompareImplItem {
|
||||||
impl_item_def_id,
|
impl_item_def_id,
|
||||||
trait_item_def_id,
|
trait_item_def_id,
|
||||||
kind: _,
|
kind: _,
|
||||||
|
@ -1017,7 +1017,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
if let Some((_, Some(parent))) = obligation.cause.code().parent() {
|
if let Some((_, Some(parent))) = obligation.cause.code().parent() {
|
||||||
// If we have a derived obligation, then the parent will be a `AsyncFn*` goal.
|
// If we have a derived obligation, then the parent will be a `AsyncFn*` goal.
|
||||||
trait_ref = parent.to_poly_trait_ref();
|
trait_ref = parent.to_poly_trait_ref();
|
||||||
} else if let &ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } =
|
} else if let &ObligationCauseCode::FunctionArg { arg_hir_id, .. } =
|
||||||
obligation.cause.code()
|
obligation.cause.code()
|
||||||
&& let Some(typeck_results) = &self.typeck_results
|
&& let Some(typeck_results) = &self.typeck_results
|
||||||
&& let ty::Closure(closure_def_id, _) | ty::CoroutineClosure(closure_def_id, _) =
|
&& let ty::Closure(closure_def_id, _) | ty::CoroutineClosure(closure_def_id, _) =
|
||||||
|
@ -1104,8 +1104,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
if let ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, .. } =
|
if let ObligationCauseCode::FunctionArg { arg_hir_id, .. } = obligation.cause.code()
|
||||||
obligation.cause.code()
|
|
||||||
&& let Node::Expr(arg) = self.tcx.hir_node(*arg_hir_id)
|
&& let Node::Expr(arg) = self.tcx.hir_node(*arg_hir_id)
|
||||||
&& let arg = arg.peel_borrows()
|
&& let arg = arg.peel_borrows()
|
||||||
&& let hir::ExprKind::Path(hir::QPath::Resolved(
|
&& let hir::ExprKind::Path(hir::QPath::Resolved(
|
||||||
|
@ -1504,13 +1503,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
match error.code {
|
match error.code {
|
||||||
FulfillmentErrorCode::SelectionError(ref selection_error) => self
|
FulfillmentErrorCode::Select(ref selection_error) => self.report_selection_error(
|
||||||
.report_selection_error(
|
|
||||||
error.obligation.clone(),
|
error.obligation.clone(),
|
||||||
&error.root_obligation,
|
&error.root_obligation,
|
||||||
selection_error,
|
selection_error,
|
||||||
),
|
),
|
||||||
FulfillmentErrorCode::ProjectionError(ref e) => {
|
FulfillmentErrorCode::Project(ref e) => {
|
||||||
self.report_projection_error(&error.obligation, e)
|
self.report_projection_error(&error.obligation, e)
|
||||||
}
|
}
|
||||||
FulfillmentErrorCode::Ambiguity { overflow: None } => {
|
FulfillmentErrorCode::Ambiguity { overflow: None } => {
|
||||||
|
@ -1519,7 +1517,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
FulfillmentErrorCode::Ambiguity { overflow: Some(suggest_increasing_limit) } => {
|
FulfillmentErrorCode::Ambiguity { overflow: Some(suggest_increasing_limit) } => {
|
||||||
self.report_overflow_no_abort(error.obligation.clone(), suggest_increasing_limit)
|
self.report_overflow_no_abort(error.obligation.clone(), suggest_increasing_limit)
|
||||||
}
|
}
|
||||||
FulfillmentErrorCode::SubtypeError(ref expected_found, ref err) => self
|
FulfillmentErrorCode::Subtype(ref expected_found, ref err) => self
|
||||||
.report_mismatched_types(
|
.report_mismatched_types(
|
||||||
&error.obligation.cause,
|
&error.obligation.cause,
|
||||||
expected_found.expected,
|
expected_found.expected,
|
||||||
|
@ -1527,7 +1525,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
*err,
|
*err,
|
||||||
)
|
)
|
||||||
.emit(),
|
.emit(),
|
||||||
FulfillmentErrorCode::ConstEquateError(ref expected_found, ref err) => {
|
FulfillmentErrorCode::ConstEquate(ref expected_found, ref err) => {
|
||||||
let mut diag = self.report_mismatched_consts(
|
let mut diag = self.report_mismatched_consts(
|
||||||
&error.obligation.cause,
|
&error.obligation.cause,
|
||||||
expected_found.expected,
|
expected_found.expected,
|
||||||
|
@ -1535,10 +1533,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
*err,
|
*err,
|
||||||
);
|
);
|
||||||
let code = error.obligation.cause.code().peel_derives().peel_match_impls();
|
let code = error.obligation.cause.code().peel_derives().peel_match_impls();
|
||||||
if let ObligationCauseCode::BindingObligation(..)
|
if let ObligationCauseCode::SpannedWhereClause(..)
|
||||||
| ObligationCauseCode::ItemObligation(..)
|
| ObligationCauseCode::WhereClause(..)
|
||||||
| ObligationCauseCode::ExprBindingObligation(..)
|
| ObligationCauseCode::SpannedWhereClauseInExpr(..)
|
||||||
| ObligationCauseCode::ExprItemObligation(..) = code
|
| ObligationCauseCode::WhereClauseInExpr(..) = code
|
||||||
{
|
{
|
||||||
self.note_obligation_cause_code(
|
self.note_obligation_cause_code(
|
||||||
error.obligation.cause.body_id,
|
error.obligation.cause.body_id,
|
||||||
|
@ -1612,10 +1610,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
|
|
||||||
let is_normalized_term_expected = !matches!(
|
let is_normalized_term_expected = !matches!(
|
||||||
obligation.cause.code().peel_derives(),
|
obligation.cause.code().peel_derives(),
|
||||||
ObligationCauseCode::ItemObligation(_)
|
ObligationCauseCode::WhereClause(_)
|
||||||
| ObligationCauseCode::BindingObligation(_, _)
|
| ObligationCauseCode::SpannedWhereClause(_, _)
|
||||||
| ObligationCauseCode::ExprItemObligation(..)
|
| ObligationCauseCode::WhereClauseInExpr(..)
|
||||||
| ObligationCauseCode::ExprBindingObligation(..)
|
| ObligationCauseCode::SpannedWhereClauseInExpr(..)
|
||||||
| ObligationCauseCode::Coercion { .. }
|
| ObligationCauseCode::Coercion { .. }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -2212,7 +2210,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
code: &ObligationCauseCode<'tcx>,
|
code: &ObligationCauseCode<'tcx>,
|
||||||
) -> Option<(Ty<'tcx>, Option<Span>)> {
|
) -> Option<(Ty<'tcx>, Option<Span>)> {
|
||||||
match code {
|
match code {
|
||||||
ObligationCauseCode::BuiltinDerivedObligation(data) => {
|
ObligationCauseCode::BuiltinDerived(data) => {
|
||||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
|
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
|
||||||
match self.get_parent_trait_ref(&data.parent_code) {
|
match self.get_parent_trait_ref(&data.parent_code) {
|
||||||
Some(t) => Some(t),
|
Some(t) => Some(t),
|
||||||
|
@ -2224,7 +2222,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => {
|
ObligationCauseCode::FunctionArg { parent_code, .. } => {
|
||||||
self.get_parent_trait_ref(parent_code)
|
self.get_parent_trait_ref(parent_code)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -2447,8 +2445,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let ObligationCauseCode::ItemObligation(def_id)
|
if let ObligationCauseCode::WhereClause(def_id)
|
||||||
| ObligationCauseCode::ExprItemObligation(def_id, ..) = *obligation.cause.code()
|
| ObligationCauseCode::WhereClauseInExpr(def_id, ..) = *obligation.cause.code()
|
||||||
{
|
{
|
||||||
self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());
|
self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());
|
||||||
}
|
}
|
||||||
|
@ -2883,8 +2881,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let (ObligationCauseCode::BindingObligation(item_def_id, span)
|
let (ObligationCauseCode::SpannedWhereClause(item_def_id, span)
|
||||||
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..)) =
|
| ObligationCauseCode::SpannedWhereClauseInExpr(item_def_id, span, ..)) =
|
||||||
*obligation.cause.code().peel_derives()
|
*obligation.cause.code().peel_derives()
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
|
@ -3004,7 +3002,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
obligated_types: &mut Vec<Ty<'tcx>>,
|
obligated_types: &mut Vec<Ty<'tcx>>,
|
||||||
cause_code: &ObligationCauseCode<'tcx>,
|
cause_code: &ObligationCauseCode<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = cause_code {
|
if let ObligationCauseCode::BuiltinDerived(ref data) = cause_code {
|
||||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
|
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
|
||||||
let self_ty = parent_trait_ref.skip_binder().self_ty();
|
let self_ty = parent_trait_ref.skip_binder().self_ty();
|
||||||
if obligated_types.iter().any(|ot| ot == &self_ty) {
|
if obligated_types.iter().any(|ot| ot == &self_ty) {
|
||||||
|
@ -3181,8 +3179,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
ObligationCauseCode::RustCall => {
|
ObligationCauseCode::RustCall => {
|
||||||
err.primary_message("functions with the \"rust-call\" ABI must take a single non-self tuple argument");
|
err.primary_message("functions with the \"rust-call\" ABI must take a single non-self tuple argument");
|
||||||
}
|
}
|
||||||
ObligationCauseCode::BindingObligation(def_id, _)
|
ObligationCauseCode::SpannedWhereClause(def_id, _)
|
||||||
| ObligationCauseCode::ItemObligation(def_id)
|
| ObligationCauseCode::WhereClause(def_id)
|
||||||
if self.tcx.is_fn_trait(*def_id) =>
|
if self.tcx.is_fn_trait(*def_id) =>
|
||||||
{
|
{
|
||||||
err.code(E0059);
|
err.code(E0059);
|
||||||
|
@ -3571,7 +3569,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
match self.tcx.sess.source_map().span_to_snippet(const_span) {
|
match self.tcx.sess.source_map().span_to_snippet(const_span) {
|
||||||
Ok(snippet) => {
|
Ok(snippet) => {
|
||||||
let code = format!("[(); {snippet}{cast}]:");
|
let code = format!("[(); {snippet}{cast}]:");
|
||||||
let def_id = if let ObligationCauseCode::CompareImplItemObligation {
|
let def_id = if let ObligationCauseCode::CompareImplItem {
|
||||||
trait_item_def_id,
|
trait_item_def_id,
|
||||||
..
|
..
|
||||||
} = obligation.cause.code()
|
} = obligation.cause.code()
|
||||||
|
|
|
@ -411,7 +411,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||||
|
|
||||||
ty::PredicateKind::ObjectSafe(trait_def_id) => {
|
ty::PredicateKind::ObjectSafe(trait_def_id) => {
|
||||||
if !self.selcx.tcx().check_is_object_safe(trait_def_id) {
|
if !self.selcx.tcx().check_is_object_safe(trait_def_id) {
|
||||||
ProcessResult::Error(FulfillmentErrorCode::SelectionError(Unimplemented))
|
ProcessResult::Error(FulfillmentErrorCode::Select(Unimplemented))
|
||||||
} else {
|
} else {
|
||||||
ProcessResult::Changed(vec![])
|
ProcessResult::Changed(vec![])
|
||||||
}
|
}
|
||||||
|
@ -435,7 +435,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||||
ty,
|
ty,
|
||||||
) {
|
) {
|
||||||
Ok(inf_ok) => ProcessResult::Changed(mk_pending(inf_ok.into_obligations())),
|
Ok(inf_ok) => ProcessResult::Changed(mk_pending(inf_ok.into_obligations())),
|
||||||
Err(_) => ProcessResult::Error(FulfillmentErrorCode::SelectionError(
|
Err(_) => ProcessResult::Error(FulfillmentErrorCode::Select(
|
||||||
SelectionError::Unimplemented,
|
SelectionError::Unimplemented,
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
|
@ -493,10 +493,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||||
Ok(Err(err)) => {
|
Ok(Err(err)) => {
|
||||||
let expected_found =
|
let expected_found =
|
||||||
ExpectedFound::new(subtype.a_is_expected, subtype.a, subtype.b);
|
ExpectedFound::new(subtype.a_is_expected, subtype.a, subtype.b);
|
||||||
ProcessResult::Error(FulfillmentErrorCode::SubtypeError(
|
ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found, err))
|
||||||
expected_found,
|
|
||||||
err,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -516,10 +513,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||||
Ok(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
|
Ok(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
|
||||||
Ok(Err(err)) => {
|
Ok(Err(err)) => {
|
||||||
let expected_found = ExpectedFound::new(false, coerce.a, coerce.b);
|
let expected_found = ExpectedFound::new(false, coerce.a, coerce.b);
|
||||||
ProcessResult::Error(FulfillmentErrorCode::SubtypeError(
|
ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found, err))
|
||||||
expected_found,
|
|
||||||
err,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -542,7 +536,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||||
Err(
|
Err(
|
||||||
e @ NotConstEvaluatable::MentionsParam
|
e @ NotConstEvaluatable::MentionsParam
|
||||||
| e @ NotConstEvaluatable::Error(_),
|
| e @ NotConstEvaluatable::Error(_),
|
||||||
) => ProcessResult::Error(FulfillmentErrorCode::SelectionError(
|
) => ProcessResult::Error(FulfillmentErrorCode::Select(
|
||||||
SelectionError::NotConstEvaluatable(e),
|
SelectionError::NotConstEvaluatable(e),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
|
@ -638,7 +632,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||||
ProcessResult::Changed(mk_pending(inf_ok.into_obligations()))
|
ProcessResult::Changed(mk_pending(inf_ok.into_obligations()))
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
ProcessResult::Error(FulfillmentErrorCode::ConstEquateError(
|
ProcessResult::Error(FulfillmentErrorCode::ConstEquate(
|
||||||
ExpectedFound::new(true, c1, c2),
|
ExpectedFound::new(true, c1, c2),
|
||||||
err,
|
err,
|
||||||
))
|
))
|
||||||
|
@ -646,13 +640,11 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Err(ErrorHandled::Reported(reported, _)), _)
|
(Err(ErrorHandled::Reported(reported, _)), _)
|
||||||
| (_, Err(ErrorHandled::Reported(reported, _))) => {
|
| (_, Err(ErrorHandled::Reported(reported, _))) => ProcessResult::Error(
|
||||||
ProcessResult::Error(FulfillmentErrorCode::SelectionError(
|
FulfillmentErrorCode::Select(SelectionError::NotConstEvaluatable(
|
||||||
SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(
|
NotConstEvaluatable::Error(reported.into()),
|
||||||
reported.into(),
|
|
||||||
)),
|
)),
|
||||||
))
|
),
|
||||||
}
|
|
||||||
(Err(ErrorHandled::TooGeneric(_)), _)
|
(Err(ErrorHandled::TooGeneric(_)), _)
|
||||||
| (_, Err(ErrorHandled::TooGeneric(_))) => {
|
| (_, Err(ErrorHandled::TooGeneric(_))) => {
|
||||||
if c1.has_non_region_infer() || c2.has_non_region_infer() {
|
if c1.has_non_region_infer() || c2.has_non_region_infer() {
|
||||||
|
@ -660,7 +652,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
// Two different constants using generic parameters ~> error.
|
// Two different constants using generic parameters ~> error.
|
||||||
let expected_found = ExpectedFound::new(true, c1, c2);
|
let expected_found = ExpectedFound::new(true, c1, c2);
|
||||||
ProcessResult::Error(FulfillmentErrorCode::ConstEquateError(
|
ProcessResult::Error(FulfillmentErrorCode::ConstEquate(
|
||||||
expected_found,
|
expected_found,
|
||||||
TypeError::ConstMismatch(expected_found),
|
TypeError::ConstMismatch(expected_found),
|
||||||
))
|
))
|
||||||
|
@ -741,7 +733,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
|
||||||
Err(selection_err) => {
|
Err(selection_err) => {
|
||||||
debug!("selecting trait at depth {} yielded Err", obligation.recursion_depth);
|
debug!("selecting trait at depth {} yielded Err", obligation.recursion_depth);
|
||||||
|
|
||||||
ProcessResult::Error(FulfillmentErrorCode::SelectionError(selection_err))
|
ProcessResult::Error(FulfillmentErrorCode::Select(selection_err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -793,7 +785,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
|
||||||
project_obligation.with(tcx, project_obligation.predicate),
|
project_obligation.with(tcx, project_obligation.predicate),
|
||||||
])),
|
])),
|
||||||
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
|
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
|
||||||
ProcessResult::Error(FulfillmentErrorCode::ProjectionError(e))
|
ProcessResult::Error(FulfillmentErrorCode::Project(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ use super::Selection;
|
||||||
use super::SelectionContext;
|
use super::SelectionContext;
|
||||||
use super::SelectionError;
|
use super::SelectionError;
|
||||||
use super::{Normalized, NormalizedTy, ProjectionCacheEntry, ProjectionCacheKey};
|
use super::{Normalized, NormalizedTy, ProjectionCacheEntry, ProjectionCacheKey};
|
||||||
|
use rustc_infer::traits::ObligationCauseCode;
|
||||||
use rustc_middle::traits::BuiltinImplSource;
|
use rustc_middle::traits::BuiltinImplSource;
|
||||||
use rustc_middle::traits::ImplSource;
|
use rustc_middle::traits::ImplSource;
|
||||||
use rustc_middle::traits::ImplSourceUserDefinedData;
|
use rustc_middle::traits::ImplSourceUserDefinedData;
|
||||||
|
@ -573,9 +574,9 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>(
|
||||||
// diagnostics which is not ideal.
|
// diagnostics which is not ideal.
|
||||||
// Consider creating separate cause codes for this specific situation.
|
// Consider creating separate cause codes for this specific situation.
|
||||||
if span.is_dummy() {
|
if span.is_dummy() {
|
||||||
super::ItemObligation(alias_ty.def_id)
|
ObligationCauseCode::WhereClause(alias_ty.def_id)
|
||||||
} else {
|
} else {
|
||||||
super::BindingObligation(alias_ty.def_id, span)
|
ObligationCauseCode::SpannedWhereClause(alias_ty.def_id, span)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -2113,22 +2114,22 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
|
||||||
|
|
||||||
let nested_cause = if matches!(
|
let nested_cause = if matches!(
|
||||||
obligation.cause.code(),
|
obligation.cause.code(),
|
||||||
super::CompareImplItemObligation { .. }
|
ObligationCauseCode::CompareImplItem { .. }
|
||||||
| super::CheckAssociatedTypeBounds { .. }
|
| ObligationCauseCode::CheckAssociatedTypeBounds { .. }
|
||||||
| super::AscribeUserTypeProvePredicate(..)
|
| ObligationCauseCode::AscribeUserTypeProvePredicate(..)
|
||||||
) {
|
) {
|
||||||
obligation.cause.clone()
|
obligation.cause.clone()
|
||||||
} else if span.is_dummy() {
|
} else if span.is_dummy() {
|
||||||
ObligationCause::new(
|
ObligationCause::new(
|
||||||
obligation.cause.span,
|
obligation.cause.span,
|
||||||
obligation.cause.body_id,
|
obligation.cause.body_id,
|
||||||
super::ItemObligation(obligation.predicate.def_id),
|
ObligationCauseCode::WhereClause(obligation.predicate.def_id),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
ObligationCause::new(
|
ObligationCause::new(
|
||||||
obligation.cause.span,
|
obligation.cause.span,
|
||||||
obligation.cause.body_id,
|
obligation.cause.body_id,
|
||||||
super::BindingObligation(obligation.predicate.def_id, span),
|
ObligationCauseCode::SpannedWhereClause(obligation.predicate.def_id, span),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
nested.push(Obligation::with_depth(
|
nested.push(Obligation::with_depth(
|
||||||
|
|
|
@ -11,6 +11,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_infer::infer::HigherRankedType;
|
use rustc_infer::infer::HigherRankedType;
|
||||||
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
||||||
|
use rustc_infer::traits::ObligationCauseCode;
|
||||||
use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData};
|
use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, GenericArgs, GenericArgsRef, GenericParamDefKind, ToPolyTraitRef, ToPredicate,
|
self, GenericArgs, GenericArgsRef, GenericParamDefKind, ToPolyTraitRef, ToPredicate,
|
||||||
|
@ -25,10 +26,9 @@ use crate::traits::vtable::{
|
||||||
VtblSegment,
|
VtblSegment,
|
||||||
};
|
};
|
||||||
use crate::traits::{
|
use crate::traits::{
|
||||||
BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource,
|
ImplDerivedCause, ImplSource, ImplSourceUserDefinedData, Normalized, Obligation,
|
||||||
ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause, PolyTraitObligation,
|
ObligationCause, PolyTraitObligation, PredicateObligation, Selection, SelectionError,
|
||||||
PredicateObligation, Selection, SelectionError, SignatureMismatch, TraitNotObjectSafe,
|
SignatureMismatch, TraitNotObjectSafe, TraitObligation, Unimplemented,
|
||||||
TraitObligation, Unimplemented,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::BuiltinImplConditions;
|
use super::BuiltinImplConditions;
|
||||||
|
@ -275,7 +275,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
bug!("obligation {:?} had matched a builtin impl but now doesn't", obligation);
|
bug!("obligation {:?} had matched a builtin impl but now doesn't", obligation);
|
||||||
};
|
};
|
||||||
|
|
||||||
let cause = obligation.derived_cause(BuiltinDerivedObligation);
|
let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
|
||||||
self.collect_predicates_for_types(
|
self.collect_predicates_for_types(
|
||||||
obligation.param_env,
|
obligation.param_env,
|
||||||
cause,
|
cause,
|
||||||
|
@ -435,7 +435,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
) -> Vec<PredicateObligation<'tcx>> {
|
) -> Vec<PredicateObligation<'tcx>> {
|
||||||
debug!(?nested, "vtable_auto_impl");
|
debug!(?nested, "vtable_auto_impl");
|
||||||
ensure_sufficient_stack(|| {
|
ensure_sufficient_stack(|| {
|
||||||
let cause = obligation.derived_cause(BuiltinDerivedObligation);
|
let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
|
||||||
|
|
||||||
let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
|
let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
|
||||||
let trait_ref = self.infcx.enter_forall_and_leak_universe(poly_trait_ref);
|
let trait_ref = self.infcx.enter_forall_and_leak_universe(poly_trait_ref);
|
||||||
|
@ -723,7 +723,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
|
|
||||||
let mut nested =
|
let mut nested =
|
||||||
self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?;
|
self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?;
|
||||||
let cause = obligation.derived_cause(BuiltinDerivedObligation);
|
let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
|
||||||
|
|
||||||
// Confirm the `type Output: Sized;` bound that is present on `FnOnce`
|
// Confirm the `type Output: Sized;` bound that is present on `FnOnce`
|
||||||
let output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
|
let output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
|
||||||
|
@ -1381,7 +1381,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
let self_ty = obligation.self_ty().map_bound(|ty| self.infcx.shallow_resolve(ty));
|
let self_ty = obligation.self_ty().map_bound(|ty| self.infcx.shallow_resolve(ty));
|
||||||
|
|
||||||
let mut nested = vec![];
|
let mut nested = vec![];
|
||||||
let cause = obligation.derived_cause(BuiltinDerivedObligation);
|
let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
|
||||||
|
|
||||||
// If we have a custom `impl const Drop`, then
|
// If we have a custom `impl const Drop`, then
|
||||||
// first check it like a regular impl candidate.
|
// first check it like a regular impl candidate.
|
||||||
|
@ -1396,7 +1396,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
debug!(?args, "impl args");
|
debug!(?args, "impl args");
|
||||||
|
|
||||||
let cause = obligation.derived_cause(|derived| {
|
let cause = obligation.derived_cause(|derived| {
|
||||||
ImplDerivedObligation(Box::new(ImplDerivedObligationCause {
|
ObligationCauseCode::ImplDerived(Box::new(ImplDerivedCause {
|
||||||
derived,
|
derived,
|
||||||
impl_or_alias_def_id: impl_def_id,
|
impl_or_alias_def_id: impl_def_id,
|
||||||
impl_def_predicate_index: None,
|
impl_def_predicate_index: None,
|
||||||
|
|
|
@ -13,9 +13,9 @@ use super::util;
|
||||||
use super::util::closure_trait_ref_and_return_type;
|
use super::util::closure_trait_ref_and_return_type;
|
||||||
use super::wf;
|
use super::wf;
|
||||||
use super::{
|
use super::{
|
||||||
ImplDerivedObligation, ImplDerivedObligationCause, Normalized, Obligation, ObligationCause,
|
ImplDerivedCause, Normalized, Obligation, ObligationCause, ObligationCauseCode, Overflow,
|
||||||
ObligationCauseCode, Overflow, PolyTraitObligation, PredicateObligation, Selection,
|
PolyTraitObligation, PredicateObligation, Selection, SelectionError, SelectionResult,
|
||||||
SelectionError, SelectionResult, TraitQueryMode,
|
TraitQueryMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::infer::{InferCtxt, InferOk, TypeFreshener};
|
use crate::infer::{InferCtxt, InferOk, TypeFreshener};
|
||||||
|
@ -2771,7 +2771,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
||||||
cause.clone()
|
cause.clone()
|
||||||
} else {
|
} else {
|
||||||
cause.clone().derived_cause(parent_trait_pred, |derived| {
|
cause.clone().derived_cause(parent_trait_pred, |derived| {
|
||||||
ImplDerivedObligation(Box::new(ImplDerivedObligationCause {
|
ObligationCauseCode::ImplDerived(Box::new(ImplDerivedCause {
|
||||||
derived,
|
derived,
|
||||||
impl_or_alias_def_id: def_id,
|
impl_or_alias_def_id: def_id,
|
||||||
impl_def_predicate_index: Some(index),
|
impl_def_predicate_index: Some(index),
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::infer::InferCtxt;
|
||||||
use crate::traits;
|
use crate::traits;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
|
use rustc_infer::traits::ObligationCauseCode;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
|
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
|
||||||
};
|
};
|
||||||
|
@ -333,7 +334,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||||
return self.out;
|
return self.out;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cause = self.cause(traits::WellFormed(None));
|
let cause = self.cause(ObligationCauseCode::WellFormed(None));
|
||||||
let param_env = self.param_env;
|
let param_env = self.param_env;
|
||||||
let mut obligations = Vec::with_capacity(self.out.len());
|
let mut obligations = Vec::with_capacity(self.out.len());
|
||||||
for mut obligation in self.out {
|
for mut obligation in self.out {
|
||||||
|
@ -381,7 +382,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||||
if let Some(parent_trait_pred) = predicate.to_opt_poly_trait_pred() {
|
if let Some(parent_trait_pred) = predicate.to_opt_poly_trait_pred() {
|
||||||
cause = cause.derived_cause(
|
cause = cause.derived_cause(
|
||||||
parent_trait_pred,
|
parent_trait_pred,
|
||||||
traits::ObligationCauseCode::WellFormedDerivedObligation,
|
traits::ObligationCauseCode::WellFormedDerived,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
extend_cause_with_original_assoc_item_obligation(tcx, item, &mut cause, predicate);
|
extend_cause_with_original_assoc_item_obligation(tcx, item, &mut cause, predicate);
|
||||||
|
@ -485,7 +486,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||||
&mut traits::SelectionContext::new(self.infcx),
|
&mut traits::SelectionContext::new(self.infcx),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
data,
|
data,
|
||||||
self.cause(traits::WellFormed(None)),
|
self.cause(ObligationCauseCode::WellFormed(None)),
|
||||||
self.recursion_depth,
|
self.recursion_depth,
|
||||||
&mut self.out,
|
&mut self.out,
|
||||||
);
|
);
|
||||||
|
@ -498,7 +499,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||||
|
|
||||||
fn compute_projection_args(&mut self, args: GenericArgsRef<'tcx>) {
|
fn compute_projection_args(&mut self, args: GenericArgsRef<'tcx>) {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
let cause = self.cause(traits::WellFormed(None));
|
let cause = self.cause(ObligationCauseCode::WellFormed(None));
|
||||||
let param_env = self.param_env;
|
let param_env = self.param_env;
|
||||||
let depth = self.recursion_depth;
|
let depth = self.recursion_depth;
|
||||||
|
|
||||||
|
@ -565,9 +566,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||||
iter::zip(predicates, origins.into_iter().rev())
|
iter::zip(predicates, origins.into_iter().rev())
|
||||||
.map(|((pred, span), origin_def_id)| {
|
.map(|((pred, span), origin_def_id)| {
|
||||||
let code = if span.is_dummy() {
|
let code = if span.is_dummy() {
|
||||||
traits::ItemObligation(origin_def_id)
|
ObligationCauseCode::WhereClause(origin_def_id)
|
||||||
} else {
|
} else {
|
||||||
traits::BindingObligation(origin_def_id, span)
|
ObligationCauseCode::SpannedWhereClause(origin_def_id, span)
|
||||||
};
|
};
|
||||||
let cause = self.cause(code);
|
let cause = self.cause(code);
|
||||||
traits::Obligation::with_depth(
|
traits::Obligation::with_depth(
|
||||||
|
@ -626,7 +627,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||||
|
|
||||||
self.out.reserve(implicit_bounds.len());
|
self.out.reserve(implicit_bounds.len());
|
||||||
for implicit_bound in implicit_bounds {
|
for implicit_bound in implicit_bounds {
|
||||||
let cause = self.cause(traits::ObjectTypeBound(ty, explicit_bound));
|
let cause = self.cause(ObligationCauseCode::ObjectTypeBound(ty, explicit_bound));
|
||||||
let outlives =
|
let outlives =
|
||||||
ty::Binder::dummy(ty::OutlivesPredicate(explicit_bound, implicit_bound));
|
ty::Binder::dummy(ty::OutlivesPredicate(explicit_bound, implicit_bound));
|
||||||
self.out.push(traits::Obligation::with_depth(
|
self.out.push(traits::Obligation::with_depth(
|
||||||
|
@ -644,7 +645,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||||
impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
|
|
||||||
fn visit_ty(&mut self, t: <TyCtxt<'tcx> as ty::Interner>::Ty) -> Self::Result {
|
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
|
||||||
debug!("wf bounds for t={:?} t.kind={:#?}", t, t.kind());
|
debug!("wf bounds for t={:?} t.kind={:#?}", t, t.kind());
|
||||||
|
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
@ -673,22 +674,22 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
||||||
ty::Infer(ty::FloatVar(_)) => {}
|
ty::Infer(ty::FloatVar(_)) => {}
|
||||||
|
|
||||||
ty::Slice(subty) => {
|
ty::Slice(subty) => {
|
||||||
self.require_sized(subty, traits::SliceOrArrayElem);
|
self.require_sized(subty, ObligationCauseCode::SliceOrArrayElem);
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Array(subty, _) => {
|
ty::Array(subty, _) => {
|
||||||
self.require_sized(subty, traits::SliceOrArrayElem);
|
self.require_sized(subty, ObligationCauseCode::SliceOrArrayElem);
|
||||||
// Note that we handle the len is implicitly checked while walking `arg`.
|
// Note that we handle the len is implicitly checked while walking `arg`.
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Pat(subty, _) => {
|
ty::Pat(subty, _) => {
|
||||||
self.require_sized(subty, traits::MiscObligation);
|
self.require_sized(subty, ObligationCauseCode::Misc);
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Tuple(tys) => {
|
ty::Tuple(tys) => {
|
||||||
if let Some((_last, rest)) = tys.split_last() {
|
if let Some((_last, rest)) = tys.split_last() {
|
||||||
for &elem in rest {
|
for &elem in rest {
|
||||||
self.require_sized(elem, traits::TupleElem);
|
self.require_sized(elem, ObligationCauseCode::TupleElem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -728,7 +729,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
||||||
ty::Ref(r, rty, _) => {
|
ty::Ref(r, rty, _) => {
|
||||||
// WfReference
|
// WfReference
|
||||||
if !r.has_escaping_bound_vars() && !rty.has_escaping_bound_vars() {
|
if !r.has_escaping_bound_vars() && !rty.has_escaping_bound_vars() {
|
||||||
let cause = self.cause(traits::ReferenceOutlivesReferent(t));
|
let cause = self.cause(ObligationCauseCode::ReferenceOutlivesReferent(t));
|
||||||
self.out.push(traits::Obligation::with_depth(
|
self.out.push(traits::Obligation::with_depth(
|
||||||
tcx,
|
tcx,
|
||||||
cause,
|
cause,
|
||||||
|
@ -825,7 +826,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
||||||
if let Some(principal) = data.principal_def_id() {
|
if let Some(principal) = data.principal_def_id() {
|
||||||
self.out.push(traits::Obligation::with_depth(
|
self.out.push(traits::Obligation::with_depth(
|
||||||
tcx,
|
tcx,
|
||||||
self.cause(traits::WellFormed(None)),
|
self.cause(ObligationCauseCode::WellFormed(None)),
|
||||||
self.recursion_depth,
|
self.recursion_depth,
|
||||||
self.param_env,
|
self.param_env,
|
||||||
ty::Binder::dummy(ty::PredicateKind::ObjectSafe(principal)),
|
ty::Binder::dummy(ty::PredicateKind::ObjectSafe(principal)),
|
||||||
|
@ -847,7 +848,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
||||||
// See also the comment on `fn obligations`, describing "livelock"
|
// See also the comment on `fn obligations`, describing "livelock"
|
||||||
// prevention, which happens before this can be reached.
|
// prevention, which happens before this can be reached.
|
||||||
ty::Infer(_) => {
|
ty::Infer(_) => {
|
||||||
let cause = self.cause(traits::WellFormed(None));
|
let cause = self.cause(ObligationCauseCode::WellFormed(None));
|
||||||
self.out.push(traits::Obligation::with_depth(
|
self.out.push(traits::Obligation::with_depth(
|
||||||
tcx,
|
tcx,
|
||||||
cause,
|
cause,
|
||||||
|
@ -863,7 +864,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
||||||
t.super_visit_with(self)
|
t.super_visit_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_const(&mut self, c: <TyCtxt<'tcx> as ty::Interner>::Const) -> Self::Result {
|
fn visit_const(&mut self, c: ty::Const<'tcx>) -> Self::Result {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
|
||||||
match c.kind() {
|
match c.kind() {
|
||||||
|
@ -875,7 +876,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
||||||
let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(
|
let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(
|
||||||
ty::ClauseKind::ConstEvaluatable(c),
|
ty::ClauseKind::ConstEvaluatable(c),
|
||||||
));
|
));
|
||||||
let cause = self.cause(traits::WellFormed(None));
|
let cause = self.cause(ObligationCauseCode::WellFormed(None));
|
||||||
self.out.push(traits::Obligation::with_depth(
|
self.out.push(traits::Obligation::with_depth(
|
||||||
tcx,
|
tcx,
|
||||||
cause,
|
cause,
|
||||||
|
@ -886,7 +887,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::ConstKind::Infer(_) => {
|
ty::ConstKind::Infer(_) => {
|
||||||
let cause = self.cause(traits::WellFormed(None));
|
let cause = self.cause(ObligationCauseCode::WellFormed(None));
|
||||||
|
|
||||||
self.out.push(traits::Obligation::with_depth(
|
self.out.push(traits::Obligation::with_depth(
|
||||||
tcx,
|
tcx,
|
||||||
|
@ -909,7 +910,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
||||||
let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(
|
let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(
|
||||||
ty::ClauseKind::ConstEvaluatable(c),
|
ty::ClauseKind::ConstEvaluatable(c),
|
||||||
));
|
));
|
||||||
let cause = self.cause(traits::WellFormed(None));
|
let cause = self.cause(ObligationCauseCode::WellFormed(None));
|
||||||
self.out.push(traits::Obligation::with_depth(
|
self.out.push(traits::Obligation::with_depth(
|
||||||
tcx,
|
tcx,
|
||||||
cause,
|
cause,
|
||||||
|
@ -933,7 +934,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
||||||
c.super_visit_with(self)
|
c.super_visit_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_predicate(&mut self, _p: <TyCtxt<'tcx> as ty::Interner>::Predicate) -> Self::Result {
|
fn visit_predicate(&mut self, _p: ty::Predicate<'tcx>) -> Self::Result {
|
||||||
bug!("predicate should not be checked for well-formedness");
|
bug!("predicate should not be checked for well-formedness");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue