Skip to content

Commit b653a18

Browse files
committed
add mut decls to rustc and make them mandatory
1 parent d7be4ab commit b653a18

Some content is hidden

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

70 files changed

+956
-924
lines changed

mk/target.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ $$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X): \
5353
$$(RUSTC_INPUTS) \
5454
$$(TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3))
5555
@$$(call E, compile_and_link: $$@)
56-
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$<
56+
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(ENFORCE_MUT_VARS_$(1)) \
57+
-o $$@ $$<
5758

5859
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \
5960
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
@@ -62,7 +63,8 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \
6263
$$(TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3)) \
6364
$$(TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3))
6465
@$$(call E, compile_and_link: $$@)
65-
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
66+
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(ENFORCE_MUT_VARS_$(1)) \
67+
-o $$@ $$< && touch $$@
6668

6769
endef
6870

src/rustc/back/link.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ mod write {
116116
let opts = sess.opts;
117117
if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
118118
link_intrinsics(sess, llmod);
119-
let pm = mk_pass_manager();
119+
let mut pm = mk_pass_manager();
120120
let td = mk_target_data(
121121
sess.targ_cfg.target_strs.data_layout);
122122
llvm::LLVMAddTargetData(td.lltd, pm.llpm);
@@ -165,7 +165,7 @@ mod write {
165165
llvm::LLVMPassManagerBuilderDispose(FPMB);
166166

167167
llvm::LLVMRunPassManager(fpm.llpm, llmod);
168-
let threshold = 225u;
168+
let mut threshold = 225u;
169169
if opts.optimize == 3u { threshold = 275u; }
170170

171171
let MPMB = llvm::LLVMPassManagerBuilderCreate();
@@ -195,15 +195,15 @@ mod write {
195195
let LLVMOptDefault = 2 as c_int; // -O2, -Os
196196
let LLVMOptAggressive = 3 as c_int; // -O3
197197

198-
let CodeGenOptLevel;
198+
let mut CodeGenOptLevel;
199199
alt check opts.optimize {
200200
0u { CodeGenOptLevel = LLVMOptNone; }
201201
1u { CodeGenOptLevel = LLVMOptLess; }
202202
2u { CodeGenOptLevel = LLVMOptDefault; }
203203
3u { CodeGenOptLevel = LLVMOptAggressive; }
204204
}
205205

206-
let FileType;
206+
let mut FileType;
207207
if opts.output_type == output_type_object ||
208208
opts.output_type == output_type_exe {
209209
FileType = LLVMObjectFile;
@@ -362,9 +362,9 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
362362

363363
fn provided_link_metas(sess: session, c: ast::crate) ->
364364
provided_metas {
365-
let name: option<str> = none;
366-
let vers: option<str> = none;
367-
let cmh_items: [@ast::meta_item] = [];
365+
let mut name: option<str> = none;
366+
let mut vers: option<str> = none;
367+
let mut cmh_items: [@ast::meta_item] = [];
368368
let linkage_metas = attr::find_linkage_metas(c.node.attrs);
369369
attr::require_unique_names(sess, linkage_metas);
370370
for meta: @ast::meta_item in linkage_metas {
@@ -433,7 +433,8 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
433433
none {
434434
let name =
435435
{
436-
let os = str::split_char(path::basename(output), '.');
436+
let mut os =
437+
str::split_char(path::basename(output), '.');
437438
if (vec::len(os) < 2u) {
438439
sess.fatal(#fmt("output file name %s doesn't\
439440
appear to have an extension", output));
@@ -494,7 +495,7 @@ fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t, link_meta: link_meta) ->
494495
}
495496

496497
fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> str {
497-
let hash = "";
498+
let mut hash = "";
498499
alt ccx.type_sha1s.find(t) {
499500
some(h) { hash = h; }
500501
none {
@@ -509,7 +510,7 @@ fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> str {
509510
// Name sanitation. LLVM will happily accept identifiers with weird names, but
510511
// gas doesn't!
511512
fn sanitize(s: str) -> str {
512-
let result = "";
513+
let mut result = "";
513514
str::chars_iter(s) {|c|
514515
alt c {
515516
'@' { result += "_sbox_"; }
@@ -536,7 +537,7 @@ fn sanitize(s: str) -> str {
536537
fn mangle(ss: path) -> str {
537538
// Follow C++ namespace-mangling style
538539

539-
let n = "_ZN"; // Begin name-sequence.
540+
let mut n = "_ZN"; // Begin name-sequence.
540541

541542
for s in ss {
542543
alt s { path_name(s) | path_mod(s) {
@@ -597,7 +598,7 @@ fn link_binary(sess: session,
597598
} else { ret filename; }
598599
};
599600
fn rmext(filename: str) -> str {
600-
let parts = str::split_char(filename, '.');
601+
let mut parts = str::split_char(filename, '.');
601602
vec::pop(parts);
602603
ret str::connect(parts, ".");
603604
}
@@ -636,11 +637,11 @@ fn link_binary(sess: session,
636637
if sess.targ_cfg.os == session::os_win32 { "gcc" } else { "cc" };
637638
// The invocations of cc share some flags across platforms
638639

639-
let cc_args =
640+
let mut cc_args =
640641
[stage] + sess.targ_cfg.target_strs.cc_args +
641642
["-o", output, obj_filename];
642643

643-
let lib_cmd;
644+
let mut lib_cmd;
644645
let os = sess.targ_cfg.os;
645646
if os == session::os_macos {
646647
lib_cmd = "-dynamiclib";

src/rustc/back/rpath.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,13 @@ fn get_relative_to(abs1: path::path, abs2: path::path) -> path::path {
130130
assert len2 > 0u;
131131

132132
let max_common_path = uint::min(len1, len2) - 1u;
133-
let start_idx = 0u;
133+
let mut start_idx = 0u;
134134
while start_idx < max_common_path
135135
&& split1[start_idx] == split2[start_idx] {
136136
start_idx += 1u;
137137
}
138138

139-
let path = [];
140-
139+
let mut path = [];
141140
uint::range(start_idx, len1 - 1u) {|_i| path += [".."]; };
142141

143142
path += vec::slice(split2, start_idx, len2 - 1u);
@@ -179,7 +178,7 @@ fn get_install_prefix_rpath(cwd: path::path, target_triple: str) -> str {
179178

180179
fn minimize_rpaths(rpaths: [str]) -> [str] {
181180
let set = map::str_hash::<()>();
182-
let minimized = [];
181+
let mut minimized = [];
183182
for rpath in rpaths {
184183
if !set.contains_key(rpath) {
185184
minimized += [rpath];

src/rustc/back/upcall.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn declare_upcalls(targ_cfg: @session::config,
3434
fn decl(llmod: ModuleRef, prefix: str, name: str,
3535
tys: [TypeRef], rv: TypeRef) ->
3636
ValueRef {
37-
let arg_tys: [TypeRef] = [];
37+
let mut arg_tys: [TypeRef] = [];
3838
for t: TypeRef in tys { arg_tys += [t]; }
3939
let fn_ty = T_fn(arg_tys, rv);
4040
ret base::decl_cdecl_fn(llmod, prefix + name, fn_ty);

src/rustc/driver/diagnostic.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
195195

196196
// arbitrarily only print up to six lines of the error
197197
let max_lines = 6u;
198-
let elided = false;
199-
let display_lines = lines.lines;
198+
let mut elided = false;
199+
let mut display_lines = lines.lines;
200200
if vec::len(display_lines) > max_lines {
201201
display_lines = vec::slice(display_lines, 0u, max_lines);
202202
elided = true;
@@ -210,8 +210,8 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
210210
if elided {
211211
let last_line = display_lines[vec::len(display_lines) - 1u];
212212
let s = #fmt["%s:%u ", fm.name, last_line + 1u];
213-
let indent = str::len(s);
214-
let out = "";
213+
let mut indent = str::len(s);
214+
let mut out = "";
215215
while indent > 0u { out += " "; indent -= 1u; }
216216
out += "...\n";
217217
io::stderr().write_str(out);
@@ -221,22 +221,22 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
221221
// If there's one line at fault we can easily point to the problem
222222
if vec::len(lines.lines) == 1u {
223223
let lo = codemap::lookup_char_pos(cm, sp.lo);
224-
let digits = 0u;
225-
let num = (lines.lines[0] + 1u) / 10u;
224+
let mut digits = 0u;
225+
let mut num = (lines.lines[0] + 1u) / 10u;
226226

227227
// how many digits must be indent past?
228228
while num > 0u { num /= 10u; digits += 1u; }
229229

230230
// indent past |name:## | and the 0-offset column location
231-
let left = str::len(fm.name) + digits + lo.col + 3u;
232-
let s = "";
231+
let mut left = str::len(fm.name) + digits + lo.col + 3u;
232+
let mut s = "";
233233
while left > 0u { str::push_char(s, ' '); left -= 1u; }
234234

235235
s += "^";
236236
let hi = codemap::lookup_char_pos(cm, sp.hi);
237237
if hi.col != lo.col {
238238
// the ^ already takes up one space
239-
let width = hi.col - lo.col - 1u;
239+
let mut width = hi.col - lo.col - 1u;
240240
while width > 0u { str::push_char(s, '~'); width -= 1u; }
241241
}
242242
io::stderr().write_str(s + "\n");

src/rustc/driver/driver.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn build_configuration(sess: session, argv0: str, input: str) ->
6666
fn parse_cfgspecs(cfgspecs: [str]) -> ast::crate_cfg {
6767
// FIXME: It would be nice to use the parser to parse all varieties of
6868
// meta_item here. At the moment we just support the meta_word variant.
69-
let words = [];
69+
let mut words = [];
7070
for s: str in cfgspecs { words += [attr::mk_word_item(s)]; }
7171
ret words;
7272
}
@@ -106,8 +106,8 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
106106
outputs: option<output_filenames>)
107107
-> {crate: @ast::crate, tcx: option<ty::ctxt>} {
108108
let time_passes = sess.opts.time_passes;
109-
let crate = time(time_passes, "parsing",
110-
bind parse_input(sess, cfg, input));
109+
let mut crate = time(time_passes, "parsing",
110+
bind parse_input(sess, cfg, input));
111111
if upto == cu_parse { ret {crate: crate, tcx: none}; }
112112

113113
sess.building_library = session::building_library(
@@ -261,7 +261,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str,
261261
};
262262
let {crate, tcx} = compile_upto(sess, cfg, input, upto, none);
263263

264-
let ann: pprust::pp_ann = pprust::no_ann();
264+
let mut ann: pprust::pp_ann = pprust::no_ann();
265265
alt ppm {
266266
ppm_typed {
267267
ann = {pre: ann_paren_for_expr,
@@ -362,7 +362,7 @@ fn build_session_options(match: getopts::match,
362362

363363
let parse_only = opt_present(match, "parse-only");
364364
let no_trans = opt_present(match, "no-trans");
365-
let lint_opts = [];
365+
let mut lint_opts = [];
366366
if opt_present(match, "no-lint-ctypes") {
367367
lint_opts += [(lint::ctypes, false)];
368368
}
@@ -388,7 +388,7 @@ fn build_session_options(match: getopts::match,
388388
let time_llvm_passes = opt_present(match, "time-llvm-passes");
389389
let sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
390390
let target_opt = getopts::opt_maybe_str(match, "target");
391-
let no_asm_comments = getopts::opt_present(match, "no-asm-comments");
391+
let mut no_asm_comments = getopts::opt_present(match, "no-asm-comments");
392392
alt output_type {
393393
// unless we're emitting huamn-readable assembly, omit comments.
394394
link::output_type_llvm_assembly | link::output_type_assembly {}
@@ -531,8 +531,8 @@ fn build_output_filenames(ifile: str,
531531
ofile: option<str>,
532532
sess: session)
533533
-> output_filenames {
534-
let obj_path = "";
535-
let out_path: str = "";
534+
let mut obj_path = "";
535+
let mut out_path: str = "";
536536
let sopts = sess.opts;
537537
let stop_after_codegen =
538538
sopts.output_type != link::output_type_exe ||

src/rustc/driver/rustc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import rustc::syntax::codemap;
1111
import rustc::driver::diagnostic;
1212

1313
fn version(argv0: str) {
14-
let vers = "unknown version";
14+
let mut vers = "unknown version";
1515
let env_vers = #env["CFG_VERSION"];
1616
if str::len(env_vers) != 0u { vers = env_vers; }
1717
io::stdout().write_str(#fmt["%s %s\n", argv0, vers]);
@@ -73,7 +73,8 @@ fn run_compiler(args: [str], demitter: diagnostic::emitter) {
7373
// Don't display log spew by default. Can override with RUST_LOG.
7474
logging::console_off();
7575

76-
let args = args, binary = vec::shift(args);
76+
let mut args = args;
77+
let binary = vec::shift(args);
7778

7879
if vec::len(args) == 0u { usage(binary); ret; }
7980

src/rustc/front/attr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export native_abi;
3737
// From a list of crate attributes get only the meta_items that impact crate
3838
// linkage
3939
fn find_linkage_metas(attrs: [ast::attribute]) -> [@ast::meta_item] {
40-
let metas: [@ast::meta_item] = [];
40+
let mut metas: [@ast::meta_item] = [];
4141
for attr: ast::attribute in find_attrs_by_name(attrs, "link") {
4242
alt attr.node.value.node {
4343
ast::meta_list(_, items) { metas += items; }
@@ -141,7 +141,7 @@ fn attr_meta(attr: ast::attribute) -> @ast::meta_item { @attr.node.value }
141141

142142
// Get the meta_items from inside a vector of attributes
143143
fn attr_metas(attrs: [ast::attribute]) -> [@ast::meta_item] {
144-
let mitems = [];
144+
let mut mitems = [];
145145
for a: ast::attribute in attrs { mitems += [attr_meta(a)]; }
146146
ret mitems;
147147
}
@@ -198,12 +198,12 @@ fn sort_meta_items(items: [@ast::meta_item]) -> [@ast::meta_item] {
198198
}
199199

200200
// This is sort of stupid here, converting to a vec of mutables and back
201-
let v: [mutable @ast::meta_item] = [mutable];
201+
let mut v: [mutable @ast::meta_item] = [mutable];
202202
for mi: @ast::meta_item in items { v += [mutable mi]; }
203203

204204
std::sort::quick_sort(lteq, v);
205205

206-
let v2: [@ast::meta_item] = [];
206+
let mut v2: [@ast::meta_item] = [];
207207
for mi: @ast::meta_item in v { v2 += [mi]; }
208208
ret v2;
209209
}

src/rustc/front/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty {
267267

268268
fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
269269
#debug("building test vector from %u tests", vec::len(cx.testfns));
270-
let descs = [];
270+
let mut descs = [];
271271
for test: test in cx.testfns {
272272
let test_ = test; // Satisfy alias analysis
273273
descs += [mk_test_desc_rec(cx, test_)];

src/rustc/lib/llvm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,8 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
965965
let kind: int = llvm::LLVMGetTypeKind(ty) as int;
966966

967967
fn tys_str(names: type_names, outer: [TypeRef], tys: [TypeRef]) -> str {
968-
let s: str = "";
969-
let first: bool = true;
968+
let mut s: str = "";
969+
let mut first: bool = true;
970970
for t: TypeRef in tys {
971971
if first { first = false; } else { s += ", "; }
972972
s += type_to_str_inner(names, outer, t);
@@ -989,7 +989,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
989989
ret "i" + int::str(llvm::LLVMGetIntTypeWidth(ty) as int);
990990
}
991991
9 {
992-
let s = "fn(";
992+
let mut s = "fn(";
993993
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
994994
let n_args = llvm::LLVMCountParamTypes(ty) as uint;
995995
let args: [TypeRef] = vec::from_elem::<TypeRef>(n_args, 0 as TypeRef);
@@ -1002,7 +1002,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
10021002
ret s;
10031003
}
10041004
10 {
1005-
let s: str = "{";
1005+
let mut s: str = "{";
10061006
let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
10071007
let elts: [TypeRef] = vec::from_elem::<TypeRef>(n_elts, 0 as TypeRef);
10081008
unsafe {
@@ -1018,7 +1018,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
10181018
uint::str(llvm::LLVMGetArrayLength(ty) as uint) + "]";
10191019
}
10201020
12 {
1021-
let i: uint = 0u;
1021+
let mut i: uint = 0u;
10221022
for tout: TypeRef in outer0 {
10231023
i += 1u;
10241024
if tout as int == ty as int {

src/rustc/metadata/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ enum astencode_tag { // Reserves 0x50 -- 0x6f
109109
fn hash_node_id(&&node_id: int) -> uint { ret 177573u ^ (node_id as uint); }
110110

111111
fn hash_path(&&s: str) -> uint {
112-
let h = 5381u;
112+
let mut h = 5381u;
113113
for ch: u8 in str::bytes(s) { h = (h << 5u) + h ^ (ch as uint); }
114114
ret h;
115115
}

src/rustc/metadata/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn visit_item(e: env, i: @ast::item) {
6868
}
6969
none { i.ident }
7070
};
71-
let already_added = false;
71+
let mut already_added = false;
7272
if vec::len(attr::find_attrs_by_name(i.attrs, "nolink")) == 0u {
7373
already_added = !cstore::add_used_library(cstore, native_name);
7474
}

0 commit comments

Comments
 (0)