diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index a9c4f0ddd8c2..6efc80ed8d34 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -707,9 +707,8 @@ impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> { { let types = self.read_to_vec(|this| Ok(f(this))).unwrap(); let selfs = self.read_to_vec(|this| Ok(f(this))).unwrap(); - let assocs = self.read_to_vec(|this| Ok(f(this))).unwrap(); let fns = self.read_to_vec(|this| Ok(f(this))).unwrap(); - VecPerParamSpace::new(types, selfs, assocs, fns) + VecPerParamSpace::new(types, selfs, fns) } fn read_vtable_res_with_key(&mut self, diff --git a/src/librustc/middle/infer/mod.rs b/src/librustc/middle/infer/mod.rs index cf9520ecfbbd..386768bd9d6f 100644 --- a/src/librustc/middle/infer/mod.rs +++ b/src/librustc/middle/infer/mod.rs @@ -864,10 +864,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let region_param_defs = generics.regions.get_slice(subst::TypeSpace); let regions = self.region_vars_for_defs(span, region_param_defs); - let assoc_type_parameter_count = generics.types.len(subst::AssocSpace); - let assoc_type_parameters = self.next_ty_vars(assoc_type_parameter_count); - - subst::Substs::new_trait(type_parameters, regions, assoc_type_parameters, self_ty) + subst::Substs::new_trait(type_parameters, regions, self_ty) } pub fn fresh_bound_region(&self, debruijn: ty::DebruijnIndex) -> ty::Region { diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index a87db776ce05..3066ae5b479e 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -55,18 +55,17 @@ impl<'tcx> Substs<'tcx> { r: Vec) -> Substs<'tcx> { - Substs::new(VecPerParamSpace::new(t, Vec::new(), Vec::new(), Vec::new()), - VecPerParamSpace::new(r, Vec::new(), Vec::new(), Vec::new())) + Substs::new(VecPerParamSpace::new(t, Vec::new(), Vec::new()), + VecPerParamSpace::new(r, Vec::new(), Vec::new())) } pub fn new_trait(t: Vec>, r: Vec, - a: Vec>, s: Ty<'tcx>) -> Substs<'tcx> { - Substs::new(VecPerParamSpace::new(t, vec!(s), a, Vec::new()), - VecPerParamSpace::new(r, Vec::new(), Vec::new(), Vec::new())) + Substs::new(VecPerParamSpace::new(t, vec!(s), Vec::new()), + VecPerParamSpace::new(r, Vec::new(), Vec::new())) } pub fn erased(t: VecPerParamSpace>) -> Substs<'tcx> @@ -123,13 +122,6 @@ impl<'tcx> Substs<'tcx> { s } - pub fn with_assoc_tys(&self, assoc_tys: Vec>) -> Substs<'tcx> { - assert!(self.types.is_empty_in(AssocSpace)); - let mut s = (*self).clone(); - s.types.replace(AssocSpace, assoc_tys); - s - } - pub fn erase_regions(self) -> Substs<'tcx> { let Substs { types, regions: _ } = self; Substs { types: types, regions: ErasedRegions } @@ -192,21 +184,19 @@ impl RegionSubsts { pub enum ParamSpace { TypeSpace, // Type parameters attached to a type definition, trait, or impl SelfSpace, // Self parameter on a trait - AssocSpace, // Assoc types defined in a trait/impl FnSpace, // Type parameters attached to a method or fn } impl ParamSpace { - pub fn all() -> [ParamSpace, ..4] { - [TypeSpace, SelfSpace, AssocSpace, FnSpace] + pub fn all() -> [ParamSpace, ..3] { + [TypeSpace, SelfSpace, FnSpace] } pub fn to_uint(self) -> uint { match self { TypeSpace => 0, SelfSpace => 1, - AssocSpace => 2, - FnSpace => 3, + FnSpace => 2, } } @@ -214,8 +204,7 @@ impl ParamSpace { match u { 0 => TypeSpace, 1 => SelfSpace, - 2 => AssocSpace, - 3 => FnSpace, + 2 => FnSpace, _ => panic!("Invalid ParamSpace: {}", u) } } @@ -235,11 +224,9 @@ pub struct VecPerParamSpace { // // AF(self) = (self.content[..self.type_limit], // self.content[self.type_limit..self.self_limit], - // self.content[self.self_limit..self.assoc_limit], - // self.content[self.assoc_limit..]) + // self.content[self.self_limit..]) type_limit: uint, self_limit: uint, - assoc_limit: uint, content: Vec, } @@ -248,7 +235,6 @@ pub struct VecPerParamSpace { pub struct SeparateVecsPerParamSpace { pub types: Vec, pub selfs: Vec, - pub assocs: Vec, pub fns: Vec, } @@ -268,8 +254,7 @@ impl VecPerParamSpace { match space { TypeSpace => (0, self.type_limit), SelfSpace => (self.type_limit, self.self_limit), - AssocSpace => (self.self_limit, self.assoc_limit), - FnSpace => (self.assoc_limit, self.content.len()), + FnSpace => (self.self_limit, self.content.len()), } } @@ -277,7 +262,6 @@ impl VecPerParamSpace { VecPerParamSpace { type_limit: 0, self_limit: 0, - assoc_limit: 0, content: Vec::new() } } @@ -290,31 +274,27 @@ impl VecPerParamSpace { /// `s` is the self space. /// `a` is the assoc space. /// `f` is the fn space. - pub fn new(t: Vec, s: Vec, a: Vec, f: Vec) -> VecPerParamSpace { + pub fn new(t: Vec, s: Vec, f: Vec) -> VecPerParamSpace { let type_limit = t.len(); let self_limit = type_limit + s.len(); - let assoc_limit = self_limit + a.len(); let mut content = t; content.extend(s.into_iter()); - content.extend(a.into_iter()); content.extend(f.into_iter()); VecPerParamSpace { type_limit: type_limit, self_limit: self_limit, - assoc_limit: assoc_limit, content: content, } } - fn new_internal(content: Vec, type_limit: uint, self_limit: uint, assoc_limit: uint) + fn new_internal(content: Vec, type_limit: uint, self_limit: uint) -> VecPerParamSpace { VecPerParamSpace { type_limit: type_limit, self_limit: self_limit, - assoc_limit: assoc_limit, content: content, } } @@ -326,9 +306,8 @@ impl VecPerParamSpace { pub fn push(&mut self, space: ParamSpace, value: T) { let (_, limit) = self.limits(space); match space { - TypeSpace => { self.type_limit += 1; self.self_limit += 1; self.assoc_limit += 1; } - SelfSpace => { self.self_limit += 1; self.assoc_limit += 1; } - AssocSpace => { self.assoc_limit += 1; } + TypeSpace => { self.type_limit += 1; self.self_limit += 1; } + SelfSpace => { self.self_limit += 1; } FnSpace => { } } self.content.insert(limit, value); @@ -340,9 +319,8 @@ impl VecPerParamSpace { None } else { match space { - TypeSpace => { self.type_limit -= 1; self.self_limit -= 1; self.assoc_limit -= 1; } - SelfSpace => { self.self_limit -= 1; self.assoc_limit -= 1; } - AssocSpace => { self.assoc_limit -= 1; } + TypeSpace => { self.type_limit -= 1; self.self_limit -= 1; } + SelfSpace => { self.self_limit -= 1; } FnSpace => {} } self.content.remove(limit - 1) @@ -439,8 +417,7 @@ impl VecPerParamSpace { let result = self.iter().map(pred).collect(); VecPerParamSpace::new_internal(result, self.type_limit, - self.self_limit, - self.assoc_limit) + self.self_limit) } pub fn map_enumerated(&self, pred: P) -> VecPerParamSpace where @@ -449,8 +426,7 @@ impl VecPerParamSpace { let result = self.iter_enumerated().map(pred).collect(); VecPerParamSpace::new_internal(result, self.type_limit, - self.self_limit, - self.assoc_limit) + self.self_limit) } pub fn map_move(self, mut pred: F) -> VecPerParamSpace where @@ -459,25 +435,22 @@ impl VecPerParamSpace { let SeparateVecsPerParamSpace { types: t, selfs: s, - assocs: a, fns: f } = self.split(); VecPerParamSpace::new(t.into_iter().map(|p| pred(p)).collect(), s.into_iter().map(|p| pred(p)).collect(), - a.into_iter().map(|p| pred(p)).collect(), f.into_iter().map(|p| pred(p)).collect()) } pub fn split(self) -> SeparateVecsPerParamSpace { - let VecPerParamSpace { type_limit, self_limit, assoc_limit, content } = self; + let VecPerParamSpace { type_limit, self_limit, content } = self; let mut content_iter = content.into_iter(); SeparateVecsPerParamSpace { types: content_iter.by_ref().take(type_limit).collect(), selfs: content_iter.by_ref().take(self_limit - type_limit).collect(), - assocs: content_iter.by_ref().take(assoc_limit - self_limit).collect(), fns: content_iter.collect() } } diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index 91f1b50521d4..755e50f13275 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -1674,8 +1674,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { }); } - let obligations = VecPerParamSpace::new(obligations, Vec::new(), - Vec::new(), Vec::new()); + let obligations = VecPerParamSpace::new(obligations, Vec::new(), Vec::new()); debug!("vtable_builtin_data: obligations={}", obligations.repr(self.tcx())); @@ -1769,7 +1768,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { Substs::new_trait( vec![arguments_tuple, output_type], vec![], - vec![], self_ty); let trait_ref = ty::Binder(Rc::new(ty::TraitRef { def_id: obligation.predicate.def_id(), @@ -1810,7 +1808,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { vec![arguments_tuple.subst(self.tcx(), substs), closure_sig.0.output.unwrap().subst(self.tcx(), substs)], vec![], - vec![], obligation.self_ty()); let trait_ref = ty::Binder(Rc::new(ty::TraitRef { def_id: obligation.predicate.def_id(), diff --git a/src/librustc/middle/traits/util.rs b/src/librustc/middle/traits/util.rs index 95567d8240a2..ddf2c9d87fee 100644 --- a/src/librustc/middle/traits/util.rs +++ b/src/librustc/middle/traits/util.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use middle::subst::{Subst, Substs, VecPerParamSpace}; +use middle::subst::{Substs, VecPerParamSpace}; use middle::infer::InferCtxt; use middle::ty::{mod, Ty, AsPredicate, ToPolyTraitRef}; use std::collections::HashSet; @@ -229,18 +229,7 @@ pub fn fresh_substs_for_impl<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>, { let tcx = infcx.tcx; let impl_generics = ty::lookup_item_type(tcx, impl_def_id).generics; - let input_substs = infcx.fresh_substs_for_generics(span, &impl_generics); - - // Add substs for the associated types bound in the impl. - let ref items = tcx.impl_items.borrow()[impl_def_id]; - let mut assoc_tys = Vec::new(); - for item in items.iter() { - if let &ty::ImplOrTraitItemId::TypeTraitItemId(id) = item { - assoc_tys.push(tcx.tcache.borrow()[id].ty.subst(tcx, &input_substs)); - } - } - - input_substs.with_assoc_tys(assoc_tys) + infcx.fresh_substs_for_generics(span, &impl_generics) } impl<'tcx, N> fmt::Show for VtableImplData<'tcx, N> { diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index ee1432bc953d..9639af5ca1cd 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -701,10 +701,9 @@ impl<'tcx> Repr<'tcx> for subst::Substs<'tcx> { impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for subst::VecPerParamSpace { fn repr(&self, tcx: &ctxt<'tcx>) -> String { - format!("[{};{};{};{}]", + format!("[{};{};{}]", self.get_slice(subst::TypeSpace).repr(tcx), self.get_slice(subst::SelfSpace).repr(tcx), - self.get_slice(subst::AssocSpace).repr(tcx), self.get_slice(subst::FnSpace).repr(tcx)) } } diff --git a/src/librustc_trans/trans/meth.rs b/src/librustc_trans/trans/meth.rs index 2ede6e2e47fd..9535ffaec0e6 100644 --- a/src/librustc_trans/trans/meth.rs +++ b/src/librustc_trans/trans/meth.rs @@ -209,7 +209,6 @@ pub fn trans_static_method_callee(bcx: Block, let subst::SeparateVecsPerParamSpace { types: rcvr_type, selfs: rcvr_self, - assocs: rcvr_assoc, fns: rcvr_method } = rcvr_substs.types.split(); @@ -238,7 +237,6 @@ pub fn trans_static_method_callee(bcx: Block, let trait_substs = Substs::erased(VecPerParamSpace::new(rcvr_type, rcvr_self, - rcvr_assoc, Vec::new())); let trait_substs = bcx.tcx().mk_substs(trait_substs); debug!("trait_substs={}", trait_substs.repr(bcx.tcx())); @@ -276,13 +274,11 @@ pub fn trans_static_method_callee(bcx: Block, let subst::SeparateVecsPerParamSpace { types: impl_type, selfs: impl_self, - assocs: impl_assoc, fns: _ } = impl_substs.types.split(); let callee_substs = Substs::erased(VecPerParamSpace::new(impl_type, impl_self, - impl_assoc, rcvr_method)); let mth_id = method_with_name(ccx, impl_did, mname); @@ -411,13 +407,12 @@ fn combine_impl_and_methods_tps<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let subst::SeparateVecsPerParamSpace { types: rcvr_type, selfs: rcvr_self, - assocs: rcvr_assoc, fns: rcvr_method } = rcvr_substs.types.clone().split(); assert!(rcvr_method.is_empty()); subst::Substs { regions: subst::ErasedRegions, - types: subst::VecPerParamSpace::new(rcvr_type, rcvr_self, rcvr_assoc, node_method) + types: subst::VecPerParamSpace::new(rcvr_type, rcvr_self, node_method) } } diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index e48360940717..1971be117605 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -155,14 +155,11 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>, } }; - let number_assoc_types = trait_def.generics.types.len(subst::AssocSpace); - let assoc_types = fcx.inh.infcx.next_ty_vars(number_assoc_types); - assert_eq!(trait_def.generics.types.len(subst::FnSpace), 0); assert!(trait_def.generics.regions.is_empty()); // Construct a trait-reference `self_ty : Trait` - let substs = subst::Substs::new_trait(input_types, Vec::new(), assoc_types, self_ty); + let substs = subst::Substs::new_trait(input_types, Vec::new(), self_ty); let trait_ref = Rc::new(ty::TraitRef::new(trait_def_id, fcx.tcx().mk_substs(substs))); // Construct an obligation diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a11f7b15e03a..7929a005af2c 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -5430,7 +5430,6 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, span_err!(fcx.tcx().sess, data.bindings[0].span, E0182, "unexpected binding of associated item in expression path \ (only allowed in type paths)"); - substs.types.truncate(subst::ParamSpace::AssocSpace, 0); } { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index da591ca04b74..8f70966dd14c 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -898,7 +898,7 @@ pub fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, // ...and also create the `Self` parameter. let self_ty = ty::mk_self_type(ccx.tcx); - subst::Substs::new_trait(types, regions, Vec::new(), self_ty) + subst::Substs::new_trait(types, regions, self_ty) } } diff --git a/src/test/compile-fail/associated-types-project-from-hrtb-in-fn b/src/test/compile-fail/associated-types-project-from-hrtb-in-fn deleted file mode 100755 index 6d2392c124b3..000000000000 Binary files a/src/test/compile-fail/associated-types-project-from-hrtb-in-fn and /dev/null differ diff --git a/src/test/compile-fail/variance-regions-direct.rs b/src/test/compile-fail/variance-regions-direct.rs index 48813ff142c1..fa38482b21c5 100644 --- a/src/test/compile-fail/variance-regions-direct.rs +++ b/src/test/compile-fail/variance-regions-direct.rs @@ -14,7 +14,7 @@ // Regions that just appear in normal spots are contravariant: #[rustc_variance] -struct Test2<'a, 'b, 'c> { //~ ERROR regions=[[-, -, -];[];[];[]] +struct Test2<'a, 'b, 'c> { //~ ERROR regions=[[-, -, -];[];[]] x: &'a int, y: &'b [int], c: &'c str @@ -23,7 +23,7 @@ struct Test2<'a, 'b, 'c> { //~ ERROR regions=[[-, -, -];[];[];[]] // Those same annotations in function arguments become covariant: #[rustc_variance] -struct Test3<'a, 'b, 'c> { //~ ERROR regions=[[+, +, +];[];[];[]] +struct Test3<'a, 'b, 'c> { //~ ERROR regions=[[+, +, +];[];[]] x: extern "Rust" fn(&'a int), y: extern "Rust" fn(&'b [int]), c: extern "Rust" fn(&'c str), @@ -32,7 +32,7 @@ struct Test3<'a, 'b, 'c> { //~ ERROR regions=[[+, +, +];[];[];[]] // Mutability induces invariance: #[rustc_variance] -struct Test4<'a, 'b:'a> { //~ ERROR regions=[[-, o];[];[];[]] +struct Test4<'a, 'b:'a> { //~ ERROR regions=[[-, o];[];[]] x: &'a mut &'b int, } @@ -40,7 +40,7 @@ struct Test4<'a, 'b:'a> { //~ ERROR regions=[[-, o];[];[];[]] // contravariant context: #[rustc_variance] -struct Test5<'a, 'b> { //~ ERROR regions=[[+, o];[];[];[]] +struct Test5<'a, 'b> { //~ ERROR regions=[[+, o];[];[]] x: extern "Rust" fn(&'a mut &'b int), } @@ -50,21 +50,21 @@ struct Test5<'a, 'b> { //~ ERROR regions=[[+, o];[];[];[]] // argument list occurs in an invariant context. #[rustc_variance] -struct Test6<'a, 'b> { //~ ERROR regions=[[-, o];[];[];[]] +struct Test6<'a, 'b> { //~ ERROR regions=[[-, o];[];[]] x: &'a mut extern "Rust" fn(&'b int), } // No uses at all is bivariant: #[rustc_variance] -struct Test7<'a> { //~ ERROR regions=[[*];[];[];[]] +struct Test7<'a> { //~ ERROR regions=[[*];[];[]] x: int } // Try enums too. #[rustc_variance] -enum Test8<'a, 'b, 'c:'b> { //~ ERROR regions=[[+, -, o];[];[];[]] +enum Test8<'a, 'b, 'c:'b> { //~ ERROR regions=[[+, -, o];[];[]] Test8A(extern "Rust" fn(&'a int)), Test8B(&'b [int]), Test8C(&'b mut &'c str), diff --git a/src/test/compile-fail/variance-regions-indirect.rs b/src/test/compile-fail/variance-regions-indirect.rs index 0e8e52df456a..c049fbc0fedb 100644 --- a/src/test/compile-fail/variance-regions-indirect.rs +++ b/src/test/compile-fail/variance-regions-indirect.rs @@ -13,29 +13,29 @@ // Try enums too. #[rustc_variance] -enum Base<'a, 'b, 'c:'b, 'd> { //~ ERROR regions=[[+, -, o, *];[];[];[]] +enum Base<'a, 'b, 'c:'b, 'd> { //~ ERROR regions=[[+, -, o, *];[];[]] Test8A(extern "Rust" fn(&'a int)), Test8B(&'b [int]), Test8C(&'b mut &'c str), } #[rustc_variance] -struct Derived1<'w, 'x:'y, 'y, 'z> { //~ ERROR regions=[[*, o, -, +];[];[];[]] +struct Derived1<'w, 'x:'y, 'y, 'z> { //~ ERROR regions=[[*, o, -, +];[];[]] f: Base<'z, 'y, 'x, 'w> } #[rustc_variance] // Combine - and + to yield o -struct Derived2<'a, 'b:'a, 'c> { //~ ERROR regions=[[o, o, *];[];[];[]] +struct Derived2<'a, 'b:'a, 'c> { //~ ERROR regions=[[o, o, *];[];[]] f: Base<'a, 'a, 'b, 'c> } #[rustc_variance] // Combine + and o to yield o (just pay attention to 'a here) -struct Derived3<'a:'b, 'b, 'c> { //~ ERROR regions=[[o, -, *];[];[];[]] +struct Derived3<'a:'b, 'b, 'c> { //~ ERROR regions=[[o, -, *];[];[]] f: Base<'a, 'b, 'a, 'c> } #[rustc_variance] // Combine + and * to yield + (just pay attention to 'a here) -struct Derived4<'a, 'b, 'c:'b> { //~ ERROR regions=[[+, -, o];[];[];[]] +struct Derived4<'a, 'b, 'c:'b> { //~ ERROR regions=[[+, -, o];[];[]] f: Base<'a, 'b, 'c, 'a> } diff --git a/src/test/compile-fail/variance-trait-object-bound.rs b/src/test/compile-fail/variance-trait-object-bound.rs index c576c5e2edd6..c61f2ff79c01 100644 --- a/src/test/compile-fail/variance-trait-object-bound.rs +++ b/src/test/compile-fail/variance-trait-object-bound.rs @@ -19,7 +19,7 @@ use std::mem; trait T { fn foo(); } #[rustc_variance] -struct TOption<'a> { //~ ERROR regions=[[-];[];[];[]] +struct TOption<'a> { //~ ERROR regions=[[-];[];[]] v: Option>, }