Skip to content

Commit bb165eb

Browse files
pcwaltonalexcrichton
authored andcommitted
libsyntax: Remove ~self and mut ~self from the language.
This eliminates the last vestige of the `~` syntax. Instead of `~self`, write `self: Box<TypeOfSelf>`; instead of `mut ~self`, write `mut self: Box<TypeOfSelf>`, replacing `TypeOfSelf` with the self-type parameter as specified in the implementation. Closes #13885. [breaking-change]
1 parent 57cade5 commit bb165eb

File tree

24 files changed

+104
-83
lines changed

24 files changed

+104
-83
lines changed

src/doc/rust.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3864,13 +3864,13 @@ Function parameters are immutable unless declared with `mut`. The
38643864
and `fn f(mut x: Box<int>, y: Box<int>)` declare one mutable variable `x` and
38653865
one immutable variable `y`).
38663866

3867-
Methods that take either `self` or `~self` can optionally place them in a
3867+
Methods that take either `self` or `Box<Self>` can optionally place them in a
38683868
mutable slot by prefixing them with `mut` (similar to regular arguments):
38693869

38703870
~~~
38713871
trait Changer {
38723872
fn change(mut self) -> Self;
3873-
fn modify(mut ~self) -> Box<Self>;
3873+
fn modify(mut self: Box<Self>) -> Box<Self>;
38743874
}
38753875
~~~
38763876

src/doc/tutorial.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,7 @@ like any other function, except for the name `self`.
19711971

19721972
The type of `self` is the type on which the method is implemented,
19731973
or a pointer thereof. As an argument it is written either `self`,
1974-
`&self`, or `~self`.
1974+
`&self`, or `self: TYPE`.
19751975
A caller must in turn have a compatible pointer type to call the method.
19761976

19771977
~~~
@@ -1984,7 +1984,7 @@ A caller must in turn have a compatible pointer type to call the method.
19841984
# }
19851985
impl Shape {
19861986
fn draw_reference(&self) { /* ... */ }
1987-
fn draw_owned(~self) { /* ... */ }
1987+
fn draw_owned(self: Box<Shape>) { /* ... */ }
19881988
fn draw_value(self) { /* ... */ }
19891989
}
19901990
@@ -2009,7 +2009,7 @@ to a reference.
20092009
# }
20102010
# impl Shape {
20112011
# fn draw_reference(&self) { /* ... */ }
2012-
# fn draw_owned(~self) { /* ... */ }
2012+
# fn draw_owned(self: Box<Shape>) { /* ... */ }
20132013
# fn draw_value(self) { /* ... */ }
20142014
# }
20152015
# let s = Circle(Point { x: 1.0, y: 2.0 }, 3.0);

