Skip to content

Commit a1d2280

Browse files
committed
Auto merge of rust-lang#104963 - petrochenkov:noaddids2, r=cjgillot
rustc_ast_lowering: Stop lowering imports into multiple items Lower them into a single item with multiple resolutions instead. This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2 parents d05e286 + b0d490e commit a1d2280

15 files changed

+57
-48
lines changed

clippy_lints/src/disallowed_types.rs

Lines changed: 3 additions & 1 deletion
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/from_over_into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SelfFinder<'a, 'tcx> {
126126
self.cx.tcx.hir()
127127
}
128128

129-
fn visit_path(&mut self, path: &'tcx Path<'tcx>, _id: HirId) {
129+
fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) {
130130
for segment in path.segments {
131131
match segment.ident.name {
132132
kw::SelfLower => self.lower.push(segment.ident.span),

clippy_lints/src/macro_use.rs

Lines changed: 4 additions & 1 deletion
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/methods/option_map_unwrap_or.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct UnwrapVisitor<'a, 'tcx> {
9797
impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> {
9898
type NestedFilter = nested_filter::All;
9999

100-
fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
100+
fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) {
101101
self.identifiers.insert(ident(path));
102102
walk_path(self, path);
103103
}
@@ -116,7 +116,7 @@ struct MapExprVisitor<'a, 'tcx> {
116116
impl<'a, 'tcx> Visitor<'tcx> for MapExprVisitor<'a, 'tcx> {
117117
type NestedFilter = nested_filter::All;
118118

119-
fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
119+
fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) {
120120
if self.identifiers.contains(&ident(path)) {
121121
self.found_identifier = true;
122122
return;

clippy_lints/src/missing_enforced_import_rename.rs

Lines changed: 31 additions & 28 deletions
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

Lines changed: 1 addition & 1 deletion
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/single_component_path_imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl SingleComponentPathImports {
149149

150150
// keep track of `use some_module;` usages
151151
if segments.len() == 1 {
152-
if let UseTreeKind::Simple(None, _, _) = use_tree.kind {
152+
if let UseTreeKind::Simple(None) = use_tree.kind {
153153
let name = segments[0].ident.name;
154154
if !macros.contains(&name) {
155155
single_use_usages.push(SingleUse {
@@ -169,7 +169,7 @@ impl SingleComponentPathImports {
169169
for tree in trees {
170170
let segments = &tree.0.prefix.segments;
171171
if segments.len() == 1 {
172-
if let UseTreeKind::Simple(None, _, _) = tree.0.kind {
172+
if let UseTreeKind::Simple(None) = tree.0.kind {
173173
let name = segments[0].ident.name;
174174
if !macros.contains(&name) {
175175
single_use_usages.push(SingleUse {

clippy_lints/src/unnecessary_self_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl EarlyLintPass for UnnecessarySelfImports {
5757
format!(
5858
"{}{};",
5959
last_segment.ident,
60-
if let UseTreeKind::Simple(Some(alias), ..) = self_tree.kind { format!(" as {alias}") } else { String::new() },
60+
if let UseTreeKind::Simple(Some(alias)) = self_tree.kind { format!(" as {alias}") } else { String::new() },
6161
),
6262
Applicability::MaybeIncorrect,
6363
);

clippy_lints/src/unsafe_removed_from_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl EarlyLintPass for UnsafeNameRemoval {
3939

4040
fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) {
4141
match use_tree.kind {
42-
UseTreeKind::Simple(Some(new_name), ..) => {
42+
UseTreeKind::Simple(Some(new_name)) => {
4343
let old_name = use_tree
4444
.prefix
4545
.segments
@@ -48,7 +48,7 @@ fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) {
4848
.ident;
4949
unsafe_to_safe_check(old_name, new_name, cx, span);
5050
},
51-
UseTreeKind::Simple(None, ..) | UseTreeKind::Glob => {},
51+
UseTreeKind::Simple(None) | UseTreeKind::Glob => {},
5252
UseTreeKind::Nested(ref nested_use_tree) => {
5353
for (use_tree, _) in nested_use_tree {
5454
check_use_tree(use_tree, cx, span);

clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ struct LintCollector<'a, 'tcx> {
330330
impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> {
331331
type NestedFilter = nested_filter::All;
332332

333-
fn visit_path(&mut self, path: &'tcx Path<'_>, _: HirId) {
333+
fn visit_path(&mut self, path: &Path<'_>, _: HirId) {
334334
if path.segments.len() == 1 {
335335
self.output.insert(path.segments[0].ident.name);
336336
}

0 commit comments

Comments
 (0)