diff options
| author | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-04-04 18:11:03 +0300 |
|---|---|---|
| committer | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-04-04 18:11:03 +0300 |
| commit | 60381cd9c29c51615975894e898b47da65f0b124 (patch) | |
| tree | e3a39a6c6839809d97253a878d26455955743c27 | |
| parent | 5309a3e31d88def1f3ea966162ed4f81f161d500 (diff) | |
| download | rust-60381cd9c29c51615975894e898b47da65f0b124.tar.gz rust-60381cd9c29c51615975894e898b47da65f0b124.zip | |
cstore: return an immutable borrow from `visible_parent_map`
Fixes #41053.
| -rw-r--r-- | src/librustc/middle/cstore.rs | 4 | ||||
| -rw-r--r-- | src/librustc_metadata/cstore_impl.rs | 16 | ||||
| -rw-r--r-- | src/test/run-pass/auxiliary/issue_41053.rs | 11 | ||||
| -rw-r--r-- | src/test/run-pass/issue-41053.rs | 30 |
4 files changed, 55 insertions, 6 deletions
diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 8bc0cf2577b..dd1941ba48a 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -172,7 +172,7 @@ pub trait CrateStore { fn stability(&self, def: DefId) -> Option<attr::Stability>; fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>; fn visibility(&self, def: DefId) -> ty::Visibility; - fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>>; + fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap<DefId>>; fn item_generics_cloned(&self, def: DefId) -> ty::Generics; fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>; fn fn_arg_names(&self, did: DefId) -> Vec<ast::Name>; @@ -302,7 +302,7 @@ impl CrateStore for DummyCrateStore { fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") } fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") } fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") } - fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>> { + fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap<DefId>> { bug!("visible_parent_map") } fn item_generics_cloned(&self, def: DefId) -> ty::Generics diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 41a2e8a8d55..b286cb8050e 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -507,12 +507,19 @@ impl CrateStore for cstore::CStore { /// Returns a map from a sufficiently visible external item (i.e. an external item that is /// visible from at least one local module) to a sufficiently visible parent (considering /// modules that re-export the external item to be parents). - fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>> { - let mut visible_parent_map = self.visible_parent_map.borrow_mut(); - if !visible_parent_map.is_empty() { return visible_parent_map; } + fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap<DefId>> { + { + let visible_parent_map = self.visible_parent_map.borrow(); + if !visible_parent_map.is_empty() { + return visible_parent_map; + } + } use std::collections::vec_deque::VecDeque; use std::collections::hash_map::Entry; + + let mut visible_parent_map = self.visible_parent_map.borrow_mut(); + for cnum in (1 .. self.next_crate_num().as_usize()).map(CrateNum::new) { let cdata = self.get_crate_data(cnum); @@ -556,6 +563,7 @@ impl CrateStore for cstore::CStore { } } - visible_parent_map + drop(visible_parent_map); + self.visible_parent_map.borrow() } } diff --git a/src/test/run-pass/auxiliary/issue_41053.rs b/src/test/run-pass/auxiliary/issue_41053.rs new file mode 100644 index 00000000000..68e92b10429 --- /dev/null +++ b/src/test/run-pass/auxiliary/issue_41053.rs @@ -0,0 +1,11 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub struct Test; diff --git a/src/test/run-pass/issue-41053.rs b/src/test/run-pass/issue-41053.rs new file mode 100644 index 00000000000..769d841e364 --- /dev/null +++ b/src/test/run-pass/issue-41053.rs @@ -0,0 +1,30 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue_41053.rs + +pub trait Trait { fn foo(&self) {} } + +pub struct Foo; + +impl Iterator for Foo { + type Item = Box<Trait>; + fn next(&mut self) -> Option<Box<Trait>> { + extern crate issue_41053; + impl ::Trait for issue_41053::Test { + fn foo(&self) {} + } + Some(Box::new(issue_41053::Test)) + } +} + +fn main() { + Foo.next().unwrap().foo(); +} |
