Skip to content

Commit bff22cf

Browse files
committed
libsyntax: add some explicit copies
1 parent 752befe commit bff22cf

File tree

8 files changed

+94
-68
lines changed

8 files changed

+94
-68
lines changed

src/libsyntax/ast_map.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ pub fn path_to_str_with_sep(p: &[path_elt], sep: ~str, itr: @ident_interner)
6060
-> ~str {
6161
let strs = do p.map |e| {
6262
match *e {
63-
path_mod(s) => *itr.get(s),
64-
path_name(s) => *itr.get(s)
63+
path_mod(s) => copy *itr.get(s),
64+
path_name(s) => copy *itr.get(s)
6565
}
6666
};
6767
str::connect(strs, sep)
@@ -70,7 +70,7 @@ pub fn path_to_str_with_sep(p: &[path_elt], sep: ~str, itr: @ident_interner)
7070
pub fn path_ident_to_str(p: path, i: ident, itr: @ident_interner) -> ~str {
7171
if vec::is_empty(p) {
7272
//FIXME /* FIXME (#2543) */ copy *i
73-
*itr.get(i)
73+
copy *itr.get(i)
7474
} else {
7575
fmt!("%s::%s", path_to_str(p, itr), *itr.get(i))
7676
}
@@ -82,8 +82,8 @@ pub fn path_to_str(p: &[path_elt], itr: @ident_interner) -> ~str {
8282

8383
pub fn path_elt_to_str(pe: path_elt, itr: @ident_interner) -> ~str {
8484
match pe {
85-
path_mod(s) => *itr.get(s),
86-
path_name(s) => *itr.get(s)
85+
path_mod(s) => copy *itr.get(s),
86+
path_name(s) => copy *itr.get(s)
8787
}
8888
}
8989

@@ -310,7 +310,10 @@ pub fn map_item(i: @item, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) {
310310
for methods.each |tm| {
311311
let id = ast_util::trait_method_to_ty_method(tm).id;
312312
let d_id = ast_util::local_def(i.id);
313-
cx.map.insert(id, node_trait_method(@*tm, d_id, item_path));
313+
cx.map.insert(
314+
id,
315+
node_trait_method(@copy *tm, d_id, item_path)
316+
);
314317
}
315318
}
316319
_ => ()

src/libsyntax/ast_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use core::vec;
2727
pub pure fn path_name_i(idents: &[ident], intr: @token::ident_interner)
2828
-> ~str {
2929
// FIXME: Bad copies (#2543 -- same for everything else that says "bad")
30-
str::connect(idents.map(|i| *intr.get(*i)), ~"::")
30+
str::connect(idents.map(|i| copy *intr.get(*i)), ~"::")
3131
}
3232

3333

@@ -283,7 +283,7 @@ pub fn split_trait_methods(trait_methods: &[trait_method])
283283
let mut reqd = ~[], provd = ~[];
284284
for trait_methods.each |trt_method| {
285285
match *trt_method {
286-
required(ref tm) => reqd.push((*tm)),
286+
required(ref tm) => reqd.push(copy *tm),
287287
provided(m) => provd.push(m)
288288
}
289289
};

src/libsyntax/ext/pipes/parse_proto.rs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ pub impl proto_parser for parser::Parser {
2727
fn parse_proto(&self, id: ~str) -> protocol {
2828
let proto = protocol(id, *self.span);
2929

30-
self.parse_seq_to_before_end(token::EOF, SeqSep {
31-
sep: None,
32-
trailing_sep_allowed: false
33-
}, |self| self.parse_state(proto));
30+
self.parse_seq_to_before_end(
31+
token::EOF,
32+
SeqSep {
33+
sep: None,
34+
trailing_sep_allowed: false,
35+
},
36+
|self| self.parse_state(proto)
37+
);
3438

3539
return proto;
3640
}
@@ -40,9 +44,9 @@ pub impl proto_parser for parser::Parser {
4044
let name = *self.interner.get(id);
4145

4246
self.expect(&token::COLON);
43-
let dir = match *self.token {
44-
token::IDENT(n, _) => self.interner.get(n),
45-
_ => fail!()
47+
let dir = match copy *self.token {
48+
token::IDENT(n, _) => self.interner.get(n),
49+
_ => fail!()
4650
};
4751
self.bump();
4852
let dir = match dir {
@@ -61,21 +65,29 @@ pub impl proto_parser for parser::Parser {
6165

6266
// parse the messages
6367
self.parse_unspanned_seq(
64-
token::LBRACE, token::RBRACE, SeqSep {
68+
token::LBRACE,
69+
token::RBRACE,
70+
SeqSep {
6571
sep: Some(token::COMMA),
66-
trailing_sep_allowed: true
67-
}, |self| self.parse_message(state));
72+
trailing_sep_allowed: true,
73+
},
74+
|self| self.parse_message(state)
75+
);
6876
}
6977

7078
fn parse_message(&self, state: state) {
7179
let mname = *self.interner.get(self.parse_ident());
7280

7381
let args = if *self.token == token::LPAREN {
74-
self.parse_unspanned_seq(token::LPAREN,
75-
token::RPAREN, SeqSep {
76-
sep: Some(token::COMMA),
77-
trailing_sep_allowed: true
78-
}, |p| p.parse_ty(false))
82+
self.parse_unspanned_seq(
83+
token::LPAREN,
84+
token::RPAREN,
85+
SeqSep {
86+
sep: Some(token::COMMA),
87+
trailing_sep_allowed: true,
88+
},
89+
|p| p.parse_ty(false)
90+
)
7991
}
8092
else { ~[] };
8193

@@ -85,11 +97,15 @@ pub impl proto_parser for parser::Parser {
8597
token::IDENT(_, _) => {
8698
let name = *self.interner.get(self.parse_ident());
8799
let ntys = if *self.token == token::LT {
88-
self.parse_unspanned_seq(token::LT,
89-
token::GT, SeqSep {
90-
sep: Some(token::COMMA),
91-
trailing_sep_allowed: true
92-
}, |p| p.parse_ty(false))
100+
self.parse_unspanned_seq(
101+
token::LT,
102+
token::GT,
103+
SeqSep {
104+
sep: Some(token::COMMA),
105+
trailing_sep_allowed: true,
106+
},
107+
|p| p.parse_ty(false)
108+
)
93109
}
94110
else { ~[] };
95111
Some(next_state {state: name, tys: ntys})

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ pub fn parse_nt(p: Parser, name: ~str) -> nonterminal {
424424
~"ident" => match *p.token {
425425
token::IDENT(sn,b) => { p.bump(); token::nt_ident(sn,b) }
426426
_ => p.fatal(~"expected ident, found "
427-
+ token::to_str(p.reader.interner(), *p.token))
427+
+ token::to_str(p.reader.interner(), copy *p.token))
428428
},
429429
~"path" => token::nt_path(p.parse_path_with_tps(false)),
430430
~"tt" => {

src/libsyntax/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ pub fn noop_fold_item_underscore(i: &item_, fld: ast_fold) -> item_ {
280280
}
281281
item_mac(ref m) => {
282282
// FIXME #2888: we might actually want to do something here.
283-
item_mac((*m))
283+
item_mac(copy *m)
284284
}
285285
}
286286
}

src/libsyntax/parse/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ pub struct SeqSep {
2727
trailing_sep_allowed: bool
2828
}
2929

30-
pub fn seq_sep_trailing_disallowed(t: token::Token) -> SeqSep {
30+
pub fn seq_sep_trailing_disallowed(+t: token::Token) -> SeqSep {
3131
SeqSep {
3232
sep: Some(t),
3333
trailing_sep_allowed: false,
3434
}
3535
}
36-
pub fn seq_sep_trailing_allowed(t: token::Token) -> SeqSep {
36+
pub fn seq_sep_trailing_allowed(+t: token::Token) -> SeqSep {
3737
SeqSep {
3838
sep: Some(t),
3939
trailing_sep_allowed: true,

src/libsyntax/parse/obsolete.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub impl Parser {
198198

199199
fn try_parse_obsolete_priv_section() -> bool {
200200
if self.is_keyword(&~"priv") && self.look_ahead(1) == token::LBRACE {
201-
self.obsolete(*self.span, ObsoletePrivSection);
201+
self.obsolete(copy *self.span, ObsoletePrivSection);
202202
self.eat_keyword(&~"priv");
203203
self.bump();
204204
while *self.token != token::RBRACE {

0 commit comments

Comments
 (0)