From 845b06542e01c618a5df47b091ec7b72cea8e2e3 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 29 Jan 2013 15:06:05 -0800 Subject: [PATCH 01/37] messing around with pipes and stages --- src/libcore/pipes.rs | 25 ++++++++++++++++--------- src/libsyntax/ext/pipes/pipec.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 5af9950ff08..052daeaeb2a 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -143,14 +143,9 @@ pub fn BufferHeader() -> BufferHeader { // This is for protocols to associate extra data to thread around. #[doc(hidden)] #[cfg(stage0)] -type Buffer = { - header: BufferHeader, - data: T, -}; -#[doc(hidden)] #[cfg(stage1)] +type Buffer = { header: BufferHeader, data: T }; #[cfg(stage2)] -#[cfg(stage3)] pub struct Buffer { header: BufferHeader, data: T, @@ -247,7 +242,6 @@ pub fn mk_packet() -> Packet { payload: None, } } - #[doc(hidden)] #[cfg(stage0)] fn unibuffer() -> ~Buffer> { @@ -264,10 +258,23 @@ fn unibuffer() -> ~Buffer> { } move b } -#[doc(hidden)] #[cfg(stage1)] +fn unibuffer() -> ~Buffer> { + let b = ~{ + header: BufferHeader(), + data: Packet { + header: PacketHeader(), + payload: None, + } + }; + + unsafe { + b.data.header.buffer = reinterpret_cast(&b); + } + move b +} +#[doc(hidden)] #[cfg(stage2)] -#[cfg(stage3)] fn unibuffer() -> ~Buffer> { let b = ~Buffer { header: BufferHeader(), diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 928885cf817..aaa909b3694 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -355,6 +355,34 @@ pub impl protocol: gen_init { })) } + #[cfg(stage0)] + fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr { + debug!("gen_init_bounded"); + let buffer_fields = self.gen_buffer_init(ext_cx); + let buffer = quote_expr!(~{ + header: ::pipes::BufferHeader(), + data: $buffer_fields, + }); + + let entangle_body = ext_cx.block_expr( + ext_cx.block( + self.states.map_to_vec( + |s| ext_cx.parse_stmt( + fmt!("data.%s.set_buffer_(buffer)", + s.name))), + ext_cx.parse_expr( + fmt!("::ptr::addr_of(&(data.%s))", + self.states[0].name)))); + + quote_expr!({ + let buffer = $buffer; + do ::pipes::entangle_buffer(move buffer) |buffer, data| { + $entangle_body + } + }) + } + #[cfg(stage1)] + #[cfg(stage2)] fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr { debug!("gen_init_bounded"); let buffer_fields = self.gen_buffer_init(ext_cx); From a71d0043934371309ba2b7b23b67552c48a41b25 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 29 Jan 2013 15:09:20 -0800 Subject: [PATCH 02/37] Don't generate set_buffer --- src/libsyntax/ext/pipes/pipec.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index aaa909b3694..9cf9038ef7e 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -368,7 +368,7 @@ pub impl protocol: gen_init { ext_cx.block( self.states.map_to_vec( |s| ext_cx.parse_stmt( - fmt!("data.%s.set_buffer_(buffer)", + fmt!("data.%s.set_buffer(buffer)", s.name))), ext_cx.parse_expr( fmt!("::ptr::addr_of(&(data.%s))", @@ -395,7 +395,7 @@ pub impl protocol: gen_init { ext_cx.block( self.states.map_to_vec( |s| ext_cx.parse_stmt( - fmt!("data.%s.set_buffer_(buffer)", + fmt!("data.%s.set_buffer(buffer)", s.name))), ext_cx.parse_expr( fmt!("::ptr::addr_of(&(data.%s))", From a9587b8fcd3e436cf2e4a25997e6eecc4608235b Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 29 Jan 2013 16:55:46 -0800 Subject: [PATCH 03/37] core: Remove transitional code --- src/libcore/extfmt.rs | 6 - src/libcore/pipes.rs | 321 ------------------------------- src/libcore/reflect.rs | 428 ----------------------------------------- src/libcore/repr.rs | 297 ---------------------------- 4 files changed, 1052 deletions(-) diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 850d1ea8427..0910975e481 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -499,12 +499,6 @@ pub mod rt { pub enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, } - #[cfg(stage0)] - pub type Conv = {flags: u32, width: Count, precision: Count, ty: Ty}; - - #[cfg(stage1)] - #[cfg(stage2)] - #[cfg(stage3)] pub struct Conv { flags: u32, width: Count, diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 052daeaeb2a..2dde9a9508b 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -142,10 +142,6 @@ pub fn BufferHeader() -> BufferHeader { // This is for protocols to associate extra data to thread around. #[doc(hidden)] -#[cfg(stage0)] -#[cfg(stage1)] -type Buffer = { header: BufferHeader, data: T }; -#[cfg(stage2)] pub struct Buffer { header: BufferHeader, data: T, @@ -207,14 +203,6 @@ impl PacketHeader { } #[doc(hidden)] -#[cfg(stage0)] -pub struct Packet { - header: PacketHeader, - mut payload: Option, -} -#[doc(hidden)] -#[cfg(stage1)] -#[cfg(stage2)] pub struct Packet { header: PacketHeader, mut payload: Option, @@ -223,16 +211,12 @@ pub struct Packet { #[doc(hidden)] pub trait HasBuffer { fn set_buffer(b: *libc::c_void); - // FIXME #4421 remove after snapshot - fn set_buffer_(b: *libc::c_void); } impl Packet: HasBuffer { fn set_buffer(b: *libc::c_void) { self.header.buffer = b; } - // FIXME #4421 remove after snapshot - fn set_buffer_(b: *libc::c_void) { self.set_buffer(b) } } #[doc(hidden)] @@ -243,38 +227,6 @@ pub fn mk_packet() -> Packet { } } #[doc(hidden)] -#[cfg(stage0)] -fn unibuffer() -> ~Buffer> { - let b = ~{ - header: BufferHeader(), - data: Packet { - header: PacketHeader(), - payload: None, - } - }; - - unsafe { - b.data.header.buffer = reinterpret_cast(&b); - } - move b -} -#[cfg(stage1)] -fn unibuffer() -> ~Buffer> { - let b = ~{ - header: BufferHeader(), - data: Packet { - header: PacketHeader(), - payload: None, - } - }; - - unsafe { - b.data.header.buffer = reinterpret_cast(&b); - } - move b -} -#[doc(hidden)] -#[cfg(stage2)] fn unibuffer() -> ~Buffer> { let b = ~Buffer { header: BufferHeader(), @@ -291,17 +243,6 @@ fn unibuffer() -> ~Buffer> { } #[doc(hidden)] -#[cfg(stage0)] -pub fn packet() -> *Packet { - let b = unibuffer(); - let p = ptr::addr_of(&(b.data)); - // We'll take over memory management from here. - unsafe { forget(move b) } - p -} -#[doc(hidden)] -#[cfg(stage1)] -#[cfg(stage2)] pub fn packet() -> *Packet { let b = unibuffer(); let p = ptr::addr_of(&(b.data)); @@ -412,42 +353,11 @@ fn swap_state_rel(dst: &mut State, src: State) -> State { } #[doc(hidden)] -#[cfg(stage0)] -pub unsafe fn get_buffer(p: *PacketHeader) -> ~Buffer { - transmute((*p).buf_header()) -} -#[doc(hidden)] -#[cfg(stage1)] -#[cfg(stage2)] pub unsafe fn get_buffer(p: *PacketHeader) -> ~Buffer { transmute((*p).buf_header()) } // This could probably be done with SharedMutableState to avoid move_it!(). -#[cfg(stage0)] -struct BufferResource { - buffer: ~Buffer, - - drop { - unsafe { - let b = move_it!(self.buffer); - //let p = ptr::addr_of(*b); - //error!("drop %?", p); - let old_count = atomic_sub_rel(&mut b.header.ref_count, 1); - //let old_count = atomic_xchng_rel(b.header.ref_count, 0); - if old_count == 1 { - // The new count is 0. - - // go go gadget drop glue - } - else { - forget(move b) - } - } - } -} -#[cfg(stage1)] -#[cfg(stage2)] struct BufferResource { buffer: ~Buffer, @@ -470,19 +380,6 @@ struct BufferResource { } } -#[cfg(stage0)] -fn BufferResource(b: ~Buffer) -> BufferResource { - //let p = ptr::addr_of(*b); - //error!("take %?", p); - atomic_add_acq(&mut b.header.ref_count, 1); - - BufferResource { - // tjc: ???? - buffer: move b - } -} -#[cfg(stage1)] -#[cfg(stage2)] fn BufferResource(b: ~Buffer) -> BufferResource { //let p = ptr::addr_of(*b); //error!("take %?", p); @@ -495,51 +392,6 @@ fn BufferResource(b: ~Buffer) -> BufferResource { } #[doc(hidden)] -#[cfg(stage0)] -pub fn send(p: SendPacketBuffered, - payload: T) -> bool { - let header = p.header(); - let p_ = p.unwrap(); - let p = unsafe { &*p_ }; - assert ptr::addr_of(&(p.header)) == header; - assert p.payload.is_none(); - p.payload = move Some(move payload); - let old_state = swap_state_rel(&mut p.header.state, Full); - match old_state { - Empty => { - // Yay, fastpath. - - // The receiver will eventually clean this up. - //unsafe { forget(p); } - return true; - } - Full => fail ~"duplicate send", - Blocked => { - debug!("waking up task for %?", p_); - let old_task = swap_task(&mut p.header.blocked_task, ptr::null()); - if !old_task.is_null() { - unsafe { - rustrt::task_signal_event( - old_task, - ptr::addr_of(&(p.header)) as *libc::c_void); - rustrt::rust_task_deref(old_task); - } - } - - // The receiver will eventually clean this up. - //unsafe { forget(p); } - return true; - } - Terminated => { - // The receiver will never receive this. Rely on drop_glue - // to clean everything up. - return false; - } - } -} -#[doc(hidden)] -#[cfg(stage1)] -#[cfg(stage2)] pub fn send(p: SendPacketBuffered, payload: T) -> bool { let header = p.header(); let p_ = p.unwrap(); @@ -925,44 +777,13 @@ pub fn select(endpoints: ~[RecvPacketBuffered]) message. */ -#[cfg(stage0)] -pub type SendPacket = SendPacketBuffered>; -#[cfg(stage1)] -#[cfg(stage2)] pub type SendPacket = SendPacketBuffered>; #[doc(hidden)] -#[cfg(stage0)] -pub fn SendPacket(p: *Packet) -> SendPacket { - SendPacketBuffered(p) -} -#[cfg(stage1)] -#[cfg(stage2)] pub fn SendPacket(p: *Packet) -> SendPacket { SendPacketBuffered(p) } -#[cfg(stage0)] -pub struct SendPacketBuffered { - mut p: Option<*Packet>, - mut buffer: Option>, - drop { - //if self.p != none { - // debug!("drop send %?", option::get(self.p)); - //} - if self.p != None { - let mut p = None; - p <-> self.p; - sender_terminate(option::unwrap(move p)) - } - //unsafe { error!("send_drop: %?", - // if self.buffer == none { - // "none" - // } else { "some" }); } - } -} -#[cfg(stage1)] -#[cfg(stage2)] pub struct SendPacketBuffered { mut p: Option<*Packet>, mut buffer: Option>, @@ -985,20 +806,6 @@ impl SendPacketBuffered : ::ops::Drop { } } -#[cfg(stage0)] -pub fn SendPacketBuffered(p: *Packet) - -> SendPacketBuffered { - //debug!("take send %?", p); - SendPacketBuffered { - p: Some(p), - buffer: unsafe { - Some(BufferResource( - get_buffer(ptr::addr_of(&((*p).header))))) - } - } -} -#[cfg(stage1)] -#[cfg(stage2)] pub fn SendPacketBuffered(p: *Packet) -> SendPacketBuffered { //debug!("take send %?", p); @@ -1011,35 +818,6 @@ pub fn SendPacketBuffered(p: *Packet) } } -#[cfg(stage0)] -impl SendPacketBuffered { - fn unwrap() -> *Packet { - let mut p = None; - p <-> self.p; - option::unwrap(move p) - } - - pure fn header() -> *PacketHeader { - match self.p { - Some(packet) => unsafe { - let packet = &*packet; - let header = ptr::addr_of(&(packet.header)); - //forget(packet); - header - }, - None => fail ~"packet already consumed" - } - } - - fn reuse_buffer() -> BufferResource { - //error!("send reuse_buffer"); - let mut tmp = None; - tmp <-> self.buffer; - option::unwrap(move tmp) - } -} -#[cfg(stage1)] -#[cfg(stage2)] impl SendPacketBuffered { fn unwrap() -> *Packet { let mut p = None; @@ -1069,45 +847,12 @@ impl SendPacketBuffered { /// Represents the receive end of a pipe. It can receive exactly one /// message. -#[cfg(stage0)] -pub type RecvPacket = RecvPacketBuffered>; -#[cfg(stage1)] -#[cfg(stage2)] pub type RecvPacket = RecvPacketBuffered>; #[doc(hidden)] -#[cfg(stage0)] -pub fn RecvPacket(p: *Packet) -> RecvPacket { - RecvPacketBuffered(p) -} -#[doc(hidden)] -#[cfg(stage1)] -#[cfg(stage2)] pub fn RecvPacket(p: *Packet) -> RecvPacket { RecvPacketBuffered(p) } - -#[cfg(stage0)] -pub struct RecvPacketBuffered { - mut p: Option<*Packet>, - mut buffer: Option>, - drop { - //if self.p != none { - // debug!("drop recv %?", option::get(self.p)); - //} - if self.p != None { - let mut p = None; - p <-> self.p; - receiver_terminate(option::unwrap(move p)) - } - //unsafe { error!("recv_drop: %?", - // if self.buffer == none { - // "none" - // } else { "some" }); } - } -} -#[cfg(stage1)] -#[cfg(stage2)] pub struct RecvPacketBuffered { mut p: Option<*Packet>, mut buffer: Option>, @@ -1159,20 +904,6 @@ impl RecvPacketBuffered : Selectable { } } -#[cfg(stage0)] -pub fn RecvPacketBuffered(p: *Packet) - -> RecvPacketBuffered { - //debug!("take recv %?", p); - RecvPacketBuffered { - p: Some(p), - buffer: unsafe { - Some(BufferResource( - get_buffer(ptr::addr_of(&((*p).header))))) - } - } -} -#[cfg(stage1)] -#[cfg(stage2)] pub fn RecvPacketBuffered(p: *Packet) -> RecvPacketBuffered { //debug!("take recv %?", p); @@ -1186,14 +917,6 @@ pub fn RecvPacketBuffered(p: *Packet) } #[doc(hidden)] -#[cfg(stage0)] -pub fn entangle() -> (SendPacket, RecvPacket) { - let p = packet(); - (SendPacket(p), RecvPacket(p)) -} -#[doc(hidden)] -#[cfg(stage1)] -#[cfg(stage2)] pub fn entangle() -> (SendPacket, RecvPacket) { let p = packet(); (SendPacket(p), RecvPacket(p)) @@ -1289,47 +1012,21 @@ pub trait Peekable { } #[doc(hidden)] -#[cfg(stage0)] -struct Chan_ { - mut endp: Option> -} -#[doc(hidden)] -#[cfg(stage1)] -#[cfg(stage2)] struct Chan_ { mut endp: Option> } /// An endpoint that can send many messages. -#[cfg(stage0)] -pub enum Chan { - Chan_(Chan_) -} -#[cfg(stage1)] -#[cfg(stage2)] pub enum Chan { Chan_(Chan_) } #[doc(hidden)] -#[cfg(stage0)] -struct Port_ { - mut endp: Option>, -} -#[doc(hidden)] -#[cfg(stage1)] -#[cfg(stage2)] struct Port_ { mut endp: Option>, } /// An endpoint that can receive many messages. -#[cfg(stage0)] -pub enum Port { - Port_(Port_) -} -#[cfg(stage1)] -#[cfg(stage2)] pub enum Port { Port_(Port_) } @@ -1418,12 +1115,6 @@ impl Port: Selectable { } /// Treat many ports as one. -#[cfg(stage0)] -pub struct PortSet { - mut ports: ~[pipes::Port], -} -#[cfg(stage1)] -#[cfg(stage2)] pub struct PortSet { mut ports: ~[pipes::Port], } @@ -1489,10 +1180,6 @@ impl PortSet : Peekable { } /// A channel that can be shared between many senders. -#[cfg(stage0)] -pub type SharedChan = private::Exclusive>; -#[cfg(stage1)] -#[cfg(stage2)] pub type SharedChan = private::Exclusive>; impl SharedChan: GenericChan { @@ -1561,16 +1248,8 @@ proto! oneshot ( ) /// The send end of a oneshot pipe. -#[cfg(stage0)] -pub type ChanOne = oneshot::client::Oneshot; -#[cfg(stage1)] -#[cfg(stage2)] pub type ChanOne = oneshot::client::Oneshot; /// The receive end of a oneshot pipe. -#[cfg(stage0)] -pub type PortOne = oneshot::server::Oneshot; -#[cfg(stage1)] -#[cfg(stage2)] pub type PortOne = oneshot::server::Oneshot; /// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair. diff --git a/src/libcore/reflect.rs b/src/libcore/reflect.rs index 94fc9e37a75..dcbb7067670 100644 --- a/src/libcore/reflect.rs +++ b/src/libcore/reflect.rs @@ -75,434 +75,6 @@ impl MovePtrAdaptor { } /// Abstract type-directed pointer-movement using the MovePtr trait -#[cfg(stage0)] -impl MovePtrAdaptor: TyVisitor { - fn visit_bot() -> bool { - self.align_to::<()>(); - if ! self.inner.visit_bot() { return false; } - self.bump_past::<()>(); - true - } - - fn visit_nil() -> bool { - self.align_to::<()>(); - if ! self.inner.visit_nil() { return false; } - self.bump_past::<()>(); - true - } - - fn visit_bool() -> bool { - self.align_to::(); - if ! self.inner.visit_bool() { return false; } - self.bump_past::(); - true - } - - fn visit_int() -> bool { - self.align_to::(); - if ! self.inner.visit_int() { return false; } - self.bump_past::(); - true - } - - fn visit_i8() -> bool { - self.align_to::(); - if ! self.inner.visit_i8() { return false; } - self.bump_past::(); - true - } - - fn visit_i16() -> bool { - self.align_to::(); - if ! self.inner.visit_i16() { return false; } - self.bump_past::(); - true - } - - fn visit_i32() -> bool { - self.align_to::(); - if ! self.inner.visit_i32() { return false; } - self.bump_past::(); - true - } - - fn visit_i64() -> bool { - self.align_to::(); - if ! self.inner.visit_i64() { return false; } - self.bump_past::(); - true - } - - fn visit_uint() -> bool { - self.align_to::(); - if ! self.inner.visit_uint() { return false; } - self.bump_past::(); - true - } - - fn visit_u8() -> bool { - self.align_to::(); - if ! self.inner.visit_u8() { return false; } - self.bump_past::(); - true - } - - fn visit_u16() -> bool { - self.align_to::(); - if ! self.inner.visit_u16() { return false; } - self.bump_past::(); - true - } - - fn visit_u32() -> bool { - self.align_to::(); - if ! self.inner.visit_u32() { return false; } - self.bump_past::(); - true - } - - fn visit_u64() -> bool { - self.align_to::(); - if ! self.inner.visit_u64() { return false; } - self.bump_past::(); - true - } - - fn visit_float() -> bool { - self.align_to::(); - if ! self.inner.visit_float() { return false; } - self.bump_past::(); - true - } - - fn visit_f32() -> bool { - self.align_to::(); - if ! self.inner.visit_f32() { return false; } - self.bump_past::(); - true - } - - fn visit_f64() -> bool { - self.align_to::(); - if ! self.inner.visit_f64() { return false; } - self.bump_past::(); - true - } - - fn visit_char() -> bool { - self.align_to::(); - if ! self.inner.visit_char() { return false; } - self.bump_past::(); - true - } - - fn visit_str() -> bool { - self.align_to::<~str>(); - if ! self.inner.visit_str() { return false; } - self.bump_past::<~str>(); - true - } - - fn visit_estr_box() -> bool { - self.align_to::<@str>(); - if ! self.inner.visit_estr_box() { return false; } - self.bump_past::<@str>(); - true - } - - fn visit_estr_uniq() -> bool { - self.align_to::<~str>(); - if ! self.inner.visit_estr_uniq() { return false; } - self.bump_past::<~str>(); - true - } - - fn visit_estr_slice() -> bool { - self.align_to::<&static/str>(); - if ! self.inner.visit_estr_slice() { return false; } - self.bump_past::<&static/str>(); - true - } - - fn visit_estr_fixed(n: uint, - sz: uint, - align: uint) -> bool { - self.align(align); - if ! self.inner.visit_estr_fixed(n, sz, align) { return false; } - self.bump(sz); - true - } - - fn visit_box(mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<@u8>(); - if ! self.inner.visit_box(mtbl, inner) { return false; } - self.bump_past::<@u8>(); - true - } - - fn visit_uniq(mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<~u8>(); - if ! self.inner.visit_uniq(mtbl, inner) { return false; } - self.bump_past::<~u8>(); - true - } - - fn visit_ptr(mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<*u8>(); - if ! self.inner.visit_ptr(mtbl, inner) { return false; } - self.bump_past::<*u8>(); - true - } - - fn visit_rptr(mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<&static/u8>(); - if ! self.inner.visit_rptr(mtbl, inner) { return false; } - self.bump_past::<&static/u8>(); - true - } - - fn visit_unboxed_vec(mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::(); - if ! self.inner.visit_vec(mtbl, inner) { return false; } - true - } - - fn visit_vec(mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<~[u8]>(); - if ! self.inner.visit_vec(mtbl, inner) { return false; } - self.bump_past::<~[u8]>(); - true - } - - fn visit_evec_box(mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<@[u8]>(); - if ! self.inner.visit_evec_box(mtbl, inner) { return false; } - self.bump_past::<@[u8]>(); - true - } - - fn visit_evec_uniq(mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<~[u8]>(); - if ! self.inner.visit_evec_uniq(mtbl, inner) { return false; } - self.bump_past::<~[u8]>(); - true - } - - fn visit_evec_slice(mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<&static/[u8]>(); - if ! self.inner.visit_evec_slice(mtbl, inner) { return false; } - self.bump_past::<&static/[u8]>(); - true - } - - fn visit_evec_fixed(n: uint, sz: uint, align: uint, - mtbl: uint, inner: *TyDesc) -> bool { - self.align(align); - if ! self.inner.visit_evec_fixed(n, sz, align, mtbl, inner) { - return false; - } - self.bump(sz); - true - } - - fn visit_enter_rec(n_fields: uint, sz: uint, align: uint) -> bool { - self.align(align); - if ! self.inner.visit_enter_rec(n_fields, sz, align) { return false; } - true - } - - fn visit_rec_field(i: uint, name: &str, - mtbl: uint, inner: *TyDesc) -> bool { - unsafe { self.align((*inner).align); } - if ! self.inner.visit_rec_field(i, name, mtbl, inner) { - return false; - } - unsafe { self.bump((*inner).size); } - true - } - - fn visit_leave_rec(n_fields: uint, sz: uint, align: uint) -> bool { - if ! self.inner.visit_leave_rec(n_fields, sz, align) { return false; } - true - } - - fn visit_enter_class(n_fields: uint, sz: uint, align: uint) - -> bool { - self.align(align); - if ! self.inner.visit_enter_class(n_fields, sz, align) { - return false; - } - true - } - - fn visit_class_field(i: uint, name: &str, - mtbl: uint, inner: *TyDesc) -> bool { - unsafe { self.align((*inner).align); } - if ! self.inner.visit_class_field(i, name, mtbl, inner) { - return false; - } - unsafe { self.bump((*inner).size); } - true - } - - fn visit_leave_class(n_fields: uint, sz: uint, align: uint) - -> bool { - if ! self.inner.visit_leave_class(n_fields, sz, align) { - return false; - } - true - } - - fn visit_enter_tup(n_fields: uint, sz: uint, align: uint) -> bool { - self.align(align); - if ! self.inner.visit_enter_tup(n_fields, sz, align) { return false; } - true - } - - fn visit_tup_field(i: uint, inner: *TyDesc) -> bool { - unsafe { self.align((*inner).align); } - if ! self.inner.visit_tup_field(i, inner) { return false; } - unsafe { self.bump((*inner).size); } - true - } - - fn visit_leave_tup(n_fields: uint, sz: uint, align: uint) -> bool { - if ! self.inner.visit_leave_tup(n_fields, sz, align) { return false; } - true - } - - fn visit_enter_fn(purity: uint, proto: uint, - n_inputs: uint, retstyle: uint) -> bool { - if ! self.inner.visit_enter_fn(purity, proto, n_inputs, retstyle) { - return false - } - true - } - - fn visit_fn_input(i: uint, mode: uint, inner: *TyDesc) -> bool { - if ! self.inner.visit_fn_input(i, mode, inner) { return false; } - true - } - - fn visit_fn_output(retstyle: uint, inner: *TyDesc) -> bool { - if ! self.inner.visit_fn_output(retstyle, inner) { return false; } - true - } - - fn visit_leave_fn(purity: uint, proto: uint, - n_inputs: uint, retstyle: uint) -> bool { - if ! self.inner.visit_leave_fn(purity, proto, n_inputs, retstyle) { - return false; - } - true - } - - fn visit_enter_enum(n_variants: uint, sz: uint, align: uint) - -> bool { - self.align(align); - if ! self.inner.visit_enter_enum(n_variants, sz, align) { - return false; - } - true - } - - fn visit_enter_enum_variant(variant: uint, - disr_val: int, - n_fields: uint, - name: &str) -> bool { - self.inner.push_ptr(); - if ! self.inner.visit_enter_enum_variant(variant, disr_val, - n_fields, name) { - return false; - } - true - } - - fn visit_enum_variant_field(i: uint, inner: *TyDesc) -> bool { - unsafe { self.align((*inner).align); } - if ! self.inner.visit_enum_variant_field(i, inner) { return false; } - unsafe { self.bump((*inner).size); } - true - } - - fn visit_leave_enum_variant(variant: uint, - disr_val: int, - n_fields: uint, - name: &str) -> bool { - if ! self.inner.visit_leave_enum_variant(variant, disr_val, - n_fields, name) { - return false; - } - self.inner.pop_ptr(); - true - } - - fn visit_leave_enum(n_variants: uint, sz: uint, align: uint) - -> bool { - if ! self.inner.visit_leave_enum(n_variants, sz, align) { - return false; - } - self.bump(sz); - true - } - - fn visit_trait() -> bool { - self.align_to::(); - if ! self.inner.visit_trait() { return false; } - self.bump_past::(); - true - } - - fn visit_var() -> bool { - if ! self.inner.visit_var() { return false; } - true - } - - fn visit_var_integral() -> bool { - if ! self.inner.visit_var_integral() { return false; } - true - } - - fn visit_param(i: uint) -> bool { - if ! self.inner.visit_param(i) { return false; } - true - } - - fn visit_self() -> bool { - self.align_to::<&static/u8>(); - if ! self.inner.visit_self() { return false; } - self.align_to::<&static/u8>(); - true - } - - fn visit_type() -> bool { - if ! self.inner.visit_type() { return false; } - true - } - - fn visit_opaque_box() -> bool { - self.align_to::<@u8>(); - if ! self.inner.visit_opaque_box() { return false; } - self.bump_past::<@u8>(); - true - } - - fn visit_constr(inner: *TyDesc) -> bool { - if ! self.inner.visit_constr(inner) { return false; } - true - } - - fn visit_closure_ptr(ck: uint) -> bool { - self.align_to::(); - if ! self.inner.visit_closure_ptr(ck) { return false; } - self.bump_past::(); - true - } -} - -/// Abstract type-directed pointer-movement using the MovePtr trait -#[cfg(stage1)] -#[cfg(stage2)] impl MovePtrAdaptor: TyVisitor { fn visit_bot(&self) -> bool { self.align_to::<()>(); diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index 75a572fa464..cce5cac8683 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -265,303 +265,6 @@ impl ReprVisitor { } -#[cfg(stage0)] -impl ReprVisitor : TyVisitor { - fn visit_bot() -> bool { - self.writer.write_str("!"); - true - } - fn visit_nil() -> bool { self.write::<()>() } - fn visit_bool() -> bool { self.write::() } - fn visit_int() -> bool { self.write::() } - fn visit_i8() -> bool { self.write::() } - fn visit_i16() -> bool { self.write::() } - fn visit_i32() -> bool { self.write::() } - fn visit_i64() -> bool { self.write::() } - - fn visit_uint() -> bool { self.write::() } - fn visit_u8() -> bool { self.write::() } - fn visit_u16() -> bool { self.write::() } - fn visit_u32() -> bool { self.write::() } - fn visit_u64() -> bool { self.write::() } - - fn visit_float() -> bool { self.write::() } - fn visit_f32() -> bool { self.write::() } - fn visit_f64() -> bool { self.write::() } - - fn visit_char() -> bool { - do self.get:: |&ch| { - self.writer.write_char('\''); - self.writer.write_escaped_char(ch); - self.writer.write_char('\''); - } - } - - // Type no longer exists, vestigial function. - fn visit_str() -> bool { fail; } - - fn visit_estr_box() -> bool { - do self.get::<@str> |s| { - self.writer.write_char('@'); - self.write_escaped_slice(*s); - } - } - fn visit_estr_uniq() -> bool { - do self.get::<~str> |s| { - self.writer.write_char('~'); - self.write_escaped_slice(*s); - } - } - fn visit_estr_slice() -> bool { - do self.get::<&str> |s| { - self.write_escaped_slice(*s); - } - } - - // Type no longer exists, vestigial function. - fn visit_estr_fixed(_n: uint, _sz: uint, - _align: uint) -> bool { fail; } - - fn visit_box(mtbl: uint, inner: *TyDesc) -> bool { - self.writer.write_char('@'); - self.write_mut_qualifier(mtbl); - do self.get::<&managed::raw::BoxRepr> |b| { - let p = ptr::to_unsafe_ptr(&b.data) as *c_void; - self.visit_ptr_inner(p, inner); - } - } - - fn visit_uniq(mtbl: uint, inner: *TyDesc) -> bool { - self.writer.write_char('~'); - self.write_mut_qualifier(mtbl); - do self.get::<&managed::raw::BoxRepr> |b| { - let p = ptr::to_unsafe_ptr(&b.data) as *c_void; - self.visit_ptr_inner(p, inner); - } - } - - fn visit_ptr(_mtbl: uint, _inner: *TyDesc) -> bool { - do self.get::<*c_void> |p| { - self.writer.write_str(fmt!("(0x%x as *())", - *p as uint)); - } - } - - fn visit_rptr(mtbl: uint, inner: *TyDesc) -> bool { - self.writer.write_char('&'); - self.write_mut_qualifier(mtbl); - do self.get::<*c_void> |p| { - self.visit_ptr_inner(*p, inner); - } - } - - // Type no longer exists, vestigial function. - fn visit_vec(_mtbl: uint, _inner: *TyDesc) -> bool { fail; } - - - fn visit_unboxed_vec(mtbl: uint, inner: *TyDesc) -> bool { - do self.get:: |b| { - self.write_unboxed_vec_repr(mtbl, b, inner); - } - } - - fn visit_evec_box(mtbl: uint, inner: *TyDesc) -> bool { - do self.get::<&VecRepr> |b| { - self.writer.write_char('@'); - self.write_unboxed_vec_repr(mtbl, &b.unboxed, inner); - } - } - - fn visit_evec_uniq(mtbl: uint, inner: *TyDesc) -> bool { - do self.get::<&VecRepr> |b| { - self.writer.write_char('~'); - self.write_unboxed_vec_repr(mtbl, &b.unboxed, inner); - } - } - - fn visit_evec_slice(mtbl: uint, inner: *TyDesc) -> bool { - do self.get:: |s| { - self.writer.write_char('&'); - self.write_vec_range(mtbl, s.data, s.len, inner); - } - } - - fn visit_evec_fixed(_n: uint, sz: uint, _align: uint, - mtbl: uint, inner: *TyDesc) -> bool { - do self.get:: |b| { - self.write_vec_range(mtbl, ptr::to_unsafe_ptr(b), sz, inner); - } - } - - fn visit_enter_rec(_n_fields: uint, - _sz: uint, _align: uint) -> bool { - self.writer.write_char('{'); - true - } - - fn visit_rec_field(i: uint, name: &str, - mtbl: uint, inner: *TyDesc) -> bool { - if i != 0 { - self.writer.write_str(", "); - } - self.write_mut_qualifier(mtbl); - self.writer.write_str(name); - self.writer.write_str(": "); - self.visit_inner(inner); - true - } - - fn visit_leave_rec(_n_fields: uint, - _sz: uint, _align: uint) -> bool { - self.writer.write_char('}'); - true - } - - fn visit_enter_class(_n_fields: uint, - _sz: uint, _align: uint) -> bool { - self.writer.write_char('{'); - true - } - fn visit_class_field(i: uint, name: &str, - mtbl: uint, inner: *TyDesc) -> bool { - if i != 0 { - self.writer.write_str(", "); - } - self.write_mut_qualifier(mtbl); - self.writer.write_str(name); - self.writer.write_str(": "); - self.visit_inner(inner); - true - } - fn visit_leave_class(_n_fields: uint, - _sz: uint, _align: uint) -> bool { - self.writer.write_char('}'); - true - } - - fn visit_enter_tup(_n_fields: uint, - _sz: uint, _align: uint) -> bool { - self.writer.write_char('('); - true - } - fn visit_tup_field(i: uint, inner: *TyDesc) -> bool { - if i != 0 { - self.writer.write_str(", "); - } - self.visit_inner(inner); - true - } - fn visit_leave_tup(_n_fields: uint, - _sz: uint, _align: uint) -> bool { - self.writer.write_char(')'); - true - } - - fn visit_enter_enum(n_variants: uint, - _sz: uint, _align: uint) -> bool { - if n_variants == 1 { - self.var_stk.push(Degenerate) - } else { - self.var_stk.push(TagMatch) - } - true - } - fn visit_enter_enum_variant(_variant: uint, - disr_val: int, - n_fields: uint, - name: &str) -> bool { - let mut write = false; - match self.var_stk.pop() { - Degenerate => { - write = true; - self.var_stk.push(Degenerate); - } - TagMatch | TagMismatch => { - do self.get::() |t| { - if disr_val == *t { - write = true; - self.var_stk.push(TagMatch); - } else { - self.var_stk.push(TagMismatch); - } - }; - self.bump_past::(); - } - } - - if write { - self.writer.write_str(name); - if n_fields > 0 { - self.writer.write_char('('); - } - } - true - } - fn visit_enum_variant_field(i: uint, inner: *TyDesc) -> bool { - match self.var_stk.last() { - Degenerate | TagMatch => { - if i != 0 { - self.writer.write_str(", "); - } - if ! self.visit_inner(inner) { - return false; - } - } - TagMismatch => () - } - true - } - fn visit_leave_enum_variant(_variant: uint, - _disr_val: int, - n_fields: uint, - _name: &str) -> bool { - match self.var_stk.last() { - Degenerate | TagMatch => { - if n_fields > 0 { - self.writer.write_char(')'); - } - } - TagMismatch => () - } - true - } - fn visit_leave_enum(_n_variants: uint, - _sz: uint, _align: uint) -> bool { - self.var_stk.pop(); - true - } - - fn visit_enter_fn(_purity: uint, _proto: uint, - _n_inputs: uint, _retstyle: uint) -> bool { true } - fn visit_fn_input(_i: uint, _mode: uint, _inner: *TyDesc) -> bool { true } - fn visit_fn_output(_retstyle: uint, _inner: *TyDesc) -> bool { true } - fn visit_leave_fn(_purity: uint, _proto: uint, - _n_inputs: uint, _retstyle: uint) -> bool { true } - - - fn visit_trait() -> bool { true } - fn visit_var() -> bool { true } - fn visit_var_integral() -> bool { true } - fn visit_param(_i: uint) -> bool { true } - fn visit_self() -> bool { true } - fn visit_type() -> bool { true } - - fn visit_opaque_box() -> bool { - self.writer.write_char('@'); - do self.get::<&managed::raw::BoxRepr> |b| { - let p = ptr::to_unsafe_ptr(&b.data) as *c_void; - self.visit_ptr_inner(p, b.header.type_desc); - } - } - - // Type no longer exists, vestigial function. - fn visit_constr(_inner: *TyDesc) -> bool { fail; } - - fn visit_closure_ptr(_ck: uint) -> bool { true } -} - -#[cfg(stage1)] -#[cfg(stage2)] impl ReprVisitor : TyVisitor { fn visit_bot(&self) -> bool { self.writer.write_str("!"); From 793f20ad327f08a59dea5f67cd07ffddf9679d15 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 29 Jan 2013 16:56:59 -0800 Subject: [PATCH 04/37] std: remove transitional code --- src/libstd/comm.rs | 7 ------- src/libstd/workcache.rs | 21 --------------------- 2 files changed, 28 deletions(-) diff --git a/src/libstd/comm.rs b/src/libstd/comm.rs index f4917934acb..dc0fbbac641 100644 --- a/src/libstd/comm.rs +++ b/src/libstd/comm.rs @@ -23,13 +23,6 @@ use core::pipes; use core::prelude::*; /// An extension of `pipes::stream` that allows both sending and receiving. -#[cfg(stage0)] -pub struct DuplexStream { - priv chan: Chan, - priv port: Port, -} -#[cfg(stage1)] -#[cfg(stage2)] pub struct DuplexStream { priv chan: Chan, priv port: Port, diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index 81285e5e563..f9a2f934e46 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -167,20 +167,6 @@ struct Database { } impl Database { - #[cfg(stage0)] - #[cfg(stage1)] - fn prepare(&mut self, fn_name: &str, - declared_inputs: &WorkMap) -> Option<(WorkMap, WorkMap, ~str)> - { - let k = json_encode(&(fn_name, declared_inputs)); - let db_cache = copy self.db_cache; - match db_cache.find(&k) { - None => None, - Some(&v) => Some(json_decode(copy v)) - } - } - - #[cfg(stage2)] fn prepare(&mut self, fn_name: &str, declared_inputs: &WorkMap) -> Option<(WorkMap, WorkMap, ~str)> { @@ -235,13 +221,6 @@ struct Exec { discovered_outputs: WorkMap } -#[cfg(stage0)] -struct Work { - prep: @Mut, - res: Option>> -} -#[cfg(stage1)] -#[cfg(stage2)] struct Work { prep: @Mut, res: Option>> From e6e1470f97507c1c4841c18cbeb2d9a95e7773ae Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 29 Jan 2013 16:57:29 -0800 Subject: [PATCH 05/37] syntax: remove transitional code --- src/libsyntax/ext/pipes/pipec.rs | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 9cf9038ef7e..7bf4f2dc1d9 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -355,34 +355,6 @@ pub impl protocol: gen_init { })) } - #[cfg(stage0)] - fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr { - debug!("gen_init_bounded"); - let buffer_fields = self.gen_buffer_init(ext_cx); - let buffer = quote_expr!(~{ - header: ::pipes::BufferHeader(), - data: $buffer_fields, - }); - - let entangle_body = ext_cx.block_expr( - ext_cx.block( - self.states.map_to_vec( - |s| ext_cx.parse_stmt( - fmt!("data.%s.set_buffer(buffer)", - s.name))), - ext_cx.parse_expr( - fmt!("::ptr::addr_of(&(data.%s))", - self.states[0].name)))); - - quote_expr!({ - let buffer = $buffer; - do ::pipes::entangle_buffer(move buffer) |buffer, data| { - $entangle_body - } - }) - } - #[cfg(stage1)] - #[cfg(stage2)] fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr { debug!("gen_init_bounded"); let buffer_fields = self.gen_buffer_init(ext_cx); From 6f0bede97c3468eaba8cf59702d04c7ede8f4b0a Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 29 Jan 2013 16:57:41 -0800 Subject: [PATCH 06/37] testsuite: Remove call to set_buffer_, use set_buffer --- src/test/run-pass/pipe-pingpong-bounded.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index d251fbf8f76..e8ae5db62aa 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -37,8 +37,8 @@ mod pingpong { } }; do pipes::entangle_buffer(move buffer) |buffer, data| { - data.ping.set_buffer_(buffer); - data.pong.set_buffer_(buffer); + data.ping.set_buffer(buffer); + data.pong.set_buffer(buffer); ptr::addr_of(&(data.ping)) } } From 8e643525d4e5bca993dada43615916c382a0645b Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sun, 3 Feb 2013 23:29:17 -0500 Subject: [PATCH 07/37] oldmap: use &K instead of K in find and get --- src/libcargo/cargo.rc | 18 +-- src/librustc/back/link.rs | 2 +- src/librustc/driver/driver.rs | 2 +- src/librustc/lib/llvm.rs | 4 +- src/librustc/metadata/cstore.rs | 4 +- src/librustc/metadata/decoder.rs | 2 +- src/librustc/metadata/encoder.rs | 16 +-- src/librustc/metadata/tydecode.rs | 2 +- src/librustc/metadata/tyencode.rs | 4 +- src/librustc/middle/astencode.rs | 28 ++--- src/librustc/middle/borrowck/check_loans.rs | 20 ++-- src/librustc/middle/borrowck/gather_loans.rs | 8 +- src/librustc/middle/borrowck/loan.rs | 2 +- src/librustc/middle/borrowck/preserve.rs | 10 +- src/librustc/middle/check_const.rs | 8 +- src/librustc/middle/check_match.rs | 14 +-- src/librustc/middle/const_eval.rs | 6 +- src/librustc/middle/freevars.rs | 4 +- src/librustc/middle/kind.rs | 10 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/lint.rs | 6 +- src/librustc/middle/liveness.rs | 28 ++--- src/librustc/middle/mem_categorization.rs | 8 +- src/librustc/middle/moves.rs | 4 +- src/librustc/middle/pat_util.rs | 4 +- src/librustc/middle/privacy.rs | 12 +- src/librustc/middle/region.rs | 16 +-- src/librustc/middle/resolve.rs | 55 ++++----- src/librustc/middle/trans/_match.rs | 23 ++-- src/librustc/middle/trans/base.rs | 30 ++--- src/librustc/middle/trans/build.rs | 4 +- src/librustc/middle/trans/callee.rs | 8 +- src/librustc/middle/trans/closure.rs | 2 +- src/librustc/middle/trans/common.rs | 6 +- src/librustc/middle/trans/consts.rs | 12 +- src/librustc/middle/trans/controlflow.rs | 2 +- src/librustc/middle/trans/datum.rs | 4 +- src/librustc/middle/trans/debuginfo.rs | 18 +-- src/librustc/middle/trans/expr.rs | 18 +-- src/librustc/middle/trans/foreign.rs | 100 ++++++++--------- src/librustc/middle/trans/glue.rs | 2 +- src/librustc/middle/trans/inline.rs | 2 +- src/librustc/middle/trans/machine.rs | 2 +- src/librustc/middle/trans/meth.rs | 18 +-- src/librustc/middle/trans/monomorphize.rs | 6 +- src/librustc/middle/trans/reachable.rs | 12 +- src/librustc/middle/trans/reflect.rs | 2 +- src/librustc/middle/trans/type_of.rs | 2 +- src/librustc/middle/trans/type_use.rs | 12 +- src/librustc/middle/ty.rs | 56 +++++----- src/librustc/middle/typeck/astconv.rs | 6 +- src/librustc/middle/typeck/check/_match.rs | 10 +- src/librustc/middle/typeck/check/method.rs | 13 ++- src/librustc/middle/typeck/check/mod.rs | 48 ++++---- src/librustc/middle/typeck/check/regionck.rs | 6 +- src/librustc/middle/typeck/check/vtable.rs | 6 +- src/librustc/middle/typeck/check/writeback.rs | 4 +- src/librustc/middle/typeck/coherence.rs | 29 ++--- src/librustc/middle/typeck/collect.rs | 22 ++-- .../middle/typeck/infer/region_inference.rs | 2 +- src/librustc/middle/typeck/mod.rs | 4 +- src/librustc/util/ppaux.rs | 6 +- src/librustdoc/attr_pass.rs | 6 +- src/librustdoc/prune_hidden_pass.rs | 2 +- src/librustdoc/prune_private_pass.rs | 2 +- src/librustdoc/tystr_pass.rs | 14 +-- src/libstd/oldmap.rs | 105 +++++++++--------- src/libsyntax/ast_map.rs | 4 +- src/libsyntax/ext/expand.rs | 8 +- src/libsyntax/ext/tt/macro_rules.rs | 4 +- src/libsyntax/ext/tt/transcribe.rs | 2 +- src/libsyntax/util/interner.rs | 2 +- src/test/auxiliary/issue-2631-a.rs | 2 +- src/test/bench/core-map.rs | 4 +- src/test/bench/core-std.rs | 2 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 2 +- src/test/bench/shootout-mandelbrot.rs | 2 +- src/test/run-pass/hashmap-memory.rs | 4 +- 78 files changed, 482 insertions(+), 479 deletions(-) diff --git a/src/libcargo/cargo.rc b/src/libcargo/cargo.rc index 960bcf88eb7..cff44ed5ef2 100644 --- a/src/libcargo/cargo.rc +++ b/src/libcargo/cargo.rc @@ -731,7 +731,7 @@ pub fn configure(opts: Options) -> Cargo { need_dir(&c.bindir); for sources.each_key_ref |&k| { - let mut s = sources.get(k); + let mut s = sources.get(&k); load_source_packages(&c, s); sources.insert(k, s); } @@ -981,7 +981,7 @@ pub fn install_named(c: &mut Cargo, wd: &Path, name: ~str) { pub fn install_uuid_specific(c: &mut Cargo, wd: &Path, src: ~str, uuid: ~str) { - match c.sources.find(src) { + match c.sources.find(&src) { Some(s) => { for s.packages.each |p| { if p.uuid == uuid { @@ -997,7 +997,7 @@ pub fn install_uuid_specific(c: &mut Cargo, wd: &Path, src: ~str, pub fn install_named_specific(c: &mut Cargo, wd: &Path, src: ~str, name: ~str) { - match c.sources.find(src) { + match c.sources.find(&src) { Some(s) => { for s.packages.each |p| { if p.name == name { @@ -1064,7 +1064,7 @@ pub fn cmd_uninstall(c: &Cargo) { } pub fn install_query(c: &mut Cargo, wd: &Path, target: ~str) { - match c.dep_cache.find(target) { + match c.dep_cache.find(&target) { Some(inst) => { if inst { return; @@ -1156,7 +1156,7 @@ pub fn cmd_install(c: &mut Cargo) { pub fn sync(c: &Cargo) { for c.sources.each_key_ref |&k| { - let mut s = c.sources.get(k); + let mut s = c.sources.get(&k); sync_one(c, s); c.sources.insert(k, s); } @@ -1558,7 +1558,7 @@ pub fn cmd_list(c: &Cargo) { if !valid_pkg_name(*name) { error(fmt!("'%s' is an invalid source name", *name)); } else { - match c.sources.find(*name) { + match c.sources.find(name) { Some(source) => { print_source(source); } @@ -1754,7 +1754,7 @@ pub fn cmd_sources(c: &Cargo) { return; } - match c.sources.find(name) { + match c.sources.find(&name) { Some(source) => { let old = copy source.url; let method = assume_source_method(url); @@ -1785,7 +1785,7 @@ pub fn cmd_sources(c: &Cargo) { return; } - match c.sources.find(name) { + match c.sources.find(&name) { Some(source) => { let old = copy source.method; @@ -1823,7 +1823,7 @@ pub fn cmd_sources(c: &Cargo) { return; } - match c.sources.find(name) { + match c.sources.find(&name) { Some(source) => { c.sources.remove(&name); c.sources.insert(newn, source); diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 22923cb7290..de7c52520cc 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -596,7 +596,7 @@ pub fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t, } pub fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> @str { - match ccx.type_hashcodes.find(t) { + match ccx.type_hashcodes.find(&t) { Some(h) => h, None => { let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta); diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 1464fa29afc..5bbf3f839ad 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -538,7 +538,7 @@ pub fn build_session_options(+binary: ~str, getopts::opt_strs(matches, level_name)); for flags.each |lint_name| { let lint_name = str::replace(*lint_name, ~"-", ~"_"); - match lint_dict.find(/*bad*/ copy lint_name) { + match lint_dict.find(&lint_name) { None => { early_error(demitter, fmt!("unknown %s flag: %s", level_name, lint_name)); diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index e114a18f4fd..50f4fe43efd 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -1331,11 +1331,11 @@ pub fn associate_type(tn: type_names, s: @str, t: TypeRef) { } pub fn type_has_name(tn: type_names, t: TypeRef) -> Option<@str> { - return tn.type_names.find(t); + return tn.type_names.find(&t); } pub fn name_has_type(tn: type_names, s: @str) -> Option { - return tn.named_types.find(s); + return tn.named_types.find(&s); } pub fn mk_type_names() -> type_names { diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index c8a1a619436..1faf8e13fda 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -74,7 +74,7 @@ pub fn mk_cstore(intr: @ident_interner) -> CStore { pub fn get_crate_data(cstore: CStore, cnum: ast::crate_num) -> crate_metadata { - return p(cstore).metas.get(cnum); + return p(cstore).metas.get(&cnum); } pub fn get_crate_hash(cstore: CStore, cnum: ast::crate_num) -> ~str { @@ -139,7 +139,7 @@ pub fn add_use_stmt_cnum(cstore: CStore, use_id: ast::node_id, pub fn find_use_stmt_cnum(cstore: CStore, use_id: ast::node_id) -> Option { - p(cstore).use_crate_map.find(use_id) + p(cstore).use_crate_map.find(&use_id) } // returns hashes of crates directly used by this crate. Hashes are diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index c3c7c969cd8..9a6a2f7e954 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -1099,7 +1099,7 @@ pub fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id { return ast::def_id { crate: cdata.cnum, node: did.node }; } - match cdata.cnum_map.find(did.crate) { + match cdata.cnum_map.find(&did.crate) { option::Some(n) => ast::def_id { crate: n, node: did.node }, option::None => die!(~"didn't find a crate in the cnum_map") } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 438084a3bd7..072b974d042 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -118,7 +118,7 @@ pub fn encode_def_id(ebml_w: writer::Encoder, id: def_id) { fn encode_region_param(ecx: @encode_ctxt, ebml_w: writer::Encoder, it: @ast::item) { - let opt_rp = ecx.tcx.region_paramd_items.find(it.id); + let opt_rp = ecx.tcx.region_paramd_items.find(&it.id); for opt_rp.each |rp| { do ebml_w.wr_tag(tag_region_param) { (*rp).encode(&ebml_w); @@ -184,7 +184,7 @@ fn encode_ty_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt, fn encode_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt, params: &[ty_param]) { let ty_param_bounds = - @params.map(|param| ecx.tcx.ty_param_bounds.get(param.id)); + @params.map(|param| ecx.tcx.ty_param_bounds.get(¶m.id)); encode_ty_type_param_bounds(ebml_w, ecx, ty_param_bounds); } @@ -224,7 +224,7 @@ fn encode_type(ecx: @encode_ctxt, ebml_w: writer::Encoder, typ: ty::t) { fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) { ebml_w.start_tag(tag_items_data_item_symbol); - let sym = match ecx.item_symbols.find(id) { + let sym = match ecx.item_symbols.find(&id) { Some(ref x) => (/*bad*/copy *x), None => { ecx.diag.handler().bug( @@ -238,7 +238,7 @@ fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) { fn encode_discriminant(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) { ebml_w.start_tag(tag_items_data_item_symbol); - ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(id))); + ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(&id))); ebml_w.end_tag(); } @@ -349,7 +349,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder, // Encode the reexports of this module. debug!("(encoding info for module) encoding reexports for %d", id); - match ecx.reexports2.find(id) { + match ecx.reexports2.find(&id) { Some(ref exports) => { debug!("(encoding info for module) found reexports for %d", id); for (*exports).each |exp| { @@ -813,7 +813,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder, encode_name(ecx, ebml_w, ty_m.ident); encode_family(ebml_w, purity_static_method_family(ty_m.purity)); - let polyty = ecx.tcx.tcache.get(local_def(ty_m.id)); + let polyty = ecx.tcx.tcache.get(&local_def(ty_m.id)); encode_ty_type_param_bounds(ebml_w, ecx, polyty.bounds); encode_type(ecx, ebml_w, polyty.ty); let mut m_path = vec::append(~[], path); // :-( @@ -881,7 +881,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: writer::Encoder, let ebml_w = copy ebml_w; |i, cx, v| { visit::visit_item(i, cx, v); - match ecx.tcx.items.get(i.id) { + match ecx.tcx.items.get(&i.id) { ast_map::node_item(_, pt) => { encode_info_for_item(ecx, ebml_w, i, index, *pt); @@ -894,7 +894,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: writer::Encoder, let ebml_w = copy ebml_w; |ni, cx, v| { visit::visit_foreign_item(ni, cx, v); - match ecx.tcx.items.get(ni.id) { + match ecx.tcx.items.get(&ni.id) { ast_map::node_foreign_item(_, abi, pt) => { encode_info_for_foreign_item(ecx, ebml_w, ni, index, /*bad*/copy *pt, diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 5dd499dfd63..ea13325ad49 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -329,7 +329,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t { let len = parse_hex(st); assert (next(st) == '#'); let key = creader_cache_key { cnum: st.crate, pos: pos, len: len }; - match st.tcx.rcache.find(key) { + match st.tcx.rcache.find(&key) { Some(tt) => return tt, None => { let ps = @{pos: pos ,.. copy *st}; diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index a0e2065b20b..0d66862c79f 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -56,7 +56,7 @@ fn cx_uses_abbrevs(cx: @ctxt) -> bool { pub fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) { match cx.abbrevs { ac_no_abbrevs => { - let result_str = match cx.tcx.short_names_cache.find(t) { + let result_str = match cx.tcx.short_names_cache.find(&t) { Some(s) => /*bad*/copy *s, None => { let s = do io::with_str_writer |wr| { @@ -69,7 +69,7 @@ pub fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) { w.write_str(result_str); } ac_use_abbrevs(abbrevs) => { - match abbrevs.find(t) { + match abbrevs.find(&t) { Some(a) => { w.write_str(*a.s); return; } None => { let pos = w.tell(); diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 2fc592e131e..71599463382 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -838,7 +838,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, debug!("Encoding side tables for id %d", id); - do option::iter(&tcx.def_map.find(id)) |def| { + do option::iter(&tcx.def_map.find(&id)) |def| { do ebml_w.tag(c::tag_table_def) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -855,7 +855,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.node_type_substs.find(id)) |tys| { + do option::iter(&tcx.node_type_substs.find(&id)) |tys| { do ebml_w.tag(c::tag_table_node_type_subst) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -864,7 +864,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.freevars.find(id)) |fv| { + do option::iter(&tcx.freevars.find(&id)) |fv| { do ebml_w.tag(c::tag_table_freevars) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -876,7 +876,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } let lid = ast::def_id { crate: ast::local_crate, node: id }; - do option::iter(&tcx.tcache.find(lid)) |tpbt| { + do option::iter(&tcx.tcache.find(&lid)) |tpbt| { do ebml_w.tag(c::tag_table_tcache) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -885,7 +885,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.ty_param_bounds.find(id)) |pbs| { + do option::iter(&tcx.ty_param_bounds.find(&id)) |pbs| { do ebml_w.tag(c::tag_table_param_bounds) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -899,7 +899,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, // is what we actually use in trans, all modes will have been // resolved. // - //option::iter(tcx.inferred_modes.find(id)) {|m| + //option::iter(tcx.inferred_modes.find(&id)) {|m| // ebml_w.tag(c::tag_table_inferred_modes) {|| // ebml_w.id(id); // ebml_w.tag(c::tag_table_val) {|| @@ -908,13 +908,13 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, // } //} - do option::iter(&maps.mutbl_map.find(id)) |_m| { + do option::iter(&maps.mutbl_map.find(&id)) |_m| { do ebml_w.tag(c::tag_table_mutbl) { ebml_w.id(id); } } - do option::iter(&maps.last_use_map.find(id)) |m| { + do option::iter(&maps.last_use_map.find(&id)) |m| { do ebml_w.tag(c::tag_table_last_use) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -925,7 +925,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&maps.method_map.find(id)) |mme| { + do option::iter(&maps.method_map.find(&id)) |mme| { do ebml_w.tag(c::tag_table_method_map) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -934,7 +934,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&maps.vtable_map.find(id)) |dr| { + do option::iter(&maps.vtable_map.find(&id)) |dr| { do ebml_w.tag(c::tag_table_vtable_map) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -943,7 +943,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.adjustments.find(id)) |adj| { + do option::iter(&tcx.adjustments.find(&id)) |adj| { do ebml_w.tag(c::tag_table_adjustments) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -952,19 +952,19 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.legacy_boxed_traits.find(id)) |_x| { + do option::iter(&tcx.legacy_boxed_traits.find(&id)) |_x| { do ebml_w.tag(c::tag_table_legacy_boxed_trait) { ebml_w.id(id); } } - for maps.moves_map.find(id).each |_| { + for maps.moves_map.find(&id).each |_| { do ebml_w.tag(c::tag_table_moves_map) { ebml_w.id(id); } } - for maps.capture_map.find(id).each |cap_vars| { + for maps.capture_map.find(&id).each |cap_vars| { do ebml_w.tag(c::tag_table_capture_map) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 19740b6a929..9b2d51289ad 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -126,12 +126,12 @@ impl check_loan_ctxt { let region_map = self.tcx().region_map; let pure_map = self.req_maps.pure_map; loop { - match pure_map.find(scope_id) { + match pure_map.find(&scope_id) { None => (), Some(ref e) => return Some(pc_cmt((*e))) } - match region_map.find(scope_id) { + match region_map.find(&scope_id) { None => return default_purity, Some(next_scope_id) => scope_id = next_scope_id } @@ -144,13 +144,13 @@ impl check_loan_ctxt { let req_loan_map = self.req_maps.req_loan_map; loop { - for req_loan_map.find(scope_id).each |loans| { + for req_loan_map.find(&scope_id).each |loans| { for loans.each |loan| { if !f(loan) { return; } } } - match region_map.find(scope_id) { + match region_map.find(&scope_id) { None => return, Some(next_scope_id) => scope_id = next_scope_id, } @@ -199,7 +199,7 @@ impl check_loan_ctxt { Some(expr) => { match expr.node { ast::expr_path(_) if pc == pc_pure_fn => { - let def = self.tcx().def_map.get(expr.id); + let def = self.tcx().def_map.get(&expr.id); let did = ast_util::def_id_of_def(def); let is_fn_arg = did.crate == ast::local_crate && @@ -247,7 +247,7 @@ impl check_loan_ctxt { fn is_allowed_pure_arg(expr: @ast::expr) -> bool { return match expr.node { ast::expr_path(_) => { - let def = self.tcx().def_map.get(expr.id); + let def = self.tcx().def_map.get(&expr.id); let did = ast_util::def_id_of_def(def); did.crate == ast::local_crate && (*self.fn_args).contains(&(did.node)) @@ -262,14 +262,14 @@ impl check_loan_ctxt { fn check_for_conflicting_loans(scope_id: ast::node_id) { debug!("check_for_conflicting_loans(scope_id=%?)", scope_id); - let new_loans = match self.req_maps.req_loan_map.find(scope_id) { + let new_loans = match self.req_maps.req_loan_map.find(&scope_id) { None => return, Some(loans) => loans }; debug!("new_loans has length %?", new_loans.len()); - let par_scope_id = self.tcx().region_map.get(scope_id); + let par_scope_id = self.tcx().region_map.get(&scope_id); for self.walk_loans(par_scope_id) |old_loan| { debug!("old_loan=%?", self.bccx.loan_to_repr(old_loan)); @@ -325,7 +325,7 @@ impl check_loan_ctxt { fn check_assignment(at: assignment_type, ex: @ast::expr) { // We don't use cat_expr() here because we don't want to treat // auto-ref'd parameters in overloaded operators as rvalues. - let cmt = match self.bccx.tcx.adjustments.find(ex.id) { + let cmt = match self.bccx.tcx.adjustments.find(&ex.id) { None => self.bccx.cat_expr_unadjusted(ex), Some(adj) => self.bccx.cat_expr_autoderefd(ex, adj) }; @@ -612,7 +612,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk, { match fty_proto { ast::ProtoBox | ast::ProtoUniq => { - let cap_vars = self.bccx.capture_map.get(id); + let cap_vars = self.bccx.capture_map.get(&id); for cap_vars.each |cap_var| { match cap_var.mode { moves::CapRef | moves::CapCopy => { loop; } diff --git a/src/librustc/middle/borrowck/gather_loans.rs b/src/librustc/middle/borrowck/gather_loans.rs index b7b99424924..8029b4c2713 100644 --- a/src/librustc/middle/borrowck/gather_loans.rs +++ b/src/librustc/middle/borrowck/gather_loans.rs @@ -126,7 +126,7 @@ fn req_loans_in_expr(ex: @ast::expr, // If this expression is borrowed, have to ensure it remains valid: if !self.ignore_adjustments.contains(&ex.id) { - for tcx.adjustments.find(ex.id).each |adjustments| { + for tcx.adjustments.find(&ex.id).each |adjustments| { self.guarantee_adjustments(ex, *adjustments); } } @@ -172,7 +172,7 @@ fn req_loans_in_expr(ex: @ast::expr, } } - match self.bccx.method_map.find(ex.id) { + match self.bccx.method_map.find(&ex.id) { Some(ref method_map_entry) => { match (*method_map_entry).explicit_self { ast::sty_by_ref => { @@ -250,7 +250,7 @@ fn req_loans_in_expr(ex: @ast::expr, // (if used like `a.b(...)`), the call where it's an argument // (if used like `x(a.b)`), or the block (if used like `let x // = a.b`). - let scope_r = ty::re_scope(self.tcx().region_map.get(ex.id)); + let scope_r = ty::re_scope(self.tcx().region_map.get(&ex.id)); let rcvr_cmt = self.bccx.cat_expr(rcvr); self.guarantee_valid(rcvr_cmt, m_imm, scope_r); visit::visit_expr(ex, self, vt); @@ -536,7 +536,7 @@ impl gather_loan_ctxt { fn add_loans_to_scope_id(&self, scope_id: ast::node_id, +loans: ~[Loan]) { debug!("adding %u loans to scope_id %?", loans.len(), scope_id); - match self.req_maps.req_loan_map.find(scope_id) { + match self.req_maps.req_loan_map.find(&scope_id) { Some(req_loans) => { req_loans.push_all(loans); } diff --git a/src/librustc/middle/borrowck/loan.rs b/src/librustc/middle/borrowck/loan.rs index 0b06fbd2a3a..7248d29aa04 100644 --- a/src/librustc/middle/borrowck/loan.rs +++ b/src/librustc/middle/borrowck/loan.rs @@ -129,7 +129,7 @@ impl LoanContext { ~"rvalue with a non-none lp"); } cat_local(local_id) | cat_arg(local_id) | cat_self(local_id) => { - let local_scope_id = self.tcx().region_map.get(local_id); + let local_scope_id = self.tcx().region_map.get(&local_id); self.issue_loan(cmt, ty::re_scope(local_scope_id), req_mutbl, owns_lent_data) } diff --git a/src/librustc/middle/borrowck/preserve.rs b/src/librustc/middle/borrowck/preserve.rs index 3bc34d2ef29..1946ba09ec7 100644 --- a/src/librustc/middle/borrowck/preserve.rs +++ b/src/librustc/middle/borrowck/preserve.rs @@ -109,7 +109,7 @@ impl PreserveCtxt { // Maybe if we pass in the parent instead here, // we can prevent the "scope not found" error debug!("scope_region thing: %? ", cmt.id); - ty::re_scope(self.tcx().region_map.get(cmt.id)) + ty::re_scope(self.tcx().region_map.get(&cmt.id)) }; self.compare_scope(cmt, scope_region) @@ -129,14 +129,14 @@ impl PreserveCtxt { cmt.span, ~"preserve() called with local and !root_managed_data"); } - let local_scope_id = self.tcx().region_map.get(local_id); + let local_scope_id = self.tcx().region_map.get(&local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } cat_binding(local_id) => { // Bindings are these kind of weird implicit pointers (cc // #2329). We require (in gather_loans) that they be // rooted in an immutable location. - let local_scope_id = self.tcx().region_map.get(local_id); + let local_scope_id = self.tcx().region_map.get(&local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } cat_arg(local_id) => { @@ -144,11 +144,11 @@ impl PreserveCtxt { // modes). In that case, the caller guarantees stability // for at least the scope of the fn. This is basically a // deref of a region ptr. - let local_scope_id = self.tcx().region_map.get(local_id); + let local_scope_id = self.tcx().region_map.get(&local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } cat_self(local_id) => { - let local_scope_id = self.tcx().region_map.get(local_id); + let local_scope_id = self.tcx().region_map.get(&local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } cat_comp(cmt_base, comp_field(*)) | diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 98c3fdaa8c3..69ace0d7797 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -126,7 +126,7 @@ pub fn check_expr(sess: Session, e.span, ~"paths in constants may only refer to \ items without type parameters"); } - match def_map.find(e.id) { + match def_map.find(&e.id) { Some(def_const(def_id)) | Some(def_fn(def_id, _)) | Some(def_variant(_, def_id)) | @@ -151,7 +151,7 @@ pub fn check_expr(sess: Session, } } expr_call(callee, _, false) => { - match def_map.find(callee.id) { + match def_map.find(&callee.id) { Some(def_struct(*)) => {} // OK. Some(def_variant(*)) => {} // OK. _ => { @@ -247,9 +247,9 @@ pub fn check_item_recursion(sess: Session, fn visit_expr(e: @expr, &&env: env, v: visit::vt) { match e.node { expr_path(*) => { - match env.def_map.find(e.id) { + match env.def_map.find(&e.id) { Some(def_const(def_id)) => { - match env.ast_map.get(def_id.node) { + match env.ast_map.get(&def_id.node) { ast_map::node_item(it, _) => { (v.visit_item)(it, env, v); } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index e25ceee5d30..978aaacb18a 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -292,7 +292,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option { match /*bad*/copy pat.node { pat_wild => { None } pat_ident(_, _, _) | pat_enum(_, _) => { - match cx.tcx.def_map.find(pat.id) { + match cx.tcx.def_map.find(&pat.id) { Some(def_variant(_, id)) => Some(variant(id)), Some(def_const(did)) => { let const_expr = lookup_const_by_id(cx.tcx, did).get(); @@ -306,7 +306,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option { Some(range(eval_const_expr(cx.tcx, lo), eval_const_expr(cx.tcx, hi))) } pat_struct(*) => { - match cx.tcx.def_map.find(pat.id) { + match cx.tcx.def_map.find(&pat.id) { Some(def_variant(_, id)) => Some(variant(id)), _ => Some(single) } @@ -329,7 +329,7 @@ pub fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool { match pat.node { pat_wild => { true } pat_ident(_, _, _) => { - match cx.tcx.def_map.find(pat.id) { + match cx.tcx.def_map.find(&pat.id) { Some(def_variant(_, _)) | Some(def_const(*)) => { false } _ => { true } } @@ -480,7 +480,7 @@ pub fn specialize(cx: @MatchCheckCtxt, pat_wild => Some(vec::append(vec::from_elem(arity, wild()), vec::tail(r))), pat_ident(_, _, _) => { - match cx.tcx.def_map.find(pat_id) { + match cx.tcx.def_map.find(&pat_id) { Some(def_variant(_, id)) => { if variant(id) == ctor_id { Some(vec::tail(r)) } else { None } @@ -505,7 +505,7 @@ pub fn specialize(cx: @MatchCheckCtxt, } } pat_enum(_, args) => { - match cx.tcx.def_map.get(pat_id) { + match cx.tcx.def_map.get(&pat_id) { def_variant(_, id) if variant(id) == ctor_id => { let args = match args { Some(args) => args, @@ -541,7 +541,7 @@ pub fn specialize(cx: @MatchCheckCtxt, } pat_struct(_, ref flds, _) => { // Is this a struct or an enum variant? - match cx.tcx.def_map.get(pat_id) { + match cx.tcx.def_map.get(&pat_id) { def_variant(_, variant_id) => { if variant(variant_id) == ctor_id { // FIXME #4731: Is this right? --pcw @@ -678,7 +678,7 @@ pub fn check_fn(cx: @MatchCheckCtxt, } pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool { - match cx.tcx.def_map.find(pat.id) { + match cx.tcx.def_map.find(&pat.id) { Some(def_variant(enum_id, _)) => { if vec::len(*ty::enum_variants(cx.tcx, enum_id)) != 1u { return true; diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index f917964d234..e01595d8d93 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -78,7 +78,7 @@ pub fn classify(e: @expr, tcx: ty::ctxt) -> constness { let did = ast_util::local_def(e.id); - match tcx.ccache.find(did) { + match tcx.ccache.find(&did) { Some(x) => x, None => { let cn = @@ -170,7 +170,7 @@ pub fn classify(e: @expr, } pub fn lookup_const(tcx: ty::ctxt, e: @expr) -> Option<@expr> { - match tcx.def_map.find(e.id) { + match tcx.def_map.find(&e.id) { Some(ast::def_const(def_id)) => lookup_const_by_id(tcx, def_id), _ => None } @@ -180,7 +180,7 @@ pub fn lookup_const_by_id(tcx: ty::ctxt, def_id: ast::def_id) -> Option<@expr> { if ast_util::is_local(def_id) { - match tcx.items.find(def_id.node) { + match tcx.items.find(&def_id.node) { None => None, Some(ast_map::node_item(it, _)) => match it.node { item_const(_, const_expr) => Some(const_expr), diff --git a/src/librustc/middle/freevars.rs b/src/librustc/middle/freevars.rs index 1e9d8c9c08e..5d65aba2a4d 100644 --- a/src/librustc/middle/freevars.rs +++ b/src/librustc/middle/freevars.rs @@ -58,7 +58,7 @@ fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk) } ast::expr_path(*) => { let mut i = 0; - match def_map.find(expr.id) { + match def_map.find(&expr.id) { None => die!(~"path not found"), Some(df) => { let mut def = df; @@ -118,7 +118,7 @@ pub fn annotate_freevars(def_map: resolve::DefMap, crate: @ast::crate) -> } pub fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info { - match tcx.freevars.find(fid) { + match tcx.freevars.find(&fid) { None => die!(~"get_freevars: " + int::str(fid) + ~" has no freevars"), Some(d) => return d } diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 09232a2a0c5..8abafe6b079 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -195,10 +195,10 @@ pub fn check_expr(e: @expr, cx: ctx, v: visit::vt) { expr_unary(*)|expr_binary(*)|expr_method_call(*) => e.callee_id, _ => e.id }; - do option::iter(&cx.tcx.node_type_substs.find(type_parameter_id)) |ts| { + do option::iter(&cx.tcx.node_type_substs.find(&type_parameter_id)) |ts| { let bounds = match e.node { expr_path(_) => { - let did = ast_util::def_id_of_def(cx.tcx.def_map.get(e.id)); + let did = ast_util::def_id_of_def(cx.tcx.def_map.get(&e.id)); ty::lookup_item_type(cx.tcx, did).bounds } _ => { @@ -292,8 +292,8 @@ pub fn check_expr(e: @expr, cx: ctx, v: visit::vt) { fn check_ty(aty: @Ty, cx: ctx, v: visit::vt) { match aty.node { ty_path(_, id) => { - do option::iter(&cx.tcx.node_type_substs.find(id)) |ts| { - let did = ast_util::def_id_of_def(cx.tcx.def_map.get(id)); + do option::iter(&cx.tcx.node_type_substs.find(&id)) |ts| { + let did = ast_util::def_id_of_def(cx.tcx.def_map.get(&id)); let bounds = ty::lookup_item_type(cx.tcx, did).bounds; for vec::each2(*ts, *bounds) |ty, bound| { check_bounds(cx, aty.id, aty.span, *ty, *bound) @@ -334,7 +334,7 @@ pub fn check_bounds(cx: ctx, id: node_id, sp: span, fn is_nullary_variant(cx: ctx, ex: @expr) -> bool { match ex.node { expr_path(_) => { - match cx.tcx.def_map.get(ex.id) { + match cx.tcx.def_map.get(&ex.id) { def_variant(edid, vdid) => { vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 3eb65505e64..b4500f87eb0 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -352,7 +352,7 @@ impl LanguageItemCollector { return; // Didn't match. } - match self.item_refs.find(/*bad*/copy value) { + match self.item_refs.find(&value) { None => { // Didn't match. } diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 0dc7a746e9e..4601941f73a 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -265,7 +265,7 @@ pub fn get_lint_settings_level(settings: lint_settings, _expr_id: ast::node_id, item_id: ast::node_id) -> level { - match settings.settings_map.find(item_id) { + match settings.settings_map.find(&item_id) { Some(modes) => get_lint_level(modes, lint_mode), None => get_lint_level(settings.default_settings, lint_mode) } @@ -346,7 +346,7 @@ impl ctxt { for triples.each |pair| { let (meta, level, lintname) = /*bad*/copy *pair; - match self.dict.find(/*bad*/ copy lintname) { + match self.dict.find(&lintname) { None => { self.span_lint( new_ctxt.get_level(unrecognized_lint), @@ -684,7 +684,7 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { for vec::each(vec::append_one(tys, decl.output)) |ty| { match ty.node { ast::ty_path(_, id) => { - match cx.def_map.get(id) { + match cx.def_map.get(&id) { ast::def_prim_ty(ast::ty_int(ast::ty_i)) => { cx.sess.span_lint( ctypes, id, fn_id, diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index d14d58122a7..a9103cb7e19 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -368,7 +368,7 @@ impl IrMaps { } fn variable(node_id: node_id, span: span) -> Variable { - match self.variable_map.find(node_id) { + match self.variable_map.find(&node_id) { Some(var) => var, None => { self.tcx.sess.span_bug( @@ -390,7 +390,7 @@ impl IrMaps { } fn captures(expr: @expr) -> @~[CaptureInfo] { - match self.capture_info_map.find(expr.id) { + match self.capture_info_map.find(&expr.id) { Some(caps) => caps, None => { self.tcx.sess.span_bug(expr.span, ~"no registered caps"); @@ -410,7 +410,7 @@ impl IrMaps { Local(LocalInfo {id: id, kind: FromLetNoInitializer, _}) | Local(LocalInfo {id: id, kind: FromLetWithInitializer, _}) | Local(LocalInfo {id: id, kind: FromMatch(_), _}) => { - let v = match self.last_use_map.find(expr_id) { + let v = match self.last_use_map.find(&expr_id) { Some(v) => v, None => { let v = @DVec(); @@ -552,7 +552,7 @@ fn visit_expr(expr: @expr, &&self: @IrMaps, vt: vt<@IrMaps>) { match expr.node { // live nodes required for uses or definitions of variables: expr_path(_) => { - let def = self.tcx.def_map.get(expr.id); + let def = self.tcx.def_map.get(&expr.id); debug!("expr %d: path that leads to %?", expr.id, def); if relevant_def(def).is_some() { self.add_live_node_for_node(expr.id, ExprNode(expr.span)); @@ -569,7 +569,7 @@ fn visit_expr(expr: @expr, &&self: @IrMaps, vt: vt<@IrMaps>) { // being the location that the variable is used. This results // in better error messages than just pointing at the closure // construction site. - let cvs = self.capture_map.get(expr.id); + let cvs = self.capture_map.get(&expr.id); let mut call_caps = ~[]; for cvs.each |cv| { match relevant_def(cv.def) { @@ -685,7 +685,7 @@ fn Liveness(ir: @IrMaps, specials: Specials) -> Liveness { impl Liveness { fn live_node(node_id: node_id, span: span) -> LiveNode { - match self.ir.live_node_map.find(node_id) { + match self.ir.live_node_map.find(&node_id) { Some(ln) => ln, None => { // This must be a mismatch between the ir_map construction @@ -702,7 +702,7 @@ impl Liveness { fn variable_from_path(expr: @expr) -> Option { match expr.node { expr_path(_) => { - let def = self.tcx.def_map.get(expr.id); + let def = self.tcx.def_map.get(&expr.id); relevant_def(def).map( |rdef| self.variable(*rdef, expr.span) ) @@ -717,7 +717,7 @@ impl Liveness { fn variable_from_def_map(node_id: node_id, span: span) -> Option { - match self.tcx.def_map.find(node_id) { + match self.tcx.def_map.find(&node_id) { Some(def) => { relevant_def(def).map( |rdef| self.variable(*rdef, span) @@ -837,7 +837,7 @@ impl Liveness { match opt_label { Some(_) => // Refers to a labeled loop. Use the results of resolve // to find with one - match self.tcx.def_map.find(id) { + match self.tcx.def_map.find(&id) { Some(def_label(loop_id)) => loop_id, _ => self.tcx.sess.span_bug(sp, ~"Label on break/loop \ doesn't refer to a loop") @@ -1203,7 +1203,7 @@ impl Liveness { // Now that we know the label we're going to, // look it up in the break loop nodes table - match self.break_ln.find(sc) { + match self.break_ln.find(&sc) { Some(b) => b, None => self.tcx.sess.span_bug(expr.span, ~"Break to unknown label") @@ -1217,7 +1217,7 @@ impl Liveness { // Now that we know the label we're going to, // look it up in the continue loop nodes table - match self.cont_ln.find(sc) { + match self.cont_ln.find(&sc) { Some(b) => b, None => self.tcx.sess.span_bug(expr.span, ~"Loop to unknown label") @@ -1424,7 +1424,7 @@ impl Liveness { } fn access_path(expr: @expr, succ: LiveNode, acc: uint) -> LiveNode { - let def = self.tcx.def_map.get(expr.id); + let def = self.tcx.def_map.get(&expr.id); match relevant_def(def) { Some(nid) => { let ln = self.live_node(expr.id, expr.span); @@ -1560,7 +1560,7 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) { let ln = self.live_node(expr.id, expr.span); self.consider_last_use(expr, ln, *var); - match self.ir.variable_moves_map.find(expr.id) { + match self.ir.variable_moves_map.find(&expr.id) { None => {} Some(entire_expr) => { debug!("(checking expr) is a move: `%s`", @@ -1689,7 +1689,7 @@ impl @Liveness { fn check_lvalue(expr: @expr, vt: vt<@Liveness>) { match expr.node { expr_path(_) => { - match self.tcx.def_map.get(expr.id) { + match self.tcx.def_map.get(&expr.id) { def_local(nid, false) => { // Assignment to an immutable variable or argument: // only legal if there is no later assignment. diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 94fc63b75dd..abe8a64fea5 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -308,7 +308,7 @@ pub struct mem_categorization_ctxt { pub impl &mem_categorization_ctxt { fn cat_expr(expr: @ast::expr) -> cmt { - match self.tcx.adjustments.find(expr.id) { + match self.tcx.adjustments.find(&expr.id) { None => { // No adjustments. self.cat_expr_unadjusted(expr) @@ -375,7 +375,7 @@ pub impl &mem_categorization_ctxt { } ast::expr_path(_) => { - let def = self.tcx.def_map.get(expr.id); + let def = self.tcx.def_map.get(&expr.id); self.cat_def(expr.id, expr.span, expr_ty, def) } @@ -840,7 +840,7 @@ pub impl &mem_categorization_ctxt { // variant(*) } ast::pat_enum(_, Some(ref subpats)) => { - match self.tcx.def_map.find(pat.id) { + match self.tcx.def_map.find(&pat.id) { Some(ast::def_variant(enum_did, _)) => { // variant(x, y, z) for subpats.each |subpat| { @@ -1063,7 +1063,7 @@ pub fn field_mutbl(tcx: ty::ctxt, } } ty::ty_enum(*) => { - match tcx.def_map.get(node_id) { + match tcx.def_map.get(&node_id) { ast::def_variant(_, variant_id) => { for ty::lookup_struct_fields(tcx, variant_id).each |fld| { if fld.ident == f_name { diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index 8adebdb4582..f7943d6edc0 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -409,7 +409,7 @@ impl VisitContext { // `expr_mode` refers to the post-adjustment value. If one of // those adjustments is to take a reference, then it's only // reading the underlying expression, not moving it. - let comp_mode = match self.tcx.adjustments.find(expr.id) { + let comp_mode = match self.tcx.adjustments.find(&expr.id) { Some(adj) if adj.autoref.is_some() => Read, _ => expr_mode.component_mode(expr) }; @@ -713,7 +713,7 @@ impl VisitContext { receiver_expr: @expr, visitor: vt) { - let callee_mode = match self.method_map.find(expr_id) { + let callee_mode = match self.method_map.find(&expr_id) { Some(ref method_map_entry) => { match method_map_entry.explicit_self { sty_by_ref => by_ref, diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index c39d750a581..823af16c605 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -35,7 +35,7 @@ pub fn pat_id_map(dm: resolve::DefMap, pat: @pat) -> PatIdMap { pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool { match pat.node { pat_enum(_, _) | pat_ident(_, _, None) | pat_struct(*) => { - match dm.find(pat.id) { + match dm.find(&pat.id) { Some(def_variant(*)) | Some(def_struct(*)) => true, _ => false } @@ -47,7 +47,7 @@ pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool { pub fn pat_is_const(dm: resolve::DefMap, pat: &pat) -> bool { match pat.node { pat_ident(_, _, None) => { - match dm.find(pat.id) { + match dm.find(&pat.id) { Some(def_const(*)) => true, _ => false } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 482f01f7201..3ec1cf3a705 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -105,7 +105,7 @@ pub fn check_crate(tcx: ty::ctxt, match *origin { method_static(method_id) => { if method_id.crate == local_crate { - match tcx.items.find(method_id.node) { + match tcx.items.find(&method_id.node) { Some(node_method(method, impl_id, _)) => { if method.vis == private && (impl_id.crate != local_crate || @@ -143,7 +143,7 @@ pub fn check_crate(tcx: ty::ctxt, method_self(trait_id, method_num) | method_super(trait_id, method_num) => { if trait_id.crate == local_crate { - match tcx.items.find(trait_id.node) { + match tcx.items.find(&trait_id.node) { Some(node_item(item, _)) => { match item.node { item_trait(_, _, ref methods) => { @@ -221,7 +221,7 @@ pub fn check_crate(tcx: ty::ctxt, ty_struct(id, _) if id.crate != local_crate || !privileged_items.contains(&(id.node)) => { - match method_map.find(expr.id) { + match method_map.find(&expr.id) { None => { debug!("(privacy checking) checking \ field access"); @@ -244,7 +244,7 @@ pub fn check_crate(tcx: ty::ctxt, ty_struct(id, _) if id.crate != local_crate || !privileged_items.contains(&(id.node)) => { - match method_map.find(expr.id) { + match method_map.find(&expr.id) { None => { tcx.sess.span_bug(expr.span, ~"method call not in \ @@ -276,7 +276,7 @@ pub fn check_crate(tcx: ty::ctxt, ty_enum(id, _) => { if id.crate != local_crate || !privileged_items.contains(&(id.node)) { - match tcx.def_map.get(expr.id) { + match tcx.def_map.get(&expr.id) { def_variant(_, variant_id) => { for (*fields).each |field| { debug!("(privacy checking) \ @@ -343,7 +343,7 @@ pub fn check_crate(tcx: ty::ctxt, if enum_id.crate != local_crate || !privileged_items.contains( &enum_id.node) { - match tcx.def_map.find(pattern.id) { + match tcx.def_map.find(&pattern.id) { Some(def_variant(_, variant_id)) => { for fields.each |field| { debug!("(privacy checking) \ diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 4602d2aff4e..867cc7c686f 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -115,7 +115,7 @@ pub fn scope_contains(region_map: region_map, superscope: ast::node_id, subscope: ast::node_id) -> bool { let mut subscope = subscope; while superscope != subscope { - match region_map.find(subscope) { + match region_map.find(&subscope) { None => return false, Some(scope) => subscope = scope } @@ -159,7 +159,7 @@ pub fn nearest_common_ancestor(region_map: region_map, let mut result = ~[scope]; let mut scope = scope; loop { - match region_map.find(scope) { + match region_map.find(&scope) { None => return result, Some(superscope) => { result.push(superscope); @@ -237,7 +237,7 @@ pub fn resolve_arm(arm: ast::arm, cx: ctxt, visitor: visit::vt) { pub fn resolve_pat(pat: @ast::pat, cx: ctxt, visitor: visit::vt) { match pat.node { ast::pat_ident(*) => { - let defn_opt = cx.def_map.find(pat.id); + let defn_opt = cx.def_map.find(&pat.id); match defn_opt { Some(ast::def_variant(_,_)) => { /* Nothing to do; this names a variant. */ @@ -475,7 +475,7 @@ pub impl determine_rp_ctxt { /// the new variance is joined with the old variance. fn add_rp(id: ast::node_id, variance: region_variance) { assert id != 0; - let old_variance = self.region_paramd_items.find(id); + let old_variance = self.region_paramd_items.find(&id); let joined_variance = match old_variance { None => variance, Some(v) => join_variance(v, variance) @@ -505,7 +505,7 @@ pub impl determine_rp_ctxt { ast_map::node_id_to_str(self.ast_map, self.item_id, self.sess.parse_sess.interner), copy self.ambient_variance); - let vec = match self.dep_map.find(from) { + let vec = match self.dep_map.find(&from) { Some(vec) => vec, None => { let vec = @DVec(); @@ -685,7 +685,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty, // that as a direct dependency. match ty.node { ast::ty_path(path, id) => { - match cx.def_map.find(id) { + match cx.def_map.find(&id) { Some(ast::def_ty(did)) | Some(ast::def_struct(did)) => { if did.crate == ast::local_crate { if cx.opt_region_is_relevant(path.rp) { @@ -818,9 +818,9 @@ pub fn determine_rp_in_crate(sess: Session, // update the region-parameterization of D to reflect the result. while cx.worklist.len() != 0 { let c_id = cx.worklist.pop(); - let c_variance = cx.region_paramd_items.get(c_id); + let c_variance = cx.region_paramd_items.get(&c_id); debug!("popped %d from worklist", c_id); - match cx.dep_map.find(c_id) { + match cx.dep_map.find(&c_id) { None => {} Some(deps) => { for deps.each |dep| { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index c40b6df6926..c647e4db262 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -947,7 +947,7 @@ pub impl Resolver { // Add or reuse the child. let new_parent = ModuleReducedGraphParent(module_); - match module_.children.find(name) { + match module_.children.find(&name) { None => { let child = @NameBindings(); module_.children.insert(name, child); @@ -1558,7 +1558,7 @@ pub impl Resolver { %s", final_ident); let parent_link = self.get_parent_link(new_parent, ident); - match modules.find(def_id) { + match modules.find(&def_id) { None => { child_name_bindings.define_module(Public, parent_link, @@ -1582,7 +1582,8 @@ pub impl Resolver { die!(~"can't happen"); } ModuleParentLink(parent_module, ident) => { - let name_bindings = parent_module.children.get(ident); + let name_bindings = parent_module.children.get( + &ident); resolution.type_target = Some(Target(parent_module, name_bindings)); } @@ -1841,7 +1842,7 @@ pub impl Resolver { self.idents_to_str(module_path.get()), self.session.str_of(target)); - match module_.import_resolutions.find(target) { + match module_.import_resolutions.find(&target) { Some(resolution) => { debug!("(building import directive) bumping \ reference"); @@ -2112,7 +2113,7 @@ pub impl Resolver { let mut type_result = UnknownResult; // Search for direct children of the containing module. - match containing_module.children.find(source) { + match containing_module.children.find(&source) { None => { // Continue. } @@ -2148,7 +2149,7 @@ pub impl Resolver { // Now search the exported imports within the containing // module. - match containing_module.import_resolutions.find(source) { + match containing_module.import_resolutions.find(&source) { None => { // The containing module definitely doesn't have an // exported import with the name in question. We can @@ -2212,7 +2213,7 @@ pub impl Resolver { // We've successfully resolved the import. Write the results in. assert module_.import_resolutions.contains_key_ref(&target); - let import_resolution = module_.import_resolutions.get(target); + let import_resolution = module_.import_resolutions.get(&target); match value_result { BoundResult(target_module, name_bindings) => { @@ -2297,7 +2298,7 @@ pub impl Resolver { let mut module_result = UnknownResult; // Search for direct children of the containing module. - match containing_module.children.find(source) { + match containing_module.children.find(&source) { None => { // Continue. } @@ -2327,7 +2328,7 @@ pub impl Resolver { // Now search the exported imports within the containing // module. - match containing_module.import_resolutions.find(source) { + match containing_module.import_resolutions.find(&source) { None => { // The containing module definitely doesn't have an // exported import with the name in question. We can @@ -2371,7 +2372,7 @@ pub impl Resolver { // We've successfully resolved the import. Write the results in. assert module_.import_resolutions.contains_key_ref(&target); - let import_resolution = module_.import_resolutions.get(target); + let import_resolution = module_.import_resolutions.get(&target); match module_result { BoundResult(target_module, name_bindings) => { @@ -2439,7 +2440,7 @@ pub impl Resolver { self.module_to_str(module_)); // Here we merge two import resolutions. - match module_.import_resolutions.find(ident) { + match module_.import_resolutions.find(&ident) { None => { // Simple: just copy the old import resolution. let new_import_resolution = @@ -2482,7 +2483,7 @@ pub impl Resolver { // Add all children from the containing module. for containing_module.children.each_ref |&ident, &name_bindings| { let mut dest_import_resolution; - match module_.import_resolutions.find(ident) { + match module_.import_resolutions.find(&ident) { None => { // Create a new import resolution from this child. dest_import_resolution = @ImportResolution(privacy, span); @@ -2686,7 +2687,7 @@ pub impl Resolver { // The current module node is handled specially. First, check for // its immediate children. - match module_.children.find(name) { + match module_.children.find(&name) { Some(name_bindings) if (*name_bindings).defined_in_namespace(namespace) => { return Success(Target(module_, name_bindings)); @@ -2699,7 +2700,7 @@ pub impl Resolver { // adjacent import statements are processed as though they mutated the // current scope. - match module_.import_resolutions.find(name) { + match module_.import_resolutions.find(&name) { None => { // Not found; continue. } @@ -2923,7 +2924,7 @@ pub impl Resolver { self.module_to_str(module_)); // First, check the direct children of the module. - match module_.children.find(name) { + match module_.children.find(&name) { Some(name_bindings) if (*name_bindings).defined_in_namespace(namespace) => { @@ -2944,7 +2945,7 @@ pub impl Resolver { } // Otherwise, we check the list of resolved imports. - match module_.import_resolutions.find(name) { + match module_.import_resolutions.find(&name) { Some(import_resolution) => { if import_resolution.outstanding_references != 0 { debug!("(resolving name in module) import unresolved; \ @@ -3114,7 +3115,7 @@ pub impl Resolver { } // Otherwise, proceed and write in the bindings. - match module_.import_resolutions.find(target_name) { + match module_.import_resolutions.find(&target_name) { None => { die!(~"(resolving one-level renaming import) reduced graph \ construction or glob importing should have created the \ @@ -3328,7 +3329,7 @@ pub impl Resolver { // Nothing to do. } Some(name) => { - match orig_module.children.find(name) { + match orig_module.children.find(&name) { None => { debug!("!!! (with scope) didn't find `%s` in `%s`", self.session.str_of(name), @@ -3405,7 +3406,7 @@ pub impl Resolver { // If the def is a ty param, and came from the parent // item, it's ok match def { - def_ty_param(did, _) if self.def_map.find(copy(did.node)) + def_ty_param(did, _) if self.def_map.find(&did.node) == Some(def_typaram_binder(item_id)) => { // ok } @@ -3477,7 +3478,7 @@ pub impl Resolver { while i != 0 { i -= 1; let rib = (*ribs).get_elt(i); - match rib.bindings.find(name) { + match rib.bindings.find(&name) { Some(def_like) => { return self.upvarify(ribs, i, def_like, span, allow_capturing_self); @@ -4069,7 +4070,7 @@ pub impl Resolver { let map_i = self.binding_mode_map(*p); for map_0.each_ref |&key, &binding_0| { - match map_i.find(key) { + match map_i.find(&key) { None => { self.session.span_err( p.span, @@ -4126,7 +4127,7 @@ pub impl Resolver { // Move down in the graph, if there's an anonymous module rooted here. let orig_module = self.current_module; - match self.current_module.anonymous_children.find(block.node.id) { + match self.current_module.anonymous_children.find(&block.node.id) { None => { /* Nothing to do. */ } Some(anonymous_module) => { debug!("(resolving block) found anonymous module, moving \ @@ -4161,7 +4162,7 @@ pub impl Resolver { match self.primitive_type_table .primitive_types - .find(name) { + .find(&name) { Some(primitive_type) => { result_def = @@ -4327,7 +4328,7 @@ pub impl Resolver { bindings_list.insert(ident, pat_id); } Some(b) => { - if b.find(ident) == Some(pat_id) { + if b.find(&ident) == Some(pat_id) { // Then this is a duplicate variable // in the same disjunct, which is an // error @@ -4526,7 +4527,7 @@ pub impl Resolver { -> NameDefinition { // First, search children. - match containing_module.children.find(name) { + match containing_module.children.find(&name) { Some(child_name_bindings) => { match (child_name_bindings.def_for_namespace(namespace), child_name_bindings.privacy_for_namespace(namespace)) { @@ -4549,7 +4550,7 @@ pub impl Resolver { } // Next, search import resolutions. - match containing_module.import_resolutions.find(name) { + match containing_module.import_resolutions.find(&name) { Some(import_resolution) if import_resolution.privacy == Public || xray == Xray => { match (*import_resolution).target_for_namespace(namespace) { @@ -5076,7 +5077,7 @@ pub impl Resolver { trait_def_id.node, self.session.str_of(name)); - match self.trait_info.find(trait_def_id) { + match self.trait_info.find(&trait_def_id) { Some(trait_info) if trait_info.contains_key_ref(&name) => { debug!("(adding trait info if containing method) found trait \ %d:%d for method '%s'", diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 6913cf8e2f5..7dca4174019 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -282,7 +282,7 @@ pub fn trans_opt(bcx: block, o: &Opt) -> opt_result { } pub fn variant_opt(tcx: ty::ctxt, pat_id: ast::node_id) -> Opt { - match tcx.def_map.get(pat_id) { + match tcx.def_map.get(&pat_id) { ast::def_variant(enum_id, var_id) => { let variants = ty::enum_variants(tcx, enum_id); for vec::each(*variants) |v| { @@ -377,7 +377,7 @@ pub fn expand_nested_bindings(bcx: block, m: &[@Match/&r], vec::view(br.pats, col + 1u, br.pats.len()))); let binding_info = - br.data.bindings_map.get(path_to_ident(path)); + br.data.bindings_map.get(&path_to_ident(path)); Store(bcx, val, binding_info.llmatch); @Match {pats: pats, data: br.data} @@ -424,7 +424,8 @@ pub fn enter_match(bcx: block, dm: DefMap, m: &[@Match/&r], ast::pat_ident(_, path, None) => { if pat_is_binding(dm, self) { let binding_info = - br.data.bindings_map.get(path_to_ident(path)); + br.data.bindings_map.get( + &path_to_ident(path)); Store(bcx, val, binding_info.llmatch); } } @@ -518,7 +519,7 @@ pub fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint, } } ast::pat_ident(_, _, None) if pat_is_const(tcx.def_map, p) => { - let const_def = tcx.def_map.get(p.id); + let const_def = tcx.def_map.get(&p.id); let const_def_id = ast_util::def_id_of_def(const_def); if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) { Some(~[]) @@ -536,7 +537,7 @@ pub fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint, if opt_eq(tcx, &variant_opt(tcx, p.id), opt) { // Look up the struct variant ID. let struct_id; - match tcx.def_map.get(p.id) { + match tcx.def_map.get(&p.id) { ast::def_variant(_, found_struct_id) => { struct_id = found_struct_id; } @@ -774,7 +775,7 @@ pub fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[Opt] { ast::pat_ident(*) => { // This is one of: an enum variant, a unit-like struct, or a // variable binding. - match ccx.tcx.def_map.find(cur.id) { + match ccx.tcx.def_map.find(&cur.id) { Some(ast::def_variant(*)) => { add_to_set(ccx.tcx, &found, variant_opt(ccx.tcx, cur.id)); @@ -793,7 +794,7 @@ pub fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[Opt] { ast::pat_enum(*) | ast::pat_struct(*) => { // This could be one of: a tuple-like enum variant, a // struct-like enum variant, or a struct. - match ccx.tcx.def_map.find(cur.id) { + match ccx.tcx.def_map.find(&cur.id) { Some(ast::def_variant(*)) => { add_to_set(ccx.tcx, &found, variant_opt(ccx.tcx, cur.id)); @@ -926,7 +927,7 @@ pub fn root_pats_as_necessary(bcx: block, let pat_id = br.pats[col].id; let key = root_map_key {id: pat_id, derefs: 0u }; - match bcx.ccx().maps.root_map.find(key) { + match bcx.ccx().maps.root_map.find(&key) { None => (), Some(root_info) => { // Note: the scope_id will always be the id of the match. See @@ -981,7 +982,7 @@ pub fn any_tuple_struct_pat(bcx: block, m: &[@Match], col: uint) -> bool { let pat = br.pats[col]; match pat.node { ast::pat_enum(_, Some(_)) => { - match bcx.tcx().def_map.find(pat.id) { + match bcx.tcx().def_map.find(&pat.id) { Some(ast::def_struct(*)) => true, _ => false } @@ -1717,9 +1718,9 @@ pub fn bind_irrefutable_pat(bcx: block, } } ast::pat_enum(_, sub_pats) => { - match bcx.tcx().def_map.find(pat.id) { + match bcx.tcx().def_map.find(&pat.id) { Some(ast::def_variant(*)) => { - let pat_def = ccx.tcx.def_map.get(pat.id); + let pat_def = ccx.tcx.def_map.get(&pat.id); let vdefs = ast_util::variant_def_ids(pat_def); let args = extract_variant_args(bcx, pat.id, vdefs, val); for sub_pats.each |sub_pat| { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index a858ecb520a..a2b1de692be 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -169,7 +169,7 @@ pub fn get_extern_fn(externs: HashMap<~str, ValueRef>, +name: ~str, cc: lib::llvm::CallConv, ty: TypeRef) -> ValueRef { - if externs.contains_key_ref(&name) { return externs.get(name); } + if externs.contains_key_ref(&name) { return externs.get(&name); } // XXX: Bad copy. let f = decl_fn(llmod, copy name, cc, ty); externs.insert(name, f); @@ -179,7 +179,7 @@ pub fn get_extern_fn(externs: HashMap<~str, ValueRef>, pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef, +name: ~str, ty: TypeRef) -> ValueRef { unsafe { - if externs.contains_key_ref(&name) { return externs.get(name); } + if externs.contains_key_ref(&name) { return externs.get(&name); } let c = str::as_c_str(name, |buf| { llvm::LLVMAddGlobal(llmod, ty, buf) }); @@ -372,7 +372,7 @@ pub fn get_tydesc_simple(ccx: @crate_ctxt, t: ty::t) -> ValueRef { } pub fn get_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info { - match ccx.tydescs.find(t) { + match ccx.tydescs.find(&t) { Some(inf) => inf, _ => { ccx.stats.n_static_tydescs += 1u; @@ -807,7 +807,7 @@ pub fn get_discrim_val(cx: @crate_ctxt, span: span, enum_did: ast::def_id, pub fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef { unsafe { let _icx = ccx.insn_ctxt("lookup_discriminant"); - match ccx.discrims.find(vid) { + match ccx.discrims.find(&vid) { None => { // It's an external discriminant that we haven't seen yet. assert (vid.crate != ast::local_crate); @@ -1095,7 +1095,7 @@ pub fn init_local(bcx: block, local: @ast::local) -> block { } } - let llptr = match bcx.fcx.lllocals.find(local.node.id) { + let llptr = match bcx.fcx.lllocals.find(&local.node.id) { Some(local_mem(v)) => v, _ => { bcx.tcx().sess.span_bug(local.span, ~"init_local: Someone forgot to document why it's\ @@ -1437,7 +1437,7 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef, session::arch_x86 | session::arch_arm => ~"llvm.memcpy.p0i8.p0i8.i32", session::arch_x86_64 => ~"llvm.memcpy.p0i8.p0i8.i64" }; - let memcpy = ccx.intrinsics.get(key); + let memcpy = ccx.intrinsics.get(&key); let src_ptr = PointerCast(cx, src, T_ptr(T_i8())); let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8())); let size = IntCast(cx, n_bytes, ccx.int_type); @@ -1484,7 +1484,7 @@ pub fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) { } } - let llintrinsicfn = ccx.intrinsics.get(intrinsic_key); + let llintrinsicfn = ccx.intrinsics.get(&intrinsic_key); let llptr = PointerCast(cx, llptr, T_ptr(T_i8())); let llzeroval = C_u8(0); let size = IntCast(cx, machine::llsize_of(ccx, llty), ccx.int_type); @@ -1884,7 +1884,7 @@ pub fn trans_enum_variant(ccx: @crate_ctxt, // If this argument to this function is a enum, it'll have come in to // this function as an opaque blob due to the way that type_of() // works. So we have to cast to the destination's view of the type. - let llarg = match fcx.llargs.find(va.id) { + let llarg = match fcx.llargs.find(&va.id) { Some(local_mem(x)) => x, _ => die!(~"trans_enum_variant: how do we know this works?"), }; @@ -1930,7 +1930,7 @@ pub fn trans_tuple_struct(ccx: @crate_ctxt, for fields.eachi |i, field| { let lldestptr = GEPi(bcx, fcx.llretptr, [0, 0, i]); - let llarg = match fcx.llargs.get(field.node.id) { + let llarg = match fcx.llargs.get(&field.node.id) { local_mem(x) => x, _ => { ccx.tcx.sess.bug(~"trans_tuple_struct: llarg wasn't \ @@ -2019,7 +2019,7 @@ pub fn trans_enum_def(ccx: @crate_ctxt, enum_definition: ast::enum_def, pub fn trans_item(ccx: @crate_ctxt, item: ast::item) { let _icx = ccx.insn_ctxt("trans_item"); - let path = match ccx.tcx.items.get(item.id) { + let path = match ccx.tcx.items.get(&item.id) { ast_map::node_item(_, p) => p, // tjc: ? _ => die!(~"trans_item"), @@ -2275,7 +2275,7 @@ pub fn fill_fn_pair(bcx: block, pair: ValueRef, llfn: ValueRef, pub fn item_path(ccx: @crate_ctxt, i: @ast::item) -> path { vec::append( - /*bad*/copy *match ccx.tcx.items.get(i.id) { + /*bad*/copy *match ccx.tcx.items.get(&i.id) { ast_map::node_item(_, p) => p, // separate map for paths? _ => die!(~"item_path") @@ -2291,7 +2291,7 @@ pub fn get_dtor_symbol(ccx: @crate_ctxt, +substs: Option) -> ~str { let t = ty::node_id_to_type(ccx.tcx, id); - match ccx.item_symbols.find(id) { + match ccx.item_symbols.find(&id) { Some(ref s) => (/*bad*/copy *s), None if substs.is_none() => { let s = mangle_exported_name( @@ -2326,12 +2326,12 @@ pub fn get_dtor_symbol(ccx: @crate_ctxt, pub fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef { debug!("get_item_val(id=`%?`)", id); let tcx = ccx.tcx; - match ccx.item_vals.find(id) { + match ccx.item_vals.find(&id) { Some(v) => v, None => { let mut exprt = false; - let val = match ccx.tcx.items.get(id) { + let val = match ccx.tcx.items.get(&id) { ast_map::node_item(i, pth) => { let my_path = vec::append(/*bad*/copy *pth, ~[path_name(i.ident)]); @@ -2770,7 +2770,7 @@ pub fn declare_dbg_intrinsics(llmod: ModuleRef, pub fn trap(bcx: block) { let v: ~[ValueRef] = ~[]; - match bcx.ccx().intrinsics.find(~"llvm.trap") { + match bcx.ccx().intrinsics.find(&~"llvm.trap") { Some(x) => { Call(bcx, x, v); }, _ => bcx.sess().bug(~"unbound llvm.trap in trap") } diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index 79236433580..24e9d967fac 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -70,7 +70,7 @@ pub fn count_insn(cx: block, category: &str) { i = 0u; while i < len { let e = /*bad*/copy v[i]; - i = mm.get(/*bad*/ copy e); + i = mm.get(&e); s += ~"/"; s += e; i += 1u; @@ -79,7 +79,7 @@ pub fn count_insn(cx: block, category: &str) { s += ~"/"; s += category; - let n = match h.find(/*bad*/ copy s) { + let n = match h.find(&s) { Some(n) => n, _ => 0u }; diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 833cff80d2d..8cfe8ba8f91 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -70,7 +70,7 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee { return trans_def(bcx, bcx.def(expr.id), expr); } ast::expr_field(base, _, _) => { - match bcx.ccx().maps.method_map.find(expr.id) { + match bcx.ccx().maps.method_map.find(&expr.id) { Some(ref origin) => { // An impl method return meth::trans_method_callee(bcx, expr.id, base, (*origin)); @@ -208,7 +208,7 @@ pub fn trans_fn_ref_with_vtables( // Modify the def_id if this is a default method; we want to be // monomorphizing the trait's code. let (def_id, opt_impl_did) = - match tcx.provided_method_sources.find(def_id) { + match tcx.provided_method_sources.find(&def_id) { None => (def_id, None), Some(source) => (source.method_id, Some(source.impl_id)) }; @@ -234,7 +234,7 @@ pub fn trans_fn_ref_with_vtables( } else if def_id.crate == ast::local_crate { let map_node = session::expect( ccx.sess, - ccx.tcx.items.find(def_id.node), + ccx.tcx.items.find(&def_id.node), || fmt!("local item should be in ast map")); match map_node { @@ -313,7 +313,7 @@ pub fn trans_method_call(in_cx: block, node_id_type(in_cx, call_ex.callee_id), expr_ty(in_cx, call_ex), |cx| { - match cx.ccx().maps.method_map.find(call_ex.id) { + match cx.ccx().maps.method_map.find(&call_ex.id) { Some(ref origin) => { meth::trans_method_callee(cx, call_ex.callee_id, diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index 9a115acbd8d..7d19c1dfaaf 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -419,7 +419,7 @@ pub fn trans_expr_fn(bcx: block, let Result {bcx: bcx, val: closure} = match proto { ast::ProtoBorrowed | ast::ProtoBox | ast::ProtoUniq => { - let cap_vars = ccx.maps.capture_map.get(user_id); + let cap_vars = ccx.maps.capture_map.get(&user_id); let ret_handle = match is_loop_body {Some(x) => x, None => None}; let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, proto, diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index f21a3150a1c..f43e0ef763c 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -700,7 +700,7 @@ pub impl block { } fn def(nid: ast::node_id) -> ast::def { - match self.tcx().def_map.find(nid) { + match self.tcx().def_map.find(&nid) { Some(v) => v, None => { self.tcx().sess.bug(fmt!( @@ -1134,7 +1134,7 @@ pub fn C_u8(i: uint) -> ValueRef { // our boxed-and-length-annotated strings. pub fn C_cstr(cx: @crate_ctxt, +s: ~str) -> ValueRef { unsafe { - match cx.const_cstr_cache.find(/*bad*/copy s) { + match cx.const_cstr_cache.find(&s) { Some(llval) => return llval, None => () } @@ -1356,7 +1356,7 @@ pub fn node_id_type_params(bcx: block, id: ast::node_id) -> ~[ty::t] { pub fn node_vtables(bcx: block, id: ast::node_id) -> Option { - let raw_vtables = bcx.ccx().maps.vtable_map.find(id); + let raw_vtables = bcx.ccx().maps.vtable_map.find(&id); raw_vtables.map( |vts| resolve_vtables_in_fn_ctxt(bcx.fcx, *vts)) } diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index b5652fed10e..12340101d9e 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -82,7 +82,7 @@ pub fn const_vec(cx: @crate_ctxt, e: @ast::expr, es: &[@ast::expr]) pub fn const_deref(cx: @crate_ctxt, v: ValueRef) -> ValueRef { unsafe { - let v = match cx.const_globals.find(v as int) { + let v = match cx.const_globals.find(&(v as int)) { Some(v) => v, None => v }; @@ -127,7 +127,7 @@ pub fn get_const_val(cx: @crate_ctxt, def_id: ast::def_id) -> ValueRef { cx.tcx.sess.bug(~"cross-crate constants"); } if !cx.const_values.contains_key_ref(&def_id.node) { - match cx.tcx.items.get(def_id.node) { + match cx.tcx.items.get(&def_id.node) { ast_map::node_item(@ast::item { node: ast::item_const(_, subexpr), _ }, _) => { @@ -136,7 +136,7 @@ pub fn get_const_val(cx: @crate_ctxt, def_id: ast::def_id) -> ValueRef { _ => cx.tcx.sess.bug(~"expected a const to be an item") } } - cx.const_values.get(def_id.node) + cx.const_values.get(&def_id.node) } pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { @@ -402,7 +402,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { } ast::expr_path(pth) => { assert pth.types.len() == 0; - match cx.tcx.def_map.find(e.id) { + match cx.tcx.def_map.find(&e.id) { Some(ast::def_fn(def_id, purity)) => { assert ast_util::is_local(def_id); let f = base::get_item_val(cx, def_id.node); @@ -437,7 +437,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { } } ast::expr_call(callee, args, _) => { - match cx.tcx.def_map.find(callee.id) { + match cx.tcx.def_map.find(&callee.id) { Some(ast::def_struct(def_id)) => { let ety = ty::expr_ty(cx.tcx, e); let llty = type_of::type_of(cx, ety); @@ -482,7 +482,7 @@ pub fn trans_const(ccx: @crate_ctxt, _e: @ast::expr, id: ast::node_id) { let g = base::get_item_val(ccx, id); // At this point, get_item_val has already translated the // constant's initializer to determine its LLVM type. - let v = ccx.const_values.get(id); + let v = ccx.const_values.get(&id); llvm::LLVMSetInitializer(g, v); llvm::LLVMSetGlobalConstant(g, True); } diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index 240c323965f..8944fceb011 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -184,7 +184,7 @@ pub fn trans_log(log_ex: @ast::expr, let modname = path_str(ccx.sess, copy modpath); let global = if ccx.module_data.contains_key_ref(&modname) { - ccx.module_data.get(modname) + ccx.module_data.get(&modname) } else { let s = link::mangle_internal_name_by_path_and_seq( ccx, modpath, ~"loglevel"); diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index c3bd34ececb..529073ca555 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -627,7 +627,7 @@ pub impl Datum { // // (Note: root'd values are always boxes) let key = root_map_key { id: expr_id, derefs: derefs }; - let bcx = match ccx.maps.root_map.find(key) { + let bcx = match ccx.maps.root_map.find(&key) { None => bcx, Some(root_info) => self.root(bcx, root_info) }; @@ -635,7 +635,7 @@ pub impl Datum { // Perform the write guard, if necessary. // // (Note: write-guarded values are always boxes) - let bcx = match ccx.maps.write_guard_map.find(key) { + let bcx = match ccx.maps.write_guard_map.find(&key) { None => bcx, Some(_) => self.perform_write_guard(bcx) }; diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 35abddfb85a..ecb63c19811 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -118,7 +118,7 @@ pub fn mk_ctxt(+crate: ~str, intr: @ident_interner) -> debug_ctxt { fn update_cache(cache: metadata_cache, mdtag: int, val: debug_metadata) { let existing = if cache.contains_key_ref(&mdtag) { - cache.get(mdtag) + cache.get(&mdtag) } else { ~[] }; @@ -177,7 +177,7 @@ fn cached_metadata(cache: metadata_cache, -> Option { unsafe { if cache.contains_key_ref(&mdtag) { - let items = cache.get(mdtag); + let items = cache.get(&mdtag); for items.each |item| { let md: T = md_from_metadata::(*item); if eq_fn(md) { @@ -289,7 +289,7 @@ fn create_block(cx: block) -> @metadata { Some(bcx) => create_block(bcx).node }; let file_node = create_file(cx.ccx(), fname); - let unique_id = match cache.find(LexicalBlockTag) { + let unique_id = match cache.find(&LexicalBlockTag) { option::Some(v) => vec::len(v) as int, option::None => 0 }; @@ -679,14 +679,14 @@ pub fn create_local_var(bcx: block, local: @ast::local) let mdval = @{node: mdnode, data: {id: local.node.id}}; update_cache(cache, AutoVariableTag, local_var_metadata(mdval)); - let llptr = match bcx.fcx.lllocals.find(local.node.id) { + let llptr = match bcx.fcx.lllocals.find(&local.node.id) { option::Some(local_mem(v)) => v, option::Some(_) => { bcx.tcx().sess.span_bug(local.span, ~"local is bound to \ something weird"); } option::None => { - match bcx.fcx.lllocals.get(local.node.pat.id) { + match bcx.fcx.lllocals.get(&local.node.pat.id) { local_imm(v) => v, _ => bcx.tcx().sess.span_bug(local.span, ~"local is bound to \ something weird") @@ -694,7 +694,7 @@ pub fn create_local_var(bcx: block, local: @ast::local) } }; let declargs = ~[llmdnode(~[llptr]), mdnode]; - trans::build::Call(bcx, cx.intrinsics.get(~"llvm.dbg.declare"), + trans::build::Call(bcx, cx.intrinsics.get(&~"llvm.dbg.declare"), declargs); return mdval; } @@ -731,12 +731,12 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span) let mdval = @{node: mdnode, data: {id: arg.id}}; update_cache(cache, tg, argument_metadata(mdval)); - let llptr = match fcx.llargs.get(arg.id) { + let llptr = match fcx.llargs.get(&arg.id) { local_mem(v) | local_imm(v) => v, }; let declargs = ~[llmdnode(~[llptr]), mdnode]; trans::build::Call(bcx, - cx.intrinsics.get(~"llvm.dbg.declare"), + cx.intrinsics.get(&~"llvm.dbg.declare"), declargs); return Some(mdval); } @@ -774,7 +774,7 @@ pub fn create_function(fcx: fn_ctxt) -> @metadata { let sp = fcx.span.get(); log(debug, cx.sess.codemap.span_to_str(sp)); - let (ident, ret_ty, id) = match cx.tcx.items.get(fcx.id) { + let (ident, ret_ty, id) = match cx.tcx.items.get(&fcx.id) { ast_map::node_item(item, _) => { match /*bad*/copy item.node { ast::item_fn(decl, _, _, _) => { diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 4cf449cd972..e19bafdb598 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -185,7 +185,7 @@ fn drop_and_cancel_clean(bcx: block, dat: Datum) -> block { pub fn trans_to_datum(bcx: block, expr: @ast::expr) -> DatumBlock { debug!("trans_to_datum(expr=%s)", bcx.expr_to_str(expr)); - return match bcx.tcx().adjustments.find(expr.id) { + return match bcx.tcx().adjustments.find(&expr.id) { None => { trans_to_datum_unadjusted(bcx, expr) } @@ -329,7 +329,7 @@ fn trans_lvalue(bcx: block, expr: @ast::expr) -> DatumBlock { * instead, but sometimes we call trans_lvalue() directly as a * means of asserting that a particular expression is an lvalue. */ - return match bcx.tcx().adjustments.find(expr.id) { + return match bcx.tcx().adjustments.find(&expr.id) { None => trans_lvalue_unadjusted(bcx, expr), Some(_) => { bcx.sess().span_bug( @@ -742,7 +742,7 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock { // the lvalue in there, and then arrange for it to be cleaned up // at the end of the scope with id `scope_id`: let root_key = root_map_key { id: expr.id, derefs: 0u }; - for bcx.ccx().maps.root_map.find(root_key).each |&root_info| { + for bcx.ccx().maps.root_map.find(&root_key).each |&root_info| { bcx = unrooted_datum.root(bcx, root_info); } @@ -934,7 +934,7 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum { ast::def_upvar(nid, _, _, _) => { // Can't move upvars, so this is never a ZeroMemLastUse. let local_ty = node_id_type(bcx, nid); - match bcx.fcx.llupvars.find(nid) { + match bcx.fcx.llupvars.find(&nid) { Some(val) => { Datum { val: val, @@ -987,7 +987,7 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum { fn take_local(bcx: block, table: HashMap, nid: ast::node_id) -> Datum { - let (v, mode) = match table.find(nid) { + let (v, mode) = match table.find(&nid) { Some(local_mem(v)) => (v, ByRef), Some(local_imm(v)) => (v, ByValue), None => { @@ -1066,7 +1066,7 @@ pub fn with_field_tys(tcx: ty::ctxt, ty_to_str(tcx, ty))); } Some(node_id) => { - match tcx.def_map.get(node_id) { + match tcx.def_map.get(&node_id) { ast::def_variant(_, variant_id) => { op(false, struct_mutable_fields( tcx, variant_id, substs)) @@ -1120,7 +1120,7 @@ fn trans_rec_or_struct(bcx: block, let tcx = bcx.tcx(); let addr = match ty::get(ty).sty { ty::ty_enum(_, ref substs) => { - match tcx.def_map.get(id) { + match tcx.def_map.get(&id) { ast::def_variant(enum_id, variant_id) => { let variant_info = ty::enum_variant_with_id( tcx, enum_id, variant_id); @@ -1479,7 +1479,7 @@ fn trans_overloaded_op(bcx: block, dest: Dest, +autoref_arg: AutorefArg) -> block { - let origin = bcx.ccx().maps.method_map.get(expr.id); + let origin = bcx.ccx().maps.method_map.get(&expr.id); let fty = node_id_type(bcx, expr.callee_id); return callee::trans_call_inner( bcx, expr.info(), fty, @@ -1636,7 +1636,7 @@ fn trans_assign_op(bcx: block, let dst_datum = unpack_datum!(bcx, trans_lvalue_unadjusted(bcx, dst)); // A user-defined operator method - if bcx.ccx().maps.method_map.find(expr.id).is_some() { + if bcx.ccx().maps.method_map.find(&expr.id).is_some() { // FIXME(#2528) evaluates the receiver twice!! let scratch = scratch_datum(bcx, dst_datum.ty, false); let bcx = trans_overloaded_op(bcx, expr, dst, ~[src], diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 3d441dc973a..73868627bcb 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -498,7 +498,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, let tp_sz = machine::llbitsize_of_real(ccx, lltp_ty), out_sz = machine::llbitsize_of_real(ccx, llout_ty); if tp_sz != out_sz { - let sp = match ccx.tcx.items.get(ref_id.get()) { + let sp = match ccx.tcx.items.get(&ref_id.get()) { ast_map::node_expr(e) => e.span, _ => die!(~"reinterpret_cast or forget has non-expr arg") }; @@ -535,7 +535,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, abi::tydesc_field_visit_glue, None); } ~"frame_address" => { - let frameaddress = ccx.intrinsics.get(~"llvm.frameaddress"); + let frameaddress = ccx.intrinsics.get(&~"llvm.frameaddress"); let frameaddress_val = Call(bcx, frameaddress, ~[C_i32(0i32)]); let star_u8 = ty::mk_imm_ptr( bcx.tcx(), @@ -576,7 +576,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, let align = C_i32(1); let volatile = C_bool(false); let llfn = bcx.ccx().intrinsics.get( - ~"llvm.memmove.p0i8.p0i8.i32"); + &~"llvm.memmove.p0i8.p0i8.i32"); Call(bcx, llfn, ~[dst_ptr, src_ptr, size, align, volatile]); } ~"memmove64" => { @@ -586,248 +586,248 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, let align = C_i32(1); let volatile = C_bool(false); let llfn = bcx.ccx().intrinsics.get( - ~"llvm.memmove.p0i8.p0i8.i64"); + &~"llvm.memmove.p0i8.p0i8.i64"); Call(bcx, llfn, ~[dst_ptr, src_ptr, size, align, volatile]); } ~"sqrtf32" => { let x = get_param(decl, first_real_arg); - let sqrtf = ccx.intrinsics.get(~"llvm.sqrt.f32"); + let sqrtf = ccx.intrinsics.get(&~"llvm.sqrt.f32"); Store(bcx, Call(bcx, sqrtf, ~[x]), fcx.llretptr); } ~"sqrtf64" => { let x = get_param(decl, first_real_arg); - let sqrtf = ccx.intrinsics.get(~"llvm.sqrt.f64"); + let sqrtf = ccx.intrinsics.get(&~"llvm.sqrt.f64"); Store(bcx, Call(bcx, sqrtf, ~[x]), fcx.llretptr); } ~"powif32" => { let a = get_param(decl, first_real_arg); let x = get_param(decl, first_real_arg + 1u); - let powif = ccx.intrinsics.get(~"llvm.powi.f32"); + let powif = ccx.intrinsics.get(&~"llvm.powi.f32"); Store(bcx, Call(bcx, powif, ~[a, x]), fcx.llretptr); } ~"powif64" => { let a = get_param(decl, first_real_arg); let x = get_param(decl, first_real_arg + 1u); - let powif = ccx.intrinsics.get(~"llvm.powi.f64"); + let powif = ccx.intrinsics.get(&~"llvm.powi.f64"); Store(bcx, Call(bcx, powif, ~[a, x]), fcx.llretptr); } ~"sinf32" => { let x = get_param(decl, first_real_arg); - let sinf = ccx.intrinsics.get(~"llvm.sin.f32"); + let sinf = ccx.intrinsics.get(&~"llvm.sin.f32"); Store(bcx, Call(bcx, sinf, ~[x]), fcx.llretptr); } ~"sinf64" => { let x = get_param(decl, first_real_arg); - let sinf = ccx.intrinsics.get(~"llvm.sin.f64"); + let sinf = ccx.intrinsics.get(&~"llvm.sin.f64"); Store(bcx, Call(bcx, sinf, ~[x]), fcx.llretptr); } ~"cosf32" => { let x = get_param(decl, first_real_arg); - let cosf = ccx.intrinsics.get(~"llvm.cos.f32"); + let cosf = ccx.intrinsics.get(&~"llvm.cos.f32"); Store(bcx, Call(bcx, cosf, ~[x]), fcx.llretptr); } ~"cosf64" => { let x = get_param(decl, first_real_arg); - let cosf = ccx.intrinsics.get(~"llvm.cos.f64"); + let cosf = ccx.intrinsics.get(&~"llvm.cos.f64"); Store(bcx, Call(bcx, cosf, ~[x]), fcx.llretptr); } ~"powf32" => { let a = get_param(decl, first_real_arg); let x = get_param(decl, first_real_arg + 1u); - let powf = ccx.intrinsics.get(~"llvm.pow.f32"); + let powf = ccx.intrinsics.get(&~"llvm.pow.f32"); Store(bcx, Call(bcx, powf, ~[a, x]), fcx.llretptr); } ~"powf64" => { let a = get_param(decl, first_real_arg); let x = get_param(decl, first_real_arg + 1u); - let powf = ccx.intrinsics.get(~"llvm.pow.f64"); + let powf = ccx.intrinsics.get(&~"llvm.pow.f64"); Store(bcx, Call(bcx, powf, ~[a, x]), fcx.llretptr); } ~"expf32" => { let x = get_param(decl, first_real_arg); - let expf = ccx.intrinsics.get(~"llvm.exp.f32"); + let expf = ccx.intrinsics.get(&~"llvm.exp.f32"); Store(bcx, Call(bcx, expf, ~[x]), fcx.llretptr); } ~"expf64" => { let x = get_param(decl, first_real_arg); - let expf = ccx.intrinsics.get(~"llvm.exp.f64"); + let expf = ccx.intrinsics.get(&~"llvm.exp.f64"); Store(bcx, Call(bcx, expf, ~[x]), fcx.llretptr); } ~"exp2f32" => { let x = get_param(decl, first_real_arg); - let exp2f = ccx.intrinsics.get(~"llvm.exp2.f32"); + let exp2f = ccx.intrinsics.get(&~"llvm.exp2.f32"); Store(bcx, Call(bcx, exp2f, ~[x]), fcx.llretptr); } ~"exp2f64" => { let x = get_param(decl, first_real_arg); - let exp2f = ccx.intrinsics.get(~"llvm.exp2.f64"); + let exp2f = ccx.intrinsics.get(&~"llvm.exp2.f64"); Store(bcx, Call(bcx, exp2f, ~[x]), fcx.llretptr); } ~"logf32" => { let x = get_param(decl, first_real_arg); - let logf = ccx.intrinsics.get(~"llvm.log.f32"); + let logf = ccx.intrinsics.get(&~"llvm.log.f32"); Store(bcx, Call(bcx, logf, ~[x]), fcx.llretptr); } ~"logf64" => { let x = get_param(decl, first_real_arg); - let logf = ccx.intrinsics.get(~"llvm.log.f64"); + let logf = ccx.intrinsics.get(&~"llvm.log.f64"); Store(bcx, Call(bcx, logf, ~[x]), fcx.llretptr); } ~"log10f32" => { let x = get_param(decl, first_real_arg); - let log10f = ccx.intrinsics.get(~"llvm.log10.f32"); + let log10f = ccx.intrinsics.get(&~"llvm.log10.f32"); Store(bcx, Call(bcx, log10f, ~[x]), fcx.llretptr); } ~"log10f64" => { let x = get_param(decl, first_real_arg); - let log10f = ccx.intrinsics.get(~"llvm.log10.f64"); + let log10f = ccx.intrinsics.get(&~"llvm.log10.f64"); Store(bcx, Call(bcx, log10f, ~[x]), fcx.llretptr); } ~"log2f32" => { let x = get_param(decl, first_real_arg); - let log2f = ccx.intrinsics.get(~"llvm.log2.f32"); + let log2f = ccx.intrinsics.get(&~"llvm.log2.f32"); Store(bcx, Call(bcx, log2f, ~[x]), fcx.llretptr); } ~"log2f64" => { let x = get_param(decl, first_real_arg); - let log2f = ccx.intrinsics.get(~"llvm.log2.f64"); + let log2f = ccx.intrinsics.get(&~"llvm.log2.f64"); Store(bcx, Call(bcx, log2f, ~[x]), fcx.llretptr); } ~"fmaf32" => { let a = get_param(decl, first_real_arg); let b = get_param(decl, first_real_arg + 1u); let c = get_param(decl, first_real_arg + 2u); - let fmaf = ccx.intrinsics.get(~"llvm.fma.f32"); + let fmaf = ccx.intrinsics.get(&~"llvm.fma.f32"); Store(bcx, Call(bcx, fmaf, ~[a, b, c]), fcx.llretptr); } ~"fmaf64" => { let a = get_param(decl, first_real_arg); let b = get_param(decl, first_real_arg + 1u); let c = get_param(decl, first_real_arg + 2u); - let fmaf = ccx.intrinsics.get(~"llvm.fma.f64"); + let fmaf = ccx.intrinsics.get(&~"llvm.fma.f64"); Store(bcx, Call(bcx, fmaf, ~[a, b, c]), fcx.llretptr); } ~"fabsf32" => { let x = get_param(decl, first_real_arg); - let fabsf = ccx.intrinsics.get(~"llvm.fabs.f32"); + let fabsf = ccx.intrinsics.get(&~"llvm.fabs.f32"); Store(bcx, Call(bcx, fabsf, ~[x]), fcx.llretptr); } ~"fabsf64" => { let x = get_param(decl, first_real_arg); - let fabsf = ccx.intrinsics.get(~"llvm.fabs.f64"); + let fabsf = ccx.intrinsics.get(&~"llvm.fabs.f64"); Store(bcx, Call(bcx, fabsf, ~[x]), fcx.llretptr); } ~"floorf32" => { let x = get_param(decl, first_real_arg); - let floorf = ccx.intrinsics.get(~"llvm.floor.f32"); + let floorf = ccx.intrinsics.get(&~"llvm.floor.f32"); Store(bcx, Call(bcx, floorf, ~[x]), fcx.llretptr); } ~"floorf64" => { let x = get_param(decl, first_real_arg); - let floorf = ccx.intrinsics.get(~"llvm.floor.f64"); + let floorf = ccx.intrinsics.get(&~"llvm.floor.f64"); Store(bcx, Call(bcx, floorf, ~[x]), fcx.llretptr); } ~"ceilf32" => { let x = get_param(decl, first_real_arg); - let ceilf = ccx.intrinsics.get(~"llvm.ceil.f32"); + let ceilf = ccx.intrinsics.get(&~"llvm.ceil.f32"); Store(bcx, Call(bcx, ceilf, ~[x]), fcx.llretptr); } ~"ceilf64" => { let x = get_param(decl, first_real_arg); - let ceilf = ccx.intrinsics.get(~"llvm.ceil.f64"); + let ceilf = ccx.intrinsics.get(&~"llvm.ceil.f64"); Store(bcx, Call(bcx, ceilf, ~[x]), fcx.llretptr); } ~"truncf32" => { let x = get_param(decl, first_real_arg); - let truncf = ccx.intrinsics.get(~"llvm.trunc.f32"); + let truncf = ccx.intrinsics.get(&~"llvm.trunc.f32"); Store(bcx, Call(bcx, truncf, ~[x]), fcx.llretptr); } ~"truncf64" => { let x = get_param(decl, first_real_arg); - let truncf = ccx.intrinsics.get(~"llvm.trunc.f64"); + let truncf = ccx.intrinsics.get(&~"llvm.trunc.f64"); Store(bcx, Call(bcx, truncf, ~[x]), fcx.llretptr); } ~"ctpop8" => { let x = get_param(decl, first_real_arg); - let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i8"); + let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i8"); Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) } ~"ctpop16" => { let x = get_param(decl, first_real_arg); - let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i16"); + let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i16"); Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) } ~"ctpop32" => { let x = get_param(decl, first_real_arg); - let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i32"); + let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i32"); Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) } ~"ctpop64" => { let x = get_param(decl, first_real_arg); - let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i64"); + let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i64"); Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) } ~"ctlz8" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i8"); + let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i8"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"ctlz16" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i16"); + let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i16"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"ctlz32" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i32"); + let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i32"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"ctlz64" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i64"); + let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i64"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"cttz8" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let cttz = ccx.intrinsics.get(~"llvm.cttz.i8"); + let cttz = ccx.intrinsics.get(&~"llvm.cttz.i8"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"cttz16" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let cttz = ccx.intrinsics.get(~"llvm.cttz.i16"); + let cttz = ccx.intrinsics.get(&~"llvm.cttz.i16"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"cttz32" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let cttz = ccx.intrinsics.get(~"llvm.cttz.i32"); + let cttz = ccx.intrinsics.get(&~"llvm.cttz.i32"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"cttz64" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let cttz = ccx.intrinsics.get(~"llvm.cttz.i64"); + let cttz = ccx.intrinsics.get(&~"llvm.cttz.i64"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"bswap16" => { let x = get_param(decl, first_real_arg); - let cttz = ccx.intrinsics.get(~"llvm.bswap.i16"); + let cttz = ccx.intrinsics.get(&~"llvm.bswap.i16"); Store(bcx, Call(bcx, cttz, ~[x]), fcx.llretptr) } ~"bswap32" => { let x = get_param(decl, first_real_arg); - let cttz = ccx.intrinsics.get(~"llvm.bswap.i32"); + let cttz = ccx.intrinsics.get(&~"llvm.bswap.i32"); Store(bcx, Call(bcx, cttz, ~[x]), fcx.llretptr) } ~"bswap64" => { let x = get_param(decl, first_real_arg); - let cttz = ccx.intrinsics.get(~"llvm.bswap.i64"); + let cttz = ccx.intrinsics.get(&~"llvm.bswap.i64"); Store(bcx, Call(bcx, cttz, ~[x]), fcx.llretptr) } _ => { @@ -955,7 +955,7 @@ pub fn register_foreign_fn(ccx: @crate_ctxt, fn abi_of_foreign_fn(ccx: @crate_ctxt, i: @ast::foreign_item) -> ast::foreign_abi { match attr::first_attr_value_str_by_name(i.attrs, ~"abi") { - None => match ccx.tcx.items.get(i.id) { + None => match ccx.tcx.items.get(&i.id) { ast_map::node_foreign_item(_, abi, _) => abi, // ?? _ => die!(~"abi_of_foreign_fn: not foreign") diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 849a718a52e..9909980fb7e 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -381,7 +381,7 @@ pub fn make_visit_glue(bcx: block, v: ValueRef, t: ty::t) { let mut bcx = bcx; let ty_visitor_name = special_idents::ty_visitor; assert bcx.ccx().tcx.intrinsic_defs.contains_key_ref(&ty_visitor_name); - let (trait_id, ty) = bcx.ccx().tcx.intrinsic_defs.get(ty_visitor_name); + let (trait_id, ty) = bcx.ccx().tcx.intrinsic_defs.get(&ty_visitor_name); let v = PointerCast(bcx, v, T_ptr(type_of::type_of(bcx.ccx(), ty))); bcx = reflect::emit_calls_to_trait_visit_ty(bcx, t, v, trait_id); build_return(bcx); diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index f5d23236334..4466e4e1b28 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -31,7 +31,7 @@ pub fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id, translate: bool) -> ast::def_id { let _icx = ccx.insn_ctxt("maybe_instantiate_inline"); - match ccx.external.find(fn_id) { + match ccx.external.find(&fn_id) { Some(Some(node_id)) => { // Already inline debug!("maybe_instantiate_inline(%s): already inline as node id %d", diff --git a/src/librustc/middle/trans/machine.rs b/src/librustc/middle/trans/machine.rs index 1b3e13cddab..e76176218b7 100644 --- a/src/librustc/middle/trans/machine.rs +++ b/src/librustc/middle/trans/machine.rs @@ -178,7 +178,7 @@ pub fn llalign_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef { // Computes the size of the data part of an enum. pub fn static_size_of_enum(cx: @crate_ctxt, t: ty::t) -> uint { - if cx.enum_sizes.contains_key_ref(&t) { return cx.enum_sizes.get(t); } + if cx.enum_sizes.contains_key_ref(&t) { return cx.enum_sizes.get(&t); } match ty::get(t).sty { ty::ty_enum(tid, ref substs) => { // Compute max(variant sizes). diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index f488c32437c..d751b8f9208 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -308,7 +308,7 @@ pub fn trans_static_method_callee(bcx: block, }; let mname = if method_id.crate == ast::local_crate { - match bcx.tcx().items.get(method_id.node) { + match bcx.tcx().items.get(&method_id.node) { ast_map::node_trait_method(trait_method, _, _) => { ast_util::trait_method_to_ty_method(*trait_method).ident } @@ -325,7 +325,7 @@ pub fn trans_static_method_callee(bcx: block, name=%s", method_id, callee_id, ccx.sess.str_of(mname)); let vtbls = resolve_vtables_in_fn_ctxt( - bcx.fcx, ccx.maps.vtable_map.get(callee_id)); + bcx.fcx, ccx.maps.vtable_map.get(&callee_id)); match /*bad*/copy vtbls[bound_index] { typeck::vtable_static(impl_did, rcvr_substs, rcvr_origins) => { @@ -362,7 +362,7 @@ pub fn method_from_methods(ms: ~[@ast::method], name: ast::ident) pub fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id, name: ast::ident) -> ast::def_id { if impl_id.crate == ast::local_crate { - match ccx.tcx.items.get(impl_id.node) { + match ccx.tcx.items.get(&impl_id.node) { ast_map::node_item(@ast::item { node: ast::item_impl(_, _, _, ref ms), _ @@ -379,7 +379,7 @@ pub fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id, pub fn method_with_name_or_default(ccx: @crate_ctxt, impl_id: ast::def_id, name: ast::ident) -> ast::def_id { if impl_id.crate == ast::local_crate { - match ccx.tcx.items.get(impl_id.node) { + match ccx.tcx.items.get(&impl_id.node) { ast_map::node_item(@ast::item { node: ast::item_impl(_, _, _, ref ms), _ }, _) => { @@ -389,7 +389,7 @@ pub fn method_with_name_or_default(ccx: @crate_ctxt, impl_id: ast::def_id, } else { // Look for a default method let pmm = ccx.tcx.provided_methods; - match pmm.find(impl_id) { + match pmm.find(&impl_id) { Some(pmis) => { for pmis.each |pmi| { if pmi.method_info.ident == name { @@ -414,10 +414,10 @@ pub fn method_ty_param_count(ccx: @crate_ctxt, m_id: ast::def_id, i_id: ast::def_id) -> uint { debug!("method_ty_param_count: m_id: %?, i_id: %?", m_id, i_id); if m_id.crate == ast::local_crate { - match ccx.tcx.items.find(m_id.node) { + match ccx.tcx.items.find(&m_id.node) { Some(ast_map::node_method(m, _, _)) => m.tps.len(), None => { - match ccx.tcx.provided_method_sources.find(m_id) { + match ccx.tcx.provided_method_sources.find(&m_id) { Some(source) => { method_ty_param_count( ccx, source.method_id, source.impl_id) @@ -779,7 +779,7 @@ pub fn get_vtable(ccx: @crate_ctxt, -> ValueRef { // XXX: Bad copy. let hash_id = vtable_id(ccx, copy origin); - match ccx.vtables.find(hash_id) { + match ccx.vtables.find(&hash_id) { Some(val) => val, None => match origin { typeck::vtable_static(id, substs, sub_vtables) => { @@ -916,7 +916,7 @@ pub fn trans_trait_cast(bcx: block, } // Store the vtable into the pair or triple. - let orig = /*bad*/copy ccx.maps.vtable_map.get(id)[0]; + let orig = /*bad*/copy ccx.maps.vtable_map.get(&id)[0]; let orig = resolve_vtable_in_fn_ctxt(bcx.fcx, orig); let vtable = get_vtable(bcx.ccx(), orig); Store(bcx, vtable, PointerCast(bcx, diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 60b4057d448..5873d0a76d9 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -69,7 +69,7 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, real_substs.map(|s| ty_to_str(ccx.tcx, *s)), substs.map(|s| ty_to_str(ccx.tcx, *s)), hash_id); - match ccx.monomorphized.find(hash_id) { + match ccx.monomorphized.find(&hash_id) { Some(val) => { debug!("leaving monomorphic fn %s", ty::item_path_str(ccx.tcx, fn_id)); @@ -81,7 +81,7 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, let tpt = ty::lookup_item_type(ccx.tcx, fn_id); let mut llitem_ty = tpt.ty; - let map_node = session::expect(ccx.sess, ccx.tcx.items.find(fn_id.node), + let map_node = session::expect(ccx.sess, ccx.tcx.items.find(&fn_id.node), || fmt!("While monomorphizing %?, couldn't find it in the item map \ (may have attempted to monomorphize an item defined in a different \ crate?)", fn_id)); @@ -136,7 +136,7 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, ccx.stats.n_monos += 1; - let depth = option::get_or_default(ccx.monomorphizing.find(fn_id), 0u); + let depth = option::get_or_default(ccx.monomorphizing.find(&fn_id), 0u); // Random cut-off -- code that needs to instantiate the same function // recursively more than ten times can probably safely be assumed to be // causing an infinite expansion. diff --git a/src/librustc/middle/trans/reachable.rs b/src/librustc/middle/trans/reachable.rs index 02e07e8484a..112b9ac4d07 100644 --- a/src/librustc/middle/trans/reachable.rs +++ b/src/librustc/middle/trans/reachable.rs @@ -54,7 +54,7 @@ pub fn find_reachable(crate_mod: _mod, exp_map2: resolve::ExportMap2, fn traverse_exports(cx: ctx, mod_id: node_id) -> bool { let mut found_export = false; - match cx.exp_map2.find(mod_id) { + match cx.exp_map2.find(&mod_id) { Some(ref exp2s) => { for (*exp2s).each |e2| { found_export = true; @@ -68,7 +68,7 @@ fn traverse_exports(cx: ctx, mod_id: node_id) -> bool { fn traverse_def_id(cx: ctx, did: def_id) { if did.crate != local_crate { return; } - let n = match cx.tcx.items.find(did.node) { + let n = match cx.tcx.items.find(&did.node) { None => return, // This can happen for self, for example Some(ref n) => (/*bad*/copy *n) }; @@ -150,7 +150,7 @@ fn traverse_ty(ty: @Ty, cx: ctx, v: visit::vt) { match ty.node { ty_path(p, p_id) => { - match cx.tcx.def_map.find(p_id) { + match cx.tcx.def_map.find(&p_id) { // Kind of a hack to check this here, but I'm not sure what else // to do Some(def_prim_ty(_)) => { /* do nothing */ } @@ -169,7 +169,7 @@ fn traverse_inline_body(cx: ctx, body: blk) { fn traverse_expr(e: @expr, cx: ctx, v: visit::vt) { match e.node { expr_path(_) => { - match cx.tcx.def_map.find(e.id) { + match cx.tcx.def_map.find(&e.id) { Some(d) => { traverse_def_id(cx, def_id_of_def(d)); } @@ -179,7 +179,7 @@ fn traverse_inline_body(cx: ctx, body: blk) { } } expr_field(_, _, _) => { - match cx.method_map.find(e.id) { + match cx.method_map.find(&e.id) { Some(typeck::method_map_entry { origin: typeck::method_static(did), _ @@ -190,7 +190,7 @@ fn traverse_inline_body(cx: ctx, body: blk) { } } expr_method_call(*) => { - match cx.method_map.find(e.id) { + match cx.method_map.find(&e.id) { Some(typeck::method_map_entry { origin: typeck::method_static(did), _ diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index b9a055ad8ab..59ba55920fd 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -317,7 +317,7 @@ pub fn emit_calls_to_trait_visit_ty(bcx: block, use syntax::parse::token::special_idents::tydesc; let final = sub_block(bcx, ~"final"); assert bcx.ccx().tcx.intrinsic_defs.contains_key_ref(&tydesc); - let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get(tydesc); + let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get(&tydesc); let tydesc_ty = type_of::type_of(bcx.ccx(), tydesc_ty); let r = reflector({ visitor_val: visitor_val, diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 72efab0c371..99c47997df0 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -87,7 +87,7 @@ pub fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef { debug!("type_of %?: %?", t, ty::get(t)); // Check the cache. - if cx.lltypes.contains_key_ref(&t) { return cx.lltypes.get(t); } + if cx.lltypes.contains_key_ref(&t) { return cx.lltypes.get(&t); } // Replace any typedef'd types with their equivalent non-typedef // type. This ensures that all LLVM nominal types that contain diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index 350b1393c33..6b0d4e17c74 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -53,7 +53,7 @@ pub type ctx = {ccx: @crate_ctxt, uses: ~[mut type_uses]}; pub fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint) -> ~[type_uses] { - match ccx.type_use_cache.find(fn_id) { + match ccx.type_use_cache.find(&fn_id) { Some(uses) => return uses, None => () } @@ -87,7 +87,7 @@ pub fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint) ccx.type_use_cache.insert(fn_id, copy uses); return uses; } - let map_node = match ccx.tcx.items.find(fn_id_loc.node) { + let map_node = match ccx.tcx.items.find(&fn_id_loc.node) { Some(ref x) => (/*bad*/copy *x), None => ccx.sess.bug(fmt!("type_uses_for: unbound item ID %?", fn_id_loc)) @@ -226,10 +226,10 @@ pub fn node_type_needs(cx: ctx, use_: uint, id: node_id) { } pub fn mark_for_method_call(cx: ctx, e_id: node_id, callee_id: node_id) { - do option::iter(&cx.ccx.maps.method_map.find(e_id)) |mth| { + do option::iter(&cx.ccx.maps.method_map.find(&e_id)) |mth| { match mth.origin { typeck::method_static(did) => { - do cx.ccx.tcx.node_type_substs.find(callee_id).iter |ts| { + do cx.ccx.tcx.node_type_substs.find(&callee_id).iter |ts| { let type_uses = type_uses_for(cx.ccx, did, ts.len()); for vec::each2(type_uses, *ts) |uses, subst| { type_needs(cx, *uses, *subst) @@ -278,8 +278,8 @@ pub fn mark_for_expr(cx: ctx, e: @expr) { } } expr_path(_) => { - do cx.ccx.tcx.node_type_substs.find(e.id).iter |ts| { - let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(e.id)); + do cx.ccx.tcx.node_type_substs.find(&e.id).iter |ts| { + let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(&e.id)); let uses_for_ts = type_uses_for(cx.ccx, id, ts.len()); for vec::each2(uses_for_ts, *ts) |uses, subst| { type_needs(cx, *uses, *subst) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 4a0448c0b24..c7028c4d044 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -876,7 +876,7 @@ fn mk_t(cx: ctxt, +st: sty) -> t { mk_t_with_id(cx, st, None) } // and returns the box as cast to an unsafe ptr (see comments for t above). fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option) -> t { let key = intern_key { sty: to_unsafe_ptr(&st), o_def_id: o_def_id }; - match cx.interner.find(key) { + match cx.interner.find(&key) { Some(t) => unsafe { return cast::reinterpret_cast(&t); }, _ => () } @@ -1142,7 +1142,7 @@ pub fn default_arg_mode_for_ty(tcx: ctxt, ty: ty::t) -> ast::rmode { // Returns the narrowest lifetime enclosing the evaluation of the expression // with id `id`. pub fn encl_region(cx: ctxt, id: ast::node_id) -> ty::Region { - match cx.region_map.find(id) { + match cx.region_map.find(&id) { Some(encl_scope) => ty::re_scope(encl_scope), None => ty::re_static } @@ -1653,7 +1653,7 @@ pub fn type_is_immediate(ty: t) -> bool { } pub fn type_needs_drop(cx: ctxt, ty: t) -> bool { - match cx.needs_drop_cache.find(ty) { + match cx.needs_drop_cache.find(&ty) { Some(result) => return result, None => {/* fall through */ } } @@ -1732,7 +1732,7 @@ pub fn type_needs_drop(cx: ctxt, ty: t) -> bool { // that only contain scalars and shared boxes can avoid unwind // cleanups. pub fn type_needs_unwind_cleanup(cx: ctxt, ty: t) -> bool { - match cx.needs_unwind_cleanup_cache.find(ty) { + match cx.needs_unwind_cleanup_cache.find(&ty) { Some(result) => return result, None => () } @@ -1749,7 +1749,7 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t, encountered_box: bool) -> bool { // Prevent infinite recursion - match tycache.find(ty) { + match tycache.find(&ty) { Some(_) => return false, None => { tycache.insert(ty, ()); } } @@ -2011,7 +2011,7 @@ pub fn type_kind(cx: ctxt, ty: t) -> Kind { // If `allow_ty_var` is true, then this is a conservative assumption; we // assume that type variables *do* have all kinds. pub fn type_kind_ext(cx: ctxt, ty: t, allow_ty_var: bool) -> Kind { - match cx.kind_cache.find(ty) { + match cx.kind_cache.find(&ty) { Some(result) => return result, None => {/* fall through */ } } @@ -2165,7 +2165,7 @@ pub fn type_kind_ext(cx: ctxt, ty: t, allow_ty_var: bool) -> Kind { // cross-crate inlining code to translate a def-id. assert p.def_id.crate == ast::local_crate; - param_bounds_to_kind(cx.ty_param_bounds.get(p.def_id.node)) + param_bounds_to_kind(cx.ty_param_bounds.get(&p.def_id.node)) } // self is a special type parameter that can only appear in traits; it @@ -2810,7 +2810,7 @@ pub fn node_id_to_type(cx: ctxt, id: ast::node_id) -> t { } pub fn node_id_to_type_params(cx: ctxt, id: ast::node_id) -> ~[t] { - match cx.node_type_substs.find(id) { + match cx.node_type_substs.find(&id) { None => return ~[], Some(ts) => return ts } @@ -2950,7 +2950,7 @@ pub fn expr_ty_adjusted(cx: ctxt, expr: @ast::expr) -> t { let unadjusted_ty = expr_ty(cx, expr); - return match cx.adjustments.find(expr.id) { + return match cx.adjustments.find(&expr.id) { None => unadjusted_ty, Some(adj) => { @@ -3054,7 +3054,7 @@ pub fn expr_has_ty_params(cx: ctxt, expr: @ast::expr) -> bool { pub fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map, id: ast::node_id) -> Option<@~[param_bounds]> { - do method_map.find(id).map |method| { + do method_map.find(&id).map |method| { match method.origin { typeck::method_static(did) => { // n.b.: When we encode impl methods, the bounds @@ -3081,7 +3081,7 @@ pub fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map, } fn resolve_expr(tcx: ctxt, expr: @ast::expr) -> ast::def { - match tcx.def_map.find(expr.id) { + match tcx.def_map.find(&expr.id) { Some(def) => def, None => { tcx.sess.span_bug(expr.span, fmt!( @@ -3335,7 +3335,7 @@ pub fn occurs_check(tcx: ctxt, sp: span, vid: TyVid, rt: t) { fn canon(tbl: HashMap>, +m0: ast::inferable) -> ast::inferable { match m0 { - ast::infer(id) => match tbl.find(id) { + ast::infer(id) => match tbl.find(&id) { None => m0, Some(ref m1) => { let cm1 = canon(tbl, (*m1)); @@ -3597,7 +3597,7 @@ pub fn store_trait_methods(cx: ctxt, id: ast::node_id, ms: @~[method]) { pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[ast::ident] { if is_local(id) { - match cx.items.find(id.node) { + match cx.items.find(&id.node) { Some(ast_map::node_item(@ast::item { node: item_trait(_, _, ref ms), _ @@ -3617,7 +3617,7 @@ pub fn trait_supertraits(cx: ctxt, id: ast::def_id) -> @~[InstantiatedTraitRef] { // Check the cache. - match cx.supertraits.find(id) { + match cx.supertraits.find(&id) { Some(instantiated_trait_info) => { return instantiated_trait_info; } None => {} // Continue. } @@ -3646,7 +3646,7 @@ pub fn trait_supertraits(cx: ctxt, } pub fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] { - match cx.trait_method_cache.find(id) { + match cx.trait_method_cache.find(&id) { // Local traits are supposed to have been added explicitly. Some(ms) => ms, _ => { @@ -3680,7 +3680,7 @@ pub fn impl_traits(cx: ctxt, id: ast::def_id, vstore: vstore) -> ~[t] { if id.crate == ast::local_crate { debug!("(impl_traits) searching for trait impl %?", id); - match cx.items.find(id.node) { + match cx.items.find(&id.node) { Some(ast_map::node_item(@ast::item { node: ast::item_impl(_, opt_trait, _, _), _}, @@ -3716,7 +3716,7 @@ fn struct_ctor_id(cx: ctxt, struct_did: ast::def_id) -> Option { cx.sess.unimpl(~"constructor ID of cross-crate tuple structs"); } - match cx.items.find(struct_did.node) { + match cx.items.find(&struct_did.node) { Some(ast_map::node_item(item, _)) => { match item.node { ast::item_struct(struct_def, _) => { @@ -3782,13 +3782,13 @@ impl DtorKind { /* If struct_id names a struct with a dtor, return Some(the dtor's id). Otherwise return none. */ pub fn ty_dtor(cx: ctxt, struct_id: def_id) -> DtorKind { - match cx.destructor_for_type.find(struct_id) { + match cx.destructor_for_type.find(&struct_id) { Some(method_def_id) => return TraitDtor(method_def_id), None => {} // Continue. } if is_local(struct_id) { - match cx.items.find(struct_id.node) { + match cx.items.find(&struct_id.node) { Some(ast_map::node_item(@ast::item { node: ast::item_struct(@ast::struct_def { dtor: Some(ref dtor), _ }, @@ -3816,7 +3816,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path { if id.crate != ast::local_crate { csearch::get_item_path(cx, id) } else { - let node = cx.items.get(id.node); + let node = cx.items.get(&id.node); match node { ast_map::node_item(item, path) => { let item_elt = match item.node { @@ -3880,7 +3880,7 @@ pub fn type_is_empty(cx: ctxt, t: t) -> bool { } pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] { - match cx.enum_var_cache.find(id) { + match cx.enum_var_cache.find(&id) { Some(variants) => return variants, _ => { /* fallthrough */ } } @@ -3893,7 +3893,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] { call eval_const_expr, it should never get called twice for the same expr, since check_enum_variants also updates the enum_var_cache */ - match cx.items.get(id.node) { + match cx.items.get(&id.node) { ast_map::node_item(@ast::item { node: ast::item_enum(ref enum_definition, _), _ @@ -3967,7 +3967,7 @@ pub fn enum_variant_with_id(cx: ctxt, pub fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_bounds_and_ty { - match cx.tcache.find(did) { + match cx.tcache.find(&did) { Some(tpt) => { // The item is in this crate. The caller should have added it to the // type cache already @@ -3993,7 +3993,7 @@ pub fn lookup_field_type(tcx: ctxt, node_id_to_type(tcx, id.node) } else { - match tcx.tcache.find(id) { + match tcx.tcache.find(&id) { Some(tpt) => tpt.ty, None => { let tpt = csearch::get_field_type(tcx, struct_id, id); @@ -4009,7 +4009,7 @@ pub fn lookup_field_type(tcx: ctxt, // Fails if the id is not bound to a struct. pub fn lookup_struct_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] { if did.crate == ast::local_crate { - match cx.items.find(did.node) { + match cx.items.find(&did.node) { Some(ast_map::node_item(i,_)) => { match i.node { ast::item_struct(struct_def, _) => { @@ -4214,7 +4214,7 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t { } } - match cx.normalized_cache.find(t) { + match cx.normalized_cache.find(&t) { Some(t) => return t, None => () } @@ -4397,8 +4397,8 @@ pub fn count_traits_and_supertraits(tcx: ctxt, // Given a trait and a type, returns the impl of that type pub fn get_impl_id(tcx: ctxt, trait_id: def_id, self_ty: t) -> def_id { - match tcx.trait_impls.find(trait_id) { - Some(ty_to_impl) => match ty_to_impl.find(self_ty) { + match tcx.trait_impls.find(&trait_id) { + Some(ty_to_impl) => match ty_to_impl.find(&self_ty) { Some(the_impl) => the_impl.did, None => // try autoderef! match deref(tcx, self_ty, false) { diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 4e4fc564c23..070360ce32f 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -211,7 +211,7 @@ pub fn ast_ty_to_ty( return ty::mk_evec(tcx, mt, vst); } ast::ty_path(path, id) if a_seq_ty.mutbl == ast::m_imm => { - match tcx.def_map.find(id) { + match tcx.def_map.find(&id) { Some(ast::def_prim_ty(ast::ty_str)) => { check_path_args(tcx, path, NO_TPS | NO_REGIONS); return ty::mk_estr(tcx, vst); @@ -273,7 +273,7 @@ pub fn ast_ty_to_ty( let tcx = self.tcx(); - match tcx.ast_ty_to_ty_cache.find(ast_ty) { + match tcx.ast_ty_to_ty_cache.find(&ast_ty) { Some(ty::atttce_resolved(ty)) => return ty, Some(ty::atttce_unresolved) => { tcx.sess.span_fatal(ast_ty.span, ~"illegal recursive type; \ @@ -330,7 +330,7 @@ pub fn ast_ty_to_ty( ty::mk_fn(tcx, fn_decl) } ast::ty_path(path, id) => { - let a_def = match tcx.def_map.find(id) { + let a_def = match tcx.def_map.find(&id) { None => tcx.sess.span_fatal( ast_ty.span, fmt!("unbound path %s", path_to_str(path, tcx.sess.intr()))), diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 3e898ce3aa6..1d84cb32c94 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -216,7 +216,7 @@ pub fn check_struct_pat_fields(pcx: pat_ctxt, // Typecheck each field. let found_fields = HashMap(); for fields.each |field| { - match field_map.find(field.ident) { + match field_map.find(&field.ident) { Some(index) => { let class_field = class_fields[index]; let field_type = ty::lookup_field_type(tcx, @@ -259,7 +259,7 @@ pub fn check_struct_pat(pcx: pat_ctxt, pat_id: ast::node_id, span: span, let class_fields = ty::lookup_struct_fields(tcx, class_id); // Check to ensure that the struct is the one specified. - match tcx.def_map.find(pat_id) { + match tcx.def_map.find(&pat_id) { Some(ast::def_struct(supplied_def_id)) if supplied_def_id == class_id => { // OK. @@ -300,7 +300,7 @@ pub fn check_struct_like_enum_variant_pat(pcx: pat_ctxt, let tcx = pcx.fcx.ccx.tcx; // Find the variant that was specified. - match tcx.def_map.find(pat_id) { + match tcx.def_map.find(&pat_id) { Some(ast::def_variant(found_enum_id, variant_id)) if found_enum_id == enum_id => { // Get the struct fields from this struct-like enum variant. @@ -360,7 +360,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { fcx.write_ty(pat.id, b_ty); } ast::pat_ident(*) if pat_is_const(tcx.def_map, pat) => { - let const_did = ast_util::def_id_of_def(tcx.def_map.get(pat.id)); + let const_did = ast_util::def_id_of_def(tcx.def_map.get(&pat.id)); let const_tpt = ty::lookup_item_type(tcx, const_did); fcx.write_ty(pat.id, const_tpt.ty); } @@ -386,7 +386,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { } } - let canon_id = pcx.map.get(ast_util::path_to_ident(name)); + let canon_id = pcx.map.get(&ast_util::path_to_ident(name)); if canon_id != pat.id { let ct = fcx.local_ty(pat.span, canon_id); demand::eqtype(fcx, pat.span, ct, typ); diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 5a12f9fc3a1..b86f8f26c25 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -323,14 +323,15 @@ pub impl LookupContext { // If the method being called is associated with a trait, then // find all the impls of that trait. Each of those are // candidates. - let opt_applicable_traits = self.fcx.ccx.trait_map.find(self.expr.id); + let opt_applicable_traits = self.fcx.ccx.trait_map.find( + &self.expr.id); for opt_applicable_traits.each |applicable_traits| { for applicable_traits.each |trait_did| { let coherence_info = self.fcx.ccx.coherence_info; // Look for explicit implementations. let opt_impl_infos = - coherence_info.extension_methods.find(*trait_did); + coherence_info.extension_methods.find(trait_did); for opt_impl_infos.each |impl_infos| { for impl_infos.each |impl_info| { self.push_candidates_from_impl( @@ -339,7 +340,7 @@ pub impl LookupContext { } // Look for default methods. - match self.tcx().provided_methods.find(*trait_did) { + match self.tcx().provided_methods.find(trait_did) { Some(methods) => { self.push_candidates_from_provided_methods( &self.extension_candidates, self_ty, *trait_did, @@ -360,7 +361,7 @@ pub impl LookupContext { let tcx = self.tcx(); let mut next_bound_idx = 0; // count only trait bounds - let bounds = tcx.ty_param_bounds.get(param_ty.def_id.node); + let bounds = tcx.ty_param_bounds.get(¶m_ty.def_id.node); for vec::each(*bounds) |bound| { let bound_trait_ty = match *bound { @@ -607,7 +608,7 @@ pub impl LookupContext { fn push_inherent_impl_candidates_for_type(did: def_id) { let opt_impl_infos = - self.fcx.ccx.coherence_info.inherent_methods.find(did); + self.fcx.ccx.coherence_info.inherent_methods.find(&did); for opt_impl_infos.each |impl_infos| { for impl_infos.each |impl_info| { self.push_candidates_from_impl( @@ -1232,7 +1233,7 @@ pub impl LookupContext { fn report_static_candidate(&self, idx: uint, did: def_id) { let span = if did.crate == ast::local_crate { - match self.tcx().items.find(did.node) { + match self.tcx().items.find(&did.node) { Some(ast_map::node_method(m, _, _)) => m.span, _ => die!(fmt!("report_static_candidate: bad item %?", did)) } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index f3abfe3282a..1c0881b6ed5 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -405,7 +405,7 @@ pub fn check_fn(ccx: @crate_ctxt, assign(self_info.self_id, Some(self_info.self_ty)); debug!("self is assigned to %s", fcx.infcx().ty_to_str( - fcx.inh.locals.get(self_info.self_id))); + fcx.inh.locals.get(&self_info.self_id))); } // Add formal parameters. @@ -438,7 +438,7 @@ pub fn check_fn(ccx: @crate_ctxt, debug!("Local variable %s is assigned type %s", fcx.pat_to_str(local.node.pat), fcx.infcx().ty_to_str( - fcx.inh.locals.get(local.node.id))); + fcx.inh.locals.get(&local.node.id))); visit::visit_local(local, e, v); }; @@ -451,7 +451,7 @@ pub fn check_fn(ccx: @crate_ctxt, debug!("Pattern binding %s is assigned to %s", tcx.sess.str_of(path.idents[0]), fcx.infcx().ty_to_str( - fcx.inh.locals.get(p.id))); + fcx.inh.locals.get(&p.id))); } _ => {} } @@ -501,7 +501,7 @@ pub fn check_no_duplicate_fields(tcx: ty::ctxt, for fields.each |p| { let (id, sp) = *p; - match field_names.find(id) { + match field_names.find(&id) { Some(orig_sp) => { tcx.sess.span_err(sp, fmt!("Duplicate field \ name %s in record type declaration", @@ -558,7 +558,7 @@ pub fn check_item(ccx: @crate_ctxt, it: @ast::item) { check_bare_fn(ccx, decl, (*body), it.id, None); } ast::item_impl(_, _, ty, ms) => { - let rp = ccx.tcx.region_paramd_items.find(it.id); + let rp = ccx.tcx.region_paramd_items.find(&it.id); debug!("item_impl %s with id %d rp %?", ccx.tcx.sess.str_of(it.ident), it.id, rp); let self_ty = ccx.to_ty(rscope::type_rscope(rp), ty); @@ -664,7 +664,7 @@ pub impl @fn_ctxt { fn tag() -> ~str { fmt!("%x", ptr::addr_of(&(*self)) as uint) } fn local_ty(span: span, nid: ast::node_id) -> ty::t { - match self.inh.locals.find(nid) { + match self.inh.locals.find(&nid) { Some(t) => t, None => { self.tcx().sess.span_bug( @@ -740,7 +740,7 @@ pub impl @fn_ctxt { } fn expr_ty(ex: @ast::expr) -> ty::t { - match self.inh.node_types.find(ex.id) { + match self.inh.node_types.find(&ex.id) { Some(t) => t, None => { self.tcx().sess.bug( @@ -750,7 +750,7 @@ pub impl @fn_ctxt { } } fn node_ty(id: ast::node_id) -> ty::t { - match self.inh.node_types.find(id) { + match self.inh.node_types.find(&id) { Some(t) => t, None => { self.tcx().sess.bug( @@ -763,7 +763,7 @@ pub impl @fn_ctxt { } } fn node_ty_substs(id: ast::node_id) -> ty::substs { - match self.inh.node_type_substs.find(id) { + match self.inh.node_type_substs.find(&id) { Some(ref ts) => (/*bad*/copy *ts), None => { self.tcx().sess.bug( @@ -776,7 +776,7 @@ pub impl @fn_ctxt { } } fn opt_node_ty_substs(id: ast::node_id) -> Option { - self.inh.node_type_substs.find(id) + self.inh.node_type_substs.find(&id) } @@ -1001,8 +1001,8 @@ pub fn impl_self_ty(vcx: &VtableContext, let tcx = vcx.tcx(); let {n_tps, region_param, raw_ty} = if did.crate == ast::local_crate { - let region_param = tcx.region_paramd_items.find(did.node); - match tcx.items.find(did.node) { + let region_param = tcx.region_paramd_items.find(&did.node); + match tcx.items.find(&did.node) { Some(ast_map::node_item(@ast::item { node: ast::item_impl(ref ts, _, st, _), _ @@ -1698,7 +1698,7 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, // Typecheck each field. for ast_fields.each |field| { - match class_field_map.find(field.node.ident) { + match class_field_map.find(&field.node.ident) { None => { tcx.sess.span_err( field.span, @@ -1734,7 +1734,7 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, let mut missing_fields = ~[]; for field_types.each |class_field| { let name = class_field.ident; - let (_, seen) = class_field_map.get(name); + let (_, seen) = class_field_map.get(&name); if !seen { missing_fields.push( ~"`" + tcx.sess.str_of(name) + ~"`"); @@ -1769,8 +1769,8 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, let type_parameter_count, region_parameterized, raw_type; if class_id.crate == ast::local_crate { region_parameterized = - tcx.region_paramd_items.find(class_id.node); - match tcx.items.find(class_id.node) { + tcx.region_paramd_items.find(&class_id.node); + match tcx.items.find(&class_id.node) { Some(ast_map::node_item(@ast::item { node: ast::item_struct(_, ref type_parameters), _ @@ -1852,8 +1852,8 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, let type_parameter_count, region_parameterized, raw_type; if enum_id.crate == ast::local_crate { region_parameterized = - tcx.region_paramd_items.find(enum_id.node); - match tcx.items.find(enum_id.node) { + tcx.region_paramd_items.find(&enum_id.node); + match tcx.items.find(&enum_id.node) { Some(ast_map::node_item(@ast::item { node: ast::item_enum(_, ref type_parameters), _ @@ -2435,7 +2435,7 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, } ast::expr_struct(path, ref fields, base_expr) => { // Resolve the path. - match tcx.def_map.find(id) { + match tcx.def_map.find(&id) { Some(ast::def_struct(type_def_id)) => { check_struct_constructor(fcx, id, expr.span, type_def_id, (/*bad*/copy *fields), base_expr); @@ -2532,7 +2532,7 @@ pub fn check_decl_local(fcx: @fn_ctxt, local: @ast::local) -> bool { } let region = - ty::re_scope(tcx.region_map.get(local.node.id)); + ty::re_scope(tcx.region_map.get(&local.node.id)); let pcx = pat_ctxt { fcx: fcx, map: pat_id_map(tcx.def_map, local.node.pat), @@ -2633,7 +2633,7 @@ pub fn check_const(ccx: @crate_ctxt, id: ast::node_id) { let rty = ty::node_id_to_type(ccx.tcx, id); let fcx = blank_fn_ctxt(ccx, rty, e.id); - let declty = fcx.ccx.tcx.tcache.get(local_def(id)).ty; + let declty = fcx.ccx.tcx.tcache.get(&local_def(id)).ty; check_const_with_ty(fcx, _sp, e, declty); } @@ -2984,7 +2984,7 @@ pub fn may_break(cx: ty::ctxt, id: ast::node_id, b: ast::blk) -> bool { (block_query(b, |e| { match e.node { ast::expr_break(Some(_)) => - match cx.def_map.find(e.id) { + match cx.def_map.find(&e.id) { Some(ast::def_label(loop_id)) if id == loop_id => true, _ => false, }, @@ -3080,8 +3080,8 @@ pub fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) { let ty_visitor_name = tcx.sess.ident_of(~"TyVisitor"); assert tcx.intrinsic_defs.contains_key_ref(&tydesc_name); assert ccx.tcx.intrinsic_defs.contains_key_ref(&ty_visitor_name); - let (_, tydesc_ty) = tcx.intrinsic_defs.get(tydesc_name); - let (_, visitor_trait) = tcx.intrinsic_defs.get(ty_visitor_name); + let (_, tydesc_ty) = tcx.intrinsic_defs.get(&tydesc_name); + let (_, visitor_trait) = tcx.intrinsic_defs.get(&ty_visitor_name); let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt {ty: tydesc_ty, mutbl: ast::m_imm}); (0u, ~[arg(ast::by_val, td_ptr), diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 9ae55d4556b..952c1a9fcd8 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -181,7 +181,7 @@ pub fn visit_block(b: ast::blk, &&rcx: @rcx, v: rvt) { pub fn visit_expr(expr: @ast::expr, &&rcx: @rcx, v: rvt) { debug!("visit_expr(e=%s)", rcx.fcx.expr_to_str(expr)); - for rcx.fcx.inh.adjustments.find(expr.id).each |adjustment| { + for rcx.fcx.inh.adjustments.find(&expr.id).each |adjustment| { for adjustment.autoref.each |autoref| { guarantor::for_autoref(rcx, expr, *adjustment, autoref); } @@ -327,7 +327,7 @@ pub fn constrain_auto_ref(rcx: @rcx, expr: @ast::expr) { debug!("constrain_auto_ref(expr=%s)", rcx.fcx.expr_to_str(expr)); - let adjustment = rcx.fcx.inh.adjustments.find(expr.id); + let adjustment = rcx.fcx.inh.adjustments.find(&expr.id); let region = match adjustment { Some(@ty::AutoAdjustment { autoref: Some(ref auto_ref), _ }) => { auto_ref.region @@ -725,7 +725,7 @@ pub mod guarantor { let mut expr_ct = categorize_unadjusted(rcx, expr); debug!("before adjustments, cat=%?", expr_ct.cat); - for rcx.fcx.inh.adjustments.find(expr.id).each |adjustment| { + for rcx.fcx.inh.adjustments.find(&expr.id).each |adjustment| { debug!("adjustment=%?", adjustment); expr_ct = apply_autoderefs( diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 18a4f20d031..9f2af3ec003 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -194,7 +194,7 @@ pub fn lookup_vtable(vcx: &VtableContext, match ty::get(ty).sty { ty::ty_param(param_ty {idx: n, def_id: did}) => { let mut n_bound = 0; - let bounds = tcx.ty_param_bounds.get(did.node); + let bounds = tcx.ty_param_bounds.get(&did.node); for ty::iter_bound_traits_and_supertraits( tcx, bounds) |ity| { debug!("checking bounds trait %?", @@ -255,7 +255,7 @@ pub fn lookup_vtable(vcx: &VtableContext, let mut impls_seen = HashMap(); - match vcx.ccx.coherence_info.extension_methods.find(trait_id) { + match vcx.ccx.coherence_info.extension_methods.find(&trait_id) { None => { // Nothing found. Continue. } @@ -525,7 +525,7 @@ pub fn early_resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, is_early: bool) { ast::expr_path(*) => { match fcx.opt_node_ty_substs(ex.id) { Some(ref substs) => { - let def = cx.tcx.def_map.get(ex.id); + let def = cx.tcx.def_map.get(&ex.id); let did = ast_util::def_id_of_def(def); let item_ty = ty::lookup_item_type(cx.tcx, did); debug!("early resolve expr: def %? %?, %?, %?", ex.id, did, def, diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 64ea45c8704..fab64c88b53 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -55,7 +55,7 @@ fn resolve_type_vars_in_type(fcx: @fn_ctxt, sp: span, typ: ty::t) fn resolve_method_map_entry(fcx: @fn_ctxt, sp: span, id: ast::node_id) { // Resolve any method map entry - match fcx.ccx.method_map.find(id) { + match fcx.ccx.method_map.find(&id) { None => {} Some(ref mme) => { for resolve_type_vars_in_type(fcx, sp, mme.self_arg.ty).each |t| { @@ -77,7 +77,7 @@ fn resolve_type_vars_for_node(wbcx: wb_ctxt, sp: span, id: ast::node_id) let fcx = wbcx.fcx, tcx = fcx.ccx.tcx; // Resolve any borrowings for the node with id `id` - match fcx.inh.adjustments.find(id) { + match fcx.inh.adjustments.find(&id) { None => (), Some(adj) => { let resolved_autoref = match adj.autoref { diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 5ad8fd4c820..324cdcc261f 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -236,7 +236,8 @@ pub impl CoherenceChecker { } fn check_implementation(item: @item, associated_traits: ~[@trait_ref]) { - let self_type = self.crate_context.tcx.tcache.get(local_def(item.id)); + let self_type = self.crate_context.tcx.tcache.get( + &local_def(item.id)); // If there are no traits, then this implementation must have a // base type. @@ -354,7 +355,7 @@ pub impl CoherenceChecker { }; let pmm = self.crate_context.tcx.provided_methods; - match pmm.find(local_def(impl_id)) { + match pmm.find(&local_def(impl_id)) { Some(mis) => { // If the trait already has an entry in the // provided_methods_map, we just need to add this @@ -382,7 +383,7 @@ pub impl CoherenceChecker { fn add_inherent_method(base_def_id: def_id, implementation: @Impl) { let implementation_list; match self.crate_context.coherence_info.inherent_methods - .find(base_def_id) { + .find(&base_def_id) { None => { implementation_list = @DVec(); self.crate_context.coherence_info.inherent_methods @@ -399,7 +400,7 @@ pub impl CoherenceChecker { fn add_trait_method(trait_id: def_id, implementation: @Impl) { let implementation_list; match self.crate_context.coherence_info.extension_methods - .find(trait_id) { + .find(&trait_id) { None => { implementation_list = @DVec(); self.crate_context.coherence_info.extension_methods @@ -462,7 +463,7 @@ pub impl CoherenceChecker { debug!("Adding impl %? of %? for %s", the_impl.did, trait_t, ty_to_str(self.crate_context.tcx, self_t)); - match self.crate_context.tcx.trait_impls.find(trait_t) { + match self.crate_context.tcx.trait_impls.find(&trait_t) { None => { let m = HashMap(); m.insert(self_t, the_impl); @@ -480,7 +481,7 @@ pub impl CoherenceChecker { let coherence_info = &self.crate_context.coherence_info; let extension_methods = &coherence_info.extension_methods; - match extension_methods.find(trait_def_id) { + match extension_methods.find(&trait_def_id) { Some(impls) => { for uint::range(0, impls.len()) |i| { f(impls[i]); @@ -612,7 +613,7 @@ pub impl CoherenceChecker { fn get_self_type_for_implementation(implementation: @Impl) -> ty_param_bounds_and_ty { - return self.crate_context.tcx.tcache.get(implementation.did); + return self.crate_context.tcx.tcache.get(&implementation.did); } // Privileged scope checking @@ -627,7 +628,7 @@ pub impl CoherenceChecker { item_impl(_, opt_trait, _, _) => { let mut ok = false; match self.base_type_def_ids.find( - local_def(item.id)) { + &local_def(item.id)) { None => { // Nothing to do. @@ -701,7 +702,7 @@ pub impl CoherenceChecker { fn trait_ref_to_trait_def_id(trait_ref: @trait_ref) -> def_id { let def_map = self.crate_context.tcx.def_map; - let trait_def = def_map.get(trait_ref.ref_id); + let trait_def = def_map.get(&trait_ref.ref_id); let trait_id = def_id_of_def(trait_def); return trait_id; } @@ -774,7 +775,7 @@ pub impl CoherenceChecker { match self.crate_context.tcx .provided_methods - .find(local_def(item.id)) { + .find(&local_def(item.id)) { None => { debug!("(creating impl) trait with node_id `%d` \ has no provided methods", trait_did.node); @@ -808,7 +809,7 @@ pub impl CoherenceChecker { fn span_of_impl(implementation: @Impl) -> span { assert implementation.did.crate == local_crate; - match self.crate_context.tcx.items.find(implementation.did.node) { + match self.crate_context.tcx.items.find(&implementation.did.node) { Some(node_item(item, _)) => { return item.span; } @@ -836,7 +837,7 @@ pub impl CoherenceChecker { // Make sure we don't visit the same implementation // multiple times. - match impls_seen.find(implementation.did) { + match impls_seen.find(&implementation.did) { None => { // Good. Continue. impls_seen.insert(implementation.did, ()); @@ -988,7 +989,7 @@ pub impl CoherenceChecker { let coherence_info = &self.crate_context.coherence_info; let tcx = self.crate_context.tcx; let drop_trait = tcx.lang_items.drop_trait(); - let impls_opt = coherence_info.extension_methods.find(drop_trait); + let impls_opt = coherence_info.extension_methods.find(&drop_trait); let impls; match impls_opt { @@ -1013,7 +1014,7 @@ pub impl CoherenceChecker { _ => { // Destructors only work on nominal types. if impl_info.did.crate == ast::local_crate { - match tcx.items.find(impl_info.did.node) { + match tcx.items.find(&impl_info.did.node) { Some(ast_map::node_item(@ref item, _)) => { tcx.sess.span_err((*item).span, ~"the Drop trait may only \ diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 32d92489188..b7b7899883b 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -130,7 +130,7 @@ pub impl @crate_ctxt: ast_conv { if id.crate != ast::local_crate { csearch::get_type(self.tcx, id) } else { - match self.tcx.items.find(id.node) { + match self.tcx.items.find(&id.node) { Some(ast_map::node_item(item, _)) => { ty_of_item(self, item) } @@ -290,8 +290,8 @@ pub fn ensure_trait_methods(ccx: @crate_ctxt, let tcx = ccx.tcx; - let region_paramd = tcx.region_paramd_items.find(id); - match tcx.items.get(id) { + let region_paramd = tcx.region_paramd_items.find(&id); + match tcx.items.get(&id) { ast_map::node_item(@ast::item { node: ast::item_trait(ref params, _, ref ms), _ @@ -521,7 +521,7 @@ pub fn check_methods_against_trait(ccx: @crate_ctxt, // trait ref. Otherwise, we will potentially overwrite the types of // the methods within the trait with bogus results. (See issue #3903.) - match tcx.items.find(did.node) { + match tcx.items.find(&did.node) { Some(ast_map::node_item(item, _)) => { let tpt = ty_of_item(ccx, item); ensure_trait_methods(ccx, did.node, tpt.ty); @@ -616,7 +616,7 @@ pub fn ensure_no_ty_param_bounds(ccx: @crate_ctxt, pub fn convert(ccx: @crate_ctxt, it: @ast::item) { let tcx = ccx.tcx; - let rp = tcx.region_paramd_items.find(it.id); + let rp = tcx.region_paramd_items.find(&it.id); debug!("convert: item %s with id %d rp %?", tcx.sess.str_of(it.ident), it.id, rp); match /*bad*/copy it.node { @@ -740,7 +740,7 @@ pub fn convert_struct(ccx: @crate_ctxt, arg { mode: ast::expl(ast::by_copy), ty: ccx.tcx.tcache.get - (local_def(field.node.id)).ty + (&local_def(field.node.id)).ty } }, output: selfty @@ -830,11 +830,11 @@ pub fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) let def_id = local_def(it.id); let tcx = ccx.tcx; - match tcx.tcache.find(def_id) { + match tcx.tcache.find(&def_id) { Some(tpt) => return tpt, _ => {} } - let rp = tcx.region_paramd_items.find(it.id); + let rp = tcx.region_paramd_items.find(&it.id); match /*bad*/copy it.node { ast::item_const(t, _) => { let typ = ccx.to_ty(empty_rscope, t); @@ -859,12 +859,12 @@ pub fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) return tpt; } ast::item_ty(t, tps) => { - match tcx.tcache.find(local_def(it.id)) { + match tcx.tcache.find(&local_def(it.id)) { Some(tpt) => return tpt, None => { } } - let rp = tcx.region_paramd_items.find(it.id); + let rp = tcx.region_paramd_items.find(&it.id); let tpt = { let ty = { let t0 = ccx.to_ty(type_rscope(rp), t); @@ -978,7 +978,7 @@ pub fn compute_bounds(ccx: @crate_ctxt, pub fn ty_param_bounds(ccx: @crate_ctxt, params: ~[ast::ty_param]) -> @~[ty::param_bounds] { @do params.map |param| { - match ccx.tcx.ty_param_bounds.find(param.id) { + match ccx.tcx.ty_param_bounds.find(¶m.id) { Some(bs) => bs, None => { let bounds = compute_bounds(ccx, param.bounds); diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index 1a8e25239b3..0d4e520122f 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -912,7 +912,7 @@ pub impl RegionVarBindings { -> cres { let vars = TwoRegions { a: a, b: b }; - match combines.find(vars) { + match combines.find(&vars) { Some(c) => Ok(re_infer(ReVar(c))), None => { let c = self.new_region_var(span); diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index d292f04caa4..742646618bd 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -225,7 +225,7 @@ pub fn write_substs_to_tcx(tcx: ty::ctxt, } pub fn lookup_def_tcx(tcx: ty::ctxt, sp: span, id: ast::node_id) -> ast::def { - match tcx.def_map.find(id) { + match tcx.def_map.find(&id) { Some(x) => x, _ => { tcx.sess.span_fatal(sp, ~"internal error looking up a definition") @@ -325,7 +325,7 @@ fn check_main_fn_ty(ccx: @crate_ctxt, let main_t = ty::node_id_to_type(tcx, main_id); match ty::get(main_t).sty { ty::ty_fn(ref fn_ty) => { - match tcx.items.find(main_id) { + match tcx.items.find(&main_id) { Some(ast_map::node_item(it,_)) => { match it.node { ast::item_fn(_, _, ref ps, _) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 2ed2d3ea5d7..9e70a6ab130 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -67,7 +67,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region) -> (~str, Option) { return match region { re_scope(node_id) => { - match cx.items.find(node_id) { + match cx.items.find(&node_id) { Some(ast_map::node_block(ref blk)) => { explain_span(cx, "block", (*blk).span) } @@ -105,7 +105,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region) bound_region_to_str(cx, br)) }; - match cx.items.find(id) { + match cx.items.find(&id) { Some(ast_map::node_block(ref blk)) => { let (msg, opt_span) = explain_span(cx, "block", (*blk).span); (fmt!("%s %s", prefix, msg), opt_span) @@ -154,7 +154,7 @@ pub fn bound_region_to_str_adorned(cx: ctxt, prefix: &str, } pub fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str { - match cx.items.find(node_id) { + match cx.items.find(&node_id) { Some(ast_map::node_block(ref blk)) => { fmt!("", cx.sess.codemap.span_to_str((*blk).span)) diff --git a/src/librustdoc/attr_pass.rs b/src/librustdoc/attr_pass.rs index 0e70900520d..c595ebce65f 100644 --- a/src/librustdoc/attr_pass.rs +++ b/src/librustdoc/attr_pass.rs @@ -116,7 +116,7 @@ fn parse_item_attrs( id: doc::AstId, parse_attrs: fn~(a: ~[ast::attribute]) -> T) -> T { do astsrv::exec(srv) |move parse_attrs, ctxt| { - let attrs = match ctxt.ast_map.get(id) { + let attrs = match ctxt.ast_map.get(&id) { ast_map::node_item(item, _) => copy item.attrs, ast_map::node_foreign_item(item, _, _) => copy item.attrs, _ => die!(~"parse_item_attrs: not an item") @@ -170,7 +170,7 @@ fn fold_enum( let desc = { let variant = copy variant; do astsrv::exec(srv.clone()) |ctxt| { - match ctxt.ast_map.get(doc_id) { + match ctxt.ast_map.get(&doc_id) { ast_map::node_item(@ast::item { node: ast::item_enum(ref enum_definition, _), _ }, _) => { @@ -234,7 +234,7 @@ fn merge_method_attrs( // Create an assoc list from method name to attributes let attrs: ~[(~str, Option<~str>)] = do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(item_id) { + match ctxt.ast_map.get(&item_id) { ast_map::node_item(@ast::item { node: ast::item_trait(_, _, ref methods), _ }, _) => { diff --git a/src/librustdoc/prune_hidden_pass.rs b/src/librustdoc/prune_hidden_pass.rs index f039bb74583..97258d99ba4 100644 --- a/src/librustdoc/prune_hidden_pass.rs +++ b/src/librustdoc/prune_hidden_pass.rs @@ -56,7 +56,7 @@ fn is_hidden(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool { let id = doc.id; do astsrv::exec(srv) |ctxt| { - let attrs = match ctxt.ast_map.get(id) { + let attrs = match ctxt.ast_map.get(&id) { ast_map::node_item(item, _) => copy item.attrs, _ => ~[] }; diff --git a/src/librustdoc/prune_private_pass.rs b/src/librustdoc/prune_private_pass.rs index 4b47b71449a..1acb6092e2c 100644 --- a/src/librustdoc/prune_private_pass.rs +++ b/src/librustdoc/prune_private_pass.rs @@ -59,7 +59,7 @@ fn is_visible(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool { let id = doc.id; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(id) { + match ctxt.ast_map.get(&id) { ast_map::node_item(item, _) => { item.vis == ast::public } diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index 4ab40530cfb..58a2e0e1324 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -68,7 +68,7 @@ fn fold_fn( fn get_fn_sig(srv: astsrv::Srv, fn_id: doc::AstId) -> Option<~str> { do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(fn_id) { + match ctxt.ast_map.get(&fn_id) { ast_map::node_item(@ast::item { ident: ident, node: ast::item_fn(ref decl, _, ref tys, _), _ @@ -107,7 +107,7 @@ fn fold_const( sig: Some({ let doc = copy doc; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(doc.id()) { + match ctxt.ast_map.get(&doc.id()) { ast_map::node_item(@ast::item { node: ast::item_const(ty, _), _ }, _) => { @@ -138,7 +138,7 @@ fn fold_enum( let sig = { let variant = copy *variant; do astsrv::exec(srv.clone()) |copy variant, ctxt| { - match ctxt.ast_map.get(doc_id) { + match ctxt.ast_map.get(&doc_id) { ast_map::node_item(@ast::item { node: ast::item_enum(ref enum_definition, _), _ }, _) => { @@ -199,7 +199,7 @@ fn get_method_sig( method_name: ~str ) -> Option<~str> { do astsrv::exec(srv) |copy method_name, ctxt| { - match ctxt.ast_map.get(item_id) { + match ctxt.ast_map.get(&item_id) { ast_map::node_item(@ast::item { node: ast::item_trait(_, _, ref methods), _ }, _) => { @@ -271,7 +271,7 @@ fn fold_impl( let (trait_types, self_ty) = { let doc = copy doc; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(doc.id()) { + match ctxt.ast_map.get(&doc.id()) { ast_map::node_item(@ast::item { node: ast::item_impl(_, opt_trait_type, self_ty, _), _ }, _) => { @@ -331,7 +331,7 @@ fn fold_type( sig: { let doc = copy doc; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(doc.id()) { + match ctxt.ast_map.get(&doc.id()) { ast_map::node_item(@ast::item { ident: ident, node: ast::item_ty(ty, ref params), _ @@ -369,7 +369,7 @@ fn fold_struct( sig: { let doc = copy doc; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(doc.id()) { + match ctxt.ast_map.get(&doc.id()) { ast_map::node_item(item, _) => { let item = strip_struct_extra_stuff(item); Some(pprust::item_to_str(item, diff --git a/src/libstd/oldmap.rs b/src/libstd/oldmap.rs index d8fecda73a7..d6fb06e3f8e 100644 --- a/src/libstd/oldmap.rs +++ b/src/libstd/oldmap.rs @@ -226,9 +226,9 @@ pub mod chained { } } - pure fn find(&self, k: K) -> Option { + pure fn find(&self, k: &K) -> Option { unsafe { - match self.search_tbl(&k, k.hash_keyed(0,0) as uint) { + match self.search_tbl(k, k.hash_keyed(0,0) as uint) { NotFound => None, FoundFirst(_, entry) => Some(entry.value), FoundAfter(_, entry) => Some(entry.value) @@ -291,7 +291,7 @@ pub mod chained { return self.update_with_key(key, newval, |_k, v, v1| ff(v,v1)); } - pure fn get(&self, k: K) -> V { + pure fn get(&self, k: &K) -> V { let opt_v = self.find(k); if opt_v.is_none() { die!(fmt!("Key not found in table: %?", k)); @@ -364,7 +364,7 @@ pub mod chained { impl T: ops::Index { pure fn index(&self, k: K) -> V { unsafe { - self.get(k) + self.get(&k) } } } @@ -421,7 +421,6 @@ pub fn hash_from_vec( #[cfg(test)] mod tests { use core::option::None; - use core::option; use core::uint; use super::*; @@ -437,13 +436,13 @@ mod tests { assert (hm_uu.insert(10u, 12u)); assert (hm_uu.insert(11u, 13u)); assert (hm_uu.insert(12u, 14u)); - assert (hm_uu.get(11u) == 13u); - assert (hm_uu.get(12u) == 14u); - assert (hm_uu.get(10u) == 12u); + assert (hm_uu.get(&11) == 13u); + assert (hm_uu.get(&12) == 14u); + assert (hm_uu.get(&10) == 12u); assert (!hm_uu.insert(12u, 14u)); - assert (hm_uu.get(12u) == 14u); + assert (hm_uu.get(&12) == 14u); assert (!hm_uu.insert(12u, 12u)); - assert (hm_uu.get(12u) == 12u); + assert (hm_uu.get(&12) == 12u); let ten: ~str = ~"ten"; let eleven: ~str = ~"eleven"; let twelve: ~str = ~"twelve"; @@ -453,40 +452,40 @@ mod tests { assert (hm_su.insert(~"ten", 12u)); assert (hm_su.insert(eleven, 13u)); assert (hm_su.insert(~"twelve", 14u)); - assert (hm_su.get(eleven) == 13u); - assert (hm_su.get(~"eleven") == 13u); - assert (hm_su.get(~"twelve") == 14u); - assert (hm_su.get(~"ten") == 12u); + assert (hm_su.get(&eleven) == 13u); + assert (hm_su.get(&~"eleven") == 13u); + assert (hm_su.get(&~"twelve") == 14u); + assert (hm_su.get(&~"ten") == 12u); assert (!hm_su.insert(~"twelve", 14u)); - assert (hm_su.get(~"twelve") == 14u); + assert (hm_su.get(&~"twelve") == 14u); assert (!hm_su.insert(~"twelve", 12u)); - assert (hm_su.get(~"twelve") == 12u); + assert (hm_su.get(&~"twelve") == 12u); debug!("uint -> str"); let hm_us: HashMap = HashMap::(); assert (hm_us.insert(10u, ~"twelve")); assert (hm_us.insert(11u, ~"thirteen")); assert (hm_us.insert(12u, ~"fourteen")); - assert hm_us.get(11u) == ~"thirteen"; - assert hm_us.get(12u) == ~"fourteen"; - assert hm_us.get(10u) == ~"twelve"; + assert hm_us.get(&11) == ~"thirteen"; + assert hm_us.get(&12) == ~"fourteen"; + assert hm_us.get(&10) == ~"twelve"; assert (!hm_us.insert(12u, ~"fourteen")); - assert hm_us.get(12u) == ~"fourteen"; + assert hm_us.get(&12) == ~"fourteen"; assert (!hm_us.insert(12u, ~"twelve")); - assert hm_us.get(12u) == ~"twelve"; + assert hm_us.get(&12) == ~"twelve"; debug!("str -> str"); let hm_ss: HashMap<~str, ~str> = HashMap::<~str, ~str>(); assert (hm_ss.insert(ten, ~"twelve")); assert (hm_ss.insert(eleven, ~"thirteen")); assert (hm_ss.insert(twelve, ~"fourteen")); - assert hm_ss.get(~"eleven") == ~"thirteen"; - assert hm_ss.get(~"twelve") == ~"fourteen"; - assert hm_ss.get(~"ten") == ~"twelve"; + assert hm_ss.get(&~"eleven") == ~"thirteen"; + assert hm_ss.get(&~"twelve") == ~"fourteen"; + assert hm_ss.get(&~"ten") == ~"twelve"; assert (!hm_ss.insert(~"twelve", ~"fourteen")); - assert hm_ss.get(~"twelve") == ~"fourteen"; + assert hm_ss.get(&~"twelve") == ~"fourteen"; assert (!hm_ss.insert(~"twelve", ~"twelve")); - assert hm_ss.get(~"twelve") == ~"twelve"; + assert hm_ss.get(&~"twelve") == ~"twelve"; debug!("*** finished test_simple"); } @@ -512,17 +511,17 @@ mod tests { debug!("-----"); i = 0u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm_uu.get(i)); - assert (hm_uu.get(i) == i * i); + debug!("get(%u) = %u", i, hm_uu.get(&i)); + assert (hm_uu.get(&i) == i * i); i += 1u; } assert (hm_uu.insert(num_to_insert, 17u)); - assert (hm_uu.get(num_to_insert) == 17u); + assert (hm_uu.get(&num_to_insert) == 17u); debug!("-----"); i = 0u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm_uu.get(i)); - assert (hm_uu.get(i) == i * i); + debug!("get(%u) = %u", i, hm_uu.get(&i)); + assert (hm_uu.get(&i) == i * i); i += 1u; } debug!("str -> str"); @@ -542,22 +541,22 @@ mod tests { while i < num_to_insert { debug!("get(\"%s\") = \"%s\"", uint::to_str_radix(i, 2u), - hm_ss.get(uint::to_str_radix(i, 2u))); - assert hm_ss.get(uint::to_str_radix(i, 2u)) == + hm_ss.get(&uint::to_str_radix(i, 2u))); + assert hm_ss.get(&uint::to_str_radix(i, 2u)) == uint::to_str_radix(i * i, 2u); i += 1u; } assert (hm_ss.insert(uint::to_str_radix(num_to_insert, 2u), uint::to_str_radix(17u, 2u))); - assert hm_ss.get(uint::to_str_radix(num_to_insert, 2u)) == + assert hm_ss.get(&uint::to_str_radix(num_to_insert, 2u)) == uint::to_str_radix(17u, 2u); debug!("-----"); i = 0u; while i < num_to_insert { debug!("get(\"%s\") = \"%s\"", uint::to_str_radix(i, 2u), - hm_ss.get(uint::to_str_radix(i, 2u))); - assert hm_ss.get(uint::to_str_radix(i, 2u)) == + hm_ss.get(&uint::to_str_radix(i, 2u))); + assert hm_ss.get(&uint::to_str_radix(i, 2u)) == uint::to_str_radix(i * i, 2u); i += 1u; } @@ -589,15 +588,15 @@ mod tests { debug!("-----"); i = 1u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm.get(i)); - assert (hm.get(i) == i * i); + debug!("get(%u) = %u", i, hm.get(&i)); + assert (hm.get(&i) == i * i); i += 2u; } debug!("-----"); i = 1u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm.get(i)); - assert (hm.get(i) == i * i); + debug!("get(%u) = %u", i, hm.get(&i)); + assert (hm.get(&i) == i * i); i += 2u; } debug!("-----"); @@ -611,16 +610,16 @@ mod tests { debug!("-----"); i = 0u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm.get(i)); - assert (hm.get(i) == i * i); + debug!("get(%u) = %u", i, hm.get(&i)); + assert (hm.get(&i) == i * i); i += 1u; } debug!("-----"); assert (hm.len() == num_to_insert); i = 0u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm.get(i)); - assert (hm.get(i) == i * i); + debug!("get(%u) = %u", i, hm.get(&i)); + assert (hm.get(&i) == i * i); i += 1u; } debug!("*** finished test_removal"); @@ -639,9 +638,9 @@ mod tests { fn test_find() { let key = ~"k"; let map = HashMap::<~str, ~str>(); - assert (option::is_none(&map.find(key))); + assert map.find(&key).is_none(); map.insert(key, ~"val"); - assert (option::get(map.find(key)) == ~"val"); + assert map.find(&key).get() == ~"val"; } #[test] @@ -664,9 +663,9 @@ mod tests { (~"c", 3) ]); assert map.len() == 3u; - assert map.get(~"a") == 1; - assert map.get(~"b") == 2; - assert map.get(~"c") == 3; + assert map.get(&~"a") == 1; + assert map.get(&~"b") == 2; + assert map.get(&~"c") == 3; } #[test] @@ -692,11 +691,11 @@ mod tests { map.update_with_key(~"cat", 2, addMoreToCount); // check the total counts - assert 10 == option::get(map.find(~"cat")); - assert 3 == option::get(map.find(~"ferret")); - assert 1 == option::get(map.find(~"mongoose")); + assert map.find(&~"cat").get() == 10; + assert map.find(&~"ferret").get() == 3; + assert map.find(&~"mongoose").get() == 1; // sadly, no mythical animals were counted! - assert None == map.find(~"unicorn"); + assert map.find(&~"unicorn").is_none(); } } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index e6a4639ad80..fe41cee919f 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -333,7 +333,7 @@ pub fn map_stmt(stmt: @stmt, cx: ctx, v: vt) { } pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { - match map.find(id) { + match map.find(&id) { None => { fmt!("unknown node (id=%d)", id) } @@ -398,7 +398,7 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { pub fn node_item_query(items: map, id: node_id, query: fn(@item) -> Result, error_msg: ~str) -> Result { - match items.find(id) { + match items.find(&id) { Some(node_item(it, _)) => query(it), _ => die!(error_msg) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 227a86e0766..18256369c78 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -40,7 +40,7 @@ pub fn expand_expr(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt, /* using idents and token::special_idents would make the the macro names be hygienic */ let extname = cx.parse_sess().interner.get(pth.idents[0]); - match exts.find(*extname) { + match exts.find(extname) { None => { cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)) @@ -104,7 +104,7 @@ pub fn expand_mod_items(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt, ast::meta_name_value(ref n, _) => (*n), ast::meta_list(ref n, _) => (*n) }; - match exts.find(mname) { + match exts.find(&mname) { None | Some(NormalTT(_)) | Some(ItemTT(*)) => items, Some(ItemDecorator(dec_fn)) => { cx.bt_push(ExpandedFrom({call_site: attr.span, @@ -161,7 +161,7 @@ pub fn expand_item_mac(exts: HashMap<~str, SyntaxExtension>, }; let extname = cx.parse_sess().interner.get(pth.idents[0]); - let expanded = match exts.find(*extname) { + let expanded = match exts.find(extname) { None => cx.span_fatal(pth.span, fmt!("macro undefined: '%s!'", *extname)), @@ -224,7 +224,7 @@ pub fn expand_stmt(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt, assert(vec::len(pth.idents) == 1u); let extname = cx.parse_sess().interner.get(pth.idents[0]); - let (fully_expanded, sp) = match exts.find(*extname) { + let (fully_expanded, sp) = match exts.find(extname) { None => cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)), diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 31172cbfa85..3e7a84240e4 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -59,11 +59,11 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, arg_reader as reader, argument_gram); // Extract the arguments: - let lhses:~[@named_match] = match argument_map.get(lhs_nm) { + let lhses:~[@named_match] = match argument_map.get(&lhs_nm) { @matched_seq(s, _) => s, _ => cx.span_bug(sp, ~"wrong-structured lhs") }; - let rhses:~[@named_match] = match argument_map.get(rhs_nm) { + let rhses:~[@named_match] = match argument_map.get(&rhs_nm) { @matched_seq(s, _) => s, _ => cx.span_bug(sp, ~"wrong-structured rhs") }; diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 6bf90617a6e..6f57ca38f1f 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -111,7 +111,7 @@ pure fn lookup_cur_matched_by_matched(r: tt_reader, } fn lookup_cur_matched(r: tt_reader, name: ident) -> @named_match { - lookup_cur_matched_by_matched(r, r.interpolations.get(name)) + lookup_cur_matched_by_matched(r, r.interpolations.get(&name)) } enum lis { lis_unconstrained, lis_constraint(uint, ident), lis_contradiction(~str) diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 19b938ccd68..905571d1817 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -44,7 +44,7 @@ pub trait Interner { pub impl hash_interner: Interner { fn intern(val: T) -> uint { - match self.map.find(val) { + match self.map.find(&val) { Some(idx) => return idx, None => { let new_idx = self.vect.len(); diff --git a/src/test/auxiliary/issue-2631-a.rs b/src/test/auxiliary/issue-2631-a.rs index 748c209229c..8679d3a7786 100644 --- a/src/test/auxiliary/issue-2631-a.rs +++ b/src/test/auxiliary/issue-2631-a.rs @@ -20,5 +20,5 @@ pub type header_map = HashMap<~str, @DVec<@~str>>; // the unused ty param is necessary so this gets monomorphized pub fn request(req: header_map) { - let _x = copy *(copy *req.get(~"METHOD"))[0u]; + let _x = copy *(copy *req.get(&~"METHOD"))[0u]; } diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index 67c071da26d..68ba40749f2 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -42,7 +42,7 @@ fn old_int_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { } for uint::range(0, num_keys) |i| { - assert map.get(i) == i+1; + assert map.get(&i) == i+1; } } } @@ -81,7 +81,7 @@ fn old_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { for uint::range(0, num_keys) |i| { let s = uint::to_str(i); - assert map.get(s) == i; + assert map.get(&s) == i; } } } diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index 32b6c491898..fafda39993e 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -83,7 +83,7 @@ fn str_set() { let mut found = 0; for int::range(0, 1000) |_i| { - match s.find(r.gen_str(10)) { + match s.find(&r.gen_str(10)) { Some(_) => { found += 1; } None => { } } diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 0f4f22196ce..811f39e4343 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -69,7 +69,7 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str { // given a map, search for the frequency of a pattern fn find(mm: HashMap<~[u8], uint>, key: ~str) -> uint { - match mm.find(str::to_bytes(str::to_lower(key))) { + match mm.find(&str::to_bytes(str::to_lower(key))) { option::None => { return 0u; } option::Some(num) => { return num; } } diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 8cf57b19825..5888dab3bb9 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -136,7 +136,7 @@ fn writer(path: ~str, pport: pipes::Port, size: uint) while prev <= i { if lines.contains_key_ref(&prev) { debug!("WS %u", prev); - cout.write(lines.get(prev)); + cout.write(lines.get(&prev)); done += 1_u; lines.remove(&prev); prev += 1_u; diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 43e2bee644a..d7a285d58e6 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -49,7 +49,7 @@ mod map_reduce { fn emit(im: oldmap::HashMap<~str, int>, ctrl: SharedChan, key: ~str, val: ~str) { let mut c; - match im.find(copy key) { + match im.find(&key) { Some(_c) => { c = _c } None => { let (pp, cc) = stream(); @@ -88,7 +88,7 @@ mod map_reduce { mapper_done => { num_mappers -= 1; } find_reducer(k, cc) => { let mut c; - match reducers.find(str::from_bytes(k)) { + match reducers.find(&str::from_bytes(k)) { Some(_c) => { c = _c; } None => { c = 0; } } From 6105f09cc163ab728ff0ef18d4f817ad1a34bfb3 Mon Sep 17 00:00:00 2001 From: ILyoan Date: Mon, 4 Feb 2013 19:30:17 +0900 Subject: [PATCH 08/37] Use x86-64 CABI for foreign function on arm target --- src/librustc/middle/trans/foreign.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 3d441dc973a..9c2245411c6 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -42,7 +42,7 @@ use syntax::parse::token::special_idents; fn abi_info(arch: session::arch) -> cabi::ABIInfo { return match arch { - arch_x86_64 => x86_64_abi_info(), + arch_x86_64 | arch_arm => x86_64_abi_info(), _ => cabi::llvm_abi_info() } } From 6d5428cb4ee9117f16d3a5c7f36def4c60b364ed Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Mon, 4 Feb 2013 23:01:47 +0900 Subject: [PATCH 09/37] Let type_is_integral return false for bool type --- src/librustc/middle/ty.rs | 2 +- src/test/compile-fail/unop-neg-bool.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/unop-neg-bool.rs diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 4a0448c0b24..1cbaeed9f25 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2435,7 +2435,7 @@ pub fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool { pub fn type_is_integral(ty: t) -> bool { match get(ty).sty { - ty_infer(IntVar(_)) | ty_int(_) | ty_uint(_) | ty_bool => true, + ty_infer(IntVar(_)) | ty_int(_) | ty_uint(_) => true, _ => false } } diff --git a/src/test/compile-fail/unop-neg-bool.rs b/src/test/compile-fail/unop-neg-bool.rs new file mode 100644 index 00000000000..6f1f1aba459 --- /dev/null +++ b/src/test/compile-fail/unop-neg-bool.rs @@ -0,0 +1,3 @@ +fn main() { + -true; //~ ERROR cannot apply unary operator `-` to type `bool` +} From 2c46bf7e318f585947c2146ce42c249fba3bc326 Mon Sep 17 00:00:00 2001 From: Dimitri Krassovski Date: Sat, 2 Feb 2013 01:07:56 +0200 Subject: [PATCH 10/37] Add support for clang 4.2 (as reported by apple clang) r=graydon --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index e9790205b90..9813f0ec6b6 100755 --- a/configure +++ b/configure @@ -515,7 +515,7 @@ then | cut -d ' ' -f 2) case $CFG_CLANG_VERSION in - (3.0svn | 3.0 | 3.1* | 3.2* | 4.0* | 4.1*) + (3.0svn | 3.0 | 3.1* | 3.2* | 4.0* | 4.1* | 4.2*) step_msg "found ok version of CLANG: $CFG_CLANG_VERSION" CFG_C_COMPILER="clang" ;; From 7d5322cf09900816d40618b70d329b8bd386ee3b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 4 Feb 2013 13:33:17 -0800 Subject: [PATCH 11/37] libcore: Add @ to Readers --- src/libcore/io.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libcore/io.rs b/src/libcore/io.rs index b726cf62cfe..e7d568c5433 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -490,11 +490,11 @@ pub fn FILERes(f: *libc::FILE) -> FILERes { } } -pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader { +pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> @Reader { if cleanup { - Wrapper { base: f, cleanup: FILERes(f) } as Reader + @Wrapper { base: f, cleanup: FILERes(f) } as @Reader } else { - f as Reader + @f as @Reader } } @@ -502,13 +502,13 @@ pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader { // top-level functions that take a reader, or a set of default methods on // reader (which can then be called reader) -pub fn stdin() -> Reader { +pub fn stdin() -> @Reader { unsafe { - rustrt::rust_get_stdin() as Reader + rustrt::rust_get_stdin() as @Reader } } -pub fn file_reader(path: &Path) -> Result { +pub fn file_reader(path: &Path) -> Result<@Reader, ~str> { unsafe { let f = os::as_c_charp(path.to_str(), |pathbuf| { os::as_c_charp("r", |modebuf| @@ -555,11 +555,11 @@ impl BytesReader: Reader { fn tell(&self) -> uint { self.pos } } -pub pure fn with_bytes_reader(bytes: &[u8], f: fn(Reader) -> t) -> t { - f(BytesReader { bytes: bytes, pos: 0u } as Reader) +pub pure fn with_bytes_reader(bytes: &[u8], f: fn(@Reader) -> t) -> t { + f(@BytesReader { bytes: bytes, pos: 0u } as @Reader) } -pub pure fn with_str_reader(s: &str, f: fn(Reader) -> T) -> T { +pub pure fn with_str_reader(s: &str, f: fn(@Reader) -> T) -> T { str::byte_slice(s, |bytes| with_bytes_reader(bytes, f)) } From 8dfab498ef21d332a50c36059db7eacabb58cbcb Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 4 Feb 2013 14:19:19 -0800 Subject: [PATCH 12/37] Ignore test exclusive_unwrap_conflict. #4689 --- src/libcore/private.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/private.rs b/src/libcore/private.rs index 1fb8166ed12..40194713365 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -486,7 +486,7 @@ pub mod tests { res.recv(); } - #[test] #[should_fail] #[ignore(cfg(windows))] + #[test] #[should_fail] #[ignore(reason = "random red")] pub fn exclusive_unwrap_conflict() { let x = exclusive(~~"hello"); let x2 = ~mut Some(x.clone()); From e22aa029fb4d923dc03748b435abd6330933b473 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 29 Jan 2013 15:06:05 -0800 Subject: [PATCH 13/37] core/syntax: Add transitional code for pipes --- src/libcore/pipes.rs | 25 ++++++++++++++++--------- src/libsyntax/ext/pipes/pipec.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 254e6010b1b..3e941da1247 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -143,14 +143,9 @@ pub fn BufferHeader() -> BufferHeader { // This is for protocols to associate extra data to thread around. #[doc(hidden)] #[cfg(stage0)] -type Buffer = { - header: BufferHeader, - data: T, -}; -#[doc(hidden)] #[cfg(stage1)] +type Buffer = { header: BufferHeader, data: T }; #[cfg(stage2)] -#[cfg(stage3)] pub struct Buffer { header: BufferHeader, data: T, @@ -247,7 +242,6 @@ pub fn mk_packet() -> Packet { payload: None, } } - #[doc(hidden)] #[cfg(stage0)] fn unibuffer() -> ~Buffer> { @@ -264,10 +258,23 @@ fn unibuffer() -> ~Buffer> { } move b } -#[doc(hidden)] #[cfg(stage1)] +fn unibuffer() -> ~Buffer> { + let b = ~{ + header: BufferHeader(), + data: Packet { + header: PacketHeader(), + payload: None, + } + }; + + unsafe { + b.data.header.buffer = reinterpret_cast(&b); + } + move b +} +#[doc(hidden)] #[cfg(stage2)] -#[cfg(stage3)] fn unibuffer() -> ~Buffer> { let b = ~Buffer { header: BufferHeader(), diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 8c73dcfc04f..4bf59d9c627 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -355,6 +355,34 @@ pub impl protocol: gen_init { })) } + #[cfg(stage0)] + fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr { + debug!("gen_init_bounded"); + let buffer_fields = self.gen_buffer_init(ext_cx); + let buffer = quote_expr!(~{ + header: ::pipes::BufferHeader(), + data: $buffer_fields, + }); + + let entangle_body = ext_cx.block_expr( + ext_cx.block( + self.states.map_to_vec( + |s| ext_cx.parse_stmt( + fmt!("data.%s.set_buffer_(buffer)", + s.name))), + ext_cx.parse_expr( + fmt!("::ptr::addr_of(&(data.%s))", + self.states[0].name)))); + + quote_expr!({ + let buffer = $buffer; + do ::pipes::entangle_buffer(move buffer) |buffer, data| { + $entangle_body + } + }) + } + #[cfg(stage1)] + #[cfg(stage2)] fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr { debug!("gen_init_bounded"); let buffer_fields = self.gen_buffer_init(ext_cx); From 4e45d7111c73f348153177ee4a1a988f3d95306d Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 29 Jan 2013 15:09:20 -0800 Subject: [PATCH 14/37] syntax: Make the pipe compiler stop generating set_buffer_ calls --- src/libsyntax/ext/pipes/pipec.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 4bf59d9c627..eec9c6eceaf 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -368,7 +368,7 @@ pub impl protocol: gen_init { ext_cx.block( self.states.map_to_vec( |s| ext_cx.parse_stmt( - fmt!("data.%s.set_buffer_(buffer)", + fmt!("data.%s.set_buffer(buffer)", s.name))), ext_cx.parse_expr( fmt!("::ptr::addr_of(&(data.%s))", @@ -395,7 +395,7 @@ pub impl protocol: gen_init { ext_cx.block( self.states.map_to_vec( |s| ext_cx.parse_stmt( - fmt!("data.%s.set_buffer_(buffer)", + fmt!("data.%s.set_buffer(buffer)", s.name))), ext_cx.parse_expr( fmt!("::ptr::addr_of(&(data.%s))", From 73a7672b8d9ddab92c91d1b343535b9a9a765b68 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 4 Feb 2013 16:48:52 -0800 Subject: [PATCH 15/37] std: Stamp out structural records See #4665 --- src/libstd/c_vec.rs | 28 ++++++++---------- src/libstd/ebml.rs | 15 ++++++---- src/libstd/md4.rs | 13 +++++++-- src/libstd/sha1.rs | 4 +-- src/libstd/std.rc | 4 --- src/libstd/test.rs | 63 +++++++++++++++++++++-------------------- src/libstd/uv_iotask.rs | 16 +++++------ src/libstd/uv_ll.rs | 2 +- 8 files changed, 74 insertions(+), 71 deletions(-) diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index c190d08687a..17920f5de3f 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -46,11 +46,11 @@ use core::task; /** * The type representing a foreign chunk of memory * - * Wrapped in a enum for opacity; FIXME #818 when it is possible to have - * truly opaque types, this should be revisited. */ -pub enum CVec { - CVecCtor({ base: *mut T, len: uint, rsrc: @DtorRes}) +pub struct CVec { + priv base: *mut T, + priv len: uint, + priv rsrc: @DtorRes } struct DtorRes { @@ -85,11 +85,11 @@ fn DtorRes(dtor: Option) -> DtorRes { * * len - The number of elements in the buffer */ pub unsafe fn CVec(base: *mut T, len: uint) -> CVec { - return CVecCtor({ + return CVec{ base: base, len: len, rsrc: @DtorRes(option::None) - }); + }; } /** @@ -105,11 +105,11 @@ pub unsafe fn CVec(base: *mut T, len: uint) -> CVec { */ pub unsafe fn c_vec_with_dtor(base: *mut T, len: uint, dtor: fn@()) -> CVec { - return CVecCtor({ + return CVec{ base: base, len: len, rsrc: @DtorRes(option::Some(dtor)) - }); + }; } /* @@ -123,7 +123,7 @@ pub unsafe fn c_vec_with_dtor(base: *mut T, len: uint, dtor: fn@()) */ pub fn get(t: CVec, ofs: uint) -> T { assert ofs < len(t); - return unsafe { *ptr::mut_offset((*t).base, ofs) }; + return unsafe { *ptr::mut_offset(t.base, ofs) }; } /** @@ -133,7 +133,7 @@ pub fn get(t: CVec, ofs: uint) -> T { */ pub fn set(t: CVec, ofs: uint, v: T) { assert ofs < len(t); - unsafe { *ptr::mut_offset((*t).base, ofs) = v }; + unsafe { *ptr::mut_offset(t.base, ofs) = v }; } /* @@ -141,14 +141,10 @@ pub fn set(t: CVec, ofs: uint, v: T) { */ /// Returns the length of the vector -pub pure fn len(t: CVec) -> uint { - return (*t).len; -} +pub pure fn len(t: CVec) -> uint { t.len } /// Returns a pointer to the first element of the vector -pub unsafe fn ptr(t: CVec) -> *mut T { - return (*t).base; -} +pub unsafe fn ptr(t: CVec) -> *mut T { t.base } #[cfg(test)] mod tests { diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 25deaf2a9b5..aaeecfb3302 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -84,22 +84,27 @@ pub mod reader { } } - fn vuint_at(data: &[u8], start: uint) -> {val: uint, next: uint} { + struct Res { + val: uint, + next: uint + } + + fn vuint_at(data: &[u8], start: uint) -> Res { let a = data[start]; if a & 0x80u8 != 0u8 { - return {val: (a & 0x7fu8) as uint, next: start + 1u}; + return Res {val: (a & 0x7fu8) as uint, next: start + 1u}; } if a & 0x40u8 != 0u8 { - return {val: ((a & 0x3fu8) as uint) << 8u | + return Res {val: ((a & 0x3fu8) as uint) << 8u | (data[start + 1u] as uint), next: start + 2u}; } else if a & 0x20u8 != 0u8 { - return {val: ((a & 0x1fu8) as uint) << 16u | + return Res {val: ((a & 0x1fu8) as uint) << 16u | (data[start + 1u] as uint) << 8u | (data[start + 2u] as uint), next: start + 3u}; } else if a & 0x10u8 != 0u8 { - return {val: ((a & 0x0fu8) as uint) << 24u | + return Res {val: ((a & 0x0fu8) as uint) << 24u | (data[start + 1u] as uint) << 16u | (data[start + 2u] as uint) << 8u | (data[start + 3u] as uint), diff --git a/src/libstd/md4.rs b/src/libstd/md4.rs index e1e2bb2697f..718e805b5d9 100644 --- a/src/libstd/md4.rs +++ b/src/libstd/md4.rs @@ -14,7 +14,14 @@ use core::str; use core::uint; use core::vec; -pub pure fn md4(msg: &[u8]) -> {a: u32, b: u32, c: u32, d: u32} { +struct Quad { + a: u32, + b: u32, + c: u32, + d: u32 +} + +pub pure 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. @@ -95,11 +102,11 @@ pub pure fn md4(msg: &[u8]) -> {a: u32, b: u32, c: u32, d: u32} { a += aa; b += bb; c += cc; d += dd; i += 64u; } - return {a: a, b: b, c: c, d: d}; + return Quad {a: a, b: b, c: c, d: d}; } pub pure fn md4_str(msg: &[u8]) -> ~str { - let {a, b, c, d} = md4(msg); + let Quad {a, b, c, d} = md4(msg); pure fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) { f(a); f(b); f(c); f(d); } diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs index a5c740c343c..5fb7d892c58 100644 --- a/src/libstd/sha1.rs +++ b/src/libstd/sha1.rs @@ -66,7 +66,7 @@ const k3: u32 = 0xCA62C1D6u32; /// Construct a `sha` object pub fn sha1() -> Sha1 { - type Sha1State = + struct Sha1State {h: ~[mut u32], mut len_low: u32, mut len_high: u32, @@ -258,7 +258,7 @@ pub fn sha1() -> Sha1 { return s; } } - let st = { + let st = Sha1State { h: vec::cast_to_mut(vec::from_elem(digest_buf_len, 0u32)), mut len_low: 0u32, mut len_high: 0u32, diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 65122bea750..a2fbc8b1db1 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -34,10 +34,6 @@ not required in or otherwise suitable for the core library. #[forbid(deprecated_pattern)]; #[allow(deprecated_self)]; - -// Transitional -#[legacy_records]; - #[no_core]; extern mod core(vers = "0.6"); diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 5a2693a42c1..4f0b7da89aa 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -92,7 +92,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes { }; let filter = - if vec::len(matches.free) > 0u { + if vec::len(matches.free) > 0 { option::Some(matches.free[0]) } else { option::None }; @@ -111,26 +111,27 @@ pub fn parse_opts(args: &[~str]) -> OptRes { #[deriving_eq] pub enum TestResult { TrOk, TrFailed, TrIgnored, } -type ConsoleTestState = - @{out: io::Writer, - log_out: Option, - use_color: bool, - mut total: uint, - mut passed: uint, - mut failed: uint, - mut ignored: uint, - mut failures: ~[TestDesc]}; +struct ConsoleTestState { + out: io::Writer, + log_out: Option, + use_color: bool, + mut total: uint, + mut passed: uint, + mut failed: uint, + mut ignored: uint, + mut failures: ~[TestDesc] +} // A simple console test runner pub fn run_tests_console(opts: &TestOpts, tests: &[TestDesc]) -> bool { - fn callback(event: &TestEvent, st: ConsoleTestState) { + fn callback(event: &TestEvent, st: @ConsoleTestState) { debug!("callback(event=%?)", event); match *event { TeFiltered(ref filtered_tests) => { st.total = filtered_tests.len(); - let noun = if st.total != 1u { ~"tests" } else { ~"test" }; + let noun = if st.total != 1 { ~"tests" } else { ~"test" }; st.out.write_line(fmt!("\nrunning %u %s", st.total, noun)); } TeWait(ref test) => st.out.write_str( @@ -142,18 +143,18 @@ pub fn run_tests_console(opts: &TestOpts, } match result { TrOk => { - st.passed += 1u; + st.passed += 1; write_ok(st.out, st.use_color); st.out.write_line(~""); } TrFailed => { - st.failed += 1u; + st.failed += 1; write_failed(st.out, st.use_color); st.out.write_line(~""); st.failures.push(move test); } TrIgnored => { - st.ignored += 1u; + st.ignored += 1; write_ignored(st.out, st.use_color); st.out.write_line(~""); } @@ -174,19 +175,19 @@ pub fn run_tests_console(opts: &TestOpts, }; let st = - @{out: io::stdout(), + @ConsoleTestState{out: io::stdout(), log_out: log_out, use_color: use_color(), - mut total: 0u, - mut passed: 0u, - mut failed: 0u, - mut ignored: 0u, + mut total: 0, + mut passed: 0, + mut failed: 0, + mut ignored: 0, mut failures: ~[]}; run_tests(opts, tests, |x| callback(&x, st)); assert (st.passed + st.failed + st.ignored == st.total); - let success = st.failed == 0u; + let success = st.failed == 0; if !success { print_failures(st); @@ -234,7 +235,7 @@ pub fn run_tests_console(opts: &TestOpts, } } -fn print_failures(st: ConsoleTestState) { +fn print_failures(st: @ConsoleTestState) { st.out.write_line(~"\nfailures:"); let failures = copy st.failures; let failures = vec::map(failures, |test| test.name); @@ -262,13 +263,13 @@ fn should_sort_failures_before_printing_them() { }; let st = - @{out: wr, + @ConsoleTestState{out: wr, log_out: option::None, use_color: false, - mut total: 0u, - mut passed: 0u, - mut failed: 0u, - mut ignored: 0u, + mut total: 0, + mut passed: 0, + mut failed: 0, + mut ignored: 0, mut failures: ~[move test_b, move test_a]}; print_failures(st); @@ -279,7 +280,7 @@ fn should_sort_failures_before_printing_them() { assert apos < bpos; } -fn use_color() -> bool { return get_concurrency() == 1u; } +fn use_color() -> bool { return get_concurrency() == 1; } enum TestEvent { TeFiltered(~[TestDesc]), @@ -334,7 +335,7 @@ fn run_tests(opts: &TestOpts, // Windows tends to dislike being overloaded with threads. #[cfg(windows)] -const sched_overcommit : uint = 1u; +const sched_overcommit : uint = 1; #[cfg(unix)] const sched_overcommit : uint = 4u; @@ -342,7 +343,7 @@ const sched_overcommit : uint = 4u; fn get_concurrency() -> uint { unsafe { let threads = rustrt::rust_sched_threads() as uint; - if threads == 1u { 1u } + if threads == 1 { 1 } else { threads * sched_overcommit } } } @@ -556,7 +557,7 @@ mod tests { ]; let filtered = filter_tests(&opts, tests); - assert (vec::len(filtered) == 1u); + assert (vec::len(filtered) == 1); assert (filtered[0].name == ~"1"); assert (filtered[0].ignore == false); } diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index 6fcbccf8183..fe4137f76be 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -27,19 +27,17 @@ use core::task::TaskBuilder; use core::task; /// Used to abstract-away direct interaction with a libuv loop. -pub enum IoTask { - IoTask_({ - async_handle: *ll::uv_async_t, - op_chan: SharedChan - }) +pub struct IoTask { + async_handle: *ll::uv_async_t, + op_chan: SharedChan } impl IoTask: Clone { fn clone(&self) -> IoTask { - IoTask_({ + IoTask{ async_handle: self.async_handle, op_chan: self.op_chan.clone() - }) + } } } @@ -131,10 +129,10 @@ fn run_loop(iotask_ch: &Chan) { // Send out a handle through which folks can talk to us // while we dwell in the I/O loop - let iotask = IoTask_({ + let iotask = IoTask{ async_handle: async_handle, op_chan: SharedChan(msg_ch) - }); + }; iotask_ch.send(iotask); log(debug, ~"about to run uv loop"); diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index 8bef6eb6c91..ca5a821921a 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -1543,7 +1543,7 @@ pub mod test { let continue_async_handle_ptr = ptr::addr_of(&continue_async_handle); let async_data = - { continue_chan: continue_chan }; + async_handle_data { continue_chan: continue_chan }; let async_data_ptr = ptr::addr_of(&async_data); let server_data = tcp_server_data { From 2f46b763da2c098913884f101b6d71d69af41b49 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 4 Feb 2013 17:41:43 -0800 Subject: [PATCH 16/37] core/syntax: Staging fixes --- src/libcore/pipes.rs | 18 ++---------------- src/libsyntax/ext/pipes/pipec.rs | 28 ---------------------------- 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 3e941da1247..947976e79af 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -143,8 +143,8 @@ pub fn BufferHeader() -> BufferHeader { // This is for protocols to associate extra data to thread around. #[doc(hidden)] #[cfg(stage0)] -#[cfg(stage1)] type Buffer = { header: BufferHeader, data: T }; +#[cfg(stage1)] #[cfg(stage2)] pub struct Buffer { header: BufferHeader, @@ -258,22 +258,8 @@ fn unibuffer() -> ~Buffer> { } move b } -#[cfg(stage1)] -fn unibuffer() -> ~Buffer> { - let b = ~{ - header: BufferHeader(), - data: Packet { - header: PacketHeader(), - payload: None, - } - }; - - unsafe { - b.data.header.buffer = reinterpret_cast(&b); - } - move b -} #[doc(hidden)] +#[cfg(stage1)] #[cfg(stage2)] fn unibuffer() -> ~Buffer> { let b = ~Buffer { diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index eec9c6eceaf..da0ac4e08ab 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -355,34 +355,6 @@ pub impl protocol: gen_init { })) } - #[cfg(stage0)] - fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr { - debug!("gen_init_bounded"); - let buffer_fields = self.gen_buffer_init(ext_cx); - let buffer = quote_expr!(~{ - header: ::pipes::BufferHeader(), - data: $buffer_fields, - }); - - let entangle_body = ext_cx.block_expr( - ext_cx.block( - self.states.map_to_vec( - |s| ext_cx.parse_stmt( - fmt!("data.%s.set_buffer(buffer)", - s.name))), - ext_cx.parse_expr( - fmt!("::ptr::addr_of(&(data.%s))", - self.states[0].name)))); - - quote_expr!({ - let buffer = $buffer; - do ::pipes::entangle_buffer(move buffer) |buffer, data| { - $entangle_body - } - }) - } - #[cfg(stage1)] - #[cfg(stage2)] fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr { debug!("gen_init_bounded"); let buffer_fields = self.gen_buffer_init(ext_cx); From 406a73fde27ac2352789ced88dad7e72e0e0d2e9 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 4 Feb 2013 11:14:33 -0500 Subject: [PATCH 17/37] Fix the each_storage() iterator on big bit vectors --- src/libstd/bitv.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index 0ad9d0af2ac..df0b36da77c 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -156,7 +156,7 @@ impl BigBitv { fn each_storage(op: fn(v: &mut uint) -> bool) { for uint::range(0, self.storage.len()) |i| { let mut w = self.storage[i]; - let b = !op(&mut w); + let b = op(&mut w); self.storage[i] = w; if !b { break; } } @@ -981,6 +981,24 @@ mod tests { assert !b1[40]; assert !b1[80]; } + + #[test] + pub fn test_small_clear() { + let b = Bitv(14, true); + b.clear(); + for b.ones |i| { + die!(fmt!("found 1 at %?", i)); + } + } + + #[test] + pub fn test_big_clear() { + let b = Bitv(140, true); + b.clear(); + for b.ones |i| { + die!(fmt!("found 1 at %?", i)); + } + } } // From abd29e5eadb46ec7d7126fa0438c1c52c4ace00f Mon Sep 17 00:00:00 2001 From: Zack Corr Date: Tue, 5 Feb 2013 22:56:40 +1000 Subject: [PATCH 18/37] core: Add a rand::Rand trait that is implemented by types that can be randomly generated Also adds Rng::gen() for generating any type that implements the Rand trait --- src/libcore/rand.rs | 100 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index 976c186912b..50232f99f85 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -23,6 +23,102 @@ use uint; use util; use vec; +/// A type that can be randomly generated using an RNG +pub trait Rand { + static fn rand(rng: rand::Rng) -> Self; +} + +impl int: Rand { + static fn rand(rng: rand::Rng) -> int { + rng.gen_int() + } +} + +impl i8: Rand { + static fn rand(rng: rand::Rng) -> i8 { + rng.gen_i8() + } +} + +impl i16: Rand { + static fn rand(rng: rand::Rng) -> i16 { + rng.gen_i16() + } +} + +impl i32: Rand { + static fn rand(rng: rand::Rng) -> i32 { + rng.gen_i32() + } +} + +impl i64: Rand { + static fn rand(rng: rand::Rng) -> i64 { + rng.gen_i64() + } +} + +impl u8: Rand { + static fn rand(rng: rand::Rng) -> u8 { + rng.gen_u8() + } +} + +impl u16: Rand { + static fn rand(rng: rand::Rng) -> u16 { + rng.gen_u16() + } +} + +impl u32: Rand { + static fn rand(rng: rand::Rng) -> u32 { + rng.gen_u32() + } +} + +impl u64: Rand { + static fn rand(rng: rand::Rng) -> u64 { + rng.gen_u64() + } +} + +impl float: Rand { + static fn rand(rng: rand::Rng) -> float { + rng.gen_float() + } +} + +impl f32: Rand { + static fn rand(rng: rand::Rng) -> f32 { + rng.gen_f32() + } +} + +impl f64: Rand { + static fn rand(rng: rand::Rng) -> f64 { + rng.gen_f64() + } +} + +impl char: Rand { + static fn rand(rng: rand::Rng) -> char { + rng.gen_char() + } +} + +impl bool: Rand { + static fn rand(rng: rand::Rng) -> bool { + rng.gen_bool() + } +} + +impl Option: Rand { + static fn rand(rng: rand::Rng) -> Option { + if rng.gen_bool() { Some(Rand::rand(rng)) } + else { None } + } +} + #[allow(non_camel_case_types)] // runtime type enum rctx {} @@ -49,6 +145,10 @@ pub struct Weighted { /// Extension methods for random number generators impl Rng { + /// Return a random value for a Rand type + fn gen() -> T { + Rand::rand(self) + } /// Return a random int fn gen_int() -> int { From b9a7d77529f24fe826fac711ad464599922a6fd0 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 5 Feb 2013 10:34:17 -0800 Subject: [PATCH 19/37] Register snapshots --- src/snapshots.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/snapshots.txt b/src/snapshots.txt index 3237c0b0268..a6ec0e499c7 100644 --- a/src/snapshots.txt +++ b/src/snapshots.txt @@ -1,3 +1,11 @@ +S 2013-02-04 2f46b76 + freebsd-x86_64 d33b5ebbf3335f6a8a5cc23572f630ad66539830 + linux-i386 7537519ae3de82592d6150b9ca81cd4bf45d9457 + linux-x86_64 17472c4ffa6a59a6dbf45158827992c4404f7d92 + macos-i386 a8473c209a199822f9bf0132449a8c38374d4d42 + macos-x86_64 3213a4166ee59dfb1167b9a31c64b747ce65884c + winnt-i386 74c718ee885193719afa2ae44f395399bf993dd3 + S 2013-01-23 e8f4da7 macos-i386 6860345b8d05986ae1b20c7532fd9667dff31b2a macos-x86_64 d0c6131e4afe93759af08d88e81cd7a8496595f0 From a4250a96fdf61142a9c8dbb6d37ae8435c99e396 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 5 Feb 2013 14:30:53 -0800 Subject: [PATCH 20/37] Revert "oldmap: use &K instead of K in find and get" This reverts commit 8e643525d4e5bca993dada43615916c382a0645b. --- src/libcargo/cargo.rc | 18 +-- src/librustc/back/link.rs | 2 +- src/librustc/driver/driver.rs | 2 +- src/librustc/lib/llvm.rs | 4 +- src/librustc/metadata/cstore.rs | 4 +- src/librustc/metadata/decoder.rs | 2 +- src/librustc/metadata/encoder.rs | 16 +-- src/librustc/metadata/tydecode.rs | 2 +- src/librustc/metadata/tyencode.rs | 4 +- src/librustc/middle/astencode.rs | 28 ++--- src/librustc/middle/borrowck/check_loans.rs | 20 ++-- src/librustc/middle/borrowck/gather_loans.rs | 8 +- src/librustc/middle/borrowck/loan.rs | 2 +- src/librustc/middle/borrowck/preserve.rs | 10 +- src/librustc/middle/check_const.rs | 8 +- src/librustc/middle/check_match.rs | 14 +-- src/librustc/middle/const_eval.rs | 6 +- src/librustc/middle/freevars.rs | 4 +- src/librustc/middle/kind.rs | 10 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/lint.rs | 6 +- src/librustc/middle/liveness.rs | 28 ++--- src/librustc/middle/mem_categorization.rs | 8 +- src/librustc/middle/moves.rs | 4 +- src/librustc/middle/pat_util.rs | 4 +- src/librustc/middle/privacy.rs | 12 +- src/librustc/middle/region.rs | 16 +-- src/librustc/middle/resolve.rs | 55 +++++---- src/librustc/middle/trans/_match.rs | 23 ++-- src/librustc/middle/trans/base.rs | 30 ++--- src/librustc/middle/trans/build.rs | 4 +- src/librustc/middle/trans/callee.rs | 8 +- src/librustc/middle/trans/closure.rs | 2 +- src/librustc/middle/trans/common.rs | 6 +- src/librustc/middle/trans/consts.rs | 12 +- src/librustc/middle/trans/controlflow.rs | 2 +- src/librustc/middle/trans/datum.rs | 4 +- src/librustc/middle/trans/debuginfo.rs | 18 +-- src/librustc/middle/trans/expr.rs | 18 +-- src/librustc/middle/trans/foreign.rs | 100 ++++++++--------- src/librustc/middle/trans/glue.rs | 2 +- src/librustc/middle/trans/inline.rs | 2 +- src/librustc/middle/trans/machine.rs | 2 +- src/librustc/middle/trans/meth.rs | 18 +-- src/librustc/middle/trans/monomorphize.rs | 6 +- src/librustc/middle/trans/reachable.rs | 12 +- src/librustc/middle/trans/reflect.rs | 2 +- src/librustc/middle/trans/type_of.rs | 2 +- src/librustc/middle/trans/type_use.rs | 12 +- src/librustc/middle/ty.rs | 56 +++++----- src/librustc/middle/typeck/astconv.rs | 6 +- src/librustc/middle/typeck/check/_match.rs | 10 +- src/librustc/middle/typeck/check/method.rs | 13 +-- src/librustc/middle/typeck/check/mod.rs | 48 ++++---- src/librustc/middle/typeck/check/regionck.rs | 6 +- src/librustc/middle/typeck/check/vtable.rs | 6 +- src/librustc/middle/typeck/check/writeback.rs | 4 +- src/librustc/middle/typeck/coherence.rs | 29 +++-- src/librustc/middle/typeck/collect.rs | 22 ++-- .../middle/typeck/infer/region_inference.rs | 2 +- src/librustc/middle/typeck/mod.rs | 4 +- src/librustc/util/ppaux.rs | 6 +- src/librustdoc/attr_pass.rs | 6 +- src/librustdoc/prune_hidden_pass.rs | 2 +- src/librustdoc/prune_private_pass.rs | 2 +- src/librustdoc/tystr_pass.rs | 14 +-- src/libstd/oldmap.rs | 105 +++++++++--------- src/libsyntax/ast_map.rs | 4 +- src/libsyntax/ext/expand.rs | 8 +- src/libsyntax/ext/tt/macro_rules.rs | 4 +- src/libsyntax/ext/tt/transcribe.rs | 2 +- src/libsyntax/util/interner.rs | 2 +- src/test/auxiliary/issue-2631-a.rs | 2 +- src/test/bench/core-map.rs | 4 +- src/test/bench/core-std.rs | 2 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 2 +- src/test/bench/shootout-mandelbrot.rs | 2 +- src/test/run-pass/hashmap-memory.rs | 4 +- 78 files changed, 479 insertions(+), 482 deletions(-) diff --git a/src/libcargo/cargo.rc b/src/libcargo/cargo.rc index cff44ed5ef2..960bcf88eb7 100644 --- a/src/libcargo/cargo.rc +++ b/src/libcargo/cargo.rc @@ -731,7 +731,7 @@ pub fn configure(opts: Options) -> Cargo { need_dir(&c.bindir); for sources.each_key_ref |&k| { - let mut s = sources.get(&k); + let mut s = sources.get(k); load_source_packages(&c, s); sources.insert(k, s); } @@ -981,7 +981,7 @@ pub fn install_named(c: &mut Cargo, wd: &Path, name: ~str) { pub fn install_uuid_specific(c: &mut Cargo, wd: &Path, src: ~str, uuid: ~str) { - match c.sources.find(&src) { + match c.sources.find(src) { Some(s) => { for s.packages.each |p| { if p.uuid == uuid { @@ -997,7 +997,7 @@ pub fn install_uuid_specific(c: &mut Cargo, wd: &Path, src: ~str, pub fn install_named_specific(c: &mut Cargo, wd: &Path, src: ~str, name: ~str) { - match c.sources.find(&src) { + match c.sources.find(src) { Some(s) => { for s.packages.each |p| { if p.name == name { @@ -1064,7 +1064,7 @@ pub fn cmd_uninstall(c: &Cargo) { } pub fn install_query(c: &mut Cargo, wd: &Path, target: ~str) { - match c.dep_cache.find(&target) { + match c.dep_cache.find(target) { Some(inst) => { if inst { return; @@ -1156,7 +1156,7 @@ pub fn cmd_install(c: &mut Cargo) { pub fn sync(c: &Cargo) { for c.sources.each_key_ref |&k| { - let mut s = c.sources.get(&k); + let mut s = c.sources.get(k); sync_one(c, s); c.sources.insert(k, s); } @@ -1558,7 +1558,7 @@ pub fn cmd_list(c: &Cargo) { if !valid_pkg_name(*name) { error(fmt!("'%s' is an invalid source name", *name)); } else { - match c.sources.find(name) { + match c.sources.find(*name) { Some(source) => { print_source(source); } @@ -1754,7 +1754,7 @@ pub fn cmd_sources(c: &Cargo) { return; } - match c.sources.find(&name) { + match c.sources.find(name) { Some(source) => { let old = copy source.url; let method = assume_source_method(url); @@ -1785,7 +1785,7 @@ pub fn cmd_sources(c: &Cargo) { return; } - match c.sources.find(&name) { + match c.sources.find(name) { Some(source) => { let old = copy source.method; @@ -1823,7 +1823,7 @@ pub fn cmd_sources(c: &Cargo) { return; } - match c.sources.find(&name) { + match c.sources.find(name) { Some(source) => { c.sources.remove(&name); c.sources.insert(newn, source); diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index de7c52520cc..22923cb7290 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -596,7 +596,7 @@ pub fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t, } pub fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> @str { - match ccx.type_hashcodes.find(&t) { + match ccx.type_hashcodes.find(t) { Some(h) => h, None => { let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta); diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 5bbf3f839ad..1464fa29afc 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -538,7 +538,7 @@ pub fn build_session_options(+binary: ~str, getopts::opt_strs(matches, level_name)); for flags.each |lint_name| { let lint_name = str::replace(*lint_name, ~"-", ~"_"); - match lint_dict.find(&lint_name) { + match lint_dict.find(/*bad*/ copy lint_name) { None => { early_error(demitter, fmt!("unknown %s flag: %s", level_name, lint_name)); diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 50f4fe43efd..e114a18f4fd 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -1331,11 +1331,11 @@ pub fn associate_type(tn: type_names, s: @str, t: TypeRef) { } pub fn type_has_name(tn: type_names, t: TypeRef) -> Option<@str> { - return tn.type_names.find(&t); + return tn.type_names.find(t); } pub fn name_has_type(tn: type_names, s: @str) -> Option { - return tn.named_types.find(&s); + return tn.named_types.find(s); } pub fn mk_type_names() -> type_names { diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index 1faf8e13fda..c8a1a619436 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -74,7 +74,7 @@ pub fn mk_cstore(intr: @ident_interner) -> CStore { pub fn get_crate_data(cstore: CStore, cnum: ast::crate_num) -> crate_metadata { - return p(cstore).metas.get(&cnum); + return p(cstore).metas.get(cnum); } pub fn get_crate_hash(cstore: CStore, cnum: ast::crate_num) -> ~str { @@ -139,7 +139,7 @@ pub fn add_use_stmt_cnum(cstore: CStore, use_id: ast::node_id, pub fn find_use_stmt_cnum(cstore: CStore, use_id: ast::node_id) -> Option { - p(cstore).use_crate_map.find(&use_id) + p(cstore).use_crate_map.find(use_id) } // returns hashes of crates directly used by this crate. Hashes are diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 9a6a2f7e954..c3c7c969cd8 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -1099,7 +1099,7 @@ pub fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id { return ast::def_id { crate: cdata.cnum, node: did.node }; } - match cdata.cnum_map.find(&did.crate) { + match cdata.cnum_map.find(did.crate) { option::Some(n) => ast::def_id { crate: n, node: did.node }, option::None => die!(~"didn't find a crate in the cnum_map") } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 072b974d042..438084a3bd7 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -118,7 +118,7 @@ pub fn encode_def_id(ebml_w: writer::Encoder, id: def_id) { fn encode_region_param(ecx: @encode_ctxt, ebml_w: writer::Encoder, it: @ast::item) { - let opt_rp = ecx.tcx.region_paramd_items.find(&it.id); + let opt_rp = ecx.tcx.region_paramd_items.find(it.id); for opt_rp.each |rp| { do ebml_w.wr_tag(tag_region_param) { (*rp).encode(&ebml_w); @@ -184,7 +184,7 @@ fn encode_ty_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt, fn encode_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt, params: &[ty_param]) { let ty_param_bounds = - @params.map(|param| ecx.tcx.ty_param_bounds.get(¶m.id)); + @params.map(|param| ecx.tcx.ty_param_bounds.get(param.id)); encode_ty_type_param_bounds(ebml_w, ecx, ty_param_bounds); } @@ -224,7 +224,7 @@ fn encode_type(ecx: @encode_ctxt, ebml_w: writer::Encoder, typ: ty::t) { fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) { ebml_w.start_tag(tag_items_data_item_symbol); - let sym = match ecx.item_symbols.find(&id) { + let sym = match ecx.item_symbols.find(id) { Some(ref x) => (/*bad*/copy *x), None => { ecx.diag.handler().bug( @@ -238,7 +238,7 @@ fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) { fn encode_discriminant(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) { ebml_w.start_tag(tag_items_data_item_symbol); - ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(&id))); + ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(id))); ebml_w.end_tag(); } @@ -349,7 +349,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder, // Encode the reexports of this module. debug!("(encoding info for module) encoding reexports for %d", id); - match ecx.reexports2.find(&id) { + match ecx.reexports2.find(id) { Some(ref exports) => { debug!("(encoding info for module) found reexports for %d", id); for (*exports).each |exp| { @@ -813,7 +813,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder, encode_name(ecx, ebml_w, ty_m.ident); encode_family(ebml_w, purity_static_method_family(ty_m.purity)); - let polyty = ecx.tcx.tcache.get(&local_def(ty_m.id)); + let polyty = ecx.tcx.tcache.get(local_def(ty_m.id)); encode_ty_type_param_bounds(ebml_w, ecx, polyty.bounds); encode_type(ecx, ebml_w, polyty.ty); let mut m_path = vec::append(~[], path); // :-( @@ -881,7 +881,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: writer::Encoder, let ebml_w = copy ebml_w; |i, cx, v| { visit::visit_item(i, cx, v); - match ecx.tcx.items.get(&i.id) { + match ecx.tcx.items.get(i.id) { ast_map::node_item(_, pt) => { encode_info_for_item(ecx, ebml_w, i, index, *pt); @@ -894,7 +894,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: writer::Encoder, let ebml_w = copy ebml_w; |ni, cx, v| { visit::visit_foreign_item(ni, cx, v); - match ecx.tcx.items.get(&ni.id) { + match ecx.tcx.items.get(ni.id) { ast_map::node_foreign_item(_, abi, pt) => { encode_info_for_foreign_item(ecx, ebml_w, ni, index, /*bad*/copy *pt, diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index ea13325ad49..5dd499dfd63 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -329,7 +329,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t { let len = parse_hex(st); assert (next(st) == '#'); let key = creader_cache_key { cnum: st.crate, pos: pos, len: len }; - match st.tcx.rcache.find(&key) { + match st.tcx.rcache.find(key) { Some(tt) => return tt, None => { let ps = @{pos: pos ,.. copy *st}; diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 0d66862c79f..a0e2065b20b 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -56,7 +56,7 @@ fn cx_uses_abbrevs(cx: @ctxt) -> bool { pub fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) { match cx.abbrevs { ac_no_abbrevs => { - let result_str = match cx.tcx.short_names_cache.find(&t) { + let result_str = match cx.tcx.short_names_cache.find(t) { Some(s) => /*bad*/copy *s, None => { let s = do io::with_str_writer |wr| { @@ -69,7 +69,7 @@ pub fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) { w.write_str(result_str); } ac_use_abbrevs(abbrevs) => { - match abbrevs.find(&t) { + match abbrevs.find(t) { Some(a) => { w.write_str(*a.s); return; } None => { let pos = w.tell(); diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 71599463382..2fc592e131e 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -838,7 +838,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, debug!("Encoding side tables for id %d", id); - do option::iter(&tcx.def_map.find(&id)) |def| { + do option::iter(&tcx.def_map.find(id)) |def| { do ebml_w.tag(c::tag_table_def) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -855,7 +855,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.node_type_substs.find(&id)) |tys| { + do option::iter(&tcx.node_type_substs.find(id)) |tys| { do ebml_w.tag(c::tag_table_node_type_subst) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -864,7 +864,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.freevars.find(&id)) |fv| { + do option::iter(&tcx.freevars.find(id)) |fv| { do ebml_w.tag(c::tag_table_freevars) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -876,7 +876,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } let lid = ast::def_id { crate: ast::local_crate, node: id }; - do option::iter(&tcx.tcache.find(&lid)) |tpbt| { + do option::iter(&tcx.tcache.find(lid)) |tpbt| { do ebml_w.tag(c::tag_table_tcache) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -885,7 +885,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.ty_param_bounds.find(&id)) |pbs| { + do option::iter(&tcx.ty_param_bounds.find(id)) |pbs| { do ebml_w.tag(c::tag_table_param_bounds) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -899,7 +899,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, // is what we actually use in trans, all modes will have been // resolved. // - //option::iter(tcx.inferred_modes.find(&id)) {|m| + //option::iter(tcx.inferred_modes.find(id)) {|m| // ebml_w.tag(c::tag_table_inferred_modes) {|| // ebml_w.id(id); // ebml_w.tag(c::tag_table_val) {|| @@ -908,13 +908,13 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, // } //} - do option::iter(&maps.mutbl_map.find(&id)) |_m| { + do option::iter(&maps.mutbl_map.find(id)) |_m| { do ebml_w.tag(c::tag_table_mutbl) { ebml_w.id(id); } } - do option::iter(&maps.last_use_map.find(&id)) |m| { + do option::iter(&maps.last_use_map.find(id)) |m| { do ebml_w.tag(c::tag_table_last_use) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -925,7 +925,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&maps.method_map.find(&id)) |mme| { + do option::iter(&maps.method_map.find(id)) |mme| { do ebml_w.tag(c::tag_table_method_map) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -934,7 +934,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&maps.vtable_map.find(&id)) |dr| { + do option::iter(&maps.vtable_map.find(id)) |dr| { do ebml_w.tag(c::tag_table_vtable_map) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -943,7 +943,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.adjustments.find(&id)) |adj| { + do option::iter(&tcx.adjustments.find(id)) |adj| { do ebml_w.tag(c::tag_table_adjustments) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -952,19 +952,19 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.legacy_boxed_traits.find(&id)) |_x| { + do option::iter(&tcx.legacy_boxed_traits.find(id)) |_x| { do ebml_w.tag(c::tag_table_legacy_boxed_trait) { ebml_w.id(id); } } - for maps.moves_map.find(&id).each |_| { + for maps.moves_map.find(id).each |_| { do ebml_w.tag(c::tag_table_moves_map) { ebml_w.id(id); } } - for maps.capture_map.find(&id).each |cap_vars| { + for maps.capture_map.find(id).each |cap_vars| { do ebml_w.tag(c::tag_table_capture_map) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 9b2d51289ad..19740b6a929 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -126,12 +126,12 @@ impl check_loan_ctxt { let region_map = self.tcx().region_map; let pure_map = self.req_maps.pure_map; loop { - match pure_map.find(&scope_id) { + match pure_map.find(scope_id) { None => (), Some(ref e) => return Some(pc_cmt((*e))) } - match region_map.find(&scope_id) { + match region_map.find(scope_id) { None => return default_purity, Some(next_scope_id) => scope_id = next_scope_id } @@ -144,13 +144,13 @@ impl check_loan_ctxt { let req_loan_map = self.req_maps.req_loan_map; loop { - for req_loan_map.find(&scope_id).each |loans| { + for req_loan_map.find(scope_id).each |loans| { for loans.each |loan| { if !f(loan) { return; } } } - match region_map.find(&scope_id) { + match region_map.find(scope_id) { None => return, Some(next_scope_id) => scope_id = next_scope_id, } @@ -199,7 +199,7 @@ impl check_loan_ctxt { Some(expr) => { match expr.node { ast::expr_path(_) if pc == pc_pure_fn => { - let def = self.tcx().def_map.get(&expr.id); + let def = self.tcx().def_map.get(expr.id); let did = ast_util::def_id_of_def(def); let is_fn_arg = did.crate == ast::local_crate && @@ -247,7 +247,7 @@ impl check_loan_ctxt { fn is_allowed_pure_arg(expr: @ast::expr) -> bool { return match expr.node { ast::expr_path(_) => { - let def = self.tcx().def_map.get(&expr.id); + let def = self.tcx().def_map.get(expr.id); let did = ast_util::def_id_of_def(def); did.crate == ast::local_crate && (*self.fn_args).contains(&(did.node)) @@ -262,14 +262,14 @@ impl check_loan_ctxt { fn check_for_conflicting_loans(scope_id: ast::node_id) { debug!("check_for_conflicting_loans(scope_id=%?)", scope_id); - let new_loans = match self.req_maps.req_loan_map.find(&scope_id) { + let new_loans = match self.req_maps.req_loan_map.find(scope_id) { None => return, Some(loans) => loans }; debug!("new_loans has length %?", new_loans.len()); - let par_scope_id = self.tcx().region_map.get(&scope_id); + let par_scope_id = self.tcx().region_map.get(scope_id); for self.walk_loans(par_scope_id) |old_loan| { debug!("old_loan=%?", self.bccx.loan_to_repr(old_loan)); @@ -325,7 +325,7 @@ impl check_loan_ctxt { fn check_assignment(at: assignment_type, ex: @ast::expr) { // We don't use cat_expr() here because we don't want to treat // auto-ref'd parameters in overloaded operators as rvalues. - let cmt = match self.bccx.tcx.adjustments.find(&ex.id) { + let cmt = match self.bccx.tcx.adjustments.find(ex.id) { None => self.bccx.cat_expr_unadjusted(ex), Some(adj) => self.bccx.cat_expr_autoderefd(ex, adj) }; @@ -612,7 +612,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk, { match fty_proto { ast::ProtoBox | ast::ProtoUniq => { - let cap_vars = self.bccx.capture_map.get(&id); + let cap_vars = self.bccx.capture_map.get(id); for cap_vars.each |cap_var| { match cap_var.mode { moves::CapRef | moves::CapCopy => { loop; } diff --git a/src/librustc/middle/borrowck/gather_loans.rs b/src/librustc/middle/borrowck/gather_loans.rs index 8029b4c2713..b7b99424924 100644 --- a/src/librustc/middle/borrowck/gather_loans.rs +++ b/src/librustc/middle/borrowck/gather_loans.rs @@ -126,7 +126,7 @@ fn req_loans_in_expr(ex: @ast::expr, // If this expression is borrowed, have to ensure it remains valid: if !self.ignore_adjustments.contains(&ex.id) { - for tcx.adjustments.find(&ex.id).each |adjustments| { + for tcx.adjustments.find(ex.id).each |adjustments| { self.guarantee_adjustments(ex, *adjustments); } } @@ -172,7 +172,7 @@ fn req_loans_in_expr(ex: @ast::expr, } } - match self.bccx.method_map.find(&ex.id) { + match self.bccx.method_map.find(ex.id) { Some(ref method_map_entry) => { match (*method_map_entry).explicit_self { ast::sty_by_ref => { @@ -250,7 +250,7 @@ fn req_loans_in_expr(ex: @ast::expr, // (if used like `a.b(...)`), the call where it's an argument // (if used like `x(a.b)`), or the block (if used like `let x // = a.b`). - let scope_r = ty::re_scope(self.tcx().region_map.get(&ex.id)); + let scope_r = ty::re_scope(self.tcx().region_map.get(ex.id)); let rcvr_cmt = self.bccx.cat_expr(rcvr); self.guarantee_valid(rcvr_cmt, m_imm, scope_r); visit::visit_expr(ex, self, vt); @@ -536,7 +536,7 @@ impl gather_loan_ctxt { fn add_loans_to_scope_id(&self, scope_id: ast::node_id, +loans: ~[Loan]) { debug!("adding %u loans to scope_id %?", loans.len(), scope_id); - match self.req_maps.req_loan_map.find(&scope_id) { + match self.req_maps.req_loan_map.find(scope_id) { Some(req_loans) => { req_loans.push_all(loans); } diff --git a/src/librustc/middle/borrowck/loan.rs b/src/librustc/middle/borrowck/loan.rs index 7248d29aa04..0b06fbd2a3a 100644 --- a/src/librustc/middle/borrowck/loan.rs +++ b/src/librustc/middle/borrowck/loan.rs @@ -129,7 +129,7 @@ impl LoanContext { ~"rvalue with a non-none lp"); } cat_local(local_id) | cat_arg(local_id) | cat_self(local_id) => { - let local_scope_id = self.tcx().region_map.get(&local_id); + let local_scope_id = self.tcx().region_map.get(local_id); self.issue_loan(cmt, ty::re_scope(local_scope_id), req_mutbl, owns_lent_data) } diff --git a/src/librustc/middle/borrowck/preserve.rs b/src/librustc/middle/borrowck/preserve.rs index 1946ba09ec7..3bc34d2ef29 100644 --- a/src/librustc/middle/borrowck/preserve.rs +++ b/src/librustc/middle/borrowck/preserve.rs @@ -109,7 +109,7 @@ impl PreserveCtxt { // Maybe if we pass in the parent instead here, // we can prevent the "scope not found" error debug!("scope_region thing: %? ", cmt.id); - ty::re_scope(self.tcx().region_map.get(&cmt.id)) + ty::re_scope(self.tcx().region_map.get(cmt.id)) }; self.compare_scope(cmt, scope_region) @@ -129,14 +129,14 @@ impl PreserveCtxt { cmt.span, ~"preserve() called with local and !root_managed_data"); } - let local_scope_id = self.tcx().region_map.get(&local_id); + let local_scope_id = self.tcx().region_map.get(local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } cat_binding(local_id) => { // Bindings are these kind of weird implicit pointers (cc // #2329). We require (in gather_loans) that they be // rooted in an immutable location. - let local_scope_id = self.tcx().region_map.get(&local_id); + let local_scope_id = self.tcx().region_map.get(local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } cat_arg(local_id) => { @@ -144,11 +144,11 @@ impl PreserveCtxt { // modes). In that case, the caller guarantees stability // for at least the scope of the fn. This is basically a // deref of a region ptr. - let local_scope_id = self.tcx().region_map.get(&local_id); + let local_scope_id = self.tcx().region_map.get(local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } cat_self(local_id) => { - let local_scope_id = self.tcx().region_map.get(&local_id); + let local_scope_id = self.tcx().region_map.get(local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } cat_comp(cmt_base, comp_field(*)) | diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 69ace0d7797..98c3fdaa8c3 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -126,7 +126,7 @@ pub fn check_expr(sess: Session, e.span, ~"paths in constants may only refer to \ items without type parameters"); } - match def_map.find(&e.id) { + match def_map.find(e.id) { Some(def_const(def_id)) | Some(def_fn(def_id, _)) | Some(def_variant(_, def_id)) | @@ -151,7 +151,7 @@ pub fn check_expr(sess: Session, } } expr_call(callee, _, false) => { - match def_map.find(&callee.id) { + match def_map.find(callee.id) { Some(def_struct(*)) => {} // OK. Some(def_variant(*)) => {} // OK. _ => { @@ -247,9 +247,9 @@ pub fn check_item_recursion(sess: Session, fn visit_expr(e: @expr, &&env: env, v: visit::vt) { match e.node { expr_path(*) => { - match env.def_map.find(&e.id) { + match env.def_map.find(e.id) { Some(def_const(def_id)) => { - match env.ast_map.get(&def_id.node) { + match env.ast_map.get(def_id.node) { ast_map::node_item(it, _) => { (v.visit_item)(it, env, v); } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 978aaacb18a..e25ceee5d30 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -292,7 +292,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option { match /*bad*/copy pat.node { pat_wild => { None } pat_ident(_, _, _) | pat_enum(_, _) => { - match cx.tcx.def_map.find(&pat.id) { + match cx.tcx.def_map.find(pat.id) { Some(def_variant(_, id)) => Some(variant(id)), Some(def_const(did)) => { let const_expr = lookup_const_by_id(cx.tcx, did).get(); @@ -306,7 +306,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option { Some(range(eval_const_expr(cx.tcx, lo), eval_const_expr(cx.tcx, hi))) } pat_struct(*) => { - match cx.tcx.def_map.find(&pat.id) { + match cx.tcx.def_map.find(pat.id) { Some(def_variant(_, id)) => Some(variant(id)), _ => Some(single) } @@ -329,7 +329,7 @@ pub fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool { match pat.node { pat_wild => { true } pat_ident(_, _, _) => { - match cx.tcx.def_map.find(&pat.id) { + match cx.tcx.def_map.find(pat.id) { Some(def_variant(_, _)) | Some(def_const(*)) => { false } _ => { true } } @@ -480,7 +480,7 @@ pub fn specialize(cx: @MatchCheckCtxt, pat_wild => Some(vec::append(vec::from_elem(arity, wild()), vec::tail(r))), pat_ident(_, _, _) => { - match cx.tcx.def_map.find(&pat_id) { + match cx.tcx.def_map.find(pat_id) { Some(def_variant(_, id)) => { if variant(id) == ctor_id { Some(vec::tail(r)) } else { None } @@ -505,7 +505,7 @@ pub fn specialize(cx: @MatchCheckCtxt, } } pat_enum(_, args) => { - match cx.tcx.def_map.get(&pat_id) { + match cx.tcx.def_map.get(pat_id) { def_variant(_, id) if variant(id) == ctor_id => { let args = match args { Some(args) => args, @@ -541,7 +541,7 @@ pub fn specialize(cx: @MatchCheckCtxt, } pat_struct(_, ref flds, _) => { // Is this a struct or an enum variant? - match cx.tcx.def_map.get(&pat_id) { + match cx.tcx.def_map.get(pat_id) { def_variant(_, variant_id) => { if variant(variant_id) == ctor_id { // FIXME #4731: Is this right? --pcw @@ -678,7 +678,7 @@ pub fn check_fn(cx: @MatchCheckCtxt, } pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool { - match cx.tcx.def_map.find(&pat.id) { + match cx.tcx.def_map.find(pat.id) { Some(def_variant(enum_id, _)) => { if vec::len(*ty::enum_variants(cx.tcx, enum_id)) != 1u { return true; diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index e01595d8d93..f917964d234 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -78,7 +78,7 @@ pub fn classify(e: @expr, tcx: ty::ctxt) -> constness { let did = ast_util::local_def(e.id); - match tcx.ccache.find(&did) { + match tcx.ccache.find(did) { Some(x) => x, None => { let cn = @@ -170,7 +170,7 @@ pub fn classify(e: @expr, } pub fn lookup_const(tcx: ty::ctxt, e: @expr) -> Option<@expr> { - match tcx.def_map.find(&e.id) { + match tcx.def_map.find(e.id) { Some(ast::def_const(def_id)) => lookup_const_by_id(tcx, def_id), _ => None } @@ -180,7 +180,7 @@ pub fn lookup_const_by_id(tcx: ty::ctxt, def_id: ast::def_id) -> Option<@expr> { if ast_util::is_local(def_id) { - match tcx.items.find(&def_id.node) { + match tcx.items.find(def_id.node) { None => None, Some(ast_map::node_item(it, _)) => match it.node { item_const(_, const_expr) => Some(const_expr), diff --git a/src/librustc/middle/freevars.rs b/src/librustc/middle/freevars.rs index 5d65aba2a4d..1e9d8c9c08e 100644 --- a/src/librustc/middle/freevars.rs +++ b/src/librustc/middle/freevars.rs @@ -58,7 +58,7 @@ fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk) } ast::expr_path(*) => { let mut i = 0; - match def_map.find(&expr.id) { + match def_map.find(expr.id) { None => die!(~"path not found"), Some(df) => { let mut def = df; @@ -118,7 +118,7 @@ pub fn annotate_freevars(def_map: resolve::DefMap, crate: @ast::crate) -> } pub fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info { - match tcx.freevars.find(&fid) { + match tcx.freevars.find(fid) { None => die!(~"get_freevars: " + int::str(fid) + ~" has no freevars"), Some(d) => return d } diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 8abafe6b079..09232a2a0c5 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -195,10 +195,10 @@ pub fn check_expr(e: @expr, cx: ctx, v: visit::vt) { expr_unary(*)|expr_binary(*)|expr_method_call(*) => e.callee_id, _ => e.id }; - do option::iter(&cx.tcx.node_type_substs.find(&type_parameter_id)) |ts| { + do option::iter(&cx.tcx.node_type_substs.find(type_parameter_id)) |ts| { let bounds = match e.node { expr_path(_) => { - let did = ast_util::def_id_of_def(cx.tcx.def_map.get(&e.id)); + let did = ast_util::def_id_of_def(cx.tcx.def_map.get(e.id)); ty::lookup_item_type(cx.tcx, did).bounds } _ => { @@ -292,8 +292,8 @@ pub fn check_expr(e: @expr, cx: ctx, v: visit::vt) { fn check_ty(aty: @Ty, cx: ctx, v: visit::vt) { match aty.node { ty_path(_, id) => { - do option::iter(&cx.tcx.node_type_substs.find(&id)) |ts| { - let did = ast_util::def_id_of_def(cx.tcx.def_map.get(&id)); + do option::iter(&cx.tcx.node_type_substs.find(id)) |ts| { + let did = ast_util::def_id_of_def(cx.tcx.def_map.get(id)); let bounds = ty::lookup_item_type(cx.tcx, did).bounds; for vec::each2(*ts, *bounds) |ty, bound| { check_bounds(cx, aty.id, aty.span, *ty, *bound) @@ -334,7 +334,7 @@ pub fn check_bounds(cx: ctx, id: node_id, sp: span, fn is_nullary_variant(cx: ctx, ex: @expr) -> bool { match ex.node { expr_path(_) => { - match cx.tcx.def_map.get(&ex.id) { + match cx.tcx.def_map.get(ex.id) { def_variant(edid, vdid) => { vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index b4500f87eb0..3eb65505e64 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -352,7 +352,7 @@ impl LanguageItemCollector { return; // Didn't match. } - match self.item_refs.find(&value) { + match self.item_refs.find(/*bad*/copy value) { None => { // Didn't match. } diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 4601941f73a..0dc7a746e9e 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -265,7 +265,7 @@ pub fn get_lint_settings_level(settings: lint_settings, _expr_id: ast::node_id, item_id: ast::node_id) -> level { - match settings.settings_map.find(&item_id) { + match settings.settings_map.find(item_id) { Some(modes) => get_lint_level(modes, lint_mode), None => get_lint_level(settings.default_settings, lint_mode) } @@ -346,7 +346,7 @@ impl ctxt { for triples.each |pair| { let (meta, level, lintname) = /*bad*/copy *pair; - match self.dict.find(&lintname) { + match self.dict.find(/*bad*/ copy lintname) { None => { self.span_lint( new_ctxt.get_level(unrecognized_lint), @@ -684,7 +684,7 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { for vec::each(vec::append_one(tys, decl.output)) |ty| { match ty.node { ast::ty_path(_, id) => { - match cx.def_map.get(&id) { + match cx.def_map.get(id) { ast::def_prim_ty(ast::ty_int(ast::ty_i)) => { cx.sess.span_lint( ctypes, id, fn_id, diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 9240bc5fbc8..c13af3a32f2 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -368,7 +368,7 @@ impl IrMaps { } fn variable(node_id: node_id, span: span) -> Variable { - match self.variable_map.find(&node_id) { + match self.variable_map.find(node_id) { Some(var) => var, None => { self.tcx.sess.span_bug( @@ -390,7 +390,7 @@ impl IrMaps { } fn captures(expr: @expr) -> @~[CaptureInfo] { - match self.capture_info_map.find(&expr.id) { + match self.capture_info_map.find(expr.id) { Some(caps) => caps, None => { self.tcx.sess.span_bug(expr.span, ~"no registered caps"); @@ -410,7 +410,7 @@ impl IrMaps { Local(LocalInfo {id: id, kind: FromLetNoInitializer, _}) | Local(LocalInfo {id: id, kind: FromLetWithInitializer, _}) | Local(LocalInfo {id: id, kind: FromMatch(_), _}) => { - let v = match self.last_use_map.find(&expr_id) { + let v = match self.last_use_map.find(expr_id) { Some(v) => v, None => { let v = @DVec(); @@ -552,7 +552,7 @@ fn visit_expr(expr: @expr, &&self: @IrMaps, vt: vt<@IrMaps>) { match expr.node { // live nodes required for uses or definitions of variables: expr_path(_) => { - let def = self.tcx.def_map.get(&expr.id); + let def = self.tcx.def_map.get(expr.id); debug!("expr %d: path that leads to %?", expr.id, def); if relevant_def(def).is_some() { self.add_live_node_for_node(expr.id, ExprNode(expr.span)); @@ -569,7 +569,7 @@ fn visit_expr(expr: @expr, &&self: @IrMaps, vt: vt<@IrMaps>) { // being the location that the variable is used. This results // in better error messages than just pointing at the closure // construction site. - let cvs = self.capture_map.get(&expr.id); + let cvs = self.capture_map.get(expr.id); let mut call_caps = ~[]; for cvs.each |cv| { match relevant_def(cv.def) { @@ -685,7 +685,7 @@ fn Liveness(ir: @IrMaps, specials: Specials) -> Liveness { impl Liveness { fn live_node(node_id: node_id, span: span) -> LiveNode { - match self.ir.live_node_map.find(&node_id) { + match self.ir.live_node_map.find(node_id) { Some(ln) => ln, None => { // This must be a mismatch between the ir_map construction @@ -702,7 +702,7 @@ impl Liveness { fn variable_from_path(expr: @expr) -> Option { match expr.node { expr_path(_) => { - let def = self.tcx.def_map.get(&expr.id); + let def = self.tcx.def_map.get(expr.id); relevant_def(def).map( |rdef| self.variable(*rdef, expr.span) ) @@ -717,7 +717,7 @@ impl Liveness { fn variable_from_def_map(node_id: node_id, span: span) -> Option { - match self.tcx.def_map.find(&node_id) { + match self.tcx.def_map.find(node_id) { Some(def) => { relevant_def(def).map( |rdef| self.variable(*rdef, span) @@ -837,7 +837,7 @@ impl Liveness { match opt_label { Some(_) => // Refers to a labeled loop. Use the results of resolve // to find with one - match self.tcx.def_map.find(&id) { + match self.tcx.def_map.find(id) { Some(def_label(loop_id)) => loop_id, _ => self.tcx.sess.span_bug(sp, ~"Label on break/loop \ doesn't refer to a loop") @@ -1203,7 +1203,7 @@ impl Liveness { // Now that we know the label we're going to, // look it up in the break loop nodes table - match self.break_ln.find(&sc) { + match self.break_ln.find(sc) { Some(b) => b, None => self.tcx.sess.span_bug(expr.span, ~"Break to unknown label") @@ -1217,7 +1217,7 @@ impl Liveness { // Now that we know the label we're going to, // look it up in the continue loop nodes table - match self.cont_ln.find(&sc) { + match self.cont_ln.find(sc) { Some(b) => b, None => self.tcx.sess.span_bug(expr.span, ~"Loop to unknown label") @@ -1424,7 +1424,7 @@ impl Liveness { } fn access_path(expr: @expr, succ: LiveNode, acc: uint) -> LiveNode { - let def = self.tcx.def_map.get(&expr.id); + let def = self.tcx.def_map.get(expr.id); match relevant_def(def) { Some(nid) => { let ln = self.live_node(expr.id, expr.span); @@ -1560,7 +1560,7 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) { let ln = self.live_node(expr.id, expr.span); self.consider_last_use(expr, ln, *var); - match self.ir.variable_moves_map.find(&expr.id) { + match self.ir.variable_moves_map.find(expr.id) { None => {} Some(entire_expr) => { debug!("(checking expr) is a move: `%s`", @@ -1689,7 +1689,7 @@ impl @Liveness { fn check_lvalue(expr: @expr, vt: vt<@Liveness>) { match expr.node { expr_path(_) => { - match self.tcx.def_map.get(&expr.id) { + match self.tcx.def_map.get(expr.id) { def_local(nid, false) => { // Assignment to an immutable variable or argument: // only legal if there is no later assignment. diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index abe8a64fea5..94fc63b75dd 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -308,7 +308,7 @@ pub struct mem_categorization_ctxt { pub impl &mem_categorization_ctxt { fn cat_expr(expr: @ast::expr) -> cmt { - match self.tcx.adjustments.find(&expr.id) { + match self.tcx.adjustments.find(expr.id) { None => { // No adjustments. self.cat_expr_unadjusted(expr) @@ -375,7 +375,7 @@ pub impl &mem_categorization_ctxt { } ast::expr_path(_) => { - let def = self.tcx.def_map.get(&expr.id); + let def = self.tcx.def_map.get(expr.id); self.cat_def(expr.id, expr.span, expr_ty, def) } @@ -840,7 +840,7 @@ pub impl &mem_categorization_ctxt { // variant(*) } ast::pat_enum(_, Some(ref subpats)) => { - match self.tcx.def_map.find(&pat.id) { + match self.tcx.def_map.find(pat.id) { Some(ast::def_variant(enum_did, _)) => { // variant(x, y, z) for subpats.each |subpat| { @@ -1063,7 +1063,7 @@ pub fn field_mutbl(tcx: ty::ctxt, } } ty::ty_enum(*) => { - match tcx.def_map.get(&node_id) { + match tcx.def_map.get(node_id) { ast::def_variant(_, variant_id) => { for ty::lookup_struct_fields(tcx, variant_id).each |fld| { if fld.ident == f_name { diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index f7943d6edc0..8adebdb4582 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -409,7 +409,7 @@ impl VisitContext { // `expr_mode` refers to the post-adjustment value. If one of // those adjustments is to take a reference, then it's only // reading the underlying expression, not moving it. - let comp_mode = match self.tcx.adjustments.find(&expr.id) { + let comp_mode = match self.tcx.adjustments.find(expr.id) { Some(adj) if adj.autoref.is_some() => Read, _ => expr_mode.component_mode(expr) }; @@ -713,7 +713,7 @@ impl VisitContext { receiver_expr: @expr, visitor: vt) { - let callee_mode = match self.method_map.find(&expr_id) { + let callee_mode = match self.method_map.find(expr_id) { Some(ref method_map_entry) => { match method_map_entry.explicit_self { sty_by_ref => by_ref, diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index 823af16c605..c39d750a581 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -35,7 +35,7 @@ pub fn pat_id_map(dm: resolve::DefMap, pat: @pat) -> PatIdMap { pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool { match pat.node { pat_enum(_, _) | pat_ident(_, _, None) | pat_struct(*) => { - match dm.find(&pat.id) { + match dm.find(pat.id) { Some(def_variant(*)) | Some(def_struct(*)) => true, _ => false } @@ -47,7 +47,7 @@ pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool { pub fn pat_is_const(dm: resolve::DefMap, pat: &pat) -> bool { match pat.node { pat_ident(_, _, None) => { - match dm.find(&pat.id) { + match dm.find(pat.id) { Some(def_const(*)) => true, _ => false } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 3ec1cf3a705..482f01f7201 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -105,7 +105,7 @@ pub fn check_crate(tcx: ty::ctxt, match *origin { method_static(method_id) => { if method_id.crate == local_crate { - match tcx.items.find(&method_id.node) { + match tcx.items.find(method_id.node) { Some(node_method(method, impl_id, _)) => { if method.vis == private && (impl_id.crate != local_crate || @@ -143,7 +143,7 @@ pub fn check_crate(tcx: ty::ctxt, method_self(trait_id, method_num) | method_super(trait_id, method_num) => { if trait_id.crate == local_crate { - match tcx.items.find(&trait_id.node) { + match tcx.items.find(trait_id.node) { Some(node_item(item, _)) => { match item.node { item_trait(_, _, ref methods) => { @@ -221,7 +221,7 @@ pub fn check_crate(tcx: ty::ctxt, ty_struct(id, _) if id.crate != local_crate || !privileged_items.contains(&(id.node)) => { - match method_map.find(&expr.id) { + match method_map.find(expr.id) { None => { debug!("(privacy checking) checking \ field access"); @@ -244,7 +244,7 @@ pub fn check_crate(tcx: ty::ctxt, ty_struct(id, _) if id.crate != local_crate || !privileged_items.contains(&(id.node)) => { - match method_map.find(&expr.id) { + match method_map.find(expr.id) { None => { tcx.sess.span_bug(expr.span, ~"method call not in \ @@ -276,7 +276,7 @@ pub fn check_crate(tcx: ty::ctxt, ty_enum(id, _) => { if id.crate != local_crate || !privileged_items.contains(&(id.node)) { - match tcx.def_map.get(&expr.id) { + match tcx.def_map.get(expr.id) { def_variant(_, variant_id) => { for (*fields).each |field| { debug!("(privacy checking) \ @@ -343,7 +343,7 @@ pub fn check_crate(tcx: ty::ctxt, if enum_id.crate != local_crate || !privileged_items.contains( &enum_id.node) { - match tcx.def_map.find(&pattern.id) { + match tcx.def_map.find(pattern.id) { Some(def_variant(_, variant_id)) => { for fields.each |field| { debug!("(privacy checking) \ diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 867cc7c686f..4602d2aff4e 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -115,7 +115,7 @@ pub fn scope_contains(region_map: region_map, superscope: ast::node_id, subscope: ast::node_id) -> bool { let mut subscope = subscope; while superscope != subscope { - match region_map.find(&subscope) { + match region_map.find(subscope) { None => return false, Some(scope) => subscope = scope } @@ -159,7 +159,7 @@ pub fn nearest_common_ancestor(region_map: region_map, let mut result = ~[scope]; let mut scope = scope; loop { - match region_map.find(&scope) { + match region_map.find(scope) { None => return result, Some(superscope) => { result.push(superscope); @@ -237,7 +237,7 @@ pub fn resolve_arm(arm: ast::arm, cx: ctxt, visitor: visit::vt) { pub fn resolve_pat(pat: @ast::pat, cx: ctxt, visitor: visit::vt) { match pat.node { ast::pat_ident(*) => { - let defn_opt = cx.def_map.find(&pat.id); + let defn_opt = cx.def_map.find(pat.id); match defn_opt { Some(ast::def_variant(_,_)) => { /* Nothing to do; this names a variant. */ @@ -475,7 +475,7 @@ pub impl determine_rp_ctxt { /// the new variance is joined with the old variance. fn add_rp(id: ast::node_id, variance: region_variance) { assert id != 0; - let old_variance = self.region_paramd_items.find(&id); + let old_variance = self.region_paramd_items.find(id); let joined_variance = match old_variance { None => variance, Some(v) => join_variance(v, variance) @@ -505,7 +505,7 @@ pub impl determine_rp_ctxt { ast_map::node_id_to_str(self.ast_map, self.item_id, self.sess.parse_sess.interner), copy self.ambient_variance); - let vec = match self.dep_map.find(&from) { + let vec = match self.dep_map.find(from) { Some(vec) => vec, None => { let vec = @DVec(); @@ -685,7 +685,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty, // that as a direct dependency. match ty.node { ast::ty_path(path, id) => { - match cx.def_map.find(&id) { + match cx.def_map.find(id) { Some(ast::def_ty(did)) | Some(ast::def_struct(did)) => { if did.crate == ast::local_crate { if cx.opt_region_is_relevant(path.rp) { @@ -818,9 +818,9 @@ pub fn determine_rp_in_crate(sess: Session, // update the region-parameterization of D to reflect the result. while cx.worklist.len() != 0 { let c_id = cx.worklist.pop(); - let c_variance = cx.region_paramd_items.get(&c_id); + let c_variance = cx.region_paramd_items.get(c_id); debug!("popped %d from worklist", c_id); - match cx.dep_map.find(&c_id) { + match cx.dep_map.find(c_id) { None => {} Some(deps) => { for deps.each |dep| { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index c647e4db262..c40b6df6926 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -947,7 +947,7 @@ pub impl Resolver { // Add or reuse the child. let new_parent = ModuleReducedGraphParent(module_); - match module_.children.find(&name) { + match module_.children.find(name) { None => { let child = @NameBindings(); module_.children.insert(name, child); @@ -1558,7 +1558,7 @@ pub impl Resolver { %s", final_ident); let parent_link = self.get_parent_link(new_parent, ident); - match modules.find(&def_id) { + match modules.find(def_id) { None => { child_name_bindings.define_module(Public, parent_link, @@ -1582,8 +1582,7 @@ pub impl Resolver { die!(~"can't happen"); } ModuleParentLink(parent_module, ident) => { - let name_bindings = parent_module.children.get( - &ident); + let name_bindings = parent_module.children.get(ident); resolution.type_target = Some(Target(parent_module, name_bindings)); } @@ -1842,7 +1841,7 @@ pub impl Resolver { self.idents_to_str(module_path.get()), self.session.str_of(target)); - match module_.import_resolutions.find(&target) { + match module_.import_resolutions.find(target) { Some(resolution) => { debug!("(building import directive) bumping \ reference"); @@ -2113,7 +2112,7 @@ pub impl Resolver { let mut type_result = UnknownResult; // Search for direct children of the containing module. - match containing_module.children.find(&source) { + match containing_module.children.find(source) { None => { // Continue. } @@ -2149,7 +2148,7 @@ pub impl Resolver { // Now search the exported imports within the containing // module. - match containing_module.import_resolutions.find(&source) { + match containing_module.import_resolutions.find(source) { None => { // The containing module definitely doesn't have an // exported import with the name in question. We can @@ -2213,7 +2212,7 @@ pub impl Resolver { // We've successfully resolved the import. Write the results in. assert module_.import_resolutions.contains_key_ref(&target); - let import_resolution = module_.import_resolutions.get(&target); + let import_resolution = module_.import_resolutions.get(target); match value_result { BoundResult(target_module, name_bindings) => { @@ -2298,7 +2297,7 @@ pub impl Resolver { let mut module_result = UnknownResult; // Search for direct children of the containing module. - match containing_module.children.find(&source) { + match containing_module.children.find(source) { None => { // Continue. } @@ -2328,7 +2327,7 @@ pub impl Resolver { // Now search the exported imports within the containing // module. - match containing_module.import_resolutions.find(&source) { + match containing_module.import_resolutions.find(source) { None => { // The containing module definitely doesn't have an // exported import with the name in question. We can @@ -2372,7 +2371,7 @@ pub impl Resolver { // We've successfully resolved the import. Write the results in. assert module_.import_resolutions.contains_key_ref(&target); - let import_resolution = module_.import_resolutions.get(&target); + let import_resolution = module_.import_resolutions.get(target); match module_result { BoundResult(target_module, name_bindings) => { @@ -2440,7 +2439,7 @@ pub impl Resolver { self.module_to_str(module_)); // Here we merge two import resolutions. - match module_.import_resolutions.find(&ident) { + match module_.import_resolutions.find(ident) { None => { // Simple: just copy the old import resolution. let new_import_resolution = @@ -2483,7 +2482,7 @@ pub impl Resolver { // Add all children from the containing module. for containing_module.children.each_ref |&ident, &name_bindings| { let mut dest_import_resolution; - match module_.import_resolutions.find(&ident) { + match module_.import_resolutions.find(ident) { None => { // Create a new import resolution from this child. dest_import_resolution = @ImportResolution(privacy, span); @@ -2687,7 +2686,7 @@ pub impl Resolver { // The current module node is handled specially. First, check for // its immediate children. - match module_.children.find(&name) { + match module_.children.find(name) { Some(name_bindings) if (*name_bindings).defined_in_namespace(namespace) => { return Success(Target(module_, name_bindings)); @@ -2700,7 +2699,7 @@ pub impl Resolver { // adjacent import statements are processed as though they mutated the // current scope. - match module_.import_resolutions.find(&name) { + match module_.import_resolutions.find(name) { None => { // Not found; continue. } @@ -2924,7 +2923,7 @@ pub impl Resolver { self.module_to_str(module_)); // First, check the direct children of the module. - match module_.children.find(&name) { + match module_.children.find(name) { Some(name_bindings) if (*name_bindings).defined_in_namespace(namespace) => { @@ -2945,7 +2944,7 @@ pub impl Resolver { } // Otherwise, we check the list of resolved imports. - match module_.import_resolutions.find(&name) { + match module_.import_resolutions.find(name) { Some(import_resolution) => { if import_resolution.outstanding_references != 0 { debug!("(resolving name in module) import unresolved; \ @@ -3115,7 +3114,7 @@ pub impl Resolver { } // Otherwise, proceed and write in the bindings. - match module_.import_resolutions.find(&target_name) { + match module_.import_resolutions.find(target_name) { None => { die!(~"(resolving one-level renaming import) reduced graph \ construction or glob importing should have created the \ @@ -3329,7 +3328,7 @@ pub impl Resolver { // Nothing to do. } Some(name) => { - match orig_module.children.find(&name) { + match orig_module.children.find(name) { None => { debug!("!!! (with scope) didn't find `%s` in `%s`", self.session.str_of(name), @@ -3406,7 +3405,7 @@ pub impl Resolver { // If the def is a ty param, and came from the parent // item, it's ok match def { - def_ty_param(did, _) if self.def_map.find(&did.node) + def_ty_param(did, _) if self.def_map.find(copy(did.node)) == Some(def_typaram_binder(item_id)) => { // ok } @@ -3478,7 +3477,7 @@ pub impl Resolver { while i != 0 { i -= 1; let rib = (*ribs).get_elt(i); - match rib.bindings.find(&name) { + match rib.bindings.find(name) { Some(def_like) => { return self.upvarify(ribs, i, def_like, span, allow_capturing_self); @@ -4070,7 +4069,7 @@ pub impl Resolver { let map_i = self.binding_mode_map(*p); for map_0.each_ref |&key, &binding_0| { - match map_i.find(&key) { + match map_i.find(key) { None => { self.session.span_err( p.span, @@ -4127,7 +4126,7 @@ pub impl Resolver { // Move down in the graph, if there's an anonymous module rooted here. let orig_module = self.current_module; - match self.current_module.anonymous_children.find(&block.node.id) { + match self.current_module.anonymous_children.find(block.node.id) { None => { /* Nothing to do. */ } Some(anonymous_module) => { debug!("(resolving block) found anonymous module, moving \ @@ -4162,7 +4161,7 @@ pub impl Resolver { match self.primitive_type_table .primitive_types - .find(&name) { + .find(name) { Some(primitive_type) => { result_def = @@ -4328,7 +4327,7 @@ pub impl Resolver { bindings_list.insert(ident, pat_id); } Some(b) => { - if b.find(&ident) == Some(pat_id) { + if b.find(ident) == Some(pat_id) { // Then this is a duplicate variable // in the same disjunct, which is an // error @@ -4527,7 +4526,7 @@ pub impl Resolver { -> NameDefinition { // First, search children. - match containing_module.children.find(&name) { + match containing_module.children.find(name) { Some(child_name_bindings) => { match (child_name_bindings.def_for_namespace(namespace), child_name_bindings.privacy_for_namespace(namespace)) { @@ -4550,7 +4549,7 @@ pub impl Resolver { } // Next, search import resolutions. - match containing_module.import_resolutions.find(&name) { + match containing_module.import_resolutions.find(name) { Some(import_resolution) if import_resolution.privacy == Public || xray == Xray => { match (*import_resolution).target_for_namespace(namespace) { @@ -5077,7 +5076,7 @@ pub impl Resolver { trait_def_id.node, self.session.str_of(name)); - match self.trait_info.find(&trait_def_id) { + match self.trait_info.find(trait_def_id) { Some(trait_info) if trait_info.contains_key_ref(&name) => { debug!("(adding trait info if containing method) found trait \ %d:%d for method '%s'", diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 7dca4174019..6913cf8e2f5 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -282,7 +282,7 @@ pub fn trans_opt(bcx: block, o: &Opt) -> opt_result { } pub fn variant_opt(tcx: ty::ctxt, pat_id: ast::node_id) -> Opt { - match tcx.def_map.get(&pat_id) { + match tcx.def_map.get(pat_id) { ast::def_variant(enum_id, var_id) => { let variants = ty::enum_variants(tcx, enum_id); for vec::each(*variants) |v| { @@ -377,7 +377,7 @@ pub fn expand_nested_bindings(bcx: block, m: &[@Match/&r], vec::view(br.pats, col + 1u, br.pats.len()))); let binding_info = - br.data.bindings_map.get(&path_to_ident(path)); + br.data.bindings_map.get(path_to_ident(path)); Store(bcx, val, binding_info.llmatch); @Match {pats: pats, data: br.data} @@ -424,8 +424,7 @@ pub fn enter_match(bcx: block, dm: DefMap, m: &[@Match/&r], ast::pat_ident(_, path, None) => { if pat_is_binding(dm, self) { let binding_info = - br.data.bindings_map.get( - &path_to_ident(path)); + br.data.bindings_map.get(path_to_ident(path)); Store(bcx, val, binding_info.llmatch); } } @@ -519,7 +518,7 @@ pub fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint, } } ast::pat_ident(_, _, None) if pat_is_const(tcx.def_map, p) => { - let const_def = tcx.def_map.get(&p.id); + let const_def = tcx.def_map.get(p.id); let const_def_id = ast_util::def_id_of_def(const_def); if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) { Some(~[]) @@ -537,7 +536,7 @@ pub fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint, if opt_eq(tcx, &variant_opt(tcx, p.id), opt) { // Look up the struct variant ID. let struct_id; - match tcx.def_map.get(&p.id) { + match tcx.def_map.get(p.id) { ast::def_variant(_, found_struct_id) => { struct_id = found_struct_id; } @@ -775,7 +774,7 @@ pub fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[Opt] { ast::pat_ident(*) => { // This is one of: an enum variant, a unit-like struct, or a // variable binding. - match ccx.tcx.def_map.find(&cur.id) { + match ccx.tcx.def_map.find(cur.id) { Some(ast::def_variant(*)) => { add_to_set(ccx.tcx, &found, variant_opt(ccx.tcx, cur.id)); @@ -794,7 +793,7 @@ pub fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[Opt] { ast::pat_enum(*) | ast::pat_struct(*) => { // This could be one of: a tuple-like enum variant, a // struct-like enum variant, or a struct. - match ccx.tcx.def_map.find(&cur.id) { + match ccx.tcx.def_map.find(cur.id) { Some(ast::def_variant(*)) => { add_to_set(ccx.tcx, &found, variant_opt(ccx.tcx, cur.id)); @@ -927,7 +926,7 @@ pub fn root_pats_as_necessary(bcx: block, let pat_id = br.pats[col].id; let key = root_map_key {id: pat_id, derefs: 0u }; - match bcx.ccx().maps.root_map.find(&key) { + match bcx.ccx().maps.root_map.find(key) { None => (), Some(root_info) => { // Note: the scope_id will always be the id of the match. See @@ -982,7 +981,7 @@ pub fn any_tuple_struct_pat(bcx: block, m: &[@Match], col: uint) -> bool { let pat = br.pats[col]; match pat.node { ast::pat_enum(_, Some(_)) => { - match bcx.tcx().def_map.find(&pat.id) { + match bcx.tcx().def_map.find(pat.id) { Some(ast::def_struct(*)) => true, _ => false } @@ -1718,9 +1717,9 @@ pub fn bind_irrefutable_pat(bcx: block, } } ast::pat_enum(_, sub_pats) => { - match bcx.tcx().def_map.find(&pat.id) { + match bcx.tcx().def_map.find(pat.id) { Some(ast::def_variant(*)) => { - let pat_def = ccx.tcx.def_map.get(&pat.id); + let pat_def = ccx.tcx.def_map.get(pat.id); let vdefs = ast_util::variant_def_ids(pat_def); let args = extract_variant_args(bcx, pat.id, vdefs, val); for sub_pats.each |sub_pat| { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index a2b1de692be..a858ecb520a 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -169,7 +169,7 @@ pub fn get_extern_fn(externs: HashMap<~str, ValueRef>, +name: ~str, cc: lib::llvm::CallConv, ty: TypeRef) -> ValueRef { - if externs.contains_key_ref(&name) { return externs.get(&name); } + if externs.contains_key_ref(&name) { return externs.get(name); } // XXX: Bad copy. let f = decl_fn(llmod, copy name, cc, ty); externs.insert(name, f); @@ -179,7 +179,7 @@ pub fn get_extern_fn(externs: HashMap<~str, ValueRef>, pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef, +name: ~str, ty: TypeRef) -> ValueRef { unsafe { - if externs.contains_key_ref(&name) { return externs.get(&name); } + if externs.contains_key_ref(&name) { return externs.get(name); } let c = str::as_c_str(name, |buf| { llvm::LLVMAddGlobal(llmod, ty, buf) }); @@ -372,7 +372,7 @@ pub fn get_tydesc_simple(ccx: @crate_ctxt, t: ty::t) -> ValueRef { } pub fn get_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info { - match ccx.tydescs.find(&t) { + match ccx.tydescs.find(t) { Some(inf) => inf, _ => { ccx.stats.n_static_tydescs += 1u; @@ -807,7 +807,7 @@ pub fn get_discrim_val(cx: @crate_ctxt, span: span, enum_did: ast::def_id, pub fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef { unsafe { let _icx = ccx.insn_ctxt("lookup_discriminant"); - match ccx.discrims.find(&vid) { + match ccx.discrims.find(vid) { None => { // It's an external discriminant that we haven't seen yet. assert (vid.crate != ast::local_crate); @@ -1095,7 +1095,7 @@ pub fn init_local(bcx: block, local: @ast::local) -> block { } } - let llptr = match bcx.fcx.lllocals.find(&local.node.id) { + let llptr = match bcx.fcx.lllocals.find(local.node.id) { Some(local_mem(v)) => v, _ => { bcx.tcx().sess.span_bug(local.span, ~"init_local: Someone forgot to document why it's\ @@ -1437,7 +1437,7 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef, session::arch_x86 | session::arch_arm => ~"llvm.memcpy.p0i8.p0i8.i32", session::arch_x86_64 => ~"llvm.memcpy.p0i8.p0i8.i64" }; - let memcpy = ccx.intrinsics.get(&key); + let memcpy = ccx.intrinsics.get(key); let src_ptr = PointerCast(cx, src, T_ptr(T_i8())); let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8())); let size = IntCast(cx, n_bytes, ccx.int_type); @@ -1484,7 +1484,7 @@ pub fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) { } } - let llintrinsicfn = ccx.intrinsics.get(&intrinsic_key); + let llintrinsicfn = ccx.intrinsics.get(intrinsic_key); let llptr = PointerCast(cx, llptr, T_ptr(T_i8())); let llzeroval = C_u8(0); let size = IntCast(cx, machine::llsize_of(ccx, llty), ccx.int_type); @@ -1884,7 +1884,7 @@ pub fn trans_enum_variant(ccx: @crate_ctxt, // If this argument to this function is a enum, it'll have come in to // this function as an opaque blob due to the way that type_of() // works. So we have to cast to the destination's view of the type. - let llarg = match fcx.llargs.find(&va.id) { + let llarg = match fcx.llargs.find(va.id) { Some(local_mem(x)) => x, _ => die!(~"trans_enum_variant: how do we know this works?"), }; @@ -1930,7 +1930,7 @@ pub fn trans_tuple_struct(ccx: @crate_ctxt, for fields.eachi |i, field| { let lldestptr = GEPi(bcx, fcx.llretptr, [0, 0, i]); - let llarg = match fcx.llargs.get(&field.node.id) { + let llarg = match fcx.llargs.get(field.node.id) { local_mem(x) => x, _ => { ccx.tcx.sess.bug(~"trans_tuple_struct: llarg wasn't \ @@ -2019,7 +2019,7 @@ pub fn trans_enum_def(ccx: @crate_ctxt, enum_definition: ast::enum_def, pub fn trans_item(ccx: @crate_ctxt, item: ast::item) { let _icx = ccx.insn_ctxt("trans_item"); - let path = match ccx.tcx.items.get(&item.id) { + let path = match ccx.tcx.items.get(item.id) { ast_map::node_item(_, p) => p, // tjc: ? _ => die!(~"trans_item"), @@ -2275,7 +2275,7 @@ pub fn fill_fn_pair(bcx: block, pair: ValueRef, llfn: ValueRef, pub fn item_path(ccx: @crate_ctxt, i: @ast::item) -> path { vec::append( - /*bad*/copy *match ccx.tcx.items.get(&i.id) { + /*bad*/copy *match ccx.tcx.items.get(i.id) { ast_map::node_item(_, p) => p, // separate map for paths? _ => die!(~"item_path") @@ -2291,7 +2291,7 @@ pub fn get_dtor_symbol(ccx: @crate_ctxt, +substs: Option) -> ~str { let t = ty::node_id_to_type(ccx.tcx, id); - match ccx.item_symbols.find(&id) { + match ccx.item_symbols.find(id) { Some(ref s) => (/*bad*/copy *s), None if substs.is_none() => { let s = mangle_exported_name( @@ -2326,12 +2326,12 @@ pub fn get_dtor_symbol(ccx: @crate_ctxt, pub fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef { debug!("get_item_val(id=`%?`)", id); let tcx = ccx.tcx; - match ccx.item_vals.find(&id) { + match ccx.item_vals.find(id) { Some(v) => v, None => { let mut exprt = false; - let val = match ccx.tcx.items.get(&id) { + let val = match ccx.tcx.items.get(id) { ast_map::node_item(i, pth) => { let my_path = vec::append(/*bad*/copy *pth, ~[path_name(i.ident)]); @@ -2770,7 +2770,7 @@ pub fn declare_dbg_intrinsics(llmod: ModuleRef, pub fn trap(bcx: block) { let v: ~[ValueRef] = ~[]; - match bcx.ccx().intrinsics.find(&~"llvm.trap") { + match bcx.ccx().intrinsics.find(~"llvm.trap") { Some(x) => { Call(bcx, x, v); }, _ => bcx.sess().bug(~"unbound llvm.trap in trap") } diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index 24e9d967fac..79236433580 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -70,7 +70,7 @@ pub fn count_insn(cx: block, category: &str) { i = 0u; while i < len { let e = /*bad*/copy v[i]; - i = mm.get(&e); + i = mm.get(/*bad*/ copy e); s += ~"/"; s += e; i += 1u; @@ -79,7 +79,7 @@ pub fn count_insn(cx: block, category: &str) { s += ~"/"; s += category; - let n = match h.find(&s) { + let n = match h.find(/*bad*/ copy s) { Some(n) => n, _ => 0u }; diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 8cfe8ba8f91..833cff80d2d 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -70,7 +70,7 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee { return trans_def(bcx, bcx.def(expr.id), expr); } ast::expr_field(base, _, _) => { - match bcx.ccx().maps.method_map.find(&expr.id) { + match bcx.ccx().maps.method_map.find(expr.id) { Some(ref origin) => { // An impl method return meth::trans_method_callee(bcx, expr.id, base, (*origin)); @@ -208,7 +208,7 @@ pub fn trans_fn_ref_with_vtables( // Modify the def_id if this is a default method; we want to be // monomorphizing the trait's code. let (def_id, opt_impl_did) = - match tcx.provided_method_sources.find(&def_id) { + match tcx.provided_method_sources.find(def_id) { None => (def_id, None), Some(source) => (source.method_id, Some(source.impl_id)) }; @@ -234,7 +234,7 @@ pub fn trans_fn_ref_with_vtables( } else if def_id.crate == ast::local_crate { let map_node = session::expect( ccx.sess, - ccx.tcx.items.find(&def_id.node), + ccx.tcx.items.find(def_id.node), || fmt!("local item should be in ast map")); match map_node { @@ -313,7 +313,7 @@ pub fn trans_method_call(in_cx: block, node_id_type(in_cx, call_ex.callee_id), expr_ty(in_cx, call_ex), |cx| { - match cx.ccx().maps.method_map.find(&call_ex.id) { + match cx.ccx().maps.method_map.find(call_ex.id) { Some(ref origin) => { meth::trans_method_callee(cx, call_ex.callee_id, diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index 62e00100d6c..4cbf6a4f4b7 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -419,7 +419,7 @@ pub fn trans_expr_fn(bcx: block, let Result {bcx: bcx, val: closure} = match proto { ast::ProtoBorrowed | ast::ProtoBox | ast::ProtoUniq => { - let cap_vars = ccx.maps.capture_map.get(&user_id); + let cap_vars = ccx.maps.capture_map.get(user_id); let ret_handle = match is_loop_body {Some(x) => x, None => None}; let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, proto, diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 0613319e4af..571f16e4b34 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -700,7 +700,7 @@ pub impl block { } fn def(nid: ast::node_id) -> ast::def { - match self.tcx().def_map.find(&nid) { + match self.tcx().def_map.find(nid) { Some(v) => v, None => { self.tcx().sess.bug(fmt!( @@ -1134,7 +1134,7 @@ pub fn C_u8(i: uint) -> ValueRef { // our boxed-and-length-annotated strings. pub fn C_cstr(cx: @crate_ctxt, +s: ~str) -> ValueRef { unsafe { - match cx.const_cstr_cache.find(&s) { + match cx.const_cstr_cache.find(/*bad*/copy s) { Some(llval) => return llval, None => () } @@ -1356,7 +1356,7 @@ pub fn node_id_type_params(bcx: block, id: ast::node_id) -> ~[ty::t] { pub fn node_vtables(bcx: block, id: ast::node_id) -> Option { - let raw_vtables = bcx.ccx().maps.vtable_map.find(&id); + let raw_vtables = bcx.ccx().maps.vtable_map.find(id); raw_vtables.map( |vts| resolve_vtables_in_fn_ctxt(bcx.fcx, *vts)) } diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 12340101d9e..b5652fed10e 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -82,7 +82,7 @@ pub fn const_vec(cx: @crate_ctxt, e: @ast::expr, es: &[@ast::expr]) pub fn const_deref(cx: @crate_ctxt, v: ValueRef) -> ValueRef { unsafe { - let v = match cx.const_globals.find(&(v as int)) { + let v = match cx.const_globals.find(v as int) { Some(v) => v, None => v }; @@ -127,7 +127,7 @@ pub fn get_const_val(cx: @crate_ctxt, def_id: ast::def_id) -> ValueRef { cx.tcx.sess.bug(~"cross-crate constants"); } if !cx.const_values.contains_key_ref(&def_id.node) { - match cx.tcx.items.get(&def_id.node) { + match cx.tcx.items.get(def_id.node) { ast_map::node_item(@ast::item { node: ast::item_const(_, subexpr), _ }, _) => { @@ -136,7 +136,7 @@ pub fn get_const_val(cx: @crate_ctxt, def_id: ast::def_id) -> ValueRef { _ => cx.tcx.sess.bug(~"expected a const to be an item") } } - cx.const_values.get(&def_id.node) + cx.const_values.get(def_id.node) } pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { @@ -402,7 +402,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { } ast::expr_path(pth) => { assert pth.types.len() == 0; - match cx.tcx.def_map.find(&e.id) { + match cx.tcx.def_map.find(e.id) { Some(ast::def_fn(def_id, purity)) => { assert ast_util::is_local(def_id); let f = base::get_item_val(cx, def_id.node); @@ -437,7 +437,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { } } ast::expr_call(callee, args, _) => { - match cx.tcx.def_map.find(&callee.id) { + match cx.tcx.def_map.find(callee.id) { Some(ast::def_struct(def_id)) => { let ety = ty::expr_ty(cx.tcx, e); let llty = type_of::type_of(cx, ety); @@ -482,7 +482,7 @@ pub fn trans_const(ccx: @crate_ctxt, _e: @ast::expr, id: ast::node_id) { let g = base::get_item_val(ccx, id); // At this point, get_item_val has already translated the // constant's initializer to determine its LLVM type. - let v = ccx.const_values.get(&id); + let v = ccx.const_values.get(id); llvm::LLVMSetInitializer(g, v); llvm::LLVMSetGlobalConstant(g, True); } diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index 8944fceb011..240c323965f 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -184,7 +184,7 @@ pub fn trans_log(log_ex: @ast::expr, let modname = path_str(ccx.sess, copy modpath); let global = if ccx.module_data.contains_key_ref(&modname) { - ccx.module_data.get(&modname) + ccx.module_data.get(modname) } else { let s = link::mangle_internal_name_by_path_and_seq( ccx, modpath, ~"loglevel"); diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index af966e4df82..554cebbbcb7 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -627,7 +627,7 @@ pub impl Datum { // // (Note: root'd values are always boxes) let key = root_map_key { id: expr_id, derefs: derefs }; - let bcx = match ccx.maps.root_map.find(&key) { + let bcx = match ccx.maps.root_map.find(key) { None => bcx, Some(root_info) => self.root(bcx, root_info) }; @@ -635,7 +635,7 @@ pub impl Datum { // Perform the write guard, if necessary. // // (Note: write-guarded values are always boxes) - let bcx = match ccx.maps.write_guard_map.find(&key) { + let bcx = match ccx.maps.write_guard_map.find(key) { None => bcx, Some(_) => self.perform_write_guard(bcx) }; diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index ecb63c19811..35abddfb85a 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -118,7 +118,7 @@ pub fn mk_ctxt(+crate: ~str, intr: @ident_interner) -> debug_ctxt { fn update_cache(cache: metadata_cache, mdtag: int, val: debug_metadata) { let existing = if cache.contains_key_ref(&mdtag) { - cache.get(&mdtag) + cache.get(mdtag) } else { ~[] }; @@ -177,7 +177,7 @@ fn cached_metadata(cache: metadata_cache, -> Option { unsafe { if cache.contains_key_ref(&mdtag) { - let items = cache.get(&mdtag); + let items = cache.get(mdtag); for items.each |item| { let md: T = md_from_metadata::(*item); if eq_fn(md) { @@ -289,7 +289,7 @@ fn create_block(cx: block) -> @metadata { Some(bcx) => create_block(bcx).node }; let file_node = create_file(cx.ccx(), fname); - let unique_id = match cache.find(&LexicalBlockTag) { + let unique_id = match cache.find(LexicalBlockTag) { option::Some(v) => vec::len(v) as int, option::None => 0 }; @@ -679,14 +679,14 @@ pub fn create_local_var(bcx: block, local: @ast::local) let mdval = @{node: mdnode, data: {id: local.node.id}}; update_cache(cache, AutoVariableTag, local_var_metadata(mdval)); - let llptr = match bcx.fcx.lllocals.find(&local.node.id) { + let llptr = match bcx.fcx.lllocals.find(local.node.id) { option::Some(local_mem(v)) => v, option::Some(_) => { bcx.tcx().sess.span_bug(local.span, ~"local is bound to \ something weird"); } option::None => { - match bcx.fcx.lllocals.get(&local.node.pat.id) { + match bcx.fcx.lllocals.get(local.node.pat.id) { local_imm(v) => v, _ => bcx.tcx().sess.span_bug(local.span, ~"local is bound to \ something weird") @@ -694,7 +694,7 @@ pub fn create_local_var(bcx: block, local: @ast::local) } }; let declargs = ~[llmdnode(~[llptr]), mdnode]; - trans::build::Call(bcx, cx.intrinsics.get(&~"llvm.dbg.declare"), + trans::build::Call(bcx, cx.intrinsics.get(~"llvm.dbg.declare"), declargs); return mdval; } @@ -731,12 +731,12 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span) let mdval = @{node: mdnode, data: {id: arg.id}}; update_cache(cache, tg, argument_metadata(mdval)); - let llptr = match fcx.llargs.get(&arg.id) { + let llptr = match fcx.llargs.get(arg.id) { local_mem(v) | local_imm(v) => v, }; let declargs = ~[llmdnode(~[llptr]), mdnode]; trans::build::Call(bcx, - cx.intrinsics.get(&~"llvm.dbg.declare"), + cx.intrinsics.get(~"llvm.dbg.declare"), declargs); return Some(mdval); } @@ -774,7 +774,7 @@ pub fn create_function(fcx: fn_ctxt) -> @metadata { let sp = fcx.span.get(); log(debug, cx.sess.codemap.span_to_str(sp)); - let (ident, ret_ty, id) = match cx.tcx.items.get(&fcx.id) { + let (ident, ret_ty, id) = match cx.tcx.items.get(fcx.id) { ast_map::node_item(item, _) => { match /*bad*/copy item.node { ast::item_fn(decl, _, _, _) => { diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index e19bafdb598..4cf449cd972 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -185,7 +185,7 @@ fn drop_and_cancel_clean(bcx: block, dat: Datum) -> block { pub fn trans_to_datum(bcx: block, expr: @ast::expr) -> DatumBlock { debug!("trans_to_datum(expr=%s)", bcx.expr_to_str(expr)); - return match bcx.tcx().adjustments.find(&expr.id) { + return match bcx.tcx().adjustments.find(expr.id) { None => { trans_to_datum_unadjusted(bcx, expr) } @@ -329,7 +329,7 @@ fn trans_lvalue(bcx: block, expr: @ast::expr) -> DatumBlock { * instead, but sometimes we call trans_lvalue() directly as a * means of asserting that a particular expression is an lvalue. */ - return match bcx.tcx().adjustments.find(&expr.id) { + return match bcx.tcx().adjustments.find(expr.id) { None => trans_lvalue_unadjusted(bcx, expr), Some(_) => { bcx.sess().span_bug( @@ -742,7 +742,7 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock { // the lvalue in there, and then arrange for it to be cleaned up // at the end of the scope with id `scope_id`: let root_key = root_map_key { id: expr.id, derefs: 0u }; - for bcx.ccx().maps.root_map.find(&root_key).each |&root_info| { + for bcx.ccx().maps.root_map.find(root_key).each |&root_info| { bcx = unrooted_datum.root(bcx, root_info); } @@ -934,7 +934,7 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum { ast::def_upvar(nid, _, _, _) => { // Can't move upvars, so this is never a ZeroMemLastUse. let local_ty = node_id_type(bcx, nid); - match bcx.fcx.llupvars.find(&nid) { + match bcx.fcx.llupvars.find(nid) { Some(val) => { Datum { val: val, @@ -987,7 +987,7 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum { fn take_local(bcx: block, table: HashMap, nid: ast::node_id) -> Datum { - let (v, mode) = match table.find(&nid) { + let (v, mode) = match table.find(nid) { Some(local_mem(v)) => (v, ByRef), Some(local_imm(v)) => (v, ByValue), None => { @@ -1066,7 +1066,7 @@ pub fn with_field_tys(tcx: ty::ctxt, ty_to_str(tcx, ty))); } Some(node_id) => { - match tcx.def_map.get(&node_id) { + match tcx.def_map.get(node_id) { ast::def_variant(_, variant_id) => { op(false, struct_mutable_fields( tcx, variant_id, substs)) @@ -1120,7 +1120,7 @@ fn trans_rec_or_struct(bcx: block, let tcx = bcx.tcx(); let addr = match ty::get(ty).sty { ty::ty_enum(_, ref substs) => { - match tcx.def_map.get(&id) { + match tcx.def_map.get(id) { ast::def_variant(enum_id, variant_id) => { let variant_info = ty::enum_variant_with_id( tcx, enum_id, variant_id); @@ -1479,7 +1479,7 @@ fn trans_overloaded_op(bcx: block, dest: Dest, +autoref_arg: AutorefArg) -> block { - let origin = bcx.ccx().maps.method_map.get(&expr.id); + let origin = bcx.ccx().maps.method_map.get(expr.id); let fty = node_id_type(bcx, expr.callee_id); return callee::trans_call_inner( bcx, expr.info(), fty, @@ -1636,7 +1636,7 @@ fn trans_assign_op(bcx: block, let dst_datum = unpack_datum!(bcx, trans_lvalue_unadjusted(bcx, dst)); // A user-defined operator method - if bcx.ccx().maps.method_map.find(&expr.id).is_some() { + if bcx.ccx().maps.method_map.find(expr.id).is_some() { // FIXME(#2528) evaluates the receiver twice!! let scratch = scratch_datum(bcx, dst_datum.ty, false); let bcx = trans_overloaded_op(bcx, expr, dst, ~[src], diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 171fdc79e3a..9c2245411c6 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -498,7 +498,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, let tp_sz = machine::llbitsize_of_real(ccx, lltp_ty), out_sz = machine::llbitsize_of_real(ccx, llout_ty); if tp_sz != out_sz { - let sp = match ccx.tcx.items.get(&ref_id.get()) { + let sp = match ccx.tcx.items.get(ref_id.get()) { ast_map::node_expr(e) => e.span, _ => die!(~"reinterpret_cast or forget has non-expr arg") }; @@ -535,7 +535,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, abi::tydesc_field_visit_glue, None); } ~"frame_address" => { - let frameaddress = ccx.intrinsics.get(&~"llvm.frameaddress"); + let frameaddress = ccx.intrinsics.get(~"llvm.frameaddress"); let frameaddress_val = Call(bcx, frameaddress, ~[C_i32(0i32)]); let star_u8 = ty::mk_imm_ptr( bcx.tcx(), @@ -576,7 +576,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, let align = C_i32(1); let volatile = C_bool(false); let llfn = bcx.ccx().intrinsics.get( - &~"llvm.memmove.p0i8.p0i8.i32"); + ~"llvm.memmove.p0i8.p0i8.i32"); Call(bcx, llfn, ~[dst_ptr, src_ptr, size, align, volatile]); } ~"memmove64" => { @@ -586,248 +586,248 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, let align = C_i32(1); let volatile = C_bool(false); let llfn = bcx.ccx().intrinsics.get( - &~"llvm.memmove.p0i8.p0i8.i64"); + ~"llvm.memmove.p0i8.p0i8.i64"); Call(bcx, llfn, ~[dst_ptr, src_ptr, size, align, volatile]); } ~"sqrtf32" => { let x = get_param(decl, first_real_arg); - let sqrtf = ccx.intrinsics.get(&~"llvm.sqrt.f32"); + let sqrtf = ccx.intrinsics.get(~"llvm.sqrt.f32"); Store(bcx, Call(bcx, sqrtf, ~[x]), fcx.llretptr); } ~"sqrtf64" => { let x = get_param(decl, first_real_arg); - let sqrtf = ccx.intrinsics.get(&~"llvm.sqrt.f64"); + let sqrtf = ccx.intrinsics.get(~"llvm.sqrt.f64"); Store(bcx, Call(bcx, sqrtf, ~[x]), fcx.llretptr); } ~"powif32" => { let a = get_param(decl, first_real_arg); let x = get_param(decl, first_real_arg + 1u); - let powif = ccx.intrinsics.get(&~"llvm.powi.f32"); + let powif = ccx.intrinsics.get(~"llvm.powi.f32"); Store(bcx, Call(bcx, powif, ~[a, x]), fcx.llretptr); } ~"powif64" => { let a = get_param(decl, first_real_arg); let x = get_param(decl, first_real_arg + 1u); - let powif = ccx.intrinsics.get(&~"llvm.powi.f64"); + let powif = ccx.intrinsics.get(~"llvm.powi.f64"); Store(bcx, Call(bcx, powif, ~[a, x]), fcx.llretptr); } ~"sinf32" => { let x = get_param(decl, first_real_arg); - let sinf = ccx.intrinsics.get(&~"llvm.sin.f32"); + let sinf = ccx.intrinsics.get(~"llvm.sin.f32"); Store(bcx, Call(bcx, sinf, ~[x]), fcx.llretptr); } ~"sinf64" => { let x = get_param(decl, first_real_arg); - let sinf = ccx.intrinsics.get(&~"llvm.sin.f64"); + let sinf = ccx.intrinsics.get(~"llvm.sin.f64"); Store(bcx, Call(bcx, sinf, ~[x]), fcx.llretptr); } ~"cosf32" => { let x = get_param(decl, first_real_arg); - let cosf = ccx.intrinsics.get(&~"llvm.cos.f32"); + let cosf = ccx.intrinsics.get(~"llvm.cos.f32"); Store(bcx, Call(bcx, cosf, ~[x]), fcx.llretptr); } ~"cosf64" => { let x = get_param(decl, first_real_arg); - let cosf = ccx.intrinsics.get(&~"llvm.cos.f64"); + let cosf = ccx.intrinsics.get(~"llvm.cos.f64"); Store(bcx, Call(bcx, cosf, ~[x]), fcx.llretptr); } ~"powf32" => { let a = get_param(decl, first_real_arg); let x = get_param(decl, first_real_arg + 1u); - let powf = ccx.intrinsics.get(&~"llvm.pow.f32"); + let powf = ccx.intrinsics.get(~"llvm.pow.f32"); Store(bcx, Call(bcx, powf, ~[a, x]), fcx.llretptr); } ~"powf64" => { let a = get_param(decl, first_real_arg); let x = get_param(decl, first_real_arg + 1u); - let powf = ccx.intrinsics.get(&~"llvm.pow.f64"); + let powf = ccx.intrinsics.get(~"llvm.pow.f64"); Store(bcx, Call(bcx, powf, ~[a, x]), fcx.llretptr); } ~"expf32" => { let x = get_param(decl, first_real_arg); - let expf = ccx.intrinsics.get(&~"llvm.exp.f32"); + let expf = ccx.intrinsics.get(~"llvm.exp.f32"); Store(bcx, Call(bcx, expf, ~[x]), fcx.llretptr); } ~"expf64" => { let x = get_param(decl, first_real_arg); - let expf = ccx.intrinsics.get(&~"llvm.exp.f64"); + let expf = ccx.intrinsics.get(~"llvm.exp.f64"); Store(bcx, Call(bcx, expf, ~[x]), fcx.llretptr); } ~"exp2f32" => { let x = get_param(decl, first_real_arg); - let exp2f = ccx.intrinsics.get(&~"llvm.exp2.f32"); + let exp2f = ccx.intrinsics.get(~"llvm.exp2.f32"); Store(bcx, Call(bcx, exp2f, ~[x]), fcx.llretptr); } ~"exp2f64" => { let x = get_param(decl, first_real_arg); - let exp2f = ccx.intrinsics.get(&~"llvm.exp2.f64"); + let exp2f = ccx.intrinsics.get(~"llvm.exp2.f64"); Store(bcx, Call(bcx, exp2f, ~[x]), fcx.llretptr); } ~"logf32" => { let x = get_param(decl, first_real_arg); - let logf = ccx.intrinsics.get(&~"llvm.log.f32"); + let logf = ccx.intrinsics.get(~"llvm.log.f32"); Store(bcx, Call(bcx, logf, ~[x]), fcx.llretptr); } ~"logf64" => { let x = get_param(decl, first_real_arg); - let logf = ccx.intrinsics.get(&~"llvm.log.f64"); + let logf = ccx.intrinsics.get(~"llvm.log.f64"); Store(bcx, Call(bcx, logf, ~[x]), fcx.llretptr); } ~"log10f32" => { let x = get_param(decl, first_real_arg); - let log10f = ccx.intrinsics.get(&~"llvm.log10.f32"); + let log10f = ccx.intrinsics.get(~"llvm.log10.f32"); Store(bcx, Call(bcx, log10f, ~[x]), fcx.llretptr); } ~"log10f64" => { let x = get_param(decl, first_real_arg); - let log10f = ccx.intrinsics.get(&~"llvm.log10.f64"); + let log10f = ccx.intrinsics.get(~"llvm.log10.f64"); Store(bcx, Call(bcx, log10f, ~[x]), fcx.llretptr); } ~"log2f32" => { let x = get_param(decl, first_real_arg); - let log2f = ccx.intrinsics.get(&~"llvm.log2.f32"); + let log2f = ccx.intrinsics.get(~"llvm.log2.f32"); Store(bcx, Call(bcx, log2f, ~[x]), fcx.llretptr); } ~"log2f64" => { let x = get_param(decl, first_real_arg); - let log2f = ccx.intrinsics.get(&~"llvm.log2.f64"); + let log2f = ccx.intrinsics.get(~"llvm.log2.f64"); Store(bcx, Call(bcx, log2f, ~[x]), fcx.llretptr); } ~"fmaf32" => { let a = get_param(decl, first_real_arg); let b = get_param(decl, first_real_arg + 1u); let c = get_param(decl, first_real_arg + 2u); - let fmaf = ccx.intrinsics.get(&~"llvm.fma.f32"); + let fmaf = ccx.intrinsics.get(~"llvm.fma.f32"); Store(bcx, Call(bcx, fmaf, ~[a, b, c]), fcx.llretptr); } ~"fmaf64" => { let a = get_param(decl, first_real_arg); let b = get_param(decl, first_real_arg + 1u); let c = get_param(decl, first_real_arg + 2u); - let fmaf = ccx.intrinsics.get(&~"llvm.fma.f64"); + let fmaf = ccx.intrinsics.get(~"llvm.fma.f64"); Store(bcx, Call(bcx, fmaf, ~[a, b, c]), fcx.llretptr); } ~"fabsf32" => { let x = get_param(decl, first_real_arg); - let fabsf = ccx.intrinsics.get(&~"llvm.fabs.f32"); + let fabsf = ccx.intrinsics.get(~"llvm.fabs.f32"); Store(bcx, Call(bcx, fabsf, ~[x]), fcx.llretptr); } ~"fabsf64" => { let x = get_param(decl, first_real_arg); - let fabsf = ccx.intrinsics.get(&~"llvm.fabs.f64"); + let fabsf = ccx.intrinsics.get(~"llvm.fabs.f64"); Store(bcx, Call(bcx, fabsf, ~[x]), fcx.llretptr); } ~"floorf32" => { let x = get_param(decl, first_real_arg); - let floorf = ccx.intrinsics.get(&~"llvm.floor.f32"); + let floorf = ccx.intrinsics.get(~"llvm.floor.f32"); Store(bcx, Call(bcx, floorf, ~[x]), fcx.llretptr); } ~"floorf64" => { let x = get_param(decl, first_real_arg); - let floorf = ccx.intrinsics.get(&~"llvm.floor.f64"); + let floorf = ccx.intrinsics.get(~"llvm.floor.f64"); Store(bcx, Call(bcx, floorf, ~[x]), fcx.llretptr); } ~"ceilf32" => { let x = get_param(decl, first_real_arg); - let ceilf = ccx.intrinsics.get(&~"llvm.ceil.f32"); + let ceilf = ccx.intrinsics.get(~"llvm.ceil.f32"); Store(bcx, Call(bcx, ceilf, ~[x]), fcx.llretptr); } ~"ceilf64" => { let x = get_param(decl, first_real_arg); - let ceilf = ccx.intrinsics.get(&~"llvm.ceil.f64"); + let ceilf = ccx.intrinsics.get(~"llvm.ceil.f64"); Store(bcx, Call(bcx, ceilf, ~[x]), fcx.llretptr); } ~"truncf32" => { let x = get_param(decl, first_real_arg); - let truncf = ccx.intrinsics.get(&~"llvm.trunc.f32"); + let truncf = ccx.intrinsics.get(~"llvm.trunc.f32"); Store(bcx, Call(bcx, truncf, ~[x]), fcx.llretptr); } ~"truncf64" => { let x = get_param(decl, first_real_arg); - let truncf = ccx.intrinsics.get(&~"llvm.trunc.f64"); + let truncf = ccx.intrinsics.get(~"llvm.trunc.f64"); Store(bcx, Call(bcx, truncf, ~[x]), fcx.llretptr); } ~"ctpop8" => { let x = get_param(decl, first_real_arg); - let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i8"); + let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i8"); Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) } ~"ctpop16" => { let x = get_param(decl, first_real_arg); - let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i16"); + let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i16"); Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) } ~"ctpop32" => { let x = get_param(decl, first_real_arg); - let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i32"); + let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i32"); Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) } ~"ctpop64" => { let x = get_param(decl, first_real_arg); - let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i64"); + let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i64"); Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) } ~"ctlz8" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i8"); + let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i8"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"ctlz16" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i16"); + let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i16"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"ctlz32" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i32"); + let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i32"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"ctlz64" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i64"); + let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i64"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"cttz8" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let cttz = ccx.intrinsics.get(&~"llvm.cttz.i8"); + let cttz = ccx.intrinsics.get(~"llvm.cttz.i8"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"cttz16" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let cttz = ccx.intrinsics.get(&~"llvm.cttz.i16"); + let cttz = ccx.intrinsics.get(~"llvm.cttz.i16"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"cttz32" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let cttz = ccx.intrinsics.get(&~"llvm.cttz.i32"); + let cttz = ccx.intrinsics.get(~"llvm.cttz.i32"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"cttz64" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let cttz = ccx.intrinsics.get(&~"llvm.cttz.i64"); + let cttz = ccx.intrinsics.get(~"llvm.cttz.i64"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"bswap16" => { let x = get_param(decl, first_real_arg); - let cttz = ccx.intrinsics.get(&~"llvm.bswap.i16"); + let cttz = ccx.intrinsics.get(~"llvm.bswap.i16"); Store(bcx, Call(bcx, cttz, ~[x]), fcx.llretptr) } ~"bswap32" => { let x = get_param(decl, first_real_arg); - let cttz = ccx.intrinsics.get(&~"llvm.bswap.i32"); + let cttz = ccx.intrinsics.get(~"llvm.bswap.i32"); Store(bcx, Call(bcx, cttz, ~[x]), fcx.llretptr) } ~"bswap64" => { let x = get_param(decl, first_real_arg); - let cttz = ccx.intrinsics.get(&~"llvm.bswap.i64"); + let cttz = ccx.intrinsics.get(~"llvm.bswap.i64"); Store(bcx, Call(bcx, cttz, ~[x]), fcx.llretptr) } _ => { @@ -955,7 +955,7 @@ pub fn register_foreign_fn(ccx: @crate_ctxt, fn abi_of_foreign_fn(ccx: @crate_ctxt, i: @ast::foreign_item) -> ast::foreign_abi { match attr::first_attr_value_str_by_name(i.attrs, ~"abi") { - None => match ccx.tcx.items.get(&i.id) { + None => match ccx.tcx.items.get(i.id) { ast_map::node_foreign_item(_, abi, _) => abi, // ?? _ => die!(~"abi_of_foreign_fn: not foreign") diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 9909980fb7e..849a718a52e 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -381,7 +381,7 @@ pub fn make_visit_glue(bcx: block, v: ValueRef, t: ty::t) { let mut bcx = bcx; let ty_visitor_name = special_idents::ty_visitor; assert bcx.ccx().tcx.intrinsic_defs.contains_key_ref(&ty_visitor_name); - let (trait_id, ty) = bcx.ccx().tcx.intrinsic_defs.get(&ty_visitor_name); + let (trait_id, ty) = bcx.ccx().tcx.intrinsic_defs.get(ty_visitor_name); let v = PointerCast(bcx, v, T_ptr(type_of::type_of(bcx.ccx(), ty))); bcx = reflect::emit_calls_to_trait_visit_ty(bcx, t, v, trait_id); build_return(bcx); diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index 4466e4e1b28..f5d23236334 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -31,7 +31,7 @@ pub fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id, translate: bool) -> ast::def_id { let _icx = ccx.insn_ctxt("maybe_instantiate_inline"); - match ccx.external.find(&fn_id) { + match ccx.external.find(fn_id) { Some(Some(node_id)) => { // Already inline debug!("maybe_instantiate_inline(%s): already inline as node id %d", diff --git a/src/librustc/middle/trans/machine.rs b/src/librustc/middle/trans/machine.rs index e76176218b7..1b3e13cddab 100644 --- a/src/librustc/middle/trans/machine.rs +++ b/src/librustc/middle/trans/machine.rs @@ -178,7 +178,7 @@ pub fn llalign_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef { // Computes the size of the data part of an enum. pub fn static_size_of_enum(cx: @crate_ctxt, t: ty::t) -> uint { - if cx.enum_sizes.contains_key_ref(&t) { return cx.enum_sizes.get(&t); } + if cx.enum_sizes.contains_key_ref(&t) { return cx.enum_sizes.get(t); } match ty::get(t).sty { ty::ty_enum(tid, ref substs) => { // Compute max(variant sizes). diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index d751b8f9208..f488c32437c 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -308,7 +308,7 @@ pub fn trans_static_method_callee(bcx: block, }; let mname = if method_id.crate == ast::local_crate { - match bcx.tcx().items.get(&method_id.node) { + match bcx.tcx().items.get(method_id.node) { ast_map::node_trait_method(trait_method, _, _) => { ast_util::trait_method_to_ty_method(*trait_method).ident } @@ -325,7 +325,7 @@ pub fn trans_static_method_callee(bcx: block, name=%s", method_id, callee_id, ccx.sess.str_of(mname)); let vtbls = resolve_vtables_in_fn_ctxt( - bcx.fcx, ccx.maps.vtable_map.get(&callee_id)); + bcx.fcx, ccx.maps.vtable_map.get(callee_id)); match /*bad*/copy vtbls[bound_index] { typeck::vtable_static(impl_did, rcvr_substs, rcvr_origins) => { @@ -362,7 +362,7 @@ pub fn method_from_methods(ms: ~[@ast::method], name: ast::ident) pub fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id, name: ast::ident) -> ast::def_id { if impl_id.crate == ast::local_crate { - match ccx.tcx.items.get(&impl_id.node) { + match ccx.tcx.items.get(impl_id.node) { ast_map::node_item(@ast::item { node: ast::item_impl(_, _, _, ref ms), _ @@ -379,7 +379,7 @@ pub fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id, pub fn method_with_name_or_default(ccx: @crate_ctxt, impl_id: ast::def_id, name: ast::ident) -> ast::def_id { if impl_id.crate == ast::local_crate { - match ccx.tcx.items.get(&impl_id.node) { + match ccx.tcx.items.get(impl_id.node) { ast_map::node_item(@ast::item { node: ast::item_impl(_, _, _, ref ms), _ }, _) => { @@ -389,7 +389,7 @@ pub fn method_with_name_or_default(ccx: @crate_ctxt, impl_id: ast::def_id, } else { // Look for a default method let pmm = ccx.tcx.provided_methods; - match pmm.find(&impl_id) { + match pmm.find(impl_id) { Some(pmis) => { for pmis.each |pmi| { if pmi.method_info.ident == name { @@ -414,10 +414,10 @@ pub fn method_ty_param_count(ccx: @crate_ctxt, m_id: ast::def_id, i_id: ast::def_id) -> uint { debug!("method_ty_param_count: m_id: %?, i_id: %?", m_id, i_id); if m_id.crate == ast::local_crate { - match ccx.tcx.items.find(&m_id.node) { + match ccx.tcx.items.find(m_id.node) { Some(ast_map::node_method(m, _, _)) => m.tps.len(), None => { - match ccx.tcx.provided_method_sources.find(&m_id) { + match ccx.tcx.provided_method_sources.find(m_id) { Some(source) => { method_ty_param_count( ccx, source.method_id, source.impl_id) @@ -779,7 +779,7 @@ pub fn get_vtable(ccx: @crate_ctxt, -> ValueRef { // XXX: Bad copy. let hash_id = vtable_id(ccx, copy origin); - match ccx.vtables.find(&hash_id) { + match ccx.vtables.find(hash_id) { Some(val) => val, None => match origin { typeck::vtable_static(id, substs, sub_vtables) => { @@ -916,7 +916,7 @@ pub fn trans_trait_cast(bcx: block, } // Store the vtable into the pair or triple. - let orig = /*bad*/copy ccx.maps.vtable_map.get(&id)[0]; + let orig = /*bad*/copy ccx.maps.vtable_map.get(id)[0]; let orig = resolve_vtable_in_fn_ctxt(bcx.fcx, orig); let vtable = get_vtable(bcx.ccx(), orig); Store(bcx, vtable, PointerCast(bcx, diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 5873d0a76d9..60b4057d448 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -69,7 +69,7 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, real_substs.map(|s| ty_to_str(ccx.tcx, *s)), substs.map(|s| ty_to_str(ccx.tcx, *s)), hash_id); - match ccx.monomorphized.find(&hash_id) { + match ccx.monomorphized.find(hash_id) { Some(val) => { debug!("leaving monomorphic fn %s", ty::item_path_str(ccx.tcx, fn_id)); @@ -81,7 +81,7 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, let tpt = ty::lookup_item_type(ccx.tcx, fn_id); let mut llitem_ty = tpt.ty; - let map_node = session::expect(ccx.sess, ccx.tcx.items.find(&fn_id.node), + let map_node = session::expect(ccx.sess, ccx.tcx.items.find(fn_id.node), || fmt!("While monomorphizing %?, couldn't find it in the item map \ (may have attempted to monomorphize an item defined in a different \ crate?)", fn_id)); @@ -136,7 +136,7 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, ccx.stats.n_monos += 1; - let depth = option::get_or_default(ccx.monomorphizing.find(&fn_id), 0u); + let depth = option::get_or_default(ccx.monomorphizing.find(fn_id), 0u); // Random cut-off -- code that needs to instantiate the same function // recursively more than ten times can probably safely be assumed to be // causing an infinite expansion. diff --git a/src/librustc/middle/trans/reachable.rs b/src/librustc/middle/trans/reachable.rs index 112b9ac4d07..02e07e8484a 100644 --- a/src/librustc/middle/trans/reachable.rs +++ b/src/librustc/middle/trans/reachable.rs @@ -54,7 +54,7 @@ pub fn find_reachable(crate_mod: _mod, exp_map2: resolve::ExportMap2, fn traverse_exports(cx: ctx, mod_id: node_id) -> bool { let mut found_export = false; - match cx.exp_map2.find(&mod_id) { + match cx.exp_map2.find(mod_id) { Some(ref exp2s) => { for (*exp2s).each |e2| { found_export = true; @@ -68,7 +68,7 @@ fn traverse_exports(cx: ctx, mod_id: node_id) -> bool { fn traverse_def_id(cx: ctx, did: def_id) { if did.crate != local_crate { return; } - let n = match cx.tcx.items.find(&did.node) { + let n = match cx.tcx.items.find(did.node) { None => return, // This can happen for self, for example Some(ref n) => (/*bad*/copy *n) }; @@ -150,7 +150,7 @@ fn traverse_ty(ty: @Ty, cx: ctx, v: visit::vt) { match ty.node { ty_path(p, p_id) => { - match cx.tcx.def_map.find(&p_id) { + match cx.tcx.def_map.find(p_id) { // Kind of a hack to check this here, but I'm not sure what else // to do Some(def_prim_ty(_)) => { /* do nothing */ } @@ -169,7 +169,7 @@ fn traverse_inline_body(cx: ctx, body: blk) { fn traverse_expr(e: @expr, cx: ctx, v: visit::vt) { match e.node { expr_path(_) => { - match cx.tcx.def_map.find(&e.id) { + match cx.tcx.def_map.find(e.id) { Some(d) => { traverse_def_id(cx, def_id_of_def(d)); } @@ -179,7 +179,7 @@ fn traverse_inline_body(cx: ctx, body: blk) { } } expr_field(_, _, _) => { - match cx.method_map.find(&e.id) { + match cx.method_map.find(e.id) { Some(typeck::method_map_entry { origin: typeck::method_static(did), _ @@ -190,7 +190,7 @@ fn traverse_inline_body(cx: ctx, body: blk) { } } expr_method_call(*) => { - match cx.method_map.find(&e.id) { + match cx.method_map.find(e.id) { Some(typeck::method_map_entry { origin: typeck::method_static(did), _ diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index 59ba55920fd..b9a055ad8ab 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -317,7 +317,7 @@ pub fn emit_calls_to_trait_visit_ty(bcx: block, use syntax::parse::token::special_idents::tydesc; let final = sub_block(bcx, ~"final"); assert bcx.ccx().tcx.intrinsic_defs.contains_key_ref(&tydesc); - let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get(&tydesc); + let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get(tydesc); let tydesc_ty = type_of::type_of(bcx.ccx(), tydesc_ty); let r = reflector({ visitor_val: visitor_val, diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 99c47997df0..72efab0c371 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -87,7 +87,7 @@ pub fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef { debug!("type_of %?: %?", t, ty::get(t)); // Check the cache. - if cx.lltypes.contains_key_ref(&t) { return cx.lltypes.get(&t); } + if cx.lltypes.contains_key_ref(&t) { return cx.lltypes.get(t); } // Replace any typedef'd types with their equivalent non-typedef // type. This ensures that all LLVM nominal types that contain diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index 6b0d4e17c74..350b1393c33 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -53,7 +53,7 @@ pub type ctx = {ccx: @crate_ctxt, uses: ~[mut type_uses]}; pub fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint) -> ~[type_uses] { - match ccx.type_use_cache.find(&fn_id) { + match ccx.type_use_cache.find(fn_id) { Some(uses) => return uses, None => () } @@ -87,7 +87,7 @@ pub fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint) ccx.type_use_cache.insert(fn_id, copy uses); return uses; } - let map_node = match ccx.tcx.items.find(&fn_id_loc.node) { + let map_node = match ccx.tcx.items.find(fn_id_loc.node) { Some(ref x) => (/*bad*/copy *x), None => ccx.sess.bug(fmt!("type_uses_for: unbound item ID %?", fn_id_loc)) @@ -226,10 +226,10 @@ pub fn node_type_needs(cx: ctx, use_: uint, id: node_id) { } pub fn mark_for_method_call(cx: ctx, e_id: node_id, callee_id: node_id) { - do option::iter(&cx.ccx.maps.method_map.find(&e_id)) |mth| { + do option::iter(&cx.ccx.maps.method_map.find(e_id)) |mth| { match mth.origin { typeck::method_static(did) => { - do cx.ccx.tcx.node_type_substs.find(&callee_id).iter |ts| { + do cx.ccx.tcx.node_type_substs.find(callee_id).iter |ts| { let type_uses = type_uses_for(cx.ccx, did, ts.len()); for vec::each2(type_uses, *ts) |uses, subst| { type_needs(cx, *uses, *subst) @@ -278,8 +278,8 @@ pub fn mark_for_expr(cx: ctx, e: @expr) { } } expr_path(_) => { - do cx.ccx.tcx.node_type_substs.find(&e.id).iter |ts| { - let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(&e.id)); + do cx.ccx.tcx.node_type_substs.find(e.id).iter |ts| { + let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(e.id)); let uses_for_ts = type_uses_for(cx.ccx, id, ts.len()); for vec::each2(uses_for_ts, *ts) |uses, subst| { type_needs(cx, *uses, *subst) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 9905701e058..2bfcecfd2f7 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -876,7 +876,7 @@ fn mk_t(cx: ctxt, +st: sty) -> t { mk_t_with_id(cx, st, None) } // and returns the box as cast to an unsafe ptr (see comments for t above). fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option) -> t { let key = intern_key { sty: to_unsafe_ptr(&st), o_def_id: o_def_id }; - match cx.interner.find(&key) { + match cx.interner.find(key) { Some(t) => unsafe { return cast::reinterpret_cast(&t); }, _ => () } @@ -1142,7 +1142,7 @@ pub fn default_arg_mode_for_ty(tcx: ctxt, ty: ty::t) -> ast::rmode { // Returns the narrowest lifetime enclosing the evaluation of the expression // with id `id`. pub fn encl_region(cx: ctxt, id: ast::node_id) -> ty::Region { - match cx.region_map.find(&id) { + match cx.region_map.find(id) { Some(encl_scope) => ty::re_scope(encl_scope), None => ty::re_static } @@ -1653,7 +1653,7 @@ pub fn type_is_immediate(ty: t) -> bool { } pub fn type_needs_drop(cx: ctxt, ty: t) -> bool { - match cx.needs_drop_cache.find(&ty) { + match cx.needs_drop_cache.find(ty) { Some(result) => return result, None => {/* fall through */ } } @@ -1732,7 +1732,7 @@ pub fn type_needs_drop(cx: ctxt, ty: t) -> bool { // that only contain scalars and shared boxes can avoid unwind // cleanups. pub fn type_needs_unwind_cleanup(cx: ctxt, ty: t) -> bool { - match cx.needs_unwind_cleanup_cache.find(&ty) { + match cx.needs_unwind_cleanup_cache.find(ty) { Some(result) => return result, None => () } @@ -1749,7 +1749,7 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t, encountered_box: bool) -> bool { // Prevent infinite recursion - match tycache.find(&ty) { + match tycache.find(ty) { Some(_) => return false, None => { tycache.insert(ty, ()); } } @@ -2011,7 +2011,7 @@ pub fn type_kind(cx: ctxt, ty: t) -> Kind { // If `allow_ty_var` is true, then this is a conservative assumption; we // assume that type variables *do* have all kinds. pub fn type_kind_ext(cx: ctxt, ty: t, allow_ty_var: bool) -> Kind { - match cx.kind_cache.find(&ty) { + match cx.kind_cache.find(ty) { Some(result) => return result, None => {/* fall through */ } } @@ -2165,7 +2165,7 @@ pub fn type_kind_ext(cx: ctxt, ty: t, allow_ty_var: bool) -> Kind { // cross-crate inlining code to translate a def-id. assert p.def_id.crate == ast::local_crate; - param_bounds_to_kind(cx.ty_param_bounds.get(&p.def_id.node)) + param_bounds_to_kind(cx.ty_param_bounds.get(p.def_id.node)) } // self is a special type parameter that can only appear in traits; it @@ -2810,7 +2810,7 @@ pub fn node_id_to_type(cx: ctxt, id: ast::node_id) -> t { } pub fn node_id_to_type_params(cx: ctxt, id: ast::node_id) -> ~[t] { - match cx.node_type_substs.find(&id) { + match cx.node_type_substs.find(id) { None => return ~[], Some(ts) => return ts } @@ -2950,7 +2950,7 @@ pub fn expr_ty_adjusted(cx: ctxt, expr: @ast::expr) -> t { let unadjusted_ty = expr_ty(cx, expr); - return match cx.adjustments.find(&expr.id) { + return match cx.adjustments.find(expr.id) { None => unadjusted_ty, Some(adj) => { @@ -3054,7 +3054,7 @@ pub fn expr_has_ty_params(cx: ctxt, expr: @ast::expr) -> bool { pub fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map, id: ast::node_id) -> Option<@~[param_bounds]> { - do method_map.find(&id).map |method| { + do method_map.find(id).map |method| { match method.origin { typeck::method_static(did) => { // n.b.: When we encode impl methods, the bounds @@ -3081,7 +3081,7 @@ pub fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map, } fn resolve_expr(tcx: ctxt, expr: @ast::expr) -> ast::def { - match tcx.def_map.find(&expr.id) { + match tcx.def_map.find(expr.id) { Some(def) => def, None => { tcx.sess.span_bug(expr.span, fmt!( @@ -3335,7 +3335,7 @@ pub fn occurs_check(tcx: ctxt, sp: span, vid: TyVid, rt: t) { fn canon(tbl: HashMap>, +m0: ast::inferable) -> ast::inferable { match m0 { - ast::infer(id) => match tbl.find(&id) { + ast::infer(id) => match tbl.find(id) { None => m0, Some(ref m1) => { let cm1 = canon(tbl, (*m1)); @@ -3597,7 +3597,7 @@ pub fn store_trait_methods(cx: ctxt, id: ast::node_id, ms: @~[method]) { pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[ast::ident] { if is_local(id) { - match cx.items.find(&id.node) { + match cx.items.find(id.node) { Some(ast_map::node_item(@ast::item { node: item_trait(_, _, ref ms), _ @@ -3617,7 +3617,7 @@ pub fn trait_supertraits(cx: ctxt, id: ast::def_id) -> @~[InstantiatedTraitRef] { // Check the cache. - match cx.supertraits.find(&id) { + match cx.supertraits.find(id) { Some(instantiated_trait_info) => { return instantiated_trait_info; } None => {} // Continue. } @@ -3646,7 +3646,7 @@ pub fn trait_supertraits(cx: ctxt, } pub fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] { - match cx.trait_method_cache.find(&id) { + match cx.trait_method_cache.find(id) { // Local traits are supposed to have been added explicitly. Some(ms) => ms, _ => { @@ -3680,7 +3680,7 @@ pub fn impl_traits(cx: ctxt, id: ast::def_id, vstore: vstore) -> ~[t] { if id.crate == ast::local_crate { debug!("(impl_traits) searching for trait impl %?", id); - match cx.items.find(&id.node) { + match cx.items.find(id.node) { Some(ast_map::node_item(@ast::item { node: ast::item_impl(_, opt_trait, _, _), _}, @@ -3716,7 +3716,7 @@ fn struct_ctor_id(cx: ctxt, struct_did: ast::def_id) -> Option { cx.sess.unimpl(~"constructor ID of cross-crate tuple structs"); } - match cx.items.find(&struct_did.node) { + match cx.items.find(struct_did.node) { Some(ast_map::node_item(item, _)) => { match item.node { ast::item_struct(struct_def, _) => { @@ -3782,13 +3782,13 @@ impl DtorKind { /* If struct_id names a struct with a dtor, return Some(the dtor's id). Otherwise return none. */ pub fn ty_dtor(cx: ctxt, struct_id: def_id) -> DtorKind { - match cx.destructor_for_type.find(&struct_id) { + match cx.destructor_for_type.find(struct_id) { Some(method_def_id) => return TraitDtor(method_def_id), None => {} // Continue. } if is_local(struct_id) { - match cx.items.find(&struct_id.node) { + match cx.items.find(struct_id.node) { Some(ast_map::node_item(@ast::item { node: ast::item_struct(@ast::struct_def { dtor: Some(ref dtor), _ }, @@ -3816,7 +3816,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path { if id.crate != ast::local_crate { csearch::get_item_path(cx, id) } else { - let node = cx.items.get(&id.node); + let node = cx.items.get(id.node); match node { ast_map::node_item(item, path) => { let item_elt = match item.node { @@ -3880,7 +3880,7 @@ pub fn type_is_empty(cx: ctxt, t: t) -> bool { } pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] { - match cx.enum_var_cache.find(&id) { + match cx.enum_var_cache.find(id) { Some(variants) => return variants, _ => { /* fallthrough */ } } @@ -3893,7 +3893,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] { call eval_const_expr, it should never get called twice for the same expr, since check_enum_variants also updates the enum_var_cache */ - match cx.items.get(&id.node) { + match cx.items.get(id.node) { ast_map::node_item(@ast::item { node: ast::item_enum(ref enum_definition, _), _ @@ -3967,7 +3967,7 @@ pub fn enum_variant_with_id(cx: ctxt, pub fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_bounds_and_ty { - match cx.tcache.find(&did) { + match cx.tcache.find(did) { Some(tpt) => { // The item is in this crate. The caller should have added it to the // type cache already @@ -3993,7 +3993,7 @@ pub fn lookup_field_type(tcx: ctxt, node_id_to_type(tcx, id.node) } else { - match tcx.tcache.find(&id) { + match tcx.tcache.find(id) { Some(tpt) => tpt.ty, None => { let tpt = csearch::get_field_type(tcx, struct_id, id); @@ -4009,7 +4009,7 @@ pub fn lookup_field_type(tcx: ctxt, // Fails if the id is not bound to a struct. pub fn lookup_struct_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] { if did.crate == ast::local_crate { - match cx.items.find(&did.node) { + match cx.items.find(did.node) { Some(ast_map::node_item(i,_)) => { match i.node { ast::item_struct(struct_def, _) => { @@ -4214,7 +4214,7 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t { } } - match cx.normalized_cache.find(&t) { + match cx.normalized_cache.find(t) { Some(t) => return t, None => () } @@ -4397,8 +4397,8 @@ pub fn count_traits_and_supertraits(tcx: ctxt, // Given a trait and a type, returns the impl of that type pub fn get_impl_id(tcx: ctxt, trait_id: def_id, self_ty: t) -> def_id { - match tcx.trait_impls.find(&trait_id) { - Some(ty_to_impl) => match ty_to_impl.find(&self_ty) { + match tcx.trait_impls.find(trait_id) { + Some(ty_to_impl) => match ty_to_impl.find(self_ty) { Some(the_impl) => the_impl.did, None => // try autoderef! match deref(tcx, self_ty, false) { diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 070360ce32f..4e4fc564c23 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -211,7 +211,7 @@ pub fn ast_ty_to_ty( return ty::mk_evec(tcx, mt, vst); } ast::ty_path(path, id) if a_seq_ty.mutbl == ast::m_imm => { - match tcx.def_map.find(&id) { + match tcx.def_map.find(id) { Some(ast::def_prim_ty(ast::ty_str)) => { check_path_args(tcx, path, NO_TPS | NO_REGIONS); return ty::mk_estr(tcx, vst); @@ -273,7 +273,7 @@ pub fn ast_ty_to_ty( let tcx = self.tcx(); - match tcx.ast_ty_to_ty_cache.find(&ast_ty) { + match tcx.ast_ty_to_ty_cache.find(ast_ty) { Some(ty::atttce_resolved(ty)) => return ty, Some(ty::atttce_unresolved) => { tcx.sess.span_fatal(ast_ty.span, ~"illegal recursive type; \ @@ -330,7 +330,7 @@ pub fn ast_ty_to_ty( ty::mk_fn(tcx, fn_decl) } ast::ty_path(path, id) => { - let a_def = match tcx.def_map.find(&id) { + let a_def = match tcx.def_map.find(id) { None => tcx.sess.span_fatal( ast_ty.span, fmt!("unbound path %s", path_to_str(path, tcx.sess.intr()))), diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 1d84cb32c94..3e898ce3aa6 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -216,7 +216,7 @@ pub fn check_struct_pat_fields(pcx: pat_ctxt, // Typecheck each field. let found_fields = HashMap(); for fields.each |field| { - match field_map.find(&field.ident) { + match field_map.find(field.ident) { Some(index) => { let class_field = class_fields[index]; let field_type = ty::lookup_field_type(tcx, @@ -259,7 +259,7 @@ pub fn check_struct_pat(pcx: pat_ctxt, pat_id: ast::node_id, span: span, let class_fields = ty::lookup_struct_fields(tcx, class_id); // Check to ensure that the struct is the one specified. - match tcx.def_map.find(&pat_id) { + match tcx.def_map.find(pat_id) { Some(ast::def_struct(supplied_def_id)) if supplied_def_id == class_id => { // OK. @@ -300,7 +300,7 @@ pub fn check_struct_like_enum_variant_pat(pcx: pat_ctxt, let tcx = pcx.fcx.ccx.tcx; // Find the variant that was specified. - match tcx.def_map.find(&pat_id) { + match tcx.def_map.find(pat_id) { Some(ast::def_variant(found_enum_id, variant_id)) if found_enum_id == enum_id => { // Get the struct fields from this struct-like enum variant. @@ -360,7 +360,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { fcx.write_ty(pat.id, b_ty); } ast::pat_ident(*) if pat_is_const(tcx.def_map, pat) => { - let const_did = ast_util::def_id_of_def(tcx.def_map.get(&pat.id)); + let const_did = ast_util::def_id_of_def(tcx.def_map.get(pat.id)); let const_tpt = ty::lookup_item_type(tcx, const_did); fcx.write_ty(pat.id, const_tpt.ty); } @@ -386,7 +386,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { } } - let canon_id = pcx.map.get(&ast_util::path_to_ident(name)); + let canon_id = pcx.map.get(ast_util::path_to_ident(name)); if canon_id != pat.id { let ct = fcx.local_ty(pat.span, canon_id); demand::eqtype(fcx, pat.span, ct, typ); diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index b86f8f26c25..5a12f9fc3a1 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -323,15 +323,14 @@ pub impl LookupContext { // If the method being called is associated with a trait, then // find all the impls of that trait. Each of those are // candidates. - let opt_applicable_traits = self.fcx.ccx.trait_map.find( - &self.expr.id); + let opt_applicable_traits = self.fcx.ccx.trait_map.find(self.expr.id); for opt_applicable_traits.each |applicable_traits| { for applicable_traits.each |trait_did| { let coherence_info = self.fcx.ccx.coherence_info; // Look for explicit implementations. let opt_impl_infos = - coherence_info.extension_methods.find(trait_did); + coherence_info.extension_methods.find(*trait_did); for opt_impl_infos.each |impl_infos| { for impl_infos.each |impl_info| { self.push_candidates_from_impl( @@ -340,7 +339,7 @@ pub impl LookupContext { } // Look for default methods. - match self.tcx().provided_methods.find(trait_did) { + match self.tcx().provided_methods.find(*trait_did) { Some(methods) => { self.push_candidates_from_provided_methods( &self.extension_candidates, self_ty, *trait_did, @@ -361,7 +360,7 @@ pub impl LookupContext { let tcx = self.tcx(); let mut next_bound_idx = 0; // count only trait bounds - let bounds = tcx.ty_param_bounds.get(¶m_ty.def_id.node); + let bounds = tcx.ty_param_bounds.get(param_ty.def_id.node); for vec::each(*bounds) |bound| { let bound_trait_ty = match *bound { @@ -608,7 +607,7 @@ pub impl LookupContext { fn push_inherent_impl_candidates_for_type(did: def_id) { let opt_impl_infos = - self.fcx.ccx.coherence_info.inherent_methods.find(&did); + self.fcx.ccx.coherence_info.inherent_methods.find(did); for opt_impl_infos.each |impl_infos| { for impl_infos.each |impl_info| { self.push_candidates_from_impl( @@ -1233,7 +1232,7 @@ pub impl LookupContext { fn report_static_candidate(&self, idx: uint, did: def_id) { let span = if did.crate == ast::local_crate { - match self.tcx().items.find(&did.node) { + match self.tcx().items.find(did.node) { Some(ast_map::node_method(m, _, _)) => m.span, _ => die!(fmt!("report_static_candidate: bad item %?", did)) } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 1c0881b6ed5..f3abfe3282a 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -405,7 +405,7 @@ pub fn check_fn(ccx: @crate_ctxt, assign(self_info.self_id, Some(self_info.self_ty)); debug!("self is assigned to %s", fcx.infcx().ty_to_str( - fcx.inh.locals.get(&self_info.self_id))); + fcx.inh.locals.get(self_info.self_id))); } // Add formal parameters. @@ -438,7 +438,7 @@ pub fn check_fn(ccx: @crate_ctxt, debug!("Local variable %s is assigned type %s", fcx.pat_to_str(local.node.pat), fcx.infcx().ty_to_str( - fcx.inh.locals.get(&local.node.id))); + fcx.inh.locals.get(local.node.id))); visit::visit_local(local, e, v); }; @@ -451,7 +451,7 @@ pub fn check_fn(ccx: @crate_ctxt, debug!("Pattern binding %s is assigned to %s", tcx.sess.str_of(path.idents[0]), fcx.infcx().ty_to_str( - fcx.inh.locals.get(&p.id))); + fcx.inh.locals.get(p.id))); } _ => {} } @@ -501,7 +501,7 @@ pub fn check_no_duplicate_fields(tcx: ty::ctxt, for fields.each |p| { let (id, sp) = *p; - match field_names.find(&id) { + match field_names.find(id) { Some(orig_sp) => { tcx.sess.span_err(sp, fmt!("Duplicate field \ name %s in record type declaration", @@ -558,7 +558,7 @@ pub fn check_item(ccx: @crate_ctxt, it: @ast::item) { check_bare_fn(ccx, decl, (*body), it.id, None); } ast::item_impl(_, _, ty, ms) => { - let rp = ccx.tcx.region_paramd_items.find(&it.id); + let rp = ccx.tcx.region_paramd_items.find(it.id); debug!("item_impl %s with id %d rp %?", ccx.tcx.sess.str_of(it.ident), it.id, rp); let self_ty = ccx.to_ty(rscope::type_rscope(rp), ty); @@ -664,7 +664,7 @@ pub impl @fn_ctxt { fn tag() -> ~str { fmt!("%x", ptr::addr_of(&(*self)) as uint) } fn local_ty(span: span, nid: ast::node_id) -> ty::t { - match self.inh.locals.find(&nid) { + match self.inh.locals.find(nid) { Some(t) => t, None => { self.tcx().sess.span_bug( @@ -740,7 +740,7 @@ pub impl @fn_ctxt { } fn expr_ty(ex: @ast::expr) -> ty::t { - match self.inh.node_types.find(&ex.id) { + match self.inh.node_types.find(ex.id) { Some(t) => t, None => { self.tcx().sess.bug( @@ -750,7 +750,7 @@ pub impl @fn_ctxt { } } fn node_ty(id: ast::node_id) -> ty::t { - match self.inh.node_types.find(&id) { + match self.inh.node_types.find(id) { Some(t) => t, None => { self.tcx().sess.bug( @@ -763,7 +763,7 @@ pub impl @fn_ctxt { } } fn node_ty_substs(id: ast::node_id) -> ty::substs { - match self.inh.node_type_substs.find(&id) { + match self.inh.node_type_substs.find(id) { Some(ref ts) => (/*bad*/copy *ts), None => { self.tcx().sess.bug( @@ -776,7 +776,7 @@ pub impl @fn_ctxt { } } fn opt_node_ty_substs(id: ast::node_id) -> Option { - self.inh.node_type_substs.find(&id) + self.inh.node_type_substs.find(id) } @@ -1001,8 +1001,8 @@ pub fn impl_self_ty(vcx: &VtableContext, let tcx = vcx.tcx(); let {n_tps, region_param, raw_ty} = if did.crate == ast::local_crate { - let region_param = tcx.region_paramd_items.find(&did.node); - match tcx.items.find(&did.node) { + let region_param = tcx.region_paramd_items.find(did.node); + match tcx.items.find(did.node) { Some(ast_map::node_item(@ast::item { node: ast::item_impl(ref ts, _, st, _), _ @@ -1698,7 +1698,7 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, // Typecheck each field. for ast_fields.each |field| { - match class_field_map.find(&field.node.ident) { + match class_field_map.find(field.node.ident) { None => { tcx.sess.span_err( field.span, @@ -1734,7 +1734,7 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, let mut missing_fields = ~[]; for field_types.each |class_field| { let name = class_field.ident; - let (_, seen) = class_field_map.get(&name); + let (_, seen) = class_field_map.get(name); if !seen { missing_fields.push( ~"`" + tcx.sess.str_of(name) + ~"`"); @@ -1769,8 +1769,8 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, let type_parameter_count, region_parameterized, raw_type; if class_id.crate == ast::local_crate { region_parameterized = - tcx.region_paramd_items.find(&class_id.node); - match tcx.items.find(&class_id.node) { + tcx.region_paramd_items.find(class_id.node); + match tcx.items.find(class_id.node) { Some(ast_map::node_item(@ast::item { node: ast::item_struct(_, ref type_parameters), _ @@ -1852,8 +1852,8 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, let type_parameter_count, region_parameterized, raw_type; if enum_id.crate == ast::local_crate { region_parameterized = - tcx.region_paramd_items.find(&enum_id.node); - match tcx.items.find(&enum_id.node) { + tcx.region_paramd_items.find(enum_id.node); + match tcx.items.find(enum_id.node) { Some(ast_map::node_item(@ast::item { node: ast::item_enum(_, ref type_parameters), _ @@ -2435,7 +2435,7 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, } ast::expr_struct(path, ref fields, base_expr) => { // Resolve the path. - match tcx.def_map.find(&id) { + match tcx.def_map.find(id) { Some(ast::def_struct(type_def_id)) => { check_struct_constructor(fcx, id, expr.span, type_def_id, (/*bad*/copy *fields), base_expr); @@ -2532,7 +2532,7 @@ pub fn check_decl_local(fcx: @fn_ctxt, local: @ast::local) -> bool { } let region = - ty::re_scope(tcx.region_map.get(&local.node.id)); + ty::re_scope(tcx.region_map.get(local.node.id)); let pcx = pat_ctxt { fcx: fcx, map: pat_id_map(tcx.def_map, local.node.pat), @@ -2633,7 +2633,7 @@ pub fn check_const(ccx: @crate_ctxt, id: ast::node_id) { let rty = ty::node_id_to_type(ccx.tcx, id); let fcx = blank_fn_ctxt(ccx, rty, e.id); - let declty = fcx.ccx.tcx.tcache.get(&local_def(id)).ty; + let declty = fcx.ccx.tcx.tcache.get(local_def(id)).ty; check_const_with_ty(fcx, _sp, e, declty); } @@ -2984,7 +2984,7 @@ pub fn may_break(cx: ty::ctxt, id: ast::node_id, b: ast::blk) -> bool { (block_query(b, |e| { match e.node { ast::expr_break(Some(_)) => - match cx.def_map.find(&e.id) { + match cx.def_map.find(e.id) { Some(ast::def_label(loop_id)) if id == loop_id => true, _ => false, }, @@ -3080,8 +3080,8 @@ pub fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) { let ty_visitor_name = tcx.sess.ident_of(~"TyVisitor"); assert tcx.intrinsic_defs.contains_key_ref(&tydesc_name); assert ccx.tcx.intrinsic_defs.contains_key_ref(&ty_visitor_name); - let (_, tydesc_ty) = tcx.intrinsic_defs.get(&tydesc_name); - let (_, visitor_trait) = tcx.intrinsic_defs.get(&ty_visitor_name); + let (_, tydesc_ty) = tcx.intrinsic_defs.get(tydesc_name); + let (_, visitor_trait) = tcx.intrinsic_defs.get(ty_visitor_name); let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt {ty: tydesc_ty, mutbl: ast::m_imm}); (0u, ~[arg(ast::by_val, td_ptr), diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 952c1a9fcd8..9ae55d4556b 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -181,7 +181,7 @@ pub fn visit_block(b: ast::blk, &&rcx: @rcx, v: rvt) { pub fn visit_expr(expr: @ast::expr, &&rcx: @rcx, v: rvt) { debug!("visit_expr(e=%s)", rcx.fcx.expr_to_str(expr)); - for rcx.fcx.inh.adjustments.find(&expr.id).each |adjustment| { + for rcx.fcx.inh.adjustments.find(expr.id).each |adjustment| { for adjustment.autoref.each |autoref| { guarantor::for_autoref(rcx, expr, *adjustment, autoref); } @@ -327,7 +327,7 @@ pub fn constrain_auto_ref(rcx: @rcx, expr: @ast::expr) { debug!("constrain_auto_ref(expr=%s)", rcx.fcx.expr_to_str(expr)); - let adjustment = rcx.fcx.inh.adjustments.find(&expr.id); + let adjustment = rcx.fcx.inh.adjustments.find(expr.id); let region = match adjustment { Some(@ty::AutoAdjustment { autoref: Some(ref auto_ref), _ }) => { auto_ref.region @@ -725,7 +725,7 @@ pub mod guarantor { let mut expr_ct = categorize_unadjusted(rcx, expr); debug!("before adjustments, cat=%?", expr_ct.cat); - for rcx.fcx.inh.adjustments.find(&expr.id).each |adjustment| { + for rcx.fcx.inh.adjustments.find(expr.id).each |adjustment| { debug!("adjustment=%?", adjustment); expr_ct = apply_autoderefs( diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 9f2af3ec003..18a4f20d031 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -194,7 +194,7 @@ pub fn lookup_vtable(vcx: &VtableContext, match ty::get(ty).sty { ty::ty_param(param_ty {idx: n, def_id: did}) => { let mut n_bound = 0; - let bounds = tcx.ty_param_bounds.get(&did.node); + let bounds = tcx.ty_param_bounds.get(did.node); for ty::iter_bound_traits_and_supertraits( tcx, bounds) |ity| { debug!("checking bounds trait %?", @@ -255,7 +255,7 @@ pub fn lookup_vtable(vcx: &VtableContext, let mut impls_seen = HashMap(); - match vcx.ccx.coherence_info.extension_methods.find(&trait_id) { + match vcx.ccx.coherence_info.extension_methods.find(trait_id) { None => { // Nothing found. Continue. } @@ -525,7 +525,7 @@ pub fn early_resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, is_early: bool) { ast::expr_path(*) => { match fcx.opt_node_ty_substs(ex.id) { Some(ref substs) => { - let def = cx.tcx.def_map.get(&ex.id); + let def = cx.tcx.def_map.get(ex.id); let did = ast_util::def_id_of_def(def); let item_ty = ty::lookup_item_type(cx.tcx, did); debug!("early resolve expr: def %? %?, %?, %?", ex.id, did, def, diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index fab64c88b53..64ea45c8704 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -55,7 +55,7 @@ fn resolve_type_vars_in_type(fcx: @fn_ctxt, sp: span, typ: ty::t) fn resolve_method_map_entry(fcx: @fn_ctxt, sp: span, id: ast::node_id) { // Resolve any method map entry - match fcx.ccx.method_map.find(&id) { + match fcx.ccx.method_map.find(id) { None => {} Some(ref mme) => { for resolve_type_vars_in_type(fcx, sp, mme.self_arg.ty).each |t| { @@ -77,7 +77,7 @@ fn resolve_type_vars_for_node(wbcx: wb_ctxt, sp: span, id: ast::node_id) let fcx = wbcx.fcx, tcx = fcx.ccx.tcx; // Resolve any borrowings for the node with id `id` - match fcx.inh.adjustments.find(&id) { + match fcx.inh.adjustments.find(id) { None => (), Some(adj) => { let resolved_autoref = match adj.autoref { diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 324cdcc261f..5ad8fd4c820 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -236,8 +236,7 @@ pub impl CoherenceChecker { } fn check_implementation(item: @item, associated_traits: ~[@trait_ref]) { - let self_type = self.crate_context.tcx.tcache.get( - &local_def(item.id)); + let self_type = self.crate_context.tcx.tcache.get(local_def(item.id)); // If there are no traits, then this implementation must have a // base type. @@ -355,7 +354,7 @@ pub impl CoherenceChecker { }; let pmm = self.crate_context.tcx.provided_methods; - match pmm.find(&local_def(impl_id)) { + match pmm.find(local_def(impl_id)) { Some(mis) => { // If the trait already has an entry in the // provided_methods_map, we just need to add this @@ -383,7 +382,7 @@ pub impl CoherenceChecker { fn add_inherent_method(base_def_id: def_id, implementation: @Impl) { let implementation_list; match self.crate_context.coherence_info.inherent_methods - .find(&base_def_id) { + .find(base_def_id) { None => { implementation_list = @DVec(); self.crate_context.coherence_info.inherent_methods @@ -400,7 +399,7 @@ pub impl CoherenceChecker { fn add_trait_method(trait_id: def_id, implementation: @Impl) { let implementation_list; match self.crate_context.coherence_info.extension_methods - .find(&trait_id) { + .find(trait_id) { None => { implementation_list = @DVec(); self.crate_context.coherence_info.extension_methods @@ -463,7 +462,7 @@ pub impl CoherenceChecker { debug!("Adding impl %? of %? for %s", the_impl.did, trait_t, ty_to_str(self.crate_context.tcx, self_t)); - match self.crate_context.tcx.trait_impls.find(&trait_t) { + match self.crate_context.tcx.trait_impls.find(trait_t) { None => { let m = HashMap(); m.insert(self_t, the_impl); @@ -481,7 +480,7 @@ pub impl CoherenceChecker { let coherence_info = &self.crate_context.coherence_info; let extension_methods = &coherence_info.extension_methods; - match extension_methods.find(&trait_def_id) { + match extension_methods.find(trait_def_id) { Some(impls) => { for uint::range(0, impls.len()) |i| { f(impls[i]); @@ -613,7 +612,7 @@ pub impl CoherenceChecker { fn get_self_type_for_implementation(implementation: @Impl) -> ty_param_bounds_and_ty { - return self.crate_context.tcx.tcache.get(&implementation.did); + return self.crate_context.tcx.tcache.get(implementation.did); } // Privileged scope checking @@ -628,7 +627,7 @@ pub impl CoherenceChecker { item_impl(_, opt_trait, _, _) => { let mut ok = false; match self.base_type_def_ids.find( - &local_def(item.id)) { + local_def(item.id)) { None => { // Nothing to do. @@ -702,7 +701,7 @@ pub impl CoherenceChecker { fn trait_ref_to_trait_def_id(trait_ref: @trait_ref) -> def_id { let def_map = self.crate_context.tcx.def_map; - let trait_def = def_map.get(&trait_ref.ref_id); + let trait_def = def_map.get(trait_ref.ref_id); let trait_id = def_id_of_def(trait_def); return trait_id; } @@ -775,7 +774,7 @@ pub impl CoherenceChecker { match self.crate_context.tcx .provided_methods - .find(&local_def(item.id)) { + .find(local_def(item.id)) { None => { debug!("(creating impl) trait with node_id `%d` \ has no provided methods", trait_did.node); @@ -809,7 +808,7 @@ pub impl CoherenceChecker { fn span_of_impl(implementation: @Impl) -> span { assert implementation.did.crate == local_crate; - match self.crate_context.tcx.items.find(&implementation.did.node) { + match self.crate_context.tcx.items.find(implementation.did.node) { Some(node_item(item, _)) => { return item.span; } @@ -837,7 +836,7 @@ pub impl CoherenceChecker { // Make sure we don't visit the same implementation // multiple times. - match impls_seen.find(&implementation.did) { + match impls_seen.find(implementation.did) { None => { // Good. Continue. impls_seen.insert(implementation.did, ()); @@ -989,7 +988,7 @@ pub impl CoherenceChecker { let coherence_info = &self.crate_context.coherence_info; let tcx = self.crate_context.tcx; let drop_trait = tcx.lang_items.drop_trait(); - let impls_opt = coherence_info.extension_methods.find(&drop_trait); + let impls_opt = coherence_info.extension_methods.find(drop_trait); let impls; match impls_opt { @@ -1014,7 +1013,7 @@ pub impl CoherenceChecker { _ => { // Destructors only work on nominal types. if impl_info.did.crate == ast::local_crate { - match tcx.items.find(&impl_info.did.node) { + match tcx.items.find(impl_info.did.node) { Some(ast_map::node_item(@ref item, _)) => { tcx.sess.span_err((*item).span, ~"the Drop trait may only \ diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index b7b7899883b..32d92489188 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -130,7 +130,7 @@ pub impl @crate_ctxt: ast_conv { if id.crate != ast::local_crate { csearch::get_type(self.tcx, id) } else { - match self.tcx.items.find(&id.node) { + match self.tcx.items.find(id.node) { Some(ast_map::node_item(item, _)) => { ty_of_item(self, item) } @@ -290,8 +290,8 @@ pub fn ensure_trait_methods(ccx: @crate_ctxt, let tcx = ccx.tcx; - let region_paramd = tcx.region_paramd_items.find(&id); - match tcx.items.get(&id) { + let region_paramd = tcx.region_paramd_items.find(id); + match tcx.items.get(id) { ast_map::node_item(@ast::item { node: ast::item_trait(ref params, _, ref ms), _ @@ -521,7 +521,7 @@ pub fn check_methods_against_trait(ccx: @crate_ctxt, // trait ref. Otherwise, we will potentially overwrite the types of // the methods within the trait with bogus results. (See issue #3903.) - match tcx.items.find(&did.node) { + match tcx.items.find(did.node) { Some(ast_map::node_item(item, _)) => { let tpt = ty_of_item(ccx, item); ensure_trait_methods(ccx, did.node, tpt.ty); @@ -616,7 +616,7 @@ pub fn ensure_no_ty_param_bounds(ccx: @crate_ctxt, pub fn convert(ccx: @crate_ctxt, it: @ast::item) { let tcx = ccx.tcx; - let rp = tcx.region_paramd_items.find(&it.id); + let rp = tcx.region_paramd_items.find(it.id); debug!("convert: item %s with id %d rp %?", tcx.sess.str_of(it.ident), it.id, rp); match /*bad*/copy it.node { @@ -740,7 +740,7 @@ pub fn convert_struct(ccx: @crate_ctxt, arg { mode: ast::expl(ast::by_copy), ty: ccx.tcx.tcache.get - (&local_def(field.node.id)).ty + (local_def(field.node.id)).ty } }, output: selfty @@ -830,11 +830,11 @@ pub fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) let def_id = local_def(it.id); let tcx = ccx.tcx; - match tcx.tcache.find(&def_id) { + match tcx.tcache.find(def_id) { Some(tpt) => return tpt, _ => {} } - let rp = tcx.region_paramd_items.find(&it.id); + let rp = tcx.region_paramd_items.find(it.id); match /*bad*/copy it.node { ast::item_const(t, _) => { let typ = ccx.to_ty(empty_rscope, t); @@ -859,12 +859,12 @@ pub fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) return tpt; } ast::item_ty(t, tps) => { - match tcx.tcache.find(&local_def(it.id)) { + match tcx.tcache.find(local_def(it.id)) { Some(tpt) => return tpt, None => { } } - let rp = tcx.region_paramd_items.find(&it.id); + let rp = tcx.region_paramd_items.find(it.id); let tpt = { let ty = { let t0 = ccx.to_ty(type_rscope(rp), t); @@ -978,7 +978,7 @@ pub fn compute_bounds(ccx: @crate_ctxt, pub fn ty_param_bounds(ccx: @crate_ctxt, params: ~[ast::ty_param]) -> @~[ty::param_bounds] { @do params.map |param| { - match ccx.tcx.ty_param_bounds.find(¶m.id) { + match ccx.tcx.ty_param_bounds.find(param.id) { Some(bs) => bs, None => { let bounds = compute_bounds(ccx, param.bounds); diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index 0d4e520122f..1a8e25239b3 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -912,7 +912,7 @@ pub impl RegionVarBindings { -> cres { let vars = TwoRegions { a: a, b: b }; - match combines.find(&vars) { + match combines.find(vars) { Some(c) => Ok(re_infer(ReVar(c))), None => { let c = self.new_region_var(span); diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 742646618bd..d292f04caa4 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -225,7 +225,7 @@ pub fn write_substs_to_tcx(tcx: ty::ctxt, } pub fn lookup_def_tcx(tcx: ty::ctxt, sp: span, id: ast::node_id) -> ast::def { - match tcx.def_map.find(&id) { + match tcx.def_map.find(id) { Some(x) => x, _ => { tcx.sess.span_fatal(sp, ~"internal error looking up a definition") @@ -325,7 +325,7 @@ fn check_main_fn_ty(ccx: @crate_ctxt, let main_t = ty::node_id_to_type(tcx, main_id); match ty::get(main_t).sty { ty::ty_fn(ref fn_ty) => { - match tcx.items.find(&main_id) { + match tcx.items.find(main_id) { Some(ast_map::node_item(it,_)) => { match it.node { ast::item_fn(_, _, ref ps, _) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 9e70a6ab130..2ed2d3ea5d7 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -67,7 +67,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region) -> (~str, Option) { return match region { re_scope(node_id) => { - match cx.items.find(&node_id) { + match cx.items.find(node_id) { Some(ast_map::node_block(ref blk)) => { explain_span(cx, "block", (*blk).span) } @@ -105,7 +105,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region) bound_region_to_str(cx, br)) }; - match cx.items.find(&id) { + match cx.items.find(id) { Some(ast_map::node_block(ref blk)) => { let (msg, opt_span) = explain_span(cx, "block", (*blk).span); (fmt!("%s %s", prefix, msg), opt_span) @@ -154,7 +154,7 @@ pub fn bound_region_to_str_adorned(cx: ctxt, prefix: &str, } pub fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str { - match cx.items.find(&node_id) { + match cx.items.find(node_id) { Some(ast_map::node_block(ref blk)) => { fmt!("", cx.sess.codemap.span_to_str((*blk).span)) diff --git a/src/librustdoc/attr_pass.rs b/src/librustdoc/attr_pass.rs index c595ebce65f..0e70900520d 100644 --- a/src/librustdoc/attr_pass.rs +++ b/src/librustdoc/attr_pass.rs @@ -116,7 +116,7 @@ fn parse_item_attrs( id: doc::AstId, parse_attrs: fn~(a: ~[ast::attribute]) -> T) -> T { do astsrv::exec(srv) |move parse_attrs, ctxt| { - let attrs = match ctxt.ast_map.get(&id) { + let attrs = match ctxt.ast_map.get(id) { ast_map::node_item(item, _) => copy item.attrs, ast_map::node_foreign_item(item, _, _) => copy item.attrs, _ => die!(~"parse_item_attrs: not an item") @@ -170,7 +170,7 @@ fn fold_enum( let desc = { let variant = copy variant; do astsrv::exec(srv.clone()) |ctxt| { - match ctxt.ast_map.get(&doc_id) { + match ctxt.ast_map.get(doc_id) { ast_map::node_item(@ast::item { node: ast::item_enum(ref enum_definition, _), _ }, _) => { @@ -234,7 +234,7 @@ fn merge_method_attrs( // Create an assoc list from method name to attributes let attrs: ~[(~str, Option<~str>)] = do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(&item_id) { + match ctxt.ast_map.get(item_id) { ast_map::node_item(@ast::item { node: ast::item_trait(_, _, ref methods), _ }, _) => { diff --git a/src/librustdoc/prune_hidden_pass.rs b/src/librustdoc/prune_hidden_pass.rs index 97258d99ba4..f039bb74583 100644 --- a/src/librustdoc/prune_hidden_pass.rs +++ b/src/librustdoc/prune_hidden_pass.rs @@ -56,7 +56,7 @@ fn is_hidden(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool { let id = doc.id; do astsrv::exec(srv) |ctxt| { - let attrs = match ctxt.ast_map.get(&id) { + let attrs = match ctxt.ast_map.get(id) { ast_map::node_item(item, _) => copy item.attrs, _ => ~[] }; diff --git a/src/librustdoc/prune_private_pass.rs b/src/librustdoc/prune_private_pass.rs index 1acb6092e2c..4b47b71449a 100644 --- a/src/librustdoc/prune_private_pass.rs +++ b/src/librustdoc/prune_private_pass.rs @@ -59,7 +59,7 @@ fn is_visible(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool { let id = doc.id; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(&id) { + match ctxt.ast_map.get(id) { ast_map::node_item(item, _) => { item.vis == ast::public } diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index 58a2e0e1324..4ab40530cfb 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -68,7 +68,7 @@ fn fold_fn( fn get_fn_sig(srv: astsrv::Srv, fn_id: doc::AstId) -> Option<~str> { do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(&fn_id) { + match ctxt.ast_map.get(fn_id) { ast_map::node_item(@ast::item { ident: ident, node: ast::item_fn(ref decl, _, ref tys, _), _ @@ -107,7 +107,7 @@ fn fold_const( sig: Some({ let doc = copy doc; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(&doc.id()) { + match ctxt.ast_map.get(doc.id()) { ast_map::node_item(@ast::item { node: ast::item_const(ty, _), _ }, _) => { @@ -138,7 +138,7 @@ fn fold_enum( let sig = { let variant = copy *variant; do astsrv::exec(srv.clone()) |copy variant, ctxt| { - match ctxt.ast_map.get(&doc_id) { + match ctxt.ast_map.get(doc_id) { ast_map::node_item(@ast::item { node: ast::item_enum(ref enum_definition, _), _ }, _) => { @@ -199,7 +199,7 @@ fn get_method_sig( method_name: ~str ) -> Option<~str> { do astsrv::exec(srv) |copy method_name, ctxt| { - match ctxt.ast_map.get(&item_id) { + match ctxt.ast_map.get(item_id) { ast_map::node_item(@ast::item { node: ast::item_trait(_, _, ref methods), _ }, _) => { @@ -271,7 +271,7 @@ fn fold_impl( let (trait_types, self_ty) = { let doc = copy doc; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(&doc.id()) { + match ctxt.ast_map.get(doc.id()) { ast_map::node_item(@ast::item { node: ast::item_impl(_, opt_trait_type, self_ty, _), _ }, _) => { @@ -331,7 +331,7 @@ fn fold_type( sig: { let doc = copy doc; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(&doc.id()) { + match ctxt.ast_map.get(doc.id()) { ast_map::node_item(@ast::item { ident: ident, node: ast::item_ty(ty, ref params), _ @@ -369,7 +369,7 @@ fn fold_struct( sig: { let doc = copy doc; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(&doc.id()) { + match ctxt.ast_map.get(doc.id()) { ast_map::node_item(item, _) => { let item = strip_struct_extra_stuff(item); Some(pprust::item_to_str(item, diff --git a/src/libstd/oldmap.rs b/src/libstd/oldmap.rs index 18cfc8d4a2d..a4d4a4e806b 100644 --- a/src/libstd/oldmap.rs +++ b/src/libstd/oldmap.rs @@ -226,9 +226,9 @@ pub mod chained { } } - pure fn find(&self, k: &K) -> Option { + pure fn find(&self, k: K) -> Option { unsafe { - match self.search_tbl(k, k.hash_keyed(0,0) as uint) { + match self.search_tbl(&k, k.hash_keyed(0,0) as uint) { NotFound => None, FoundFirst(_, entry) => Some(entry.value), FoundAfter(_, entry) => Some(entry.value) @@ -291,7 +291,7 @@ pub mod chained { return self.update_with_key(key, newval, |_k, v, v1| ff(v,v1)); } - pure fn get(&self, k: &K) -> V { + pure fn get(&self, k: K) -> V { let opt_v = self.find(k); if opt_v.is_none() { die!(fmt!("Key not found in table: %?", k)); @@ -364,7 +364,7 @@ pub mod chained { impl T: ops::Index { pure fn index(&self, k: K) -> V { unsafe { - self.get(&k) + self.get(k) } } } @@ -421,6 +421,7 @@ pub fn hash_from_vec( #[cfg(test)] mod tests { use core::option::None; + use core::option; use core::uint; use super::*; @@ -436,13 +437,13 @@ mod tests { assert (hm_uu.insert(10u, 12u)); assert (hm_uu.insert(11u, 13u)); assert (hm_uu.insert(12u, 14u)); - assert (hm_uu.get(&11) == 13u); - assert (hm_uu.get(&12) == 14u); - assert (hm_uu.get(&10) == 12u); + assert (hm_uu.get(11u) == 13u); + assert (hm_uu.get(12u) == 14u); + assert (hm_uu.get(10u) == 12u); assert (!hm_uu.insert(12u, 14u)); - assert (hm_uu.get(&12) == 14u); + assert (hm_uu.get(12u) == 14u); assert (!hm_uu.insert(12u, 12u)); - assert (hm_uu.get(&12) == 12u); + assert (hm_uu.get(12u) == 12u); let ten: ~str = ~"ten"; let eleven: ~str = ~"eleven"; let twelve: ~str = ~"twelve"; @@ -452,40 +453,40 @@ mod tests { assert (hm_su.insert(~"ten", 12u)); assert (hm_su.insert(eleven, 13u)); assert (hm_su.insert(~"twelve", 14u)); - assert (hm_su.get(&eleven) == 13u); - assert (hm_su.get(&~"eleven") == 13u); - assert (hm_su.get(&~"twelve") == 14u); - assert (hm_su.get(&~"ten") == 12u); + assert (hm_su.get(eleven) == 13u); + assert (hm_su.get(~"eleven") == 13u); + assert (hm_su.get(~"twelve") == 14u); + assert (hm_su.get(~"ten") == 12u); assert (!hm_su.insert(~"twelve", 14u)); - assert (hm_su.get(&~"twelve") == 14u); + assert (hm_su.get(~"twelve") == 14u); assert (!hm_su.insert(~"twelve", 12u)); - assert (hm_su.get(&~"twelve") == 12u); + assert (hm_su.get(~"twelve") == 12u); debug!("uint -> str"); let hm_us: HashMap = HashMap::(); assert (hm_us.insert(10u, ~"twelve")); assert (hm_us.insert(11u, ~"thirteen")); assert (hm_us.insert(12u, ~"fourteen")); - assert hm_us.get(&11) == ~"thirteen"; - assert hm_us.get(&12) == ~"fourteen"; - assert hm_us.get(&10) == ~"twelve"; + assert hm_us.get(11u) == ~"thirteen"; + assert hm_us.get(12u) == ~"fourteen"; + assert hm_us.get(10u) == ~"twelve"; assert (!hm_us.insert(12u, ~"fourteen")); - assert hm_us.get(&12) == ~"fourteen"; + assert hm_us.get(12u) == ~"fourteen"; assert (!hm_us.insert(12u, ~"twelve")); - assert hm_us.get(&12) == ~"twelve"; + assert hm_us.get(12u) == ~"twelve"; debug!("str -> str"); let hm_ss: HashMap<~str, ~str> = HashMap::<~str, ~str>(); assert (hm_ss.insert(ten, ~"twelve")); assert (hm_ss.insert(eleven, ~"thirteen")); assert (hm_ss.insert(twelve, ~"fourteen")); - assert hm_ss.get(&~"eleven") == ~"thirteen"; - assert hm_ss.get(&~"twelve") == ~"fourteen"; - assert hm_ss.get(&~"ten") == ~"twelve"; + assert hm_ss.get(~"eleven") == ~"thirteen"; + assert hm_ss.get(~"twelve") == ~"fourteen"; + assert hm_ss.get(~"ten") == ~"twelve"; assert (!hm_ss.insert(~"twelve", ~"fourteen")); - assert hm_ss.get(&~"twelve") == ~"fourteen"; + assert hm_ss.get(~"twelve") == ~"fourteen"; assert (!hm_ss.insert(~"twelve", ~"twelve")); - assert hm_ss.get(&~"twelve") == ~"twelve"; + assert hm_ss.get(~"twelve") == ~"twelve"; debug!("*** finished test_simple"); } @@ -511,17 +512,17 @@ mod tests { debug!("-----"); i = 0u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm_uu.get(&i)); - assert (hm_uu.get(&i) == i * i); + debug!("get(%u) = %u", i, hm_uu.get(i)); + assert (hm_uu.get(i) == i * i); i += 1u; } assert (hm_uu.insert(num_to_insert, 17u)); - assert (hm_uu.get(&num_to_insert) == 17u); + assert (hm_uu.get(num_to_insert) == 17u); debug!("-----"); i = 0u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm_uu.get(&i)); - assert (hm_uu.get(&i) == i * i); + debug!("get(%u) = %u", i, hm_uu.get(i)); + assert (hm_uu.get(i) == i * i); i += 1u; } debug!("str -> str"); @@ -541,22 +542,22 @@ mod tests { while i < num_to_insert { debug!("get(\"%s\") = \"%s\"", uint::to_str_radix(i, 2u), - hm_ss.get(&uint::to_str_radix(i, 2u))); - assert hm_ss.get(&uint::to_str_radix(i, 2u)) == + hm_ss.get(uint::to_str_radix(i, 2u))); + assert hm_ss.get(uint::to_str_radix(i, 2u)) == uint::to_str_radix(i * i, 2u); i += 1u; } assert (hm_ss.insert(uint::to_str_radix(num_to_insert, 2u), uint::to_str_radix(17u, 2u))); - assert hm_ss.get(&uint::to_str_radix(num_to_insert, 2u)) == + assert hm_ss.get(uint::to_str_radix(num_to_insert, 2u)) == uint::to_str_radix(17u, 2u); debug!("-----"); i = 0u; while i < num_to_insert { debug!("get(\"%s\") = \"%s\"", uint::to_str_radix(i, 2u), - hm_ss.get(&uint::to_str_radix(i, 2u))); - assert hm_ss.get(&uint::to_str_radix(i, 2u)) == + hm_ss.get(uint::to_str_radix(i, 2u))); + assert hm_ss.get(uint::to_str_radix(i, 2u)) == uint::to_str_radix(i * i, 2u); i += 1u; } @@ -588,15 +589,15 @@ mod tests { debug!("-----"); i = 1u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm.get(&i)); - assert (hm.get(&i) == i * i); + debug!("get(%u) = %u", i, hm.get(i)); + assert (hm.get(i) == i * i); i += 2u; } debug!("-----"); i = 1u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm.get(&i)); - assert (hm.get(&i) == i * i); + debug!("get(%u) = %u", i, hm.get(i)); + assert (hm.get(i) == i * i); i += 2u; } debug!("-----"); @@ -610,16 +611,16 @@ mod tests { debug!("-----"); i = 0u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm.get(&i)); - assert (hm.get(&i) == i * i); + debug!("get(%u) = %u", i, hm.get(i)); + assert (hm.get(i) == i * i); i += 1u; } debug!("-----"); assert (hm.len() == num_to_insert); i = 0u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm.get(&i)); - assert (hm.get(&i) == i * i); + debug!("get(%u) = %u", i, hm.get(i)); + assert (hm.get(i) == i * i); i += 1u; } debug!("*** finished test_removal"); @@ -638,9 +639,9 @@ mod tests { fn test_find() { let key = ~"k"; let map = HashMap::<~str, ~str>(); - assert map.find(&key).is_none(); + assert (option::is_none(&map.find(key))); map.insert(key, ~"val"); - assert map.find(&key).get() == ~"val"; + assert (option::get(map.find(key)) == ~"val"); } #[test] @@ -663,9 +664,9 @@ mod tests { (~"c", 3) ]); assert map.len() == 3u; - assert map.get(&~"a") == 1; - assert map.get(&~"b") == 2; - assert map.get(&~"c") == 3; + assert map.get(~"a") == 1; + assert map.get(~"b") == 2; + assert map.get(~"c") == 3; } #[test] @@ -691,11 +692,11 @@ mod tests { map.update_with_key(~"cat", 2, addMoreToCount); // check the total counts - assert map.find(&~"cat").get() == 10; - assert map.find(&~"ferret").get() == 3; - assert map.find(&~"mongoose").get() == 1; + assert 10 == option::get(map.find(~"cat")); + assert 3 == option::get(map.find(~"ferret")); + assert 1 == option::get(map.find(~"mongoose")); // sadly, no mythical animals were counted! - assert map.find(&~"unicorn").is_none(); + assert None == map.find(~"unicorn"); } } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index fe41cee919f..e6a4639ad80 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -333,7 +333,7 @@ pub fn map_stmt(stmt: @stmt, cx: ctx, v: vt) { } pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { - match map.find(&id) { + match map.find(id) { None => { fmt!("unknown node (id=%d)", id) } @@ -398,7 +398,7 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { pub fn node_item_query(items: map, id: node_id, query: fn(@item) -> Result, error_msg: ~str) -> Result { - match items.find(&id) { + match items.find(id) { Some(node_item(it, _)) => query(it), _ => die!(error_msg) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 18256369c78..227a86e0766 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -40,7 +40,7 @@ pub fn expand_expr(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt, /* using idents and token::special_idents would make the the macro names be hygienic */ let extname = cx.parse_sess().interner.get(pth.idents[0]); - match exts.find(extname) { + match exts.find(*extname) { None => { cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)) @@ -104,7 +104,7 @@ pub fn expand_mod_items(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt, ast::meta_name_value(ref n, _) => (*n), ast::meta_list(ref n, _) => (*n) }; - match exts.find(&mname) { + match exts.find(mname) { None | Some(NormalTT(_)) | Some(ItemTT(*)) => items, Some(ItemDecorator(dec_fn)) => { cx.bt_push(ExpandedFrom({call_site: attr.span, @@ -161,7 +161,7 @@ pub fn expand_item_mac(exts: HashMap<~str, SyntaxExtension>, }; let extname = cx.parse_sess().interner.get(pth.idents[0]); - let expanded = match exts.find(extname) { + let expanded = match exts.find(*extname) { None => cx.span_fatal(pth.span, fmt!("macro undefined: '%s!'", *extname)), @@ -224,7 +224,7 @@ pub fn expand_stmt(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt, assert(vec::len(pth.idents) == 1u); let extname = cx.parse_sess().interner.get(pth.idents[0]); - let (fully_expanded, sp) = match exts.find(extname) { + let (fully_expanded, sp) = match exts.find(*extname) { None => cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)), diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 3e7a84240e4..31172cbfa85 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -59,11 +59,11 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, arg_reader as reader, argument_gram); // Extract the arguments: - let lhses:~[@named_match] = match argument_map.get(&lhs_nm) { + let lhses:~[@named_match] = match argument_map.get(lhs_nm) { @matched_seq(s, _) => s, _ => cx.span_bug(sp, ~"wrong-structured lhs") }; - let rhses:~[@named_match] = match argument_map.get(&rhs_nm) { + let rhses:~[@named_match] = match argument_map.get(rhs_nm) { @matched_seq(s, _) => s, _ => cx.span_bug(sp, ~"wrong-structured rhs") }; diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 6f57ca38f1f..6bf90617a6e 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -111,7 +111,7 @@ pure fn lookup_cur_matched_by_matched(r: tt_reader, } fn lookup_cur_matched(r: tt_reader, name: ident) -> @named_match { - lookup_cur_matched_by_matched(r, r.interpolations.get(&name)) + lookup_cur_matched_by_matched(r, r.interpolations.get(name)) } enum lis { lis_unconstrained, lis_constraint(uint, ident), lis_contradiction(~str) diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 905571d1817..19b938ccd68 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -44,7 +44,7 @@ pub trait Interner { pub impl hash_interner: Interner { fn intern(val: T) -> uint { - match self.map.find(&val) { + match self.map.find(val) { Some(idx) => return idx, None => { let new_idx = self.vect.len(); diff --git a/src/test/auxiliary/issue-2631-a.rs b/src/test/auxiliary/issue-2631-a.rs index 8679d3a7786..748c209229c 100644 --- a/src/test/auxiliary/issue-2631-a.rs +++ b/src/test/auxiliary/issue-2631-a.rs @@ -20,5 +20,5 @@ pub type header_map = HashMap<~str, @DVec<@~str>>; // the unused ty param is necessary so this gets monomorphized pub fn request(req: header_map) { - let _x = copy *(copy *req.get(&~"METHOD"))[0u]; + let _x = copy *(copy *req.get(~"METHOD"))[0u]; } diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index 68ba40749f2..67c071da26d 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -42,7 +42,7 @@ fn old_int_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { } for uint::range(0, num_keys) |i| { - assert map.get(&i) == i+1; + assert map.get(i) == i+1; } } } @@ -81,7 +81,7 @@ fn old_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { for uint::range(0, num_keys) |i| { let s = uint::to_str(i); - assert map.get(&s) == i; + assert map.get(s) == i; } } } diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index fafda39993e..32b6c491898 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -83,7 +83,7 @@ fn str_set() { let mut found = 0; for int::range(0, 1000) |_i| { - match s.find(&r.gen_str(10)) { + match s.find(r.gen_str(10)) { Some(_) => { found += 1; } None => { } } diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 811f39e4343..0f4f22196ce 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -69,7 +69,7 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str { // given a map, search for the frequency of a pattern fn find(mm: HashMap<~[u8], uint>, key: ~str) -> uint { - match mm.find(&str::to_bytes(str::to_lower(key))) { + match mm.find(str::to_bytes(str::to_lower(key))) { option::None => { return 0u; } option::Some(num) => { return num; } } diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 5888dab3bb9..8cf57b19825 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -136,7 +136,7 @@ fn writer(path: ~str, pport: pipes::Port, size: uint) while prev <= i { if lines.contains_key_ref(&prev) { debug!("WS %u", prev); - cout.write(lines.get(&prev)); + cout.write(lines.get(prev)); done += 1_u; lines.remove(&prev); prev += 1_u; diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index d7a285d58e6..43e2bee644a 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -49,7 +49,7 @@ mod map_reduce { fn emit(im: oldmap::HashMap<~str, int>, ctrl: SharedChan, key: ~str, val: ~str) { let mut c; - match im.find(&key) { + match im.find(copy key) { Some(_c) => { c = _c } None => { let (pp, cc) = stream(); @@ -88,7 +88,7 @@ mod map_reduce { mapper_done => { num_mappers -= 1; } find_reducer(k, cc) => { let mut c; - match reducers.find(&str::from_bytes(k)) { + match reducers.find(str::from_bytes(k)) { Some(_c) => { c = _c; } None => { c = 0; } } From fd7b732e5873ff3085875f1de48b9d5c9721657c Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 5 Feb 2013 17:30:35 -0800 Subject: [PATCH 21/37] testsuite: Add test for #4523 --- src/test/compile-fail/issue-4523.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/compile-fail/issue-4523.rs diff --git a/src/test/compile-fail/issue-4523.rs b/src/test/compile-fail/issue-4523.rs new file mode 100644 index 00000000000..e72b73f8fa4 --- /dev/null +++ b/src/test/compile-fail/issue-4523.rs @@ -0,0 +1,17 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foopy() {} + +const f: fn() = foopy; //~ ERROR mismatched types: expected `&static/fn()` + +fn main () { + f(); +} \ No newline at end of file From 801f3225b24a796402b83f660f80e62ac504befe Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 5 Feb 2013 19:41:45 -0800 Subject: [PATCH 22/37] oldmap: use &K instead of K in find and get This reverts commit a4250a96fdf61142a9c8dbb6d37ae8435c99e396. This is not the cause of the nonexhaustive-match failure. --- src/libcargo/cargo.rc | 18 +-- src/librustc/back/link.rs | 2 +- src/librustc/driver/driver.rs | 2 +- src/librustc/lib/llvm.rs | 4 +- src/librustc/metadata/cstore.rs | 4 +- src/librustc/metadata/decoder.rs | 2 +- src/librustc/metadata/encoder.rs | 16 +-- src/librustc/metadata/tydecode.rs | 2 +- src/librustc/metadata/tyencode.rs | 4 +- src/librustc/middle/astencode.rs | 28 ++--- src/librustc/middle/borrowck/check_loans.rs | 20 ++-- src/librustc/middle/borrowck/gather_loans.rs | 8 +- src/librustc/middle/borrowck/loan.rs | 2 +- src/librustc/middle/borrowck/preserve.rs | 10 +- src/librustc/middle/check_const.rs | 8 +- src/librustc/middle/check_match.rs | 14 +-- src/librustc/middle/const_eval.rs | 6 +- src/librustc/middle/freevars.rs | 4 +- src/librustc/middle/kind.rs | 10 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/lint.rs | 6 +- src/librustc/middle/liveness.rs | 28 ++--- src/librustc/middle/mem_categorization.rs | 8 +- src/librustc/middle/moves.rs | 4 +- src/librustc/middle/pat_util.rs | 4 +- src/librustc/middle/privacy.rs | 12 +- src/librustc/middle/region.rs | 16 +-- src/librustc/middle/resolve.rs | 55 ++++----- src/librustc/middle/trans/_match.rs | 23 ++-- src/librustc/middle/trans/base.rs | 30 ++--- src/librustc/middle/trans/build.rs | 4 +- src/librustc/middle/trans/callee.rs | 8 +- src/librustc/middle/trans/closure.rs | 2 +- src/librustc/middle/trans/common.rs | 6 +- src/librustc/middle/trans/consts.rs | 12 +- src/librustc/middle/trans/controlflow.rs | 2 +- src/librustc/middle/trans/datum.rs | 4 +- src/librustc/middle/trans/debuginfo.rs | 18 +-- src/librustc/middle/trans/expr.rs | 18 +-- src/librustc/middle/trans/foreign.rs | 100 ++++++++--------- src/librustc/middle/trans/glue.rs | 2 +- src/librustc/middle/trans/inline.rs | 2 +- src/librustc/middle/trans/machine.rs | 2 +- src/librustc/middle/trans/meth.rs | 18 +-- src/librustc/middle/trans/monomorphize.rs | 6 +- src/librustc/middle/trans/reachable.rs | 12 +- src/librustc/middle/trans/reflect.rs | 2 +- src/librustc/middle/trans/type_of.rs | 2 +- src/librustc/middle/trans/type_use.rs | 12 +- src/librustc/middle/ty.rs | 56 +++++----- src/librustc/middle/typeck/astconv.rs | 6 +- src/librustc/middle/typeck/check/_match.rs | 10 +- src/librustc/middle/typeck/check/method.rs | 13 ++- src/librustc/middle/typeck/check/mod.rs | 48 ++++---- src/librustc/middle/typeck/check/regionck.rs | 6 +- src/librustc/middle/typeck/check/vtable.rs | 6 +- src/librustc/middle/typeck/check/writeback.rs | 4 +- src/librustc/middle/typeck/coherence.rs | 29 ++--- src/librustc/middle/typeck/collect.rs | 22 ++-- .../middle/typeck/infer/region_inference.rs | 2 +- src/librustc/middle/typeck/mod.rs | 4 +- src/librustc/util/ppaux.rs | 6 +- src/librustdoc/attr_pass.rs | 6 +- src/librustdoc/prune_hidden_pass.rs | 2 +- src/librustdoc/prune_private_pass.rs | 2 +- src/librustdoc/tystr_pass.rs | 14 +-- src/libstd/oldmap.rs | 105 +++++++++--------- src/libsyntax/ast_map.rs | 4 +- src/libsyntax/ext/expand.rs | 8 +- src/libsyntax/ext/tt/macro_rules.rs | 4 +- src/libsyntax/ext/tt/transcribe.rs | 2 +- src/libsyntax/util/interner.rs | 2 +- src/test/auxiliary/issue-2631-a.rs | 2 +- src/test/bench/core-map.rs | 4 +- src/test/bench/core-std.rs | 2 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 2 +- src/test/bench/shootout-mandelbrot.rs | 2 +- src/test/run-pass/hashmap-memory.rs | 4 +- 78 files changed, 482 insertions(+), 479 deletions(-) diff --git a/src/libcargo/cargo.rc b/src/libcargo/cargo.rc index 960bcf88eb7..cff44ed5ef2 100644 --- a/src/libcargo/cargo.rc +++ b/src/libcargo/cargo.rc @@ -731,7 +731,7 @@ pub fn configure(opts: Options) -> Cargo { need_dir(&c.bindir); for sources.each_key_ref |&k| { - let mut s = sources.get(k); + let mut s = sources.get(&k); load_source_packages(&c, s); sources.insert(k, s); } @@ -981,7 +981,7 @@ pub fn install_named(c: &mut Cargo, wd: &Path, name: ~str) { pub fn install_uuid_specific(c: &mut Cargo, wd: &Path, src: ~str, uuid: ~str) { - match c.sources.find(src) { + match c.sources.find(&src) { Some(s) => { for s.packages.each |p| { if p.uuid == uuid { @@ -997,7 +997,7 @@ pub fn install_uuid_specific(c: &mut Cargo, wd: &Path, src: ~str, pub fn install_named_specific(c: &mut Cargo, wd: &Path, src: ~str, name: ~str) { - match c.sources.find(src) { + match c.sources.find(&src) { Some(s) => { for s.packages.each |p| { if p.name == name { @@ -1064,7 +1064,7 @@ pub fn cmd_uninstall(c: &Cargo) { } pub fn install_query(c: &mut Cargo, wd: &Path, target: ~str) { - match c.dep_cache.find(target) { + match c.dep_cache.find(&target) { Some(inst) => { if inst { return; @@ -1156,7 +1156,7 @@ pub fn cmd_install(c: &mut Cargo) { pub fn sync(c: &Cargo) { for c.sources.each_key_ref |&k| { - let mut s = c.sources.get(k); + let mut s = c.sources.get(&k); sync_one(c, s); c.sources.insert(k, s); } @@ -1558,7 +1558,7 @@ pub fn cmd_list(c: &Cargo) { if !valid_pkg_name(*name) { error(fmt!("'%s' is an invalid source name", *name)); } else { - match c.sources.find(*name) { + match c.sources.find(name) { Some(source) => { print_source(source); } @@ -1754,7 +1754,7 @@ pub fn cmd_sources(c: &Cargo) { return; } - match c.sources.find(name) { + match c.sources.find(&name) { Some(source) => { let old = copy source.url; let method = assume_source_method(url); @@ -1785,7 +1785,7 @@ pub fn cmd_sources(c: &Cargo) { return; } - match c.sources.find(name) { + match c.sources.find(&name) { Some(source) => { let old = copy source.method; @@ -1823,7 +1823,7 @@ pub fn cmd_sources(c: &Cargo) { return; } - match c.sources.find(name) { + match c.sources.find(&name) { Some(source) => { c.sources.remove(&name); c.sources.insert(newn, source); diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 22923cb7290..de7c52520cc 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -596,7 +596,7 @@ pub fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t, } pub fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> @str { - match ccx.type_hashcodes.find(t) { + match ccx.type_hashcodes.find(&t) { Some(h) => h, None => { let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta); diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 1464fa29afc..5bbf3f839ad 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -538,7 +538,7 @@ pub fn build_session_options(+binary: ~str, getopts::opt_strs(matches, level_name)); for flags.each |lint_name| { let lint_name = str::replace(*lint_name, ~"-", ~"_"); - match lint_dict.find(/*bad*/ copy lint_name) { + match lint_dict.find(&lint_name) { None => { early_error(demitter, fmt!("unknown %s flag: %s", level_name, lint_name)); diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index e114a18f4fd..50f4fe43efd 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -1331,11 +1331,11 @@ pub fn associate_type(tn: type_names, s: @str, t: TypeRef) { } pub fn type_has_name(tn: type_names, t: TypeRef) -> Option<@str> { - return tn.type_names.find(t); + return tn.type_names.find(&t); } pub fn name_has_type(tn: type_names, s: @str) -> Option { - return tn.named_types.find(s); + return tn.named_types.find(&s); } pub fn mk_type_names() -> type_names { diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index c8a1a619436..1faf8e13fda 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -74,7 +74,7 @@ pub fn mk_cstore(intr: @ident_interner) -> CStore { pub fn get_crate_data(cstore: CStore, cnum: ast::crate_num) -> crate_metadata { - return p(cstore).metas.get(cnum); + return p(cstore).metas.get(&cnum); } pub fn get_crate_hash(cstore: CStore, cnum: ast::crate_num) -> ~str { @@ -139,7 +139,7 @@ pub fn add_use_stmt_cnum(cstore: CStore, use_id: ast::node_id, pub fn find_use_stmt_cnum(cstore: CStore, use_id: ast::node_id) -> Option { - p(cstore).use_crate_map.find(use_id) + p(cstore).use_crate_map.find(&use_id) } // returns hashes of crates directly used by this crate. Hashes are diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index c3c7c969cd8..9a6a2f7e954 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -1099,7 +1099,7 @@ pub fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id { return ast::def_id { crate: cdata.cnum, node: did.node }; } - match cdata.cnum_map.find(did.crate) { + match cdata.cnum_map.find(&did.crate) { option::Some(n) => ast::def_id { crate: n, node: did.node }, option::None => die!(~"didn't find a crate in the cnum_map") } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 438084a3bd7..072b974d042 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -118,7 +118,7 @@ pub fn encode_def_id(ebml_w: writer::Encoder, id: def_id) { fn encode_region_param(ecx: @encode_ctxt, ebml_w: writer::Encoder, it: @ast::item) { - let opt_rp = ecx.tcx.region_paramd_items.find(it.id); + let opt_rp = ecx.tcx.region_paramd_items.find(&it.id); for opt_rp.each |rp| { do ebml_w.wr_tag(tag_region_param) { (*rp).encode(&ebml_w); @@ -184,7 +184,7 @@ fn encode_ty_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt, fn encode_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt, params: &[ty_param]) { let ty_param_bounds = - @params.map(|param| ecx.tcx.ty_param_bounds.get(param.id)); + @params.map(|param| ecx.tcx.ty_param_bounds.get(¶m.id)); encode_ty_type_param_bounds(ebml_w, ecx, ty_param_bounds); } @@ -224,7 +224,7 @@ fn encode_type(ecx: @encode_ctxt, ebml_w: writer::Encoder, typ: ty::t) { fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) { ebml_w.start_tag(tag_items_data_item_symbol); - let sym = match ecx.item_symbols.find(id) { + let sym = match ecx.item_symbols.find(&id) { Some(ref x) => (/*bad*/copy *x), None => { ecx.diag.handler().bug( @@ -238,7 +238,7 @@ fn encode_symbol(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) { fn encode_discriminant(ecx: @encode_ctxt, ebml_w: writer::Encoder, id: node_id) { ebml_w.start_tag(tag_items_data_item_symbol); - ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(id))); + ebml_w.writer.write(str::to_bytes(ecx.discrim_symbols.get(&id))); ebml_w.end_tag(); } @@ -349,7 +349,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder, // Encode the reexports of this module. debug!("(encoding info for module) encoding reexports for %d", id); - match ecx.reexports2.find(id) { + match ecx.reexports2.find(&id) { Some(ref exports) => { debug!("(encoding info for module) found reexports for %d", id); for (*exports).each |exp| { @@ -813,7 +813,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder, encode_name(ecx, ebml_w, ty_m.ident); encode_family(ebml_w, purity_static_method_family(ty_m.purity)); - let polyty = ecx.tcx.tcache.get(local_def(ty_m.id)); + let polyty = ecx.tcx.tcache.get(&local_def(ty_m.id)); encode_ty_type_param_bounds(ebml_w, ecx, polyty.bounds); encode_type(ecx, ebml_w, polyty.ty); let mut m_path = vec::append(~[], path); // :-( @@ -881,7 +881,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: writer::Encoder, let ebml_w = copy ebml_w; |i, cx, v| { visit::visit_item(i, cx, v); - match ecx.tcx.items.get(i.id) { + match ecx.tcx.items.get(&i.id) { ast_map::node_item(_, pt) => { encode_info_for_item(ecx, ebml_w, i, index, *pt); @@ -894,7 +894,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: writer::Encoder, let ebml_w = copy ebml_w; |ni, cx, v| { visit::visit_foreign_item(ni, cx, v); - match ecx.tcx.items.get(ni.id) { + match ecx.tcx.items.get(&ni.id) { ast_map::node_foreign_item(_, abi, pt) => { encode_info_for_foreign_item(ecx, ebml_w, ni, index, /*bad*/copy *pt, diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 5dd499dfd63..ea13325ad49 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -329,7 +329,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t { let len = parse_hex(st); assert (next(st) == '#'); let key = creader_cache_key { cnum: st.crate, pos: pos, len: len }; - match st.tcx.rcache.find(key) { + match st.tcx.rcache.find(&key) { Some(tt) => return tt, None => { let ps = @{pos: pos ,.. copy *st}; diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index a0e2065b20b..0d66862c79f 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -56,7 +56,7 @@ fn cx_uses_abbrevs(cx: @ctxt) -> bool { pub fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) { match cx.abbrevs { ac_no_abbrevs => { - let result_str = match cx.tcx.short_names_cache.find(t) { + let result_str = match cx.tcx.short_names_cache.find(&t) { Some(s) => /*bad*/copy *s, None => { let s = do io::with_str_writer |wr| { @@ -69,7 +69,7 @@ pub fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) { w.write_str(result_str); } ac_use_abbrevs(abbrevs) => { - match abbrevs.find(t) { + match abbrevs.find(&t) { Some(a) => { w.write_str(*a.s); return; } None => { let pos = w.tell(); diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 2fc592e131e..71599463382 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -838,7 +838,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, debug!("Encoding side tables for id %d", id); - do option::iter(&tcx.def_map.find(id)) |def| { + do option::iter(&tcx.def_map.find(&id)) |def| { do ebml_w.tag(c::tag_table_def) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -855,7 +855,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.node_type_substs.find(id)) |tys| { + do option::iter(&tcx.node_type_substs.find(&id)) |tys| { do ebml_w.tag(c::tag_table_node_type_subst) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -864,7 +864,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.freevars.find(id)) |fv| { + do option::iter(&tcx.freevars.find(&id)) |fv| { do ebml_w.tag(c::tag_table_freevars) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -876,7 +876,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } let lid = ast::def_id { crate: ast::local_crate, node: id }; - do option::iter(&tcx.tcache.find(lid)) |tpbt| { + do option::iter(&tcx.tcache.find(&lid)) |tpbt| { do ebml_w.tag(c::tag_table_tcache) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -885,7 +885,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.ty_param_bounds.find(id)) |pbs| { + do option::iter(&tcx.ty_param_bounds.find(&id)) |pbs| { do ebml_w.tag(c::tag_table_param_bounds) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -899,7 +899,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, // is what we actually use in trans, all modes will have been // resolved. // - //option::iter(tcx.inferred_modes.find(id)) {|m| + //option::iter(tcx.inferred_modes.find(&id)) {|m| // ebml_w.tag(c::tag_table_inferred_modes) {|| // ebml_w.id(id); // ebml_w.tag(c::tag_table_val) {|| @@ -908,13 +908,13 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, // } //} - do option::iter(&maps.mutbl_map.find(id)) |_m| { + do option::iter(&maps.mutbl_map.find(&id)) |_m| { do ebml_w.tag(c::tag_table_mutbl) { ebml_w.id(id); } } - do option::iter(&maps.last_use_map.find(id)) |m| { + do option::iter(&maps.last_use_map.find(&id)) |m| { do ebml_w.tag(c::tag_table_last_use) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -925,7 +925,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&maps.method_map.find(id)) |mme| { + do option::iter(&maps.method_map.find(&id)) |mme| { do ebml_w.tag(c::tag_table_method_map) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -934,7 +934,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&maps.vtable_map.find(id)) |dr| { + do option::iter(&maps.vtable_map.find(&id)) |dr| { do ebml_w.tag(c::tag_table_vtable_map) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -943,7 +943,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.adjustments.find(id)) |adj| { + do option::iter(&tcx.adjustments.find(&id)) |adj| { do ebml_w.tag(c::tag_table_adjustments) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { @@ -952,19 +952,19 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt, } } - do option::iter(&tcx.legacy_boxed_traits.find(id)) |_x| { + do option::iter(&tcx.legacy_boxed_traits.find(&id)) |_x| { do ebml_w.tag(c::tag_table_legacy_boxed_trait) { ebml_w.id(id); } } - for maps.moves_map.find(id).each |_| { + for maps.moves_map.find(&id).each |_| { do ebml_w.tag(c::tag_table_moves_map) { ebml_w.id(id); } } - for maps.capture_map.find(id).each |cap_vars| { + for maps.capture_map.find(&id).each |cap_vars| { do ebml_w.tag(c::tag_table_capture_map) { ebml_w.id(id); do ebml_w.tag(c::tag_table_val) { diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 19740b6a929..9b2d51289ad 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -126,12 +126,12 @@ impl check_loan_ctxt { let region_map = self.tcx().region_map; let pure_map = self.req_maps.pure_map; loop { - match pure_map.find(scope_id) { + match pure_map.find(&scope_id) { None => (), Some(ref e) => return Some(pc_cmt((*e))) } - match region_map.find(scope_id) { + match region_map.find(&scope_id) { None => return default_purity, Some(next_scope_id) => scope_id = next_scope_id } @@ -144,13 +144,13 @@ impl check_loan_ctxt { let req_loan_map = self.req_maps.req_loan_map; loop { - for req_loan_map.find(scope_id).each |loans| { + for req_loan_map.find(&scope_id).each |loans| { for loans.each |loan| { if !f(loan) { return; } } } - match region_map.find(scope_id) { + match region_map.find(&scope_id) { None => return, Some(next_scope_id) => scope_id = next_scope_id, } @@ -199,7 +199,7 @@ impl check_loan_ctxt { Some(expr) => { match expr.node { ast::expr_path(_) if pc == pc_pure_fn => { - let def = self.tcx().def_map.get(expr.id); + let def = self.tcx().def_map.get(&expr.id); let did = ast_util::def_id_of_def(def); let is_fn_arg = did.crate == ast::local_crate && @@ -247,7 +247,7 @@ impl check_loan_ctxt { fn is_allowed_pure_arg(expr: @ast::expr) -> bool { return match expr.node { ast::expr_path(_) => { - let def = self.tcx().def_map.get(expr.id); + let def = self.tcx().def_map.get(&expr.id); let did = ast_util::def_id_of_def(def); did.crate == ast::local_crate && (*self.fn_args).contains(&(did.node)) @@ -262,14 +262,14 @@ impl check_loan_ctxt { fn check_for_conflicting_loans(scope_id: ast::node_id) { debug!("check_for_conflicting_loans(scope_id=%?)", scope_id); - let new_loans = match self.req_maps.req_loan_map.find(scope_id) { + let new_loans = match self.req_maps.req_loan_map.find(&scope_id) { None => return, Some(loans) => loans }; debug!("new_loans has length %?", new_loans.len()); - let par_scope_id = self.tcx().region_map.get(scope_id); + let par_scope_id = self.tcx().region_map.get(&scope_id); for self.walk_loans(par_scope_id) |old_loan| { debug!("old_loan=%?", self.bccx.loan_to_repr(old_loan)); @@ -325,7 +325,7 @@ impl check_loan_ctxt { fn check_assignment(at: assignment_type, ex: @ast::expr) { // We don't use cat_expr() here because we don't want to treat // auto-ref'd parameters in overloaded operators as rvalues. - let cmt = match self.bccx.tcx.adjustments.find(ex.id) { + let cmt = match self.bccx.tcx.adjustments.find(&ex.id) { None => self.bccx.cat_expr_unadjusted(ex), Some(adj) => self.bccx.cat_expr_autoderefd(ex, adj) }; @@ -612,7 +612,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk, { match fty_proto { ast::ProtoBox | ast::ProtoUniq => { - let cap_vars = self.bccx.capture_map.get(id); + let cap_vars = self.bccx.capture_map.get(&id); for cap_vars.each |cap_var| { match cap_var.mode { moves::CapRef | moves::CapCopy => { loop; } diff --git a/src/librustc/middle/borrowck/gather_loans.rs b/src/librustc/middle/borrowck/gather_loans.rs index b7b99424924..8029b4c2713 100644 --- a/src/librustc/middle/borrowck/gather_loans.rs +++ b/src/librustc/middle/borrowck/gather_loans.rs @@ -126,7 +126,7 @@ fn req_loans_in_expr(ex: @ast::expr, // If this expression is borrowed, have to ensure it remains valid: if !self.ignore_adjustments.contains(&ex.id) { - for tcx.adjustments.find(ex.id).each |adjustments| { + for tcx.adjustments.find(&ex.id).each |adjustments| { self.guarantee_adjustments(ex, *adjustments); } } @@ -172,7 +172,7 @@ fn req_loans_in_expr(ex: @ast::expr, } } - match self.bccx.method_map.find(ex.id) { + match self.bccx.method_map.find(&ex.id) { Some(ref method_map_entry) => { match (*method_map_entry).explicit_self { ast::sty_by_ref => { @@ -250,7 +250,7 @@ fn req_loans_in_expr(ex: @ast::expr, // (if used like `a.b(...)`), the call where it's an argument // (if used like `x(a.b)`), or the block (if used like `let x // = a.b`). - let scope_r = ty::re_scope(self.tcx().region_map.get(ex.id)); + let scope_r = ty::re_scope(self.tcx().region_map.get(&ex.id)); let rcvr_cmt = self.bccx.cat_expr(rcvr); self.guarantee_valid(rcvr_cmt, m_imm, scope_r); visit::visit_expr(ex, self, vt); @@ -536,7 +536,7 @@ impl gather_loan_ctxt { fn add_loans_to_scope_id(&self, scope_id: ast::node_id, +loans: ~[Loan]) { debug!("adding %u loans to scope_id %?", loans.len(), scope_id); - match self.req_maps.req_loan_map.find(scope_id) { + match self.req_maps.req_loan_map.find(&scope_id) { Some(req_loans) => { req_loans.push_all(loans); } diff --git a/src/librustc/middle/borrowck/loan.rs b/src/librustc/middle/borrowck/loan.rs index 0b06fbd2a3a..7248d29aa04 100644 --- a/src/librustc/middle/borrowck/loan.rs +++ b/src/librustc/middle/borrowck/loan.rs @@ -129,7 +129,7 @@ impl LoanContext { ~"rvalue with a non-none lp"); } cat_local(local_id) | cat_arg(local_id) | cat_self(local_id) => { - let local_scope_id = self.tcx().region_map.get(local_id); + let local_scope_id = self.tcx().region_map.get(&local_id); self.issue_loan(cmt, ty::re_scope(local_scope_id), req_mutbl, owns_lent_data) } diff --git a/src/librustc/middle/borrowck/preserve.rs b/src/librustc/middle/borrowck/preserve.rs index 3bc34d2ef29..1946ba09ec7 100644 --- a/src/librustc/middle/borrowck/preserve.rs +++ b/src/librustc/middle/borrowck/preserve.rs @@ -109,7 +109,7 @@ impl PreserveCtxt { // Maybe if we pass in the parent instead here, // we can prevent the "scope not found" error debug!("scope_region thing: %? ", cmt.id); - ty::re_scope(self.tcx().region_map.get(cmt.id)) + ty::re_scope(self.tcx().region_map.get(&cmt.id)) }; self.compare_scope(cmt, scope_region) @@ -129,14 +129,14 @@ impl PreserveCtxt { cmt.span, ~"preserve() called with local and !root_managed_data"); } - let local_scope_id = self.tcx().region_map.get(local_id); + let local_scope_id = self.tcx().region_map.get(&local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } cat_binding(local_id) => { // Bindings are these kind of weird implicit pointers (cc // #2329). We require (in gather_loans) that they be // rooted in an immutable location. - let local_scope_id = self.tcx().region_map.get(local_id); + let local_scope_id = self.tcx().region_map.get(&local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } cat_arg(local_id) => { @@ -144,11 +144,11 @@ impl PreserveCtxt { // modes). In that case, the caller guarantees stability // for at least the scope of the fn. This is basically a // deref of a region ptr. - let local_scope_id = self.tcx().region_map.get(local_id); + let local_scope_id = self.tcx().region_map.get(&local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } cat_self(local_id) => { - let local_scope_id = self.tcx().region_map.get(local_id); + let local_scope_id = self.tcx().region_map.get(&local_id); self.compare_scope(cmt, ty::re_scope(local_scope_id)) } cat_comp(cmt_base, comp_field(*)) | diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 98c3fdaa8c3..69ace0d7797 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -126,7 +126,7 @@ pub fn check_expr(sess: Session, e.span, ~"paths in constants may only refer to \ items without type parameters"); } - match def_map.find(e.id) { + match def_map.find(&e.id) { Some(def_const(def_id)) | Some(def_fn(def_id, _)) | Some(def_variant(_, def_id)) | @@ -151,7 +151,7 @@ pub fn check_expr(sess: Session, } } expr_call(callee, _, false) => { - match def_map.find(callee.id) { + match def_map.find(&callee.id) { Some(def_struct(*)) => {} // OK. Some(def_variant(*)) => {} // OK. _ => { @@ -247,9 +247,9 @@ pub fn check_item_recursion(sess: Session, fn visit_expr(e: @expr, &&env: env, v: visit::vt) { match e.node { expr_path(*) => { - match env.def_map.find(e.id) { + match env.def_map.find(&e.id) { Some(def_const(def_id)) => { - match env.ast_map.get(def_id.node) { + match env.ast_map.get(&def_id.node) { ast_map::node_item(it, _) => { (v.visit_item)(it, env, v); } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index e25ceee5d30..978aaacb18a 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -292,7 +292,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option { match /*bad*/copy pat.node { pat_wild => { None } pat_ident(_, _, _) | pat_enum(_, _) => { - match cx.tcx.def_map.find(pat.id) { + match cx.tcx.def_map.find(&pat.id) { Some(def_variant(_, id)) => Some(variant(id)), Some(def_const(did)) => { let const_expr = lookup_const_by_id(cx.tcx, did).get(); @@ -306,7 +306,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option { Some(range(eval_const_expr(cx.tcx, lo), eval_const_expr(cx.tcx, hi))) } pat_struct(*) => { - match cx.tcx.def_map.find(pat.id) { + match cx.tcx.def_map.find(&pat.id) { Some(def_variant(_, id)) => Some(variant(id)), _ => Some(single) } @@ -329,7 +329,7 @@ pub fn is_wild(cx: @MatchCheckCtxt, p: @pat) -> bool { match pat.node { pat_wild => { true } pat_ident(_, _, _) => { - match cx.tcx.def_map.find(pat.id) { + match cx.tcx.def_map.find(&pat.id) { Some(def_variant(_, _)) | Some(def_const(*)) => { false } _ => { true } } @@ -480,7 +480,7 @@ pub fn specialize(cx: @MatchCheckCtxt, pat_wild => Some(vec::append(vec::from_elem(arity, wild()), vec::tail(r))), pat_ident(_, _, _) => { - match cx.tcx.def_map.find(pat_id) { + match cx.tcx.def_map.find(&pat_id) { Some(def_variant(_, id)) => { if variant(id) == ctor_id { Some(vec::tail(r)) } else { None } @@ -505,7 +505,7 @@ pub fn specialize(cx: @MatchCheckCtxt, } } pat_enum(_, args) => { - match cx.tcx.def_map.get(pat_id) { + match cx.tcx.def_map.get(&pat_id) { def_variant(_, id) if variant(id) == ctor_id => { let args = match args { Some(args) => args, @@ -541,7 +541,7 @@ pub fn specialize(cx: @MatchCheckCtxt, } pat_struct(_, ref flds, _) => { // Is this a struct or an enum variant? - match cx.tcx.def_map.get(pat_id) { + match cx.tcx.def_map.get(&pat_id) { def_variant(_, variant_id) => { if variant(variant_id) == ctor_id { // FIXME #4731: Is this right? --pcw @@ -678,7 +678,7 @@ pub fn check_fn(cx: @MatchCheckCtxt, } pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool { - match cx.tcx.def_map.find(pat.id) { + match cx.tcx.def_map.find(&pat.id) { Some(def_variant(enum_id, _)) => { if vec::len(*ty::enum_variants(cx.tcx, enum_id)) != 1u { return true; diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index f917964d234..e01595d8d93 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -78,7 +78,7 @@ pub fn classify(e: @expr, tcx: ty::ctxt) -> constness { let did = ast_util::local_def(e.id); - match tcx.ccache.find(did) { + match tcx.ccache.find(&did) { Some(x) => x, None => { let cn = @@ -170,7 +170,7 @@ pub fn classify(e: @expr, } pub fn lookup_const(tcx: ty::ctxt, e: @expr) -> Option<@expr> { - match tcx.def_map.find(e.id) { + match tcx.def_map.find(&e.id) { Some(ast::def_const(def_id)) => lookup_const_by_id(tcx, def_id), _ => None } @@ -180,7 +180,7 @@ pub fn lookup_const_by_id(tcx: ty::ctxt, def_id: ast::def_id) -> Option<@expr> { if ast_util::is_local(def_id) { - match tcx.items.find(def_id.node) { + match tcx.items.find(&def_id.node) { None => None, Some(ast_map::node_item(it, _)) => match it.node { item_const(_, const_expr) => Some(const_expr), diff --git a/src/librustc/middle/freevars.rs b/src/librustc/middle/freevars.rs index 1e9d8c9c08e..5d65aba2a4d 100644 --- a/src/librustc/middle/freevars.rs +++ b/src/librustc/middle/freevars.rs @@ -58,7 +58,7 @@ fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk) } ast::expr_path(*) => { let mut i = 0; - match def_map.find(expr.id) { + match def_map.find(&expr.id) { None => die!(~"path not found"), Some(df) => { let mut def = df; @@ -118,7 +118,7 @@ pub fn annotate_freevars(def_map: resolve::DefMap, crate: @ast::crate) -> } pub fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info { - match tcx.freevars.find(fid) { + match tcx.freevars.find(&fid) { None => die!(~"get_freevars: " + int::str(fid) + ~" has no freevars"), Some(d) => return d } diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 09232a2a0c5..8abafe6b079 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -195,10 +195,10 @@ pub fn check_expr(e: @expr, cx: ctx, v: visit::vt) { expr_unary(*)|expr_binary(*)|expr_method_call(*) => e.callee_id, _ => e.id }; - do option::iter(&cx.tcx.node_type_substs.find(type_parameter_id)) |ts| { + do option::iter(&cx.tcx.node_type_substs.find(&type_parameter_id)) |ts| { let bounds = match e.node { expr_path(_) => { - let did = ast_util::def_id_of_def(cx.tcx.def_map.get(e.id)); + let did = ast_util::def_id_of_def(cx.tcx.def_map.get(&e.id)); ty::lookup_item_type(cx.tcx, did).bounds } _ => { @@ -292,8 +292,8 @@ pub fn check_expr(e: @expr, cx: ctx, v: visit::vt) { fn check_ty(aty: @Ty, cx: ctx, v: visit::vt) { match aty.node { ty_path(_, id) => { - do option::iter(&cx.tcx.node_type_substs.find(id)) |ts| { - let did = ast_util::def_id_of_def(cx.tcx.def_map.get(id)); + do option::iter(&cx.tcx.node_type_substs.find(&id)) |ts| { + let did = ast_util::def_id_of_def(cx.tcx.def_map.get(&id)); let bounds = ty::lookup_item_type(cx.tcx, did).bounds; for vec::each2(*ts, *bounds) |ty, bound| { check_bounds(cx, aty.id, aty.span, *ty, *bound) @@ -334,7 +334,7 @@ pub fn check_bounds(cx: ctx, id: node_id, sp: span, fn is_nullary_variant(cx: ctx, ex: @expr) -> bool { match ex.node { expr_path(_) => { - match cx.tcx.def_map.get(ex.id) { + match cx.tcx.def_map.get(&ex.id) { def_variant(edid, vdid) => { vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 3eb65505e64..b4500f87eb0 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -352,7 +352,7 @@ impl LanguageItemCollector { return; // Didn't match. } - match self.item_refs.find(/*bad*/copy value) { + match self.item_refs.find(&value) { None => { // Didn't match. } diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 0dc7a746e9e..4601941f73a 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -265,7 +265,7 @@ pub fn get_lint_settings_level(settings: lint_settings, _expr_id: ast::node_id, item_id: ast::node_id) -> level { - match settings.settings_map.find(item_id) { + match settings.settings_map.find(&item_id) { Some(modes) => get_lint_level(modes, lint_mode), None => get_lint_level(settings.default_settings, lint_mode) } @@ -346,7 +346,7 @@ impl ctxt { for triples.each |pair| { let (meta, level, lintname) = /*bad*/copy *pair; - match self.dict.find(/*bad*/ copy lintname) { + match self.dict.find(&lintname) { None => { self.span_lint( new_ctxt.get_level(unrecognized_lint), @@ -684,7 +684,7 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { for vec::each(vec::append_one(tys, decl.output)) |ty| { match ty.node { ast::ty_path(_, id) => { - match cx.def_map.get(id) { + match cx.def_map.get(&id) { ast::def_prim_ty(ast::ty_int(ast::ty_i)) => { cx.sess.span_lint( ctypes, id, fn_id, diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index c13af3a32f2..9240bc5fbc8 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -368,7 +368,7 @@ impl IrMaps { } fn variable(node_id: node_id, span: span) -> Variable { - match self.variable_map.find(node_id) { + match self.variable_map.find(&node_id) { Some(var) => var, None => { self.tcx.sess.span_bug( @@ -390,7 +390,7 @@ impl IrMaps { } fn captures(expr: @expr) -> @~[CaptureInfo] { - match self.capture_info_map.find(expr.id) { + match self.capture_info_map.find(&expr.id) { Some(caps) => caps, None => { self.tcx.sess.span_bug(expr.span, ~"no registered caps"); @@ -410,7 +410,7 @@ impl IrMaps { Local(LocalInfo {id: id, kind: FromLetNoInitializer, _}) | Local(LocalInfo {id: id, kind: FromLetWithInitializer, _}) | Local(LocalInfo {id: id, kind: FromMatch(_), _}) => { - let v = match self.last_use_map.find(expr_id) { + let v = match self.last_use_map.find(&expr_id) { Some(v) => v, None => { let v = @DVec(); @@ -552,7 +552,7 @@ fn visit_expr(expr: @expr, &&self: @IrMaps, vt: vt<@IrMaps>) { match expr.node { // live nodes required for uses or definitions of variables: expr_path(_) => { - let def = self.tcx.def_map.get(expr.id); + let def = self.tcx.def_map.get(&expr.id); debug!("expr %d: path that leads to %?", expr.id, def); if relevant_def(def).is_some() { self.add_live_node_for_node(expr.id, ExprNode(expr.span)); @@ -569,7 +569,7 @@ fn visit_expr(expr: @expr, &&self: @IrMaps, vt: vt<@IrMaps>) { // being the location that the variable is used. This results // in better error messages than just pointing at the closure // construction site. - let cvs = self.capture_map.get(expr.id); + let cvs = self.capture_map.get(&expr.id); let mut call_caps = ~[]; for cvs.each |cv| { match relevant_def(cv.def) { @@ -685,7 +685,7 @@ fn Liveness(ir: @IrMaps, specials: Specials) -> Liveness { impl Liveness { fn live_node(node_id: node_id, span: span) -> LiveNode { - match self.ir.live_node_map.find(node_id) { + match self.ir.live_node_map.find(&node_id) { Some(ln) => ln, None => { // This must be a mismatch between the ir_map construction @@ -702,7 +702,7 @@ impl Liveness { fn variable_from_path(expr: @expr) -> Option { match expr.node { expr_path(_) => { - let def = self.tcx.def_map.get(expr.id); + let def = self.tcx.def_map.get(&expr.id); relevant_def(def).map( |rdef| self.variable(*rdef, expr.span) ) @@ -717,7 +717,7 @@ impl Liveness { fn variable_from_def_map(node_id: node_id, span: span) -> Option { - match self.tcx.def_map.find(node_id) { + match self.tcx.def_map.find(&node_id) { Some(def) => { relevant_def(def).map( |rdef| self.variable(*rdef, span) @@ -837,7 +837,7 @@ impl Liveness { match opt_label { Some(_) => // Refers to a labeled loop. Use the results of resolve // to find with one - match self.tcx.def_map.find(id) { + match self.tcx.def_map.find(&id) { Some(def_label(loop_id)) => loop_id, _ => self.tcx.sess.span_bug(sp, ~"Label on break/loop \ doesn't refer to a loop") @@ -1203,7 +1203,7 @@ impl Liveness { // Now that we know the label we're going to, // look it up in the break loop nodes table - match self.break_ln.find(sc) { + match self.break_ln.find(&sc) { Some(b) => b, None => self.tcx.sess.span_bug(expr.span, ~"Break to unknown label") @@ -1217,7 +1217,7 @@ impl Liveness { // Now that we know the label we're going to, // look it up in the continue loop nodes table - match self.cont_ln.find(sc) { + match self.cont_ln.find(&sc) { Some(b) => b, None => self.tcx.sess.span_bug(expr.span, ~"Loop to unknown label") @@ -1424,7 +1424,7 @@ impl Liveness { } fn access_path(expr: @expr, succ: LiveNode, acc: uint) -> LiveNode { - let def = self.tcx.def_map.get(expr.id); + let def = self.tcx.def_map.get(&expr.id); match relevant_def(def) { Some(nid) => { let ln = self.live_node(expr.id, expr.span); @@ -1560,7 +1560,7 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) { let ln = self.live_node(expr.id, expr.span); self.consider_last_use(expr, ln, *var); - match self.ir.variable_moves_map.find(expr.id) { + match self.ir.variable_moves_map.find(&expr.id) { None => {} Some(entire_expr) => { debug!("(checking expr) is a move: `%s`", @@ -1689,7 +1689,7 @@ impl @Liveness { fn check_lvalue(expr: @expr, vt: vt<@Liveness>) { match expr.node { expr_path(_) => { - match self.tcx.def_map.get(expr.id) { + match self.tcx.def_map.get(&expr.id) { def_local(nid, false) => { // Assignment to an immutable variable or argument: // only legal if there is no later assignment. diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 94fc63b75dd..abe8a64fea5 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -308,7 +308,7 @@ pub struct mem_categorization_ctxt { pub impl &mem_categorization_ctxt { fn cat_expr(expr: @ast::expr) -> cmt { - match self.tcx.adjustments.find(expr.id) { + match self.tcx.adjustments.find(&expr.id) { None => { // No adjustments. self.cat_expr_unadjusted(expr) @@ -375,7 +375,7 @@ pub impl &mem_categorization_ctxt { } ast::expr_path(_) => { - let def = self.tcx.def_map.get(expr.id); + let def = self.tcx.def_map.get(&expr.id); self.cat_def(expr.id, expr.span, expr_ty, def) } @@ -840,7 +840,7 @@ pub impl &mem_categorization_ctxt { // variant(*) } ast::pat_enum(_, Some(ref subpats)) => { - match self.tcx.def_map.find(pat.id) { + match self.tcx.def_map.find(&pat.id) { Some(ast::def_variant(enum_did, _)) => { // variant(x, y, z) for subpats.each |subpat| { @@ -1063,7 +1063,7 @@ pub fn field_mutbl(tcx: ty::ctxt, } } ty::ty_enum(*) => { - match tcx.def_map.get(node_id) { + match tcx.def_map.get(&node_id) { ast::def_variant(_, variant_id) => { for ty::lookup_struct_fields(tcx, variant_id).each |fld| { if fld.ident == f_name { diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index 8adebdb4582..f7943d6edc0 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -409,7 +409,7 @@ impl VisitContext { // `expr_mode` refers to the post-adjustment value. If one of // those adjustments is to take a reference, then it's only // reading the underlying expression, not moving it. - let comp_mode = match self.tcx.adjustments.find(expr.id) { + let comp_mode = match self.tcx.adjustments.find(&expr.id) { Some(adj) if adj.autoref.is_some() => Read, _ => expr_mode.component_mode(expr) }; @@ -713,7 +713,7 @@ impl VisitContext { receiver_expr: @expr, visitor: vt) { - let callee_mode = match self.method_map.find(expr_id) { + let callee_mode = match self.method_map.find(&expr_id) { Some(ref method_map_entry) => { match method_map_entry.explicit_self { sty_by_ref => by_ref, diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index c39d750a581..823af16c605 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -35,7 +35,7 @@ pub fn pat_id_map(dm: resolve::DefMap, pat: @pat) -> PatIdMap { pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool { match pat.node { pat_enum(_, _) | pat_ident(_, _, None) | pat_struct(*) => { - match dm.find(pat.id) { + match dm.find(&pat.id) { Some(def_variant(*)) | Some(def_struct(*)) => true, _ => false } @@ -47,7 +47,7 @@ pub fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool { pub fn pat_is_const(dm: resolve::DefMap, pat: &pat) -> bool { match pat.node { pat_ident(_, _, None) => { - match dm.find(pat.id) { + match dm.find(&pat.id) { Some(def_const(*)) => true, _ => false } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 482f01f7201..3ec1cf3a705 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -105,7 +105,7 @@ pub fn check_crate(tcx: ty::ctxt, match *origin { method_static(method_id) => { if method_id.crate == local_crate { - match tcx.items.find(method_id.node) { + match tcx.items.find(&method_id.node) { Some(node_method(method, impl_id, _)) => { if method.vis == private && (impl_id.crate != local_crate || @@ -143,7 +143,7 @@ pub fn check_crate(tcx: ty::ctxt, method_self(trait_id, method_num) | method_super(trait_id, method_num) => { if trait_id.crate == local_crate { - match tcx.items.find(trait_id.node) { + match tcx.items.find(&trait_id.node) { Some(node_item(item, _)) => { match item.node { item_trait(_, _, ref methods) => { @@ -221,7 +221,7 @@ pub fn check_crate(tcx: ty::ctxt, ty_struct(id, _) if id.crate != local_crate || !privileged_items.contains(&(id.node)) => { - match method_map.find(expr.id) { + match method_map.find(&expr.id) { None => { debug!("(privacy checking) checking \ field access"); @@ -244,7 +244,7 @@ pub fn check_crate(tcx: ty::ctxt, ty_struct(id, _) if id.crate != local_crate || !privileged_items.contains(&(id.node)) => { - match method_map.find(expr.id) { + match method_map.find(&expr.id) { None => { tcx.sess.span_bug(expr.span, ~"method call not in \ @@ -276,7 +276,7 @@ pub fn check_crate(tcx: ty::ctxt, ty_enum(id, _) => { if id.crate != local_crate || !privileged_items.contains(&(id.node)) { - match tcx.def_map.get(expr.id) { + match tcx.def_map.get(&expr.id) { def_variant(_, variant_id) => { for (*fields).each |field| { debug!("(privacy checking) \ @@ -343,7 +343,7 @@ pub fn check_crate(tcx: ty::ctxt, if enum_id.crate != local_crate || !privileged_items.contains( &enum_id.node) { - match tcx.def_map.find(pattern.id) { + match tcx.def_map.find(&pattern.id) { Some(def_variant(_, variant_id)) => { for fields.each |field| { debug!("(privacy checking) \ diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 4602d2aff4e..867cc7c686f 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -115,7 +115,7 @@ pub fn scope_contains(region_map: region_map, superscope: ast::node_id, subscope: ast::node_id) -> bool { let mut subscope = subscope; while superscope != subscope { - match region_map.find(subscope) { + match region_map.find(&subscope) { None => return false, Some(scope) => subscope = scope } @@ -159,7 +159,7 @@ pub fn nearest_common_ancestor(region_map: region_map, let mut result = ~[scope]; let mut scope = scope; loop { - match region_map.find(scope) { + match region_map.find(&scope) { None => return result, Some(superscope) => { result.push(superscope); @@ -237,7 +237,7 @@ pub fn resolve_arm(arm: ast::arm, cx: ctxt, visitor: visit::vt) { pub fn resolve_pat(pat: @ast::pat, cx: ctxt, visitor: visit::vt) { match pat.node { ast::pat_ident(*) => { - let defn_opt = cx.def_map.find(pat.id); + let defn_opt = cx.def_map.find(&pat.id); match defn_opt { Some(ast::def_variant(_,_)) => { /* Nothing to do; this names a variant. */ @@ -475,7 +475,7 @@ pub impl determine_rp_ctxt { /// the new variance is joined with the old variance. fn add_rp(id: ast::node_id, variance: region_variance) { assert id != 0; - let old_variance = self.region_paramd_items.find(id); + let old_variance = self.region_paramd_items.find(&id); let joined_variance = match old_variance { None => variance, Some(v) => join_variance(v, variance) @@ -505,7 +505,7 @@ pub impl determine_rp_ctxt { ast_map::node_id_to_str(self.ast_map, self.item_id, self.sess.parse_sess.interner), copy self.ambient_variance); - let vec = match self.dep_map.find(from) { + let vec = match self.dep_map.find(&from) { Some(vec) => vec, None => { let vec = @DVec(); @@ -685,7 +685,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty, // that as a direct dependency. match ty.node { ast::ty_path(path, id) => { - match cx.def_map.find(id) { + match cx.def_map.find(&id) { Some(ast::def_ty(did)) | Some(ast::def_struct(did)) => { if did.crate == ast::local_crate { if cx.opt_region_is_relevant(path.rp) { @@ -818,9 +818,9 @@ pub fn determine_rp_in_crate(sess: Session, // update the region-parameterization of D to reflect the result. while cx.worklist.len() != 0 { let c_id = cx.worklist.pop(); - let c_variance = cx.region_paramd_items.get(c_id); + let c_variance = cx.region_paramd_items.get(&c_id); debug!("popped %d from worklist", c_id); - match cx.dep_map.find(c_id) { + match cx.dep_map.find(&c_id) { None => {} Some(deps) => { for deps.each |dep| { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index c40b6df6926..c647e4db262 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -947,7 +947,7 @@ pub impl Resolver { // Add or reuse the child. let new_parent = ModuleReducedGraphParent(module_); - match module_.children.find(name) { + match module_.children.find(&name) { None => { let child = @NameBindings(); module_.children.insert(name, child); @@ -1558,7 +1558,7 @@ pub impl Resolver { %s", final_ident); let parent_link = self.get_parent_link(new_parent, ident); - match modules.find(def_id) { + match modules.find(&def_id) { None => { child_name_bindings.define_module(Public, parent_link, @@ -1582,7 +1582,8 @@ pub impl Resolver { die!(~"can't happen"); } ModuleParentLink(parent_module, ident) => { - let name_bindings = parent_module.children.get(ident); + let name_bindings = parent_module.children.get( + &ident); resolution.type_target = Some(Target(parent_module, name_bindings)); } @@ -1841,7 +1842,7 @@ pub impl Resolver { self.idents_to_str(module_path.get()), self.session.str_of(target)); - match module_.import_resolutions.find(target) { + match module_.import_resolutions.find(&target) { Some(resolution) => { debug!("(building import directive) bumping \ reference"); @@ -2112,7 +2113,7 @@ pub impl Resolver { let mut type_result = UnknownResult; // Search for direct children of the containing module. - match containing_module.children.find(source) { + match containing_module.children.find(&source) { None => { // Continue. } @@ -2148,7 +2149,7 @@ pub impl Resolver { // Now search the exported imports within the containing // module. - match containing_module.import_resolutions.find(source) { + match containing_module.import_resolutions.find(&source) { None => { // The containing module definitely doesn't have an // exported import with the name in question. We can @@ -2212,7 +2213,7 @@ pub impl Resolver { // We've successfully resolved the import. Write the results in. assert module_.import_resolutions.contains_key_ref(&target); - let import_resolution = module_.import_resolutions.get(target); + let import_resolution = module_.import_resolutions.get(&target); match value_result { BoundResult(target_module, name_bindings) => { @@ -2297,7 +2298,7 @@ pub impl Resolver { let mut module_result = UnknownResult; // Search for direct children of the containing module. - match containing_module.children.find(source) { + match containing_module.children.find(&source) { None => { // Continue. } @@ -2327,7 +2328,7 @@ pub impl Resolver { // Now search the exported imports within the containing // module. - match containing_module.import_resolutions.find(source) { + match containing_module.import_resolutions.find(&source) { None => { // The containing module definitely doesn't have an // exported import with the name in question. We can @@ -2371,7 +2372,7 @@ pub impl Resolver { // We've successfully resolved the import. Write the results in. assert module_.import_resolutions.contains_key_ref(&target); - let import_resolution = module_.import_resolutions.get(target); + let import_resolution = module_.import_resolutions.get(&target); match module_result { BoundResult(target_module, name_bindings) => { @@ -2439,7 +2440,7 @@ pub impl Resolver { self.module_to_str(module_)); // Here we merge two import resolutions. - match module_.import_resolutions.find(ident) { + match module_.import_resolutions.find(&ident) { None => { // Simple: just copy the old import resolution. let new_import_resolution = @@ -2482,7 +2483,7 @@ pub impl Resolver { // Add all children from the containing module. for containing_module.children.each_ref |&ident, &name_bindings| { let mut dest_import_resolution; - match module_.import_resolutions.find(ident) { + match module_.import_resolutions.find(&ident) { None => { // Create a new import resolution from this child. dest_import_resolution = @ImportResolution(privacy, span); @@ -2686,7 +2687,7 @@ pub impl Resolver { // The current module node is handled specially. First, check for // its immediate children. - match module_.children.find(name) { + match module_.children.find(&name) { Some(name_bindings) if (*name_bindings).defined_in_namespace(namespace) => { return Success(Target(module_, name_bindings)); @@ -2699,7 +2700,7 @@ pub impl Resolver { // adjacent import statements are processed as though they mutated the // current scope. - match module_.import_resolutions.find(name) { + match module_.import_resolutions.find(&name) { None => { // Not found; continue. } @@ -2923,7 +2924,7 @@ pub impl Resolver { self.module_to_str(module_)); // First, check the direct children of the module. - match module_.children.find(name) { + match module_.children.find(&name) { Some(name_bindings) if (*name_bindings).defined_in_namespace(namespace) => { @@ -2944,7 +2945,7 @@ pub impl Resolver { } // Otherwise, we check the list of resolved imports. - match module_.import_resolutions.find(name) { + match module_.import_resolutions.find(&name) { Some(import_resolution) => { if import_resolution.outstanding_references != 0 { debug!("(resolving name in module) import unresolved; \ @@ -3114,7 +3115,7 @@ pub impl Resolver { } // Otherwise, proceed and write in the bindings. - match module_.import_resolutions.find(target_name) { + match module_.import_resolutions.find(&target_name) { None => { die!(~"(resolving one-level renaming import) reduced graph \ construction or glob importing should have created the \ @@ -3328,7 +3329,7 @@ pub impl Resolver { // Nothing to do. } Some(name) => { - match orig_module.children.find(name) { + match orig_module.children.find(&name) { None => { debug!("!!! (with scope) didn't find `%s` in `%s`", self.session.str_of(name), @@ -3405,7 +3406,7 @@ pub impl Resolver { // If the def is a ty param, and came from the parent // item, it's ok match def { - def_ty_param(did, _) if self.def_map.find(copy(did.node)) + def_ty_param(did, _) if self.def_map.find(&did.node) == Some(def_typaram_binder(item_id)) => { // ok } @@ -3477,7 +3478,7 @@ pub impl Resolver { while i != 0 { i -= 1; let rib = (*ribs).get_elt(i); - match rib.bindings.find(name) { + match rib.bindings.find(&name) { Some(def_like) => { return self.upvarify(ribs, i, def_like, span, allow_capturing_self); @@ -4069,7 +4070,7 @@ pub impl Resolver { let map_i = self.binding_mode_map(*p); for map_0.each_ref |&key, &binding_0| { - match map_i.find(key) { + match map_i.find(&key) { None => { self.session.span_err( p.span, @@ -4126,7 +4127,7 @@ pub impl Resolver { // Move down in the graph, if there's an anonymous module rooted here. let orig_module = self.current_module; - match self.current_module.anonymous_children.find(block.node.id) { + match self.current_module.anonymous_children.find(&block.node.id) { None => { /* Nothing to do. */ } Some(anonymous_module) => { debug!("(resolving block) found anonymous module, moving \ @@ -4161,7 +4162,7 @@ pub impl Resolver { match self.primitive_type_table .primitive_types - .find(name) { + .find(&name) { Some(primitive_type) => { result_def = @@ -4327,7 +4328,7 @@ pub impl Resolver { bindings_list.insert(ident, pat_id); } Some(b) => { - if b.find(ident) == Some(pat_id) { + if b.find(&ident) == Some(pat_id) { // Then this is a duplicate variable // in the same disjunct, which is an // error @@ -4526,7 +4527,7 @@ pub impl Resolver { -> NameDefinition { // First, search children. - match containing_module.children.find(name) { + match containing_module.children.find(&name) { Some(child_name_bindings) => { match (child_name_bindings.def_for_namespace(namespace), child_name_bindings.privacy_for_namespace(namespace)) { @@ -4549,7 +4550,7 @@ pub impl Resolver { } // Next, search import resolutions. - match containing_module.import_resolutions.find(name) { + match containing_module.import_resolutions.find(&name) { Some(import_resolution) if import_resolution.privacy == Public || xray == Xray => { match (*import_resolution).target_for_namespace(namespace) { @@ -5076,7 +5077,7 @@ pub impl Resolver { trait_def_id.node, self.session.str_of(name)); - match self.trait_info.find(trait_def_id) { + match self.trait_info.find(&trait_def_id) { Some(trait_info) if trait_info.contains_key_ref(&name) => { debug!("(adding trait info if containing method) found trait \ %d:%d for method '%s'", diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 6913cf8e2f5..7dca4174019 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -282,7 +282,7 @@ pub fn trans_opt(bcx: block, o: &Opt) -> opt_result { } pub fn variant_opt(tcx: ty::ctxt, pat_id: ast::node_id) -> Opt { - match tcx.def_map.get(pat_id) { + match tcx.def_map.get(&pat_id) { ast::def_variant(enum_id, var_id) => { let variants = ty::enum_variants(tcx, enum_id); for vec::each(*variants) |v| { @@ -377,7 +377,7 @@ pub fn expand_nested_bindings(bcx: block, m: &[@Match/&r], vec::view(br.pats, col + 1u, br.pats.len()))); let binding_info = - br.data.bindings_map.get(path_to_ident(path)); + br.data.bindings_map.get(&path_to_ident(path)); Store(bcx, val, binding_info.llmatch); @Match {pats: pats, data: br.data} @@ -424,7 +424,8 @@ pub fn enter_match(bcx: block, dm: DefMap, m: &[@Match/&r], ast::pat_ident(_, path, None) => { if pat_is_binding(dm, self) { let binding_info = - br.data.bindings_map.get(path_to_ident(path)); + br.data.bindings_map.get( + &path_to_ident(path)); Store(bcx, val, binding_info.llmatch); } } @@ -518,7 +519,7 @@ pub fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint, } } ast::pat_ident(_, _, None) if pat_is_const(tcx.def_map, p) => { - let const_def = tcx.def_map.get(p.id); + let const_def = tcx.def_map.get(&p.id); let const_def_id = ast_util::def_id_of_def(const_def); if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) { Some(~[]) @@ -536,7 +537,7 @@ pub fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint, if opt_eq(tcx, &variant_opt(tcx, p.id), opt) { // Look up the struct variant ID. let struct_id; - match tcx.def_map.get(p.id) { + match tcx.def_map.get(&p.id) { ast::def_variant(_, found_struct_id) => { struct_id = found_struct_id; } @@ -774,7 +775,7 @@ pub fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[Opt] { ast::pat_ident(*) => { // This is one of: an enum variant, a unit-like struct, or a // variable binding. - match ccx.tcx.def_map.find(cur.id) { + match ccx.tcx.def_map.find(&cur.id) { Some(ast::def_variant(*)) => { add_to_set(ccx.tcx, &found, variant_opt(ccx.tcx, cur.id)); @@ -793,7 +794,7 @@ pub fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[Opt] { ast::pat_enum(*) | ast::pat_struct(*) => { // This could be one of: a tuple-like enum variant, a // struct-like enum variant, or a struct. - match ccx.tcx.def_map.find(cur.id) { + match ccx.tcx.def_map.find(&cur.id) { Some(ast::def_variant(*)) => { add_to_set(ccx.tcx, &found, variant_opt(ccx.tcx, cur.id)); @@ -926,7 +927,7 @@ pub fn root_pats_as_necessary(bcx: block, let pat_id = br.pats[col].id; let key = root_map_key {id: pat_id, derefs: 0u }; - match bcx.ccx().maps.root_map.find(key) { + match bcx.ccx().maps.root_map.find(&key) { None => (), Some(root_info) => { // Note: the scope_id will always be the id of the match. See @@ -981,7 +982,7 @@ pub fn any_tuple_struct_pat(bcx: block, m: &[@Match], col: uint) -> bool { let pat = br.pats[col]; match pat.node { ast::pat_enum(_, Some(_)) => { - match bcx.tcx().def_map.find(pat.id) { + match bcx.tcx().def_map.find(&pat.id) { Some(ast::def_struct(*)) => true, _ => false } @@ -1717,9 +1718,9 @@ pub fn bind_irrefutable_pat(bcx: block, } } ast::pat_enum(_, sub_pats) => { - match bcx.tcx().def_map.find(pat.id) { + match bcx.tcx().def_map.find(&pat.id) { Some(ast::def_variant(*)) => { - let pat_def = ccx.tcx.def_map.get(pat.id); + let pat_def = ccx.tcx.def_map.get(&pat.id); let vdefs = ast_util::variant_def_ids(pat_def); let args = extract_variant_args(bcx, pat.id, vdefs, val); for sub_pats.each |sub_pat| { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index a858ecb520a..a2b1de692be 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -169,7 +169,7 @@ pub fn get_extern_fn(externs: HashMap<~str, ValueRef>, +name: ~str, cc: lib::llvm::CallConv, ty: TypeRef) -> ValueRef { - if externs.contains_key_ref(&name) { return externs.get(name); } + if externs.contains_key_ref(&name) { return externs.get(&name); } // XXX: Bad copy. let f = decl_fn(llmod, copy name, cc, ty); externs.insert(name, f); @@ -179,7 +179,7 @@ pub fn get_extern_fn(externs: HashMap<~str, ValueRef>, pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef, +name: ~str, ty: TypeRef) -> ValueRef { unsafe { - if externs.contains_key_ref(&name) { return externs.get(name); } + if externs.contains_key_ref(&name) { return externs.get(&name); } let c = str::as_c_str(name, |buf| { llvm::LLVMAddGlobal(llmod, ty, buf) }); @@ -372,7 +372,7 @@ pub fn get_tydesc_simple(ccx: @crate_ctxt, t: ty::t) -> ValueRef { } pub fn get_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info { - match ccx.tydescs.find(t) { + match ccx.tydescs.find(&t) { Some(inf) => inf, _ => { ccx.stats.n_static_tydescs += 1u; @@ -807,7 +807,7 @@ pub fn get_discrim_val(cx: @crate_ctxt, span: span, enum_did: ast::def_id, pub fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef { unsafe { let _icx = ccx.insn_ctxt("lookup_discriminant"); - match ccx.discrims.find(vid) { + match ccx.discrims.find(&vid) { None => { // It's an external discriminant that we haven't seen yet. assert (vid.crate != ast::local_crate); @@ -1095,7 +1095,7 @@ pub fn init_local(bcx: block, local: @ast::local) -> block { } } - let llptr = match bcx.fcx.lllocals.find(local.node.id) { + let llptr = match bcx.fcx.lllocals.find(&local.node.id) { Some(local_mem(v)) => v, _ => { bcx.tcx().sess.span_bug(local.span, ~"init_local: Someone forgot to document why it's\ @@ -1437,7 +1437,7 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef, session::arch_x86 | session::arch_arm => ~"llvm.memcpy.p0i8.p0i8.i32", session::arch_x86_64 => ~"llvm.memcpy.p0i8.p0i8.i64" }; - let memcpy = ccx.intrinsics.get(key); + let memcpy = ccx.intrinsics.get(&key); let src_ptr = PointerCast(cx, src, T_ptr(T_i8())); let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8())); let size = IntCast(cx, n_bytes, ccx.int_type); @@ -1484,7 +1484,7 @@ pub fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) { } } - let llintrinsicfn = ccx.intrinsics.get(intrinsic_key); + let llintrinsicfn = ccx.intrinsics.get(&intrinsic_key); let llptr = PointerCast(cx, llptr, T_ptr(T_i8())); let llzeroval = C_u8(0); let size = IntCast(cx, machine::llsize_of(ccx, llty), ccx.int_type); @@ -1884,7 +1884,7 @@ pub fn trans_enum_variant(ccx: @crate_ctxt, // If this argument to this function is a enum, it'll have come in to // this function as an opaque blob due to the way that type_of() // works. So we have to cast to the destination's view of the type. - let llarg = match fcx.llargs.find(va.id) { + let llarg = match fcx.llargs.find(&va.id) { Some(local_mem(x)) => x, _ => die!(~"trans_enum_variant: how do we know this works?"), }; @@ -1930,7 +1930,7 @@ pub fn trans_tuple_struct(ccx: @crate_ctxt, for fields.eachi |i, field| { let lldestptr = GEPi(bcx, fcx.llretptr, [0, 0, i]); - let llarg = match fcx.llargs.get(field.node.id) { + let llarg = match fcx.llargs.get(&field.node.id) { local_mem(x) => x, _ => { ccx.tcx.sess.bug(~"trans_tuple_struct: llarg wasn't \ @@ -2019,7 +2019,7 @@ pub fn trans_enum_def(ccx: @crate_ctxt, enum_definition: ast::enum_def, pub fn trans_item(ccx: @crate_ctxt, item: ast::item) { let _icx = ccx.insn_ctxt("trans_item"); - let path = match ccx.tcx.items.get(item.id) { + let path = match ccx.tcx.items.get(&item.id) { ast_map::node_item(_, p) => p, // tjc: ? _ => die!(~"trans_item"), @@ -2275,7 +2275,7 @@ pub fn fill_fn_pair(bcx: block, pair: ValueRef, llfn: ValueRef, pub fn item_path(ccx: @crate_ctxt, i: @ast::item) -> path { vec::append( - /*bad*/copy *match ccx.tcx.items.get(i.id) { + /*bad*/copy *match ccx.tcx.items.get(&i.id) { ast_map::node_item(_, p) => p, // separate map for paths? _ => die!(~"item_path") @@ -2291,7 +2291,7 @@ pub fn get_dtor_symbol(ccx: @crate_ctxt, +substs: Option) -> ~str { let t = ty::node_id_to_type(ccx.tcx, id); - match ccx.item_symbols.find(id) { + match ccx.item_symbols.find(&id) { Some(ref s) => (/*bad*/copy *s), None if substs.is_none() => { let s = mangle_exported_name( @@ -2326,12 +2326,12 @@ pub fn get_dtor_symbol(ccx: @crate_ctxt, pub fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef { debug!("get_item_val(id=`%?`)", id); let tcx = ccx.tcx; - match ccx.item_vals.find(id) { + match ccx.item_vals.find(&id) { Some(v) => v, None => { let mut exprt = false; - let val = match ccx.tcx.items.get(id) { + let val = match ccx.tcx.items.get(&id) { ast_map::node_item(i, pth) => { let my_path = vec::append(/*bad*/copy *pth, ~[path_name(i.ident)]); @@ -2770,7 +2770,7 @@ pub fn declare_dbg_intrinsics(llmod: ModuleRef, pub fn trap(bcx: block) { let v: ~[ValueRef] = ~[]; - match bcx.ccx().intrinsics.find(~"llvm.trap") { + match bcx.ccx().intrinsics.find(&~"llvm.trap") { Some(x) => { Call(bcx, x, v); }, _ => bcx.sess().bug(~"unbound llvm.trap in trap") } diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index 79236433580..24e9d967fac 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -70,7 +70,7 @@ pub fn count_insn(cx: block, category: &str) { i = 0u; while i < len { let e = /*bad*/copy v[i]; - i = mm.get(/*bad*/ copy e); + i = mm.get(&e); s += ~"/"; s += e; i += 1u; @@ -79,7 +79,7 @@ pub fn count_insn(cx: block, category: &str) { s += ~"/"; s += category; - let n = match h.find(/*bad*/ copy s) { + let n = match h.find(&s) { Some(n) => n, _ => 0u }; diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 833cff80d2d..8cfe8ba8f91 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -70,7 +70,7 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee { return trans_def(bcx, bcx.def(expr.id), expr); } ast::expr_field(base, _, _) => { - match bcx.ccx().maps.method_map.find(expr.id) { + match bcx.ccx().maps.method_map.find(&expr.id) { Some(ref origin) => { // An impl method return meth::trans_method_callee(bcx, expr.id, base, (*origin)); @@ -208,7 +208,7 @@ pub fn trans_fn_ref_with_vtables( // Modify the def_id if this is a default method; we want to be // monomorphizing the trait's code. let (def_id, opt_impl_did) = - match tcx.provided_method_sources.find(def_id) { + match tcx.provided_method_sources.find(&def_id) { None => (def_id, None), Some(source) => (source.method_id, Some(source.impl_id)) }; @@ -234,7 +234,7 @@ pub fn trans_fn_ref_with_vtables( } else if def_id.crate == ast::local_crate { let map_node = session::expect( ccx.sess, - ccx.tcx.items.find(def_id.node), + ccx.tcx.items.find(&def_id.node), || fmt!("local item should be in ast map")); match map_node { @@ -313,7 +313,7 @@ pub fn trans_method_call(in_cx: block, node_id_type(in_cx, call_ex.callee_id), expr_ty(in_cx, call_ex), |cx| { - match cx.ccx().maps.method_map.find(call_ex.id) { + match cx.ccx().maps.method_map.find(&call_ex.id) { Some(ref origin) => { meth::trans_method_callee(cx, call_ex.callee_id, diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index 4cbf6a4f4b7..62e00100d6c 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -419,7 +419,7 @@ pub fn trans_expr_fn(bcx: block, let Result {bcx: bcx, val: closure} = match proto { ast::ProtoBorrowed | ast::ProtoBox | ast::ProtoUniq => { - let cap_vars = ccx.maps.capture_map.get(user_id); + let cap_vars = ccx.maps.capture_map.get(&user_id); let ret_handle = match is_loop_body {Some(x) => x, None => None}; let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, proto, diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 571f16e4b34..0613319e4af 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -700,7 +700,7 @@ pub impl block { } fn def(nid: ast::node_id) -> ast::def { - match self.tcx().def_map.find(nid) { + match self.tcx().def_map.find(&nid) { Some(v) => v, None => { self.tcx().sess.bug(fmt!( @@ -1134,7 +1134,7 @@ pub fn C_u8(i: uint) -> ValueRef { // our boxed-and-length-annotated strings. pub fn C_cstr(cx: @crate_ctxt, +s: ~str) -> ValueRef { unsafe { - match cx.const_cstr_cache.find(/*bad*/copy s) { + match cx.const_cstr_cache.find(&s) { Some(llval) => return llval, None => () } @@ -1356,7 +1356,7 @@ pub fn node_id_type_params(bcx: block, id: ast::node_id) -> ~[ty::t] { pub fn node_vtables(bcx: block, id: ast::node_id) -> Option { - let raw_vtables = bcx.ccx().maps.vtable_map.find(id); + let raw_vtables = bcx.ccx().maps.vtable_map.find(&id); raw_vtables.map( |vts| resolve_vtables_in_fn_ctxt(bcx.fcx, *vts)) } diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index b5652fed10e..12340101d9e 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -82,7 +82,7 @@ pub fn const_vec(cx: @crate_ctxt, e: @ast::expr, es: &[@ast::expr]) pub fn const_deref(cx: @crate_ctxt, v: ValueRef) -> ValueRef { unsafe { - let v = match cx.const_globals.find(v as int) { + let v = match cx.const_globals.find(&(v as int)) { Some(v) => v, None => v }; @@ -127,7 +127,7 @@ pub fn get_const_val(cx: @crate_ctxt, def_id: ast::def_id) -> ValueRef { cx.tcx.sess.bug(~"cross-crate constants"); } if !cx.const_values.contains_key_ref(&def_id.node) { - match cx.tcx.items.get(def_id.node) { + match cx.tcx.items.get(&def_id.node) { ast_map::node_item(@ast::item { node: ast::item_const(_, subexpr), _ }, _) => { @@ -136,7 +136,7 @@ pub fn get_const_val(cx: @crate_ctxt, def_id: ast::def_id) -> ValueRef { _ => cx.tcx.sess.bug(~"expected a const to be an item") } } - cx.const_values.get(def_id.node) + cx.const_values.get(&def_id.node) } pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { @@ -402,7 +402,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { } ast::expr_path(pth) => { assert pth.types.len() == 0; - match cx.tcx.def_map.find(e.id) { + match cx.tcx.def_map.find(&e.id) { Some(ast::def_fn(def_id, purity)) => { assert ast_util::is_local(def_id); let f = base::get_item_val(cx, def_id.node); @@ -437,7 +437,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { } } ast::expr_call(callee, args, _) => { - match cx.tcx.def_map.find(callee.id) { + match cx.tcx.def_map.find(&callee.id) { Some(ast::def_struct(def_id)) => { let ety = ty::expr_ty(cx.tcx, e); let llty = type_of::type_of(cx, ety); @@ -482,7 +482,7 @@ pub fn trans_const(ccx: @crate_ctxt, _e: @ast::expr, id: ast::node_id) { let g = base::get_item_val(ccx, id); // At this point, get_item_val has already translated the // constant's initializer to determine its LLVM type. - let v = ccx.const_values.get(id); + let v = ccx.const_values.get(&id); llvm::LLVMSetInitializer(g, v); llvm::LLVMSetGlobalConstant(g, True); } diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index 240c323965f..8944fceb011 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -184,7 +184,7 @@ pub fn trans_log(log_ex: @ast::expr, let modname = path_str(ccx.sess, copy modpath); let global = if ccx.module_data.contains_key_ref(&modname) { - ccx.module_data.get(modname) + ccx.module_data.get(&modname) } else { let s = link::mangle_internal_name_by_path_and_seq( ccx, modpath, ~"loglevel"); diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index 554cebbbcb7..af966e4df82 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -627,7 +627,7 @@ pub impl Datum { // // (Note: root'd values are always boxes) let key = root_map_key { id: expr_id, derefs: derefs }; - let bcx = match ccx.maps.root_map.find(key) { + let bcx = match ccx.maps.root_map.find(&key) { None => bcx, Some(root_info) => self.root(bcx, root_info) }; @@ -635,7 +635,7 @@ pub impl Datum { // Perform the write guard, if necessary. // // (Note: write-guarded values are always boxes) - let bcx = match ccx.maps.write_guard_map.find(key) { + let bcx = match ccx.maps.write_guard_map.find(&key) { None => bcx, Some(_) => self.perform_write_guard(bcx) }; diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 35abddfb85a..ecb63c19811 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -118,7 +118,7 @@ pub fn mk_ctxt(+crate: ~str, intr: @ident_interner) -> debug_ctxt { fn update_cache(cache: metadata_cache, mdtag: int, val: debug_metadata) { let existing = if cache.contains_key_ref(&mdtag) { - cache.get(mdtag) + cache.get(&mdtag) } else { ~[] }; @@ -177,7 +177,7 @@ fn cached_metadata(cache: metadata_cache, -> Option { unsafe { if cache.contains_key_ref(&mdtag) { - let items = cache.get(mdtag); + let items = cache.get(&mdtag); for items.each |item| { let md: T = md_from_metadata::(*item); if eq_fn(md) { @@ -289,7 +289,7 @@ fn create_block(cx: block) -> @metadata { Some(bcx) => create_block(bcx).node }; let file_node = create_file(cx.ccx(), fname); - let unique_id = match cache.find(LexicalBlockTag) { + let unique_id = match cache.find(&LexicalBlockTag) { option::Some(v) => vec::len(v) as int, option::None => 0 }; @@ -679,14 +679,14 @@ pub fn create_local_var(bcx: block, local: @ast::local) let mdval = @{node: mdnode, data: {id: local.node.id}}; update_cache(cache, AutoVariableTag, local_var_metadata(mdval)); - let llptr = match bcx.fcx.lllocals.find(local.node.id) { + let llptr = match bcx.fcx.lllocals.find(&local.node.id) { option::Some(local_mem(v)) => v, option::Some(_) => { bcx.tcx().sess.span_bug(local.span, ~"local is bound to \ something weird"); } option::None => { - match bcx.fcx.lllocals.get(local.node.pat.id) { + match bcx.fcx.lllocals.get(&local.node.pat.id) { local_imm(v) => v, _ => bcx.tcx().sess.span_bug(local.span, ~"local is bound to \ something weird") @@ -694,7 +694,7 @@ pub fn create_local_var(bcx: block, local: @ast::local) } }; let declargs = ~[llmdnode(~[llptr]), mdnode]; - trans::build::Call(bcx, cx.intrinsics.get(~"llvm.dbg.declare"), + trans::build::Call(bcx, cx.intrinsics.get(&~"llvm.dbg.declare"), declargs); return mdval; } @@ -731,12 +731,12 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span) let mdval = @{node: mdnode, data: {id: arg.id}}; update_cache(cache, tg, argument_metadata(mdval)); - let llptr = match fcx.llargs.get(arg.id) { + let llptr = match fcx.llargs.get(&arg.id) { local_mem(v) | local_imm(v) => v, }; let declargs = ~[llmdnode(~[llptr]), mdnode]; trans::build::Call(bcx, - cx.intrinsics.get(~"llvm.dbg.declare"), + cx.intrinsics.get(&~"llvm.dbg.declare"), declargs); return Some(mdval); } @@ -774,7 +774,7 @@ pub fn create_function(fcx: fn_ctxt) -> @metadata { let sp = fcx.span.get(); log(debug, cx.sess.codemap.span_to_str(sp)); - let (ident, ret_ty, id) = match cx.tcx.items.get(fcx.id) { + let (ident, ret_ty, id) = match cx.tcx.items.get(&fcx.id) { ast_map::node_item(item, _) => { match /*bad*/copy item.node { ast::item_fn(decl, _, _, _) => { diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 4cf449cd972..e19bafdb598 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -185,7 +185,7 @@ fn drop_and_cancel_clean(bcx: block, dat: Datum) -> block { pub fn trans_to_datum(bcx: block, expr: @ast::expr) -> DatumBlock { debug!("trans_to_datum(expr=%s)", bcx.expr_to_str(expr)); - return match bcx.tcx().adjustments.find(expr.id) { + return match bcx.tcx().adjustments.find(&expr.id) { None => { trans_to_datum_unadjusted(bcx, expr) } @@ -329,7 +329,7 @@ fn trans_lvalue(bcx: block, expr: @ast::expr) -> DatumBlock { * instead, but sometimes we call trans_lvalue() directly as a * means of asserting that a particular expression is an lvalue. */ - return match bcx.tcx().adjustments.find(expr.id) { + return match bcx.tcx().adjustments.find(&expr.id) { None => trans_lvalue_unadjusted(bcx, expr), Some(_) => { bcx.sess().span_bug( @@ -742,7 +742,7 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock { // the lvalue in there, and then arrange for it to be cleaned up // at the end of the scope with id `scope_id`: let root_key = root_map_key { id: expr.id, derefs: 0u }; - for bcx.ccx().maps.root_map.find(root_key).each |&root_info| { + for bcx.ccx().maps.root_map.find(&root_key).each |&root_info| { bcx = unrooted_datum.root(bcx, root_info); } @@ -934,7 +934,7 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum { ast::def_upvar(nid, _, _, _) => { // Can't move upvars, so this is never a ZeroMemLastUse. let local_ty = node_id_type(bcx, nid); - match bcx.fcx.llupvars.find(nid) { + match bcx.fcx.llupvars.find(&nid) { Some(val) => { Datum { val: val, @@ -987,7 +987,7 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum { fn take_local(bcx: block, table: HashMap, nid: ast::node_id) -> Datum { - let (v, mode) = match table.find(nid) { + let (v, mode) = match table.find(&nid) { Some(local_mem(v)) => (v, ByRef), Some(local_imm(v)) => (v, ByValue), None => { @@ -1066,7 +1066,7 @@ pub fn with_field_tys(tcx: ty::ctxt, ty_to_str(tcx, ty))); } Some(node_id) => { - match tcx.def_map.get(node_id) { + match tcx.def_map.get(&node_id) { ast::def_variant(_, variant_id) => { op(false, struct_mutable_fields( tcx, variant_id, substs)) @@ -1120,7 +1120,7 @@ fn trans_rec_or_struct(bcx: block, let tcx = bcx.tcx(); let addr = match ty::get(ty).sty { ty::ty_enum(_, ref substs) => { - match tcx.def_map.get(id) { + match tcx.def_map.get(&id) { ast::def_variant(enum_id, variant_id) => { let variant_info = ty::enum_variant_with_id( tcx, enum_id, variant_id); @@ -1479,7 +1479,7 @@ fn trans_overloaded_op(bcx: block, dest: Dest, +autoref_arg: AutorefArg) -> block { - let origin = bcx.ccx().maps.method_map.get(expr.id); + let origin = bcx.ccx().maps.method_map.get(&expr.id); let fty = node_id_type(bcx, expr.callee_id); return callee::trans_call_inner( bcx, expr.info(), fty, @@ -1636,7 +1636,7 @@ fn trans_assign_op(bcx: block, let dst_datum = unpack_datum!(bcx, trans_lvalue_unadjusted(bcx, dst)); // A user-defined operator method - if bcx.ccx().maps.method_map.find(expr.id).is_some() { + if bcx.ccx().maps.method_map.find(&expr.id).is_some() { // FIXME(#2528) evaluates the receiver twice!! let scratch = scratch_datum(bcx, dst_datum.ty, false); let bcx = trans_overloaded_op(bcx, expr, dst, ~[src], diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 9c2245411c6..171fdc79e3a 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -498,7 +498,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, let tp_sz = machine::llbitsize_of_real(ccx, lltp_ty), out_sz = machine::llbitsize_of_real(ccx, llout_ty); if tp_sz != out_sz { - let sp = match ccx.tcx.items.get(ref_id.get()) { + let sp = match ccx.tcx.items.get(&ref_id.get()) { ast_map::node_expr(e) => e.span, _ => die!(~"reinterpret_cast or forget has non-expr arg") }; @@ -535,7 +535,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, abi::tydesc_field_visit_glue, None); } ~"frame_address" => { - let frameaddress = ccx.intrinsics.get(~"llvm.frameaddress"); + let frameaddress = ccx.intrinsics.get(&~"llvm.frameaddress"); let frameaddress_val = Call(bcx, frameaddress, ~[C_i32(0i32)]); let star_u8 = ty::mk_imm_ptr( bcx.tcx(), @@ -576,7 +576,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, let align = C_i32(1); let volatile = C_bool(false); let llfn = bcx.ccx().intrinsics.get( - ~"llvm.memmove.p0i8.p0i8.i32"); + &~"llvm.memmove.p0i8.p0i8.i32"); Call(bcx, llfn, ~[dst_ptr, src_ptr, size, align, volatile]); } ~"memmove64" => { @@ -586,248 +586,248 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, let align = C_i32(1); let volatile = C_bool(false); let llfn = bcx.ccx().intrinsics.get( - ~"llvm.memmove.p0i8.p0i8.i64"); + &~"llvm.memmove.p0i8.p0i8.i64"); Call(bcx, llfn, ~[dst_ptr, src_ptr, size, align, volatile]); } ~"sqrtf32" => { let x = get_param(decl, first_real_arg); - let sqrtf = ccx.intrinsics.get(~"llvm.sqrt.f32"); + let sqrtf = ccx.intrinsics.get(&~"llvm.sqrt.f32"); Store(bcx, Call(bcx, sqrtf, ~[x]), fcx.llretptr); } ~"sqrtf64" => { let x = get_param(decl, first_real_arg); - let sqrtf = ccx.intrinsics.get(~"llvm.sqrt.f64"); + let sqrtf = ccx.intrinsics.get(&~"llvm.sqrt.f64"); Store(bcx, Call(bcx, sqrtf, ~[x]), fcx.llretptr); } ~"powif32" => { let a = get_param(decl, first_real_arg); let x = get_param(decl, first_real_arg + 1u); - let powif = ccx.intrinsics.get(~"llvm.powi.f32"); + let powif = ccx.intrinsics.get(&~"llvm.powi.f32"); Store(bcx, Call(bcx, powif, ~[a, x]), fcx.llretptr); } ~"powif64" => { let a = get_param(decl, first_real_arg); let x = get_param(decl, first_real_arg + 1u); - let powif = ccx.intrinsics.get(~"llvm.powi.f64"); + let powif = ccx.intrinsics.get(&~"llvm.powi.f64"); Store(bcx, Call(bcx, powif, ~[a, x]), fcx.llretptr); } ~"sinf32" => { let x = get_param(decl, first_real_arg); - let sinf = ccx.intrinsics.get(~"llvm.sin.f32"); + let sinf = ccx.intrinsics.get(&~"llvm.sin.f32"); Store(bcx, Call(bcx, sinf, ~[x]), fcx.llretptr); } ~"sinf64" => { let x = get_param(decl, first_real_arg); - let sinf = ccx.intrinsics.get(~"llvm.sin.f64"); + let sinf = ccx.intrinsics.get(&~"llvm.sin.f64"); Store(bcx, Call(bcx, sinf, ~[x]), fcx.llretptr); } ~"cosf32" => { let x = get_param(decl, first_real_arg); - let cosf = ccx.intrinsics.get(~"llvm.cos.f32"); + let cosf = ccx.intrinsics.get(&~"llvm.cos.f32"); Store(bcx, Call(bcx, cosf, ~[x]), fcx.llretptr); } ~"cosf64" => { let x = get_param(decl, first_real_arg); - let cosf = ccx.intrinsics.get(~"llvm.cos.f64"); + let cosf = ccx.intrinsics.get(&~"llvm.cos.f64"); Store(bcx, Call(bcx, cosf, ~[x]), fcx.llretptr); } ~"powf32" => { let a = get_param(decl, first_real_arg); let x = get_param(decl, first_real_arg + 1u); - let powf = ccx.intrinsics.get(~"llvm.pow.f32"); + let powf = ccx.intrinsics.get(&~"llvm.pow.f32"); Store(bcx, Call(bcx, powf, ~[a, x]), fcx.llretptr); } ~"powf64" => { let a = get_param(decl, first_real_arg); let x = get_param(decl, first_real_arg + 1u); - let powf = ccx.intrinsics.get(~"llvm.pow.f64"); + let powf = ccx.intrinsics.get(&~"llvm.pow.f64"); Store(bcx, Call(bcx, powf, ~[a, x]), fcx.llretptr); } ~"expf32" => { let x = get_param(decl, first_real_arg); - let expf = ccx.intrinsics.get(~"llvm.exp.f32"); + let expf = ccx.intrinsics.get(&~"llvm.exp.f32"); Store(bcx, Call(bcx, expf, ~[x]), fcx.llretptr); } ~"expf64" => { let x = get_param(decl, first_real_arg); - let expf = ccx.intrinsics.get(~"llvm.exp.f64"); + let expf = ccx.intrinsics.get(&~"llvm.exp.f64"); Store(bcx, Call(bcx, expf, ~[x]), fcx.llretptr); } ~"exp2f32" => { let x = get_param(decl, first_real_arg); - let exp2f = ccx.intrinsics.get(~"llvm.exp2.f32"); + let exp2f = ccx.intrinsics.get(&~"llvm.exp2.f32"); Store(bcx, Call(bcx, exp2f, ~[x]), fcx.llretptr); } ~"exp2f64" => { let x = get_param(decl, first_real_arg); - let exp2f = ccx.intrinsics.get(~"llvm.exp2.f64"); + let exp2f = ccx.intrinsics.get(&~"llvm.exp2.f64"); Store(bcx, Call(bcx, exp2f, ~[x]), fcx.llretptr); } ~"logf32" => { let x = get_param(decl, first_real_arg); - let logf = ccx.intrinsics.get(~"llvm.log.f32"); + let logf = ccx.intrinsics.get(&~"llvm.log.f32"); Store(bcx, Call(bcx, logf, ~[x]), fcx.llretptr); } ~"logf64" => { let x = get_param(decl, first_real_arg); - let logf = ccx.intrinsics.get(~"llvm.log.f64"); + let logf = ccx.intrinsics.get(&~"llvm.log.f64"); Store(bcx, Call(bcx, logf, ~[x]), fcx.llretptr); } ~"log10f32" => { let x = get_param(decl, first_real_arg); - let log10f = ccx.intrinsics.get(~"llvm.log10.f32"); + let log10f = ccx.intrinsics.get(&~"llvm.log10.f32"); Store(bcx, Call(bcx, log10f, ~[x]), fcx.llretptr); } ~"log10f64" => { let x = get_param(decl, first_real_arg); - let log10f = ccx.intrinsics.get(~"llvm.log10.f64"); + let log10f = ccx.intrinsics.get(&~"llvm.log10.f64"); Store(bcx, Call(bcx, log10f, ~[x]), fcx.llretptr); } ~"log2f32" => { let x = get_param(decl, first_real_arg); - let log2f = ccx.intrinsics.get(~"llvm.log2.f32"); + let log2f = ccx.intrinsics.get(&~"llvm.log2.f32"); Store(bcx, Call(bcx, log2f, ~[x]), fcx.llretptr); } ~"log2f64" => { let x = get_param(decl, first_real_arg); - let log2f = ccx.intrinsics.get(~"llvm.log2.f64"); + let log2f = ccx.intrinsics.get(&~"llvm.log2.f64"); Store(bcx, Call(bcx, log2f, ~[x]), fcx.llretptr); } ~"fmaf32" => { let a = get_param(decl, first_real_arg); let b = get_param(decl, first_real_arg + 1u); let c = get_param(decl, first_real_arg + 2u); - let fmaf = ccx.intrinsics.get(~"llvm.fma.f32"); + let fmaf = ccx.intrinsics.get(&~"llvm.fma.f32"); Store(bcx, Call(bcx, fmaf, ~[a, b, c]), fcx.llretptr); } ~"fmaf64" => { let a = get_param(decl, first_real_arg); let b = get_param(decl, first_real_arg + 1u); let c = get_param(decl, first_real_arg + 2u); - let fmaf = ccx.intrinsics.get(~"llvm.fma.f64"); + let fmaf = ccx.intrinsics.get(&~"llvm.fma.f64"); Store(bcx, Call(bcx, fmaf, ~[a, b, c]), fcx.llretptr); } ~"fabsf32" => { let x = get_param(decl, first_real_arg); - let fabsf = ccx.intrinsics.get(~"llvm.fabs.f32"); + let fabsf = ccx.intrinsics.get(&~"llvm.fabs.f32"); Store(bcx, Call(bcx, fabsf, ~[x]), fcx.llretptr); } ~"fabsf64" => { let x = get_param(decl, first_real_arg); - let fabsf = ccx.intrinsics.get(~"llvm.fabs.f64"); + let fabsf = ccx.intrinsics.get(&~"llvm.fabs.f64"); Store(bcx, Call(bcx, fabsf, ~[x]), fcx.llretptr); } ~"floorf32" => { let x = get_param(decl, first_real_arg); - let floorf = ccx.intrinsics.get(~"llvm.floor.f32"); + let floorf = ccx.intrinsics.get(&~"llvm.floor.f32"); Store(bcx, Call(bcx, floorf, ~[x]), fcx.llretptr); } ~"floorf64" => { let x = get_param(decl, first_real_arg); - let floorf = ccx.intrinsics.get(~"llvm.floor.f64"); + let floorf = ccx.intrinsics.get(&~"llvm.floor.f64"); Store(bcx, Call(bcx, floorf, ~[x]), fcx.llretptr); } ~"ceilf32" => { let x = get_param(decl, first_real_arg); - let ceilf = ccx.intrinsics.get(~"llvm.ceil.f32"); + let ceilf = ccx.intrinsics.get(&~"llvm.ceil.f32"); Store(bcx, Call(bcx, ceilf, ~[x]), fcx.llretptr); } ~"ceilf64" => { let x = get_param(decl, first_real_arg); - let ceilf = ccx.intrinsics.get(~"llvm.ceil.f64"); + let ceilf = ccx.intrinsics.get(&~"llvm.ceil.f64"); Store(bcx, Call(bcx, ceilf, ~[x]), fcx.llretptr); } ~"truncf32" => { let x = get_param(decl, first_real_arg); - let truncf = ccx.intrinsics.get(~"llvm.trunc.f32"); + let truncf = ccx.intrinsics.get(&~"llvm.trunc.f32"); Store(bcx, Call(bcx, truncf, ~[x]), fcx.llretptr); } ~"truncf64" => { let x = get_param(decl, first_real_arg); - let truncf = ccx.intrinsics.get(~"llvm.trunc.f64"); + let truncf = ccx.intrinsics.get(&~"llvm.trunc.f64"); Store(bcx, Call(bcx, truncf, ~[x]), fcx.llretptr); } ~"ctpop8" => { let x = get_param(decl, first_real_arg); - let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i8"); + let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i8"); Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) } ~"ctpop16" => { let x = get_param(decl, first_real_arg); - let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i16"); + let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i16"); Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) } ~"ctpop32" => { let x = get_param(decl, first_real_arg); - let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i32"); + let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i32"); Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) } ~"ctpop64" => { let x = get_param(decl, first_real_arg); - let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i64"); + let ctpop = ccx.intrinsics.get(&~"llvm.ctpop.i64"); Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) } ~"ctlz8" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i8"); + let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i8"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"ctlz16" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i16"); + let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i16"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"ctlz32" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i32"); + let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i32"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"ctlz64" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i64"); + let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i64"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"cttz8" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let cttz = ccx.intrinsics.get(~"llvm.cttz.i8"); + let cttz = ccx.intrinsics.get(&~"llvm.cttz.i8"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"cttz16" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let cttz = ccx.intrinsics.get(~"llvm.cttz.i16"); + let cttz = ccx.intrinsics.get(&~"llvm.cttz.i16"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"cttz32" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let cttz = ccx.intrinsics.get(~"llvm.cttz.i32"); + let cttz = ccx.intrinsics.get(&~"llvm.cttz.i32"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"cttz64" => { let x = get_param(decl, first_real_arg); let y = C_bool(false); - let cttz = ccx.intrinsics.get(~"llvm.cttz.i64"); + let cttz = ccx.intrinsics.get(&~"llvm.cttz.i64"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"bswap16" => { let x = get_param(decl, first_real_arg); - let cttz = ccx.intrinsics.get(~"llvm.bswap.i16"); + let cttz = ccx.intrinsics.get(&~"llvm.bswap.i16"); Store(bcx, Call(bcx, cttz, ~[x]), fcx.llretptr) } ~"bswap32" => { let x = get_param(decl, first_real_arg); - let cttz = ccx.intrinsics.get(~"llvm.bswap.i32"); + let cttz = ccx.intrinsics.get(&~"llvm.bswap.i32"); Store(bcx, Call(bcx, cttz, ~[x]), fcx.llretptr) } ~"bswap64" => { let x = get_param(decl, first_real_arg); - let cttz = ccx.intrinsics.get(~"llvm.bswap.i64"); + let cttz = ccx.intrinsics.get(&~"llvm.bswap.i64"); Store(bcx, Call(bcx, cttz, ~[x]), fcx.llretptr) } _ => { @@ -955,7 +955,7 @@ pub fn register_foreign_fn(ccx: @crate_ctxt, fn abi_of_foreign_fn(ccx: @crate_ctxt, i: @ast::foreign_item) -> ast::foreign_abi { match attr::first_attr_value_str_by_name(i.attrs, ~"abi") { - None => match ccx.tcx.items.get(i.id) { + None => match ccx.tcx.items.get(&i.id) { ast_map::node_foreign_item(_, abi, _) => abi, // ?? _ => die!(~"abi_of_foreign_fn: not foreign") diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 849a718a52e..9909980fb7e 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -381,7 +381,7 @@ pub fn make_visit_glue(bcx: block, v: ValueRef, t: ty::t) { let mut bcx = bcx; let ty_visitor_name = special_idents::ty_visitor; assert bcx.ccx().tcx.intrinsic_defs.contains_key_ref(&ty_visitor_name); - let (trait_id, ty) = bcx.ccx().tcx.intrinsic_defs.get(ty_visitor_name); + let (trait_id, ty) = bcx.ccx().tcx.intrinsic_defs.get(&ty_visitor_name); let v = PointerCast(bcx, v, T_ptr(type_of::type_of(bcx.ccx(), ty))); bcx = reflect::emit_calls_to_trait_visit_ty(bcx, t, v, trait_id); build_return(bcx); diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index f5d23236334..4466e4e1b28 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -31,7 +31,7 @@ pub fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id, translate: bool) -> ast::def_id { let _icx = ccx.insn_ctxt("maybe_instantiate_inline"); - match ccx.external.find(fn_id) { + match ccx.external.find(&fn_id) { Some(Some(node_id)) => { // Already inline debug!("maybe_instantiate_inline(%s): already inline as node id %d", diff --git a/src/librustc/middle/trans/machine.rs b/src/librustc/middle/trans/machine.rs index 1b3e13cddab..e76176218b7 100644 --- a/src/librustc/middle/trans/machine.rs +++ b/src/librustc/middle/trans/machine.rs @@ -178,7 +178,7 @@ pub fn llalign_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef { // Computes the size of the data part of an enum. pub fn static_size_of_enum(cx: @crate_ctxt, t: ty::t) -> uint { - if cx.enum_sizes.contains_key_ref(&t) { return cx.enum_sizes.get(t); } + if cx.enum_sizes.contains_key_ref(&t) { return cx.enum_sizes.get(&t); } match ty::get(t).sty { ty::ty_enum(tid, ref substs) => { // Compute max(variant sizes). diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index f488c32437c..d751b8f9208 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -308,7 +308,7 @@ pub fn trans_static_method_callee(bcx: block, }; let mname = if method_id.crate == ast::local_crate { - match bcx.tcx().items.get(method_id.node) { + match bcx.tcx().items.get(&method_id.node) { ast_map::node_trait_method(trait_method, _, _) => { ast_util::trait_method_to_ty_method(*trait_method).ident } @@ -325,7 +325,7 @@ pub fn trans_static_method_callee(bcx: block, name=%s", method_id, callee_id, ccx.sess.str_of(mname)); let vtbls = resolve_vtables_in_fn_ctxt( - bcx.fcx, ccx.maps.vtable_map.get(callee_id)); + bcx.fcx, ccx.maps.vtable_map.get(&callee_id)); match /*bad*/copy vtbls[bound_index] { typeck::vtable_static(impl_did, rcvr_substs, rcvr_origins) => { @@ -362,7 +362,7 @@ pub fn method_from_methods(ms: ~[@ast::method], name: ast::ident) pub fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id, name: ast::ident) -> ast::def_id { if impl_id.crate == ast::local_crate { - match ccx.tcx.items.get(impl_id.node) { + match ccx.tcx.items.get(&impl_id.node) { ast_map::node_item(@ast::item { node: ast::item_impl(_, _, _, ref ms), _ @@ -379,7 +379,7 @@ pub fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id, pub fn method_with_name_or_default(ccx: @crate_ctxt, impl_id: ast::def_id, name: ast::ident) -> ast::def_id { if impl_id.crate == ast::local_crate { - match ccx.tcx.items.get(impl_id.node) { + match ccx.tcx.items.get(&impl_id.node) { ast_map::node_item(@ast::item { node: ast::item_impl(_, _, _, ref ms), _ }, _) => { @@ -389,7 +389,7 @@ pub fn method_with_name_or_default(ccx: @crate_ctxt, impl_id: ast::def_id, } else { // Look for a default method let pmm = ccx.tcx.provided_methods; - match pmm.find(impl_id) { + match pmm.find(&impl_id) { Some(pmis) => { for pmis.each |pmi| { if pmi.method_info.ident == name { @@ -414,10 +414,10 @@ pub fn method_ty_param_count(ccx: @crate_ctxt, m_id: ast::def_id, i_id: ast::def_id) -> uint { debug!("method_ty_param_count: m_id: %?, i_id: %?", m_id, i_id); if m_id.crate == ast::local_crate { - match ccx.tcx.items.find(m_id.node) { + match ccx.tcx.items.find(&m_id.node) { Some(ast_map::node_method(m, _, _)) => m.tps.len(), None => { - match ccx.tcx.provided_method_sources.find(m_id) { + match ccx.tcx.provided_method_sources.find(&m_id) { Some(source) => { method_ty_param_count( ccx, source.method_id, source.impl_id) @@ -779,7 +779,7 @@ pub fn get_vtable(ccx: @crate_ctxt, -> ValueRef { // XXX: Bad copy. let hash_id = vtable_id(ccx, copy origin); - match ccx.vtables.find(hash_id) { + match ccx.vtables.find(&hash_id) { Some(val) => val, None => match origin { typeck::vtable_static(id, substs, sub_vtables) => { @@ -916,7 +916,7 @@ pub fn trans_trait_cast(bcx: block, } // Store the vtable into the pair or triple. - let orig = /*bad*/copy ccx.maps.vtable_map.get(id)[0]; + let orig = /*bad*/copy ccx.maps.vtable_map.get(&id)[0]; let orig = resolve_vtable_in_fn_ctxt(bcx.fcx, orig); let vtable = get_vtable(bcx.ccx(), orig); Store(bcx, vtable, PointerCast(bcx, diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 60b4057d448..5873d0a76d9 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -69,7 +69,7 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, real_substs.map(|s| ty_to_str(ccx.tcx, *s)), substs.map(|s| ty_to_str(ccx.tcx, *s)), hash_id); - match ccx.monomorphized.find(hash_id) { + match ccx.monomorphized.find(&hash_id) { Some(val) => { debug!("leaving monomorphic fn %s", ty::item_path_str(ccx.tcx, fn_id)); @@ -81,7 +81,7 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, let tpt = ty::lookup_item_type(ccx.tcx, fn_id); let mut llitem_ty = tpt.ty; - let map_node = session::expect(ccx.sess, ccx.tcx.items.find(fn_id.node), + let map_node = session::expect(ccx.sess, ccx.tcx.items.find(&fn_id.node), || fmt!("While monomorphizing %?, couldn't find it in the item map \ (may have attempted to monomorphize an item defined in a different \ crate?)", fn_id)); @@ -136,7 +136,7 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, ccx.stats.n_monos += 1; - let depth = option::get_or_default(ccx.monomorphizing.find(fn_id), 0u); + let depth = option::get_or_default(ccx.monomorphizing.find(&fn_id), 0u); // Random cut-off -- code that needs to instantiate the same function // recursively more than ten times can probably safely be assumed to be // causing an infinite expansion. diff --git a/src/librustc/middle/trans/reachable.rs b/src/librustc/middle/trans/reachable.rs index 02e07e8484a..112b9ac4d07 100644 --- a/src/librustc/middle/trans/reachable.rs +++ b/src/librustc/middle/trans/reachable.rs @@ -54,7 +54,7 @@ pub fn find_reachable(crate_mod: _mod, exp_map2: resolve::ExportMap2, fn traverse_exports(cx: ctx, mod_id: node_id) -> bool { let mut found_export = false; - match cx.exp_map2.find(mod_id) { + match cx.exp_map2.find(&mod_id) { Some(ref exp2s) => { for (*exp2s).each |e2| { found_export = true; @@ -68,7 +68,7 @@ fn traverse_exports(cx: ctx, mod_id: node_id) -> bool { fn traverse_def_id(cx: ctx, did: def_id) { if did.crate != local_crate { return; } - let n = match cx.tcx.items.find(did.node) { + let n = match cx.tcx.items.find(&did.node) { None => return, // This can happen for self, for example Some(ref n) => (/*bad*/copy *n) }; @@ -150,7 +150,7 @@ fn traverse_ty(ty: @Ty, cx: ctx, v: visit::vt) { match ty.node { ty_path(p, p_id) => { - match cx.tcx.def_map.find(p_id) { + match cx.tcx.def_map.find(&p_id) { // Kind of a hack to check this here, but I'm not sure what else // to do Some(def_prim_ty(_)) => { /* do nothing */ } @@ -169,7 +169,7 @@ fn traverse_inline_body(cx: ctx, body: blk) { fn traverse_expr(e: @expr, cx: ctx, v: visit::vt) { match e.node { expr_path(_) => { - match cx.tcx.def_map.find(e.id) { + match cx.tcx.def_map.find(&e.id) { Some(d) => { traverse_def_id(cx, def_id_of_def(d)); } @@ -179,7 +179,7 @@ fn traverse_inline_body(cx: ctx, body: blk) { } } expr_field(_, _, _) => { - match cx.method_map.find(e.id) { + match cx.method_map.find(&e.id) { Some(typeck::method_map_entry { origin: typeck::method_static(did), _ @@ -190,7 +190,7 @@ fn traverse_inline_body(cx: ctx, body: blk) { } } expr_method_call(*) => { - match cx.method_map.find(e.id) { + match cx.method_map.find(&e.id) { Some(typeck::method_map_entry { origin: typeck::method_static(did), _ diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index b9a055ad8ab..59ba55920fd 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -317,7 +317,7 @@ pub fn emit_calls_to_trait_visit_ty(bcx: block, use syntax::parse::token::special_idents::tydesc; let final = sub_block(bcx, ~"final"); assert bcx.ccx().tcx.intrinsic_defs.contains_key_ref(&tydesc); - let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get(tydesc); + let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get(&tydesc); let tydesc_ty = type_of::type_of(bcx.ccx(), tydesc_ty); let r = reflector({ visitor_val: visitor_val, diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 72efab0c371..99c47997df0 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -87,7 +87,7 @@ pub fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef { debug!("type_of %?: %?", t, ty::get(t)); // Check the cache. - if cx.lltypes.contains_key_ref(&t) { return cx.lltypes.get(t); } + if cx.lltypes.contains_key_ref(&t) { return cx.lltypes.get(&t); } // Replace any typedef'd types with their equivalent non-typedef // type. This ensures that all LLVM nominal types that contain diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index 350b1393c33..6b0d4e17c74 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -53,7 +53,7 @@ pub type ctx = {ccx: @crate_ctxt, uses: ~[mut type_uses]}; pub fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint) -> ~[type_uses] { - match ccx.type_use_cache.find(fn_id) { + match ccx.type_use_cache.find(&fn_id) { Some(uses) => return uses, None => () } @@ -87,7 +87,7 @@ pub fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint) ccx.type_use_cache.insert(fn_id, copy uses); return uses; } - let map_node = match ccx.tcx.items.find(fn_id_loc.node) { + let map_node = match ccx.tcx.items.find(&fn_id_loc.node) { Some(ref x) => (/*bad*/copy *x), None => ccx.sess.bug(fmt!("type_uses_for: unbound item ID %?", fn_id_loc)) @@ -226,10 +226,10 @@ pub fn node_type_needs(cx: ctx, use_: uint, id: node_id) { } pub fn mark_for_method_call(cx: ctx, e_id: node_id, callee_id: node_id) { - do option::iter(&cx.ccx.maps.method_map.find(e_id)) |mth| { + do option::iter(&cx.ccx.maps.method_map.find(&e_id)) |mth| { match mth.origin { typeck::method_static(did) => { - do cx.ccx.tcx.node_type_substs.find(callee_id).iter |ts| { + do cx.ccx.tcx.node_type_substs.find(&callee_id).iter |ts| { let type_uses = type_uses_for(cx.ccx, did, ts.len()); for vec::each2(type_uses, *ts) |uses, subst| { type_needs(cx, *uses, *subst) @@ -278,8 +278,8 @@ pub fn mark_for_expr(cx: ctx, e: @expr) { } } expr_path(_) => { - do cx.ccx.tcx.node_type_substs.find(e.id).iter |ts| { - let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(e.id)); + do cx.ccx.tcx.node_type_substs.find(&e.id).iter |ts| { + let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(&e.id)); let uses_for_ts = type_uses_for(cx.ccx, id, ts.len()); for vec::each2(uses_for_ts, *ts) |uses, subst| { type_needs(cx, *uses, *subst) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 2bfcecfd2f7..9905701e058 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -876,7 +876,7 @@ fn mk_t(cx: ctxt, +st: sty) -> t { mk_t_with_id(cx, st, None) } // and returns the box as cast to an unsafe ptr (see comments for t above). fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option) -> t { let key = intern_key { sty: to_unsafe_ptr(&st), o_def_id: o_def_id }; - match cx.interner.find(key) { + match cx.interner.find(&key) { Some(t) => unsafe { return cast::reinterpret_cast(&t); }, _ => () } @@ -1142,7 +1142,7 @@ pub fn default_arg_mode_for_ty(tcx: ctxt, ty: ty::t) -> ast::rmode { // Returns the narrowest lifetime enclosing the evaluation of the expression // with id `id`. pub fn encl_region(cx: ctxt, id: ast::node_id) -> ty::Region { - match cx.region_map.find(id) { + match cx.region_map.find(&id) { Some(encl_scope) => ty::re_scope(encl_scope), None => ty::re_static } @@ -1653,7 +1653,7 @@ pub fn type_is_immediate(ty: t) -> bool { } pub fn type_needs_drop(cx: ctxt, ty: t) -> bool { - match cx.needs_drop_cache.find(ty) { + match cx.needs_drop_cache.find(&ty) { Some(result) => return result, None => {/* fall through */ } } @@ -1732,7 +1732,7 @@ pub fn type_needs_drop(cx: ctxt, ty: t) -> bool { // that only contain scalars and shared boxes can avoid unwind // cleanups. pub fn type_needs_unwind_cleanup(cx: ctxt, ty: t) -> bool { - match cx.needs_unwind_cleanup_cache.find(ty) { + match cx.needs_unwind_cleanup_cache.find(&ty) { Some(result) => return result, None => () } @@ -1749,7 +1749,7 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t, encountered_box: bool) -> bool { // Prevent infinite recursion - match tycache.find(ty) { + match tycache.find(&ty) { Some(_) => return false, None => { tycache.insert(ty, ()); } } @@ -2011,7 +2011,7 @@ pub fn type_kind(cx: ctxt, ty: t) -> Kind { // If `allow_ty_var` is true, then this is a conservative assumption; we // assume that type variables *do* have all kinds. pub fn type_kind_ext(cx: ctxt, ty: t, allow_ty_var: bool) -> Kind { - match cx.kind_cache.find(ty) { + match cx.kind_cache.find(&ty) { Some(result) => return result, None => {/* fall through */ } } @@ -2165,7 +2165,7 @@ pub fn type_kind_ext(cx: ctxt, ty: t, allow_ty_var: bool) -> Kind { // cross-crate inlining code to translate a def-id. assert p.def_id.crate == ast::local_crate; - param_bounds_to_kind(cx.ty_param_bounds.get(p.def_id.node)) + param_bounds_to_kind(cx.ty_param_bounds.get(&p.def_id.node)) } // self is a special type parameter that can only appear in traits; it @@ -2810,7 +2810,7 @@ pub fn node_id_to_type(cx: ctxt, id: ast::node_id) -> t { } pub fn node_id_to_type_params(cx: ctxt, id: ast::node_id) -> ~[t] { - match cx.node_type_substs.find(id) { + match cx.node_type_substs.find(&id) { None => return ~[], Some(ts) => return ts } @@ -2950,7 +2950,7 @@ pub fn expr_ty_adjusted(cx: ctxt, expr: @ast::expr) -> t { let unadjusted_ty = expr_ty(cx, expr); - return match cx.adjustments.find(expr.id) { + return match cx.adjustments.find(&expr.id) { None => unadjusted_ty, Some(adj) => { @@ -3054,7 +3054,7 @@ pub fn expr_has_ty_params(cx: ctxt, expr: @ast::expr) -> bool { pub fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map, id: ast::node_id) -> Option<@~[param_bounds]> { - do method_map.find(id).map |method| { + do method_map.find(&id).map |method| { match method.origin { typeck::method_static(did) => { // n.b.: When we encode impl methods, the bounds @@ -3081,7 +3081,7 @@ pub fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map, } fn resolve_expr(tcx: ctxt, expr: @ast::expr) -> ast::def { - match tcx.def_map.find(expr.id) { + match tcx.def_map.find(&expr.id) { Some(def) => def, None => { tcx.sess.span_bug(expr.span, fmt!( @@ -3335,7 +3335,7 @@ pub fn occurs_check(tcx: ctxt, sp: span, vid: TyVid, rt: t) { fn canon(tbl: HashMap>, +m0: ast::inferable) -> ast::inferable { match m0 { - ast::infer(id) => match tbl.find(id) { + ast::infer(id) => match tbl.find(&id) { None => m0, Some(ref m1) => { let cm1 = canon(tbl, (*m1)); @@ -3597,7 +3597,7 @@ pub fn store_trait_methods(cx: ctxt, id: ast::node_id, ms: @~[method]) { pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[ast::ident] { if is_local(id) { - match cx.items.find(id.node) { + match cx.items.find(&id.node) { Some(ast_map::node_item(@ast::item { node: item_trait(_, _, ref ms), _ @@ -3617,7 +3617,7 @@ pub fn trait_supertraits(cx: ctxt, id: ast::def_id) -> @~[InstantiatedTraitRef] { // Check the cache. - match cx.supertraits.find(id) { + match cx.supertraits.find(&id) { Some(instantiated_trait_info) => { return instantiated_trait_info; } None => {} // Continue. } @@ -3646,7 +3646,7 @@ pub fn trait_supertraits(cx: ctxt, } pub fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] { - match cx.trait_method_cache.find(id) { + match cx.trait_method_cache.find(&id) { // Local traits are supposed to have been added explicitly. Some(ms) => ms, _ => { @@ -3680,7 +3680,7 @@ pub fn impl_traits(cx: ctxt, id: ast::def_id, vstore: vstore) -> ~[t] { if id.crate == ast::local_crate { debug!("(impl_traits) searching for trait impl %?", id); - match cx.items.find(id.node) { + match cx.items.find(&id.node) { Some(ast_map::node_item(@ast::item { node: ast::item_impl(_, opt_trait, _, _), _}, @@ -3716,7 +3716,7 @@ fn struct_ctor_id(cx: ctxt, struct_did: ast::def_id) -> Option { cx.sess.unimpl(~"constructor ID of cross-crate tuple structs"); } - match cx.items.find(struct_did.node) { + match cx.items.find(&struct_did.node) { Some(ast_map::node_item(item, _)) => { match item.node { ast::item_struct(struct_def, _) => { @@ -3782,13 +3782,13 @@ impl DtorKind { /* If struct_id names a struct with a dtor, return Some(the dtor's id). Otherwise return none. */ pub fn ty_dtor(cx: ctxt, struct_id: def_id) -> DtorKind { - match cx.destructor_for_type.find(struct_id) { + match cx.destructor_for_type.find(&struct_id) { Some(method_def_id) => return TraitDtor(method_def_id), None => {} // Continue. } if is_local(struct_id) { - match cx.items.find(struct_id.node) { + match cx.items.find(&struct_id.node) { Some(ast_map::node_item(@ast::item { node: ast::item_struct(@ast::struct_def { dtor: Some(ref dtor), _ }, @@ -3816,7 +3816,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path { if id.crate != ast::local_crate { csearch::get_item_path(cx, id) } else { - let node = cx.items.get(id.node); + let node = cx.items.get(&id.node); match node { ast_map::node_item(item, path) => { let item_elt = match item.node { @@ -3880,7 +3880,7 @@ pub fn type_is_empty(cx: ctxt, t: t) -> bool { } pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] { - match cx.enum_var_cache.find(id) { + match cx.enum_var_cache.find(&id) { Some(variants) => return variants, _ => { /* fallthrough */ } } @@ -3893,7 +3893,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] { call eval_const_expr, it should never get called twice for the same expr, since check_enum_variants also updates the enum_var_cache */ - match cx.items.get(id.node) { + match cx.items.get(&id.node) { ast_map::node_item(@ast::item { node: ast::item_enum(ref enum_definition, _), _ @@ -3967,7 +3967,7 @@ pub fn enum_variant_with_id(cx: ctxt, pub fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_bounds_and_ty { - match cx.tcache.find(did) { + match cx.tcache.find(&did) { Some(tpt) => { // The item is in this crate. The caller should have added it to the // type cache already @@ -3993,7 +3993,7 @@ pub fn lookup_field_type(tcx: ctxt, node_id_to_type(tcx, id.node) } else { - match tcx.tcache.find(id) { + match tcx.tcache.find(&id) { Some(tpt) => tpt.ty, None => { let tpt = csearch::get_field_type(tcx, struct_id, id); @@ -4009,7 +4009,7 @@ pub fn lookup_field_type(tcx: ctxt, // Fails if the id is not bound to a struct. pub fn lookup_struct_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] { if did.crate == ast::local_crate { - match cx.items.find(did.node) { + match cx.items.find(&did.node) { Some(ast_map::node_item(i,_)) => { match i.node { ast::item_struct(struct_def, _) => { @@ -4214,7 +4214,7 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t { } } - match cx.normalized_cache.find(t) { + match cx.normalized_cache.find(&t) { Some(t) => return t, None => () } @@ -4397,8 +4397,8 @@ pub fn count_traits_and_supertraits(tcx: ctxt, // Given a trait and a type, returns the impl of that type pub fn get_impl_id(tcx: ctxt, trait_id: def_id, self_ty: t) -> def_id { - match tcx.trait_impls.find(trait_id) { - Some(ty_to_impl) => match ty_to_impl.find(self_ty) { + match tcx.trait_impls.find(&trait_id) { + Some(ty_to_impl) => match ty_to_impl.find(&self_ty) { Some(the_impl) => the_impl.did, None => // try autoderef! match deref(tcx, self_ty, false) { diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 4e4fc564c23..070360ce32f 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -211,7 +211,7 @@ pub fn ast_ty_to_ty( return ty::mk_evec(tcx, mt, vst); } ast::ty_path(path, id) if a_seq_ty.mutbl == ast::m_imm => { - match tcx.def_map.find(id) { + match tcx.def_map.find(&id) { Some(ast::def_prim_ty(ast::ty_str)) => { check_path_args(tcx, path, NO_TPS | NO_REGIONS); return ty::mk_estr(tcx, vst); @@ -273,7 +273,7 @@ pub fn ast_ty_to_ty( let tcx = self.tcx(); - match tcx.ast_ty_to_ty_cache.find(ast_ty) { + match tcx.ast_ty_to_ty_cache.find(&ast_ty) { Some(ty::atttce_resolved(ty)) => return ty, Some(ty::atttce_unresolved) => { tcx.sess.span_fatal(ast_ty.span, ~"illegal recursive type; \ @@ -330,7 +330,7 @@ pub fn ast_ty_to_ty( ty::mk_fn(tcx, fn_decl) } ast::ty_path(path, id) => { - let a_def = match tcx.def_map.find(id) { + let a_def = match tcx.def_map.find(&id) { None => tcx.sess.span_fatal( ast_ty.span, fmt!("unbound path %s", path_to_str(path, tcx.sess.intr()))), diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 3e898ce3aa6..1d84cb32c94 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -216,7 +216,7 @@ pub fn check_struct_pat_fields(pcx: pat_ctxt, // Typecheck each field. let found_fields = HashMap(); for fields.each |field| { - match field_map.find(field.ident) { + match field_map.find(&field.ident) { Some(index) => { let class_field = class_fields[index]; let field_type = ty::lookup_field_type(tcx, @@ -259,7 +259,7 @@ pub fn check_struct_pat(pcx: pat_ctxt, pat_id: ast::node_id, span: span, let class_fields = ty::lookup_struct_fields(tcx, class_id); // Check to ensure that the struct is the one specified. - match tcx.def_map.find(pat_id) { + match tcx.def_map.find(&pat_id) { Some(ast::def_struct(supplied_def_id)) if supplied_def_id == class_id => { // OK. @@ -300,7 +300,7 @@ pub fn check_struct_like_enum_variant_pat(pcx: pat_ctxt, let tcx = pcx.fcx.ccx.tcx; // Find the variant that was specified. - match tcx.def_map.find(pat_id) { + match tcx.def_map.find(&pat_id) { Some(ast::def_variant(found_enum_id, variant_id)) if found_enum_id == enum_id => { // Get the struct fields from this struct-like enum variant. @@ -360,7 +360,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { fcx.write_ty(pat.id, b_ty); } ast::pat_ident(*) if pat_is_const(tcx.def_map, pat) => { - let const_did = ast_util::def_id_of_def(tcx.def_map.get(pat.id)); + let const_did = ast_util::def_id_of_def(tcx.def_map.get(&pat.id)); let const_tpt = ty::lookup_item_type(tcx, const_did); fcx.write_ty(pat.id, const_tpt.ty); } @@ -386,7 +386,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) { } } - let canon_id = pcx.map.get(ast_util::path_to_ident(name)); + let canon_id = pcx.map.get(&ast_util::path_to_ident(name)); if canon_id != pat.id { let ct = fcx.local_ty(pat.span, canon_id); demand::eqtype(fcx, pat.span, ct, typ); diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 5a12f9fc3a1..b86f8f26c25 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -323,14 +323,15 @@ pub impl LookupContext { // If the method being called is associated with a trait, then // find all the impls of that trait. Each of those are // candidates. - let opt_applicable_traits = self.fcx.ccx.trait_map.find(self.expr.id); + let opt_applicable_traits = self.fcx.ccx.trait_map.find( + &self.expr.id); for opt_applicable_traits.each |applicable_traits| { for applicable_traits.each |trait_did| { let coherence_info = self.fcx.ccx.coherence_info; // Look for explicit implementations. let opt_impl_infos = - coherence_info.extension_methods.find(*trait_did); + coherence_info.extension_methods.find(trait_did); for opt_impl_infos.each |impl_infos| { for impl_infos.each |impl_info| { self.push_candidates_from_impl( @@ -339,7 +340,7 @@ pub impl LookupContext { } // Look for default methods. - match self.tcx().provided_methods.find(*trait_did) { + match self.tcx().provided_methods.find(trait_did) { Some(methods) => { self.push_candidates_from_provided_methods( &self.extension_candidates, self_ty, *trait_did, @@ -360,7 +361,7 @@ pub impl LookupContext { let tcx = self.tcx(); let mut next_bound_idx = 0; // count only trait bounds - let bounds = tcx.ty_param_bounds.get(param_ty.def_id.node); + let bounds = tcx.ty_param_bounds.get(¶m_ty.def_id.node); for vec::each(*bounds) |bound| { let bound_trait_ty = match *bound { @@ -607,7 +608,7 @@ pub impl LookupContext { fn push_inherent_impl_candidates_for_type(did: def_id) { let opt_impl_infos = - self.fcx.ccx.coherence_info.inherent_methods.find(did); + self.fcx.ccx.coherence_info.inherent_methods.find(&did); for opt_impl_infos.each |impl_infos| { for impl_infos.each |impl_info| { self.push_candidates_from_impl( @@ -1232,7 +1233,7 @@ pub impl LookupContext { fn report_static_candidate(&self, idx: uint, did: def_id) { let span = if did.crate == ast::local_crate { - match self.tcx().items.find(did.node) { + match self.tcx().items.find(&did.node) { Some(ast_map::node_method(m, _, _)) => m.span, _ => die!(fmt!("report_static_candidate: bad item %?", did)) } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index f3abfe3282a..1c0881b6ed5 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -405,7 +405,7 @@ pub fn check_fn(ccx: @crate_ctxt, assign(self_info.self_id, Some(self_info.self_ty)); debug!("self is assigned to %s", fcx.infcx().ty_to_str( - fcx.inh.locals.get(self_info.self_id))); + fcx.inh.locals.get(&self_info.self_id))); } // Add formal parameters. @@ -438,7 +438,7 @@ pub fn check_fn(ccx: @crate_ctxt, debug!("Local variable %s is assigned type %s", fcx.pat_to_str(local.node.pat), fcx.infcx().ty_to_str( - fcx.inh.locals.get(local.node.id))); + fcx.inh.locals.get(&local.node.id))); visit::visit_local(local, e, v); }; @@ -451,7 +451,7 @@ pub fn check_fn(ccx: @crate_ctxt, debug!("Pattern binding %s is assigned to %s", tcx.sess.str_of(path.idents[0]), fcx.infcx().ty_to_str( - fcx.inh.locals.get(p.id))); + fcx.inh.locals.get(&p.id))); } _ => {} } @@ -501,7 +501,7 @@ pub fn check_no_duplicate_fields(tcx: ty::ctxt, for fields.each |p| { let (id, sp) = *p; - match field_names.find(id) { + match field_names.find(&id) { Some(orig_sp) => { tcx.sess.span_err(sp, fmt!("Duplicate field \ name %s in record type declaration", @@ -558,7 +558,7 @@ pub fn check_item(ccx: @crate_ctxt, it: @ast::item) { check_bare_fn(ccx, decl, (*body), it.id, None); } ast::item_impl(_, _, ty, ms) => { - let rp = ccx.tcx.region_paramd_items.find(it.id); + let rp = ccx.tcx.region_paramd_items.find(&it.id); debug!("item_impl %s with id %d rp %?", ccx.tcx.sess.str_of(it.ident), it.id, rp); let self_ty = ccx.to_ty(rscope::type_rscope(rp), ty); @@ -664,7 +664,7 @@ pub impl @fn_ctxt { fn tag() -> ~str { fmt!("%x", ptr::addr_of(&(*self)) as uint) } fn local_ty(span: span, nid: ast::node_id) -> ty::t { - match self.inh.locals.find(nid) { + match self.inh.locals.find(&nid) { Some(t) => t, None => { self.tcx().sess.span_bug( @@ -740,7 +740,7 @@ pub impl @fn_ctxt { } fn expr_ty(ex: @ast::expr) -> ty::t { - match self.inh.node_types.find(ex.id) { + match self.inh.node_types.find(&ex.id) { Some(t) => t, None => { self.tcx().sess.bug( @@ -750,7 +750,7 @@ pub impl @fn_ctxt { } } fn node_ty(id: ast::node_id) -> ty::t { - match self.inh.node_types.find(id) { + match self.inh.node_types.find(&id) { Some(t) => t, None => { self.tcx().sess.bug( @@ -763,7 +763,7 @@ pub impl @fn_ctxt { } } fn node_ty_substs(id: ast::node_id) -> ty::substs { - match self.inh.node_type_substs.find(id) { + match self.inh.node_type_substs.find(&id) { Some(ref ts) => (/*bad*/copy *ts), None => { self.tcx().sess.bug( @@ -776,7 +776,7 @@ pub impl @fn_ctxt { } } fn opt_node_ty_substs(id: ast::node_id) -> Option { - self.inh.node_type_substs.find(id) + self.inh.node_type_substs.find(&id) } @@ -1001,8 +1001,8 @@ pub fn impl_self_ty(vcx: &VtableContext, let tcx = vcx.tcx(); let {n_tps, region_param, raw_ty} = if did.crate == ast::local_crate { - let region_param = tcx.region_paramd_items.find(did.node); - match tcx.items.find(did.node) { + let region_param = tcx.region_paramd_items.find(&did.node); + match tcx.items.find(&did.node) { Some(ast_map::node_item(@ast::item { node: ast::item_impl(ref ts, _, st, _), _ @@ -1698,7 +1698,7 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, // Typecheck each field. for ast_fields.each |field| { - match class_field_map.find(field.node.ident) { + match class_field_map.find(&field.node.ident) { None => { tcx.sess.span_err( field.span, @@ -1734,7 +1734,7 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, let mut missing_fields = ~[]; for field_types.each |class_field| { let name = class_field.ident; - let (_, seen) = class_field_map.get(name); + let (_, seen) = class_field_map.get(&name); if !seen { missing_fields.push( ~"`" + tcx.sess.str_of(name) + ~"`"); @@ -1769,8 +1769,8 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, let type_parameter_count, region_parameterized, raw_type; if class_id.crate == ast::local_crate { region_parameterized = - tcx.region_paramd_items.find(class_id.node); - match tcx.items.find(class_id.node) { + tcx.region_paramd_items.find(&class_id.node); + match tcx.items.find(&class_id.node) { Some(ast_map::node_item(@ast::item { node: ast::item_struct(_, ref type_parameters), _ @@ -1852,8 +1852,8 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, let type_parameter_count, region_parameterized, raw_type; if enum_id.crate == ast::local_crate { region_parameterized = - tcx.region_paramd_items.find(enum_id.node); - match tcx.items.find(enum_id.node) { + tcx.region_paramd_items.find(&enum_id.node); + match tcx.items.find(&enum_id.node) { Some(ast_map::node_item(@ast::item { node: ast::item_enum(_, ref type_parameters), _ @@ -2435,7 +2435,7 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, } ast::expr_struct(path, ref fields, base_expr) => { // Resolve the path. - match tcx.def_map.find(id) { + match tcx.def_map.find(&id) { Some(ast::def_struct(type_def_id)) => { check_struct_constructor(fcx, id, expr.span, type_def_id, (/*bad*/copy *fields), base_expr); @@ -2532,7 +2532,7 @@ pub fn check_decl_local(fcx: @fn_ctxt, local: @ast::local) -> bool { } let region = - ty::re_scope(tcx.region_map.get(local.node.id)); + ty::re_scope(tcx.region_map.get(&local.node.id)); let pcx = pat_ctxt { fcx: fcx, map: pat_id_map(tcx.def_map, local.node.pat), @@ -2633,7 +2633,7 @@ pub fn check_const(ccx: @crate_ctxt, id: ast::node_id) { let rty = ty::node_id_to_type(ccx.tcx, id); let fcx = blank_fn_ctxt(ccx, rty, e.id); - let declty = fcx.ccx.tcx.tcache.get(local_def(id)).ty; + let declty = fcx.ccx.tcx.tcache.get(&local_def(id)).ty; check_const_with_ty(fcx, _sp, e, declty); } @@ -2984,7 +2984,7 @@ pub fn may_break(cx: ty::ctxt, id: ast::node_id, b: ast::blk) -> bool { (block_query(b, |e| { match e.node { ast::expr_break(Some(_)) => - match cx.def_map.find(e.id) { + match cx.def_map.find(&e.id) { Some(ast::def_label(loop_id)) if id == loop_id => true, _ => false, }, @@ -3080,8 +3080,8 @@ pub fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) { let ty_visitor_name = tcx.sess.ident_of(~"TyVisitor"); assert tcx.intrinsic_defs.contains_key_ref(&tydesc_name); assert ccx.tcx.intrinsic_defs.contains_key_ref(&ty_visitor_name); - let (_, tydesc_ty) = tcx.intrinsic_defs.get(tydesc_name); - let (_, visitor_trait) = tcx.intrinsic_defs.get(ty_visitor_name); + let (_, tydesc_ty) = tcx.intrinsic_defs.get(&tydesc_name); + let (_, visitor_trait) = tcx.intrinsic_defs.get(&ty_visitor_name); let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt {ty: tydesc_ty, mutbl: ast::m_imm}); (0u, ~[arg(ast::by_val, td_ptr), diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 9ae55d4556b..952c1a9fcd8 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -181,7 +181,7 @@ pub fn visit_block(b: ast::blk, &&rcx: @rcx, v: rvt) { pub fn visit_expr(expr: @ast::expr, &&rcx: @rcx, v: rvt) { debug!("visit_expr(e=%s)", rcx.fcx.expr_to_str(expr)); - for rcx.fcx.inh.adjustments.find(expr.id).each |adjustment| { + for rcx.fcx.inh.adjustments.find(&expr.id).each |adjustment| { for adjustment.autoref.each |autoref| { guarantor::for_autoref(rcx, expr, *adjustment, autoref); } @@ -327,7 +327,7 @@ pub fn constrain_auto_ref(rcx: @rcx, expr: @ast::expr) { debug!("constrain_auto_ref(expr=%s)", rcx.fcx.expr_to_str(expr)); - let adjustment = rcx.fcx.inh.adjustments.find(expr.id); + let adjustment = rcx.fcx.inh.adjustments.find(&expr.id); let region = match adjustment { Some(@ty::AutoAdjustment { autoref: Some(ref auto_ref), _ }) => { auto_ref.region @@ -725,7 +725,7 @@ pub mod guarantor { let mut expr_ct = categorize_unadjusted(rcx, expr); debug!("before adjustments, cat=%?", expr_ct.cat); - for rcx.fcx.inh.adjustments.find(expr.id).each |adjustment| { + for rcx.fcx.inh.adjustments.find(&expr.id).each |adjustment| { debug!("adjustment=%?", adjustment); expr_ct = apply_autoderefs( diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 18a4f20d031..9f2af3ec003 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -194,7 +194,7 @@ pub fn lookup_vtable(vcx: &VtableContext, match ty::get(ty).sty { ty::ty_param(param_ty {idx: n, def_id: did}) => { let mut n_bound = 0; - let bounds = tcx.ty_param_bounds.get(did.node); + let bounds = tcx.ty_param_bounds.get(&did.node); for ty::iter_bound_traits_and_supertraits( tcx, bounds) |ity| { debug!("checking bounds trait %?", @@ -255,7 +255,7 @@ pub fn lookup_vtable(vcx: &VtableContext, let mut impls_seen = HashMap(); - match vcx.ccx.coherence_info.extension_methods.find(trait_id) { + match vcx.ccx.coherence_info.extension_methods.find(&trait_id) { None => { // Nothing found. Continue. } @@ -525,7 +525,7 @@ pub fn early_resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, is_early: bool) { ast::expr_path(*) => { match fcx.opt_node_ty_substs(ex.id) { Some(ref substs) => { - let def = cx.tcx.def_map.get(ex.id); + let def = cx.tcx.def_map.get(&ex.id); let did = ast_util::def_id_of_def(def); let item_ty = ty::lookup_item_type(cx.tcx, did); debug!("early resolve expr: def %? %?, %?, %?", ex.id, did, def, diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 64ea45c8704..fab64c88b53 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -55,7 +55,7 @@ fn resolve_type_vars_in_type(fcx: @fn_ctxt, sp: span, typ: ty::t) fn resolve_method_map_entry(fcx: @fn_ctxt, sp: span, id: ast::node_id) { // Resolve any method map entry - match fcx.ccx.method_map.find(id) { + match fcx.ccx.method_map.find(&id) { None => {} Some(ref mme) => { for resolve_type_vars_in_type(fcx, sp, mme.self_arg.ty).each |t| { @@ -77,7 +77,7 @@ fn resolve_type_vars_for_node(wbcx: wb_ctxt, sp: span, id: ast::node_id) let fcx = wbcx.fcx, tcx = fcx.ccx.tcx; // Resolve any borrowings for the node with id `id` - match fcx.inh.adjustments.find(id) { + match fcx.inh.adjustments.find(&id) { None => (), Some(adj) => { let resolved_autoref = match adj.autoref { diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 5ad8fd4c820..324cdcc261f 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -236,7 +236,8 @@ pub impl CoherenceChecker { } fn check_implementation(item: @item, associated_traits: ~[@trait_ref]) { - let self_type = self.crate_context.tcx.tcache.get(local_def(item.id)); + let self_type = self.crate_context.tcx.tcache.get( + &local_def(item.id)); // If there are no traits, then this implementation must have a // base type. @@ -354,7 +355,7 @@ pub impl CoherenceChecker { }; let pmm = self.crate_context.tcx.provided_methods; - match pmm.find(local_def(impl_id)) { + match pmm.find(&local_def(impl_id)) { Some(mis) => { // If the trait already has an entry in the // provided_methods_map, we just need to add this @@ -382,7 +383,7 @@ pub impl CoherenceChecker { fn add_inherent_method(base_def_id: def_id, implementation: @Impl) { let implementation_list; match self.crate_context.coherence_info.inherent_methods - .find(base_def_id) { + .find(&base_def_id) { None => { implementation_list = @DVec(); self.crate_context.coherence_info.inherent_methods @@ -399,7 +400,7 @@ pub impl CoherenceChecker { fn add_trait_method(trait_id: def_id, implementation: @Impl) { let implementation_list; match self.crate_context.coherence_info.extension_methods - .find(trait_id) { + .find(&trait_id) { None => { implementation_list = @DVec(); self.crate_context.coherence_info.extension_methods @@ -462,7 +463,7 @@ pub impl CoherenceChecker { debug!("Adding impl %? of %? for %s", the_impl.did, trait_t, ty_to_str(self.crate_context.tcx, self_t)); - match self.crate_context.tcx.trait_impls.find(trait_t) { + match self.crate_context.tcx.trait_impls.find(&trait_t) { None => { let m = HashMap(); m.insert(self_t, the_impl); @@ -480,7 +481,7 @@ pub impl CoherenceChecker { let coherence_info = &self.crate_context.coherence_info; let extension_methods = &coherence_info.extension_methods; - match extension_methods.find(trait_def_id) { + match extension_methods.find(&trait_def_id) { Some(impls) => { for uint::range(0, impls.len()) |i| { f(impls[i]); @@ -612,7 +613,7 @@ pub impl CoherenceChecker { fn get_self_type_for_implementation(implementation: @Impl) -> ty_param_bounds_and_ty { - return self.crate_context.tcx.tcache.get(implementation.did); + return self.crate_context.tcx.tcache.get(&implementation.did); } // Privileged scope checking @@ -627,7 +628,7 @@ pub impl CoherenceChecker { item_impl(_, opt_trait, _, _) => { let mut ok = false; match self.base_type_def_ids.find( - local_def(item.id)) { + &local_def(item.id)) { None => { // Nothing to do. @@ -701,7 +702,7 @@ pub impl CoherenceChecker { fn trait_ref_to_trait_def_id(trait_ref: @trait_ref) -> def_id { let def_map = self.crate_context.tcx.def_map; - let trait_def = def_map.get(trait_ref.ref_id); + let trait_def = def_map.get(&trait_ref.ref_id); let trait_id = def_id_of_def(trait_def); return trait_id; } @@ -774,7 +775,7 @@ pub impl CoherenceChecker { match self.crate_context.tcx .provided_methods - .find(local_def(item.id)) { + .find(&local_def(item.id)) { None => { debug!("(creating impl) trait with node_id `%d` \ has no provided methods", trait_did.node); @@ -808,7 +809,7 @@ pub impl CoherenceChecker { fn span_of_impl(implementation: @Impl) -> span { assert implementation.did.crate == local_crate; - match self.crate_context.tcx.items.find(implementation.did.node) { + match self.crate_context.tcx.items.find(&implementation.did.node) { Some(node_item(item, _)) => { return item.span; } @@ -836,7 +837,7 @@ pub impl CoherenceChecker { // Make sure we don't visit the same implementation // multiple times. - match impls_seen.find(implementation.did) { + match impls_seen.find(&implementation.did) { None => { // Good. Continue. impls_seen.insert(implementation.did, ()); @@ -988,7 +989,7 @@ pub impl CoherenceChecker { let coherence_info = &self.crate_context.coherence_info; let tcx = self.crate_context.tcx; let drop_trait = tcx.lang_items.drop_trait(); - let impls_opt = coherence_info.extension_methods.find(drop_trait); + let impls_opt = coherence_info.extension_methods.find(&drop_trait); let impls; match impls_opt { @@ -1013,7 +1014,7 @@ pub impl CoherenceChecker { _ => { // Destructors only work on nominal types. if impl_info.did.crate == ast::local_crate { - match tcx.items.find(impl_info.did.node) { + match tcx.items.find(&impl_info.did.node) { Some(ast_map::node_item(@ref item, _)) => { tcx.sess.span_err((*item).span, ~"the Drop trait may only \ diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 32d92489188..b7b7899883b 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -130,7 +130,7 @@ pub impl @crate_ctxt: ast_conv { if id.crate != ast::local_crate { csearch::get_type(self.tcx, id) } else { - match self.tcx.items.find(id.node) { + match self.tcx.items.find(&id.node) { Some(ast_map::node_item(item, _)) => { ty_of_item(self, item) } @@ -290,8 +290,8 @@ pub fn ensure_trait_methods(ccx: @crate_ctxt, let tcx = ccx.tcx; - let region_paramd = tcx.region_paramd_items.find(id); - match tcx.items.get(id) { + let region_paramd = tcx.region_paramd_items.find(&id); + match tcx.items.get(&id) { ast_map::node_item(@ast::item { node: ast::item_trait(ref params, _, ref ms), _ @@ -521,7 +521,7 @@ pub fn check_methods_against_trait(ccx: @crate_ctxt, // trait ref. Otherwise, we will potentially overwrite the types of // the methods within the trait with bogus results. (See issue #3903.) - match tcx.items.find(did.node) { + match tcx.items.find(&did.node) { Some(ast_map::node_item(item, _)) => { let tpt = ty_of_item(ccx, item); ensure_trait_methods(ccx, did.node, tpt.ty); @@ -616,7 +616,7 @@ pub fn ensure_no_ty_param_bounds(ccx: @crate_ctxt, pub fn convert(ccx: @crate_ctxt, it: @ast::item) { let tcx = ccx.tcx; - let rp = tcx.region_paramd_items.find(it.id); + let rp = tcx.region_paramd_items.find(&it.id); debug!("convert: item %s with id %d rp %?", tcx.sess.str_of(it.ident), it.id, rp); match /*bad*/copy it.node { @@ -740,7 +740,7 @@ pub fn convert_struct(ccx: @crate_ctxt, arg { mode: ast::expl(ast::by_copy), ty: ccx.tcx.tcache.get - (local_def(field.node.id)).ty + (&local_def(field.node.id)).ty } }, output: selfty @@ -830,11 +830,11 @@ pub fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) let def_id = local_def(it.id); let tcx = ccx.tcx; - match tcx.tcache.find(def_id) { + match tcx.tcache.find(&def_id) { Some(tpt) => return tpt, _ => {} } - let rp = tcx.region_paramd_items.find(it.id); + let rp = tcx.region_paramd_items.find(&it.id); match /*bad*/copy it.node { ast::item_const(t, _) => { let typ = ccx.to_ty(empty_rscope, t); @@ -859,12 +859,12 @@ pub fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) return tpt; } ast::item_ty(t, tps) => { - match tcx.tcache.find(local_def(it.id)) { + match tcx.tcache.find(&local_def(it.id)) { Some(tpt) => return tpt, None => { } } - let rp = tcx.region_paramd_items.find(it.id); + let rp = tcx.region_paramd_items.find(&it.id); let tpt = { let ty = { let t0 = ccx.to_ty(type_rscope(rp), t); @@ -978,7 +978,7 @@ pub fn compute_bounds(ccx: @crate_ctxt, pub fn ty_param_bounds(ccx: @crate_ctxt, params: ~[ast::ty_param]) -> @~[ty::param_bounds] { @do params.map |param| { - match ccx.tcx.ty_param_bounds.find(param.id) { + match ccx.tcx.ty_param_bounds.find(¶m.id) { Some(bs) => bs, None => { let bounds = compute_bounds(ccx, param.bounds); diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index 1a8e25239b3..0d4e520122f 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -912,7 +912,7 @@ pub impl RegionVarBindings { -> cres { let vars = TwoRegions { a: a, b: b }; - match combines.find(vars) { + match combines.find(&vars) { Some(c) => Ok(re_infer(ReVar(c))), None => { let c = self.new_region_var(span); diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index d292f04caa4..742646618bd 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -225,7 +225,7 @@ pub fn write_substs_to_tcx(tcx: ty::ctxt, } pub fn lookup_def_tcx(tcx: ty::ctxt, sp: span, id: ast::node_id) -> ast::def { - match tcx.def_map.find(id) { + match tcx.def_map.find(&id) { Some(x) => x, _ => { tcx.sess.span_fatal(sp, ~"internal error looking up a definition") @@ -325,7 +325,7 @@ fn check_main_fn_ty(ccx: @crate_ctxt, let main_t = ty::node_id_to_type(tcx, main_id); match ty::get(main_t).sty { ty::ty_fn(ref fn_ty) => { - match tcx.items.find(main_id) { + match tcx.items.find(&main_id) { Some(ast_map::node_item(it,_)) => { match it.node { ast::item_fn(_, _, ref ps, _) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 2ed2d3ea5d7..9e70a6ab130 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -67,7 +67,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region) -> (~str, Option) { return match region { re_scope(node_id) => { - match cx.items.find(node_id) { + match cx.items.find(&node_id) { Some(ast_map::node_block(ref blk)) => { explain_span(cx, "block", (*blk).span) } @@ -105,7 +105,7 @@ pub fn explain_region_and_span(cx: ctxt, region: ty::Region) bound_region_to_str(cx, br)) }; - match cx.items.find(id) { + match cx.items.find(&id) { Some(ast_map::node_block(ref blk)) => { let (msg, opt_span) = explain_span(cx, "block", (*blk).span); (fmt!("%s %s", prefix, msg), opt_span) @@ -154,7 +154,7 @@ pub fn bound_region_to_str_adorned(cx: ctxt, prefix: &str, } pub fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str { - match cx.items.find(node_id) { + match cx.items.find(&node_id) { Some(ast_map::node_block(ref blk)) => { fmt!("", cx.sess.codemap.span_to_str((*blk).span)) diff --git a/src/librustdoc/attr_pass.rs b/src/librustdoc/attr_pass.rs index 0e70900520d..c595ebce65f 100644 --- a/src/librustdoc/attr_pass.rs +++ b/src/librustdoc/attr_pass.rs @@ -116,7 +116,7 @@ fn parse_item_attrs( id: doc::AstId, parse_attrs: fn~(a: ~[ast::attribute]) -> T) -> T { do astsrv::exec(srv) |move parse_attrs, ctxt| { - let attrs = match ctxt.ast_map.get(id) { + let attrs = match ctxt.ast_map.get(&id) { ast_map::node_item(item, _) => copy item.attrs, ast_map::node_foreign_item(item, _, _) => copy item.attrs, _ => die!(~"parse_item_attrs: not an item") @@ -170,7 +170,7 @@ fn fold_enum( let desc = { let variant = copy variant; do astsrv::exec(srv.clone()) |ctxt| { - match ctxt.ast_map.get(doc_id) { + match ctxt.ast_map.get(&doc_id) { ast_map::node_item(@ast::item { node: ast::item_enum(ref enum_definition, _), _ }, _) => { @@ -234,7 +234,7 @@ fn merge_method_attrs( // Create an assoc list from method name to attributes let attrs: ~[(~str, Option<~str>)] = do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(item_id) { + match ctxt.ast_map.get(&item_id) { ast_map::node_item(@ast::item { node: ast::item_trait(_, _, ref methods), _ }, _) => { diff --git a/src/librustdoc/prune_hidden_pass.rs b/src/librustdoc/prune_hidden_pass.rs index f039bb74583..97258d99ba4 100644 --- a/src/librustdoc/prune_hidden_pass.rs +++ b/src/librustdoc/prune_hidden_pass.rs @@ -56,7 +56,7 @@ fn is_hidden(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool { let id = doc.id; do astsrv::exec(srv) |ctxt| { - let attrs = match ctxt.ast_map.get(id) { + let attrs = match ctxt.ast_map.get(&id) { ast_map::node_item(item, _) => copy item.attrs, _ => ~[] }; diff --git a/src/librustdoc/prune_private_pass.rs b/src/librustdoc/prune_private_pass.rs index 4b47b71449a..1acb6092e2c 100644 --- a/src/librustdoc/prune_private_pass.rs +++ b/src/librustdoc/prune_private_pass.rs @@ -59,7 +59,7 @@ fn is_visible(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool { let id = doc.id; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(id) { + match ctxt.ast_map.get(&id) { ast_map::node_item(item, _) => { item.vis == ast::public } diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index 4ab40530cfb..58a2e0e1324 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -68,7 +68,7 @@ fn fold_fn( fn get_fn_sig(srv: astsrv::Srv, fn_id: doc::AstId) -> Option<~str> { do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(fn_id) { + match ctxt.ast_map.get(&fn_id) { ast_map::node_item(@ast::item { ident: ident, node: ast::item_fn(ref decl, _, ref tys, _), _ @@ -107,7 +107,7 @@ fn fold_const( sig: Some({ let doc = copy doc; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(doc.id()) { + match ctxt.ast_map.get(&doc.id()) { ast_map::node_item(@ast::item { node: ast::item_const(ty, _), _ }, _) => { @@ -138,7 +138,7 @@ fn fold_enum( let sig = { let variant = copy *variant; do astsrv::exec(srv.clone()) |copy variant, ctxt| { - match ctxt.ast_map.get(doc_id) { + match ctxt.ast_map.get(&doc_id) { ast_map::node_item(@ast::item { node: ast::item_enum(ref enum_definition, _), _ }, _) => { @@ -199,7 +199,7 @@ fn get_method_sig( method_name: ~str ) -> Option<~str> { do astsrv::exec(srv) |copy method_name, ctxt| { - match ctxt.ast_map.get(item_id) { + match ctxt.ast_map.get(&item_id) { ast_map::node_item(@ast::item { node: ast::item_trait(_, _, ref methods), _ }, _) => { @@ -271,7 +271,7 @@ fn fold_impl( let (trait_types, self_ty) = { let doc = copy doc; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(doc.id()) { + match ctxt.ast_map.get(&doc.id()) { ast_map::node_item(@ast::item { node: ast::item_impl(_, opt_trait_type, self_ty, _), _ }, _) => { @@ -331,7 +331,7 @@ fn fold_type( sig: { let doc = copy doc; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(doc.id()) { + match ctxt.ast_map.get(&doc.id()) { ast_map::node_item(@ast::item { ident: ident, node: ast::item_ty(ty, ref params), _ @@ -369,7 +369,7 @@ fn fold_struct( sig: { let doc = copy doc; do astsrv::exec(srv) |ctxt| { - match ctxt.ast_map.get(doc.id()) { + match ctxt.ast_map.get(&doc.id()) { ast_map::node_item(item, _) => { let item = strip_struct_extra_stuff(item); Some(pprust::item_to_str(item, diff --git a/src/libstd/oldmap.rs b/src/libstd/oldmap.rs index a4d4a4e806b..18cfc8d4a2d 100644 --- a/src/libstd/oldmap.rs +++ b/src/libstd/oldmap.rs @@ -226,9 +226,9 @@ pub mod chained { } } - pure fn find(&self, k: K) -> Option { + pure fn find(&self, k: &K) -> Option { unsafe { - match self.search_tbl(&k, k.hash_keyed(0,0) as uint) { + match self.search_tbl(k, k.hash_keyed(0,0) as uint) { NotFound => None, FoundFirst(_, entry) => Some(entry.value), FoundAfter(_, entry) => Some(entry.value) @@ -291,7 +291,7 @@ pub mod chained { return self.update_with_key(key, newval, |_k, v, v1| ff(v,v1)); } - pure fn get(&self, k: K) -> V { + pure fn get(&self, k: &K) -> V { let opt_v = self.find(k); if opt_v.is_none() { die!(fmt!("Key not found in table: %?", k)); @@ -364,7 +364,7 @@ pub mod chained { impl T: ops::Index { pure fn index(&self, k: K) -> V { unsafe { - self.get(k) + self.get(&k) } } } @@ -421,7 +421,6 @@ pub fn hash_from_vec( #[cfg(test)] mod tests { use core::option::None; - use core::option; use core::uint; use super::*; @@ -437,13 +436,13 @@ mod tests { assert (hm_uu.insert(10u, 12u)); assert (hm_uu.insert(11u, 13u)); assert (hm_uu.insert(12u, 14u)); - assert (hm_uu.get(11u) == 13u); - assert (hm_uu.get(12u) == 14u); - assert (hm_uu.get(10u) == 12u); + assert (hm_uu.get(&11) == 13u); + assert (hm_uu.get(&12) == 14u); + assert (hm_uu.get(&10) == 12u); assert (!hm_uu.insert(12u, 14u)); - assert (hm_uu.get(12u) == 14u); + assert (hm_uu.get(&12) == 14u); assert (!hm_uu.insert(12u, 12u)); - assert (hm_uu.get(12u) == 12u); + assert (hm_uu.get(&12) == 12u); let ten: ~str = ~"ten"; let eleven: ~str = ~"eleven"; let twelve: ~str = ~"twelve"; @@ -453,40 +452,40 @@ mod tests { assert (hm_su.insert(~"ten", 12u)); assert (hm_su.insert(eleven, 13u)); assert (hm_su.insert(~"twelve", 14u)); - assert (hm_su.get(eleven) == 13u); - assert (hm_su.get(~"eleven") == 13u); - assert (hm_su.get(~"twelve") == 14u); - assert (hm_su.get(~"ten") == 12u); + assert (hm_su.get(&eleven) == 13u); + assert (hm_su.get(&~"eleven") == 13u); + assert (hm_su.get(&~"twelve") == 14u); + assert (hm_su.get(&~"ten") == 12u); assert (!hm_su.insert(~"twelve", 14u)); - assert (hm_su.get(~"twelve") == 14u); + assert (hm_su.get(&~"twelve") == 14u); assert (!hm_su.insert(~"twelve", 12u)); - assert (hm_su.get(~"twelve") == 12u); + assert (hm_su.get(&~"twelve") == 12u); debug!("uint -> str"); let hm_us: HashMap = HashMap::(); assert (hm_us.insert(10u, ~"twelve")); assert (hm_us.insert(11u, ~"thirteen")); assert (hm_us.insert(12u, ~"fourteen")); - assert hm_us.get(11u) == ~"thirteen"; - assert hm_us.get(12u) == ~"fourteen"; - assert hm_us.get(10u) == ~"twelve"; + assert hm_us.get(&11) == ~"thirteen"; + assert hm_us.get(&12) == ~"fourteen"; + assert hm_us.get(&10) == ~"twelve"; assert (!hm_us.insert(12u, ~"fourteen")); - assert hm_us.get(12u) == ~"fourteen"; + assert hm_us.get(&12) == ~"fourteen"; assert (!hm_us.insert(12u, ~"twelve")); - assert hm_us.get(12u) == ~"twelve"; + assert hm_us.get(&12) == ~"twelve"; debug!("str -> str"); let hm_ss: HashMap<~str, ~str> = HashMap::<~str, ~str>(); assert (hm_ss.insert(ten, ~"twelve")); assert (hm_ss.insert(eleven, ~"thirteen")); assert (hm_ss.insert(twelve, ~"fourteen")); - assert hm_ss.get(~"eleven") == ~"thirteen"; - assert hm_ss.get(~"twelve") == ~"fourteen"; - assert hm_ss.get(~"ten") == ~"twelve"; + assert hm_ss.get(&~"eleven") == ~"thirteen"; + assert hm_ss.get(&~"twelve") == ~"fourteen"; + assert hm_ss.get(&~"ten") == ~"twelve"; assert (!hm_ss.insert(~"twelve", ~"fourteen")); - assert hm_ss.get(~"twelve") == ~"fourteen"; + assert hm_ss.get(&~"twelve") == ~"fourteen"; assert (!hm_ss.insert(~"twelve", ~"twelve")); - assert hm_ss.get(~"twelve") == ~"twelve"; + assert hm_ss.get(&~"twelve") == ~"twelve"; debug!("*** finished test_simple"); } @@ -512,17 +511,17 @@ mod tests { debug!("-----"); i = 0u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm_uu.get(i)); - assert (hm_uu.get(i) == i * i); + debug!("get(%u) = %u", i, hm_uu.get(&i)); + assert (hm_uu.get(&i) == i * i); i += 1u; } assert (hm_uu.insert(num_to_insert, 17u)); - assert (hm_uu.get(num_to_insert) == 17u); + assert (hm_uu.get(&num_to_insert) == 17u); debug!("-----"); i = 0u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm_uu.get(i)); - assert (hm_uu.get(i) == i * i); + debug!("get(%u) = %u", i, hm_uu.get(&i)); + assert (hm_uu.get(&i) == i * i); i += 1u; } debug!("str -> str"); @@ -542,22 +541,22 @@ mod tests { while i < num_to_insert { debug!("get(\"%s\") = \"%s\"", uint::to_str_radix(i, 2u), - hm_ss.get(uint::to_str_radix(i, 2u))); - assert hm_ss.get(uint::to_str_radix(i, 2u)) == + hm_ss.get(&uint::to_str_radix(i, 2u))); + assert hm_ss.get(&uint::to_str_radix(i, 2u)) == uint::to_str_radix(i * i, 2u); i += 1u; } assert (hm_ss.insert(uint::to_str_radix(num_to_insert, 2u), uint::to_str_radix(17u, 2u))); - assert hm_ss.get(uint::to_str_radix(num_to_insert, 2u)) == + assert hm_ss.get(&uint::to_str_radix(num_to_insert, 2u)) == uint::to_str_radix(17u, 2u); debug!("-----"); i = 0u; while i < num_to_insert { debug!("get(\"%s\") = \"%s\"", uint::to_str_radix(i, 2u), - hm_ss.get(uint::to_str_radix(i, 2u))); - assert hm_ss.get(uint::to_str_radix(i, 2u)) == + hm_ss.get(&uint::to_str_radix(i, 2u))); + assert hm_ss.get(&uint::to_str_radix(i, 2u)) == uint::to_str_radix(i * i, 2u); i += 1u; } @@ -589,15 +588,15 @@ mod tests { debug!("-----"); i = 1u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm.get(i)); - assert (hm.get(i) == i * i); + debug!("get(%u) = %u", i, hm.get(&i)); + assert (hm.get(&i) == i * i); i += 2u; } debug!("-----"); i = 1u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm.get(i)); - assert (hm.get(i) == i * i); + debug!("get(%u) = %u", i, hm.get(&i)); + assert (hm.get(&i) == i * i); i += 2u; } debug!("-----"); @@ -611,16 +610,16 @@ mod tests { debug!("-----"); i = 0u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm.get(i)); - assert (hm.get(i) == i * i); + debug!("get(%u) = %u", i, hm.get(&i)); + assert (hm.get(&i) == i * i); i += 1u; } debug!("-----"); assert (hm.len() == num_to_insert); i = 0u; while i < num_to_insert { - debug!("get(%u) = %u", i, hm.get(i)); - assert (hm.get(i) == i * i); + debug!("get(%u) = %u", i, hm.get(&i)); + assert (hm.get(&i) == i * i); i += 1u; } debug!("*** finished test_removal"); @@ -639,9 +638,9 @@ mod tests { fn test_find() { let key = ~"k"; let map = HashMap::<~str, ~str>(); - assert (option::is_none(&map.find(key))); + assert map.find(&key).is_none(); map.insert(key, ~"val"); - assert (option::get(map.find(key)) == ~"val"); + assert map.find(&key).get() == ~"val"; } #[test] @@ -664,9 +663,9 @@ mod tests { (~"c", 3) ]); assert map.len() == 3u; - assert map.get(~"a") == 1; - assert map.get(~"b") == 2; - assert map.get(~"c") == 3; + assert map.get(&~"a") == 1; + assert map.get(&~"b") == 2; + assert map.get(&~"c") == 3; } #[test] @@ -692,11 +691,11 @@ mod tests { map.update_with_key(~"cat", 2, addMoreToCount); // check the total counts - assert 10 == option::get(map.find(~"cat")); - assert 3 == option::get(map.find(~"ferret")); - assert 1 == option::get(map.find(~"mongoose")); + assert map.find(&~"cat").get() == 10; + assert map.find(&~"ferret").get() == 3; + assert map.find(&~"mongoose").get() == 1; // sadly, no mythical animals were counted! - assert None == map.find(~"unicorn"); + assert map.find(&~"unicorn").is_none(); } } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index e6a4639ad80..fe41cee919f 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -333,7 +333,7 @@ pub fn map_stmt(stmt: @stmt, cx: ctx, v: vt) { } pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { - match map.find(id) { + match map.find(&id) { None => { fmt!("unknown node (id=%d)", id) } @@ -398,7 +398,7 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { pub fn node_item_query(items: map, id: node_id, query: fn(@item) -> Result, error_msg: ~str) -> Result { - match items.find(id) { + match items.find(&id) { Some(node_item(it, _)) => query(it), _ => die!(error_msg) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 227a86e0766..18256369c78 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -40,7 +40,7 @@ pub fn expand_expr(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt, /* using idents and token::special_idents would make the the macro names be hygienic */ let extname = cx.parse_sess().interner.get(pth.idents[0]); - match exts.find(*extname) { + match exts.find(extname) { None => { cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)) @@ -104,7 +104,7 @@ pub fn expand_mod_items(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt, ast::meta_name_value(ref n, _) => (*n), ast::meta_list(ref n, _) => (*n) }; - match exts.find(mname) { + match exts.find(&mname) { None | Some(NormalTT(_)) | Some(ItemTT(*)) => items, Some(ItemDecorator(dec_fn)) => { cx.bt_push(ExpandedFrom({call_site: attr.span, @@ -161,7 +161,7 @@ pub fn expand_item_mac(exts: HashMap<~str, SyntaxExtension>, }; let extname = cx.parse_sess().interner.get(pth.idents[0]); - let expanded = match exts.find(*extname) { + let expanded = match exts.find(extname) { None => cx.span_fatal(pth.span, fmt!("macro undefined: '%s!'", *extname)), @@ -224,7 +224,7 @@ pub fn expand_stmt(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt, assert(vec::len(pth.idents) == 1u); let extname = cx.parse_sess().interner.get(pth.idents[0]); - let (fully_expanded, sp) = match exts.find(*extname) { + let (fully_expanded, sp) = match exts.find(extname) { None => cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)), diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 31172cbfa85..3e7a84240e4 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -59,11 +59,11 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, arg_reader as reader, argument_gram); // Extract the arguments: - let lhses:~[@named_match] = match argument_map.get(lhs_nm) { + let lhses:~[@named_match] = match argument_map.get(&lhs_nm) { @matched_seq(s, _) => s, _ => cx.span_bug(sp, ~"wrong-structured lhs") }; - let rhses:~[@named_match] = match argument_map.get(rhs_nm) { + let rhses:~[@named_match] = match argument_map.get(&rhs_nm) { @matched_seq(s, _) => s, _ => cx.span_bug(sp, ~"wrong-structured rhs") }; diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 6bf90617a6e..6f57ca38f1f 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -111,7 +111,7 @@ pure fn lookup_cur_matched_by_matched(r: tt_reader, } fn lookup_cur_matched(r: tt_reader, name: ident) -> @named_match { - lookup_cur_matched_by_matched(r, r.interpolations.get(name)) + lookup_cur_matched_by_matched(r, r.interpolations.get(&name)) } enum lis { lis_unconstrained, lis_constraint(uint, ident), lis_contradiction(~str) diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 19b938ccd68..905571d1817 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -44,7 +44,7 @@ pub trait Interner { pub impl hash_interner: Interner { fn intern(val: T) -> uint { - match self.map.find(val) { + match self.map.find(&val) { Some(idx) => return idx, None => { let new_idx = self.vect.len(); diff --git a/src/test/auxiliary/issue-2631-a.rs b/src/test/auxiliary/issue-2631-a.rs index 748c209229c..8679d3a7786 100644 --- a/src/test/auxiliary/issue-2631-a.rs +++ b/src/test/auxiliary/issue-2631-a.rs @@ -20,5 +20,5 @@ pub type header_map = HashMap<~str, @DVec<@~str>>; // the unused ty param is necessary so this gets monomorphized pub fn request(req: header_map) { - let _x = copy *(copy *req.get(~"METHOD"))[0u]; + let _x = copy *(copy *req.get(&~"METHOD"))[0u]; } diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index 67c071da26d..68ba40749f2 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -42,7 +42,7 @@ fn old_int_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { } for uint::range(0, num_keys) |i| { - assert map.get(i) == i+1; + assert map.get(&i) == i+1; } } } @@ -81,7 +81,7 @@ fn old_str_benchmarks(rng: @rand::Rng, num_keys: uint, results: &mut Results) { for uint::range(0, num_keys) |i| { let s = uint::to_str(i); - assert map.get(s) == i; + assert map.get(&s) == i; } } } diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index 32b6c491898..fafda39993e 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -83,7 +83,7 @@ fn str_set() { let mut found = 0; for int::range(0, 1000) |_i| { - match s.find(r.gen_str(10)) { + match s.find(&r.gen_str(10)) { Some(_) => { found += 1; } None => { } } diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 0f4f22196ce..811f39e4343 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -69,7 +69,7 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str { // given a map, search for the frequency of a pattern fn find(mm: HashMap<~[u8], uint>, key: ~str) -> uint { - match mm.find(str::to_bytes(str::to_lower(key))) { + match mm.find(&str::to_bytes(str::to_lower(key))) { option::None => { return 0u; } option::Some(num) => { return num; } } diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 8cf57b19825..5888dab3bb9 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -136,7 +136,7 @@ fn writer(path: ~str, pport: pipes::Port, size: uint) while prev <= i { if lines.contains_key_ref(&prev) { debug!("WS %u", prev); - cout.write(lines.get(prev)); + cout.write(lines.get(&prev)); done += 1_u; lines.remove(&prev); prev += 1_u; diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 43e2bee644a..d7a285d58e6 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -49,7 +49,7 @@ mod map_reduce { fn emit(im: oldmap::HashMap<~str, int>, ctrl: SharedChan, key: ~str, val: ~str) { let mut c; - match im.find(copy key) { + match im.find(&key) { Some(_c) => { c = _c } None => { let (pp, cc) = stream(); @@ -88,7 +88,7 @@ mod map_reduce { mapper_done => { num_mappers -= 1; } find_reducer(k, cc) => { let mut c; - match reducers.find(str::from_bytes(k)) { + match reducers.find(&str::from_bytes(k)) { Some(_c) => { c = _c; } None => { c = 0; } } From 01cc9ecafeb235ad3c12aa2222c3911b2b450052 Mon Sep 17 00:00:00 2001 From: Kang Seonghoon Date: Wed, 6 Feb 2013 16:49:24 +0900 Subject: [PATCH 23/37] libsyntax: no binary/hex float literals --- src/libsyntax/parse/lexer.rs | 7 +++++++ .../compile-fail/no-binary-float-literal.rs | 18 ++++++++++++++++++ src/test/compile-fail/no-hex-float-literal.rs | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 src/test/compile-fail/no-binary-float-literal.rs create mode 100644 src/test/compile-fail/no-hex-float-literal.rs diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 381183e736c..0f672d1de81 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -431,6 +431,13 @@ fn scan_number(c: char, rdr: string_reader) -> token::Token { let dec_part = scan_digits(rdr, 10u); num_str += ~"." + dec_part; } + if is_float { + match base { + 16u => rdr.fatal(~"hexadecimal float literal is not supported"), + 2u => rdr.fatal(~"binary float literal is not supported"), + _ => () + } + } match scan_exponent(rdr) { Some(ref s) => { is_float = true; diff --git a/src/test/compile-fail/no-binary-float-literal.rs b/src/test/compile-fail/no-binary-float-literal.rs new file mode 100644 index 00000000000..58afd5ba349 --- /dev/null +++ b/src/test/compile-fail/no-binary-float-literal.rs @@ -0,0 +1,18 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern:binary float literal is not supported + +fn main() { + 0b101010f; + 0b101.010; + 0b101p4f; +} + diff --git a/src/test/compile-fail/no-hex-float-literal.rs b/src/test/compile-fail/no-hex-float-literal.rs new file mode 100644 index 00000000000..3bc52e029d7 --- /dev/null +++ b/src/test/compile-fail/no-hex-float-literal.rs @@ -0,0 +1,18 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern:hexadecimal float literal is not supported + +fn main() { + 0xABC.Df; + 0x567.89; + 0xDEAD.BEEFp-2f; +} + From 2600bcc05dcd51a5f6fe3404c60a5c1891a22dfe Mon Sep 17 00:00:00 2001 From: Kang Seonghoon Date: Wed, 6 Feb 2013 17:43:14 +0900 Subject: [PATCH 24/37] got rid of last empty lines --- src/test/compile-fail/no-binary-float-literal.rs | 1 - src/test/compile-fail/no-hex-float-literal.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/test/compile-fail/no-binary-float-literal.rs b/src/test/compile-fail/no-binary-float-literal.rs index 58afd5ba349..0fa61b1af52 100644 --- a/src/test/compile-fail/no-binary-float-literal.rs +++ b/src/test/compile-fail/no-binary-float-literal.rs @@ -15,4 +15,3 @@ fn main() { 0b101.010; 0b101p4f; } - diff --git a/src/test/compile-fail/no-hex-float-literal.rs b/src/test/compile-fail/no-hex-float-literal.rs index 3bc52e029d7..4abb6093b24 100644 --- a/src/test/compile-fail/no-hex-float-literal.rs +++ b/src/test/compile-fail/no-hex-float-literal.rs @@ -15,4 +15,3 @@ fn main() { 0x567.89; 0xDEAD.BEEFp-2f; } - From 48df2f4aafec32f75141d57a99982643ce04ec85 Mon Sep 17 00:00:00 2001 From: kud1ing Date: Wed, 6 Feb 2013 10:14:50 +0100 Subject: [PATCH 25/37] `core::send_map` renamed to `core::hashmap` Encountered this while trying to port rustsqlite to rust 0.6 --- RELEASES.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/RELEASES.txt b/RELEASES.txt index b3b81964d85..64120f66351 100644 --- a/RELEASES.txt +++ b/RELEASES.txt @@ -1,3 +1,9 @@ +Version 0.6 (?) +--------------------------- + + * Libraries + * `core::send_map` renamed to `core::hashmap` + Version 0.5 (December 2012) --------------------------- From 739e5ba369cfe19da10d7adf1bcfcd14b80f52bb Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 4 Feb 2013 15:30:32 -0800 Subject: [PATCH 26/37] rustc: Less copy --- src/librustc/middle/trans/base.rs | 26 +++++++++++++------------- src/librustc/middle/trans/common.rs | 4 +++- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index a2b1de692be..34a68c1468c 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -137,7 +137,7 @@ pub fn log_fn_time(ccx: @crate_ctxt, +name: ~str, start: time::Timespec, ccx.stats.fn_times.push({ident: name, time: elapsed}); } -pub fn decl_fn(llmod: ModuleRef, name: ~str, cc: lib::llvm::CallConv, +pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv, llty: TypeRef) -> ValueRef { let llfn: ValueRef = str::as_c_str(name, |buf| { unsafe { @@ -150,7 +150,7 @@ pub fn decl_fn(llmod: ModuleRef, name: ~str, cc: lib::llvm::CallConv, return llfn; } -pub fn decl_cdecl_fn(llmod: ModuleRef, +name: ~str, llty: TypeRef) +pub fn decl_cdecl_fn(llmod: ModuleRef, name: &str, llty: TypeRef) -> ValueRef { return decl_fn(llmod, name, lib::llvm::CCallConv, llty); } @@ -164,20 +164,19 @@ pub fn decl_internal_cdecl_fn(llmod: ModuleRef, +name: ~str, llty: TypeRef) -> return llfn; } -pub fn get_extern_fn(externs: HashMap<~str, ValueRef>, +pub fn get_extern_fn(externs: ExternMap, llmod: ModuleRef, - +name: ~str, + name: @str, cc: lib::llvm::CallConv, ty: TypeRef) -> ValueRef { if externs.contains_key_ref(&name) { return externs.get(&name); } - // XXX: Bad copy. - let f = decl_fn(llmod, copy name, cc, ty); + let f = decl_fn(llmod, name, cc, ty); externs.insert(name, f); return f; } -pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef, - +name: ~str, ty: TypeRef) -> ValueRef { +pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef, + name: @str, ty: TypeRef) -> ValueRef { unsafe { if externs.contains_key_ref(&name) { return externs.get(&name); } let c = str::as_c_str(name, |buf| { @@ -189,9 +188,9 @@ pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef, } fn get_simple_extern_fn(cx: block, - externs: HashMap<~str, ValueRef>, + externs: ExternMap, llmod: ModuleRef, - +name: ~str, + name: @str, n_args: int) -> ValueRef { let _icx = cx.insn_ctxt("get_simple_extern_fn"); let ccx = cx.fcx.ccx; @@ -201,8 +200,8 @@ pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef, return get_extern_fn(externs, llmod, name, lib::llvm::CCallConv, t); } -pub fn trans_foreign_call(cx: block, externs: HashMap<~str, ValueRef>, - llmod: ModuleRef, +name: ~str, args: ~[ValueRef]) -> +pub fn trans_foreign_call(cx: block, externs: ExternMap, + llmod: ModuleRef, name: @str, args: ~[ValueRef]) -> ValueRef { let _icx = cx.insn_ctxt("trans_foreign_call"); let n = args.len() as int; @@ -474,6 +473,7 @@ pub fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id, let class_ty = ty::subst_tps(tcx, substs, None, ty::lookup_item_type(tcx, parent_id).ty); let llty = type_of_dtor(ccx, class_ty); + let name = name.to_managed(); // :-( get_extern_fn(ccx.externs, ccx.llmod, name, lib::llvm::CCallConv, llty) } @@ -766,7 +766,7 @@ pub fn null_env_ptr(bcx: block) -> ValueRef { pub fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t) -> ValueRef { - let name = csearch::get_symbol(ccx.sess.cstore, did); + let name = csearch::get_symbol(ccx.sess.cstore, did).to_managed(); // Sad match ty::get(t).sty { ty::ty_fn(_) => { let llty = type_of_fn_from_ty(ccx, t); diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 0613319e4af..995d78a02e8 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -152,13 +152,15 @@ pub fn BuilderRef_res(B: BuilderRef) -> BuilderRef_res { } } +type ExternMap = HashMap<@str, ValueRef>; + // Crate context. Every crate we compile has one of these. pub struct crate_ctxt { sess: session::Session, llmod: ModuleRef, td: target_data, tn: type_names, - externs: HashMap<~str, ValueRef>, + externs: ExternMap, intrinsics: HashMap<~str, ValueRef>, item_vals: HashMap, exp_map2: resolve::ExportMap2, From b34f871ddac7bc84366b25c89d0a69926cb069e0 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 6 Feb 2013 14:28:02 -0800 Subject: [PATCH 27/37] librustc: Change i1 to i8 for bools. Attempts to put out burning tree. rs=burningtree --- src/librustc/middle/trans/_match.rs | 15 +++++++++-- src/librustc/middle/trans/base.rs | 25 ++++++++++++------ src/librustc/middle/trans/callee.rs | 7 ++++-- src/librustc/middle/trans/common.rs | 11 +++++++- src/librustc/middle/trans/controlflow.rs | 4 +++ src/librustc/middle/trans/debuginfo.rs | 2 +- src/librustc/middle/trans/expr.rs | 32 +++++++++++++++++------- src/librustc/middle/trans/foreign.rs | 23 +++++++++-------- src/librustc/middle/trans/reflect.rs | 1 + 9 files changed, 86 insertions(+), 34 deletions(-) diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 7dca4174019..99b5641ac6a 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -1028,6 +1028,8 @@ pub fn pick_col(m: &[@Match]) -> uint { pub enum branch_kind { no_branch, single, switch, compare, compare_vec_len, } // Compiles a comparison between two things. +// +// NB: This must produce an i1, not a Rust bool (i8). pub fn compare_values(cx: block, lhs: ValueRef, rhs: ValueRef, @@ -1053,7 +1055,11 @@ pub fn compare_values(cx: block, scratch_rhs], expr::SaveIn( scratch_result.val)); - return scratch_result.to_result(bcx); + let result = scratch_result.to_result(bcx); + Result { + bcx: result.bcx, + val: bool_to_i1(result.bcx, result.val) + } } ty::ty_estr(_) => { let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()), @@ -1063,7 +1069,11 @@ pub fn compare_values(cx: block, ~[lhs, rhs], expr::SaveIn( scratch_result.val)); - return scratch_result.to_result(bcx); + let result = scratch_result.to_result(bcx); + Result { + bcx: result.bcx, + val: bool_to_i1(result.bcx, result.val) + } } _ => { cx.tcx().sess.bug(~"only scalars and strings supported in \ @@ -1176,6 +1186,7 @@ pub fn compile_guard(bcx: block, expr::trans_to_datum(bcx, guard_expr).to_result() } }); + let val = bool_to_i1(bcx, val); // Revoke the temp cleanups now that the guard successfully executed. for temp_cleanups.each |llval| { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index a2b1de692be..b48eb088c50 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -494,8 +494,13 @@ pub fn maybe_name_value(cx: @crate_ctxt, v: ValueRef, s: ~str) { // Used only for creating scalar comparison glue. pub enum scalar_type { nil_type, signed_int, unsigned_int, floating_point, } -pub fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef, - t: ty::t, op: ast::binop) -> Result { +// NB: This produces an i1, not a Rust bool (i8). +pub fn compare_scalar_types(cx: block, + lhs: ValueRef, + rhs: ValueRef, + t: ty::t, + op: ast::binop) + -> Result { let f = |a| compare_scalar_values(cx, lhs, rhs, a, op); match ty::get(t).sty { @@ -521,8 +526,12 @@ pub fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef, // A helper function to do the actual comparison of scalar values. -pub fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef, - nt: scalar_type, op: ast::binop) -> ValueRef { +pub fn compare_scalar_values(cx: block, + lhs: ValueRef, + rhs: ValueRef, + nt: scalar_type, + op: ast::binop) + -> ValueRef { let _icx = cx.insn_ctxt("compare_scalar_values"); fn die(cx: block) -> ! { cx.tcx().sess.bug(~"compare_scalar_values: must be a\ @@ -533,8 +542,8 @@ pub fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef, // We don't need to do actual comparisons for nil. // () == () holds but () < () does not. match op { - ast::eq | ast::le | ast::ge => return C_bool(true), - ast::ne | ast::lt | ast::gt => return C_bool(false), + ast::eq | ast::le | ast::ge => return C_i1(true), + ast::ne | ast::lt | ast::gt => return C_i1(false), // refinements would be nice _ => die(cx) } @@ -1442,7 +1451,7 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef, let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8())); let size = IntCast(cx, n_bytes, ccx.int_type); let align = C_i32(1i32); - let volatile = C_bool(false); + let volatile = C_i1(false); Call(cx, memcpy, ~[dst_ptr, src_ptr, size, align, volatile]); } @@ -1489,7 +1498,7 @@ pub fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) { let llzeroval = C_u8(0); let size = IntCast(cx, machine::llsize_of(ccx, llty), ccx.int_type); let align = C_i32(1i32); - let volatile = C_bool(false); + let volatile = C_i1(false); Call(cx, llintrinsicfn, ~[llptr, llzeroval, size, align, volatile]); } diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 8cfe8ba8f91..4bd5ae969f2 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -438,7 +438,9 @@ pub fn trans_call_inner( let flag = alloca(bcx, T_bool()); Store(bcx, C_bool(false), flag); Some(flag) - } else { None }; + } else { + None + }; let (llfn, llenv) = unsafe { match callee.data { @@ -506,7 +508,8 @@ pub fn trans_call_inner( if ty::type_is_bot(ret_ty) { Unreachable(bcx); } else if ret_in_loop { - bcx = do with_cond(bcx, Load(bcx, ret_flag.get())) |bcx| { + let ret_flag_result = bool_to_i1(bcx, Load(bcx, ret_flag.get())); + bcx = do with_cond(bcx, ret_flag_result) |bcx| { do option::iter(© bcx.fcx.loop_ret) |lret| { Store(bcx, C_bool(true), lret.flagptr); Store(bcx, C_bool(false), bcx.fcx.llretptr); diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 0613319e4af..837ca8ca3aa 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -759,7 +759,7 @@ pub fn T_f32() -> TypeRef { unsafe { return llvm::LLVMFloatType(); } } pub fn T_f64() -> TypeRef { unsafe { return llvm::LLVMDoubleType(); } } -pub fn T_bool() -> TypeRef { return T_i1(); } +pub fn T_bool() -> TypeRef { return T_i8(); } pub fn T_int(targ_cfg: @session::config) -> TypeRef { return match targ_cfg.arch { @@ -1109,6 +1109,10 @@ pub fn C_bool(b: bool) -> ValueRef { C_integral(T_bool(), if b { 1u64 } else { 0u64 }, False) } +pub fn C_i1(b: bool) -> ValueRef { + return C_integral(T_i1(), if b { 1 } else { 0 }, False); +} + pub fn C_i32(i: i32) -> ValueRef { return C_integral(T_i32(), i as u64, True); } @@ -1435,6 +1439,11 @@ pub fn struct_dtor() -> [uint * 2] { [0, 1] } +// Casts a Rust bool value to an i1. +pub fn bool_to_i1(bcx: block, llval: ValueRef) -> ValueRef { + build::ICmp(bcx, lib::llvm::IntNE, llval, C_bool(false)) +} + // // Local Variables: // mode: rust diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index 8944fceb011..a1505dd2f11 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -62,6 +62,8 @@ pub fn trans_if(bcx: block, let then_bcx_in = scope_block(bcx, thn.info(), ~"then"); let else_bcx_in = scope_block(bcx, els.info(), ~"else"); + + let cond_val = bool_to_i1(bcx, cond_val); CondBr(bcx, cond_val, then_bcx_in.llbb, else_bcx_in.llbb); debug!("then_bcx_in=%s, else_bcx_in=%s", @@ -139,6 +141,7 @@ pub fn trans_while(bcx: block, cond: @ast::expr, body: ast::blk) -> block { // compile the condition let Result {bcx: cond_bcx_out, val: cond_val} = expr::trans_to_datum(cond_bcx_in, cond).to_result(); + let cond_val = bool_to_i1(cond_bcx_out, cond_val); let cond_bcx_out = trans_block_cleanups(cond_bcx_out, block_cleanups(cond_bcx_in)); CondBr(cond_bcx_out, cond_val, body_bcx_in.llbb, next_bcx.llbb); @@ -324,6 +327,7 @@ pub fn trans_check_expr(bcx: block, expr::trans_to_datum(bcx, pred_expr).to_result() } }; + let val = bool_to_i1(bcx, val); do with_cond(bcx, Not(bcx, val)) |bcx| { trans_fail(bcx, Some(pred_expr.span), /*bad*/copy expr_str) } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index ecb63c19811..ff842b5b4be 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -77,7 +77,7 @@ fn lli64(val: int) -> ValueRef { C_i64(val as i64) } fn lli1(bval: bool) -> ValueRef { - C_bool(bval) + C_i1(bval) } fn llmdnode(elems: ~[ValueRef]) -> ValueRef { unsafe { diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index e19bafdb598..61204fe4e07 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -1236,7 +1236,6 @@ fn trans_unary_datum(bcx: block, un_expr: @ast::expr, op: ast::unop, sub_expr: @ast::expr) -> DatumBlock { - let _icx = bcx.insn_ctxt("trans_unary_datum"); // if deref, would be LvalueExpr @@ -1251,7 +1250,21 @@ fn trans_unary_datum(bcx: block, return match op { ast::not => { let Result {bcx, val} = trans_to_datum(bcx, sub_expr).to_result(); - immediate_rvalue_bcx(bcx, Not(bcx, val), un_ty) + + // If this is a boolean type, we must not use the LLVM Not + // instruction, as that is a *bitwise* not and we want *logical* + // not on our 8-bit boolean values. + let llresult = match ty::get(un_ty).sty { + ty::ty_bool => { + let llcond = ICmp(bcx, + lib::llvm::IntEQ, + val, + C_bool(false)); + Select(bcx, llcond, C_bool(true), C_bool(false)) + } + _ => Not(bcx, val) + }; + immediate_rvalue_bcx(bcx, llresult, un_ty) } ast::neg => { let Result {bcx, val} = trans_to_datum(bcx, sub_expr).to_result(); @@ -1308,8 +1321,8 @@ fn trans_eager_binop(bcx: block, binop_ty: ty::t, op: ast::binop, lhs_datum: &Datum, - rhs_datum: &Datum) -> DatumBlock -{ + rhs_datum: &Datum) + -> DatumBlock { let mut bcx = bcx; let _icx = bcx.insn_ctxt("trans_eager_binop"); @@ -1388,7 +1401,7 @@ fn trans_eager_binop(bcx: block, } let cmpr = base::compare_scalar_types(bcx, lhs, rhs, rhs_t, op); bcx = cmpr.bcx; - cmpr.val + ZExt(bcx, cmpr.val, T_i8()) } } _ => { @@ -1406,8 +1419,7 @@ fn trans_lazy_binop(bcx: block, binop_expr: @ast::expr, op: lazy_binop_ty, a: @ast::expr, - b: @ast::expr) -> DatumBlock -{ + b: @ast::expr) -> DatumBlock { let _icx = bcx.insn_ctxt("trans_lazy_binop"); let binop_ty = expr_ty(bcx, binop_expr); let mut bcx = bcx; @@ -1425,10 +1437,12 @@ fn trans_lazy_binop(bcx: block, let join = base::sub_block(bcx, ~"join"); let before_rhs = base::sub_block(bcx, ~"rhs"); + let lhs_i1 = bool_to_i1(past_lhs, lhs); match op { - lazy_and => CondBr(past_lhs, lhs, before_rhs.llbb, join.llbb), - lazy_or => CondBr(past_lhs, lhs, join.llbb, before_rhs.llbb) + lazy_and => CondBr(past_lhs, lhs_i1, before_rhs.llbb, join.llbb), + lazy_or => CondBr(past_lhs, lhs_i1, join.llbb, before_rhs.llbb) } + let Result {bcx: past_rhs, val: rhs} = { do base::with_scope_result(before_rhs, b.info(), ~"rhs") |bcx| { trans_to_datum(bcx, b).to_result() diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 171fdc79e3a..ae05ceb1ec5 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -524,7 +524,8 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, } ~"needs_drop" => { let tp_ty = substs.tys[0]; - Store(bcx, C_bool(ty::type_needs_drop(ccx.tcx, tp_ty)), + Store(bcx, + C_bool(ty::type_needs_drop(ccx.tcx, tp_ty)), fcx.llretptr); } ~"visit_tydesc" => { @@ -574,7 +575,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, let src_ptr = get_param(decl, first_real_arg + 1); let size = get_param(decl, first_real_arg + 2); let align = C_i32(1); - let volatile = C_bool(false); + let volatile = C_i1(false); let llfn = bcx.ccx().intrinsics.get( &~"llvm.memmove.p0i8.p0i8.i32"); Call(bcx, llfn, ~[dst_ptr, src_ptr, size, align, volatile]); @@ -584,7 +585,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, let src_ptr = get_param(decl, first_real_arg + 1); let size = get_param(decl, first_real_arg + 2); let align = C_i32(1); - let volatile = C_bool(false); + let volatile = C_i1(false); let llfn = bcx.ccx().intrinsics.get( &~"llvm.memmove.p0i8.p0i8.i64"); Call(bcx, llfn, ~[dst_ptr, src_ptr, size, align, volatile]); @@ -769,49 +770,49 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, } ~"ctlz8" => { let x = get_param(decl, first_real_arg); - let y = C_bool(false); + let y = C_i1(false); let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i8"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"ctlz16" => { let x = get_param(decl, first_real_arg); - let y = C_bool(false); + let y = C_i1(false); let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i16"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"ctlz32" => { let x = get_param(decl, first_real_arg); - let y = C_bool(false); + let y = C_i1(false); let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i32"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"ctlz64" => { let x = get_param(decl, first_real_arg); - let y = C_bool(false); + let y = C_i1(false); let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i64"); Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) } ~"cttz8" => { let x = get_param(decl, first_real_arg); - let y = C_bool(false); + let y = C_i1(false); let cttz = ccx.intrinsics.get(&~"llvm.cttz.i8"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"cttz16" => { let x = get_param(decl, first_real_arg); - let y = C_bool(false); + let y = C_i1(false); let cttz = ccx.intrinsics.get(&~"llvm.cttz.i16"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"cttz32" => { let x = get_param(decl, first_real_arg); - let y = C_bool(false); + let y = C_i1(false); let cttz = ccx.intrinsics.get(&~"llvm.cttz.i32"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } ~"cttz64" => { let x = get_param(decl, first_real_arg); - let y = C_bool(false); + let y = C_i1(false); let cttz = ccx.intrinsics.get(&~"llvm.cttz.i64"); Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) } diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index 59ba55920fd..7380fa2e562 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -109,6 +109,7 @@ pub impl reflector { ast::m_imm)), ArgVals(args), SaveIn(scratch.val), DontAutorefArg); let result = scratch.to_value_llval(bcx); + let result = bool_to_i1(bcx, result); let next_bcx = sub_block(bcx, ~"next"); CondBr(bcx, result, next_bcx.llbb, self.final_bcx.llbb); self.bcx = next_bcx From b91a51daca705b5aebfa58079963f24592a7e411 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 6 Feb 2013 00:03:12 -0500 Subject: [PATCH 28/37] remove issue #3148 workarounds (no longer needed) --- src/libcore/hashmap.rs | 7 ++----- src/libstd/json.rs | 8 -------- src/libstd/treemap.rs | 1 - 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs index adb16a92905..88981f514cf 100644 --- a/src/libcore/hashmap.rs +++ b/src/libcore/hashmap.rs @@ -49,9 +49,8 @@ pub mod linear { buckets: ~[Option>], } - // FIXME(#3148) -- we could rewrite FoundEntry - // to have type Option<&Bucket> which would be nifty - // However, that won't work until #3148 is fixed + // We could rewrite FoundEntry to have type Option<&Bucket> + // which would be nifty enum SearchResult { FoundEntry(uint), FoundHole(uint), TableFull } @@ -296,8 +295,6 @@ pub mod linear { FoundEntry(idx) => { match self.buckets[idx] { Some(ref bkt) => { - // FIXME(#3148)---should be inferred - let bkt: &self/Bucket = bkt; Some(&bkt.value) } None => { diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 4b34f318e91..13b58c43300 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -856,9 +856,6 @@ pub impl Decoder: serialize::Decoder { debug!("read_vec_elt(idx=%u)", idx); match *self.peek() { List(ref list) => { - // FIXME(#3148)---should be inferred - let list: &self/~[Json] = list; - self.stack.push(&list[idx]); f() } @@ -885,9 +882,6 @@ pub impl Decoder: serialize::Decoder { let top = self.peek(); match *top { Object(ref obj) => { - // FIXME(#3148) This hint should not be necessary. - let obj: &self/~Object = obj; - match obj.find(&name.to_owned()) { None => die!(fmt!("no such field: %s", name)), Some(json) => { @@ -917,8 +911,6 @@ pub impl Decoder: serialize::Decoder { debug!("read_tup_elt(idx=%u)", idx); match *self.peek() { List(ref list) => { - // FIXME(#3148)---should be inferred - let list: &self/~[Json] = list; self.stack.push(&list[idx]); f() } diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index 1105d65a4ed..b7af5de4cbf 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -142,7 +142,6 @@ impl TreeMap: Map { loop { match *current { Some(ref r) => { - let r: &self/~TreeNode = r; // FIXME: #3148 if *key < r.key { current = &r.left; } else if r.key < *key { From 5b6c26b4e44e05717cc9a1d0041f44fb4df4d102 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 6 Feb 2013 02:10:53 -0500 Subject: [PATCH 29/37] treemap: get rid of some implicit vector copies --- src/libstd/treemap.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index b7af5de4cbf..87801d76505 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -745,8 +745,8 @@ mod test_treemap { let v1 = str::to_bytes(~"baz"); let v2 = str::to_bytes(~"foobar"); - m.insert(k1, v1); - m.insert(k2, v2); + m.insert(copy k1, copy v1); + m.insert(copy k2, copy v2); assert m.find(&k2) == Some(&v2); assert m.find(&k1) == Some(&v1); From 37e998696f840ffea047efc50814819422750c20 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 6 Feb 2013 02:27:33 -0500 Subject: [PATCH 30/37] get rid of implicit vec copies in treemap iterator Each call to next() was doing a copy rather than a move. There's currently no way for this to be a method that uses &mut self, so it has to be a free function. Closes #4763. --- src/libstd/treemap.rs | 136 +++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 69 deletions(-) diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index 87801d76505..610f2f5a59c 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -49,8 +49,8 @@ impl TreeMap: Eq { let mut y = other.iter(); for self.len().times { unsafe { // unsafe as a purity workaround - x = x.next(); - y = y.next(); + map_next(&mut x); + map_next(&mut y); // FIXME: #4492 (ICE), x.get() == y.get() let (x1, x2) = x.get().unwrap(); let (y1, y2) = y.get().unwrap(); @@ -74,8 +74,8 @@ pure fn lt(a: &TreeMap, b: &TreeMap) -> bool { let (a_len, b_len) = (a.len(), b.len()); for uint::min(a_len, b_len).times { unsafe { // purity workaround - x = x.next(); - y = y.next(); + map_next(&mut x); + map_next(&mut y); let (key_a,_) = x.get().unwrap(); let (key_b,_) = y.get().unwrap(); if *key_a < *key_b { return true; } @@ -210,32 +210,30 @@ impl TreeMapIterator { // Returns the current node, or None if this iterator is at the end. fn get(&const self) -> Option<(&self/K, &self/V)> { match self.current { - Some(res) => Some((&res.key, &res.value)), - None => None + Some(res) => Some((&res.key, &res.value)), + None => None } } +} - /// Advance the iterator to the next node (in order). If this iterator - /// is finished, does nothing. - fn next(self) -> TreeMapIterator/&self { - let mut this = self; - while !this.stack.is_empty() || this.node.is_some() { - match *this.node { - Some(ref x) => { - this.stack.push(x); - this.node = &x.left; - } - None => { - let res = this.stack.pop(); - this.node = &res.right; - this.current = Some(res); - return this; - } - } +/// Advance the iterator to the next node (in order). If this iterator +/// is finished, does nothing. +fn map_next(iter: &mut TreeMapIterator/&a) { + while !iter.stack.is_empty() || iter.node.is_some() { + match *iter.node { + Some(ref x) => { + iter.stack.push(x); + iter.node = &x.left; + } + None => { + let res = iter.stack.pop(); + iter.node = &res.right; + iter.current = Some(res); + return; + } } - this.current = None; - return this; } + iter.current = None; } pub struct TreeSet { @@ -297,18 +295,18 @@ impl TreeSet: Set { let mut x = self.iter(); let mut y = other.iter(); unsafe { // purity workaround - x = x.next(); - y = y.next(); + set_next(&mut x); + set_next(&mut y); let mut a = x.get(); let mut b = y.get(); while a.is_some() && b.is_some() { let a1 = a.unwrap(); let b1 = b.unwrap(); if a1 < b1 { - x = x.next(); + set_next(&mut x); a = x.get(); } else if b1 < a1 { - y = y.next(); + set_next(&mut y); b = y.get(); } else { return false; @@ -328,8 +326,8 @@ impl TreeSet: Set { let mut x = self.iter(); let mut y = other.iter(); unsafe { // purity workaround - x = x.next(); - y = y.next(); + set_next(&mut x); + set_next(&mut y); let mut a = x.get(); let mut b = y.get(); while b.is_some() { @@ -345,10 +343,10 @@ impl TreeSet: Set { } if !(a1 < b1) { - y = y.next(); + set_next(&mut y); b = y.get(); } - x = x.next(); + set_next(&mut x); a = x.get(); } } @@ -361,15 +359,15 @@ impl TreeSet: Set { let mut y = other.iter(); unsafe { // purity workaround - x = x.next(); - y = y.next(); + set_next(&mut x); + set_next(&mut y); let mut a = x.get(); let mut b = y.get(); while a.is_some() { if b.is_none() { return do a.while_some() |a1| { - if f(a1) { x = x.next(); x.get() } else { None } + if f(a1) { set_next(&mut x); x.get() } else { None } } } @@ -378,11 +376,11 @@ impl TreeSet: Set { if a1 < b1 { if !f(a1) { return } - x = x.next(); + set_next(&mut x); a = x.get(); } else { - if !(b1 < a1) { x = x.next(); a = x.get() } - y = y.next(); + if !(b1 < a1) { set_next(&mut x); a = x.get() } + set_next(&mut y); b = y.get(); } } @@ -396,15 +394,15 @@ impl TreeSet: Set { let mut y = other.iter(); unsafe { // purity workaround - x = x.next(); - y = y.next(); + set_next(&mut x); + set_next(&mut y); let mut a = x.get(); let mut b = y.get(); while a.is_some() { if b.is_none() { return do a.while_some() |a1| { - if f(a1) { x.next(); x.get() } else { None } + if f(a1) { set_next(&mut x); x.get() } else { None } } } @@ -413,21 +411,21 @@ impl TreeSet: Set { if a1 < b1 { if !f(a1) { return } - x = x.next(); + set_next(&mut x); a = x.get(); } else { if b1 < a1 { if !f(b1) { return } } else { - x = x.next(); + set_next(&mut x); a = x.get(); } - y = y.next(); + set_next(&mut y); b = y.get(); } } do b.while_some |b1| { - if f(b1) { y = y.next(); y.get() } else { None } + if f(b1) { set_next(&mut y); y.get() } else { None } } } } @@ -438,8 +436,8 @@ impl TreeSet: Set { let mut y = other.iter(); unsafe { // purity workaround - x = x.next(); - y = y.next(); + set_next(&mut x); + set_next(&mut y); let mut a = x.get(); let mut b = y.get(); @@ -447,13 +445,13 @@ impl TreeSet: Set { let a1 = a.unwrap(); let b1 = b.unwrap(); if a1 < b1 { - x = x.next(); + set_next(&mut x); a = x.get(); } else { if !(b1 < a1) { if !f(a1) { return } } - y = y.next(); + set_next(&mut y); b = y.get(); } } @@ -466,15 +464,15 @@ impl TreeSet: Set { let mut y = other.iter(); unsafe { // purity workaround - x = x.next(); - y = y.next(); + set_next(&mut x); + set_next(&mut y); let mut a = x.get(); let mut b = y.get(); while a.is_some() { if b.is_none() { return do a.while_some() |a1| { - if f(a1) { x = x.next(); x.get() } else { None } + if f(a1) { set_next(&mut x); x.get() } else { None } } } @@ -483,15 +481,15 @@ impl TreeSet: Set { if b1 < a1 { if !f(b1) { return } - y = y.next(); + set_next(&mut y); b = y.get(); } else { if !f(a1) { return } if !(a1 < b1) { - y = y.next(); + set_next(&mut y); b = y.get() } - x = x.next(); + set_next(&mut x); a = x.get(); } } @@ -524,16 +522,16 @@ impl TreeSetIterator { /// Returns the current node, or None if this iterator is at the end. fn get(&const self) -> Option<&self/T> { match self.iter.get() { - None => None, - Some((k, _)) => Some(k) + None => None, + Some((k, _)) => Some(k) } } +} - /// Advance the iterator to the next node (in order). If this iterator is - /// finished, does nothing. - fn next(self) -> TreeSetIterator/&self { - TreeSetIterator { iter: self.iter.next() } - } +/// Advance the iterator to the next node (in order). If this iterator is +/// finished, does nothing. +fn set_next(iter: &mut TreeSetIterator/&a) { + map_next(&mut iter.iter); } // Nodes keep track of their level in the tree, starting at 1 in the @@ -967,18 +965,18 @@ mod test_treemap { // FIXME: #4492 (ICE): iter.next() == Some((&x1, &y1)) - iter = iter.next(); + map_next(&mut iter); assert iter.get().unwrap() == (&x1, &y1); - iter = iter.next(); + map_next(&mut iter); assert iter.get().unwrap() == (&x2, &y2); - iter = iter.next(); + map_next(&mut iter); assert iter.get().unwrap() == (&x3, &y3); - iter = iter.next(); + map_next(&mut iter); assert iter.get().unwrap() == (&x4, &y4); - iter = iter.next(); + map_next(&mut iter); assert iter.get().unwrap() == (&x5, &y5); - iter = iter.next(); + map_next(&mut iter); assert iter.get().is_none(); } } From 16941687839a4fa06e57d1d1cf36a3ccbc0257e1 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 6 Feb 2013 02:34:15 -0500 Subject: [PATCH 31/37] update treemap FIXME --- src/libstd/treemap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index 610f2f5a59c..b234f9b0f3d 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -963,7 +963,7 @@ mod test_treemap { let m = m; let mut iter = m.iter(); - // FIXME: #4492 (ICE): iter.next() == Some((&x1, &y1)) + // FIXME: #4492 (ICE): iter.get() == Some((&x1, &y1)) map_next(&mut iter); assert iter.get().unwrap() == (&x1, &y1); From bdfb930f3412bcbf792bd8ab10f40b6560663a5f Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 6 Feb 2013 02:39:47 -0500 Subject: [PATCH 32/37] treemap: make map_next and set_next public --- src/libstd/treemap.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index b234f9b0f3d..3cc287b16a3 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -218,7 +218,7 @@ impl TreeMapIterator { /// Advance the iterator to the next node (in order). If this iterator /// is finished, does nothing. -fn map_next(iter: &mut TreeMapIterator/&a) { +pub fn map_next(iter: &mut TreeMapIterator/&a) { while !iter.stack.is_empty() || iter.node.is_some() { match *iter.node { Some(ref x) => { @@ -530,7 +530,7 @@ impl TreeSetIterator { /// Advance the iterator to the next node (in order). If this iterator is /// finished, does nothing. -fn set_next(iter: &mut TreeSetIterator/&a) { +pub fn set_next(iter: &mut TreeSetIterator/&a) { map_next(&mut iter.iter); } From dab2f2fac0d5147b088489abfbcf43714ed36156 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 6 Feb 2013 02:49:05 -0500 Subject: [PATCH 33/37] remove old snapshot workaround from smallintmap --- src/libstd/smallintmap.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index a21328b3d63..1cd35722ab4 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -116,8 +116,6 @@ pub impl SmallIntMap { } pub impl SmallIntMap { - // FIXME: #4733, remove after the next snapshot - #[cfg(stage2)] fn update_with_key(&mut self, key: uint, val: V, ff: fn(uint, V, V) -> V) -> bool { match self.find(&key) { @@ -126,8 +124,6 @@ pub impl SmallIntMap { } } - // FIXME: #4733, remove after the next snapshot - #[cfg(stage2)] fn update(&mut self, key: uint, newval: V, ff: fn(V, V) -> V) -> bool { self.update_with_key(key, newval, |_k, v, v1| ff(v,v1)) } From 79dc10dba91d242b2bbdc65e20dd0fe5fe7f3f40 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 6 Feb 2013 14:59:03 -0800 Subject: [PATCH 34/37] doc: improvements to version-stamp makefile logic. --- mk/docs.mk | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mk/docs.mk b/mk/docs.mk index 9f64712b9c8..36e8bee7f7a 100644 --- a/mk/docs.mk +++ b/mk/docs.mk @@ -45,7 +45,7 @@ doc/rust.html: rust.md doc/version_info.html doc/rust.css doc/manual.css --from=markdown --to=html \ --css=rust.css \ --css=manual.css \ - --include-before-body=doc/version_info.html \ + --include-before-body=doc/version_info.html \ --output=$@ endif @@ -66,6 +66,7 @@ doc/rust.tex: rust.md doc/version.md "$(CFG_PANDOC)" \ --standalone --toc \ --number-sections \ + --include-before-body=doc/version.md \ --from=markdown --to=latex \ --output=$@ @@ -199,16 +200,17 @@ ifdef CFG_DISABLE_DOCS endif -doc/version.md: $(MKFILE_DEPS) rust.md +doc/version.md: $(MKFILE_DEPS) $(wildcard $(S)doc/*.*) @$(call E, version-stamp: $@) $(Q)echo "$(CFG_VERSION)" >$@ -doc/version_info.html: version_info.html.template +doc/version_info.html: version_info.html.template $(MKFILE_DEPS) \ + $(wildcard $(S)doc/*.*) @$(call E, version-info: $@) sed -e "s/VERSION/$(CFG_RELEASE)/; s/SHORT_HASH/$(shell echo \ $(CFG_VER_HASH) | head -c 8)/;\ s/STAMP/$(CFG_VER_HASH)/;" $< >$@ -GENERATED += doc/version.md +GENERATED += doc/version.md doc/version_info.html docs: $(DOCS) From 6d13c9025611cf904c0ef209dfad3d0d29fd7d5a Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 6 Feb 2013 15:08:33 -0800 Subject: [PATCH 35/37] librustc: Stop loading enum variant discriminants from memory --- src/librustc/middle/trans/base.rs | 21 --------------------- src/librustc/middle/trans/expr.rs | 6 +++--- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index b48eb088c50..30004dcfdca 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -813,27 +813,6 @@ pub fn get_discrim_val(cx: @crate_ctxt, span: span, enum_did: ast::def_id, } } -pub fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef { - unsafe { - let _icx = ccx.insn_ctxt("lookup_discriminant"); - match ccx.discrims.find(&vid) { - None => { - // It's an external discriminant that we haven't seen yet. - assert (vid.crate != ast::local_crate); - let sym = csearch::get_symbol(ccx.sess.cstore, vid); - let gvar = str::as_c_str(sym, |buf| { - llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf) - }); - lib::llvm::SetLinkage(gvar, lib::llvm::ExternalLinkage); - llvm::LLVMSetGlobalConstant(gvar, True); - ccx.discrims.insert(vid, gvar); - return gvar; - } - Some(llval) => return llval, - } - } -} - pub fn invoke(bcx: block, llfn: ValueRef, +llargs: ~[ValueRef]) -> block { let _icx = bcx.insn_ctxt("invoke_"); if bcx.unreachable { return bcx; } diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 61204fe4e07..56833d373c5 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -696,15 +696,15 @@ fn trans_def_dps_unadjusted(bcx: block, ref_expr: @ast::expr, return fn_data_to_datum(bcx, impl_did, fn_data, lldest); } ast::def_variant(tid, vid) => { - if ty::enum_variant_with_id(ccx.tcx, tid, vid).args.len() > 0u { + let variant_info = ty::enum_variant_with_id(ccx.tcx, tid, vid); + if variant_info.args.len() > 0u { // N-ary variant. let fn_data = callee::trans_fn_ref(bcx, vid, ref_expr.id); return fn_data_to_datum(bcx, vid, fn_data, lldest); } else { // Nullary variant. let lldiscrimptr = GEPi(bcx, lldest, [0u, 0u]); - let lldiscrim_gv = base::lookup_discriminant(ccx, vid); - let lldiscrim = Load(bcx, lldiscrim_gv); + let lldiscrim = C_int(bcx.ccx(), variant_info.disr_val); Store(bcx, lldiscrim, lldiscrimptr); return bcx; } From cf6c3d96fb1a7230cbdd8ebc77af30ba35b9e35a Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 6 Feb 2013 15:37:34 -0800 Subject: [PATCH 36/37] librustc: Attempt to put out burning tree by fixing translation of unary negation in boolean constants. rs=burningtree --- src/librustc/lib/llvm.rs | 33 +++++++++++++++++------------ src/librustc/middle/trans/consts.rs | 13 +++++++++++- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 50f4fe43efd..2e3967021c1 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -445,14 +445,19 @@ pub extern mod llvm { Count: c_uint, Packed: Bool) -> ValueRef; - pub unsafe fn LLVMConstString(Str: *c_char, Length: c_uint, - DontNullTerminate: Bool) -> ValueRef; - pub unsafe fn LLVMConstArray(ElementTy: TypeRef, ConstantVals: *ValueRef, - Length: c_uint) -> ValueRef; + pub unsafe fn LLVMConstString(Str: *c_char, + Length: c_uint, + DontNullTerminate: Bool) + -> ValueRef; + pub unsafe fn LLVMConstArray(ElementTy: TypeRef, + ConstantVals: *ValueRef, + Length: c_uint) + -> ValueRef; pub unsafe fn LLVMConstStruct(ConstantVals: *ValueRef, - Count: c_uint, Packed: Bool) -> ValueRef; + Count: c_uint, + Packed: Bool) -> ValueRef; pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef, - Size: c_uint) -> ValueRef; + Size: c_uint) -> ValueRef; /* Constant expressions */ pub unsafe fn LLVMAlignOf(Ty: TypeRef) -> ValueRef; @@ -463,8 +468,8 @@ pub extern mod llvm { pub unsafe fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef; pub unsafe fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef; pub unsafe fn LLVMConstAdd(LHSConstant: ValueRef, - RHSConstant: ValueRef) - -> ValueRef; + RHSConstant: ValueRef) + -> ValueRef; pub unsafe fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; @@ -475,14 +480,14 @@ pub extern mod llvm { RHSConstant: ValueRef) -> ValueRef; pub unsafe fn LLVMConstSub(LHSConstant: ValueRef, - RHSConstant: ValueRef) - -> ValueRef; + RHSConstant: ValueRef) + -> ValueRef; pub unsafe fn LLVMConstNSWSub(LHSConstant: ValueRef, - RHSConstant: ValueRef) - -> ValueRef; + RHSConstant: ValueRef) + -> ValueRef; pub unsafe fn LLVMConstNUWSub(LHSConstant: ValueRef, - RHSConstant: ValueRef) - -> ValueRef; + RHSConstant: ValueRef) + -> ValueRef; pub unsafe fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 12340101d9e..34f1f1f2314 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -204,7 +204,18 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { ast::box(_) | ast::uniq(_) | ast::deref => const_deref(cx, te), - ast::not => llvm::LLVMConstNot(te), + ast::not => { + match ty::get(ty).sty { + ty::ty_bool => { + // Somewhat questionable, but I believe this is + // correct. + let te = llvm::LLVMConstTrunc(te, T_i1()); + let te = llvm::LLVMConstNot(te); + llvm::LLVMConstZExt(te, T_bool()) + } + _ => llvm::LLVMConstNot(te), + } + } ast::neg => { if is_float { llvm::LLVMConstFNeg(te) } else { llvm::LLVMConstNeg(te) } From a32498d8464e0dfa4e2cb31967a66e076da40109 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 31 Jan 2013 17:12:29 -0800 Subject: [PATCH 37/37] Make ~fn non-copyable, make &fn copyable, split barefn/closure types, correct handling of moves for struct-record update. Part of #3678. Fixes #2828, #3904, #4719. --- src/compiletest/compiletest.rc | 15 +- src/libcore/at_vec.rs | 4 - src/libcore/bool.rs | 4 - src/libcore/cast.rs | 3 - src/libcore/char.rs | 4 - src/libcore/cleanup.rs | 4 - src/libcore/cmp.rs | 4 - src/libcore/container.rs | 3 - src/libcore/core.rc | 2 - src/libcore/dlist.rs | 4 - src/libcore/dvec.rs | 4 - src/libcore/either.rs | 4 - src/libcore/extfmt.rs | 4 - src/libcore/flate.rs | 4 - src/libcore/from_str.rs | 4 - src/libcore/gc.rs | 3 - src/libcore/hash.rs | 4 - src/libcore/hashmap.rs | 4 - src/libcore/io.rs | 3 - src/libcore/iter-trait.rs | 3 - src/libcore/iter.rs | 3 - src/libcore/libc.rs | 3 - src/libcore/logging.rs | 4 - src/libcore/managed.rs | 4 - src/libcore/mutable.rs | 2 - src/libcore/nil.rs | 4 - src/libcore/num/cmath.rs | 3 - src/libcore/num/f32.rs | 4 - src/libcore/num/f64.rs | 4 - src/libcore/num/float.rs | 4 - src/libcore/num/int-template.rs | 4 - src/libcore/num/uint-template.rs | 4 - src/libcore/ops.rs | 3 - src/libcore/option.rs | 3 - src/libcore/os.rs | 3 - src/libcore/owned.rs | 4 - src/libcore/path.rs | 4 - src/libcore/pipes.rs | 5 - src/libcore/prelude.rs | 2 +- src/libcore/private.rs | 5 - src/libcore/private/finally.rs | 22 + src/libcore/ptr.rs | 3 - src/libcore/rand.rs | 4 - src/libcore/reflect.rs | 3 - src/libcore/repr.rs | 3 - src/libcore/result.rs | 3 - src/libcore/rt.rs | 3 - src/libcore/run.rs | 3 - src/libcore/stackwalk.rs | 5 - src/libcore/str.rs | 18 +- src/libcore/sys.rs | 4 - src/libcore/task/mod.rs | 5 - src/libcore/task/spawn.rs | 1 - src/libcore/to_bytes.rs | 6 +- src/libcore/to_str.rs | 4 - src/libcore/tuple.rs | 4 - src/libcore/unicode.rs | 3 - src/libcore/util.rs | 4 - src/libcore/vec.rs | 104 +++- src/librustc/front/config.rs | 25 +- src/librustc/front/test.rs | 113 ++-- src/librustc/metadata/decoder.rs | 24 +- src/librustc/metadata/encoder.rs | 10 +- src/librustc/metadata/tydecode.rs | 79 ++- src/librustc/metadata/tyencode.rs | 54 +- src/librustc/middle/borrowck/check_loans.rs | 60 +- src/librustc/middle/check_const.rs | 2 +- src/librustc/middle/check_loop.rs | 4 +- src/librustc/middle/check_match.rs | 14 +- src/librustc/middle/freevars.rs | 6 +- src/librustc/middle/kind.rs | 58 +- src/librustc/middle/lint.rs | 17 +- src/librustc/middle/mem_categorization.rs | 99 ++-- src/librustc/middle/moves.rs | 34 +- src/librustc/middle/region.rs | 12 +- src/librustc/middle/trans/_match.rs | 2 +- src/librustc/middle/trans/base.rs | 32 +- src/librustc/middle/trans/callee.rs | 9 +- src/librustc/middle/trans/closure.rs | 116 ++-- src/librustc/middle/trans/controlflow.rs | 12 +- src/librustc/middle/trans/expr.rs | 71 +-- src/librustc/middle/trans/foreign.rs | 25 +- src/librustc/middle/trans/glue.rs | 15 +- src/librustc/middle/trans/inline.rs | 4 +- src/librustc/middle/trans/machine.rs | 7 +- src/librustc/middle/trans/meth.rs | 6 +- src/librustc/middle/trans/monomorphize.rs | 65 ++- src/librustc/middle/trans/reflect.rs | 97 ++-- src/librustc/middle/trans/type_of.rs | 14 +- src/librustc/middle/trans/type_use.rs | 29 +- src/librustc/middle/ty.rs | 540 ++++++------------ src/librustc/middle/typeck/astconv.rs | 162 +++--- src/librustc/middle/typeck/check/method.rs | 8 +- src/librustc/middle/typeck/check/mod.rs | 525 +++++++++-------- src/librustc/middle/typeck/check/regionck.rs | 19 +- .../middle/typeck/check/regionmanip.rs | 17 - src/librustc/middle/typeck/check/vtable.rs | 2 +- src/librustc/middle/typeck/coherence.rs | 6 +- src/librustc/middle/typeck/collect.rs | 186 +++--- src/librustc/middle/typeck/infer/coercion.rs | 43 +- src/librustc/middle/typeck/infer/combine.rs | 78 ++- src/librustc/middle/typeck/infer/glb.rs | 18 +- src/librustc/middle/typeck/infer/lattice.rs | 17 - src/librustc/middle/typeck/infer/lub.rs | 18 +- src/librustc/middle/typeck/infer/mod.rs | 4 - .../middle/typeck/infer/region_inference.rs | 3 - src/librustc/middle/typeck/infer/sub.rs | 18 +- src/librustc/middle/typeck/infer/to_str.rs | 14 +- src/librustc/middle/typeck/mod.rs | 6 +- src/librustc/util/ppaux.rs | 169 +++--- src/librustdoc/astsrv.rs | 5 +- src/librustdoc/attr_parser.rs | 2 +- src/librustdoc/desc_to_brief_pass.rs | 4 +- src/librustdoc/doc.rs | 34 +- src/librustdoc/extract.rs | 2 +- src/librustdoc/fold.rs | 40 +- src/librustdoc/markdown_index_pass.rs | 8 +- src/librustdoc/markdown_pass.rs | 7 +- src/librustdoc/page_pass.rs | 4 +- src/librustdoc/pass.rs | 2 +- src/librustdoc/sectionalize_pass.rs | 4 +- src/librustdoc/sort_pass.rs | 6 +- src/librustdoc/text_pass.rs | 12 +- src/librustdoc/unindent_pass.rs | 2 +- src/libstd/arc.rs | 2 - src/libstd/arena.rs | 2 - src/libstd/base64.rs | 2 - src/libstd/bitv.rs | 2 - src/libstd/c_vec.rs | 1 - src/libstd/cell.rs | 2 - src/libstd/cmp.rs | 1 - src/libstd/comm.rs | 3 - src/libstd/dbg.rs | 1 - src/libstd/deque.rs | 1 - src/libstd/ebml.rs | 2 - src/libstd/fun_treemap.rs | 2 - src/libstd/getopts.rs | 1 - src/libstd/json.rs | 1 - src/libstd/list.rs | 1 - src/libstd/md4.rs | 2 - src/libstd/net_ip.rs | 1 - src/libstd/net_tcp.rs | 1 + src/libstd/net_url.rs | 3 +- src/libstd/oldmap.rs | 1 - src/libstd/par.rs | 51 +- src/libstd/prettyprint.rs | 2 - src/libstd/rl.rs | 4 +- src/libstd/rope.rs | 2 - src/libstd/serialize.rs | 1 - src/libstd/sha1.rs | 2 - src/libstd/smallintmap.rs | 1 - src/libstd/sort.rs | 14 +- src/libstd/std.rc | 4 - src/libstd/sync.rs | 2 - src/libstd/tempfile.rs | 2 - src/libstd/term.rs | 1 - src/libstd/test.rs | 209 ++++--- src/libstd/time.rs | 2 - src/libstd/timer.rs | 2 - src/libstd/treemap.rs | 2 - src/libstd/uv_global_loop.rs | 2 - src/libstd/uv_iotask.rs | 1 - src/libstd/workcache.rs | 2 + src/libsyntax/ast.rs | 82 ++- src/libsyntax/attr.rs | 6 +- src/libsyntax/codemap.rs | 4 +- src/libsyntax/ext/auto_encode.rs | 2 +- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/fold.rs | 15 +- src/libsyntax/parse/classify.rs | 6 +- src/libsyntax/parse/parser.rs | 170 +++--- src/libsyntax/print/pprust.rs | 108 ++-- src/libsyntax/syntax.rc | 1 - src/libsyntax/visit.rs | 15 +- src/test/bench/graph500-bfs.rs | 44 +- src/test/bench/task-perf-alloc-unwind.rs | 9 +- .../bad-var-env-capture-in-block-arg.rs | 17 - ...ock-arg-used-as-lambda-with-illegal-cap.rs | 20 - .../compile-fail/functional-struct-update.rs | 31 - src/test/compile-fail/issue-3044.rs | 7 +- src/test/compile-fail/kindck-owned.rs | 4 +- .../compile-fail/moves-sru-moved-field.rs | 27 + src/test/run-pass/bounded-fn-type.rs | 17 - src/test/run-pass/morestack6.rs | 6 +- src/test/run-pass/newtype.rs | 1 + src/test/run-pass/sendfn-deep-copy.rs | 36 -- src/test/run-pass/test-ignore-cfg.rs | 12 +- 187 files changed, 2065 insertions(+), 2373 deletions(-) delete mode 100644 src/test/compile-fail/bad-var-env-capture-in-block-arg.rs delete mode 100644 src/test/compile-fail/block-arg-used-as-lambda-with-illegal-cap.rs delete mode 100644 src/test/compile-fail/functional-struct-update.rs create mode 100644 src/test/compile-fail/moves-sru-moved-field.rs delete mode 100644 src/test/run-pass/bounded-fn-type.rs delete mode 100644 src/test/run-pass/sendfn-deep-copy.rs diff --git a/src/compiletest/compiletest.rc b/src/compiletest/compiletest.rc index 8f5f9547c52..b63ac5e75a2 100644 --- a/src/compiletest/compiletest.rc +++ b/src/compiletest/compiletest.rc @@ -159,7 +159,7 @@ pub fn test_opts(config: config) -> test::TestOpts { } } -pub fn make_tests(config: config) -> ~[test::TestDesc] { +pub fn make_tests(config: config) -> ~[test::TestDescAndFn] { debug!("making tests from %s", config.src_base.to_str()); let mut tests = ~[]; @@ -196,13 +196,14 @@ pub fn is_test(config: config, testfile: &Path) -> bool { return valid; } -pub fn make_test(config: config, testfile: &Path) -> - test::TestDesc { - test::TestDesc { - name: make_test_name(config, testfile), +pub fn make_test(config: config, testfile: &Path) -> test::TestDescAndFn { + test::TestDescAndFn { + desc: test::TestDesc { + name: make_test_name(config, testfile), + ignore: header::is_test_ignored(config, testfile), + should_fail: false + }, testfn: make_test_closure(config, testfile), - ignore: header::is_test_ignored(config, testfile), - should_fail: false } } diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index be95148e554..75db5359e2e 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -10,10 +10,6 @@ //! Managed vectors -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cast::transmute; use kinds::Copy; use iter; diff --git a/src/libcore/bool.rs b/src/libcore/bool.rs index 2f3a53ea504..1eebb716a59 100644 --- a/src/libcore/bool.rs +++ b/src/libcore/bool.rs @@ -9,10 +9,6 @@ // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - //! Boolean logic use bool; diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index 950a753d73f..14cc79ceaff 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Unsafe operations -#[forbid(deprecated_mode)] - #[abi = "rust-intrinsic"] extern mod rusti { fn forget(-x: T); diff --git a/src/libcore/char.rs b/src/libcore/char.rs index deecdc98ffa..f7a369489d1 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -10,10 +10,6 @@ //! Utilities for manipulating the char type -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use char; use cmp::Eq; use option::{None, Option, Some}; diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs index 1967f1771be..11a4cad5d1b 100644 --- a/src/libcore/cleanup.rs +++ b/src/libcore/cleanup.rs @@ -10,10 +10,6 @@ #[doc(hidden)]; -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use libc::{c_char, c_void, intptr_t, uintptr_t}; use ptr::{mut_null, null, to_unsafe_ptr}; use repr::BoxRepr; diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 038ea2ba675..e1ec8c7737c 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -20,10 +20,6 @@ and `Eq` to overload the `==` and `!=` operators. */ -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - /** * Trait for values that can be compared for equality * and inequality. diff --git a/src/libcore/container.rs b/src/libcore/container.rs index c8be690a38c..2a5ca7d8dfa 100644 --- a/src/libcore/container.rs +++ b/src/libcore/container.rs @@ -10,9 +10,6 @@ //! Container traits -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use option::Option; pub trait Container { diff --git a/src/libcore/core.rc b/src/libcore/core.rc index aece60652a2..64b480818b1 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -48,8 +48,6 @@ Implicitly, all crates behave as if they included the following prologue: // Don't link to core. We are core. #[no_core]; -#[warn(deprecated_mode)]; -#[warn(deprecated_pattern)]; #[warn(vecs_implicitly_copyable)]; #[deny(non_camel_case_types)]; #[allow(deprecated_self)]; diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index d4216b283a9..ed67e010b40 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -18,10 +18,6 @@ Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate. */ -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use kinds::Copy; use managed; use option::{None, Option, Some}; diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 2fd7d71a7fc..fe36ed15960 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -19,10 +19,6 @@ Note that recursive use is not permitted. */ -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cast; use cast::reinterpret_cast; use prelude::*; diff --git a/src/libcore/either.rs b/src/libcore/either.rs index 5e9ccd84195..7efde62c4ca 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -8,10 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - //! A type that represents one of two alternatives use cmp::Eq; diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 259895da2a5..4d2a1b2afe0 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -51,10 +51,6 @@ //! * s - str (any flavor) //! * ? - arbitrary type (does not use the to_str trait) -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - // Transitional #[allow(structural_records)]; // Macros -- needs a snapshot diff --git a/src/libcore/flate.rs b/src/libcore/flate.rs index 39a3aa890df..6b5c083662b 100644 --- a/src/libcore/flate.rs +++ b/src/libcore/flate.rs @@ -14,10 +14,6 @@ Simple compression */ -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use libc; use libc::{c_void, size_t, c_int}; use ptr; diff --git a/src/libcore/from_str.rs b/src/libcore/from_str.rs index c3fda7eb8bd..9322c7e7cb8 100644 --- a/src/libcore/from_str.rs +++ b/src/libcore/from_str.rs @@ -10,10 +10,6 @@ //! The trait for types that can be created from strings -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use option::Option; pub trait FromStr { diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index 8150bfbe0ee..d0c40ccf19a 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -35,9 +35,6 @@ with destructors. */ -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; // Transitional #[allow(structural_records)]; diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index d676570e1e6..692cfee5365 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -8,10 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - /*! * Implementation of SipHash 2-4 * diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs index 88981f514cf..be785863f71 100644 --- a/src/libcore/hashmap.rs +++ b/src/libcore/hashmap.rs @@ -10,10 +10,6 @@ //! Sendable hash maps. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use container::{Container, Mutable, Map, Set}; use cmp::Eq; use hash::Hash; diff --git a/src/libcore/io.rs b/src/libcore/io.rs index e7d568c5433..721a6584c65 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -14,9 +14,6 @@ Basic input/output */ -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use result::Result; use cmp::Eq; diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs index 942db1c5f29..df2aa6271d1 100644 --- a/src/libcore/iter-trait.rs +++ b/src/libcore/iter-trait.rs @@ -12,9 +12,6 @@ // workaround our lack of traits and lack of macros. See core.{rc,rs} for // how this file is used. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cmp::{Eq, Ord}; use iter::BaseIter; use iter; diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 2ffa8702261..c414ab0f5f3 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -14,9 +14,6 @@ The iteration traits and common implementation */ -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cmp::{Eq, Ord}; use kinds::Copy; use option::{None, Option, Some}; diff --git a/src/libcore/libc.rs b/src/libcore/libc.rs index a1107d49c0e..6976c83a6f4 100644 --- a/src/libcore/libc.rs +++ b/src/libcore/libc.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; /*! * Bindings for libc. * diff --git a/src/libcore/logging.rs b/src/libcore/logging.rs index 922995a5af7..357a3415ac2 100644 --- a/src/libcore/logging.rs +++ b/src/libcore/logging.rs @@ -10,10 +10,6 @@ //! Logging -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cast::transmute; use io; use libc; diff --git a/src/libcore/managed.rs b/src/libcore/managed.rs index 32fc5f527b7..700feee9839 100644 --- a/src/libcore/managed.rs +++ b/src/libcore/managed.rs @@ -10,10 +10,6 @@ //! Operations on managed box types -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cast::transmute; use cmp::{Eq, Ord}; use managed::raw::BoxRepr; diff --git a/src/libcore/mutable.rs b/src/libcore/mutable.rs index 4623a3f4543..3c44c197f5e 100644 --- a/src/libcore/mutable.rs +++ b/src/libcore/mutable.rs @@ -18,8 +18,6 @@ dynamic checks: your program will fail if you attempt to perform mutation when the data structure should be immutable. */ -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; use util::with; use cast::transmute_immut; diff --git a/src/libcore/nil.rs b/src/libcore/nil.rs index f3eb62a3a3a..8f03a1b6e34 100644 --- a/src/libcore/nil.rs +++ b/src/libcore/nil.rs @@ -14,10 +14,6 @@ Functions for the unit type. */ -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cmp::{Eq, Ord}; #[cfg(notest)] diff --git a/src/libcore/num/cmath.rs b/src/libcore/num/cmath.rs index 6341481809e..c030dfc5899 100644 --- a/src/libcore/num/cmath.rs +++ b/src/libcore/num/cmath.rs @@ -9,9 +9,6 @@ // except according to those terms. #[doc(hidden)]; // FIXME #3538 -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; use libc::c_int; use libc::c_float; diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 24ad5c114af..738445b5cd9 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -8,10 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - //! Operations and constants for `f32` use cmath; diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 126a48cf280..f09d874803c 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -8,10 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - //! Operations and constants for `f64` use cmath; diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs index 32cda029cd1..f5ae05ebffb 100644 --- a/src/libcore/num/float.rs +++ b/src/libcore/num/float.rs @@ -8,10 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - //! Operations and constants for `float` // Even though this module exports everything defined in it, diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index 8b02f3a94c5..1856781b1d7 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -8,10 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use T = self::inst::T; use char; diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index 82c6e017014..f8bbb35204a 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -8,10 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use T = self::inst::T; use T_SIGNED = self::inst::T_SIGNED; diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 36293d6a1c0..aaa4ab3fecf 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -10,9 +10,6 @@ // Core operators -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - #[lang="drop"] pub trait Drop { fn finalize(&self); // FIXME(#4332): Rename to "drop"? --pcwalton diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 9cb955ad352..e5d703eec4a 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -41,9 +41,6 @@ let unwrapped_msg = match move msg { */ -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cmp::Eq; use kinds::Copy; use option; diff --git a/src/libcore/os.rs b/src/libcore/os.rs index af484454ef4..a14abd23cc3 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; #[allow(structural_records)]; /*! diff --git a/src/libcore/owned.rs b/src/libcore/owned.rs index fb14820113e..d841188501d 100644 --- a/src/libcore/owned.rs +++ b/src/libcore/owned.rs @@ -10,10 +10,6 @@ //! Operations on unique pointer types -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cmp::{Eq, Ord}; #[cfg(notest)] diff --git a/src/libcore/path.rs b/src/libcore/path.rs index 0b64df8c112..bf1f1c713a9 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -14,10 +14,6 @@ Cross-platform file path handling */ -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cmp::Eq; use libc; use option::{None, Option, Some}; diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 5f9eed70868..3f0aecb887d 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -82,11 +82,6 @@ bounded and unbounded protocols allows for less code duplication. */ -// NB: transitionary, de-mode-ing. -// tjc: allowing deprecated modes due to function issue, -// re-forbid after snapshot -#[forbid(deprecated_pattern)]; - // Transitional -- needs snapshot #[allow(structural_records)]; diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 4e6f209e79e..a798d8c866a 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -36,7 +36,7 @@ pub use path::PosixPath; pub use path::WindowsPath; pub use pipes::{GenericChan, GenericPort}; pub use ptr::Ptr; -pub use str::{StrSlice, Trimmable}; +pub use str::{StrSlice, Trimmable, OwnedStr}; pub use to_bytes::IterBytes; pub use to_str::ToStr; pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps}; diff --git a/src/libcore/private.rs b/src/libcore/private.rs index 40194713365..d4cf39ad262 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -8,11 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -// tjc: Re-forbid deprecated modes once a snapshot fixes the -// function problem -#[forbid(deprecated_pattern)]; - #[doc(hidden)]; use cast; diff --git a/src/libcore/private/finally.rs b/src/libcore/private/finally.rs index 2c27b8ab3a2..50c5ea70cbb 100644 --- a/src/libcore/private/finally.rs +++ b/src/libcore/private/finally.rs @@ -26,10 +26,19 @@ do || { use ops::Drop; use task::{spawn, failing}; +#[cfg(stage0)] pub trait Finally { fn finally(&self, +dtor: &fn()) -> T; } +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] +pub trait Finally { + fn finally(&self, dtor: &fn()) -> T; +} + +#[cfg(stage0)] impl &fn() -> T: Finally { // FIXME #4518: Should not require a mode here fn finally(&self, +dtor: &fn()) -> T { @@ -41,6 +50,19 @@ impl &fn() -> T: Finally { } } +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] +impl &fn() -> T: Finally { + fn finally(&self, dtor: &fn()) -> T { + let _d = Finallyalizer { + dtor: dtor + }; + + (*self)() + } +} + struct Finallyalizer { dtor: &fn() } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index fb82c07da04..ad0bcb5cff8 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -10,9 +10,6 @@ //! Unsafe pointer utility functions -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cast; use cmp::{Eq, Ord}; use libc; diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index 50232f99f85..452ab945251 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -10,10 +10,6 @@ //! Random number generation -// NB: transitional, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use int; use prelude::*; use str; diff --git a/src/libcore/reflect.rs b/src/libcore/reflect.rs index dcbb7067670..de94100d7a5 100644 --- a/src/libcore/reflect.rs +++ b/src/libcore/reflect.rs @@ -14,9 +14,6 @@ Runtime type reflection */ -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use intrinsic::{TyDesc, get_tydesc, visit_tydesc, TyVisitor}; use libc::c_void; use sys; diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index 1f04f9e77a9..a47bad008b8 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -14,9 +14,6 @@ More runtime type reflection */ -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cast::transmute; use cast; use char; diff --git a/src/libcore/result.rs b/src/libcore/result.rs index d04667698fd..7f151317378 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -12,9 +12,6 @@ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cmp; use cmp::Eq; use either; diff --git a/src/libcore/rt.rs b/src/libcore/rt.rs index f9de0bc91fd..33d76cb3c68 100644 --- a/src/libcore/rt.rs +++ b/src/libcore/rt.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; //! Runtime calls emitted by the compiler. use cast::transmute; diff --git a/src/libcore/run.rs b/src/libcore/run.rs index c10eacc7a0a..e44bd2aab81 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; #[allow(structural_records)]; //! Process spawning diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs index 17921a1a1b0..2e24df86c78 100644 --- a/src/libcore/stackwalk.rs +++ b/src/libcore/stackwalk.rs @@ -11,12 +11,7 @@ #[doc(hidden)]; // FIXME #3538 #[legacy_modes]; // tjc: remove after snapshot - -// NB: transitionary, de-mode-ing. -// FIXME #4425: Can't forbid this because frame_address needs a deprecated -// mode. #[allow(deprecated_mode)]; -#[forbid(deprecated_pattern)]; use cast::reinterpret_cast; use ptr::offset; diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 64695be21d5..9b25f92ede2 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -17,9 +17,6 @@ * some heavy-duty uses, try std::rope. */ -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use at_vec; use cast; use char; @@ -2314,6 +2311,21 @@ impl &str: StrSlice { pure fn char_at(i: uint) -> char { char_at(self, i) } } +pub trait OwnedStr { + fn push_str(&mut self, v: &str); + fn push_char(&mut self, c: char); +} + +pub impl ~str : OwnedStr { + fn push_str(&mut self, v: &str) { + push_str(self, v); + } + + fn push_char(&mut self, c: char) { + push_char(self, c); + } +} + #[cfg(test)] mod tests { use char; diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 914eccd3d86..1571e645117 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -10,10 +10,6 @@ //! Misc low level stuff -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cast; use cmp::{Eq, Ord}; use gc; diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs index d276f0c6ea9..9240a67c69a 100644 --- a/src/libcore/task/mod.rs +++ b/src/libcore/task/mod.rs @@ -8,11 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -// tjc: Deprecated modes allowed because of function arg issue -// in task::spawn. Re-forbid after snapshot. -#[forbid(deprecated_pattern)]; - /*! * Task management. * diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index c88587067c1..22a0c870de6 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -71,7 +71,6 @@ ****************************************************************************/ #[doc(hidden)]; // FIXME #3538 -#[warn(deprecated_mode)]; use cast; use container::Map; diff --git a/src/libcore/to_bytes.rs b/src/libcore/to_bytes.rs index 84e5140d8ed..b4647d0c621 100644 --- a/src/libcore/to_bytes.rs +++ b/src/libcore/to_bytes.rs @@ -14,16 +14,12 @@ The `ToBytes` and `IterBytes` traits */ -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use io; use io::Writer; use option::{None, Option, Some}; use str; -pub type Cb = fn(buf: &[const u8]) -> bool; +pub type Cb = &fn(buf: &[const u8]) -> bool; /** * A trait to implement in order to make a type hashable; diff --git a/src/libcore/to_str.rs b/src/libcore/to_str.rs index 0e46b4fd004..d98e341eab8 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -14,10 +14,6 @@ The `ToStr` trait for converting to strings */ -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use kinds::Copy; use str; use vec; diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index c497a2f3c7f..484fc1a5a27 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -8,10 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - //! Operations on tuples use cmp::{Eq, Ord}; diff --git a/src/libcore/unicode.rs b/src/libcore/unicode.rs index dedd5d12c55..ff3b908186a 100644 --- a/src/libcore/unicode.rs +++ b/src/libcore/unicode.rs @@ -9,9 +9,6 @@ // except according to those terms. #[doc(hidden)]; // FIXME #3538 -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; pub mod general_category { pub pure fn Cc(c: char) -> bool { diff --git a/src/libcore/util.rs b/src/libcore/util.rs index 8dff492e634..3b6a134bc52 100644 --- a/src/libcore/util.rs +++ b/src/libcore/util.rs @@ -14,10 +14,6 @@ Miscellaneous helpers for common patterns. */ -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; - use cmp::Eq; use prelude::*; diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 7846d3d0302..9ad5d9f32da 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -10,8 +10,6 @@ //! Vectors -#[forbid(deprecated_mode)]; -#[forbid(deprecated_pattern)]; #[warn(non_camel_case_types)]; use container::{Container, Mutable}; @@ -841,14 +839,37 @@ pub pure fn map2(v0: &[T], v1: &[U], u } -/** - * Apply a function to each element of a vector and return the results - * - * If function `f` returns `none` then that element is excluded from - * the resulting vector. - */ -pub pure fn filter_map(v: &[T], f: fn(t: &T) -> Option) - -> ~[U] { +pub fn filter_map( + v: ~[T], + f: fn(t: T) -> Option) -> ~[U] +{ + /*! + * + * Apply a function to each element of a vector and return the results. + * Consumes the input vector. If function `f` returns `None` then that + * element is excluded from the resulting vector. + */ + + let mut result = ~[]; + do consume(v) |_, elem| { + match f(elem) { + None => {} + Some(result_elem) => { result.push(result_elem); } + } + } + result +} + +pub pure fn filter_mapped( + v: &[T], + f: fn(t: &T) -> Option) -> ~[U] +{ + /*! + * + * Like `filter_map()`, but operates on a borrowed slice + * and does not consume the input. + */ + let mut result = ~[]; for each(v) |elem| { match f(elem) { @@ -1695,7 +1716,7 @@ pub trait ImmutableVector { fn map_r(&self, f: fn(x: &T) -> U) -> ~[U]; pure fn alli(&self, f: fn(uint, t: &T) -> bool) -> bool; pure fn flat_map(&self, f: fn(t: &T) -> ~[U]) -> ~[U]; - pure fn filter_map(&self, f: fn(t: &T) -> Option) -> ~[U]; + pure fn filter_mapped(&self, f: fn(t: &T) -> Option) -> ~[U]; } /// Extension methods for vectors @@ -1758,8 +1779,8 @@ impl &[T]: ImmutableVector { * the resulting vector. */ #[inline] - pure fn filter_map(&self, f: fn(t: &T) -> Option) -> ~[U] { - filter_map(*self, f) + pure fn filter_mapped(&self, f: fn(t: &T) -> Option) -> ~[U] { + filter_mapped(*self, f) } } @@ -2439,10 +2460,14 @@ mod tests { pure fn is_equal(x: &uint, y:&uint) -> bool { return *x == *y; } - fn square_if_odd(n: &uint) -> Option { + fn square_if_odd_r(n: &uint) -> Option { return if *n % 2u == 1u { Some(*n * *n) } else { None }; } + fn square_if_odd_v(n: uint) -> Option { + return if n % 2u == 1u { Some(n * n) } else { None }; + } + fn add(x: uint, y: &uint) -> uint { return x + *y; } #[test] @@ -2775,17 +2800,17 @@ mod tests { } #[test] - fn test_filter_map() { + fn test_filter_mapped() { // Test on-stack filter-map. let mut v = ~[1u, 2u, 3u]; - let mut w = filter_map(v, square_if_odd); + let mut w = filter_mapped(v, square_if_odd_r); assert (len(w) == 2u); assert (w[0] == 1u); assert (w[1] == 9u); // Test on-heap filter-map. v = ~[1u, 2u, 3u, 4u, 5u]; - w = filter_map(v, square_if_odd); + w = filter_mapped(v, square_if_odd_r); assert (len(w) == 3u); assert (w[0] == 1u); assert (w[1] == 9u); @@ -2804,7 +2829,46 @@ mod tests { let all_odd2: ~[int] = ~[]; let mix: ~[int] = ~[9, 2, 6, 7, 1, 0, 0, 3]; let mix_dest: ~[int] = ~[1, 3, 0, 0]; - assert (filter_map(all_even, halve) == map(all_even, halve_for_sure)); + assert (filter_mapped(all_even, halve) == + map(all_even, halve_for_sure)); + assert (filter_mapped(all_odd1, halve) == ~[]); + assert (filter_mapped(all_odd2, halve) == ~[]); + assert (filter_mapped(mix, halve) == mix_dest); + } + + #[test] + fn test_filter_map() { + // Test on-stack filter-map. + let mut v = ~[1u, 2u, 3u]; + let mut w = filter_map(v, square_if_odd_v); + assert (len(w) == 2u); + assert (w[0] == 1u); + assert (w[1] == 9u); + + // Test on-heap filter-map. + v = ~[1u, 2u, 3u, 4u, 5u]; + w = filter_map(v, square_if_odd_v); + assert (len(w) == 3u); + assert (w[0] == 1u); + assert (w[1] == 9u); + assert (w[2] == 25u); + + fn halve(i: int) -> Option { + if i % 2 == 0 { + return option::Some::(i / 2); + } else { + return option::None::; + } + } + fn halve_for_sure(i: &int) -> int { return *i / 2; } + let all_even: ~[int] = ~[0, 2, 8, 6]; + let all_even0: ~[int] = copy all_even; + let all_odd1: ~[int] = ~[1, 7, 3]; + let all_odd2: ~[int] = ~[]; + let mix: ~[int] = ~[9, 2, 6, 7, 1, 0, 0, 3]; + let mix_dest: ~[int] = ~[1, 3, 0, 0]; + assert (filter_map(all_even, halve) == + map(all_even0, halve_for_sure)); assert (filter_map(all_odd1, halve) == ~[]); assert (filter_map(all_odd2, halve) == ~[]); assert (filter_map(mix, halve) == mix_dest); @@ -3664,10 +3728,10 @@ mod tests { #[ignore(windows)] #[should_fail] #[allow(non_implicitly_copyable_typarams)] - fn test_filter_map_fail() { + fn test_filter_mapped_fail() { let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; let mut i = 0; - do filter_map(v) |_elt| { + do filter_mapped(v) |_elt| { if i == 2 { die!() } diff --git a/src/librustc/front/config.rs b/src/librustc/front/config.rs index a7c071919ff..cf75db3a900 100644 --- a/src/librustc/front/config.rs +++ b/src/librustc/front/config.rs @@ -64,12 +64,13 @@ fn filter_view_item(cx: ctxt, &&view_item: @ast::view_item } fn fold_mod(cx: ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { - let filtered_items = vec::filter_map(m.items, |a| filter_item(cx, *a)); - let filtered_view_items = vec::filter_map(m.view_items, - |a| filter_view_item(cx, *a)); + let filtered_items = + m.items.filter_mapped(|a| filter_item(cx, *a)); + let filtered_view_items = + m.view_items.filter_mapped(|a| filter_view_item(cx, *a)); ast::_mod { view_items: filtered_view_items.map(|x| fld.fold_view_item(*x)), - items: filtered_items.filter_map(|x| fld.fold_item(*x)), + items: vec::filter_map(filtered_items, |x| fld.fold_item(x)) } } @@ -85,10 +86,10 @@ fn fold_foreign_mod( nm: ast::foreign_mod, fld: fold::ast_fold ) -> ast::foreign_mod { - let filtered_items = vec::filter_map(nm.items, - |a| filter_foreign_item(cx, *a)); - let filtered_view_items = vec::filter_map(nm.view_items, - |a| filter_view_item(cx, *a)); + let filtered_items = + nm.items.filter_mapped(|a| filter_foreign_item(cx, *a)); + let filtered_view_items = + nm.view_items.filter_mapped(|a| filter_view_item(cx, *a)); ast::foreign_mod { sort: nm.sort, abi: nm.abi, @@ -136,7 +137,8 @@ fn fold_block( b: ast::blk_, fld: fold::ast_fold ) -> ast::blk_ { - let filtered_stmts = vec::filter_map(b.stmts, |a| filter_stmt(cx, *a)); + let filtered_stmts = + b.stmts.filter_mapped(|a| filter_stmt(cx, *a)); ast::blk_ { view_items: /*bad*/copy b.view_items, stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)), @@ -183,8 +185,9 @@ pub fn metas_in_cfg(cfg: ast::crate_cfg, // Pull the inner meta_items from the #[cfg(meta_item, ...)] attributes, // so we can match against them. This is the list of configurations for // which the item is valid - let cfg_metas = vec::concat(vec::filter_map(cfg_metas, - |i| attr::get_meta_item_list(*i))); + let cfg_metas = + vec::concat( + vec::filter_map(cfg_metas, |i| attr::get_meta_item_list(i))); let has_cfg_metas = vec::len(cfg_metas) > 0u; if !has_cfg_metas { return true; } diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 91eb8148bb7..9fa1cea3e10 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -168,9 +168,11 @@ fn is_test_fn(i: @ast::item) -> bool { fn is_ignored(cx: test_ctxt, i: @ast::item) -> bool { let ignoreattrs = attr::find_attrs_by_name(i.attrs, "ignore"); let ignoreitems = attr::attr_metas(ignoreattrs); - let cfg_metas = vec::concat(vec::filter_map(ignoreitems, - |i| attr::get_meta_item_list(*i))); return if !ignoreitems.is_empty() { + let cfg_metas = + vec::concat( + vec::filter_map(ignoreitems, + |i| attr::get_meta_item_list(i))); config::metas_in_cfg(/*bad*/copy cx.crate.node.config, cfg_metas) } else { false @@ -277,7 +279,7 @@ fn mk_std(cx: test_ctxt) -> @ast::view_item { } fn mk_tests(cx: test_ctxt) -> @ast::item { - let ret_ty = mk_test_desc_vec_ty(cx); + let ret_ty = mk_test_desc_and_fn_vec_ty(cx); let decl = ast::fn_decl { inputs: ~[], @@ -286,7 +288,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item { }; // The vector of test_descs for this crate - let test_descs = mk_test_desc_vec(cx); + let test_descs = mk_test_desc_and_fn_vec(cx); let body_: ast::blk_ = default_block(~[], option::Some(test_descs), cx.sess.next_node_id()); @@ -327,19 +329,21 @@ fn mk_path(cx: test_ctxt, +path: ~[ast::ident]) -> @ast::path { } } -// The ast::Ty of ~[std::test::test_desc] -fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::Ty { - let test_desc_ty_path = +// The ast::Ty of ~[std::test::TestDescAndFn] +fn mk_test_desc_and_fn_vec_ty(cx: test_ctxt) -> @ast::Ty { + let test_desc_and_fn_ty_path = mk_path(cx, ~[cx.sess.ident_of(~"test"), - cx.sess.ident_of(~"TestDesc")]); + cx.sess.ident_of(~"TestDescAndFn")]); - let test_desc_ty = ast::Ty { + let test_desc_and_fn_ty = ast::Ty { id: cx.sess.next_node_id(), - node: ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()), + node: ast::ty_path(test_desc_and_fn_ty_path, + cx.sess.next_node_id()), span: dummy_sp(), }; - let vec_mt = ast::mt {ty: @test_desc_ty, mutbl: ast::m_imm}; + let vec_mt = ast::mt {ty: @test_desc_and_fn_ty, + mutbl: ast::m_imm}; let inner_ty = @ast::Ty { id: cx.sess.next_node_id(), @@ -354,11 +358,11 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::Ty { } } -fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr { +fn mk_test_desc_and_fn_vec(cx: test_ctxt) -> @ast::expr { debug!("building test vector from %u tests", cx.testfns.len()); let mut descs = ~[]; for cx.testfns.each |test| { - descs.push(mk_test_desc_rec(cx, *test)); + descs.push(mk_test_desc_and_fn_rec(cx, *test)); } let inner_expr = @ast::expr { @@ -376,7 +380,7 @@ fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr { } } -fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr { +fn mk_test_desc_and_fn_rec(cx: test_ctxt, test: test) -> @ast::expr { let span = test.span; let path = /*bad*/copy test.path; @@ -407,23 +411,6 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr { expr: @name_expr, }); - let fn_path = path_node_global(path); - - let fn_expr = ast::expr { - id: cx.sess.next_node_id(), - callee_id: cx.sess.next_node_id(), - node: ast::expr_path(fn_path), - span: span, - }; - - let fn_wrapper_expr = mk_test_wrapper(cx, fn_expr, span); - - let fn_field = nospan(ast::field_ { - mutbl: ast::m_imm, - ident: cx.sess.ident_of(~"testfn"), - expr: fn_wrapper_expr, - }); - let ignore_lit: ast::lit = nospan(ast::lit_bool(test.ignore)); let ignore_expr = ast::expr { @@ -460,62 +447,52 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr { let desc_rec_ = ast::expr_struct( test_desc_path, - ~[name_field, fn_field, ignore_field, fail_field], + ~[name_field, ignore_field, fail_field], option::None ); - let desc_rec = ast::expr { + let desc_rec = @ast::expr { id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(), node: desc_rec_, span: span, }; - return @desc_rec; -} + let desc_field = nospan(ast::field_ { + mutbl: ast::m_imm, + ident: cx.sess.ident_of(~"desc"), + expr: desc_rec + }); -// Produces a bare function that wraps the test function + let fn_path = path_node_global(path); -// FIXME (#1281): This can go away once fn is the type of bare function. -fn mk_test_wrapper(cx: test_ctxt, - +fn_path_expr: ast::expr, - span: span) -> @ast::expr { - let call_expr = ast::expr { + let fn_expr = @ast::expr { id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(), - node: ast::expr_call(@fn_path_expr, ~[], false), + node: ast::expr_path(fn_path), span: span, }; - let call_stmt: ast::stmt = nospan( - ast::stmt_semi(@call_expr, cx.sess.next_node_id())); - - let wrapper_decl = ast::fn_decl { - inputs: ~[], - output: @ast::Ty { - id: cx.sess.next_node_id(), - node: ast::ty_nil, - span: span, - }, - cf: ast::return_val - }; - - let wrapper_body = nospan(ast::blk_ { - view_items: ~[], - stmts: ~[@call_stmt], - expr: option::None, - id: cx.sess.next_node_id(), - rules: ast::default_blk + let fn_field = nospan(ast::field_ { + mutbl: ast::m_imm, + ident: cx.sess.ident_of(~"testfn"), + expr: fn_expr, }); - let wrapper_expr = ast::expr { + let test_desc_and_fn_path = + mk_path(cx, ~[cx.sess.ident_of(~"test"), + cx.sess.ident_of(~"TestDescAndFn")]); + + let desc_and_fn_rec = @ast::expr { id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(), - node: ast::expr_fn(ast::ProtoBare, wrapper_decl, wrapper_body, @()), - span: span + node: ast::expr_struct(test_desc_and_fn_path, + ~[fn_field, desc_field], + option::None), + span: span, }; - return @wrapper_expr; + return desc_and_fn_rec; } fn mk_main(cx: test_ctxt) -> @ast::item { @@ -567,7 +544,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr { let args_call_expr = ast::expr { id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(), - node: ast::expr_call(@args_path_expr, ~[], false), + node: ast::expr_call(@args_path_expr, ~[], ast::NoSugar), span: dummy_sp(), }; @@ -584,7 +561,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr { let test_call_expr = ast::expr { id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(), - node: ast::expr_call(@test_path_expr, ~[], false), + node: ast::expr_call(@test_path_expr, ~[], ast::NoSugar), span: dummy_sp(), }; @@ -606,7 +583,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr { node: ast::expr_call( @test_main_path_expr, ~[@args_call_expr, @test_call_expr], - false + ast::NoSugar ), span: dummy_sp(), }; diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 9a6a2f7e954..67498ad5aaf 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -586,10 +586,8 @@ 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_fn(ref f) => (*f).sig.inputs.map(|a| a.ty), - - // Nullary enum variant. - _ => ~[], + ty::ty_bare_fn(ref f) => f.sig.inputs.map(|a| a.ty), + _ => ~[], // Nullary enum variant. }; match variant_disr_val(item) { Some(val) => { disr_val = val; } @@ -705,11 +703,12 @@ pub fn get_trait_methods(intr: @ident_interner, cdata: cmd, id: ast::node_id, let ty = doc_type(mth, tcx, cdata); let def_id = item_def_id(mth, cdata); let fty = match ty::get(ty).sty { - ty::ty_fn(ref f) => (/*bad*/copy *f), - _ => { - tcx.diag.handler().bug( - ~"get_trait_methods: id has non-function type"); - } }; + ty::ty_bare_fn(ref f) => copy *f, + _ => { + tcx.diag.handler().bug( + ~"get_trait_methods: id has non-function type"); + } + }; let self_ty = get_self_ty(mth); result.push({ident: name, tps: bounds, fty: fty, self_ty: self_ty, vis: ast::public, def_id: def_id}); @@ -734,14 +733,13 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd, let name = item_name(intr, mth); let ty = doc_type(mth, tcx, cdata); - let fty; - match ty::get(ty).sty { - ty::ty_fn(ref f) => fty = (/*bad*/copy *f), + let fty = match ty::get(ty).sty { + ty::ty_bare_fn(ref f) => copy *f, _ => { tcx.diag.handler().bug(~"get_provided_trait_methods(): id \ has non-function type"); } - } + }; let self_ty = get_self_ty(mth); let ty_method = {ident: name, tps: bounds, fty: fty, self_ty: self_ty, diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 072b974d042..b0a424447b3 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -768,8 +768,9 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder, encode_name(ecx, ebml_w, mty.ident); encode_type_param_bounds(ebml_w, ecx, (*ty_m).tps); - encode_type(ecx, ebml_w, ty::mk_fn(tcx, /*bad*/copy mty.fty)); - encode_family(ebml_w, purity_fn_family(mty.fty.meta.purity)); + encode_type(ecx, ebml_w, + ty::mk_bare_fn(tcx, copy mty.fty)); + encode_family(ebml_w, purity_fn_family(mty.fty.purity)); encode_self_type(ebml_w, mty.self_ty); encode_method_sort(ebml_w, 'r'); ebml_w.end_tag(); @@ -781,8 +782,9 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder, encode_def_id(ebml_w, local_def(m.id)); encode_name(ecx, ebml_w, mty.ident); encode_type_param_bounds(ebml_w, ecx, m.tps); - encode_type(ecx, ebml_w, ty::mk_fn(tcx, /*bad*/copy mty.fty)); - encode_family(ebml_w, purity_fn_family(mty.fty.meta.purity)); + encode_type(ecx, ebml_w, + ty::mk_bare_fn(tcx, copy mty.fty)); + encode_family(ebml_w, purity_fn_family(mty.fty.purity)); encode_self_type(ebml_w, mty.self_ty); encode_method_sort(ebml_w, 'p'); ebml_w.end_tag(); diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index ea13325ad49..3f989339e27 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -17,8 +17,6 @@ use core::prelude::*; use middle::ty; -use middle::ty::{FnTyBase, FnMeta, FnSig, arg, creader_cache_key, field}; -use middle::ty::{substs}; use core::io; use core::str; @@ -124,17 +122,12 @@ fn parse_path(st: @pstate) -> @ast::path { }; } -fn parse_ty_rust_fn(st: @pstate, conv: conv_did) -> ty::t { - return ty::mk_fn(st.tcx, parse_ty_fn(st, conv)); -} - -fn parse_proto(st: @pstate) -> ast::Proto { +fn parse_sigil(st: @pstate) -> ast::Sigil { match next(st) { - '_' => ast::ProtoBare, - '@' => ast::ProtoBox, - '~' => ast::ProtoUniq, - '&' => ast::ProtoBorrowed, - _ => die!(~"parse_proto(): bad input") + '@' => ast::ManagedSigil, + '~' => ast::OwnedSigil, + '&' => ast::BorrowedSigil, + c => st.tcx.sess.bug(fmt!("parse_sigil(): bad input '%c'", c)) } } @@ -152,7 +145,7 @@ fn parse_vstore(st: @pstate) -> ty::vstore { '~' => ty::vstore_uniq, '@' => ty::vstore_box, '&' => ty::vstore_slice(parse_region(st)), - _ => die!(~"parse_vstore: bad input") + c => st.tcx.sess.bug(fmt!("parse_vstore(): bad input '%c'", c)) } } @@ -166,7 +159,7 @@ fn parse_substs(st: @pstate, conv: conv_did) -> ty::substs { while peek(st) != ']' { params.push(parse_ty(st, conv)); } st.pos = st.pos + 1u; - return substs { + return ty::substs { self_r: self_r, self_ty: self_ty, tps: params @@ -316,19 +309,24 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t { return ty::mk_tup(st.tcx, params); } 'f' => { - parse_ty_rust_fn(st, conv) + return ty::mk_closure(st.tcx, parse_closure_ty(st, conv)); + } + 'F' => { + return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, conv)); } 'Y' => return ty::mk_type(st.tcx), 'C' => { - let proto = parse_proto(st); - return ty::mk_opaque_closure_ptr(st.tcx, proto); + let sigil = parse_sigil(st); + return ty::mk_opaque_closure_ptr(st.tcx, sigil); } '#' => { let pos = parse_hex(st); assert (next(st) == ':'); let len = parse_hex(st); assert (next(st) == '#'); - let key = creader_cache_key { cnum: st.crate, pos: pos, len: len }; + let key = ty::creader_cache_key {cnum: st.crate, + pos: pos, + len: len }; match st.tcx.rcache.find(&key) { Some(tt) => return tt, None => { @@ -408,6 +406,13 @@ fn parse_purity(c: char) -> purity { } } +fn parse_abi(c: char) -> Abi { + match c { + 'r' => ast::RustAbi, + _ => die!(fmt!("parse_abi: bad ABI '%c'", c)) + } +} + fn parse_onceness(c: char) -> ast::Onceness { match c { 'o' => ast::Once, @@ -430,12 +435,33 @@ fn parse_mode(st: @pstate) -> ast::mode { return m; } -fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::FnTy { - let proto = parse_proto(st); +fn parse_closure_ty(st: @pstate, conv: conv_did) -> ty::ClosureTy { + let sigil = parse_sigil(st); let purity = parse_purity(next(st)); let onceness = parse_onceness(next(st)); let region = parse_region(st); - let bounds = parse_bounds(st, conv); + let sig = parse_sig(st, conv); + ty::ClosureTy { + purity: purity, + sigil: sigil, + onceness: onceness, + region: region, + sig: sig + } +} + +fn parse_bare_fn_ty(st: @pstate, conv: conv_did) -> ty::BareFnTy { + let purity = parse_purity(next(st)); + let abi = parse_abi(next(st)); + let sig = parse_sig(st, conv); + ty::BareFnTy { + purity: purity, + abi: abi, + sig: sig + } +} + +fn parse_sig(st: @pstate, conv: conv_did) -> ty::FnSig { assert (next(st) == '['); let mut inputs: ~[ty::arg] = ~[]; while peek(st) != ']' { @@ -444,18 +470,9 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::FnTy { } st.pos += 1u; // eat the ']' let ret_ty = parse_ty(st, conv); - return FnTyBase { - meta: FnMeta {purity: purity, - proto: proto, - onceness: onceness, - bounds: bounds, - region: region}, - sig: FnSig {inputs: inputs, - output: ret_ty} - }; + ty::FnSig {inputs: inputs, output: ret_ty} } - // Rust metadata parsing pub fn parse_def_id(buf: &[u8]) -> ast::def_id { let mut colon_idx = 0u; diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 0d66862c79f..a87ce02d5a3 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -288,8 +288,13 @@ fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) { } w.write_char(']'); } - ty::ty_fn(ref f) => { - enc_ty_fn(w, cx, (*f)); + ty::ty_closure(ref f) => { + w.write_char('f'); + enc_closure_ty(w, cx, f); + } + ty::ty_bare_fn(ref f) => { + w.write_char('F'); + enc_bare_fn_ty(w, cx, f); } ty::ty_infer(_) => { cx.diag.handler().bug(~"Cannot encode inference variable types"); @@ -306,7 +311,7 @@ fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) { ty::ty_type => w.write_char('Y'), ty::ty_opaque_closure_ptr(p) => { w.write_str(&"C&"); - enc_proto(w, p); + enc_sigil(w, p); } ty::ty_opaque_box => w.write_char('B'), ty::ty_struct(def, ref substs) => { @@ -325,13 +330,11 @@ fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) { } } -fn enc_proto(w: io::Writer, proto: Proto) { - w.write_str(&"f"); - match proto { - ProtoBare => w.write_str(&"_"), - ProtoBox => w.write_str(&"@"), - ProtoUniq => w.write_str(&"~"), - ProtoBorrowed => w.write_str(&"&"), +fn enc_sigil(w: io::Writer, sigil: Sigil) { + match sigil { + ManagedSigil => w.write_str("@"), + OwnedSigil => w.write_str("~"), + BorrowedSigil => w.write_str("&"), } } @@ -357,6 +360,12 @@ fn enc_purity(w: io::Writer, p: purity) { } } +fn enc_abi(w: io::Writer, a: Abi) { + match a { + RustAbi => w.write_char('r'), + } +} + fn enc_onceness(w: io::Writer, o: Onceness) { match o { Once => w.write_char('o'), @@ -364,18 +373,27 @@ fn enc_onceness(w: io::Writer, o: Onceness) { } } -fn enc_ty_fn(w: io::Writer, cx: @ctxt, ft: ty::FnTy) { - enc_proto(w, ft.meta.proto); - enc_purity(w, ft.meta.purity); - enc_onceness(w, ft.meta.onceness); - enc_region(w, cx, ft.meta.region); - enc_bounds(w, cx, ft.meta.bounds); +fn enc_bare_fn_ty(w: io::Writer, cx: @ctxt, ft: &ty::BareFnTy) { + enc_purity(w, ft.purity); + enc_abi(w, ft.abi); + enc_fn_sig(w, cx, &ft.sig); +} + +fn enc_closure_ty(w: io::Writer, cx: @ctxt, ft: &ty::ClosureTy) { + enc_sigil(w, ft.sigil); + enc_purity(w, ft.purity); + enc_onceness(w, ft.onceness); + enc_region(w, cx, ft.region); + enc_fn_sig(w, cx, &ft.sig); +} + +fn enc_fn_sig(w: io::Writer, cx: @ctxt, fsig: &ty::FnSig) { w.write_char('['); - for ft.sig.inputs.each |arg| { + for fsig.inputs.each |arg| { enc_arg(w, cx, *arg); } w.write_char(']'); - enc_ty(w, cx, ft.sig.output); + enc_ty(w, cx, fsig.output); } pub fn enc_bounds(w: io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) { diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 9b2d51289ad..dfc26000116 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -221,18 +221,19 @@ impl check_loan_ctxt { let callee_ty = ty::node_id_to_type(tcx, callee_id); match ty::get(callee_ty).sty { - ty::ty_fn(ref fn_ty) => { - match fn_ty.meta.purity { - ast::pure_fn => return, // case (c) above - ast::impure_fn | ast::unsafe_fn | ast::extern_fn => { - self.report_purity_error( - pc, callee_span, - fmt!("access to %s function", - fn_ty.meta.purity.to_str())); - } + ty::ty_bare_fn(ty::BareFnTy {purity: purity, _}) | + ty::ty_closure(ty::ClosureTy {purity: purity, _}) => { + match purity { + ast::pure_fn => return, // case (c) above + ast::impure_fn | ast::unsafe_fn | ast::extern_fn => { + self.report_purity_error( + pc, callee_span, + fmt!("access to %s function", + purity.to_str())); + } + } } - } - _ => return, // case (d) above + _ => return, // case (d) above } } @@ -240,8 +241,11 @@ impl check_loan_ctxt { // The expression must be an expr_fn(*) or expr_fn_block(*) fn is_stack_closure(id: ast::node_id) -> bool { let fn_ty = ty::node_id_to_type(self.tcx(), id); - let proto = ty::ty_fn_proto(fn_ty); - return proto == ast::ProtoBorrowed; + match ty::get(fn_ty).sty { + ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil, + _}) => true, + _ => false + } } fn is_allowed_pure_arg(expr: @ast::expr) -> bool { @@ -564,17 +568,27 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk, { let is_stack_closure = self.is_stack_closure(id); let fty = ty::node_id_to_type(self.tcx(), id); - let fty_proto = ty::ty_fn_proto(fty); - check_moves_from_captured_variables(self, id, fty_proto); + let declared_purity; + match fk { + visit::fk_item_fn(*) | visit::fk_method(*) | + visit::fk_dtor(*) => { + declared_purity = ty::ty_fn_purity(fty); + } + + visit::fk_anon(*) | visit::fk_fn_block(*) => { + let fty_sigil = ty::ty_closure_sigil(fty); + check_moves_from_captured_variables(self, id, fty_sigil); + declared_purity = ty::determine_inherited_purity( + copy self.declared_purity, ty::ty_fn_purity(fty), + fty_sigil); + } + } debug!("purity on entry=%?", copy self.declared_purity); do save_and_restore(&mut(self.declared_purity)) { do save_and_restore(&mut(self.fn_args)) { - self.declared_purity = ty::determine_inherited_purity( - copy self.declared_purity, - ty::ty_fn_purity(fty), - fty_proto); + self.declared_purity = declared_purity; match fk { visit::fk_anon(*) | @@ -608,10 +622,10 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk, fn check_moves_from_captured_variables(&&self: check_loan_ctxt, id: ast::node_id, - fty_proto: ast::Proto) + fty_sigil: ast::Sigil) { - match fty_proto { - ast::ProtoBox | ast::ProtoUniq => { + match fty_sigil { + ast::ManagedSigil | ast::OwnedSigil => { let cap_vars = self.bccx.capture_map.get(&id); for cap_vars.each |cap_var| { match cap_var.mode { @@ -646,7 +660,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk, } } - ast::ProtoBorrowed | ast::ProtoBare => {} + ast::BorrowedSigil => {} } } } diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 69ace0d7797..ad46d3b6f4d 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -150,7 +150,7 @@ pub fn check_expr(sess: Session, } } } - expr_call(callee, _, false) => { + expr_call(callee, _, NoSugar) => { match def_map.find(&callee.id) { Some(def_struct(*)) => {} // OK. Some(def_variant(*)) => {} // OK. diff --git a/src/librustc/middle/check_loop.rs b/src/librustc/middle/check_loop.rs index 11c557f0249..38450de6b54 100644 --- a/src/librustc/middle/check_loop.rs +++ b/src/librustc/middle/check_loop.rs @@ -39,8 +39,8 @@ pub fn check_crate(tcx: ty::ctxt, crate: @crate) { (v.visit_block)((*b), {in_loop: false, can_ret: false}, v); } expr_loop_body(@expr {node: expr_fn_block(_, ref b), _}) => { - let proto = ty::ty_fn_proto(ty::expr_ty(tcx, e)); - let blk = (proto == ProtoBorrowed); + let sigil = ty::ty_closure_sigil(ty::expr_ty(tcx, e)); + let blk = (sigil == BorrowedSigil); (v.visit_block)((*b), {in_loop: true, can_ret: blk}, v); } expr_break(_) => { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 978aaacb18a..6f9fe1edca5 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -100,7 +100,7 @@ pub fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) { } _ => { /* We assume only enum types can be uninhabited */ } } - let arms = vec::concat(vec::filter_map((*arms), unguarded_pat)); + let arms = vec::concat(arms.filter_mapped(unguarded_pat)); check_exhaustive(cx, ex.span, arms); } _ => () @@ -255,7 +255,8 @@ pub fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: &[@pat]) -> useful { } } Some(ref ctor) => { - match is_useful(cx, vec::filter_map(m, |r| default(cx, copy *r)), + match is_useful(cx, + vec::filter_map(m, |r| default(cx, r)), vec::tail(v)) { useful_ => useful(left_ty, (/*bad*/copy *ctor)), ref u => (/*bad*/copy *u) @@ -277,8 +278,7 @@ pub fn is_useful_specialized(cx: @MatchCheckCtxt, arity: uint, lty: ty::t) -> useful { - let ms = vec::filter_map(m, |r| specialize(cx, *r, - ctor, arity, lty)); + let ms = m.filter_mapped(|r| specialize(cx, *r, ctor, arity, lty)); let could_be_useful = is_useful( cx, ms, specialize(cx, v, ctor, arity, lty).get()); match could_be_useful { @@ -387,9 +387,9 @@ pub fn missing_ctor(cx: @MatchCheckCtxt, ty::ty_unboxed_vec(*) | ty::ty_evec(*) => { // Find the lengths and tails of all vector patterns. - let vec_pat_lens = do m.filter_map |r| { - match /*bad*/copy r[0].node { - pat_vec(elems, tail) => { + let vec_pat_lens = do m.filter_mapped |r| { + match r[0].node { + pat_vec(ref elems, ref tail) => { Some((elems.len(), tail.is_some())) } _ => None diff --git a/src/librustc/middle/freevars.rs b/src/librustc/middle/freevars.rs index 5d65aba2a4d..e6091077210 100644 --- a/src/librustc/middle/freevars.rs +++ b/src/librustc/middle/freevars.rs @@ -48,10 +48,8 @@ fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk) let walk_expr = fn@(expr: @ast::expr, &&depth: int, v: visit::vt) { match expr.node { - ast::expr_fn(proto, _, _, _) => { - if proto != ast::ProtoBare { - visit::visit_expr(expr, depth + 1, v); - } + ast::expr_fn(_, _, _, _) => { + visit::visit_expr(expr, depth + 1, v); } ast::expr_fn_block(*) => { visit::visit_expr(expr, depth + 1, v); diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 8abafe6b079..35d5595fefd 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -150,11 +150,23 @@ fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) { } let fty = ty::node_id_to_type(cx.tcx, id); - match ty::ty_fn_proto(fty) { - ProtoUniq => b(check_for_uniq), - ProtoBox => b(check_for_box), - ProtoBare => b(check_for_bare), - ProtoBorrowed => b(check_for_block), + match ty::get(fty).sty { + ty::ty_closure(ty::ClosureTy {sigil: OwnedSigil, _}) => { + b(check_for_uniq) + } + ty::ty_closure(ty::ClosureTy {sigil: ManagedSigil, _}) => { + b(check_for_box) + } + ty::ty_closure(ty::ClosureTy {sigil: BorrowedSigil, _}) => { + b(check_for_block) + } + ty::ty_bare_fn(_) => { + b(check_for_bare) + } + ref s => { + cx.tcx.sess.bug( + fmt!("expect fn type in kind checker, not %?", s)); + } } } @@ -240,42 +252,6 @@ pub fn check_expr(e: @expr, cx: ctx, v: visit::vt) { expr.span, "explicit copy requires a copyable argument"); } - expr_rec(ref fields, def) | expr_struct(_, ref fields, def) => { - match def { - Some(ex) => { - // All noncopyable fields must be overridden - let t = ty::expr_ty(cx.tcx, ex); - let ty_fields = match ty::get(t).sty { - ty::ty_rec(ref f) => { - copy *f - } - ty::ty_struct(did, ref substs) => { - ty::struct_fields(cx.tcx, did, substs) - } - _ => { - cx.tcx.sess.span_bug( - ex.span, - ~"bad base expr type in record") - } - }; - for ty_fields.each |tf| { - // If this field would not be copied, ok. - if fields.any(|f| f.node.ident == tf.ident) { loop; } - - // If this field is copyable, ok. - let kind = ty::type_kind(cx.tcx, tf.mt.ty); - if ty::kind_can_be_copied(kind) { loop; } - - cx.tcx.sess.span_err( - e.span, - fmt!("cannot copy field `%s` of base expression, \ - which has a noncopyable type", - *cx.tcx.sess.intr().get(tf.ident))); - } - } - _ => {} - } - } expr_repeat(element, count_expr, _) => { let count = ty::eval_repeat_count(cx.tcx, count_expr, e.span); if count > 1 { diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 4601941f73a..51bbdfdc19c 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -897,9 +897,10 @@ fn check_fn(tcx: ty::ctxt, fk: visit::fn_kind, decl: ast::fn_decl, fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: ast::fn_decl, span: span, id: ast::node_id) { match ty::get(fn_ty).sty { - ty::ty_fn(ref fn_ty) => { + ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) | + ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) => { let mut counter = 0; - for vec::each2(fn_ty.sig.inputs, decl.inputs) |arg_ty, arg_ast| { + for vec::each2(sig.inputs, decl.inputs) |arg_ty, arg_ast| { counter += 1; debug!("arg %d, ty=%s, mode=%s", counter, @@ -938,13 +939,14 @@ fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: ast::fn_decl, } match ty::get(arg_ty.ty).sty { - ty::ty_fn(*) => { + ty::ty_closure(*) | ty::ty_bare_fn(*) => { let span = arg_ast.ty.span; // Recurse to check fn-type argument match arg_ast.ty.node { - ast::ty_fn(f) => { + ast::ty_closure(@ast::TyClosure{decl: ref d, _}) | + ast::ty_bare_fn(@ast::TyBareFn{decl: ref d, _})=>{ check_fn_deprecated_modes(tcx, arg_ty.ty, - f.decl, span, id); + *d, span, id); } ast::ty_path(*) => { // This is probably a typedef, so we can't @@ -976,10 +978,11 @@ fn check_item_deprecated_modes(tcx: ty::ctxt, it: @ast::item) { match it.node { ast::item_ty(ty, _) => { match ty.node { - ast::ty_fn(f) => { + ast::ty_closure(@ast::TyClosure {decl: ref decl, _}) | + ast::ty_bare_fn(@ast::TyBareFn {decl: ref decl, _}) => { let fn_ty = ty::node_id_to_type(tcx, it.id); check_fn_deprecated_modes( - tcx, fn_ty, f.decl, ty.span, it.id) + tcx, fn_ty, *decl, ty.span, it.id) } _ => () } diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index abe8a64fea5..07de9987096 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -146,63 +146,55 @@ pub enum deref_kind {deref_ptr(ptr_kind), deref_comp(comp_kind)} // pointer adjustment). pub fn opt_deref_kind(t: ty::t) -> Option { match ty::get(t).sty { - ty::ty_uniq(*) | - ty::ty_evec(_, ty::vstore_uniq) | - ty::ty_estr(ty::vstore_uniq) => { - Some(deref_ptr(uniq_ptr)) - } + ty::ty_uniq(*) | + ty::ty_evec(_, ty::vstore_uniq) | + ty::ty_estr(ty::vstore_uniq) | + ty::ty_closure(ty::ClosureTy {sigil: ast::OwnedSigil, _}) => { + Some(deref_ptr(uniq_ptr)) + } - ty::ty_fn(ref f) if (*f).meta.proto == ast::ProtoUniq => { - Some(deref_ptr(uniq_ptr)) - } + ty::ty_rptr(r, mt) | + ty::ty_evec(mt, ty::vstore_slice(r)) => { + Some(deref_ptr(region_ptr(mt.mutbl, r))) + } - ty::ty_rptr(r, mt) | - ty::ty_evec(mt, ty::vstore_slice(r)) => { - Some(deref_ptr(region_ptr(mt.mutbl, r))) - } + ty::ty_estr(ty::vstore_slice(r)) | + ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil, + region: r, _}) => { + Some(deref_ptr(region_ptr(ast::m_imm, r))) + } - ty::ty_estr(ty::vstore_slice(r)) => { - Some(deref_ptr(region_ptr(ast::m_imm, r))) - } + ty::ty_box(mt) | + ty::ty_evec(mt, ty::vstore_box) => { + Some(deref_ptr(gc_ptr(mt.mutbl))) + } - ty::ty_fn(ref f) if (*f).meta.proto == ast::ProtoBorrowed => { - Some(deref_ptr(region_ptr(ast::m_imm, (*f).meta.region))) - } + ty::ty_estr(ty::vstore_box) | + ty::ty_closure(ty::ClosureTy {sigil: ast::ManagedSigil, _}) => { + Some(deref_ptr(gc_ptr(ast::m_imm))) + } - ty::ty_box(mt) | - ty::ty_evec(mt, ty::vstore_box) => { - Some(deref_ptr(gc_ptr(mt.mutbl))) - } + ty::ty_ptr(*) => { + Some(deref_ptr(unsafe_ptr)) + } - ty::ty_estr(ty::vstore_box) => { - Some(deref_ptr(gc_ptr(ast::m_imm))) - } + ty::ty_enum(did, _) => { + Some(deref_comp(comp_variant(did))) + } - ty::ty_fn(ref f) if (*f).meta.proto == ast::ProtoBox => { - Some(deref_ptr(gc_ptr(ast::m_imm))) - } + ty::ty_struct(_, _) => { + Some(deref_comp(comp_anon_field)) + } - ty::ty_ptr(*) => { - Some(deref_ptr(unsafe_ptr)) - } + ty::ty_evec(mt, ty::vstore_fixed(_)) => { + Some(deref_comp(comp_index(t, mt.mutbl))) + } - ty::ty_enum(did, _) => { - Some(deref_comp(comp_variant(did))) - } + ty::ty_estr(ty::vstore_fixed(_)) => { + Some(deref_comp(comp_index(t, m_imm))) + } - ty::ty_struct(_, _) => { - Some(deref_comp(comp_anon_field)) - } - - ty::ty_evec(mt, ty::vstore_fixed(_)) => { - Some(deref_comp(comp_index(t, mt.mutbl))) - } - - ty::ty_estr(ty::vstore_fixed(_)) => { - Some(deref_comp(comp_index(t, m_imm))) - } - - _ => None + _ => None } } @@ -473,9 +465,9 @@ pub impl &mem_categorization_ctxt { ast::def_upvar(_, inner, fn_node_id, _) => { let ty = ty::node_id_to_type(self.tcx, fn_node_id); - let proto = ty::ty_fn_proto(ty); - match proto { - ast::ProtoBorrowed => { + let sigil = ty::ty_closure_sigil(ty); + match sigil { + ast::BorrowedSigil => { let upcmt = self.cat_def(id, span, expr_ty, *inner); @cmt_ { id:id, @@ -486,7 +478,7 @@ pub impl &mem_categorization_ctxt { ty:upcmt.ty } } - ast::ProtoUniq | ast::ProtoBox => { + ast::OwnedSigil | ast::ManagedSigil => { // FIXME #2152 allow mutation of moved upvars @cmt_ { id:id, @@ -497,11 +489,6 @@ pub impl &mem_categorization_ctxt { ty:expr_ty } } - ast::ProtoBare => { - self.tcx.sess.span_bug( - span, - fmt!("Upvar in a bare closure?")); - } } } diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index f7943d6edc0..aaa3156e27c 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -474,7 +474,35 @@ impl VisitContext { } for opt_with.each |with_expr| { - self.consume_expr(*with_expr, visitor); + // If there are any fields whose type is move-by-default, + // then `with` is consumed, otherwise it is only read + let with_ty = ty::expr_ty(self.tcx, *with_expr); + let with_fields = match ty::get(with_ty).sty { + ty::ty_rec(ref f) => copy *f, + ty::ty_struct(did, ref substs) => { + ty::struct_fields(self.tcx, did, substs) + } + ref r => { + self.tcx.sess.span_bug( + with_expr.span, + fmt!("bad base expr type in record: %?", r)) + } + }; + + // The `with` expr must be consumed if it contains + // any fields which (1) were not explicitly + // specified and (2) have a type that + // moves-by-default: + let consume_with = with_fields.any(|tf| { + !fields.any(|f| f.node.ident == tf.ident) && + ty::type_implicitly_moves(self.tcx, tf.mt.ty) + }); + + if consume_with { + self.consume_expr(*with_expr, visitor); + } else { + self.use_expr(*with_expr, Read, visitor); + } } } @@ -786,9 +814,9 @@ impl VisitContext { let _indenter = indenter(); let fn_ty = ty::node_id_to_type(self.tcx, fn_expr_id); - let proto = ty::ty_fn_proto(fn_ty); + let sigil = ty::ty_closure_sigil(fn_ty); let freevars = freevars::get_freevars(self.tcx, fn_expr_id); - if proto == ProtoBorrowed { + if sigil == BorrowedSigil { // &fn() captures everything by ref at_vec::from_fn(freevars.len(), |i| { let fvar = &freevars[i]; diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 867cc7c686f..68e41b329e3 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -657,7 +657,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty, } } - ast::ty_fn(f) => { + ast::ty_closure(ref f) => { debug!("referenced fn type: %s", pprust::ty_to_str(ty, cx.sess.intr())); match f.region { @@ -668,7 +668,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty, } } None => { - if f.proto == ast::ProtoBorrowed && cx.anon_implies_rp { + if f.sigil == ast::BorrowedSigil && cx.anon_implies_rp { cx.add_rp(cx.item_id, cx.add_variance(rv_contravariant)); } @@ -732,18 +732,18 @@ pub fn determine_rp_in_ty(ty: @ast::Ty, } } - ast::ty_fn(f) => { + ast::ty_closure(@ast::TyClosure {decl: ref decl, _}) | + ast::ty_bare_fn(@ast::TyBareFn {decl: ref decl, _}) => { // fn() binds the & region, so do not consider &T types that // appear *inside* a fn() type to affect the enclosing item: do cx.with(cx.item_id, false) { // parameters are contravariant do cx.with_ambient_variance(rv_contravariant) { - for f.decl.inputs.each |a| { + for decl.inputs.each |a| { (visitor.visit_ty)(a.ty, cx, visitor); } } - visit::visit_ty_param_bounds(f.bounds, cx, visitor); - (visitor.visit_ty)(f.decl.output, cx, visitor); + (visitor.visit_ty)(decl.output, cx, visitor); } } diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 99b5641ac6a..ebd6d9f9056 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -1652,7 +1652,7 @@ pub fn trans_match_inner(scope_cx: block, // insert bindings into the lllocals map and add cleanups bcx = insert_lllocals(bcx, *arm_data, true); - bcx = controlflow::trans_block(bcx, arm_data.arm.body, dest); + bcx = controlflow::trans_block(bcx, &arm_data.arm.body, dest); bcx = trans_block_cleanups(bcx, block_cleanups(arm_data.bodycx)); arm_cxs.push(bcx); } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index a1f863332bd..588e2916e47 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -613,7 +613,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t, let ccx = cx.ccx(); let mut cx = cx; match ty::get(fn_ty).sty { - ty::ty_fn(ref fn_ty) => { + ty::ty_bare_fn(ref fn_ty) => { let mut j = 0u; let v_id = variant.id; for vec::each(fn_ty.sig.inputs) |a| { @@ -777,10 +777,10 @@ pub fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t) -> ValueRef { let name = csearch::get_symbol(ccx.sess.cstore, did).to_managed(); // Sad match ty::get(t).sty { - ty::ty_fn(_) => { + ty::ty_bare_fn(_) | ty::ty_closure(_) => { let llty = type_of_fn_from_ty(ccx, t); return get_extern_fn(ccx.externs, ccx.llmod, name, - lib::llvm::CCallConv, llty); + lib::llvm::CCallConv, llty); } _ => { let llty = type_of(ccx, t); @@ -1363,7 +1363,7 @@ pub fn with_scope_datumblock(bcx: block, opt_node_info: Option, DatumBlock {bcx: leave_block(bcx, scope_cx), datum: datum} } -pub fn block_locals(b: ast::blk, it: fn(@ast::local)) { +pub fn block_locals(b: &ast::blk, it: fn(@ast::local)) { for vec::each(b.node.stmts) |s| { match s.node { ast::stmt_decl(d, _) => { @@ -1727,8 +1727,8 @@ pub enum self_arg { impl_self(ty::t), impl_owned_self(ty::t), no_self, } // returned. pub fn trans_closure(ccx: @crate_ctxt, +path: path, - decl: ast::fn_decl, - body: ast::blk, + decl: &ast::fn_decl, + body: &ast::blk, llfndecl: ValueRef, ty_self: self_arg, +param_substs: Option, @@ -1791,8 +1791,8 @@ pub fn trans_closure(ccx: @crate_ctxt, // function. pub fn trans_fn(ccx: @crate_ctxt, +path: path, - decl: ast::fn_decl, - body: ast::blk, + decl: &ast::fn_decl, + body: &ast::blk, llfndecl: ValueRef, ty_self: self_arg, +param_substs: Option, @@ -1935,7 +1935,7 @@ pub fn trans_tuple_struct(ccx: @crate_ctxt, pub fn trans_struct_dtor(ccx: @crate_ctxt, +path: path, - body: ast::blk, + body: &ast::blk, dtor_id: ast::node_id, +psubsts: Option, hash_id: Option, @@ -1966,8 +1966,9 @@ pub fn trans_struct_dtor(ccx: @crate_ctxt, ccx.monomorphized.insert(*h_id, lldecl); } /* Translate the dtor body */ - trans_fn(ccx, path, ast_util::dtor_dec(), - body, lldecl, impl_self(class_ty), psubsts, dtor_id, None); + let decl = ast_util::dtor_dec(); + trans_fn(ccx, path, &decl, body, lldecl, + impl_self(class_ty), psubsts, dtor_id, None); lldecl } @@ -2013,20 +2014,19 @@ pub fn trans_item(ccx: @crate_ctxt, item: ast::item) { _ => die!(~"trans_item"), }; match /*bad*/copy item.node { - // XXX: Bad copies. - ast::item_fn(copy decl, purity, copy tps, ref body) => { + ast::item_fn(ref decl, purity, ref tps, ref body) => { if purity == ast::extern_fn { let llfndecl = get_item_val(ccx, item.id); foreign::trans_foreign_fn(ccx, vec::append( /*bad*/copy *path, ~[path_name(item.ident)]), - decl, (*body), llfndecl, item.id); + decl, body, llfndecl, item.id); } else if tps.is_empty() { let llfndecl = get_item_val(ccx, item.id); trans_fn(ccx, vec::append(/*bad*/copy *path, ~[path_name(item.ident)]), - decl, (*body), llfndecl, no_self, None, item.id, None); + decl, body, llfndecl, no_self, None, item.id, None); } else { for vec::each((*body).node.stmts) |stmt| { match stmt.node { @@ -2078,7 +2078,7 @@ pub fn trans_struct_def(ccx: @crate_ctxt, struct_def: @ast::struct_def, id: ast::node_id) { // Translate the destructor. do option::iter(&struct_def.dtor) |dtor| { - trans_struct_dtor(ccx, /*bad*/copy *path, dtor.node.body, + trans_struct_dtor(ccx, /*bad*/copy *path, &dtor.node.body, dtor.node.id, None, None, local_def(id)); }; diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 4bd5ae969f2..4af74b3623f 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -627,18 +627,17 @@ pub fn trans_arg_expr(bcx: block, Some(_) => { match arg_expr.node { ast::expr_loop_body( - // XXX: Bad copy. - blk@@ast::expr { - node: ast::expr_fn_block(copy decl, ref body), + blk @ @ast::expr { + node: ast::expr_fn_block(ref decl, ref body), _ }) => { let scratch_ty = expr_ty(bcx, arg_expr); let scratch = alloc_ty(bcx, scratch_ty); let arg_ty = expr_ty(bcx, arg_expr); - let proto = ty::ty_fn_proto(arg_ty); + let sigil = ty::ty_closure_sigil(arg_ty); let bcx = closure::trans_expr_fn( - bcx, proto, decl, /*bad*/copy *body, arg_expr.id, + bcx, sigil, decl, body, arg_expr.id, blk.id, Some(ret_flag), expr::SaveIn(scratch)); DatumBlock {bcx: bcx, datum: Datum {val: scratch, diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index 62e00100d6c..c70425da9fa 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -160,7 +160,7 @@ pub fn mk_closure_tys(tcx: ty::ctxt, return cdata_ty; } -pub fn allocate_cbox(bcx: block, proto: ast::Proto, cdata_ty: ty::t) +pub fn allocate_cbox(bcx: block, sigil: ast::Sigil, cdata_ty: ty::t) -> Result { let _icx = bcx.insn_ctxt("closure::allocate_cbox"); let ccx = bcx.ccx(), tcx = ccx.tcx; @@ -176,23 +176,19 @@ pub fn allocate_cbox(bcx: block, proto: ast::Proto, cdata_ty: ty::t) } // Allocate and initialize the box: - match proto { - ast::ProtoBox => { + match sigil { + ast::ManagedSigil => { malloc_raw(bcx, cdata_ty, heap_shared) } - ast::ProtoUniq => { + ast::OwnedSigil => { malloc_raw(bcx, cdata_ty, heap_exchange) } - ast::ProtoBorrowed => { + ast::BorrowedSigil => { let cbox_ty = tuplify_box_ty(tcx, cdata_ty); let llbox = base::alloc_ty(bcx, cbox_ty); nuke_ref_count(bcx, llbox); rslt(bcx, llbox) } - ast::ProtoBare => { - let cdata_llty = type_of(bcx.ccx(), cdata_ty); - rslt(bcx, C_null(cdata_llty)) - } } } @@ -208,7 +204,7 @@ pub type closure_result = { // Otherwise, it is stack allocated and copies pointers to the upvars. pub fn store_environment(bcx: block, bound_values: ~[EnvValue], - proto: ast::Proto) -> closure_result { + sigil: ast::Sigil) -> closure_result { let _icx = bcx.insn_ctxt("closure::store_environment"); let ccx = bcx.ccx(), tcx = ccx.tcx; @@ -217,7 +213,7 @@ pub fn store_environment(bcx: block, let cdata_ty = mk_closure_tys(tcx, copy bound_values); // allocate closure in the heap - let Result {bcx: bcx, val: llbox} = allocate_cbox(bcx, proto, cdata_ty); + let Result {bcx: bcx, val: llbox} = allocate_cbox(bcx, sigil, cdata_ty); let mut temp_cleanups = ~[]; // cbox_ty has the form of a tuple: (a, b, c) we want a ptr to a @@ -265,7 +261,7 @@ pub fn store_environment(bcx: block, // collects the upvars and packages them up for store_environment. pub fn build_closure(bcx0: block, cap_vars: &[moves::CaptureVar], - proto: ast::Proto, + sigil: ast::Sigil, include_ret_handle: Option) -> closure_result { let _icx = bcx0.insn_ctxt("closure::build_closure"); // If we need to, package up the iterator body to call @@ -279,7 +275,7 @@ pub fn build_closure(bcx0: block, let datum = expr::trans_local_var(bcx, cap_var.def); match cap_var.mode { moves::CapRef => { - assert proto == ast::ProtoBorrowed; + assert sigil == ast::BorrowedSigil; env_vals.push(EnvValue {action: EnvRef, datum: datum}); } @@ -316,7 +312,7 @@ pub fn build_closure(bcx0: block, datum: ret_datum}); } - return store_environment(bcx, env_vals, proto); + return store_environment(bcx, env_vals, sigil); } // Given an enclosing block context, a new function context, a closure type, @@ -326,7 +322,7 @@ pub fn load_environment(fcx: fn_ctxt, cdata_ty: ty::t, cap_vars: &[moves::CaptureVar], load_ret_handle: bool, - proto: ast::Proto) { + sigil: ast::Sigil) { let _icx = fcx.insn_ctxt("closure::load_environment"); let llloadenv = match fcx.llloadenv { @@ -352,9 +348,9 @@ pub fn load_environment(fcx: fn_ctxt, let mut i = 0u; for cap_vars.each |cap_var| { let mut upvarptr = GEPi(bcx, llcdata, [0u, i]); - match proto { - ast::ProtoBorrowed => { upvarptr = Load(bcx, upvarptr); } - ast::ProtoBox | ast::ProtoUniq | ast::ProtoBare => {} + match sigil { + ast::BorrowedSigil => { upvarptr = Load(bcx, upvarptr); } + ast::ManagedSigil | ast::OwnedSigil => {} } let def_id = ast_util::def_id_of_def(cap_var.def); fcx.llupvars.insert(def_id.node, upvarptr); @@ -369,9 +365,9 @@ pub fn load_environment(fcx: fn_ctxt, } pub fn trans_expr_fn(bcx: block, - proto: ast::Proto, - +decl: ast::fn_decl, - +body: ast::blk, + sigil: ast::Sigil, + decl: &ast::fn_decl, + body: &ast::blk, outer_id: ast::node_id, user_id: ast::node_id, is_loop_body: Option>, @@ -381,7 +377,7 @@ pub fn trans_expr_fn(bcx: block, * * Translates the body of a closure expression. * - * - `proto` + * - `sigil` * - `decl` * - `body` * - `outer_id`: The id of the closure expression with the correct @@ -417,18 +413,18 @@ pub fn trans_expr_fn(bcx: block, ~"expr_fn"); let llfn = decl_internal_cdecl_fn(ccx.llmod, s, llfnty); - let Result {bcx: bcx, val: closure} = match proto { - ast::ProtoBorrowed | ast::ProtoBox | ast::ProtoUniq => { + let Result {bcx: bcx, val: closure} = match sigil { + ast::BorrowedSigil | ast::ManagedSigil | ast::OwnedSigil => { let cap_vars = ccx.maps.capture_map.get(&user_id); let ret_handle = match is_loop_body {Some(x) => x, None => None}; - let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, proto, + let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, sigil, ret_handle); trans_closure(ccx, sub_path, decl, body, llfn, no_self, /*bad*/ copy bcx.fcx.param_substs, user_id, None, |fcx| load_environment(fcx, cdata_ty, cap_vars, - ret_handle.is_some(), proto), + ret_handle.is_some(), sigil), |bcx| { if is_loop_body.is_some() { Store(bcx, C_bool(true), bcx.fcx.llretptr); @@ -436,34 +432,30 @@ pub fn trans_expr_fn(bcx: block, }); rslt(bcx, llbox) } - ast::ProtoBare => { - trans_closure(ccx, sub_path, decl, body, llfn, no_self, None, - user_id, None, |_fcx| { }, |_bcx| { }); - rslt(bcx, C_null(T_opaque_box_ptr(ccx))) - } }; fill_fn_pair(bcx, dest_addr, llfn, closure); return bcx; } -pub fn make_fn_glue(cx: block, - v: ValueRef, - t: ty::t, - glue_fn: fn@(block, v: ValueRef, t: ty::t) -> block) - -> block { - let _icx = cx.insn_ctxt("closure::make_fn_glue"); +pub fn make_closure_glue( + cx: block, + v: ValueRef, + t: ty::t, + glue_fn: fn@(block, v: ValueRef, t: ty::t) -> block) -> block +{ + let _icx = cx.insn_ctxt("closure::make_closure_glue"); let bcx = cx; let tcx = cx.tcx(); - let proto = ty::ty_fn_proto(t); - match proto { - ast::ProtoBare | ast::ProtoBorrowed => bcx, - ast::ProtoUniq | ast::ProtoBox => { + let sigil = ty::ty_closure_sigil(t); + match sigil { + ast::BorrowedSigil => bcx, + ast::OwnedSigil | ast::ManagedSigil => { let box_cell_v = GEPi(cx, v, [0u, abi::fn_field_box]); let box_ptr_v = Load(cx, box_cell_v); do with_cond(cx, IsNotNull(cx, box_ptr_v)) |bcx| { - let closure_ty = ty::mk_opaque_closure_ptr(tcx, proto); + let closure_ty = ty::mk_opaque_closure_ptr(tcx, sigil); glue_fn(bcx, box_cell_v, closure_ty) } } @@ -472,20 +464,20 @@ pub fn make_fn_glue(cx: block, pub fn make_opaque_cbox_take_glue( bcx: block, - proto: ast::Proto, + sigil: ast::Sigil, cboxptr: ValueRef) // ptr to ptr to the opaque closure -> block { // Easy cases: let _icx = bcx.insn_ctxt("closure::make_opaque_cbox_take_glue"); - match proto { - ast::ProtoBare | ast::ProtoBorrowed => { + match sigil { + ast::BorrowedSigil => { return bcx; } - ast::ProtoBox => { + ast::ManagedSigil => { glue::incr_refcnt_of_boxed(bcx, Load(bcx, cboxptr)); return bcx; } - ast::ProtoUniq => { + ast::OwnedSigil => { /* hard case: fallthrough to code below */ } } @@ -531,36 +523,36 @@ pub fn make_opaque_cbox_take_glue( pub fn make_opaque_cbox_drop_glue( bcx: block, - proto: ast::Proto, + sigil: ast::Sigil, cboxptr: ValueRef) // ptr to the opaque closure -> block { let _icx = bcx.insn_ctxt("closure::make_opaque_cbox_drop_glue"); - match proto { - ast::ProtoBare | ast::ProtoBorrowed => bcx, - ast::ProtoBox => { + match sigil { + ast::BorrowedSigil => bcx, + ast::ManagedSigil => { glue::decr_refcnt_maybe_free( bcx, Load(bcx, cboxptr), - ty::mk_opaque_closure_ptr(bcx.tcx(), proto)) + ty::mk_opaque_closure_ptr(bcx.tcx(), sigil)) } - ast::ProtoUniq => { + ast::OwnedSigil => { glue::free_ty( bcx, cboxptr, - ty::mk_opaque_closure_ptr(bcx.tcx(), proto)) + ty::mk_opaque_closure_ptr(bcx.tcx(), sigil)) } } } pub fn make_opaque_cbox_free_glue( bcx: block, - proto: ast::Proto, + sigil: ast::Sigil, cbox: ValueRef) // ptr to ptr to the opaque closure -> block { let _icx = bcx.insn_ctxt("closure::make_opaque_cbox_free_glue"); - match proto { - ast::ProtoBare | ast::ProtoBorrowed => { + match sigil { + ast::BorrowedSigil => { return bcx; } - ast::ProtoBox | ast::ProtoUniq => { + ast::ManagedSigil | ast::OwnedSigil => { /* hard cases: fallthrough to code below */ } } @@ -580,10 +572,10 @@ pub fn make_opaque_cbox_free_glue( abi::tydesc_field_drop_glue, None); // Free the ty descr (if necc) and the box itself - match proto { - ast::ProtoBox => glue::trans_free(bcx, cbox), - ast::ProtoUniq => glue::trans_unique_free(bcx, cbox), - ast::ProtoBare | ast::ProtoBorrowed => { + match sigil { + ast::ManagedSigil => glue::trans_free(bcx, cbox), + ast::OwnedSigil => glue::trans_unique_free(bcx, cbox), + ast::BorrowedSigil => { bcx.sess().bug(~"impossible") } } diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index a1505dd2f11..0933eedd5e4 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -23,7 +23,7 @@ pub fn macros() { include!("macros.rs"); } -pub fn trans_block(bcx: block, b: ast::blk, dest: expr::Dest) -> block { +pub fn trans_block(bcx: block, b: &ast::blk, dest: expr::Dest) -> block { let _icx = bcx.insn_ctxt("trans_block"); let mut bcx = bcx; do block_locals(b) |local| { @@ -47,7 +47,7 @@ pub fn trans_block(bcx: block, b: ast::blk, dest: expr::Dest) -> block { pub fn trans_if(bcx: block, cond: @ast::expr, - thn: ast::blk, + thn: &ast::blk, els: Option<@ast::expr>, dest: expr::Dest) -> block { @@ -82,10 +82,10 @@ pub fn trans_if(bcx: block, match elexpr.node { ast::expr_if(_, _, _) => { let elseif_blk = ast_util::block_from_expr(elexpr); - trans_block(else_bcx_in, elseif_blk, dest) + trans_block(else_bcx_in, &elseif_blk, dest) } ast::expr_block(ref blk) => { - trans_block(else_bcx_in, (*blk), dest) + trans_block(else_bcx_in, blk, dest) } // would be nice to have a constraint on ifs _ => bcx.tcx().sess.bug(~"strange alternative in if") @@ -114,7 +114,7 @@ pub fn join_blocks(parent_bcx: block, in_cxs: ~[block]) -> block { return out; } -pub fn trans_while(bcx: block, cond: @ast::expr, body: ast::blk) -> block { +pub fn trans_while(bcx: block, cond: @ast::expr, body: &ast::blk) -> block { let _icx = bcx.insn_ctxt("trans_while"); let next_bcx = sub_block(bcx, ~"while next"); @@ -154,7 +154,7 @@ pub fn trans_while(bcx: block, cond: @ast::expr, body: ast::blk) -> block { } pub fn trans_loop(bcx:block, - body: ast::blk, + body: &ast::blk, opt_label: Option) -> block { let _icx = bcx.insn_ctxt("trans_loop"); diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 56833d373c5..f2da47eb0ec 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -475,10 +475,10 @@ fn trans_rvalue_stmt_unadjusted(bcx: block, expr: @ast::expr) -> block { return controlflow::trans_check_expr(bcx, expr, a, ~"Assertion"); } ast::expr_while(cond, ref body) => { - return controlflow::trans_while(bcx, cond, (*body)); + return controlflow::trans_while(bcx, cond, body); } ast::expr_loop(ref body, opt_label) => { - return controlflow::trans_loop(bcx, (*body), opt_label); + return controlflow::trans_loop(bcx, body, opt_label); } ast::expr_assign(dst, src) => { let src_datum = unpack_datum!( @@ -530,7 +530,7 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr, bcx.def(expr.id), dest); } ast::expr_if(cond, ref thn, els) => { - return controlflow::trans_if(bcx, cond, *thn, els, dest); + return controlflow::trans_if(bcx, cond, thn, els, dest); } ast::expr_match(discr, ref arms) => { return _match::trans_match(bcx, expr, discr, /*bad*/copy *arms, @@ -539,7 +539,7 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr, ast::expr_block(ref blk) => { return do base::with_scope(bcx, blk.info(), ~"block-expr body") |bcx| { - controlflow::trans_block(bcx, (*blk), dest) + controlflow::trans_block(bcx, blk, dest) }; } ast::expr_rec(ref fields, base) | @@ -562,58 +562,31 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr, ast::expr_vec(*) | ast::expr_repeat(*) => { return tvec::trans_fixed_vstore(bcx, expr, expr, dest); } - // XXX: Bad copy. - ast::expr_fn(proto, copy decl, ref body, _) => { - // Don't use this function for anything real. Use the one in - // astconv instead. - return closure::trans_expr_fn(bcx, proto, decl, - /*bad*/copy *body, + ast::expr_fn(_, ref decl, ref body, _) | + ast::expr_fn_block(ref decl, ref body) => { + let expr_ty = expr_ty(bcx, expr); + let sigil = ty::ty_closure_sigil(expr_ty); + debug!("translating fn_block %s with type %s", + expr_to_str(expr, tcx.sess.intr()), + ty_to_str(tcx, expr_ty)); + return closure::trans_expr_fn(bcx, sigil, decl, body, expr.id, expr.id, None, dest); } - ast::expr_fn_block(ref decl, ref body) => { - let expr_ty = expr_ty(bcx, expr); - match ty::get(expr_ty).sty { - ty::ty_fn(ref fn_ty) => { - debug!("translating fn_block %s with type %s", - expr_to_str(expr, tcx.sess.intr()), - ty_to_str(tcx, expr_ty)); - return closure::trans_expr_fn( - bcx, fn_ty.meta.proto, /*bad*/copy *decl, - /*bad*/copy *body, expr.id, expr.id, - None, dest); - } - _ => { - bcx.sess().impossible_case( - expr.span, "fn_block has body with a non-fn type"); - } - } - } ast::expr_loop_body(blk) => { - match ty::get(expr_ty(bcx, expr)).sty { - ty::ty_fn(ref fn_ty) => { - match blk.node { - ast::expr_fn_block(copy decl, ref body) => { - return closure::trans_expr_fn( - bcx, - fn_ty.meta.proto, - decl, - /*bad*/copy *body, - expr.id, - blk.id, - Some(None), - dest); - } - _ => { - bcx.sess().impossible_case( - expr.span, - "loop_body has the wrong kind of contents") - } - } + let expr_ty = expr_ty(bcx, expr); + let sigil = ty::ty_closure_sigil(expr_ty); + match blk.node { + ast::expr_fn_block(ref decl, ref body) => { + return closure::trans_expr_fn(bcx, sigil, + decl, body, + expr.id, blk.id, + Some(None), dest); } _ => { bcx.sess().impossible_case( - expr.span, "loop_body has body with a non-fn type") + expr.span, + "loop_body has the wrong kind of contents") } } } diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index ae05ceb1ec5..bb14fce8053 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -31,7 +31,7 @@ use middle::trans::machine; use middle::trans::shape; use middle::trans::type_of::*; use middle::trans::type_of; -use middle::ty::{FnTyBase, FnMeta, FnSig, arg}; +use middle::ty::{FnSig, arg}; use util::ppaux::ty_to_str; use core::libc::c_uint; @@ -66,10 +66,8 @@ type c_stack_tys = { fn c_arg_and_ret_lltys(ccx: @crate_ctxt, id: ast::node_id) -> (~[TypeRef], TypeRef, ty::t) { match ty::get(ty::node_id_to_type(ccx.tcx, id)).sty { - ty::ty_fn(ref fn_ty) => { - let llargtys = type_of_explicit_args( - ccx, - fn_ty.sig.inputs); + ty::ty_bare_fn(ref fn_ty) => { + let llargtys = type_of_explicit_args(ccx, fn_ty.sig.inputs); let llretty = type_of::type_of(ccx, fn_ty.sig.output); (llargtys, llretty, fn_ty.sig.output) } @@ -541,12 +539,11 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, let star_u8 = ty::mk_imm_ptr( bcx.tcx(), ty::mk_mach_uint(bcx.tcx(), ast::ty_u8)); - let fty = ty::mk_fn(bcx.tcx(), FnTyBase { - meta: FnMeta {purity: ast::impure_fn, - proto: ast::ProtoBorrowed, - onceness: ast::Many, - region: ty::re_bound(ty::br_anon(0)), - bounds: @~[]}, + let fty = ty::mk_closure(bcx.tcx(), ty::ClosureTy { + purity: ast::impure_fn, + sigil: ast::BorrowedSigil, + onceness: ast::Many, + region: ty::re_bound(ty::br_anon(0)), sig: FnSig {inputs: ~[arg {mode: ast::expl(ast::by_copy), ty: star_u8}], output: ty::mk_nil(bcx.tcx())} @@ -843,14 +840,14 @@ pub fn trans_intrinsic(ccx: @crate_ctxt, pub fn trans_foreign_fn(ccx: @crate_ctxt, +path: ast_map::path, - decl: ast::fn_decl, - body: ast::blk, + decl: &ast::fn_decl, + body: &ast::blk, llwrapfn: ValueRef, id: ast::node_id) { let _icx = ccx.insn_ctxt("foreign::build_foreign_fn"); fn build_rust_fn(ccx: @crate_ctxt, +path: ast_map::path, - decl: ast::fn_decl, body: ast::blk, + decl: &ast::fn_decl, body: &ast::blk, id: ast::node_id) -> ValueRef { let _icx = ccx.insn_ctxt("foreign::foreign::build_rust_fn"); let t = ty::node_id_to_type(ccx.tcx, id); diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 9909980fb7e..564460fd88e 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -172,7 +172,8 @@ pub fn simplified_glue_type(tcx: ty::ctxt, field: uint, t: ty::t) -> ty::t { if field == abi::tydesc_field_free_glue { match ty::get(t).sty { - ty::ty_fn(*) | + ty::ty_bare_fn(*) | + ty::ty_closure(*) | ty::ty_box(*) | ty::ty_opaque_box | ty::ty_uniq(*) | @@ -419,8 +420,8 @@ pub fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) { tvec::expand_boxed_vec_ty(bcx.tcx(), t)); return; } - ty::ty_fn(_) => { - closure::make_fn_glue(bcx, v, t, free_ty) + ty::ty_closure(_) => { + closure::make_closure_glue(bcx, v, t, free_ty) } ty::ty_opaque_closure_ptr(ck) => { closure::make_opaque_cbox_free_glue(bcx, ck, v) @@ -528,8 +529,8 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) { } } } - ty::ty_fn(_) => { - closure::make_fn_glue(bcx, v0, t, drop_ty) + ty::ty_closure(_) => { + closure::make_closure_glue(bcx, v0, t, drop_ty) } ty::ty_trait(_, _, ty::vstore_box) => { let llbox = Load(bcx, GEPi(bcx, v0, [0u, 1u])); @@ -594,8 +595,8 @@ pub fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) { | ty::ty_estr(ty::vstore_slice(_)) => { bcx } - ty::ty_fn(_) => { - closure::make_fn_glue(bcx, v, t, take_ty) + ty::ty_closure(_) => { + closure::make_closure_glue(bcx, v, t, take_ty) } ty::ty_trait(_, _, ty::vstore_box) => { let llbox = Load(bcx, GEPi(bcx, v, [0u, 1u])); diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index 4466e4e1b28..c094db4ecca 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -108,8 +108,8 @@ pub fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id, }; trans_fn(ccx, path, - mth.decl, - mth.body, + &mth.decl, + &mth.body, llfn, self_kind, None, diff --git a/src/librustc/middle/trans/machine.rs b/src/librustc/middle/trans/machine.rs index e76176218b7..828b5619390 100644 --- a/src/librustc/middle/trans/machine.rs +++ b/src/librustc/middle/trans/machine.rs @@ -34,8 +34,11 @@ pub fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t { ty::ty_box(_) | ty::ty_opaque_box | ty::ty_uniq(_) | ty::ty_evec(_, ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_uniq) | ty::ty_estr(ty::vstore_box) | - ty::ty_ptr(_) | ty::ty_rptr(_,_) => nilptr(tcx), - ty::ty_fn(_) => ty::mk_tup(tcx, ~[nilptr(tcx), nilptr(tcx)]), + ty::ty_ptr(_) | ty::ty_rptr(*) => nilptr(tcx), + + ty::ty_bare_fn(*) | // FIXME(#4804) Bare fn repr + ty::ty_closure(*) => ty::mk_tup(tcx, ~[nilptr(tcx), nilptr(tcx)]), + ty::ty_evec(_, ty::vstore_slice(_)) | ty::ty_estr(ty::vstore_slice(_)) => { ty::mk_tup(tcx, ~[nilptr(tcx), ty::mk_int(tcx)]) diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index d751b8f9208..1d48d2dde6b 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -142,8 +142,8 @@ pub fn trans_method(ccx: @crate_ctxt, // generate the actual code trans_fn(ccx, path, - method.decl, - method.body, + &method.decl, + &method.body, llfn, self_arg, param_substs, @@ -822,7 +822,7 @@ pub fn make_impl_vtable(ccx: @crate_ctxt, let has_tps = (*ty::lookup_item_type(ccx.tcx, impl_id).bounds).len() > 0u; make_vtable(ccx, vec::map(*ty::trait_methods(tcx, trt_id), |im| { let fty = ty::subst_tps(tcx, substs, None, - ty::mk_fn(tcx, copy im.fty)); + ty::mk_bare_fn(tcx, copy im.fty)); if (*im.tps).len() > 0u || ty::type_has_self(fty) { debug!("(making impl vtable) method has self or type params: %s", tcx.sess.str_of(im.ident)); diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 5873d0a76d9..b09a41f2b7f 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -26,7 +26,7 @@ use middle::trans::shape; use middle::trans::type_of::type_of_fn_from_ty; use middle::trans::type_of; use middle::trans::type_use; -use middle::ty::{FnTyBase, FnMeta, FnSig}; +use middle::ty::{FnSig}; use middle::typeck; use core::option; @@ -166,12 +166,12 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, let lldecl = match map_node { ast_map::node_item(i@@ast::item { // XXX: Bad copy. - node: ast::item_fn(copy decl, _, _, ref body), + node: ast::item_fn(ref decl, _, _, ref body), _ }, _) => { let d = mk_lldecl(); set_inline_hint_if_appr(/*bad*/copy i.attrs, d); - trans_fn(ccx, pt, decl, *body, d, no_self, psubsts, fn_id.node, None); + trans_fn(ccx, pt, decl, body, d, no_self, psubsts, fn_id.node, None); d } ast_map::node_item(*) => { @@ -224,7 +224,7 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, None => ccx.sess.span_bug(dtor.span, ~"Bad self ty in \ dtor") }; - trans_struct_dtor(ccx, /*bad*/copy *pt, dtor.node.body, + trans_struct_dtor(ccx, /*bad*/copy *pt, &dtor.node.body, dtor.node.id, psubsts, Some(hash_id), parent_id) } ast_map::node_trait_method(@ast::provided(mth), _, pt) => { @@ -267,31 +267,34 @@ pub fn monomorphic_fn(ccx: @crate_ctxt, pub fn normalize_for_monomorphization(tcx: ty::ctxt, ty: ty::t) -> Option { // FIXME[mono] could do this recursively. is that worthwhile? (#2529) - match ty::get(ty).sty { + return match ty::get(ty).sty { ty::ty_box(*) => { Some(ty::mk_opaque_box(tcx)) } - ty::ty_fn(ref fty) => { - Some(ty::mk_fn( + ty::ty_bare_fn(_) => { + Some(ty::mk_bare_fn( tcx, - FnTyBase {meta: FnMeta {purity: ast::impure_fn, - proto: fty.meta.proto, - onceness: ast::Many, - region: ty::re_static, - bounds: @~[]}, - sig: FnSig {inputs: ~[], - output: ty::mk_nil(tcx)}})) + ty::BareFnTy { + purity: ast::impure_fn, + abi: ast::RustAbi, + sig: FnSig {inputs: ~[], + output: ty::mk_nil(tcx)}})) } - ty::ty_trait(_, _, _) => { - Some(ty::mk_fn( - tcx, - FnTyBase {meta: FnMeta {purity: ast::impure_fn, - proto: ast::ProtoBox, - onceness: ast::Many, - region: ty::re_static, - bounds: @~[]}, - sig: FnSig {inputs: ~[], - output: ty::mk_nil(tcx)}})) + ty::ty_closure(ref fty) => { + Some(normalized_closure_ty(tcx, fty.sigil)) + } + ty::ty_trait(_, _, ref vstore) => { + let sigil = match *vstore { + ty::vstore_uniq => ast::OwnedSigil, + ty::vstore_box => ast::ManagedSigil, + ty::vstore_slice(_) => ast::BorrowedSigil, + ty::vstore_fixed(*) => { + tcx.sess.bug(fmt!("ty_trait with vstore_fixed")); + } + }; + + // Traits have the same runtime representation as closures. + Some(normalized_closure_ty(tcx, sigil)) } ty::ty_ptr(_) => { Some(ty::mk_uint(tcx)) @@ -299,6 +302,20 @@ pub fn normalize_for_monomorphization(tcx: ty::ctxt, _ => { None } + }; + + fn normalized_closure_ty(tcx: ty::ctxt, + sigil: ast::Sigil) -> ty::t + { + ty::mk_closure( + tcx, + ty::ClosureTy { + purity: ast::impure_fn, + sigil: sigil, + onceness: ast::Many, + region: ty::re_static, + sig: ty::FnSig {inputs: ~[], + output: ty::mk_nil(tcx)}}) } } diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index 7380fa2e562..9466099904c 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -86,9 +86,8 @@ pub impl reflector { tcx.sess.ident_of(~"visit_" + ty_name), *self.visitor_methods).expect(fmt!("Couldn't find visit method \ for %s", ty_name)); - let mth_ty = ty::mk_fn( - tcx, - /*bad*/copy self.visitor_methods[mth_idx].fty); + 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)); let bcx = self.bcx; @@ -211,39 +210,33 @@ pub impl reflector { } } - // FIXME (#2594): fetch constants out of intrinsic:: for the - // numbers. - ty::ty_fn(ref fty) => { - let pureval = match fty.meta.purity { - ast::pure_fn => 0u, - ast::unsafe_fn => 1u, - ast::impure_fn => 2u, - ast::extern_fn => 3u - }; - let protoval = ast_proto_constant(fty.meta.proto); + // FIXME (#2594): fetch constants out of intrinsic + // FIXME (#4809): visitor should break out bare fns from other fns + ty::ty_closure(ref fty) => { + let pureval = ast_purity_constant(fty.purity); + let sigilval = ast_sigil_constant(fty.sigil); let retval = if ty::type_is_bot(fty.sig.output) {0u} else {1u}; let extra = ~[self.c_uint(pureval), - self.c_uint(protoval), + self.c_uint(sigilval), self.c_uint(vec::len(fty.sig.inputs)), self.c_uint(retval)]; self.visit(~"enter_fn", copy extra); // XXX: Bad copy. - for fty.sig.inputs.eachi |i, arg| { - let modeval = match arg.mode { - ast::infer(_) => 0u, - ast::expl(e) => match e { - ast::by_ref => 1u, - ast::by_val => 2u, - ast::by_copy => 5u - } - }; - self.visit(~"fn_input", - ~[self.c_uint(i), - self.c_uint(modeval), - self.c_tydesc(arg.ty)]); - } - self.visit(~"fn_output", - ~[self.c_uint(retval), - self.c_tydesc(fty.sig.output)]); + self.visit_sig(retval, &fty.sig); + self.visit(~"leave_fn", extra); + } + + // FIXME (#2594): fetch constants out of intrinsic:: for the + // numbers. + ty::ty_bare_fn(ref fty) => { + let pureval = ast_purity_constant(fty.purity); + let sigilval = 0u; + 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(retval)]; + self.visit(~"enter_fn", copy extra); // XXX: Bad copy. + self.visit_sig(retval, &fty.sig); self.visit(~"leave_fn", extra); } @@ -302,11 +295,31 @@ pub impl reflector { ty::ty_type => self.leaf(~"type"), ty::ty_opaque_box => self.leaf(~"opaque_box"), ty::ty_opaque_closure_ptr(ck) => { - let ckval = ast_proto_constant(ck); + let ckval = ast_sigil_constant(ck); self.visit(~"closure_ptr", ~[self.c_uint(ckval)]) } } } + + fn visit_sig(&self, retval: uint, sig: &ty::FnSig) { + for sig.inputs.eachi |i, arg| { + let modeval = match arg.mode { + ast::infer(_) => 0u, + ast::expl(e) => match e { + ast::by_ref => 1u, + ast::by_val => 2u, + ast::by_copy => 5u + } + }; + self.visit(~"fn_input", + ~[self.c_uint(i), + self.c_uint(modeval), + self.c_tydesc(arg.ty)]); + } + self.visit(~"fn_output", + ~[self.c_uint(retval), + self.c_tydesc(sig.output)]); + } } // Emit a sequence of calls to visit_ty::visit_foo @@ -332,12 +345,20 @@ pub fn emit_calls_to_trait_visit_ty(bcx: block, return final; } -pub fn ast_proto_constant(proto: ast::Proto) -> uint { - match proto { - ast::ProtoBare => 0u, - ast::ProtoUniq => 2u, - ast::ProtoBox => 3u, - ast::ProtoBorrowed => 4u, +pub fn ast_sigil_constant(sigil: ast::Sigil) -> uint { + match sigil { + ast::OwnedSigil => 2u, + ast::ManagedSigil => 3u, + ast::BorrowedSigil => 4u, + } +} + +pub fn ast_purity_constant(purity: ast::purity) -> uint { + match purity { + ast::pure_fn => 0u, + ast::unsafe_fn => 1u, + ast::impure_fn => 2u, + ast::extern_fn => 3u } } diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 99c47997df0..f727b5a2de0 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -59,7 +59,13 @@ pub fn type_of_fn(cx: @crate_ctxt, inputs: &[ty::arg], // Given a function type and a count of ty params, construct an llvm type pub fn type_of_fn_from_ty(cx: @crate_ctxt, fty: ty::t) -> TypeRef { - type_of_fn(cx, ty::ty_fn_args(fty), ty::ty_fn_ret(fty)) + match ty::get(fty).sty { + ty::ty_closure(ref f) => type_of_fn(cx, f.sig.inputs, f.sig.output), + ty::ty_bare_fn(ref f) => type_of_fn(cx, f.sig.inputs, f.sig.output), + _ => { + cx.sess.bug(~"type_of_fn_from_ty given non-closure, non-bare-fn") + } + } } pub fn type_of_non_gc_box(cx: @crate_ctxt, t: ty::t) -> TypeRef { @@ -170,7 +176,11 @@ pub fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef { // structs T_struct(~[T_struct(tys)]) } - ty::ty_fn(_) => T_fn_pair(cx, type_of_fn_from_ty(cx, t)), + + // FIXME(#4804) Bare fn repr + // ty::ty_bare_fn(_) => T_ptr(type_of_fn_from_ty(cx, t)), + ty::ty_bare_fn(_) => T_fn_pair(cx, type_of_fn_from_ty(cx, t)), + ty::ty_closure(_) => T_fn_pair(cx, type_of_fn_from_ty(cx, t)), ty::ty_trait(_, _, vstore) => T_opaque_trait(cx, vstore), ty::ty_type => T_ptr(cx.tydesc_type), ty::ty_tup(elts) => { diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index 6b0d4e17c74..3fd334c2d15 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -69,8 +69,9 @@ pub fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint) let cx = {ccx: ccx, uses: vec::cast_to_mut(vec::from_elem(n_tps, 0u))}; match ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).sty { - ty::ty_fn(ref fn_ty) => { - for vec::each(fn_ty.sig.inputs) |arg| { + ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) | + ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) => { + for vec::each(sig.inputs) |arg| { match ty::resolved_mode(ccx.tcx, arg.mode) { by_val | by_copy => { type_needs(cx, use_repr, arg.ty); @@ -197,8 +198,12 @@ pub fn type_needs_inner(cx: ctx, it, we depend on the drop glue for T (we have to write the right tydesc into the result) */ - ty::ty_fn(_) | ty::ty_ptr(_) | ty::ty_rptr(_, _) - | ty::ty_trait(_, _, _) => false, + ty::ty_closure(*) | + ty::ty_bare_fn(*) | + ty::ty_ptr(_) | + ty::ty_rptr(_, _) | + ty::ty_trait(_, _, _) => false, + ty::ty_enum(did, ref substs) => { if option::is_none(&list::find(enums_seen, |id| *id == did)) { let seen = @Cons(did, enums_seen); @@ -287,15 +292,15 @@ pub fn mark_for_expr(cx: ctx, e: @expr) { } } expr_fn(*) | expr_fn_block(*) => { - match ty::ty_fn_proto(ty::expr_ty(cx.ccx.tcx, e)) { - ast::ProtoBare | ast::ProtoUniq => {} - ast::ProtoBox | ast::ProtoBorrowed => { - for vec::each(*freevars::get_freevars(cx.ccx.tcx, e.id)) |fv| { - let node_id = ast_util::def_id_of_def(fv.def).node; - node_type_needs(cx, use_repr, node_id); - } + match ty::ty_closure_sigil(ty::expr_ty(cx.ccx.tcx, e)) { + ast::OwnedSigil => {} + ast::BorrowedSigil | ast::ManagedSigil => { + for freevars::get_freevars(cx.ccx.tcx, e.id).each |fv| { + let node_id = ast_util::def_id_of_def(fv.def).node; + node_type_needs(cx, use_repr, node_id); + } + } } - } } expr_assign(val, _) | expr_swap(val, _) | expr_assign_op(_, val, _) | expr_ret(Some(val)) => { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 9905701e058..ef62fb3caf1 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[warn(deprecated_pattern)]; - use core::prelude::*; use driver::session; @@ -27,7 +25,7 @@ use middle; use session::Session; use util::ppaux::{note_and_explain_region, bound_region_to_str}; use util::ppaux::{region_to_str, explain_region, vstore_to_str}; -use util::ppaux::{ty_to_str, proto_ty_to_str, tys_to_str}; +use util::ppaux::{ty_to_str, tys_to_str}; use core::cast; use core::cmp; @@ -73,7 +71,7 @@ pub type param_bounds = @~[param_bound]; pub type method = { ident: ast::ident, tps: @~[param_bounds], - fty: FnTy, + fty: BareFnTy, self_ty: ast::self_ty_, vis: ast::visibility, def_id: ast::def_id @@ -344,22 +342,20 @@ pub pure fn type_contains_err(t: t) -> bool { pub pure fn type_def_id(t: t) -> Option { get(t).o_def_id } pub pure fn type_id(t: t) -> uint { get(t).id } -/** - * Meta information about a closure. - * - * - `purity` is the function's effect (pure, impure, unsafe). - * - `proto` is the protocol (fn@, fn~, etc). - * - `onceness` indicates whether the function can be called one time or many - * times. - * - `region` is the region bound on the function's upvars (often &static). - * - `bounds` is the parameter bounds on the function's upvars. */ #[deriving_eq] -pub struct FnMeta { +pub struct BareFnTy { purity: ast::purity, - proto: ast::Proto, + abi: Abi, + sig: FnSig +} + +#[deriving_eq] +pub struct ClosureTy { + purity: ast::purity, + sigil: ast::Sigil, onceness: ast::Onceness, region: Region, - bounds: @~[param_bound] + sig: FnSig } /** @@ -374,24 +370,18 @@ pub struct FnSig { output: t } -/** - * Function type: combines the meta information and the - * type signature. This particular type is parameterized - * by the meta information because, in some cases, the - * meta information is inferred. */ -#[deriving_eq] -pub struct FnTyBase { - meta: M, // Either FnMeta or FnVid - sig: FnSig // Types of arguments/return type -} - -impl FnTyBase : to_bytes::IterBytes { +impl BareFnTy : to_bytes::IterBytes { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { - to_bytes::iter_bytes_2(&self.meta, &self.sig, lsb0, f) + to_bytes::iter_bytes_3(&self.purity, &self.abi, &self.sig, lsb0, f) } } -pub type FnTy = FnTyBase; +impl ClosureTy : to_bytes::IterBytes { + pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { + to_bytes::iter_bytes_5(&self.purity, &self.sigil, &self.onceness, + &self.region, &self.sig, lsb0, f) + } +} #[deriving_eq] pub struct param_ty { @@ -491,6 +481,7 @@ pub struct substs { // NB: If you change this, you'll probably want to change the corresponding // AST structure in libsyntax/ast.rs as well. +#[deriving_eq] pub enum sty { ty_nil, ty_bot, @@ -506,7 +497,8 @@ pub enum sty { ty_ptr(mt), ty_rptr(Region, mt), ty_rec(~[field]), - ty_fn(FnTy), + ty_bare_fn(BareFnTy), + ty_closure(ClosureTy), ty_trait(def_id, substs, vstore), ty_struct(def_id, substs), ty_tup(~[t]), @@ -522,7 +514,7 @@ pub enum sty { // "Fake" types, used for trans purposes ty_type, // type_desc* ty_opaque_box, // used by monomorphizer to represent any @ box - ty_opaque_closure_ptr(ast::Proto), // ptr to env for fn, fn@, fn~ + ty_opaque_closure_ptr(Sigil), // ptr to env for fn, fn@, fn~ ty_unboxed_vec(mt), } @@ -546,8 +538,9 @@ pub enum type_err { terr_mismatch, terr_purity_mismatch(expected_found), terr_onceness_mismatch(expected_found), + terr_abi_mismatch(expected_found), terr_mutability, - terr_proto_mismatch(expected_found), + terr_sigil_mismatch(expected_found), terr_box_mutability, terr_ptr_mutability, terr_ref_mutability, @@ -744,6 +737,15 @@ pub impl RegionVid : to_bytes::IterBytes { } } +pub fn kind_to_param_bounds(kind: Kind) -> param_bounds { + let mut bounds = ~[]; + if kind_can_be_copied(kind) { bounds.push(bound_copy); } + if kind_can_be_sent(kind) { bounds.push(bound_owned); } + else if kind_is_durable(kind) { bounds.push(bound_durable); } + if kind_is_const(kind) { bounds.push(bound_const); } + return @bounds; +} + pub fn param_bounds_to_kind(bounds: param_bounds) -> Kind { let mut kind = kind_noncopyable(); for vec::each(*bounds) |bound| { @@ -925,8 +927,12 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option) -> t { } &ty_rec(ref flds) => for flds.each |f| { flags |= get(f.mt.ty).flags; }, &ty_tup(ref ts) => for ts.each |tt| { flags |= get(*tt).flags; }, - &ty_fn(ref f) => { - flags |= rflags(f.meta.region); + &ty_bare_fn(ref f) => { + for f.sig.inputs.each |a| { flags |= get(a.ty).flags; } + flags |= get(f.sig.output).flags; + } + &ty_closure(ref f) => { + flags |= rflags(f.region); for f.sig.inputs.each |a| { flags |= get(a.ty).flags; } flags |= get(f.sig.output).flags; } @@ -1044,8 +1050,25 @@ pub fn mk_rec(cx: ctxt, +fs: ~[field]) -> t { mk_t(cx, ty_rec(fs)) } pub fn mk_tup(cx: ctxt, +ts: ~[t]) -> t { mk_t(cx, ty_tup(ts)) } -// take a copy because we want to own the various vectors inside -pub fn mk_fn(cx: ctxt, +fty: FnTy) -> t { mk_t(cx, ty_fn(fty)) } +pub fn mk_closure(cx: ctxt, +fty: ClosureTy) -> t { + mk_t(cx, ty_closure(fty)) +} + +pub fn mk_bare_fn(cx: ctxt, +fty: BareFnTy) -> t { + mk_t(cx, ty_bare_fn(fty)) +} + +pub fn mk_ctor_fn(cx: ctxt, input_tys: &[ty::t], output: ty::t) -> t { + let input_args = input_tys.map(|t| arg {mode: ast::expl(ast::by_copy), + ty: *t}); + mk_bare_fn(cx, + BareFnTy { + purity: ast::pure_fn, + abi: ast::RustAbi, + sig: FnSig {inputs: input_args, + output: output}}) +} + pub fn mk_trait(cx: ctxt, did: ast::def_id, +substs: substs, vstore: vstore) -> t { @@ -1074,8 +1097,8 @@ pub fn mk_param(cx: ctxt, n: uint, k: def_id) -> t { pub fn mk_type(cx: ctxt) -> t { mk_t(cx, ty_type) } -pub fn mk_opaque_closure_ptr(cx: ctxt, proto: ast::Proto) -> t { - mk_t(cx, ty_opaque_closure_ptr(proto)) +pub fn mk_opaque_closure_ptr(cx: ctxt, sigil: ast::Sigil) -> t { + mk_t(cx, ty_opaque_closure_ptr(sigil)) } pub fn mk_opaque_box(cx: ctxt) -> t { mk_t(cx, ty_opaque_box) } @@ -1097,13 +1120,11 @@ pub pure fn mach_sty(cfg: @session::config, t: t) -> sty { pub fn default_arg_mode_for_ty(tcx: ctxt, ty: ty::t) -> ast::rmode { // FIXME(#2202) --- We retain by-ref for fn& things to workaround a // memory leak that otherwise results when @fn is upcast to &fn. - if type_is_fn(ty) { - match ty_fn_proto(ty) { - ast::ProtoBorrowed => { - return ast::by_ref; - } - _ => {} + match ty::get(ty).sty { + ty::ty_closure(ClosureTy {sigil: ast::BorrowedSigil, _}) => { + return ast::by_ref; } + _ => {} } return if tcx.legacy_modes { if type_is_borrowed(ty) { @@ -1119,13 +1140,6 @@ pub fn default_arg_mode_for_ty(tcx: ctxt, ty: ty::t) -> ast::rmode { ast::by_copy }; - fn type_is_fn(ty: t) -> bool { - match get(ty).sty { - ty_fn(*) => true, - _ => false - } - } - fn type_is_borrowed(ty: t) -> bool { match ty::get(ty).sty { ty::ty_rptr(*) => true, @@ -1171,7 +1185,11 @@ pub fn maybe_walk_ty(ty: t, f: fn(t) -> bool) { for fields.each |fl| { maybe_walk_ty(fl.mt.ty, f); } } ty_tup(ts) => { for ts.each |tt| { maybe_walk_ty(*tt, f); } } - ty_fn(ref ft) => { + ty_bare_fn(ref ft) => { + for ft.sig.inputs.each |a| { maybe_walk_ty(a.ty, f); } + maybe_walk_ty(ft.sig.output, f); + } + ty_closure(ref ft) => { for ft.sig.inputs.each |a| { maybe_walk_ty(a.ty, f); } maybe_walk_ty(ft.sig.output, f); } @@ -1235,9 +1253,13 @@ fn fold_sty(sty: &sty, fldop: fn(t) -> t) -> sty { let new_ts = vec::map(ts, |tt| fldop(*tt)); ty_tup(new_ts) } - ty_fn(ref f) => { + ty_bare_fn(ref f) => { let sig = fold_sig(&f.sig, fldop); - ty_fn(FnTyBase {meta: f.meta, sig: sig}) + ty_bare_fn(BareFnTy {sig: sig, abi: f.abi, purity: f.purity}) + } + ty_closure(ref f) => { + let sig = fold_sig(&f.sig, fldop); + ty_closure(ClosureTy {sig: sig, ..copy *f}) } ty_rptr(r, tm) => { ty_rptr(r, mt {ty: fldop(tm.ty), mutbl: tm.mutbl}) @@ -1318,10 +1340,14 @@ pub fn fold_regions_and_ty( ty_trait(def_id, ref substs, vst) => { ty::mk_trait(cx, def_id, fold_substs(substs, fldr, fldt), vst) } - ty_fn(ref f) => { - ty::mk_fn(cx, FnTyBase {meta: FnMeta {region: fldr(f.meta.region), - ..f.meta}, - sig: fold_sig(&f.sig, fldfnt)}) + ty_bare_fn(ref f) => { + ty::mk_bare_fn(cx, BareFnTy {sig: fold_sig(&f.sig, fldfnt), + ..copy *f}) + } + ty_closure(ref f) => { + ty::mk_closure(cx, ClosureTy {region: fldr(f.region), + sig: fold_sig(&f.sig, fldfnt), + ..copy *f}) } ref sty => { fold_sty_to_ty(cx, sty, |t| fldt(t)) @@ -1329,30 +1355,6 @@ pub fn fold_regions_and_ty( } } -/* A little utility: it often happens that I have a `fn_ty`, - * but I want to use some function like `fold_regions_and_ty()` - * that is defined over all types. This utility converts to - * a full type and back. It's not the best way to do this (somewhat - * inefficient to do the conversion), it would be better to refactor - * all this folding business. However, I've been waiting on that - * until trait support is improved. */ -pub fn apply_op_on_t_to_ty_fn( - cx: ctxt, - f: &FnTy, - t_op: fn(t) -> t) -> FnTy -{ - let t0 = ty::mk_fn(cx, /*bad*/copy *f); - let t1 = t_op(t0); - match ty::get(t1).sty { - ty::ty_fn(copy f) => { - move f - } - _ => { - cx.sess.bug(~"`t_op` did not return a function type"); - } - } -} - // n.b. this function is intended to eventually replace fold_region() below, // that is why its name is so similar. pub fn fold_regions( @@ -1372,41 +1374,6 @@ pub fn fold_regions( do_fold(cx, ty, false, fldr) } -pub fn fold_region(cx: ctxt, t0: t, fldop: fn(Region, bool) -> Region) -> t { - fn do_fold(cx: ctxt, t0: t, under_r: bool, - fldop: fn(Region, bool) -> Region) -> t { - let tb = get(t0); - if !tbox_has_flag(tb, has_regions) { return t0; } - match tb.sty { - ty_rptr(r, mt {ty: t1, mutbl: m}) => { - let m_r = fldop(r, under_r); - let m_t1 = do_fold(cx, t1, true, fldop); - ty::mk_rptr(cx, m_r, mt {ty: m_t1, mutbl: m}) - } - ty_estr(vstore_slice(r)) => { - let m_r = fldop(r, under_r); - ty::mk_estr(cx, vstore_slice(m_r)) - } - ty_evec(mt {ty: t1, mutbl: m}, vstore_slice(r)) => { - let m_r = fldop(r, under_r); - let m_t1 = do_fold(cx, t1, true, fldop); - ty::mk_evec(cx, mt {ty: m_t1, mutbl: m}, vstore_slice(m_r)) - } - ty_fn(_) => { - // do not recurse into functions, which introduce fresh bindings - t0 - } - ref sty => { - do fold_sty_to_ty(cx, sty) |t| { - do_fold(cx, t, under_r, fldop) - } - } - } - } - - do_fold(cx, t0, false, fldop) -} - // Substitute *only* type parameters. Used in trans where regions are erased. pub fn subst_tps(cx: ctxt, tps: &[t], self_ty_opt: Option, typ: t) -> t { if tps.len() == 0u && self_ty_opt.is_none() { return typ; } @@ -1529,7 +1496,9 @@ pub fn type_is_bool(ty: t) -> bool { get(ty).sty == ty_bool } pub fn type_is_structural(ty: t) -> bool { match get(ty).sty { - ty_rec(_) | ty_struct(*) | ty_tup(_) | ty_enum(*) | ty_fn(_) | + ty_rec(_) | ty_struct(*) | ty_tup(_) | ty_enum(*) | + ty_closure(_) | + ty_bare_fn(_) | // FIXME(#4804) Bare fn repr ty_trait(*) | ty_evec(_, vstore_fixed(_)) | ty_estr(vstore_fixed(_)) | ty_evec(_, vstore_slice(_)) | ty_estr(vstore_slice(_)) @@ -1715,10 +1684,11 @@ pub fn type_needs_drop(cx: ctxt, ty: t) -> bool { } accum } - ty_fn(ref fty) => { - match fty.meta.proto { - ast::ProtoBare | ast::ProtoBorrowed => false, - ast::ProtoBox | ast::ProtoUniq => true, + ty_bare_fn(*) => false, + ty_closure(ref fty) => { + match fty.sigil { + ast::BorrowedSigil => false, + ast::ManagedSigil | ast::OwnedSigil => true, } } }; @@ -1813,7 +1783,7 @@ pub enum Kind { kind_(u32) } const KIND_MASK_COPY : u32 = 0b000000000000000000000000001_u32; /// no shared box, borrowed ptr (must imply DURABLE) -const KIND_MASK_OWNED : u32 = 0b000000000000000000000000010_u32; +const KIND_MASK_OWNED : u32 = 0b000000000000000000000000010_u32; /// is durable (no borrowed ptrs) const KIND_MASK_DURABLE : u32 = 0b000000000000000000000000100_u32; @@ -1942,20 +1912,25 @@ pub pure fn kind_is_durable(k: Kind) -> bool { *k & KIND_MASK_DURABLE == KIND_MASK_DURABLE } -pub fn meta_kind(p: FnMeta) -> Kind { - match p.proto { // XXX consider the kind bounds! - ast::ProtoBare => { - kind_safe_for_default_mode_send() | kind_const() | kind_durable() - } - ast::ProtoBorrowed => { - kind_noncopyable() | kind_(KIND_MASK_DEFAULT_MODE) - } - ast::ProtoBox => { - kind_safe_for_default_mode() | kind_durable() - } - ast::ProtoUniq => { - kind_owned_copy() | kind_durable() - } +pure fn kind_is_const(k: Kind) -> bool { + *k & KIND_MASK_CONST == KIND_MASK_CONST +} + +fn closure_kind(cty: &ClosureTy) -> Kind { + let kind = match cty.sigil { + ast::BorrowedSigil => kind_implicitly_copyable(), + ast::ManagedSigil => kind_implicitly_copyable(), + ast::OwnedSigil => kind_owned_only() | kind_durable(), + }; + + let kind = match cty.region { + re_static => kind | kind_durable(), + _ => kind - kind_owned_only() - kind_durable() + }; + + match cty.onceness { + ast::Once => kind - kind_implicitly_copyable(), + ast::Many => kind } } @@ -2022,7 +1997,7 @@ pub fn type_kind_ext(cx: ctxt, ty: t, allow_ty_var: bool) -> Kind { let mut result = match /*bad*/copy get(ty).sty { // Scalar and unique types are sendable, constant, and owned ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) | - ty_ptr(_) => { + ty_bare_fn(_) | ty_ptr(_) => { kind_safe_for_default_mode_send() | kind_const() | kind_durable() } @@ -2035,8 +2010,9 @@ pub fn type_kind_ext(cx: ctxt, ty: t, allow_ty_var: bool) -> Kind { } } - // functions depend on the protocol - ty_fn(ref f) => meta_kind(f.meta), + ty_closure(ref c) => { + closure_kind(c) + } // Those with refcounts raise noncopyable to copyable, // lower sendable to copyable. Therefore just set result to copyable. @@ -2215,7 +2191,8 @@ fn type_size(cx: ctxt, ty: t) -> uint { ty_evec(_, vstore_slice(_)) | ty_estr(vstore_slice(_)) | - ty_fn(_) => { + ty_bare_fn(*) | + ty_closure(*) => { 2 } @@ -2297,7 +2274,8 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool { ty_uint(_) | ty_float(_) | ty_estr(_) | - ty_fn(_) | + ty_bare_fn(_) | + ty_closure(_) | ty_infer(_) | ty_err | ty_param(_) | @@ -2472,9 +2450,9 @@ pub fn type_is_pod(cx: ctxt, ty: t) -> bool { match /*bad*/copy get(ty).sty { // Scalar types ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) | - ty_type | ty_ptr(_) => result = true, + ty_type | ty_ptr(_) | ty_bare_fn(_) => result = true, // Boxed types - ty_box(_) | ty_uniq(_) | ty_fn(_) | + ty_box(_) | ty_uniq(_) | ty_closure(_) | ty_estr(vstore_uniq) | ty_estr(vstore_box) | ty_evec(_, vstore_uniq) | ty_evec(_, vstore_box) | ty_trait(_, _, _) | ty_rptr(_,_) | ty_opaque_box => result = false, @@ -2700,14 +2678,9 @@ impl arg : to_bytes::IterBytes { } } -impl FnMeta : to_bytes::IterBytes { +impl Kind : to_bytes::IterBytes { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { - to_bytes::iter_bytes_5(&self.purity, - &self.proto, - &self.onceness, - &self.region, - &self.bounds, - lsb0, f); + (**self).iter_bytes(lsb0, f) } } @@ -2755,7 +2728,7 @@ impl sty : to_bytes::IterBytes { ty_rec(ref fs) => to_bytes::iter_bytes_2(&11u8, fs, lsb0, f), - ty_fn(ref ft) => + ty_bare_fn(ref ft) => to_bytes::iter_bytes_2(&12u8, ft, lsb0, f), ty_self => 13u8.iter_bytes(lsb0, f), @@ -2789,7 +2762,10 @@ impl sty : to_bytes::IterBytes { ty_rptr(ref r, ref mt) => to_bytes::iter_bytes_3(&24u8, r, mt, lsb0, f), - ty_err => 25u8.iter_bytes(lsb0, f) + ty_err => 25u8.iter_bytes(lsb0, f), + + ty_closure(ref ct) => + to_bytes::iter_bytes_2(&26u8, ct, lsb0, f), } } } @@ -2823,36 +2799,48 @@ fn node_id_has_type_params(cx: ctxt, id: ast::node_id) -> bool { // Type accessors for substructures of types pub fn ty_fn_args(fty: t) -> ~[arg] { match get(fty).sty { - ty_fn(ref f) => /*bad*/copy f.sig.inputs, - _ => die!(~"ty_fn_args() called on non-fn type") + ty_bare_fn(ref f) => copy f.sig.inputs, + ty_closure(ref f) => copy f.sig.inputs, + ref s => { + die!(fmt!("ty_fn_args() called on non-fn type: %?", s)) + } } } -pub fn ty_fn_proto(fty: t) -> Proto { +pub fn ty_closure_sigil(fty: t) -> Sigil { match get(fty).sty { - ty_fn(ref f) => f.meta.proto, - _ => die!(~"ty_fn_proto() called on non-fn type") + ty_closure(ref f) => f.sigil, + ref s => { + die!(fmt!("ty_closure_sigil() called on non-closure type: %?", s)) + } } } pub fn ty_fn_purity(fty: t) -> ast::purity { match get(fty).sty { - ty_fn(ref f) => f.meta.purity, - _ => die!(~"ty_fn_purity() called on non-fn type") + ty_bare_fn(ref f) => f.purity, + ty_closure(ref f) => f.purity, + ref s => { + die!(fmt!("ty_fn_purity() called on non-fn type: %?", s)) + } } } pub pure fn ty_fn_ret(fty: t) -> t { match get(fty).sty { - ty_fn(ref f) => f.sig.output, - _ => die!(~"ty_fn_ret() called on non-fn type") + ty_bare_fn(ref f) => f.sig.output, + ty_closure(ref f) => f.sig.output, + ref s => { + die!(fmt!("ty_fn_ret() called on non-fn type: %?", s)) + } } } fn is_fn_ty(fty: t) -> bool { match get(fty).sty { - ty_fn(_) => true, - _ => false + ty_bare_fn(_) => true, + ty_closure(_) => true, + _ => false } } @@ -2874,17 +2862,17 @@ pub fn ty_region(ty: t) -> Region { } } -pub fn replace_fn_return_type(tcx: ctxt, fn_type: t, ret_type: t) -> t { +pub fn replace_closure_return_type(tcx: ctxt, fn_type: t, ret_type: t) -> t { /*! * * Returns a new function type based on `fn_type` but returning a value of * type `ret_type` instead. */ match ty::get(fn_type).sty { - ty::ty_fn(ref fty) => { - ty::mk_fn(tcx, FnTyBase { - meta: fty.meta, - sig: FnSig {output: ret_type, ..copy fty.sig} + ty::ty_closure(ref fty) => { + ty::mk_closure(tcx, ClosureTy { + sig: FnSig {output: ret_type, ..copy fty.sig}, + ..copy *fty }) } _ => { @@ -2900,12 +2888,6 @@ pub fn tys_in_fn_sig(sig: &FnSig) -> ~[t] { vec::append_one(sig.inputs.map(|a| a.ty), sig.output) } -// Just checks whether it's a fn that returns bool, -// not its purity. -pub fn is_pred_ty(fty: t) -> bool { - is_fn_ty(fty) && type_is_bool(ty_fn_ret(fty)) -} - // Type accessors for AST nodes pub fn block_ty(cx: ctxt, b: &ast::blk) -> t { return node_id_to_type(cx, b.node.id); @@ -3023,11 +3005,12 @@ pub fn expr_ty_adjusted(cx: ctxt, expr: @ast::expr) -> t { fn borrow_fn(cx: ctxt, expr: @ast::expr, autoref: &AutoRef, ty: ty::t) -> ty::t { match get(ty).sty { - ty_fn(ref fty) => { - ty::mk_fn(cx, FnTyBase {meta: FnMeta {proto: ProtoBorrowed, - region: autoref.region, - ..copy fty.meta}, - sig: copy fty.sig}) + ty_closure(ref fty) => { + ty::mk_closure(cx, ClosureTy { + sigil: BorrowedSigil, + region: autoref.region, + ..copy *fty + }) } ref s => { @@ -3417,7 +3400,8 @@ pub fn ty_sort_str(cx: ctxt, t: t) -> ~str { ty_ptr(_) => ~"*-ptr", ty_rptr(_, _) => ~"&-ptr", ty_rec(_) => ~"record", - ty_fn(_) => ~"fn", + ty_bare_fn(_) => ~"extern fn", + ty_closure(_) => ~"fn", ty_trait(id, _, _) => fmt!("trait %s", item_path_str(cx, id)), ty_struct(id, _) => fmt!("struct %s", item_path_str(cx, id)), ty_tup(_) => ~"tuple", @@ -3455,14 +3439,18 @@ pub fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str { fmt!("expected %s fn but found %s fn", values.expected.to_str(), values.found.to_str()) } + terr_abi_mismatch(values) => { + fmt!("expected %s fn but found %s fn", + values.expected.to_str(), values.found.to_str()) + } terr_onceness_mismatch(values) => { fmt!("expected %s fn but found %s fn", values.expected.to_str(), values.found.to_str()) } - terr_proto_mismatch(values) => { + terr_sigil_mismatch(values) => { fmt!("expected %s closure, found %s closure", - proto_ty_to_str(cx, values.expected, false), - proto_ty_to_str(cx, values.found, false)) + values.expected.to_str(), + values.found.to_str()) } terr_mutability => ~"values differ in mutability", terr_box_mutability => ~"boxed values differ in mutability", @@ -4232,13 +4220,10 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t { // This type has a region. Get rid of it mk_rptr(cx, re_static, normalize_mt(cx, mt)), - ty_fn(ref fn_ty) => { - mk_fn(cx, FnTyBase { - meta: FnMeta { - region: ty::re_static, - ..fn_ty.meta - }, - sig: /*bad*/copy fn_ty.sig + ty_closure(ref closure_ty) => { + mk_closure(cx, ClosureTy { + region: ty::re_static, + ..copy *closure_ty }) } @@ -4310,13 +4295,13 @@ pub fn eval_repeat_count(tcx: ctxt, // Determine what purity to check a nested function under pub pure fn determine_inherited_purity(parent_purity: ast::purity, child_purity: ast::purity, - child_proto: ast::Proto) + child_sigil: ast::Sigil) -> ast::purity { // If the closure is a stack closure and hasn't had some non-standard // purity inferred for it, then check it under its parent's purity. // Otherwise, use its own - match child_proto { - ast::ProtoBorrowed if child_purity == ast::impure_fn => parent_purity, + match child_sigil { + ast::BorrowedSigil if child_purity == ast::impure_fn => parent_purity, _ => child_purity } } @@ -4526,171 +4511,6 @@ impl bound_region : cmp::Eq { pure fn ne(&self, other: &bound_region) -> bool { !(*self).eq(other) } } -impl sty : cmp::Eq { - pure fn eq(&self, other: &sty) -> bool { - match (/*bad*/copy *self) { - ty_nil => { - match (*other) { - ty_nil => true, - _ => false - } - } - ty_bot => { - match (*other) { - ty_bot => true, - _ => false - } - } - ty_bool => { - match (*other) { - ty_bool => true, - _ => false - } - } - ty_int(e0a) => { - match (*other) { - ty_int(e0b) => e0a == e0b, - _ => false - } - } - ty_uint(e0a) => { - match (*other) { - ty_uint(e0b) => e0a == e0b, - _ => false - } - } - ty_float(e0a) => { - match (*other) { - ty_float(e0b) => e0a == e0b, - _ => false - } - } - ty_estr(e0a) => { - match (*other) { - ty_estr(e0b) => e0a == e0b, - _ => false - } - } - ty_enum(e0a, ref e1a) => { - match (*other) { - ty_enum(e0b, ref e1b) => e0a == e0b && (*e1a) == (*e1b), - _ => false - } - } - ty_box(e0a) => { - match (*other) { - ty_box(e0b) => e0a == e0b, - _ => false - } - } - ty_uniq(e0a) => { - match (*other) { - ty_uniq(e0b) => e0a == e0b, - _ => false - } - } - ty_evec(e0a, e1a) => { - match (*other) { - ty_evec(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - ty_ptr(e0a) => { - match (*other) { - ty_ptr(e0b) => e0a == e0b, - _ => false - } - } - ty_rptr(e0a, e1a) => { - match (*other) { - ty_rptr(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - ty_rec(e0a) => { - match (/*bad*/copy *other) { - ty_rec(e0b) => e0a == e0b, - _ => false - } - } - ty_fn(ref e0a) => { - match (*other) { - ty_fn(ref e0b) => (*e0a) == (*e0b), - _ => false - } - } - ty_trait(e0a, ref e1a, e2a) => { - match (*other) { - ty_trait(e0b, ref e1b, e2b) => - e0a == e0b && (*e1a) == (*e1b) && e2a == e2b, - _ => false - } - } - ty_struct(e0a, ref e1a) => { - match (*other) { - ty_struct(e0b, ref e1b) => e0a == e0b && (*e1a) == (*e1b), - _ => false - } - } - ty_tup(e0a) => { - match (/*bad*/copy *other) { - ty_tup(e0b) => e0a == e0b, - _ => false - } - } - ty_infer(ref e0a) => { - match (*other) { - ty_infer(ref e0b) => *e0a == *e0b, - _ => false - } - } - ty_err => { - match (*other) { - ty_err => true, - _ => false - } - } - ty_param(e0a) => { - match (*other) { - ty_param(e0b) => e0a == e0b, - _ => false - } - } - ty_self => { - match (*other) { - ty_self => true, - _ => false - } - } - ty_type => { - match (*other) { - ty_type => true, - _ => false - } - } - ty_opaque_box => { - match (*other) { - ty_opaque_box => true, - _ => false - } - } - ty_opaque_closure_ptr(e0a) => { - match (*other) { - ty_opaque_closure_ptr(e0b) => e0a == e0b, - _ => false - } - } - ty_unboxed_vec(e0a) => { - match (*other) { - ty_unboxed_vec(e0b) => e0a == e0b, - _ => false - } - } - } - } - pure fn ne(&self, other: &sty) -> bool { !(*self).eq(other) } -} - impl param_bound : cmp::Eq { pure fn eq(&self, other: ¶m_bound) -> bool { match (*self) { diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 070360ce32f..0aafeac265a 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -55,7 +55,7 @@ use core::prelude::*; use middle::pat_util::pat_id_map; -use middle::ty::{FnTyBase, FnMeta, FnSig, arg, field, substs}; +use middle::ty::{arg, field, substs}; use middle::ty::{ty_param_substs_and_ty}; use middle::ty; use middle::typeck::check::fn_ctxt; @@ -70,7 +70,7 @@ use core::vec; use syntax::ast; use syntax::codemap::span; use syntax::print::pprust::path_to_str; -use util::common::indent; +use util::common::indenter; pub trait ast_conv { fn tcx() -> ty::ctxt; @@ -321,13 +321,16 @@ pub fn ast_ty_to_ty( }; ty::mk_rec(tcx, flds) } - ast::ty_fn(f) => { - let bounds = collect::compute_bounds(self.ccx(), f.bounds); - let fn_decl = ty_of_fn_decl(self, rscope, f.proto, - f.purity, f.onceness, - bounds, f.region, f.decl, None, - ast_ty.span); - ty::mk_fn(tcx, fn_decl) + ast::ty_bare_fn(bf) => { + ty::mk_bare_fn(tcx, ty_of_bare_fn(self, rscope, bf.purity, + bf.abi, bf.decl)) + } + ast::ty_closure(f) => { + let fn_decl = ty_of_closure(self, rscope, f.sigil, + f.purity, f.onceness, + f.region, f.decl, None, + ast_ty.span); + ty::mk_closure(tcx, fn_decl) } ast::ty_path(path, id) => { let a_def = match tcx.def_map.find(&id) { @@ -452,71 +455,92 @@ pub fn ty_of_arg( arg {mode: mode, ty: ty} } -pub type expected_tys = Option<{inputs: ~[ty::arg], - output: ty::t}>; - -pub fn ty_of_fn_decl( +pub fn ty_of_bare_fn( self: AC, rscope: RS, - ast_proto: ast::Proto, purity: ast::purity, - onceness: ast::Onceness, - bounds: @~[ty::param_bound], - opt_region: Option<@ast::region>, - decl: ast::fn_decl, - expected_tys: expected_tys, - span: span) -> ty::FnTy { + abi: ast::Abi, + decl: ast::fn_decl) -> ty::BareFnTy +{ debug!("ty_of_fn_decl"); - do indent { - // resolve the function bound region in the original region - // scope `rscope`, not the scope of the function parameters - let bound_region = match opt_region { - Some(region) => { - ast_region_to_region(self, rscope, span, region) - } - None => { - match ast_proto { - ast::ProtoBare | ast::ProtoUniq | ast::ProtoBox => { - // @fn(), ~fn() default to static as the bound - // on their upvars: - ty::re_static - } - ast::ProtoBorrowed => { - // &fn() defaults to an anonymous region: - let r_result = rscope.anon_region(span); - get_region_reporting_err(self.tcx(), span, r_result) - } - } - } - }; - // new region names that appear inside of the fn decl are bound to - // that function type - let rb = in_binding_rscope(rscope); + // new region names that appear inside of the fn decl are bound to + // that function type + let rb = in_binding_rscope(rscope); - let input_tys = do decl.inputs.mapi |i, a| { - let expected_arg_ty = do expected_tys.chain_ref |e| { - // no guarantee that the correct number of expected args - // were supplied - if i < e.inputs.len() {Some(e.inputs[i])} else {None} - }; - ty_of_arg(self, rb, *a, expected_arg_ty) - }; + let input_tys = decl.inputs.map(|a| ty_of_arg(self, rb, *a, None)); + let output_ty = match decl.output.node { + ast::ty_infer => self.ty_infer(decl.output.span), + _ => ast_ty_to_ty(self, rb, decl.output) + }; - let expected_ret_ty = expected_tys.map(|e| e.output); - let output_ty = match decl.output.node { - ast::ty_infer if expected_ret_ty.is_some() => expected_ret_ty.get(), - ast::ty_infer => self.ty_infer(decl.output.span), - _ => ast_ty_to_ty(self, rb, decl.output) - }; - - FnTyBase { - meta: FnMeta {purity: purity, - proto: ast_proto, - onceness: onceness, - region: bound_region, - bounds: bounds}, - sig: FnSig {inputs: input_tys, - output: output_ty} - } + ty::BareFnTy { + purity: purity, + abi: abi, + sig: ty::FnSig {inputs: input_tys, output: output_ty} + } +} + +pub fn ty_of_closure( + self: AC, rscope: RS, + sigil: ast::Sigil, + purity: ast::purity, + onceness: ast::Onceness, + opt_region: Option<@ast::region>, + decl: ast::fn_decl, + expected_tys: Option, + span: span) -> ty::ClosureTy +{ + debug!("ty_of_fn_decl"); + let _i = indenter(); + + // resolve the function bound region in the original region + // scope `rscope`, not the scope of the function parameters + let bound_region = match opt_region { + Some(region) => { + ast_region_to_region(self, rscope, span, region) + } + None => { + match sigil { + ast::OwnedSigil | ast::ManagedSigil => { + // @fn(), ~fn() default to static as the bound + // on their upvars: + ty::re_static + } + ast::BorrowedSigil => { + // &fn() defaults to an anonymous region: + let r_result = rscope.anon_region(span); + get_region_reporting_err(self.tcx(), span, r_result) + } + } + } + }; + + // new region names that appear inside of the fn decl are bound to + // that function type + let rb = in_binding_rscope(rscope); + + let input_tys = do decl.inputs.mapi |i, a| { + let expected_arg_ty = do expected_tys.chain_ref |e| { + // no guarantee that the correct number of expected args + // were supplied + if i < e.inputs.len() {Some(e.inputs[i])} else {None} + }; + ty_of_arg(self, rb, *a, expected_arg_ty) + }; + + let expected_ret_ty = expected_tys.map(|e| e.output); + let output_ty = match decl.output.node { + ast::ty_infer if expected_ret_ty.is_some() => expected_ret_ty.get(), + ast::ty_infer => self.ty_infer(decl.output.span), + _ => ast_ty_to_ty(self, rb, decl.output) + }; + + ty::ClosureTy { + purity: purity, + sigil: sigil, + onceness: onceness, + region: bound_region, + sig: ty::FnSig {inputs: input_tys, + output: output_ty} } } diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index b86f8f26c25..f5faa968791 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -883,7 +883,7 @@ pub impl LookupContext { }) } - ty_trait(*) | ty_fn(*) => { + ty_trait(*) | ty_closure(*) => { // NDM---eventually these should be some variant of autoref None } @@ -906,14 +906,14 @@ pub impl LookupContext { let tcx = self.tcx(); match ty::get(self_ty).sty { - ty_box(*) | ty_uniq(*) | ty_rptr(*) | + ty_bare_fn(*) | ty_box(*) | ty_uniq(*) | ty_rptr(*) | ty_infer(IntVar(_)) | ty_infer(FloatVar(_)) | ty_self | ty_param(*) | ty_nil | ty_bot | ty_bool | ty_int(*) | ty_uint(*) | ty_float(*) | ty_enum(*) | ty_ptr(*) | ty_rec(*) | ty_struct(*) | ty_tup(*) | ty_estr(*) | ty_evec(*) | - ty_trait(*) | ty_fn(*) => { + ty_trait(*) | ty_closure(*) => { self.search_for_some_kind_of_autorefd_method( AutoPtr, autoderefs, [m_const, m_imm, m_mutbl], |m,r| ty::mk_rptr(tcx, r, ty::mt {ty:self_ty, mutbl:m})) @@ -1212,7 +1212,7 @@ pub impl LookupContext { trait_did: def_id, method_num: uint) -> ty::t { let trait_methods = ty::trait_methods(tcx, trait_did); - ty::mk_fn(tcx, /*bad*/copy trait_methods[method_num].fty) + ty::mk_bare_fn(tcx, copy trait_methods[method_num].fty) } } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 1c0881b6ed5..074a0a565ae 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -81,7 +81,7 @@ use core::prelude::*; use middle::const_eval; use middle::pat_util::pat_id_map; use middle::pat_util; -use middle::ty::{TyVid, Vid, FnTyBase, FnMeta, FnSig, VariantInfo_, field}; +use middle::ty::{TyVid, Vid, FnSig, VariantInfo_, field}; use middle::ty::{ty_param_bounds_and_ty, ty_param_substs_and_ty}; use middle::ty::{re_bound, br_cap_avoid, substs, arg, param_ty}; use middle::ty; @@ -90,7 +90,6 @@ use middle::typeck::astconv::{ast_region_to_region, ast_ty_to_ty}; use middle::typeck::astconv; use middle::typeck::check::_match::pat_ctxt; use middle::typeck::check::method::TransformTypeNormally; -use middle::typeck::check::regionmanip::replace_bound_regions_in_fn_ty; use middle::typeck::check::regionmanip::replace_bound_regions_in_fn_sig; use middle::typeck::check::vtable::{LocationInfo, VtableContext}; use middle::typeck::crate_ctxt; @@ -248,8 +247,9 @@ pub fn check_bare_fn(ccx: @crate_ctxt, self_info: Option) { let fty = ty::node_id_to_type(ccx.tcx, id); match ty::get(fty).sty { - ty::ty_fn(ref fn_ty) => { - check_fn(ccx, self_info, fn_ty, decl, body, Vanilla, None) + ty::ty_bare_fn(ref fn_ty) => { + check_fn(ccx, self_info, fn_ty.purity, None, + &fn_ty.sig, decl, body, Vanilla, None) } _ => ccx.tcx.sess.impossible_case(body.span, "check_bare_fn: function type expected") @@ -258,12 +258,14 @@ pub fn check_bare_fn(ccx: @crate_ctxt, pub fn check_fn(ccx: @crate_ctxt, self_info: Option, - fn_ty: &ty::FnTy, + purity: ast::purity, + sigil: Option, + fn_sig: &ty::FnSig, decl: &ast::fn_decl, body: ast::blk, fn_kind: FnKind, - old_fcx: Option<@fn_ctxt>) { - + old_fcx: Option<@fn_ctxt>) +{ let tcx = ccx.tcx; let indirect_ret = match fn_kind { ForLoop => true, _ => false @@ -277,7 +279,7 @@ pub fn check_fn(ccx: @crate_ctxt, let {isr, self_info, fn_sig} = { let old_isr = option::map_default(&old_fcx, @Nil, |fcx| fcx.in_scope_regions); - replace_bound_regions_in_fn_sig(tcx, old_isr, self_info, &fn_ty.sig, + replace_bound_regions_in_fn_sig(tcx, old_isr, self_info, fn_sig, |br| ty::re_free(body.node.id, br)) }; @@ -294,13 +296,10 @@ pub fn check_fn(ccx: @crate_ctxt, // in the case of function expressions, based on the outer context. let fcx: @fn_ctxt = { let (purity, inherited) = match old_fcx { - None => { - (fn_ty.meta.purity, - blank_inherited(ccx)) - } + None => (purity, blank_inherited(ccx)), Some(fcx) => { - (ty::determine_inherited_purity(fcx.purity, fn_ty.meta.purity, - fn_ty.meta.proto), + (ty::determine_inherited_purity(fcx.purity, purity, + sigil.get()), fcx.inh) } }; @@ -1092,8 +1091,9 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, in_fty: ty::t, callee_expr: @ast::expr, args: ~[@ast::expr], - deref_args: DerefArgs) -> {fty: ty::t, bot: bool} { - + sugar: ast::CallSugar, + deref_args: DerefArgs) -> (ty::t, bool) + { let tcx = fcx.ccx.tcx; let mut bot = false; @@ -1103,62 +1103,72 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, debug!("check_call_inner: before universal quant., in_fty=%s", fcx.infcx().ty_to_str(in_fty)); - let mut formal_tys; + let formal_tys; // This is subtle: we expect `fty` to be a function type, which // normally introduce a level of binding. In this case, we want to // process the types bound by the function but not by any nested // functions. Therefore, we match one level of structure. - let fty = - match structure_of(fcx, sp, in_fty) { - ty::ty_fn(ref fn_ty) => { - let fn_ty = - /*bad*/copy replace_bound_regions_in_fn_ty(tcx, @Nil, - None, fn_ty, |_br| fcx.infcx().next_region_var(sp, - call_expr_id)).fn_ty; + let ret_ty = match structure_of(fcx, sp, in_fty) { + ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) | + ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) => { + let {fn_sig: sig, _} = + replace_bound_regions_in_fn_sig( + tcx, @Nil, None, sig, + |_br| fcx.infcx().next_region_var( + sp, call_expr_id)); - let supplied_arg_count = args.len(); + let supplied_arg_count = args.len(); - bot |= ty::type_is_bot(fn_ty.sig.output); + bot |= ty::type_is_bot(sig.output); - // Grab the argument types, supplying fresh type variables - // if the wrong number of arguments were supplied - let expected_arg_count = fn_ty.sig.inputs.len(); - formal_tys = if expected_arg_count == supplied_arg_count { - fn_ty.sig.inputs.map(|a| a.ty) - } else { - tcx.sess.span_err( - sp, fmt!("this function takes %u parameter%s but \ - %u parameter%s supplied", + // Grab the argument types, supplying fresh type variables + // if the wrong number of arguments were supplied + let expected_arg_count = sig.inputs.len(); + formal_tys = if expected_arg_count == supplied_arg_count { + sig.inputs.map(|a| a.ty) + } else { + let suffix = match sugar { + ast::NoSugar => "", + ast::DoSugar => " (including the closure passed by \ + the `do` keyword)", + ast::ForSugar => " (including the closure passed by \ + the `for` keyword)" + }; + let msg = fmt!("this function takes %u parameter%s but \ + %u parameter%s supplied%s", expected_arg_count, - if expected_arg_count == 1 { - ~"" - } else { - ~"s" - }, + if expected_arg_count == 1 {""} + else {"s"}, supplied_arg_count, - if supplied_arg_count == 1 { - ~" was" - } else { - ~"s were" - })); - fcx.infcx().next_ty_vars(supplied_arg_count) - }; - ty::mk_fn(tcx, fn_ty) - } - _ => { - fcx.type_error_message(sp, |actual| { - fmt!("expected function or foreign function but \ - found `%s`", actual) }, in_fty, None); - // check each arg against "error", in order to set up - // all the node type bindings - formal_tys = args.map(|_x| ty::mk_err(tcx)); - ty::mk_err(tcx) - } - }; + if supplied_arg_count == 1 {" was"} + else {"s were"}, + suffix); - debug!("check_call_inner: after universal quant., fty=%s", - fcx.infcx().ty_to_str(fty)); + tcx.sess.span_err(sp, msg); + + vec::from_fn(expected_arg_count, |_| ty::mk_err(tcx)) + }; + + sig.output + } + + _ => { + fcx.type_error_message(sp, |actual| { + fmt!("expected function or foreign function but \ + found `%s`", actual) }, in_fty, None); + + // check each arg against "error", in order to set up + // all the node type bindings + formal_tys = args.map(|_x| ty::mk_err(tcx)); + ty::mk_err(tcx) + } + }; + + debug!("check_call_inner: after universal quant., \ + formal_tys=%? ret_ty=%s", + formal_tys.map(|t| fcx.infcx().ty_to_str(*t)), + fcx.infcx().ty_to_str(ret_ty)); // Check the arguments. // We do this in a pretty awful way: first we typecheck any arguments @@ -1209,7 +1219,7 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, } } - {fty: fty, bot: bot} + (ret_ty, bot) } // A generic function for checking assignment expressions @@ -1233,36 +1243,26 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, fn_ty: ty::t, expr: @ast::expr, +args: ~[@ast::expr], - bot: bool) - -> bool { + bot: bool, + sugar: ast::CallSugar) -> bool + { let mut bot = bot; // Call the generic checker. - let fty = { - let r = check_call_inner(fcx, sp, call_expr_id, - fn_ty, expr, args, DontDerefArgs); - bot |= r.bot; - r.fty - }; + let (ret_ty, b) = check_call_inner(fcx, sp, call_expr_id, + fn_ty, expr, args, sugar, + DontDerefArgs); + bot |= b; // Pull the return type out of the type of the function. - match structure_of(fcx, sp, fty) { - ty::ty_fn(ref f) => { - fcx.write_ty(call_expr_id, f.sig.output); - return bot; - } - _ => { - fcx.write_ty(call_expr_id, ty::mk_err(fcx.ccx.tcx)); - fcx.type_error_message(sp, |_actual| { - ~"expected function"}, fty, None); - return bot; - } - } + fcx.write_ty(call_expr_id, ret_ty); + return bot; } // A generic function for doing all of the checking for call expressions fn check_call(fcx: @fn_ctxt, sp: span, call_expr_id: ast::node_id, - f: @ast::expr, +args: ~[@ast::expr]) -> bool { + f: @ast::expr, +args: ~[@ast::expr], + sugar: ast::CallSugar) -> bool { // Index expressions need to be handled separately, to inform them // that they appear in call position. let mut bot = match /*bad*/copy f.node { @@ -1278,7 +1278,8 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, fcx.expr_ty(f), f, args, - bot) + bot, + sugar) } // Checks a method call. @@ -1287,7 +1288,8 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, rcvr: @ast::expr, method_name: ast::ident, +args: ~[@ast::expr], - tps: ~[@ast::Ty]) + tps: ~[@ast::Ty], + sugar: ast::CallSugar) -> bool { let bot = check_expr(fcx, rcvr); let expr_t = structurally_resolved_type(fcx, @@ -1329,7 +1331,8 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, fcx.node_ty(expr.callee_id), expr, args, - bot) + bot, + sugar) } // A generic function for checking for or for-each loops @@ -1378,13 +1381,11 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, op_ex.callee_id, opname, self_t, ~[], deref_args) { Some(ref origin) => { - let {fty: method_ty, bot: bot} = { - let method_ty = fcx.node_ty(op_ex.callee_id); - check_call_inner(fcx, op_ex.span, op_ex.id, - method_ty, op_ex, args, deref_args) - }; - fcx.ccx.method_map.insert(op_ex.id, (*origin)); - Some((ty::ty_fn_ret(method_ty), bot)) + let method_ty = fcx.node_ty(op_ex.callee_id); + fcx.ccx.method_map.insert(op_ex.id, *origin); + Some(check_call_inner(fcx, op_ex.span, op_ex.id, + method_ty, op_ex, args, + ast::NoSugar, deref_args)) } _ => None } @@ -1472,13 +1473,14 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, // If the or operator is used it might be that the user forgot to // supply the do keyword. Let's be more helpful in that situation. if op == ast::or { - match ty::get(lhs_resolved_t).sty { - ty::ty_fn(_) => { - tcx.sess.span_note( - ex.span, ~"did you forget the `do` keyword for the call?"); + match ty::get(lhs_resolved_t).sty { + ty::ty_bare_fn(_) | ty::ty_closure(_) => { + tcx.sess.span_note( + ex.span, ~"did you forget the `do` keyword \ + for the call?"); + } + _ => () } - _ => () - } } (lhs_resolved_t, false) @@ -1523,7 +1525,7 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, fn check_expr_fn(fcx: @fn_ctxt, expr: @ast::expr, - ast_proto_opt: Option, + ast_sigil_opt: Option, decl: &ast::fn_decl, body: ast::blk, fn_kind: FnKind, @@ -1534,50 +1536,44 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, // avoid capture of bound regions in the expected type. See // def'n of br_cap_avoid() for a more lengthy explanation of // what's going on here. - // Also try to pick up inferred purity and proto, defaulting + // Also try to pick up inferred purity and sigil, defaulting // to impure and block. Note that we only will use those for // block syntax lambdas; that is, lambdas without explicit - // protos. + // sigils. let expected_sty = unpack_expected(fcx, expected, |x| Some(copy *x)); let (expected_tys, expected_purity, - expected_proto, + expected_sigil, expected_onceness) = { match expected_sty { - Some(ty::ty_fn(ref fn_ty)) => { + Some(ty::ty_closure(ref cenv)) => { let id = expr.id; - let {fn_ty: fn_ty, _} = - replace_bound_regions_in_fn_ty( - tcx, @Nil, None, fn_ty, + let {fn_sig: sig, _} = + replace_bound_regions_in_fn_sig( + tcx, @Nil, None, &cenv.sig, |br| ty::re_bound(ty::br_cap_avoid(id, @br))); - (Some({inputs: /*bad*/copy fn_ty.sig.inputs, - output: fn_ty.sig.output}), - fn_ty.meta.purity, - fn_ty.meta.proto, - fn_ty.meta.onceness) + (Some(sig), cenv.purity, cenv.sigil, cenv.onceness) } _ => { - (None, ast::impure_fn, ast::ProtoBorrowed, ast::Many) + (None, ast::impure_fn, ast::BorrowedSigil, ast::Many) } } }; // If the proto is specified, use that, otherwise select a // proto based on inference. - let (proto, purity) = match ast_proto_opt { + let (sigil, purity) = match ast_sigil_opt { Some(p) => (p, ast::impure_fn), - None => (expected_proto, expected_purity) + None => (expected_sigil, expected_purity) }; // construct the function type - let mut fn_ty = astconv::ty_of_fn_decl( + let mut fn_ty = astconv::ty_of_closure( fcx, fcx, - proto, purity, expected_onceness, - /*bounds:*/ @~[], /*opt_region:*/ None, - *decl, expected_tys, expr.span); + sigil, purity, expected_onceness, + None, *decl, expected_tys, expr.span); - // XXX: Bad copy. - let fty = ty::mk_fn(tcx, copy fn_ty); + let fty = ty::mk_closure(tcx, copy fn_ty); debug!("check_expr_fn_with_unifier %s fty=%s", fcx.expr_to_str(expr), @@ -1587,8 +1583,8 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, // We inherit the same self info as the enclosing scope, // since the function we're checking might capture `self` - check_fn(fcx.ccx, fcx.self_info, &fn_ty, decl, body, - fn_kind, Some(fcx)); + check_fn(fcx.ccx, fcx.self_info, fn_ty.purity, Some(fn_ty.sigil), + &fn_ty.sig, decl, body, fn_kind, Some(fcx)); } @@ -1913,6 +1909,119 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, return bot; } + fn check_loop_body(fcx: @fn_ctxt, + expr: @ast::expr, + expected: Option, + loop_body: @ast::expr) + { + // a loop body is the special argument to a `for` loop. We know that + // there will be an expected type in this context because it can only + // appear in the context of a call, so we get the expected type of the + // parameter. The catch here is that we need to validate two things: + // 1. a closure that returns a bool is expected + // 2. the closure that was given returns unit + let tcx = fcx.tcx(); + let mut err_happened = false; + let expected_sty = unpack_expected(fcx, expected, |x| Some(copy *x)); + let inner_ty = match expected_sty { + Some(ty::ty_closure(ref fty)) => { + match fcx.mk_subty(false, expr.span, + fty.sig.output, ty::mk_bool(tcx)) { + result::Ok(_) => { + ty::mk_closure(tcx, ty::ClosureTy { + sig: FnSig {output: ty::mk_nil(tcx), + ..copy fty.sig}, + ..copy *fty + }) + } + result::Err(_) => { + fcx.type_error_message( + expr.span, + |actual| { + let did_you_mean = { + if ty::type_is_nil(fty.sig.output) { + "\nDid you mean to use \ + `do` instead of `for`?" + } else { + "" + } + }; + fmt!("A `for` loop iterator should expect a \ + closure that returns `bool`. This \ + iterator expects a closure that \ + returns `%s`.%s", + actual, did_you_mean) + }, + fty.sig.output, + None); + err_happened = true; + + // Kind of a hack: create a function type with + // the result replaced with ty_err, to + // suppress derived errors. + let t = ty::replace_closure_return_type( + tcx, ty::mk_closure(tcx, copy *fty), + ty::mk_err(tcx)); + fcx.write_ty(expr.id, ty::mk_err(tcx)); + t + } + } + } + _ => { + match expected { + Some(expected_t) => { + fcx.type_error_message( + expr.span, + |actual| { + fmt!("last argument in `for` call \ + has non-closure type: %s", + actual) + }, + expected_t, None); + let err_ty = ty::mk_err(tcx); + fcx.write_ty(expr.id, err_ty); + err_happened = true; + err_ty + } + None => fcx.tcx().sess.impossible_case( + expr.span, + ~"loop body must have an expected type") + } + } + }; + + match loop_body.node { + ast::expr_fn_block(ref decl, ref body) => { + // If an error occurred, we pretend this isn't a for + // loop, so as to assign types to all nodes while also + // propagating ty_err throughout so as to suppress + // derived errors. If we passed in ForLoop in the + // error case, we'd potentially emit a spurious error + // message because of the indirect_ret_ty. + let fn_kind = if err_happened {Vanilla} else {ForLoop}; + check_expr_fn(fcx, loop_body, None, + decl, *body, fn_kind, Some(inner_ty)); + demand::suptype(fcx, loop_body.span, + inner_ty, fcx.expr_ty(loop_body)); + } + ref n => { + die!(fmt!( + "check_loop_body expected expr_fn_block, not %?", n)) + } + } + + let block_ty = structurally_resolved_type( + fcx, expr.span, fcx.node_ty(loop_body.id)); + if err_happened { + fcx.write_ty(expr.id, ty::mk_err(fcx.tcx())); + } else { + let loop_body_ty = + ty::replace_closure_return_type( + tcx, block_ty, ty::mk_bool(tcx)); + fcx.write_ty(expr.id, loop_body_ty); + } + } + let tcx = fcx.ccx.tcx; let id = expr.id; let mut bot = false; @@ -2153,121 +2262,38 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, ast::expr_match(discrim, ref arms) => { bot = _match::check_match(fcx, expr, discrim, (/*bad*/copy *arms)); } - ast::expr_fn(proto, ref decl, ref body, _) => { - check_expr_fn(fcx, expr, Some(proto), + ast::expr_fn(sigil, ref decl, ref body, _) => { + check_expr_fn(fcx, expr, Some(sigil), decl, (*body), Vanilla, expected); } ast::expr_fn_block(ref decl, ref body) => { check_expr_fn(fcx, expr, None, decl, (*body), Vanilla, expected); } - ast::expr_loop_body(b) => { - // a loop body is the special argument to a `for` loop. We know that - // there will be an expected type in this context because it can only - // appear in the context of a call, so we get the expected type of the - // parameter. The catch here is that we need to validate two things: - // 1. a closure that returns a bool is expected - // 2. the closure that was given returns unit - let mut err_happened = false; - let expected_sty = unpack_expected(fcx, expected, |x| Some(copy *x)); - let inner_ty = match expected_sty { - Some(ty::ty_fn(ref fty)) => { - match fcx.mk_subty(false, expr.span, - (*fty).sig.output, ty::mk_bool(tcx)) { - result::Ok(_) => - ty::mk_fn(tcx, FnTyBase { - meta: (*fty).meta, - sig: FnSig {output: ty::mk_nil(tcx), - ../*bad*/copy (*fty).sig} - }), - result::Err(_) => { - fcx.type_error_message(expr.span, - |actual| { - fmt!("A `for` loop iterator should expect a \ - closure that returns `bool`. This iterator \ - expects a closure that returns `%s`. %s", - actual, if ty::type_is_nil((*fty).sig.output) { - "\nDid you mean to use `do` instead of \ - `for`?" } else { "" } ) - }, - (*fty).sig.output, None); - err_happened = true; - // Kind of a hack: create a function type with the result - // replaced with ty_err, to suppress derived errors. - let t = ty::replace_fn_return_type(tcx, ty::mk_fn(tcx, - copy *fty), - ty::mk_err(tcx)); - fcx.write_ty(id, ty::mk_err(tcx)); - t - } - } - } - _ => - match expected { - Some(expected_t) => { - fcx.type_error_message(expr.span, |actual| { - fmt!("a `loop` function's last \ - argument should be of function \ - type, not `%s`", - actual) - }, - expected_t, None); - let err_ty = ty::mk_err(tcx); - fcx.write_ty(id, err_ty); - err_happened = true; - err_ty - } - None => fcx.tcx().sess.impossible_case(expr.span, - ~"loop body must have an expected type") - } - }; - match b.node { - ast::expr_fn_block(ref decl, ref body) => { - // If an error occurred, we pretend this isn't a for - // loop, so as to assign types to all nodes while also - // propagating ty_err throughout so as to suppress - // derived errors. If we passed in ForLoop in the - // error case, we'd potentially emit a spurious error - // message because of the indirect_ret_ty. - let fn_kind = if err_happened { Vanilla } - else { ForLoop }; - check_expr_fn(fcx, b, None, - decl, *body, fn_kind, Some(inner_ty)); - demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b)); - } - // argh - _ => die!(~"expr_fn_block") - } - let block_ty = structurally_resolved_type( - fcx, expr.span, fcx.node_ty(b.id)); - if err_happened { - fcx.write_ty(expr.id, ty::mk_err(fcx.tcx())); - } else { - let loop_body_ty = ty::replace_fn_return_type(tcx, block_ty, - ty::mk_bool(tcx)); - fcx.write_ty(expr.id, loop_body_ty); - } + ast::expr_loop_body(loop_body) => { + check_loop_body(fcx, expr, expected, loop_body); } ast::expr_do_body(b) => { let expected_sty = unpack_expected(fcx, expected, |x| Some(copy *x)); let inner_ty = match expected_sty { - Some(ty::ty_fn(ref fty)) => { - ty::mk_fn(tcx, (/*bad*/copy *fty)) - } - _ => match expected { - Some(expected_t) => { - fcx.type_error_message(expr.span, |_actual| { - ~"Non-function passed to a `do` \ - function as its last argument, or wrong number \ - of arguments passed to a `do` function" - }, expected_t, None); - let err_ty = ty::mk_err(tcx); - fcx.write_ty(id, err_ty); - err_ty - } - None => fcx.tcx().sess.impossible_case(expr.span, - ~"do body must have expected type") - } + Some(ty::ty_closure(_)) => expected.get(), + _ => match expected { + Some(expected_t) => { + fcx.type_error_message(expr.span, |actual| { + fmt!("last argument in `do` call \ + has non-closure type: %s", + actual) + }, expected_t, None); + let err_ty = ty::mk_err(tcx); + fcx.write_ty(id, err_ty); + err_ty + } + None => { + fcx.tcx().sess.impossible_case( + expr.span, + ~"do body must have expected type") + } + } }; match b.node { ast::expr_fn_block(ref decl, ref body) => { @@ -2290,11 +2316,11 @@ pub fn check_expr_with_unifier(fcx: @fn_ctxt, }; fcx.write_ty(id, typ); } - ast::expr_call(f, args, _) => { - bot = check_call(fcx, expr.span, expr.id, f, args); + ast::expr_call(f, args, sugar) => { + bot = check_call(fcx, expr.span, expr.id, f, args, sugar); } - ast::expr_method_call(rcvr, ident, tps, args, _) => { - bot = check_method_call(fcx, expr, rcvr, ident, args, tps); + ast::expr_method_call(rcvr, ident, tps, args, sugar) => { + bot = check_method_call(fcx, expr, rcvr, ident, args, tps, sugar); } ast::expr_cast(e, t) => { bot = check_expr(fcx, e); @@ -3088,20 +3114,18 @@ pub fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) { arg(ast::by_ref, visitor_trait)], ty::mk_nil(tcx)) } ~"frame_address" => { - let fty = ty::mk_fn(ccx.tcx, FnTyBase { - meta: FnMeta {purity: ast::impure_fn, - proto: ast::ProtoBorrowed, - onceness: ast::Once, - region: ty::re_bound(ty::br_anon(0)), - bounds: @~[]}, - sig: FnSig { - inputs: ~[arg { - mode: ast::expl(ast::by_val), - ty: ty::mk_imm_ptr( - ccx.tcx, - ty::mk_mach_uint(ccx.tcx, ast::ty_u8)) - }], - output: ty::mk_nil(ccx.tcx)} + let fty = ty::mk_closure(ccx.tcx, ty::ClosureTy { + purity: ast::impure_fn, + sigil: ast::BorrowedSigil, + onceness: ast::Once, + region: ty::re_bound(ty::br_anon(0)), + sig: ty::FnSig { + inputs: ~[arg {mode: ast::expl(ast::by_val), + ty: ty::mk_imm_ptr( + ccx.tcx, + ty::mk_mach_uint(ccx.tcx, ast::ty_u8))}], + output: ty::mk_nil(ccx.tcx) + } }); (0u, ~[arg(ast::by_ref, fty)], ty::mk_nil(tcx)) } @@ -3324,12 +3348,9 @@ pub fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) { return; } }; - let fty = ty::mk_fn(tcx, FnTyBase { - meta: FnMeta {purity: ast::unsafe_fn, - proto: ast::ProtoBare, - onceness: ast::Many, - region: ty::re_static, - bounds: @~[]}, + let fty = ty::mk_bare_fn(tcx, ty::BareFnTy { + purity: ast::unsafe_fn, + abi: ast::RustAbi, sig: FnSig {inputs: inputs, output: output} }); diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 952c1a9fcd8..9dfaaeebc8f 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -32,7 +32,7 @@ use core::prelude::*; use middle::freevars::get_freevars; use middle::pat_util::{pat_bindings, pat_is_binding}; use middle::ty::{encl_region, re_scope}; -use middle::ty::{ty_fn_proto, vstore_box, vstore_fixed, vstore_slice}; +use middle::ty::{vstore_box, vstore_fixed, vstore_slice}; use middle::ty::{vstore_uniq}; use middle::ty; use middle::typeck::check::fn_ctxt; @@ -42,7 +42,7 @@ use middle::typeck::infer::{resolve_type}; use util::ppaux::{note_and_explain_region, ty_to_str}; use core::result; -use syntax::ast::{ProtoBare, ProtoBox, ProtoUniq, ProtoBorrowed}; +use syntax::ast::{ManagedSigil, OwnedSigil, BorrowedSigil}; use syntax::ast::{def_arg, def_binding, def_local, def_self, def_upvar}; use syntax::ast; use syntax::codemap::span; @@ -59,10 +59,9 @@ pub fn encl_region_of_def(fcx: @fn_ctxt, def: ast::def) -> ty::Region { def_self(node_id, _) | def_binding(node_id, _) => return encl_region(tcx, node_id), def_upvar(_, subdef, closure_id, body_id) => { - match ty_fn_proto(fcx.node_ty(closure_id)) { - ProtoBare => tcx.sess.bug(~"ProtoBare with upvars?!"), - ProtoBorrowed => encl_region_of_def(fcx, *subdef), - ProtoBox | ProtoUniq => re_scope(body_id) + match ty::ty_closure_sigil(fcx.node_ty(closure_id)) { + BorrowedSigil => encl_region_of_def(fcx, *subdef), + ManagedSigil | OwnedSigil => re_scope(body_id) } } _ => { @@ -278,11 +277,9 @@ pub fn visit_expr(expr: @ast::expr, &&rcx: @rcx, v: rvt) { ast::expr_fn(*) | ast::expr_fn_block(*) => { let function_type = rcx.resolve_node_type(expr.id); match ty::get(function_type).sty { - ty::ty_fn(ref fn_ty) => { - if fn_ty.meta.proto == ast::ProtoBorrowed { - constrain_free_variables( - rcx, fn_ty.meta.region, expr); - } + ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil, + region: region, _}) => { + constrain_free_variables(rcx, region, expr); } _ => () } diff --git a/src/librustc/middle/typeck/check/regionmanip.rs b/src/librustc/middle/typeck/check/regionmanip.rs index 8ea35824e32..f0956df545c 100644 --- a/src/librustc/middle/typeck/check/regionmanip.rs +++ b/src/librustc/middle/typeck/check/regionmanip.rs @@ -12,7 +12,6 @@ use core::prelude::*; -use middle::ty::{FnTyBase}; use middle::ty; use middle::typeck::check::self_info; use middle::typeck::isr_alist; @@ -27,22 +26,6 @@ use syntax::print::pprust::{expr_to_str}; // Helper functions related to manipulating region types. -pub fn replace_bound_regions_in_fn_ty( - tcx: ty::ctxt, - isr: isr_alist, - self_info: Option, - fn_ty: &ty::FnTy, - mapf: fn(ty::bound_region) -> ty::Region) -> - {isr: isr_alist, self_info: Option, fn_ty: ty::FnTy} { - let {isr, self_info, fn_sig} = - replace_bound_regions_in_fn_sig( - tcx, isr, self_info, &fn_ty.sig, mapf); - {isr: isr, - self_info: self_info, - fn_ty: FnTyBase {meta: fn_ty.meta, - sig: fn_sig}} -} - pub fn replace_bound_regions_in_fn_sig( tcx: ty::ctxt, isr: isr_alist, diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 9f2af3ec003..abd4697eb31 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -233,7 +233,7 @@ pub fn lookup_vtable(vcx: &VtableContext, relate_trait_tys(vcx, location_info, trait_ty, ty); if !allow_unsafe && !is_early { for vec::each(*ty::trait_methods(tcx, did)) |m| { - if ty::type_has_self(ty::mk_fn(tcx, /*bad*/copy m.fty)) { + if ty::type_has_self(ty::mk_bare_fn(tcx, copy m.fty)) { tcx.sess.span_err( location_info.span, ~"a boxed trait with self types may not be \ diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 324cdcc261f..8fc8c4f6cbb 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -26,10 +26,10 @@ use middle::resolve::{Impl, MethodInfo}; use middle::ty::{ProvidedMethodSource, ProvidedMethodInfo, bound_copy, get}; use middle::ty::{kind_can_be_copied, lookup_item_type, param_bounds, subst}; use middle::ty::{substs, t, ty_bool, ty_bot, ty_box, ty_enum, ty_err}; -use middle::ty::{ty_estr, ty_evec, ty_float, ty_fn, ty_infer, ty_int, ty_nil}; +use middle::ty::{ty_estr, ty_evec, ty_float, ty_infer, ty_int, ty_nil}; use middle::ty::{ty_opaque_box, ty_param, ty_param_bounds_and_ty, ty_ptr}; use middle::ty::{ty_rec, ty_rptr, ty_self, ty_struct, ty_trait, ty_tup}; -use middle::ty::{ty_type, ty_uint, ty_uniq}; +use middle::ty::{ty_type, ty_uint, ty_uniq, ty_bare_fn, ty_closure}; use middle::ty::{ty_opaque_closure_ptr, ty_unboxed_vec, type_kind_ext}; use middle::ty::{type_is_ty_var}; use middle::ty; @@ -108,7 +108,7 @@ pub fn get_base_type(inference_context: @InferCtxt, ty_nil | ty_bot | ty_bool | ty_int(*) | ty_uint(*) | ty_float(*) | ty_estr(*) | ty_evec(*) | ty_rec(*) | - ty_fn(*) | ty_tup(*) | ty_infer(*) | + ty_bare_fn(*) | ty_closure(*) | ty_tup(*) | ty_infer(*) | ty_param(*) | ty_self | ty_type | ty_opaque_box | ty_opaque_closure_ptr(*) | ty_unboxed_vec(*) | ty_err => { debug!("(getting base type) no base type; found %?", diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index b7b7899883b..120fd89e5eb 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -33,10 +33,10 @@ are represented as `ty_param()` instances. use core::prelude::*; use metadata::csearch; -use middle::ty::{FnMeta, FnSig, FnTyBase, InstantiatedTraitRef, arg}; +use middle::ty::{InstantiatedTraitRef, arg}; use middle::ty::{substs, ty_param_substs_and_ty}; use middle::ty; -use middle::typeck::astconv::{ast_conv, ty_of_fn_decl, ty_of_arg}; +use middle::typeck::astconv::{ast_conv, ty_of_arg}; use middle::typeck::astconv::{ast_ty_to_ty}; use middle::typeck::astconv; use middle::typeck::infer; @@ -153,9 +153,10 @@ pub impl @crate_ctxt: ast_conv { pub fn get_enum_variant_types(ccx: @crate_ctxt, enum_ty: ty::t, - variants: ~[ast::variant], - ty_params: ~[ast::ty_param], - rp: Option) { + variants: &[ast::variant], + ty_params: &[ast::ty_param], + rp: Option) +{ let tcx = ccx.tcx; // Create a set of parameter types shared among all the variants. @@ -166,58 +167,35 @@ pub fn get_enum_variant_types(ccx: @crate_ctxt, match variant.node.kind { ast::tuple_variant_kind(ref args) if args.len() > 0 => { let rs = type_rscope(rp); - let args = args.map(|va| { - let arg_ty = ccx.to_ty(rs, va.ty); - arg { mode: ast::expl(ast::by_copy), ty: arg_ty } - }); - result_ty = Some(ty::mk_fn(tcx, FnTyBase { - meta: FnMeta {purity: ast::pure_fn, - proto: ast::ProtoBare, - onceness: ast::Many, - bounds: @~[], - region: ty::re_static}, - sig: FnSig {inputs: args, - output: enum_ty} - })); + let input_tys = args.map(|va| ccx.to_ty(rs, va.ty)); + result_ty = Some(ty::mk_ctor_fn(tcx, input_tys, enum_ty)); } + ast::tuple_variant_kind(_) => { result_ty = Some(enum_ty); } + ast::struct_variant_kind(struct_def) => { - // XXX: Merge with computation of the the same value below? - let tpt = { - bounds: ty_param_bounds(ccx, /*bad*/copy ty_params), - region_param: rp, - ty: enum_ty - }; - convert_struct( - ccx, - rp, - struct_def, - /*bad*/copy ty_params, - tpt, - variant.node.id); - // Compute the ctor arg types from the struct fields - let struct_fields = do struct_def.fields.map |struct_field| { - arg { - mode: ast::expl(ast::by_val), - ty: ty::node_id_to_type(ccx.tcx, struct_field.node.id) - } - }; - result_ty = Some(ty::mk_fn(tcx, FnTyBase { - meta: FnMeta {purity: ast::pure_fn, - proto: ast::ProtoBare, - onceness: ast::Many, - bounds: @~[], - region: ty::re_static}, - sig: FnSig {inputs: struct_fields, output: enum_ty }})); + let tpt = {bounds: ty_param_bounds(ccx, ty_params), + region_param: rp, + ty: enum_ty}; + + convert_struct(ccx, + rp, + struct_def, + ty_params.to_vec(), + tpt, + variant.node.id); + + let input_tys = struct_def.fields.map( + |f| ty::node_id_to_type(ccx.tcx, f.node.id)); + result_ty = Some(ty::mk_ctor_fn(tcx, input_tys, enum_ty)); } + ast::enum_variant_kind(ref enum_definition) => { - get_enum_variant_types(ccx, - enum_ty, - /*bad*/copy enum_definition.variants, - /*bad*/copy ty_params, - rp); + get_enum_variant_types(ccx, enum_ty, + enum_definition.variants, + ty_params, rp); result_ty = None; } }; @@ -225,11 +203,9 @@ pub fn get_enum_variant_types(ccx: @crate_ctxt, match result_ty { None => {} Some(result_ty) => { - let tpt = { - bounds: ty_param_bounds(ccx, /*bad*/copy ty_params), - region_param: rp, - ty: result_ty - }; + let tpt = {bounds: ty_param_bounds(ccx, ty_params), + region_param: rp, + ty: result_ty}; tcx.tcache.insert(local_def(variant.node.id), tpt); write_ty_to_tcx(tcx, variant.node.id, result_ty); } @@ -279,7 +255,7 @@ pub fn ensure_trait_methods(ccx: @crate_ctxt, }; let ty = ty::subst(ccx.tcx, &substs, - ty::mk_fn(ccx.tcx, /*bad*/copy m.fty)); + ty::mk_bare_fn(ccx.tcx, copy m.fty)); let bounds = @(*trait_bounds + ~[@~[ty::bound_trait(trait_ty)]] + *m.tps); ccx.tcx.tcache.insert(local_def(am.id), @@ -305,7 +281,7 @@ pub fn ensure_trait_methods(ccx: @crate_ctxt, ast::provided(method) => def_id = local_def(method.id) } - let trait_bounds = ty_param_bounds(ccx, copy *params); + let trait_bounds = ty_param_bounds(ccx, *params); let ty_m = trait_method_to_ty_method(*m); let method_ty = ty_of_ty_method(ccx, ty_m, region_paramd, def_id); if ty_m.self_ty.node == ast::sty_static { @@ -458,7 +434,7 @@ pub fn compare_impl_method(tcx: ty::ctxt, // that correspond to the parameters we will find on the impl // - replace self region with a fresh, dummy region let impl_fty = { - let impl_fty = ty::mk_fn(tcx, /*bad*/copy impl_m.fty); + let impl_fty = ty::mk_bare_fn(tcx, copy impl_m.fty); debug!("impl_fty (pre-subst): %s", ppaux::ty_to_str(tcx, impl_fty)); replace_bound_self(tcx, impl_fty, dummy_self_r) }; @@ -476,7 +452,7 @@ pub fn compare_impl_method(tcx: ty::ctxt, self_ty: Some(self_ty), tps: vec::append(trait_tps, dummy_tps) }; - let trait_fty = ty::mk_fn(tcx, /*bad*/copy trait_m.fty); + let trait_fty = ty::mk_bare_fn(tcx, copy trait_m.fty); debug!("trait_fty (pre-subst): %s", ppaux::ty_to_str(tcx, trait_fty)); ty::subst(tcx, &substs, trait_fty) }; @@ -583,9 +559,9 @@ pub fn convert_methods(ccx: @crate_ctxt, let tcx = ccx.tcx; do vec::map(ms) |m| { - let bounds = ty_param_bounds(ccx, /*bad*/copy m.tps); + let bounds = ty_param_bounds(ccx, m.tps); let mty = ty_of_method(ccx, *m, rp); - let fty = ty::mk_fn(tcx, /*bad*/copy mty.fty); + let fty = ty::mk_bare_fn(tcx, copy mty.fty); tcx.tcache.insert( local_def(m.id), @@ -626,13 +602,11 @@ pub fn convert(ccx: @crate_ctxt, it: @ast::item) { ensure_no_ty_param_bounds(ccx, it.span, *ty_params, "enumeration"); let tpt = ty_of_item(ccx, it); write_ty_to_tcx(tcx, it.id, tpt.ty); - get_enum_variant_types(ccx, - tpt.ty, - /*bad*/copy (*enum_definition).variants, - /*bad*/copy *ty_params, rp); + get_enum_variant_types(ccx, tpt.ty, enum_definition.variants, + *ty_params, rp); } ast::item_impl(ref tps, trait_ref, selfty, ref ms) => { - let i_bounds = ty_param_bounds(ccx, /*bad*/copy *tps); + let i_bounds = ty_param_bounds(ccx, *tps); let selfty = ccx.to_ty(type_rscope(rp), selfty); write_ty_to_tcx(tcx, it.id, selfty); tcx.tcache.insert(local_def(it.id), @@ -695,13 +669,12 @@ pub fn convert_struct(ccx: @crate_ctxt, do option::iter(&struct_def.dtor) |dtor| { // Write the dtor type - let t_dtor = ty::mk_fn( + let t_dtor = ty::mk_bare_fn( tcx, - ty_of_fn_decl( - ccx, type_rscope(rp), ast::ProtoBare, - ast::impure_fn, ast::Many, - /*bounds:*/ @~[], /*opt_region:*/ None, - ast_util::dtor_dec(), None, dtor.span)); + astconv::ty_of_bare_fn( + ccx, type_rscope(rp), + ast::impure_fn, ast::RustAbi, + ast_util::dtor_dec())); write_ty_to_tcx(tcx, dtor.node.id, t_dtor); tcx.tcache.insert(local_def(dtor.node.id), {bounds: tpt.bounds, @@ -727,25 +700,11 @@ pub fn convert_struct(ccx: @crate_ctxt, tcx.tcache.insert(local_def(ctor_id), tpt); } else if struct_def.fields[0].node.kind == ast::unnamed_field { // Tuple-like. - let ctor_fn_ty = ty::mk_fn(tcx, FnTyBase { - meta: FnMeta { - purity: ast::pure_fn, - proto: ast::ProtoBare, - onceness: ast::Many, - bounds: @~[], - region: ty::re_static - }, - sig: FnSig { - inputs: do struct_def.fields.map |field| { - arg { - mode: ast::expl(ast::by_copy), - ty: ccx.tcx.tcache.get - (&local_def(field.node.id)).ty - } - }, - output: selfty - } - }); + let inputs = + struct_def.fields.map( + |field| ccx.tcx.tcache.get( + &local_def(field.node.id)).ty); + let ctor_fn_ty = ty::mk_ctor_fn(tcx, inputs, selfty); write_ty_to_tcx(tcx, ctor_id, ctor_fn_ty); tcx.tcache.insert(local_def(ctor_id), { bounds: tpt.bounds, @@ -770,11 +729,9 @@ pub fn ty_of_method(ccx: @crate_ctxt, m: @ast::method, rp: Option) -> ty::method { {ident: m.ident, - tps: ty_param_bounds(ccx, /*bad*/copy m.tps), - fty: ty_of_fn_decl(ccx, type_rscope(rp), ast::ProtoBare, - m.purity, ast::Many, - /*bounds:*/ @~[], /*opt_region:*/ None, - m.decl, None, m.span), + tps: ty_param_bounds(ccx, m.tps), + fty: astconv::ty_of_bare_fn(ccx, type_rscope(rp), m.purity, + ast::RustAbi, m.decl), self_ty: m.self_ty.node, vis: m.vis, def_id: local_def(m.id)} @@ -785,11 +742,9 @@ pub fn ty_of_ty_method(self: @crate_ctxt, rp: Option, id: ast::def_id) -> ty::method { {ident: m.ident, - tps: ty_param_bounds(self, /*bad*/copy m.tps), - fty: ty_of_fn_decl(self, type_rscope(rp), ast::ProtoBare, - m.purity, ast::Many, - /*bounds:*/ @~[], /*opt_region:*/ None, - m.decl, None, m.span), + tps: ty_param_bounds(self, m.tps), + fty: astconv::ty_of_bare_fn(self, type_rscope(rp), m.purity, + ast::RustAbi, m.decl), // assume public, because this is only invoked on trait methods self_ty: m.self_ty.node, vis: ast::public, @@ -844,13 +799,11 @@ pub fn ty_of_item(ccx: @crate_ctxt, it: @ast::item) } ast::item_fn(decl, purity, tps, _) => { let bounds = ty_param_bounds(ccx, tps); - let tofd = ty_of_fn_decl(ccx, empty_rscope, - ast::ProtoBare, purity, ast::Many, - /*bounds:*/ @~[], /*opt_region:*/ None, - decl, None, it.span); + let tofd = astconv::ty_of_bare_fn(ccx, empty_rscope, purity, + ast::RustAbi, decl); let tpt = {bounds: bounds, region_param: None, - ty: ty::mk_fn(ccx.tcx, tofd)}; + ty: ty::mk_bare_fn(ccx.tcx, tofd)}; debug!("type of %s (id %d) is %s", tcx.sess.str_of(it.ident), it.id, @@ -976,7 +929,7 @@ pub fn compute_bounds(ccx: @crate_ctxt, } pub fn ty_param_bounds(ccx: @crate_ctxt, - params: ~[ast::ty_param]) -> @~[ty::param_bounds] { + params: &[ast::ty_param]) -> @~[ty::param_bounds] { @do params.map |param| { match ccx.tcx.ty_param_bounds.find(¶m.id) { Some(bs) => bs, @@ -999,15 +952,13 @@ pub fn ty_of_foreign_fn_decl(ccx: @crate_ctxt, let input_tys = decl.inputs.map(|a| ty_of_arg(ccx, rb, *a, None) ); let output_ty = ast_ty_to_ty(ccx, rb, decl.output); - let t_fn = ty::mk_fn(ccx.tcx, FnTyBase { - meta: FnMeta {purity: ast::unsafe_fn, - onceness: ast::Many, - proto: ast::ProtoBare, - bounds: @~[], - region: ty::re_static}, - sig: FnSig {inputs: input_tys, - output: output_ty} - }); + let t_fn = ty::mk_bare_fn( + ccx.tcx, + ty::BareFnTy { + abi: ast::RustAbi, + purity: ast::unsafe_fn, + sig: ty::FnSig {inputs: input_tys, output: output_ty} + }); let tpt = {bounds: bounds, region_param: None, ty: t_fn}; ccx.tcx.tcache.insert(def_id, tpt); return tpt; @@ -1017,8 +968,7 @@ pub fn mk_ty_params(ccx: @crate_ctxt, atps: ~[ast::ty_param]) -> {bounds: @~[ty::param_bounds], params: ~[ty::t]} { let mut i = 0u; - // XXX: Bad copy. - let bounds = ty_param_bounds(ccx, copy atps); + let bounds = ty_param_bounds(ccx, atps); {bounds: bounds, params: vec::map(atps, |atp| { let t = ty::mk_param(ccx.tcx, i, local_def(atp.id)); diff --git a/src/librustc/middle/typeck/infer/coercion.rs b/src/librustc/middle/typeck/infer/coercion.rs index f0fe2deffdf..5d291fdde77 100644 --- a/src/librustc/middle/typeck/infer/coercion.rs +++ b/src/librustc/middle/typeck/infer/coercion.rs @@ -69,7 +69,7 @@ use core::prelude::*; use middle::ty::{TyVar, AutoPtr, AutoBorrowVec, AutoBorrowFn}; use middle::ty::{AutoAdjustment, AutoRef}; use middle::ty::{vstore_slice, vstore_box, vstore_uniq, vstore_fixed}; -use middle::ty::{FnMeta, FnTyBase, mt}; +use middle::ty::{mt}; use middle::ty; use middle::typeck::infer::{CoerceResult, resolve_type}; use middle::typeck::infer::combine::CombineFields; @@ -117,7 +117,7 @@ impl Coerce { }; } - ty::ty_fn(ref b_f) if b_f.meta.proto == ast::ProtoBorrowed => { + ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil, _}) => { return do self.unpack_actual_value(a) |sty_a| { self.coerce_borrowed_fn(a, sty_a, b) }; @@ -134,7 +134,7 @@ impl Coerce { do self.unpack_actual_value(a) |sty_a| { match *sty_a { - ty::ty_fn(ref a_f) if a_f.meta.proto == ast::ProtoBare => { + ty::ty_bare_fn(ref a_f) => { // Bare functions are coercable to any closure type. // // FIXME(#3320) this should go away and be @@ -289,9 +289,9 @@ impl Coerce { b.inf_str(self.infcx)); let fn_ty = match *sty_a { - ty::ty_fn(ref f) if f.meta.proto == ast::ProtoBox => {f} - ty::ty_fn(ref f) if f.meta.proto == ast::ProtoUniq => {f} - ty::ty_fn(ref f) if f.meta.proto == ast::ProtoBare => { + ty::ty_closure(ref f) if f.sigil == ast::ManagedSigil => copy *f, + ty::ty_closure(ref f) if f.sigil == ast::OwnedSigil => copy *f, + ty::ty_bare_fn(ref f) => { return self.coerce_from_bare_fn(a, f, b); } _ => { @@ -300,12 +300,13 @@ impl Coerce { }; let r_borrow = self.infcx.next_region_var_nb(self.span); - let meta = FnMeta {proto: ast::ProtoBorrowed, - region: r_borrow, - ..fn_ty.meta}; - let a_borrowed = ty::mk_fn(self.infcx.tcx, - FnTyBase {meta: meta, - sig: copy fn_ty.sig}); + let a_borrowed = ty::mk_closure( + self.infcx.tcx, + ty::ClosureTy { + sigil: ast::BorrowedSigil, + region: r_borrow, + ..fn_ty + }); if_ok!(self.subtype(a_borrowed, b)); Ok(Some(@AutoAdjustment { @@ -320,7 +321,7 @@ impl Coerce { fn coerce_from_bare_fn(&self, a: ty::t, - fn_ty_a: &ty::FnTy, + fn_ty_a: &ty::BareFnTy, b: ty::t) -> CoerceResult { do self.unpack_actual_value(b) |sty_b| { @@ -330,7 +331,7 @@ impl Coerce { fn coerce_from_bare_fn_post_unpack(&self, a: ty::t, - fn_ty_a: &ty::FnTy, + fn_ty_a: &ty::BareFnTy, b: ty::t, sty_b: &ty::sty) -> CoerceResult { @@ -338,18 +339,18 @@ impl Coerce { a.inf_str(self.infcx), b.inf_str(self.infcx)); let fn_ty_b = match *sty_b { - ty::ty_fn(ref f) if f.meta.proto != ast::ProtoBare => {f} + ty::ty_closure(ref f) => {copy *f} _ => { return self.subtype(a, b); } }; - // for now, bare fn and closures have the same - // representation - let a_adapted = ty::mk_fn(self.infcx.tcx, - FnTyBase {meta: copy fn_ty_b.meta, - sig: copy fn_ty_a.sig}); - self.subtype(a_adapted, b) + // for now, bare fn and closures have the same + // representation + let a_closure = ty::mk_closure( + self.infcx.tcx, + ty::ClosureTy {sig: copy fn_ty_a.sig, ..fn_ty_b}); + self.subtype(a_closure, b) } fn coerce_unsafe_ptr(&self, diff --git a/src/librustc/middle/typeck/infer/combine.rs b/src/librustc/middle/typeck/infer/combine.rs index 819348e744e..7737327bc0c 100644 --- a/src/librustc/middle/typeck/infer/combine.rs +++ b/src/librustc/middle/typeck/infer/combine.rs @@ -56,7 +56,7 @@ use core::prelude::*; -use middle::ty::{FloatVar, FnTyBase, FnMeta, FnSig, IntVar, TyVar}; +use middle::ty::{FloatVar, FnSig, IntVar, TyVar}; use middle::ty::{IntType, UintType, arg, substs}; use middle::ty; use middle::typeck::infer::glb::Glb; @@ -94,14 +94,17 @@ pub trait Combine { fn self_tys(a: Option, b: Option) -> cres>; fn substs(did: ast::def_id, as_: &ty::substs, bs: &ty::substs) -> cres; - fn fns(a: &ty::FnTy, b: &ty::FnTy) -> cres; + fn bare_fn_tys(a: &ty::BareFnTy, + b: &ty::BareFnTy) -> cres; + fn closure_tys(a: &ty::ClosureTy, + b: &ty::ClosureTy) -> cres; fn fn_sigs(a: &ty::FnSig, b: &ty::FnSig) -> cres; - fn fn_metas(a: &ty::FnMeta, b: &ty::FnMeta) -> cres; fn flds(a: ty::field, b: ty::field) -> cres; fn modes(a: ast::mode, b: ast::mode) -> cres; fn args(a: ty::arg, b: ty::arg) -> cres; - fn protos(p1: ast::Proto, p2: ast::Proto) -> cres; + fn sigils(p1: ast::Sigil, p2: ast::Sigil) -> cres; fn purities(a: purity, b: purity) -> cres; + fn abis(a: ast::Abi, b: ast::Abi) -> cres; fn oncenesses(a: Onceness, b: Onceness) -> cres; fn contraregions(a: ty::Region, b: ty::Region) -> cres; fn regions(a: ty::Region, b: ty::Region) -> cres; @@ -287,12 +290,12 @@ pub fn super_self_tys( } } -pub fn super_protos( - self: &C, p1: ast::Proto, p2: ast::Proto) -> cres { +pub fn super_sigils( + self: &C, p1: ast::Sigil, p2: ast::Sigil) -> cres { if p1 == p2 { Ok(p1) } else { - Err(ty::terr_proto_mismatch(expected_found(self, p1, p2))) + Err(ty::terr_sigil_mismatch(expected_found(self, p1, p2))) } } @@ -350,21 +353,45 @@ pub fn super_vstores( } } -pub fn super_fn_metas( - self: &C, a_f: &ty::FnMeta, b_f: &ty::FnMeta) -> cres { - let p = if_ok!(self.protos(a_f.proto, b_f.proto)); +pub fn super_closure_tys( + self: &C, a_f: &ty::ClosureTy, b_f: &ty::ClosureTy) -> cres +{ + let p = if_ok!(self.sigils(a_f.sigil, b_f.sigil)); let r = if_ok!(self.contraregions(a_f.region, b_f.region)); let purity = if_ok!(self.purities(a_f.purity, b_f.purity)); let onceness = if_ok!(self.oncenesses(a_f.onceness, b_f.onceness)); - Ok(FnMeta {purity: purity, - proto: p, - onceness: onceness, - region: r, - bounds: a_f.bounds}) // XXX: This is wrong! + let sig = if_ok!(self.fn_sigs(&a_f.sig, &b_f.sig)); + Ok(ty::ClosureTy {purity: purity, + sigil: p, + onceness: onceness, + region: r, + sig: sig}) +} + +pub fn super_abis( + self: &C, a: ast::Abi, b: ast::Abi) -> cres +{ + if a == b { + Ok(a) + } else { + Err(ty::terr_abi_mismatch(expected_found(self, a, b))) + } +} + +pub fn super_bare_fn_tys( + self: &C, a_f: &ty::BareFnTy, b_f: &ty::BareFnTy) -> cres +{ + let purity = if_ok!(self.purities(a_f.purity, b_f.purity)); + let abi = if_ok!(self.abis(a_f.abi, b_f.abi)); + let sig = if_ok!(self.fn_sigs(&a_f.sig, &b_f.sig)); + Ok(ty::BareFnTy {purity: purity, + abi: abi, + sig: sig}) } pub fn super_fn_sigs( - self: &C, a_f: &ty::FnSig, b_f: &ty::FnSig) -> cres { + self: &C, a_f: &ty::FnSig, b_f: &ty::FnSig) -> cres +{ fn argvecs(self: &C, +a_args: ~[ty::arg], +b_args: ~[ty::arg]) -> cres<~[ty::arg]> @@ -384,13 +411,6 @@ pub fn super_fn_sigs( } } -pub fn super_fns( - self: &C, a_f: &ty::FnTy, b_f: &ty::FnTy) -> cres { - let m = if_ok!(self.fn_metas(&a_f.meta, &b_f.meta)); - let s = if_ok!(self.fn_sigs(&a_f.sig, &b_f.sig)); - Ok(FnTyBase {meta: m, sig: s}) -} - pub fn super_tys( self: &C, a: ty::t, b: ty::t) -> cres { let tcx = self.infcx().tcx; @@ -551,9 +571,15 @@ pub fn super_tys( } } - (ty::ty_fn(ref a_fty), ty::ty_fn(ref b_fty)) => { - do self.fns(a_fty, b_fty).chain |fty| { - Ok(ty::mk_fn(tcx, fty)) + (ty::ty_bare_fn(ref a_fty), ty::ty_bare_fn(ref b_fty)) => { + do self.bare_fn_tys(a_fty, b_fty).chain |fty| { + Ok(ty::mk_bare_fn(tcx, fty)) + } + } + + (ty::ty_closure(ref a_fty), ty::ty_closure(ref b_fty)) => { + do self.closure_tys(a_fty, b_fty).chain |fty| { + Ok(ty::mk_closure(tcx, fty)) } } diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index 58d9f1019ae..382d5f24cc7 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -267,16 +267,22 @@ pub impl Glb: Combine { } } - fn protos(p1: ast::Proto, p2: ast::Proto) -> cres { - super_protos(&self, p1, p2) + fn sigils(p1: ast::Sigil, p2: ast::Sigil) -> cres { + super_sigils(&self, p1, p2) } - fn fns(a: &ty::FnTy, b: &ty::FnTy) -> cres { - super_fns(&self, a, b) + fn abis(p1: ast::Abi, p2: ast::Abi) -> cres { + super_abis(&self, p1, p2) } - fn fn_metas(a: &ty::FnMeta, b: &ty::FnMeta) -> cres { - super_fn_metas(&self, a, b) + fn bare_fn_tys(a: &ty::BareFnTy, + b: &ty::BareFnTy) -> cres { + super_bare_fn_tys(&self, a, b) + } + + fn closure_tys(a: &ty::ClosureTy, + b: &ty::ClosureTy) -> cres { + super_closure_tys(&self, a, b) } fn substs(did: ast::def_id, diff --git a/src/librustc/middle/typeck/infer/lattice.rs b/src/librustc/middle/typeck/infer/lattice.rs index 4f7bedd8149..4bf8a0bae86 100644 --- a/src/librustc/middle/typeck/infer/lattice.rs +++ b/src/librustc/middle/typeck/infer/lattice.rs @@ -71,23 +71,6 @@ pub impl ty::t: LatticeValue { } } -pub impl FnMeta: LatticeValue { - static fn sub(cf: &CombineFields, - a: &FnMeta, b: &FnMeta) -> ures { - Sub(*cf).fn_metas(a, b).to_ures() - } - - static fn lub(cf: &CombineFields, - a: &FnMeta, b: &FnMeta) -> cres { - Lub(*cf).fn_metas(a, b) - } - - static fn glb(cf: &CombineFields, - a: &FnMeta, b: &FnMeta) -> cres { - Glb(*cf).fn_metas(a, b) - } -} - pub impl CombineFields { fn var_sub_var>>( diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/typeck/infer/lub.rs index f24d245db58..44ad367c9dc 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/typeck/infer/lub.rs @@ -191,18 +191,24 @@ pub impl Lub: Combine { } } - fn fns(a: &ty::FnTy, b: &ty::FnTy) -> cres { - super_fns(&self, a, b) + fn bare_fn_tys(a: &ty::BareFnTy, + b: &ty::BareFnTy) -> cres { + super_bare_fn_tys(&self, a, b) } - fn fn_metas(a: &ty::FnMeta, b: &ty::FnMeta) -> cres { - super_fn_metas(&self, a, b) + fn closure_tys(a: &ty::ClosureTy, + b: &ty::ClosureTy) -> cres { + super_closure_tys(&self, a, b) } // Traits please (FIXME: #2794): - fn protos(p1: ast::Proto, p2: ast::Proto) -> cres { - super_protos(&self, p1, p2) + fn sigils(p1: ast::Sigil, p2: ast::Sigil) -> cres { + super_sigils(&self, p1, p2) + } + + fn abis(p1: ast::Abi, p2: ast::Abi) -> cres { + super_abis(&self, p1, p2) } fn tys(a: ty::t, b: ty::t) -> cres { diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index 6140390a24e..d6ecf11ef26 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -242,9 +242,6 @@ section on "Type Combining" below for details. */ -#[warn(deprecated_mode)]; -#[warn(deprecated_pattern)]; - use core::prelude::*; pub use middle::ty::IntVarValue; @@ -257,7 +254,6 @@ pub use middle::typeck::infer::resolve::{resolve_nested_tvar}; pub use middle::typeck::infer::resolve::{resolve_rvar}; use middle::ty::{TyVid, IntVid, FloatVid, RegionVid, Vid}; -use middle::ty::{mk_fn, type_is_bot}; use middle::ty::{ty_int, ty_uint, get, terr_fn, TyVar, IntVar, FloatVar}; use middle::ty; use middle::typeck::check::regionmanip::{replace_bound_regions_in_fn_sig}; diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index 0d4e520122f..afb18888cd9 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -536,9 +536,6 @@ more convincing in the future. */ -#[warn(deprecated_mode)]; -#[warn(deprecated_pattern)]; - use core::prelude::*; use middle::region::is_subregion_of; diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index 2e30bdc5888..bc834ef0289 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -212,20 +212,26 @@ pub impl Sub: Combine { // Traits please (FIXME: #2794): - fn protos(p1: ast::Proto, p2: ast::Proto) -> cres { - super_protos(&self, p1, p2) + fn sigils(p1: ast::Sigil, p2: ast::Sigil) -> cres { + super_sigils(&self, p1, p2) + } + + fn abis(p1: ast::Abi, p2: ast::Abi) -> cres { + super_abis(&self, p1, p2) } fn flds(a: ty::field, b: ty::field) -> cres { super_flds(&self, a, b) } - fn fns(a: &ty::FnTy, b: &ty::FnTy) -> cres { - super_fns(&self, a, b) + fn bare_fn_tys(a: &ty::BareFnTy, + b: &ty::BareFnTy) -> cres { + super_bare_fn_tys(&self, a, b) } - fn fn_metas(a: &ty::FnMeta, b: &ty::FnMeta) -> cres { - super_fn_metas(&self, a, b) + fn closure_tys(a: &ty::ClosureTy, + b: &ty::ClosureTy) -> cres { + super_closure_tys(&self, a, b) } fn vstores(vk: ty::terr_vstore_kind, diff --git a/src/librustc/middle/typeck/infer/to_str.rs b/src/librustc/middle/typeck/infer/to_str.rs index 57e05926173..bade7639e4b 100644 --- a/src/librustc/middle/typeck/infer/to_str.rs +++ b/src/librustc/middle/typeck/infer/to_str.rs @@ -10,7 +10,7 @@ use core::prelude::*; -use middle::ty::{FnMeta, FnTyBase, FnSig, Vid}; +use middle::ty::{FnSig, Vid}; use middle::ty::{IntVarValue, IntType, UintType}; use middle::ty; use middle::typeck::infer::{Bound, Bounds}; @@ -34,12 +34,6 @@ pub impl ty::t : InferStr { } } -pub impl FnMeta : InferStr { - fn inf_str(&self, _cx: &InferCtxt) -> ~str { - fmt!("%?", *self) - } -} - pub impl FnSig : InferStr { fn inf_str(&self, cx: &InferCtxt) -> ~str { fmt!("(%s) -> %s", @@ -48,12 +42,6 @@ pub impl FnSig : InferStr { } } -pub impl FnTyBase : InferStr { - fn inf_str(&self, cx: &InferCtxt) -> ~str { - fmt!("%s%s", self.meta.inf_str(cx), self.sig.inf_str(cx)) - } -} - pub impl ty::mt : InferStr { fn inf_str(&self, cx: &InferCtxt) -> ~str { mt_to_str(cx.tcx, *self) diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 742646618bd..3d9e2e7b86a 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -324,7 +324,7 @@ fn check_main_fn_ty(ccx: @crate_ctxt, let tcx = ccx.tcx; let main_t = ty::node_id_to_type(tcx, main_id); match ty::get(main_t).sty { - ty::ty_fn(ref fn_ty) => { + ty::ty_bare_fn(ref fn_ty) => { match tcx.items.find(&main_id) { Some(ast_map::node_item(it,_)) => { match it.node { @@ -341,8 +341,8 @@ fn check_main_fn_ty(ccx: @crate_ctxt, } _ => () } - let mut ok = ty::type_is_nil((*fn_ty).sig.output); - let num_args = vec::len((*fn_ty).sig.inputs); + let mut ok = ty::type_is_nil(fn_ty.sig.output); + let num_args = vec::len(fn_ty.sig.inputs); ok &= num_args == 0u; if !ok { tcx.sess.span_err( diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 9e70a6ab130..43d12c95c4d 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -21,7 +21,8 @@ use middle::ty::{mt, t, param_bound, param_ty}; use middle::ty::{re_bound, re_free, re_scope, re_infer, re_static, Region}; use middle::ty::{ReSkolemized, ReVar}; use middle::ty::{ty_bool, ty_bot, ty_box, ty_struct, ty_enum}; -use middle::ty::{ty_err, ty_estr, ty_evec, ty_float, ty_fn, ty_trait, ty_int}; +use middle::ty::{ty_err, ty_estr, ty_evec, ty_float, ty_bare_fn, ty_closure}; +use middle::ty::{ty_trait, ty_int}; use middle::ty::{ty_nil, ty_opaque_box, ty_opaque_closure_ptr, ty_param}; use middle::ty::{ty_ptr, ty_rec, ty_rptr, ty_self, ty_tup}; use middle::ty::{ty_type, ty_uniq, ty_uint, ty_infer}; @@ -30,7 +31,7 @@ use metadata::encoder; use syntax::codemap; use syntax::codemap::span; use syntax::print::pprust; -use syntax::print::pprust::{path_to_str, proto_to_str, mode_to_str}; +use syntax::print::pprust::{path_to_str, mode_to_str}; use syntax::{ast, ast_util}; use syntax::ast_map; @@ -252,17 +253,6 @@ pub fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str { } } -pub fn proto_ty_to_str(_cx: ctxt, proto: ast::Proto, - followed_by_word: bool) -> &static/str { - match proto { - ast::ProtoBare if followed_by_word => "extern ", - ast::ProtoBare => "extern", - ast::ProtoBox => "@", - ast::ProtoBorrowed => "&", - ast::ProtoUniq => "~", - } -} - pub fn expr_repr(cx: ctxt, expr: @ast::expr) -> ~str { fmt!("expr(%d: %s)", expr.id, @@ -306,69 +296,95 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { }; fmt!("%s%s", modestr, ty_to_str(cx, ty)) } - fn fn_to_str(cx: ctxt, - proto: ast::Proto, - region: ty::Region, - purity: ast::purity, - onceness: ast::Onceness, - ident: Option, - inputs: &[arg], - output: t) -> ~str { - let mut s; + fn bare_fn_to_str(cx: ctxt, + purity: ast::purity, + abi: ast::Abi, + ident: Option, + sig: &ty::FnSig) -> ~str + { + let mut s = ~"extern "; - s = match purity { - ast::impure_fn => ~"", - _ => purity.to_str() + ~" " - }; - - s += match onceness { - ast::Many => ~"", - ast::Once => onceness.to_str() + ~" " - }; - - s += proto_ty_to_str(cx, proto, true); - - match (proto, region) { - (ast::ProtoBox, ty::re_static) | - (ast::ProtoUniq, ty::re_static) | - (ast::ProtoBare, ty::re_static) => { - } - - (_, region) => { - s += region_to_str_adorned(cx, ~"", region, ~"/"); - } + match abi { + ast::RustAbi => {} } - s += ~"fn"; + match purity { + ast::impure_fn => {} + _ => { + s.push_str(purity.to_str()); + s.push_char(' '); + } + }; + + s.push_str("fn"); match ident { - Some(i) => { s += ~" "; s += cx.sess.str_of(i); } + Some(i) => { + s.push_char(' '); + s.push_str(cx.sess.str_of(i)); + } _ => { } } - s += ~"("; - let strs = inputs.map(|a| fn_input_to_str(cx, *a)); - s += str::connect(strs, ~", "); - s += ~")"; - if ty::get(output).sty != ty_nil { - s += ~" -> "; - if ty::type_is_bot(output) { - s += ~"!"; - } else { - s += ty_to_str(cx, output); - } - } + + push_sig_to_str(cx, &mut s, sig); + return s; } + fn closure_to_str(cx: ctxt, cty: &ty::ClosureTy) -> ~str + { + let mut s = cty.sigil.to_str(); + + match (cty.sigil, cty.region) { + (ast::ManagedSigil, ty::re_static) | + (ast::OwnedSigil, ty::re_static) => {} + + (_, region) => { + s.push_str(region_to_str_adorned(cx, "", region, "/")); + } + } + + match cty.purity { + ast::impure_fn => {} + _ => { + s.push_str(cty.purity.to_str()); + s.push_char(' '); + } + }; + + match cty.onceness { + ast::Many => {} + ast::Once => { + s.push_str(cty.onceness.to_str()); + s.push_char(' '); + } + }; + + s.push_str("fn"); + + push_sig_to_str(cx, &mut s, &cty.sig); + + return s; + } + fn push_sig_to_str(cx: ctxt, s: &mut ~str, sig: &ty::FnSig) { + s.push_char('('); + let strs = sig.inputs.map(|a| fn_input_to_str(cx, *a)); + s.push_str(str::connect(strs, ", ")); + s.push_char(')'); + if ty::get(sig.output).sty != ty_nil { + s.push_str(" -> "); + if ty::type_is_bot(sig.output) { + s.push_char('!'); + } else { + s.push_str(ty_to_str(cx, sig.output)); + } + } + } fn method_to_str(cx: ctxt, m: method) -> ~str { - return fn_to_str( - cx, - m.fty.meta.proto, - m.fty.meta.region, - m.fty.meta.purity, - m.fty.meta.onceness, - Some(m.ident), - m.fty.sig.inputs, - m.fty.sig.output) + ~";"; + bare_fn_to_str(cx, + m.fty.purity, + m.fty.abi, + Some(m.ident), + &m.fty.sig) + ~";" } fn field_to_str(cx: ctxt, f: field) -> ~str { return cx.sess.str_of(f.ident) + ~": " + mt_to_str(cx, f.mt); @@ -409,15 +425,11 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { let strs = elems.map(|elem| ty_to_str(cx, *elem)); ~"(" + str::connect(strs, ~",") + ~")" } - ty_fn(ref f) => { - fn_to_str(cx, - f.meta.proto, - f.meta.region, - f.meta.purity, - f.meta.onceness, - None, - f.sig.inputs, - f.sig.output) + ty_closure(ref f) => { + closure_to_str(cx, f) + } + ty_bare_fn(ref f) => { + bare_fn_to_str(cx, f.purity, f.abi, None, &f.sig) } ty_infer(infer_ty) => infer_ty.to_str(), ty_err => ~"[type error]", @@ -448,10 +460,9 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str { } ty_estr(vs) => vstore_ty_to_str(cx, ~"str", vs), ty_opaque_box => ~"@?", - ty_opaque_closure_ptr(ast::ProtoBorrowed) => ~"closure&", - ty_opaque_closure_ptr(ast::ProtoBox) => ~"closure@", - ty_opaque_closure_ptr(ast::ProtoUniq) => ~"closure~", - ty_opaque_closure_ptr(ast::ProtoBare) => ~"closure" + ty_opaque_closure_ptr(ast::BorrowedSigil) => ~"closure&", + ty_opaque_closure_ptr(ast::ManagedSigil) => ~"closure@", + ty_opaque_closure_ptr(ast::OwnedSigil) => ~"closure~", } } diff --git a/src/librustdoc/astsrv.rs b/src/librustdoc/astsrv.rs index dd6e889008f..1d629467a42 100644 --- a/src/librustdoc/astsrv.rs +++ b/src/librustdoc/astsrv.rs @@ -21,6 +21,7 @@ use core::prelude::*; use parse; use util; +use std::cell::Cell; use core::pipes::{stream, Chan, SharedChan, Port}; use core::vec; @@ -78,8 +79,10 @@ fn run(owner: SrvOwner, source: ~str, parse: Parser) -> T { let (po, ch) = stream(); + let source = Cell(source); + let parse = Cell(parse); do task::spawn { - act(&po, copy source, copy parse); + act(&po, source.take(), parse.take()); } let srv_ = Srv { diff --git a/src/librustdoc/attr_parser.rs b/src/librustdoc/attr_parser.rs index afbb10f2cbb..0beb651afc4 100644 --- a/src/librustdoc/attr_parser.rs +++ b/src/librustdoc/attr_parser.rs @@ -96,7 +96,7 @@ fn should_not_extract_crate_name_if_no_name_value_in_link_attribute() { } pub fn parse_desc(attrs: ~[ast::attribute]) -> Option<~str> { - let doc_strs = do doc_metas(attrs).filter_map |meta| { + let doc_strs = do doc_metas(attrs).filter_mapped |meta| { attr::get_meta_item_value_str(*meta) }; if doc_strs.is_empty() { diff --git a/src/librustdoc/desc_to_brief_pass.rs b/src/librustdoc/desc_to_brief_pass.rs index 225b62f72cb..2d0969562a0 100644 --- a/src/librustdoc/desc_to_brief_pass.rs +++ b/src/librustdoc/desc_to_brief_pass.rs @@ -62,7 +62,7 @@ fn fold_trait(fold: &fold::Fold<()>, doc: doc::TraitDoc) -> doc::TraitDoc { let doc =fold::default_seq_fold_trait(fold, doc); doc::TraitDoc { - methods: par::map(doc.methods, |doc| doc::MethodDoc { + methods: doc.methods.map(|doc| doc::MethodDoc { brief: extract(copy doc.desc), .. copy *doc }), @@ -74,7 +74,7 @@ fn fold_impl(fold: &fold::Fold<()>, doc: doc::ImplDoc) -> doc::ImplDoc { let doc =fold::default_seq_fold_impl(fold, doc); doc::ImplDoc { - methods: par::map(doc.methods, |doc| doc::MethodDoc { + methods: doc.methods.map(|doc| doc::MethodDoc { brief: extract(copy doc.desc), .. copy *doc }), diff --git a/src/librustdoc/doc.rs b/src/librustdoc/doc.rs index e51c8106f3d..2eb4ed97871 100644 --- a/src/librustdoc/doc.rs +++ b/src/librustdoc/doc.rs @@ -192,7 +192,7 @@ impl Doc { /// Some helper methods on ModDoc, mostly for testing impl ModDoc { fn mods(&self) -> ~[ModDoc] { - do vec::filter_map(self.items) |itemtag| { + do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { ModTag(ModDoc) => Some(ModDoc), _ => None @@ -201,7 +201,7 @@ impl ModDoc { } fn nmods(&self) -> ~[NmodDoc] { - do vec::filter_map(self.items) |itemtag| { + do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { NmodTag(nModDoc) => Some(nModDoc), _ => None @@ -210,7 +210,7 @@ impl ModDoc { } fn fns(&self) -> ~[FnDoc] { - do vec::filter_map(self.items) |itemtag| { + do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { FnTag(FnDoc) => Some(FnDoc), _ => None @@ -219,7 +219,7 @@ impl ModDoc { } fn consts(&self) -> ~[ConstDoc] { - do vec::filter_map(self.items) |itemtag| { + do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { ConstTag(ConstDoc) => Some(ConstDoc), _ => None @@ -228,7 +228,7 @@ impl ModDoc { } fn enums(&self) -> ~[EnumDoc] { - do vec::filter_map(self.items) |itemtag| { + do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { EnumTag(EnumDoc) => Some(EnumDoc), _ => None @@ -237,7 +237,7 @@ impl ModDoc { } fn traits(&self) -> ~[TraitDoc] { - do vec::filter_map(self.items) |itemtag| { + do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { TraitTag(TraitDoc) => Some(TraitDoc), _ => None @@ -246,7 +246,7 @@ impl ModDoc { } fn impls(&self) -> ~[ImplDoc] { - do vec::filter_map(self.items) |itemtag| { + do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { ImplTag(ImplDoc) => Some(ImplDoc), _ => None @@ -255,7 +255,7 @@ impl ModDoc { } fn types(&self) -> ~[TyDoc] { - do vec::filter_map(self.items) |itemtag| { + do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { TyTag(TyDoc) => Some(TyDoc), _ => None @@ -264,7 +264,7 @@ impl ModDoc { } fn structs(&self) -> ~[StructDoc] { - do vec::filter_map(self.items) |itemtag| { + do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { StructTag(StructDoc) => Some(StructDoc), _ => None @@ -287,7 +287,7 @@ pub trait PageUtils { impl ~[Page]: PageUtils { fn mods(&self) -> ~[ModDoc] { - do vec::filter_map(*self) |page| { + do vec::filter_mapped(*self) |page| { match copy *page { ItemPage(ModTag(ModDoc)) => Some(ModDoc), _ => None @@ -296,7 +296,7 @@ impl ~[Page]: PageUtils { } fn nmods(&self) -> ~[NmodDoc] { - do vec::filter_map(*self) |page| { + do vec::filter_mapped(*self) |page| { match copy *page { ItemPage(NmodTag(nModDoc)) => Some(nModDoc), _ => None @@ -305,7 +305,7 @@ impl ~[Page]: PageUtils { } fn fns(&self) -> ~[FnDoc] { - do vec::filter_map(*self) |page| { + do vec::filter_mapped(*self) |page| { match copy *page { ItemPage(FnTag(FnDoc)) => Some(FnDoc), _ => None @@ -314,7 +314,7 @@ impl ~[Page]: PageUtils { } fn consts(&self) -> ~[ConstDoc] { - do vec::filter_map(*self) |page| { + do vec::filter_mapped(*self) |page| { match copy *page { ItemPage(ConstTag(ConstDoc)) => Some(ConstDoc), _ => None @@ -323,7 +323,7 @@ impl ~[Page]: PageUtils { } fn enums(&self) -> ~[EnumDoc] { - do vec::filter_map(*self) |page| { + do vec::filter_mapped(*self) |page| { match copy *page { ItemPage(EnumTag(EnumDoc)) => Some(EnumDoc), _ => None @@ -332,7 +332,7 @@ impl ~[Page]: PageUtils { } fn traits(&self) -> ~[TraitDoc] { - do vec::filter_map(*self) |page| { + do vec::filter_mapped(*self) |page| { match copy *page { ItemPage(TraitTag(TraitDoc)) => Some(TraitDoc), _ => None @@ -341,7 +341,7 @@ impl ~[Page]: PageUtils { } fn impls(&self) -> ~[ImplDoc] { - do vec::filter_map(*self) |page| { + do vec::filter_mapped(*self) |page| { match copy *page { ItemPage(ImplTag(ImplDoc)) => Some(ImplDoc), _ => None @@ -350,7 +350,7 @@ impl ~[Page]: PageUtils { } fn types(&self) -> ~[TyDoc] { - do vec::filter_map(*self) |page| { + do vec::filter_mapped(*self) |page| { match copy *page { ItemPage(TyTag(TyDoc)) => Some(TyDoc), _ => None diff --git a/src/librustdoc/extract.rs b/src/librustdoc/extract.rs index fc572e3da2c..822a423eae4 100644 --- a/src/librustdoc/extract.rs +++ b/src/librustdoc/extract.rs @@ -92,7 +92,7 @@ fn moddoc_from_mod( ) -> doc::ModDoc { doc::ModDoc { item: itemdoc, - items: do vec::filter_map(module_.items) |item| { + items: do vec::filter_mapped(module_.items) |item| { let ItemDoc = mk_itemdoc(item.id, to_str(item.ident)); match copy item.node { ast::item_mod(m) => { diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index c93d9f3d7c1..e9b25b07de1 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -55,23 +55,23 @@ impl Fold: Clone { } } -type FoldDoc = fn~(fold: &Fold, doc: doc::Doc) -> doc::Doc; -type FoldCrate = fn~(fold: &Fold, doc: doc::CrateDoc) -> doc::CrateDoc; -type FoldItem = fn~(fold: &Fold, doc: doc::ItemDoc) -> doc::ItemDoc; -type FoldMod = fn~(fold: &Fold, doc: doc::ModDoc) -> doc::ModDoc; -type FoldNmod = fn~(fold: &Fold, doc: doc::NmodDoc) -> doc::NmodDoc; -type FoldFn = fn~(fold: &Fold, doc: doc::FnDoc) -> doc::FnDoc; -type FoldConst = fn~(fold: &Fold, doc: doc::ConstDoc) -> doc::ConstDoc; -type FoldEnum = fn~(fold: &Fold, doc: doc::EnumDoc) -> doc::EnumDoc; -type FoldTrait = fn~(fold: &Fold, doc: doc::TraitDoc) -> doc::TraitDoc; -type FoldImpl = fn~(fold: &Fold, doc: doc::ImplDoc) -> doc::ImplDoc; -type FoldType = fn~(fold: &Fold, doc: doc::TyDoc) -> doc::TyDoc; -type FoldStruct = fn~(fold: &Fold, +type FoldDoc = @fn(fold: &Fold, doc: doc::Doc) -> doc::Doc; +type FoldCrate = @fn(fold: &Fold, doc: doc::CrateDoc) -> doc::CrateDoc; +type FoldItem = @fn(fold: &Fold, doc: doc::ItemDoc) -> doc::ItemDoc; +type FoldMod = @fn(fold: &Fold, doc: doc::ModDoc) -> doc::ModDoc; +type FoldNmod = @fn(fold: &Fold, doc: doc::NmodDoc) -> doc::NmodDoc; +type FoldFn = @fn(fold: &Fold, doc: doc::FnDoc) -> doc::FnDoc; +type FoldConst = @fn(fold: &Fold, doc: doc::ConstDoc) -> doc::ConstDoc; +type FoldEnum = @fn(fold: &Fold, doc: doc::EnumDoc) -> doc::EnumDoc; +type FoldTrait = @fn(fold: &Fold, doc: doc::TraitDoc) -> doc::TraitDoc; +type FoldImpl = @fn(fold: &Fold, doc: doc::ImplDoc) -> doc::ImplDoc; +type FoldType = @fn(fold: &Fold, doc: doc::TyDoc) -> doc::TyDoc; +type FoldStruct = @fn(fold: &Fold, doc: doc::StructDoc) -> doc::StructDoc; // This exists because fn types don't infer correctly as record // initializers, but they do as function arguments -fn mk_fold( +fn mk_fold( ctxt: T, fold_doc: FoldDoc, fold_crate: FoldCrate, @@ -103,7 +103,7 @@ fn mk_fold( } } -pub fn default_any_fold(ctxt: T) -> Fold { +pub fn default_any_fold(ctxt: T) -> Fold { mk_fold( move ctxt, |f, d| default_seq_fold_doc(f, d), @@ -121,7 +121,7 @@ pub fn default_any_fold(ctxt: T) -> Fold { ) } -pub fn default_seq_fold(ctxt: T) -> Fold { +pub fn default_seq_fold(ctxt: T) -> Fold { mk_fold( move ctxt, |f, d| default_seq_fold_doc(f, d), @@ -139,7 +139,7 @@ pub fn default_seq_fold(ctxt: T) -> Fold { ) } -pub fn default_par_fold(ctxt: T) -> Fold { +pub fn default_par_fold(ctxt: T) -> Fold { mk_fold( move ctxt, |f, d| default_seq_fold_doc(f, d), @@ -189,7 +189,7 @@ pub fn default_seq_fold_item( doc } -pub fn default_any_fold_mod( +pub fn default_any_fold_mod( fold: &Fold, doc: doc::ModDoc ) -> doc::ModDoc { @@ -215,7 +215,7 @@ pub fn default_seq_fold_mod( } } -pub fn default_par_fold_mod( +pub fn default_par_fold_mod( fold: &Fold, doc: doc::ModDoc ) -> doc::ModDoc { @@ -228,7 +228,7 @@ pub fn default_par_fold_mod( } } -pub fn default_any_fold_nmod( +pub fn default_any_fold_nmod( fold: &Fold, doc: doc::NmodDoc ) -> doc::NmodDoc { @@ -254,7 +254,7 @@ pub fn default_seq_fold_nmod( } } -pub fn default_par_fold_nmod( +pub fn default_par_fold_nmod( fold: &Fold, doc: doc::NmodDoc ) -> doc::NmodDoc { diff --git a/src/librustdoc/markdown_index_pass.rs b/src/librustdoc/markdown_index_pass.rs index 776d2fe9083..42a7d0006db 100644 --- a/src/librustdoc/markdown_index_pass.rs +++ b/src/librustdoc/markdown_index_pass.rs @@ -28,9 +28,7 @@ use std::par; pub fn mk_pass(config: config::Config) -> Pass { Pass { name: ~"markdown_index", - f: fn~(srv: astsrv::Srv, doc: doc::Doc) -> doc::Doc { - run(srv, doc, copy config) - } + f: |srv, doc| run(srv, doc, copy config) } } @@ -78,7 +76,7 @@ fn build_mod_index( config: config::Config ) -> doc::Index { doc::Index { - entries: par::map(doc.items, |doc| { + entries: doc.items.map(|doc| { item_to_entry(copy *doc, copy config) }) } @@ -89,7 +87,7 @@ fn build_nmod_index( config: config::Config ) -> doc::Index { doc::Index { - entries: par::map(doc.fns, |doc| { + entries: doc.fns.map(|doc| { item_to_entry(doc::FnTag(copy *doc), copy config) }) } diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs index fc13af8a221..161642a2f3d 100644 --- a/src/librustdoc/markdown_pass.rs +++ b/src/librustdoc/markdown_pass.rs @@ -43,14 +43,9 @@ use syntax; pub fn mk_pass(writer_factory: WriterFactory) -> Pass { let writer_factory = Cell(writer_factory); - let f = fn~(move writer_factory, - srv: astsrv::Srv, doc: doc::Doc) -> doc::Doc { - run(srv, doc, writer_factory.take()) - }; - Pass { name: ~"markdown", - f: move f + f: |srv, doc| run(srv, doc, writer_factory.take()) } } diff --git a/src/librustdoc/page_pass.rs b/src/librustdoc/page_pass.rs index c8509826fdb..08abe4b351b 100644 --- a/src/librustdoc/page_pass.rs +++ b/src/librustdoc/page_pass.rs @@ -36,9 +36,7 @@ use syntax::ast; pub fn mk_pass(output_style: config::OutputStyle) -> Pass { Pass { name: ~"page", - f: fn~(srv: astsrv::Srv, doc: doc::Doc) -> doc::Doc { - run(srv, doc, output_style) - } + f: |srv, doc| run(srv, doc, output_style) } } diff --git a/src/librustdoc/pass.rs b/src/librustdoc/pass.rs index 91e3264db1c..e78c7d54019 100644 --- a/src/librustdoc/pass.rs +++ b/src/librustdoc/pass.rs @@ -20,7 +20,7 @@ use core::vec; /// A single operation on the document model pub struct Pass { name: ~str, - f: fn~(srv: astsrv::Srv, +doc: doc::Doc) -> doc::Doc + f: @fn(srv: astsrv::Srv, +doc: doc::Doc) -> doc::Doc } pub fn run_passes( diff --git a/src/librustdoc/sectionalize_pass.rs b/src/librustdoc/sectionalize_pass.rs index d6455c4c783..205fc0aa86d 100644 --- a/src/librustdoc/sectionalize_pass.rs +++ b/src/librustdoc/sectionalize_pass.rs @@ -57,7 +57,7 @@ fn fold_trait(fold: &fold::Fold<()>, doc: doc::TraitDoc) -> doc::TraitDoc { let doc = fold::default_seq_fold_trait(fold, doc); doc::TraitDoc { - methods: do par::map(doc.methods) |method| { + methods: do doc.methods.map |method| { let (desc, sections) = sectionalize(copy method.desc); doc::MethodDoc { @@ -74,7 +74,7 @@ fn fold_impl(fold: &fold::Fold<()>, doc: doc::ImplDoc) -> doc::ImplDoc { let doc = fold::default_seq_fold_impl(fold, doc); doc::ImplDoc { - methods: do par::map(doc.methods) |method| { + methods: do doc.methods.map |method| { let (desc, sections) = sectionalize(copy method.desc); doc::MethodDoc { diff --git a/src/librustdoc/sort_pass.rs b/src/librustdoc/sort_pass.rs index 2792508483c..b7614a785c7 100644 --- a/src/librustdoc/sort_pass.rs +++ b/src/librustdoc/sort_pass.rs @@ -23,16 +23,14 @@ use util::NominalOp; use std::sort; -pub type ItemLtEqOp = pure fn~(v1: &doc::ItemTag, v2: &doc::ItemTag) -> bool; +pub type ItemLtEqOp = @pure fn(v1: &doc::ItemTag, v2: &doc::ItemTag) -> bool; type ItemLtEq = NominalOp; pub fn mk_pass(name: ~str, lteq: ItemLtEqOp) -> Pass { Pass { name: copy name, - f: fn~(move lteq, srv: astsrv::Srv, doc: doc::Doc) -> doc::Doc { - run(srv, doc, NominalOp { op: copy lteq }) - } + f: |srv, doc| run(srv, doc, NominalOp { op: lteq }) } } diff --git a/src/librustdoc/text_pass.rs b/src/librustdoc/text_pass.rs index aec8b56341f..79ba8f0684a 100644 --- a/src/librustdoc/text_pass.rs +++ b/src/librustdoc/text_pass.rs @@ -23,17 +23,17 @@ use util::NominalOp; use std::par; use std::cell::Cell; -pub fn mk_pass(name: ~str, op: fn~(&str) -> ~str) -> Pass { +pub fn mk_pass(name: ~str, op: @fn(&str) -> ~str) -> Pass { let op = Cell(op); Pass { name: copy name, - f: fn~(move op, srv: astsrv::Srv, doc: doc::Doc) -> doc::Doc { + f: |srv: astsrv::Srv, doc: doc::Doc| -> doc::Doc { run(srv, doc, op.take()) } } } -type Op = fn~(&str) -> ~str; +type Op = @fn(&str) -> ~str; #[allow(non_implicitly_copyable_typarams)] fn run( @@ -76,7 +76,7 @@ fn apply_to_sections( op: NominalOp, sections: ~[doc::Section] ) -> ~[doc::Section] { - par::map(sections, |section, copy op| doc::Section { + sections.map(|section, copy op| doc::Section { header: (op.op)(copy section.header), body: (op.op)(copy section.body) }) @@ -89,7 +89,7 @@ fn fold_enum( let fold_copy = copy *fold; doc::EnumDoc { - variants: do par::map(doc.variants) |variant, copy fold_copy| { + variants: do doc.variants.map |variant, copy fold_copy| { doc::VariantDoc { desc: maybe_apply_op(copy fold_copy.ctxt, &variant.desc), .. copy *variant @@ -116,7 +116,7 @@ fn apply_to_methods( docs: ~[doc::MethodDoc] ) -> ~[doc::MethodDoc] { let op = copy op; - do par::map(docs) |doc| { + do docs.map |doc| { doc::MethodDoc { brief: maybe_apply_op(copy op, &doc.brief), desc: maybe_apply_op(copy op, &doc.desc), diff --git a/src/librustdoc/unindent_pass.rs b/src/librustdoc/unindent_pass.rs index 1c53ed5dcce..fa8c2dd93c0 100644 --- a/src/librustdoc/unindent_pass.rs +++ b/src/librustdoc/unindent_pass.rs @@ -80,7 +80,7 @@ fn unindent(s: &str) -> ~str { if !lines.is_empty() { let unindented = ~[str::trim(vec::head(lines))] - + do par::map(vec::tail(lines)) |line| { + + do vec::tail(lines).map |line| { if str::is_whitespace(*line) { copy *line } else { diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index a8d3f156104..a1fd7a66f7e 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; /** * Concurrency-enabled mechanisms for sharing mutable and/or immutable state * between tasks. diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs index 3e21a320d44..a2cbe27ea90 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -32,8 +32,6 @@ // overhead when initializing plain-old-data and means we don't need // to waste time running the destructors of POD. -#[forbid(deprecated_mode)]; - use arena; use list; use list::{List, Cons, Nil}; diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index 5813e0919d9..d9e121798f1 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[forbid(deprecated_mode)]; - use core::io::Reader; use core::iter; use core::str; diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index 244d388bffe..a94c4f79064 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[forbid(deprecated_mode)]; - use core::ops; use core::prelude::*; use core::uint; diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index 17920f5de3f..5ea5418d988 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -35,7 +35,6 @@ * great care must be taken to ensure that a reference to the c_vec::t is * still held if needed. */ -#[forbid(deprecated_mode)]; use core::libc; use core::option; diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index aae84a86957..10a896a4089 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[forbid(deprecated_mode)]; - use core::option; use core::prelude::*; diff --git a/src/libstd/cmp.rs b/src/libstd/cmp.rs index 0bd7538d947..110559ddcef 100644 --- a/src/libstd/cmp.rs +++ b/src/libstd/cmp.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[forbid(deprecated_mode)]; //! Additional general-purpose comparison functionality. use core::f32; diff --git a/src/libstd/comm.rs b/src/libstd/comm.rs index dc0fbbac641..71eb29e26eb 100644 --- a/src/libstd/comm.rs +++ b/src/libstd/comm.rs @@ -14,9 +14,6 @@ Higher level communication abstractions. */ -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; - use core::pipes::{GenericChan, GenericSmartChan, GenericPort}; use core::pipes::{Chan, Port, Selectable, Peekable}; use core::pipes; diff --git a/src/libstd/dbg.rs b/src/libstd/dbg.rs index cf1b816f238..7813357caf2 100644 --- a/src/libstd/dbg.rs +++ b/src/libstd/dbg.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[forbid(deprecated_mode)]; //! Unsafe debugging functions for inspecting values. use core::cast::reinterpret_cast; diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index 2f001ae866c..465c5d8f8fe 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -9,7 +9,6 @@ // except according to those terms. //! A deque. Untested as of yet. Likely buggy -#[forbid(deprecated_mode)]; #[forbid(non_camel_case_types)]; use core::cmp::Eq; diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index aaeecfb3302..768d2dbf2d4 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[forbid(deprecated_mode)]; - use serialize; use core::io; diff --git a/src/libstd/fun_treemap.rs b/src/libstd/fun_treemap.rs index e0d4b95a7e4..d6c2cf5a265 100644 --- a/src/libstd/fun_treemap.rs +++ b/src/libstd/fun_treemap.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[forbid(deprecated_mode)]; - /*! * A functional key,value store that works on anything. * diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 6e1a0861035..fa8fdf56428 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -72,7 +72,6 @@ * do_work(input, output); * } */ -#[forbid(deprecated_mode)]; use core::cmp::Eq; use core::prelude::*; diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 13b58c43300..99c6c2f008d 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -10,7 +10,6 @@ // Rust JSON serialization library // Copyright (c) 2011 Google Inc. -#[forbid(deprecated_mode)]; #[forbid(non_camel_case_types)]; //! json serialization diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 3016abee464..140c2013738 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -9,7 +9,6 @@ // except according to those terms. //! A standard linked list -#[forbid(deprecated_mode)]; use core::cmp::Eq; use core::option; diff --git a/src/libstd/md4.rs b/src/libstd/md4.rs index 718e805b5d9..1d831af0e29 100644 --- a/src/libstd/md4.rs +++ b/src/libstd/md4.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[forbid(deprecated_mode)]; - use core::str; use core::uint; use core::vec; diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index f4fd69aae1e..511e80b0160 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -9,7 +9,6 @@ // except according to those terms. //! Types/fns concerning Internet Protocol (IP), versions 4 & 6 -#[forbid(deprecated_mode)]; use core::libc; use core::prelude::*; diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 429bd6ae474..c90518f1692 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -10,6 +10,7 @@ //! High-level interface to libuv's TCP functionality // FIXME #4425: Need FFI fixes + #[allow(deprecated_mode)]; use future; diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index b32c97c6998..9403438dde0 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -9,7 +9,8 @@ // except according to those terms. //! Types/fns concerning URLs (see RFC 3986) -#[forbid(deprecated_mode)]; + +#[allow(deprecated_mode)]; use core::cmp::Eq; use core::dvec::DVec; diff --git a/src/libstd/oldmap.rs b/src/libstd/oldmap.rs index 18cfc8d4a2d..ad7e8e50e38 100644 --- a/src/libstd/oldmap.rs +++ b/src/libstd/oldmap.rs @@ -9,7 +9,6 @@ // except according to those terms. //! A map type - **deprecated**, use `core::hashmap` instead -#[forbid(deprecated_mode)]; use core::container::{Container, Mutable, Map}; use core::cmp::Eq; diff --git a/src/libstd/par.rs b/src/libstd/par.rs index 779dda0ab29..8293ff1c2af 100644 --- a/src/libstd/par.rs +++ b/src/libstd/par.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[forbid(deprecated_mode)]; - use core::cast; use core::prelude::*; use core::ptr; @@ -38,7 +36,7 @@ const min_granularity : uint = 1024u; */ fn map_slices( xs: &[A], - f: fn() -> fn~(uint, v: &[A]) -> B) + f: &fn() -> ~fn(uint, v: &[A]) -> B) -> ~[B] { let len = xs.len(); @@ -93,9 +91,9 @@ fn map_slices( /// A parallel version of map. pub fn map( - xs: &[A], f: fn~(&A) -> B) -> ~[B] { + xs: &[A], fn_factory: &fn() -> ~fn(&A) -> B) -> ~[B] { vec::concat(map_slices(xs, || { - let f = copy f; + let f = fn_factory(); fn~(_base: uint, slice : &[A]) -> ~[B] { vec::map(slice, |x| f(x)) } @@ -103,10 +101,12 @@ pub fn map( } /// A parallel version of mapi. -pub fn mapi(xs: &[A], - f: fn~(uint, &A) -> B) -> ~[B] { +pub fn mapi( + xs: &[A], + fn_factory: &fn() -> ~fn(uint, &A) -> B) -> ~[B] +{ let slices = map_slices(xs, || { - let f = copy f; + let f = fn_factory(); fn~(base: uint, slice : &[A], copy f) -> ~[B] { vec::mapi(slice, |i, x| { f(i + base, x) @@ -119,32 +119,13 @@ pub fn mapi(xs: &[A], r } -/** - * A parallel version of mapi. - * - * In this case, f is a function that creates functions to run over the - * inner elements. This is to skirt the need for copy constructors. - */ -pub fn mapi_factory( - xs: &[A], f: fn() -> fn~(uint, A) -> B) -> ~[B] { - let slices = map_slices(xs, || { - let f = f(); - fn~(base: uint, slice : &[A], move f) -> ~[B] { - vec::mapi(slice, |i, x| { - f(i + base, *x) - }) - } - }); - let r = vec::concat(slices); - log(info, (r.len(), xs.len())); - assert(r.len() == xs.len()); - r -} - /// Returns true if the function holds for all elements in the vector. -pub fn alli(xs: &[A], f: fn~(uint, &A) -> bool) -> bool { +pub fn alli( + xs: &[A], + fn_factory: &fn() -> ~fn(uint, &A) -> bool) -> bool +{ do vec::all(map_slices(xs, || { - let f = copy f; + let f = fn_factory(); fn~(base: uint, slice : &[A], copy f) -> bool { vec::alli(slice, |i, x| { f(i + base, x) @@ -154,9 +135,11 @@ pub fn alli(xs: &[A], f: fn~(uint, &A) -> bool) -> bool { } /// Returns true if the function holds for any elements in the vector. -pub fn any(xs: &[A], f: fn~(&A) -> bool) -> bool { +pub fn any( + xs: &[A], + fn_factory: &fn() -> ~fn(&A) -> bool) -> bool { do vec::any(map_slices(xs, || { - let f = copy f; + let f = fn_factory(); fn~(_base : uint, slice: &[A], copy f) -> bool { vec::any(slice, |x| f(x)) } diff --git a/src/libstd/prettyprint.rs b/src/libstd/prettyprint.rs index d07c29d624c..dc2e3d3da2b 100644 --- a/src/libstd/prettyprint.rs +++ b/src/libstd/prettyprint.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[forbid(deprecated_mode)]; - use serialize; use core::io::Writer; diff --git a/src/libstd/rl.rs b/src/libstd/rl.rs index 5dd2a056327..30baa3cc5f1 100644 --- a/src/libstd/rl.rs +++ b/src/libstd/rl.rs @@ -64,7 +64,7 @@ pub unsafe fn read(prompt: ~str) -> Option<~str> { } } -pub type CompletionCb = fn~(~str, fn(~str)); +pub type CompletionCb = @fn(~str, fn(~str)); fn complete_key(_v: @CompletionCb) {} @@ -75,7 +75,7 @@ pub unsafe fn complete(cb: CompletionCb) { extern fn callback(line: *c_char, completions: *()) { unsafe { - let cb = copy *task::local_data::local_data_get(complete_key) + let cb = *task::local_data::local_data_get(complete_key) .get(); do cb(str::raw::from_c_str(line)) |suggestion| { diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index c7601f6b6b5..f8aef2c5f1e 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -33,8 +33,6 @@ * * access to a character by index is logarithmic (linear in strings); */ -#[forbid(deprecated_mode)]; - use core::cast; use core::char; use core::option; diff --git a/src/libstd/serialize.rs b/src/libstd/serialize.rs index 4938ead9ea8..972df73d216 100644 --- a/src/libstd/serialize.rs +++ b/src/libstd/serialize.rs @@ -14,7 +14,6 @@ Core encoding and decoding interfaces. */ -#[forbid(deprecated_mode)]; #[forbid(non_camel_case_types)]; use core::at_vec; diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs index 5fb7d892c58..6209170ac3d 100644 --- a/src/libstd/sha1.rs +++ b/src/libstd/sha1.rs @@ -22,8 +22,6 @@ * the `reset` method. */ -#[forbid(deprecated_mode)]; - use core::str; use core::uint; use core::vec; diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 1cd35722ab4..9af596eb1f5 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -12,7 +12,6 @@ * A simple map based on a vector for small integer keys. Space requirements * are O(highest integer key). */ -#[forbid(deprecated_mode)]; use core::container::{Container, Mutable, Map, Set}; use core::option::{Some, None}; diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index 6e89cd9e24f..680a2b99c4a 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -9,7 +9,6 @@ // except according to those terms. //! Sorting methods -#[forbid(deprecated_mode)]; use core::cmp::{Eq, Ord}; use core::dvec::DVec; @@ -64,14 +63,13 @@ pub pure fn merge_sort(v: &[const T], le: Le) -> ~[T] { } } -fn part(arr: &mut [T], left: uint, - right: uint, pivot: uint, compare_func: Le) -> uint { - let pivot_value = arr[pivot]; +fn part(arr: &mut [T], left: uint, + right: uint, pivot: uint, compare_func: Le) -> uint { arr[pivot] <-> arr[right]; let mut storage_index: uint = left; let mut i: uint = left; while i < right { - if compare_func(&arr[i], &pivot_value) { + if compare_func(&arr[i], &arr[right]) { arr[i] <-> arr[storage_index]; storage_index += 1; } @@ -81,8 +79,8 @@ fn part(arr: &mut [T], left: uint, return storage_index; } -fn qsort(arr: &mut [T], left: uint, - right: uint, compare_func: Le) { +fn qsort(arr: &mut [T], left: uint, + right: uint, compare_func: Le) { if right > left { let pivot = (left + right) / 2u; let new_pivot = part::(arr, left, right, pivot, compare_func); @@ -100,7 +98,7 @@ fn qsort(arr: &mut [T], left: uint, * Has worst case O(n^2) performance, average case O(n log n). * This is an unstable sort. */ -pub fn quick_sort(arr: &mut [T], compare_func: Le) { +pub fn quick_sort(arr: &mut [T], compare_func: Le) { if len::(arr) == 0u { return; } qsort::(arr, 0u, len::(arr) - 1u, compare_func); } diff --git a/src/libstd/std.rc b/src/libstd/std.rc index a2fbc8b1db1..8c142908d10 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -28,10 +28,6 @@ not required in or otherwise suitable for the core library. #[allow(vecs_implicitly_copyable)]; #[deny(non_camel_case_types)]; -// XXX this is set to allow because there are two methods in encoding -// that can't be silenced otherwise. Most every module is set to forbid -#[allow(deprecated_mode)]; -#[forbid(deprecated_pattern)]; #[allow(deprecated_self)]; #[no_core]; diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 31c596c5038..b7e75897bf1 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; /** * The concurrency primitives you know and love. * diff --git a/src/libstd/tempfile.rs b/src/libstd/tempfile.rs index f10d54f3271..b786d913639 100644 --- a/src/libstd/tempfile.rs +++ b/src/libstd/tempfile.rs @@ -10,8 +10,6 @@ //! Temporary files and directories -#[forbid(deprecated_mode)]; - use core::os; use core::prelude::*; use core::rand; diff --git a/src/libstd/term.rs b/src/libstd/term.rs index ae5949e6f18..5616c7211c1 100644 --- a/src/libstd/term.rs +++ b/src/libstd/term.rs @@ -9,7 +9,6 @@ // except according to those terms. //! Simple ANSI color library -#[forbid(deprecated_mode)]; use core::i32; use core::io; diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 4f0b7da89aa..e83b759f901 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -15,8 +15,6 @@ // simplest interface possible for representing and running tests // while providing a base that other test frameworks may build off of. -#[forbid(deprecated_mode)]; - use getopts; use sort; use term; @@ -51,20 +49,24 @@ pub type TestName = ~str; // the test succeeds; if the function fails then the test fails. We // may need to come up with a more clever definition of test in order // to support isolation of tests into tasks. -pub type TestFn = fn~(); +pub type TestFn = ~fn(); // The definition of a single test. A test runner will run a list of // these. pub struct TestDesc { name: TestName, - testfn: TestFn, ignore: bool, should_fail: bool } +pub struct TestDescAndFn { + desc: TestDesc, + testfn: TestFn, +} + // The default console test runner. It accepts the command line // arguments and a vector of test_descs (generated at compile time). -pub fn test_main(args: &[~str], tests: &[TestDesc]) { +pub fn test_main(args: &[~str], tests: ~[TestDescAndFn]) { let opts = match parse_opts(args) { either::Left(move o) => o, @@ -124,7 +126,7 @@ struct ConsoleTestState { // A simple console test runner pub fn run_tests_console(opts: &TestOpts, - tests: &[TestDesc]) -> bool { + tests: ~[TestDescAndFn]) -> bool { fn callback(event: &TestEvent, st: @ConsoleTestState) { debug!("callback(event=%?)", event); @@ -247,17 +249,17 @@ fn print_failures(st: @ConsoleTestState) { #[test] fn should_sort_failures_before_printing_them() { + fn dummy() {} + let s = do io::with_str_writer |wr| { let test_a = TestDesc { name: ~"a", - testfn: fn~() { }, ignore: false, should_fail: false }; let test_b = TestDesc { name: ~"b", - testfn: fn~() { }, ignore: false, should_fail: false }; @@ -291,45 +293,44 @@ enum TestEvent { type MonitorMsg = (TestDesc, TestResult); fn run_tests(opts: &TestOpts, - tests: &[TestDesc], + tests: ~[TestDescAndFn], callback: fn@(e: TestEvent)) { let mut filtered_tests = filter_tests(opts, tests); - callback(TeFiltered(copy filtered_tests)); + + let filtered_descs = filtered_tests.map(|t| t.desc); + callback(TeFiltered(filtered_descs)); // It's tempting to just spawn all the tests at once, but since we have // many tests that run in other processes we would be making a big mess. let concurrency = get_concurrency(); debug!("using %u test tasks", concurrency); - let total = vec::len(filtered_tests); - let mut run_idx = 0; - let mut wait_idx = 0; - let mut done_idx = 0; + let mut remaining = filtered_tests; + vec::reverse(remaining); + let mut pending = 0; let (p, ch) = stream(); let ch = SharedChan(ch); - while done_idx < total { - while wait_idx < concurrency && run_idx < total { - let test = copy filtered_tests[run_idx]; + while pending > 0 || !remaining.is_empty() { + while pending < concurrency && !remaining.is_empty() { + let test = remaining.pop(); if concurrency == 1 { // We are doing one test at a time so we can print the name // of the test before we run it. Useful for debugging tests // that hang forever. - callback(TeWait(copy test)); + callback(TeWait(test.desc)); } - run_test(move test, ch.clone()); - wait_idx += 1; - run_idx += 1; + run_test(test, ch.clone()); + pending += 1; } - let (test, result) = p.recv(); + let (desc, result) = p.recv(); if concurrency != 1 { - callback(TeWait(copy test)); + callback(TeWait(desc)); } - callback(TeResult(move test, result)); - wait_idx -= 1; - done_idx += 1; + callback(TeResult(desc, result)); + pending -= 1; } } @@ -349,10 +350,11 @@ fn get_concurrency() -> uint { } #[allow(non_implicitly_copyable_typarams)] -pub fn filter_tests(opts: &TestOpts, - tests: &[TestDesc]) - -> ~[TestDesc] { - let mut filtered = vec::slice(tests, 0, tests.len()); +pub fn filter_tests( + opts: &TestOpts, + tests: ~[TestDescAndFn]) -> ~[TestDescAndFn] +{ + let mut filtered = tests; // Remove tests that don't match the test filter filtered = if opts.filter.is_none() { @@ -364,10 +366,10 @@ pub fn filter_tests(opts: &TestOpts, option::None => ~"" }; - fn filter_fn(test: &TestDesc, filter_str: &str) -> - Option { - if str::contains(test.name, filter_str) { - return option::Some(copy *test); + fn filter_fn(test: TestDescAndFn, filter_str: &str) -> + Option { + if str::contains(test.desc.name, filter_str) { + return option::Some(test); } else { return option::None; } } @@ -378,26 +380,26 @@ pub fn filter_tests(opts: &TestOpts, filtered = if !opts.run_ignored { move filtered } else { - fn filter(test: &TestDesc) -> Option { - if test.ignore { - return option::Some(TestDesc { - name: test.name, - testfn: copy test.testfn, - ignore: false, - should_fail: test.should_fail}); - } else { return option::None; } + fn filter(test: TestDescAndFn) -> Option { + if test.desc.ignore { + let TestDescAndFn {desc, testfn} = test; + Some(TestDescAndFn { + desc: TestDesc {ignore: false, ..desc}, + testfn: testfn + }) + } else { + None + } }; vec::filter_map(filtered, |x| filter(x)) }; // Sort the tests alphabetically - filtered = { - pure fn lteq(t1: &TestDesc, t2: &TestDesc) -> bool { - str::le(t1.name, t2.name) - } - sort::merge_sort(filtered, lteq) - }; + pure fn lteq(t1: &TestDescAndFn, t2: &TestDescAndFn) -> bool { + str::le(t1.desc.name, t2.desc.name) + } + sort::quick_sort(filtered, lteq); move filtered } @@ -407,37 +409,40 @@ struct TestFuture { wait: fn@() -> TestResult, } -pub fn run_test(test: TestDesc, monitor_ch: SharedChan) { - if test.ignore { - monitor_ch.send((copy test, TrIgnored)); +pub fn run_test(test: TestDescAndFn, monitor_ch: SharedChan) { + let TestDescAndFn {desc, testfn} = test; + + if desc.ignore { + monitor_ch.send((desc, TrIgnored)); return; } - do task::spawn |move test| { - let testfn = copy test.testfn; + let testfn_cell = ::cell::Cell(testfn); + do task::spawn { let mut result_future = None; // task::future_result(builder); task::task().unlinked().future_result(|+r| { result_future = Some(move r); - }).spawn(move testfn); + }).spawn(testfn_cell.take()); let task_result = option::unwrap(move result_future).recv(); - let test_result = calc_result(&test, task_result == task::Success); - monitor_ch.send((copy test, test_result)); + let test_result = calc_result(&desc, task_result == task::Success); + monitor_ch.send((desc, test_result)); }; } -fn calc_result(test: &TestDesc, task_succeeded: bool) -> TestResult { +fn calc_result(desc: &TestDesc, task_succeeded: bool) -> TestResult { if task_succeeded { - if test.should_fail { TrFailed } + if desc.should_fail { TrFailed } else { TrOk } } else { - if test.should_fail { TrOk } + if desc.should_fail { TrOk } else { TrFailed } } } #[cfg(test)] mod tests { - use test::{TrFailed, TrIgnored, TrOk, filter_tests, parse_opts, TestDesc}; + use test::{TrFailed, TrIgnored, TrOk, filter_tests, parse_opts, + TestDesc, TestDescAndFn}; use test::{TestOpts, run_test}; use core::either; @@ -448,11 +453,13 @@ mod tests { #[test] pub fn do_not_run_ignored_tests() { fn f() { die!(); } - let desc = TestDesc { - name: ~"whatever", + let desc = TestDescAndFn { + desc: TestDesc { + name: ~"whatever", + ignore: true, + should_fail: false + }, testfn: f, - ignore: true, - should_fail: false }; let (p, ch) = stream(); let ch = SharedChan(ch); @@ -464,11 +471,13 @@ mod tests { #[test] pub fn ignored_tests_result_in_ignored() { fn f() { } - let desc = TestDesc { - name: ~"whatever", + let desc = TestDescAndFn { + desc: TestDesc { + name: ~"whatever", + ignore: true, + should_fail: false + }, testfn: f, - ignore: true, - should_fail: false }; let (p, ch) = stream(); let ch = SharedChan(ch); @@ -481,11 +490,13 @@ mod tests { #[ignore(cfg(windows))] pub fn test_should_fail() { fn f() { die!(); } - let desc = TestDesc { - name: ~"whatever", + let desc = TestDescAndFn { + desc: TestDesc { + name: ~"whatever", + ignore: false, + should_fail: true + }, testfn: f, - ignore: false, - should_fail: true }; let (p, ch) = stream(); let ch = SharedChan(ch); @@ -497,11 +508,13 @@ mod tests { #[test] pub fn test_should_fail_but_succeeds() { fn f() { } - let desc = TestDesc { - name: ~"whatever", + let desc = TestDescAndFn { + desc: TestDesc { + name: ~"whatever", + ignore: false, + should_fail: true + }, testfn: f, - ignore: false, - should_fail: true }; let (p, ch) = stream(); let ch = SharedChan(ch); @@ -532,6 +545,8 @@ mod tests { #[test] pub fn filter_for_ignored_option() { + fn dummy() {} + // When we run ignored tests the test filter should filter out all the // unignored tests and flip the ignore flag on the rest to false @@ -542,24 +557,28 @@ mod tests { }; let tests = ~[ - TestDesc { - name: ~"1", - testfn: fn~() { }, - ignore: true, - should_fail: false, + TestDescAndFn { + desc: TestDesc { + name: ~"1", + ignore: true, + should_fail: false, + }, + testfn: dummy, }, - TestDesc { - name: ~"2", - testfn: fn~() { }, - ignore: false, - should_fail: false, + TestDescAndFn { + desc: TestDesc { + name: ~"2", + ignore: false, + should_fail: false + }, + testfn: dummy, }, ]; let filtered = filter_tests(&opts, tests); assert (vec::len(filtered) == 1); - assert (filtered[0].name == ~"1"); - assert (filtered[0].ignore == false); + assert (filtered[0].desc.name == ~"1"); + assert (filtered[0].desc.ignore == false); } #[test] @@ -579,12 +598,16 @@ mod tests { ~"test::sort_tests"]; let tests = { - let testfn = fn~() { }; + fn testfn() { } let mut tests = ~[]; for vec::each(names) |name| { - let test = TestDesc { - name: *name, testfn: copy testfn, ignore: false, - should_fail: false}; + let test = TestDescAndFn { + desc: TestDesc { + name: *name, ignore: false, + should_fail: false + }, + testfn: testfn, + }; tests.push(move test); } move tests @@ -604,7 +627,7 @@ mod tests { for vec::each(pairs) |p| { match *p { - (ref a, ref b) => { assert (*a == b.name); } + (ref a, ref b) => { assert (*a == b.desc.name); } } } } diff --git a/src/libstd/time.rs b/src/libstd/time.rs index dd25fc36d2d..f696d239d30 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[forbid(deprecated_mode)]; - use core::cmp::{Eq, Ord}; use core::int; use core::libc::{c_char, c_int, c_long, size_t, time_t}; diff --git a/src/libstd/timer.rs b/src/libstd/timer.rs index f89830ed12a..1da1bc60314 100644 --- a/src/libstd/timer.rs +++ b/src/libstd/timer.rs @@ -10,8 +10,6 @@ //! Utilities that leverage libuv's `uv_timer_*` API -#[forbid(deprecated_mode)]; - use uv; use uv::iotask; use uv::iotask::IoTask; diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index 3cc287b16a3..1e90abcc03d 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -12,8 +12,6 @@ //! trees. The only requirement for the types is that the key implements //! `Ord`, and that the `lt` method provides a total ordering. -#[forbid(deprecated_mode)]; - use core::container::{Container, Mutable, Map, Set}; use core::cmp::{Eq, Ord}; use core::option::{Option, Some, None}; diff --git a/src/libstd/uv_global_loop.rs b/src/libstd/uv_global_loop.rs index 736954f6b22..9763f655a6f 100644 --- a/src/libstd/uv_global_loop.rs +++ b/src/libstd/uv_global_loop.rs @@ -10,8 +10,6 @@ //! A process-wide libuv event loop for library use. -#[forbid(deprecated_mode)]; - use ll = uv_ll; use iotask = uv_iotask; use get_gl = get; diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index fe4137f76be..a44fef54b72 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -14,7 +14,6 @@ * The I/O task runs in its own single-threaded scheduler. By using the * `interact` function you can execute code in a uv callback. */ -#[forbid(deprecated_mode)]; use ll = uv_ll; diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index 4e9df14419b..b828c4ef629 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[allow(deprecated_mode)]; + use json; use sha1; use serialize::{Encoder, Encodable, Decoder, Decodable}; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index bc808495ca3..574ce281e28 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -399,16 +399,46 @@ pub impl mutability : cmp::Eq { #[auto_encode] #[auto_decode] #[deriving_eq] -pub enum Proto { - ProtoBare, // bare functions (deprecated) - ProtoUniq, // ~fn - ProtoBox, // @fn - ProtoBorrowed, // &fn +pub enum Abi { + RustAbi } -pub impl Proto : to_bytes::IterBytes { +pub impl Abi : to_bytes::IterBytes { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { - (*self as uint).iter_bytes(lsb0, f); + (*self as uint).iter_bytes(lsb0, f) + } +} + +pub impl Abi : ToStr { + pure fn to_str(&self) -> ~str { + match *self { + RustAbi => ~"\"rust\"" + } + } +} + +#[auto_encode] +#[auto_decode] +#[deriving_eq] +pub enum Sigil { + BorrowedSigil, + OwnedSigil, + ManagedSigil +} + +pub impl Sigil : to_bytes::IterBytes { + pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { + (*self as uint).iter_bytes(lsb0, f) + } +} + +pub impl Sigil : ToStr { + pure fn to_str(&self) -> ~str { + match *self { + BorrowedSigil => ~"&", + OwnedSigil => ~"~", + ManagedSigil => ~"@" + } } } @@ -434,13 +464,6 @@ pub enum expr_vstore { expr_vstore_mut_slice, // &mut [1,2,3,4] } -pub pure fn is_blockish(p: Proto) -> bool { - match p { - ProtoBorrowed => true, - ProtoBare | ProtoUniq | ProtoBox => false - } -} - #[auto_encode] #[auto_decode] pub enum binop { @@ -671,14 +694,23 @@ pub struct expr { pub enum log_level { error, debug, log_other } // 0 = error, 1 = debug, 2 = log_other +#[auto_encode] +#[auto_decode] +#[deriving_eq] +pub enum CallSugar { + NoSugar, + DoSugar, + ForSugar +} + #[auto_encode] #[auto_decode] pub enum expr_ { expr_vstore(@expr, expr_vstore), expr_vec(~[@expr], mutability), expr_rec(~[field], Option<@expr>), - expr_call(@expr, ~[@expr], bool), // True iff last argument is a block - expr_method_call(@expr, ident, ~[@Ty], ~[@expr], bool), // Ditto + expr_call(@expr, ~[@expr], CallSugar), + expr_method_call(@expr, ident, ~[@Ty], ~[@expr], CallSugar), expr_tup(~[@expr]), expr_binary(binop, @expr, @expr), expr_unary(unop, @expr), @@ -693,7 +725,7 @@ pub enum expr_ { expr_match(@expr, ~[arm]), // FIXME(#4717) the @() is req'd on windows or else LLVM croaks - expr_fn(Proto, fn_decl, blk, @()), + expr_fn(Sigil, fn_decl, blk, @()), expr_fn_block(fn_decl, blk), // Inner expr is always an expr_fn_block. We need the wrapping node to @@ -1112,12 +1144,19 @@ pub impl Onceness : to_bytes::IterBytes { #[auto_encode] #[auto_decode] -pub struct TyFn { - proto: Proto, +pub struct TyClosure { + sigil: Sigil, region: Option<@region>, purity: purity, onceness: Onceness, - bounds: @~[ty_param_bound], + decl: fn_decl +} + +#[auto_encode] +#[auto_decode] +pub struct TyBareFn { + purity: purity, + abi: Abi, decl: fn_decl } @@ -1133,7 +1172,8 @@ pub enum ty_ { ty_ptr(mt), ty_rptr(@region, mt), ty_rec(~[ty_field]), - ty_fn(@TyFn), + ty_closure(@TyClosure), + ty_bare_fn(@TyBareFn), ty_tup(~[@Ty]), ty_path(@path, node_id), ty_mac(mac), diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index ca28641c4a3..c347c04641f 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -154,7 +154,7 @@ pub fn find_attrs_by_name(attrs: &[ast::attribute], name: &str) -> option::None } }; - return vec::filter_map(attrs, filter); + return vec::filter_mapped(attrs, filter); } /// Search a list of meta items and return only those with a specific name @@ -277,9 +277,9 @@ pub fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] { pub fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: ~str) -> ~[@ast::meta_item] { - return vec::filter_map(items, |item| { + return vec::filter_mapped(items, |item| { if get_meta_item_name(*item) != name { - option::Some(/* FIXME (#2543) */ copy *item) + option::Some(*item) } else { option::None } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 31ed65d8065..a509325face 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -76,7 +76,7 @@ pub impl BytePos: Sub { } pub impl BytePos: to_bytes::IterBytes { - pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(&self, +lsb0: bool, &&f: to_bytes::Cb) { (**self).iter_bytes(lsb0, f) } } @@ -99,7 +99,7 @@ pub impl CharPos: cmp::Ord { } pub impl CharPos: to_bytes::IterBytes { - pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(&self, +lsb0: bool, &&f: to_bytes::Cb) { (**self).iter_bytes(lsb0, f) } } diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 03aa0cde811..21154bff01e 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -392,7 +392,7 @@ priv impl ext_ctxt { expr: @ast::expr, args: ~[@ast::expr] ) -> @ast::expr { - self.expr(span, ast::expr_call(expr, args, false)) + self.expr(span, ast::expr_call(expr, args, ast::NoSugar)) } fn lambda_expr(expr: @ast::expr) -> @ast::expr { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 4d8fd39c960..a050b2316e8 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -103,7 +103,7 @@ pub fn mk_addr_of(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { } pub fn mk_call_(cx: ext_ctxt, sp: span, fn_expr: @ast::expr, args: ~[@ast::expr]) -> @ast::expr { - mk_expr(cx, sp, ast::expr_call(fn_expr, args, false)) + mk_expr(cx, sp, ast::expr_call(fn_expr, args, ast::NoSugar)) } pub fn mk_call(cx: ext_ctxt, sp: span, fn_path: ~[ast::ident], args: ~[@ast::expr]) -> @ast::expr { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index cfa8a3c1153..8cecbfb1210 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -536,13 +536,18 @@ pub fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ { ty_rptr(region, mt) => ty_rptr(region, fold_mt(mt, fld)), ty_rec(ref fields) => ty_rec(vec::map((*fields), |f| fold_field(*f, fld))), - ty_fn(f) => - ty_fn(@TyFn { - proto: f.proto, + ty_closure(f) => + ty_closure(@TyClosure { + sigil: f.sigil, purity: f.purity, region: f.region, onceness: f.onceness, - bounds: @vec::map(*f.bounds, |x| fold_ty_param_bound(*x, fld)), + decl: fold_fn_decl(f.decl, fld) + }), + ty_bare_fn(f) => + ty_bare_fn(@TyBareFn { + purity: f.purity, + abi: f.abi, decl: fold_fn_decl(f.decl, fld) }), ty_tup(tys) => ty_tup(vec::map(tys, |ty| fld.fold_ty(*ty))), @@ -557,7 +562,7 @@ pub fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ { pub fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod { ast::_mod { view_items: vec::map(m.view_items, |x| fld.fold_view_item(*x)), - items: vec::filter_map(m.items, |x| fld.fold_item(*x)), + items: vec::filter_mapped(m.items, |x| fld.fold_item(*x)), } } diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 4ceb04c55d0..64c4cb3c508 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -23,8 +23,10 @@ pub fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool { | ast::expr_block(_) | ast::expr_while(*) | ast::expr_loop(*) - | ast::expr_call(_, _, true) - | ast::expr_method_call(_, _, _, _, true) => false, + | ast::expr_call(_, _, ast::DoSugar) + | ast::expr_call(_, _, ast::ForSugar) + | ast::expr_method_call(_, _, _, _, ast::DoSugar) + | ast::expr_method_call(_, _, _, _, ast::ForSugar) => false, _ => true } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5cd78dd9049..7fb3064c388 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -10,7 +10,10 @@ use core::prelude::*; -use ast::{ProtoBox, ProtoUniq, RegionTyParamBound, TraitTyParamBound}; +use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil, RustAbi}; +use ast::{CallSugar, NoSugar, DoSugar, ForSugar}; +use ast::{TyBareFn, TyClosure}; +use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{provided, public, pure_fn, purity, re_static}; use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer}; use ast::{bind_by_copy, bitand, bitor, bitxor, blk}; @@ -27,7 +30,7 @@ use ast::{expr_ret, expr_swap, expr_struct, expr_tup, expr_unary}; use ast::{expr_vec, expr_vstore, expr_vstore_mut_box}; use ast::{expr_vstore_fixed, expr_vstore_slice, expr_vstore_box}; use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl}; -use ast::{expr_vstore_uniq, TyFn, Onceness, Once, Many}; +use ast::{expr_vstore_uniq, TyClosure, TyBareFn, Onceness, Once, Many}; use ast::{foreign_item, foreign_item_const, foreign_item_fn, foreign_mod}; use ast::{ident, impure_fn, infer, inherited, item, item_, item_const}; use ast::{item_const, item_enum, item_fn, item_foreign_mod, item_impl}; @@ -38,15 +41,16 @@ use ast::{m_imm, m_mutbl, mac_, mac_invoc_tt, matcher, match_nonterminal}; use ast::{match_seq, match_tok, method, mode, module_ns, mt, mul, mutability}; use ast::{named_field, neg, node_id, noreturn, not, pat, pat_box, pat_enum}; use ast::{pat_ident, pat_lit, pat_range, pat_rec, pat_region, pat_struct}; -use ast::{pat_tup, pat_uniq, pat_wild, path, private, Proto, ProtoBare}; -use ast::{ProtoBorrowed, re_self, re_anon, re_named, region, rem, required}; +use ast::{pat_tup, pat_uniq, pat_wild, path, private}; +use ast::{re_self, re_anon, re_named, region, rem, required}; use ast::{ret_style, return_val, self_ty, shl, shr, stmt, stmt_decl}; use ast::{stmt_expr, stmt_semi, stmt_mac, struct_def, struct_field}; use ast::{struct_immutable, struct_mutable, struct_variant_kind, subtract}; use ast::{sty_box, sty_by_ref, sty_region, sty_static, sty_uniq, sty_value}; use ast::{token_tree, trait_method, trait_ref, tt_delim, tt_seq, tt_tok}; use ast::{tt_nonterminal, tuple_variant_kind, Ty, ty_, ty_bot, ty_box}; -use ast::{ty_field, ty_fixed_length_vec, ty_fn, ty_infer, ty_mac, ty_method}; +use ast::{ty_field, ty_fixed_length_vec, ty_closure, ty_bare_fn}; +use ast::{ty_infer, ty_mac, ty_method}; use ast::{ty_nil, ty_param, ty_param_bound, ty_path, ty_ptr, ty_rec, ty_rptr}; use ast::{ty_tup, ty_u32, ty_uniq, ty_vec, type_value_ns, uniq}; use ast::{unnamed_field, unsafe_blk, unsafe_fn, variant, view_item}; @@ -293,25 +297,49 @@ pub impl Parser { pure fn id_to_str(id: ident) -> @~str { self.sess.interner.get(id) } - fn token_is_fn_keyword(+tok: token::Token) -> bool { + fn token_is_closure_keyword(+tok: token::Token) -> bool { self.token_is_keyword(~"pure", tok) || self.token_is_keyword(~"unsafe", tok) || self.token_is_keyword(~"once", tok) || - self.token_is_keyword(~"fn", tok) || - self.token_is_keyword(~"extern", tok) + self.token_is_keyword(~"fn", tok) } - fn parse_ty_fn(pre_proto: Option, - pre_region_name: Option) -> ty_ + fn parse_ty_bare_fn() -> ty_ { /* - (&|~|@) [r/] [pure|unsafe] [once] fn [:K] (S) -> T - ^~~~~~^ ^~~^ ^~~~~~~~~~~~^ ^~~~~^ ^~~^ ^~^ ^ - | | | | | | | - | | | | | | Return type - | | | | | Argument types - | | | | Environment bounds + extern "ABI" [pure|unsafe] fn (S) -> T + ^~~~^ ^~~~~~~~~~~~^ ^~^ ^ + | | | | + | | | Return type + | | Argument types + | | + | | + | Purity + ABI + + */ + + let purity = self.parse_purity(); + self.expect_keyword(~"fn"); + return ty_bare_fn(@TyBareFn { + abi: RustAbi, + purity: purity, + decl: self.parse_ty_fn_decl() + }); + } + + fn parse_ty_closure(pre_sigil: Option, + pre_region_name: Option) -> ty_ + { + /* + + (&|~|@) [r/] [pure|unsafe] [once] fn (S) -> T + ^~~~~~^ ^~~^ ^~~~~~~~~~~~^ ^~~~~^ ^~^ ^ + | | | | | | + | | | | | Return type + | | | | Argument types + | | | | | | | Once-ness (a.k.a., affine) | | Purity | Lifetime bound @@ -322,22 +350,13 @@ pub impl Parser { // At this point, the allocation type and lifetime bound have been // parsed. - let purity = parse_purity(&self); + let purity = self.parse_purity(); let onceness = parse_onceness(&self); + self.expect_keyword(~"fn"); + let post_sigil = self.parse_fn_ty_sigil(); - let bounds, post_proto; - if self.eat_keyword(~"extern") { - self.expect_keyword(~"fn"); - post_proto = Some(ast::ProtoBare); - bounds = @~[]; - } else { - self.expect_keyword(~"fn"); - post_proto = self.parse_fn_ty_proto(); - bounds = self.parse_optional_ty_param_bounds(); - }; - - let proto = match (pre_proto, post_proto) { - (None, None) => ast::ProtoBorrowed, + let sigil = match (pre_sigil, post_sigil) { + (None, None) => BorrowedSigil, (Some(p), None) | (None, Some(p)) => p, (Some(_), Some(_)) => { self.fatal(~"cannot combine prefix and postfix \ @@ -352,30 +371,28 @@ pub impl Parser { None }; - return ty_fn(@TyFn { - proto: proto, + return ty_closure(@TyClosure { + sigil: sigil, region: region, purity: purity, onceness: onceness, - bounds: bounds, decl: self.parse_ty_fn_decl() }); - fn parse_purity(self: &Parser) -> purity { - if self.eat_keyword(~"pure") { - return pure_fn; - } else if self.eat_keyword(~"unsafe") { - return unsafe_fn; - } else { - return impure_fn; - } - } - fn parse_onceness(self: &Parser) -> Onceness { if self.eat_keyword(~"once") {Once} else {Many} } } + fn parse_purity() -> purity { + if self.eat_keyword(~"pure") { + return pure_fn; + } else if self.eat_keyword(~"unsafe") { + return unsafe_fn; + } else { + return impure_fn; + } + } fn parse_ty_fn_decl() -> fn_decl { let inputs = do self.parse_unspanned_seq( @@ -560,10 +577,10 @@ pub impl Parser { } } else if self.token == token::AT { self.bump(); - self.parse_box_or_uniq_pointee(ast::ProtoBox, ty_box) + self.parse_box_or_uniq_pointee(ManagedSigil, ty_box) } else if self.token == token::TILDE { self.bump(); - self.parse_box_or_uniq_pointee(ast::ProtoUniq, ty_uniq) + self.parse_box_or_uniq_pointee(OwnedSigil, ty_uniq) } else if self.token == token::BINOP(token::STAR) { self.bump(); ty_ptr(self.parse_mt()) @@ -590,8 +607,10 @@ pub impl Parser { } else if self.token == token::BINOP(token::AND) { self.bump(); self.parse_borrowed_pointee() - } else if self.token_is_fn_keyword(self.token) { - self.parse_ty_fn(None, None) + } else if self.eat_keyword(~"extern") { + self.parse_ty_bare_fn() + } else if self.token_is_closure_keyword(self.token) { + self.parse_ty_closure(None, None) } else if self.token == token::MOD_SEP || is_ident_or_path(self.token) { let path = self.parse_path_with_tps(colons_before_params); @@ -603,19 +622,19 @@ pub impl Parser { } fn parse_box_or_uniq_pointee( - proto: ast::Proto, + sigil: ast::Sigil, ctor: &fn(+v: mt) -> ty_) -> ty_ { // @foo/fn() or @fn() are parsed directly as fn types: match copy self.token { token::IDENT(rname, _) => { if self.look_ahead(1u) == token::BINOP(token::SLASH) && - self.token_is_fn_keyword(self.look_ahead(2u)) + self.token_is_closure_keyword(self.look_ahead(2u)) { self.bump(); self.bump(); - return self.parse_ty_fn(Some(proto), Some(rname)); - } else if self.token_is_fn_keyword(self.token) { - return self.parse_ty_fn(Some(proto), None); + return self.parse_ty_closure(Some(sigil), Some(rname)); + } else if self.token_is_closure_keyword(self.token) { + return self.parse_ty_closure(Some(sigil), None); } } _ => {} @@ -643,8 +662,8 @@ pub impl Parser { _ => { None } }; - if self.token_is_fn_keyword(self.token) { - return self.parse_ty_fn(Some(ProtoBorrowed), rname); + if self.token_is_closure_keyword(self.token) { + return self.parse_ty_closure(Some(BorrowedSigil), rname); } let r = self.region_from_name(rname); @@ -981,9 +1000,11 @@ pub impl Parser { } else if self.eat_keyword(~"if") { return self.parse_if_expr(); } else if self.eat_keyword(~"for") { - return self.parse_sugary_call_expr(~"for", expr_loop_body); + return self.parse_sugary_call_expr(~"for", ForSugar, + expr_loop_body); } else if self.eat_keyword(~"do") { - return self.parse_sugary_call_expr(~"do", expr_do_body); + return self.parse_sugary_call_expr(~"do", DoSugar, + expr_do_body); } else if self.eat_keyword(~"while") { return self.parse_while_expr(); } else if self.eat_keyword(~"loop") { @@ -991,14 +1012,14 @@ pub impl Parser { } else if self.eat_keyword(~"match") { return self.parse_match_expr(); } else if self.eat_keyword(~"fn") { - let opt_proto = self.parse_fn_ty_proto(); - let proto = match opt_proto { - None | Some(ast::ProtoBare) => { + let opt_sigil = self.parse_fn_ty_sigil(); + let sigil = match opt_sigil { + None => { self.fatal(~"fn expr are deprecated, use fn@") } Some(p) => { p } }; - return self.parse_fn_expr(proto); + return self.parse_fn_expr(sigil); } else if self.eat_keyword(~"unsafe") { return self.parse_block_expr(lo, unsafe_blk); } else if self.token == token::LBRACKET { @@ -1176,7 +1197,7 @@ pub impl Parser { |p| p.parse_expr()); hi = self.span.hi; - let nd = expr_method_call(e, i, tys, es, false); + let nd = expr_method_call(e, i, tys, es, NoSugar); e = self.mk_expr(lo, hi, move nd); } _ => { @@ -1198,7 +1219,7 @@ pub impl Parser { |p| p.parse_expr()); hi = self.span.hi; - let nd = expr_call(e, es, false); + let nd = expr_call(e, es, NoSugar); e = self.mk_expr(lo, hi, nd); } @@ -1566,7 +1587,7 @@ pub impl Parser { self.mk_expr(q.lo, q.hi, expr_if(q.cond, q.then, q.els)) } - fn parse_fn_expr(proto: Proto) -> @expr { + fn parse_fn_expr(sigil: Sigil) -> @expr { let lo = self.last_span.lo; // if we want to allow fn expression argument types to be inferred in @@ -1576,7 +1597,7 @@ pub impl Parser { let body = self.parse_block(); self.mk_expr(lo, body.span.hi, - expr_fn(proto, decl, body, @())) + expr_fn(sigil, decl, body, @())) } // `|args| { ... }` like in `do` expressions @@ -1641,6 +1662,7 @@ pub impl Parser { } fn parse_sugary_call_expr(keyword: ~str, + sugar: CallSugar, ctor: fn(+v: @expr) -> expr_) -> @expr { let lo = self.last_span; // Parse the callee `foo` in @@ -1654,27 +1676,27 @@ pub impl Parser { // them as the lambda arguments let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP); match e.node { - expr_call(f, args, false) => { + expr_call(f, args, NoSugar) => { let block = self.parse_lambda_block_expr(); let last_arg = self.mk_expr(block.span.lo, block.span.hi, ctor(block)); let args = vec::append(args, ~[last_arg]); - self.mk_expr(lo.lo, block.span.hi, expr_call(f, args, true)) + self.mk_expr(lo.lo, block.span.hi, expr_call(f, args, sugar)) } - expr_method_call(f, i, tps, args, false) => { + expr_method_call(f, i, tps, args, NoSugar) => { let block = self.parse_lambda_block_expr(); let last_arg = self.mk_expr(block.span.lo, block.span.hi, ctor(block)); let args = vec::append(args, ~[last_arg]); self.mk_expr(lo.lo, block.span.hi, - expr_method_call(f, i, tps, args, true)) + expr_method_call(f, i, tps, args, sugar)) } expr_field(f, i, tps) => { let block = self.parse_lambda_block_expr(); let last_arg = self.mk_expr(block.span.lo, block.span.hi, ctor(block)); self.mk_expr(lo.lo, block.span.hi, - expr_method_call(f, i, tps, ~[last_arg], true)) + expr_method_call(f, i, tps, ~[last_arg], sugar)) } expr_path(*) | expr_call(*) | expr_method_call(*) | expr_paren(*) => { @@ -1682,7 +1704,7 @@ pub impl Parser { let last_arg = self.mk_expr(block.span.lo, block.span.hi, ctor(block)); self.mk_expr(lo.lo, last_arg.span.hi, - expr_call(e, ~[last_arg], true)) + expr_call(e, ~[last_arg], sugar)) } _ => { // There may be other types of expressions that can @@ -3592,19 +3614,19 @@ pub impl Parser { (id, item_enum(enum_definition, ty_params), None) } - fn parse_fn_ty_proto() -> Option { + fn parse_fn_ty_sigil() -> Option { match self.token { token::AT => { self.bump(); - Some(ProtoBox) + Some(ManagedSigil) } token::TILDE => { self.bump(); - Some(ProtoUniq) + Some(OwnedSigil) } token::BINOP(token::AND) => { self.bump(); - Some(ProtoBorrowed) + Some(BorrowedSigil) } _ => { None diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 5079766239b..bcbee7b2f24 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -404,9 +404,15 @@ pub fn print_type_ex(s: ps, &&ty: @ast::Ty, print_colons: bool) { commasep(s, inconsistent, elts, print_type); pclose(s); } - ast::ty_fn(f) => { - print_ty_fn(s, Some(f.proto), f.region, f.purity, - f.onceness, f.bounds, f.decl, None, None, None); + ast::ty_bare_fn(f) => { + print_ty_fn(s, Some(f.abi), None, None, + f.purity, ast::Many, f.decl, None, + None, None); + } + ast::ty_closure(f) => { + print_ty_fn(s, None, Some(f.sigil), f.region, + f.purity, f.onceness, f.decl, None, + None, None); } ast::ty_path(path, _) => print_path(s, path, print_colons), ast::ty_fixed_length_vec(mt, v) => { @@ -806,8 +812,8 @@ pub fn print_ty_method(s: ps, m: ast::ty_method) { hardbreak_if_not_bol(s); maybe_print_comment(s, m.span.lo); print_outer_attributes(s, m.attrs); - print_ty_fn(s, None, None, m.purity, ast::Many, - @~[], m.decl, Some(m.ident), Some(m.tps), + print_ty_fn(s, None, None, None, m.purity, ast::Many, + m.decl, Some(m.ident), Some(m.tps), Some(m.self_ty.node)); word(s.s, ~";"); } @@ -1046,32 +1052,32 @@ pub fn print_expr_vstore(s: ps, t: ast::expr_vstore) { } pub fn print_call_pre(s: ps, - has_block: bool, + sugar: ast::CallSugar, base_args: &mut ~[@ast::expr]) -> Option<@ast::expr> { - if has_block { - let blk_arg = base_args.pop(); - match blk_arg.node { - ast::expr_loop_body(_) => { head(s, ~"for"); } - ast::expr_do_body(_) => { head(s, ~"do"); } - _ => {} + match sugar { + ast::DoSugar => { + head(s, ~"do"); + Some(base_args.pop()) } - Some(blk_arg) - } else { - None + ast::ForSugar => { + head(s, ~"for"); + Some(base_args.pop()) + } + ast::NoSugar => None } } pub fn print_call_post(s: ps, - has_block: bool, + sugar: ast::CallSugar, blk: &Option<@ast::expr>, base_args: &mut ~[@ast::expr]) { - if !has_block || !base_args.is_empty() { + if sugar == ast::NoSugar || !base_args.is_empty() { popen(s); commasep_exprs(s, inconsistent, *base_args); pclose(s); } - if has_block { + if sugar != ast::NoSugar { nbsp(s); match blk.get().node { // need to handle closures specifically @@ -1181,15 +1187,15 @@ pub fn print_expr(s: ps, &&expr: @ast::expr) { commasep_exprs(s, inconsistent, exprs); pclose(s); } - ast::expr_call(func, args, has_block) => { + ast::expr_call(func, args, sugar) => { let mut base_args = copy args; - let blk = print_call_pre(s, has_block, &mut base_args); + let blk = print_call_pre(s, sugar, &mut base_args); print_expr(s, func); - print_call_post(s, has_block, &blk, &mut base_args); + print_call_post(s, sugar, &blk, &mut base_args); } - ast::expr_method_call(func, ident, tys, args, has_block) => { + ast::expr_method_call(func, ident, tys, args, sugar) => { let mut base_args = copy args; - let blk = print_call_pre(s, has_block, &mut base_args); + let blk = print_call_pre(s, sugar, &mut base_args); print_expr(s, func); word(s.s, ~"."); print_ident(s, ident); @@ -1198,7 +1204,7 @@ pub fn print_expr(s: ps, &&expr: @ast::expr) { commasep(s, inconsistent, tys, print_type); word(s.s, ~">"); } - print_call_post(s, has_block, &blk, &mut base_args); + print_call_post(s, sugar, &blk, &mut base_args); } ast::expr_binary(op, lhs, rhs) => { print_expr(s, lhs); @@ -1305,13 +1311,13 @@ pub fn print_expr(s: ps, &&expr: @ast::expr) { } bclose_(s, expr.span, match_indent_unit); } - ast::expr_fn(proto, decl, ref body, _) => { + ast::expr_fn(sigil, decl, ref body, _) => { // containing cbox, will be closed by print-block at } cbox(s, indent_unit); // head-box, will be closed by print-block at start ibox(s, 0u); print_fn_header_info(s, None, None, ast::Many, - Some(proto), ast::inherited); + Some(sigil), ast::inherited); print_fn_args_and_ret(s, decl, None); space(s.s); print_block(s, (*body)); @@ -1900,33 +1906,32 @@ pub fn print_arg(s: ps, input: ast::arg) { } pub fn print_ty_fn(s: ps, - opt_proto: Option, + opt_abi: Option, + opt_sigil: Option, opt_region: Option<@ast::region>, purity: ast::purity, onceness: ast::Onceness, - bounds: @~[ast::ty_param_bound], decl: ast::fn_decl, id: Option, tps: Option<~[ast::ty_param]>, opt_self_ty: Option) { ibox(s, indent_unit); // Duplicates the logic in `print_fn_header_info()`. This is because that - // function prints the proto in the wrong place. That should be fixed. + // function prints the sigil in the wrong place. That should be fixed. print_self_ty_if_static(s, opt_self_ty); - print_opt_proto(s, opt_proto); + print_opt_abi(s, opt_abi); + print_opt_sigil(s, opt_sigil); for opt_region.each |r| { print_region(s, ~"", *r, ~"/"); } print_purity(s, purity); print_onceness(s, onceness); word(s.s, ~"fn"); - print_bounds(s, bounds); match id { Some(id) => { word(s.s, ~" "); print_ident(s, id); } _ => () } match tps { Some(tps) => print_type_params(s, tps), _ => () } zerobreak(s.s); popen(s); - // It is unfortunate to duplicate the commasep logic, but we - // we want the self type, the args, and the capture clauses all - // in the same box. + // 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| { @@ -2157,12 +2162,18 @@ pub fn print_opt_purity(s: ps, opt_purity: Option) { } } -pub fn print_opt_proto(s: ps, opt_proto: Option) { - match opt_proto { - Some(ast::ProtoBare) => { word(s.s, ~"extern "); } - Some(ast::ProtoBorrowed) => { word(s.s, ~"&"); } - Some(ast::ProtoUniq) => { word(s.s, ~"~"); } - Some(ast::ProtoBox) => { word(s.s, ~"@"); } +pub fn print_opt_abi(s: ps, opt_abi: Option) { + match opt_abi { + Some(ast::RustAbi) => { word_nbsp(s, ~"extern"); } + None => {} + }; +} + +pub fn print_opt_sigil(s: ps, opt_sigil: Option) { + match opt_sigil { + Some(ast::BorrowedSigil) => { word(s.s, ~"&"); } + Some(ast::OwnedSigil) => { word(s.s, ~"~"); } + Some(ast::ManagedSigil) => { word(s.s, ~"@"); } None => {} }; } @@ -2171,20 +2182,20 @@ pub fn print_fn_header_info(s: ps, opt_sty: Option, opt_purity: Option, onceness: ast::Onceness, - opt_proto: Option, + opt_sigil: Option, vis: ast::visibility) { print_self_ty_if_static(s, opt_sty); word(s.s, visibility_qualified(vis, ~"")); print_opt_purity(s, opt_purity); print_onceness(s, onceness); word(s.s, ~"fn"); - print_opt_proto(s, opt_proto); + print_opt_sigil(s, opt_sigil); } -pub fn opt_proto_to_str(opt_p: Option) -> ~str { +pub fn opt_sigil_to_str(opt_p: Option) -> ~str { match opt_p { None => ~"fn", - Some(p) => proto_to_str(p) + Some(p) => fmt!("fn%s", p.to_str()) } } @@ -2218,15 +2229,6 @@ pub fn print_onceness(s: ps, o: ast::Onceness) { } } -pub fn proto_to_str(p: ast::Proto) -> ~str { - return match p { - ast::ProtoBare => ~"extern fn", - ast::ProtoBorrowed => ~"fn&", - ast::ProtoUniq => ~"fn~", - ast::ProtoBox => ~"fn@" - }; -} - #[cfg(test)] pub mod test { use ast; diff --git a/src/libsyntax/syntax.rc b/src/libsyntax/syntax.rc index a6d50b9cf09..877817af06c 100644 --- a/src/libsyntax/syntax.rc +++ b/src/libsyntax/syntax.rc @@ -22,7 +22,6 @@ #[allow(vecs_implicitly_copyable)]; #[allow(non_camel_case_types)]; #[allow(deprecated_mode)]; -#[warn(deprecated_pattern)]; #[allow(deprecated_self)]; #[no_core]; diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index eea1a6906e4..37b96e05653 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -30,10 +30,10 @@ use core::vec; pub enum vt { mk_vt(visitor), } pub enum fn_kind { - fk_item_fn(ident, ~[ty_param], purity), //< an item declared with fn() - fk_method(ident, ~[ty_param], @method), - fk_anon(Proto), //< an anonymous function like fn@(...) - fk_fn_block, //< a block {||...} + fk_item_fn(ident, ~[ty_param], purity), // fn foo() + fk_method(ident, ~[ty_param], @method), // fn foo(&self) + fk_anon(ast::Sigil), // fn@(x, y) { ... } + fk_fn_block, // |x, y| ... fk_dtor(~[ty_param], ~[attribute], node_id /* self id */, def_id /* parent class id */) // class destructor @@ -217,9 +217,12 @@ pub fn visit_ty(t: @Ty, e: E, v: vt) { ty_tup(ts) => for ts.each |tt| { (v.visit_ty)(*tt, e, v); }, - ty_fn(f) => { + ty_closure(f) => { + for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); } + (v.visit_ty)(f.decl.output, e, v); + } + ty_bare_fn(f) => { for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, e, v); } - visit_ty_param_bounds(f.bounds, e, v); (v.visit_ty)(f.decl.output, e, v); } ty_path(p, _) => visit_path(p, e, v), diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 5ade0c9ed25..222307bd240 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -9,6 +9,7 @@ // except according to those terms. #[legacy_modes]; +#[allow(deprecated_mode)]; /*! @@ -247,8 +248,13 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { } } + fn is_gray_factory() -> ~fn(c: &color) -> bool { + let r: ~fn(c: &color) -> bool = is_gray; + r + } + let mut i = 0; - while par::any(colors, is_gray) { + while par::any(colors, is_gray_factory) { // Do the BFS. log(info, fmt!("PBFS iteration %?", i)); i += 1; @@ -257,14 +263,13 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { let color = arc::ARC(move colors); let color_vec = arc::get(&color); // FIXME #3387 requires this temp - colors = do par::mapi_factory(*color_vec) { + colors = do par::mapi(*color_vec) { let colors = arc::clone(&color); let graph = arc::clone(&graph); - fn~(move graph, move colors, +i: uint, +c: color) -> color { - let c : color = c; + fn~(+i: uint, +c: &color) -> color { let colors = arc::get(&colors); let graph = arc::get(&graph); - match c { + match *c { white => { let i = i as node_id; @@ -290,11 +295,13 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { } // Convert the results. - do par::map(colors) |c| { - match *c { - white => { -1i64 } - black(parent) => { parent } - _ => { die!(~"Found remaining gray nodes in BFS") } + do par::map(colors) { + fn~(c: &color) -> i64 { + match *c { + white => { -1i64 } + black(parent) => { parent } + _ => { die!(~"Found remaining gray nodes in BFS") } + } } } } @@ -377,14 +384,15 @@ fn validate(edges: ~[(node_id, node_id)], log(info, ~"Verifying tree and graph edges..."); - let edges = copy edges; - let status = do par::alli(tree) |u, v| { - let u = u as node_id; - if *v == -1i64 || u == root { - true - } - else { - edges.contains(&(u, *v)) || edges.contains(&(*v, u)) + let status = do par::alli(tree) { + let edges = copy edges; + fn~(+u: uint, v: &i64) -> bool { + let u = u as node_id; + if *v == -1i64 || u == root { + true + } else { + edges.contains(&(u, *v)) || edges.contains(&(*v, u)) + } } }; diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index 20dcb079597..8e5ab45bae8 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -15,6 +15,10 @@ extern mod std; use std::list::{List, Cons, Nil}; use std::time::precise_time_s; +enum UniqueList { + ULNil, ULCons(~UniqueList) +} + fn main() { let (repeat, depth) = if os::getenv(~"RUST_BENCH").is_some() { (50, 1000) @@ -43,7 +47,6 @@ struct State { box: @nillist, unique: ~nillist, fn_box: fn@() -> @nillist, - fn_unique: fn~() -> ~nillist, tuple: (@nillist, ~nillist), vec: ~[@nillist], res: r @@ -76,7 +79,6 @@ fn recurse_or_fail(depth: int, st: Option) { box: @Nil, unique: ~Nil, fn_box: fn@() -> @nillist { @Nil::<()> }, - fn_unique: fn~() -> ~nillist { ~Nil::<()> }, tuple: (@Nil, ~Nil), vec: ~[@Nil], res: r(@Nil) @@ -84,14 +86,11 @@ fn recurse_or_fail(depth: int, st: Option) { } Some(st) => { let fn_box = st.fn_box; - let fn_unique = copy st.fn_unique; State { box: @Cons((), st.box), unique: ~Cons((), @*st.unique), fn_box: fn@() -> @nillist { @Cons((), fn_box()) }, - fn_unique: fn~(move fn_unique) -> ~nillist - { ~Cons((), @*fn_unique()) }, tuple: (@Cons((), st.tuple.first()), ~Cons((), @*st.tuple.second())), vec: st.vec + ~[@Cons((), st.vec.last())], diff --git a/src/test/compile-fail/bad-var-env-capture-in-block-arg.rs b/src/test/compile-fail/bad-var-env-capture-in-block-arg.rs deleted file mode 100644 index b093af6e80c..00000000000 --- a/src/test/compile-fail/bad-var-env-capture-in-block-arg.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let x = 3; - fn blah(_a: extern fn()) {} - blah(|| { - log(debug, x); //~ ERROR attempted dynamic environment capture - }); -} \ No newline at end of file diff --git a/src/test/compile-fail/block-arg-used-as-lambda-with-illegal-cap.rs b/src/test/compile-fail/block-arg-used-as-lambda-with-illegal-cap.rs deleted file mode 100644 index 0671e804601..00000000000 --- a/src/test/compile-fail/block-arg-used-as-lambda-with-illegal-cap.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn to_lambda1(f: fn@(uint) -> uint) -> fn@(uint) -> uint { - return f; -} - -fn to_lambda2(b: fn(uint) -> uint) -> fn@(uint) -> uint { - return to_lambda1(|x| b(x)); //~ ERROR illegal move from argument `b` -} - -fn main() { -} diff --git a/src/test/compile-fail/functional-struct-update.rs b/src/test/compile-fail/functional-struct-update.rs deleted file mode 100644 index c0430a6a8bb..00000000000 --- a/src/test/compile-fail/functional-struct-update.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct Bar { - x: int, -} - -impl Bar : Drop { - fn finalize(&self) { - io::println("Goodbye, cruel world"); - } -} - -struct Foo { - x: int, - y: Bar -} - -fn main() { - let a = Foo { x: 1, y: Bar { x: 5 } }; - let c = Foo { x: 4, .. a}; //~ ERROR cannot copy field `y` of base expression, which has a noncopyable type - io::println(fmt!("%?", c)); -} - diff --git a/src/test/compile-fail/issue-3044.rs b/src/test/compile-fail/issue-3044.rs index 2a5785b23b7..46ad7f64589 100644 --- a/src/test/compile-fail/issue-3044.rs +++ b/src/test/compile-fail/issue-3044.rs @@ -8,12 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: Non-function passed to a `do` function as its last argument, or wrong number of arguments passed to a `do` function fn main() { let needlesArr: ~[char] = ~['a', 'f']; do vec::foldr(needlesArr) |x, y| { + //~^ ERROR 2 parameters were supplied (including the closure passed by the `do` keyword) + //~^^ ERROR Unconstrained region variable #2 + // + // this last error is, um, non-ideal. } -// for some reason if I use the new error syntax for the two error messages this generates, -// the test runner gets confused -- tjc } diff --git a/src/test/compile-fail/kindck-owned.rs b/src/test/compile-fail/kindck-owned.rs index 52031c900a2..bc6dd8f5dc9 100644 --- a/src/test/compile-fail/kindck-owned.rs +++ b/src/test/compile-fail/kindck-owned.rs @@ -24,6 +24,6 @@ fn main() { copy2(@&x); //~ ERROR missing `&static` copy2(fn@() {}); - copy2(fn~() {}); //~ WARNING instantiating copy type parameter with a not implicitly copyable type - copy2(fn&() {}); //~ ERROR missing `copy &static` + copy2(fn~() {}); //~ ERROR missing `copy` + copy2(fn&() {}); //~ ERROR missing `&static` } diff --git a/src/test/compile-fail/moves-sru-moved-field.rs b/src/test/compile-fail/moves-sru-moved-field.rs new file mode 100644 index 00000000000..660e5596ca5 --- /dev/null +++ b/src/test/compile-fail/moves-sru-moved-field.rs @@ -0,0 +1,27 @@ +type Noncopyable = ~fn(); + +struct Foo { + copied: int, + moved: ~int, + noncopyable: Noncopyable +} + +fn test0(f: Foo, g: Noncopyable, h: Noncopyable) { + // just copy implicitly copyable fields from `f`, no moves: + let _b = Foo {moved: ~1, noncopyable: g, ..f}; + let _c = Foo {moved: ~2, noncopyable: h, ..f}; +} + +fn test1(f: Foo, g: Noncopyable, h: Noncopyable) { + // copying move-by-default fields from `f`, so move: + let _b = Foo {noncopyable: g, ..f}; + let _c = Foo {noncopyable: h, ..f}; //~ ERROR use of moved value: `f` +} + +fn test2(f: Foo, g: Noncopyable) { + // move non-copyable field + let _b = Foo {copied: 22, moved: ~23, ..f}; + let _c = Foo {noncopyable: g, ..f}; //~ ERROR use of moved value: `f` +} + +fn main() {} diff --git a/src/test/run-pass/bounded-fn-type.rs b/src/test/run-pass/bounded-fn-type.rs deleted file mode 100644 index 5f4a88375a4..00000000000 --- a/src/test/run-pass/bounded-fn-type.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn ignore(_x: T) {} - -pub fn main() { - let f: fn@:Owned() = ||(); - ignore(f); -} - diff --git a/src/test/run-pass/morestack6.rs b/src/test/run-pass/morestack6.rs index 4a254f6a7eb..9b852cbc635 100644 --- a/src/test/run-pass/morestack6.rs +++ b/src/test/run-pass/morestack6.rs @@ -29,11 +29,11 @@ fn calllink08() { unsafe { rustrt::get_task_id(); } } fn calllink09() { unsafe { rustrt::rust_sched_threads(); } } fn calllink10() { unsafe { rustrt::rust_get_task(); } } -fn runtest(f: fn~(), frame_backoff: u32) { +fn runtest(f: extern fn(), frame_backoff: u32) { runtest2(f, frame_backoff, 0 as *u8); } -fn runtest2(f: fn~(), frame_backoff: u32, last_stk: *u8) -> u32 { +fn runtest2(f: extern fn(), frame_backoff: u32, last_stk: *u8) -> u32 { unsafe { let curr_stk = rustrt::debug_get_stk_seg(); if (last_stk != curr_stk && last_stk != 0 as *u8) { @@ -67,6 +67,6 @@ pub fn main() { let f = *f; let sz = rng.next() % 256u32 + 256u32; let frame_backoff = rng.next() % 10u32 + 1u32; - task::try(|move f| runtest(f, frame_backoff) ); + task::try(|| runtest(f, frame_backoff) ); } } diff --git a/src/test/run-pass/newtype.rs b/src/test/run-pass/newtype.rs index 697a579f4bc..18c446fe350 100644 --- a/src/test/run-pass/newtype.rs +++ b/src/test/run-pass/newtype.rs @@ -16,5 +16,6 @@ fn compute(i: mytype) -> int { return i.val + 20; } pub fn main() { let myval = mytype(Mytype{compute: compute, val: 30}); + io::println(fmt!("%d", compute(myval))); assert ((myval.compute)(myval) == 50); } diff --git a/src/test/run-pass/sendfn-deep-copy.rs b/src/test/run-pass/sendfn-deep-copy.rs deleted file mode 100644 index 520ddf3f73a..00000000000 --- a/src/test/run-pass/sendfn-deep-copy.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pub fn main() { test05(); } - -fn mk_counter() -> fn~(A) -> (A,uint) { - // The only reason that the counter is generic is so that it closes - // over both a type descriptor and some data. - let v = ~[mut 0u]; - return fn~(a: A) -> (A,uint) { - let n = v[0]; - v[0] = n + 1u; - (a, n) - }; -} - -fn test05() { - let fp0 = mk_counter::(); - - assert (5.3f, 0u) == fp0(5.3f); - assert (5.5f, 1u) == fp0(5.5f); - - let fp1 = copy fp0; - - assert (5.3f, 2u) == fp0(5.3f); - assert (5.3f, 2u) == fp1(5.3f); - assert (5.5f, 3u) == fp0(5.5f); - assert (5.5f, 3u) == fp1(5.5f); -} diff --git a/src/test/run-pass/test-ignore-cfg.rs b/src/test/run-pass/test-ignore-cfg.rs index 589b9794f64..1f4df7be1f3 100644 --- a/src/test/run-pass/test-ignore-cfg.rs +++ b/src/test/run-pass/test-ignore-cfg.rs @@ -28,11 +28,11 @@ fn checktests() { // Pull the tests out of the secreturn test module let tests = __test::tests(); - let shouldignore = option::get( - vec::find(tests, |t| t.name == ~"shouldignore" )); - assert shouldignore.ignore == true; + assert vec::any( + tests, + |t| t.desc.name == ~"shouldignore" && t.desc.ignore); - let shouldnotignore = option::get( - vec::find(tests, |t| t.name == ~"shouldnotignore" )); - assert shouldnotignore.ignore == false; + assert vec::any( + tests, + |t| t.desc.name == ~"shouldnotignore" && !t.desc.ignore); } \ No newline at end of file