let hir_id = item.hir_id();
let attrs = cx.tcx.hir().attrs(hir_id);
if let Some(mac_attr) = attrs.iter().find(|attr| attr.has_name(sym::macro_use));
- if let Res::Def(DefKind::Mod, id) = path.res;
+ if let Some(id) = path.res.iter().find_map(|res| match res {
+ Res::Def(DefKind::Mod, id) => Some(id),
+ _ => None,
+ });
if !id.is_local();
then {
for kid in cx.tcx.module_children(id).iter() {
}
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
- if_chain! {
- if let ItemKind::Use(path, UseKind::Single) = &item.kind;
- if let Res::Def(_, id) = path.res;
- if let Some(name) = self.renames.get(&id);
- // Remove semicolon since it is not present for nested imports
- let span_without_semi = cx.sess().source_map().span_until_char(item.span, ';');
- if let Some(snip) = snippet_opt(cx, span_without_semi);
- if let Some(import) = match snip.split_once(" as ") {
- None => Some(snip.as_str()),
- Some((import, rename)) => {
- if rename.trim() == name.as_str() {
- None
- } else {
- Some(import.trim())
+ if let ItemKind::Use(path, UseKind::Single) = &item.kind {
+ for &res in &path.res {
+ if_chain! {
+ if let Res::Def(_, id) = res;
+ if let Some(name) = self.renames.get(&id);
+ // Remove semicolon since it is not present for nested imports
+ let span_without_semi = cx.sess().source_map().span_until_char(item.span, ';');
+ if let Some(snip) = snippet_opt(cx, span_without_semi);
+ if let Some(import) = match snip.split_once(" as ") {
+ None => Some(snip.as_str()),
+ Some((import, rename)) => {
+ if rename.trim() == name.as_str() {
+ None
+ } else {
+ Some(import.trim())
+ }
+ },
+ };
+ then {
+ span_lint_and_sugg(
+ cx,
+ MISSING_ENFORCED_IMPORT_RENAMES,
+ span_without_semi,
+ "this import should be renamed",
+ "try",
+ format!(
+ "{import} as {name}",
+ ),
+ Applicability::MachineApplicable,
+ );
}
- },
- };
- then {
- span_lint_and_sugg(
- cx,
- MISSING_ENFORCED_IMPORT_RENAMES,
- span_without_semi,
- "this import should be renamed",
- "try",
- format!(
- "{import} as {name}",
- ),
- Applicability::MachineApplicable,
- );
+ }
}
}
}
fn is_not_macro_export<'tcx>(item: &'tcx Item<'tcx>) -> bool {
if let ItemKind::Use(path, _) = item.kind {
- if let Res::Def(DefKind::Macro(MacroKind::Bang), _) = path.res {
+ if path.res.iter().all(|res| matches!(res, Res::Def(DefKind::Macro(MacroKind::Bang), _))) {
return false;
}
} else if let ItemKind::Macro(..) = item.kind {
format!("{import_source_snippet}::{imports_string}")
};
- let (lint, message) = if let Res::Def(DefKind::Enum, _) = use_path.res {
+ // Glob imports always have a single resolution.
+ let (lint, message) = if let Res::Def(DefKind::Enum, _) = use_path.res[0] {
(ENUM_GLOB_USE, "usage of wildcard import for enum variants")
} else {
(WILDCARD_IMPORTS, "usage of wildcard import")