Obligation tweaks
This commit is contained in:
parent
7f75bfa1ad
commit
1638948890
8 changed files with 28 additions and 42 deletions
|
@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::{self as hir, HirId, LangItem};
|
use rustc_hir::{self as hir, HirId, LangItem};
|
||||||
use rustc_hir_analysis::autoderef::Autoderef;
|
use rustc_hir_analysis::autoderef::Autoderef;
|
||||||
use rustc_infer::infer;
|
use rustc_infer::infer;
|
||||||
use rustc_infer::traits::{self, Obligation, ObligationCause, ObligationCauseCode};
|
use rustc_infer::traits::{Obligation, ObligationCause, ObligationCauseCode};
|
||||||
use rustc_middle::ty::adjustment::{
|
use rustc_middle::ty::adjustment::{
|
||||||
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
|
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
|
||||||
};
|
};
|
||||||
|
@ -512,7 +512,7 @@ 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, ObligationCauseCode::RustCall),
|
self.cause(sp, ObligationCauseCode::RustCall),
|
||||||
);
|
);
|
||||||
self.require_type_is_sized(ty, sp, ObligationCauseCode::RustCall);
|
self.require_type_is_sized(ty, sp, ObligationCauseCode::RustCall);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -580,11 +580,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
let mut selcx = traits::SelectionContext::new(self);
|
let mut selcx = traits::SelectionContext::new(self);
|
||||||
|
|
||||||
// Create an obligation for `Source: CoerceUnsized<Target>`.
|
// Create an obligation for `Source: CoerceUnsized<Target>`.
|
||||||
let cause =
|
let cause = self.cause(self.cause.span, ObligationCauseCode::Coercion { source, target });
|
||||||
ObligationCause::new(self.cause.span, self.body_id, ObligationCauseCode::Coercion {
|
|
||||||
source,
|
|
||||||
target,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Use a FIFO queue for this custom fulfillment procedure.
|
// Use a FIFO queue for this custom fulfillment procedure.
|
||||||
//
|
//
|
||||||
|
|
|
@ -22,7 +22,6 @@ use rustc_hir::{ExprKind, HirId, QPath};
|
||||||
use rustc_hir_analysis::hir_ty_lowering::{FeedConstTy, HirTyLowerer as _};
|
use rustc_hir_analysis::hir_ty_lowering::{FeedConstTy, HirTyLowerer as _};
|
||||||
use rustc_infer::infer;
|
use rustc_infer::infer;
|
||||||
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
||||||
use rustc_infer::traits::ObligationCause;
|
|
||||||
use rustc_infer::traits::query::NoSolution;
|
use rustc_infer::traits::query::NoSolution;
|
||||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
|
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
|
||||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||||
|
@ -1174,9 +1173,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
for err in errors {
|
for err in errors {
|
||||||
let cause = &mut err.obligation.cause;
|
let cause = &mut err.obligation.cause;
|
||||||
if let ObligationCauseCode::OpaqueReturnType(None) = cause.code() {
|
if let ObligationCauseCode::OpaqueReturnType(None) = cause.code() {
|
||||||
let new_cause = ObligationCause::new(
|
let new_cause = self.cause(
|
||||||
cause.span,
|
cause.span,
|
||||||
cause.body_id,
|
|
||||||
ObligationCauseCode::OpaqueReturnType(Some((return_expr_ty, hir_id))),
|
ObligationCauseCode::OpaqueReturnType(Some((return_expr_ty, hir_id))),
|
||||||
);
|
);
|
||||||
*cause = new_cause;
|
*cause = new_cause;
|
||||||
|
@ -3856,7 +3854,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
// Enums are anyway always sized. But just to safeguard against future
|
// Enums are anyway always sized. But just to safeguard against future
|
||||||
// language extensions, let's double-check.
|
// language extensions, let's double-check.
|
||||||
self.require_type_is_sized(field_ty, expr.span, ObligationCauseCode::Misc);
|
self.require_type_is_sized(
|
||||||
|
field_ty,
|
||||||
|
expr.span,
|
||||||
|
ObligationCauseCode::FieldSized {
|
||||||
|
adt_kind: AdtKind::Enum,
|
||||||
|
span: self.tcx.def_span(field.did),
|
||||||
|
last: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
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);
|
||||||
|
@ -3884,11 +3890,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);
|
||||||
|
|
||||||
if self.tcx.features().offset_of_slice() {
|
if self.tcx.features().offset_of_slice() {
|
||||||
self.require_type_has_static_alignment(
|
self.require_type_has_static_alignment(field_ty, expr.span);
|
||||||
field_ty,
|
|
||||||
expr.span,
|
|
||||||
ObligationCauseCode::Misc,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
self.require_type_is_sized(
|
self.require_type_is_sized(
|
||||||
field_ty,
|
field_ty,
|
||||||
|
@ -3917,11 +3919,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
{
|
{
|
||||||
if let Some(&field_ty) = tys.get(index) {
|
if let Some(&field_ty) = tys.get(index) {
|
||||||
if self.tcx.features().offset_of_slice() {
|
if self.tcx.features().offset_of_slice() {
|
||||||
self.require_type_has_static_alignment(
|
self.require_type_has_static_alignment(field_ty, expr.span);
|
||||||
field_ty,
|
|
||||||
expr.span,
|
|
||||||
ObligationCauseCode::Misc,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
self.require_type_is_sized(
|
self.require_type_is_sized(
|
||||||
field_ty,
|
field_ty,
|
||||||
|
|
|
@ -384,7 +384,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
code: traits::ObligationCauseCode<'tcx>,
|
code: traits::ObligationCauseCode<'tcx>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
) {
|
) {
|
||||||
self.register_bound(ty, def_id, traits::ObligationCause::new(span, self.body_id, code));
|
self.register_bound(ty, def_id, self.cause(span, code));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn require_type_is_sized(
|
pub(crate) fn require_type_is_sized(
|
||||||
|
@ -410,12 +410,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn require_type_has_static_alignment(
|
pub(crate) fn require_type_has_static_alignment(&self, ty: Ty<'tcx>, span: Span) {
|
||||||
&self,
|
|
||||||
ty: Ty<'tcx>,
|
|
||||||
span: Span,
|
|
||||||
code: traits::ObligationCauseCode<'tcx>,
|
|
||||||
) {
|
|
||||||
if !ty.references_error() {
|
if !ty.references_error() {
|
||||||
let tail = self.tcx.struct_tail_raw(
|
let tail = self.tcx.struct_tail_raw(
|
||||||
ty,
|
ty,
|
||||||
|
@ -434,7 +429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
// We can't be sure, let's required full `Sized`.
|
// We can't be sure, let's required full `Sized`.
|
||||||
let lang_item = self.tcx.require_lang_item(LangItem::Sized, None);
|
let lang_item = self.tcx.require_lang_item(LangItem::Sized, None);
|
||||||
self.require_type_meets(ty, span, code, lang_item);
|
self.require_type_meets(ty, span, ObligationCauseCode::Misc, lang_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -572,7 +567,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
code: traits::ObligationCauseCode<'tcx>,
|
code: traits::ObligationCauseCode<'tcx>,
|
||||||
) {
|
) {
|
||||||
// WF obligations never themselves fail, so no real need to give a detailed cause:
|
// WF obligations never themselves fail, so no real need to give a detailed cause:
|
||||||
let cause = traits::ObligationCause::new(span, self.body_id, code);
|
let cause = self.cause(span, code);
|
||||||
self.register_predicate(traits::Obligation::new(
|
self.register_predicate(traits::Obligation::new(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
cause,
|
cause,
|
||||||
|
@ -1426,9 +1421,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let bounds = self.instantiate_bounds(span, def_id, args);
|
let bounds = self.instantiate_bounds(span, def_id, args);
|
||||||
|
|
||||||
for obligation in traits::predicates_for_generics(
|
for obligation in traits::predicates_for_generics(
|
||||||
|idx, predicate_span| {
|
|idx, predicate_span| self.cause(span, code(idx, predicate_span)),
|
||||||
traits::ObligationCause::new(span, self.body_id, code(idx, predicate_span))
|
|
||||||
},
|
|
||||||
param_env,
|
param_env,
|
||||||
bounds,
|
bounds,
|
||||||
) {
|
) {
|
||||||
|
@ -1561,7 +1554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
query_result: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
|
query_result: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
|
||||||
) -> InferResult<'tcx, Ty<'tcx>> {
|
) -> InferResult<'tcx, Ty<'tcx>> {
|
||||||
self.instantiate_query_response_and_region_obligations(
|
self.instantiate_query_response_and_region_obligations(
|
||||||
&traits::ObligationCause::misc(span, self.body_id),
|
&self.misc(span),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
original_values,
|
original_values,
|
||||||
query_result,
|
query_result,
|
||||||
|
|
|
@ -207,7 +207,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.register_wf_obligation(
|
self.register_wf_obligation(
|
||||||
fn_input_ty.into(),
|
fn_input_ty.into(),
|
||||||
arg_expr.span,
|
arg_expr.span,
|
||||||
ObligationCauseCode::Misc,
|
ObligationCauseCode::WellFormed(None),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -601,7 +601,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||||
self.call_expr.hir_id,
|
self.call_expr.hir_id,
|
||||||
idx,
|
idx,
|
||||||
);
|
);
|
||||||
traits::ObligationCause::new(self.span, self.body_id, code)
|
self.cause(self.span, code)
|
||||||
},
|
},
|
||||||
self.param_env,
|
self.param_env,
|
||||||
method_predicates,
|
method_predicates,
|
||||||
|
|
|
@ -1739,8 +1739,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
trait_ref: ty::TraitRef<'tcx>,
|
trait_ref: ty::TraitRef<'tcx>,
|
||||||
) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
|
) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
|
||||||
let cause = traits::ObligationCause::misc(self.span, self.body_id);
|
let obligation =
|
||||||
let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, trait_ref);
|
traits::Obligation::new(self.tcx, self.misc(self.span), self.param_env, trait_ref);
|
||||||
traits::SelectionContext::new(self).select(&obligation)
|
traits::SelectionContext::new(self).select(&obligation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1841,7 +1841,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
self.scope_expr_id,
|
self.scope_expr_id,
|
||||||
idx,
|
idx,
|
||||||
);
|
);
|
||||||
ObligationCause::new(self.span, self.body_id, code)
|
self.cause(self.span, code)
|
||||||
},
|
},
|
||||||
self.param_env,
|
self.param_env,
|
||||||
impl_bounds,
|
impl_bounds,
|
||||||
|
|
|
@ -105,8 +105,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::Misc);
|
let obligation = Obligation::new(self.tcx, self.misc(span), 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;
|
||||||
}
|
}
|
||||||
|
@ -3489,7 +3488,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let pred = ty::TraitRef::new(self.tcx, unpin_trait, [*rcvr_ty]);
|
let pred = ty::TraitRef::new(self.tcx, unpin_trait, [*rcvr_ty]);
|
||||||
let unpin = self.predicate_must_hold_considering_regions(&Obligation::new(
|
let unpin = self.predicate_must_hold_considering_regions(&Obligation::new(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
ObligationCause::misc(rcvr.span, self.body_id),
|
self.misc(rcvr.span),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
pred,
|
pred,
|
||||||
));
|
));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue