From abc4ea2001c24f3a1e3d9edf3bebb1b2bb8629ec Mon Sep 17 00:00:00 2001 From: Ben Striegel Date: Mon, 25 Feb 2013 19:49:28 -0500 Subject: Stop parsing capture clauses --- src/libsyntax/parse/parser.rs | 58 +++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 38 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9bac163dab6..853b1408050 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -748,18 +748,6 @@ pub impl Parser { } } - fn parse_capture_item_or(parse_arg_fn: fn(Parser) -> arg_or_capture_item) - -> arg_or_capture_item - { - if self.eat_keyword(~"copy") { - // XXX outdated syntax now that moves-based-on-type has gone in - self.parse_ident(); - either::Right(()) - } else { - parse_arg_fn(self) - } - } - // This version of parse arg doesn't necessarily require // identifier names. fn parse_arg_general(require_name: bool) -> arg { @@ -788,32 +776,26 @@ pub impl Parser { either::Left(self.parse_arg_general(true)) } - fn parse_arg_or_capture_item() -> arg_or_capture_item { - self.parse_capture_item_or(|p| p.parse_arg()) - } - fn parse_fn_block_arg() -> arg_or_capture_item { - do self.parse_capture_item_or |p| { - let m = p.parse_arg_mode(); - let is_mutbl = self.eat_keyword(~"mut"); - let pat = p.parse_pat(false); - let t = if p.eat(token::COLON) { - p.parse_ty(false) - } else { - @Ty { - id: p.get_id(), - node: ty_infer, - span: mk_sp(p.span.lo, p.span.hi), - } - }; - either::Left(ast::arg { - mode: m, - is_mutbl: is_mutbl, - ty: t, - pat: pat, - id: p.get_id() - }) - } + let m = self.parse_arg_mode(); + let is_mutbl = self.eat_keyword(~"mut"); + let pat = self.parse_pat(false); + let t = if self.eat(token::COLON) { + self.parse_ty(false) + } else { + @Ty { + id: self.get_id(), + node: ty_infer, + span: mk_sp(self.span.lo, self.span.hi), + } + }; + either::Left(ast::arg { + mode: m, + is_mutbl: is_mutbl, + ty: t, + pat: pat, + id: self.get_id() + }) } fn maybe_parse_fixed_vstore_with_star() -> Option { @@ -1722,7 +1704,7 @@ pub impl Parser { // if we want to allow fn expression argument types to be inferred in // the future, just have to change parse_arg to parse_fn_block_arg. - let decl = self.parse_fn_decl(|p| p.parse_arg_or_capture_item()); + let decl = self.parse_fn_decl(|p| p.parse_arg()); let body = self.parse_block(); -- cgit 1.4.1-3-g733a5 From 9b8ce0d3b5dd5fd371d665258555db54b1656300 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 26 Feb 2013 04:01:35 -0800 Subject: libsyntax: Remove a mutable field from the tests. rs=demuting --- src/libsyntax/ext/auto_encode.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 7fbba987cc7..b345b116425 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -1176,9 +1176,9 @@ mod test { // all of the ones I was too lazy to handle: CallToOther } - // using a mutable field rather than changing the + // using `@mut` rather than changing the // type of self in every method of every encoder everywhere. - pub struct TestEncoder {mut call_log : ~[call]} + pub struct TestEncoder {call_log : @mut ~[call]} pub impl TestEncoder { // these self's should be &mut self's, as well.... @@ -1272,9 +1272,9 @@ mod test { struct Node {id: uint} fn to_call_log (val: Encodable) -> ~[call] { - let mut te = TestEncoder {call_log: ~[]}; + let mut te = TestEncoder {call_log: @mut ~[]}; val.encode(&te); - te.call_log + copy *te.call_log } /* #[test] fn encode_test () { -- cgit 1.4.1-3-g733a5 From 24893e8d02d70045254082067c0c6141b7946783 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Feb 2013 15:54:13 -0800 Subject: libsyntax: Stop parsing `~mut` --- src/libsyntax/parse/obsolete.rs | 7 +++++++ src/libsyntax/parse/parser.rs | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 1ae8786e09b..7b3030124b7 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -48,6 +48,7 @@ pub enum ObsoleteSyntax { ObsoleteUnenforcedBound, ObsoleteImplSyntax, ObsoleteTraitBoundSeparator, + ObsoleteMutOwnedPointer, } pub impl to_bytes::IterBytes for ObsoleteSyntax { @@ -126,6 +127,12 @@ pub impl Parser { "space-separated trait bounds", "write `+` between trait bounds" ), + ObsoleteMutOwnedPointer => ( + "mutable owned pointer", + "mutability inherits through `~` pointers; place the `~` box + in a mutable location, like a mutable local variable or an \ + `@mut` box" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 853b1408050..af25a4f6e58 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -75,7 +75,7 @@ use parse::obsolete::{ObsoleteMoveInit, ObsoleteBinaryMove}; use parse::obsolete::{ObsoleteStructCtor, ObsoleteWith}; use parse::obsolete::{ObsoleteSyntax, ObsoleteLowerCaseKindBounds}; use parse::obsolete::{ObsoleteUnsafeBlock, ObsoleteImplSyntax}; -use parse::obsolete::{ObsoleteTraitBoundSeparator}; +use parse::obsolete::{ObsoleteTraitBoundSeparator, ObsoleteMutOwnedPointer}; 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}; @@ -677,6 +677,11 @@ pub impl Parser { // rather than boxed ptrs. But the special casing of str/vec is not // reflected in the AST type. let mt = self.parse_mt(); + + if mt.mutbl == m_mutbl && sigil == OwnedSigil { + self.obsolete(*self.last_span, ObsoleteMutOwnedPointer); + } + ctor(mt) } -- cgit 1.4.1-3-g733a5 From 5e319fb2827903d6cb0c0d9d0af638c3f9503c81 Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 26 Feb 2013 10:12:44 -0800 Subject: Adds (more) test cases for auto_encode. --- src/libsyntax/ext/auto_encode.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 7fbba987cc7..2c685c360e9 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -1173,6 +1173,8 @@ mod test { CallToEmitEnumVariantArg(uint), CallToEmitUint(uint), CallToEmitNil, + CallToEmitStruct(~str,uint), + CallToEmitField(~str,uint), // all of the ones I was too lazy to handle: CallToOther } @@ -1251,11 +1253,11 @@ mod test { fn emit_rec(&self, f: fn()) { self.add_unknown_to_log(); f(); } - fn emit_struct(&self, _name: &str, +_len: uint, f: fn()) { - self.add_unknown_to_log(); f(); + 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()) { - self.add_unknown_to_log(); f(); + 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()) { @@ -1267,23 +1269,12 @@ mod test { } - #[auto_decode] - #[auto_encode] - struct Node {id: uint} - fn to_call_log (val: Encodable) -> ~[call] { let mut te = TestEncoder {call_log: ~[]}; val.encode(&te); te.call_log } -/* - #[test] fn encode_test () { - check_equal (to_call_log(Node{id:34} - as Encodable::), - ~[CallToEnum (~"Node"), - CallToEnumVariant]); - } -*/ + #[auto_encode] enum Written { Book(uint,uint), @@ -1300,4 +1291,17 @@ 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)} + as Encodable::), + ~[CallToEmitStruct(~"HasPos",1), + CallToEmitField(~"pos",0), + CallToEmitUint(48)]); + } } -- cgit 1.4.1-3-g733a5 From 08b6057538b9bb81bb71db632344ed0312e57f5f Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 26 Feb 2013 10:15:29 -0800 Subject: Macros now leave scope Macro scope is now delimited by function, block, and module boundaries, except for modules that are marked with #[macro_escape], which allows macros to escape. --- src/libsyntax/ast.rs | 32 +++- src/libsyntax/ext/base.rs | 221 ++++++++++++++++++++++++--- src/libsyntax/ext/expand.rs | 313 +++++++++++++++++++++++++++++++++------ src/libsyntax/ext/source_util.rs | 43 ++++-- src/libsyntax/parse/lexer.rs | 48 ++++++ src/libsyntax/parse/mod.rs | 36 ++--- src/libsyntax/parse/token.rs | 4 +- 7 files changed, 586 insertions(+), 111 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6befb2f1880..5af67aa0e3b 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -29,8 +29,37 @@ macro_rules! interner_key ( (-3 as uint, 0u))) ) +// an identifier contains an index into the interner +// table and a SyntaxContext to track renaming and +// macro expansion per Flatt et al., "Macros +// That Work Together" #[deriving_eq] -pub struct ident { repr: uint } +pub struct ident { repr: Name } + +// a SyntaxContext represents a chain of macro-expandings +// and renamings. Each macro expansion corresponds to +// a fresh uint +#[deriving_eq] +pub enum SyntaxContext { + MT, + Mark (Mrk,~SyntaxContext), + Rename (~ident,Name,~SyntaxContext) +} + +/* +// ** this is going to have to apply to paths, not to idents. +// Returns true if these two identifiers access the same +// local binding or top-level binding... that's what it +// should do. For now, it just compares the names. +pub fn free_ident_eq (a : ident, b: ident) -> bool{ + a.repr == b.repr +} +*/ +// a name represents a string, interned +type Name = uint; +// a mark represents a unique id associated +// with a macro expansion +type Mrk = uint; pub impl Encodable for ident { fn encode(&self, s: &S) { @@ -1230,6 +1259,7 @@ pub enum item_ { Option<@trait_ref>, // (optional) trait this impl implements @Ty, // self ~[@method]), + // a macro invocation (which includes macro definition) item_mac(mac), } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index f3a74302400..e75181eb89b 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -21,12 +21,12 @@ use parse::{parser, token}; use core::io; use core::vec; -use std::oldmap::HashMap; +use core::hashmap::linear::LinearMap; // new-style macro! tt code: // // SyntaxExpanderTT, SyntaxExpanderTTItem, MacResult, -// NormalTT, ItemTT +// NormalTT, IdentTT // // also note that ast::mac used to have a bunch of extraneous cases and // is now probably a redundant AST node, can be merged with @@ -71,25 +71,55 @@ pub enum SyntaxExtension { // Token-tree expanders NormalTT(SyntaxExpanderTT), + // An IdentTT is a macro that has an + // identifier in between the name of the + // macro and the argument. Currently, + // the only examples of this are + // macro_rules! and proto! + // perhaps macro_rules! will lose its odd special identifier argument, // and this can go away also - ItemTT(SyntaxExpanderTTItem), + IdentTT(SyntaxExpanderTTItem), } -type SyntaxExtensions = HashMap<@~str, SyntaxExtension>; +type SyntaxEnv = @mut MapChain; + +// Name : the domain of SyntaxEnvs +// want to change these to uints.... +// note that we use certain strings that are not legal as identifiers +// to indicate, for instance, how blocks are supposed to behave. +type Name = @~str; + +// Transformer : the codomain of SyntaxEnvs + +// NB: it may seem crazy to lump both of these into one environment; +// what would it mean to bind "foo" to BlockLimit(true)? The idea +// is that this follows the lead of MTWT, and accommodates growth +// toward a more uniform syntax syntax (sorry) where blocks are just +// another kind of transformer. + +enum Transformer { + // this identifier maps to a syntax extension or macro + SE(SyntaxExtension), + // should blocks occurring here limit macro scopes? + ScopeMacros(bool) +} -// A temporary hard-coded map of methods for expanding syntax extension +// The base map of methods for expanding syntax extension // AST nodes into full ASTs -pub fn syntax_expander_table() -> SyntaxExtensions { +pub fn syntax_expander_table() -> SyntaxEnv { // utility function to simplify creating NormalTT syntax extensions - fn builtin_normal_tt(f: SyntaxExpanderTTFun) -> SyntaxExtension { - NormalTT(SyntaxExpanderTT{expander: f, span: None}) + fn builtin_normal_tt(f: SyntaxExpanderTTFun) -> @Transformer { + @SE(NormalTT(SyntaxExpanderTT{expander: f, span: None})) } - // utility function to simplify creating ItemTT syntax extensions - fn builtin_item_tt(f: SyntaxExpanderTTItemFun) -> SyntaxExtension { - ItemTT(SyntaxExpanderTTItem{expander: f, span: None}) + // utility function to simplify creating IdentTT syntax extensions + fn builtin_item_tt(f: SyntaxExpanderTTItemFun) -> @Transformer { + @SE(IdentTT(SyntaxExpanderTTItem{expander: f, span: None})) } - let syntax_expanders = HashMap(); + let mut syntax_expanders = LinearMap::new(); + // NB identifier starts with space, and can't conflict with legal idents + syntax_expanders.insert(@~" block", + @ScopeMacros(true)); syntax_expanders.insert(@~"macro_rules", builtin_item_tt( ext::tt::macro_rules::add_new_extension)); @@ -97,10 +127,10 @@ pub fn syntax_expander_table() -> SyntaxExtensions { builtin_normal_tt(ext::fmt::expand_syntax_ext)); syntax_expanders.insert( @~"auto_encode", - ItemDecorator(ext::auto_encode::expand_auto_encode)); + @SE(ItemDecorator(ext::auto_encode::expand_auto_encode))); syntax_expanders.insert( @~"auto_decode", - ItemDecorator(ext::auto_encode::expand_auto_decode)); + @SE(ItemDecorator(ext::auto_encode::expand_auto_decode))); syntax_expanders.insert(@~"env", builtin_normal_tt(ext::env::expand_syntax_ext)); syntax_expanders.insert(@~"concat_idents", @@ -110,25 +140,25 @@ pub fn syntax_expander_table() -> SyntaxExtensions { builtin_normal_tt( ext::log_syntax::expand_syntax_ext)); syntax_expanders.insert(@~"deriving_eq", - ItemDecorator( - ext::deriving::expand_deriving_eq)); + @SE(ItemDecorator( + ext::deriving::expand_deriving_eq))); syntax_expanders.insert(@~"deriving_iter_bytes", - ItemDecorator( - ext::deriving::expand_deriving_iter_bytes)); + @SE(ItemDecorator( + ext::deriving::expand_deriving_iter_bytes))); // Quasi-quoting expanders syntax_expanders.insert(@~"quote_tokens", builtin_normal_tt(ext::quote::expand_quote_tokens)); syntax_expanders.insert(@~"quote_expr", - builtin_normal_tt(ext::quote::expand_quote_expr)); + builtin_normal_tt(ext::quote::expand_quote_expr)); syntax_expanders.insert(@~"quote_ty", - builtin_normal_tt(ext::quote::expand_quote_ty)); + builtin_normal_tt(ext::quote::expand_quote_ty)); syntax_expanders.insert(@~"quote_item", - builtin_normal_tt(ext::quote::expand_quote_item)); + builtin_normal_tt(ext::quote::expand_quote_item)); syntax_expanders.insert(@~"quote_pat", - builtin_normal_tt(ext::quote::expand_quote_pat)); + builtin_normal_tt(ext::quote::expand_quote_pat)); syntax_expanders.insert(@~"quote_stmt", - builtin_normal_tt(ext::quote::expand_quote_stmt)); + builtin_normal_tt(ext::quote::expand_quote_stmt)); syntax_expanders.insert(@~"line", builtin_normal_tt( @@ -159,7 +189,7 @@ pub fn syntax_expander_table() -> SyntaxExtensions { syntax_expanders.insert( @~"trace_macros", builtin_normal_tt(ext::trace_macros::expand_trace_macros)); - return syntax_expanders; + MapChain::new(~syntax_expanders) } // One of these is made during expansion and incrementally updated as we go; @@ -348,6 +378,149 @@ pub fn get_exprs_from_tts(cx: ext_ctxt, tts: ~[ast::token_tree]) es } +// in order to have some notion of scoping for macros, +// we want to implement the notion of a transformation +// environment. + +// This environment maps Names to Transformers. +// Initially, this includes macro definitions and +// block directives. + + + +// Actually, the following implementation is parameterized +// by both key and value types. + +//impl question: how to implement it? Initially, the +// env will contain only macros, so it might be painful +// to add an empty frame for every context. Let's just +// get it working, first.... + +// NB! the mutability of the underlying maps means that +// if expansion is out-of-order, a deeper scope may be +// able to refer to a macro that was added to an enclosing +// scope lexically later than the deeper scope. + +// Note on choice of representation: I've been pushed to +// use a top-level managed pointer by some difficulties +// with pushing and popping functionally, and the ownership +// issues. As a result, the values returned by the table +// also need to be managed; the &self/... type that Maps +// return won't work for things that need to get outside +// of that managed pointer. The easiest way to do this +// is just to insist that the values in the tables are +// managed to begin with. + +// a transformer env is either a base map or a map on top +// of another chain. +pub enum MapChain { + TEC_Base(~LinearMap), + TEC_Cons(~LinearMap,@mut MapChain) +} + + +// get the map from an env frame +impl MapChain{ + + // Constructor. I don't think we need a zero-arg one. + static fn new(+init: ~LinearMap) -> @mut MapChain { + @mut TEC_Base(init) + } + + // add a new frame to the environment (functionally) + fn push_frame (@mut self) -> @mut MapChain { + @mut TEC_Cons(~LinearMap::new() ,self) + } + +// no need for pop, it'll just be functional. + + // utility fn... + + // ugh: can't get this to compile with mut because of the + // lack of flow sensitivity. + fn get_map(&self) -> &self/LinearMap { + match *self { + TEC_Base (~ref map) => map, + TEC_Cons (~ref map,_) => map + } + } + +// traits just don't work anywhere...? +//pub impl Map for MapChain { + + pure fn contains_key (&self, key: &K) -> bool { + match *self { + TEC_Base (ref map) => map.contains_key(key), + TEC_Cons (ref map,ref rest) => + (map.contains_key(key) + || rest.contains_key(key)) + } + } + // should each_key and each_value operate on shadowed + // names? I think not. + // delaying implementing this.... + pure fn each_key (&self, _f: &fn (&K)->bool) { + fail!(~"unimplemented 2013-02-15T10:01"); + } + + pure fn each_value (&self, _f: &fn (&V) -> bool) { + fail!(~"unimplemented 2013-02-15T10:02"); + } + + // Returns a copy of the value that the name maps to. + // Goes down the chain 'til it finds one (or bottom out). + fn find (&self, key: &K) -> Option<@V> { + match self.get_map().find (key) { + Some(ref v) => Some(**v), + None => match *self { + TEC_Base (_) => None, + TEC_Cons (_,ref rest) => rest.find(key) + } + } + } + + // insert the binding into the top-level map + fn insert (&mut self, +key: K, +ext: @V) -> bool { + // can't abstract over get_map because of flow sensitivity... + match *self { + TEC_Base (~ref mut map) => map.insert(key, ext), + TEC_Cons (~ref mut map,_) => map.insert(key,ext) + } + } + +} + +#[cfg(test)] +mod test { + use super::*; + use super::MapChain; + use util::testing::check_equal; + + #[test] fn testenv () { + let mut a = LinearMap::new(); + a.insert (@~"abc",@15); + let m = MapChain::new(~a); + m.insert (@~"def",@16); + // FIXME: #4492 (ICE) check_equal(m.find(&@~"abc"),Some(@15)); + // .... check_equal(m.find(&@~"def"),Some(@16)); + check_equal(*(m.find(&@~"abc").get()),15); + check_equal(*(m.find(&@~"def").get()),16); + let n = m.push_frame(); + // old bindings are still present: + check_equal(*(n.find(&@~"abc").get()),15); + check_equal(*(n.find(&@~"def").get()),16); + n.insert (@~"def",@17); + // n shows the new binding + check_equal(*(n.find(&@~"abc").get()),15); + check_equal(*(n.find(&@~"def").get()),17); + // ... but m still has the old ones + // FIXME: #4492: check_equal(m.find(&@~"abc"),Some(@15)); + // FIXME: #4492: check_equal(m.find(&@~"def"),Some(@16)); + check_equal(*(m.find(&@~"abc").get()),15); + check_equal(*(m.find(&@~"def").get()),16); + } +} + // // Local Variables: // mode: rust diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 0b2aaa89d9b..0655a5efbf4 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -17,13 +17,13 @@ use attr; use codemap::{span, CallInfo, ExpandedFrom, NameAndSpan}; use ext::base::*; use fold::*; -use parse::{parser, parse_expr_from_source_str, new_parser_from_tts}; +use parse::{parser, parse_item_from_source_str, new_parser_from_tts}; use core::option; use core::vec; -use std::oldmap::HashMap; +use core::hashmap::LinearMap; -pub fn expand_expr(exts: SyntaxExtensions, cx: ext_ctxt, +pub fn expand_expr(extsbox: @mut SyntaxEnv, cx: ext_ctxt, e: expr_, s: span, fld: ast_fold, orig: fn@(expr_, span, ast_fold) -> (expr_, span)) -> (expr_, span) { @@ -41,13 +41,14 @@ pub fn expand_expr(exts: SyntaxExtensions, cx: ext_ctxt, /* using idents and token::special_idents would make the the macro names be hygienic */ let extname = cx.parse_sess().interner.get(pth.idents[0]); - match exts.find(&extname) { + // leaving explicit deref here to highlight unbox op: + match (*extsbox).find(&extname) { None => { cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)) } - Some(NormalTT(SyntaxExpanderTT{expander: exp, - span: exp_sp})) => { + Some(@SE(NormalTT(SyntaxExpanderTT{expander: exp, + span: exp_sp}))) => { cx.bt_push(ExpandedFrom(CallInfo{ call_site: s, callee: NameAndSpan { @@ -92,7 +93,7 @@ pub fn expand_expr(exts: SyntaxExtensions, cx: ext_ctxt, // // NB: there is some redundancy between this and expand_item, below, and // they might benefit from some amount of semantic and language-UI merger. -pub fn expand_mod_items(exts: SyntaxExtensions, cx: ext_ctxt, +pub fn expand_mod_items(extsbox: @mut SyntaxEnv, cx: ext_ctxt, module_: ast::_mod, fld: ast_fold, orig: fn@(ast::_mod, ast_fold) -> ast::_mod) -> ast::_mod { @@ -106,9 +107,8 @@ pub fn expand_mod_items(exts: SyntaxExtensions, cx: ext_ctxt, do vec::foldr(item.attrs, ~[*item]) |attr, items| { let mname = attr::get_attr_name(attr); - match exts.find(&mname) { - None | Some(NormalTT(_)) | Some(ItemTT(*)) => items, - Some(ItemDecorator(dec_fn)) => { + match (*extsbox).find(&mname) { + Some(@SE(ItemDecorator(dec_fn))) => { cx.bt_push(ExpandedFrom(CallInfo { call_site: attr.span, callee: NameAndSpan { @@ -119,7 +119,8 @@ pub fn expand_mod_items(exts: SyntaxExtensions, cx: ext_ctxt, let r = dec_fn(cx, attr.span, attr.node.value, items); cx.bt_pop(); r - } + }, + _ => items, } } }; @@ -128,34 +129,94 @@ pub fn expand_mod_items(exts: SyntaxExtensions, cx: ext_ctxt, } +// eval $e with a new exts frame: +macro_rules! with_exts_frame ( + ($extsboxexpr:expr,$e:expr) => + ({let extsbox = $extsboxexpr; + let oldexts = *extsbox; + *extsbox = oldexts.push_frame(); + let result = $e; + *extsbox = oldexts; + result + }) +) + // When we enter a module, record it, for the sake of `module!` -pub fn expand_item(exts: SyntaxExtensions, +pub fn expand_item(extsbox: @mut SyntaxEnv, cx: ext_ctxt, &&it: @ast::item, fld: ast_fold, orig: fn@(&&v: @ast::item, ast_fold) -> Option<@ast::item>) -> Option<@ast::item> { - let is_mod = match it.node { - ast::item_mod(_) | ast::item_foreign_mod(_) => true, - _ => false - }; + // need to do expansion first... it might turn out to be a module. let maybe_it = match it.node { - ast::item_mac(*) => expand_item_mac(exts, cx, it, fld), + ast::item_mac(*) => expand_item_mac(extsbox, cx, it, fld), _ => Some(it) }; - match maybe_it { Some(it) => { - if is_mod { cx.mod_push(it.ident); } - let ret_val = orig(it, fld); - if is_mod { cx.mod_pop(); } - return ret_val; + match it.node { + ast::item_mod(_) | ast::item_foreign_mod(_) => { + cx.mod_push(it.ident); + let result = + // don't push a macro scope for macro_escape: + if contains_macro_escape(it.attrs) { + orig(it,fld) + } else { + // otherwise, push a scope: + with_exts_frame!(extsbox,orig(it,fld)) + }; + cx.mod_pop(); + result + } + _ => orig(it,fld) + } } - None => return None + None => None } } +// does this attribute list contain "macro_escape" ? +fn contains_macro_escape (attrs: &[ast::attribute]) -> bool{ + let mut accum = false; + do attrs.each |attr| { + let mname = attr::get_attr_name(attr); + if (mname == @~"macro_escape") { + accum = true; + false + } else { + true + } + } + accum +} + +// this macro disables (one layer of) macro +// scoping, to allow a block to add macro bindings +// to its parent env +macro_rules! without_macro_scoping( + ($extsexpr:expr,$exp:expr) => + ({ + // only evaluaate this once: + let exts = $extsexpr; + // capture the existing binding: + let existingBlockBinding = + match exts.find(&@~" block"){ + Some(binding) => binding, + None => cx.bug("expected to find \" block\" binding") + }; + // this prevents the block from limiting the macros' scope: + exts.insert(@~" block",@ScopeMacros(false)); + let result = $exp; + // reset the block binding. Note that since the original + // one may have been inherited, this procedure may wind + // up introducing a block binding where one didn't exist + // before. + exts.insert(@~" block",existingBlockBinding); + result + })) + // Support for item-position macro invocations, exactly the same // logic as for expression-position macro invocations. -pub fn expand_item_mac(exts: SyntaxExtensions, +pub fn expand_item_mac(+extsbox: @mut SyntaxEnv, cx: ext_ctxt, &&it: @ast::item, fld: ast_fold) -> Option<@ast::item> { @@ -167,11 +228,11 @@ pub fn expand_item_mac(exts: SyntaxExtensions, }; let extname = cx.parse_sess().interner.get(pth.idents[0]); - let expanded = match exts.find(&extname) { + let expanded = match (*extsbox).find(&extname) { None => cx.span_fatal(pth.span, fmt!("macro undefined: '%s!'", *extname)), - Some(NormalTT(ref expand)) => { + Some(@SE(NormalTT(ref expand))) => { if it.ident != parse::token::special_idents::invalid { cx.span_fatal(pth.span, fmt!("macro %s! expects no ident argument, \ @@ -187,7 +248,7 @@ pub fn expand_item_mac(exts: SyntaxExtensions, })); ((*expand).expander)(cx, it.span, tts) } - Some(ItemTT(ref expand)) => { + Some(@SE(IdentTT(ref expand))) => { if it.ident == parse::token::special_idents::invalid { cx.span_fatal(pth.span, fmt!("macro %s! expects an ident argument", @@ -214,7 +275,7 @@ pub fn expand_item_mac(exts: SyntaxExtensions, MRAny(_, item_maker, _) => option::chain(item_maker(), |i| {fld.fold_item(i)}), MRDef(ref mdef) => { - exts.insert(@/*bad*/ copy mdef.name, (*mdef).ext); + extsbox.insert(@/*bad*/ copy mdef.name, @SE((*mdef).ext)); None } }; @@ -222,7 +283,8 @@ pub fn expand_item_mac(exts: SyntaxExtensions, return maybe_it; } -pub fn expand_stmt(exts: SyntaxExtensions, cx: ext_ctxt, +// expand a stmt +pub fn expand_stmt(extsbox: @mut SyntaxEnv, cx: ext_ctxt, && s: stmt_, sp: span, fld: ast_fold, orig: fn@(&&s: stmt_, span, ast_fold) -> (stmt_, span)) -> (stmt_, span) { @@ -238,12 +300,12 @@ pub fn expand_stmt(exts: SyntaxExtensions, cx: ext_ctxt, assert(vec::len(pth.idents) == 1u); let extname = cx.parse_sess().interner.get(pth.idents[0]); - let (fully_expanded, sp) = match exts.find(&extname) { + let (fully_expanded, sp) = match (*extsbox).find(&extname) { None => cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)), - Some(NormalTT( - SyntaxExpanderTT{expander: exp, span: exp_sp})) => { + Some(@SE(NormalTT( + SyntaxExpanderTT{expander: exp, span: exp_sp}))) => { cx.bt_push(ExpandedFrom(CallInfo { call_site: sp, callee: NameAndSpan { name: *extname, span: exp_sp } @@ -271,7 +333,7 @@ pub fn expand_stmt(exts: SyntaxExtensions, cx: ext_ctxt, } }; - return (match fully_expanded { + (match fully_expanded { stmt_expr(e, stmt_id) if semi => stmt_semi(e, stmt_id), _ => { fully_expanded } /* might already have a semi */ }, sp) @@ -279,19 +341,39 @@ pub fn expand_stmt(exts: SyntaxExtensions, cx: ext_ctxt, } + +pub fn expand_block(extsbox: @mut SyntaxEnv, cx: ext_ctxt, + && blk: blk_, sp: span, fld: ast_fold, + orig: fn@(&&s: blk_, span, ast_fold) -> (blk_, span)) + -> (blk_, span) { + match (*extsbox).find(&@~" block") { + // no scope limit on macros in this block, no need + // to push an exts frame: + Some(@ScopeMacros(false)) => { + orig (blk,sp,fld) + }, + // this block should limit the scope of its macros: + Some(@ScopeMacros(true)) => { + // see note below about treatment of exts table + with_exts_frame!(extsbox,orig(blk,sp,fld)) + }, + _ => cx.span_bug(sp, + ~"expected ScopeMacros binding for \" block\"") + } +} + pub fn new_span(cx: ext_ctxt, sp: span) -> span { /* this discards information in the case of macro-defining macros */ return span {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()}; } -// FIXME (#2247): this is a terrible kludge to inject some macros into -// the default compilation environment. When the macro-definition system -// is substantially more mature, these should move from here, into a -// compiled part of libcore at very least. +// FIXME (#2247): this is a moderately bad kludge to inject some macros into +// the default compilation environment. It would be much nicer to use +// a mechanism like syntax_quote to ensure hygiene. pub fn core_macros() -> ~str { return -~"{ +~"pub mod macros { macro_rules! ignore (($($x:tt)*) => (())) macro_rules! error ( ($( $arg:expr ),+) => ( @@ -339,31 +421,164 @@ pub fn core_macros() -> ~str { }"; } +// could cfg just be a borrowed pointer here? + pub fn expand_crate(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg, c: @crate) -> @crate { - let exts = syntax_expander_table(); + // adding *another* layer of indirection here so that the block + // visitor can swap out one exts table for another for the duration + // of the block. The cleaner alternative would be to thread the + // exts table through the fold, but that would require updating + // every method/element of AstFoldFns in fold.rs. + let extsbox = @mut syntax_expander_table(); let afp = default_ast_fold(); let cx: ext_ctxt = mk_ctxt(parse_sess, cfg); let f_pre = @AstFoldFns { - fold_expr: |a,b,c| expand_expr(exts, cx, a, b, c, afp.fold_expr), - fold_mod: |a,b| expand_mod_items(exts, cx, a, b, afp.fold_mod), - fold_item: |a,b| expand_item(exts, cx, a, b, afp.fold_item), - fold_stmt: |a,b,c| expand_stmt(exts, cx, a, b, c, afp.fold_stmt), + fold_expr: |expr,span,recur| + expand_expr(extsbox, cx, expr, span, recur, afp.fold_expr), + fold_mod: |modd,recur| + expand_mod_items(extsbox, cx, modd, recur, afp.fold_mod), + fold_item: |item,recur| + expand_item(extsbox, cx, item, recur, afp.fold_item), + fold_stmt: |stmt,span,recur| + expand_stmt(extsbox, cx, stmt, span, recur, afp.fold_stmt), + fold_block: |blk,span,recur| + expand_block (extsbox, cx, blk, span, recur, afp.fold_block), new_span: |a| new_span(cx, a), .. *afp}; let f = make_fold(f_pre); - let cm = parse_expr_from_source_str(~"", - @core_macros(), - cfg, - parse_sess); - + // add a bunch of macros as though they were placed at the + // head of the program (ick). + let attrs = ~[spanned {span:codemap::dummy_sp(), + node: attribute_ + {style:attr_outer, + value:spanned + {node:meta_word(@~"macro_escape"), + span:codemap::dummy_sp()}, + is_sugared_doc:false}}]; + + let cm = match parse_item_from_source_str(~"", + @core_macros(), + cfg,attrs, + parse_sess) { + Some(item) => item, + None => cx.bug(~"expected core macros to parse correctly") + }; // This is run for its side-effects on the expander env, // as it registers all the core macros as expanders. - f.fold_expr(cm); + f.fold_item(cm); let res = @f.fold_crate(*c); return res; } + +#[cfg(test)] +mod test { + use super::*; + use util::testing::check_equal; + + // make sure that fail! is present + #[test] fn fail_exists_test () { + let src = ~"fn main() { fail!(~\"something appropriately gloomy\");}"; + let sess = parse::new_parse_sess(None); + let cfg = ~[]; + let crate_ast = parse::parse_crate_from_source_str( + ~"", + @src, + cfg,sess); + expand_crate(sess,cfg,crate_ast); + } + + // these following tests are quite fragile, in that they don't test what + // *kind* of failure occurs. + + // make sure that macros can leave scope + #[should_fail] + #[test] fn macros_cant_escape_fns_test () { + let src = ~"fn bogus() {macro_rules! z (() => (3+4))}\ + fn inty() -> int { z!() }"; + let sess = parse::new_parse_sess(None); + let cfg = ~[]; + let crate_ast = parse::parse_crate_from_source_str( + ~"", + @src, + cfg,sess); + // should fail: + expand_crate(sess,cfg,crate_ast); + } + + // make sure that macros can leave scope for modules + #[should_fail] + #[test] fn macros_cant_escape_mods_test () { + let src = ~"mod foo {macro_rules! z (() => (3+4))}\ + fn inty() -> int { z!() }"; + let sess = parse::new_parse_sess(None); + let cfg = ~[]; + let crate_ast = parse::parse_crate_from_source_str( + ~"", + @src, + cfg,sess); + // should fail: + expand_crate(sess,cfg,crate_ast); + } + + // macro_escape modules shouldn't cause macros to leave scope + #[test] fn macros_can_escape_flattened_mods_test () { + let src = ~"#[macro_escape] mod foo {macro_rules! z (() => (3+4))}\ + fn inty() -> int { z!() }"; + let sess = parse::new_parse_sess(None); + let cfg = ~[]; + let crate_ast = parse::parse_crate_from_source_str( + ~"", + @src, + cfg,sess); + // should fail: + expand_crate(sess,cfg,crate_ast); + } + + #[test] fn core_macros_must_parse () { + let src = ~" + pub mod macros { + macro_rules! ignore (($($x:tt)*) => (())) + + macro_rules! error ( ($( $arg:expr ),+) => ( + log(::core::error, fmt!( $($arg),+ )) )) +}"; + let sess = parse::new_parse_sess(None); + let cfg = ~[]; + let item_ast = parse::parse_item_from_source_str( + ~"", + @src, + cfg,~[make_dummy_attr (@~"macro_escape")],sess); + match item_ast { + Some(_) => (), // success + None => fail!(~"expected this to parse") + } + } + + #[test] fn test_contains_flatten (){ + let attr1 = make_dummy_attr (@~"foo"); + let attr2 = make_dummy_attr (@~"bar"); + let escape_attr = make_dummy_attr (@~"macro_escape"); + let attrs1 = ~[attr1, escape_attr, attr2]; + check_equal (contains_macro_escape (attrs1),true); + let attrs2 = ~[attr1,attr2]; + check_equal (contains_macro_escape (attrs2),false); + } + + // make a "meta_word" outer attribute with the given name + fn make_dummy_attr(s: @~str) -> ast::attribute { + spanned {span:codemap::dummy_sp(), + node: attribute_ + {style:attr_outer, + value:spanned + {node:meta_word(s), + span:codemap::dummy_sp()}, + is_sugared_doc:false}} + } + +} + // Local Variables: // mode: rust // fill-column: 78; diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 26c38c945c7..808a80e6ad0 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -22,22 +22,9 @@ use core::result; use core::str; use core::vec; -fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo { - let ExpandedFrom(CallInfo { call_site, _ }) = *expn_info; - match call_site.expn_info { - Some(next_expn_info) => { - let ExpandedFrom(CallInfo { - callee: NameAndSpan {name, _}, - _ - }) = *next_expn_info; - // Don't recurse into file using "include!" - if name == ~"include" { return expn_info; } - - topmost_expn_info(next_expn_info) - }, - None => expn_info - } -} +// These macros all relate to the file system; they either return +// the column/row/filename of the expression, or they include +// a given file into the current one. /* line!(): expands to the current line number */ pub fn expand_line(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) @@ -87,6 +74,9 @@ pub fn expand_mod(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) |x| cx.str_of(*x)), ~"::"))) } +// include! : parse the given file as an expr +// This is generally a bad idea because it's going to behave +// unhygienically. pub fn expand_include(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include!"); @@ -96,6 +86,7 @@ pub fn expand_include(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) base::MRExpr(p.parse_expr()) } +// include_str! : read the given file, insert it as a literal string expr pub fn expand_include_str(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); @@ -126,6 +117,26 @@ pub fn expand_include_bin(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) } } +// recur along an ExpnInfo chain to find the original expression +fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo { + let ExpandedFrom(CallInfo { call_site, _ }) = *expn_info; + match call_site.expn_info { + Some(next_expn_info) => { + let ExpandedFrom(CallInfo { + callee: NameAndSpan {name, _}, + _ + }) = *next_expn_info; + // Don't recurse into file using "include!" + if name == ~"include" { return expn_info; } + + topmost_expn_info(next_expn_info) + }, + None => expn_info + } +} + +// resolve a file-system path to an absolute file-system path (if it +// isn't already) fn res_rel_file(cx: ext_ctxt, sp: codemap::span, arg: &Path) -> Path { // NB: relative paths are resolved relative to the compilation unit if !arg.is_absolute { diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 92c4f1e828f..51cc25e84a3 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -770,11 +770,13 @@ pub mod test { use diagnostic; use util::testing::{check_equal, check_equal_ptr}; + // represents a testing reader (incl. both reader and interner) struct Env { interner: @token::ident_interner, string_reader: @mut StringReader } + // open a string reader for the given string fn setup(teststr: ~str) -> Env { let cm = CodeMap::new(); let fm = cm.new_filemap(~"zebra.rs", @teststr); @@ -809,6 +811,52 @@ pub mod test { check_equal (string_reader.last_pos,BytePos(29)) } + // check that the given reader produces the desired stream + // of tokens (stop checking after exhausting the expected vec) + fn check_tokenization (env: Env, expected: ~[token::Token]) { + for expected.each |expected_tok| { + let TokenAndSpan {tok:actual_tok, sp: _} = + env.string_reader.next_token(); + check_equal(&actual_tok,expected_tok); + } + } + + // make the identifier by looking up the string in the interner + fn mk_ident (env: Env, id: ~str, is_mod_name: bool) -> token::Token { + token::IDENT (env.interner.intern(@id),is_mod_name) + } + + #[test] fn doublecolonparsing () { + let env = setup (~"a b"); + check_tokenization (env, + ~[mk_ident (env,~"a",false), + mk_ident (env,~"b",false)]); + } + + #[test] fn dcparsing_2 () { + let env = setup (~"a::b"); + check_tokenization (env, + ~[mk_ident (env,~"a",true), + token::MOD_SEP, + mk_ident (env,~"b",false)]); + } + + #[test] fn dcparsing_3 () { + let env = setup (~"a ::b"); + check_tokenization (env, + ~[mk_ident (env,~"a",false), + token::MOD_SEP, + mk_ident (env,~"b",false)]); + } + + #[test] fn dcparsing_4 () { + let env = setup (~"a:: b"); + check_tokenization (env, + ~[mk_ident (env,~"a",true), + token::MOD_SEP, + mk_ident (env,~"b",false)]); + } + #[test] fn character_a() { let env = setup(~"'a'"); let TokenAndSpan {tok, sp: _} = diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 5fa61159385..a31a73f594a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -94,9 +94,7 @@ pub fn parse_crate_from_source_str(name: ~str, sess: @mut ParseSess) -> @ast::crate { let p = new_parser_from_source_str(sess, cfg, name, codemap::FssNone, source); - let r = p.parse_crate_mod(cfg); - p.abort_if_errors(); - return r; + maybe_aborted(p.parse_crate_mod(cfg),p) } pub fn parse_expr_from_source_str(name: ~str, @@ -105,9 +103,7 @@ pub fn parse_expr_from_source_str(name: ~str, sess: @mut ParseSess) -> @ast::expr { let p = new_parser_from_source_str(sess, cfg, name, codemap::FssNone, source); - let r = p.parse_expr(); - p.abort_if_errors(); - return r; + maybe_aborted(p.parse_expr(), p) } pub fn parse_item_from_source_str(name: ~str, @@ -118,9 +114,7 @@ pub fn parse_item_from_source_str(name: ~str, -> Option<@ast::item> { let p = new_parser_from_source_str(sess, cfg, name, codemap::FssNone, source); - let r = p.parse_item(attrs); - p.abort_if_errors(); - return r; + maybe_aborted(p.parse_item(attrs),p) } pub fn parse_stmt_from_source_str(name: ~str, @@ -130,9 +124,7 @@ pub fn parse_stmt_from_source_str(name: ~str, sess: @mut ParseSess) -> @ast::stmt { let p = new_parser_from_source_str(sess, cfg, name, codemap::FssNone, source); - let r = p.parse_stmt(attrs); - p.abort_if_errors(); - return r; + maybe_aborted(p.parse_stmt(attrs),p) } pub fn parse_tts_from_source_str(name: ~str, @@ -142,9 +134,7 @@ pub fn parse_tts_from_source_str(name: ~str, let p = new_parser_from_source_str(sess, cfg, name, codemap::FssNone, source); *p.quote_depth += 1u; - let r = p.parse_all_token_trees(); - p.abort_if_errors(); - return r; + maybe_aborted(p.parse_all_token_trees(),p) } pub fn parse_from_source_str(f: fn (p: Parser) -> T, @@ -159,8 +149,7 @@ pub fn parse_from_source_str(f: fn (p: Parser) -> T, if !p.reader.is_eof() { p.reader.fatal(~"expected end-of-string"); } - p.abort_if_errors(); - r + maybe_aborted(r,p) } pub fn next_node_id(sess: @mut ParseSess) -> node_id { @@ -181,8 +170,8 @@ pub fn new_parser_from_source_str(sess: @mut ParseSess, cfg: ast::crate_cfg, return Parser(sess, cfg, srdr as reader); } -// Read the entire source file, return a parser -// that draws from that string +/// Read the entire source file, return a parser +/// that draws from that string pub fn new_parser_result_from_file(sess: @mut ParseSess, cfg: ast::crate_cfg, path: &Path) @@ -201,7 +190,7 @@ pub fn new_parser_result_from_file(sess: @mut ParseSess, } } -/// Create a new parser for an entire crate, handling errors as appropriate +/// Create a new parser, handling errors as appropriate /// if the file doesn't exist pub fn new_parser_from_file(sess: @mut ParseSess, cfg: ast::crate_cfg, path: &Path) -> Parser { @@ -232,6 +221,13 @@ pub fn new_parser_from_tts(sess: @mut ParseSess, cfg: ast::crate_cfg, return Parser(sess, cfg, trdr as reader) } +// abort if necessary +pub fn maybe_aborted(+result : T, p: Parser) -> T { + p.abort_if_errors(); + result +} + + #[cfg(test)] mod test { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index f145e433fa7..207f6d49915 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -87,7 +87,9 @@ pub enum Token { LIT_STR(ast::ident), /* Name components */ - // an identifier contains an "is_mod_name" boolean. + // an identifier contains an "is_mod_name" boolean, + // indicating whether :: follows this token with no + // whitespace in between. IDENT(ast::ident, bool), UNDERSCORE, LIFETIME(ast::ident), -- cgit 1.4.1-3-g733a5 From 6aefaf22c758b76703ed850bcf817dda127a5d67 Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 26 Feb 2013 15:48:00 -0800 Subject: typo-fixing and name-changes --- src/libsyntax/ext/base.rs | 24 ++++++++++++------------ src/libsyntax/ext/expand.rs | 4 +--- 2 files changed, 13 insertions(+), 15 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index e75181eb89b..0eaf6849b7e 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -414,8 +414,8 @@ pub fn get_exprs_from_tts(cx: ext_ctxt, tts: ~[ast::token_tree]) // a transformer env is either a base map or a map on top // of another chain. pub enum MapChain { - TEC_Base(~LinearMap), - TEC_Cons(~LinearMap,@mut MapChain) + BaseMapChain(~LinearMap), + ConsMapChain(~LinearMap,@mut MapChain) } @@ -424,12 +424,12 @@ impl MapChain{ // Constructor. I don't think we need a zero-arg one. static fn new(+init: ~LinearMap) -> @mut MapChain { - @mut TEC_Base(init) + @mut BaseMapChain(init) } // add a new frame to the environment (functionally) fn push_frame (@mut self) -> @mut MapChain { - @mut TEC_Cons(~LinearMap::new() ,self) + @mut ConsMapChain(~LinearMap::new() ,self) } // no need for pop, it'll just be functional. @@ -440,8 +440,8 @@ impl MapChain{ // lack of flow sensitivity. fn get_map(&self) -> &self/LinearMap { match *self { - TEC_Base (~ref map) => map, - TEC_Cons (~ref map,_) => map + BaseMapChain (~ref map) => map, + ConsMapChain (~ref map,_) => map } } @@ -450,8 +450,8 @@ impl MapChain{ pure fn contains_key (&self, key: &K) -> bool { match *self { - TEC_Base (ref map) => map.contains_key(key), - TEC_Cons (ref map,ref rest) => + BaseMapChain (ref map) => map.contains_key(key), + ConsMapChain (ref map,ref rest) => (map.contains_key(key) || rest.contains_key(key)) } @@ -473,8 +473,8 @@ impl MapChain{ match self.get_map().find (key) { Some(ref v) => Some(**v), None => match *self { - TEC_Base (_) => None, - TEC_Cons (_,ref rest) => rest.find(key) + BaseMapChain (_) => None, + ConsMapChain (_,ref rest) => rest.find(key) } } } @@ -483,8 +483,8 @@ impl MapChain{ fn insert (&mut self, +key: K, +ext: @V) -> bool { // can't abstract over get_map because of flow sensitivity... match *self { - TEC_Base (~ref mut map) => map.insert(key, ext), - TEC_Cons (~ref mut map,_) => map.insert(key,ext) + BaseMapChain (~ref mut map) => map.insert(key, ext), + ConsMapChain (~ref mut map,_) => map.insert(key,ext) } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 0655a5efbf4..9a3e8da2b81 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -195,7 +195,7 @@ fn contains_macro_escape (attrs: &[ast::attribute]) -> bool{ macro_rules! without_macro_scoping( ($extsexpr:expr,$exp:expr) => ({ - // only evaluaate this once: + // only evaluate this once: let exts = $extsexpr; // capture the existing binding: let existingBlockBinding = @@ -421,8 +421,6 @@ pub fn core_macros() -> ~str { }"; } -// could cfg just be a borrowed pointer here? - pub fn expand_crate(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg, c: @crate) -> @crate { // adding *another* layer of indirection here so that the block -- cgit 1.4.1-3-g733a5 From 8d7e6ef7725f8a11de940892a74398fc1911dfc7 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 26 Feb 2013 11:32:00 -0800 Subject: libsyntax: Forbid `~mut` and `~const`. rs=demuting --- doc/tutorial.md | 2 +- src/libcore/owned.rs | 16 ++++++++-------- src/libstd/arc.rs | 7 ++++--- src/libstd/future.rs | 11 +++++------ src/libstd/sync.rs | 11 ++++++----- src/libstd/workcache.rs | 5 +++-- src/libsyntax/parse/obsolete.rs | 2 +- src/libsyntax/parse/parser.rs | 6 +++++- src/test/compile-fail/mutable-huh-unique-assign.rs | 19 ------------------- 9 files changed, 33 insertions(+), 46 deletions(-) delete mode 100644 src/test/compile-fail/mutable-huh-unique-assign.rs (limited to 'src/libsyntax') diff --git a/doc/tutorial.md b/doc/tutorial.md index 98ec9d1f580..f9408761877 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1126,7 +1126,7 @@ points to. ~~~ let managed = @mut 10; -let owned = ~mut 20; +let mut owned = ~20; let mut value = 30; let borrowed = &mut value; diff --git a/src/libcore/owned.rs b/src/libcore/owned.rs index 230386655e0..3b839e5a9e0 100644 --- a/src/libcore/owned.rs +++ b/src/libcore/owned.rs @@ -13,22 +13,22 @@ use cmp::{Eq, Ord}; #[cfg(notest)] -impl Eq for ~const T { +impl Eq for ~T { #[inline(always)] - pure fn eq(&self, other: &~const T) -> bool { *(*self) == *(*other) } + pure fn eq(&self, other: &~T) -> bool { *(*self) == *(*other) } #[inline(always)] - pure fn ne(&self, other: &~const T) -> bool { *(*self) != *(*other) } + pure fn ne(&self, other: &~T) -> bool { *(*self) != *(*other) } } #[cfg(notest)] -impl Ord for ~const T { +impl Ord for ~T { #[inline(always)] - pure fn lt(&self, other: &~const T) -> bool { *(*self) < *(*other) } + pure fn lt(&self, other: &~T) -> bool { *(*self) < *(*other) } #[inline(always)] - pure fn le(&self, other: &~const T) -> bool { *(*self) <= *(*other) } + pure fn le(&self, other: &~T) -> bool { *(*self) <= *(*other) } #[inline(always)] - pure fn ge(&self, other: &~const T) -> bool { *(*self) >= *(*other) } + pure fn ge(&self, other: &~T) -> bool { *(*self) >= *(*other) } #[inline(always)] - pure fn gt(&self, other: &~const T) -> bool { *(*self) > *(*other) } + pure fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) } } diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index 61b5ffd845f..f258e649122 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -17,6 +17,7 @@ use sync; use sync::{Mutex, mutex_with_condvars, RWlock, rwlock_with_condvars}; use core::cast; +use core::cell::Cell; use core::pipes; use core::prelude::*; use core::private::{SharedMutableState, shared_mutable_state}; @@ -532,17 +533,17 @@ mod tests { let arc = ~MutexARC(false); let arc2 = ~arc.clone(); let (p,c) = comm::oneshot(); - let (c,p) = (~mut Some(c), ~mut Some(p)); + let (c,p) = (Cell(c), Cell(p)); do task::spawn || { // wait until parent gets in - comm::recv_one(option::swap_unwrap(p)); + comm::recv_one(p.take()); do arc2.access_cond |state, cond| { *state = true; cond.signal(); } } do arc.access_cond |state, cond| { - comm::send_one(option::swap_unwrap(c), ()); + comm::send_one(c.take(), ()); assert !*state; while !*state { cond.wait(); diff --git a/src/libstd/future.rs b/src/libstd/future.rs index b6b001727a4..7f48466ed0a 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -23,6 +23,7 @@ use core::cast::copy_lifetime; use core::cast; +use core::cell::Cell; use core::either::Either; use core::option; use core::comm::{oneshot, ChanOne, PortOne, send_one, recv_one}; @@ -103,11 +104,9 @@ pub fn from_port(port: PortOne) -> * waiting for the result to be received on the port. */ - let port = ~mut Some(port); + let port = Cell(port); do from_fn || { - let mut port_ = None; - port_ <-> *port; - let port = option::unwrap(port_); + let port = port.take(); match recv(port) { oneshot::send(data) => data } @@ -136,9 +135,9 @@ pub fn spawn(blk: fn~() -> A) -> Future { let (chan, port) = oneshot::init(); - let chan = ~mut Some(chan); + let chan = Cell(chan); do task::spawn || { - let chan = option::swap_unwrap(&mut *chan); + let chan = chan.take(); send_one(chan, blk()); } diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 016847a5bfd..1ff51e8bff0 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -15,6 +15,7 @@ * in std. */ +use core::cell::Cell; use core::option; use core::pipes; use core::prelude::*; @@ -799,9 +800,9 @@ mod tests { let s = ~semaphore(1); let s2 = ~s.clone(); let (p,c) = comm::stream(); - let child_data = ~mut Some((s2, c)); + let child_data = Cell((s2, c)); do s.access { - let (s2,c) = option::swap_unwrap(child_data); + let (s2, c) = child_data.take(); do task::spawn || { c.send(()); do s2.access { } @@ -976,13 +977,13 @@ mod tests { let mut sibling_convos = ~[]; for 2.times { let (p,c) = comm::stream(); - let c = ~mut Some(c); + let c = Cell(c); sibling_convos.push(p); let mi = ~m2.clone(); // spawn sibling task - do task::spawn || { // linked + do task::spawn { // linked do mi.lock_cond |cond| { - let c = option::swap_unwrap(c); + let c = c.take(); c.send(()); // tell sibling to go ahead let _z = SendOnFailure(c); cond.wait(); // block forever diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index 8ce68a41f81..d7ca766f183 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -15,6 +15,7 @@ use sha1; use serialize::{Encoder, Encodable, Decoder, Decodable}; use sort; +use core::cell::Cell; use core::cmp; use core::either::{Either, Left, Right}; use core::io; @@ -339,11 +340,11 @@ impl TPrep for @Mut { let mut blk = None; blk <-> bo; let blk = blk.unwrap(); - let chan = ~mut Some(chan); + let chan = Cell(chan); do task::spawn || { let exe = Exec{discovered_inputs: LinearMap::new(), discovered_outputs: LinearMap::new()}; - let chan = option::swap_unwrap(&mut *chan); + let chan = chan.take(); let v = blk(&exe); send_one(chan, (exe, v)); } diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 7b3030124b7..0c5c0f3d513 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -128,7 +128,7 @@ pub impl Parser { "write `+` between trait bounds" ), ObsoleteMutOwnedPointer => ( - "mutable owned pointer", + "const or mutable owned pointer", "mutability inherits through `~` pointers; place the `~` box in a mutable location, like a mutable local variable or an \ `@mut` box" diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index af25a4f6e58..c9102cbb86b 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -678,7 +678,7 @@ pub impl Parser { // reflected in the AST type. let mt = self.parse_mt(); - if mt.mutbl == m_mutbl && sigil == OwnedSigil { + if mt.mutbl != m_imm && sigil == OwnedSigil { self.obsolete(*self.last_span, ObsoleteMutOwnedPointer); } @@ -1574,6 +1574,10 @@ pub impl Parser { token::TILDE => { self.bump(); let m = self.parse_mutability(); + if m != m_imm { + self.obsolete(*self.last_span, ObsoleteMutOwnedPointer); + } + let e = self.parse_prefix_expr(); hi = e.span.hi; // HACK: turn ~[...] into a ~-evec diff --git a/src/test/compile-fail/mutable-huh-unique-assign.rs b/src/test/compile-fail/mutable-huh-unique-assign.rs deleted file mode 100644 index 8b59879acd9..00000000000 --- a/src/test/compile-fail/mutable-huh-unique-assign.rs +++ /dev/null @@ -1,19 +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. - -fn main() { - fn f(&&v: ~const int) { - *v = 1 //~ ERROR assigning to dereference of const ~ pointer - } - - let v = ~0; - - f(v); -} -- cgit 1.4.1-3-g733a5 From 573a31dfa769887f4be77a621ef4cab2d92a74e5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 26 Feb 2013 14:50:09 -0800 Subject: libsyntax: Forbid mutable vectors. rs=demuting --- src/libcore/dvec.rs | 14 +---------- src/libcore/os.rs | 2 +- src/libcore/vec.rs | 45 +++++++----------------------------- src/libstd/sort.rs | 6 ++--- src/libstd/stats.rs | 2 +- src/libstd/test.rs | 2 +- src/libsyntax/parse/obsolete.rs | 7 ++++++ src/libsyntax/parse/parser.rs | 8 +++++++ src/test/run-pass/import-in-block.rs | 6 ++--- 9 files changed, 31 insertions(+), 61 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 7651b737bf3..9f2036c5f41 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -133,18 +133,6 @@ impl DVec { self.check_out(|v| self.give_back(f(v))) } - /** - * Swaps out the current vector and hands it off to a user-provided - * function `f`. The function should transform it however is desired - * and return a new vector to replace it with. - */ - #[inline(always)] - fn swap_mut(f: &fn(v: ~[mut A]) -> ~[mut A]) { - do self.swap |v| { - vec::cast_from_mut(f(vec::cast_to_mut(v))) - } - } - /// Returns the number of elements currently in the dvec #[inline(always)] pure fn len() -> uint { @@ -217,7 +205,7 @@ impl DVec { } /// Gives access to the vector as a slice with mutable contents - fn borrow_mut(op: fn(x: &[mut A]) -> R) -> R { + fn borrow_mut(op: &fn(x: &mut [A]) -> R) -> R { do self.check_out |v| { let mut v = v; let result = op(v); diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 9cd5e8f4965..2522e9c2cda 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -109,7 +109,7 @@ pub mod win32 { let mut done = false; while !done { let mut k: DWORD = 0; - let buf = vec::cast_to_mut(vec::from_elem(n as uint, 0u16)); + let mut buf = vec::from_elem(n as uint, 0u16); do vec::as_mut_buf(buf) |b, _sz| { k = f(b, TMPBUF_SZ as DWORD); if k == (0 as DWORD) { diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 31c837e7e8a..687ad2f7938 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -209,16 +209,6 @@ pub pure fn build_sized_opt(size: Option, build_sized(size.get_or_default(4), builder) } -/// Produces a mut vector from an immutable vector. -pub pure fn cast_to_mut(v: ~[T]) -> ~[mut T] { - unsafe { ::cast::transmute(v) } -} - -/// Produces an immutable vector from a mut vector. -pub pure fn cast_from_mut(v: ~[mut T]) -> ~[T] { - unsafe { ::cast::transmute(v) } -} - // Accessors /// Returns the first element of a vector @@ -274,9 +264,10 @@ pub pure fn slice(v: &r/[T], start: uint, end: uint) -> &r/[T] { /// Return a slice that points into another slice. #[inline(always)] -pub pure fn mut_slice(v: &r/[mut T], start: uint, - end: uint) -> &r/[mut T] { - +pub pure fn mut_slice(v: &r/mut [T], + start: uint, + end: uint) + -> &r/mut [T] { assert (start <= end); assert (end <= len(v)); do as_mut_buf(v) |p, _len| { @@ -290,8 +281,10 @@ pub pure fn mut_slice(v: &r/[mut T], start: uint, /// Return a slice that points into another slice. #[inline(always)] -pub pure fn const_slice(v: &r/[const T], start: uint, - end: uint) -> &r/[const T] { +pub pure fn const_slice(v: &r/[const T], + start: uint, + end: uint) + -> &r/[const T] { assert (start <= end); assert (end <= len(v)); do as_const_buf(v) |p, _len| { @@ -3337,28 +3330,6 @@ mod tests { let _x = windowed (0u, ~[1u,2u,3u,4u,5u,6u]); } - #[test] - fn cast_to_mut_no_copy() { - unsafe { - let x = ~[1, 2, 3]; - let addr = raw::to_ptr(x); - let x_mut = cast_to_mut(x); - let addr_mut = raw::to_ptr(x_mut); - assert addr == addr_mut; - } - } - - #[test] - fn cast_from_mut_no_copy() { - unsafe { - let x = ~[mut 1, 2, 3]; - let addr = raw::to_ptr(x); - let x_imm = cast_from_mut(x); - let addr_imm = raw::to_ptr(x_imm); - assert addr == addr_imm; - } - } - #[test] fn test_unshift() { let mut x = ~[1, 2, 3]; diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index d2515df3e1b..75f38da5a19 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -455,8 +455,7 @@ impl MergeState { base2: uint, len2: uint) { assert len1 != 0 && len2 != 0 && base1+len1 == base2; - let tmp = vec::cast_to_mut( - vec::slice(array, base1, base1+len1).to_vec()); + let mut tmp = vec::slice(array, base1, base1+len1).to_vec(); let mut c1 = 0; let mut c2 = base2; @@ -559,8 +558,7 @@ impl MergeState { base2: uint, len2: uint) { assert len1 != 1 && len2 != 0 && base1 + len1 == base2; - let tmp = vec::cast_to_mut( - vec::slice(array, base2, base2+len2).to_vec()); + let mut tmp = vec::slice(array, base2, base2+len2).to_vec(); let mut c1 = base1 + len1 - 1; let mut c2 = len2 - 1; diff --git a/src/libstd/stats.rs b/src/libstd/stats.rs index fb6f80a6500..7dafdec95e0 100644 --- a/src/libstd/stats.rs +++ b/src/libstd/stats.rs @@ -52,7 +52,7 @@ impl Stats for &[f64] { fn median(self) -> f64 { assert self.len() != 0; - let tmp = vec::cast_to_mut(vec::from_slice(self)); + let mut tmp = vec::from_slice(self); sort::tim_sort(tmp); if tmp.len() & 1 == 0 { let m = tmp.len() / 2; diff --git a/src/libstd/test.rs b/src/libstd/test.rs index e14e9665216..bfeaf8400bc 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -377,7 +377,7 @@ pub fn run_tests_console(opts: &TestOpts, fn print_failures(st: @ConsoleTestState) { st.out.write_line(~"\nfailures:"); - let failures = vec::cast_to_mut(st.failures.map(|t| t.name.to_str())); + let mut failures = st.failures.map(|t| t.name.to_str()); sort::tim_sort(failures); for vec::each(failures) |name| { st.out.write_line(fmt!(" %s", name.to_str())); diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 0c5c0f3d513..33d959a7753 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -49,6 +49,7 @@ pub enum ObsoleteSyntax { ObsoleteImplSyntax, ObsoleteTraitBoundSeparator, ObsoleteMutOwnedPointer, + ObsoleteMutVector, } pub impl to_bytes::IterBytes for ObsoleteSyntax { @@ -133,6 +134,12 @@ pub impl Parser { in a mutable location, like a mutable local variable or an \ `@mut` box" ), + ObsoleteMutVector => ( + "const or mutable vector", + "mutability inherits through `~` pointers; place the vector \ + in a mutable location, like a mutable local variable or an \ + `@mut` box" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c9102cbb86b..b4bd28cbfe2 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -76,6 +76,7 @@ use parse::obsolete::{ObsoleteStructCtor, ObsoleteWith}; use parse::obsolete::{ObsoleteSyntax, ObsoleteLowerCaseKindBounds}; use parse::obsolete::{ObsoleteUnsafeBlock, ObsoleteImplSyntax}; use parse::obsolete::{ObsoleteTraitBoundSeparator, ObsoleteMutOwnedPointer}; +use parse::obsolete::{ObsoleteMutVector}; 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}; @@ -624,6 +625,9 @@ pub impl Parser { } else if *self.token == token::LBRACKET { self.expect(token::LBRACKET); let mt = self.parse_mt(); + if mt.mutbl == m_mutbl { // `m_const` too after snapshot + self.obsolete(*self.last_span, ObsoleteMutVector); + } // Parse the `* 3` in `[ int * 3 ]` let t = match self.maybe_parse_fixed_vstore_with_star() { @@ -1134,6 +1138,10 @@ pub impl Parser { } else if *self.token == token::LBRACKET { self.bump(); let mutbl = self.parse_mutability(); + if mutbl == m_mutbl { // `m_const` too after snapshot + self.obsolete(*self.last_span, ObsoleteMutVector); + } + if *self.token == token::RBRACKET { // Empty vector. self.bump(); diff --git a/src/test/run-pass/import-in-block.rs b/src/test/run-pass/import-in-block.rs index 6ad33445997..72f6d23cacc 100644 --- a/src/test/run-pass/import-in-block.rs +++ b/src/test/run-pass/import-in-block.rs @@ -9,10 +9,8 @@ // except according to those terms. pub fn main() { - // Once cast_to_mut is removed, pick a better function to import - // for this test! - use vec::cast_to_mut; - log(debug, vec::len(cast_to_mut(~[1, 2]))); + use vec::from_fn; + log(debug, vec::len(from_fn(2, |i| i))); { use vec::*; log(debug, len(~[2])); -- cgit 1.4.1-3-g733a5 From 07c3f5c0de752166ae34f0fe50e50e65a2403b66 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 26 Feb 2013 17:12:00 -0800 Subject: librustc: Forbid `pub` or `priv` before trait implementations --- src/libcore/at_vec.rs | 2 +- src/libcore/num/f32.rs | 2 +- src/libcore/num/f64.rs | 2 +- src/libcore/num/float.rs | 2 +- src/libcore/num/int-template/i16.rs | 2 +- src/libcore/num/int-template/i32.rs | 2 +- src/libcore/num/int-template/i64.rs | 2 +- src/libcore/num/int-template/i8.rs | 2 +- src/libcore/num/int-template/int.rs | 2 +- src/libcore/num/uint-template/u16.rs | 2 +- src/libcore/num/uint-template/u32.rs | 2 +- src/libcore/num/uint-template/u64.rs | 2 +- src/libcore/num/uint-template/u8.rs | 2 +- src/libcore/num/uint-template/uint.rs | 4 +- src/libcore/option.rs | 2 +- src/libcore/str.rs | 2 +- src/libcore/to_bytes.rs | 4 +- src/librustc/middle/borrowck/mod.rs | 2 +- src/librustc/middle/mem_categorization.rs | 6 +- src/librustc/middle/trans/base.rs | 6 +- src/librustc/middle/trans/common.rs | 10 +- src/librustc/middle/trans/datum.rs | 4 +- src/librustc/middle/ty.rs | 30 +++--- src/librustc/middle/typeck/check/mod.rs | 4 +- src/librustc/middle/typeck/collect.rs | 2 +- src/librustc/middle/typeck/infer/glb.rs | 2 +- src/librustc/middle/typeck/infer/lattice.rs | 10 +- src/librustc/middle/typeck/infer/lub.rs | 2 +- src/librustc/middle/typeck/infer/sub.rs | 2 +- src/librustc/middle/typeck/infer/to_str.rs | 18 ++-- src/librustc/middle/typeck/infer/unify.rs | 10 +- src/librustc/middle/typeck/rscope.rs | 12 ++- src/librustdoc/config.rs | 2 +- src/libstd/flatpipes.rs | 18 ++-- src/libstd/json.rs | 8 +- src/libstd/prettyprint.rs | 2 +- src/libstd/serialize.rs | 116 ++++++++++----------- src/libstd/workcache.rs | 4 +- src/libsyntax/ast.rs | 48 ++++----- src/libsyntax/ast_map.rs | 2 +- src/libsyntax/ast_util.rs | 4 +- src/libsyntax/codemap.rs | 30 +++--- src/libsyntax/ext/auto_encode.rs | 2 +- src/libsyntax/ext/pipes/ast_builder.rs | 4 +- src/libsyntax/ext/pipes/check.rs | 2 +- src/libsyntax/ext/pipes/parse_proto.rs | 2 +- src/libsyntax/ext/pipes/pipec.rs | 6 +- src/libsyntax/ext/pipes/proto.rs | 2 +- src/libsyntax/fold.rs | 2 +- src/libsyntax/parse/lexer.rs | 2 +- src/libsyntax/parse/obsolete.rs | 9 +- src/libsyntax/parse/parser.rs | 17 ++- src/test/auxiliary/cci_class_cast.rs | 2 +- .../auxiliary/crate-method-reexport-grrrrrrr2.rs | 4 +- src/test/auxiliary/issue-3012-1.rs | 2 +- src/test/auxiliary/issue2170lib.rs | 2 +- .../auxiliary/trait_inheritance_overloading_xc.rs | 10 +- src/test/compile-fail/issue-3953.rs | 2 +- src/test/compile-fail/issue-3969.rs | 2 +- src/test/run-pass/issue-2718.rs | 4 +- src/test/run-pass/pipe-presentation-examples.rs | 2 +- src/test/run-pass/static-impl.rs | 4 +- src/test/run-pass/static-methods-in-traits2.rs | 4 +- src/test/run-pass/trait-inheritance-num2.rs | 104 +++++++++--------- src/test/run-pass/trait-inheritance-num3.rs | 2 +- src/test/run-pass/trait-inheritance-num5.rs | 4 +- .../run-pass/trait-static-method-overwriting.rs | 4 +- 67 files changed, 304 insertions(+), 288 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 57bd8a97b5d..ab604d1f0b6 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -168,7 +168,7 @@ pub mod traits { use kinds::Copy; use ops::Add; - pub impl Add<&[const T],@[T]> for @[T] { + impl Add<&[const T],@[T]> for @[T] { #[inline(always)] pure fn add(&self, rhs: & &self/[const T]) -> @[T] { append(*self, (*rhs)) diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index d5407daca80..c4f2704ab9f 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -284,7 +284,7 @@ impl num::One for f32 { static pure fn one() -> f32 { 1.0 } } -pub impl NumCast for f32 { +impl NumCast for f32 { /** * Cast `n` to an `f32` */ diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 4e4e7c68646..8f3771312e4 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -299,7 +299,7 @@ impl cmp::Ord for f64 { pure fn gt(&self, other: &f64) -> bool { (*self) > (*other) } } -pub impl NumCast for f64 { +impl NumCast for f64 { /** * Cast `n` to an `f64` */ diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs index b857f76570f..1b79ec614d4 100644 --- a/src/libcore/num/float.rs +++ b/src/libcore/num/float.rs @@ -420,7 +420,7 @@ impl num::One for float { static pure fn one() -> float { 1.0 } } -pub impl NumCast for float { +impl NumCast for float { /** * Cast `n` to a `float` */ diff --git a/src/libcore/num/int-template/i16.rs b/src/libcore/num/int-template/i16.rs index 1352959306a..a3def10bda8 100644 --- a/src/libcore/num/int-template/i16.rs +++ b/src/libcore/num/int-template/i16.rs @@ -17,7 +17,7 @@ mod inst { pub const bits: uint = ::u16::bits; } -pub impl NumCast for i16 { +impl NumCast for i16 { /** * Cast `n` to a `i16` */ diff --git a/src/libcore/num/int-template/i32.rs b/src/libcore/num/int-template/i32.rs index e8dd603d507..eccd1f6ce3c 100644 --- a/src/libcore/num/int-template/i32.rs +++ b/src/libcore/num/int-template/i32.rs @@ -17,7 +17,7 @@ mod inst { pub const bits: uint = ::u32::bits; } -pub impl NumCast for i32 { +impl NumCast for i32 { /** * Cast `n` to a `i32` */ diff --git a/src/libcore/num/int-template/i64.rs b/src/libcore/num/int-template/i64.rs index 6f1371f8ee2..05d529cbcf4 100644 --- a/src/libcore/num/int-template/i64.rs +++ b/src/libcore/num/int-template/i64.rs @@ -17,7 +17,7 @@ mod inst { pub const bits: uint = ::u64::bits; } -pub impl NumCast for i64 { +impl NumCast for i64 { /** * Cast `n` to a `i64` */ diff --git a/src/libcore/num/int-template/i8.rs b/src/libcore/num/int-template/i8.rs index 46c734b9548..d8819d4fed0 100644 --- a/src/libcore/num/int-template/i8.rs +++ b/src/libcore/num/int-template/i8.rs @@ -17,7 +17,7 @@ mod inst { pub const bits: uint = ::u8::bits; } -pub impl NumCast for i8 { +impl NumCast for i8 { /** * Cast `n` to a `i8` */ diff --git a/src/libcore/num/int-template/int.rs b/src/libcore/num/int-template/int.rs index 83ef421b705..7e376a47b89 100644 --- a/src/libcore/num/int-template/int.rs +++ b/src/libcore/num/int-template/int.rs @@ -58,7 +58,7 @@ mod inst { } } -pub impl NumCast for int { +impl NumCast for int { /** * Cast `n` to a `int` */ diff --git a/src/libcore/num/uint-template/u16.rs b/src/libcore/num/uint-template/u16.rs index 315ff84cc23..01ec0cc77bf 100644 --- a/src/libcore/num/uint-template/u16.rs +++ b/src/libcore/num/uint-template/u16.rs @@ -19,7 +19,7 @@ mod inst { pub const bits: uint = 16; } -pub impl NumCast for u16 { +impl NumCast for u16 { /** * Cast `n` to a `u16` */ diff --git a/src/libcore/num/uint-template/u32.rs b/src/libcore/num/uint-template/u32.rs index 834feff292c..772ef51d30d 100644 --- a/src/libcore/num/uint-template/u32.rs +++ b/src/libcore/num/uint-template/u32.rs @@ -19,7 +19,7 @@ mod inst { pub const bits: uint = 32; } -pub impl NumCast for u32 { +impl NumCast for u32 { /** * Cast `n` to a `u32` */ diff --git a/src/libcore/num/uint-template/u64.rs b/src/libcore/num/uint-template/u64.rs index b661b3b20b1..ec7301a01e4 100644 --- a/src/libcore/num/uint-template/u64.rs +++ b/src/libcore/num/uint-template/u64.rs @@ -19,7 +19,7 @@ mod inst { pub const bits: uint = 64; } -pub impl NumCast for u64 { +impl NumCast for u64 { /** * Cast `n` to a `u64` */ diff --git a/src/libcore/num/uint-template/u8.rs b/src/libcore/num/uint-template/u8.rs index c2be9e252d9..53e4be70727 100644 --- a/src/libcore/num/uint-template/u8.rs +++ b/src/libcore/num/uint-template/u8.rs @@ -26,7 +26,7 @@ mod inst { pub pure fn is_ascii(x: T) -> bool { return 0 as T == x & 128 as T; } } -pub impl NumCast for u8 { +impl NumCast for u8 { /** * Cast `n` to a `u8` */ diff --git a/src/libcore/num/uint-template/uint.rs b/src/libcore/num/uint-template/uint.rs index 475ae243915..e2a75b25eae 100644 --- a/src/libcore/num/uint-template/uint.rs +++ b/src/libcore/num/uint-template/uint.rs @@ -110,7 +110,7 @@ pub mod inst { return true; } - pub impl iter::Times for uint { + impl iter::Times for uint { #[inline(always)] /** * A convenience form for basic iteration. Given a uint `x`, @@ -209,7 +209,7 @@ pub mod inst { } } -pub impl NumCast for uint { +impl NumCast for uint { /** * Cast `n` to a `uint` */ diff --git a/src/libcore/option.rs b/src/libcore/option.rs index e27b7086bc4..1c2df949a2e 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -56,7 +56,7 @@ pub enum Option { Some(T), } -pub impl Ord for Option { +impl Ord for Option { pure fn lt(&self, other: &Option) -> bool { match (self, other) { (&None, &None) => false, diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 92e980e34d0..66be5481819 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -2362,7 +2362,7 @@ pub trait OwnedStr { fn push_char(&mut self, c: char); } -pub impl OwnedStr for ~str { +impl OwnedStr for ~str { fn push_str(&mut self, v: &str) { push_str(self, v); } diff --git a/src/libcore/to_bytes.rs b/src/libcore/to_bytes.rs index 4b2cd3c2fab..1f0f3b0779c 100644 --- a/src/libcore/to_bytes.rs +++ b/src/libcore/to_bytes.rs @@ -170,7 +170,7 @@ impl IterBytes for char { pub mod x32 { use to_bytes::{Cb, IterBytes}; - pub impl IterBytes for uint { + impl IterBytes for uint { #[inline(always)] pure fn iter_bytes(&self, lsb0: bool, f: Cb) { (*self as u32).iter_bytes(lsb0, f) @@ -182,7 +182,7 @@ pub mod x32 { pub mod x64 { use to_bytes::{Cb, IterBytes}; - pub impl IterBytes for uint { + impl IterBytes for uint { #[inline(always)] pure fn iter_bytes(&self, lsb0: bool, f: Cb) { (*self as u64).iter_bytes(lsb0, f) diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 568bc5b5e70..eb2a93d86f9 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -451,7 +451,7 @@ impl LoanKind { /// Creates and returns a new root_map -pub impl to_bytes::IterBytes for root_map_key { +impl to_bytes::IterBytes for root_map_key { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.id, &self.derefs, lsb0, f); } diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index f027ca99d51..3f8ee61e841 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -281,12 +281,12 @@ pub trait ast_node { fn span(&self) -> span; } -pub impl ast_node for @ast::expr { +impl ast_node for @ast::expr { fn id(&self) -> ast::node_id { self.id } fn span(&self) -> span { self.span } } -pub impl ast_node for @ast::pat { +impl ast_node for @ast::pat { fn id(&self) -> ast::node_id { self.id } fn span(&self) -> span { self.span } } @@ -295,7 +295,7 @@ pub trait get_type_for_node { fn ty(&self, node: N) -> ty::t; } -pub impl get_type_for_node for ty::ctxt { +impl get_type_for_node for ty::ctxt { fn ty(&self, node: N) -> ty::t { ty::node_id_to_type(*self, node.id()) } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 53555dc9ff8..740a7e043d4 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -107,7 +107,7 @@ pub trait get_insn_ctxt { fn insn_ctxt(&self, s: &str) -> icx_popper; } -pub impl get_insn_ctxt for @CrateContext { +impl get_insn_ctxt for @CrateContext { fn insn_ctxt(&self, s: &str) -> icx_popper { debug!("new insn_ctxt: %s", s); if self.sess.count_llvm_insns() { @@ -117,13 +117,13 @@ pub impl get_insn_ctxt for @CrateContext { } } -pub impl get_insn_ctxt for block { +impl get_insn_ctxt for block { fn insn_ctxt(&self, s: &str) -> icx_popper { self.ccx().insn_ctxt(s) } } -pub impl get_insn_ctxt for fn_ctxt { +impl get_insn_ctxt for fn_ctxt { fn insn_ctxt(&self, s: &str) -> icx_popper { self.ccx.insn_ctxt(s) } diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 48a3d2c82c8..f8a7f477976 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -538,13 +538,13 @@ pub trait get_node_info { fn info(&self) -> Option; } -pub impl get_node_info for @ast::expr { +impl get_node_info for @ast::expr { fn info(&self) -> Option { Some(NodeInfo { id: self.id, span: self.span }) } } -pub impl get_node_info for ast::blk { +impl get_node_info for ast::blk { fn info(&self) -> Option { Some(NodeInfo { id: self.node.id, span: self.span }) } @@ -553,7 +553,7 @@ pub impl get_node_info for ast::blk { // XXX: Work around a trait parsing bug. remove after snapshot pub type optional_boxed_ast_expr = Option<@ast::expr>; -pub impl get_node_info for optional_boxed_ast_expr { +impl get_node_info for optional_boxed_ast_expr { fn info(&self) -> Option { self.chain_ref(|s| s.info()) } @@ -1275,7 +1275,7 @@ pub struct mono_id_ { pub type mono_id = @mono_id_; -pub impl to_bytes::IterBytes for mono_param_id { +impl to_bytes::IterBytes for mono_param_id { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { match /*bad*/copy *self { mono_precise(t, mids) => @@ -1289,7 +1289,7 @@ pub impl to_bytes::IterBytes for mono_param_id { } } -pub impl to_bytes::IterBytes for mono_id_ { +impl to_bytes::IterBytes for mono_id_ { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.def, &self.params, lsb0, f); } diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index ba56eb56c0a..07499dac62e 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -151,14 +151,14 @@ pub impl DatumMode { } } -pub impl cmp::Eq for DatumMode { +impl cmp::Eq for DatumMode { pure fn eq(&self, other: &DatumMode) -> bool { (*self) as uint == (*other as uint) } pure fn ne(&self, other: &DatumMode) -> bool { !(*self).eq(other) } } -pub impl to_bytes::IterBytes for DatumMode { +impl to_bytes::IterBytes for DatumMode { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as uint).iter_bytes(lsb0, f) } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 182ab11b917..efbbfc46cb9 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -660,46 +660,46 @@ pub trait Vid { pure fn to_uint(&self) -> uint; } -pub impl Vid for TyVid { +impl Vid for TyVid { pure fn to_uint(&self) -> uint { **self } } -pub impl ToStr for TyVid { +impl ToStr for TyVid { pure fn to_str(&self) -> ~str { fmt!("", self.to_uint()) } } -pub impl Vid for IntVid { +impl Vid for IntVid { pure fn to_uint(&self) -> uint { **self } } -pub impl ToStr for IntVid { +impl ToStr for IntVid { pure fn to_str(&self) -> ~str { fmt!("", self.to_uint()) } } -pub impl Vid for FloatVid { +impl Vid for FloatVid { pure fn to_uint(&self) -> uint { **self } } -pub impl ToStr for FloatVid { +impl ToStr for FloatVid { pure fn to_str(&self) -> ~str { fmt!("", self.to_uint()) } } -pub impl Vid for RegionVid { +impl Vid for RegionVid { pure fn to_uint(&self) -> uint { **self } } -pub impl ToStr for RegionVid { +impl ToStr for RegionVid { pure fn to_str(&self) -> ~str { fmt!("%?", self) } } -pub impl ToStr for FnSig { +impl ToStr for FnSig { pure fn to_str(&self) -> ~str { // grr, without tcx not much we can do. return ~"(...)"; } } -pub impl ToStr for InferTy { +impl ToStr for InferTy { pure fn to_str(&self) -> ~str { match *self { TyVar(ref v) => v.to_str(), @@ -709,7 +709,7 @@ pub impl ToStr for InferTy { } } -pub impl ToStr for IntVarValue { +impl ToStr for IntVarValue { pure fn to_str(&self) -> ~str { match *self { IntType(ref v) => v.to_str(), @@ -718,25 +718,25 @@ pub impl ToStr for IntVarValue { } } -pub impl to_bytes::IterBytes for TyVid { +impl to_bytes::IterBytes for TyVid { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { self.to_uint().iter_bytes(lsb0, f) } } -pub impl to_bytes::IterBytes for IntVid { +impl to_bytes::IterBytes for IntVid { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { self.to_uint().iter_bytes(lsb0, f) } } -pub impl to_bytes::IterBytes for FloatVid { +impl to_bytes::IterBytes for FloatVid { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { self.to_uint().iter_bytes(lsb0, f) } } -pub impl to_bytes::IterBytes for RegionVid { +impl to_bytes::IterBytes for RegionVid { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { self.to_uint().iter_bytes(lsb0, f) } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index e63e46ace3d..998c007c86d 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -625,7 +625,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) { } } -pub impl AstConv for FnCtxt { +impl AstConv for FnCtxt { fn tcx(@mut self) -> ty::ctxt { self.ccx.tcx } fn ccx(@mut self) -> @mut CrateCtxt { self.ccx } @@ -659,7 +659,7 @@ pub impl FnCtxt { } } -pub impl region_scope for @mut FnCtxt { +impl region_scope for @mut FnCtxt { pure fn anon_region(&self, span: span) -> Result { // XXX: Unsafe to work around purity unsafe { diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 96c76b52181..1bbee20e2e2 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -121,7 +121,7 @@ pub impl @mut CrateCtxt { } } -pub impl AstConv for CrateCtxt { +impl AstConv for CrateCtxt { fn tcx(@mut self) -> ty::ctxt { self.tcx } fn ccx(@mut self) -> @mut CrateCtxt { self } diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index 5008791723e..936ca1e8297 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -27,7 +27,7 @@ use std::list; pub enum Glb = CombineFields; // "greatest lower bound" (common subtype) -pub impl Combine for Glb { +impl Combine for Glb { fn infcx(&self) -> @mut InferCtxt { self.infcx } fn tag(&self) -> ~str { ~"glb" } fn a_is_expected(&self) -> bool { self.a_is_expected } diff --git a/src/librustc/middle/typeck/infer/lattice.rs b/src/librustc/middle/typeck/infer/lattice.rs index 1a919ac0f3b..8fa887fca0b 100644 --- a/src/librustc/middle/typeck/infer/lattice.rs +++ b/src/librustc/middle/typeck/infer/lattice.rs @@ -59,7 +59,7 @@ pub trait LatticeValue { pub type LatticeOp = &fn(cf: &CombineFields, a: &T, b: &T) -> cres; -pub impl LatticeValue for ty::t { +impl LatticeValue for ty::t { static fn sub(&self, cf: &CombineFields, a: &ty::t, b: &ty::t) -> ures { Sub(*cf).tys(*a, *b).to_ures() } @@ -305,7 +305,7 @@ pub trait TyLatticeDir { fn ty_bot(&self, t: ty::t) -> cres; } -pub impl LatticeDir for Lub { +impl LatticeDir for Lub { fn combine_fields(&self) -> CombineFields { **self } fn bnd(&self, b: &Bounds) -> Option { b.ub } fn with_bnd(&self, b: &Bounds, +t: T) -> Bounds { @@ -313,13 +313,13 @@ pub impl LatticeDir for Lub { } } -pub impl TyLatticeDir for Lub { +impl TyLatticeDir for Lub { fn ty_bot(&self, t: ty::t) -> cres { Ok(t) } } -pub impl LatticeDir for Glb { +impl LatticeDir for Glb { fn combine_fields(&self) -> CombineFields { **self } fn bnd(&self, b: &Bounds) -> Option { b.lb } fn with_bnd(&self, b: &Bounds, +t: T) -> Bounds { @@ -327,7 +327,7 @@ pub impl LatticeDir for Glb { } } -pub impl TyLatticeDir for Glb { +impl TyLatticeDir for Glb { fn ty_bot(&self, _t: ty::t) -> cres { Ok(ty::mk_bot(self.infcx.tcx)) } diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/typeck/infer/lub.rs index 4fee6f061b1..2c4fd9f01ee 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/typeck/infer/lub.rs @@ -32,7 +32,7 @@ pub impl Lub { -> cres { self.bot_ty(b) } // commutative } -pub impl Combine for Lub { +impl Combine for Lub { fn infcx(&self) -> @mut InferCtxt { self.infcx } fn tag(&self) -> ~str { ~"lub" } fn a_is_expected(&self) -> bool { self.a_is_expected } diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index 12a9a6c4076..5552b71d0d7 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -28,7 +28,7 @@ use syntax::ast::{m_const, purity, ret_style}; pub enum Sub = CombineFields; // "subtype", "subregion" etc -pub impl Combine for Sub { +impl Combine for Sub { fn infcx(&self) -> @mut InferCtxt { self.infcx } fn tag(&self) -> ~str { ~"sub" } fn a_is_expected(&self) -> bool { self.a_is_expected } diff --git a/src/librustc/middle/typeck/infer/to_str.rs b/src/librustc/middle/typeck/infer/to_str.rs index 0013b417f7a..9b74ac85351 100644 --- a/src/librustc/middle/typeck/infer/to_str.rs +++ b/src/librustc/middle/typeck/infer/to_str.rs @@ -28,13 +28,13 @@ pub trait InferStr { fn inf_str(&self, cx: &InferCtxt) -> ~str; } -pub impl InferStr for ty::t { +impl InferStr for ty::t { fn inf_str(&self, cx: &InferCtxt) -> ~str { ty_to_str(cx.tcx, *self) } } -pub impl InferStr for FnSig { +impl InferStr for FnSig { fn inf_str(&self, cx: &InferCtxt) -> ~str { fmt!("(%s) -> %s", str::connect(self.inputs.map(|a| a.ty.inf_str(cx)), ", "), @@ -42,19 +42,19 @@ pub impl InferStr for FnSig { } } -pub impl InferStr for ty::mt { +impl InferStr for ty::mt { fn inf_str(&self, cx: &InferCtxt) -> ~str { mt_to_str(cx.tcx, *self) } } -pub impl InferStr for ty::Region { +impl InferStr for ty::Region { fn inf_str(&self, _cx: &InferCtxt) -> ~str { fmt!("%?", *self) } } -pub impl InferStr for Bound { +impl InferStr for Bound { fn inf_str(&self, cx: &InferCtxt) -> ~str { match *self { Some(ref v) => v.inf_str(cx), @@ -63,7 +63,7 @@ pub impl InferStr for Bound { } } -pub impl InferStr for Bounds { +impl InferStr for Bounds { fn inf_str(&self, cx: &InferCtxt) -> ~str { fmt!("{%s <: %s}", self.lb.inf_str(cx), @@ -71,7 +71,7 @@ pub impl InferStr for Bounds { } } -pub impl InferStr for VarValue { +impl InferStr for VarValue { fn inf_str(&self, cx: &InferCtxt) -> ~str { match *self { Redirect(ref vid) => fmt!("Redirect(%s)", vid.to_str()), @@ -81,13 +81,13 @@ pub impl InferStr for VarValue { } } -pub impl InferStr for IntVarValue { +impl InferStr for IntVarValue { fn inf_str(&self, _cx: &InferCtxt) -> ~str { self.to_str() } } -pub impl InferStr for ast::float_ty { +impl InferStr for ast::float_ty { fn inf_str(&self, _cx: &InferCtxt) -> ~str { self.to_str() } diff --git a/src/librustc/middle/typeck/infer/unify.rs b/src/librustc/middle/typeck/infer/unify.rs index 93c6131d340..fec3f3d9779 100644 --- a/src/librustc/middle/typeck/infer/unify.rs +++ b/src/librustc/middle/typeck/infer/unify.rs @@ -237,35 +237,35 @@ pub impl InferCtxt { // ______________________________________________________________________ -pub impl UnifyVid> for ty::TyVid { +impl UnifyVid> for ty::TyVid { static fn appropriate_vals_and_bindings(&self, infcx: &v/mut InferCtxt) -> &v/mut ValsAndBindings> { return &mut infcx.ty_var_bindings; } } -pub impl UnifyVid> for ty::IntVid { +impl UnifyVid> for ty::IntVid { static fn appropriate_vals_and_bindings(&self, infcx: &v/mut InferCtxt) -> &v/mut ValsAndBindings> { return &mut infcx.int_var_bindings; } } -pub impl SimplyUnifiable for IntVarValue { +impl SimplyUnifiable for IntVarValue { static fn to_type_err(&self, err: expected_found) -> ty::type_err { return ty::terr_int_mismatch(err); } } -pub impl UnifyVid> for ty::FloatVid { +impl UnifyVid> for ty::FloatVid { static fn appropriate_vals_and_bindings(&self, infcx: &v/mut InferCtxt) -> &v/mut ValsAndBindings> { return &mut infcx.float_var_bindings; } } -pub impl SimplyUnifiable for ast::float_ty { +impl SimplyUnifiable for ast::float_ty { static fn to_type_err(&self, err: expected_found) -> ty::type_err { return ty::terr_float_mismatch(err); diff --git a/src/librustc/middle/typeck/rscope.rs b/src/librustc/middle/typeck/rscope.rs index 141a730ca8d..628cccfa9a2 100644 --- a/src/librustc/middle/typeck/rscope.rs +++ b/src/librustc/middle/typeck/rscope.rs @@ -26,7 +26,8 @@ pub trait region_scope { } pub enum empty_rscope { empty_rscope } -pub impl region_scope for empty_rscope { + +impl region_scope for empty_rscope { pure fn anon_region(&self, _span: span) -> Result { result::Ok(ty::re_static) } @@ -40,7 +41,8 @@ pub impl region_scope for empty_rscope { } pub enum type_rscope = Option; -pub impl region_scope for type_rscope { + +impl region_scope for type_rscope { pure fn anon_region(&self, _span: span) -> Result { match **self { Some(_) => result::Ok(ty::re_bound(ty::br_self)), @@ -74,7 +76,8 @@ pub fn in_anon_rscope(self: RS, -> @anon_rscope { @anon_rscope {anon: r, base: self as region_scope} } -pub impl region_scope for @anon_rscope { + +impl region_scope for @anon_rscope { pure fn anon_region(&self, _span: span) -> Result { result::Ok(self.anon) } @@ -97,7 +100,8 @@ pub fn in_binding_rscope(self: RS) let base = self as region_scope; @mut binding_rscope { base: base, anon_bindings: 0 } } -pub impl region_scope for @mut binding_rscope { + +impl region_scope for @mut binding_rscope { pure fn anon_region(&self, _span: span) -> Result { // XXX: Unsafe to work around purity unsafe { diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 11a1b9f3576..0add7926630 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -59,7 +59,7 @@ pub struct Config { pandoc_cmd: Option<~str> } -pub impl Clone for Config { +impl Clone for Config { fn clone(&self) -> Config { copy *self } } diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index 13c0bbe1a67..2ee994bdf32 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -258,7 +258,7 @@ pub trait ByteChan { const CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD]; -pub impl,P:BytePort> GenericPort for FlatPort { +impl,P:BytePort> GenericPort for FlatPort { fn recv() -> T { match self.try_recv() { Some(val) => val, @@ -358,7 +358,7 @@ pub mod flatteners { bogus: () } - pub impl Unflattener for PodUnflattener { + impl Unflattener for PodUnflattener { fn unflatten(&self, buf: ~[u8]) -> T { assert size_of::() != 0; assert size_of::() == buf.len(); @@ -368,7 +368,7 @@ pub mod flatteners { } } - pub impl Flattener for PodFlattener { + impl Flattener for PodFlattener { fn flatten(&self, val: T) -> ~[u8] { assert size_of::() != 0; let val: *T = ptr::to_unsafe_ptr(&val); @@ -406,14 +406,14 @@ pub mod flatteners { serialize_value: SerializeValue } - pub impl> Unflattener + impl> Unflattener for DeserializingUnflattener { fn unflatten(&self, buf: ~[u8]) -> T { (self.deserialize_buffer)(buf) } } - pub impl> Flattener + impl> Flattener for SerializingFlattener { fn flatten(&self, val: T) -> ~[u8] { (self.serialize_value)(&val) @@ -519,7 +519,7 @@ pub mod bytepipes { writer: W } - pub impl BytePort for ReaderBytePort { + impl BytePort for ReaderBytePort { fn try_recv(&self, count: uint) -> Option<~[u8]> { let mut left = count; let mut bytes = ~[]; @@ -541,7 +541,7 @@ pub mod bytepipes { } } - pub impl ByteChan for WriterByteChan { + impl ByteChan for WriterByteChan { fn send(&self, val: ~[u8]) { self.writer.write(val); } @@ -572,7 +572,7 @@ pub mod bytepipes { chan: comm::Chan<~[u8]> } - pub impl BytePort for PipeBytePort { + impl BytePort for PipeBytePort { fn try_recv(&self, count: uint) -> Option<~[u8]> { if self.buf.len() >= count { let mut bytes = ::core::util::replace(&mut self.buf, ~[]); @@ -604,7 +604,7 @@ pub mod bytepipes { } } - pub impl ByteChan for PipeByteChan { + impl ByteChan for PipeByteChan { fn send(&self, val: ~[u8]) { self.chan.send(val) } diff --git a/src/libstd/json.rs b/src/libstd/json.rs index d16b1282c7c..c6e76aa1a68 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -82,7 +82,7 @@ pub fn Encoder(wr: io::Writer) -> Encoder { Encoder { wr: wr } } -pub impl serialize::Encoder for Encoder { +impl serialize::Encoder for Encoder { fn emit_nil(&self) { self.wr.write_str("null") } fn emit_uint(&self, v: uint) { self.emit_float(v as float); } @@ -217,7 +217,7 @@ pub fn PrettyEncoder(wr: io::Writer) -> PrettyEncoder { PrettyEncoder { wr: wr, indent: 0 } } -pub impl serialize::Encoder for PrettyEncoder { +impl serialize::Encoder for PrettyEncoder { fn emit_nil(&self) { self.wr.write_str("null") } fn emit_uint(&self, v: uint) { self.emit_float(v as float); } @@ -323,7 +323,7 @@ pub impl serialize::Encoder for PrettyEncoder { } } -pub impl serialize::Encodable for Json { +impl serialize::Encodable for Json { fn encode(&self, s: &S) { match *self { Number(v) => v.encode(s), @@ -768,7 +768,7 @@ priv impl Decoder { } } -pub impl serialize::Decoder for Decoder { +impl serialize::Decoder for Decoder { fn read_nil(&self) -> () { debug!("read_nil"); match *self.pop() { diff --git a/src/libstd/prettyprint.rs b/src/libstd/prettyprint.rs index cb9090225bf..dd873650b66 100644 --- a/src/libstd/prettyprint.rs +++ b/src/libstd/prettyprint.rs @@ -22,7 +22,7 @@ pub fn Serializer(wr: io::Writer) -> Serializer { Serializer { wr: wr } } -pub impl serialize::Encoder for Serializer { +impl serialize::Encoder for Serializer { fn emit_nil(&self) { self.wr.write_str(~"()") } diff --git a/src/libstd/serialize.rs b/src/libstd/serialize.rs index 3178e141097..66db951e12b 100644 --- a/src/libstd/serialize.rs +++ b/src/libstd/serialize.rs @@ -113,210 +113,210 @@ pub trait Decodable { static fn decode(&self, d: &D) -> Self; } -pub impl Encodable for uint { +impl Encodable for uint { fn encode(&self, s: &S) { s.emit_uint(*self) } } -pub impl Decodable for uint { +impl Decodable for uint { static fn decode(&self, d: &D) -> uint { d.read_uint() } } -pub impl Encodable for u8 { +impl Encodable for u8 { fn encode(&self, s: &S) { s.emit_u8(*self) } } -pub impl Decodable for u8 { +impl Decodable for u8 { static fn decode(&self, d: &D) -> u8 { d.read_u8() } } -pub impl Encodable for u16 { +impl Encodable for u16 { fn encode(&self, s: &S) { s.emit_u16(*self) } } -pub impl Decodable for u16 { +impl Decodable for u16 { static fn decode(&self, d: &D) -> u16 { d.read_u16() } } -pub impl Encodable for u32 { +impl Encodable for u32 { fn encode(&self, s: &S) { s.emit_u32(*self) } } -pub impl Decodable for u32 { +impl Decodable for u32 { static fn decode(&self, d: &D) -> u32 { d.read_u32() } } -pub impl Encodable for u64 { +impl Encodable for u64 { fn encode(&self, s: &S) { s.emit_u64(*self) } } -pub impl Decodable for u64 { +impl Decodable for u64 { static fn decode(&self, d: &D) -> u64 { d.read_u64() } } -pub impl Encodable for int { +impl Encodable for int { fn encode(&self, s: &S) { s.emit_int(*self) } } -pub impl Decodable for int { +impl Decodable for int { static fn decode(&self, d: &D) -> int { d.read_int() } } -pub impl Encodable for i8 { +impl Encodable for i8 { fn encode(&self, s: &S) { s.emit_i8(*self) } } -pub impl Decodable for i8 { +impl Decodable for i8 { static fn decode(&self, d: &D) -> i8 { d.read_i8() } } -pub impl Encodable for i16 { +impl Encodable for i16 { fn encode(&self, s: &S) { s.emit_i16(*self) } } -pub impl Decodable for i16 { +impl Decodable for i16 { static fn decode(&self, d: &D) -> i16 { d.read_i16() } } -pub impl Encodable for i32 { +impl Encodable for i32 { fn encode(&self, s: &S) { s.emit_i32(*self) } } -pub impl Decodable for i32 { +impl Decodable for i32 { static fn decode(&self, d: &D) -> i32 { d.read_i32() } } -pub impl Encodable for i64 { +impl Encodable for i64 { fn encode(&self, s: &S) { s.emit_i64(*self) } } -pub impl Decodable for i64 { +impl Decodable for i64 { static fn decode(&self, d: &D) -> i64 { d.read_i64() } } -pub impl Encodable for &str { +impl Encodable for &str { fn encode(&self, s: &S) { s.emit_borrowed_str(*self) } } -pub impl Encodable for ~str { +impl Encodable for ~str { fn encode(&self, s: &S) { s.emit_owned_str(*self) } } -pub impl Decodable for ~str { +impl Decodable for ~str { static fn decode(&self, d: &D) -> ~str { d.read_owned_str() } } -pub impl Encodable for @str { +impl Encodable for @str { fn encode(&self, s: &S) { s.emit_managed_str(*self) } } -pub impl Decodable for @str { +impl Decodable for @str { static fn decode(&self, d: &D) -> @str { d.read_managed_str() } } -pub impl Encodable for float { +impl Encodable for float { fn encode(&self, s: &S) { s.emit_float(*self) } } -pub impl Decodable for float { +impl Decodable for float { static fn decode(&self, d: &D) -> float { d.read_float() } } -pub impl Encodable for f32 { +impl Encodable for f32 { fn encode(&self, s: &S) { s.emit_f32(*self) } } -pub impl Decodable for f32 { +impl Decodable for f32 { static fn decode(&self, d: &D) -> f32 { d.read_f32() } } -pub impl Encodable for f64 { +impl Encodable for f64 { fn encode(&self, s: &S) { s.emit_f64(*self) } } -pub impl Decodable for f64 { +impl Decodable for f64 { static fn decode(&self, d: &D) -> f64 { d.read_f64() } } -pub impl Encodable for bool { +impl Encodable for bool { fn encode(&self, s: &S) { s.emit_bool(*self) } } -pub impl Decodable for bool { +impl Decodable for bool { static fn decode(&self, d: &D) -> bool { d.read_bool() } } -pub impl Encodable for () { +impl Encodable for () { fn encode(&self, s: &S) { s.emit_nil() } } -pub impl Decodable for () { +impl Decodable for () { static fn decode(&self, d: &D) -> () { d.read_nil() } } -pub impl> Encodable for &T { +impl> Encodable for &T { fn encode(&self, s: &S) { s.emit_borrowed(|| (**self).encode(s)) } } -pub impl> Encodable for ~T { +impl> Encodable for ~T { fn encode(&self, s: &S) { s.emit_owned(|| (**self).encode(s)) } } -pub impl> Decodable for ~T { +impl> Decodable for ~T { static fn decode(&self, d: &D) -> ~T { d.read_owned(|| ~Decodable::decode(d)) } } -pub impl> Encodable for @T { +impl> Encodable for @T { fn encode(&self, s: &S) { s.emit_managed(|| (**self).encode(s)) } } -pub impl> Decodable for @T { +impl> Decodable for @T { static fn decode(&self, d: &D) -> @T { d.read_managed(|| @Decodable::decode(d)) } } -pub impl> Encodable for &[T] { +impl> Encodable for &[T] { fn encode(&self, s: &S) { do s.emit_borrowed_vec(self.len()) { for self.eachi |i, e| { @@ -326,7 +326,7 @@ pub impl> Encodable for &[T] { } } -pub impl> Encodable for ~[T] { +impl> Encodable for ~[T] { fn encode(&self, s: &S) { do s.emit_owned_vec(self.len()) { for self.eachi |i, e| { @@ -336,7 +336,7 @@ pub impl> Encodable for ~[T] { } } -pub impl> Decodable for ~[T] { +impl> Decodable for ~[T] { static fn decode(&self, d: &D) -> ~[T] { do d.read_owned_vec |len| { do vec::from_fn(len) |i| { @@ -346,7 +346,7 @@ pub impl> Decodable for ~[T] { } } -pub impl> Encodable for @[T] { +impl> Encodable for @[T] { fn encode(&self, s: &S) { do s.emit_managed_vec(self.len()) { for self.eachi |i, e| { @@ -356,7 +356,7 @@ pub impl> Encodable for @[T] { } } -pub impl> Decodable for @[T] { +impl> Decodable for @[T] { static fn decode(&self, d: &D) -> @[T] { do d.read_managed_vec |len| { do at_vec::from_fn(len) |i| { @@ -366,7 +366,7 @@ pub impl> Decodable for @[T] { } } -pub impl> Encodable for Option { +impl> Encodable for Option { fn encode(&self, s: &S) { do s.emit_enum(~"option") { match *self { @@ -381,7 +381,7 @@ pub impl> Encodable for Option { } } -pub impl> Decodable for Option { +impl> Decodable for Option { static fn decode(&self, d: &D) -> Option { do d.read_enum(~"option") { do d.read_enum_variant |i| { @@ -396,8 +396,7 @@ pub impl> Decodable for Option { } } -pub impl,T1:Encodable> Encodable - for (T0, T1) { +impl,T1:Encodable> Encodable for (T0, T1) { fn encode(&self, s: &S) { match *self { (ref t0, ref t1) => { @@ -410,8 +409,7 @@ pub impl,T1:Encodable> Encodable } } -pub impl,T1:Decodable> Decodable - for (T0, T1) { +impl,T1:Decodable> Decodable for (T0, T1) { static fn decode(&self, d: &D) -> (T0, T1) { do d.read_tup(2) { ( @@ -422,7 +420,7 @@ pub impl,T1:Decodable> Decodable } } -pub impl< +impl< S: Encoder, T0: Encodable, T1: Encodable, @@ -441,7 +439,7 @@ pub impl< } } -pub impl< +impl< D: Decoder, T0: Decodable, T1: Decodable, @@ -458,7 +456,7 @@ pub impl< } } -pub impl< +impl< S: Encoder, T0: Encodable, T1: Encodable, @@ -479,7 +477,7 @@ pub impl< } } -pub impl< +impl< D: Decoder, T0: Decodable, T1: Decodable, @@ -498,7 +496,7 @@ pub impl< } } -pub impl< +impl< S: Encoder, T0: Encodable, T1: Encodable, @@ -521,7 +519,7 @@ pub impl< } } -pub impl< +impl< D: Decoder, T0: Decodable, T1: Decodable, @@ -552,7 +550,7 @@ pub trait EncoderHelpers { fn emit_from_vec(&self, v: &[T], f: fn(v: &T)); } -pub impl EncoderHelpers for S { +impl EncoderHelpers for S { fn emit_from_vec(&self, v: &[T], f: fn(v: &T)) { do self.emit_owned_vec(v.len()) { for v.eachi |i, e| { @@ -568,7 +566,7 @@ pub trait DecoderHelpers { fn read_to_vec(&self, f: fn() -> T) -> ~[T]; } -pub impl DecoderHelpers for D { +impl DecoderHelpers for D { fn read_to_vec(&self, f: fn() -> T) -> ~[T] { do self.read_owned_vec |len| { do vec::from_fn(len) |i| { diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index d7ca766f183..c85aa78d983 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -140,7 +140,7 @@ impl WorkKey { type WorkMap = LinearMap; -pub impl Encodable for WorkMap { +impl Encodable for WorkMap { fn encode(&self, s: &S) { let mut d = ~[]; for self.each |&(k, v)| { @@ -151,7 +151,7 @@ pub impl Encodable for WorkMap { } } -pub impl Decodable for WorkMap { +impl Decodable for WorkMap { static fn decode(&self, d: &D) -> WorkMap { let v : ~[(WorkKey,~str)] = Decodable::decode(d); let mut w = LinearMap::new(); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 5af67aa0e3b..744cb92fb1c 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -61,7 +61,7 @@ type Name = uint; // with a macro expansion type Mrk = uint; -pub impl Encodable for ident { +impl Encodable for ident { fn encode(&self, s: &S) { let intr = match unsafe { task::local_data::local_data_get(interner_key!()) @@ -74,7 +74,7 @@ pub impl Encodable for ident { } } -pub impl Decodable for ident { +impl Decodable for ident { static fn decode(d: &D) -> ident { let intr = match unsafe { task::local_data::local_data_get(interner_key!()) @@ -87,7 +87,7 @@ pub impl Decodable for ident { } } -pub impl to_bytes::IterBytes for ident { +impl to_bytes::IterBytes for ident { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { self.repr.iter_bytes(lsb0, f) } @@ -246,7 +246,7 @@ pub enum binding_mode { bind_infer } -pub impl to_bytes::IterBytes for binding_mode { +impl to_bytes::IterBytes for binding_mode { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { match *self { bind_by_copy => 0u8.iter_bytes(lsb0, f), @@ -291,7 +291,7 @@ pub enum pat_ { #[deriving_eq] pub enum mutability { m_mutbl, m_imm, m_const, } -pub impl to_bytes::IterBytes for mutability { +impl to_bytes::IterBytes for mutability { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -304,13 +304,13 @@ pub enum Abi { RustAbi } -pub impl to_bytes::IterBytes for Abi { +impl to_bytes::IterBytes for Abi { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as uint).iter_bytes(lsb0, f) } } -pub impl ToStr for Abi { +impl ToStr for Abi { pure fn to_str(&self) -> ~str { match *self { RustAbi => ~"\"rust\"" @@ -327,13 +327,13 @@ pub enum Sigil { ManagedSigil } -pub impl to_bytes::IterBytes for Sigil { +impl to_bytes::IterBytes for Sigil { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as uint).iter_bytes(lsb0, f) } } -pub impl ToStr for Sigil { +impl ToStr for Sigil { pure fn to_str(&self) -> ~str { match *self { BorrowedSigil => ~"&", @@ -412,7 +412,7 @@ pub enum inferable { infer(node_id) } -pub impl to_bytes::IterBytes for inferable { +impl to_bytes::IterBytes for inferable { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { match *self { expl(ref t) => @@ -430,7 +430,7 @@ pub impl to_bytes::IterBytes for inferable { #[deriving_eq] pub enum rmode { by_ref, by_val, by_copy } -pub impl to_bytes::IterBytes for rmode { +impl to_bytes::IterBytes for rmode { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -771,13 +771,13 @@ pub enum trait_method { #[deriving_eq] pub enum int_ty { ty_i, ty_char, ty_i8, ty_i16, ty_i32, ty_i64, } -pub impl ToStr for int_ty { +impl ToStr for int_ty { pure fn to_str(&self) -> ~str { ::ast_util::int_ty_to_str(*self) } } -pub impl to_bytes::IterBytes for int_ty { +impl to_bytes::IterBytes for int_ty { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -788,13 +788,13 @@ pub impl to_bytes::IterBytes for int_ty { #[deriving_eq] pub enum uint_ty { ty_u, ty_u8, ty_u16, ty_u32, ty_u64, } -pub impl ToStr for uint_ty { +impl ToStr for uint_ty { pure fn to_str(&self) -> ~str { ::ast_util::uint_ty_to_str(*self) } } -pub impl to_bytes::IterBytes for uint_ty { +impl to_bytes::IterBytes for uint_ty { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -805,13 +805,13 @@ pub impl to_bytes::IterBytes for uint_ty { #[deriving_eq] pub enum float_ty { ty_f, ty_f32, ty_f64, } -pub impl ToStr for float_ty { +impl ToStr for float_ty { pure fn to_str(&self) -> ~str { ::ast_util::float_ty_to_str(*self) } } -pub impl to_bytes::IterBytes for float_ty { +impl to_bytes::IterBytes for float_ty { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -865,7 +865,7 @@ pub enum Onceness { Many } -pub impl ToStr for Onceness { +impl ToStr for Onceness { pure fn to_str(&self) -> ~str { match *self { Once => ~"once", @@ -874,7 +874,7 @@ pub impl ToStr for Onceness { } } -pub impl to_bytes::IterBytes for Onceness { +impl to_bytes::IterBytes for Onceness { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as uint).iter_bytes(lsb0, f); } @@ -924,7 +924,7 @@ pub enum ty_ { ty_infer, } -pub impl to_bytes::IterBytes for Ty { +impl to_bytes::IterBytes for Ty { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.span.lo, &self.span.hi, lsb0, f); } @@ -960,7 +960,7 @@ pub enum purity { extern_fn, // declared with "extern fn" } -pub impl ToStr for purity { +impl ToStr for purity { pure fn to_str(&self) -> ~str { match *self { impure_fn => ~"impure", @@ -971,7 +971,7 @@ pub impl ToStr for purity { } } -pub impl to_bytes::IterBytes for purity { +impl to_bytes::IterBytes for purity { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -986,7 +986,7 @@ pub enum ret_style { return_val, // everything else } -pub impl to_bytes::IterBytes for ret_style { +impl to_bytes::IterBytes for ret_style { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -1268,7 +1268,7 @@ pub enum item_ { #[deriving_eq] pub enum struct_mutability { struct_mutable, struct_immutable } -pub impl to_bytes::IterBytes for struct_mutability { +impl to_bytes::IterBytes for struct_mutability { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 74f67808a5e..959454841a2 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -34,7 +34,7 @@ pub enum path_elt { path_name(ident) } -pub impl cmp::Eq for path_elt { +impl cmp::Eq for path_elt { pure fn eq(&self, other: &path_elt) -> bool { match (*self) { path_mod(e0a) => { diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index fec3a961a52..4c5c4da5142 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -198,7 +198,7 @@ pub pure fn is_call_expr(e: @expr) -> bool { } // This makes def_id hashable -pub impl to_bytes::IterBytes for def_id { +impl to_bytes::IterBytes for def_id { #[inline(always)] pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.crate, &self.node, lsb0, f); @@ -303,7 +303,7 @@ pub trait inlined_item_utils { fn accept(&self, e: E, v: visit::vt); } -pub impl inlined_item_utils for inlined_item { +impl inlined_item_utils for inlined_item { fn ident(&self) -> ident { match *self { ii_item(i) => /* FIXME (#2543) */ copy i.ident, diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 1ab55fe9035..65711d9894a 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -46,71 +46,71 @@ pub enum CharPos = uint; // XXX: Lots of boilerplate in these impls, but so far my attempts to fix // have been unsuccessful -pub impl Pos for BytePos { +impl Pos for BytePos { static pure fn from_uint(n: uint) -> BytePos { BytePos(n) } pure fn to_uint(&self) -> uint { **self } } -pub impl cmp::Eq for BytePos { +impl cmp::Eq for BytePos { pure fn eq(&self, other: &BytePos) -> bool { **self == **other } pure fn ne(&self, other: &BytePos) -> bool { !(*self).eq(other) } } -pub impl cmp::Ord for BytePos { +impl cmp::Ord for BytePos { pure fn lt(&self, other: &BytePos) -> bool { **self < **other } pure fn le(&self, other: &BytePos) -> bool { **self <= **other } pure fn ge(&self, other: &BytePos) -> bool { **self >= **other } pure fn gt(&self, other: &BytePos) -> bool { **self > **other } } -pub impl Add for BytePos { +impl Add for BytePos { pure fn add(&self, rhs: &BytePos) -> BytePos { BytePos(**self + **rhs) } } -pub impl Sub for BytePos { +impl Sub for BytePos { pure fn sub(&self, rhs: &BytePos) -> BytePos { BytePos(**self - **rhs) } } -pub impl to_bytes::IterBytes for BytePos { +impl to_bytes::IterBytes for BytePos { pure fn iter_bytes(&self, +lsb0: bool, &&f: to_bytes::Cb) { (**self).iter_bytes(lsb0, f) } } -pub impl Pos for CharPos { +impl Pos for CharPos { static pure fn from_uint(n: uint) -> CharPos { CharPos(n) } pure fn to_uint(&self) -> uint { **self } } -pub impl cmp::Eq for CharPos { +impl cmp::Eq for CharPos { pure fn eq(&self, other: &CharPos) -> bool { **self == **other } pure fn ne(&self, other: &CharPos) -> bool { !(*self).eq(other) } } -pub impl cmp::Ord for CharPos { +impl cmp::Ord for CharPos { pure fn lt(&self, other: &CharPos) -> bool { **self < **other } pure fn le(&self, other: &CharPos) -> bool { **self <= **other } pure fn ge(&self, other: &CharPos) -> bool { **self >= **other } pure fn gt(&self, other: &CharPos) -> bool { **self > **other } } -pub impl to_bytes::IterBytes for CharPos { +impl to_bytes::IterBytes for CharPos { pure fn iter_bytes(&self, +lsb0: bool, &&f: to_bytes::Cb) { (**self).iter_bytes(lsb0, f) } } -pub impl Add for CharPos { +impl Add for CharPos { pure fn add(&self, rhs: &CharPos) -> CharPos { CharPos(**self + **rhs) } } -pub impl Sub for CharPos { +impl Sub for CharPos { pure fn sub(&self, rhs: &CharPos) -> CharPos { CharPos(**self - **rhs) } @@ -133,19 +133,19 @@ pub struct span { #[deriving_eq] pub struct spanned { node: T, span: span } -pub impl cmp::Eq for span { +impl cmp::Eq for span { pure fn eq(&self, other: &span) -> bool { return (*self).lo == (*other).lo && (*self).hi == (*other).hi; } pure fn ne(&self, other: &span) -> bool { !(*self).eq(other) } } -pub impl Encodable for span { +impl Encodable for span { /* Note #1972 -- spans are encoded but not decoded */ fn encode(&self, _s: &S) { } } -pub impl Decodable for span { +impl Decodable for span { static fn decode(_d: &D) -> span { dummy_sp() } diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 0019acc1291..9e60e215174 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -1192,7 +1192,7 @@ mod test { } } - pub impl Encoder for TestEncoder { + impl Encoder for TestEncoder { fn emit_nil(&self) { self.add_to_log(CallToEmitNil) } fn emit_uint(&self, +v: uint) {self.add_to_log(CallToEmitUint(v)); } diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index 49f7fe5853e..6adea6395a3 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -54,7 +54,7 @@ pub trait append_types { fn add_tys(+tys: ~[@ast::Ty]) -> @ast::path; } -pub impl append_types for @ast::path { +impl append_types for @ast::path { fn add_ty(ty: @ast::Ty) -> @ast::path { @ast::path { types: vec::append_one(self.types, ty), .. *self} @@ -119,7 +119,7 @@ pub trait ext_ctxt_ast_builder { fn strip_bounds(&self, bounds: &[ast::ty_param]) -> ~[ast::ty_param]; } -pub impl ext_ctxt_ast_builder for ext_ctxt { +impl ext_ctxt_ast_builder for ext_ctxt { fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty { self.ty_path_ast_builder(path_global(~[ self.ident_of(~"core"), diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs index cc42a0992cb..f456f7b81ae 100644 --- a/src/libsyntax/ext/pipes/check.rs +++ b/src/libsyntax/ext/pipes/check.rs @@ -37,7 +37,7 @@ use ext::base::ext_ctxt; use ext::pipes::proto::{state, protocol, next_state}; use ext::pipes::proto; -pub impl proto::visitor<(), (), ()> for ext_ctxt { +impl proto::visitor<(), (), ()> for ext_ctxt { fn visit_proto(&self, _proto: protocol, _states: &[()]) { } diff --git a/src/libsyntax/ext/pipes/parse_proto.rs b/src/libsyntax/ext/pipes/parse_proto.rs index 66feb7cc753..9a330db9f18 100644 --- a/src/libsyntax/ext/pipes/parse_proto.rs +++ b/src/libsyntax/ext/pipes/parse_proto.rs @@ -23,7 +23,7 @@ pub trait proto_parser { fn parse_message(&self, state: state); } -pub impl proto_parser for parser::Parser { +impl proto_parser for parser::Parser { fn parse_proto(&self, id: ~str) -> protocol { let proto = protocol(id, *self.span); diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 444b09d9ae4..84d46e318b1 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -46,7 +46,7 @@ pub trait gen_init { fn gen_init_bounded(&self, ext_cx: ext_ctxt) -> @ast::expr; } -pub impl gen_send for message { +impl gen_send for message { fn gen_send(&mut self, cx: ext_ctxt, try: bool) -> @ast::item { debug!("pipec: gen_send"); let name = self.name(); @@ -196,7 +196,7 @@ pub impl gen_send for message { } } -pub impl to_type_decls for state { +impl to_type_decls for state { fn to_type_decls(&self, cx: ext_ctxt) -> ~[@ast::item] { debug!("pipec: to_type_decls"); // This compiles into two different type declarations. Say the @@ -307,7 +307,7 @@ pub impl to_type_decls for state { } } -pub impl gen_init for protocol { +impl gen_init for protocol { fn gen_init(&self, cx: ext_ctxt) -> @ast::item { let ext_cx = cx; diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 7c6dc1f937d..d22feff9470 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -21,7 +21,7 @@ use core::to_str::ToStr; #[deriving_eq] pub enum direction { send, recv } -pub impl ToStr for direction { +impl ToStr for direction { pure fn to_str(&self) -> ~str { match *self { send => ~"Send", diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index dacb6f60e37..2d8b62629ee 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -694,7 +694,7 @@ pub fn default_ast_fold() -> ast_fold_fns { new_span: noop_span}; } -pub impl ast_fold for ast_fold_fns { +impl ast_fold for ast_fold_fns { /* naturally, a macro to write these would be nice */ fn fold_crate(c: crate) -> crate { let (n, s) = (self.fold_crate)(c.node, c.span, self as ast_fold); diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 51cc25e84a3..dc5bdeba92a 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -127,7 +127,7 @@ impl reader for StringReader { fn dup(@mut self) -> reader { dup_string_reader(self) as reader } } -pub impl reader for TtReader { +impl reader for TtReader { fn is_eof(@mut self) -> bool { self.cur_tok == token::EOF } fn next_token(@mut self) -> TokenAndSpan { tt_next_token(self) } fn fatal(@mut self, m: ~str) -> ! { diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 33d959a7753..b384e7ebdd0 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -50,9 +50,10 @@ pub enum ObsoleteSyntax { ObsoleteTraitBoundSeparator, ObsoleteMutOwnedPointer, ObsoleteMutVector, + ObsoleteTraitImplVisibility, } -pub impl to_bytes::IterBytes for ObsoleteSyntax { +impl to_bytes::IterBytes for ObsoleteSyntax { #[inline(always)] pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as uint).iter_bytes(lsb0, f); @@ -140,6 +141,12 @@ pub impl Parser { in a mutable location, like a mutable local variable or an \ `@mut` box" ), + ObsoleteTraitImplVisibility => ( + "visibility-qualified trait implementation", + "`pub` or `priv` is meaningless for trait implementations, \ + because the `impl...for...` form defines overloads for \ + methods that already exist; remove the `pub` or `priv`" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b4bd28cbfe2..59ad35b38e4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -76,7 +76,7 @@ use parse::obsolete::{ObsoleteStructCtor, ObsoleteWith}; use parse::obsolete::{ObsoleteSyntax, ObsoleteLowerCaseKindBounds}; use parse::obsolete::{ObsoleteUnsafeBlock, ObsoleteImplSyntax}; use parse::obsolete::{ObsoleteTraitBoundSeparator, ObsoleteMutOwnedPointer}; -use parse::obsolete::{ObsoleteMutVector}; +use parse::obsolete::{ObsoleteMutVector, ObsoleteTraitImplVisibility}; 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}; @@ -2942,9 +2942,9 @@ pub impl Parser { } // Parses two variants (with the region/type params always optional): - // impl ~[T] : to_str { ... } - // impl to_str for ~[T] { ... } - fn parse_item_impl() -> item_info { + // impl Foo { ... } + // impl ToStr for ~[T] { ... } + fn parse_item_impl(visibility: ast::visibility) -> item_info { fn wrap_path(p: Parser, pt: @path) -> @Ty { @Ty { id: p.get_id(), @@ -2993,6 +2993,12 @@ pub impl Parser { None }; + // Do not allow visibility to be specified in `impl...for...`. It is + // meaningless. + if opt_trait.is_some() && visibility != ast::inherited { + self.obsolete(*self.span, ObsoleteTraitImplVisibility); + } + let mut meths = ~[]; if !self.eat(token::SEMI) { self.expect(token::LBRACE); @@ -3860,7 +3866,8 @@ pub impl Parser { maybe_append(attrs, extra_attrs))); } else if items_allowed && self.eat_keyword(~"impl") { // IMPL ITEM - let (ident, item_, extra_attrs) = self.parse_item_impl(); + let (ident, item_, extra_attrs) = + self.parse_item_impl(visibility); return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_, visibility, maybe_append(attrs, extra_attrs))); diff --git a/src/test/auxiliary/cci_class_cast.rs b/src/test/auxiliary/cci_class_cast.rs index a2896dad814..5006c72ad15 100644 --- a/src/test/auxiliary/cci_class_cast.rs +++ b/src/test/auxiliary/cci_class_cast.rs @@ -17,7 +17,7 @@ pub mod kitty { name : ~str, } - pub impl ToStr for cat { + impl ToStr for cat { pure fn to_str(&self) -> ~str { copy self.name } } diff --git a/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs b/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs index 2b3fd47e5bc..f578ad82d6d 100644 --- a/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs +++ b/src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs @@ -19,7 +19,7 @@ pub mod name_pool { fn add(s: ~str); } - pub impl add for name_pool { + impl add for name_pool { fn add(s: ~str) { } } @@ -34,7 +34,7 @@ pub mod rust { fn cx(); } - pub impl cx for rt { + impl cx for rt { fn cx() { } } diff --git a/src/test/auxiliary/issue-3012-1.rs b/src/test/auxiliary/issue-3012-1.rs index cbc1c4b2fec..36343d42b75 100644 --- a/src/test/auxiliary/issue-3012-1.rs +++ b/src/test/auxiliary/issue-3012-1.rs @@ -16,7 +16,7 @@ pub mod socket { sockfd: libc::c_int, } - pub impl Drop for socket_handle { + impl Drop for socket_handle { fn finalize(&self) { /* c::close(self.sockfd); */ } diff --git a/src/test/auxiliary/issue2170lib.rs b/src/test/auxiliary/issue2170lib.rs index d664ad62edf..0690a017449 100644 --- a/src/test/auxiliary/issue2170lib.rs +++ b/src/test/auxiliary/issue2170lib.rs @@ -15,7 +15,7 @@ pub struct rsrc { x: i32, } -pub impl Drop for rsrc { +impl Drop for rsrc { fn finalize(&self) { foo(self.x); } diff --git a/src/test/auxiliary/trait_inheritance_overloading_xc.rs b/src/test/auxiliary/trait_inheritance_overloading_xc.rs index 2ed3b3b1f5c..67da2541ca2 100644 --- a/src/test/auxiliary/trait_inheritance_overloading_xc.rs +++ b/src/test/auxiliary/trait_inheritance_overloading_xc.rs @@ -17,25 +17,25 @@ pub struct MyInt { val: int } -pub impl Add for MyInt { +impl Add for MyInt { pure fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) } } -pub impl Sub for MyInt { +impl Sub for MyInt { pure fn sub(&self, other: &MyInt) -> MyInt { mi(self.val - other.val) } } -pub impl Mul for MyInt { +impl Mul for MyInt { pure fn mul(&self, other: &MyInt) -> MyInt { mi(self.val * other.val) } } -pub impl Eq for MyInt { +impl Eq for MyInt { pure fn eq(&self, other: &MyInt) -> bool { self.val == other.val } pure fn ne(&self, other: &MyInt) -> bool { !self.eq(other) } } -pub impl MyNum for MyInt; +impl MyNum for MyInt; pure fn mi(v: int) -> MyInt { MyInt { val: v } } diff --git a/src/test/compile-fail/issue-3953.rs b/src/test/compile-fail/issue-3953.rs index 227ea5c1521..90ca7c1797c 100644 --- a/src/test/compile-fail/issue-3953.rs +++ b/src/test/compile-fail/issue-3953.rs @@ -19,7 +19,7 @@ trait Hahaha: Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq //~ ERROR Duplicat enum Lol = int; -pub impl Hahaha for Lol { } +impl Hahaha for Lol { } impl Eq for Lol { pure fn eq(&self, other: &Lol) -> bool { **self != **other } diff --git a/src/test/compile-fail/issue-3969.rs b/src/test/compile-fail/issue-3969.rs index a0035639287..e2bf708feab 100644 --- a/src/test/compile-fail/issue-3969.rs +++ b/src/test/compile-fail/issue-3969.rs @@ -16,7 +16,7 @@ trait BikeMethods { fn woops(&const self) -> ~str; } -pub impl BikeMethods for Bike { +impl BikeMethods for Bike { static fn woops(&const self) -> ~str { ~"foo" } //~^ ERROR method `woops` is declared as static in its impl, but not in its trait } diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index b97ebb04f71..4a7263266b7 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -155,7 +155,7 @@ pub mod pipes { p: Option<*packet>, } - pub impl Drop for send_packet { + impl Drop for send_packet { fn finalize(&self) { unsafe { if self.p != None { @@ -187,7 +187,7 @@ pub mod pipes { p: Option<*packet>, } - pub impl Drop for recv_packet { + impl Drop for recv_packet { fn finalize(&self) { unsafe { if self.p != None { diff --git a/src/test/run-pass/pipe-presentation-examples.rs b/src/test/run-pass/pipe-presentation-examples.rs index 85ab1f89dbe..8749c1cb113 100644 --- a/src/test/run-pass/pipe-presentation-examples.rs +++ b/src/test/run-pass/pipe-presentation-examples.rs @@ -79,7 +79,7 @@ pub struct Buffer { } -pub impl Drop for Buffer { +impl Drop for Buffer { fn finalize(&self) {} } diff --git a/src/test/run-pass/static-impl.rs b/src/test/run-pass/static-impl.rs index 201193fd738..d1b2870fef6 100644 --- a/src/test/run-pass/static-impl.rs +++ b/src/test/run-pass/static-impl.rs @@ -16,12 +16,12 @@ pub trait plus { mod a { use plus; - pub impl plus for uint { fn plus() -> int { self as int + 20 } } + impl plus for uint { fn plus() -> int { self as int + 20 } } } mod b { use plus; - pub impl plus for ~str { fn plus() -> int { 200 } } + impl plus for ~str { fn plus() -> int { 200 } } } trait uint_utils { diff --git a/src/test/run-pass/static-methods-in-traits2.rs b/src/test/run-pass/static-methods-in-traits2.rs index b4c28fd52a6..20ab9014c70 100644 --- a/src/test/run-pass/static-methods-in-traits2.rs +++ b/src/test/run-pass/static-methods-in-traits2.rs @@ -2,7 +2,7 @@ pub trait Number: NumConv { static pure fn from(n: T) -> Self; } -pub impl Number for float { +impl Number for float { static pure fn from(n: T) -> float { n.to_float() } } @@ -10,7 +10,7 @@ pub trait NumConv { pure fn to_float(&self) -> float; } -pub impl NumConv for float { +impl NumConv for float { pure fn to_float(&self) -> float { *self } } diff --git a/src/test/run-pass/trait-inheritance-num2.rs b/src/test/run-pass/trait-inheritance-num2.rs index 64b30d71e1d..f20181d22d3 100644 --- a/src/test/run-pass/trait-inheritance-num2.rs +++ b/src/test/run-pass/trait-inheritance-num2.rs @@ -21,84 +21,84 @@ use std::cmp::FuzzyEq; pub trait TypeExt {} -pub impl TypeExt for u8 {} -pub impl TypeExt for u16 {} -pub impl TypeExt for u32 {} -pub impl TypeExt for u64 {} -pub impl TypeExt for uint {} +impl TypeExt for u8 {} +impl TypeExt for u16 {} +impl TypeExt for u32 {} +impl TypeExt for u64 {} +impl TypeExt for uint {} -pub impl TypeExt for i8 {} -pub impl TypeExt for i16 {} -pub impl TypeExt for i32 {} -pub impl TypeExt for i64 {} -pub impl TypeExt for int {} +impl TypeExt for i8 {} +impl TypeExt for i16 {} +impl TypeExt for i32 {} +impl TypeExt for i64 {} +impl TypeExt for int {} -pub impl TypeExt for f32 {} -pub impl TypeExt for f64 {} -pub impl TypeExt for float {} +impl TypeExt for f32 {} +impl TypeExt for f64 {} +impl TypeExt for float {} pub trait NumExt: TypeExt Eq Ord NumCast {} -pub impl NumExt for u8 {} -pub impl NumExt for u16 {} -pub impl NumExt for u32 {} -pub impl NumExt for u64 {} -pub impl NumExt for uint {} +impl NumExt for u8 {} +impl NumExt for u16 {} +impl NumExt for u32 {} +impl NumExt for u64 {} +impl NumExt for uint {} -pub impl NumExt for i8 {} -pub impl NumExt for i16 {} -pub impl NumExt for i32 {} -pub impl NumExt for i64 {} -pub impl NumExt for int {} +impl NumExt for i8 {} +impl NumExt for i16 {} +impl NumExt for i32 {} +impl NumExt for i64 {} +impl NumExt for int {} -pub impl NumExt for f32 {} -pub impl NumExt for f64 {} -pub impl NumExt for float {} +impl NumExt for f32 {} +impl NumExt for f64 {} +impl NumExt for float {} pub trait UnSignedExt: NumExt {} -pub impl UnSignedExt for u8 {} -pub impl UnSignedExt for u16 {} -pub impl UnSignedExt for u32 {} -pub impl UnSignedExt for u64 {} -pub impl UnSignedExt for uint {} +impl UnSignedExt for u8 {} +impl UnSignedExt for u16 {} +impl UnSignedExt for u32 {} +impl UnSignedExt for u64 {} +impl UnSignedExt for uint {} pub trait SignedExt: NumExt {} -pub impl SignedExt for i8 {} -pub impl SignedExt for i16 {} -pub impl SignedExt for i32 {} -pub impl SignedExt for i64 {} -pub impl SignedExt for int {} +impl SignedExt for i8 {} +impl SignedExt for i16 {} +impl SignedExt for i32 {} +impl SignedExt for i64 {} +impl SignedExt for int {} -pub impl SignedExt for f32 {} -pub impl SignedExt for f64 {} -pub impl SignedExt for float {} +impl SignedExt for f32 {} +impl SignedExt for f64 {} +impl SignedExt for float {} pub trait IntegerExt: NumExt {} -pub impl IntegerExt for u8 {} -pub impl IntegerExt for u16 {} -pub impl IntegerExt for u32 {} -pub impl IntegerExt for u64 {} -pub impl IntegerExt for uint {} +impl IntegerExt for u8 {} +impl IntegerExt for u16 {} +impl IntegerExt for u32 {} +impl IntegerExt for u64 {} +impl IntegerExt for uint {} -pub impl IntegerExt for i8 {} -pub impl IntegerExt for i16 {} -pub impl IntegerExt for i32 {} -pub impl IntegerExt for i64 {} -pub impl IntegerExt for int {} +impl IntegerExt for i8 {} +impl IntegerExt for i16 {} +impl IntegerExt for i32 {} +impl IntegerExt for i64 {} +impl IntegerExt for int {} pub trait FloatExt: NumExt FuzzyEq {} -pub impl FloatExt for f32 {} -pub impl FloatExt for f64 {} -pub impl FloatExt for float {} +impl FloatExt for f32 {} +impl FloatExt for f64 {} +impl FloatExt for float {} fn test_float_ext(n: T) { io::println(fmt!("%?", n < n)) } diff --git a/src/test/run-pass/trait-inheritance-num3.rs b/src/test/run-pass/trait-inheritance-num3.rs index f184ab2741a..adb9f01fff8 100644 --- a/src/test/run-pass/trait-inheritance-num3.rs +++ b/src/test/run-pass/trait-inheritance-num3.rs @@ -13,7 +13,7 @@ use num::NumCast::from; pub trait NumExt: Eq Ord NumCast {} -pub impl NumExt for f32 {} +impl NumExt for f32 {} fn num_eq_one(n: T) { io::println(fmt!("%?", n == from(1))) } diff --git a/src/test/run-pass/trait-inheritance-num5.rs b/src/test/run-pass/trait-inheritance-num5.rs index 692d50e541a..d10126dddb6 100644 --- a/src/test/run-pass/trait-inheritance-num5.rs +++ b/src/test/run-pass/trait-inheritance-num5.rs @@ -13,8 +13,8 @@ use num::NumCast::from; pub trait NumExt: Eq NumCast {} -pub impl NumExt for f32 {} -pub impl NumExt for int {} +impl NumExt for f32 {} +impl NumExt for int {} fn num_eq_one() -> T { from(1) diff --git a/src/test/run-pass/trait-static-method-overwriting.rs b/src/test/run-pass/trait-static-method-overwriting.rs index d416f3f6c91..9565919a5d8 100644 --- a/src/test/run-pass/trait-static-method-overwriting.rs +++ b/src/test/run-pass/trait-static-method-overwriting.rs @@ -19,7 +19,7 @@ mod base { dummy: (), } - pub impl ::base::HasNew for Foo { + impl ::base::HasNew for Foo { static pure fn new() -> Foo { unsafe { io::println("Foo"); } Foo { dummy: () } @@ -30,7 +30,7 @@ mod base { dummy: (), } - pub impl ::base::HasNew for Bar { + impl ::base::HasNew for Bar { static pure fn new() -> Bar { unsafe { io::println("Bar"); } Bar { dummy: () } -- cgit 1.4.1-3-g733a5