Skip to content
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

Less bad copy throughout libsyntax/librustc #5443

Closed
wants to merge 2 commits into from
Closed
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: 4 additions & 4 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ pub mod write {
let opts = sess.opts;
if sess.time_llvm_passes() { llvm::LLVMRustEnableTimePasses(); }
let mut pm = mk_pass_manager();
let td = mk_target_data(
/*bad*/copy sess.targ_cfg.target_strs.data_layout);
let td = mk_target_data(sess.targ_cfg.target_strs.data_layout);
llvm::LLVMAddTargetData(td.lltd, pm.llpm);
// FIXME (#2812): run the linter here also, once there are llvm-c
// bindings for it.
Expand Down Expand Up @@ -834,8 +833,9 @@ pub fn link_binary(sess: Session,
// to be found at compile time so it is still entirely up to outside
// forces to make sure that library can be found at runtime.

let addl_paths = /*bad*/copy sess.opts.addl_lib_search_paths;
for addl_paths.each |path| { cc_args.push(~"-L" + path.to_str()); }
for sess.opts.addl_lib_search_paths.each |path| {
cc_args.push(~"-L" + path.to_str());
}

// The names of the extern libraries
let used_libs = cstore::get_used_libraries(cstore);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path)
// where rustrt is and we know every rust program needs it
let libs = vec::append_one(libs, get_sysroot_absolute_rt_lib(sess));

let target_triple = /*bad*/copy sess.opts.target_triple;
let rpaths = get_rpaths(os, &sysroot, output, libs, target_triple);
let rpaths = get_rpaths(os, &sysroot, output, libs,
sess.opts.target_triple);
rpaths_to_flags(rpaths)
}

Expand Down Expand Up @@ -140,8 +140,8 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
let abs2 = abs2.normalize();
debug!("finding relative path from %s to %s",
abs1.to_str(), abs2.to_str());
let split1 = /*bad*/copy abs1.components;
let split2 = /*bad*/copy abs2.components;
let split1: &[~str] = abs1.components;
let split2: &[~str] = abs2.components;
let len1 = vec::len(split1);
let len2 = vec::len(split2);
fail_unless!(len1 > 0);
Expand Down
17 changes: 7 additions & 10 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,12 @@ pub fn build_configuration(sess: Session, +argv0: ~str, input: input) ->
}

