From e38cb972dcfc0fdab44270257eac3405a39bd996 Mon Sep 17 00:00:00 2001 From: John Clements Date: Mon, 30 Jun 2014 18:02:14 -0700 Subject: Simplify PatIdent to contain an Ident rather than a Path Rationale: for what appear to be historical reasons only, the PatIdent contains a Path rather than an Ident. This means that there are many places in the code where an ident is artificially promoted to a path, and---much more problematically--- a bunch of elements from a path are simply thrown away, which seems like an invitation to some really nasty bugs. This commit replaces the Path in a PatIdent with a SpannedIdent, which just contains an ident and a span. --- src/libsyntax/parse/mod.rs | 53 ++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 35 deletions(-) (limited to 'src/libsyntax/parse/mod.rs') diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 331a49c83be..4b5252bfba3 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -594,23 +594,15 @@ mod test { #[test] fn parse_ident_pat () { let sess = new_parse_sess(); let mut parser = string_to_parser(&sess, "b".to_string()); - assert!(parser.parse_pat() == - box(GC) ast::Pat{id: ast::DUMMY_NODE_ID, - node: ast::PatIdent( - ast::BindByValue(ast::MutImmutable), - ast::Path { - span:sp(0,1), - global:false, - segments: vec!( - ast::PathSegment { - identifier: str_to_ident("b"), - lifetimes: Vec::new(), - types: OwnedSlice::empty(), - } - ), - }, - None /* no idea */), - span: sp(0,1)}); + assert!(parser.parse_pat() + == box(GC) ast::Pat{ + id: ast::DUMMY_NODE_ID, + node: ast::PatIdent(ast::BindByValue(ast::MutImmutable), + Spanned{ span:sp(0, 1), + node: str_to_ident("b") + }, + None), + span: sp(0,1)}); parser_done(parser); } @@ -643,24 +635,15 @@ mod test { id: ast::DUMMY_NODE_ID, node: ast::PatIdent( ast::BindByValue(ast::MutImmutable), - ast::Path { - span:sp(6,7), - global:false, - segments: vec!( - ast::PathSegment { - identifier: - str_to_ident("b"), - lifetimes: Vec::new(), - types: OwnedSlice::empty(), - } - ), - }, - None // no idea - ), - span: sp(6,7) - }, - id: ast::DUMMY_NODE_ID - }), + Spanned{ + span: sp(6,7), + node: str_to_ident("b")}, + None + ), + span: sp(6,7) + }, + id: ast::DUMMY_NODE_ID + }), output: ast::P(ast::Ty{id: ast::DUMMY_NODE_ID, node: ast::TyNil, span:sp(15,15)}), // not sure -- cgit 1.4.1-3-g733a5