From d18f7854578e8c2e1d7dce90db6e3b5cf9befba9 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 7 Mar 2013 14:38:38 -0800 Subject: librustc: Replace all uses of `fn()` with `&fn()`. rs=defun --- src/libsyntax/ast_map.rs | 2 +- src/libsyntax/ast_util.rs | 2 +- src/libsyntax/diagnostic.rs | 2 +- src/libsyntax/ext/auto_encode.rs | 32 ++++++++++++++++---------------- src/libsyntax/ext/pipes/proto.rs | 2 +- src/libsyntax/opt_vec.rs | 20 ++++++++++---------- src/libsyntax/parse/common.rs | 12 ++++++------ src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 6 +++--- src/libsyntax/print/pprust.rs | 4 ++-- 10 files changed, 42 insertions(+), 42 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 3001fe8069c..a7d5c0ce75f 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -423,7 +423,7 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { } pub fn node_item_query(items: map, id: node_id, - query: fn(@item) -> Result, + query: &fn(@item) -> Result, +error_msg: ~str) -> Result { match items.find(&id) { Some(node_item(it, _)) => query(it), diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 7b0e72e6e95..35b188a248f 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -516,7 +516,7 @@ pub pure fn is_item_impl(item: @ast::item) -> bool { } } -pub fn walk_pat(pat: @pat, it: fn(@pat)) { +pub fn walk_pat(pat: @pat, it: &fn(@pat)) { it(pat); match pat.node { pat_ident(_, _, Some(p)) => walk_pat(p, it), diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 33e734fbd64..4e177fecec9 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -306,7 +306,7 @@ fn print_macro_backtrace(cm: @codemap::CodeMap, sp: span) { pub fn expect(diag: span_handler, opt: Option, - msg: fn() -> ~str) -> T { + msg: &fn() -> ~str) -> T { match opt { Some(ref t) => (*t), None => diag.handler().bug(msg()) diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index ecb5be6cc3c..8aa03e14fa4 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -432,7 +432,7 @@ fn mk_impl( ty_param: ast::TyParam, path: @ast::path, generics: &ast::Generics, - f: fn(@ast::Ty) -> @ast::method + f: &fn(@ast::Ty) -> @ast::method ) -> @ast::item { /*! * @@ -1256,51 +1256,51 @@ mod test { fn emit_owned_str(&self, +_v: &str) { self.add_unknown_to_log(); } fn emit_managed_str(&self, +_v: &str) { self.add_unknown_to_log(); } - fn emit_borrowed(&self, f: fn()) { self.add_unknown_to_log(); f() } - fn emit_owned(&self, f: fn()) { self.add_unknown_to_log(); f() } - fn emit_managed(&self, f: fn()) { self.add_unknown_to_log(); f() } + fn emit_borrowed(&self, f: &fn()) { self.add_unknown_to_log(); f() } + fn emit_owned(&self, f: &fn()) { self.add_unknown_to_log(); f() } + fn emit_managed(&self, f: &fn()) { self.add_unknown_to_log(); f() } - fn emit_enum(&self, name: &str, f: fn()) { + fn emit_enum(&self, name: &str, f: &fn()) { self.add_to_log(CallToEmitEnum(name.to_str())); f(); } fn emit_enum_variant(&self, name: &str, +id: uint, - +cnt: uint, f: fn()) { + +cnt: uint, f: &fn()) { self.add_to_log(CallToEmitEnumVariant (name.to_str(),id,cnt)); f(); } - fn emit_enum_variant_arg(&self, +idx: uint, f: fn()) { + fn emit_enum_variant_arg(&self, +idx: uint, f: &fn()) { self.add_to_log(CallToEmitEnumVariantArg (idx)); f(); } - fn emit_borrowed_vec(&self, +_len: uint, f: fn()) { + fn emit_borrowed_vec(&self, +_len: uint, f: &fn()) { self.add_unknown_to_log(); f(); } - fn emit_owned_vec(&self, +_len: uint, f: fn()) { + fn emit_owned_vec(&self, +_len: uint, f: &fn()) { self.add_unknown_to_log(); f(); } - fn emit_managed_vec(&self, +_len: uint, f: fn()) { + fn emit_managed_vec(&self, +_len: uint, f: &fn()) { self.add_unknown_to_log(); f(); } - fn emit_vec_elt(&self, +_idx: uint, f: fn()) { + fn emit_vec_elt(&self, +_idx: uint, f: &fn()) { self.add_unknown_to_log(); f(); } - fn emit_rec(&self, f: fn()) { + fn emit_rec(&self, f: &fn()) { self.add_unknown_to_log(); f(); } - fn emit_struct(&self, name: &str, +len: uint, f: fn()) { + fn emit_struct(&self, name: &str, +len: uint, f: &fn()) { self.add_to_log(CallToEmitStruct (name.to_str(),len)); f(); } - fn emit_field(&self, name: &str, +idx: uint, f: fn()) { + fn emit_field(&self, name: &str, +idx: uint, f: &fn()) { self.add_to_log(CallToEmitField (name.to_str(),idx)); f(); } - fn emit_tup(&self, +_len: uint, f: fn()) { + fn emit_tup(&self, +_len: uint, f: &fn()) { self.add_unknown_to_log(); f(); } - fn emit_tup_elt(&self, +_idx: uint, f: fn()) { + fn emit_tup_elt(&self, +_idx: uint, f: &fn()) { self.add_unknown_to_log(); f(); } } diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 329b3f59b1e..dc9abd536d1 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -104,7 +104,7 @@ pub impl state_ { /// Iterate over the states that can be reached in one message /// from this state. - fn reachable(&self, f: fn(state) -> bool) { + fn reachable(&self, f: &fn(state) -> bool) { for self.messages.each |m| { match *m { message(_, _, _, _, Some(next_state { state: ref id, _ })) => { diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs index 16db384bb06..ba0c7a71b7c 100644 --- a/src/libsyntax/opt_vec.rs +++ b/src/libsyntax/opt_vec.rs @@ -122,7 +122,7 @@ impl Eq for OptVec { } impl BaseIter for OptVec { - pure fn each(&self, blk: fn(v: &A) -> bool) { + pure fn each(&self, blk: &fn(v: &A) -> bool) { match *self { Empty => {} Vec(ref v) => v.each(blk) @@ -136,31 +136,31 @@ impl BaseIter for OptVec { impl iter::ExtendedIter for OptVec { #[inline(always)] - pure fn eachi(&self, blk: fn(+v: uint, v: &A) -> bool) { + pure fn eachi(&self, blk: &fn(+v: uint, v: &A) -> bool) { iter::eachi(self, blk) } #[inline(always)] - pure fn all(&self, blk: fn(&A) -> bool) -> bool { + pure fn all(&self, blk: &fn(&A) -> bool) -> bool { iter::all(self, blk) } #[inline(always)] - pure fn any(&self, blk: fn(&A) -> bool) -> bool { + pure fn any(&self, blk: &fn(&A) -> bool) -> bool { iter::any(self, blk) } #[inline(always)] - pure fn foldl(&self, +b0: B, blk: fn(&B, &A) -> B) -> B { + pure fn foldl(&self, +b0: B, blk: &fn(&B, &A) -> B) -> B { iter::foldl(self, b0, blk) } #[inline(always)] - pure fn position(&self, f: fn(&A) -> bool) -> Option { + pure fn position(&self, f: &fn(&A) -> bool) -> Option { iter::position(self, f) } #[inline(always)] - pure fn map_to_vec(&self, op: fn(&A) -> B) -> ~[B] { + pure fn map_to_vec(&self, op: &fn(&A) -> B) -> ~[B] { iter::map_to_vec(self, op) } #[inline(always)] - pure fn flat_map_to_vec>(&self, op: fn(&A) -> IB) + pure fn flat_map_to_vec>(&self, op: &fn(&A) -> IB) -> ~[B] { iter::flat_map_to_vec(self, op) } @@ -176,13 +176,13 @@ impl iter::EqIter for OptVec { impl iter::CopyableIter for OptVec { #[inline(always)] - pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] { + pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] { iter::filter_to_vec(self, pred) } #[inline(always)] pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) } #[inline(always)] - pure fn find(&self, f: fn(&A) -> bool) -> Option { + pure fn find(&self, f: &fn(&A) -> bool) -> Option { iter::find(self, f) } } diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index 7af2204fafd..c7b9a769293 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -248,7 +248,7 @@ pub impl Parser { fn parse_seq_to_before_gt( &self, sep: Option, - f: fn(&Parser) -> T + f: &fn(&Parser) -> T ) -> OptVec { let mut first = true; let mut v = opt_vec::Empty; @@ -269,7 +269,7 @@ pub impl Parser { fn parse_seq_to_gt( &self, sep: Option, - f: fn(&Parser) -> T + f: &fn(&Parser) -> T ) -> OptVec { let v = self.parse_seq_to_before_gt(sep, f); self.expect_gt(); @@ -283,7 +283,7 @@ pub impl Parser { &self, ket: &token::Token, sep: SeqSep, - f: fn(&Parser) -> T + f: &fn(&Parser) -> T ) -> ~[T] { let val = self.parse_seq_to_before_end(ket, sep, f); self.bump(); @@ -297,7 +297,7 @@ pub impl Parser { &self, ket: &token::Token, sep: SeqSep, - f: fn(&Parser) -> T + f: &fn(&Parser) -> T ) -> ~[T] { let mut first: bool = true; let mut v: ~[T] = ~[]; @@ -323,7 +323,7 @@ pub impl Parser { bra: &token::Token, ket: &token::Token, sep: SeqSep, - f: fn(&Parser) -> T + f: &fn(&Parser) -> T ) -> ~[T] { self.expect(bra); let result = self.parse_seq_to_before_end(ket, sep, f); @@ -338,7 +338,7 @@ pub impl Parser { bra: &token::Token, ket: &token::Token, sep: SeqSep, - f: fn(&Parser) -> T + f: &fn(&Parser) -> T ) -> spanned<~[T]> { let lo = self.span.lo; self.expect(bra); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index a1fc7230dd1..fd84f867068 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -173,7 +173,7 @@ pub fn parse_tts_from_source_str( } pub fn parse_from_source_str( - f: fn (Parser) -> T, + f: &fn (Parser) -> T, name: ~str, ss: codemap::FileSubstr, source: @~str, +cfg: ast::crate_cfg, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 38cd09abad4..92ff83a3975 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1829,7 +1829,7 @@ pub impl Parser { fn parse_sugary_call_expr(&self, keyword: ~str, sugar: CallSugar, - ctor: fn(+v: @expr) -> expr_) -> @expr { + ctor: &fn(+v: @expr) -> expr_) -> @expr { let lo = self.last_span; // Parse the callee `foo` in // for foo || { @@ -2769,7 +2769,7 @@ pub impl Parser { (lifetimes, opt_vec::take_vec(result)) } - fn parse_fn_decl(&self, parse_arg_fn: fn(&Parser) -> arg_or_capture_item) + fn parse_fn_decl(&self, parse_arg_fn: &fn(&Parser) -> arg_or_capture_item) -> fn_decl { let args_or_capture_items: ~[arg_or_capture_item] = @@ -2816,7 +2816,7 @@ pub impl Parser { fn(&Parser) -> arg_or_capture_item ) -> (self_ty, fn_decl) { fn maybe_parse_self_ty( - cnstr: fn(+v: mutability) -> ast::self_ty_, + cnstr: &fn(+v: mutability) -> ast::self_ty_, p: &Parser ) -> ast::self_ty_ { // We need to make sure it isn't a mode or a type diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index c81c1c8bd0e..e7e2435587e 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -314,8 +314,8 @@ pub fn commasep(s: @ps, b: breaks, elts: ~[IN], op: &fn(@ps, IN)) { } -pub fn commasep_cmnt(s: @ps, b: breaks, elts: ~[IN], op: fn(@ps, IN), - get_span: fn(IN) -> codemap::span) { +pub fn commasep_cmnt(s: @ps, b: breaks, elts: ~[IN], op: &fn(@ps, IN), + get_span: &fn(IN) -> codemap::span) { box(s, 0u, b); let len = vec::len::(elts); let mut i = 0u; -- cgit 1.4.1-3-g733a5 From bd2d17e4a1f75bc7e451fc1054d98ff13c456850 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 7 Mar 2013 15:44:21 -0800 Subject: libsyntax: Stop parsing bare functions in preparation for switching them over --- src/libcore/hashmap.rs | 4 +++- src/libcore/num/uint-template.rs | 5 ++++- src/libcore/str.rs | 12 +++++++++--- src/libcore/trie.rs | 5 ++++- src/libstd/rl.rs | 2 +- src/libstd/treemap.rs | 4 +++- src/libsyntax/parse/obsolete.rs | 5 +++++ src/libsyntax/parse/parser.rs | 12 +++++++++++- 8 files changed, 40 insertions(+), 9 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs index 6f63cdbabb5..2adcee495a7 100644 --- a/src/libcore/hashmap.rs +++ b/src/libcore/hashmap.rs @@ -599,7 +599,9 @@ pub mod linear { } /// Visit the values representing the intersection - pure fn intersection(&self, other: &LinearSet, f: &fn(&T) -> bool) { + pure fn intersection(&self, + other: &LinearSet, + f: &fn(&T) -> bool) { for self.each |v| { if other.contains(v) { if !f(v) { return } diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index 9a141bfd341..9abbfb03d7a 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -67,7 +67,10 @@ pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T } * Iterate over the range [`start`,`start`+`step`..`stop`) * */ -pub pure fn range_step(start: T, stop: T, step: T_SIGNED, it: &fn(T) -> bool) { +pub pure fn range_step(start: T, + stop: T, + step: T_SIGNED, + it: &fn(T) -> bool) { let mut i = start; if step == 0 { fail!(~"range_step called with step == 0"); diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 415c12e33a8..ae778cb7649 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -491,7 +491,10 @@ pub pure fn split(s: &str, sepfn: &fn(char) -> bool) -> ~[~str] { * Splits a string into substrings using a character function, cutting at * most `count` times. */ -pub pure fn splitn(s: &str, sepfn: &fn(char) -> bool, count: uint) -> ~[~str] { +pub pure fn splitn(s: &str, + sepfn: &fn(char) -> bool, + count: uint) + -> ~[~str] { split_inner(s, sepfn, count, true) } @@ -1246,8 +1249,11 @@ pub pure fn find_from(s: &str, start: uint, f: &fn(char) * or equal to `len(s)`. `start` must be the index of a character * boundary, as defined by `is_char_boundary`. */ -pub pure fn find_between(s: &str, start: uint, end: uint, f: &fn(char) -> bool) - -> Option { +pub pure fn find_between(s: &str, + start: uint, + end: uint, + f: &fn(char) -> bool) + -> Option { fail_unless!(start <= end); fail_unless!(end <= len(s)); fail_unless!(is_char_boundary(s, start)); diff --git a/src/libcore/trie.rs b/src/libcore/trie.rs index 4bd751adc3c..7dc85cba297 100644 --- a/src/libcore/trie.rs +++ b/src/libcore/trie.rs @@ -81,7 +81,10 @@ impl Map for TrieMap { /// Visit all values in order #[inline(always)] - pure fn each_value(&self, f: &fn(&T) -> bool) { self.each(|&(_, v)| f(v)) } + pure fn each_value(&self, + f: &fn(&T) -> bool) { + self.each(|&(_, v)| f(v)) + } /// Return the value corresponding to the key in the map #[inline(hint)] diff --git a/src/libstd/rl.rs b/src/libstd/rl.rs index b2b30c1057e..a8b25767ce5 100644 --- a/src/libstd/rl.rs +++ b/src/libstd/rl.rs @@ -68,7 +68,7 @@ pub unsafe fn read(prompt: ~str) -> Option<~str> { } } -pub type CompletionCb = @fn(~str, fn(~str)); +pub type CompletionCb<'self> = @fn(~str, &'self fn(~str)); fn complete_key(_v: @CompletionCb) {} diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index f053bcfd397..72351aac339 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -138,7 +138,9 @@ impl Map for TreeMap { pure fn each_key(&self, f: &fn(&K) -> bool) { self.each(|&(k, _)| f(k)) } /// Visit all values in order - pure fn each_value(&self, f: &fn(&V) -> bool) { self.each(|&(_, v)| f(v)) } + pure fn each_value(&self, f: &fn(&V) -> bool) { + self.each(|&(_, v)| f(v)) + } /// Return the value corresponding to the key in the map pure fn find(&self, key: &K) -> Option<&self/V> { diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 97ff175da07..757df713fc0 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -53,6 +53,7 @@ pub enum ObsoleteSyntax { ObsoleteRecordPattern, ObsoleteAssertion, ObsoletePostFnTySigil, + ObsoleteBareFnType, } impl to_bytes::IterBytes for ObsoleteSyntax { @@ -166,6 +167,10 @@ pub impl Parser { "Rather than `fn@`, `fn~`, or `fn&`, \ write `@fn`, `~fn`, and `&fn` respectively" ), + ObsoleteBareFnType => ( + "bare function type", + "use `&fn` or `extern fn` instead" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 92ff83a3975..1c3d906e164 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -76,7 +76,11 @@ use parse::obsolete::{ObsoleteUnsafeBlock, ObsoleteImplSyntax}; use parse::obsolete::{ObsoleteTraitBoundSeparator, ObsoleteMutOwnedPointer}; use parse::obsolete::{ObsoleteMutVector, ObsoleteTraitImplVisibility}; use parse::obsolete::{ObsoleteRecordType, ObsoleteRecordPattern}; +<<<<<<< HEAD use parse::obsolete::{ObsoleteAssertion, ObsoletePostFnTySigil}; +======= +use parse::obsolete::{ObsoleteAssertion, ObsoleteBareFnType}; +>>>>>>> libsyntax: Stop parsing bare functions in preparation for switching them over use parse::prec::{as_prec, token_to_binop}; use parse::token::{can_begin_expr, is_ident, is_ident_or_path}; use parse::token::{is_plain_ident, INTERPOLATED, special_idents}; @@ -647,8 +651,14 @@ pub impl Parser { } else if self.eat_keyword(&~"extern") { self.parse_ty_bare_fn() } else if self.token_is_closure_keyword(© *self.token) { +<<<<<<< HEAD // self.warn(fmt!("Old-school closure keyword")); self.parse_ty_closure(ast::BorrowedSigil, None) +======= + let result = self.parse_ty_closure(None, None); + self.obsolete(*self.last_span, ObsoleteBareFnType); + result +>>>>>>> libsyntax: Stop parsing bare functions in preparation for switching them over } else if *self.token == token::MOD_SEP || is_ident_or_path(&*self.token) { let path = self.parse_path_with_tps(colons_before_params); @@ -2813,7 +2823,7 @@ pub impl Parser { fn parse_fn_decl_with_self( &self, parse_arg_fn: - fn(&Parser) -> arg_or_capture_item + &fn(&Parser) -> arg_or_capture_item ) -> (self_ty, fn_decl) { fn maybe_parse_self_ty( cnstr: &fn(+v: mutability) -> ast::self_ty_, -- cgit 1.4.1-3-g733a5 From 7538450b8d5e831dca7891bdd54ebdf25d865970 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 7 Mar 2013 18:04:21 -0800 Subject: libsyntax: Remove newtype enums from libsyntax. rs=deenum --- src/libsyntax/ast.rs | 7 +------ src/libsyntax/codemap.rs | 4 ++-- src/libsyntax/ext/auto_encode.rs | 12 ------------ src/libsyntax/ext/pipes/pipec.rs | 4 +--- src/libsyntax/fold.rs | 21 ++++++++------------- src/libsyntax/parse/parser.rs | 6 ++---- 6 files changed, 14 insertions(+), 40 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f3e73823f69..27dba9c2b5e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1086,16 +1086,11 @@ pub enum variant_kind { #[auto_encode] #[auto_decode] #[deriving_eq] -pub struct enum_def_ { +pub struct enum_def { variants: ~[variant], common: Option<@struct_def>, } -#[auto_encode] -#[auto_decode] -#[deriving_eq] -pub enum enum_def = enum_def_; - #[auto_encode] #[auto_decode] #[deriving_eq] diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 3397ca91c96..0d6ece8ad92 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -35,11 +35,11 @@ pub trait Pos { } /// A byte offset -pub enum BytePos = uint; +pub struct BytePos(uint); /// A character offset. Because of multibyte utf8 characters, a byte offset /// is not equivalent to a character offset. The CodeMap will convert BytePos /// values to CharPos values as necessary. -pub enum CharPos = uint; +pub struct CharPos(uint); // XXX: Lots of boilerplate in these impls, but so far my attempts to fix // have been unsuccessful diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 8aa03e14fa4..c99d8977643 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -1327,16 +1327,4 @@ mod test { CallToEmitEnumVariantArg (1), CallToEmitUint (44)]); } - - pub enum BPos = uint; - - #[auto_encode] - pub struct HasPos { pos : BPos } - - #[test] fn encode_newtype_test () { - check_equal (to_call_log (HasPos {pos:BPos(48)}), - ~[CallToEmitStruct(~"HasPos",1), - CallToEmitField(~"pos",0), - CallToEmitUint(48)]); - } } diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 001e1b0daf6..fd8b2dbf72f 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -238,9 +238,7 @@ impl to_type_decls for state { cx.item_enum_poly( name, self.span, - ast::enum_def(enum_def_ { - variants: items_msg, - common: None }), + ast::enum_def { variants: items_msg, common: None }, cx.strip_bounds(&self.generics) ) ] diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 2a5fe788770..427760c920f 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -254,16 +254,14 @@ pub fn noop_fold_item_underscore(i: &item_, fld: @ast_fold) -> item_ { } item_enum(ref enum_definition, ref generics) => { item_enum( - ast::enum_def( - ast::enum_def_ { - variants: do enum_definition.variants.map |x| { - fld.fold_variant(x) - }, - common: do enum_definition.common.map |x| { - fold_struct_def(*x, fld) - } + ast::enum_def { + variants: do enum_definition.variants.map |x| { + fld.fold_variant(x) + }, + common: do enum_definition.common.map |x| { + fold_struct_def(*x, fld) } - ), + }, fold_generics(generics, fld)) } item_struct(ref struct_def, ref generics) => { @@ -684,10 +682,7 @@ fn noop_fold_variant(v: &variant_, fld: @ast_fold) -> variant_ { fold_struct_def(*x, fld) }; kind = enum_variant_kind( - ast::enum_def(ast::enum_def_ { - variants: variants, - common: common - }) + ast::enum_def { variants: variants, common: common } ); } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1c3d906e164..b2f11b8c437 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3775,7 +3775,7 @@ pub impl Parser { enum"); } - enum_def(ast::enum_def_ { variants: variants, common: common_fields }) + ast::enum_def { variants: variants, common: common_fields } } fn parse_item_enum(&self) -> item_info { @@ -3801,9 +3801,7 @@ pub impl Parser { return ( id, item_enum( - enum_def( - ast::enum_def_ { variants: ~[variant], common: None } - ), + ast::enum_def { variants: ~[variant], common: None }, generics), None ); -- cgit 1.4.1-3-g733a5 From a34749c28908997f8c58a646c9238c3dd8ea1103 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 7 Mar 2013 18:59:00 -0800 Subject: libsyntax: Stop parsing newtype enums --- src/libsyntax/parse/obsolete.rs | 5 +++++ src/libsyntax/parse/parser.rs | 14 ++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 757df713fc0..ef858a2d5eb 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -54,6 +54,7 @@ pub enum ObsoleteSyntax { ObsoleteAssertion, ObsoletePostFnTySigil, ObsoleteBareFnType, + ObsoleteNewtypeEnum, } impl to_bytes::IterBytes for ObsoleteSyntax { @@ -171,6 +172,10 @@ pub impl Parser { "bare function type", "use `&fn` or `extern fn` instead" ), + ObsoleteNewtypeEnum => ( + "newtype enum", + "instead of `enum Foo = int`, write `struct Foo(int)`" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b2f11b8c437..99c1c2cb1fe 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -76,11 +76,8 @@ use parse::obsolete::{ObsoleteUnsafeBlock, ObsoleteImplSyntax}; use parse::obsolete::{ObsoleteTraitBoundSeparator, ObsoleteMutOwnedPointer}; use parse::obsolete::{ObsoleteMutVector, ObsoleteTraitImplVisibility}; use parse::obsolete::{ObsoleteRecordType, ObsoleteRecordPattern}; -<<<<<<< HEAD use parse::obsolete::{ObsoleteAssertion, ObsoletePostFnTySigil}; -======= -use parse::obsolete::{ObsoleteAssertion, ObsoleteBareFnType}; ->>>>>>> libsyntax: Stop parsing bare functions in preparation for switching them over +use parse::obsolete::{ObsoleteBareFnType, ObsoleteNewtypeEnum}; use parse::prec::{as_prec, token_to_binop}; use parse::token::{can_begin_expr, is_ident, is_ident_or_path}; use parse::token::{is_plain_ident, INTERPOLATED, special_idents}; @@ -651,14 +648,9 @@ pub impl Parser { } else if self.eat_keyword(&~"extern") { self.parse_ty_bare_fn() } else if self.token_is_closure_keyword(© *self.token) { -<<<<<<< HEAD - // self.warn(fmt!("Old-school closure keyword")); - self.parse_ty_closure(ast::BorrowedSigil, None) -======= - let result = self.parse_ty_closure(None, None); + let result = self.parse_ty_closure(ast::BorrowedSigil, None); self.obsolete(*self.last_span, ObsoleteBareFnType); result ->>>>>>> libsyntax: Stop parsing bare functions in preparation for switching them over } else if *self.token == token::MOD_SEP || is_ident_or_path(&*self.token) { let path = self.parse_path_with_tps(colons_before_params); @@ -3798,6 +3790,8 @@ pub impl Parser { vis: public, }); + self.obsolete(*self.last_span, ObsoleteNewtypeEnum); + return ( id, item_enum( -- cgit 1.4.1-3-g733a5 From 08c840205ea477d4f76216abac45be6a4ce9fa4b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 8 Mar 2013 16:21:58 -0800 Subject: librustc: Lint the old `drop` destructor notation off --- doc/rust.md | 12 ++++----- doc/tutorial.md | 18 +++++++------- src/libcore/core.rc | 1 + src/librustc/middle/lint.rs | 29 ++++++++++++++++++++++ src/libsyntax/print/pprust.rs | 29 ++-------------------- src/test/compile-fail/issue-2063.rs | 2 ++ src/test/compile-fail/issue-2718-a.rs | 2 ++ src/test/run-pass/coherence-copy-bound.rs | 13 ---------- .../run-pass/operator-overloading-explicit-self.rs | 26 ------------------- 9 files changed, 51 insertions(+), 81 deletions(-) delete mode 100644 src/test/run-pass/coherence-copy-bound.rs delete mode 100644 src/test/run-pass/operator-overloading-explicit-self.rs (limited to 'src/libsyntax') diff --git a/doc/rust.md b/doc/rust.md index 8924ee6f4f6..e559af62e36 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -889,10 +889,10 @@ declared, in an angle-bracket-enclosed, comma-separated list following the function name. ~~~~ {.xfail-test} -fn iter(seq: &[T], f: fn(T)) { +fn iter(seq: &[T], f: &fn(T)) { for seq.each |elt| { f(elt); } } -fn map(seq: &[T], f: fn(T) -> U) -> ~[U] { +fn map(seq: &[T], f: &fn(T) -> U) -> ~[U] { let mut acc = ~[]; for seq.each |elt| { acc.push(f(elt)); } acc @@ -1198,7 +1198,7 @@ These appear after the trait name, using the same syntax used in [generic functi trait Seq { fn len() -> uint; fn elt_at(n: uint) -> T; - fn iter(fn(T)); + fn iter(&fn(T)); } ~~~~ @@ -2074,7 +2074,7 @@ and moving values from the environment into the lambda expression's captured env An example of a lambda expression: ~~~~ -fn ten_times(f: fn(int)) { +fn ten_times(f: &fn(int)) { let mut i = 0; while i < 10 { f(i); @@ -2177,7 +2177,7 @@ If the `expr` is a [field expression](#field-expressions), it is parsed as thoug In this example, both calls to `f` are equivalent: ~~~~ -# fn f(f: fn(int)) { } +# fn f(f: &fn(int)) { } # fn g(i: int) { } f(|j| g(j)); @@ -2755,7 +2755,7 @@ and the cast expression in `main`. Within the body of an item that has type parameter declarations, the names of its type parameters are types: ~~~~~~~ -fn map(f: fn(A) -> B, xs: &[A]) -> ~[B] { +fn map(f: &fn(A) -> B, xs: &[A]) -> ~[B] { if xs.len() == 0 { return ~[]; } let first: B = f(xs[0]); let rest: ~[B] = map(f, xs.slice(1, xs.len())); diff --git a/doc/tutorial.md b/doc/tutorial.md index 23ab1ce4400..e4775e1b11b 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1361,7 +1361,7 @@ the enclosing scope. ~~~~ # use println = core::io::println; -fn call_closure_with_ten(b: fn(int)) { b(10); } +fn call_closure_with_ten(b: &fn(int)) { b(10); } let captured_var = 20; let closure = |arg| println(fmt!("captured_var=%d, arg=%d", captured_var, arg)); @@ -1447,7 +1447,7 @@ should almost always declare the type of that argument as `fn()`. That way, callers may pass any kind of closure. ~~~~ -fn call_twice(f: fn()) { f(); f(); } +fn call_twice(f: &fn()) { f(); f(); } let closure = || { "I'm a closure, and it doesn't matter what type I am"; }; fn function() { "I'm a normal function"; } call_twice(closure); @@ -1467,7 +1467,7 @@ Consider this function that iterates over a vector of integers, passing in a pointer to each integer in the vector: ~~~~ -fn each(v: &[int], op: fn(v: &int)) { +fn each(v: &[int], op: &fn(v: &int)) { let mut n = 0; while n < v.len() { op(&v[n]); @@ -1488,7 +1488,7 @@ argument, we can write it in a way that has a pleasant, block-like structure. ~~~~ -# fn each(v: &[int], op: fn(v: &int)) { } +# fn each(v: &[int], op: &fn(v: &int)) { } # fn do_some_work(i: &int) { } each([1, 2, 3], |n| { do_some_work(n); @@ -1499,7 +1499,7 @@ This is such a useful pattern that Rust has a special form of function call that can be written more like a built-in control structure: ~~~~ -# fn each(v: &[int], op: fn(v: &int)) { } +# fn each(v: &[int], op: &fn(v: &int)) { } # fn do_some_work(i: &int) { } do each([1, 2, 3]) |n| { do_some_work(n); @@ -1546,7 +1546,7 @@ Consider again our `each` function, this time improved to break early when the iteratee returns `false`: ~~~~ -fn each(v: &[int], op: fn(v: &int) -> bool) { +fn each(v: &[int], op: &fn(v: &int) -> bool) { let mut n = 0; while n < v.len() { if !op(&v[n]) { @@ -1770,7 +1770,7 @@ vector consisting of the result of applying `function` to each element of `vector`: ~~~~ -fn map(vector: &[T], function: fn(v: &T) -> U) -> ~[U] { +fn map(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] { let mut accumulator = ~[]; for vec::each(vector) |element| { accumulator.push(function(element)); @@ -1969,12 +1969,12 @@ types might look like the following: ~~~~ trait Seq { fn len(&self) -> uint; - fn iter(&self, b: fn(v: &T)); + fn iter(&self, b: &fn(v: &T)); } impl Seq for ~[T] { fn len(&self) -> uint { vec::len(*self) } - fn iter(&self, b: fn(v: &T)) { + fn iter(&self, b: &fn(v: &T)) { for vec::each(*self) |elt| { b(elt); } } } diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 4d686c8ab33..db1dc1e28aa 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -52,6 +52,7 @@ Implicitly, all crates behave as if they included the following prologue: #[deny(non_camel_case_types)]; #[allow(deprecated_mutable_fields)]; #[deny(deprecated_self)]; +#[allow(deprecated_drop)]; // On Linux, link to the runtime with -lrt. #[cfg(target_os = "linux")] diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 5ff731a27f0..93f0557028e 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -77,6 +77,7 @@ pub enum lint { default_methods, deprecated_self, deprecated_mutable_fields, + deprecated_drop, managed_heap_memory, owned_heap_memory, @@ -251,6 +252,13 @@ pub fn get_lint_dict() -> LintDict { default: deny }), + (@~"deprecated_drop", + @LintSpec { + lint: deprecated_drop, + desc: "deprecated \"drop\" notation for the destructor", + default: deny + }), + /* FIXME(#3266)--make liveness warnings lintable (@~"unused_variable", @LintSpec { @@ -483,6 +491,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) { check_item_default_methods(cx, i); check_item_deprecated_self(cx, i); check_item_deprecated_mutable_fields(cx, i); + check_item_deprecated_drop(cx, i); } // Take a visitor, and modify it so that it will not proceed past subitems. @@ -720,6 +729,26 @@ fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) { } } +fn check_item_deprecated_drop(cx: ty::ctxt, item: @ast::item) { + match item.node { + ast::item_struct(struct_def, _) => { + match struct_def.dtor { + None => {} + Some(ref dtor) => { + cx.sess.span_lint(deprecated_drop, + item.id, + item.id, + dtor.span, + ~"`drop` notation for destructors is \ + deprecated; implement the `Drop` \ + trait instead"); + } + } + } + _ => {} + } +} + fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index e7e2435587e..49899fdeec4 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -612,36 +612,11 @@ pub fn print_item(s: @ps, &&item: @ast::item) { pub fn print_enum_def(s: @ps, enum_definition: ast::enum_def, generics: &ast::Generics, ident: ast::ident, span: codemap::span, visibility: ast::visibility) { - let mut newtype = - vec::len(enum_definition.variants) == 1u && - ident == enum_definition.variants[0].node.name; - if newtype { - match enum_definition.variants[0].node.kind { - ast::tuple_variant_kind(ref args) if args.len() == 1 => {} - _ => newtype = false - } - } - if newtype { - ibox(s, indent_unit); - word_space(s, visibility_qualified(visibility, ~"enum")); - } else { - head(s, visibility_qualified(visibility, ~"enum")); - } - + head(s, visibility_qualified(visibility, ~"enum")); print_ident(s, ident); print_generics(s, generics); space(s.s); - if newtype { - word_space(s, ~"="); - match /*bad*/ copy enum_definition.variants[0].node.kind { - ast::tuple_variant_kind(args) => print_type(s, args[0].ty), - _ => fail!(~"newtype syntax with struct?") - } - word(s.s, ~";"); - end(s); - } else { - print_variants(s, enum_definition.variants, span); - } + print_variants(s, enum_definition.variants, span); } pub fn print_variants(s: @ps, diff --git a/src/test/compile-fail/issue-2063.rs b/src/test/compile-fail/issue-2063.rs index 2f174671bd9..0ebf0218efe 100644 --- a/src/test/compile-fail/issue-2063.rs +++ b/src/test/compile-fail/issue-2063.rs @@ -1,3 +1,5 @@ +// xfail-test + // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/test/compile-fail/issue-2718-a.rs b/src/test/compile-fail/issue-2718-a.rs index 318982c3b13..8afaf8995c2 100644 --- a/src/test/compile-fail/issue-2718-a.rs +++ b/src/test/compile-fail/issue-2718-a.rs @@ -1,3 +1,5 @@ +// xfail-test + // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. diff --git a/src/test/run-pass/coherence-copy-bound.rs b/src/test/run-pass/coherence-copy-bound.rs deleted file mode 100644 index 9921389da66..00000000000 --- a/src/test/run-pass/coherence-copy-bound.rs +++ /dev/null @@ -1,13 +0,0 @@ -trait X {} - -impl X for A {} - -struct S { - x: int, - drop {} -} - -impl X for S {} - -pub fn main(){} - diff --git a/src/test/run-pass/operator-overloading-explicit-self.rs b/src/test/run-pass/operator-overloading-explicit-self.rs deleted file mode 100644 index 3d2fd649f15..00000000000 --- a/src/test/run-pass/operator-overloading-explicit-self.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct S { - x: int -} - -pub impl S { - pure fn add(&self, other: &S) -> S { - S { x: self.x + other.x } - } -} - -pub fn main() { - let mut s = S { x: 1 }; - s += S { x: 2 }; - fail_unless!(s.x == 3); -} - -- cgit 1.4.1-3-g733a5