Skip to content

Commit 78e95bb

Browse files
committed
Auto merge of #42588 - ishitatsuyuki:patch-1, r=petrochenkov
Make unused-extern-crate warn-by-default Apart from enabling the lint, this pull request also removes existing unused crates in the codebase, and fix some amount of false positives on crates with special purposes. Now that all false positive issues are closed, it should be possible to make it available to wider users. Quote: > Now that macro modularization is implemented, this is true today! *#30849 (comment) Concerns: can break some `#[deny(warnings)]`. Close #42591
2 parents 93cdf5e + a91bdf4 commit 78e95bb

Some content is hidden

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

51 files changed

+96
-38
lines changed

src/Cargo.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/liballoc/tests/lib.rs

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

1111
#![deny(warnings)]
1212

13-
#![feature(alloc)]
1413
#![feature(attr_literals)]
1514
#![feature(box_syntax)]
1615
#![feature(inclusive_range_syntax)]
@@ -27,14 +26,10 @@
2726
#![feature(splice)]
2827
#![feature(str_escape)]
2928
#![feature(string_retain)]
30-
#![feature(test)]
3129
#![feature(unboxed_closures)]
3230
#![feature(unicode)]
3331

34-
extern crate alloc;
35-
extern crate test;
3632
extern crate std_unicode;
37-
extern crate core;
3833

3934
use std::hash::{Hash, Hasher};
4035
use std::collections::hash_map::DefaultHasher;

src/liballoc_jemalloc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#![feature(libc)]
2020
#![feature(linkage)]
2121
#![feature(staged_api)]
22-
#![cfg_attr(dummy_jemalloc, allow(dead_code))]
22+
#![cfg_attr(dummy_jemalloc, allow(dead_code, unused_extern_crates))]
2323
#![cfg_attr(not(dummy_jemalloc), feature(allocator_api))]
2424

2525
extern crate alloc;

src/libcore/tests/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#![feature(inclusive_range)]
2727
#![feature(inclusive_range_syntax)]
2828
#![feature(iter_rfind)]
29-
#![feature(libc)]
3029
#![feature(nonzero)]
3130
#![feature(ord_max_min)]
3231
#![feature(rand)]
@@ -41,13 +40,10 @@
4140
#![feature(test)]
4241
#![feature(trusted_len)]
4342
#![feature(try_from)]
44-
#![feature(unicode)]
4543
#![feature(unique)]
4644

4745
extern crate core;
4846
extern crate test;
49-
extern crate libc;
50-
extern crate std_unicode;
5147
extern crate rand;
5248

5349
mod any;

src/libpanic_unwind/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
#![feature(core_intrinsics)]
3535
#![feature(lang_items)]
3636
#![feature(libc)]
37-
#![feature(panic_unwind)]
37+
#![cfg_attr(not(any(target_env = "msvc",
38+
all(windows, target_arch = "x86_64", target_env = "gnu"))),
39+
feature(panic_unwind))]
3840
#![feature(raw)]
3941
#![feature(staged_api)]
4042
#![feature(unwind_attributes)]
@@ -45,6 +47,7 @@
4547

4648
extern crate alloc;
4749
extern crate libc;
50+
#[cfg(not(any(target_env = "msvc", all(windows, target_arch = "x86_64", target_env = "gnu"))))]
4851
extern crate unwind;
4952

5053
use core::intrinsics;

src/librustc/dep_graph/dep_node.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ define_dep_nodes!( <'tcx>
522522
[] DylibDepFormats(DefId),
523523
[] IsAllocator(DefId),
524524
[] IsPanicRuntime(DefId),
525+
[] IsCompilerBuiltins(DefId),
526+
[] HasGlobalAllocator(DefId),
525527
[] ExternCrate(DefId),
526528
[] LintLevels,
527529
);

src/librustc/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#![feature(core_intrinsics)]
2727
#![feature(discriminant_value)]
2828
#![feature(i128_type)]
29-
#![feature(libc)]
29+
#![cfg_attr(windows, feature(libc))]
3030
#![feature(never_type)]
3131
#![feature(nonzero)]
3232
#![feature(quote)]
@@ -45,6 +45,7 @@ extern crate core;
4545
extern crate fmt_macros;
4646
extern crate getopts;
4747
extern crate graphviz;
48+
#[cfg(windows)]
4849
extern crate libc;
4950
extern crate owning_ref;
5051
extern crate rustc_back;
@@ -62,7 +63,9 @@ extern crate serialize as rustc_serialize; // used by deriving
6263

6364
// Note that librustc doesn't actually depend on these crates, see the note in
6465
// `Cargo.toml` for this crate about why these are here.
66+
#[allow(unused_extern_crates)]
6567
extern crate flate2;
68+
#[allow(unused_extern_crates)]
6669
extern crate test;
6770

6871
#[macro_use]

src/librustc/lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ declare_lint! {
3030

3131
declare_lint! {
3232
pub UNUSED_EXTERN_CRATES,
33-
Allow,
33+
Warn,
3434
"extern crates that are never used"
3535
}
3636

src/librustc/ty/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,8 @@ pub struct GlobalCtxt<'tcx> {
797797

798798
pub maybe_unused_trait_imports: NodeSet,
799799

800+
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
801+
800802
// Internal cache for metadata decoding. No need to track deps on this.
801803
pub rcache: RefCell<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,
802804

@@ -1038,6 +1040,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
10381040
mir_passes,
10391041
freevars: RefCell::new(resolutions.freevars),
10401042
maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports,
1043+
maybe_unused_extern_crates: resolutions.maybe_unused_extern_crates,
10411044
rcache: RefCell::new(FxHashMap()),
10421045
normalized_cache: RefCell::new(FxHashMap()),
10431046
inhabitedness_cache: RefCell::new(FxHashMap()),

src/librustc/ty/maps.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,18 @@ impl<'tcx> QueryDescription for queries::is_panic_runtime<'tcx> {
516516
}
517517
}
518518

519+
impl<'tcx> QueryDescription for queries::is_compiler_builtins<'tcx> {
520+
fn describe(_: TyCtxt, _: DefId) -> String {
521+
"checking if the crate is_compiler_builtins".to_string()
522+
}
523+
}
524+
525+
impl<'tcx> QueryDescription for queries::has_global_allocator<'tcx> {
526+
fn describe(_: TyCtxt, _: DefId) -> String {
527+
"checking if the crate has_global_allocator".to_string()
528+
}
529+
}
530+
519531
impl<'tcx> QueryDescription for queries::extern_crate<'tcx> {
520532
fn describe(_: TyCtxt, _: DefId) -> String {
521533
"getting crate's ExternCrateData".to_string()
@@ -1079,6 +1091,8 @@ define_maps! { <'tcx>
10791091

10801092
[] is_allocator: IsAllocator(DefId) -> bool,
10811093
[] is_panic_runtime: IsPanicRuntime(DefId) -> bool,
1094+
[] is_compiler_builtins: IsCompilerBuiltins(DefId) -> bool,
1095+
[] has_global_allocator: HasGlobalAllocator(DefId) -> bool,
10821096

10831097
[] extern_crate: ExternCrate(DefId) -> Rc<Option<ExternCrate>>,
10841098

0 commit comments

Comments
 (0)