Add a span to ast::TyParam

This commit is contained in:
Nick Cameron 2014-04-03 13:53:57 +13:00
parent 09bfb92fdc
commit c3b2f2b0c6
6 changed files with 13 additions and 6 deletions

View File

@ -181,7 +181,8 @@ pub struct TyParam {
pub ident: Ident,
pub id: NodeId,
pub bounds: OwnedSlice<TyParamBound>,
pub default: Option<P<Ty>>
pub default: Option<P<Ty>>,
pub span: Span
}
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]

View File

@ -66,6 +66,7 @@ pub trait AstBuilder {
fn strip_bounds(&self, bounds: &Generics) -> Generics;
fn typaram(&self,
span: Span,
id: ast::Ident,
bounds: OwnedSlice<ast::TyParamBound>,
default: Option<P<ast::Ty>>) -> ast::TyParam;
@ -368,6 +369,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}
fn typaram(&self,
span: Span,
id: ast::Ident,
bounds: OwnedSlice<ast::TyParamBound>,
default: Option<P<ast::Ty>>) -> ast::TyParam {
@ -375,7 +377,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
ident: id,
id: ast::DUMMY_NODE_ID,
bounds: bounds,
default: default
default: default,
span: span
}
}

View File

@ -380,7 +380,7 @@ impl<'a> TraitDef<'a> {
// require the current trait
bounds.push(cx.typarambound(trait_path.clone()));
cx.typaram(ty_param.ident, OwnedSlice::from_vec(bounds), None)
cx.typaram(self.span, ty_param.ident, OwnedSlice::from_vec(bounds), None)
}));
let trait_generics = Generics {
lifetimes: lifetimes,

View File

@ -193,7 +193,7 @@ fn mk_ty_param(cx: &ExtCtxt, span: Span, name: &str, bounds: &[Path],
let path = b.to_path(cx, span, self_ident, self_generics);
cx.typarambound(path)
}).collect();
cx.typaram(cx.ident_of(name), bounds, None)
cx.typaram(span, cx.ident_of(name), bounds, None)
}
fn mk_generics(lifetimes: Vec<ast::Lifetime> , ty_params: Vec<ast::TyParam> ) -> Generics {

View File

@ -448,7 +448,8 @@ pub fn fold_ty_param<T: Folder>(tp: &TyParam, fld: &mut T) -> TyParam {
ident: tp.ident,
id: id,
bounds: tp.bounds.map(|x| fold_ty_param_bound(x, fld)),
default: tp.default.map(|x| fld.fold_ty(x))
default: tp.default.map(|x| fld.fold_ty(x)),
span: tp.span
}
}

View File

@ -3393,6 +3393,7 @@ impl<'a> Parser<'a> {
// matches typaram = IDENT optbounds ( EQ ty )?
fn parse_ty_param(&mut self) -> TyParam {
let ident = self.parse_ident();
let span = self.span;
let (_, opt_bounds) = self.parse_optional_ty_param_bounds(false);
// For typarams we don't care about the difference b/w "<T>" and "<T:>".
let bounds = opt_bounds.unwrap_or_default();
@ -3407,7 +3408,8 @@ impl<'a> Parser<'a> {
ident: ident,
id: ast::DUMMY_NODE_ID,
bounds: bounds,
default: default
default: default,
span: span,
}
}