diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-09-07 18:53:14 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-09-10 12:48:42 -0700 |
| commit | 22b875770543ec1fe93cfb35fd07c692db5675e2 (patch) | |
| tree | 62004747db05cf0fb7d82b85133210c67e2c7bb3 /src/libsyntax | |
| parent | 9a15c50f6c3cec5320ef91f000142af0367890a4 (diff) | |
| download | rust-22b875770543ec1fe93cfb35fd07c692db5675e2.tar.gz rust-22b875770543ec1fe93cfb35fd07c692db5675e2.zip | |
rustc: Make shape-based compare glue never called for comparison operators.
Only called for string patterns.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 51 | ||||
| -rw-r--r-- | src/libsyntax/attr.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/proto.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/simplext.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/comments.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 43 |
6 files changed, 97 insertions, 19 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e2cfdd119b6..364576aae33 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -405,6 +405,13 @@ enum proto { proto_block, // fn& } +impl proto : cmp::Eq { + pure fn eq(&&other: proto) -> bool { + (self as uint) == (other as uint) + } + pure fn ne(&&other: proto) -> bool { !self.eq(other) } +} + #[auto_serialize] enum vstore { // FIXME (#2112): Change uint to @expr (actually only constant exprs) @@ -454,7 +461,49 @@ impl binop : cmp::Eq { enum unop { box(mutability), uniq(mutability), - deref, not, neg + deref, + not, + neg +} + +impl unop : cmp::Eq { + pure fn eq(&&other: unop) -> bool { + match self { + box(e0a) => { + match other { + box(e0b) => e0a == e0b, + _ => false + } + } + uniq(e0a) => { + match other { + uniq(e0b) => e0a == e0b, + _ => false + } + } + deref => { + match other { + deref => true, + _ => false + } + } + not => { + match other { + not => true, + _ => false + } + } + neg => { + match other { + neg => true, + _ => false + } + } + } + } + pure fn ne(&&other: unop) -> bool { + !self.eq(other) + } } // Generally, after typeck you can get the inferred value diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 9dc610e2fb6..a12233765ca 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -337,6 +337,13 @@ enum inline_attr { ia_never, } +impl inline_attr : cmp::Eq { + pure fn eq(&&other: inline_attr) -> bool { + (self as uint) == (other as uint) + } + pure fn ne(&&other: inline_attr) -> bool { !self.eq(other) } +} + /// True if something like #[inline] is found in the list of attrs. fn find_inline_attr(attrs: ~[ast::attribute]) -> inline_attr { // FIXME (#2809)---validate the usage of #[inline] and #[inline(always)] diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 4065c8cf2ba..cb470aee7f3 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -143,7 +143,7 @@ struct protocol_ { fn get_state_by_id(id: uint) -> state { self.states[id] } fn has_state(name: ~str) -> bool { - self.states.find(|i| i.name == name) != None + self.states.find(|i| i.name == name).is_some() } fn filename() -> ~str { diff --git a/src/libsyntax/ext/simplext.rs b/src/libsyntax/ext/simplext.rs index bb5af8402df..c6ddc449b20 100644 --- a/src/libsyntax/ext/simplext.rs +++ b/src/libsyntax/ext/simplext.rs @@ -68,7 +68,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) -> match elt.node { expr_mac(m) => match m.node { ast::mac_ellipsis => { - if res != None { + if res.is_some() { cx.span_fatal(m.span, ~"only one ellipsis allowed"); } res = @@ -449,7 +449,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { } } {pre: pre, rep: None, post: post} => { - if post != ~[] { + if post.len() > 0 { cx.bug(~"elts_to_ell provided an invalid result"); } p_t_s_r_length(cx, vec::len(pre), false, s, b); diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index b85262cb79d..7fcf7a032dc 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -17,6 +17,15 @@ enum cmnt_style { blank_line, // Just a manual blank line "\n\n", for layout } +impl cmnt_style : cmp::Eq { + pure fn eq(&&other: cmnt_style) -> bool { + (self as uint) == (other as uint) + } + pure fn ne(&&other: cmnt_style) -> bool { + (self as uint) != (other as uint) + } +} + type cmnt = {style: cmnt_style, lines: ~[~str], pos: uint}; fn is_doc_comment(s: ~str) -> bool { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 942963797cb..46faa67114e 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1616,10 +1616,13 @@ fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl, pclose(s); maybe_print_comment(s, decl.output.span.lo); - if decl.output.node != ast::ty_nil { - space_if_not_bol(s); - word_space(s, ~"->"); - print_type(s, decl.output); + match decl.output.node { + ast::ty_nil => {} + _ => { + space_if_not_bol(s); + word_space(s, ~"->"); + print_type(s, decl.output); + } } } @@ -1628,11 +1631,16 @@ fn print_fn_block_args(s: ps, decl: ast::fn_decl, word(s.s, ~"|"); print_fn_args(s, decl, cap_items, None); word(s.s, ~"|"); - if decl.output.node != ast::ty_infer { - space_if_not_bol(s); - word_space(s, ~"->"); - print_type(s, decl.output); + + match decl.output.node { + ast::ty_infer => {} + _ => { + space_if_not_bol(s); + word_space(s, ~"->"); + print_type(s, decl.output); + } } + maybe_print_comment(s, decl.output.span.lo); } @@ -1829,14 +1837,19 @@ fn print_ty_fn(s: ps, opt_proto: Option<ast::proto>, purity: ast::purity, pclose(s); maybe_print_comment(s, decl.output.span.lo); - if decl.output.node != ast::ty_nil { - space_if_not_bol(s); - ibox(s, indent_unit); - word_space(s, ~"->"); - if decl.cf == ast::noreturn { word_nbsp(s, ~"!"); } - else { print_type(s, decl.output); } - end(s); + + match decl.output.node { + ast::ty_nil => {} + _ => { + space_if_not_bol(s); + ibox(s, indent_unit); + word_space(s, ~"->"); + if decl.cf == ast::noreturn { word_nbsp(s, ~"!"); } + else { print_type(s, decl.output); } + end(s); + } } + end(s); } |
