Auto merge of #26354 - jroesch:remove-param-bounds-take-n, r=nikomatsakis
This pull request removes `ParamBounds` a old holdover in the type checker that we (@nikomatsakis and I) had wanted to remove. I'm not sure if the current form is the best possible refactor but I figured we can use this as a place to discuss it. r? @nikomatsakis
This commit is contained in:
commit
997bd334fb
9 changed files with 100 additions and 226 deletions
|
|
@ -195,15 +195,6 @@ pub fn parse_substs_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum, pos: us
|
|||
parse_substs(&mut st, conv)
|
||||
}
|
||||
|
||||
pub fn parse_bounds_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum,
|
||||
pos: usize, tcx: &ty::ctxt<'tcx>, conv: F)
|
||||
-> ty::ParamBounds<'tcx> where
|
||||
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
|
||||
{
|
||||
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
|
||||
parse_bounds(&mut st, conv)
|
||||
}
|
||||
|
||||
pub fn parse_existential_bounds_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum,
|
||||
pos: usize, tcx: &ty::ctxt<'tcx>, conv: F)
|
||||
-> ty::ExistentialBounds<'tcx> where
|
||||
|
|
@ -879,11 +870,23 @@ fn parse_existential_bounds_<'a,'tcx, F>(st: &mut PState<'a,'tcx>,
|
|||
-> ty::ExistentialBounds<'tcx> where
|
||||
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
|
||||
{
|
||||
let ty::ParamBounds { trait_bounds, mut region_bounds, builtin_bounds, projection_bounds } =
|
||||
parse_bounds_(st, conv);
|
||||
assert_eq!(region_bounds.len(), 1);
|
||||
assert_eq!(trait_bounds.len(), 0);
|
||||
let region_bound = region_bounds.pop().unwrap();
|
||||
let builtin_bounds = parse_builtin_bounds_(st, conv);
|
||||
let region_bound = parse_region_(st, conv);
|
||||
let mut projection_bounds = Vec::new();
|
||||
|
||||
loop {
|
||||
match next(st) {
|
||||
'P' => {
|
||||
projection_bounds.push(
|
||||
ty::Binder(parse_projection_predicate_(st, conv)));
|
||||
}
|
||||
'.' => { break; }
|
||||
c => {
|
||||
panic!("parse_bounds: bad bounds ('{}')", c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ty::ExistentialBounds { region_bound: region_bound,
|
||||
builtin_bounds: builtin_bounds,
|
||||
projection_bounds: projection_bounds };
|
||||
|
|
@ -923,60 +926,3 @@ fn parse_builtin_bounds_<F>(st: &mut PState, _conv: &mut F) -> ty::BuiltinBounds
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_bounds<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, mut conv: F)
|
||||
-> ty::ParamBounds<'tcx> where
|
||||
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
|
||||
{
|
||||
parse_bounds_(st, &mut conv)
|
||||
}
|
||||
|
||||
fn parse_bounds_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
|
||||
-> ty::ParamBounds<'tcx> where
|
||||
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
|
||||
{
|
||||
let builtin_bounds = parse_builtin_bounds_(st, conv);
|
||||
|
||||
let region_bounds = parse_region_bounds_(st, conv);
|
||||
|
||||
let mut param_bounds = ty::ParamBounds {
|
||||
region_bounds: region_bounds,
|
||||
builtin_bounds: builtin_bounds,
|
||||
trait_bounds: Vec::new(),
|
||||
projection_bounds: Vec::new(),
|
||||
};
|
||||
|
||||
|
||||
loop {
|
||||
match next(st) {
|
||||
'I' => {
|
||||
param_bounds.trait_bounds.push(
|
||||
ty::Binder(parse_trait_ref_(st, conv)));
|
||||
}
|
||||
'P' => {
|
||||
param_bounds.projection_bounds.push(
|
||||
ty::Binder(parse_projection_predicate_(st, conv)));
|
||||
}
|
||||
'.' => {
|
||||
return param_bounds;
|
||||
}
|
||||
c => {
|
||||
panic!("parse_bounds: bad bounds ('{}')", c)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_region_bounds_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
|
||||
-> Vec<ty::Region> where
|
||||
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
|
||||
{
|
||||
let mut region_bounds = Vec::new();
|
||||
loop {
|
||||
match next(st) {
|
||||
'R' => { region_bounds.push(parse_region_(st, conv)); }
|
||||
'.' => { return region_bounds; }
|
||||
c => { panic!("parse_bounds: bad bounds ('{}')", c); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -380,23 +380,9 @@ pub fn enc_builtin_bounds(w: &mut Encoder, _cx: &ctxt, bs: &ty::BuiltinBounds) {
|
|||
pub fn enc_existential_bounds<'a,'tcx>(w: &mut Encoder,
|
||||
cx: &ctxt<'a,'tcx>,
|
||||
bs: &ty::ExistentialBounds<'tcx>) {
|
||||
let param_bounds = ty::ParamBounds { trait_bounds: vec!(),
|
||||
region_bounds: vec!(bs.region_bound),
|
||||
builtin_bounds: bs.builtin_bounds,
|
||||
projection_bounds: bs.projection_bounds.clone() };
|
||||
enc_bounds(w, cx, ¶m_bounds);
|
||||
}
|
||||
|
||||
pub fn enc_bounds<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
|
||||
bs: &ty::ParamBounds<'tcx>) {
|
||||
enc_builtin_bounds(w, cx, &bs.builtin_bounds);
|
||||
|
||||
enc_region_bounds(w, cx, &bs.region_bounds);
|
||||
|
||||
for tp in &bs.trait_bounds {
|
||||
mywrite!(w, "I");
|
||||
enc_trait_ref(w, cx, tp.0);
|
||||
}
|
||||
enc_region(w, cx, bs.region_bound);
|
||||
|
||||
for tp in &bs.projection_bounds {
|
||||
mywrite!(w, "P");
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
use middle::infer::{InferCtxt, GenericKind};
|
||||
use middle::subst::Substs;
|
||||
use middle::traits;
|
||||
use middle::ty::{self, RegionEscape, ToPolyTraitRef, Ty};
|
||||
use middle::ty::{self, RegionEscape, ToPolyTraitRef, AsPredicate, Ty};
|
||||
use middle::ty_fold::{TypeFoldable, TypeFolder};
|
||||
|
||||
use syntax::ast;
|
||||
|
|
@ -444,13 +444,8 @@ pub fn object_region_bounds<'tcx>(
|
|||
let substs = tcx.mk_substs(principal.0.substs.with_self_ty(open_ty));
|
||||
let trait_refs = vec!(ty::Binder(ty::TraitRef::new(principal.0.def_id, substs)));
|
||||
|
||||
let param_bounds = ty::ParamBounds {
|
||||
region_bounds: Vec::new(),
|
||||
builtin_bounds: others,
|
||||
trait_bounds: trait_refs,
|
||||
projection_bounds: Vec::new(), // not relevant to computing region bounds
|
||||
};
|
||||
let mut predicates = others.to_predicates(tcx, open_ty);
|
||||
predicates.extend(trait_refs.iter().map(|t| t.as_predicate()));
|
||||
|
||||
let predicates = ty::predicates(tcx, open_ty, ¶m_bounds);
|
||||
ty::required_region_bounds(tcx, open_ty, predicates)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1847,21 +1847,8 @@ pub enum type_err<'tcx> {
|
|||
terr_projection_bounds_length(expected_found<usize>),
|
||||
}
|
||||
|
||||
/// Bounds suitable for a named type parameter like `A` in `fn foo<A>`
|
||||
/// as well as the existential type parameter in an object type.
|
||||
#[derive(PartialEq, Eq, Hash, Clone)]
|
||||
pub struct ParamBounds<'tcx> {
|
||||
pub region_bounds: Vec<ty::Region>,
|
||||
pub builtin_bounds: BuiltinBounds,
|
||||
pub trait_bounds: Vec<PolyTraitRef<'tcx>>,
|
||||
pub projection_bounds: Vec<PolyProjectionPredicate<'tcx>>,
|
||||
}
|
||||
|
||||
/// Bounds suitable for an existentially quantified type parameter
|
||||
/// such as those that appear in object types or closure types. The
|
||||
/// major difference between this case and `ParamBounds` is that
|
||||
/// general purpose trait bounds are omitted and there must be
|
||||
/// *exactly one* region.
|
||||
/// such as those that appear in object types or closure types.
|
||||
#[derive(PartialEq, Eq, Hash, Clone)]
|
||||
pub struct ExistentialBounds<'tcx> {
|
||||
pub region_bound: ty::Region,
|
||||
|
|
@ -1873,13 +1860,24 @@ pub struct ExistentialBounds<'tcx> {
|
|||
pub struct BuiltinBounds(EnumSet<BuiltinBound>);
|
||||
|
||||
impl BuiltinBounds {
|
||||
pub fn empty() -> BuiltinBounds {
|
||||
pub fn empty() -> BuiltinBounds {
|
||||
BuiltinBounds(EnumSet::new())
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> enum_set::Iter<BuiltinBound> {
|
||||
self.into_iter()
|
||||
}
|
||||
|
||||
pub fn to_predicates<'tcx>(&self,
|
||||
tcx: &ty::ctxt<'tcx>,
|
||||
self_ty: Ty<'tcx>) -> Vec<Predicate<'tcx>> {
|
||||
self.iter().filter_map(|builtin_bound|
|
||||
match traits::trait_ref_for_builtin_bound(tcx, builtin_bound, self_ty) {
|
||||
Ok(trait_ref) => Some(trait_ref.as_predicate()),
|
||||
Err(ErrorReported) => { None }
|
||||
}
|
||||
).collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::Deref for BuiltinBounds {
|
||||
|
|
@ -3704,17 +3702,6 @@ impl<'tcx> ItemSubsts<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ParamBounds<'tcx> {
|
||||
pub fn empty() -> ParamBounds<'tcx> {
|
||||
ParamBounds {
|
||||
builtin_bounds: BuiltinBounds::empty(),
|
||||
trait_bounds: Vec::new(),
|
||||
region_bounds: Vec::new(),
|
||||
projection_bounds: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Type utilities
|
||||
|
||||
pub fn type_is_nil(ty: Ty) -> bool {
|
||||
|
|
@ -6143,39 +6130,6 @@ pub fn lookup_super_predicates<'tcx>(cx: &ctxt<'tcx>, did: ast::DefId)
|
|||
|| csearch::get_super_predicates(cx, did))
|
||||
}
|
||||
|
||||
pub fn predicates<'tcx>(
|
||||
tcx: &ctxt<'tcx>,
|
||||
param_ty: Ty<'tcx>,
|
||||
bounds: &ParamBounds<'tcx>)
|
||||
-> Vec<Predicate<'tcx>>
|
||||
{
|
||||
let mut vec = Vec::new();
|
||||
|
||||
for builtin_bound in &bounds.builtin_bounds {
|
||||
match traits::trait_ref_for_builtin_bound(tcx, builtin_bound, param_ty) {
|
||||
Ok(trait_ref) => { vec.push(trait_ref.as_predicate()); }
|
||||
Err(ErrorReported) => { }
|
||||
}
|
||||
}
|
||||
|
||||
for ®ion_bound in &bounds.region_bounds {
|
||||
// account for the binder being introduced below; no need to shift `param_ty`
|
||||
// because, at present at least, it can only refer to early-bound regions
|
||||
let region_bound = ty_fold::shift_region(region_bound, 1);
|
||||
vec.push(ty::Binder(ty::OutlivesPredicate(param_ty, region_bound)).as_predicate());
|
||||
}
|
||||
|
||||
for bound_trait_ref in &bounds.trait_bounds {
|
||||
vec.push(bound_trait_ref.as_predicate());
|
||||
}
|
||||
|
||||
for projection in &bounds.projection_bounds {
|
||||
vec.push(projection.as_predicate());
|
||||
}
|
||||
|
||||
vec
|
||||
}
|
||||
|
||||
/// Get the attributes of a definition.
|
||||
pub fn get_attrs<'tcx>(tcx: &'tcx ctxt, did: DefId)
|
||||
-> Cow<'tcx, [ast::Attribute]> {
|
||||
|
|
|
|||
|
|
@ -350,17 +350,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialBounds<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ParamBounds<'tcx> {
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::ParamBounds<'tcx> {
|
||||
ty::ParamBounds {
|
||||
region_bounds: self.region_bounds.fold_with(folder),
|
||||
builtin_bounds: self.builtin_bounds.fold_with(folder),
|
||||
trait_bounds: self.trait_bounds.fold_with(folder),
|
||||
projection_bounds: self.projection_bounds.fold_with(folder),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::TypeParameterDef<'tcx> {
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::TypeParameterDef<'tcx> {
|
||||
ty::TypeParameterDef {
|
||||
|
|
|
|||
|
|
@ -347,23 +347,6 @@ impl fmt::Debug for subst::RegionSubsts {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'tcx> fmt::Debug for ty::ParamBounds<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(f, "{:?}", self.builtin_bounds));
|
||||
let mut bounds = self.trait_bounds.iter();
|
||||
if self.builtin_bounds.is_empty() {
|
||||
if let Some(bound) = bounds.next() {
|
||||
try!(write!(f, "{:?}", bound));
|
||||
}
|
||||
}
|
||||
for bound in bounds {
|
||||
try!(write!(f, " + {:?}", bound));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// when printing out the debug representation, we don't need
|
||||
|
|
@ -539,22 +522,6 @@ impl<'tcx> fmt::Debug for ty::MethodObject<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Display for ty::ParamBounds<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(f, "{}", self.builtin_bounds));
|
||||
let mut bounds = self.trait_bounds.iter();
|
||||
if self.builtin_bounds.is_empty() {
|
||||
if let Some(bound) = bounds.next() {
|
||||
try!(write!(f, "{}", bound));
|
||||
}
|
||||
}
|
||||
for bound in bounds {
|
||||
try!(write!(f, " + {}", bound));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Debug for ty::ExistentialBounds<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut empty = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue