diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 674b6ccf34f9..e92afc14c20d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -152,6 +152,9 @@ jobs: - name: show the current environment run: src/ci/scripts/dump-environment.sh + - name: install rust + run: src/ci/scripts/install-rust.sh + - name: install awscli run: src/ci/scripts/install-awscli.sh diff --git a/.gitignore b/.gitignore index a549b6e6e56c..5988a64916ad 100644 --- a/.gitignore +++ b/.gitignore @@ -85,8 +85,6 @@ __pycache__/ ## Node node_modules -package-lock.json -package.json /src/doc/rustc-dev-guide/mermaid.min.js ## Rustdoc GUI tests diff --git a/.gitmodules b/.gitmodules index 3426b1bc8dbd..439fde6d7660 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,7 +25,7 @@ [submodule "src/llvm-project"] path = src/llvm-project url = https://github.com/rust-lang/llvm-project.git - branch = rustc/20.1-2025-02-13 + branch = rustc/20.1-2025-07-13 shallow = true [submodule "src/doc/embedded-book"] path = src/doc/embedded-book diff --git a/Cargo.lock b/Cargo.lock index 6d823c5b5a59..b7fc2de20b55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -216,7 +216,7 @@ dependencies = [ "memchr", "serde", "serde_derive", - "winnow 0.7.11", + "winnow 0.7.12", ] [[package]] @@ -351,12 +351,6 @@ version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "175812e0be2bccb6abe50bb8d566126198344f707e304f45c648fd8f2cc0365e" -[[package]] -name = "bytes" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" - [[package]] name = "camino" version = "1.1.10" @@ -390,7 +384,7 @@ dependencies = [ name = "cargo-miri" version = "0.1.0" dependencies = [ - "cargo_metadata 0.19.2", + "cargo_metadata 0.21.0", "directories", "rustc-build-sysroot", "rustc_tools_util 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -408,6 +402,31 @@ dependencies = [ "serde", ] +[[package]] +name = "cargo-platform" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84982c6c0ae343635a3a4ee6dedef965513735c8b183caa7289fa6e27399ebd4" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-util-schemas" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dc1a6f7b5651af85774ae5a34b4e8be397d9cf4bc063b7e6dbd99a841837830" +dependencies = [ + "semver", + "serde", + "serde-untagged", + "serde-value", + "thiserror 2.0.12", + "toml 0.8.23", + "unicode-xid", + "url", +] + [[package]] name = "cargo_metadata" version = "0.18.1" @@ -415,7 +434,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" dependencies = [ "camino", - "cargo-platform", + "cargo-platform 0.1.9", "semver", "serde", "serde_json", @@ -429,7 +448,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba" dependencies = [ "camino", - "cargo-platform", + "cargo-platform 0.1.9", + "semver", + "serde", + "serde_json", + "thiserror 2.0.12", +] + +[[package]] +name = "cargo_metadata" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cfca2aaa699835ba88faf58a06342a314a950d2b9686165e038286c30316868" +dependencies = [ + "camino", + "cargo-platform 0.2.0", + "cargo-util-schemas", "semver", "serde", "serde_json", @@ -476,23 +510,12 @@ dependencies = [ [[package]] name = "chrono-tz" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efdce149c370f133a071ca8ef6ea340b7b88748ab0810097a9e2976eaa34b4f3" +checksum = "a6139a8597ed92cf816dfb33f5dd6cf0bb93a6adc938f11039f371bc5bcd26c3" dependencies = [ "chrono", - "chrono-tz-build", - "phf", -] - -[[package]] -name = "chrono-tz-build" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f10f8c9340e31fc120ff885fcdb54a0b48e474bbd77cab557f0c30a3e569402" -dependencies = [ - "parse-zoneinfo", - "phf_codegen", + "phf 0.12.1", ] [[package]] @@ -507,9 +530,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.40" +version = "4.5.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" +checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9" dependencies = [ "clap_builder", "clap_derive", @@ -527,9 +550,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.40" +version = "4.5.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" +checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d" dependencies = [ "anstream", "anstyle", @@ -539,9 +562,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.40" +version = "4.5.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" +checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -569,20 +592,14 @@ dependencies = [ "color-print", "declare_clippy_lint", "filetime", - "futures", - "if_chain", "itertools", - "parking_lot", "pulldown-cmark", - "quote", "regex", "rustc_tools_util 0.4.2", "serde", "serde_json", - "syn 2.0.104", "tempfile", - "termize 0.1.1", - "tokio", + "termize", "toml 0.7.8", "ui_test", "walkdir", @@ -726,6 +743,15 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "colored" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "comma" version = "1.0.0" @@ -739,7 +765,7 @@ dependencies = [ "anstyle-svg", "build_helper", "camino", - "colored", + "colored 2.2.0", "diff", "getopts", "glob", @@ -810,9 +836,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.4.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" dependencies = [ "cfg-if", ] @@ -1001,9 +1027,9 @@ dependencies = [ [[package]] name = "derive_setters" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c848e86c87e5cc305313041c5677d4d95d60baa71cf95e5f6ea2554bb629ff" +checksum = "ae5c625eda104c228c06ecaf988d1c60e542176bd7a490e60eeda3493244c0c9" dependencies = [ "darling", "proc-macro2", @@ -1166,6 +1192,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "erased-serde" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e004d887f51fcb9fef17317a2f3525c887d8aa3f4f50fed920816a688284a5b7" +dependencies = [ + "serde", + "typeid", +] + [[package]] name = "errno" version = "0.3.13" @@ -1322,95 +1358,6 @@ dependencies = [ "new_debug_unreachable", ] -[[package]] -name = "futures" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" - -[[package]] -name = "futures-executor" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" - -[[package]] -name = "futures-macro" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.104", -] - -[[package]] -name = "futures-sink" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" - -[[package]] -name = "futures-task" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" - -[[package]] -name = "futures-util" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - [[package]] name = "generate-copyright" version = "0.1.0" @@ -1848,12 +1795,6 @@ dependencies = [ "icu_properties", ] -[[package]] -name = "if_chain" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed" - [[package]] name = "ignore" version = "0.4.23" @@ -1947,30 +1888,18 @@ dependencies = [ "unic-langid", ] -[[package]] -name = "io-uring" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013" -dependencies = [ - "bitflags", - "cfg-if", - "libc", -] - [[package]] name = "ipc-channel" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8251fb7bcd9ccd3725ed8deae9fe7db8e586495c9eb5b0c52e6233e5e75ea" +checksum = "5b1c98b70019c830a1fc39cecfe1f60ff99c4122f0a189697c810c90ec545c14" dependencies = [ "bincode", "crossbeam-channel", "fnv", - "lazy_static", "libc", "mio", - "rand 0.8.5", + "rand 0.9.1", "serde", "tempfile", "uuid", @@ -2163,9 +2092,9 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] name = "libredox" -version = "0.1.4" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1580801010e535496706ba011c15f8532df6b42297d2e471fec38ceadd8c0638" +checksum = "4488594b9328dee448adb906d8b126d9b7deb7cf5c22161ee591610bb1be83c0" dependencies = [ "bitflags", "libc", @@ -2275,7 +2204,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7a7213d12e1864c0f002f52c2923d4556935a43dec5e71355c2760e0f6e7a18" dependencies = [ "log", - "phf", + "phf 0.11.3", "phf_codegen", "string_cache", "string_cache_codegen", @@ -2314,9 +2243,9 @@ dependencies = [ [[package]] name = "measureme" -version = "12.0.1" +version = "12.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "570a507d8948a66a97f42cbbaf8a6bb9516a51017d4ee949502ad7a10a864395" +checksum = "6ebd1ebda747ae161a4a377bf93f87e18d46faad2331cc0c7d25b84b1d445f49" dependencies = [ "log", "memmap2", @@ -2369,7 +2298,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" dependencies = [ "libc", - "log", "wasi 0.11.1+wasi-snapshot-preview1", "windows-sys 0.59.0", ] @@ -2392,7 +2320,7 @@ dependencies = [ "capstone", "chrono", "chrono-tz", - "colored", + "colored 3.0.0", "directories", "getrandom 0.3.3", "ipc-channel", @@ -2689,6 +2617,15 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "ordered-float" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" +dependencies = [ + "num-traits", +] + [[package]] name = "overload" version = "0.1.1" @@ -2750,15 +2687,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "parse-zoneinfo" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f2a05b18d44e2957b88f96ba460715e295bc1d7510468a2f3d3b44535d26c24" -dependencies = [ - "regex", -] - [[package]] name = "pathdiff" version = "0.2.3" @@ -2830,7 +2758,16 @@ version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" dependencies = [ - "phf_shared", + "phf_shared 0.11.3", +] + +[[package]] +name = "phf" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7" +dependencies = [ + "phf_shared 0.12.1", ] [[package]] @@ -2840,7 +2777,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a" dependencies = [ "phf_generator", - "phf_shared", + "phf_shared 0.11.3", ] [[package]] @@ -2849,7 +2786,7 @@ version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" dependencies = [ - "phf_shared", + "phf_shared 0.11.3", "rand 0.8.5", ] @@ -2862,18 +2799,21 @@ dependencies = [ "siphasher", ] +[[package]] +name = "phf_shared" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06005508882fb681fd97892ecff4b7fd0fee13ef1aa569f8695dae7ab9099981" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project-lite" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "pkg-config" version = "0.3.32" @@ -3214,7 +3154,7 @@ dependencies = [ [[package]] name = "run_make_support" -version = "0.2.0" +version = "0.0.0" dependencies = [ "bstr", "build_helper", @@ -3260,9 +3200,9 @@ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" [[package]] name = "rustc-literal-escaper" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab03008eb631b703dd16978282ae36c73282e7922fe101a4bd072a40ecea7b8b" +checksum = "e4ee29da77c5a54f42697493cd4c9b9f31b74df666a6c04dfc4fde77abe0438b" [[package]] name = "rustc-main" @@ -3271,8 +3211,8 @@ dependencies = [ "rustc_codegen_ssa", "rustc_driver", "rustc_driver_impl", - "rustc_smir", - "stable_mir", + "rustc_public", + "rustc_public_bridge", "tikv-jemalloc-sys", ] @@ -3709,6 +3649,7 @@ dependencies = [ "rustc_passes", "rustc_pattern_analysis", "rustc_privacy", + "rustc_public", "rustc_query_system", "rustc_resolve", "rustc_session", @@ -3718,7 +3659,6 @@ dependencies = [ "rustc_ty_utils", "serde_json", "shlex", - "stable_mir", "tracing", "windows 0.61.3", ] @@ -3773,7 +3713,7 @@ dependencies = [ "serde", "serde_json", "termcolor", - "termize 0.2.0", + "termize", "tracing", "windows 0.61.3", ] @@ -4349,6 +4289,7 @@ dependencies = [ "rustc_ast_lowering", "rustc_ast_pretty", "rustc_attr_data_structures", + "rustc_attr_parsing", "rustc_data_structures", "rustc_errors", "rustc_expand", @@ -4414,6 +4355,36 @@ dependencies = [ "rustc-literal-escaper", ] +[[package]] +name = "rustc_public" +version = "0.1.0-preview" +dependencies = [ + "rustc_abi", + "rustc_hir", + "rustc_middle", + "rustc_public_bridge", + "rustc_session", + "rustc_span", + "rustc_target", + "scoped-tls", + "serde", + "tracing", +] + +[[package]] +name = "rustc_public_bridge" +version = "0.0.0" +dependencies = [ + "rustc_abi", + "rustc_data_structures", + "rustc_hir", + "rustc_hir_pretty", + "rustc_middle", + "rustc_session", + "rustc_span", + "rustc_target", +] + [[package]] name = "rustc_query_impl" version = "0.0.0" @@ -4536,25 +4507,11 @@ dependencies = [ "rustc_serialize", "rustc_span", "rustc_target", - "termize 0.2.0", + "termize", "tracing", "windows 0.61.3", ] -[[package]] -name = "rustc_smir" -version = "0.0.0" -dependencies = [ - "rustc_abi", - "rustc_data_structures", - "rustc_hir", - "rustc_hir_pretty", - "rustc_middle", - "rustc_session", - "rustc_span", - "rustc_target", -] - [[package]] name = "rustc_span" version = "0.0.0" @@ -4859,15 +4816,15 @@ dependencies = [ [[package]] name = "rustix" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" +checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -4954,6 +4911,27 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-untagged" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "299d9c19d7d466db4ab10addd5703e4c615dec2a5a16dbbafe191045e87ee66e" +dependencies = [ + "erased-serde", + "serde", + "typeid", +] + +[[package]] +name = "serde-value" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" +dependencies = [ + "ordered-float", + "serde", +] + [[package]] name = "serde_derive" version = "1.0.219" @@ -4967,9 +4945,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.140" +version = "1.0.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3" dependencies = [ "itoa", "memchr", @@ -5035,12 +5013,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" -[[package]] -name = "slab" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d" - [[package]] name = "smallvec" version = "1.15.1" @@ -5059,10 +5031,11 @@ dependencies = [ [[package]] name = "spanned" -version = "0.3.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86af297923fbcfd107c20a189a6e9c872160df71a7190ae4a7a6c5dce4b2feb6" +checksum = "c92d4b0c055fde758f086eb4a6e73410247df8a3837fd606d2caeeaf72aa566d" dependencies = [ + "anyhow", "bstr", "color-eyre", ] @@ -5102,22 +5075,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "stable_mir" -version = "0.1.0-preview" -dependencies = [ - "rustc_abi", - "rustc_hir", - "rustc_middle", - "rustc_session", - "rustc_smir", - "rustc_span", - "rustc_target", - "scoped-tls", - "serde", - "tracing", -] - [[package]] name = "stacker" version = "0.1.21" @@ -5145,7 +5102,7 @@ checksum = "bf776ba3fa74f83bf4b63c3dcbbf82173db2632ed8452cb2d891d33f459de70f" dependencies = [ "new_debug_unreachable", "parking_lot", - "phf_shared", + "phf_shared 0.11.3", "precomputed-hash", "serde", ] @@ -5157,7 +5114,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c711928715f1fe0fe509c53b43e993a9a557babc2d0a3567d0a3006f1ac931a0" dependencies = [ "phf_generator", - "phf_shared", + "phf_shared 0.11.3", "proc-macro2", "quote", ] @@ -5187,14 +5144,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "suggest-tests" -version = "0.1.0" -dependencies = [ - "build_helper", - "glob", -] - [[package]] name = "syn" version = "1.0.109" @@ -5230,9 +5179,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.35.2" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3ffa3e4ff2b324a57f7aeb3c349656c7b127c3c189520251a648102a92496e" +checksum = "252800745060e7b9ffb7b2badbd8b31cfa4aa2e61af879d0a3bf2a317c20217d" dependencies = [ "libc", "objc2-core-foundation", @@ -5305,16 +5254,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "termize" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1706be6b564323ce7092f5f7e6b118a14c8ef7ed0e69c8c5329c914a9f101295" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "termize" version = "0.2.0" @@ -5480,21 +5419,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "tokio" -version = "1.46.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17" -dependencies = [ - "backtrace", - "bytes", - "io-uring", - "libc", - "mio", - "pin-project-lite", - "slab", -] - [[package]] name = "toml" version = "0.5.11" @@ -5562,7 +5486,7 @@ dependencies = [ "serde_spanned", "toml_datetime", "toml_write", - "winnow 0.7.11", + "winnow 0.7.12", ] [[package]] @@ -5682,6 +5606,12 @@ dependencies = [ "rustc-hash 2.1.1", ] +[[package]] +name = "typeid" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c" + [[package]] name = "typenum" version = "1.18.0" @@ -5705,17 +5635,17 @@ checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" [[package]] name = "ui_test" -version = "0.29.2" +version = "0.30.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1211b1111c752c73b33073d2958072be08825fd97c9ab4d83444da361a06634b" +checksum = "b56a6897cc4bb6f8daf1939b0b39cd9645856997f46f4d0b3e3cb7122dfe9251" dependencies = [ "annotate-snippets 0.11.5", "anyhow", "bstr", - "cargo-platform", + "cargo-platform 0.1.9", "cargo_metadata 0.18.1", "color-eyre", - "colored", + "colored 2.2.0", "comma", "crossbeam-channel", "indicatif", @@ -5954,9 +5884,9 @@ dependencies = [ [[package]] name = "wasi-preview1-component-adapter-provider" -version = "34.0.1" +version = "34.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafa1e6af9a954a4bcf6ef420c33355d0ce84ddc6afbcba7bb6f05126f9120ae" +checksum = "33696c5f1ff1e083de9f36c3da471abd736362bc173e093f8b0b1ed5a387e39b" [[package]] name = "wasm-bindgen" @@ -6600,9 +6530,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.7.11" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" +checksum = "f3edebf492c8125044983378ecb5766203ad3b4c2f7a922bd7dd207f6d443e95" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 6d3425f4115a..67c7a9d67edc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,6 @@ members = [ "src/tools/rustdoc-gui-test", "src/tools/rustdoc-themes", "src/tools/rustfmt", - "src/tools/suggest-tests", "src/tools/test-float-parse", "src/tools/tidy", "src/tools/tier-check", diff --git a/REUSE.toml b/REUSE.toml index 027b4ccbe259..13aa3e0a4112 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -37,6 +37,8 @@ path = [ "rust-bors.toml", "triagebot.toml", "typos.toml", + "package.json", + "package-lock.json", "x", "x.ps1", "x.py", diff --git a/bootstrap.example.toml b/bootstrap.example.toml index b59f112bdfb8..73e93ccbe420 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -392,7 +392,8 @@ # For example, to build Miri with tracing support, use `tool.miri.features = ["tracing"]` # # The default value for the `features` array is `[]`. However, please note that other flags in -# `bootstrap.toml` might influence the features enabled for some tools. +# `bootstrap.toml` might influence the features enabled for some tools. Also, enabling features +# in tools which are not part of the internal "extra-features" preset might not always work. #build.tool.TOOL_NAME.features = [FEATURE1, FEATURE2] # Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose, 3 == print environment variables on each rustc invocation diff --git a/compiler/rustc/Cargo.toml b/compiler/rustc/Cargo.toml index f4caa3ef769d..3ca752354466 100644 --- a/compiler/rustc/Cargo.toml +++ b/compiler/rustc/Cargo.toml @@ -13,11 +13,11 @@ rustc_codegen_ssa = { path = "../rustc_codegen_ssa" } rustc_driver = { path = "../rustc_driver" } rustc_driver_impl = { path = "../rustc_driver_impl" } -# Make sure rustc_smir ends up in the sysroot, because this -# crate is intended to be used by stable MIR consumers, which are not in-tree. -rustc_smir = { path = "../rustc_smir" } +rustc_public = { path = "../rustc_public" } -stable_mir = { path = "../stable_mir" } +# Make sure rustc_public_bridge ends up in the sysroot, because this +# crate is intended to be used by stable MIR consumers, which are not in-tree. +rustc_public_bridge = { path = "../rustc_public_bridge" } # tidy-alphabetical-end [dependencies.tikv-jemalloc-sys] @@ -27,6 +27,7 @@ features = ['unprefixed_malloc_on_supported_platforms'] [features] # tidy-alphabetical-start +check_only = ['rustc_driver_impl/check_only'] jemalloc = ['dep:tikv-jemalloc-sys'] llvm = ['rustc_driver_impl/llvm'] max_level_info = ['rustc_driver_impl/max_level_info'] diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index de4b5a46c81a..5bd73502d980 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -43,7 +43,7 @@ use std::fmt; #[cfg(feature = "nightly")] use std::iter::Step; use std::num::{NonZeroUsize, ParseIntError}; -use std::ops::{Add, AddAssign, Deref, Mul, RangeInclusive, Sub}; +use std::ops::{Add, AddAssign, Deref, Mul, RangeFull, RangeInclusive, Sub}; use std::str::FromStr; use bitflags::bitflags; @@ -1391,12 +1391,45 @@ impl WrappingRange { } /// Returns `true` if `size` completely fills the range. + /// + /// Note that this is *not* the same as `self == WrappingRange::full(size)`. + /// Niche calculations can produce full ranges which are not the canonical one; + /// for example `Option>` gets `valid_range: (..=0) | (1..)`. #[inline] fn is_full_for(&self, size: Size) -> bool { let max_value = size.unsigned_int_max(); debug_assert!(self.start <= max_value && self.end <= max_value); self.start == (self.end.wrapping_add(1) & max_value) } + + /// Checks whether this range is considered non-wrapping when the values are + /// interpreted as *unsigned* numbers of width `size`. + /// + /// Returns `Ok(true)` if there's no wrap-around, `Ok(false)` if there is, + /// and `Err(..)` if the range is full so it depends how you think about it. + #[inline] + pub fn no_unsigned_wraparound(&self, size: Size) -> Result { + if self.is_full_for(size) { Err(..) } else { Ok(self.start <= self.end) } + } + + /// Checks whether this range is considered non-wrapping when the values are + /// interpreted as *signed* numbers of width `size`. + /// + /// This is heavily dependent on the `size`, as `100..=200` does wrap when + /// interpreted as `i8`, but doesn't when interpreted as `i16`. + /// + /// Returns `Ok(true)` if there's no wrap-around, `Ok(false)` if there is, + /// and `Err(..)` if the range is full so it depends how you think about it. + #[inline] + pub fn no_signed_wraparound(&self, size: Size) -> Result { + if self.is_full_for(size) { + Err(..) + } else { + let start: i128 = size.sign_extend(self.start); + let end: i128 = size.sign_extend(self.end); + Ok(start <= end) + } + } } impl fmt::Debug for WrappingRange { diff --git a/compiler/rustc_ast/Cargo.toml b/compiler/rustc_ast/Cargo.toml index 5de2e69072fa..155e14a3796e 100644 --- a/compiler/rustc_ast/Cargo.toml +++ b/compiler/rustc_ast/Cargo.toml @@ -7,7 +7,7 @@ edition = "2024" # tidy-alphabetical-start bitflags = "2.4.1" memchr = "2.7.4" -rustc-literal-escaper = "0.0.4" +rustc-literal-escaper = "0.0.5" rustc_ast_ir = { path = "../rustc_ast_ir" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_index = { path = "../rustc_index" } diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 3c576316f623..97e070958751 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -18,7 +18,7 @@ //! - [`Attribute`]: Metadata associated with item. //! - [`UnOp`], [`BinOp`], and [`BinOpKind`]: Unary and binary operators. -use std::borrow::Cow; +use std::borrow::{Borrow, Cow}; use std::{cmp, fmt}; pub use GenericArgs::*; @@ -28,7 +28,7 @@ use rustc_data_structures::packed::Pu128; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::tagged_ptr::Tag; -use rustc_macros::{Decodable, Encodable, HashStable_Generic}; +use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable}; pub use rustc_span::AttrId; use rustc_span::source_map::{Spanned, respan}; use rustc_span::{ByteSymbol, DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, sym}; @@ -39,6 +39,7 @@ use crate::ptr::P; use crate::token::{self, CommentKind, Delimiter}; use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream}; use crate::util::parser::{ExprPrecedence, Fixity}; +use crate::visit::{AssocCtxt, BoundKind, LifetimeCtxt}; /// A "Label" is an identifier of some point in sources, /// e.g. in the following code: @@ -50,7 +51,7 @@ use crate::util::parser::{ExprPrecedence, Fixity}; /// ``` /// /// `'outer` is a label. -#[derive(Clone, Encodable, Decodable, Copy, HashStable_Generic, Eq, PartialEq)] +#[derive(Clone, Encodable, Decodable, Copy, HashStable_Generic, Eq, PartialEq, Walkable)] pub struct Label { pub ident: Ident, } @@ -63,7 +64,7 @@ impl fmt::Debug for Label { /// A "Lifetime" is an annotation of the scope in which variable /// can be used, e.g. `'a` in `&'a i32`. -#[derive(Clone, Encodable, Decodable, Copy, PartialEq, Eq, Hash)] +#[derive(Clone, Encodable, Decodable, Copy, PartialEq, Eq, Hash, Walkable)] pub struct Lifetime { pub id: NodeId, pub ident: Ident, @@ -87,7 +88,7 @@ impl fmt::Display for Lifetime { /// along with a bunch of supporting information. /// /// E.g., `std::cmp::PartialEq`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Path { pub span: Span, /// The segments in the path: the things separated by `::`. @@ -155,10 +156,63 @@ impl Path { } } +/// Joins multiple symbols with "::" into a path, e.g. "a::b::c". If the first +/// segment is `kw::PathRoot` it will be printed as empty, e.g. "::b::c". +/// +/// The generics on the `path` argument mean it can accept many forms, such as: +/// - `&[Symbol]` +/// - `Vec` +/// - `Vec<&Symbol>` +/// - `impl Iterator` +/// - `impl Iterator` +/// +/// Panics if `path` is empty or a segment after the first is `kw::PathRoot`. +pub fn join_path_syms(path: impl IntoIterator>) -> String { + // This is a guess at the needed capacity that works well in practice. It is slightly faster + // than (a) starting with an empty string, or (b) computing the exact capacity required. + // `8` works well because it's about the right size and jemalloc's size classes are all + // multiples of 8. + let mut iter = path.into_iter(); + let len_hint = iter.size_hint().1.unwrap_or(1); + let mut s = String::with_capacity(len_hint * 8); + + let first_sym = *iter.next().unwrap().borrow(); + if first_sym != kw::PathRoot { + s.push_str(first_sym.as_str()); + } + for sym in iter { + let sym = *sym.borrow(); + debug_assert_ne!(sym, kw::PathRoot); + s.push_str("::"); + s.push_str(sym.as_str()); + } + s +} + +/// Like `join_path_syms`, but for `Ident`s. This function is necessary because +/// `Ident::to_string` does more than just print the symbol in the `name` field. +pub fn join_path_idents(path: impl IntoIterator>) -> String { + let mut iter = path.into_iter(); + let len_hint = iter.size_hint().1.unwrap_or(1); + let mut s = String::with_capacity(len_hint * 8); + + let first_ident = *iter.next().unwrap().borrow(); + if first_ident.name != kw::PathRoot { + s.push_str(&first_ident.to_string()); + } + for ident in iter { + let ident = *ident.borrow(); + debug_assert_ne!(ident.name, kw::PathRoot); + s.push_str("::"); + s.push_str(&ident.to_string()); + } + s +} + /// A segment of a path: an identifier, an optional lifetime, and a set of types. /// /// E.g., `std`, `String` or `Box`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct PathSegment { /// The identifier portion of this path segment. pub ident: Ident, @@ -202,7 +256,7 @@ impl PathSegment { /// The generic arguments and associated item constraints of a path segment. /// /// E.g., `` as in `Foo` or `(A, B)` as in `Foo(A, B)`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum GenericArgs { /// The `<'a, A, B, C>` in `foo::bar::baz::<'a, A, B, C>`. AngleBracketed(AngleBracketedArgs), @@ -227,10 +281,10 @@ impl GenericArgs { } /// Concrete argument in the sequence of generic args. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum GenericArg { /// `'a` in `Foo<'a>`. - Lifetime(Lifetime), + Lifetime(#[visitable(extra = LifetimeCtxt::GenericArg)] Lifetime), /// `Bar` in `Foo`. Type(P), /// `1` in `Foo<1>`. @@ -248,7 +302,7 @@ impl GenericArg { } /// A path like `Foo<'a, T>`. -#[derive(Clone, Encodable, Decodable, Debug, Default)] +#[derive(Clone, Encodable, Decodable, Debug, Default, Walkable)] pub struct AngleBracketedArgs { /// The overall span. pub span: Span, @@ -257,7 +311,7 @@ pub struct AngleBracketedArgs { } /// Either an argument for a generic parameter or a constraint on an associated item. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum AngleBracketedArg { /// A generic argument for a generic parameter. Arg(GenericArg), @@ -287,7 +341,7 @@ impl From for P { } /// A path like `Foo(A, B) -> C`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct ParenthesizedArgs { /// ```text /// Foo(A, B) -> C @@ -323,7 +377,7 @@ impl ParenthesizedArgs { pub use crate::node_id::{CRATE_NODE_ID, DUMMY_NODE_ID, NodeId}; /// Modifiers on a trait bound like `[const]`, `?` and `!`. -#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Walkable)] pub struct TraitBoundModifiers { pub constness: BoundConstness, pub asyncness: BoundAsyncness, @@ -338,10 +392,10 @@ impl TraitBoundModifiers { }; } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum GenericBound { Trait(PolyTraitRef), - Outlives(Lifetime), + Outlives(#[visitable(extra = LifetimeCtxt::Bound)] Lifetime), /// Precise capturing syntax: `impl Sized + use<'a>` Use(ThinVec, Span), } @@ -376,7 +430,7 @@ impl fmt::Display for ParamKindOrd { } } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum GenericParamKind { /// A lifetime definition (e.g., `'a: 'b + 'c + 'd`). Lifetime, @@ -392,11 +446,12 @@ pub enum GenericParamKind { }, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct GenericParam { pub id: NodeId, pub ident: Ident, pub attrs: AttrVec, + #[visitable(extra = BoundKind::Bound)] pub bounds: GenericBounds, pub is_placeholder: bool, pub kind: GenericParamKind, @@ -417,7 +472,7 @@ impl GenericParam { /// Represents lifetime, type and const parameters attached to a declaration of /// a function, enum, trait, etc. -#[derive(Clone, Encodable, Decodable, Debug, Default)] +#[derive(Clone, Encodable, Decodable, Debug, Default, Walkable)] pub struct Generics { pub params: ThinVec, pub where_clause: WhereClause, @@ -425,7 +480,7 @@ pub struct Generics { } /// A where-clause in a definition. -#[derive(Clone, Encodable, Decodable, Debug, Default)] +#[derive(Clone, Encodable, Decodable, Debug, Default, Walkable)] pub struct WhereClause { /// `true` if we ate a `where` token. /// @@ -443,7 +498,7 @@ impl WhereClause { } /// A single predicate in a where-clause. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct WherePredicate { pub attrs: AttrVec, pub kind: WherePredicateKind, @@ -453,7 +508,7 @@ pub struct WherePredicate { } /// Predicate kind in where-clause. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum WherePredicateKind { /// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`). BoundPredicate(WhereBoundPredicate), @@ -466,42 +521,45 @@ pub enum WherePredicateKind { /// A type bound. /// /// E.g., `for<'c> Foo: Send + Clone + 'c`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct WhereBoundPredicate { /// Any generics from a `for` binding. pub bound_generic_params: ThinVec, /// The type being bounded. pub bounded_ty: P, /// Trait and lifetime bounds (`Clone + Send + 'static`). + #[visitable(extra = BoundKind::Bound)] pub bounds: GenericBounds, } /// A lifetime predicate. /// /// E.g., `'a: 'b + 'c`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct WhereRegionPredicate { + #[visitable(extra = LifetimeCtxt::Bound)] pub lifetime: Lifetime, + #[visitable(extra = BoundKind::Bound)] pub bounds: GenericBounds, } /// An equality predicate (unsupported). /// /// E.g., `T = int`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct WhereEqPredicate { pub lhs_ty: P, pub rhs_ty: P, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Crate { - pub attrs: AttrVec, - pub items: ThinVec>, - pub spans: ModSpans, /// Must be equal to `CRATE_NODE_ID` after the crate root is expanded, but may hold /// expansion placeholders or an unassigned value (`DUMMY_NODE_ID`) before that. pub id: NodeId, + pub attrs: AttrVec, + pub items: ThinVec>, + pub spans: ModSpans, pub is_placeholder: bool, } @@ -555,7 +613,7 @@ pub enum MetaItemInner { /// A block (`{ .. }`). /// /// E.g., `{ .. }` as in `fn foo() { .. }`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Block { /// The statements in the block. pub stmts: ThinVec, @@ -569,7 +627,7 @@ pub struct Block { /// A match pattern. /// /// Patterns appear in match statements and some other contexts, such as `let` and `if let`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Pat { pub id: NodeId, pub kind: PatKind, @@ -717,7 +775,7 @@ impl From> for Pat { /// Patterns like the fields of `Foo { x, ref y, ref mut z }` /// are treated the same as `x: x, y: ref y, z: ref mut z`, /// except when `is_shorthand` is true. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct PatField { /// The identifier for the field. pub ident: Ident, @@ -731,7 +789,7 @@ pub struct PatField { } #[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[derive(Encodable, Decodable, HashStable_Generic)] +#[derive(Encodable, Decodable, HashStable_Generic, Walkable)] pub enum ByRef { Yes(Mutability), No, @@ -753,7 +811,7 @@ impl ByRef { /// `.0` is the by-reference mode (`ref`, `ref mut`, or by value), /// `.1` is the mutability of the binding. #[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[derive(Encodable, Decodable, HashStable_Generic)] +#[derive(Encodable, Decodable, HashStable_Generic, Walkable)] pub struct BindingMode(pub ByRef, pub Mutability); impl BindingMode { @@ -776,7 +834,7 @@ impl BindingMode { } } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum RangeEnd { /// `..=` or `...` Included(RangeSyntax), @@ -784,7 +842,7 @@ pub enum RangeEnd { Excluded, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum RangeSyntax { /// `...` DotDotDot, @@ -795,7 +853,7 @@ pub enum RangeSyntax { /// All the different flavors of pattern that Rust recognizes. // // Adding a new variant? Please update `test_pat` in `tests/ui/macros/stringify.rs`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum PatKind { /// A missing pattern, e.g. for an anonymous param in a bare fn like `fn f(u32)`. Missing, @@ -877,7 +935,7 @@ pub enum PatKind { } /// Whether the `..` is present in a struct fields pattern. -#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq, Walkable)] pub enum PatFieldsRest { /// `module::StructName { field, ..}` Rest, @@ -890,7 +948,7 @@ pub enum PatFieldsRest { /// The kind of borrow in an `AddrOf` expression, /// e.g., `&place` or `&raw const place`. #[derive(Clone, Copy, PartialEq, Eq, Debug)] -#[derive(Encodable, Decodable, HashStable_Generic)] +#[derive(Encodable, Decodable, HashStable_Generic, Walkable)] pub enum BorrowKind { /// A normal borrow, `&$expr` or `&mut $expr`. /// The resulting type is either `&'a T` or `&'a mut T` @@ -906,7 +964,7 @@ pub enum BorrowKind { Pin, } -#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)] +#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)] pub enum BinOpKind { /// The `+` operator (addition) Add, @@ -1036,7 +1094,7 @@ impl From for BinOpKind { } } -#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)] +#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)] pub enum AssignOpKind { /// The `+=` operator (addition) AddAssign, @@ -1088,7 +1146,7 @@ pub type AssignOp = Spanned; /// Unary operator. /// /// Note that `&data` is not an operator, it's an `AddrOf` expression. -#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)] +#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)] pub enum UnOp { /// The `*` operator for dereferencing Deref, @@ -1162,7 +1220,7 @@ impl Stmt { } // Adding a new variant? Please update `test_stmt` in `tests/ui/macros/stringify.rs`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum StmtKind { /// A local (let) binding. Let(P), @@ -1178,7 +1236,7 @@ pub enum StmtKind { MacCall(P), } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct MacCallStmt { pub mac: P, pub style: MacStmtStyle, @@ -1186,7 +1244,7 @@ pub struct MacCallStmt { pub tokens: Option, } -#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, Walkable)] pub enum MacStmtStyle { /// The macro statement had a trailing semicolon (e.g., `foo! { ... };` /// `foo!(...);`, `foo![...];`). @@ -1200,7 +1258,7 @@ pub enum MacStmtStyle { } /// Local represents a `let` statement, e.g., `let : = ;`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Local { pub id: NodeId, pub super_: Option, @@ -1213,7 +1271,7 @@ pub struct Local { pub tokens: Option, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum LocalKind { /// Local declaration. /// Example: `let x;` @@ -1253,7 +1311,7 @@ impl LocalKind { /// _ => { println!("no match!") }, /// } /// ``` -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Arm { pub attrs: AttrVec, /// Match arm pattern, e.g. `10` in `match foo { 10 => {}, _ => {} }`. @@ -1268,7 +1326,7 @@ pub struct Arm { } /// A single field in a struct expression, e.g. `x: value` and `y` in `Foo { x: value, y }`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct ExprField { pub attrs: AttrVec, pub id: NodeId, @@ -1279,13 +1337,13 @@ pub struct ExprField { pub is_placeholder: bool, } -#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, Walkable)] pub enum BlockCheckMode { Default, Unsafe(UnsafeSource), } -#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, Walkable)] pub enum UnsafeSource { CompilerGenerated, UserProvided, @@ -1296,7 +1354,7 @@ pub enum UnsafeSource { /// These are usually found nested inside types (e.g., array lengths) /// or expressions (e.g., repeat counts), and also used to define /// explicit discriminant values for enum variants. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct AnonConst { pub id: NodeId, pub value: P, @@ -1580,7 +1638,7 @@ impl From> for Expr { } } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Closure { pub binder: ClosureBinder, pub capture_clause: CaptureBy, @@ -1596,7 +1654,7 @@ pub struct Closure { } /// Limit types of a range (inclusive or exclusive). -#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, Walkable)] pub enum RangeLimits { /// Inclusive at the beginning, exclusive at the end. HalfOpen, @@ -1627,7 +1685,7 @@ pub struct MethodCall { pub span: Span, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum StructRest { /// `..x`. Base(P), @@ -1637,7 +1695,7 @@ pub enum StructRest { None, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct StructExpr { pub qself: Option>, pub path: Path, @@ -1827,14 +1885,14 @@ pub enum ExprKind { } /// Used to differentiate between `for` loops and `for await` loops. -#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq, Eq, Walkable)] pub enum ForLoopKind { For, ForAwait, } /// Used to differentiate between `async {}` blocks and `gen {}` blocks. -#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq)] +#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, Walkable)] pub enum GenBlockKind { Async, Gen, @@ -1859,7 +1917,7 @@ impl GenBlockKind { /// Whether we're unwrapping or wrapping an unsafe binder #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -#[derive(Encodable, Decodable, HashStable_Generic)] +#[derive(Encodable, Decodable, HashStable_Generic, Walkable)] pub enum UnsafeBinderCastKind { // e.g. `&i32` -> `unsafe<'a> &'a i32` Wrap, @@ -1881,7 +1939,7 @@ pub enum UnsafeBinderCastKind { /// ^~~~~ ^ /// ty position = 0 /// ``` -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct QSelf { pub ty: P, @@ -1893,7 +1951,7 @@ pub struct QSelf { } /// A capture clause used in closures and `async` blocks. -#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] pub enum CaptureBy { /// `move |x| y + x`. Value { @@ -1914,7 +1972,7 @@ pub enum CaptureBy { } /// Closure lifetime binder, `for<'a, 'b>` in `for<'a, 'b> |_: &'a (), _: &'b ()|`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum ClosureBinder { /// The binder is not present, all closure lifetimes are inferred. NotPresent, @@ -1940,7 +1998,7 @@ pub enum ClosureBinder { /// Represents a macro invocation. The `path` indicates which macro /// is being invoked, and the `args` are arguments passed to it. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct MacCall { pub path: Path, pub args: P, @@ -1953,7 +2011,7 @@ impl MacCall { } /// Arguments passed to an attribute macro. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum AttrArgs { /// No arguments: `#[attr]`. Empty, @@ -1988,7 +2046,7 @@ impl AttrArgs { } /// Delimited arguments, as used in `#[attr()/[]/{}]` or `mac!()/[]/{}`. -#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] pub struct DelimArgs { pub dspan: DelimSpan, pub delim: Delimiter, // Note: `Delimiter::Invisible` never occurs @@ -2004,7 +2062,7 @@ impl DelimArgs { } /// Represents a macro definition. -#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] pub struct MacroDef { pub body: P, /// `true` if macro was defined with `macro_rules`. @@ -2012,7 +2070,7 @@ pub struct MacroDef { } #[derive(Clone, Encodable, Decodable, Debug, Copy, Hash, Eq, PartialEq)] -#[derive(HashStable_Generic)] +#[derive(HashStable_Generic, Walkable)] pub enum StrStyle { /// A regular string, like `"foo"`. Cooked, @@ -2023,7 +2081,7 @@ pub enum StrStyle { } /// The kind of match expression -#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq, Walkable)] pub enum MatchKind { /// match expr { ... } Prefix, @@ -2032,7 +2090,7 @@ pub enum MatchKind { } /// The kind of yield expression -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum YieldKind { /// yield expr { ... } Prefix(Option>), @@ -2083,7 +2141,7 @@ pub struct MetaItemLit { } /// Similar to `MetaItemLit`, but restricted to string literals. -#[derive(Clone, Copy, Encodable, Decodable, Debug)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, Walkable)] pub struct StrLit { /// The original literal as written in source code. pub symbol: Symbol, @@ -2212,7 +2270,7 @@ impl LitKind { // N.B., If you change this, you'll probably want to change the corresponding // type structure in `middle/ty.rs` as well. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct MutTy { pub ty: P, pub mutbl: Mutability, @@ -2336,7 +2394,7 @@ impl UintTy { /// * the `RetTy` in `Trait(ArgTy, ArgTy) -> RetTy` /// * the `C = { Ct }` in `Trait` (feature `associated_const_equality`) /// * the `f(..): Bound` in `Trait` (feature `return_type_notation`) -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct AssocItemConstraint { pub id: NodeId, pub ident: Ident, @@ -2345,7 +2403,7 @@ pub struct AssocItemConstraint { pub span: Span, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum Term { Ty(P), Const(AnonConst), @@ -2364,7 +2422,7 @@ impl From for Term { } /// The kind of [associated item constraint][AssocItemConstraint]. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum AssocItemConstraintKind { /// An equality constraint for an associated item (e.g., `AssocTy = Ty` in `Trait`). /// @@ -2374,10 +2432,13 @@ pub enum AssocItemConstraintKind { /// bindings*. Similarly with associated const equality constraints and *associated const bindings*. Equality { term: Term }, /// A bound on an associated type (e.g., `AssocTy: Bound` in `Trait`). - Bound { bounds: GenericBounds }, + Bound { + #[visitable(extra = BoundKind::Bound)] + bounds: GenericBounds, + }, } -#[derive(Encodable, Decodable, Debug)] +#[derive(Encodable, Decodable, Debug, Walkable)] pub struct Ty { pub id: NodeId, pub kind: TyKind, @@ -2421,7 +2482,7 @@ impl Ty { } } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct FnPtrTy { pub safety: Safety, pub ext: Extern, @@ -2432,7 +2493,7 @@ pub struct FnPtrTy { pub decl_span: Span, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct UnsafeBinderTy { pub generic_params: ThinVec, pub inner_ty: P, @@ -2441,7 +2502,7 @@ pub struct UnsafeBinderTy { /// The various kinds of type recognized by the compiler. // // Adding a new variant? Please update `test_ty` in `tests/ui/macros/stringify.rs`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum TyKind { /// A variable-length slice (`[T]`). Slice(P), @@ -2450,11 +2511,11 @@ pub enum TyKind { /// A raw pointer (`*const T` or `*mut T`). Ptr(MutTy), /// A reference (`&'a T` or `&'a mut T`). - Ref(Option, MutTy), + Ref(#[visitable(extra = LifetimeCtxt::Ref)] Option, MutTy), /// A pinned reference (`&'a pin const T` or `&'a pin mut T`). /// /// Desugars into `Pin<&'a T>` or `Pin<&'a mut T>`. - PinnedRef(Option, MutTy), + PinnedRef(#[visitable(extra = LifetimeCtxt::Ref)] Option, MutTy), /// A function pointer type (e.g., `fn(usize) -> bool`). FnPtr(P), /// An unsafe existential lifetime binder (e.g., `unsafe<'a> &'a ()`). @@ -2470,14 +2531,14 @@ pub enum TyKind { Path(Option>, Path), /// A trait object type `Bound1 + Bound2 + Bound3` /// where `Bound` is a trait or a lifetime. - TraitObject(GenericBounds, TraitObjectSyntax), + TraitObject(#[visitable(extra = BoundKind::TraitObject)] GenericBounds, TraitObjectSyntax), /// An `impl Bound1 + Bound2 + Bound3` type /// where `Bound` is a trait or a lifetime. /// /// The `NodeId` exists to prevent lowering from having to /// generate `NodeId`s on the fly, which would complicate /// the generation of opaque `type Foo = impl Trait` items significantly. - ImplTrait(NodeId, GenericBounds), + ImplTrait(NodeId, #[visitable(extra = BoundKind::Impl)] GenericBounds), /// No-op; kept solely so that we can pretty-print faithfully. Paren(P), /// Unused for now. @@ -2555,7 +2616,7 @@ impl TyKind { } /// A pattern type pattern. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct TyPat { pub id: NodeId, pub kind: TyPatKind, @@ -2566,7 +2627,7 @@ pub struct TyPat { /// All the different flavors of pattern that Rust recognizes. // // Adding a new variant? Please update `test_pat` in `tests/ui/macros/stringify.rs`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum TyPatKind { /// A range pattern (e.g., `1...2`, `1..2`, `1..`, `..2`, `1..=2`, `..=2`). Range(Option>, Option>, Spanned), @@ -2578,7 +2639,7 @@ pub enum TyPatKind { } /// Syntax used to declare a trait object. -#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] #[repr(u8)] pub enum TraitObjectSyntax { // SAFETY: When adding new variants make sure to update the `Tag` impl. @@ -2605,10 +2666,10 @@ unsafe impl Tag for TraitObjectSyntax { } } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum PreciseCapturingArg { /// Lifetime parameter. - Lifetime(Lifetime), + Lifetime(#[visitable(extra = LifetimeCtxt::GenericArg)] Lifetime), /// Type or const parameter. Arg(Path, NodeId), } @@ -2616,7 +2677,7 @@ pub enum PreciseCapturingArg { /// Inline assembly operand explicit register or register class. /// /// E.g., `"eax"` as in `asm!("mov eax, 2", out("eax") result)`. -#[derive(Clone, Copy, Encodable, Decodable, Debug)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, Walkable)] pub enum InlineAsmRegOrRegClass { Reg(Symbol), RegClass(Symbol), @@ -2685,7 +2746,7 @@ impl std::fmt::Debug for InlineAsmOptions { } } -#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Hash, HashStable_Generic)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Hash, HashStable_Generic, Walkable)] pub enum InlineAsmTemplatePiece { String(Cow<'static, str>), Placeholder { operand_idx: usize, modifier: Option, span: Span }, @@ -2733,7 +2794,7 @@ impl InlineAsmTemplatePiece { /// `DefCollector`. Instead this is deferred until AST lowering where we /// lower it to an `AnonConst` (for functions) or a `Path` (for statics) /// depending on what the path resolves to. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct InlineAsmSym { pub id: NodeId, pub qself: Option>, @@ -2743,7 +2804,7 @@ pub struct InlineAsmSym { /// Inline assembly operand. /// /// E.g., `out("eax") result` as in `asm!("mov eax, 2", out("eax") result)`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum InlineAsmOperand { In { reg: InlineAsmRegOrRegClass, @@ -2788,7 +2849,7 @@ impl InlineAsmOperand { } } -#[derive(Clone, Copy, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] pub enum AsmMacro { /// The `asm!` macro Asm, @@ -2827,13 +2888,14 @@ impl AsmMacro { /// Inline assembly. /// /// E.g., `asm!("NOP");`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct InlineAsm { pub asm_macro: AsmMacro, pub template: Vec, pub template_strs: Box<[(Symbol, Option, Span)]>, pub operands: Vec<(InlineAsmOperand, Span)>, pub clobber_abis: Vec<(Symbol, Span)>, + #[visitable(ignore)] pub options: InlineAsmOptions, pub line_spans: Vec, } @@ -2841,7 +2903,7 @@ pub struct InlineAsm { /// A parameter in a function header. /// /// E.g., `bar: usize` as in `fn foo(bar: usize)`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Param { pub attrs: AttrVec, pub ty: P, @@ -2969,7 +3031,7 @@ impl Param { /// /// Please note that it's different from `FnHeader` structure /// which contains metadata about function safety, asyncness, constness and ABI. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct FnDecl { pub inputs: ThinVec, pub output: FnRetTy, @@ -2985,7 +3047,7 @@ impl FnDecl { } /// Is the trait definition an auto trait? -#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] pub enum IsAuto { Yes, No, @@ -2993,7 +3055,7 @@ pub enum IsAuto { /// Safety of items. #[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable, Debug)] -#[derive(HashStable_Generic)] +#[derive(HashStable_Generic, Walkable)] pub enum Safety { /// `unsafe` an item is explicitly marked as `unsafe`. Unsafe(Span), @@ -3009,7 +3071,7 @@ pub enum Safety { /// Coroutine markers are things that cause the function to generate a coroutine, such as `async`, /// which makes the function return `impl Future`, or `gen`, which makes the function return `impl /// Iterator`. -#[derive(Copy, Clone, Encodable, Decodable, Debug)] +#[derive(Copy, Clone, Encodable, Decodable, Debug, Walkable)] pub enum CoroutineKind { /// `async`, which returns an `impl Future`. Async { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId }, @@ -3058,7 +3120,7 @@ impl CoroutineKind { } #[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable, Debug)] -#[derive(HashStable_Generic)] +#[derive(HashStable_Generic, Walkable)] pub enum Const { Yes(Span), No, @@ -3066,13 +3128,13 @@ pub enum Const { /// Item defaultness. /// For details see the [RFC #2532](https://github.com/rust-lang/rfcs/pull/2532). -#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] pub enum Defaultness { Default(Span), Final, } -#[derive(Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)] pub enum ImplPolarity { /// `impl Trait for Type` Positive, @@ -3091,7 +3153,7 @@ impl fmt::Debug for ImplPolarity { /// The polarity of a trait bound. #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash)] -#[derive(HashStable_Generic)] +#[derive(HashStable_Generic, Walkable)] pub enum BoundPolarity { /// `Type: Trait` Positive, @@ -3113,7 +3175,7 @@ impl BoundPolarity { /// The constness of a trait bound. #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash)] -#[derive(HashStable_Generic)] +#[derive(HashStable_Generic, Walkable)] pub enum BoundConstness { /// `Type: Trait` Never, @@ -3135,7 +3197,7 @@ impl BoundConstness { /// The asyncness of a trait bound. #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)] -#[derive(HashStable_Generic)] +#[derive(HashStable_Generic, Walkable)] pub enum BoundAsyncness { /// `Type: Trait` Normal, @@ -3152,7 +3214,7 @@ impl BoundAsyncness { } } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum FnRetTy { /// Returns type is not specified. /// @@ -3172,14 +3234,14 @@ impl FnRetTy { } } -#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, Walkable)] pub enum Inline { Yes, No, } /// Module item kind. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum ModKind { /// Module with inlined definition `mod foo { ... }`, /// or with definition outlined to a separate file `mod foo;` and already loaded from it. @@ -3190,7 +3252,7 @@ pub enum ModKind { Unloaded, } -#[derive(Copy, Clone, Encodable, Decodable, Debug, Default)] +#[derive(Copy, Clone, Encodable, Decodable, Debug, Default, Walkable)] pub struct ModSpans { /// `inner_span` covers the body of the module; for a file module, its the whole file. /// For an inline module, its the span inside the `{ ... }`, not including the curly braces. @@ -3201,7 +3263,7 @@ pub struct ModSpans { /// Foreign module declaration. /// /// E.g., `extern { .. }` or `extern "C" { .. }`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct ForeignMod { /// Span of the `extern` keyword. pub extern_span: Span, @@ -3212,12 +3274,13 @@ pub struct ForeignMod { pub items: ThinVec>, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct EnumDef { pub variants: ThinVec, } + /// Enum variant. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Variant { /// Attributes of the variant. pub attrs: AttrVec, @@ -3239,7 +3302,7 @@ pub struct Variant { } /// Part of `use` item to the right of its prefix. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum UseTreeKind { /// `use prefix` or `use prefix as rename` Simple(Option), @@ -3258,7 +3321,7 @@ pub enum UseTreeKind { /// A tree of paths sharing common prefixes. /// Used in `use` items both at top-level and inside of braces in import groups. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct UseTree { pub prefix: Path, pub kind: UseTreeKind, @@ -3280,7 +3343,7 @@ impl UseTree { /// Distinguishes between `Attribute`s that decorate items and Attributes that /// are contained as statements within items. These two cases need to be /// distinguished for pretty-printing. -#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, HashStable_Generic)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, HashStable_Generic, Walkable)] pub enum AttrStyle { Outer, Inner, @@ -3290,7 +3353,7 @@ pub enum AttrStyle { pub type AttrVec = ThinVec; /// A syntax-level representation of an attribute. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Attribute { pub kind: AttrKind, pub id: AttrId, @@ -3300,7 +3363,7 @@ pub struct Attribute { pub span: Span, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum AttrKind { /// A normal attribute. Normal(P), @@ -3311,7 +3374,7 @@ pub enum AttrKind { DocComment(CommentKind, Symbol), } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct NormalAttr { pub item: AttrItem, // Tokens for the full attribute, e.g. `#[foo]`, `#![bar]`. @@ -3332,7 +3395,7 @@ impl NormalAttr { } } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct AttrItem { pub unsafety: Safety, pub path: Path, @@ -3358,20 +3421,20 @@ impl AttrItem { /// that the `ref_id` is for. The `impl_id` maps to the "self type" of this impl. /// If this impl is an `ItemKind::Impl`, the `impl_id` is redundant (it could be the /// same as the impl's `NodeId`). -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct TraitRef { pub path: Path, pub ref_id: NodeId, } /// Whether enclosing parentheses are present or not. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum Parens { Yes, No, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct PolyTraitRef { /// The `'a` in `for<'a> Foo<&'a T>`. pub bound_generic_params: ThinVec, @@ -3407,14 +3470,14 @@ impl PolyTraitRef { } } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Visibility { pub kind: VisibilityKind, pub span: Span, pub tokens: Option, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum VisibilityKind { Public, Restricted { path: P, id: NodeId, shorthand: bool }, @@ -3430,7 +3493,7 @@ impl VisibilityKind { /// Field definition in a struct, variant or union. /// /// E.g., `bar: usize` as in `struct Foo { bar: usize }`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct FieldDef { pub attrs: AttrVec, pub id: NodeId, @@ -3445,14 +3508,14 @@ pub struct FieldDef { } /// Was parsing recovery performed? -#[derive(Copy, Clone, Debug, Encodable, Decodable, HashStable_Generic)] +#[derive(Copy, Clone, Debug, Encodable, Decodable, HashStable_Generic, Walkable)] pub enum Recovered { No, Yes(ErrorGuaranteed), } /// Fields and constructor ids of enum variants and structs. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum VariantData { /// Struct variant. /// @@ -3538,7 +3601,7 @@ impl Item { } /// `extern` qualifier on a function item or function type. -#[derive(Clone, Copy, Encodable, Decodable, Debug)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, Walkable)] pub enum Extern { /// No explicit extern keyword was used. /// @@ -3569,7 +3632,7 @@ impl Extern { /// /// All the information between the visibility and the name of the function is /// included in this struct (e.g., `async unsafe fn` or `const extern "C" fn`). -#[derive(Clone, Copy, Encodable, Decodable, Debug)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, Walkable)] pub struct FnHeader { /// Whether this is `unsafe`, or has a default safety. pub safety: Safety, @@ -3635,13 +3698,16 @@ impl Default for FnHeader { } } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Trait { + pub constness: Const, pub safety: Safety, pub is_auto: IsAuto, pub ident: Ident, pub generics: Generics, + #[visitable(extra = BoundKind::SuperTraits)] pub bounds: GenericBounds, + #[visitable(extra = AssocCtxt::Trait)] pub items: ThinVec>, } @@ -3663,14 +3729,14 @@ pub struct Trait { /// ``` /// /// If there is no where clause, then this is `false` with `DUMMY_SP`. -#[derive(Copy, Clone, Encodable, Decodable, Debug, Default)] +#[derive(Copy, Clone, Encodable, Decodable, Debug, Default, Walkable)] pub struct TyAliasWhereClause { pub has_where_token: bool, pub span: Span, } /// The span information for the two where clauses on a `TyAlias`. -#[derive(Copy, Clone, Encodable, Decodable, Debug, Default)] +#[derive(Copy, Clone, Encodable, Decodable, Debug, Default, Walkable)] pub struct TyAliasWhereClauses { /// Before the equals sign. pub before: TyAliasWhereClause, @@ -3682,12 +3748,13 @@ pub struct TyAliasWhereClauses { pub split: usize, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct TyAlias { pub defaultness: Defaultness, pub ident: Ident, pub generics: Generics, pub where_clauses: TyAliasWhereClauses, + #[visitable(extra = BoundKind::Bound)] pub bounds: GenericBounds, pub ty: Option>, } @@ -3705,7 +3772,7 @@ pub struct Impl { pub items: ThinVec>, } -#[derive(Clone, Encodable, Decodable, Debug, Default)] +#[derive(Clone, Encodable, Decodable, Debug, Default, Walkable)] pub struct FnContract { pub requires: Option>, pub ensures: Option>, @@ -3722,7 +3789,7 @@ pub struct Fn { pub body: Option>, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Delegation { /// Path resolution id. pub id: NodeId, @@ -3735,7 +3802,7 @@ pub struct Delegation { pub from_glob: bool, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct DelegationMac { pub qself: Option>, pub prefix: Path, @@ -3744,7 +3811,7 @@ pub struct DelegationMac { pub body: Option>, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct StaticItem { pub ident: Ident, pub ty: P, @@ -3754,7 +3821,7 @@ pub struct StaticItem { pub define_opaque: Option>, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct ConstItem { pub defaultness: Defaultness, pub ident: Ident, diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 44865c493b3b..4348a4bb120e 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -217,6 +217,10 @@ impl AttributeExt for Attribute { _ => None, } } + + fn is_automatically_derived_attr(&self) -> bool { + self.has_name(sym::automatically_derived) + } } impl Attribute { @@ -810,6 +814,7 @@ pub trait AttributeExt: Debug { .iter() .any(|kind| self.has_name(*kind)) } + fn is_automatically_derived_attr(&self) -> bool; /// Returns the documentation and its kind if this is a doc comment or a sugared doc comment. /// * `///doc` returns `Some(("doc", CommentKind::Line))`. diff --git a/compiler/rustc_ast/src/expand/mod.rs b/compiler/rustc_ast/src/expand/mod.rs index 323a8fab6d59..069bff67b97a 100644 --- a/compiler/rustc_ast/src/expand/mod.rs +++ b/compiler/rustc_ast/src/expand/mod.rs @@ -1,24 +1,7 @@ //! Definitions shared by macros / syntax extensions and e.g. `rustc_middle`. use rustc_macros::{Decodable, Encodable, HashStable_Generic}; -use rustc_span::Ident; -use rustc_span::def_id::DefId; - -use crate::MetaItem; pub mod allocator; pub mod autodiff_attrs; pub mod typetree; - -#[derive(Debug, Clone, Encodable, Decodable, HashStable_Generic)] -pub struct StrippedCfgItem { - pub parent_module: ModId, - pub ident: Ident, - pub cfg: MetaItem, -} - -impl StrippedCfgItem { - pub fn map_mod_id(self, f: impl FnOnce(ModId) -> New) -> StrippedCfgItem { - StrippedCfgItem { parent_module: f(self.parent_module), ident: self.ident, cfg: self.cfg } - } -} diff --git a/compiler/rustc_ast/src/format.rs b/compiler/rustc_ast/src/format.rs index 28d260419c51..c2a1de60a981 100644 --- a/compiler/rustc_ast/src/format.rs +++ b/compiler/rustc_ast/src/format.rs @@ -1,5 +1,5 @@ use rustc_data_structures::fx::FxHashMap; -use rustc_macros::{Decodable, Encodable}; +use rustc_macros::{Decodable, Encodable, Walkable}; use rustc_span::{Ident, Span, Symbol}; use crate::Expr; @@ -41,7 +41,7 @@ use crate::token::LitKind; /// Basically the "AST" for a complete `format_args!()`. /// /// E.g., `format_args!("hello {name}");`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct FormatArgs { pub span: Span, pub template: Vec, @@ -63,7 +63,7 @@ pub struct FormatArgs { /// A piece of a format template string. /// /// E.g. "hello" or "{name}". -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum FormatArgsPiece { Literal(Symbol), Placeholder(FormatPlaceholder), @@ -73,7 +73,7 @@ pub enum FormatArgsPiece { /// /// E.g. `1, 2, name="ferris", n=3`, /// but also implicit captured arguments like `x` in `format_args!("{x}")`. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct FormatArguments { arguments: Vec, num_unnamed_args: usize, @@ -144,13 +144,13 @@ impl FormatArguments { } } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct FormatArgument { pub kind: FormatArgumentKind, pub expr: P, } -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum FormatArgumentKind { /// `format_args(…, arg)` Normal, @@ -170,24 +170,28 @@ impl FormatArgumentKind { } } -#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq)] +#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, Walkable)] pub struct FormatPlaceholder { /// Index into [`FormatArgs::arguments`]. pub argument: FormatArgPosition, /// The span inside the format string for the full `{…}` placeholder. pub span: Option, /// `{}`, `{:?}`, or `{:x}`, etc. + #[visitable(ignore)] pub format_trait: FormatTrait, /// `{}` or `{:.5}` or `{:-^20}`, etc. + #[visitable(ignore)] pub format_options: FormatOptions, } -#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq)] +#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, Walkable)] pub struct FormatArgPosition { /// Which argument this position refers to (Ok), /// or would've referred to if it existed (Err). + #[visitable(ignore)] pub index: Result, /// What kind of position this is. See [`FormatArgPositionKind`]. + #[visitable(ignore)] pub kind: FormatArgPositionKind, /// The span of the name or number. pub span: Option, diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 3eae19f4daa1..06708e2e703a 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -12,14 +12,14 @@ use std::panic; use rustc_data_structures::flat_map_in_place::FlatMapInPlace; use rustc_span::source_map::Spanned; -use rustc_span::{Ident, Span}; +use rustc_span::{Ident, Span, Symbol}; use smallvec::{SmallVec, smallvec}; use thin_vec::ThinVec; use crate::ast::*; use crate::ptr::P; use crate::tokenstream::*; -use crate::visit::{AssocCtxt, BoundKind, FnCtxt, VisitorResult, try_visit, visit_opt, walk_list}; +use crate::visit::{AssocCtxt, BoundKind, FnCtxt, LifetimeCtxt, VisitorResult, try_visit}; mod sealed { use rustc_ast_ir::visit::VisitorResult; @@ -36,11 +36,249 @@ mod sealed { use sealed::MutVisitorResult; +pub(crate) trait MutVisitable { + type Extra: Copy; + fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra); +} + +impl MutVisitable for P +where + T: MutVisitable, +{ + type Extra = T::Extra; + fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra) { + (**self).visit_mut(visitor, extra) + } +} + +impl MutVisitable for Option +where + T: MutVisitable, +{ + type Extra = T::Extra; + fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra) { + if let Some(this) = self { + this.visit_mut(visitor, extra) + } + } +} + +impl MutVisitable for Spanned +where + T: MutVisitable, +{ + type Extra = T::Extra; + fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra) { + let Spanned { span, node } = self; + span.visit_mut(visitor, ()); + node.visit_mut(visitor, extra); + } +} + +impl MutVisitable for [T] +where + T: MutVisitable, +{ + type Extra = T::Extra; + fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra) { + for item in self { + item.visit_mut(visitor, extra); + } + } +} + +impl MutVisitable for Vec +where + T: MutVisitable, +{ + type Extra = T::Extra; + fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra) { + for item in self { + item.visit_mut(visitor, extra); + } + } +} + +impl MutVisitable for (T,) +where + T: MutVisitable, +{ + type Extra = T::Extra; + fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra) { + self.0.visit_mut(visitor, extra); + } +} + +impl MutVisitable for (T1, T2) +where + T1: MutVisitable, + T2: MutVisitable, +{ + type Extra = (); + fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra) { + self.0.visit_mut(visitor, extra); + self.1.visit_mut(visitor, extra); + } +} + +impl MutVisitable for (T1, T2, T3) +where + T1: MutVisitable, + T2: MutVisitable, + T3: MutVisitable, +{ + type Extra = (); + fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra) { + self.0.visit_mut(visitor, extra); + self.1.visit_mut(visitor, extra); + self.2.visit_mut(visitor, extra); + } +} + +impl MutVisitable for (T1, T2, T3, T4) +where + T1: MutVisitable, + T2: MutVisitable, + T3: MutVisitable, + T4: MutVisitable, +{ + type Extra = (); + fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra) { + self.0.visit_mut(visitor, extra); + self.1.visit_mut(visitor, extra); + self.2.visit_mut(visitor, extra); + self.3.visit_mut(visitor, extra); + } +} + +pub trait MutWalkable { + fn walk_mut(&mut self, visitor: &mut V); +} + +macro_rules! visit_visitable { + (mut $visitor:expr, $($expr:expr),* $(,)?) => {{ + $(MutVisitable::visit_mut($expr, $visitor, ());)* + }}; +} + +macro_rules! visit_visitable_with { + (mut $visitor:expr, $expr:expr, $extra:expr $(,)?) => { + MutVisitable::visit_mut($expr, $visitor, $extra) + }; +} + +macro_rules! walk_walkable { + ($visitor:expr, $expr:expr, mut) => { + MutWalkable::walk_mut($expr, $visitor) + }; +} + +macro_rules! impl_visitable { + (|&mut $self:ident: $self_ty:ty, + $vis:ident: &mut $vis_ty:ident, + $extra:ident: $extra_ty:ty| $block:block) => { + #[allow(unused_parens, non_local_definitions)] + impl<$vis_ty: MutVisitor> MutVisitable<$vis_ty> for $self_ty { + type Extra = $extra_ty; + fn visit_mut(&mut $self, $vis: &mut $vis_ty, $extra: Self::Extra) -> V::Result { + $block + } + } + }; +} + +macro_rules! impl_walkable { + ($(<$K:ident: $Kb:ident>)? |&mut $self:ident: $self_ty:ty, + $vis:ident: &mut $vis_ty:ident| $block:block) => { + #[allow(unused_parens, non_local_definitions)] + impl<$($K: $Kb,)? $vis_ty: MutVisitor> MutWalkable<$vis_ty> for $self_ty { + fn walk_mut(&mut $self, $vis: &mut $vis_ty) -> V::Result { + $block + } + } + }; +} + +macro_rules! impl_visitable_noop { + ( $($ty:ty,)*) => { + $( + impl_visitable!(|&mut self: $ty, _vis: &mut V, _extra: ()| {}); + )* + }; +} + +macro_rules! impl_visitable_list { + ( $($ty:ty,)*) => { + $(impl MutVisitable for $ty + where + for<'a> &'a mut $ty: IntoIterator, + T: MutVisitable, + { + type Extra = >::Extra; + + #[inline] + fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra) { + for i in self { + i.visit_mut(visitor, extra); + } + } + })* + } +} + +macro_rules! impl_visitable_direct { + ( $($ty:ty,)*) => { + $(impl_visitable!( + |&mut self: $ty, visitor: &mut V, _extra: ()| { + MutWalkable::walk_mut(self, visitor) + } + );)* + } +} + +macro_rules! impl_visitable_calling_walkable { + ( + $( fn $method:ident($ty:ty $(, $extra_name:ident: $extra_ty:ty)?); )* + ) => { + $(fn $method(&mut self, node: &mut $ty $(, $extra_name:$extra_ty)?) { + impl_visitable!(|&mut self: $ty, visitor: &mut V, extra: ($($extra_ty)?)| { + let ($($extra_name)?) = extra; + visitor.$method(self $(, $extra_name)?); + }); + walk_walkable!(self, node, mut) + })* + } +} + +macro_rules! define_named_walk { + ((mut) $Visitor:ident + $( pub fn $method:ident($ty:ty); )* + ) => { + $(pub fn $method(visitor: &mut V, node: &mut $ty) { + walk_walkable!(visitor, node, mut) + })* + }; +} + super::common_visitor_and_walkers!((mut) MutVisitor); macro_rules! generate_flat_map_visitor_fns { ($($name:ident, $Ty:ty, $flat_map_fn:ident$(, $param:ident: $ParamTy:ty)*;)+) => { $( + #[allow(unused_parens)] + impl MutVisitable for ThinVec<$Ty> { + type Extra = ($($ParamTy),*); + + #[inline] + fn visit_mut( + &mut self, + visitor: &mut V, + ($($param),*): Self::Extra, + ) -> V::Result { + $name(visitor, self $(, $param)*) + } + } + fn $name( vis: &mut V, values: &mut ThinVec<$Ty>, @@ -78,15 +316,6 @@ pub fn walk_flat_map_pat_field( smallvec![fp] } -fn visit_nested_use_tree( - vis: &mut V, - nested_tree: &mut UseTree, - nested_id: &mut NodeId, -) { - vis.visit_id(nested_id); - vis.visit_use_tree(nested_tree); -} - macro_rules! generate_walk_flat_map_fns { ($($fn_name:ident($Ty:ty$(,$extra_name:ident: $ExtraTy:ty)*) => $visit_fn_name:ident;)+) => {$( pub fn $fn_name(vis: &mut V, mut value: $Ty$(,$extra_name: $ExtraTy)*) -> SmallVec<[$Ty; 1]> { @@ -109,14 +338,6 @@ generate_walk_flat_map_fns! { walk_flat_map_assoc_item(P, ctxt: AssocCtxt) => visit_assoc_item; } -fn walk_ty_alias_where_clauses(vis: &mut T, tawcs: &mut TyAliasWhereClauses) { - let TyAliasWhereClauses { before, after, split: _ } = tawcs; - let TyAliasWhereClause { has_where_token: _, span: span_before } = before; - let TyAliasWhereClause { has_where_token: _, span: span_after } = after; - vis.visit_span(span_before); - vis.visit_span(span_after); -} - pub fn walk_filter_map_expr(vis: &mut T, mut e: P) -> Option> { vis.visit_expr(&mut e); Some(e) diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index c60185cdde00..e55399adfb85 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -20,7 +20,7 @@ use std::{cmp, fmt, iter, mem}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync; -use rustc_macros::{Decodable, Encodable, HashStable_Generic}; +use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable}; use rustc_serialize::{Decodable, Encodable}; use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym}; use thin_vec::ThinVec; @@ -977,7 +977,7 @@ impl TokenCursor { } } -#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)] +#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)] pub struct DelimSpan { pub open: Span, pub close: Span, diff --git a/compiler/rustc_ast/src/util/literal.rs b/compiler/rustc_ast/src/util/literal.rs index fa7878873e56..2dfd695d8802 100644 --- a/compiler/rustc_ast/src/util/literal.rs +++ b/compiler/rustc_ast/src/util/literal.rs @@ -126,11 +126,11 @@ impl LitKind { token::CStr => { let s = symbol.as_str(); let mut buf = Vec::with_capacity(s.len()); - unescape_c_str(s, |_span, c| match c { + unescape_c_str(s, |_span, res| match res { Ok(MixedUnit::Char(c)) => { - buf.extend_from_slice(c.encode_utf8(&mut [0; 4]).as_bytes()) + buf.extend_from_slice(c.get().encode_utf8(&mut [0; 4]).as_bytes()) } - Ok(MixedUnit::HighByte(b)) => buf.push(b), + Ok(MixedUnit::HighByte(b)) => buf.push(b.get()), Err(err) => { assert!(!err.is_fatal(), "failed to unescape C string literal") } diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 37fcc0d2167b..ab15cb28fa12 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -16,7 +16,7 @@ pub use rustc_ast_ir::visit::VisitorResult; pub use rustc_ast_ir::{try_visit, visit_opt, walk_list, walk_visitable_list}; use rustc_span::source_map::Spanned; -use rustc_span::{Ident, Span}; +use rustc_span::{Ident, Span, Symbol}; use thin_vec::ThinVec; use crate::ast::*; @@ -75,6 +75,241 @@ pub enum LifetimeCtxt { GenericArg, } +pub(crate) trait Visitable<'a, V: Visitor<'a>> { + type Extra: Copy; + + #[must_use] + fn visit(&'a self, visitor: &mut V, extra: Self::Extra) -> V::Result; +} + +impl<'a, V: Visitor<'a>, T: ?Sized> Visitable<'a, V> for P +where + T: Visitable<'a, V>, +{ + type Extra = T::Extra; + fn visit(&'a self, visitor: &mut V, extra: Self::Extra) -> V::Result { + (**self).visit(visitor, extra) + } +} + +impl<'a, V: Visitor<'a>, T> Visitable<'a, V> for Option +where + T: Visitable<'a, V>, +{ + type Extra = T::Extra; + fn visit(&'a self, visitor: &mut V, extra: Self::Extra) -> V::Result { + if let Some(this) = self { + try_visit!(this.visit(visitor, extra)); + } + V::Result::output() + } +} + +impl<'a, V: Visitor<'a>, T> Visitable<'a, V> for Spanned +where + T: Visitable<'a, V>, +{ + type Extra = T::Extra; + fn visit(&'a self, visitor: &mut V, extra: Self::Extra) -> V::Result { + let Spanned { span: _, node } = self; + node.visit(visitor, extra) + } +} + +impl<'a, V: Visitor<'a>, T> Visitable<'a, V> for [T] +where + T: Visitable<'a, V>, +{ + type Extra = T::Extra; + fn visit(&'a self, visitor: &mut V, extra: Self::Extra) -> V::Result { + for item in self { + try_visit!(item.visit(visitor, extra)); + } + V::Result::output() + } +} + +impl<'a, V: Visitor<'a>, T> Visitable<'a, V> for Vec +where + T: Visitable<'a, V>, +{ + type Extra = T::Extra; + fn visit(&'a self, visitor: &mut V, extra: Self::Extra) -> V::Result { + for item in self { + try_visit!(item.visit(visitor, extra)); + } + V::Result::output() + } +} + +impl<'a, V: Visitor<'a>, T> Visitable<'a, V> for (T,) +where + T: Visitable<'a, V>, +{ + type Extra = T::Extra; + fn visit(&'a self, visitor: &mut V, extra: Self::Extra) -> V::Result { + self.0.visit(visitor, extra) + } +} + +impl<'a, V: Visitor<'a>, T1, T2> Visitable<'a, V> for (T1, T2) +where + T1: Visitable<'a, V, Extra = ()>, + T2: Visitable<'a, V, Extra = ()>, +{ + type Extra = (); + fn visit(&'a self, visitor: &mut V, extra: Self::Extra) -> V::Result { + try_visit!(self.0.visit(visitor, extra)); + try_visit!(self.1.visit(visitor, extra)); + V::Result::output() + } +} + +impl<'a, V: Visitor<'a>, T1, T2, T3> Visitable<'a, V> for (T1, T2, T3) +where + T1: Visitable<'a, V, Extra = ()>, + T2: Visitable<'a, V, Extra = ()>, + T3: Visitable<'a, V, Extra = ()>, +{ + type Extra = (); + fn visit(&'a self, visitor: &mut V, extra: Self::Extra) -> V::Result { + try_visit!(self.0.visit(visitor, extra)); + try_visit!(self.1.visit(visitor, extra)); + try_visit!(self.2.visit(visitor, extra)); + V::Result::output() + } +} + +impl<'a, V: Visitor<'a>, T1, T2, T3, T4> Visitable<'a, V> for (T1, T2, T3, T4) +where + T1: Visitable<'a, V, Extra = ()>, + T2: Visitable<'a, V, Extra = ()>, + T3: Visitable<'a, V, Extra = ()>, + T4: Visitable<'a, V, Extra = ()>, +{ + type Extra = (); + fn visit(&'a self, visitor: &mut V, extra: Self::Extra) -> V::Result { + try_visit!(self.0.visit(visitor, extra)); + try_visit!(self.1.visit(visitor, extra)); + try_visit!(self.2.visit(visitor, extra)); + try_visit!(self.3.visit(visitor, extra)); + V::Result::output() + } +} + +pub(crate) trait Walkable<'a, V: Visitor<'a>> { + #[must_use] + fn walk_ref(&'a self, visitor: &mut V) -> V::Result; +} + +macro_rules! visit_visitable { + ($visitor:expr, $($expr:expr),* $(,)?) => {{ + $(try_visit!(Visitable::visit($expr, $visitor, ()));)* + }}; +} + +macro_rules! visit_visitable_with { + ($visitor:expr, $expr:expr, $extra:expr $(,)?) => { + try_visit!(Visitable::visit($expr, $visitor, $extra)) + }; +} + +macro_rules! walk_walkable { + ($visitor:expr, $expr:expr, ) => { + Walkable::walk_ref($expr, $visitor) + }; +} + +macro_rules! impl_visitable { + (|&$lt:lifetime $self:ident: $self_ty:ty, + $vis:ident: &mut $vis_ty:ident, + $extra:ident: $extra_ty:ty| $block:block) => { + #[allow(unused_parens, non_local_definitions)] + impl<$lt, $vis_ty: Visitor<$lt>> Visitable<$lt, $vis_ty> for $self_ty { + type Extra = $extra_ty; + fn visit(&$lt $self, $vis: &mut $vis_ty, $extra: Self::Extra) -> V::Result { + $block + } + } + }; +} + +macro_rules! impl_walkable { + ($(<$K:ident: $Kb:ident>)? |&$lt:lifetime $self:ident: $self_ty:ty, + $vis:ident: &mut $vis_ty:ident| $block:block) => { + #[allow(unused_parens, non_local_definitions)] + impl<$($K: $Kb,)? $lt, $vis_ty: Visitor<$lt>> Walkable<$lt, $vis_ty> for $self_ty { + fn walk_ref(&$lt $self, $vis: &mut $vis_ty) -> V::Result { + $block + } + } + }; +} + +macro_rules! impl_visitable_noop { + (<$lt:lifetime> $($ty:ty,)*) => { + $( + impl_visitable!(|&$lt self: $ty, _vis: &mut V, _extra: ()| { + V::Result::output() + }); + )* + }; +} + +macro_rules! impl_visitable_list { + (<$lt:lifetime> $($ty:ty,)*) => { + $(impl<$lt, V: Visitor<$lt>, T> Visitable<$lt, V> for $ty + where + &$lt $ty: IntoIterator, + T: $lt + Visitable<$lt, V>, + { + type Extra = >::Extra; + + #[inline] + fn visit(&$lt self, visitor: &mut V, extra: Self::Extra) -> V::Result { + for i in self { + try_visit!(i.visit(visitor, extra)); + } + V::Result::output() + } + })* + }; +} + +macro_rules! impl_visitable_direct { + (<$lt:lifetime> $($ty:ty,)*) => { + $(impl_visitable!( + |&$lt self: $ty, visitor: &mut V, _extra: ()| { + Walkable::walk_ref(self, visitor) + } + );)* + }; +} + +macro_rules! impl_visitable_calling_walkable { + (<$lt:lifetime> + $( fn $method:ident($ty:ty $(, $extra_name:ident: $extra_ty:ty)?); )* + ) => { + $(fn $method(&mut self, node: &$lt $ty $(, $extra_name:$extra_ty)?) -> Self::Result { + impl_visitable!(|&$lt self: $ty, visitor: &mut V, extra: ($($extra_ty)?)| { + let ($($extra_name)?) = extra; + visitor.$method(self $(, $extra_name)?) + }); + walk_walkable!(self, node, ) + })* + }; +} + +macro_rules! define_named_walk { + ($Visitor:ident<$lt:lifetime> + $( pub fn $method:ident($ty:ty); )* + ) => { + $(pub fn $method<$lt, V: $Visitor<$lt>>(visitor: &mut V, node: &$lt $ty) -> V::Result { + walk_walkable!(visitor, node,) + })* + }; +} + #[macro_export] macro_rules! common_visitor_and_walkers { ($(($mut: ident))? $Visitor:ident$(<$lt:lifetime>)?) => { @@ -120,6 +355,139 @@ macro_rules! common_visitor_and_walkers { } } + // This macro generates `impl Visitable` and `impl MutVisitable` that do nothing. + impl_visitable_noop!(<$($lt)? $($mut)?> + AttrId, + bool, + rustc_span::ByteSymbol, + char, + crate::token::CommentKind, + crate::token::Delimiter, + crate::token::Lit, + crate::token::LitKind, + crate::tokenstream::LazyAttrTokenStream, + crate::tokenstream::TokenStream, + Movability, + Mutability, + Result<(), rustc_span::ErrorGuaranteed>, + rustc_data_structures::fx::FxHashMap, + rustc_span::ErrorGuaranteed, + std::borrow::Cow<'_, str>, + Symbol, + u8, + usize, + ); + // `Span` is only a no-op for the non-mutable visitor. + $(impl_visitable_noop!(<$lt> Span,);)? + + // This macro generates `impl Visitable` and `impl MutVisitable` that simply iterate over + // their contents. We do not use a generic impl for `ThinVec` because we want to allow + // custom visits for the `MutVisitor`. + impl_visitable_list!(<$($lt)? $($mut)?> + ThinVec, + ThinVec, + ThinVec<(Ident, Option)>, + ThinVec<(NodeId, Path)>, + ThinVec, + ThinVec, + ThinVec>, + ThinVec>, + ThinVec>, + ); + + // This macro generates `impl Visitable` and `impl MutVisitable` that forward to `Walkable` + // or `MutWalkable`. By default, all types that do not have a custom visit method in the + // visitor should appear here. + impl_visitable_direct!(<$($lt)? $($mut)?> + AngleBracketedArg, + AngleBracketedArgs, + AsmMacro, + AssignOpKind, + AssocItemConstraintKind, + AttrArgs, + AttrItem, + AttrKind, + AttrStyle, + FnPtrTy, + BindingMode, + GenBlockKind, + RangeLimits, + UnsafeBinderCastKind, + BinOpKind, + BlockCheckMode, + BorrowKind, + BoundAsyncness, + BoundConstness, + BoundPolarity, + ByRef, + Closure, + Const, + ConstItem, + Defaultness, + Delegation, + DelegationMac, + DelimArgs, + DelimSpan, + EnumDef, + Extern, + ForLoopKind, + FormatArgPosition, + FormatArgsPiece, + FormatArgument, + FormatArgumentKind, + FormatArguments, + FormatPlaceholder, + GenericParamKind, + Impl, + ImplPolarity, + Inline, + InlineAsmOperand, + InlineAsmRegOrRegClass, + InlineAsmTemplatePiece, + IsAuto, + LocalKind, + MacCallStmt, + MacStmtStyle, + MatchKind, + MethodCall, + ModKind, + ModSpans, + MutTy, + NormalAttr, + Parens, + ParenthesizedArgs, + PatFieldsRest, + PatKind, + RangeEnd, + RangeSyntax, + Recovered, + Safety, + StaticItem, + StrLit, + StrStyle, + StructExpr, + StructRest, + Term, + Trait, + TraitBoundModifiers, + TraitObjectSyntax, + TyAlias, + TyAliasWhereClause, + TyAliasWhereClauses, + TyKind, + TyPatKind, + UnOp, + UnsafeBinderTy, + UnsafeSource, + UseTreeKind, + VisibilityKind, + WhereBoundPredicate, + WhereClause, + WhereEqPredicate, + WhereRegionPredicate, + YieldKind, + ); + /// Each method of this trait is a hook to be potentially /// overridden. Each method's default implementation recursively visits /// the substructure of the input via the corresponding `walk` method; @@ -169,47 +537,82 @@ macro_rules! common_visitor_and_walkers { // field access version will continue working and it would be easy to // forget to add handling for it. fn visit_ident(&mut self, Ident { name: _, span }: &$($lt)? $($mut)? Ident) -> Self::Result { + impl_visitable!(|&$($lt)? $($mut)? self: Ident, visitor: &mut V, _extra: ()| { + visitor.visit_ident(self) + }); visit_span(self, span) } - fn visit_foreign_mod(&mut self, nm: &$($lt)? $($mut)? ForeignMod) -> Self::Result { - walk_foreign_mod(self, nm) - } + // This macro defines a custom visit method for each listed type. + // It implements `impl Visitable` and `impl MutVisitable` to call those methods on the + // visitor. + impl_visitable_calling_walkable!(<$($lt)? $($mut)?> + fn visit_anon_const(AnonConst); + fn visit_arm(Arm); + //fn visit_assoc_item(AssocItem, _ctxt: AssocCtxt); + fn visit_assoc_item_constraint(AssocItemConstraint); + fn visit_attribute(Attribute); + fn visit_block(Block); + //fn visit_nested_use_tree((UseTree, NodeId)); + fn visit_capture_by(CaptureBy); + fn visit_closure_binder(ClosureBinder); + fn visit_contract(FnContract); + fn visit_coroutine_kind(CoroutineKind); + fn visit_crate(Crate); + fn visit_expr(Expr); + fn visit_expr_field(ExprField); + fn visit_field_def(FieldDef); + fn visit_fn_decl(FnDecl); + fn visit_fn_header(FnHeader); + fn visit_fn_ret_ty(FnRetTy); + //fn visit_foreign_item(ForeignItem); + fn visit_foreign_mod(ForeignMod); + fn visit_format_args(FormatArgs); + fn visit_generic_arg(GenericArg); + fn visit_generic_args(GenericArgs); + fn visit_generic_param(GenericParam); + fn visit_generics(Generics); + fn visit_inline_asm(InlineAsm); + fn visit_inline_asm_sym(InlineAsmSym); + //fn visit_item(Item); + fn visit_label(Label); + fn visit_lifetime(Lifetime, _ctxt: LifetimeCtxt); + fn visit_local(Local); + fn visit_mac_call(MacCall); + fn visit_macro_def(MacroDef); + fn visit_param_bound(GenericBound, _ctxt: BoundKind); + fn visit_param(Param); + fn visit_pat_field(PatField); + fn visit_path(Path); + fn visit_path_segment(PathSegment); + fn visit_pat(Pat); + fn visit_poly_trait_ref(PolyTraitRef); + fn visit_precise_capturing_arg(PreciseCapturingArg); + fn visit_qself(QSelf); + fn visit_trait_ref(TraitRef); + fn visit_ty_pat(TyPat); + fn visit_ty(Ty); + fn visit_use_tree(UseTree); + fn visit_variant_data(VariantData); + fn visit_variant(Variant); + fn visit_vis(Visibility); + fn visit_where_predicate_kind(WherePredicateKind); + fn visit_where_predicate(WherePredicate); + ); - fn visit_foreign_item(&mut self, i: &$($lt)? $($mut)? ForeignItem) -> Self::Result { - walk_item(self, i) - } - - fn visit_item(&mut self, i: &$($lt)? $($mut)? Item) -> Self::Result { - walk_item(self, i) - } - - fn visit_local(&mut self, l: &$($lt)? $($mut)? Local) -> Self::Result { - walk_local(self, l) - } - - fn visit_block(&mut self, b: &$($lt)? $($mut)? Block) -> Self::Result { - walk_block(self, b) - } - - fn visit_param(&mut self, param: &$($lt)? $($mut)? Param) -> Self::Result { - walk_param(self, param) - } - - fn visit_arm(&mut self, a: &$($lt)? $($mut)? Arm) -> Self::Result { - walk_arm(self, a) - } - - fn visit_pat(&mut self, p: &$($lt)? $($mut)? Pat) -> Self::Result { - walk_pat(self, p) - } - - fn visit_anon_const(&mut self, c: &$($lt)? $($mut)? AnonConst) -> Self::Result { - walk_anon_const(self, c) - } - - fn visit_expr(&mut self, ex: &$($lt)? $($mut)? Expr) -> Self::Result { - walk_expr(self, ex) + // We want `Visitor` to take the `NodeId` by value. + fn visit_id(&mut self, _id: $(&$mut)? NodeId) -> Self::Result { + $(impl_visitable!( + |&$lt self: NodeId, visitor: &mut V, _extra: ()| { + visitor.visit_id(*self) + } + );)? + $(impl_visitable!( + |&$mut self: NodeId, visitor: &mut V, _extra: ()| { + visitor.visit_id(self) + } + );)? + Self::Result::output() } /// This method is a hack to workaround unstable of `stmt_expr_attributes`. @@ -218,34 +621,25 @@ macro_rules! common_visitor_and_walkers { self.visit_expr(ex) } - fn visit_ty(&mut self, t: &$($lt)? $($mut)? Ty) -> Self::Result { - walk_ty(self, t) + fn visit_item(&mut self, item: &$($lt)? $($mut)? Item) -> Self::Result { + impl_visitable!(|&$($lt)? $($mut)? self: Item, vis: &mut V, _extra: ()| { + vis.visit_item(self) + }); + walk_item(self, item) } - fn visit_ty_pat(&mut self, t: &$($lt)? $($mut)? TyPat) -> Self::Result { - walk_ty_pat(self, t) + fn visit_foreign_item(&mut self, item: &$($lt)? $($mut)? ForeignItem) -> Self::Result { + impl_visitable!(|&$($lt)? $($mut)? self: ForeignItem, vis: &mut V, _extra: ()| { + vis.visit_foreign_item(self) + }); + walk_item(self, item) } - fn visit_generic_param(&mut self, param: &$($lt)? $($mut)? GenericParam) -> Self::Result { - walk_generic_param(self, param) - } - - fn visit_generics(&mut self, g: &$($lt)? $($mut)? Generics) -> Self::Result { - walk_generics(self, g) - } - fn visit_closure_binder(&mut self, b: &$($lt)? $($mut)? ClosureBinder) -> Self::Result { - walk_closure_binder(self, b) - } - fn visit_contract(&mut self, c: &$($lt)? $($mut)? FnContract) -> Self::Result { - walk_contract(self, c) - } - - fn visit_where_predicate(&mut self, p: &$($lt)? $($mut)? WherePredicate) -> Self::Result { - walk_where_predicate(self, p) - } - - fn visit_where_predicate_kind(&mut self, k: &$($lt)? $($mut)? WherePredicateKind) -> Self::Result { - walk_where_predicate_kind(self, k) + fn visit_assoc_item(&mut self, item: &$($lt)? $($mut)? AssocItem, ctxt: AssocCtxt) -> Self::Result { + impl_visitable!(|&$($lt)? $($mut)? self: AssocItem, vis: &mut V, ctxt: AssocCtxt| { + vis.visit_assoc_item(self, ctxt) + }); + walk_assoc_item(self, item, ctxt) } // for `MutVisitor`: `Span` and `NodeId` are mutated at the caller site. @@ -258,141 +652,6 @@ macro_rules! common_visitor_and_walkers { walk_fn(self, fk) } - fn visit_assoc_item(&mut self, i: &$($lt)? $($mut)? AssocItem, ctxt: AssocCtxt) -> Self::Result { - walk_assoc_item(self, i, ctxt) - } - - fn visit_trait_ref(&mut self, t: &$($lt)? $($mut)? TraitRef) -> Self::Result { - walk_trait_ref(self, t) - } - - fn visit_param_bound(&mut self, bounds: &$($lt)? $($mut)? GenericBound, _ctxt: BoundKind) -> Self::Result { - walk_param_bound(self, bounds) - } - - fn visit_precise_capturing_arg(&mut self, arg: &$($lt)? $($mut)? PreciseCapturingArg) -> Self::Result { - walk_precise_capturing_arg(self, arg) - } - - fn visit_poly_trait_ref(&mut self, t: &$($lt)? $($mut)? PolyTraitRef) -> Self::Result { - walk_poly_trait_ref(self, t) - } - - fn visit_variant_data(&mut self, s: &$($lt)? $($mut)? VariantData) -> Self::Result { - walk_variant_data(self, s) - } - - fn visit_field_def(&mut self, s: &$($lt)? $($mut)? FieldDef) -> Self::Result { - walk_field_def(self, s) - } - - fn visit_variant(&mut self, v: &$($lt)? $($mut)? Variant) -> Self::Result { - walk_variant(self, v) - } - - fn visit_label(&mut self, label: &$($lt)? $($mut)? Label) -> Self::Result { - walk_label(self, label) - } - - fn visit_lifetime(&mut self, lifetime: &$($lt)? $($mut)? Lifetime, $(${ignore($lt)} _: LifetimeCtxt )?) -> Self::Result { - walk_lifetime(self, lifetime) - } - - fn visit_mac_call(&mut self, mac: &$($lt)? $($mut)? MacCall) -> Self::Result { - walk_mac(self, mac) - } - - fn visit_id(&mut self, _id: $(&$mut)? NodeId) -> Self::Result { - Self::Result::output() - } - - fn visit_macro_def(&mut self, macro_def: &$($lt)? $($mut)? MacroDef) -> Self::Result { - walk_macro_def(self, macro_def) - } - - fn visit_path(&mut self, path: &$($lt)? $($mut)? Path) -> Self::Result { - walk_path(self, path) - } - - fn visit_use_tree(&mut self, use_tree: &$($lt)? $($mut)? UseTree) -> Self::Result { - walk_use_tree(self, use_tree) - } - - fn visit_path_segment(&mut self, path_segment: &$($lt)? $($mut)? PathSegment) -> Self::Result { - walk_path_segment(self, path_segment) - } - - fn visit_generic_args(&mut self, generic_args: &$($lt)? $($mut)? GenericArgs) -> Self::Result { - walk_generic_args(self, generic_args) - } - - fn visit_generic_arg(&mut self, generic_arg: &$($lt)? $($mut)? GenericArg) -> Self::Result { - walk_generic_arg(self, generic_arg) - } - - fn visit_assoc_item_constraint( - &mut self, - constraint: &$($lt)? $($mut)? AssocItemConstraint, - ) -> Self::Result { - walk_assoc_item_constraint(self, constraint) - } - - fn visit_attribute(&mut self, attr: &$($lt)? $($mut)? Attribute) -> Self::Result { - walk_attribute(self, attr) - } - - fn visit_vis(&mut self, vis: &$($lt)? $($mut)? Visibility) -> Self::Result { - walk_vis(self, vis) - } - - fn visit_fn_ret_ty(&mut self, ret_ty: &$($lt)? $($mut)? FnRetTy) -> Self::Result { - walk_fn_ret_ty(self, ret_ty) - } - - fn visit_fn_header(&mut self, header: &$($lt)? $($mut)? FnHeader) -> Self::Result { - walk_fn_header(self, header) - } - - fn visit_expr_field(&mut self, f: &$($lt)? $($mut)? ExprField) -> Self::Result { - walk_expr_field(self, f) - } - - fn visit_pat_field(&mut self, fp: &$($lt)? $($mut)? PatField) -> Self::Result { - walk_pat_field(self, fp) - } - - fn visit_crate(&mut self, krate: &$($lt)? $($mut)? Crate) -> Self::Result { - walk_crate(self, krate) - } - - fn visit_inline_asm(&mut self, asm: &$($lt)? $($mut)? InlineAsm) -> Self::Result { - walk_inline_asm(self, asm) - } - - fn visit_format_args(&mut self, fmt: &$($lt)? $($mut)? FormatArgs) -> Self::Result { - walk_format_args(self, fmt) - } - - fn visit_inline_asm_sym(&mut self, sym: &$($lt)? $($mut)? InlineAsmSym) -> Self::Result { - walk_inline_asm_sym(self, sym) - } - - fn visit_capture_by(&mut self, capture_by: &$($lt)? $($mut)? CaptureBy) -> Self::Result { - walk_capture_by(self, capture_by) - } - - fn visit_coroutine_kind(&mut self, coroutine_kind: &$($lt)? $($mut)? CoroutineKind) -> Self::Result { - walk_coroutine_kind(self, coroutine_kind) - } - - fn visit_fn_decl(&mut self, fn_decl: &$($lt)? $($mut)? FnDecl) -> Self::Result { - walk_fn_decl(self, fn_decl) - } - - fn visit_qself(&mut self, qs: &$($lt)? $($mut)? Option>) -> Self::Result { - walk_qself(self, qs) - } - // (non-mut) `Visitor`-only methods $( fn visit_stmt(&mut self, s: &$lt Stmt) -> Self::Result { @@ -407,6 +666,16 @@ macro_rules! common_visitor_and_walkers { // `MutVisitor`-only methods $( + // Span visiting is no longer used, but we keep it for now, + // in case it's needed for something like #127241. + #[inline] + fn visit_span(&mut self, _sp: &$mut Span) { + impl_visitable!(|&mut self: Span, visitor: &mut V, _extra: ()| { + visitor.visit_span(self) + }); + // Do nothing. + } + fn flat_map_foreign_item(&mut self, ni: P) -> SmallVec<[P; 1]> { walk_flat_map_foreign_item(self, ni) } @@ -462,12 +731,6 @@ macro_rules! common_visitor_and_walkers { walk_flat_map_where_predicate(self, where_predicate) } - // Span visiting is no longer used, but we keep it for now, - // in case it's needed for something like #127241. - fn visit_span(&mut self, _sp: &$mut Span) { - // Do nothing. - } - fn flat_map_pat_field(&mut self, fp: PatField) -> SmallVec<[PatField; 1]> { walk_flat_map_pat_field(self, fp) } @@ -492,148 +755,45 @@ macro_rules! common_visitor_and_walkers { #[inline] )? fn visit_span<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, span: &$($lt)? $($mut)? Span) -> V::Result { - $( - ${ignore($mut)} - vis.visit_span(span); - )? + $(${ignore($mut)} vis.visit_span(span))?; V::Result::output() } - /// helper since `Visitor` wants `NodeId` but `MutVisitor` wants `&mut NodeId` - $(${ignore($lt)} - #[expect(rustc::pass_by_value)] - )? - #[inline] - fn visit_id<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, id: &$($lt)? $($mut)? NodeId) -> V::Result { - // deref `&NodeId` into `NodeId` only for `Visitor` - vis.visit_id( $(${ignore($lt)} * )? id) - } - - // this is only used by the MutVisitor. We include this symmetry here to make writing other functions easier - fn visit_safety<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, safety: &$($lt)? $($mut)? Safety) -> V::Result { - match safety { - Safety::Unsafe(span) => visit_span(vis, span), - Safety::Safe(span) => visit_span(vis, span), - Safety::Default => { V::Result::output() } - } - } - - fn visit_constness<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, constness: &$($lt)? $($mut)? Const) -> V::Result { - match constness { - Const::Yes(span) => visit_span(vis, span), - Const::No => { - V::Result::output() - } - } - } - - fn visit_defaultness<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, defaultness: &$($lt)? $($mut)? Defaultness) -> V::Result { - match defaultness { - Defaultness::Default(span) => visit_span(vis, span), - Defaultness::Final => { - V::Result::output() - } - } - } - - fn visit_polarity<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - polarity: &$($lt)? $($mut)? ImplPolarity, - ) -> V::Result { - match polarity { - ImplPolarity::Positive => { V::Result::output() } - ImplPolarity::Negative(span) => visit_span(vis, span), - } - } - - $(${ignore($lt)} - #[inline] - )? - fn visit_modifiers<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - m: &$($lt)? $($mut)? TraitBoundModifiers - ) -> V::Result { - let TraitBoundModifiers { constness, asyncness, polarity } = m; - match constness { - BoundConstness::Never => {} - BoundConstness::Always(span) | BoundConstness::Maybe(span) => try_visit!(visit_span(vis, span)), - } - match asyncness { - BoundAsyncness::Normal => {} - BoundAsyncness::Async(span) => try_visit!(visit_span(vis, span)), - } - match polarity { - BoundPolarity::Positive => {} - BoundPolarity::Negative(span) | BoundPolarity::Maybe(span) => try_visit!(visit_span(vis, span)), + $(impl_visitable!(|&$lt self: ThinVec<(UseTree, NodeId)>, vis: &mut V, _extra: ()| { + for (nested_tree, nested_id) in self { + try_visit!(vis.visit_nested_use_tree(nested_tree, *nested_id)); } V::Result::output() - } + });)? + $(impl_visitable_list!(<$mut> ThinVec<(UseTree, NodeId)>,);)? - $(${ignore($lt)} - #[inline] - )? - fn walk_capture_by<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - capture_by: &$($lt)? $($mut)? CaptureBy - ) -> V::Result { - match capture_by { - CaptureBy::Ref => { V::Result::output() } - CaptureBy::Value { move_kw } => { - visit_span(vis, move_kw) - } - CaptureBy::Use { use_kw } => { - visit_span(vis, use_kw) - } - } - } - - fn visit_bounds<$($lt,)? V: $Visitor$(<$lt>)?>(visitor: &mut V, bounds: &$($lt)? $($mut)? GenericBounds, ctxt: BoundKind) -> V::Result { - walk_list!(visitor, visit_param_bound, bounds, ctxt); - V::Result::output() - } - - pub fn walk_label<$($lt,)? V: $Visitor$(<$lt>)?>(visitor: &mut V, Label { ident }: &$($lt)? $($mut)? Label) -> V::Result { - visitor.visit_ident(ident) - } - - pub fn walk_fn_header<$($lt,)? V: $Visitor$(<$lt>)?>(visitor: &mut V, header: &$($lt)? $($mut)? FnHeader) -> V::Result { - let FnHeader { safety, coroutine_kind, constness, ext: _ } = header; - try_visit!(visit_constness(visitor, constness)); - visit_opt!(visitor, visit_coroutine_kind, coroutine_kind); - visit_safety(visitor, safety) - } - - pub fn walk_lifetime<$($lt,)? V: $Visitor$(<$lt>)?>(visitor: &mut V, Lifetime { id, ident }: &$($lt)? $($mut)? Lifetime) -> V::Result { - try_visit!(visit_id(visitor, id)); - visitor.visit_ident(ident) - } - - fn walk_item_ctxt<$($lt,)? V: $Visitor$(<$lt>)?, K: WalkItemKind>( + fn walk_item_inner<$($lt,)? K: WalkItemKind, V: $Visitor$(<$lt>)?>( visitor: &mut V, item: &$($mut)? $($lt)? Item, ctxt: K::Ctxt, ) -> V::Result { let Item { attrs, id, kind, vis, span, tokens: _ } = item; - try_visit!(visit_id(visitor, id)); - walk_list!(visitor, visit_attribute, attrs); - try_visit!(visitor.visit_vis(vis)); + visit_visitable!($($mut)? visitor, id, attrs, vis); try_visit!(kind.walk(*span, *id, vis, ctxt, visitor)); - visit_span(visitor, span) + visit_visitable!($($mut)? visitor, span); + V::Result::output() } - pub fn walk_item<$($lt,)? V: $Visitor$(<$lt>)?, K: WalkItemKind>( + // Do not implement `Walkable`/`MutWalkable` for *Item to avoid confusion. + pub fn walk_item<$($lt,)? K: WalkItemKind, V: $Visitor$(<$lt>)?>( visitor: &mut V, item: &$($mut)? $($lt)? Item, ) -> V::Result { - walk_item_ctxt(visitor, item, ()) + walk_item_inner(visitor, item, ()) } - pub fn walk_assoc_item<$($lt,)? V: $Visitor$(<$lt>)?>( + // Do not implement `Walkable`/`MutWalkable` for *Item to avoid confusion. + pub fn walk_assoc_item<$($lt,)? K: WalkItemKind, V: $Visitor$(<$lt>)?>( visitor: &mut V, - item: &$($mut)? $($lt)? AssocItem, + item: &$($mut)? $($lt)? Item, ctxt: AssocCtxt, ) -> V::Result { - walk_item_ctxt(visitor, item, ctxt) + walk_item_inner(visitor, item, ctxt) } impl WalkItemKind for ItemKind { @@ -647,179 +807,52 @@ macro_rules! common_visitor_and_walkers { vis: &mut V, ) -> V::Result { match self { - ItemKind::ExternCrate(_orig_name, ident) => vis.visit_ident(ident), - ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree), - ItemKind::Static(box StaticItem { - ident, - ty, - safety: _, - mutability: _, - expr, - define_opaque, - }) => { - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_ty(ty)); - visit_opt!(vis, visit_expr, expr); - walk_define_opaques(vis, define_opaque) - } - ItemKind::Const(item) => { - walk_const_item(vis, item) - } ItemKind::Fn(func) => { let kind = FnKind::Fn(FnCtxt::Free, visibility, &$($mut)? *func); - vis.visit_fn(kind, span, id) - } - ItemKind::Mod(safety, ident, mod_kind) => { - try_visit!(visit_safety(vis, safety)); - try_visit!(vis.visit_ident(ident)); - match mod_kind { - ModKind::Loaded( - items, - _inline, - ModSpans { inner_span, inject_use_span }, - _, - ) => { - try_visit!(visit_items(vis, items)); - try_visit!(visit_span(vis, inner_span)); - try_visit!(visit_span(vis, inject_use_span)); - } - ModKind::Unloaded => {} - } - V::Result::output() - } - ItemKind::ForeignMod(nm) => vis.visit_foreign_mod(nm), - ItemKind::GlobalAsm(asm) => vis.visit_inline_asm(asm), - ItemKind::TyAlias(box TyAlias { - defaultness, - ident, - generics, - $(${ignore($lt)} #[expect(unused)])? - where_clauses, - bounds, - ty, - }) => { - try_visit!(visit_defaultness(vis, defaultness)); - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_generics(generics)); - try_visit!(visit_bounds(vis, bounds, BoundKind::Bound)); - visit_opt!(vis, visit_ty, ty); - $(${ignore($mut)} - walk_ty_alias_where_clauses(vis, where_clauses); - )? - V::Result::output() - } - ItemKind::Enum(ident, generics, enum_definition) => { - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_generics(generics)); - visit_variants(vis, &$($mut)? enum_definition.variants) + try_visit!(vis.visit_fn(kind, span, id)); } + ItemKind::ExternCrate(orig_name, ident) => + visit_visitable!($($mut)? vis, orig_name, ident), + ItemKind::Use(use_tree) => + visit_visitable!($($mut)? vis, use_tree), + ItemKind::Static(item) => + visit_visitable!($($mut)? vis, item), + ItemKind::Const(item) => + visit_visitable!($($mut)? vis, item), + ItemKind::Mod(safety, ident, mod_kind) => + visit_visitable!($($mut)? vis, safety, ident, mod_kind), + ItemKind::ForeignMod(nm) => + visit_visitable!($($mut)? vis, nm), + ItemKind::GlobalAsm(asm) => + visit_visitable!($($mut)? vis, asm), + ItemKind::TyAlias(ty_alias) => + visit_visitable!($($mut)? vis, ty_alias), + ItemKind::Enum(ident, generics, enum_definition) => + visit_visitable!($($mut)? vis, ident, generics, enum_definition), ItemKind::Struct(ident, generics, variant_data) - | ItemKind::Union(ident, generics, variant_data) => { - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_generics(generics)); - vis.visit_variant_data(variant_data) - } - ItemKind::Impl(box Impl { - defaultness, - safety, - generics, - constness, - polarity, - of_trait, - self_ty, - items, - }) => { - try_visit!(visit_defaultness(vis, defaultness)); - try_visit!(visit_safety(vis, safety)); - try_visit!(vis.visit_generics(generics)); - try_visit!(visit_constness(vis, constness)); - try_visit!(visit_polarity(vis, polarity)); - visit_opt!(vis, visit_trait_ref, of_trait); - try_visit!(vis.visit_ty(self_ty)); - visit_assoc_items(vis, items, AssocCtxt::Impl { of_trait: of_trait.is_some() }) - } - ItemKind::Trait(box Trait { safety, is_auto: _, ident, generics, bounds, items }) => { - try_visit!(visit_safety(vis, safety)); - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_generics(generics)); - try_visit!(visit_bounds(vis, bounds, BoundKind::Bound)); - visit_assoc_items(vis, items, AssocCtxt::Trait) - } + | ItemKind::Union(ident, generics, variant_data) => + visit_visitable!($($mut)? vis, ident, generics, variant_data), + ItemKind::Impl(impl_) => + visit_visitable!($($mut)? vis, impl_), + ItemKind::Trait(trait_) => + visit_visitable!($($mut)? vis, trait_), ItemKind::TraitAlias(ident, generics, bounds) => { - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_generics(generics)); - visit_bounds(vis, bounds, BoundKind::Bound) - } - ItemKind::MacCall(m) => vis.visit_mac_call(m), - ItemKind::MacroDef(ident, def) => { - try_visit!(vis.visit_ident(ident)); - vis.visit_macro_def(def) - } - ItemKind::Delegation(box Delegation { - id, - qself, - path, - ident, - rename, - body, - from_glob: _, - }) => { - try_visit!(visit_id(vis, id)); - try_visit!(vis.visit_qself(qself)); - try_visit!(vis.visit_path(path)); - try_visit!(vis.visit_ident(ident)); - visit_opt!(vis, visit_ident, rename); - visit_opt!(vis, visit_block, body); - V::Result::output() - } - ItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => { - try_visit!(vis.visit_qself(qself)); - try_visit!(vis.visit_path(prefix)); - if let Some(suffixes) = suffixes { - for (ident, rename) in suffixes { - try_visit!(vis.visit_ident(ident)); - visit_opt!(vis, visit_ident, rename); - } - } - visit_opt!(vis, visit_block, body); - V::Result::output() + visit_visitable!($($mut)? vis, ident, generics); + visit_visitable_with!($($mut)? vis, bounds, BoundKind::Bound) } + ItemKind::MacCall(m) => + visit_visitable!($($mut)? vis, m), + ItemKind::MacroDef(ident, def) => + visit_visitable!($($mut)? vis, ident, def), + ItemKind::Delegation(delegation) => + visit_visitable!($($mut)? vis, delegation), + ItemKind::DelegationMac(dm) => + visit_visitable!($($mut)? vis, dm), } + V::Result::output() } } - fn walk_const_item<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - item: &$($lt)? $($mut)? ConstItem, - ) -> V::Result { - let ConstItem { defaultness, ident, generics, ty, expr, define_opaque } = item; - try_visit!(visit_defaultness(vis, defaultness)); - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_generics(generics)); - try_visit!(vis.visit_ty(ty)); - visit_opt!(vis, visit_expr, expr); - walk_define_opaques(vis, define_opaque) - } - - fn walk_foreign_mod<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, foreign_mod: &$($lt)? $($mut)? ForeignMod) -> V::Result { - let ForeignMod { extern_span: _, safety, abi: _, items } = foreign_mod; - try_visit!(visit_safety(vis, safety)); - visit_foreign_items(vis, items) - } - - fn walk_define_opaques<$($lt,)? V: $Visitor$(<$lt>)?>( - visitor: &mut V, - define_opaque: &$($lt)? $($mut)? Option>, - ) -> V::Result { - if let Some(define_opaque) = define_opaque { - for (id, path) in define_opaque { - try_visit!(visit_id(visitor, id)); - try_visit!(visitor.visit_path(path)); - } - } - V::Result::output() - } - impl WalkItemKind for AssocItemKind { type Ctxt = AssocCtxt; fn walk<$($lt,)? V: $Visitor$(<$lt>)?>( @@ -831,64 +864,22 @@ macro_rules! common_visitor_and_walkers { vis: &mut V, ) -> V::Result { match self { - AssocItemKind::Const(item) => { - walk_const_item(vis, item) - } + AssocItemKind::Const(item) => + visit_visitable!($($mut)? vis, item), AssocItemKind::Fn(func) => { - vis.visit_fn(FnKind::Fn(FnCtxt::Assoc(ctxt), visibility, &$($mut)? *func), span, id) - } - AssocItemKind::Type(box TyAlias { - generics, - ident, - bounds, - ty, - defaultness, - $(${ignore($lt)} #[expect(unused)])? - where_clauses, - }) => { - try_visit!(visit_defaultness(vis, defaultness)); - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_generics(generics)); - try_visit!(visit_bounds(vis, bounds, BoundKind::Bound)); - visit_opt!(vis, visit_ty, ty); - $(${ignore($mut)} - walk_ty_alias_where_clauses(vis, where_clauses); - )? - V::Result::output() - } - AssocItemKind::MacCall(mac) => { - vis.visit_mac_call(mac) - } - AssocItemKind::Delegation(box Delegation { - id, - qself, - path, - ident, - rename, - body, - from_glob: _, - }) => { - try_visit!(visit_id(vis, id)); - try_visit!(vis.visit_qself(qself)); - try_visit!(vis.visit_path(path)); - try_visit!(vis.visit_ident(ident)); - visit_opt!(vis, visit_ident, rename); - visit_opt!(vis, visit_block, body); - V::Result::output() - } - AssocItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => { - try_visit!(vis.visit_qself(qself)); - try_visit!(vis.visit_path(prefix)); - if let Some(suffixes) = suffixes { - for (ident, rename) in suffixes { - try_visit!(vis.visit_ident(ident)); - visit_opt!(vis, visit_ident, rename); - } - } - visit_opt!(vis, visit_block, body); - V::Result::output() + let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), visibility, &$($mut)? *func); + try_visit!(vis.visit_fn(kind, span, id)) } + AssocItemKind::Type(alias) => + visit_visitable!($($mut)? vis, alias), + AssocItemKind::MacCall(mac) => + visit_visitable!($($mut)? vis, mac), + AssocItemKind::Delegation(delegation) => + visit_visitable!($($mut)? vis, delegation), + AssocItemKind::DelegationMac(dm) => + visit_visitable!($($mut)? vis, dm), } + V::Result::output() } } @@ -903,545 +894,18 @@ macro_rules! common_visitor_and_walkers { vis: &mut V, ) -> V::Result { match self { - ForeignItemKind::Static(box StaticItem { - ident, - ty, - mutability: _, - expr, - safety: _, - define_opaque, - }) => { - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_ty(ty)); - visit_opt!(vis, visit_expr, expr); - walk_define_opaques(vis, define_opaque) - } + ForeignItemKind::Static(item) => + visit_visitable!($($mut)? vis, item), ForeignItemKind::Fn(func) => { - vis.visit_fn(FnKind::Fn(FnCtxt::Foreign, visibility, &$($mut)?*func), span, id) - } - ForeignItemKind::TyAlias(box TyAlias { - defaultness, - ident, - generics, - bounds, - ty, - $(${ignore($lt)} #[expect(unused)])? - where_clauses, - }) => { - try_visit!(visit_defaultness(vis, defaultness)); - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_generics(generics)); - try_visit!(visit_bounds(vis, bounds, BoundKind::Bound)); - visit_opt!(vis, visit_ty, ty); - $(${ignore($mut)} - walk_ty_alias_where_clauses(vis, where_clauses); - )? - V::Result::output() - } - ForeignItemKind::MacCall(mac) => { - vis.visit_mac_call(mac) + let kind = FnKind::Fn(FnCtxt::Foreign, visibility, &$($mut)?*func); + try_visit!(vis.visit_fn(kind, span, id)) } + ForeignItemKind::TyAlias(alias) => + visit_visitable!($($mut)? vis, alias), + ForeignItemKind::MacCall(mac) => + visit_visitable!($($mut)? vis, mac), } - } - } - - fn walk_coroutine_kind<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - coroutine_kind: &$($lt)? $($mut)? CoroutineKind, - ) -> V::Result { - let (CoroutineKind::Async { span, closure_id, return_impl_trait_id } - | CoroutineKind::Gen { span, closure_id, return_impl_trait_id } - | CoroutineKind::AsyncGen { span, closure_id, return_impl_trait_id }) - = coroutine_kind; - try_visit!(visit_id(vis, closure_id)); - try_visit!(visit_id(vis, return_impl_trait_id)); - visit_span(vis, span) - } - - pub fn walk_pat<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - pattern: &$($lt)? $($mut)? Pat - ) -> V::Result { - let Pat { id, kind, span, tokens: _ } = pattern; - try_visit!(visit_id(vis, id)); - match kind { - PatKind::Err(_guar) => {} - PatKind::Missing | PatKind::Wild | PatKind::Rest | PatKind::Never => {} - PatKind::Ident(_bmode, ident, optional_subpattern) => { - try_visit!(vis.visit_ident(ident)); - visit_opt!(vis, visit_pat, optional_subpattern); - } - PatKind::Expr(expression) => try_visit!(vis.visit_expr(expression)), - PatKind::TupleStruct(opt_qself, path, elems) => { - try_visit!(vis.visit_qself(opt_qself)); - try_visit!(vis.visit_path(path)); - walk_list!(vis, visit_pat, elems); - } - PatKind::Path(opt_qself, path) => { - try_visit!(vis.visit_qself(opt_qself)); - try_visit!(vis.visit_path(path)) - } - PatKind::Struct(opt_qself, path, fields, _rest) => { - try_visit!(vis.visit_qself(opt_qself)); - try_visit!(vis.visit_path(path)); - try_visit!(visit_pat_fields(vis, fields)); - } - PatKind::Box(subpattern) | PatKind::Deref(subpattern) | PatKind::Paren(subpattern) => { - try_visit!(vis.visit_pat(subpattern)); - } - PatKind::Ref(subpattern, _ /*mutbl*/) => { - try_visit!(vis.visit_pat(subpattern)); - } - PatKind::Range(lower_bound, upper_bound, _end) => { - visit_opt!(vis, visit_expr, lower_bound); - visit_opt!(vis, visit_expr, upper_bound); - try_visit!(visit_span(vis, span)); - } - PatKind::Guard(subpattern, guard_condition) => { - try_visit!(vis.visit_pat(subpattern)); - try_visit!(vis.visit_expr(guard_condition)); - } - PatKind::Tuple(elems) | PatKind::Slice(elems) | PatKind::Or(elems) => { - walk_list!(vis, visit_pat, elems); - } - PatKind::MacCall(mac) => try_visit!(vis.visit_mac_call(mac)), - } - visit_span(vis, span) - } - - pub fn walk_anon_const<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - constant: &$($lt)? $($mut)? AnonConst, - ) -> V::Result { - let AnonConst { id, value } = constant; - try_visit!(visit_id(vis, id)); - vis.visit_expr(value) - } - - pub fn walk_path_segment<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - segment: &$($lt)? $($mut)? PathSegment, - ) -> V::Result { - let PathSegment { ident, id, args } = segment; - try_visit!(visit_id(vis, id)); - try_visit!(vis.visit_ident(ident)); - visit_opt!(vis, visit_generic_args, args); - V::Result::output() - } - - pub fn walk_block<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - block: &$($lt)? $($mut)? Block - ) -> V::Result { - let Block { stmts, id, rules: _, span, tokens: _ } = block; - try_visit!(visit_id(vis, id)); - try_visit!(visit_stmts(vis, stmts)); - visit_span(vis, span) - } - - - pub fn walk_ty<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, ty: &$($lt)? $($mut)? Ty - ) -> V::Result { - let Ty { id, kind, span, tokens: _ } = ty; - try_visit!(visit_id(vis, id)); - match kind { - TyKind::Err(_guar) => {} - TyKind::Infer | TyKind::ImplicitSelf | TyKind::Dummy | TyKind::Never | TyKind::CVarArgs => {} - TyKind::Slice(ty) | TyKind::Paren(ty) => try_visit!(vis.visit_ty(ty)), - TyKind::Ptr(MutTy { ty, mutbl: _ }) => try_visit!(vis.visit_ty(ty)), - TyKind::Ref(opt_lifetime, MutTy { ty, mutbl: _ }) - | TyKind::PinnedRef(opt_lifetime, MutTy { ty, mutbl: _ }) => { - // FIXME(fee1-dead) asymmetry - visit_opt!(vis, visit_lifetime, opt_lifetime$(${ignore($lt)}, LifetimeCtxt::Ref)?); - try_visit!(vis.visit_ty(ty)); - } - TyKind::Tup(tuple_element_types) => { - walk_list!(vis, visit_ty, tuple_element_types); - } - TyKind::FnPtr(function_declaration) => { - let FnPtrTy { safety, ext: _, generic_params, decl, decl_span } = - &$($mut)? **function_declaration; - try_visit!(visit_safety(vis, safety)); - try_visit!(visit_generic_params(vis, generic_params)); - try_visit!(vis.visit_fn_decl(decl)); - try_visit!(visit_span(vis, decl_span)); - } - TyKind::UnsafeBinder(binder) => { - try_visit!(visit_generic_params(vis, &$($mut)? binder.generic_params)); - try_visit!(vis.visit_ty(&$($mut)? binder.inner_ty)); - } - TyKind::Path(maybe_qself, path) => { - try_visit!(vis.visit_qself(maybe_qself)); - try_visit!(vis.visit_path(path)); - } - TyKind::Pat(ty, pat) => { - try_visit!(vis.visit_ty(ty)); - try_visit!(vis.visit_ty_pat(pat)); - } - TyKind::Array(ty, length) => { - try_visit!(vis.visit_ty(ty)); - try_visit!(vis.visit_anon_const(length)); - } - TyKind::TraitObject(bounds, _syntax) => { - walk_list!(vis, visit_param_bound, bounds, BoundKind::TraitObject); - } - TyKind::ImplTrait(id, bounds) => { - try_visit!(visit_id(vis, id)); - walk_list!(vis, visit_param_bound, bounds, BoundKind::Impl); - } - TyKind::Typeof(expression) => try_visit!(vis.visit_anon_const(expression)), - - TyKind::MacCall(mac) => try_visit!(vis.visit_mac_call(mac)), - } - visit_span(vis, span) - } - - pub fn walk_crate<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - krate: &$($lt)? $($mut)? Crate, - ) -> V::Result { - let Crate { attrs, items, spans, id, is_placeholder: _ } = krate; - try_visit!(visit_id(vis, id)); - walk_list!(vis, visit_attribute, attrs); - try_visit!(visit_items(vis, items)); - let ModSpans { inner_span, inject_use_span } = spans; - try_visit!(visit_span(vis, inner_span)); - visit_span(vis, inject_use_span) - } - - pub fn walk_local<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - local: &$($lt)? $($mut)? Local, - ) -> V::Result { - let Local { id, super_, pat, ty, kind, span, colon_sp, attrs, tokens: _ } = local; - if let Some(sp) = super_ { - try_visit!(visit_span(vis, sp)); - } - try_visit!(visit_id(vis, id)); - walk_list!(vis, visit_attribute, attrs); - try_visit!(vis.visit_pat(pat)); - visit_opt!(vis, visit_ty, ty); - match kind { - LocalKind::Decl => {} - LocalKind::Init(init) => { - try_visit!(vis.visit_expr(init)) - } - LocalKind::InitElse(init, els) => { - try_visit!(vis.visit_expr(init)); - try_visit!(vis.visit_block(els)); - } - } - if let Some(sp) = colon_sp { - try_visit!(visit_span(vis, sp)); - } - visit_span(vis, span) - } - - pub fn walk_poly_trait_ref<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - p: &$($lt)? $($mut)? PolyTraitRef, - ) -> V::Result { - let PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens: _ } = p; - try_visit!(visit_modifiers(vis, modifiers)); - try_visit!(visit_generic_params(vis, bound_generic_params)); - try_visit!(vis.visit_trait_ref(trait_ref)); - visit_span(vis, span) - } - - pub fn walk_trait_ref<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - TraitRef { path, ref_id }: &$($lt)? $($mut)? TraitRef, - ) -> V::Result { - try_visit!(vis.visit_path(path)); - visit_id(vis, ref_id) - } - - pub fn walk_variant<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - variant: &$($lt)? $($mut)? Variant, - ) -> V::Result { - let Variant { attrs, id, span, vis: visibility, ident, data, disr_expr, is_placeholder: _ } = variant; - try_visit!(visit_id(vis, id)); - walk_list!(vis, visit_attribute, attrs); - try_visit!(vis.visit_vis(visibility)); - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_variant_data(data)); - visit_opt!(vis, visit_anon_const, disr_expr); - visit_span(vis, span) - } - - pub fn walk_expr_field<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - f: &$($lt)? $($mut)? ExprField, - ) -> V::Result { - let ExprField { attrs, id, span, ident, expr, is_shorthand: _, is_placeholder: _ } = f; - try_visit!(visit_id(vis, id)); - walk_list!(vis, visit_attribute, attrs); - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_expr(expr)); - visit_span(vis, span) - } - - pub fn walk_pat_field<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - fp: &$($lt)? $($mut)? PatField, - ) -> V::Result { - let PatField { ident, pat, is_shorthand: _, attrs, id, span, is_placeholder: _ } = fp; - try_visit!(visit_id(vis, id)); - walk_list!(vis, visit_attribute, attrs); - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_pat(pat)); - visit_span(vis, span) - } - - pub fn walk_ty_pat<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - tp: &$($lt)? $($mut)? TyPat, - ) -> V::Result { - let TyPat { id, kind, span, tokens: _ } = tp; - try_visit!(visit_id(vis, id)); - match kind { - TyPatKind::Range(start, end, Spanned { span, node: _include_end }) => { - visit_opt!(vis, visit_anon_const, start); - visit_opt!(vis, visit_anon_const, end); - try_visit!(visit_span(vis, span)); - } - TyPatKind::Or(variants) => walk_list!(vis, visit_ty_pat, variants), - TyPatKind::Err(_) => {} - } - visit_span(vis, span) - } - - fn walk_qself<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - qself: &$($lt)? $($mut)? Option>, - ) -> V::Result { - if let Some(qself) = qself { - let QSelf { ty, path_span, position: _ } = &$($mut)? **qself; - try_visit!(vis.visit_ty(ty)); - try_visit!(visit_span(vis, path_span)); - } - V::Result::output() - } - - pub fn walk_path<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - path: &$($lt)? $($mut)? Path, - ) -> V::Result { - let Path { span, segments, tokens: _ } = path; - walk_list!(vis, visit_path_segment, segments); - visit_span(vis, span) - } - - pub fn walk_use_tree<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - use_tree: &$($lt)? $($mut)? UseTree, - ) -> V::Result { - let UseTree { prefix, kind, span } = use_tree; - try_visit!(vis.visit_path(prefix)); - match kind { - UseTreeKind::Simple(rename) => { - // The extra IDs are handled during AST lowering. - visit_opt!(vis, visit_ident, rename); - } - UseTreeKind::Glob => {} - UseTreeKind::Nested { items, span } => { - for (nested_tree, nested_id) in items { - try_visit!(visit_nested_use_tree(vis, nested_tree, nested_id)); - } - try_visit!(visit_span(vis, span)); - } - } - visit_span(vis, span) - } - - pub fn walk_generic_args<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - generic_args: &$($lt)? $($mut)? GenericArgs - ) -> V::Result { - match generic_args { - GenericArgs::AngleBracketed(AngleBracketedArgs { span, args }) => { - for arg in args { - match arg { - AngleBracketedArg::Arg(a) => try_visit!(vis.visit_generic_arg(a)), - AngleBracketedArg::Constraint(c) => { - try_visit!(vis.visit_assoc_item_constraint(c)) - } - } - } - visit_span(vis, span) - } - GenericArgs::Parenthesized(data) => { - let ParenthesizedArgs { span, inputs, inputs_span, output } = data; - walk_list!(vis, visit_ty, inputs); - try_visit!(vis.visit_fn_ret_ty(output)); - try_visit!(visit_span(vis, span)); - visit_span(vis, inputs_span) - } - GenericArgs::ParenthesizedElided(span) => visit_span(vis, span) - } - } - - pub fn walk_generic_arg<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - generic_arg: &$($lt)? $($mut)? GenericArg, - ) -> V::Result { - match generic_arg { - GenericArg::Lifetime(lt) => vis.visit_lifetime(lt, $(${ignore($lt)} LifetimeCtxt::GenericArg)? ), - GenericArg::Type(ty) => vis.visit_ty(ty), - GenericArg::Const(ct) => vis.visit_anon_const(ct), - } - } - - pub fn walk_assoc_item_constraint<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - constraint: &$($lt)? $($mut)? AssocItemConstraint, - ) -> V::Result { - let AssocItemConstraint { id, ident, gen_args, kind, span } = constraint; - try_visit!(visit_id(vis, id)); - try_visit!(vis.visit_ident(ident)); - visit_opt!(vis, visit_generic_args, gen_args); - match kind { - AssocItemConstraintKind::Equality { term } => match term { - Term::Ty(ty) => try_visit!(vis.visit_ty(ty)), - Term::Const(c) => try_visit!(vis.visit_anon_const(c)), - }, - AssocItemConstraintKind::Bound { bounds } => { - try_visit!(visit_bounds(vis, bounds, BoundKind::Bound)); - } - } - visit_span(vis, span) - } - - pub fn walk_param_bound<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, bound: &$($lt)? $($mut)? GenericBound) -> V::Result { - match bound { - GenericBound::Trait(trait_ref) => vis.visit_poly_trait_ref(trait_ref), - GenericBound::Outlives(lifetime) => vis.visit_lifetime(lifetime, $(${ignore($lt)} LifetimeCtxt::Bound)?), - GenericBound::Use(args, span) => { - walk_list!(vis, visit_precise_capturing_arg, args); - visit_span(vis, span) - } - } - } - - pub fn walk_precise_capturing_arg<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - arg: &$($lt)? $($mut)? PreciseCapturingArg, - ) -> V::Result { - match arg { - PreciseCapturingArg::Lifetime(lt) => vis.visit_lifetime(lt, $(${ignore($lt)} LifetimeCtxt::GenericArg)?), - PreciseCapturingArg::Arg(path, id) => { - try_visit!(visit_id(vis, id)); - vis.visit_path(path) - } - } - } - - pub fn walk_generic_param<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - param: &$($lt)? $($mut)? GenericParam, - ) -> V::Result { - let GenericParam { id, ident, attrs, bounds, is_placeholder: _, kind, colon_span } = - param; - try_visit!(visit_id(vis, id)); - walk_list!(vis, visit_attribute, attrs); - try_visit!(vis.visit_ident(ident)); - walk_list!(vis, visit_param_bound, bounds, BoundKind::Bound); - match kind { - GenericParamKind::Lifetime => (), - GenericParamKind::Type { default } => visit_opt!(vis, visit_ty, default), - GenericParamKind::Const { ty, default, span } => { - try_visit!(vis.visit_ty(ty)); - visit_opt!(vis, visit_anon_const, default); - try_visit!(visit_span(vis, span)); - } - } - if let Some(sp) = colon_span { - try_visit!(visit_span(vis, sp)) - } - V::Result::output() - } - - pub fn walk_generics<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, generics: &$($lt)? $($mut)? Generics) -> V::Result { - let Generics { params, where_clause, span } = generics; - let WhereClause { has_where_token: _, predicates, span: where_clause_span } = where_clause; - try_visit!(visit_generic_params(vis, params)); - try_visit!(visit_where_predicates(vis, predicates)); - try_visit!(visit_span(vis, span)); - visit_span(vis, where_clause_span) - } - - pub fn walk_contract<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, c: &$($lt)? $($mut)? FnContract) -> V::Result { - let FnContract { requires, ensures } = c; - visit_opt!(vis, visit_expr, requires); - visit_opt!(vis, visit_expr, ensures); - V::Result::output() - } - - pub fn walk_where_predicate<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - predicate: &$($lt)? $($mut)? WherePredicate, - ) -> V::Result { - let WherePredicate { attrs, kind, id, span, is_placeholder: _ } = predicate; - try_visit!(visit_id(vis, id)); - walk_list!(vis, visit_attribute, attrs); - try_visit!(visit_span(vis, span)); - vis.visit_where_predicate_kind(kind) - } - - pub fn walk_closure_binder<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - binder: &$($lt)? $($mut)? ClosureBinder, - ) -> V::Result { - match binder { - ClosureBinder::NotPresent => {} - ClosureBinder::For { generic_params, span } => { - try_visit!(visit_generic_params(vis, generic_params)); - try_visit!(visit_span(vis, span)); - } - } - V::Result::output() - } - - pub fn walk_where_predicate_kind<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - kind: &$($lt)? $($mut)? WherePredicateKind, - ) -> V::Result { - match kind { - WherePredicateKind::BoundPredicate(WhereBoundPredicate { - bounded_ty, - bounds, - bound_generic_params, - }) => { - try_visit!(visit_generic_params(vis, bound_generic_params)); - try_visit!(vis.visit_ty(bounded_ty)); - walk_list!(vis, visit_param_bound, bounds, BoundKind::Bound); - } - WherePredicateKind::RegionPredicate(WhereRegionPredicate { lifetime, bounds }) => { - try_visit!(vis.visit_lifetime(lifetime, $(${ignore($lt)} LifetimeCtxt::Bound )?)); - walk_list!(vis, visit_param_bound, bounds, BoundKind::Bound); - } - WherePredicateKind::EqPredicate(WhereEqPredicate { lhs_ty, rhs_ty }) => { - try_visit!(vis.visit_ty(lhs_ty)); - try_visit!(vis.visit_ty(rhs_ty)); - } - } - V::Result::output() - } - - pub fn walk_fn_decl<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - FnDecl { inputs, output }: &$($lt)? $($mut)? FnDecl, - ) -> V::Result { - try_visit!(visit_params(vis, inputs)); - vis.visit_fn_ret_ty(output) - } - - pub fn walk_fn_ret_ty<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, ret_ty: &$($lt)? $($mut)? FnRetTy) -> V::Result { - match ret_ty { - FnRetTy::Default(span) => visit_span(vis, span), - FnRetTy::Ty(output_ty) => vis.visit_ty(output_ty), + V::Result::output() } } @@ -1449,455 +913,200 @@ macro_rules! common_visitor_and_walkers { match kind { FnKind::Fn( _ctxt, - _vis, - Fn { - defaultness, - ident, - sig: FnSig { header, decl, span }, - generics, - contract, - body, - define_opaque, - }, - ) => { // Visibility is visited as a part of the item. - try_visit!(visit_defaultness(vis, defaultness)); - try_visit!(vis.visit_ident(ident)); - try_visit!(vis.visit_fn_header(header)); - try_visit!(vis.visit_generics(generics)); - try_visit!(vis.visit_fn_decl(decl)); - visit_opt!(vis, visit_contract, contract); - visit_opt!(vis, visit_block, body); - try_visit!(visit_span(vis, span)); - walk_define_opaques(vis, define_opaque) + _vis, + Fn { defaultness, ident, sig, generics, contract, body, define_opaque }, + ) => { + let FnSig { header, decl, span } = sig; + visit_visitable!($($mut)? vis, + defaultness, ident, header, generics, decl, + contract, body, span, define_opaque + ) } - FnKind::Closure(binder, coroutine_kind, decl, body) => { - try_visit!(vis.visit_closure_binder(binder)); - visit_opt!(vis, visit_coroutine_kind, coroutine_kind); - try_visit!(vis.visit_fn_decl(decl)); - vis.visit_expr(body) - } - } - } - - pub fn walk_variant_data<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, data: &$($lt)? $($mut)? VariantData) -> V::Result { - match data { - VariantData::Struct { fields, recovered: _ } => { - visit_field_defs(vis, fields) - } - VariantData::Tuple(fields, id) => { - try_visit!(visit_id(vis, id)); - visit_field_defs(vis, fields) - } - VariantData::Unit(id) => visit_id(vis, id), - } - } - - pub fn walk_field_def<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, field: &$($lt)? $($mut)? FieldDef) -> V::Result { - let FieldDef { attrs, id, span, vis: visibility, ident, ty, is_placeholder: _, safety: _, default } = - field; - try_visit!(visit_id(vis, id)); - walk_list!(vis, visit_attribute, attrs); - try_visit!(vis.visit_vis(visibility)); - visit_opt!(vis, visit_ident, ident); - try_visit!(vis.visit_ty(ty)); - visit_opt!(vis, visit_anon_const, default); - visit_span(vis, span) - } - - fn visit_delim_args<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, args: &$($lt)? $($mut)? DelimArgs) -> V::Result { - let DelimArgs { dspan, delim: _, tokens: _ } = args; - let DelimSpan { open, close } = dspan; - try_visit!(visit_span(vis, open)); - visit_span(vis, close) - } - - pub fn walk_mac<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, mac: &$($lt)? $($mut)? MacCall) -> V::Result { - let MacCall { path, args } = mac; - try_visit!(vis.visit_path(path)); - visit_delim_args(vis, args) - } - - fn walk_macro_def<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, macro_def: &$($lt)? $($mut)? MacroDef) -> V::Result { - let MacroDef { body, macro_rules: _ } = macro_def; - visit_delim_args(vis, body) - } - - pub fn walk_inline_asm<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, asm: &$($lt)? $($mut)? InlineAsm) -> V::Result { - let InlineAsm { - asm_macro: _, - template, - template_strs, - operands, - clobber_abis, - options: _, - line_spans, - } = asm; - for piece in template { - match piece { - InlineAsmTemplatePiece::String(_str) => {} - InlineAsmTemplatePiece::Placeholder { operand_idx: _, modifier: _, span } => { - try_visit!(visit_span(vis, span)); - } - } - } - for (_s1, _s2, span) in template_strs { - try_visit!(visit_span(vis, span)); - } - for (op, span) in operands { - match op { - InlineAsmOperand::In { expr, reg: _ } - | InlineAsmOperand::Out { expr: Some(expr), reg: _, late: _ } - | InlineAsmOperand::InOut { expr, reg: _, late: _ } => { - try_visit!(vis.visit_expr(expr)) - } - InlineAsmOperand::Out { expr: None, reg: _, late: _ } => {} - InlineAsmOperand::SplitInOut { in_expr, out_expr, reg: _, late: _ } => { - try_visit!(vis.visit_expr(in_expr)); - visit_opt!(vis, visit_expr, out_expr); - } - InlineAsmOperand::Const { anon_const } => { - try_visit!(vis.visit_anon_const(anon_const)) - } - InlineAsmOperand::Sym { sym } => try_visit!(vis.visit_inline_asm_sym(sym)), - InlineAsmOperand::Label { block } => try_visit!(vis.visit_block(block)), - } - try_visit!(visit_span(vis, span)); - } - for (_s1, span) in clobber_abis { - try_visit!(visit_span(vis, span)) - } - for span in line_spans { - try_visit!(visit_span(vis, span)) + FnKind::Closure(binder, coroutine_kind, decl, body) => + visit_visitable!($($mut)? vis, binder, coroutine_kind, decl, body), } V::Result::output() } - pub fn walk_inline_asm_sym<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - InlineAsmSym { id, qself, path }: &$($lt)? $($mut)? InlineAsmSym, - ) -> V::Result { - try_visit!(visit_id(vis, id)); - try_visit!(vis.visit_qself(qself)); - vis.visit_path(path) - } - - pub fn walk_format_args<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, fmt: &$($lt)? $($mut)? FormatArgs) -> V::Result { - let FormatArgs { span, template, arguments, uncooked_fmt_str: _, is_source_literal: _ } = fmt; - - let args = $(${ignore($mut)} arguments.all_args_mut())? $(${ignore($lt)} arguments.all_args())? ; - for FormatArgument { kind, expr } in args { - match kind { - FormatArgumentKind::Named(ident) | FormatArgumentKind::Captured(ident) => { - try_visit!(vis.visit_ident(ident)) - } - FormatArgumentKind::Normal => {} - } - try_visit!(vis.visit_expr(expr)); - } - for piece in template { - match piece { - FormatArgsPiece::Literal(_symbol) => {} - FormatArgsPiece::Placeholder(placeholder) => try_visit!(walk_format_placeholder(vis, placeholder)), - } - } - visit_span(vis, span) - } - - fn walk_format_placeholder<$($lt,)? V: $Visitor$(<$lt>)?>( - vis: &mut V, - placeholder: &$($lt)? $($mut)? FormatPlaceholder, - ) -> V::Result { - let FormatPlaceholder { argument, span, format_options, format_trait: _ } = placeholder; - if let Some(span) = span { - try_visit!(visit_span(vis, span)); - } - let FormatArgPosition { span, index: _, kind: _ } = argument; - if let Some(span) = span { - try_visit!(visit_span(vis, span)); - } - let FormatOptions { - width, - precision, - alignment: _, - fill: _, - sign: _, - alternate: _, - zero_pad: _, - debug_hex: _, - } = format_options; - match width { - None => {} - Some(FormatCount::Literal(_)) => {} - Some(FormatCount::Argument(FormatArgPosition { span, index: _, kind: _ })) => { - if let Some(span) = span { - try_visit!(visit_span(vis, span)); - } - } - } - match precision { - None => {} - Some(FormatCount::Literal(_)) => {} - Some(FormatCount::Argument(FormatArgPosition { span, index: _, kind: _ })) => { - if let Some(span) = span { - try_visit!(visit_span(vis, span)); - } - } - } + impl_walkable!(|&$($mut)? $($lt)? self: Impl, vis: &mut V| { + let Impl { defaultness, safety, generics, constness, polarity, of_trait, self_ty, items } = self; + visit_visitable!($($mut)? vis, defaultness, safety, generics, constness, polarity, of_trait, self_ty); + visit_visitable_with!($($mut)? vis, items, AssocCtxt::Impl { of_trait: of_trait.is_some() }); V::Result::output() - } + }); - pub fn walk_expr<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, expression: &$($lt)? $($mut)? Expr) -> V::Result { - let Expr { id, kind, span, attrs, tokens: _ } = expression; - try_visit!(visit_id(vis, id)); - walk_list!(vis, visit_attribute, attrs); + // Special case to call `visit_method_receiver_expr`. + impl_walkable!(|&$($mut)? $($lt)? self: MethodCall, vis: &mut V| { + let MethodCall { seg, receiver, args, span } = self; + try_visit!(vis.visit_method_receiver_expr(receiver)); + visit_visitable!($($mut)? vis, seg, args, span); + V::Result::output() + }); + + impl_walkable!(|&$($mut)? $($lt)? self: Expr, vis: &mut V| { + let Expr { id, kind, span, attrs, tokens: _ } = self; + visit_visitable!($($mut)? vis, id, attrs); match kind { - ExprKind::Array(exprs) => { - try_visit!(visit_exprs(vis, exprs)); - } - ExprKind::ConstBlock(anon_const) => try_visit!(vis.visit_anon_const(anon_const)), - ExprKind::Repeat(element, count) => { - try_visit!(vis.visit_expr(element)); - try_visit!(vis.visit_anon_const(count)); - } - ExprKind::Struct(se) => { - let StructExpr { qself, path, fields, rest } = &$($mut)?**se; - try_visit!(vis.visit_qself(qself)); - try_visit!(vis.visit_path(path)); - try_visit!(visit_expr_fields(vis, fields)); - match rest { - StructRest::Base(expr) => try_visit!(vis.visit_expr(expr)), - StructRest::Rest(span) => try_visit!(visit_span(vis, span)), - StructRest::None => {} - } - } - ExprKind::Tup(exprs) => { - try_visit!(visit_exprs(vis, exprs)); - } - ExprKind::Call(callee_expression, arguments) => { - try_visit!(vis.visit_expr(callee_expression)); - try_visit!(visit_exprs(vis, arguments)); - } - ExprKind::MethodCall(box MethodCall { seg, receiver, args, span }) => { - try_visit!(vis.visit_method_receiver_expr(receiver)); - try_visit!(vis.visit_path_segment(seg)); - try_visit!(visit_exprs(vis, args)); - try_visit!(visit_span(vis, span)); - } - ExprKind::Binary(Spanned { span, node: _ }, left_expression, right_expression) => { - try_visit!(vis.visit_expr(left_expression)); - try_visit!(vis.visit_expr(right_expression)); - try_visit!(visit_span(vis, span)) - } - ExprKind::AddrOf(_kind, _mutbl, subexpression) => { - try_visit!(vis.visit_expr(subexpression)); - } - ExprKind::Unary(_op, subexpression) => { - try_visit!(vis.visit_expr(subexpression)); - } - ExprKind::Cast(subexpression, typ) | ExprKind::Type(subexpression, typ) => { - try_visit!(vis.visit_expr(subexpression)); - try_visit!(vis.visit_ty(typ)); - } - ExprKind::Let(pat, expr, span, _recovered) => { - try_visit!(vis.visit_pat(pat)); - try_visit!(vis.visit_expr(expr)); - try_visit!(visit_span(vis, span)) - } - ExprKind::If(head_expression, if_block, optional_else) => { - try_visit!(vis.visit_expr(head_expression)); - try_visit!(vis.visit_block(if_block)); - visit_opt!(vis, visit_expr, optional_else); - } - ExprKind::While(subexpression, block, opt_label) => { - visit_opt!(vis, visit_label, opt_label); - try_visit!(vis.visit_expr(subexpression)); - try_visit!(vis.visit_block(block)); - } - ExprKind::ForLoop { pat, iter, body, label, kind: _ } => { - visit_opt!(vis, visit_label, label); - try_visit!(vis.visit_pat(pat)); - try_visit!(vis.visit_expr(iter)); - try_visit!(vis.visit_block(body)); - } - ExprKind::Loop(block, opt_label, span) => { - visit_opt!(vis, visit_label, opt_label); - try_visit!(vis.visit_block(block)); - try_visit!(visit_span(vis, span)) - } - ExprKind::Match(subexpression, arms, _kind) => { - try_visit!(vis.visit_expr(subexpression)); - try_visit!(visit_arms(vis, arms)); - } + ExprKind::Array(exprs) => + visit_visitable!($($mut)? vis, exprs), + ExprKind::ConstBlock(anon_const) => + visit_visitable!($($mut)? vis, anon_const), + ExprKind::Repeat(element, count) => + visit_visitable!($($mut)? vis, element, count), + ExprKind::Struct(se) => + visit_visitable!($($mut)? vis, se), + ExprKind::Tup(exprs) => + visit_visitable!($($mut)? vis, exprs), + ExprKind::Call(callee_expression, arguments) => + visit_visitable!($($mut)? vis, callee_expression, arguments), + ExprKind::MethodCall(mc) => + visit_visitable!($($mut)? vis, mc), + ExprKind::Binary(op, lhs, rhs) => + visit_visitable!($($mut)? vis, op, lhs, rhs), + ExprKind::AddrOf(kind, mutbl, subexpression) => + visit_visitable!($($mut)? vis, kind, mutbl, subexpression), + ExprKind::Unary(op, subexpression) => + visit_visitable!($($mut)? vis, op, subexpression), + ExprKind::Cast(subexpression, typ) | ExprKind::Type(subexpression, typ) => + visit_visitable!($($mut)? vis, subexpression, typ), + ExprKind::Let(pat, expr, span, _recovered) => + visit_visitable!($($mut)? vis, pat, expr, span), + ExprKind::If(head_expression, if_block, optional_else) => + visit_visitable!($($mut)? vis, head_expression, if_block, optional_else), + ExprKind::While(subexpression, block, opt_label) => + visit_visitable!($($mut)? vis, subexpression, block, opt_label), + ExprKind::ForLoop { pat, iter, body, label, kind } => + visit_visitable!($($mut)? vis, pat, iter, body, label, kind), + ExprKind::Loop(block, opt_label, span) => + visit_visitable!($($mut)? vis, block, opt_label, span), + ExprKind::Match(subexpression, arms, kind) => + visit_visitable!($($mut)? vis, subexpression, arms, kind), ExprKind::Closure(box Closure { binder, capture_clause, coroutine_kind, constness, - movability: _, + movability, fn_decl, body, fn_decl_span, fn_arg_span, }) => { - try_visit!(visit_constness(vis, constness)); - try_visit!(vis.visit_capture_by(capture_clause)); - try_visit!(vis.visit_fn( - FnKind::Closure(binder, coroutine_kind, fn_decl, body), - *span, - *id - )); - try_visit!(visit_span(vis, fn_decl_span)); - try_visit!(visit_span(vis, fn_arg_span)); - } - ExprKind::Block(block, opt_label) => { - visit_opt!(vis, visit_label, opt_label); - try_visit!(vis.visit_block(block)); - } - ExprKind::Gen(capture_clause, body, _kind, decl_span) => { - try_visit!(vis.visit_capture_by(capture_clause)); - try_visit!(vis.visit_block(body)); - try_visit!(visit_span(vis, decl_span)); - } - ExprKind::Await(expr, span) => { - try_visit!(vis.visit_expr(expr)); - try_visit!(visit_span(vis, span)); - } - ExprKind::Use(expr, span) => { - try_visit!(vis.visit_expr(expr)); - try_visit!(visit_span(vis, span)); - } - ExprKind::Assign(lhs, rhs, span) => { - try_visit!(vis.visit_expr(lhs)); - try_visit!(vis.visit_expr(rhs)); - try_visit!(visit_span(vis, span)); - } - ExprKind::AssignOp(Spanned { span, node: _ }, left_expression, right_expression) => { - try_visit!(vis.visit_expr(left_expression)); - try_visit!(vis.visit_expr(right_expression)); - try_visit!(visit_span(vis, span)); - } - ExprKind::Field(subexpression, ident) => { - try_visit!(vis.visit_expr(subexpression)); - try_visit!(vis.visit_ident(ident)); - } - ExprKind::Index(main_expression, index_expression, span) => { - try_visit!(vis.visit_expr(main_expression)); - try_visit!(vis.visit_expr(index_expression)); - try_visit!(visit_span(vis, span)); - } - ExprKind::Range(start, end, _limit) => { - visit_opt!(vis, visit_expr, start); - visit_opt!(vis, visit_expr, end); + visit_visitable!($($mut)? vis, constness, movability, capture_clause); + let kind = FnKind::Closure(binder, coroutine_kind, fn_decl, body); + try_visit!(vis.visit_fn(kind, *span, *id)); + visit_visitable!($($mut)? vis, fn_decl_span, fn_arg_span); } + ExprKind::Block(block, opt_label) => + visit_visitable!($($mut)? vis, block, opt_label), + ExprKind::Gen(capt, body, kind, decl_span) => + visit_visitable!($($mut)? vis, capt, body, kind, decl_span), + ExprKind::Await(expr, span) | ExprKind::Use(expr, span) => + visit_visitable!($($mut)? vis, expr, span), + ExprKind::Assign(lhs, rhs, span) => + visit_visitable!($($mut)? vis, lhs, rhs, span), + ExprKind::AssignOp(op, lhs, rhs) => + visit_visitable!($($mut)? vis, op, lhs, rhs), + ExprKind::Field(subexpression, ident) => + visit_visitable!($($mut)? vis, subexpression, ident), + ExprKind::Index(main_expression, index_expression, span) => + visit_visitable!($($mut)? vis, main_expression, index_expression, span), + ExprKind::Range(start, end, limit) => + visit_visitable!($($mut)? vis, start, end, limit), ExprKind::Underscore => {} - ExprKind::Path(maybe_qself, path) => { - try_visit!(vis.visit_qself(maybe_qself)); - try_visit!(vis.visit_path(path)); - } - ExprKind::Break(opt_label, opt_expr) => { - visit_opt!(vis, visit_label, opt_label); - visit_opt!(vis, visit_expr, opt_expr); - } - ExprKind::Continue(opt_label) => { - visit_opt!(vis, visit_label, opt_label); - } - ExprKind::Ret(optional_expression) => { - visit_opt!(vis, visit_expr, optional_expression); - } - ExprKind::Yeet(optional_expression) => { - visit_opt!(vis, visit_expr, optional_expression); - } - ExprKind::Become(expr) => try_visit!(vis.visit_expr(expr)), - ExprKind::MacCall(mac) => try_visit!(vis.visit_mac_call(mac)), - ExprKind::Paren(subexpression) => try_visit!(vis.visit_expr(subexpression)), - ExprKind::InlineAsm(asm) => try_visit!(vis.visit_inline_asm(asm)), - ExprKind::FormatArgs(f) => try_visit!(vis.visit_format_args(f)), - ExprKind::OffsetOf(container, fields) => { - try_visit!(vis.visit_ty(container)); - walk_list!(vis, visit_ident, fields); - } - ExprKind::Yield(kind) => { - match kind { - YieldKind::Postfix(expr) => { - try_visit!(vis.visit_expr(expr)); - } - YieldKind::Prefix(expr) => { - visit_opt!(vis, visit_expr, expr); - } - } - } - ExprKind::Try(subexpression) => try_visit!(vis.visit_expr(subexpression)), - ExprKind::TryBlock(body) => try_visit!(vis.visit_block(body)), - ExprKind::Lit(_token) => {} - ExprKind::IncludedBytes(_bytes) => {} - ExprKind::UnsafeBinderCast(_kind, expr, ty) => { - try_visit!(vis.visit_expr(expr)); - visit_opt!(vis, visit_ty, ty); - } + ExprKind::Path(maybe_qself, path) => + visit_visitable!($($mut)? vis, maybe_qself, path), + ExprKind::Break(opt_label, opt_expr) => + visit_visitable!($($mut)? vis, opt_label, opt_expr), + ExprKind::Continue(opt_label) => + visit_visitable!($($mut)? vis, opt_label), + ExprKind::Ret(optional_expression) | ExprKind::Yeet(optional_expression) => + visit_visitable!($($mut)? vis, optional_expression), + ExprKind::Become(expr) => + visit_visitable!($($mut)? vis, expr), + ExprKind::MacCall(mac) => + visit_visitable!($($mut)? vis, mac), + ExprKind::Paren(subexpression) => + visit_visitable!($($mut)? vis, subexpression), + ExprKind::InlineAsm(asm) => + visit_visitable!($($mut)? vis, asm), + ExprKind::FormatArgs(f) => + visit_visitable!($($mut)? vis, f), + ExprKind::OffsetOf(container, fields) => + visit_visitable!($($mut)? vis, container, fields), + ExprKind::Yield(kind) => + visit_visitable!($($mut)? vis, kind), + ExprKind::Try(subexpression) => + visit_visitable!($($mut)? vis, subexpression), + ExprKind::TryBlock(body) => + visit_visitable!($($mut)? vis, body), + ExprKind::Lit(token) => + visit_visitable!($($mut)? vis, token), + ExprKind::IncludedBytes(bytes) => + visit_visitable!($($mut)? vis, bytes), + ExprKind::UnsafeBinderCast(kind, expr, ty) => + visit_visitable!($($mut)? vis, kind, expr, ty), ExprKind::Err(_guar) => {} ExprKind::Dummy => {} } visit_span(vis, span) - } + }); - pub fn walk_param<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, param: &$($lt)? $($mut)? Param) -> V::Result { - let Param { attrs, ty, pat, id, span, is_placeholder: _ } = param; - try_visit!(visit_id(vis, id)); - walk_list!(vis, visit_attribute, attrs); - try_visit!(vis.visit_pat(pat)); - try_visit!(vis.visit_ty(ty)); - visit_span(vis, span) - } - - pub fn walk_arm<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, arm: &$($lt)? $($mut)? Arm) -> V::Result { - let Arm { attrs, pat, guard, body, span, id, is_placeholder: _ } = arm; - try_visit!(visit_id(vis, id)); - walk_list!(vis, visit_attribute, attrs); - try_visit!(vis.visit_pat(pat)); - visit_opt!(vis, visit_expr, guard); - visit_opt!(vis, visit_expr, body); - visit_span(vis, span) - } - - pub fn walk_vis<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, visibility: &$($lt)? $($mut)? Visibility) -> V::Result { - let Visibility { kind, span, tokens: _ } = visibility; - match kind { - VisibilityKind::Restricted { path, id, shorthand: _ } => { - try_visit!(visit_id(vis, id)); - try_visit!(vis.visit_path(path)); - } - VisibilityKind::Public | VisibilityKind::Inherited => {} - } - visit_span(vis, span) - } - - pub fn walk_attribute<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, attr: &$($lt)? $($mut)? Attribute) -> V::Result { - let Attribute { kind, id: _, style: _, span } = attr; - match kind { - AttrKind::Normal(normal) => { - let NormalAttr { item, tokens: _ } = &$($mut)?**normal; - let AttrItem { unsafety: _, path, args, tokens: _ } = item; - try_visit!(vis.visit_path(path)); - try_visit!(walk_attr_args(vis, args)); - } - AttrKind::DocComment(_kind, _sym) => {} - } - visit_span(vis, span) - } - - pub fn walk_attr_args<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, args: &$($lt)? $($mut)? AttrArgs) -> V::Result { - match args { - AttrArgs::Empty => {} - AttrArgs::Delimited(args) => try_visit!(visit_delim_args(vis, args)), - AttrArgs::Eq { eq_span, expr } => { - try_visit!(vis.visit_expr(expr)); - try_visit!(visit_span(vis, eq_span)); - } - } - V::Result::output() - } + define_named_walk!($(($mut))? $Visitor$(<$lt>)? + pub fn walk_anon_const(AnonConst); + pub fn walk_arm(Arm); + //pub fn walk_assoc_item(AssocItem, _ctxt: AssocCtxt); + pub fn walk_assoc_item_constraint(AssocItemConstraint); + pub fn walk_attribute(Attribute); + pub fn walk_block(Block); + //pub fn walk_nested_use_tree((UseTree, NodeId)); + pub fn walk_capture_by(CaptureBy); + pub fn walk_closure_binder(ClosureBinder); + pub fn walk_contract(FnContract); + pub fn walk_coroutine_kind(CoroutineKind); + pub fn walk_crate(Crate); + pub fn walk_expr(Expr); + pub fn walk_expr_field(ExprField); + pub fn walk_field_def(FieldDef); + pub fn walk_fn_decl(FnDecl); + pub fn walk_fn_header(FnHeader); + pub fn walk_fn_ret_ty(FnRetTy); + //pub fn walk_foreign_item(ForeignItem); + pub fn walk_foreign_mod(ForeignMod); + pub fn walk_format_args(FormatArgs); + pub fn walk_generic_arg(GenericArg); + pub fn walk_generic_args(GenericArgs); + pub fn walk_generic_param(GenericParam); + pub fn walk_generics(Generics); + pub fn walk_inline_asm(InlineAsm); + pub fn walk_inline_asm_sym(InlineAsmSym); + //pub fn walk_item(Item); + pub fn walk_label(Label); + pub fn walk_lifetime(Lifetime); + pub fn walk_local(Local); + pub fn walk_mac(MacCall); + pub fn walk_macro_def(MacroDef); + pub fn walk_param_bound(GenericBound); + pub fn walk_param(Param); + pub fn walk_pat_field(PatField); + pub fn walk_path(Path); + pub fn walk_path_segment(PathSegment); + pub fn walk_pat(Pat); + pub fn walk_poly_trait_ref(PolyTraitRef); + pub fn walk_precise_capturing_arg(PreciseCapturingArg); + pub fn walk_qself(QSelf); + pub fn walk_trait_ref(TraitRef); + pub fn walk_ty_pat(TyPat); + pub fn walk_ty(Ty); + pub fn walk_use_tree(UseTree); + pub fn walk_variant_data(VariantData); + pub fn walk_variant(Variant); + pub fn walk_vis(Visibility); + pub fn walk_where_predicate_kind(WherePredicateKind); + pub fn walk_where_predicate(WherePredicate); + ); }; } @@ -1906,6 +1115,20 @@ common_visitor_and_walkers!(Visitor<'a>); macro_rules! generate_list_visit_fns { ($($name:ident, $Ty:ty, $visit_fn:ident$(, $param:ident: $ParamTy:ty)*;)+) => { $( + #[allow(unused_parens)] + impl<'a, V: Visitor<'a>> Visitable<'a, V> for ThinVec<$Ty> { + type Extra = ($($ParamTy),*); + + #[inline] + fn visit( + &'a self, + visitor: &mut V, + ($($param),*): Self::Extra, + ) -> V::Result { + $name(visitor, self $(, $param)*) + } + } + fn $name<'a, V: Visitor<'a>>( vis: &mut V, values: &'a ThinVec<$Ty>, @@ -1936,18 +1159,9 @@ generate_list_visit_fns! { visit_arms, Arm, visit_arm; } -#[expect(rustc::pass_by_value)] // needed for symmetry with mut_visit -fn visit_nested_use_tree<'a, V: Visitor<'a>>( - vis: &mut V, - nested_tree: &'a UseTree, - &nested_id: &NodeId, -) -> V::Result { - vis.visit_nested_use_tree(nested_tree, nested_id) -} - pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V::Result { let Stmt { id, kind, span: _ } = statement; - try_visit!(visit_id(visitor, id)); + try_visit!(visitor.visit_id(*id)); match kind { StmtKind::Let(local) => try_visit!(visitor.visit_local(local)), StmtKind::Item(item) => try_visit!(visitor.visit_item(item)), diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl index c6472fd45fa9..370b15d2871a 100644 --- a/compiler/rustc_ast_lowering/messages.ftl +++ b/compiler/rustc_ast_lowering/messages.ftl @@ -127,9 +127,6 @@ ast_lowering_misplaced_impl_trait = `impl Trait` is not allowed in {$position} .note = `impl Trait` is only allowed in arguments and return types of functions and methods -ast_lowering_misplaced_relax_trait_bound = - `?Trait` bounds are only permitted at the point where a type parameter is declared - ast_lowering_never_pattern_with_body = a never pattern is always unreachable .label = this will never be executed diff --git a/compiler/rustc_ast_lowering/src/delegation.rs b/compiler/rustc_ast_lowering/src/delegation.rs index 42d25b512f5c..9bfcd232221b 100644 --- a/compiler/rustc_ast_lowering/src/delegation.rs +++ b/compiler/rustc_ast_lowering/src/delegation.rs @@ -47,6 +47,7 @@ use rustc_errors::ErrorGuaranteed; use rustc_hir::def_id::DefId; use rustc_middle::span_bug; use rustc_middle::ty::{Asyncness, ResolverAstLowering}; +use rustc_span::symbol::kw; use rustc_span::{Ident, Span, Symbol}; use {rustc_ast as ast, rustc_hir as hir}; @@ -61,21 +62,6 @@ pub(crate) struct DelegationResults<'hir> { } impl<'hir> LoweringContext<'_, 'hir> { - /// Defines whether the delegatee is an associated function whose first parameter is `self`. - pub(crate) fn delegatee_is_method( - &self, - item_id: NodeId, - path_id: NodeId, - span: Span, - is_in_trait_impl: bool, - ) -> bool { - let sig_id = self.get_delegation_sig_id(item_id, path_id, span, is_in_trait_impl); - let Ok(sig_id) = sig_id else { - return false; - }; - self.is_method(sig_id, span) - } - fn is_method(&self, def_id: DefId, span: Span) -> bool { match self.tcx.def_kind(def_id) { DefKind::Fn => false, @@ -101,10 +87,11 @@ impl<'hir> LoweringContext<'_, 'hir> { let sig_id = self.get_delegation_sig_id(item_id, delegation.id, span, is_in_trait_impl); match sig_id { Ok(sig_id) => { + let is_method = self.is_method(sig_id, span); let (param_count, c_variadic) = self.param_count(sig_id); let decl = self.lower_delegation_decl(sig_id, param_count, c_variadic, span); let sig = self.lower_delegation_sig(sig_id, decl, span); - let body_id = self.lower_delegation_body(delegation, param_count, span); + let body_id = self.lower_delegation_body(delegation, is_method, param_count, span); let ident = self.lower_ident(delegation.ident); let generics = self.lower_delegation_generics(span); DelegationResults { body_id, sig, ident, generics } @@ -234,10 +221,21 @@ impl<'hir> LoweringContext<'_, 'hir> { hir::FnSig { decl, header, span } } - fn generate_param(&mut self, idx: usize, span: Span) -> (hir::Param<'hir>, NodeId) { + fn generate_param( + &mut self, + is_method: bool, + idx: usize, + span: Span, + ) -> (hir::Param<'hir>, NodeId) { let pat_node_id = self.next_node_id(); let pat_id = self.lower_node_id(pat_node_id); - let ident = Ident::with_dummy_span(Symbol::intern(&format!("arg{idx}"))); + // FIXME(cjgillot) AssocItem currently relies on self parameter being exactly named `self`. + let name = if is_method && idx == 0 { + kw::SelfLower + } else { + Symbol::intern(&format!("arg{idx}")) + }; + let ident = Ident::with_dummy_span(name); let pat = self.arena.alloc(hir::Pat { hir_id: pat_id, kind: hir::PatKind::Binding(hir::BindingMode::NONE, pat_id, ident, None), @@ -248,9 +246,21 @@ impl<'hir> LoweringContext<'_, 'hir> { (hir::Param { hir_id: self.next_id(), pat, ty_span: span, span }, pat_node_id) } - fn generate_arg(&mut self, idx: usize, param_id: HirId, span: Span) -> hir::Expr<'hir> { + fn generate_arg( + &mut self, + is_method: bool, + idx: usize, + param_id: HirId, + span: Span, + ) -> hir::Expr<'hir> { + // FIXME(cjgillot) AssocItem currently relies on self parameter being exactly named `self`. + let name = if is_method && idx == 0 { + kw::SelfLower + } else { + Symbol::intern(&format!("arg{idx}")) + }; let segments = self.arena.alloc_from_iter(iter::once(hir::PathSegment { - ident: Ident::with_dummy_span(Symbol::intern(&format!("arg{idx}"))), + ident: Ident::with_dummy_span(name), hir_id: self.next_id(), res: Res::Local(param_id), args: None, @@ -264,6 +274,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_delegation_body( &mut self, delegation: &Delegation, + is_method: bool, param_count: usize, span: Span, ) -> BodyId { @@ -274,7 +285,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let mut args: Vec> = Vec::with_capacity(param_count); for idx in 0..param_count { - let (param, pat_node_id) = this.generate_param(idx, span); + let (param, pat_node_id) = this.generate_param(is_method, idx, span); parameters.push(param); let arg = if let Some(block) = block @@ -290,7 +301,7 @@ impl<'hir> LoweringContext<'_, 'hir> { this.ident_and_label_to_local_id.insert(pat_node_id, param.pat.hir_id.local_id); this.lower_target_expr(&block) } else { - this.generate_arg(idx, param.pat.hir_id, span) + this.generate_arg(is_method, idx, param.pat.hir_id, span) }; args.push(arg); } diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index b444324ef914..83f3a976e83f 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -324,13 +324,6 @@ pub(crate) struct MisplacedDoubleDot { pub span: Span, } -#[derive(Diagnostic)] -#[diag(ast_lowering_misplaced_relax_trait_bound)] -pub(crate) struct MisplacedRelaxTraitBound { - #[primary_span] - pub span: Span, -} - #[derive(Diagnostic)] #[diag(ast_lowering_match_arm_with_no_body)] pub(crate) struct MatchArmWithNoBody { diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 8747e624a4a9..15e736261d58 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -528,7 +528,7 @@ impl<'hir> LoweringContext<'_, 'hir> { then: &Block, else_opt: Option<&Expr>, ) -> hir::ExprKind<'hir> { - let lowered_cond = self.lower_cond(cond); + let lowered_cond = self.lower_expr(cond); let then_expr = self.lower_block_expr(then); if let Some(rslt) = else_opt { hir::ExprKind::If( @@ -541,44 +541,6 @@ impl<'hir> LoweringContext<'_, 'hir> { } } - // Lowers a condition (i.e. `cond` in `if cond` or `while cond`), wrapping it in a terminating scope - // so that temporaries created in the condition don't live beyond it. - fn lower_cond(&mut self, cond: &Expr) -> &'hir hir::Expr<'hir> { - fn has_let_expr(expr: &Expr) -> bool { - match &expr.kind { - ExprKind::Binary(_, lhs, rhs) => has_let_expr(lhs) || has_let_expr(rhs), - ExprKind::Let(..) => true, - _ => false, - } - } - - // We have to take special care for `let` exprs in the condition, e.g. in - // `if let pat = val` or `if foo && let pat = val`, as we _do_ want `val` to live beyond the - // condition in this case. - // - // In order to maintain the drop behavior for the non `let` parts of the condition, - // we still wrap them in terminating scopes, e.g. `if foo && let pat = val` essentially - // gets transformed into `if { let _t = foo; _t } && let pat = val` - match &cond.kind { - ExprKind::Binary(op @ Spanned { node: ast::BinOpKind::And, .. }, lhs, rhs) - if has_let_expr(cond) => - { - let op = self.lower_binop(*op); - let lhs = self.lower_cond(lhs); - let rhs = self.lower_cond(rhs); - - self.arena.alloc(self.expr(cond.span, hir::ExprKind::Binary(op, lhs, rhs))) - } - ExprKind::Let(..) => self.lower_expr(cond), - _ => { - let cond = self.lower_expr(cond); - let reason = DesugaringKind::CondTemporary; - let span_block = self.mark_span_with_reason(reason, cond.span, None); - self.expr_drop_temps(span_block, cond) - } - } - } - // We desugar: `'label: while $cond $body` into: // // ``` @@ -602,7 +564,7 @@ impl<'hir> LoweringContext<'_, 'hir> { body: &Block, opt_label: Option