Skip to content

Skip disallowed-* checking for current crate #14768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion clippy_config/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Applicability, Diag};
use rustc_hir::PrimTy;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefIdMap;
use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE};
use rustc_middle::ty::TyCtxt;
use rustc_span::{Span, Symbol};
use serde::de::{self, Deserializer, Visitor};
Expand Down Expand Up @@ -145,9 +145,14 @@ pub fn create_disallowed_map<const REPLACEMENT_ALLOWED: bool>(
let mut def_ids: DefIdMap<(&'static str, &'static DisallowedPath<REPLACEMENT_ALLOWED>)> = DefIdMap::default();
let mut prim_tys: FxHashMap<PrimTy, (&'static str, &'static DisallowedPath<REPLACEMENT_ALLOWED>)> =
FxHashMap::default();
let local_crate = tcx.crate_name(LOCAL_CRATE);
for disallowed_path in disallowed_paths {
let path = disallowed_path.path();
let sym_path: Vec<Symbol> = path.split("::").map(Symbol::intern).collect();
// Skip checking disallowed type for current crate.
if sym_path.first() == Some(&local_crate) {
continue;
}
let mut resolutions = lookup_path(tcx, ns, &sym_path);
resolutions.retain(|&def_id| def_kind_predicate(tcx.def_kind(def_id)));

Expand Down
11 changes: 11 additions & 0 deletions tests/ui-cargo/disallowed_types/fail_local_crate/Cargo.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: use of a disallowed type `foo::Fooo`
--> src/lib.rs:1:1
|
1 | use foo::Fooo;
| ^^^^^^^^^^^^^^
|
= note: Noooooooooo
= note: `-D clippy::disallowed-types` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::disallowed_types)]`

error: could not compile `fail-local-crate` (lib) due to 1 previous error
14 changes: 14 additions & 0 deletions tests/ui-cargo/disallowed_types/fail_local_crate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "fail-local-crate"
version = "0.1.0"
rust-version = "1.56.1"
edition = "2021"
publish = false

[dependencies]
foo.path = "foo"

[workspace]
members = [
"foo",
]
3 changes: 3 additions & 0 deletions tests/ui-cargo/disallowed_types/fail_local_crate/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
disallowed-types = [
{ path = "foo::Fooo", reason = "Noooooooooo" },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub struct Fooo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod fooo;
pub use fooo::Fooo;
5 changes: 5 additions & 0 deletions tests/ui-cargo/disallowed_types/fail_local_crate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use foo::Fooo;

pub fn bar() {
let _foo = Fooo;
}
Loading