src/libgreen/sched.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl Scheduler {
180180

181181
// Take a main task to run, and a scheduler to run it in. Create a
182182
// scheduler task and bootstrap into it.
183-
pub fn bootstrap(mut ~self) {
183+
pub fn bootstrap(mut self: Box<Scheduler>) {
184184

185185
// Build an Idle callback.
186186
let cb = box SchedRunner as Box<Callback + Send>;
@@ -224,7 +224,8 @@ impl Scheduler {
224224

225225
// This does not return a scheduler, as the scheduler is placed
226226
// inside the task.
227-
pub fn run(mut ~self, stask: Box<GreenTask>) -> Box<GreenTask> {
227+
pub fn run(mut self: Box<Scheduler>, stask: Box<GreenTask>)
228+
-> Box<GreenTask> {
228229

229230
// This is unsafe because we need to place the scheduler, with
230231
// the event_loop inside, inside our task. But we still need a
@@ -271,7 +272,7 @@ impl Scheduler {
271272
// If we try really hard to do some work, but no work is available to be
272273
// done, then we fall back to epoll() to block this thread waiting for more
273274
// work (instead of busy waiting).
274-
fn run_sched_once(mut ~self, stask: Box<GreenTask>) {
275+
fn run_sched_once(mut self: Box<Scheduler>, stask: Box<GreenTask>) {
275276
// Make sure that we're not lying in that the `stask` argument is indeed
276277
// the scheduler task for this scheduler.
277278
assert!(self.sched_task.is_none());
@@ -349,11 +350,10 @@ impl Scheduler {
349350
// returns the still-available scheduler. At this point all
350351
// message-handling will count as a turn of work, and as a result
351352
// return None.
352-
fn interpret_message_queue(mut ~self, stask: Box<GreenTask>,
353+
fn interpret_message_queue(mut self: Box<Scheduler>,
354+
stask: Box<GreenTask>,
353355
effort: EffortLevel)
354-
-> (Box<Scheduler>, Box<GreenTask>, bool)
355-
{
356-
356+
-> (Box<Scheduler>, Box<GreenTask>, bool) {
357357
let msg = if effort == DontTryTooHard {
358358
self.message_queue.casual_pop()
359359
} else {
@@ -432,7 +432,7 @@ impl Scheduler {
432432
}
433433
}
434434

435-
fn do_work(mut ~self, stask: Box<GreenTask>)
435+
fn do_work(mut self: Box<Scheduler>, stask: Box<GreenTask>)
436436
-> (Box<Scheduler>, Box<GreenTask>, bool) {
437437
rtdebug!("scheduler calling do work");
438438
match self.find_work() {
@@ -517,7 +517,7 @@ impl Scheduler {
517517
// * Task Routing Functions - Make sure tasks send up in the right
518518
// place.
519519

520-
fn process_task(mut ~self,
520+
fn process_task(mut self: Box<Scheduler>,
521521
cur: Box<GreenTask>,
522522
mut next: Box<GreenTask>,
523523
schedule_fn: SchedulingFn)
@@ -610,7 +610,7 @@ impl Scheduler {
610610
// cleanup function f, which takes the scheduler and the
611611
// old task as inputs.
612612

613-
pub fn change_task_context(mut ~self,
613+
pub fn change_task_context(mut self: Box<Scheduler>,
614614
mut current_task: Box<GreenTask>,
615615
mut next_task: Box<GreenTask>,
616616
f: |&mut Scheduler, Box<GreenTask>|)
@@ -693,7 +693,7 @@ impl Scheduler {
693693

694694
// * Context Swapping Helpers - Here be ugliness!
695695

696-
pub fn resume_task_immediately(~self,
696+
pub fn resume_task_immediately(self: Box<Scheduler>,
697697
cur: Box<GreenTask>,
698698
next: Box<GreenTask>)
699699
-> (Box<Scheduler>, Box<GreenTask>) {
@@ -733,7 +733,7 @@ impl Scheduler {
733733
/// This situation is currently prevented, or in other words it is
734734
/// guaranteed that this function will not return before the given closure
735735
/// has returned.
736-
pub fn deschedule_running_task_and_then(mut ~self,
736+
pub fn deschedule_running_task_and_then(mut self: Box<Scheduler>,
737737
cur: Box<GreenTask>,
738738
f: |&mut Scheduler, BlockedTask|) {
739739
// Trickier - we need to get the scheduler task out of self
@@ -743,7 +743,7 @@ impl Scheduler {
743743
self.switch_running_tasks_and_then(cur, stask, f)
744744
}
745745

746-
pub fn switch_running_tasks_and_then(~self,
746+
pub fn switch_running_tasks_and_then(self: Box<Scheduler>,
747747
cur: Box<GreenTask>,
748748
next: Box<GreenTask>,
749749
f: |&mut Scheduler, BlockedTask|) {
@@ -795,7 +795,9 @@ impl Scheduler {
795795

796796
/// Called by a running task to end execution, after which it will
797797
/// be recycled by the scheduler for reuse in a new task.
798-
pub fn terminate_current_task(mut ~self, cur: Box<GreenTask>) -> ! {
798+
pub fn terminate_current_task(mut self: Box<Scheduler>,
799+
cur: Box<GreenTask>)
800+
-> ! {
799801
// Similar to deschedule running task and then, but cannot go through
800802
// the task-blocking path. The task is already dying.
801803
let stask = self.sched_task.take_unwrap();
@@ -807,7 +809,9 @@ impl Scheduler {
807809
fail!("should never return!");
808810
}
809811

810-
pub fn run_task(~self, cur: Box<GreenTask>, next: Box<GreenTask>) {
812+
pub fn run_task(self: Box<Scheduler>,
813+
cur: Box<GreenTask>,
814+
next: Box<GreenTask>) {
811815
let (sched, task) =
812816
self.process_task(cur, next, Scheduler::switch_task);
813817
task.put_with_sched(sched);
@@ -823,7 +827,7 @@ impl Scheduler {
823827
/// to introduce some amount of randomness to the scheduler. Currently the
824828
/// randomness is a result of performing a round of work stealing (which
825829
/// may end up stealing from the current scheduler).
826-
pub fn yield_now(mut ~self, cur: Box<GreenTask>) {
830+
pub fn yield_now(mut self: Box<Scheduler>, cur: Box<GreenTask>) {
827831
// Async handles trigger the scheduler by calling yield_now on the local
828832
// task, which eventually gets us to here. See comments in SchedRunner
829833
// for more info on this.
@@ -842,7 +846,7 @@ impl Scheduler {
842846
}
843847
}
844848

845-
pub fn maybe_yield(mut ~self, cur: Box<GreenTask>) {
849+
pub fn maybe_yield(mut self: Box<Scheduler>, cur: Box<GreenTask>) {
846850
// It's possible for sched tasks to possibly call this function, and it
847851
// just means that they're likely sending on channels (which
848852
// occasionally call this function). Sched tasks follow different paths

src/libgreen/simple.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ struct SimpleTask {
2727
impl Runtime for SimpleTask {
2828
// Implement the simple tasks of descheduling and rescheduling, but only in
2929
// a simple number of cases.
30-
fn deschedule(mut ~self, times: uint, mut cur_task: Box<Task>,
30+
fn deschedule(mut self: Box<SimpleTask>,
31+
times: uint,
32+
mut cur_task: Box<Task>,
3133
f: |BlockedTask| -> Result<(), BlockedTask>) {
3234
assert!(times == 1);
3335

@@ -54,7 +56,7 @@ impl Runtime for SimpleTask {
5456
}
5557
Local::put(cur_task);
5658
}
57-
fn reawaken(mut ~self, mut to_wake: Box<Task>) {
59+
fn reawaken(mut self: Box<SimpleTask>, mut to_wake: Box<Task>) {
5860
let me = &mut *self as *mut SimpleTask;
5961
to_wake.put_runtime(self);
6062
unsafe {
@@ -69,9 +71,9 @@ impl Runtime for SimpleTask {
6971
// purpose. A "simple task" is just that, a very simple task that can't
7072
// really do a whole lot. The only purpose of the task is to get us off our
7173
// feet and running.
72-
fn yield_now(~self, _cur_task: Box<Task>) { fail!() }
73-
fn maybe_yield(~self, _cur_task: Box<Task>) { fail!() }
74-
fn spawn_sibling(~self,
74+
fn yield_now(self: Box<SimpleTask>, _cur_task: Box<Task>) { fail!() }
75+
fn maybe_yield(self: Box<SimpleTask>, _cur_task: Box<Task>) { fail!() }
76+
fn spawn_sibling(self: Box<SimpleTask>,
7577
_cur_task: Box<Task>,
7678
_opts: TaskOpts,
7779
_f: proc():Send) {
@@ -80,7 +82,7 @@ impl Runtime for SimpleTask {
8082
fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>> { None }
8183
fn stack_bounds(&self) -> (uint, uint) { fail!() }
8284
fn can_block(&self) -> bool { true }
83-
fn wrap(~self) -> Box<Any> { fail!() }
85+
fn wrap(self: Box<SimpleTask>) -> Box<Any> { fail!() }
8486
}
8587

8688
pub fn task() -> Box<Task> {

src/libgreen/task.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl GreenTask {
265265

266266
// Runtime glue functions and helpers
267267

268-
pub fn put_with_sched(mut ~self, sched: Box<Scheduler>) {
268+
pub fn put_with_sched(mut self: Box<GreenTask>, sched: Box<Scheduler>) {
269269
assert!(self.sched.is_none());
270270
self.sched = Some(sched);
271271
self.put();
@@ -276,18 +276,18 @@ impl GreenTask {
276276
self.task = Some(task);
277277
}
278278

279-
pub fn swap(mut ~self) -> Box<Task> {
279+
pub fn swap(mut self: Box<GreenTask>) -> Box<Task> {
280280
let mut task = self.task.take_unwrap();
281281
task.put_runtime(self);
282282
return task;
283283
}
284284

285-
pub fn put(~self) {
285+
pub fn put(self: Box<GreenTask>) {
286286
assert!(self.sched.is_some());
287287
Local::put(self.swap());
288288
}
289289

290-
fn terminate(mut ~self) -> ! {
290+
fn terminate(mut self: Box<GreenTask>) -> ! {
291291
let sched = self.sched.take_unwrap();
292292
sched.terminate_current_task(self)
293293
}
@@ -311,7 +311,7 @@ impl GreenTask {
311311
// *not* a cheap operation to clone a handle. Until the day comes that we
312312
// need to optimize this, a lock should do just fine (it's completely
313313
// uncontended except for when the task is rescheduled).
314-
fn reawaken_remotely(mut ~self) {
314+
fn reawaken_remotely(mut self: Box<GreenTask>) {
315315
unsafe {
316316
let mtx = &mut self.nasty_deschedule_lock as *mut NativeMutex;
317317
let handle = self.handle.get_mut_ref() as *mut SchedHandle;
@@ -322,19 +322,21 @@ impl GreenTask {
322322
}
323323

324324
impl Runtime for GreenTask {
325-
fn yield_now(mut ~self, cur_task: Box<Task>) {
325+
fn yield_now(mut self: Box<GreenTask>, cur_task: Box<Task>) {
326326
self.put_task(cur_task);
327327
let sched = self.sched.take_unwrap();
328328
sched.yield_now(self);
329329
}
330330

331-
fn maybe_yield(mut ~self, cur_task: Box<Task>) {
331+
fn maybe_yield(mut self: Box<GreenTask>, cur_task: Box<Task>) {
332332
self.put_task(cur_task);
333333
let sched = self.sched.take_unwrap();
334334
sched.maybe_yield(self);
335335
}
336336

337-
fn deschedule(mut ~self, times: uint, cur_task: Box<Task>,
337+
fn deschedule(mut self: Box<GreenTask>,
338+
times: uint,
339+
cur_task: Box<Task>,
338340
f: |BlockedTask| -> Result<(), BlockedTask>) {
339341
self.put_task(cur_task);
340342
let mut sched = self.sched.take_unwrap();
@@ -383,7 +385,7 @@ impl Runtime for GreenTask {
383385
}
384386
}
385387

386-
fn reawaken(mut ~self, to_wake: Box<Task>) {
388+
fn reawaken(mut self: Box<GreenTask>, to_wake: Box<Task>) {
387389
self.put_task(to_wake);
388390
assert!(self.sched.is_none());
389391

@@ -434,7 +436,7 @@ impl Runtime for GreenTask {
434436
}
435437
}
436438

437-
fn spawn_sibling(mut ~self,
439+
fn spawn_sibling(mut self: Box<GreenTask>,
438440
cur_task: Box<Task>,
439441
opts: TaskOpts,
440442
f: proc():Send) {
@@ -471,7 +473,7 @@ impl Runtime for GreenTask {
471473

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

474-
fn wrap(~self) -> Box<Any> { self as Box<Any> }
476+
fn wrap(self: Box<GreenTask>) -> Box<Any> { self as Box<Any> }
475477
}
476478

477479
#[cfg(test)]

src/libnative/io/net.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ impl TcpListener {
484484
}
485485

486486
impl rtio::RtioTcpListener for TcpListener {
487-
fn listen(~self) -> IoResult<Box<rtio::RtioTcpAcceptor + Send>> {
487+
fn listen(self: Box<TcpListener>)
488+
-> IoResult<Box<rtio::RtioTcpAcceptor + Send>> {
488489
self.native_listen(128).map(|a| {
489490
box a as Box<rtio::RtioTcpAcceptor + Send>
490491
})

src/libnative/io/pipe_unix.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ impl UnixListener {
229229
}
230230

231231
impl rtio::RtioUnixListener for UnixListener {
232-
fn listen(~self) -> IoResult<Box<rtio::RtioUnixAcceptor + Send>> {
232+
fn listen(self: Box<UnixListener>)
233+
-> IoResult<Box<rtio::RtioUnixAcceptor + Send>> {
233234
self.native_listen(128).map(|a| {
234235
box a as Box<rtio::RtioUnixAcceptor + Send>
235236
})

src/libnative/io/pipe_win32.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,8 @@ impl Drop for UnixListener {
588588
}
589589

590590
impl rtio::RtioUnixListener for UnixListener {
591-
fn listen(~self) -> IoResult<Box<rtio::RtioUnixAcceptor + Send>> {
591+
fn listen(self: Box<UnixListener>)
592+
-> IoResult<Box<rtio::RtioUnixAcceptor + Send>> {
592593
self.native_listen().map(|a| {
593594
box a as Box<rtio::RtioUnixAcceptor + Send>
594595
})

src/libnative/task.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,21 @@ struct Ops {
131131
}
132132

133133
impl rt::Runtime for Ops {
134-
fn yield_now(~self, mut cur_task: Box<Task>) {
134+
fn yield_now(self: Box<Ops>, mut cur_task: Box<Task>) {
135135
// put the task back in TLS and then invoke the OS thread yield
136136
cur_task.put_runtime(self);
137137
Local::put(cur_task);
138138
Thread::yield_now();
139139
}
140140

141-
fn maybe_yield(~self, mut cur_task: Box<Task>) {
141+
fn maybe_yield(self: Box<Ops>, mut cur_task: Box<Task>) {
142142
// just put the task back in TLS, on OS threads we never need to
143143
// opportunistically yield b/c the OS will do that for us (preemption)
144144
cur_task.put_runtime(self);
145145
Local::put(cur_task);
146146
}
147147

148-
fn wrap(~self) -> Box<Any> {
148+
fn wrap(self: Box<Ops>) -> Box<Any> {
149149
self as Box<Any>
150150
}
151151

@@ -192,7 +192,9 @@ impl rt::Runtime for Ops {
192192
// `awoken` field which indicates whether we were actually woken up via some
193193
// invocation of `reawaken`. This flag is only ever accessed inside the
194194
// lock, so there's no need to make it atomic.
195-
fn deschedule(mut ~self, times: uint, mut cur_task: Box<Task>,
195+
fn deschedule(mut self: Box<Ops>,
196+
times: uint,
197+
mut cur_task: Box<Task>,
196198
f: |BlockedTask| -> Result<(), BlockedTask>) {
197199
let me = &mut *self as *mut Ops;
198200
cur_task.put_runtime(self);
@@ -250,7 +252,7 @@ impl rt::Runtime for Ops {
250252

251253
// See the comments on `deschedule` for why the task is forgotten here, and
252254
// why it's valid to do so.
253-
fn reawaken(mut ~self, mut to_wake: Box<Task>) {
255+
fn reawaken(mut self: Box<Ops>, mut to_wake: Box<Task>) {
254256
unsafe {
255257
let me = &mut *self as *mut Ops;
256258
to_wake.put_runtime(self);
@@ -261,7 +263,7 @@ impl rt::Runtime for Ops {
261263
}
262264
}
263265

264-
fn spawn_sibling(~self,
266+
fn spawn_sibling(self: Box<Ops>,
265267
mut cur_task: Box<Task>,
266268
opts: TaskOpts,
267269
f: proc():Send) {

0 commit comments

Comments
 (0)