diff options
Diffstat (limited to 'src')
113 files changed, 885 insertions, 768 deletions
diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 73e1e3ee763..d58c2e596bd 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -264,7 +264,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) { fatal(~"gdb failed to execute"); } - let num_check_lines = vec::len(check_lines); + let num_check_lines = check_lines.len(); if num_check_lines > 0 { // check if each line in props.check_lines appears in the // output (in order) @@ -303,7 +303,7 @@ fn check_error_patterns(props: &TestProps, if str::contains(line, *next_err_pat) { debug!("found error pattern %s", *next_err_pat); next_err_idx += 1u; - if next_err_idx == vec::len(props.error_patterns) { + if next_err_idx == props.error_patterns.len() { debug!("found all error patterns"); done = true; break; @@ -315,8 +315,8 @@ fn check_error_patterns(props: &TestProps, let missing_patterns = vec::slice(props.error_patterns, next_err_idx, - vec::len(props.error_patterns)); - if vec::len(missing_patterns) == 1u { + props.error_patterns.len()); + if missing_patterns.len() == 1u { fatal_ProcRes(fmt!("error pattern '%s' not found!", missing_patterns[0]), ProcRes); } else { @@ -333,7 +333,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError], // true if we found the error in question let mut found_flags = vec::from_elem( - vec::len(expected_errors), false); + expected_errors.len(), false); if ProcRes.status == 0 { fatal(~"process did not return an error status"); @@ -377,7 +377,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError], } } - for uint::range(0u, vec::len(found_flags)) |i| { + for uint::range(0u, found_flags.len()) |i| { if !found_flags[i] { let ee = &expected_errors[i]; fatal_ProcRes(fmt!("expected %s on line %u not found: %s", diff --git a/src/libcore/either.rs b/src/libcore/either.rs index 618a484a515..8c16f5c6482 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -201,14 +201,14 @@ fn test_lefts() { fn test_lefts_none() { let input: ~[Either<int, int>] = ~[Right(10), Right(10)]; let result = lefts(input); - assert_eq!(vec::len(result), 0u); + assert_eq!(result.len(), 0u); } #[test] fn test_lefts_empty() { let input: ~[Either<int, int>] = ~[]; let result = lefts(input); - assert_eq!(vec::len(result), 0u); + assert_eq!(result.len(), 0u); } #[test] @@ -222,14 +222,14 @@ fn test_rights() { fn test_rights_none() { let input: ~[Either<int, int>] = ~[Left(10), Left(10)]; let result = rights(input); - assert_eq!(vec::len(result), 0u); + assert_eq!(result.len(), 0u); } #[test] fn test_rights_empty() { let input: ~[Either<int, int>] = ~[]; let result = rights(input); - assert_eq!(vec::len(result), 0u); + assert_eq!(result.len(), 0u); } #[test] @@ -247,22 +247,22 @@ fn test_partition() { fn test_partition_no_lefts() { let input: ~[Either<int, int>] = ~[Right(10), Right(11)]; let (lefts, rights) = partition(input); - assert_eq!(vec::len(lefts), 0u); - assert_eq!(vec::len(rights), 2u); + assert_eq!(lefts.len(), 0u); + assert_eq!(rights.len(), 2u); } #[test] fn test_partition_no_rights() { let input: ~[Either<int, int>] = ~[Left(10), Left(11)]; let (lefts, rights) = partition(input); - assert_eq!(vec::len(lefts), 2u); - assert_eq!(vec::len(rights), 0u); + assert_eq!(lefts.len(), 2u); + assert_eq!(rights.len(), 0u); } #[test] fn test_partition_empty() { let input: ~[Either<int, int>] = ~[]; let (lefts, rights) = partition(input); - assert_eq!(vec::len(lefts), 0u); - assert_eq!(vec::len(rights), 0u); + assert_eq!(lefts.len(), 0u); + assert_eq!(rights.len(), 0u); } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index ab5db67ddb6..7b7d278380f 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -673,10 +673,10 @@ impl<T:Reader> ReaderUtil for T { fn read_char(&self) -> char { let c = self.read_chars(1); - if vec::len(c) == 0 { + if c.len() == 0 { return -1 as char; // FIXME will this stay valid? // #2004 } - assert!((vec::len(c) == 1)); + assert!(c.len() == 1); return c[0]; } @@ -1802,7 +1802,7 @@ mod tests { fn test_readchars_empty() { do io::with_str_reader(~"") |inp| { let res : ~[char] = inp.read_chars(128); - assert!((vec::len(res) == 0)); + assert!(res.len() == 0); } } @@ -1841,10 +1841,10 @@ mod tests { fn check_read_ln(len : uint, s: &str, ivals: &[int]) { do io::with_str_reader(s) |inp| { let res : ~[char] = inp.read_chars(len); - if (len <= vec::len(ivals)) { - assert!((vec::len(res) == len)); + if len <= ivals.len() { + assert!(res.len() == len); } - assert!(vec::slice(ivals, 0u, vec::len(res)) == + assert!(vec::slice(ivals, 0u, res.len()) == vec::map(res, |x| *x as int)); } } diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 9129b33fff5..daad9cee0fc 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -410,7 +410,7 @@ pub fn self_exe_path() -> Option<Path> { KERN_PROC as c_int, KERN_PROC_PATHNAME as c_int, -1 as c_int]; let mut sz = sz; - sysctl(vec::raw::to_ptr(mib), vec::len(mib) as ::libc::c_uint, + sysctl(vec::raw::to_ptr(mib), mib.len() as ::libc::c_uint, buf as *mut c_void, &mut sz, ptr::null(), 0u as size_t) == (0 as c_int) } @@ -1490,7 +1490,7 @@ mod tests { #[ignore] fn test_env_getenv() { let e = env(); - assert!(vec::len(e) > 0u); + assert!(e.len() > 0u); for e.each |p| { let (n, v) = copy *p; debug!(copy n); @@ -1581,7 +1581,7 @@ mod tests { fn list_dir() { let dirs = os::list_dir(&Path(".")); // Just assuming that we've got some contents in the current directory - assert!((vec::len(dirs) > 0u)); + assert!(dirs.len() > 0u); for dirs.each |dir| { debug!(copy *dir); diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 9feb8676036..e116dc01943 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -441,7 +441,7 @@ pub mod ptr_tests { let arr_ptr = &arr[0]; let mut ctr = 0; let mut iteration_count = 0; - array_each_with_len(arr_ptr, vec::len(arr), + array_each_with_len(arr_ptr, arr.len(), |e| { let actual = str::raw::from_c_str(e); let expected = copy expected_arr[ctr]; diff --git a/src/libcore/rt/uvll.rs b/src/libcore/rt/uvll.rs index 4bff3bff7d3..0d298bde6b5 100644 --- a/src/libcore/rt/uvll.rs +++ b/src/libcore/rt/uvll.rs @@ -221,7 +221,7 @@ pub unsafe fn accept(server: *c_void, client: *c_void) -> c_int { pub unsafe fn write<T>(req: *uv_write_t, stream: *T, buf_in: &[uv_buf_t], cb: *u8) -> c_int { let buf_ptr = vec::raw::to_ptr(buf_in); - let buf_cnt = vec::len(buf_in) as i32; + let buf_cnt = buf_in.len() as i32; return rust_uv_write(req as *c_void, stream as *c_void, buf_ptr, buf_cnt, cb); } pub unsafe fn read_start(stream: *uv_stream_t, on_alloc: *u8, on_read: *u8) -> c_int { diff --git a/src/libcore/str.rs b/src/libcore/str.rs index ce9db796b67..ec7177e5211 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -2059,7 +2059,7 @@ pub fn is_utf8(v: &const [u8]) -> bool { /// Determines if a vector of `u16` contains valid UTF-16 pub fn is_utf16(v: &[u16]) -> bool { - let len = vec::len(v); + let len = v.len(); let mut i = 0u; while (i < len) { let u = v[i]; @@ -2103,7 +2103,7 @@ pub fn to_utf16(s: &str) -> ~[u16] { } pub fn utf16_chars(v: &[u16], f: &fn(char)) { - let len = vec::len(v); + let len = v.len(); let mut i = 0u; while (i < len && v[i] != 0u16) { let u = v[i]; @@ -2128,7 +2128,7 @@ pub fn utf16_chars(v: &[u16], f: &fn(char)) { pub fn from_utf16(v: &[u16]) -> ~str { let mut buf = ~""; - reserve(&mut buf, vec::len(v)); + reserve(&mut buf, v.len()); utf16_chars(v, |ch| push_char(&mut buf, ch)); buf } @@ -2398,7 +2398,7 @@ static tag_six_b: uint = 252u; * # Example * * ~~~ - * let i = str::as_bytes("Hello World") { |bytes| vec::len(bytes) }; + * let i = str::as_bytes("Hello World") { |bytes| bytes.len() }; * ~~~ */ #[inline] diff --git a/src/libcore/to_bytes.rs b/src/libcore/to_bytes.rs index 6cc621e3419..ad42881ffa0 100644 --- a/src/libcore/to_bytes.rs +++ b/src/libcore/to_bytes.rs @@ -458,6 +458,7 @@ pub fn iter_bytes_2<A:IterBytes,B:IterBytes>(a: &A, b: &B, b.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); } #[cfg(not(stage0))] +#[inline(always)] pub fn iter_bytes_2<A:IterBytes,B:IterBytes>(a: &A, b: &B, lsb0: bool, z: Cb) -> bool { a.iter_bytes(lsb0, z) && b.iter_bytes(lsb0, z) diff --git a/src/libfuzzer/ast_match.rs b/src/libfuzzer/ast_match.rs index 806a7aedd31..2502830250d 100644 --- a/src/libfuzzer/ast_match.rs +++ b/src/libfuzzer/ast_match.rs @@ -15,8 +15,8 @@ fn vec_equal<T>(v: ~[T], u: ~[T], element_equality_test: @fn(&&T, &&T) -> bool) -> bool { - let Lv = vec::len(v); - if Lv != vec::len(u) { return false; } + let Lv = v.len(); + if Lv != u.len() { return false; } let i = 0u; while i < Lv { if !element_equality_test(v[i], u[i]) { return false; } diff --git a/src/libfuzzer/cycles.rs b/src/libfuzzer/cycles.rs index c18d1f43b56..a6434d64cdc 100644 --- a/src/libfuzzer/cycles.rs +++ b/src/libfuzzer/cycles.rs @@ -19,7 +19,7 @@ fn under(r : rand::rng, n : uint) -> uint { // random choice from a vec fn choice<T:copy>(r : rand::rng, v : ~[const T]) -> T { - assert!(vec::len(v) != 0u); v[under(r, vec::len(v))] + assert!(v.len() != 0u); v[under(r, v.len())] } // k in n chance of being true diff --git a/src/libfuzzer/rand_util.rs b/src/libfuzzer/rand_util.rs index 2422c146e24..c239e8ab933 100644 --- a/src/libfuzzer/rand_util.rs +++ b/src/libfuzzer/rand_util.rs @@ -18,7 +18,7 @@ fn under(r : rand::rng, n : uint) -> uint { // random choice from a vec fn choice<T:copy>(r : rand::rng, v : ~[T]) -> T { - assert!(vec::len(v) != 0u); v[under(r, vec::len(v))] + assert!(v.len() != 0u); v[under(r, v.len())] } // 1 in n chance of being true @@ -26,7 +26,7 @@ fn unlikely(r : rand::rng, n : uint) -> bool { under(r, n) == 0u } // shuffle a vec in place fn shuffle<T>(r : rand::rng, &v : ~[T]) { - let i = vec::len(v); + let i = v.len(); while i >= 2u { // Loop invariant: elements with index >= i have been locked in place. i -= 1u; @@ -49,7 +49,7 @@ fn shuffled<T:copy>(r : rand::rng, v : ~[T]) -> ~[T] { // * weighted_vec is O(total weight) space type weighted<T> = { weight: uint, item: T }; fn weighted_choice<T:copy>(r : rand::rng, v : ~[weighted<T>]) -> T { - assert!(vec::len(v) != 0u); + assert!(v.len() != 0u); let total = 0u; for {weight: weight, item: _} in v { total += weight; diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index eebb20b19f5..37a025cd820 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -137,8 +137,8 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path { abs1.to_str(), abs2.to_str()); let split1: &[~str] = abs1.components; let split2: &[~str] = abs2.components; - let len1 = vec::len(split1); - let len2 = vec::len(split2); + let len1 = split1.len(); + let len2 = split2.len(); assert!(len1 > 0); assert!(len2 > 0); diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index b11aec5b841..0e37653e5c4 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -905,7 +905,6 @@ mod test { use driver::driver::{build_configuration, build_session}; use driver::driver::{build_session_options, optgroups, str_input}; - use core::vec; use std::getopts::groups::getopts; use std::getopts; use syntax::attr; @@ -942,6 +941,6 @@ mod test { let sess = build_session(sessopts, diagnostic::emit); let cfg = build_configuration(sess, @~"whatever", &str_input(~"")); let test_items = attr::find_meta_items_by_name(cfg, ~"test"); - assert!((vec::len(test_items) == 1u)); + assert!(test_items.len() == 1u); } } diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index f556baee918..be03ed99ad7 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -206,7 +206,7 @@ fn is_bench_fn(i: @ast::item) -> bool { fn has_test_signature(i: @ast::item) -> bool { match i.node { ast::item_fn(ref decl, _, _, ref generics, _) => { - let input_cnt = vec::len(decl.inputs); + let input_cnt = decl.inputs.len(); let no_output = match decl.output.node { ast::ty_nil => true, _ => false diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index d2b71447f47..9426cd6041d 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -100,7 +100,7 @@ pub static tag_mod_impl_trait: uint = 0x47u; different tags. */ pub static tag_item_impl_method: uint = 0x48u; -pub static tag_item_trait_method_self_ty: uint = 0x4b; +pub static tag_item_trait_method_explicit_self: uint = 0x4b; pub static tag_item_trait_method_self_ty_region: uint = 0x4c; diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index d8117a87480..e6b8432854d 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -22,7 +22,7 @@ use syntax::ast_map; use syntax::diagnostic::expect; pub struct ProvidedTraitMethodInfo { - ty: ty::method, + ty: ty::Method, def_id: ast::def_id } @@ -129,17 +129,18 @@ pub fn get_impls_for_mod(cstore: @mut cstore::CStore, def: ast::def_id, } pub fn get_method(tcx: ty::ctxt, - def: ast::def_id) -> ty::method + def: ast::def_id) -> ty::Method { let cdata = cstore::get_crate_data(tcx.cstore, def.crate); decoder::get_method(tcx.cstore.intr, cdata, def.node, tcx) } -pub fn get_method_name_and_self_ty(cstore: @mut cstore::CStore, - def: ast::def_id) -> (ast::ident, ast::self_ty_) +pub fn get_method_name_and_explicit_self(cstore: @mut cstore::CStore, + def: ast::def_id) + -> (ast::ident, ast::explicit_self_) { let cdata = cstore::get_crate_data(cstore, def.crate); - decoder::get_method_name_and_self_ty(cstore.intr, cdata, def.node) + decoder::get_method_name_and_explicit_self(cstore.intr, cdata, def.node) } pub fn get_trait_method_def_ids(cstore: @mut cstore::CStore, diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index c3dd9cdf23b..2592875cd57 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -653,7 +653,7 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id, item, tcx, cdata); let name = item_name(intr, item); let arg_tys = match ty::get(ctor_ty).sty { - ty::ty_bare_fn(ref f) => f.sig.inputs.map(|a| a.ty), + ty::ty_bare_fn(ref f) => copy f.sig.inputs, _ => ~[], // Nullary enum variant. }; match variant_disr_val(item) { @@ -670,7 +670,7 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id, return infos; } -fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ { +fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ { fn get_mutability(ch: u8) -> ast::mutability { match ch as char { 'i' => { ast::m_imm } @@ -682,11 +682,11 @@ fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ { } } - let self_type_doc = reader::get_doc(item, tag_item_trait_method_self_ty); - let string = reader::doc_as_str(self_type_doc); + let explicit_self_doc = reader::get_doc(item, tag_item_trait_method_explicit_self); + let string = reader::doc_as_str(explicit_self_doc); - let self_ty_kind = string[0]; - match self_ty_kind as char { + let explicit_self_kind = string[0]; + match explicit_self_kind as char { 's' => { return ast::sty_static; } 'v' => { return ast::sty_value; } '@' => { return ast::sty_box(get_mutability(string[1])); } @@ -696,7 +696,7 @@ fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ { return ast::sty_region(None, get_mutability(string[1])); } _ => { - fail!("unknown self type code: `%c`", self_ty_kind as char); + fail!("unknown self type code: `%c`", explicit_self_kind as char); } } } @@ -707,12 +707,12 @@ fn item_impl_methods(intr: @ident_interner, cdata: cmd, item: ebml::Doc, for reader::tagged_docs(item, tag_item_impl_method) |doc| { let m_did = reader::with_doc_data(doc, |d| parse_def_id(d)); let mth_item = lookup_item(m_did.node, cdata.data); - let self_ty = get_self_ty(mth_item); + let explicit_self = get_explicit_self(mth_item); rslt.push(@resolve::MethodInfo { did: translate_def_id(cdata, m_did), n_tps: item_ty_param_count(mth_item) - base_tps, ident: item_name(intr, mth_item), - self_type: self_ty}); + explicit_self: explicit_self}); } rslt } @@ -748,19 +748,19 @@ pub fn get_impls_for_mod(intr: @ident_interner, @result } -pub fn get_method_name_and_self_ty( +pub fn get_method_name_and_explicit_self( intr: @ident_interner, cdata: cmd, - id: ast::node_id) -> (ast::ident, ast::self_ty_) + id: ast::node_id) -> (ast::ident, ast::explicit_self_) { let method_doc = lookup_item(id, cdata.data); let name = item_name(intr, method_doc); - let self_ty = get_self_ty(method_doc); - (name, self_ty) + let explicit_self = get_explicit_self(method_doc); + (name, explicit_self) } pub fn get_method(intr: @ident_interner, cdata: cmd, id: ast::node_id, - tcx: ty::ctxt) -> ty::method + tcx: ty::ctxt) -> ty::Method { let method_doc = lookup_item(id, cdata.data); let def_id = item_def_id(method_doc, cdata); @@ -770,19 +770,20 @@ pub fn get_method(intr: @ident_interner, cdata: cmd, id: ast::node_id, let transformed_self_ty = doc_transformed_self_ty(method_doc, tcx, cdata); let fty = doc_method_fty(method_doc, tcx, cdata); let vis = item_visibility(method_doc); - let self_ty = get_self_ty(method_doc); - ty::method { - ident: name, - generics: ty::Generics { + let explicit_self = get_explicit_self(method_doc); + + ty::Method::new( + name, + ty::Generics { type_param_defs: type_param_defs, region_param: None }, - transformed_self_ty: transformed_self_ty, - fty: fty, - self_ty: self_ty, - vis: vis, - def_id: def_id - } + transformed_self_ty, + fty, + explicit_self, + vis, + def_id + ) } pub fn get_trait_method_def_ids(cdata: cmd, @@ -823,19 +824,20 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd, }; let transformed_self_ty = doc_transformed_self_ty(mth, tcx, cdata); - let self_ty = get_self_ty(mth); - let ty_method = ty::method { - ident: name, - generics: ty::Generics { + let explicit_self = get_explicit_self(mth); + + let ty_method = ty::Method::new( + name, + ty::Generics { type_param_defs: type_param_defs, region_param: None }, - transformed_self_ty: transformed_self_ty, - fty: fty, - self_ty: self_ty, - vis: ast::public, - def_id: did - }; + transformed_self_ty, + fty, + explicit_self, + ast::public, + did + ); let provided_trait_method_info = ProvidedTraitMethodInfo { ty: ty_method, def_id: did @@ -1061,7 +1063,7 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] { let meta_items = get_meta_items(attr_doc); // Currently it's only possible to have a single meta item on // an attribute - assert!((vec::len(meta_items) == 1u)); + assert!(meta_items.len() == 1u); let meta_item = meta_items[0]; attrs.push( codemap::spanned { diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index def24e5bc89..d27bfd081bc 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -366,7 +366,7 @@ fn encode_path(ecx: @EncodeContext, fn encode_reexported_static_method(ecx: @EncodeContext, ebml_w: &mut writer::Encoder, exp: &middle::resolve::Export2, - m: @ty::method) { + m: @ty::Method) { debug!("(encode static trait method) reexport '%s::%s'", *exp.name, *ecx.tcx.sess.str_of(m.ident)); ebml_w.start_tag(tag_items_data_item_reexport); @@ -389,7 +389,7 @@ fn encode_reexported_static_methods(ecx: @EncodeContext, Some(&ast_map::node_item(_, path)) => { if mod_path != *path { for methods.each |&m| { - if m.self_ty == ast::sty_static { + if m.explicit_self == ast::sty_static { encode_reexported_static_method(ecx, ebml_w, exp, m); @@ -486,11 +486,11 @@ fn encode_visibility(ebml_w: &mut writer::Encoder, visibility: visibility) { ebml_w.end_tag(); } -fn encode_self_type(ebml_w: &mut writer::Encoder, self_type: ast::self_ty_) { - ebml_w.start_tag(tag_item_trait_method_self_ty); +fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::explicit_self_) { + ebml_w.start_tag(tag_item_trait_method_explicit_self); // Encode the base self type. - match self_type { + match explicit_self { sty_static => { ebml_w.writer.write(&[ 's' as u8 ]); } @@ -625,7 +625,7 @@ fn encode_info_for_struct_ctor(ecx: @EncodeContext, fn encode_method_ty_fields(ecx: @EncodeContext, ebml_w: &mut writer::Encoder, - method_ty: &ty::method) { + method_ty: &ty::Method) { encode_def_id(ebml_w, method_ty.def_id); encode_name(ecx, ebml_w, method_ty.ident); encode_ty_type_param_defs(ebml_w, ecx, @@ -634,7 +634,7 @@ fn encode_method_ty_fields(ecx: @EncodeContext, encode_transformed_self_ty(ecx, ebml_w, method_ty.transformed_self_ty); encode_method_fty(ecx, ebml_w, &method_ty.fty); encode_visibility(ebml_w, method_ty.vis); - encode_self_type(ebml_w, method_ty.self_ty); + encode_explicit_self(ebml_w, method_ty.explicit_self); } fn encode_info_for_method(ecx: @EncodeContext, @@ -652,10 +652,10 @@ fn encode_info_for_method(ecx: @EncodeContext, ebml_w.start_tag(tag_items_data_item); let method_def_id = local_def(m.id); - let method_ty: @ty::method = ty::method(ecx.tcx, method_def_id); + let method_ty = ty::method(ecx.tcx, method_def_id); encode_method_ty_fields(ecx, ebml_w, method_ty); - match m.self_ty.node { + match m.explicit_self.node { ast::sty_static => { encode_family(ebml_w, purity_static_method_family(m.purity)); } @@ -948,7 +948,7 @@ fn encode_info_for_item(ecx: @EncodeContext, for ty::trait_method_def_ids(tcx, local_def(item.id)).eachi |i, &method_def_id| { assert!(method_def_id.crate == ast::local_crate); - let method_ty: @ty::method = ty::method(tcx, method_def_id); + let method_ty = ty::method(tcx, method_def_id); index.push(entry {val: method_def_id.node, pos: ebml_w.writer.tell()}); @@ -962,7 +962,7 @@ fn encode_info_for_item(ecx: @EncodeContext, trait_path.push(ast_map::path_name(item.ident)); encode_path(ecx, ebml_w, trait_path, ast_map::path_name(method_ty.ident)); - match method_ty.self_ty { + match method_ty.explicit_self { sty_static => { encode_family(ebml_w, purity_static_method_family( @@ -991,7 +991,7 @@ fn encode_info_for_item(ecx: @EncodeContext, // This is obviously a bogus assert but I don't think this // ever worked before anyhow...near as I can tell, before // we would emit two items. - if method_ty.self_ty == sty_static { + if method_ty.explicit_self == sty_static { tcx.sess.span_unimpl( item.span, fmt!("Method %s is both provided and static", diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index ba2e336b639..cfb2bd4b837 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -171,7 +171,7 @@ pub fn metadata_matches(extern_metas: &[@ast::meta_item], local_metas: &[@ast::meta_item]) -> bool { debug!("matching %u metadata requirements against %u items", - vec::len(local_metas), vec::len(extern_metas)); + local_metas.len(), extern_metas.len()); for local_metas.each |needed| { if !attr::contains(extern_metas, *needed) { diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index cc9a18ea3a3..151ccad88ea 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -126,12 +126,6 @@ pub fn parse_trait_ref_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ct parse_trait_ref(st, conv) } -pub fn parse_arg_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ctxt, - conv: conv_did) -> ty::arg { - let st = parse_state_from_data(data, crate_num, pos, tcx); - parse_arg(st, conv) -} - fn parse_path(st: @mut PState) -> @ast::Path { let mut idents: ~[ast::ident] = ~[]; fn is_last(c: char) -> bool { return c == '(' || c == ':'; } @@ -471,12 +465,6 @@ fn parse_onceness(c: char) -> ast::Onceness { } } -fn parse_arg(st: @mut PState, conv: conv_did) -> ty::arg { - ty::arg { - ty: parse_ty(st, conv) - } -} - fn parse_closure_ty(st: @mut PState, conv: conv_did) -> ty::ClosureTy { let sigil = parse_sigil(st); let purity = parse_purity(next(st)); @@ -505,9 +493,9 @@ fn parse_bare_fn_ty(st: @mut PState, conv: conv_did) -> ty::BareFnTy { fn parse_sig(st: @mut PState, conv: conv_did) -> ty::FnSig { assert!((next(st) == '[')); - let mut inputs: ~[ty::arg] = ~[]; + let mut inputs = ~[]; while peek(st) != ']' { - inputs.push(ty::arg { ty: parse_ty(st, conv) }); + inputs.push(parse_ty(st, conv)); } st.pos += 1u; // eat the ']' let ret_ty = parse_ty(st, conv); @@ -519,7 +507,7 @@ fn parse_sig(st: @mut PState, conv: conv_did) -> ty::FnSig { // Rust metadata parsing pub fn parse_def_id(buf: &[u8]) -> ast::def_id { let mut colon_idx = 0u; - let len = vec::len(buf); + let len = buf.len(); while colon_idx < len && buf[colon_idx] != ':' as u8 { colon_idx += 1u; } if colon_idx == len { error!("didn't find ':' when parsing def id"); diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index e1b3230b0ff..2cb95e1a2fc 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -344,10 +344,6 @@ fn enc_sigil(w: @io::Writer, sigil: Sigil) { } } -pub fn enc_arg(w: @io::Writer, cx: @ctxt, arg: ty::arg) { - enc_ty(w, cx, arg.ty); -} - fn enc_purity(w: @io::Writer, p: purity) { match p { pure_fn => w.write_char('p'), @@ -389,8 +385,8 @@ fn enc_closure_ty(w: @io::Writer, cx: @ctxt, ft: &ty::ClosureTy) { fn enc_fn_sig(w: @io::Writer, cx: @ctxt, fsig: &ty::FnSig) { w.write_char('['); - for fsig.inputs.each |arg| { - enc_arg(w, cx, *arg); + for fsig.inputs.each |ty| { + enc_ty(w, cx, *ty); } w.write_char(']'); enc_ty(w, cx, fsig.output); diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 20a56ab0ee9..2996c4c8476 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -526,8 +526,8 @@ fn encode_method_map_entry(ecx: @e::EncodeContext, ebml_w: &mut writer::Encoder, mme: method_map_entry) { do ebml_w.emit_struct("method_map_entry", 3) |ebml_w| { - do ebml_w.emit_struct_field("self_arg", 0u) |ebml_w| { - ebml_w.emit_arg(ecx, mme.self_arg); + do ebml_w.emit_struct_field("self_ty", 0u) |ebml_w| { + ebml_w.emit_ty(ecx, mme.self_ty); } do ebml_w.emit_struct_field("explicit_self", 2u) |ebml_w| { mme.explicit_self.encode(ebml_w); @@ -546,14 +546,14 @@ impl read_method_map_entry_helper for reader::Decoder { -> method_map_entry { do self.read_struct("method_map_entry", 3) |this| { method_map_entry { - self_arg: this.read_struct_field("self_arg", 0, |this| { - this.read_arg(xcx) + self_ty: this.read_struct_field("self_ty", 0u, |this| { + this.read_ty(xcx) }), explicit_self: this.read_struct_field("explicit_self", 2, |this| { - let self_type: ast::self_ty_ = Decodable::decode(this); - self_type + let explicit_self: ast::explicit_self_ = Decodable::decode(this); + explicit_self }), origin: this.read_struct_field("origin", 1, |this| { let method_origin: method_origin = @@ -712,7 +712,6 @@ impl get_ty_str_ctxt for e::EncodeContext { } trait ebml_writer_helpers { - fn emit_arg(&mut self, ecx: @e::EncodeContext, arg: ty::arg); fn emit_ty(&mut self, ecx: @e::EncodeContext, ty: ty::t); fn emit_vstore(&mut self, ecx: @e::EncodeContext, vstore: ty::vstore); fn emit_tys(&mut self, ecx: @e::EncodeContext, tys: &[ty::t]); @@ -737,12 +736,6 @@ impl ebml_writer_helpers for writer::Encoder { } } - fn emit_arg(&mut self, ecx: @e::EncodeContext, arg: ty::arg) { - do self.emit_opaque |this| { - tyencode::enc_arg(this.writer, ecx.ty_str_ctxt(), arg); - } - } - fn emit_tys(&mut self, ecx: @e::EncodeContext, tys: &[ty::t]) { do self.emit_from_vec(tys) |this, ty| { this.emit_ty(ecx, *ty) @@ -943,7 +936,6 @@ impl doc_decoder_helpers for ebml::Doc { } trait ebml_decoder_decoder_helpers { - fn read_arg(&mut self, xcx: @ExtendedDecodeContext) -> ty::arg; fn read_ty(&mut self, xcx: @ExtendedDecodeContext) -> ty::t; fn read_tys(&mut self, xcx: @ExtendedDecodeContext) -> ~[ty::t]; fn read_type_param_def(&mut self, xcx: @ExtendedDecodeContext) @@ -958,17 +950,6 @@ trait ebml_decoder_decoder_helpers { } impl ebml_decoder_decoder_helpers for reader::Decoder { - fn read_arg(&mut self, xcx: @ExtendedDecodeContext) -> ty::arg { - do self.read_opaque |this, doc| { - tydecode::parse_arg_data( - doc.data, - xcx.dcx.cdata.cnum, - doc.start, - xcx.dcx.tcx, - |s, a| this.convert_def_id(xcx, s, a)) - } - } - fn read_ty(&mut self, xcx: @ExtendedDecodeContext) -> ty::t { // Note: regions types embed local node ids. In principle, we // should translate these node ids into the new decode diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index b220379e330..a891e8d3b7f 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -360,7 +360,7 @@ fn is_nullary_variant(cx: Context, ex: @expr) -> bool { expr_path(_) => { match cx.tcx.def_map.get_copy(&ex.id) { def_variant(edid, vdid) => { - vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u + vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u } _ => false } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 171048eac55..9995de24e8d 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -381,7 +381,7 @@ fn visit_fn(fk: &visit::fn_kind, // Add `this`, whether explicit or implicit. match *fk { fk_method(_, _, method) => { - match method.self_ty.node { + match method.explicit_self.node { sty_value | sty_region(*) | sty_box(_) | sty_uniq(_) => { fn_maps.add_variable(Arg(method.self_id, special_idents::self_)); diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 2c62130feb1..27b62738793 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -283,8 +283,8 @@ pub impl RegionMaps { let a_ancestors = ancestors_of(self, scope_a); let b_ancestors = ancestors_of(self, scope_b); - let mut a_index = vec::len(a_ancestors) - 1u; - let mut b_index = vec::len(b_ancestors) - 1u; + let mut a_index = a_ancestors.len() - 1u; + let mut b_index = b_ancestors.len() - 1u; // Here, ~[ab]_ancestors is a vector going from narrow to broad. // The end of each vector will be the item where the scope is diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index a962ea07c54..9b864bd0ef2 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -10,7 +10,7 @@ use driver::session::Session; use metadata::csearch::{each_path, get_trait_method_def_ids}; -use metadata::csearch::get_method_name_and_self_ty; +use metadata::csearch::get_method_name_and_explicit_self; use metadata::csearch::get_static_methods_if_impl; use metadata::csearch::get_type_name_if_impl; use metadata::cstore::find_extern_mod_stmt_cnum; @@ -28,7 +28,7 @@ use syntax::ast::{def_const, def_foreign_mod, def_fn, def_id, def_label}; use syntax::ast::{def_local, def_mod, def_prim_ty, def_region, def_self}; use syntax::ast::{def_self_ty, def_static_method, def_struct, def_ty}; use syntax::ast::{def_ty_param, def_typaram_binder, def_trait}; -use syntax::ast::{def_upvar, def_use, def_variant, expr, expr_assign_op}; +use syntax::ast::{def_upvar, def_use, def_variant, explicit_self_, expr, expr_assign_op}; use syntax::ast::{expr_binary, expr_break, expr_field}; use syntax::ast::{expr_fn_block, expr_index, expr_method_call, expr_path}; use syntax::ast::{def_prim_ty, def_region, def_self, def_ty, def_ty_param}; @@ -45,7 +45,7 @@ use syntax::ast::{local, local_crate, lt, method, mul}; use syntax::ast::{named_field, ne, neg, node_id, pat, pat_enum, pat_ident}; use syntax::ast::{Path, pat_lit, pat_range, pat_struct}; use syntax::ast::{prim_ty, private, provided}; -use syntax::ast::{public, required, rem, self_ty_, shl, shr, stmt_decl}; +use syntax::ast::{public, required, rem, shl, shr, stmt_decl}; use syntax::ast::{struct_field, struct_variant_kind}; 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}; @@ -96,7 +96,7 @@ pub struct MethodInfo { did: def_id, n_tps: uint, ident: ident, - self_type: self_ty_ + explicit_self: explicit_self_ } pub struct Impl { @@ -1203,7 +1203,7 @@ pub impl Resolver { // Bail out early if there are no static methods. let mut has_static_methods = false; for methods.each |method| { - match method.self_ty.node { + match method.explicit_self.node { sty_static => has_static_methods = true, _ => {} } @@ -1236,7 +1236,7 @@ pub impl Resolver { // For each static method... for methods.each |method| { - match method.self_ty.node { + match method.explicit_self.node { sty_static => { // Add the static method to the // module. @@ -1274,7 +1274,7 @@ pub impl Resolver { let mut has_static_methods = false; for (*methods).each |method| { let ty_m = trait_method_to_ty_method(method); - match ty_m.self_ty.node { + match ty_m.explicit_self.node { sty_static => { has_static_methods = true; break; @@ -1306,7 +1306,7 @@ pub impl Resolver { let ident = ty_m.ident; // Add it to the trait info if not static, // add it as a name in the trait module otherwise. - match ty_m.self_ty.node { + match ty_m.explicit_self.node { sty_static => { let def = def_static_method( local_def(ty_m.id), @@ -1612,9 +1612,9 @@ pub impl Resolver { def_id); let mut interned_method_names = HashSet::new(); for method_def_ids.each |&method_def_id| { - let (method_name, self_ty) = - get_method_name_and_self_ty(self.session.cstore, - method_def_id); + let (method_name, explicit_self) = + get_method_name_and_explicit_self(self.session.cstore, + method_def_id); debug!("(building reduced graph for \ external crate) ... adding \ @@ -1622,7 +1622,7 @@ pub impl Resolver { *self.session.str_of(method_name)); // Add it to the trait info if not static. - if self_ty != sty_static { + if explicit_self != sty_static { interned_method_names.insert(method_name); } } @@ -2058,7 +2058,8 @@ pub impl Resolver { self.resolve_single_import(module_, containing_module, target, - source); + source, + import_directive.span); } GlobImport => { let span = import_directive.span; @@ -2121,7 +2122,8 @@ pub impl Resolver { module_: @mut Module, containing_module: @mut Module, target: ident, - source: ident) + source: ident, + span: span) -> ResolveResult<()> { debug!("(resolving single import) resolving `%s` = `%s::%s` from \ `%s`", @@ -2325,14 +2327,14 @@ pub impl Resolver { } if resolve_fail { - self.session.err(fmt!("unresolved import: there is no `%s` in `%s`", - *self.session.str_of(source), - self.module_to_str(containing_module))); + self.session.span_err(span, fmt!("unresolved import: there is no `%s` in `%s`", + *self.session.str_of(source), + self.module_to_str(containing_module))); return Failed; } else if priv_fail { - self.session.err(fmt!("unresolved import: found `%s` in `%s` but it is private", - *self.session.str_of(source), - self.module_to_str(containing_module))); + self.session.span_err(span, fmt!("unresolved import: found `%s` in `%s` but it is \ + private", *self.session.str_of(source), + self.module_to_str(containing_module))); return Failed; } @@ -2593,7 +2595,18 @@ pub impl Resolver { let start_index; match module_prefix_result { Failed => { - self.session.span_err(span, ~"unresolved name"); + let mpath = self.idents_to_str(module_path); + match str::rfind(self.idents_to_str(module_path), |c| { c == ':' }) { + Some(idx) => { + self.session.span_err(span, fmt!("unresolved import: could not find `%s` \ + in `%s`", str::substr(mpath, idx, + mpath.len() - idx), + // idx - 1 to account for the extra + // colon + str::substr(mpath, 0, idx - 1))); + }, + None => (), + }; return Failed; } Indeterminate => { @@ -3774,7 +3787,7 @@ pub impl Resolver { outer_type_parameter_count, rib_kind); // we only have self ty if it is a non static method - let self_binding = match method.self_ty.node { + let self_binding = match method.explicit_self.node { sty_static => { NoSelfBinding } _ => { HasSelfBinding(method.self_id, false) } }; @@ -4693,7 +4706,7 @@ pub impl Resolver { } } - if vec::len(values) > 0 && + if values.len() > 0 && values[smallest] != uint::max_value && values[smallest] < str::len(name) + 2 && values[smallest] <= max_distance && diff --git a/src/librustc/middle/resolve_stage0.rs b/src/librustc/middle/resolve_stage0.rs index 2fc0fdca317..a404dcf7249 100644 --- a/src/librustc/middle/resolve_stage0.rs +++ b/src/librustc/middle/resolve_stage0.rs @@ -11,7 +11,7 @@ use driver::session; use driver::session::Session; use metadata::csearch::{each_path, get_trait_method_def_ids}; -use metadata::csearch::get_method_name_and_self_ty; +use metadata::csearch::get_method_name_and_explicit_self; use metadata::csearch::get_static_methods_if_impl; use metadata::csearch::get_type_name_if_impl; use metadata::cstore::find_extern_mod_stmt_cnum; @@ -46,7 +46,7 @@ use syntax::ast::{local, local_crate, lt, method, mul}; use syntax::ast::{named_field, ne, neg, node_id, pat, pat_enum, pat_ident}; use syntax::ast::{Path, pat_lit, pat_range, pat_struct}; use syntax::ast::{prim_ty, private, provided}; -use syntax::ast::{public, required, rem, self_ty_, shl, shr, stmt_decl}; +use syntax::ast::{public, required, rem, explicit_self_, shl, shr, stmt_decl}; use syntax::ast::{struct_field, struct_variant_kind}; 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}; @@ -97,7 +97,7 @@ pub struct MethodInfo { did: def_id, n_tps: uint, ident: ident, - self_type: self_ty_ + explicit_self: explicit_self_ } pub struct Impl { @@ -1219,7 +1219,7 @@ pub impl Resolver { // Bail out early if there are no static methods. let mut has_static_methods = false; for methods.each |method| { - match method.self_ty.node { + match method.explicit_self.node { sty_static => has_static_methods = true, _ => {} } @@ -1252,7 +1252,7 @@ pub impl Resolver { // For each static method... for methods.each |method| { - match method.self_ty.node { + match method.explicit_self.node { sty_static => { // Add the static method to the // module. @@ -1290,7 +1290,7 @@ pub impl Resolver { let mut has_static_methods = false; for (*methods).each |method| { let ty_m = trait_method_to_ty_method(method); - match ty_m.self_ty.node { + match ty_m.explicit_self.node { sty_static => { has_static_methods = true; break; @@ -1322,7 +1322,7 @@ pub impl Resolver { let ident = ty_m.ident; // Add it to the trait info if not static, // add it as a name in the trait module otherwise. - match ty_m.self_ty.node { + match ty_m.explicit_self.node { sty_static => { let def = def_static_method( local_def(ty_m.id), @@ -1628,9 +1628,9 @@ pub impl Resolver { def_id); let mut interned_method_names = HashSet::new(); for method_def_ids.each |&method_def_id| { - let (method_name, self_ty) = - get_method_name_and_self_ty(self.session.cstore, - method_def_id); + let (method_name, explicit_self) = + get_method_name_and_explicit_self(self.session.cstore, + method_def_id); debug!("(building reduced graph for \ external crate) ... adding \ @@ -1638,7 +1638,7 @@ pub impl Resolver { *self.session.str_of(method_name)); // Add it to the trait info if not static. - if self_ty != sty_static { + if explicit_self != sty_static { interned_method_names.insert(method_name); } } @@ -3800,7 +3800,7 @@ pub impl Resolver { outer_type_parameter_count, rib_kind); // we only have self ty if it is a non static method - let self_binding = match method.self_ty.node { + let self_binding = match method.explicit_self.node { sty_static => { NoSelfBinding } _ => { HasSelfBinding(method.self_id, false) } }; @@ -4720,7 +4720,7 @@ pub impl Resolver { } } - if vec::len(values) > 0 && + if values.len() > 0 && values[smallest] != uint::max_value && values[smallest] < str::len(name) + 2 && values[smallest] <= max_distance && diff --git a/src/librustc/middle/trans/asm.rs b/src/librustc/middle/trans/asm.rs index cac9bdd186c..9211939cd2a 100644 --- a/src/librustc/middle/trans/asm.rs +++ b/src/librustc/middle/trans/asm.rs @@ -32,12 +32,9 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block { let outputs = do ia.outputs.map |&(c, out)| { constraints.push(copy *c); - let aoutty = ty::arg { - ty: expr_ty(bcx, out) - }; aoutputs.push(unpack_result!(bcx, { callee::trans_arg_expr(bcx, - aoutty, + expr_ty(bcx, out), ty::ByCopy, out, &mut cleanups, @@ -50,13 +47,9 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block { _ => fail!("Expression must be addr of") }; - let outty = ty::arg { - ty: expr_ty(bcx, e) - }; - unpack_result!(bcx, { callee::trans_arg_expr(bcx, - outty, + expr_ty(bcx, e), ty::ByCopy, e, &mut cleanups, @@ -75,13 +68,9 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block { let inputs = do ia.inputs.map |&(c, in)| { constraints.push(copy *c); - let inty = ty::arg { - ty: expr_ty(bcx, in) - }; - unpack_result!(bcx, { callee::trans_arg_expr(bcx, - inty, + expr_ty(bcx, in), ty::ByCopy, in, &mut cleanups, diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 7015a8b7f8b..e14d6d79ab5 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1664,12 +1664,12 @@ pub fn new_fn_ctxt(ccx: @CrateContext, // the function's fn_ctxt). create_llargs_for_fn_args populates the llargs // field of the fn_ctxt with pub fn create_llargs_for_fn_args(cx: fn_ctxt, - ty_self: self_arg, + self_arg: self_arg, args: &[ast::arg]) -> ~[ValueRef] { let _icx = cx.insn_ctxt("create_llargs_for_fn_args"); - match ty_self { + match self_arg { impl_self(tt) => { cx.llself = Some(ValSelfData { v: cx.llenv, @@ -1701,7 +1701,7 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt, bcx: block, args: &[ast::arg], raw_llargs: &[ValueRef], - arg_tys: &[ty::arg]) -> block { + arg_tys: &[ty::t]) -> block { let _icx = fcx.insn_ctxt("copy_args_to_allocas"); let mut bcx = bcx; @@ -1720,7 +1720,7 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt, } for uint::range(0, arg_tys.len()) |arg_n| { - let arg_ty = &arg_tys[arg_n]; + let arg_ty = arg_tys[arg_n]; let raw_llarg = raw_llargs[arg_n]; let arg_id = args[arg_n].id; @@ -1732,15 +1732,15 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt, // This alloca should be optimized away by LLVM's mem-to-reg pass in // the event it's not truly needed. // only by value if immediate: - let llarg = if datum::appropriate_mode(arg_ty.ty).is_by_value() { - let alloc = alloc_ty(bcx, arg_ty.ty); + let llarg = if datum::appropriate_mode(arg_ty).is_by_value() { + let alloc = alloc_ty(bcx, arg_ty); Store(bcx, raw_llarg, alloc); alloc } else { raw_llarg }; - add_clean(bcx, llarg, arg_ty.ty); + add_clean(bcx, llarg, arg_ty); bcx = _match::bind_irrefutable_pat(bcx, args[arg_n].pat, @@ -1801,7 +1801,7 @@ pub fn trans_closure(ccx: @CrateContext, decl: &ast::fn_decl, body: &ast::blk, llfndecl: ValueRef, - ty_self: self_arg, + self_arg: self_arg, param_substs: Option<@param_substs>, id: ast::node_id, impl_id: Option<ast::def_id>, @@ -1825,7 +1825,7 @@ pub fn trans_closure(ccx: @CrateContext, impl_id, param_substs, Some(body.span)); - let raw_llargs = create_llargs_for_fn_args(fcx, ty_self, decl.inputs); + let raw_llargs = create_llargs_for_fn_args(fcx, self_arg, decl.inputs); // Set the fixed stack segment flag if necessary. if attr::attrs_contains_name(attributes, "fixed_stack_segment") { @@ -1882,7 +1882,7 @@ pub fn trans_fn(ccx: @CrateContext, decl: &ast::fn_decl, body: &ast::blk, llfndecl: ValueRef, - ty_self: self_arg, + self_arg: self_arg, param_substs: Option<@param_substs>, id: ast::node_id, impl_id: Option<ast::def_id>, @@ -1890,8 +1890,8 @@ pub fn trans_fn(ccx: @CrateContext, let do_time = ccx.sess.trans_stats(); let start = if do_time { time::get_time() } else { time::Timespec::new(0, 0) }; - debug!("trans_fn(ty_self=%?, param_substs=%s)", - ty_self, + debug!("trans_fn(self_arg=%?, param_substs=%s)", + self_arg, param_substs.repr(ccx.tcx)); let _icx = ccx.insn_ctxt("trans_fn"); ccx.stats.n_fns += 1; @@ -1902,7 +1902,7 @@ pub fn trans_fn(ccx: @CrateContext, decl, body, llfndecl, - ty_self, + self_arg, param_substs, id, impl_id, @@ -1987,7 +1987,7 @@ pub fn trans_enum_variant(ccx: @CrateContext, Some(&local_mem(x)) => x, _ => fail!("trans_enum_variant: how do we know this works?"), }; - let arg_ty = arg_tys[i].ty; + let arg_ty = arg_tys[i]; memcpy_ty(bcx, lldestptr, llarg, arg_ty); } build_return(bcx); @@ -2061,7 +2061,7 @@ pub fn trans_tuple_struct(ccx: @CrateContext, local_mem") } }; - let arg_ty = arg_tys[i].ty; + let arg_ty = arg_tys[i]; memcpy_ty(bcx, lldestptr, llarg, arg_ty); } diff --git a/src/librustc/middle/trans/cabi.rs b/src/librustc/middle/trans/cabi.rs index 702d62f1363..e103bbc5de7 100644 --- a/src/librustc/middle/trans/cabi.rs +++ b/src/librustc/middle/trans/cabi.rs @@ -65,7 +65,7 @@ pub impl FnType { let mut llargvals = ~[]; let mut i = 0u; - let n = vec::len(arg_tys); + let n = arg_tys.len(); if self.sret { let llretptr = GEPi(bcx, llargbundle, [0u, n]); @@ -113,7 +113,7 @@ pub impl FnType { if self.sret || !ret_def { return; } - let n = vec::len(arg_tys); + let n = arg_tys.len(); // R** llretptr = &args->r; let llretptr = GEPi(bcx, llargbundle, [0u, n]); // R* llretloc = *llretptr; /* (args->r) */ @@ -149,7 +149,7 @@ pub impl FnType { }; let mut i = 0u; - let n = vec::len(atys); + let n = atys.len(); while i < n { let mut argval = get_param(llwrapfn, i + j); if attrs[i].is_some() { diff --git a/src/librustc/middle/trans/cabi_x86_64.rs b/src/librustc/middle/trans/cabi_x86_64.rs index 3a2ab74c33a..a44f203c7ab 100644 --- a/src/librustc/middle/trans/cabi_x86_64.rs +++ b/src/librustc/middle/trans/cabi_x86_64.rs @@ -50,7 +50,7 @@ fn is_sse(c: x86_64_reg_class) -> bool { } fn is_ymm(cls: &[x86_64_reg_class]) -> bool { - let len = vec::len(cls); + let len = cls.len(); return (len > 2u && is_sse(cls[0]) && cls[1] == sseup_class && @@ -223,8 +223,8 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] { unsafe { let mut i = 0u; let llty = llvm::LLVMGetTypeKind(ty) as int; - let e = vec::len(cls); - if vec::len(cls) > 2u && + let e = cls.len(); + if cls.len() > 2u && (llty == 10 /* struct */ || llty == 11 /* array */) { if is_sse(cls[i]) { @@ -295,7 +295,7 @@ fn llreg_ty(cls: &[x86_64_reg_class]) -> TypeRef { unsafe { let mut tys = ~[]; let mut i = 0u; - let e = vec::len(cls); + let e = cls.len(); while i < e { match cls[i] { integer_class => { diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 70a0a7d06d3..dc81a980588 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -674,7 +674,7 @@ pub enum AutorefArg { // temp_cleanups: cleanups that should run only if failure occurs before the // call takes place: pub fn trans_arg_expr(bcx: block, - formal_ty: ty::arg, + formal_arg_ty: ty::t, self_mode: ty::SelfMode, arg_expr: @ast::expr, temp_cleanups: &mut ~[ValueRef], @@ -683,9 +683,9 @@ pub fn trans_arg_expr(bcx: block, let _icx = bcx.insn_ctxt("trans_arg_expr"); let ccx = bcx.ccx(); - debug!("trans_arg_expr(formal_ty=(%s), self_mode=%?, arg_expr=%s, \ + debug!("trans_arg_expr(formal_arg_ty=(%s), self_mode=%?, arg_expr=%s, \ ret_flag=%?)", - formal_ty.ty.repr(bcx.tcx()), + formal_arg_ty.repr(bcx.tcx()), self_mode, arg_expr.repr(bcx.tcx()), ret_flag.map(|v| bcx.val_str(*v))); @@ -734,9 +734,9 @@ pub fn trans_arg_expr(bcx: block, // "undef" value, as such a value should never // be inspected. It's important for the value // to have type lldestty (the callee's expected type). - let llformal_ty = type_of::type_of(ccx, formal_ty.ty); + let llformal_arg_ty = type_of::type_of(ccx, formal_arg_ty); unsafe { - val = llvm::LLVMGetUndef(llformal_ty); + val = llvm::LLVMGetUndef(llformal_arg_ty); } } else { // FIXME(#3548) use the adjustments table @@ -784,16 +784,16 @@ pub fn trans_arg_expr(bcx: block, } } - if formal_ty.ty != arg_datum.ty { + if formal_arg_ty != arg_datum.ty { // this could happen due to e.g. subtyping - let llformal_ty = type_of::type_of_explicit_arg(ccx, &formal_ty); - let llformal_ty = match self_mode { - ty::ByRef => T_ptr(llformal_ty), - ty::ByCopy => llformal_ty, + let llformal_arg_ty = type_of::type_of_explicit_arg(ccx, &formal_arg_ty); + let llformal_arg_ty = match self_mode { + ty::ByRef => T_ptr(llformal_arg_ty), + ty::ByCopy => llformal_arg_ty, }; debug!("casting actual type (%s) to match formal (%s)", - bcx.val_str(val), bcx.llty_str(llformal_ty)); - val = PointerCast(bcx, val, llformal_ty); + bcx.val_str(val), bcx.llty_str(llformal_arg_ty)); + val = PointerCast(bcx, val, llformal_arg_ty); } } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 0b56fe67f8a..d8252a449ba 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -785,7 +785,7 @@ fn create_ty(cx: @CrateContext, t: ty::t, span: span) cx.sess.span_bug(span, "debuginfo for rptr NYI") }, ty::ty_bare_fn(ref barefnty) => { - let inputs = do barefnty.sig.inputs.map |a| { a.ty }; + let inputs = barefnty.sig.inputs.map(|a| *a); let output = barefnty.sig.output; create_fn_ty(cx, t, inputs, output, span) }, diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index fcf5d05a744..5b1cae473f7 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -29,7 +29,7 @@ use middle::trans::machine; use middle::trans::type_of::*; use middle::trans::type_of; use middle::ty; -use middle::ty::{FnSig, arg}; +use middle::ty::FnSig; use util::ppaux::ty_to_str; use syntax::codemap::span; @@ -94,7 +94,7 @@ fn foreign_signature(ccx: @CrateContext, fn_sig: &ty::FnSig) * values by pointer like we do. */ - let llarg_tys = fn_sig.inputs.map(|arg| type_of(ccx, arg.ty)); + let llarg_tys = fn_sig.inputs.map(|arg_ty| type_of(ccx, *arg_ty)); let llret_ty = type_of::type_of(ccx, fn_sig.output); LlvmSignature { llarg_tys: llarg_tys, @@ -509,7 +509,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext, llargbundle: ValueRef) { let _icx = bcx.insn_ctxt("foreign::wrap::build_args"); let ccx = bcx.ccx(); - let n = vec::len(tys.llsig.llarg_tys); + let n = tys.llsig.llarg_tys.len(); let implicit_args = first_real_arg; // return + env for uint::range(0, n) |i| { let mut llargval = get_param(llwrapfn, i + implicit_args); @@ -820,7 +820,7 @@ pub fn trans_intrinsic(ccx: @CrateContext, region: ty::re_bound(ty::br_anon(0)), sig: FnSig { bound_lifetime_names: opt_vec::Empty, - inputs: ~[ arg { ty: star_u8 } ], + inputs: ~[ star_u8 ], output: ty::mk_nil() } }); diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index e5c6244879d..10e019b2a37 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -99,14 +99,14 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::def_id, let path = vec::append( ty::item_path(ccx.tcx, impl_did), ~[path_name(mth.ident)]); - let self_kind = match mth.self_ty.node { + let self_kind = match mth.explicit_self.node { ast::sty_static => no_self, _ => { let self_ty = ty::node_id_to_type(ccx.tcx, mth.self_id); debug!("calling inline trans_fn with self_ty %s", ty_to_str(ccx.tcx, self_ty)); - match mth.self_ty.node { + match mth.explicit_self.node { ast::sty_value => impl_owned_self(self_ty), _ => impl_self(self_ty), } diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index d4856de2184..bdbb45bf275 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -25,7 +25,6 @@ use middle::trans::inline; use middle::trans::monomorphize; use middle::trans::type_of::*; use middle::ty; -use middle::ty::arg; use middle::typeck; use util::common::indenter; use util::ppaux::Repr; @@ -70,7 +69,12 @@ pub fn trans_impl(ccx: @CrateContext, path: path, name: ast::ident, } } - trans_method(ccx, path, *method, param_substs_opt, self_ty, llfn, + trans_method(ccx, + path, + *method, + param_substs_opt, + self_ty, + llfn, ast_util::local_def(id)); } } @@ -99,18 +103,17 @@ pub fn trans_method(ccx: @CrateContext, llfn: ValueRef, impl_id: ast::def_id) { // figure out how self is being passed - let self_arg = match method.self_ty.node { + let self_arg = match method.explicit_self.node { ast::sty_static => { no_self } _ => { // determine the (monomorphized) type that `self` maps to for // this method - let self_ty; - match base_self_ty { - None => self_ty = ty::node_id_to_type(ccx.tcx, method.self_id), - Some(provided_self_ty) => self_ty = provided_self_ty - } + let self_ty = match base_self_ty { + None => ty::node_id_to_type(ccx.tcx, method.self_id), + Some(provided_self_ty) => provided_self_ty, + }; let self_ty = match param_substs { None => self_ty, Some(@param_substs {tys: ref tys, _}) => { @@ -120,7 +123,7 @@ pub fn trans_method(ccx: @CrateContext, debug!("calling trans_fn with base_self_ty %s, self_ty %s", base_self_ty.repr(ccx.tcx), self_ty.repr(ccx.tcx)); - match method.self_ty.node { + match method.explicit_self.node { ast::sty_value => { impl_owned_self(self_ty) } @@ -151,12 +154,10 @@ pub fn trans_self_arg(bcx: block, let mut temp_cleanups = ~[]; // Compute the type of self. - let self_arg = arg { - ty: monomorphize_type(bcx, mentry.self_arg.ty) - }; + let self_ty = monomorphize_type(bcx, mentry.self_ty); let result = trans_arg_expr(bcx, - self_arg, + self_ty, mentry.self_mode, base, &mut temp_cleanups, @@ -589,7 +590,7 @@ pub fn trans_trait_callee(bcx: block, n_method: uint, self_expr: @ast::expr, store: ty::TraitStore, - explicit_self: ast::self_ty_) + explicit_self: ast::explicit_self_) -> Callee { //! // @@ -626,7 +627,7 @@ pub fn trans_trait_callee_from_llval(bcx: block, n_method: uint, llpair: ValueRef, store: ty::TraitStore, - explicit_self: ast::self_ty_) + explicit_self: ast::explicit_self_) -> Callee { //! // diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index 2183472d591..1141e0c007f 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -35,7 +35,7 @@ use syntax::parse::token::special_idents; pub struct Reflector { visitor_val: ValueRef, - visitor_methods: @~[@ty::method], + visitor_methods: @~[@ty::Method], final_bcx: block, tydesc_ty: TypeRef, bcx: block @@ -93,7 +93,7 @@ pub impl Reflector { let mth_ty = ty::mk_bare_fn(tcx, copy self.visitor_methods[mth_idx].fty); let v = self.visitor_val; - debug!("passing %u args:", vec::len(args)); + debug!("passing %u args:", args.len()); let bcx = self.bcx; for args.eachi |i, a| { debug!("arg %u: %s", i, val_str(bcx.ccx().tn, *a)); @@ -224,7 +224,7 @@ pub impl Reflector { let retval = if ty::type_is_bot(fty.sig.output) {0u} else {1u}; let extra = ~[self.c_uint(pureval), self.c_uint(sigilval), - self.c_uint(vec::len(fty.sig.inputs)), + self.c_uint(fty.sig.inputs.len()), self.c_uint(retval)]; self.visit(~"enter_fn", copy extra); // XXX: Bad copy. self.visit_sig(retval, &fty.sig); @@ -239,7 +239,7 @@ pub impl Reflector { let retval = if ty::type_is_bot(fty.sig.output) {0u} else {1u}; let extra = ~[self.c_uint(pureval), self.c_uint(sigilval), - self.c_uint(vec::len(fty.sig.inputs)), + self.c_uint(fty.sig.inputs.len()), self.c_uint(retval)]; self.visit(~"enter_fn", copy extra); // XXX: Bad copy. self.visit_sig(retval, &fty.sig); @@ -284,13 +284,8 @@ pub impl Reflector { let sym = mangle_internal_name_by_path_and_seq(ccx, sub_path, "get_disr"); - let args = [ - ty::arg { - ty: opaqueptrty - } - ]; - let llfty = type_of_fn(ccx, args, ty::mk_int()); + let llfty = type_of_fn(ccx, [opaqueptrty], ty::mk_int()); let llfdecl = decl_internal_cdecl_fn(ccx.llmod, sym, llfty); let arg = unsafe { llvm::LLVMGetParam(llfdecl, first_real_arg as c_uint) @@ -309,13 +304,13 @@ pub impl Reflector { llfdecl }; - let enum_args = ~[self.c_uint(vec::len(variants)), make_get_disr()] + let enum_args = ~[self.c_uint(variants.len()), make_get_disr()] + self.c_size_and_align(t); do self.bracketed(~"enum", enum_args) |this| { for variants.eachi |i, v| { let variant_args = ~[this.c_uint(i), this.c_int(v.disr_val), - this.c_uint(vec::len(v.args)), + this.c_uint(v.args.len()), this.c_slice(ccx.sess.str_of(v.name))]; do this.bracketed(~"enum_variant", variant_args) |this| { for v.args.eachi |j, a| { @@ -357,7 +352,7 @@ pub impl Reflector { let modeval = 5u; // "by copy" let extra = ~[self.c_uint(i), self.c_uint(modeval), - self.c_tydesc(arg.ty)]; + self.c_tydesc(*arg)]; self.visit(~"fn_input", extra); } let extra = ~[self.c_uint(retval), diff --git a/src/librustc/middle/trans/shape.rs b/src/librustc/middle/trans/shape.rs index 6ff9e1cfc57..31de1280741 100644 --- a/src/librustc/middle/trans/shape.rs +++ b/src/librustc/middle/trans/shape.rs @@ -18,7 +18,6 @@ use middle::trans::common::*; use middle::trans; use core::str; -use core::vec; pub struct Ctxt { next_tag_id: u16, @@ -71,6 +70,6 @@ pub fn add_u16(dest: &mut ~[u8], val: u16) { } pub fn add_substr(dest: &mut ~[u8], src: ~[u8]) { - add_u16(&mut *dest, vec::len(src) as u16); + add_u16(&mut *dest, src.len() as u16); *dest += src; } diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index b8e0b58f866..dfbebd90c29 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -19,21 +19,21 @@ use util::ppaux; use syntax::ast; -pub fn arg_is_indirect(_: @CrateContext, arg: &ty::arg) -> bool { - !ty::type_is_immediate(arg.ty) +pub fn arg_is_indirect(_: @CrateContext, arg_ty: &ty::t) -> bool { + !ty::type_is_immediate(*arg_ty) } -pub fn type_of_explicit_arg(ccx: @CrateContext, arg: &ty::arg) -> TypeRef { - let llty = type_of(ccx, arg.ty); - if arg_is_indirect(ccx, arg) {T_ptr(llty)} else {llty} +pub fn type_of_explicit_arg(ccx: @CrateContext, arg_ty: &ty::t) -> TypeRef { + let llty = type_of(ccx, *arg_ty); + if arg_is_indirect(ccx, arg_ty) {T_ptr(llty)} else {llty} } pub fn type_of_explicit_args(ccx: @CrateContext, - inputs: &[ty::arg]) -> ~[TypeRef] { - inputs.map(|arg| type_of_explicit_arg(ccx, arg)) + inputs: &[ty::t]) -> ~[TypeRef] { + inputs.map(|arg_ty| type_of_explicit_arg(ccx, arg_ty)) } -pub fn type_of_fn(cx: @CrateContext, inputs: &[ty::arg], output: ty::t) +pub fn type_of_fn(cx: @CrateContext, inputs: &[ty::t], output: ty::t) -> TypeRef { unsafe { let mut atys: ~[TypeRef] = ~[]; diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index c15c31055c3..4a8adfba11c 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -78,7 +78,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) | ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) => { for sig.inputs.each |arg| { - type_needs(cx, use_repr, arg.ty); + type_needs(cx, use_repr, *arg); } } _ => () @@ -331,18 +331,16 @@ pub fn mark_for_expr(cx: Context, e: @expr) { node_type_needs(cx, use_tydesc, val.id); } expr_call(f, _, _) => { - for vec::each(ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, - f.id))) |a| { - type_needs(cx, use_repr, a.ty); + for ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id)).each |a| { + type_needs(cx, use_repr, *a); } } expr_method_call(rcvr, _, _, _, _) => { let base_ty = ty::node_id_to_type(cx.ccx.tcx, rcvr.id); type_needs(cx, use_repr, ty::type_autoderef(cx.ccx.tcx, base_ty)); - for ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, - e.callee_id)).each |a| { - type_needs(cx, use_repr, a.ty); + for ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, e.callee_id)).each |a| { + type_needs(cx, use_repr, *a); } mark_for_method_call(cx, e.id, e.callee_id); } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index fbb84751d03..4ee2c5b0100 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -47,27 +47,49 @@ use syntax; // Data types -#[deriving(Eq, IterBytes)] -pub struct arg { - ty: t -} - #[deriving(Eq)] pub struct field { ident: ast::ident, mt: mt } -pub struct method { +pub struct Method { ident: ast::ident, generics: ty::Generics, transformed_self_ty: Option<ty::t>, fty: BareFnTy, - self_ty: ast::self_ty_, + explicit_self: ast::explicit_self_, vis: ast::visibility, def_id: ast::def_id } +pub impl Method { + fn new(ident: ast::ident, + generics: ty::Generics, + transformed_self_ty: Option<ty::t>, + fty: BareFnTy, + explicit_self: ast::explicit_self_, + vis: ast::visibility, + def_id: ast::def_id) -> Method { + // Check the invariants. + if explicit_self == ast::sty_static { + assert!(transformed_self_ty.is_none()); + } else { + assert!(transformed_self_ty.is_some()); + } + + Method { + ident: ident, + generics: generics, + transformed_self_ty: transformed_self_ty, + fty: fty, + explicit_self: explicit_self, + vis: vis, + def_id: def_id + } + } +} + #[deriving(Eq)] pub struct mt { ty: t, @@ -259,13 +281,13 @@ struct ctxt_ { node_type_substs: @mut HashMap<node_id, ~[t]>, // Maps from a method to the method "descriptor" - methods: @mut HashMap<def_id, @method>, + methods: @mut HashMap<def_id, @Method>, // Maps from a trait def-id to a list of the def-ids of its methods trait_method_def_ids: @mut HashMap<def_id, @~[def_id]>, // A cache for the trait_methods() routine - trait_methods_cache: @mut HashMap<def_id, @~[@method]>, + trait_methods_cache: @mut HashMap<def_id, @~[@Method]>, trait_refs: @mut HashMap<node_id, @TraitRef>, trait_defs: @mut HashMap<def_id, @TraitDef>, @@ -392,7 +414,7 @@ pub struct ClosureTy { #[deriving(Eq)] pub struct FnSig { bound_lifetime_names: OptVec<ast::ident>, - inputs: ~[arg], + inputs: ~[t], output: t } @@ -1107,14 +1129,14 @@ fn mk_t(cx: ctxt, st: sty) -> t { } &ty_tup(ref ts) => for ts.each |tt| { flags |= get(*tt).flags; }, &ty_bare_fn(ref f) => { - for f.sig.inputs.each |a| { flags |= get(a.ty).flags; } + for f.sig.inputs.each |a| { flags |= get(*a).flags; } flags |= get(f.sig.output).flags; // T -> _|_ is *not* _|_ ! flags &= !(has_ty_bot as uint); } &ty_closure(ref f) => { flags |= rflags(f.region); - for f.sig.inputs.each |a| { flags |= get(a.ty).flags; } + for f.sig.inputs.each |a| { flags |= get(*a).flags; } flags |= get(f.sig.output).flags; // T -> _|_ is *not* _|_ ! flags &= !(has_ty_bot as uint); @@ -1298,7 +1320,7 @@ pub fn mk_bare_fn(cx: ctxt, fty: BareFnTy) -> t { } pub fn mk_ctor_fn(cx: ctxt, input_tys: &[ty::t], output: ty::t) -> t { - let input_args = input_tys.map(|t| arg { ty: *t }); + let input_args = input_tys.map(|t| *t); mk_bare_fn(cx, BareFnTy { purity: ast::pure_fn, @@ -1372,11 +1394,11 @@ pub fn maybe_walk_ty(ty: t, f: &fn(t) -> bool) { } ty_tup(ref ts) => { for ts.each |tt| { maybe_walk_ty(*tt, f); } } ty_bare_fn(ref ft) => { - for ft.sig.inputs.each |a| { maybe_walk_ty(a.ty, f); } + for ft.sig.inputs.each |a| { maybe_walk_ty(*a, f); } maybe_walk_ty(ft.sig.output, f); } ty_closure(ref ft) => { - for ft.sig.inputs.each |a| { maybe_walk_ty(a.ty, f); } + for ft.sig.inputs.each |a| { maybe_walk_ty(*a, f); } maybe_walk_ty(ft.sig.output, f); } } @@ -1387,11 +1409,7 @@ pub fn fold_sty_to_ty(tcx: ty::ctxt, sty: &sty, foldop: &fn(t) -> t) -> t { } pub fn fold_sig(sig: &FnSig, fldop: &fn(t) -> t) -> FnSig { - let args = do sig.inputs.map |arg| { - arg { - ty: fldop(arg.ty) - } - }; + let args = sig.inputs.map(|arg| fldop(*arg)); FnSig { bound_lifetime_names: copy sig.bound_lifetime_names, @@ -2616,7 +2634,7 @@ pub fn deref_sty(cx: ctxt, sty: &sty, explicit: bool) -> Option<mt> { ty_enum(did, ref substs) => { let variants = enum_variants(cx, did); - if vec::len(*variants) == 1u && vec::len(variants[0].args) == 1u { + if (*variants).len() == 1u && variants[0].args.len() == 1u { let v_t = subst(cx, substs, variants[0].args[0]); Some(mt {ty: v_t, mutbl: ast::m_imm}) } else { @@ -2999,7 +3017,7 @@ pub fn ty_fn_sig(fty: t) -> FnSig { } // Type accessors for substructures of types -pub fn ty_fn_args(fty: t) -> ~[arg] { +pub fn ty_fn_args(fty: t) -> ~[t] { match get(fty).sty { ty_bare_fn(ref f) => copy f.sig.inputs, ty_closure(ref f) => copy f.sig.inputs, @@ -3103,7 +3121,7 @@ pub fn replace_closure_return_type(tcx: ctxt, fn_type: t, ret_type: t) -> t { // Returns a vec of all the input and output types of fty. pub fn tys_in_fn_sig(sig: &FnSig) -> ~[t] { - vec::append_one(sig.inputs.map(|a| a.ty), sig.output) + vec::append_one(sig.inputs.map(|a| *a), sig.output) } // Type accessors for AST nodes @@ -3507,7 +3525,7 @@ pub fn field_idx_strict(tcx: ty::ctxt, id: ast::ident, fields: &[field]) fields.map(|f| tcx.sess.str_of(f.ident)))); } -pub fn method_idx(id: ast::ident, meths: &[@method]) -> Option<uint> { +pub fn method_idx(id: ast::ident, meths: &[@Method]) -> Option<uint> { vec::position(meths, |m| m.ident == id) } @@ -3831,12 +3849,12 @@ fn lookup_locally_or_in_crate_store<V:Copy>( return v; } -pub fn trait_method(cx: ctxt, trait_did: ast::def_id, idx: uint) -> @method { +pub fn trait_method(cx: ctxt, trait_did: ast::def_id, idx: uint) -> @Method { let method_def_id = ty::trait_method_def_ids(cx, trait_did)[idx]; ty::method(cx, method_def_id) } -pub fn trait_methods(cx: ctxt, trait_did: ast::def_id) -> @~[@method] { +pub fn trait_methods(cx: ctxt, trait_did: ast::def_id) -> @~[@Method] { match cx.trait_methods_cache.find(&trait_did) { Some(&methods) => methods, None => { @@ -3848,7 +3866,7 @@ pub fn trait_methods(cx: ctxt, trait_did: ast::def_id) -> @~[@method] { } } -pub fn method(cx: ctxt, id: ast::def_id) -> @method { +pub fn method(cx: ctxt, id: ast::def_id) -> @Method { lookup_locally_or_in_crate_store( "methods", id, cx.methods, || @csearch::get_method(cx, id)) @@ -4061,7 +4079,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] { let ctor_ty = node_id_to_type(cx, variant.node.id); let arg_tys = { if args.len() > 0u { - ty_fn_args(ctor_ty).map(|a| a.ty) + ty_fn_args(ctor_ty).map(|a| *a) } else { ~[] } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 469e31d0c49..de6064b0a31 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -53,7 +53,7 @@ */ use middle::const_eval; -use middle::ty::{arg, substs}; +use middle::ty::{substs}; use middle::ty::{ty_param_substs_and_ty}; use middle::ty; use middle::typeck::rscope::in_binding_rscope; @@ -501,16 +501,12 @@ pub fn ty_of_arg<AC:AstConv, this: &AC, rscope: &RS, a: ast::arg, - expected_ty: Option<ty::arg>) - -> ty::arg { - let ty = match a.ty.node { - ast::ty_infer if expected_ty.is_some() => expected_ty.get().ty, + expected_ty: Option<ty::t>) + -> ty::t { + match a.ty.node { + ast::ty_infer if expected_ty.is_some() => expected_ty.get(), ast::ty_infer => this.ty_infer(a.ty.span), _ => ast_ty_to_ty(this, rscope, a.ty), - }; - - arg { - ty: ty } } @@ -546,7 +542,7 @@ pub fn bound_lifetimes<AC:AstConv>( struct SelfInfo { untransformed_self_ty: ty::t, - self_transform: ast::self_ty + explicit_self: ast::explicit_self } pub fn ty_of_method<AC:AstConv,RS:region_scope + Copy + 'static>( @@ -555,12 +551,12 @@ pub fn ty_of_method<AC:AstConv,RS:region_scope + Copy + 'static>( purity: ast::purity, lifetimes: &OptVec<ast::Lifetime>, untransformed_self_ty: ty::t, - self_transform: ast::self_ty, + explicit_self: ast::explicit_self, decl: &ast::fn_decl) -> (Option<ty::t>, ty::BareFnTy) { let self_info = SelfInfo { untransformed_self_ty: untransformed_self_ty, - self_transform: self_transform + explicit_self: explicit_self }; let (a, b) = ty_of_method_or_bare_fn( this, rscope, purity, AbiSet::Rust(), lifetimes, Some(&self_info), decl); @@ -621,7 +617,7 @@ fn ty_of_method_or_bare_fn<AC:AstConv,RS:region_scope + Copy + 'static>( rscope: &RS, self_info: &SelfInfo) -> Option<ty::t> { - match self_info.self_transform.node { + match self_info.explicit_self.node { ast::sty_static => None, ast::sty_value => { Some(self_info.untransformed_self_ty) @@ -629,7 +625,7 @@ fn ty_of_method_or_bare_fn<AC:AstConv,RS:region_scope + Copy + 'static>( ast::sty_region(lifetime, mutability) => { let region = ast_region_to_region(this, rscope, - self_info.self_transform.span, + self_info.explicit_self.span, lifetime); Some(ty::mk_rptr(this.tcx(), region, ty::mt {ty: self_info.untransformed_self_ty, diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 24edf4a6033..9e8103f4527 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -170,7 +170,7 @@ pub struct LookupContext<'self> { pub struct Candidate { rcvr_ty: ty::t, rcvr_substs: ty::substs, - method_ty: @ty::method, + method_ty: @ty::Method, origin: method_origin, } @@ -381,7 +381,7 @@ pub impl<'self> LookupContext<'self> { let trait_methods = ty::trait_methods(tcx, bound_trait_ref.def_id); let pos = { match trait_methods.position(|m| { - m.self_ty != ast::sty_static && + m.explicit_self != ast::sty_static && m.ident == self.m_name }) { Some(pos) => pos, @@ -469,7 +469,7 @@ pub impl<'self> LookupContext<'self> { did: def_id, substs: &ty::substs) { struct MethodInfo { - method_ty: @ty::method, + method_ty: @ty::Method, trait_def_id: ast::def_id, index: uint } @@ -830,10 +830,10 @@ pub impl<'self> LookupContext<'self> { } fn search_for_method(&self, - self_ty: ty::t) + rcvr_ty: ty::t) -> Option<method_map_entry> { - debug!("search_for_method(self_ty=%s)", self.ty_to_str(self_ty)); + debug!("search_for_method(rcvr_ty=%s)", self.ty_to_str(rcvr_ty)); let _indenter = indenter(); // I am not sure that inherent methods should have higher @@ -841,7 +841,7 @@ pub impl<'self> LookupContext<'self> { // existing code. debug!("searching inherent candidates"); - match self.consider_candidates(self_ty, self.inherent_candidates) { + match self.consider_candidates(rcvr_ty, self.inherent_candidates) { None => {} Some(mme) => { return Some(mme); @@ -849,7 +849,7 @@ pub impl<'self> LookupContext<'self> { } debug!("searching extension candidates"); - match self.consider_candidates(self_ty, self.extension_candidates) { + match self.consider_candidates(rcvr_ty, self.extension_candidates) { None => { return None; } @@ -860,12 +860,12 @@ pub impl<'self> LookupContext<'self> { } fn consider_candidates(&self, - self_ty: ty::t, + rcvr_ty: ty::t, candidates: &mut ~[Candidate]) -> Option<method_map_entry> { let relevant_candidates = - candidates.filter_to_vec(|c| self.is_relevant(self_ty, c)); + candidates.filter_to_vec(|c| self.is_relevant(rcvr_ty, c)); let relevant_candidates = self.merge_candidates(relevant_candidates); @@ -882,7 +882,7 @@ pub impl<'self> LookupContext<'self> { } } - Some(self.confirm_candidate(self_ty, &relevant_candidates[0])) + Some(self.confirm_candidate(rcvr_ty, &relevant_candidates[0])) } fn merge_candidates(&self, candidates: &[Candidate]) -> ~[Candidate] { @@ -932,7 +932,7 @@ pub impl<'self> LookupContext<'self> { } fn confirm_candidate(&self, - self_ty: ty::t, + rcvr_ty: ty::t, candidate: &Candidate) -> method_map_entry { @@ -948,11 +948,11 @@ pub impl<'self> LookupContext<'self> { self.enforce_drop_trait_limitations(candidate); // static methods should never have gotten this far: - assert!(candidate.method_ty.self_ty != sty_static); + assert!(candidate.method_ty.explicit_self != sty_static); let transformed_self_ty = match candidate.origin { method_trait(*) => { - match candidate.method_ty.self_ty { + match candidate.method_ty.explicit_self { sty_region(*) => { // FIXME(#5762) again, preserving existing // behavior here which (for &self) desires @@ -1033,7 +1033,7 @@ pub impl<'self> LookupContext<'self> { let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {sig: fn_sig, ..bare_fn_ty}); debug!("after replacing bound regions, fty=%s", self.ty_to_str(fty)); - let self_mode = get_mode_from_self_type(candidate.method_ty.self_ty); + let self_mode = get_mode_from_explicit_self(candidate.method_ty.explicit_self); // before we only checked whether self_ty could be a subtype // of rcvr_ty; now we actually make it so (this may cause @@ -1041,11 +1041,11 @@ pub impl<'self> LookupContext<'self> { // nothing has changed in the meantime, this unification // should never fail. match self.fcx.mk_subty(false, self.self_expr.span, - self_ty, transformed_self_ty) { + rcvr_ty, transformed_self_ty) { result::Ok(_) => (), result::Err(_) => { self.bug(fmt!("%s was a subtype of %s but now is not?", - self.ty_to_str(self_ty), + self.ty_to_str(rcvr_ty), self.ty_to_str(transformed_self_ty))); } } @@ -1053,11 +1053,9 @@ pub impl<'self> LookupContext<'self> { self.fcx.write_ty(self.callee_id, fty); self.fcx.write_substs(self.callee_id, all_substs); method_map_entry { - self_arg: arg { - ty: candidate.rcvr_ty, - }, + self_ty: candidate.rcvr_ty, self_mode: self_mode, - explicit_self: candidate.method_ty.self_ty, + explicit_self: candidate.method_ty.explicit_self, origin: candidate.origin, } } @@ -1116,9 +1114,11 @@ pub impl<'self> LookupContext<'self> { } } - fn is_relevant(&self, self_ty: ty::t, candidate: &Candidate) -> bool { - debug!("is_relevant(self_ty=%s, candidate=%s)", - self.ty_to_str(self_ty), self.cand_to_str(candidate)); + // `rcvr_ty` is the type of the expression. It may be a subtype of a + // candidate method's `self_ty`. + fn is_relevant(&self, rcvr_ty: ty::t, candidate: &Candidate) -> bool { + debug!("is_relevant(rcvr_ty=%s, candidate=%s)", + self.ty_to_str(rcvr_ty), self.cand_to_str(candidate)); // Check for calls to object methods. We resolve these differently. // @@ -1126,7 +1126,7 @@ pub impl<'self> LookupContext<'self> { // on an @Trait object here and so forth match candidate.origin { method_trait(*) => { - match candidate.method_ty.self_ty { + match candidate.method_ty.explicit_self { sty_static | sty_value => { return false; } @@ -1136,7 +1136,7 @@ pub impl<'self> LookupContext<'self> { // an &@Trait receiver (wacky) } sty_box(*) | sty_uniq(*) => { - return self.fcx.can_mk_subty(self_ty, + return self.fcx.can_mk_subty(rcvr_ty, candidate.rcvr_ty).is_ok(); } }; @@ -1144,17 +1144,17 @@ pub impl<'self> LookupContext<'self> { _ => {} } - return match candidate.method_ty.self_ty { + return match candidate.method_ty.explicit_self { sty_static => { false } sty_value => { - self.fcx.can_mk_subty(self_ty, candidate.rcvr_ty).is_ok() + self.fcx.can_mk_subty(rcvr_ty, candidate.rcvr_ty).is_ok() } sty_region(_, m) => { - match ty::get(self_ty).sty { + match ty::get(rcvr_ty).sty { ty::ty_rptr(_, mt) => { mutability_matches(mt.mutbl, m) && self.fcx.can_mk_subty(mt.ty, candidate.rcvr_ty).is_ok() @@ -1165,7 +1165,7 @@ pub impl<'self> LookupContext<'self> { } sty_box(m) => { - match ty::get(self_ty).sty { + match ty::get(rcvr_ty).sty { ty::ty_box(mt) => { mutability_matches(mt.mutbl, m) && self.fcx.can_mk_subty(mt.ty, candidate.rcvr_ty).is_ok() @@ -1176,7 +1176,7 @@ pub impl<'self> LookupContext<'self> { } sty_uniq(m) => { - match ty::get(self_ty).sty { + match ty::get(rcvr_ty).sty { ty::ty_uniq(mt) => { mutability_matches(mt.mutbl, m) && self.fcx.can_mk_subty(mt.ty, candidate.rcvr_ty).is_ok() @@ -1301,8 +1301,8 @@ pub impl<'self> LookupContext<'self> { } } -pub fn get_mode_from_self_type(self_type: ast::self_ty_) -> SelfMode { - match self_type { +pub fn get_mode_from_explicit_self(explicit_self: ast::explicit_self_) -> SelfMode { + match explicit_self { sty_value => ty::ByCopy, _ => ty::ByRef, } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index fd511b6fc53..548b9e454ce 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -81,7 +81,7 @@ use middle::pat_util::pat_id_map; use middle::pat_util; use middle::ty::{FnSig, VariantInfo_}; use middle::ty::{ty_param_bounds_and_ty, ty_param_substs_and_ty}; -use middle::ty::{substs, arg, param_ty}; +use middle::ty::{substs, param_ty}; use middle::ty; use middle::typeck::astconv::AstConv; use middle::typeck::astconv::{ast_region_to_region, ast_ty_to_ty}; @@ -352,7 +352,7 @@ pub fn check_fn(ccx: @mut CrateCtxt, relate_free_regions(tcx, opt_self_info.map(|s| s.self_ty), &fn_sig); - let arg_tys = fn_sig.inputs.map(|a| a.ty); + let arg_tys = fn_sig.inputs.map(|a| *a); let ret_ty = fn_sig.output; debug!("check_fn(arg_tys=%?, ret_ty=%?, opt_self_ty=%?)", @@ -527,7 +527,7 @@ pub fn check_method(ccx: @mut CrateCtxt, let opt_self_info = method_ty.transformed_self_ty.map(|&ty| { SelfInfo {self_ty: ty, self_id: method.self_id, - span: method.self_ty.span} + span: method.explicit_self.span} }); check_bare_fn( @@ -1192,7 +1192,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, fn check_argument_types( fcx: @mut FnCtxt, sp: span, - fn_inputs: &[ty::arg], + fn_inputs: &[ty::t], callee_expr: @ast::expr, args: &[@ast::expr], sugar: ast::CallSugar, @@ -1211,7 +1211,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, let supplied_arg_count = args.len(); let expected_arg_count = fn_inputs.len(); let formal_tys = if expected_arg_count == supplied_arg_count { - fn_inputs.map(|a| a.ty) + fn_inputs.map(|a| *a) } else { let suffix = match sugar { ast::NoSugar => "", @@ -1287,8 +1287,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, } } - fn err_args(len: uint) -> ~[ty::arg] { - vec::from_fn(len, |_| ty::arg { ty: ty::mk_err() }) + fn err_args(len: uint) -> ~[ty::t] { + vec::from_fn(len, |_| ty::mk_err()) } // A generic function for checking assignment expressions @@ -1701,11 +1701,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, let fty = if error_happened { fty_sig = FnSig { bound_lifetime_names: opt_vec::Empty, - inputs: fn_ty.sig.inputs.map(|_| { - arg { - ty: ty::mk_err() - } - }), + inputs: fn_ty.sig.inputs.map(|_| ty::mk_err()), output: ty::mk_err() }; ty::mk_err() @@ -3132,24 +3128,23 @@ pub fn check_enum_variants(ccx: @mut CrateCtxt, } disr_vals.push(*disr_val); let ctor_ty = ty::node_id_to_type(ccx.tcx, v.node.id); - let arg_tys; let this_disr_val = *disr_val; *disr_val += 1; - match v.node.kind { + let arg_tys = match v.node.kind { ast::tuple_variant_kind(ref args) if args.len() > 0u => { - arg_tys = Some(ty::ty_fn_args(ctor_ty).map(|a| a.ty)); + Some(ty::ty_fn_args(ctor_ty).map(|a| *a)) } ast::tuple_variant_kind(_) => { - arg_tys = Some(~[]); + Some(~[]) } ast::struct_variant_kind(_) => { - arg_tys = Some(ty::lookup_struct_fields( + Some(ty::lookup_struct_fields( ccx.tcx, local_def(v.node.id)).map(|cf| - ty::node_id_to_type(ccx.tcx, cf.id.node))); + ty::node_id_to_type(ccx.tcx, cf.id.node))) } - } + }; match arg_tys { None => {} @@ -3281,7 +3276,7 @@ pub fn instantiate_path(fcx: @mut FnCtxt, debug!(">>> instantiate_path"); let ty_param_count = tpt.generics.type_param_defs.len(); - let ty_substs_len = vec::len(pth.types); + let ty_substs_len = pth.types.len(); debug!("ty_param_count=%? ty_substs_len=%?", ty_param_count, @@ -3454,11 +3449,6 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { fn param(ccx: @mut CrateCtxt, n: uint) -> ty::t { ty::mk_param(ccx.tcx, n, local_def(0)) } - fn arg(ty: ty::t) -> ty::arg { - arg { - ty: ty - } - } let tcx = ccx.tcx; let (n_tps, inputs, output) = match *ccx.tcx.sess.str_of(it.ident) { @@ -3466,15 +3456,13 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { ~"pref_align_of" | ~"min_align_of" => (1u, ~[], ty::mk_uint()), ~"init" => (1u, ~[], param(ccx, 0u)), ~"uninit" => (1u, ~[], param(ccx, 0u)), - ~"forget" => (1u, ~[arg(param(ccx, 0u))], ty::mk_nil()), - ~"transmute" => (2, ~[ arg(param(ccx, 0)) ], param(ccx, 1)), + ~"forget" => (1u, ~[ param(ccx, 0) ], ty::mk_nil()), + ~"transmute" => (2, ~[ param(ccx, 0) ], param(ccx, 1)), ~"move_val" | ~"move_val_init" => { (1u, ~[ - arg(ty::mk_mut_rptr(tcx, - ty::re_bound(ty::br_anon(0)), - param(ccx, 0))), - arg(param(ccx, 0u)) + ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)), param(ccx, 0)), + param(ccx, 0u) ], ty::mk_nil()) } @@ -3483,30 +3471,26 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { ~"atomic_cxchg" | ~"atomic_cxchg_acq"| ~"atomic_cxchg_rel" => { (0, ~[ - arg(ty::mk_mut_rptr(tcx, - ty::re_bound(ty::br_anon(0)), - ty::mk_int())), - arg(ty::mk_int()), - arg(ty::mk_int()) + ty::mk_mut_rptr(tcx, + ty::re_bound(ty::br_anon(0)), + ty::mk_int()), + ty::mk_int(), + ty::mk_int() ], ty::mk_int()) } ~"atomic_load" | ~"atomic_load_acq" => { (0, ~[ - arg(ty::mk_imm_rptr(tcx, - ty::re_bound(ty::br_anon(0)), - ty::mk_int())) + ty::mk_imm_rptr(tcx, ty::re_bound(ty::br_anon(0)), ty::mk_int()) ], ty::mk_int()) } ~"atomic_store" | ~"atomic_store_rel" => { (0, ~[ - arg(ty::mk_mut_rptr(tcx, - ty::re_bound(ty::br_anon(0)), - ty::mk_int())), - arg(ty::mk_int()) + ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)), ty::mk_int()), + ty::mk_int() ], ty::mk_nil()) } @@ -3515,10 +3499,8 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { ~"atomic_xchg_rel" | ~"atomic_xadd_rel" | ~"atomic_xsub_rel" => { (0, ~[ - arg(ty::mk_mut_rptr(tcx, - ty::re_bound(ty::br_anon(0)), - ty::mk_int())), - arg(ty::mk_int()) + ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)), ty::mk_int()), + ty::mk_int() ], ty::mk_int()) } @@ -3536,7 +3518,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { ty: tydesc_ty, mutbl: ast::m_imm }); - (0, ~[ arg(td_ptr), arg(visitor_object_ty) ], ty::mk_nil()) + (0, ~[ td_ptr, visitor_object_ty ], ty::mk_nil()) } ~"frame_address" => { let fty = ty::mk_closure(ccx.tcx, ty::ClosureTy { @@ -3546,16 +3528,11 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { region: ty::re_bound(ty::br_anon(0)), sig: ty::FnSig { bound_lifetime_names: opt_vec::Empty, - inputs: ~[ - arg { - ty: ty::mk_imm_ptr(ccx.tcx, - ty::mk_mach_uint(ast::ty_u8)) - } - ], + inputs: ~[ty::mk_imm_ptr(ccx.tcx, ty::mk_mach_uint(ast::ty_u8))], output: ty::mk_nil() } }); - (0u, ~[ arg(fty) ], ty::mk_nil()) + (0u, ~[fty], ty::mk_nil()) } ~"morestack_addr" => { (0u, ~[], ty::mk_nil_ptr(ccx.tcx)) @@ -3563,101 +3540,102 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) { ~"memmove32" => { (0, ~[ - arg(ty::mk_ptr(tcx, ty::mt { + ty::mk_ptr(tcx, ty::mt { ty: ty::mk_u8(), mutbl: ast::m_mutbl - })), - arg(ty::mk_ptr(tcx, ty::mt { + }), + ty::mk_ptr(tcx, ty::mt { ty: ty::mk_u8(), mutbl: ast::m_imm - })), - arg(ty::mk_u32()) + }), + ty::mk_u32() ], ty::mk_nil()) } ~"memmove64" => { (0, - ~[arg(ty::mk_ptr(tcx, ty::mt { - ty: ty::mk_u8(), - mutbl: ast::m_mutbl - })), - arg(ty::mk_ptr(tcx, ty::mt { - ty: ty::mk_u8(), - mutbl: ast::m_imm - })), - arg(ty::mk_u64()) + ~[ + ty::mk_ptr(tcx, ty::mt { + ty: ty::mk_u8(), + mutbl: ast::m_mutbl + }), + ty::mk_ptr(tcx, ty::mt { + ty: ty::mk_u8(), + mutbl: ast::m_imm + }), + ty::mk_u64() ], ty::mk_nil()) } - ~"sqrtf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), - ~"sqrtf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"sqrtf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()), + ~"sqrtf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()), ~"powif32" => { (0, - ~[ arg(ty::mk_f32()), arg(ty::mk_i32()) ], + ~[ ty::mk_f32(), ty::mk_i32() ], ty::mk_f32()) } ~"powif64" => { (0, - ~[ arg(ty::mk_f64()), arg(ty::mk_i32()) ], + ~[ ty::mk_f64(), ty::mk_i32() ], ty::mk_f64()) } - ~"sinf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), - ~"sinf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), - ~"cosf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), - ~"cosf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"sinf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()), + ~"sinf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()), + ~"cosf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()), + ~"cosf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()), ~"powf32" => { (0, - ~[ arg(ty::mk_f32()), arg(ty::mk_f32()) ], + ~[ ty::mk_f32(), ty::mk_f32() ], ty::mk_f32()) } ~"powf64" => { (0, - ~[ arg(ty::mk_f64()), arg(ty::mk_f64()) ], + ~[ ty::mk_f64(), ty::mk_f64() ], ty::mk_f64()) } - ~"expf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), - ~"expf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), - ~"exp2f32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), - ~"exp2f64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), - ~"logf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), - ~"logf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), - ~"log10f32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), - ~"log10f64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), - ~"log2f32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), - ~"log2f64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), + ~"expf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()), + ~"expf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()), + ~"exp2f32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()), + ~"exp2f64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()), + ~"logf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()), + ~"logf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()), + ~"log10f32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()), + ~"log10f64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()), + ~"log2f32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()), + ~"log2f64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()), ~"fmaf32" => { (0, - ~[ arg(ty::mk_f32()), arg(ty::mk_f32()), arg(ty::mk_f32()) ], + ~[ ty::mk_f32(), ty::mk_f32(), ty::mk_f32() ], ty::mk_f32()) } ~"fmaf64" => { (0, - ~[ arg(ty::mk_f64()), arg(ty::mk_f64()), arg(ty::mk_f64()) ], + ~[ ty::mk_f64(), ty::mk_f64(), ty::mk_f64() ], ty::mk_f64()) } - ~"fabsf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), - ~"fabsf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), - ~"floorf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), - ~"floorf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), - ~"ceilf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), - ~"ceilf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), - ~"truncf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()), - ~"truncf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()), - ~"ctpop8" => (0, ~[ arg(ty::mk_i8()) ], ty::mk_i8()), - ~"ctpop16" => (0, ~[ arg(ty::mk_i16()) ], ty::mk_i16()), - ~"ctpop32" => (0, ~[ arg(ty::mk_i32()) ], ty::mk_i32()), - ~"ctpop64" => (0, ~[ arg(ty::mk_i64()) ], ty::mk_i64()), - ~"ctlz8" => (0, ~[ arg(ty::mk_i8()) ], ty::mk_i8()), - ~"ctlz16" => (0, ~[ arg(ty::mk_i16()) ], ty::mk_i16()), - ~"ctlz32" => (0, ~[ arg(ty::mk_i32()) ], ty::mk_i32()), - ~"ctlz64" => (0, ~[ arg(ty::mk_i64()) ], ty::mk_i64()), - ~"cttz8" => (0, ~[ arg(ty::mk_i8()) ], ty::mk_i8()), - ~"cttz16" => (0, ~[ arg(ty::mk_i16()) ], ty::mk_i16()), - ~"cttz32" => (0, ~[ arg(ty::mk_i32()) ], ty::mk_i32()), - ~"cttz64" => (0, ~[ arg(ty::mk_i64()) ], ty::mk_i64()), - ~"bswap16" => (0, ~[ arg(ty::mk_i16()) ], ty::mk_i16()), - ~"bswap32" => (0, ~[ arg(ty::mk_i32()) ], ty::mk_i32()), - ~"bswap64" => (0, ~[ arg(ty::mk_i64()) ], ty::mk_i64()), + ~"fabsf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()), + ~"fabsf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()), + ~"floorf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()), + ~"floorf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()), + ~"ceilf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()), + ~"ceilf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()), + ~"truncf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()), + ~"truncf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()), + ~"ctpop8" => (0, ~[ ty::mk_i8() ], ty::mk_i8()), + ~"ctpop16" => (0, ~[ ty::mk_i16() ], ty::mk_i16()), + ~"ctpop32" => (0, ~[ ty::mk_i32() ], ty::mk_i32()), + ~"ctpop64" => (0, ~[ ty::mk_i64() ], ty::mk_i64()), + ~"ctlz8" => (0, ~[ ty::mk_i8() ], ty::mk_i8()), + ~"ctlz16" => (0, ~[ ty::mk_i16() ], ty::mk_i16()), + ~"ctlz32" => (0, ~[ ty::mk_i32() ], ty::mk_i32()), + ~"ctlz64" => (0, ~[ ty::mk_i64() ], ty::mk_i64()), + ~"cttz8" => (0, ~[ ty::mk_i8() ], ty::mk_i8()), + ~"cttz16" => (0, ~[ ty::mk_i16() ], ty::mk_i16()), + ~"cttz32" => (0, ~[ ty::mk_i32() ], ty::mk_i32()), + ~"cttz64" => (0, ~[ ty::mk_i64() ], ty::mk_i64()), + ~"bswap16" => (0, ~[ ty::mk_i16() ], ty::mk_i16()), + ~"bswap32" => (0, ~[ ty::mk_i32() ], ty::mk_i32()), + ~"bswap64" => (0, ~[ ty::mk_i64() ], ty::mk_i64()), ref other => { tcx.sess.span_err(it.span, ~"unrecognized intrinsic function: `" + diff --git a/src/librustc/middle/typeck/check/regionmanip.rs b/src/librustc/middle/typeck/check/regionmanip.rs index cfbd012b7b7..87b105e3c7d 100644 --- a/src/librustc/middle/typeck/check/regionmanip.rs +++ b/src/librustc/middle/typeck/check/regionmanip.rs @@ -258,7 +258,7 @@ pub fn relate_free_regions( let mut all_tys = ~[]; for fn_sig.inputs.each |arg| { - all_tys.push(arg.ty); + all_tys.push(*arg); } for self_ty.each |&t| { all_tys.push(t); diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 2869c3737c9..394d00bef2d 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -13,7 +13,6 @@ // substitutions. use middle::pat_util; -use middle::ty::arg; use middle::ty; use middle::typeck::check::{FnCtxt, SelfInfo}; use middle::typeck::infer::{force_all, resolve_all, resolve_region}; @@ -63,14 +62,9 @@ fn resolve_method_map_entry(fcx: @mut FnCtxt, sp: span, id: ast::node_id) { match fcx.inh.method_map.find(&id) { None => {} Some(mme) => { - for resolve_type_vars_in_type(fcx, sp, mme.self_arg.ty).each |t| { + for resolve_type_vars_in_type(fcx, sp, mme.self_ty).each |t| { let method_map = fcx.ccx.method_map; - let new_entry = method_map_entry { - self_arg: arg { - ty: *t - }, - ..*mme - }; + let new_entry = method_map_entry { self_ty: *t, ..*mme }; debug!("writeback::resolve_method_map_entry(id=%?, \ new_entry=%?)", id, new_entry); diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 17103806d1e..c64a0235eb1 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -156,7 +156,7 @@ pub fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo { did: local_def(ast_method.id), n_tps: ast_method.generics.ty_params.len(), ident: ast_method.ident, - self_type: ast_method.self_ty.node + explicit_self: ast_method.explicit_self.node } } @@ -383,7 +383,7 @@ pub impl CoherenceChecker { did: new_did, n_tps: trait_method.generics.type_param_defs.len(), ident: trait_method.ident, - self_type: trait_method.self_ty + explicit_self: trait_method.explicit_self }, trait_method_def_id: trait_method.def_id }; @@ -527,7 +527,7 @@ pub impl CoherenceChecker { #[cfg(stage0)] fn each_provided_trait_method(&self, trait_did: ast::def_id, - f: &fn(x: @ty::method) -> bool) { + f: &fn(@ty::Method) -> bool) { // Make a list of all the names of the provided methods. // XXX: This is horrible. let mut provided_method_idents = HashSet::new(); @@ -547,7 +547,7 @@ pub impl CoherenceChecker { #[cfg(not(stage0))] fn each_provided_trait_method(&self, trait_did: ast::def_id, - f: &fn(x: @ty::method) -> bool) -> bool { + f: &fn(x: @ty::Method) -> bool) -> bool { // Make a list of all the names of the provided methods. // XXX: This is horrible. let mut provided_method_idents = HashSet::new(); @@ -975,7 +975,7 @@ pub impl CoherenceChecker { did: new_did, n_tps: trait_method_info.ty.generics.type_param_defs.len(), ident: trait_method_info.ty.ident, - self_type: trait_method_info.ty.self_ty + explicit_self: trait_method_info.ty.explicit_self }, trait_method_def_id: trait_method_info.def_id }; @@ -1073,7 +1073,7 @@ fn subst_receiver_types_in_method_ty( impl_id: ast::node_id, trait_ref: &ty::TraitRef, new_def_id: ast::def_id, - method: &ty::method) -> ty::method + method: &ty::Method) -> ty::Method { /*! * Substitutes the values for the receiver's type parameters @@ -1117,19 +1117,22 @@ fn subst_receiver_types_in_method_ty( tps: combined_tps }; - ty::method { - ident: method.ident, + ty::Method::new( + method.ident, + + // method types *can* appear in the generic bounds + method.generics.subst(tcx, &combined_substs), // method tps cannot appear in the self_ty, so use `substs` from trait ref - transformed_self_ty: method.transformed_self_ty.subst(tcx, &trait_ref.substs), - - // method types *can* appear in the generic bounds or the fty - generics: method.generics.subst(tcx, &combined_substs), - fty: method.fty.subst(tcx, &combined_substs), - self_ty: method.self_ty, - vis: method.vis, - def_id: new_def_id - } + method.transformed_self_ty.subst(tcx, &trait_ref.substs), + + // method types *can* appear in the fty + method.fty.subst(tcx, &combined_substs), + + method.explicit_self, + method.vis, + new_def_id + ) } pub fn check_coherence(crate_context: @mut CrateCtxt, crate: @crate) { diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index dd432352432..4773e637c35 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -52,7 +52,7 @@ use syntax::ast_map; use syntax::ast_util::{local_def, split_trait_methods}; use syntax::codemap::span; use syntax::codemap; -use syntax::print::pprust::{path_to_str, self_ty_to_str}; +use syntax::print::pprust::{path_to_str, explicit_self_to_str}; use syntax::visit; use syntax::opt_vec::OptVec; use syntax::opt_vec; @@ -227,26 +227,26 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, }, _) => { let trait_ty_generics = ty_generics(ccx, region_paramd, generics, 0); - // For each method, construct a suitable ty::method and + // For each method, construct a suitable ty::Method and // store it into the `tcx.methods` table: for ms.each |m| { let ty_method = @match m { &ast::required(ref m) => { ty_method_of_trait_method( ccx, trait_id, region_paramd, generics, - &m.id, &m.ident, &m.self_ty, + &m.id, &m.ident, &m.explicit_self, &m.generics, &m.purity, &m.decl) } &ast::provided(ref m) => { ty_method_of_trait_method( ccx, trait_id, region_paramd, generics, - &m.id, &m.ident, &m.self_ty, + &m.id, &m.ident, &m.explicit_self, &m.generics, &m.purity, &m.decl) } }; - if ty_method.self_ty == ast::sty_static { + if ty_method.explicit_self == ast::sty_static { make_static_method_ty(ccx, trait_id, ty_method, &trait_ty_generics); } @@ -270,7 +270,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, fn make_static_method_ty(ccx: &CrateCtxt, trait_id: ast::node_id, - m: &ty::method, + m: &ty::Method, trait_ty_generics: &ty::Generics) { // If declaration is // @@ -376,27 +376,27 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_generics: &ast::Generics, m_id: &ast::node_id, m_ident: &ast::ident, - m_self_ty: &ast::self_ty, + m_explicit_self: &ast::explicit_self, m_generics: &ast::Generics, m_purity: &ast::purity, - m_decl: &ast::fn_decl) -> ty::method + m_decl: &ast::fn_decl) -> ty::Method { let trait_self_ty = ty::mk_self(this.tcx, local_def(trait_id)); - let rscope = MethodRscope::new(m_self_ty.node, trait_rp, trait_generics); + let rscope = MethodRscope::new(m_explicit_self.node, trait_rp, trait_generics); let (transformed_self_ty, fty) = astconv::ty_of_method(this, &rscope, *m_purity, &m_generics.lifetimes, - trait_self_ty, *m_self_ty, m_decl); + trait_self_ty, *m_explicit_self, m_decl); let num_trait_type_params = trait_generics.ty_params.len(); - ty::method { - ident: *m_ident, - generics: ty_generics(this, None, m_generics, num_trait_type_params), - transformed_self_ty: transformed_self_ty, - fty: fty, - self_ty: m_self_ty.node, + ty::Method::new( + *m_ident, + ty_generics(this, None, m_generics, num_trait_type_params), + transformed_self_ty, + fty, + m_explicit_self.node, // assume public, because this is only invoked on trait methods - vis: ast::public, - def_id: local_def(*m_id) - } + ast::public, + local_def(*m_id) + ) } } @@ -444,7 +444,7 @@ pub fn ensure_supertraits(ccx: &CrateCtxt, pub fn compare_impl_method(tcx: ty::ctxt, impl_tps: uint, cm: &ConvertedMethod, - trait_m: &ty::method, + trait_m: &ty::Method, trait_substs: &ty::substs, self_ty: ty::t) { debug!("compare_impl_method()"); @@ -459,7 +459,7 @@ pub fn compare_impl_method(tcx: ty::ctxt, // that the error messages you get out of this code are a bit more // inscrutable, particularly for cases where one method has no // self. - match (&trait_m.self_ty, &impl_m.self_ty) { + match (&trait_m.explicit_self, &impl_m.explicit_self) { (&ast::sty_static, &ast::sty_static) => {} (&ast::sty_static, _) => { tcx.sess.span_err( @@ -467,7 +467,7 @@ pub fn compare_impl_method(tcx: ty::ctxt, fmt!("method `%s` has a `%s` declaration in the impl, \ but not in the trait", *tcx.sess.str_of(trait_m.ident), - self_ty_to_str(impl_m.self_ty, tcx.sess.intr()))); + explicit_self_to_str(impl_m.explicit_self, tcx.sess.intr()))); return; } (_, &ast::sty_static) => { @@ -476,7 +476,7 @@ pub fn compare_impl_method(tcx: ty::ctxt, fmt!("method `%s` has a `%s` declaration in the trait, \ but not in the impl", *tcx.sess.str_of(trait_m.ident), - self_ty_to_str(trait_m.self_ty, tcx.sess.intr()))); + explicit_self_to_str(trait_m.explicit_self, tcx.sess.intr()))); return; } _ => { @@ -499,15 +499,15 @@ pub fn compare_impl_method(tcx: ty::ctxt, return; } - if vec::len(impl_m.fty.sig.inputs) != vec::len(trait_m.fty.sig.inputs) { + if impl_m.fty.sig.inputs.len() != trait_m.fty.sig.inputs.len() { tcx.sess.span_err( cm.span, fmt!("method `%s` has %u parameter%s \ but the trait has %u", *tcx.sess.str_of(trait_m.ident), - vec::len(impl_m.fty.sig.inputs), - if vec::len(impl_m.fty.sig.inputs) == 1 { "" } else { "s" }, - vec::len(trait_m.fty.sig.inputs))); + impl_m.fty.sig.inputs.len(), + if impl_m.fty.sig.inputs.len() == 1 { "" } else { "s" }, + trait_m.fty.sig.inputs.len())); return; } @@ -576,14 +576,10 @@ pub fn compare_impl_method(tcx: ty::ctxt, // represent the self argument (unless this is a static method). // This argument will have the *transformed* self type. for trait_m.transformed_self_ty.each |&t| { - trait_fn_args.push(ty::arg { - ty: t - }); + trait_fn_args.push(t); } for impl_m.transformed_self_ty.each |&t| { - impl_fn_args.push(ty::arg { - ty: t - }); + impl_fn_args.push(t); } // Add in the normal arguments. @@ -727,7 +723,7 @@ pub fn convert_field(ccx: &CrateCtxt, } pub struct ConvertedMethod { - mty: @ty::method, + mty: @ty::Method, id: ast::node_id, span: span, body_id: ast::node_id @@ -780,16 +776,16 @@ pub fn convert_methods(ccx: &CrateCtxt, untransformed_rcvr_ty: ty::t, rcvr_generics: &ast::Generics, rcvr_visibility: ast::visibility, - method_generics: &ast::Generics) -> ty::method + method_generics: &ast::Generics) -> ty::Method { - let rscope = MethodRscope::new(m.self_ty.node, + let rscope = MethodRscope::new(m.explicit_self.node, rp, rcvr_generics); let (transformed_self_ty, fty) = astconv::ty_of_method(ccx, &rscope, m.purity, &method_generics.lifetimes, untransformed_rcvr_ty, - m.self_ty, &m.decl); + m.explicit_self, &m.decl); // if the method specifies a visibility, use that, otherwise // inherit the visibility from the impl (so `foo` in `pub impl @@ -798,15 +794,15 @@ pub fn convert_methods(ccx: &CrateCtxt, let method_vis = m.vis.inherit_from(rcvr_visibility); let num_rcvr_type_params = rcvr_generics.ty_params.len(); - ty::method { - ident: m.ident, - generics: ty_generics(ccx, None, &m.generics, num_rcvr_type_params), - transformed_self_ty: transformed_self_ty, - fty: fty, - self_ty: m.self_ty.node, - vis: method_vis, - def_id: local_def(m.id) - } + ty::Method::new( + m.ident, + ty_generics(ccx, None, &m.generics, num_rcvr_type_params), + transformed_self_ty, + fty, + m.explicit_self.node, + method_vis, + local_def(m.id) + ) } } diff --git a/src/librustc/middle/typeck/infer/combine.rs b/src/librustc/middle/typeck/infer/combine.rs index a845d6fe9d0..fcd2c6ffe59 100644 --- a/src/librustc/middle/typeck/infer/combine.rs +++ b/src/librustc/middle/typeck/infer/combine.rs @@ -55,7 +55,7 @@ // now. use middle::ty::{FloatVar, FnSig, IntVar, TyVar}; -use middle::ty::{IntType, UintType, arg, substs}; +use middle::ty::{IntType, UintType, substs}; use middle::ty; use middle::typeck::infer::glb::Glb; use middle::typeck::infer::lub::Lub; @@ -95,7 +95,7 @@ pub trait Combine { b: &ty::ClosureTy) -> cres<ty::ClosureTy>; fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig>; fn flds(&self, a: ty::field, b: ty::field) -> cres<ty::field>; - fn args(&self, a: ty::arg, b: ty::arg) -> cres<ty::arg>; + fn args(&self, a: ty::t, b: ty::t) -> cres<ty::t>; fn sigils(&self, p1: ast::Sigil, p2: ast::Sigil) -> cres<ast::Sigil>; fn purities(&self, a: purity, b: purity) -> cres<purity>; fn abis(&self, a: AbiSet, b: AbiSet) -> cres<AbiSet>; @@ -311,12 +311,9 @@ pub fn super_flds<C:Combine>( } } -pub fn super_args<C:Combine>(this: &C, a: ty::arg, b: ty::arg) - -> cres<ty::arg> { - do this.contratys(a.ty, b.ty).chain |t| { - Ok(arg { - ty: t - }) +pub fn super_args<C:Combine>(this: &C, a: ty::t, b: ty::t) -> cres<ty::t> { + do this.contratys(a, b).chain |t| { + Ok(t) } } @@ -407,10 +404,7 @@ pub fn super_bare_fn_tys<C:Combine>( pub fn super_fn_sigs<C:Combine>( this: &C, a_f: &ty::FnSig, b_f: &ty::FnSig) -> cres<ty::FnSig> { - fn argvecs<C:Combine>(this: &C, - a_args: &[ty::arg], - b_args: &[ty::arg]) -> cres<~[ty::arg]> - { + fn argvecs<C:Combine>(this: &C, a_args: &[ty::t], b_args: &[ty::t]) -> cres<~[ty::t]> { if vec::same_length(a_args, b_args) { map_vec2(a_args, b_args, |a, b| this.args(*a, *b)) } else { diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index 462d7a003f4..42e42ddb1e7 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -153,7 +153,7 @@ impl Combine for Glb { super_trait_stores(self, vk, a, b) } - fn args(&self, a: ty::arg, b: ty::arg) -> cres<ty::arg> { + fn args(&self, a: ty::t, b: ty::t) -> cres<ty::t> { super_args(self, a, b) } diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/typeck/infer/lub.rs index bd5821873d2..20a051f0531 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/typeck/infer/lub.rs @@ -236,7 +236,7 @@ impl Combine for Lub { super_trait_stores(self, vk, a, b) } - fn args(&self, a: ty::arg, b: ty::arg) -> cres<ty::arg> { + fn args(&self, a: ty::t, b: ty::t) -> cres<ty::t> { super_args(self, a, b) } diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index 48d7765f88e..ca083bc2d86 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -245,7 +245,7 @@ impl Combine for Sub { super_trait_stores(self, vk, a, b) } - fn args(&self, a: ty::arg, b: ty::arg) -> cres<ty::arg> { + fn args(&self, a: ty::t, b: ty::t) -> cres<ty::t> { super_args(self, a, b) } diff --git a/src/librustc/middle/typeck/infer/to_str.rs b/src/librustc/middle/typeck/infer/to_str.rs index 779346c380c..d9088c06493 100644 --- a/src/librustc/middle/typeck/infer/to_str.rs +++ b/src/librustc/middle/typeck/infer/to_str.rs @@ -31,7 +31,7 @@ impl InferStr for ty::t { 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)), ", "), + str::connect(self.inputs.map(|a| a.inf_str(cx)), ", "), self.output.inf_str(cx)) } } diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 5da14d99171..0dec0fc937b 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -118,13 +118,13 @@ pub struct method_param { pub struct method_map_entry { // the type of the self parameter, which is not reflected in the fn type // (FIXME #3446) - self_arg: ty::arg, + self_ty: ty::t, // the mode of `self` self_mode: ty::SelfMode, // the type of explicit self on the method - explicit_self: ast::self_ty_, + explicit_self: ast::explicit_self_, // method details being invoked origin: method_origin, @@ -310,7 +310,7 @@ fn check_main_fn_ty(ccx: @mut CrateCtxt, _ => () } let mut ok = ty::type_is_nil(fn_ty.sig.output); - let num_args = vec::len(fn_ty.sig.inputs); + let num_args = fn_ty.sig.inputs.len(); ok &= num_args == 0u; if !ok { tcx.sess.span_err( @@ -351,22 +351,15 @@ fn check_start_fn_ty(ccx: @mut CrateCtxt, _ => () } - fn arg(ty: ty::t) -> ty::arg { - ty::arg { - ty: ty - } - } - let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy { purity: ast::impure_fn, abis: abi::AbiSet::Rust(), sig: ty::FnSig { bound_lifetime_names: opt_vec::Empty, inputs: ~[ - arg(ty::mk_int()), - arg(ty::mk_imm_ptr(tcx, - ty::mk_imm_ptr(tcx, ty::mk_u8()))), - arg(ty::mk_imm_ptr(tcx, ty::mk_u8())) + ty::mk_int(), + ty::mk_imm_ptr(tcx, ty::mk_imm_ptr(tcx, ty::mk_u8())), + ty::mk_imm_ptr(tcx, ty::mk_u8()) ], output: ty::mk_int() } diff --git a/src/librustc/middle/typeck/rscope.rs b/src/librustc/middle/typeck/rscope.rs index f7bf5106fa6..7c37784b09d 100644 --- a/src/librustc/middle/typeck/rscope.rs +++ b/src/librustc/middle/typeck/rscope.rs @@ -142,7 +142,7 @@ impl RegionParameterization { } pub struct MethodRscope { - self_ty: ast::self_ty_, + explicit_self: ast::explicit_self_, variance: Option<ty::region_variance>, region_param_names: RegionParamNames, } @@ -150,14 +150,14 @@ pub struct MethodRscope { impl MethodRscope { // `generics` here refers to the generics of the outer item (impl or // trait). - pub fn new(self_ty: ast::self_ty_, + pub fn new(explicit_self: ast::explicit_self_, variance: Option<ty::region_variance>, rcvr_generics: &ast::Generics) -> MethodRscope { let region_param_names = RegionParamNames::from_generics(rcvr_generics); MethodRscope { - self_ty: self_ty, + explicit_self: explicit_self, variance: variance, region_param_names: region_param_names } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 804b23025f0..13a2f376c06 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -11,7 +11,7 @@ use metadata::encoder; use middle::ty::{ReSkolemized, ReVar}; use middle::ty::{bound_region, br_anon, br_named, br_self, br_cap_avoid}; -use middle::ty::{br_fresh, ctxt, field, method}; +use middle::ty::{br_fresh, ctxt, field}; use middle::ty::{mt, t, param_ty}; use middle::ty::{re_bound, re_free, re_scope, re_infer, re_static, Region, re_empty}; @@ -281,7 +281,7 @@ pub fn tys_to_str(cx: ctxt, ts: &[t]) -> ~str { pub fn fn_sig_to_str(cx: ctxt, typ: &ty::FnSig) -> ~str { fmt!("fn%s -> %s", - tys_to_str(cx, typ.inputs.map(|a| a.ty)), + tys_to_str(cx, typ.inputs.map(|a| *a)), ty_to_str(cx, typ.output)) } @@ -290,8 +290,8 @@ pub fn trait_ref_to_str(cx: ctxt, trait_ref: &ty::TraitRef) -> ~str { } pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { - fn fn_input_to_str(cx: ctxt, input: ty::arg) -> ~str { - ty_to_str(cx, input.ty) + fn fn_input_to_str(cx: ctxt, input: ty::t) -> ~str { + ty_to_str(cx, input) } fn bare_fn_to_str(cx: ctxt, purity: ast::purity, @@ -375,7 +375,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { } } } - fn method_to_str(cx: ctxt, m: method) -> ~str { + fn method_to_str(cx: ctxt, m: ty::Method) -> ~str { bare_fn_to_str(cx, m.fty.purity, m.fty.abis, @@ -470,7 +470,7 @@ pub fn parameterized(cx: ctxt, } }; - if vec::len(tps) > 0u { + if tps.len() > 0u { let strs = vec::map(tps, |t| ty_to_str(cx, *t)); fmt!("%s%s<%s>", base, r_str, str::connect(strs, ",")) } else { @@ -633,15 +633,15 @@ impl Repr for ty::Generics { } } -impl Repr for ty::method { +impl Repr for ty::Method { fn repr(&self, tcx: ctxt) -> ~str { fmt!("method {ident: %s, generics: %s, transformed_self_ty: %s, \ - fty: %s, self_ty: %s, vis: %s, def_id: %s}", + fty: %s, explicit_self: %s, vis: %s, def_id: %s}", self.ident.repr(tcx), self.generics.repr(tcx), self.transformed_self_ty.repr(tcx), self.fty.repr(tcx), - self.self_ty.repr(tcx), + self.explicit_self.repr(tcx), self.vis.repr(tcx), self.def_id.repr(tcx)) } @@ -653,7 +653,7 @@ impl Repr for ast::ident { } } -impl Repr for ast::self_ty_ { +impl Repr for ast::explicit_self_ { fn repr(&self, _tcx: ctxt) -> ~str { fmt!("%?", *self) } @@ -685,18 +685,12 @@ impl Repr for typeck::method_map_entry { fmt!("method_map_entry {self_arg: %s, \ explicit_self: %s, \ origin: %s}", - self.self_arg.repr(tcx), + self.self_ty.repr(tcx), self.explicit_self.repr(tcx), self.origin.repr(tcx)) } } -impl Repr for ty::arg { - fn repr(&self, tcx: ctxt) -> ~str { - fmt!("(%s)", self.ty.repr(tcx)) - } -} - impl Repr for typeck::method_origin { fn repr(&self, tcx: ctxt) -> ~str { match self { diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index bd6777df4af..12689466c8c 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -187,7 +187,7 @@ fn get_method_sig( &ty_m.decl, ty_m.purity, ty_m.ident, - Some(ty_m.self_ty.node), + Some(ty_m.explicit_self.node), &ty_m.generics, extract::interner() )) @@ -197,7 +197,7 @@ fn get_method_sig( &m.decl, m.purity, m.ident, - Some(m.self_ty.node), + Some(m.explicit_self.node), &m.generics, extract::interner() )) @@ -218,7 +218,7 @@ fn get_method_sig( &method.decl, method.purity, method.ident, - Some(method.self_ty.node), + Some(method.explicit_self.node), &method.generics, extract::interner() )) @@ -405,7 +405,7 @@ mod test { #[test] fn should_not_add_impl_trait_types_if_none() { let doc = mk_doc(~"impl int { fn a() { } }"); - assert!(vec::len(doc.cratemod().impls()[0].trait_types) == 0); + assert!(doc.cratemod().impls()[0].trait_types.len() == 0); } #[test] diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 062ad403dd6..07c1c226d1f 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -628,7 +628,6 @@ pub mod writer { use core::io; use core::str; - use core::vec; // ebml writing pub struct Encoder { @@ -707,7 +706,7 @@ pub mod writer { fn wr_tagged_bytes(&mut self, tag_id: uint, b: &[u8]) { write_vuint(self.writer, tag_id); - write_vuint(self.writer, vec::len(b)); + write_vuint(self.writer, b.len()); self.writer.write(b); } @@ -760,7 +759,7 @@ pub mod writer { } fn wr_bytes(&mut self, b: &[u8]) { - debug!("Write %u bytes", vec::len(b)); + debug!("Write %u bytes", b.len()); self.writer.write(b); } diff --git a/src/libstd/fun_treemap.rs b/src/libstd/fun_treemap.rs index 3bffeddbe09..6b051fa21b1 100644 --- a/src/libstd/fun_treemap.rs +++ b/src/libstd/fun_treemap.rs @@ -33,45 +33,40 @@ enum TreeNode<K, V> { pub fn init<K, V>() -> Treemap<K, V> { @Empty } /// Insert a value into the map -pub fn insert<K:Copy + Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K, v: V) - -> Treemap<K, V> { +pub fn insert<K:Copy + Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K, v: V) -> Treemap<K, V> { @match m { - @Empty => Node(@k, @v, @Empty, @Empty), - @Node(@copy kk, vv, left, right) => { - if k < kk { - Node(@kk, vv, insert(left, k, v), right) - } else if k == kk { - Node(@kk, @v, left, right) - } else { Node(@kk, vv, left, insert(right, k, v)) } - } - } + @Empty => Node(@k, @v, @Empty, @Empty), + @Node(@copy kk, vv, left, right) => cond!( + (k < kk) { Node(@kk, vv, insert(left, k, v), right) } + (k == kk) { Node(@kk, @v, left, right) } + _ { Node(@kk, vv, left, insert(right, k, v)) } + ) + } } /// Find a value based on the key pub fn find<K:Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K) -> Option<V> { match *m { - Empty => None, - Node(@ref kk, @copy v, left, right) => { - if k == *kk { - Some(v) - } else if k < *kk { find(left, k) } else { find(right, k) } - } + Empty => None, + Node(@ref kk, @copy v, left, right) => cond!( + (k == *kk) { Some(v) } + (k < *kk) { find(left, k) } + _ { find(right, k) } + ) } } /// Visit all pairs in the map in order. pub fn traverse<K, V: Copy>(m: Treemap<K, V>, f: &fn(&K, &V)) { match *m { - Empty => (), - /* - Previously, this had what looked like redundant - matches to me, so I changed it. but that may be a - de-optimization -- tjc - */ - Node(@ref k, @ref v, left, right) => { - traverse(left, f); - f(k, v); - traverse(right, f); - } + Empty => (), + // Previously, this had what looked like redundant + // matches to me, so I changed it. but that may be a + // de-optimization -- tjc + Node(@ref k, @ref v, left, right) => { + traverse(left, f); + f(k, v); + traverse(right, f); + } } } diff --git a/src/libstd/md4.rs b/src/libstd/md4.rs index 71b62ca36a5..84561256cd1 100644 --- a/src/libstd/md4.rs +++ b/src/libstd/md4.rs @@ -23,7 +23,7 @@ pub fn md4(msg: &[u8]) -> Quad { // subtle: if orig_len is merely uint, then the code below // which performs shifts by 32 bits or more has undefined // results. - let orig_len: u64 = (vec::len(msg) * 8u) as u64; + let orig_len: u64 = (msg.len() * 8u) as u64; // pad message let mut msg = vec::append(vec::to_owned(msg), ~[0x80u8]); @@ -51,7 +51,7 @@ pub fn md4(msg: &[u8]) -> Quad { } let mut i = 0u; - let e = vec::len(msg); + let e = msg.len(); let mut x = vec::from_elem(16u, 0u32); while i < e { let aa = a, bb = b, cc = c, dd = d; diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index f928f10b5fc..cc4e7ee0204 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -15,7 +15,6 @@ use core::comm::{stream, SharedChan}; use core::ptr; use core::result; use core::str; -use core::vec; use iotask = uv::iotask::IoTask; use interact = uv::iotask::interact; @@ -340,7 +339,7 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, } } debug!("successful process addrinfo result, len: %?", - vec::len(out_vec)); + out_vec.len()); output_ch.send(result::Ok(out_vec)); } else { @@ -424,7 +423,7 @@ mod test { // this.. mostly just wanting to see it work, atm. let results = result::unwrap(ga_result); debug!("test_get_addr: Number of results for %s: %?", - localhost_name, vec::len(results)); + localhost_name, results.len()); for results.each |r| { let ipv_prefix = match *r { Ipv4(_) => ~"IPv4", diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 9387903d842..37578e42baf 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -1802,7 +1802,7 @@ mod test { debug!("BUF_WRITE: val len %?", str::len(val)); do str::byte_slice(val) |b_slice| { debug!("BUF_WRITE: b_slice len %?", - vec::len(b_slice)); + b_slice.len()); w.write(b_slice) } } @@ -1810,7 +1810,7 @@ mod test { fn buf_read<R:io::Reader>(r: &R, len: uint) -> ~str { let new_bytes = (*r).read_bytes(len); debug!("in buf_read.. new_bytes len: %?", - vec::len(new_bytes)); + new_bytes.len()); str::from_bytes(new_bytes) } @@ -1863,7 +1863,7 @@ mod test { result::Ok(data) => { debug!("SERVER: got REQ str::from_bytes.."); debug!("SERVER: REQ data len: %?", - vec::len(data)); + data.len()); server_ch.send( str::from_bytes(data)); debug!("SERVER: before write"); diff --git a/src/libstd/par.rs b/src/libstd/par.rs index cf0eba9d30c..d1af484cb22 100644 --- a/src/libstd/par.rs +++ b/src/libstd/par.rs @@ -58,9 +58,8 @@ fn map_slices<A:Copy + Owned,B:Copy + Owned>( info!("pre-slice: %?", (base, slice)); let slice : &[A] = cast::transmute(slice); - info!("slice: %?", - (base, vec::len(slice), end - base)); - assert!((vec::len(slice) == end - base)); + info!("slice: %?", (base, slice.len(), end - base)); + assert!(slice.len() == end - base); f(base, slice) } }; diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index 2fa12809db6..9afa7262ce4 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -164,7 +164,7 @@ pub fn append_rope(left: Rope, right: Rope) -> Rope { */ pub fn concat(v: ~[Rope]) -> Rope { //Copy `v` into a mut vector - let mut len = vec::len(v); + let mut len = v.len(); if len == 0u { return node::Empty; } let mut ropes = vec::from_elem(len, v[0]); for uint::range(1u, len) |i| { @@ -770,7 +770,7 @@ pub mod node { */ pub fn tree_from_forest_destructive(forest: &mut [@Node]) -> @Node { let mut i; - let mut len = vec::len(forest); + let mut len = forest.len(); while len > 1u { i = 0u; while i < len - 1u {//Concat nodes 0 with 1, 2 with 3 etc. diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs index 4b410ebfdd2..6d8bf20d837 100644 --- a/src/libstd/sha1.rs +++ b/src/libstd/sha1.rs @@ -90,8 +90,8 @@ pub fn sha1() -> @Sha1 { } } fn process_msg_block(st: &mut Sha1State) { - assert!((vec::len(st.h) == digest_buf_len)); - assert!((vec::uniq_len(st.work_buf) == work_buf_len)); + assert!(st.h.len() == digest_buf_len); + assert!(vec::uniq_len(st.work_buf) == work_buf_len); let mut t: int; // Loop counter let w = st.work_buf; @@ -230,7 +230,7 @@ pub fn sha1() -> @Sha1 { impl Sha1 for Sha1State { fn reset(&mut self) { - assert!((vec::len(self.h) == digest_buf_len)); + assert!(self.h.len() == digest_buf_len); self.len_low = 0u32; self.len_high = 0u32; self.msg_block_idx = 0u; diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 915aab59a71..d29791449b6 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -63,6 +63,7 @@ pub mod flatpipes; pub mod bitv; pub mod deque; +#[cfg(not(stage0))] pub mod fun_treemap; pub mod list; pub mod priority_queue; diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 59c6a804408..449edacad32 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -19,7 +19,6 @@ use core::unstable::sync::{Exclusive, exclusive}; use core::ptr; use core::task; use core::util; -use core::vec; /**************************************************************************** * Internals @@ -220,7 +219,7 @@ pub impl<'self> Condvar<'self> { do task::unkillable { // Release lock, 'atomically' enqueuing ourselves in so doing. do (**self.sem).with |state| { - if condvar_id < vec::len(state.blocked) { + if condvar_id < state.blocked.len() { // Drop the lock. state.count += 1; if state.count <= 0 { @@ -230,7 +229,7 @@ pub impl<'self> Condvar<'self> { let SignalEnd = SignalEnd.swap_unwrap(); state.blocked[condvar_id].tail.send(SignalEnd); } else { - out_of_bounds = Some(vec::len(state.blocked)); + out_of_bounds = Some(state.blocked.len()); } } @@ -285,10 +284,10 @@ pub impl<'self> Condvar<'self> { let mut out_of_bounds = None; let mut result = false; do (**self.sem).with |state| { - if condvar_id < vec::len(state.blocked) { + if condvar_id < state.blocked.len() { result = signal_waitqueue(&state.blocked[condvar_id]); } else { - out_of_bounds = Some(vec::len(state.blocked)); + out_of_bounds = Some(state.blocked.len()); } } do check_cvar_bounds(out_of_bounds, condvar_id, "cond.signal_on()") { @@ -304,14 +303,14 @@ pub impl<'self> Condvar<'self> { let mut out_of_bounds = None; let mut queue = None; do (**self.sem).with |state| { - if condvar_id < vec::len(state.blocked) { + if condvar_id < state.blocked.len() { // To avoid :broadcast_heavy, we make a new waitqueue, // swap it out with the old one, and broadcast on the // old one outside of the little-lock. queue = Some(util::replace(&mut state.blocked[condvar_id], new_waitqueue())); } else { - out_of_bounds = Some(vec::len(state.blocked)); + out_of_bounds = Some(state.blocked.len()); } } do check_cvar_bounds(out_of_bounds, condvar_id, "cond.signal_on()") { diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 78f46b4ca03..b2f73df316d 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -144,7 +144,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes { }; let filter = - if vec::len(matches.free) > 0 { + if matches.free.len() > 0 { option::Some(copy (matches).free[0]) } else { option::None }; @@ -901,7 +901,7 @@ mod tests { ]; let filtered = filter_tests(&opts, tests); - assert!((vec::len(filtered) == 1)); + assert!(filtered.len() == 1); assert!((filtered[0].desc.name.to_str() == ~"1")); assert!((filtered[0].desc.ignore == false)); } diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index a14c048b8de..37052f7d1b7 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -1358,7 +1358,7 @@ mod test { let req_msg_ptr: *u8 = vec::raw::to_ptr(req_str_bytes); debug!("req_msg ptr: %u", req_msg_ptr as uint); let req_msg = ~[ - buf_init(req_msg_ptr, vec::len(req_str_bytes)) + buf_init(req_msg_ptr, req_str_bytes.len()) ]; // this is the enclosing record, we'll pass a ptr to // this to C.. diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 94bd9a18589..f77d00ce9b1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -17,6 +17,7 @@ use opt_vec::OptVec; use core::cast; use core::option::{None, Option, Some}; use core::to_bytes; +use core::to_bytes::IterBytes; use core::to_str::ToStr; use std::serialize::{Encodable, Decodable, Encoder, Decoder}; @@ -98,12 +99,14 @@ impl<D:Decoder> Decodable<D> for ident { #[cfg(stage0)] impl to_bytes::IterBytes for ident { + #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { self.repr.iter_bytes(lsb0, f) } } #[cfg(not(stage0))] impl to_bytes::IterBytes for ident { + #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { self.repr.iter_bytes(lsb0, f) } @@ -121,6 +124,20 @@ pub struct Lifetime { ident: ident } +#[cfg(stage0)] +impl to_bytes::IterBytes for Lifetime { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { + to_bytes::iter_bytes_3(&self.id, &self.span, &self.ident, lsb0, f) + } +} + +#[cfg(not(stage0))] +impl to_bytes::IterBytes for Lifetime { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { + to_bytes::iter_bytes_3(&self.id, &self.span, &self.ident, lsb0, f) + } +} + // a "Path" is essentially Rust's notion of a name; // for instance: core::cmp::Eq . It's represented // as a sequence of identifiers, along with a bunch @@ -752,7 +769,7 @@ pub struct ty_method { purity: purity, decl: fn_decl, generics: Generics, - self_ty: self_ty, + explicit_self: explicit_self, id: node_id, span: span, } @@ -1049,7 +1066,7 @@ impl to_bytes::IterBytes for ret_style { #[auto_encode] #[auto_decode] #[deriving(Eq)] -pub enum self_ty_ { +pub enum explicit_self_ { sty_static, // no self sty_value, // `self` sty_region(Option<@Lifetime>, mutability), // `&'lt self` @@ -1057,7 +1074,33 @@ pub enum self_ty_ { sty_uniq(mutability) // `~self` } -pub type self_ty = spanned<self_ty_>; +#[cfg(stage0)] +impl to_bytes::IterBytes for explicit_self_ { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { + match *self { + sty_static => 0u8.iter_bytes(lsb0, f), + sty_value => 1u8.iter_bytes(lsb0, f), + sty_region(ref lft, ref mutbl) => to_bytes::iter_bytes_3(&2u8, &lft, mutbl, lsb0, f), + sty_box(ref mutbl) => to_bytes::iter_bytes_2(&3u8, mutbl, lsb0, f), + sty_uniq(ref mutbl) => to_bytes::iter_bytes_2(&4u8, mutbl, lsb0, f), + } + } +} + +#[cfg(not(stage0))] +impl to_bytes::IterBytes for explicit_self_ { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { + match *self { + sty_static => 0u8.iter_bytes(lsb0, f), + sty_value => 1u8.iter_bytes(lsb0, f), + sty_region(ref lft, ref mutbl) => to_bytes::iter_bytes_3(&2u8, &lft, mutbl, lsb0, f), + sty_box(ref mutbl) => to_bytes::iter_bytes_2(&3u8, mutbl, lsb0, f), + sty_uniq(ref mutbl) => to_bytes::iter_bytes_2(&4u8, mutbl, lsb0, f), + } + } +} + +pub type explicit_self = spanned<explicit_self_>; #[auto_encode] #[auto_decode] @@ -1066,7 +1109,7 @@ pub struct method { ident: ident, attrs: ~[attribute], generics: Generics, - self_ty: self_ty, + explicit_self: explicit_self, purity: purity, decl: fn_decl, body: blk, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 212ceadf912..a98e3002dcf 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -272,7 +272,7 @@ pub fn trait_method_to_ty_method(method: &trait_method) -> ty_method { purity: m.purity, decl: copy m.decl, generics: copy m.generics, - self_ty: m.self_ty, + explicit_self: m.explicit_self, id: m.id, span: m.span, } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index e0392b476e4..cd0b29f2a1e 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -152,6 +152,20 @@ impl<D:Decoder> Decodable<D> for span { } } +#[cfg(stage0)] +impl to_bytes::IterBytes for span { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { + to_bytes::iter_bytes_3(&self.lo, &self.hi, &self.expn_info, lsb0, f); + } +} + +#[cfg(not(stage0))] +impl to_bytes::IterBytes for span { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { + to_bytes::iter_bytes_3(&self.lo, &self.hi, &self.expn_info, lsb0, f) + } +} + pub fn spanned<T>(lo: BytePos, hi: BytePos, t: T) -> spanned<T> { respan(mk_sp(lo, hi), t) } @@ -199,16 +213,62 @@ pub struct FileMapAndLine {fm: @FileMap, line: uint} pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos} pub struct NameAndSpan {name: ~str, span: Option<span>} +#[cfg(stage0)] +impl to_bytes::IterBytes for NameAndSpan { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { + to_bytes::iter_bytes_2(&self.name, &self.span, lsb0, f) + } +} + +#[cfg(not(stage0))] +impl to_bytes::IterBytes for NameAndSpan { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { + to_bytes::iter_bytes_2(&self.name, &self.span, lsb0, f) + } +} + pub struct CallInfo { call_site: span, callee: NameAndSpan } +#[cfg(stage0)] +impl to_bytes::IterBytes for CallInfo { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { + to_bytes::iter_bytes_2(&self.call_site, &self.callee, lsb0, f) + } +} + +#[cfg(not(stage0))] +impl to_bytes::IterBytes for CallInfo { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { + to_bytes::iter_bytes_2(&self.call_site, &self.callee, lsb0, f) + } +} + /// Extra information for tracking macro expansion of spans pub enum ExpnInfo { ExpandedFrom(CallInfo) } +#[cfg(stage0)] +impl to_bytes::IterBytes for ExpnInfo { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { + match *self { + ExpandedFrom(ref call_info) => to_bytes::iter_bytes_2(&0u8, call_info, lsb0, f) + } + } +} + +#[cfg(not(stage0))] +impl to_bytes::IterBytes for ExpnInfo { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { + match *self { + ExpandedFrom(ref call_info) => to_bytes::iter_bytes_2(&0u8, call_info, lsb0, f) + } + } +} + pub type FileName = ~str; pub struct FileLines diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 6b2aa2416f8..993fa612a27 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -232,7 +232,7 @@ fn highlight_lines(cm: @codemap::CodeMap, let max_lines = 6u; let mut elided = false; let mut display_lines = /* FIXME (#2543) */ copy lines.lines; - if vec::len(display_lines) > max_lines { + if display_lines.len() > max_lines { display_lines = vec::slice(display_lines, 0u, max_lines).to_vec(); elided = true; } @@ -243,7 +243,7 @@ fn highlight_lines(cm: @codemap::CodeMap, io::stderr().write_str(s); } if elided { - let last_line = display_lines[vec::len(display_lines) - 1u]; + let last_line = display_lines[display_lines.len() - 1u]; let s = fmt!("%s:%u ", fm.name, last_line + 1u); let mut indent = str::len(s); let mut out = ~""; @@ -254,7 +254,7 @@ fn highlight_lines(cm: @codemap::CodeMap, // FIXME (#3260) // If there's one line at fault we can easily point to the problem - if vec::len(lines.lines) == 1u { + if lines.lines.len() == 1u { let lo = cm.lookup_char_pos(sp.lo); let mut digits = 0u; let mut num = (lines.lines[0] + 1u) / 10u; diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index ac86d266d73..5c306aefc6a 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -713,7 +713,7 @@ fn mk_ser_method( ident: cx.ident_of("encode"), attrs: ~[], generics: ast_util::empty_generics(), - self_ty: codemap::spanned { + explicit_self: codemap::spanned { node: ast::sty_region(None, ast::m_imm), span: span }, @@ -772,7 +772,7 @@ fn mk_deser_method( ident: cx.ident_of("decode"), attrs: ~[], generics: ast_util::empty_generics(), - self_ty: codemap::spanned { node: ast::sty_static, span: span }, + explicit_self: codemap::spanned { node: ast::sty_static, span: span }, purity: ast::impure_fn, decl: deser_decl, body: deser_body, @@ -824,7 +824,7 @@ fn mk_struct_ser_impl( cx.ident_of("emit_struct"), ~[ cx.lit_str(span, @cx.str_of(ident)), - cx.lit_uint(span, vec::len(fields)), + cx.lit_uint(span, fields.len()), cx.lambda_stmts_1(span, fields, cx.ident_of("__s")), ] ); @@ -886,7 +886,7 @@ fn mk_struct_deser_impl( cx.ident_of("read_struct"), ~[ cx.lit_str(span, @cx.str_of(ident)), - cx.lit_uint(span, vec::len(fields)), + cx.lit_uint(span, fields.len()), cx.lambda_expr_1( cx.expr( span, diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 20bf01c0dc1..30470d2ebe7 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -351,7 +351,7 @@ pub fn expr_to_ident(cx: @ext_ctxt, err_msg: &str) -> ast::ident { match expr.node { ast::expr_path(p) => { - if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { + if p.types.len() > 0u || p.idents.len() != 1u { cx.span_fatal(expr.span, err_msg); } return p.idents[0]; diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index 2151e9529c4..1a45107c267 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -28,7 +28,7 @@ pub fn expand_deriving_clone(cx: @ext_ctxt, MethodDef { name: ~"clone", generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[], ret_ty: Self, const_nonmatching: false, diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index e431e1f78bf..7fc2fdc7963 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -34,7 +34,7 @@ pub fn expand_deriving_eq(cx: @ext_ctxt, MethodDef { name: $name, generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~[~"bool"])), const_nonmatching: true, diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index cdb9f620301..5445aef4491 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -24,7 +24,7 @@ pub fn expand_deriving_ord(cx: @ext_ctxt, MethodDef { name: $name, generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~[~"bool"])), const_nonmatching: false, diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index 068a7bc06b1..4541569b829 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -33,7 +33,7 @@ pub fn expand_deriving_totaleq(cx: @ext_ctxt, MethodDef { name: ~"equals", generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~[~"bool"])), const_nonmatching: true, diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 5ec4e028454..8f156e6a9e3 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -27,7 +27,7 @@ pub fn expand_deriving_totalord(cx: @ext_ctxt, MethodDef { name: ~"cmp", generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~[~"core", ~"cmp", ~"Ordering"])), const_nonmatching: false, diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index fd5d26a1787..3be65ecd8db 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -119,13 +119,13 @@ fn create_decode_method( let body_block = build::mk_simple_block(cx, span, expr); // Create the method. - let self_ty = spanned { node: sty_static, span: span }; + let explicit_self = spanned { node: sty_static, span: span }; let method_ident = cx.ident_of("decode"); @ast::method { ident: method_ident, attrs: ~[], generics: ast_util::empty_generics(), - self_ty: self_ty, + explicit_self: explicit_self, purity: impure_fn, decl: fn_decl, body: body_block, diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index a5edd92022f..2078ec9d45c 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -111,13 +111,13 @@ fn create_encode_method( let body_block = build::mk_block_(cx, span, statements); // Create the method. - let self_ty = spanned { node: sty_region(None, m_imm), span: span }; + let explicit_self = spanned { node: sty_region(None, m_imm), span: span }; let method_ident = cx.ident_of("encode"); @ast::method { ident: method_ident, attrs: ~[], generics: ast_util::empty_generics(), - self_ty: self_ty, + explicit_self: explicit_self, purity: impure_fn, decl: fn_decl, body: body_block, diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index be2cc6dd25e..fc14e3c3f73 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -216,7 +216,7 @@ pub struct MethodDef<'self> { /// Whether there is a self argument (outer Option) i.e. whether /// this is a static function, and whether it is a pointer (inner /// Option) - self_ty: Option<Option<PtrTy>>, + explicit_self: Option<Option<PtrTy>>, /// Arguments other than the self argument args: ~[Ty], @@ -321,7 +321,7 @@ impl<'self> TraitDef<'self> { type_ident: ident, generics: &Generics) -> @ast::item { let methods = do self.methods.map |method_def| { - let (self_ty, self_args, nonself_args, tys) = + let (explicit_self, self_args, nonself_args, tys) = method_def.split_self_nonself_args(cx, span, type_ident, generics); let body = if method_def.is_static() { @@ -339,7 +339,7 @@ impl<'self> TraitDef<'self> { method_def.create_method(cx, span, type_ident, generics, - self_ty, tys, + explicit_self, tys, body) }; @@ -352,7 +352,7 @@ impl<'self> TraitDef<'self> { type_ident: ident, generics: &Generics) -> @ast::item { let methods = do self.methods.map |method_def| { - let (self_ty, self_args, nonself_args, tys) = + let (explicit_self, self_args, nonself_args, tys) = method_def.split_self_nonself_args(cx, span, type_ident, generics); let body = if method_def.is_static() { @@ -370,7 +370,7 @@ impl<'self> TraitDef<'self> { method_def.create_method(cx, span, type_ident, generics, - self_ty, tys, + explicit_self, tys, body) }; @@ -404,28 +404,27 @@ impl<'self> MethodDef<'self> { } fn is_static(&self) -> bool { - self.self_ty.is_none() + self.explicit_self.is_none() } fn split_self_nonself_args(&self, cx: @ext_ctxt, span: span, type_ident: ident, generics: &Generics) - -> (ast::self_ty, ~[@expr], ~[@expr], ~[(ident, @ast::Ty)]) { + -> (ast::explicit_self, ~[@expr], ~[@expr], ~[(ident, @ast::Ty)]) { let mut self_args = ~[], nonself_args = ~[], arg_tys = ~[]; - let mut ast_self_ty = respan(span, ast::sty_static); let mut nonstatic = false; - match self.self_ty { + let ast_explicit_self = match self.explicit_self { Some(ref self_ptr) => { - let (self_expr, self_ty) = ty::get_explicit_self(cx, span, - self_ptr); + let (self_expr, explicit_self) = ty::get_explicit_self(cx, span, self_ptr); - ast_self_ty = self_ty; self_args.push(self_expr); nonstatic = true; + + explicit_self } - _ => {} - } + None => respan(span, ast::sty_static), + }; for self.args.eachi |i, ty| { let ast_ty = ty.to_ty(cx, span, type_ident, generics); @@ -449,13 +448,13 @@ impl<'self> MethodDef<'self> { } } - (ast_self_ty, self_args, nonself_args, arg_tys) + (ast_explicit_self, self_args, nonself_args, arg_tys) } fn create_method(&self, cx: @ext_ctxt, span: span, type_ident: ident, generics: &Generics, - self_ty: ast::self_ty, + explicit_self: ast::explicit_self, arg_types: ~[(ident, @ast::Ty)], body: @expr) -> @ast::method { // create the generics that aren't for Self @@ -477,7 +476,7 @@ impl<'self> MethodDef<'self> { ident: method_ident, attrs: ~[], generics: fn_generics, - self_ty: self_ty, + explicit_self: explicit_self, purity: ast::impure_fn, decl: fn_decl, body: body_block, diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index 9eb246ffe22..27e3a54add5 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -26,7 +26,7 @@ pub fn expand_deriving_iter_bytes(cx: @ext_ctxt, MethodDef { name: ~"iter_bytes", generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[ Literal(Path::new(~[~"bool"])), Literal(Path::new(~[~"core", ~"to_bytes", ~"Cb"])) diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 9030be86f39..2d91fcd346a 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -32,7 +32,7 @@ pub fn expand_deriving_rand(cx: @ext_ctxt, bounds: ~[(~"R", ~[ Path::new(~[~"core", ~"rand", ~"Rng"]) ])] }, - self_ty: None, + explicit_self: None, args: ~[ Ptr(~Literal(Path::new_local(~"R")), Borrowed(None, ast::m_mutbl)) diff --git a/src/libsyntax/ext/deriving/to_str.rs b/src/libsyntax/ext/deriving/to_str.rs index 6010354349e..13cb09e970d 100644 --- a/src/libsyntax/ext/deriving/to_str.rs +++ b/src/libsyntax/ext/deriving/to_str.rs @@ -27,7 +27,7 @@ pub fn expand_deriving_to_str(cx: @ext_ctxt, MethodDef { name: ~"to_str", generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[], ret_ty: Ptr(~Literal(Path::new_local(~"str")), Owned), const_nonmatching: false, diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 768ac7458d6..8fd372e4792 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -217,7 +217,7 @@ pub impl LifetimeBounds { pub fn get_explicit_self(cx: @ext_ctxt, span: span, self_ptr: &Option<PtrTy>) - -> (@expr, ast::self_ty) { + -> (@expr, ast::explicit_self) { let self_path = build::make_self(cx, span); match *self_ptr { None => { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 9afbe1e479d..f9ca84473fb 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -542,7 +542,41 @@ pub fn core_macros() -> ~str { } ) - + // + // A scheme-style conditional that helps to improve code clarity in some instances when + // the `if`, `else if`, and `else` keywords obscure predicates undesirably. + // + // # Example + // + // ~~~ + // let clamped = + // if x > mx { mx } + // else if x < mn { mn } + // else { x }; + // ~~~ + // + // Using `cond!`, the above could be written as: + // + // ~~~ + // let clamped = cond!( + // (x > mx) { mx } + // (x < mn) { mn } + // _ { x } + // ); + // ~~~ + // + // The optional default case is denoted by `_`. + // + macro_rules! cond ( + ( $(($pred:expr) $body:block)+ _ $default:block ) => ( + $(if $pred $body else)+ + $default + ); + // for if the default case was ommitted + ( $(($pred:expr) $body:block)+ ) => ( + $(if $pred $body)else+ + ); + ) }"; } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 6ed8994ed33..f6dbbbf420d 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -323,7 +323,7 @@ fn noop_fold_method(m: @method, fld: @ast_fold) -> @method { ident: fld.fold_ident(m.ident), attrs: /* FIXME (#2543) */ copy m.attrs, generics: fold_generics(&m.generics, fld), - self_ty: m.self_ty, + explicit_self: m.explicit_self, purity: m.purity, decl: fold_fn_decl(&m.decl, fld), body: fld.fold_block(&m.body), diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index fa91b968f69..89873b27935 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -276,7 +276,7 @@ fn read_block_comment(rdr: @mut StringReader, let mut style = if code_to_the_left { trailing } else { isolated }; consume_non_eol_whitespace(rdr); - if !is_eof(rdr) && rdr.curr != '\n' && vec::len(lines) == 1u { + if !is_eof(rdr) && rdr.curr != '\n' && lines.len() == 1u { style = mixed; } debug!("<<< block comment"); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e1fe20695c7..b76098858cb 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -19,7 +19,7 @@ use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer}; use ast::{bind_by_copy, bitand, bitor, bitxor, blk}; use ast::{blk_check_mode, box}; use ast::{crate, crate_cfg, decl, decl_item}; -use ast::{decl_local, default_blk, deref, div, enum_def}; +use ast::{decl_local, default_blk, deref, div, enum_def, explicit_self}; use ast::{expr, expr_, expr_addr_of, expr_match, expr_again}; use ast::{expr_assign, expr_assign_op, expr_binary, expr_block}; use ast::{expr_break, expr_call, expr_cast, expr_copy, expr_do_body}; @@ -43,7 +43,7 @@ use ast::{named_field, neg, node_id, noreturn, not, pat, pat_box, pat_enum}; use ast::{pat_ident, pat_lit, pat_range, pat_region, pat_struct}; use ast::{pat_tup, pat_uniq, pat_wild, private}; use ast::{rem, required}; -use ast::{ret_style, return_val, self_ty, shl, shr, stmt, stmt_decl}; +use ast::{ret_style, return_val, shl, shr, stmt, stmt_decl}; use ast::{stmt_expr, stmt_semi, stmt_mac, struct_def, struct_field}; use ast::{struct_variant_kind, subtract}; use ast::{sty_box, sty_region, sty_static, sty_uniq, sty_value}; @@ -504,7 +504,7 @@ pub impl Parser { let generics = p.parse_generics(); - let (self_ty, d) = do self.parse_fn_decl_with_self() |p| { + let (explicit_self, d) = do self.parse_fn_decl_with_self() |p| { // This is somewhat dubious; We don't want to allow argument // names to be left off if there is a definition... either::Left(p.parse_arg_general(false)) @@ -526,7 +526,7 @@ pub impl Parser { purity: pur, decl: d, generics: generics, - self_ty: self_ty, + explicit_self: explicit_self, id: p.get_id(), span: mk_sp(lo, hi) }) @@ -540,7 +540,7 @@ pub impl Parser { ident: ident, attrs: attrs, generics: generics, - self_ty: self_ty, + explicit_self: explicit_self, purity: pur, decl: d, body: body, @@ -2471,7 +2471,7 @@ pub impl Parser { } }, _ => { - if vec::len(enum_path.idents)==1u { + if enum_path.idents.len()==1u { // it could still be either an enum // or an identifier pattern, resolve // will sort it out: @@ -3002,11 +3002,11 @@ pub impl Parser { &self, parse_arg_fn: &fn(&Parser) -> arg_or_capture_item - ) -> (self_ty, fn_decl) { - fn maybe_parse_self_ty( - cnstr: &fn(v: mutability) -> ast::self_ty_, + ) -> (explicit_self, fn_decl) { + fn maybe_parse_explicit_self( + cnstr: &fn(v: mutability) -> ast::explicit_self_, p: &Parser - ) -> ast::self_ty_ { + ) -> ast::explicit_self_ { // We need to make sure it isn't a mode or a type if p.token_is_keyword(&~"self", &p.look_ahead(1)) || ((p.token_is_keyword(&~"const", &p.look_ahead(1)) || @@ -3022,7 +3022,7 @@ pub impl Parser { } } - fn maybe_parse_borrowed_self_ty(this: &Parser) -> ast::self_ty_ { + fn maybe_parse_borrowed_explicit_self(this: &Parser) -> ast::explicit_self_ { // The following things are possible to see here: // // fn(&self) @@ -3066,15 +3066,15 @@ pub impl Parser { // A bit of complexity and lookahead is needed here in order to to be // backwards compatible. let lo = self.span.lo; - let self_ty = match *self.token { + let explicit_self = match *self.token { token::BINOP(token::AND) => { - maybe_parse_borrowed_self_ty(self) + maybe_parse_borrowed_explicit_self(self) } token::AT => { - maybe_parse_self_ty(sty_box, self) + maybe_parse_explicit_self(sty_box, self) } token::TILDE => { - maybe_parse_self_ty(sty_uniq, self) + maybe_parse_explicit_self(sty_uniq, self) } token::IDENT(*) if self.is_self_ident() => { self.bump(); @@ -3087,7 +3087,7 @@ pub impl Parser { // If we parsed a self type, expect a comma before the argument list. let args_or_capture_items; - if self_ty != sty_static { + if explicit_self != sty_static { match *self.token { token::COMMA => { self.bump(); @@ -3132,7 +3132,7 @@ pub impl Parser { cf: ret_style }; - (spanned(lo, hi, self_ty), fn_decl) + (spanned(lo, hi, explicit_self), fn_decl) } // parse the |arg, arg| header on a lambda @@ -3199,7 +3199,7 @@ pub impl Parser { let pur = self.parse_fn_purity(); let ident = self.parse_ident(); let generics = self.parse_generics(); - let (self_ty, decl) = do self.parse_fn_decl_with_self() |p| { + let (explicit_self, decl) = do self.parse_fn_decl_with_self() |p| { p.parse_arg() }; @@ -3210,7 +3210,7 @@ pub impl Parser { ident: ident, attrs: attrs, generics: generics, - self_ty: self_ty, + explicit_self: explicit_self, purity: pur, decl: decl, body: body, @@ -4337,7 +4337,7 @@ pub impl Parser { } _ => () } - let last = path[vec::len(path) - 1u]; + let last = path[path.len() - 1u]; let path = @ast::Path { span: mk_sp(lo, self.span.hi), global: false, idents: path, diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 27686c4e4aa..fe479ab81f7 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -357,12 +357,14 @@ impl<'self> Equiv<@~str> for StringRef<'self> { #[cfg(stage0)] impl<'self> to_bytes::IterBytes for StringRef<'self> { + #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { (**self).iter_bytes(lsb0, f); } } #[cfg(not(stage0))] impl<'self> to_bytes::IterBytes for StringRef<'self> { + #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { (**self).iter_bytes(lsb0, f) } diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 7944469cb96..38c58612f43 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -110,8 +110,8 @@ pub fn tok_str(t: token) -> ~str { pub fn buf_str(toks: ~[token], szs: ~[int], left: uint, right: uint, lim: uint) -> ~str { - let n = vec::len(toks); - assert!(n == vec::len(szs)); + let n = toks.len(); + assert!(n == szs.len()); let mut i = left; let mut L = lim; let mut s = ~"["; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 1e94c16f87a..ea1682978a4 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -181,12 +181,12 @@ pub fn path_to_str(p: @ast::Path, intr: @ident_interner) -> ~str { } pub fn fun_to_str(decl: &ast::fn_decl, purity: ast::purity, name: ast::ident, - opt_self_ty: Option<ast::self_ty_>, + opt_explicit_self: Option<ast::explicit_self_>, generics: &ast::Generics, intr: @ident_interner) -> ~str { do io::with_str_writer |wr| { let s = rust_printer(wr, intr); print_fn(s, decl, Some(purity), AbiSet::Rust(), - name, generics, opt_self_ty, ast::inherited); + name, generics, opt_explicit_self, ast::inherited); end(s); // Close the head box end(s); // Close the outer box eof(s.s); @@ -797,7 +797,7 @@ pub fn print_ty_method(s: @ps, m: &ast::ty_method) { print_outer_attributes(s, m.attrs); print_ty_fn(s, None, None, None, m.purity, ast::Many, &m.decl, Some(m.ident), Some(&m.generics), - Some(/*bad*/ copy m.self_ty.node)); + Some(/*bad*/ copy m.explicit_self.node)); word(s.s, ~";"); } @@ -813,7 +813,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), AbiSet::Rust(), - meth.ident, &meth.generics, Some(meth.self_ty.node), + meth.ident, &meth.generics, Some(meth.explicit_self.node), meth.vis); word(s.s, ~" "); print_block_with_attrs(s, &meth.body, meth.attrs); @@ -1626,13 +1626,13 @@ pub fn print_pat(s: @ps, pat: @ast::pat, refutable: bool) { (s.ann.post)(ann_node); } -pub fn self_ty_to_str(self_ty: ast::self_ty_, intr: @ident_interner) -> ~str { - to_str(self_ty, |a, b| { print_self_ty(a, b); () }, intr) +pub fn explicit_self_to_str(explicit_self: ast::explicit_self_, intr: @ident_interner) -> ~str { + to_str(explicit_self, |a, b| { print_explicit_self(a, b); () }, intr) } // Returns whether it printed anything -pub fn print_self_ty(s: @ps, self_ty: ast::self_ty_) -> bool { - match self_ty { +pub fn print_explicit_self(s: @ps, explicit_self: ast::explicit_self_) -> bool { + match explicit_self { ast::sty_static => { return false; } ast::sty_value => { word(s.s, ~"self"); } ast::sty_region(lt, m) => { @@ -1657,24 +1657,24 @@ pub fn print_fn(s: @ps, abis: AbiSet, name: ast::ident, generics: &ast::Generics, - opt_self_ty: Option<ast::self_ty_>, + opt_explicit_self: Option<ast::explicit_self_>, vis: ast::visibility) { head(s, ~""); - print_fn_header_info(s, opt_self_ty, purity, abis, ast::Many, None, vis); + print_fn_header_info(s, opt_explicit_self, purity, abis, ast::Many, None, vis); nbsp(s); print_ident(s, name); print_generics(s, generics); - print_fn_args_and_ret(s, decl, opt_self_ty); + print_fn_args_and_ret(s, decl, opt_explicit_self); } pub fn print_fn_args(s: @ps, decl: &ast::fn_decl, - opt_self_ty: Option<ast::self_ty_>) { + opt_explicit_self: Option<ast::explicit_self_>) { // It is unfortunate to duplicate the commasep logic, but we we want the // self type and the args all in the same box. box(s, 0u, inconsistent); let mut first = true; - for opt_self_ty.each |self_ty| { - first = !print_self_ty(s, *self_ty); + for opt_explicit_self.each |explicit_self| { + first = !print_explicit_self(s, *explicit_self); } for decl.inputs.each |arg| { @@ -1686,9 +1686,9 @@ pub fn print_fn_args(s: @ps, decl: &ast::fn_decl, } pub fn print_fn_args_and_ret(s: @ps, decl: &ast::fn_decl, - opt_self_ty: Option<ast::self_ty_>) { + opt_explicit_self: Option<ast::explicit_self_>) { popen(s); - print_fn_args(s, decl, opt_self_ty); + print_fn_args(s, decl, opt_explicit_self); pclose(s); maybe_print_comment(s, decl.output.span.lo); @@ -1798,7 +1798,7 @@ pub fn print_meta_item(s: @ps, item: @ast::meta_item) { pub fn print_view_path(s: @ps, vp: @ast::view_path) { match vp.node { ast::view_path_simple(ident, path, _) => { - if path.idents[vec::len(path.idents)-1u] != ident { + if path.idents[path.idents.len()-1u] != ident { print_ident(s, ident); space(s.s); word_space(s, ~"="); @@ -1900,7 +1900,7 @@ pub fn print_ty_fn(s: @ps, decl: &ast::fn_decl, id: Option<ast::ident>, generics: Option<&ast::Generics>, - opt_self_ty: Option<ast::self_ty_>) { + opt_explicit_self: Option<ast::explicit_self_>) { ibox(s, indent_unit); // Duplicates the logic in `print_fn_header_info()`. This is because that @@ -1920,8 +1920,8 @@ pub fn print_ty_fn(s: @ps, // self type and the args all in the same box. box(s, 0u, inconsistent); let mut first = true; - for opt_self_ty.each |self_ty| { - first = !print_self_ty(s, *self_ty); + for opt_explicit_self.each |explicit_self| { + first = !print_explicit_self(s, *explicit_self); } for decl.inputs.each |arg| { if first { first = false; } else { word_space(s, ~","); } @@ -2067,7 +2067,7 @@ pub fn maybe_print_comment(s: @ps, pos: BytePos) { pub fn print_comment(s: @ps, cmnt: &comments::cmnt) { match cmnt.style { comments::mixed => { - assert!((vec::len(cmnt.lines) == 1u)); + assert!(cmnt.lines.len() == 1u); zerobreak(s.s); word(s.s, cmnt.lines[0]); zerobreak(s.s); @@ -2083,7 +2083,7 @@ pub fn print_comment(s: @ps, cmnt: &comments::cmnt) { } comments::trailing => { word(s.s, ~" "); - if vec::len(cmnt.lines) == 1u { + if cmnt.lines.len() == 1u { word(s.s, cmnt.lines[0]); hardbreak(s.s); } else { @@ -2163,7 +2163,7 @@ pub fn print_opt_sigil(s: @ps, opt_sigil: Option<ast::Sigil>) { } pub fn print_fn_header_info(s: @ps, - _opt_sty: Option<ast::self_ty_>, + _opt_explicit_self: Option<ast::explicit_self_>, opt_purity: Option<ast::purity>, abis: AbiSet, onceness: ast::Onceness, diff --git a/src/test/auxiliary/cci_iter_lib.rs b/src/test/auxiliary/cci_iter_lib.rs index e44267373ef..a264c7d238f 100644 --- a/src/test/auxiliary/cci_iter_lib.rs +++ b/src/test/auxiliary/cci_iter_lib.rs @@ -13,7 +13,7 @@ #[inline] pub fn iter<T>(v: &[T], f: &fn(&T)) { let mut i = 0u; - let n = vec::len(v); + let n = v.len(); while i < n { f(&v[i]); i += 1u; diff --git a/src/test/auxiliary/cci_no_inline_lib.rs b/src/test/auxiliary/cci_no_inline_lib.rs index f79227d87cd..fbdb7806b5e 100644 --- a/src/test/auxiliary/cci_no_inline_lib.rs +++ b/src/test/auxiliary/cci_no_inline_lib.rs @@ -13,7 +13,7 @@ // same as cci_iter_lib, more-or-less, but not marked inline pub fn iter(v: ~[uint], f: &fn(uint)) { let mut i = 0u; - let n = vec::len(v); + let n = v.len(); while i < n { f(v[i]); i += 1u; diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 6fd31aa7b9f..ddf6f4bfc55 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -126,7 +126,7 @@ fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] { */ fn bfs(graph: graph, key: node_id) -> bfs_result { let mut marks : ~[node_id] - = vec::from_elem(vec::len(graph), -1i64); + = vec::from_elem(graph.len(), -1i64); let mut q = Deque::new(); @@ -429,7 +429,7 @@ fn main() { let stop = time::precise_time_s(); io::stdout().write_line(fmt!("Generated %? edges in %? seconds.", - vec::len(edges), stop - start)); + edges.len(), stop - start)); let start = time::precise_time_s(); let graph = make_graph(1 << scale, copy edges); diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index fa6b7066e40..3c32ec338b7 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -95,7 +95,7 @@ fn windows_with_carry(bb: &[u8], nn: uint, it: &fn(window: &[u8])) -> ~[u8] { let mut ii = 0u; - let len = vec::len(bb); + let len = bb.len(); while ii < len - (nn - 1u) { it(vec::slice(bb, ii, ii+nn)); ii += 1u; diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index c383cdf4318..c18c1eaedd6 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -70,7 +70,7 @@ pub impl Sudoku { let line = reader.read_line(); let mut comps = ~[]; for str::each_split_char(line.trim(), ',') |s| { comps.push(s.to_owned()) } - if vec::len(comps) == 3u { + if comps.len() == 3u { let row = uint::from_str(comps[0]).get() as u8; let col = uint::from_str(comps[1]).get() as u8; g[row][col] = uint::from_str(comps[2]).get() as u8; @@ -103,7 +103,7 @@ pub impl Sudoku { } let mut ptr = 0u; - let end = vec::len(work); + let end = work.len(); while (ptr < end) { let (row, col) = work[ptr]; // is there another color to try? @@ -265,7 +265,7 @@ fn check_default_sudoku_solution() { fn main() { let args = os::args(); - let use_default = vec::len(args) == 1u; + let use_default = args.len() == 1u; let mut sudoku = if use_default { Sudoku::from_vec(&default_sudoku) } else { diff --git a/src/test/compile-fail/issue-2123.rs b/src/test/compile-fail/issue-2123.rs index 56f0c5e3dd0..6d617d338ed 100644 --- a/src/test/compile-fail/issue-2123.rs +++ b/src/test/compile-fail/issue-2123.rs @@ -9,6 +9,7 @@ // except according to those terms. use x = m::f; //~ ERROR failed to resolve import + //~^ unresolved import: there is no `f` in `m` mod m { } diff --git a/src/test/compile-fail/issue-2937.rs b/src/test/compile-fail/issue-2937.rs index 56f0c5e3dd0..b225c5496e2 100644 --- a/src/test/compile-fail/issue-2937.rs +++ b/src/test/compile-fail/issue-2937.rs @@ -9,6 +9,7 @@ // except according to those terms. use x = m::f; //~ ERROR failed to resolve import + //~^ ERROR unresolved import: there is no `f` in `m` mod m { } diff --git a/src/test/compile-fail/issue-3993-2.rs b/src/test/compile-fail/issue-3993-2.rs index 1293dc8a875..2ca871cd11c 100644 --- a/src/test/compile-fail/issue-3993-2.rs +++ b/src/test/compile-fail/issue-3993-2.rs @@ -9,6 +9,7 @@ // except according to those terms. use zoo::{duck, goose}; //~ ERROR failed to resolve import + //~^ ERROR unresolved import: found `goose` in `zoo` but it is private mod zoo { pub enum bird { diff --git a/src/test/compile-fail/issue-3993-3.rs b/src/test/compile-fail/issue-3993-3.rs index 1ccf019a7c1..ccda6f158ed 100644 --- a/src/test/compile-fail/issue-3993-3.rs +++ b/src/test/compile-fail/issue-3993-3.rs @@ -9,6 +9,7 @@ // except according to those terms. use zoo::fly; //~ ERROR failed to resolve import + //~^ ERROR unresolved import: found `fly` in `zoo` but it is private mod zoo { priv type fly = (); diff --git a/src/test/compile-fail/issue-3993.rs b/src/test/compile-fail/issue-3993.rs index 5b47c3e2406..450ea023bcb 100644 --- a/src/test/compile-fail/issue-3993.rs +++ b/src/test/compile-fail/issue-3993.rs @@ -9,6 +9,7 @@ // except according to those terms. use zoo::fly; //~ ERROR failed to resolve import + //~^ ERROR unresolved import: found `fly` in `zoo` but it is private mod zoo { priv fn fly() {} diff --git a/src/test/compile-fail/super-at-top-level.rs b/src/test/compile-fail/super-at-top-level.rs index f1064a62905..9ec92e6dbfa 100644 --- a/src/test/compile-fail/super-at-top-level.rs +++ b/src/test/compile-fail/super-at-top-level.rs @@ -1,5 +1,4 @@ -use super::f; //~ ERROR unresolved name -//~^ ERROR failed to resolve import +use super::f; //~ ERROR failed to resolve import fn main() { } diff --git a/src/test/compile-fail/unresolved-import.rs b/src/test/compile-fail/unresolved-import.rs index 1bd3efeadcb..fc69c34c118 100644 --- a/src/test/compile-fail/unresolved-import.rs +++ b/src/test/compile-fail/unresolved-import.rs @@ -8,5 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use foo::bar; //~ ERROR unresolved import. maybe a missing - //~^ ERROR failed to resolve import +use foo::bar; //~ ERROR unresolved import. maybe a missing `extern mod foo`? + //~^ ERROR failed to resolve import `foo::bar` +use x = bar::baz; //~ ERROR unresolved import: there is no `baz` in `bar` + //~^ ERROR failed to resolve import `bar::baz` + +mod bar { + struct bar; +} diff --git a/src/test/compile-fail/unsafe-fn-autoderef.rs b/src/test/compile-fail/unsafe-fn-autoderef.rs index b602d1717be..82efd579518 100644 --- a/src/test/compile-fail/unsafe-fn-autoderef.rs +++ b/src/test/compile-fail/unsafe-fn-autoderef.rs @@ -9,9 +9,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// xfail-test -type rec = {f: int}; -fn f(p: *rec) -> int { +struct Rec { + f: int +} + +fn f(p: *Rec) -> int { // Test that * ptrs do not autoderef. There is a deeper reason for // prohibiting this, beyond making unsafe things annoying (which doesn't @@ -25,7 +27,7 @@ fn f(p: *rec) -> int { // are prohibited by various checks, such as that the enum is // instantiable and so forth). - return p.f; //~ ERROR attempted access of field `f` on type `*rec` + return p.f; //~ ERROR attempted access of field `f` on type `*Rec` } fn main() { diff --git a/src/test/run-pass/assignability-trait.rs b/src/test/run-pass/assignability-trait.rs index 6946ed3fbcf..b21213bb221 100644 --- a/src/test/run-pass/assignability-trait.rs +++ b/src/test/run-pass/assignability-trait.rs @@ -39,15 +39,15 @@ pub fn main() { // Call a method for x.iterate() |y| { assert!(x[*y] == *y); } // Call a parameterized function - assert!(length(x.clone()) == vec::len(x)); + assert!(length(x.clone()) == x.len()); // Call a parameterized function, with type arguments that require // a borrow - assert!(length::<int, &[int]>(x) == vec::len(x)); + assert!(length::<int, &[int]>(x) == x.len()); // Now try it with a type that *needs* to be borrowed let z = [0,1,2,3]; // Call a method for z.iterate() |y| { assert!(z[*y] == *y); } // Call a parameterized function - assert!(length::<int, &[int]>(z) == vec::len(z)); + assert!(length::<int, &[int]>(z) == z.len()); } diff --git a/src/test/run-pass/class-implements-multiple-traits.rs b/src/test/run-pass/class-implements-multiple-traits.rs index 3a5bd648639..61dfcfed7bd 100644 --- a/src/test/run-pass/class-implements-multiple-traits.rs +++ b/src/test/run-pass/class-implements-multiple-traits.rs @@ -103,7 +103,7 @@ fn annoy_neighbors<T:noisy>(critter: T) { fn bite_everything<T:bitey>(critter: T) -> bool { let mut left : ~[body_part] = ~[finger, toe, nose, ear]; - while vec::len(left) > 0u { + while left.len() > 0u { let part = critter.bite(); debug!("%? %?", left, part); if vec_includes(left, part) { diff --git a/src/test/run-pass/cond-macro-no-default.rs b/src/test/run-pass/cond-macro-no-default.rs new file mode 100644 index 00000000000..6b90308f8a8 --- /dev/null +++ b/src/test/run-pass/cond-macro-no-default.rs @@ -0,0 +1,23 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn clamp<T:Copy + Ord + Signed>(x: T, mn: T, mx: T) -> T { + cond!( + (x > mx) { return mx; } + (x < mn) { return mn; } + ) + return x; +} + +fn main() { + assert_eq!(clamp(1, 2, 4), 2); + assert_eq!(clamp(8, 2, 4), 4); + assert_eq!(clamp(3, 2, 4), 3); +} diff --git a/src/test/run-pass/cond-macro.rs b/src/test/run-pass/cond-macro.rs new file mode 100644 index 00000000000..929752b3f1a --- /dev/null +++ b/src/test/run-pass/cond-macro.rs @@ -0,0 +1,23 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn clamp<T:Copy + Ord + Signed>(x: T, mn: T, mx: T) -> T { + cond!( + (x > mx) { mx } + (x < mn) { mn } + _ { x } + ) +} + +fn main() { + assert_eq!(clamp(1, 2, 4), 2); + assert_eq!(clamp(8, 2, 4), 4); + assert_eq!(clamp(3, 2, 4), 3); +} diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index bca4cbafc6c..c6ae2047147 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -71,7 +71,7 @@ mod map_reduce { start_mappers(ctrl_chan, inputs.clone()); - let mut num_mappers = vec::len(inputs) as int; + let mut num_mappers = inputs.len() as int; while num_mappers > 0 { match ctrl_port.recv() { diff --git a/src/test/run-pass/vec-self-append.rs b/src/test/run-pass/vec-self-append.rs index acd9cf6f01b..7507a78378e 100644 --- a/src/test/run-pass/vec-self-append.rs +++ b/src/test/run-pass/vec-self-append.rs @@ -14,7 +14,7 @@ fn test_heap_to_heap() { // a spills onto the heap let mut a = ~[0, 1, 2, 3, 4]; a = a + a; // FIXME(#3387)---can't write a += a - assert!((vec::len(a) == 10u)); + assert!(a.len() == 10u); assert!((a[0] == 0)); assert!((a[1] == 1)); assert!((a[2] == 2)); @@ -32,7 +32,7 @@ fn test_stack_to_heap() { let mut a = ~[0, 1, 2]; // a spills to the heap a = a + a; // FIXME(#3387)---can't write a += a - assert!((vec::len(a) == 6u)); + assert!(a.len() == 6u); assert!((a[0] == 0)); assert!((a[1] == 1)); assert!((a[2] == 2)); @@ -47,8 +47,8 @@ fn test_loop() { let mut i = 20; let mut expected_len = 1u; while i > 0 { - error!(vec::len(a)); - assert!((vec::len(a) == expected_len)); + error!(a.len()); + assert!(a.len() == expected_len); a = a + a; // FIXME(#3387)---can't write a += a i -= 1; expected_len *= 2u; |
