diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index a4faff8e3bd85c2bc3a0da714c67495c5fdd2dc1..66c311e4d664be40819490efee5e746f3ad74a63 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -1661,35 +1661,30 @@ fn ty_generics_for_type(ccx: &CrateCtxt, fn ty_generics_for_trait(ccx: &CrateCtxt, trait_id: ast::NodeId, substs: &subst::Substs, - generics: &ast::Generics, + ast_generics: &ast::Generics, items: &[ast::TraitItem]) -> ty::Generics { let mut generics = ty_generics(ccx, subst::TypeSpace, - generics.lifetimes.as_slice(), - generics.ty_params.as_slice(), + ast_generics.lifetimes.as_slice(), + ast_generics.ty_params.as_slice(), ty::Generics::empty(), - &generics.where_clause, + &ast_generics.where_clause, DontCreateTypeParametersForAssociatedTypes); // Add in type parameters for any associated types. for item in items.iter() { match *item { ast::TypeTraitItem(ref associated_type) => { - let def = ty::TypeParameterDef { - space: subst::TypeSpace, - index: generics.types.len(subst::TypeSpace), - name: associated_type.ty_param.ident.name, - def_id: local_def(associated_type.ty_param.id), - bounds: ty::ParamBounds { - builtin_bounds: ty::empty_builtin_bounds(), - trait_bounds: Vec::new(), - region_bounds: Vec::new(), - }, - associated_with: Some(local_def(trait_id)), - default: None, - }; + let def = + get_or_create_type_parameter_def( + ccx, + subst::TypeSpace, + &associated_type.ty_param, + generics.types.len(subst::TypeSpace), + &ast_generics.where_clause, + Some(local_def(trait_id))); ccx.tcx.ty_param_defs.borrow_mut().insert(associated_type.ty_param.id, def.clone()); generics.types.push(subst::TypeSpace, def); @@ -1960,7 +1955,8 @@ fn ty_generics<'tcx,AC>(this: &AC, space, param, i, - where_clause); + where_clause, + None); debug!("ty_generics: def for type param: {}, {}", def.repr(this.tcx()), space); @@ -1980,63 +1976,64 @@ fn ty_generics<'tcx,AC>(this: &AC, } return result; +} - fn get_or_create_type_parameter_def<'tcx,AC>( - this: &AC, - space: subst::ParamSpace, - param: &ast::TyParam, - index: uint, - where_clause: &ast::WhereClause) - -> ty::TypeParameterDef - where AC: AstConv<'tcx> { - match this.tcx().ty_param_defs.borrow().find(¶m.id) { - Some(d) => { return (*d).clone(); } - None => { } - } - - let param_ty = ty::ParamTy::new(space, index, local_def(param.id)); - let bounds = compute_bounds(this, - param.ident.name, - param_ty, - param.bounds.as_slice(), - ¶m.unbound, - param.span, - where_clause); - let default = match param.default { - None => None, - Some(ref path) => { - let ty = ast_ty_to_ty(this, &ExplicitRscope, &**path); - let cur_idx = index; - - ty::walk_ty(ty, |t| { - match ty::get(t).sty { - ty::ty_param(p) => if p.idx > cur_idx { +fn get_or_create_type_parameter_def<'tcx,AC>(this: &AC, + space: subst::ParamSpace, + param: &ast::TyParam, + index: uint, + where_clause: &ast::WhereClause, + associated_with: Option) + -> ty::TypeParameterDef + where AC: AstConv<'tcx> +{ + match this.tcx().ty_param_defs.borrow().find(¶m.id) { + Some(d) => { return (*d).clone(); } + None => { } + } + + let param_ty = ty::ParamTy::new(space, index, local_def(param.id)); + let bounds = compute_bounds(this, + param.ident.name, + param_ty, + param.bounds.as_slice(), + ¶m.unbound, + param.span, + where_clause); + let default = match param.default { + None => None, + Some(ref path) => { + let ty = ast_ty_to_ty(this, &ExplicitRscope, &**path); + let cur_idx = index; + + ty::walk_ty(ty, |t| { + match ty::get(t).sty { + ty::ty_param(p) => if p.idx > cur_idx { span_err!(this.tcx().sess, path.span, E0128, "type parameters with a default cannot use \ forward declared identifiers"); }, _ => {} } - }); + }); - Some(ty) - } - }; + Some(ty) + } + }; - let def = ty::TypeParameterDef { - space: space, - index: index, - name: param.ident.name, - def_id: local_def(param.id), - associated_with: None, - bounds: bounds, - default: default - }; + let def = ty::TypeParameterDef { + space: space, + index: index, + name: param.ident.name, + def_id: local_def(param.id), + associated_with: associated_with, + bounds: bounds, + default: default + }; - this.tcx().ty_param_defs.borrow_mut().insert(param.id, def.clone()); + this.tcx().ty_param_defs.borrow_mut().insert(param.id, def.clone()); - def - } + def } fn compute_bounds<'tcx,AC>(this: &AC, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c128588918e28183a150caa7fbf84d8e82edc9b8..f96b3916f06dee31cdf5a2f6ae16b2f4a680ac8f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2203,12 +2203,12 @@ fn clean(&self, _: &DocContext) -> Stability { impl Clean for ast::AssociatedType { fn clean(&self, cx: &DocContext) -> Item { Item { - source: self.span.clean(cx), - name: Some(self.ident.clean(cx)), + source: self.ty_param.span.clean(cx), + name: Some(self.ty_param.ident.clean(cx)), attrs: self.attrs.clean(cx), inner: AssociatedTypeItem, visibility: None, - def_id: ast_util::local_def(self.id), + def_id: ast_util::local_def(self.ty_param.id), stability: None, } }