Skip to content

Commit 910012a

Browse files
committed
auto merge of #12637 : pcwalton/rust/devecing, r=alexcrichton
r? @alexcrichton
2 parents baf7908 + 3559324 commit 910012a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2144
-1607
lines changed

src/libfourcc/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ struct Ident {
131131
}
132132

133133
fn parse_tts(cx: &ExtCtxt, tts: &[ast::TokenTree]) -> (@ast::Expr, Option<Ident>) {
134-
let p = &mut parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_owned());
134+
let p = &mut parse::new_parser_from_tts(cx.parse_sess(),
135+
cx.cfg(),
136+
tts.iter()
137+
.map(|x| (*x).clone())
138+
.collect());
135139
let ex = p.parse_expr();
136140
let id = if p.token == token::EOF {
137141
None
@@ -151,7 +155,7 @@ fn parse_tts(cx: &ExtCtxt, tts: &[ast::TokenTree]) -> (@ast::Expr, Option<Ident>
151155
fn target_endian_little(cx: &ExtCtxt, sp: Span) -> bool {
152156
let meta = cx.meta_name_value(sp, InternedString::new("target_endian"),
153157
ast::LitStr(InternedString::new("little"), ast::CookedStr));
154-
contains(cx.cfg(), meta)
158+
contains(cx.cfg().as_slice(), meta)
155159
}
156160

157161
// FIXME (10872): This is required to prevent an LLVM assert on Windows

src/librustc/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ pub fn crate_id_hash(crate_id: &CrateId) -> ~str {
519519
pub fn build_link_meta(krate: &ast::Crate,
520520
output: &OutputFilenames) -> LinkMeta {
521521
let r = LinkMeta {
522-
crateid: find_crate_id(krate.attrs, output),
522+
crateid: find_crate_id(krate.attrs.as_slice(), output),
523523
crate_hash: Svh::calculate(krate),
524524
};
525525
info!("{}", r);

src/librustc/driver/driver.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ use std::io::fs;
3535
use std::io::MemReader;
3636
use std::os;
3737
use std::vec;
38+
use std::vec_ng::Vec;
39+
use std::vec_ng;
3840
use collections::{HashMap, HashSet};
3941
use getopts::{optopt, optmulti, optflag, optflagopt};
4042
use getopts;
@@ -101,15 +103,15 @@ pub fn default_configuration(sess: Session) ->
101103
};
102104

103105
let mk = attr::mk_name_value_item_str;
104-
return ~[ // Target bindings.
106+
return vec!(// Target bindings.
105107
attr::mk_word_item(fam.clone()),
106108
mk(InternedString::new("target_os"), tos),
107109
mk(InternedString::new("target_family"), fam),
108110
mk(InternedString::new("target_arch"), InternedString::new(arch)),
109111
mk(InternedString::new("target_endian"), InternedString::new(end)),
110112
mk(InternedString::new("target_word_size"),
111-
InternedString::new(wordsz)),
112-
];
113+
InternedString::new(wordsz))
114+
);
113115
}
114116

115117
pub fn append_configuration(cfg: &mut ast::CrateConfig,
@@ -119,8 +121,7 @@ pub fn append_configuration(cfg: &mut ast::CrateConfig,
119121
}
120122
}
121123

122-
pub fn build_configuration(sess: Session) ->
123-
ast::CrateConfig {
124+
pub fn build_configuration(sess: Session) -> ast::CrateConfig {
124125
// Combine the configuration requested by the session (command line) with
125126
// some default and generated configuration items
126127
let default_cfg = default_configuration(sess);
@@ -135,15 +136,19 @@ pub fn build_configuration(sess: Session) ->
135136
} else {
136137
InternedString::new("nogc")
137138
});
138-
return vec::append(user_cfg, default_cfg);
139+
return vec_ng::append(user_cfg.move_iter().collect(),
140+
default_cfg.as_slice());
139141
}
140142

141143
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
142144
fn parse_cfgspecs(cfgspecs: ~[~str])
143145
-> ast::CrateConfig {
144146
cfgspecs.move_iter().map(|s| {
145147
let sess = parse::new_parse_sess();
146-
parse::parse_meta_from_source_str("cfgspec".to_str(), s, ~[], sess)
148+
parse::parse_meta_from_source_str("cfgspec".to_str(),
149+
s,
150+
Vec::new(),
151+
sess)
147152
}).collect::<ast::CrateConfig>()
148153
}
149154

