Skip to content

Commit 27e235b

Browse files
committed
libsyntax and librustc: minor cleanup
1 parent 1a5b8e4 commit 27e235b

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

src/librustc/driver/driver.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn anon_src() -> ~str { ~"<anon>" }
6262
6363
pub fn source_name(input: input) -> ~str {
6464
match input {
65-
file_input(ref ifile) => (*ifile).to_str(),
65+
file_input(ref ifile) => ifile.to_str(),
6666
str_input(_) => anon_src()
6767
}
6868
}
@@ -112,9 +112,9 @@ pub fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
112112
pub fn append_configuration(+cfg: ast::crate_cfg, +name: ~str)
113113
-> ast::crate_cfg {
114114
if attr::contains_name(cfg, name) {
115-
return cfg;
115+
cfg
116116
} else {
117-
return vec::append_one(cfg, attr::mk_word_item(name));
117+
vec::append_one(cfg, attr::mk_word_item(name))
118118
}
119119
}
120120

src/librustc/metadata/encoder.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ fn encode_crate_deps(ecx: @encode_ctxt,
11241124
type numdep = decoder::crate_dep;
11251125
11261126
// Pull the cnums and name,vers,hash out of cstore
1127-
let mut deps: ~[numdep] = ~[];
1127+
let mut deps = ~[];
11281128
do cstore::iter_crate_data(cstore) |key, val| {
11291129
let dep = {cnum: key,
11301130
name: ecx.tcx.sess.ident_of(/*bad*/copy val.name),
@@ -1134,10 +1134,7 @@ fn encode_crate_deps(ecx: @encode_ctxt,
11341134
};
11351135
11361136
// Sort by cnum
1137-
pure fn lteq(kv1: &numdep, kv2: &numdep) -> bool {
1138-
kv1.cnum <= kv2.cnum
1139-
}
1140-
std::sort::quick_sort(deps, lteq);
1137+
std::sort::quick_sort(deps, |kv1, kv2| kv1.cnum <= kv2.cnum);
11411138
11421139
// Sanity-check the crate numbers
11431140
let mut expected_cnum = 1;
@@ -1147,7 +1144,7 @@ fn encode_crate_deps(ecx: @encode_ctxt,
11471144
}
11481145
11491146
// mut -> immutable hack for vec::map
1150-
return vec::slice(deps, 0u, vec::len(deps)).to_vec();
1147+
deps.slice(0, deps.len())
11511148
}
11521149
11531150
// We're just going to write a list of crate 'name-hash-version's, with

src/libsyntax/attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ pub fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] {
267267
}
268268

269269
// This is sort of stupid here, converting to a vec of mutables and back
270-
let mut v: ~[@ast::meta_item] = items;
270+
let mut v = items;
271271
std::sort::quick_sort(v, lteq);
272272

273273
// There doesn't seem to be a more optimal way to do this
@@ -371,7 +371,7 @@ pub fn require_unique_names(diagnostic: span_handler,
371371
let name = get_meta_item_name(*meta);
372372

373373
// FIXME: How do I silence the warnings? --pcw (#2619)
374-
if !set.insert(name) {
374+
if !set.insert(copy name) {
375375
diagnostic.span_fatal(meta.span,
376376
fmt!("duplicate meta item `%s`", name));
377377
}

src/libsyntax/ext/expand.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use core::prelude::*;
1313
use ast::{crate, expr_, expr_mac, mac_invoc_tt};
1414
use ast::{tt_delim, tt_tok, item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi};
1515
use ast;
16+
use attr;
1617
use codemap::{span, ExpandedFrom};
1718
use ext::base::*;
1819
use fold::*;
@@ -99,11 +100,8 @@ pub fn expand_mod_items(exts: HashMap<~str, SyntaxExtension>, cx: ext_ctxt,
99100
// the item into a new set of items.
100101
let new_items = do vec::flat_map(module_.items) |item| {
101102
do vec::foldr(item.attrs, ~[*item]) |attr, items| {
102-
let mname = match attr.node.value.node {
103-
ast::meta_word(ref n) => (*n),
104-
ast::meta_name_value(ref n, _) => (*n),
105-
ast::meta_list(ref n, _) => (*n)
106-
};
103+
let mname = attr::get_attr_name(attr);
104+
107105
match exts.find(&mname) {
108106
None | Some(NormalTT(_)) | Some(ItemTT(*)) => items,
109107
Some(ItemDecorator(dec_fn)) => {

0 commit comments

Comments
 (0)