// Convert strings provided as --cfg [cfgspec] into a crate_cfg
fn parse_cfgspecs(cfgspecs: ~[~str],
fn parse_cfgspecs(+cfgspecs: ~[~str],
demitter: diagnostic::Emitter) -> ast::crate_cfg {
let mut meta = ~[];
for cfgspecs.each |s| {
do vec::map_consume(cfgspecs) |s| {
let sess = parse::new_parse_sess(Some(demitter));
let m = parse::parse_meta_from_source_str(~"cfgspec", @/*bad*/ copy *s, ~[], sess);
meta.push(m)
parse::parse_meta_from_source_str(~"cfgspec", @s, ~[], sess)
}
return meta;
}

pub enum input {
Expand Down Expand Up @@ -566,9 +563,9 @@ pub fn build_session_options(+binary: ~str,
let debug_map = session::debugging_opts_map();
for debug_flags.each |debug_flag| {
let mut this_bit = 0u;
for debug_map.each |pair| {
let (name, _, bit) = /*bad*/copy *pair;
if name == *debug_flag { this_bit = bit; break; }
for debug_map.each |tuple| {
let (name, bit) = match *tuple { (ref a, _, b) => (a, b) };
if name == debug_flag { this_bit = bit; break; }
}
if this_bit == 0u {
early_error(demitter, fmt!("unknown debug flag: %s", *debug_flag))
Expand Down Expand Up @@ -633,7 +630,7 @@ pub fn build_session_options(+binary: ~str,
let target =
match target_opt {
None => host_triple(),
Some(ref s) => (/*bad*/copy *s)
Some(s) => s
};

let addl_lib_search_paths =
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ pub struct TargetData {
dtor: @target_data_res
}

pub fn mk_target_data(string_rep: ~str) -> TargetData {
pub fn mk_target_data(string_rep: &str) -> TargetData {
let lltd =
str::as_c_str(string_rep, |buf| unsafe {
llvm::LLVMCreateTargetData(buf)
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ fn visit_crate(e: @mut Env, c: ast::crate) {
}

fn visit_view_item(e: @mut Env, i: @ast::view_item) {
match /*bad*/copy i.node {
ast::view_item_extern_mod(ident, meta_items, id) => {
match i.node {
ast::view_item_extern_mod(ident, /*bad*/copy meta_items, id) => {
debug!("resolving extern mod stmt. ident: %?, meta: %?",
ident, meta_items);
let cnum = resolve_crate(e, ident, meta_items, @~"", i.span);
Expand All @@ -154,8 +154,8 @@ fn visit_view_item(e: @mut Env, i: @ast::view_item) {
}

fn visit_item(e: @mut Env, i: @ast::item) {
match /*bad*/copy i.node {
ast::item_foreign_mod(fm) => {
match i.node {
ast::item_foreign_mod(ref fm) => {
match attr::foreign_abi(i.attrs) {
either::Right(abi) => {
if abi != ast::foreign_abi_cdecl &&
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
debug!("encoding info for item at %s",
ecx.tcx.sess.codemap.span_to_str(item.span));

match /*bad*/copy item.node {
match item.node {
item_const(_, _) => {
add_to_index();
ebml_w.start_tag(tag_items_data_item);
Expand Down Expand Up @@ -1189,10 +1189,10 @@ fn synthesize_crate_attrs(ecx: @EncodeContext,
if *attr::get_attr_name(attr) != ~"link" {
/*bad*/copy *attr
} else {
match /*bad*/copy attr.node.value.node {
meta_list(_, l) => {
match attr.node.value.node {
meta_list(_, ref l) => {
found_link_attr = true;;
synthesize_link_attr(ecx, l)
synthesize_link_attr(ecx, /*bad*/copy *l)
}
_ => /*bad*/copy *attr
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,14 @@ fn encode_vtable_origin(ecx: @e::EncodeContext,
ebml_w: writer::Encoder,
vtable_origin: typeck::vtable_origin) {
do ebml_w.emit_enum(~"vtable_origin") {
match /*bad*/copy vtable_origin {
typeck::vtable_static(def_id, tys, vtable_res) => {
match vtable_origin {
typeck::vtable_static(def_id, ref tys, vtable_res) => {
do ebml_w.emit_enum_variant(~"vtable_static", 0u, 3u) {
do ebml_w.emit_enum_variant_arg(0u) {
ebml_w.emit_def_id(def_id)
}
do ebml_w.emit_enum_variant_arg(1u) {
ebml_w.emit_tys(ecx, /*bad*/copy tys);
ebml_w.emit_tys(ecx, /*bad*/copy *tys);
}
do ebml_w.emit_enum_variant_arg(2u) {
encode_vtable_res(ecx, ebml_w, vtable_res);
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/borrowck/gather_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn req_loans_in_expr(ex: @ast::expr,
}

// Special checks for various kinds of expressions:
match /*bad*/copy ex.node {
match ex.node {
ast::expr_addr_of(mutbl, base) => {
let base_cmt = self.bccx.cat_expr(base);

Expand All @@ -150,10 +150,10 @@ fn req_loans_in_expr(ex: @ast::expr,
visit::visit_expr(ex, self, vt);
}

ast::expr_call(f, args, _) => {
ast::expr_call(f, ref args, _) => {
let arg_tys = ty::ty_fn_args(ty::expr_ty(self.tcx(), f));
let scope_r = ty::re_scope(ex.id);
for vec::each2(args, arg_tys) |arg, arg_ty| {
for vec::each2(*args, arg_tys) |arg, arg_ty| {
match ty::resolved_mode(self.tcx(), arg_ty.mode) {
ast::by_ref => {
let arg_cmt = self.bccx.cat_expr(*arg);
Expand All @@ -165,11 +165,11 @@ fn req_loans_in_expr(ex: @ast::expr,
visit::visit_expr(ex, self, vt);
}

ast::expr_method_call(rcvr, _, _, args, _) => {
ast::expr_method_call(rcvr, _, _, ref args, _) => {
let arg_tys = ty::ty_fn_args(ty::node_id_to_type(self.tcx(),
ex.callee_id));
let scope_r = ty::re_scope(ex.id);
for vec::each2(args, arg_tys) |arg, arg_ty| {
for vec::each2(*args, arg_tys) |arg, arg_ty| {
match ty::resolved_mode(self.tcx(), arg_ty.mode) {
ast::by_ref => {
let arg_cmt = self.bccx.cat_expr(*arg);
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ pub fn is_useful(cx: @MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful {
}
ty::ty_unboxed_vec(*) | ty::ty_evec(*) => {
let max_len = do m.foldr(0) |r, max_len| {
match /*bad*/copy r[0].node {
pat_vec(before, _, after) => {
match r[0].node {
pat_vec(ref before, _, ref after) => {
uint::max(before.len() + after.len(), max_len)
}
_ => max_len
Expand Down Expand Up @@ -299,7 +299,7 @@ pub fn is_useful_specialized(cx: @MatchCheckCtxt,

pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
let pat = raw_pat(p);
match /*bad*/copy pat.node {
match pat.node {
pat_wild => { None }
pat_ident(_, _, _) | pat_enum(_, _) => {
match cx.tcx.def_map.find(&pat.id) {
Expand All @@ -324,7 +324,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
pat_box(_) | pat_uniq(_) | pat_tup(_) | pat_region(*) => {
Some(single)
}
pat_vec(before, slice, after) => {
pat_vec(ref before, slice, ref after) => {
match slice {
Some(_) => None,
None => Some(vec(before.len() + after.len()))
Expand Down Expand Up @@ -448,8 +448,8 @@ pub fn missing_ctor(cx: @MatchCheckCtxt,
}

pub fn ctor_arity(cx: @MatchCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
match /*bad*/copy ty::get(ty).sty {
ty::ty_tup(fs) => fs.len(),
match ty::get(ty).sty {
ty::ty_tup(ref fs) => fs.len(),
ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_rptr(*) => 1u,
ty::ty_enum(eid, _) => {
let id = match ctor { variant(id) => id,
Expand Down Expand Up @@ -704,7 +704,7 @@ pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
_ => ()
}

match /*bad*/copy pat.node {
match pat.node {
pat_box(sub) | pat_uniq(sub) | pat_region(sub) |
pat_ident(_, _, Some(sub)) => {
is_refutable(cx, sub)
Expand All @@ -715,13 +715,13 @@ pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
false
}
pat_lit(_) | pat_range(_, _) => { true }
pat_struct(_, fields, _) => {
pat_struct(_, ref fields, _) => {
fields.any(|f| is_refutable(cx, f.pat))
}
pat_tup(elts) => {
pat_tup(ref elts) => {
elts.any(|elt| is_refutable(cx, *elt))
}
pat_enum(_, Some(args)) => {
pat_enum(_, Some(ref args)) => {
args.any(|a| is_refutable(cx, *a))
}
pat_enum(_,_) => { false }
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn classify(e: @expr,
Some(x) => x,
None => {
let cn =
match /*bad*/copy e.node {
match e.node {
ast::expr_lit(lit) => {
match lit.node {
ast::lit_str(*) |
Expand All @@ -101,9 +101,9 @@ pub fn classify(e: @expr,
classify(b, def_map, tcx))
}

ast::expr_tup(es) |
ast::expr_vec(es, ast::m_imm) => {
join_all(vec::map(es, |e| classify(*e, def_map, tcx)))
ast::expr_tup(ref es) |
ast::expr_vec(ref es, ast::m_imm) => {
join_all(vec::map(*es, |e| classify(*e, def_map, tcx)))
}

ast::expr_vstore(e, vstore) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/freevars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn collect_freevars(def_map: resolve::DefMap, blk: &ast::blk)
Some(df) => {
let mut def = df;
while i < depth {
match copy def {
match def {
ast::def_upvar(_, inner, _, _) => { def = *inner; }
_ => break
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ pub impl Context {
let metas =
attr::attr_metas(attr::find_attrs_by_name(attrs, level_name));
for metas.each |meta| {
match /*bad*/copy meta.node {
ast::meta_list(_, metas) => {
match meta.node {
ast::meta_list(_, ref metas) => {
for metas.each |meta| {
match meta.node {
ast::meta_word(ref lintname) => {
Expand Down Expand Up @@ -653,8 +653,8 @@ fn check_item_type_limits(cx: ty::ctxt, it: @ast::item) {
}

fn check_item_default_methods(cx: ty::ctxt, item: @ast::item) {
match /*bad*/copy item.node {
ast::item_trait(_, _, methods) => {
match item.node {
ast::item_trait(_, _, ref methods) => {
for methods.each |method| {
match *method {
ast::required(*) => {}
Expand Down
Loading