Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea13461

Browse files
authored
Don't warn about unloaded crates (#14733)
Fixes #14397 (comment) r? @samueltardieu changelog: Don't warn about clippy.toml disallowed paths for crates that were not loaded
2 parents 56f0182 + 7b7a9a6 commit ea13461

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

clippy_config/src/types.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::PrimTy;
44
use rustc_hir::def::{DefKind, Res};
55
use rustc_hir::def_id::DefIdMap;
66
use rustc_middle::ty::TyCtxt;
7-
use rustc_span::Span;
7+
use rustc_span::{Span, Symbol};
88
use serde::de::{self, Deserializer, Visitor};
99
use serde::{Deserialize, Serialize, ser};
1010
use std::collections::HashMap;
@@ -145,7 +145,8 @@ pub fn create_disallowed_map<const REPLACEMENT_ALLOWED: bool>(
145145
FxHashMap::default();
146146
for disallowed_path in disallowed_paths {
147147
let path = disallowed_path.path();
148-
let mut resolutions = clippy_utils::def_path_res(tcx, &path.split("::").collect::<Vec<_>>());
148+
let path_split = path.split("::").collect::<Vec<_>>();
149+
let mut resolutions = clippy_utils::def_path_res(tcx, &path_split);
149150

150151
let mut found_def_id = None;
151152
let mut found_prim_ty = false;
@@ -160,8 +161,12 @@ pub fn create_disallowed_map<const REPLACEMENT_ALLOWED: bool>(
160161
},
161162
_ => false,
162163
});
163-
164-
if resolutions.is_empty() {
164+
if resolutions.is_empty()
165+
// Don't warn about unloaded crates:
166+
// https://github.com/rust-lang/rust-clippy/pull/14397#issuecomment-2848328221
167+
&& (path_split.len() < 2
168+
|| !clippy_utils::find_crates(tcx, Symbol::intern(path_split[0])).is_empty())
169+
{
165170
let span = disallowed_path.span();
166171

167172
if let Some(def_id) = found_def_id {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# The first two `disallowed-methods` paths should generate warnings, but the third should not.
2+
3+
[[disallowed-methods]]
4+
path = "regex::Regex::new_"
5+
6+
[[disallowed-methods]]
7+
path = "regex::Regex_::new"
8+
9+
[[disallowed-methods]]
10+
path = "regex_::Regex::new"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@error-in-other-file: `regex::Regex::new_` does not refer to an existing function
2+
//@error-in-other-file: `regex::Regex_::new` does not refer to an existing function
3+
4+
extern crate regex;
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: `regex::Regex::new_` does not refer to an existing function
2+
--> $DIR/tests/ui-toml/toml_unloaded_crate/clippy.toml:3:1
3+
|
4+
LL | / [[disallowed-methods]]
5+
LL | | path = "regex::Regex::new_"
6+
| |___________________________^
7+
8+
warning: `regex::Regex_::new` does not refer to an existing function
9+
--> $DIR/tests/ui-toml/toml_unloaded_crate/clippy.toml:6:1
10+
|
11+
LL | / [[disallowed-methods]]
12+
LL | | path = "regex::Regex_::new"
13+
| |___________________________^
14+
15+
warning: 2 warnings emitted
16+

0 commit comments

Comments
 (0)