about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2021-02-19 02:49:08 +0100
committerGitHub <noreply@github.com>2021-02-19 02:49:08 +0100
commit2c302b246ede1bc03be3b9ecabdde7e775fe02e2 (patch)
treeffb80682163d0afc0fe6a6c62ebc69df65b21131
parent6e12a2f9e225e97fbc041b7201d5821e46e2439f (diff)
parentb185fa3ae233b234760990f4e84bb5fcfd0ca499 (diff)
downloadrust-2c302b246ede1bc03be3b9ecabdde7e775fe02e2.tar.gz
rust-2c302b246ede1bc03be3b9ecabdde7e775fe02e2.zip
Rollup merge of #82238 - petrochenkov:nocratemod, r=Aaron1011
ast: Keep expansion status for out-of-line module items

I.e. whether a module `mod foo;` is already loaded from a file or not.
This is a pre-requisite to correctly treating inner attributes on such modules (https://github.com/rust-lang/rust/issues/81661).

With this change AST structures for `mod` items diverge even more for AST structure for the crate root, which previously used `ast::Mod`.
Therefore this PR removes `ast::Mod` from `ast::Crate` in the first commit, these two things are sufficiently different from each other, at least at syntactic level.
Customization points for visiting a "`mod` item or crate root" were also removed from AST visitors (`fn visit_mod`).
`ast::Mod` itself was refactored away in the second commit in favor of `ItemKind::Mod(Unsafe, ModKind)`.
-rw-r--r--clippy_lints/src/utils/ast_utils.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/clippy_lints/src/utils/ast_utils.rs b/clippy_lints/src/utils/ast_utils.rs
index 64232646972..9ff7ef7cc3b 100644
--- a/clippy_lints/src/utils/ast_utils.rs
+++ b/clippy_lints/src/utils/ast_utils.rs
@@ -241,9 +241,12 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
                 && eq_generics(lg, rg)
                 && both(lb, rb, |l, r| eq_block(l, r))
         }
-        (Mod(l), Mod(r)) => {
-            l.inline == r.inline && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_item_kind))
-        }
+        (Mod(lu, lmk), Mod(ru, rmk)) => lu == ru && match (lmk, rmk) {
+            (ModKind::Loaded(litems, linline, _), ModKind::Loaded(ritems, rinline, _)) =>
+                linline == rinline && over(litems, ritems, |l, r| eq_item(l, r, eq_item_kind)),
+            (ModKind::Unloaded, ModKind::Unloaded) => true,
+            _ => false,
+        },
         (ForeignMod(l), ForeignMod(r)) => {
             both(&l.abi, &r.abi, |l, r| eq_str_lit(l, r))
                 && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_foreign_item_kind))