From c8d8f6cfec50cad6b35e3b5fc604abc01a26143e Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Mon, 18 Feb 2013 22:48:18 +0000 Subject: [PATCH 01/85] Refactored make_absolute into functionality on the Path --- src/libcore/os.rs | 8 ++------ src/libcore/path.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 98bac3a49d8a2..8667efb746806 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -565,17 +565,13 @@ pub fn path_exists(p: &Path) -> bool { * * If the given path is relative, return it prepended with the current working * directory. If the given path is already an absolute path, return it - * as is. + * as is. This is a shortcut for calling os::getcwd().unsafe_join(p) */ // NB: this is here rather than in path because it is a form of environment // querying; what it does depends on the process working directory, not just // the input paths. pub fn make_absolute(p: &Path) -> Path { - if p.is_absolute { - copy *p - } else { - getcwd().push_many(p.components) - } + getcwd().unsafe_join(p) } diff --git a/src/libcore/path.rs b/src/libcore/path.rs index 531ce95d067be..46f8743ff15fd 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -64,6 +64,8 @@ pub trait GenericPath { pure fn push_many((&[~str])) -> Self; pure fn pop() -> Self; + pure fn unsafe_join((&Self)) -> Self; + pure fn normalize() -> Self; } @@ -485,6 +487,15 @@ impl GenericPath for PosixPath { self.push_many(other.components) } + pure fn unsafe_join(other: &PosixPath) -> PosixPath { + if other.is_absolute { + PosixPath { is_absolute: true, + components: copy other.components } + } else { + self.push_rel(other) + } + } + pure fn push_many(cs: &[~str]) -> PosixPath { let mut v = copy self.components; for cs.each |e| { @@ -685,6 +696,25 @@ impl GenericPath for WindowsPath { self.push_many(other.components) } + pure fn unsafe_join(other: &WindowsPath) -> WindowsPath { + if !other.is_absolute { + self.push_rel(other) + } else { + WindowsPath { + host: match other.host { + None => copy self.host, + Some(copy x) => Some(x) + }, + device: match other.device { + None => copy self.device, + Some(copy x) => Some(x) + }, + is_absolute: true, + components: copy other.components + } + } + } + pure fn push_many(cs: &[~str]) -> WindowsPath { let mut v = copy self.components; for cs.each |e| { From b07eab5faab16a975df89eae8ea5d7276bc44507 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 19 Feb 2013 01:34:48 +0000 Subject: [PATCH 02/85] Improved windows path handling support --- src/libcore/path.rs | 118 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 100 insertions(+), 18 deletions(-) diff --git a/src/libcore/path.rs b/src/libcore/path.rs index 46f8743ff15fd..96a921cf20bfb 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -697,21 +697,44 @@ impl GenericPath for WindowsPath { } pure fn unsafe_join(other: &WindowsPath) -> WindowsPath { + /* rhs not absolute is simple push */ if !other.is_absolute { - self.push_rel(other) - } else { - WindowsPath { - host: match other.host { - None => copy self.host, - Some(copy x) => Some(x) - }, - device: match other.device { - None => copy self.device, - Some(copy x) => Some(x) - }, - is_absolute: true, - components: copy other.components + return self.push_many(other.components); + } + + /* if rhs has a host set, then the whole thing wins */ + match other.host { + Some(copy host) => { + return WindowsPath { + host: Some(host), + device: copy other.device, + is_absolute: true, + components: copy other.components + }; + } + _ => {} + } + + /* if rhs has a device set, then a part wins */ + match other.device { + Some(copy device) => { + return WindowsPath { + host: None, + device: Some(device), + is_absolute: true, + components: copy other.components + }; } + _ => {} + } + + /* fallback: host and device of lhs win, but the + whole path of the right */ + WindowsPath { + host: copy self.host, + device: copy self.device, + is_absolute: self.is_absolute || other.is_absolute, + components: copy other.components } } @@ -755,7 +778,10 @@ impl GenericPath for WindowsPath { pure fn normalize() -> WindowsPath { return WindowsPath { host: copy self.host, - device: copy self.device, + device: match self.device { + None => None, + Some(ref device) => Some(device.to_upper()) + }, is_absolute: self.is_absolute, components: normalize(self.components) } @@ -794,13 +820,13 @@ pub mod windows { pub pure fn extract_unc_prefix(s: &str) -> Option<(~str,~str)> { if (s.len() > 1 && - s[0] == '\\' as u8 && - s[1] == '\\' as u8) { + (s[0] == '\\' as u8 || s[0] == '/' as u8) && + s[0] == s[1]) { let mut i = 2; while i < s.len() { - if s[i] == '\\' as u8 { + if is_sep(s[i]) { let pre = s.slice(2, i); - let rest = s.slice(i, s.len()); + let mut rest = s.slice(i, s.len()); return Some((pre, rest)); } i += 1; @@ -946,13 +972,21 @@ mod tests { #[test] fn test_extract_unc_prefixes() { assert windows::extract_unc_prefix("\\\\").is_none(); + assert windows::extract_unc_prefix("//").is_none(); assert windows::extract_unc_prefix("\\\\hi").is_none(); + assert windows::extract_unc_prefix("//hi").is_none(); assert windows::extract_unc_prefix("\\\\hi\\") == Some((~"hi", ~"\\")); + assert windows::extract_unc_prefix("//hi\\") == + Some((~"hi", ~"\\")); assert windows::extract_unc_prefix("\\\\hi\\there") == Some((~"hi", ~"\\there")); + assert windows::extract_unc_prefix("//hi/there") == + Some((~"hi", ~"/there")); assert windows::extract_unc_prefix("\\\\hi\\there\\friends.txt") == Some((~"hi", ~"\\there\\friends.txt")); + assert windows::extract_unc_prefix("//hi\\there\\friends.txt") == + Some((~"hi", ~"\\there\\friends.txt")); } #[test] @@ -1011,5 +1045,53 @@ mod tests { .push_many([~"lib", ~"thingy.dll"]) .with_filename("librustc.dll")), "c:\\program files (x86)\\rust\\lib\\librustc.dll"); + + t(&(WindowsPath("\\\\computer\\share") + .unsafe_join(&WindowsPath("\\a"))), + "\\\\computer\\a"); + + t(&(WindowsPath("//computer/share") + .unsafe_join(&WindowsPath("\\a"))), + "\\\\computer\\a"); + + t(&(WindowsPath("//computer/share") + .unsafe_join(&WindowsPath("\\\\computer\\share"))), + "\\\\computer\\share"); + + t(&(WindowsPath("C:/whatever") + .unsafe_join(&WindowsPath("//computer/share/a/b"))), + "\\\\computer\\share\\a\\b"); + + t(&(WindowsPath("C:") + .unsafe_join(&WindowsPath("D:/foo"))), + "D:\\foo"); + + t(&(WindowsPath("C:") + .unsafe_join(&WindowsPath("B"))), + "C:B"); + + t(&(WindowsPath("C:") + .unsafe_join(&WindowsPath("/foo"))), + "C:\\foo"); + + t(&(WindowsPath("C:\\") + .unsafe_join(&WindowsPath("\\bar"))), + "C:\\bar"); + + t(&(WindowsPath("") + .unsafe_join(&WindowsPath(""))), + ""); + + t(&(WindowsPath("") + .unsafe_join(&WindowsPath("a"))), + "a"); + + t(&(WindowsPath("") + .unsafe_join(&WindowsPath("C:\\a"))), + "C:\\a"); + + t(&(WindowsPath("c:\\foo") + .normalize()), + "C:\\foo"); } } From c77c5c4674c92b342132a56bd1b59f86af3d5a63 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 19 Feb 2013 01:54:05 +0000 Subject: [PATCH 03/85] Added is_restricted() to path --- src/libcore/path.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/libcore/path.rs b/src/libcore/path.rs index 96a921cf20bfb..1753862649f57 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -65,6 +65,7 @@ pub trait GenericPath { pure fn pop() -> Self; pure fn unsafe_join((&Self)) -> Self; + pure fn is_restricted() -> bool; pure fn normalize() -> Self; } @@ -496,6 +497,10 @@ impl GenericPath for PosixPath { } } + pure fn is_restricted() -> bool { + false + } + pure fn push_many(cs: &[~str]) -> PosixPath { let mut v = copy self.components; for cs.each |e| { @@ -738,6 +743,19 @@ impl GenericPath for WindowsPath { } } + pure fn is_restricted() -> bool { + match self.filestem() { + Some(stem) => { + match stem.to_lower() { + ~"con" | ~"aux" | ~"com1" | ~"com2" | ~"com3" | ~"com4" | + ~"lpt1" | ~"lpt2" | ~"lpt3" | ~"prn" | ~"nul" => true, + _ => false + } + }, + None => false + } + } + pure fn push_many(cs: &[~str]) -> WindowsPath { let mut v = copy self.components; for cs.each |e| { @@ -1094,4 +1112,12 @@ mod tests { .normalize()), "C:\\foo"); } + + #[test] + fn test_windows_path_restrictions() { + assert WindowsPath("hi").is_restricted() == false; + assert WindowsPath("C:\\NUL").is_restricted() == true; + assert WindowsPath("C:\\COM1.TXT").is_restricted() == true; + assert WindowsPath("c:\\prn.exe").is_restricted() == true; + } } From 4ffff6697b144b346cc3853a82f1056b593ef58d Mon Sep 17 00:00:00 2001 From: oncemoreification Date: Mon, 18 Feb 2013 23:55:37 -0800 Subject: [PATCH 04/85] Fix vector syntax in error messages --- src/librustc/middle/typeck/infer/mod.rs | 3 +-- src/librustc/util/ppaux.rs | 14 ++++++++------ src/test/compile-fail/issue-2149.rs | 2 +- src/test/compile-fail/issue-4517.rs | 6 ++++++ 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 src/test/compile-fail/issue-4517.rs diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index 7d799b7ea2fb6..55a9527213848 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -733,10 +733,10 @@ impl @mut InferCtxt { fn report_mismatched_types(sp: span, e: ty::t, a: ty::t, err: &ty::type_err) { - // Don't report an error if expected is ty_err let resolved_expected = self.resolve_type_vars_if_possible(e); let mk_msg = match ty::get(resolved_expected).sty { + // Don't report an error if expected is ty_err ty::ty_err => return, _ => { // if I leave out : ~str, it infers &str and complains @@ -779,4 +779,3 @@ impl @mut InferCtxt { } } - diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 8b0c84cff8343..924574a4c0c01 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -238,6 +238,7 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str { ty::vstore_fixed(n) => fmt!("%u", n), ty::vstore_uniq => ~"~", ty::vstore_box => ~"@", + /* FIXME(#4517) slice fmt */ ty::vstore_slice(r) => region_to_str(cx, r) } } @@ -245,12 +246,13 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str { pub fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str { match vs { ty::vstore_fixed(_) => { - fmt!("%s/%s", ty, vstore_to_str(cx, vs)) + fmt!("[%s * %s]", ty, vstore_to_str(cx, vs)) } + /* FIXME(#4517) slice fmt */ ty::vstore_slice(_) => { fmt!("%s/%s", vstore_to_str(cx, vs), ty) } - _ => fmt!("%s%s", vstore_to_str(cx, vs), ty) + _ => fmt!("%s[%s]", vstore_to_str(cx, vs), ty) } } @@ -453,13 +455,13 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { ty_trait(did, ref substs, vs) => { let path = ty::item_path(cx, did); let base = ast_map::path_to_str(path, cx.sess.intr()); - let result = parameterized(cx, base, substs.self_r, substs.tps); - vstore_ty_to_str(cx, result, vs) + let ty = parameterized(cx, base, substs.self_r, substs.tps); + fmt!("%s%s", vstore_to_str(cx, vs), ty) } ty_evec(mt, vs) => { - vstore_ty_to_str(cx, fmt!("[%s]", mt_to_str(cx, mt)), vs) + vstore_ty_to_str(cx, fmt!("%s", mt_to_str(cx, mt)), vs) } - ty_estr(vs) => vstore_ty_to_str(cx, ~"str", vs), + ty_estr(vs) => fmt!("%s%s", vstore_to_str(cx, vs), ~"str"), ty_opaque_box => ~"@?", ty_opaque_closure_ptr(ast::BorrowedSigil) => ~"closure&", ty_opaque_closure_ptr(ast::ManagedSigil) => ~"closure@", diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index 7e3ffb92950ad..b3820939f8a9e 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -22,6 +22,6 @@ impl vec_monad for ~[A] { } fn main() { ["hi"].bind(|x| [x] ); - //~^ ERROR type `[&static/str]/1` does not implement any method in scope named `bind` + //~^ ERROR type `[&staticstr * 1]` does not implement any method in scope named `bind` //~^^ ERROR Unconstrained region variable } diff --git a/src/test/compile-fail/issue-4517.rs b/src/test/compile-fail/issue-4517.rs new file mode 100644 index 0000000000000..18caaa697a17d --- /dev/null +++ b/src/test/compile-fail/issue-4517.rs @@ -0,0 +1,6 @@ +fn bar(int_param: int) {} + +fn main() { + let foo: [u8 * 4] = [1u8, ..4u8]; + bar(foo); //~ ERROR mismatched types: expected `int` but found `[u8 * 4]` (expected int but found vector) +} From ad414dec67f3f9583938a2a1212e104443fca798 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Sat, 23 Feb 2013 01:25:10 +0900 Subject: [PATCH 05/85] Consolidate codes dealing with LLVM struct type --- src/librustc/lib/llvm.rs | 24 +++++++++--------------- src/librustc/middle/trans/base.rs | 5 ----- src/librustc/middle/trans/cabi_x86_64.rs | 14 +------------- src/librustc/middle/trans/callee.rs | 2 +- src/librustc/middle/trans/common.rs | 13 ------------- 5 files changed, 11 insertions(+), 47 deletions(-) diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index e42d3aeaf144c..d2bb7c75a27f6 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -1379,12 +1379,7 @@ pub fn type_to_str_inner(names: @TypeNames, +outer0: &[TypeRef], ty: TypeRef) type_to_str_inner(names, outer, out_ty)).to_managed(); } Struct => { - let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint; - let mut elts = vec::from_elem(n_elts, 0 as TypeRef); - if !elts.is_empty() { - llvm::LLVMGetStructElementTypes( - ty, ptr::to_mut_unsafe_ptr(&mut elts[0])); - } + let elts = struct_tys(ty); // See [Note at-str] return fmt!("{%s}", tys_str(names, outer, elts)).to_managed(); } @@ -1445,17 +1440,16 @@ pub fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] { } } -pub fn struct_element_types(struct_ty: TypeRef) -> ~[TypeRef] { +pub fn struct_tys(struct_ty: TypeRef) -> ~[TypeRef] { unsafe { - let count = llvm::LLVMCountStructElementTypes(struct_ty); - let mut buf: ~[TypeRef] = - vec::from_elem(count as uint, - cast::transmute::(0)); - if buf.len() > 0 { - llvm::LLVMGetStructElementTypes( - struct_ty, ptr::to_mut_unsafe_ptr(&mut buf[0])); + let n_elts = llvm::LLVMCountStructElementTypes(struct_ty) as uint; + if n_elts == 0 { + return ~[]; } - return buf; + let mut elts = vec::from_elem(n_elts, ptr::null()); + llvm::LLVMGetStructElementTypes( + struct_ty, ptr::to_mut_unsafe_ptr(&mut elts[0])); + return elts; } } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index cadbe1208ad2b..d69ae8e1c7b74 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2150,11 +2150,6 @@ pub fn trans_mod(ccx: @CrateContext, m: ast::_mod) { } } -pub fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef { - // Bit of a kludge: pick the fn typeref out of the pair. - return struct_elt(llpairty, 0u); -} - pub fn register_fn(ccx: @CrateContext, sp: span, +path: path, diff --git a/src/librustc/middle/trans/cabi_x86_64.rs b/src/librustc/middle/trans/cabi_x86_64.rs index 9f717682dae09..df0f11eedae88 100644 --- a/src/librustc/middle/trans/cabi_x86_64.rs +++ b/src/librustc/middle/trans/cabi_x86_64.rs @@ -14,6 +14,7 @@ use lib::llvm::{llvm, TypeRef, ValueRef, Integer, Pointer, Float, Double}; use lib::llvm::{Struct, Array, Attribute}; use lib::llvm::{StructRetAttribute, ByValAttribute}; +use lib::llvm::struct_tys; use middle::trans::common::*; use middle::trans::cabi::*; @@ -65,19 +66,6 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] { return (off + a - 1u) / a * a; } - fn struct_tys(ty: TypeRef) -> ~[TypeRef] { - unsafe { - let n = llvm::LLVMCountStructElementTypes(ty); - if (n == 0) { - return ~[]; - } - let mut elts = vec::from_elem(n as uint, ptr::null()); - llvm::LLVMGetStructElementTypes(ty, - ptr::to_mut_unsafe_ptr(&mut elts[0])); - return elts; - } - } - fn ty_align(ty: TypeRef) -> uint { unsafe { return match llvm::LLVMGetTypeKind(ty) { diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index c1dac70ae97d9..6924ccf3ab644 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -380,7 +380,7 @@ pub fn trans_rtcall_or_lang_call_with_type_params(bcx: block, fty); let mut llfnty = type_of::type_of(callee.bcx.ccx(), substituted); - llfnty = T_ptr(struct_elt(llfnty, 0)); + llfnty = lib::llvm::struct_tys(llfnty)[0]; new_llval = PointerCast(callee.bcx, fn_data.llfn, llfnty); } _ => fail!() diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 8bd85be0f7082..fe0c4243e35ba 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -645,19 +645,6 @@ pub fn val_str(tn: @TypeNames, v: ValueRef) -> @str { return ty_str(tn, val_ty(v)); } -// Returns the nth element of the given LLVM structure type. -pub fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef { - unsafe { - let elt_count = llvm::LLVMCountStructElementTypes(llstructty) as uint; - assert (n < elt_count); - let mut elt_tys = vec::from_elem(elt_count, T_nil()); - llvm::LLVMGetStructElementTypes( - llstructty, - ptr::to_mut_unsafe_ptr(&mut elt_tys[0])); - return llvm::LLVMGetElementType(elt_tys[n]); - } -} - pub fn in_scope_cx(cx: block, f: &fn(&mut scope_info)) { let mut cur = cx; loop { From 1afddff97ff825c88b106f98955ed84d135ef6f7 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 23 Feb 2013 00:37:37 -0500 Subject: [PATCH 06/85] remove oldsmallintmap Closes #4738 --- src/librustc/middle/astencode.rs | 4 +- src/librustc/middle/lint.rs | 20 +- src/librustc/middle/trans/base.rs | 1 - src/librustc/middle/ty.rs | 15 +- src/librustc/middle/typeck/infer/mod.rs | 4 +- src/librustc/middle/typeck/infer/unify.rs | 12 +- src/librustc/middle/typeck/mod.rs | 1 - src/libstd/oldsmallintmap.rs | 237 ---------------------- src/libstd/std.rc | 1 - 9 files changed, 27 insertions(+), 268 deletions(-) delete mode 100644 src/libstd/oldsmallintmap.rs diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 0b1abd683b122..02cd5afc920a1 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -860,7 +860,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext, } } } - do option::iter(&(*tcx.node_types).find(id as uint)) |ty| { + do option::iter(&tcx.node_types.find(&(id as uint))) |&ty| { do ebml_w.tag(c::tag_table_node_type) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -1135,7 +1135,7 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext, let ty = val_dsr.read_ty(xcx); debug!("inserting ty for node %?: %s", id, ty_to_str(dcx.tcx, ty)); - (*dcx.tcx.node_types).insert(id as uint, ty); + dcx.tcx.node_types.insert(id as uint, ty); } else if tag == (c::tag_table_node_type_subst as uint) { let tys = val_dsr.read_tys(xcx); dcx.tcx.node_type_substs.insert(id, tys); diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 0a06808b63356..a25bc84f8a214 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -34,8 +34,7 @@ use core::uint; use core::vec; use std::oldmap::{Map, HashMap}; use std::oldmap; -use std::oldsmallintmap::{Map, SmallIntMap}; -use std::oldsmallintmap; +use std::smallintmap::SmallIntMap; use syntax::ast_util::{path_to_ident}; use syntax::attr; use syntax::codemap::span; @@ -275,7 +274,7 @@ pub fn get_lint_dict() -> LintDict { } // This is a highly not-optimal set of data structure decisions. -type LintModes = SmallIntMap; +type LintModes = @mut SmallIntMap; type LintModeMap = HashMap; // settings_map maps node ids of items with non-default lint settings @@ -288,14 +287,14 @@ pub struct LintSettings { pub fn mk_lint_settings() -> LintSettings { LintSettings { - default_settings: oldsmallintmap::mk(), + default_settings: @mut SmallIntMap::new(), settings_map: HashMap() } } pub fn get_lint_level(modes: LintModes, lint: lint) -> level { - match modes.find(lint as uint) { - Some(c) => c, + match modes.find(&(lint as uint)) { + Some(&c) => c, None => allow } } @@ -314,8 +313,7 @@ pub fn get_lint_settings_level(settings: LintSettings, // This is kind of unfortunate. It should be somewhere else, or we should use // a persistent data structure... fn clone_lint_modes(modes: LintModes) -> LintModes { - oldsmallintmap::SmallIntMap_(@oldsmallintmap::SmallIntMap_ - {v: copy modes.v}) + @mut (copy *modes) } struct Context { @@ -332,7 +330,7 @@ impl Context { fn set_level(&self, lint: lint, level: level) { if level == allow { - self.curr.remove(lint as uint); + self.curr.remove(&(lint as uint)); } else { self.curr.insert(lint as uint, level); } @@ -440,7 +438,7 @@ fn build_settings_item(i: @ast::item, &&cx: Context, v: visit::vt) { pub fn build_settings_crate(sess: session::Session, crate: @ast::crate) { let cx = Context { dict: get_lint_dict(), - curr: oldsmallintmap::mk(), + curr: @mut SmallIntMap::new(), is_default: true, sess: sess }; @@ -458,7 +456,7 @@ pub fn build_settings_crate(sess: session::Session, crate: @ast::crate) { do cx.with_lint_attrs(/*bad*/copy crate.node.attrs) |cx| { // Copy out the default settings - for cx.curr.each |k, v| { + for cx.curr.each |&(k, &v)| { sess.lint_settings.default_settings.insert(k, v); } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index f5fa83e3fff3f..b9f88b1763464 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -76,7 +76,6 @@ use core::option::{is_none, is_some}; use core::option; use core::uint; use std::oldmap::HashMap; -use std::oldsmallintmap; use std::{oldmap, time, list}; use syntax::ast_map::{path, path_elt_to_str, path_mod, path_name}; use syntax::ast_util::{def_id_of_def, local_def, path_to_ident}; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 239e86623cabd..2fa397e919690 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -42,7 +42,8 @@ use core::uint; use core::vec; use core::hashmap::linear::LinearMap; use std::oldmap::HashMap; -use std::{oldmap, oldsmallintmap}; +use std::oldmap; +use std::smallintmap::SmallIntMap; use syntax::ast::*; use syntax::ast_util::{is_local, local_def}; use syntax::ast_util; @@ -767,7 +768,7 @@ type type_cache = HashMap; type constness_cache = HashMap; -pub type node_type_table = @oldsmallintmap::SmallIntMap; +pub type node_type_table = @mut SmallIntMap; fn mk_rcache() -> creader_cache { type val = {cnum: int, pos: uint, len: uint}; @@ -812,7 +813,7 @@ pub fn mk_ctxt(s: session::Session, def_map: dm, region_map: region_map, region_paramd_items: region_paramd_items, - node_types: @oldsmallintmap::mk(), + node_types: @mut SmallIntMap::new(), node_type_substs: oldmap::HashMap(), items: amap, intrinsic_defs: oldmap::HashMap(), @@ -2787,8 +2788,8 @@ pub fn br_hashmap() -> HashMap { pub fn node_id_to_type(cx: ctxt, id: ast::node_id) -> t { //io::println(fmt!("%?/%?", id, cx.node_types.len())); - match oldsmallintmap::find(*cx.node_types, id as uint) { - Some(t) => t, + match cx.node_types.find(&(id as uint)) { + Some(&t) => t, None => cx.sess.bug( fmt!("node_id_to_type: no type for node `%s`", ast_map::node_id_to_str(cx.items, id, @@ -3179,8 +3180,8 @@ pub fn expr_kind(tcx: ctxt, } ast::expr_cast(*) => { - match oldsmallintmap::find(*tcx.node_types, expr.id as uint) { - Some(t) => { + match tcx.node_types.find(&(expr.id as uint)) { + Some(&t) => { if ty::type_is_immediate(t) { RvalueDatumExpr } else { diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index f013712595281..b7e1b8a14ec68 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -277,7 +277,7 @@ use core::result; use core::vec; use std::list::Nil; use std::oldmap::HashMap; -use std::oldsmallintmap; +use std::smallintmap::SmallIntMap; use syntax::ast::{ret_style, purity}; use syntax::ast::{m_const, m_imm, m_mutbl}; use syntax::ast::{unsafe_fn, impure_fn, pure_fn, extern_fn}; @@ -353,7 +353,7 @@ pub fn fixup_err_to_str(f: fixup_err) -> ~str { fn new_ValsAndBindings() -> ValsAndBindings { ValsAndBindings { - vals: oldsmallintmap::mk(), + vals: @mut SmallIntMap::new(), bindings: ~[] } } diff --git a/src/librustc/middle/typeck/infer/unify.rs b/src/librustc/middle/typeck/infer/unify.rs index d9b2b73890d42..93c6131d3406a 100644 --- a/src/librustc/middle/typeck/infer/unify.rs +++ b/src/librustc/middle/typeck/infer/unify.rs @@ -10,7 +10,7 @@ use core::prelude::*; use core::result; -use std::oldsmallintmap::SmallIntMap; +use std::smallintmap::SmallIntMap; use middle::ty::{Vid, expected_found, IntVarValue}; use middle::ty; @@ -27,7 +27,7 @@ pub enum VarValue { } pub struct ValsAndBindings { - vals: SmallIntMap>, + vals: @mut SmallIntMap>, bindings: ~[(V, VarValue)], } @@ -64,12 +64,12 @@ pub impl InferCtxt { vid: V) -> Node { let vid_u = vid.to_uint(); - match vb.vals.find(vid_u) { + match vb.vals.find(&vid_u) { None => { tcx.sess.bug(fmt!( "failed lookup of vid `%u`", vid_u)); } - Some(ref var_val) => { + Some(var_val) => { match *var_val { Redirect(vid) => { let node: Node = helper(tcx, vb, vid); @@ -103,8 +103,8 @@ pub impl InferCtxt { { // FIXME(#4903)---borrow checker is not flow sensitive let vb = UnifyVid::appropriate_vals_and_bindings(self); - let old_v = vb.vals.get(vid.to_uint()); - vb.bindings.push((vid, old_v)); + let old_v = vb.vals.get(&vid.to_uint()); + vb.bindings.push((vid, *old_v)); vb.vals.insert(vid.to_uint(), new_v); } } diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 49b818328be06..de3df62d62caf 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -69,7 +69,6 @@ use std::list::{List, Nil, Cons}; use std::list; use std::oldmap::HashMap; use std::oldmap; -use std::oldsmallintmap; use syntax::ast::{provided, required}; use syntax::ast_map::node_id_to_str; use syntax::ast_util::{local_def, split_trait_methods}; diff --git a/src/libstd/oldsmallintmap.rs b/src/libstd/oldsmallintmap.rs deleted file mode 100644 index a31309d7980dc..0000000000000 --- a/src/libstd/oldsmallintmap.rs +++ /dev/null @@ -1,237 +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. - -/*! - * A simple map based on a vector for small integer keys. Space requirements - * are O(highest integer key). - */ -#[forbid(deprecated_mode)]; - -use core::container::{Container, Mutable, Map, Set}; -use core::dvec::DVec; -use core::ops; -use core::option::{Some, None}; -use core::option; -use core::prelude::*; - -// FIXME (#2347): Should not be @; there's a bug somewhere in rustc that -// requires this to be. -struct SmallIntMap_ { - v: DVec>, -} - -pub enum SmallIntMap { - SmallIntMap_(@SmallIntMap_) -} - -/// Create a smallintmap -pub fn mk() -> SmallIntMap { - let v = DVec(); - SmallIntMap_(@SmallIntMap_ { v: v } ) -} - -/** - * Add a value to the map. If the map already contains a value for - * the specified key then the original value is replaced. - */ -#[inline(always)] -pub fn insert(self: SmallIntMap, key: uint, val: T) { - //io::println(fmt!("%?", key)); - self.v.grow_set_elt(key, &None, Some(val)); -} - -/** - * Get the value for the specified key. If the key does not exist - * in the map then returns none - */ -pub pure fn find(self: SmallIntMap, key: uint) -> Option { - if key < self.v.len() { return self.v.get_elt(key); } - return None::; -} - -/** - * Get the value for the specified key - * - * # Failure - * - * If the key does not exist in the map - */ -pub pure fn get(self: SmallIntMap, key: uint) -> T { - match find(self, key) { - None => { - error!("smallintmap::get(): key not present"); - fail!(); - } - Some(v) => return v - } -} - -/// Returns true if the map contains a value for the specified key -pub pure fn contains_key(self: SmallIntMap, key: uint) -> bool { - return !find(self, key).is_none(); -} - -impl Container for SmallIntMap { - /// Return the number of elements in the map - pure fn len(&self) -> uint { - let mut sz = 0u; - for self.v.each |item| { - match *item { - Some(_) => sz += 1u, - _ => () - } - } - sz - } - - /// Return true if the map contains no elements - pure fn is_empty(&self) -> bool { self.len() == 0 } -} - -impl Mutable for SmallIntMap { - fn clear(&mut self) { self.v.set(~[]) } -} - -/// Implements the map::map interface for smallintmap -impl SmallIntMap { - #[inline(always)] - fn insert(key: uint, value: V) -> bool { - let exists = contains_key(self, key); - insert(self, key, value); - return !exists; - } - fn remove(key: uint) -> bool { - if key >= self.v.len() { - return false; - } - let old = self.v.get_elt(key); - self.v.set_elt(key, None); - old.is_some() - } - pure fn contains_key(key: uint) -> bool { - contains_key(self, key) - } - pure fn contains_key_ref(key: &uint) -> bool { - contains_key(self, *key) - } - pure fn get(key: uint) -> V { get(self, key) } - pure fn find(key: uint) -> Option { find(self, key) } - - fn update_with_key(key: uint, val: V, ff: fn(uint, V, V) -> V) -> bool { - match self.find(key) { - None => return self.insert(key, val), - Some(copy orig) => return self.insert(key, ff(key, orig, val)), - } - } - - fn update(key: uint, newval: V, ff: fn(V, V) -> V) -> bool { - return self.update_with_key(key, newval, |_k, v, v1| ff(v,v1)); - } - - pure fn each(it: fn(key: uint, value: V) -> bool) { - self.each_ref(|k, v| it(*k, *v)) - } - pure fn each_key(it: fn(key: uint) -> bool) { - self.each_ref(|k, _v| it(*k)) - } - pure fn each_value(it: fn(value: V) -> bool) { - self.each_ref(|_k, v| it(*v)) - } - pure fn each_ref(it: fn(key: &uint, value: &V) -> bool) { - let mut idx = 0u, l = self.v.len(); - while idx < l { - match self.v.get_elt(idx) { - Some(ref elt) => if !it(&idx, elt) { break }, - None => () - } - idx += 1u; - } - } - pure fn each_key_ref(blk: fn(key: &uint) -> bool) { - self.each_ref(|k, _v| blk(k)) - } - pure fn each_value_ref(blk: fn(value: &V) -> bool) { - self.each_ref(|_k, v| blk(v)) - } -} - -impl ops::Index for SmallIntMap { - pure fn index(&self, key: uint) -> V { - unsafe { - get(*self, key) - } - } -} - -#[cfg(test)] -mod tests { - use super::{mk, SmallIntMap}; - - use core::option::None; - - #[test] - fn test_len() { - let mut map = mk(); - assert map.len() == 0; - assert map.is_empty(); - map.insert(5, 20); - assert map.len() == 1; - assert !map.is_empty(); - map.insert(11, 12); - assert map.len() == 2; - assert !map.is_empty(); - map.insert(14, 22); - assert map.len() == 3; - assert !map.is_empty(); - } - - #[test] - fn test_clear() { - let mut map = mk(); - map.insert(5, 20); - map.insert(11, 12); - map.insert(14, 22); - map.clear(); - assert map.is_empty(); - assert map.find(5).is_none(); - assert map.find(11).is_none(); - assert map.find(14).is_none(); - } - - #[test] - fn test_insert_with_key() { - let map: SmallIntMap = mk(); - - // given a new key, initialize it with this new count, given - // given an existing key, add more to its count - fn addMoreToCount(_k: uint, v0: uint, v1: uint) -> uint { - v0 + v1 - } - - fn addMoreToCount_simple(v0: uint, v1: uint) -> uint { - v0 + v1 - } - - // count integers - map.update(3, 1, addMoreToCount_simple); - map.update_with_key(9, 1, addMoreToCount); - map.update(3, 7, addMoreToCount_simple); - map.update_with_key(5, 3, addMoreToCount); - map.update_with_key(3, 2, addMoreToCount); - - // check the total counts - assert map.find(3).get() == 10; - assert map.find(5).get() == 3; - assert map.find(9).get() == 1; - - // sadly, no sevens were counted - assert None == map.find(7); - } -} diff --git a/src/libstd/std.rc b/src/libstd/std.rc index b0756104fe532..1ece8c17ff7a7 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -75,7 +75,6 @@ pub mod oldmap; pub mod priority_queue; pub mod rope; pub mod smallintmap; -pub mod oldsmallintmap; pub mod sort; pub mod treemap; From a712d828f93ca08c072808d57fb110b1f9d0ca72 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Sat, 23 Feb 2013 17:41:44 -0500 Subject: [PATCH 07/85] libcore: remove default to_str implementations for pointer types These couldn't be overridden and so ended up being quite restrictive. This has the side effect of changing the stringification of ~vecs, but nothing in relied on this. Closes #4869. --- src/libcore/to_str.rs | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/libcore/to_str.rs b/src/libcore/to_str.rs index 0145adc77b826..02192ec344fbb 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -94,15 +94,6 @@ impl ToStr for ~[A] { } } -impl ToStr for @A { - #[inline(always)] - pure fn to_str(&self) -> ~str { ~"@" + (**self).to_str() } -} -impl ToStr for ~A { - #[inline(always)] - pure fn to_str(&self) -> ~str { ~"~" + (**self).to_str() } -} - #[cfg(test)] #[allow(non_implicitly_copyable_typarams)] mod tests { @@ -127,19 +118,12 @@ mod tests { } #[test] - #[ignore] fn test_vectors() { let x: ~[int] = ~[]; - assert x.to_str() == ~"~[]"; - assert (~[1]).to_str() == ~"~[1]"; - assert (~[1, 2, 3]).to_str() == ~"~[1, 2, 3]"; + assert x.to_str() == ~"[]"; + assert (~[1]).to_str() == ~"[1]"; + assert (~[1, 2, 3]).to_str() == ~"[1, 2, 3]"; assert (~[~[], ~[1], ~[1, 1]]).to_str() == - ~"~[~[], ~[1], ~[1, 1]]"; - } - - #[test] - fn test_pointer_types() { - assert (@1).to_str() == ~"@1"; - assert (~(true, false)).to_str() == ~"~(true, false)"; + ~"[[], [1], [1, 1]]"; } } From c4ef822dc7e4fcd05f9e4663e6f5c2196129d605 Mon Sep 17 00:00:00 2001 From: oncemoreification Date: Sat, 23 Feb 2013 21:46:36 -0800 Subject: [PATCH 08/85] Fix slice printing --- src/librustc/util/ppaux.rs | 4 +--- src/test/compile-fail/issue-2149.rs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 924574a4c0c01..a337431cefdb8 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -238,8 +238,7 @@ pub fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str { ty::vstore_fixed(n) => fmt!("%u", n), ty::vstore_uniq => ~"~", ty::vstore_box => ~"@", - /* FIXME(#4517) slice fmt */ - ty::vstore_slice(r) => region_to_str(cx, r) + ty::vstore_slice(r) => region_to_str_adorned(cx, "&", r, "/") } } @@ -248,7 +247,6 @@ pub fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str { ty::vstore_fixed(_) => { fmt!("[%s * %s]", ty, vstore_to_str(cx, vs)) } - /* FIXME(#4517) slice fmt */ ty::vstore_slice(_) => { fmt!("%s/%s", vstore_to_str(cx, vs), ty) } diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index b3820939f8a9e..0880cabb2abf9 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -22,6 +22,6 @@ impl vec_monad for ~[A] { } fn main() { ["hi"].bind(|x| [x] ); - //~^ ERROR type `[&staticstr * 1]` does not implement any method in scope named `bind` + //~^ ERROR type `[&static/str * 1]` does not implement any method in scope named `bind` //~^^ ERROR Unconstrained region variable } From f0d0b5c116eb464544bd48cec116c1ec8908d04d Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 21 Feb 2013 22:48:05 +0900 Subject: [PATCH 09/85] Report error for non constant vector repeat count Fix issue #3645 --- src/librustc/middle/ty.rs | 11 +++++++++-- src/test/compile-fail/repeat_count.rs | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/repeat_count.rs diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 239e86623cabd..298c2c95f46be 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -4289,7 +4289,8 @@ pub fn eval_repeat_count(tcx: ctxt, count_expr: @ast::expr, span: span) -> uint { - match const_eval::eval_const_expr(tcx, count_expr) { + match const_eval::eval_const_expr_partial(tcx, count_expr) { + Ok(ref const_val) => match *const_val { const_eval::const_int(count) => return count as uint, const_eval::const_uint(count) => return count as uint, const_eval::const_float(count) => { @@ -4310,7 +4311,13 @@ pub fn eval_repeat_count(tcx: ctxt, repeat count but found boolean"); return 0; } - + }, + Err(*) => { + tcx.sess.span_err(span, + ~"expected constant integer for repeat count \ + but found variable"); + return 0; + } } } diff --git a/src/test/compile-fail/repeat_count.rs b/src/test/compile-fail/repeat_count.rs new file mode 100644 index 0000000000000..579575e2008f8 --- /dev/null +++ b/src/test/compile-fail/repeat_count.rs @@ -0,0 +1,16 @@ +// Copyright 2013 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. + +// Regression test for issue #3645 + +fn main() { + let n = 1; + let a = ~[0, ..n]; //~ ERROR expected constant integer for repeat count but found variable +} From 4bf94a7b30eeebd820a341890f05e5b709a6d2f2 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Mon, 25 Feb 2013 23:35:48 +1100 Subject: [PATCH 10/85] Emacs: Update emacs mode to be more similar to the vim mode. Copy the keyword list, and add `self` so that it is somewhat highlighted (being liberal with the correct categories). --- src/etc/emacs/rust-mode.el | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el index 5fbd2ab67c29d..5a6acbaddda0a 100644 --- a/src/etc/emacs/rust-mode.el +++ b/src/etc/emacs/rust-mode.el @@ -66,22 +66,17 @@ "trait" "struct" "fn" "enum" "impl")) (puthash word 'def table)) - (dolist (word '("again" "assert" - "break" - "copy" - "do" "drop" - "else" "export" "extern" - "fail" "for" - "if" "use" - "let" "log" "loop" - "move" "new" - "pure" "pub" "priv" - "ref" "return" "static" - "unchecked" "unsafe" - "while")) + (dolist (word '("as" "break" + "copy" "do" "drop" "else" + "extern" "for" "if" "let" "log" + "loop" "once" "priv" "pub" "pure" + "ref" "return" "static" "unsafe" "use" + "while" "while" + "assert" + "mut")) (puthash word t table)) (puthash "match" 'alt table) - (dolist (word '("true" "false")) (puthash word 'atom table)) + (dolist (word '("self" "true" "false")) (puthash word 'atom table)) table)) ;; FIXME type-context keywords From b8dd2d8c67907f61a985e4200d46249211b0306d Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 25 Feb 2013 16:34:38 +0100 Subject: [PATCH 11/85] Fix typo in grammar: underscore, not minus, can appear amongst hex digits. --- doc/rust.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/rust.md b/doc/rust.md index 975e4bbb8a209..10fb203d022d6 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -297,7 +297,7 @@ the following forms: num_lit : nonzero_dec [ dec_digit | '_' ] * num_suffix ? | '0' [ [ dec_digit | '_' ] + num_suffix ? | 'b' [ '1' | '0' | '_' ] + int_suffix ? - | 'x' [ hex_digit | '-' ] + int_suffix ? ] ; + | 'x' [ hex_digit | '_' ] + int_suffix ? ] ; num_suffix : int_suffix | float_suffix ; From a08eda4b6318af0df153322d10d9b907b13d0cdc Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Feb 2013 15:14:33 -0800 Subject: [PATCH 12/85] test: Residual de-muting of the test suite. rs=demuting --- src/test/auxiliary/cci_class.rs | 2 +- src/test/auxiliary/cci_class_2.rs | 2 +- src/test/auxiliary/cci_class_3.rs | 6 +-- src/test/auxiliary/cci_class_4.rs | 27 ++++++----- src/test/auxiliary/cci_class_6.rs | 8 ++-- src/test/auxiliary/cci_class_cast.rs | 10 ++--- src/test/auxiliary/cci_class_trait.rs | 2 +- src/test/run-pass/class-cast-to-trait.rs | 16 +++---- .../class-impl-very-parameterized-trait.rs | 13 +++--- .../class-implement-trait-cross-crate.rs | 42 +++++++++-------- src/test/run-pass/class-implement-traits.rs | 45 +++++++++---------- .../run-pass/class-methods-cross-crate.rs | 12 ++--- src/test/run-pass/class-methods.rs | 13 +++--- .../class-poly-methods-cross-crate.rs | 4 +- src/test/run-pass/class-poly-methods.rs | 18 ++++---- src/test/run-pass/class-separate-impl.rs | 43 +++++++++--------- src/test/run-pass/class-typarams.rs | 14 +++--- src/test/run-pass/classes-cross-crate.rs | 10 ++--- src/test/run-pass/classes-simple-method.rs | 10 ++--- src/test/run-pass/classes-simple.rs | 9 ++-- src/test/run-pass/classes.rs | 44 +++++++++--------- src/test/run-pass/private-class-field.rs | 10 ++--- 22 files changed, 174 insertions(+), 186 deletions(-) diff --git a/src/test/auxiliary/cci_class.rs b/src/test/auxiliary/cci_class.rs index 3d39aeffa0a07..e27fc68df9cc0 100644 --- a/src/test/auxiliary/cci_class.rs +++ b/src/test/auxiliary/cci_class.rs @@ -10,7 +10,7 @@ pub mod kitties { pub struct cat { - priv mut meows : uint, + priv meows : uint, how_hungry : int, } diff --git a/src/test/auxiliary/cci_class_2.rs b/src/test/auxiliary/cci_class_2.rs index 47cbed741cdd4..b955ed9c2a7f0 100644 --- a/src/test/auxiliary/cci_class_2.rs +++ b/src/test/auxiliary/cci_class_2.rs @@ -10,7 +10,7 @@ pub mod kitties { pub struct cat { - priv mut meows : uint, + priv meows : uint, how_hungry : int, diff --git a/src/test/auxiliary/cci_class_3.rs b/src/test/auxiliary/cci_class_3.rs index ae224684c8454..a516f5398df62 100644 --- a/src/test/auxiliary/cci_class_3.rs +++ b/src/test/auxiliary/cci_class_3.rs @@ -10,14 +10,14 @@ pub mod kitties { pub struct cat { - priv mut meows : uint, + priv meows : uint, how_hungry : int, } pub impl cat { - fn speak() { self.meows += 1u; } - fn meow_count() -> uint { self.meows } + fn speak(&mut self) { self.meows += 1u; } + fn meow_count(&mut self) -> uint { self.meows } } pub fn cat(in_x : uint, in_y : int) -> cat { diff --git a/src/test/auxiliary/cci_class_4.rs b/src/test/auxiliary/cci_class_4.rs index 127562309ce8c..68143b32741c8 100644 --- a/src/test/auxiliary/cci_class_4.rs +++ b/src/test/auxiliary/cci_class_4.rs @@ -10,30 +10,29 @@ pub mod kitties { pub struct cat { - priv mut meows : uint, + priv meows : uint, - mut how_hungry : int, + how_hungry : int, name : ~str, } pub impl cat { - fn speak() { self.meow(); } + fn speak(&mut self) { self.meow(); } - fn eat() -> bool { - if self.how_hungry > 0 { - error!("OM NOM NOM"); - self.how_hungry -= 2; - return true; - } - else { - error!("Not hungry!"); - return false; + fn eat(&mut self) -> bool { + if self.how_hungry > 0 { + error!("OM NOM NOM"); + self.how_hungry -= 2; + return true; + } else { + error!("Not hungry!"); + return false; + } } - } } pub impl cat { - fn meow() { + fn meow(&mut self) { error!("Meow"); self.meows += 1u; if self.meows % 5u == 0u { diff --git a/src/test/auxiliary/cci_class_6.rs b/src/test/auxiliary/cci_class_6.rs index 3ab101bc0b4e8..ceccea409c44a 100644 --- a/src/test/auxiliary/cci_class_6.rs +++ b/src/test/auxiliary/cci_class_6.rs @@ -10,17 +10,17 @@ pub mod kitties { pub struct cat { - priv mut info : ~[U], - priv mut meows : uint, + priv info : ~[U], + priv meows : uint, how_hungry : int, } pub impl cat { - fn speak(stuff: ~[T]) { + fn speak(&mut self, stuff: ~[T]) { self.meows += stuff.len(); } - fn meow_count() -> uint { self.meows } + fn meow_count(&mut self) -> uint { self.meows } } pub fn cat(in_x : uint, in_y : int, -in_info: ~[U]) -> cat { diff --git a/src/test/auxiliary/cci_class_cast.rs b/src/test/auxiliary/cci_class_cast.rs index 5256944b18ecb..a2896dad814c2 100644 --- a/src/test/auxiliary/cci_class_cast.rs +++ b/src/test/auxiliary/cci_class_cast.rs @@ -12,8 +12,8 @@ use core::to_str::*; pub mod kitty { pub struct cat { - priv mut meows : uint, - mut how_hungry : int, + priv meows : uint, + how_hungry : int, name : ~str, } @@ -22,7 +22,7 @@ pub mod kitty { } priv impl cat { - fn meow() { + fn meow(&mut self) { error!("Meow"); self.meows += 1u; if self.meows % 5u == 0u { @@ -33,9 +33,9 @@ pub mod kitty { } pub impl cat { - fn speak() { self.meow(); } + fn speak(&mut self) { self.meow(); } - fn eat() -> bool { + fn eat(&mut self) -> bool { if self.how_hungry > 0 { error!("OM NOM NOM"); self.how_hungry -= 2; diff --git a/src/test/auxiliary/cci_class_trait.rs b/src/test/auxiliary/cci_class_trait.rs index 0363e1afd6086..7ca3d7c4ac990 100644 --- a/src/test/auxiliary/cci_class_trait.rs +++ b/src/test/auxiliary/cci_class_trait.rs @@ -10,6 +10,6 @@ pub mod animals { pub trait noisy { - fn speak(); + fn speak(&mut self); } } diff --git a/src/test/run-pass/class-cast-to-trait.rs b/src/test/run-pass/class-cast-to-trait.rs index cb2e56d7f6e1a..157ea586c2c4e 100644 --- a/src/test/run-pass/class-cast-to-trait.rs +++ b/src/test/run-pass/class-cast-to-trait.rs @@ -9,21 +9,21 @@ // except according to those terms. trait noisy { - fn speak(); + fn speak(&mut self); } struct cat { - priv mut meows : uint, - mut how_hungry : int, - name : ~str, + priv meows: uint, + how_hungry: int, + name: ~str, } impl noisy for cat { - fn speak() { self.meow(); } + fn speak(&mut self) { self.meow(); } } impl cat { - fn eat() -> bool { + fn eat(&mut self) -> bool { if self.how_hungry > 0 { error!("OM NOM NOM"); self.how_hungry -= 2; @@ -37,7 +37,7 @@ impl cat { } priv impl cat { - fn meow() { + fn meow(&mut self) { error!("Meow"); self.meows += 1u; if self.meows % 5u == 0u { @@ -56,6 +56,6 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { pub fn main() { - let nyan : noisy = cat(0u, 2, ~"nyan") as noisy; + let mut nyan: noisy = cat(0u, 2, ~"nyan") as noisy; nyan.speak(); } diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs index 09cf008fd099a..40f728d40bfe3 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -28,9 +28,9 @@ impl cmp::Eq for cat_type { // ok: T should be in scope when resolving the trait ref for map struct cat { // Yes, you can have negative meows - priv mut meows : int, + priv meows : int, - mut how_hungry : int, + how_hungry : int, name : T, } @@ -95,11 +95,10 @@ impl Map for cat { } fn remove(&mut self, k: &int) -> bool { - match self.find(k) { - Some(_) => { - self.meows -= *k; true - } - None => { false } + if self.find(k).is_some() { + self.meows -= *k; true + } else { + false } } } diff --git a/src/test/run-pass/class-implement-trait-cross-crate.rs b/src/test/run-pass/class-implement-trait-cross-crate.rs index 155090b44dfc3..aa7bb738bf54f 100644 --- a/src/test/run-pass/class-implement-trait-cross-crate.rs +++ b/src/test/run-pass/class-implement-trait-cross-crate.rs @@ -14,39 +14,37 @@ extern mod cci_class_trait; use cci_class_trait::animals::*; struct cat { - priv mut meows : uint, + priv meows: uint, - mut how_hungry : int, + how_hungry : int, name : ~str, } impl cat { - fn eat() -> bool { - if self.how_hungry > 0 { - error!("OM NOM NOM"); - self.how_hungry -= 2; - return true; + fn eat(&mut self) -> bool { + if self.how_hungry > 0 { + error!("OM NOM NOM"); + self.how_hungry -= 2; + return true; + } + else { + error!("Not hungry!"); + return false; + } } - else { - error!("Not hungry!"); - return false; - } - } } impl noisy for cat { - - fn speak() { self.meow(); } - + fn speak(&mut self) { self.meow(); } } priv impl cat { - fn meow() { - error!("Meow"); - self.meows += 1u; - if self.meows % 5u == 0u { - self.how_hungry += 1; - } + fn meow(&mut self) { + error!("Meow"); + self.meows += 1u; + if self.meows % 5u == 0u { + self.how_hungry += 1; + } } } @@ -60,7 +58,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { pub fn main() { - let nyan = cat(0u, 2, ~"nyan"); + let mut nyan = cat(0u, 2, ~"nyan"); nyan.eat(); assert(!nyan.eat()); for uint::range(1u, 10u) |_i| { nyan.speak(); }; diff --git a/src/test/run-pass/class-implement-traits.rs b/src/test/run-pass/class-implement-traits.rs index 15564d73e1f70..bdc8f7568a165 100644 --- a/src/test/run-pass/class-implement-traits.rs +++ b/src/test/run-pass/class-implement-traits.rs @@ -12,42 +12,41 @@ #[legacy_modes]; trait noisy { - fn speak(); + fn speak(&mut self); } struct cat { - priv mut meows : uint, + priv meows : uint, - mut how_hungry : int, - name : ~str, + how_hungry : int, + name : ~str, } priv impl cat { - fn meow() { - error!("Meow"); - self.meows += 1u; - if self.meows % 5u == 0u { - self.how_hungry += 1; - } + fn meow(&mut self) { + error!("Meow"); + self.meows += 1u; + if self.meows % 5u == 0u { + self.how_hungry += 1; + } } } impl cat { - fn eat() -> bool { - if self.how_hungry > 0 { - error!("OM NOM NOM"); - self.how_hungry -= 2; - return true; + fn eat(&mut self) -> bool { + if self.how_hungry > 0 { + error!("OM NOM NOM"); + self.how_hungry -= 2; + return true; + } else { + error!("Not hungry!"); + return false; + } } - else { - error!("Not hungry!"); - return false; - } - } } impl noisy for cat { - fn speak() { self.meow(); } + fn speak(&mut self) { self.meow(); } } fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { @@ -59,12 +58,12 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { } -fn make_speak(c: C) { +fn make_speak(mut c: C) { c.speak(); } pub fn main() { - let nyan = cat(0u, 2, ~"nyan"); + let mut nyan = cat(0u, 2, ~"nyan"); nyan.eat(); assert(!nyan.eat()); for uint::range(1u, 10u) |_i| { make_speak(nyan); }; diff --git a/src/test/run-pass/class-methods-cross-crate.rs b/src/test/run-pass/class-methods-cross-crate.rs index b555abb6ec5c1..fc5191e522d76 100644 --- a/src/test/run-pass/class-methods-cross-crate.rs +++ b/src/test/run-pass/class-methods-cross-crate.rs @@ -14,10 +14,10 @@ extern mod cci_class_3; use cci_class_3::kitties::*; pub fn main() { - let nyan : cat = cat(52u, 99); - let kitty = cat(1000u, 2); - assert(nyan.how_hungry == 99); - assert(kitty.how_hungry == 2); - nyan.speak(); - assert(nyan.meow_count() == 53u); + let mut nyan : cat = cat(52u, 99); + let mut kitty = cat(1000u, 2); + assert(nyan.how_hungry == 99); + assert(kitty.how_hungry == 2); + nyan.speak(); + assert(nyan.meow_count() == 53u); } diff --git a/src/test/run-pass/class-methods.rs b/src/test/run-pass/class-methods.rs index fa43968da0a62..1e41b60a8223e 100644 --- a/src/test/run-pass/class-methods.rs +++ b/src/test/run-pass/class-methods.rs @@ -9,18 +9,17 @@ // except according to those terms. struct cat { - priv mut meows : uint, + priv meows : uint, how_hungry : int, } impl cat { - - fn speak() { self.meows += 1u; } - fn meow_count() -> uint { self.meows } + fn speak(&mut self) { self.meows += 1u; } + fn meow_count(&mut self) -> uint { self.meows } } -fn cat(in_x : uint, in_y : int) -> cat { +fn cat(in_x: uint, in_y: int) -> cat { cat { meows: in_x, how_hungry: in_y @@ -28,8 +27,8 @@ fn cat(in_x : uint, in_y : int) -> cat { } pub fn main() { - let nyan : cat = cat(52u, 99); - let kitty = cat(1000u, 2); + let mut nyan: cat = cat(52u, 99); + let mut kitty = cat(1000u, 2); assert(nyan.how_hungry == 99); assert(kitty.how_hungry == 2); nyan.speak(); diff --git a/src/test/run-pass/class-poly-methods-cross-crate.rs b/src/test/run-pass/class-poly-methods-cross-crate.rs index b0f5b916dd4e8..a96a1920d9233 100644 --- a/src/test/run-pass/class-poly-methods-cross-crate.rs +++ b/src/test/run-pass/class-poly-methods-cross-crate.rs @@ -14,8 +14,8 @@ extern mod cci_class_6; use cci_class_6::kitties::*; pub fn main() { - let nyan : cat = cat::(52u, 99, ~['p']); - let kitty = cat(1000u, 2, ~[~"tabby"]); + let mut nyan : cat = cat::(52u, 99, ~['p']); + let mut kitty = cat(1000u, 2, ~[~"tabby"]); assert(nyan.how_hungry == 99); assert(kitty.how_hungry == 2); nyan.speak(~[1u,2u,3u]); diff --git a/src/test/run-pass/class-poly-methods.rs b/src/test/run-pass/class-poly-methods.rs index 5ef5e55b7293e..e81d07a783b99 100644 --- a/src/test/run-pass/class-poly-methods.rs +++ b/src/test/run-pass/class-poly-methods.rs @@ -9,17 +9,17 @@ // except according to those terms. struct cat { - priv mut info : ~[U], - priv mut meows : uint, + priv info : ~[U], + priv meows : uint, - how_hungry : int, + how_hungry : int, } impl cat { - fn speak(stuff: ~[T]) { - self.meows += stuff.len(); - } - fn meow_count() -> uint { self.meows } + fn speak(&mut self, stuff: ~[T]) { + self.meows += stuff.len(); + } + fn meow_count(&mut self) -> uint { self.meows } } fn cat(in_x : uint, in_y : int, -in_info: ~[U]) -> cat { @@ -31,8 +31,8 @@ fn cat(in_x : uint, in_y : int, -in_info: ~[U]) -> cat { } pub fn main() { - let nyan : cat = cat::(52u, 99, ~[9]); - let kitty = cat(1000u, 2, ~[~"tabby"]); + let mut nyan : cat = cat::(52u, 99, ~[9]); + let mut kitty = cat(1000u, 2, ~[~"tabby"]); assert(nyan.how_hungry == 99); assert(kitty.how_hungry == 2); nyan.speak(~[1,2,3]); diff --git a/src/test/run-pass/class-separate-impl.rs b/src/test/run-pass/class-separate-impl.rs index fda358a86a2f5..9c7d9ce7415a4 100644 --- a/src/test/run-pass/class-separate-impl.rs +++ b/src/test/run-pass/class-separate-impl.rs @@ -12,36 +12,35 @@ use core::to_str::*; struct cat { - priv mut meows : uint, + priv meows : uint, - mut how_hungry : int, - name : ~str, + how_hungry : int, + name : ~str, } impl cat { + fn speak(&mut self) { self.meow(); } - fn speak() { self.meow(); } - - fn eat() -> bool { - if self.how_hungry > 0 { - error!("OM NOM NOM"); - self.how_hungry -= 2; - return true; - } - else { - error!("Not hungry!"); - return false; + fn eat(&mut self) -> bool { + if self.how_hungry > 0 { + error!("OM NOM NOM"); + self.how_hungry -= 2; + return true; + } + else { + error!("Not hungry!"); + return false; + } } - } } priv impl cat { - fn meow() { - error!("Meow"); - self.meows += 1u; - if self.meows % 5u == 0u { - self.how_hungry += 1; - } + fn meow(&mut self) { + error!("Meow"); + self.meows += 1u; + if self.meows % 5u == 0u { + self.how_hungry += 1; + } } } @@ -64,6 +63,6 @@ fn print_out(thing: T, expected: ~str) { } pub fn main() { - let nyan : ToStr = cat(0u, 2, ~"nyan") as ToStr; + let mut nyan : ToStr = cat(0u, 2, ~"nyan") as ToStr; print_out(nyan, ~"nyan"); } diff --git a/src/test/run-pass/class-typarams.rs b/src/test/run-pass/class-typarams.rs index b8d0e59328623..cbc69719caa62 100644 --- a/src/test/run-pass/class-typarams.rs +++ b/src/test/run-pass/class-typarams.rs @@ -9,16 +9,14 @@ // except according to those terms. struct cat { - priv mut meows : uint, + priv meows : uint, - how_hungry : int, + how_hungry : int, } impl cat { - fn speak() { - self.meows += 1u; - } - fn meow_count() -> uint { self.meows } + fn speak(&mut self) { self.meows += 1u; } + fn meow_count(&mut self) -> uint { self.meows } } fn cat(in_x : uint, in_y : int) -> cat { @@ -30,6 +28,6 @@ fn cat(in_x : uint, in_y : int) -> cat { pub fn main() { - let _nyan : cat = cat::(52u, 99); - // let kitty = cat(1000u, 2); + let mut _nyan : cat = cat::(52u, 99); + // let mut kitty = cat(1000u, 2); } diff --git a/src/test/run-pass/classes-cross-crate.rs b/src/test/run-pass/classes-cross-crate.rs index d40f948431e25..2ab6ce01b2432 100644 --- a/src/test/run-pass/classes-cross-crate.rs +++ b/src/test/run-pass/classes-cross-crate.rs @@ -14,9 +14,9 @@ extern mod cci_class_4; use cci_class_4::kitties::*; pub fn main() { - let nyan = cat(0u, 2, ~"nyan"); - nyan.eat(); - assert(!nyan.eat()); - for uint::range(1u, 10u) |_i| { nyan.speak(); }; - assert(nyan.eat()); + let mut nyan = cat(0u, 2, ~"nyan"); + nyan.eat(); + assert(!nyan.eat()); + for uint::range(1u, 10u) |_i| { nyan.speak(); }; + assert(nyan.eat()); } diff --git a/src/test/run-pass/classes-simple-method.rs b/src/test/run-pass/classes-simple-method.rs index f44ee4bd502a6..ac80ca9b9e930 100644 --- a/src/test/run-pass/classes-simple-method.rs +++ b/src/test/run-pass/classes-simple-method.rs @@ -9,13 +9,13 @@ // except according to those terms. struct cat { - priv mut meows : uint, + priv meows : uint, - how_hungry : int, + how_hungry : int, } impl cat { - fn speak() {} + fn speak(&mut self) {} } fn cat(in_x : uint, in_y : int) -> cat { @@ -26,8 +26,8 @@ fn cat(in_x : uint, in_y : int) -> cat { } pub fn main() { - let nyan : cat = cat(52u, 99); - let kitty = cat(1000u, 2); + let mut nyan : cat = cat(52u, 99); + let mut kitty = cat(1000u, 2); assert(nyan.how_hungry == 99); assert(kitty.how_hungry == 2); nyan.speak(); diff --git a/src/test/run-pass/classes-simple.rs b/src/test/run-pass/classes-simple.rs index 3520719d4996c..b17e81160e510 100644 --- a/src/test/run-pass/classes-simple.rs +++ b/src/test/run-pass/classes-simple.rs @@ -9,10 +9,9 @@ // except according to those terms. struct cat { - priv mut meows : uint, - - how_hungry : int, + priv meows : uint, + how_hungry : int, } fn cat(in_x : uint, in_y : int) -> cat { @@ -23,8 +22,8 @@ fn cat(in_x : uint, in_y : int) -> cat { } pub fn main() { - let nyan : cat = cat(52u, 99); - let kitty = cat(1000u, 2); + let mut nyan : cat = cat(52u, 99); + let mut kitty = cat(1000u, 2); assert(nyan.how_hungry == 99); assert(kitty.how_hungry == 2); } diff --git a/src/test/run-pass/classes.rs b/src/test/run-pass/classes.rs index 808b7cac501a6..552715dccb445 100644 --- a/src/test/run-pass/classes.rs +++ b/src/test/run-pass/classes.rs @@ -9,36 +9,34 @@ // except according to those terms. struct cat { - priv mut meows : uint, + priv meows : uint, - mut how_hungry : int, - name : ~str, + how_hungry : int, + name : ~str, } impl cat { - - fn speak() { self.meow(); } - - fn eat() -> bool { - if self.how_hungry > 0 { - error!("OM NOM NOM"); - self.how_hungry -= 2; - return true; - } - else { - error!("Not hungry!"); - return false; + fn speak(&mut self) { self.meow(); } + + fn eat(&mut self) -> bool { + if self.how_hungry > 0 { + error!("OM NOM NOM"); + self.how_hungry -= 2; + return true; + } else { + error!("Not hungry!"); + return false; + } } - } } priv impl cat { - fn meow() { - error!("Meow"); - self.meows += 1u; - if self.meows % 5u == 0u { - self.how_hungry += 1; - } + fn meow(&mut self) { + error!("Meow"); + self.meows += 1u; + if self.meows % 5u == 0u { + self.how_hungry += 1; + } } } @@ -51,7 +49,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat { } pub fn main() { - let nyan = cat(0u, 2, ~"nyan"); + let mut nyan = cat(0u, 2, ~"nyan"); nyan.eat(); assert(!nyan.eat()); for uint::range(1u, 10u) |_i| { nyan.speak(); }; diff --git a/src/test/run-pass/private-class-field.rs b/src/test/run-pass/private-class-field.rs index 3be87fd5047ca..9cb86ffe83707 100644 --- a/src/test/run-pass/private-class-field.rs +++ b/src/test/run-pass/private-class-field.rs @@ -9,13 +9,13 @@ // except according to those terms. struct cat { - priv mut meows : uint, + priv meows : uint, - how_hungry : int, + how_hungry : int, } impl cat { - fn meow_count() -> uint { self.meows } + fn meow_count(&mut self) -> uint { self.meows } } fn cat(in_x : uint, in_y : int) -> cat { @@ -26,6 +26,6 @@ fn cat(in_x : uint, in_y : int) -> cat { } pub fn main() { - let nyan : cat = cat(52u, 99); - assert (nyan.meow_count() == 52u); + let mut nyan : cat = cat(52u, 99); + assert (nyan.meow_count() == 52u); } From f63efdc2100ff28e2a42600641835e7bd8bde591 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Feb 2013 14:04:32 -0800 Subject: [PATCH 13/85] test: De-~mut the test suite. rs=demuting --- src/test/bench/msgsend-ring-mutex-arcs.rs | 17 ++++++--------- src/test/bench/msgsend-ring-pipes.rs | 20 +++++++----------- src/test/bench/msgsend-ring-rw-arcs.rs | 17 ++++++--------- .../bench/task-perf-jargon-metal-smoke.rs | 8 ++++--- .../compile-fail/mutable-huh-variance-deep.rs | 4 ++-- .../mutable-huh-variance-unique.rs | 21 ------------------- src/test/compile-fail/no-send-res-ports.rs | 7 ++++--- src/test/compile-fail/unique-mut.rs | 14 ------------- .../run-pass/borrowck-preserve-box-in-uniq.rs | 2 +- src/test/run-pass/explicit-self-closures.rs | 3 --- src/test/run-pass/intrinsic-atomics.rs | 2 +- src/test/run-pass/issue-2718.rs | 14 ++++++------- src/test/run-pass/pipe-pingpong-bounded.rs | 19 ++++++++--------- src/test/run-pass/pipe-pingpong-proto.rs | 19 ++++++++--------- src/test/run-pass/pure-sum.rs | 4 ++-- src/test/run-pass/rcvr-borrowed-to-region.rs | 2 +- src/test/run-pass/task-killjoin-rsrc.rs | 7 +++---- src/test/run-pass/unique-assign-copy.rs | 2 +- src/test/run-pass/unique-decl-init-copy.rs | 2 +- src/test/run-pass/unique-in-vec-copy.rs | 2 +- src/test/run-pass/unique-mutable.rs | 2 +- 21 files changed, 67 insertions(+), 121 deletions(-) delete mode 100644 src/test/compile-fail/mutable-huh-variance-unique.rs delete mode 100644 src/test/compile-fail/unique-mut.rs diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 9b6fee5e23bc1..22045007134a0 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -87,17 +87,12 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = ~mut None; - *num_chan2 <-> num_chan; - let num_port = ~mut Some(num_port); - let new_future = do future::spawn() || { - let mut num_chan = None; - num_chan <-> *num_chan2; - let mut num_port1 = None; - num_port1 <-> *num_port; - thread_ring(i, msg_per_task, - option::unwrap(num_chan), - option::unwrap(num_port1)) + let num_chan2 = Cell(num_chan); + let num_port = Cell(num_port); + let new_future = do future::spawn() { + let num_chan = num_chan2.take(); + let num_port1 = num_port.take(); + thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); num_chan = Some(new_chan); diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index 0f7c41f5997a8..dfe5c6de832c1 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -17,10 +17,11 @@ // This version uses automatically compiled channel contracts. extern mod std; -use std::time; -use std::future; +use core::cell::Cell; use core::pipes::recv; +use std::time; +use std::future; proto! ring ( num:send { @@ -80,17 +81,12 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = ring::init(); - let num_chan2 = ~mut None; - *num_chan2 <-> num_chan; - let num_port = ~mut Some(num_port); + let num_chan2 = Cell(num_chan); + let num_port = Cell(num_port); let new_future = do future::spawn || { - let mut num_chan = None; - num_chan <-> *num_chan2; - let mut num_port1 = None; - num_port1 <-> *num_port; - thread_ring(i, msg_per_task, - option::unwrap(num_chan), - option::unwrap(num_port1)) + let num_chan = num_chan2.take(); + let num_port1 = num_port.take(); + thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); num_chan = Some(new_chan); diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index eaae8370d6b8b..98c0129918a47 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -87,17 +87,12 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = ~mut None; - *num_chan2 <-> num_chan; - let num_port = ~mut Some(num_port); - let new_future = do future::spawn || { - let mut num_chan = None; - num_chan <-> *num_chan2; - let mut num_port1 = None; - num_port1 <-> *num_port; - thread_ring(i, msg_per_task, - option::unwrap(num_chan), - option::unwrap(num_port1)) + let num_chan2 = Cell(num_chan); + let num_port = Cell(num_port); + let new_future = do future::spawn { + let num_chan = num_chan2.take(); + let num_port1 = num_port.take(); + thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); num_chan = Some(new_chan); diff --git a/src/test/bench/task-perf-jargon-metal-smoke.rs b/src/test/bench/task-perf-jargon-metal-smoke.rs index 49a06fd491cd0..9bdc5aae3f283 100644 --- a/src/test/bench/task-perf-jargon-metal-smoke.rs +++ b/src/test/bench/task-perf-jargon-metal-smoke.rs @@ -17,13 +17,15 @@ // // The filename is a song reference; google it in quotes. +use core::cell::Cell; + fn child_generation(gens_left: uint, -c: comm::Chan<()>) { // This used to be O(n^2) in the number of generations that ever existed. // With this code, only as many generations are alive at a time as tasks // alive at a time, - let c = ~mut Some(c); - do task::spawn_supervised || { - let c = option::swap_unwrap(c); + let c = Cell(c); + do task::spawn_supervised { + let c = c.take(); if gens_left & 1 == 1 { task::yield(); // shake things up a bit } diff --git a/src/test/compile-fail/mutable-huh-variance-deep.rs b/src/test/compile-fail/mutable-huh-variance-deep.rs index 4f0c6d7a4c87d..51d5a6177f6aa 100644 --- a/src/test/compile-fail/mutable-huh-variance-deep.rs +++ b/src/test/compile-fail/mutable-huh-variance-deep.rs @@ -11,9 +11,9 @@ // error-pattern: mismatched types fn main() { - let v = ~[mut @mut ~mut ~[0]]; + let v = @[mut @mut @mut @[0]]; - fn f(&&v: ~[mut @mut ~mut ~[const int]]) { + fn f(&&v: @[mut @mut @mut @[const int]]) { } f(v); diff --git a/src/test/compile-fail/mutable-huh-variance-unique.rs b/src/test/compile-fail/mutable-huh-variance-unique.rs deleted file mode 100644 index f2188911346e9..0000000000000 --- a/src/test/compile-fail/mutable-huh-variance-unique.rs +++ /dev/null @@ -1,21 +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. - -// error-pattern: mismatched types - -fn main() { - let v = ~mut ~[0]; - - fn f(&&v: ~mut ~[const int]) { - *v = ~[mut 3] - } - - f(v); -} diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index 4954bbfa09d06..0d7e2d2377c20 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use core::cell::Cell; + struct Port(@T); fn main() { @@ -25,11 +27,10 @@ fn main() { } } - let x = ~mut Some(foo(Port(@()))); + let x = Cell(foo(Port(@()))); do task::spawn { - let mut y = None; - *x <-> y; //~ ERROR value has non-owned type + let y = x.take(); //~ ERROR value has non-owned type log(error, y); } } diff --git a/src/test/compile-fail/unique-mut.rs b/src/test/compile-fail/unique-mut.rs deleted file mode 100644 index a3a197505a340..0000000000000 --- a/src/test/compile-fail/unique-mut.rs +++ /dev/null @@ -1,14 +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. - -//error-pattern:mismatched types -fn main() { - let i: ~int = ~mut 0; -} diff --git a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs index 9724717f2d580..b11a5356f698c 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs @@ -20,7 +20,7 @@ fn borrow(x: &int, f: fn(x: &int)) { struct F { f: ~int } pub fn main() { - let mut x = ~mut @F{f: ~3}; + let mut x = ~@F{f: ~3}; do borrow(x.f) |b_x| { assert *b_x == 3; assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)); diff --git a/src/test/run-pass/explicit-self-closures.rs b/src/test/run-pass/explicit-self-closures.rs index 4c12b6ad47c2f..d40b2f72ae8ba 100644 --- a/src/test/run-pass/explicit-self-closures.rs +++ b/src/test/run-pass/explicit-self-closures.rs @@ -21,9 +21,6 @@ impl Box { fn set_many2(@mut self, xs: &[uint]) { for xs.each |x| { self.x = *x; } } - fn set_many3(~mut self, xs: &[uint]) { - for xs.each |x| { self.x = *x; } - } } pub fn main() {} diff --git a/src/test/run-pass/intrinsic-atomics.rs b/src/test/run-pass/intrinsic-atomics.rs index eb10a51c0bd65..7d5bf65dad7c1 100644 --- a/src/test/run-pass/intrinsic-atomics.rs +++ b/src/test/run-pass/intrinsic-atomics.rs @@ -29,7 +29,7 @@ extern mod rusti { pub fn main() { unsafe { - let x = ~mut 1; + let mut x = ~1; assert rusti::atomic_cxchg(x, 1, 2) == 1; assert *x == 2; diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 249d1c21376bd..b97ebb04f716d 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -318,18 +318,16 @@ pub fn main() { // Commented out because of option::get error let (client_, server_) = pingpong::init(); - let client_ = ~mut Some(client_); - let server_ = ~mut Some(server_); + let client_ = Cell(client_); + let server_ = Cell(server_); task::spawn {|client_| - let mut client__ = none; - *client_ <-> client__; - client(option::unwrap(client__)); + let client__ = client_.take(); + client(client__); }; task::spawn {|server_| - let mut server_ËŠ = none; - *server_ <-> server_ËŠ; - server(option::unwrap(server_ËŠ)); + let server__ = server_.take(); + server(server_ËŠ); }; */ } diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index 2ada6df76a6a8..23f2bc10046b2 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -14,6 +14,7 @@ // experiment with what code the compiler should generate for bounded // protocols. +use core::cell::Cell; // This was generated initially by the pipe compiler, but it's been // modified in hopefully straightforward ways. @@ -111,16 +112,14 @@ mod test { pub fn main() { let (client_, server_) = ::pingpong::init(); - let client_ = ~mut Some(client_); - let server_ = ~mut Some(server_); - do task::spawn || { - let mut client__ = None; - *client_ <-> client__; - test::client(option::unwrap(client__)); + let client_ = Cell(client_); + let server_ = Cell(server_); + do task::spawn { + let client__ = client_.take(); + test::client(client__); }; - do task::spawn || { - let mut server_ËŠ = None; - *server_ <-> server_ËŠ; - test::server(option::unwrap(server_ËŠ)); + do task::spawn { + let server__ = server_.take(); + test::server(server_ËŠ); }; } diff --git a/src/test/run-pass/pipe-pingpong-proto.rs b/src/test/run-pass/pipe-pingpong-proto.rs index 050ff76ef9b75..a4a1c562bcaff 100644 --- a/src/test/run-pass/pipe-pingpong-proto.rs +++ b/src/test/run-pass/pipe-pingpong-proto.rs @@ -12,6 +12,7 @@ // An example to make sure the protocol parsing syntax extension works. +use core::cell::Cell; use core::option; proto! pingpong ( @@ -49,17 +50,15 @@ mod test { pub fn main() { let (client_, server_) = pingpong::init(); - let client_ = ~mut Some(client_); - let server_ = ~mut Some(server_); + let client_ = Cell(client_); + let server_ = Cell(server_); - do task::spawn || { - let mut client__ = None; - *client_ <-> client__; - test::client(option::unwrap(client__)); + do task::spawn { + let client__ = client_.take(); + test::client(client__); }; - do task::spawn || { - let mut server_ËŠ = None; - *server_ <-> server_ËŠ; - test::server(option::unwrap(server_ËŠ)); + do task::spawn { + let server__ = server_.take(); + test::server(server_ËŠ); }; } diff --git a/src/test/run-pass/pure-sum.rs b/src/test/run-pass/pure-sum.rs index f4c92c869e46e..cac6b4ef34932 100644 --- a/src/test/run-pass/pure-sum.rs +++ b/src/test/run-pass/pure-sum.rs @@ -20,7 +20,7 @@ pure fn sums_to(v: ~[int], sum: int) -> bool { } pure fn sums_to_using_uniq(v: ~[int], sum: int) -> bool { - let mut i = 0u, sum0 = ~mut 0; + let mut i = 0u, sum0 = ~0; while i < v.len() { *sum0 += v[i]; i += 1u; @@ -40,7 +40,7 @@ pure fn sums_to_using_rec(v: ~[int], sum: int) -> bool { struct F { f: T } pure fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool { - let mut i = 0u, sum0 = F {f: ~mut 0}; + let mut i = 0u, sum0 = F {f: ~0}; while i < v.len() { *sum0.f += v[i]; i += 1u; diff --git a/src/test/run-pass/rcvr-borrowed-to-region.rs b/src/test/run-pass/rcvr-borrowed-to-region.rs index 61cb473bf8fb2..7011f5ba1add0 100644 --- a/src/test/run-pass/rcvr-borrowed-to-region.rs +++ b/src/test/run-pass/rcvr-borrowed-to-region.rs @@ -31,7 +31,7 @@ pub fn main() { debug!("y=%d", y); assert y == 6; - let x = ~mut 6; + let mut x = ~6; let y = x.get(); debug!("y=%d", y); assert y == 6; diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index b90c39ab34e50..991025a1ad282 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -13,6 +13,7 @@ // A port of task-killjoin to use a class with a dtor to manage // the join. +use core::cell::Cell; use core::comm::*; struct notify { @@ -49,11 +50,9 @@ fn joinable(f: fn~()) -> Port { *b = true; } let (p, c) = stream(); - let c = ~mut Some(c); + let c = Cell(c); do task::spawn_unlinked { - let mut cc = None; - *c <-> cc; - let ccc = option::unwrap(cc); + let ccc = c.take(); wrapper(ccc, f) } p diff --git a/src/test/run-pass/unique-assign-copy.rs b/src/test/run-pass/unique-assign-copy.rs index 4723356dcd0c7..1bb04aef28687 100644 --- a/src/test/run-pass/unique-assign-copy.rs +++ b/src/test/run-pass/unique-assign-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let i = ~mut 1; + let mut i = ~1; // Should be a copy let mut j; j = copy i; diff --git a/src/test/run-pass/unique-decl-init-copy.rs b/src/test/run-pass/unique-decl-init-copy.rs index 628eb7265a5c6..a0b7fc336e259 100644 --- a/src/test/run-pass/unique-decl-init-copy.rs +++ b/src/test/run-pass/unique-decl-init-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let i = ~mut 1; + let mut i = ~1; // Should be a copy let j = copy i; *i = 2; diff --git a/src/test/run-pass/unique-in-vec-copy.rs b/src/test/run-pass/unique-in-vec-copy.rs index 54ea0258c7c6f..ac8796674abb8 100644 --- a/src/test/run-pass/unique-in-vec-copy.rs +++ b/src/test/run-pass/unique-in-vec-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let a = ~[~mut 10]; + let mut a = ~[~10]; let b = copy a; assert *a[0] == 10; diff --git a/src/test/run-pass/unique-mutable.rs b/src/test/run-pass/unique-mutable.rs index c52d3b563ac55..8784dbeb0af40 100644 --- a/src/test/run-pass/unique-mutable.rs +++ b/src/test/run-pass/unique-mutable.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let i = ~mut 0; + let mut i = ~0; *i = 1; assert *i == 1; } From 00d8db5b5d37e3039ff7cf170bc9c3473b3ab0de Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Feb 2013 15:16:36 -0800 Subject: [PATCH 14/85] Revert "test: De-~mut the test suite. rs=demuting" This reverts commit f63efdc2100ff28e2a42600641835e7bd8bde591. --- src/test/bench/msgsend-ring-mutex-arcs.rs | 17 +++++++++------ src/test/bench/msgsend-ring-pipes.rs | 20 +++++++++++------- src/test/bench/msgsend-ring-rw-arcs.rs | 17 +++++++++------ .../bench/task-perf-jargon-metal-smoke.rs | 8 +++---- .../compile-fail/mutable-huh-variance-deep.rs | 4 ++-- .../mutable-huh-variance-unique.rs | 21 +++++++++++++++++++ src/test/compile-fail/no-send-res-ports.rs | 7 +++---- src/test/compile-fail/unique-mut.rs | 14 +++++++++++++ .../run-pass/borrowck-preserve-box-in-uniq.rs | 2 +- src/test/run-pass/explicit-self-closures.rs | 3 +++ src/test/run-pass/intrinsic-atomics.rs | 2 +- src/test/run-pass/issue-2718.rs | 14 +++++++------ src/test/run-pass/pipe-pingpong-bounded.rs | 19 +++++++++-------- src/test/run-pass/pipe-pingpong-proto.rs | 19 +++++++++-------- src/test/run-pass/pure-sum.rs | 4 ++-- src/test/run-pass/rcvr-borrowed-to-region.rs | 2 +- src/test/run-pass/task-killjoin-rsrc.rs | 7 ++++--- src/test/run-pass/unique-assign-copy.rs | 2 +- src/test/run-pass/unique-decl-init-copy.rs | 2 +- src/test/run-pass/unique-in-vec-copy.rs | 2 +- src/test/run-pass/unique-mutable.rs | 2 +- 21 files changed, 121 insertions(+), 67 deletions(-) create mode 100644 src/test/compile-fail/mutable-huh-variance-unique.rs create mode 100644 src/test/compile-fail/unique-mut.rs diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 22045007134a0..9b6fee5e23bc1 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -87,12 +87,17 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = Cell(num_chan); - let num_port = Cell(num_port); - let new_future = do future::spawn() { - let num_chan = num_chan2.take(); - let num_port1 = num_port.take(); - thread_ring(i, msg_per_task, num_chan, num_port1) + let num_chan2 = ~mut None; + *num_chan2 <-> num_chan; + let num_port = ~mut Some(num_port); + let new_future = do future::spawn() || { + let mut num_chan = None; + num_chan <-> *num_chan2; + let mut num_port1 = None; + num_port1 <-> *num_port; + thread_ring(i, msg_per_task, + option::unwrap(num_chan), + option::unwrap(num_port1)) }; futures.push(new_future); num_chan = Some(new_chan); diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index dfe5c6de832c1..0f7c41f5997a8 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -17,12 +17,11 @@ // This version uses automatically compiled channel contracts. extern mod std; - -use core::cell::Cell; -use core::pipes::recv; use std::time; use std::future; +use core::pipes::recv; + proto! ring ( num:send { num(uint) -> num @@ -81,12 +80,17 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = ring::init(); - let num_chan2 = Cell(num_chan); - let num_port = Cell(num_port); + let num_chan2 = ~mut None; + *num_chan2 <-> num_chan; + let num_port = ~mut Some(num_port); let new_future = do future::spawn || { - let num_chan = num_chan2.take(); - let num_port1 = num_port.take(); - thread_ring(i, msg_per_task, num_chan, num_port1) + let mut num_chan = None; + num_chan <-> *num_chan2; + let mut num_port1 = None; + num_port1 <-> *num_port; + thread_ring(i, msg_per_task, + option::unwrap(num_chan), + option::unwrap(num_port1)) }; futures.push(new_future); num_chan = Some(new_chan); diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 98c0129918a47..eaae8370d6b8b 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -87,12 +87,17 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = Cell(num_chan); - let num_port = Cell(num_port); - let new_future = do future::spawn { - let num_chan = num_chan2.take(); - let num_port1 = num_port.take(); - thread_ring(i, msg_per_task, num_chan, num_port1) + let num_chan2 = ~mut None; + *num_chan2 <-> num_chan; + let num_port = ~mut Some(num_port); + let new_future = do future::spawn || { + let mut num_chan = None; + num_chan <-> *num_chan2; + let mut num_port1 = None; + num_port1 <-> *num_port; + thread_ring(i, msg_per_task, + option::unwrap(num_chan), + option::unwrap(num_port1)) }; futures.push(new_future); num_chan = Some(new_chan); diff --git a/src/test/bench/task-perf-jargon-metal-smoke.rs b/src/test/bench/task-perf-jargon-metal-smoke.rs index 9bdc5aae3f283..49a06fd491cd0 100644 --- a/src/test/bench/task-perf-jargon-metal-smoke.rs +++ b/src/test/bench/task-perf-jargon-metal-smoke.rs @@ -17,15 +17,13 @@ // // The filename is a song reference; google it in quotes. -use core::cell::Cell; - fn child_generation(gens_left: uint, -c: comm::Chan<()>) { // This used to be O(n^2) in the number of generations that ever existed. // With this code, only as many generations are alive at a time as tasks // alive at a time, - let c = Cell(c); - do task::spawn_supervised { - let c = c.take(); + let c = ~mut Some(c); + do task::spawn_supervised || { + let c = option::swap_unwrap(c); if gens_left & 1 == 1 { task::yield(); // shake things up a bit } diff --git a/src/test/compile-fail/mutable-huh-variance-deep.rs b/src/test/compile-fail/mutable-huh-variance-deep.rs index 51d5a6177f6aa..4f0c6d7a4c87d 100644 --- a/src/test/compile-fail/mutable-huh-variance-deep.rs +++ b/src/test/compile-fail/mutable-huh-variance-deep.rs @@ -11,9 +11,9 @@ // error-pattern: mismatched types fn main() { - let v = @[mut @mut @mut @[0]]; + let v = ~[mut @mut ~mut ~[0]]; - fn f(&&v: @[mut @mut @mut @[const int]]) { + fn f(&&v: ~[mut @mut ~mut ~[const int]]) { } f(v); diff --git a/src/test/compile-fail/mutable-huh-variance-unique.rs b/src/test/compile-fail/mutable-huh-variance-unique.rs new file mode 100644 index 0000000000000..f2188911346e9 --- /dev/null +++ b/src/test/compile-fail/mutable-huh-variance-unique.rs @@ -0,0 +1,21 @@ +// 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. + +// error-pattern: mismatched types + +fn main() { + let v = ~mut ~[0]; + + fn f(&&v: ~mut ~[const int]) { + *v = ~[mut 3] + } + + f(v); +} diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index 0d7e2d2377c20..4954bbfa09d06 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::cell::Cell; - struct Port(@T); fn main() { @@ -27,10 +25,11 @@ fn main() { } } - let x = Cell(foo(Port(@()))); + let x = ~mut Some(foo(Port(@()))); do task::spawn { - let y = x.take(); //~ ERROR value has non-owned type + let mut y = None; + *x <-> y; //~ ERROR value has non-owned type log(error, y); } } diff --git a/src/test/compile-fail/unique-mut.rs b/src/test/compile-fail/unique-mut.rs new file mode 100644 index 0000000000000..a3a197505a340 --- /dev/null +++ b/src/test/compile-fail/unique-mut.rs @@ -0,0 +1,14 @@ +// 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. + +//error-pattern:mismatched types +fn main() { + let i: ~int = ~mut 0; +} diff --git a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs index b11a5356f698c..9724717f2d580 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs @@ -20,7 +20,7 @@ fn borrow(x: &int, f: fn(x: &int)) { struct F { f: ~int } pub fn main() { - let mut x = ~@F{f: ~3}; + let mut x = ~mut @F{f: ~3}; do borrow(x.f) |b_x| { assert *b_x == 3; assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)); diff --git a/src/test/run-pass/explicit-self-closures.rs b/src/test/run-pass/explicit-self-closures.rs index d40b2f72ae8ba..4c12b6ad47c2f 100644 --- a/src/test/run-pass/explicit-self-closures.rs +++ b/src/test/run-pass/explicit-self-closures.rs @@ -21,6 +21,9 @@ impl Box { fn set_many2(@mut self, xs: &[uint]) { for xs.each |x| { self.x = *x; } } + fn set_many3(~mut self, xs: &[uint]) { + for xs.each |x| { self.x = *x; } + } } pub fn main() {} diff --git a/src/test/run-pass/intrinsic-atomics.rs b/src/test/run-pass/intrinsic-atomics.rs index 7d5bf65dad7c1..eb10a51c0bd65 100644 --- a/src/test/run-pass/intrinsic-atomics.rs +++ b/src/test/run-pass/intrinsic-atomics.rs @@ -29,7 +29,7 @@ extern mod rusti { pub fn main() { unsafe { - let mut x = ~1; + let x = ~mut 1; assert rusti::atomic_cxchg(x, 1, 2) == 1; assert *x == 2; diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index b97ebb04f716d..249d1c21376bd 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -318,16 +318,18 @@ pub fn main() { // Commented out because of option::get error let (client_, server_) = pingpong::init(); - let client_ = Cell(client_); - let server_ = Cell(server_); + let client_ = ~mut Some(client_); + let server_ = ~mut Some(server_); task::spawn {|client_| - let client__ = client_.take(); - client(client__); + let mut client__ = none; + *client_ <-> client__; + client(option::unwrap(client__)); }; task::spawn {|server_| - let server__ = server_.take(); - server(server_ËŠ); + let mut server_ËŠ = none; + *server_ <-> server_ËŠ; + server(option::unwrap(server_ËŠ)); }; */ } diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index 23f2bc10046b2..2ada6df76a6a8 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -14,7 +14,6 @@ // experiment with what code the compiler should generate for bounded // protocols. -use core::cell::Cell; // This was generated initially by the pipe compiler, but it's been // modified in hopefully straightforward ways. @@ -112,14 +111,16 @@ mod test { pub fn main() { let (client_, server_) = ::pingpong::init(); - let client_ = Cell(client_); - let server_ = Cell(server_); - do task::spawn { - let client__ = client_.take(); - test::client(client__); + let client_ = ~mut Some(client_); + let server_ = ~mut Some(server_); + do task::spawn || { + let mut client__ = None; + *client_ <-> client__; + test::client(option::unwrap(client__)); }; - do task::spawn { - let server__ = server_.take(); - test::server(server_ËŠ); + do task::spawn || { + let mut server_ËŠ = None; + *server_ <-> server_ËŠ; + test::server(option::unwrap(server_ËŠ)); }; } diff --git a/src/test/run-pass/pipe-pingpong-proto.rs b/src/test/run-pass/pipe-pingpong-proto.rs index a4a1c562bcaff..050ff76ef9b75 100644 --- a/src/test/run-pass/pipe-pingpong-proto.rs +++ b/src/test/run-pass/pipe-pingpong-proto.rs @@ -12,7 +12,6 @@ // An example to make sure the protocol parsing syntax extension works. -use core::cell::Cell; use core::option; proto! pingpong ( @@ -50,15 +49,17 @@ mod test { pub fn main() { let (client_, server_) = pingpong::init(); - let client_ = Cell(client_); - let server_ = Cell(server_); + let client_ = ~mut Some(client_); + let server_ = ~mut Some(server_); - do task::spawn { - let client__ = client_.take(); - test::client(client__); + do task::spawn || { + let mut client__ = None; + *client_ <-> client__; + test::client(option::unwrap(client__)); }; - do task::spawn { - let server__ = server_.take(); - test::server(server_ËŠ); + do task::spawn || { + let mut server_ËŠ = None; + *server_ <-> server_ËŠ; + test::server(option::unwrap(server_ËŠ)); }; } diff --git a/src/test/run-pass/pure-sum.rs b/src/test/run-pass/pure-sum.rs index cac6b4ef34932..f4c92c869e46e 100644 --- a/src/test/run-pass/pure-sum.rs +++ b/src/test/run-pass/pure-sum.rs @@ -20,7 +20,7 @@ pure fn sums_to(v: ~[int], sum: int) -> bool { } pure fn sums_to_using_uniq(v: ~[int], sum: int) -> bool { - let mut i = 0u, sum0 = ~0; + let mut i = 0u, sum0 = ~mut 0; while i < v.len() { *sum0 += v[i]; i += 1u; @@ -40,7 +40,7 @@ pure fn sums_to_using_rec(v: ~[int], sum: int) -> bool { struct F { f: T } pure fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool { - let mut i = 0u, sum0 = F {f: ~0}; + let mut i = 0u, sum0 = F {f: ~mut 0}; while i < v.len() { *sum0.f += v[i]; i += 1u; diff --git a/src/test/run-pass/rcvr-borrowed-to-region.rs b/src/test/run-pass/rcvr-borrowed-to-region.rs index 7011f5ba1add0..61cb473bf8fb2 100644 --- a/src/test/run-pass/rcvr-borrowed-to-region.rs +++ b/src/test/run-pass/rcvr-borrowed-to-region.rs @@ -31,7 +31,7 @@ pub fn main() { debug!("y=%d", y); assert y == 6; - let mut x = ~6; + let x = ~mut 6; let y = x.get(); debug!("y=%d", y); assert y == 6; diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index 991025a1ad282..b90c39ab34e50 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -13,7 +13,6 @@ // A port of task-killjoin to use a class with a dtor to manage // the join. -use core::cell::Cell; use core::comm::*; struct notify { @@ -50,9 +49,11 @@ fn joinable(f: fn~()) -> Port { *b = true; } let (p, c) = stream(); - let c = Cell(c); + let c = ~mut Some(c); do task::spawn_unlinked { - let ccc = c.take(); + let mut cc = None; + *c <-> cc; + let ccc = option::unwrap(cc); wrapper(ccc, f) } p diff --git a/src/test/run-pass/unique-assign-copy.rs b/src/test/run-pass/unique-assign-copy.rs index 1bb04aef28687..4723356dcd0c7 100644 --- a/src/test/run-pass/unique-assign-copy.rs +++ b/src/test/run-pass/unique-assign-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let mut i = ~1; + let i = ~mut 1; // Should be a copy let mut j; j = copy i; diff --git a/src/test/run-pass/unique-decl-init-copy.rs b/src/test/run-pass/unique-decl-init-copy.rs index a0b7fc336e259..628eb7265a5c6 100644 --- a/src/test/run-pass/unique-decl-init-copy.rs +++ b/src/test/run-pass/unique-decl-init-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let mut i = ~1; + let i = ~mut 1; // Should be a copy let j = copy i; *i = 2; diff --git a/src/test/run-pass/unique-in-vec-copy.rs b/src/test/run-pass/unique-in-vec-copy.rs index ac8796674abb8..54ea0258c7c6f 100644 --- a/src/test/run-pass/unique-in-vec-copy.rs +++ b/src/test/run-pass/unique-in-vec-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let mut a = ~[~10]; + let a = ~[~mut 10]; let b = copy a; assert *a[0] == 10; diff --git a/src/test/run-pass/unique-mutable.rs b/src/test/run-pass/unique-mutable.rs index 8784dbeb0af40..c52d3b563ac55 100644 --- a/src/test/run-pass/unique-mutable.rs +++ b/src/test/run-pass/unique-mutable.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let mut i = ~0; + let i = ~mut 0; *i = 1; assert *i == 1; } From abc4ea2001c24f3a1e3d9edf3bebb1b2bb8629ec Mon Sep 17 00:00:00 2001 From: Ben Striegel Date: Mon, 25 Feb 2013 19:49:28 -0500 Subject: [PATCH 15/85] Stop parsing capture clauses --- src/libsyntax/parse/parser.rs | 58 ++++++++---------------- src/test/run-pass/cap-clause-not-used.rs | 15 ------ 2 files changed, 20 insertions(+), 53 deletions(-) delete mode 100644 src/test/run-pass/cap-clause-not-used.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9bac163dab6ef..853b140805027 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(); diff --git a/src/test/run-pass/cap-clause-not-used.rs b/src/test/run-pass/cap-clause-not-used.rs deleted file mode 100644 index e26a8ae11fdb2..0000000000000 --- a/src/test/run-pass/cap-clause-not-used.rs +++ /dev/null @@ -1,15 +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. - -// error-pattern: warning: Captured variable 'y' not used in closure -pub fn main() { - let x = 5; - let _y = fn~(copy x) { }; -} From 046fc5e0b18921a55d19922865e5f65a98ab0f56 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 25 Feb 2013 18:46:36 -0800 Subject: [PATCH 16/85] Add Kang Seonghoon to AUTHORS --- AUTHORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index 92903a26093f9..33ac21e6db9d8 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -93,6 +93,7 @@ Josh Matthews Joshua Clark Joshua Wise Jyun-Yan You +Kang Seonghoon Kelly Wilson Kevin Atkinson Kevin Cantu From 5098cf5bd2abbef4418e93c9ab7db1eac43bb1bb Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Tue, 26 Feb 2013 20:24:15 +0900 Subject: [PATCH 17/85] ARM C ABI implementation --- src/librustc/middle/trans/cabi_arm.rs | 164 ++++++++++++++++++++++++++ src/librustc/middle/trans/foreign.rs | 4 +- src/librustc/rustc.rc | 1 + 3 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 src/librustc/middle/trans/cabi_arm.rs diff --git a/src/librustc/middle/trans/cabi_arm.rs b/src/librustc/middle/trans/cabi_arm.rs new file mode 100644 index 0000000000000..259392bef40c8 --- /dev/null +++ b/src/librustc/middle/trans/cabi_arm.rs @@ -0,0 +1,164 @@ +// Copyright 2012-2013 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. + +use lib::llvm::{llvm, Integer, Pointer, Float, Double, Struct, Array}; +use lib::llvm::struct_tys; +use lib::llvm::TypeRef; +use lib::llvm::{Attribute, StructRetAttribute}; +use middle::trans::cabi::{ABIInfo, FnType, LLVMType}; +use middle::trans::common::{T_i8, T_i16, T_i32, T_i64}; +use middle::trans::common::{T_array, T_ptr, T_void}; + +use core::option::{Option, None, Some}; +use core::uint; +use core::vec; + +fn align_up_to(off: uint, a: uint) -> uint { + return (off + a - 1u) / a * a; +} + +fn align(off: uint, ty: TypeRef) -> uint { + let a = ty_align(ty); + return align_up_to(off, a); +} + +fn ty_align(ty: TypeRef) -> uint { + unsafe { + return match llvm::LLVMGetTypeKind(ty) { + Integer => { + ((llvm::LLVMGetIntTypeWidth(ty) as uint) + 7) / 8 + } + Pointer => 4, + Float => 4, + Double => 8, + Struct => { + do vec::foldl(1, struct_tys(ty)) |a, t| { + uint::max(a, ty_align(*t)) + } + } + Array => { + let elt = llvm::LLVMGetElementType(ty); + ty_align(elt) + } + _ => fail!(~"ty_align: unhandled type") + }; + } +} + +fn ty_size(ty: TypeRef) -> uint { + unsafe { + return match llvm::LLVMGetTypeKind(ty) { + Integer => { + ((llvm::LLVMGetIntTypeWidth(ty) as uint) + 7) / 8 + } + Pointer => 4, + Float => 4, + Double => 8, + Struct => { + let size = do vec::foldl(0, struct_tys(ty)) |s, t| { + align(s, *t) + ty_size(*t) + }; + align(size, ty) + } + Array => { + let len = llvm::LLVMGetArrayLength(ty) as uint; + let elt = llvm::LLVMGetElementType(ty); + let eltsz = ty_size(elt); + len * eltsz + } + _ => fail!(~"ty_size: unhandled type") + }; + } +} + +fn classify_ret_ty(ty: TypeRef) -> (LLVMType, Option) { + if is_reg_ty(ty) { + return (LLVMType { cast: false, ty: ty }, None); + } + let size = ty_size(ty); + if size <= 4 { + let llty = if size <= 1 { + T_i8() + } else if size <= 2 { + T_i16() + } else { + T_i32() + }; + return (LLVMType { cast: true, ty: llty }, None); + } + (LLVMType { cast: false, ty: T_ptr(ty) }, Some(StructRetAttribute)) +} + +fn classify_arg_ty(ty: TypeRef) -> (LLVMType, Option) { + if is_reg_ty(ty) { + return (LLVMType { cast: false, ty: ty }, None); + } + let align = ty_align(ty); + let size = ty_size(ty); + let llty = if align <= 4 { + T_array(T_i32(), (size + 3) / 4) + } else { + T_array(T_i64(), (size + 7) / 8) + }; + (LLVMType { cast: true, ty: llty }, None) +} + +fn is_reg_ty(ty: TypeRef) -> bool { + unsafe { + return match llvm::LLVMGetTypeKind(ty) { + Integer + | Pointer + | Float + | Double => true, + _ => false + }; + } +} + +enum ARM_ABIInfo { ARM_ABIInfo } + +impl ABIInfo for ARM_ABIInfo { + fn compute_info(&self, + atys: &[TypeRef], + rty: TypeRef, + ret_def: bool) -> FnType { + let mut arg_tys = ~[]; + let mut attrs = ~[]; + for atys.each |&aty| { + let (ty, attr) = classify_arg_ty(aty); + arg_tys.push(ty); + attrs.push(attr); + } + + let mut (ret_ty, ret_attr) = if ret_def { + classify_ret_ty(rty) + } else { + (LLVMType { cast: false, ty: T_void() }, None) + }; + + let sret = ret_attr.is_some(); + if sret { + arg_tys.unshift(ret_ty); + attrs.unshift(ret_attr); + ret_ty = LLVMType { cast: false, ty: T_void() }; + } + + return FnType { + arg_tys: arg_tys, + ret_ty: ret_ty, + attrs: attrs, + sret: sret + }; + } +} + +pub fn abi_info() -> ABIInfo { + return ARM_ABIInfo as ABIInfo; +} diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 3d1d70abefda1..ef9cc89eb90df 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -21,6 +21,7 @@ use lib; use middle::trans::base::*; use middle::trans::cabi; use middle::trans::cabi_x86_64::*; +use middle::trans::cabi_arm; use middle::trans::build::*; use middle::trans::callee::*; use middle::trans::common::*; @@ -42,7 +43,8 @@ use syntax::parse::token::special_idents; fn abi_info(arch: session::arch) -> cabi::ABIInfo { return match arch { - arch_x86_64 | arch_arm => x86_64_abi_info(), + arch_x86_64 => x86_64_abi_info(), + arch_arm => cabi_arm::abi_info(), _ => cabi::llvm_abi_info() } } diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc index 01758a1845d7c..31fbe9a9f1384 100644 --- a/src/librustc/rustc.rc +++ b/src/librustc/rustc.rc @@ -68,6 +68,7 @@ pub mod middle { pub mod meth; pub mod cabi; pub mod cabi_x86_64; + pub mod cabi_arm; pub mod foreign; pub mod reflect; pub mod shape; From 9b8ce0d3b5dd5fd371d665258555db54b1656300 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 26 Feb 2013 04:01:35 -0800 Subject: [PATCH 18/85] libsyntax: Remove a mutable field from the tests. rs=demuting --- src/libsyntax/ext/auto_encode.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 7fbba987cc7df..b345b116425ca 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 () { From c483aab4ae391eb26dae5a17d40c148551a6c674 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Feb 2013 11:34:16 -0800 Subject: [PATCH 19/85] librustc: Implement a lint mode for mutable structures; deny by default. r=tjc --- src/libcore/core.rc | 1 + src/librustc/middle/lint.rs | 29 ++++++++++++++++++++++++++ src/libstd/std.rc | 1 + src/test/run-pass/cycle-collection4.rs | 6 +++--- src/test/run-pass/issue-1989.rs | 17 +++++++-------- src/test/run-pass/issue-980.rs | 6 +++--- src/test/run-pass/private-method.rs | 16 +++++++------- src/test/run-pass/uniq-cc-generic.rs | 11 +++++----- src/test/run-pass/uniq-cc.rs | 13 ++++++------ 9 files changed, 64 insertions(+), 36 deletions(-) diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 01669557389ae..829651ae90925 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -51,6 +51,7 @@ Implicitly, all crates behave as if they included the following prologue: #[warn(vecs_implicitly_copyable)]; #[deny(non_camel_case_types)]; #[allow(deprecated_self)]; +#[allow(deprecated_mutable_fields)]; /* The Prelude. */ diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index a25bc84f8a214..f4c3a1e8d1261 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -80,6 +80,7 @@ pub enum lint { type_limits, default_methods, deprecated_self, + deprecated_mutable_fields, managed_heap_memory, owned_heap_memory, @@ -254,6 +255,13 @@ pub fn get_lint_dict() -> LintDict { default: warn }), + (@~"deprecated_mutable_fields", + @LintSpec { + lint: deprecated_mutable_fields, + desc: "deprecated mutable fields in structures", + default: deny + }), + /* FIXME(#3266)--make liveness warnings lintable (@~"unused_variable", @LintSpec { @@ -486,6 +494,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) { check_item_type_limits(cx, i); check_item_default_methods(cx, i); check_item_deprecated_self(cx, i); + check_item_deprecated_mutable_fields(cx, i); } // Take a visitor, and modify it so that it will not proceed past subitems. @@ -703,6 +712,26 @@ fn check_item_deprecated_self(cx: ty::ctxt, item: @ast::item) { } } +fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) { + match item.node { + ast::item_struct(struct_def, _) => { + for struct_def.fields.each |field| { + match field.node.kind { + ast::named_field(_, ast::struct_mutable, _) => { + cx.sess.span_lint(deprecated_mutable_fields, + item.id, + item.id, + field.span, + ~"mutable fields are deprecated"); + } + ast::named_field(*) | ast::unnamed_field => {} + } + } + } + _ => {} + } +} + fn check_item_structural_records(cx: ty::ctxt, it: @ast::item) { let visit = item_stopping_visitor( visit::mk_simple_visitor(@visit::SimpleVisitor { diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 1ece8c17ff7a7..b6d99800aa2a3 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -29,6 +29,7 @@ not required in or otherwise suitable for the core library. #[allow(vecs_implicitly_copyable)]; #[deny(non_camel_case_types)]; #[allow(deprecated_self)]; +#[allow(deprecated_mutable_fields)]; #[no_core]; diff --git a/src/test/run-pass/cycle-collection4.rs b/src/test/run-pass/cycle-collection4.rs index 4be43fc1296ed..8a3139157fdf6 100644 --- a/src/test/run-pass/cycle-collection4.rs +++ b/src/test/run-pass/cycle-collection4.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct foo { mut z : fn@() } +struct foo { z : fn@() } fn nop() { } -fn nop_foo(_y: ~[int], _x : @foo) { } +fn nop_foo(_y: ~[int], _x : @mut foo) { } pub fn main() { - let w = @foo{ z: || nop() }; + let w = @mut foo{ z: || nop() }; let x : fn@() = || nop_foo(~[], w); w.z = x; } diff --git a/src/test/run-pass/issue-1989.rs b/src/test/run-pass/issue-1989.rs index f941a9002ef74..95129851d5bcd 100644 --- a/src/test/run-pass/issue-1989.rs +++ b/src/test/run-pass/issue-1989.rs @@ -12,23 +12,22 @@ enum maybe_pointy { none, - p(@Pointy) + p(@mut Pointy) } struct Pointy { - mut a : maybe_pointy, - mut f : fn@()->(), + a : maybe_pointy, + f : fn@()->(), } -fn empty_pointy() -> @Pointy { - return @Pointy{ - mut a : none, - mut f : fn@()->(){}, +fn empty_pointy() -> @mut Pointy { + return @mut Pointy{ + a : none, + f : fn@()->(){}, } } -pub fn main() -{ +pub fn main() { let v = ~[empty_pointy(), empty_pointy()]; v[0].a = p(v[0]); } diff --git a/src/test/run-pass/issue-980.rs b/src/test/run-pass/issue-980.rs index 842eabf8fc502..e2e5dfcc7d519 100644 --- a/src/test/run-pass/issue-980.rs +++ b/src/test/run-pass/issue-980.rs @@ -10,14 +10,14 @@ enum maybe_pointy { no_pointy, - yes_pointy(@Pointy), + yes_pointy(@mut Pointy), } struct Pointy { - mut x : maybe_pointy + x : maybe_pointy } pub fn main() { - let m = @Pointy { mut x : no_pointy }; + let m = @mut Pointy { x : no_pointy }; m.x = yes_pointy(m); } diff --git a/src/test/run-pass/private-method.rs b/src/test/run-pass/private-method.rs index ae149421f0a16..432c189ae423c 100644 --- a/src/test/run-pass/private-method.rs +++ b/src/test/run-pass/private-method.rs @@ -9,20 +9,20 @@ // except according to those terms. struct cat { - priv mut meows : uint, + priv meows : uint, - how_hungry : int, + how_hungry : int, } impl cat { - fn play() { - self.meows += 1u; - self.nap(); - } + fn play(&mut self) { + self.meows += 1u; + self.nap(); + } } priv impl cat { - fn nap() { for uint::range(1u, 10u) |_i| { }} + fn nap(&mut self) { for uint::range(1u, 10u) |_i| { }} } fn cat(in_x : uint, in_y : int) -> cat { @@ -33,6 +33,6 @@ fn cat(in_x : uint, in_y : int) -> cat { } pub fn main() { - let nyan : cat = cat(52u, 99); + let mut nyan : cat = cat(52u, 99); nyan.play(); } diff --git a/src/test/run-pass/uniq-cc-generic.rs b/src/test/run-pass/uniq-cc-generic.rs index dd86150b93bf9..1b602ab7d3009 100644 --- a/src/test/run-pass/uniq-cc-generic.rs +++ b/src/test/run-pass/uniq-cc-generic.rs @@ -10,11 +10,11 @@ enum maybe_pointy { none, - p(@Pointy), + p(@mut Pointy), } struct Pointy { - mut a : maybe_pointy, + a : maybe_pointy, d : fn~() -> uint, } @@ -22,15 +22,14 @@ fn make_uniq_closure(a: A) -> fn~() -> uint { fn~() -> uint { ptr::addr_of(&a) as uint } } -fn empty_pointy() -> @Pointy { - return @Pointy { +fn empty_pointy() -> @mut Pointy { + return @mut Pointy { mut a : none, d : make_uniq_closure(~"hi") } } -pub fn main() -{ +pub fn main() { let v = empty_pointy(); v.a = p(v); } diff --git a/src/test/run-pass/uniq-cc.rs b/src/test/run-pass/uniq-cc.rs index 384450ec57fed..3d72a41182868 100644 --- a/src/test/run-pass/uniq-cc.rs +++ b/src/test/run-pass/uniq-cc.rs @@ -10,25 +10,24 @@ enum maybe_pointy { none, - p(@Pointy), + p(@mut Pointy), } struct Pointy { - mut a : maybe_pointy, + a : maybe_pointy, c : ~int, d : fn~()->(), } -fn empty_pointy() -> @Pointy { - return @Pointy { - mut a : none, +fn empty_pointy() -> @mut Pointy { + return @mut Pointy { + a : none, c : ~22, d : fn~()->(){}, } } -pub fn main() -{ +pub fn main() { let v = empty_pointy(); v.a = p(v); } From e2f90091cf652218fe456ec1a54892fe1ceabb36 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Feb 2013 13:23:16 -0800 Subject: [PATCH 20/85] libcore: Move Cell to core and de-~mut core and std --- src/{libstd => libcore}/cell.rs | 4 +- src/libcore/core.rc | 1 + src/libcore/pipes.rs | 17 ++++---- src/libcore/private.rs | 40 +++++++++++-------- src/libcore/private/weak_task.rs | 25 ++++++------ src/libcore/repr.rs | 1 - src/libcore/task/mod.rs | 7 ++-- src/libcore/task/spawn.rs | 9 +++-- .../middle/typeck/infer/region_inference.rs | 2 +- src/librustc/rustc.rc | 2 +- src/librustdoc/astsrv.rs | 2 +- src/librustdoc/config.rs | 2 +- src/librustdoc/markdown_pass.rs | 2 +- src/librustdoc/text_pass.rs | 2 +- src/libstd/std.rc | 1 - 15 files changed, 60 insertions(+), 57 deletions(-) rename src/{libstd => libcore}/cell.rs (98%) diff --git a/src/libstd/cell.rs b/src/libcore/cell.rs similarity index 98% rename from src/libstd/cell.rs rename to src/libcore/cell.rs index c8121daddabd0..5887df6802f57 100644 --- a/src/libstd/cell.rs +++ b/src/libcore/cell.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::option; -use core::prelude::*; +use option; +use prelude::*; /// A dynamic, mutable location. /// diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 829651ae90925..ed18388f5783b 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -143,6 +143,7 @@ pub mod dlist; #[path="iter-trait.rs"] #[merge = "iter-trait/dlist.rs"] pub mod dlist_iter; pub mod hashmap; +pub mod cell; /* Tasks and communication */ diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 94c0a567f4c09..15a6e700ffd84 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -86,6 +86,7 @@ bounded and unbounded protocols allows for less code duplication. use cmp::Eq; use cast::{forget, reinterpret_cast, transmute}; +use cell::Cell; use either::{Either, Left, Right}; use kinds::Owned; use libc; @@ -917,11 +918,9 @@ pub fn spawn_service( // This is some nasty gymnastics required to safely move the pipe // into a new task. - let server = ~mut Some(server); - do task::spawn || { - let mut server_ = None; - server_ <-> *server; - service(option::unwrap(server_)) + let server = Cell(server); + do task::spawn { + service(server.take()); } client @@ -941,11 +940,9 @@ pub fn spawn_service_recv( // This is some nasty gymnastics required to safely move the pipe // into a new task. - let server = ~mut Some(server); - do task::spawn || { - let mut server_ = None; - server_ <-> *server; - service(option::unwrap(server_)) + let server = Cell(server); + do task::spawn { + service(server.take()) } client diff --git a/src/libcore/private.rs b/src/libcore/private.rs index 280eb14b172c4..2580efe6d0968 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -107,10 +107,14 @@ fn compare_and_swap(address: &mut int, oldval: int, newval: int) -> bool { * Shared state & exclusive ARC ****************************************************************************/ +struct UnwrapProtoInner { + contents: Option<(comm::ChanOne<()>, comm::PortOne)>, +} + // An unwrapper uses this protocol to communicate with the "other" task that // drops the last refcount on an arc. Unfortunately this can't be a proper // pipe protocol because the unwrapper has to access both stages at once. -type UnwrapProto = ~mut Option<(comm::ChanOne<()>, comm::PortOne)>; +type UnwrapProto = ~UnwrapProtoInner; struct ArcData { mut count: libc::intptr_t, @@ -139,9 +143,10 @@ struct ArcDestruct { // reference. In effect, being here means we're the only // *awake* task with the data. if data.unwrapper != 0 { - let p: UnwrapProto = + let mut p: UnwrapProto = cast::reinterpret_cast(&data.unwrapper); - let (message, response) = option::swap_unwrap(p); + let (message, response) = + option::swap_unwrap(&mut p.contents); // Send 'ready' and wait for a response. comm::send_one(message, ()); // Unkillable wait. Message guaranteed to come. @@ -196,7 +201,9 @@ pub unsafe fn unwrap_shared_mutable_state(rc: SharedMutableState) let ptr: ~ArcData = cast::reinterpret_cast(&rc.data); let (p1,c1) = comm::oneshot(); // () let (p2,c2) = comm::oneshot(); // bool - let server: UnwrapProto = ~mut Some((c1,p2)); + let mut server: UnwrapProto = ~UnwrapProtoInner { + contents: Some((c1,p2)) + }; let serverp: int = cast::transmute(server); // Try to put our server end in the unwrapper slot. if compare_and_swap(&mut ptr.unwrapper, 0, serverp) { @@ -409,8 +416,9 @@ pub fn unwrap_exclusive(arc: Exclusive) -> T { pub mod tests { use core::option::{None, Some}; - use option; + use cell::Cell; use comm; + use option; use private::{exclusive, unwrap_exclusive}; use result; use task; @@ -423,7 +431,7 @@ pub mod tests { let num_tasks = 10; let count = 10; - let total = exclusive(~mut 0); + let total = exclusive(~0); for uint::range(0, num_tasks) |_i| { let total = total.clone(); @@ -472,9 +480,9 @@ pub mod tests { #[test] pub fn exclusive_unwrap_contended() { let x = exclusive(~~"hello"); - let x2 = ~mut Some(x.clone()); - do task::spawn || { - let x2 = option::swap_unwrap(x2); + let x2 = Cell(x.clone()); + do task::spawn { + let x2 = x2.take(); do x2.with |_hello| { } task::yield(); } @@ -482,11 +490,10 @@ pub mod tests { // Now try the same thing, but with the child task blocking. let x = exclusive(~~"hello"); - let x2 = ~mut Some(x.clone()); + let x2 = Cell(x.clone()); let mut res = None; - do task::task().future_result(|+r| res = Some(r)).spawn - || { - let x2 = option::swap_unwrap(x2); + do task::task().future_result(|+r| res = Some(r)).spawn { + let x2 = x2.take(); assert unwrap_exclusive(x2) == ~~"hello"; } // Have to get rid of our reference before blocking. @@ -498,11 +505,10 @@ pub mod tests { #[test] #[should_fail] #[ignore(cfg(windows))] pub fn exclusive_unwrap_conflict() { let x = exclusive(~~"hello"); - let x2 = ~mut Some(x.clone()); + let x2 = Cell(x.clone()); let mut res = None; - do task::task().future_result(|+r| res = Some(r)).spawn - || { - let x2 = option::swap_unwrap(x2); + do task::task().future_result(|+r| res = Some(r)).spawn { + let x2 = x2.take(); assert unwrap_exclusive(x2) == ~~"hello"; } assert unwrap_exclusive(x) == ~~"hello"; diff --git a/src/libcore/private/weak_task.rs b/src/libcore/private/weak_task.rs index f3df8ce72f146..8445638850cd0 100644 --- a/src/libcore/private/weak_task.rs +++ b/src/libcore/private/weak_task.rs @@ -18,16 +18,17 @@ it is running, sending a notification to the task that the runtime is trying to shut down. */ +use cell::Cell; +use comm::{GenericSmartChan, stream}; +use comm::{Port, Chan, SharedChan, GenericChan, GenericPort}; +use hashmap::linear::LinearMap; +use ops::Drop; use option::{Some, None, swap_unwrap}; use private::at_exit::at_exit; -use private::global::global_data_clone_create; use private::finally::Finally; -use comm::{Port, Chan, SharedChan, GenericChan, - GenericPort, GenericSmartChan, stream}; -use task::{Task, task, spawn}; +use private::global::global_data_clone_create; use task::rt::{task_id, get_task_id}; -use hashmap::linear::LinearMap; -use ops::Drop; +use task::{Task, task, spawn}; type ShutdownMsg = (); @@ -37,14 +38,13 @@ pub unsafe fn weaken_task(f: &fn(Port)) { let service = global_data_clone_create(global_data_key, create_global_service); let (shutdown_port, shutdown_chan) = stream::(); - let shutdown_port = ~mut Some(shutdown_port); + let shutdown_port = Cell(shutdown_port); let task = get_task_id(); // Expect the weak task service to be alive assert service.try_send(RegisterWeakTask(task, shutdown_chan)); unsafe { rust_dec_kernel_live_count(); } do fn&() { - let shutdown_port = swap_unwrap(&mut *shutdown_port); - f(shutdown_port) + f(shutdown_port.take()) }.finally || { unsafe { rust_inc_kernel_live_count(); } // Service my have already exited @@ -67,16 +67,15 @@ fn create_global_service() -> ~WeakTaskService { debug!("creating global weak task service"); let (port, chan) = stream::(); - let port = ~mut Some(port); + let port = Cell(port); let chan = SharedChan(chan); let chan_clone = chan.clone(); do task().unlinked().spawn { debug!("running global weak task service"); - let port = swap_unwrap(&mut *port); - let port = ~mut Some(port); + let port = Cell(port.take()); do fn&() { - let port = swap_unwrap(&mut *port); + let port = port.take(); // The weak task service is itself a weak task debug!("weakening the weak service task"); unsafe { rust_dec_kernel_live_count(); } diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index 7f1687b08608a..4c3abb09756e9 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -602,7 +602,6 @@ fn test_repr() { exact_test(&(@10), "@10"); exact_test(&(@mut 10), "@10"); exact_test(&(~10), "~10"); - exact_test(&(~mut 10), "~mut 10"); exact_test(&(&10), "&10"); let mut x = 10; exact_test(&(&mut x), "&mut 10"); diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs index 336e686193b91..2a640e4bf8cf7 100644 --- a/src/libcore/task/mod.rs +++ b/src/libcore/task/mod.rs @@ -34,6 +34,7 @@ */ use cast; +use cell::Cell; use cmp; use cmp::Eq; use iter; @@ -397,9 +398,9 @@ impl TaskBuilder { } /// Runs a task, while transfering ownership of one argument to the child. fn spawn_with(arg: A, f: fn~(v: A)) { - let arg = ~mut Some(arg); - do self.spawn || { - f(option::swap_unwrap(arg)) + let arg = Cell(arg); + do self.spawn { + f(arg.take()); } } diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index e77af820079b6..5110f70ff11be 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -73,6 +73,7 @@ #[doc(hidden)]; // FIXME #3538 use cast; +use cell::Cell; use container::Map; use option; use comm::{Chan, GenericChan, GenericPort, Port, stream}; @@ -530,11 +531,11 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) { gen_child_taskgroup(opts.linked, opts.supervised); unsafe { - let child_data = ~mut Some((child_tg, ancestors, f)); + let child_data = Cell((child_tg, ancestors, f)); // Being killed with the unsafe task/closure pointers would leak them. do unkillable { // Agh. Get move-mode items into the closure. FIXME (#2829) - let (child_tg, ancestors, f) = option::swap_unwrap(child_data); + let (child_tg, ancestors, f) = child_data.take(); // Create child task. let new_task = match opts.sched.mode { DefaultScheduler => rt::new_task(), @@ -571,10 +572,10 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) { ancestors: AncestorList, is_main: bool, notify_chan: Option>, f: fn~()) -> fn~() { - let child_data = ~mut Some((child_arc, ancestors)); + let child_data = Cell((child_arc, ancestors)); return fn~() { // Agh. Get move-mode items into the closure. FIXME (#2829) - let mut (child_arc, ancestors) = option::swap_unwrap(child_data); + let mut (child_arc, ancestors) = child_data.take(); // Child task runs this code. // Even if the below code fails to kick the child off, we must diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index cc5e860715d6d..ee59868665252 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -549,6 +549,7 @@ use syntax::codemap; use util::common::indenter; use util::ppaux::note_and_explain_region; +use core::cell::{Cell, empty_cell}; use core::cmp; use core::dvec::DVec; use core::to_bytes; @@ -557,7 +558,6 @@ use core::vec; use result::Result; use result::{Ok, Err}; use std::oldmap::HashMap; -use std::cell::{Cell, empty_cell}; use std::list::{List, Nil, Cons}; use syntax::codemap::span; use syntax::codemap; diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc index 01758a1845d7c..251e21578a523 100644 --- a/src/librustc/rustc.rc +++ b/src/librustc/rustc.rc @@ -314,8 +314,8 @@ fails without recording a fatal error then we've encountered a compiler bug and need to present an error. */ pub fn monitor(+f: fn~(diagnostic::Emitter)) { + use core::cell::Cell; use core::comm::*; - use std::cell::Cell; let (p, ch) = stream(); let ch = SharedChan(ch); let ch_capture = ch.clone(); diff --git a/src/librustdoc/astsrv.rs b/src/librustdoc/astsrv.rs index fff2e189eb85c..1c45fdafa189c 100644 --- a/src/librustdoc/astsrv.rs +++ b/src/librustdoc/astsrv.rs @@ -21,8 +21,8 @@ use core::prelude::*; use parse; use util; -use std::cell::Cell; +use core::cell::Cell; use core::comm::{stream, Chan, SharedChan, Port}; use core::vec; use core::ops::Drop; diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index e904015e419f6..11a1b9f357657 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -10,6 +10,7 @@ use core::prelude::*; +use core::cell::Cell; use core::cmp; use core::os; use core::result; @@ -18,7 +19,6 @@ use core::run::ProgramOutput; use core::vec; use core::result::Result; use std::getopts; -use std::cell::Cell; /// The type of document to output pub enum OutputFormat { diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs index ff9faabaec24b..f64f365496d83 100644 --- a/src/librustdoc/markdown_pass.rs +++ b/src/librustdoc/markdown_pass.rs @@ -34,11 +34,11 @@ use sort_pass; use trim_pass; use unindent_pass; +use core::cell::Cell; use core::iter; use core::str; use core::vec; use std::par; -use std::cell::Cell; use syntax; pub fn mk_pass(writer_factory: WriterFactory) -> Pass { diff --git a/src/librustdoc/text_pass.rs b/src/librustdoc/text_pass.rs index b9dbe523fdd33..83f35418b0b1f 100644 --- a/src/librustdoc/text_pass.rs +++ b/src/librustdoc/text_pass.rs @@ -20,8 +20,8 @@ use fold; use pass::Pass; use util::NominalOp; +use core::cell::Cell; use std::par; -use std::cell::Cell; pub fn mk_pass(name: ~str, op: @fn(&str) -> ~str) -> Pass { let op = Cell(op); diff --git a/src/libstd/std.rc b/src/libstd/std.rc index b6d99800aa2a3..854abfdd112e6 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -54,7 +54,6 @@ pub mod uv_global_loop; pub mod c_vec; pub mod timer; -pub mod cell; pub mod io_util; // Concurrency From e3d43e490be9b298d2bcebf26ac4708157fda9e2 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Feb 2013 14:04:32 -0800 Subject: [PATCH 21/85] test: De-~mut the test suite. rs=demuting --- src/test/bench/msgsend-ring-mutex-arcs.rs | 17 ++++++--------- src/test/bench/msgsend-ring-pipes.rs | 20 +++++++----------- src/test/bench/msgsend-ring-rw-arcs.rs | 17 ++++++--------- .../bench/task-perf-jargon-metal-smoke.rs | 8 ++++--- .../compile-fail/mutable-huh-variance-deep.rs | 4 ++-- .../mutable-huh-variance-unique.rs | 21 ------------------- src/test/compile-fail/no-send-res-ports.rs | 7 ++++--- src/test/compile-fail/unique-mut.rs | 14 ------------- .../run-pass/borrowck-preserve-box-in-uniq.rs | 2 +- src/test/run-pass/explicit-self-closures.rs | 3 --- src/test/run-pass/intrinsic-atomics.rs | 2 +- src/test/run-pass/issue-2718.rs | 14 ++++++------- src/test/run-pass/pipe-pingpong-bounded.rs | 19 ++++++++--------- src/test/run-pass/pipe-pingpong-proto.rs | 19 ++++++++--------- src/test/run-pass/pure-sum.rs | 4 ++-- src/test/run-pass/rcvr-borrowed-to-region.rs | 2 +- src/test/run-pass/task-killjoin-rsrc.rs | 7 +++---- src/test/run-pass/unique-assign-copy.rs | 2 +- src/test/run-pass/unique-decl-init-copy.rs | 4 ++-- src/test/run-pass/unique-in-vec-copy.rs | 2 +- src/test/run-pass/unique-mutable.rs | 2 +- 21 files changed, 68 insertions(+), 122 deletions(-) delete mode 100644 src/test/compile-fail/mutable-huh-variance-unique.rs delete mode 100644 src/test/compile-fail/unique-mut.rs diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 9b6fee5e23bc1..22045007134a0 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -87,17 +87,12 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = ~mut None; - *num_chan2 <-> num_chan; - let num_port = ~mut Some(num_port); - let new_future = do future::spawn() || { - let mut num_chan = None; - num_chan <-> *num_chan2; - let mut num_port1 = None; - num_port1 <-> *num_port; - thread_ring(i, msg_per_task, - option::unwrap(num_chan), - option::unwrap(num_port1)) + let num_chan2 = Cell(num_chan); + let num_port = Cell(num_port); + let new_future = do future::spawn() { + let num_chan = num_chan2.take(); + let num_port1 = num_port.take(); + thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); num_chan = Some(new_chan); diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index 0f7c41f5997a8..dfe5c6de832c1 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -17,10 +17,11 @@ // This version uses automatically compiled channel contracts. extern mod std; -use std::time; -use std::future; +use core::cell::Cell; use core::pipes::recv; +use std::time; +use std::future; proto! ring ( num:send { @@ -80,17 +81,12 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = ring::init(); - let num_chan2 = ~mut None; - *num_chan2 <-> num_chan; - let num_port = ~mut Some(num_port); + let num_chan2 = Cell(num_chan); + let num_port = Cell(num_port); let new_future = do future::spawn || { - let mut num_chan = None; - num_chan <-> *num_chan2; - let mut num_port1 = None; - num_port1 <-> *num_port; - thread_ring(i, msg_per_task, - option::unwrap(num_chan), - option::unwrap(num_port1)) + let num_chan = num_chan2.take(); + let num_port1 = num_port.take(); + thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); num_chan = Some(new_chan); diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index eaae8370d6b8b..98c0129918a47 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -87,17 +87,12 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = ~mut None; - *num_chan2 <-> num_chan; - let num_port = ~mut Some(num_port); - let new_future = do future::spawn || { - let mut num_chan = None; - num_chan <-> *num_chan2; - let mut num_port1 = None; - num_port1 <-> *num_port; - thread_ring(i, msg_per_task, - option::unwrap(num_chan), - option::unwrap(num_port1)) + let num_chan2 = Cell(num_chan); + let num_port = Cell(num_port); + let new_future = do future::spawn { + let num_chan = num_chan2.take(); + let num_port1 = num_port.take(); + thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); num_chan = Some(new_chan); diff --git a/src/test/bench/task-perf-jargon-metal-smoke.rs b/src/test/bench/task-perf-jargon-metal-smoke.rs index 49a06fd491cd0..9bdc5aae3f283 100644 --- a/src/test/bench/task-perf-jargon-metal-smoke.rs +++ b/src/test/bench/task-perf-jargon-metal-smoke.rs @@ -17,13 +17,15 @@ // // The filename is a song reference; google it in quotes. +use core::cell::Cell; + fn child_generation(gens_left: uint, -c: comm::Chan<()>) { // This used to be O(n^2) in the number of generations that ever existed. // With this code, only as many generations are alive at a time as tasks // alive at a time, - let c = ~mut Some(c); - do task::spawn_supervised || { - let c = option::swap_unwrap(c); + let c = Cell(c); + do task::spawn_supervised { + let c = c.take(); if gens_left & 1 == 1 { task::yield(); // shake things up a bit } diff --git a/src/test/compile-fail/mutable-huh-variance-deep.rs b/src/test/compile-fail/mutable-huh-variance-deep.rs index 4f0c6d7a4c87d..51d5a6177f6aa 100644 --- a/src/test/compile-fail/mutable-huh-variance-deep.rs +++ b/src/test/compile-fail/mutable-huh-variance-deep.rs @@ -11,9 +11,9 @@ // error-pattern: mismatched types fn main() { - let v = ~[mut @mut ~mut ~[0]]; + let v = @[mut @mut @mut @[0]]; - fn f(&&v: ~[mut @mut ~mut ~[const int]]) { + fn f(&&v: @[mut @mut @mut @[const int]]) { } f(v); diff --git a/src/test/compile-fail/mutable-huh-variance-unique.rs b/src/test/compile-fail/mutable-huh-variance-unique.rs deleted file mode 100644 index f2188911346e9..0000000000000 --- a/src/test/compile-fail/mutable-huh-variance-unique.rs +++ /dev/null @@ -1,21 +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. - -// error-pattern: mismatched types - -fn main() { - let v = ~mut ~[0]; - - fn f(&&v: ~mut ~[const int]) { - *v = ~[mut 3] - } - - f(v); -} diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index 4954bbfa09d06..0d7e2d2377c20 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use core::cell::Cell; + struct Port(@T); fn main() { @@ -25,11 +27,10 @@ fn main() { } } - let x = ~mut Some(foo(Port(@()))); + let x = Cell(foo(Port(@()))); do task::spawn { - let mut y = None; - *x <-> y; //~ ERROR value has non-owned type + let y = x.take(); //~ ERROR value has non-owned type log(error, y); } } diff --git a/src/test/compile-fail/unique-mut.rs b/src/test/compile-fail/unique-mut.rs deleted file mode 100644 index a3a197505a340..0000000000000 --- a/src/test/compile-fail/unique-mut.rs +++ /dev/null @@ -1,14 +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. - -//error-pattern:mismatched types -fn main() { - let i: ~int = ~mut 0; -} diff --git a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs index 9724717f2d580..b11a5356f698c 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs @@ -20,7 +20,7 @@ fn borrow(x: &int, f: fn(x: &int)) { struct F { f: ~int } pub fn main() { - let mut x = ~mut @F{f: ~3}; + let mut x = ~@F{f: ~3}; do borrow(x.f) |b_x| { assert *b_x == 3; assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)); diff --git a/src/test/run-pass/explicit-self-closures.rs b/src/test/run-pass/explicit-self-closures.rs index 4c12b6ad47c2f..d40b2f72ae8ba 100644 --- a/src/test/run-pass/explicit-self-closures.rs +++ b/src/test/run-pass/explicit-self-closures.rs @@ -21,9 +21,6 @@ impl Box { fn set_many2(@mut self, xs: &[uint]) { for xs.each |x| { self.x = *x; } } - fn set_many3(~mut self, xs: &[uint]) { - for xs.each |x| { self.x = *x; } - } } pub fn main() {} diff --git a/src/test/run-pass/intrinsic-atomics.rs b/src/test/run-pass/intrinsic-atomics.rs index eb10a51c0bd65..7d5bf65dad7c1 100644 --- a/src/test/run-pass/intrinsic-atomics.rs +++ b/src/test/run-pass/intrinsic-atomics.rs @@ -29,7 +29,7 @@ extern mod rusti { pub fn main() { unsafe { - let x = ~mut 1; + let mut x = ~1; assert rusti::atomic_cxchg(x, 1, 2) == 1; assert *x == 2; diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 249d1c21376bd..b97ebb04f716d 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -318,18 +318,16 @@ pub fn main() { // Commented out because of option::get error let (client_, server_) = pingpong::init(); - let client_ = ~mut Some(client_); - let server_ = ~mut Some(server_); + let client_ = Cell(client_); + let server_ = Cell(server_); task::spawn {|client_| - let mut client__ = none; - *client_ <-> client__; - client(option::unwrap(client__)); + let client__ = client_.take(); + client(client__); }; task::spawn {|server_| - let mut server_ËŠ = none; - *server_ <-> server_ËŠ; - server(option::unwrap(server_ËŠ)); + let server__ = server_.take(); + server(server_ËŠ); }; */ } diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index 2ada6df76a6a8..2b270a54d80a0 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -14,6 +14,7 @@ // experiment with what code the compiler should generate for bounded // protocols. +use core::cell::Cell; // This was generated initially by the pipe compiler, but it's been // modified in hopefully straightforward ways. @@ -111,16 +112,14 @@ mod test { pub fn main() { let (client_, server_) = ::pingpong::init(); - let client_ = ~mut Some(client_); - let server_ = ~mut Some(server_); - do task::spawn || { - let mut client__ = None; - *client_ <-> client__; - test::client(option::unwrap(client__)); + let client_ = Cell(client_); + let server_ = Cell(server_); + do task::spawn { + let client__ = client_.take(); + test::client(client__); }; - do task::spawn || { - let mut server_ËŠ = None; - *server_ <-> server_ËŠ; - test::server(option::unwrap(server_ËŠ)); + do task::spawn { + let server__ = server_.take(); + test::server(server__); }; } diff --git a/src/test/run-pass/pipe-pingpong-proto.rs b/src/test/run-pass/pipe-pingpong-proto.rs index 050ff76ef9b75..c51c073362278 100644 --- a/src/test/run-pass/pipe-pingpong-proto.rs +++ b/src/test/run-pass/pipe-pingpong-proto.rs @@ -12,6 +12,7 @@ // An example to make sure the protocol parsing syntax extension works. +use core::cell::Cell; use core::option; proto! pingpong ( @@ -49,17 +50,15 @@ mod test { pub fn main() { let (client_, server_) = pingpong::init(); - let client_ = ~mut Some(client_); - let server_ = ~mut Some(server_); + let client_ = Cell(client_); + let server_ = Cell(server_); - do task::spawn || { - let mut client__ = None; - *client_ <-> client__; - test::client(option::unwrap(client__)); + do task::spawn { + let client__ = client_.take(); + test::client(client__); }; - do task::spawn || { - let mut server_ËŠ = None; - *server_ <-> server_ËŠ; - test::server(option::unwrap(server_ËŠ)); + do task::spawn { + let server__ = server_.take(); + test::server(server__); }; } diff --git a/src/test/run-pass/pure-sum.rs b/src/test/run-pass/pure-sum.rs index f4c92c869e46e..cac6b4ef34932 100644 --- a/src/test/run-pass/pure-sum.rs +++ b/src/test/run-pass/pure-sum.rs @@ -20,7 +20,7 @@ pure fn sums_to(v: ~[int], sum: int) -> bool { } pure fn sums_to_using_uniq(v: ~[int], sum: int) -> bool { - let mut i = 0u, sum0 = ~mut 0; + let mut i = 0u, sum0 = ~0; while i < v.len() { *sum0 += v[i]; i += 1u; @@ -40,7 +40,7 @@ pure fn sums_to_using_rec(v: ~[int], sum: int) -> bool { struct F { f: T } pure fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool { - let mut i = 0u, sum0 = F {f: ~mut 0}; + let mut i = 0u, sum0 = F {f: ~0}; while i < v.len() { *sum0.f += v[i]; i += 1u; diff --git a/src/test/run-pass/rcvr-borrowed-to-region.rs b/src/test/run-pass/rcvr-borrowed-to-region.rs index 61cb473bf8fb2..7011f5ba1add0 100644 --- a/src/test/run-pass/rcvr-borrowed-to-region.rs +++ b/src/test/run-pass/rcvr-borrowed-to-region.rs @@ -31,7 +31,7 @@ pub fn main() { debug!("y=%d", y); assert y == 6; - let x = ~mut 6; + let mut x = ~6; let y = x.get(); debug!("y=%d", y); assert y == 6; diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index b90c39ab34e50..991025a1ad282 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -13,6 +13,7 @@ // A port of task-killjoin to use a class with a dtor to manage // the join. +use core::cell::Cell; use core::comm::*; struct notify { @@ -49,11 +50,9 @@ fn joinable(f: fn~()) -> Port { *b = true; } let (p, c) = stream(); - let c = ~mut Some(c); + let c = Cell(c); do task::spawn_unlinked { - let mut cc = None; - *c <-> cc; - let ccc = option::unwrap(cc); + let ccc = c.take(); wrapper(ccc, f) } p diff --git a/src/test/run-pass/unique-assign-copy.rs b/src/test/run-pass/unique-assign-copy.rs index 4723356dcd0c7..1bb04aef28687 100644 --- a/src/test/run-pass/unique-assign-copy.rs +++ b/src/test/run-pass/unique-assign-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let i = ~mut 1; + let mut i = ~1; // Should be a copy let mut j; j = copy i; diff --git a/src/test/run-pass/unique-decl-init-copy.rs b/src/test/run-pass/unique-decl-init-copy.rs index 628eb7265a5c6..67e59cb08e0c0 100644 --- a/src/test/run-pass/unique-decl-init-copy.rs +++ b/src/test/run-pass/unique-decl-init-copy.rs @@ -9,9 +9,9 @@ // except according to those terms. pub fn main() { - let i = ~mut 1; + let mut i = ~1; // Should be a copy - let j = copy i; + let mut j = copy i; *i = 2; *j = 3; assert *i == 2; diff --git a/src/test/run-pass/unique-in-vec-copy.rs b/src/test/run-pass/unique-in-vec-copy.rs index 54ea0258c7c6f..ac8796674abb8 100644 --- a/src/test/run-pass/unique-in-vec-copy.rs +++ b/src/test/run-pass/unique-in-vec-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let a = ~[~mut 10]; + let mut a = ~[~10]; let b = copy a; assert *a[0] == 10; diff --git a/src/test/run-pass/unique-mutable.rs b/src/test/run-pass/unique-mutable.rs index c52d3b563ac55..8784dbeb0af40 100644 --- a/src/test/run-pass/unique-mutable.rs +++ b/src/test/run-pass/unique-mutable.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let i = ~mut 0; + let mut i = ~0; *i = 1; assert *i == 1; } From 24893e8d02d70045254082067c0c6141b7946783 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Feb 2013 15:54:13 -0800 Subject: [PATCH 22/85] libsyntax: Stop parsing `~mut` --- src/libsyntax/parse/obsolete.rs | 7 +++++++ src/libsyntax/parse/parser.rs | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 1ae8786e09bb2..7b3030124b72f 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 853b140805027..af25a4f6e58dc 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) } From 96bdc349303c1bd55ebba4e2dd5f7f51e087dad2 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Feb 2013 17:03:31 -0800 Subject: [PATCH 23/85] librustc: De-[mut] librustc (remove all mutable arrays). rs=demuting --- src/librustc/middle/liveness.rs | 33 ++++++++++++--------------- src/librustc/middle/trans/type_use.rs | 14 ++++++------ 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 75bf7cf26091c..96aa41f780913 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -667,8 +667,8 @@ struct Liveness { tcx: ty::ctxt, ir: @mut IrMaps, s: Specials, - successors: ~[mut LiveNode], - users: ~[mut Users], + successors: @mut ~[LiveNode], + users: @mut ~[Users], // The list of node IDs for the nested loop scopes // we're in. loop_scope: DVec, @@ -684,14 +684,9 @@ fn Liveness(ir: @mut IrMaps, specials: Specials) -> Liveness { ir: ir, tcx: ir.tcx, s: specials, - successors: - vec::cast_to_mut( - vec::from_elem(ir.num_live_nodes, - invalid_node())), - users: - vec::cast_to_mut( - vec::from_elem(ir.num_live_nodes * ir.num_vars, - invalid_users())), + successors: @mut vec::from_elem(ir.num_live_nodes, invalid_node()), + users: @mut vec::from_elem(ir.num_live_nodes * ir.num_vars, + invalid_users()), loop_scope: DVec(), break_ln: HashMap(), cont_ln: HashMap() @@ -916,12 +911,13 @@ impl Liveness { let mut changed = false; do self.indices2(ln, succ_ln) |idx, succ_idx| { - changed |= copy_if_invalid(copy self.users[succ_idx].reader, - &mut self.users[idx].reader); - changed |= copy_if_invalid(copy self.users[succ_idx].writer, - &mut self.users[idx].writer); - if self.users[succ_idx].used && !self.users[idx].used { - self.users[idx].used = true; + let users = &mut *self.users; + changed |= copy_if_invalid(copy users[succ_idx].reader, + &mut users[idx].reader); + changed |= copy_if_invalid(copy users[succ_idx].writer, + &mut users[idx].writer); + if users[succ_idx].used && !users[idx].used { + users[idx].used = true; changed = true; } } @@ -956,7 +952,8 @@ impl Liveness { // Either read, write, or both depending on the acc bitset fn acc(&self, ln: LiveNode, var: Variable, acc: uint) { let idx = self.idx(ln, var); - let user = &mut self.users[idx]; + let users = &mut *self.users; + let user = &mut users[idx]; if (acc & ACC_WRITE) != 0 { user.reader = invalid_node(); @@ -970,7 +967,7 @@ impl Liveness { } if (acc & ACC_USE) != 0 { - self.users[idx].used = true; + user.used = true; } debug!("%s accesses[%x] %s: %s", diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index 3013f928b75da..2fc7497f5e33b 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -51,7 +51,7 @@ pub const use_tydesc: uint = 2u; /* Takes the tydesc, or compares */ pub struct Context { ccx: @CrateContext, - uses: ~[mut type_uses] + uses: @mut ~[type_uses] } pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) @@ -72,7 +72,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) let cx = Context { ccx: ccx, - uses: vec::cast_to_mut(vec::from_elem(n_tps, 0u)) + uses: @mut vec::from_elem(n_tps, 0u) }; match ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).sty { ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) | @@ -90,7 +90,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) } if fn_id_loc.crate != local_crate { - let uses = vec::cast_from_mut(copy cx.uses); + let uses = copy *cx.uses; ccx.type_use_cache.insert(fn_id, copy uses); return uses; } @@ -175,16 +175,16 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) ccx.tcx.sess.parse_sess.interner))); } } - let uses = vec::cast_from_mut(copy cx.uses); - // XXX: Bad copy, use @vec instead? + // XXX: Bad copies, use @vec instead? + let uses = copy *cx.uses; ccx.type_use_cache.insert(fn_id, copy uses); uses } pub fn type_needs(cx: Context, use_: uint, ty: ty::t) { // Optimization -- don't descend type if all params already have this use - for vec::each_mut(cx.uses) |u| { - if *u & use_ != use_ { + for uint::range(0, cx.uses.len()) |i| { + if cx.uses[i] & use_ != use_ { type_needs_inner(cx, use_, ty, @Nil); return; } From 8fceee6c88ee58a506b9d2d9f5f04c1dc423214c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Feb 2013 17:28:40 -0800 Subject: [PATCH 24/85] test: De-[mut] (remove all mutable arrays from) the tests. rs=demuting --- src/test/compile-fail/assign-super.rs | 15 ----- .../compile-fail/borrowck-assign-comp-idx.rs | 6 +- .../compile-fail/borrowck-loan-vec-content.rs | 6 +- .../borrowck-mut-slice-of-imm-vec.rs | 2 +- .../borrowck-mut-vec-as-imm-slice-bad.rs | 24 -------- .../borrowck-vec-pattern-move-tail.rs | 2 +- src/test/compile-fail/issue-2969.rs | 2 +- src/test/compile-fail/issue-3243.rs | 4 +- src/test/compile-fail/lub-in-args.rs | 3 - .../compile-fail/mutable-huh-variance-box.rs | 21 ------- .../compile-fail/mutable-huh-variance-deep.rs | 20 ------- .../compile-fail/mutable-huh-variance-ptr.rs | 26 --------- .../compile-fail/mutable-huh-variance-vec1.rs | 22 -------- .../compile-fail/mutable-huh-variance-vec2.rs | 22 -------- .../compile-fail/mutable-huh-variance-vec3.rs | 22 -------- .../compile-fail/mutable-huh-variance-vec4.rs | 56 ------------------- ...ns-infer-invariance-due-to-mutability-2.rs | 2 +- src/test/compile-fail/vec-add.rs | 26 ++++----- 18 files changed, 25 insertions(+), 256 deletions(-) delete mode 100644 src/test/compile-fail/assign-super.rs delete mode 100644 src/test/compile-fail/borrowck-mut-vec-as-imm-slice-bad.rs delete mode 100644 src/test/compile-fail/mutable-huh-variance-box.rs delete mode 100644 src/test/compile-fail/mutable-huh-variance-deep.rs delete mode 100644 src/test/compile-fail/mutable-huh-variance-ptr.rs delete mode 100644 src/test/compile-fail/mutable-huh-variance-vec1.rs delete mode 100644 src/test/compile-fail/mutable-huh-variance-vec2.rs delete mode 100644 src/test/compile-fail/mutable-huh-variance-vec3.rs delete mode 100644 src/test/compile-fail/mutable-huh-variance-vec4.rs diff --git a/src/test/compile-fail/assign-super.rs b/src/test/compile-fail/assign-super.rs deleted file mode 100644 index 17c7ff1bb6037..0000000000000 --- a/src/test/compile-fail/assign-super.rs +++ /dev/null @@ -1,15 +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() { - let mut x: ~[mut int] = ~[mut 3]; - let y: ~[int] = ~[3]; - x = y; //~ ERROR values differ in mutability -} diff --git a/src/test/compile-fail/borrowck-assign-comp-idx.rs b/src/test/compile-fail/borrowck-assign-comp-idx.rs index 21236dc4a83c5..ded47fc9f7fe2 100644 --- a/src/test/compile-fail/borrowck-assign-comp-idx.rs +++ b/src/test/compile-fail/borrowck-assign-comp-idx.rs @@ -11,7 +11,7 @@ type point = { x: int, y: int }; fn a() { - let mut p = ~[mut 1]; + let mut p = ~[1]; // Create an immutable pointer into p's contents: let _q: &int = &p[0]; //~ NOTE loan of mutable vec content granted here @@ -25,7 +25,7 @@ fn b() { // here we alias the mutable vector into an imm slice and try to // modify the original: - let mut p = ~[mut 1]; + let mut p = ~[1]; do borrow(p) { //~ NOTE loan of mutable vec content granted here p[0] = 5; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan @@ -35,7 +35,7 @@ fn b() { fn c() { // Legal because the scope of the borrow does not include the // modification: - let mut p = ~[mut 1]; + let mut p = ~[1]; borrow(p, ||{}); p[0] = 5; } diff --git a/src/test/compile-fail/borrowck-loan-vec-content.rs b/src/test/compile-fail/borrowck-loan-vec-content.rs index b0b22dcfe61d0..8457fce255ea3 100644 --- a/src/test/compile-fail/borrowck-loan-vec-content.rs +++ b/src/test/compile-fail/borrowck-loan-vec-content.rs @@ -17,13 +17,13 @@ fn takes_imm_elt(_v: &int, f: fn()) { } fn has_mut_vec_and_does_not_try_to_change_it() { - let v = ~[mut 1, 2, 3]; + let mut v = ~[1, 2, 3]; do takes_imm_elt(&v[0]) { } } fn has_mut_vec_but_tries_to_change_it() { - let v = ~[mut 1, 2, 3]; + let mut v = ~[1, 2, 3]; do takes_imm_elt(&v[0]) { //~ NOTE loan of mutable vec content granted here v[1] = 4; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan } @@ -34,7 +34,7 @@ fn takes_const_elt(_v: &const int, f: fn()) { } fn has_mut_vec_and_tries_to_change_it() { - let v = ~[mut 1, 2, 3]; + let mut v = ~[1, 2, 3]; do takes_const_elt(&const v[0]) { v[1] = 4; } diff --git a/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs b/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs index 51448d6061e2c..bc0340983ae34 100644 --- a/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs +++ b/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn write(v: &[mut int]) { +fn write(v: &mut [int]) { v[0] += 1; } diff --git a/src/test/compile-fail/borrowck-mut-vec-as-imm-slice-bad.rs b/src/test/compile-fail/borrowck-mut-vec-as-imm-slice-bad.rs deleted file mode 100644 index 43feb65c8b96b..0000000000000 --- a/src/test/compile-fail/borrowck-mut-vec-as-imm-slice-bad.rs +++ /dev/null @@ -1,24 +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 want_slice(v: &[int]) -> int { - let mut sum = 0; - for vec::each(v) |i| { sum += *i; } - return sum; -} - -fn has_mut_vec(+v: @~[mut int]) -> int { - want_slice(*v) //~ ERROR illegal borrow unless pure - //~^ NOTE impure due to access to impure function -} - -fn main() { - assert has_mut_vec(@~[mut 1, 2, 3]) == 6; -} diff --git a/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs b/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs index 941883f80f93e..16b48aedb0c7f 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs @@ -1,5 +1,5 @@ fn main() { - let a = [mut 1, 2, 3, 4]; + let mut a = [1, 2, 3, 4]; let _ = match a { [1, 2, ..tail] => tail, _ => core::util::unreachable() diff --git a/src/test/compile-fail/issue-2969.rs b/src/test/compile-fail/issue-2969.rs index 5e1b9397247d9..88c76fb31a1ff 100644 --- a/src/test/compile-fail/issue-2969.rs +++ b/src/test/compile-fail/issue-2969.rs @@ -12,7 +12,7 @@ fn main() { // See #2969 -- error message should be improved - let mut x = [mut 1, 2, 4]; + let mut x = [1, 2, 4]; let v : &int = &x[2]; x[2] = 6; assert *v == 6; diff --git a/src/test/compile-fail/issue-3243.rs b/src/test/compile-fail/issue-3243.rs index ac5c099e1146a..443fae619ba7b 100644 --- a/src/test/compile-fail/issue-3243.rs +++ b/src/test/compile-fail/issue-3243.rs @@ -9,8 +9,8 @@ // except according to those terms. // xfail-test -fn function() -> &[mut int] { - let mut x: &static/[mut int] = &[mut 1,2,3]; +fn function() -> &mut [int] { + let mut x: &static/mut [int] = &[1,2,3]; x[0] = 12345; x //~ ERROR bad } diff --git a/src/test/compile-fail/lub-in-args.rs b/src/test/compile-fail/lub-in-args.rs index c2879d7f27203..5c71ae38a64c0 100644 --- a/src/test/compile-fail/lub-in-args.rs +++ b/src/test/compile-fail/lub-in-args.rs @@ -11,8 +11,6 @@ fn two_args(x: T, y: T) { } fn main() { - let x: ~[mut int] = ~[mut 3]; - let y: ~[int] = ~[3]; let a: @mut int = @mut 3; let b: @int = @3; @@ -22,6 +20,5 @@ fn main() { // shortcoming of the current inference algorithm. These errors // are *not* desirable. - two_args(x, y); //~ ERROR (values differ in mutability) two_args(a, b); //~ ERROR (values differ in mutability) } diff --git a/src/test/compile-fail/mutable-huh-variance-box.rs b/src/test/compile-fail/mutable-huh-variance-box.rs deleted file mode 100644 index 316c832f0119e..0000000000000 --- a/src/test/compile-fail/mutable-huh-variance-box.rs +++ /dev/null @@ -1,21 +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. - -// error-pattern: mismatched types - -fn main() { - let v = @mut ~[0]; - - fn f(&&v: @mut ~[const int]) { - *v = ~[mut 3] - } - - f(v); -} diff --git a/src/test/compile-fail/mutable-huh-variance-deep.rs b/src/test/compile-fail/mutable-huh-variance-deep.rs deleted file mode 100644 index 51d5a6177f6aa..0000000000000 --- a/src/test/compile-fail/mutable-huh-variance-deep.rs +++ /dev/null @@ -1,20 +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. - -// error-pattern: mismatched types - -fn main() { - let v = @[mut @mut @mut @[0]]; - - fn f(&&v: @[mut @mut @mut @[const int]]) { - } - - f(v); -} diff --git a/src/test/compile-fail/mutable-huh-variance-ptr.rs b/src/test/compile-fail/mutable-huh-variance-ptr.rs deleted file mode 100644 index dba6f9ae3fa0f..0000000000000 --- a/src/test/compile-fail/mutable-huh-variance-ptr.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// error-pattern: mismatched types - -extern mod std; - -fn main() { - let mut a = ~[0]; - let v: *mut ~[int] = &mut a; - - fn f(&&v: *mut ~[const int]) { - unsafe { - *v = ~[mut 3] - } - } - - f(v); -} diff --git a/src/test/compile-fail/mutable-huh-variance-vec1.rs b/src/test/compile-fail/mutable-huh-variance-vec1.rs deleted file mode 100644 index c3f4636f898b1..0000000000000 --- a/src/test/compile-fail/mutable-huh-variance-vec1.rs +++ /dev/null @@ -1,22 +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() { - // Note: explicit type annot is required here - // because otherwise the inference gets smart - // and assigns a type of ~[mut ~[const int]]. - let v: ~[mut ~[int]] = ~[mut ~[0]]; - - fn f(&&v: ~[mut ~[const int]]) { - v[0] = ~[mut 3] - } - - f(v); //~ ERROR (values differ in mutability) -} diff --git a/src/test/compile-fail/mutable-huh-variance-vec2.rs b/src/test/compile-fail/mutable-huh-variance-vec2.rs deleted file mode 100644 index aeb06324341f4..0000000000000 --- a/src/test/compile-fail/mutable-huh-variance-vec2.rs +++ /dev/null @@ -1,22 +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() { - // Note: explicit type annot is required here - // because otherwise the inference gets smart - // and assigns a type of ~[mut ~[const int]]. - let v: ~[mut ~[mut int]] = ~[mut ~[mut 0]]; - - fn f(&&v: ~[mut ~[const int]]) { - v[0] = ~[3] - } - - f(v); //~ ERROR (values differ in mutability) -} diff --git a/src/test/compile-fail/mutable-huh-variance-vec3.rs b/src/test/compile-fail/mutable-huh-variance-vec3.rs deleted file mode 100644 index edc66536e9bac..0000000000000 --- a/src/test/compile-fail/mutable-huh-variance-vec3.rs +++ /dev/null @@ -1,22 +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() { - // Note: explicit type annot is required here - // because otherwise the inference gets smart - // and assigns a type of ~[mut ~[const int]]. - let v: ~[mut ~[mut ~[int]]] = ~[mut ~[mut ~[0]]]; - - fn f(&&v: ~[mut ~[mut ~[const int]]]) { - v[0][1] = ~[mut 3] - } - - f(v); //~ ERROR (values differ in mutability) -} diff --git a/src/test/compile-fail/mutable-huh-variance-vec4.rs b/src/test/compile-fail/mutable-huh-variance-vec4.rs deleted file mode 100644 index e0980826a2a59..0000000000000 --- a/src/test/compile-fail/mutable-huh-variance-vec4.rs +++ /dev/null @@ -1,56 +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() { - - // Note: here we do not have any type annotations - // but we do express conflicting requirements: - - let v = ~[mut ~[0]]; - let w = ~[mut ~[mut 0]]; - let x = ~[mut ~[mut 0]]; - - fn f(&&v: ~[mut ~[int]]) { - v[0] = ~[3] - } - - fn g(&&v: ~[const ~[const int]]) { - } - - fn h(&&v: ~[mut ~[mut int]]) { - v[0] = ~[mut 3] - } - - fn i(&&v: ~[mut ~[const int]]) { - v[0] = ~[mut 3] - } - - fn j(&&v: ~[~[const int]]) { - } - - f(v); - g(v); - h(v); //~ ERROR (values differ in mutability) - i(v); //~ ERROR (values differ in mutability) - j(v); //~ ERROR (values differ in mutability) - - f(w); //~ ERROR (values differ in mutability) - g(w); - h(w); - i(w); //~ ERROR (values differ in mutability) - j(w); //~ ERROR (values differ in mutability) - - // Note that without adding f() or h() to the mix, it is valid for - // x to have the type ~[mut ~[const int]], and thus we can safely - // call g() and i() but not j(): - g(x); - i(x); - j(x); //~ ERROR (values differ in mutability) -} diff --git a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-2.rs b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-2.rs index 1a20ca23faedb..4b637b0195c31 100644 --- a/src/test/compile-fail/regions-infer-invariance-due-to-mutability-2.rs +++ b/src/test/compile-fail/regions-infer-invariance-due-to-mutability-2.rs @@ -9,7 +9,7 @@ // except according to those terms. struct invariant { - f: @[mut &int] + f: @mut [&int] } fn to_same_lifetime(bi: invariant/&r) { diff --git a/src/test/compile-fail/vec-add.rs b/src/test/compile-fail/vec-add.rs index 0eaf40e110f10..0f51d34fc2ff2 100644 --- a/src/test/compile-fail/vec-add.rs +++ b/src/test/compile-fail/vec-add.rs @@ -14,7 +14,7 @@ // the right hand side in all cases. We are getting compiler errors // about this now, so I'm xfailing the test for now. -eholk -fn add(i: ~[int], m: ~[mut int], c: ~[const int]) { +fn add(i: ~[int], mut m: ~[int], c: ~[const int]) { // Check that: // (1) vectors of any two mutabilities can be added @@ -24,9 +24,9 @@ fn add(i: ~[int], m: ~[mut int], c: ~[const int]) { m + ~[3], ~[3]); - add(i + ~[mut 3], - m + ~[mut 3], - ~[mut 3]); + add(i + ~[3], + m + ~[3], + ~[3]); add(i + i, m + i, @@ -54,19 +54,19 @@ fn add(i: ~[int], m: ~[mut int], c: ~[const int]) { //~^ mismatched types ~[3]); - add(m + ~[mut 3], //~ ERROR mismatched types - m + ~[mut 3], - m + ~[mut 3]); + add(m + ~[3], //~ ERROR mismatched types + m + ~[3], + m + ~[3]); - add(i + ~[mut 3], - i + ~[mut 3], //~ ERROR mismatched types - i + ~[mut 3]); + add(i + ~[3], + i + ~[3], //~ ERROR mismatched types + i + ~[3]); - add(c + ~[mut 3], //~ ERROR binary operation + cannot be applied + add(c + ~[3], //~ ERROR binary operation + cannot be applied //~^ mismatched types - c + ~[mut 3], //~ ERROR binary operation + cannot be applied + c + ~[3], //~ ERROR binary operation + cannot be applied //~^ mismatched types - ~[mut 3]); + ~[3]); add(m + i, //~ ERROR mismatched types m + i, From 9b08cd4903f7b3b5bb193dec85b055f24ff09cb7 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Feb 2013 18:15:38 -0800 Subject: [PATCH 25/85] librustc: Make `&const [T]` mean the same thing as `&[const T]` --- src/librustc/middle/typeck/astconv.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 9269752b8ecf4..d0affaa170218 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -216,7 +216,8 @@ pub fn ast_ty_to_ty( match a_seq_ty.ty.node { ast::ty_vec(mt) => { let mut mt = ast_mt_to_mt(self, rscope, mt); - if a_seq_ty.mutbl == ast::m_mutbl { + if a_seq_ty.mutbl == ast::m_mutbl || + a_seq_ty.mutbl == ast::m_const { mt = ty::mt { ty: mt.ty, mutbl: ast::m_mutbl }; } return ty::mk_evec(tcx, mt, vst); From b79c4dc262227f0d09706a13f76fdb347ca6d70d Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Tue, 26 Feb 2013 21:32:36 +0900 Subject: [PATCH 26/85] Add non-exhaustive check for match guards Fix ICE while there is no remained arms after checking guards --- src/librustc/middle/check_match.rs | 6 +++++- src/test/compile-fail/match-non-exhaustive.rs | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/match-non-exhaustive.rs diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 85ed4e74efb71..fbe28d7ac9b8d 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -101,7 +101,11 @@ pub fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) { _ => { /* We assume only enum types can be uninhabited */ } } let arms = vec::concat(arms.filter_mapped(unguarded_pat)); - check_exhaustive(cx, ex.span, arms); + if arms.is_empty() { + cx.tcx.sess.span_err(ex.span, ~"non-exhaustive patterns"); + } else { + check_exhaustive(cx, ex.span, arms); + } } _ => () } diff --git a/src/test/compile-fail/match-non-exhaustive.rs b/src/test/compile-fail/match-non-exhaustive.rs new file mode 100644 index 0000000000000..a24d2ed4b7fba --- /dev/null +++ b/src/test/compile-fail/match-non-exhaustive.rs @@ -0,0 +1,14 @@ +// Copyright 2013 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() { + match 0 { 1 => () } //~ ERROR non-exhaustive patterns + match 0 { 0 if false => () } //~ ERROR non-exhaustive patterns +} From 42b0bacd76a9242fd44b2ec3e982d42f81dec6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20L=C3=B6bel?= Date: Tue, 26 Feb 2013 16:36:59 +0100 Subject: [PATCH 27/85] Removed deprecated `str()` functions in int-template.rs and uint-template.rs --- doc/tutorial.md | 2 +- src/libcore/num/int-template.rs | 5 ----- src/libcore/num/uint-template.rs | 5 ----- src/libfuzzer/fuzzer.rc | 4 ++-- src/librustc/metadata/tyencode.rs | 2 +- src/librustc/middle/freevars.rs | 2 +- src/libstd/time.rs | 20 ++++++++++---------- src/test/bench/shootout-pfib.rs | 2 +- src/test/run-pass/monad.rs | 2 +- src/test/run-pass/static-impl.rs | 2 +- src/test/run-pass/trait-generic.rs | 2 +- src/test/run-pass/trait-to-str.rs | 2 +- 12 files changed, 20 insertions(+), 30 deletions(-) diff --git a/doc/tutorial.md b/doc/tutorial.md index 41895ebed7c59..0017af9e021ea 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -556,7 +556,7 @@ let mut x = 5; loop { x += x - 3; if x % 5 == 0 { break; } - io::println(int::str(x)); + io::println(int::to_str(x)); } ~~~~ diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index 8d72878ef6acb..ef661d2160b64 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -265,11 +265,6 @@ pub pure fn to_str_radix(num: T, radix: uint) -> ~str { buf } -/// Convert to a string. -/// *Deprecated*, use to_str() instead. -#[inline(always)] -pub pure fn str(i: T) -> ~str { to_str(i) } - impl ToStr for T { #[inline(always)] pure fn to_str(&self) -> ~str { diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index 005f0f2b5a4df..8d5726b867920 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -229,11 +229,6 @@ pub pure fn to_str_radix(num: T, radix: uint) -> ~str { buf } -/// Convert to a string. -/// *Deprecated*, use to_str() instead. -#[inline(always)] -pub pure fn str(i: T) -> ~str { to_str(i) } - impl ToStr for T { #[inline(always)] pure fn to_str(&self) -> ~str { diff --git a/src/libfuzzer/fuzzer.rc b/src/libfuzzer/fuzzer.rc index a9ddfe8140455..634c1aff55529 100644 --- a/src/libfuzzer/fuzzer.rc +++ b/src/libfuzzer/fuzzer.rc @@ -290,7 +290,7 @@ pub fn check_variants_T( if L < 100 { do under(uint::min(L, 20)) |i| { - log(error, ~"Replacing... #" + uint::str(i)); + log(error, ~"Replacing... #" + uint::to_str(i)); let fname = str::from_slice(filename.to_str()); do under(uint::min(L, 30)) |j| { log(error, ~"With... " + stringifier(@things[j], intr)); @@ -415,7 +415,7 @@ pub fn check_running(exe_filename: &Path) -> happiness { } rc => { failed(~"Rust program ran but exited with status " + - int::str(rc)) + int::to_str(rc)) } } } diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 12d998ee9448f..dccbf7c778eb9 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -307,7 +307,7 @@ fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) { w.write_char('p'); w.write_str((cx.ds)(did)); w.write_char('|'); - w.write_str(uint::str(id)); + w.write_str(uint::to_str(id)); } ty::ty_self => { w.write_char('s'); diff --git a/src/librustc/middle/freevars.rs b/src/librustc/middle/freevars.rs index 2c39e41c57bc4..a3ef3833d9755 100644 --- a/src/librustc/middle/freevars.rs +++ b/src/librustc/middle/freevars.rs @@ -117,7 +117,7 @@ pub fn annotate_freevars(def_map: resolve::DefMap, crate: @ast::crate) -> pub fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info { match tcx.freevars.find(&fid) { - None => fail!(~"get_freevars: " + int::str(fid) + ~" has no freevars"), + None => fail!(~"get_freevars: "+int::to_str(fid)+~" has no freevars"), Some(d) => return d } } diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 0b8b6c8d34d68..c8379d3ef4444 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -842,7 +842,7 @@ priv fn do_strftime(format: &str, tm: &Tm) -> ~str { //'U' {} 'u' => { let i = tm.tm_wday as int; - int::str(if i == 0 { 7 } else { i }) + int::to_str(if i == 0 { 7 } else { i }) } //'V' {} 'v' => { @@ -852,10 +852,10 @@ priv fn do_strftime(format: &str, tm: &Tm) -> ~str { parse_type('Y', tm)) } //'W' {} - 'w' => int::str(tm.tm_wday as int), + 'w' => int::to_str(tm.tm_wday as int), //'X' {} //'x' {} - 'Y' => int::str(tm.tm_year as int + 1900), + 'Y' => int::to_str(tm.tm_year as int + 1900), 'y' => fmt!("%02d", (tm.tm_year as int + 1900) % 100), 'Z' => copy tm.tm_zone, 'z' => { @@ -902,15 +902,15 @@ mod tests { const some_future_date: i64 = 1577836800i64; // 2020-01-01T00:00:00Z let tv1 = get_time(); - log(debug, ~"tv1=" + uint::str(tv1.sec as uint) + ~" sec + " - + uint::str(tv1.nsec as uint) + ~" nsec"); + log(debug, ~"tv1=" + uint::to_str(tv1.sec as uint) + ~" sec + " + + uint::to_str(tv1.nsec as uint) + ~" nsec"); assert tv1.sec > some_recent_date; assert tv1.nsec < 1000000000i32; let tv2 = get_time(); - log(debug, ~"tv2=" + uint::str(tv2.sec as uint) + ~" sec + " - + uint::str(tv2.nsec as uint) + ~" nsec"); + log(debug, ~"tv2=" + uint::to_str(tv2.sec as uint) + ~" sec + " + + uint::to_str(tv2.nsec as uint) + ~" nsec"); assert tv2.sec >= tv1.sec; assert tv2.sec < some_future_date; @@ -927,13 +927,13 @@ mod tests { log(debug, ~"s0=" + float::to_str_digits(s0, 9u) + ~" sec"); assert s0 > 0.; let ns0 = (s0 * 1000000000.) as u64; - log(debug, ~"ns0=" + u64::str(ns0) + ~" ns"); + log(debug, ~"ns0=" + u64::to_str(ns0) + ~" ns"); - log(debug, ~"ns1=" + u64::str(ns1) + ~" ns"); + log(debug, ~"ns1=" + u64::to_str(ns1) + ~" ns"); assert ns1 >= ns0; let ns2 = precise_time_ns(); - log(debug, ~"ns2=" + u64::str(ns2) + ~" ns"); + log(debug, ~"ns2=" + u64::to_str(ns2) + ~" ns"); assert ns2 >= ns1; } diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index a8383c4647ec1..2853382136546 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -122,7 +122,7 @@ fn main() { let elapsed = stop - start; out.write_line(fmt!("%d\t%d\t%s", n, fibn, - u64::str(elapsed))); + u64::to_str(elapsed))); } } } diff --git a/src/test/run-pass/monad.rs b/src/test/run-pass/monad.rs index 5f4e6e984a44b..1f803f28e7a25 100644 --- a/src/test/run-pass/monad.rs +++ b/src/test/run-pass/monad.rs @@ -36,7 +36,7 @@ impl option_monad for Option { } fn transform(x: Option) -> Option<~str> { - x.bind(|n| Some(*n + 1) ).bind(|n| Some(int::str(*n)) ) + x.bind(|n| Some(*n + 1) ).bind(|n| Some(int::to_str(*n)) ) } pub fn main() { diff --git a/src/test/run-pass/static-impl.rs b/src/test/run-pass/static-impl.rs index 9d7c2fe446d32..201193fd738e8 100644 --- a/src/test/run-pass/static-impl.rs +++ b/src/test/run-pass/static-impl.rs @@ -30,7 +30,7 @@ trait uint_utils { } impl uint_utils for uint { - fn str() -> ~str { uint::str(self) } + fn str() -> ~str { uint::to_str(self) } fn multi(f: fn(uint)) { let mut c = 0u; while c < self { f(c); c += 1u; } diff --git a/src/test/run-pass/trait-generic.rs b/src/test/run-pass/trait-generic.rs index 1f32cc94de97d..4a6651fe20555 100644 --- a/src/test/run-pass/trait-generic.rs +++ b/src/test/run-pass/trait-generic.rs @@ -14,7 +14,7 @@ trait to_str { fn to_str() -> ~str; } impl to_str for int { - fn to_str() -> ~str { int::str(self) } + fn to_str() -> ~str { int::to_str(self) } } impl to_str for ~str { fn to_str() -> ~str { copy self } diff --git a/src/test/run-pass/trait-to-str.rs b/src/test/run-pass/trait-to-str.rs index 20e23c0fc58e7..23d03ba217209 100644 --- a/src/test/run-pass/trait-to-str.rs +++ b/src/test/run-pass/trait-to-str.rs @@ -21,7 +21,7 @@ trait to_str { } impl to_str for int { - fn to_str() -> ~str { int::str(self) } + fn to_str() -> ~str { int::to_str(self) } } impl to_str for ~[T] { From 4a9d4aa52e70eba52dad0719ed6e1eca95f1a2cc Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 26 Feb 2013 07:10:23 -0800 Subject: [PATCH 28/85] bench: Fix botched option dances. rs=demuting --- src/test/bench/msgsend-ring-mutex-arcs.rs | 9 +++++---- src/test/bench/msgsend-ring-pipes.rs | 8 ++++---- src/test/bench/msgsend-ring-rw-arcs.rs | 10 ++++++---- src/test/bench/shootout-chameneos-redux.rs | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 22045007134a0..12060a87850a0 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -19,6 +19,7 @@ extern mod std; use std::time; use std::arc; use std::future; +use core::cell::Cell; // A poor man's pipe. type pipe = arc::MutexARC<~[uint]>; @@ -77,7 +78,7 @@ fn main() { let msg_per_task = uint::from_str(args[2]).get(); let (num_chan, num_port) = init(); - let mut num_chan = Some(num_chan); + let mut num_chan = Cell(num_chan); let start = time::precise_time_s(); @@ -87,7 +88,7 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = Cell(num_chan); + let num_chan2 = Cell(num_chan.take()); let num_port = Cell(num_port); let new_future = do future::spawn() { let num_chan = num_chan2.take(); @@ -95,11 +96,11 @@ fn main() { thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); - num_chan = Some(new_chan); + num_chan.put_back(new_chan); }; // do our iteration - thread_ring(0, msg_per_task, option::unwrap(num_chan), num_port); + thread_ring(0, msg_per_task, num_chan.take(), num_port); // synchronize for futures.each |f| { f.get() }; diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index dfe5c6de832c1..56a46d3e006cc 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -71,7 +71,7 @@ fn main() { let msg_per_task = uint::from_str(args[2]).get(); let (num_chan, num_port) = ring::init(); - let mut num_chan = Some(num_chan); + let mut num_chan = Cell(num_chan); let start = time::precise_time_s(); @@ -81,7 +81,7 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = ring::init(); - let num_chan2 = Cell(num_chan); + let num_chan2 = Cell(num_chan.take()); let num_port = Cell(num_port); let new_future = do future::spawn || { let num_chan = num_chan2.take(); @@ -89,11 +89,11 @@ fn main() { thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); - num_chan = Some(new_chan); + num_chan.put_back(new_chan); }; // do our iteration - thread_ring(0, msg_per_task, option::unwrap(num_chan), num_port); + thread_ring(0, msg_per_task, num_chan.take(), num_port); // synchronize for futures.each |f| { f.get() }; diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 98c0129918a47..57d04abb414c1 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -16,6 +16,8 @@ // This also serves as a pipes test, because ARCs are implemented with pipes. extern mod std; + +use core::cell::Cell; use std::time; use std::arc; use std::future; @@ -77,7 +79,7 @@ fn main() { let msg_per_task = uint::from_str(args[2]).get(); let (num_chan, num_port) = init(); - let mut num_chan = Some(num_chan); + let mut num_chan = Cell(num_chan); let start = time::precise_time_s(); @@ -87,7 +89,7 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = Cell(num_chan); + let num_chan2 = Cell(num_chan.take()); let num_port = Cell(num_port); let new_future = do future::spawn { let num_chan = num_chan2.take(); @@ -95,11 +97,11 @@ fn main() { thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); - num_chan = Some(new_chan); + num_chan.put_back(new_chan); }; // do our iteration - thread_ring(0, msg_per_task, option::unwrap(num_chan), num_port); + thread_ring(0, msg_per_task, num_chan.take(), num_port); // synchronize for futures.each |f| { f.get() }; diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 42a1e4b504660..111219974d098 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -14,7 +14,7 @@ extern mod std; use std::oldmap; use std::oldmap::HashMap; use std::sort; -use std::cell::Cell; +use core::cell::Cell; use core::comm::*; fn print_complements() { From c9dd917fad8ead284643b9873de60e3df894fb59 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 26 Feb 2013 10:02:36 -0800 Subject: [PATCH 29/85] doc: Remove references to mut fields. rs=demuting --- doc/rust.md | 4 +- doc/tutorial-borrowed-ptr.md | 161 +---------------------------------- doc/tutorial-ffi.md | 14 +-- doc/tutorial.md | 27 +++--- 4 files changed, 25 insertions(+), 181 deletions(-) diff --git a/doc/rust.md b/doc/rust.md index 975e4bbb8a209..9a3d087f3d723 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -1610,11 +1610,11 @@ The following are examples of structure expressions: ~~~~ # struct Point { x: float, y: float } # struct TuplePoint(float, float); -# mod game { pub struct User { name: &str, age: uint, mut score: uint } } +# mod game { pub struct User { name: &str, age: uint, score: uint } } # use game; Point {x: 10f, y: 20f}; TuplePoint(10f, 20f); -let u = game::User {name: "Joe", age: 35u, mut score: 100_000}; +let u = game::User {name: "Joe", age: 35u, score: 100_000}; ~~~~ A structure expression forms a new value of the named structure type. diff --git a/doc/tutorial-borrowed-ptr.md b/doc/tutorial-borrowed-ptr.md index c13b2528598c1..0c1624706bfeb 100644 --- a/doc/tutorial-borrowed-ptr.md +++ b/doc/tutorial-borrowed-ptr.md @@ -348,12 +348,12 @@ mutations: ~~~ {.xfail-test} fn example3() -> int { struct R { g: int } - struct S { mut f: ~R } + struct S { f: ~R } - let mut x = ~S {mut f: ~R {g: 3}}; + let mut x = ~S {f: ~R {g: 3}}; let y = &x.f.g; - x = ~S {mut f: ~R {g: 4}}; // Error reported here. - x.f = ~R {g: 5}; // Error reported here. + x = ~S {f: ~R {g: 4}}; // Error reported here. + x.f = ~R {g: 5}; // Error reported here. *y } ~~~ @@ -362,91 +362,6 @@ In this case, two errors are reported, one when the variable `x` is modified and another when `x.f` is modified. Either modification would invalidate the pointer `y`. -Things get trickier when the unique box is not uniquely owned by the -stack frame, or when there is no way for the compiler to determine the -box's owner. Consider a program like this: - -~~~ {.xfail-test} -struct R { g: int } -struct S { mut f: ~R } -fn example5a(x: @S, callback: @fn()) -> int { - let y = &x.f.g; // Error reported here. - ... - callback(); - ... -# return 0; -} -~~~ - -Here the heap looks something like: - -~~~ {.notrust} - Stack Managed Heap Exchange Heap - - x +------+ +-------------+ +------+ - | @... | ----> | mut f: ~... | --+-> | g: 3 | - y +------+ +-------------+ | +------+ - | &int | -------------------------+ - +------+ -~~~ - -In this case, the owning reference to the value being borrowed is -`x.f`. Moreover, `x.f` is both mutable and *aliasable*. Aliasable -means that there may be other pointers to that same managed box, so -even if the compiler were to prove an absence of mutations to `x.f`, -code could mutate `x.f` indirectly by changing an alias of -`x`. Therefore, to be safe, the compiler only accepts *pure* actions -during the lifetime of `y`. We define what "pure" means in the section -on [purity](#purity). - -Besides ensuring purity, the only way to borrow the interior of a -unique found in aliasable memory is to ensure that the borrowed field -itself is also unique, as in the following example: - -~~~ -struct R { g: int } -struct S { f: ~R } -fn example5b(x: @S) -> int { - let y = &x.f.g; - ... -# return 0; -} -~~~ - -Here, the field `f` is not declared as mutable. But that is enough for -the compiler to know that, even if aliases to `x` exist, the field `f` -cannot be changed and hence the unique box `g` will remain valid. - -If you do have a unique box in a mutable field, and you wish to borrow -it, one option is to use the swap operator to move that unique box -onto your stack: - -~~~ -struct R { g: int } -struct S { mut f: ~R } -fn example5c(x: @S) -> int { - let mut v = ~R {g: 0}; - v <-> x.f; // Swap v and x.f - { // Block constrains the scope of `y`: - let y = &v.g; - ... - } - x.f = v; // Replace x.f - ... -# return 0; -} -~~~ - -Of course, this has the side effect of modifying your managed box for -the duration of the borrow, so it only works when you know that you -won't be accessing that same box for the duration of the loan. Also, -it is sometimes necessary to introduce additional blocks to constrain -the scope of the loan. In this example, the borrowed pointer `y` -would still be in scope when you moved the value `v` back into `x.f`, -and hence moving `v` would be considered illegal. You cannot move -values if they are the targets of valid outstanding loans. Introducing -the block restricts the scope of `y`, making the move legal. - # Borrowing and enums The previous example showed that the type system forbids any borrowing @@ -558,11 +473,6 @@ permit `ref` bindings into data owned by the stack frame even if the data are mutable, but otherwise it requires that the data reside in immutable memory. -> ***Note:*** Right now, pattern bindings not explicitly annotated -> with `ref` or `copy` use a special mode of "implicit by reference". -> This is changing as soon as we finish updating all the existing code -> in the compiler that relies on the current settings. - # Returning borrowed pointers So far, all of the examples we've looked at use borrowed pointers in a @@ -745,69 +655,6 @@ fn select(shape: &Shape, threshold: float, This is equivalent to the previous definition. -# Purity - -As mentioned before, the Rust compiler offers a kind of escape hatch -that permits borrowing of any data, as long as the actions that occur -during the lifetime of the borrow are pure. Pure actions are those -that only modify data owned by the current stack frame. The compiler -can therefore permit arbitrary pointers into the heap, secure in the -knowledge that no pure action will ever cause them to become -invalidated (the compiler must still track data on the stack which is -borrowed and enforce those rules normally, of course). A pure function -in Rust is referentially transparent: it returns the same results -given the same (observably equivalent) inputs. That is because while -pure functions are allowed to modify data, they may only modify -*stack-local* data, which cannot be observed outside the scope of the -function itself. (Using an `unsafe` block invalidates this guarantee.) - -Let’s revisit a previous example and show how purity can affect -typechecking. Here is `example5a()`, which borrows the interior of a -unique box found in an aliasable, mutable location, only now we’ve -replaced the `...` with some specific code: - -~~~ -struct R { g: int } -struct S { mut f: ~R } -fn example5a(x: @S ...) -> int { - let y = &x.f.g; // Unsafe - *y + 1 -} -~~~ - -The new code simply returns an incremented version of `y`. This code -clearly doesn't mutate the heap, so the compiler is satisfied. - -But suppose we wanted to pull the increment code into a helper, like -this: - -~~~ -fn add_one(x: &int) -> int { *x + 1 } -~~~ - -We can now update `example5a()` to use `add_one()`: - -~~~ -# struct R { g: int } -# struct S { mut f: ~R } -# pure fn add_one(x: &int) -> int { *x + 1 } -fn example5a(x: @S ...) -> int { - let y = &x.f.g; - add_one(y) // Error reported here -} -~~~ - -But now the compiler will report an error again. The reason is that it -only considers one function at a time (like most typecheckers), and -so it does not know that `add_one()` consists of pure code. We can -help the compiler by labeling `add_one()` as pure: - -~~~ -pure fn add_one(x: &int) -> int { *x + 1 } -~~~ - -With this change, the modified version of `example5a()` will again compile. - # Conclusion So there you have it: a (relatively) brief tour of the borrowed pointer diff --git a/doc/tutorial-ffi.md b/doc/tutorial-ffi.md index c3def1f4b27c4..b7659376ed65c 100644 --- a/doc/tutorial-ffi.md +++ b/doc/tutorial-ffi.md @@ -220,21 +220,21 @@ extern mod std; use libc::c_ulonglong; struct timeval { - mut tv_sec: c_ulonglong, - mut tv_usec: c_ulonglong + tv_sec: c_ulonglong, + tv_usec: c_ulonglong } #[nolink] extern mod lib_c { - fn gettimeofday(tv: *timeval, tz: *()) -> i32; + fn gettimeofday(tv: *mut timeval, tz: *()) -> i32; } fn unix_time_in_microseconds() -> u64 { unsafe { - let x = timeval { - mut tv_sec: 0 as c_ulonglong, - mut tv_usec: 0 as c_ulonglong + let mut x = timeval { + tv_sec: 0 as c_ulonglong, + tv_usec: 0 as c_ulonglong }; - lib_c::gettimeofday(ptr::addr_of(&x), ptr::null()); + lib_c::gettimeofday(&mut x, ptr::null()); return (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64); } } diff --git a/doc/tutorial.md b/doc/tutorial.md index 41895ebed7c59..909bad9e2f40b 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -583,19 +583,16 @@ Inherited mutability means that any field of a struct may be mutable, if the struct is in a mutable slot (or a field of a struct in a mutable slot, and so forth). -A struct that is not mutable due to inherited mutability may declare some -of its fields nevertheless mutable, using the `mut` keyword. - ~~~~ struct Stack { content: ~[int], - mut head: uint + head: uint } ~~~~ -With a value of such a type, you can do `mystack.head += 1`. If `mut` were -omitted from the type, such an assignment to a struct without inherited -mutability would result in a type error. +With a value (say, `mystack`) of such a type in a mutable location, you can do +`mystack.head += 1`. But in an immutable location, such an assignment to a +struct without inherited mutability would result in a type error. `match` patterns destructure structs. The basic syntax is `Name { fieldname: pattern, ... }`: @@ -938,19 +935,19 @@ type that contains managed boxes or other managed types. ~~~ // A linked list node struct Node { - mut next: MaybeNode, - mut prev: MaybeNode, + next: MaybeNode, + prev: MaybeNode, payload: int } enum MaybeNode { - SomeNode(@Node), + SomeNode(@mut Node), NoNode } -let node1 = @Node { next: NoNode, prev: NoNode, payload: 1 }; -let node2 = @Node { next: NoNode, prev: NoNode, payload: 2 }; -let node3 = @Node { next: NoNode, prev: NoNode, payload: 3 }; +let node1 = @mut Node { next: NoNode, prev: NoNode, payload: 1 }; +let node2 = @mut Node { next: NoNode, prev: NoNode, payload: 2 }; +let node3 = @mut Node { next: NoNode, prev: NoNode, payload: 3 }; // Link the three list nodes together node1.next = SomeNode(node2); @@ -2300,8 +2297,8 @@ mod farm { # impl Human { fn rest(&self) { } } # pub fn make_me_a_farm() -> farm::Farm { farm::Farm { chickens: ~[], cows: ~[], farmer: Human(0) } } pub struct Farm { - priv mut chickens: ~[Chicken], - priv mut cows: ~[Cow], + priv chickens: ~[Chicken], + priv cows: ~[Cow], farmer: Human } From ca147a029e2052f03029a78602c292e4ec267ed6 Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 26 Feb 2013 10:10:21 -0800 Subject: [PATCH 30/85] Change imported macros to use leaky modules rather than leaky functions. --- src/librustc/middle/trans/_match.rs | 5 ----- src/librustc/middle/trans/controlflow.rs | 5 ----- src/librustc/middle/trans/expr.rs | 2 -- src/librustc/middle/trans/macros.rs | 11 +++++------ src/librustc/middle/trans/meth.rs | 5 ----- src/librustc/middle/typeck/infer/combine.rs | 5 ----- src/librustc/middle/typeck/infer/lub.rs | 5 ----- src/librustc/middle/typeck/infer/macros.rs | 5 ++--- src/librustc/middle/typeck/infer/mod.rs | 1 + src/librustc/middle/typeck/infer/sub.rs | 4 ---- src/librustc/rustc.rc | 1 + 11 files changed, 9 insertions(+), 40 deletions(-) diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index df6073f9339b4..3686c31ea6e64 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -172,11 +172,6 @@ use syntax::ast_util; use syntax::codemap::span; use syntax::print::pprust::pat_to_str; -pub fn macros() { - // FIXME(#3114): Macro import/export. - include!("macros.rs"); -} - // An option identifying a literal: either a unit-like struct or an // expression. pub enum Lit { diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index 4cf12576a78ee..57cb1a937764c 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -18,11 +18,6 @@ use middle::trans::datum::*; use core::str; -pub fn macros() { - // FIXME(#3114): Macro import/export. - include!("macros.rs"); -} - pub fn trans_block(bcx: block, b: &ast::blk, dest: expr::Dest) -> block { let _icx = bcx.insn_ctxt("trans_block"); let mut bcx = bcx; diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index a7b12d13d4e12..6226e83d046b3 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -149,8 +149,6 @@ use syntax::codemap::spanned; // These are passed around by the code generating functions to track the // destination of a computation's value. -fn macros() { include!("macros.rs"); } // FIXME(#3114): Macro import/export. - pub enum Dest { SaveIn(ValueRef), Ignore, diff --git a/src/librustc/middle/trans/macros.rs b/src/librustc/middle/trans/macros.rs index dad4a8bd2bf4b..14ed7692661d4 100644 --- a/src/librustc/middle/trans/macros.rs +++ b/src/librustc/middle/trans/macros.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -{ +#[macro_escape]; macro_rules! unpack_datum( ($bcx: ident, $inp: expr) => ( @@ -18,7 +18,7 @@ macro_rules! unpack_datum( db.datum } ) -); +) macro_rules! unpack_result( ($bcx: ident, $inp: expr) => ( @@ -28,7 +28,7 @@ macro_rules! unpack_result( db.val } ) -); +) macro_rules! trace_span( ($bcx: ident, $sp: expr, $str: expr) => ( @@ -39,7 +39,7 @@ macro_rules! trace_span( } } ) -); +) macro_rules! trace( ($bcx: ident, $str: expr) => ( @@ -50,6 +50,5 @@ macro_rules! trace( } } ) -); +) -} diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 02ea29f915d69..07b6556df6aa0 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -39,11 +39,6 @@ use syntax::ast_util::local_def; use syntax::print::pprust::expr_to_str; use syntax::{ast, ast_map}; -pub fn macros() { - // FIXME(#3114): Macro import/export. - include!("macros.rs"); -} - /** The main "translation" pass for methods. Generates code for non-monomorphized methods only. Other methods will diff --git a/src/librustc/middle/typeck/infer/combine.rs b/src/librustc/middle/typeck/infer/combine.rs index 1c6b1507629c5..f63dac4c5ae55 100644 --- a/src/librustc/middle/typeck/infer/combine.rs +++ b/src/librustc/middle/typeck/infer/combine.rs @@ -72,11 +72,6 @@ use syntax::ast::{Onceness, purity, ret_style}; use syntax::ast; use syntax::codemap::span; -pub fn macros() { - // FIXME(#3114): Macro import/export. - include!("macros.rs"); -} - pub trait Combine { fn infcx(&self) -> @mut InferCtxt; fn tag(&self) -> ~str; diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/typeck/infer/lub.rs index df4b8c0be09b5..4fee6f061b1ca 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/typeck/infer/lub.rs @@ -24,11 +24,6 @@ use std::list; use syntax::ast::{Many, Once, extern_fn, m_const, impure_fn, noreturn}; use syntax::ast::{pure_fn, ret_style, return_val, unsafe_fn}; -pub fn macros() { - // FIXME(#3114): Macro import/export. - include!("macros.rs"); -} - pub enum Lub = CombineFields; // least-upper-bound: common supertype pub impl Lub { diff --git a/src/librustc/middle/typeck/infer/macros.rs b/src/librustc/middle/typeck/infer/macros.rs index 01174d1620ada..e02772d951c55 100644 --- a/src/librustc/middle/typeck/infer/macros.rs +++ b/src/librustc/middle/typeck/infer/macros.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -{ +#[macro_escape]; macro_rules! if_ok( ($inp: expr) => ( @@ -17,6 +17,5 @@ macro_rules! if_ok( Err(e) => { return Err(e); } } ) -); +) -} diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index b55b45a318341..8bb1f2f47e5e4 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -287,6 +287,7 @@ use syntax::codemap; use syntax::ast_util; use syntax::codemap::span; +pub mod macros; pub mod combine; pub mod glb; pub mod lattice; diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index 661c67dbefc62..12a9a6c4076e7 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -25,10 +25,6 @@ use std::list::Nil; use std::list; use syntax::ast::{m_const, purity, ret_style}; -pub fn macros() { - // FIXME(#3114): Macro import/export. - include!("macros.rs"); -} pub enum Sub = CombineFields; // "subtype", "subregion" etc diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc index 01758a1845d7c..617a64f32d3ec 100644 --- a/src/librustc/rustc.rc +++ b/src/librustc/rustc.rc @@ -49,6 +49,7 @@ use back_ = back; pub mod middle { pub mod trans { + pub mod macros; pub mod inline; pub mod monomorphize; pub mod controlflow; From 598e8141524c0dd316c586738c9920cd4b98fe93 Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 26 Feb 2013 10:11:10 -0800 Subject: [PATCH 31/85] Hoist macro defs out of inner function --- src/libcore/hash.rs | 62 ++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index 7c1448c88eef7..4a1a1952907c6 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -186,6 +186,39 @@ fn SipState(key0: u64, key1: u64) -> SipState { state } +// sadly, these macro definitions can't appear later, +// because they're needed in the following defs; +// this design could be improved. + +macro_rules! u8to64_le ( + ($buf:expr, $i:expr) => + ($buf[0+$i] as u64 | + $buf[1+$i] as u64 << 8 | + $buf[2+$i] as u64 << 16 | + $buf[3+$i] as u64 << 24 | + $buf[4+$i] as u64 << 32 | + $buf[5+$i] as u64 << 40 | + $buf[6+$i] as u64 << 48 | + $buf[7+$i] as u64 << 56) +) + +macro_rules! rotl ( + ($x:expr, $b:expr) => + (($x << $b) | ($x >> (64 - $b))) +) + +macro_rules! compress ( + ($v0:expr, $v1:expr, $v2:expr, $v3:expr) => + ({ + $v0 += $v1; $v1 = rotl!($v1, 13); $v1 ^= $v0; + $v0 = rotl!($v0, 32); + $v2 += $v3; $v3 = rotl!($v3, 16); $v3 ^= $v2; + $v0 += $v3; $v3 = rotl!($v3, 21); $v3 ^= $v0; + $v2 += $v1; $v1 = rotl!($v1, 17); $v1 ^= $v2; + $v2 = rotl!($v2, 32); + }) +) + impl io::Writer for SipState { @@ -193,35 +226,6 @@ impl io::Writer for SipState { #[inline(always)] fn write(&self, msg: &[const u8]) { - macro_rules! u8to64_le ( - ($buf:expr, $i:expr) => - ($buf[0+$i] as u64 | - $buf[1+$i] as u64 << 8 | - $buf[2+$i] as u64 << 16 | - $buf[3+$i] as u64 << 24 | - $buf[4+$i] as u64 << 32 | - $buf[5+$i] as u64 << 40 | - $buf[6+$i] as u64 << 48 | - $buf[7+$i] as u64 << 56) - ); - - macro_rules! rotl ( - ($x:expr, $b:expr) => - (($x << $b) | ($x >> (64 - $b))) - ); - - macro_rules! compress ( - ($v0:expr, $v1:expr, $v2:expr, $v3:expr) => - ({ - $v0 += $v1; $v1 = rotl!($v1, 13); $v1 ^= $v0; - $v0 = rotl!($v0, 32); - $v2 += $v3; $v3 = rotl!($v3, 16); $v3 ^= $v2; - $v0 += $v3; $v3 = rotl!($v3, 21); $v3 ^= $v0; - $v2 += $v1; $v1 = rotl!($v1, 17); $v1 ^= $v2; - $v2 = rotl!($v2, 32); - }) - ); - let length = msg.len(); self.length += length; From 5328f3c1ee50a6140638a705551d5bb232921c4d Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 26 Feb 2013 10:11:47 -0800 Subject: [PATCH 32/85] Remove space from the middle of path --- src/librustdoc/extract.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/extract.rs b/src/librustdoc/extract.rs index 0184945d6f8fd..f129df3f300c1 100644 --- a/src/librustdoc/extract.rs +++ b/src/librustdoc/extract.rs @@ -161,7 +161,7 @@ fn nmoddoc_from_mod( ast::foreign_item_const(*) => {} // XXX: Not implemented. } } - doc:: NmodDoc { + doc::NmodDoc { item: itemdoc, fns: fns, index: None From 5e319fb2827903d6cb0c0d9d0af638c3f9503c81 Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 26 Feb 2013 10:12:44 -0800 Subject: [PATCH 33/85] Adds (more) test cases for auto_encode. --- src/libsyntax/ext/auto_encode.rs | 36 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 7fbba987cc7df..2c685c360e9d0 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)]); + } } From 08b6057538b9bb81bb71db632344ed0312e57f5f Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 26 Feb 2013 10:15:29 -0800 Subject: [PATCH 34/85] 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(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6befb2f188042..5af67aa0e3b33 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 f3a74302400c9..e75181eb89b7c 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 0b2aaa89d9b3a..0655a5efbf45f 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 26c38c945c7f1..808a80e6ad049 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 92c4f1e828f62..51cc25e84a33c 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 5fa6115938506..a31a73f594ad2 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 f145e433fa7c1..207f6d499159f 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), From 85aaf392914626441b3b681edb4d79552e078781 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 26 Feb 2013 13:23:18 -0500 Subject: [PATCH 35/85] Reimplement type_needs_drop on top of TypeContents --- src/librustc/middle/ty.rs | 98 +++++++-------------------------------- 1 file changed, 17 insertions(+), 81 deletions(-) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index dafc3b6718e1c..182ab11b91721 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -259,7 +259,6 @@ struct ctxt_ { rcache: creader_cache, ccache: constness_cache, short_names_cache: HashMap, - needs_drop_cache: HashMap, needs_unwind_cleanup_cache: HashMap, tc_cache: @mut LinearMap, ast_ty_to_ty_cache: HashMap, @@ -822,7 +821,6 @@ pub fn mk_ctxt(s: session::Session, rcache: mk_rcache(), ccache: HashMap(), short_names_cache: new_ty_hash(), - needs_drop_cache: new_ty_hash(), needs_unwind_cleanup_cache: new_ty_hash(), tc_cache: @mut LinearMap::new(), ast_ty_to_ty_cache: HashMap(), @@ -1600,79 +1598,7 @@ pub fn type_is_immediate(ty: t) -> bool { } pub fn type_needs_drop(cx: ctxt, ty: t) -> bool { - match cx.needs_drop_cache.find(&ty) { - Some(result) => return result, - None => {/* fall through */ } - } - - let mut accum = false; - let result = match /*bad*/copy get(ty).sty { - // scalar types - ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) | - ty_type | ty_ptr(_) | ty_rptr(_, _) | - ty_estr(vstore_fixed(_)) | - ty_estr(vstore_slice(_)) | - ty_evec(_, vstore_slice(_)) | - ty_self => false, - - ty_box(_) | ty_uniq(_) | - ty_opaque_box | ty_opaque_closure_ptr(*) | - ty_estr(vstore_uniq) | - ty_estr(vstore_box) | - ty_evec(_, vstore_uniq) | - ty_evec(_, vstore_box) => true, - - ty_trait(_, _, vstore_box) | - ty_trait(_, _, vstore_uniq) => true, - ty_trait(_, _, vstore_fixed(_)) | - ty_trait(_, _, vstore_slice(_)) => false, - - ty_param(*) | ty_infer(*) | ty_err => true, - - ty_evec(mt, vstore_fixed(_)) => type_needs_drop(cx, mt.ty), - ty_unboxed_vec(mt) => type_needs_drop(cx, mt.ty), - ty_rec(flds) => { - for flds.each |f| { - if type_needs_drop(cx, f.mt.ty) { accum = true; } - } - accum - } - ty_struct(did, ref substs) => { - // Any struct with a dtor needs a drop - ty_dtor(cx, did).is_present() || { - for vec::each(ty::struct_fields(cx, did, substs)) |f| { - if type_needs_drop(cx, f.mt.ty) { accum = true; } - } - accum - } - } - ty_tup(elts) => { - for elts.each |m| { if type_needs_drop(cx, *m) { accum = true; } } - accum - } - ty_enum(did, ref substs) => { - let variants = enum_variants(cx, did); - for vec::each(*variants) |variant| { - for variant.args.each |aty| { - // Perform any type parameter substitutions. - let arg_ty = subst(cx, substs, *aty); - if type_needs_drop(cx, arg_ty) { accum = true; } - } - if accum { break; } - } - accum - } - ty_bare_fn(*) => false, - ty_closure(ref fty) => { - match fty.sigil { - ast::BorrowedSigil => false, - ast::ManagedSigil | ast::OwnedSigil => true, - } - } - }; - - cx.needs_drop_cache.insert(ty, result); - return result; + type_contents(cx, ty).needs_drop(cx) } // Some things don't need cleanups during unwinding because the @@ -1819,7 +1745,7 @@ pub impl TypeContents { static fn nonimplicitly_copyable(cx: ctxt) -> TypeContents { let base = TypeContents::noncopyable(cx) + TC_OWNED_POINTER; - if cx.vecs_implicitly_copyable {base} else {base + TC_OWNED_SLICE} + if cx.vecs_implicitly_copyable {base} else {base + TC_OWNED_VEC} } fn is_safe_for_default_mode(&self, cx: ctxt) -> bool { @@ -1828,7 +1754,17 @@ pub impl TypeContents { static fn nondefault_mode(cx: ctxt) -> TypeContents { let tc = TypeContents::nonimplicitly_copyable(cx); - tc + TC_BIG + TC_OWNED_SLICE // disregard cx.vecs_implicitly_copyable + tc + TC_BIG + TC_OWNED_VEC // disregard cx.vecs_implicitly_copyable + } + + fn needs_drop(&self, cx: ctxt) -> bool { + let tc = TC_MANAGED + TC_DTOR + TypeContents::owned(cx); + self.intersects(tc) + } + + static fn owned(&self, _cx: ctxt) -> TypeContents { + //! Any kind of owned contents. + TC_OWNED_CLOSURE + TC_OWNED_POINTER + TC_OWNED_VEC } } @@ -1859,8 +1795,8 @@ const TC_BORROWED_POINTER: TypeContents = TypeContents{bits:0b0000_00000001}; /// Contains an owned pointer (~T) but not slice of some kind const TC_OWNED_POINTER: TypeContents = TypeContents{bits:0b000000000010}; -/// Contains an owned slice -const TC_OWNED_SLICE: TypeContents = TypeContents{bits:0b000000000100}; +/// Contains an owned vector ~[] or owned string ~str +const TC_OWNED_VEC: TypeContents = TypeContents{bits:0b000000000100}; /// Contains a ~fn() or a ~Trait, which is non-copyable. const TC_OWNED_CLOSURE: TypeContents = TypeContents{bits:0b000000001000}; @@ -1963,7 +1899,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { } ty_estr(vstore_uniq) => { - TC_OWNED_SLICE + TC_OWNED_VEC } ty_closure(ref c) => { @@ -1996,7 +1932,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents { } ty_evec(mt, vstore_uniq) => { - TC_OWNED_SLICE + tc_mt(cx, mt, cache) + TC_OWNED_VEC + tc_mt(cx, mt, cache) } ty_evec(mt, vstore_box) => { From 7e08d8f23cf284b95e0d6ca237633b6756898648 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 25 Feb 2013 11:37:17 -0500 Subject: [PATCH 36/85] Don't warn about 'pub use' statements --- src/librustc/middle/resolve.rs | 7 +++++-- src/test/compile-fail/unused-imports-warn.rs | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 689d6ca40eefe..d087112687df2 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -5285,10 +5285,13 @@ pub impl Resolver { for module_.import_resolutions.each_value |&import_resolution| { // Ignore dummy spans for things like automatically injected // imports for the prelude, and also don't warn about the same - // import statement being unused more than once. + // import statement being unused more than once. Furthermore, if + // the import is public, then we can't be sure whether it's unused + // or not so don't warn about it. if !import_resolution.state.used && !import_resolution.state.warned && - import_resolution.span != dummy_sp() { + import_resolution.span != dummy_sp() && + import_resolution.privacy != Public { import_resolution.state.warned = true; match self.unused_import_lint_level { warn => { diff --git a/src/test/compile-fail/unused-imports-warn.rs b/src/test/compile-fail/unused-imports-warn.rs index 6dcdb413f88a2..5707c18331ca8 100644 --- a/src/test/compile-fail/unused-imports-warn.rs +++ b/src/test/compile-fail/unused-imports-warn.rs @@ -31,6 +31,9 @@ mod foo { } mod bar { + // Don't ignore on 'pub use' because we're not sure if it's used or not + pub use core::cmp::Eq; + pub mod c { use foo::Point; use foo::Square; //~ ERROR unused import From 681e6dd40d5882465f74eebf2f1802c76b0df063 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 25 Feb 2013 12:12:22 -0500 Subject: [PATCH 37/85] Fix using the #[]-style attribute for unused imports --- src/librustc/middle/resolve.rs | 34 ++++++++------------ src/test/compile-fail/unused-imports-warn.rs | 7 +++- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index d087112687df2..7058f802bc4a4 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -19,6 +19,7 @@ use metadata::cstore::find_extern_mod_stmt_cnum; use metadata::decoder::{def_like, dl_def, dl_field, dl_impl}; use middle::lang_items::LanguageItems; use middle::lint::{deny, allow, forbid, level, unused_imports, warn}; +use middle::lint::{get_lint_level, get_lint_settings_level}; use middle::pat_util::{pat_bindings}; use core::cmp; @@ -508,16 +509,6 @@ pub impl Module { } } -pub fn unused_import_lint_level(session: Session) -> level { - for session.opts.lint_opts.each |lint_option_pair| { - let (lint_type, lint_level) = *lint_option_pair; - if lint_type == unused_imports { - return lint_level; - } - } - return allow; -} - // Records a possibly-private type definition. pub struct TypeNsDef { privacy: Privacy, @@ -770,8 +761,6 @@ pub fn Resolver(session: Session, graph_root: graph_root, - unused_import_lint_level: unused_import_lint_level(session), - trait_info: @HashMap(), structs: @HashMap(), @@ -816,8 +805,6 @@ pub struct Resolver { graph_root: @mut NameBindings, - unused_import_lint_level: level, - trait_info: @HashMap>, structs: @HashMap, @@ -5232,8 +5219,17 @@ pub impl Resolver { // resolve data structures. // + fn unused_import_lint_level(@mut self, m: @mut Module) -> level { + let settings = self.session.lint_settings; + match m.def_id { + Some(def) => get_lint_settings_level(settings, unused_imports, + def.node, def.node), + None => get_lint_level(settings.default_settings, unused_imports) + } + } + fn check_for_unused_imports_if_necessary(@mut self) { - if self.unused_import_lint_level == allow { + if self.unused_import_lint_level(self.current_module) == allow { return; } @@ -5293,7 +5289,7 @@ pub impl Resolver { import_resolution.span != dummy_sp() && import_resolution.privacy != Public { import_resolution.state.warned = true; - match self.unused_import_lint_level { + match self.unused_import_lint_level(module_) { warn => { self.session.span_warn(copy import_resolution.span, ~"unused import"); @@ -5302,11 +5298,7 @@ pub impl Resolver { self.session.span_err(copy import_resolution.span, ~"unused import"); } - allow => { - self.session.span_bug(copy import_resolution.span, - ~"shouldn't be here if lint \ - is allowed"); - } + allow => () } } } diff --git a/src/test/compile-fail/unused-imports-warn.rs b/src/test/compile-fail/unused-imports-warn.rs index 5707c18331ca8..7756f96b4703a 100644 --- a/src/test/compile-fail/unused-imports-warn.rs +++ b/src/test/compile-fail/unused-imports-warn.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: -D unused-imports +#[deny(unused_imports)]; use cal = bar::c::cc; @@ -39,6 +39,11 @@ mod bar { use foo::Square; //~ ERROR unused import pub fn cc(p: Point) -> int { return 2 * (p.x + p.y); } } + + #[allow(unused_imports)] + mod foo { + use core::cmp::Eq; + } } fn main() { From df481473dae024e522afd669646fa779d97c5e2d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 26 Feb 2013 01:23:36 -0500 Subject: [PATCH 38/85] Fix unused imports in the tutorials --- doc/rust.md | 1 - doc/tutorial-tasks.md | 2 -- doc/tutorial.md | 2 ++ 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/rust.md b/doc/rust.md index 9a3d087f3d723..a4e4e4cdf24f4 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -1611,7 +1611,6 @@ The following are examples of structure expressions: # struct Point { x: float, y: float } # struct TuplePoint(float, float); # mod game { pub struct User { name: &str, age: uint, score: uint } } -# use game; Point {x: 10f, y: 20f}; TuplePoint(10f, 20f); let u = game::User {name: "Joe", age: 35u, score: 100_000}; diff --git a/doc/tutorial-tasks.md b/doc/tutorial-tasks.md index c0f9a37627065..22d0ff8bf78a2 100644 --- a/doc/tutorial-tasks.md +++ b/doc/tutorial-tasks.md @@ -468,7 +468,6 @@ Here is the function that implements the child task: ~~~~ # use std::comm::DuplexStream; -# use comm::{Port, Chan}; fn stringifier(channel: &DuplexStream<~str, uint>) { let mut value: uint; loop { @@ -491,7 +490,6 @@ Here is the code for the parent task: ~~~~ # use std::comm::DuplexStream; -# use comm::{Port, Chan}; # use task::spawn; # fn stringifier(channel: &DuplexStream<~str, uint>) { # let mut value: uint; diff --git a/doc/tutorial.md b/doc/tutorial.md index cd683490a59ac..98ec9d1f58037 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -2270,7 +2270,9 @@ fn chicken_farmer() { // The same, but name it `my_chicken` use my_chicken = farm::chicken; ... +# my_chicken(); } +# chicken(); # } ~~~ From 6aefaf22c758b76703ed850bcf817dda127a5d67 Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 26 Feb 2013 15:48:00 -0800 Subject: [PATCH 39/85] typo-fixing and name-changes --- src/libsyntax/ext/base.rs | 24 ++++++++++++------------ src/libsyntax/ext/expand.rs | 4 +--- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index e75181eb89b7c..0eaf6849b7eb7 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 0655a5efbf45f..9a3e8da2b8145 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 From 0a0fcdb018ebee4aa8acb138418ff53c37ce5051 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Sat, 23 Feb 2013 00:22:51 -0800 Subject: [PATCH 40/85] librustc: offer suggestions for unresolved names. --- src/librustc/middle/resolve.rs | 84 +++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 7058f802bc4a4..3db328ceb9162 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -4816,6 +4816,75 @@ pub impl Resolver { } } + fn find_best_match_for_name(@mut self, name: &str) -> Option<~str> { + let mut maybes: ~[~str] = ~[]; + let mut values: ~[uint] = ~[]; + + let mut j = self.value_ribs.len(); + while j != 0 { + j -= 1; + let rib = self.value_ribs.get_elt(j); + for rib.bindings.each_entry |e| { + vec::push(&mut maybes, copy *self.session.str_of(e.key)); + vec::push(&mut values, uint::max_value); + } + } + + // Levenshtein Distance between two strings + fn distance(s: &str, t: &str) -> uint { + + let slen = str::len(s); + let tlen = str::len(t); + + if slen == 0 { return tlen; } + if tlen == 0 { return slen; } + + let mut dcol = vec::from_fn(tlen + 1, |x| x); + + for str::each_chari(s) |i, sc| { + + let mut current = i; + dcol[0] = current + 1; + + for str::each_chari(t) |j, tc| { + + let mut next = dcol[j + 1]; + + if sc == tc { + dcol[j + 1] = current; + } else { + dcol[j + 1] = cmp::min(current, next); + dcol[j + 1] = cmp::min(dcol[j + 1], dcol[j]) + 1; + } + + current = next; + } + } + + return dcol[tlen]; + } + + let mut smallest = 0; + for vec::eachi(maybes) |i, &other| { + + values[i] = distance(name, other); + + if values[i] <= values[smallest] { + smallest = i; + } + } + + if vec::len(values) > 0 && + values[smallest] != uint::max_value && + values[smallest] < str::len(name) + 2 { + + Some(vec::swap_remove(&mut maybes, smallest)) + + } else { + None + } + } + fn name_exists_in_scope_struct(@mut self, name: &str) -> bool { let mut i = self.type_ribs.len(); while i != 0 { @@ -4882,9 +4951,20 @@ pub impl Resolver { wrong_name)); } else { - self.session.span_err(expr.span, - fmt!("unresolved name: %s", + match self.find_best_match_for_name(wrong_name) { + + Some(m) => { + self.session.span_err(expr.span, + fmt!("unresolved name: `%s`. \ + Did you mean: `%s`?", + wrong_name, m)); + } + None => { + self.session.span_err(expr.span, + fmt!("unresolved name: `%s`.", wrong_name)); + } + } } } } From f460c2adf8223fdff2eaa039af8781bcba11e587 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Sun, 24 Feb 2013 20:44:01 -0800 Subject: [PATCH 41/85] Move levenshtein distance fn to core::str. --- src/libcore/str.rs | 34 ++++++++++++++++++++++++++++++++ src/librustc/middle/resolve.rs | 36 +--------------------------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 3c15a89081d7f..92e980e34d08f 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -590,6 +590,40 @@ pub pure fn split_str_nonempty(s: &a/str, sep: &b/str) -> ~[~str] { result } +/// Levenshtein Distance between two strings +pub fn levdistance(s: &str, t: &str) -> uint { + + let slen = str::len(s); + let tlen = str::len(t); + + if slen == 0 { return tlen; } + if tlen == 0 { return slen; } + + let mut dcol = vec::from_fn(tlen + 1, |x| x); + + for str::each_chari(s) |i, sc| { + + let mut current = i; + dcol[0] = current + 1; + + for str::each_chari(t) |j, tc| { + + let mut next = dcol[j + 1]; + + if sc == tc { + dcol[j + 1] = current; + } else { + dcol[j + 1] = ::cmp::min(current, next); + dcol[j + 1] = ::cmp::min(dcol[j + 1], dcol[j]) + 1; + } + + current = next; + } + } + + return dcol[tlen]; +} + /** * Splits a string into a vector of the substrings separated by LF ('\n') */ diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 3db328ceb9162..3f1e4dca3a19a 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -4830,44 +4830,10 @@ pub impl Resolver { } } - // Levenshtein Distance between two strings - fn distance(s: &str, t: &str) -> uint { - - let slen = str::len(s); - let tlen = str::len(t); - - if slen == 0 { return tlen; } - if tlen == 0 { return slen; } - - let mut dcol = vec::from_fn(tlen + 1, |x| x); - - for str::each_chari(s) |i, sc| { - - let mut current = i; - dcol[0] = current + 1; - - for str::each_chari(t) |j, tc| { - - let mut next = dcol[j + 1]; - - if sc == tc { - dcol[j + 1] = current; - } else { - dcol[j + 1] = cmp::min(current, next); - dcol[j + 1] = cmp::min(dcol[j + 1], dcol[j]) + 1; - } - - current = next; - } - } - - return dcol[tlen]; - } - let mut smallest = 0; for vec::eachi(maybes) |i, &other| { - values[i] = distance(name, other); + values[i] = str::levdistance(name, other); if values[i] <= values[smallest] { smallest = i; From a0866d0166283ffca0ce6ded21ba11ffb73f9554 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Tue, 26 Feb 2013 17:23:12 -0800 Subject: [PATCH 42/85] Adjust error messages for compile-fail tests. --- src/librustc/middle/resolve.rs | 3 ++- src/test/compile-fail/alt-join.rs | 2 +- src/test/compile-fail/bad-expr-path.rs | 2 +- src/test/compile-fail/bad-expr-path2.rs | 2 +- src/test/compile-fail/does-nothing.rs | 2 +- src/test/compile-fail/issue-1476.rs | 2 +- src/test/compile-fail/issue-3021-b.rs | 2 +- src/test/compile-fail/issue-3021-d.rs | 4 ++-- src/test/compile-fail/issue-3021.rs | 2 +- 9 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 3f1e4dca3a19a..e75a73650b425 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -4842,7 +4842,8 @@ pub impl Resolver { if vec::len(values) > 0 && values[smallest] != uint::max_value && - values[smallest] < str::len(name) + 2 { + values[smallest] < str::len(name) + 2 && + maybes[smallest] != name.to_owned() { Some(vec::swap_remove(&mut maybes, smallest)) diff --git a/src/test/compile-fail/alt-join.rs b/src/test/compile-fail/alt-join.rs index a94709c577466..94488fbb55213 100644 --- a/src/test/compile-fail/alt-join.rs +++ b/src/test/compile-fail/alt-join.rs @@ -16,6 +16,6 @@ fn my_fail() -> ! { fail!(); } fn main() { match true { false => { my_fail(); } true => { } } - log(debug, x); //~ ERROR unresolved name: x + log(debug, x); //~ ERROR unresolved name: `x`. let x: int; } diff --git a/src/test/compile-fail/bad-expr-path.rs b/src/test/compile-fail/bad-expr-path.rs index 576f9ef677ec3..30014817308f4 100644 --- a/src/test/compile-fail/bad-expr-path.rs +++ b/src/test/compile-fail/bad-expr-path.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: unresolved name: m1::a +// error-pattern: unresolved name: `m1::a`. Did you mean: `args`? mod m1 {} diff --git a/src/test/compile-fail/bad-expr-path2.rs b/src/test/compile-fail/bad-expr-path2.rs index 5545bbf68f045..88239a4cc3fee 100644 --- a/src/test/compile-fail/bad-expr-path2.rs +++ b/src/test/compile-fail/bad-expr-path2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: unresolved name: m1::a +// error-pattern: unresolved name: `m1::a`. Did you mean: `args`? mod m1 { pub mod a {} diff --git a/src/test/compile-fail/does-nothing.rs b/src/test/compile-fail/does-nothing.rs index c6115f408535f..a360d6579574f 100644 --- a/src/test/compile-fail/does-nothing.rs +++ b/src/test/compile-fail/does-nothing.rs @@ -1,3 +1,3 @@ -// error-pattern: unresolved name: this_does_nothing_what_the +// error-pattern: unresolved name: `this_does_nothing_what_the`. fn main() { debug!("doing"); this_does_nothing_what_the; debug!("boing"); } diff --git a/src/test/compile-fail/issue-1476.rs b/src/test/compile-fail/issue-1476.rs index 4f21e30cc1681..7a45ecc83b0c2 100644 --- a/src/test/compile-fail/issue-1476.rs +++ b/src/test/compile-fail/issue-1476.rs @@ -9,5 +9,5 @@ // except according to those terms. fn main() { - log(error, x); //~ ERROR unresolved name: x + log(error, x); //~ ERROR unresolved name: `x`. } diff --git a/src/test/compile-fail/issue-3021-b.rs b/src/test/compile-fail/issue-3021-b.rs index a782dd58ee671..1d4cd69c54ee0 100644 --- a/src/test/compile-fail/issue-3021-b.rs +++ b/src/test/compile-fail/issue-3021-b.rs @@ -19,7 +19,7 @@ fn siphash(k0 : u64) { impl siphash { fn reset(&mut self) { self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture - //~^ ERROR unresolved name: k0 + //~^ ERROR unresolved name: `k0`. } } } diff --git a/src/test/compile-fail/issue-3021-d.rs b/src/test/compile-fail/issue-3021-d.rs index 38bd007f1891e..7381d36a22396 100644 --- a/src/test/compile-fail/issue-3021-d.rs +++ b/src/test/compile-fail/issue-3021-d.rs @@ -31,9 +31,9 @@ fn siphash(k0 : u64, k1 : u64) -> siphash { impl siphash for sipstate { fn reset() { self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture - //~^ ERROR unresolved name: k0 + //~^ ERROR unresolved name: `k0`. self.v1 = k1 ^ 0x646f72616e646f6d; //~ ERROR attempted dynamic environment-capture - //~^ ERROR unresolved name: k1 + //~^ ERROR unresolved name: `k1`. } fn result() -> u64 { return mk_result(self); } } diff --git a/src/test/compile-fail/issue-3021.rs b/src/test/compile-fail/issue-3021.rs index fdfd256217508..e5a7a7990e526 100644 --- a/src/test/compile-fail/issue-3021.rs +++ b/src/test/compile-fail/issue-3021.rs @@ -23,7 +23,7 @@ fn siphash(k0 : u64) -> siphash { impl siphash for sipstate { fn reset() { self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture - //~^ ERROR unresolved name: k0 + //~^ ERROR unresolved name: `k0`. } } fail!(); From 3e6b2cfab5b838138f2bec5c696089b7f5005361 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 26 Feb 2013 17:30:32 -0800 Subject: [PATCH 43/85] Fix --disable-optimize-llvm --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index d9f2db8e11099..3576e43468dd7 100755 --- a/configure +++ b/configure @@ -678,7 +678,7 @@ do LLVM_BUILD_DIR=${CFG_BUILD_DIR}llvm/$t if [ ! -z "$CFG_DISABLE_OPTIMIZE_LLVM" ] then - LLVM_DBG_OPTS="" + LLVM_DBG_OPTS="--enable-debug-symbols --disable-optimized" # Just use LLVM straight from its build directory to # avoid 'make install' time LLVM_INST_DIR=$LLVM_BUILD_DIR/Debug+Asserts From f4327230fa348283f4b9c81aed76cd0759983965 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 26 Feb 2013 19:40:39 -0800 Subject: [PATCH 44/85] Add a 'start' lang item and use it instead of rust_start --- src/libcore/rt.rs | 17 ++++++++++++- src/librustc/back/link.rs | 6 ++--- src/librustc/middle/lang_items.rs | 12 +++++++-- src/librustc/middle/trans/base.rs | 41 ++++++++++++++++++++++--------- 4 files changed, 58 insertions(+), 18 deletions(-) diff --git a/src/libcore/rt.rs b/src/libcore/rt.rs index 60e6118057d6a..c3e4f925c4014 100644 --- a/src/libcore/rt.rs +++ b/src/libcore/rt.rs @@ -11,7 +11,7 @@ //! Runtime calls emitted by the compiler. use cast::transmute; -use libc::{c_char, c_uchar, c_void, size_t, uintptr_t}; +use libc::{c_char, c_uchar, c_void, size_t, uintptr_t, c_int}; use managed::raw::BoxRepr; use str; use sys; @@ -121,6 +121,21 @@ pub unsafe fn strdup_uniq(ptr: *c_uchar, len: uint) -> ~str { str::raw::from_buf_len(ptr, len) } +#[lang="start"] +pub fn start(main: *u8, argc: int, argv: *c_char, + crate_map: *u8) -> int { + + extern { + fn rust_start(main: *c_void, argc: c_int, argv: *c_char, + crate_map: *c_void) -> c_int; + } + + unsafe { + return rust_start(main as *c_void, argc as c_int, argv, + crate_map as *c_void) as int; + } +} + // Local Variables: // mode: rust; // fill-column: 78; diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index b30f9fcb9dd83..8db27bd675d6e 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -838,9 +838,6 @@ pub fn link_binary(sess: Session, } } - // Always want the runtime linked in - cc_args.push(~"-lrustrt"); - // On linux librt and libdl are an indirect dependencies via rustrt, // and binutils 2.22+ won't add them automatically if sess.targ_cfg.os == session::os_linux { @@ -880,6 +877,9 @@ pub fn link_binary(sess: Session, cc_args.push(~"-lmorestack"); } + // Always want the runtime linked in + cc_args.push(~"-lrustrt"); + // FIXME (#2397): At some point we want to rpath our guesses as to where // extern libraries might live, based on the addl_lib_search_paths cc_args.push_all(rpath::get_rpath_flags(sess, &output)); diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index b997c94a71b4d..84871f7496472 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -75,16 +75,18 @@ pub enum LangItem { ReturnToMutFnLangItem, // 31 CheckNotBorrowedFnLangItem, // 32 StrDupUniqFnLangItem, // 33 + + StartFnLangItem, // 34 } pub struct LanguageItems { - items: [ Option * 34 ] + items: [ Option * 35 ] } pub impl LanguageItems { static pub fn new(&self) -> LanguageItems { LanguageItems { - items: [ None, ..34 ] + items: [ None, ..35 ] } } @@ -136,6 +138,8 @@ pub impl LanguageItems { 32 => "check_not_borrowed", 33 => "strdup_uniq", + 34 => "start", + _ => "???" } } @@ -248,6 +252,9 @@ pub impl LanguageItems { pub fn strdup_uniq_fn(&const self) -> def_id { self.items[StrDupUniqFnLangItem as uint].get() } + pub fn start_fn(&const self) -> def_id { + self.items[StartFnLangItem as uint].get() + } } fn LanguageItemCollector(crate: @crate, @@ -296,6 +303,7 @@ fn LanguageItemCollector(crate: @crate, item_refs.insert(@~"check_not_borrowed", CheckNotBorrowedFnLangItem as uint); item_refs.insert(@~"strdup_uniq", StrDupUniqFnLangItem as uint); + item_refs.insert(@~"start", StartFnLangItem as uint); LanguageItemCollector { crate: crate, diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 9844aa53f467c..53555dc9ff855 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2267,7 +2267,7 @@ pub fn create_main_wrapper(ccx: @CrateContext, fn main_name() -> ~str { return ~"WinMain@16"; } #[cfg(unix)] fn main_name() -> ~str { return ~"main"; } - let llfty = T_fn(~[ccx.int_type, ccx.int_type], ccx.int_type); + let llfty = T_fn(~[ccx.int_type, T_ptr(T_i8())], ccx.int_type); // FIXME #4404 android JNI hacks let llfn = if *ccx.sess.building_library { @@ -2285,33 +2285,50 @@ pub fn create_main_wrapper(ccx: @CrateContext, llvm::LLVMPositionBuilderAtEnd(bld, llbb); } let crate_map = ccx.crate_map; - let start_ty = T_fn(~[val_ty(rust_main), ccx.int_type, ccx.int_type, - val_ty(crate_map)], ccx.int_type); - let start = decl_cdecl_fn(ccx.llmod, ~"rust_start", start_ty); + let start_def_id = ccx.tcx.lang_items.start_fn(); + let start_fn = if start_def_id.crate == ast::local_crate { + ccx.sess.bug(~"start lang item is never in the local crate") + } else { + let start_fn_type = csearch::get_type(ccx.tcx, + start_def_id).ty; + trans_external_path(ccx, start_def_id, start_fn_type) + }; + + let retptr = unsafe { + llvm::LLVMBuildAlloca(bld, ccx.int_type, noname()) + }; let args = unsafe { + let opaque_rust_main = llvm::LLVMBuildPointerCast( + bld, rust_main, T_ptr(T_i8()), noname()); + let opaque_crate_map = llvm::LLVMBuildPointerCast( + bld, crate_map, T_ptr(T_i8()), noname()); + if *ccx.sess.building_library { ~[ - rust_main, + retptr, + C_null(T_opaque_box_ptr(ccx)), + opaque_rust_main, llvm::LLVMConstInt(T_i32(), 0u as c_ulonglong, False), llvm::LLVMConstInt(T_i32(), 0u as c_ulonglong, False), - crate_map + opaque_crate_map ] } else { ~[ - rust_main, + retptr, + C_null(T_opaque_box_ptr(ccx)), + opaque_rust_main, llvm::LLVMGetParam(llfn, 0 as c_uint), llvm::LLVMGetParam(llfn, 1 as c_uint), - crate_map + opaque_crate_map ] } }; - let result = unsafe { - llvm::LLVMBuildCall(bld, start, vec::raw::to_ptr(args), - args.len() as c_uint, noname()) - }; unsafe { + llvm::LLVMBuildCall(bld, start_fn, vec::raw::to_ptr(args), + args.len() as c_uint, noname()); + let result = llvm::LLVMBuildLoad(bld, retptr, noname()); llvm::LLVMBuildRet(bld, result); } } From 5b0a2d1fc0186fdcb6dff68d4736e172c82a50a1 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 26 Feb 2013 14:15:08 -0500 Subject: [PATCH 45/85] treemap: improve the lazy iterator * replace the dual next() and get() calls with a single next() function * drop one of the pointer members from the struct * add a method for using the lazy iterator with a for loop --- src/libstd/treemap.rs | 206 +++++++++++++++++++----------------------- 1 file changed, 93 insertions(+), 113 deletions(-) diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index eb3093a27451f..0e593ba42d129 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -48,13 +48,8 @@ impl Eq for TreeMap { let mut y = other.iter(); for self.len().times { unsafe { // unsafe as a purity workaround - map_next(&mut x); - map_next(&mut y); - // FIXME: #4492 (ICE), x.get() == y.get() - let (x1, x2) = x.get().unwrap(); - let (y1, y2) = y.get().unwrap(); - - if x1 != y1 || x2 != y2 { + if map_next(&mut x).unwrap() != + map_next(&mut y).unwrap() { return false } } @@ -73,10 +68,8 @@ pure fn lt(a: &TreeMap, b: &TreeMap) -> bool { let (a_len, b_len) = (a.len(), b.len()); for uint::min(a_len, b_len).times { unsafe { // purity workaround - map_next(&mut x); - map_next(&mut y); - let (key_a,_) = x.get().unwrap(); - let (key_b,_) = y.get().unwrap(); + let (key_a,_) = map_next(&mut x).unwrap(); + let (key_b,_) = map_next(&mut y).unwrap(); if *key_a < *key_b { return true; } if *key_a > *key_b { return false; } } @@ -201,30 +194,21 @@ impl TreeMap { /// Get a lazy iterator over the key-value pairs in the map. /// Requires that it be frozen (immutable). pure fn iter(&self) -> TreeMapIterator/&self { - TreeMapIterator{stack: ~[], node: &self.root, current: None} + TreeMapIterator{stack: ~[], node: &self.root} } } /// Lazy forward iterator over a map pub struct TreeMapIterator { priv stack: ~[&~TreeNode], - priv node: &Option<~TreeNode>, - priv current: Option<&~TreeNode> + priv node: &Option<~TreeNode> } -impl TreeMapIterator { - // Returns the current node, or None if this iterator is at the end. - fn get(&const self) -> Option<(&self/K, &self/V)> { - match self.current { - Some(res) => Some((&res.key, &res.value)), - None => None - } - } -} - -/// Advance the iterator to the next node (in order). If this iterator -/// is finished, does nothing. -pub fn map_next(iter: &mut TreeMapIterator/&a) { +/// Advance the iterator to the next node (in order) and return a +/// tuple with a reference to the key and value. If there are no +/// more nodes, return `None`. +fn map_next(iter: &mut TreeMapIterator/&r) + -> Option<(&r/K, &r/V)> { while !iter.stack.is_empty() || iter.node.is_some() { match *iter.node { Some(ref x) => { @@ -234,12 +218,24 @@ pub fn map_next(iter: &mut TreeMapIterator/&a) { None => { let res = iter.stack.pop(); iter.node = &res.right; - iter.current = Some(res); - return; + return Some((&res.key, &res.value)); } } } - iter.current = None; + None +} + +/// Advance the iterator through the map +fn map_advance(iter: &mut TreeMapIterator/&r, + f: fn((&r/K, &r/V)) -> bool) { + loop { + match map_next(iter) { + Some(x) => { + if !f(x) { return } + } + None => return + } + } } pub struct TreeSet { @@ -308,19 +304,15 @@ impl Set for TreeSet { let mut x = self.iter(); let mut y = other.iter(); unsafe { // purity workaround - set_next(&mut x); - set_next(&mut y); - let mut a = x.get(); - let mut b = y.get(); + let mut a = set_next(&mut x); + let mut b = set_next(&mut y); while a.is_some() && b.is_some() { let a1 = a.unwrap(); let b1 = b.unwrap(); if a1 < b1 { - set_next(&mut x); - a = x.get(); + a = set_next(&mut x); } else if b1 < a1 { - set_next(&mut y); - b = y.get(); + b = set_next(&mut y); } else { return false; } @@ -339,10 +331,8 @@ impl Set for TreeSet { let mut x = self.iter(); let mut y = other.iter(); unsafe { // purity workaround - set_next(&mut x); - set_next(&mut y); - let mut a = x.get(); - let mut b = y.get(); + let mut a = set_next(&mut x); + let mut b = set_next(&mut y); while b.is_some() { if a.is_none() { return false @@ -356,11 +346,9 @@ impl Set for TreeSet { } if !(a1 < b1) { - set_next(&mut y); - b = y.get(); + b = set_next(&mut y); } - set_next(&mut x); - a = x.get(); + a = set_next(&mut x); } } true @@ -372,15 +360,13 @@ impl Set for TreeSet { let mut y = other.iter(); unsafe { // purity workaround - set_next(&mut x); - set_next(&mut y); - let mut a = x.get(); - let mut b = y.get(); + let mut a = set_next(&mut x); + let mut b = set_next(&mut y); while a.is_some() { if b.is_none() { return do a.while_some() |a1| { - if f(a1) { set_next(&mut x); x.get() } else { None } + if f(a1) { set_next(&mut x) } else { None } } } @@ -389,12 +375,10 @@ impl Set for TreeSet { if a1 < b1 { if !f(a1) { return } - set_next(&mut x); - a = x.get(); + a = set_next(&mut x); } else { - if !(b1 < a1) { set_next(&mut x); a = x.get() } - set_next(&mut y); - b = y.get(); + if !(b1 < a1) { a = set_next(&mut x) } + b = set_next(&mut y); } } } @@ -407,15 +391,13 @@ impl Set for TreeSet { let mut y = other.iter(); unsafe { // purity workaround - set_next(&mut x); - set_next(&mut y); - let mut a = x.get(); - let mut b = y.get(); + let mut a = set_next(&mut x); + let mut b = set_next(&mut y); while a.is_some() { if b.is_none() { return do a.while_some() |a1| { - if f(a1) { set_next(&mut x); x.get() } else { None } + if f(a1) { set_next(&mut x) } else { None } } } @@ -424,21 +406,18 @@ impl Set for TreeSet { if a1 < b1 { if !f(a1) { return } - set_next(&mut x); - a = x.get(); + a = set_next(&mut x); } else { if b1 < a1 { if !f(b1) { return } } else { - set_next(&mut x); - a = x.get(); + a = set_next(&mut x); } - set_next(&mut y); - b = y.get(); + b = set_next(&mut y); } } do b.while_some |b1| { - if f(b1) { set_next(&mut y); y.get() } else { None } + if f(b1) { set_next(&mut y) } else { None } } } } @@ -449,23 +428,19 @@ impl Set for TreeSet { let mut y = other.iter(); unsafe { // purity workaround - set_next(&mut x); - set_next(&mut y); - let mut a = x.get(); - let mut b = y.get(); + let mut a = set_next(&mut x); + let mut b = set_next(&mut y); while a.is_some() && b.is_some() { let a1 = a.unwrap(); let b1 = b.unwrap(); if a1 < b1 { - set_next(&mut x); - a = x.get(); + a = set_next(&mut x); } else { if !(b1 < a1) { if !f(a1) { return } } - set_next(&mut y); - b = y.get(); + b = set_next(&mut y); } } } @@ -477,15 +452,13 @@ impl Set for TreeSet { let mut y = other.iter(); unsafe { // purity workaround - set_next(&mut x); - set_next(&mut y); - let mut a = x.get(); - let mut b = y.get(); + let mut a = set_next(&mut x); + let mut b = set_next(&mut y); while a.is_some() { if b.is_none() { return do a.while_some() |a1| { - if f(a1) { set_next(&mut x); x.get() } else { None } + if f(a1) { set_next(&mut x) } else { None } } } @@ -494,16 +467,13 @@ impl Set for TreeSet { if b1 < a1 { if !f(b1) { return } - set_next(&mut y); - b = y.get(); + b = set_next(&mut y); } else { if !f(a1) { return } if !(a1 < b1) { - set_next(&mut y); - b = y.get() + b = set_next(&mut y); } - set_next(&mut x); - a = x.get(); + a = set_next(&mut x); } } } @@ -526,20 +496,16 @@ pub struct TreeSetIterator { priv iter: TreeMapIterator } -impl TreeSetIterator { - /// Returns the current node, or None if this iterator is at the end. - fn get(&const self) -> Option<&self/T> { - match self.iter.get() { - None => None, - Some((k, _)) => Some(k) - } - } -} - /// Advance the iterator to the next node (in order). If this iterator is /// finished, does nothing. -pub fn set_next(iter: &mut TreeSetIterator/&a) { - map_next(&mut iter.iter); +pub fn set_next(iter: &mut TreeSetIterator/&r) -> Option<&r/T> { + do map_next(&mut iter.iter).map |&(value, _)| { value } +} + +/// Advance the iterator through the set +fn set_advance(iter: &mut TreeSetIterator/&r, + f: fn(&r/T) -> bool) { + do map_advance(&mut iter.iter) |(k, _)| { f(k) } } // Nodes keep track of their level in the tree, starting at 1 in the @@ -983,23 +949,37 @@ mod test_treemap { assert m.insert(x5, y5); let m = m; - let mut iter = m.iter(); + let mut a = m.iter(); // FIXME: #4492 (ICE): iter.get() == Some((&x1, &y1)) - map_next(&mut iter); - assert iter.get().unwrap() == (&x1, &y1); - map_next(&mut iter); - assert iter.get().unwrap() == (&x2, &y2); - map_next(&mut iter); - assert iter.get().unwrap() == (&x3, &y3); - map_next(&mut iter); - assert iter.get().unwrap() == (&x4, &y4); - map_next(&mut iter); - assert iter.get().unwrap() == (&x5, &y5); - - map_next(&mut iter); - assert iter.get().is_none(); + assert map_next(&mut a).unwrap() == (&x1, &y1); + assert map_next(&mut a).unwrap() == (&x2, &y2); + assert map_next(&mut a).unwrap() == (&x3, &y3); + assert map_next(&mut a).unwrap() == (&x4, &y4); + assert map_next(&mut a).unwrap() == (&x5, &y5); + + assert map_next(&mut a).is_none(); + + let mut b = m.iter(); + + let expected = [(&x1, &y1), (&x2, &y2), (&x3, &y3), (&x4, &y4), + (&x5, &y5)]; + let mut i = 0; + + for map_advance(&mut b) |x| { + assert expected[i] == x; + i += 1; + + if i == 2 { + break + } + } + + for map_advance(&mut b) |x| { + assert expected[i] == x; + i += 1; + } } } From 5ae9b2949fd632f20ccc8afe30e273c0aa5b665b Mon Sep 17 00:00:00 2001 From: Jihyun Yu Date: Wed, 27 Feb 2013 22:48:55 +0900 Subject: [PATCH 46/85] Fix: now sha1 result_str() return correct value --- src/libstd/sha1.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs index 242e318e8a8f0..69c3de5ff6285 100644 --- a/src/libstd/sha1.rs +++ b/src/libstd/sha1.rs @@ -251,7 +251,11 @@ pub fn sha1() -> Sha1 { let rr = mk_result(self); let mut s = ~""; for vec::each(rr) |b| { - s += uint::to_str_radix(*b as uint, 16u); + let hex = uint::to_str_radix(*b as uint, 16u); + if hex.len() == 1 { + s += "0"; + } + s += hex; } return s; } @@ -283,6 +287,7 @@ mod tests { struct Test { input: ~str, output: ~[u8], + output_str: ~str, } fn a_million_letter_a() -> ~str { @@ -306,6 +311,7 @@ mod tests { 0x78u8, 0x50u8, 0xC2u8, 0x6Cu8, 0x9Cu8, 0xD0u8, 0xD8u8, 0x9Du8, ], + output_str: ~"a9993e364706816aba3e25717850c26c9cd0d89d" }, Test { input: @@ -318,6 +324,7 @@ mod tests { 0xF9u8, 0x51u8, 0x29u8, 0xE5u8, 0xE5u8, 0x46u8, 0x70u8, 0xF1u8, ], + output_str: ~"84983e441c3bd26ebaae4aa1f95129e5e54670f1" }, Test { input: a_million_letter_a(), @@ -328,6 +335,7 @@ mod tests { 0xDBu8, 0xADu8, 0x27u8, 0x31u8, 0x65u8, 0x34u8, 0x01u8, 0x6Fu8, ], + output_str: ~"34aa973cd4c4daa4f61eeb2bdbad27316534016f" }, ]; // Examples from wikipedia @@ -342,6 +350,7 @@ mod tests { 0xbbu8, 0x76u8, 0xe7u8, 0x39u8, 0x1bu8, 0x93u8, 0xebu8, 0x12u8, ], + output_str: ~"2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", }, Test { input: ~"The quick brown fox jumps over the lazy cog", @@ -352,6 +361,7 @@ mod tests { 0x0bu8, 0xd1u8, 0x7du8, 0x9bu8, 0x10u8, 0x0du8, 0xb4u8, 0xb3u8, ], + output_str: ~"de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3", }, ]; let tests = fips_180_1_tests + wikipedia_tests; @@ -373,6 +383,11 @@ mod tests { sh.input_str(t.input); let out = sh.result(); check_vec_eq(t.output, out); + + let out_str = sh.result_str(); + assert(out_str.len() == 40); + assert(out_str == t.output_str); + sh.reset(); } @@ -389,6 +404,11 @@ mod tests { } let out = sh.result(); check_vec_eq(t.output, out); + + let out_str = sh.result_str(); + assert(out_str.len() == 40); + assert(out_str == t.output_str); + sh.reset(); } } From c2be2ec42df4381ad805d81ff964215c3ce414b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20L=C3=B6bel?= Date: Wed, 27 Feb 2013 16:01:53 +0100 Subject: [PATCH 47/85] Added ToStr implementations for &[T] and @[T] --- src/libcore/to_str.rs | 43 +++++++++++++++++++++++++++++++++ src/test/run-pass/vec-to_str.rs | 24 ++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/test/run-pass/vec-to_str.rs diff --git a/src/libcore/to_str.rs b/src/libcore/to_str.rs index 0145adc77b826..17e4e042a5afc 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -74,10 +74,53 @@ impl ToStr for (A, B, C) { } } +impl ToStr for &[A] { + #[inline(always)] + pure fn to_str(&self) -> ~str { + unsafe { + // FIXME #4568 + // Bleh -- not really unsafe + // push_str and push_char + let mut acc = ~"[", first = true; + for self.each |elt| { + unsafe { + if first { first = false; } + else { str::push_str(&mut acc, ~", "); } + str::push_str(&mut acc, elt.to_str()); + } + } + str::push_char(&mut acc, ']'); + acc + } + } +} + impl ToStr for ~[A] { #[inline(always)] pure fn to_str(&self) -> ~str { unsafe { + // FIXME #4568 + // Bleh -- not really unsafe + // push_str and push_char + let mut acc = ~"[", first = true; + for self.each |elt| { + unsafe { + if first { first = false; } + else { str::push_str(&mut acc, ~", "); } + str::push_str(&mut acc, elt.to_str()); + } + } + str::push_char(&mut acc, ']'); + acc + } + } +} + +impl ToStr for @[A] { + #[inline(always)] + pure fn to_str(&self) -> ~str { + unsafe { + // FIXME #4568 // Bleh -- not really unsafe // push_str and push_char let mut acc = ~"[", first = true; diff --git a/src/test/run-pass/vec-to_str.rs b/src/test/run-pass/vec-to_str.rs new file mode 100644 index 0000000000000..fed091e0fe681 --- /dev/null +++ b/src/test/run-pass/vec-to_str.rs @@ -0,0 +1,24 @@ +// Copyright 2013 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. + +pub fn main() { + assert (~[0, 1]).to_str() == ~"[0, 1]"; + assert (&[1, 2]).to_str() == ~"[1, 2]"; + assert (@[2, 3]).to_str() == ~"[2, 3]"; + + let foo = ~[3, 4]; + let bar = &[4, 5]; + let baz = @[5, 6]; + + assert foo.to_str() == ~"[3, 4]"; + assert bar.to_str() == ~"[4, 5]"; + assert baz.to_str() == ~"[5, 6]"; + +} From 8d7e6ef7725f8a11de940892a74398fc1911dfc7 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 26 Feb 2013 11:32:00 -0800 Subject: [PATCH 48/85] 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 +++++- .../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 diff --git a/doc/tutorial.md b/doc/tutorial.md index 98ec9d1f58037..f940876187788 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 230386655e08e..3b839e5a9e008 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 61b5ffd845f89..f258e649122bd 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 b6b001727a45a..7f48466ed0a87 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 016847a5bfd7d..1ff51e8bff030 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 8ce68a41f81bf..d7ca766f183a9 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 7b3030124b72f..0c5c0f3d5138c 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 af25a4f6e58dc..c9102cbb86b4b 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 8b59879acd979..0000000000000 --- 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); -} From 573a31dfa769887f4be77a621ef4cab2d92a74e5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 26 Feb 2013 14:50:09 -0800 Subject: [PATCH 49/85] 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(-) diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 7651b737bf34e..9f2036c5f41a6 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 9cd5e8f4965d2..2522e9c2cda5a 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 31c837e7e8a3a..687ad2f79387d 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 d2515df3e1b40..75f38da5a19a1 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 fb6f80a650084..7dafdec95e072 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 e14e9665216f6..bfeaf8400bc44 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 0c5c0f3d5138c..33d959a7753cf 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 c9102cbb86b4b..b4bd28cbfe215 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 6ad3344599734..72f6d23cacce1 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])); From 07c3f5c0de752166ae34f0fe50e50e65a2403b66 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 26 Feb 2013 17:12:00 -0800 Subject: [PATCH 50/85] 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 +- .../crate-method-reexport-grrrrrrr2.rs | 4 +- src/test/auxiliary/issue-3012-1.rs | 2 +- src/test/auxiliary/issue2170lib.rs | 2 +- .../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 +- .../run-pass/pipe-presentation-examples.rs | 2 +- src/test/run-pass/static-impl.rs | 4 +- .../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 +- .../trait-static-method-overwriting.rs | 4 +- 67 files changed, 304 insertions(+), 288 deletions(-) diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 57bd8a97b5db9..ab604d1f0b6fe 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 d5407daca80d0..c4f2704ab9f6e 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 4e4e7c68646f2..8f3771312e4d6 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 b857f76570ff5..1b79ec614d49b 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 1352959306a03..a3def10bda8a5 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 e8dd603d50753..eccd1f6ce3c8a 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 6f1371f8ee221..05d529cbcf46a 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 46c734b95483e..d8819d4fed0f9 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 83ef421b70578..7e376a47b8966 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 315ff84cc234c..01ec0cc77bf91 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 834feff292c59..772ef51d30d4a 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 b661b3b20b1cd..ec7301a01e486 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 c2be9e252d9a1..53e4be70727bf 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 475ae243915d9..e2a75b25eaeb6 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 e27b7086bc45b..1c2df949a2e9c 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 92e980e34d08f..66be548181956 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 4b2cd3c2fab5b..1f0f3b0779cbe 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 568bc5b5e70f6..eb2a93d86f9a4 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 f027ca99d514f..3f8ee61e8412d 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 53555dc9ff855..740a7e043d4dd 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 48a3d2c82c873..f8a7f4779764c 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 ba56eb56c0a9d..07499dac62e14 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 182ab11b91721..efbbfc46cb944 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 e63e46ace3d05..998c007c86d7d 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 96c76b52181c1..1bbee20e2e261 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 5008791723eee..936ca1e829775 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 1a919ac0f3b0b..8fa887fca0bad 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 4fee6f061b1ca..2c4fd9f01eea5 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 12a9a6c4076e7..5552b71d0d771 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 0013b417f7a31..9b74ac8535148 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 93c6131d3406a..fec3f3d977962 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 141a730ca8d34..628cccfa9a22f 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 11a1b9f357657..0add792663027 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 13c0bbe1a674c..2ee994bdf32b4 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 d16b1282c7c0b..c6e76aa1a688c 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 cb9090225bf1c..dd873650b662e 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 3178e141097f9..66db951e12bde 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 d7ca766f183a9..c85aa78d9834a 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 5af67aa0e3b33..744cb92fb1c2c 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 74f67808a5e97..959454841a2a7 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 fec3a961a52a2..4c5c4da514273 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 1ab55fe9035bc..65711d9894a73 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 0019acc1291f4..9e60e2151744b 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 49f7fe5853e7b..6adea6395a356 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 cc42a0992cbed..f456f7b81ae15 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 66feb7cc753cf..9a330db9f1825 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 444b09d9ae458..84d46e318b1cd 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 7c6dc1f937dca..d22feff947075 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 dacb6f60e3764..2d8b62629ee27 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 51cc25e84a33c..dc5bdeba92a88 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 33d959a7753cf..b384e7ebdd0f4 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 b4bd28cbfe215..59ad35b38e4ff 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 a2896dad814c2..5006c72ad156b 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 2b3fd47e5bc49..f578ad82d6d80 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 cbc1c4b2fec44..36343d42b7589 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 d664ad62edf1d..0690a01744947 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 2ed3b3b1f5c98..67da2541ca212 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 227ea5c1521c0..90ca7c1797c3a 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 a003563928738..e2bf708feabc7 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 b97ebb04f716d..4a7263266b78f 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 85ab1f89dbeca..8749c1cb1133b 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 201193fd738e8..d1b2870fef627 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 b4c28fd52a64c..20ab9014c700b 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 64b30d71e1dff..f20181d22d344 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 f184ab2741a1d..adb9f01fff8a8 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 692d50e541a97..d10126dddb6cc 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 d416f3f6c910e..9565919a5d8c7 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: () } From 35baf5b2021fab393ff4d52581c55a0f6477bfb8 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Mon, 25 Feb 2013 00:15:53 +0900 Subject: [PATCH 51/85] Fix reversed current/expected type Fix some reversed type of arm pattern and type of search pattern in error message. --- src/librustc/middle/typeck/check/_match.rs | 8 ++++---- src/librustc/middle/typeck/check/demand.rs | 17 +++++++++++------ src/librustc/middle/typeck/check/mod.rs | 3 ++- src/test/compile-fail/issue-3680.rs | 2 +- src/test/compile-fail/match-struct.rs | 3 +-- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 82f9828db3fb3..795ea4323fe82 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -103,7 +103,7 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, // check that the type of the value being matched is a subtype // of the type of the pattern: let pat_ty = fcx.node_ty(pat.id); - demand::suptype(fcx, pat.span, pat_ty, expected); + demand::subtype(fcx, pat.span, expected, pat_ty); // Get the expected types of the arguments. arg_types = { @@ -142,7 +142,7 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, // Check that the type of the value being matched is a subtype of // the type of the pattern. let pat_ty = fcx.node_ty(pat.id); - demand::suptype(fcx, pat.span, pat_ty, expected); + demand::subtype(fcx, pat.span, expected, pat_ty); // Get the expected types of the arguments. let class_fields = ty::struct_fields( @@ -154,8 +154,8 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, _ => { tcx.sess.span_fatal( pat.span, - fmt!("mismatched types: expected enum or structure but \ - found `%s`", + fmt!("mismatched types: expected `%s` but found enum or \ + structure", fcx.infcx().ty_to_str(expected))); } } diff --git a/src/librustc/middle/typeck/check/demand.rs b/src/librustc/middle/typeck/check/demand.rs index 5f1a3b5c17c4a..a3fac8b4e1cde 100644 --- a/src/librustc/middle/typeck/check/demand.rs +++ b/src/librustc/middle/typeck/check/demand.rs @@ -21,20 +21,25 @@ use syntax::codemap::span; // Requires that the two types unify, and prints an error message if they // don't. pub fn suptype(fcx: @mut FnCtxt, sp: span, expected: ty::t, actual: ty::t) { - suptype_with_fn(fcx, sp, expected, actual, + suptype_with_fn(fcx, sp, false, expected, actual, |sp, e, a, s| { fcx.report_mismatched_types(sp, e, a, s) }) } +pub fn subtype(fcx: @mut FnCtxt, sp: span, expected: ty::t, actual: ty::t) { + suptype_with_fn(fcx, sp, true, actual, expected, + |sp, a, e, s| { fcx.report_mismatched_types(sp, e, a, s) }) +} + pub fn suptype_with_fn(fcx: @mut FnCtxt, - sp: span, - expected: ty::t, actual: ty::t, + sp: span, b_is_expected: bool, + ty_a: ty::t, ty_b: ty::t, handle_err: fn(span, ty::t, ty::t, &ty::type_err)) { // n.b.: order of actual, expected is reversed - match infer::mk_subty(fcx.infcx(), false, sp, - actual, expected) { + match infer::mk_subty(fcx.infcx(), b_is_expected, sp, + ty_b, ty_a) { result::Ok(()) => { /* ok */ } result::Err(ref err) => { - handle_err(sp, expected, actual, err); + handle_err(sp, ty_a, ty_b, err); } } } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index e63e46ace3d05..7cf8b31ffc8ff 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -355,7 +355,8 @@ pub fn check_fn(ccx: @mut CrateCtxt, let tail_expr_ty = fcx.expr_ty(tail_expr); // Special case: we print a special error if there appears // to be do-block/for-loop confusion - demand::suptype_with_fn(fcx, tail_expr.span, fcx.ret_ty, tail_expr_ty, + demand::suptype_with_fn(fcx, tail_expr.span, false, + fcx.ret_ty, tail_expr_ty, |sp, e, a, s| { fcx.report_mismatched_return_types(sp, e, a, s) }); } diff --git a/src/test/compile-fail/issue-3680.rs b/src/test/compile-fail/issue-3680.rs index 9044c6b6d79b5..18b5d290f3d6d 100644 --- a/src/test/compile-fail/issue-3680.rs +++ b/src/test/compile-fail/issue-3680.rs @@ -10,6 +10,6 @@ fn main() { match None { - Err(_) => () //~ ERROR expected `core::result + Err(_) => () //~ ERROR mismatched types: expected `core::option::Option<>` but found `core::result::Result<,>` } } diff --git a/src/test/compile-fail/match-struct.rs b/src/test/compile-fail/match-struct.rs index fa406aa278e81..6e9bf603aef9e 100644 --- a/src/test/compile-fail/match-struct.rs +++ b/src/test/compile-fail/match-struct.rs @@ -1,11 +1,10 @@ -// error-pattern: mismatched types struct S { a: int } enum E { C(int) } fn main() { match S { a: 1 } { - C(_) => (), + C(_) => (), //~ ERROR mismatched types: expected `S` but found `E` _ => () } } From 1b1017087be4e842ef0ff43486da8b4e9b085f14 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 27 Feb 2013 12:39:11 -0800 Subject: [PATCH 52/85] rt: Make some runtime calls work outside of task context --- src/rt/rust_builtin.cpp | 6 ++---- src/rt/rust_upcall.cpp | 7 ++++++- src/rt/rust_util.h | 7 ++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 2c5b56f3fa4ef..1243d82460346 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -124,8 +124,7 @@ vec_reserve_shared_actual(type_desc* ty, rust_vec_box** vp, extern "C" CDECL void vec_reserve_shared(type_desc* ty, rust_vec_box** vp, size_t n_elts) { - rust_task *task = rust_get_current_task(); - reserve_vec_exact(task, vp, n_elts * ty->size); + reserve_vec_exact(vp, n_elts * ty->size); } extern "C" CDECL size_t @@ -445,9 +444,8 @@ void tm_to_rust_tm(tm* in_tm, rust_tm* out_tm, int32_t gmtoff, out_tm->tm_nsec = nsec; if (zone != NULL) { - rust_task *task = rust_get_current_task(); size_t size = strlen(zone); - reserve_vec_exact(task, &out_tm->tm_zone, size + 1); + reserve_vec_exact(&out_tm->tm_zone, size + 1); memcpy(out_tm->tm_zone->body.data, zone, size); out_tm->tm_zone->body.fill = size + 1; out_tm->tm_zone->body.data[size] = '\0'; diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index 008b470fede76..b0e13717b8289 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -118,7 +118,12 @@ extern "C" CDECL void upcall_fail(char const *expr, char const *file, size_t line) { - rust_task *task = rust_get_current_task(); + rust_task *task = rust_try_get_current_task(); + if (task == NULL) { + // NOTE: Need to think about what to do here + printf("failure outside of a task"); + abort(); + } s_fail_args args = {task,expr,file,line}; UPCALL_SWITCH_STACK(task, &args, upcall_s_fail); } diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h index 0385804a77871..fbedb9bc6efb2 100644 --- a/src/rt/rust_util.h +++ b/src/rt/rust_util.h @@ -67,11 +67,12 @@ inline void reserve_vec_exact_shared(rust_task* task, rust_vec_box** vpp, } } -inline void reserve_vec_exact(rust_task* task, rust_vec_box** vpp, +inline void reserve_vec_exact(rust_vec_box** vpp, size_t size) { if (size > (*vpp)->body.alloc) { - *vpp = (rust_vec_box*)task->kernel - ->realloc(*vpp, size + sizeof(rust_vec_box)); + rust_exchange_alloc exchange_alloc; + *vpp = (rust_vec_box*)exchange_alloc + .realloc(*vpp, size + sizeof(rust_vec_box)); (*vpp)->body.alloc = size; } } From dbbdca31b45997604d4bf99662cb32939c838149 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 22 Feb 2013 22:15:11 -0800 Subject: [PATCH 53/85] testsuite: Update and un-xfail #3601 test --- src/test/compile-fail/issue-3601.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/compile-fail/issue-3601.rs b/src/test/compile-fail/issue-3601.rs index 3dd070b44a04c..e0adf9eca51e4 100644 --- a/src/test/compile-fail/issue-3601.rs +++ b/src/test/compile-fail/issue-3601.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// xfail-test struct HTMLImageData { image: Option<~str> } @@ -25,18 +24,19 @@ enum NodeKind { Element(ElementData) } -enum NodeData = { +struct NodeData { kind: ~NodeKind -}; +} fn main() { let mut id = HTMLImageData { image: None }; let ed = ElementData { kind: ~HTMLImageElement(id) }; - let n = NodeData({kind : ~Element(ed)}); + let n = NodeData {kind : ~Element(ed)}; + // n.b. span could be better match n.kind { - ~Element(ed) => match ed.kind { - ~HTMLImageElement(d) if d.image.is_some() => { true } + ~Element(ed) => match ed.kind { //~ ERROR non-exhaustive patterns + ~HTMLImageElement(ref d) if d.image.is_some() => { true } }, - _ => fail!(~"WAT") //~ ERROR wat + _ => fail!(~"WAT") //~ ERROR unreachable pattern }; } From 43d43adf6bd2024b1ddc0e596d4bed88e1df82b1 Mon Sep 17 00:00:00 2001 From: Ben Striegel Date: Wed, 27 Feb 2013 19:13:53 -0500 Subject: [PATCH 54/85] Turn old `drop` blocks into `Drop` traits --- src/libcore/io.rs | 10 ++++++++-- src/libcore/option.rs | 5 ++++- src/libcore/pipes.rs | 5 ++++- src/libcore/private.rs | 15 +++++++++++--- src/libcore/rand.rs | 5 ++++- src/libcore/run.rs | 5 ++++- src/libcore/task/spawn.rs | 10 ++++++++-- src/libcore/util.rs | 5 ++++- src/librustc/lib/llvm.rs | 20 +++++++++++++++---- src/librustc/middle/trans/base.rs | 5 ++++- src/librustc/middle/trans/common.rs | 5 ++++- src/librustc/rustc.rc | 5 ++++- src/librustc/util/common.rs | 5 ++++- src/librustdoc/demo.rs | 5 ++++- src/libstd/task_pool.rs | 5 ++++- src/libsyntax/parse/parser.rs | 6 +++++- src/test/auxiliary/moves_based_on_type_lib.rs | 5 ++++- .../use-after-move-self-based-on-type.rs | 5 ++++- .../run-fail/too-much-recursion-unwinding.rs | 5 ++++- src/test/run-fail/unwind-resource-fail.rs | 5 ++++- src/test/run-fail/unwind-resource-fail2.rs | 5 ++++- src/test/run-pass/issue-3563-3.rs | 5 ++++- 22 files changed, 117 insertions(+), 29 deletions(-) diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 421eb94a29128..45d89b29a2e9a 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -474,7 +474,10 @@ impl Reader for Wrapper { pub struct FILERes { f: *libc::FILE, - drop { +} + +impl Drop for FILERes { + fn finalize(&self) { unsafe { libc::fclose(self.f); } @@ -683,7 +686,10 @@ impl Writer for fd_t { pub struct FdRes { fd: fd_t, - drop { +} + +impl Drop for FdRes { + fn finalize(&self) { unsafe { libc::close(self.fd); } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 1c2df949a2e9c..12ed0df007621 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -450,7 +450,10 @@ fn test_unwrap_str() { fn test_unwrap_resource() { struct R { i: @mut int, - drop { *(self.i) += 1; } + } + + impl ::ops::Drop for R { + fn finalize(&self) { *(self.i) += 1; } } fn R(i: @mut int) -> R { diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 15a6e700ffd84..a0a29c6b51601 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -346,7 +346,10 @@ pub unsafe fn get_buffer(p: *PacketHeader) -> ~Buffer { struct BufferResource { buffer: ~Buffer, - drop { +} + +impl ::ops::Drop for BufferResource { + fn finalize(&self) { unsafe { let b = move_it!(self.buffer); //let p = ptr::addr_of(*b); diff --git a/src/libcore/private.rs b/src/libcore/private.rs index 2580efe6d0968..e4fab18966cad 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -126,7 +126,10 @@ struct ArcData { struct ArcDestruct { mut data: *libc::c_void, - drop { +} + +impl Drop for ArcDestruct{ + fn finalize(&self) { unsafe { if self.data.is_null() { return; // Happens when destructing an unwrapper's handle. @@ -178,7 +181,10 @@ pub unsafe fn unwrap_shared_mutable_state(rc: SharedMutableState) struct DeathThroes { mut ptr: Option<~ArcData>, mut response: Option>, - drop { + } + + impl Drop for DeathThroes{ + fn finalize(&self) { unsafe { let response = option::swap_unwrap(&mut self.response); // In case we get killed early, we need to tell the person who @@ -311,7 +317,10 @@ type rust_little_lock = *libc::c_void; struct LittleLock { l: rust_little_lock, - drop { +} + +impl Drop for LittleLock { + fn finalize(&self) { unsafe { rustrt::rust_destroy_little_lock(self.l); } diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index a88b83465161d..15362f89e3fb6 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -365,7 +365,10 @@ impl Rng { struct RandRes { rng: *rust_rng, - drop { +} + +impl Drop for RandRes { + fn finalize(&self) { unsafe { rustrt::rand_free(self.rng); } diff --git a/src/libcore/run.rs b/src/libcore/run.rs index 4e2337b833133..aa1e473e3bf8c 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -248,7 +248,10 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program { } struct ProgRes { r: ProgRepr, - drop { + } + + impl Drop for ProgRes { + fn finalize(&self) { unsafe { // FIXME #4943: This is bad. destroy_repr(cast::transmute(&self.r)); diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 5110f70ff11be..bf7209f9fc3fc 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -308,8 +308,11 @@ struct TCB { mut ancestors: AncestorList, is_main: bool, notifier: Option, +} + +impl Drop for TCB { // Runs on task exit. - drop { + fn finalize(&self) { unsafe { // If we are failing, the whole taskgroup needs to die. if rt::rust_task_is_unwinding(self.me) { @@ -353,7 +356,10 @@ fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, struct AutoNotify { notify_chan: Chan, mut failed: bool, - drop { +} + +impl Drop for AutoNotify { + fn finalize(&self) { let result = if self.failed { Failure } else { Success }; self.notify_chan.send(result); } diff --git a/src/libcore/util.rs b/src/libcore/util.rs index 629c4a3291ce0..522cb2d2783cf 100644 --- a/src/libcore/util.rs +++ b/src/libcore/util.rs @@ -66,7 +66,10 @@ pub fn replace(dest: &mut T, src: T) -> T { /// A non-copyable dummy type. pub struct NonCopyable { i: (), - drop { } +} + +impl Drop for NonCopyable { + fn finalize(&self) { } } pub fn NonCopyable() -> NonCopyable { NonCopyable { i: () } } diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index d2bb7c75a27f6..78528fa053ae0 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -1458,7 +1458,10 @@ pub fn struct_tys(struct_ty: TypeRef) -> ~[TypeRef] { pub struct target_data_res { TD: TargetDataRef, - drop { +} + +impl Drop for target_data_res { + fn finalize(&self) { unsafe { llvm::LLVMDisposeTargetData(self.TD); } @@ -1492,7 +1495,10 @@ pub fn mk_target_data(string_rep: ~str) -> TargetData { pub struct pass_manager_res { PM: PassManagerRef, - drop { +} + +impl Drop for pass_manager_res { + fn finalize(&self) { unsafe { llvm::LLVMDisposePassManager(self.PM); } @@ -1525,7 +1531,10 @@ pub fn mk_pass_manager() -> PassManager { pub struct object_file_res { ObjectFile: ObjectFileRef, - drop { +} + +impl Drop for object_file_res { + fn finalize(&self) { unsafe { llvm::LLVMDisposeObjectFile(self.ObjectFile); } @@ -1559,7 +1568,10 @@ pub fn mk_object_file(llmb: MemoryBufferRef) -> Option { pub struct section_iter_res { SI: SectionIteratorRef, - drop { +} + +impl Drop for section_iter_res { + fn finalize(&self) { unsafe { llvm::LLVMDisposeSectionIterator(self.SI); } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 740a7e043d4dd..c7f59a83cf5e7 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -90,7 +90,10 @@ use syntax::{ast, ast_util, codemap, ast_map}; pub struct icx_popper { ccx: @CrateContext, - drop { +} + +impl Drop for icx_popper { + fn finalize(&self) { if self.ccx.sess.count_llvm_insns() { self.ccx.stats.llvm_insn_ctxt.pop(); } diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index f8a7f4779764c..c45278ee454b9 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -141,7 +141,10 @@ pub struct Stats { pub struct BuilderRef_res { B: BuilderRef, - drop { +} + +impl Drop for BuilderRef_res { + fn finalize(&self) { unsafe { llvm::LLVMDisposeBuilder(self.B); } diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc index 5df7ae493baac..56ad56c3ae690 100644 --- a/src/librustc/rustc.rc +++ b/src/librustc/rustc.rc @@ -336,7 +336,10 @@ pub fn monitor(+f: fn~(diagnostic::Emitter)) { struct finally { ch: SharedChan, - drop { self.ch.send(done); } + } + + impl Drop for finally { + fn finalize(&self) { self.ch.send(done); } } let _finally = finally { ch: ch }; diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 7b980b9de0db6..a83447432a006 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -32,7 +32,10 @@ pub fn indent(op: fn() -> R) -> R { pub struct _indenter { _i: (), - drop { debug!("<<"); } +} + +impl Drop for _indenter { + fn finalize(&self) { debug!("<<"); } } pub fn _indenter(_i: ()) -> _indenter { diff --git a/src/librustdoc/demo.rs b/src/librustdoc/demo.rs index 3c45c4a6fa036..b823be95ef752 100644 --- a/src/librustdoc/demo.rs +++ b/src/librustdoc/demo.rs @@ -125,7 +125,10 @@ mod blade_runner { */ struct Bored { bored: bool, - drop { log(error, self.bored); } +} + +impl Drop for Bored { + fn finalize(&self) { log(error, self.bored); } } /** diff --git a/src/libstd/task_pool.rs b/src/libstd/task_pool.rs index 6b8ea8a6ef42c..35b7ff5ad275c 100644 --- a/src/libstd/task_pool.rs +++ b/src/libstd/task_pool.rs @@ -28,7 +28,10 @@ pub struct TaskPool { channels: ~[Chan>], mut next_index: uint, - drop { +} + +impl Drop for TaskPool { + fn finalize(&self) { for self.channels.each |channel| { channel.send(Quit); } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 59ad35b38e4ff..1799d807564bf 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -243,7 +243,11 @@ pub struct Parser { /// Used to determine the path to externally loaded source files mod_path_stack: @mut ~[~str], - drop {} /* do not copy the parser; its state is tied to outside state */ +} + +impl Drop for Parser { + /* do not copy the parser; its state is tied to outside state */ + fn finalize(&self) {} } pub impl Parser { diff --git a/src/test/auxiliary/moves_based_on_type_lib.rs b/src/test/auxiliary/moves_based_on_type_lib.rs index 3dd78eb3f1caa..826bd0db12964 100644 --- a/src/test/auxiliary/moves_based_on_type_lib.rs +++ b/src/test/auxiliary/moves_based_on_type_lib.rs @@ -12,7 +12,10 @@ pub struct S { x: int, - drop { +} + +impl Drop for S { + fn finalize(&self) { io::println("goodbye"); } } diff --git a/src/test/compile-fail/use-after-move-self-based-on-type.rs b/src/test/compile-fail/use-after-move-self-based-on-type.rs index 270fe3626e8a7..a06bc42d29aba 100644 --- a/src/test/compile-fail/use-after-move-self-based-on-type.rs +++ b/src/test/compile-fail/use-after-move-self-based-on-type.rs @@ -1,6 +1,9 @@ struct S { x: int, - drop {} +} + +impl Drop for S { + fn finalize(&self) {} } impl S { diff --git a/src/test/run-fail/too-much-recursion-unwinding.rs b/src/test/run-fail/too-much-recursion-unwinding.rs index fbea8022cfc3c..3890e24cdfe05 100644 --- a/src/test/run-fail/too-much-recursion-unwinding.rs +++ b/src/test/run-fail/too-much-recursion-unwinding.rs @@ -21,7 +21,10 @@ fn recurse() { struct r { recursed: *mut bool, - drop { +} + +impl Drop for r { + fn finalize(&self) { unsafe { if !*(self.recursed) { *(self.recursed) = true; diff --git a/src/test/run-fail/unwind-resource-fail.rs b/src/test/run-fail/unwind-resource-fail.rs index 0d57e9279bc72..d60e575bac466 100644 --- a/src/test/run-fail/unwind-resource-fail.rs +++ b/src/test/run-fail/unwind-resource-fail.rs @@ -12,7 +12,10 @@ struct r { i: int, - drop { fail!(~"squirrel") } +} + +impl Drop for r { + fn finalize(&self) { fail!(~"squirrel") } } fn r(i: int) -> r { r { i: i } } diff --git a/src/test/run-fail/unwind-resource-fail2.rs b/src/test/run-fail/unwind-resource-fail2.rs index 0b33326abe719..e276f2065f708 100644 --- a/src/test/run-fail/unwind-resource-fail2.rs +++ b/src/test/run-fail/unwind-resource-fail2.rs @@ -13,7 +13,10 @@ struct r { i: int, - drop { fail!(~"wombat") } +} + +impl Drop for r { + fn finalize(&self) { fail!(~"wombat") } } fn r(i: int) -> r { r { i: i } } diff --git a/src/test/run-pass/issue-3563-3.rs b/src/test/run-pass/issue-3563-3.rs index c4f4aa46a8a42..f66a3cc474c20 100644 --- a/src/test/run-pass/issue-3563-3.rs +++ b/src/test/run-pass/issue-3563-3.rs @@ -54,7 +54,10 @@ struct AsciiArt // This struct can be quite large so we'll disable copying: developers need // to either pass these structs around via borrowed pointers or move them. - drop {} +} + +impl Drop for AsciiArt { + fn finalize(&self) {} } // It's common to define a constructor sort of function to create struct instances. From c623d21e388315df672951fcb8efb5000923ab3d Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 14 Feb 2013 21:50:03 -0800 Subject: [PATCH 55/85] Introduce lifetime declarations into the lists of type parameters. Major changes are: - replace ~[ty_param] with Generics structure, which includes both OptVec and OptVec; - the use of syntax::opt_vec to avoid allocation for empty lists; cc #4846 --- src/librustc/front/test.rs | 6 +- src/librustc/metadata/encoder.rs | 101 ++++++---- src/librustc/middle/astencode.rs | 8 +- src/librustc/middle/lint.rs | 8 +- src/librustc/middle/region.rs | 3 +- src/librustc/middle/resolve.rs | 131 ++++++------ src/librustc/middle/trans/base.rs | 6 +- src/librustc/middle/trans/inline.rs | 4 +- src/librustc/middle/trans/meth.rs | 14 +- src/librustc/middle/trans/reachable.rs | 27 +-- src/librustc/middle/ty.rs | 9 +- src/librustc/middle/typeck/check/mod.rs | 34 ++-- src/librustc/middle/typeck/coherence.rs | 2 +- src/librustc/middle/typeck/collect.rs | 133 ++++++------ src/librustdoc/tystr_pass.rs | 10 +- src/libsyntax/ast.rs | 49 +++-- src/libsyntax/ast_map.rs | 2 +- src/libsyntax/ast_util.rs | 45 +++-- src/libsyntax/ext/auto_encode.rs | 122 ++++++----- src/libsyntax/ext/build.rs | 15 +- src/libsyntax/ext/deriving.rs | 112 ++++++----- src/libsyntax/ext/pipes/ast_builder.rs | 72 ++++--- src/libsyntax/ext/pipes/check.rs | 4 +- src/libsyntax/ext/pipes/parse_proto.rs | 8 +- src/libsyntax/ext/pipes/pipec.rs | 53 +++-- src/libsyntax/ext/pipes/proto.rs | 14 +- src/libsyntax/ext/quote.rs | 50 ++--- src/libsyntax/fold.rs | 49 +++-- src/libsyntax/opt_vec.rs | 187 +++++++++++++++++ src/libsyntax/parse/common.rs | 26 +-- src/libsyntax/parse/parser.rs | 257 +++++++++++------------- src/libsyntax/print/pprust.rs | 102 ++++++---- src/libsyntax/syntax.rc | 1 + src/libsyntax/visit.rs | 122 ++++++----- 34 files changed, 1067 insertions(+), 719 deletions(-) create mode 100644 src/libsyntax/opt_vec.rs diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index f19b52661f210..22333f236ed8e 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -200,14 +200,14 @@ fn is_bench_fn(i: @ast::item) -> bool { vec::len(attr::find_attrs_by_name(i.attrs, ~"bench")) > 0u; fn has_test_signature(i: @ast::item) -> bool { - match /*bad*/copy i.node { - ast::item_fn(decl, _, tps, _) => { + match i.node { + ast::item_fn(ref decl, _, ref generics, _) => { let input_cnt = vec::len(decl.inputs); let no_output = match decl.output.node { ast::ty_nil => true, _ => false }; - let tparm_cnt = vec::len(tps); + let tparm_cnt = generics.ty_params.len(); // NB: inadequate check, but we're running // well before resolve, can't get too deep. input_cnt == 1u diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 86b07abffc2e9..95973aaaf90ad 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -49,6 +49,8 @@ use syntax::diagnostic::span_handler; use syntax::parse::token::special_idents; use syntax::print::pprust; use syntax::{ast_util, visit}; +use syntax::opt_vec::OptVec; +use syntax::opt_vec; use syntax; use writer = std::ebml::writer; @@ -187,10 +189,11 @@ fn encode_ty_type_param_bounds(ebml_w: writer::Encoder, ecx: @EncodeContext, } } -fn encode_type_param_bounds(ebml_w: writer::Encoder, ecx: @EncodeContext, - params: &[ty_param]) { +fn encode_type_param_bounds(ebml_w: writer::Encoder, + ecx: @EncodeContext, + params: &OptVec) { let ty_param_bounds = - @params.map(|param| ecx.tcx.ty_param_bounds.get(¶m.id)); + @params.map_to_vec(|param| ecx.tcx.ty_param_bounds.get(¶m.id)); encode_ty_type_param_bounds(ebml_w, ecx, ty_param_bounds); } @@ -265,7 +268,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder, id: node_id, variants: &[variant], path: &[ast_map::path_elt], index: @mut ~[entry], - ty_params: &[ty_param]) { + generics: &ast::Generics) { let mut disr_val = 0; let mut i = 0; let vi = ty::enum_variants(ecx.tcx, @@ -281,7 +284,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder, node_id_to_type(ecx.tcx, variant.node.id)); match variant.node.kind { ast::tuple_variant_kind(ref args) - if args.len() > 0 && ty_params.len() == 0 => { + if args.len() > 0 && generics.ty_params.len() == 0 => { encode_symbol(ecx, ebml_w, variant.node.id); } ast::tuple_variant_kind(_) | ast::struct_variant_kind(_) | @@ -292,7 +295,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder, encode_disr_val(ecx, ebml_w, vi[i].disr_val); disr_val = vi[i].disr_val; } - encode_type_param_bounds(ebml_w, ecx, ty_params); + encode_type_param_bounds(ebml_w, ecx, &generics.ty_params); encode_path(ecx, ebml_w, path, ast_map::path_name(variant.node.name)); ebml_w.end_tag(); @@ -465,14 +468,18 @@ fn encode_info_for_struct(ecx: @EncodeContext, ebml_w: writer::Encoder, } // This is for encoding info for ctors and dtors -fn encode_info_for_ctor(ecx: @EncodeContext, ebml_w: writer::Encoder, - id: node_id, ident: ident, path: &[ast_map::path_elt], - item: Option, tps: &[ty_param]) { +fn encode_info_for_ctor(ecx: @EncodeContext, + ebml_w: writer::Encoder, + id: node_id, + ident: ident, + path: &[ast_map::path_elt], + item: Option, + generics: &ast::Generics) { ebml_w.start_tag(tag_items_data_item); encode_name(ecx, ebml_w, ident); encode_def_id(ebml_w, local_def(id)); encode_family(ebml_w, purity_fn_family(ast::impure_fn)); - encode_type_param_bounds(ebml_w, ecx, tps); + encode_type_param_bounds(ebml_w, ecx, &generics.ty_params); let its_ty = node_id_to_type(ecx.tcx, id); debug!("fn name = %s ty = %s its node id = %d", *ecx.tcx.sess.str_of(ident), @@ -518,9 +525,12 @@ fn encode_info_for_method(ecx: @EncodeContext, should_inline: bool, parent_id: node_id, m: @method, - +all_tps: ~[ty_param]) { - debug!("encode_info_for_method: %d %s %u", m.id, - *ecx.tcx.sess.str_of(m.ident), all_tps.len()); + owner_generics: &ast::Generics, + method_generics: &ast::Generics) { + debug!("encode_info_for_method: %d %s %u %u", m.id, + *ecx.tcx.sess.str_of(m.ident), + owner_generics.ty_params.len(), + method_generics.ty_params.len()); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(m.id)); match m.self_ty.node { @@ -529,8 +539,13 @@ fn encode_info_for_method(ecx: @EncodeContext, } _ => encode_family(ebml_w, purity_fn_family(m.purity)) } - let len = all_tps.len(); - encode_type_param_bounds(ebml_w, ecx, all_tps); + + let mut combined_ty_params = opt_vec::Empty; + combined_ty_params.push_all(&owner_generics.ty_params); + combined_ty_params.push_all(&method_generics.ty_params); + let len = combined_ty_params.len(); + encode_type_param_bounds(ebml_w, ecx, &combined_ty_params); + encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, m.id)); encode_name(ecx, ebml_w, m.ident); encode_path(ecx, ebml_w, impl_path, ast_map::path_name(m.ident)); @@ -604,13 +619,13 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder, encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident)); ebml_w.end_tag(); } - item_fn(_, purity, tps, _) => { + item_fn(_, purity, ref generics, _) => { add_to_index(); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(item.id)); encode_family(ebml_w, purity_fn_family(purity)); - let tps_len = tps.len(); - encode_type_param_bounds(ebml_w, ecx, tps); + let tps_len = generics.ty_params.len(); + encode_type_param_bounds(ebml_w, ecx, &generics.ty_params); encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id)); encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident)); encode_attributes(ebml_w, item.attrs); @@ -634,24 +649,24 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder, encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident)); ebml_w.end_tag(); } - item_ty(_, tps) => { + item_ty(_, ref generics) => { add_to_index(); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(item.id)); encode_family(ebml_w, 'y'); - encode_type_param_bounds(ebml_w, ecx, tps); + encode_type_param_bounds(ebml_w, ecx, &generics.ty_params); encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id)); encode_name(ecx, ebml_w, item.ident); encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident)); encode_region_param(ecx, ebml_w, item); ebml_w.end_tag(); } - item_enum(ref enum_definition, ref tps) => { + item_enum(ref enum_definition, ref generics) => { add_to_index(); do ebml_w.wr_tag(tag_items_data_item) { encode_def_id(ebml_w, local_def(item.id)); encode_family(ebml_w, 't'); - encode_type_param_bounds(ebml_w, ecx, *tps); + encode_type_param_bounds(ebml_w, ecx, &generics.ty_params); encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id)); encode_name(ecx, ebml_w, item.ident); for (*enum_definition).variants.each |v| { @@ -667,9 +682,9 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder, (*enum_definition).variants, path, index, - *tps); + generics); } - item_struct(struct_def, tps) => { + item_struct(struct_def, ref generics) => { /* First, encode the fields These come first because we need to write them to make the index, and the index needs to be in the item for the @@ -686,24 +701,25 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder, *ecx.tcx.sess.str_of(item.ident) + ~"_dtor"), path, - if tps.len() > 0u { + if generics.ty_params.len() > 0u { Some(ii_dtor(copy *dtor, item.ident, - copy tps, + copy *generics, local_def(item.id))) } else { None }, - tps); + generics); } /* Index the class*/ add_to_index(); + /* Now, make an item for the class itself */ ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(item.id)); encode_family(ebml_w, 'S'); - encode_type_param_bounds(ebml_w, ecx, tps); + encode_type_param_bounds(ebml_w, ecx, &generics.ty_params); encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id)); // If this is a tuple- or enum-like struct, encode the type of the @@ -759,13 +775,13 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder, encode_index(ebml_w, bkts, write_int); ebml_w.end_tag(); } - item_impl(tps, opt_trait, ty, methods) => { + item_impl(ref generics, opt_trait, ty, ref methods) => { add_to_index(); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(item.id)); encode_family(ebml_w, 'i'); encode_region_param(ecx, ebml_w, item); - encode_type_param_bounds(ebml_w, ecx, tps); + encode_type_param_bounds(ebml_w, ecx, &generics.ty_params); encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id)); encode_name(ecx, ebml_w, item.ident); encode_attributes(ebml_w, item.attrs); @@ -797,10 +813,10 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder, encode_info_for_method(ecx, ebml_w, impl_path, should_inline(m.attrs), item.id, *m, - vec::append(/*bad*/copy tps, m.tps)); + generics, &m.generics); } } - item_trait(ref tps, ref traits, ref ms) => { + item_trait(ref generics, ref traits, ref ms) => { let provided_methods = dvec::DVec(); add_to_index(); @@ -808,7 +824,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder, encode_def_id(ebml_w, local_def(item.id)); encode_family(ebml_w, 'I'); encode_region_param(ecx, ebml_w, item); - encode_type_param_bounds(ebml_w, ecx, *tps); + encode_type_param_bounds(ebml_w, ecx, &generics.ty_params); encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id)); encode_name(ecx, ebml_w, item.ident); encode_attributes(ebml_w, item.attrs); @@ -820,7 +836,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder, encode_def_id(ebml_w, local_def((*ty_m).id)); encode_name(ecx, ebml_w, mty.ident); encode_type_param_bounds(ebml_w, ecx, - (*ty_m).tps); + &ty_m.generics.ty_params); encode_type(ecx, ebml_w, ty::mk_bare_fn(tcx, copy mty.fty)); encode_family(ebml_w, purity_fn_family(mty.fty.purity)); @@ -834,7 +850,8 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder, ebml_w.start_tag(tag_item_trait_method); encode_def_id(ebml_w, local_def(m.id)); encode_name(ecx, ebml_w, mty.ident); - encode_type_param_bounds(ebml_w, ecx, m.tps); + encode_type_param_bounds(ebml_w, ecx, + &m.generics.ty_params); encode_type(ecx, ebml_w, ty::mk_bare_fn(tcx, copy mty.fty)); encode_family(ebml_w, purity_fn_family(mty.fty.purity)); @@ -880,8 +897,14 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder, // Finally, output all the provided methods as items. for provided_methods.each |m| { index.push(entry { val: m.id, pos: ebml_w.writer.tell() }); + + // We do not concatenate the generics of the owning impl and that + // of provided methods. I am not sure why this is. -ndm + let owner_generics = ast_util::empty_generics(); + encode_info_for_method(ecx, ebml_w, /*bad*/copy path, - true, item.id, *m, /*bad*/copy m.tps); + true, item.id, *m, + &owner_generics, &m.generics); } } item_mac(*) => fail!(~"item macros unimplemented") @@ -898,11 +921,11 @@ fn encode_info_for_foreign_item(ecx: @EncodeContext, index.push(entry { val: nitem.id, pos: ebml_w.writer.tell() }); ebml_w.start_tag(tag_items_data_item); - match /*bad*/copy nitem.node { - foreign_item_fn(_, purity, tps) => { + match nitem.node { + foreign_item_fn(_, purity, ref generics) => { encode_def_id(ebml_w, local_def(nitem.id)); encode_family(ebml_w, purity_fn_family(purity)); - encode_type_param_bounds(ebml_w, ecx, tps); + encode_type_param_bounds(ebml_w, ecx, &generics.ty_params); encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id)); if abi == foreign_abi_rust_intrinsic { (ecx.encode_inlined_item)(ecx, ebml_w, path, ii_foreign(nitem)); diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 02cd5afc920a1..58433cec2725d 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -371,10 +371,10 @@ fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item) ast::ii_foreign(i) => { ast::ii_foreign(fld.fold_foreign_item(i)) } - ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => { + ast::ii_dtor(ref dtor, nm, ref generics, parent_id) => { let dtor_body = fld.fold_block((*dtor).node.body); - let dtor_attrs = fld.fold_attributes(/*bad*/copy (*dtor).node.attrs); - let new_params = fold::fold_ty_params(/*bad*/copy *tps, fld); + let dtor_attrs = fld.fold_attributes(copy dtor.node.attrs); + let new_generics = fold::fold_generics(generics, fld); let dtor_id = fld.new_id((*dtor).node.id); let new_parent = xcx.tr_def_id(parent_id); let new_self = fld.new_id((*dtor).node.self_id); @@ -386,7 +386,7 @@ fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item) body: dtor_body }, .. (/*bad*/copy *dtor) }, - nm, new_params, new_parent) + nm, new_generics, new_parent) } } } diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index f4c3a1e8d1261..eb418d0cd5acb 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -753,7 +753,7 @@ fn check_item_structural_records(cx: ty::ctxt, it: @ast::item) { fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id, - decl: ast::fn_decl) { + decl: ast::fn_decl) { let tys = vec::map(decl.inputs, |a| a.ty ); for vec::each(vec::append_one(tys, decl.output)) |ty| { match ty.node { @@ -786,9 +786,9 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { if attr::foreign_abi(it.attrs) != either::Right(ast::foreign_abi_rust_intrinsic) => { for nmod.items.each |ni| { - match /*bad*/copy ni.node { - ast::foreign_item_fn(decl, _, _) => { - check_foreign_fn(cx, it.id, decl); + match ni.node { + ast::foreign_item_fn(ref decl, _, _) => { + check_foreign_fn(cx, it.id, *decl); } // FIXME #4622: Not implemented. ast::foreign_item_const(*) => {} diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 5b2d3c9bb96cd..19accd25c12c3 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -621,7 +621,8 @@ pub fn determine_rp_in_fn(fk: visit::fn_kind, } } (visitor.visit_ty)(decl.output, cx, visitor); - (visitor.visit_ty_params)(visit::tps_of_fn(fk), cx, visitor); + let generics = visit::generics_of_fn(fk); + (visitor.visit_generics)(&generics, cx, visitor); (visitor.visit_block)(body, cx, visitor); } } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index e75a73650b425..2b0263a47365a 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -42,6 +42,7 @@ use syntax::ast::{enum_variant_kind, expr, expr_again, expr_assign_op}; use syntax::ast::{expr_fn_block, expr_index, expr_loop}; use syntax::ast::{expr_path, expr_struct, expr_unary, fn_decl}; use syntax::ast::{foreign_item, foreign_item_const, foreign_item_fn, ge}; +use syntax::ast::{Generics}; use syntax::ast::{gt, ident, impure_fn, inherited, item, item_struct}; use syntax::ast::{item_const, item_enum, item_fn, item_foreign_mod}; use syntax::ast::{item_impl, item_mac, item_mod, item_trait, item_ty, le}; @@ -53,9 +54,9 @@ use syntax::ast::{public, required, rem, self_ty_, shl, shr, stmt_decl}; use syntax::ast::{struct_dtor, struct_field, struct_variant_kind, sty_by_ref}; use syntax::ast::{sty_static, subtract, trait_ref, tuple_variant_kind, Ty}; use syntax::ast::{ty_bool, ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i}; -use syntax::ast::{ty_i16, ty_i32, ty_i64, ty_i8, ty_int, ty_param, ty_path}; +use syntax::ast::{ty_i16, ty_i32, ty_i64, ty_i8, ty_int, TyParam, ty_path}; use syntax::ast::{ty_str, ty_u, ty_u16, ty_u32, ty_u64, ty_u8, ty_uint}; -use syntax::ast::{type_value_ns, ty_param_bound, unnamed_field}; +use syntax::ast::{type_value_ns, unnamed_field}; use syntax::ast::{variant, view_item, view_item_extern_mod}; use syntax::ast::{view_item_use, view_path_glob, view_path_list}; use syntax::ast::{view_path_simple, visibility, anonymous, named, not}; @@ -73,6 +74,8 @@ use syntax::visit::{default_visitor, fk_method, mk_vt, Visitor, visit_block}; use syntax::visit::{visit_crate, visit_expr, visit_expr_opt, visit_fn}; use syntax::visit::{visit_foreign_item, visit_item, visit_method_helper}; use syntax::visit::{visit_mod, visit_ty, vt}; +use syntax::opt_vec; +use syntax::opt_vec::OptVec; use managed::ptr_eq; use dvec::DVec; @@ -216,9 +219,9 @@ pub impl ResolveResult { } pub enum TypeParameters/& { - NoTypeParameters, //< No type parameters. - HasTypeParameters(&~[ty_param], //< Type parameters. - node_id, //< ID of the enclosing item + NoTypeParameters, //< No type parameters. + HasTypeParameters(&Generics, //< Type parameters. + node_id, //< ID of the enclosing item // The index to start numbering the type parameters at. // This is zero if this is the outermost set of type @@ -231,7 +234,6 @@ pub enum TypeParameters/& { // // The index at the method site will be 1, because the // outer T had index 0. - uint, // The kind of the rib used for type parameters. @@ -1500,14 +1502,15 @@ pub impl Resolver { self.add_child(name, parent, ForbidDuplicateValues, foreign_item.span); - match /*bad*/copy foreign_item.node { - foreign_item_fn(_, _, type_parameters) => { + match foreign_item.node { + foreign_item_fn(_, _, ref generics) => { let def = def_fn(local_def(foreign_item.id), unsafe_fn); name_bindings.define_value(Public, def, foreign_item.span); - do self.with_type_parameter_rib - (HasTypeParameters(&type_parameters, foreign_item.id, - 0, NormalRibKind)) { + do self.with_type_parameter_rib( + HasTypeParameters( + generics, foreign_item.id, 0, NormalRibKind)) + { visit_foreign_item(foreign_item, new_parent, visitor); } } @@ -3582,8 +3585,7 @@ pub impl Resolver { // enum item: resolve all the variants' discrs, // then resolve the ty params - item_enum(ref enum_def, ref type_parameters) => { - + item_enum(ref enum_def, ref generics) => { for (*enum_def).variants.each() |variant| { do variant.node.disr_expr.iter() |dis_expr| { // resolve the discriminator expr @@ -3599,14 +3601,14 @@ pub impl Resolver { // error if there is one? -- tjc do self.with_type_parameter_rib( HasTypeParameters( - type_parameters, item.id, 0, NormalRibKind)) { + generics, item.id, 0, NormalRibKind)) { visit_item(item, (), visitor); } } - item_ty(_, type_parameters) => { + item_ty(_, ref generics) => { do self.with_type_parameter_rib - (HasTypeParameters(&type_parameters, item.id, 0, + (HasTypeParameters(generics, item.id, 0, NormalRibKind)) || { @@ -3614,20 +3616,20 @@ pub impl Resolver { } } - item_impl(type_parameters, + item_impl(ref generics, implemented_traits, self_type, - methods) => { + ref methods) => { self.resolve_implementation(item.id, item.span, - type_parameters, + generics, implemented_traits, self_type, - methods, + *methods, visitor); } - item_trait(ref type_parameters, ref traits, ref methods) => { + item_trait(ref generics, ref traits, ref methods) => { // Create a new rib for the self type. let self_type_rib = @Rib(NormalRibKind); (*self.type_ribs).push(self_type_rib); @@ -3636,10 +3638,10 @@ pub impl Resolver { // Create a new rib for the trait-wide type parameters. do self.with_type_parameter_rib - (HasTypeParameters(type_parameters, item.id, 0, + (HasTypeParameters(generics, item.id, 0, NormalRibKind)) { - self.resolve_type_parameters(/*bad*/copy *type_parameters, + self.resolve_type_parameters(&generics.ty_params, visitor); // Resolve derived traits. @@ -3672,18 +3674,18 @@ pub impl Resolver { match *method { required(ref ty_m) => { do self.with_type_parameter_rib - (HasTypeParameters(&(*ty_m).tps, + (HasTypeParameters(&ty_m.generics, item.id, - type_parameters.len(), + generics.ty_params.len(), MethodRibKind(item.id, Required))) { // Resolve the method-specific type // parameters. self.resolve_type_parameters( - /*bad*/copy (*ty_m).tps, + &ty_m.generics.ty_params, visitor); - for (*ty_m).decl.inputs.each |argument| { + for ty_m.decl.inputs.each |argument| { self.resolve_type(argument.ty, visitor); } @@ -3694,7 +3696,7 @@ pub impl Resolver { self.resolve_method(MethodRibKind(item.id, Provided(m.id)), m, - type_parameters.len(), + generics.ty_params.len(), visitor) } } @@ -3704,12 +3706,12 @@ pub impl Resolver { (*self.type_ribs).pop(); } - item_struct(struct_def, ty_params) => { + item_struct(struct_def, ref generics) => { self.resolve_struct(item.id, - @copy ty_params, - /*bad*/copy struct_def.fields, - struct_def.dtor, - visitor); + generics, + struct_def.fields, + struct_def.dtor, + visitor); } item_mod(module_) => { @@ -3722,18 +3724,14 @@ pub impl Resolver { item_foreign_mod(foreign_module) => { do self.with_scope(Some(item.ident)) { for foreign_module.items.each |foreign_item| { - match /*bad*/copy foreign_item.node { - foreign_item_fn(_, _, type_parameters) => { - do self.with_type_parameter_rib - (HasTypeParameters(&type_parameters, - foreign_item.id, - 0, - OpaqueFunctionRibKind)) - || { - - visit_foreign_item(*foreign_item, (), - visitor); - } + match foreign_item.node { + foreign_item_fn(_, _, ref generics) => { + self.with_type_parameter_rib( + HasTypeParameters( + generics, foreign_item.id, 0, + NormalRibKind), + || visit_foreign_item(*foreign_item, (), + visitor)); } foreign_item_const(_) => { visit_foreign_item(*foreign_item, (), @@ -3744,7 +3742,7 @@ pub impl Resolver { } } - item_fn(ref fn_decl, _, ref ty_params, ref block) => { + item_fn(ref fn_decl, _, ref generics, ref block) => { // If this is the main function, we must record it in the // session. // FIXME #4404 android JNI hacks @@ -3771,7 +3769,7 @@ pub impl Resolver { self.resolve_function(OpaqueFunctionRibKind, Some(@/*bad*/copy *fn_decl), HasTypeParameters - (ty_params, + (generics, item.id, 0, OpaqueFunctionRibKind), @@ -3798,13 +3796,13 @@ pub impl Resolver { type_parameters: TypeParameters, f: fn()) { match type_parameters { - HasTypeParameters(type_parameters, node_id, initial_index, + HasTypeParameters(generics, node_id, initial_index, rib_kind) => { let function_type_rib = @Rib(rib_kind); - (*self.type_ribs).push(function_type_rib); + self.type_ribs.push(function_type_rib); - for (*type_parameters).eachi |index, type_parameter| { + for generics.ty_params.eachi |index, type_parameter| { let name = type_parameter.ident; debug!("with_type_parameter_rib: %d %d", node_id, type_parameter.id); @@ -3815,7 +3813,7 @@ pub impl Resolver { // the item that bound it self.record_def(type_parameter.id, def_typaram_binder(node_id)); - (*function_type_rib).bindings.insert(name, def_like); + function_type_rib.bindings.insert(name, def_like); } } @@ -3828,7 +3826,7 @@ pub impl Resolver { match type_parameters { HasTypeParameters(*) => { - (*self.type_ribs).pop(); + self.type_ribs.pop(); } NoTypeParameters => { @@ -3871,8 +3869,8 @@ pub impl Resolver { NoTypeParameters => { // Continue. } - HasTypeParameters(type_parameters, _, _, _) => { - self.resolve_type_parameters(/*bad*/copy *type_parameters, + HasTypeParameters(ref generics, _, _, _) => { + self.resolve_type_parameters(&generics.ty_params, visitor); } } @@ -3927,7 +3925,7 @@ pub impl Resolver { } fn resolve_type_parameters(@mut self, - type_parameters: ~[ty_param], + type_parameters: &OptVec, visitor: ResolveVisitor) { for type_parameters.each |type_parameter| { for type_parameter.bounds.each |&bound| { @@ -3941,19 +3939,17 @@ pub impl Resolver { fn resolve_struct(@mut self, id: node_id, - type_parameters: @~[ty_param], - fields: ~[@struct_field], + generics: &Generics, + fields: &[@struct_field], optional_destructor: Option, visitor: ResolveVisitor) { // If applicable, create a rib for the type parameters. - let borrowed_type_parameters: &~[ty_param] = &*type_parameters; do self.with_type_parameter_rib(HasTypeParameters - (borrowed_type_parameters, id, 0, + (generics, id, 0, OpaqueFunctionRibKind)) { // Resolve the type parameters. - self.resolve_type_parameters(/*bad*/copy *type_parameters, - visitor); + self.resolve_type_parameters(&generics.ty_params, visitor); // Resolve fields. for fields.each |field| { @@ -3986,9 +3982,9 @@ pub impl Resolver { method: @method, outer_type_parameter_count: uint, visitor: ResolveVisitor) { - let borrowed_method_type_parameters = &method.tps; + let method_generics = &method.generics; let type_parameters = - HasTypeParameters(borrowed_method_type_parameters, + HasTypeParameters(method_generics, method.id, outer_type_parameter_count, rib_kind); @@ -4010,19 +4006,18 @@ pub impl Resolver { fn resolve_implementation(@mut self, id: node_id, span: span, - type_parameters: ~[ty_param], + generics: &Generics, opt_trait_reference: Option<@trait_ref>, self_type: @Ty, methods: ~[@method], visitor: ResolveVisitor) { // If applicable, create a rib for the type parameters. - let outer_type_parameter_count = type_parameters.len(); - let borrowed_type_parameters: &~[ty_param] = &type_parameters; + let outer_type_parameter_count = generics.ty_params.len(); do self.with_type_parameter_rib(HasTypeParameters - (borrowed_type_parameters, id, 0, + (generics, id, 0, NormalRibKind)) { // Resolve the type parameters. - self.resolve_type_parameters(/*bad*/copy type_parameters, + self.resolve_type_parameters(&generics.ty_params, visitor); // Resolve the trait reference, if necessary. diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 53555dc9ff855..142c327855651 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2103,9 +2103,9 @@ pub fn trans_item(ccx: @CrateContext, item: ast::item) { } } } - ast::item_impl(tps, _, _, ms) => { - meth::trans_impl(ccx, /*bad*/copy *path, item.ident, ms, tps, None, - item.id); + ast::item_impl(ref generics, _, _, ref ms) => { + meth::trans_impl(ccx, /*bad*/copy *path, item.ident, *ms, + generics, None, item.id); } ast::item_mod(m) => { trans_mod(ccx, m); diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index 43369aa9d755e..b352b078a473c 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -91,7 +91,9 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::def_id, region_param: _, ty: _ } = ty::lookup_item_type(ccx.tcx, impl_did); - if translate && (*impl_bnds).len() + mth.tps.len() == 0u { + if translate && + impl_bnds.len() + mth.generics.ty_params.len() == 0u + { let llfn = get_item_val(ccx, mth.id); let path = vec::append( ty::item_path(ccx.tcx, impl_did), diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 07b6556df6aa0..777711889c7a8 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -46,13 +46,13 @@ be generated once they are invoked with specific type parameters, see `trans::base::lval_static_fn()` or `trans::base::monomorphic_fn()`. */ pub fn trans_impl(ccx: @CrateContext, +path: path, name: ast::ident, - methods: ~[@ast::method], tps: ~[ast::ty_param], + methods: ~[@ast::method], generics: &ast::Generics, self_ty: Option, id: ast::node_id) { let _icx = ccx.insn_ctxt("impl::trans_impl"); - if tps.len() > 0u { return; } + if !generics.ty_params.is_empty() { return; } let sub_path = vec::append_one(path, path_name(name)); for vec::each(methods) |method| { - if method.tps.len() == 0u { + if method.generics.ty_params.len() == 0u { let llfn = get_item_val(ccx, method.id); let path = vec::append_one(/*bad*/copy sub_path, path_name(method.ident)); @@ -410,7 +410,7 @@ pub fn method_ty_param_count(ccx: @CrateContext, m_id: ast::def_id, debug!("method_ty_param_count: m_id: %?, i_id: %?", m_id, i_id); if m_id.crate == ast::local_crate { match ccx.tcx.items.find(&m_id.node) { - Some(ast_map::node_method(m, _, _)) => m.tps.len(), + Some(ast_map::node_method(m, _, _)) => m.generics.ty_params.len(), None => { match ccx.tcx.provided_method_sources.find(&m_id) { Some(source) => { @@ -420,9 +420,9 @@ pub fn method_ty_param_count(ccx: @CrateContext, m_id: ast::def_id, None => fail!() } } - Some(ast_map::node_trait_method(@ast::provided(@ref m), _, _)) - => { - m.tps.len() + Some(ast_map::node_trait_method(@ast::provided(@ref m), + _, _)) => { + m.generics.ty_params.len() } copy e => fail!(fmt!("method_ty_param_count %?", e)) } diff --git a/src/librustc/middle/trans/reachable.rs b/src/librustc/middle/trans/reachable.rs index d56d28c982d7d..a235322532b06 100644 --- a/src/librustc/middle/trans/reachable.rs +++ b/src/librustc/middle/trans/reachable.rs @@ -97,38 +97,41 @@ fn traverse_public_mod(cx: ctx, mod_id: node_id, m: _mod) { fn traverse_public_item(cx: ctx, item: @item) { if cx.rmap.contains_key(&item.id) { return; } cx.rmap.insert(item.id, ()); - match /*bad*/copy item.node { - item_mod(m) => traverse_public_mod(cx, item.id, m), - item_foreign_mod(nm) => { + match item.node { + item_mod(ref m) => traverse_public_mod(cx, item.id, *m), + item_foreign_mod(ref nm) => { if !traverse_exports(cx, item.id) { for vec::each(nm.items) |item| { cx.rmap.insert(item.id, ()); } } } - item_fn(_, _, ref tps, ref blk) => { - if tps.len() > 0u || + item_fn(_, _, ref generics, ref blk) => { + if generics.ty_params.len() > 0u || attr::find_inline_attr(item.attrs) != attr::ia_none { traverse_inline_body(cx, (*blk)); } } - item_impl(tps, _, _, ms) => { - for vec::each(ms) |m| { - if tps.len() > 0u || m.tps.len() > 0u || - attr::find_inline_attr(m.attrs) != attr::ia_none { + item_impl(ref generics, _, _, ref ms) => { + for ms.each |m| { + if generics.ty_params.len() > 0u || + m.generics.ty_params.len() > 0u || + attr::find_inline_attr(m.attrs) != attr::ia_none + { cx.rmap.insert(m.id, ()); traverse_inline_body(cx, m.body); } } } - item_struct(struct_def, tps) => { + item_struct(ref struct_def, ref generics) => { for struct_def.ctor_id.each |&ctor_id| { cx.rmap.insert(ctor_id, ()); } do option::iter(&struct_def.dtor) |dtor| { cx.rmap.insert(dtor.node.id, ()); - if tps.len() > 0u || attr::find_inline_attr(dtor.node.attrs) - != attr::ia_none { + if generics.ty_params.len() > 0u || + attr::find_inline_attr(dtor.node.attrs) != attr::ia_none + { traverse_inline_body(cx, dtor.node.body); } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 182ab11b91721..792d1fb4dfb1d 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -4143,10 +4143,11 @@ pub fn is_binopable(_cx: ctxt, ty: t, op: ast::binop) -> bool { return tbl[tycat(ty)][opcat(op)]; } -pub fn ty_params_to_tys(tcx: ty::ctxt, tps: ~[ast::ty_param]) -> ~[t] { - vec::from_fn(tps.len(), |i| { - ty::mk_param(tcx, i, ast_util::local_def(tps[i].id)) - }) +pub fn ty_params_to_tys(tcx: ty::ctxt, generics: &ast::Generics) -> ~[t] { + vec::from_fn(generics.ty_params.len(), |i| { + let id = generics.ty_params.get(i).id; + ty::mk_param(tcx, i, ast_util::local_def(id)) + }) } /// Returns an equivalent type with all the typedefs and self regions removed. diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index e63e46ace3d05..fe956162786d5 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -127,6 +127,8 @@ use syntax::codemap; use syntax::parse::token::special_idents; use syntax::print::pprust; use syntax::visit; +use syntax::opt_vec::OptVec; +use syntax::opt_vec; use syntax; pub mod _match; @@ -592,9 +594,9 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) { ast::item_struct(struct_def, _) => { check_struct(ccx, struct_def, it.id, it.span); } - ast::item_ty(t, tps) => { + ast::item_ty(t, ref generics) => { let tpt_ty = ty::node_id_to_type(ccx.tcx, it.id); - check_bounds_are_used(ccx, t.span, tps, tpt_ty); + check_bounds_are_used(ccx, t.span, &generics.ty_params, tpt_ty); // If this is a record ty, check for duplicate fields match t.node { ast::ty_rec(ref fields) => { @@ -1062,8 +1064,9 @@ pub fn impl_self_ty(vcx: &VtableContext, node: ast::item_impl(ref ts, _, st, _), _ }, _)) => { - (ts.len(), region_param, - vcx.ccx.to_ty(rscope::type_rscope(region_param), st)) + (ts.ty_params.len(), + region_param, + vcx.ccx.to_ty(rscope::type_rscope(region_param), st)) } Some(ast_map::node_item(@ast::item { node: ast::item_struct(_, ref ts), @@ -1074,12 +1077,13 @@ pub fn impl_self_ty(vcx: &VtableContext, (doing a no-op subst for the ty params; in the next step, we substitute in fresh vars for them) */ - (ts.len(), region_param, - ty::mk_struct(tcx, local_def(class_id), + (ts.ty_params.len(), + region_param, + ty::mk_struct(tcx, local_def(class_id), substs { self_r: rscope::bound_self_region(region_param), self_ty: None, - tps: ty::ty_params_to_tys(tcx, /*bad*/copy *ts) + tps: ty::ty_params_to_tys(tcx, ts) })) } _ => { tcx.sess.bug(~"impl_self_ty: unbound item or item that \ @@ -1862,11 +1866,11 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, tcx.region_paramd_items.find(&class_id.node); match tcx.items.find(&class_id.node) { Some(ast_map::node_item(@ast::item { - node: ast::item_struct(_, ref type_parameters), + node: ast::item_struct(_, ref generics), _ }, _)) => { - type_parameter_count = type_parameters.len(); + type_parameter_count = generics.ty_params.len(); let self_region = bound_self_region(region_parameterized); @@ -1876,7 +1880,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, self_ty: None, tps: ty::ty_params_to_tys( tcx, - /*bad*/copy *type_parameters) + generics) }); } _ => { @@ -1946,11 +1950,11 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, tcx.region_paramd_items.find(&enum_id.node); match tcx.items.find(&enum_id.node) { Some(ast_map::node_item(@ast::item { - node: ast::item_enum(_, ref type_parameters), + node: ast::item_enum(_, ref generics), _ }, _)) => { - type_parameter_count = type_parameters.len(); + type_parameter_count = generics.ty_params.len(); let self_region = bound_self_region(region_parameterized); @@ -1960,7 +1964,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, self_ty: None, tps: ty::ty_params_to_tys( tcx, - /*bad*/copy *type_parameters) + generics) }); } _ => { @@ -3126,7 +3130,7 @@ pub fn may_break(cx: ty::ctxt, id: ast::node_id, b: ast::blk) -> bool { pub fn check_bounds_are_used(ccx: @mut CrateCtxt, span: span, - tps: ~[ast::ty_param], + tps: &OptVec, ty: ty::t) { debug!("check_bounds_are_used(n_tps=%u, ty=%s)", tps.len(), ppaux::ty_to_str(ccx.tcx, ty)); @@ -3153,7 +3157,7 @@ pub fn check_bounds_are_used(ccx: @mut CrateCtxt, if !*b { ccx.tcx.sess.span_err( span, fmt!("type parameter `%s` is unused", - *ccx.tcx.sess.str_of(tps[i].ident))); + *ccx.tcx.sess.str_of(tps.get(i).ident))); } } } diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 29738f2826661..5ab2bcd851912 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -147,7 +147,7 @@ pub fn get_base_type_def_id(inference_context: @mut InferCtxt, pub fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo { @MethodInfo { did: local_def(ast_method.id), - n_tps: ast_method.tps.len(), + n_tps: ast_method.generics.ty_params.len(), ident: ast_method.ident, self_type: ast_method.self_ty.node } diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 96c76b52181c1..630ff46ccfbef 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -60,6 +60,8 @@ use syntax::codemap::span; use syntax::codemap; use syntax::print::pprust::path_to_str; use syntax::visit; +use syntax::opt_vec; +use syntax::opt_vec::OptVec; pub fn collect_item_types(ccx: @mut CrateCtxt, crate: @ast::crate) { @@ -70,8 +72,8 @@ pub fn collect_item_types(ccx: @mut CrateCtxt, crate: @ast::crate) { if crate_item.ident == ::syntax::parse::token::special_idents::intrinsic { - match /*bad*/copy crate_item.node { - ast::item_mod(m) => { + match crate_item.node { + ast::item_mod(ref m) => { for m.items.each |intrinsic_item| { let def_id = ast::def_id { crate: ast::local_crate, node: intrinsic_item.id }; @@ -153,7 +155,7 @@ pub impl AstConv for CrateCtxt { pub fn get_enum_variant_types(ccx: @mut CrateCtxt, enum_ty: ty::t, variants: &[ast::variant], - +ty_params: ~[ast::ty_param], + generics: &ast::Generics, rp: Option) { let tcx = ccx.tcx; @@ -175,7 +177,7 @@ pub fn get_enum_variant_types(ccx: @mut CrateCtxt, ast::struct_variant_kind(struct_def) => { let tpt = ty_param_bounds_and_ty { - bounds: ty_param_bounds(ccx, ty_params), + bounds: ty_param_bounds(ccx, generics), region_param: rp, ty: enum_ty }; @@ -183,7 +185,7 @@ pub fn get_enum_variant_types(ccx: @mut CrateCtxt, convert_struct(ccx, rp, struct_def, - ty_params.to_vec(), + generics, tpt, variant.node.id); @@ -196,7 +198,7 @@ pub fn get_enum_variant_types(ccx: @mut CrateCtxt, get_enum_variant_types(ccx, enum_ty, enum_definition.variants, - copy ty_params, + generics, rp); result_ty = None; } @@ -206,7 +208,7 @@ pub fn get_enum_variant_types(ccx: @mut CrateCtxt, None => {} Some(result_ty) => { let tpt = ty_param_bounds_and_ty { - bounds: ty_param_bounds(ccx, ty_params), + bounds: ty_param_bounds(ccx, generics), region_param: rp, ty: result_ty }; @@ -276,7 +278,7 @@ pub fn ensure_trait_methods(ccx: @mut CrateCtxt, let region_paramd = tcx.region_paramd_items.find(&id); match tcx.items.get(&id) { ast_map::node_item(@ast::item { - node: ast::item_trait(ref params, _, ref ms), + node: ast::item_trait(ref generics, _, ref ms), _ }, _) => { store_methods::(ccx, id, (/*bad*/copy *ms), |m| { @@ -288,7 +290,7 @@ pub fn ensure_trait_methods(ccx: @mut CrateCtxt, ast::provided(method) => def_id = local_def(method.id) } - let trait_bounds = ty_param_bounds(ccx, *params); + let trait_bounds = ty_param_bounds(ccx, generics); let ty_m = trait_method_to_ty_method(*m); let method_ty = ty_of_ty_method(ccx, ty_m, region_paramd, def_id); if ty_m.self_ty.node == ast::sty_static { @@ -488,7 +490,7 @@ pub fn compare_impl_method(tcx: ty::ctxt, } pub fn check_methods_against_trait(ccx: @mut CrateCtxt, - tps: ~[ast::ty_param], + generics: &ast::Generics, rp: Option, selfty: ty::t, a_trait_ty: @ast::trait_ref, @@ -522,8 +524,9 @@ pub fn check_methods_against_trait(ccx: @mut CrateCtxt, for impl_ms.each |impl_m| { match trait_ms.find(|trait_m| trait_m.ident == impl_m.mty.ident) { Some(ref trait_m) => { + let num_impl_tps = generics.ty_params.len(); compare_impl_method( - ccx.tcx, tps.len(), impl_m, trait_m, + ccx.tcx, num_impl_tps, impl_m, trait_m, &tpt.substs, selfty); } None => { @@ -568,7 +571,7 @@ pub fn convert_methods(ccx: @mut CrateCtxt, let tcx = ccx.tcx; do vec::map(ms) |m| { - let bounds = ty_param_bounds(ccx, m.tps); + let bounds = ty_param_bounds(ccx, &m.generics); let mty = ty_of_method(ccx, *m, rp); let fty = ty::mk_bare_fn(tcx, copy mty.fty); tcx.tcache.insert( @@ -589,9 +592,9 @@ pub fn convert_methods(ccx: @mut CrateCtxt, pub fn ensure_no_ty_param_bounds(ccx: @mut CrateCtxt, span: span, - ty_params: &[ast::ty_param], + generics: &ast::Generics, thing: &static/str) { - for ty_params.each |ty_param| { + for generics.ty_params.each |ty_param| { if ty_param.bounds.len() > 0 { ccx.tcx.sess.span_err( span, @@ -606,21 +609,21 @@ pub fn convert(ccx: @mut CrateCtxt, it: @ast::item) { let rp = tcx.region_paramd_items.find(&it.id); debug!("convert: item %s with id %d rp %?", *tcx.sess.str_of(it.ident), it.id, rp); - match /*bad*/copy it.node { + match it.node { // These don't define types. ast::item_foreign_mod(_) | ast::item_mod(_) => {} - ast::item_enum(ref enum_definition, ref ty_params) => { - ensure_no_ty_param_bounds(ccx, it.span, *ty_params, "enumeration"); + ast::item_enum(ref enum_definition, ref generics) => { + ensure_no_ty_param_bounds(ccx, it.span, generics, "enumeration"); let tpt = ty_of_item(ccx, it); write_ty_to_tcx(tcx, it.id, tpt.ty); get_enum_variant_types(ccx, tpt.ty, enum_definition.variants, - copy *ty_params, + generics, rp); } - ast::item_impl(ref tps, trait_ref, selfty, ref ms) => { - let i_bounds = ty_param_bounds(ccx, *tps); + ast::item_impl(ref generics, trait_ref, selfty, ref ms) => { + let i_bounds = ty_param_bounds(ccx, generics); let selfty = ccx.to_ty(type_rscope(rp), selfty); write_ty_to_tcx(tcx, it.id, selfty); tcx.tcache.insert(local_def(it.id), @@ -632,11 +635,11 @@ pub fn convert(ccx: @mut CrateCtxt, it: @ast::item) { // XXX: Bad copy of `ms` below. let cms = convert_methods(ccx, /*bad*/copy *ms, rp, i_bounds); for trait_ref.each |t| { - check_methods_against_trait(ccx, /*bad*/copy *tps, rp, selfty, + check_methods_against_trait(ccx, generics, rp, selfty, *t, /*bad*/copy cms); } } - ast::item_trait(ref tps, ref supertraits, ref trait_methods) => { + ast::item_trait(ref generics, ref supertraits, ref trait_methods) => { let tpt = ty_of_item(ccx, it); debug!("item_trait(it.id=%d, tpt.ty=%s)", it.id, ppaux::ty_to_str(tcx, tpt.ty)); @@ -646,21 +649,21 @@ pub fn convert(ccx: @mut CrateCtxt, it: @ast::item) { let (_, provided_methods) = split_trait_methods(/*bad*/copy *trait_methods); - let (bounds, _) = mk_substs(ccx, /*bad*/copy *tps, rp); + let (bounds, _) = mk_substs(ccx, generics, rp); let _ = convert_methods(ccx, provided_methods, rp, bounds); } - ast::item_struct(struct_def, tps) => { - ensure_no_ty_param_bounds(ccx, it.span, tps, "structure"); + ast::item_struct(struct_def, ref generics) => { + ensure_no_ty_param_bounds(ccx, it.span, generics, "structure"); // Write the class type let tpt = ty_of_item(ccx, it); write_ty_to_tcx(tcx, it.id, tpt.ty); tcx.tcache.insert(local_def(it.id), tpt); - convert_struct(ccx, rp, struct_def, tps, tpt, it.id); + convert_struct(ccx, rp, struct_def, generics, tpt, it.id); } - ast::item_ty(_, ref ty_params) => { - ensure_no_ty_param_bounds(ccx, it.span, *ty_params, "type"); + ast::item_ty(_, ref generics) => { + ensure_no_ty_param_bounds(ccx, it.span, generics, "type"); let tpt = ty_of_item(ccx, it); write_ty_to_tcx(tcx, it.id, tpt.ty); } @@ -677,7 +680,7 @@ pub fn convert(ccx: @mut CrateCtxt, it: @ast::item) { pub fn convert_struct(ccx: @mut CrateCtxt, rp: Option, struct_def: @ast::struct_def, - +tps: ~[ast::ty_param], + generics: &ast::Generics, tpt: ty::ty_param_bounds_and_ty, id: ast::node_id) { let tcx = ccx.tcx; @@ -702,7 +705,7 @@ pub fn convert_struct(ccx: @mut CrateCtxt, for struct_def.fields.each |f| { convert_field(ccx, rp, tpt.bounds, *f); } - let (_, substs) = mk_substs(ccx, tps, rp); + let (_, substs) = mk_substs(ccx, generics, rp); let selfty = ty::mk_struct(tcx, local_def(id), substs); // If this struct is enum-like or tuple-like, create the type of its @@ -746,7 +749,7 @@ pub fn ty_of_method(ccx: @mut CrateCtxt, rp: Option) -> ty::method { ty::method { ident: m.ident, - tps: ty_param_bounds(ccx, m.tps), + tps: ty_param_bounds(ccx, &m.generics), fty: astconv::ty_of_bare_fn(ccx, type_rscope(rp), m.purity, ast::RustAbi, m.decl), self_ty: m.self_ty.node, @@ -761,7 +764,7 @@ pub fn ty_of_ty_method(self: @mut CrateCtxt, id: ast::def_id) -> ty::method { ty::method { ident: m.ident, - tps: ty_param_bounds(self, m.tps), + tps: ty_param_bounds(self, &m.generics), fty: astconv::ty_of_bare_fn(self, type_rscope(rp), m.purity, ast::RustAbi, m.decl), // assume public, because this is only invoked on trait methods @@ -809,17 +812,17 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item) _ => {} } let rp = tcx.region_paramd_items.find(&it.id); - match /*bad*/copy it.node { + match it.node { ast::item_const(t, _) => { let typ = ccx.to_ty(empty_rscope, t); let tpt = no_params(typ); tcx.tcache.insert(local_def(it.id), tpt); return tpt; } - ast::item_fn(decl, purity, tps, _) => { - let bounds = ty_param_bounds(ccx, tps); + ast::item_fn(ref decl, purity, ref generics, _) => { + let bounds = ty_param_bounds(ccx, generics); let tofd = astconv::ty_of_bare_fn(ccx, empty_rscope, purity, - ast::RustAbi, decl); + ast::RustAbi, *decl); let tpt = ty_param_bounds_and_ty { bounds: bounds, region_param: None, @@ -832,7 +835,7 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item) ccx.tcx.tcache.insert(local_def(it.id), tpt); return tpt; } - ast::item_ty(t, tps) => { + ast::item_ty(t, ref generics) => { match tcx.tcache.find(&local_def(it.id)) { Some(tpt) => return tpt, None => { } @@ -846,12 +849,12 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item) // like "foo". This is because otherwise ty_to_str will // print the name as merely "foo", as it has no way to // reconstruct the value of X. - if !vec::is_empty(tps) { t0 } else { + if !generics.is_empty() { t0 } else { ty::mk_with_id(tcx, t0, def_id) } }; ty_param_bounds_and_ty { - bounds: ty_param_bounds(ccx, tps), + bounds: ty_param_bounds(ccx, generics), region_param: rp, ty: ty } @@ -860,9 +863,9 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item) tcx.tcache.insert(local_def(it.id), tpt); return tpt; } - ast::item_enum(_, tps) => { + ast::item_enum(_, ref generics) => { // Create a new generic polytype. - let (bounds, substs) = mk_substs(ccx, tps, rp); + let (bounds, substs) = mk_substs(ccx, generics, rp); let t = ty::mk_enum(tcx, local_def(it.id), substs); let tpt = ty_param_bounds_and_ty { bounds: bounds, @@ -872,8 +875,8 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item) tcx.tcache.insert(local_def(it.id), tpt); return tpt; } - ast::item_trait(tps, _, _) => { - let (bounds, substs) = mk_substs(ccx, tps, rp); + ast::item_trait(ref generics, _, _) => { + let (bounds, substs) = mk_substs(ccx, generics, rp); let t = ty::mk_trait(tcx, local_def(it.id), substs, ty::vstore_box); let tpt = ty_param_bounds_and_ty { bounds: bounds, @@ -883,8 +886,8 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item) tcx.tcache.insert(local_def(it.id), tpt); return tpt; } - ast::item_struct(_, tps) => { - let (bounds, substs) = mk_substs(ccx, tps, rp); + ast::item_struct(_, ref generics) => { + let (bounds, substs) = mk_substs(ccx, generics, rp); let t = ty::mk_struct(tcx, local_def(it.id), substs); let tpt = ty_param_bounds_and_ty { bounds: bounds, @@ -902,9 +905,10 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item) pub fn ty_of_foreign_item(ccx: @mut CrateCtxt, it: @ast::foreign_item) -> ty::ty_param_bounds_and_ty { - match /*bad*/copy it.node { - ast::foreign_item_fn(fn_decl, _, params) => { - return ty_of_foreign_fn_decl(ccx, fn_decl, params, local_def(it.id)); + match it.node { + ast::foreign_item_fn(ref fn_decl, _, ref generics) => { + return ty_of_foreign_fn_decl(ccx, *fn_decl, local_def(it.id), + generics); } ast::foreign_item_const(t) => { let rb = in_binding_rscope(empty_rscope); @@ -922,9 +926,9 @@ pub fn ty_of_foreign_item(ccx: @mut CrateCtxt, it: @ast::foreign_item) // either be user-defined traits, or one of the four built-in traits (formerly // known as kinds): Const, Copy, Durable, and Send. pub fn compute_bounds(ccx: @mut CrateCtxt, - ast_bounds: @~[ast::ty_param_bound]) + ast_bounds: @OptVec) -> ty::param_bounds { - @do vec::flat_map(*ast_bounds) |b| { + @ast_bounds.flat_map_to_vec(|b| { match b { &TraitTyParamBound(b) => { let li = &ccx.tcx.lang_items; @@ -954,13 +958,13 @@ pub fn compute_bounds(ccx: @mut CrateCtxt, } &RegionTyParamBound => ~[ty::bound_durable] } - } + }) } pub fn ty_param_bounds(ccx: @mut CrateCtxt, - params: ~[ast::ty_param]) + generics: &ast::Generics) -> @~[ty::param_bounds] { - @do params.map |param| { + @do generics.ty_params.map_to_vec |param| { match ccx.tcx.ty_param_bounds.find(¶m.id) { Some(bs) => bs, None => { @@ -974,10 +978,10 @@ pub fn ty_param_bounds(ccx: @mut CrateCtxt, pub fn ty_of_foreign_fn_decl(ccx: @mut CrateCtxt, decl: ast::fn_decl, - +ty_params: ~[ast::ty_param], - def_id: ast::def_id) + def_id: ast::def_id, + generics: &ast::Generics) -> ty::ty_param_bounds_and_ty { - let bounds = ty_param_bounds(ccx, ty_params); + let bounds = ty_param_bounds(ccx, generics); let rb = in_binding_rscope(empty_rscope); let input_tys = decl.inputs.map(|a| ty_of_arg(ccx, rb, *a, None) ); let output_ty = ast_ty_to_ty(ccx, rb, decl.output); @@ -998,13 +1002,13 @@ pub fn ty_of_foreign_fn_decl(ccx: @mut CrateCtxt, return tpt; } -pub fn mk_ty_params(ccx: @mut CrateCtxt, atps: ~[ast::ty_param]) - -> (@~[ty::param_bounds], ~[ty::t]) { - +pub fn mk_generics(ccx: @mut CrateCtxt, generics: &ast::Generics) + -> (@~[ty::param_bounds], ~[ty::t]) +{ let mut i = 0u; - let bounds = ty_param_bounds(ccx, atps); + let bounds = ty_param_bounds(ccx, generics); (bounds, - vec::map(atps, |atp| { + generics.ty_params.map_to_vec(|atp| { let t = ty::mk_param(ccx.tcx, i, local_def(atp.id)); i += 1u; t @@ -1012,10 +1016,11 @@ pub fn mk_ty_params(ccx: @mut CrateCtxt, atps: ~[ast::ty_param]) } pub fn mk_substs(ccx: @mut CrateCtxt, - +atps: ~[ast::ty_param], + generics: &ast::Generics, rp: Option) - -> (@~[ty::param_bounds], ty::substs) { - let (bounds, params) = mk_ty_params(ccx, atps); + -> (@~[ty::param_bounds], ty::substs) +{ + let (bounds, params) = mk_generics(ccx, generics); let self_r = rscope::bound_self_region(rp); (bounds, substs { self_r: self_r, self_ty: None, tps: params }) } diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index b39cee875251a..bdfc2be7bd673 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -77,7 +77,7 @@ fn get_fn_sig(srv: astsrv::Srv, fn_id: doc::AstId) -> Option<~str> { ident: ident, node: ast::foreign_item_fn(ref decl, _, ref tys), _ }, _, _) => { - Some(pprust::fun_to_str(*decl, ident, copy *tys, + Some(pprust::fun_to_str(*decl, ident, tys, extract::interner())) } _ => fail!(~"get_fn_sig: fn_id not bound to a fn item") @@ -215,7 +215,7 @@ fn get_method_sig( Some(pprust::fun_to_str( ty_m.decl, ty_m.ident, - copy ty_m.tps, + &ty_m.generics, extract::interner() )) } @@ -223,7 +223,7 @@ fn get_method_sig( Some(pprust::fun_to_str( m.decl, m.ident, - copy m.tps, + &m.generics, extract::interner() )) } @@ -242,7 +242,7 @@ fn get_method_sig( Some(pprust::fun_to_str( method.decl, method.ident, - copy method.tps, + &method.generics, extract::interner() )) } @@ -339,7 +339,7 @@ fn fold_type( Some(fmt!( "type %s%s = %s", to_str(ident), - pprust::typarams_to_str(*params, + pprust::generics_to_str(params, extract::interner()), pprust::ty_to_str(ty, extract::interner()) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 5af67aa0e3b33..5460584763eec 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -21,6 +21,8 @@ use core::to_bytes; use core::to_str::ToStr; use std::serialize::{Encodable, Decodable, Encoder, Decoder}; +use opt_vec::OptVec; + /* can't import macros yet, so this is copied from token.rs. See its comment * there. */ macro_rules! interner_key ( @@ -96,6 +98,9 @@ pub impl to_bytes::IterBytes for ident { // Functions may or may not have names. pub type fn_ident = Option; +#[auto_encode] +#[auto_decode] +#[deriving_eq] pub struct Lifetime { id: node_id, span: span, @@ -135,7 +140,7 @@ pub const crate_node_id: node_id = 0; // typeck::collect::compute_bounds matches these against // the "special" built-in traits (see middle::lang_items) and // detects Copy, Send, Owned, and Const. -pub enum ty_param_bound { +pub enum TyParamBound { TraitTyParamBound(@Ty), RegionTyParamBound } @@ -143,10 +148,24 @@ pub enum ty_param_bound { #[auto_encode] #[auto_decode] #[deriving_eq] -pub struct ty_param { +pub struct TyParam { ident: ident, id: node_id, - bounds: @~[ty_param_bound] + bounds: @OptVec +} + +#[auto_encode] +#[auto_decode] +#[deriving_eq] +pub struct Generics { + lifetimes: OptVec, + ty_params: OptVec +} + +impl Generics { + fn is_empty(&self) -> bool { + self.lifetimes.len() + self.ty_params.len() == 0 + } } #[auto_encode] @@ -273,8 +292,8 @@ pub enum pat_ { // records this pattern's node_id in an auxiliary // set (of "pat_idents that refer to nullary enums") pat_ident(binding_mode, @path, Option<@pat>), - pat_enum(@path, Option<~[@pat]>), // "none" means a * pattern where - // we don't bind the fields to names + pat_enum(@path, Option<~[@pat]>), /* "none" means a * pattern where + * we don't bind the fields to names */ pat_rec(~[field_pat], bool), pat_struct(@path, ~[field_pat], bool), pat_tup(~[@pat]), @@ -749,7 +768,7 @@ pub struct ty_method { attrs: ~[attribute], purity: purity, decl: fn_decl, - tps: ~[ty_param], + generics: Generics, self_ty: self_ty, id: node_id, span: span, @@ -1012,7 +1031,7 @@ pub type self_ty = spanned; pub struct method { ident: ident, attrs: ~[attribute], - tps: ~[ty_param], + generics: Generics, self_ty: self_ty, purity: purity, decl: fn_decl, @@ -1248,14 +1267,14 @@ pub struct item { #[deriving_eq] pub enum item_ { item_const(@Ty, @expr), - item_fn(fn_decl, purity, ~[ty_param], blk), + item_fn(fn_decl, purity, Generics, blk), item_mod(_mod), item_foreign_mod(foreign_mod), - item_ty(@Ty, ~[ty_param]), - item_enum(enum_def, ~[ty_param]), - item_struct(@struct_def, ~[ty_param]), - item_trait(~[ty_param], ~[@trait_ref], ~[trait_method]), - item_impl(~[ty_param], + item_ty(@Ty, Generics), + item_enum(enum_def, Generics), + item_struct(@struct_def, Generics), + item_trait(Generics, ~[@trait_ref], ~[trait_method]), + item_impl(Generics, Option<@trait_ref>, // (optional) trait this impl implements @Ty, // self ~[@method]), @@ -1302,7 +1321,7 @@ pub struct foreign_item { #[auto_decode] #[deriving_eq] pub enum foreign_item_ { - foreign_item_fn(fn_decl, purity, ~[ty_param]), + foreign_item_fn(fn_decl, purity, Generics), foreign_item_const(@Ty) } @@ -1316,7 +1335,7 @@ pub enum inlined_item { ii_item(@item), ii_method(def_id /* impl id */, @method), ii_foreign(@foreign_item), - ii_dtor(struct_dtor, ident, ~[ty_param], def_id /* parent id */) + ii_dtor(struct_dtor, ident, Generics, def_id /* parent id */) } #[cfg(test)] diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 74f67808a5e97..ea34d5a2779bf 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -101,7 +101,7 @@ pub enum ast_node { node_arg(arg, uint), node_local(uint), // Destructor for a struct - node_dtor(~[ty_param], @struct_dtor, def_id, @path), + node_dtor(Generics, @struct_dtor, def_id, @path), node_block(blk), node_struct_ctor(@struct_def, @item, @path), } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index fec3a961a52a2..95f52fbea99ae 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -16,6 +16,7 @@ use ast_util; use codemap::{span, BytePos, dummy_sp}; use parse::token; use visit; +use opt_vec; use core::cmp; use core::int; @@ -263,13 +264,13 @@ pub fn public_methods(ms: ~[@method]) -> ~[@method] { pub fn trait_method_to_ty_method(method: trait_method) -> ty_method { match method { required(ref m) => (*m), - provided(m) => { + provided(ref m) => { ty_method { ident: m.ident, attrs: m.attrs, purity: m.purity, decl: m.decl, - tps: m.tps, + generics: copy m.generics, self_ty: m.self_ty, id: m.id, span: m.span, @@ -327,8 +328,9 @@ pub impl inlined_item_utils for inlined_item { ii_item(i) => (v.visit_item)(i, e, v), ii_foreign(i) => (v.visit_foreign_item)(i, e, v), ii_method(_, m) => visit::visit_method_helper(m, e, v), - ii_dtor(/*bad*/ copy dtor, _, /*bad*/ copy tps, parent_id) => { - visit::visit_struct_dtor_helper(dtor, tps, parent_id, e, v); + ii_dtor(/*bad*/ copy dtor, _, ref generics, parent_id) => { + visit::visit_struct_dtor_helper(dtor, generics, + parent_id, e, v); } } } @@ -375,6 +377,11 @@ pub fn dtor_dec() -> fn_decl { } } +pub fn empty_generics() -> Generics { + Generics {lifetimes: opt_vec::Empty, + ty_params: opt_vec::Empty} +} + // ______________________________________________________________________ // Enumerating the IDs which appear in an AST @@ -390,6 +397,14 @@ pub fn empty(range: id_range) -> bool { } pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { + let visit_generics = fn@(generics: &Generics) { + for generics.ty_params.each |p| { + vfn(p.id); + } + for generics.lifetimes.each |p| { + vfn(p.id); + } + }; visit::mk_simple_visitor(@visit::SimpleVisitor { visit_mod: |_m, _sp, id| vfn(id), @@ -457,29 +472,25 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { } }, - visit_ty_params: fn@(ps: ~[ty_param]) { - for vec::each(ps) |p| { - vfn(p.id); - } - }, + visit_generics: visit_generics, visit_fn: fn@(fk: visit::fn_kind, d: ast::fn_decl, _b: ast::blk, _sp: span, id: ast::node_id) { vfn(id); match fk { - visit::fk_dtor(tps, _, self_id, parent_id) => { - for vec::each(tps) |tp| { vfn(tp.id); } + visit::fk_dtor(ref generics, _, self_id, parent_id) => { + visit_generics(generics); vfn(id); vfn(self_id); vfn(parent_id.node); } - visit::fk_item_fn(_, tps, _) => { - for vec::each(tps) |tp| { vfn(tp.id); } + visit::fk_item_fn(_, ref generics, _) => { + visit_generics(generics); } - visit::fk_method(_, tps, m) => { + visit::fk_method(_, ref generics, m) => { vfn(m.self_id); - for vec::each(tps) |tp| { vfn(tp.id); } + visit_generics(generics); } visit::fk_anon(_) | visit::fk_fn_block => { @@ -497,7 +508,9 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { visit_trait_method: fn@(_ty_m: trait_method) { }, - visit_struct_def: fn@(_sd: @struct_def, _id: ident, _tps: ~[ty_param], + visit_struct_def: fn@(_sd: @struct_def, + _id: ident, + _generics: &Generics, _id: node_id) { }, diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 0019acc1291f4..6417707d8bb24 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -/* +/*! The compiler code necessary to implement the #[auto_encode] and #[auto_decode] extension. The idea here is that type-defining items may @@ -96,6 +96,9 @@ use attr; use codemap::span; use ext::base::*; use parse; +use opt_vec; +use opt_vec::OptVec; +use ext::build; use core::vec; use std::oldmap; @@ -127,24 +130,24 @@ pub fn expand_auto_encode( do vec::flat_map(in_items) |item| { if item.attrs.any(is_auto_encode) { match item.node { - ast::item_struct(ref struct_def, ref tps) => { + ast::item_struct(ref struct_def, ref generics) => { let ser_impl = mk_struct_ser_impl( cx, item.span, item.ident, struct_def.fields, - *tps + generics ); ~[filter_attrs(*item), ser_impl] }, - ast::item_enum(ref enum_def, ref tps) => { + ast::item_enum(ref enum_def, ref generics) => { let ser_impl = mk_enum_ser_impl( cx, item.span, item.ident, *enum_def, - *tps + generics ); ~[filter_attrs(*item), ser_impl] @@ -182,24 +185,24 @@ pub fn expand_auto_decode( do vec::flat_map(in_items) |item| { if item.attrs.any(is_auto_decode) { match item.node { - ast::item_struct(ref struct_def, ref tps) => { + ast::item_struct(ref struct_def, ref generics) => { let deser_impl = mk_struct_deser_impl( cx, item.span, item.ident, struct_def.fields, - *tps + generics ); ~[filter_attrs(*item), deser_impl] }, - ast::item_enum(ref enum_def, ref tps) => { + ast::item_enum(ref enum_def, ref generics) => { let deser_impl = mk_enum_deser_impl( cx, item.span, item.ident, *enum_def, - *tps + generics ); ~[filter_attrs(*item), deser_impl] @@ -222,18 +225,18 @@ priv impl ext_ctxt { span: span, ident: ast::ident, path: @ast::path, - bounds: @~[ast::ty_param_bound] - ) -> ast::ty_param { + bounds: @OptVec + ) -> ast::TyParam { let bound = ast::TraitTyParamBound(@ast::Ty { id: self.next_id(), node: ast::ty_path(path, self.next_id()), span: span, }); - ast::ty_param { + ast::TyParam { ident: ident, id: self.next_id(), - bounds: @vec::append(~[bound], *bounds) + bounds: @bounds.prepend(bound) } } @@ -408,28 +411,45 @@ fn mk_impl( cx: ext_ctxt, span: span, ident: ast::ident, - ty_param: ast::ty_param, + ty_param: ast::TyParam, path: @ast::path, - tps: &[ast::ty_param], + generics: &ast::Generics, f: fn(@ast::Ty) -> @ast::method ) -> @ast::item { + /*! + * + * Given that we are deriving auto-encode a type `T<'a, ..., + * 'z, A, ..., Z>`, creates an impl like: + * + * impl<'a, ..., 'z, A:Tr, ..., Z:Tr> Tr for T { ... } + * + * where Tr is either Serializable and Deserialize. + * + * FIXME(#5090): Remove code duplication between this and the code + * in deriving.rs + */ + + + // Copy the lifetimes + let impl_lifetimes = generics.lifetimes.map(|l| { + build::mk_lifetime(cx, l.span, l.ident) + }); + // All the type parameters need to bound to the trait. - let mut trait_tps = vec::append( - ~[ty_param], - do tps.map |tp| { - let t_bound = ast::TraitTyParamBound(@ast::Ty { - id: cx.next_id(), - node: ast::ty_path(path, cx.next_id()), - span: span, - }); + let mut impl_tps = opt_vec::with(ty_param); + for generics.ty_params.each |tp| { + let t_bound = ast::TraitTyParamBound(@ast::Ty { + id: cx.next_id(), + node: ast::ty_path(path, cx.next_id()), + span: span, + }); - ast::ty_param { - ident: tp.ident, - id: cx.next_id(), - bounds: @vec::append(~[t_bound], *tp.bounds) - } - } - ); + impl_tps.push(ast::TyParam { + ident: tp.ident, + id: cx.next_id(), + bounds: @tp.bounds.prepend(t_bound) + }) + } let opt_trait = Some(@ast::trait_ref { path: path, @@ -439,16 +459,22 @@ fn mk_impl( let ty = cx.ty_path( span, ~[ident], - tps.map(|tp| cx.ty_path(span, ~[tp.ident], ~[])) + generics.ty_params.map( + |tp| cx.ty_path(span, ~[tp.ident], ~[])).to_vec() ); + let generics = ast::Generics { + lifetimes: impl_lifetimes, + ty_params: impl_tps + }; + @ast::item { // This is a new-style impl declaration. // XXX: clownshoes ident: parse::token::special_idents::clownshoes_extensions, attrs: ~[], id: cx.next_id(), - node: ast::item_impl(trait_tps, opt_trait, ty, ~[f(ty)]), + node: ast::item_impl(generics, opt_trait, ty, ~[f(ty)]), vis: ast::public, span: span, } @@ -458,7 +484,7 @@ fn mk_ser_impl( cx: ext_ctxt, span: span, ident: ast::ident, - tps: &[ast::ty_param], + generics: &ast::Generics, body: @ast::expr ) -> @ast::item { // Make a path to the std::serialize::Encodable typaram. @@ -473,7 +499,7 @@ fn mk_ser_impl( cx.ident_of(~"Encoder"), ] ), - @~[] + @opt_vec::Empty ); // Make a path to the std::serialize::Encodable trait. @@ -493,7 +519,7 @@ fn mk_ser_impl( ident, ty_param, path, - tps, + generics, |_ty| mk_ser_method(cx, span, cx.expr_blk(body)) ) } @@ -502,7 +528,7 @@ fn mk_deser_impl( cx: ext_ctxt, span: span, ident: ast::ident, - tps: ~[ast::ty_param], + generics: &ast::Generics, body: @ast::expr ) -> @ast::item { // Make a path to the std::serialize::Decodable typaram. @@ -517,7 +543,7 @@ fn mk_deser_impl( cx.ident_of(~"Decoder"), ] ), - @~[] + @opt_vec::Empty ); // Make a path to the std::serialize::Decodable trait. @@ -537,7 +563,7 @@ fn mk_deser_impl( ident, ty_param, path, - tps, + generics, |ty| mk_deser_method(cx, span, ty, cx.expr_blk(body)) ) } @@ -592,7 +618,7 @@ fn mk_ser_method( @ast::method { ident: cx.ident_of(~"encode"), attrs: ~[], - tps: ~[], + generics: ast_util::empty_generics(), self_ty: codemap::spanned { node: ast::sty_region(ast::m_imm), span: span }, purity: ast::impure_fn, @@ -650,7 +676,7 @@ fn mk_deser_method( @ast::method { ident: cx.ident_of(~"decode"), attrs: ~[], - tps: ~[], + generics: ast_util::empty_generics(), self_ty: codemap::spanned { node: ast::sty_static, span: span }, purity: ast::impure_fn, decl: deser_decl, @@ -667,7 +693,7 @@ fn mk_struct_ser_impl( span: span, ident: ast::ident, fields: &[@ast::struct_field], - tps: &[ast::ty_param] + generics: &ast::Generics ) -> @ast::item { let fields = do mk_struct_fields(fields).mapi |idx, field| { // ast for `|| self.$(name).encode(__s)` @@ -720,7 +746,7 @@ fn mk_struct_ser_impl( ] ); - mk_ser_impl(cx, span, ident, tps, ser_body) + mk_ser_impl(cx, span, ident, generics, ser_body) } fn mk_struct_deser_impl( @@ -728,7 +754,7 @@ fn mk_struct_deser_impl( span: span, ident: ast::ident, fields: ~[@ast::struct_field], - tps: ~[ast::ty_param] + generics: &ast::Generics ) -> @ast::item { let fields = do mk_struct_fields(fields).mapi |idx, field| { // ast for `|| std::serialize::decode(__d)` @@ -796,7 +822,7 @@ fn mk_struct_deser_impl( ] ); - mk_deser_impl(cx, span, ident, tps, body) + mk_deser_impl(cx, span, ident, generics, body) } // Records and structs don't have the same fields types, but they share enough @@ -832,7 +858,7 @@ fn mk_enum_ser_impl( span: span, ident: ast::ident, enum_def: ast::enum_def, - tps: ~[ast::ty_param] + generics: &ast::Generics ) -> @ast::item { let body = mk_enum_ser_body( cx, @@ -841,7 +867,7 @@ fn mk_enum_ser_impl( enum_def.variants ); - mk_ser_impl(cx, span, ident, tps, body) + mk_ser_impl(cx, span, ident, generics, body) } fn mk_enum_deser_impl( @@ -849,7 +875,7 @@ fn mk_enum_deser_impl( span: span, ident: ast::ident, enum_def: ast::enum_def, - tps: ~[ast::ty_param] + generics: &ast::Generics ) -> @ast::item { let body = mk_enum_deser_body( cx, @@ -858,7 +884,7 @@ fn mk_enum_deser_impl( enum_def.variants ); - mk_deser_impl(cx, span, ident, tps, body) + mk_deser_impl(cx, span, ident, generics, body) } fn ser_variant( diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 55e5d5fbe17cc..fa21243df0367 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -16,6 +16,9 @@ use codemap::span; use ext::base::ext_ctxt; use ext::build; +use opt_vec; +use opt_vec::OptVec; + use core::dvec; use core::option; @@ -354,8 +357,14 @@ pub fn mk_fn_decl(+inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl { } pub fn mk_ty_param(cx: ext_ctxt, ident: ast::ident, - bounds: @~[ast::ty_param_bound]) - -> ast::ty_param { - ast::ty_param { ident: ident, id: cx.next_id(), bounds: bounds } + bounds: @OptVec) + -> ast::TyParam { + ast::TyParam { ident: ident, id: cx.next_id(), bounds: bounds } +} +pub fn mk_lifetime(cx: ext_ctxt, + span: span, + ident: ast::ident) -> ast::Lifetime +{ + ast::Lifetime { id: cx.next_id(), span: span, ident: ident } } diff --git a/src/libsyntax/ext/deriving.rs b/src/libsyntax/ext/deriving.rs index 094eea81fd2fd..0164f807f4b5f 100644 --- a/src/libsyntax/ext/deriving.rs +++ b/src/libsyntax/ext/deriving.rs @@ -16,15 +16,19 @@ use core::prelude::*; use ast; use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def}; use ast::{enum_variant_kind, expr, expr_match, ident, item, item_}; -use ast::{item_enum, item_impl, item_struct, m_imm, meta_item, method}; +use ast::{item_enum, item_impl, item_struct, Generics}; +use ast::{m_imm, meta_item, method}; use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn}; use ast::{re_anon, stmt, struct_def, struct_variant_kind}; -use ast::{sty_by_ref, sty_region, tuple_variant_kind, ty_nil, ty_param}; -use ast::{ty_param_bound, ty_path, ty_rptr, unnamed_field, variant}; +use ast::{sty_by_ref, sty_region, tuple_variant_kind, ty_nil, TyParam}; +use ast::{TyParamBound, ty_path, ty_rptr, unnamed_field, variant}; use ext::base::ext_ctxt; use ext::build; use codemap::{span, spanned}; use parse::token::special_idents::clownshoes_extensions; +use ast_util; +use opt_vec; +use opt_vec::OptVec; use core::dvec; use core::uint; @@ -47,13 +51,13 @@ type ExpandDerivingStructDefFn = &fn(ext_ctxt, span, x: &struct_def, ident, - +y: ~[ty_param]) + y: &Generics) -> @item; type ExpandDerivingEnumDefFn = &fn(ext_ctxt, span, x: &enum_def, ident, - +y: ~[ty_param]) + y: &Generics) -> @item; pub fn expand_deriving_eq(cx: ext_ctxt, @@ -90,19 +94,19 @@ fn expand_deriving(cx: ext_ctxt, for in_items.each |item| { result.push(copy *item); match item.node { - item_struct(struct_def, copy ty_params) => { + item_struct(struct_def, ref generics) => { result.push(expand_deriving_struct_def(cx, span, struct_def, item.ident, - ty_params)); + generics)); } - item_enum(ref enum_definition, copy ty_params) => { + item_enum(ref enum_definition, ref generics) => { result.push(expand_deriving_enum_def(cx, span, enum_definition, item.ident, - ty_params)); + generics)); } _ => () } @@ -127,14 +131,14 @@ fn create_eq_method(cx: ext_ctxt, span: span, method_ident: ident, type_ident: ident, - ty_params: &[ty_param], + generics: &Generics, body: @expr) -> @method { // Create the type of the `other` parameter. let arg_path_type = create_self_type_with_params(cx, span, type_ident, - ty_params); + generics); let arg_region = @ast::region { id: cx.next_id(), node: re_anon }; let arg_type = ty_rptr( arg_region, @@ -171,7 +175,7 @@ fn create_eq_method(cx: ext_ctxt, @ast::method { ident: method_ident, attrs: ~[], - tps: ~[], + generics: ast_util::empty_generics(), self_ty: self_ty, purity: pure_fn, decl: fn_decl, @@ -186,11 +190,11 @@ fn create_eq_method(cx: ext_ctxt, fn create_self_type_with_params(cx: ext_ctxt, span: span, type_ident: ident, - ty_params: &[ty_param]) + generics: &Generics) -> @Ty { // Create the type parameters on the `self` path. let self_ty_params = dvec::DVec(); - for ty_params.each |ty_param| { + for generics.ty_params.each |ty_param| { let self_ty_param = build::mk_simple_ty_path(cx, span, ty_param.ident); @@ -209,21 +213,34 @@ fn create_self_type_with_params(cx: ext_ctxt, fn create_derived_impl(cx: ext_ctxt, span: span, type_ident: ident, - +ty_params: ~[ty_param], + generics: &Generics, methods: &[@method], trait_path: &[ident]) -> @item { + /*! + * + * Given that we are deriving a trait `Tr` for a type `T<'a, ..., + * 'z, A, ..., Z>`, creates an impl like: + * + * impl<'a, ..., 'z, A:Tr, ..., Z: Tr> Tr for T { ... } + * + * FIXME(#5090): Remove code duplication between this and the + * code in auto_encode.rs + */ + + // Copy the lifetimes + let impl_lifetimes = generics.lifetimes.map(|l| { + build::mk_lifetime(cx, l.span, l.ident) + }); + // Create the type parameters. - let impl_ty_params = dvec::DVec(); - for ty_params.each |ty_param| { + let impl_ty_params = generics.ty_params.map(|ty_param| { let bound = build::mk_ty_path_global(cx, span, trait_path.map(|x| *x)); - let bounds = @~[ TraitTyParamBound(bound) ]; - let impl_ty_param = build::mk_ty_param(cx, ty_param.ident, bounds); - impl_ty_params.push(impl_ty_param); - } - let impl_ty_params = dvec::unwrap(impl_ty_params); + let bounds = @opt_vec::with(TraitTyParamBound(bound)); + build::mk_ty_param(cx, ty_param.ident, bounds) + }); // Create the reference to the trait. let trait_path = ast::path { @@ -244,10 +261,11 @@ fn create_derived_impl(cx: ext_ctxt, let self_type = create_self_type_with_params(cx, span, type_ident, - ty_params); + generics); // Create the impl item. - let impl_item = item_impl(impl_ty_params, + let impl_item = item_impl(Generics {lifetimes: impl_lifetimes, + ty_params: impl_ty_params}, Some(trait_ref), self_type, methods.map(|x| *x)); @@ -257,7 +275,7 @@ fn create_derived_impl(cx: ext_ctxt, fn create_derived_eq_impl(cx: ext_ctxt, span: span, type_ident: ident, - +ty_params: ~[ty_param], + generics: &Generics, eq_method: @method, ne_method: @method) -> @item { @@ -267,13 +285,13 @@ fn create_derived_eq_impl(cx: ext_ctxt, cx.ident_of(~"cmp"), cx.ident_of(~"Eq") ]; - create_derived_impl(cx, span, type_ident, ty_params, methods, trait_path) + create_derived_impl(cx, span, type_ident, generics, methods, trait_path) } fn create_derived_iter_bytes_impl(cx: ext_ctxt, span: span, type_ident: ident, - +ty_params: ~[ty_param], + generics: &Generics, method: @method) -> @item { let methods = [ method ]; @@ -282,7 +300,7 @@ fn create_derived_iter_bytes_impl(cx: ext_ctxt, cx.ident_of(~"to_bytes"), cx.ident_of(~"IterBytes") ]; - create_derived_impl(cx, span, type_ident, ty_params, methods, trait_path) + create_derived_impl(cx, span, type_ident, generics, methods, trait_path) } // Creates a method from the given set of statements conforming to the @@ -322,7 +340,7 @@ fn create_iter_bytes_method(cx: ext_ctxt, @ast::method { ident: method_ident, attrs: ~[], - tps: ~[], + generics: ast_util::empty_generics(), self_ty: self_ty, purity: pure_fn, decl: fn_decl, @@ -484,7 +502,7 @@ fn expand_deriving_eq_struct_def(cx: ext_ctxt, span: span, struct_def: &struct_def, type_ident: ident, - +ty_params: ~[ty_param]) + generics: &Generics) -> @item { // Create the methods. let eq_ident = cx.ident_of(~"eq"); @@ -510,21 +528,21 @@ fn expand_deriving_eq_struct_def(cx: ext_ctxt, struct_def, eq_ident, type_ident, - ty_params, + generics, Conjunction); let ne_method = derive_struct_fn(cx, span, struct_def, ne_ident, type_ident, - ty_params, + generics, Disjunction); // Create the implementation. return create_derived_eq_impl(cx, span, type_ident, - ty_params, + generics, eq_method, ne_method); } @@ -533,7 +551,7 @@ fn expand_deriving_eq_enum_def(cx: ext_ctxt, span: span, enum_definition: &enum_def, type_ident: ident, - +ty_params: ~[ty_param]) + generics: &Generics) -> @item { // Create the methods. let eq_ident = cx.ident_of(~"eq"); @@ -543,21 +561,21 @@ fn expand_deriving_eq_enum_def(cx: ext_ctxt, enum_definition, eq_ident, type_ident, - ty_params, + generics, Conjunction); let ne_method = expand_deriving_eq_enum_method(cx, span, enum_definition, ne_ident, type_ident, - ty_params, + generics, Disjunction); // Create the implementation. return create_derived_eq_impl(cx, span, type_ident, - ty_params, + generics, eq_method, ne_method); } @@ -566,7 +584,7 @@ fn expand_deriving_iter_bytes_struct_def(cx: ext_ctxt, span: span, struct_def: &struct_def, type_ident: ident, - +ty_params: ~[ty_param]) + generics: &Generics) -> @item { // Create the method. let method = expand_deriving_iter_bytes_struct_method(cx, @@ -577,7 +595,7 @@ fn expand_deriving_iter_bytes_struct_def(cx: ext_ctxt, return create_derived_iter_bytes_impl(cx, span, type_ident, - ty_params, + generics, method); } @@ -585,7 +603,7 @@ fn expand_deriving_iter_bytes_enum_def(cx: ext_ctxt, span: span, enum_definition: &enum_def, type_ident: ident, - +ty_params: ~[ty_param]) + generics: &Generics) -> @item { // Create the method. let method = expand_deriving_iter_bytes_enum_method(cx, @@ -596,7 +614,7 @@ fn expand_deriving_iter_bytes_enum_def(cx: ext_ctxt, return create_derived_iter_bytes_impl(cx, span, type_ident, - ty_params, + generics, method); } @@ -605,7 +623,7 @@ fn expand_deriving_eq_struct_method(cx: ext_ctxt, struct_def: &struct_def, method_ident: ident, type_ident: ident, - ty_params: &[ty_param], + generics: &Generics, junction: Junction) -> @method { let self_ident = cx.ident_of(~"self"); @@ -652,7 +670,7 @@ fn expand_deriving_eq_struct_method(cx: ext_ctxt, span, method_ident, type_ident, - ty_params, + generics, body); } @@ -696,7 +714,7 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt, enum_definition: &enum_def, method_ident: ident, type_ident: ident, - ty_params: &[ty_param], + generics: &Generics, junction: Junction) -> @method { let self_ident = cx.ident_of(~"self"); @@ -823,7 +841,7 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt, span, method_ident, type_ident, - ty_params, + generics, self_match_expr); } @@ -832,7 +850,7 @@ fn expand_deriving_eq_struct_tuple_method(cx: ext_ctxt, struct_def: &struct_def, method_ident: ident, type_ident: ident, - ty_params: &[ty_param], + generics: &Generics, junction: Junction) -> @method { let self_str = ~"self"; @@ -883,7 +901,7 @@ fn expand_deriving_eq_struct_tuple_method(cx: ext_ctxt, let self_match_expr = build::mk_expr(cx, span, self_match_expr); create_eq_method(cx, span, method_ident, - type_ident, ty_params, self_match_expr) + type_ident, generics, self_match_expr) } fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt, diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index 49f7fe5853e7b..6324379fc9a2c 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -24,6 +24,8 @@ use codemap::{span, respan, dummy_sp}; use codemap; use ext::base::{ext_ctxt, mk_ctxt}; use ext::quote::rt::*; +use opt_vec; +use opt_vec::OptVec; use core::vec; @@ -67,8 +69,8 @@ pub impl append_types for @ast::path { } pub trait ext_ctxt_ast_builder { - fn ty_param(&self, id: ast::ident, +bounds: ~[ast::ty_param_bound]) - -> ast::ty_param; + fn ty_param(&self, id: ast::ident, bounds: @OptVec) + -> ast::TyParam; fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg; fn expr_block(&self, e: @ast::expr) -> ast::blk; fn fn_decl(&self, +inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl; @@ -76,7 +78,7 @@ pub trait ext_ctxt_ast_builder { fn item_fn_poly(&self, name: ident, +inputs: ~[ast::arg], output: @ast::Ty, - +ty_params: ~[ast::ty_param], + +generics: Generics, +body: ast::blk) -> @ast::item; fn item_fn(&self, name: ident, +inputs: ~[ast::arg], @@ -85,12 +87,12 @@ pub trait ext_ctxt_ast_builder { fn item_enum_poly(&self, name: ident, span: span, +enum_definition: ast::enum_def, - +ty_params: ~[ast::ty_param]) -> @ast::item; + +generics: Generics) -> @ast::item; fn item_enum(&self, name: ident, span: span, +enum_definition: ast::enum_def) -> @ast::item; fn item_struct_poly(&self, name: ident, span: span, struct_def: ast::struct_def, - ty_params: ~[ast::ty_param]) -> @ast::item; + +generics: Generics) -> @ast::item; fn item_struct(&self, name: ident, span: span, struct_def: ast::struct_def) -> @ast::item; fn struct_expr(&self, path: @ast::path, @@ -103,10 +105,10 @@ pub trait ext_ctxt_ast_builder { fn item_ty_poly(&self, name: ident, span: span, ty: @ast::Ty, - +params: ~[ast::ty_param]) -> @ast::item; + +generics: Generics) -> @ast::item; fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item; - fn ty_vars(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty]; - fn ty_vars_global(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty]; + fn ty_vars(&self, ty_params: &OptVec) -> ~[@ast::Ty]; + fn ty_vars_global(&self, ty_params: &OptVec) -> ~[@ast::Ty]; fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field; fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field; fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk; @@ -116,7 +118,7 @@ pub trait ext_ctxt_ast_builder { fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty; fn ty_infer(&self) -> @ast::Ty; fn ty_nil_ast_builder(&self) -> @ast::Ty; - fn strip_bounds(&self, bounds: &[ast::ty_param]) -> ~[ast::ty_param]; + fn strip_bounds(&self, bounds: &Generics) -> Generics; } pub impl ext_ctxt_ast_builder for ext_ctxt { @@ -172,10 +174,10 @@ pub impl ext_ctxt_ast_builder for ext_ctxt { } } - fn ty_param(&self, id: ast::ident, +bounds: ~[ast::ty_param_bound]) - -> ast::ty_param + fn ty_param(&self, id: ast::ident, bounds: @OptVec) + -> ast::TyParam { - ast::ty_param { ident: id, id: self.next_id(), bounds: @bounds } + ast::TyParam { ident: id, id: self.next_id(), bounds: bounds } } fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg { @@ -247,13 +249,13 @@ pub impl ext_ctxt_ast_builder for ext_ctxt { fn item_fn_poly(&self, name: ident, +inputs: ~[ast::arg], output: @ast::Ty, - +ty_params: ~[ast::ty_param], + +generics: Generics, +body: ast::blk) -> @ast::item { self.item(name, dummy_sp(), ast::item_fn(self.fn_decl(inputs, output), ast::impure_fn, - ty_params, + generics, body)) } @@ -261,29 +263,32 @@ pub impl ext_ctxt_ast_builder for ext_ctxt { +inputs: ~[ast::arg], output: @ast::Ty, +body: ast::blk) -> @ast::item { - self.item_fn_poly(name, inputs, output, ~[], body) + self.item_fn_poly(name, inputs, output, + ast_util::empty_generics(), body) } fn item_enum_poly(&self, name: ident, span: span, +enum_definition: ast::enum_def, - +ty_params: ~[ast::ty_param]) -> @ast::item { - self.item(name, span, ast::item_enum(enum_definition, ty_params)) + +generics: Generics) -> @ast::item { + self.item(name, span, ast::item_enum(enum_definition, generics)) } fn item_enum(&self, name: ident, span: span, +enum_definition: ast::enum_def) -> @ast::item { - self.item_enum_poly(name, span, enum_definition, ~[]) + self.item_enum_poly(name, span, enum_definition, + ast_util::empty_generics()) } fn item_struct(&self, name: ident, span: span, struct_def: ast::struct_def) -> @ast::item { - self.item_struct_poly(name, span, struct_def, ~[]) + self.item_struct_poly(name, span, struct_def, + ast_util::empty_generics()) } fn item_struct_poly(&self, name: ident, span: span, struct_def: ast::struct_def, - ty_params: ~[ast::ty_param]) -> @ast::item { - self.item(name, span, ast::item_struct(@struct_def, ty_params)) + +generics: Generics) -> @ast::item { + self.item(name, span, ast::item_struct(@struct_def, generics)) } fn struct_expr(&self, path: @ast::path, @@ -371,28 +376,31 @@ pub impl ext_ctxt_ast_builder for ext_ctxt { } } - fn strip_bounds(&self, bounds: &[ast::ty_param]) -> ~[ast::ty_param] { - do bounds.map |ty_param| { - ast::ty_param { bounds: @~[], ..copy *ty_param } - } + fn strip_bounds(&self, generics: &Generics) -> Generics { + let no_bounds = @opt_vec::Empty; + let new_params = do generics.ty_params.map |ty_param| { + ast::TyParam { bounds: no_bounds, ..copy *ty_param } + }; + Generics { ty_params: new_params, ..*generics } } fn item_ty_poly(&self, name: ident, span: span, ty: @ast::Ty, - +params: ~[ast::ty_param]) -> @ast::item { - self.item(name, span, ast::item_ty(ty, params)) + +generics: Generics) -> @ast::item { + self.item(name, span, ast::item_ty(ty, generics)) } fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item { - self.item_ty_poly(name, span, ty, ~[]) + self.item_ty_poly(name, span, ty, ast_util::empty_generics()) } - fn ty_vars(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] { + fn ty_vars(&self, ty_params: &OptVec) -> ~[@ast::Ty] { ty_params.map(|p| self.ty_path_ast_builder( - path(~[p.ident], dummy_sp()))) + path(~[p.ident], dummy_sp()))).to_vec() } - fn ty_vars_global(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] { + fn ty_vars_global(&self, + ty_params: &OptVec) -> ~[@ast::Ty] { ty_params.map(|p| self.ty_path_ast_builder( - path(~[p.ident], dummy_sp()))) + path(~[p.ident], dummy_sp()))).to_vec() } } diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs index cc42a0992cbed..1d49b8c1be825 100644 --- a/src/libsyntax/ext/pipes/check.rs +++ b/src/libsyntax/ext/pipes/check.rs @@ -67,13 +67,13 @@ pub impl proto::visitor<(), (), ()> for ext_ctxt { else { let next = proto.get_state(next_state.state); - if next.ty_params.len() != next_state.tys.len() { + if next.generics.ty_params.len() != next_state.tys.len() { self.span_err( next.span, // use a real span fmt!("message %s target (%s) \ needs %u type parameters, but got %u", name, next.name, - next.ty_params.len(), + next.generics.ty_params.len(), next_state.tys.len())); } } diff --git a/src/libsyntax/ext/pipes/parse_proto.rs b/src/libsyntax/ext/pipes/parse_proto.rs index 66feb7cc753cf..ef7056529294a 100644 --- a/src/libsyntax/ext/pipes/parse_proto.rs +++ b/src/libsyntax/ext/pipes/parse_proto.rs @@ -51,13 +51,13 @@ pub impl proto_parser for parser::Parser { _ => fail!() }; - let typarms = if *self.token == token::LT { - self.parse_ty_params() + let generics = if *self.token == token::LT { + self.parse_generics() } else { - ~[] + ast_util::empty_generics() }; - let state = proto.add_state_poly(name, id, dir, typarms); + let state = proto.add_state_poly(name, id, dir, generics); // parse the messages self.parse_unspanned_seq( diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 444b09d9ae458..6bb25e31f6993 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -19,6 +19,8 @@ use ext::pipes::proto::*; use ext::quote::rt::*; use parse::*; use util::interner; +use opt_vec; +use opt_vec::OptVec; use core::dvec::DVec; use core::prelude::*; @@ -50,20 +52,19 @@ pub 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(); - let params = self.get_params(); match *self { message(ref _id, span, ref tys, this, Some(ref next_state)) => { debug!("pipec: next state exists"); let next = this.proto.get_state(next_state.state); - assert next_state.tys.len() == next.ty_params.len(); + assert next_state.tys.len() == next.generics.ty_params.len(); let arg_names = tys.mapi(|i, _ty| cx.ident_of(~"x_"+i.to_str())); let args_ast = (arg_names, *tys).map(|n, t| cx.arg(*n, *t)); let pipe_ty = cx.ty_path_ast_builder( path(~[this.data_name()], span) - .add_tys(cx.ty_vars_global(this.ty_params))); + .add_tys(cx.ty_vars_global(&this.generics.ty_params))); let args_ast = vec::append( ~[cx.arg(cx.ident_of(~"pipe"), pipe_ty)], @@ -129,7 +130,7 @@ pub impl gen_send for message { cx.item_fn_poly(name, args_ast, rty, - params, + self.get_generics(), cx.expr_block(body)) } @@ -143,10 +144,10 @@ pub impl gen_send for message { let args_ast = vec::append( ~[cx.arg(cx.ident_of(~"pipe"), - cx.ty_path_ast_builder( - path(~[this.data_name()], span) - .add_tys(cx.ty_vars_global( - this.ty_params))))], + cx.ty_path_ast_builder( + path(~[this.data_name()], span) + .add_tys(cx.ty_vars_global( + &this.generics.ty_params))))], args_ast); let message_args = if arg_names.len() == 0 { @@ -184,7 +185,7 @@ pub impl gen_send for message { } else { cx.ty_nil_ast_builder() }, - params, + self.get_generics(), cx.expr_block(body)) } } @@ -192,7 +193,7 @@ pub impl gen_send for message { fn to_ty(&mut self, cx: ext_ctxt) -> @ast::Ty { cx.ty_path_ast_builder(path(~[cx.ident_of(self.name())], self.span()) - .add_tys(cx.ty_vars_global(self.get_params()))) + .add_tys(cx.ty_vars_global(&self.get_generics().ty_params))) } } @@ -243,7 +244,7 @@ pub impl to_type_decls for state { ast::enum_def(enum_def_ { variants: items_msg, common: None }), - cx.strip_bounds(self.ty_params) + cx.strip_bounds(&self.generics) ) ] } @@ -281,8 +282,9 @@ pub impl to_type_decls for state { path(~[cx.ident_of(~"super"), self.data_name()], dummy_sp()) - .add_tys(cx.ty_vars_global(self.ty_params))))), - cx.strip_bounds(self.ty_params))); + .add_tys(cx.ty_vars_global( + &self.generics.ty_params))))), + cx.strip_bounds(&self.generics))); } else { items.push( @@ -299,9 +301,10 @@ pub impl to_type_decls for state { path(~[cx.ident_of(~"super"), self.data_name()], dummy_sp()) - .add_tys(cx.ty_vars_global(self.ty_params))), + .add_tys(cx.ty_vars_global( + &self.generics.ty_params))), self.proto.buffer_ty_path(cx)])), - cx.strip_bounds(self.ty_params))); + cx.strip_bounds(&self.generics))); }; items } @@ -340,7 +343,7 @@ pub impl gen_init for protocol { cx.parse_item(fmt!("pub fn init%s() -> (client::%s, server::%s)\ { use core::pipes::HasBuffer; %s }", - start_state.ty_params.to_source(cx), + start_state.generics.to_source(cx), start_state.to_ty(cx).to_source(cx), start_state.to_ty(cx).to_source(cx), body.to_source(cx))) @@ -385,9 +388,9 @@ pub impl gen_init for protocol { } fn buffer_ty_path(&self, cx: ext_ctxt) -> @ast::Ty { - let mut params: ~[ast::ty_param] = ~[]; + let mut params: OptVec = opt_vec::Empty; for (copy self.states).each |s| { - for s.ty_params.each |tp| { + for s.generics.ty_params.each |tp| { match params.find(|tpp| tp.ident == tpp.ident) { None => params.push(*tp), _ => () @@ -398,19 +401,20 @@ pub impl gen_init for protocol { cx.ty_path_ast_builder(path(~[cx.ident_of(~"super"), cx.ident_of(~"__Buffer")], copy self.span) - .add_tys(cx.ty_vars_global(params))) + .add_tys(cx.ty_vars_global(¶ms))) } fn gen_buffer_type(&self, cx: ext_ctxt) -> @ast::item { let ext_cx = cx; - let mut params: ~[ast::ty_param] = ~[]; + let mut params: OptVec = opt_vec::Empty; let fields = do (copy self.states).map_to_vec |s| { - for s.ty_params.each |tp| { + for s.generics.ty_params.each |tp| { match params.find(|tpp| tp.ident == tpp.ident) { None => params.push(*tp), _ => () } } + let ty = s.to_ty(cx); let fty = quote_ty!( ::core::pipes::Packet<$ty> ); @@ -427,6 +431,11 @@ pub impl gen_init for protocol { } }; + let generics = Generics { + lifetimes: opt_vec::Empty, + ty_params: params + }; + cx.item_struct_poly( cx.ident_of(~"__Buffer"), dummy_sp(), @@ -435,7 +444,7 @@ pub impl gen_init for protocol { dtor: None, ctor_id: None }, - cx.strip_bounds(params)) + cx.strip_bounds(&generics)) } fn compile(&self, cx: ext_ctxt) -> @ast::item { diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 7c6dc1f937dca..6052e20e6e917 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -61,9 +61,9 @@ pub impl message { } /// Return the type parameters actually used by this message - fn get_params(&mut self) -> ~[ast::ty_param] { + fn get_generics(&self) -> ast::Generics { match *self { - message(_, _, _, this, _) => this.ty_params + message(_, _, _, this, _) => this.generics } } } @@ -76,7 +76,7 @@ pub struct state_ { ident: ast::ident, span: span, dir: direction, - ty_params: ~[ast::ty_param], + generics: ast::Generics, messages: @mut ~[message], proto: protocol } @@ -100,7 +100,7 @@ pub impl state_ { fn to_ty(&self, cx: ext_ctxt) -> @ast::Ty { cx.ty_path_ast_builder (path(~[cx.ident_of(self.name)],self.span).add_tys( - cx.ty_vars(self.ty_params))) + cx.ty_vars(&self.generics.ty_params))) } /// Iterate over the states that can be reached in one message @@ -161,7 +161,7 @@ pub impl protocol_ { fn has_ty_params(&mut self) -> bool { for self.states.each |s| { - if s.ty_params.len() > 0 { + if s.generics.ty_params.len() > 0 { return true; } } @@ -175,7 +175,7 @@ pub impl protocol_ { pub impl protocol { fn add_state_poly(&self, name: ~str, ident: ast::ident, dir: direction, - +ty_params: ~[ast::ty_param]) -> state { + +generics: ast::Generics) -> state { let messages = @mut ~[]; let state = @state_ { @@ -184,7 +184,7 @@ pub impl protocol { ident: ident, span: self.span, dir: dir, - ty_params: ty_params, + generics: generics, messages: messages, proto: *self }; diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index d529ee0c01b01..b313d42e81260 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -50,12 +50,12 @@ pub mod rt { use print::pprust::{item_to_str, ty_to_str}; trait ToTokens { - pub fn to_tokens(_cx: ext_ctxt) -> ~[token_tree]; + pub fn to_tokens(&self, _cx: ext_ctxt) -> ~[token_tree]; } impl ToTokens for ~[token_tree] { - pub fn to_tokens(_cx: ext_ctxt) -> ~[token_tree] { - copy self + pub fn to_tokens(&self, _cx: ext_ctxt) -> ~[token_tree] { + copy *self } } @@ -75,91 +75,91 @@ pub mod rt { trait ToSource { // Takes a thing and generates a string containing rust code for it. - pub fn to_source(cx: ext_ctxt) -> ~str; + pub fn to_source(&self, cx: ext_ctxt) -> ~str; } impl ToSource for ast::ident { - fn to_source(cx: ext_ctxt) -> ~str { - copy *cx.parse_sess().interner.get(self) + fn to_source(&self, cx: ext_ctxt) -> ~str { + copy *cx.parse_sess().interner.get(*self) } } impl ToSource for @ast::item { - fn to_source(cx: ext_ctxt) -> ~str { - item_to_str(self, cx.parse_sess().interner) + fn to_source(&self, cx: ext_ctxt) -> ~str { + item_to_str(*self, cx.parse_sess().interner) } } impl ToSource for ~[@ast::item] { - fn to_source(cx: ext_ctxt) -> ~str { + fn to_source(&self, cx: ext_ctxt) -> ~str { str::connect(self.map(|i| i.to_source(cx)), ~"\n\n") } } impl ToSource for @ast::Ty { - fn to_source(cx: ext_ctxt) -> ~str { - ty_to_str(self, cx.parse_sess().interner) + fn to_source(&self, cx: ext_ctxt) -> ~str { + ty_to_str(*self, cx.parse_sess().interner) } } impl ToSource for ~[@ast::Ty] { - fn to_source(cx: ext_ctxt) -> ~str { + fn to_source(&self, cx: ext_ctxt) -> ~str { str::connect(self.map(|i| i.to_source(cx)), ~", ") } } - impl ToSource for ~[ast::ty_param] { - fn to_source(cx: ext_ctxt) -> ~str { - pprust::typarams_to_str(self, cx.parse_sess().interner) + impl ToSource for Generics { + fn to_source(&self, cx: ext_ctxt) -> ~str { + pprust::generics_to_str(self, cx.parse_sess().interner) } } impl ToSource for @ast::expr { - fn to_source(cx: ext_ctxt) -> ~str { - pprust::expr_to_str(self, cx.parse_sess().interner) + fn to_source(&self, cx: ext_ctxt) -> ~str { + pprust::expr_to_str(*self, cx.parse_sess().interner) } } // Alas ... we write these out instead. All redundant. impl ToTokens for ast::ident { - fn to_tokens(cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for @ast::item { - fn to_tokens(cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for ~[@ast::item] { - fn to_tokens(cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for @ast::Ty { - fn to_tokens(cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for ~[@ast::Ty] { - fn to_tokens(cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } - impl ToTokens for ~[ast::ty_param] { - fn to_tokens(cx: ext_ctxt) -> ~[token_tree] { + impl ToTokens for Generics { + fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } impl ToTokens for @ast::expr { - fn to_tokens(cx: ext_ctxt) -> ~[token_tree] { + fn to_tokens(&self, cx: ext_ctxt) -> ~[token_tree] { cx.parse_tts(self.to_source(cx)) } } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index dacb6f60e3764..acc1054aa713e 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -130,21 +130,38 @@ pub fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl { } } -fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound { +fn fold_ty_param_bound(tpb: TyParamBound, fld: ast_fold) -> TyParamBound { match tpb { TraitTyParamBound(ty) => TraitTyParamBound(fld.fold_ty(ty)), RegionTyParamBound => RegionTyParamBound } } -pub fn fold_ty_param(tp: ty_param, fld: ast_fold) -> ty_param { - ast::ty_param { ident: /* FIXME (#2543) */ copy tp.ident, - id: fld.new_id(tp.id), - bounds: @tp.bounds.map(|x| fold_ty_param_bound(*x, fld) )} +pub fn fold_ty_param(tp: TyParam, fld: ast_fold) -> TyParam { + TyParam {ident: tp.ident, + id: fld.new_id(tp.id), + bounds: @tp.bounds.map(|x| fold_ty_param_bound(*x, fld))} } -pub fn fold_ty_params(tps: ~[ty_param], fld: ast_fold) -> ~[ty_param] { - tps.map(|x| fold_ty_param(*x, fld)) +pub fn fold_ty_params(tps: &OptVec, + fld: ast_fold) -> OptVec { + tps.map(|tp| fold_ty_param(*tp, fld)) +} + +pub fn fold_lifetime(l: &Lifetime, fld: ast_fold) -> Lifetime { + Lifetime {id: fld.new_id(l.id), + span: fld.new_span(l.span), + ident: l.ident} +} + +pub fn fold_lifetimes(lts: &OptVec, + fld: ast_fold) -> OptVec { + lts.map(|l| fold_lifetime(l, fld)) +} + +pub fn fold_generics(generics: &Generics, fld: ast_fold) -> Generics { + Generics {ty_params: fold_ty_params(&generics.ty_params, fld), + lifetimes: fold_lifetimes(&generics.lifetimes, fld)} } pub fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ { @@ -173,7 +190,7 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold) attrs: vec::map(ni.attrs, |x| fold_attribute(*x)), node: match ni.node { - foreign_item_fn(fdec, purity, typms) => { + foreign_item_fn(fdec, purity, ref generics) => { foreign_item_fn( ast::fn_decl { inputs: fdec.inputs.map(|a| fold_arg(*a)), @@ -181,7 +198,7 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold) cf: fdec.cf, }, purity, - fold_ty_params(typms, fld)) + fold_generics(generics, fld)) } foreign_item_const(t) => { foreign_item_const(fld.fold_ty(t)) @@ -218,20 +235,20 @@ pub fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { item_fn(ref decl, purity, ref typms, ref body) => { item_fn(fold_fn_decl(/* FIXME (#2543) */ copy *decl, fld), purity, - fold_ty_params(/* FIXME (#2543) */ copy *typms, fld), + fold_generics(typms, fld), fld.fold_block(*body)) } item_mod(m) => item_mod(fld.fold_mod(m)), item_foreign_mod(nm) => item_foreign_mod(fld.fold_foreign_mod(nm)), - item_ty(t, typms) => item_ty(fld.fold_ty(t), - fold_ty_params(typms, fld)), + item_ty(t, ref typms) => item_ty(fld.fold_ty(t), + fold_generics(typms, fld)), item_enum(ref enum_definition, ref typms) => { item_enum(ast::enum_def(ast::enum_def_ { variants: enum_definition.variants.map( |x| fld.fold_variant(*x)), common: enum_definition.common.map( |x| fold_struct_def(*x, fld)), - }), fold_ty_params(/* FIXME (#2543) */ copy *typms, fld)) + }), fold_generics(typms, fld)) } item_struct(ref struct_def, ref typms) => { let struct_def = fold_struct_def( @@ -240,7 +257,7 @@ pub fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { item_struct(struct_def, /* FIXME (#2543) */ copy *typms) } item_impl(ref tps, ifce, ty, ref methods) => { - item_impl(fold_ty_params(/* FIXME (#2543) */ copy *tps, fld), + item_impl(fold_generics(tps, fld), ifce.map(|p| fold_trait_ref(*p, fld)), fld.fold_ty(ty), methods.map(|x| fld.fold_method(*x))) @@ -252,7 +269,7 @@ pub fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { provided(method) => provided(fld.fold_method(method)) } }; - item_trait(fold_ty_params(/* FIXME (#2543) */ copy *tps, fld), + item_trait(fold_generics(tps, fld), traits.map(|p| fold_trait_ref(*p, fld)), methods) } @@ -298,7 +315,7 @@ fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method { @ast::method { ident: fld.fold_ident(m.ident), attrs: /* FIXME (#2543) */ copy m.attrs, - tps: fold_ty_params(m.tps, fld), + generics: fold_generics(&m.generics, fld), self_ty: m.self_ty, purity: m.purity, decl: fold_fn_decl(m.decl, fld), diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs new file mode 100644 index 0000000000000..22d69d89e8163 --- /dev/null +++ b/src/libsyntax/opt_vec.rs @@ -0,0 +1,187 @@ +// 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. + +/*! + * + * Defines a type OptVec that can be used in place of ~[T]. + * OptVec avoids the need for allocation for empty vectors. + * OptVec implements the iterable interface as well as + * other useful things like `push()` and `len()`. + */ + +use core::prelude::*; +use core::iter; +use core::iter::BaseIter; + +#[auto_encode] +#[auto_decode] +pub enum OptVec { + Empty, + Vec(~[T]) +} + +pub fn with(+t: T) -> OptVec { + Vec(~[t]) +} + +impl OptVec { + fn push(&mut self, +t: T) { + match *self { + Vec(ref mut v) => { + v.push(t); + return; + } + Empty => {} + } + + // FIXME(#5074): flow insensitive means we can't move + // assignment inside `match` + *self = Vec(~[t]); + } + + fn map(&self, op: &fn(&T) -> U) -> OptVec { + match *self { + Empty => Empty, + Vec(ref v) => Vec(v.map(op)) + } + } + + pure fn get(&self, i: uint) -> &self/T { + match *self { + Empty => fail!(fmt!("Invalid index %u", i)), + Vec(ref v) => &v[i] + } + } + + pure fn is_empty(&self) -> bool { + self.len() == 0 + } + + pure fn len(&self) -> uint { + match *self { + Empty => 0, + Vec(ref v) => v.len() + } + } + + pure fn to_vec(self) -> ~[T] { + match self { + Empty => ~[], + Vec(v) => v + } + } +} + +impl OptVec { + fn prepend(&self, +t: T) -> OptVec { + let mut v0 = ~[t]; + match *self { + Empty => {} + Vec(v1) => { v0.push_all(v1); } + } + return Vec(v0); + } + + fn push_all>(&mut self, from: &I) { + for from.each |e| { + self.push(copy *e); + } + } +} + +impl Eq for OptVec { + pure fn eq(&self, other: &OptVec) -> bool { + // Note: cannot use #[deriving_eq] here because + // (Empty, Vec(~[])) ought to be equal. + match (self, other) { + (&Empty, &Empty) => true, + (&Empty, &Vec(ref v)) => v.is_empty(), + (&Vec(ref v), &Empty) => v.is_empty(), + (&Vec(ref v1), &Vec(ref v2)) => *v1 == *v2 + } + } + + pure fn ne(&self, other: &OptVec) -> bool { + !self.eq(other) + } +} + +impl BaseIter for OptVec { + pure fn each(&self, blk: fn(v: &A) -> bool) { + match *self { + Empty => {} + Vec(ref v) => v.each(blk) + } + } + + pure fn size_hint(&self) -> Option { + Some(self.len()) + } +} + +impl iter::ExtendedIter for OptVec { + #[inline(always)] + pure fn eachi(&self, blk: fn(+v: uint, v: &A) -> bool) { + iter::eachi(self, blk) + } + #[inline(always)] + pure fn all(&self, blk: fn(&A) -> bool) -> bool { + iter::all(self, blk) + } + #[inline(always)] + pure fn any(&self, blk: fn(&A) -> bool) -> bool { + iter::any(self, blk) + } + #[inline(always)] + pure fn foldl(&self, +b0: B, blk: fn(&B, &A) -> B) -> B { + iter::foldl(self, b0, blk) + } + #[inline(always)] + pure fn position(&self, f: fn(&A) -> bool) -> Option { + iter::position(self, f) + } + #[inline(always)] + pure fn map_to_vec(&self, op: fn(&A) -> B) -> ~[B] { + iter::map_to_vec(self, op) + } + #[inline(always)] + pure fn flat_map_to_vec>(&self, op: fn(&A) -> IB) + -> ~[B] { + iter::flat_map_to_vec(self, op) + } + +} + +impl iter::EqIter for OptVec { + #[inline(always)] + pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) } + #[inline(always)] + pure fn count(&self, x: &A) -> uint { iter::count(self, x) } +} + +impl iter::CopyableIter for OptVec { + #[inline(always)] + pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] { + iter::filter_to_vec(self, pred) + } + #[inline(always)] + pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) } + #[inline(always)] + pure fn find(&self, f: fn(&A) -> bool) -> Option { + iter::find(self, f) + } +} + +impl iter::CopyableOrderedIter for OptVec { + #[inline(always)] + pure fn min(&self) -> A { iter::min(self) } + #[inline(always)] + pure fn max(&self) -> A { iter::max(self) } +} diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index 57d62d628dc6f..a92eb2db42aa2 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -20,6 +20,9 @@ use core::option::{None, Option, Some}; use core::option; use std::oldmap::HashMap; +use opt_vec; +use opt_vec::OptVec; + // SeqSep : a sequence separator (token) // and whether a trailing separator is allowed. pub struct SeqSep { @@ -221,10 +224,10 @@ pub impl Parser { // parse a sequence bracketed by '<' and '>', stopping // before the '>'. - fn parse_seq_to_before_gt(sep: Option, - f: fn(Parser) -> T) -> ~[T] { + fn parse_seq_to_before_gt(sep: Option, + f: fn(Parser) -> T) -> OptVec { let mut first = true; - let mut v = ~[]; + let mut v = opt_vec::Empty; while *self.token != token::GT && *self.token != token::BINOP(token::SHR) { match sep { @@ -236,29 +239,16 @@ pub impl Parser { } v.push(f(self)); } - return v; } - fn parse_seq_to_gt(sep: Option, - f: fn(Parser) -> T) -> ~[T] { + fn parse_seq_to_gt(sep: Option, + f: fn(Parser) -> T) -> OptVec { let v = self.parse_seq_to_before_gt(sep, f); self.expect_gt(); - return v; } - // parse a sequence bracketed by '<' and '>' - fn parse_seq_lt_gt(sep: Option, - f: fn(Parser) -> T) -> spanned<~[T]> { - let lo = self.span.lo; - self.expect(token::LT); - let result = self.parse_seq_to_before_gt::(sep, f); - let hi = self.span.hi; - self.expect_gt(); - return spanned(lo, hi, result); - } - // parse a sequence, including the closing delimiter. The function // f must consume tokens until reaching the next separator or // closing bracket. diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index af25a4f6e58dc..d4b7f2ae5b4e3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -51,7 +51,7 @@ use ast::{token_tree, trait_method, trait_ref, tt_delim, tt_seq, tt_tok}; use ast::{tt_nonterminal, tuple_variant_kind, Ty, ty_, ty_bot, ty_box}; use ast::{ty_field, ty_fixed_length_vec, ty_closure, ty_bare_fn}; use ast::{ty_infer, ty_mac, ty_method}; -use ast::{ty_nil, ty_param, ty_param_bound, ty_path, ty_ptr, ty_rec, ty_rptr}; +use ast::{ty_nil, TyParam, TyParamBound, ty_path, ty_ptr, ty_rec, ty_rptr}; use ast::{ty_tup, ty_u32, ty_uniq, ty_vec, type_value_ns, uniq}; use ast::{unnamed_field, unsafe_blk, unsafe_fn, variant, view_item}; use ast::{view_item_, view_item_extern_mod, view_item_use}; @@ -83,6 +83,8 @@ use parse::token; use parse::{new_sub_parser_from_file, next_node_id, ParseSess}; use print::pprust::expr_to_str; use util::interner::Interner; +use opt_vec; +use opt_vec::OptVec; use core::cmp; use core::either::{Either, Left, Right}; @@ -438,7 +440,7 @@ pub impl Parser { // could change. let ident = p.parse_method_name(); - let tps = p.parse_ty_params(); + let generics = p.parse_generics(); let (self_ty, d) = do self.parse_fn_decl_with_self() |p| { // This is somewhat dubious; We don't want to allow argument @@ -463,7 +465,7 @@ pub impl Parser { attrs: attrs, purity: pur, decl: d, - tps: tps, + generics: generics, self_ty: self_ty, id: p.get_id(), span: mk_sp(lo, hi) @@ -477,7 +479,7 @@ pub impl Parser { provided(@ast::method { ident: ident, attrs: attrs, - tps: tps, + generics: generics, self_ty: self_ty, purity: pur, decl: d, @@ -917,19 +919,7 @@ pub impl Parser { }; // Parse any lifetime or type parameters which may appear: - let tps = { - if !self.eat(token::LT) { - ~[] - } else { - // First consume lifetimes. - let _lifetimes = self.parse_lifetimes(); - let result = self.parse_seq_to_gt( - Some(token::COMMA), - |p| p.parse_ty(false)); - result - } - }; - + let tps = self.parse_generic_values(); let hi = self.span.lo; @ast::path { span: mk_sp(lo, hi), @@ -975,7 +965,7 @@ pub impl Parser { } } - fn parse_lifetimes() -> ~[ast::Lifetime] { + fn parse_lifetimes() -> OptVec { /*! * * Parses zero or more comma separated lifetimes. @@ -984,7 +974,7 @@ pub impl Parser { * lists, where we expect something like `<'a, 'b, T>`. */ - let mut res = ~[]; + let mut res = opt_vec::Empty; loop { match *self.token { token::LIFETIME(_) => { @@ -1155,7 +1145,7 @@ pub impl Parser { let remaining_exprs = self.parse_seq_to_end(token::RBRACKET, seq_sep_trailing_allowed(token::COMMA), - |p| p.parse_expr()); + |p| p.parse_expr()).to_vec(); ex = expr_vec(~[first_expr] + remaining_exprs, mutbl); } else { // Vector with one element. @@ -1287,8 +1277,7 @@ pub impl Parser { self.bump(); let tys = if self.eat(token::MOD_SEP) { self.expect(token::LT); - self.parse_seq_to_gt(Some(token::COMMA), - |p| p.parse_ty(false)) + self.parse_generic_values_after_lt() } else { ~[] }; @@ -1418,7 +1407,7 @@ pub impl Parser { vec::append( self.parse_seq_to_before_end( ket, seq_sep_none(), - |p| p.parse_token_tree()), + |p| p.parse_token_tree()).to_vec(), // the close delimiter: ~[parse_any_tt_tok(self)]))) } @@ -2624,81 +2613,105 @@ pub impl Parser { if self.eat_keyword(~"once") { ast::Once } else { ast::Many } } - fn parse_optional_ty_param_bounds() -> @~[ty_param_bound] { - let mut bounds = ~[]; - if self.eat(token::COLON) { - loop { - if self.eat(token::BINOP(token::AND)) { - if self.eat_keyword(~"static") { - bounds.push(RegionTyParamBound); - } else { - self.span_err(*self.span, - ~"`&static` is the only permissible \ - region bound here"); - } - } else if is_ident(*self.token) { - let maybe_bound = match *self.token { - token::IDENT(copy sid, _) => { + fn parse_optional_ty_param_bounds() -> @OptVec { + if !self.eat(token::COLON) { + return @opt_vec::Empty; + } + + let mut result = opt_vec::Empty; + loop { + if self.eat(token::BINOP(token::AND)) { + if self.eat_keyword(~"static") { + result.push(RegionTyParamBound); + } else { + self.span_err(*self.span, + ~"`&static` is the only permissible \ + region bound here"); + } + } else if is_ident(*self.token) { + let maybe_bound = match *self.token { + token::IDENT(sid, _) => { match *self.id_to_str(sid) { + ~"send" | + ~"copy" | + ~"const" | + ~"owned" => { + self.obsolete( + *self.span, + ObsoleteLowerCaseKindBounds); + + // Bogus value, but doesn't matter, since + // is an error + Some(TraitTyParamBound( + self.mk_ty_path(sid))) + } - ~"send" - | ~"copy" - | ~"const" - | ~"owned" => { - self.obsolete(*self.span, - ObsoleteLowerCaseKindBounds); - // Bogus value, but doesn't matter, since - // is an error - Some(TraitTyParamBound(self.mk_ty_path(sid))) - } - - _ => None + _ => None } - } - _ => self.bug( - ~"is_ident() said this would be an identifier") - }; + } + _ => fail!() + }; - match maybe_bound { - Some(bound) => { - self.bump(); - bounds.push(bound); - } - None => { - let ty = self.parse_ty(false); - bounds.push(TraitTyParamBound(ty)); - } + match maybe_bound { + Some(bound) => { + self.bump(); + result.push(bound); + } + None => { + let ty = self.parse_ty(false); + result.push(TraitTyParamBound(ty)); } - } else { - break; } + } else { + break; + } - if self.eat(token::BINOP(token::PLUS)) { - loop; - } + if self.eat(token::BINOP(token::PLUS)) { + loop; + } - if is_ident_or_path(*self.token) { - self.obsolete(*self.span, - ObsoleteTraitBoundSeparator); - } + if is_ident_or_path(*self.token) { + self.obsolete(*self.span, + ObsoleteTraitBoundSeparator); } } - return @bounds; + + return @result; } - fn parse_ty_param() -> ty_param { + fn parse_ty_param() -> TyParam { let ident = self.parse_ident(); let bounds = self.parse_optional_ty_param_bounds(); - ast::ty_param { ident: ident, id: self.get_id(), bounds: bounds } + ast::TyParam { ident: ident, id: self.get_id(), bounds: bounds } } - fn parse_ty_params() -> ~[ty_param] { + fn parse_generics() -> ast::Generics { if self.eat(token::LT) { - let _lifetimes = self.parse_lifetimes(); - self.parse_seq_to_gt( + let lifetimes = self.parse_lifetimes(); + let ty_params = self.parse_seq_to_gt( Some(token::COMMA), - |p| p.parse_ty_param()) - } else { ~[] } + |p| p.parse_ty_param()); + return ast::Generics {lifetimes: lifetimes, + ty_params: ty_params}; + } else { + return ast_util::empty_generics(); + } + } + + fn parse_generic_values() -> ~[@Ty] { + if !self.eat(token::LT) { + ~[] + } else { + self.parse_generic_values_after_lt() + } + } + + fn parse_generic_values_after_lt() -> ~[@Ty] { + let _lifetimes = self.parse_lifetimes(); + let result = self.parse_seq_to_gt( + Some(token::COMMA), + |p| p.parse_ty(false)); + result.to_vec() } fn parse_fn_decl(parse_arg_fn: fn(Parser) -> arg_or_capture_item) @@ -2790,7 +2803,7 @@ pub impl Parser { args_or_capture_items = self.parse_seq_to_before_end(token::RPAREN, sep, - parse_arg_fn); + parse_arg_fn).to_vec(); } token::RPAREN => { args_or_capture_items = ~[]; @@ -2806,7 +2819,7 @@ pub impl Parser { args_or_capture_items = self.parse_seq_to_before_end(token::RPAREN, sep, - parse_arg_fn); + parse_arg_fn).to_vec(); } self.expect(token::RPAREN); @@ -2849,10 +2862,10 @@ pub impl Parser { } } - fn parse_fn_header() -> (ident, ~[ty_param]) { + fn parse_fn_header() -> (ident, ast::Generics) { let id = self.parse_value_ident(); - let ty_params = self.parse_ty_params(); - (id, ty_params) + let generics = self.parse_generics(); + (id, generics) } fn mk_item(+lo: BytePos, +hi: BytePos, +ident: ident, @@ -2867,10 +2880,10 @@ pub impl Parser { } fn parse_item_fn(purity: purity) -> item_info { - let (ident, tps) = self.parse_fn_header(); + let (ident, generics) = self.parse_fn_header(); let decl = self.parse_fn_decl(|p| p.parse_arg()); let (inner_attrs, body) = self.parse_inner_attrs_and_block(true); - (ident, item_fn(decl, purity, tps, body), Some(inner_attrs)) + (ident, item_fn(decl, purity, generics, body), Some(inner_attrs)) } fn parse_method_name() -> ident { @@ -2887,7 +2900,7 @@ pub impl Parser { let visa = self.parse_visibility(); let pur = self.parse_fn_purity(); let ident = self.parse_method_name(); - let tps = self.parse_ty_params(); + let generics = self.parse_generics(); let (self_ty, decl) = do self.parse_fn_decl_with_self() |p| { p.parse_arg() }; @@ -2899,7 +2912,7 @@ pub impl Parser { @ast::method { ident: ident, attrs: attrs, - tps: tps, + generics: generics, self_ty: self_ty, purity: pur, decl: decl, @@ -2914,7 +2927,7 @@ pub impl Parser { fn parse_item_trait() -> item_info { let ident = self.parse_ident(); self.parse_region_param(); - let tps = self.parse_ty_params(); + let tps = self.parse_generics(); // Parse traits, if necessary. let traits; @@ -2942,12 +2955,7 @@ pub impl Parser { } // First, parse type parameters if necessary. - let mut tps; - if *self.token == token::LT { - tps = self.parse_ty_params(); - } else { - tps = ~[]; - } + let generics = self.parse_generics(); // This is a new-style impl declaration. // XXX: clownshoes @@ -2989,37 +2997,7 @@ pub impl Parser { } } - (ident, item_impl(tps, opt_trait, ty, meths), None) - } - - // Instantiates ident with references to as arguments. - // Used to create a path that refers to a class which will be defined as - // the return type of the ctor function. - fn ident_to_path_tys(i: ident, - typarams: ~[ty_param]) -> @path { - let s = *self.last_span; - - @ast::path { - span: s, - global: false, - idents: ~[i], - rp: None, - types: do typarams.map |tp| { - @Ty { - id: self.get_id(), - node: ty_path(ident_to_path(s, tp.ident), self.get_id()), - span: s - } - } - } - } - - fn ident_to_path(i: ident) -> @path { - @ast::path { span: *self.last_span, - global: false, - idents: ~[i], - rp: None, - types: ~[] } + (ident, item_impl(generics, opt_trait, ty, meths), None) } fn parse_trait_ref() -> @trait_ref { @@ -3032,13 +3010,13 @@ pub impl Parser { fn parse_trait_ref_list(ket: token::Token) -> ~[@trait_ref] { self.parse_seq_to_before_end( ket, seq_sep_none(), - |p| p.parse_trait_ref()) + |p| p.parse_trait_ref()).to_vec() } fn parse_item_struct() -> item_info { let class_name = self.parse_value_ident(); self.parse_region_param(); - let ty_params = self.parse_ty_params(); + let generics = self.parse_generics(); if self.eat(token::COLON) { self.obsolete(*self.span, ObsoleteClassTraits); let _ = self.parse_trait_ref_list(token::LBRACE); @@ -3115,7 +3093,7 @@ pub impl Parser { fields: fields, dtor: actual_dtor, ctor_id: if is_tuple_like { Some(new_id) } else { None } - }, ty_params), + }, generics), None) } @@ -3379,13 +3357,13 @@ pub impl Parser { let lo = self.span.lo; let vis = self.parse_visibility(); let purity = self.parse_fn_purity(); - let (ident, tps) = self.parse_fn_header(); + let (ident, generics) = self.parse_fn_header(); let decl = self.parse_fn_decl(|p| p.parse_arg()); let mut hi = self.span.hi; self.expect(token::SEMI); @ast::foreign_item { ident: ident, attrs: attrs, - node: foreign_item_fn(decl, purity, tps), + node: foreign_item_fn(decl, purity, generics), id: self.get_id(), span: mk_sp(lo, hi), vis: vis } @@ -3548,7 +3526,7 @@ pub impl Parser { fn parse_item_type() -> item_info { let (_, ident) = self.parse_type_decl(); self.parse_region_param(); - let tps = self.parse_ty_params(); + let tps = self.parse_generics(); self.expect(token::EQ); let ty = self.parse_ty(false); self.expect(token::SEMI); @@ -3604,8 +3582,7 @@ pub impl Parser { }; } - fn parse_enum_def(ty_params: ~[ast::ty_param]) - -> enum_def { + fn parse_enum_def(+generics: ast::Generics) -> enum_def { let mut variants: ~[variant] = ~[]; let mut all_nullary = true, have_disr = false; let mut common_fields = None; @@ -3632,7 +3609,7 @@ pub impl Parser { if self.eat_keyword(~"enum") { ident = self.parse_ident(); self.expect(token::LBRACE); - let nested_enum_def = self.parse_enum_def(ty_params); + let nested_enum_def = self.parse_enum_def(generics); kind = enum_variant_kind(nested_enum_def); needs_comma = false; } else { @@ -3688,7 +3665,7 @@ pub impl Parser { fn parse_item_enum() -> item_info { let id = self.parse_ident(); self.parse_region_param(); - let ty_params = self.parse_ty_params(); + let generics = self.parse_generics(); // Newtype syntax if *self.token == token::EQ { self.bump(); @@ -3711,14 +3688,14 @@ pub impl Parser { enum_def( ast::enum_def_ { variants: ~[variant], common: None } ), - ty_params), + generics), None ); } self.expect(token::LBRACE); - let enum_definition = self.parse_enum_def(ty_params); - (id, item_enum(enum_definition, ty_params), None) + let enum_definition = self.parse_enum_def(generics); + (id, item_enum(enum_definition, generics), None) } fn parse_fn_ty_sigil() -> Option { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d5a09e087a02e..5eb40626437ea 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -14,6 +14,8 @@ use ast::{RegionTyParamBound, TraitTyParamBound, required, provided}; use ast; use ast_util; use ast_util::{operator_prec}; +use opt_vec; +use opt_vec::OptVec; use attr; use codemap::{CodeMap, BytePos}; use codemap; @@ -164,8 +166,9 @@ pub fn item_to_str(i: @ast::item, intr: @ident_interner) -> ~str { to_str(i, print_item, intr) } -pub fn typarams_to_str(tps: ~[ast::ty_param], intr: @ident_interner) -> ~str { - to_str(tps, print_type_params, intr) +pub fn generics_to_str(generics: &ast::Generics, + intr: @ident_interner) -> ~str { + to_str(generics, print_generics, intr) } pub fn path_to_str(&&p: @ast::path, intr: @ident_interner) -> ~str { @@ -173,10 +176,10 @@ pub fn path_to_str(&&p: @ast::path, intr: @ident_interner) -> ~str { } pub fn fun_to_str(decl: ast::fn_decl, name: ast::ident, - params: ~[ast::ty_param], intr: @ident_interner) -> ~str { + generics: &ast::Generics, intr: @ident_interner) -> ~str { do io::with_str_writer |wr| { let s = rust_printer(wr, intr); - print_fn(s, decl, None, name, params, None, ast::inherited); + print_fn(s, decl, None, name, generics, None, ast::inherited); end(s); // Close the head box end(s); // Close the outer box eof(s.s); @@ -300,7 +303,7 @@ pub fn synth_comment(s: @ps, text: ~str) { word(s.s, ~"*/"); } -pub fn commasep(s: @ps, b: breaks, elts: ~[IN], op: fn(@ps, IN)) { +pub fn commasep(s: @ps, b: breaks, elts: ~[IN], op: &fn(@ps, IN)) { box(s, 0u, b); let mut first = true; for elts.each |elt| { @@ -459,8 +462,8 @@ pub fn print_foreign_item(s: @ps, item: @ast::foreign_item) { maybe_print_comment(s, item.span.lo); print_outer_attributes(s, item.attrs); match item.node { - ast::foreign_item_fn(decl, purity, typarams) => { - print_fn(s, decl, Some(purity), item.ident, typarams, None, + ast::foreign_item_fn(decl, purity, ref generics) => { + print_fn(s, decl, Some(purity), item.ident, generics, None, ast::inherited); end(s); // end head-ibox word(s.s, ~";"); @@ -505,7 +508,7 @@ pub fn print_item(s: @ps, &&item: @ast::item) { /* FIXME (#2543) */ copy *decl, Some(purity), item.ident, - /* FIXME (#2543) */ copy *typarams, + typarams, None, item.vis ); @@ -536,12 +539,12 @@ pub fn print_item(s: @ps, &&item: @ast::item) { print_foreign_mod(s, nmod, item.attrs); bclose(s, item.span); } - ast::item_ty(ty, params) => { + ast::item_ty(ty, ref params) => { ibox(s, indent_unit); ibox(s, 0u); word_nbsp(s, visibility_qualified(item.vis, ~"type")); print_ident(s, item.ident); - print_type_params(s, params); + print_generics(s, params); end(s); // end the inner ibox space(s.s); @@ -554,21 +557,21 @@ pub fn print_item(s: @ps, &&item: @ast::item) { print_enum_def( s, *enum_definition, - /* FIXME (#2543) */ copy *params, + params, item.ident, item.span, item.vis ); } - ast::item_struct(struct_def, tps) => { + ast::item_struct(struct_def, ref generics) => { head(s, visibility_qualified(item.vis, ~"struct")); - print_struct(s, struct_def, tps, item.ident, item.span); + print_struct(s, struct_def, generics, item.ident, item.span); } - ast::item_impl(tps, opt_trait, ty, methods) => { + ast::item_impl(ref generics, opt_trait, ty, methods) => { head(s, visibility_qualified(item.vis, ~"impl")); - if !tps.is_empty() { - print_type_params(s, tps); + if !generics.is_empty() { + print_generics(s, generics); space(s.s); } @@ -594,10 +597,10 @@ pub fn print_item(s: @ps, &&item: @ast::item) { bclose(s, item.span); } } - ast::item_trait(ref tps, ref traits, ref methods) => { + ast::item_trait(ref generics, ref traits, ref methods) => { head(s, visibility_qualified(item.vis, ~"trait")); print_ident(s, item.ident); - print_type_params(s, /* FIXME (#2543) */ copy *tps); + print_generics(s, generics); if traits.len() != 0u { word(s.s, ~":"); for traits.each |trait_| { @@ -629,7 +632,7 @@ pub fn print_item(s: @ps, &&item: @ast::item) { } pub fn print_enum_def(s: @ps, enum_definition: ast::enum_def, - params: ~[ast::ty_param], ident: ast::ident, + generics: &ast::Generics, ident: ast::ident, span: codemap::span, visibility: ast::visibility) { let mut newtype = vec::len(enum_definition.variants) == 1u && @@ -648,7 +651,7 @@ pub fn print_enum_def(s: @ps, enum_definition: ast::enum_def, } print_ident(s, ident); - print_type_params(s, params); + print_generics(s, generics); space(s.s); if newtype { word_space(s, ~"="); @@ -706,12 +709,12 @@ pub fn print_visibility(s: @ps, vis: ast::visibility) { pub fn print_struct(s: @ps, struct_def: @ast::struct_def, - tps: ~[ast::ty_param], + generics: &ast::Generics, ident: ast::ident, span: codemap::span) { print_ident(s, ident); nbsp(s); - print_type_params(s, tps); + print_generics(s, generics); if ast_util::struct_def_is_tuple_like(struct_def) { popen(s); let mut first = true; @@ -823,7 +826,8 @@ pub fn print_variant(s: @ps, v: ast::variant) { } ast::struct_variant_kind(struct_def) => { head(s, ~""); - print_struct(s, struct_def, ~[], v.node.name, v.span); + let generics = ast_util::empty_generics(); + print_struct(s, struct_def, &generics, v.node.name, v.span); } ast::enum_variant_kind(ref enum_definition) => { print_variants(s, (*enum_definition).variants, v.span); @@ -844,7 +848,7 @@ pub fn print_ty_method(s: @ps, m: ast::ty_method) { maybe_print_comment(s, m.span.lo); print_outer_attributes(s, m.attrs); print_ty_fn(s, None, None, None, m.purity, ast::Many, - m.decl, Some(m.ident), Some(m.tps), + m.decl, Some(m.ident), Some(&m.generics), Some(m.self_ty.node)); word(s.s, ~";"); } @@ -861,7 +865,7 @@ pub fn print_method(s: @ps, meth: @ast::method) { maybe_print_comment(s, meth.span.lo); print_outer_attributes(s, meth.attrs); print_fn(s, meth.decl, Some(meth.purity), - meth.ident, meth.tps, Some(meth.self_ty.node), + meth.ident, &meth.generics, Some(meth.self_ty.node), meth.vis); word(s.s, ~" "); print_block_with_attrs(s, meth.body, meth.attrs); @@ -1714,14 +1718,14 @@ pub fn print_fn(s: @ps, decl: ast::fn_decl, purity: Option, name: ast::ident, - typarams: ~[ast::ty_param], + generics: &ast::Generics, opt_self_ty: Option, vis: ast::visibility) { head(s, ~""); print_fn_header_info(s, opt_self_ty, purity, ast::Many, None, vis); nbsp(s); print_ident(s, name); - print_type_params(s, typarams); + print_generics(s, generics); print_fn_args_and_ret(s, decl, opt_self_ty); } @@ -1791,11 +1795,11 @@ pub fn print_arg_mode(s: @ps, m: ast::mode) { if ms != ~"" { word(s.s, ms); } } -pub fn print_bounds(s: @ps, bounds: @~[ast::ty_param_bound]) { +pub fn print_bounds(s: @ps, bounds: @OptVec) { if !bounds.is_empty() { word(s.s, ~":"); let mut first = true; - for vec::each(*bounds) |&bound| { + for bounds.each |bound| { nbsp(s); if first { first = false; @@ -1803,7 +1807,7 @@ pub fn print_bounds(s: @ps, bounds: @~[ast::ty_param_bound]) { word_space(s, ~"+"); } - match bound { + match *bound { TraitTyParamBound(ty) => print_type(s, ty), RegionTyParamBound => word(s.s, ~"&static"), } @@ -1811,14 +1815,33 @@ pub fn print_bounds(s: @ps, bounds: @~[ast::ty_param_bound]) { } } -pub fn print_type_params(s: @ps, &¶ms: ~[ast::ty_param]) { - if vec::len(params) > 0u { +pub fn print_lifetime(s: @ps, lifetime: &ast::Lifetime) { + word(s.s, ~"'"); + print_ident(s, lifetime.ident); +} + +pub fn print_generics(s: @ps, &&generics: &ast::Generics) { + let total = generics.lifetimes.len() + generics.ty_params.len(); + if total > 0 { word(s.s, ~"<"); - fn printParam(s: @ps, param: ast::ty_param) { - print_ident(s, param.ident); - print_bounds(s, param.bounds); + fn print_item(s: @ps, generics: &ast::Generics, idx: uint) { + if idx < generics.lifetimes.len() { + let lifetime = generics.lifetimes.get(idx); + print_lifetime(s, lifetime); + } else { + let param = generics.ty_params.get(idx); + print_ident(s, param.ident); + print_bounds(s, param.bounds); + } } - commasep(s, inconsistent, params, printParam); + + let mut ints = ~[]; + for uint::range(0, total) |i| { + ints.push(i); + } + + commasep(s, inconsistent, ints, + |s, i| print_item(s, generics, i)); word(s.s, ~">"); } } @@ -1954,7 +1977,7 @@ pub fn print_ty_fn(s: @ps, purity: ast::purity, onceness: ast::Onceness, decl: ast::fn_decl, id: Option, - tps: Option<~[ast::ty_param]>, + generics: Option<&ast::Generics>, opt_self_ty: Option) { ibox(s, indent_unit); @@ -1968,7 +1991,7 @@ pub fn print_ty_fn(s: @ps, print_onceness(s, onceness); word(s.s, ~"fn"); match id { Some(id) => { word(s.s, ~" "); print_ident(s, id); } _ => () } - match tps { Some(tps) => print_type_params(s, tps), _ => () } + match generics { Some(g) => print_generics(s, g), _ => () } zerobreak(s.s); popen(s); @@ -2301,7 +2324,8 @@ pub mod test { span: codemap::dummy_sp()}, cf: ast::return_val }; - check_equal (&fun_to_str(decl, abba_ident, ~[],mock_interner), + let generics = ast_util::empty_generics(); + check_equal (&fun_to_str(decl, abba_ident, &generics, mock_interner), &~"fn abba()"); } diff --git a/src/libsyntax/syntax.rc b/src/libsyntax/syntax.rc index 05bbe43ee9abf..9eb7507f3d0d7 100644 --- a/src/libsyntax/syntax.rc +++ b/src/libsyntax/syntax.rc @@ -35,6 +35,7 @@ pub mod syntax { pub use parse; } +pub mod opt_vec; pub mod attr; pub mod diagnostic; pub mod codemap; diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 3701607ffc13f..95a6500955dd9 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -15,6 +15,7 @@ use ast; use ast_util; use codemap::span; use parse; +use opt_vec; use core::option; use core::vec; @@ -30,11 +31,11 @@ use core::vec; pub enum vt { mk_vt(visitor), } pub enum fn_kind { - fk_item_fn(ident, ~[ty_param], purity), // fn foo() - fk_method(ident, ~[ty_param], @method), // fn foo(&self) + fk_item_fn(ident, Generics, purity), // fn foo() + fk_method(ident, Generics, @method), // fn foo(&self) fk_anon(ast::Sigil), // fn@(x, y) { ... } fk_fn_block, // |x, y| ... - fk_dtor(~[ty_param], ~[attribute], node_id /* self id */, + fk_dtor(Generics, ~[attribute], node_id /* self id */, def_id /* parent class id */) // class destructor } @@ -49,13 +50,17 @@ pub fn name_of_fn(fk: fn_kind) -> ident { } } -pub fn tps_of_fn(fk: fn_kind) -> ~[ty_param] { +pub fn generics_of_fn(fk: fn_kind) -> Generics { match fk { - fk_item_fn(_, tps, _) | fk_method(_, tps, _) | + fk_item_fn(_, tps, _) | + fk_method(_, tps, _) | fk_dtor(tps, _, _, _) => { - /* FIXME (#2543) */ copy tps + copy tps + } + fk_anon(*) | fk_fn_block(*) => { + Generics {lifetimes: opt_vec::Empty, + ty_params: opt_vec::Empty} } - fk_anon(*) | fk_fn_block(*) => ~[] } } @@ -73,11 +78,11 @@ pub struct Visitor { visit_expr: fn@(@expr, E, vt), visit_expr_post: fn@(@expr, E, vt), visit_ty: fn@(@Ty, E, vt), - visit_ty_params: fn@(~[ty_param], E, vt), + visit_generics: fn@(&Generics, E, vt), visit_fn: fn@(fn_kind, fn_decl, blk, span, node_id, E, vt), visit_ty_method: fn@(ty_method, E, vt), visit_trait_method: fn@(trait_method, E, vt), - visit_struct_def: fn@(@struct_def, ident, ~[ty_param], node_id, E, + visit_struct_def: fn@(@struct_def, ident, &Generics, node_id, E, vt), visit_struct_field: fn@(@struct_field, E, vt), visit_struct_method: fn@(@method, E, vt) @@ -100,7 +105,7 @@ pub fn default_visitor() -> visitor { visit_expr: |a,b,c|visit_expr::(a, b, c), visit_expr_post: |_a,_b,_c| (), visit_ty: |a,b,c|skip_ty::(a, b, c), - visit_ty_params: |a,b,c|visit_ty_params::(a, b, c), + visit_generics: |a,b,c|visit_generics::(a, b, c), visit_fn: |a,b,c,d,e,f,g|visit_fn::(a, b, c, d, e, f, g), visit_ty_method: |a,b,c|visit_ty_method::(a, b, c), visit_trait_method: |a,b,c|visit_trait_method::(a, b, c), @@ -157,21 +162,21 @@ pub fn visit_item(i: @item, e: E, v: vt) { for nm.view_items.each |vi| { (v.visit_view_item)(*vi, e, v); } for nm.items.each |ni| { (v.visit_foreign_item)(*ni, e, v); } } - item_ty(t, tps) => { + item_ty(t, ref tps) => { (v.visit_ty)(t, e, v); - (v.visit_ty_params)(tps, e, v); + (v.visit_generics)(tps, e, v); } item_enum(ref enum_definition, ref tps) => { - (v.visit_ty_params)(/* FIXME (#2543) */ copy *tps, e, v); + (v.visit_generics)(tps, e, v); visit_enum_def( *enum_definition, - /* FIXME (#2543) */ copy *tps, + tps, e, v ); } - item_impl(tps, traits, ty, methods) => { - (v.visit_ty_params)(tps, e, v); + item_impl(ref tps, traits, ty, methods) => { + (v.visit_generics)(tps, e, v); for traits.each |p| { visit_path(p.path, e, v); } @@ -180,12 +185,12 @@ pub fn visit_item(i: @item, e: E, v: vt) { visit_method_helper(*m, e, v) } } - item_struct(struct_def, tps) => { - (v.visit_ty_params)(tps, e, v); + item_struct(struct_def, ref tps) => { + (v.visit_generics)(tps, e, v); (v.visit_struct_def)(struct_def, i.ident, tps, i.id, e, v); } item_trait(ref tps, ref traits, ref methods) => { - (v.visit_ty_params)(/* FIXME (#2543) */ copy *tps, e, v); + (v.visit_generics)(tps, e, v); for traits.each |p| { visit_path(p.path, e, v); } for (*methods).each |m| { (v.visit_trait_method)(*m, e, v); @@ -196,7 +201,7 @@ pub fn visit_item(i: @item, e: E, v: vt) { } pub fn visit_enum_def(enum_definition: ast::enum_def, - tps: ~[ast::ty_param], + tps: &Generics, e: E, v: vt) { for enum_definition.variants.each |vr| { @@ -296,9 +301,9 @@ pub fn visit_pat(p: @pat, e: E, v: vt) { pub fn visit_foreign_item(ni: @foreign_item, e: E, v: vt) { match ni.node { - foreign_item_fn(fd, _, tps) => { - (v.visit_ty_params)(tps, e, v); + foreign_item_fn(fd, _, ref generics) => { visit_fn_decl(fd, e, v); + (v.visit_generics)(generics, e, v); } foreign_item_const(t) => { (v.visit_ty)(t, e, v); @@ -306,17 +311,18 @@ pub fn visit_foreign_item(ni: @foreign_item, e: E, v: vt) { } } -pub fn visit_ty_param_bounds(bounds: @~[ty_param_bound], e: E, v: vt) { - for bounds.each |&bound| { - match bound { +pub fn visit_ty_param_bounds(bounds: @OptVec, + e: E, v: vt) { + for bounds.each |bound| { + match *bound { TraitTyParamBound(ty) => (v.visit_ty)(ty, e, v), RegionTyParamBound => () } } } -pub fn visit_ty_params(tps: ~[ty_param], e: E, v: vt) { - for tps.each |tp| { +pub fn visit_generics(generics: &Generics, e: E, v: vt) { + for generics.ty_params.each |tp| { visit_ty_param_bounds(tp.bounds, e, v); } } @@ -334,29 +340,33 @@ pub fn visit_fn_decl(fd: fn_decl, e: E, v: vt) { // because it is not a default impl of any method, though I doubt that really // clarifies anything. - Niko pub fn visit_method_helper(m: @method, e: E, v: vt) { - (v.visit_fn)(fk_method(/* FIXME (#2543) */ copy m.ident, - /* FIXME (#2543) */ copy m.tps, m), - m.decl, m.body, m.span, m.id, e, v); + (v.visit_fn)(fk_method(m.ident, /* FIXME (#2543) */ copy m.generics, m), + m.decl, m.body, m.span, m.id, e, v); } -pub fn visit_struct_dtor_helper(dtor: struct_dtor, tps: ~[ty_param], +pub fn visit_struct_dtor_helper(dtor: struct_dtor, generics: &Generics, parent_id: def_id, e: E, v: vt) { - (v.visit_fn)(fk_dtor(/* FIXME (#2543) */ copy tps, dtor.node.attrs, - dtor.node.self_id, parent_id), ast_util::dtor_dec(), - dtor.node.body, dtor.span, dtor.node.id, e, v) + (v.visit_fn)(fk_dtor(copy *generics, dtor.node.attrs, + dtor.node.self_id, parent_id), + ast_util::dtor_dec(), + dtor.node.body, + dtor.span, + dtor.node.id, + e, v) } pub fn visit_fn(fk: fn_kind, decl: fn_decl, body: blk, _sp: span, _id: node_id, e: E, v: vt) { visit_fn_decl(decl, e, v); - (v.visit_ty_params)(tps_of_fn(fk), e, v); + let generics = generics_of_fn(fk); + (v.visit_generics)(&generics, e, v); (v.visit_block)(body, e, v); } pub fn visit_ty_method(m: ty_method, e: E, v: vt) { for m.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); } - (v.visit_ty_params)(m.tps, e, v); + (v.visit_generics)(&m.generics, e, v); (v.visit_ty)(m.decl.output, e, v); } @@ -367,13 +377,16 @@ pub fn visit_trait_method(m: trait_method, e: E, v: vt) { } } -pub fn visit_struct_def(sd: @struct_def, _nm: ast::ident, tps: ~[ty_param], - id: node_id, e: E, v: vt) { +pub fn visit_struct_def(sd: @struct_def, + _nm: ast::ident, + generics: &Generics, + id: node_id, + e: E, v: vt) { for sd.fields.each |f| { (v.visit_struct_field)(*f, e, v); } do option::iter(&sd.dtor) |dtor| { - visit_struct_dtor_helper(*dtor, tps, ast_util::local_def(id), e, v) + visit_struct_dtor_helper(*dtor, generics, ast_util::local_def(id), e, v) }; } @@ -552,11 +565,11 @@ pub struct SimpleVisitor { visit_expr: fn@(@expr), visit_expr_post: fn@(@expr), visit_ty: fn@(@Ty), - visit_ty_params: fn@(~[ty_param]), + visit_generics: fn@(&Generics), visit_fn: fn@(fn_kind, fn_decl, blk, span, node_id), visit_ty_method: fn@(ty_method), visit_trait_method: fn@(trait_method), - visit_struct_def: fn@(@struct_def, ident, ~[ty_param], node_id), + visit_struct_def: fn@(@struct_def, ident, &Generics, node_id), visit_struct_field: fn@(@struct_field), visit_struct_method: fn@(@method) } @@ -579,13 +592,13 @@ pub fn default_simple_visitor() -> @SimpleVisitor { visit_expr: |_e: @expr| { }, visit_expr_post: |_e: @expr| { }, visit_ty: simple_ignore_ty, - visit_ty_params: fn@(_ps: ~[ty_param]) {}, + visit_generics: fn@(_ps: &Generics) {}, visit_fn: fn@(_fk: fn_kind, _d: fn_decl, _b: blk, _sp: span, _id: node_id) { }, visit_ty_method: fn@(_m: ty_method) { }, visit_trait_method: fn@(_m: trait_method) { }, visit_struct_def: fn@(_sd: @struct_def, _nm: ident, - _tps: ~[ty_param], _id: node_id) { }, + _generics: &Generics, _id: node_id) { }, visit_struct_field: fn@(_f: @struct_field) { }, visit_struct_method: fn@(_m: @method) { } }; @@ -654,17 +667,20 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> { f(m); visit_trait_method(m, e, v); } - fn v_struct_def(f: fn@(@struct_def, ident, ~[ty_param], node_id), - sd: @struct_def, nm: ident, tps: ~[ty_param], id: node_id, + fn v_struct_def(f: fn@(@struct_def, ident, &Generics, node_id), + sd: @struct_def, + nm: ident, + generics: &Generics, + id: node_id, &&e: (), v: vt<()>) { - f(sd, nm, tps, id); - visit_struct_def(sd, nm, tps, id, e, v); + f(sd, nm, generics, id); + visit_struct_def(sd, nm, generics, id, e, v); } - fn v_ty_params(f: fn@(~[ty_param]), - ps: ~[ty_param], - &&e: (), v: vt<()>) { + fn v_generics(f: fn@(&Generics), + ps: &Generics, + &&e: (), v: vt<()>) { f(ps); - visit_ty_params(ps, e, v); + visit_generics(ps, e, v); } fn v_fn(f: fn@(fn_kind, fn_decl, blk, span, node_id), fk: fn_kind, decl: fn_decl, body: blk, sp: span, @@ -699,8 +715,8 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> { visit_expr_post: |a,b,c| v_expr_post(v.visit_expr_post, a, b, c), visit_ty: visit_ty, - visit_ty_params: |a,b,c| - v_ty_params(v.visit_ty_params, a, b, c), + visit_generics: |a,b,c| + v_generics(v.visit_generics, a, b, c), visit_fn: |a,b,c,d,e,f,g| v_fn(v.visit_fn, a, b, c, d, e, f, g), visit_ty_method: |a,b,c| From 2f858de1c39f3fd8bdc77a6517e12a6458c54f03 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 27 Feb 2013 18:34:04 -0800 Subject: [PATCH 56/85] Remove the last remnants of rtcalls --- src/libcore/cleanup.rs | 4 ++-- src/libcore/rt.rs | 28 ++++++++++-------------- src/librustc/middle/trans/_match.rs | 4 ++-- src/librustc/middle/trans/base.rs | 2 +- src/librustc/middle/trans/callee.rs | 22 +++++++++---------- src/librustc/middle/trans/closure.rs | 2 +- src/librustc/middle/trans/common.rs | 2 +- src/librustc/middle/trans/controlflow.rs | 6 ++--- src/librustc/middle/trans/datum.rs | 4 ++-- src/librustc/middle/trans/glue.rs | 4 ++-- src/librustc/middle/trans/tvec.rs | 2 +- 11 files changed, 37 insertions(+), 43 deletions(-) diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs index 567d6da23a68c..6912d6d995b8f 100644 --- a/src/libcore/cleanup.rs +++ b/src/libcore/cleanup.rs @@ -154,7 +154,7 @@ fn debug_mem() -> bool { #[cfg(notest)] #[lang="annihilate"] pub unsafe fn annihilate() { - use rt::rt_free; + use rt::local_free; use io::WriterUtil; use io; use libc; @@ -192,7 +192,7 @@ pub unsafe fn annihilate() { stats.n_bytes_freed += (*((*box).header.type_desc)).size + sys::size_of::(); - rt_free(transmute(box)); + local_free(transmute(box)); } } diff --git a/src/libcore/rt.rs b/src/libcore/rt.rs index c3e4f925c4014..5d0bad3ceb3c2 100644 --- a/src/libcore/rt.rs +++ b/src/libcore/rt.rs @@ -36,60 +36,54 @@ pub extern mod rustrt { unsafe fn rust_upcall_free(ptr: *c_char); } -#[rt(fail_)] #[lang="fail_"] -pub fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) -> ! { +pub fn fail_(expr: *c_char, file: *c_char, line: size_t) -> ! { sys::begin_unwind_(expr, file, line); } -#[rt(fail_bounds_check)] #[lang="fail_bounds_check"] -pub unsafe fn rt_fail_bounds_check(file: *c_char, line: size_t, - index: size_t, len: size_t) { +pub unsafe fn fail_bounds_check(file: *c_char, line: size_t, + index: size_t, len: size_t) { let msg = fmt!("index out of bounds: the len is %d but the index is %d", len as int, index as int); do str::as_buf(msg) |p, _len| { - rt_fail_(p as *c_char, file, line); + fail_(p as *c_char, file, line); } } -pub unsafe fn rt_fail_borrowed() { +pub unsafe fn fail_borrowed() { let msg = "borrowed"; do str::as_buf(msg) |msg_p, _| { do str::as_buf("???") |file_p, _| { - rt_fail_(msg_p as *c_char, file_p as *c_char, 0); + fail_(msg_p as *c_char, file_p as *c_char, 0); } } } // FIXME #4942: Make these signatures agree with exchange_alloc's signatures -#[rt(exchange_malloc)] #[lang="exchange_malloc"] -pub unsafe fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { +pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { transmute(exchange_alloc::malloc(transmute(td), transmute(size))) } // NB: Calls to free CANNOT be allowed to fail, as throwing an exception from // inside a landing pad may corrupt the state of the exception handler. If a // problem occurs, call exit instead. -#[rt(exchange_free)] #[lang="exchange_free"] -pub unsafe fn rt_exchange_free(ptr: *c_char) { +pub unsafe fn exchange_free(ptr: *c_char) { exchange_alloc::free(transmute(ptr)) } -#[rt(malloc)] #[lang="malloc"] -pub unsafe fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char { +pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char { return rustrt::rust_upcall_malloc(td, size); } // NB: Calls to free CANNOT be allowed to fail, as throwing an exception from // inside a landing pad may corrupt the state of the exception handler. If a // problem occurs, call exit instead. -#[rt(free)] #[lang="free"] -pub unsafe fn rt_free(ptr: *c_char) { +pub unsafe fn local_free(ptr: *c_char) { rustrt::rust_upcall_free(ptr); } @@ -112,7 +106,7 @@ pub unsafe fn return_to_mut(a: *u8) { pub unsafe fn check_not_borrowed(a: *u8) { let a: *mut BoxRepr = transmute(a); if ((*a).header.ref_count & FROZEN_BIT) != 0 { - rt_fail_borrowed(); + fail_borrowed(); } } diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 3686c31ea6e64..8ed85b8f42196 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -1054,7 +1054,7 @@ pub fn compare_values(cx: block, let scratch_rhs = alloca(cx, val_ty(rhs)); Store(cx, rhs, scratch_rhs); let did = cx.tcx().lang_items.uniq_str_eq_fn(); - let bcx = callee::trans_rtcall_or_lang_call(cx, did, + let bcx = callee::trans_lang_call(cx, did, ~[scratch_lhs, scratch_rhs], expr::SaveIn( @@ -1069,7 +1069,7 @@ pub fn compare_values(cx: block, let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()), false); let did = cx.tcx().lang_items.str_eq_fn(); - let bcx = callee::trans_rtcall_or_lang_call(cx, did, + let bcx = callee::trans_lang_call(cx, did, ~[lhs, rhs], expr::SaveIn( scratch_result.val)); diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 740a7e043d4dd..b92501a2f7c32 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -304,7 +304,7 @@ pub fn malloc_raw_dyn(bcx: block, // Allocate space: let tydesc = PointerCast(bcx, static_ti.tydesc, T_ptr(T_i8())); let rval = alloca(bcx, T_ptr(T_i8())); - let bcx = callee::trans_rtcall_or_lang_call( + let bcx = callee::trans_lang_call( bcx, langcall, ~[tydesc, size], diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 6924ccf3ab644..42542d79f39b2 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -332,11 +332,11 @@ pub fn trans_method_call(in_cx: block, DontAutorefArg) } -pub fn trans_rtcall_or_lang_call(bcx: block, - did: ast::def_id, - args: &[ValueRef], - dest: expr::Dest) - -> block { +pub fn trans_lang_call(bcx: block, + did: ast::def_id, + args: &[ValueRef], + dest: expr::Dest) + -> block { let fty = if did.crate == ast::local_crate { ty::node_id_to_type(bcx.ccx().tcx, did.node) } else { @@ -349,12 +349,12 @@ pub fn trans_rtcall_or_lang_call(bcx: block, ArgVals(args), dest, DontAutorefArg); } -pub fn trans_rtcall_or_lang_call_with_type_params(bcx: block, - did: ast::def_id, - args: &[ValueRef], - type_params: ~[ty::t], - dest: expr::Dest) - -> block { +pub fn trans_lang_call_with_type_params(bcx: block, + did: ast::def_id, + args: &[ValueRef], + type_params: ~[ty::t], + dest: expr::Dest) + -> block { let fty; if did.crate == ast::local_crate { fty = ty::node_id_to_type(bcx.tcx(), did.node); diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index 1409199a0d2d7..40407fbf52baa 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -500,7 +500,7 @@ pub fn make_opaque_cbox_take_glue( // Allocate memory, update original ptr, and copy existing data let opaque_tydesc = PointerCast(bcx, tydesc, T_ptr(T_i8())); let rval = alloca(bcx, T_ptr(T_i8())); - let bcx = callee::trans_rtcall_or_lang_call( + let bcx = callee::trans_lang_call( bcx, bcx.tcx().lang_items.exchange_malloc_fn(), ~[opaque_tydesc, sz], diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index f8a7f4779764c..642de12e55275 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -442,7 +442,7 @@ pub fn add_clean_frozen_root(bcx: block, val: ValueRef, t: ty::t) { do in_scope_cx(bcx) |scope_info| { scope_info.cleanups.push( clean_temp(val, |bcx| { - let bcx = callee::trans_rtcall_or_lang_call( + let bcx = callee::trans_lang_call( bcx, bcx.tcx().lang_items.return_to_mut_fn(), ~[ diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index 57cb1a937764c..70321d50f3faa 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -216,7 +216,7 @@ pub fn trans_log(log_ex: @ast::expr, // Call the polymorphic log function let val = val_datum.to_ref_llval(bcx); let did = bcx.tcx().lang_items.log_type_fn(); - let bcx = callee::trans_rtcall_or_lang_call_with_type_params( + let bcx = callee::trans_lang_call_with_type_params( bcx, did, ~[level, val], ~[val_datum.ty], expr::Ignore); bcx } @@ -384,7 +384,7 @@ fn trans_fail_value(bcx: block, let V_str = PointerCast(bcx, V_fail_str, T_ptr(T_i8())); let V_filename = PointerCast(bcx, V_filename, T_ptr(T_i8())); let args = ~[V_str, V_filename, C_int(ccx, V_line)]; - let bcx = callee::trans_rtcall_or_lang_call( + let bcx = callee::trans_lang_call( bcx, bcx.tcx().lang_items.fail_fn(), args, expr::Ignore); Unreachable(bcx); return bcx; @@ -401,7 +401,7 @@ pub fn trans_fail_bounds_check(bcx: block, sp: span, let filename = PointerCast(bcx, filename_cstr, T_ptr(T_i8())); let args = ~[filename, line, index, len]; - let bcx = callee::trans_rtcall_or_lang_call( + let bcx = callee::trans_lang_call( bcx, bcx.tcx().lang_items.fail_bounds_check_fn(), args, expr::Ignore); Unreachable(bcx); return bcx; diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index 07499dac62e14..c93ab056de0ee 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -544,7 +544,7 @@ pub impl Datum { // If we need to freeze the box, do that now. if root_info.freezes { - callee::trans_rtcall_or_lang_call( + callee::trans_lang_call( bcx, bcx.tcx().lang_items.borrow_as_imm_fn(), ~[ @@ -566,7 +566,7 @@ pub impl Datum { ByRef => Load(bcx, self.val), }; - callee::trans_rtcall_or_lang_call( + callee::trans_lang_call( bcx, bcx.tcx().lang_items.check_not_borrowed_fn(), ~[ PointerCast(bcx, llval, T_ptr(T_i8())) ], diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index cd3a14b69e71d..bcb22022d46a3 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -30,7 +30,7 @@ use core::str; pub fn trans_free(cx: block, v: ValueRef) -> block { let _icx = cx.insn_ctxt("trans_free"); - callee::trans_rtcall_or_lang_call( + callee::trans_lang_call( cx, cx.tcx().lang_items.free_fn(), ~[PointerCast(cx, v, T_ptr(T_i8()))], @@ -39,7 +39,7 @@ pub fn trans_free(cx: block, v: ValueRef) -> block { pub fn trans_exchange_free(cx: block, v: ValueRef) -> block { let _icx = cx.insn_ctxt("trans_exchange_free"); - callee::trans_rtcall_or_lang_call( + callee::trans_lang_call( cx, cx.tcx().lang_items.exchange_free_fn(), ~[PointerCast(cx, v, T_ptr(T_i8()))], diff --git a/src/librustc/middle/trans/tvec.rs b/src/librustc/middle/trans/tvec.rs index df89647321ab4..dc004c81b1147 100644 --- a/src/librustc/middle/trans/tvec.rs +++ b/src/librustc/middle/trans/tvec.rs @@ -306,7 +306,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, let llsizeval = C_uint(bcx.ccx(), s.len()); let typ = ty::mk_estr(bcx.tcx(), ty::vstore_uniq); let lldestval = datum::scratch_datum(bcx, typ, false); - let bcx = callee::trans_rtcall_or_lang_call( + let bcx = callee::trans_lang_call( bcx, bcx.tcx().lang_items.strdup_uniq_fn(), ~[ llptrval, llsizeval ], From 4a04a188e3cf86cdef0e499dc65810009de27808 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 27 Feb 2013 18:44:35 -0800 Subject: [PATCH 57/85] Convert NOTEs to FIXMEs --- src/libcore/comm.rs | 4 ++-- src/rt/rust_upcall.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 7939644e51cb9..4e4e88162e6cc 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -20,8 +20,8 @@ use vec; use pipes::{recv, try_recv, wait_many, peek, PacketHeader}; -// NOTE Making this public exposes some plumbing from pipes. Needs -// some refactoring +// FIXME #5160: Making this public exposes some plumbing from +// pipes. Needs some refactoring pub use pipes::Selectable; /// A trait for things that can send multiple messages. diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index b0e13717b8289..9f39e1433fc63 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -120,7 +120,7 @@ upcall_fail(char const *expr, size_t line) { rust_task *task = rust_try_get_current_task(); if (task == NULL) { - // NOTE: Need to think about what to do here + // FIXME #5161: Need to think about what to do here printf("failure outside of a task"); abort(); } From 1bcd4c674c710cdd2dd9b817a2d44f021d718559 Mon Sep 17 00:00:00 2001 From: Daniel Ursache Dogariu Date: Thu, 28 Feb 2013 11:52:25 +0200 Subject: [PATCH 58/85] Add syntax highlighting support for GtkSourceView / GEdit --- src/etc/gedit/readme.txt | 11 + .../language-specs/rust.lang | 264 ++++++++++++++++++ src/etc/gedit/share/mime/packages/rust.xml | 7 + 3 files changed, 282 insertions(+) create mode 100644 src/etc/gedit/readme.txt create mode 100644 src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang create mode 100644 src/etc/gedit/share/mime/packages/rust.xml diff --git a/src/etc/gedit/readme.txt b/src/etc/gedit/readme.txt new file mode 100644 index 0000000000000..735b023627662 --- /dev/null +++ b/src/etc/gedit/readme.txt @@ -0,0 +1,11 @@ +Add syntax highlighting for Mozilla Rust in GtkSourceView (used by GEdit). + + +Instructions for Ubuntu Linux 12.04+ + +1) Close all instances of GEdit + +2) Copy the included "share" folder into "~/.local/" + +3) Open a shell in "~/.local/share/" and run "update-mime-database mime" + diff --git a/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang b/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang new file mode 100644 index 0000000000000..0b23808b76524 --- /dev/null +++ b/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang @@ -0,0 +1,264 @@ + + + + + + + text/x-rust + *.rs;*.rc + // + /* + */ + + + +