Skip to content

libsyntax: Change ~[T] to Vec<T>. #12637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/libfourcc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ struct Ident {
}

fn parse_tts(cx: &ExtCtxt, tts: &[ast::TokenTree]) -> (@ast::Expr, Option<Ident>) {
let p = &mut parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_owned());
let p = &mut parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(),
tts.iter()
.map(|x| (*x).clone())
.collect());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a rather unfortunate pattern. Shouldn't there be something like tts.to_vec() or Vec::from_slice(tts)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just transitionary. I don't really want to add methods to Vec that will persist for only a week or so.

let ex = p.parse_expr();
let id = if p.token == token::EOF {
None
Expand All @@ -151,7 +155,7 @@ fn parse_tts(cx: &ExtCtxt, tts: &[ast::TokenTree]) -> (@ast::Expr, Option<Ident>
fn target_endian_little(cx: &ExtCtxt, sp: Span) -> bool {
let meta = cx.meta_name_value(sp, InternedString::new("target_endian"),
ast::LitStr(InternedString::new("little"), ast::CookedStr));
contains(cx.cfg(), meta)
contains(cx.cfg().as_slice(), meta)
}

// FIXME (10872): This is required to prevent an LLVM assert on Windows
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ pub fn crate_id_hash(crate_id: &CrateId) -> ~str {
pub fn build_link_meta(krate: &ast::Crate,
output: &OutputFilenames) -> LinkMeta {
let r = LinkMeta {
crateid: find_crate_id(krate.attrs, output),
crateid: find_crate_id(krate.attrs.as_slice(), output),
crate_hash: Svh::calculate(krate),
};
info!("{}", r);
Expand Down
34 changes: 22 additions & 12 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use std::io::fs;
use std::io::MemReader;
use std::os;
use std::vec;
use std::vec_ng::Vec;
use std::vec_ng;
use collections::{HashMap, HashSet};
use getopts::{optopt, optmulti, optflag, optflagopt};
use getopts;
Expand Down Expand Up @@ -101,15 +103,15 @@ pub fn default_configuration(sess: Session) ->
};

let mk = attr::mk_name_value_item_str;
return ~[ // Target bindings.
return vec!(// Target bindings.
attr::mk_word_item(fam.clone()),
mk(InternedString::new("target_os"), tos),
mk(InternedString::new("target_family"), fam),
mk(InternedString::new("target_arch"), InternedString::new(arch)),
mk(InternedString::new("target_endian"), InternedString::new(end)),
mk(InternedString::new("target_word_size"),
InternedString::new(wordsz)),
];
InternedString::new(wordsz))
);
}

pub fn append_configuration(cfg: &mut ast::CrateConfig,
Expand All @@ -119,8 +121,7 @@ pub fn append_configuration(cfg: &mut ast::CrateConfig,
}
}

pub fn build_configuration(sess: Session) ->
ast::CrateConfig {
pub fn build_configuration(sess: Session) -> ast::CrateConfig {
// Combine the configuration requested by the session (command line) with
// some default and generated configuration items
let default_cfg = default_configuration(sess);
Expand All @@ -135,15 +136,19 @@ pub fn build_configuration(sess: Session) ->
} else {
InternedString::new("nogc")
});
return vec::append(user_cfg, default_cfg);
return vec_ng::append(user_cfg.move_iter().collect(),
default_cfg.as_slice());
}

// Convert strings provided as --cfg [cfgspec] into a crate_cfg
fn parse_cfgspecs(cfgspecs: ~[~str])
-> ast::CrateConfig {
cfgspecs.move_iter().map(|s| {
let sess = parse::new_parse_sess();
parse::parse_meta_from_source_str("cfgspec".to_str(), s, ~[], sess)
parse::parse_meta_from_source_str("cfgspec".to_str(),
s,
Vec::new(),
sess)
}).collect::<ast::CrateConfig>()
}

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

sess.building_library.set(session::building_library(sess.opts, &krate));
sess.crate_types.set(session::collect_crate_types(&sess, krate.attrs));
sess.crate_types.set(session::collect_crate_types(&sess,
krate.attrs
.as_slice()));

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

let mut out_filenames = ~[];
for output_type in sess.opts.output_types.iter() {
Expand Down Expand Up @@ -546,8 +553,11 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
let loader = &mut Loader::new(sess);
phase_2_configure_and_expand(sess, loader, krate)
};
let outputs = build_output_filenames(input, outdir, output,
expanded_crate.attrs, sess);
let outputs = build_output_filenames(input,
outdir,
output,
expanded_crate.attrs.as_slice(),
sess);

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

Expand Down Expand Up @@ -1180,7 +1190,7 @@ mod test {
let sessopts = build_session_options(matches);
let sess = build_session(sessopts, None);
let cfg = build_configuration(sess);
assert!((attr::contains_name(cfg, "test")));
assert!((attr::contains_name(cfg.as_slice(), "test")));
}

// When the user supplies --test and --cfg test, don't implicitly add
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use syntax::{abi, ast, codemap};
use syntax;

use std::cell::{Cell, RefCell};
use std::vec_ng::Vec;
use collections::{HashMap,HashSet};