@@ -193,7 +198,9 @@ pub fn phase_2_configure_and_expand(sess: Session,
193198
let time_passes = sess.time_passes();
194199

195200
sess.building_library.set(session::building_library(sess.opts, &krate));
196-
sess.crate_types.set(session::collect_crate_types(&sess, krate.attrs));
201+
sess.crate_types.set(session::collect_crate_types(&sess,
202+
krate.attrs
203+
.as_slice()));
197204

198205
time(time_passes, "gated feature checking", (), |_|
199206
front::feature_gate::check_crate(sess, &krate));
@@ -472,7 +479,7 @@ fn write_out_deps(sess: Session,
472479
input: &Input,
473480
outputs: &OutputFilenames,
474481
krate: &ast::Crate) -> io::IoResult<()> {
475-
let id = link::find_crate_id(krate.attrs, outputs);
482+
let id = link::find_crate_id(krate.attrs.as_slice(), outputs);
476483

477484
let mut out_filenames = ~[];
478485
for output_type in sess.opts.output_types.iter() {
@@ -546,8 +553,11 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
546553
let loader = &mut Loader::new(sess);
547554
phase_2_configure_and_expand(sess, loader, krate)
548555
};
549-
let outputs = build_output_filenames(input, outdir, output,
550-
expanded_crate.attrs, sess);
556+
let outputs = build_output_filenames(input,
557+
outdir,
558+
output,
559+
expanded_crate.attrs.as_slice(),
560+
sess);
551561

552562
write_out_deps(sess, input, &outputs, &expanded_crate).unwrap();
553563

@@ -1180,7 +1190,7 @@ mod test {
11801190
let sessopts = build_session_options(matches);
11811191
let sess = build_session(sessopts, None);
11821192
let cfg = build_configuration(sess);
1183-
assert!((attr::contains_name(cfg, "test")));
1193+
assert!((attr::contains_name(cfg.as_slice(), "test")));
11841194
}
11851195

11861196
// When the user supplies --test and --cfg test, don't implicitly add

src/librustc/driver/session.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use syntax::{abi, ast, codemap};
2727
use syntax;
2828

2929
use std::cell::{Cell, RefCell};
30+
use std::vec_ng::Vec;
3031
use collections::{HashMap,HashSet};
3132

3233
pub struct Config {
@@ -319,7 +320,7 @@ pub fn basic_options() -> @Options {
319320
addl_lib_search_paths: @RefCell::new(HashSet::new()),
320321
maybe_sysroot: None,
321322
target_triple: host_triple(),
322-
cfg: ~[],
323+
cfg: Vec::new(),
323324
test: false,
324325
parse_only: false,
325326
no_trans: false,
@@ -451,7 +452,8 @@ pub fn building_library(options: &Options, krate: &ast::Crate) -> bool {
451452
CrateTypeStaticlib | CrateTypeDylib | CrateTypeRlib => return true
452453
}
453454
}
454-
match syntax::attr::first_attr_value_str_by_name(krate.attrs, "crate_type") {
455+
match syntax::attr::first_attr_value_str_by_name(krate.attrs.as_slice(),
456+
"crate_type") {
455457
Some(s) => {
456458
s.equiv(&("lib")) ||
457459
s.equiv(&("rlib")) ||

src/librustc/front/config.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct Context<'a> {
2121
// any items that do not belong in the current configuration
2222
pub fn strip_unconfigured_items(krate: ast::Crate) -> ast::Crate {
2323
let config = krate.config.clone();
24-
strip_items(krate, |attrs| in_cfg(config, attrs))
24+
strip_items(krate, |attrs| in_cfg(config.as_slice(), attrs))
2525
}
2626

2727
impl<'a> fold::Folder for Context<'a> {
@@ -117,7 +117,7 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
117117
ast::ItemEnum(ref def, ref generics) => {
118118
let mut variants = def.variants.iter().map(|c| c.clone()).
119119
filter_map(|v| {
120-
if !(cx.in_cfg)(v.node.attrs) {
120+
if !(cx.in_cfg)(v.node.attrs.as_slice()) {
121121
None
122122
} else {
123123
Some(match v.node.kind {
@@ -147,7 +147,7 @@ fn fold_item_underscore(cx: &mut Context, item: &ast::Item_) -> ast::Item_ {
147147

148148
fn fold_struct(cx: &Context, def: &ast::StructDef) -> @ast::StructDef {
149149
let mut fields = def.fields.iter().map(|c| c.clone()).filter(|m| {
150-
(cx.in_cfg)(m.node.attrs)
150+
(cx.in_cfg)(m.node.attrs.as_slice())
151151
});
152152
@ast::StructDef {
153153
fields: fields.collect(),
@@ -189,25 +189,25 @@ fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
189189
}
190190

191191
fn item_in_cfg(cx: &Context, item: &ast::Item) -> bool {
192-
return (cx.in_cfg)(item.attrs);
192+
return (cx.in_cfg)(item.attrs.as_slice());
193193
}
194194

195195
fn foreign_item_in_cfg(cx: &Context, item: &ast::ForeignItem) -> bool {
196-
return (cx.in_cfg)(item.attrs);
196+
return (cx.in_cfg)(item.attrs.as_slice());
197197
}
198198

199199
fn view_item_in_cfg(cx: &Context, item: &ast::ViewItem) -> bool {
200-
return (cx.in_cfg)(item.attrs);
200+
return (cx.in_cfg)(item.attrs.as_slice());
201201
}
202202

203203
fn method_in_cfg(cx: &Context, meth: &ast::Method) -> bool {
204-
return (cx.in_cfg)(meth.attrs);
204+
return (cx.in_cfg)(meth.attrs.as_slice());
205205
}
206206

207207
fn trait_method_in_cfg(cx: &Context, meth: &ast::TraitMethod) -> bool {
208208
match *meth {
209-
ast::Required(ref meth) => (cx.in_cfg)(meth.attrs),
210-
ast::Provided(meth) => (cx.in_cfg)(meth.attrs)
209+
ast::Required(ref meth) => (cx.in_cfg)(meth.attrs.as_slice()),
210+
ast::Provided(meth) => (cx.in_cfg)(meth.attrs.as_slice())
211211
}
212212
}
213213

src/librustc/front/feature_gate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl Visitor<()> for Context {
171171
}
172172

173173
ast::ItemForeignMod(..) => {
174-
if attr::contains_name(i.attrs, "link_args") {
174+
if attr::contains_name(i.attrs.as_slice(), "link_args") {
175175
self.gate_feature("link_args", i.span,
176176
"the `link_args` attribute is not portable \
177177
across platforms, it is recommended to \
@@ -180,15 +180,15 @@ impl Visitor<()> for Context {
180180
}
181181

182182
ast::ItemFn(..) => {
183-
if attr::contains_name(i.attrs, "macro_registrar") {
183+
if attr::contains_name(i.attrs.as_slice(), "macro_registrar") {
184184
self.gate_feature("macro_registrar", i.span,
185185
"cross-crate macro exports are \
186186
experimental and possibly buggy");
187187
}
188188
}
189189

190190
ast::ItemStruct(..) => {
191-
if attr::contains_name(i.attrs, "simd") {
191+
if attr::contains_name(i.attrs.as_slice(), "simd") {
192192
self.gate_feature("simd", i.span,
193193
"SIMD types are experimental and possibly buggy");
194194
}

src/librustc/front/std_inject.rs

+19-20
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
use driver::session::Session;
1313

14-
use std::vec;
14+
use std::vec_ng::Vec;
15+
use std::vec_ng;
1516
use syntax::ast;
1617
use syntax::attr;
1718
use syntax::codemap::DUMMY_SP;
@@ -43,11 +44,11 @@ pub fn maybe_inject_prelude(sess: Session, krate: ast::Crate) -> ast::Crate {
4344
}
4445

4546
fn use_std(krate: &ast::Crate) -> bool {
46-
!attr::contains_name(krate.attrs, "no_std")
47+
!attr::contains_name(krate.attrs.as_slice(), "no_std")
4748
}
4849

4950
fn use_uv(krate: &ast::Crate) -> bool {
50-
!attr::contains_name(krate.attrs, "no_uv")
51+
!attr::contains_name(krate.attrs.as_slice(), "no_uv")
5152
}
5253

5354
fn no_prelude(attrs: &[ast::Attribute]) -> bool {
@@ -72,42 +73,41 @@ pub fn with_version(krate: &str) -> Option<(InternedString, ast::StrStyle)> {
7273

7374
impl fold::Folder for StandardLibraryInjector {
7475
fn fold_crate(&mut self, krate: ast::Crate) -> ast::Crate {
75-
let mut vis = ~[ast::ViewItem {
76+
let mut vis = vec!(ast::ViewItem {
7677
node: ast::ViewItemExternMod(token::str_to_ident("std"),
7778
with_version("std"),
7879
ast::DUMMY_NODE_ID),
79-
attrs: ~[
80+
attrs: vec!(
8081
attr::mk_attr(attr::mk_list_item(
8182
InternedString::new("phase"),
82-
~[
83+
vec!(
8384
attr::mk_word_item(InternedString::new("syntax")),
8485
attr::mk_word_item(InternedString::new("link")
85-
)]))
86-
],
86+
))))),
8787
vis: ast::Inherited,
8888
span: DUMMY_SP
89-
}];
89+
});
9090

9191
if use_uv(&krate) && !self.sess.building_library.get() {
9292
vis.push(ast::ViewItem {
9393
node: ast::ViewItemExternMod(token::str_to_ident("green"),
9494
with_version("green"),
9595
ast::DUMMY_NODE_ID),
96-
attrs: ~[],
96+
attrs: Vec::new(),
9797
vis: ast::Inherited,
9898
span: DUMMY_SP
9999
});
100100
vis.push(ast::ViewItem {
101101
node: ast::ViewItemExternMod(token::str_to_ident("rustuv"),
102102
with_version("rustuv"),
103103
ast::DUMMY_NODE_ID),
104-
attrs: ~[],
104+
attrs: Vec::new(),
105105
vis: ast::Inherited,
106106
span: DUMMY_SP
107107
});
108108
}
109109

110-
vis.push_all(krate.module.view_items);
110+
vis.push_all_move(krate.module.view_items.clone());
111111
let new_module = ast::Mod {
112112
view_items: vis,
113113
..krate.module.clone()
@@ -134,7 +134,7 @@ struct PreludeInjector {
134134

135135
impl fold::Folder for PreludeInjector {
136136
fn fold_crate(&mut self, krate: ast::Crate) -> ast::Crate {
137-
if !no_prelude(krate.attrs) {
137+
if !no_prelude(krate.attrs.as_slice()) {
138138
// only add `use std::prelude::*;` if there wasn't a
139139
// `#[no_implicit_prelude];` at the crate level.
140140
ast::Crate {
@@ -147,7 +147,7 @@ impl fold::Folder for PreludeInjector {
147147
}
148148

149149
fn fold_item(&mut self, item: @ast::Item) -> SmallVector<@ast::Item> {
150-
if !no_prelude(item.attrs) {
150+
if !no_prelude(item.attrs.as_slice()) {
151151
// only recur if there wasn't `#[no_implicit_prelude];`
152152
// on this item, i.e. this means that the prelude is not
153153
// implicitly imported though the whole subtree
@@ -161,7 +161,7 @@ impl fold::Folder for PreludeInjector {
161161
let prelude_path = ast::Path {
162162
span: DUMMY_SP,
163163
global: false,
164-
segments: ~[
164+
segments: vec!(
165165
ast::PathSegment {
166166
identifier: token::str_to_ident("std"),
167167
lifetimes: opt_vec::Empty,
@@ -171,19 +171,18 @@ impl fold::Folder for PreludeInjector {
171171
identifier: token::str_to_ident("prelude"),
172172
lifetimes: opt_vec::Empty,
173173
types: opt_vec::Empty,
174-
},
175-
],
174+
}),
176175
};
177176

178177
let vp = @codemap::dummy_spanned(ast::ViewPathGlob(prelude_path, ast::DUMMY_NODE_ID));
179178
let vi2 = ast::ViewItem {
180-
node: ast::ViewItemUse(~[vp]),
181-
attrs: ~[],
179+
node: ast::ViewItemUse(vec!(vp)),
180+
attrs: Vec::new(),
182181
vis: ast::Inherited,
183182
span: DUMMY_SP,
184183
};
185184

186-
let vis = vec::append(~[vi2], module.view_items);
185+
let vis = vec_ng::append(vec!(vi2), module.view_items.as_slice());
187186

188187
// FIXME #2543: Bad copy.
189188
let new_module = ast::Mod {

0 commit comments

Comments
 (0)