Skip to content

Commit 9314e5b

Browse files
committed
rustc_hir: Change representation of import paths to support multiple resolutions
1 parent 4f8c49e commit 9314e5b

File tree

5 files changed

+41
-32
lines changed

5 files changed

+41
-32
lines changed

clippy_lints/src/disallowed_types.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedTypes {
106106

107107
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
108108
if let ItemKind::Use(path, UseKind::Single) = &item.kind {
109-
self.check_res_emit(cx, &path.res, item.span);
109+
for res in &path.res {
110+
self.check_res_emit(cx, res, item.span);
111+
}
110112
}
111113
}
112114

clippy_lints/src/macro_use.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
9494
let hir_id = item.hir_id();
9595
let attrs = cx.tcx.hir().attrs(hir_id);
9696
if let Some(mac_attr) = attrs.iter().find(|attr| attr.has_name(sym::macro_use));
97-
if let Res::Def(DefKind::Mod, id) = path.res;
97+
if let Some(id) = path.res.iter().find_map(|res| match res {
98+
Res::Def(DefKind::Mod, id) => Some(id),
99+
_ => None,
100+
});
98101
if !id.is_local();
99102
then {
100103
for kid in cx.tcx.module_children(id).iter() {

clippy_lints/src/missing_enforced_import_rename.rs

+31-28
Original file line numberDiff line numberDiff line change
@@ -66,35 +66,38 @@ impl LateLintPass<'_> for ImportRename {
6666
}
6767

6868
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
69-
if_chain! {
70-
if let ItemKind::Use(path, UseKind::Single) = &item.kind;
71-
if let Res::Def(_, id) = path.res;
72-
if let Some(name) = self.renames.get(&id);
73-
// Remove semicolon since it is not present for nested imports
74-
let span_without_semi = cx.sess().source_map().span_until_char(item.span, ';');
75-
if let Some(snip) = snippet_opt(cx, span_without_semi);
76-
if let Some(import) = match snip.split_once(" as ") {
77-
None => Some(snip.as_str()),
78-
Some((import, rename)) => {
79-
if rename.trim() == name.as_str() {
80-
None
81-
} else {
82-
Some(import.trim())
69+
if let ItemKind::Use(path, UseKind::Single) = &item.kind {
70+
for &res in &path.res {
71+
if_chain! {
72+
if let Res::Def(_, id) = res;
73+
if let Some(name) = self.renames.get(&id);
74+
// Remove semicolon since it is not present for nested imports
75+
let span_without_semi = cx.sess().source_map().span_until_char(item.span, ';');
76+
if let Some(snip) = snippet_opt(cx, span_without_semi);
77+
if let Some(import) = match snip.split_once(" as ") {
78+
None => Some(snip.as_str()),
79+
Some((import, rename)) => {
80+
if rename.trim() == name.as_str() {
81+
None
82+
} else {
83+
Some(import.trim())
84+
}
85+
},
86+
};
87+
then {
88+
span_lint_and_sugg(
89+
cx,
90+
MISSING_ENFORCED_IMPORT_RENAMES,
91+
span_without_semi,
92+
"this import should be renamed",
93+
"try",
94+
format!(
95+
"{import} as {name}",
96+
),
97+
Applicability::MachineApplicable,
98+
);
8399
}
84-
},
85-
};
86-
then {
87-
span_lint_and_sugg(
88-
cx,
89-
MISSING_ENFORCED_IMPORT_RENAMES,
90-
span_without_semi,
91-
"this import should be renamed",
92-
"try",
93-
format!(
94-
"{import} as {name}",
95-
),
96-
Applicability::MachineApplicable,
97-
);
100+
}
98101
}
99102
}
100103
}

clippy_lints/src/redundant_pub_crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
8484

8585
fn is_not_macro_export<'tcx>(item: &'tcx Item<'tcx>) -> bool {
8686
if let ItemKind::Use(path, _) = item.kind {
87-
if let Res::Def(DefKind::Macro(MacroKind::Bang), _) = path.res {
87+
if path.res.iter().all(|res| matches!(res, Res::Def(DefKind::Macro(MacroKind::Bang), _))) {
8888
return false;
8989
}
9090
} else if let ItemKind::Macro(..) = item.kind {

clippy_lints/src/wildcard_imports.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ impl LateLintPass<'_> for WildcardImports {
176176
format!("{import_source_snippet}::{imports_string}")
177177
};
178178

179-
let (lint, message) = if let Res::Def(DefKind::Enum, _) = use_path.res {
179+
// Glob imports always have a single resolution.
180+
let (lint, message) = if let Res::Def(DefKind::Enum, _) = use_path.res[0] {
180181
(ENUM_GLOB_USE, "usage of wildcard import for enum variants")
181182
} else {
182183
(WILDCARD_IMPORTS, "usage of wildcard import")

0 commit comments

Comments
 (0)