Skip to content

Commit 8e414e0

Browse files
committed
Auto merge of #33091 - sanxiyn:unused-trait-import-3, r=nrc
Warn unused trait imports, rebased Rebase of #30021. Fix #25730.
2 parents 4896832 + 282afda commit 8e414e0

File tree

60 files changed

+193
-83
lines changed

Some content is hidden

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

60 files changed

+193
-83
lines changed

src/libcoretest/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![feature(box_syntax)]
1616
#![feature(cell_extras)]
1717
#![feature(const_fn)]
18-
#![feature(core_float)]
1918
#![feature(core_private_bignum)]
2019
#![feature(core_private_diy_float)]
2120
#![feature(dec2flt)]

src/libcoretest/num/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ pub fn test_num<T>(ten: T, two: T) where
5252
mod tests {
5353
use core::option::Option;
5454
use core::option::Option::{Some, None};
55-
use core::num::Float;
5655

5756
#[test]
5857
fn from_str_issue7588() {

src/librand/distributions/exponential.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
//! The exponential distribution.
1212
13+
#[cfg(not(test))] // only necessary for no_std
1314
use FloatMath;
1415

1516
use {Rng, Rand};

src/librand/distributions/gamma.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use self::GammaRepr::*;
1414
use self::ChiSquaredRepr::*;
1515

16+
#[cfg(not(test))] // only necessary for no_std
1617
use FloatMath;
1718

1819
use {Rng, Open01};

src/librand/distributions/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
//! internally. The `IndependentSample` trait is for generating values
1818
//! that do not need to record state.
1919
20+
#[cfg(not(test))] // only necessary for no_std
2021
use core::num::Float;
22+
2123
use core::marker::PhantomData;
2224

2325
use {Rng, Rand};

src/librand/distributions/normal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
//! The normal and derived distributions.
1212
13+
#[cfg(not(test))] // only necessary for no_std
1314
use FloatMath;
1415

1516
use {Rng, Rand, Open01};

src/librand/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
#![unstable(feature = "rand",
2929
reason = "use `rand` from crates.io",
3030
issue = "27703")]
31-
#![feature(core_float)]
3231
#![feature(core_intrinsics)]
3332
#![feature(staged_api)]
3433
#![feature(step_by)]
3534
#![feature(custom_attribute)]
3635
#![allow(unused_attributes)]
3736

37+
#![cfg_attr(not(test), feature(core_float))] // only necessary for no_std
3838
#![cfg_attr(test, feature(test, rand))]
3939

4040
#![allow(deprecated)]

src/librustc/dep_graph/dep_node.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub enum DepNode<D: Clone + Debug> {
5959
TypeckItemBody(D),
6060
Dropck,
6161
DropckImpl(D),
62+
UnusedTraitCheck,
6263
CheckConst(D),
6364
Privacy,
6465
IntrinsicCheck(D),
@@ -165,6 +166,7 @@ impl<D: Clone + Debug> DepNode<D> {
165166
CheckEntryFn => Some(CheckEntryFn),
166167
Variance => Some(Variance),
167168
Dropck => Some(Dropck),
169+
UnusedTraitCheck => Some(UnusedTraitCheck),
168170
Privacy => Some(Privacy),
169171
Reachability => Some(Reachability),
170172
DeadCheck => Some(DeadCheck),

src/librustc/hir/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1639,8 +1639,13 @@ pub type FreevarMap = NodeMap<Vec<Freevar>>;
16391639

16401640
pub type CaptureModeMap = NodeMap<CaptureClause>;
16411641

1642+
pub struct TraitCandidate {
1643+
pub def_id: DefId,
1644+
pub import_id: Option<NodeId>,
1645+
}
1646+
16421647
// Trait method resolution
1643-
pub type TraitMap = NodeMap<Vec<DefId>>;
1648+
pub type TraitMap = NodeMap<Vec<TraitCandidate>>;
16441649

16451650
// Map from the NodeId of a glob import to a list of items which are actually
16461651
// imported.

src/librustc/ty/context.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ pub struct TyCtxt<'tcx> {
289289
// scratch every time.
290290
pub freevars: RefCell<FreevarMap>,
291291

292+
pub maybe_unused_trait_imports: NodeSet,
293+
292294
// Records the type of every item.
293295
pub tcache: RefCell<DepTrackingMap<maps::Tcache<'tcx>>>,
294296

@@ -338,6 +340,10 @@ pub struct TyCtxt<'tcx> {
338340
/// about.
339341
pub used_mut_nodes: RefCell<NodeSet>,
340342

343+
/// Set of trait imports actually used in the method resolution.
344+
/// This is used for warning unused imports.
345+
pub used_trait_imports: RefCell<NodeSet>,
346+
341347
/// The set of external nominal types whose implementations have been read.
342348
/// This is used for lazy resolution of methods.
343349
pub populated_external_types: RefCell<DefIdSet>,
@@ -543,6 +549,7 @@ impl<'tcx> TyCtxt<'tcx> {
543549
named_region_map: resolve_lifetime::NamedRegionMap,
544550
map: ast_map::Map<'tcx>,
545551
freevars: FreevarMap,
552+
maybe_unused_trait_imports: NodeSet,
546553
region_maps: RegionMaps,
547554
lang_items: middle::lang_items::LanguageItems,
548555
stability: stability::Index<'tcx>,
@@ -581,6 +588,7 @@ impl<'tcx> TyCtxt<'tcx> {
581588
fulfilled_predicates: RefCell::new(fulfilled_predicates),
582589
map: map,
583590
freevars: RefCell::new(freevars),
591+
maybe_unused_trait_imports: maybe_unused_trait_imports,
584592
tcache: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
585593
rcache: RefCell::new(FnvHashMap()),
586594
tc_cache: RefCell::new(FnvHashMap()),
@@ -595,6 +603,7 @@ impl<'tcx> TyCtxt<'tcx> {
595603
impl_items: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
596604
used_unsafe: RefCell::new(NodeSet()),
597605
used_mut_nodes: RefCell::new(NodeSet()),
606+
used_trait_imports: RefCell::new(NodeSet()),
598607
populated_external_types: RefCell::new(DefIdSet()),
599608
populated_external_primitive_impls: RefCell::new(DefIdSet()),
600609
extern_const_statics: RefCell::new(DefIdMap()),

0 commit comments

Comments
 (0)