Skip to content

Commit 60425eb

Browse files
committed
---
yaml --- r: 272179 b: refs/heads/auto c: b0d3170 h: refs/heads/master i: 272177: 872c209 272175: 1cdbda6
1 parent 4b6440e commit 60425eb

File tree

156 files changed

+751
-880
lines changed

Some content is hidden

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

156 files changed

+751
-880
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 9a28d4edc9375e5bf606c453d1e03a45ae8be0af
11+
refs/heads/auto: b0d31707cc849bd385ae8677823d1f2bcc8aba41
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/libcollections/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#![feature(placement_new_protocol)]
4949
#![feature(shared)]
5050
#![feature(slice_patterns)]
51+
#![feature(specialization)]
5152
#![feature(staged_api)]
5253
#![feature(step_by)]
5354
#![feature(str_char)]

branches/auto/src/libcollections/string.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@ pub trait ToString {
17551755
#[stable(feature = "rust1", since = "1.0.0")]
17561756
impl<T: fmt::Display + ?Sized> ToString for T {
17571757
#[inline]
1758-
fn to_string(&self) -> String {
1758+
default fn to_string(&self) -> String {
17591759
use core::fmt::Write;
17601760
let mut buf = String::new();
17611761
let _ = buf.write_fmt(format_args!("{}", self));
@@ -1764,6 +1764,14 @@ impl<T: fmt::Display + ?Sized> ToString for T {
17641764
}
17651765
}
17661766

1767+
#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
1768+
impl ToString for str {
1769+
#[inline]
1770+
fn to_string(&self) -> String {
1771+
String::from(self)
1772+
}
1773+
}
1774+
17671775
#[stable(feature = "rust1", since = "1.0.0")]
17681776
impl AsRef<str> for String {
17691777
#[inline]

branches/auto/src/libcore/cell.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,6 @@ impl<T:Copy> Cell<T> {
216216

217217
/// Returns a reference to the underlying `UnsafeCell`.
218218
///
219-
/// # Safety
220-
///
221-
/// This function is `unsafe` because `UnsafeCell`'s field is public.
222-
///
223219
/// # Examples
224220
///
225221
/// ```
@@ -229,11 +225,11 @@ impl<T:Copy> Cell<T> {
229225
///
230226
/// let c = Cell::new(5);
231227
///
232-
/// let uc = unsafe { c.as_unsafe_cell() };
228+
/// let uc = c.as_unsafe_cell();
233229
/// ```
234230
#[inline]
235231
#[unstable(feature = "as_unsafe_cell", issue = "27708")]
236-
pub unsafe fn as_unsafe_cell(&self) -> &UnsafeCell<T> {
232+
pub fn as_unsafe_cell(&self) -> &UnsafeCell<T> {
237233
&self.value
238234
}
239235
}

branches/auto/src/librustc/front/map/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -581,14 +581,6 @@ impl<'ast> Map<'ast> {
581581
}
582582
}
583583

584-
pub fn get_foreign_vis(&self, id: NodeId) -> Visibility {
585-
let vis = self.expect_foreign_item(id).vis; // read recorded by `expect_foreign_item`
586-
match self.find(self.get_parent(id)) { // read recorded by `find`
587-
Some(NodeItem(i)) => vis.inherit_from(i.vis),
588-
_ => vis
589-
}
590-
}
591-
592584
pub fn expect_item(&self, id: NodeId) -> &'ast Item {
593585
match self.find(id) { // read recorded by `find`
594586
Some(NodeItem(item)) => item,

branches/auto/src/librustc/middle/cstore.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use mir::repr::Mir;
3232
use mir::mir_map::MirMap;
3333
use session::Session;
3434
use session::search_paths::PathKind;
35-
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
35+
use util::nodemap::{FnvHashMap, NodeMap, NodeSet, DefIdMap};
3636
use std::any::Any;
3737
use std::cell::RefCell;
3838
use std::rc::Rc;
@@ -169,6 +169,7 @@ pub trait CrateStore<'tcx> : Any {
169169
fn item_type(&self, tcx: &TyCtxt<'tcx>, def: DefId)
170170
-> ty::TypeScheme<'tcx>;
171171
fn relative_item_path(&self, def: DefId) -> Vec<hir_map::PathElem>;
172+
fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>>;
172173
fn extern_item_path(&self, def: DefId) -> Vec<hir_map::PathElem>;
173174
fn item_name(&self, def: DefId) -> ast::Name;
174175
fn item_predicates(&self, tcx: &TyCtxt<'tcx>, def: DefId)
@@ -347,6 +348,9 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
347348
fn item_type(&self, tcx: &TyCtxt<'tcx>, def: DefId)
348349
-> ty::TypeScheme<'tcx> { unimplemented!() }
349350
fn relative_item_path(&self, def: DefId) -> Vec<hir_map::PathElem> { unimplemented!() }
351+
fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>> {
352+
unimplemented!()
353+
}
350354
fn extern_item_path(&self, def: DefId) -> Vec<hir_map::PathElem> { unimplemented!() }
351355
fn item_name(&self, def: DefId) -> ast::Name { unimplemented!() }
352356
fn item_predicates(&self, tcx: &TyCtxt<'tcx>, def: DefId)

branches/auto/src/librustc/ty/item_path.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use front::map::DefPathData;
1212
use middle::cstore::LOCAL_CRATE;
13-
use middle::def_id::DefId;
13+
use middle::def_id::{DefId, CRATE_DEF_INDEX};
1414
use ty::{self, Ty, TyCtxt};
1515
use syntax::ast;
1616

@@ -75,9 +75,51 @@ impl<'tcx> TyCtxt<'tcx> {
7575
}
7676
}
7777

78+
/// If possible, this pushes a global path resolving to `external_def_id` that is visible
79+
/// from at least one local module and returns true. If the crate defining `external_def_id` is
80+
/// declared with an `extern crate`, the path is guarenteed to use the `extern crate`.
81+
pub fn try_push_visible_item_path<T>(&self, buffer: &mut T, external_def_id: DefId) -> bool
82+
where T: ItemPathBuffer
83+
{
84+
let visible_parent_map = self.sess.cstore.visible_parent_map();
85+
86+
let (mut cur_def, mut cur_path) = (external_def_id, Vec::<ast::Name>::new());
87+
loop {
88+
// If `cur_def` is a direct or injected extern crate, push the path to the crate
89+
// followed by the path to the item within the crate and return.
90+
if cur_def.index == CRATE_DEF_INDEX {
91+
match self.sess.cstore.extern_crate(cur_def.krate) {
92+
Some(extern_crate) if extern_crate.direct => {
93+
self.push_item_path(buffer, extern_crate.def_id);
94+
cur_path.iter().rev().map(|segment| buffer.push(&segment.as_str())).count();
95+
return true;
96+
}
97+
None => {
98+
buffer.push(&self.crate_name(cur_def.krate));
99+
cur_path.iter().rev().map(|segment| buffer.push(&segment.as_str())).count();
100+
return true;
101+
}
102+
_ => {},
103+
}
104+
}
105+
106+
cur_path.push(self.sess.cstore.item_name(cur_def));
107+
match visible_parent_map.get(&cur_def) {
108+
Some(&def) => cur_def = def,
109+
None => return false,
110+
};
111+
}
112+
}
113+
78114
pub fn push_item_path<T>(&self, buffer: &mut T, def_id: DefId)
79115
where T: ItemPathBuffer
80116
{
117+
match *buffer.root_mode() {
118+
RootMode::Local if !def_id.is_local() =>
119+
if self.try_push_visible_item_path(buffer, def_id) { return },
120+
_ => {}
121+
}
122+
81123
let key = self.def_key(def_id);
82124
match key.disambiguated_data.data {
83125
DefPathData::CrateRoot => {

branches/auto/src/librustc_metadata/csearch.rs

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ use decoder;
1313
use encoder;
1414
use loader;
1515

16-
use middle::cstore::{CrateStore, CrateSource, ChildItem, ExternCrate, FoundAst};
16+
use middle::cstore::{CrateStore, CrateSource, ChildItem, ExternCrate, FoundAst, DefLike};
1717
use middle::cstore::{NativeLibraryKind, LinkMeta, LinkagePreference};
1818
use middle::def;
1919
use middle::lang_items;
2020
use rustc::ty::{self, Ty, TyCtxt, VariantKind};
21-
use middle::def_id::{DefId, DefIndex};
21+
use middle::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
2222

2323
use rustc::front::map as hir_map;
2424
use rustc::mir::repr::Mir;
2525
use rustc::mir::mir_map::MirMap;
26-
use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet};
26+
use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet, DefIdMap};
2727

2828
use std::cell::RefCell;
2929
use std::rc::Rc;
@@ -544,4 +544,60 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
544544
{
545545
encoder::metadata_encoding_version
546546
}
547+
548+
/// Returns a map from a sufficiently visible external item (i.e. an external item that is
549+
/// visible from at least one local module) to a sufficiently visible parent (considering
550+
/// modules that re-export the external item to be parents).
551+
fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>> {
552+
let mut visible_parent_map = self.visible_parent_map.borrow_mut();
553+
if !visible_parent_map.is_empty() { return visible_parent_map; }
554+
555+
use rustc_front::hir;
556+
use rustc::middle::cstore::{CrateStore, ChildItem};
557+
use std::collections::vec_deque::VecDeque;
558+
use std::collections::hash_map::Entry;
559+
for cnum in 1 .. self.next_crate_num() {
560+
let cdata = self.get_crate_data(cnum);
561+
562+
match cdata.extern_crate.get() {
563+
// Ignore crates without a corresponding local `extern crate` item.
564+
Some(extern_crate) if !extern_crate.direct => continue,
565+
_ => {},
566+
}
567+
568+
let mut bfs_queue = &mut VecDeque::new();
569+
let mut add_child = |bfs_queue: &mut VecDeque<_>, child: ChildItem, parent: DefId| {
570+
let child = match child.def {
571+
DefLike::DlDef(def) if child.vis == hir::Public => def.def_id(),
572+
_ => return,
573+
};
574+
575+
match visible_parent_map.entry(child) {
576+
Entry::Occupied(mut entry) => {
577+
// If `child` is defined in crate `cnum`, ensure
578+
// that it is mapped to a parent in `cnum`.
579+
if child.krate == cnum && entry.get().krate != cnum {
580+
entry.insert(parent);
581+
}
582+
}
583+
Entry::Vacant(entry) => {
584+
entry.insert(parent);
585+
bfs_queue.push_back(child);
586+
}
587+
}
588+
};
589+
590+
let croot = DefId { krate: cnum, index: CRATE_DEF_INDEX };
591+
for child in self.crate_top_level_items(cnum) {
592+
add_child(bfs_queue, child, croot);
593+
}
594+
while let Some(def) = bfs_queue.pop_front() {
595+
for child in self.item_children(def) {
596+
add_child(bfs_queue, child, def);
597+
}
598+
}
599+
}
600+
601+
visible_parent_map
602+
}
547603
}

branches/auto/src/librustc_metadata/cstore.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use loader;
2222

2323
use rustc::back::svh::Svh;
2424
use rustc::middle::cstore::{ExternCrate};
25-
use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet};
25+
use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet, DefIdMap};
26+
use rustc::middle::def_id::DefId;
2627

2728
use std::cell::{RefCell, Ref, Cell};
2829
use std::rc::Rc;
@@ -92,6 +93,7 @@ pub struct CStore {
9293
used_link_args: RefCell<Vec<String>>,
9394
statically_included_foreign_items: RefCell<NodeSet>,
9495
pub intr: Rc<IdentInterner>,
96+
pub visible_parent_map: RefCell<DefIdMap<DefId>>,
9597
}
9698

9799
impl CStore {
@@ -104,6 +106,7 @@ impl CStore {
104106
used_link_args: RefCell::new(Vec::new()),
105107
intr: intr,
106108
statically_included_foreign_items: RefCell::new(NodeSet()),
109+
visible_parent_map: RefCell::new(FnvHashMap()),
107110
}
108111
}
109112

0 commit comments

Comments
 (0)