diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-02-13 09:46:46 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-02-19 16:35:31 -0800 |
| commit | 33923f47e3f90442ae3c604d8ea80992b71611f7 (patch) | |
| tree | 4130c674d6114c3b6a7399b599e98cf62fca3aac /src/libsyntax | |
| parent | ea0058281cfea06a61e5eb23b31c15e9d1dcfda3 (diff) | |
| download | rust-33923f47e3f90442ae3c604d8ea80992b71611f7.tar.gz rust-33923f47e3f90442ae3c604d8ea80992b71611f7.zip | |
librustc: Remove unique vector patterns from the language.
Preparatory work for removing unique vectors from the language, which is itself preparatory work for dynamically sized types.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/deriving/clone.rs | 43 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/generic.rs | 37 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/mod.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/show.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/ext/env.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 58 | ||||
| -rw-r--r-- | src/libsyntax/util/small_vector.rs | 8 |
8 files changed, 96 insertions, 79 deletions
diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index bd961002f53..5595bdee688 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -97,30 +97,27 @@ fn cs_clone( name)) } - match *all_fields { - [FieldInfo { name: None, .. }, ..] => { - // enum-like - let subcalls = all_fields.map(subcall); - cx.expr_call_ident(trait_span, ctor_ident, subcalls) - }, - _ => { - // struct-like - let fields = all_fields.map(|field| { - let ident = match field.name { - Some(i) => i, - None => cx.span_bug(trait_span, - format!("unnamed field in normal struct in `deriving({})`", - name)) - }; - cx.field_imm(field.span, ident, subcall(field)) - }); + if all_fields.len() >= 1 && all_fields[0].name.is_none() { + // enum-like + let subcalls = all_fields.map(subcall); + cx.expr_call_ident(trait_span, ctor_ident, subcalls) + } else { + // struct-like + let fields = all_fields.map(|field| { + let ident = match field.name { + Some(i) => i, + None => cx.span_bug(trait_span, + format!("unnamed field in normal struct in `deriving({})`", + name)) + }; + cx.field_imm(field.span, ident, subcall(field)) + }); - if fields.is_empty() { - // no fields, so construct like `None` - cx.expr_ident(trait_span, ctor_ident) - } else { - cx.expr_struct_ident(trait_span, ctor_ident, fields) - } + if fields.is_empty() { + // no fields, so construct like `None` + cx.expr_ident(trait_span, ctor_ident) + } else { + cx.expr_struct_ident(trait_span, ctor_ident, fields) } } } diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 029e87afbe2..fb7f9b74364 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -663,25 +663,26 @@ impl<'a> MethodDef<'a> { } // transpose raw_fields - let fields = match raw_fields { - [ref self_arg, .. rest] => { - self_arg.iter().enumerate().map(|(i, &(span, opt_id, field))| { - let other_fields = rest.map(|l| { - match &l[i] { - &(_, _, ex) => ex - } - }); - FieldInfo { - span: span, - name: opt_id, - self_: field, - other: other_fields + let fields = if raw_fields.len() > 0 { + raw_fields[0].iter() + .enumerate() + .map(|(i, &(span, opt_id, field))| { + let other_fields = raw_fields.tail().map(|l| { + match &l[i] { + &(_, _, ex) => ex } - }).collect() - } - [] => { cx.span_bug(trait_.span, - "no self arguments to non-static method \ - in generic `deriving`") } + }); + FieldInfo { + span: span, + name: opt_id, + self_: field, + other: other_fields + } + }).collect() + } else { + cx.span_bug(trait_.span, + "no self arguments to non-static method in generic \ + `deriving`") }; // body of the inner most destructuring match diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 62408d79ee3..7c686e5cd67 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -54,7 +54,10 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt, MetaNameValue(_, ref l) => { cx.span_err(l.span, "unexpected value in `deriving`"); } - MetaWord(_) | MetaList(_, []) => { + MetaWord(_) => { + cx.span_warn(mitem.span, "empty trait list in `deriving`"); + } + MetaList(_, ref titems) if titems.len() == 0 => { cx.span_warn(mitem.span, "empty trait list in `deriving`"); } MetaList(_, ref titems) => { diff --git a/src/libsyntax/ext/deriving/show.rs b/src/libsyntax/ext/deriving/show.rs index 83d327daf17..d5b08503fd0 100644 --- a/src/libsyntax/ext/deriving/show.rs +++ b/src/libsyntax/ext/deriving/show.rs @@ -74,7 +74,8 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, // Getting harder... making the format string: match *substr.fields { // unit struct/nullary variant: no work necessary! - Struct([]) | EnumMatching(_, _, []) => {} + Struct(ref fields) if fields.len() == 0 => {} + EnumMatching(_, _, ref fields) if fields.len() == 0 => {} Struct(ref fields) | EnumMatching(_, _, ref fields) => { if fields[0].name.is_none() { diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index fec1e70af07..aacb2a74087 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -40,7 +40,7 @@ pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) pub fn expand_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { let exprs = match get_exprs_from_tts(cx, sp, tts) { - Some([]) => { + Some(ref exprs) if exprs.len() == 0 => { cx.span_err(sp, "env! takes 1 or 2 arguments"); return MacResult::dummy_expr(sp); } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 4b81713f7d0..1e0bfb0d3e9 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -647,14 +647,10 @@ impl Visitor<()> for NewNameFinderContext { &ast::Path { global: false, span: _, - segments: [ - ast::PathSegment { - identifier: id, - lifetimes: _, - types: _ - } - ] - } => self.ident_accumulator.push(id), + segments: ref segments + } if segments.len() == 1 => { + self.ident_accumulator.push(segments[0].identifier) + } // I believe these must be enums... _ => () } @@ -1187,7 +1183,12 @@ foo_module!() let bindings = name_finder.ident_accumulator; let cxbinds: ~[&ast::Ident] = - bindings.iter().filter(|b| "xx" == token::get_ident(**b).get()).collect(); + bindings.iter().filter(|b| { + let ident = token::get_ident(**b); + let string = ident.get(); + "xx" == string + }).collect(); + let cxbinds: &[&ast::Ident] = cxbinds; let cxbind = match cxbinds { [b] => b, _ => fail!("expected just one binding for ext_cx") diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 6ddb4bbc11f..b4139714a2e 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -363,40 +363,48 @@ mod test { // check the token-tree-ization of macros #[test] fn string_to_tts_macro () { let tts = string_to_tts(~"macro_rules! zip (($a)=>($a))"); + let tts: &[ast::TokenTree] = tts; match tts { [ast::TTTok(_,_), ast::TTTok(_,token::NOT), ast::TTTok(_,_), - ast::TTDelim(delim_elts)] => - match *delim_elts { - [ast::TTTok(_,token::LPAREN), - ast::TTDelim(first_set), - ast::TTTok(_,token::FAT_ARROW), - ast::TTDelim(second_set), - ast::TTTok(_,token::RPAREN)] => - match *first_set { + ast::TTDelim(delim_elts)] => { + let delim_elts: &[ast::TokenTree] = *delim_elts; + match delim_elts { [ast::TTTok(_,token::LPAREN), - ast::TTTok(_,token::DOLLAR), - ast::TTTok(_,_), - ast::TTTok(_,token::RPAREN)] => - match *second_set { - [ast::TTTok(_,token::LPAREN), - ast::TTTok(_,token::DOLLAR), - ast::TTTok(_,_), - ast::TTTok(_,token::RPAREN)] => - assert_eq!("correct","correct"), - _ => assert_eq!("wrong 4","correct") + ast::TTDelim(first_set), + ast::TTTok(_,token::FAT_ARROW), + ast::TTDelim(second_set), + ast::TTTok(_,token::RPAREN)] => { + let first_set: &[ast::TokenTree] = *first_set; + match first_set { + [ast::TTTok(_,token::LPAREN), + ast::TTTok(_,token::DOLLAR), + ast::TTTok(_,_), + ast::TTTok(_,token::RPAREN)] => { + let second_set: &[ast::TokenTree] = + *second_set; + match second_set { + [ast::TTTok(_,token::LPAREN), + ast::TTTok(_,token::DOLLAR), + ast::TTTok(_,_), + ast::TTTok(_,token::RPAREN)] => { + assert_eq!("correct","correct") + } + _ => assert_eq!("wrong 4","correct") + } + }, + _ => { + error!("failing value 3: {:?}",first_set); + assert_eq!("wrong 3","correct") + } + } }, _ => { - error!("failing value 3: {:?}",first_set); - assert_eq!("wrong 3","correct") + error!("failing value 2: {:?}",delim_elts); + assert_eq!("wrong","correct"); } - }, - _ => { - error!("failing value 2: {:?}",delim_elts); - assert_eq!("wrong","correct"); } - }, _ => { error!("failing value: {:?}",tts); diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index 32e5b83ee04..d6cc35a6f9d 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -81,7 +81,13 @@ impl<T> SmallVector<T> { pub fn expect_one(self, err: &'static str) -> T { match self { One(v) => v, - Many([v]) => v, + Many(v) => { + if v.len() == 1 { + v.move_iter().next().unwrap() + } else { + fail!(err) + } + } _ => fail!(err) } } |
