Skip to content

Commit 3c60bc0

Browse files
committed
auto merge of #19254 : nick29581/rust/dxr-glob, r=pcwalton
There is also some work here to make resolve a bit more stable - it no longer overwrites a specific import with a glob import. r?
2 parents c06edba + 4b92a5a commit 3c60bc0

File tree

27 files changed

+286
-97
lines changed

27 files changed

+286
-97
lines changed

src/libcollections/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3330,10 +3330,10 @@ mod tests {
33303330

33313331
#[cfg(test)]
33323332
mod bench {
3333+
use super::*;
33333334
use prelude::*;
33343335
use test::Bencher;
33353336
use test::black_box;
3336-
use super::*;
33373337

33383338
#[bench]
33393339
fn char_iterator(b: &mut Bencher) {

src/libgraphviz/maybe_owned_vec.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub use self::MaybeOwnedVector::*;
1414

1515
use std::default::Default;
1616
use std::fmt;
17-
use std::iter::FromIterator;
1817
use std::path::BytesContainer;
1918
use std::slice;
2019

src/librustc/metadata/csearch.rs

+7
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ pub fn get_impl_or_trait_item<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId)
146146
tcx)
147147
}
148148

149+
pub fn get_trait_name(cstore: &cstore::CStore, def: ast::DefId) -> ast::Name {
150+
let cdata = cstore.get_crate_data(def.krate);
151+
decoder::get_trait_name(cstore.intr.clone(),
152+
&*cdata,
153+
def.node)
154+
}
155+
149156
pub fn get_trait_item_name_and_kind(cstore: &cstore::CStore, def: ast::DefId)
150157
-> (ast::Name, def::TraitItemKind) {
151158
let cdata = cstore.get_crate_data(def.krate);

src/librustc/metadata/decoder.rs

+8
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,14 @@ pub fn get_impl_items(cdata: Cmd, impl_id: ast::NodeId)
781781
impl_items
782782
}
783783

784+
pub fn get_trait_name(intr: Rc<IdentInterner>,
785+
cdata: Cmd,
786+
id: ast::NodeId)
787+
-> ast::Name {
788+
let doc = lookup_item(id, cdata.data());
789+
item_name(&*intr, doc)
790+
}
791+
784792
pub fn get_trait_item_name_and_kind(intr: Rc<IdentInterner>,
785793
cdata: Cmd,
786794
id: ast::NodeId)

src/librustc/middle/ty.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ use std::mem;
7777
use std::ops;
7878
use std::rc::Rc;
7979
use collections::enum_set::{EnumSet, CLike};
80-
use std::collections::hash_map::HashMap;
80+
use std::collections::{HashMap, HashSet};
8181
use std::collections::hash_map::Entry::{Occupied, Vacant};
8282
use syntax::abi;
8383
use syntax::ast::{CrateNum, DefId, DUMMY_NODE_ID, Ident, ItemTrait, LOCAL_CRATE};
@@ -105,6 +105,7 @@ pub struct CrateAnalysis<'tcx> {
105105
pub ty_cx: ty::ctxt<'tcx>,
106106
pub reachable: NodeSet,
107107
pub name: String,
108+
pub glob_map: Option<GlobMap>,
108109
}
109110

110111
#[deriving(Copy, PartialEq, Eq, Hash)]
@@ -6285,6 +6286,10 @@ pub type CaptureModeMap = NodeMap<ast::CaptureClause>;
62856286
// Trait method resolution
62866287
pub type TraitMap = NodeMap<Vec<DefId>>;
62876288

6289+
// Map from the NodeId of a glob import to a list of items which are actually
6290+
// imported.
6291+
pub type GlobMap = HashMap<NodeId, HashSet<Name>>;
6292+
62886293
pub fn with_freevars<T, F>(tcx: &ty::ctxt, fid: ast::NodeId, f: F) -> T where
62896294
F: FnOnce(&[Freevar]) -> T,
62906295
{

src/librustc_borrowck/borrowck/check_loans.rs

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
use self::UseError::*;
2020

2121
use borrowck::*;
22-
use borrowck::LoanPathElem::*;
23-
use borrowck::LoanPathKind::*;
2422
use rustc::middle::expr_use_visitor as euv;
2523
use rustc::middle::mem_categorization as mc;
2624
use rustc::middle::region;

src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//! Computes moves.
1212
1313
use borrowck::*;
14-
use borrowck::LoanPathKind::*;
1514
use borrowck::gather_loans::move_error::MoveSpanAndPath;
1615
use borrowck::gather_loans::move_error::{MoveError, MoveErrorCollector};
1716
use borrowck::move_data::*;

src/librustc_borrowck/borrowck/gather_loans/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
// sure that all of these loans are honored.
1818

1919
use borrowck::*;
20-
use borrowck::LoanPathKind::*;
2120
use borrowck::move_data::MoveData;
2221
use rustc::middle::expr_use_visitor as euv;
2322
use rustc::middle::mem_categorization as mc;

src/librustc_borrowck/borrowck/gather_loans/restrictions.rs

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
pub use self::RestrictionResult::*;
1414

1515
use borrowck::*;
16-
use borrowck::LoanPathElem::*;
17-
use borrowck::LoanPathKind::*;
1816
use rustc::middle::expr_use_visitor as euv;
1917
use rustc::middle::mem_categorization as mc;
2018
use rustc::middle::ty;

src/librustc_driver/driver.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,27 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
342342
let lang_items = time(time_passes, "language item collection", (), |_|
343343
middle::lang_items::collect_language_items(krate, &sess));
344344

345+
let make_glob_map = if save_analysis(&sess) {
346+
resolve::MakeGlobMap::Yes
347+
} else {
348+
resolve::MakeGlobMap::No
349+
};
345350
let resolve::CrateMap {
346351
def_map,
347352
freevars,
348353
capture_mode_map,
349354
export_map,
350355
trait_map,
351356
external_exports,
352-
last_private_map
357+
last_private_map,
358+
glob_map,
353359
} =
354360
time(time_passes, "resolution", (),
355-
|_| resolve::resolve_crate(&sess, &lang_items, krate));
361+
|_| resolve::resolve_crate(&sess,
362+
&ast_map,
363+
&lang_items,
364+
krate,
365+
make_glob_map));
356366