pub struct Config {
Expand Down Expand Up @@ -319,7 +320,7 @@ pub fn basic_options() -> @Options {
addl_lib_search_paths: @RefCell::new(HashSet::new()),
maybe_sysroot: None,
target_triple: host_triple(),
cfg: ~[],
cfg: Vec::new(),
test: false,
parse_only: false,
no_trans: false,
Expand Down Expand Up @@ -451,7 +452,8 @@ pub fn building_library(options: &Options, krate: &ast::Crate) -> bool {
CrateTypeStaticlib | CrateTypeDylib | CrateTypeRlib => return true
}
}
match syntax::attr::first_attr_value_str_by_name(krate.attrs, "crate_type") {
match syntax::attr::first_attr_value_str_by_name(krate.attrs.as_slice(),
"crate_type") {
Some(s) => {
s.equiv(&("lib")) ||
s.equiv(&("rlib")) ||
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/front/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct Context<'a> {
// any items that do not belong in the current configuration
pub fn strip_unconfigured_items(krate: ast::Crate) -> ast::Crate {
let config = krate.config.clone();
strip_items(krate, |attrs| in_cfg(config, attrs))
strip_items(krate, |attrs| in_cfg(config.as_slice(), attrs))
}

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

fn fold_struct(cx: &Context, def: &ast::StructDef) -> @ast::StructDef {
let mut fields = def.fields.iter().map(|c| c.clone()).filter(|m| {
(cx.in_cfg)(m.node.attrs)
(cx.in_cfg)(m.node.attrs.as_slice())
});
@ast::StructDef {
fields: fields.collect(),
Expand Down Expand Up @@ -189,25 +189,25 @@ fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
}

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

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

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

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

fn trait_method_in_cfg(cx: &Context, meth: &ast::TraitMethod) -> bool {
match *meth {
ast::Required(ref meth) => (cx.in_cfg)(meth.attrs),
ast::Provided(meth) => (cx.in_cfg)(meth.attrs)
ast::Required(ref meth) => (cx.in_cfg)(meth.attrs.as_slice()),
ast::Provided(meth) => (cx.in_cfg)(meth.attrs.as_slice())
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/front/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl Visitor<()> for Context {
}

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

ast::ItemFn(..) => {
if attr::contains_name(i.attrs, "macro_registrar") {
if attr::contains_name(i.attrs.as_slice(), "macro_registrar") {
self.gate_feature("macro_registrar", i.span,
"cross-crate macro exports are \
experimental and possibly buggy");
}
}

ast::ItemStruct(..) => {
if attr::contains_name(i.attrs, "simd") {
if attr::contains_name(i.attrs.as_slice(), "simd") {
self.gate_feature("simd", i.span,
"SIMD types are experimental and possibly buggy");
}
Expand Down
39 changes: 19 additions & 20 deletions src/librustc/front/std_inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

use driver::session::Session;

use std::vec;
use std::vec_ng::Vec;
use std::vec_ng;
use syntax::ast;
use syntax::attr;
use syntax::codemap::DUMMY_SP;
Expand Down Expand Up @@ -43,11 +44,11 @@ pub fn maybe_inject_prelude(sess: Session, krate: ast::Crate) -> ast::Crate {
}

fn use_std(krate: &ast::Crate) -> bool {
!attr::contains_name(krate.attrs, "no_std")
!attr::contains_name(krate.attrs.as_slice(), "no_std")
}

fn use_uv(krate: &ast::Crate) -> bool {
!attr::contains_name(krate.attrs, "no_uv")
!attr::contains_name(krate.attrs.as_slice(), "no_uv")
}

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

impl fold::Folder for StandardLibraryInjector {
fn fold_crate(&mut self, krate: ast::Crate) -> ast::Crate {
let mut vis = ~[ast::ViewItem {
let mut vis = vec!(ast::ViewItem {
node: ast::ViewItemExternMod(token::str_to_ident("std"),
with_version("std"),
ast::DUMMY_NODE_ID),
attrs: ~[
attrs: vec!(
attr::mk_attr(attr::mk_list_item(
InternedString::new("phase"),
~[
vec!(
attr::mk_word_item(InternedString::new("syntax")),
attr::mk_word_item(InternedString::new("link")
)]))
],
))))),
vis: ast::Inherited,
span: DUMMY_SP
}];
});

if use_uv(&krate) && !self.sess.building_library.get() {
vis.push(ast::ViewItem {
node: ast::ViewItemExternMod(token::str_to_ident("green"),
with_version("green"),
ast::DUMMY_NODE_ID),
attrs: ~[],
attrs: Vec::new(),
vis: ast::Inherited,
span: DUMMY_SP
});
vis.push(ast::ViewItem {
node: ast::ViewItemExternMod(token::str_to_ident("rustuv"),
with_version("rustuv"),
ast::DUMMY_NODE_ID),
attrs: ~[],
attrs: Vec::new(),
vis: ast::Inherited,
span: DUMMY_SP
});
}

vis.push_all(krate.module.view_items);
vis.push_all_move(krate.module.view_items.clone());
let new_module = ast::Mod {
view_items: vis,
..krate.module.clone()
Expand All @@ -134,7 +134,7 @@ struct PreludeInjector {

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

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

let vp = @codemap::dummy_spanned(ast::ViewPathGlob(prelude_path, ast::DUMMY_NODE_ID));
let vi2 = ast::ViewItem {
node: ast::ViewItemUse(~[vp]),
attrs: ~[],
node: ast::ViewItemUse(vec!(vp)),
attrs: Vec::new(),
vis: ast::Inherited,
span: DUMMY_SP,
};

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

// FIXME #2543: Bad copy.
let new_module = ast::Mod {
Expand Down
Loading