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.
This commit is contained in:
Vadim Petrochenkov 2022-12-01 18:51:20 +03:00
parent 9314e5b942
commit b0d490e308
5 changed files with 10 additions and 10 deletions

View File

@ -149,7 +149,7 @@ fn track_uses(
// keep track of `use some_module;` usages
if segments.len() == 1 {
if let UseTreeKind::Simple(None, _, _) = use_tree.kind {
if let UseTreeKind::Simple(None) = use_tree.kind {
let name = segments[0].ident.name;
if !macros.contains(&name) {
single_use_usages.push(SingleUse {
@ -169,7 +169,7 @@ fn track_uses(
for tree in trees {
let segments = &tree.0.prefix.segments;
if segments.len() == 1 {
if let UseTreeKind::Simple(None, _, _) = tree.0.kind {
if let UseTreeKind::Simple(None) = tree.0.kind {
let name = segments[0].ident.name;
if !macros.contains(&name) {
single_use_usages.push(SingleUse {

View File

@ -57,7 +57,7 @@ fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
format!(
"{}{};",
last_segment.ident,
if let UseTreeKind::Simple(Some(alias), ..) = self_tree.kind { format!(" as {alias}") } else { String::new() },
if let UseTreeKind::Simple(Some(alias)) = self_tree.kind { format!(" as {alias}") } else { String::new() },
),
Applicability::MaybeIncorrect,
);

View File

@ -39,7 +39,7 @@ fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) {
match use_tree.kind {
UseTreeKind::Simple(Some(new_name), ..) => {
UseTreeKind::Simple(Some(new_name)) => {
let old_name = use_tree
.prefix
.segments
@ -48,7 +48,7 @@ fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) {
.ident;
unsafe_to_safe_check(old_name, new_name, cx, span);
},
UseTreeKind::Simple(None, ..) | UseTreeKind::Glob => {},
UseTreeKind::Simple(None) | UseTreeKind::Glob => {},
UseTreeKind::Nested(ref nested_use_tree) => {
for (use_tree, _) in nested_use_tree {
check_use_tree(use_tree, cx, span);

View File

@ -566,7 +566,7 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool {
use UseTreeKind::*;
match (l, r) {
(Glob, Glob) => true,
(Simple(l, _, _), Simple(r, _, _)) => both(l, r, |l, r| eq_id(*l, *r)),
(Simple(l), Simple(r)) => both(l, r, |l, r| eq_id(*l, *r)),
(Nested(l), Nested(r)) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)),
_ => false,
}

View File

@ -1,8 +1,8 @@
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_imports.rs:23:5
--> $DIR/macro_use_imports.rs:25:5
|
LL | #[macro_use]
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};`
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;`
|
= note: `-D clippy::macro-use-imports` implied by `-D warnings`
@ -13,10 +13,10 @@ LL | #[macro_use]
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;`
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_imports.rs:25:5
--> $DIR/macro_use_imports.rs:23:5
|
LL | #[macro_use]
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;`
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};`
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_imports.rs:19:5