Skip to content

Commit 955fcad

Browse files
committed
Add bound_impl_subject and bound_return_ty
1 parent 96a69dc commit 955fcad

File tree

8 files changed

+26
-21
lines changed

8 files changed

+26
-21
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::mir::pretty::display_allocation;
1313
use rustc_middle::traits::Reveal;
1414
use rustc_middle::ty::layout::LayoutOf;
1515
use rustc_middle::ty::print::with_no_trimmed_paths;
16-
use rustc_middle::ty::{self, subst::Subst, EarlyBinder, TyCtxt};
16+
use rustc_middle::ty::{self, subst::Subst, TyCtxt};
1717
use rustc_span::source_map::Span;
1818
use rustc_target::abi::{self, Abi};
1919
use std::borrow::Cow;
@@ -45,7 +45,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
4545
"Unexpected DefKind: {:?}",
4646
ecx.tcx.def_kind(cid.instance.def_id())
4747
);
48-
let layout = ecx.layout_of(EarlyBinder(body.return_ty()).subst(tcx, cid.instance.substs))?;
48+
let layout = ecx.layout_of(body.bound_return_ty().subst(tcx, cid.instance.substs))?;
4949
assert!(!layout.is_unsized());
5050
let ret = ecx.allocate(layout, MemoryKind::Stack)?;
5151

compiler/rustc_middle/src/mir/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,12 @@ impl<'tcx> Body<'tcx> {
431431
self.local_decls[RETURN_PLACE].ty
432432
}
433433

434+
/// Returns the return type; it always return first element from `local_decls` array.
435+
#[inline]
436+
pub fn bound_return_ty(&self) -> ty::EarlyBinder<Ty<'tcx>> {
437+
ty::EarlyBinder(self.local_decls[RETURN_PLACE].ty)
438+
}
439+
434440
/// Gets the location of the terminator for the given block.
435441
#[inline]
436442
pub fn terminator_loc(&self, bb: BasicBlock) -> Location {

compiler/rustc_middle/src/ty/util.rs

+4
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,10 @@ impl<'tcx> TyCtxt<'tcx> {
694694
) -> ty::EarlyBinder<ty::generics::GenericPredicates<'tcx>> {
695695
ty::EarlyBinder(self.explicit_predicates_of(def_id))
696696
}
697+
698+
pub fn bound_impl_subject(self, def_id: DefId) -> ty::EarlyBinder<ty::ImplSubject<'tcx>> {
699+
ty::EarlyBinder(self.impl_subject(def_id))
700+
}
697701
}
698702

699703
struct OpaqueTypeExpander<'tcx> {

compiler/rustc_mir_transform/src/const_prop.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use rustc_middle::mir::{
1818
};
1919
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
2020
use rustc_middle::ty::subst::{InternalSubsts, Subst};
21-
use rustc_middle::ty::{
22-
self, ConstKind, EarlyBinder, Instance, ParamEnv, Ty, TyCtxt, TypeVisitable,
23-
};
21+
use rustc_middle::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeVisitable};
2422
use rustc_span::{def_id::DefId, Span};
2523
use rustc_target::abi::{self, HasDataLayout, Size, TargetDataLayout};
2624
use rustc_target::spec::abi::Abi as CallAbi;
@@ -387,7 +385,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
387385
);
388386

389387
let ret_layout = ecx
390-
.layout_of(EarlyBinder(body.return_ty()).subst(tcx, substs))
388+
.layout_of(body.bound_return_ty().subst(tcx, substs))
391389
.ok()
392390
// Don't bother allocating memory for large values.
393391
// I don't know how return types can seem to be unsized but this happens in the

compiler/rustc_mir_transform/src/const_prop_lint.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ use rustc_middle::mir::{
2323
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
2424
use rustc_middle::ty::subst::{InternalSubsts, Subst};
2525
use rustc_middle::ty::{
26-
self, ConstInt, ConstKind, EarlyBinder, Instance, ParamEnv, ScalarInt, Ty, TyCtxt,
27-
TypeVisitable,
26+
self, ConstInt, ConstKind, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeVisitable,
2827
};
2928
use rustc_session::lint;
3029
use rustc_span::Span;
@@ -196,7 +195,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
196195
);
197196

198197
let ret_layout = ecx
199-
.layout_of(EarlyBinder(body.return_ty()).subst(tcx, substs))
198+
.layout_of(body.bound_return_ty().subst(tcx, substs))
200199
.ok()
201200
// Don't bother allocating memory for large values.
202201
// I don't know how return types can seem to be unsized but this happens in the

