Skip to content

Commit 2ea9c8d

Browse files
committed
Accept prefix notation for writing the types of str/~ and friends.
1 parent acb8692 commit 2ea9c8d

37 files changed

+198
-147
lines changed

doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ imply ownership. Pointers may be borrowed from any type, in which case
13471347
the pointer is guaranteed not to outlive the value it points to.
13481348
13491349
~~~~
1350-
# fn work_with_foo_by_pointer(f: &str) { }
1350+
# fn work_with_foo_by_pointer(f: &str/~) { }
13511351
let foo = "foo";
13521352
work_with_foo_by_pointer(&foo);
13531353
~~~~

src/fuzzer/fuzzer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ fn check_compiling(filename: str) -> happiness {
418418
}
419419

420420

421-
fn parse_and_print(code: @str) -> str {
421+
fn parse_and_print(code: @str/~) -> str {
422422
let filename = "tmp.rs";
423423
let sess = parse::new_parse_sess(option::none);
424424
write_file(filename, *code);
@@ -501,7 +501,7 @@ fn file_might_not_converge(filename: str) -> bool {
501501
ret false;
502502
}
503503

504-
fn check_roundtrip_convergence(code: @str, maxIters: uint) {
504+
fn check_roundtrip_convergence(code: @str/~, maxIters: uint) {
505505

506506
let mut i = 0u;
507507
let mut newv = code;

src/libcore/task.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ fn test_unkillable_nested() {
13001300

13011301
#[test]
13021302
fn test_tls_multitask() unsafe {
1303-
fn my_key(+_x: @str) { }
1303+
fn my_key(+_x: @str/~) { }
13041304
local_data_set(my_key, @"parent data");
13051305
do task::spawn {
13061306
assert local_data_get(my_key) == none; // TLS shouldn't carry over.
@@ -1316,15 +1316,15 @@ fn test_tls_multitask() unsafe {
13161316

13171317
#[test]
13181318
fn test_tls_overwrite() unsafe {
1319-
fn my_key(+_x: @str) { }
1319+
fn my_key(+_x: @str/~) { }
13201320
local_data_set(my_key, @"first data");
13211321
local_data_set(my_key, @"next data"); // Shouldn't leak.
13221322
assert *(local_data_get(my_key).get()) == "next data";
13231323
}
13241324

13251325
#[test]
13261326
fn test_tls_pop() unsafe {
1327-
fn my_key(+_x: @str) { }
1327+
fn my_key(+_x: @str/~) { }
13281328
local_data_set(my_key, @"weasel");
13291329
assert *(local_data_pop(my_key).get()) == "weasel";
13301330
// Pop must remove the data from the map.
@@ -1333,7 +1333,7 @@ fn test_tls_pop() unsafe {
13331333

13341334
#[test]
13351335
fn test_tls_modify() unsafe {
1336-
fn my_key(+_x: @str) { }
1336+
fn my_key(+_x: @str/~) { }
13371337
local_data_modify(my_key, |data| {
13381338
alt data {
13391339
some(@val) { fail "unwelcome value: " + val }
@@ -1357,15 +1357,15 @@ fn test_tls_crust_automorestack_memorial_bug() unsafe {
13571357
// jump over to the rust stack, which causes next_c_sp to get recorded as
13581358
// something within a rust stack segment. Then a subsequent upcall (esp.
13591359
// for logging, think vsnprintf) would run on a stack smaller than 1 MB.
1360-
fn my_key(+_x: @str) { }
1360+
fn my_key(+_x: @str/~) { }
13611361
do task::spawn {
13621362
unsafe { local_data_set(my_key, @"hax"); }
13631363
}
13641364
}
13651365

13661366
#[test]
13671367
fn test_tls_multiple_types() unsafe {
1368-
fn str_key(+_x: @str) { }
1368+
fn str_key(+_x: @str/~) { }
13691369
fn box_key(+_x: @@()) { }
13701370
fn int_key(+_x: @int) { }
13711371
do task::spawn {
@@ -1377,7 +1377,7 @@ fn test_tls_multiple_types() unsafe {
13771377

13781378
#[test]
13791379
fn test_tls_overwrite_multiple_types() unsafe {
1380-
fn str_key(+_x: @str) { }
1380+
fn str_key(+_x: @str/~) { }
13811381
fn box_key(+_x: @@()) { }
13821382
fn int_key(+_x: @int) { }
13831383
do task::spawn {
@@ -1393,7 +1393,7 @@ fn test_tls_overwrite_multiple_types() unsafe {
13931393
#[should_fail]
13941394
#[ignore(cfg(windows))]
13951395
fn test_tls_cleanup_on_failure() unsafe {
1396-
fn str_key(+_x: @str) { }
1396+
fn str_key(+_x: @str/~) { }
13971397
fn box_key(+_x: @@()) { }
13981398
fn int_key(+_x: @int) { }
13991399
local_data_set(str_key, @"parent data");

src/libcore/to_bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ impl of to_bytes for str {
1414
fn to_bytes() -> ~[u8] { str::bytes(self) }
1515
}
1616

17-
impl of to_bytes for @str {
17+
impl of to_bytes for @(str/~) {
1818
fn to_bytes() -> ~[u8] { str::bytes(*self) }
1919
}

src/libcore/unsafe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ mod tests {
6161
let box = @"box box box"; // refcount 1
6262
bump_box_refcount(box); // refcount 2
6363
let ptr: *int = transmute(box); // refcount 2
64-
let _box1: @str = reinterpret_cast(ptr);
65-
let _box2: @str = reinterpret_cast(ptr);
64+
let _box1: @str/~ = reinterpret_cast(ptr);
65+
let _box2: @str/~ = reinterpret_cast(ptr);
6666
assert *_box1 == "box box box";
6767
assert *_box2 == "box box box";
6868
// Will destroy _box1 and _box2. Without the bump, this would

src/libstd/json.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export null;
2929
/// Represents a json value
3030
enum json {
3131
num(float),
32-
string(@str),
32+
string(@str/~),
3333
boolean(bool),
3434
list(@~[json]),
3535
dict(map::hashmap<str, json>),
@@ -39,7 +39,7 @@ enum json {
3939
type error = {
4040
line: uint,
4141
col: uint,
42-
msg: @str,
42+
msg: @str/~,
4343
};
4444

4545
/// Serializes a json value into a io::writer
@@ -324,7 +324,7 @@ impl parser for parser {
324324
ok(res)
325325
}
326326

327-
fn parse_str() -> result<@str, error> {
327+
fn parse_str() -> result<@str/~, error> {
328328
let mut escape = false;
329329
let mut res = "";
330330

@@ -579,7 +579,7 @@ impl of to_json for str {
579579
fn to_json() -> json { string(@copy self) }
580580
}
581581

582-
impl of to_json for @str {
582+
impl of to_json for @str/~ {
583583
fn to_json() -> json { string(self) }
584584
}
585585

src/libstd/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ fn str_hash<V: copy>() -> hashmap<str, V> {
310310
}
311311

312312
/// Construct a hashmap for boxed string keys
313-
fn box_str_hash<V: copy>() -> hashmap<@str, V> {
314-
ret hashmap(|x: @str| str::hash(*x), |x,y| str::eq(*x,*y));
313+
fn box_str_hash<V: copy>() -> hashmap<@str/~, V> {
314+
ret hashmap(|x: @str/~| str::hash(*x), |x,y| str::eq(*x,*y));
315315
}
316316

317317
/// Construct a hashmap for byte string keys

src/libstd/rope.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn empty() -> rope {
5353
* * this operation does not copy the string;
5454
* * the function runs in linear time.
5555
*/
56-
fn of_str(str: @str) -> rope {
56+
fn of_str(str: @str/~) -> rope {
5757
ret of_substr(str, 0u, str::len(*str));
5858
}
5959

@@ -79,7 +79,7 @@ fn of_str(str: @str) -> rope {
7979
* * this function does _not_ check the validity of the substring;
8080
* * this function fails if `byte_offset` or `byte_len` do not match `str`.
8181
*/
82-
fn of_substr(str: @str, byte_offset: uint, byte_len: uint) -> rope {
82+
fn of_substr(str: @str/~, byte_offset: uint, byte_len: uint) -> rope {
8383
if byte_len == 0u { ret node::empty; }
8484
if byte_offset + byte_len > str::len(*str) { fail; }
8585
ret node::content(node::of_substr(str, byte_offset, byte_len));
@@ -107,7 +107,7 @@ fn append_char(rope: rope, char: char) -> rope {
107107
*
108108
* * this function executes in near-linear time
109109
*/
110-
fn append_str(rope: rope, str: @str) -> rope {
110+
fn append_str(rope: rope, str: @str/~) -> rope {
111111
ret append_rope(rope, of_str(str))
112112
}
113113

@@ -127,7 +127,7 @@ fn prepend_char(rope: rope, char: char) -> rope {
127127
* # Performance note
128128
* * this function executes in near-linear time
129129
*/
130-
fn prepend_str(rope: rope, str: @str) -> rope {
130+
fn prepend_str(rope: rope, str: @str/~) -> rope {
131131
ret append_rope(of_str(str), rope)
132132
}
133133

@@ -567,7 +567,7 @@ mod node {
567567
byte_offset: uint,
568568
byte_len: uint,
569569
char_len: uint,
570-
content: @str
570+
content: @str/~
571571
};
572572

573573
/**
@@ -627,7 +627,7 @@ mod node {
627627
* Performance note: The complexity of this function is linear in
628628
* the length of `str`.
629629
*/
630-
fn of_str(str: @str) -> @node {
630+
fn of_str(str: @str/~) -> @node {
631631
ret of_substr(str, 0u, str::len(*str));
632632
}
633633

@@ -648,7 +648,7 @@ mod node {
648648
* Behavior is undefined if `byte_start` or `byte_len` do not represent
649649
* valid positions in `str`
650650
*/
651-
fn of_substr(str: @str, byte_start: uint, byte_len: uint) -> @node {
651+
fn of_substr(str: @str/~, byte_start: uint, byte_len: uint) -> @node {
652652
ret of_substr_unsafer(str, byte_start, byte_len,
653653
str::count_chars(*str, byte_start, byte_len));
654654
}
@@ -674,7 +674,7 @@ mod node {
674674
* * Behavior is undefined if `char_len` does not accurately represent the
675675
* number of chars between byte_start and byte_start+byte_len
676676
*/
677-
fn of_substr_unsafer(str: @str, byte_start: uint, byte_len: uint,
677+
fn of_substr_unsafer(str: @str/~, byte_start: uint, byte_len: uint,
678678
char_len: uint) -> @node {
679679
assert(byte_start + byte_len <= str::len(*str));
680680
let candidate = @leaf({

src/libsyntax/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn deserialize_span<D>(_d: D) -> span {
3232
type spanned<T> = {node: T, span: span};
3333

3434
#[auto_serialize]
35-
type ident = @str;
35+
type ident = @str/~;
3636

3737
// Functions may or may not have names.
3838
#[auto_serialize]
@@ -427,11 +427,11 @@ type lit = spanned<lit_>;
427427

428428
#[auto_serialize]
429429
enum lit_ {
430-
lit_str(@str),
430+
lit_str(@str/~),
431431
lit_int(i64, int_ty),
432432
lit_uint(u64, uint_ty),
433433
lit_int_unsuffixed(i64),
434-
lit_float(@str, float_ty),
434+
lit_float(@str/~, float_ty),
435435
lit_nil,
436436
lit_bool(bool),
437437
}

src/libsyntax/attr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident {
124124
* Gets the string value if the meta_item is a meta_name_value variant
125125
* containing a string, otherwise none
126126
*/
127-
fn get_meta_item_value_str(meta: @ast::meta_item) -> option<@str> {
127+
fn get_meta_item_value_str(meta: @ast::meta_item) -> option<@str/~> {
128128
alt meta.node {
129129
ast::meta_name_value(_, v) {
130130
alt v.node {
@@ -154,7 +154,7 @@ fn get_meta_item_list(meta: @ast::meta_item) -> option<~[@ast::meta_item]> {
154154
*/
155155
fn get_name_value_str_pair(
156156
item: @ast::meta_item
157-
) -> option<(ast::ident, @str)> {
157+
) -> option<(ast::ident, @str/~)> {
158158
alt attr::get_meta_item_value_str(item) {
159159
some(value) {
160160
let name = attr::get_meta_item_name(item);
@@ -239,7 +239,7 @@ fn attrs_contains_name(attrs: ~[ast::attribute], +name: str) -> bool {
239239
}
240240

241241
fn first_attr_value_str_by_name(attrs: ~[ast::attribute], +name: str)
242-
-> option<@str> {
242+
-> option<@str/~> {
243243
let mattrs = find_attrs_by_name(attrs, name);
244244
if vec::len(mattrs) > 0u {
245245
ret get_meta_item_value_str(attr_meta(mattrs[0]));
@@ -258,7 +258,7 @@ fn last_meta_item_by_name(
258258
fn last_meta_item_value_str_by_name(
259259
items: ~[@ast::meta_item],
260260
+name: str
261-
) -> option<@str> {
261+
) -> option<@str/~> {
262262
alt last_meta_item_by_name(items, name) {
263263
some(item) {
264264
alt attr::get_meta_item_value_str(item) {

src/libsyntax/codemap.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ enum file_substr {
4545
}
4646

4747
type filemap =
48-
@{name: filename, substr: file_substr, src: @str,
48+
@{name: filename, substr: file_substr, src: @str/~,
4949
start_pos: file_pos, mut lines: ~[file_pos]};
5050

5151
type codemap = @{files: dvec<filemap>};
@@ -55,15 +55,15 @@ type loc = {file: filemap, line: uint, col: uint};
5555
fn new_codemap() -> codemap { @{files: dvec()} }
5656

5757
fn new_filemap_w_substr(+filename: filename, +substr: file_substr,
58-
src: @str,
58+
src: @str/~,
5959
start_pos_ch: uint, start_pos_byte: uint)
6060
-> filemap {
6161
ret @{name: filename, substr: substr, src: src,
6262
start_pos: {ch: start_pos_ch, byte: start_pos_byte},
6363
mut lines: ~[{ch: start_pos_ch, byte: start_pos_byte}]};
6464
}
6565

66-
fn new_filemap(+filename: filename, src: @str,
66+
fn new_filemap(+filename: filename, src: @str/~,
6767
start_pos_ch: uint, start_pos_byte: uint)
6868
-> filemap {
6969
ret new_filemap_w_substr(filename, fss_none, src,

src/libsyntax/ext/auto_serialize.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl helpers for ext_ctxt {
218218
ast::expr_alt(v, arms, ast::alt_exhaustive)))
219219
}
220220

221-
fn lit_str(span: span, s: @str) -> @ast::expr {
221+
fn lit_str(span: span, s: @str/~) -> @ast::expr {
222222
self.expr(
223223
span,
224224
ast::expr_lit(
@@ -343,8 +343,19 @@ fn ser_lambda(cx: ext_ctxt, tps: ser_tps_map, ty: @ast::ty,
343343
cx.lambda(cx.blk(ty.span, ser_ty(cx, tps, ty, s, v)))
344344
}
345345

346+
fn is_vec_or_str(ty: @ast::ty) -> bool {
347+
alt ty.node {
348+
ast::ty_vec(_) { true }
349+
// This may be wrong if the user has shadowed (!) str
350+
ast::ty_path(@{span: _, global: _, idents: ids,
351+
rp: none, types: _}, _)
352+
if ids == ~[@"str"] { true }
353+
_ { false }
354+
}
355+
}
356+
346357
fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
347-
ty: @ast::ty, -s: @ast::expr, -v: @ast::expr)
358+
ty: @ast::ty, -s: @ast::expr, -v: @ast::expr)
348359
-> ~[@ast::stmt] {
349360

350361
let ext_cx = cx; // required for #ast{}
@@ -365,6 +376,11 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
365376
~[#ast(stmt){$(s).emit_box($(l));}]
366377
}
367378

379+
// For unique evecs/estrs, just pass through to underlying vec or str
380+
ast::ty_uniq(mt) if is_vec_or_str(mt.ty) {
381+
ser_ty(cx, tps, mt.ty, s, v)
382+
}
383+
368384
ast::ty_uniq(mt) {
369385
let l = ser_lambda(cx, tps, mt.ty, cx.clone(s), #ast{ *$(v) });
370386
~[#ast(stmt){$(s).emit_uniq($(l));}]
@@ -612,6 +628,11 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map,
612628
#ast{ @$(d).read_box($(l)) }
613629
}
614630

631+
// For unique evecs/estrs, just pass through to underlying vec or str
632+
ast::ty_uniq(mt) if is_vec_or_str(mt.ty) {
633+
deser_ty(cx, tps, mt.ty, d)
634+
}
635+
615636
ast::ty_uniq(mt) {
616637
let l = deser_lambda(cx, tps, mt.ty, cx.clone(d));
617638
#ast{ ~$(d).read_uniq($(l)) }

src/libsyntax/ext/simplext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
679679
_body: ast::mac_body) -> base::macro_def {
680680
let args = get_mac_args_no_max(cx, sp, arg, 0u, "macro");
681681

682-
let mut macro_name: option<@str> = none;
682+
let mut macro_name: option<@str/~> = none;
683683
let mut clauses: ~[@clause] = ~[];
684684
for args.each |arg| {
685685
alt arg.node {

0 commit comments

Comments
 (0)