357367
// Discard MTWT tables that aren't required past resolution.
358368
syntax::ext::mtwt::clear_tables();
@@ -454,14 +464,19 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
454464
public_items: public_items,
455465
reachable: reachable_map,
456466
name: name,
467+
glob_map: glob_map,
457468
}
458469
}
459470

471+
fn save_analysis(sess: &Session) -> bool {
472+
(sess.opts.debugging_opts & config::SAVE_ANALYSIS) != 0
473+
}
474+
460475
pub fn phase_save_analysis(sess: &Session,
461476
krate: &ast::Crate,
462477
analysis: &ty::CrateAnalysis,
463478
odir: &Option<Path>) {
464-
if (sess.opts.debugging_opts & config::SAVE_ANALYSIS) == 0 {
479+
if !save_analysis(sess) {
465480
return;
466481
}
467482
time(sess.time_passes(), "save analysis", krate, |krate|

src/librustc_driver/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn test_env<F>(source_string: &str,
123123
// run just enough stuff to build a tcx:
124124
let lang_items = lang_items::collect_language_items(krate, &sess);
125125
let resolve::CrateMap { def_map, freevars, capture_mode_map, .. } =
126-
resolve::resolve_crate(&sess, &lang_items, krate);
126+
resolve::resolve_crate(&sess, &ast_map, &lang_items, krate, resolve::MakeGlobMap::No);
127127
let named_region_map = resolve_lifetime::krate(&sess, krate, &def_map);
128128
let region_map = region::resolve_crate(&sess, krate);
129129
let stability_index = stability::Index::build(krate);

src/librustc_resolve/check_unused.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@ use syntax::ast::{ViewPathGlob, ViewPathList, ViewPathSimple};
2828
use syntax::codemap::{Span, DUMMY_SP};
2929
use syntax::visit::{mod, Visitor};
3030

31-
struct UnusedImportCheckVisitor<'a, 'b:'a> {
32-
resolver: &'a mut Resolver<'b>
31+
struct UnusedImportCheckVisitor<'a, 'b:'a, 'tcx:'b> {
32+
resolver: &'a mut Resolver<'b, 'tcx>
3333
}
3434

3535
// Deref and DerefMut impls allow treating UnusedImportCheckVisitor as Resolver.
36-
impl<'a, 'b> Deref<Resolver<'b>> for UnusedImportCheckVisitor<'a, 'b> {
37-
fn deref<'c>(&'c self) -> &'c Resolver<'b> {
36+
impl<'a, 'b, 'tcx:'b> Deref<Resolver<'b, 'tcx>> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
37+
fn deref<'c>(&'c self) -> &'c Resolver<'b, 'tcx> {
3838
&*self.resolver
3939
}
4040
}
4141

42-
impl<'a, 'b> DerefMut<Resolver<'b>> for UnusedImportCheckVisitor<'a, 'b> {
43-
fn deref_mut<'c>(&'c mut self) -> &'c mut Resolver<'b> {
42+
impl<'a, 'b, 'tcx:'b> DerefMut<Resolver<'b, 'tcx>> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
43+
fn deref_mut<'c>(&'c mut self) -> &'c mut Resolver<'b, 'tcx> {
4444
&mut *self.resolver
4545
}
4646
}
4747

48-
impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
48+
impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> {
4949
// We have information about whether `use` (import) directives are actually used now.
5050
// If an import is not used at all, we signal a lint error. If an import is only used
5151
// for a single namespace, we remove the other namespace from the recorded privacy
@@ -104,7 +104,7 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
104104
}
105105
}
106106

107-
impl<'a, 'b, 'v> Visitor<'v> for UnusedImportCheckVisitor<'a, 'b> {
107+
impl<'a, 'b, 'v, 'tcx> Visitor<'v> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
108108
fn visit_view_item(&mut self, vi: &ViewItem) {
109109
// Ignore is_public import statements because there's no way to be sure
110110
// whether they're used or not. Also ignore imports with a dummy span

0 commit comments

Comments
 (0)