compiler/rustc_trait_selection/src/traits/project.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc_middle::traits::select::OverflowError;
3232
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
3333
use rustc_middle::ty::subst::Subst;
3434
use rustc_middle::ty::visit::{MaxUniverse, TypeVisitable};
35-
use rustc_middle::ty::{self, EarlyBinder, Term, ToPredicate, Ty, TyCtxt};
35+
use rustc_middle::ty::{self, Term, ToPredicate, Ty, TyCtxt};
3636
use rustc_span::symbol::sym;
3737

3838
use std::collections::BTreeMap;
@@ -2005,16 +2005,16 @@ fn confirm_impl_candidate<'cx, 'tcx>(
20052005
let substs = obligation.predicate.substs.rebase_onto(tcx, trait_def_id, substs);
20062006
let substs =
20072007
translate_substs(selcx.infcx(), param_env, impl_def_id, substs, assoc_ty.defining_node);
2008-
let ty = tcx.type_of(assoc_ty.item.def_id);
2008+
let ty = tcx.bound_type_of(assoc_ty.item.def_id);
20092009
let is_const = matches!(tcx.def_kind(assoc_ty.item.def_id), DefKind::AssocConst);
2010-
let term: ty::Term<'tcx> = if is_const {
2010+
let term: ty::EarlyBinder<ty::Term<'tcx>> = if is_const {
20112011
let identity_substs =
20122012
crate::traits::InternalSubsts::identity_for_item(tcx, assoc_ty.item.def_id);
20132013
let did = ty::WithOptConstParam::unknown(assoc_ty.item.def_id);
20142014
let kind = ty::ConstKind::Unevaluated(ty::Unevaluated::new(did, identity_substs));
2015-
tcx.mk_const(ty::ConstS { ty, kind }).into()
2015+
ty.map_bound(|ty| tcx.mk_const(ty::ConstS { ty, kind }).into())
20162016
} else {
2017-
ty.into()
2017+
ty.map_bound(|ty| ty.into())
20182018
};
20192019
if substs.len() != tcx.generics_of(assoc_ty.item.def_id).count() {
20202020
let err = tcx.ty_error_with_message(
@@ -2024,7 +2024,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
20242024
Progress { term: err.into(), obligations: nested }
20252025
} else {
20262026
assoc_ty_own_obligations(selcx, obligation, &mut nested);
2027-
Progress { term: EarlyBinder(term).subst(tcx, substs), obligations: nested }
2027+
Progress { term: term.subst(tcx, substs), obligations: nested }
20282028
}
20292029
}
20302030

compiler/rustc_trait_selection/src/traits/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use smallvec::SmallVec;
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_hir::def_id::DefId;
88
use rustc_middle::ty::subst::{GenericArg, Subst, SubstsRef};
9-
use rustc_middle::ty::{self, EarlyBinder, ImplSubject, ToPredicate, Ty, TyCtxt, TypeVisitable};
9+
use rustc_middle::ty::{self, ImplSubject, ToPredicate, Ty, TyCtxt, TypeVisitable};
1010

1111
use super::{Normalized, Obligation, ObligationCause, PredicateObligation, SelectionContext};
1212
pub use rustc_infer::traits::{self, util::*};
@@ -200,8 +200,8 @@ pub fn impl_subject_and_oblig<'a, 'tcx>(
200200
impl_def_id: DefId,
201201
impl_substs: SubstsRef<'tcx>,
202202
) -> (ImplSubject<'tcx>, impl Iterator<Item = PredicateObligation<'tcx>>) {
203-
let subject = selcx.tcx().impl_subject(impl_def_id);
204-
let subject = EarlyBinder(subject).subst(selcx.tcx(), impl_substs);
203+
let subject = selcx.tcx().bound_impl_subject(impl_def_id);
204+
let subject = subject.subst(selcx.tcx(), impl_substs);
205205
let Normalized { value: subject, obligations: normalization_obligations1 } =
206206
super::normalize(selcx, param_env, ObligationCause::dummy(), subject);
207207

compiler/rustc_ty_utils/src/ty.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use rustc_data_structures::fx::FxIndexSet;
22
use rustc_hir as hir;
33
use rustc_hir::def_id::DefId;
44
use rustc_middle::ty::subst::Subst;
5-
use rustc_middle::ty::{
6-
self, Binder, EarlyBinder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt,
7-
};
5+
use rustc_middle::ty::{self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt};
86
use rustc_trait_selection::traits;
97

108
fn sized_constraint_for_ty<'tcx>(

0 commit comments

Comments
 (0)