Skip to content

Commit 403e869

Browse files
committed
auto merge of #13053 : alexcrichton/rust/removing-ref-cell-get, r=huonw
This commit removes the `get()` method from `Ref` and `RefMut` in favor of the `*` operator, and removes all usage of the `deref()` function manually from rustc, favoring using `*` instead. Some of the code is a little wacky, but that's due to either #13044 or #13042
2 parents 5e8e1b5 + 9dc357b commit 403e869

Some content is hidden

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

107 files changed

+1587
-2639
lines changed

src/libarena/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ struct Chunk {
5454
}
5555
impl Chunk {
5656
fn capacity(&self) -> uint {
57-
self.data.deref().borrow().get().capacity()
57+
self.data.borrow().capacity()
5858
}
5959

6060
unsafe fn as_ptr(&self) -> *u8 {
61-
self.data.deref().borrow().get().as_ptr()
61+
self.data.borrow().as_ptr()
6262
}
6363
}
6464

src/librustc/back/archive.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,8 @@ impl<'a> Archive<'a> {
206206

207207
let mut rustpath = filesearch::rust_path();
208208
rustpath.push(self.sess.filesearch().get_target_lib_path());
209-
let addl_lib_search_paths = self.sess
210-
.opts
211-
.addl_lib_search_paths
212-
.borrow();
213-
let path = addl_lib_search_paths.get().iter();
214-
for path in path.chain(rustpath.iter()) {
209+
let search = self.sess.opts.addl_lib_search_paths.borrow();
210+
for path in search.iter().chain(rustpath.iter()) {
215211
debug!("looking for {} inside {}", name, path.display());
216212
let test = path.join(oslibname.as_slice());
217213
if test.exists() { return test }

src/librustc/back/link.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,8 @@ pub mod write {
209209
// Emit the bytecode if we're either saving our temporaries or
210210
// emitting an rlib. Whenever an rlib is created, the bytecode is
211211
// inserted into the archive in order to allow LTO against it.
212-
let crate_types = sess.crate_types.borrow();
213212
if sess.opts.cg.save_temps ||
214-
(crate_types.get().contains(&session::CrateTypeRlib) &&
213+
(sess.crate_types.borrow().contains(&session::CrateTypeRlib) &&
215214
sess.opts.output_types.contains(&OutputTypeExe)) {
216215
output.temp_path(OutputTypeBitcode).with_c_str(|buf| {
217216
llvm::LLVMWriteBitcodeToFile(llmod, buf);
@@ -550,15 +549,14 @@ fn symbol_hash(tcx: &ty::ctxt, symbol_hasher: &mut Sha256,
550549
}
551550

552551
fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> ~str {
553-
match ccx.type_hashcodes.borrow().get().find(&t) {
552+
match ccx.type_hashcodes.borrow().find(&t) {
554553
Some(h) => return h.to_str(),
555554
None => {}
556555
}
557556

558-
let mut type_hashcodes = ccx.type_hashcodes.borrow_mut();
559557
let mut symbol_hasher = ccx.symbol_hasher.borrow_mut();
560-
let hash = symbol_hash(ccx.tcx(), symbol_hasher.get(), t, &ccx.link_meta);
561-
type_hashcodes.get().insert(t, hash.clone());
558+
let hash = symbol_hash(ccx.tcx(), &mut *symbol_hasher, t, &ccx.link_meta);
559+
ccx.type_hashcodes.borrow_mut().insert(t, hash.clone());
562560
hash
563561
}
564562

@@ -779,8 +777,7 @@ pub fn link_binary(sess: &Session,
779777
outputs: &OutputFilenames,
780778
id: &CrateId) -> Vec<Path> {
781779
let mut out_filenames = Vec::new();
782-
let crate_types = sess.crate_types.borrow();
783-
for &crate_type in crate_types.get().iter() {
780+
for &crate_type in sess.crate_types.borrow().iter() {
784781
let out_file = link_binary_output(sess, trans, crate_type, outputs, id);
785782
out_filenames.push(out_file);
786783
}
@@ -887,9 +884,7 @@ fn link_rlib<'a>(sess: &'a Session,
887884
out_filename: &Path) -> Archive<'a> {
888885
let mut a = Archive::create(sess, out_filename, obj_filename);
889886

890-
let used_libraries = sess.cstore.get_used_libraries();
891-
let used_libraries = used_libraries.borrow();
892-
for &(ref l, kind) in used_libraries.get().iter() {
887+
for &(ref l, kind) in sess.cstore.get_used_libraries().borrow().iter() {
893888
match kind {
894889
cstore::NativeStatic => {
895890
a.add_native_library(l.as_slice()).unwrap();
@@ -1227,9 +1222,7 @@ fn link_args(sess: &Session,
12271222
// Finally add all the linker arguments provided on the command line along
12281223
// with any #[link_args] attributes found inside the crate
12291224
args.push_all(sess.opts.cg.link_args.as_slice());
1230-
let used_link_args = sess.cstore.get_used_link_args();
1231-
let used_link_args = used_link_args.borrow();
1232-
for arg in used_link_args.get().iter() {
1225+
for arg in sess.cstore.get_used_link_args().borrow().iter() {
12331226
args.push(arg.clone());
12341227
}
12351228
return args;
@@ -1247,8 +1240,7 @@ fn link_args(sess: &Session,
12471240
// in the current crate. Upstream crates with native library dependencies
12481241
// may have their native library pulled in above.
12491242
fn add_local_native_libraries(args: &mut Vec<~str>, sess: &Session) {
1250-
let addl_lib_search_paths = sess.opts.addl_lib_search_paths.borrow();
1251-
for path in addl_lib_search_paths.get().iter() {
1243+
for path in sess.opts.addl_lib_search_paths.borrow().iter() {
12521244
// FIXME (#9639): This needs to handle non-utf8 paths
12531245
args.push("-L" + path.as_str().unwrap().to_owned());
12541246
}
@@ -1259,9 +1251,7 @@ fn add_local_native_libraries(args: &mut Vec<~str>, sess: &Session) {
12591251
args.push("-L" + path.as_str().unwrap().to_owned());
12601252
}
12611253

1262-
let used_libraries = sess.cstore.get_used_libraries();
1263-
let used_libraries = used_libraries.borrow();
1264-
for &(ref l, kind) in used_libraries.get().iter() {
1254+
for &(ref l, kind) in sess.cstore.get_used_libraries().borrow().iter() {
12651255
match kind {
12661256
cstore::NativeUnknown | cstore::NativeStatic => {
12671257
args.push("-l" + *l);

src/librustc/back/lto.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
2727
}
2828

2929
// Make sure we actually can run LTO
30-
let crate_types = sess.crate_types.borrow();
31-
for crate_type in crate_types.get().iter() {
30+
for crate_type in sess.crate_types.borrow().iter() {
3231
match *crate_type {
3332
session::CrateTypeExecutable | session::CrateTypeStaticlib => {}
3433
_ => {

src/librustc/driver/driver.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,7 @@ fn write_out_deps(sess: &Session,
512512
let file = outputs.path(*output_type);
513513
match *output_type {
514514
link::OutputTypeExe => {
515-
let crate_types = sess.crate_types.borrow();
516-
for output in crate_types.get().iter() {
515+
for output in sess.crate_types.borrow().iter() {
517516
let p = link::filename_for_input(sess, *output, &id, &file);
518517
out_filenames.push(p);
519518
}
@@ -542,10 +541,10 @@ fn write_out_deps(sess: &Session,
542541

543542
// Build a list of files used to compile the output and
544543
// write Makefile-compatible dependency rules
545-
let files: Vec<~str> = sess.codemap().files.borrow().get()
544+
let files: Vec<~str> = sess.codemap().files.borrow()
546545
.iter().filter_map(|fmap| {
547-
if fmap.deref().is_real_file() {
548-
Some(fmap.deref().name.clone())
546+
if fmap.is_real_file() {
547+
Some(fmap.name.clone())
549548
} else {
550549
None
551550
}
@@ -683,7 +682,7 @@ pub fn pretty_print_input(sess: Session,
683682
};
684683

685684
let src_name = source_name(input);
686-
let src = sess.codemap().get_filemap(src_name).deref().src.as_bytes().to_owned();
685+
let src = sess.codemap().get_filemap(src_name).src.as_bytes().to_owned();
687686
let mut rdr = MemReader::new(src);
688687

689688
match ppm {

src/librustc/driver/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ impl Session {
253253
sp: Span,
254254
msg: ~str) {
255255
let mut lints = self.lints.borrow_mut();
256-
match lints.get().find_mut(&id) {
256+
match lints.find_mut(&id) {
257257
Some(arr) => { arr.push((lint, sp, msg)); return; }
258258
None => {}
259259
}
260-
lints.get().insert(id, vec!((lint, sp, msg)));
260+
lints.insert(id, vec!((lint, sp, msg)));
261261
}
262262
pub fn next_node_id(&self) -> ast::NodeId {
263263
self.reserve_node_ids(1)

src/librustc/front/test.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
8888
}
8989

9090
fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> {
91-
{
92-
let mut path = self.cx.path.borrow_mut();
93-
path.get().push(i.ident);
94-
}
91+
self.cx.path.borrow_mut().push(i.ident);
9592
debug!("current path: {}",
9693
ast_util::path_name_i(self.cx.path.get().as_slice()));
9794

@@ -112,21 +109,15 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
112109
ignore: is_ignored(&self.cx, i),
113110
should_fail: should_fail(i)
114111
};
115-
{
116-
let mut testfns = self.cx.testfns.borrow_mut();
117-
testfns.get().push(test);
118-
}
112+
self.cx.testfns.borrow_mut().push(test);
119113
// debug!("have {} test/bench functions",
120114
// cx.testfns.len());
121115
}
122116
}
123117
}
124118

125119
let res = fold::noop_fold_item(i, self);
126-
{
127-
let mut path = self.cx.path.borrow_mut();
128-
path.get().pop();
129-
}
120+
self.cx.path.borrow_mut().pop();
130121
res
131122
}
132123

@@ -414,12 +405,9 @@ fn is_test_crate(krate: &ast::Crate) -> bool {
414405

415406
fn mk_test_descs(cx: &TestCtxt) -> @ast::Expr {
416407
let mut descs = Vec::new();
417-
{
418-
let testfns = cx.testfns.borrow();
419-
debug!("building test vector from {} tests", testfns.get().len());
420-
for test in testfns.get().iter() {
421-
descs.push(mk_test_desc_and_fn_rec(cx, test));
422-
}
408+
debug!("building test vector from {} tests", cx.testfns.borrow().len());
409+
for test in cx.testfns.borrow().iter() {
410+
descs.push(mk_test_desc_and_fn_rec(cx, test));
423411
}
424412

425413
let inner_expr = @ast::Expr {

src/librustc/lib/llvm.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,13 +1831,11 @@ impl TypeNames {
18311831
}
18321832

18331833
pub fn associate_type(&self, s: &str, t: &Type) {
1834-
let mut named_types = self.named_types.borrow_mut();
1835-
assert!(named_types.get().insert(s.to_owned(), t.to_ref()));
1834+
assert!(self.named_types.borrow_mut().insert(s.to_owned(), t.to_ref()));
18361835
}
18371836

18381837
pub fn find_type(&self, s: &str) -> Option<Type> {
1839-
let named_types = self.named_types.borrow();
1840-
named_types.get().find_equiv(&s).map(|x| Type::from_ref(*x))
1838+
self.named_types.borrow().find_equiv(&s).map(|x| Type::from_ref(*x))
18411839
}
18421840

18431841
pub fn type_to_str(&self, ty: Type) -> ~str {

src/librustc/metadata/creader.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ pub fn read_crates(sess: &Session,
5151
};
5252
visit_crate(&e, krate);
5353
visit::walk_crate(&mut e, krate, ());
54-
let crate_cache = e.crate_cache.borrow();
55-
dump_crates(crate_cache.get().as_slice());
54+
dump_crates(e.crate_cache.borrow().as_slice());
5655
warn_if_multiple_versions(&mut e,
5756
sess.diagnostic(),
58-
crate_cache.get().as_slice());
57+
e.crate_cache.borrow().as_slice());
5958
}
6059

6160
impl<'a> visit::Visitor<()> for Env<'a> {
@@ -268,8 +267,7 @@ fn visit_item(e: &Env, i: &ast::Item) {
268267

269268
fn existing_match(e: &Env, crate_id: &CrateId,
270269
hash: Option<&Svh>) -> Option<ast::CrateNum> {
271-
let crate_cache = e.crate_cache.borrow();
272-
for c in crate_cache.get().iter() {
270+
for c in e.crate_cache.borrow().iter() {
273271
if !crate_id.matches(&c.crate_id) { continue }
274272
match hash {
275273
Some(hash) if *hash != c.hash => {}
@@ -309,15 +307,12 @@ fn resolve_crate(e: &mut Env,
309307

310308
// Claim this crate number and cache it
311309
let cnum = e.next_crate_num;
312-
{
313-
let mut crate_cache = e.crate_cache.borrow_mut();
314-
crate_cache.get().push(cache_entry {
315-
cnum: cnum,
316-
span: span,
317-
hash: hash,
318-
crate_id: crate_id,
319-
});
320-
}
310+
e.crate_cache.borrow_mut().push(cache_entry {
311+
cnum: cnum,
312+
span: span,
313+
hash: hash,
314+
crate_id: crate_id,
315+
});
321316
e.next_crate_num += 1;
322317

323318
// Maintain a reference to the top most crate.

src/librustc/metadata/cstore.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ impl CStore {
8989
}
9090

9191
pub fn get_crate_data(&self, cnum: ast::CrateNum) -> @crate_metadata {
92-
let metas = self.metas.borrow();
93-
*metas.get().get(&cnum)
92+
*self.metas.borrow().get(&cnum)
9493
}
9594

9695
pub fn get_crate_hash(&self, cnum: ast::CrateNum) -> Svh {
@@ -104,33 +103,30 @@ impl CStore {
104103
}
105104

106105
pub fn set_crate_data(&self, cnum: ast::CrateNum, data: @crate_metadata) {
107-
let mut metas = self.metas.borrow_mut();
108-
metas.get().insert(cnum, data);
106+
self.metas.borrow_mut().insert(cnum, data);
109107
}
110108

111109
pub fn have_crate_data(&self, cnum: ast::CrateNum) -> bool {
112-
let metas = self.metas.borrow();
113-
metas.get().contains_key(&cnum)
110+
self.metas.borrow().contains_key(&cnum)
114111
}
115112

116113
pub fn iter_crate_data(&self, i: |ast::CrateNum, @crate_metadata|) {
117-
let metas = self.metas.borrow();
118-
for (&k, &v) in metas.get().iter() {
114+
for (&k, &v) in self.metas.borrow().iter() {
119115
i(k, v);
120116
}
121117
}
122118

123119
pub fn add_used_crate_source(&self, src: CrateSource) {
124120
let mut used_crate_sources = self.used_crate_sources.borrow_mut();
125-
if !used_crate_sources.get().contains(&src) {
126-
used_crate_sources.get().push(src);
121+
if !used_crate_sources.contains(&src) {
122+
used_crate_sources.push(src);
127123
}
128124
}
129125

130126
pub fn get_used_crate_source(&self, cnum: ast::CrateNum)
131127
-> Option<CrateSource> {
132-
let mut used_crate_sources = self.used_crate_sources.borrow_mut();
133-
used_crate_sources.get().iter().find(|source| source.cnum == cnum)
128+
self.used_crate_sources.borrow_mut()
129+
.iter().find(|source| source.cnum == cnum)
134130
.map(|source| source.clone())
135131
}
136132

@@ -158,18 +154,17 @@ impl CStore {
158154
ordering: &mut Vec<ast::CrateNum>) {
159155
if ordering.as_slice().contains(&cnum) { return }
160156
let meta = cstore.get_crate_data(cnum);
161-
for (_, &dep) in meta.cnum_map.borrow().get().iter() {
157+
for (_, &dep) in meta.cnum_map.borrow().iter() {
162158
visit(cstore, dep, ordering);
163159
}
164160
ordering.push(cnum);
165161
};
166-
for (&num, _) in self.metas.borrow().get().iter() {
162+
for (&num, _) in self.metas.borrow().iter() {
167163
visit(self, num, &mut ordering);
168164
}
169165
ordering.as_mut_slice().reverse();
170166
let ordering = ordering.as_slice();
171-
let used_crate_sources = self.used_crate_sources.borrow();
172-
let mut libs = used_crate_sources.get()
167+
let mut libs = self.used_crate_sources.borrow()
173168
.iter()
174169
.map(|src| (src.cnum, match prefer {
175170
RequireDynamic => src.dylib.clone(),
@@ -184,8 +179,7 @@ impl CStore {
184179

185180
pub fn add_used_library(&self, lib: ~str, kind: NativeLibaryKind) {
186181
assert!(!lib.is_empty());
187-
let mut used_libraries = self.used_libraries.borrow_mut();
188-
used_libraries.get().push((lib, kind));
182+
self.used_libraries.borrow_mut().push((lib, kind));
189183
}
190184

191185
pub fn get_used_libraries<'a>(&'a self)
@@ -194,9 +188,8 @@ impl CStore {
194188
}
195189

196190
pub fn add_used_link_args(&self, args: &str) {
197-
let mut used_link_args = self.used_link_args.borrow_mut();
198191
for s in args.split(' ') {
199-
used_link_args.get().push(s.to_owned());
192+
self.used_link_args.borrow_mut().push(s.to_owned());
200193
}
201194
}
202195

@@ -207,14 +200,12 @@ impl CStore {
207200
pub fn add_extern_mod_stmt_cnum(&self,
208201
emod_id: ast::NodeId,
209202
cnum: ast::CrateNum) {
210-
let mut extern_mod_crate_map = self.extern_mod_crate_map.borrow_mut();
211-
extern_mod_crate_map.get().insert(emod_id, cnum);
203+
self.extern_mod_crate_map.borrow_mut().insert(emod_id, cnum);
212204
}
213205

214206
pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId)
215207
-> Option<ast::CrateNum> {
216-
let extern_mod_crate_map = self.extern_mod_crate_map.borrow();
217-
extern_mod_crate_map.get().find(&emod_id).map(|x| *x)
208+
self.extern_mod_crate_map.borrow().find(&emod_id).map(|x| *x)
218209
}
219210
}
220211

0 commit comments

Comments
 (0)