Skip to content

Commit 517298d

Browse files
committed
Implemented IntoSendStr on SendStr to allow naming a
task with a `SendStr` directly
1 parent 49ac6ba commit 517298d

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/libstd/send_str.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ impl IntoSendStr for &'static str {
6464
fn into_send_str(self) -> SendStr { SendStrStatic(self) }
6565
}
6666

67+
impl IntoSendStr for SendStr {
68+
#[inline]
69+
fn into_send_str(self) -> SendStr { self }
70+
}
71+
6772
/*
6873
Section: String trait impls.
6974
`SendStr` should behave like a normal string, so we don't derive.

src/libstd/task/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,21 @@ fn test_static_named_task() {
974974
}
975975
}
976976

977+
#[test]
978+
fn test_send_named_task() {
979+
use rt::test::run_in_newsched_task;
980+
981+
do run_in_newsched_task {
982+
let mut t = task();
983+
t.name("ada lovelace".into_send_str());
984+
do t.spawn {
985+
do with_task_name |name| {
986+
assert!(name.unwrap() == "ada lovelace");
987+
}
988+
}
989+
}
990+
}
991+
977992
#[test]
978993
fn test_run_basic() {
979994
let (po, ch) = stream::<()>();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern:task 'send name' failed at 'test'
12+
13+
fn main() {
14+
let mut t = ::std::task::task();
15+
t.name("send name".to_send_str());
16+
do t.spawn {
17+
fail2!("test");
18+
}
19+
}

0 commit comments

Comments
 (0)