Add bound_impl_subject and bound_return_ty
This commit is contained in:
parent
96a69dce2c
commit
955fcad758
8 changed files with 26 additions and 21 deletions
|
@ -13,7 +13,7 @@ use rustc_middle::mir::pretty::display_allocation;
|
||||||
use rustc_middle::traits::Reveal;
|
use rustc_middle::traits::Reveal;
|
||||||
use rustc_middle::ty::layout::LayoutOf;
|
use rustc_middle::ty::layout::LayoutOf;
|
||||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||||
use rustc_middle::ty::{self, subst::Subst, EarlyBinder, TyCtxt};
|
use rustc_middle::ty::{self, subst::Subst, TyCtxt};
|
||||||
use rustc_span::source_map::Span;
|
use rustc_span::source_map::Span;
|
||||||
use rustc_target::abi::{self, Abi};
|
use rustc_target::abi::{self, Abi};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
@ -45,7 +45,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
|
||||||
"Unexpected DefKind: {:?}",
|
"Unexpected DefKind: {:?}",
|
||||||
ecx.tcx.def_kind(cid.instance.def_id())
|
ecx.tcx.def_kind(cid.instance.def_id())
|
||||||
);
|
);
|
||||||
let layout = ecx.layout_of(EarlyBinder(body.return_ty()).subst(tcx, cid.instance.substs))?;
|
let layout = ecx.layout_of(body.bound_return_ty().subst(tcx, cid.instance.substs))?;
|
||||||
assert!(!layout.is_unsized());
|
assert!(!layout.is_unsized());
|
||||||
let ret = ecx.allocate(layout, MemoryKind::Stack)?;
|
let ret = ecx.allocate(layout, MemoryKind::Stack)?;
|
||||||
|
|
||||||
|
|
|
@ -431,6 +431,12 @@ impl<'tcx> Body<'tcx> {
|
||||||
self.local_decls[RETURN_PLACE].ty
|
self.local_decls[RETURN_PLACE].ty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the return type; it always return first element from `local_decls` array.
|
||||||
|
#[inline]
|
||||||
|
pub fn bound_return_ty(&self) -> ty::EarlyBinder<Ty<'tcx>> {
|
||||||
|
ty::EarlyBinder(self.local_decls[RETURN_PLACE].ty)
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets the location of the terminator for the given block.
|
/// Gets the location of the terminator for the given block.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn terminator_loc(&self, bb: BasicBlock) -> Location {
|
pub fn terminator_loc(&self, bb: BasicBlock) -> Location {
|
||||||
|
|
|
@ -694,6 +694,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
) -> ty::EarlyBinder<ty::generics::GenericPredicates<'tcx>> {
|
) -> ty::EarlyBinder<ty::generics::GenericPredicates<'tcx>> {
|
||||||
ty::EarlyBinder(self.explicit_predicates_of(def_id))
|
ty::EarlyBinder(self.explicit_predicates_of(def_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn bound_impl_subject(self, def_id: DefId) -> ty::EarlyBinder<ty::ImplSubject<'tcx>> {
|
||||||
|
ty::EarlyBinder(self.impl_subject(def_id))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct OpaqueTypeExpander<'tcx> {
|
struct OpaqueTypeExpander<'tcx> {
|
||||||
|
|
|
@ -18,9 +18,7 @@ use rustc_middle::mir::{
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
|
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
|
||||||
use rustc_middle::ty::subst::{InternalSubsts, Subst};
|
use rustc_middle::ty::subst::{InternalSubsts, Subst};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeVisitable};
|
||||||
self, ConstKind, EarlyBinder, Instance, ParamEnv, Ty, TyCtxt, TypeVisitable,
|
|
||||||
};
|
|
||||||
use rustc_span::{def_id::DefId, Span};
|
use rustc_span::{def_id::DefId, Span};
|
||||||
use rustc_target::abi::{self, HasDataLayout, Size, TargetDataLayout};
|
use rustc_target::abi::{self, HasDataLayout, Size, TargetDataLayout};
|
||||||
use rustc_target::spec::abi::Abi as CallAbi;
|
use rustc_target::spec::abi::Abi as CallAbi;
|
||||||
|
@ -387,7 +385,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
);
|
);
|
||||||
|
|
||||||
let ret_layout = ecx
|
let ret_layout = ecx
|
||||||
.layout_of(EarlyBinder(body.return_ty()).subst(tcx, substs))
|
.layout_of(body.bound_return_ty().subst(tcx, substs))
|
||||||
.ok()
|
.ok()
|
||||||
// Don't bother allocating memory for large values.
|
// Don't bother allocating memory for large values.
|
||||||
// I don't know how return types can seem to be unsized but this happens in the
|
// I don't know how return types can seem to be unsized but this happens in the
|
||||||
|
|
|
@ -23,8 +23,7 @@ use rustc_middle::mir::{
|
||||||
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
|
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
|
||||||
use rustc_middle::ty::subst::{InternalSubsts, Subst};
|
use rustc_middle::ty::subst::{InternalSubsts, Subst};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, ConstInt, ConstKind, EarlyBinder, Instance, ParamEnv, ScalarInt, Ty, TyCtxt,
|
self, ConstInt, ConstKind, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeVisitable,
|
||||||
TypeVisitable,
|
|
||||||
};
|
};
|
||||||
use rustc_session::lint;
|
use rustc_session::lint;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
@ -196,7 +195,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
);
|
);
|
||||||
|
|
||||||
let ret_layout = ecx
|
let ret_layout = ecx
|
||||||
.layout_of(EarlyBinder(body.return_ty()).subst(tcx, substs))
|
.layout_of(body.bound_return_ty().subst(tcx, substs))
|
||||||
.ok()
|
.ok()
|
||||||
// Don't bother allocating memory for large values.
|
// Don't bother allocating memory for large values.
|
||||||
// I don't know how return types can seem to be unsized but this happens in the
|
// I don't know how return types can seem to be unsized but this happens in the
|
||||||
|
|
|
@ -32,7 +32,7 @@ use rustc_middle::traits::select::OverflowError;
|
||||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||||
use rustc_middle::ty::subst::Subst;
|
use rustc_middle::ty::subst::Subst;
|
||||||
use rustc_middle::ty::visit::{MaxUniverse, TypeVisitable};
|
use rustc_middle::ty::visit::{MaxUniverse, TypeVisitable};
|
||||||
use rustc_middle::ty::{self, EarlyBinder, Term, ToPredicate, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Term, ToPredicate, Ty, TyCtxt};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
@ -2005,16 +2005,16 @@ fn confirm_impl_candidate<'cx, 'tcx>(
|
||||||
let substs = obligation.predicate.substs.rebase_onto(tcx, trait_def_id, substs);
|
let substs = obligation.predicate.substs.rebase_onto(tcx, trait_def_id, substs);
|
||||||
let substs =
|
let substs =
|
||||||
translate_substs(selcx.infcx(), param_env, impl_def_id, substs, assoc_ty.defining_node);
|
translate_substs(selcx.infcx(), param_env, impl_def_id, substs, assoc_ty.defining_node);
|
||||||
let ty = tcx.type_of(assoc_ty.item.def_id);
|
let ty = tcx.bound_type_of(assoc_ty.item.def_id);
|
||||||
let is_const = matches!(tcx.def_kind(assoc_ty.item.def_id), DefKind::AssocConst);
|
let is_const = matches!(tcx.def_kind(assoc_ty.item.def_id), DefKind::AssocConst);
|
||||||
let term: ty::Term<'tcx> = if is_const {
|
let term: ty::EarlyBinder<ty::Term<'tcx>> = if is_const {
|
||||||
let identity_substs =
|
let identity_substs =
|
||||||
crate::traits::InternalSubsts::identity_for_item(tcx, assoc_ty.item.def_id);
|
crate::traits::InternalSubsts::identity_for_item(tcx, assoc_ty.item.def_id);
|
||||||
let did = ty::WithOptConstParam::unknown(assoc_ty.item.def_id);
|
let did = ty::WithOptConstParam::unknown(assoc_ty.item.def_id);
|
||||||
let kind = ty::ConstKind::Unevaluated(ty::Unevaluated::new(did, identity_substs));
|
let kind = ty::ConstKind::Unevaluated(ty::Unevaluated::new(did, identity_substs));
|
||||||
tcx.mk_const(ty::ConstS { ty, kind }).into()
|
ty.map_bound(|ty| tcx.mk_const(ty::ConstS { ty, kind }).into())
|
||||||
} else {
|
} else {
|
||||||
ty.into()
|
ty.map_bound(|ty| ty.into())
|
||||||
};
|
};
|
||||||
if substs.len() != tcx.generics_of(assoc_ty.item.def_id).count() {
|
if substs.len() != tcx.generics_of(assoc_ty.item.def_id).count() {
|
||||||
let err = tcx.ty_error_with_message(
|
let err = tcx.ty_error_with_message(
|
||||||
|
@ -2024,7 +2024,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
|
||||||
Progress { term: err.into(), obligations: nested }
|
Progress { term: err.into(), obligations: nested }
|
||||||
} else {
|
} else {
|
||||||
assoc_ty_own_obligations(selcx, obligation, &mut nested);
|
assoc_ty_own_obligations(selcx, obligation, &mut nested);
|
||||||
Progress { term: EarlyBinder(term).subst(tcx, substs), obligations: nested }
|
Progress { term: term.subst(tcx, substs), obligations: nested }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use smallvec::SmallVec;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::ty::subst::{GenericArg, Subst, SubstsRef};
|
use rustc_middle::ty::subst::{GenericArg, Subst, SubstsRef};
|
||||||
use rustc_middle::ty::{self, EarlyBinder, ImplSubject, ToPredicate, Ty, TyCtxt, TypeVisitable};
|
use rustc_middle::ty::{self, ImplSubject, ToPredicate, Ty, TyCtxt, TypeVisitable};
|
||||||
|
|
||||||
use super::{Normalized, Obligation, ObligationCause, PredicateObligation, SelectionContext};
|
use super::{Normalized, Obligation, ObligationCause, PredicateObligation, SelectionContext};
|
||||||
pub use rustc_infer::traits::{self, util::*};
|
pub use rustc_infer::traits::{self, util::*};
|
||||||
|
@ -200,8 +200,8 @@ pub fn impl_subject_and_oblig<'a, 'tcx>(
|
||||||
impl_def_id: DefId,
|
impl_def_id: DefId,
|
||||||
impl_substs: SubstsRef<'tcx>,
|
impl_substs: SubstsRef<'tcx>,
|
||||||
) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) {
|
) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) {
|
||||||
let subject = selcx.tcx().impl_subject(impl_def_id);
|
let subject = selcx.tcx().bound_impl_subject(impl_def_id);
|
||||||
let subject = EarlyBinder(subject).subst(selcx.tcx(), impl_substs);
|
let subject = subject.subst(selcx.tcx(), impl_substs);
|
||||||
let Normalized { value: subject, obligations: normalization_obligations1 } =
|
let Normalized { value: subject, obligations: normalization_obligations1 } =
|
||||||
super::normalize(selcx, param_env, ObligationCause::dummy(), subject);
|
super::normalize(selcx, param_env, ObligationCause::dummy(), subject);
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,7 @@ use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::ty::subst::Subst;
|
use rustc_middle::ty::subst::Subst;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt};
|
||||||
self, Binder, EarlyBinder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt,
|
|
||||||
};
|
|
||||||
use rustc_trait_selection::traits;
|
use rustc_trait_selection::traits;
|
||||||
|
|
||||||
fn sized_constraint_for_ty<'tcx>(
|
fn sized_constraint_for_ty<'tcx>(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue