Skip to content

librustc: Implement arbitrary lifetimes in trait objects. #16068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ pub trait BoxAny {
}

#[stable]
impl BoxAny for Box<Any> {
impl<'a> BoxAny for Box<Any+'a> {
#[inline]
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any+'a>> {
if self.is::<T>() {
unsafe {
// Get the raw representation of the trait object
let to: TraitObject =
*mem::transmute::<&Box<Any>, &TraitObject>(&self);
*mem::transmute::<&Box<Any+'a>, &TraitObject>(&self);

// Prevent destructor on self being run
intrinsics::forget(self);
Expand All @@ -130,7 +130,7 @@ impl<T: fmt::Show> fmt::Show for Box<T> {
}
}

impl fmt::Show for Box<Any> {
impl<'a> fmt::Show for Box<Any+'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Box<Any>")
}
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
html_root_url = "http://doc.rust-lang.org/")]

#![no_std]
#![feature(lang_items, phase, unsafe_destructor)]
#![feature(lang_items, phase, unsafe_destructor, issue_5723_bootstrap)]

#[phase(plugin, link)]
extern crate core;
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub trait AnyRefExt<'a> {
}

#[stable]
impl<'a> AnyRefExt<'a> for &'a Any {
impl<'a,'b> AnyRefExt<'a> for &'a Any+'b {
#[inline]
#[stable]
fn is<T: 'static>(self) -> bool {
Expand Down Expand Up @@ -181,7 +181,7 @@ pub trait AnyMutRefExt<'a> {
}

#[stable]
impl<'a> AnyMutRefExt<'a> for &'a mut Any {
impl<'a,'b> AnyMutRefExt<'a> for &'a mut Any+'b {
#[inline]
#[unstable = "naming conventions around acquiring references may change"]
fn downcast_mut<T: 'static>(self) -> Option<&'a mut T> {
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub trait FormatWriter {
/// A struct to represent both where to emit formatting strings to and how they
/// should be formatted. A mutable version of this is passed to all formatting
/// traits.
pub struct Formatter<'a> {
pub struct Formatter<'a,'b> {
/// Flags for formatting (packed version of rt::Flag)
pub flags: uint,
/// Character used as 'fill' whenever there is alignment
Expand All @@ -93,7 +93,7 @@ pub struct Formatter<'a> {
/// Optionally specified precision for numeric types
pub precision: Option<uint>,

buf: &'a mut FormatWriter,
buf: &'a mut FormatWriter+'b,
curarg: slice::Items<'a, Argument<'a>>,
args: &'a [Argument<'a>],
}
Expand Down Expand Up @@ -281,7 +281,7 @@ pub fn write(output: &mut FormatWriter, args: &Arguments) -> Result {
Ok(())
}

impl<'a> Formatter<'a> {
impl<'a,'b> Formatter<'a,'b> {

// First up is the collection of functions used to execute a format string
// at runtime. This consumes all of the compile-time statics generated by
Expand Down Expand Up @@ -520,7 +520,7 @@ impl<'a, T: Show> Show for &'a T {
impl<'a, T: Show> Show for &'a mut T {
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) }
}
impl<'a> Show for &'a Show {
impl<'a,'b> Show for &'a Show+'b {
fn fmt(&self, f: &mut Formatter) -> Result { (*self).fmt(f) }
}

Expand Down Expand Up @@ -686,7 +686,7 @@ macro_rules! tuple (

tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }

impl<'a> Show for &'a any::Any {
impl<'a,'b> Show for &'a any::Any+'b {
fn fmt(&self, f: &mut Formatter) -> Result { f.pad("&Any") }
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

#![no_std]
#![feature(globs, intrinsics, lang_items, macro_rules, managed_boxes, phase)]
#![feature(simd, unsafe_destructor)]
#![feature(simd, unsafe_destructor, issue_5723_bootstrap)]
#![deny(missing_doc)]

mod macros;
Expand Down
2 changes: 1 addition & 1 deletion src/libdebug/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/master/")]
#![experimental]
#![feature(managed_boxes, macro_rules)]
#![feature(managed_boxes, macro_rules, issue_5723_bootstrap)]
#![allow(experimental)]

pub mod fmt;
Expand Down
13 changes: 7 additions & 6 deletions src/libdebug/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ enum VariantState {
AlreadyFound
}

pub struct ReprVisitor<'a> {
pub struct ReprVisitor<'a,'b> {
ptr: *const u8,
ptr_stk: Vec<*const u8>,
var_stk: Vec<VariantState>,
writer: &'a mut io::Writer,
writer: &'a mut io::Writer+'b,
last_err: Option<io::IoError>,
}

impl<'a> MovePtr for ReprVisitor<'a> {
impl<'a,'b> MovePtr for ReprVisitor<'a,'b> {
#[inline]
fn move_ptr(&mut self, adjustment: |*const u8| -> *const u8) {
self.ptr = adjustment(self.ptr);
Expand All @@ -112,9 +112,10 @@ impl<'a> MovePtr for ReprVisitor<'a> {
}
}

impl<'a> ReprVisitor<'a> {
impl<'a,'b> ReprVisitor<'a,'b> {
// Various helpers for the TyVisitor impl
pub fn new(ptr: *const u8, writer: &'a mut io::Writer) -> ReprVisitor<'a> {
pub fn new(ptr: *const u8, writer: &'a mut io::Writer+'b)
-> ReprVisitor<'a,'b> {
ReprVisitor {
ptr: ptr,
ptr_stk: vec!(),
Expand Down Expand Up @@ -239,7 +240,7 @@ impl<'a> ReprVisitor<'a> {
}
}

impl<'a> TyVisitor for ReprVisitor<'a> {
impl<'a,'b> TyVisitor for ReprVisitor<'a,'b> {
fn visit_bot(&mut self) -> bool {
try!(self, self.writer.write("!".as_bytes()));
true
Expand Down
2 changes: 1 addition & 1 deletion src/libfourcc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
}

pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> Box<base::MacResult> {
-> Box<base::MacResult+'static> {
let (expr, endian) = parse_tts(cx, tts);

let little = match endian {
Expand Down
22 changes: 12 additions & 10 deletions src/libgreen/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ use std::rt::rtio::{PausableIdleCallback, Callback};
use std::rt::exclusive::Exclusive;

/// This is the only exported function from this module.
pub fn event_loop() -> Box<EventLoop + Send> {
box BasicLoop::new() as Box<EventLoop + Send>
pub fn event_loop() -> Box<EventLoop + Send + 'static> {
box BasicLoop::new() as Box<EventLoop + Send + 'static>
}

struct BasicLoop {
work: Vec<proc(): Send>, // pending work
remotes: Vec<(uint, Box<Callback + Send>)>,
remotes: Vec<(uint, Box<Callback + Send + 'static>)>,
next_remote: uint,
messages: Arc<Exclusive<Vec<Message>>>,
idle: Option<Box<Callback + Send>>,
idle: Option<Box<Callback + Send + 'static>>,
idle_active: Option<Arc<atomics::AtomicBool>>,
}

Expand Down Expand Up @@ -132,22 +132,24 @@ impl EventLoop for BasicLoop {
}

// FIXME: Seems like a really weird requirement to have an event loop provide.
fn pausable_idle_callback(&mut self, cb: Box<Callback + Send>)
-> Box<PausableIdleCallback + Send> {
fn pausable_idle_callback(&mut self, cb: Box<Callback + Send + 'static>)
-> Box<PausableIdleCallback + Send + 'static> {
rtassert!(self.idle.is_none());
self.idle = Some(cb);
let a = Arc::new(atomics::AtomicBool::new(true));
self.idle_active = Some(a.clone());
box BasicPausable { active: a } as Box<PausableIdleCallback + Send>
box BasicPausable {
active: a,
} as Box<PausableIdleCallback + Send + 'static>
}

fn remote_callback(&mut self, f: Box<Callback + Send>)
-> Box<RemoteCallback + Send> {
fn remote_callback(&mut self, f: Box<Callback + Send + 'static>)
-> Box<RemoteCallback + Send + 'static> {
let id = self.next_remote;
self.next_remote += 1;
self.remotes.push((id, f));
box BasicRemote::new(self.messages.clone(), id) as
Box<RemoteCallback + Send>
Box<RemoteCallback + Send + 'static>
}

fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory> { None }
Expand Down
8 changes: 4 additions & 4 deletions src/libgreen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ macro_rules! green_start( ($f:ident) => (
/// The return value is used as the process return code. 0 on success, 101 on
/// error.
pub fn start(argc: int, argv: *const *const u8,
event_loop_factory: fn() -> Box<rtio::EventLoop + Send>,
event_loop_factory: fn() -> Box<rtio::EventLoop+Send+'static>,
main: proc():Send) -> int {
rt::init(argc, argv);
let mut main = Some(main);
Expand All @@ -320,7 +320,7 @@ pub fn start(argc: int, argv: *const *const u8,
///
/// This function will not return until all schedulers in the associated pool
/// have returned.
pub fn run(event_loop_factory: fn() -> Box<rtio::EventLoop + Send>,
pub fn run(event_loop_factory: fn() -> Box<rtio::EventLoop + Send + 'static>,
main: proc():Send) -> int {
// Create a scheduler pool and spawn the main task into this pool. We will
// get notified over a channel when the main task exits.
Expand Down Expand Up @@ -351,7 +351,7 @@ pub struct PoolConfig {
pub threads: uint,
/// A factory function used to create new event loops. If this is not
/// specified then the default event loop factory is used.
pub event_loop_factory: fn() -> Box<rtio::EventLoop + Send>,
pub event_loop_factory: fn() -> Box<rtio::EventLoop + Send + 'static>,
}

impl PoolConfig {
Expand All @@ -376,7 +376,7 @@ pub struct SchedPool {
stack_pool: StackPool,
deque_pool: deque::BufferPool<Box<task::GreenTask>>,
sleepers: SleeperList,
factory: fn() -> Box<rtio::EventLoop + Send>,
factory: fn() -> Box<rtio::EventLoop + Send + 'static>,
task_state: TaskState,
tasks_done: Receiver<()>,
}
Expand Down
16 changes: 8 additions & 8 deletions src/libgreen/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub struct Scheduler {
/// A fast XorShift rng for scheduler use
rng: XorShiftRng,
/// A toggleable idle callback
idle_callback: Option<Box<PausableIdleCallback + Send>>,
idle_callback: Option<Box<PausableIdleCallback + Send + 'static>>,
/// A countdown that starts at a random value and is decremented
/// every time a yield check is performed. When it hits 0 a task
/// will yield.
Expand All @@ -100,7 +100,7 @@ pub struct Scheduler {
// destroyed before it's actually destroyed.

/// The event loop used to drive the scheduler and perform I/O
pub event_loop: Box<EventLoop + Send>,
pub event_loop: Box<EventLoop + Send + 'static>,
}

/// An indication of how hard to work on a given operation, the difference
Expand All @@ -123,7 +123,7 @@ impl Scheduler {
// * Initialization Functions

pub fn new(pool_id: uint,
event_loop: Box<EventLoop + Send>,
event_loop: Box<EventLoop + Send + 'static>,
work_queue: deque::Worker<Box<GreenTask>>,
work_queues: Vec<deque::Stealer<Box<GreenTask>>>,
sleeper_list: SleeperList,
Expand All @@ -136,7 +136,7 @@ impl Scheduler {
}

pub fn new_special(pool_id: uint,
event_loop: Box<EventLoop + Send>,
event_loop: Box<EventLoop + Send + 'static>,
work_queue: deque::Worker<Box<GreenTask>>,
work_queues: Vec<deque::Stealer<Box<GreenTask>>>,
sleeper_list: SleeperList,
Expand Down Expand Up @@ -181,9 +181,8 @@ impl Scheduler {
// Take a main task to run, and a scheduler to run it in. Create a
// scheduler task and bootstrap into it.
pub fn bootstrap(mut self: Box<Scheduler>) {

// Build an Idle callback.
let cb = box SchedRunner as Box<Callback + Send>;
let cb = box SchedRunner as Box<Callback + Send + 'static>;
self.idle_callback = Some(self.event_loop.pausable_idle_callback(cb));

// Create a task for the scheduler with an empty context.
Expand Down Expand Up @@ -232,7 +231,8 @@ impl Scheduler {
// mutable reference to the event_loop to give it the "run"
// command.
unsafe {
let event_loop: *mut Box<EventLoop + Send> = &mut self.event_loop;
let event_loop: *mut Box<EventLoop + Send + 'static> =
&mut self.event_loop;
// Our scheduler must be in the task before the event loop
// is started.
stask.put_with_sched(self);
Expand Down Expand Up @@ -908,7 +908,7 @@ pub enum SchedMessage {
}

pub struct SchedHandle {
remote: Box<RemoteCallback + Send>,
remote: Box<RemoteCallback + Send + 'static>,
queue: msgq::Producer<SchedMessage>,
pub sched_id: uint
}
Expand Down
2 changes: 1 addition & 1 deletion src/libgreen/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Runtime for SimpleTask {
fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>> { None }
fn stack_bounds(&self) -> (uint, uint) { fail!() }
fn can_block(&self) -> bool { true }
fn wrap(self: Box<SimpleTask>) -> Box<Any> { fail!() }
fn wrap(self: Box<SimpleTask>) -> Box<Any+'static> { fail!() }
}

pub fn task() -> Box<Task> {
Expand Down
10 changes: 8 additions & 2 deletions src/libgreen/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,11 @@ impl Runtime for GreenTask {
// Local I/O is provided by the scheduler's event loop
fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>> {
match self.sched.get_mut_ref().event_loop.io() {
Some(io) => Some(rtio::LocalIo::new(io)),
Some(io) => {
unsafe {
Some(rtio::LocalIo::new(mem::transmute(io)))
}
}
None => None,
}
}
Expand All @@ -473,7 +477,9 @@ impl Runtime for GreenTask {

fn can_block(&self) -> bool { false }

fn wrap(self: Box<GreenTask>) -> Box<Any> { self as Box<Any> }
fn wrap(self: Box<GreenTask>) -> Box<Any + 'static> {
self as Box<Any + 'static>
}
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/libhexfloat/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn hex_float_lit_err(s: &str) -> Option<(uint, String)> {
}

pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> Box<base::MacResult> {
-> Box<base::MacResult+'static> {
let (expr, ty_lit) = parse_tts(cx, tts);

let ty = match ty_lit {
Expand Down
9 changes: 6 additions & 3 deletions src/liblog/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub static WARN: u32 = 2;
/// Error log level
pub static ERROR: u32 = 1;

local_data_key!(local_logger: Box<Logger + Send>)
local_data_key!(local_logger: Box<Logger + Send + 'static>)

/// A trait used to represent an interface to a task-local logger. Each task
/// can have its own custom logger which can respond to logging messages
Expand Down Expand Up @@ -226,7 +226,9 @@ pub fn log(level: u32, loc: &'static LogLocation, args: &fmt::Arguments) {
// frob the slot while we're doing the logging. This will destroy any logger
// set during logging.
let mut logger = local_logger.replace(None).unwrap_or_else(|| {
box DefaultLogger { handle: io::stderr() } as Box<Logger + Send>
box DefaultLogger {
handle: io::stderr(),
} as Box<Logger + Send + 'static>
});
logger.log(&LogRecord {
level: LogLevel(level),
Expand All @@ -246,7 +248,8 @@ pub fn log_level() -> u32 { unsafe { LOG_LEVEL } }

/// Replaces the task-local logger with the specified logger, returning the old
/// logger.
pub fn set_logger(logger: Box<Logger + Send>) -> Option<Box<Logger + Send>> {
pub fn set_logger(logger: Box<Logger + Send + 'static>)
-> Option<Box<Logger + Send + 'static>> {
local_logger.replace(Some(logger))
}

Expand Down
Loading