Skip to content

Commit 8447df3

Browse files
committed
use effective_visibilities to check unused
1 parent a4a10bd commit 8447df3

File tree

28 files changed

+131
-48
lines changed

28 files changed

+131
-48
lines changed

compiler/rustc_ast/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ pub mod visit;
5353

5454
pub use self::ast::*;
5555
pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasSpan, HasTokens};
56-
pub use self::format::*;
5756

5857
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
5958

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ mod utils;
5050

5151
pub use self::create_scope_map::compute_mir_scopes;
5252
pub use self::metadata::build_global_var_di_node;
53-
pub use self::metadata::extend_scope_to_file;
5453

5554
#[allow(non_upper_case_globals)]
5655
const DW_TAG_auto_variable: c_uint = 0x100;

compiler/rustc_codegen_llvm/src/mono_item.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::llvm;
66
use crate::type_of::LayoutLlvmExt;
77
use rustc_codegen_ssa::traits::*;
88
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
9-
pub use rustc_middle::mir::mono::MonoItem;
109
use rustc_middle::mir::mono::{Linkage, Visibility};
1110
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf};
1211
use rustc_middle::ty::{self, Instance, TypeVisitableExt};

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ mod arg_matrix;
44
mod checks;
55
mod suggestions;
66

7-
pub use _impl::*;
87
use rustc_errors::ErrorGuaranteed;
9-
pub use suggestions::*;
108

119
use crate::coercion::DynamicCoerceMany;
1210
use crate::{Diverges, EnclosingBreakables, Inherited};

compiler/rustc_infer/src/traits/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_span::Span;
1919

2020
pub use self::FulfillmentErrorCode::*;
2121
pub use self::ImplSource::*;
22-
pub use self::ObligationCauseCode::*;
2322
pub use self::SelectionError::*;
2423

2524
pub use self::engine::{TraitEngine, TraitEngineExt};

compiler/rustc_middle/src/mir/terminator.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ use rustc_hir::LangItem;
33
use smallvec::SmallVec;
44

55
use super::{BasicBlock, InlineAsmOperand, Operand, SourceInfo, TerminatorKind, UnwindAction};
6-
pub use rustc_ast::Mutability;
76
use rustc_macros::HashStable;
87
use std::iter;
98
use std::slice;
109

11-
pub use super::query::*;
1210
use super::*;
1311

1412
impl SwitchTargets {

compiler/rustc_middle/src/ty/assoc.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
pub use self::AssocItemContainer::*;
2-
31
use crate::ty;
42
use rustc_data_structures::sorted_map::SortedIndexMultiMap;
53
use rustc_hir as hir;

compiler/rustc_mir_dataflow/src/framework/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mod visitor;
4848
pub use self::cursor::{AnalysisResults, ResultsClonedCursor, ResultsCursor, ResultsRefCursor};
4949
pub use self::direction::{Backward, Direction, Forward};
5050
pub use self::engine::{Engine, EntrySets, Results, ResultsCloned};
51-
pub use self::lattice::{JoinSemiLattice, MaybeReachable, MeetSemiLattice};
51+
pub use self::lattice::{JoinSemiLattice, MaybeReachable};
5252
pub use self::visitor::{visit_results, ResultsVisitable, ResultsVisitor};
5353

5454
/// Analysis domains are all bitsets of various kinds. This trait holds

compiler/rustc_resolve/src/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'a, 'b, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
173173
self.base_use_tree = Some(use_tree);
174174
}
175175

