Skip to content

Commit 98a8263

Browse files
committed
add limitation
1 parent a1db83a commit 98a8263

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

clippy_lints/src/disallowed_modules.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ declare_clippy_lint! {
2020
///
2121
/// ### Why is this bad?
2222
/// Some modules are undesirable in certain contexts.
23-
///
23+
/// ### Known limitations
24+
/// Items that are not defined in the banned module and not imported via the banned module are not flagged.
2425
/// ### Example:
2526
/// An example clippy.toml configuration:
2627
/// ```toml
@@ -132,12 +133,11 @@ pub fn def_kind_predicate(def_kind: DefKind) -> bool {
132133
impl<'tcx> LateLintPass<'tcx> for DisallowedModules {
133134
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx rustc_hir::Item<'tcx>) {
134135
match item.kind {
135-
ItemKind::Use(path, UseKind::Single(_) | UseKind::Glob) => {
136+
ItemKind::Use(path, UseKind::Single(_) | UseKind::Glob)
136137
if self.check_path_segments(cx, path.segments.iter(), path.span).is_some()
137-
&& let Some(res) = path.res.type_ns
138-
{
139-
self.check_res_emit(cx, &res, path.span);
140-
}
138+
&& let Some(res) = path.res.type_ns =>
139+
{
140+
self.check_res_emit(cx, &res, path.span);
141141
},
142142
ItemKind::Impl(impl_trait)
143143
if let Some(trait_ref) = impl_trait.of_trait

tests/ui-toml/disallowed_modules/disallowed_modules.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ use syn::token::Token;
2727

2828
mod inner {
2929
// allow import via this module
30-
pub mod sync {
31-
#![allow(clippy::disallowed_modules)]
32-
pub use std::sync::*;
33-
}
30+
#![allow(clippy::disallowed_modules)]
31+
pub use std::sync::{Mutex, Weak};
3432
}
3533

36-
// Does not get flagged because DefID parent is alloc::sync, not std::sync, and path is inner::Weak,
37-
// not std::sync::Weak.
38-
use inner::sync::Weak;
34+
// Weak does not get flagged because it is defined in alloc::sync, which is not banned, not
35+
// std::sync and its path is inner::Weak, which is also not banned, not std::sync::Weak.
36+
// Note that importing Mutex still fails, since it is defined in std::sync, which is banned.
37+
use inner::{Mutex as StdMutex, Weak as InnerWeak};
38+
//~^ disallowed_modules
3939

4040
type DisallowedAlias = std::collections::BTreeMap<u32, u32>;
4141
//~^ disallowed_modules

tests/ui-toml/disallowed_modules/disallowed_modules.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ error: use of a disallowed module `syn::token`
6969
LL | use syn::token::Token;
7070
| ^^^^^^^^^^^^^^^^^
7171

72+
error: use of a disallowed module `std::sync`
73+
--> tests/ui-toml/disallowed_modules/disallowed_modules.rs:37:13
74+
|
75+
LL | use inner::{Mutex as StdMutex, Weak as InnerWeak};
76+
| ^^^^^
77+
7278
error: use of a disallowed module `std::collections`
7379
--> tests/ui-toml/disallowed_modules/disallowed_modules.rs:40:24
7480
|
@@ -315,5 +321,5 @@ LL | && let Some(std::net::Shutdown::Both) = None
315321
|
316322
= note: no net allowed
317323

318-
error: aborting due to 50 previous errors
324+
error: aborting due to 51 previous errors
319325

0 commit comments

Comments
 (0)