Skip to content

Commit

Permalink
Add a span to ast::TyParam
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Apr 23, 2014
1 parent 09bfb92 commit c3b2f2b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/libsyntax/ast.rs
Expand Up @@ -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)]
Expand Down
5 changes: 4 additions & 1 deletion src/libsyntax/ext/build.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -368,14 +369,16 @@ 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 {
ast::TyParam {
ident: id,
id: ast::DUMMY_NODE_ID,
bounds: bounds,
default: default
default: default,
span: span
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/generic.rs
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/ty.rs
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/libsyntax/fold.rs
Expand Up @@ -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
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/parse/parser.rs
Expand Up @@ -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();
Expand All @@ -3407,7 +3408,8 @@ impl<'a> Parser<'a> {
ident: ident,
id: ast::DUMMY_NODE_ID,
bounds: bounds,
default: default
default: default,
span: span,
}
}

Expand Down

0 comments on commit c3b2f2b

Please sign in to comment.