176-
if self.base_use_is_pub {
176+
if self.r.effective_visibilities.is_exported(self.r.local_def_id(id)) {
177177
self.check_import_as_underscore(use_tree, id);
178178
return;
179179
}

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use std::ops::ControlFlow;
2020

2121
pub use self::infer_ctxt_ext::*;
2222
pub use self::type_err_ctxt_ext::*;
23-
pub use rustc_infer::traits::error_reporting::*;
2423

2524
// When outputting impl candidates, prefer showing those that are more similar.
2625
//

compiler/rustc_trait_selection/src/traits/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ use std::ops::ControlFlow;
4141

4242
pub(crate) use self::project::{needs_normalization, BoundVarReplacer, PlaceholderReplacer};
4343

44-
pub use self::FulfillmentErrorCode::*;
45-
pub use self::ImplSource::*;
46-
pub use self::ObligationCauseCode::*;
47-
pub use self::SelectionError::*;
48-
4944
pub use self::coherence::{add_placeholder_note, orphan_check, overlapping_impls};
5045
pub use self::coherence::{OrphanCheckErr, OverlapResult};
5146
pub use self::engine::{ObligationCtxt, TraitEngineExt};

compiler/rustc_trait_selection/src/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::ty::{self, ImplSubject, ToPredicate, Ty, TyCtxt, TypeVisitable
99
use rustc_span::Span;
1010
use smallvec::SmallVec;
1111

12-
pub use rustc_infer::traits::{self, util::*};
12+
pub use rustc_infer::traits::util::*;
1313

1414
///////////////////////////////////////////////////////////////////////////
1515
// `TraitAliasExpander` iterator

library/portable-simd/crates/core_simd/src/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@ pub mod simd {
3535
pub use crate::core_simd::masks::*;
3636
pub use crate::core_simd::ord::*;
3737
pub use crate::core_simd::swizzle::*;
38-
pub use crate::core_simd::swizzle_dyn::*;
3938
pub use crate::core_simd::vector::*;
4039
}

library/std/src/sys/unix/process/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
pub use self::process_common::{Command, CommandArgs, ExitCode, Stdio, StdioPipes};
22
pub use self::process_inner::{ExitStatus, ExitStatusError, Process};
33
pub use crate::ffi::OsString as EnvKey;
4-
pub use crate::sys_common::process::CommandEnvs;
54

65
#[cfg_attr(any(target_os = "espidf", target_os = "horizon"), allow(unused))]
76
mod process_common;

src/tools/rust-analyzer/crates/parser/src/syntax_kind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
mod generated;
55

66
#[allow(unreachable_pub)]
7-
pub use self::generated::{SyntaxKind, T};
7+
pub use self::generated::SyntaxKind;
88

99
impl From<u16> for SyntaxKind {
1010
#[inline]

src/tools/rust-analyzer/crates/parser/src/syntax_kind/generated.rs

-1
Original file line numberDiff line numberDiff line change
@@ -497,4 +497,3 @@ impl SyntaxKind {
497497
}
498498
#[macro_export]
499499
macro_rules ! T { [;] => { $ crate :: SyntaxKind :: SEMICOLON } ; [,] => { $ crate :: SyntaxKind :: COMMA } ; ['('] => { $ crate :: SyntaxKind :: L_PAREN } ; [')'] => { $ crate :: SyntaxKind :: R_PAREN } ; ['{'] => { $ crate :: SyntaxKind :: L_CURLY } ; ['}'] => { $ crate :: SyntaxKind :: R_CURLY } ; ['['] => { $ crate :: SyntaxKind :: L_BRACK } ; [']'] => { $ crate :: SyntaxKind :: R_BRACK } ; [<] => { $ crate :: SyntaxKind :: L_ANGLE } ; [>] => { $ crate :: SyntaxKind :: R_ANGLE } ; [@] => { $ crate :: SyntaxKind :: AT } ; [#] => { $ crate :: SyntaxKind :: POUND } ; [~] => { $ crate :: SyntaxKind :: TILDE } ; [?] => { $ crate :: SyntaxKind :: QUESTION } ; [$] => { $ crate :: SyntaxKind :: DOLLAR } ; [&] => { $ crate :: SyntaxKind :: AMP } ; [|] => { $ crate :: SyntaxKind :: PIPE } ; [+] => { $ crate :: SyntaxKind :: PLUS } ; [*] => { $ crate :: SyntaxKind :: STAR } ; [/] => { $ crate :: SyntaxKind :: SLASH } ; [^] => { $ crate :: SyntaxKind :: CARET } ; [%] => { $ crate :: SyntaxKind :: PERCENT } ; [_] => { $ crate :: SyntaxKind :: UNDERSCORE } ; [.] => { $ crate :: SyntaxKind :: DOT } ; [..] => { $ crate :: SyntaxKind :: DOT2 } ; [...] => { $ crate :: SyntaxKind :: DOT3 } ; [..=] => { $ crate :: SyntaxKind :: DOT2EQ } ; [:] => { $ crate :: SyntaxKind :: COLON } ; [::] => { $ crate :: SyntaxKind :: COLON2 } ; [=] => { $ crate :: SyntaxKind :: EQ } ; [==] => { $ crate :: SyntaxKind :: EQ2 } ; [=>] => { $ crate :: SyntaxKind :: FAT_ARROW } ; [!] => { $ crate :: SyntaxKind :: BANG } ; [!=] => { $ crate :: SyntaxKind :: NEQ } ; [-] => { $ crate :: SyntaxKind :: MINUS } ; [->] => { $ crate :: SyntaxKind :: THIN_ARROW } ; [<=] => { $ crate :: SyntaxKind :: LTEQ } ; [>=] => { $ crate :: SyntaxKind :: GTEQ } ; [+=] => { $ crate :: SyntaxKind :: PLUSEQ } ; [-=] => { $ crate :: SyntaxKind :: MINUSEQ } ; [|=] => { $ crate :: SyntaxKind :: PIPEEQ } ; [&=] => { $ crate :: SyntaxKind :: AMPEQ } ; [^=] => { $ crate :: SyntaxKind :: CARETEQ } ; [/=] => { $ crate :: SyntaxKind :: SLASHEQ } ; [*=] => { $ crate :: SyntaxKind :: STAREQ } ; [%=] => { $ crate :: SyntaxKind :: PERCENTEQ } ; [&&] => { $ crate :: SyntaxKind :: AMP2 } ; [||] => { $ crate :: SyntaxKind :: PIPE2 } ; [<<] => { $ crate :: SyntaxKind :: SHL } ; [>>] => { $ crate :: SyntaxKind :: SHR } ; [<<=] => { $ crate :: SyntaxKind :: SHLEQ } ; [>>=] => { $ crate :: SyntaxKind :: SHREQ } ; [as] => { $ crate :: SyntaxKind :: AS_KW } ; [async] => { $ crate :: SyntaxKind :: ASYNC_KW } ; [await] => { $ crate :: SyntaxKind :: AWAIT_KW } ; [box] => { $ crate :: SyntaxKind :: BOX_KW } ; [break] => { $ crate :: SyntaxKind :: BREAK_KW } ; [const] => { $ crate :: SyntaxKind :: CONST_KW } ; [continue] => { $ crate :: SyntaxKind :: CONTINUE_KW } ; [crate] => { $ crate :: SyntaxKind :: CRATE_KW } ; [do] => { $ crate :: SyntaxKind :: DO_KW } ; [dyn] => { $ crate :: SyntaxKind :: DYN_KW } ; [else] => { $ crate :: SyntaxKind :: ELSE_KW } ; [enum] => { $ crate :: SyntaxKind :: ENUM_KW } ; [extern] => { $ crate :: SyntaxKind :: EXTERN_KW } ; [false] => { $ crate :: SyntaxKind :: FALSE_KW } ; [fn] => { $ crate :: SyntaxKind :: FN_KW } ; [for] => { $ crate :: SyntaxKind :: FOR_KW } ; [if] => { $ crate :: SyntaxKind :: IF_KW } ; [impl] => { $ crate :: SyntaxKind :: IMPL_KW } ; [in] => { $ crate :: SyntaxKind :: IN_KW } ; [let] => { $ crate :: SyntaxKind :: LET_KW } ; [loop] => { $ crate :: SyntaxKind :: LOOP_KW } ; [macro] => { $ crate :: SyntaxKind :: MACRO_KW } ; [match] => { $ crate :: SyntaxKind :: MATCH_KW } ; [mod] => { $ crate :: SyntaxKind :: MOD_KW } ; [move] => { $ crate :: SyntaxKind :: MOVE_KW } ; [mut] => { $ crate :: SyntaxKind :: MUT_KW } ; [pub] => { $ crate :: SyntaxKind :: PUB_KW } ; [ref] => { $ crate :: SyntaxKind :: REF_KW } ; [return] => { $ crate :: SyntaxKind :: RETURN_KW } ; [self] => { $ crate :: SyntaxKind :: SELF_KW } ; [Self] => { $ crate :: SyntaxKind :: SELF_TYPE_KW } ; [static] => { $ crate :: SyntaxKind :: STATIC_KW } ; [struct] => { $ crate :: SyntaxKind :: STRUCT_KW } ; [super] => { $ crate :: SyntaxKind :: SUPER_KW } ; [trait] => { $ crate :: SyntaxKind :: TRAIT_KW } ; [true] => { $ crate :: SyntaxKind :: TRUE_KW } ; [try] => { $ crate :: SyntaxKind :: TRY_KW } ; [type] => { $ crate :: SyntaxKind :: TYPE_KW } ; [unsafe] => { $ crate :: SyntaxKind :: UNSAFE_KW } ; [use] => { $ crate :: SyntaxKind :: USE_KW } ; [where] => { $ crate :: SyntaxKind :: WHERE_KW } ; [while] => { $ crate :: SyntaxKind :: WHILE_KW } ; [yield] => { $ crate :: SyntaxKind :: YIELD_KW } ; [auto] => { $ crate :: SyntaxKind :: AUTO_KW } ; [builtin] => { $ crate :: SyntaxKind :: BUILTIN_KW } ; [default] => { $ crate :: SyntaxKind :: DEFAULT_KW } ; [existential] => { $ crate :: SyntaxKind :: EXISTENTIAL_KW } ; [union] => { $ crate :: SyntaxKind :: UNION_KW } ; [raw] => { $ crate :: SyntaxKind :: RAW_KW } ; [macro_rules] => { $ crate :: SyntaxKind :: MACRO_RULES_KW } ; [yeet] => { $ crate :: SyntaxKind :: YEET_KW } ; [offset_of] => { $ crate :: SyntaxKind :: OFFSET_OF_KW } ; [asm] => { $ crate :: SyntaxKind :: ASM_KW } ; [format_args] => { $ crate :: SyntaxKind :: FORMAT_ARGS_KW } ; [lifetime_ident] => { $ crate :: SyntaxKind :: LIFETIME_IDENT } ; [ident] => { $ crate :: SyntaxKind :: IDENT } ; [shebang] => { $ crate :: SyntaxKind :: SHEBANG } ; }
500-
pub use T;
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![deny(unused_imports)]
2+
3+
mod a {}
4+
5+
pub use a::*;
6+
//~^ ERROR: unused import: `a::*`
7+
8+
mod b {
9+
mod c {
10+
#[derive(Clone)]
11+
pub struct D;
12+
}
13+
pub use self::c::*; // don't show unused import lint
14+
}
15+
16+
pub use b::*; // don't show unused import lint
17+
18+
mod d {
19+
const D: i32 = 1;
20+
}
21+
22+
pub use d::*;
23+
//~^ ERROR: unused import: `d::*`
24+
25+
fn main() {}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: unused import: `a::*`
2+
--> $DIR/pub-reexport-empty.rs:5:9
3+
|
4+
LL | pub use a::*;
5+
| ^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/pub-reexport-empty.rs:1:9
9+
|
10+
LL | #![deny(unused_imports)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: unused import: `d::*`
14+
--> $DIR/pub-reexport-empty.rs:22:9
15+
|
16+
LL | pub use d::*;
17+
| ^^^^
18+
19+
error: aborting due to 2 previous errors
20+

tests/ui/imports/reexports.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ mod a {
55
mod foo {}
66

77
mod a {
8-
pub use super::foo; //~ ERROR cannot be re-exported
8+
pub use super::foo;
9+
//~^ ERROR cannot be re-exported
10+
//~| WARNING unused import: `super::foo`
911
pub use super::*;
1012
//~^ WARNING glob import doesn't reexport anything because no candidate is public enough
13+
//~| WARNING unused import: `super::*`
1114
}
1215
}
1316

tests/ui/imports/reexports.stderr

+23-11
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,64 @@ LL | pub use super::foo;
1111
| ^^^^^^^^^^
1212

1313
error[E0603]: module import `foo` is private
14-
--> $DIR/reexports.rs:33:15
14+
--> $DIR/reexports.rs:36:15
1515
|
1616
LL | use b::a::foo::S;
1717
| ^^^ private module import
1818
|
1919
note: the module import `foo` is defined here...
20-
--> $DIR/reexports.rs:21:17
20+
--> $DIR/reexports.rs:24:17
2121
|
2222
LL | pub use super::foo; // This is OK since the value `foo` is visible enough.
2323
| ^^^^^^^^^^
2424
note: ...and refers to the module `foo` which is defined here
25-
--> $DIR/reexports.rs:16:5
25+
--> $DIR/reexports.rs:19:5
2626
|
2727
LL | mod foo {
2828
| ^^^^^^^
2929

3030
error[E0603]: module import `foo` is private
31-
--> $DIR/reexports.rs:34:15
31+
--> $DIR/reexports.rs:37:15
3232
|
3333
LL | use b::b::foo::S as T;
3434
| ^^^ private module import
3535
|
3636
note: the module import `foo` is defined here...
37-
--> $DIR/reexports.rs:26:17
37+
--> $DIR/reexports.rs:29:17
3838
|
3939
LL | pub use super::*; // This is also OK since the value `foo` is visible enough.
4040
| ^^^^^^^^
4141
note: ...and refers to the module `foo` which is defined here
42-
--> $DIR/reexports.rs:16:5
42+
--> $DIR/reexports.rs:19:5
4343
|
4444
LL | mod foo {
4545
| ^^^^^^^
4646

47-
warning: glob import doesn't reexport anything because no candidate is public enough
48-
--> $DIR/reexports.rs:9:17
47+
warning: unused import: `super::foo`
48+
--> $DIR/reexports.rs:8:17
4949
|
50-
LL | pub use super::*;
51-
| ^^^^^^^^
50+
LL | pub use super::foo;
51+
| ^^^^^^^^^^
5252
|
5353
note: the lint level is defined here
5454
--> $DIR/reexports.rs:1:9
5555
|
5656
LL | #![warn(unused_imports)]
5757
| ^^^^^^^^^^^^^^
5858

59-
error: aborting due to 3 previous errors; 1 warning emitted
59+
warning: glob import doesn't reexport anything because no candidate is public enough
60+
--> $DIR/reexports.rs:11:17
61+
|
62+
LL | pub use super::*;
63+
| ^^^^^^^^
64+
65+
warning: unused import: `super::*`
66+
--> $DIR/reexports.rs:11:17
67+
|
68+
LL | pub use super::*;
69+
| ^^^^^^^^
70+
71+
error: aborting due to 3 previous errors; 3 warnings emitted
6072

6173
Some errors have detailed explanations: E0364, E0603.
6274
For more information about an error, try `rustc --explain E0364`.

tests/ui/lint/unused/lint-unused-imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ mod foo {
4444

4545
mod bar {
4646
// Don't ignore on 'pub use' because we're not sure if it's used or not
47-
pub use std::cmp::PartialEq;
47+
pub use std::cmp::PartialEq; //~ ERROR unused import: `std::cmp::PartialEq`
4848
pub struct Square;
4949

5050
pub mod c {

tests/ui/lint/unused/lint-unused-imports.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ error: unused import: `bar`
2828
LL | use test2::{foo, bar};
2929
| ^^^
3030

31+
error: unused import: `std::cmp::PartialEq`
32+
--> $DIR/lint-unused-imports.rs:47:13
33+
|
34+
LL | pub use std::cmp::PartialEq;
35+
| ^^^^^^^^^^^^^^^^^^^
36+
3137
error: unused import: `foo::Square`
3238
--> $DIR/lint-unused-imports.rs:52:13
3339
|
@@ -74,5 +80,5 @@ error: unused import: `test::B2`
7480
LL | use test::B2;
7581
| ^^^^^^^^
7682

77-
error: aborting due to 10 previous errors
83+
error: aborting due to 11 previous errors
7884

tests/ui/parser/recover-missing-semi-before-item.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-rustfix
22

3-
#![allow(unused_variables, dead_code)]
3+
#![allow(unused_variables, dead_code, unused_imports)]
44

55
fn for_struct() {
66
let foo = 3; //~ ERROR expected `;`, found keyword `struct`

tests/ui/parser/recover-missing-semi-before-item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-rustfix
22

3-
#![allow(unused_variables, dead_code)]
3+
#![allow(unused_variables, dead_code, unused_imports)]
44

55
fn for_struct() {
66
let foo = 3 //~ ERROR expected `;`, found keyword `struct`

tests/ui/privacy/issue-46209-private-enum-variant-reexport.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
mod rank {
33
pub use self::Professor::*;
44
//~^ ERROR glob import doesn't reexport anything
5+
//~| ERROR unused import: `self::Professor::*`
56
pub use self::Lieutenant::{JuniorGrade, Full};
67
//~^ ERROR `JuniorGrade` is private, and cannot be re-exported
78
//~| ERROR `Full` is private, and cannot be re-exported
9+
//~| ERROR unused imports: `Full`, `JuniorGrade`
810
pub use self::PettyOfficer::*;
911
//~^ ERROR glob import doesn't reexport anything
12+
//~| ERROR unused import: `self::PettyOfficer::*`
1013
pub use self::Crewman::*;
1114
//~^ ERROR glob import doesn't reexport anything
15+
//~| ERROR unused import: `self::Crewman::*`
1216

1317
enum Professor {
1418
Adjunct,

0 commit comments

Comments
 (0)