diff options
1681 files changed, 33010 insertions, 14835 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f436c236dc9..767ea29d636 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: - name: mingw-check-tidy os: ubuntu-20.04-4core-16gb env: {} - - name: x86_64-gnu-llvm-16 + - name: x86_64-gnu-llvm-17 env: ENABLE_GCC_CODEGEN: "1" os: ubuntu-20.04-16core-64gb @@ -323,10 +323,6 @@ jobs: env: RUST_BACKTRACE: 1 os: ubuntu-20.04-8core-32gb - - name: x86_64-gnu-llvm-16 - env: - RUST_BACKTRACE: 1 - os: ubuntu-20.04-8core-32gb - name: x86_64-gnu-nopt os: ubuntu-20.04-4core-16gb env: {} diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml index 97ed891c491..c182f3245e5 100644 --- a/.github/workflows/dependencies.yml +++ b/.github/workflows/dependencies.yml @@ -6,6 +6,8 @@ on: schedule: # Run weekly - cron: '0 0 * * Sun' + # Re-bump deps every 4 hours + - cron: '0 */4 * * *' workflow_dispatch: # Needed so we can run it manually permissions: @@ -135,8 +137,8 @@ jobs: gh pr edit cargo_update --title "${PR_TITLE}" --body-file body.md --repo $GITHUB_REPOSITORY - name: open new pull request - # Only run if there wasn't an existing PR - if: steps.edit.outcome != 'success' + # Only run if there wasn't an existing PR and if this is the weekly run + if: steps.edit.outcome != 'success' && github.event.schedule == '0 0 * * Sun' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: gh pr create --title "${PR_TITLE}" --body-file body.md --repo $GITHUB_REPOSITORY diff --git a/Cargo.lock b/Cargo.lock index 29ebd2b3979..b8fe1ebaf80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,9 +37,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b79b82693f705137f8fb9b37871d99e4f9a7df12b917eed79c3d3954830a60b" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "once_cell", @@ -201,9 +201,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" dependencies = [ "backtrace", ] @@ -246,7 +246,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -293,9 +293,9 @@ checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "basic-toml" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2db21524cad41c5591204d22d75e1970a2d1f71060214ca931dc7d5afe2c14e5" +checksum = "823388e228f614e9558c6804262db37960ec8821856535f5c3f59913140558f8" dependencies = [ "serde", ] @@ -379,9 +379,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.15.3" +version = "3.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b" +checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" [[package]] name = "bytecount" @@ -484,10 +484,16 @@ dependencies = [ ] [[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + +[[package]] name = "chrono" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", @@ -508,9 +514,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.1" +version = "4.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" +checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813" dependencies = [ "clap_builder", "clap_derive", @@ -528,9 +534,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.1" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstream", "anstyle", @@ -550,14 +556,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.0" +version = "4.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" +checksum = "90239a040c80f5e14809ca132ddc4176ab33d5e17e49691793296e3fcb34d72f" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -568,7 +574,7 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "clippy" -version = "0.1.78" +version = "0.1.79" dependencies = [ "anstream", "clippy_config", @@ -584,7 +590,7 @@ dependencies = [ "regex", "rustc_tools_util", "serde", - "syn 2.0.52", + "syn 2.0.53", "tempfile", "termize", "tester", @@ -596,7 +602,7 @@ dependencies = [ [[package]] name = "clippy_config" -version = "0.1.78" +version = "0.1.79" dependencies = [ "rustc-semver", "serde", @@ -619,7 +625,7 @@ dependencies = [ [[package]] name = "clippy_lints" -version = "0.1.78" +version = "0.1.79" dependencies = [ "arrayvec", "cargo_metadata 0.18.1", @@ -644,7 +650,7 @@ dependencies = [ [[package]] name = "clippy_utils" -version = "0.1.78" +version = "0.1.79" dependencies = [ "arrayvec", "clippy_config", @@ -664,9 +670,9 @@ dependencies = [ [[package]] name = "color-eyre" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" +checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" dependencies = [ "backtrace", "color-spantrace", @@ -884,9 +890,9 @@ dependencies = [ [[package]] name = "ctrlc" -version = "3.4.2" +version = "3.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b467862cc8610ca6fc9a1532d7777cee0804e678ab45410897b9396495994a0b" +checksum = "672465ae37dc1bc6380a6547a8883d5dd397b0f1faaad4f265726cc7042a5345" dependencies = [ "nix", "windows-sys 0.52.0", @@ -943,7 +949,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -954,7 +960,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -965,11 +971,11 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69" [[package]] name = "declare_clippy_lint" -version = "0.1.78" +version = "0.1.79" dependencies = [ "itertools 0.12.1", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1010,7 +1016,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1020,7 +1026,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b" dependencies = [ "derive_builder_core", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1043,7 +1049,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1132,7 +1138,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1217,9 +1223,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c012a26a7f605efc424dd53697843a72be7dc86ad2d01f7814337794a12231d" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" dependencies = [ "anstream", "anstyle", @@ -1478,7 +1484,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -1603,9 +1609,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" +checksum = "4fbd2820c5e49886948654ab546d0688ff24530286bdcf8fca3cefb16d4618eb" dependencies = [ "bytes", "fnv", @@ -1654,6 +1660,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] name = "hermit-abi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1712,9 +1724,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" dependencies = [ "bytes", "fnv", @@ -1910,7 +1922,7 @@ checksum = "d2abdd3a62551e8337af119c5899e600ca0c88ec8f23a46c60ba216c803dcf1a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -2090,9 +2102,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -2188,12 +2200,12 @@ dependencies = [ [[package]] name = "libloading" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2caa5afb8bf9f3a2652760ce7d4f62d21c4d5a423e68466fca30df82f2330164" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.52.4", + "windows-targets 0.48.5", ] [[package]] @@ -2524,18 +2536,19 @@ dependencies = [ [[package]] name = "new_debug_unreachable" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" [[package]] name = "nix" -version = "0.27.1" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" +checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ "bitflags 2.4.2", "cfg-if", + "cfg_aliases", "libc", ] @@ -2687,7 +2700,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -2880,7 +2893,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -3003,9 +3016,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -3272,9 +3285,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.24" +version = "0.11.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" +checksum = "78bf93c4af7a8bb7d879d51cebe797356ff10ae8516ace542b5182d9dcac10b2" dependencies = [ "base64", "bytes", @@ -3916,7 +3929,7 @@ dependencies = [ "fluent-syntax", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "unic-langid", ] @@ -4051,7 +4064,7 @@ version = "0.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "synstructure", ] @@ -4197,7 +4210,7 @@ version = "0.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "synstructure", ] @@ -4236,6 +4249,7 @@ name = "rustc_middle" version = "0.0.0" dependencies = [ "bitflags 2.4.2", + "derivative", "either", "field-offset", "gsgdt", @@ -4413,6 +4427,7 @@ dependencies = [ "rustc_lexer", "rustc_macros", "rustc_middle", + "rustc_privacy", "rustc_session", "rustc_span", "rustc_target", @@ -4439,6 +4454,8 @@ dependencies = [ "rustc_target", "smallvec", "tracing", + "tracing-subscriber", + "tracing-tree", ] [[package]] @@ -4821,7 +4838,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5004,7 +5021,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5282,7 +5299,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -5311,9 +5328,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.52" +version = "2.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032" dependencies = [ "proc-macro2", "quote", @@ -5334,14 +5351,14 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] name = "sysinfo" -version = "0.30.6" +version = "0.30.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6746919caf9f2a85bff759535664c060109f21975c5ac2e8652e60102bd4d196" +checksum = "0c385888ef380a852a16209afc8cfad22795dd8873d69c9a14d2e2088f118d18" dependencies = [ "cfg-if", "core-foundation-sys", @@ -5498,22 +5515,22 @@ checksum = "a38c90d48152c236a3ab59271da4f4ae63d678c5d7ad6b7714d7cb9760be5e4b" [[package]] name = "thiserror" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5632,7 +5649,6 @@ dependencies = [ "bytes", "libc", "mio", - "num_cpus", "pin-project-lite", "socket2", "windows-sys 0.48.0", @@ -5737,7 +5753,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -5954,7 +5970,7 @@ checksum = "fea2a4c80deb4fb3ca51f66b5e2dd91e3642bbce52234bcf22e41668281208e4" dependencies = [ "proc-macro-hack", "quote", - "syn 2.0.52", + "syn 2.0.53", "unic-langid-impl", ] @@ -6167,9 +6183,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -6177,24 +6193,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.41" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" dependencies = [ "cfg-if", "js-sys", @@ -6204,9 +6220,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -6214,22 +6230,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm-encoder" @@ -6252,9 +6268,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", @@ -6303,13 +6319,15 @@ dependencies = [ [[package]] name = "windows-bindgen" -version = "0.52.0" +version = "0.55.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "970efb0b6849eb8a87a898f586af7cc167567b070014c7434514c0bde0ca341c" +checksum = "073ff8a486ebad239d557809d2cd5fe5e04ee1de29e09c6cd83fb0bae19b8a4c" dependencies = [ "proc-macro2", "rayon", - "syn 2.0.52", + "serde", + "serde_json", + "syn 2.0.53", "windows-metadata", ] @@ -6324,9 +6342,9 @@ dependencies = [ [[package]] name = "windows-metadata" -version = "0.52.0" +version = "0.55.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "218fd59201e26acdbb894fa2b302d1de84bf3eec7d0eb894ac8e9c5a854ee4ef" +checksum = "b602635050172a1fc57a35040d4d225baefc6098fefd97094919921d95961a7d" [[package]] name = "windows-sys" @@ -6563,7 +6581,7 @@ checksum = "9e6936f0cce458098a201c245a11bef556c6a0181129c7034d10d76d1ec3a2b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "synstructure", ] @@ -6584,7 +6602,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -6604,7 +6622,7 @@ checksum = "e6a647510471d372f2e6c2e6b7219e44d8c574d24fdc11c610a61455782f18c3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "synstructure", ] @@ -6627,7 +6645,7 @@ checksum = "7b4e5997cbf58990550ef1f0e5124a05e47e1ebd33a84af25739be6031a62c20" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] diff --git a/INSTALL.md b/INSTALL.md index 03e7a3431a5..a23ea4f1eee 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -154,11 +154,11 @@ toolchain. however this is not recommended as it's excrutiatingly slow, and not frequently tested for compatability. -2. Start a MINGW64 or MINGW32 shell (depending on whether you want 32-bit +3. Start a MINGW64 or MINGW32 shell (depending on whether you want 32-bit or 64-bit Rust) either from your start menu, or by running `mingw64.exe` or `mingw32.exe` from your MSYS2 installation directory (e.g. `C:\msys64`). -3. From this terminal, install the required tools: +4. From this terminal, install the required tools: ```sh # Update package mirrors (may be needed if you have a fresh install of MSYS2) @@ -178,7 +178,7 @@ toolchain. mingw-w64-x86_64-ninja ``` -4. Navigate to Rust's source code (or clone it), then build it: +5. Navigate to Rust's source code (or clone it), then build it: ```sh python x.py setup dist && python x.py build && python x.py install diff --git a/RELEASES.md b/RELEASES.md index 20e317a4d23..922afdd3e18 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,120 @@ +Version 1.77.0 (2024-03-21) +========================== + +<a id="1.77.0-Language"></a> + +Language +-------- + +- [Reveal opaque types within the defining body for exhaustiveness checking.](https://github.com/rust-lang/rust/pull/116821/) +- [Stabilize C-string literals.](https://github.com/rust-lang/rust/pull/117472/) +- [Stabilize THIR unsafeck.](https://github.com/rust-lang/rust/pull/117673/) +- [Add lint `static_mut_refs` to warn on references to mutable statics.](https://github.com/rust-lang/rust/pull/117556/) +- [Support async recursive calls (as long as they have indirection).](https://github.com/rust-lang/rust/pull/117703/) +- [Undeprecate lint `unstable_features` and make use of it in the compiler.](https://github.com/rust-lang/rust/pull/118639/) +- [Make inductive cycles in coherence ambiguous always.](https://github.com/rust-lang/rust/pull/118649/) +- [Get rid of type-driven traversal in const-eval interning](https://github.com/rust-lang/rust/pull/119044/), + only as a [future compatiblity lint](https://github.com/rust-lang/rust/pull/122204) for now. +- [Deny braced macro invocations in let-else.](https://github.com/rust-lang/rust/pull/119062/) + +<a id="1.77.0-Compiler"></a> + +Compiler +-------- + +- [Include lint `soft_unstable` in future breakage reports.](https://github.com/rust-lang/rust/pull/116274/) +- [Make `i128` and `u128` 16-byte aligned on x86-based targets.](https://github.com/rust-lang/rust/pull/116672/) +- [Use `--verbose` in diagnostic output.](https://github.com/rust-lang/rust/pull/119129/) +- [Improve spacing between printed tokens.](https://github.com/rust-lang/rust/pull/120227/) +- [Merge the `unused_tuple_struct_fields` lint into `dead_code`.](https://github.com/rust-lang/rust/pull/118297/) +- [Error on incorrect implied bounds in well-formedness check](https://github.com/rust-lang/rust/pull/118553/), + with a temporary exception for Bevy. +- [Fix coverage instrumentation/reports for non-ASCII source code.](https://github.com/rust-lang/rust/pull/119033/) +- [Fix `fn`/`const` items implied bounds and well-formedness check.](https://github.com/rust-lang/rust/pull/120019/) +- [Promote `riscv32{im|imafc}-unknown-none-elf` targets to tier 2.](https://github.com/rust-lang/rust/pull/118704/) +- Add several new tier 3 targets: + - [`aarch64-unknown-illumos`](https://github.com/rust-lang/rust/pull/112936/) + - [`hexagon-unknown-none-elf`](https://github.com/rust-lang/rust/pull/117601/) + - [`riscv32imafc-esp-espidf`](https://github.com/rust-lang/rust/pull/119738/) + - [`riscv32im-risc0-zkvm-elf`](https://github.com/rust-lang/rust/pull/117958/) + +Refer to Rust's [platform support page][platform-support-doc] +for more information on Rust's tiered platform support. + +<a id="1.77.0-Libraries"></a> + +Libraries +--------- + +- [Implement `From<&[T; N]>` for `Cow<[T]>`.](https://github.com/rust-lang/rust/pull/113489/) +- [Remove special-case handling of `vec.split_off(0)`.](https://github.com/rust-lang/rust/pull/119917/) + +<a id="1.77.0-Stabilized-APIs"></a> + +Stabilized APIs +--------------- + +- [`array::each_ref`](https://doc.rust-lang.org/stable/std/primitive.array.html#method.each_ref) +- [`array::each_mut`](https://doc.rust-lang.org/stable/std/primitive.array.html#method.each_mut) +- [`core::net`](https://doc.rust-lang.org/stable/core/net/index.html) +- [`f32::round_ties_even`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.round_ties_even) +- [`f64::round_ties_even`](https://doc.rust-lang.org/stable/std/primitive.f64.html#method.round_ties_even) +- [`mem::offset_of!`](https://doc.rust-lang.org/stable/std/mem/macro.offset_of.html) +- [`slice::first_chunk`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.first_chunk) +- [`slice::first_chunk_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.first_chunk_mut) +- [`slice::split_first_chunk`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_first_chunk) +- [`slice::split_first_chunk_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_first_chunk_mut) +- [`slice::last_chunk`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.last_chunk) +- [`slice::last_chunk_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.last_chunk_mut) +- [`slice::split_last_chunk`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_last_chunk) +- [`slice::split_last_chunk_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_last_chunk_mut) +- [`slice::chunk_by`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.chunk_by) +- [`slice::chunk_by_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.chunk_by_mut) +- [`Bound::map`](https://doc.rust-lang.org/stable/std/ops/enum.Bound.html#method.map) +- [`File::create_new`](https://doc.rust-lang.org/stable/std/fs/struct.File.html#method.create_new) +- [`Mutex::clear_poison`](https://doc.rust-lang.org/stable/std/sync/struct.Mutex.html#method.clear_poison) +- [`RwLock::clear_poison`](https://doc.rust-lang.org/stable/std/sync/struct.RwLock.html#method.clear_poison) + +<a id="1.77.0-Cargo"></a> + +Cargo +----- + +- [Extend the build directive syntax with `cargo::`.](https://github.com/rust-lang/cargo/pull/12201/) +- [Stabilize metadata `id` format as `PackageIDSpec`.](https://github.com/rust-lang/cargo/pull/12914/) +- [Pull out `cargo-util-schemas` as a crate.](https://github.com/rust-lang/cargo/pull/13178/) +- [Strip all debuginfo when debuginfo is not requested.](https://github.com/rust-lang/cargo/pull/13257/) +- [Inherit jobserver from env for all kinds of runners.](https://github.com/rust-lang/cargo/pull/12776/) +- [Deprecate rustc plugin support in cargo.](https://github.com/rust-lang/cargo/pull/13248/) + +<a id="1.77.0-Rustdoc"></a> + +Rustdoc +----- + +- [Allows links in markdown headings.](https://github.com/rust-lang/rust/pull/117662/) +- [Search for tuples and unit by type with `()`.](https://github.com/rust-lang/rust/pull/118194/) +- [Clean up the source sidebar's hide button.](https://github.com/rust-lang/rust/pull/119066/) +- [Prevent JS injection from `localStorage`.](https://github.com/rust-lang/rust/pull/120250/) + +<a id="1.77.0-Misc"></a> + +Misc +---- + +- [Recommend version-sorting for all sorting in style guide.](https://github.com/rust-lang/rust/pull/115046/) + +<a id="1.77.0-Internal-Changes"></a> + +Internal Changes +---------------- + +These changes do not affect any public interfaces of Rust, but they represent +significant improvements to the performance or internals of rustc and related +tools. + +- [Add more weirdness to `weird-exprs.rs`.](https://github.com/rust-lang/rust/pull/119028/) + Version 1.76.0 (2024-02-08) ========================== diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index d0e8b86b71d..915cb386075 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -303,10 +303,6 @@ impl TraitBoundModifiers { }; } -/// The AST represents all type param bounds as types. -/// `typeck::collect::compute_bounds` matches these against -/// the "special" built-in traits (see `middle::lang_items`) and -/// detects `Copy`, `Send` and `Sync`. #[derive(Clone, Encodable, Decodable, Debug)] pub enum GenericBound { Trait(PolyTraitRef, TraitBoundModifiers), @@ -621,7 +617,9 @@ impl Pat { | PatKind::Or(s) => s.iter().for_each(|p| p.walk(it)), // Trivial wrappers over inner patterns. - PatKind::Box(s) | PatKind::Ref(s, _) | PatKind::Paren(s) => s.walk(it), + PatKind::Box(s) | PatKind::Deref(s) | PatKind::Ref(s, _) | PatKind::Paren(s) => { + s.walk(it) + } // These patterns do not contain subpatterns, skip. PatKind::Wild @@ -792,6 +790,9 @@ pub enum PatKind { /// A `box` pattern. Box(P<Pat>), + /// A `deref` pattern (currently `deref!()` macro-based syntax). + Deref(P<Pat>), + /// A reference pattern (e.g., `&mut (a, b)`). Ref(P<Pat>, Mutability), @@ -1436,7 +1437,7 @@ pub enum ExprKind { /// `'label: loop { block }` Loop(P<Block>, Option<Label>, Span), /// A `match` block. - Match(P<Expr>, ThinVec<Arm>), + Match(P<Expr>, ThinVec<Arm>, MatchKind), /// A closure (e.g., `move |a, b, c| a + b + c`). Closure(Box<Closure>), /// A block (`'label: { ... }`). @@ -1761,6 +1762,15 @@ pub enum StrStyle { Raw(u8), } +/// The kind of match expression +#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq)] +pub enum MatchKind { + /// match expr { ... } + Prefix, + /// expr.match { ... } + Postfix, +} + /// A literal in a meta item. #[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] pub struct MetaItemLit { diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 6e42cf37b86..4f21ff41529 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -11,12 +11,11 @@ #![doc(rust_logo)] #![allow(internal_features)] #![feature(rustdoc_internals)] -#![feature(associated_type_bounds)] +#![cfg_attr(bootstrap, feature(associated_type_bounds))] #![feature(associated_type_defaults)] #![feature(box_patterns)] #![feature(if_let_guard)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(min_specialization))] #![feature(never_type)] #![feature(negative_impls)] #![feature(stmt_expr_attributes)] diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 83468c5f101..7337b969242 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -1295,6 +1295,7 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) { fields.flat_map_in_place(|field| vis.flat_map_pat_field(field)); } PatKind::Box(inner) => vis.visit_pat(inner), + PatKind::Deref(inner) => vis.visit_pat(inner), PatKind::Ref(inner, _mutbl) => vis.visit_pat(inner), PatKind::Range(e1, e2, Spanned { span: _, node: _ }) => { visit_opt(e1, |e| vis.visit_expr(e)); @@ -1424,7 +1425,7 @@ pub fn noop_visit_expr<T: MutVisitor>( visit_opt(label, |label| vis.visit_label(label)); vis.visit_span(span); } - ExprKind::Match(expr, arms) => { + ExprKind::Match(expr, arms, _kind) => { vis.visit_expr(expr); arms.flat_map_in_place(|arm| vis.flat_map_arm(arm)); } diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 5ccc7d51066..f49eb2f22c5 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -11,6 +11,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::Lrc; use rustc_macros::HashStable_Generic; use rustc_span::symbol::{kw, sym}; +#[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint. #[allow(hidden_glob_reexports)] use rustc_span::symbol::{Ident, Symbol}; use rustc_span::{edition::Edition, ErrorGuaranteed, Span, DUMMY_SP}; @@ -104,7 +105,7 @@ impl Lit { } } - /// Keep this in sync with `Token::can_begin_literal_or_bool` excluding unary negation. + /// Keep this in sync with `Token::can_begin_literal_maybe_minus` excluding unary negation. pub fn from_token(token: &Token) -> Option<Lit> { match token.uninterpolate().kind { Ident(name, IdentIsRaw::No) if name.is_bool_lit() => Some(Lit::new(Bool, name, None)), @@ -663,7 +664,7 @@ impl Token { } /// Returns `true` if the token is an interpolated path. - fn is_path(&self) -> bool { + fn is_whole_path(&self) -> bool { if let Interpolated(nt) = &self.kind && let NtPath(..) = &nt.0 { @@ -709,7 +710,7 @@ impl Token { pub fn is_path_start(&self) -> bool { self == &ModSep || self.is_qpath_start() - || self.is_path() + || self.is_whole_path() || self.is_path_segment_keyword() || self.is_ident() && !self.is_reserved_ident() } diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index adc3056cc29..239735456ad 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -28,18 +28,7 @@ use smallvec::{smallvec, SmallVec}; use std::borrow::Cow; use std::{cmp, fmt, iter}; -/// When the main Rust parser encounters a syntax-extension invocation, it -/// parses the arguments to the invocation as a token tree. This is a very -/// loose structure, such that all sorts of different AST fragments can -/// be passed to syntax extensions using a uniform type. -/// -/// If the syntax extension is an MBE macro, it will attempt to match its -/// LHS token tree against the provided token tree, and if it finds a -/// match, will transcribe the RHS token tree, splicing in any captured -/// `macro_parser::matched_nonterminals` into the `SubstNt`s it finds. -/// -/// The RHS of an MBE macro is the only place `SubstNt`s are substituted. -/// Nothing special happens to misnamed or misplaced `SubstNt`s. +/// Part of a `TokenStream`. #[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)] pub enum TokenTree { /// A single token. Should never be `OpenDelim` or `CloseDelim`, because diff --git a/compiler/rustc_ast/src/util/literal.rs b/compiler/rustc_ast/src/util/literal.rs index 5ed2762b726..a17c7708e4a 100644 --- a/compiler/rustc_ast/src/util/literal.rs +++ b/compiler/rustc_ast/src/util/literal.rs @@ -276,8 +276,10 @@ fn filtered_float_lit( Some(suffix) => LitKind::Float( symbol, ast::LitFloatType::Suffixed(match suffix { + sym::f16 => ast::FloatTy::F16, sym::f32 => ast::FloatTy::F32, sym::f64 => ast::FloatTy::F64, + sym::f128 => ast::FloatTy::F128, _ => return Err(LitError::InvalidFloatSuffix(suffix)), }), ), diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index d75ff4565e6..18986fb7504 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -480,7 +480,7 @@ pub fn walk_use_tree<'a, V: Visitor<'a>>( try_visit!(visitor.visit_path(&use_tree.prefix, id)); match use_tree.kind { UseTreeKind::Simple(rename) => { - // The extra IDs are handled during HIR lowering. + // The extra IDs are handled during AST lowering. visit_opt!(visitor, visit_ident, rename); } UseTreeKind::Glob => {} @@ -576,7 +576,10 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Res try_visit!(visitor.visit_path(path, pattern.id)); walk_list!(visitor, visit_pat_field, fields); } - PatKind::Box(subpattern) | PatKind::Ref(subpattern, _) | PatKind::Paren(subpattern) => { + PatKind::Box(subpattern) + | PatKind::Deref(subpattern) + | PatKind::Ref(subpattern, _) + | PatKind::Paren(subpattern) => { try_visit!(visitor.visit_pat(subpattern)); } PatKind::Ident(_, ident, optional_subpattern) => { @@ -755,7 +758,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>( } AssocItemKind::Delegation(box Delegation { id, qself, path, body }) => { if let Some(qself) = qself { - visitor.visit_ty(&qself.ty); + try_visit!(visitor.visit_ty(&qself.ty)); } try_visit!(visitor.visit_path(path, *id)); visit_opt!(visitor, visit_block, body); @@ -920,7 +923,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V visit_opt!(visitor, visit_label, opt_label); try_visit!(visitor.visit_block(block)); } - ExprKind::Match(subexpression, arms) => { + ExprKind::Match(subexpression, arms, _kind) => { try_visit!(visitor.visit_expr(subexpression)); walk_list!(visitor, visit_arm, arms); } @@ -994,7 +997,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V ExprKind::InlineAsm(asm) => try_visit!(visitor.visit_inline_asm(asm)), ExprKind::FormatArgs(f) => try_visit!(visitor.visit_format_args(f)), ExprKind::OffsetOf(container, fields) => { - visitor.visit_ty(container); + try_visit!(visitor.visit_ty(container)); walk_list!(visitor, visit_ident, fields.iter().copied()); } ExprKind::Yield(optional_expression) => { diff --git a/compiler/rustc_ast_lowering/src/delegation.rs b/compiler/rustc_ast_lowering/src/delegation.rs index 4e1c477a3d7..e26a65c1f29 100644 --- a/compiler/rustc_ast_lowering/src/delegation.rs +++ b/compiler/rustc_ast_lowering/src/delegation.rs @@ -29,11 +29,12 @@ //! item id (`item_id`) in case of impl trait or path resolution id (`path_id`) otherwise. //! //! Since we do not have a proper way to obtain function type information by path resolution -//! in AST, we mark each function parameter type as `InferDelegation` and inherit it in `AstConv`. +//! in AST, we mark each function parameter type as `InferDelegation` and inherit it during +//! HIR ty lowering. //! //! Similarly generics, predicates and header are set to the "default" values. //! In case of discrepancy with callee function the `NotSupportedDelegation` error will -//! also be emitted in `AstConv`. +//! also be emitted during HIR ty lowering. use crate::{ImplTraitPosition, ResolverAstLoweringExt}; @@ -129,7 +130,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ) -> &'hir hir::FnDecl<'hir> { let args_count = if let Some(local_sig_id) = sig_id.as_local() { // Map may be filled incorrectly due to recursive delegation. - // Error will be emmited later in astconv. + // Error will be emitted later during HIR ty lowering. self.resolver.fn_parameter_counts.get(&local_sig_id).cloned().unwrap_or_default() } else { self.tcx.fn_arg_names(sig_id).len() diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 41f7418ddde..389cf4e3132 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -157,7 +157,7 @@ impl<'hir> LoweringContext<'_, 'hir> { hir::ExprKind::AddrOf(*k, *m, ohs) } ExprKind::Let(pat, scrutinee, span, is_recovered) => { - hir::ExprKind::Let(self.arena.alloc(hir::Let { + hir::ExprKind::Let(self.arena.alloc(hir::LetExpr { span: self.lower_span(*span), pat: self.lower_pat(pat), ty: None, @@ -181,10 +181,13 @@ impl<'hir> LoweringContext<'_, 'hir> { ) }), ExprKind::TryBlock(body) => self.lower_expr_try_block(body), - ExprKind::Match(expr, arms) => hir::ExprKind::Match( + ExprKind::Match(expr, arms, kind) => hir::ExprKind::Match( self.lower_expr(expr), self.arena.alloc_from_iter(arms.iter().map(|x| self.lower_arm(x))), - hir::MatchSource::Normal, + match kind { + MatchKind::Prefix => hir::MatchSource::Normal, + MatchKind::Postfix => hir::MatchSource::Postfix, + }, ), ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr), ExprKind::Closure(box Closure { diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index 3f84e6b100d..d2c3b8b2d56 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -604,8 +604,7 @@ fn may_contain_yield_point(e: &ast::Expr) -> bool { if let ast::ExprKind::Await(_, _) | ast::ExprKind::Yield(_) = e.kind { ControlFlow::Break(()) } else { - visit::walk_expr(self, e); - ControlFlow::Continue(()) + visit::walk_expr(self, e) } } diff --git a/compiler/rustc_ast_lowering/src/index.rs b/compiler/rustc_ast_lowering/src/index.rs index 793fe9cfd5e..9078b1f889c 100644 --- a/compiler/rustc_ast_lowering/src/index.rs +++ b/compiler/rustc_ast_lowering/src/index.rs @@ -55,7 +55,7 @@ pub(super) fn index_hir<'hir>( OwnerNode::TraitItem(item) => collector.visit_trait_item(item), OwnerNode::ImplItem(item) => collector.visit_impl_item(item), OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item), - OwnerNode::AssocOpaqueTy(..) => unreachable!(), + OwnerNode::Synthetic => unreachable!(), }; for (local_id, node) in collector.nodes.iter_enumerated() { diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 52300138186..c9786328565 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -373,6 +373,7 @@ impl<'hir> LoweringContext<'_, 'hir> { (trait_ref, lowered_ty) }); + self.is_in_trait_impl = trait_ref.is_some(); let new_impl_items = self .arena .alloc_from_iter(impl_items.iter().map(|item| self.lower_impl_item_ref(item))); @@ -978,13 +979,6 @@ impl<'hir> LoweringContext<'_, 'hir> { } fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef { - let trait_item_def_id = self - .resolver - .get_partial_res(i.id) - .map(|r| r.expect_full_res().opt_def_id()) - .unwrap_or(None); - self.is_in_trait_impl = trait_item_def_id.is_some(); - hir::ImplItemRef { id: hir::ImplItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } }, ident: self.lower_ident(i.ident), @@ -1000,7 +994,11 @@ impl<'hir> LoweringContext<'_, 'hir> { }, AssocItemKind::MacCall(..) => unimplemented!(), }, - trait_item_def_id, + trait_item_def_id: self + .resolver + .get_partial_res(i.id) + .map(|r| r.expect_full_res().opt_def_id()) + .unwrap_or(None), } } @@ -1429,8 +1427,8 @@ impl<'hir> LoweringContext<'_, 'hir> { // Error if `?Trait` bounds in where clauses don't refer directly to type parameters. // Note: we used to clone these bounds directly onto the type parameter (and avoid lowering // these into hir when we lower thee where clauses), but this makes it quite difficult to - // keep track of the Span info. Now, `add_implicitly_sized` in `AstConv` checks both param bounds and - // where clauses for `?Sized`. + // keep track of the Span info. Now, `<dyn HirTyLowerer>::add_implicit_sized_bound` + // checks both param bounds and where clauses for `?Sized`. for pred in &generics.where_clause.predicates { let WherePredicate::BoundPredicate(bound_pred) = pred else { continue; diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 6a7ee936f66..d2744e8ff68 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -55,7 +55,9 @@ use rustc_errors::{DiagArgFromDisplay, DiagCtxt, StashKey}; use rustc_hir as hir; use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res}; use rustc_hir::def_id::{LocalDefId, LocalDefIdMap, CRATE_DEF_ID, LOCAL_CRATE}; -use rustc_hir::{ConstArg, GenericArg, ItemLocalMap, ParamName, TraitCandidate}; +use rustc_hir::{ + ConstArg, GenericArg, ItemLocalMap, MissingLifetimeKind, ParamName, TraitCandidate, +}; use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_macros::extension; use rustc_middle::span_bug; @@ -797,7 +799,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { LifetimeRes::Param { .. } => { (hir::ParamName::Plain(ident), hir::LifetimeParamKind::Explicit) } - LifetimeRes::Fresh { param, .. } => { + LifetimeRes::Fresh { param, kind, .. } => { // Late resolution delegates to us the creation of the `LocalDefId`. let _def_id = self.create_def( self.current_hir_id_owner.def_id, @@ -808,7 +810,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ); debug!(?_def_id); - (hir::ParamName::Fresh, hir::LifetimeParamKind::Elided) + (hir::ParamName::Fresh, hir::LifetimeParamKind::Elided(kind)) } LifetimeRes::Static | LifetimeRes::Error => return None, res => panic!( @@ -1605,13 +1607,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { for lifetime in captured_lifetimes_to_duplicate { let res = self.resolver.get_lifetime_res(lifetime.id).unwrap_or(LifetimeRes::Error); - let old_def_id = match res { - LifetimeRes::Param { param: old_def_id, binder: _ } => old_def_id, + let (old_def_id, missing_kind) = match res { + LifetimeRes::Param { param: old_def_id, binder: _ } => (old_def_id, None), - LifetimeRes::Fresh { param, binder: _ } => { + LifetimeRes::Fresh { param, kind, .. } => { debug_assert_eq!(lifetime.ident.name, kw::UnderscoreLifetime); if let Some(old_def_id) = self.orig_opt_local_def_id(param) { - old_def_id + (old_def_id, Some(kind)) } else { self.dcx() .span_delayed_bug(lifetime.ident.span, "no def-id for fresh lifetime"); @@ -1651,6 +1653,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { duplicated_lifetime_node_id, duplicated_lifetime_def_id, self.lower_ident(lifetime.ident), + missing_kind, )); // Now make an arg that we can use for the generic params of the opaque tykind. @@ -1668,27 +1671,33 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let bounds = this .with_remapping(captured_to_synthesized_mapping, |this| lower_item_bounds(this)); - let generic_params = this.arena.alloc_from_iter( - synthesized_lifetime_definitions.iter().map(|&(new_node_id, new_def_id, ident)| { - let hir_id = this.lower_node_id(new_node_id); - let (name, kind) = if ident.name == kw::UnderscoreLifetime { - (hir::ParamName::Fresh, hir::LifetimeParamKind::Elided) - } else { - (hir::ParamName::Plain(ident), hir::LifetimeParamKind::Explicit) - }; + let generic_params = + this.arena.alloc_from_iter(synthesized_lifetime_definitions.iter().map( + |&(new_node_id, new_def_id, ident, missing_kind)| { + let hir_id = this.lower_node_id(new_node_id); + let (name, kind) = if ident.name == kw::UnderscoreLifetime { + ( + hir::ParamName::Fresh, + hir::LifetimeParamKind::Elided( + missing_kind.unwrap_or(MissingLifetimeKind::Underscore), + ), + ) + } else { + (hir::ParamName::Plain(ident), hir::LifetimeParamKind::Explicit) + }; - hir::GenericParam { - hir_id, - def_id: new_def_id, - name, - span: ident.span, - pure_wrt_drop: false, - kind: hir::GenericParamKind::Lifetime { kind }, - colon_span: None, - source: hir::GenericParamSource::Generics, - } - }), - ); + hir::GenericParam { + hir_id, + def_id: new_def_id, + name, + span: ident.span, + pure_wrt_drop: false, + kind: hir::GenericParamKind::Lifetime { kind }, + colon_span: None, + source: hir::GenericParamSource::Generics, + } + }, + )); debug!("lower_async_fn_ret_ty: generic_params={:#?}", generic_params); let lifetime_mapping = self.arena.alloc_slice(&synthesized_lifetime_args); diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index 469cdac11e4..8631d90be81 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -91,6 +91,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { PatKind::Box(inner) => { break hir::PatKind::Box(self.lower_pat(inner)); } + PatKind::Deref(inner) => { + break hir::PatKind::Deref(self.lower_pat(inner)); + } PatKind::Ref(inner, mutbl) => { break hir::PatKind::Ref(self.lower_pat(inner), *mutbl); } diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 2bef4c91224..3edb832b9a0 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -1527,6 +1527,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { generics, body.as_deref(), ); + walk_list!(self, visit_attribute, &item.attrs); self.visit_fn(kind, item.span, item.id); } AssocItemKind::Type(_) => { diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 2e14238f950..bb83f4c0f0e 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -1,7 +1,7 @@ use rustc_ast as ast; use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor}; use rustc_ast::{attr, AssocConstraint, AssocConstraintKind, NodeId}; -use rustc_ast::{PatKind, RangeEnd}; +use rustc_ast::{token, PatKind, RangeEnd}; use rustc_feature::{AttributeGate, BuiltinAttribute, Features, GateIssue, BUILTIN_ATTRIBUTE_MAP}; use rustc_session::parse::{feature_err, feature_err_issue, feature_warn}; use rustc_session::Session; @@ -378,6 +378,17 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { ast::ExprKind::TryBlock(_) => { gate!(&self, try_blocks, e.span, "`try` expression is experimental"); } + ast::ExprKind::Lit(token::Lit { kind: token::LitKind::Float, suffix, .. }) => { + match suffix { + Some(sym::f16) => { + gate!(&self, f16, e.span, "the type `f16` is unstable") + } + Some(sym::f128) => { + gate!(&self, f128, e.span, "the type `f128` is unstable") + } + _ => (), + } + } _ => {} } visit::walk_expr(self, e) @@ -452,13 +463,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { constraint.span, "return type notation is experimental" ); - } else { - gate!( - &self, - associated_type_bounds, - constraint.span, - "associated type bounds are unstable" - ); } } visit::walk_assoc_constraint(self, constraint) @@ -560,6 +564,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) { gate_all!(generic_const_items, "generic const items are experimental"); gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented"); gate_all!(fn_delegation, "functions delegation is not yet fully implemented"); + gate_all!(postfix_match, "postfix match is experimental"); if !visitor.features.never_patterns { if let Some(spans) = spans.get(&sym::never_patterns) { @@ -603,14 +608,13 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) { }; } + gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental"); gate_all_legacy_dont_use!(trait_alias, "trait aliases are experimental"); - gate_all_legacy_dont_use!(associated_type_bounds, "associated type bounds are unstable"); // Despite being a new feature, `where T: Trait<Assoc(): Sized>`, which is RTN syntax now, // used to be gated under associated_type_bounds, which are right above, so RTN needs to // be too. gate_all_legacy_dont_use!(return_type_notation, "return type notation is experimental"); gate_all_legacy_dont_use!(decl_macro, "`macro` is experimental"); - gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental"); gate_all_legacy_dont_use!( exclusive_range_pattern, "exclusive range pattern syntax is experimental" diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index c50878e32a4..a70daf1b644 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1626,6 +1626,12 @@ impl<'a> State<'a> { self.word("box "); self.print_pat(inner); } + PatKind::Deref(inner) => { + self.word("deref!"); + self.popen(); + self.print_pat(inner); + self.pclose(); + } PatKind::Ref(inner, mutbl) => { self.word("&"); if mutbl.is_mut() { diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs index 433ef03b6e5..8bd8b6ac144 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs @@ -1,6 +1,6 @@ use crate::pp::Breaks::Inconsistent; use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT}; -use ast::ForLoopKind; +use ast::{ForLoopKind, MatchKind}; use itertools::{Itertools, Position}; use rustc_ast::ptr::P; use rustc_ast::token; @@ -589,12 +589,22 @@ impl<'a> State<'a> { self.word_nbsp("loop"); self.print_block_with_attrs(blk, attrs); } - ast::ExprKind::Match(expr, arms) => { + ast::ExprKind::Match(expr, arms, match_kind) => { self.cbox(0); self.ibox(0); - self.word_nbsp("match"); - self.print_expr_as_cond(expr); - self.space(); + + match match_kind { + MatchKind::Prefix => { + self.word_nbsp("match"); + self.print_expr_as_cond(expr); + self.space(); + } + MatchKind::Postfix => { + self.print_expr_as_cond(expr); + self.word_nbsp(".match"); + } + } + self.bopen(); self.print_inner_attributes_no_trailing_hardbreak(attrs); for arm in arms { diff --git a/compiler/rustc_borrowck/messages.ftl b/compiler/rustc_borrowck/messages.ftl index bf14d5eb9a0..587536e1f9a 100644 --- a/compiler/rustc_borrowck/messages.ftl +++ b/compiler/rustc_borrowck/messages.ftl @@ -16,6 +16,9 @@ borrowck_borrow_due_to_use_closure = borrowck_borrow_due_to_use_coroutine = borrow occurs due to use in coroutine +borrowck_calling_operator_moves = + calling this operator moves the value + borrowck_calling_operator_moves_lhs = calling this operator moves the left-hand side @@ -129,6 +132,12 @@ borrowck_moved_due_to_usage_in_operator = *[false] operator } +borrowck_opaque_type_lifetime_mismatch = + opaque type used twice with different lifetimes + .label = lifetime `{$arg}` used here + .prev_lifetime_label = lifetime `{$prev}` previously used here + .note = if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + borrowck_opaque_type_non_generic_param = expected generic {$kind} parameter, found `{$ty}` .label = {STREQ($ty, "'static") -> diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index bdbd53495f3..aa98d060f5f 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -9,10 +9,9 @@ use rustc_data_structures::fx::FxIndexSet; use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::intravisit::{walk_block, walk_expr, Visitor}; +use rustc_hir::intravisit::{walk_block, walk_expr, Map, Visitor}; use rustc_hir::{CoroutineDesugaring, PatField}; use rustc_hir::{CoroutineKind, CoroutineSource, LangItem}; -use rustc_infer::traits::ObligationCause; use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::mir::tcx::PlaceTy; use rustc_middle::mir::{ @@ -21,16 +20,21 @@ use rustc_middle::mir::{ PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm, }; -use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty, TyCtxt}; +use rustc_middle::ty::{ + self, suggest_constraining_type_params, PredicateKind, ToPredicate, Ty, TyCtxt, + TypeSuperVisitable, TypeVisitor, +}; use rustc_middle::util::CallKind; use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex}; +use rustc_span::def_id::DefId; use rustc_span::def_id::LocalDefId; use rustc_span::hygiene::DesugaringKind; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::{BytePos, Span, Symbol}; use rustc_trait_selection::infer::InferCtxtExt; +use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; use rustc_trait_selection::traits::error_reporting::FindExprBySpan; -use rustc_trait_selection::traits::ObligationCtxt; +use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt}; use std::iter; use crate::borrow_set::TwoPhaseActivation; @@ -283,7 +287,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // something that already has `Fn`-like bounds (or is a closure), so we can't // restrict anyways. } else { - self.suggest_adding_copy_bounds(&mut err, ty, span); + let copy_did = self.infcx.tcx.require_lang_item(LangItem::Copy, Some(span)); + self.suggest_adding_bounds(&mut err, ty, copy_did, span); } if needs_note { @@ -442,8 +447,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { err.span_note( span, format!( - "consider changing this parameter type in {descr} `{ident}` to \ - borrow instead if owning the value isn't necessary", + "consider changing this parameter type in {descr} `{ident}` to borrow \ + instead if owning the value isn't necessary", ), ); } @@ -458,7 +463,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } else if let UseSpans::FnSelfUse { kind: CallKind::Normal { .. }, .. } = move_spans { // We already suggest cloning for these cases in `explain_captures`. - } else { + } else if self.suggest_hoisting_call_outside_loop(err, expr) { + // The place where the the type moves would be misleading to suggest clone. + // #121466 self.suggest_cloning(err, ty, expr, move_span); } } @@ -709,7 +716,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { .copied() .find_map(find_fn_kind_from_did), ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => tcx - .explicit_item_bounds(def_id) + .explicit_item_super_predicates(def_id) .iter_instantiated_copied(tcx, args) .find_map(|(clause, span)| find_fn_kind_from_did((clause, span))), ty::Closure(_, args) => match args.as_closure().kind() { @@ -742,6 +749,234 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { true } + /// In a move error that occurs on a call wihtin a loop, we try to identify cases where cloning + /// the value would lead to a logic error. We infer these cases by seeing if the moved value is + /// part of the logic to break the loop, either through an explicit `break` or if the expression + /// is part of a `while let`. + fn suggest_hoisting_call_outside_loop(&self, err: &mut Diag<'_>, expr: &hir::Expr<'_>) -> bool { + let tcx = self.infcx.tcx; + let mut can_suggest_clone = true; + + // If the moved value is a locally declared binding, we'll look upwards on the expression + // tree until the scope where it is defined, and no further, as suggesting to move the + // expression beyond that point would be illogical. + let local_hir_id = if let hir::ExprKind::Path(hir::QPath::Resolved( + _, + hir::Path { res: hir::def::Res::Local(local_hir_id), .. }, + )) = expr.kind + { + Some(local_hir_id) + } else { + // This case would be if the moved value comes from an argument binding, we'll just + // look within the entire item, that's fine. + None + }; + + /// This will allow us to look for a specific `HirId`, in our case `local_hir_id` where the + /// binding was declared, within any other expression. We'll use it to search for the + /// binding declaration within every scope we inspect. + struct Finder { + hir_id: hir::HirId, + found: bool, + } + impl<'hir> Visitor<'hir> for Finder { + fn visit_pat(&mut self, pat: &'hir hir::Pat<'hir>) { + if pat.hir_id == self.hir_id { + self.found = true; + } + hir::intravisit::walk_pat(self, pat); + } + fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) { + if ex.hir_id == self.hir_id { + self.found = true; + } + hir::intravisit::walk_expr(self, ex); + } + } + // The immediate HIR parent of the moved expression. We'll look for it to be a call. + let mut parent = None; + // The top-most loop where the moved expression could be moved to a new binding. + let mut outer_most_loop: Option<&hir::Expr<'_>> = None; + for (_, node) in tcx.hir().parent_iter(expr.hir_id) { + let e = match node { + hir::Node::Expr(e) => e, + hir::Node::Local(hir::Local { els: Some(els), .. }) => { + let mut finder = BreakFinder { found_breaks: vec![], found_continues: vec![] }; + finder.visit_block(els); + if !finder.found_breaks.is_empty() { + // Don't suggest clone as it could be will likely end in an infinite + // loop. + // let Some(_) = foo(non_copy.clone()) else { break; } + // --- ^^^^^^^^ ----- + can_suggest_clone = false; + } + continue; + } + _ => continue, + }; + if let Some(&hir_id) = local_hir_id { + let mut finder = Finder { hir_id, found: false }; + finder.visit_expr(e); + if finder.found { + // The current scope includes the declaration of the binding we're accessing, we + // can't look up any further for loops. + break; + } + } + if parent.is_none() { + parent = Some(e); + } + match e.kind { + hir::ExprKind::Let(_) => { + match tcx.parent_hir_node(e.hir_id) { + hir::Node::Expr(hir::Expr { + kind: hir::ExprKind::If(cond, ..), .. + }) => { + let mut finder = Finder { hir_id: expr.hir_id, found: false }; + finder.visit_expr(cond); + if finder.found { + // The expression where the move error happened is in a `while let` + // condition Don't suggest clone as it will likely end in an + // infinite loop. + // while let Some(_) = foo(non_copy.clone()) { } + // --------- ^^^^^^^^ + can_suggest_clone = false; + } + } + _ => {} + } + } + hir::ExprKind::Loop(..) => { + outer_most_loop = Some(e); + } + _ => {} + } + } + let loop_count: usize = tcx + .hir() + .parent_iter(expr.hir_id) + .map(|(_, node)| match node { + hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Loop(..), .. }) => 1, + _ => 0, + }) + .sum(); + + let sm = tcx.sess.source_map(); + if let Some(in_loop) = outer_most_loop { + let mut finder = BreakFinder { found_breaks: vec![], found_continues: vec![] }; + finder.visit_expr(in_loop); + // All of the spans for `break` and `continue` expressions. + let spans = finder + .found_breaks + .iter() + .chain(finder.found_continues.iter()) + .map(|(_, span)| *span) + .filter(|span| { + !matches!( + span.desugaring_kind(), + Some(DesugaringKind::ForLoop | DesugaringKind::WhileLoop) + ) + }) + .collect::<Vec<Span>>(); + // All of the spans for the loops above the expression with the move error. + let loop_spans: Vec<_> = tcx + .hir() + .parent_iter(expr.hir_id) + .filter_map(|(_, node)| match node { + hir::Node::Expr(hir::Expr { span, kind: hir::ExprKind::Loop(..), .. }) => { + Some(*span) + } + _ => None, + }) + .collect(); + // It is possible that a user written `break` or `continue` is in the wrong place. We + // point them out at the user for them to make a determination. (#92531) + if !spans.is_empty() && loop_count > 1 { + // Getting fancy: if the spans of the loops *do not* overlap, we only use the line + // number when referring to them. If there *are* overlaps (multiple loops on the + // same line) then we use the more verbose span output (`file.rs:col:ll`). + let mut lines: Vec<_> = + loop_spans.iter().map(|sp| sm.lookup_char_pos(sp.lo()).line).collect(); + lines.sort(); + lines.dedup(); + let fmt_span = |span: Span| { + if lines.len() == loop_spans.len() { + format!("line {}", sm.lookup_char_pos(span.lo()).line) + } else { + sm.span_to_diagnostic_string(span) + } + }; + let mut spans: MultiSpan = spans.clone().into(); + // Point at all the `continue`s and explicit `break`s in the relevant loops. + for (desc, elements) in [ + ("`break` exits", &finder.found_breaks), + ("`continue` advances", &finder.found_continues), + ] { + for (destination, sp) in elements { + if let Ok(hir_id) = destination.target_id + && let hir::Node::Expr(expr) = tcx.hir().hir_node(hir_id) + && !matches!( + sp.desugaring_kind(), + Some(DesugaringKind::ForLoop | DesugaringKind::WhileLoop) + ) + { + spans.push_span_label( + *sp, + format!("this {desc} the loop at {}", fmt_span(expr.span)), + ); + } + } + } + // Point at all the loops that are between this move and the parent item. + for span in loop_spans { + spans.push_span_label(sm.guess_head_span(span), ""); + } + + // note: verify that your loop breaking logic is correct + // --> $DIR/nested-loop-moved-value-wrong-continue.rs:41:17 + // | + // 28 | for foo in foos { + // | --------------- + // ... + // 33 | for bar in &bars { + // | ---------------- + // ... + // 41 | continue; + // | ^^^^^^^^ this `continue` advances the loop at line 33 + err.span_note(spans, "verify that your loop breaking logic is correct"); + } + if let Some(parent) = parent + && let hir::ExprKind::MethodCall(..) | hir::ExprKind::Call(..) = parent.kind + { + // FIXME: We could check that the call's *parent* takes `&mut val` to make the + // suggestion more targeted to the `mk_iter(val).next()` case. Maybe do that only to + // check for wheter to suggest `let value` or `let mut value`. + + let span = in_loop.span; + if !finder.found_breaks.is_empty() + && let Ok(value) = sm.span_to_snippet(parent.span) + { + // We know with high certainty that this move would affect the early return of a + // loop, so we suggest moving the expression with the move out of the loop. + let indent = if let Some(indent) = sm.indentation_before(span) { + format!("\n{indent}") + } else { + " ".to_string() + }; + err.multipart_suggestion( + "consider moving the expression out of the loop so it is only moved once", + vec![ + (parent.span, "value".to_string()), + (span.shrink_to_lo(), format!("let mut value = {value};{indent}")), + ], + Applicability::MaybeIncorrect, + ); + } + } + } + can_suggest_clone + } + fn suggest_cloning(&self, err: &mut Diag<'_>, ty: Ty<'tcx>, expr: &hir::Expr<'_>, span: Span) { let tcx = self.infcx.tcx; // Try to find predicates on *generic params* that would allow copying `ty` @@ -774,7 +1009,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } } - fn suggest_adding_copy_bounds(&self, err: &mut Diag<'_>, ty: Ty<'tcx>, span: Span) { + fn suggest_adding_bounds(&self, err: &mut Diag<'_>, ty: Ty<'tcx>, def_id: DefId, span: Span) { let tcx = self.infcx.tcx; let generics = tcx.generics_of(self.mir_def_id()); @@ -787,10 +1022,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { }; // Try to find predicates on *generic params* that would allow copying `ty` let ocx = ObligationCtxt::new(self.infcx); - let copy_did = tcx.require_lang_item(LangItem::Copy, Some(span)); let cause = ObligationCause::misc(span, self.mir_def_id()); - ocx.register_bound(cause, self.param_env, ty, copy_did); + ocx.register_bound(cause, self.param_env, ty, def_id); let errors = ocx.select_all_or_error(); // Only emit suggestion if all required predicates are on generic @@ -876,6 +1110,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { Some(borrow_span), None, ); + self.suggest_copy_for_type_in_cloned_ref(&mut err, place); self.buffer_error(err); } @@ -1214,10 +1449,104 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ); self.suggest_using_local_if_applicable(&mut err, location, issued_borrow, explanation); + self.suggest_copy_for_type_in_cloned_ref(&mut err, place); err } + fn suggest_copy_for_type_in_cloned_ref(&self, err: &mut Diag<'tcx>, place: Place<'tcx>) { + let tcx = self.infcx.tcx; + let hir = tcx.hir(); + let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return }; + struct FindUselessClone<'hir> { + pub clones: Vec<&'hir hir::Expr<'hir>>, + } + impl<'hir> FindUselessClone<'hir> { + pub fn new() -> Self { + Self { clones: vec![] } + } + } + + impl<'v> Visitor<'v> for FindUselessClone<'v> { + fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) { + // FIXME: use `lookup_method_for_diagnostic`? + if let hir::ExprKind::MethodCall(segment, _rcvr, args, _span) = ex.kind + && segment.ident.name == sym::clone + && args.len() == 0 + { + self.clones.push(ex); + } + hir::intravisit::walk_expr(self, ex); + } + } + let mut expr_finder = FindUselessClone::new(); + + let body = hir.body(body_id).value; + expr_finder.visit_expr(body); + + pub struct Holds<'tcx> { + ty: Ty<'tcx>, + holds: bool, + } + + impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for Holds<'tcx> { + type Result = std::ops::ControlFlow<()>; + + fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result { + if t == self.ty { + self.holds = true; + } + t.super_visit_with(self) + } + } + + let mut types_to_constrain = FxIndexSet::default(); + + let local_ty = self.body.local_decls[place.local].ty; + let typeck_results = tcx.typeck(self.mir_def_id()); + let clone = tcx.require_lang_item(LangItem::Clone, Some(body.span)); + for expr in expr_finder.clones { + if let hir::ExprKind::MethodCall(_, rcvr, _, span) = expr.kind + && let Some(rcvr_ty) = typeck_results.node_type_opt(rcvr.hir_id) + && let Some(ty) = typeck_results.node_type_opt(expr.hir_id) + && rcvr_ty == ty + && let ty::Ref(_, inner, _) = rcvr_ty.kind() + && let inner = inner.peel_refs() + && let mut v = (Holds { ty: inner, holds: false }) + && let _ = v.visit_ty(local_ty) + && v.holds + && let None = self.infcx.type_implements_trait_shallow(clone, inner, self.param_env) + { + err.span_label( + span, + format!( + "this call doesn't do anything, the result is still `{rcvr_ty}` \ + because `{inner}` doesn't implement `Clone`", + ), + ); + types_to_constrain.insert(inner); + } + } + for ty in types_to_constrain { + self.suggest_adding_bounds(err, ty, clone, body.span); + if let ty::Adt(..) = ty.kind() { + // The type doesn't implement Clone. + let trait_ref = ty::Binder::dummy(ty::TraitRef::new(self.infcx.tcx, clone, [ty])); + let obligation = Obligation::new( + self.infcx.tcx, + ObligationCause::dummy(), + self.param_env, + trait_ref, + ); + self.infcx.err_ctxt().suggest_derive( + &obligation, + err, + trait_ref.to_predicate(self.infcx.tcx), + ); + } + } + } + #[instrument(level = "debug", skip(self, err))] fn suggest_using_local_if_applicable( &self, @@ -3589,6 +3918,28 @@ impl<'a, 'v> Visitor<'v> for ReferencedStatementsVisitor<'a> { } } +/// Look for `break` expressions within any arbitrary expressions. We'll do this to infer +/// whether this is a case where the moved value would affect the exit of a loop, making it +/// unsuitable for a `.clone()` suggestion. +struct BreakFinder { + found_breaks: Vec<(hir::Destination, Span)>, + found_continues: Vec<(hir::Destination, Span)>, +} +impl<'hir> Visitor<'hir> for BreakFinder { + fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) { + match ex.kind { + hir::ExprKind::Break(destination, _) => { + self.found_breaks.push((destination, ex.span)); + } + hir::ExprKind::Continue(destination) => { + self.found_continues.push((destination, ex.span)); + } + _ => {} + } + hir::intravisit::walk_expr(self, ex); + } +} + /// Given a set of spans representing statements initializing the relevant binding, visit all the /// function expressions looking for branching code paths that *do not* initialize the binding. struct ConditionVisitor<'b> { diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 560928d3941..914f68a38b4 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -1050,7 +1050,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ); err.subdiagnostic(self.dcx(), CaptureReasonNote::FnOnceMoveInCall { var_span }); } - CallKind::Operator { self_arg, .. } => { + CallKind::Operator { self_arg, trait_id, .. } => { let self_arg = self_arg.unwrap(); err.subdiagnostic( self.dcx(), @@ -1062,9 +1062,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { }, ); if self.fn_self_span_reported.insert(fn_span) { + let lang = self.infcx.tcx.lang_items(); err.subdiagnostic( self.dcx(), - CaptureReasonNote::LhsMoveByOperator { span: self_arg.span }, + if [lang.not_trait(), lang.deref_trait(), lang.neg_trait()] + .contains(&Some(trait_id)) + { + CaptureReasonNote::UnOpMoveByOperator { span: self_arg.span } + } else { + CaptureReasonNote::LhsMoveByOperator { span: self_arg.span } + }, ); } } @@ -1226,20 +1233,20 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { { let msg = match &errors[..] { [] => "you can `clone` the value and consume it, but this \ - might not be your desired behavior" + might not be your desired behavior" .to_string(), [error] => { format!( - "you could `clone` the value and consume it, if \ - the `{}` trait bound could be satisfied", + "you could `clone` the value and consume it, if the \ + `{}` trait bound could be satisfied", error.obligation.predicate, ) } [errors @ .., last] => { format!( - "you could `clone` the value and consume it, if \ - the following trait bounds could be satisfied: {} \ - and `{}`", + "you could `clone` the value and consume it, if the \ + following trait bounds could be satisfied: \ + {} and `{}`", errors .iter() .map(|e| format!("`{}`", e.obligation.predicate)) diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index a27d016e0ba..36c2723b66d 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -2,7 +2,7 @@ #![allow(rustc::untranslatable_diagnostic)] use core::ops::ControlFlow; -use hir::ExprKind; +use hir::{ExprKind, Param}; use rustc_errors::{Applicability, Diag}; use rustc_hir as hir; use rustc_hir::intravisit::Visitor; @@ -725,25 +725,26 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { _ => local_decl.source_info.span, }; - let def_id = self.body.source.def_id(); - let hir_id = if let Some(local_def_id) = def_id.as_local() - && let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id) - { - let body = self.infcx.tcx.hir().body(body_id); - BindingFinder { span: pat_span }.visit_body(body).break_value() - } else { - None - }; - // With ref-binding patterns, the mutability suggestion has to apply to // the binding, not the reference (which would be a type error): // // `let &b = a;` -> `let &(mut b) = a;` - if let Some(hir_id) = hir_id + // or + // `fn foo(&x: &i32)` -> `fn foo(&(mut x): &i32)` + let def_id = self.body.source.def_id(); + if let Some(local_def_id) = def_id.as_local() + && let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id) + && let body = self.infcx.tcx.hir().body(body_id) + && let Some(hir_id) = (BindingFinder { span: pat_span }).visit_body(body).break_value() + && let node = self.infcx.tcx.hir_node(hir_id) && let hir::Node::Local(hir::Local { pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. }, .. - }) = self.infcx.tcx.hir_node(hir_id) + }) + | hir::Node::Param(Param { + pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. }, + .. + }) = node && let Ok(name) = self.infcx.tcx.sess.source_map().span_to_snippet(local_decl.source_info.span) { @@ -1310,6 +1311,16 @@ impl<'tcx> Visitor<'tcx> for BindingFinder { hir::intravisit::walk_stmt(self, s) } } + + fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) -> Self::Result { + if let hir::Pat { kind: hir::PatKind::Ref(_, _), span, .. } = param.pat + && *span == self.span + { + ControlFlow::Break(param.hir_id) + } else { + ControlFlow::Continue(()) + } + } } pub fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<Symbol>) -> bool { diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 415ba095a1b..9f4f88b2b93 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -4,7 +4,7 @@ #![feature(rustdoc_internals)] #![doc(rust_logo)] #![feature(assert_matches)] -#![feature(associated_type_bounds)] +#![cfg_attr(bootstrap, feature(associated_type_bounds))] #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(let_chains)] diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index 8a172233037..d5875a226fe 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -9,17 +9,77 @@ use rustc_infer::traits::{Obligation, ObligationCause}; use rustc_macros::extension; use rustc_middle::traits::DefiningAnchor; use rustc_middle::ty::visit::TypeVisitableExt; +use rustc_middle::ty::RegionVid; use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable}; use rustc_middle::ty::{GenericArgKind, GenericArgs}; use rustc_span::Span; use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _; use rustc_trait_selection::traits::ObligationCtxt; +use crate::session_diagnostics::LifetimeMismatchOpaqueParam; use crate::session_diagnostics::NonGenericOpaqueTypeParam; use super::RegionInferenceContext; impl<'tcx> RegionInferenceContext<'tcx> { + fn universal_name(&self, vid: ty::RegionVid) -> Option<ty::Region<'tcx>> { + let scc = self.constraint_sccs.scc(vid); + self.scc_values + .universal_regions_outlived_by(scc) + .find_map(|lb| self.eval_equal(vid, lb).then_some(self.definitions[lb].external_name?)) + } + + fn generic_arg_to_region(&self, arg: ty::GenericArg<'tcx>) -> Option<RegionVid> { + let region = arg.as_region()?; + + if let ty::RePlaceholder(..) = region.kind() { + None + } else { + Some(self.to_region_vid(region)) + } + } + + /// Check that all opaque types have the same region parameters if they have the same + /// non-region parameters. This is necessary because within the new solver we perform various query operations + /// modulo regions, and thus could unsoundly select some impls that don't hold. + fn check_unique( + &self, + infcx: &InferCtxt<'tcx>, + opaque_ty_decls: &FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>>, + ) { + for (i, (a, a_ty)) in opaque_ty_decls.iter().enumerate() { + for (b, b_ty) in opaque_ty_decls.iter().skip(i + 1) { + if a.def_id != b.def_id { + continue; + } + // Non-lifetime params differ -> ok + if infcx.tcx.erase_regions(a.args) != infcx.tcx.erase_regions(b.args) { + continue; + } + trace!(?a, ?b); + for (a, b) in a.args.iter().zip(b.args) { + trace!(?a, ?b); + let Some(r1) = self.generic_arg_to_region(a) else { + continue; + }; + let Some(r2) = self.generic_arg_to_region(b) else { + continue; + }; + if self.eval_equal(r1, r2) { + continue; + } + + infcx.dcx().emit_err(LifetimeMismatchOpaqueParam { + arg: self.universal_name(r1).unwrap().into(), + prev: self.universal_name(r2).unwrap().into(), + span: a_ty.span, + prev_span: b_ty.span, + }); + } + } + } + } + /// Resolve any opaque types that were encountered while borrow checking /// this item. This is then used to get the type in the `type_of` query. /// @@ -65,6 +125,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { infcx: &InferCtxt<'tcx>, opaque_ty_decls: FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>>, ) -> FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>> { + self.check_unique(infcx, &opaque_ty_decls); + let mut result: FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>> = FxIndexMap::default(); let member_constraints: FxIndexMap<_, _> = self @@ -80,26 +142,20 @@ impl<'tcx> RegionInferenceContext<'tcx> { let mut arg_regions = vec![self.universal_regions.fr_static]; - let to_universal_region = |vid, arg_regions: &mut Vec<_>| { - trace!(?vid); - let scc = self.constraint_sccs.scc(vid); - trace!(?scc); - match self.scc_values.universal_regions_outlived_by(scc).find_map(|lb| { - self.eval_equal(vid, lb).then_some(self.definitions[lb].external_name?) - }) { - Some(region) => { - let vid = self.universal_regions.to_region_vid(region); - arg_regions.push(vid); - region - } - None => { - arg_regions.push(vid); - ty::Region::new_error_with_message( - infcx.tcx, - concrete_type.span, - "opaque type with non-universal region args", - ) - } + let to_universal_region = |vid, arg_regions: &mut Vec<_>| match self.universal_name(vid) + { + Some(region) => { + let vid = self.universal_regions.to_region_vid(region); + arg_regions.push(vid); + region + } + None => { + arg_regions.push(vid); + ty::Region::new_error_with_message( + infcx.tcx, + concrete_type.span, + "opaque type with non-universal region args", + ) } }; @@ -136,6 +192,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { .find(|ur_vid| self.eval_equal(vid, **ur_vid)) .and_then(|ur_vid| self.definitions[*ur_vid].external_name) .unwrap_or(infcx.tcx.lifetimes.re_erased), + ty::RePlaceholder(_) => ty::Region::new_error_with_message( + infcx.tcx, + concrete_type.span, + "hidden type contains placeholders, we don't support higher kinded opaques yet", + ), _ => region, }); debug!(?universal_concrete_type); @@ -378,10 +439,6 @@ fn check_opaque_type_parameter_valid( // Only check the parent generics, which will ignore any of the // duplicated lifetime args that come from reifying late-bounds. for (i, arg) in opaque_type_key.args.iter().take(parent_generics.count()).enumerate() { - if let Err(guar) = arg.error_reported() { - return Err(guar); - } - let arg_is_param = match arg.unpack() { GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)), GenericArgKind::Lifetime(lt) if is_ty_alias => { diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index a055ce95e8e..40c2ef1c91e 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -304,6 +304,19 @@ pub(crate) struct NonGenericOpaqueTypeParam<'a, 'tcx> { pub param_span: Span, } +#[derive(Diagnostic)] +#[diag(borrowck_opaque_type_lifetime_mismatch)] +pub(crate) struct LifetimeMismatchOpaqueParam<'tcx> { + pub arg: GenericArg<'tcx>, + pub prev: GenericArg<'tcx>, + #[primary_span] + #[label] + #[note] + pub span: Span, + #[label(borrowck_prev_lifetime_label)] + pub prev_span: Span, +} + #[derive(Subdiagnostic)] pub(crate) enum CaptureReasonLabel<'a> { #[label(borrowck_moved_due_to_call)] @@ -368,6 +381,11 @@ pub(crate) enum CaptureReasonNote { #[primary_span] var_span: Span, }, + #[note(borrowck_calling_operator_moves)] + UnOpMoveByOperator { + #[primary_span] + span: Span, + }, #[note(borrowck_calling_operator_moves_lhs)] LhsMoveByOperator { #[primary_span] diff --git a/compiler/rustc_borrowck/src/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs index e5ebf97cfc4..a673c4c2aca 100644 --- a/compiler/rustc_borrowck/src/type_check/canonical.rs +++ b/compiler/rustc_borrowck/src/type_check/canonical.rs @@ -61,7 +61,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { Ok(output) } - pub(super) fn instantiate_canonical_with_fresh_inference_vars<T>( + pub(super) fn instantiate_canonical<T>( &mut self, span: Span, canonical: &Canonical<'tcx, T>, @@ -69,8 +69,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { where T: TypeFoldable<TyCtxt<'tcx>>, { - let (instantiated, _) = - self.infcx.instantiate_canonical_with_fresh_inference_vars(span, canonical); + let (instantiated, _) = self.infcx.instantiate_canonical(span, canonical); instantiated } diff --git a/compiler/rustc_borrowck/src/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs index 8af78b08f69..a4c1066ee8e 100644 --- a/compiler/rustc_borrowck/src/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -39,8 +39,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // (e.g., the `_` in the code above) with fresh variables. // Then replace the bound items in the fn sig with fresh variables, // so that they represent the view from "inside" the closure. - let user_provided_sig = self - .instantiate_canonical_with_fresh_inference_vars(body.span, &user_provided_poly_sig); + let user_provided_sig = self.instantiate_canonical(body.span, &user_provided_poly_sig); let mut user_provided_sig = self.infcx.instantiate_binder_with_fresh_vars( body.span, BoundRegionConversionTime::FnCall, @@ -88,7 +87,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.tcx(), ty::CoroutineArgsParts { parent_args: args.parent_args(), - kind_ty: Ty::from_closure_kind(self.tcx(), args.kind()), + kind_ty: Ty::from_coroutine_closure_kind(self.tcx(), args.kind()), return_ty: user_provided_sig.output(), tupled_upvars_ty, // For async closures, none of these can be annotated, so just fill diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 412d50f493e..acda2a7524c 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1109,7 +1109,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let tcx = self.tcx(); for user_annotation in self.user_type_annotations { let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = *user_annotation; - let annotation = self.instantiate_canonical_with_fresh_inference_vars(span, user_ty); + let annotation = self.instantiate_canonical(span, user_ty); if let ty::UserType::TypeOf(def, args) = annotation && let DefKind::InlineConst = tcx.def_kind(def) { diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index 62c02817011..76805617c93 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -189,7 +189,7 @@ pub fn parse_asm_args<'a>( args.templates.push(template); continue; } else { - return p.unexpected(); + p.unexpected_any()? }; allow_templates = false; diff --git a/compiler/rustc_builtin_macros/src/assert.rs b/compiler/rustc_builtin_macros/src/assert.rs index 35a0857fe51..5905bdd7108 100644 --- a/compiler/rustc_builtin_macros/src/assert.rs +++ b/compiler/rustc_builtin_macros/src/assert.rs @@ -151,7 +151,7 @@ fn parse_assert<'a>(cx: &mut ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PRes }; if parser.token != token::Eof { - return parser.unexpected(); + parser.unexpected()?; } Ok(Assert { cond_expr, custom_message }) diff --git a/compiler/rustc_builtin_macros/src/assert/context.rs b/compiler/rustc_builtin_macros/src/assert/context.rs index 56c56b2704b..92efeab08eb 100644 --- a/compiler/rustc_builtin_macros/src/assert/context.rs +++ b/compiler/rustc_builtin_macros/src/assert/context.rs @@ -245,7 +245,7 @@ impl<'cx, 'a> Context<'cx, 'a> { ExprKind::Let(_, local_expr, _, _) => { self.manage_cond_expr(local_expr); } - ExprKind::Match(local_expr, _) => { + ExprKind::Match(local_expr, ..) => { self.manage_cond_expr(local_expr); } ExprKind::MethodCall(call) => { diff --git a/compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs b/compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs index 6eccd67f8af..60dbdf8b544 100644 --- a/compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs +++ b/compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs @@ -132,7 +132,7 @@ fn cs_partial_cmp( // Reference: https://github.com/rust-lang/rust/pull/103659#issuecomment-1328126354 if !tag_then_data - && let ExprKind::Match(_, arms) = &mut expr1.kind + && let ExprKind::Match(_, arms, _) = &mut expr1.kind && let Some(last) = arms.last_mut() && let PatKind::Wild = last.pat.kind { diff --git a/compiler/rustc_builtin_macros/src/deriving/debug.rs b/compiler/rustc_builtin_macros/src/deriving/debug.rs index b11a1b6cda1..108c1078eaa 100644 --- a/compiler/rustc_builtin_macros/src/deriving/debug.rs +++ b/compiler/rustc_builtin_macros/src/deriving/debug.rs @@ -2,8 +2,7 @@ use crate::deriving::generic::ty::*; use crate::deriving::generic::*; use crate::deriving::path_std; -use ast::EnumDef; -use rustc_ast::{self as ast, MetaItem}; +use rustc_ast::{self as ast, EnumDef, MetaItem}; use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::Span; diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index f344dbcd10c..554dac0852f 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -49,7 +49,6 @@ mod log_syntax; mod source_util; mod test; mod trace_macros; -mod type_ascribe; mod util; pub mod asm; @@ -99,7 +98,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) { std_panic: edition_panic::expand_panic, stringify: source_util::expand_stringify, trace_macros: trace_macros::expand_trace_macros, - type_ascribe: type_ascribe::expand_type_ascribe, unreachable: edition_panic::expand_unreachable, // tidy-alphabetical-end } diff --git a/compiler/rustc_builtin_macros/src/type_ascribe.rs b/compiler/rustc_builtin_macros/src/type_ascribe.rs deleted file mode 100644 index f3e66ffc759..00000000000 --- a/compiler/rustc_builtin_macros/src/type_ascribe.rs +++ /dev/null @@ -1,35 +0,0 @@ -use rustc_ast::ptr::P; -use rustc_ast::tokenstream::TokenStream; -use rustc_ast::{token, Expr, ExprKind, Ty}; -use rustc_errors::PResult; -use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult}; -use rustc_span::Span; - -pub fn expand_type_ascribe( - cx: &mut ExtCtxt<'_>, - span: Span, - tts: TokenStream, -) -> MacroExpanderResult<'static> { - let (expr, ty) = match parse_ascribe(cx, tts) { - Ok(parsed) => parsed, - Err(err) => { - let guar = err.emit(); - return ExpandResult::Ready(DummyResult::any(span, guar)); - } - }; - - let asc_expr = cx.expr(span, ExprKind::Type(expr, ty)); - - ExpandResult::Ready(MacEager::expr(asc_expr)) -} - -fn parse_ascribe<'a>(cx: &mut ExtCtxt<'a>, stream: TokenStream) -> PResult<'a, (P<Expr>, P<Ty>)> { - let mut parser = cx.new_parser_from_tts(stream); - - let expr = parser.parse_expr()?; - parser.expect(&token::Comma)?; - - let ty = parser.parse_ty()?; - - Ok((expr, ty)) -} diff --git a/compiler/rustc_codegen_cranelift/.github/workflows/main.yml b/compiler/rustc_codegen_cranelift/.github/workflows/main.yml index 5f0f3e6549c..526871d0c05 100644 --- a/compiler/rustc_codegen_cranelift/.github/workflows/main.yml +++ b/compiler/rustc_codegen_cranelift/.github/workflows/main.yml @@ -44,10 +44,9 @@ jobs: env: TARGET_TRIPLE: x86_64-apple-darwin # cross-compile from Linux to Windows using mingw - # FIXME The wine version in Ubuntu 22.04 is missing ProcessPrng - #- os: ubuntu-latest - # env: - # TARGET_TRIPLE: x86_64-pc-windows-gnu + - os: ubuntu-latest + env: + TARGET_TRIPLE: x86_64-pc-windows-gnu - os: ubuntu-latest env: TARGET_TRIPLE: aarch64-unknown-linux-gnu @@ -81,11 +80,11 @@ jobs: if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' run: rustup set default-host x86_64-pc-windows-gnu - #- name: Install MinGW toolchain and wine - # if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' - # run: | - # sudo apt-get update - # sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable + - name: Install MinGW toolchain and wine + if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' + run: | + sudo apt-get update + sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable - name: Install AArch64 toolchain and qemu if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu' @@ -108,6 +107,15 @@ jobs: - name: Prepare dependencies run: ./y.sh prepare + # The Wine version shipped with Ubuntu 22.04 doesn't implement bcryptprimitives.dll + - name: Build bcryptprimitives.dll shim for Wine + if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' + run: | + rustup target add x86_64-pc-windows-gnu + mkdir wine_shims + rustc patches/bcryptprimitives.rs -Copt-level=3 -Clto=fat --out-dir wine_shims --target x86_64-pc-windows-gnu + echo "WINEPATH=$(pwd)/wine_shims" >> $GITHUB_ENV + - name: Build run: ./y.sh build --sysroot none @@ -234,11 +242,11 @@ jobs: if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' run: rustup set default-host x86_64-pc-windows-gnu - - name: Install MinGW toolchain and wine + - name: Install MinGW toolchain if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' run: | sudo apt-get update - sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable + sudo apt-get install -y gcc-mingw-w64-x86-64 - name: Prepare dependencies run: ./y.sh prepare diff --git a/compiler/rustc_codegen_cranelift/example/std_example.rs b/compiler/rustc_codegen_cranelift/example/std_example.rs index 9bd2ab5c638..2fee912e52c 100644 --- a/compiler/rustc_codegen_cranelift/example/std_example.rs +++ b/compiler/rustc_codegen_cranelift/example/std_example.rs @@ -167,6 +167,14 @@ fn main() { transmute_fat_pointer(); rust_call_abi(); + + const fn no_str() -> Option<Box<str>> { + None + } + + static STATIC_WITH_MAYBE_NESTED_BOX: &Option<Box<str>> = &no_str(); + + println!("{:?}", STATIC_WITH_MAYBE_NESTED_BOX); } fn panic(_: u128) { diff --git a/compiler/rustc_codegen_cranelift/patches/bcryptprimitives.rs b/compiler/rustc_codegen_cranelift/patches/bcryptprimitives.rs new file mode 100644 index 00000000000..4d186485aac --- /dev/null +++ b/compiler/rustc_codegen_cranelift/patches/bcryptprimitives.rs @@ -0,0 +1,22 @@ +// Shim for bcryptprimitives.dll. The Wine version shipped with Ubuntu 22.04 +// doesn't support it yet. Authored by @ChrisDenton + +#![crate_type = "cdylib"] +#![allow(nonstandard_style)] + +#[no_mangle] +pub unsafe extern "system" fn ProcessPrng(mut pbData: *mut u8, mut cbData: usize) -> i32 { + while cbData > 0 { + let size = core::cmp::min(cbData, u32::MAX as usize); + RtlGenRandom(pbData, size as u32); + cbData -= size; + pbData = pbData.add(size); + } + 1 +} + +#[link(name = "advapi32")] +extern "system" { + #[link_name = "SystemFunction036"] + pub fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: u32) -> u8; +} diff --git a/compiler/rustc_codegen_cranelift/patches/stdlib-lock.toml b/compiler/rustc_codegen_cranelift/patches/stdlib-lock.toml index 369f9c88be1..a72fa2c62a9 100644 --- a/compiler/rustc_codegen_cranelift/patches/stdlib-lock.toml +++ b/compiler/rustc_codegen_cranelift/patches/stdlib-lock.toml @@ -42,12 +42,9 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "cc" -version = "1.0.83" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" [[package]] name = "cfg-if" diff --git a/compiler/rustc_codegen_cranelift/rust-toolchain b/compiler/rustc_codegen_cranelift/rust-toolchain index e9f225b4e9e..f3cd4cbe493 100644 --- a/compiler/rustc_codegen_cranelift/rust-toolchain +++ b/compiler/rustc_codegen_cranelift/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-03-08" +channel = "nightly-2024-03-16" components = ["rust-src", "rustc-dev", "llvm-tools"] diff --git a/compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh b/compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh index e884577d519..9b360fb3036 100755 --- a/compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh +++ b/compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh @@ -83,6 +83,7 @@ rm -r tests/run-make/symbols-include-type-name # --emit=asm not supported rm -r tests/run-make/target-specs # i686 not supported by Cranelift rm -r tests/run-make/mismatching-target-triples # same rm tests/ui/asm/x86_64/issue-96797.rs # const and sym inline asm operands don't work entirely correctly +rm tests/ui/asm/x86_64/goto.rs # inline asm labels not supported # requires LTO rm -r tests/run-make/cdylib @@ -121,6 +122,7 @@ rm -r tests/run-make/optimization-remarks-dir # remarks are LLVM specific rm tests/ui/mir/mir_misc_casts.rs # depends on deduplication of constants rm tests/ui/mir/mir_raw_fat_ptr.rs # same rm tests/ui/consts/issue-33537.rs # same +rm tests/ui/consts/const-mut-refs-crate.rs # same # rustdoc-clif passes extra args, suppressing the help message when no args are passed rm -r tests/run-make/issue-88756-default-output diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index cec479218b7..fc9b0f6ef02 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -53,7 +53,11 @@ pub(crate) fn codegen_tls_ref<'tcx>( let call = fx.bcx.ins().call(func_ref, &[]); fx.bcx.func.dfg.first_result(call) } else { - let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); + let data_id = data_id_for_static( + fx.tcx, fx.module, def_id, false, + // For a declaration the stated mutability doesn't matter. + false, + ); let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); if fx.clif_comments.enabled() { fx.add_comment(local_data_id, format!("tls {:?}", def_id)); @@ -70,7 +74,7 @@ pub(crate) fn eval_mir_constant<'tcx>( let cv = fx.monomorphize(constant.const_); // This cannot fail because we checked all required_consts in advance. let val = cv - .eval(fx.tcx, ty::ParamEnv::reveal_all(), Some(constant.span)) + .eval(fx.tcx, ty::ParamEnv::reveal_all(), constant.span) .expect("erroneous constant missed by mono item collection"); (val, cv.ty()) } @@ -164,7 +168,11 @@ pub(crate) fn codegen_const_value<'tcx>( } GlobalAlloc::Static(def_id) => { assert!(fx.tcx.is_static(def_id)); - let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); + let data_id = data_id_for_static( + fx.tcx, fx.module, def_id, false, + // For a declaration the stated mutability doesn't matter. + false, + ); let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); if fx.clif_comments.enabled() { @@ -232,21 +240,19 @@ fn data_id_for_static( module: &mut dyn Module, def_id: DefId, definition: bool, + definition_writable: bool, ) -> DataId { let attrs = tcx.codegen_fn_attrs(def_id); let instance = Instance::mono(tcx, def_id).polymorphize(tcx); let symbol_name = tcx.symbol_name(instance).name; - let ty = instance.ty(tcx, ParamEnv::reveal_all()); - let is_mutable = if tcx.is_mutable_static(def_id) { - true - } else { - !ty.is_freeze(tcx, ParamEnv::reveal_all()) - }; - let align = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().align.pref.bytes(); if let Some(import_linkage) = attrs.import_linkage { assert!(!definition); + assert!(!tcx.is_mutable_static(def_id)); + + let ty = instance.ty(tcx, ParamEnv::reveal_all()); + let align = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().align.pref.bytes(); let linkage = if import_linkage == rustc_middle::mir::mono::Linkage::ExternalWeak || import_linkage == rustc_middle::mir::mono::Linkage::WeakAny @@ -259,7 +265,7 @@ fn data_id_for_static( let data_id = match module.declare_data( symbol_name, linkage, - is_mutable, + false, attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL), ) { Ok(data_id) => data_id, @@ -307,7 +313,7 @@ fn data_id_for_static( let data_id = match module.declare_data( symbol_name, linkage, - is_mutable, + definition_writable, attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL), ) { Ok(data_id) => data_id, @@ -341,7 +347,13 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant let alloc = tcx.eval_static_initializer(def_id).unwrap(); - let data_id = data_id_for_static(tcx, module, def_id, true); + let data_id = data_id_for_static( + tcx, + module, + def_id, + true, + alloc.inner().mutability == Mutability::Mut, + ); (data_id, alloc, section_name) } }; @@ -421,7 +433,11 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant // Don't push a `TodoItem::Static` here, as it will cause statics used by // multiple crates to be duplicated between them. It isn't necessary anyway, // as it will get pushed by `codegen_static` when necessary. - data_id_for_static(tcx, module, def_id, false) + data_id_for_static( + tcx, module, def_id, false, + // For a declaration the stated mutability doesn't matter. + false, + ) } }; diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs index 8b86a116df1..25694af78f1 100644 --- a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs @@ -728,8 +728,10 @@ fn codegen_regular_intrinsic_call<'tcx>( | sym::variant_count => { intrinsic_args!(fx, args => (); intrinsic); - let const_val = - fx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap(); + let const_val = fx + .tcx + .const_eval_instance(ParamEnv::reveal_all(), instance, source_info.span) + .unwrap(); let val = crate::constant::codegen_const_value(fx, const_val, ret.layout().ty); ret.write_cvalue(fx, val); } @@ -755,13 +757,6 @@ fn codegen_regular_intrinsic_call<'tcx>( ret.write_cvalue(fx, val); } - sym::ptr_guaranteed_cmp => { - intrinsic_args!(fx, args => (a, b); intrinsic); - - let val = crate::num::codegen_ptr_binop(fx, BinOp::Eq, a, b).load_scalar(fx); - ret.write_cvalue(fx, CValue::by_val(val, fx.layout_of(fx.tcx.types.u8))); - } - sym::caller_location => { intrinsic_args!(fx, args => (); intrinsic); diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs index 79da970a58e..4d55a95aa9d 100644 --- a/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs +++ b/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs @@ -131,7 +131,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( let idx = generic_args[2] .expect_const() - .eval(fx.tcx, ty::ParamEnv::reveal_all(), Some(span)) + .eval(fx.tcx, ty::ParamEnv::reveal_all(), span) .unwrap() .unwrap_branch(); diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs index a4ee3015b8d..345c22394f2 100644 --- a/compiler/rustc_codegen_gcc/src/lib.rs +++ b/compiler/rustc_codegen_gcc/src/lib.rs @@ -19,11 +19,11 @@ #![feature( rustc_private, decl_macro, - associated_type_bounds, never_type, trusted_len, hash_raw_entry )] +#![cfg_attr(bootstrap, feature(associated_type_bounds))] #![allow(broken_intra_doc_links)] #![recursion_limit = "256"] #![warn(rust_2018_idioms)] diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index f89c8c9f836..649ff9df2cc 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -126,17 +126,6 @@ pub unsafe fn create_module<'ll>( let mut target_data_layout = sess.target.data_layout.to_string(); let llvm_version = llvm_util::get_version(); - if llvm_version < (17, 0, 0) { - if sess.target.arch.starts_with("powerpc") { - // LLVM 17 specifies function pointer alignment for ppc: - // https://reviews.llvm.org/D147016 - target_data_layout = target_data_layout - .replace("-Fn32", "") - .replace("-Fi32", "") - .replace("-Fn64", "") - .replace("-Fi64", ""); - } - } if llvm_version < (18, 0, 0) { if sess.target.arch == "x86" || sess.target.arch == "x86_64" { // LLVM 18 adjusts i128 to be 128-bit aligned on x86 variants. @@ -326,6 +315,7 @@ pub unsafe fn create_module<'ll>( // // On the wasm targets it will get hooked up to the "producer" sections // `processed-by` information. + #[allow(clippy::option_env_unwrap)] let rustc_producer = format!("rustc version {}", option_env!("CFG_VERSION").expect("CFG_VERSION")); let name_metadata = llvm::LLVMMDStringInContext( diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs index 133084b7c12..54f4bc06340 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs @@ -85,14 +85,6 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> { let bx = self; - match coverage.kind { - // Marker statements have no effect during codegen, - // so return early and don't create `func_coverage`. - CoverageKind::SpanMarker | CoverageKind::BlockMarker { .. } => return, - // Match exhaustively to ensure that newly-added kinds are classified correctly. - CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. } => {} - } - let Some(function_coverage_info) = bx.tcx.instance_mir(instance.def).function_coverage_info.as_deref() else { @@ -109,7 +101,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> { let Coverage { kind } = coverage; match *kind { CoverageKind::SpanMarker | CoverageKind::BlockMarker { .. } => unreachable!( - "unexpected marker statement {kind:?} should have caused an early return" + "marker statement {kind:?} should have been removed by CleanupPostBorrowck" ), CoverageKind::CounterIncrement { id } => { func_coverage.mark_counter_id_seen(id); diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 467e02d55e3..71b69a94e99 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -1129,7 +1129,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( if name == sym::simd_shuffle_generic { let idx = fn_args[2] .expect_const() - .eval(tcx, ty::ParamEnv::reveal_all(), Some(span)) + .eval(tcx, ty::ParamEnv::reveal_all(), span) .unwrap() .unwrap_branch(); let n = idx.len() as u64; diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index d34c289887e..284bc74d5c4 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -1519,7 +1519,7 @@ extern "C" { #[link(name = "llvm-wrapper", kind = "static")] extern "C" { - pub fn LLVMRustInstallFatalErrorHandler(); + pub fn LLVMRustInstallErrorHandlers(); pub fn LLVMRustDisableSystemDialogsOnCrash(); // Create and destroy contexts. diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index e32c38644aa..c9e62e504ae 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -49,7 +49,7 @@ unsafe fn configure_llvm(sess: &Session) { let mut llvm_c_strs = Vec::with_capacity(n_args + 1); let mut llvm_args = Vec::with_capacity(n_args + 1); - llvm::LLVMRustInstallFatalErrorHandler(); + llvm::LLVMRustInstallErrorHandlers(); // On Windows, an LLVM assertion will open an Abort/Retry/Ignore dialog // box for the purpose of launching a debugger. However, on CI this will // cause it to hang until it times out, which can take several hours. diff --git a/compiler/rustc_codegen_ssa/src/back/command.rs b/compiler/rustc_codegen_ssa/src/back/command.rs index 9b0ba34135c..3a89be89951 100644 --- a/compiler/rustc_codegen_ssa/src/back/command.rs +++ b/compiler/rustc_codegen_ssa/src/back/command.rs @@ -100,12 +100,6 @@ impl Command { Program::Lld(ref p, flavor) => { let mut c = process::Command::new(p); c.arg("-flavor").arg(flavor.as_str()); - if let LldFlavor::Wasm = flavor { - // LLVM expects host-specific formatting for @file - // arguments, but we always generate posix formatted files - // at this time. Indicate as such. - c.arg("--rsp-quoting=posix"); - } c } }; diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index f5e8d5fc92a..c8b8594c0dd 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -785,7 +785,7 @@ fn link_natively<'a>( let mut i = 0; loop { i += 1; - prog = sess.time("run_linker", || exec_linker(sess, &cmd, out_filename, tmpdir)); + prog = sess.time("run_linker", || exec_linker(sess, &cmd, out_filename, flavor, tmpdir)); let Ok(ref output) = prog else { break; }; @@ -1576,6 +1576,7 @@ fn exec_linker( sess: &Session, cmd: &Command, out_filename: &Path, + flavor: LinkerFlavor, tmpdir: &Path, ) -> io::Result<Output> { // When attempting to spawn the linker we run a risk of blowing out the @@ -1584,9 +1585,9 @@ fn exec_linker( // // Here we attempt to handle errors from the OS saying "your list of // arguments is too big" by reinvoking the linker again with an `@`-file - // that contains all the arguments. The theory is that this is then - // accepted on all linkers and the linker will read all its options out of - // there instead of looking at the command line. + // that contains all the arguments (aka 'response' files). + // The theory is that this is then accepted on all linkers and the linker + // will read all its options out of there instead of looking at the command line. if !cmd.very_likely_to_exceed_some_spawn_limit() { match cmd.command().stdout(Stdio::piped()).stderr(Stdio::piped()).spawn() { Ok(child) => { @@ -1606,8 +1607,12 @@ fn exec_linker( let mut args = String::new(); for arg in cmd2.take_args() { args.push_str( - &Escape { arg: arg.to_str().unwrap(), is_like_msvc: sess.target.is_like_msvc } - .to_string(), + &Escape { + arg: arg.to_str().unwrap(), + // LLD also uses MSVC-like parsing for @-files by default when running on windows hosts + is_like_msvc: sess.target.is_like_msvc || (cfg!(windows) && flavor.uses_lld()), + } + .to_string(), ); args.push('\n'); } diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 87b6f0e914c..b19f52182b6 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -81,10 +81,6 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S return library.kind.is_statically_included().then_some(def_id); } - if tcx.intrinsic(def_id).is_some_and(|i| i.must_be_overridden) { - return None; - } - // Only consider nodes that actually have exported symbols. match tcx.def_kind(def_id) { DefKind::Fn | DefKind::Static { .. } => {} diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index 5bd7442822a..fcd7fa9247b 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -19,6 +19,7 @@ use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource, Mutability} use rustc_middle::ty::layout::{IntegerExt, TyAndLayout}; use rustc_middle::ty::{self, ExistentialProjection, ParamEnv, Ty, TyCtxt}; use rustc_middle::ty::{GenericArgKind, GenericArgsRef}; +use rustc_span::DUMMY_SP; use rustc_target::abi::Integer; use smallvec::SmallVec; @@ -704,7 +705,7 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S // avoiding collisions and will make the emitted type names shorter. let hash_short = tcx.with_stable_hashing_context(|mut hcx| { let mut hasher = StableHasher::new(); - let ct = ct.eval(tcx, ty::ParamEnv::reveal_all(), None).unwrap(); + let ct = ct.eval(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP).unwrap(); hcx.while_hashing_spans(false, |hcx| ct.hash_stable(hcx, &mut hasher)); hasher.finish::<Hash64>() }); diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 92f0be541c0..9be8dcf166d 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -4,7 +4,7 @@ #![allow(internal_features)] #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] -#![feature(associated_type_bounds)] +#![cfg_attr(bootstrap, feature(associated_type_bounds))] #![feature(box_patterns)] #![feature(if_let_guard)] #![feature(let_chains)] diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 8fd84d8c053..dcc27a4f0e5 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1721,7 +1721,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn try_llbb(&mut self, bb: mir::BasicBlock) -> Option<Bx::BasicBlock> { match self.cached_llbbs[bb] { CachedLlbb::None => { - // FIXME(eddyb) only name the block if `fewer_names` is `false`. let llbb = Bx::append_block(self.cx, self.llfn, &format!("{bb:?}")); self.cached_llbbs[bb] = CachedLlbb::Some(llbb); Some(llbb) diff --git a/compiler/rustc_codegen_ssa/src/mir/constant.rs b/compiler/rustc_codegen_ssa/src/mir/constant.rs index ff899c50b3d..c6260d35916 100644 --- a/compiler/rustc_codegen_ssa/src/mir/constant.rs +++ b/compiler/rustc_codegen_ssa/src/mir/constant.rs @@ -24,7 +24,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // `MirUsedCollector` visited all required_consts before codegen began, so if we got here // there can be no more constants that fail to evaluate. self.monomorphize(constant.const_) - .eval(self.cx.tcx(), ty::ParamEnv::reveal_all(), Some(constant.span)) + .eval(self.cx.tcx(), ty::ParamEnv::reveal_all(), constant.span) .expect("erroneous constant missed by mono item collection") } @@ -56,11 +56,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { other => span_bug!(constant.span, "{other:#?}"), }; let uv = self.monomorphize(uv); - self.cx.tcx().const_eval_resolve_for_typeck( - ty::ParamEnv::reveal_all(), - uv, - Some(constant.span), - ) + self.cx.tcx().const_eval_resolve_for_typeck(ty::ParamEnv::reveal_all(), uv, constant.span) } /// process constant containing SIMD shuffle indices diff --git a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs index 1d1826d9844..5532ff6e6a5 100644 --- a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs +++ b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs @@ -1,7 +1,6 @@ use super::operand::{OperandRef, OperandValue}; use super::place::PlaceRef; use super::FunctionCx; -use crate::common::IntPredicate; use crate::errors; use crate::errors::InvalidMonomorphization; use crate::meth; @@ -130,7 +129,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | sym::variant_count => { let value = bx .tcx() - .const_eval_instance(ty::ParamEnv::reveal_all(), instance, None) + .const_eval_instance(ty::ParamEnv::reveal_all(), instance, span) .unwrap(); OperandRef::from_const(bx, value, ret_ty).immediate_or_packed_pair(bx) } @@ -456,12 +455,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { return Ok(()); } - sym::ptr_guaranteed_cmp => { - let a = args[0].immediate(); - let b = args[1].immediate(); - bx.icmp(IntPredicate::IntEQ, a, b) - } - sym::ptr_offset_from | sym::ptr_offset_from_unsigned => { let ty = fn_args.type_at(0); let pointee_size = bx.layout_of(ty).size; diff --git a/compiler/rustc_codegen_ssa/src/mono_item.rs b/compiler/rustc_codegen_ssa/src/mono_item.rs index 7b7cdae0ed6..df564f705bc 100644 --- a/compiler/rustc_codegen_ssa/src/mono_item.rs +++ b/compiler/rustc_codegen_ssa/src/mono_item.rs @@ -2,6 +2,7 @@ use crate::base; use crate::common; use crate::traits::*; use rustc_hir as hir; +use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::mir::mono::MonoItem; use rustc_middle::mir::mono::{Linkage, Visibility}; use rustc_middle::ty; @@ -40,23 +41,34 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> { .iter() .map(|(op, op_sp)| match *op { hir::InlineAsmOperand::Const { ref anon_const } => { - let const_value = cx - .tcx() - .const_eval_poly(anon_const.def_id.to_def_id()) - .unwrap_or_else(|_| { - span_bug!(*op_sp, "asm const cannot be resolved") - }); - let ty = cx - .tcx() - .typeck_body(anon_const.body) - .node_type(anon_const.hir_id); - let string = common::asm_const_to_str( - cx.tcx(), - *op_sp, - const_value, - cx.layout_of(ty), - ); - GlobalAsmOperandRef::Const { string } + match cx.tcx().const_eval_poly(anon_const.def_id.to_def_id()) { + Ok(const_value) => { + let ty = cx + .tcx() + .typeck_body(anon_const.body) + .node_type(anon_const.hir_id); + let string = common::asm_const_to_str( + cx.tcx(), + *op_sp, + const_value, + cx.layout_of(ty), + ); + GlobalAsmOperandRef::Const { string } + } + Err(ErrorHandled::Reported { .. }) => { + // An error has already been reported and + // compilation is guaranteed to fail if execution + // hits this path. So an empty string instead of + // a stringified constant value will suffice. + GlobalAsmOperandRef::Const { string: String::new() } + } + Err(ErrorHandled::TooGeneric(_)) => { + span_bug!( + *op_sp, + "asm const cannot be resolved; too generic" + ) + } + } } hir::InlineAsmOperand::SymFn { ref anon_const } => { let ty = cx diff --git a/compiler/rustc_codegen_ssa/src/traits/backend.rs b/compiler/rustc_codegen_ssa/src/traits/backend.rs index e6d42c596d2..e8b9490d401 100644 --- a/compiler/rustc_codegen_ssa/src/traits/backend.rs +++ b/compiler/rustc_codegen_ssa/src/traits/backend.rs @@ -21,7 +21,6 @@ use rustc_session::{ }; use rustc_span::symbol::Symbol; use rustc_target::abi::call::FnAbi; -use rustc_target::spec::Target; use std::fmt; @@ -70,12 +69,6 @@ pub trait CodegenBackend { fn print_passes(&self) {} fn print_version(&self) {} - /// If this plugin provides additional builtin targets, provide the one enabled by the options here. - /// Be careful: this is called *before* init() is called. - fn target_override(&self, _opts: &config::Options) -> Option<Target> { - None - } - /// The metadata loader used to load rlib and dylib metadata. /// /// Alternative codegen backends may want to use different rlib or dylib formats than the diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 09e9cc4b35d..3283bcc4c45 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -826,7 +826,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { for &const_ in &body.required_consts { let c = self .instantiate_from_current_frame_and_normalize_erasing_regions(const_.const_)?; - c.eval(*self.tcx, self.param_env, Some(const_.span)).map_err(|err| { + c.eval(*self.tcx, self.param_env, const_.span).map_err(|err| { err.emit_note(*self.tcx); err })?; @@ -1034,8 +1034,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ) -> InterpResult<'tcx> { trace!("{:?} is now live", local); - // We avoid `ty.is_trivially_sized` since that (a) cannot assume WF, so it recurses through - // all fields of a tuple, and (b) does something expensive for ADTs. + // We avoid `ty.is_trivially_sized` since that does something expensive for ADTs. fn is_very_trivially_sized(ty: Ty<'_>) -> bool { match ty.kind() { ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) @@ -1054,9 +1053,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Never - | ty::Error(_) => true, + | ty::Error(_) + | ty::Dynamic(_, _, ty::DynStar) => true, - ty::Str | ty::Slice(_) | ty::Dynamic(..) | ty::Foreign(..) => false, + ty::Str | ty::Slice(_) | ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => false, ty::Tuple(tys) => tys.last().iter().all(|ty| is_very_trivially_sized(**ty)), @@ -1174,7 +1174,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { pub fn eval_mir_constant( &self, val: &mir::Const<'tcx>, - span: Option<Span>, + span: Span, layout: Option<TyAndLayout<'tcx>>, ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> { M::eval_mir_constant(self, *val, span, layout, |ecx, val, span, layout| { diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index 17bb59aae8f..58eaef65e55 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -111,6 +111,8 @@ fn intern_as_new_static<'tcx>( feed.generics_of(tcx.generics_of(static_id).clone()); feed.def_ident_span(tcx.def_ident_span(static_id)); feed.explicit_predicates_of(tcx.explicit_predicates_of(static_id)); + + feed.feed_hir() } /// How a constant value should be interned. @@ -291,7 +293,9 @@ pub fn intern_const_alloc_for_constprop< return Ok(()); } // Move allocation to `tcx`. - for _ in intern_shallow(ecx, alloc_id, Mutability::Not).map_err(|()| err_ub!(DeadLocal))? { + if let Some(_) = + (intern_shallow(ecx, alloc_id, Mutability::Not).map_err(|()| err_ub!(DeadLocal))?).next() + { // We are not doing recursive interning, so we don't currently support provenance. // (If this assertion ever triggers, we should just implement a // proper recursive interning loop -- or just call `intern_const_alloc_recursive`. diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index b68bfb4211d..748c7dce5a3 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -153,9 +153,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { sym::type_name => Ty::new_static_str(self.tcx.tcx), _ => bug!(), }; - let val = self.ctfe_query(|tcx| { - tcx.const_eval_global_id(self.param_env, gid, Some(tcx.span)) - })?; + let val = + self.ctfe_query(|tcx| tcx.const_eval_global_id(self.param_env, gid, tcx.span))?; let val = self.const_val_to_op(val, ty, Some(dest.layout))?; self.copy_op(&val, dest)?; } diff --git a/compiler/rustc_const_eval/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs index afc4a80c283..827d8fd9417 100644 --- a/compiler/rustc_const_eval/src/interpret/machine.rs +++ b/compiler/rustc_const_eval/src/interpret/machine.rs @@ -525,7 +525,7 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized { fn eval_mir_constant<F>( ecx: &InterpCx<'mir, 'tcx, Self>, val: mir::Const<'tcx>, - span: Option<Span>, + span: Span, layout: Option<TyAndLayout<'tcx>>, eval: F, ) -> InterpResult<'tcx, OpTy<'tcx, Self::Provenance>> @@ -533,7 +533,7 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized { F: Fn( &InterpCx<'mir, 'tcx, Self>, mir::Const<'tcx>, - Option<Span>, + Span, Option<TyAndLayout<'tcx>>, ) -> InterpResult<'tcx, OpTy<'tcx, Self::Provenance>>, { diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 86aad2e1642..9b1d9cf932b 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -949,6 +949,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { /// Runs the close in "validation" mode, which means the machine's memory read hooks will be /// suppressed. Needless to say, this must only be set with great care! Cannot be nested. pub(super) fn run_for_validation<R>(&self, f: impl FnOnce() -> R) -> R { + // This deliberately uses `==` on `bool` to follow the pattern + // `assert!(val.replace(new) == old)`. assert!( self.memory.validation_in_progress.replace(true) == false, "`validation_in_progress` was already set" @@ -1157,11 +1159,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { }; // Side-step AllocRef and directly access the underlying bytes more efficiently. - // (We are staying inside the bounds here so all is good.) + // (We are staying inside the bounds here and all bytes do get overwritten so all is good.) let alloc_id = alloc_ref.alloc_id; let bytes = alloc_ref .alloc - .get_bytes_mut(&alloc_ref.tcx, alloc_ref.range) + .get_bytes_unchecked_for_overwrite(&alloc_ref.tcx, alloc_ref.range) .map_err(move |e| e.to_interp_error(alloc_id))?; // `zip` would stop when the first iterator ends; we want to definitely // cover all of `bytes`. @@ -1182,6 +1184,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { self.mem_copy_repeatedly(src, dest, size, 1, nonoverlapping) } + /// Performs `num_copies` many copies of `size` many bytes from `src` to `dest + i*size` (where + /// `i` is the index of the copy). + /// + /// Either `nonoverlapping` must be true or `num_copies` must be 1; doing repeated copies that + /// may overlap is not supported. pub fn mem_copy_repeatedly( &mut self, src: Pointer<Option<M::Provenance>>, @@ -1243,8 +1250,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { (dest_alloc_id, dest_prov), dest_range, )?; + // Yes we do overwrite all bytes in `dest_bytes`. let dest_bytes = dest_alloc - .get_bytes_mut_ptr(&tcx, dest_range) + .get_bytes_unchecked_for_overwrite_ptr(&tcx, dest_range) .map_err(|e| e.to_interp_error(dest_alloc_id))? .as_mut_ptr(); @@ -1278,6 +1286,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } } } + if num_copies > 1 { + assert!(nonoverlapping, "multi-copy only supported in non-overlapping mode"); + } let size_in_bytes = size.bytes_usize(); // For particularly large arrays (where this is perf-sensitive) it's common that @@ -1290,6 +1301,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } else if src_alloc_id == dest_alloc_id { let mut dest_ptr = dest_bytes; for _ in 0..num_copies { + // Here we rely on `src` and `dest` being non-overlapping if there is more than + // one copy. ptr::copy(src_bytes, dest_ptr, size_in_bytes); dest_ptr = dest_ptr.add(size_in_bytes); } diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index e49067a2f00..dbc6a317640 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -741,7 +741,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // * During ConstProp, with `TooGeneric` or since the `required_consts` were not all // checked yet. // * During CTFE, since promoteds in `const`/`static` initializer bodies can fail. - self.eval_mir_constant(&c, Some(constant.span), layout)? + self.eval_mir_constant(&c, constant.span, layout)? } }; trace!("{:?}: {:?}", mir_op, op); diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index 15720f25c5c..e87e60f62dc 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -99,7 +99,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { #[allow(rustc::untranslatable_diagnostic)] fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, _: Span) -> Diag<'tcx> { let FnCallNonConst { caller, callee, args, span, call_source, feature } = *self; - let ConstCx { tcx, param_env, .. } = *ccx; + let ConstCx { tcx, param_env, body, .. } = *ccx; let diag_trait = |err, self_ty: Ty<'_>, trait_id| { let trait_ref = TraitRef::from_method(tcx, trait_id, args); @@ -297,10 +297,12 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { ccx.const_kind(), )); - if let Some(feature) = feature - && ccx.tcx.sess.is_nightly_build() - { - err.help(format!("add `#![feature({feature})]` to the crate attributes to enable",)); + if let Some(feature) = feature { + ccx.tcx.disabled_nightly_features( + &mut err, + body.source.def_id().as_local().map(|local| ccx.tcx.local_def_id_to_hir_id(local)), + [(String::new(), feature)], + ); } if let ConstContext::Static(_) = ccx.const_kind() { diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index f26c8f8592d..4bc49f90607 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -4,6 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::bit_set::BitSet; use rustc_index::IndexVec; use rustc_infer::traits::Reveal; +use rustc_middle::mir::coverage::CoverageKind; use rustc_middle::mir::interpret::Scalar; use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; @@ -341,15 +342,25 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> { // FIXME(JakobDegen) The validator should check that `self.mir_phase < // DropsLowered`. However, this causes ICEs with generation of drop shims, which // seem to fail to set their `MirPhase` correctly. - if matches!(kind, RetagKind::Raw | RetagKind::TwoPhase) { + if matches!(kind, RetagKind::TwoPhase) { self.fail(location, format!("explicit `{kind:?}` is forbidden")); } } + StatementKind::Coverage(coverage) => { + let kind = &coverage.kind; + if self.mir_phase >= MirPhase::Analysis(AnalysisPhase::PostCleanup) + && let CoverageKind::BlockMarker { .. } | CoverageKind::SpanMarker { .. } = kind + { + self.fail( + location, + format!("{kind:?} should have been removed after analysis"), + ); + } + } StatementKind::Assign(..) | StatementKind::StorageLive(_) | StatementKind::StorageDead(_) | StatementKind::Intrinsic(_) - | StatementKind::Coverage(_) | StatementKind::ConstEvalCounter | StatementKind::PlaceMention(..) | StatementKind::Nop => {} @@ -1272,7 +1283,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { // FIXME(JakobDegen) The validator should check that `self.mir_phase < // DropsLowered`. However, this causes ICEs with generation of drop shims, which // seem to fail to set their `MirPhase` correctly. - if matches!(kind, RetagKind::Raw | RetagKind::TwoPhase) { + if matches!(kind, RetagKind::TwoPhase) { self.fail(location, format!("explicit `{kind:?}` is forbidden")); } } diff --git a/compiler/rustc_data_structures/src/memmap.rs b/compiler/rustc_data_structures/src/memmap.rs index 30403a61442..c7f66b2fee8 100644 --- a/compiler/rustc_data_structures/src/memmap.rs +++ b/compiler/rustc_data_structures/src/memmap.rs @@ -18,8 +18,14 @@ impl Mmap { /// However in practice most callers do not ensure this, so uses of this function are likely unsound. #[inline] pub unsafe fn map(file: File) -> io::Result<Self> { - // Safety: the caller must ensure that this is safe. - unsafe { memmap2::Mmap::map(&file).map(Mmap) } + // By default, memmap2 creates shared mappings, implying that we could see updates to the + // file through the mapping. That would violate our precondition; so by requesting a + // map_copy_read_only we do not lose anything. + // This mapping mode also improves our support for filesystems such as cacheless virtiofs. + // For more details see https://github.com/rust-lang/rust/issues/122262 + // + // SAFETY: The caller must ensure that this is safe. + unsafe { memmap2::MmapOptions::new().map_copy_read_only(&file).map(Mmap) } } } diff --git a/compiler/rustc_data_structures/src/sync.rs b/compiler/rustc_data_structures/src/sync.rs index 32202ac3ede..eab6d8168ca 100644 --- a/compiler/rustc_data_structures/src/sync.rs +++ b/compiler/rustc_data_structures/src/sync.rs @@ -20,6 +20,7 @@ //! | ----------------------- | ------------------- | ------------------------------- | //! | `Lrc<T>` | `rc::Rc<T>` | `sync::Arc<T>` | //! |` Weak<T>` | `rc::Weak<T>` | `sync::Weak<T>` | +//! | `LRef<'a, T>` [^2] | `&'a mut T` | `&'a T` | //! | | | | //! | `AtomicBool` | `Cell<bool>` | `atomic::AtomicBool` | //! | `AtomicU32` | `Cell<u32>` | `atomic::AtomicU32` | @@ -38,7 +39,7 @@ //! of a `RefCell`. This is appropriate when interior mutability is not //! required. //! -//! [^2] `MTLockRef` is a typedef. +//! [^2] `MTRef`, `MTLockRef` are type aliases. pub use crate::marker::*; use std::collections::HashMap; @@ -208,7 +209,7 @@ cfg_match! { use std::cell::RefCell as InnerRwLock; - pub type MTLockRef<'a, T> = &'a mut MTLock<T>; + pub type LRef<'a, T> = &'a mut T; #[derive(Debug, Default)] pub struct MTLock<T>(T); @@ -274,7 +275,7 @@ cfg_match! { pub use std::sync::Arc as Lrc; pub use std::sync::Weak as Weak; - pub type MTLockRef<'a, T> = &'a MTLock<T>; + pub type LRef<'a, T> = &'a T; #[derive(Debug, Default)] pub struct MTLock<T>(Lock<T>); @@ -314,6 +315,8 @@ cfg_match! { } } +pub type MTLockRef<'a, T> = LRef<'a, MTLock<T>>; + #[derive(Default)] #[cfg_attr(parallel_compiler, repr(align(64)))] pub struct CacheAligned<T>(pub T); diff --git a/compiler/rustc_data_structures/src/sync/lock.rs b/compiler/rustc_data_structures/src/sync/lock.rs index 040a8aa6b63..756984642c7 100644 --- a/compiler/rustc_data_structures/src/sync/lock.rs +++ b/compiler/rustc_data_structures/src/sync/lock.rs @@ -189,6 +189,7 @@ mod no_sync { use super::Mode; use std::cell::RefCell; + #[doc(no_inline)] pub use std::cell::RefMut as LockGuard; pub struct Lock<T>(RefCell<T>); diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 938f9f0beaa..716e31080dd 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -890,7 +890,7 @@ pub fn version_at_macro_invocation( let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend=")); let opts = config::Options::default(); let sysroot = filesearch::materialize_sysroot(opts.maybe_sysroot.clone()); - let target = config::build_target_config(early_dcx, &opts, None, &sysroot); + let target = config::build_target_config(early_dcx, &opts, &sysroot); get_codegen_backend(early_dcx, &sysroot, backend_name, &target).print_version(); } @@ -1100,7 +1100,7 @@ pub fn describe_flag_categories(early_dcx: &EarlyDiagCtxt, matches: &Matches) -> let opts = config::Options::default(); let sysroot = filesearch::materialize_sysroot(opts.maybe_sysroot.clone()); - let target = config::build_target_config(early_dcx, &opts, None, &sysroot); + let target = config::build_target_config(early_dcx, &opts, &sysroot); get_codegen_backend(early_dcx, &sysroot, backend_name, &target).print_passes(); return true; diff --git a/compiler/rustc_driver_impl/src/signal_handler.rs b/compiler/rustc_driver_impl/src/signal_handler.rs index deca1082221..441219eec90 100644 --- a/compiler/rustc_driver_impl/src/signal_handler.rs +++ b/compiler/rustc_driver_impl/src/signal_handler.rs @@ -1,6 +1,7 @@ //! Signal handler for rustc //! Primarily used to extract a backtrace from stack overflow +use rustc_interface::util::{DEFAULT_STACK_SIZE, STACK_SIZE}; use std::alloc::{alloc, Layout}; use std::{fmt, mem, ptr}; @@ -100,7 +101,10 @@ extern "C" fn print_stack_trace(_: libc::c_int) { written += 1; } raw_errln!("note: we would appreciate a report at https://github.com/rust-lang/rust"); - written += 1; + // get the current stack size WITHOUT blocking and double it + let new_size = STACK_SIZE.get().copied().unwrap_or(DEFAULT_STACK_SIZE) * 2; + raw_errln!("help: you can increase rustc's stack size by setting RUST_MIN_STACK={new_size}"); + written += 2; if written > 24 { // We probably just scrolled the earlier "we got SIGSEGV" message off the terminal raw_errln!("note: backtrace dumped due to SIGSEGV! resuming signal"); diff --git a/compiler/rustc_error_codes/src/error_codes/E0719.md b/compiler/rustc_error_codes/src/error_codes/E0719.md index 057a0b1645c..cd981db1058 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0719.md +++ b/compiler/rustc_error_codes/src/error_codes/E0719.md @@ -3,8 +3,6 @@ An associated type value was specified more than once. Erroneous code example: ```compile_fail,E0719 -#![feature(associated_type_bounds)] - trait FooTrait {} trait BarTrait {} @@ -19,8 +17,6 @@ specify the associated type with the new trait. Corrected example: ``` -#![feature(associated_type_bounds)] - trait FooTrait {} trait BarTrait {} trait FooBarTrait: FooTrait + BarTrait {} diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 4f033e3fefa..fceccb7e9b6 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1638,6 +1638,27 @@ impl HumanEmitter { *style, ); } + if let Some(line) = annotated_file.lines.get(line_idx) { + for ann in &line.annotations { + if let AnnotationType::MultilineStart(pos) = ann.annotation_type + { + // In the case where we have elided the entire start of the + // multispan because those lines were empty, we still need + // to draw the `|`s across the `...`. + draw_multiline_line( + &mut buffer, + last_buffer_line_num, + width_offset, + pos, + if ann.is_primary { + Style::UnderlinePrimary + } else { + Style::UnderlineSecondary + }, + ); + } + } + } } else if line_idx_delta == 2 { let unannotated_line = annotated_file .file @@ -1665,6 +1686,24 @@ impl HumanEmitter { *style, ); } + if let Some(line) = annotated_file.lines.get(line_idx) { + for ann in &line.annotations { + if let AnnotationType::MultilineStart(pos) = ann.annotation_type + { + draw_multiline_line( + &mut buffer, + last_buffer_line_num, + width_offset, + pos, + if ann.is_primary { + Style::UnderlinePrimary + } else { + Style::UnderlineSecondary + }, + ); + } + } + } } } @@ -2417,7 +2456,15 @@ impl FileWithAnnotatedLines { // the beginning doesn't have an underline, but the current logic seems to be // working correctly. let middle = min(ann.line_start + 4, ann.line_end); - for line in ann.line_start + 1..middle { + // We'll show up to 4 lines past the beginning of the multispan start. + // We will *not* include the tail of lines that are only whitespace. + let until = (ann.line_start..middle) + .rev() + .filter_map(|line| file.get_line(line - 1).map(|s| (line + 1, s))) + .find(|(_, s)| !s.trim().is_empty()) + .map(|(line, _)| line) + .unwrap_or(ann.line_start); + for line in ann.line_start + 1..until { // Every `|` that joins the beginning of the span (`___^`) to the end (`|__^`). add_annotation_to_file(&mut output, file.clone(), line, ann.as_line()); } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 723f13dbe8d..238bc63ec58 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -7,7 +7,6 @@ #![allow(internal_features)] #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] -#![cfg_attr(bootstrap, feature(min_specialization))] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(rust_logo)] #![feature(array_windows)] diff --git a/compiler/rustc_expand/messages.ftl b/compiler/rustc_expand/messages.ftl index 1f0488130b2..fdd1a87cae8 100644 --- a/compiler/rustc_expand/messages.ftl +++ b/compiler/rustc_expand/messages.ftl @@ -33,6 +33,9 @@ expand_duplicate_matcher_binding = duplicate matcher binding expand_expected_comma_in_list = expected token: `,` +expand_expected_paren_or_brace = + expected `(` or `{"{"}`, found `{$token}` + expand_explain_doc_comment_inner = inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index e71047f94fa..30559871b4e 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -1,6 +1,6 @@ use crate::base::ExtCtxt; use rustc_ast::ptr::P; -use rustc_ast::{self as ast, AttrVec, BlockCheckMode, Expr, LocalKind, PatKind, UnOp}; +use rustc_ast::{self as ast, AttrVec, BlockCheckMode, Expr, LocalKind, MatchKind, PatKind, UnOp}; use rustc_ast::{attr, token, util::literal}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident, Symbol}; @@ -524,7 +524,7 @@ impl<'a> ExtCtxt<'a> { } pub fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: ThinVec<ast::Arm>) -> P<Expr> { - self.expr(span, ast::ExprKind::Match(arg, arms)) + self.expr(span, ast::ExprKind::Match(arg, arms, MatchKind::Prefix)) } pub fn expr_if( diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index fe901603c73..21ce5e1d81e 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -448,3 +448,11 @@ pub struct InvalidFragmentSpecifier { pub fragment: Ident, pub help: String, } + +#[derive(Diagnostic)] +#[diag(expand_expected_paren_or_brace)] +pub struct ExpectedParenOrBrace<'a> { + #[primary_span] + pub span: Span, + pub token: Cow<'a, str>, +} diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index e550f7242c3..c9a3aeedd02 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -1,7 +1,7 @@ #![doc(rust_logo)] #![feature(rustdoc_internals)] #![feature(array_windows)] -#![feature(associated_type_bounds)] +#![cfg_attr(bootstrap, feature(associated_type_bounds))] #![feature(associated_type_defaults)] #![feature(if_let_guard)] #![feature(let_chains)] @@ -12,6 +12,7 @@ #![feature(proc_macro_internals)] #![feature(proc_macro_span)] #![feature(try_blocks)] +#![feature(yeet_expr)] #![allow(rustc::diagnostic_outside_of_impl)] #![allow(internal_features)] diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index ac5136539c3..a31be05ccc4 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -392,12 +392,7 @@ pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize { #[derive(Debug, Clone)] pub(crate) enum NamedMatch { MatchedSeq(Vec<NamedMatch>), - - // A metavar match of type `tt`. - MatchedTokenTree(rustc_ast::tokenstream::TokenTree), - - // A metavar match of any type other than `tt`. - MatchedNonterminal(Lrc<(Nonterminal, rustc_span::Span)>), + MatchedSingle(ParseNtResult<Lrc<(Nonterminal, Span)>>), } /// Performs a token equality check, ignoring syntax context (that is, an unhygienic comparison) @@ -691,11 +686,11 @@ impl TtParser { } Ok(nt) => nt, }; - let m = match nt { - ParseNtResult::Nt(nt) => MatchedNonterminal(Lrc::new((nt, span))), - ParseNtResult::Tt(tt) => MatchedTokenTree(tt), - }; - mp.push_match(next_metavar, seq_depth, m); + mp.push_match( + next_metavar, + seq_depth, + MatchedSingle(nt.map_nt(|nt| (Lrc::new((nt, span))))), + ); mp.idx += 1; } else { unreachable!() diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 3f29d7f7465..7099f1b0d35 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -5,7 +5,7 @@ use crate::mbe; use crate::mbe::diagnostics::{annotate_doc_comment, parse_failure_msg}; use crate::mbe::macro_check; use crate::mbe::macro_parser::{Error, ErrorReported, Failure, Success, TtParser}; -use crate::mbe::macro_parser::{MatchedSeq, MatchedTokenTree, MatcherLoc}; +use crate::mbe::macro_parser::{MatcherLoc, NamedMatch::*}; use crate::mbe::transcribe::transcribe; use ast::token::IdentIsRaw; @@ -22,7 +22,7 @@ use rustc_lint_defs::builtin::{ RUST_2021_INCOMPATIBLE_OR_PATTERNS, SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, }; use rustc_lint_defs::BuiltinLintDiag; -use rustc_parse::parser::{Parser, Recovery}; +use rustc_parse::parser::{ParseNtResult, Parser, Recovery}; use rustc_session::parse::ParseSess; use rustc_session::Session; use rustc_span::edition::Edition; @@ -479,7 +479,7 @@ pub fn compile_declarative_macro( MatchedSeq(s) => s .iter() .map(|m| { - if let MatchedTokenTree(tt) = m { + if let MatchedSingle(ParseNtResult::Tt(tt)) = m { let tt = mbe::quoted::parse( &TokenStream::new(vec![tt.clone()]), true, @@ -505,7 +505,7 @@ pub fn compile_declarative_macro( MatchedSeq(s) => s .iter() .map(|m| { - if let MatchedTokenTree(tt) = m { + if let MatchedSingle(ParseNtResult::Tt(tt)) = m { return mbe::quoted::parse( &TokenStream::new(vec![tt.clone()]), false, diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index 5fd3716743b..06c1612ddba 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -194,9 +194,11 @@ fn parse_tree<'a>( } Delimiter::Parenthesis => {} _ => { - let tok = pprust::token_kind_to_string(&token::OpenDelim(delim)); - let msg = format!("expected `(` or `{{`, found `{tok}`"); - sess.dcx().span_err(delim_span.entire(), msg); + let token = pprust::token_kind_to_string(&token::OpenDelim(delim)); + sess.dcx().emit_err(errors::ExpectedParenOrBrace { + span: delim_span.entire(), + token, + }); } } } diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 8fcd468e34b..dad83984c8b 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -3,14 +3,14 @@ use crate::errors::{ CountRepetitionMisplaced, MetaVarExprUnrecognizedVar, MetaVarsDifSeqMatchers, MustRepeatOnce, NoSyntaxVarsExprRepeat, VarStillRepeating, }; -use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, MatchedTokenTree, NamedMatch}; +use crate::mbe::macro_parser::{NamedMatch, NamedMatch::*}; use crate::mbe::{self, KleeneOp, MetaVarExpr}; use rustc_ast::mut_visit::{self, MutVisitor}; use rustc_ast::token::{self, Delimiter, Token, TokenKind}; use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree}; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::Diag; -use rustc_errors::{pluralize, PResult}; +use rustc_errors::{pluralize, Diag, PResult}; +use rustc_parse::parser::ParseNtResult; use rustc_span::hygiene::{LocalExpnId, Transparency}; use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent}; use rustc_span::{with_metavar_spans, Span, SyntaxContext}; @@ -250,26 +250,25 @@ pub(super) fn transcribe<'a>( // the meta-var. let ident = MacroRulesNormalizedIdent::new(original_ident); if let Some(cur_matched) = lookup_cur_matched(ident, interp, &repeats) { - match cur_matched { - MatchedTokenTree(tt) => { + let tt = match cur_matched { + MatchedSingle(ParseNtResult::Tt(tt)) => { // `tt`s are emitted into the output stream directly as "raw tokens", // without wrapping them into groups. - let tt = maybe_use_metavar_location(cx, &stack, sp, tt, &mut marker); - result.push(tt); + maybe_use_metavar_location(cx, &stack, sp, tt, &mut marker) } - MatchedNonterminal(nt) => { + MatchedSingle(ParseNtResult::Nt(nt)) => { // Other variables are emitted into the output stream as groups with // `Delimiter::Invisible` to maintain parsing priorities. // `Interpolated` is currently used for such groups in rustc parser. marker.visit_span(&mut sp); - result - .push(TokenTree::token_alone(token::Interpolated(nt.clone()), sp)); + TokenTree::token_alone(token::Interpolated(nt.clone()), sp) } MatchedSeq(..) => { // We were unable to descend far enough. This is an error. return Err(cx.dcx().create_err(VarStillRepeating { span: sp, ident })); } - } + }; + result.push(tt) } else { // If we aren't able to match the meta-var, we push it back into the result but // with modified syntax context. (I believe this supports nested macros). @@ -424,7 +423,7 @@ fn lookup_cur_matched<'a>( interpolations.get(&ident).map(|mut matched| { for &(idx, _) in repeats { match matched { - MatchedTokenTree(_) | MatchedNonterminal(_) => break, + MatchedSingle(_) => break, MatchedSeq(ads) => matched = ads.get(idx).unwrap(), } } @@ -514,7 +513,7 @@ fn lockstep_iter_size( let name = MacroRulesNormalizedIdent::new(*name); match lookup_cur_matched(name, interpolations, repeats) { Some(matched) => match matched { - MatchedTokenTree(_) | MatchedNonterminal(_) => LockstepIterSize::Unconstrained, + MatchedSingle(_) => LockstepIterSize::Unconstrained, MatchedSeq(ads) => LockstepIterSize::Constraint(ads.len(), name), }, _ => LockstepIterSize::Unconstrained, @@ -557,7 +556,7 @@ fn count_repetitions<'a>( // (or at the top-level of `matched` if no depth is given). fn count<'a>(depth_curr: usize, depth_max: usize, matched: &NamedMatch) -> PResult<'a, usize> { match matched { - MatchedTokenTree(_) | MatchedNonterminal(_) => Ok(1), + MatchedSingle(_) => Ok(1), MatchedSeq(named_matches) => { if depth_curr == depth_max { Ok(named_matches.len()) @@ -571,7 +570,7 @@ fn count_repetitions<'a>( /// Maximum depth fn depth(counter: usize, matched: &NamedMatch) -> usize { match matched { - MatchedTokenTree(_) | MatchedNonterminal(_) => counter, + MatchedSingle(_) => counter, MatchedSeq(named_matches) => { let rslt = counter + 1; if let Some(elem) = named_matches.first() { depth(rslt, elem) } else { rslt } @@ -599,7 +598,7 @@ fn count_repetitions<'a>( } } - if let MatchedTokenTree(_) | MatchedNonterminal(_) = matched { + if let MatchedSingle(_) = matched { return Err(cx.dcx().create_err(CountRepetitionMisplaced { span: sp.entire() })); } diff --git a/compiler/rustc_expand/src/module.rs b/compiler/rustc_expand/src/module.rs index 8a68b39e496..c8983619e70 100644 --- a/compiler/rustc_expand/src/module.rs +++ b/compiler/rustc_expand/src/module.rs @@ -62,7 +62,7 @@ pub(crate) fn parse_external_mod( // Ensure file paths are acyclic. if let Some(pos) = module.file_path_stack.iter().position(|p| p == &mp.file_path) { - Err(ModError::CircularInclusion(module.file_path_stack[pos..].to_vec()))?; + do yeet ModError::CircularInclusion(module.file_path_stack[pos..].to_vec()); } // Actually parse the external file as a module. diff --git a/compiler/rustc_expand/src/tests.rs b/compiler/rustc_expand/src/tests.rs index a3510dc9bff..2b0b58eb1d9 100644 --- a/compiler/rustc_expand/src/tests.rs +++ b/compiler/rustc_expand/src/tests.rs @@ -276,8 +276,7 @@ error: foo | 2 | fn foo() { | __________^ -3 | | -4 | | +... | 5 | | } | |___^ test diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 7e5197f16f9..a83f9f56beb 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -59,6 +59,8 @@ declare_features! ( (accepted, asm_sym, "1.66.0", Some(93333)), /// Allows the definition of associated constants in `trait` or `impl` blocks. (accepted, associated_consts, "1.20.0", Some(29646)), + /// Allows the user of associated type bounds. + (accepted, associated_type_bounds, "CURRENT_RUSTC_VERSION", Some(52662)), /// Allows using associated `type`s in `trait`s. (accepted, associated_types, "1.0.0", None), /// Allows free and inherent `async fn`s, `async` blocks, and `<expr>.await` expressions. @@ -85,7 +87,7 @@ declare_features! ( /// Enables `#[cfg(panic = "...")]` config key. (accepted, cfg_panic, "1.60.0", Some(77443)), /// Allows `cfg(target_abi = "...")`. - (accepted, cfg_target_abi, "CURRENT_RUSTC_VERSION", Some(80970)), + (accepted, cfg_target_abi, "1.78.0", Some(80970)), /// Allows `cfg(target_feature = "...")`. (accepted, cfg_target_feature, "1.27.0", Some(29717)), /// Allows `cfg(target_vendor = "...")`. @@ -147,7 +149,7 @@ declare_features! ( /// Allows the use of destructuring assignments. (accepted, destructuring_assignment, "1.59.0", Some(71126)), /// Allows using the `#[diagnostic]` attribute tool namespace - (accepted, diagnostic_namespace, "CURRENT_RUSTC_VERSION", Some(111996)), + (accepted, diagnostic_namespace, "1.78.0", Some(111996)), /// Allows `#[doc(alias = "...")]`. (accepted, doc_alias, "1.48.0", Some(50146)), /// Allows `..` in tuple (struct) patterns. @@ -203,6 +205,8 @@ declare_features! ( (accepted, impl_header_lifetime_elision, "1.31.0", Some(15872)), /// Allows referencing `Self` and projections in impl-trait. (accepted, impl_trait_projections, "1.74.0", Some(103532)), + /// Allows using imported `main` function + (accepted, imported_main, "CURRENT_RUSTC_VERSION", Some(28937)), /// Allows using `a..=b` and `..=b` as inclusive range syntaxes. (accepted, inclusive_range_syntax, "1.26.0", Some(28237)), /// Allows inferring outlives requirements (RFC 2093). diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 1f77484d65c..22cf50fce7f 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -150,16 +150,6 @@ pub enum AttributeDuplicates { FutureWarnPreceding, } -/// A convenience macro to deal with `$($expr)?`. -macro_rules! or_default { - ($default:expr,) => { - $default - }; - ($default:expr, $next:expr) => { - $next - }; -} - /// A convenience macro for constructing attribute templates. /// E.g., `template!(Word, List: "description")` means that the attribute /// supports forms `#[attr]` and `#[attr(description)]`. @@ -181,10 +171,10 @@ macro_rules! template { } macro_rules! ungated { - ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr $(, @only_local: $only_local:expr)? $(,)?) => { + ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr $(,)?) => { BuiltinAttribute { name: sym::$attr, - only_local: or_default!(false, $($only_local)?), + encode_cross_crate: $encode_cross_crate, type_: $typ, template: $tpl, gate: Ungated, @@ -194,20 +184,20 @@ macro_rules! ungated { } macro_rules! gated { - ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr $(, @only_local: $only_local:expr)?, $gate:ident, $msg:expr $(,)?) => { + ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $gate:ident, $msg:expr $(,)?) => { BuiltinAttribute { name: sym::$attr, - only_local: or_default!(false, $($only_local)?), + encode_cross_crate: $encode_cross_crate, type_: $typ, template: $tpl, duplicates: $duplicates, gate: Gated(Stability::Unstable, sym::$gate, $msg, cfg_fn!($gate)), } }; - ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr $(, @only_local: $only_local:expr)?, $msg:expr $(,)?) => { + ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $msg:expr $(,)?) => { BuiltinAttribute { name: sym::$attr, - only_local: or_default!(false, $($only_local)?), + encode_cross_crate: $encode_cross_crate, type_: $typ, template: $tpl, duplicates: $duplicates, @@ -217,13 +207,13 @@ macro_rules! gated { } macro_rules! rustc_attr { - (TEST, $attr:ident, $typ:expr, $tpl:expr, $duplicate:expr $(, @only_local: $only_local:expr)? $(,)?) => { + (TEST, $attr:ident, $typ:expr, $tpl:expr, $duplicate:expr, $encode_cross_crate:expr $(,)?) => { rustc_attr!( $attr, $typ, $tpl, $duplicate, - $(@only_local: $only_local,)? + $encode_cross_crate, concat!( "the `#[", stringify!($attr), @@ -232,10 +222,10 @@ macro_rules! rustc_attr { ), ) }; - ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr $(, @only_local: $only_local:expr)?, $msg:expr $(,)?) => { + ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $msg:expr $(,)?) => { BuiltinAttribute { name: sym::$attr, - only_local: or_default!(false, $($only_local)?), + encode_cross_crate: $encode_cross_crate, type_: $typ, template: $tpl, duplicates: $duplicates, @@ -253,12 +243,19 @@ macro_rules! experimental { const IMPL_DETAIL: &str = "internal implementation detail"; const INTERNAL_UNSTABLE: &str = "this is an internal attribute that will never be stable"; +#[derive(PartialEq)] +pub enum EncodeCrossCrate { + Yes, + No, +} + pub struct BuiltinAttribute { pub name: Symbol, - /// Whether this attribute is only used in the local crate. + /// Whether this attribute is encode cross crate. /// - /// If so, it is not encoded in the crate metadata. - pub only_local: bool, + /// If so, it is encoded in the crate metadata. + /// Otherwise, it can only be used in the local crate. + pub encode_cross_crate: EncodeCrossCrate, pub type_: AttributeType, pub template: AttributeTemplate, pub duplicates: AttributeDuplicates, @@ -273,65 +270,71 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // ========================================================================== // Conditional compilation: - ungated!(cfg, Normal, template!(List: "predicate"), DuplicatesOk), - ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ..."), DuplicatesOk), + ungated!(cfg, Normal, template!(List: "predicate"), DuplicatesOk, EncodeCrossCrate::Yes), + ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ..."), DuplicatesOk, EncodeCrossCrate::Yes), // Testing: ungated!( ignore, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing, - @only_local: true, + EncodeCrossCrate::No, ), ungated!( should_panic, Normal, template!(Word, List: r#"expected = "reason""#, NameValueStr: "reason"), FutureWarnFollowing, - @only_local: true, + EncodeCrossCrate::No, ), // FIXME(Centril): This can be used on stable but shouldn't. ungated!( reexport_test_harness_main, CrateLevel, template!(NameValueStr: "name"), ErrorFollowing, - @only_local: true, + EncodeCrossCrate::No, ), // Macros: - ungated!(automatically_derived, Normal, template!(Word), WarnFollowing), + ungated!(automatically_derived, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes), ungated!( macro_use, Normal, template!(Word, List: "name1, name2, ..."), WarnFollowingWordOnly, - @only_local: true, + EncodeCrossCrate::No, ), - ungated!(macro_escape, Normal, template!(Word), WarnFollowing, @only_local: true), // Deprecated synonym for `macro_use`. - ungated!(macro_export, Normal, template!(Word, List: "local_inner_macros"), WarnFollowing), - ungated!(proc_macro, Normal, template!(Word), ErrorFollowing, @only_local: true), + ungated!(macro_escape, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), // Deprecated synonym for `macro_use`. + ungated!( + macro_export, Normal, template!(Word, List: "local_inner_macros"), + WarnFollowing, EncodeCrossCrate::Yes + ), + ungated!(proc_macro, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::No), ungated!( proc_macro_derive, Normal, template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"), - ErrorFollowing, @only_local: true, + ErrorFollowing, EncodeCrossCrate::No, ), - ungated!(proc_macro_attribute, Normal, template!(Word), ErrorFollowing, @only_local: true), + ungated!(proc_macro_attribute, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::No), // Lints: ungated!( warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), - DuplicatesOk, @only_local: true, + DuplicatesOk, EncodeCrossCrate::No, ), ungated!( allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), - DuplicatesOk, @only_local: true, + DuplicatesOk, EncodeCrossCrate::No, ), gated!( expect, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk, - @only_local: true, lint_reasons, experimental!(expect) + EncodeCrossCrate::No, lint_reasons, experimental!(expect) ), ungated!( forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), - DuplicatesOk, @only_local: true, + DuplicatesOk, EncodeCrossCrate::No ), ungated!( deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), - DuplicatesOk, @only_local: true, + DuplicatesOk, EncodeCrossCrate::No + ), + ungated!( + must_use, Normal, template!(Word, NameValueStr: "reason"), + FutureWarnFollowing, EncodeCrossCrate::Yes ), - ungated!(must_use, Normal, template!(Word, NameValueStr: "reason"), FutureWarnFollowing), gated!( must_not_suspend, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing, - experimental!(must_not_suspend) + EncodeCrossCrate::Yes, experimental!(must_not_suspend) ), ungated!( deprecated, Normal, @@ -340,22 +343,22 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#, NameValueStr: "reason" ), - ErrorFollowing + ErrorFollowing, EncodeCrossCrate::Yes ), // Crate properties: ungated!( crate_name, CrateLevel, template!(NameValueStr: "name"), FutureWarnFollowing, - @only_local: true, + EncodeCrossCrate::No, ), ungated!( crate_type, CrateLevel, template!(NameValueStr: "bin|lib|..."), DuplicatesOk, - @only_local: true, + EncodeCrossCrate::No, ), // crate_id is deprecated ungated!( crate_id, CrateLevel, template!(NameValueStr: "ignored"), FutureWarnFollowing, - @only_local: true, + EncodeCrossCrate::No, ), // ABI, linking, symbols, and FFI @@ -363,81 +366,88 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ link, Normal, template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated""#), DuplicatesOk, - @only_local: true, + EncodeCrossCrate::No, ), - ungated!(link_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding), - ungated!(no_link, Normal, template!(Word), WarnFollowing, @only_local: true), - ungated!(repr, Normal, template!(List: "C"), DuplicatesOk, @only_local: true), - ungated!(export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, @only_local: true), - ungated!(link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, @only_local: true), - ungated!(no_mangle, Normal, template!(Word), WarnFollowing, @only_local: true), - ungated!(used, Normal, template!(Word, List: "compiler|linker"), WarnFollowing, @only_local: true), - ungated!(link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding), + ungated!( + link_name, Normal, template!(NameValueStr: "name"), + FutureWarnPreceding, EncodeCrossCrate::Yes + ), + ungated!(no_link, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), + ungated!(repr, Normal, template!(List: "C"), DuplicatesOk, EncodeCrossCrate::No), + ungated!(export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No), + ungated!(link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No), + ungated!(no_mangle, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), + ungated!(used, Normal, template!(Word, List: "compiler|linker"), WarnFollowing, EncodeCrossCrate::No), + ungated!(link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding, EncodeCrossCrate::Yes), // Limits: ungated!( recursion_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing, - @only_local: true + EncodeCrossCrate::No ), ungated!( type_length_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing, - @only_local: true + EncodeCrossCrate::No ), gated!( move_size_limit, CrateLevel, template!(NameValueStr: "N"), ErrorFollowing, - @only_local: true, large_assignments, experimental!(move_size_limit) + EncodeCrossCrate::No, large_assignments, experimental!(move_size_limit) ), // Entry point: - gated!(unix_sigpipe, Normal, template!(NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)), - ungated!(start, Normal, template!(Word), WarnFollowing, @only_local: true), - ungated!(no_start, CrateLevel, template!(Word), WarnFollowing, @only_local: true), - ungated!(no_main, CrateLevel, template!(Word), WarnFollowing, @only_local: true), + gated!( + unix_sigpipe, Normal, template!(NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, + EncodeCrossCrate::Yes, experimental!(unix_sigpipe) + ), + ungated!(start, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), + ungated!(no_start, CrateLevel, template!(Word), WarnFollowing, EncodeCrossCrate::No), + ungated!(no_main, CrateLevel, template!(Word), WarnFollowing, EncodeCrossCrate::No), // Modules, prelude, and resolution: - ungated!(path, Normal, template!(NameValueStr: "file"), FutureWarnFollowing, @only_local: true), - ungated!(no_std, CrateLevel, template!(Word), WarnFollowing, @only_local: true), - ungated!(no_implicit_prelude, Normal, template!(Word), WarnFollowing, @only_local: true), - ungated!(non_exhaustive, Normal, template!(Word), WarnFollowing), + ungated!(path, Normal, template!(NameValueStr: "file"), FutureWarnFollowing, EncodeCrossCrate::No), + ungated!(no_std, CrateLevel, template!(Word), WarnFollowing, EncodeCrossCrate::No), + ungated!(no_implicit_prelude, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), + ungated!(non_exhaustive, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes), // Runtime ungated!( windows_subsystem, CrateLevel, template!(NameValueStr: "windows|console"), FutureWarnFollowing, - @only_local: true + EncodeCrossCrate::No ), - ungated!(panic_handler, Normal, template!(Word), WarnFollowing), // RFC 2070 + ungated!(panic_handler, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes), // RFC 2070 // Code generation: - ungated!(inline, Normal, template!(Word, List: "always|never"), FutureWarnFollowing, @only_local: true), - ungated!(cold, Normal, template!(Word), WarnFollowing, @only_local: true), - ungated!(no_builtins, CrateLevel, template!(Word), WarnFollowing), + ungated!(inline, Normal, template!(Word, List: "always|never"), FutureWarnFollowing, EncodeCrossCrate::No), + ungated!(cold, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), + ungated!(no_builtins, CrateLevel, template!(Word), WarnFollowing, EncodeCrossCrate::Yes), ungated!( target_feature, Normal, template!(List: r#"enable = "name""#), - DuplicatesOk, @only_local: true, + DuplicatesOk, EncodeCrossCrate::No, ), - ungated!(track_caller, Normal, template!(Word), WarnFollowing), - ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding, @only_local: true), + ungated!(track_caller, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes), + ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding, EncodeCrossCrate::No), gated!( no_sanitize, Normal, template!(List: "address, kcfi, memory, thread"), DuplicatesOk, - @only_local: true, experimental!(no_sanitize) + EncodeCrossCrate::No, experimental!(no_sanitize) ), gated!( coverage, Normal, template!(Word, List: "on|off"), - WarnFollowing, @only_local: true, + WarnFollowing, EncodeCrossCrate::No, coverage_attribute, experimental!(coverage) ), ungated!( - doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk + doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk, + EncodeCrossCrate::Yes ), // Debugging ungated!( debugger_visualizer, Normal, template!(List: r#"natvis_file = "...", gdb_script_file = "...""#), - DuplicatesOk, @only_local: true + DuplicatesOk, EncodeCrossCrate::No ), // ========================================================================== @@ -446,54 +456,55 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // Linking: gated!( - naked, Normal, template!(Word), WarnFollowing, @only_local: true, + naked, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, naked_functions, experimental!(naked) ), // Testing: gated!( - test_runner, CrateLevel, template!(List: "path"), ErrorFollowing, custom_test_frameworks, + test_runner, CrateLevel, template!(List: "path"), ErrorFollowing, + EncodeCrossCrate::Yes, custom_test_frameworks, "custom test frameworks are an unstable feature", ), // RFC #1268 gated!( - marker, Normal, template!(Word), WarnFollowing, @only_local: true, + marker, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, marker_trait_attr, experimental!(marker) ), gated!( - thread_local, Normal, template!(Word), WarnFollowing, @only_local: true, + thread_local, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, "`#[thread_local]` is an experimental feature, and does not currently handle destructors", ), gated!( no_core, CrateLevel, template!(Word), WarnFollowing, - @only_local: true, experimental!(no_core) + EncodeCrossCrate::No, experimental!(no_core) ), // RFC 2412 gated!( optimize, Normal, template!(List: "size|speed"), ErrorPreceding, - @only_local: true, optimize_attribute, experimental!(optimize) + EncodeCrossCrate::No, optimize_attribute, experimental!(optimize) ), gated!( ffi_pure, Normal, template!(Word), WarnFollowing, - @only_local: true, experimental!(ffi_pure) + EncodeCrossCrate::No, experimental!(ffi_pure) ), gated!( ffi_const, Normal, template!(Word), WarnFollowing, - @only_local: true, experimental!(ffi_const) + EncodeCrossCrate::No, experimental!(ffi_const) ), gated!( register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), DuplicatesOk, - @only_local: true, experimental!(register_tool), + EncodeCrossCrate::No, experimental!(register_tool), ), gated!( cmse_nonsecure_entry, Normal, template!(Word), WarnFollowing, - @only_local: true, experimental!(cmse_nonsecure_entry) + EncodeCrossCrate::No, experimental!(cmse_nonsecure_entry) ), // RFC 2632 gated!( - const_trait, Normal, template!(Word), WarnFollowing, const_trait_impl, + const_trait, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes, const_trait_impl, "`const_trait` is a temporary placeholder for marking a trait that is suitable for `const` \ `impls` and all default bodies as `const`, which may be removed or renamed in the \ future." @@ -501,25 +512,25 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // lang-team MCP 147 gated!( deprecated_safe, Normal, template!(List: r#"since = "version", note = "...""#), ErrorFollowing, - experimental!(deprecated_safe), + EncodeCrossCrate::Yes, experimental!(deprecated_safe), ), // `#[collapse_debuginfo]` gated!( collapse_debuginfo, Normal, template!(Word, List: "no|external|yes"), ErrorFollowing, - @only_local: true, experimental!(collapse_debuginfo) + EncodeCrossCrate::No, experimental!(collapse_debuginfo) ), // RFC 2397 gated!( do_not_recommend, Normal, template!(Word), WarnFollowing, - @only_local: true, experimental!(do_not_recommend) + EncodeCrossCrate::No, experimental!(do_not_recommend) ), // `#[cfi_encoding = ""]` gated!( cfi_encoding, Normal, template!(NameValueStr: "encoding"), ErrorPreceding, - experimental!(cfi_encoding) + EncodeCrossCrate::Yes, experimental!(cfi_encoding) ), // ========================================================================== @@ -528,43 +539,48 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ungated!( feature, CrateLevel, - template!(List: "name1, name2, ..."), DuplicatesOk, @only_local: true, + template!(List: "name1, name2, ..."), DuplicatesOk, EncodeCrossCrate::No, ), // DuplicatesOk since it has its own validation ungated!( stable, Normal, - template!(List: r#"feature = "name", since = "version""#), DuplicatesOk, @only_local: true, + template!(List: r#"feature = "name", since = "version""#), DuplicatesOk, EncodeCrossCrate::No, ), ungated!( unstable, Normal, template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk, + EncodeCrossCrate::Yes + ), + ungated!( + rustc_const_unstable, Normal, template!(List: r#"feature = "name""#), + DuplicatesOk, EncodeCrossCrate::Yes ), - ungated!(rustc_const_unstable, Normal, template!(List: r#"feature = "name""#), DuplicatesOk), ungated!( rustc_const_stable, Normal, - template!(List: r#"feature = "name""#), DuplicatesOk, @only_local: true, + template!(List: r#"feature = "name""#), DuplicatesOk, EncodeCrossCrate::No, ), ungated!( rustc_default_body_unstable, Normal, template!(List: r#"feature = "name", reason = "...", issue = "N""#), - DuplicatesOk, @only_local: true + DuplicatesOk, EncodeCrossCrate::No ), gated!( - allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), DuplicatesOk, + allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), + DuplicatesOk, EncodeCrossCrate::Yes, "allow_internal_unstable side-steps feature gating and stability checks", ), gated!( rustc_allow_const_fn_unstable, Normal, - template!(Word, List: "feat1, feat2, ..."), DuplicatesOk, @only_local: true, + template!(Word, List: "feat1, feat2, ..."), DuplicatesOk, EncodeCrossCrate::No, "rustc_allow_const_fn_unstable side-steps feature gating and stability checks" ), gated!( allow_internal_unsafe, Normal, template!(Word), WarnFollowing, - @only_local: true, "allow_internal_unsafe side-steps the unsafe_code lint", + EncodeCrossCrate::No, "allow_internal_unsafe side-steps the unsafe_code lint", ), rustc_attr!( rustc_allowed_through_unstable_modules, Normal, template!(Word), - WarnFollowing, @only_local: true, + WarnFollowing, EncodeCrossCrate::No, "rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \ through unstable paths" ), @@ -573,62 +589,72 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // Internal attributes: Type system related: // ========================================================================== - gated!(fundamental, Normal, template!(Word), WarnFollowing, experimental!(fundamental)), + gated!(fundamental, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes, experimental!(fundamental)), gated!( may_dangle, Normal, template!(Word), WarnFollowing, - @only_local: true, dropck_eyepatch, + EncodeCrossCrate::No, dropck_eyepatch, "`may_dangle` has unstable semantics and may be removed in the future", ), + rustc_attr!( + rustc_never_type_options, + Normal, + template!(List: r#"/*opt*/ fallback = "unit|niko|never|no""#), + ErrorFollowing, + EncodeCrossCrate::No, + "`rustc_never_type_options` is used to experiment with never type fallback and work on \ + never type stabilization, and will never be stable" + ), + // ========================================================================== // Internal attributes: Runtime related: // ========================================================================== rustc_attr!( rustc_allocator, Normal, template!(Word), WarnFollowing, - @only_local: true, IMPL_DETAIL + EncodeCrossCrate::No, IMPL_DETAIL ), rustc_attr!( rustc_nounwind, Normal, template!(Word), WarnFollowing, - @only_local: true, IMPL_DETAIL + EncodeCrossCrate::No, IMPL_DETAIL ), rustc_attr!( rustc_reallocator, Normal, template!(Word), WarnFollowing, - @only_local: true, IMPL_DETAIL + EncodeCrossCrate::No, IMPL_DETAIL ), rustc_attr!( rustc_deallocator, Normal, template!(Word), WarnFollowing, - @only_local: true, IMPL_DETAIL + EncodeCrossCrate::No, IMPL_DETAIL ), rustc_attr!( rustc_allocator_zeroed, Normal, template!(Word), WarnFollowing, - @only_local: true, IMPL_DETAIL + EncodeCrossCrate::No, IMPL_DETAIL ), gated!( default_lib_allocator, Normal, template!(Word), WarnFollowing, - @only_local: true, allocator_internals, experimental!(default_lib_allocator), + EncodeCrossCrate::No, allocator_internals, experimental!(default_lib_allocator), ), gated!( needs_allocator, Normal, template!(Word), WarnFollowing, - @only_local: true, allocator_internals, experimental!(needs_allocator), + EncodeCrossCrate::No, allocator_internals, experimental!(needs_allocator), ), gated!( panic_runtime, Normal, template!(Word), WarnFollowing, - @only_local: true, experimental!(panic_runtime) + EncodeCrossCrate::No, experimental!(panic_runtime) ), gated!( needs_panic_runtime, Normal, template!(Word), WarnFollowing, - @only_local: true, experimental!(needs_panic_runtime) + EncodeCrossCrate::No, experimental!(needs_panic_runtime) ), gated!( compiler_builtins, Normal, template!(Word), WarnFollowing, - @only_local: true, + EncodeCrossCrate::No, "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \ which contains compiler-rt intrinsics and will never be stable", ), gated!( profiler_runtime, Normal, template!(Word), WarnFollowing, - @only_local: true, + EncodeCrossCrate::No, "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \ which contains the profiler runtime and will never be stable", ), @@ -638,11 +664,13 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // ========================================================================== gated!( - linkage, Normal, template!(NameValueStr: "external|internal|..."), ErrorPreceding, @only_local: true, + linkage, Normal, template!(NameValueStr: "external|internal|..."), + ErrorPreceding, EncodeCrossCrate::No, "the `linkage` attribute is experimental and not portable across platforms", ), rustc_attr!( - rustc_std_internal_symbol, Normal, template!(Word), WarnFollowing, @only_local: true, INTERNAL_UNSTABLE + rustc_std_internal_symbol, Normal, template!(Word), WarnFollowing, + EncodeCrossCrate::No, INTERNAL_UNSTABLE ), // ========================================================================== @@ -652,16 +680,16 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ rustc_attr!( rustc_builtin_macro, Normal, template!(Word, List: "name, /*opt*/ attributes(name1, name2, ...)"), ErrorFollowing, - IMPL_DETAIL, + EncodeCrossCrate::Yes, IMPL_DETAIL ), rustc_attr!( rustc_proc_macro_decls, Normal, template!(Word), WarnFollowing, - @only_local: true, INTERNAL_UNSTABLE + EncodeCrossCrate::No, INTERNAL_UNSTABLE ), rustc_attr!( rustc_macro_transparency, Normal, template!(NameValueStr: "transparent|semitransparent|opaque"), ErrorFollowing, - "used internally for testing macro hygiene", + EncodeCrossCrate::Yes, "used internally for testing macro hygiene", ), // ========================================================================== @@ -674,36 +702,50 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#, NameValueStr: "message" ), - ErrorFollowing, + ErrorFollowing, EncodeCrossCrate::Yes, INTERNAL_UNSTABLE ), rustc_attr!( rustc_confusables, Normal, template!(List: r#""name1", "name2", ..."#), - ErrorFollowing, + ErrorFollowing, EncodeCrossCrate::Yes, INTERNAL_UNSTABLE, ), // Enumerates "identity-like" conversion methods to suggest on type mismatch. rustc_attr!( - rustc_conversion_suggestion, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE + rustc_conversion_suggestion, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::Yes, INTERNAL_UNSTABLE ), // Prevents field reads in the marked trait or method to be considered // during dead code analysis. rustc_attr!( - rustc_trivial_field_reads, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE + rustc_trivial_field_reads, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::Yes, INTERNAL_UNSTABLE ), // Used by the `rustc::potential_query_instability` lint to warn methods which // might not be stable during incremental compilation. - rustc_attr!(rustc_lint_query_instability, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE), + rustc_attr!( + rustc_lint_query_instability, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::Yes, INTERNAL_UNSTABLE + ), // Used by the `rustc::diagnostic_outside_of_impl` lints to assist in changes to diagnostic // APIs. Any function with this attribute will be checked by that lint. - rustc_attr!(rustc_lint_diagnostics, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE), + rustc_attr!( + rustc_lint_diagnostics, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::Yes, INTERNAL_UNSTABLE + ), // Used by the `rustc::bad_opt_access` lint to identify `DebuggingOptions` and `CodegenOptions` // types (as well as any others in future). - rustc_attr!(rustc_lint_opt_ty, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE), + rustc_attr!( + rustc_lint_opt_ty, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::Yes, INTERNAL_UNSTABLE + ), // Used by the `rustc::bad_opt_access` lint on fields // types (as well as any others in future). - rustc_attr!(rustc_lint_opt_deny_field_access, Normal, template!(List: "message"), WarnFollowing, INTERNAL_UNSTABLE), + rustc_attr!( + rustc_lint_opt_deny_field_access, Normal, template!(List: "message"), + WarnFollowing, EncodeCrossCrate::Yes, INTERNAL_UNSTABLE + ), // ========================================================================== // Internal attributes, Const related: @@ -711,18 +753,20 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ rustc_attr!( rustc_promotable, Normal, template!(Word), WarnFollowing, - @only_local: true, IMPL_DETAIL), + EncodeCrossCrate::No, IMPL_DETAIL), rustc_attr!( rustc_legacy_const_generics, Normal, template!(List: "N"), ErrorFollowing, - INTERNAL_UNSTABLE + EncodeCrossCrate::Yes, INTERNAL_UNSTABLE ), // Do not const-check this function's body. It will always get replaced during CTFE. rustc_attr!( - rustc_do_not_const_check, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE + rustc_do_not_const_check, Normal, template!(Word), WarnFollowing, + EncodeCrossCrate::Yes, INTERNAL_UNSTABLE ), // Ensure the argument to this function is &&str during const-check. rustc_attr!( - rustc_const_panic_str, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE + rustc_const_panic_str, Normal, template!(Word), WarnFollowing, + EncodeCrossCrate::Yes, INTERNAL_UNSTABLE ), // ========================================================================== @@ -731,16 +775,19 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ rustc_attr!( rustc_layout_scalar_valid_range_start, Normal, template!(List: "value"), ErrorFollowing, + EncodeCrossCrate::Yes, "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \ niche optimizations in libcore and libstd and will never be stable", ), rustc_attr!( rustc_layout_scalar_valid_range_end, Normal, template!(List: "value"), ErrorFollowing, + EncodeCrossCrate::Yes, "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \ niche optimizations in libcore and libstd and will never be stable", ), rustc_attr!( rustc_nonnull_optimization_guaranteed, Normal, template!(Word), WarnFollowing, + EncodeCrossCrate::Yes, "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to enable \ niche optimizations in libcore and libstd and will never be stable", ), @@ -749,27 +796,29 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // Internal attributes, Misc: // ========================================================================== gated!( - lang, Normal, template!(NameValueStr: "name"), DuplicatesOk, @only_local: true, lang_items, + lang, Normal, template!(NameValueStr: "name"), DuplicatesOk, EncodeCrossCrate::No, lang_items, "language items are subject to change", ), rustc_attr!( rustc_pass_by_value, Normal, template!(Word), ErrorFollowing, + EncodeCrossCrate::Yes, "#[rustc_pass_by_value] is used to mark types that must be passed by value instead of reference." ), rustc_attr!( rustc_never_returns_null_ptr, Normal, template!(Word), ErrorFollowing, + EncodeCrossCrate::Yes, "#[rustc_never_returns_null_ptr] is used to mark functions returning non-null pointers." ), rustc_attr!( - rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, @only_local: true, + rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No, "#![rustc_coherence_is_core] allows inherent methods on builtin types, only intended to be used in `core`." ), rustc_attr!( - rustc_coinductive, AttributeType::Normal, template!(Word), WarnFollowing, @only_local: true, + rustc_coinductive, AttributeType::Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, "#![rustc_coinductive] changes a trait to be coinductive, allowing cycles in the trait solver." ), rustc_attr!( - rustc_allow_incoherent_impl, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: true, + rustc_allow_incoherent_impl, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::No, "#[rustc_allow_incoherent_impl] has to be added to all impl items of an incoherent inherent impl." ), rustc_attr!( @@ -777,16 +826,17 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ AttributeType::Normal, template!(List: "implement_via_object = (true|false)"), ErrorFollowing, - @only_local: true, + EncodeCrossCrate::No, "#[rustc_deny_explicit_impl] enforces that a trait can have no user-provided impls" ), rustc_attr!( - rustc_has_incoherent_inherent_impls, AttributeType::Normal, template!(Word), ErrorFollowing, + rustc_has_incoherent_inherent_impls, AttributeType::Normal, template!(Word), + ErrorFollowing, EncodeCrossCrate::Yes, "#[rustc_has_incoherent_inherent_impls] allows the addition of incoherent inherent impls for \ the given type by annotating all impl items with #[rustc_allow_incoherent_impl]." ), rustc_attr!( - rustc_box, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: true, + rustc_box, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::No, "#[rustc_box] allows creating boxes \ and it is only intended to be used in `alloc`." ), @@ -794,7 +844,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ BuiltinAttribute { name: sym::rustc_diagnostic_item, // FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`. - only_local: false, + encode_cross_crate: EncodeCrossCrate::Yes, type_: Normal, template: template!(NameValueStr: "name"), duplicates: ErrorFollowing, @@ -808,74 +858,74 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ gated!( // Used in resolve: prelude_import, Normal, template!(Word), WarnFollowing, - @only_local: true, "`#[prelude_import]` is for use by rustc only", + EncodeCrossCrate::No, "`#[prelude_import]` is for use by rustc only", ), gated!( - rustc_paren_sugar, Normal, template!(Word), WarnFollowing, @only_local: true, + rustc_paren_sugar, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, unboxed_closures, "unboxed_closures are still evolving", ), rustc_attr!( - rustc_inherit_overflow_checks, Normal, template!(Word), WarnFollowing, @only_local: true, + rustc_inherit_overflow_checks, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \ overflow checking behavior of several libcore functions that are inlined \ across crates and will never be stable", ), rustc_attr!( rustc_reservation_impl, Normal, - template!(NameValueStr: "reservation message"), ErrorFollowing, + template!(NameValueStr: "reservation message"), ErrorFollowing, EncodeCrossCrate::Yes, "the `#[rustc_reservation_impl]` attribute is internally used \ for reserving for `for<T> From<!> for T` impl" ), rustc_attr!( rustc_test_marker, Normal, template!(NameValueStr: "name"), WarnFollowing, - @only_local: true, "the `#[rustc_test_marker]` attribute is used internally to track tests", + EncodeCrossCrate::No, "the `#[rustc_test_marker]` attribute is used internally to track tests", ), rustc_attr!( rustc_unsafe_specialization_marker, Normal, template!(Word), - WarnFollowing, @only_local: true, + WarnFollowing, EncodeCrossCrate::No, "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations" ), rustc_attr!( rustc_specialization_trait, Normal, template!(Word), - WarnFollowing, @only_local: true, + WarnFollowing, EncodeCrossCrate::No, "the `#[rustc_specialization_trait]` attribute is used to check specializations" ), rustc_attr!( - rustc_main, Normal, template!(Word), WarnFollowing, @only_local: true, + rustc_main, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, "the `#[rustc_main]` attribute is used internally to specify test entry point function", ), rustc_attr!( rustc_skip_array_during_method_dispatch, Normal, template!(Word), - WarnFollowing, @only_local: true, + WarnFollowing, EncodeCrossCrate::No, "the `#[rustc_skip_array_during_method_dispatch]` attribute is used to exclude a trait \ from method dispatch when the receiver is an array, for compatibility in editions < 2021." ), rustc_attr!( rustc_must_implement_one_of, Normal, template!(List: "function1, function2, ..."), - ErrorFollowing, @only_local: true, + ErrorFollowing, EncodeCrossCrate::No, "the `#[rustc_must_implement_one_of]` attribute is used to change minimal complete \ definition of a trait, it's currently in experimental form and should be changed before \ being exposed outside of the std" ), rustc_attr!( rustc_doc_primitive, Normal, template!(NameValueStr: "primitive name"), ErrorFollowing, - r#"`rustc_doc_primitive` is a rustc internal attribute"#, + EncodeCrossCrate::Yes, r#"`rustc_doc_primitive` is a rustc internal attribute"#, ), rustc_attr!( rustc_safe_intrinsic, Normal, template!(Word), WarnFollowing, - @only_local: true, + EncodeCrossCrate::No, "the `#[rustc_safe_intrinsic]` attribute is used internally to mark intrinsics as safe" ), rustc_attr!( - rustc_intrinsic, Normal, template!(Word), ErrorFollowing, + rustc_intrinsic, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes, "the `#[rustc_intrinsic]` attribute is used to declare intrinsics with function bodies", ), rustc_attr!( - rustc_no_mir_inline, Normal, template!(Word), WarnFollowing, + rustc_no_mir_inline, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes, "#[rustc_no_mir_inline] prevents the MIR inliner from inlining a function while not affecting codegen" ), rustc_attr!( - rustc_intrinsic_must_be_overridden, Normal, template!(Word), ErrorFollowing, + rustc_intrinsic_must_be_overridden, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes, "the `#[rustc_intrinsic_must_be_overridden]` attribute is used to declare intrinsics without real bodies", ), @@ -883,109 +933,135 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // Internal attributes, Testing: // ========================================================================== - rustc_attr!(TEST, rustc_effective_visibility, Normal, template!(Word), WarnFollowing), + rustc_attr!(TEST, rustc_effective_visibility, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes), rustc_attr!( TEST, rustc_outlives, Normal, template!(Word), - WarnFollowing, @only_local: true + WarnFollowing, EncodeCrossCrate::No ), rustc_attr!( TEST, rustc_capture_analysis, Normal, template!(Word), - WarnFollowing, @only_local: true + WarnFollowing, EncodeCrossCrate::No + ), + rustc_attr!( + TEST, rustc_insignificant_dtor, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::Yes + ), + rustc_attr!( + TEST, rustc_strict_coherence, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::Yes + ), + rustc_attr!( + TEST, rustc_variance, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::No ), - rustc_attr!(TEST, rustc_insignificant_dtor, Normal, template!(Word), WarnFollowing), - rustc_attr!(TEST, rustc_strict_coherence, Normal, template!(Word), WarnFollowing), - rustc_attr!(TEST, rustc_variance, Normal, template!(Word), WarnFollowing, @only_local: true), rustc_attr!( TEST, rustc_variance_of_opaques, Normal, template!(Word), - WarnFollowing, @only_local: true + WarnFollowing, EncodeCrossCrate::No ), rustc_attr!( TEST, rustc_hidden_type_of_opaques, Normal, template!(Word), - WarnFollowing, @only_local: true), - rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ..."), WarnFollowing), + WarnFollowing, EncodeCrossCrate::No + ), + rustc_attr!( + TEST, rustc_layout, Normal, template!(List: "field1, field2, ..."), + WarnFollowing, EncodeCrossCrate::Yes + ), rustc_attr!( TEST, rustc_abi, Normal, template!(List: "field1, field2, ..."), - WarnFollowing, @only_local: true + WarnFollowing, EncodeCrossCrate::No ), rustc_attr!( TEST, rustc_regions, Normal, template!(Word), - WarnFollowing, @only_local: true + WarnFollowing, EncodeCrossCrate::No ), rustc_attr!( TEST, rustc_error, Normal, - template!(Word, List: "delayed_bug_from_inside_query"), WarnFollowingWordOnly + template!(Word, List: "delayed_bug_from_inside_query"), + WarnFollowingWordOnly, EncodeCrossCrate::Yes ), rustc_attr!( - TEST, rustc_dump_user_args, Normal, template!(Word), WarnFollowing, - @only_local: true + TEST, rustc_dump_user_args, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::No ), - rustc_attr!(TEST, rustc_evaluate_where_clauses, Normal, template!(Word), WarnFollowing), rustc_attr!( - TEST, rustc_if_this_changed, Normal, template!(Word, List: "DepNode"), - DuplicatesOk, @only_local: true + TEST, rustc_evaluate_where_clauses, Normal, template!(Word), WarnFollowing, + EncodeCrossCrate::Yes ), rustc_attr!( - TEST, rustc_then_this_would_need, Normal, template!(List: "DepNode"), - DuplicatesOk, @only_local: true + TEST, rustc_if_this_changed, Normal, template!(Word, List: "DepNode"), DuplicatesOk, + EncodeCrossCrate::No + ), + rustc_attr!( + TEST, rustc_then_this_would_need, Normal, template!(List: "DepNode"), DuplicatesOk, + EncodeCrossCrate::No ), rustc_attr!( TEST, rustc_clean, Normal, template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#), - DuplicatesOk, @only_local: true + DuplicatesOk, EncodeCrossCrate::No ), rustc_attr!( TEST, rustc_partition_reused, Normal, - template!(List: r#"cfg = "...", module = "...""#), DuplicatesOk, @only_local: true + template!(List: r#"cfg = "...", module = "...""#), DuplicatesOk, EncodeCrossCrate::No ), rustc_attr!( TEST, rustc_partition_codegened, Normal, - template!(List: r#"cfg = "...", module = "...""#), DuplicatesOk, @only_local: true + template!(List: r#"cfg = "...", module = "...""#), DuplicatesOk, EncodeCrossCrate::No ), rustc_attr!( TEST, rustc_expected_cgu_reuse, Normal, template!(List: r#"cfg = "...", module = "...", kind = "...""#), DuplicatesOk, - @only_local: true + EncodeCrossCrate::No + ), + rustc_attr!( + TEST, rustc_symbol_name, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::No + ), + rustc_attr!( + TEST, rustc_polymorphize_error, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::Yes ), rustc_attr!( - TEST, rustc_symbol_name, Normal, template!(Word), WarnFollowing, - @only_local: true + TEST, rustc_def_path, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::No ), - rustc_attr!(TEST, rustc_polymorphize_error, Normal, template!(Word), WarnFollowing), rustc_attr!( - TEST, rustc_def_path, Normal, template!(Word), WarnFollowing, - @only_local: true + TEST, rustc_mir, Normal, template!(List: "arg1, arg2, ..."), + DuplicatesOk, EncodeCrossCrate::Yes ), - rustc_attr!(TEST, rustc_mir, Normal, template!(List: "arg1, arg2, ..."), DuplicatesOk), gated!( custom_mir, Normal, template!(List: r#"dialect = "...", phase = "...""#), - ErrorFollowing, @only_local: true, + ErrorFollowing, EncodeCrossCrate::No, "the `#[custom_mir]` attribute is just used for the Rust test suite", ), rustc_attr!( - TEST, rustc_dump_program_clauses, Normal, template!(Word), WarnFollowing, - @only_local: true + TEST, rustc_dump_program_clauses, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::No ), rustc_attr!( - TEST, rustc_dump_env_program_clauses, Normal, template!(Word), WarnFollowing, - @only_local: true + TEST, rustc_dump_env_program_clauses, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::No ), rustc_attr!( - TEST, rustc_object_lifetime_default, Normal, template!(Word), WarnFollowing, - @only_local: true + TEST, rustc_object_lifetime_default, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::No ), - rustc_attr!(TEST, rustc_dump_vtable, Normal, template!(Word), WarnFollowing), rustc_attr!( - TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/), DuplicatesOk, - @only_local: true + TEST, rustc_dump_vtable, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::Yes + ), + rustc_attr!( + TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/), + DuplicatesOk, EncodeCrossCrate::No ), gated!( - omit_gdb_pretty_printer_section, Normal, template!(Word), WarnFollowing, - @only_local: true, + omit_gdb_pretty_printer_section, Normal, template!(Word), + WarnFollowing, EncodeCrossCrate::No, "the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite", ), rustc_attr!( TEST, pattern_complexity, CrateLevel, template!(NameValueStr: "N"), - ErrorFollowing, @only_local: true, + ErrorFollowing, EncodeCrossCrate::No, ), ]; @@ -997,10 +1073,14 @@ pub fn is_builtin_attr_name(name: Symbol) -> bool { BUILTIN_ATTRIBUTE_MAP.get(&name).is_some() } -/// Whether this builtin attribute is only used in the local crate. -/// If so, it is not encoded in the crate metadata. -pub fn is_builtin_only_local(name: Symbol) -> bool { - BUILTIN_ATTRIBUTE_MAP.get(&name).is_some_and(|attr| attr.only_local) +/// Whether this builtin attribute is encoded cross crate. +/// This means it can be used cross crate. +pub fn encode_cross_crate(name: Symbol) -> bool { + if let Some(attr) = BUILTIN_ATTRIBUTE_MAP.get(&name) { + if attr.encode_cross_crate == EncodeCrossCrate::Yes { true } else { false } + } else { + true + } } pub fn is_valid_for_get_attr(name: Symbol) -> bool { diff --git a/compiler/rustc_feature/src/lib.rs b/compiler/rustc_feature/src/lib.rs index cbc0ce8c974..cb28bb4e8e4 100644 --- a/compiler/rustc_feature/src/lib.rs +++ b/compiler/rustc_feature/src/lib.rs @@ -124,7 +124,7 @@ pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option<NonZero<u pub use accepted::ACCEPTED_FEATURES; pub use builtin_attrs::AttributeDuplicates; pub use builtin_attrs::{ - deprecated_attributes, find_gated_cfg, is_builtin_attr_name, is_builtin_only_local, + deprecated_attributes, encode_cross_crate, find_gated_cfg, is_builtin_attr_name, is_valid_for_get_attr, AttributeGate, AttributeTemplate, AttributeType, BuiltinAttribute, GatedCfg, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP, }; diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index 05bb7480732..eaaf7ca34e0 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -98,7 +98,7 @@ declare_features! ( (removed, external_doc, "1.54.0", Some(44732), Some("use #[doc = include_str!(\"filename\")] instead, which handles macro invocations")), /// Allows using `#[ffi_returns_twice]` on foreign functions. - (removed, ffi_returns_twice, "CURRENT_RUSTC_VERSION", Some(58314), + (removed, ffi_returns_twice, "1.78.0", Some(58314), Some("being investigated by the ffi-unwind project group")), /// Allows generators to be cloned. (removed, generator_clone, "1.65.0", Some(95360), Some("renamed to `coroutine_clone`")), diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 52421fce867..8d72f4924d6 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -214,7 +214,7 @@ declare_features! ( /// Allows using `#[omit_gdb_pretty_printer_section]`. (internal, omit_gdb_pretty_printer_section, "1.5.0", None), /// Set the maximum pattern complexity allowed (not limited by default). - (internal, pattern_complexity, "CURRENT_RUSTC_VERSION", None), + (internal, pattern_complexity, "1.78.0", None), /// Allows using `#[prelude_import]` on glob `use` items. (internal, prelude_import, "1.2.0", None), /// Used to identify crates that contain the profiler runtime. @@ -301,11 +301,11 @@ declare_features! ( (unstable, csky_target_feature, "1.73.0", Some(44839)), (unstable, ermsb_target_feature, "1.49.0", Some(44839)), (unstable, hexagon_target_feature, "1.27.0", Some(44839)), - (unstable, lahfsahf_target_feature, "CURRENT_RUSTC_VERSION", Some(44839)), + (unstable, lahfsahf_target_feature, "1.78.0", Some(44839)), (unstable, loongarch_target_feature, "1.73.0", Some(44839)), (unstable, mips_target_feature, "1.27.0", Some(44839)), (unstable, powerpc_target_feature, "1.27.0", Some(44839)), - (unstable, prfchw_target_feature, "CURRENT_RUSTC_VERSION", Some(44839)), + (unstable, prfchw_target_feature, "1.78.0", Some(44839)), (unstable, riscv_target_feature, "1.45.0", Some(44839)), (unstable, rtm_target_feature, "1.35.0", Some(44839)), (unstable, sse4a_target_feature, "1.27.0", Some(44839)), @@ -346,13 +346,11 @@ declare_features! ( /// Enables experimental inline assembly support for additional architectures. (unstable, asm_experimental_arch, "1.58.0", Some(93335)), /// Allows using `label` operands in inline assembly. - (unstable, asm_goto, "CURRENT_RUSTC_VERSION", Some(119364)), + (unstable, asm_goto, "1.78.0", Some(119364)), /// Allows the `may_unwind` option in inline assembly. (unstable, asm_unwind, "1.58.0", Some(93334)), /// Allows users to enforce equality of associated constants `TraitImpl<AssocConst=3>`. (unstable, associated_const_equality, "1.58.0", Some(92827)), - /// Allows the user of associated type bounds. - (unstable, associated_type_bounds, "1.34.0", Some(52662)), /// Allows associated type defaults. (unstable, associated_type_defaults, "1.2.0", Some(29661)), /// Allows `async || body` closures. @@ -412,7 +410,7 @@ declare_features! ( /// Allows references to types with interior mutability within constants (unstable, const_refs_to_cell, "1.51.0", Some(80384)), /// Allows creating pointers and references to `static` items in constants. - (unstable, const_refs_to_static, "CURRENT_RUSTC_VERSION", Some(119618)), + (unstable, const_refs_to_static, "1.78.0", Some(119618)), /// Allows `impl const Trait for T` syntax. (unstable, const_trait_impl, "1.42.0", Some(67792)), /// Allows the `?` operator in const contexts. @@ -438,6 +436,8 @@ declare_features! ( (unstable, deprecated_safe, "1.61.0", Some(94978)), /// Allows having using `suggestion` in the `#[deprecated]` attribute. (unstable, deprecated_suggestion, "1.61.0", Some(94785)), + /// Allows deref patterns. + (incomplete, deref_patterns, "CURRENT_RUSTC_VERSION", Some(87121)), /// Controls errors in trait implementations. (unstable, do_not_recommend, "1.67.0", Some(51992)), /// Tells rustdoc to automatically generate `#[doc(cfg(...))]`. @@ -463,6 +463,10 @@ declare_features! ( (unstable, extended_varargs_abi_support, "1.65.0", Some(100189)), /// Allows defining `extern type`s. (unstable, extern_types, "1.23.0", Some(43467)), + /// Allow using 128-bit (quad precision) floating point numbers. + (unstable, f128, "1.78.0", Some(116909)), + /// Allow using 16-bit (half precision) floating point numbers. + (unstable, f16, "1.78.0", Some(116909)), /// Allows the use of `#[ffi_const]` on foreign functions. (unstable, ffi_const, "1.45.0", Some(58328)), /// Allows the use of `#[ffi_pure]` on foreign functions. @@ -472,7 +476,7 @@ declare_features! ( /// Support delegating implementation of functions to other already implemented functions. (incomplete, fn_delegation, "1.76.0", Some(118212)), /// Allows impls for the Freeze trait. - (internal, freeze_impls, "CURRENT_RUSTC_VERSION", Some(121675)), + (internal, freeze_impls, "1.78.0", Some(121675)), /// Allows defining gen blocks and `gen fn`. (unstable, gen_blocks, "1.75.0", Some(117078)), /// Infer generic args for both consts and types. @@ -491,8 +495,6 @@ declare_features! ( (unstable, impl_trait_in_assoc_type, "1.70.0", Some(63063)), /// Allows `impl Trait` as output type in `Fn` traits in return position of functions. (unstable, impl_trait_in_fn_trait_return, "1.64.0", Some(99697)), - /// Allows using imported `main` function - (unstable, imported_main, "1.53.0", Some(28937)), /// Allows associated types in inherent impls. (incomplete, inherent_associated_types, "1.52.0", Some(8995)), /// Allow anonymous constants from an inline `const` block @@ -557,6 +559,8 @@ declare_features! ( (unstable, offset_of_nested, "1.77.0", Some(120140)), /// Allows using `#[optimize(X)]`. (unstable, optimize_attribute, "1.34.0", Some(54882)), + /// Allows postfix match `expr.match { ... }` + (unstable, postfix_match, "CURRENT_RUSTC_VERSION", Some(121618)), /// Allows macro attributes on expressions, statements and non-inline modules. (unstable, proc_macro_hygiene, "1.30.0", Some(54727)), /// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions. diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 1810193c16b..e8cecb1930f 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -810,6 +810,8 @@ pub enum LifetimeRes { param: NodeId, /// Id of the introducing place. See `Param`. binder: NodeId, + /// Kind of elided lifetime + kind: hir::MissingLifetimeKind, }, /// This variant is used for anonymous lifetimes that we did not resolve during /// late resolution. Those lifetimes will be inferred by typechecking. diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index bb468b2e056..162ec16fabc 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -428,10 +428,6 @@ pub enum TraitBoundModifier { MaybeConst, } -/// The AST represents all type param bounds as types. -/// `typeck::collect::compute_bounds` matches these against -/// the "special" built-in traits (see `middle::lang_items`) and -/// detects `Copy`, `Send` and `Sync`. #[derive(Clone, Copy, Debug, HashStable_Generic)] pub enum GenericBound<'hir> { Trait(PolyTraitRef<'hir>, TraitBoundModifier), @@ -456,6 +452,18 @@ impl GenericBound<'_> { pub type GenericBounds<'hir> = &'hir [GenericBound<'hir>]; +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic, Debug)] +pub enum MissingLifetimeKind { + /// An explicit `'_`. + Underscore, + /// An elided lifetime `&' ty`. + Ampersand, + /// An elided lifetime in brackets with written brackets. + Comma, + /// An elided lifetime with elided brackets. + Brackets, +} + #[derive(Copy, Clone, Debug, HashStable_Generic)] pub enum LifetimeParamKind { // Indicates that the lifetime definition was explicitly declared (e.g., in @@ -464,7 +472,7 @@ pub enum LifetimeParamKind { // Indication that the lifetime was elided (e.g., in both cases in // `fn foo(x: &u8) -> &'_ u8 { x }`). - Elided, + Elided(MissingLifetimeKind), // Indication that the lifetime name was somehow in error. Error, @@ -512,7 +520,7 @@ impl<'hir> GenericParam<'hir> { /// /// See `lifetime_to_generic_param` in `rustc_ast_lowering` for more information. pub fn is_elided_lifetime(&self) -> bool { - matches!(self.kind, GenericParamKind::Lifetime { kind: LifetimeParamKind::Elided }) + matches!(self.kind, GenericParamKind::Lifetime { kind: LifetimeParamKind::Elided(_) }) } } @@ -1003,7 +1011,7 @@ impl<'hir> Pat<'hir> { use PatKind::*; match self.kind { Wild | Never | Lit(_) | Range(..) | Binding(.., None) | Path(_) | Err(_) => true, - Box(s) | Ref(s, _) | Binding(.., Some(s)) => s.walk_short_(it), + Box(s) | Deref(s) | Ref(s, _) | Binding(.., Some(s)) => s.walk_short_(it), Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk_short_(it)), TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().all(|p| p.walk_short_(it)), Slice(before, slice, after) => { @@ -1030,7 +1038,7 @@ impl<'hir> Pat<'hir> { use PatKind::*; match self.kind { Wild | Never | Lit(_) | Range(..) | Binding(.., None) | Path(_) | Err(_) => {} - Box(s) | Ref(s, _) | Binding(.., Some(s)) => s.walk_(it), + Box(s) | Deref(s) | Ref(s, _) | Binding(.., Some(s)) => s.walk_(it), Struct(_, fields, _) => fields.iter().for_each(|field| field.pat.walk_(it)), TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().for_each(|p| p.walk_(it)), Slice(before, slice, after) => { @@ -1173,6 +1181,9 @@ pub enum PatKind<'hir> { /// A `box` pattern. Box(&'hir Pat<'hir>), + /// A `deref` pattern (currently `deref!()` macro-based syntax). + Deref(&'hir Pat<'hir>), + /// A reference pattern (e.g., `&mut (a, b)`). Ref(&'hir Pat<'hir>, Mutability), @@ -1259,7 +1270,7 @@ pub struct Arm<'hir> { /// In an `if let`, imagine it as `if (let <pat> = <expr>) { ... }`; in a let-else, it is part of /// the desugaring to if-let. Only let-else supports the type annotation at present. #[derive(Debug, Clone, Copy, HashStable_Generic)] -pub struct Let<'hir> { +pub struct LetExpr<'hir> { pub span: Span, pub pat: &'hir Pat<'hir>, pub ty: Option<&'hir Ty<'hir>>, @@ -1845,14 +1856,14 @@ pub enum ExprKind<'hir> { /// Wraps the expression in a terminating scope. /// This makes it semantically equivalent to `{ let _t = expr; _t }`. /// - /// This construct only exists to tweak the drop order in HIR lowering. + /// This construct only exists to tweak the drop order in AST lowering. /// An example of that is the desugaring of `for` loops. DropTemps(&'hir Expr<'hir>), /// A `let $pat = $expr` expression. /// /// These are not `Local` and only occur as expressions. /// The `let Some(x) = foo()` in `if let Some(x) = foo()` is an example of `Let(..)`. - Let(&'hir Let<'hir>), + Let(&'hir LetExpr<'hir>), /// An `if` block, with an optional else block. /// /// I.e., `if <expr> { <expr> } else { <expr> }`. @@ -2004,6 +2015,8 @@ pub enum LocalSource { pub enum MatchSource { /// A `match _ { .. }`. Normal, + /// A `expr.match { .. }`. + Postfix, /// A desugared `for _ in _ { .. }` loop. ForLoopDesugar, /// A desugared `?` operator. @@ -2020,6 +2033,7 @@ impl MatchSource { use MatchSource::*; match self { Normal => "match", + Postfix => ".match", ForLoopDesugar => "for", TryDesugar(_) => "?", AwaitDesugar => ".await", @@ -2049,7 +2063,7 @@ impl LoopSource { } } -#[derive(Copy, Clone, Debug, HashStable_Generic)] +#[derive(Copy, Clone, Debug, PartialEq, HashStable_Generic)] pub enum LoopIdError { OutsideLoopScope, UnlabeledCfInWhileCondition, @@ -2278,7 +2292,7 @@ pub enum ImplItemKind<'hir> { /// Bind a type to an associated type (i.e., `A = Foo`). /// /// Bindings like `A: Debug` are represented as a special type `A = -/// $::Debug` that is understood by the astconv code. +/// $::Debug` that is understood by the HIR ty lowering code. /// /// FIXME(alexreg): why have a separate type for the binding case, /// wouldn't it be better to make the `ty` field an enum like the @@ -2444,7 +2458,7 @@ pub enum PrimTy { impl PrimTy { /// All of the primitive types - pub const ALL: [Self; 17] = [ + pub const ALL: [Self; 19] = [ // any changes here should also be reflected in `PrimTy::from_name` Self::Int(IntTy::I8), Self::Int(IntTy::I16), @@ -2458,9 +2472,10 @@ impl PrimTy { Self::Uint(UintTy::U64), Self::Uint(UintTy::U128), Self::Uint(UintTy::Usize), + Self::Float(FloatTy::F16), Self::Float(FloatTy::F32), Self::Float(FloatTy::F64), - // FIXME(f16_f128): add these when enabled below + Self::Float(FloatTy::F128), Self::Bool, Self::Char, Self::Str, @@ -2508,12 +2523,10 @@ impl PrimTy { sym::u64 => Self::Uint(UintTy::U64), sym::u128 => Self::Uint(UintTy::U128), sym::usize => Self::Uint(UintTy::Usize), + sym::f16 => Self::Float(FloatTy::F16), sym::f32 => Self::Float(FloatTy::F32), sym::f64 => Self::Float(FloatTy::F64), - // FIXME(f16_f128): enabling these will open the gates of f16 and f128 being - // understood by rustc. - // sym::f16 => Self::Float(FloatTy::F16), - // sym::f128 => Self::Float(FloatTy::F128), + sym::f128 => Self::Float(FloatTy::F128), sym::bool => Self::Bool, sym::char => Self::Char, sym::str => Self::Str, @@ -2553,11 +2566,6 @@ pub struct OpaqueTy<'hir> { pub in_trait: bool, } -#[derive(Copy, Clone, Debug, HashStable_Generic)] -pub struct AssocOpaqueTy { - // Add some data if necessary -} - /// From whence the opaque type came. #[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable_Generic)] pub enum OpaqueTyOrigin { @@ -3368,7 +3376,7 @@ pub enum OwnerNode<'hir> { TraitItem(&'hir TraitItem<'hir>), ImplItem(&'hir ImplItem<'hir>), Crate(&'hir Mod<'hir>), - AssocOpaqueTy(&'hir AssocOpaqueTy), + Synthetic, } impl<'hir> OwnerNode<'hir> { @@ -3378,7 +3386,7 @@ impl<'hir> OwnerNode<'hir> { | OwnerNode::ForeignItem(ForeignItem { ident, .. }) | OwnerNode::ImplItem(ImplItem { ident, .. }) | OwnerNode::TraitItem(TraitItem { ident, .. }) => Some(*ident), - OwnerNode::Crate(..) | OwnerNode::AssocOpaqueTy(..) => None, + OwnerNode::Crate(..) | OwnerNode::Synthetic => None, } } @@ -3391,7 +3399,7 @@ impl<'hir> OwnerNode<'hir> { | OwnerNode::ImplItem(ImplItem { span, .. }) | OwnerNode::TraitItem(TraitItem { span, .. }) => span, OwnerNode::Crate(Mod { spans: ModSpans { inner_span, .. }, .. }) => inner_span, - OwnerNode::AssocOpaqueTy(..) => unreachable!(), + OwnerNode::Synthetic => unreachable!(), } } @@ -3450,7 +3458,7 @@ impl<'hir> OwnerNode<'hir> { | OwnerNode::ImplItem(ImplItem { owner_id, .. }) | OwnerNode::ForeignItem(ForeignItem { owner_id, .. }) => *owner_id, OwnerNode::Crate(..) => crate::CRATE_HIR_ID.owner, - OwnerNode::AssocOpaqueTy(..) => unreachable!(), + OwnerNode::Synthetic => unreachable!(), } } @@ -3494,7 +3502,7 @@ impl<'hir> Into<Node<'hir>> for OwnerNode<'hir> { OwnerNode::ImplItem(n) => Node::ImplItem(n), OwnerNode::TraitItem(n) => Node::TraitItem(n), OwnerNode::Crate(n) => Node::Crate(n), - OwnerNode::AssocOpaqueTy(n) => Node::AssocOpaqueTy(n), + OwnerNode::Synthetic => Node::Synthetic, } } } @@ -3532,7 +3540,8 @@ pub enum Node<'hir> { WhereBoundPredicate(&'hir WhereBoundPredicate<'hir>), // FIXME: Merge into `Node::Infer`. ArrayLenInfer(&'hir InferArg), - AssocOpaqueTy(&'hir AssocOpaqueTy), + // Created by query feeding + Synthetic, // Span by reference to minimize `Node`'s size #[allow(rustc::pass_by_value)] Err(&'hir Span), @@ -3583,7 +3592,7 @@ impl<'hir> Node<'hir> { | Node::Infer(..) | Node::WhereBoundPredicate(..) | Node::ArrayLenInfer(..) - | Node::AssocOpaqueTy(..) + | Node::Synthetic | Node::Err(..) => None, } } @@ -3641,35 +3650,42 @@ impl<'hir> Node<'hir> { } } - pub fn body_id(&self) -> Option<BodyId> { + #[inline] + pub fn associated_body(&self) -> Option<(LocalDefId, BodyId)> { match self { Node::Item(Item { + owner_id, kind: - ItemKind::Static(_, _, body) - | ItemKind::Const(_, _, body) - | ItemKind::Fn(_, _, body), + ItemKind::Const(_, _, body) | ItemKind::Static(.., body) | ItemKind::Fn(.., body), .. }) | Node::TraitItem(TraitItem { + owner_id, kind: - TraitItemKind::Fn(_, TraitFn::Provided(body)) | TraitItemKind::Const(_, Some(body)), + TraitItemKind::Const(_, Some(body)) | TraitItemKind::Fn(_, TraitFn::Provided(body)), .. }) | Node::ImplItem(ImplItem { - kind: ImplItemKind::Fn(_, body) | ImplItemKind::Const(_, body), + owner_id, + kind: ImplItemKind::Const(_, body) | ImplItemKind::Fn(_, body), .. - }) - | Node::Expr(Expr { - kind: - ExprKind::ConstBlock(ConstBlock { body, .. }) - | ExprKind::Closure(Closure { body, .. }) - | ExprKind::Repeat(_, ArrayLen::Body(AnonConst { body, .. })), - .. - }) => Some(*body), + }) => Some((owner_id.def_id, *body)), + + Node::Expr(Expr { kind: ExprKind::Closure(Closure { def_id, body, .. }), .. }) => { + Some((*def_id, *body)) + } + + Node::AnonConst(constant) => Some((constant.def_id, constant.body)), + Node::ConstBlock(constant) => Some((constant.def_id, constant.body)), + _ => None, } } + pub fn body_id(&self) -> Option<BodyId> { + Some(self.associated_body()?.1) + } + pub fn generics(self) -> Option<&'hir Generics<'hir>> { match self { Node::ForeignItem(ForeignItem { @@ -3689,7 +3705,7 @@ impl<'hir> Node<'hir> { Node::TraitItem(i) => Some(OwnerNode::TraitItem(i)), Node::ImplItem(i) => Some(OwnerNode::ImplItem(i)), Node::Crate(i) => Some(OwnerNode::Crate(i)), - Node::AssocOpaqueTy(i) => Some(OwnerNode::AssocOpaqueTy(i)), + Node::Synthetic => Some(OwnerNode::Synthetic), _ => None, } } diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index fbbad38d17f..468c7fd5c73 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -660,7 +660,9 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) -> V: PatKind::Tuple(tuple_elements, _) => { walk_list!(visitor, visit_pat, tuple_elements); } - PatKind::Box(ref subpattern) | PatKind::Ref(ref subpattern, _) => { + PatKind::Box(ref subpattern) + | PatKind::Deref(ref subpattern) + | PatKind::Ref(ref subpattern, _) => { try_visit!(visitor.visit_pat(subpattern)); } PatKind::Binding(_, _hir_id, ident, ref optional_subpattern) => { @@ -753,7 +755,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) ExprKind::DropTemps(ref subexpression) => { try_visit!(visitor.visit_expr(subexpression)); } - ExprKind::Let(Let { span: _, pat, ty, init, is_recovered: _ }) => { + ExprKind::Let(LetExpr { span: _, pat, ty, init, is_recovered: _ }) => { // match the visit order in walk_local try_visit!(visitor.visit_expr(init)); try_visit!(visitor.visit_pat(pat)); @@ -899,7 +901,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>( GenericParamKind::Const { ref ty, ref default, is_host_effect: _ } => { try_visit!(visitor.visit_ty(ty)); if let Some(ref default) = default { - visitor.visit_const_param_default(param.hir_id, default); + try_visit!(visitor.visit_const_param_default(param.hir_id, default)); } } } diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 5118bf5c3b7..dbf86f5cf74 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -214,6 +214,7 @@ language_item_table! { FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None; Iterator, sym::iterator, iterator_trait, Target::Trait, GenericRequirement::Exact(0); + FusedIterator, sym::fused_iterator, fused_iterator_trait, Target::Trait, GenericRequirement::Exact(0); Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0); AsyncIterator, sym::async_iterator, async_iterator_trait, Target::Trait, GenericRequirement::Exact(0); diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index 9921686ce28..c5c4075c6ba 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -5,7 +5,6 @@ #![feature(associated_type_defaults)] #![feature(closure_track_caller)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(min_specialization))] #![feature(never_type)] #![feature(rustc_attrs)] #![feature(variant_count)] diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index bad472dcb5c..9bf4d63267a 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -118,6 +118,11 @@ hir_analysis_enum_discriminant_overflowed = enum discriminant overflowed .label = overflowed on value after {$discr} .note = explicitly set `{$item_name} = {$wrapped_discr}` if that is desired outcome +hir_analysis_escaping_bound_var_in_ty_of_assoc_const_binding = + the type of the associated constant `{$assoc_const}` cannot capture late-bound generic parameters + .label = its type cannot capture the late-bound {$var_def_kind} `{$var_name}` + .var_defined_here_label = the late-bound {$var_def_kind} `{$var_name}` is defined here + hir_analysis_field_already_declared = field `{$field_name}` is already declared .label = field already declared @@ -316,6 +321,22 @@ hir_analysis_opaque_captures_higher_ranked_lifetime = `impl Trait` cannot captur .label = `impl Trait` implicitly captures all lifetimes in scope .note = lifetime declared here +hir_analysis_param_in_ty_of_assoc_const_binding = + the type of the associated constant `{$assoc_const}` must not depend on {$param_category -> + [self] `Self` + [synthetic] `impl Trait` + *[normal] generic parameters + } + .label = its type must not depend on {$param_category -> + [self] `Self` + [synthetic] `impl Trait` + *[normal] the {$param_def_kind} `{$param_name}` + } + .param_defined_here_label = {$param_category -> + [synthetic] the `impl Trait` is specified here + *[normal] the {$param_def_kind} `{$param_name}` is defined here + } + hir_analysis_paren_sugar_attribute = the `#[rustc_paren_sugar]` attribute is a temporary means of controlling which traits can use parenthetical notation .help = add `#![feature(unboxed_closures)]` to the crate attributes to use it @@ -351,6 +372,7 @@ hir_analysis_rpitit_refined = impl trait in impl method signature does not match .label = return type from trait method defined here .unmatched_bound_label = this bound is stronger than that defined on the trait .note = add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + .feedback_note = we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information hir_analysis_self_in_impl_self = `Self` is not valid in the self type of an impl block @@ -431,6 +453,8 @@ hir_analysis_transparent_non_zero_sized_enum = the variant of a transparent {$de .label = needs at most one field with non-trivial size or alignment, but has {$field_count} .labels = this field has non-zero size or requires alignment +hir_analysis_ty_of_assoc_const_binding_note = `{$assoc_const}` has type `{$ty}` + hir_analysis_ty_param_first_local = type parameter `{$param_ty}` must be covered by another type when it appears before the first local type (`{$local_type}`) .label = type parameter `{$param_ty}` must be covered by another type when it appears before the first local type (`{$local_type}`) .note = implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type diff --git a/compiler/rustc_hir_analysis/src/bounds.rs b/compiler/rustc_hir_analysis/src/bounds.rs index b69f679880d..d659d2c5235 100644 --- a/compiler/rustc_hir_analysis/src/bounds.rs +++ b/compiler/rustc_hir_analysis/src/bounds.rs @@ -1,5 +1,5 @@ -//! Bounds are restrictions applied to some types after they've been converted into the -//! `ty` form from the HIR. +//! Bounds are restrictions applied to some types after they've been lowered from the HIR to the +//! [`rustc_middle::ty`] form. use rustc_hir::LangItem; use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt}; diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index d1fed13ee9f..09b20917e2a 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -382,8 +382,8 @@ fn check_opaque_meets_bounds<'tcx>( Ok(()) => {} Err(ty_err) => { // Some types may be left "stranded" if they can't be reached - // from an astconv'd bound but they're mentioned in the HIR. This - // will happen, e.g., when a nested opaque is inside of a non- + // from a lowered rustc_middle bound but they're mentioned in the HIR. + // This will happen, e.g., when a nested opaque is inside of a non- // existent associated type, like `impl Trait<Missing = impl Trait>`. // See <tests/ui/impl-trait/stranded-opaque.rs>. let ty_err = ty_err.to_string(tcx); diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index ec9e928ce59..8fb6569aa14 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -746,7 +746,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( // We may not collect all RPITITs that we see in the HIR for a trait signature // because an RPITIT was located within a missing item. Like if we have a sig - // returning `-> Missing<impl Sized>`, that gets converted to `-> [type error]`, + // returning `-> Missing<impl Sized>`, that gets converted to `-> {type error}`, // and when walking through the signature we end up never collecting the def id // of the `impl Sized`. Insert that here, so we don't ICE later. for assoc_item in tcx.associated_types_for_impl_traits_in_associated_fn(trait_m.def_id) { @@ -1305,7 +1305,7 @@ fn compare_number_of_generics<'tcx>( .iter() .filter(|p| match p.kind { hir::GenericParamKind::Lifetime { - kind: hir::LifetimeParamKind::Elided, + kind: hir::LifetimeParamKind::Elided(_), } => { // A fn can have an arbitrary number of extra elided lifetimes for the // same signature. diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index 8c4c4fc774e..a2a20082bb0 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -2,7 +2,7 @@ use rustc_data_structures::fx::FxIndexSet; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer::{outlives::env::OutlivesEnvironment, TyCtxtInferExt}; -use rustc_lint_defs::builtin::REFINING_IMPL_TRAIT; +use rustc_lint_defs::builtin::{REFINING_IMPL_TRAIT_INTERNAL, REFINING_IMPL_TRAIT_REACHABLE}; use rustc_middle::traits::{ObligationCause, Reveal}; use rustc_middle::ty::{ self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable, TypeVisitor, @@ -23,26 +23,23 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>( if !tcx.impl_method_has_trait_impl_trait_tys(impl_m.def_id) { return; } + // unreachable traits don't have any library guarantees, there's no need to do this check. - if trait_m + let is_internal = trait_m .container_id(tcx) .as_local() .is_some_and(|trait_def_id| !tcx.effective_visibilities(()).is_reachable(trait_def_id)) - { - return; - } + // If a type in the trait ref is private, then there's also no reason to do this check. + || impl_trait_ref.args.iter().any(|arg| { + if let Some(ty) = arg.as_type() + && let Some(self_visibility) = type_visibility(tcx, ty) + { + return !self_visibility.is_public(); + } + false + }); - // If a type in the trait ref is private, then there's also no reason to do this check. let impl_def_id = impl_m.container_id(tcx); - for arg in impl_trait_ref.args { - if let Some(ty) = arg.as_type() - && let Some(self_visibility) = type_visibility(tcx, ty) - && !self_visibility.is_public() - { - return; - } - } - let impl_m_args = ty::GenericArgs::identity_for_item(tcx, impl_m.def_id); let trait_m_to_impl_m_args = impl_m_args.rebase_onto(tcx, impl_def_id, impl_trait_ref.args); let bound_trait_m_sig = tcx.fn_sig(trait_m.def_id).instantiate(tcx, trait_m_to_impl_m_args); @@ -85,6 +82,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>( trait_m.def_id, impl_m.def_id, None, + is_internal, ); return; }; @@ -104,6 +102,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>( trait_m.def_id, impl_m.def_id, None, + is_internal, ); return; } @@ -198,6 +197,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>( trait_m.def_id, impl_m.def_id, Some(span), + is_internal, ); return; } @@ -235,6 +235,7 @@ fn report_mismatched_rpitit_signature<'tcx>( trait_m_def_id: DefId, impl_m_def_id: DefId, unmatched_bound: Option<Span>, + is_internal: bool, ) { let mapping = std::iter::zip( tcx.fn_sig(trait_m_def_id).skip_binder().bound_vars(), @@ -287,7 +288,7 @@ fn report_mismatched_rpitit_signature<'tcx>( let span = unmatched_bound.unwrap_or(span); tcx.emit_node_span_lint( - REFINING_IMPL_TRAIT, + if is_internal { REFINING_IMPL_TRAIT_INTERNAL } else { REFINING_IMPL_TRAIT_REACHABLE }, tcx.local_def_id_to_hir_id(impl_m_def_id.expect_local()), span, crate::errors::ReturnPositionImplTraitInTraitRefined { diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index bf5838143d9..07054c184f4 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -441,7 +441,7 @@ pub fn check_intrinsic_type( sym::ptr_guaranteed_cmp => ( 1, - 0, + 1, vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))], tcx.types.u8, ), @@ -579,7 +579,7 @@ pub fn check_intrinsic_type( sym::is_val_statically_known => (1, 1, vec![param(0)], tcx.types.bool), - sym::const_eval_select => (4, 0, vec![param(0), param(1), param(2)], param(3)), + sym::const_eval_select => (4, 1, vec![param(0), param(1), param(2)], param(3)), sym::vtable_size | sym::vtable_align => { (0, 0, vec![Ty::new_imm_ptr(tcx, Ty::new_unit(tcx))], tcx.types.usize) @@ -658,10 +658,6 @@ pub fn check_intrinsic_type( sym::simd_shuffle => (3, 0, vec![param(0), param(0), param(1)], param(2)), sym::simd_shuffle_generic => (2, 1, vec![param(0), param(0)], param(1)), - sym::retag_box_to_raw => { - (2, 0, vec![Ty::new_mut_ptr(tcx, param(0))], Ty::new_mut_ptr(tcx, param(0))) - } - other => { tcx.dcx().emit_err(UnrecognizedIntrinsicFunction { span, name: other }); return; diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 22afddad633..8760901b71b 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -291,12 +291,16 @@ fn default_body_is_unstable( reason: reason_str, }); + let inject_span = item_did + .as_local() + .and_then(|id| tcx.crate_level_attribute_injection_span(tcx.local_def_id_to_hir_id(id))); rustc_session::parse::add_feature_diagnostics_for_issue( &mut err, &tcx.sess, feature, rustc_feature::GateIssue::Library(issue), false, + inject_span, ); err.emit(); @@ -427,7 +431,7 @@ fn fn_sig_suggestion<'tcx>( let asyncness = if tcx.asyncness(assoc.def_id).is_async() { output = if let ty::Alias(_, alias_ty) = *output.kind() { - tcx.explicit_item_bounds(alias_ty.def_id) + tcx.explicit_item_super_predicates(alias_ty.def_id) .iter_instantiated_copied(tcx, alias_ty.args) .find_map(|(bound, _)| bound.as_projection_clause()?.no_bound_vars()?.term.ty()) .unwrap_or_else(|| { diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs index 3c26729eff8..e84bce92fc5 100644 --- a/compiler/rustc_hir_analysis/src/check/region.rs +++ b/compiler/rustc_hir_analysis/src/check/region.rs @@ -668,7 +668,7 @@ fn resolve_local<'tcx>( | PatKind::TupleStruct(_, subpats, _) | PatKind::Tuple(subpats, _) => subpats.iter().any(|p| is_binding_pat(p)), - PatKind::Box(subpat) => is_binding_pat(subpat), + PatKind::Box(subpat) | PatKind::Deref(subpat) => is_binding_pat(subpat), PatKind::Ref(_, _) | PatKind::Binding(hir::BindingAnnotation(hir::ByRef::No, _), ..) @@ -760,7 +760,7 @@ impl<'tcx> RegionResolutionVisitor<'tcx> { fn enter_node_scope_with_dtor(&mut self, id: hir::ItemLocalId) { // If node was previously marked as a terminating scope during the - // recursive visit of its parent node in the AST, then we need to + // recursive visit of its parent node in the HIR, then we need to // account for the destruction scope representing the scope of // the destructors that run immediately after it completes. if self.terminating_scopes.contains(&id) { diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index f5250045344..2b4a35d0b9b 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -196,7 +196,7 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: hir::OwnerId) -> Result<(), ErrorG hir::OwnerNode::TraitItem(item) => check_trait_item(tcx, item), hir::OwnerNode::ImplItem(item) => check_impl_item(tcx, item), hir::OwnerNode::ForeignItem(item) => check_foreign_item(tcx, item), - hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(), + hir::OwnerNode::Synthetic => unreachable!(), }; if let Some(generics) = node.generics() { @@ -272,7 +272,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<() } Some(ty::ImplPolarity::Negative) => { let ast::ImplPolarity::Negative(span) = impl_.polarity else { - bug!("impl_polarity query disagrees with impl's polarity in AST"); + bug!("impl_polarity query disagrees with impl's polarity in HIR"); }; // FIXME(#27579): what amount of WF checking do we need for neg impls? if let hir::Defaultness::Default { .. } = impl_.defaultness { @@ -999,9 +999,14 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(), // Implments `ConstParamTy`, suggest adding the feature to enable. Ok(..) => true, }; - if may_suggest_feature && tcx.sess.is_nightly_build() { - diag.help( - "add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types", + if may_suggest_feature { + tcx.disabled_nightly_features( + &mut diag, + Some(param.hir_id), + [( + " more complex and user defined types".to_string(), + sym::adt_const_params, + )], ); } @@ -1861,7 +1866,7 @@ fn check_variances_for_type_defn<'tcx>( .iter() .filter_map(|predicate| match predicate { hir::WherePredicate::BoundPredicate(predicate) => { - match icx.to_ty(predicate.bounded_ty).kind() { + match icx.lower_ty(predicate.bounded_ty).kind() { ty::Param(data) => Some(Parameter(data.index)), _ => None, } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 5cd6862786b..a705d3bc107 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -40,9 +40,9 @@ use std::cell::Cell; use std::iter; use std::ops::Bound; -use crate::astconv::AstConv; use crate::check::intrinsic::intrinsic_operation_unsafety; use crate::errors; +use crate::hir_ty_lowering::HirTyLowerer; pub use type_of::test_opaque_hidden_types; mod generics_of; @@ -61,6 +61,9 @@ pub fn provide(providers: &mut Providers) { type_alias_is_lazy: type_of::type_alias_is_lazy, item_bounds: item_bounds::item_bounds, explicit_item_bounds: item_bounds::explicit_item_bounds, + item_super_predicates: item_bounds::item_super_predicates, + explicit_item_super_predicates: item_bounds::explicit_item_super_predicates, + item_non_self_assumptions: item_bounds::item_non_self_assumptions, generics_of: generics_of::generics_of, predicates_of: predicates_of::predicates_of, predicates_defined_on, @@ -85,13 +88,12 @@ pub fn provide(providers: &mut Providers) { /////////////////////////////////////////////////////////////////////////// -/// Context specific to some particular item. This is what implements -/// [`AstConv`]. +/// Context specific to some particular item. This is what implements [`HirTyLowerer`]. /// /// # `ItemCtxt` vs `FnCtxt` /// /// `ItemCtxt` is primarily used to type-check item signatures and lower them -/// from HIR to their [`ty::Ty`] representation, which is exposed using [`AstConv`]. +/// from HIR to their [`ty::Ty`] representation, which is exposed using [`HirTyLowerer`]. /// It's also used for the bodies of items like structs where the body (the fields) /// are just signatures. /// @@ -108,11 +110,11 @@ pub fn provide(providers: &mut Providers) { /// `ItemCtxt` has information about the predicates that are defined /// on the trait. Unfortunately, this predicate information is /// available in various different forms at various points in the -/// process. So we can't just store a pointer to e.g., the AST or the +/// process. So we can't just store a pointer to e.g., the HIR or the /// parsed ty form, we have to be more flexible. To this end, the /// `ItemCtxt` is parameterized by a `DefId` that it uses to satisfy -/// `get_type_parameter_bounds` requests, drawing the information from -/// the AST (`hir::Generics`), recursively. +/// `probe_ty_param_bounds` requests, drawing the information from +/// the HIR (`hir::Generics`), recursively. pub struct ItemCtxt<'tcx> { tcx: TyCtxt<'tcx>, item_def_id: LocalDefId, @@ -274,7 +276,7 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { } fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { - convert_item(self.tcx, item.item_id()); + lower_item(self.tcx, item.item_id()); reject_placeholder_type_signatures_in_item(self.tcx, item); intravisit::walk_item(self, item); } @@ -312,12 +314,12 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { } fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { - convert_trait_item(self.tcx, trait_item.trait_item_id()); + lower_trait_item(self.tcx, trait_item.trait_item_id()); intravisit::walk_trait_item(self, trait_item); } fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { - convert_impl_item(self.tcx, impl_item.impl_item_id()); + lower_impl_item(self.tcx, impl_item.impl_item_id()); intravisit::walk_impl_item(self, impl_item); } } @@ -341,8 +343,8 @@ impl<'tcx> ItemCtxt<'tcx> { ItemCtxt { tcx, item_def_id, tainted_by_errors: Cell::new(None) } } - pub fn to_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { - self.astconv().ast_ty_to_ty(ast_ty) + pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { + self.lowerer().lower_ty(hir_ty) } pub fn hir_id(&self) -> hir::HirId { @@ -361,7 +363,7 @@ impl<'tcx> ItemCtxt<'tcx> { } } -impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { +impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { fn tcx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -370,23 +372,14 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { self.item_def_id.to_def_id() } - fn get_type_parameter_bounds( - &self, - span: Span, - def_id: LocalDefId, - assoc_name: Ident, - ) -> ty::GenericPredicates<'tcx> { - self.tcx.at(span).type_param_predicates((self.item_def_id, def_id, assoc_name)) + fn allow_infer(&self) -> bool { + false } fn re_infer(&self, _: Option<&ty::GenericParamDef>, _: Span) -> Option<ty::Region<'tcx>> { None } - fn allow_ty_infer(&self) -> bool { - false - } - fn ty_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> { Ty::new_error_with_message(self.tcx(), span, "bad placeholder type") } @@ -401,7 +394,16 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { ty::Const::new_error_with_message(self.tcx(), ty, span, "bad placeholder constant") } - fn projected_ty_from_poly_trait_ref( + fn probe_ty_param_bounds( + &self, + span: Span, + def_id: LocalDefId, + assoc_name: Ident, + ) -> ty::GenericPredicates<'tcx> { + self.tcx.at(span).type_param_predicates((self.item_def_id, def_id, assoc_name)) + } + + fn lower_assoc_ty( &self, span: Span, item_def_id: DefId, @@ -409,7 +411,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { poly_trait_ref: ty::PolyTraitRef<'tcx>, ) -> Ty<'tcx> { if let Some(trait_ref) = poly_trait_ref.no_bound_vars() { - let item_args = self.astconv().create_args_for_associated_item( + let item_args = self.lowerer().lower_generic_args_of_assoc_item( span, item_def_id, item_segment, @@ -494,10 +496,6 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { ty.ty_adt_def() } - fn set_tainted_by_errors(&self, err: ErrorGuaranteed) { - self.tainted_by_errors.set(Some(err)); - } - fn record_ty(&self, _hir_id: hir::HirId, _ty: Ty<'tcx>, _span: Span) { // There's no place to record types from signatures? } @@ -505,6 +503,10 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { fn infcx(&self) -> Option<&InferCtxt<'tcx>> { None } + + fn set_tainted_by_errors(&self, err: ErrorGuaranteed) { + self.tainted_by_errors.set(Some(err)); + } } /// Synthesize a new lifetime name that doesn't clash with any of the lifetimes already present. @@ -544,9 +546,10 @@ fn get_new_lifetime_name<'tcx>( (1..).flat_map(a_to_z_repeat_n).find(|lt| !existing_lifetimes.contains(lt.as_str())).unwrap() } -fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { +#[instrument(level = "debug", skip_all)] +fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { let it = tcx.hir().item(item_id); - debug!("convert: item {} with id {}", it.ident, it.hir_id()); + debug!(item = %it.ident, id = %it.hir_id()); let def_id = item_id.owner_id.def_id; match &it.kind { @@ -588,7 +591,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { tcx.ensure().generics_of(def_id); tcx.ensure().type_of(def_id); tcx.ensure().predicates_of(def_id); - convert_enum_variant_types(tcx, def_id.to_def_id()); + lower_enum_variant_types(tcx, def_id.to_def_id()); } hir::ItemKind::Impl { .. } => { tcx.ensure().generics_of(def_id); @@ -622,7 +625,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { } if let Some(ctor_def_id) = struct_def.ctor_def_id() { - convert_variant_ctor(tcx, ctor_def_id); + lower_variant_ctor(tcx, ctor_def_id); } } @@ -633,7 +636,9 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { tcx.ensure().generics_of(def_id); tcx.ensure().predicates_of(def_id); tcx.ensure().explicit_item_bounds(def_id); + tcx.ensure().explicit_item_super_predicates(def_id); tcx.ensure().item_bounds(def_id); + tcx.ensure().item_super_predicates(def_id); } hir::ItemKind::TyAlias(..) => { @@ -663,7 +668,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { } } -fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { +fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { let trait_item = tcx.hir().trait_item(trait_item_id); let def_id = trait_item_id.owner_id; tcx.ensure().generics_of(def_id); @@ -689,6 +694,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { hir::TraitItemKind::Type(_, Some(_)) => { tcx.ensure().item_bounds(def_id); + tcx.ensure().item_super_predicates(def_id); tcx.ensure().type_of(def_id); // Account for `type T = _;`. let mut visitor = HirPlaceholderCollector::default(); @@ -698,6 +704,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { hir::TraitItemKind::Type(_, None) => { tcx.ensure().item_bounds(def_id); + tcx.ensure().item_super_predicates(def_id); // #74612: Visit and try to find bad placeholders // even if there is no concrete type. let mut visitor = HirPlaceholderCollector::default(); @@ -710,7 +717,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { tcx.ensure().predicates_of(def_id); } -fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { +fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { let def_id = impl_item_id.owner_id; tcx.ensure().generics_of(def_id); tcx.ensure().type_of(def_id); @@ -739,13 +746,13 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { } } -fn convert_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) { +fn lower_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) { tcx.ensure().generics_of(def_id); tcx.ensure().type_of(def_id); tcx.ensure().predicates_of(def_id); } -fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) { +fn lower_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) { let def = tcx.adt_def(def_id); let repr_type = def.repr().discr_type(); let initial = repr_type.initial_discriminant(tcx); @@ -778,10 +785,9 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) { tcx.ensure().predicates_of(f.did); } - // Convert the ctor, if any. This also registers the variant as - // an item. + // Lower the ctor, if any. This also registers the variant as an item. if let Some(ctor_def_id) = variant.ctor_def_id() { - convert_variant_ctor(tcx, ctor_def_id.expect_local()); + lower_variant_ctor(tcx, ctor_def_id.expect_local()); } } } @@ -968,7 +974,7 @@ impl<'tcx> FieldUniquenessCheckContext<'tcx> { } } -fn convert_variant( +fn lower_variant( tcx: TyCtxt<'_>, variant_did: Option<LocalDefId>, ident: Ident, @@ -1053,7 +1059,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> { }; distance_from_explicit += 1; - convert_variant( + lower_variant( tcx, Some(v.def_id), v.ident, @@ -1073,7 +1079,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> { ItemKind::Struct(..) => AdtKind::Struct, _ => AdtKind::Union, }; - let variants = std::iter::once(convert_variant( + let variants = std::iter::once(lower_variant( tcx, None, item.ident, @@ -1277,7 +1283,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig< if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) = tcx.parent_hir_node(hir_id) && i.of_trait.is_some() { - icx.astconv().ty_of_fn( + icx.lowerer().lower_fn_ty( hir_id, sig.header.unsafety, sig.header.abi, @@ -1294,9 +1300,14 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig< kind: TraitItemKind::Fn(FnSig { header, decl, span: _ }, _), generics, .. - }) => { - icx.astconv().ty_of_fn(hir_id, header.unsafety, header.abi, decl, Some(generics), None) - } + }) => icx.lowerer().lower_fn_ty( + hir_id, + header.unsafety, + header.abi, + decl, + Some(generics), + None, + ), ForeignItem(&hir::ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => { let abi = tcx.hir().get_foreign_abi(hir_id); @@ -1364,7 +1375,7 @@ fn infer_return_ty_for_fn_sig<'tcx>( // recursive function definition to leak out into the fn sig. let mut should_recover = false; - if let Some(ret_ty) = ret_ty.make_suggestable(tcx, false) { + if let Some(ret_ty) = ret_ty.make_suggestable(tcx, false, None) { diag.span_suggestion( ty.span, "replace with the correct return type", @@ -1404,7 +1415,7 @@ fn infer_return_ty_for_fn_sig<'tcx>( )) } } - None => icx.astconv().ty_of_fn( + None => icx.lowerer().lower_fn_ty( hir_id, sig.header.unsafety, sig.header.abi, @@ -1442,7 +1453,7 @@ fn suggest_impl_trait<'tcx>( let ty::Tuple(types) = *args_tuple.kind() else { return None; }; - let types = types.make_suggestable(tcx, false)?; + let types = types.make_suggestable(tcx, false, None)?; let maybe_ret = if item_ty.is_unit() { String::new() } else { format!(" -> {item_ty}") }; Some(format!( @@ -1500,7 +1511,7 @@ fn suggest_impl_trait<'tcx>( // FIXME(compiler-errors): We may benefit from resolving regions here. if ocx.select_where_possible().is_empty() && let item_ty = infcx.resolve_vars_if_possible(item_ty) - && let Some(item_ty) = item_ty.make_suggestable(tcx, false) + && let Some(item_ty) = item_ty.make_suggestable(tcx, false, None) && let Some(sugg) = formatter( tcx, infcx.resolve_vars_if_possible(args), @@ -1522,19 +1533,19 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::ImplTrai impl_ .of_trait .as_ref() - .map(|ast_trait_ref| { - let selfty = tcx.type_of(def_id).instantiate_identity(); + .map(|hir_trait_ref| { + let self_ty = tcx.type_of(def_id).instantiate_identity(); let trait_ref = if let Some(ErrorGuaranteed { .. }) = check_impl_constness( tcx, tcx.is_const_trait_impl_raw(def_id.to_def_id()), - ast_trait_ref, + hir_trait_ref, ) { // we have a const impl, but for a trait without `#[const_trait]`, so // without the host param. If we continue with the HIR trait ref, we get // ICEs for generic arg count mismatch. We do a little HIR editing to - // make astconv happy. - let mut path_segments = ast_trait_ref.path.segments.to_vec(); + // make HIR ty lowering happy. + let mut path_segments = hir_trait_ref.path.segments.to_vec(); let last_segment = path_segments.len() - 1; let mut args = *path_segments[last_segment].args(); let last_arg = args.args.len() - 1; @@ -1542,19 +1553,19 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::ImplTrai args.args = &args.args[..args.args.len() - 1]; path_segments[last_segment].args = Some(tcx.hir_arena.alloc(args)); let path = hir::Path { - span: ast_trait_ref.path.span, - res: ast_trait_ref.path.res, + span: hir_trait_ref.path.span, + res: hir_trait_ref.path.res, segments: tcx.hir_arena.alloc_slice(&path_segments), }; - let trait_ref = tcx.hir_arena.alloc(hir::TraitRef { path: tcx.hir_arena.alloc(path), hir_ref_id: ast_trait_ref.hir_ref_id }); - icx.astconv().instantiate_mono_trait_ref(trait_ref, selfty) + let trait_ref = tcx.hir_arena.alloc(hir::TraitRef { path: tcx.hir_arena.alloc(path), hir_ref_id: hir_trait_ref.hir_ref_id }); + icx.lowerer().lower_impl_trait_ref(trait_ref, self_ty) } else { - icx.astconv().instantiate_mono_trait_ref(ast_trait_ref, selfty) + icx.lowerer().lower_impl_trait_ref(hir_trait_ref, self_ty) }; ty::ImplTraitHeader { trait_ref: ty::EarlyBinder::bind(trait_ref), unsafety: impl_.unsafety, - polarity: polarity_of_impl(tcx, def_id, impl_, item.span) + polarity: polarity_of_impl(tcx, def_id, impl_, item.span) } }) } @@ -1562,20 +1573,20 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::ImplTrai fn check_impl_constness( tcx: TyCtxt<'_>, is_const: bool, - ast_trait_ref: &hir::TraitRef<'_>, + hir_trait_ref: &hir::TraitRef<'_>, ) -> Option<ErrorGuaranteed> { if !is_const { return None; } - let trait_def_id = ast_trait_ref.trait_def_id()?; + let trait_def_id = hir_trait_ref.trait_def_id()?; if tcx.has_attr(trait_def_id, sym::const_trait) { return None; } let trait_name = tcx.item_name(trait_def_id).to_string(); Some(tcx.dcx().emit_err(errors::ConstImplForNonConstTrait { - trait_ref_span: ast_trait_ref.path.span, + trait_ref_span: hir_trait_ref.path.span, trait_name, local_trait_span: trait_def_id.as_local().map(|_| tcx.def_span(trait_def_id).shrink_to_lo()), @@ -1671,19 +1682,19 @@ fn compute_sig_of_foreign_fn_decl<'tcx>( }; let hir_id = tcx.local_def_id_to_hir_id(def_id); let fty = - ItemCtxt::new(tcx, def_id).astconv().ty_of_fn(hir_id, unsafety, abi, decl, None, None); + ItemCtxt::new(tcx, def_id).lowerer().lower_fn_ty(hir_id, unsafety, abi, decl, None, None); // Feature gate SIMD types in FFI, since I am not sure that the // ABIs are handled at all correctly. -huonw if abi != abi::Abi::RustIntrinsic && !tcx.features().simd_ffi { - let check = |ast_ty: &hir::Ty<'_>, ty: Ty<'_>| { + let check = |hir_ty: &hir::Ty<'_>, ty: Ty<'_>| { if ty.is_simd() { let snip = tcx .sess .source_map() - .span_to_snippet(ast_ty.span) + .span_to_snippet(hir_ty.span) .map_or_else(|_| String::new(), |s| format!(" `{s}`")); - tcx.dcx().emit_err(errors::SIMDFFIHighlyExperimental { span: ast_ty.span, snip }); + tcx.dcx().emit_err(errors::SIMDFFIHighlyExperimental { span: hir_ty.span, snip }); } }; for (input, ty) in iter::zip(decl.inputs, fty.inputs().skip_binder()) { diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index c86788db988..4d6a02f50bf 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -218,8 +218,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { Deny, } - let no_generics = hir::Generics::empty(); - let ast_generics = node.generics().unwrap_or(no_generics); + let hir_generics = node.generics().unwrap_or(hir::Generics::empty()); let (opt_self, allow_defaults) = match node { Node::Item(item) => { match item.kind { @@ -275,13 +274,13 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { generics.parent_count + generics.params.len() }); - let mut params: Vec<_> = Vec::with_capacity(ast_generics.params.len() + has_self as usize); + let mut params: Vec<_> = Vec::with_capacity(hir_generics.params.len() + has_self as usize); if let Some(opt_self) = opt_self { params.push(opt_self); } - let early_lifetimes = super::early_bound_lifetimes_from_generics(tcx, ast_generics); + let early_lifetimes = super::early_bound_lifetimes_from_generics(tcx, hir_generics); params.extend(early_lifetimes.enumerate().map(|(i, param)| ty::GenericParamDef { name: param.name.ident().name, index: own_start + i as u32, @@ -302,7 +301,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { const TYPE_DEFAULT_NOT_ALLOWED: &'static str = "defaults for type parameters are only allowed in \ `struct`, `enum`, `type`, or `trait` definitions"; - params.extend(ast_generics.params.iter().filter_map(|param| match param.kind { + params.extend(hir_generics.params.iter().filter_map(|param| match param.kind { GenericParamKind::Lifetime { .. } => None, GenericParamKind::Type { default, synthetic, .. } => { if default.is_some() { @@ -508,29 +507,9 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S visitor.has_late_bound_regions } - match node { - Node::TraitItem(item) => match &item.kind { - hir::TraitItemKind::Fn(sig, _) => has_late_bound_regions(tcx, item.generics, sig.decl), - _ => None, - }, - Node::ImplItem(item) => match &item.kind { - hir::ImplItemKind::Fn(sig, _) => has_late_bound_regions(tcx, item.generics, sig.decl), - _ => None, - }, - Node::ForeignItem(item) => match item.kind { - hir::ForeignItemKind::Fn(fn_decl, _, generics) => { - has_late_bound_regions(tcx, generics, fn_decl) - } - _ => None, - }, - Node::Item(item) => match &item.kind { - hir::ItemKind::Fn(sig, .., generics, _) => { - has_late_bound_regions(tcx, generics, sig.decl) - } - _ => None, - }, - _ => None, - } + let decl = node.fn_decl()?; + let generics = node.generics()?; + has_late_bound_regions(tcx, generics, decl) } struct AnonConstInParamTyDetector { diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs index 78c390d0924..f1b14adcb7a 100644 --- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs +++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs @@ -1,5 +1,6 @@ use super::ItemCtxt; -use crate::astconv::{AstConv, PredicateFilter}; +use crate::hir_ty_lowering::{HirTyLowerer, PredicateFilter}; +use rustc_data_structures::fx::FxIndexSet; use rustc_hir as hir; use rustc_infer::traits::util; use rustc_middle::ty::GenericArgs; @@ -17,8 +18,9 @@ use rustc_span::Span; fn associated_type_bounds<'tcx>( tcx: TyCtxt<'tcx>, assoc_item_def_id: LocalDefId, - ast_bounds: &'tcx [hir::GenericBound<'tcx>], + hir_bounds: &'tcx [hir::GenericBound<'tcx>], span: Span, + filter: PredicateFilter, ) -> &'tcx [(ty::Clause<'tcx>, Span)] { let item_ty = Ty::new_projection( tcx, @@ -27,9 +29,9 @@ fn associated_type_bounds<'tcx>( ); let icx = ItemCtxt::new(tcx, assoc_item_def_id); - let mut bounds = icx.astconv().compute_bounds(item_ty, ast_bounds, PredicateFilter::All); + let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, hir_bounds, filter); // Associated types are implicitly sized unless a `?Sized` bound is found - icx.astconv().add_implicitly_sized(&mut bounds, item_ty, ast_bounds, None, span); + icx.lowerer().add_sized_bound(&mut bounds, item_ty, hir_bounds, None, span); let trait_def_id = tcx.local_parent(assoc_item_def_id); let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id); @@ -60,15 +62,16 @@ fn associated_type_bounds<'tcx>( fn opaque_type_bounds<'tcx>( tcx: TyCtxt<'tcx>, opaque_def_id: LocalDefId, - ast_bounds: &'tcx [hir::GenericBound<'tcx>], + hir_bounds: &'tcx [hir::GenericBound<'tcx>], item_ty: Ty<'tcx>, span: Span, + filter: PredicateFilter, ) -> &'tcx [(ty::Clause<'tcx>, Span)] { ty::print::with_reduced_queries!({ let icx = ItemCtxt::new(tcx, opaque_def_id); - let mut bounds = icx.astconv().compute_bounds(item_ty, ast_bounds, PredicateFilter::All); + let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, hir_bounds, filter); // Opaque types are implicitly sized unless a `?Sized` bound is found - icx.astconv().add_implicitly_sized(&mut bounds, item_ty, ast_bounds, None, span); + icx.lowerer().add_sized_bound(&mut bounds, item_ty, hir_bounds, None, span); debug!(?bounds); tcx.arena.alloc_from_iter(bounds.clauses()) @@ -79,6 +82,21 @@ pub(super) fn explicit_item_bounds( tcx: TyCtxt<'_>, def_id: LocalDefId, ) -> ty::EarlyBinder<&'_ [(ty::Clause<'_>, Span)]> { + explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::All) +} + +pub(super) fn explicit_item_super_predicates( + tcx: TyCtxt<'_>, + def_id: LocalDefId, +) -> ty::EarlyBinder<&'_ [(ty::Clause<'_>, Span)]> { + explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::SelfOnly) +} + +pub(super) fn explicit_item_bounds_with_filter( + tcx: TyCtxt<'_>, + def_id: LocalDefId, + filter: PredicateFilter, +) -> ty::EarlyBinder<&'_ [(ty::Clause<'_>, Span)]> { match tcx.opt_rpitit_info(def_id.to_def_id()) { // RPITIT's bounds are the same as opaque type bounds, but with // a projection self type. @@ -95,6 +113,7 @@ pub(super) fn explicit_item_bounds( ty::GenericArgs::identity_for_item(tcx, def_id), ), item.span, + filter, )); } Some(ty::ImplTraitInTraitData::Impl { .. }) => span_bug!( @@ -109,7 +128,7 @@ pub(super) fn explicit_item_bounds( kind: hir::TraitItemKind::Type(bounds, _), span, .. - }) => associated_type_bounds(tcx, def_id, bounds, *span), + }) => associated_type_bounds(tcx, def_id, bounds, *span, filter), hir::Node::Item(hir::Item { kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, in_trait: false, .. }), span, @@ -117,10 +136,10 @@ pub(super) fn explicit_item_bounds( }) => { let args = GenericArgs::identity_for_item(tcx, def_id); let item_ty = Ty::new_opaque(tcx, def_id.to_def_id(), args); - opaque_type_bounds(tcx, def_id, bounds, item_ty, *span) + opaque_type_bounds(tcx, def_id, bounds, item_ty, *span, filter) } - // Since RPITITs are astconv'd as projections in `ast_ty_to_ty`, when we're asking - // for the item bounds of the *opaques* in a trait's default method signature, we + // Since RPITITs are lowered as projections in `<dyn HirTyLowerer>::lower_ty`, when we're + // asking for the item bounds of the *opaques* in a trait's default method signature, we // need to map these projections back to opaques. hir::Node::Item(hir::Item { kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, in_trait: true, origin, .. }), @@ -135,7 +154,7 @@ pub(super) fn explicit_item_bounds( let args = GenericArgs::identity_for_item(tcx, def_id); let item_ty = Ty::new_opaque(tcx, def_id.to_def_id(), args); tcx.arena.alloc_slice( - &opaque_type_bounds(tcx, def_id, bounds, item_ty, *span) + &opaque_type_bounds(tcx, def_id, bounds, item_ty, *span, filter) .to_vec() .fold_with(&mut AssocTyToOpaque { tcx, fn_def_id: fn_def_id.to_def_id() }), ) @@ -155,6 +174,31 @@ pub(super) fn item_bounds( }) } +pub(super) fn item_super_predicates( + tcx: TyCtxt<'_>, + def_id: DefId, +) -> ty::EarlyBinder<&'_ ty::List<ty::Clause<'_>>> { + tcx.explicit_item_super_predicates(def_id).map_bound(|bounds| { + tcx.mk_clauses_from_iter( + util::elaborate(tcx, bounds.iter().map(|&(bound, _span)| bound)).filter_only_self(), + ) + }) +} + +pub(super) fn item_non_self_assumptions( + tcx: TyCtxt<'_>, + def_id: DefId, +) -> ty::EarlyBinder<&'_ ty::List<ty::Clause<'_>>> { + let all_bounds: FxIndexSet<_> = tcx.item_bounds(def_id).skip_binder().iter().collect(); + let own_bounds: FxIndexSet<_> = + tcx.item_super_predicates(def_id).skip_binder().iter().collect(); + if all_bounds.len() == own_bounds.len() { + ty::EarlyBinder::bind(ty::List::empty()) + } else { + ty::EarlyBinder::bind(tcx.mk_clauses_from_iter(all_bounds.difference(&own_bounds).copied())) + } +} + struct AssocTyToOpaque<'tcx> { tcx: TyCtxt<'tcx>, fn_def_id: DefId, diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 6aae4aa21b8..6d8b257a0f5 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -1,7 +1,7 @@ -use crate::astconv::{AstConv, OnlySelfBounds, PredicateFilter}; use crate::bounds::Bounds; use crate::collect::ItemCtxt; use crate::constrained_generic_params as cgp; +use crate::hir_ty_lowering::{HirTyLowerer, OnlySelfBounds, PredicateFilter}; use hir::{HirId, Node}; use rustc_data_structures::fx::FxIndexSet; use rustc_hir as hir; @@ -123,43 +123,22 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // Preserving the order of insertion is important here so as not to break UI tests. let mut predicates: FxIndexSet<(ty::Clause<'_>, Span)> = FxIndexSet::default(); - let ast_generics = match node { - Node::TraitItem(item) => item.generics, - - Node::ImplItem(item) => item.generics, - - Node::Item(item) => match item.kind { + let hir_generics = node.generics().unwrap_or(NO_GENERICS); + if let Node::Item(item) = node { + match item.kind { ItemKind::Impl(impl_) => { if impl_.defaultness.is_default() { is_default_impl_trait = tcx .impl_trait_ref(def_id) .map(|t| ty::Binder::dummy(t.instantiate_identity())); } - impl_.generics } - ItemKind::Fn(.., generics, _) - | ItemKind::TyAlias(_, generics) - | ItemKind::Const(_, generics, _) - | ItemKind::Enum(_, generics) - | ItemKind::Struct(_, generics) - | ItemKind::Union(_, generics) => generics, - - ItemKind::Trait(_, _, generics, self_bounds, ..) - | ItemKind::TraitAlias(generics, self_bounds) => { + + ItemKind::Trait(_, _, _, self_bounds, ..) | ItemKind::TraitAlias(_, self_bounds) => { is_trait = Some(self_bounds); - generics } - ItemKind::OpaqueTy(OpaqueTy { generics, .. }) => generics, - _ => NO_GENERICS, - }, - - Node::ForeignItem(item) => match item.kind { - ForeignItemKind::Static(..) => NO_GENERICS, - ForeignItemKind::Fn(_, _, generics) => generics, - ForeignItemKind::Type => NO_GENERICS, - }, - - _ => NO_GENERICS, + _ => {} + } }; let generics = tcx.generics_of(def_id); @@ -170,8 +149,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // like `trait Foo: A + B + C`. if let Some(self_bounds) = is_trait { predicates.extend( - icx.astconv() - .compute_bounds(tcx.types.self_param, self_bounds, PredicateFilter::All) + icx.lowerer() + .lower_mono_bounds(tcx.types.self_param, self_bounds, PredicateFilter::All) .clauses(), ); } @@ -191,19 +170,19 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // Collect the predicates that were written inline by the user on each // type parameter (e.g., `<T: Foo>`). Also add `ConstArgHasType` predicates // for each const parameter. - for param in ast_generics.params { + for param in hir_generics.params { match param.kind { // We already dealt with early bound lifetimes above. GenericParamKind::Lifetime { .. } => (), GenericParamKind::Type { .. } => { - let param_ty = icx.astconv().hir_id_to_bound_ty(param.hir_id); + let param_ty = icx.lowerer().lower_ty_param(param.hir_id); let mut bounds = Bounds::default(); // Params are implicitly sized unless a `?Sized` bound is found - icx.astconv().add_implicitly_sized( + icx.lowerer().add_sized_bound( &mut bounds, param_ty, &[], - Some((param.def_id, ast_generics.predicates)), + Some((param.def_id, hir_generics.predicates)), param.span, ); trace!(?bounds); @@ -215,7 +194,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen .type_of(param.def_id.to_def_id()) .no_bound_vars() .expect("const parameters cannot be generic"); - let ct = icx.astconv().hir_id_to_bound_const(param.hir_id, ct_ty); + let ct = icx.lowerer().lower_const_param(param.hir_id, ct_ty); predicates.insert(( ty::ClauseKind::ConstArgHasType(ct, ct_ty).to_predicate(tcx), param.span, @@ -226,10 +205,10 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen trace!(?predicates); // Add in the bounds that appear in the where-clause. - for predicate in ast_generics.predicates { + for predicate in hir_generics.predicates { match predicate { hir::WherePredicate::BoundPredicate(bound_pred) => { - let ty = icx.to_ty(bound_pred.bounded_ty); + let ty = icx.lower_ty(bound_pred.bounded_ty); let bound_vars = tcx.late_bound_vars(bound_pred.hir_id); // Keep the type around in a dummy predicate, in case of no bounds. // That way, `where Ty:` is not a complete noop (see #53696) and `Ty` @@ -253,7 +232,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen } let mut bounds = Bounds::default(); - icx.astconv().add_bounds( + icx.lowerer().lower_poly_bounds( ty, bound_pred.bounds.iter(), &mut bounds, @@ -264,11 +243,11 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen } hir::WherePredicate::RegionPredicate(region_pred) => { - let r1 = icx.astconv().ast_region_to_region(region_pred.lifetime, None); + let r1 = icx.lowerer().lower_lifetime(region_pred.lifetime, None); predicates.extend(region_pred.bounds.iter().map(|bound| { let (r2, span) = match bound { hir::GenericBound::Outlives(lt) => { - (icx.astconv().ast_region_to_region(lt, None), lt.ident.span) + (icx.lowerer().lower_lifetime(lt, None), lt.ident.span) } bound => { span_bug!( @@ -563,8 +542,8 @@ pub(super) fn explicit_predicates_of<'tcx>( } /// Ensures that the super-predicates of the trait with a `DefId` -/// of `trait_def_id` are converted and stored. This also ensures that -/// the transitive super-predicates are converted. +/// of `trait_def_id` are lowered and stored. This also ensures that +/// the transitive super-predicates are lowered. pub(super) fn super_predicates_of( tcx: TyCtxt<'_>, trait_def_id: LocalDefId, @@ -595,8 +574,8 @@ pub(super) fn implied_predicates_of( } /// Ensures that the super-predicates of the trait with a `DefId` -/// of `trait_def_id` are converted and stored. This also ensures that -/// the transitive super-predicates are converted. +/// of `trait_def_id` are lowered and stored. This also ensures that +/// the transitive super-predicates are lowered. pub(super) fn implied_predicates_with_filter( tcx: TyCtxt<'_>, trait_def_id: DefId, @@ -622,9 +601,9 @@ pub(super) fn implied_predicates_with_filter( let icx = ItemCtxt::new(tcx, trait_def_id); let self_param_ty = tcx.types.self_param; - let superbounds = icx.astconv().compute_bounds(self_param_ty, bounds, filter); + let superbounds = icx.lowerer().lower_mono_bounds(self_param_ty, bounds, filter); - let where_bounds_that_match = icx.type_parameter_bounds_in_generics( + let where_bounds_that_match = icx.probe_ty_param_bounds_in_generics( generics, item.owner_id.def_id, self_param_ty, @@ -636,7 +615,7 @@ pub(super) fn implied_predicates_with_filter( &*tcx.arena.alloc_from_iter(superbounds.clauses().chain(where_bounds_that_match)); debug!(?implied_bounds); - // Now require that immediate supertraits are converted, which will, in + // Now require that immediate supertraits are lowered, which will, in // turn, reach indirect supertraits, so we detect cycles now instead of // overflowing during elaboration. Same for implied predicates, which // make sure we walk into associated type bounds. @@ -677,7 +656,7 @@ pub(super) fn type_param_predicates( use rustc_hir::*; use rustc_middle::ty::Ty; - // In the AST, bounds can derive from two places. Either + // In the HIR, bounds can derive from two places. Either // written inline like `<T: Foo>` or in a where-clause like // `where T: Foo`. @@ -697,56 +676,28 @@ pub(super) fn type_param_predicates( let mut result = parent .map(|parent| { let icx = ItemCtxt::new(tcx, parent); - icx.get_type_parameter_bounds(DUMMY_SP, def_id, assoc_name) + icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_name) }) .unwrap_or_default(); let mut extend = None; let item_hir_id = tcx.local_def_id_to_hir_id(item_def_id); - let ast_generics = match tcx.hir_node(item_hir_id) { - Node::TraitItem(item) => item.generics, - - Node::ImplItem(item) => item.generics, - - Node::Item(item) => { - match item.kind { - ItemKind::Fn(.., generics, _) - | ItemKind::Impl(&hir::Impl { generics, .. }) - | ItemKind::TyAlias(_, generics) - | ItemKind::Const(_, generics, _) - | ItemKind::OpaqueTy(&OpaqueTy { - generics, - origin: hir::OpaqueTyOrigin::TyAlias { .. }, - .. - }) - | ItemKind::Enum(_, generics) - | ItemKind::Struct(_, generics) - | ItemKind::Union(_, generics) => generics, - ItemKind::Trait(_, _, generics, ..) => { - // Implied `Self: Trait` and supertrait bounds. - if param_id == item_hir_id { - let identity_trait_ref = - ty::TraitRef::identity(tcx, item_def_id.to_def_id()); - extend = Some((identity_trait_ref.to_predicate(tcx), item.span)); - } - generics - } - _ => return result, - } - } - - Node::ForeignItem(item) => match item.kind { - ForeignItemKind::Fn(_, _, generics) => generics, - _ => return result, - }, - _ => return result, - }; + let hir_node = tcx.hir_node(item_hir_id); + let Some(hir_generics) = hir_node.generics() else { return result }; + if let Node::Item(item) = hir_node + && let ItemKind::Trait(..) = item.kind + // Implied `Self: Trait` and supertrait bounds. + && param_id == item_hir_id + { + let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id.to_def_id()); + extend = Some((identity_trait_ref.to_predicate(tcx), item.span)); + } let icx = ItemCtxt::new(tcx, item_def_id); let extra_predicates = extend.into_iter().chain( - icx.type_parameter_bounds_in_generics( - ast_generics, + icx.probe_ty_param_bounds_in_generics( + hir_generics, def_id, ty, PredicateFilter::SelfThatDefines(assoc_name), @@ -763,21 +714,22 @@ pub(super) fn type_param_predicates( } impl<'tcx> ItemCtxt<'tcx> { - /// Finds bounds from `hir::Generics`. This requires scanning through the - /// AST. We do this to avoid having to convert *all* the bounds, which - /// would create artificial cycles. Instead, we can only convert the - /// bounds for a type parameter `X` if `X::Foo` is used. - #[instrument(level = "trace", skip(self, ast_generics))] - fn type_parameter_bounds_in_generics( + /// Finds bounds from `hir::Generics`. + /// + /// This requires scanning through the HIR. + /// We do this to avoid having to lower *all* the bounds, which would create artificial cycles. + /// Instead, we can only lower the bounds for a type parameter `X` if `X::Foo` is used. + #[instrument(level = "trace", skip(self, hir_generics))] + fn probe_ty_param_bounds_in_generics( &self, - ast_generics: &'tcx hir::Generics<'tcx>, + hir_generics: &'tcx hir::Generics<'tcx>, param_def_id: LocalDefId, ty: Ty<'tcx>, filter: PredicateFilter, ) -> Vec<(ty::Clause<'tcx>, Span)> { let mut bounds = Bounds::default(); - for predicate in ast_generics.predicates { + for predicate in hir_generics.predicates { let hir::WherePredicate::BoundPredicate(predicate) = predicate else { continue; }; @@ -799,13 +751,13 @@ impl<'tcx> ItemCtxt<'tcx> { let bound_ty = if predicate.is_param_bound(param_def_id.to_def_id()) { ty } else if matches!(filter, PredicateFilter::All) { - self.to_ty(predicate.bounded_ty) + self.lower_ty(predicate.bounded_ty) } else { continue; }; let bound_vars = self.tcx.late_bound_vars(predicate.hir_id); - self.astconv().add_bounds( + self.lowerer().lower_poly_bounds( bound_ty, predicate.bounds.iter().filter(|bound| { assoc_name diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index d1da2fa0fdc..27a26cfe474 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -262,7 +262,7 @@ fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBou visitor.visit_impl_item(item) } hir::OwnerNode::Crate(_) => {} - hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(), + hir::OwnerNode::Synthetic => unreachable!(), } let mut rl = ResolveBoundVars::default(); @@ -1917,18 +1917,18 @@ fn is_late_bound_map( /// /// If we conservatively considered `'a` unconstrained then we could break users who had written code before /// we started correctly handling aliases. If we considered `'a` constrained then it would become late bound - /// causing an error during astconv as the `'a` is not constrained by the input type `<() as Trait<'a>>::Assoc` + /// causing an error during HIR ty lowering as the `'a` is not constrained by the input type `<() as Trait<'a>>::Assoc` /// but appears in the output type `<() as Trait<'a>>::Assoc`. /// /// We must therefore "look into" the `Alias` to see whether we should consider `'a` constrained or not. /// /// See #100508 #85533 #47511 for additional context - struct ConstrainedCollectorPostAstConv { + struct ConstrainedCollectorPostHirTyLowering { arg_is_constrained: Box<[bool]>, } use ty::Ty; - impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstrainedCollectorPostAstConv { + impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstrainedCollectorPostHirTyLowering { fn visit_ty(&mut self, t: Ty<'tcx>) { match t.kind() { ty::Param(param_ty) => { @@ -1970,10 +1970,10 @@ fn is_late_bound_map( None, hir::Path { res: Res::Def(DefKind::TyAlias, alias_def), segments, span }, )) => { - // See comments on `ConstrainedCollectorPostAstConv` for why this arm does not just consider - // args to be unconstrained. + // See comments on `ConstrainedCollectorPostHirTyLowering` for why this arm does not + // just consider args to be unconstrained. let generics = self.tcx.generics_of(alias_def); - let mut walker = ConstrainedCollectorPostAstConv { + let mut walker = ConstrainedCollectorPostHirTyLowering { arg_is_constrained: vec![false; generics.params.len()].into_boxed_slice(), }; walker.visit_ty(self.tcx.type_of(alias_def).instantiate_identity()); diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index fd86f2dd1b1..722def2563c 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -47,7 +47,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> { let ty = tcx.fold_regions(ty, |r, _| { if r.is_erased() { ty::Region::new_error_misc(tcx) } else { r } }); - let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false) { + let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false, None) { (ty, Some((span, Applicability::MachineApplicable))) } else { (ty, None) @@ -97,10 +97,10 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> { // I believe this match arm is only needed for GAT but I am not 100% sure - BoxyUwU Node::Ty(hir_ty @ hir::Ty { kind: TyKind::Path(QPath::TypeRelative(_, segment)), .. }) => { // Find the Item containing the associated type so we can create an ItemCtxt. - // Using the ItemCtxt convert the HIR for the unresolved assoc type into a + // Using the ItemCtxt lower the HIR for the unresolved assoc type into a // ty which is a fully resolved projection. - // For the code example above, this would mean converting Self::Assoc<3> - // into a ty::Alias(ty::Projection, <Self as Foo>::Assoc<3>) + // For the code example above, this would mean lowering `Self::Assoc<3>` + // to a ty::Alias(ty::Projection, `<Self as Foo>::Assoc<3>`). let item_def_id = tcx .hir() .parent_owner_iter(hir_id) @@ -108,7 +108,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> { .unwrap() .0 .def_id; - let ty = ItemCtxt::new(tcx, item_def_id).to_ty(hir_ty); + let ty = ItemCtxt::new(tcx, item_def_id).lower_ty(hir_ty); // Iterate through the generics of the projection to find the one that corresponds to // the def_id that this query was called with. We filter to only type and const args here @@ -369,8 +369,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty ) }) }) - .unwrap_or_else(|| icx.to_ty(ty)), - TraitItemKind::Type(_, Some(ty)) => icx.to_ty(ty), + .unwrap_or_else(|| icx.lower_ty(ty)), + TraitItemKind::Type(_, Some(ty)) => icx.lower_ty(ty), TraitItemKind::Type(_, None) => { span_bug!(item.span, "associated type missing default"); } @@ -392,7 +392,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty "associated constant", ) } else { - icx.to_ty(ty) + icx.lower_ty(ty) } } ImplItemKind::Type(ty) => { @@ -400,7 +400,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty check_feature_inherent_assoc_ty(tcx, item.span); } - icx.to_ty(ty) + icx.lower_ty(ty) } }, @@ -416,17 +416,17 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty "static variable", ) } else { - icx.to_ty(ty) + icx.lower_ty(ty) } } ItemKind::Const(ty, _, body_id) => { if ty.is_suggestable_infer_ty() { infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident, "constant") } else { - icx.to_ty(ty) + icx.lower_ty(ty) } } - ItemKind::TyAlias(self_ty, _) => icx.to_ty(self_ty), + ItemKind::TyAlias(self_ty, _) => icx.lower_ty(self_ty), ItemKind::Impl(hir::Impl { self_ty, .. }) => match self_ty.find_self_aliases() { spans if spans.len() > 0 => { let guar = tcx @@ -434,7 +434,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty .emit_err(crate::errors::SelfInImplSelf { span: spans.into(), note: () }); Ty::new_error(tcx, guar) } - _ => icx.to_ty(*self_ty), + _ => icx.lower_ty(*self_ty), }, ItemKind::Fn(..) => { let args = ty::GenericArgs::identity_for_item(tcx, def_id); @@ -466,7 +466,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty let args = ty::GenericArgs::identity_for_item(tcx, def_id); Ty::new_fn_def(tcx, def_id.to_def_id(), args) } - ForeignItemKind::Static(t, _) => icx.to_ty(t), + ForeignItemKind::Static(t, _) => icx.lower_ty(t), ForeignItemKind::Type => Ty::new_foreign(tcx, def_id.to_def_id()), }, @@ -480,7 +480,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty } }, - Node::Field(field) => icx.to_ty(field.ty), + Node::Field(field) => icx.lower_ty(field.ty), Node::Expr(&Expr { kind: ExprKind::Closure { .. }, .. }) => { tcx.typeck(def_id).node_type(hir_id) @@ -495,7 +495,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty Node::GenericParam(param) => match ¶m.kind { GenericParamKind::Type { default: Some(ty), .. } - | GenericParamKind::Const { ty, .. } => icx.to_ty(ty), + | GenericParamKind::Const { ty, .. } => icx.lower_ty(ty), x => bug!("unexpected non-type Node::GenericParam: {:?}", x), }, @@ -587,7 +587,7 @@ fn infer_placeholder_type<'a>( suggestions.clear(); } - if let Some(ty) = ty.make_suggestable(tcx, false) { + if let Some(ty) = ty.make_suggestable(tcx, false, None) { err.span_suggestion( span, format!("provide a type for the {kind}"), @@ -606,7 +606,7 @@ fn infer_placeholder_type<'a>( let mut diag = bad_placeholder(tcx, vec![span], kind); if !ty.references_error() { - if let Some(ty) = ty.make_suggestable(tcx, false) { + if let Some(ty) = ty.make_suggestable(tcx, false, None) { diag.span_suggestion( span, "replace with the correct type", diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 175991b1be2..fb919714afd 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -295,6 +295,44 @@ pub struct AssocTypeBindingNotAllowed { pub fn_trait_expansion: Option<ParenthesizedFnTraitExpansion>, } +#[derive(Diagnostic)] +#[diag(hir_analysis_param_in_ty_of_assoc_const_binding)] +pub(crate) struct ParamInTyOfAssocConstBinding<'tcx> { + #[primary_span] + #[label] + pub span: Span, + pub assoc_const: Ident, + pub param_name: Symbol, + pub param_def_kind: &'static str, + pub param_category: &'static str, + #[label(hir_analysis_param_defined_here_label)] + pub param_defined_here_label: Option<Span>, + #[subdiagnostic] + pub ty_note: Option<TyOfAssocConstBindingNote<'tcx>>, +} + +#[derive(Subdiagnostic, Clone, Copy)] +#[note(hir_analysis_ty_of_assoc_const_binding_note)] +pub(crate) struct TyOfAssocConstBindingNote<'tcx> { + pub assoc_const: Ident, + pub ty: Ty<'tcx>, +} + +#[derive(Diagnostic)] +#[diag(hir_analysis_escaping_bound_var_in_ty_of_assoc_const_binding)] +pub(crate) struct EscapingBoundVarInTyOfAssocConstBinding<'tcx> { + #[primary_span] + #[label] + pub span: Span, + pub assoc_const: Ident, + pub var_name: Symbol, + pub var_def_kind: &'static str, + #[label(hir_analysis_var_defined_here_label)] + pub var_defined_here_label: Span, + #[subdiagnostic] + pub ty_note: Option<TyOfAssocConstBindingNote<'tcx>>, +} + #[derive(Subdiagnostic)] #[help(hir_analysis_parenthesized_fn_trait_expansion)] pub struct ParenthesizedFnTraitExpansion { @@ -1072,6 +1110,7 @@ pub struct UnusedAssociatedTypeBounds { #[derive(LintDiagnostic)] #[diag(hir_analysis_rpitit_refined)] #[note] +#[note(hir_analysis_feedback_note)] pub(crate) struct ReturnPositionImplTraitInTraitRefined<'tcx> { #[suggestion(applicability = "maybe-incorrect", code = "{pre}{return_ty}{post}")] pub impl_return_span: Span, diff --git a/compiler/rustc_hir_analysis/src/astconv/bounds.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs index 17e0aeb044c..6f7a788ca6e 100644 --- a/compiler/rustc_hir_analysis/src/astconv/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -1,25 +1,30 @@ -use rustc_data_structures::fx::FxIndexMap; +use std::ops::ControlFlow; + +use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_errors::{codes::*, struct_span_code_err}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_middle::ty::{self as ty, Ty}; +use rustc_middle::ty::{self as ty, IsSuggestable, Ty, TyCtxt}; use rustc_span::symbol::Ident; -use rustc_span::{ErrorGuaranteed, Span}; +use rustc_span::{ErrorGuaranteed, Span, Symbol}; use rustc_trait_selection::traits; +use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor}; use smallvec::SmallVec; -use crate::astconv::{AstConv, OnlySelfBounds, PredicateFilter}; use crate::bounds::Bounds; use crate::errors; +use crate::hir_ty_lowering::{HirTyLowerer, OnlySelfBounds, PredicateFilter}; -impl<'tcx> dyn AstConv<'tcx> + '_ { - /// Sets `implicitly_sized` to true on `Bounds` if necessary - pub(crate) fn add_implicitly_sized( +impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { + /// Add a `Sized` bound to the `bounds` if appropriate. + /// + /// Doesn't add the bound if the HIR bounds contain any of `Sized`, `?Sized` or `!Sized`. + pub(crate) fn add_sized_bound( &self, bounds: &mut Bounds<'tcx>, self_ty: Ty<'tcx>, - ast_bounds: &'tcx [hir::GenericBound<'tcx>], + hir_bounds: &'tcx [hir::GenericBound<'tcx>], self_ty_where_predicates: Option<(LocalDefId, &'tcx [hir::WherePredicate<'tcx>])>, span: Span, ) { @@ -30,9 +35,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Try to find an unbound in bounds. let mut unbounds: SmallVec<[_; 1]> = SmallVec::new(); - let mut search_bounds = |ast_bounds: &'tcx [hir::GenericBound<'tcx>]| { - for ab in ast_bounds { - let hir::GenericBound::Trait(ptr, modifier) = ab else { + let mut search_bounds = |hir_bounds: &'tcx [hir::GenericBound<'tcx>]| { + for hir_bound in hir_bounds { + let hir::GenericBound::Trait(ptr, modifier) = hir_bound else { continue; }; match modifier { @@ -55,7 +60,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } }; - search_bounds(ast_bounds); + search_bounds(hir_bounds); if let Some((self_ty, where_clause)) = self_ty_where_predicates { for clause in where_clause { if let hir::WherePredicate::BoundPredicate(pred) = clause @@ -98,34 +103,40 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - /// This helper takes a *converted* parameter type (`param_ty`) - /// and an *unconverted* list of bounds: + /// Lower HIR bounds into `bounds` given the self type `param_ty` and the overarching late-bound vars if any. + /// + /// ### Examples + /// + /// ```ignore (illustrative) + /// fn foo<T>() where for<'a> T: Trait<'a> + Copy {} + /// // ^^^^^^^ ^ ^^^^^^^^^^^^^^^^ `hir_bounds`, in HIR form + /// // | | + /// // | `param_ty`, in ty form + /// // `bound_vars`, in ty form /// - /// ```text - /// fn foo<T: Debug> - /// ^ ^^^^^ `ast_bounds` parameter, in HIR form - /// | - /// `param_ty`, in ty form + /// fn bar<T>() where T: for<'a> Trait<'a> + Copy {} // no overarching `bound_vars` here! + /// // ^ ^^^^^^^^^^^^^^^^^^^^^^^^ `hir_bounds`, in HIR form + /// // | + /// // `param_ty`, in ty form /// ``` /// - /// It adds these `ast_bounds` into the `bounds` structure. + /// ### A Note on Binders /// - /// **A note on binders:** there is an implied binder around - /// `param_ty` and `ast_bounds`. See `instantiate_poly_trait_ref` - /// for more details. - #[instrument(level = "debug", skip(self, ast_bounds, bounds))] - pub(crate) fn add_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>( + /// There is an implied binder around `param_ty` and `hir_bounds`. + /// See `lower_poly_trait_ref` for more details. + #[instrument(level = "debug", skip(self, hir_bounds, bounds))] + pub(crate) fn lower_poly_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>( &self, param_ty: Ty<'tcx>, - ast_bounds: I, + hir_bounds: I, bounds: &mut Bounds<'tcx>, bound_vars: &'tcx ty::List<ty::BoundVariableKind>, only_self_bounds: OnlySelfBounds, ) where 'tcx: 'hir, { - for ast_bound in ast_bounds { - match ast_bound { + for hir_bound in hir_bounds { + match hir_bound { hir::GenericBound::Trait(poly_trait_ref, modifier) => { let (constness, polarity) = match modifier { hir::TraitBoundModifier::Const => { @@ -142,19 +153,18 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } hir::TraitBoundModifier::Maybe => continue, }; - let _ = self.instantiate_poly_trait_ref( + let _ = self.lower_poly_trait_ref( &poly_trait_ref.trait_ref, poly_trait_ref.span, constness, polarity, param_ty, bounds, - false, only_self_bounds, ); } hir::GenericBound::Outlives(lifetime) => { - let region = self.ast_region_to_region(lifetime, None); + let region = self.lower_lifetime(lifetime, None); bounds.push_region_bound( self.tcx(), ty::Binder::bind_with_vars( @@ -168,26 +178,19 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - /// Translates a list of bounds from the HIR into the `Bounds` data structure. - /// The self-type for the bounds is given by `param_ty`. + /// Lower HIR bounds into `bounds` given the self type `param_ty` and *no* overarching late-bound vars. /// - /// Example: + /// ### Example /// /// ```ignore (illustrative) /// fn foo<T: Bar + Baz>() { } - /// // ^ ^^^^^^^^^ ast_bounds + /// // ^ ^^^^^^^^^ hir_bounds /// // param_ty /// ``` - /// - /// The `sized_by_default` parameter indicates if, in this context, the `param_ty` should be - /// considered `Sized` unless there is an explicit `?Sized` bound. This would be true in the - /// example above, but is not true in supertrait listings like `trait Foo: Bar + Baz`. - /// - /// `span` should be the declaration size of the parameter. - pub(crate) fn compute_bounds( + pub(crate) fn lower_mono_bounds( &self, param_ty: Ty<'tcx>, - ast_bounds: &[hir::GenericBound<'tcx>], + hir_bounds: &[hir::GenericBound<'tcx>], filter: PredicateFilter, ) -> Bounds<'tcx> { let mut bounds = Bounds::default(); @@ -199,9 +202,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { PredicateFilter::SelfOnly | PredicateFilter::SelfThatDefines(_) => OnlySelfBounds(true), }; - self.add_bounds( + self.lower_poly_bounds( param_ty, - ast_bounds.iter().filter(|bound| match filter { + hir_bounds.iter().filter(|bound| match filter { PredicateFilter::All | PredicateFilter::SelfOnly | PredicateFilter::SelfAndAssociatedTypeBounds => true, @@ -225,40 +228,25 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { bounds } - /// Given an HIR binding like `Item = Foo` or `Item: Foo`, pushes the corresponding predicates - /// onto `bounds`. + /// Lower an associated item binding from HIR into `bounds`. /// - /// **A note on binders:** given something like `T: for<'a> Iterator<Item = &'a u32>`, the - /// `trait_ref` here will be `for<'a> T: Iterator`. The `binding` data however is from *inside* - /// the binder (e.g., `&'a u32`) and hence may reference bound regions. - #[instrument(level = "debug", skip(self, bounds, speculative, dup_bindings, path_span))] - pub(super) fn add_predicates_for_ast_type_binding( + /// ### A Note on Binders + /// + /// Given something like `T: for<'a> Iterator<Item = &'a u32>`, + /// the `trait_ref` here will be `for<'a> T: Iterator`. + /// The `binding` data however is from *inside* the binder + /// (e.g., `&'a u32`) and hence may reference bound regions. + #[instrument(level = "debug", skip(self, bounds, dup_bindings, path_span))] + pub(super) fn lower_assoc_item_binding( &self, hir_ref_id: hir::HirId, trait_ref: ty::PolyTraitRef<'tcx>, binding: &hir::TypeBinding<'tcx>, bounds: &mut Bounds<'tcx>, - speculative: bool, dup_bindings: &mut FxIndexMap<DefId, Span>, path_span: Span, only_self_bounds: OnlySelfBounds, ) -> Result<(), ErrorGuaranteed> { - // Given something like `U: SomeTrait<T = X>`, we want to produce a - // predicate like `<U as SomeTrait>::T = X`. This is somewhat - // subtle in the event that `T` is defined in a supertrait of - // `SomeTrait`, because in that case we need to upcast. - // - // That is, consider this case: - // - // ``` - // trait SubTrait: SuperTrait<i32> { } - // trait SuperTrait<A> { type T; } - // - // ... B: SubTrait<T = foo> ... - // ``` - // - // We want to produce `<B as SuperTrait<i32>>::T == foo`. - let tcx = self.tcx(); let assoc_kind = if binding.gen_args.parenthesized @@ -271,7 +259,15 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { ty::AssocKind::Type }; - let candidate = if self.trait_defines_associated_item_named( + // Given something like `U: Trait<T = X>`, we want to produce a predicate like + // `<U as Trait>::T = X`. + // This is somewhat subtle in the event that `T` is defined in a supertrait of `Trait`, + // because in that case we need to upcast. I.e., we want to produce + // `<B as SuperTrait<i32>>::T == X` for `B: SubTrait<T = X>` where + // + // trait SubTrait: SuperTrait<i32> {} + // trait SuperTrait<A> { type T; } + let candidate = if self.probe_trait_that_defines_assoc_item( trait_ref.def_id(), assoc_kind, binding.ident, @@ -281,7 +277,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } else { // Otherwise, we have to walk through the supertraits to find // one that does define it. - self.one_bound_for_assoc_item( + self.probe_single_bound_for_assoc_item( || traits::supertraits(tcx, trait_ref), trait_ref.skip_binder().print_only_trait_name(), None, @@ -317,19 +313,17 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } tcx.check_stability(assoc_item.def_id, Some(hir_ref_id), binding.span, None); - if !speculative { - dup_bindings - .entry(assoc_item.def_id) - .and_modify(|prev_span| { - tcx.dcx().emit_err(errors::ValueOfAssociatedStructAlreadySpecified { - span: binding.span, - prev_span: *prev_span, - item_name: binding.ident, - def_path: tcx.def_path_str(assoc_item.container_id(tcx)), - }); - }) - .or_insert(binding.span); - } + dup_bindings + .entry(assoc_item.def_id) + .and_modify(|prev_span| { + tcx.dcx().emit_err(errors::ValueOfAssociatedStructAlreadySpecified { + span: binding.span, + prev_span: *prev_span, + item_name: binding.ident, + def_path: tcx.def_path_str(assoc_item.container_id(tcx)), + }); + }) + .or_insert(binding.span); let projection_ty = if let ty::AssocKind::Fn = assoc_kind { let mut emitted_bad_param_err = None; @@ -418,7 +412,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { infer_args: false, }; - let alias_args = self.create_args_for_associated_item( + let alias_args = self.lower_generic_args_of_assoc_item( path_span, assoc_item.def_id, &item_segment, @@ -433,19 +427,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { }); // Provide the resolved type of the associated constant to `type_of(AnonConst)`. - if !speculative - && let hir::TypeBindingKind::Equality { term: hir::Term::Const(anon_const) } = - binding.kind + if let hir::TypeBindingKind::Equality { term: hir::Term::Const(anon_const) } = + binding.kind { let ty = alias_ty.map_bound(|ty| tcx.type_of(ty.def_id).instantiate(tcx, ty.args)); - // Since the arguments passed to the alias type above may contain early-bound - // generic parameters, the instantiated type may contain some as well. - // Therefore wrap it in `EarlyBinder`. - // FIXME(fmease): Reject escaping late-bound vars. - tcx.feed_anon_const_type( - anon_const.def_id, - ty::EarlyBinder::bind(ty.skip_binder()), - ); + let ty = check_assoc_const_binding_type(tcx, assoc_ident, ty, binding.hir_id); + tcx.feed_anon_const_type(anon_const.def_id, ty::EarlyBinder::bind(ty)); } alias_ty @@ -457,53 +444,49 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { span: binding.span, })); } + // Lower an equality constraint like `Item = u32` as found in HIR bound `T: Iterator<Item = u32>` + // to a projection predicate: `<T as Iterator>::Item = u32`. hir::TypeBindingKind::Equality { term } => { let term = match term { - hir::Term::Ty(ty) => self.ast_ty_to_ty(ty).into(), + hir::Term::Ty(ty) => self.lower_ty(ty).into(), hir::Term::Const(ct) => ty::Const::from_anon_const(tcx, ct.def_id).into(), }; - if !speculative { - // Find any late-bound regions declared in `ty` that are not - // declared in the trait-ref or assoc_item. These are not well-formed. - // - // Example: - // - // for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad - // for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok - let late_bound_in_projection_ty = - tcx.collect_constrained_late_bound_regions(projection_ty); - let late_bound_in_term = - tcx.collect_referenced_late_bound_regions(trait_ref.rebind(term)); - debug!(?late_bound_in_projection_ty); - debug!(?late_bound_in_term); - - // FIXME: point at the type params that don't have appropriate lifetimes: - // struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F); - // ---- ---- ^^^^^^^ - // NOTE(associated_const_equality): This error should be impossible to trigger - // with associated const equality bounds. - self.validate_late_bound_regions( - late_bound_in_projection_ty, - late_bound_in_term, - |br_name| { - struct_span_code_err!( - tcx.dcx(), - binding.span, - E0582, - "binding for associated type `{}` references {}, \ - which does not appear in the trait input types", - binding.ident, - br_name - ) - }, - ); - } - - // "Desugar" a constraint like `T: Iterator<Item = u32>` this to - // the "projection predicate" for: + // Find any late-bound regions declared in `ty` that are not + // declared in the trait-ref or assoc_item. These are not well-formed. // - // `<T as Iterator>::Item = u32` + // Example: + // + // for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad + // for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok + let late_bound_in_projection_ty = + tcx.collect_constrained_late_bound_regions(projection_ty); + let late_bound_in_term = + tcx.collect_referenced_late_bound_regions(trait_ref.rebind(term)); + debug!(?late_bound_in_projection_ty); + debug!(?late_bound_in_term); + + // FIXME: point at the type params that don't have appropriate lifetimes: + // struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F); + // ---- ---- ^^^^^^^ + // NOTE(associated_const_equality): This error should be impossible to trigger + // with associated const equality bounds. + self.validate_late_bound_regions( + late_bound_in_projection_ty, + late_bound_in_term, + |br_name| { + struct_span_code_err!( + tcx.dcx(), + binding.span, + E0582, + "binding for associated type `{}` references {}, \ + which does not appear in the trait input types", + binding.ident, + br_name + ) + }, + ); + bounds.push_projection_bound( tcx, projection_ty @@ -511,22 +494,18 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { binding.span, ); } - hir::TypeBindingKind::Constraint { bounds: ast_bounds } => { - // "Desugar" a constraint like `T: Iterator<Item: Debug>` to - // - // `<T as Iterator>::Item: Debug` - // - // Calling `skip_binder` is okay, because `add_bounds` expects the `param_ty` - // parameter to have a skipped binder. - // - // NOTE: If `only_self_bounds` is true, do NOT expand this associated - // type bound into a trait predicate, since we only want to add predicates - // for the `Self` type. + // Lower a constraint like `Item: Debug` as found in HIR bound `T: Iterator<Item: Debug>` + // to a bound involving a projection: `<T as Iterator>::Item: Debug`. + hir::TypeBindingKind::Constraint { bounds: hir_bounds } => { + // NOTE: If `only_self_bounds` is true, do NOT expand this associated type bound into + // a trait predicate, since we only want to add predicates for the `Self` type. if !only_self_bounds.0 { + // Calling `skip_binder` is okay, because `lower_bounds` expects the `param_ty` + // parameter to have a skipped binder. let param_ty = Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder()); - self.add_bounds( + self.lower_poly_bounds( param_ty, - ast_bounds.iter(), + hir_bounds.iter(), bounds, projection_ty.bound_vars(), only_self_bounds, @@ -537,3 +516,167 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { Ok(()) } } + +/// Detect and reject early-bound & escaping late-bound generic params in the type of assoc const bindings. +/// +/// FIXME(const_generics): This is a temporary and semi-artifical restriction until the +/// arrival of *generic const generics*[^1]. +/// +/// It might actually be possible that we can already support early-bound generic params +/// in such types if we just lifted some more checks in other places, too, for example +/// inside [`ty::Const::from_anon_const`]. However, even if that were the case, we should +/// probably gate this behind another feature flag. +/// +/// [^1]: <https://github.com/rust-lang/project-const-generics/issues/28>. +fn check_assoc_const_binding_type<'tcx>( + tcx: TyCtxt<'tcx>, + assoc_const: Ident, + ty: ty::Binder<'tcx, Ty<'tcx>>, + hir_id: hir::HirId, +) -> Ty<'tcx> { + // We can't perform the checks for early-bound params during name resolution unlike E0770 + // because this information depends on *type* resolution. + // We can't perform these checks in `resolve_bound_vars` either for the same reason. + // Consider the trait ref `for<'a> Trait<'a, C = { &0 }>`. We need to know the fully + // resolved type of `Trait::C` in order to know if it references `'a` or not. + + let ty = ty.skip_binder(); + if !ty.has_param() && !ty.has_escaping_bound_vars() { + return ty; + } + + let mut collector = GenericParamAndBoundVarCollector { + tcx, + params: Default::default(), + vars: Default::default(), + depth: ty::INNERMOST, + }; + let mut guar = ty.visit_with(&mut collector).break_value(); + + let ty_note = ty + .make_suggestable(tcx, false, None) + .map(|ty| crate::errors::TyOfAssocConstBindingNote { assoc_const, ty }); + + let enclosing_item_owner_id = tcx + .hir() + .parent_owner_iter(hir_id) + .find_map(|(owner_id, parent)| parent.generics().map(|_| owner_id)) + .unwrap(); + let generics = tcx.generics_of(enclosing_item_owner_id); + for index in collector.params { + let param = generics.param_at(index as _, tcx); + let is_self_param = param.name == rustc_span::symbol::kw::SelfUpper; + guar.get_or_insert(tcx.dcx().emit_err(crate::errors::ParamInTyOfAssocConstBinding { + span: assoc_const.span, + assoc_const, + param_name: param.name, + param_def_kind: tcx.def_descr(param.def_id), + param_category: if is_self_param { + "self" + } else if param.kind.is_synthetic() { + "synthetic" + } else { + "normal" + }, + param_defined_here_label: + (!is_self_param).then(|| tcx.def_ident_span(param.def_id).unwrap()), + ty_note, + })); + } + for (var_def_id, var_name) in collector.vars { + guar.get_or_insert(tcx.dcx().emit_err( + crate::errors::EscapingBoundVarInTyOfAssocConstBinding { + span: assoc_const.span, + assoc_const, + var_name, + var_def_kind: tcx.def_descr(var_def_id), + var_defined_here_label: tcx.def_ident_span(var_def_id).unwrap(), + ty_note, + }, + )); + } + + let guar = guar.unwrap_or_else(|| bug!("failed to find gen params or bound vars in ty")); + Ty::new_error(tcx, guar) +} + +struct GenericParamAndBoundVarCollector<'tcx> { + tcx: TyCtxt<'tcx>, + params: FxIndexSet<u32>, + vars: FxIndexSet<(DefId, Symbol)>, + depth: ty::DebruijnIndex, +} + +impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'tcx> { + type Result = ControlFlow<ErrorGuaranteed>; + + fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>( + &mut self, + binder: &ty::Binder<'tcx, T>, + ) -> Self::Result { + self.depth.shift_in(1); + let result = binder.super_visit_with(self); + self.depth.shift_out(1); + result + } + + fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { + match ty.kind() { + ty::Param(param) => { + self.params.insert(param.index); + } + ty::Bound(db, bt) if *db >= self.depth => { + self.vars.insert(match bt.kind { + ty::BoundTyKind::Param(def_id, name) => (def_id, name), + ty::BoundTyKind::Anon => { + let reported = self + .tcx + .dcx() + .delayed_bug(format!("unexpected anon bound ty: {:?}", bt.var)); + return ControlFlow::Break(reported); + } + }); + } + _ if ty.has_param() || ty.has_bound_vars() => return ty.super_visit_with(self), + _ => {} + } + ControlFlow::Continue(()) + } + + fn visit_region(&mut self, re: ty::Region<'tcx>) -> Self::Result { + match re.kind() { + ty::ReEarlyParam(param) => { + self.params.insert(param.index); + } + ty::ReBound(db, br) if db >= self.depth => { + self.vars.insert(match br.kind { + ty::BrNamed(def_id, name) => (def_id, name), + ty::BrAnon | ty::BrEnv => { + let guar = self + .tcx + .dcx() + .delayed_bug(format!("unexpected bound region kind: {:?}", br.kind)); + return ControlFlow::Break(guar); + } + }); + } + _ => {} + } + ControlFlow::Continue(()) + } + + fn visit_const(&mut self, ct: ty::Const<'tcx>) -> Self::Result { + match ct.kind() { + ty::ConstKind::Param(param) => { + self.params.insert(param.index); + } + ty::ConstKind::Bound(db, ty::BoundVar { .. }) if db >= self.depth => { + let guar = self.tcx.dcx().delayed_bug("unexpected escaping late-bound const var"); + return ControlFlow::Break(guar); + } + _ if ct.has_param() || ct.has_bound_vars() => return ct.super_visit_with(self), + _ => {} + } + ControlFlow::Continue(()) + } +} diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs index 37fbf45235a..ca2e14ee359 100644 --- a/compiler/rustc_hir_analysis/src/astconv/errors.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs @@ -1,9 +1,9 @@ -use crate::astconv::AstConv; use crate::errors::{ self, AssocTypeBindingNotAllowed, ManualImplementation, MissingTypeParams, ParenthesizedFnTraitExpansion, }; use crate::fluent_generated as fluent; +use crate::hir_ty_lowering::HirTyLowerer; use crate::traits::error_reporting::report_object_safety_error; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::sorted_map::SortedMap; @@ -22,7 +22,7 @@ use rustc_span::symbol::{sym, Ident}; use rustc_span::{Span, Symbol, DUMMY_SP}; use rustc_trait_selection::traits::object_safety_violations_for_assoc_item; -impl<'tcx> dyn AstConv<'tcx> + '_ { +impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { /// On missing type parameters, emit an E0393 error and provide a structured suggestion using /// the type parameter's name as a placeholder. pub(crate) fn complain_about_missing_type_params( @@ -311,7 +311,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // FIXME(associated_const_equality): This has quite a few false positives and negatives. let wrap_in_braces_sugg = if let Some(binding) = binding && let hir::TypeBindingKind::Equality { term: hir::Term::Ty(hir_ty) } = binding.kind - && let ty = self.ast_ty_to_ty(hir_ty) + && let ty = self.lower_ty(hir_ty) && (ty.is_enum() || ty.references_error()) && tcx.features().associated_const_equality { @@ -349,7 +349,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { }) } - pub(super) fn report_ambiguous_associated_type( + pub(super) fn report_ambiguous_assoc_ty( &self, span: Span, types: &[String], @@ -408,10 +408,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { traits with associated type `{name}`, you could use the \ fully-qualified path", ), - traits - .iter() - .map(|trait_str| format!("<Example as {trait_str}>::{name}")) - .collect::<Vec<_>>(), + traits.iter().map(|trait_str| format!("<Example as {trait_str}>::{name}")), Applicability::HasPlaceholders, ); } @@ -461,7 +458,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { reported } - pub(crate) fn complain_about_ambiguous_inherent_assoc_type( + pub(crate) fn complain_about_ambiguous_inherent_assoc_ty( &self, name: Ident, candidates: Vec<DefId>, @@ -474,14 +471,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { "multiple applicable items in scope" ); err.span_label(name.span, format!("multiple `{name}` found")); - self.note_ambiguous_inherent_assoc_type(&mut err, candidates, span); + self.note_ambiguous_inherent_assoc_ty(&mut err, candidates, span); let reported = err.emit(); self.set_tainted_by_errors(reported); reported } // FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate. - fn note_ambiguous_inherent_assoc_type( + fn note_ambiguous_inherent_assoc_ty( &self, err: &mut Diag<'_>, candidates: Vec<DefId>, @@ -524,7 +521,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } // FIXME(inherent_associated_types): Find similarly named associated types and suggest them. - pub(crate) fn complain_about_inherent_assoc_type_not_found( + pub(crate) fn complain_about_inherent_assoc_ty_not_found( &self, name: Ident, self_ty: Ty<'tcx>, @@ -700,7 +697,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { /// reasonable suggestion on how to write it. For the case of multiple associated types in the /// same trait bound have the same name (as they come from different supertraits), we instead /// emit a generic note suggesting using a `where` clause to constraint instead. - pub(crate) fn complain_about_missing_associated_types( + pub(crate) fn complain_about_missing_assoc_tys( &self, associated_types: FxIndexMap<Span, FxIndexSet<DefId>>, potential_assoc_types: Vec<Span>, @@ -1030,7 +1027,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } /// Emits an error regarding forbidden type binding associations -pub fn prohibit_assoc_ty_binding( +pub fn prohibit_assoc_item_binding( tcx: TyCtxt<'_>, span: Span, segment: Option<(&hir::PathSegment<'_>, Span)>, diff --git a/compiler/rustc_hir_analysis/src/astconv/generics.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs index 428eea2f686..d340a08ee79 100644 --- a/compiler/rustc_hir_analysis/src/astconv/generics.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs @@ -1,7 +1,7 @@ use super::IsMethodCall; -use crate::astconv::{ - errors::prohibit_assoc_ty_binding, CreateInstantiationsForGenericArgsCtxt, ExplicitLateBound, - GenericArgCountMismatch, GenericArgCountResult, GenericArgPosition, +use crate::hir_ty_lowering::{ + errors::prohibit_assoc_item_binding, ExplicitLateBound, GenericArgCountMismatch, + GenericArgCountResult, GenericArgPosition, GenericArgsLowerer, }; use crate::structured_errors::{GenericArgsInfo, StructuredDiag, WrongNumberOfGenericArgs}; use rustc_ast::ast::ParamKindOrd; @@ -16,7 +16,7 @@ use rustc_middle::ty::{ self, GenericArgsRef, GenericParamDef, GenericParamDefKind, IsSuggestable, Ty, TyCtxt, }; use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS; -use rustc_span::symbol::kw; +use rustc_span::symbol::{kw, sym}; use smallvec::SmallVec; /// Report an error that a generic argument did not match the generic parameter that was @@ -41,9 +41,11 @@ fn generic_arg_mismatch_err( if let GenericParamDefKind::Const { .. } = param.kind { if matches!(arg, GenericArg::Type(hir::Ty { kind: hir::TyKind::Infer, .. })) { err.help("const arguments cannot yet be inferred with `_`"); - if sess.is_nightly_build() { - err.help("add `#![feature(generic_arg_infer)]` to the crate attributes to enable"); - } + tcx.disabled_nightly_features( + &mut err, + param.def_id.as_local().map(|local| tcx.local_def_id_to_hir_id(local)), + [(String::new(), sym::generic_arg_infer)], + ); } } @@ -141,24 +143,22 @@ fn generic_arg_mismatch_err( err.emit() } -/// Creates the relevant generic arguments -/// corresponding to a set of generic parameters. This is a -/// rather complex function. Let us try to explain the role +/// Lower generic arguments from the HIR to the [`rustc_middle::ty`] representation. +/// +/// This is a rather complex function. Let us try to explain the role /// of each of its parameters: /// -/// To start, we are given the `def_id` of the thing whose generic -/// parameters we are instantiating, and a partial set of -/// arguments `parent_args`. In general, the generic arguments -/// for an item begin with arguments for all the "parents" of -/// that item -- e.g., for a method it might include the -/// parameters from the impl. +/// To start, we are given the `def_id` of the thing whose generic parameters we +/// are creating, and a partial set of arguments `parent_args`. In general, +/// the generic arguments for an item begin with arguments for all the "parents" +/// of that item -- e.g., for a method it might include the parameters from the impl. /// /// Therefore, the method begins by walking down these parents, /// starting with the outermost parent and proceed inwards until /// it reaches `def_id`. For each parent `P`, it will check `parent_args` /// first to see if the parent's arguments are listed in there. If so, -/// we can append those and move on. Otherwise, it invokes the -/// three callback functions: +/// we can append those and move on. Otherwise, it uses the provided +/// [`GenericArgsLowerer`] `ctx` which has the following methods: /// /// - `args_for_def_id`: given the `DefId` `P`, supplies back the /// generic arguments that were given to that parent from within @@ -166,18 +166,18 @@ fn generic_arg_mismatch_err( /// might refer to the trait `Foo`, and the arguments might be /// `[T]`. The boolean value indicates whether to infer values /// for arguments whose values were not explicitly provided. -/// - `provided_kind`: given the generic parameter and the value from `args_for_def_id`, -/// instantiate a `GenericArg`. -/// - `inferred_kind`: if no parameter was provided, and inference is enabled, then -/// creates a suitable inference variable. -pub fn create_args_for_parent_generic_args<'tcx: 'a, 'a>( +/// - `provided_kind`: given the generic parameter and the value +/// from `args_for_def_id`, creating a `GenericArg`. +/// - `inferred_kind`: if no parameter was provided, and inference +/// is enabled, then creates a suitable inference variable. +pub fn lower_generic_args<'tcx: 'a, 'a>( tcx: TyCtxt<'tcx>, def_id: DefId, parent_args: &[ty::GenericArg<'tcx>], has_self: bool, self_ty: Option<Ty<'tcx>>, arg_count: &GenericArgCountResult, - ctx: &mut impl CreateInstantiationsForGenericArgsCtxt<'a, 'tcx>, + ctx: &mut impl GenericArgsLowerer<'a, 'tcx>, ) -> GenericArgsRef<'tcx> { // Collect the segments of the path; we need to instantiate arguments // for parameters throughout the entire path (wherever there are @@ -454,7 +454,7 @@ pub(crate) fn check_generic_arg_count( if gen_pos != GenericArgPosition::Type && let Some(b) = gen_args.bindings.first() { - prohibit_assoc_ty_binding(tcx, b.span, None); + prohibit_assoc_item_binding(tcx, b.span, None); } let explicit_late_bound = diff --git a/compiler/rustc_hir_analysis/src/astconv/lint.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs index b421a33ba29..80be563686a 100644 --- a/compiler/rustc_hir_analysis/src/astconv/lint.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs @@ -6,9 +6,9 @@ use rustc_lint_defs::{builtin::BARE_TRAIT_OBJECTS, Applicability}; use rustc_span::Span; use rustc_trait_selection::traits::error_reporting::suggestions::NextTypeParamName; -use super::AstConv; +use super::HirTyLowerer; -impl<'tcx> dyn AstConv<'tcx> + '_ { +impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { /// Make sure that we are in the condition to suggest the blanket implementation. pub(super) fn maybe_lint_blanket_trait_impl<G: EmissionGuarantee>( &self, diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 401dd76a9f9..109e00d4f24 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -1,6 +1,17 @@ -//! Conversion from AST representation of types to the `ty.rs` representation. -//! The main routine here is `ast_ty_to_ty()`; each use is parameterized by an -//! instance of `AstConv`. +//! HIR ty lowering: Lowers type-system entities[^1] from the [HIR][hir] to +//! the [`rustc_middle::ty`] representation. +//! +//! Not to be confused with *AST lowering* which lowers AST constructs to HIR ones +//! or with *THIR* / *MIR* *lowering* / *building* which lowers HIR *bodies* +//! (i.e., “executable code”) to THIR / MIR. +//! +//! Most lowering routines are defined on [`dyn HirTyLowerer`](HirTyLowerer) directly, +//! like the main routine of this module, `lower_ty`. +//! +//! This module used to be called `astconv`. +//! +//! [^1]: This includes types, lifetimes / regions, constants in type positions, +//! trait references and bounds. mod bounds; mod errors; @@ -8,11 +19,11 @@ pub mod generics; mod lint; mod object_safety; -use crate::astconv::errors::prohibit_assoc_ty_binding; -use crate::astconv::generics::{check_generic_arg_count, create_args_for_parent_generic_args}; use crate::bounds::Bounds; use crate::collect::HirPlaceholderCollector; use crate::errors::AmbiguousLifetimeBound; +use crate::hir_ty_lowering::errors::prohibit_assoc_item_binding; +use crate::hir_ty_lowering::generics::{check_generic_arg_count, lower_generic_args}; use crate::middle::resolve_bound_vars as rbv; use crate::require_c_abi_if_c_variadic; use rustc_ast::TraitObjectSyntax; @@ -43,8 +54,9 @@ use rustc_trait_selection::traits::{self, ObligationCtxt}; use std::fmt::Display; use std::slice; +/// A path segment that is semantically allowed to have generic arguments. #[derive(Debug)] -pub struct PathSeg(pub DefId, pub usize); +pub struct GenericPathSegment(pub DefId, pub usize); #[derive(Copy, Clone, Debug)] pub struct OnlySelfBounds(pub bool); @@ -67,40 +79,26 @@ pub enum PredicateFilter { SelfAndAssociatedTypeBounds, } -pub trait AstConv<'tcx> { +/// A context which can lower type-system entities from the [HIR][hir] to +/// the [`rustc_middle::ty`] representation. +/// +/// This trait used to be called `AstConv`. +pub trait HirTyLowerer<'tcx> { fn tcx(&self) -> TyCtxt<'tcx>; + /// Returns the [`DefId`] of the overarching item whose constituents get lowered. fn item_def_id(&self) -> DefId; - /// Returns predicates in scope of the form `X: Foo<T>`, where `X` - /// is a type parameter `X` with the given id `def_id` and T - /// matches `assoc_name`. This is a subset of the full set of - /// predicates. - /// - /// This is used for one specific purpose: resolving "short-hand" - /// associated type references like `T::Item`. In principle, we - /// would do that by first getting the full set of predicates in - /// scope and then filtering down to find those that apply to `T`, - /// but this can lead to cycle errors. The problem is that we have - /// to do this resolution *in order to create the predicates in - /// the first place*. Hence, we have this "special pass". - fn get_type_parameter_bounds( - &self, - span: Span, - def_id: LocalDefId, - assoc_name: Ident, - ) -> ty::GenericPredicates<'tcx>; + /// Returns `true` if the current context allows the use of inference variables. + fn allow_infer(&self) -> bool; - /// Returns the lifetime to use when a lifetime is omitted (and not elided). + /// Returns the region to use when a lifetime is omitted (and not elided). fn re_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Option<ty::Region<'tcx>>; /// Returns the type to use when a type is omitted. fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx>; - /// Returns `true` if `_` is allowed in type signatures in the current context. - fn allow_ty_infer(&self) -> bool; - /// Returns the const to use when a const is omitted. fn ct_infer( &self, @@ -109,14 +107,40 @@ pub trait AstConv<'tcx> { span: Span, ) -> Const<'tcx>; - /// Projecting an associated type from a (potentially) - /// higher-ranked trait reference is more complicated, because of - /// the possibility of late-bound regions appearing in the - /// associated type binding. This is not legal in function - /// signatures for that reason. In a function body, we can always - /// handle it because we can use inference variables to remove the - /// late-bound regions. - fn projected_ty_from_poly_trait_ref( + /// Probe bounds in scope where the bounded type coincides with the given type parameter. + /// + /// Rephrased, this returns bounds of the form `T: Trait`, where `T` is a type parameter + /// with the given `def_id`. This is a subset of the full set of bounds. + /// + /// This method may use the given `assoc_name` to disregard bounds whose trait reference + /// doesn't define an associated item with the provided name. + /// + /// This is used for one specific purpose: Resolving “short-hand” associated type references + /// like `T::Item` where `T` is a type parameter. In principle, we would do that by first + /// getting the full set of predicates in scope and then filtering down to find those that + /// apply to `T`, but this can lead to cycle errors. The problem is that we have to do this + /// resolution *in order to create the predicates in the first place*. + /// Hence, we have this “special pass”. + fn probe_ty_param_bounds( + &self, + span: Span, + def_id: LocalDefId, + assoc_name: Ident, + ) -> ty::GenericPredicates<'tcx>; + + /// Lower an associated type to a projection. + /// + /// This method has to be defined by the concrete lowering context because + /// dealing with higher-ranked trait references depends on its capabilities: + /// + /// If the context can make use of type inference, it can simply instantiate + /// any late-bound vars bound by the trait reference with inference variables. + /// If it doesn't support type inference, there is nothing reasonable it can + /// do except reject the associated type. + /// + /// The canonical example of this is associated type `T::P` where `T` is a type + /// param constrained by `T: for<'a> Trait<'a>` and where `Trait` defines `P`. + fn lower_assoc_ty( &self, span: Span, item_def_id: DefId, @@ -125,28 +149,35 @@ pub trait AstConv<'tcx> { ) -> Ty<'tcx>; /// Returns `AdtDef` if `ty` is an ADT. - /// Note that `ty` might be a projection type that needs normalization. + /// + /// Note that `ty` might be a alias type that needs normalization. /// This used to get the enum variants in scope of the type. /// For example, `Self::A` could refer to an associated type /// or to an enum variant depending on the result of this function. fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>>; - /// Invoked when we encounter an error from some prior pass - /// (e.g., resolve) that is translated into a ty-error. This is - /// used to help suppress derived errors typeck might otherwise - /// report. - fn set_tainted_by_errors(&self, e: ErrorGuaranteed); - + /// Record the lowered type of a HIR node in this context. fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span); - fn astconv(&self) -> &dyn AstConv<'tcx> + /// The inference context of the lowering context if applicable. + fn infcx(&self) -> Option<&InferCtxt<'tcx>>; + + /// Taint the context with errors. + /// + /// Invoke this when you encounter an error from some prior pass like name resolution. + /// This is used to help suppress derived errors typeck might otherwise report. + fn set_tainted_by_errors(&self, e: ErrorGuaranteed); + + /// Convenience method for coercing the lowering context into a trait object type. + /// + /// Most lowering routines are defined on the trait object type directly + /// necessitating a coercion step from the concrete lowering context. + fn lowerer(&self) -> &dyn HirTyLowerer<'tcx> where Self: Sized, { self } - - fn infcx(&self) -> Option<&InferCtxt<'tcx>>; } /// New-typed boolean indicating whether explicit late-bound lifetimes @@ -197,7 +228,11 @@ pub struct GenericArgCountResult { pub correct: Result<(), GenericArgCountMismatch>, } -pub trait CreateInstantiationsForGenericArgsCtxt<'a, 'tcx> { +/// A context which can lower HIR's [`GenericArg`] to `rustc_middle`'s [`ty::GenericArg`]. +/// +/// Its only consumer is [`generics::lower_generic_args`]. +/// Read its documentation to learn more. +pub trait GenericArgsLowerer<'a, 'tcx> { fn args_for_def_id(&mut self, def_id: DefId) -> (Option<&'a GenericArgs<'tcx>>, bool); fn provided_kind( @@ -214,9 +249,10 @@ pub trait CreateInstantiationsForGenericArgsCtxt<'a, 'tcx> { ) -> ty::GenericArg<'tcx>; } -impl<'tcx> dyn AstConv<'tcx> + '_ { +impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { + /// Lower a lifetime from the HIR to our internal notion of a lifetime called a *region*. #[instrument(level = "debug", skip(self), ret)] - pub fn ast_region_to_region( + pub fn lower_lifetime( &self, lifetime: &hir::Lifetime, def: Option<&ty::GenericParamDef>, @@ -271,15 +307,13 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - /// Given a path `path` that refers to an item `I` with the declared generics `decl_generics`, - /// returns an appropriate set of generic arguments for this particular reference to `I`. - pub fn ast_path_args_for_ty( + pub fn lower_generic_args_of_path_segment( &self, span: Span, def_id: DefId, item_segment: &hir::PathSegment<'tcx>, ) -> GenericArgsRef<'tcx> { - let (args, _) = self.create_args_for_ast_path( + let (args, _) = self.lower_generic_args_of_path( span, def_id, &[], @@ -288,20 +322,19 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { ty::BoundConstness::NotConst, ); if let Some(b) = item_segment.args().bindings.first() { - prohibit_assoc_ty_binding(self.tcx(), b.span, Some((item_segment, span))); + prohibit_assoc_item_binding(self.tcx(), b.span, Some((item_segment, span))); } - args } - /// Given the type/lifetime/const arguments provided to some path (along with - /// an implicit `Self`, if this is a trait reference), returns the complete - /// set of generic arguments. This may involve applying defaulted type parameters. + /// Lower the generic arguments provided to some path. /// - /// Constraints on associated types are not converted here but - /// separately in `add_predicates_for_ast_type_binding`. + /// If this is a trait reference, you also need to pass the self type `self_ty`. + /// The lowering process may involve applying defaulted type parameters. /// - /// Example: + /// Associated item bindings are not handled here! + /// + /// ### Example /// /// ```ignore (illustrative) /// T: std::ops::Index<usize, Output = u32> @@ -328,7 +361,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { /// type itself: `['a]`. The returned `GenericArgsRef` concatenates these two /// lists: `[Vec<u8>, u8, 'a]`. #[instrument(level = "debug", skip(self, span), ret)] - fn create_args_for_ast_path( + fn lower_generic_args_of_path( &self, span: Span, def_id: DefId, @@ -343,7 +376,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { let tcx = self.tcx(); let generics = tcx.generics_of(def_id); - debug!("generics: {:?}", generics); + debug!(?generics); if generics.has_self { if generics.parent.is_some() { @@ -381,8 +414,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { return (tcx.mk_args(parent_args), arg_count); } - struct InstantiationsForAstPathCtxt<'a, 'tcx> { - astconv: &'a dyn AstConv<'tcx>, + struct GenericArgsCtxt<'a, 'tcx> { + lowerer: &'a dyn HirTyLowerer<'tcx>, def_id: DefId, generic_args: &'a GenericArgs<'tcx>, span: Span, @@ -390,9 +423,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { infer_args: bool, } - impl<'a, 'tcx> CreateInstantiationsForGenericArgsCtxt<'a, 'tcx> - for InstantiationsForAstPathCtxt<'a, 'tcx> - { + impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> { fn args_for_def_id(&mut self, did: DefId) -> (Option<&'a GenericArgs<'tcx>>, bool) { if did == self.def_id { (Some(self.generic_args), self.infer_args) @@ -407,7 +438,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { param: &ty::GenericParamDef, arg: &GenericArg<'tcx>, ) -> ty::GenericArg<'tcx> { - let tcx = self.astconv.tcx(); + let tcx = self.lowerer.tcx(); let mut handle_ty_args = |has_default, ty: &hir::Ty<'tcx>| { if has_default { @@ -426,17 +457,17 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { }, ); } - if let (hir::TyKind::Infer, false) = (&ty.kind, self.astconv.allow_ty_infer()) { + if let (hir::TyKind::Infer, false) = (&ty.kind, self.lowerer.allow_infer()) { self.inferred_params.push(ty.span); Ty::new_misc_error(tcx).into() } else { - self.astconv.ast_ty_to_ty(ty).into() + self.lowerer.lower_ty(ty).into() } }; match (¶m.kind, arg) { (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => { - self.astconv.ast_region_to_region(lt, Some(param)).into() + self.lowerer.lower_lifetime(lt, Some(param)).into() } (&GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => { handle_ty_args(has_default, ty) @@ -455,8 +486,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .type_of(param.def_id) .no_bound_vars() .expect("const parameter types cannot be generic"); - if self.astconv.allow_ty_infer() { - self.astconv.ct_infer(ty, Some(param), inf.span).into() + if self.lowerer.allow_infer() { + self.lowerer.ct_infer(ty, Some(param), inf.span).into() } else { self.inferred_params.push(inf.span); ty::Const::new_misc_error(tcx, ty).into() @@ -475,10 +506,10 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { param: &ty::GenericParamDef, infer_args: bool, ) -> ty::GenericArg<'tcx> { - let tcx = self.astconv.tcx(); + let tcx = self.lowerer.tcx(); match param.kind { GenericParamDefKind::Lifetime => self - .astconv + .lowerer .re_infer(Some(param), self.span) .unwrap_or_else(|| { debug!(?param, "unelided lifetime in signature"); @@ -504,7 +535,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } tcx.at(self.span).type_of(param.def_id).instantiate(tcx, args).into() } else if infer_args { - self.astconv.ty_infer(Some(param), self.span).into() + self.lowerer.ty_infer(Some(param), self.span).into() } else { // We've already errored above about the mismatch. Ty::new_misc_error(tcx).into() @@ -526,7 +557,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .into() } else { if infer_args { - self.astconv.ct_infer(ty, Some(param), self.span).into() + self.lowerer.ct_infer(ty, Some(param), self.span).into() } else { // We've already errored above about the mismatch. ty::Const::new_misc_error(tcx, ty).into() @@ -537,8 +568,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - let mut args_ctx = InstantiationsForAstPathCtxt { - astconv: self, + let mut args_ctx = GenericArgsCtxt { + lowerer: self, def_id, span, generic_args: segment.args(), @@ -557,7 +588,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { arg_count.correct = Err(GenericArgCountMismatch { reported: Some(e), invalid_args: vec![] }); } - let args = create_args_for_parent_generic_args( + let args = lower_generic_args( tcx, def_id, parent_args, @@ -570,18 +601,16 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { (args, arg_count) } - pub fn create_args_for_associated_item( + #[instrument(level = "debug", skip_all)] + pub fn lower_generic_args_of_assoc_item( &self, span: Span, item_def_id: DefId, item_segment: &hir::PathSegment<'tcx>, parent_args: GenericArgsRef<'tcx>, ) -> GenericArgsRef<'tcx> { - debug!( - "create_args_for_associated_item(span: {:?}, item_def_id: {:?}, item_segment: {:?}", - span, item_def_id, item_segment - ); - let (args, _) = self.create_args_for_ast_path( + debug!(?span, ?item_def_id, ?item_segment); + let (args, _) = self.lower_generic_args_of_path( span, item_def_id, parent_args, @@ -589,28 +618,23 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { None, ty::BoundConstness::NotConst, ); - if let Some(b) = item_segment.args().bindings.first() { - prohibit_assoc_ty_binding(self.tcx(), b.span, Some((item_segment, span))); + prohibit_assoc_item_binding(self.tcx(), b.span, Some((item_segment, span))); } - args } - /// Instantiates the path for the given trait reference, assuming that it's - /// bound to a valid trait type. Returns the `DefId` of the defining trait. - /// The type _cannot_ be a type other than a trait type. + /// Lower a trait reference as found in an impl header as the implementee. /// - /// If the `projections` argument is `None`, then assoc type bindings like `Foo<T = X>` - /// are disallowed. Otherwise, they are pushed onto the vector given. - pub fn instantiate_mono_trait_ref( + /// The self type `self_ty` is the implementer of the trait. + pub fn lower_impl_trait_ref( &self, trait_ref: &hir::TraitRef<'tcx>, self_ty: Ty<'tcx>, ) -> ty::TraitRef<'tcx> { - self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {}); + self.prohibit_generic_args(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {}); - self.ast_path_to_mono_trait_ref( + self.lower_mono_trait_ref( trait_ref.path.span, trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise()), self_ty, @@ -620,27 +644,31 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { ) } - /// Given a trait bound like `Debug`, applies that trait bound the given self-type to construct - /// a full trait reference. The resulting trait reference is returned. This may also generate - /// auxiliary bounds, which are added to `bounds`. + /// Lower a polymorphic trait reference given a self type into `bounds`. /// - /// Example: + /// *Polymorphic* in the sense that it may bind late-bound vars. /// - /// ```ignore (illustrative) - /// poly_trait_ref = Iterator<Item = u32> - /// self_ty = Foo - /// ``` + /// This may generate auxiliary bounds if the trait reference contains associated item bindings. + /// + /// ### Example + /// + /// Given the trait ref `Iterator<Item = u32>` and the self type `Ty`, this will add the /// - /// this would return `Foo: Iterator` and add `<Foo as Iterator>::Item = u32` into `bounds`. + /// 1. *trait predicate* `<Ty as Iterator>` (known as `Foo: Iterator` in surface syntax) and the + /// 2. *projection predicate* `<Ty as Iterator>::Item = u32` + /// + /// to `bounds`. + /// + /// ### A Note on Binders + /// + /// Against our usual convention, there is an implied binder around the `self_ty` and the + /// `trait_ref` here. So they may reference late-bound vars. /// - /// **A note on binders:** against our usual convention, there is an implied binder around - /// the `self_ty` and `poly_trait_ref` parameters here. So they may reference bound regions. /// If for example you had `for<'a> Foo<'a>: Bar<'a>`, then the `self_ty` would be `Foo<'a>` - /// where `'a` is a bound region at depth 0. Similarly, the `poly_trait_ref` would be - /// `Bar<'a>`. The returned poly-trait-ref will have this binder instantiated explicitly, - /// however. - #[instrument(level = "debug", skip(self, span, constness, bounds, speculative))] - pub(crate) fn instantiate_poly_trait_ref( + /// where `'a` is a bound region at depth 0. Similarly, the `trait_ref` would be `Bar<'a>`. + /// The lowered poly-trait-ref will track this binder explicitly, however. + #[instrument(level = "debug", skip(self, span, constness, bounds))] + pub(crate) fn lower_poly_trait_ref( &self, trait_ref: &hir::TraitRef<'tcx>, span: Span, @@ -648,16 +676,15 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { polarity: ty::ImplPolarity, self_ty: Ty<'tcx>, bounds: &mut Bounds<'tcx>, - speculative: bool, only_self_bounds: OnlySelfBounds, ) -> GenericArgCountResult { let trait_def_id = trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise()); let trait_segment = trait_ref.path.segments.last().unwrap(); - self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {}); + self.prohibit_generic_args(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {}); self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, false); - let (generic_args, arg_count) = self.create_args_for_ast_path( + let (generic_args, arg_count) = self.lower_generic_args_of_path( trait_ref.path.span, trait_def_id, &[], @@ -692,12 +719,11 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } // Specify type to assert that error was already reported in `Err` case. - let _: Result<_, ErrorGuaranteed> = self.add_predicates_for_ast_type_binding( + let _: Result<_, ErrorGuaranteed> = self.lower_assoc_item_binding( trait_ref.hir_ref_id, poly_trait_ref, binding, bounds, - speculative, &mut dup_bindings, binding.span, only_self_bounds, @@ -708,19 +734,22 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { arg_count } - fn ast_path_to_mono_trait_ref( + /// Lower a monomorphic trait reference given a self type while prohibiting associated item bindings. + /// + /// *Monomorphic* in the sense that it doesn't bind any late-bound vars. + fn lower_mono_trait_ref( &self, span: Span, trait_def_id: DefId, self_ty: Ty<'tcx>, trait_segment: &hir::PathSegment<'tcx>, is_impl: bool, - // FIXME(effects) move all host param things in astconv to hir lowering + // FIXME(effects): Move all host param things in HIR ty lowering to AST lowering. constness: ty::BoundConstness, ) -> ty::TraitRef<'tcx> { self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, is_impl); - let (generic_args, _) = self.create_args_for_ast_path( + let (generic_args, _) = self.lower_generic_args_of_path( span, trait_def_id, &[], @@ -729,12 +758,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { constness, ); if let Some(b) = trait_segment.args().bindings.first() { - prohibit_assoc_ty_binding(self.tcx(), b.span, Some((trait_segment, span))); + prohibit_assoc_item_binding(self.tcx(), b.span, Some((trait_segment, span))); } ty::TraitRef::new(self.tcx(), trait_def_id, generic_args) } - fn trait_defines_associated_item_named( + fn probe_trait_that_defines_assoc_item( &self, trait_def_id: DefId, assoc_kind: ty::AssocKind, @@ -746,14 +775,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .is_some() } - fn ast_path_to_ty( + fn lower_path_segment( &self, span: Span, did: DefId, item_segment: &hir::PathSegment<'tcx>, ) -> Ty<'tcx> { let tcx = self.tcx(); - let args = self.ast_path_args_for_ty(span, did, item_segment); + let args = self.lower_generic_args_of_path_segment(span, did, item_segment); if let DefKind::TyAlias = tcx.def_kind(did) && tcx.type_alias_is_lazy(did) @@ -768,30 +797,27 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - // Search for a bound on a type parameter which includes the associated item - // given by `assoc_name`. `ty_param_def_id` is the `DefId` of the type parameter - // This function will fail if there are no suitable bounds or there is - // any ambiguity. - fn find_bound_for_assoc_item( + /// Search for a trait bound on a type parameter whose trait defines the associated type given by `assoc_name`. + /// + /// This fails if there is no such bound in the list of candidates or if there are multiple + /// candidates in which case it reports ambiguity. + /// + /// `ty_param_def_id` is the `LocalDefId` of the type parameter. + #[instrument(level = "debug", skip_all, ret)] + fn probe_single_ty_param_bound_for_assoc_ty( &self, ty_param_def_id: LocalDefId, assoc_name: Ident, span: Span, ) -> Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed> { + debug!(?ty_param_def_id, ?assoc_name, ?span); let tcx = self.tcx(); - debug!( - "find_bound_for_assoc_item(ty_param_def_id={:?}, assoc_name={:?}, span={:?})", - ty_param_def_id, assoc_name, span, - ); - - let predicates = - &self.get_type_parameter_bounds(span, ty_param_def_id, assoc_name).predicates; - - debug!("find_bound_for_assoc_item: predicates={:#?}", predicates); + let predicates = &self.probe_ty_param_bounds(span, ty_param_def_id, assoc_name).predicates; + debug!("predicates={:#?}", predicates); let param_name = tcx.hir().ty_param_name(ty_param_def_id); - self.one_bound_for_assoc_item( + self.probe_single_bound_for_assoc_item( || { traits::transitive_bounds_that_define_assoc_item( tcx, @@ -810,10 +836,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { ) } - // Checks that `bounds` contains exactly one element and reports appropriate - // errors otherwise. + /// Search for a single trait bound whose trait defines the associated item given by `assoc_name`. + /// + /// This fails if there is no such bound in the list of candidates or if there are multiple + /// candidates in which case it reports ambiguity. #[instrument(level = "debug", skip(self, all_candidates, ty_param_name, binding), ret)] - fn one_bound_for_assoc_item<I>( + fn probe_single_bound_for_assoc_item<I>( &self, all_candidates: impl Fn() -> I, ty_param_name: impl Display, @@ -829,7 +857,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { let tcx = self.tcx(); let mut matching_candidates = all_candidates().filter(|r| { - self.trait_defines_associated_item_named(r.def_id(), assoc_kind, assoc_name) + self.probe_trait_that_defines_assoc_item(r.def_id(), assoc_kind, assoc_name) }); let Some(bound) = matching_candidates.next() else { @@ -888,7 +916,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { match binding.kind { hir::TypeBindingKind::Equality { term } => { let term: ty::Term<'_> = match term { - hir::Term::Ty(ty) => self.ast_ty_to_ty(ty).into(), + hir::Term::Ty(ty) => self.lower_ty(ty).into(), hir::Term::Const(ct) => { ty::Const::from_anon_const(tcx, ct.def_id).into() } @@ -934,16 +962,35 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { Ok(bound) } - // Create a type from a path to an associated type or to an enum variant. - // For a path `A::B::C::D`, `qself_ty` and `qself_def` are the type and def for `A::B::C` - // and item_segment is the path segment for `D`. We return a type and a def for - // the whole path. - // Will fail except for `T::A` and `Self::A`; i.e., if `qself_ty`/`qself_def` are not a type - // parameter or `Self`. + /// Lower a [type-relative] path referring to an associated type or to an enum variant. + /// + /// If the path refers to an enum variant and `permit_variants` holds, + /// the returned type is simply the provided self type `qself_ty`. + /// + /// A path like `A::B::C::D` is understood as `<A::B::C>::D`. I.e., + /// `qself_ty` / `qself` is `A::B::C` and `assoc_segment` is `D`. + /// We return the lowered type and the `DefId` for the whole path. + /// + /// We only support associated type paths whose self type is a type parameter or a `Self` + /// type alias (in a trait impl) like `T::Ty` (where `T` is a ty param) or `Self::Ty`. + /// We **don't** support paths whose self type is an arbitrary type like `Struct::Ty` where + /// struct `Struct` impls an in-scope trait that defines an associated type called `Ty`. + /// For the latter case, we report ambiguity. + /// While desirable to support, the implemention would be non-trivial. Tracked in [#22519]. + /// + /// At the time of writing, *inherent associated types* are also resolved here. This however + /// is [problematic][iat]. A proper implementation would be as non-trivial as the one + /// described in the previous paragraph and their modeling of projections would likely be + /// very similar in nature. + /// + /// [type-relative]: hir::QPath::TypeRelative + /// [#22519]: https://github.com/rust-lang/rust/issues/22519 + /// [iat]: https://github.com/rust-lang/rust/issues/8995#issuecomment-1569208403 + // // NOTE: When this function starts resolving `Trait::AssocTy` successfully // it should also start reporting the `BARE_TRAIT_OBJECTS` lint. - #[instrument(level = "debug", skip(self, hir_ref_id, span, qself, assoc_segment), fields(assoc_ident=?assoc_segment.ident), ret)] - pub fn associated_path_to_ty( + #[instrument(level = "debug", skip_all, ret)] + pub fn lower_assoc_path( &self, hir_ref_id: hir::HirId, span: Span, @@ -952,7 +999,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { assoc_segment: &hir::PathSegment<'tcx>, permit_variants: bool, ) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed> { + debug!(%qself_ty, ?assoc_segment.ident); let tcx = self.tcx(); + let assoc_ident = assoc_segment.ident; let qself_res = if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = &qself.kind { path.res @@ -971,7 +1020,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { if let Some(variant_def) = variant_def { if permit_variants { tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span, None); - self.prohibit_generics(slice::from_ref(assoc_segment).iter(), |err| { + self.prohibit_generic_args(slice::from_ref(assoc_segment).iter(), |err| { err.note("enum variants can't have type parameters"); let type_name = tcx.item_name(adt_def.did()); let msg = format!( @@ -1071,7 +1120,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - if let Some((ty, did)) = self.lookup_inherent_assoc_ty( + // FIXME(inherent_associated_types, #106719): Support self types other than ADTs. + if let Some((ty, did)) = self.probe_inherent_assoc_ty( assoc_ident, assoc_segment, adt_def.did(), @@ -1094,7 +1144,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { tcx.dcx().span_bug(span, "expected cycle error"); }; - self.one_bound_for_assoc_item( + self.probe_single_bound_for_assoc_item( || { traits::supertraits( tcx, @@ -1112,7 +1162,11 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { ( &ty::Param(_), Res::SelfTyParam { trait_: param_did } | Res::Def(DefKind::TyParam, param_did), - ) => self.find_bound_for_assoc_item(param_did.expect_local(), assoc_ident, span)?, + ) => self.probe_single_ty_param_bound_for_assoc_ty( + param_did.expect_local(), + assoc_ident, + span, + )?, _ => { let reported = if variant_resolution.is_some() { // Variant in type position @@ -1174,7 +1228,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { self.probe_traits_that_match_assoc_ty(qself_ty, assoc_ident); // Don't print `ty::Error` to the user. - self.report_ambiguous_associated_type( + self.report_ambiguous_assoc_ty( span, &[qself_ty.to_string()], &traits, @@ -1187,8 +1241,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { }; let trait_did = bound.def_id(); - let assoc_ty_did = self.lookup_assoc_ty(assoc_ident, hir_ref_id, span, trait_did).unwrap(); - let ty = self.projected_ty_from_poly_trait_ref(span, assoc_ty_did, assoc_segment, bound); + let assoc_ty_did = self.probe_assoc_ty(assoc_ident, hir_ref_id, span, trait_did).unwrap(); + let ty = self.lower_assoc_ty(span, assoc_ty_did, assoc_segment, bound); if let Some(variant_def_id) = variant_resolution { tcx.node_span_lint( @@ -1222,7 +1276,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { Ok((ty, DefKind::AssocTy, assoc_ty_did)) } - fn lookup_inherent_assoc_ty( + fn probe_inherent_assoc_ty( &self, name: Ident, segment: &hir::PathSegment<'tcx>, @@ -1236,8 +1290,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Don't attempt to look up inherent associated types when the feature is not enabled. // Theoretically it'd be fine to do so since we feature-gate their definition site. // However, due to current limitations of the implementation (caused by us performing - // selection in AstConv), IATs can lead to cycle errors (#108491, #110106) which mask the - // feature-gate error, needlessly confusing users that use IATs by accident (#113265). + // selection during HIR ty lowering instead of in the trait solver), IATs can lead to cycle + // errors (#108491) which mask the feature-gate error, needlessly confusing users + // who use IATs by accident (#113265). if !tcx.features().inherent_associated_types { return Ok(None); } @@ -1245,7 +1300,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { let candidates: Vec<_> = tcx .inherent_impls(adt_did)? .iter() - .filter_map(|&impl_| Some((impl_, self.lookup_assoc_ty_unchecked(name, block, impl_)?))) + .filter_map(|&impl_| Some((impl_, self.probe_assoc_ty_unchecked(name, block, impl_)?))) .collect(); if candidates.is_empty() { @@ -1292,10 +1347,10 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { self.check_assoc_ty(assoc_item, name, def_scope, block, span); // FIXME(fmease): Currently creating throwaway `parent_args` to please - // `create_args_for_associated_item`. Modify the latter instead (or sth. similar) to + // `lower_generic_args_of_assoc_item`. Modify the latter instead (or sth. similar) to // not require the parent args logic. let parent_args = ty::GenericArgs::identity_for_item(tcx, impl_); - let args = self.create_args_for_associated_item(span, assoc_item, segment, parent_args); + let args = self.lower_generic_args_of_assoc_item(span, assoc_item, segment, parent_args); let args = tcx.mk_args_from_iter( std::iter::once(ty::GenericArg::from(self_ty)) .chain(args.into_iter().skip(parent_args.len())), @@ -1358,7 +1413,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .collect(); match &applicable_candidates[..] { - &[] => Err(self.complain_about_inherent_assoc_type_not_found( + &[] => Err(self.complain_about_inherent_assoc_ty_not_found( name, self_ty, candidates, @@ -1368,7 +1423,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { &[applicable_candidate] => Ok(applicable_candidate), - &[_, ..] => Err(self.complain_about_ambiguous_inherent_assoc_type( + &[_, ..] => Err(self.complain_about_ambiguous_inherent_assoc_ty( name, applicable_candidates.into_iter().map(|(_, (candidate, _))| candidate).collect(), span, @@ -1376,19 +1431,19 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - fn lookup_assoc_ty( + fn probe_assoc_ty( &self, name: Ident, block: hir::HirId, span: Span, scope: DefId, ) -> Option<DefId> { - let (item, def_scope) = self.lookup_assoc_ty_unchecked(name, block, scope)?; + let (item, def_scope) = self.probe_assoc_ty_unchecked(name, block, scope)?; self.check_assoc_ty(item, name, def_scope, block, span); Some(item) } - fn lookup_assoc_ty_unchecked( + fn probe_assoc_ty_unchecked( &self, name: Ident, block: hir::HirId, @@ -1493,7 +1548,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .collect() } - fn qpath_to_ty( + /// Lower a qualified path to a type. + #[instrument(level = "debug", skip_all)] + fn lower_qpath( &self, span: Span, opt_self_ty: Option<Ty<'tcx>>, @@ -1505,22 +1562,19 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { let tcx = self.tcx(); let trait_def_id = tcx.parent(item_def_id); - - debug!("qpath_to_ty: trait_def_id={:?}", trait_def_id); + debug!(?trait_def_id); let Some(self_ty) = opt_self_ty else { let path_str = tcx.def_path_str(trait_def_id); let def_id = self.item_def_id(); - - debug!("qpath_to_ty: self.item_def_id()={:?}", def_id); + debug!(item_def_id = ?def_id); let parent_def_id = def_id .as_local() .map(|def_id| tcx.local_def_id_to_hir_id(def_id)) .map(|hir_id| tcx.hir().get_parent_item(hir_id).to_def_id()); - - debug!("qpath_to_ty: parent_def_id={:?}", parent_def_id); + debug!(?parent_def_id); // If the trait in segment is the same as the trait defining the item, // use the `<Self as ..>` syntax in the error. @@ -1547,7 +1601,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // FIXME: also look at `tcx.generics_of(self.item_def_id()).params` any that // references the trait. Relevant for the first case in // `src/test/ui/associated-types/associated-types-in-ambiguous-context.rs` - let reported = self.report_ambiguous_associated_type( + let reported = self.report_ambiguous_assoc_ty( span, &type_names, &[path_str], @@ -1555,27 +1609,19 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { ); return Ty::new_error(tcx, reported); }; + debug!(?self_ty); - debug!("qpath_to_ty: self_type={:?}", self_ty); - - let trait_ref = self.ast_path_to_mono_trait_ref( - span, - trait_def_id, - self_ty, - trait_segment, - false, - constness, - ); + let trait_ref = + self.lower_mono_trait_ref(span, trait_def_id, self_ty, trait_segment, false, constness); + debug!(?trait_ref); let item_args = - self.create_args_for_associated_item(span, item_def_id, item_segment, trait_ref.args); - - debug!("qpath_to_ty: trait_ref={:?}", trait_ref); + self.lower_generic_args_of_assoc_item(span, item_def_id, item_segment, trait_ref.args); Ty::new_projection(tcx, item_def_id, item_args) } - pub fn prohibit_generics<'a>( + pub fn prohibit_generic_args<'a>( &self, segments: impl Iterator<Item = &'a hir::PathSegment<'a>> + Clone, extend: impl Fn(&mut Diag<'_>), @@ -1678,25 +1724,41 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { for segment in segments { // Only emit the first error to avoid overloading the user with error messages. if let Some(b) = segment.args().bindings.first() { - prohibit_assoc_ty_binding(self.tcx(), b.span, None); + prohibit_assoc_item_binding(self.tcx(), b.span, None); return true; } } emitted } + /// Probe path segments that are semantically allowed to have generic arguments. + /// + /// ### Example + /// + /// ```ignore (illustrative) + /// Option::None::<()> + /// // ^^^^ permitted to have generic args + /// + /// // ==> [GenericPathSegment(Option_def_id, 1)] + /// + /// Option::<()>::None + /// // ^^^^^^ ^^^^ *not* permitted to have generic args + /// // permitted to have generic args + /// + /// // ==> [GenericPathSegment(Option_def_id, 0)] + /// ``` // FIXME(eddyb, varkor) handle type paths here too, not just value ones. - pub fn def_ids_for_value_path_segments( + pub fn probe_generic_path_segments( &self, segments: &[hir::PathSegment<'_>], self_ty: Option<Ty<'tcx>>, kind: DefKind, def_id: DefId, span: Span, - ) -> Vec<PathSeg> { - // We need to extract the type parameters supplied by the user in + ) -> Vec<GenericPathSegment> { + // We need to extract the generic arguments supplied by the user in // the path `path`. Due to the current setup, this is a bit of a - // tricky-process; the problem is that resolve only tells us the + // tricky process; the problem is that resolve only tells us the // end-point of the path resolution, and not the intermediate steps. // Luckily, we can (at least for now) deduce the intermediate steps // just from the end-point. @@ -1707,35 +1769,35 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // // struct Foo<T>(...) // - // In this case, the parameters are declared in the type space. + // In this case, the generic arguments are declared in the type space. // // 2. Reference to a constructor of an enum variant: // // enum E<T> { Foo(...) } // - // In this case, the parameters are defined in the type space, + // In this case, the generic arguments are defined in the type space, // but may be specified either on the type or the variant. // - // 3. Reference to a fn item or a free constant: + // 3. Reference to a free function or constant: // - // fn foo<T>() { } + // fn foo<T>() {} // // In this case, the path will again always have the form - // `a::b::foo::<T>` where only the final segment should have - // type parameters. However, in this case, those parameters are - // declared on a value, and hence are in the `FnSpace`. + // `a::b::foo::<T>` where only the final segment should have generic + // arguments. However, in this case, those arguments are declared on + // a value, and hence are in the value space. // - // 4. Reference to a method or an associated constant: + // 4. Reference to an associated function or constant: // // impl<A> SomeStruct<A> { - // fn foo<B>(...) + // fn foo<B>(...) {} // } // - // Here we can have a path like - // `a::b::SomeStruct::<A>::foo::<B>`, in which case parameters - // may appear in two places. The penultimate segment, - // `SomeStruct::<A>`, contains parameters in TypeSpace, and the - // final segment, `foo::<B>` contains parameters in fn space. + // Here we can have a path like `a::b::SomeStruct::<A>::foo::<B>`, + // in which case generic arguments may appear in two places. The + // penultimate segment, `SomeStruct::<A>`, contains generic arguments + // in the type space, and the final segment, `foo::<B>` contains + // generic arguments in value space. // // The first step then is to categorize the segments appropriately. @@ -1744,7 +1806,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { assert!(!segments.is_empty()); let last = segments.len() - 1; - let mut path_segs = vec![]; + let mut generic_segments = vec![]; match kind { // Case 1. Reference to a struct constructor. @@ -1755,7 +1817,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Variant and struct constructors use the // generics of their parent type definition. let generics_def_id = generics.parent.unwrap_or(def_id); - path_segs.push(PathSeg(generics_def_id, last)); + generic_segments.push(GenericPathSegment(generics_def_id, last)); } // Case 2. Reference to a variant constructor. @@ -1788,56 +1850,53 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // generics of their parent type definition. (generics.parent.unwrap_or(def_id), last) }; - path_segs.push(PathSeg(generics_def_id, index)); + generic_segments.push(GenericPathSegment(generics_def_id, index)); } // Case 3. Reference to a top-level value. DefKind::Fn | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } => { - path_segs.push(PathSeg(def_id, last)); + generic_segments.push(GenericPathSegment(def_id, last)); } // Case 4. Reference to a method or associated const. DefKind::AssocFn | DefKind::AssocConst => { if segments.len() >= 2 { let generics = tcx.generics_of(def_id); - path_segs.push(PathSeg(generics.parent.unwrap(), last - 1)); + generic_segments.push(GenericPathSegment(generics.parent.unwrap(), last - 1)); } - path_segs.push(PathSeg(def_id, last)); + generic_segments.push(GenericPathSegment(def_id, last)); } kind => bug!("unexpected definition kind {:?} for {:?}", kind, def_id), } - debug!("path_segs = {:?}", path_segs); + debug!(?generic_segments); - path_segs + generic_segments } - /// Check a type `Path` and convert it to a `Ty`. - pub fn res_to_ty( + /// Lower a type `Path` to a type. + #[instrument(level = "debug", skip_all)] + pub fn lower_path( &self, opt_self_ty: Option<Ty<'tcx>>, path: &hir::Path<'tcx>, hir_id: hir::HirId, permit_variants: bool, ) -> Ty<'tcx> { + debug!(?path.res, ?opt_self_ty, ?path.segments); let tcx = self.tcx(); - debug!( - "res_to_ty(res={:?}, opt_self_ty={:?}, path_segments={:?})", - path.res, opt_self_ty, path.segments - ); - let span = path.span; match path.res { Res::Def(DefKind::OpaqueTy, did) => { // Check for desugared `impl Trait`. assert!(tcx.is_type_alias_impl_trait(did)); let item_segment = path.segments.split_last().unwrap(); - self.prohibit_generics(item_segment.1.iter(), |err| { + self.prohibit_generic_args(item_segment.1.iter(), |err| { err.note("`impl Trait` types can't have type parameters"); }); - let args = self.ast_path_args_for_ty(span, did, item_segment.0); + let args = self.lower_generic_args_of_path_segment(span, did, item_segment.0); Ty::new_opaque(tcx, did, args) } Res::Def( @@ -1849,44 +1908,44 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { did, ) => { assert_eq!(opt_self_ty, None); - self.prohibit_generics(path.segments.split_last().unwrap().1.iter(), |_| {}); - self.ast_path_to_ty(span, did, path.segments.last().unwrap()) + self.prohibit_generic_args(path.segments.split_last().unwrap().1.iter(), |_| {}); + self.lower_path_segment(span, did, path.segments.last().unwrap()) } Res::Def(kind @ DefKind::Variant, def_id) if permit_variants => { - // Convert "variant type" as if it were a real type. + // Lower "variant type" as if it were a real type. // The resulting `Ty` is type of the variant's enum for now. assert_eq!(opt_self_ty, None); - let path_segs = - self.def_ids_for_value_path_segments(path.segments, None, kind, def_id, span); - let generic_segs: FxHashSet<_> = - path_segs.iter().map(|PathSeg(_, index)| index).collect(); - self.prohibit_generics( + let generic_segments = + self.probe_generic_path_segments(path.segments, None, kind, def_id, span); + let indices: FxHashSet<_> = + generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect(); + self.prohibit_generic_args( path.segments.iter().enumerate().filter_map(|(index, seg)| { - if !generic_segs.contains(&index) { Some(seg) } else { None } + if !indices.contains(&index) { Some(seg) } else { None } }), |err| { err.note("enum variants can't have type parameters"); }, ); - let PathSeg(def_id, index) = path_segs.last().unwrap(); - self.ast_path_to_ty(span, *def_id, &path.segments[*index]) + let GenericPathSegment(def_id, index) = generic_segments.last().unwrap(); + self.lower_path_segment(span, *def_id, &path.segments[*index]) } Res::Def(DefKind::TyParam, def_id) => { assert_eq!(opt_self_ty, None); - self.prohibit_generics(path.segments.iter(), |err| { + self.prohibit_generic_args(path.segments.iter(), |err| { if let Some(span) = tcx.def_ident_span(def_id) { let name = tcx.item_name(def_id); err.span_note(span, format!("type parameter `{name}` defined here")); } }); - self.hir_id_to_bound_ty(hir_id) + self.lower_ty_param(hir_id) } Res::SelfTyParam { .. } => { // `Self` in trait or type alias. assert_eq!(opt_self_ty, None); - self.prohibit_generics(path.segments.iter(), |err| { + self.prohibit_generic_args(path.segments.iter(), |err| { if let [hir::PathSegment { args: Some(args), ident, .. }] = &path.segments { err.span_suggestion_verbose( ident.span.shrink_to_hi().to(args.span_ext), @@ -1904,7 +1963,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Try to evaluate any array length constants. let ty = tcx.at(span).type_of(def_id).instantiate_identity(); let span_of_impl = tcx.span_of_impl(def_id); - self.prohibit_generics(path.segments.iter(), |err| { + self.prohibit_generic_args(path.segments.iter(), |err| { let def_id = match *ty.kind() { ty::Adt(self_def, _) => self_def.did(), _ => return, @@ -2002,14 +2061,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } Res::Def(DefKind::AssocTy, def_id) => { debug_assert!(path.segments.len() >= 2); - self.prohibit_generics(path.segments[..path.segments.len() - 2].iter(), |_| {}); + self.prohibit_generic_args(path.segments[..path.segments.len() - 2].iter(), |_| {}); // HACK: until we support `<Type as ~const Trait>`, assume all of them are. let constness = if tcx.has_attr(tcx.parent(def_id), sym::const_trait) { ty::BoundConstness::ConstIfConst } else { ty::BoundConstness::NotConst }; - self.qpath_to_ty( + self.lower_qpath( span, opt_self_ty, def_id, @@ -2020,7 +2079,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } Res::PrimTy(prim_ty) => { assert_eq!(opt_self_ty, None); - self.prohibit_generics(path.segments.iter(), |err| { + self.prohibit_generic_args(path.segments.iter(), |err| { let name = prim_ty.name_str(); for segment in path.segments { if let Some(args) = segment.args { @@ -2054,9 +2113,11 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - // Converts a hir id corresponding to a type parameter to - // a early-bound `ty::Param` or late-bound `ty::Bound`. - pub(crate) fn hir_id_to_bound_ty(&self, hir_id: hir::HirId) -> Ty<'tcx> { + /// Lower a type parameter from the HIR to our internal notion of a type. + /// + /// Early-bound type parameters get lowered to [`ty::Param`] + /// and late-bound ones to [`ty::Bound`]. + pub(crate) fn lower_ty_param(&self, hir_id: hir::HirId) -> Ty<'tcx> { let tcx = self.tcx(); match tcx.named_bound_var(hir_id) { Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => { @@ -2079,13 +2140,11 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - // Converts a hir id corresponding to a const parameter to - // a early-bound `ConstKind::Param` or late-bound `ConstKind::Bound`. - pub(crate) fn hir_id_to_bound_const( - &self, - hir_id: hir::HirId, - param_ty: Ty<'tcx>, - ) -> Const<'tcx> { + /// Lower a const parameter from the HIR to our internal notion of a constant. + /// + /// Early-bound const parameters get lowered to [`ty::ConstKind::Param`] + /// and late-bound ones to [`ty::ConstKind::Bound`]. + pub(crate) fn lower_const_param(&self, hir_id: hir::HirId, param_ty: Ty<'tcx>) -> Const<'tcx> { let tcx = self.tcx(); match tcx.named_bound_var(hir_id) { Some(rbv::ResolvedArg::EarlyBound(def_id)) => { @@ -2105,16 +2164,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - /// Parses the programmer's textual representation of a type into our - /// internal notion of a type. - pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { - self.ast_ty_to_ty_inner(ast_ty, false, false) + /// Lower a type from the HIR to our internal notion of a type. + pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { + self.lower_ty_common(hir_ty, false, false) } - /// Parses the programmer's textual representation of a type into our - /// internal notion of a type. This is meant to be used within a path. - pub fn ast_ty_to_ty_in_path(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { - self.ast_ty_to_ty_inner(ast_ty, false, true) + /// Lower a type inside of a path from the HIR to our internal notion of a type. + pub fn lower_ty_in_path(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { + self.lower_ty_common(hir_ty, false, true) } fn check_delegation_constraints(&self, sig_id: DefId, span: Span, emit: bool) -> bool { @@ -2181,7 +2238,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { error_occured } - fn ty_from_delegation( + fn lower_delegation_ty( &self, sig_id: DefId, idx: hir::InferDelegationKind, @@ -2215,8 +2272,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { sig.instantiate_identity() }; - // Bound vars are also inherited from `sig_id`. They will be - // rebinded later in `ty_of_fn`. + // Bound vars are also inherited from `sig_id`. + // They will be rebound later in `lower_fn_ty`. let sig = sig.skip_binder(); match idx { @@ -2225,66 +2282,74 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - /// Turns a `hir::Ty` into a `Ty`. For diagnostics' purposes we keep track of whether trait - /// objects are borrowed like `&dyn Trait` to avoid emitting redundant errors. + /// Lower a type from the HIR to our internal notion of a type given some extra data for diagnostics. + /// + /// Extra diagnostic data: + /// + /// 1. `borrowed`: Whether trait object types are borrowed like in `&dyn Trait`. + /// Used to avoid emitting redundant errors. + /// 2. `in_path`: Whether the type appears inside of a path. + /// Used to provide correct diagnostics for bare trait object types. #[instrument(level = "debug", skip(self), ret)] - fn ast_ty_to_ty_inner( - &self, - ast_ty: &hir::Ty<'tcx>, - borrowed: bool, - in_path: bool, - ) -> Ty<'tcx> { + fn lower_ty_common(&self, hir_ty: &hir::Ty<'tcx>, borrowed: bool, in_path: bool) -> Ty<'tcx> { let tcx = self.tcx(); - let result_ty = match &ast_ty.kind { + let result_ty = match &hir_ty.kind { hir::TyKind::InferDelegation(sig_id, idx) => { - self.ty_from_delegation(*sig_id, *idx, ast_ty.span) + self.lower_delegation_ty(*sig_id, *idx, hir_ty.span) } - hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.ast_ty_to_ty(ty)), + hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.lower_ty(ty)), hir::TyKind::Ptr(mt) => { - Ty::new_ptr(tcx, ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl }) + Ty::new_ptr(tcx, ty::TypeAndMut { ty: self.lower_ty(mt.ty), mutbl: mt.mutbl }) } hir::TyKind::Ref(region, mt) => { - let r = self.ast_region_to_region(region, None); + let r = self.lower_lifetime(region, None); debug!(?r); - let t = self.ast_ty_to_ty_inner(mt.ty, true, false); + let t = self.lower_ty_common(mt.ty, true, false); Ty::new_ref(tcx, r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl }) } hir::TyKind::Never => tcx.types.never, hir::TyKind::Tup(fields) => { - Ty::new_tup_from_iter(tcx, fields.iter().map(|t| self.ast_ty_to_ty(t))) + Ty::new_tup_from_iter(tcx, fields.iter().map(|t| self.lower_ty(t))) } hir::TyKind::AnonAdt(item_id) => { + let _guard = debug_span!("AnonAdt"); + let did = item_id.owner_id.def_id; let adt_def = tcx.adt_def(did); - let generics = tcx.generics_of(did); - debug!("ast_ty_to_ty_inner(AnonAdt): generics={:?}", generics); let args = ty::GenericArgs::for_item(tcx, did.to_def_id(), |param, _| { tcx.mk_param_from_def(param) }); - debug!("ast_ty_to_ty_inner(AnonAdt): args={:?}", args); + debug!(?args); Ty::new_adt(tcx, adt_def, tcx.mk_args(args)) } hir::TyKind::BareFn(bf) => { - require_c_abi_if_c_variadic(tcx, bf.decl, bf.abi, ast_ty.span); + require_c_abi_if_c_variadic(tcx, bf.decl, bf.abi, hir_ty.span); Ty::new_fn_ptr( tcx, - self.ty_of_fn(ast_ty.hir_id, bf.unsafety, bf.abi, bf.decl, None, Some(ast_ty)), + self.lower_fn_ty( + hir_ty.hir_id, + bf.unsafety, + bf.abi, + bf.decl, + None, + Some(hir_ty), + ), ) } hir::TyKind::TraitObject(bounds, lifetime, repr) => { - self.maybe_lint_bare_trait(ast_ty, in_path); + self.maybe_lint_bare_trait(hir_ty, in_path); let repr = match repr { TraitObjectSyntax::Dyn | TraitObjectSyntax::None => ty::Dyn, TraitObjectSyntax::DynStar => ty::DynStar, }; - self.conv_object_ty_poly_trait_ref( - ast_ty.span, - ast_ty.hir_id, + self.lower_trait_object_ty( + hir_ty.span, + hir_ty.hir_id, bounds, lifetime, borrowed, @@ -2293,8 +2358,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path)) => { debug!(?maybe_qself, ?path); - let opt_self_ty = maybe_qself.as_ref().map(|qself| self.ast_ty_to_ty(qself)); - self.res_to_ty(opt_self_ty, path, ast_ty.hir_id, false) + let opt_self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself)); + self.lower_path(opt_self_ty, path, hir_ty.hir_id, false) } &hir::TyKind::OpaqueDef(item_id, lifetimes, in_trait) => { let opaque_ty = tcx.hir().item(item_id); @@ -2310,21 +2375,21 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } else { local_def_id.to_def_id() }; - self.impl_trait_ty_to_ty(def_id, lifetimes, in_trait) + self.lower_opaque_ty(def_id, lifetimes, in_trait) } ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i), } } hir::TyKind::Path(hir::QPath::TypeRelative(qself, segment)) => { debug!(?qself, ?segment); - let ty = self.ast_ty_to_ty_inner(qself, false, true); - self.associated_path_to_ty(ast_ty.hir_id, ast_ty.span, ty, qself, segment, false) + let ty = self.lower_ty_common(qself, false, true); + self.lower_assoc_path(hir_ty.hir_id, hir_ty.span, ty, qself, segment, false) .map(|(ty, _, _)| ty) .unwrap_or_else(|guar| Ty::new_error(tcx, guar)) } &hir::TyKind::Path(hir::QPath::LangItem(lang_item, span)) => { let def_id = tcx.require_lang_item(lang_item, Some(span)); - let (args, _) = self.create_args_for_ast_path( + let (args, _) = self.lower_generic_args_of_path( span, def_id, &[], @@ -2342,7 +2407,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } }; - Ty::new_array_with_const_len(tcx, self.ast_ty_to_ty(ty), length) + Ty::new_array_with_const_len(tcx, self.lower_ty(ty), length) } hir::TyKind::Typeof(e) => tcx.type_of(e.def_id).instantiate_identity(), hir::TyKind::Infer => { @@ -2350,28 +2415,29 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // values in an ExprKind::Closure, or as // the type of local variables. Both of these cases are // handled specially and will not descend into this routine. - self.ty_infer(None, ast_ty.span) + self.ty_infer(None, hir_ty.span) } hir::TyKind::Err(guar) => Ty::new_error(tcx, *guar), }; - self.record_ty(ast_ty.hir_id, result_ty, ast_ty.span); + self.record_ty(hir_ty.hir_id, result_ty, hir_ty.span); result_ty } - #[instrument(level = "debug", skip(self), ret)] - fn impl_trait_ty_to_ty( + /// Lower an opaque type (i.e., an existential impl-Trait type) from the HIR. + #[instrument(level = "debug", skip_all, ret)] + fn lower_opaque_ty( &self, def_id: DefId, lifetimes: &[hir::GenericArg<'_>], in_trait: bool, ) -> Ty<'tcx> { - debug!("impl_trait_ty_to_ty(def_id={:?}, lifetimes={:?})", def_id, lifetimes); + debug!(?def_id, ?lifetimes); let tcx = self.tcx(); let generics = tcx.generics_of(def_id); + debug!(?generics); - debug!("impl_trait_ty_to_ty: generics={:?}", generics); let args = ty::GenericArgs::for_item(tcx, def_id, |param, _| { // We use `generics.count() - lifetimes.len()` here instead of `generics.parent_count` // since return-position impl trait in trait squashes all of the generics from its source fn @@ -2392,12 +2458,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { &lifetimes[i] ) }; - self.ast_region_to_region(lifetime, None).into() + self.lower_lifetime(lifetime, None).into() } else { tcx.mk_param_from_def(param) } }); - debug!("impl_trait_ty_to_ty: args={:?}", args); + debug!(?args); if in_trait { Ty::new_projection(tcx, def_id, args) @@ -2406,18 +2472,19 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - pub fn ty_of_arg(&self, ty: &hir::Ty<'tcx>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> { + pub fn lower_arg_ty(&self, ty: &hir::Ty<'tcx>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> { match ty.kind { hir::TyKind::Infer if let Some(expected_ty) = expected_ty => { self.record_ty(ty.hir_id, expected_ty, ty.span); expected_ty } - _ => self.ast_ty_to_ty(ty), + _ => self.lower_ty(ty), } } + /// Lower a function type from the HIR to our internal notion of a function signature. #[instrument(level = "debug", skip(self, hir_id, unsafety, abi, decl, generics, hir_ty), ret)] - pub fn ty_of_fn( + pub fn lower_fn_ty( &self, hir_id: hir::HirId, unsafety: hir::Unsafety, @@ -2450,7 +2517,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .enumerate() .map(|(i, a)| { if let hir::TyKind::Infer = a.kind - && !self.allow_ty_infer() + && !self.allow_infer() { if let Some(suggested_ty) = self.suggest_trait_fn_ty_for_impl_fn_infer(hir_id, Some(i)) @@ -2466,14 +2533,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Only visit the type looking for `_` if we didn't fix the type above visitor.visit_ty(a); - self.ty_of_arg(a, None) + self.lower_arg_ty(a, None) }) .collect(); let output_ty = match decl.output { hir::FnRetTy::Return(output) => { if let hir::TyKind::Infer = output.kind - && !self.allow_ty_infer() + && !self.allow_infer() && let Some(suggested_ty) = self.suggest_trait_fn_ty_for_impl_fn_infer(hir_id, None) { @@ -2481,7 +2548,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { Ty::new_error_with_message(self.tcx(), output.span, suggested_ty.to_string()) } else { visitor.visit_ty(output); - self.ast_ty_to_ty(output) + self.lower_ty(output) } } hir::FnRetTy::DefaultReturn(..) => Ty::new_unit(tcx), @@ -2492,10 +2559,10 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, unsafety, abi); let bare_fn_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars); - if !self.allow_ty_infer() && !(visitor.0.is_empty() && infer_replacements.is_empty()) { + if !self.allow_infer() && !(visitor.0.is_empty() && infer_replacements.is_empty()) { // We always collect the spans for placeholder types when evaluating `fn`s, but we // only want to emit an error complaining about them if infer types (`_`) are not - // allowed. `allow_ty_infer` gates this behavior. We check for the presence of + // allowed. `allow_infer` gates this behavior. We check for the presence of // `ident_span` to not emit an error twice when we have `fn foo(_: fn() -> _)`. let mut diag = crate::collect::placeholder_type_error_diag( @@ -2564,8 +2631,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { }; let i = tcx.parent_hir_node(fn_hir_id).expect_item().expect_impl(); - let trait_ref = - self.instantiate_mono_trait_ref(i.of_trait.as_ref()?, self.ast_ty_to_ty(i.self_ty)); + let trait_ref = self.lower_impl_trait_ref(i.of_trait.as_ref()?, self.lower_ty(i.self_ty)); let assoc = tcx.associated_items(trait_ref.def_id).find_by_name_and_kind( tcx, @@ -2622,7 +2688,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } /// Given the bounds on an object, determines what single region bound (if any) we can - /// use to summarize this type. The basic idea is that we will use the bound the user + /// use to summarize this type. + /// + /// The basic idea is that we will use the bound the user /// provided, if they provided one, and otherwise search the supertypes of trait bounds /// for region bounds. It may be that we can derive no bound at all, in which case /// we return `None`. diff --git a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs index d97728c3303..c5a36128cff 100644 --- a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs @@ -1,6 +1,6 @@ -use crate::astconv::{GenericArgCountMismatch, GenericArgCountResult, OnlySelfBounds}; use crate::bounds::Bounds; use crate::errors::TraitObjectDeclaredWithNoTraits; +use crate::hir_ty_lowering::{GenericArgCountMismatch, GenericArgCountResult, OnlySelfBounds}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_errors::{codes::*, struct_span_code_err}; use rustc_hir as hir; @@ -11,14 +11,16 @@ use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{DynKind, ToPredicate}; use rustc_span::Span; use rustc_trait_selection::traits::error_reporting::report_object_safety_error; -use rustc_trait_selection::traits::{self, astconv_object_safety_violations}; +use rustc_trait_selection::traits::{self, hir_ty_lowering_object_safety_violations}; use smallvec::{smallvec, SmallVec}; -use super::AstConv; +use super::HirTyLowerer; -impl<'tcx> dyn AstConv<'tcx> + '_ { - pub(super) fn conv_object_ty_poly_trait_ref( +impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { + /// Lower a trait object type from the HIR to our internal notion of a type. + #[instrument(level = "debug", skip_all, ret)] + pub(super) fn lower_trait_object_ty( &self, span: Span, hir_id: hir::HirId, @@ -37,14 +39,13 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { correct: Err(GenericArgCountMismatch { invalid_args: cur_potential_assoc_types, .. }), .. - } = self.instantiate_poly_trait_ref( + } = self.lower_poly_trait_ref( &trait_bound.trait_ref, trait_bound.span, ty::BoundConstness::NotConst, ty::ImplPolarity::Positive, dummy_self, &mut bounds, - false, // True so we don't populate `bounds` with associated type bounds, even // though they're disallowed from object types. OnlySelfBounds(true), @@ -134,7 +135,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // to avoid ICEs. for item in ®ular_traits { let object_safety_violations = - astconv_object_safety_violations(tcx, item.trait_ref().def_id()); + hir_ty_lowering_object_safety_violations(tcx, item.trait_ref().def_id()); if !object_safety_violations.is_empty() { let reported = report_object_safety_error( tcx, @@ -157,7 +158,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { for (base_trait_ref, span) in regular_traits_refs_spans { let base_pred: ty::Predicate<'tcx> = base_trait_ref.to_predicate(tcx); for pred in traits::elaborate(tcx, [base_pred]).filter_only_self() { - debug!("conv_object_ty_poly_trait_ref: observing object predicate `{:?}`", pred); + debug!("observing object predicate `{pred:?}`"); let bound_predicate = pred.kind(); match bound_predicate.skip_binder() { @@ -232,7 +233,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { def_ids.retain(|def_id| !tcx.generics_require_sized_self(def_id)); } - self.complain_about_missing_associated_types( + self.complain_about_missing_assoc_tys( associated_types, potential_assoc_types, hir_trait_bounds, @@ -244,8 +245,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // the bounds let mut duplicates = FxHashSet::default(); auto_traits.retain(|i| duplicates.insert(i.trait_ref().def_id())); - debug!("regular_traits: {:?}", regular_traits); - debug!("auto_traits: {:?}", auto_traits); + debug!(?regular_traits); + debug!(?auto_traits); // Erase the `dummy_self` (`trait_object_dummy_self`) used above. let existential_trait_refs = regular_traits.iter().map(|i| { @@ -363,11 +364,11 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Use explicitly-specified region bound. let region_bound = if !lifetime.is_elided() { - self.ast_region_to_region(lifetime, None) + self.lower_lifetime(lifetime, None) } else { self.compute_object_lifetime_bound(span, existential_predicates).unwrap_or_else(|| { if tcx.named_bound_var(lifetime.hir_id).is_some() { - self.ast_region_to_region(lifetime, None) + self.lower_lifetime(lifetime, None) } else { self.re_infer(None, span).unwrap_or_else(|| { let err = struct_span_code_err!( @@ -390,10 +391,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } }) }; - debug!("region_bound: {:?}", region_bound); + debug!(?region_bound); - let ty = Ty::new_dynamic(tcx, existential_predicates, region_bound, representation); - debug!("trait_object_type: {:?}", ty); - ty + Ty::new_dynamic(tcx, existential_predicates, region_bound, representation) } } diff --git a/compiler/rustc_hir_analysis/src/hir_wf_check.rs b/compiler/rustc_hir_analysis/src/hir_wf_check.rs index 2a9101b3808..7014b23ff07 100644 --- a/compiler/rustc_hir_analysis/src/hir_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/hir_wf_check.rs @@ -68,7 +68,7 @@ fn diagnostic_hir_wf_check<'tcx>( let infcx = self.tcx.infer_ctxt().build(); let ocx = ObligationCtxt::new(&infcx); - let tcx_ty = self.icx.to_ty(ty); + let tcx_ty = self.icx.lower_ty(ty); // This visitor can walk into binders, resulting in the `tcx_ty` to // potentially reference escaping bound variables. We simply erase // those here. @@ -163,6 +163,16 @@ fn diagnostic_hir_wf_check<'tcx>( kind: hir::GenericParamKind::Type { default: Some(ty), .. }, .. }) => vec![*ty], + hir::Node::AnonConst(_) + if let Some(const_param_id) = + tcx.hir().opt_const_param_default_param_def_id(hir_id) + && let hir::Node::GenericParam(hir::GenericParam { + kind: hir::GenericParamKind::Const { ty, .. }, + .. + }) = tcx.hir_node_by_def_id(const_param_id) => + { + vec![*ty] + } ref node => bug!("Unexpected node {:?}", node), }, WellFormedLoc::Param { function: _, param_idx } => { diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 19ab2045cc5..3ec5894700f 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -30,8 +30,8 @@ several major phases: The type checker is defined into various submodules which are documented independently: -- astconv: converts the AST representation of types - into the `ty` representation. +- hir_ty_lowering: lowers type-system entities from the [HIR][hir] to the + [`rustc_middle::ty`] representation. - collect: computes the types of each top-level item and enters them into the `tcx.types` table for later use. @@ -68,7 +68,6 @@ This API is completely unstable and subject to change. #![feature(is_sorted)] #![feature(iter_intersperse)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(min_specialization))] #![feature(never_type)] #![feature(lazy_cell)] #![feature(slice_partition_dedup)] @@ -83,11 +82,11 @@ extern crate rustc_middle; // These are used by Clippy. pub mod check; -pub mod astconv; pub mod autoderef; mod bounds; mod check_unused; mod coherence; +pub mod hir_ty_lowering; // FIXME: This module shouldn't be public. pub mod collect; mod constrained_generic_params; @@ -212,12 +211,20 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { Ok(()) } -/// A quasi-deprecated helper used in rustdoc and clippy to get -/// the type from a HIR node. -pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { +/// Lower a [`hir::Ty`] to a [`Ty`]. +/// +/// <div class="warning"> +/// +/// This function is **quasi-deprecated**. It can cause ICEs if called inside of a body +/// (of a function or constant) and especially if it contains inferred types (`_`). +/// +/// It's used in rustdoc and Clippy. +/// +/// </div> +pub fn lower_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { // In case there are any projections, etc., find the "environment" // def-ID that will be used to determine the traits/predicates in // scope. This is derived from the enclosing item-like thing. let env_def_id = tcx.hir().get_parent_item(hir_ty.hir_id); - collect::ItemCtxt::new(tcx, env_def_id.def_id).to_ty(hir_ty) + collect::ItemCtxt::new(tcx, env_def_id.def_id).lower_ty(hir_ty) } diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 580cdb4a3a2..93a0e924099 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -1,6 +1,6 @@ //! Constraint construction and representation //! -//! The second pass over the AST determines the set of constraints. +//! The second pass over the HIR determines the set of constraints. //! We walk the set of items and, for each member, generate new constraints. use hir::def_id::{DefId, LocalDefId}; diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index e070db9423d..71fdcc76a70 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -121,7 +121,7 @@ impl<'a> State<'a> { self.print_bounds(":", pred.bounds); } Node::ArrayLenInfer(_) => self.word("_"), - Node::AssocOpaqueTy(..) => unreachable!(), + Node::Synthetic => unreachable!(), Node::Err(_) => self.word("/*ERROR*/"), } } @@ -1387,7 +1387,7 @@ impl<'a> State<'a> { // Print `}`: self.bclose_maybe_open(expr.span, true); } - hir::ExprKind::Let(&hir::Let { pat, ty, init, .. }) => { + hir::ExprKind::Let(&hir::LetExpr { pat, ty, init, .. }) => { self.print_let(pat, ty, init); } hir::ExprKind::If(test, blk, elseopt) => { @@ -1808,6 +1808,12 @@ impl<'a> State<'a> { self.pclose(); } } + PatKind::Deref(inner) => { + self.word("deref!"); + self.popen(); + self.print_pat(inner); + self.pclose(); + } PatKind::Ref(inner, mutbl) => { let is_range_inner = matches!(inner.kind, PatKind::Range(..)); self.word("&"); diff --git a/compiler/rustc_hir_typeck/src/_match.rs b/compiler/rustc_hir_typeck/src/_match.rs index 4b3359858f1..1805e9fbb98 100644 --- a/compiler/rustc_hir_typeck/src/_match.rs +++ b/compiler/rustc_hir_typeck/src/_match.rs @@ -317,7 +317,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.note("`if` expressions without `else` evaluate to `()`"); err.help("consider adding an `else` block that evaluates to the expected type"); *error = true; - if let ExprKind::Let(hir::Let { span, pat, init, .. }) = cond_expr.kind + if let ExprKind::Let(hir::LetExpr { span, pat, init, .. }) = cond_expr.kind && let ExprKind::Block(block, _) = then_expr.kind // Refutability checks occur on the MIR, so we approximate it here by checking // if we have an enum with a single variant or a struct in the pattern. @@ -645,7 +645,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { for ty in [first_ty, second_ty] { for (clause, _) in self .tcx - .explicit_item_bounds(rpit_def_id) + .explicit_item_super_predicates(rpit_def_id) .iter_instantiated_copied(self.tcx, args) { let pred = clause.kind().rebind(match clause.kind().skip_binder() { diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 25d34531379..0e75a47683d 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -184,16 +184,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { kind: TypeVariableOriginKind::TypeInference, span: callee_expr.span, }); + // We may actually receive a coroutine back whose kind is different + // from the closure that this dispatched from. This is because when + // we have no captures, we automatically implement `FnOnce`. This + // impl forces the closure kind to `FnOnce` i.e. `u8`. + let kind_ty = self.next_ty_var(TypeVariableOrigin { + kind: TypeVariableOriginKind::TypeInference, + span: callee_expr.span, + }); let call_sig = self.tcx.mk_fn_sig( [coroutine_closure_sig.tupled_inputs_ty], coroutine_closure_sig.to_coroutine( self.tcx, closure_args.parent_args(), - // Inherit the kind ty of the closure, since we're calling this - // coroutine with the most relaxed `AsyncFn*` trait that we can. - // We don't necessarily need to do this here, but it saves us - // computing one more infer var that will get constrained later. - closure_args.kind_ty(), + kind_ty, self.tcx.coroutine_for_closure(def_id), tupled_upvars_ty, ), @@ -755,7 +759,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = callee_expr.kind && let Res::Local(_) = path.res - && let [segment] = &path.segments[..] + && let [segment] = &path.segments { for id in self.tcx.hir().items() { if let Some(node) = self.tcx.hir().get_if_local(id.owner_id.into()) diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 4bea4bb3e82..40555bf14eb 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -5,7 +5,7 @@ use super::{check_fn, CoroutineTypes, Expectation, FnCtxt}; use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::lang_items::LangItem; -use rustc_hir_analysis::astconv::AstConv; +use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes}; use rustc_infer::infer::{InferOk, InferResult}; @@ -262,6 +262,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }, ); + let coroutine_kind_ty = self.next_ty_var(TypeVariableOrigin { + kind: TypeVariableOriginKind::ClosureSynthetic, + span: expr_span, + }); let coroutine_upvars_ty = self.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::ClosureSynthetic, span: expr_span, @@ -279,7 +283,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { sig.to_coroutine( tcx, parent_args, - closure_kind_ty, + coroutine_kind_ty, tcx.coroutine_for_closure(expr_def_id), coroutine_upvars_ty, ) @@ -325,7 +329,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected_ty, closure_kind, self.tcx - .explicit_item_bounds(def_id) + .explicit_item_super_predicates(def_id) .iter_instantiated_copied(self.tcx, args) .map(|(c, s)| (c.as_predicate(), s)), ), @@ -780,7 +784,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { decl: &hir::FnDecl<'tcx>, closure_kind: hir::ClosureKind, ) -> ty::PolyFnSig<'tcx> { - let astconv = self.astconv(); + let lowerer = self.lowerer(); trace!("decl = {:#?}", decl); debug!(?closure_kind); @@ -789,9 +793,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let bound_vars = self.tcx.late_bound_vars(hir_id); // First, convert the types that the user supplied (if any). - let supplied_arguments = decl.inputs.iter().map(|a| astconv.ast_ty_to_ty(a)); + let supplied_arguments = decl.inputs.iter().map(|a| lowerer.lower_ty(a)); let supplied_return = match decl.output { - hir::FnRetTy::Return(ref output) => astconv.ast_ty_to_ty(output), + hir::FnRetTy::Return(ref output) => lowerer.lower_ty(output), hir::FnRetTy::DefaultReturn(_) => match closure_kind { // In the case of the async block that we create for a function body, // we expect the return type of the block to match that of the enclosing @@ -809,7 +813,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // easily (and locally) prove that we // *have* reported an // error. --nikomatsakis - astconv.ty_infer(None, decl.output.span()) + lowerer.ty_infer(None, decl.output.span()) }) } // All `gen {}` and `async gen {}` must return unit. @@ -828,7 +832,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | hir::ClosureKind::Coroutine(hir::CoroutineKind::Coroutine(_)) | hir::ClosureKind::Closure | hir::ClosureKind::CoroutineClosure(_) => { - astconv.ty_infer(None, decl.output.span()) + lowerer.ty_infer(None, decl.output.span()) } }, }; @@ -902,7 +906,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => self .tcx - .explicit_item_bounds(def_id) + .explicit_item_super_predicates(def_id) .iter_instantiated_copied(self.tcx, args) .find_map(|(p, s)| get_future_output(p.as_predicate(), s))?, ty::Error(_) => return Some(ret_ty), @@ -985,17 +989,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { decl: &hir::FnDecl<'tcx>, guar: ErrorGuaranteed, ) -> ty::PolyFnSig<'tcx> { - let astconv = self.astconv(); + let lowerer = self.lowerer(); let err_ty = Ty::new_error(self.tcx, guar); let supplied_arguments = decl.inputs.iter().map(|a| { // Convert the types that the user supplied (if any), but ignore them. - astconv.ast_ty_to_ty(a); + lowerer.lower_ty(a); err_ty }); if let hir::FnRetTy::Return(ref output) = decl.output { - astconv.ast_ty_to_ty(output); + lowerer.lower_ty(output); } let result = ty::Binder::dummy(self.tcx.mk_fn_sig( diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 792359c9dda..a218b4ec7a5 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -41,7 +41,7 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::Expr; -use rustc_hir_analysis::astconv::AstConv; +use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult}; use rustc_infer::traits::TraitEngine; diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 1a142f27809..bd1d7d122d1 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -35,8 +35,8 @@ use rustc_hir::def_id::DefId; use rustc_hir::intravisit::Visitor; use rustc_hir::lang_items::LangItem; use rustc_hir::{ExprKind, HirId, QPath}; -use rustc_hir_analysis::astconv::AstConv as _; use rustc_hir_analysis::check::ty_kind_suggestion; +use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer as _; use rustc_infer::infer; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::DefineOpaqueTypes; @@ -333,7 +333,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } ExprKind::Cast(e, t) => self.check_expr_cast(e, t, expr), ExprKind::Type(e, t) => { - let ascribed_ty = self.to_ty_saving_user_provided_ty(t); + let ascribed_ty = self.lower_ty_saving_user_provided_ty(t); let ty = self.check_expr_with_hint(e, ascribed_ty); self.demand_eqtype(e.span, ascribed_ty, ty); ascribed_ty @@ -1261,7 +1261,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - pub(super) fn check_expr_let(&self, let_expr: &'tcx hir::Let<'tcx>, hir_id: HirId) -> Ty<'tcx> { + pub(super) fn check_expr_let( + &self, + let_expr: &'tcx hir::LetExpr<'tcx>, + hir_id: HirId, + ) -> Ty<'tcx> { // for let statements, this is done in check_stmt let init = let_expr.init; self.warn_if_unreachable(init.hir_id, init.span, "block in `let` expression"); @@ -1371,7 +1375,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> Ty<'tcx> { // Find the type of `e`. Supply hints based on the type we are casting to, // if appropriate. - let t_cast = self.to_ty_saving_user_provided_ty(t); + let t_cast = self.lower_ty_saving_user_provided_ty(t); let t_cast = self.resolve_vars_if_possible(t_cast); let t_expr = self.check_expr_with_expectation(e, ExpectCastableToType(t_cast)); let t_expr = self.resolve_vars_if_possible(t_expr); @@ -1499,7 +1503,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expr: &'tcx hir::Expr<'tcx>, ) -> Ty<'tcx> { let tcx = self.tcx; - let count = self.array_length_to_const(count); + let count = self.lower_array_length(count); if let Some(count) = count.try_eval_target_usize(tcx, self.param_env) { self.suggest_array_len(expr, count); } @@ -1675,7 +1679,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expr: &hir::Expr<'_>, span: Span, variant: &'tcx ty::VariantDef, - ast_fields: &'tcx [hir::ExprField<'tcx>], + hir_fields: &'tcx [hir::ExprField<'tcx>], base_expr: &'tcx Option<&'tcx hir::Expr<'tcx>>, ) { let tcx = self.tcx; @@ -1706,7 +1710,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut error_happened = false; // Type-check each field. - for (idx, field) in ast_fields.iter().enumerate() { + for (idx, field) in hir_fields.iter().enumerate() { let ident = tcx.adjust_ident(field.ident, variant.def_id); let field_type = if let Some((i, v_field)) = remaining_fields.remove(&ident) { seen_fields.insert(ident, field.span); @@ -1735,7 +1739,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { variant, expr, field, - ast_fields, + hir_fields, adt.variant_descr(), ) }; @@ -1750,7 +1754,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.demand_coerce_diag(field.expr, ty, field_type, None, AllowTwoPhase::No); if let Some(diag) = diag { - if idx == ast_fields.len() - 1 { + if idx == hir_fields.len() - 1 { if remaining_fields.is_empty() { self.suggest_fru_from_range_and_emit(field, variant, args, diag); } else { @@ -1764,7 +1768,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Make sure the programmer specified correct number of fields. if adt_kind == AdtKind::Union { - if ast_fields.len() != 1 { + if hir_fields.len() != 1 { struct_span_code_err!( tcx.dcx(), span, @@ -1901,14 +1905,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .collect(); if !private_fields.is_empty() { - self.report_private_fields(adt_ty, span, expr.span, private_fields, ast_fields); + self.report_private_fields(adt_ty, span, expr.span, private_fields, hir_fields); } else { self.report_missing_fields( adt_ty, span, remaining_fields, variant, - ast_fields, + hir_fields, args, ); } @@ -1945,7 +1949,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: Span, remaining_fields: UnordMap<Ident, (FieldIdx, &ty::FieldDef)>, variant: &'tcx ty::VariantDef, - ast_fields: &'tcx [hir::ExprField<'tcx>], + hir_fields: &'tcx [hir::ExprField<'tcx>], args: GenericArgsRef<'tcx>, ) { let len = remaining_fields.len(); @@ -1982,8 +1986,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); err.span_label(span, format!("missing {remaining_fields_names}{truncated_fields_error}")); - if let Some(last) = ast_fields.last() { - self.suggest_fru_from_range_and_emit(last, variant, args, err); + if let Some(hir_field) = hir_fields.last() { + self.suggest_fru_from_range_and_emit(hir_field, variant, args, err); } else { err.emit(); } @@ -3279,7 +3283,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fields: &[Ident], expr: &'tcx hir::Expr<'tcx>, ) -> Ty<'tcx> { - let container = self.to_ty(container).normalized; + let container = self.lower_ty(container).normalized; if let Some(ident_2) = fields.get(1) && !self.tcx.features().offset_of_nested diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index 43e95544594..f3d523efd68 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -245,7 +245,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { } } - hir::ExprKind::Let(hir::Let { pat, init, .. }) => { + hir::ExprKind::Let(hir::LetExpr { pat, init, .. }) => { self.walk_local(init, pat, None, |t| t.borrow_expr(init, ty::ImmBorrow)) } @@ -463,6 +463,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { } PatKind::Or(_) | PatKind::Box(_) + | PatKind::Deref(_) | PatKind::Ref(..) | PatKind::Wild | PatKind::Err(_) => { diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs index aa8bbad1d12..140618e97cc 100644 --- a/compiler/rustc_hir_typeck/src/fallback.rs +++ b/compiler/rustc_hir_typeck/src/fallback.rs @@ -7,6 +7,19 @@ use rustc_data_structures::{ use rustc_infer::infer::{DefineOpaqueTypes, InferOk}; use rustc_middle::ty::{self, Ty}; +#[derive(Copy, Clone)] +pub enum DivergingFallbackBehavior { + /// Always fallback to `()` (aka "always spontaneous decay") + FallbackToUnit, + /// Sometimes fallback to `!`, but mainly fallback to `()` so that most of the crates are not broken. + FallbackToNiko, + /// Always fallback to `!` (which should be equivalent to never falling back + not making + /// never-to-any coercions unless necessary) + FallbackToNever, + /// Don't fallback at all + NoFallback, +} + impl<'tcx> FnCtxt<'_, 'tcx> { /// Performs type inference fallback, setting `FnCtxt::fallback_has_occurred` /// if fallback has occurred. @@ -64,7 +77,8 @@ impl<'tcx> FnCtxt<'_, 'tcx> { return false; } - let diverging_fallback = self.calculate_diverging_fallback(&unresolved_variables); + let diverging_fallback = self + .calculate_diverging_fallback(&unresolved_variables, self.diverging_fallback_behavior); // We do fallback in two passes, to try to generate // better error messages. @@ -232,6 +246,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { fn calculate_diverging_fallback( &self, unresolved_variables: &[Ty<'tcx>], + behavior: DivergingFallbackBehavior, ) -> UnordMap<Ty<'tcx>, Ty<'tcx>> { debug!("calculate_diverging_fallback({:?})", unresolved_variables); @@ -345,39 +360,61 @@ impl<'tcx> FnCtxt<'_, 'tcx> { output: infer_var_infos.items().any(|info| info.output), }; - if found_infer_var_info.self_in_trait && found_infer_var_info.output { - // This case falls back to () to ensure that the code pattern in - // tests/ui/never_type/fallback-closure-ret.rs continues to - // compile when never_type_fallback is enabled. - // - // This rule is not readily explainable from first principles, - // but is rather intended as a patchwork fix to ensure code - // which compiles before the stabilization of never type - // fallback continues to work. - // - // Typically this pattern is encountered in a function taking a - // closure as a parameter, where the return type of that closure - // (checked by `relationship.output`) is expected to implement - // some trait (checked by `relationship.self_in_trait`). This - // can come up in non-closure cases too, so we do not limit this - // rule to specifically `FnOnce`. - // - // When the closure's body is something like `panic!()`, the - // return type would normally be inferred to `!`. However, it - // needs to fall back to `()` in order to still compile, as the - // trait is specifically implemented for `()` but not `!`. - // - // For details on the requirements for these relationships to be - // set, see the relationship finding module in - // compiler/rustc_trait_selection/src/traits/relationships.rs. - debug!("fallback to () - found trait and projection: {:?}", diverging_vid); - diverging_fallback.insert(diverging_ty, self.tcx.types.unit); - } else if can_reach_non_diverging { - debug!("fallback to () - reached non-diverging: {:?}", diverging_vid); - diverging_fallback.insert(diverging_ty, self.tcx.types.unit); - } else { - debug!("fallback to ! - all diverging: {:?}", diverging_vid); - diverging_fallback.insert(diverging_ty, Ty::new_diverging_default(self.tcx)); + use DivergingFallbackBehavior::*; + match behavior { + FallbackToUnit => { + debug!("fallback to () - legacy: {:?}", diverging_vid); + diverging_fallback.insert(diverging_ty, self.tcx.types.unit); + } + FallbackToNiko => { + if found_infer_var_info.self_in_trait && found_infer_var_info.output { + // This case falls back to () to ensure that the code pattern in + // tests/ui/never_type/fallback-closure-ret.rs continues to + // compile when never_type_fallback is enabled. + // + // This rule is not readily explainable from first principles, + // but is rather intended as a patchwork fix to ensure code + // which compiles before the stabilization of never type + // fallback continues to work. + // + // Typically this pattern is encountered in a function taking a + // closure as a parameter, where the return type of that closure + // (checked by `relationship.output`) is expected to implement + // some trait (checked by `relationship.self_in_trait`). This + // can come up in non-closure cases too, so we do not limit this + // rule to specifically `FnOnce`. + // + // When the closure's body is something like `panic!()`, the + // return type would normally be inferred to `!`. However, it + // needs to fall back to `()` in order to still compile, as the + // trait is specifically implemented for `()` but not `!`. + // + // For details on the requirements for these relationships to be + // set, see the relationship finding module in + // compiler/rustc_trait_selection/src/traits/relationships.rs. + debug!("fallback to () - found trait and projection: {:?}", diverging_vid); + diverging_fallback.insert(diverging_ty, self.tcx.types.unit); + } else if can_reach_non_diverging { + debug!("fallback to () - reached non-diverging: {:?}", diverging_vid); + diverging_fallback.insert(diverging_ty, self.tcx.types.unit); + } else { + debug!("fallback to ! - all diverging: {:?}", diverging_vid); + diverging_fallback.insert(diverging_ty, self.tcx.types.never); + } + } + FallbackToNever => { + debug!( + "fallback to ! - `rustc_never_type_mode = \"fallback_to_never\")`: {:?}", + diverging_vid + ); + diverging_fallback.insert(diverging_ty, self.tcx.types.never); + } + NoFallback => { + debug!( + "no fallback - `rustc_never_type_mode = \"no_fallback\"`: {:?}", + diverging_vid + ); + } } } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index dd44fdd8893..8e0be7c7163 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -11,12 +11,12 @@ use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::lang_items::LangItem; use rustc_hir::{ExprKind, GenericArg, Node, QPath}; -use rustc_hir_analysis::astconv::generics::{ - check_generic_arg_count_for_call, create_args_for_parent_generic_args, +use rustc_hir_analysis::hir_ty_lowering::generics::{ + check_generic_arg_count_for_call, lower_generic_args, }; -use rustc_hir_analysis::astconv::{ - AstConv, CreateInstantiationsForGenericArgsCtxt, ExplicitLateBound, GenericArgCountMismatch, - GenericArgCountResult, IsMethodCall, PathSeg, +use rustc_hir_analysis::hir_ty_lowering::{ + ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgsLowerer, + GenericPathSegment, HirTyLowerer, IsMethodCall, }; use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse}; use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282; @@ -138,7 +138,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[inline] pub fn write_ty(&self, id: hir::HirId, ty: Ty<'tcx>) { debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag()); - self.typeck_results.borrow_mut().node_types_mut().insert(id, ty); + let mut typeck = self.typeck_results.borrow_mut(); + let mut node_ty = typeck.node_types_mut(); + if let Some(ty) = node_ty.get(id) + && let Err(e) = ty.error_reported() + { + // Do not overwrite nodes that were already marked as `{type error}`. This allows us to + // silence unnecessary errors from obligations that were set earlier than a type error + // was produced, but that is overwritten by later analysis. This happens in particular + // for `Sized` obligations introduced in gather_locals. (#117846) + self.set_tainted_by_errors(e); + return; + } + + node_ty.insert(id, ty); if let Err(e) = ty.error_reported() { self.set_tainted_by_errors(e); @@ -381,20 +394,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - pub fn to_ty(&self, ast_t: &hir::Ty<'tcx>) -> LoweredTy<'tcx> { - let t = self.astconv().ast_ty_to_ty(ast_t); - self.register_wf_obligation(t.into(), ast_t.span, traits::WellFormed(None)); - LoweredTy::from_raw(self, ast_t.span, t) + pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> LoweredTy<'tcx> { + let ty = self.lowerer().lower_ty(hir_ty); + self.register_wf_obligation(ty.into(), hir_ty.span, traits::WellFormed(None)); + LoweredTy::from_raw(self, hir_ty.span, ty) } - pub fn to_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { - let ty = self.to_ty(ast_ty); - debug!("to_ty_saving_user_provided_ty: ty={:?}", ty); + #[instrument(level = "debug", skip_all)] + pub fn lower_ty_saving_user_provided_ty(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { + let ty = self.lower_ty(hir_ty); + debug!(?ty); if Self::can_contain_user_lifetime_bounds(ty.raw) { let c_ty = self.canonicalize_response(UserType::Ty(ty.raw)); - debug!("to_ty_saving_user_provided_ty: c_ty={:?}", c_ty); - self.typeck_results.borrow_mut().user_provided_types_mut().insert(ast_ty.hir_id, c_ty); + debug!(?c_ty); + self.typeck_results.borrow_mut().user_provided_types_mut().insert(hir_ty.hir_id, c_ty); } ty.normalized @@ -411,7 +425,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - pub fn array_length_to_const(&self, length: &hir::ArrayLen) -> ty::Const<'tcx> { + pub fn lower_array_length(&self, length: &hir::ArrayLen) -> ty::Const<'tcx> { match length { hir::ArrayLen::Infer(inf) => self.ct_infer(self.tcx.types.usize, None, inf.span), hir::ArrayLen::Body(anon_const) => { @@ -423,20 +437,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - pub fn const_arg_to_const( - &self, - ast_c: &hir::AnonConst, - param_def_id: DefId, - ) -> ty::Const<'tcx> { - let did = ast_c.def_id; + pub fn lower_const_arg(&self, hir_ct: &hir::AnonConst, param_def_id: DefId) -> ty::Const<'tcx> { + let did = hir_ct.def_id; self.tcx.feed_anon_const_type(did, self.tcx.type_of(param_def_id)); - let c = ty::Const::from_anon_const(self.tcx, did); + let ct = ty::Const::from_anon_const(self.tcx, did); self.register_wf_obligation( - c.into(), - self.tcx.hir().span(ast_c.hir_id), + ct.into(), + self.tcx.hir().span(hir_ct.hir_id), ObligationCauseCode::WellFormed(None), ); - c + ct } // If the type given by the user has free regions, save it for later, since @@ -814,12 +824,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { QPath::Resolved(ref opt_qself, path) => { return ( path.res, - opt_qself.as_ref().map(|qself| self.to_ty(qself)), + opt_qself.as_ref().map(|qself| self.lower_ty(qself)), path.segments, ); } QPath::TypeRelative(ref qself, ref segment) => { - // Don't use `self.to_ty`, since this will register a WF obligation. + // Don't use `self.lower_ty`, since this will register a WF obligation. // If we're trying to call a nonexistent method on a trait // (e.g. `MyTrait::missing_method`), then resolution will // give us a `QPath::TypeRelative` with a trait object as @@ -828,7 +838,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // to be object-safe. // We manually call `register_wf_obligation` in the success path // below. - let ty = self.astconv().ast_ty_to_ty_in_path(qself); + let ty = self.lowerer().lower_ty_in_path(qself); (LoweredTy::from_raw(self, span, ty), qself, segment) } QPath::LangItem(..) => { @@ -1106,9 +1116,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> (Ty<'tcx>, Res) { let tcx = self.tcx; - let path_segs = match res { + let generic_segments = match res { Res::Local(_) | Res::SelfCtor(_) => vec![], - Res::Def(kind, def_id) => self.astconv().def_ids_for_value_path_segments( + Res::Def(kind, def_id) => self.lowerer().probe_generic_path_segments( segments, self_ty.map(|ty| ty.raw), kind, @@ -1165,14 +1175,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // provided (if any) into their appropriate spaces. We'll also report // errors if type parameters are provided in an inappropriate place. - let generic_segs: FxHashSet<_> = path_segs.iter().map(|PathSeg(_, index)| index).collect(); - let generics_has_err = self.astconv().prohibit_generics( + let indices: FxHashSet<_> = + generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect(); + let generics_has_err = self.lowerer().prohibit_generic_args( segments.iter().enumerate().filter_map(|(index, seg)| { - if !generic_segs.contains(&index) || is_alias_variant_ctor { - Some(seg) - } else { - None - } + if !indices.contains(&index) || is_alias_variant_ctor { Some(seg) } else { None } }), |_| {}, ); @@ -1199,7 +1206,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut infer_args_for_err = FxHashSet::default(); let mut explicit_late_bound = ExplicitLateBound::No; - for &PathSeg(def_id, index) in &path_segs { + for &GenericPathSegment(def_id, index) in &generic_segments { let seg = &segments[index]; let generics = tcx.generics_of(def_id); @@ -1220,8 +1227,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - let has_self = - path_segs.last().is_some_and(|PathSeg(def_id, _)| tcx.generics_of(*def_id).has_self); + let has_self = generic_segments + .last() + .is_some_and(|GenericPathSegment(def_id, _)| tcx.generics_of(*def_id).has_self); let (res, self_ctor_args) = if let Res::SelfCtor(impl_def_id) = res { let ty = LoweredTy::from_raw( @@ -1281,22 +1289,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }, }; - struct CreateCtorInstantiationsContext<'a, 'tcx> { + struct CtorGenericArgsCtxt<'a, 'tcx> { fcx: &'a FnCtxt<'a, 'tcx>, span: Span, - path_segs: &'a [PathSeg], + generic_segments: &'a [GenericPathSegment], infer_args_for_err: &'a FxHashSet<usize>, segments: &'tcx [hir::PathSegment<'tcx>], } - impl<'tcx, 'a> CreateInstantiationsForGenericArgsCtxt<'a, 'tcx> - for CreateCtorInstantiationsContext<'a, 'tcx> - { + impl<'tcx, 'a> GenericArgsLowerer<'a, 'tcx> for CtorGenericArgsCtxt<'a, 'tcx> { fn args_for_def_id( &mut self, def_id: DefId, ) -> (Option<&'a hir::GenericArgs<'tcx>>, bool) { - if let Some(&PathSeg(_, index)) = - self.path_segs.iter().find(|&PathSeg(did, _)| *did == def_id) + if let Some(&GenericPathSegment(_, index)) = + self.generic_segments.iter().find(|&GenericPathSegment(did, _)| *did == def_id) { // If we've encountered an `impl Trait`-related error, we're just // going to infer the arguments for better error messages. @@ -1319,13 +1325,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> ty::GenericArg<'tcx> { match (¶m.kind, arg) { (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => { - self.fcx.astconv().ast_region_to_region(lt, Some(param)).into() + self.fcx.lowerer().lower_lifetime(lt, Some(param)).into() } (GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => { - self.fcx.to_ty(ty).raw.into() + self.fcx.lower_ty(ty).raw.into() } (GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => { - self.fcx.const_arg_to_const(&ct.value, param.def_id).into() + self.fcx.lower_const_arg(&ct.value, param.def_id).into() } (GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => { self.fcx.ty_infer(Some(param), inf.span).into() @@ -1407,17 +1413,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } let args_raw = self_ctor_args.unwrap_or_else(|| { - create_args_for_parent_generic_args( + lower_generic_args( tcx, def_id, &[], has_self, self_ty.map(|s| s.raw), &arg_count, - &mut CreateCtorInstantiationsContext { + &mut CtorGenericArgsCtxt { fcx: self, span, - path_segs: &path_segs, + generic_segments: &generic_segments, infer_args_for_err: &infer_args_for_err, segments, }, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 536d44a0ccb..5695594eb1b 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -24,9 +24,9 @@ use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::Visitor; use rustc_hir::{ExprKind, Node, QPath}; -use rustc_hir_analysis::astconv::AstConv; use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt; use rustc_hir_analysis::check::potentially_plural_count; +use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; use rustc_hir_analysis::structured_errors::StructuredDiag; use rustc_index::IndexVec; use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt}; @@ -45,6 +45,29 @@ use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext} use std::iter; use std::mem; +#[derive(Clone, Copy, Default)] +pub enum DivergingBlockBehavior { + /// This is the current stable behavior: + /// + /// ```rust + /// { + /// return; + /// } // block has type = !, even though we are supposedly dropping it with `;` + /// ``` + #[default] + Never, + + /// Alternative behavior: + /// + /// ```ignore (very-unstable-new-attribute) + /// #![rustc_never_type_options(diverging_block_default = "unit")] + /// { + /// return; + /// } // block has type = (), since we are dropping `!` from `return` with `;` + /// ``` + Unit, +} + impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn check_casts(&mut self) { // don't hold the borrow to deferred_cast_checks while checking to avoid borrow checker errors @@ -1710,7 +1733,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // // #41425 -- label the implicit `()` as being the // "found type" here, rather than the "expected type". - if !self.diverges.get().is_always() { + if !self.diverges.get().is_always() + || matches!(self.diverging_block_behavior, DivergingBlockBehavior::Unit) + { // #50009 -- Do not point at the entire fn block span, point at the return type // span, as it is the cause of the requirement, and // `consider_hint_about_removing_semicolon` will point at the last expression @@ -1892,11 +1917,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pat: &'tcx hir::Pat<'tcx>, ty: Ty<'tcx>, ) { + struct V<'tcx> { + tcx: TyCtxt<'tcx>, + pat_hir_ids: Vec<hir::HirId>, + } + + impl<'tcx> Visitor<'tcx> for V<'tcx> { + type NestedFilter = rustc_middle::hir::nested_filter::All; + + fn nested_visit_map(&mut self) -> Self::Map { + self.tcx.hir() + } + + fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) { + self.pat_hir_ids.push(p.hir_id); + hir::intravisit::walk_pat(self, p); + } + } if let Err(guar) = ty.error_reported() { // Override the types everywhere with `err()` to avoid knock on errors. let err = Ty::new_error(self.tcx, guar); self.write_ty(hir_id, err); self.write_ty(pat.hir_id, err); + let mut visitor = V { tcx: self.tcx, pat_hir_ids: vec![] }; + hir::intravisit::walk_pat(&mut visitor, pat); + // Mark all the subpatterns as `{type error}` as well. This allows errors for specific + // subpatterns to be silenced. + for hir_id in visitor.pat_hir_ids { + self.write_ty(hir_id, err); + } self.locals.borrow_mut().insert(hir_id, err); self.locals.borrow_mut().insert(pat.hir_id, err); } @@ -1912,16 +1961,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> (Res, LoweredTy<'tcx>) { match *qpath { QPath::Resolved(ref maybe_qself, path) => { - let self_ty = maybe_qself.as_ref().map(|qself| self.to_ty(qself).raw); - let ty = self.astconv().res_to_ty(self_ty, path, hir_id, true); + let self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself).raw); + let ty = self.lowerer().lower_path(self_ty, path, hir_id, true); (path.res, LoweredTy::from_raw(self, path_span, ty)) } QPath::TypeRelative(qself, segment) => { - let ty = self.to_ty(qself); + let ty = self.lower_ty(qself); let result = self - .astconv() - .associated_path_to_ty(hir_id, path_span, ty.raw, qself, segment, true); + .lowerer() + .lower_assoc_path(hir_id, path_span, ty.raw, qself, segment, true); let ty = result .map(|(ty, _, _)| ty) .unwrap_or_else(|guar| Ty::new_error(self.tcx(), guar)); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index 685b1af931e..efa2862177e 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -5,11 +5,14 @@ mod checks; mod suggestions; use crate::coercion::DynamicCoerceMany; +use crate::fallback::DivergingFallbackBehavior; +use crate::fn_ctxt::checks::DivergingBlockBehavior; use crate::{CoroutineTypes, Diverges, EnclosingBreakables, Inherited}; +use hir::def_id::CRATE_DEF_ID; use rustc_errors::{DiagCtxt, ErrorGuaranteed}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_hir_analysis::astconv::AstConv; +use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; use rustc_infer::infer; use rustc_infer::infer::error_reporting::sub_relations::SubRelations; use rustc_infer::infer::error_reporting::TypeErrCtxt; @@ -18,7 +21,7 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt}; use rustc_session::Session; use rustc_span::symbol::Ident; -use rustc_span::{self, Span, DUMMY_SP}; +use rustc_span::{self, sym, Span, DUMMY_SP}; use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode, ObligationCtxt}; use std::cell::{Cell, RefCell}; @@ -108,6 +111,9 @@ pub struct FnCtxt<'a, 'tcx> { pub(super) inh: &'a Inherited<'tcx>, pub(super) fallback_has_occurred: Cell<bool>, + + pub(super) diverging_fallback_behavior: DivergingFallbackBehavior, + pub(super) diverging_block_behavior: DivergingBlockBehavior, } impl<'a, 'tcx> FnCtxt<'a, 'tcx> { @@ -116,6 +122,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { param_env: ty::ParamEnv<'tcx>, body_id: LocalDefId, ) -> FnCtxt<'a, 'tcx> { + let (diverging_fallback_behavior, diverging_block_behavior) = + parse_never_type_options_attr(inh.tcx); FnCtxt { body_id, param_env, @@ -131,6 +139,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }), inh, fallback_has_occurred: Cell::new(false), + diverging_fallback_behavior, + diverging_block_behavior, } } @@ -202,7 +212,7 @@ impl<'a, 'tcx> Deref for FnCtxt<'a, 'tcx> { } } -impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { +impl<'a, 'tcx> HirTyLowerer<'tcx> for FnCtxt<'a, 'tcx> { fn tcx<'b>(&'b self) -> TyCtxt<'tcx> { self.tcx } @@ -211,31 +221,8 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { self.body_id.to_def_id() } - fn get_type_parameter_bounds( - &self, - _: Span, - def_id: LocalDefId, - _: Ident, - ) -> ty::GenericPredicates<'tcx> { - let tcx = self.tcx; - let item_def_id = tcx.hir().ty_param_owner(def_id); - let generics = tcx.generics_of(item_def_id); - let index = generics.param_def_id_to_index[&def_id.to_def_id()]; - // HACK(eddyb) should get the original `Span`. - let span = tcx.def_span(def_id); - ty::GenericPredicates { - parent: None, - predicates: tcx.arena.alloc_from_iter( - self.param_env.caller_bounds().iter().filter_map(|predicate| { - match predicate.kind().skip_binder() { - ty::ClauseKind::Trait(data) if data.self_ty().is_param(index) => { - Some((predicate, span)) - } - _ => None, - } - }), - ), - } + fn allow_infer(&self) -> bool { + true } fn re_infer(&self, def: Option<&ty::GenericParamDef>, span: Span) -> Option<ty::Region<'tcx>> { @@ -246,10 +233,6 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { Some(self.next_region_var(v)) } - fn allow_ty_infer(&self) -> bool { - true - } - fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> { match param { Some(param) => self.var_for_def(span, param).as_type().unwrap(), @@ -282,7 +265,34 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { } } - fn projected_ty_from_poly_trait_ref( + fn probe_ty_param_bounds( + &self, + _: Span, + def_id: LocalDefId, + _: Ident, + ) -> ty::GenericPredicates<'tcx> { + let tcx = self.tcx; + let item_def_id = tcx.hir().ty_param_owner(def_id); + let generics = tcx.generics_of(item_def_id); + let index = generics.param_def_id_to_index[&def_id.to_def_id()]; + // HACK(eddyb) should get the original `Span`. + let span = tcx.def_span(def_id); + ty::GenericPredicates { + parent: None, + predicates: tcx.arena.alloc_from_iter( + self.param_env.caller_bounds().iter().filter_map(|predicate| { + match predicate.kind().skip_binder() { + ty::ClauseKind::Trait(data) if data.self_ty().is_param(index) => { + Some((predicate, span)) + } + _ => None, + } + }), + ), + } + } + + fn lower_assoc_ty( &self, span: Span, item_def_id: DefId, @@ -295,7 +305,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { poly_trait_ref, ); - let item_args = self.astconv().create_args_for_associated_item( + let item_args = self.lowerer().lower_generic_args_of_assoc_item( span, item_def_id, item_segment, @@ -318,10 +328,6 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { } } - fn set_tainted_by_errors(&self, e: ErrorGuaranteed) { - self.infcx.set_tainted_by_errors(e) - } - fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span) { // FIXME: normalization and escaping regions let ty = if !ty.has_escaping_bound_vars() { @@ -345,13 +351,17 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { fn infcx(&self) -> Option<&infer::InferCtxt<'tcx>> { Some(&self.infcx) } + + fn set_tainted_by_errors(&self, e: ErrorGuaranteed) { + self.infcx.set_tainted_by_errors(e) + } } /// The `ty` representation of a user-provided type. Depending on the use-site /// we want to either use the unnormalized or the normalized form of this type. /// -/// This is a bridge between the interface of `AstConv`, which outputs a raw `Ty`, -/// and the API in this module, which expect `Ty` to be fully normalized. +/// This is a bridge between the interface of HIR ty lowering, which outputs a raw +/// `Ty`, and the API in this module, which expect `Ty` to be fully normalized. #[derive(Clone, Copy, Debug)] pub struct LoweredTy<'tcx> { /// The unnormalized type provided by the user. @@ -374,3 +384,64 @@ impl<'tcx> LoweredTy<'tcx> { LoweredTy { raw, normalized } } } + +fn parse_never_type_options_attr( + tcx: TyCtxt<'_>, +) -> (DivergingFallbackBehavior, DivergingBlockBehavior) { + use DivergingFallbackBehavior::*; + + // Error handling is dubious here (unwraps), but that's probably fine for an internal attribute. + // Just don't write incorrect attributes <3 + + let mut fallback = None; + let mut block = None; + + let items = tcx + .get_attr(CRATE_DEF_ID, sym::rustc_never_type_options) + .map(|attr| attr.meta_item_list().unwrap()) + .unwrap_or_default(); + + for item in items { + if item.has_name(sym::fallback) && fallback.is_none() { + let mode = item.value_str().unwrap(); + match mode { + sym::unit => fallback = Some(FallbackToUnit), + sym::niko => fallback = Some(FallbackToNiko), + sym::never => fallback = Some(FallbackToNever), + sym::no => fallback = Some(NoFallback), + _ => { + tcx.dcx().span_err(item.span(), format!("unknown never type fallback mode: `{mode}` (supported: `unit`, `niko`, `never` and `no`)")); + } + }; + continue; + } + + if item.has_name(sym::diverging_block_default) && fallback.is_none() { + let mode = item.value_str().unwrap(); + match mode { + sym::unit => block = Some(DivergingBlockBehavior::Unit), + sym::never => block = Some(DivergingBlockBehavior::Never), + _ => { + tcx.dcx().span_err(item.span(), format!("unknown diverging block default: `{mode}` (supported: `unit` and `never`)")); + } + }; + continue; + } + + tcx.dcx().span_err( + item.span(), + format!( + "unknown never type option: `{}` (supported: `fallback`)", + item.name_or_empty() + ), + ); + } + + let fallback = fallback.unwrap_or_else(|| { + if tcx.features().never_type_fallback { FallbackToNiko } else { FallbackToUnit } + }); + + let block = block.unwrap_or_default(); + + (fallback, block) +} diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 3f6f4cccba7..21f52f72080 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -21,7 +21,7 @@ use rustc_hir::{ CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, GenericBound, HirId, Node, Path, QPath, Stmt, StmtKind, TyKind, WherePredicate, }; -use rustc_hir_analysis::astconv::AstConv; +use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; use rustc_infer::traits::{self}; use rustc_middle::lint::in_external_macro; use rustc_middle::middle::stability::EvalResult; @@ -809,7 +809,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return true; } &hir::FnRetTy::DefaultReturn(span) if expected.is_unit() => { - if let Some(found) = found.make_suggestable(self.tcx, false) { + if let Some(found) = found.make_suggestable(self.tcx, false, None) { err.subdiagnostic( self.dcx(), errors::AddReturnTypeSuggestion::Add { span, found: found.to_string() }, @@ -877,7 +877,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Only point to return type if the expected type is the return type, as if they // are not, the expectation must have been caused by something else. debug!("return type {:?}", hir_ty); - let ty = self.astconv().ast_ty_to_ty(hir_ty); + let ty = self.lowerer().lower_ty(hir_ty); debug!("return type {:?}", ty); debug!("expected type {:?}", expected); let bound_vars = self.tcx.late_bound_vars(hir_ty.hir_id.owner.into()); @@ -957,8 +957,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { bounded_ty, .. }) => { - // FIXME: Maybe these calls to `ast_ty_to_ty` can be removed (and the ones below) - let ty = self.astconv().ast_ty_to_ty(bounded_ty); + // FIXME: Maybe these calls to `lower_ty` can be removed (and the ones below) + let ty = self.lowerer().lower_ty(bounded_ty); Some((ty, bounds)) } _ => None, @@ -996,7 +996,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let all_bounds_str = all_matching_bounds_strs.join(" + "); let ty_param_used_in_fn_params = fn_parameters.iter().any(|param| { - let ty = self.astconv().ast_ty_to_ty( param); + let ty = self.lowerer().lower_ty( param); matches!(ty.kind(), ty::Param(fn_param_ty_param) if expected_ty_as_param == fn_param_ty_param) }); @@ -1071,7 +1071,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let can_return = match fn_decl.output { hir::FnRetTy::Return(ty) => { - let ty = self.astconv().ast_ty_to_ty(ty); + let ty = self.lowerer().lower_ty(ty); let bound_vars = self.tcx.late_bound_vars(fn_id); let ty = self .tcx diff --git a/compiler/rustc_hir_typeck/src/gather_locals.rs b/compiler/rustc_hir_typeck/src/gather_locals.rs index 4d37f725c94..8fddccab5bf 100644 --- a/compiler/rustc_hir_typeck/src/gather_locals.rs +++ b/compiler/rustc_hir_typeck/src/gather_locals.rs @@ -29,7 +29,7 @@ impl<'a> DeclOrigin<'a> { } } -/// A declaration is an abstraction of [hir::Local] and [hir::Let]. +/// A declaration is an abstraction of [hir::Local] and [hir::LetExpr]. /// /// It must have a hir_id, as this is how we connect gather_locals to the check functions. pub(super) struct Declaration<'a> { @@ -48,9 +48,9 @@ impl<'a> From<&'a hir::Local<'a>> for Declaration<'a> { } } -impl<'a> From<(&'a hir::Let<'a>, hir::HirId)> for Declaration<'a> { - fn from((let_expr, hir_id): (&'a hir::Let<'a>, hir::HirId)) -> Self { - let hir::Let { pat, ty, span, init, is_recovered: _ } = *let_expr; +impl<'a> From<(&'a hir::LetExpr<'a>, hir::HirId)> for Declaration<'a> { + fn from((let_expr, hir_id): (&'a hir::LetExpr<'a>, hir::HirId)) -> Self { + let hir::LetExpr { pat, ty, span, init, is_recovered: _ } = *let_expr; Declaration { hir_id, pat, ty, span, init: Some(init), origin: DeclOrigin::LetExpr } } } @@ -93,7 +93,7 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> { fn declare(&mut self, decl: Declaration<'tcx>) { let local_ty = match decl.ty { Some(ref ty) => { - let o_ty = self.fcx.to_ty(ty); + let o_ty = self.fcx.lower_ty(ty); let c_ty = self.fcx.inh.infcx.canonicalize_user_type_annotation(UserType::Ty(o_ty.raw)); diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index d86b4912c89..0b67b37df29 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -5,7 +5,6 @@ #![feature(try_blocks)] #![feature(never_type)] #![feature(box_patterns)] -#![cfg_attr(bootstrap, feature(min_specialization))] #![feature(control_flow_enum)] #[macro_use] @@ -58,8 +57,8 @@ use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::Visitor; use rustc_hir::{HirIdMap, Node}; -use rustc_hir_analysis::astconv::AstConv; use rustc_hir_analysis::check::check_abi; +use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, WellFormedLoc}; use rustc_middle::query::Providers; @@ -95,29 +94,7 @@ macro_rules! type_error_struct { fn primary_body_of( node: Node<'_>, ) -> Option<(hir::BodyId, Option<&hir::Ty<'_>>, Option<&hir::FnSig<'_>>)> { - match node { - Node::Item(item) => match item.kind { - hir::ItemKind::Const(ty, _, body) | hir::ItemKind::Static(ty, _, body) => { - Some((body, Some(ty), None)) - } - hir::ItemKind::Fn(ref sig, .., body) => Some((body, None, Some(sig))), - _ => None, - }, - Node::TraitItem(item) => match item.kind { - hir::TraitItemKind::Const(ty, Some(body)) => Some((body, Some(ty), None)), - hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => { - Some((body, None, Some(sig))) - } - _ => None, - }, - Node::ImplItem(item) => match item.kind { - hir::ImplItemKind::Const(ty, body) => Some((body, Some(ty), None)), - hir::ImplItemKind::Fn(ref sig, body) => Some((body, None, Some(sig))), - _ => None, - }, - Node::AnonConst(constant) => Some((constant.body, None, None)), - _ => None, - } + Some((node.body_id()?, node.ty(), node.fn_sig())) } fn has_typeck_results(tcx: TyCtxt<'_>, def_id: DefId) -> bool { @@ -201,7 +178,7 @@ fn typeck_with_fallback<'tcx>( if let Some(hir::FnSig { header, decl, .. }) = fn_sig { let fn_sig = if decl.output.get_infer_ret_ty().is_some() { - fcx.astconv().ty_of_fn(id, header.unsafety, header.abi, decl, None, None) + fcx.lowerer().lower_fn_ty(id, header.unsafety, header.abi, decl, None, None) } else { tcx.fn_sig(def_id).instantiate_identity() }; diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index 9307cccf092..d949772f1a3 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -719,7 +719,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { self.cat_pattern_(place_with_id, subpat, op)?; } - PatKind::Box(subpat) | PatKind::Ref(subpat, _) => { + PatKind::Box(subpat) | PatKind::Ref(subpat, _) | PatKind::Deref(subpat) => { // box p1, &p1, &mut p1. we can ignore the mutability of // PatKind::Ref since that information is already contained // in the type. diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index a580c114f26..d5413a120c7 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -4,10 +4,10 @@ use crate::{callee, FnCtxt}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::GenericArg; -use rustc_hir_analysis::astconv::generics::{ - check_generic_arg_count_for_call, create_args_for_parent_generic_args, +use rustc_hir_analysis::hir_ty_lowering::generics::{ + check_generic_arg_count_for_call, lower_generic_args, }; -use rustc_hir_analysis::astconv::{AstConv, CreateInstantiationsForGenericArgsCtxt, IsMethodCall}; +use rustc_hir_analysis::hir_ty_lowering::{GenericArgsLowerer, HirTyLowerer, IsMethodCall}; use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk}; use rustc_middle::traits::{ObligationCauseCode, UnifyReceiverContext}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion}; @@ -366,14 +366,12 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // combining parameters from the type and those from the method. assert_eq!(generics.parent_count, parent_args.len()); - struct MethodInstantiationsCtxt<'a, 'tcx> { + struct GenericArgsCtxt<'a, 'tcx> { cfcx: &'a ConfirmContext<'a, 'tcx>, pick: &'a probe::Pick<'tcx>, seg: &'a hir::PathSegment<'tcx>, } - impl<'a, 'tcx> CreateInstantiationsForGenericArgsCtxt<'a, 'tcx> - for MethodInstantiationsCtxt<'a, 'tcx> - { + impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> { fn args_for_def_id( &mut self, def_id: DefId, @@ -393,13 +391,13 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { ) -> ty::GenericArg<'tcx> { match (¶m.kind, arg) { (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => { - self.cfcx.fcx.astconv().ast_region_to_region(lt, Some(param)).into() + self.cfcx.fcx.lowerer().lower_lifetime(lt, Some(param)).into() } (GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => { - self.cfcx.to_ty(ty).raw.into() + self.cfcx.lower_ty(ty).raw.into() } (GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => { - self.cfcx.const_arg_to_const(&ct.value, param.def_id).into() + self.cfcx.lower_const_arg(&ct.value, param.def_id).into() } (GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => { self.cfcx.ty_infer(Some(param), inf.span).into() @@ -432,14 +430,14 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { } } - let args = create_args_for_parent_generic_args( + let args = lower_generic_args( self.tcx, pick.item.def_id, parent_args, false, None, &arg_count_correct, - &mut MethodInstantiationsCtxt { cfcx: self, pick, seg }, + &mut GenericArgsCtxt { cfcx: self, pick, seg }, ); // When the method is confirmed, the `args` includes diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index bdc796aca3a..eada5a0bc30 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -386,10 +386,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let infcx = &self.infcx; let (ParamEnvAnd { param_env: _, value: self_ty }, canonical_inference_vars) = - infcx.instantiate_canonical_with_fresh_inference_vars( - span, - ¶m_env_and_self_ty, - ); + infcx.instantiate_canonical(span, ¶m_env_and_self_ty); debug!( "probe_op: Mode::Path, param_env_and_self_ty={:?} self_ty={:?}", param_env_and_self_ty, self_ty @@ -661,13 +658,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // of the iterations in the autoderef loop, so there is no problem with it // being discoverable in another one of these iterations. // - // Using `instantiate_canonical_with_fresh_inference_vars` on our + // Using `instantiate_canonical` on our // `Canonical<QueryResponse<Ty<'tcx>>>` and then *throwing away* the // `CanonicalVarValues` will exactly give us such a generalization - it // will still match the original object type, but it won't pollute our // type variables in any form, so just do that! let (QueryResponse { value: generalized_self_ty, .. }, _ignored_var_values) = - self.fcx.instantiate_canonical_with_fresh_inference_vars(self.span, self_ty); + self.fcx.instantiate_canonical(self.span, self_ty); self.assemble_inherent_candidates_from_object(generalized_self_ty); self.assemble_inherent_impl_candidates_for_type(p.def_id()); @@ -1420,15 +1417,13 @@ impl<'tcx> Pick<'tcx> { } _ => {} } - if tcx.sess.is_nightly_build() { - for (candidate, feature) in &self.unstable_candidates { - lint.help(format!( - "add `#![feature({})]` to the crate attributes to enable `{}`", - feature, - tcx.def_path_str(candidate.item.def_id), - )); - } - } + tcx.disabled_nightly_features( + lint, + Some(scope_expr_id), + self.unstable_candidates.iter().map(|(candidate, feature)| { + (format!(" `{}`", tcx.def_path_str(candidate.item.def_id)), *feature) + }), + ); }, ); } @@ -1935,7 +1930,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { } } - /// Determine if the associated item withe the given DefId matches + /// Determine if the associated item with the given DefId matches /// the desired name via a doc alias. fn matches_by_doc_alias(&self, def_id: DefId) -> bool { let Some(name) = self.method_name else { diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index c5bbcc56f86..f3615c03215 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -3264,8 +3264,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Colon, Nothing, } - let ast_generics = hir.get_generics(id.owner.def_id).unwrap(); - let trait_def_ids: DefIdSet = ast_generics + let hir_generics = hir.get_generics(id.owner.def_id).unwrap(); + let trait_def_ids: DefIdSet = hir_generics .bounds_for_param(def_id) .flat_map(|bp| bp.bounds.iter()) .filter_map(|bound| bound.trait_ref()?.trait_def_id()) @@ -3277,7 +3277,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { "restrict type parameter `{}` with", param.name.ident(), )); - let bounds_span = ast_generics.bounds_span_for_suggestions(def_id); + let bounds_span = hir_generics.bounds_span_for_suggestions(def_id); if rcvr_ty.is_ref() && param.is_impl_trait() && bounds_span.is_some() { err.multipart_suggestions( msg, diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index 79f574aa7fd..8969030d683 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -601,8 +601,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some(output_def_id) = output_def_id && let Some(trait_def_id) = trait_def_id && self.tcx.parent(output_def_id) == trait_def_id - && let Some(output_ty) = - output_ty.make_suggestable(self.tcx, false) + && let Some(output_ty) = output_ty + .make_suggestable(self.tcx, false, None) { Some(("Output", output_ty)) } else { diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index bb963ad7a39..dad43cb8abe 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -18,8 +18,7 @@ use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::hygiene::DesugaringKind; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident}; -use rustc_span::Span; -use rustc_span::{BytePos, DUMMY_SP}; +use rustc_span::{BytePos, Span, DUMMY_SP}; use rustc_target::abi::FieldIdx; use rustc_trait_selection::traits::{ObligationCause, Pattern}; use ty::VariantDef; @@ -83,6 +82,9 @@ struct PatInfo<'tcx, 'a> { binding_mode: BindingMode, top_info: TopInfo<'tcx>, decl_origin: Option<DeclOrigin<'a>>, + + /// The depth of current pattern + current_depth: u32, } impl<'tcx> FnCtxt<'_, 'tcx> { @@ -152,7 +154,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { decl_origin: Option<DeclOrigin<'tcx>>, ) { let info = TopInfo { expected, origin_expr, span }; - let pat_info = PatInfo { binding_mode: INITIAL_BM, top_info: info, decl_origin }; + let pat_info = + PatInfo { binding_mode: INITIAL_BM, top_info: info, decl_origin, current_depth: 0 }; self.check_pat(pat, expected, pat_info); } @@ -163,7 +166,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Conversely, inside this module, `check_pat_top` should never be used. #[instrument(level = "debug", skip(self, pat_info))] fn check_pat(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, pat_info: PatInfo<'tcx, '_>) { - let PatInfo { binding_mode: def_bm, top_info: ti, .. } = pat_info; + let PatInfo { binding_mode: def_bm, top_info: ti, current_depth, .. } = pat_info; + let path_res = match &pat.kind { PatKind::Path(qpath) => Some( self.resolve_ty_and_res_fully_qualified_call(qpath, pat.hir_id, pat.span, None), @@ -172,8 +176,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let adjust_mode = self.calc_adjust_mode(pat, path_res.map(|(res, ..)| res)); let (expected, def_bm) = self.calc_default_binding_mode(pat, expected, def_bm, adjust_mode); - let pat_info = - PatInfo { binding_mode: def_bm, top_info: ti, decl_origin: pat_info.decl_origin }; + let pat_info = PatInfo { + binding_mode: def_bm, + top_info: ti, + decl_origin: pat_info.decl_origin, + current_depth: current_depth + 1, + }; let ty = match pat.kind { PatKind::Wild | PatKind::Err(_) => expected, @@ -203,6 +211,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.check_pat_tuple(pat.span, elements, ddpos, expected, pat_info) } PatKind::Box(inner) => self.check_pat_box(pat.span, inner, expected, pat_info), + PatKind::Deref(inner) => self.check_pat_deref(pat.span, inner, expected, pat_info), PatKind::Ref(inner, mutbl) => self.check_pat_ref(pat, inner, mutbl, expected, pat_info), PatKind::Slice(before, slice, after) => { self.check_pat_slice(pat.span, before, slice, after, expected, pat_info) @@ -286,6 +295,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | PatKind::TupleStruct(..) | PatKind::Tuple(..) | PatKind::Box(_) + | PatKind::Deref(_) | PatKind::Range(..) | PatKind::Slice(..) => AdjustMode::Peel, // A never pattern behaves somewhat like a literal or unit variant. @@ -751,6 +761,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | PatKind::Binding(..) | PatKind::Path(..) | PatKind::Box(..) + | PatKind::Deref(_) | PatKind::Ref(..) | PatKind::Lit(..) | PatKind::Range(..) @@ -1046,14 +1057,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, pat_info: PatInfo<'tcx, '_>, ) -> Ty<'tcx> { - let PatInfo { binding_mode: def_bm, top_info: ti, decl_origin } = pat_info; + let PatInfo { binding_mode: def_bm, top_info: ti, decl_origin, current_depth } = pat_info; let tcx = self.tcx; let on_error = |e| { for pat in subpats { self.check_pat( pat, Ty::new_error(tcx, e), - PatInfo { binding_mode: def_bm, top_info: ti, decl_origin }, + PatInfo { binding_mode: def_bm, top_info: ti, decl_origin, current_depth }, ); } }; @@ -1120,7 +1131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.check_pat( subpat, field_ty, - PatInfo { binding_mode: def_bm, top_info: ti, decl_origin }, + PatInfo { binding_mode: def_bm, top_info: ti, decl_origin, current_depth }, ); self.tcx.check_stability( @@ -1966,6 +1977,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { box_ty } + fn check_pat_deref( + &self, + span: Span, + inner: &'tcx Pat<'tcx>, + expected: Ty<'tcx>, + pat_info: PatInfo<'tcx, '_>, + ) -> Ty<'tcx> { + let tcx = self.tcx; + // FIXME(deref_patterns): use `DerefPure` for soundness + // FIXME(deref_patterns): use `DerefMut` when required + // <expected as Deref>::Target + let ty = Ty::new_projection( + tcx, + tcx.require_lang_item(hir::LangItem::DerefTarget, Some(span)), + [expected], + ); + let ty = self.normalize(span, ty); + let ty = self.try_structurally_resolve_type(span, ty); + self.check_pat(inner, ty, pat_info); + expected + } + // Precondition: Pat is Ref(inner) fn check_pat_ref( &self, @@ -2134,7 +2167,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // The expected type must be an array or slice, but was neither, so error. _ => { let guar = expected.error_reported().err().unwrap_or_else(|| { - self.error_expected_array_or_slice(span, expected, pat_info.top_info) + self.error_expected_array_or_slice(span, expected, pat_info) }); let err = Ty::new_error(self.tcx, guar); (err, Some(err), err) @@ -2169,7 +2202,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { len: ty::Const<'tcx>, min_len: u64, ) -> (Option<Ty<'tcx>>, Ty<'tcx>) { - let len = match len.eval(self.tcx, self.param_env, None) { + let len = match len.eval(self.tcx, self.param_env, span) { Ok(val) => val .try_to_scalar() .and_then(|scalar| scalar.try_to_int().ok()) @@ -2273,8 +2306,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, span: Span, expected_ty: Ty<'tcx>, - ti: TopInfo<'tcx>, + pat_info: PatInfo<'tcx, '_>, ) -> ErrorGuaranteed { + let PatInfo { top_info: ti, current_depth, .. } = pat_info; + let mut err = struct_span_code_err!( self.dcx(), span, @@ -2292,9 +2327,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && let Some(_) = ti.origin_expr && let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) { - let ty = self.resolve_vars_if_possible(ti.expected); - let is_slice_or_array_or_vector = self.is_slice_or_array_or_vector(ty); - match is_slice_or_array_or_vector.1.kind() { + let resolved_ty = self.resolve_vars_if_possible(ti.expected); + let (is_slice_or_array_or_vector, resolved_ty) = + self.is_slice_or_array_or_vector(resolved_ty); + match resolved_ty.kind() { ty::Adt(adt_def, _) if self.tcx.is_diagnostic_item(sym::Option, adt_def.did()) || self.tcx.is_diagnostic_item(sym::Result, adt_def.did()) => @@ -2309,7 +2345,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } _ => (), } - if is_slice_or_array_or_vector.0 { + + let is_top_level = current_depth <= 1; + if is_slice_or_array_or_vector && is_top_level { err.span_suggestion( span, "consider slicing here", diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index be14f5bf0d8..b71e88a1579 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -410,7 +410,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.demand_eqtype( span, coroutine_args.as_coroutine().kind_ty(), - Ty::from_closure_kind(self.tcx, closure_kind), + Ty::from_coroutine_closure_kind(self.tcx, closure_kind), ); } diff --git a/compiler/rustc_incremental/src/persist/dirty_clean.rs b/compiler/rustc_incremental/src/persist/dirty_clean.rs index 24512dea939..5156a8d3479 100644 --- a/compiler/rustc_incremental/src/persist/dirty_clean.rs +++ b/compiler/rustc_incremental/src/persist/dirty_clean.rs @@ -148,7 +148,7 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) { let crate_items = tcx.hir_crate_items(()); - for id in crate_items.items() { + for id in crate_items.free_items() { dirty_clean_visitor.check_item(id.owner_id.def_id); } diff --git a/compiler/rustc_index_macros/src/lib.rs b/compiler/rustc_index_macros/src/lib.rs index 532cac5791e..015518ae4d6 100644 --- a/compiler/rustc_index_macros/src/lib.rs +++ b/compiler/rustc_index_macros/src/lib.rs @@ -34,13 +34,7 @@ mod newtype; #[proc_macro] #[cfg_attr( feature = "nightly", - allow_internal_unstable( - step_trait, - rustc_attrs, - trusted_step, - spec_option_partial_eq, - min_specialization - ) + allow_internal_unstable(step_trait, rustc_attrs, trusted_step, min_specialization) )] pub fn newtype_index(input: TokenStream) -> TokenStream { newtype::newtype(input) diff --git a/compiler/rustc_index_macros/src/newtype.rs b/compiler/rustc_index_macros/src/newtype.rs index 0b25628b9e1..e5c2ba42483 100644 --- a/compiler/rustc_index_macros/src/newtype.rs +++ b/compiler/rustc_index_macros/src/newtype.rs @@ -156,32 +156,6 @@ impl Parse for Newtype { } }; - let spec_partial_eq_impl = if let Lit::Int(max) = &max { - if let Ok(max_val) = max.base10_parse::<u32>() { - quote! { - #gate_rustc_only - impl core::option::SpecOptionPartialEq for #name { - #[inline] - fn eq(l: &Option<Self>, r: &Option<Self>) -> bool { - if #max_val < u32::MAX { - l.map(|i| i.as_u32()).unwrap_or(#max_val+1) == r.map(|i| i.as_u32()).unwrap_or(#max_val+1) - } else { - match (l, r) { - (Some(l), Some(r)) => r == l, - (None, None) => true, - _ => false - } - } - } - } - } - } else { - quote! {} - } - } else { - quote! {} - }; - Ok(Self(quote! { #(#attrs)* #[derive(Clone, Copy, PartialEq, Eq, Hash, #(#derive_paths),*)] @@ -283,8 +257,6 @@ impl Parse for Newtype { #step - #spec_partial_eq_impl - impl From<#name> for u32 { #[inline] fn from(v: #name) -> u32 { diff --git a/compiler/rustc_infer/src/infer/canonical/mod.rs b/compiler/rustc_infer/src/infer/canonical/mod.rs index 1d203a29b14..bcc476393ea 100644 --- a/compiler/rustc_infer/src/infer/canonical/mod.rs +++ b/compiler/rustc_infer/src/infer/canonical/mod.rs @@ -38,8 +38,8 @@ mod instantiate; pub mod query_response; impl<'tcx> InferCtxt<'tcx> { - /// Creates an instantiation S for the canonical value with fresh - /// inference variables and applies it to the canonical value. + /// Creates an instantiation S for the canonical value with fresh inference + /// variables and placeholders then applies it to the canonical value. /// Returns both the instantiated result *and* the instantiation S. /// /// This can be invoked as part of constructing an @@ -50,7 +50,7 @@ impl<'tcx> InferCtxt<'tcx> { /// At the end of processing, the instantiation S (once /// canonicalized) then represents the values that you computed /// for each of the canonical inputs to your query. - pub fn instantiate_canonical_with_fresh_inference_vars<T>( + pub fn instantiate_canonical<T>( &self, span: Span, canonical: &Canonical<'tcx, T>, diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 5d2a95593cd..7ce6c35f8c3 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -403,8 +403,10 @@ impl<'tcx> InferCtxt<'tcx> { let future_trait = self.tcx.require_lang_item(LangItem::Future, None); let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0]; - self.tcx.explicit_item_bounds(def_id).iter_instantiated_copied(self.tcx, args).find_map( - |(predicate, _)| { + self.tcx + .explicit_item_super_predicates(def_id) + .iter_instantiated_copied(self.tcx, args) + .find_map(|(predicate, _)| { predicate .kind() .map_bound(|kind| match kind { @@ -417,8 +419,7 @@ impl<'tcx> InferCtxt<'tcx> { }) .no_bound_vars() .flatten() - }, - ) + }) } } @@ -2553,7 +2554,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { hir::OwnerNode::ImplItem(i) => visitor.visit_impl_item(i), hir::OwnerNode::TraitItem(i) => visitor.visit_trait_item(i), hir::OwnerNode::Crate(_) => bug!("OwnerNode::Crate doesn't not have generics"), - hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(), + hir::OwnerNode::Synthetic => unreachable!(), } let ast_generics = self.tcx.hir().get_generics(lifetime_scope).unwrap(); diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 13e2152e45e..ce9001ccb1c 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -546,40 +546,55 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } } InferSourceKind::FullyQualifiedMethodCall { receiver, successor, args, def_id } => { - let mut printer = fmt_printer(self, Namespace::ValueNS); - printer.print_def_path(def_id, args).unwrap(); - let def_path = printer.into_buffer(); - - // We only care about whether we have to add `&` or `&mut ` for now. - // This is the case if the last adjustment is a borrow and the - // first adjustment was not a builtin deref. - let adjustment = match typeck_results.expr_adjustments(receiver) { - [ - Adjustment { kind: Adjust::Deref(None), target: _ }, - .., - Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), target: _ }, - ] => "", - [ - .., - Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(_, mut_)), target: _ }, - ] => hir::Mutability::from(*mut_).ref_prefix_str(), - _ => "", - }; + let placeholder = Some(self.next_ty_var(TypeVariableOrigin { + span: rustc_span::DUMMY_SP, + kind: TypeVariableOriginKind::MiscVariable, + })); + if let Some(args) = args.make_suggestable(self.infcx.tcx, true, placeholder) { + let mut printer = fmt_printer(self, Namespace::ValueNS); + printer.print_def_path(def_id, args).unwrap(); + let def_path = printer.into_buffer(); + + // We only care about whether we have to add `&` or `&mut ` for now. + // This is the case if the last adjustment is a borrow and the + // first adjustment was not a builtin deref. + let adjustment = match typeck_results.expr_adjustments(receiver) { + [ + Adjustment { kind: Adjust::Deref(None), target: _ }, + .., + Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), target: _ }, + ] => "", + [ + .., + Adjustment { + kind: Adjust::Borrow(AutoBorrow::Ref(_, mut_)), + target: _, + }, + ] => hir::Mutability::from(*mut_).ref_prefix_str(), + _ => "", + }; - multi_suggestions.push(SourceKindMultiSuggestion::new_fully_qualified( - receiver.span, - def_path, - adjustment, - successor, - )); + multi_suggestions.push(SourceKindMultiSuggestion::new_fully_qualified( + receiver.span, + def_path, + adjustment, + successor, + )); + } } InferSourceKind::ClosureReturn { ty, data, should_wrap_expr } => { - let ty_info = ty_to_string(self, ty, None); - multi_suggestions.push(SourceKindMultiSuggestion::new_closure_return( - ty_info, - data, - should_wrap_expr, - )); + let placeholder = Some(self.next_ty_var(TypeVariableOrigin { + span: rustc_span::DUMMY_SP, + kind: TypeVariableOriginKind::MiscVariable, + })); + if let Some(ty) = ty.make_suggestable(self.infcx.tcx, true, placeholder) { + let ty_info = ty_to_string(self, ty, None); + multi_suggestions.push(SourceKindMultiSuggestion::new_closure_return( + ty_info, + data, + should_wrap_expr, + )); + } } } match error_code { @@ -990,7 +1005,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { let generics_def_id = tcx.res_generics_def_id(path.res)?; let generics = tcx.generics_of(generics_def_id); if generics.has_impl_trait() { - None?; + do yeet (); } let insert_span = path.segments.last().unwrap().ident.span.shrink_to_hi().with_hi(path.span.hi()); @@ -1044,7 +1059,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { let generics = tcx.generics_of(def_id); let segment: Option<_> = try { if !segment.infer_args || generics.has_impl_trait() { - None?; + do yeet (); } let span = tcx.hir().span(segment.hir_id); let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi()); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index 503645191aa..fe70b631cdb 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -13,8 +13,8 @@ use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan, Subdiagnosti use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_ty, Visitor}; use rustc_hir::{ - self as hir, GenericBound, GenericParamKind, Item, ItemKind, Lifetime, LifetimeName, Node, - TyKind, + self as hir, GenericBound, GenericParam, GenericParamKind, Item, ItemKind, Lifetime, + LifetimeName, LifetimeParamKind, MissingLifetimeKind, Node, TyKind, }; use rustc_middle::ty::{ self, AssocItemContainer, StaticLifetimeVisitor, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, @@ -355,20 +355,8 @@ pub fn suggest_new_region_bound( // introducing a new lifetime `'a` or making use of one from existing named lifetimes if any if let Some(id) = scope_def_id && let Some(generics) = tcx.hir().get_generics(id) - && let mut spans_suggs = generics - .params - .iter() - .filter(|p| p.is_elided_lifetime()) - .map(|p| { - if p.span.hi() - p.span.lo() == rustc_span::BytePos(1) { - // Ampersand (elided without '_) - (p.span.shrink_to_hi(), format!("{name} ")) - } else { - // Underscore (elided with '_) - (p.span, name.to_string()) - } - }) - .collect::<Vec<_>>() + && let mut spans_suggs = + make_elided_region_spans_suggs(name, generics.params.iter()) && spans_suggs.len() > 1 { let use_lt = if existing_lt_name == None { @@ -430,6 +418,57 @@ pub fn suggest_new_region_bound( } } +fn make_elided_region_spans_suggs<'a>( + name: &str, + generic_params: impl Iterator<Item = &'a GenericParam<'a>>, +) -> Vec<(Span, String)> { + let mut spans_suggs = Vec::new(); + let mut bracket_span = None; + let mut consecutive_brackets = 0; + + let mut process_consecutive_brackets = + |span: Option<Span>, spans_suggs: &mut Vec<(Span, String)>| { + if span + .is_some_and(|span| bracket_span.map_or(true, |bracket_span| span == bracket_span)) + { + consecutive_brackets += 1; + } else if let Some(bracket_span) = bracket_span.take() { + let sugg = std::iter::once("<") + .chain(std::iter::repeat(name).take(consecutive_brackets).intersperse(", ")) + .chain([">"]) + .collect(); + spans_suggs.push((bracket_span.shrink_to_hi(), sugg)); + consecutive_brackets = 0; + } + bracket_span = span; + }; + + for p in generic_params { + if let GenericParamKind::Lifetime { kind: LifetimeParamKind::Elided(kind) } = p.kind { + match kind { + MissingLifetimeKind::Underscore => { + process_consecutive_brackets(None, &mut spans_suggs); + spans_suggs.push((p.span, name.to_string())) + } + MissingLifetimeKind::Ampersand => { + process_consecutive_brackets(None, &mut spans_suggs); + spans_suggs.push((p.span.shrink_to_hi(), format!("{name} "))); + } + MissingLifetimeKind::Comma => { + process_consecutive_brackets(None, &mut spans_suggs); + spans_suggs.push((p.span.shrink_to_hi(), format!("{name}, "))); + } + MissingLifetimeKind::Brackets => { + process_consecutive_brackets(Some(p.span), &mut spans_suggs); + } + } + } + } + process_consecutive_brackets(None, &mut spans_suggs); + + spans_suggs +} + impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { pub fn get_impl_ident_and_self_ty_from_trait( tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs index 24eaff08220..fda3564bdbe 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs @@ -299,8 +299,11 @@ impl<T> Trait<T> for X { } (ty::Dynamic(t, _, ty::DynKind::Dyn), ty::Alias(ty::Opaque, alias)) if let Some(def_id) = t.principal_def_id() - && tcx.explicit_item_bounds(alias.def_id).skip_binder().iter().any( - |(pred, _span)| match pred.kind().skip_binder() { + && tcx + .explicit_item_super_predicates(alias.def_id) + .skip_binder() + .iter() + .any(|(pred, _span)| match pred.kind().skip_binder() { ty::ClauseKind::Trait(trait_predicate) if trait_predicate.polarity == ty::ImplPolarity::Positive => @@ -308,8 +311,7 @@ impl<T> Trait<T> for X { trait_predicate.def_id() == def_id } _ => false, - }, - ) => + }) => { diag.help(format!( "you can box the `{}` to coerce it to `Box<{}>`, but you'll have to \ @@ -412,7 +414,7 @@ impl<T> Trait<T> for X { ty::Alias(..) => values.expected, _ => values.found, }; - let preds = tcx.explicit_item_bounds(opaque_ty.def_id); + let preds = tcx.explicit_item_super_predicates(opaque_ty.def_id); for (pred, _span) in preds.skip_binder() { let ty::ClauseKind::Trait(trait_predicate) = pred.kind().skip_binder() else { diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index c39d0425f7e..5ae7f8bf504 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -13,6 +13,7 @@ use rustc_data_structures::graph::implementation::{ Direction, Graph, NodeIndex, INCOMING, OUTGOING, }; use rustc_data_structures::intern::Interned; +use rustc_data_structures::unord::UnordSet; use rustc_index::{IndexSlice, IndexVec}; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -139,8 +140,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { let mut var_data = self.construct_var_data(); // Deduplicating constraints is shown to have a positive perf impact. - self.data.constraints.sort_by_key(|(constraint, _)| *constraint); - self.data.constraints.dedup_by_key(|(constraint, _)| *constraint); + let mut seen = UnordSet::default(); + self.data.constraints.retain(|(constraint, _)| seen.insert(*constraint)); if cfg!(debug_assertions) { self.dump_constraints(); @@ -888,12 +889,14 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { } Constraint::RegSubVar(region, _) | Constraint::VarSubReg(_, region) => { - let constraint_idx = - this.constraints.binary_search_by(|(c, _)| c.cmp(&edge.data)).unwrap(); - state.result.push(RegionAndOrigin { - region, - origin: this.constraints[constraint_idx].1.clone(), - }); + let origin = this + .constraints + .iter() + .find(|(c, _)| *c == edge.data) + .unwrap() + .1 + .clone(); + state.result.push(RegionAndOrigin { region, origin }); } Constraint::RegSubReg(..) => panic!( diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 89e4e88b3df..a3ff655b609 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -678,7 +678,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> { T: TypeFoldable<TyCtxt<'tcx>>, { let infcx = self.build(); - let (value, args) = infcx.instantiate_canonical_with_fresh_inference_vars(span, canonical); + let (value, args) = infcx.instantiate_canonical(span, canonical); (infcx, value, args) } @@ -1475,7 +1475,7 @@ impl<'tcx> InferCtxt<'tcx> { param_env: ty::ParamEnv<'tcx>, unevaluated: ty::UnevaluatedConst<'tcx>, ty: Ty<'tcx>, - span: Option<Span>, + span: Span, ) -> Result<ty::Const<'tcx>, ErrorHandled> { match self.const_eval_resolve(param_env, unevaluated, span) { Ok(Some(val)) => Ok(ty::Const::new_value(self.tcx, val, ty)), @@ -1509,7 +1509,7 @@ impl<'tcx> InferCtxt<'tcx> { &self, mut param_env: ty::ParamEnv<'tcx>, unevaluated: ty::UnevaluatedConst<'tcx>, - span: Option<Span>, + span: Span, ) -> EvalToValTreeResult<'tcx> { let mut args = self.resolve_vars_if_possible(unevaluated.args); debug!(?args); @@ -1521,12 +1521,9 @@ impl<'tcx> InferCtxt<'tcx> { if let Some(ct) = tcx.thir_abstract_const(unevaluated.def)? { let ct = tcx.expand_abstract_consts(ct.instantiate(tcx, args)); if let Err(e) = ct.error_reported() { - return Err(ErrorHandled::Reported( - e.into(), - span.unwrap_or(rustc_span::DUMMY_SP), - )); + return Err(ErrorHandled::Reported(e.into(), span)); } else if ct.has_non_region_infer() || ct.has_non_region_param() { - return Err(ErrorHandled::TooGeneric(span.unwrap_or(rustc_span::DUMMY_SP))); + return Err(ErrorHandled::TooGeneric(span)); } else { args = replace_param_and_infer_args_with_placeholder(tcx, args); } diff --git a/compiler/rustc_infer/src/infer/opaque_types/mod.rs b/compiler/rustc_infer/src/infer/opaque_types/mod.rs index a6f8115c27e..02b8ded285f 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/mod.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/mod.rs @@ -94,9 +94,6 @@ impl<'tcx> InferCtxt<'tcx> { cause: &ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, ) -> InferResult<'tcx, ()> { - if a.references_error() || b.references_error() { - return Ok(InferOk { value: (), obligations: vec![] }); - } let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() { ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => { let def_id = def_id.expect_local(); diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index 3ef37bf3466..bd981c20567 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -300,7 +300,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { alias_ty: ty::AliasTy<'tcx>, ) -> impl Iterator<Item = ty::Region<'tcx>> { let tcx = self.tcx; - let bounds = tcx.item_bounds(alias_ty.def_id); + let bounds = tcx.item_super_predicates(alias_ty.def_id); trace!("{:#?}", bounds.skip_binder()); bounds .iter_instantiated(tcx, alias_ty.args) diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index 0f3f2bc5fa6..3d6b54721d0 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -104,7 +104,7 @@ pub struct RegionConstraintData<'tcx> { } /// Represents a constraint that influences the inference process. -#[derive(Clone, Copy, PartialEq, Eq, Debug, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] pub enum Constraint<'tcx> { /// A region variable is a subregion of another. VarSubVar(RegionVid, RegionVid), diff --git a/compiler/rustc_infer/src/lib.rs b/compiler/rustc_infer/src/lib.rs index 029bddda1e1..ee9ce842d00 100644 --- a/compiler/rustc_infer/src/lib.rs +++ b/compiler/rustc_infer/src/lib.rs @@ -18,15 +18,16 @@ #![allow(internal_features)] #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] -#![feature(associated_type_bounds)] +#![cfg_attr(bootstrap, feature(associated_type_bounds))] #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(extend_one)] #![feature(let_chains)] #![feature(if_let_guard)] +#![feature(iter_intersperse)] #![feature(iterator_try_collect)] -#![cfg_attr(bootstrap, feature(min_specialization))] #![feature(try_blocks)] +#![feature(yeet_expr)] #![recursion_limit = "512"] // For rustdoc #[macro_use] diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 1a82e6c6910..8ba14d37982 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -341,51 +341,22 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se let sysroot = filesearch::materialize_sysroot(config.opts.maybe_sysroot.clone()); - let (codegen_backend, target_override) = match config.make_codegen_backend { - None => { - // Build a target without override, so that it can override the backend if needed - let target = - config::build_target_config(&early_dcx, &config.opts, None, &sysroot); - - let backend = util::get_codegen_backend( - &early_dcx, - &sysroot, - config.opts.unstable_opts.codegen_backend.as_deref(), - &target, - ); - - // target_override is documented to be called before init(), so this is okay - let target_override = backend.target_override(&config.opts); - - // Assert that we don't use target's override of the backend and - // backend's override of the target at the same time - if config.opts.unstable_opts.codegen_backend.is_none() - && target.default_codegen_backend.is_some() - && target_override.is_some() - { - rustc_middle::bug!( - "Codegen backend requested target override even though the target requested the backend" - ); - } - - (backend, target_override) - } + let target = config::build_target_config(&early_dcx, &config.opts, &sysroot); + + let codegen_backend = match config.make_codegen_backend { + None => util::get_codegen_backend( + &early_dcx, + &sysroot, + config.opts.unstable_opts.codegen_backend.as_deref(), + &target, + ), Some(make_codegen_backend) => { - // N.B. `make_codegen_backend` takes precedence over `target.default_codegen_backend`, - // which is ignored in this case. - let backend = make_codegen_backend(&config.opts); - - // target_override is documented to be called before init(), so this is okay - let target_override = backend.target_override(&config.opts); - - (backend, target_override) + // N.B. `make_codegen_backend` takes precedence over + // `target.default_codegen_backend`, which is ignored in this case. + make_codegen_backend(&config.opts) } }; - // Re-build target with the (potential) override - let target_cfg = - config::build_target_config(&early_dcx, &config.opts, target_override, &sysroot); - let temps_dir = config.opts.unstable_opts.temps_dir.as_deref().map(PathBuf::from); let bundle = match rustc_errors::fluent_bundle( @@ -418,7 +389,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se locale_resources, config.lint_caps, config.file_loader, - target_cfg, + target, sysroot, util::rustc_version_str().unwrap_or("unknown"), config.ice_file, diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 4d8e749d1da..8a27e9a6453 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -41,8 +41,7 @@ fn mk_session(matches: getopts::Matches) -> (Session, Cfg) { let sysroot = filesearch::materialize_sysroot(sessopts.maybe_sysroot.clone()); - let target_cfg = - rustc_session::config::build_target_config(&early_dcx, &sessopts, None, &sysroot); + let target = rustc_session::config::build_target_config(&early_dcx, &sessopts, &sysroot); let sess = build_session( early_dcx, @@ -53,7 +52,7 @@ fn mk_session(matches: getopts::Matches) -> (Session, Cfg) { vec![], Default::default(), None, - target_cfg, + target, sysroot, "", None, diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 7d48f90db36..d09f8d7d7cf 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -48,12 +48,20 @@ pub fn add_configuration(cfg: &mut Cfg, sess: &mut Session, codegen_backend: &dy } } -const STACK_SIZE: usize = 8 * 1024 * 1024; - -fn get_stack_size() -> Option<usize> { - // FIXME: Hacks on hacks. If the env is trying to override the stack size - // then *don't* set it explicitly. - env::var_os("RUST_MIN_STACK").is_none().then_some(STACK_SIZE) +pub static STACK_SIZE: OnceLock<usize> = OnceLock::new(); +pub const DEFAULT_STACK_SIZE: usize = 8 * 1024 * 1024; + +fn init_stack_size() -> usize { + // Obey the environment setting or default + *STACK_SIZE.get_or_init(|| { + env::var_os("RUST_MIN_STACK") + .map(|os_str| os_str.to_string_lossy().into_owned()) + // ignore if it is set to nothing + .filter(|s| s.trim() != "") + .map(|s| s.trim().parse::<usize>().unwrap()) + // otherwise pick a consistent default + .unwrap_or(DEFAULT_STACK_SIZE) + }) } pub(crate) fn run_in_thread_with_globals<F: FnOnce() -> R + Send, R: Send>( @@ -66,10 +74,7 @@ pub(crate) fn run_in_thread_with_globals<F: FnOnce() -> R + Send, R: Send>( // the parallel compiler, in particular to ensure there is no accidental // sharing of data between the main thread and the compilation thread // (which might cause problems for the parallel compiler). - let mut builder = thread::Builder::new().name("rustc".to_string()); - if let Some(size) = get_stack_size() { - builder = builder.stack_size(size); - } + let builder = thread::Builder::new().name("rustc".to_string()).stack_size(init_stack_size()); // We build the session globals and run `f` on the spawned thread, because // `SessionGlobals` does not impl `Send` in the non-parallel compiler. @@ -120,7 +125,7 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>( }); } - let mut builder = rayon::ThreadPoolBuilder::new() + let builder = rayon::ThreadPoolBuilder::new() .thread_name(|_| "rustc".to_string()) .acquire_thread_handler(jobserver::acquire_thread) .release_thread_handler(jobserver::release_thread) @@ -144,10 +149,8 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>( on_panic.disable(); }) .unwrap(); - }); - if let Some(size) = get_stack_size() { - builder = builder.stack_size(size); - } + }) + .stack_size(init_stack_size()); // We create the session globals on the main thread, then create the thread // pool. Upon creation, each worker thread created gets a copy of the diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index d1343e3b4ba..aff1dc40954 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2468,6 +2468,8 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { ty: Ty<'tcx>, init: InitKind, ) -> Option<InitError> { + let ty = cx.tcx.try_normalize_erasing_regions(cx.param_env, ty).unwrap_or(ty); + use rustc_type_ir::TyKind::*; match ty.kind() { // Primitive types that don't like 0 as a value. diff --git a/compiler/rustc_lint/src/context/diagnostics.rs b/compiler/rustc_lint/src/context/diagnostics.rs index a0be1c09c9a..e2010ab3830 100644 --- a/compiler/rustc_lint/src/context/diagnostics.rs +++ b/compiler/rustc_lint/src/context/diagnostics.rs @@ -5,49 +5,11 @@ use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS; use rustc_errors::{add_elided_lifetime_in_path_suggestion, Diag}; use rustc_errors::{Applicability, SuggestionStyle}; use rustc_middle::middle::stability; -use rustc_session::config::ExpectedValues; use rustc_session::lint::BuiltinLintDiag; use rustc_session::Session; -use rustc_span::edit_distance::find_best_match_for_name; -use rustc_span::symbol::{sym, Symbol}; use rustc_span::BytePos; -const MAX_CHECK_CFG_NAMES_OR_VALUES: usize = 35; - -fn check_cfg_expected_note( - sess: &Session, - possibilities: &[Symbol], - type_: &str, - name: Option<Symbol>, - suffix: &str, -) -> String { - use std::fmt::Write; - - let n_possibilities = if sess.opts.unstable_opts.check_cfg_all_expected { - possibilities.len() - } else { - std::cmp::min(possibilities.len(), MAX_CHECK_CFG_NAMES_OR_VALUES) - }; - - let mut possibilities = possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>(); - possibilities.sort(); - - let and_more = possibilities.len().saturating_sub(n_possibilities); - let possibilities = possibilities[..n_possibilities].join("`, `"); - - let mut note = String::with_capacity(50 + possibilities.len()); - - write!(&mut note, "expected {type_}").unwrap(); - if let Some(name) = name { - write!(&mut note, " for `{name}`").unwrap(); - } - write!(&mut note, " are: {suffix}`{possibilities}`").unwrap(); - if and_more > 0 { - write!(&mut note, " and {and_more} more").unwrap(); - } - - note -} +mod check_cfg; pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Diag<'_, ()>) { match diagnostic { @@ -219,242 +181,11 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di diag.help(help); diag.note("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information"); } - BuiltinLintDiag::UnexpectedCfgName((name, name_span), value) => { - #[allow(rustc::potential_query_instability)] - let possibilities: Vec<Symbol> = - sess.psess.check_config.expecteds.keys().copied().collect(); - - let mut names_possibilities: Vec<_> = if value.is_none() { - // We later sort and display all the possibilities, so the order here does not matter. - #[allow(rustc::potential_query_instability)] - sess.psess - .check_config - .expecteds - .iter() - .filter_map(|(k, v)| match v { - ExpectedValues::Some(v) if v.contains(&Some(name)) => Some(k), - _ => None, - }) - .collect() - } else { - Vec::new() - }; - - let is_from_cargo = rustc_session::utils::was_invoked_from_cargo(); - let mut is_feature_cfg = name == sym::feature; - - if is_feature_cfg && is_from_cargo { - diag.help("consider defining some features in `Cargo.toml`"); - // Suggest the most probable if we found one - } else if let Some(best_match) = find_best_match_for_name(&possibilities, name, None) { - if let Some(ExpectedValues::Some(best_match_values)) = - sess.psess.check_config.expecteds.get(&best_match) - { - // We will soon sort, so the initial order does not matter. - #[allow(rustc::potential_query_instability)] - let mut possibilities = - best_match_values.iter().flatten().map(Symbol::as_str).collect::<Vec<_>>(); - possibilities.sort(); - - let mut should_print_possibilities = true; - if let Some((value, value_span)) = value { - if best_match_values.contains(&Some(value)) { - diag.span_suggestion( - name_span, - "there is a config with a similar name and value", - best_match, - Applicability::MaybeIncorrect, - ); - should_print_possibilities = false; - } else if best_match_values.contains(&None) { - diag.span_suggestion( - name_span.to(value_span), - "there is a config with a similar name and no value", - best_match, - Applicability::MaybeIncorrect, - ); - should_print_possibilities = false; - } else if let Some(first_value) = possibilities.first() { - diag.span_suggestion( - name_span.to(value_span), - "there is a config with a similar name and different values", - format!("{best_match} = \"{first_value}\""), - Applicability::MaybeIncorrect, - ); - } else { - diag.span_suggestion( - name_span.to(value_span), - "there is a config with a similar name and different values", - best_match, - Applicability::MaybeIncorrect, - ); - }; - } else { - diag.span_suggestion( - name_span, - "there is a config with a similar name", - best_match, - Applicability::MaybeIncorrect, - ); - } - - if !possibilities.is_empty() && should_print_possibilities { - let possibilities = possibilities.join("`, `"); - diag.help(format!( - "expected values for `{best_match}` are: `{possibilities}`" - )); - } - } else { - diag.span_suggestion( - name_span, - "there is a config with a similar name", - best_match, - Applicability::MaybeIncorrect, - ); - } - - is_feature_cfg |= best_match == sym::feature; - } else { - if !names_possibilities.is_empty() && names_possibilities.len() <= 3 { - names_possibilities.sort(); - for cfg_name in names_possibilities.iter() { - diag.span_suggestion( - name_span, - "found config with similar value", - format!("{cfg_name} = \"{name}\""), - Applicability::MaybeIncorrect, - ); - } - } - if !possibilities.is_empty() { - diag.help_once(check_cfg_expected_note( - sess, - &possibilities, - "names", - None, - "", - )); - } - } - - let inst = if let Some((value, _value_span)) = value { - let pre = if is_from_cargo { "\\" } else { "" }; - format!("cfg({name}, values({pre}\"{value}{pre}\"))") - } else { - format!("cfg({name})") - }; - - if is_from_cargo { - if !is_feature_cfg { - diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`")); - } - diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration"); - } else { - diag.help(format!("to expect this configuration use `--check-cfg={inst}`")); - diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration"); - } + BuiltinLintDiag::UnexpectedCfgName(name, value) => { + check_cfg::unexpected_cfg_name(sess, diag, name, value) } - BuiltinLintDiag::UnexpectedCfgValue((name, name_span), value) => { - let Some(ExpectedValues::Some(values)) = &sess.psess.check_config.expecteds.get(&name) - else { - bug!( - "it shouldn't be possible to have a diagnostic on a value whose name is not in values" - ); - }; - let mut have_none_possibility = false; - // We later sort possibilities if it is not empty, so the - // order here does not matter. - #[allow(rustc::potential_query_instability)] - let possibilities: Vec<Symbol> = values - .iter() - .inspect(|a| have_none_possibility |= a.is_none()) - .copied() - .flatten() - .collect(); - let is_from_cargo = rustc_session::utils::was_invoked_from_cargo(); - - // Show the full list if all possible values for a given name, but don't do it - // for names as the possibilities could be very long - if !possibilities.is_empty() { - diag.note(check_cfg_expected_note( - sess, - &possibilities, - "values", - Some(name), - if have_none_possibility { "(none), " } else { "" }, - )); - - if let Some((value, value_span)) = value { - // Suggest the most probable if we found one - if let Some(best_match) = find_best_match_for_name(&possibilities, value, None) - { - diag.span_suggestion( - value_span, - "there is a expected value with a similar name", - format!("\"{best_match}\""), - Applicability::MaybeIncorrect, - ); - } - } else if let &[first_possibility] = &possibilities[..] { - diag.span_suggestion( - name_span.shrink_to_hi(), - "specify a config value", - format!(" = \"{first_possibility}\""), - Applicability::MaybeIncorrect, - ); - } - } else if have_none_possibility { - diag.note(format!("no expected value for `{name}`")); - if let Some((_value, value_span)) = value { - diag.span_suggestion( - name_span.shrink_to_hi().to(value_span), - "remove the value", - "", - Applicability::MaybeIncorrect, - ); - } - } else { - diag.note(format!("no expected values for `{name}`")); - - let sp = if let Some((_value, value_span)) = value { - name_span.to(value_span) - } else { - name_span - }; - diag.span_suggestion(sp, "remove the condition", "", Applicability::MaybeIncorrect); - } - - // We don't want to suggest adding values to well known names - // since those are defined by rustc it-self. Users can still - // do it if they want, but should not encourage them. - let is_cfg_a_well_know_name = sess.psess.check_config.well_known_names.contains(&name); - - let inst = if let Some((value, _value_span)) = value { - let pre = if is_from_cargo { "\\" } else { "" }; - format!("cfg({name}, values({pre}\"{value}{pre}\"))") - } else { - format!("cfg({name})") - }; - - if is_from_cargo { - if name == sym::feature { - if let Some((value, _value_span)) = value { - diag.help(format!( - "consider adding `{value}` as a feature in `Cargo.toml`" - )); - } else { - diag.help("consider defining some features in `Cargo.toml`"); - } - } else if !is_cfg_a_well_know_name { - diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`")); - } - diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration"); - } else { - if !is_cfg_a_well_know_name { - diag.help(format!("to expect this configuration use `--check-cfg={inst}`")); - } - diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration"); - } + BuiltinLintDiag::UnexpectedCfgValue(name, value) => { + check_cfg::unexpected_cfg_value(sess, diag, name, value) } BuiltinLintDiag::DeprecatedWhereclauseLocation(sugg) => { let left_sp = diag.span.primary_span().unwrap(); diff --git a/compiler/rustc_lint/src/context/diagnostics/check_cfg.rs b/compiler/rustc_lint/src/context/diagnostics/check_cfg.rs new file mode 100644 index 00000000000..2c9a3a6d1b2 --- /dev/null +++ b/compiler/rustc_lint/src/context/diagnostics/check_cfg.rs @@ -0,0 +1,277 @@ +use rustc_errors::{Applicability, Diag}; +use rustc_session::{config::ExpectedValues, Session}; +use rustc_span::edit_distance::find_best_match_for_name; +use rustc_span::{sym, Span, Symbol}; + +const MAX_CHECK_CFG_NAMES_OR_VALUES: usize = 35; + +fn check_cfg_expected_note( + sess: &Session, + possibilities: &[Symbol], + type_: &str, + name: Option<Symbol>, + suffix: &str, +) -> String { + use std::fmt::Write; + + let n_possibilities = if sess.opts.unstable_opts.check_cfg_all_expected { + possibilities.len() + } else { + std::cmp::min(possibilities.len(), MAX_CHECK_CFG_NAMES_OR_VALUES) + }; + + let mut possibilities = possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>(); + possibilities.sort(); + + let and_more = possibilities.len().saturating_sub(n_possibilities); + let possibilities = possibilities[..n_possibilities].join("`, `"); + + let mut note = String::with_capacity(50 + possibilities.len()); + + write!(&mut note, "expected {type_}").unwrap(); + if let Some(name) = name { + write!(&mut note, " for `{name}`").unwrap(); + } + write!(&mut note, " are: {suffix}`{possibilities}`").unwrap(); + if and_more > 0 { + write!(&mut note, " and {and_more} more").unwrap(); + } + + note +} + +pub(super) fn unexpected_cfg_name( + sess: &Session, + diag: &mut Diag<'_, ()>, + (name, name_span): (Symbol, Span), + value: Option<(Symbol, Span)>, +) { + #[allow(rustc::potential_query_instability)] + let possibilities: Vec<Symbol> = sess.psess.check_config.expecteds.keys().copied().collect(); + + let mut names_possibilities: Vec<_> = if value.is_none() { + // We later sort and display all the possibilities, so the order here does not matter. + #[allow(rustc::potential_query_instability)] + sess.psess + .check_config + .expecteds + .iter() + .filter_map(|(k, v)| match v { + ExpectedValues::Some(v) if v.contains(&Some(name)) => Some(k), + _ => None, + }) + .collect() + } else { + Vec::new() + }; + + let is_from_cargo = rustc_session::utils::was_invoked_from_cargo(); + let mut is_feature_cfg = name == sym::feature; + + if is_feature_cfg && is_from_cargo { + diag.help("consider defining some features in `Cargo.toml`"); + // Suggest the most probable if we found one + } else if let Some(best_match) = find_best_match_for_name(&possibilities, name, None) { + if let Some(ExpectedValues::Some(best_match_values)) = + sess.psess.check_config.expecteds.get(&best_match) + { + // We will soon sort, so the initial order does not matter. + #[allow(rustc::potential_query_instability)] + let mut possibilities = + best_match_values.iter().flatten().map(Symbol::as_str).collect::<Vec<_>>(); + possibilities.sort(); + + let mut should_print_possibilities = true; + if let Some((value, value_span)) = value { + if best_match_values.contains(&Some(value)) { + diag.span_suggestion( + name_span, + "there is a config with a similar name and value", + best_match, + Applicability::MaybeIncorrect, + ); + should_print_possibilities = false; + } else if best_match_values.contains(&None) { + diag.span_suggestion( + name_span.to(value_span), + "there is a config with a similar name and no value", + best_match, + Applicability::MaybeIncorrect, + ); + should_print_possibilities = false; + } else if let Some(first_value) = possibilities.first() { + diag.span_suggestion( + name_span.to(value_span), + "there is a config with a similar name and different values", + format!("{best_match} = \"{first_value}\""), + Applicability::MaybeIncorrect, + ); + } else { + diag.span_suggestion( + name_span.to(value_span), + "there is a config with a similar name and different values", + best_match, + Applicability::MaybeIncorrect, + ); + }; + } else { + diag.span_suggestion( + name_span, + "there is a config with a similar name", + best_match, + Applicability::MaybeIncorrect, + ); + } + + if !possibilities.is_empty() && should_print_possibilities { + let possibilities = possibilities.join("`, `"); + diag.help(format!("expected values for `{best_match}` are: `{possibilities}`")); + } + } else { + diag.span_suggestion( + name_span, + "there is a config with a similar name", + best_match, + Applicability::MaybeIncorrect, + ); + } + + is_feature_cfg |= best_match == sym::feature; + } else { + if !names_possibilities.is_empty() && names_possibilities.len() <= 3 { + names_possibilities.sort(); + for cfg_name in names_possibilities.iter() { + diag.span_suggestion( + name_span, + "found config with similar value", + format!("{cfg_name} = \"{name}\""), + Applicability::MaybeIncorrect, + ); + } + } + if !possibilities.is_empty() { + diag.help_once(check_cfg_expected_note(sess, &possibilities, "names", None, "")); + } + } + + let inst = if let Some((value, _value_span)) = value { + let pre = if is_from_cargo { "\\" } else { "" }; + format!("cfg({name}, values({pre}\"{value}{pre}\"))") + } else { + format!("cfg({name})") + }; + + if is_from_cargo { + if !is_feature_cfg { + diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`")); + } + diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration"); + } else { + diag.help(format!("to expect this configuration use `--check-cfg={inst}`")); + diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration"); + } +} + +pub(super) fn unexpected_cfg_value( + sess: &Session, + diag: &mut Diag<'_, ()>, + (name, name_span): (Symbol, Span), + value: Option<(Symbol, Span)>, +) { + let Some(ExpectedValues::Some(values)) = &sess.psess.check_config.expecteds.get(&name) else { + bug!( + "it shouldn't be possible to have a diagnostic on a value whose name is not in values" + ); + }; + let mut have_none_possibility = false; + // We later sort possibilities if it is not empty, so the + // order here does not matter. + #[allow(rustc::potential_query_instability)] + let possibilities: Vec<Symbol> = values + .iter() + .inspect(|a| have_none_possibility |= a.is_none()) + .copied() + .flatten() + .collect(); + let is_from_cargo = rustc_session::utils::was_invoked_from_cargo(); + + // Show the full list if all possible values for a given name, but don't do it + // for names as the possibilities could be very long + if !possibilities.is_empty() { + diag.note(check_cfg_expected_note( + sess, + &possibilities, + "values", + Some(name), + if have_none_possibility { "(none), " } else { "" }, + )); + + if let Some((value, value_span)) = value { + // Suggest the most probable if we found one + if let Some(best_match) = find_best_match_for_name(&possibilities, value, None) { + diag.span_suggestion( + value_span, + "there is a expected value with a similar name", + format!("\"{best_match}\""), + Applicability::MaybeIncorrect, + ); + } + } else if let &[first_possibility] = &possibilities[..] { + diag.span_suggestion( + name_span.shrink_to_hi(), + "specify a config value", + format!(" = \"{first_possibility}\""), + Applicability::MaybeIncorrect, + ); + } + } else if have_none_possibility { + diag.note(format!("no expected value for `{name}`")); + if let Some((_value, value_span)) = value { + diag.span_suggestion( + name_span.shrink_to_hi().to(value_span), + "remove the value", + "", + Applicability::MaybeIncorrect, + ); + } + } else { + diag.note(format!("no expected values for `{name}`")); + + let sp = if let Some((_value, value_span)) = value { + name_span.to(value_span) + } else { + name_span + }; + diag.span_suggestion(sp, "remove the condition", "", Applicability::MaybeIncorrect); + } + + // We don't want to suggest adding values to well known names + // since those are defined by rustc it-self. Users can still + // do it if they want, but should not encourage them. + let is_cfg_a_well_know_name = sess.psess.check_config.well_known_names.contains(&name); + + let inst = if let Some((value, _value_span)) = value { + let pre = if is_from_cargo { "\\" } else { "" }; + format!("cfg({name}, values({pre}\"{value}{pre}\"))") + } else { + format!("cfg({name})") + }; + + if is_from_cargo { + if name == sym::feature { + if let Some((value, _value_span)) = value { + diag.help(format!("consider adding `{value}` as a feature in `Cargo.toml`")); + } else { + diag.help("consider defining some features in `Cargo.toml`"); + } + } else if !is_cfg_a_well_know_name { + diag.help(format!("consider using a Cargo feature instead or adding `println!(\"cargo:rustc-check-cfg={inst}\");` to the top of a `build.rs`")); + } + diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration"); + } else { + if !is_cfg_a_well_know_name { + diag.help(format!("to expect this configuration use `--check-cfg={inst}`")); + } + diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration"); + } +} diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 95f312a31b3..26fc3f20b2c 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -191,7 +191,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe levels.add_id(hir::CRATE_HIR_ID); levels.visit_mod(mod_, mod_.spans.inner_span, hir::CRATE_HIR_ID) } - hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(), + hir::OwnerNode::Synthetic => unreachable!(), }, } @@ -1078,6 +1078,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { feature, GateIssue::Language, lint_from_cli, + None, ); }, ); diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 250c4adb948..31c80c4d75b 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -313,6 +313,12 @@ fn register_builtins(store: &mut LintStore) { // MACRO_USE_EXTERN_CRATE ); + add_lint_group!( + "refining_impl_trait", + REFINING_IMPL_TRAIT_REACHABLE, + REFINING_IMPL_TRAIT_INTERNAL + ); + // Register renamed and removed lints. store.register_renamed("single_use_lifetime", "single_use_lifetimes"); store.register_renamed("elided_lifetime_in_path", "elided_lifetimes_in_paths"); diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 5d36a8b3d0e..0ad257d02bd 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -561,10 +561,11 @@ fn lint_literal<'tcx>( ty::Float(t) => { let is_infinite = match lit.node { ast::LitKind::Float(v, _) => match t { - ty::FloatTy::F16 => unimplemented!("f16_f128"), + // FIXME(f16_f128): add this check once we have library support + ty::FloatTy::F16 => Ok(false), ty::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite), ty::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite), - ty::FloatTy::F128 => unimplemented!("f16_f128"), + ty::FloatTy::F128 => Ok(false), }, _ => bug!(), }; @@ -984,7 +985,14 @@ pub fn transparent_newtype_field<'a, 'tcx>( } /// Is type known to be non-null? -fn ty_is_known_nonnull<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, mode: CItemKind) -> bool { +fn ty_is_known_nonnull<'tcx>( + tcx: TyCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + ty: Ty<'tcx>, + mode: CItemKind, +) -> bool { + let ty = tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty); + match ty.kind() { ty::FnPtr(_) => true, ty::Ref(..) => true, @@ -1004,7 +1012,7 @@ fn ty_is_known_nonnull<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, mode: CItemKind) - def.variants() .iter() .filter_map(|variant| transparent_newtype_field(tcx, variant)) - .any(|field| ty_is_known_nonnull(tcx, field.ty(tcx, args), mode)) + .any(|field| ty_is_known_nonnull(tcx, param_env, field.ty(tcx, args), mode)) } _ => false, } @@ -1012,7 +1020,13 @@ fn ty_is_known_nonnull<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, mode: CItemKind) - /// Given a non-null scalar (or transparent) type `ty`, return the nullable version of that type. /// If the type passed in was not scalar, returns None. -fn get_nullable_type<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>> { +fn get_nullable_type<'tcx>( + tcx: TyCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + ty: Ty<'tcx>, +) -> Option<Ty<'tcx>> { + let ty = tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty); + Some(match *ty.kind() { ty::Adt(field_def, field_args) => { let inner_field_ty = { @@ -1028,22 +1042,19 @@ fn get_nullable_type<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>> .expect("No non-zst fields in transparent type.") .ty(tcx, field_args) }; - return get_nullable_type(tcx, inner_field_ty); + return get_nullable_type(tcx, param_env, inner_field_ty); } ty::Int(ty) => Ty::new_int(tcx, ty), ty::Uint(ty) => Ty::new_uint(tcx, ty), ty::RawPtr(ty_mut) => Ty::new_ptr(tcx, ty_mut), // As these types are always non-null, the nullable equivalent of - // Option<T> of these types are their raw pointer counterparts. + // `Option<T>` of these types are their raw pointer counterparts. ty::Ref(_region, ty, mutbl) => Ty::new_ptr(tcx, ty::TypeAndMut { ty, mutbl }), - ty::FnPtr(..) => { - // There is no nullable equivalent for Rust's function pointers -- you - // must use an Option<fn(..) -> _> to represent it. - ty - } - - // We should only ever reach this case if ty_is_known_nonnull is extended - // to other types. + // There is no nullable equivalent for Rust's function pointers, + // you must use an `Option<fn(..) -> _>` to represent it. + ty::FnPtr(..) => ty, + // We should only ever reach this case if `ty_is_known_nonnull` is + // extended to other types. ref unhandled => { debug!( "get_nullable_type: Unhandled scalar kind: {:?} while checking {:?}", @@ -1056,7 +1067,7 @@ fn get_nullable_type<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>> /// Check if this enum can be safely exported based on the "nullable pointer optimization". If it /// can, return the type that `ty` can be safely converted to, otherwise return `None`. -/// Currently restricted to function pointers, boxes, references, `core::num::NonZero*`, +/// Currently restricted to function pointers, boxes, references, `core::num::NonZero`, /// `core::ptr::NonNull`, and `#[repr(transparent)]` newtypes. /// FIXME: This duplicates code in codegen. pub(crate) fn repr_nullable_ptr<'tcx>( @@ -1075,7 +1086,7 @@ pub(crate) fn repr_nullable_ptr<'tcx>( _ => return None, }; - if !ty_is_known_nonnull(tcx, field_ty, ckind) { + if !ty_is_known_nonnull(tcx, param_env, field_ty, ckind) { return None; } @@ -1099,10 +1110,10 @@ pub(crate) fn repr_nullable_ptr<'tcx>( WrappingRange { start: 0, end } if end == field_ty_scalar.size(&tcx).unsigned_int_max() - 1 => { - return Some(get_nullable_type(tcx, field_ty).unwrap()); + return Some(get_nullable_type(tcx, param_env, field_ty).unwrap()); } WrappingRange { start: 1, .. } => { - return Some(get_nullable_type(tcx, field_ty).unwrap()); + return Some(get_nullable_type(tcx, param_env, field_ty).unwrap()); } WrappingRange { start, end } => { unreachable!("Unhandled start and end range: ({}, {})", start, end) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 3e10879e241..0b757f95a99 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -295,7 +295,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { ty::Alias(ty::Opaque | ty::Projection, ty::AliasTy { def_id: def, .. }) => { elaborate( cx.tcx, - cx.tcx.explicit_item_bounds(def).instantiate_identity_iter_copied(), + cx.tcx + .explicit_item_super_predicates(def) + .instantiate_identity_iter_copied(), ) // We only care about self bounds for the impl-trait .filter_only_self() @@ -863,7 +865,7 @@ trait UnusedDelimLint { (iter, UnusedDelimsCtx::ForIterExpr, true, None, Some(body.span.lo()), true) } - Match(ref head, _) if Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX => { + Match(ref head, ..) if Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX => { let left = e.span.lo() + rustc_span::BytePos(5); (head, UnusedDelimsCtx::MatchScrutineeExpr, true, Some(left), None, true) } @@ -1131,7 +1133,7 @@ impl EarlyLintPass for UnusedParens { } return; } - ExprKind::Match(ref _expr, ref arm) => { + ExprKind::Match(ref _expr, ref arm, _) => { for a in arm { if let Some(body) = &a.body { self.check_unused_delims_expr( @@ -1181,7 +1183,7 @@ impl EarlyLintPass for UnusedParens { self.check_unused_parens_pat(cx, &f.pat, false, false, keep_space); }, // Avoid linting on `i @ (p0 | .. | pn)` and `box (p0 | .. | pn)`, #64106. - Ident(.., Some(p)) | Box(p) => self.check_unused_parens_pat(cx, p, true, false, keep_space), + Ident(.., Some(p)) | Box(p) | Deref(p) => self.check_unused_parens_pat(cx, p, true, false, keep_space), // Avoid linting on `&(mut x)` as `&mut x` has a different meaning, #55342. // Also avoid linting on `& mut? (p0 | .. | pn)`, #64106. Ref(p, m) => self.check_unused_parens_pat(cx, p, true, *m == Mutability::Not, keep_space), diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 6506aa33431..9f09f46ea5a 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -79,7 +79,8 @@ declare_lint_pass! { PROC_MACRO_BACK_COMPAT, PROC_MACRO_DERIVE_RESOLUTION_FALLBACK, PUB_USE_OF_PRIVATE_EXTERN_CRATE, - REFINING_IMPL_TRAIT, + REFINING_IMPL_TRAIT_INTERNAL, + REFINING_IMPL_TRAIT_REACHABLE, RENAMED_AND_REMOVED_LINTS, REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS, RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES, @@ -130,6 +131,7 @@ declare_lint_pass! { UNUSED_VARIABLES, USELESS_DEPRECATED, WARNINGS, + WASM_C_ABI, WHERE_CLAUSES_OBJECT_SAFETY, WRITES_THROUGH_IMMUTABLE_POINTER, // tidy-alphabetical-end @@ -4401,8 +4403,10 @@ declare_lint! { } declare_lint! { - /// The `refining_impl_trait` lint detects usages of return-position impl - /// traits in trait signatures which are refined by implementations. + /// The `refining_impl_trait_reachable` lint detects `impl Trait` return + /// types in method signatures that are refined by a publically reachable + /// trait implementation, meaning the implementation adds information about + /// the return type that is not present in the trait. /// /// ### Example /// @@ -4424,7 +4428,7 @@ declare_lint! { /// fn main() { /// // users can observe that the return type of /// // `<&str as AsDisplay>::as_display()` is `&str`. - /// let x: &str = "".as_display(); + /// let _x: &str = "".as_display(); /// } /// ``` /// @@ -4432,13 +4436,80 @@ declare_lint! { /// /// ### Explanation /// - /// Return-position impl trait in traits (RPITITs) desugar to associated types, - /// and callers of methods for types where the implementation is known are + /// Callers of methods for types where the implementation is known are /// able to observe the types written in the impl signature. This may be - /// intended behavior, but may also pose a semver hazard for authors of libraries - /// who do not wish to make stronger guarantees about the types than what is - /// written in the trait signature. - pub REFINING_IMPL_TRAIT, + /// intended behavior, but may also lead to implementation details being + /// revealed unintentionally. In particular, it may pose a semver hazard + /// for authors of libraries who do not wish to make stronger guarantees + /// about the types than what is written in the trait signature. + /// + /// `refining_impl_trait` is a lint group composed of two lints: + /// + /// * `refining_impl_trait_reachable`, for refinements that are publically + /// reachable outside a crate, and + /// * `refining_impl_trait_internal`, for refinements that are only visible + /// within a crate. + /// + /// We are seeking feedback on each of these lints; see issue + /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more + /// information. + pub REFINING_IMPL_TRAIT_REACHABLE, + Warn, + "impl trait in impl method signature does not match trait method signature", +} + +declare_lint! { + /// The `refining_impl_trait_internal` lint detects `impl Trait` return + /// types in method signatures that are refined by a trait implementation, + /// meaning the implementation adds information about the return type that + /// is not present in the trait. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #![deny(refining_impl_trait)] + /// + /// use std::fmt::Display; + /// + /// trait AsDisplay { + /// fn as_display(&self) -> impl Display; + /// } + /// + /// impl<'s> AsDisplay for &'s str { + /// fn as_display(&self) -> Self { + /// *self + /// } + /// } + /// + /// fn main() { + /// // users can observe that the return type of + /// // `<&str as AsDisplay>::as_display()` is `&str`. + /// let _x: &str = "".as_display(); + /// } + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Callers of methods for types where the implementation is known are + /// able to observe the types written in the impl signature. This may be + /// intended behavior, but may also lead to implementation details being + /// revealed unintentionally. In particular, it may pose a semver hazard + /// for authors of libraries who do not wish to make stronger guarantees + /// about the types than what is written in the trait signature. + /// + /// `refining_impl_trait` is a lint group composed of two lints: + /// + /// * `refining_impl_trait_reachable`, for refinements that are publically + /// reachable outside a crate, and + /// * `refining_impl_trait_internal`, for refinements that are only visible + /// within a crate. + /// + /// We are seeking feedback on each of these lints; see issue + /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more + /// information. + pub REFINING_IMPL_TRAIT_INTERNAL, Warn, "impl trait in impl method signature does not match trait method signature", } @@ -4564,3 +4635,41 @@ declare_lint! { reference: "issue #120192 <https://github.com/rust-lang/rust/issues/120192>", }; } + +declare_lint! { + /// The `wasm_c_abi` lint detects crate dependencies that are incompatible + /// with future versions of Rust that will emit spec-compliant C ABI. + /// + /// ### Example + /// + /// ```rust,ignore (needs extern crate) + /// #![deny(wasm_c_abi)] + /// ``` + /// + /// This will produce: + /// + /// ```text + /// error: the following packages contain code that will be rejected by a future version of Rust: wasm-bindgen v0.2.87 + /// | + /// note: the lint level is defined here + /// --> src/lib.rs:1:9 + /// | + /// 1 | #![deny(wasm_c_abi)] + /// | ^^^^^^^^^^ + /// ``` + /// + /// ### Explanation + /// + /// Rust has historically emitted non-spec-compliant C ABI. This has caused + /// incompatibilities between other compilers and Wasm targets. In a future + /// version of Rust this will be fixed and therefore dependencies relying + /// on the non-spec-compliant C ABI will stop functioning. + pub WASM_C_ABI, + Warn, + "detects dependencies that are incompatible with the Wasm C ABI", + @future_incompatible = FutureIncompatibleInfo { + reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps, + reference: "issue #71871 <https://github.com/rust-lang/rust/issues/71871>", + }; + crate_level_only +} diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index f6253068eaa..067374c0261 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -24,9 +24,7 @@ #include "llvm/Passes/StandardInstrumentations.h" #include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/FileSystem.h" -#if LLVM_VERSION_GE(17, 0) #include "llvm/Support/VirtualFileSystem.h" -#endif #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/IPO/AlwaysInliner.h" #include "llvm/Transforms/IPO/FunctionImport.h" @@ -334,14 +332,8 @@ extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM, std::ostringstream Buf; -#if LLVM_VERSION_GE(17, 0) const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo(); const ArrayRef<SubtargetSubTypeKV> CPUTable = MCInfo->getAllProcessorDescriptions(); -#else - Buf << "Full target CPU help is not supported by this LLVM version.\n\n"; - SubtargetSubTypeKV TargetCPUKV = { TargetCPU, {{}}, {{}} }; - const ArrayRef<SubtargetSubTypeKV> CPUTable = TargetCPUKV; -#endif unsigned MaxCPULen = getLongestEntryLength(CPUTable); Buf << "Available CPUs for this target:\n"; @@ -476,10 +468,6 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( Options.RelaxELFRelocations = RelaxELFRelocations; #endif Options.UseInitArray = UseInitArray; - -#if LLVM_VERSION_LT(17, 0) - Options.ExplicitEmulatedTLS = true; -#endif Options.EmulatedTLS = UseEmulatedTls; if (TrapUnreachable) { @@ -761,16 +749,10 @@ LLVMRustOptimize( } std::optional<PGOOptions> PGOOpt; -#if LLVM_VERSION_GE(17, 0) auto FS = vfs::getRealFileSystem(); -#endif if (PGOGenPath) { assert(!PGOUsePath && !PGOSampleUsePath); - PGOOpt = PGOOptions(PGOGenPath, "", "", -#if LLVM_VERSION_GE(17, 0) - "", - FS, -#endif + PGOOpt = PGOOptions(PGOGenPath, "", "", "", FS, PGOOptions::IRInstr, PGOOptions::NoCSAction, #if LLVM_VERSION_GE(19, 0) PGOOptions::ColdFuncOpt::Default, @@ -778,33 +760,21 @@ LLVMRustOptimize( DebugInfoForProfiling); } else if (PGOUsePath) { assert(!PGOSampleUsePath); - PGOOpt = PGOOptions(PGOUsePath, "", "", -#if LLVM_VERSION_GE(17, 0) - "", - FS, -#endif + PGOOpt = PGOOptions(PGOUsePath, "", "", "", FS, PGOOptions::IRUse, PGOOptions::NoCSAction, #if LLVM_VERSION_GE(19, 0) PGOOptions::ColdFuncOpt::Default, #endif DebugInfoForProfiling); } else if (PGOSampleUsePath) { - PGOOpt = PGOOptions(PGOSampleUsePath, "", "", -#if LLVM_VERSION_GE(17, 0) - "", - FS, -#endif + PGOOpt = PGOOptions(PGOSampleUsePath, "", "", "", FS, PGOOptions::SampleUse, PGOOptions::NoCSAction, #if LLVM_VERSION_GE(19, 0) PGOOptions::ColdFuncOpt::Default, #endif DebugInfoForProfiling); } else if (DebugInfoForProfiling) { - PGOOpt = PGOOptions("", "", "", -#if LLVM_VERSION_GE(17, 0) - "", - FS, -#endif + PGOOpt = PGOOptions("", "", "", "", FS, PGOOptions::NoAction, PGOOptions::NoCSAction, #if LLVM_VERSION_GE(19, 0) PGOOptions::ColdFuncOpt::Default, @@ -1353,9 +1323,7 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules, ComputeCrossModuleImport( Ret->Index, Ret->ModuleToDefinedGVSummaries, -#if LLVM_VERSION_GE(17, 0) isPrevailing, -#endif Ret->ImportLists, Ret->ExportLists ); diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 1632b9e1249..f6ec410bfac 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -25,6 +25,13 @@ #include <iostream> +// for raw `write` in the bad-alloc handler +#ifdef _MSC_VER +#include <io.h> +#else +#include <unistd.h> +#endif + //===----------------------------------------------------------------------=== // // This file defines alternate interfaces to core functions that are more @@ -88,8 +95,24 @@ static void FatalErrorHandler(void *UserData, exit(101); } -extern "C" void LLVMRustInstallFatalErrorHandler() { +// Custom error handler for bad-alloc LLVM errors. +// +// It aborts the process without any further allocations, similar to LLVM's +// default except that may be configured to `throw std::bad_alloc()` instead. +static void BadAllocErrorHandler(void *UserData, + const char* Reason, + bool GenCrashDiag) { + const char *OOM = "rustc-LLVM ERROR: out of memory\n"; + (void)!::write(2, OOM, strlen(OOM)); + (void)!::write(2, Reason, strlen(Reason)); + (void)!::write(2, "\n", 1); + abort(); +} + +extern "C" void LLVMRustInstallErrorHandlers() { + install_bad_alloc_error_handler(BadAllocErrorHandler); install_fatal_error_handler(FatalErrorHandler); + install_out_of_memory_new_handler(); } extern "C" void LLVMRustDisableSystemDialogsOnCrash() { @@ -2129,19 +2152,3 @@ extern "C" LLVMValueRef LLVMConstStringInContext2(LLVMContextRef C, return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length), !DontNullTerminate)); } #endif - -// FIXME: Remove when Rust's minimum supported LLVM version reaches 17. -// https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc -#if LLVM_VERSION_LT(17, 0) -extern "C" LLVMValueRef LLVMConstArray2(LLVMTypeRef ElementTy, - LLVMValueRef *ConstantVals, - uint64_t Length) { - ArrayRef<Constant *> V(unwrap<Constant>(ConstantVals, Length), Length); - return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V)); -} - -extern "C" LLVMTypeRef LLVMArrayType2(LLVMTypeRef ElementTy, - uint64_t ElementCount) { - return wrap(ArrayType::get(unwrap(ElementTy), ElementCount)); -} -#endif diff --git a/compiler/rustc_metadata/messages.ftl b/compiler/rustc_metadata/messages.ftl index a1c6fba4d43..3d0846ae6de 100644 --- a/compiler/rustc_metadata/messages.ftl +++ b/compiler/rustc_metadata/messages.ftl @@ -38,6 +38,9 @@ metadata_crate_dep_multiple = cannot satisfy dependencies so `{$crate_name}` only shows up once .help = having upstream crates all available in one format will likely make this go away +metadata_crate_dep_not_static = + `{$crate_name}` was unavailable as a static crate, preventing fully static linking + metadata_crate_location_unknown_type = extern location for {$crate_name} is of an unknown type: {$path} @@ -281,6 +284,8 @@ metadata_unsupported_abi = metadata_unsupported_abi_i686 = ABI not supported by `#[link(kind = "raw-dylib")]` on i686 +metadata_wasm_c_abi = + older versions of the `wasm-bindgen` crate will be incompatible with future versions of Rust; please update to `wasm-bindgen` v0.2.88 metadata_wasm_import_form = wasm import module must be of the form `wasm_import_module = "string"` diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 72757d90e42..b544bc8a782 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -31,8 +31,9 @@ use proc_macro::bridge::client::ProcMacro; use std::error::Error; use std::ops::Fn; use std::path::Path; +use std::str::FromStr; use std::time::Duration; -use std::{cmp, iter}; +use std::{cmp, env, iter}; /// The backend's way to give the crate store access to the metadata in a library. /// Note that it returns the raw metadata bytes stored in the library file, whether @@ -397,7 +398,8 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { name: Symbol, private_dep: Option<bool>, ) -> Result<CrateNum, CrateError> { - let _prof_timer = self.sess.prof.generic_activity("metadata_register_crate"); + let _prof_timer = + self.sess.prof.generic_activity_with_arg("metadata_register_crate", name.as_str()); let Library { source, metadata } = lib; let crate_root = metadata.get_root(); @@ -985,6 +987,44 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { } } + fn report_future_incompatible_deps(&self, krate: &ast::Crate) { + let name = self.tcx.crate_name(LOCAL_CRATE); + + if name.as_str() == "wasm_bindgen" { + let major = env::var("CARGO_PKG_VERSION_MAJOR") + .ok() + .and_then(|major| u64::from_str(&major).ok()); + let minor = env::var("CARGO_PKG_VERSION_MINOR") + .ok() + .and_then(|minor| u64::from_str(&minor).ok()); + let patch = env::var("CARGO_PKG_VERSION_PATCH") + .ok() + .and_then(|patch| u64::from_str(&patch).ok()); + + match (major, minor, patch) { + // v1 or bigger is valid. + (Some(1..), _, _) => return, + // v0.3 or bigger is valid. + (Some(0), Some(3..), _) => return, + // v0.2.88 or bigger is valid. + (Some(0), Some(2), Some(88..)) => return, + // Not using Cargo. + (None, None, None) => return, + _ => (), + } + + // Make a point span rather than covering the whole file + let span = krate.spans.inner_span.shrink_to_lo(); + + self.sess.psess.buffer_lint( + lint::builtin::WASM_C_ABI, + span, + ast::CRATE_NODE_ID, + crate::fluent_generated::metadata_wasm_c_abi, + ); + } + } + pub fn postprocess(&mut self, krate: &ast::Crate) { self.inject_forced_externs(); self.inject_profiler_runtime(krate); @@ -992,6 +1032,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { self.inject_panic_runtime(krate); self.report_unused_deps(krate); + self.report_future_incompatible_deps(krate); info!("{:?}", CrateDump(self.cstore)); } diff --git a/compiler/rustc_metadata/src/dependency_format.rs b/compiler/rustc_metadata/src/dependency_format.rs index b80a9e9612a..4d1bd455412 100644 --- a/compiler/rustc_metadata/src/dependency_format.rs +++ b/compiler/rustc_metadata/src/dependency_format.rs @@ -54,7 +54,7 @@ use crate::creader::CStore; use crate::errors::{ BadPanicStrategy, CrateDepMultiple, IncompatiblePanicInDropStrategy, LibRequired, - RequiredPanicStrategy, RlibRequired, RustcLibRequired, TwoPanicRuntimes, + NonStaticCrateDep, RequiredPanicStrategy, RlibRequired, RustcLibRequired, TwoPanicRuntimes, }; use rustc_data_structures::fx::FxHashMap; @@ -123,13 +123,15 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList { CrateType::Rlib => Linkage::NotLinked, }; + let mut unavailable_as_static = Vec::new(); + match preferred_linkage { // If the crate is not linked, there are no link-time dependencies. Linkage::NotLinked => return Vec::new(), Linkage::Static => { // Attempt static linkage first. For dylibs and executables, we may be // able to retry below with dynamic linkage. - if let Some(v) = attempt_static(tcx) { + if let Some(v) = attempt_static(tcx, &mut unavailable_as_static) { return v; } @@ -169,11 +171,11 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList { let src = tcx.used_crate_source(cnum); if src.dylib.is_some() { info!("adding dylib: {}", name); - add_library(tcx, cnum, RequireDynamic, &mut formats); + add_library(tcx, cnum, RequireDynamic, &mut formats, &mut unavailable_as_static); let deps = tcx.dylib_dependency_formats(cnum); for &(depnum, style) in deps.iter() { info!("adding {:?}: {}", style, tcx.crate_name(depnum)); - add_library(tcx, depnum, style, &mut formats); + add_library(tcx, depnum, style, &mut formats, &mut unavailable_as_static); } } } @@ -201,7 +203,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList { { assert!(src.rlib.is_some() || src.rmeta.is_some()); info!("adding staticlib: {}", tcx.crate_name(cnum)); - add_library(tcx, cnum, RequireStatic, &mut formats); + add_library(tcx, cnum, RequireStatic, &mut formats, &mut unavailable_as_static); ret[cnum.as_usize() - 1] = Linkage::Static; } } @@ -252,6 +254,7 @@ fn add_library( cnum: CrateNum, link: LinkagePreference, m: &mut FxHashMap<CrateNum, LinkagePreference>, + unavailable_as_static: &mut Vec<CrateNum>, ) { match m.get(&cnum) { Some(&link2) => { @@ -263,7 +266,13 @@ fn add_library( // This error is probably a little obscure, but I imagine that it // can be refined over time. if link2 != link || link == RequireStatic { - tcx.dcx().emit_err(CrateDepMultiple { crate_name: tcx.crate_name(cnum) }); + tcx.dcx().emit_err(CrateDepMultiple { + crate_name: tcx.crate_name(cnum), + non_static_deps: unavailable_as_static + .drain(..) + .map(|cnum| NonStaticCrateDep { crate_name: tcx.crate_name(cnum) }) + .collect(), + }); } } None => { @@ -272,7 +281,7 @@ fn add_library( } } -fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> { +fn attempt_static(tcx: TyCtxt<'_>, unavailable: &mut Vec<CrateNum>) -> Option<DependencyList> { let all_crates_available_as_rlib = tcx .crates(()) .iter() @@ -281,7 +290,11 @@ fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> { if tcx.dep_kind(cnum).macros_only() { return None; } - Some(tcx.used_crate_source(cnum).rlib.is_some()) + let is_rlib = tcx.used_crate_source(cnum).rlib.is_some(); + if !is_rlib { + unavailable.push(cnum); + } + Some(is_rlib) }) .all(|is_rlib| is_rlib); if !all_crates_available_as_rlib { diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 8bf6b665de8..b50ae057709 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -38,6 +38,14 @@ pub struct RustcLibRequired<'a> { #[help] pub struct CrateDepMultiple { pub crate_name: Symbol, + #[subdiagnostic] + pub non_static_deps: Vec<NonStaticCrateDep>, +} + +#[derive(Subdiagnostic)] +#[note(metadata_crate_dep_not_static)] +pub struct NonStaticCrateDep { + pub crate_name: Symbol, } #[derive(Diagnostic)] diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 0467cf2969f..596da58b091 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1063,6 +1063,20 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { ty::EarlyBinder::bind(&*output) } + fn get_explicit_item_super_predicates( + self, + index: DefIndex, + tcx: TyCtxt<'tcx>, + ) -> ty::EarlyBinder<&'tcx [(ty::Clause<'tcx>, Span)]> { + let lazy = self.root.tables.explicit_item_super_predicates.get(self, index); + let output = if lazy.is_default() { + &mut [] + } else { + tcx.arena.alloc_from_iter(lazy.decode((self, tcx))) + }; + ty::EarlyBinder::bind(&*output) + } + fn get_variant( self, kind: DefKind, @@ -1590,17 +1604,17 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { }) } - // Translate the virtual `/rustc/$hash` prefix back to a real directory - // that should hold actual sources, where possible. - // - // NOTE: if you update this, you might need to also update bootstrap's code for generating - // the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`. - let virtual_rust_source_base_dir = [ - filter(sess, option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(Path::new)), - filter(sess, sess.opts.unstable_opts.simulate_remapped_rust_src_base.as_deref()), - ]; - let try_to_translate_virtual_to_real = |name: &mut rustc_span::FileName| { + // Translate the virtual `/rustc/$hash` prefix back to a real directory + // that should hold actual sources, where possible. + // + // NOTE: if you update this, you might need to also update bootstrap's code for generating + // the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`. + let virtual_rust_source_base_dir = [ + filter(sess, option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(Path::new)), + filter(sess, sess.opts.unstable_opts.simulate_remapped_rust_src_base.as_deref()), + ]; + debug!( "try_to_translate_virtual_to_real(name={:?}): \ virtual_rust_source_base_dir={:?}, real_rust_source_base_dir={:?}", diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 1c59af51589..1aabd296641 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -206,6 +206,7 @@ impl IntoArgs for (CrateNum, SimplifiedType) { provide! { tcx, def_id, other, cdata, explicit_item_bounds => { cdata.get_explicit_item_bounds(def_id.index, tcx) } + explicit_item_super_predicates => { cdata.get_explicit_item_super_predicates(def_id.index, tcx) } explicit_predicates_of => { table } generics_of => { table } inferred_outlives_of => { table_defaulted_array } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index d8cfceab460..42724f7dd2b 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -817,8 +817,8 @@ struct AnalyzeAttrState { #[inline] fn analyze_attr(attr: &Attribute, state: &mut AnalyzeAttrState) -> bool { let mut should_encode = false; - if rustc_feature::is_builtin_only_local(attr.name_or_empty()) { - // Attributes marked local-only don't need to be encoded for downstream crates. + if !rustc_feature::encode_cross_crate(attr.name_or_empty()) { + // Attributes not marked encode-cross-crate don't need to be encoded for downstream crates. } else if attr.doc_str().is_some() { // We keep all doc comments reachable to rustdoc because they might be "imported" into // downstream crates if they use `#[doc(inline)]` to copy an item's documentation into @@ -1067,14 +1067,11 @@ fn should_encode_mir( // Full-fledged functions + closures DefKind::AssocFn | DefKind::Fn | DefKind::Closure => { let generics = tcx.generics_of(def_id); - let mut opt = tcx.sess.opts.unstable_opts.always_encode_mir + let opt = tcx.sess.opts.unstable_opts.always_encode_mir || (tcx.sess.opts.output_types.should_codegen() && reachable_set.contains(&def_id) && (generics.requires_monomorphization(tcx) || tcx.cross_crate_inlinable(def_id))); - if let Some(intrinsic) = tcx.intrinsic(def_id) { - opt &= !intrinsic.must_be_overridden; - } // The function has a `const` modifier or is in a `#[const_trait]`. let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id()) || tcx.is_const_default_method(def_id.to_def_id()); @@ -1494,6 +1491,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } if let DefKind::OpaqueTy = def_kind { self.encode_explicit_item_bounds(def_id); + self.encode_explicit_item_super_predicates(def_id); self.tables .is_type_alias_impl_trait .set(def_id.index, self.tcx.is_type_alias_impl_trait(def_id)); @@ -1602,6 +1600,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { record_defaulted_array!(self.tables.explicit_item_bounds[def_id] <- bounds); } + fn encode_explicit_item_super_predicates(&mut self, def_id: DefId) { + debug!("EncodeContext::encode_explicit_item_super_predicates({:?})", def_id); + let bounds = self.tcx.explicit_item_super_predicates(def_id).skip_binder(); + record_defaulted_array!(self.tables.explicit_item_super_predicates[def_id] <- bounds); + } + #[instrument(level = "debug", skip(self))] fn encode_info_for_assoc_item(&mut self, def_id: DefId) { let tcx = self.tcx; @@ -1614,6 +1618,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { AssocItemContainer::TraitContainer => { if let ty::AssocKind::Type = item.kind { self.encode_explicit_item_bounds(def_id); + self.encode_explicit_item_super_predicates(def_id); } } AssocItemContainer::ImplContainer => { @@ -2201,7 +2206,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata { let mmap = if len > 0 { let mut mmap = MmapMut::map_anon(len).unwrap(); for _ in 0..len { - (&mut mmap[..]).write(&[d.read_u8()]).unwrap(); + (&mut mmap[..]).write_all(&[d.read_u8()]).unwrap(); } mmap.flush().unwrap(); Some(mmap.make_read_only().unwrap()) diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 8aa31ef564f..5b0be8ac230 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -387,6 +387,7 @@ define_tables! { // corresponding DefPathHash. def_path_hashes: Table<DefIndex, u64>, explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>, + explicit_item_super_predicates: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>, inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>, inherent_impls: Table<DefIndex, LazyArray<DefIndex>>, associated_types_for_impl_traits_in_associated_fn: Table<DefIndex, LazyArray<DefId>>, diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index 96c58ef411b..9e8ee92b5d9 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start bitflags = "2.4.1" +derivative = "2.2.0" either = "1.5.0" field-offset = "0.3.5" gsgdt = "0.1.2" diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 5043bd855cc..a1bcee84d4c 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -20,44 +20,6 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{ErrorGuaranteed, Span}; use rustc_target::spec::abi::Abi; -#[inline] -pub fn associated_body(node: Node<'_>) -> Option<(LocalDefId, BodyId)> { - match node { - Node::Item(Item { - owner_id, - kind: ItemKind::Const(_, _, body) | ItemKind::Static(.., body) | ItemKind::Fn(.., body), - .. - }) - | Node::TraitItem(TraitItem { - owner_id, - kind: - TraitItemKind::Const(_, Some(body)) | TraitItemKind::Fn(_, TraitFn::Provided(body)), - .. - }) - | Node::ImplItem(ImplItem { - owner_id, - kind: ImplItemKind::Const(_, body) | ImplItemKind::Fn(_, body), - .. - }) => Some((owner_id.def_id, *body)), - - Node::Expr(Expr { kind: ExprKind::Closure(Closure { def_id, body, .. }), .. }) => { - Some((*def_id, *body)) - } - - Node::AnonConst(constant) => Some((constant.def_id, constant.body)), - Node::ConstBlock(constant) => Some((constant.def_id, constant.body)), - - _ => None, - } -} - -fn is_body_owner(node: Node<'_>, hir_id: HirId) -> bool { - match associated_body(node) { - Some((_, b)) => b.hir_id == hir_id, - None => false, - } -} - // FIXME: the structure was necessary in the past but now it // only serves as "namespace" for HIR-related methods, and can be // removed if all the methods are reasonably renamed and moved to tcx @@ -114,20 +76,16 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> { if self.current_id == CRATE_HIR_ID { return None; } - loop { - // There are nodes that do not have entries, so we need to skip them. - let parent_id = self.map.def_key(self.current_id.owner.def_id).parent; - let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| { - let def_id = LocalDefId { local_def_index }; - self.map.tcx.local_def_id_to_hir_id(def_id).owner - }); - self.current_id = HirId::make_owner(parent_id.def_id); + let parent_id = self.map.def_key(self.current_id.owner.def_id).parent; + let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| { + let def_id = LocalDefId { local_def_index }; + self.map.tcx.local_def_id_to_hir_id(def_id).owner + }); + self.current_id = HirId::make_owner(parent_id.def_id); - // If this `HirId` doesn't have an entry, skip it and look for its `parent_id`. - let node = self.map.tcx.hir_owner_node(self.current_id.owner); - return Some((self.current_id.owner, node)); - } + let node = self.map.tcx.hir_owner_node(self.current_id.owner); + return Some((self.current_id.owner, node)); } } @@ -208,12 +166,12 @@ impl<'hir> Map<'hir> { #[inline] pub fn items(self) -> impl Iterator<Item = ItemId> + 'hir { - self.tcx.hir_crate_items(()).items.iter().copied() + self.tcx.hir_crate_items(()).free_items.iter().copied() } #[inline] pub fn module_items(self, module: LocalModDefId) -> impl Iterator<Item = ItemId> + 'hir { - self.tcx.hir_module_items(module).items() + self.tcx.hir_module_items(module).free_items() } pub fn def_key(self, def_id: LocalDefId) -> DefKey { @@ -273,7 +231,7 @@ impl<'hir> Map<'hir> { #[track_caller] pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId { for (_, node) in self.parent_iter(hir_id) { - if let Some((def_id, _)) = associated_body(node) { + if let Some((def_id, _)) = node.associated_body() { return def_id; } } @@ -286,20 +244,18 @@ impl<'hir> Map<'hir> { /// item (possibly associated), a closure, or a `hir::AnonConst`. pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId { let parent = self.tcx.parent_hir_id(hir_id); - assert!(is_body_owner(self.tcx.hir_node(parent), hir_id), "{hir_id:?}"); + assert_eq!(self.tcx.hir_node(parent).body_id().unwrap().hir_id, hir_id, "{hir_id:?}"); parent } pub fn body_owner_def_id(self, BodyId { hir_id }: BodyId) -> LocalDefId { - associated_body(self.tcx.parent_hir_node(hir_id)).unwrap().0 + self.tcx.parent_hir_node(hir_id).associated_body().unwrap().0 } /// Given a `LocalDefId`, returns the `BodyId` associated with it, /// if the node is a body owner, otherwise returns `None`. pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId> { - let node = self.tcx.hir_node_by_def_id(id); - let (_, body_id) = associated_body(node)?; - Some(body_id) + self.tcx.hir_node_by_def_id(id).body_id() } /// Given a body owner's id, returns the `BodyId` associated with it. @@ -462,7 +418,7 @@ impl<'hir> Map<'hir> { V: Visitor<'hir>, { let krate = self.tcx.hir_crate_items(()); - walk_list!(visitor, visit_item, krate.items().map(|id| self.item(id))); + walk_list!(visitor, visit_item, krate.free_items().map(|id| self.item(id))); walk_list!(visitor, visit_trait_item, krate.trait_items().map(|id| self.trait_item(id))); walk_list!(visitor, visit_impl_item, krate.impl_items().map(|id| self.impl_item(id))); walk_list!( @@ -480,7 +436,7 @@ impl<'hir> Map<'hir> { V: Visitor<'hir>, { let module = self.tcx.hir_module_items(module); - walk_list!(visitor, visit_item, module.items().map(|id| self.item(id))); + walk_list!(visitor, visit_item, module.free_items().map(|id| self.item(id))); walk_list!(visitor, visit_trait_item, module.trait_items().map(|id| self.trait_item(id))); walk_list!(visitor, visit_impl_item, module.impl_items().map(|id| self.impl_item(id))); walk_list!( @@ -954,7 +910,7 @@ impl<'hir> Map<'hir> { Node::Crate(item) => item.spans.inner_span, Node::WhereBoundPredicate(pred) => pred.span, Node::ArrayLenInfer(inf) => inf.span, - Node::AssocOpaqueTy(..) => unreachable!(), + Node::Synthetic => unreachable!(), Node::Err(span) => *span, } } @@ -1219,7 +1175,7 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String { Node::Crate(..) => String::from("(root_crate)"), Node::WhereBoundPredicate(_) => node_str("where bound predicate"), Node::ArrayLenInfer(_) => node_str("array len infer"), - Node::AssocOpaqueTy(..) => unreachable!(), + Node::Synthetic => unreachable!(), Node::Err(_) => node_str("error"), } } @@ -1241,7 +1197,7 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod } = collector; return ModuleItems { submodules: submodules.into_boxed_slice(), - items: items.into_boxed_slice(), + free_items: items.into_boxed_slice(), trait_items: trait_items.into_boxed_slice(), impl_items: impl_items.into_boxed_slice(), foreign_items: foreign_items.into_boxed_slice(), @@ -1270,7 +1226,7 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems { return ModuleItems { submodules: submodules.into_boxed_slice(), - items: items.into_boxed_slice(), + free_items: items.into_boxed_slice(), trait_items: trait_items.into_boxed_slice(), impl_items: impl_items.into_boxed_slice(), foreign_items: foreign_items.into_boxed_slice(), @@ -1314,7 +1270,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> { } fn visit_item(&mut self, item: &'hir Item<'hir>) { - if associated_body(Node::Item(item)).is_some() { + if Node::Item(item).associated_body().is_some() { self.body_owners.push(item.owner_id.def_id); } @@ -1355,7 +1311,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> { } fn visit_trait_item(&mut self, item: &'hir TraitItem<'hir>) { - if associated_body(Node::TraitItem(item)).is_some() { + if Node::TraitItem(item).associated_body().is_some() { self.body_owners.push(item.owner_id.def_id); } @@ -1364,7 +1320,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> { } fn visit_impl_item(&mut self, item: &'hir ImplItem<'hir>) { - if associated_body(Node::ImplItem(item)).is_some() { + if Node::ImplItem(item).associated_body().is_some() { self.body_owners.push(item.owner_id.def_id); } diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index f9fa8ac2f7a..28f7574f66f 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -22,7 +22,7 @@ use rustc_span::{ErrorGuaranteed, ExpnId}; #[derive(Debug, HashStable, Encodable, Decodable)] pub struct ModuleItems { submodules: Box<[OwnerId]>, - items: Box<[ItemId]>, + free_items: Box<[ItemId]>, trait_items: Box<[TraitItemId]>, impl_items: Box<[ImplItemId]>, foreign_items: Box<[ForeignItemId]>, @@ -30,14 +30,22 @@ pub struct ModuleItems { } impl ModuleItems { - pub fn items(&self) -> impl Iterator<Item = ItemId> + '_ { - self.items.iter().copied() + /// Returns all non-associated locally defined items in all modules. + /// + /// Note that this does *not* include associated items of `impl` blocks! It also does not + /// include foreign items. If you want to e.g. get all functions, use `definitions()` below. + /// + /// However, this does include the `impl` blocks themselves. + pub fn free_items(&self) -> impl Iterator<Item = ItemId> + '_ { + self.free_items.iter().copied() } pub fn trait_items(&self) -> impl Iterator<Item = TraitItemId> + '_ { self.trait_items.iter().copied() } + /// Returns all items that are associated with some `impl` block (both inherent and trait impl + /// blocks). pub fn impl_items(&self) -> impl Iterator<Item = ImplItemId> + '_ { self.impl_items.iter().copied() } @@ -47,7 +55,7 @@ impl ModuleItems { } pub fn owners(&self) -> impl Iterator<Item = OwnerId> + '_ { - self.items + self.free_items .iter() .map(|id| id.owner_id) .chain(self.trait_items.iter().map(|id| id.owner_id)) @@ -63,7 +71,7 @@ impl ModuleItems { &self, f: impl Fn(ItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync, ) -> Result<(), ErrorGuaranteed> { - try_par_for_each_in(&self.items[..], |&id| f(id)) + try_par_for_each_in(&self.free_items[..], |&id| f(id)) } pub fn par_trait_items( diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index c3e4a03ad16..e52a5863fd0 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -24,13 +24,13 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(rust_logo)] -#![cfg_attr(bootstrap, feature(exhaustive_patterns))] -#![cfg_attr(not(bootstrap), feature(min_exhaustive_patterns))] +#![feature(min_exhaustive_patterns)] #![feature(rustdoc_internals)] #![feature(allocator_api)] #![feature(array_windows)] #![feature(assert_matches)] #![feature(box_patterns)] +#![feature(closure_track_caller)] #![feature(core_intrinsics)] #![feature(const_type_name)] #![feature(discriminant_kind)] @@ -48,7 +48,7 @@ #![feature(trusted_len)] #![feature(type_alias_impl_trait)] #![feature(strict_provenance)] -#![feature(associated_type_bounds)] +#![cfg_attr(bootstrap, feature(associated_type_bounds))] #![feature(rustc_attrs)] #![feature(control_flow_enum)] #![feature(trait_upcasting)] diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index d8d6899f057..8d9e0dfd869 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -398,8 +398,22 @@ pub fn lint_level( } } - // Finally, run `decorate`. - decorate(&mut err); + // Finally, run `decorate`. `decorate` can call `trimmed_path_str` (directly or indirectly), + // so we need to make sure when we do call `decorate` that the diagnostic is eventually + // emitted or we'll get a `must_produce_diag` ICE. + // + // When is a diagnostic *eventually* emitted? Well, that is determined by 2 factors: + // 1. If the corresponding `rustc_errors::Level` is beyond warning, i.e. `ForceWarning(_)` + // or `Error`, then the diagnostic will be emitted regardless of CLI options. + // 2. If the corresponding `rustc_errors::Level` is warning, then that can be affected by + // `-A warnings` or `--cap-lints=xxx` on the command line. In which case, the diagnostic + // will be emitted if `can_emit_warnings` is true. + let skip = err_level == rustc_errors::Level::Warning && !sess.dcx().can_emit_warnings(); + + if !skip { + decorate(&mut err); + } + explain_lint_level_source(lint, level, src, &mut err); err.emit() } diff --git a/compiler/rustc_middle/src/macros.rs b/compiler/rustc_middle/src/macros.rs index 0ee97a6bed0..f70ef51107f 100644 --- a/compiler/rustc_middle/src/macros.rs +++ b/compiler/rustc_middle/src/macros.rs @@ -11,12 +11,18 @@ /// [`span_bug`]: crate::span_bug #[macro_export] macro_rules! bug { - () => ( $crate::bug!("impossible case reached") ); - ($msg:expr) => ({ $crate::util::bug::bug_fmt(::std::format_args!($msg)) }); - ($msg:expr,) => ({ $crate::bug!($msg) }); - ($fmt:expr, $($arg:tt)+) => ({ + () => ( + $crate::bug!("impossible case reached") + ); + ($msg:expr) => ( + $crate::util::bug::bug_fmt(::std::format_args!($msg)) + ); + ($msg:expr,) => ( + $crate::bug!($msg) + ); + ($fmt:expr, $($arg:tt)+) => ( $crate::util::bug::bug_fmt(::std::format_args!($fmt, $($arg)+)) - }); + ); } /// A macro for triggering an ICE with a span. @@ -30,11 +36,15 @@ macro_rules! bug { /// [`DiagCtxt::span_delayed_bug`]: rustc_errors::DiagCtxt::span_delayed_bug #[macro_export] macro_rules! span_bug { - ($span:expr, $msg:expr) => ({ $crate::util::bug::span_bug_fmt($span, ::std::format_args!($msg)) }); - ($span:expr, $msg:expr,) => ({ $crate::span_bug!($span, $msg) }); - ($span:expr, $fmt:expr, $($arg:tt)+) => ({ + ($span:expr, $msg:expr) => ( + $crate::util::bug::span_bug_fmt($span, ::std::format_args!($msg)) + ); + ($span:expr, $msg:expr,) => ( + $crate::span_bug!($span, $msg) + ); + ($span:expr, $fmt:expr, $($arg:tt)+) => ( $crate::util::bug::span_bug_fmt($span, ::std::format_args!($fmt, $($arg)+)) - }); + ); } /////////////////////////////////////////////////////////////////////////// diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index 5feee3c3ba1..02185cbeacf 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -2,7 +2,7 @@ use std::fmt::{self, Debug, Display, Formatter}; use rustc_hir::def_id::DefId; use rustc_session::RemapFileNameExt; -use rustc_span::Span; +use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::{HasDataLayout, Size}; use crate::mir::interpret::{alloc_range, AllocId, ConstAllocation, ErrorHandled, Scalar}; @@ -273,7 +273,7 @@ impl<'tcx> Const<'tcx> { self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, - span: Option<Span>, + span: Span, ) -> Result<ConstValue<'tcx>, ErrorHandled> { match self { Const::Ty(c) => { @@ -293,7 +293,7 @@ impl<'tcx> Const<'tcx> { /// Normalizes the constant to a value or an error if possible. #[inline] pub fn normalize(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self { - match self.eval(tcx, param_env, None) { + match self.eval(tcx, param_env, DUMMY_SP) { Ok(val) => Self::Val(val, self.ty()), Err(ErrorHandled::Reported(guar, _span)) => { Self::Ty(ty::Const::new_error(tcx, guar.into(), self.ty())) @@ -313,10 +313,10 @@ impl<'tcx> Const<'tcx> { // Avoid the `valtree_to_const_val` query. Can only be done on primitive types that // are valtree leaves, and *not* on references. (References should return the // pointer here, which valtrees don't represent.) - let val = c.eval(tcx, param_env, None).ok()?; + let val = c.eval(tcx, param_env, DUMMY_SP).ok()?; Some(val.unwrap_leaf().into()) } - _ => self.eval(tcx, param_env, None).ok()?.try_to_scalar(), + _ => self.eval(tcx, param_env, DUMMY_SP).ok()?.try_to_scalar(), } } @@ -456,7 +456,7 @@ impl<'tcx> Const<'tcx> { } /// An unevaluated (potentially generic) constant used in MIR. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable)] #[derive(Hash, HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct UnevaluatedConst<'tcx> { pub def: DefId, diff --git a/compiler/rustc_middle/src/mir/coverage.rs b/compiler/rustc_middle/src/mir/coverage.rs index 645a417c322..588aa1f40d7 100644 --- a/compiler/rustc_middle/src/mir/coverage.rs +++ b/compiler/rustc_middle/src/mir/coverage.rs @@ -88,14 +88,13 @@ pub enum CoverageKind { /// Marks a span that might otherwise not be represented in MIR, so that /// coverage instrumentation can associate it with its enclosing block/BCB. /// - /// Only used by the `InstrumentCoverage` pass, and has no effect during - /// codegen. + /// Should be erased before codegen (at some point after `InstrumentCoverage`). SpanMarker, /// Marks its enclosing basic block with an ID that can be referred to by /// side data in [`BranchInfo`]. /// - /// Has no effect during codegen. + /// Should be erased before codegen (at some point after `InstrumentCoverage`). BlockMarker { id: BlockMarkerId }, /// Marks the point in MIR control flow represented by a coverage counter. diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 4047891d769..00faa211853 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -37,9 +37,16 @@ pub trait AllocBytes: /// Create a zeroed `AllocBytes` of the specified size and alignment. /// Returns `None` if we ran out of memory on the host. fn zeroed(size: Size, _align: Align) -> Option<Self>; + + /// Gives direct access to the raw underlying storage. + /// + /// Crucially this pointer is compatible with: + /// - other pointers retunred by this method, and + /// - references returned from `deref()`, as long as there was no write. + fn as_mut_ptr(&mut self) -> *mut u8; } -// Default `bytes` for `Allocation` is a `Box<[u8]>`. +/// Default `bytes` for `Allocation` is a `Box<u8>`. impl AllocBytes for Box<[u8]> { fn from_bytes<'a>(slice: impl Into<Cow<'a, [u8]>>, _align: Align) -> Self { Box::<[u8]>::from(slice.into()) @@ -51,6 +58,11 @@ impl AllocBytes for Box<[u8]> { let bytes = unsafe { bytes.assume_init() }; Some(bytes) } + + fn as_mut_ptr(&mut self) -> *mut u8 { + // Carefully avoiding any intermediate references. + ptr::addr_of_mut!(**self).cast() + } } /// This type represents an Allocation in the Miri/CTFE core engine. @@ -399,10 +411,6 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes> /// Byte accessors. impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes> { - pub fn base_addr(&self) -> *const u8 { - self.bytes.as_ptr() - } - /// This is the entirely abstraction-violating way to just grab the raw bytes without /// caring about provenance or initialization. /// @@ -452,13 +460,14 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes> Ok(self.get_bytes_unchecked(range)) } - /// Just calling this already marks everything as defined and removes provenance, - /// so be sure to actually put data there! + /// This is the entirely abstraction-violating way to just get mutable access to the raw bytes. + /// Just calling this already marks everything as defined and removes provenance, so be sure to + /// actually overwrite all the data there! /// /// It is the caller's responsibility to check bounds and alignment beforehand. /// Most likely, you want to use the `PlaceTy` and `OperandTy`-based methods /// on `InterpCx` instead. - pub fn get_bytes_mut( + pub fn get_bytes_unchecked_for_overwrite( &mut self, cx: &impl HasDataLayout, range: AllocRange, @@ -469,8 +478,9 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes> Ok(&mut self.bytes[range.start.bytes_usize()..range.end().bytes_usize()]) } - /// A raw pointer variant of `get_bytes_mut` that avoids invalidating existing aliases into this memory. - pub fn get_bytes_mut_ptr( + /// A raw pointer variant of `get_bytes_unchecked_for_overwrite` that avoids invalidating existing immutable aliases + /// into this memory. + pub fn get_bytes_unchecked_for_overwrite_ptr( &mut self, cx: &impl HasDataLayout, range: AllocRange, @@ -479,10 +489,19 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes> self.provenance.clear(range, cx)?; assert!(range.end().bytes_usize() <= self.bytes.len()); // need to do our own bounds-check + // Cruciall, we go via `AllocBytes::as_mut_ptr`, not `AllocBytes::deref_mut`. let begin_ptr = self.bytes.as_mut_ptr().wrapping_add(range.start.bytes_usize()); let len = range.end().bytes_usize() - range.start.bytes_usize(); Ok(ptr::slice_from_raw_parts_mut(begin_ptr, len)) } + + /// This gives direct mutable access to the entire buffer, just exposing their internal state + /// without reseting anything. Directly exposes `AllocBytes::as_mut_ptr`. Only works if + /// `OFFSET_IS_ADDR` is true. + pub fn get_bytes_unchecked_raw_mut(&mut self) -> *mut u8 { + assert!(Prov::OFFSET_IS_ADDR); + self.bytes.as_mut_ptr() + } } /// Reading and writing. @@ -589,7 +608,8 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes> }; let endian = cx.data_layout().endian; - let dst = self.get_bytes_mut(cx, range)?; + // Yes we do overwrite all the bytes in `dst`. + let dst = self.get_bytes_unchecked_for_overwrite(cx, range)?; write_target_uint(endian, dst, bytes).unwrap(); // See if we have to also store some provenance. diff --git a/compiler/rustc_middle/src/mir/interpret/mod.rs b/compiler/rustc_middle/src/mir/interpret/mod.rs index f9edbb3c5ae..6275942bafe 100644 --- a/compiler/rustc_middle/src/mir/interpret/mod.rs +++ b/compiler/rustc_middle/src/mir/interpret/mod.rs @@ -671,11 +671,11 @@ pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result<u128, i // So we do not read exactly 16 bytes into the u128, just the "payload". let uint = match endianness { Endian::Little => { - source.read(&mut buf)?; + source.read_exact(&mut buf[..source.len()])?; Ok(u128::from_le_bytes(buf)) } Endian::Big => { - source.read(&mut buf[16 - source.len()..])?; + source.read_exact(&mut buf[16 - source.len()..])?; Ok(u128::from_be_bytes(buf)) } }; diff --git a/compiler/rustc_middle/src/mir/interpret/queries.rs b/compiler/rustc_middle/src/mir/interpret/queries.rs index 643b61c1de3..04d6301116e 100644 --- a/compiler/rustc_middle/src/mir/interpret/queries.rs +++ b/compiler/rustc_middle/src/mir/interpret/queries.rs @@ -24,7 +24,7 @@ impl<'tcx> TyCtxt<'tcx> { let instance = ty::Instance::new(def_id, args); let cid = GlobalId { instance, promoted: None }; let param_env = self.param_env(def_id).with_reveal_all_normalized(self); - self.const_eval_global_id(param_env, cid, None) + self.const_eval_global_id(param_env, cid, DUMMY_SP) } /// Resolves and evaluates a constant. /// @@ -40,7 +40,7 @@ impl<'tcx> TyCtxt<'tcx> { self, param_env: ty::ParamEnv<'tcx>, ct: mir::UnevaluatedConst<'tcx>, - span: Option<Span>, + span: Span, ) -> EvalToConstValueResult<'tcx> { // Cannot resolve `Unevaluated` constants that contain inference // variables. We reject those here since `resolve` @@ -73,7 +73,7 @@ impl<'tcx> TyCtxt<'tcx> { self, param_env: ty::ParamEnv<'tcx>, ct: ty::UnevaluatedConst<'tcx>, - span: Option<Span>, + span: Span, ) -> EvalToValTreeResult<'tcx> { // Cannot resolve `Unevaluated` constants that contain inference // variables. We reject those here since `resolve` @@ -130,7 +130,7 @@ impl<'tcx> TyCtxt<'tcx> { self, param_env: ty::ParamEnv<'tcx>, instance: ty::Instance<'tcx>, - span: Option<Span>, + span: Span, ) -> EvalToConstValueResult<'tcx> { self.const_eval_global_id(param_env, GlobalId { instance, promoted: None }, span) } @@ -141,12 +141,12 @@ impl<'tcx> TyCtxt<'tcx> { self, param_env: ty::ParamEnv<'tcx>, cid: GlobalId<'tcx>, - span: Option<Span>, + span: Span, ) -> EvalToConstValueResult<'tcx> { // Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should // improve caching of queries. let inputs = self.erase_regions(param_env.with_reveal_all_normalized(self).and(cid)); - if let Some(span) = span { + if !span.is_dummy() { // The query doesn't know where it is being invoked, so we need to fix the span. self.at(span).eval_to_const_value_raw(inputs).map_err(|e| e.with_span(span)) } else { @@ -160,13 +160,13 @@ impl<'tcx> TyCtxt<'tcx> { self, param_env: ty::ParamEnv<'tcx>, cid: GlobalId<'tcx>, - span: Option<Span>, + span: Span, ) -> EvalToValTreeResult<'tcx> { // Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should // improve caching of queries. let inputs = self.erase_regions(param_env.with_reveal_all_normalized(self).and(cid)); debug!(?inputs); - if let Some(span) = span { + if !span.is_dummy() { // The query doesn't know where it is being invoked, so we need to fix the span. self.at(span).eval_to_valtree(inputs).map_err(|e| e.with_span(span)) } else { diff --git a/compiler/rustc_middle/src/mir/interpret/value.rs b/compiler/rustc_middle/src/mir/interpret/value.rs index e937c17c8ac..24d4a79c7d7 100644 --- a/compiler/rustc_middle/src/mir/interpret/value.rs +++ b/compiler/rustc_middle/src/mir/interpret/value.rs @@ -3,7 +3,7 @@ use std::fmt; use either::{Either, Left, Right}; use rustc_apfloat::{ - ieee::{Double, Single}, + ieee::{Double, Half, Quad, Single}, Float, }; use rustc_macros::HashStable; @@ -202,6 +202,11 @@ impl<Prov> Scalar<Prov> { } #[inline] + pub fn from_f16(f: Half) -> Self { + Scalar::Int(f.into()) + } + + #[inline] pub fn from_f32(f: Single) -> Self { Scalar::Int(f.into()) } @@ -211,6 +216,11 @@ impl<Prov> Scalar<Prov> { Scalar::Int(f.into()) } + #[inline] + pub fn from_f128(f: Quad) -> Self { + Scalar::Int(f.into()) + } + /// This is almost certainly not the method you want! You should dispatch on the type /// and use `to_{u8,u16,...}`/`scalar_to_ptr` to perform ptr-to-int / int-to-ptr casts as needed. /// @@ -423,6 +433,11 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> { } #[inline] + pub fn to_f16(self) -> InterpResult<'tcx, Half> { + self.to_float() + } + + #[inline] pub fn to_f32(self) -> InterpResult<'tcx, Single> { self.to_float() } @@ -431,4 +446,9 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> { pub fn to_f64(self) -> InterpResult<'tcx, Double> { self.to_float() } + + #[inline] + pub fn to_f128(self) -> InterpResult<'tcx, Quad> { + self.to_float() + } } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index d57ffc0f8b5..48edbde68e5 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -20,6 +20,7 @@ use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; use rustc_hir::{self, CoroutineDesugaring, CoroutineKind, ImplicitSelfKind}; use rustc_hir::{self as hir, HirId}; use rustc_session::Session; +use rustc_span::source_map::Spanned; use rustc_target::abi::{FieldIdx, VariantIdx}; use polonius_engine::Atom; @@ -44,6 +45,7 @@ use std::ops::{Index, IndexMut}; use std::{iter, mem}; pub use self::query::*; +use self::visit::TyContext; pub use basic_blocks::BasicBlocks; mod basic_blocks; @@ -278,13 +280,6 @@ pub struct CoroutineInfo<'tcx> { /// using `run_passes`. pub by_move_body: Option<Body<'tcx>>, - /// The body of the coroutine, modified to take its upvars by mutable ref rather than by - /// immutable ref. - /// - /// FIXME(async_closures): This is literally the same body as the parent body. Find a better - /// way to represent the by-mut signature (or cap the closure-kind of the coroutine). - pub by_mut_body: Option<Body<'tcx>>, - /// The layout of a coroutine. This field is populated after the state transform pass. pub coroutine_layout: Option<CoroutineLayout<'tcx>>, @@ -305,13 +300,27 @@ impl<'tcx> CoroutineInfo<'tcx> { yield_ty: Some(yield_ty), resume_ty: Some(resume_ty), by_move_body: None, - by_mut_body: None, coroutine_drop: None, coroutine_layout: None, } } } +/// Some item that needs to monomorphize successfully for a MIR body to be considered well-formed. +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, HashStable, TyEncodable, TyDecodable)] +#[derive(TypeFoldable, TypeVisitable)] +pub enum MentionedItem<'tcx> { + /// A function that gets called. We don't necessarily know its precise type yet, since it can be + /// hidden behind a generic. + Fn(Ty<'tcx>), + /// A type that has its drop shim called. + Drop(Ty<'tcx>), + /// Unsizing casts might require vtables, so we have to record them. + UnsizeCast { source_ty: Ty<'tcx>, target_ty: Ty<'tcx> }, + /// A closure that is coerced to a function pointer. + Closure(Ty<'tcx>), +} + /// The lowered representation of a single function. #[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable, TypeVisitable)] pub struct Body<'tcx> { @@ -375,8 +384,24 @@ pub struct Body<'tcx> { /// Constants that are required to evaluate successfully for this MIR to be well-formed. /// We hold in this field all the constants we are not able to evaluate yet. + /// + /// This is soundness-critical, we make a guarantee that all consts syntactically mentioned in a + /// function have successfully evaluated if the function ever gets executed at runtime. pub required_consts: Vec<ConstOperand<'tcx>>, + /// Further items that were mentioned in this function and hence *may* become monomorphized, + /// depending on optimizations. We use this to avoid optimization-dependent compile errors: the + /// collector recursively traverses all "mentioned" items and evaluates all their + /// `required_consts`. + /// + /// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee. + /// All that's relevant is that this set is optimization-level-independent, and that it includes + /// everything that the collector would consider "used". (For example, we currently compute this + /// set after drop elaboration, so some drop calls that can never be reached are not considered + /// "mentioned".) See the documentation of `CollectionMode` in + /// `compiler/rustc_monomorphize/src/collector.rs` for more context. + pub mentioned_items: Vec<Spanned<MentionedItem<'tcx>>>, + /// Does this body use generic parameters. This is used for the `ConstEvaluatable` check. /// /// Note that this does not actually mean that this body is not computable right now. @@ -453,6 +478,7 @@ impl<'tcx> Body<'tcx> { var_debug_info, span, required_consts: Vec::new(), + mentioned_items: Vec::new(), is_polymorphic: false, injection_phase: None, tainted_by_errors, @@ -482,6 +508,7 @@ impl<'tcx> Body<'tcx> { spread_arg: None, span: DUMMY_SP, required_consts: Vec::new(), + mentioned_items: Vec::new(), var_debug_info: Vec::new(), is_polymorphic: false, injection_phase: None, @@ -576,6 +603,17 @@ impl<'tcx> Body<'tcx> { } } + pub fn span_for_ty_context(&self, ty_context: TyContext) -> Span { + match ty_context { + TyContext::UserTy(span) => span, + TyContext::ReturnTy(source_info) + | TyContext::LocalDecl { source_info, .. } + | TyContext::YieldTy(source_info) + | TyContext::ResumeTy(source_info) => source_info.span, + TyContext::Location(loc) => self.source_info(loc).span, + } + } + /// Returns the return type; it always return first element from `local_decls` array. #[inline] pub fn return_ty(&self) -> Ty<'tcx> { @@ -628,10 +666,6 @@ impl<'tcx> Body<'tcx> { self.coroutine.as_ref()?.by_move_body.as_ref() } - pub fn coroutine_by_mut_body(&self) -> Option<&Body<'tcx>> { - self.coroutine.as_ref()?.by_mut_body.as_ref() - } - #[inline] pub fn coroutine_kind(&self) -> Option<CoroutineKind> { self.coroutine.as_ref().map(|coroutine| coroutine.coroutine_kind) diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs index 8bd872c1b19..731e050ca9b 100644 --- a/compiler/rustc_middle/src/mir/query.rs +++ b/compiler/rustc_middle/src/mir/query.rs @@ -284,8 +284,15 @@ rustc_data_structures::static_assert_size!(ConstraintCategory<'_>, 16); /// order of the category, thereby influencing diagnostic output. /// /// See also `rustc_const_eval::borrow_check::constraints`. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] #[derive(TyEncodable, TyDecodable, HashStable, TypeVisitable, TypeFoldable)] +#[derive(derivative::Derivative)] +#[derivative( + PartialOrd, + Ord, + PartialOrd = "feature_allow_slow_enum", + Ord = "feature_allow_slow_enum" +)] pub enum ConstraintCategory<'tcx> { Return(ReturnConstraint), Yield, @@ -295,6 +302,7 @@ pub enum ConstraintCategory<'tcx> { Cast { /// Whether this is an unsizing cast and if yes, this contains the target type. /// Region variables are erased to ReErased. + #[derivative(PartialOrd = "ignore", Ord = "ignore")] unsize_to: Option<Ty<'tcx>>, }, @@ -304,7 +312,7 @@ pub enum ConstraintCategory<'tcx> { ClosureBounds, /// Contains the function type if available. - CallArgument(Option<Ty<'tcx>>), + CallArgument(#[derivative(PartialOrd = "ignore", Ord = "ignore")] Option<Ty<'tcx>>), CopyBound, SizedBound, Assignment, diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 0ab797134c0..752f5845afb 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -124,6 +124,7 @@ pub enum AnalysisPhase { /// * [`TerminatorKind::FalseEdge`] /// * [`StatementKind::FakeRead`] /// * [`StatementKind::AscribeUserType`] + /// * [`StatementKind::Coverage`] with [`CoverageKind::BlockMarker`] or [`CoverageKind::SpanMarker`] /// * [`Rvalue::Ref`] with `BorrowKind::Fake` /// /// Furthermore, `Deref` projections must be the first projection within any place (if they diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 845b1717550..be960669ff4 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -345,8 +345,11 @@ macro_rules! make_mir_visitor { ty::InstanceDef::Virtual(_def_id, _) | ty::InstanceDef::ThreadLocalShim(_def_id) | ty::InstanceDef::ClosureOnceShim { call_once: _def_id, track_caller: _ } | - ty::InstanceDef::ConstructCoroutineInClosureShim { coroutine_closure_def_id: _def_id, target_kind: _ } | - ty::InstanceDef::CoroutineKindShim { coroutine_def_id: _def_id, target_kind: _ } | + ty::InstanceDef::ConstructCoroutineInClosureShim { + coroutine_closure_def_id: _def_id, + receiver_by_ref: _, + } | + ty::InstanceDef::CoroutineKindShim { coroutine_def_id: _def_id } | ty::InstanceDef::DropGlue(_def_id, None) => {} ty::InstanceDef::FnPtrShim(_def_id, ty) | diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 865299e15c8..10d92583a55 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -343,11 +343,14 @@ rustc_queries! { } } - /// Returns the list of bounds that can be used for - /// `SelectionCandidate::ProjectionCandidate(_)` and - /// `ProjectionTyCandidate::TraitDef`. - /// Specifically this is the bounds written on the trait's type - /// definition, or those after the `impl` keyword + /// Returns the list of bounds that are required to be satsified + /// by a implementation or definition. For associated types, these + /// must be satisfied for an implementation to be well-formed, + /// and for opaque types, these are required to be satisfied by + /// the hidden-type of the opaque. + /// + /// Syntactially, these are the bounds written on the trait's type + /// definition, or those after the `impl` keyword for an opaque: /// /// ```ignore (incomplete) /// type X: Bound + 'lt @@ -363,7 +366,16 @@ rustc_queries! { desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) } cache_on_disk_if { key.is_local() } separate_provide_extern - feedable + } + + /// The set of item bounds (see [`TyCtxt::explicit_item_bounds`]) that + /// share the `Self` type of the item. These are a subset of the bounds + /// that may explicitly be used for things like closure signature + /// deduction. + query explicit_item_super_predicates(key: DefId) -> ty::EarlyBinder<&'tcx [(ty::Clause<'tcx>, Span)]> { + desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) } + cache_on_disk_if { key.is_local() } + separate_provide_extern } /// Elaborated version of the predicates from `explicit_item_bounds`. @@ -390,6 +402,14 @@ rustc_queries! { desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) } } + query item_super_predicates(key: DefId) -> ty::EarlyBinder<&'tcx ty::List<ty::Clause<'tcx>>> { + desc { |tcx| "elaborating item assumptions for `{}`", tcx.def_path_str(key) } + } + + query item_non_self_assumptions(key: DefId) -> ty::EarlyBinder<&'tcx ty::List<ty::Clause<'tcx>>> { + desc { |tcx| "elaborating item assumptions for `{}`", tcx.def_path_str(key) } + } + /// Look up all native libraries this crate depends on. /// These are assembled from the following places: /// - `extern` blocks (depending on their `link` attributes) @@ -703,8 +723,8 @@ rustc_queries! { separate_provide_extern } - query adt_sized_constraint(key: DefId) -> ty::EarlyBinder<&'tcx ty::List<Ty<'tcx>>> { - desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) } + query adt_sized_constraint(key: DefId) -> Option<ty::EarlyBinder<Ty<'tcx>>> { + desc { |tcx| "computing the `Sized` constraint for `{}`", tcx.def_path_str(key) } } query adt_dtorck_constraint( diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 96a61883cc1..f684f83a261 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -647,6 +647,7 @@ impl<'tcx> Pat<'tcx> { AscribeUserType { subpattern, .. } | Binding { subpattern: Some(subpattern), .. } | Deref { subpattern } + | DerefPattern { subpattern } | InlineConstant { subpattern, .. } => subpattern.walk_(it), Leaf { subpatterns } | Variant { subpatterns, .. } => { subpatterns.iter().for_each(|field| field.pattern.walk_(it)) @@ -762,6 +763,11 @@ pub enum PatKind<'tcx> { subpattern: Box<Pat<'tcx>>, }, + /// Deref pattern, written `box P` for now. + DerefPattern { + subpattern: Box<Pat<'tcx>>, + }, + /// One of the following: /// * `&str` (represented as a valtree), which will be handled as a string pattern and thus /// exhaustiveness checking will detect if you use the same string twice in different @@ -1172,6 +1178,9 @@ impl<'tcx> fmt::Display for Pat<'tcx> { } write!(f, "{subpattern}") } + PatKind::DerefPattern { ref subpattern } => { + write!(f, "deref!({subpattern})") + } PatKind::Constant { value } => write!(f, "{value}"), PatKind::InlineConstant { def: _, ref subpattern } => { write!(f, "{} (from inline const)", subpattern) diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs index 5952c296fb6..99ab006bcc0 100644 --- a/compiler/rustc_middle/src/thir/visit.rs +++ b/compiler/rustc_middle/src/thir/visit.rs @@ -229,6 +229,7 @@ pub fn walk_pat<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>( match &pat.kind { AscribeUserType { subpattern, ascription: _ } | Deref { subpattern } + | DerefPattern { subpattern } | Binding { subpattern: Some(subpattern), mutability: _, diff --git a/compiler/rustc_middle/src/traits/solve.rs b/compiler/rustc_middle/src/traits/solve.rs index dc4cd203415..6dcea2aaff1 100644 --- a/compiler/rustc_middle/src/traits/solve.rs +++ b/compiler/rustc_middle/src/traits/solve.rs @@ -164,6 +164,19 @@ pub struct ExternalConstraintsData<'tcx> { // FIXME: implement this. pub region_constraints: QueryRegionConstraints<'tcx>, pub opaque_types: Vec<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)>, + pub normalization_nested_goals: NestedNormalizationGoals<'tcx>, +} + +#[derive(Debug, PartialEq, Eq, Clone, Hash, HashStable, Default, TypeVisitable, TypeFoldable)] +pub struct NestedNormalizationGoals<'tcx>(pub Vec<(GoalSource, Goal<'tcx, ty::Predicate<'tcx>>)>); +impl<'tcx> NestedNormalizationGoals<'tcx> { + pub fn empty() -> Self { + NestedNormalizationGoals(vec![]) + } + + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } } // FIXME: Having to clone `region_constraints` for folding feels bad and @@ -183,6 +196,10 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> { .iter() .map(|opaque| opaque.try_fold_with(folder)) .collect::<Result<_, F::Error>>()?, + normalization_nested_goals: self + .normalization_nested_goals + .clone() + .try_fold_with(folder)?, })) } @@ -190,6 +207,7 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> { TypeFolder::interner(folder).mk_external_constraints(ExternalConstraintsData { region_constraints: self.region_constraints.clone().fold_with(folder), opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(), + normalization_nested_goals: self.normalization_nested_goals.clone().fold_with(folder), }) } } @@ -197,7 +215,8 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> { impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> { fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result { try_visit!(self.region_constraints.visit_with(visitor)); - self.opaque_types.visit_with(visitor) + try_visit!(self.opaque_types.visit_with(visitor)); + self.normalization_nested_goals.visit_with(visitor) } } @@ -239,7 +258,7 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> { /// /// This is necessary as we treat nested goals different depending on /// their source. -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, TypeVisitable, TypeFoldable)] pub enum GoalSource { Misc, /// We're proving a where-bound of an impl. @@ -256,12 +275,6 @@ pub enum GoalSource { ImplWhereBound, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable)] -pub enum IsNormalizesToHack { - Yes, - No, -} - /// Possible ways the given goal can be proven. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum CandidateSource { diff --git a/compiler/rustc_middle/src/traits/solve/inspect.rs b/compiler/rustc_middle/src/traits/solve/inspect.rs index 90180af3b16..16842c8208f 100644 --- a/compiler/rustc_middle/src/traits/solve/inspect.rs +++ b/compiler/rustc_middle/src/traits/solve/inspect.rs @@ -19,8 +19,8 @@ //! [canonicalized]: https://rustc-dev-guide.rust-lang.org/solve/canonicalization.html use super::{ - CandidateSource, Canonical, CanonicalInput, Certainty, Goal, GoalSource, IsNormalizesToHack, - NoSolution, QueryInput, QueryResult, + CandidateSource, Canonical, CanonicalInput, Certainty, Goal, GoalSource, NoSolution, + QueryInput, QueryResult, }; use crate::{infer::canonical::CanonicalVarValues, ty}; use format::ProofTreeFormatter; @@ -50,7 +50,7 @@ pub type CanonicalState<'tcx, T> = Canonical<'tcx, State<'tcx, T>>; #[derive(Eq, PartialEq)] pub enum GoalEvaluationKind<'tcx> { Root { orig_values: Vec<ty::GenericArg<'tcx>> }, - Nested { is_normalizes_to_hack: IsNormalizesToHack }, + Nested, } #[derive(Eq, PartialEq)] diff --git a/compiler/rustc_middle/src/traits/solve/inspect/format.rs b/compiler/rustc_middle/src/traits/solve/inspect/format.rs index 8d3109a7b28..43931205017 100644 --- a/compiler/rustc_middle/src/traits/solve/inspect/format.rs +++ b/compiler/rustc_middle/src/traits/solve/inspect/format.rs @@ -55,10 +55,7 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> { pub(super) fn format_goal_evaluation(&mut self, eval: &GoalEvaluation<'_>) -> std::fmt::Result { let goal_text = match eval.kind { GoalEvaluationKind::Root { orig_values: _ } => "ROOT GOAL", - GoalEvaluationKind::Nested { is_normalizes_to_hack } => match is_normalizes_to_hack { - IsNormalizesToHack::No => "GOAL", - IsNormalizesToHack::Yes => "NORMALIZES-TO HACK GOAL", - }, + GoalEvaluationKind::Nested => "GOAL", }; write!(self.f, "{}: {:?}", goal_text, eval.uncanonicalized_goal)?; self.nested(|this| this.format_canonical_goal_evaluation(&eval.evaluation)) diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 2e1c7df6454..a7144316769 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -590,10 +590,10 @@ impl<'tcx> AdtDef<'tcx> { tcx.adt_destructor(self.did()) } - /// Returns a list of types such that `Self: Sized` if and only if that - /// type is `Sized`, or `ty::Error` if this type has a recursive layout. - pub fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> ty::EarlyBinder<&'tcx ty::List<Ty<'tcx>>> { - tcx.adt_sized_constraint(self.did()) + /// Returns a type such that `Self: Sized` if and only if that type is `Sized`, + /// or `None` if the type is always sized. + pub fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> Option<ty::EarlyBinder<Ty<'tcx>>> { + if self.is_struct() { tcx.adt_sized_constraint(self.did()) } else { None } } } @@ -601,5 +601,5 @@ impl<'tcx> AdtDef<'tcx> { #[derive(HashStable)] pub enum Representability { Representable, - Infinite, + Infinite(ErrorGuaranteed), } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 5b62c0bf931..0d621cd1cfd 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -335,7 +335,7 @@ impl<'tcx> Const<'tcx> { self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, - span: Option<Span>, + span: Span, ) -> Result<ValTree<'tcx>, ErrorHandled> { assert!(!self.has_escaping_bound_vars(), "escaping vars in {self:?}"); match self.kind() { @@ -349,7 +349,7 @@ impl<'tcx> Const<'tcx> { else { // This can happen when we run on ill-typed code. let e = tcx.dcx().span_delayed_bug( - span.unwrap_or(DUMMY_SP), + span, "`ty::Const::eval` called on a non-valtree-compatible type", ); return Err(e.into()); @@ -362,14 +362,14 @@ impl<'tcx> Const<'tcx> { | ConstKind::Infer(_) | ConstKind::Bound(_, _) | ConstKind::Placeholder(_) - | ConstKind::Expr(_) => Err(ErrorHandled::TooGeneric(span.unwrap_or(DUMMY_SP))), + | ConstKind::Expr(_) => Err(ErrorHandled::TooGeneric(span)), } } /// Normalizes the constant to a value or an error if possible. #[inline] pub fn normalize(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Self { - match self.eval(tcx, param_env, None) { + match self.eval(tcx, param_env, DUMMY_SP) { Ok(val) => Self::new_value(tcx, val, self.ty()), Err(ErrorHandled::Reported(r, _span)) => Self::new_error(tcx, r.into(), self.ty()), Err(ErrorHandled::TooGeneric(_span)) => self, @@ -382,7 +382,7 @@ impl<'tcx> Const<'tcx> { tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, ) -> Option<Scalar> { - self.eval(tcx, param_env, None).ok()?.try_to_scalar() + self.eval(tcx, param_env, DUMMY_SP).ok()?.try_to_scalar() } #[inline] diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs index a70e01645f4..71d7dfd8b01 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -1,4 +1,4 @@ -use rustc_apfloat::ieee::{Double, Single}; +use rustc_apfloat::ieee::{Double, Half, Quad, Single}; use rustc_apfloat::Float; use rustc_errors::{DiagArgValue, IntoDiagArg}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; @@ -370,6 +370,11 @@ impl ScalarInt { } #[inline] + pub fn try_to_f16(self) -> Result<Half, Size> { + self.try_to_float() + } + + #[inline] pub fn try_to_f32(self) -> Result<Single, Size> { self.try_to_float() } @@ -378,6 +383,11 @@ impl ScalarInt { pub fn try_to_f64(self) -> Result<Double, Size> { self.try_to_float() } + + #[inline] + pub fn try_to_f128(self) -> Result<Quad, Size> { + self.try_to_float() + } } macro_rules! from { @@ -450,6 +460,22 @@ impl TryFrom<ScalarInt> for char { } } +impl From<Half> for ScalarInt { + #[inline] + fn from(f: Half) -> Self { + // We trust apfloat to give us properly truncated data. + Self { data: f.to_bits(), size: NonZero::new((Half::BITS / 8) as u8).unwrap() } + } +} + +impl TryFrom<ScalarInt> for Half { + type Error = Size; + #[inline] + fn try_from(int: ScalarInt) -> Result<Self, Size> { + int.to_bits(Size::from_bytes(2)).map(Self::from_bits) + } +} + impl From<Single> for ScalarInt { #[inline] fn from(f: Single) -> Self { @@ -482,6 +508,22 @@ impl TryFrom<ScalarInt> for Double { } } +impl From<Quad> for ScalarInt { + #[inline] + fn from(f: Quad) -> Self { + // We trust apfloat to give us properly truncated data. + Self { data: f.to_bits(), size: NonZero::new((Quad::BITS / 8) as u8).unwrap() } + } +} + +impl TryFrom<ScalarInt> for Quad { + type Error = Size; + #[inline] + fn try_from(int: ScalarInt) -> Result<Self, Size> { + int.to_bits(Size::from_bytes(16)).map(Self::from_bits) + } +} + impl fmt::Debug for ScalarInt { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // Dispatch to LowerHex below. diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 17ba97c5fd3..8a87538e788 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -43,7 +43,9 @@ use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, Lrc, WorkerLocal} #[cfg(parallel_compiler)] use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_data_structures::unord::UnordSet; -use rustc_errors::{Diag, DiagCtxt, DiagMessage, ErrorGuaranteed, LintDiagnostic, MultiSpan}; +use rustc_errors::{ + Applicability, Diag, DiagCtxt, DiagMessage, ErrorGuaranteed, LintDiagnostic, MultiSpan, +}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; @@ -594,6 +596,27 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> { pub fn feed_owner_id(&self) -> TyCtxtFeed<'tcx, hir::OwnerId> { TyCtxtFeed { tcx: self.tcx, key: hir::OwnerId { def_id: self.key } } } + + // Fills in all the important parts needed by HIR queries + pub fn feed_hir(&self) { + self.local_def_id_to_hir_id(HirId::make_owner(self.def_id())); + + let node = hir::OwnerNode::Synthetic; + let bodies = Default::default(); + let attrs = hir::AttributeMap::EMPTY; + + let (opt_hash_including_bodies, _) = self.tcx.hash_owner_nodes(node, &bodies, &attrs.map); + let node = node.into(); + self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes { + opt_hash_including_bodies, + nodes: IndexVec::from_elem_n( + hir::ParentedNode { parent: hir::ItemLocalId::INVALID, node }, + 1, + ), + bodies, + }))); + self.feed_owner_id().hir_attrs(attrs); + } } /// The central data structure of the compiler. It stores references @@ -1805,7 +1828,7 @@ impl<'tcx> TyCtxt<'tcx> { let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = ty.kind() else { return false }; let future_trait = self.require_lang_item(LangItem::Future, None); - self.explicit_item_bounds(def_id).skip_binder().iter().any(|&(predicate, _)| { + self.explicit_item_super_predicates(def_id).skip_binder().iter().any(|&(predicate, _)| { let ty::ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() else { return false; }; @@ -2174,6 +2197,45 @@ impl<'tcx> TyCtxt<'tcx> { lint_level(self.sess, lint, level, src, Some(span.into()), msg, decorate); } + /// Find the crate root and the appropriate span where `use` and outer attributes can be + /// inserted at. + pub fn crate_level_attribute_injection_span(self, hir_id: HirId) -> Option<Span> { + for (_hir_id, node) in self.hir().parent_iter(hir_id) { + if let hir::Node::Crate(m) = node { + return Some(m.spans.inject_use_span.shrink_to_lo()); + } + } + None + } + + pub fn disabled_nightly_features<E: rustc_errors::EmissionGuarantee>( + self, + diag: &mut Diag<'_, E>, + hir_id: Option<HirId>, + features: impl IntoIterator<Item = (String, Symbol)>, + ) { + if !self.sess.is_nightly_build() { + return; + } + + let span = hir_id.and_then(|id| self.crate_level_attribute_injection_span(id)); + for (desc, feature) in features { + // FIXME: make this string translatable + let msg = + format!("add `#![feature({feature})]` to the crate attributes to enable{desc}"); + if let Some(span) = span { + diag.span_suggestion_verbose( + span, + msg, + format!("#![feature({feature})]\n"), + Applicability::MachineApplicable, + ); + } else { + diag.help(msg); + } + } + } + /// Emit a lint from a lint struct (some type that implements `LintDiagnostic`, typically /// generated by `#[derive(LintDiagnostic)]`). #[track_caller] diff --git a/compiler/rustc_middle/src/ty/context/tls.rs b/compiler/rustc_middle/src/ty/context/tls.rs index 788ccd5dbbd..5e256dc8d26 100644 --- a/compiler/rustc_middle/src/ty/context/tls.rs +++ b/compiler/rustc_middle/src/ty/context/tls.rs @@ -85,6 +85,7 @@ where /// Allows access to the current `ImplicitCtxt` in a closure if one is available. #[inline] +#[track_caller] pub fn with_context_opt<F, R>(f: F) -> R where F: for<'a, 'tcx> FnOnce(Option<&ImplicitCtxt<'a, 'tcx>>) -> R, @@ -147,9 +148,13 @@ where /// Allows access to the `TyCtxt` in the current `ImplicitCtxt`. /// The closure is passed None if there is no `ImplicitCtxt` available. #[inline] +#[track_caller] pub fn with_opt<F, R>(f: F) -> R where F: for<'tcx> FnOnce(Option<TyCtxt<'tcx>>) -> R, { - with_context_opt(|opt_context| f(opt_context.map(|context| context.tcx))) + with_context_opt( + #[track_caller] + |opt_context| f(opt_context.map(|context| context.tcx)), + ) } diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 05463b8554f..ee18647cdd8 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -91,7 +91,12 @@ pub trait IsSuggestable<'tcx>: Sized { /// inference variables to be suggestable. fn is_suggestable(self, tcx: TyCtxt<'tcx>, infer_suggestable: bool) -> bool; - fn make_suggestable(self, tcx: TyCtxt<'tcx>, infer_suggestable: bool) -> Option<Self>; + fn make_suggestable( + self, + tcx: TyCtxt<'tcx>, + infer_suggestable: bool, + placeholder: Option<Ty<'tcx>>, + ) -> Option<Self>; } impl<'tcx, T> IsSuggestable<'tcx> for T @@ -103,8 +108,13 @@ where self.visit_with(&mut IsSuggestableVisitor { tcx, infer_suggestable }).is_continue() } - fn make_suggestable(self, tcx: TyCtxt<'tcx>, infer_suggestable: bool) -> Option<T> { - self.try_fold_with(&mut MakeSuggestableFolder { tcx, infer_suggestable }).ok() + fn make_suggestable( + self, + tcx: TyCtxt<'tcx>, + infer_suggestable: bool, + placeholder: Option<Ty<'tcx>>, + ) -> Option<T> { + self.try_fold_with(&mut MakeSuggestableFolder { tcx, infer_suggestable, placeholder }).ok() } } @@ -559,6 +569,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> { pub struct MakeSuggestableFolder<'tcx> { tcx: TyCtxt<'tcx>, infer_suggestable: bool, + placeholder: Option<Ty<'tcx>>, } impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> { @@ -572,19 +583,24 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> { let t = match *t.kind() { Infer(InferTy::TyVar(_)) if self.infer_suggestable => t, - FnDef(def_id, args) => { + FnDef(def_id, args) if self.placeholder.is_none() => { Ty::new_fn_ptr(self.tcx, self.tcx.fn_sig(def_id).instantiate(self.tcx, args)) } - // FIXME(compiler-errors): We could replace these with infer, I guess. Closure(..) + | FnDef(..) | Infer(..) | Coroutine(..) | CoroutineWitness(..) | Bound(_, _) | Placeholder(_) | Error(_) => { - return Err(()); + if let Some(placeholder) = self.placeholder { + // We replace these with infer (which is passed in from an infcx). + placeholder + } else { + return Err(()); + } } Alias(Opaque, AliasTy { def_id, .. }) => { diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs index bbcc244cb26..da5d57db5be 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs @@ -61,7 +61,7 @@ pub(crate) fn provide(providers: &mut Providers) { /// requires calling [`InhabitedPredicate::instantiate`] fn inhabited_predicate_adt(tcx: TyCtxt<'_>, def_id: DefId) -> InhabitedPredicate<'_> { if let Some(def_id) = def_id.as_local() { - if matches!(tcx.representability(def_id), ty::Representability::Infinite) { + if matches!(tcx.representability(def_id), ty::Representability::Infinite(_)) { return InhabitedPredicate::True; } } diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index b82e959844f..65574f5702b 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -91,15 +91,19 @@ pub enum InstanceDef<'tcx> { /// and dispatch to the `FnMut::call_mut` instance for the closure. ClosureOnceShim { call_once: DefId, track_caller: bool }, - /// `<[FnMut/Fn coroutine-closure] as FnOnce>::call_once` or - /// `<[Fn coroutine-closure] as FnMut>::call_mut`. + /// `<[FnMut/Fn coroutine-closure] as FnOnce>::call_once` /// /// The body generated here differs significantly from the `ClosureOnceShim`, /// since we need to generate a distinct coroutine type that will move the /// closure's upvars *out* of the closure. ConstructCoroutineInClosureShim { coroutine_closure_def_id: DefId, - target_kind: ty::ClosureKind, + // Whether the generated MIR body takes the coroutine by-ref. This is + // because the signature of `<{async fn} as FnMut>::call_mut` is: + // `fn(&mut self, args: A) -> <Self as FnOnce>::Output`, that is to say + // that it returns the `FnOnce`-flavored coroutine but takes the closure + // by mut ref (and similarly for `Fn::call`). + receiver_by_ref: bool, }, /// `<[coroutine] as Future>::poll`, but for coroutines produced when `AsyncFnOnce` @@ -108,7 +112,7 @@ pub enum InstanceDef<'tcx> { /// /// This will select the body that is produced by the `ByMoveBody` transform, and thus /// take and use all of its upvars by-move rather than by-ref. - CoroutineKindShim { coroutine_def_id: DefId, target_kind: ty::ClosureKind }, + CoroutineKindShim { coroutine_def_id: DefId }, /// Compiler-generated accessor for thread locals which returns a reference to the thread local /// the `DefId` defines. This is used to export thread locals from dylibs on platforms lacking @@ -198,9 +202,9 @@ impl<'tcx> InstanceDef<'tcx> { | InstanceDef::ClosureOnceShim { call_once: def_id, track_caller: _ } | ty::InstanceDef::ConstructCoroutineInClosureShim { coroutine_closure_def_id: def_id, - target_kind: _, + receiver_by_ref: _, } - | ty::InstanceDef::CoroutineKindShim { coroutine_def_id: def_id, target_kind: _ } + | ty::InstanceDef::CoroutineKindShim { coroutine_def_id: def_id } | InstanceDef::DropGlue(def_id, _) | InstanceDef::CloneShim(def_id, _) | InstanceDef::FnPtrAddrShim(def_id, _) => def_id, @@ -657,10 +661,7 @@ impl<'tcx> Instance<'tcx> { Some(Instance { def: ty::InstanceDef::Item(coroutine_def_id), args }) } else { Some(Instance { - def: ty::InstanceDef::CoroutineKindShim { - coroutine_def_id, - target_kind: args.as_coroutine().kind_ty().to_opt_closure_kind().unwrap(), - }, + def: ty::InstanceDef::CoroutineKindShim { coroutine_def_id }, args, }) } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 11fd73c9094..595ef71cc32 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -2,7 +2,7 @@ use crate::error::UnsupportedFnAbi; use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::query::TyCtxtAt; use crate::ty::normalize_erasing_regions::NormalizationError; -use crate::ty::{self, ConstKind, Ty, TyCtxt, TypeVisitableExt}; +use crate::ty::{self, Ty, TyCtxt, TypeVisitableExt}; use rustc_error_messages::DiagMessage; use rustc_errors::{ Diag, DiagArgValue, DiagCtxt, Diagnostic, EmissionGuarantee, IntoDiagArg, Level, @@ -356,21 +356,10 @@ impl<'tcx> SizeSkeleton<'tcx> { .ok_or_else(|| &*tcx.arena.alloc(LayoutError::SizeOverflow(ty)))?; return Ok(SizeSkeleton::Known(Size::from_bytes(size))); } - let len = tcx.expand_abstract_consts(len); - let prev = ty::Const::from_target_usize(tcx, s.bytes()); - let Some(gen_size) = mul_sorted_consts(tcx, param_env, len, prev) else { - return Err(tcx.arena.alloc(LayoutError::SizeOverflow(ty))); - }; - Ok(SizeSkeleton::Generic(gen_size)) + Err(tcx.arena.alloc(LayoutError::Unknown(ty))) } SizeSkeleton::Pointer { .. } => Err(err), - SizeSkeleton::Generic(g) => { - let len = tcx.expand_abstract_consts(len); - let Some(gen_size) = mul_sorted_consts(tcx, param_env, len, g) else { - return Err(tcx.arena.alloc(LayoutError::SizeOverflow(ty))); - }; - Ok(SizeSkeleton::Generic(gen_size)) - } + SizeSkeleton::Generic(_) => Err(tcx.arena.alloc(LayoutError::Unknown(ty))), } } @@ -468,56 +457,6 @@ impl<'tcx> SizeSkeleton<'tcx> { } } -/// When creating the layout for types with abstract consts in their size (i.e. [usize; 4 * N]), -/// to ensure that they have a canonical order and can be compared directly we combine all -/// constants, and sort the other terms. This allows comparison of expressions of sizes, -/// allowing for things like transmuting between types that depend on generic consts. -/// This returns `None` if multiplication of constants overflows. -fn mul_sorted_consts<'tcx>( - tcx: TyCtxt<'tcx>, - param_env: ty::ParamEnv<'tcx>, - a: ty::Const<'tcx>, - b: ty::Const<'tcx>, -) -> Option<ty::Const<'tcx>> { - use crate::mir::BinOp::Mul; - - let mut work = vec![a, b]; - let mut done = vec![]; - while let Some(n) = work.pop() { - if let ConstKind::Expr(ty::Expr::Binop(Mul, l, r)) = n.kind() { - work.push(l); - work.push(r) - } else { - done.push(n); - } - } - let mut k = 1; - let mut overflow = false; - done.retain(|c| { - let Some(c) = c.try_eval_target_usize(tcx, param_env) else { - return true; - }; - let Some(next) = c.checked_mul(k) else { - overflow = true; - return false; - }; - k = next; - false - }); - if overflow { - return None; - } - if k != 1 { - done.push(ty::Const::from_target_usize(tcx, k)); - } else if k == 0 { - return Some(ty::Const::from_target_usize(tcx, 0)); - } - done.sort_unstable(); - - // create a single tree from the buffer - done.into_iter().reduce(|acc, n| ty::Const::new_expr(tcx, ty::Expr::Binop(Mul, n, acc), n.ty())) -} - pub trait HasTyCtxt<'tcx>: HasDataLayout { fn tcx(&self) -> TyCtxt<'tcx>; } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 8565f90957f..6632d980bff 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1752,9 +1752,8 @@ impl<'tcx> TyCtxt<'tcx> { let filter_fn = move |a: &&ast::Attribute| a.has_name(attr); if let Some(did) = did.as_local() { self.hir().attrs(self.local_def_id_to_hir_id(did)).iter().filter(filter_fn) - } else if cfg!(debug_assertions) && rustc_feature::is_builtin_only_local(attr) { - bug!("tried to access the `only_local` attribute `{}` from an extern crate", attr); } else { + debug_assert!(rustc_feature::encode_cross_crate(attr)); self.item_attrs(did).iter().filter(filter_fn) } } @@ -1786,12 +1785,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Determines whether an item is annotated with an attribute. pub fn has_attr(self, did: impl Into<DefId>, attr: Symbol) -> bool { - let did: DefId = did.into(); - if cfg!(debug_assertions) && !did.is_local() && rustc_feature::is_builtin_only_local(attr) { - bug!("tried to access the `only_local` attribute `{}` from an extern crate", attr); - } else { - self.get_attrs(did, attr).next().is_some() - } + self.get_attrs(did, attr).next().is_some() } /// Returns `true` if this is an `auto trait`. diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 802953867ac..995b439d10a 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -4,7 +4,7 @@ use crate::query::Providers; use crate::traits::util::{super_predicates_for_pretty_printing, supertraits_for_pretty_printing}; use crate::ty::GenericArgKind; use crate::ty::{ - ConstInt, ParamConst, ScalarInt, Term, TermKind, TypeFoldable, TypeSuperFoldable, + ConstInt, Expr, ParamConst, ScalarInt, Term, TermKind, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, }; use rustc_apfloat::ieee::{Double, Single}; @@ -270,6 +270,31 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { Ok(()) } + /// Prints `(...)` around what `f` prints. + fn parenthesized( + &mut self, + f: impl FnOnce(&mut Self) -> Result<(), PrintError>, + ) -> Result<(), PrintError> { + self.write_str("(")?; + f(self)?; + self.write_str(")")?; + Ok(()) + } + + /// Prints `(...)` around what `f` prints if `parenthesized` is true, otherwise just prints `f`. + fn maybe_parenthesized( + &mut self, + f: impl FnOnce(&mut Self) -> Result<(), PrintError>, + parenthesized: bool, + ) -> Result<(), PrintError> { + if parenthesized { + self.parenthesized(f)?; + } else { + f(self)?; + } + Ok(()) + } + /// Prints `<...>` around what `f` prints. fn generic_delimiters( &mut self, @@ -1490,12 +1515,137 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { ty::ConstKind::Placeholder(placeholder) => p!(write("{placeholder:?}")), // FIXME(generic_const_exprs): // write out some legible representation of an abstract const? - ty::ConstKind::Expr(_) => p!("{{const expr}}"), + ty::ConstKind::Expr(expr) => self.pretty_print_const_expr(expr, print_ty)?, ty::ConstKind::Error(_) => p!("{{const error}}"), }; Ok(()) } + fn pretty_print_const_expr( + &mut self, + expr: Expr<'tcx>, + print_ty: bool, + ) -> Result<(), PrintError> { + define_scoped_cx!(self); + match expr { + Expr::Binop(op, c1, c2) => { + let precedence = |binop: rustc_middle::mir::BinOp| { + use rustc_ast::util::parser::AssocOp; + AssocOp::from_ast_binop(binop.to_hir_binop().into()).precedence() + }; + let op_precedence = precedence(op); + let formatted_op = op.to_hir_binop().as_str(); + let (lhs_parenthesized, rhs_parenthesized) = match (c1.kind(), c2.kind()) { + ( + ty::ConstKind::Expr(Expr::Binop(lhs_op, _, _)), + ty::ConstKind::Expr(Expr::Binop(rhs_op, _, _)), + ) => (precedence(lhs_op) < op_precedence, precedence(rhs_op) < op_precedence), + (ty::ConstKind::Expr(Expr::Binop(lhs_op, ..)), ty::ConstKind::Expr(_)) => { + (precedence(lhs_op) < op_precedence, true) + } + (ty::ConstKind::Expr(_), ty::ConstKind::Expr(Expr::Binop(rhs_op, ..))) => { + (true, precedence(rhs_op) < op_precedence) + } + (ty::ConstKind::Expr(_), ty::ConstKind::Expr(_)) => (true, true), + (ty::ConstKind::Expr(Expr::Binop(lhs_op, ..)), _) => { + (precedence(lhs_op) < op_precedence, false) + } + (_, ty::ConstKind::Expr(Expr::Binop(rhs_op, ..))) => { + (false, precedence(rhs_op) < op_precedence) + } + (ty::ConstKind::Expr(_), _) => (true, false), + (_, ty::ConstKind::Expr(_)) => (false, true), + _ => (false, false), + }; + + self.maybe_parenthesized( + |this| this.pretty_print_const(c1, print_ty), + lhs_parenthesized, + )?; + p!(write(" {formatted_op} ")); + self.maybe_parenthesized( + |this| this.pretty_print_const(c2, print_ty), + rhs_parenthesized, + )?; + } + Expr::UnOp(op, ct) => { + use rustc_middle::mir::UnOp; + let formatted_op = match op { + UnOp::Not => "!", + UnOp::Neg => "-", + }; + let parenthesized = match ct.kind() { + ty::ConstKind::Expr(Expr::UnOp(c_op, ..)) => c_op != op, + ty::ConstKind::Expr(_) => true, + _ => false, + }; + p!(write("{formatted_op}")); + self.maybe_parenthesized( + |this| this.pretty_print_const(ct, print_ty), + parenthesized, + )? + } + Expr::FunctionCall(fn_def, fn_args) => { + use ty::TyKind; + match fn_def.ty().kind() { + TyKind::FnDef(def_id, gen_args) => { + p!(print_value_path(*def_id, gen_args), "("); + if print_ty { + let tcx = self.tcx(); + let sig = tcx.fn_sig(def_id).instantiate(tcx, gen_args).skip_binder(); + + let mut args_with_ty = fn_args.iter().map(|ct| (ct, ct.ty())); + let output_ty = sig.output(); + + if let Some((ct, ty)) = args_with_ty.next() { + self.typed_value( + |this| this.pretty_print_const(ct, print_ty), + |this| this.pretty_print_type(ty), + ": ", + )?; + for (ct, ty) in args_with_ty { + p!(", "); + self.typed_value( + |this| this.pretty_print_const(ct, print_ty), + |this| this.pretty_print_type(ty), + ": ", + )?; + } + } + p!(write(") -> {output_ty}")); + } else { + p!(comma_sep(fn_args.iter()), ")"); + } + } + _ => bug!("unexpected type of fn def"), + } + } + Expr::Cast(kind, ct, ty) => { + use ty::abstract_const::CastKind; + if kind == CastKind::As || (kind == CastKind::Use && self.should_print_verbose()) { + let parenthesized = match ct.kind() { + ty::ConstKind::Expr(Expr::Cast(_, _, _)) => false, + ty::ConstKind::Expr(_) => true, + _ => false, + }; + self.maybe_parenthesized( + |this| { + this.typed_value( + |this| this.pretty_print_const(ct, print_ty), + |this| this.pretty_print_type(ty), + " as ", + ) + }, + parenthesized, + )?; + } else { + self.pretty_print_const(ct, print_ty)? + } + } + } + Ok(()) + } + fn pretty_print_const_scalar( &mut self, scalar: Scalar, diff --git a/compiler/rustc_middle/src/ty/region.rs b/compiler/rustc_middle/src/ty/region.rs index 7abc3cd2838..c66b9864e46 100644 --- a/compiler/rustc_middle/src/ty/region.rs +++ b/compiler/rustc_middle/src/ty/region.rs @@ -251,6 +251,7 @@ impl<'tcx> Region<'tcx> { } ty::ReError(_) => { flags = flags | TypeFlags::HAS_FREE_REGIONS; + flags = flags | TypeFlags::HAS_ERROR; } } @@ -336,7 +337,9 @@ pub struct EarlyParamRegion { impl std::fmt::Debug for EarlyParamRegion { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}, {}, {}", self.def_id, self.index, self.name) + // FIXME(BoxyUwU): self.def_id goes first because of `erased-regions-in-hidden-ty.rs` being impossible to write + // error annotations for otherwise. :). Ideally this would be `self.name, self.index, self.def_id`. + write!(f, "{:?}_{}/#{}", self.def_id, self.name, self.index) } } @@ -381,13 +384,25 @@ pub enum BoundRegionKind { BrEnv, } -#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, PartialOrd, Ord)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)] #[derive(HashStable)] pub struct BoundRegion { pub var: BoundVar, pub kind: BoundRegionKind, } +impl core::fmt::Debug for BoundRegion { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self.kind { + BoundRegionKind::BrAnon => write!(f, "{:?}", self.var), + BoundRegionKind::BrEnv => write!(f, "{:?}.Env", self.var), + BoundRegionKind::BrNamed(def, symbol) => { + write!(f, "{:?}.Named({:?}, {:?})", self.var, def, symbol) + } + } + } +} + impl BoundRegionKind { pub fn is_named(&self) -> bool { match *self { diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 11065b2a382..6e0a9eb86dd 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -483,7 +483,7 @@ impl<'tcx> CoroutineClosureSignature<'tcx> { self.to_coroutine( tcx, parent_args, - Ty::from_closure_kind(tcx, goal_kind), + Ty::from_coroutine_closure_kind(tcx, goal_kind), coroutine_def_id, tupled_upvars_ty, ) @@ -2456,6 +2456,25 @@ impl<'tcx> Ty<'tcx> { } } + /// Like [`Ty::to_opt_closure_kind`], but it caps the "maximum" closure kind + /// to `FnMut`. This is because although we have three capability states, + /// `AsyncFn`/`AsyncFnMut`/`AsyncFnOnce`, we only need to distinguish two coroutine + /// bodies: by-ref and by-value. + /// + /// See the definition of `AsyncFn` and `AsyncFnMut` and the `CallRefFuture` + /// associated type for why we don't distinguish [`ty::ClosureKind::Fn`] and + /// [`ty::ClosureKind::FnMut`] for the purpose of the generated MIR bodies. + /// + /// This method should be used when constructing a `Coroutine` out of a + /// `CoroutineClosure`, when the `Coroutine`'s `kind` field is being populated + /// directly from the `CoroutineClosure`'s `kind`. + pub fn from_coroutine_closure_kind(tcx: TyCtxt<'tcx>, kind: ty::ClosureKind) -> Ty<'tcx> { + match kind { + ty::ClosureKind::Fn | ty::ClosureKind::FnMut => tcx.types.i16, + ty::ClosureKind::FnOnce => tcx.types.i32, + } + } + /// Fast path helper for testing if a type is `Sized`. /// /// Returning true means the type is known to be sized. Returning @@ -2484,13 +2503,16 @@ impl<'tcx> Ty<'tcx> { | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Never - | ty::Error(_) => true, + | ty::Error(_) + | ty::Dynamic(_, _, ty::DynStar) => true, - ty::Str | ty::Slice(_) | ty::Dynamic(..) | ty::Foreign(..) => false, + ty::Str | ty::Slice(_) | ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => false, - ty::Tuple(tys) => tys.iter().all(|ty| ty.is_trivially_sized(tcx)), + ty::Tuple(tys) => tys.last().map_or(true, |ty| ty.is_trivially_sized(tcx)), - ty::Adt(def, _args) => def.sized_constraint(tcx).skip_binder().is_empty(), + ty::Adt(def, args) => def + .sized_constraint(tcx) + .map_or(true, |ty| ty.instantiate(tcx, args).is_trivially_sized(tcx)), ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) | ty::Bound(..) => false, diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index 4287b382604..d8541f4b25a 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -568,6 +568,11 @@ impl<'a, V> LocalTableInContextMut<'a, V> { self.data.get_mut(&id.local_id) } + pub fn get(&mut self, id: hir::HirId) -> Option<&V> { + validate_hir_id_for_typeck_results(self.hir_owner, id); + self.data.get(&id.local_id) + } + pub fn entry(&mut self, id: hir::HirId) -> Entry<'_, hir::ItemLocalId, V> { validate_hir_id_for_typeck_results(self.hir_owner, id); self.data.entry(id.local_id) diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index a6526b06851..e1081423489 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -682,6 +682,9 @@ impl<'tcx> TyCtxt<'tcx> { /// Return the set of types that should be taken into account when checking /// trait bounds on a coroutine's internal state. + // FIXME(compiler-errors): We should remove this when the old solver goes away; + // and all other usages of this function should go through `bound_coroutine_hidden_types` + // instead. pub fn coroutine_hidden_types( self, def_id: DefId, @@ -694,6 +697,33 @@ impl<'tcx> TyCtxt<'tcx> { .map(|decl| ty::EarlyBinder::bind(decl.ty)) } + /// Return the set of types that should be taken into account when checking + /// trait bounds on a coroutine's internal state. This properly replaces + /// `ReErased` with new existential bound lifetimes. + pub fn bound_coroutine_hidden_types( + self, + def_id: DefId, + ) -> impl Iterator<Item = ty::EarlyBinder<ty::Binder<'tcx, Ty<'tcx>>>> { + let coroutine_layout = self.mir_coroutine_witnesses(def_id); + coroutine_layout + .as_ref() + .map_or_else(|| [].iter(), |l| l.field_tys.iter()) + .filter(|decl| !decl.ignore_for_traits) + .map(move |decl| { + let mut vars = vec![]; + let ty = self.fold_regions(decl.ty, |re, debruijn| { + assert_eq!(re, self.lifetimes.re_erased); + let var = ty::BoundVar::from_usize(vars.len()); + vars.push(ty::BoundVariableKind::Region(ty::BrAnon)); + ty::Region::new_bound(self, debruijn, ty::BoundRegion { var, kind: ty::BrAnon }) + }); + ty::EarlyBinder::bind(ty::Binder::bind_with_vars( + ty, + self.mk_bound_variable_kinds(&vars), + )) + }) + } + /// Expands the given impl trait type, stopping if the type is recursive. #[instrument(skip(self), level = "debug", ret)] pub fn try_expand_impl_trait_type( @@ -998,8 +1028,10 @@ impl<'tcx> OpaqueTypeExpander<'tcx> { Some(expanded_ty) => *expanded_ty, None => { if matches!(self.inspect_coroutine_fields, InspectCoroutineFields::Yes) { - for bty in self.tcx.coroutine_hidden_types(def_id) { - let hidden_ty = bty.instantiate(self.tcx, args); + for bty in self.tcx.bound_coroutine_hidden_types(def_id) { + let hidden_ty = self.tcx.instantiate_bound_regions_with_erased( + bty.instantiate(self.tcx, args), + ); self.fold_ty(hidden_ty); } } diff --git a/compiler/rustc_middle/src/util/bug.rs b/compiler/rustc_middle/src/util/bug.rs index a67ec991582..43853a10896 100644 --- a/compiler/rustc_middle/src/util/bug.rs +++ b/compiler/rustc_middle/src/util/bug.rs @@ -28,14 +28,17 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>( args: fmt::Arguments<'_>, location: &Location<'_>, ) -> ! { - tls::with_opt(move |tcx| { - let msg = format!("{location}: {args}"); - match (tcx, span) { - (Some(tcx), Some(span)) => tcx.dcx().span_bug(span, msg), - (Some(tcx), None) => tcx.dcx().bug(msg), - (None, _) => panic_any(msg), - } - }) + tls::with_opt( + #[track_caller] + move |tcx| { + let msg = format!("{location}: {args}"); + match (tcx, span) { + (Some(tcx), Some(span)) => tcx.dcx().span_bug(span, msg), + (Some(tcx), None) => tcx.dcx().bug(msg), + (None, _) => panic_any(msg), + } + }, + ) } /// A query to trigger a delayed bug. Clearly, if one has a `tcx` one can already trigger a diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index f7a3879a7d4..5c17c0b3088 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -106,8 +106,8 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability { representable_ids.insert(def_id); } } - recursive_type_error(tcx, item_and_field_ids, &representable_ids); - Representability::Infinite + let guar = recursive_type_error(tcx, item_and_field_ids, &representable_ids); + Representability::Infinite(guar) } } @@ -268,7 +268,7 @@ pub fn recursive_type_error( tcx: TyCtxt<'_>, mut item_and_field_ids: Vec<(LocalDefId, LocalDefId)>, representable_ids: &FxHashSet<LocalDefId>, -) { +) -> ErrorGuaranteed { const ITEM_LIMIT: usize = 5; // Rotate the cycle so that the item with the lowest span is first @@ -344,7 +344,7 @@ pub fn recursive_type_error( suggestion, Applicability::HasPlaceholders, ) - .emit(); + .emit() } fn find_item_ty_spans( diff --git a/compiler/rustc_mir_build/messages.ftl b/compiler/rustc_mir_build/messages.ftl index 8a6ccdb8578..1de691f32a7 100644 --- a/compiler/rustc_mir_build/messages.ftl +++ b/compiler/rustc_mir_build/messages.ftl @@ -24,7 +24,7 @@ mir_build_borrow_of_layout_constrained_field_requires_unsafe_unsafe_op_in_unsafe mir_build_borrow_of_moved_value = borrow of moved value .label = value moved into `{$name}` here - .occurs_because_label = move occurs because `{$name}` has type `{$ty}` which does not implement the `Copy` trait + .occurs_because_label = move occurs because `{$name}` has type `{$ty}`, which does not implement the `Copy` trait .value_borrowed_label = value borrowed here after move .suggestion = borrow this binding in the pattern to avoid moving the value diff --git a/compiler/rustc_mir_build/src/build/custom/mod.rs b/compiler/rustc_mir_build/src/build/custom/mod.rs index 288b787798b..109ffedec55 100644 --- a/compiler/rustc_mir_build/src/build/custom/mod.rs +++ b/compiler/rustc_mir_build/src/build/custom/mod.rs @@ -56,6 +56,7 @@ pub(super) fn build_custom_mir<'tcx>( var_debug_info: Vec::new(), span, required_consts: Vec::new(), + mentioned_items: Vec::new(), is_polymorphic: false, tainted_by_errors: None, injection_phase: None, diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index e7808ff880b..f4f452d474f 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -229,7 +229,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { span: Span, scrutinee_span: Span, ) -> BlockAnd<()> { - let scrutinee_span = scrutinee_span; let scrutinee_place = unpack!(block = self.lower_scrutinee(block, scrutinee_id, scrutinee_span)); @@ -880,6 +879,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.visit_primary_bindings(subpattern, pattern_user_ty.deref(), f); } + PatKind::DerefPattern { ref subpattern } => { + self.visit_primary_bindings(subpattern, UserTypeProjections::none(), f); + } + PatKind::AscribeUserType { ref subpattern, ascription: thir::Ascription { ref annotation, variance: _ }, diff --git a/compiler/rustc_mir_build/src/build/matches/util.rs b/compiler/rustc_mir_build/src/build/matches/util.rs index d0d49c13f13..1148cd19a01 100644 --- a/compiler/rustc_mir_build/src/build/matches/util.rs +++ b/compiler/rustc_mir_build/src/build/matches/util.rs @@ -256,6 +256,12 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> { subpairs.push(MatchPair::new(place_builder, subpattern, cx)); default_irrefutable() } + + PatKind::DerefPattern { .. } => { + // FIXME(deref_patterns) + // Treat it like a wildcard for now. + default_irrefutable() + } }; MatchPair { place, test_case, subpairs, pattern } diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index 2fe5d3fb5e0..acadfe7b35e 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -1,7 +1,7 @@ use crate::build::expr::as_place::PlaceBuilder; use crate::build::scope::DropKind; use itertools::Itertools; -use rustc_apfloat::ieee::{Double, Single}; +use rustc_apfloat::ieee::{Double, Half, Quad, Single}; use rustc_apfloat::Float; use rustc_ast::attr; use rustc_data_structures::fx::FxHashMap; @@ -1013,8 +1013,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { if let Some(source_scope) = scope { self.source_scope = source_scope; } - - self.expr_into_dest(Place::return_place(), block, expr_id) + if self.tcx.intrinsic(self.def_id).is_some_and(|i| i.must_be_overridden) { + let source_info = self.source_info(rustc_span::DUMMY_SP); + self.cfg.terminate(block, source_info, TerminatorKind::Unreachable); + self.cfg.start_new_block().unit() + } else { + self.expr_into_dest(Place::return_place(), block, expr_id) + } } fn set_correct_source_scope_for_arg( @@ -1060,7 +1065,8 @@ pub(crate) fn parse_float_into_scalar( ) -> Option<Scalar> { let num = num.as_str(); match float_ty { - ty::FloatTy::F16 => unimplemented!("f16_f128"), + // FIXME(f16_f128): When available, compare to the library parser as with `f32` and `f64` + ty::FloatTy::F16 => num.parse::<Half>().ok().map(Scalar::from_f16), ty::FloatTy::F32 => { let Ok(rust_f) = num.parse::<f32>() else { return None }; let mut f = num @@ -1107,7 +1113,8 @@ pub(crate) fn parse_float_into_scalar( Some(Scalar::from_f64(f)) } - ty::FloatTy::F128 => unimplemented!("f16_f128"), + // FIXME(f16_f128): When available, compare to the library parser as with `f32` and `f64` + ty::FloatTy::F128 => num.parse::<Quad>().ok().map(Scalar::from_f128), } } diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index 88ac05cabb6..aef63896dde 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -774,7 +774,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let (current_root, parent_root) = if self.tcx.sess.opts.unstable_opts.maximal_hir_to_mir_coverage { // Some consumers of rustc need to map MIR locations back to HIR nodes. Currently - // the the only part of rustc that tracks MIR -> HIR is the + // the only part of rustc that tracks MIR -> HIR is the // `SourceScopeLocalData::lint_root` field that tracks lint levels for MIR // locations. Normally the number of source scopes is limited to the set of nodes // with lint annotations. The -Zmaximal-hir-to-mir-coverage flag changes this diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 1ce8da162bf..e04fe31a76f 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -250,6 +250,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { | PatKind::Variant { .. } | PatKind::Leaf { .. } | PatKind::Deref { .. } + | PatKind::DerefPattern { .. } | PatKind::Range { .. } | PatKind::Slice { .. } | PatKind::Array { .. } => { @@ -310,7 +311,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { } visit::walk_pat(self, pat); } - PatKind::Deref { .. } => { + PatKind::Deref { .. } | PatKind::DerefPattern { .. } => { let old_inside_adt = std::mem::replace(&mut self.inside_adt, false); visit::walk_pat(self, pat); self.inside_adt = old_inside_adt; diff --git a/compiler/rustc_mir_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs index e3f202b7f18..7b22aea9158 100644 --- a/compiler/rustc_mir_build/src/lib.rs +++ b/compiler/rustc_mir_build/src/lib.rs @@ -5,11 +5,10 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] #![feature(assert_matches)] -#![feature(associated_type_bounds)] +#![cfg_attr(bootstrap, feature(associated_type_bounds))] #![feature(box_patterns)] #![feature(if_let_guard)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(min_specialization))] #![feature(try_blocks)] #[macro_use] diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 20d3b3f98ce..434ed16d5c6 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -481,6 +481,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> { // when the iterator is an uninhabited type. unreachable_code will trigger instead. hir::MatchSource::ForLoopDesugar if arms.len() == 1 => {} hir::MatchSource::ForLoopDesugar + | hir::MatchSource::Postfix | hir::MatchSource::Normal | hir::MatchSource::FormatArgs => report_arm_reachability(&cx, &report), // Unreachable patterns in try and await expressions occur when one of @@ -938,9 +939,6 @@ fn report_non_exhaustive_match<'p, 'tcx>( }; // In the case of an empty match, replace the '`_` not covered' diagnostic with something more // informative. - let mut err; - let pattern; - let patterns_len; if is_empty_match && !non_empty_enum { return cx.tcx.dcx().emit_err(NonExhaustivePatternsTypeNotEmpty { cx, @@ -948,33 +946,23 @@ fn report_non_exhaustive_match<'p, 'tcx>( span: sp, ty: scrut_ty, }); - } else { - // FIXME: migration of this diagnostic will require list support - let joined_patterns = joined_uncovered_patterns(cx, &witnesses); - err = create_e0004( - cx.tcx.sess, - sp, - format!("non-exhaustive patterns: {joined_patterns} not covered"), - ); - err.span_label( - sp, - format!( - "pattern{} {} not covered", - rustc_errors::pluralize!(witnesses.len()), - joined_patterns - ), - ); - patterns_len = witnesses.len(); - pattern = if witnesses.len() < 4 { - witnesses - .iter() - .map(|witness| cx.hoist_witness_pat(witness).to_string()) - .collect::<Vec<String>>() - .join(" | ") - } else { - "_".to_string() - }; - }; + } + + // FIXME: migration of this diagnostic will require list support + let joined_patterns = joined_uncovered_patterns(cx, &witnesses); + let mut err = create_e0004( + cx.tcx.sess, + sp, + format!("non-exhaustive patterns: {joined_patterns} not covered"), + ); + err.span_label( + sp, + format!( + "pattern{} {} not covered", + rustc_errors::pluralize!(witnesses.len()), + joined_patterns + ), + ); // Point at the definition of non-covered `enum` variants. if let Some(AdtDefinedHere { adt_def_span, ty, variants }) = @@ -1021,6 +1009,23 @@ fn report_non_exhaustive_match<'p, 'tcx>( } } + // Whether we suggest the actual missing patterns or `_`. + let suggest_the_witnesses = witnesses.len() < 4; + let suggested_arm = if suggest_the_witnesses { + let pattern = witnesses + .iter() + .map(|witness| cx.hoist_witness_pat(witness).to_string()) + .collect::<Vec<String>>() + .join(" | "); + if witnesses.iter().all(|p| p.is_never_pattern()) && cx.tcx.features().never_patterns { + // Arms with a never pattern don't take a body. + pattern + } else { + format!("{pattern} => todo!()") + } + } else { + format!("_ => todo!()") + }; let mut suggestion = None; let sm = cx.tcx.sess.source_map(); match arms { @@ -1033,7 +1038,7 @@ fn report_non_exhaustive_match<'p, 'tcx>( }; suggestion = Some(( sp.shrink_to_hi().with_hi(expr_span.hi()), - format!(" {{{indentation}{more}{pattern} => todo!(),{indentation}}}",), + format!(" {{{indentation}{more}{suggested_arm},{indentation}}}",), )); } [only] => { @@ -1059,7 +1064,7 @@ fn report_non_exhaustive_match<'p, 'tcx>( }; suggestion = Some(( only.span.shrink_to_hi(), - format!("{comma}{pre_indentation}{pattern} => todo!()"), + format!("{comma}{pre_indentation}{suggested_arm}"), )); } [.., prev, last] => { @@ -1082,7 +1087,7 @@ fn report_non_exhaustive_match<'p, 'tcx>( if let Some(spacing) = spacing { suggestion = Some(( last.span.shrink_to_hi(), - format!("{comma}{spacing}{pattern} => todo!()"), + format!("{comma}{spacing}{suggested_arm}"), )); } } @@ -1093,13 +1098,13 @@ fn report_non_exhaustive_match<'p, 'tcx>( let msg = format!( "ensure that all possible cases are being handled by adding a match arm with a wildcard \ pattern{}{}", - if patterns_len > 1 && patterns_len < 4 && suggestion.is_some() { + if witnesses.len() > 1 && suggest_the_witnesses && suggestion.is_some() { ", a match arm with multiple or-patterns" } else { // we are either not suggesting anything, or suggesting `_` "" }, - match patterns_len { + match witnesses.len() { // non-exhaustive enum case 0 if suggestion.is_some() => " as shown", 0 => "", diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index ac3043afcff..0a7e9653377 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -257,6 +257,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { return self.lower_path(qpath, pat.hir_id, pat.span); } + hir::PatKind::Deref(subpattern) => { + PatKind::DerefPattern { subpattern: self.lower_pattern(subpattern) } + } hir::PatKind::Ref(subpattern, _) | hir::PatKind::Box(subpattern) => { PatKind::Deref { subpattern: self.lower_pattern(subpattern) } } @@ -524,12 +527,12 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { // Prefer valtrees over opaque constants. let const_value = self .tcx - .const_eval_global_id_for_typeck(param_env_reveal_all, cid, Some(span)) + .const_eval_global_id_for_typeck(param_env_reveal_all, cid, span) .map(|val| match val { Some(valtree) => mir::Const::Ty(ty::Const::new_value(self.tcx, valtree, ty)), None => mir::Const::Val( self.tcx - .const_eval_global_id(param_env_reveal_all, cid, Some(span)) + .const_eval_global_id(param_env_reveal_all, cid, span) .expect("const_eval_global_id_for_typeck should have already failed"), ty, ), @@ -627,15 +630,14 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { // First try using a valtree in order to destructure the constant into a pattern. // FIXME: replace "try to do a thing, then fall back to another thing" // but something more principled, like a trait query checking whether this can be turned into a valtree. - if let Ok(Some(valtree)) = - self.tcx.const_eval_resolve_for_typeck(self.param_env, ct, Some(span)) + if let Ok(Some(valtree)) = self.tcx.const_eval_resolve_for_typeck(self.param_env, ct, span) { let subpattern = self.const_to_pat(Const::Ty(ty::Const::new_value(self.tcx, valtree, ty)), id, span); PatKind::InlineConstant { subpattern, def: def_id } } else { // If that fails, convert it to an opaque constant pattern. - match tcx.const_eval_resolve(self.param_env, uneval, Some(span)) { + match tcx.const_eval_resolve(self.param_env, uneval, span) { Ok(val) => self.const_to_pat(mir::Const::Val(val, ty), id, span).kind, Err(ErrorHandled::TooGeneric(_)) => { // If we land here it means the const can't be evaluated because it's `TooGeneric`. diff --git a/compiler/rustc_mir_build/src/thir/print.rs b/compiler/rustc_mir_build/src/thir/print.rs index d53704f89e7..16c4248a159 100644 --- a/compiler/rustc_mir_build/src/thir/print.rs +++ b/compiler/rustc_mir_build/src/thir/print.rs @@ -688,6 +688,12 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> { self.print_pat(subpattern, depth_lvl + 2); print_indented!(self, "}", depth_lvl + 1); } + PatKind::DerefPattern { subpattern } => { + print_indented!(self, "DerefPattern { ", depth_lvl + 1); + print_indented!(self, "subpattern:", depth_lvl + 2); + self.print_pat(subpattern, depth_lvl + 2); + print_indented!(self, "}", depth_lvl + 1); + } PatKind::Constant { value } => { print_indented!(self, "Constant {", depth_lvl + 1); print_indented!(self, format!("value: {:?}", value), depth_lvl + 2); diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs index f18a2354301..c5adb81b614 100644 --- a/compiler/rustc_mir_dataflow/src/lib.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -2,7 +2,6 @@ #![feature(box_patterns)] #![feature(exact_size_is_empty)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(min_specialization))] #![feature(try_blocks)] #[macro_use] diff --git a/compiler/rustc_mir_transform/src/add_retag.rs b/compiler/rustc_mir_transform/src/add_retag.rs index 6f668aa4ce8..f880476cec2 100644 --- a/compiler/rustc_mir_transform/src/add_retag.rs +++ b/compiler/rustc_mir_transform/src/add_retag.rs @@ -24,7 +24,7 @@ fn may_contain_reference<'tcx>(ty: Ty<'tcx>, depth: u32, tcx: TyCtxt<'tcx>) -> b | ty::Str | ty::FnDef(..) | ty::Never => false, - // References + // References and Boxes (`noalias` sources) ty::Ref(..) => true, ty::Adt(..) if ty.is_box() => true, ty::Adt(adt, _) if Some(adt.did()) == tcx.lang_items().ptr_unique() => true, @@ -125,15 +125,39 @@ impl<'tcx> MirPass<'tcx> for AddRetag { for i in (0..block_data.statements.len()).rev() { let (retag_kind, place) = match block_data.statements[i].kind { // Retag after assignments of reference type. - StatementKind::Assign(box (ref place, ref rvalue)) if needs_retag(place) => { + StatementKind::Assign(box (ref place, ref rvalue)) => { let add_retag = match rvalue { // Ptr-creating operations already do their own internal retagging, no // need to also add a retag statement. - Rvalue::Ref(..) | Rvalue::AddressOf(..) => false, - _ => true, + // *Except* if we are deref'ing a Box, because those get desugared to directly working + // with the inner raw pointer! That's relevant for `AddressOf` as Miri otherwise makes it + // a NOP when the original pointer is already raw. + Rvalue::AddressOf(_mutbl, place) => { + // Using `is_box_global` here is a bit sketchy: if this code is + // generic over the allocator, we'll not add a retag! This is a hack + // to make Stacked Borrows compatible with custom allocator code. + // Long-term, we'll want to move to an aliasing model where "cast to + // raw pointer" is a complete NOP, and then this will no longer be + // an issue. + if place.is_indirect_first_projection() + && body.local_decls[place.local].ty.is_box_global(tcx) + { + Some(RetagKind::Raw) + } else { + None + } + } + Rvalue::Ref(..) => None, + _ => { + if needs_retag(place) { + Some(RetagKind::Default) + } else { + None + } + } }; - if add_retag { - (RetagKind::Default, *place) + if let Some(kind) = add_retag { + (kind, *place) } else { continue; } diff --git a/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs b/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs index 5b4bc4fa134..aaf2035fc21 100644 --- a/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs +++ b/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs @@ -5,15 +5,20 @@ //! - [`AscribeUserType`] //! - [`FakeRead`] //! - [`Assign`] statements with a [`Fake`] borrow +//! - [`Coverage`] statements of kind [`BlockMarker`] or [`SpanMarker`] //! //! [`AscribeUserType`]: rustc_middle::mir::StatementKind::AscribeUserType //! [`Assign`]: rustc_middle::mir::StatementKind::Assign //! [`FakeRead`]: rustc_middle::mir::StatementKind::FakeRead //! [`Nop`]: rustc_middle::mir::StatementKind::Nop //! [`Fake`]: rustc_middle::mir::BorrowKind::Fake +//! [`Coverage`]: rustc_middle::mir::StatementKind::Coverage +//! [`BlockMarker`]: rustc_middle::mir::coverage::CoverageKind::BlockMarker +//! [`SpanMarker`]: rustc_middle::mir::coverage::CoverageKind::SpanMarker use crate::MirPass; -use rustc_middle::mir::{Body, BorrowKind, Rvalue, StatementKind, TerminatorKind}; +use rustc_middle::mir::coverage::CoverageKind; +use rustc_middle::mir::{Body, BorrowKind, Coverage, Rvalue, StatementKind, TerminatorKind}; use rustc_middle::ty::TyCtxt; pub struct CleanupPostBorrowck; @@ -25,6 +30,12 @@ impl<'tcx> MirPass<'tcx> for CleanupPostBorrowck { match statement.kind { StatementKind::AscribeUserType(..) | StatementKind::Assign(box (_, Rvalue::Ref(_, BorrowKind::Fake, _))) + | StatementKind::Coverage(box Coverage { + // These kinds of coverage statements are markers inserted during + // MIR building, and are not needed after InstrumentCoverage. + kind: CoverageKind::BlockMarker { .. } | CoverageKind::SpanMarker { .. }, + .. + }) | StatementKind::FakeRead(..) => statement.make_nop(), _ => (), } diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index 54b13a40e92..0d18d4fd69e 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -1964,15 +1964,21 @@ fn check_must_not_suspend_ty<'tcx>( debug!("Checking must_not_suspend for {}", ty); match *ty.kind() { - ty::Adt(..) if ty.is_box() => { - let boxed_ty = ty.boxed_ty(); - let descr_pre = &format!("{}boxed ", data.descr_pre); + ty::Adt(_, args) if ty.is_box() => { + let boxed_ty = args.type_at(0); + let allocator_ty = args.type_at(1); check_must_not_suspend_ty( tcx, boxed_ty, hir_id, param_env, - SuspendCheckData { descr_pre, ..data }, + SuspendCheckData { descr_pre: &format!("{}boxed ", data.descr_pre), ..data }, + ) || check_must_not_suspend_ty( + tcx, + allocator_ty, + hir_id, + param_env, + SuspendCheckData { descr_pre: &format!("{}allocator ", data.descr_pre), ..data }, ) } ty::Adt(def, _) => check_must_not_suspend_def(tcx, def.did(), hir_id, data), diff --git a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs index e40f4520671..000b96ee801 100644 --- a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs +++ b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs @@ -67,45 +67,10 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody { by_move_body.source = mir::MirSource { instance: InstanceDef::CoroutineKindShim { coroutine_def_id: coroutine_def_id.to_def_id(), - target_kind: ty::ClosureKind::FnOnce, }, promoted: None, }; body.coroutine.as_mut().unwrap().by_move_body = Some(by_move_body); - - // If this is coming from an `AsyncFn` coroutine-closure, we must also create a by-mut body. - // This is actually just a copy of the by-ref body, but with a different self type. - // FIXME(async_closures): We could probably unify this with the by-ref body somehow. - if coroutine_kind == ty::ClosureKind::Fn { - let by_mut_coroutine_ty = Ty::new_coroutine( - tcx, - coroutine_def_id.to_def_id(), - ty::CoroutineArgs::new( - tcx, - ty::CoroutineArgsParts { - parent_args: args.as_coroutine().parent_args(), - kind_ty: Ty::from_closure_kind(tcx, ty::ClosureKind::FnMut), - resume_ty: args.as_coroutine().resume_ty(), - yield_ty: args.as_coroutine().yield_ty(), - return_ty: args.as_coroutine().return_ty(), - witness: args.as_coroutine().witness(), - tupled_upvars_ty: args.as_coroutine().tupled_upvars_ty(), - }, - ) - .args, - ); - let mut by_mut_body = body.clone(); - by_mut_body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty = by_mut_coroutine_ty; - dump_mir(tcx, false, "coroutine_by_mut", &0, &by_mut_body, |_, _| Ok(())); - by_mut_body.source = mir::MirSource { - instance: InstanceDef::CoroutineKindShim { - coroutine_def_id: coroutine_def_id.to_def_id(), - target_kind: ty::ClosureKind::FnMut, - }, - promoted: None, - }; - body.coroutine.as_mut().unwrap().by_mut_body = Some(by_mut_body); - } } } diff --git a/compiler/rustc_mir_transform/src/coverage/counters.rs b/compiler/rustc_mir_transform/src/coverage/counters.rs index 9a1d8bae6b4..69dc4f2ddea 100644 --- a/compiler/rustc_mir_transform/src/coverage/counters.rs +++ b/compiler/rustc_mir_transform/src/coverage/counters.rs @@ -1,13 +1,12 @@ +use std::fmt::{self, Debug}; + use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::graph::WithNumNodes; -use rustc_index::bit_set::BitSet; use rustc_index::IndexVec; -use rustc_middle::mir::coverage::*; +use rustc_middle::mir::coverage::{CounterId, CovTerm, Expression, ExpressionId, Op}; -use super::graph::{BasicCoverageBlock, CoverageGraph, TraverseCoverageGraphWithLoops}; - -use std::fmt::{self, Debug}; +use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph, TraverseCoverageGraphWithLoops}; /// The coverage counter or counter expression associated with a particular /// BCB node or BCB edge. @@ -18,10 +17,6 @@ pub(super) enum BcbCounter { } impl BcbCounter { - fn is_expression(&self) -> bool { - matches!(self, Self::Expression { .. }) - } - pub(super) fn as_term(&self) -> CovTerm { match *self { BcbCounter::Counter { id, .. } => CovTerm::Counter(id), @@ -60,10 +55,6 @@ pub(super) struct CoverageCounters { /// We currently don't iterate over this map, but if we do in the future, /// switch it back to `FxIndexMap` to avoid query stability hazards. bcb_edge_counters: FxHashMap<(BasicCoverageBlock, BasicCoverageBlock), BcbCounter>, - /// Tracks which BCBs have a counter associated with some incoming edge. - /// Only used by assertions, to verify that BCBs with incoming edge - /// counters do not have their own physical counters (expressions are allowed). - bcb_has_incoming_edge_counters: BitSet<BasicCoverageBlock>, /// Table of expression data, associating each expression ID with its /// corresponding operator (+ or -) and its LHS/RHS operands. expressions: IndexVec<ExpressionId, Expression>, @@ -83,7 +74,6 @@ impl CoverageCounters { counter_increment_sites: IndexVec::new(), bcb_counters: IndexVec::from_elem_n(None, num_bcbs), bcb_edge_counters: FxHashMap::default(), - bcb_has_incoming_edge_counters: BitSet::new_empty(num_bcbs), expressions: IndexVec::new(), }; @@ -122,14 +112,6 @@ impl CoverageCounters { } fn set_bcb_counter(&mut self, bcb: BasicCoverageBlock, counter_kind: BcbCounter) -> BcbCounter { - assert!( - // If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also - // have an expression (to be injected into an existing `BasicBlock` represented by this - // `BasicCoverageBlock`). - counter_kind.is_expression() || !self.bcb_has_incoming_edge_counters.contains(bcb), - "attempt to add a `Counter` to a BCB target with existing incoming edge counters" - ); - if let Some(replaced) = self.bcb_counters[bcb].replace(counter_kind) { bug!( "attempt to set a BasicCoverageBlock coverage counter more than once; \ @@ -146,19 +128,6 @@ impl CoverageCounters { to_bcb: BasicCoverageBlock, counter_kind: BcbCounter, ) -> BcbCounter { - // If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also - // have an expression (to be injected into an existing `BasicBlock` represented by this - // `BasicCoverageBlock`). - if let Some(node_counter) = self.bcb_counter(to_bcb) - && !node_counter.is_expression() - { - bug!( - "attempt to add an incoming edge counter from {from_bcb:?} \ - when the target BCB already has {node_counter:?}" - ); - } - - self.bcb_has_incoming_edge_counters.insert(to_bcb); if let Some(replaced) = self.bcb_edge_counters.insert((from_bcb, to_bcb), counter_kind) { bug!( "attempt to set an edge counter more than once; from_bcb: \ diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index b2407c54507..83189c6a50a 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -13,7 +13,6 @@ use self::spans::{BcbMapping, BcbMappingKind, CoverageSpans}; use crate::MirPass; -use rustc_middle::hir; use rustc_middle::mir::coverage::*; use rustc_middle::mir::{ self, BasicBlock, BasicBlockData, Coverage, SourceInfo, Statement, StatementKind, Terminator, @@ -368,8 +367,7 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir // to HIR for it. let hir_node = tcx.hir_node_by_def_id(def_id); - let (_, fn_body_id) = - hir::map::associated_body(hir_node).expect("HIR node is a function with body"); + let fn_body_id = hir_node.body_id().expect("HIR node is a function with body"); let hir_body = tcx.hir().body(fn_body_id); let maybe_fn_sig = hir_node.fn_sig(); diff --git a/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs b/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs index 86097bdcd95..3f6a4156044 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs @@ -401,9 +401,8 @@ pub(super) fn extract_branch_mappings( } let (span, _) = unexpand_into_body_span_with_visible_macro(raw_span, body_span)?; - let bcb_from_marker = |marker: BlockMarkerId| { - Some(basic_coverage_blocks.bcb_from_bb(block_markers[marker]?)?) - }; + let bcb_from_marker = + |marker: BlockMarkerId| basic_coverage_blocks.bcb_from_bb(block_markers[marker]?); let true_bcb = bcb_from_marker(true_marker)?; let false_bcb = bcb_from_marker(false_marker)?; diff --git a/compiler/rustc_mir_transform/src/cross_crate_inline.rs b/compiler/rustc_mir_transform/src/cross_crate_inline.rs index 07e6ecccaa4..483fd753e70 100644 --- a/compiler/rustc_mir_transform/src/cross_crate_inline.rs +++ b/compiler/rustc_mir_transform/src/cross_crate_inline.rs @@ -23,10 +23,6 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { return false; } - if tcx.intrinsic(def_id).is_some_and(|i| i.must_be_overridden) { - return false; - } - // This just reproduces the logic from Instance::requires_inline. match tcx.def_kind(def_id) { DefKind::Ctor(..) | DefKind::Closure => return true, diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index f456196b282..3389305e7ee 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -394,7 +394,7 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> { } Operand::Constant(box constant) => { if let Ok(constant) = - self.ecx.eval_mir_constant(&constant.const_, Some(constant.span), None) + self.ecx.eval_mir_constant(&constant.const_, constant.span, None) { self.assign_constant(state, place, constant, &[]); } diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index a3a2108787a..87dff49e0be 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -367,7 +367,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { Repeat(..) => return None, Constant { ref value, disambiguator: _ } => { - self.ecx.eval_mir_constant(value, None, None).ok()? + self.ecx.eval_mir_constant(value, DUMMY_SP, None).ok()? } Aggregate(kind, variant, ref fields) => { let fields = fields diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index f6a0945c222..4ec76eec3a9 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -565,7 +565,8 @@ impl<'tcx> Inliner<'tcx> { mut callee_body: Body<'tcx>, ) { let terminator = caller_body[callsite.block].terminator.take().unwrap(); - let TerminatorKind::Call { args, destination, unwind, target, .. } = terminator.kind else { + let TerminatorKind::Call { func, args, destination, unwind, target, .. } = terminator.kind + else { bug!("unexpected terminator kind {:?}", terminator.kind); }; @@ -717,6 +718,24 @@ impl<'tcx> Inliner<'tcx> { Const::Val(..) | Const::Unevaluated(..) => true, }, )); + // Now that we incorporated the callee's `required_consts`, we can remove the callee from + // `mentioned_items` -- but we have to take their `mentioned_items` in return. This does + // some extra work here to save the monomorphization collector work later. It helps a lot, + // since monomorphization can avoid a lot of work when the "mentioned items" are similar to + // the actually used items. By doing this we can entirely avoid visiting the callee! + // We need to reconstruct the `required_item` for the callee so that we can find and + // remove it. + let callee_item = MentionedItem::Fn(func.ty(caller_body, self.tcx)); + if let Some(idx) = + caller_body.mentioned_items.iter().position(|item| item.node == callee_item) + { + // We found the callee, so remove it and add its items instead. + caller_body.mentioned_items.remove(idx); + caller_body.mentioned_items.extend(callee_body.mentioned_items); + } else { + // If we can't find the callee, there's no point in adding its items. + // Probably it already got removed by being inlined elsewhere in the same function. + } } fn make_call_args( diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index 6629face940..116d6f48456 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -417,7 +417,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> { // If we expect `lhs ?= A`, we have an opportunity if we assume `constant == A`. Operand::Constant(constant) => { let constant = - self.ecx.eval_mir_constant(&constant.const_, Some(constant.span), None).ok()?; + self.ecx.eval_mir_constant(&constant.const_, constant.span, None).ok()?; self.process_constant(bb, lhs, constant, state); } // Transfer the conditions on the copied rhs. diff --git a/compiler/rustc_mir_transform/src/known_panics_lint.rs b/compiler/rustc_mir_transform/src/known_panics_lint.rs index 4bca437ea6f..f19b78a3a5c 100644 --- a/compiler/rustc_mir_transform/src/known_panics_lint.rs +++ b/compiler/rustc_mir_transform/src/known_panics_lint.rs @@ -261,7 +261,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // manually normalized. let val = self.tcx.try_normalize_erasing_regions(self.param_env, c.const_).ok()?; - self.use_ecx(|this| this.ecx.eval_mir_constant(&val, Some(c.span), None))? + self.use_ecx(|this| this.ecx.eval_mir_constant(&val, c.span, None))? .as_mplace_or_imm() .right() } diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 45513801522..24bc263e5a7 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -8,7 +8,6 @@ #![feature(is_sorted)] #![feature(let_chains)] #![feature(map_try_insert)] -#![cfg_attr(bootstrap, feature(min_specialization))] #![feature(never_type)] #![feature(option_get_or_insert_default)] #![feature(round_char_boundary)] @@ -89,6 +88,7 @@ mod lint; mod lower_intrinsics; mod lower_slice_len; mod match_branches; +mod mentioned_items; mod multiple_return_terminators; mod normalize_array_len; mod nrvo; @@ -507,7 +507,7 @@ fn run_analysis_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let passes: &[&dyn MirPass<'tcx>] = &[ &cleanup_post_borrowck::CleanupPostBorrowck, &remove_noop_landing_pads::RemoveNoopLandingPads, - &simplify::SimplifyCfg::EarlyOpt, + &simplify::SimplifyCfg::PostAnalysis, &deref_separator::Derefer, ]; @@ -529,11 +529,11 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { // AddMovesForPackedDrops needs to run after drop // elaboration. &add_moves_for_packed_drops::AddMovesForPackedDrops, - // `AddRetag` needs to run after `ElaborateDrops`. Otherwise it should run fairly late, + // `AddRetag` needs to run after `ElaborateDrops` but before `ElaborateBoxDerefs`. Otherwise it should run fairly late, // but before optimizations begin. + &add_retag::AddRetag, &elaborate_box_derefs::ElaborateBoxDerefs, &coroutine::StateTransform, - &add_retag::AddRetag, &Lint(known_panics_lint::KnownPanicsLint), ]; pm::run_passes_no_validate(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::Initial))); @@ -544,7 +544,7 @@ fn run_runtime_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let passes: &[&dyn MirPass<'tcx>] = &[ &lower_intrinsics::LowerIntrinsics, &remove_place_mention::RemovePlaceMention, - &simplify::SimplifyCfg::ElaborateDrops, + &simplify::SimplifyCfg::PreOptimizations, ]; pm::run_passes(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::PostCleanup))); @@ -566,6 +566,10 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { tcx, body, &[ + // Before doing anything, remember which items are being mentioned so that the set of items + // visited does not depend on the optimization level. + &mentioned_items::MentionedItems, + // Add some UB checks before any UB gets optimized away. &check_alignment::CheckAlignment, // Before inlining: trim down MIR with passes to reduce inlining work. @@ -633,12 +637,6 @@ fn optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> &Body<'_> { } fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> { - if tcx.intrinsic(did).is_some_and(|i| i.must_be_overridden) { - span_bug!( - tcx.def_span(did), - "this intrinsic must be overridden by the codegen backend, it has no meaningful body", - ) - } if tcx.is_constructor(did.to_def_id()) { // There's no reason to run all of the MIR passes on constructors when // we can just output the MIR we want directly. This also saves const diff --git a/compiler/rustc_mir_transform/src/mentioned_items.rs b/compiler/rustc_mir_transform/src/mentioned_items.rs new file mode 100644 index 00000000000..57b6126dece --- /dev/null +++ b/compiler/rustc_mir_transform/src/mentioned_items.rs @@ -0,0 +1,117 @@ +use rustc_middle::mir::visit::Visitor; +use rustc_middle::mir::{self, Location, MentionedItem, MirPass}; +use rustc_middle::ty::{self, adjustment::PointerCoercion, TyCtxt}; +use rustc_session::Session; +use rustc_span::source_map::Spanned; + +pub struct MentionedItems; + +struct MentionedItemsVisitor<'a, 'tcx> { + tcx: TyCtxt<'tcx>, + body: &'a mir::Body<'tcx>, + mentioned_items: &'a mut Vec<Spanned<MentionedItem<'tcx>>>, +} + +impl<'tcx> MirPass<'tcx> for MentionedItems { + fn is_enabled(&self, _sess: &Session) -> bool { + // If this pass is skipped the collector assume that nothing got mentioned! We could + // potentially skip it in opt-level 0 if we are sure that opt-level will never *remove* uses + // of anything, but that still seems fragile. Furthermore, even debug builds use level 1, so + // special-casing level 0 is just not worth it. + true + } + + fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut mir::Body<'tcx>) { + debug_assert!(body.mentioned_items.is_empty()); + let mut mentioned_items = Vec::new(); + MentionedItemsVisitor { tcx, body, mentioned_items: &mut mentioned_items }.visit_body(body); + body.mentioned_items = mentioned_items; + } +} + +// This visitor is carefully in sync with the one in `rustc_monomorphize::collector`. We are +// visiting the exact same places but then instead of monomorphizing and creating `MonoItems`, we +// have to remain generic and just recording the relevant information in `mentioned_items`, where it +// will then be monomorphized later during "mentioned items" collection. +impl<'tcx> Visitor<'tcx> for MentionedItemsVisitor<'_, 'tcx> { + fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) { + self.super_terminator(terminator, location); + let span = || self.body.source_info(location).span; + match &terminator.kind { + mir::TerminatorKind::Call { func, .. } => { + let callee_ty = func.ty(self.body, self.tcx); + self.mentioned_items + .push(Spanned { node: MentionedItem::Fn(callee_ty), span: span() }); + } + mir::TerminatorKind::Drop { place, .. } => { + let ty = place.ty(self.body, self.tcx).ty; + self.mentioned_items.push(Spanned { node: MentionedItem::Drop(ty), span: span() }); + } + mir::TerminatorKind::InlineAsm { ref operands, .. } => { + for op in operands { + match *op { + mir::InlineAsmOperand::SymFn { ref value } => { + self.mentioned_items.push(Spanned { + node: MentionedItem::Fn(value.const_.ty()), + span: span(), + }); + } + _ => {} + } + } + } + _ => {} + } + } + + fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) { + self.super_rvalue(rvalue, location); + let span = || self.body.source_info(location).span; + match *rvalue { + // We need to detect unsizing casts that required vtables. + mir::Rvalue::Cast( + mir::CastKind::PointerCoercion(PointerCoercion::Unsize), + ref operand, + target_ty, + ) + | mir::Rvalue::Cast(mir::CastKind::DynStar, ref operand, target_ty) => { + // This isn't monomorphized yet so we can't tell what the actual types are -- just + // add everything that may involve a vtable. + let source_ty = operand.ty(self.body, self.tcx); + let may_involve_vtable = match ( + source_ty.builtin_deref(true).map(|t| t.ty.kind()), + target_ty.builtin_deref(true).map(|t| t.ty.kind()), + ) { + (Some(ty::Array(..)), Some(ty::Str | ty::Slice(..))) => false, // &str/&[T] unsizing + _ => true, + }; + if may_involve_vtable { + self.mentioned_items.push(Spanned { + node: MentionedItem::UnsizeCast { source_ty, target_ty }, + span: span(), + }); + } + } + // Similarly, record closures that are turned into function pointers. + mir::Rvalue::Cast( + mir::CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(_)), + ref operand, + _, + ) => { + let source_ty = operand.ty(self.body, self.tcx); + self.mentioned_items + .push(Spanned { node: MentionedItem::Closure(source_ty), span: span() }); + } + // And finally, function pointer reification casts. + mir::Rvalue::Cast( + mir::CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer), + ref operand, + _, + ) => { + let fn_ty = operand.ty(self.body, self.tcx); + self.mentioned_items.push(Spanned { node: MentionedItem::Fn(fn_ty), span: span() }); + } + _ => {} + } + } +} diff --git a/compiler/rustc_mir_transform/src/pass_manager.rs b/compiler/rustc_mir_transform/src/pass_manager.rs index 77478cc741d..17a1c3c7157 100644 --- a/compiler/rustc_mir_transform/src/pass_manager.rs +++ b/compiler/rustc_mir_transform/src/pass_manager.rs @@ -186,9 +186,6 @@ fn run_passes_inner<'tcx>( if let Some(by_move_body) = coroutine.by_move_body.as_mut() { run_passes_inner(tcx, by_move_body, passes, phase_change, validate_each); } - if let Some(by_mut_body) = coroutine.by_mut_body.as_mut() { - run_passes_inner(tcx, by_mut_body, passes, phase_change, validate_each); - } } } diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 733e2f93b25..71de64c6d26 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -3,8 +3,8 @@ use rustc_hir::def_id::DefId; use rustc_hir::lang_items::LangItem; use rustc_middle::mir::*; use rustc_middle::query::Providers; +use rustc_middle::ty::GenericArgs; use rustc_middle::ty::{self, CoroutineArgs, EarlyBinder, Ty, TyCtxt}; -use rustc_middle::ty::{GenericArgs, CAPTURE_STRUCT_LOCAL}; use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT}; use rustc_index::{Idx, IndexVec}; @@ -17,7 +17,7 @@ use std::iter; use crate::{ abort_unwinding_calls, add_call_guards, add_moves_for_packed_drops, deref_separator, - pass_manager as pm, remove_noop_landing_pads, simplify, + mentioned_items, pass_manager as pm, remove_noop_landing_pads, simplify, }; use rustc_middle::mir::patch::MirPatch; use rustc_mir_dataflow::elaborate_drops::{self, DropElaborator, DropFlagMode, DropStyle}; @@ -72,37 +72,12 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<' ty::InstanceDef::ConstructCoroutineInClosureShim { coroutine_closure_def_id, - target_kind, - } => match target_kind { - ty::ClosureKind::Fn => unreachable!("shouldn't be building shim for Fn"), - ty::ClosureKind::FnMut => { - // No need to optimize the body, it has already been optimized - // since we steal it from the `AsyncFn::call` body and just fix - // the return type. - return build_construct_coroutine_by_mut_shim(tcx, coroutine_closure_def_id); - } - ty::ClosureKind::FnOnce => { - build_construct_coroutine_by_move_shim(tcx, coroutine_closure_def_id) - } - }, + receiver_by_ref, + } => build_construct_coroutine_by_move_shim(tcx, coroutine_closure_def_id, receiver_by_ref), - ty::InstanceDef::CoroutineKindShim { coroutine_def_id, target_kind } => match target_kind { - ty::ClosureKind::Fn => unreachable!(), - ty::ClosureKind::FnMut => { - return tcx - .optimized_mir(coroutine_def_id) - .coroutine_by_mut_body() - .unwrap() - .clone(); - } - ty::ClosureKind::FnOnce => { - return tcx - .optimized_mir(coroutine_def_id) - .coroutine_by_move_body() - .unwrap() - .clone(); - } - }, + ty::InstanceDef::CoroutineKindShim { coroutine_def_id } => { + return tcx.optimized_mir(coroutine_def_id).coroutine_by_move_body().unwrap().clone(); + } ty::InstanceDef::DropGlue(def_id, ty) => { // FIXME(#91576): Drop shims for coroutines aren't subject to the MIR passes at the end @@ -123,21 +98,11 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<' let body = if id_args.as_coroutine().kind_ty() == args.as_coroutine().kind_ty() { coroutine_body.coroutine_drop().unwrap() } else { - match args.as_coroutine().kind_ty().to_opt_closure_kind().unwrap() { - ty::ClosureKind::Fn => { - unreachable!() - } - ty::ClosureKind::FnMut => coroutine_body - .coroutine_by_mut_body() - .unwrap() - .coroutine_drop() - .unwrap(), - ty::ClosureKind::FnOnce => coroutine_body - .coroutine_by_move_body() - .unwrap() - .coroutine_drop() - .unwrap(), - } + assert_eq!( + args.as_coroutine().kind_ty().to_opt_closure_kind().unwrap(), + ty::ClosureKind::FnOnce + ); + coroutine_body.coroutine_by_move_body().unwrap().coroutine_drop().unwrap() }; let mut body = EarlyBinder::bind(body.clone()).instantiate(tcx, args); @@ -147,6 +112,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<' tcx, &mut body, &[ + &mentioned_items::MentionedItems, &abort_unwinding_calls::AbortUnwindingCalls, &add_call_guards::CriticalCallEdges, ], @@ -178,6 +144,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<' tcx, &mut result, &[ + &mentioned_items::MentionedItems, &add_moves_for_packed_drops::AddMovesForPackedDrops, &deref_separator::Derefer, &remove_noop_landing_pads::RemoveNoopLandingPads, @@ -1051,12 +1018,26 @@ fn build_fn_ptr_addr_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'t fn build_construct_coroutine_by_move_shim<'tcx>( tcx: TyCtxt<'tcx>, coroutine_closure_def_id: DefId, + receiver_by_ref: bool, ) -> Body<'tcx> { - let self_ty = tcx.type_of(coroutine_closure_def_id).instantiate_identity(); + let mut self_ty = tcx.type_of(coroutine_closure_def_id).instantiate_identity(); let ty::CoroutineClosure(_, args) = *self_ty.kind() else { bug!(); }; + // We use `*mut Self` here because we only need to emit an ABI-compatible shim body, + // rather than match the signature exactly. + // + // The self type here is a coroutine-closure, not a coroutine, and we never read from + // it because it never has any captures, because this is only true in the Fn/FnMut + // implementation, not the AsyncFn/AsyncFnMut implementation, which is implemented only + // if the coroutine-closure has no captures. + if receiver_by_ref { + // Triple-check that there's no captures here. + assert_eq!(args.as_coroutine_closure().tupled_upvars_ty(), tcx.types.unit); + self_ty = Ty::new_mut_ptr(tcx, self_ty); + } + let poly_sig = args.as_coroutine_closure().coroutine_closure_sig().map_bound(|sig| { tcx.mk_fn_sig( [self_ty].into_iter().chain(sig.tupled_inputs_ty.tuple_fields()), @@ -1112,49 +1093,19 @@ fn build_construct_coroutine_by_move_shim<'tcx>( let source = MirSource::from_instance(ty::InstanceDef::ConstructCoroutineInClosureShim { coroutine_closure_def_id, - target_kind: ty::ClosureKind::FnOnce, + receiver_by_ref, }); let body = new_body(source, IndexVec::from_elem_n(start_block, 1), locals, sig.inputs().len(), span); - dump_mir(tcx, false, "coroutine_closure_by_move", &0, &body, |_, _| Ok(())); - - body -} - -fn build_construct_coroutine_by_mut_shim<'tcx>( - tcx: TyCtxt<'tcx>, - coroutine_closure_def_id: DefId, -) -> Body<'tcx> { - let mut body = tcx.optimized_mir(coroutine_closure_def_id).clone(); - let coroutine_closure_ty = tcx.type_of(coroutine_closure_def_id).instantiate_identity(); - let ty::CoroutineClosure(_, args) = *coroutine_closure_ty.kind() else { - bug!(); - }; - let args = args.as_coroutine_closure(); - - body.local_decls[RETURN_PLACE].ty = - tcx.instantiate_bound_regions_with_erased(args.coroutine_closure_sig().map_bound(|sig| { - sig.to_coroutine_given_kind_and_upvars( - tcx, - args.parent_args(), - tcx.coroutine_for_closure(coroutine_closure_def_id), - ty::ClosureKind::FnMut, - tcx.lifetimes.re_erased, - args.tupled_upvars_ty(), - args.coroutine_captures_by_ref_ty(), - ) - })); - body.local_decls[CAPTURE_STRUCT_LOCAL].ty = - Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, coroutine_closure_ty); - - body.source = MirSource::from_instance(ty::InstanceDef::ConstructCoroutineInClosureShim { - coroutine_closure_def_id, - target_kind: ty::ClosureKind::FnMut, - }); - - body.pass_count = 0; - dump_mir(tcx, false, "coroutine_closure_by_mut", &0, &body, |_, _| Ok(())); + dump_mir( + tcx, + false, + if receiver_by_ref { "coroutine_closure_by_ref" } else { "coroutine_closure_by_move" }, + &0, + &body, + |_, _| Ok(()), + ); body } diff --git a/compiler/rustc_mir_transform/src/simplify.rs b/compiler/rustc_mir_transform/src/simplify.rs index 8c8818bd68e..574330cc355 100644 --- a/compiler/rustc_mir_transform/src/simplify.rs +++ b/compiler/rustc_mir_transform/src/simplify.rs @@ -37,8 +37,11 @@ pub enum SimplifyCfg { Initial, PromoteConsts, RemoveFalseEdges, - EarlyOpt, - ElaborateDrops, + /// Runs at the beginning of "analysis to runtime" lowering, *before* drop elaboration. + PostAnalysis, + /// Runs at the end of "analysis to runtime" lowering, *after* drop elaboration. + /// This is before the main optimization passes on runtime MIR kick in. + PreOptimizations, Final, MakeShim, AfterUninhabitedEnumBranching, @@ -50,8 +53,8 @@ impl SimplifyCfg { SimplifyCfg::Initial => "SimplifyCfg-initial", SimplifyCfg::PromoteConsts => "SimplifyCfg-promote-consts", SimplifyCfg::RemoveFalseEdges => "SimplifyCfg-remove-false-edges", - SimplifyCfg::EarlyOpt => "SimplifyCfg-early-opt", - SimplifyCfg::ElaborateDrops => "SimplifyCfg-elaborate-drops", + SimplifyCfg::PostAnalysis => "SimplifyCfg-post-analysis", + SimplifyCfg::PreOptimizations => "SimplifyCfg-pre-optimizations", SimplifyCfg::Final => "SimplifyCfg-final", SimplifyCfg::MakeShim => "SimplifyCfg-make_shim", SimplifyCfg::AfterUninhabitedEnumBranching => { diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index cf4a62a5edf..673cd968e28 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -28,6 +28,7 @@ //! - VTables //! - Object Shims //! +//! The main entry point is `collect_crate_mono_items`, at the bottom of this file. //! //! General Algorithm //! ----------------- @@ -137,21 +138,61 @@ //! just linked to and no node is created; which is exactly what we want, since //! no machine code should be generated in the current crate for such an item. //! -//! Eager and Lazy Collection Mode -//! ------------------------------ -//! Mono item collection can be performed in one of two modes: +//! Eager and Lazy Collection Strategy +//! ---------------------------------- +//! Mono item collection can be performed with one of two strategies: //! -//! - Lazy mode means that items will only be instantiated when actually +//! - Lazy strategy means that items will only be instantiated when actually //! used. The goal is to produce the least amount of machine code //! possible. //! -//! - Eager mode is meant to be used in conjunction with incremental compilation +//! - Eager strategy is meant to be used in conjunction with incremental compilation //! where a stable set of mono items is more important than a minimal -//! one. Thus, eager mode will instantiate drop-glue for every drop-able type +//! one. Thus, eager strategy will instantiate drop-glue for every drop-able type //! in the crate, even if no drop call for that type exists (yet). It will //! also instantiate default implementations of trait methods, something that //! otherwise is only done on demand. //! +//! Collection-time const evaluation and "mentioned" items +//! ------------------------------------------------------ +//! +//! One important role of collection is to evaluate all constants that are used by all the items +//! which are being collected. Codegen can then rely on only encountering constants that evaluate +//! successfully, and if a constant fails to evaluate, the collector has much better context to be +//! able to show where this constant comes up. +//! +//! However, the exact set of "used" items (collected as described above), and therefore the exact +//! set of used constants, can depend on optimizations. Optimizing away dead code may optimize away +//! a function call that uses a failing constant, so an unoptimized build may fail where an +//! optimized build succeeds. This is undesirable. +//! +//! To avoid this, the collector has the concept of "mentioned" items. Some time during the MIR +//! pipeline, before any optimization-level-dependent optimizations, we compute a list of all items +//! that syntactically appear in the code. These are considered "mentioned", and even if they are in +//! dead code and get optimized away (which makes them no longer "used"), they are still +//! "mentioned". For every used item, the collector ensures that all mentioned items, recursively, +//! do not use a failing constant. This is reflected via the [`CollectionMode`], which determines +//! whether we are visiting a used item or merely a mentioned item. +//! +//! The collector and "mentioned items" gathering (which lives in `rustc_mir_transform::mentioned_items`) +//! need to stay in sync in the following sense: +//! +//! - For every item that the collector gather that could eventually lead to build failure (most +//! likely due to containing a constant that fails to evaluate), a corresponding mentioned item +//! must be added. This should use the exact same strategy as the ecollector to make sure they are +//! in sync. However, while the collector works on monomorphized types, mentioned items are +//! collected on generic MIR -- so any time the collector checks for a particular type (such as +//! `ty::FnDef`), we have to just onconditionally add this as a mentioned item. +//! - In `visit_mentioned_item`, we then do with that mentioned item exactly what the collector +//! would have done during regular MIR visiting. Basically you can think of the collector having +//! two stages, a pre-monomorphization stage and a post-monomorphization stage (usually quite +//! literally separated by a call to `self.monomorphize`); the pre-monomorphizationn stage is +//! duplicated in mentioned items gathering and the post-monomorphization stage is duplicated in +//! `visit_mentioned_item`. +//! - Finally, as a performance optimization, the collector should fill `used_mentioned_item` during +//! its MIR traversal with exactly what mentioned item gathering would have added in the same +//! situation. This detects mentioned items that have *not* been optimized away and hence don't +//! need a dedicated traversal. //! //! Open Issues //! ----------- @@ -165,15 +206,16 @@ //! regardless of whether it is actually needed or not. use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_data_structures::sync::{par_for_each_in, MTLock, MTLockRef}; +use rustc_data_structures::sync::{par_for_each_in, LRef, MTLock}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId}; use rustc_hir::lang_items::LangItem; +use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::{AllocId, ErrorHandled, GlobalAlloc, Scalar}; use rustc_middle::mir::mono::{InstantiationMode, MonoItem}; use rustc_middle::mir::visit::Visitor as MirVisitor; -use rustc_middle::mir::{self, Location}; +use rustc_middle::mir::{self, Location, MentionedItem}; use rustc_middle::query::TyCtxtAt; use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCoercion}; use rustc_middle::ty::layout::ValidityRequirement; @@ -183,7 +225,6 @@ use rustc_middle::ty::{ TypeVisitableExt, VtblEntry, }; use rustc_middle::ty::{GenericArgKind, GenericArgs}; -use rustc_middle::{middle::codegen_fn_attrs::CodegenFnAttrFlags, mir::visit::TyContext}; use rustc_session::config::EntryFnType; use rustc_session::lint::builtin::LARGE_ASSIGNMENTS; use rustc_session::Limit; @@ -199,7 +240,7 @@ use crate::errors::{ }; #[derive(PartialEq)] -pub enum MonoItemCollectionMode { +pub enum MonoItemCollectionStrategy { Eager, Lazy, } @@ -214,6 +255,35 @@ pub struct UsageMap<'tcx> { type MonoItems<'tcx> = Vec<Spanned<MonoItem<'tcx>>>; +/// The state that is shared across the concurrent threads that are doing collection. +struct SharedState<'tcx> { + /// Items that have been or are currently being recursively collected. + visited: MTLock<FxHashSet<MonoItem<'tcx>>>, + /// Items that have been or are currently being recursively treated as "mentioned", i.e., their + /// consts are evaluated but nothing is added to the collection. + mentioned: MTLock<FxHashSet<MonoItem<'tcx>>>, + /// Which items are being used where, for better errors. + usage_map: MTLock<UsageMap<'tcx>>, +} + +/// See module-level docs on some contect for "mentioned" items. +#[derive(Copy, Clone, Debug, PartialEq)] +enum CollectionMode { + /// Collect items that are used, i.e., actually needed for codegen. + /// + /// Which items are used can depend on optimization levels, as MIR optimizations can remove + /// uses. + UsedItems, + /// Collect items that are mentioned. The goal of this mode is that it is independent of + /// optimizations: the set of "mentioned" items is computed before optimizations are run. + /// + /// The exact contents of this set are *not* a stable guarantee. (For instance, it is currently + /// computed after drop-elaboration. If we ever do some optimizations even in debug builds, we + /// might decide to run them before computing mentioned items.) The key property of this set is + /// that it is optimization-independent. + MentionedItems, +} + impl<'tcx> UsageMap<'tcx> { fn new() -> UsageMap<'tcx> { UsageMap { used_map: FxHashMap::default(), user_map: FxHashMap::default() } @@ -253,99 +323,40 @@ impl<'tcx> UsageMap<'tcx> { } } -#[instrument(skip(tcx, mode), level = "debug")] -pub fn collect_crate_mono_items( - tcx: TyCtxt<'_>, - mode: MonoItemCollectionMode, -) -> (FxHashSet<MonoItem<'_>>, UsageMap<'_>) { - let _prof_timer = tcx.prof.generic_activity("monomorphization_collector"); - - let roots = - tcx.sess.time("monomorphization_collector_root_collections", || collect_roots(tcx, mode)); - - debug!("building mono item graph, beginning at roots"); - - let mut visited = MTLock::new(FxHashSet::default()); - let mut usage_map = MTLock::new(UsageMap::new()); - let recursion_limit = tcx.recursion_limit(); - - { - let visited: MTLockRef<'_, _> = &mut visited; - let usage_map: MTLockRef<'_, _> = &mut usage_map; - - tcx.sess.time("monomorphization_collector_graph_walk", || { - par_for_each_in(roots, |root| { - let mut recursion_depths = DefIdMap::default(); - collect_items_rec( - tcx, - dummy_spanned(root), - visited, - &mut recursion_depths, - recursion_limit, - usage_map, - ); - }); - }); - } - - (visited.into_inner(), usage_map.into_inner()) -} - -// Find all non-generic items by walking the HIR. These items serve as roots to -// start monomorphizing from. -#[instrument(skip(tcx, mode), level = "debug")] -fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec<MonoItem<'_>> { - debug!("collecting roots"); - let mut roots = Vec::new(); - - { - let entry_fn = tcx.entry_fn(()); - - debug!("collect_roots: entry_fn = {:?}", entry_fn); - - let mut collector = RootCollector { tcx, mode, entry_fn, output: &mut roots }; - - let crate_items = tcx.hir_crate_items(()); - - for id in crate_items.items() { - collector.process_item(id); - } - - for id in crate_items.impl_items() { - collector.process_impl_item(id); - } - - collector.push_extra_entry_roots(); - } - - // We can only codegen items that are instantiable - items all of - // whose predicates hold. Luckily, items that aren't instantiable - // can't actually be used, so we can just skip codegenning them. - roots - .into_iter() - .filter_map(|Spanned { node: mono_item, .. }| { - mono_item.is_instantiable(tcx).then_some(mono_item) - }) - .collect() -} - /// Collect all monomorphized items reachable from `starting_point`, and emit a note diagnostic if a /// post-monomorphization error is encountered during a collection step. -#[instrument(skip(tcx, visited, recursion_depths, recursion_limit, usage_map), level = "debug")] +/// +/// `mode` determined whether we are scanning for [used items][CollectionMode::UsedItems] +/// or [mentioned items][CollectionMode::MentionedItems]. +#[instrument(skip(tcx, state, recursion_depths, recursion_limit), level = "debug")] fn collect_items_rec<'tcx>( tcx: TyCtxt<'tcx>, starting_item: Spanned<MonoItem<'tcx>>, - visited: MTLockRef<'_, FxHashSet<MonoItem<'tcx>>>, + state: LRef<'_, SharedState<'tcx>>, recursion_depths: &mut DefIdMap<usize>, recursion_limit: Limit, - usage_map: MTLockRef<'_, UsageMap<'tcx>>, + mode: CollectionMode, ) { - if !visited.lock_mut().insert(starting_item.node) { - // We've been here already, no need to search again. - return; + if mode == CollectionMode::UsedItems { + if !state.visited.lock_mut().insert(starting_item.node) { + // We've been here already, no need to search again. + return; + } + } else { + if state.visited.lock().contains(&starting_item.node) { + // We've already done a *full* visit on this one, no need to do the "mention" visit. + return; + } + if !state.mentioned.lock_mut().insert(starting_item.node) { + // We've been here already, no need to search again. + return; + } + // There's some risk that we first do a 'mention' visit and then a full visit. But there's no + // harm in that, the mention visit will trigger all the queries and the results are cached. } - let mut used_items = Vec::new(); + let mut used_items = MonoItems::new(); + let mut mentioned_items = MonoItems::new(); let recursion_depth_reset; // Post-monomorphization errors MVP @@ -373,37 +384,48 @@ fn collect_items_rec<'tcx>( // FIXME: don't rely on global state, instead bubble up errors. Note: this is very hard to do. let error_count = tcx.dcx().err_count(); + // In `mentioned_items` we collect items that were mentioned in this MIR but possibly do not + // need to be monomorphized. This is done to ensure that optimizing away function calls does not + // hide const-eval errors that those calls would otherwise have triggered. match starting_item.node { MonoItem::Static(def_id) => { - let instance = Instance::mono(tcx, def_id); + recursion_depth_reset = None; - // Sanity check whether this ended up being collected accidentally - debug_assert!(should_codegen_locally(tcx, &instance)); + // Statics always get evaluted (which is possible because they can't be generic), so for + // `MentionedItems` collection there's nothing to do here. + if mode == CollectionMode::UsedItems { + let instance = Instance::mono(tcx, def_id); - let DefKind::Static { nested, .. } = tcx.def_kind(def_id) else { bug!() }; - // Nested statics have no type. - if !nested { - let ty = instance.ty(tcx, ty::ParamEnv::reveal_all()); - visit_drop_use(tcx, ty, true, starting_item.span, &mut used_items); - } + // Sanity check whether this ended up being collected accidentally + debug_assert!(should_codegen_locally(tcx, &instance)); - recursion_depth_reset = None; + let DefKind::Static { nested, .. } = tcx.def_kind(def_id) else { bug!() }; + // Nested statics have no type. + if !nested { + let ty = instance.ty(tcx, ty::ParamEnv::reveal_all()); + visit_drop_use(tcx, ty, true, starting_item.span, &mut used_items); + } - if let Ok(alloc) = tcx.eval_static_initializer(def_id) { - for &prov in alloc.inner().provenance().ptrs().values() { - collect_alloc(tcx, prov.alloc_id(), &mut used_items); + if let Ok(alloc) = tcx.eval_static_initializer(def_id) { + for &prov in alloc.inner().provenance().ptrs().values() { + collect_alloc(tcx, prov.alloc_id(), &mut used_items); + } } - } - if tcx.needs_thread_local_shim(def_id) { - used_items.push(respan( - starting_item.span, - MonoItem::Fn(Instance { - def: InstanceDef::ThreadLocalShim(def_id), - args: GenericArgs::empty(), - }), - )); + if tcx.needs_thread_local_shim(def_id) { + used_items.push(respan( + starting_item.span, + MonoItem::Fn(Instance { + def: InstanceDef::ThreadLocalShim(def_id), + args: GenericArgs::empty(), + }), + )); + } } + + // mentioned_items stays empty since there's no codegen for statics. statics don't get + // optimized, and if they did then the const-eval interpreter would have to worry about + // mentioned_items. } MonoItem::Fn(instance) => { // Sanity check whether this ended up being collected accidentally @@ -420,10 +442,20 @@ fn collect_items_rec<'tcx>( check_type_length_limit(tcx, instance); rustc_data_structures::stack::ensure_sufficient_stack(|| { - collect_used_items(tcx, instance, &mut used_items); + collect_items_of_instance( + tcx, + instance, + &mut used_items, + &mut mentioned_items, + mode, + ) }); } MonoItem::GlobalAsm(item_id) => { + assert!( + mode == CollectionMode::UsedItems, + "should never encounter global_asm when collecting mentioned items" + ); recursion_depth_reset = None; let item = tcx.hir().item(item_id); @@ -459,8 +491,10 @@ fn collect_items_rec<'tcx>( } else { span_bug!(item.span, "Mismatch between hir::Item type and MonoItem type") } + + // mention_items stays empty as nothing gets optimized here. } - } + }; // Check for PMEs and emit a diagnostic if one happened. To try to show relevant edges of the // mono item graph. @@ -474,10 +508,41 @@ fn collect_items_rec<'tcx>( formatted_item, }); } - usage_map.lock_mut().record_used(starting_item.node, &used_items); + // Only updating `usage_map` for used items as otherwise we may be inserting the same item + // multiple times (if it is first 'mentioned' and then later actuall used), and the usage map + // logic does not like that. + // This is part of the output of collection and hence only relevant for "used" items. + // ("Mentioned" items are only considered internally during collection.) + if mode == CollectionMode::UsedItems { + state.usage_map.lock_mut().record_used(starting_item.node, &used_items); + } - for used_item in used_items { - collect_items_rec(tcx, used_item, visited, recursion_depths, recursion_limit, usage_map); + if mode == CollectionMode::MentionedItems { + assert!(used_items.is_empty(), "'mentioned' collection should never encounter used items"); + } else { + for used_item in used_items { + collect_items_rec( + tcx, + used_item, + state, + recursion_depths, + recursion_limit, + CollectionMode::UsedItems, + ); + } + } + + // Walk over mentioned items *after* used items, so that if an item is both mentioned and used then + // the loop above has fully collected it, so this loop will skip it. + for mentioned_item in mentioned_items { + collect_items_rec( + tcx, + mentioned_item, + state, + recursion_depths, + recursion_limit, + CollectionMode::MentionedItems, + ); } if let Some((def_id, depth)) = recursion_depth_reset { @@ -596,7 +661,10 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) { struct MirUsedCollector<'a, 'tcx> { tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, - output: &'a mut MonoItems<'tcx>, + used_items: &'a mut MonoItems<'tcx>, + /// See the comment in `collect_items_of_instance` for the purpose of this set. + /// Note that this contains *not-monomorphized* items! + used_mentioned_items: &'a mut FxHashSet<MentionedItem<'tcx>>, instance: Instance<'tcx>, /// Spans for move size lints already emitted. Helps avoid duplicate lints. move_size_spans: Vec<Span>, @@ -606,11 +674,11 @@ struct MirUsedCollector<'a, 'tcx> { } impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> { - pub fn monomorphize<T>(&self, value: T) -> T + fn monomorphize<T>(&self, value: T) -> T where T: TypeFoldable<TyCtxt<'tcx>>, { - debug!("monomorphize: self.instance={:?}", self.instance); + trace!("monomorphize: self.instance={:?}", self.instance); self.instance.instantiate_mir_and_normalize_erasing_regions( self.tcx, ty::ParamEnv::reveal_all(), @@ -735,6 +803,31 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> { ); self.move_size_spans.push(span); } + + /// Evaluates a *not yet monomorphized* constant. + fn eval_constant( + &mut self, + constant: &mir::ConstOperand<'tcx>, + ) -> Option<mir::ConstValue<'tcx>> { + let const_ = self.monomorphize(constant.const_); + let param_env = ty::ParamEnv::reveal_all(); + // Evaluate the constant. This makes const eval failure a collection-time error (rather than + // a codegen-time error). rustc stops after collection if there was an error, so this + // ensures codegen never has to worry about failing consts. + // (codegen relies on this and ICEs will happen if this is violated.) + match const_.eval(self.tcx, param_env, constant.span) { + Ok(v) => Some(v), + Err(ErrorHandled::TooGeneric(..)) => span_bug!( + constant.span, + "collection encountered polymorphic constant: {:?}", + const_ + ), + Err(err @ ErrorHandled::Reported(..)) => { + err.emit_note(self.tcx); + return None; + } + } + } } impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { @@ -753,8 +846,11 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { target_ty, ) | mir::Rvalue::Cast(mir::CastKind::DynStar, ref operand, target_ty) => { - let target_ty = self.monomorphize(target_ty); let source_ty = operand.ty(self.body, self.tcx); + // *Before* monomorphizing, record that we already handled this mention. + self.used_mentioned_items + .insert(MentionedItem::UnsizeCast { source_ty, target_ty }); + let target_ty = self.monomorphize(target_ty); let source_ty = self.monomorphize(source_ty); let (source_ty, target_ty) = find_vtable_types_for_unsizing(self.tcx.at(span), source_ty, target_ty); @@ -769,7 +865,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { target_ty, source_ty, span, - self.output, + self.used_items, ); } } @@ -779,8 +875,10 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { _, ) => { let fn_ty = operand.ty(self.body, self.tcx); + // *Before* monomorphizing, record that we already handled this mention. + self.used_mentioned_items.insert(MentionedItem::Fn(fn_ty)); let fn_ty = self.monomorphize(fn_ty); - visit_fn_use(self.tcx, fn_ty, false, span, self.output); + visit_fn_use(self.tcx, fn_ty, false, span, self.used_items); } mir::Rvalue::Cast( mir::CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(_)), @@ -788,20 +886,17 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { _, ) => { let source_ty = operand.ty(self.body, self.tcx); + // *Before* monomorphizing, record that we already handled this mention. + self.used_mentioned_items.insert(MentionedItem::Closure(source_ty)); let source_ty = self.monomorphize(source_ty); - match *source_ty.kind() { - ty::Closure(def_id, args) => { - let instance = Instance::resolve_closure( - self.tcx, - def_id, - args, - ty::ClosureKind::FnOnce, - ); - if should_codegen_locally(self.tcx, &instance) { - self.output.push(create_fn_mono_item(self.tcx, instance, span)); - } + if let ty::Closure(def_id, args) = *source_ty.kind() { + let instance = + Instance::resolve_closure(self.tcx, def_id, args, ty::ClosureKind::FnOnce); + if should_codegen_locally(self.tcx, &instance) { + self.used_items.push(create_fn_mono_item(self.tcx, instance, span)); } - _ => bug!(), + } else { + bug!() } } mir::Rvalue::ThreadLocalRef(def_id) => { @@ -809,7 +904,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { let instance = Instance::mono(self.tcx, def_id); if should_codegen_locally(self.tcx, &instance) { trace!("collecting thread-local static {:?}", def_id); - self.output.push(respan(span, MonoItem::Static(def_id))); + self.used_items.push(respan(span, MonoItem::Static(def_id))); } } _ => { /* not interesting */ } @@ -822,26 +917,9 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { /// to ensure that the constant evaluates successfully and walk the result. #[instrument(skip(self), level = "debug")] fn visit_constant(&mut self, constant: &mir::ConstOperand<'tcx>, location: Location) { - let const_ = self.monomorphize(constant.const_); - let param_env = ty::ParamEnv::reveal_all(); - // Evaluate the constant. This makes const eval failure a collection-time error (rather than - // a codegen-time error). rustc stops after collection if there was an error, so this - // ensures codegen never has to worry about failing consts. - // (codegen relies on this and ICEs will happen if this is violated.) - let val = match const_.eval(self.tcx, param_env, Some(constant.span)) { - Ok(v) => v, - Err(ErrorHandled::TooGeneric(..)) => span_bug!( - self.body.source_info(location).span, - "collection encountered polymorphic constant: {:?}", - const_ - ), - Err(err @ ErrorHandled::Reported(..)) => { - err.emit_note(self.tcx); - return; - } - }; - collect_const_value(self.tcx, val, self.output); - MirVisitor::visit_ty(self, const_.ty(), TyContext::Location(location)); + // No `super_constant` as we don't care about `visit_ty`/`visit_ty_const`. + let Some(val) = self.eval_constant(constant) else { return }; + collect_const_value(self.tcx, val, self.used_items); } fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) { @@ -852,34 +930,41 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { let push_mono_lang_item = |this: &mut Self, lang_item: LangItem| { let instance = Instance::mono(tcx, tcx.require_lang_item(lang_item, Some(source))); if should_codegen_locally(tcx, &instance) { - this.output.push(create_fn_mono_item(tcx, instance, source)); + this.used_items.push(create_fn_mono_item(tcx, instance, source)); } }; match terminator.kind { mir::TerminatorKind::Call { ref func, ref args, ref fn_span, .. } => { let callee_ty = func.ty(self.body, tcx); + // *Before* monomorphizing, record that we already handled this mention. + self.used_mentioned_items.insert(MentionedItem::Fn(callee_ty)); let callee_ty = self.monomorphize(callee_ty); self.check_fn_args_move_size(callee_ty, args, *fn_span, location); - visit_fn_use(self.tcx, callee_ty, true, source, &mut self.output) + visit_fn_use(self.tcx, callee_ty, true, source, &mut self.used_items) } mir::TerminatorKind::Drop { ref place, .. } => { let ty = place.ty(self.body, self.tcx).ty; + // *Before* monomorphizing, record that we already handled this mention. + self.used_mentioned_items.insert(MentionedItem::Drop(ty)); let ty = self.monomorphize(ty); - visit_drop_use(self.tcx, ty, true, source, self.output); + visit_drop_use(self.tcx, ty, true, source, self.used_items); } mir::TerminatorKind::InlineAsm { ref operands, .. } => { for op in operands { match *op { mir::InlineAsmOperand::SymFn { ref value } => { - let fn_ty = self.monomorphize(value.const_.ty()); - visit_fn_use(self.tcx, fn_ty, false, source, self.output); + let fn_ty = value.const_.ty(); + // *Before* monomorphizing, record that we already handled this mention. + self.used_mentioned_items.insert(MentionedItem::Fn(fn_ty)); + let fn_ty = self.monomorphize(fn_ty); + visit_fn_use(self.tcx, fn_ty, false, source, self.used_items); } mir::InlineAsmOperand::SymStatic { def_id } => { let instance = Instance::mono(self.tcx, def_id); if should_codegen_locally(self.tcx, &instance) { trace!("collecting asm sym static {:?}", def_id); - self.output.push(respan(source, MonoItem::Static(def_id))); + self.used_items.push(respan(source, MonoItem::Static(def_id))); } } _ => {} @@ -936,6 +1021,8 @@ fn visit_drop_use<'tcx>( visit_instance_use(tcx, instance, is_direct_call, source, output); } +/// For every call of this function in the visitor, make sure there is a matching call in the +/// `mentioned_items` pass! fn visit_fn_use<'tcx>( tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, @@ -1030,11 +1117,6 @@ pub(crate) fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instanc return false; } - if tcx.intrinsic(def_id).is_some_and(|i| i.must_be_overridden) { - // These are implemented by backends directly and have no meaningful body. - return false; - } - if def_id.is_local() { // Local items cannot be referred to locally without monomorphizing them locally. return true; @@ -1202,34 +1284,225 @@ fn create_mono_items_for_vtable_methods<'tcx>( ) { assert!(!trait_ty.has_escaping_bound_vars() && !impl_ty.has_escaping_bound_vars()); - if let ty::Dynamic(trait_ty, ..) = trait_ty.kind() { - if let Some(principal) = trait_ty.principal() { - let poly_trait_ref = principal.with_self_ty(tcx, impl_ty); - assert!(!poly_trait_ref.has_escaping_bound_vars()); - - // Walk all methods of the trait, including those of its supertraits - let entries = tcx.vtable_entries(poly_trait_ref); - let methods = entries - .iter() - .filter_map(|entry| match entry { - VtblEntry::MetadataDropInPlace - | VtblEntry::MetadataSize - | VtblEntry::MetadataAlign - | VtblEntry::Vacant => None, - VtblEntry::TraitVPtr(_) => { - // all super trait items already covered, so skip them. - None - } - VtblEntry::Method(instance) => { - Some(*instance).filter(|instance| should_codegen_locally(tcx, instance)) + let ty::Dynamic(trait_ty, ..) = trait_ty.kind() else { + bug!("create_mono_items_for_vtable_methods: {trait_ty:?} not a trait type"); + }; + if let Some(principal) = trait_ty.principal() { + let poly_trait_ref = principal.with_self_ty(tcx, impl_ty); + assert!(!poly_trait_ref.has_escaping_bound_vars()); + + // Walk all methods of the trait, including those of its supertraits + let entries = tcx.vtable_entries(poly_trait_ref); + debug!(?entries); + let methods = entries + .iter() + .filter_map(|entry| match entry { + VtblEntry::MetadataDropInPlace + | VtblEntry::MetadataSize + | VtblEntry::MetadataAlign + | VtblEntry::Vacant => None, + VtblEntry::TraitVPtr(_) => { + // all super trait items already covered, so skip them. + None + } + VtblEntry::Method(instance) => { + Some(*instance).filter(|instance| should_codegen_locally(tcx, instance)) + } + }) + .map(|item| create_fn_mono_item(tcx, item, source)); + output.extend(methods); + } + + // Also add the destructor. + visit_drop_use(tcx, impl_ty, false, source, output); +} + +/// Scans the CTFE alloc in order to find function pointers and statics that must be monomorphized. +fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoItems<'tcx>) { + match tcx.global_alloc(alloc_id) { + GlobalAlloc::Static(def_id) => { + assert!(!tcx.is_thread_local_static(def_id)); + let instance = Instance::mono(tcx, def_id); + if should_codegen_locally(tcx, &instance) { + trace!("collecting static {:?}", def_id); + output.push(dummy_spanned(MonoItem::Static(def_id))); + } + } + GlobalAlloc::Memory(alloc) => { + trace!("collecting {:?} with {:#?}", alloc_id, alloc); + let ptrs = alloc.inner().provenance().ptrs(); + // avoid `ensure_sufficient_stack` in the common case of "no pointers" + if !ptrs.is_empty() { + rustc_data_structures::stack::ensure_sufficient_stack(move || { + for &prov in ptrs.values() { + collect_alloc(tcx, prov.alloc_id(), output); } - }) - .map(|item| create_fn_mono_item(tcx, item, source)); - output.extend(methods); + }); + } + } + GlobalAlloc::Function(fn_instance) => { + if should_codegen_locally(tcx, &fn_instance) { + trace!("collecting {:?} with {:#?}", alloc_id, fn_instance); + output.push(create_fn_mono_item(tcx, fn_instance, DUMMY_SP)); + } + } + GlobalAlloc::VTable(ty, trait_ref) => { + let alloc_id = tcx.vtable_allocation((ty, trait_ref)); + collect_alloc(tcx, alloc_id, output) } + } +} - // Also add the destructor. - visit_drop_use(tcx, impl_ty, false, source, output); +fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) -> Option<DefId> { + for impl_def_id in tcx.inherent_impls(def_id).ok()? { + if let Some(new) = tcx.associated_items(impl_def_id).find_by_name_and_kind( + tcx, + fn_ident, + AssocKind::Fn, + def_id, + ) { + return Some(new.def_id); + } + } + return None; +} + +fn build_skip_move_check_fns(tcx: TyCtxt<'_>) -> Vec<DefId> { + let fns = [ + (tcx.lang_items().owned_box(), "new"), + (tcx.get_diagnostic_item(sym::Rc), "new"), + (tcx.get_diagnostic_item(sym::Arc), "new"), + ]; + fns.into_iter() + .filter_map(|(def_id, fn_name)| { + def_id.and_then(|def_id| assoc_fn_of_type(tcx, def_id, Ident::from_str(fn_name))) + }) + .collect::<Vec<_>>() +} + +/// Scans the MIR in order to find function calls, closures, and drop-glue. +/// +/// Anything that's found is added to `output`. Furthermore the "mentioned items" of the MIR are returned. +#[instrument(skip(tcx, used_items, mentioned_items), level = "debug")] +fn collect_items_of_instance<'tcx>( + tcx: TyCtxt<'tcx>, + instance: Instance<'tcx>, + used_items: &mut MonoItems<'tcx>, + mentioned_items: &mut MonoItems<'tcx>, + mode: CollectionMode, +) { + let body = tcx.instance_mir(instance.def); + // Naively, in "used" collection mode, all functions get added to *both* `used_items` and + // `mentioned_items`. Mentioned items processing will then notice that they have already been + // visited, but at that point each mentioned item has been monomorphized, added to the + // `mentioned_items` worklist, and checked in the global set of visited items. To remove that + // overhead, we have a special optimization that avoids adding items to `mentioned_items` when + // they are already added in `used_items`. We could just scan `used_items`, but that's a linear + // scan and not very efficient. Furthermore we can only do that *after* monomorphizing the + // mentioned item. So instead we collect all pre-monomorphized `MentionedItem` that were already + // added to `used_items` in a hash set, which can efficiently query in the + // `body.mentioned_items` loop below without even having to monomorphize the item. + let mut used_mentioned_items = FxHashSet::<MentionedItem<'tcx>>::default(); + let mut collector = MirUsedCollector { + tcx, + body, + used_items, + used_mentioned_items: &mut used_mentioned_items, + instance, + move_size_spans: vec![], + visiting_call_terminator: false, + skip_move_check_fns: None, + }; + + if mode == CollectionMode::UsedItems { + // Visit everything. Here we rely on the visitor also visiting `required_consts`, so that we + // evaluate them and abort compilation if any of them errors. + collector.visit_body(body); + } else { + // We only need to evaluate all constants, but can ignore the rest of the MIR. + for const_op in &body.required_consts { + if let Some(val) = collector.eval_constant(const_op) { + collect_const_value(tcx, val, mentioned_items); + } + } + } + + // Always gather mentioned items. We try to avoid processing items that we have already added to + // `used_items` above. + for item in &body.mentioned_items { + if !collector.used_mentioned_items.contains(&item.node) { + let item_mono = collector.monomorphize(item.node); + visit_mentioned_item(tcx, &item_mono, item.span, mentioned_items); + } + } +} + +/// `item` must be already monomorphized. +#[instrument(skip(tcx, span, output), level = "debug")] +fn visit_mentioned_item<'tcx>( + tcx: TyCtxt<'tcx>, + item: &MentionedItem<'tcx>, + span: Span, + output: &mut MonoItems<'tcx>, +) { + match *item { + MentionedItem::Fn(ty) => { + if let ty::FnDef(def_id, args) = *ty.kind() { + let instance = + Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args); + // `visit_instance_use` was written for "used" item collection but works just as well + // for "mentioned" item collection. + // We can set `is_direct_call`; that just means we'll skip a bunch of shims that anyway + // can't have their own failing constants. + visit_instance_use(tcx, instance, /*is_direct_call*/ true, span, output); + } + } + MentionedItem::Drop(ty) => { + visit_drop_use(tcx, ty, /*is_direct_call*/ true, span, output); + } + MentionedItem::UnsizeCast { source_ty, target_ty } => { + let (source_ty, target_ty) = + find_vtable_types_for_unsizing(tcx.at(span), source_ty, target_ty); + // This could also be a different Unsize instruction, like + // from a fixed sized array to a slice. But we are only + // interested in things that produce a vtable. + if (target_ty.is_trait() && !source_ty.is_trait()) + || (target_ty.is_dyn_star() && !source_ty.is_dyn_star()) + { + create_mono_items_for_vtable_methods(tcx, target_ty, source_ty, span, output); + } + } + MentionedItem::Closure(source_ty) => { + if let ty::Closure(def_id, args) = *source_ty.kind() { + let instance = + Instance::resolve_closure(tcx, def_id, args, ty::ClosureKind::FnOnce); + if should_codegen_locally(tcx, &instance) { + output.push(create_fn_mono_item(tcx, instance, span)); + } + } else { + bug!() + } + } + } +} + +#[instrument(skip(tcx, output), level = "debug")] +fn collect_const_value<'tcx>( + tcx: TyCtxt<'tcx>, + value: mir::ConstValue<'tcx>, + output: &mut MonoItems<'tcx>, +) { + match value { + mir::ConstValue::Scalar(Scalar::Ptr(ptr, _size)) => { + collect_alloc(tcx, ptr.provenance.alloc_id(), output) + } + mir::ConstValue::Indirect { alloc_id, .. } => collect_alloc(tcx, alloc_id, output), + mir::ConstValue::Slice { data, meta: _ } => { + for &prov in data.inner().provenance().ptrs().values() { + collect_alloc(tcx, prov.alloc_id(), output); + } + } + _ => {} } } @@ -1237,9 +1510,47 @@ fn create_mono_items_for_vtable_methods<'tcx>( // Root Collection //=----------------------------------------------------------------------------- +// Find all non-generic items by walking the HIR. These items serve as roots to +// start monomorphizing from. +#[instrument(skip(tcx, mode), level = "debug")] +fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionStrategy) -> Vec<MonoItem<'_>> { + debug!("collecting roots"); + let mut roots = Vec::new(); + + { + let entry_fn = tcx.entry_fn(()); + + debug!("collect_roots: entry_fn = {:?}", entry_fn); + + let mut collector = RootCollector { tcx, strategy: mode, entry_fn, output: &mut roots }; + + let crate_items = tcx.hir_crate_items(()); + + for id in crate_items.free_items() { + collector.process_item(id); + } + + for id in crate_items.impl_items() { + collector.process_impl_item(id); + } + + collector.push_extra_entry_roots(); + } + + // We can only codegen items that are instantiable - items all of + // whose predicates hold. Luckily, items that aren't instantiable + // can't actually be used, so we can just skip codegenning them. + roots + .into_iter() + .filter_map(|Spanned { node: mono_item, .. }| { + mono_item.is_instantiable(tcx).then_some(mono_item) + }) + .collect() +} + struct RootCollector<'a, 'tcx> { tcx: TyCtxt<'tcx>, - mode: MonoItemCollectionMode, + strategy: MonoItemCollectionStrategy, output: &'a mut MonoItems<'tcx>, entry_fn: Option<(DefId, EntryFnType)>, } @@ -1248,7 +1559,7 @@ impl<'v> RootCollector<'_, 'v> { fn process_item(&mut self, id: hir::ItemId) { match self.tcx.def_kind(id.owner_id) { DefKind::Enum | DefKind::Struct | DefKind::Union => { - if self.mode == MonoItemCollectionMode::Eager + if self.strategy == MonoItemCollectionStrategy::Eager && self.tcx.generics_of(id.owner_id).count() == 0 { debug!("RootCollector: ADT drop-glue for `{id:?}`",); @@ -1279,7 +1590,7 @@ impl<'v> RootCollector<'_, 'v> { } } DefKind::Impl { .. } => { - if self.mode == MonoItemCollectionMode::Eager { + if self.strategy == MonoItemCollectionStrategy::Eager { create_mono_items_for_default_impls(self.tcx, id, self.output); } } @@ -1298,9 +1609,9 @@ impl<'v> RootCollector<'_, 'v> { fn is_root(&self, def_id: LocalDefId) -> bool { !self.tcx.generics_of(def_id).requires_monomorphization(self.tcx) - && match self.mode { - MonoItemCollectionMode::Eager => true, - MonoItemCollectionMode::Lazy => { + && match self.strategy { + MonoItemCollectionStrategy::Eager => true, + MonoItemCollectionStrategy::Lazy => { self.entry_fn.and_then(|(id, _)| id.as_local()) == Some(def_id) || self.tcx.is_reachable_non_generic(def_id) || self @@ -1433,104 +1744,47 @@ fn create_mono_items_for_default_impls<'tcx>( } } -/// Scans the CTFE alloc in order to find function calls, closures, and drop-glue. -fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoItems<'tcx>) { - match tcx.global_alloc(alloc_id) { - GlobalAlloc::Static(def_id) => { - assert!(!tcx.is_thread_local_static(def_id)); - let instance = Instance::mono(tcx, def_id); - if should_codegen_locally(tcx, &instance) { - trace!("collecting static {:?}", def_id); - output.push(dummy_spanned(MonoItem::Static(def_id))); - } - } - GlobalAlloc::Memory(alloc) => { - trace!("collecting {:?} with {:#?}", alloc_id, alloc); - for &prov in alloc.inner().provenance().ptrs().values() { - rustc_data_structures::stack::ensure_sufficient_stack(|| { - collect_alloc(tcx, prov.alloc_id(), output); - }); - } - } - GlobalAlloc::Function(fn_instance) => { - if should_codegen_locally(tcx, &fn_instance) { - trace!("collecting {:?} with {:#?}", alloc_id, fn_instance); - output.push(create_fn_mono_item(tcx, fn_instance, DUMMY_SP)); - } - } - GlobalAlloc::VTable(ty, trait_ref) => { - let alloc_id = tcx.vtable_allocation((ty, trait_ref)); - collect_alloc(tcx, alloc_id, output) - } - } -} +//=----------------------------------------------------------------------------- +// Top-level entry point, tying it all together +//=----------------------------------------------------------------------------- -fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) -> Option<DefId> { - for impl_def_id in tcx.inherent_impls(def_id).ok()? { - if let Some(new) = tcx.associated_items(impl_def_id).find_by_name_and_kind( - tcx, - fn_ident, - AssocKind::Fn, - def_id, - ) { - return Some(new.def_id); - } - } - return None; -} +#[instrument(skip(tcx, strategy), level = "debug")] +pub fn collect_crate_mono_items( + tcx: TyCtxt<'_>, + strategy: MonoItemCollectionStrategy, +) -> (FxHashSet<MonoItem<'_>>, UsageMap<'_>) { + let _prof_timer = tcx.prof.generic_activity("monomorphization_collector"); -fn build_skip_move_check_fns(tcx: TyCtxt<'_>) -> Vec<DefId> { - let fns = [ - (tcx.lang_items().owned_box(), "new"), - (tcx.get_diagnostic_item(sym::Rc), "new"), - (tcx.get_diagnostic_item(sym::Arc), "new"), - ]; - fns.into_iter() - .filter_map(|(def_id, fn_name)| { - def_id.and_then(|def_id| assoc_fn_of_type(tcx, def_id, Ident::from_str(fn_name))) - }) - .collect::<Vec<_>>() -} + let roots = tcx + .sess + .time("monomorphization_collector_root_collections", || collect_roots(tcx, strategy)); -/// Scans the MIR in order to find function calls, closures, and drop-glue. -#[instrument(skip(tcx, output), level = "debug")] -fn collect_used_items<'tcx>( - tcx: TyCtxt<'tcx>, - instance: Instance<'tcx>, - output: &mut MonoItems<'tcx>, -) { - let body = tcx.instance_mir(instance.def); + debug!("building mono item graph, beginning at roots"); - // Here we rely on the visitor also visiting `required_consts`, so that we evaluate them - // and abort compilation if any of them errors. - MirUsedCollector { - tcx, - body: body, - output, - instance, - move_size_spans: vec![], - visiting_call_terminator: false, - skip_move_check_fns: None, - } - .visit_body(body); -} + let mut state = SharedState { + visited: MTLock::new(FxHashSet::default()), + mentioned: MTLock::new(FxHashSet::default()), + usage_map: MTLock::new(UsageMap::new()), + }; + let recursion_limit = tcx.recursion_limit(); -#[instrument(skip(tcx, output), level = "debug")] -fn collect_const_value<'tcx>( - tcx: TyCtxt<'tcx>, - value: mir::ConstValue<'tcx>, - output: &mut MonoItems<'tcx>, -) { - match value { - mir::ConstValue::Scalar(Scalar::Ptr(ptr, _size)) => { - collect_alloc(tcx, ptr.provenance.alloc_id(), output) - } - mir::ConstValue::Indirect { alloc_id, .. } => collect_alloc(tcx, alloc_id, output), - mir::ConstValue::Slice { data, meta: _ } => { - for &prov in data.inner().provenance().ptrs().values() { - collect_alloc(tcx, prov.alloc_id(), output); - } - } - _ => {} + { + let state: LRef<'_, _> = &mut state; + + tcx.sess.time("monomorphization_collector_graph_walk", || { + par_for_each_in(roots, |root| { + let mut recursion_depths = DefIdMap::default(); + collect_items_rec( + tcx, + dummy_spanned(root), + state, + &mut recursion_depths, + recursion_limit, + CollectionMode::UsedItems, + ); + }); + }); } + + (state.visited.into_inner(), state.usage_map.into_inner()) } diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 15041b9cd41..5a92657cb40 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -117,7 +117,7 @@ use rustc_session::CodegenUnits; use rustc_span::symbol::Symbol; use crate::collector::UsageMap; -use crate::collector::{self, MonoItemCollectionMode}; +use crate::collector::{self, MonoItemCollectionStrategy}; use crate::errors::{CouldntDumpMonoStats, SymbolAlreadyDefined, UnknownCguCollectionMode}; struct PartitioningCx<'a, 'tcx> { @@ -1087,30 +1087,30 @@ where } fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[CodegenUnit<'_>]) { - let collection_mode = match tcx.sess.opts.unstable_opts.print_mono_items { + let collection_strategy = match tcx.sess.opts.unstable_opts.print_mono_items { Some(ref s) => { let mode = s.to_lowercase(); let mode = mode.trim(); if mode == "eager" { - MonoItemCollectionMode::Eager + MonoItemCollectionStrategy::Eager } else { if mode != "lazy" { tcx.dcx().emit_warn(UnknownCguCollectionMode { mode }); } - MonoItemCollectionMode::Lazy + MonoItemCollectionStrategy::Lazy } } None => { if tcx.sess.link_dead_code() { - MonoItemCollectionMode::Eager + MonoItemCollectionStrategy::Eager } else { - MonoItemCollectionMode::Lazy + MonoItemCollectionStrategy::Lazy } } }; - let (items, usage_map) = collector::collect_crate_mono_items(tcx, collection_mode); + let (items, usage_map) = collector::collect_crate_mono_items(tcx, collection_strategy); // If there was an error during collection (e.g. from one of the constants we evaluated), // then we stop here. This way codegen does not have to worry about failing constants. diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index a100e2d47bb..e1d26f090e0 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -390,8 +390,6 @@ parse_invalid_dyn_keyword = invalid `dyn` keyword parse_invalid_expression_in_let_else = a `{$operator}` expression cannot be directly assigned in `let...else` parse_invalid_identifier_with_leading_number = identifiers cannot start with a number -parse_invalid_interpolated_expression = invalid interpolated expression - parse_invalid_literal_suffix_on_tuple_index = suffixes on a tuple index are invalid .label = invalid suffix `{$suffix}` .tuple_exception_line_1 = `{$suffix}` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 32b56bb7e87..5cad3a568ee 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -851,13 +851,6 @@ pub(crate) struct StructLiteralNotAllowedHereSugg { } #[derive(Diagnostic)] -#[diag(parse_invalid_interpolated_expression)] -pub(crate) struct InvalidInterpolatedExpression { - #[primary_span] - pub span: Span, -} - -#[derive(Diagnostic)] #[diag(parse_invalid_literal_suffix_on_tuple_index)] pub(crate) struct InvalidLiteralSuffixOnTupleIndex { #[primary_span] diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index eb9a10f4bda..ab5f51eedc3 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -3,11 +3,12 @@ use crate::errors::{ SuffixedLiteralInAttribute, }; use crate::fluent_generated as fluent; +use crate::maybe_whole; use super::{AttrWrapper, Capturing, FnParseMode, ForceCollect, Parser, PathStyle}; use rustc_ast as ast; use rustc_ast::attr; -use rustc_ast::token::{self, Delimiter, Nonterminal}; +use rustc_ast::token::{self, Delimiter}; use rustc_errors::{codes::*, Diag, PResult}; use rustc_span::{sym, BytePos, Span}; use thin_vec::ThinVec; @@ -251,25 +252,15 @@ impl<'a> Parser<'a> { /// PATH `=` UNSUFFIXED_LIT /// The delimiters or `=` are still put into the resulting token stream. pub fn parse_attr_item(&mut self, capture_tokens: bool) -> PResult<'a, ast::AttrItem> { - let item = match &self.token.kind { - token::Interpolated(nt) => match &nt.0 { - Nonterminal::NtMeta(item) => Some(item.clone().into_inner()), - _ => None, - }, - _ => None, + maybe_whole!(self, NtMeta, |attr| attr.into_inner()); + + let do_parse = |this: &mut Self| { + let path = this.parse_path(PathStyle::Mod)?; + let args = this.parse_attr_args()?; + Ok(ast::AttrItem { path, args, tokens: None }) }; - Ok(if let Some(item) = item { - self.bump(); - item - } else { - let do_parse = |this: &mut Self| { - let path = this.parse_path(PathStyle::Mod)?; - let args = this.parse_attr_args()?; - Ok(ast::AttrItem { path, args, tokens: None }) - }; - // Attr items don't have attributes - if capture_tokens { self.collect_tokens_no_attrs(do_parse) } else { do_parse(self) }? - }) + // Attr items don't have attributes + if capture_tokens { self.collect_tokens_no_attrs(do_parse) } else { do_parse(self) } } /// Parses attributes that appear after the opening of an item. These should @@ -371,22 +362,18 @@ impl<'a> Parser<'a> { /// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ; /// ``` pub fn parse_meta_item(&mut self) -> PResult<'a, ast::MetaItem> { - let nt_meta = match &self.token.kind { - token::Interpolated(nt) => match &nt.0 { - token::NtMeta(e) => Some(e.clone()), - _ => None, - }, - _ => None, - }; - - if let Some(item) = nt_meta { - return match item.meta(item.path.span) { + // We can't use `maybe_whole` here because it would bump in the `None` + // case, which we don't want. + if let token::Interpolated(nt) = &self.token.kind + && let token::NtMeta(attr_item) = &nt.0 + { + match attr_item.meta(attr_item.path.span) { Some(meta) => { self.bump(); - Ok(meta) + return Ok(meta); } - None => self.unexpected(), - }; + None => self.unexpected()?, + } } let lo = self.token.span; diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index e27a5f93799..fe17eba0d7b 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -11,7 +11,7 @@ use crate::errors; use crate::maybe_recover_from_interpolated_ty_qpath; use ast::mut_visit::{noop_visit_expr, MutVisitor}; use ast::token::IdentIsRaw; -use ast::{CoroutineKind, ForLoopKind, GenBlockKind, Pat, Path, PathSegment}; +use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment}; use core::mem; use core::ops::ControlFlow; use rustc_ast::ptr::P; @@ -943,7 +943,10 @@ impl<'a> Parser<'a> { // Stitch the list of outer attributes onto the return value. // A little bit ugly, but the best way given the current code // structure - let res = self.parse_expr_dot_or_call_with_(e0, lo); + let res = ensure_sufficient_stack( + // this expr demonstrates the recursion it guards against + || self.parse_expr_dot_or_call_with_(e0, lo), + ); if attrs.is_empty() { res } else { @@ -1376,6 +1379,13 @@ impl<'a> Parser<'a> { return Ok(self.mk_await_expr(self_arg, lo)); } + // Post-fix match + if self.eat_keyword(kw::Match) { + let match_span = self.prev_token.span; + self.psess.gated_spans.gate(sym::postfix_match, match_span); + return self.parse_match_block(lo, match_span, self_arg, MatchKind::Postfix); + } + let fn_span_lo = self.token.span; let mut seg = self.parse_path_segment(PathStyle::Expr, None)?; self.check_trailing_angle_brackets(&seg, &[&token::OpenDelim(Delimiter::Parenthesis)]); @@ -1936,11 +1946,11 @@ impl<'a> Parser<'a> { /// Parse `builtin # ident(args,*)`. fn parse_expr_builtin(&mut self) -> PResult<'a, P<Expr>> { self.parse_builtin(|this, lo, ident| { - if ident.name == sym::offset_of { - return Ok(Some(this.parse_expr_offset_of(lo)?)); - } - - Ok(None) + Ok(match ident.name { + sym::offset_of => Some(this.parse_expr_offset_of(lo)?), + sym::type_ascribe => Some(this.parse_expr_type_ascribe(lo)?), + _ => None, + }) }) } @@ -1975,6 +1985,7 @@ impl<'a> Parser<'a> { ret } + /// Built-in macro for `offset_of!` expressions. pub(crate) fn parse_expr_offset_of(&mut self, lo: Span) -> PResult<'a, P<Expr>> { let container = self.parse_ty()?; self.expect(&TokenKind::Comma)?; @@ -2004,6 +2015,15 @@ impl<'a> Parser<'a> { Ok(self.mk_expr(span, ExprKind::OffsetOf(container, fields))) } + /// Built-in macro for type ascription expressions. + pub(crate) fn parse_expr_type_ascribe(&mut self, lo: Span) -> PResult<'a, P<Expr>> { + let expr = self.parse_expr()?; + self.expect(&token::Comma)?; + let ty = self.parse_ty()?; + let span = lo.to(self.token.span); + Ok(self.mk_expr(span, ExprKind::Type(expr, ty))) + } + /// Returns a string literal if the next token is a string literal. /// In case of error returns `Some(lit)` if the next token is a literal with a wrong kind, /// and returns `None` if the next token is not literal at all. @@ -2040,16 +2060,6 @@ impl<'a> Parser<'a> { &mut self, mk_lit_char: impl FnOnce(Symbol, Span) -> L, ) -> PResult<'a, L> { - if let token::Interpolated(nt) = &self.token.kind - && let token::NtExpr(e) | token::NtLiteral(e) = &nt.0 - && matches!(e.kind, ExprKind::Err(_)) - { - let mut err = self - .dcx() - .create_err(errors::InvalidInterpolatedExpression { span: self.token.span }); - err.downgrade_to_delayed_bug(); - return Err(err); - } let token = self.token.clone(); let err = |self_: &Self| { let msg = format!("unexpected token: {}", super::token_descr(&token)); @@ -2891,8 +2901,20 @@ impl<'a> Parser<'a> { /// Parses a `match ... { ... }` expression (`match` token already eaten). fn parse_expr_match(&mut self) -> PResult<'a, P<Expr>> { let match_span = self.prev_token.span; - let lo = self.prev_token.span; let scrutinee = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?; + + self.parse_match_block(match_span, match_span, scrutinee, MatchKind::Prefix) + } + + /// Parses the block of a `match expr { ... }` or a `expr.match { ... }` + /// expression. This is after the match token and scrutinee are eaten + fn parse_match_block( + &mut self, + lo: Span, + match_span: Span, + scrutinee: P<Expr>, + match_kind: MatchKind, + ) -> PResult<'a, P<Expr>> { if let Err(mut e) = self.expect(&token::OpenDelim(Delimiter::Brace)) { if self.token == token::Semi { e.span_suggestion_short( @@ -2935,7 +2957,7 @@ impl<'a> Parser<'a> { }); return Ok(self.mk_expr_with_attrs( span, - ExprKind::Match(scrutinee, arms), + ExprKind::Match(scrutinee, arms, match_kind), attrs, )); } @@ -2943,7 +2965,7 @@ impl<'a> Parser<'a> { } let hi = self.token.span; self.bump(); - Ok(self.mk_expr_with_attrs(lo.to(hi), ExprKind::Match(scrutinee, arms), attrs)) + Ok(self.mk_expr_with_attrs(lo.to(hi), ExprKind::Match(scrutinee, arms, match_kind), attrs)) } /// Attempt to recover from match arm body with statements and no surrounding braces. @@ -3952,7 +3974,7 @@ impl MutVisitor for CondChecker<'_> { | ExprKind::While(_, _, _) | ExprKind::ForLoop { .. } | ExprKind::Loop(_, _, _) - | ExprKind::Match(_, _) + | ExprKind::Match(_, _, _) | ExprKind::Closure(_) | ExprKind::Block(_, _) | ExprKind::Gen(_, _, _) diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs index 263b2a90643..fde16ac957d 100644 --- a/compiler/rustc_parse/src/parser/generics.rs +++ b/compiler/rustc_parse/src/parser/generics.rs @@ -481,7 +481,7 @@ impl<'a> Parser<'a> { })) } else { self.maybe_recover_bounds_doubled_colon(&ty)?; - self.unexpected() + self.unexpected_any() } } diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 79492fe62ed..d54eb8dc4c9 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -6,6 +6,7 @@ use super::{ }; use crate::errors::{self, MacroExpandsToAdtField}; use crate::fluent_generated as fluent; +use crate::maybe_whole; use ast::token::IdentIsRaw; use rustc_ast::ast::*; use rustc_ast::ptr::P; @@ -115,17 +116,10 @@ impl<'a> Parser<'a> { fn_parse_mode: FnParseMode, force_collect: ForceCollect, ) -> PResult<'a, Option<Item>> { - // Don't use `maybe_whole` so that we have precise control - // over when we bump the parser - if let token::Interpolated(nt) = &self.token.kind - && let token::NtItem(item) = &nt.0 - { - let mut item = item.clone(); - self.bump(); - + maybe_whole!(self, NtItem, |item| { attrs.prepend_to_nt_inner(&mut item.attrs); - return Ok(Some(item.into_inner())); - }; + Some(item.into_inner()) + }); let item = self.collect_tokens_trailing_token(attrs, force_collect, |this: &mut Self, attrs| { @@ -1514,7 +1508,7 @@ impl<'a> Parser<'a> { let ident = this.parse_field_ident("enum", vlo)?; if this.token == token::Not { - if let Err(err) = this.unexpected::<()>() { + if let Err(err) = this.unexpected() { err.with_note(fluent::parse_macro_expands_to_enum_variant).emit(); } @@ -1937,7 +1931,7 @@ impl<'a> Parser<'a> { ) -> PResult<'a, FieldDef> { let name = self.parse_field_ident(adt_ty, lo)?; if self.token.kind == token::Not { - if let Err(mut err) = self.unexpected::<FieldDef>() { + if let Err(mut err) = self.unexpected() { // Encounter the macro invocation err.subdiagnostic(self.dcx(), MacroExpandsToAdtField { adt_ty }); return Err(err); @@ -2067,7 +2061,7 @@ impl<'a> Parser<'a> { let params = self.parse_token_tree(); // `MacParams` let pspan = params.span(); if !self.check(&token::OpenDelim(Delimiter::Brace)) { - return self.unexpected(); + self.unexpected()?; } let body = self.parse_token_tree(); // `MacBody` // Convert `MacParams MacBody` into `{ MacParams => MacBody }`. @@ -2077,7 +2071,7 @@ impl<'a> Parser<'a> { let dspan = DelimSpan::from_pair(pspan.shrink_to_lo(), bspan.shrink_to_hi()); P(DelimArgs { dspan, delim: Delimiter::Brace, tokens }) } else { - return self.unexpected(); + self.unexpected_any()? }; self.psess.gated_spans.gate(sym::decl_macro, lo.to(self.prev_token.span)); @@ -2692,7 +2686,7 @@ impl<'a> Parser<'a> { debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required); let (pat, colon) = this.parse_fn_param_pat_colon()?; if !colon { - let mut err = this.unexpected::<()>().unwrap_err(); + let mut err = this.unexpected().unwrap_err(); return if let Some(ident) = this.parameter_without_type(&mut err, pat, is_name_required, first_param) { @@ -2716,7 +2710,7 @@ impl<'a> Parser<'a> { { // This wasn't actually a type, but a pattern looking like a type, // so we are going to rollback and re-parse for recovery. - ty = this.unexpected(); + ty = this.unexpected_any(); } match ty { Ok(ty) => { diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 12879dc429b..de83528b52c 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -20,7 +20,7 @@ pub use pat::{CommaRecoveryMode, RecoverColon, RecoverComma}; pub use path::PathStyle; use rustc_ast::ptr::P; -use rustc_ast::token::{self, Delimiter, Nonterminal, Token, TokenKind}; +use rustc_ast::token::{self, Delimiter, Token, TokenKind}; use rustc_ast::tokenstream::{AttributesData, DelimSpacing, DelimSpan, Spacing}; use rustc_ast::tokenstream::{TokenStream, TokenTree, TokenTreeCursor}; use rustc_ast::util::case::Case; @@ -93,12 +93,13 @@ pub enum TrailingToken { #[macro_export] macro_rules! maybe_whole { ($p:expr, $constructor:ident, |$x:ident| $e:expr) => { - if let token::Interpolated(nt) = &$p.token.kind { - if let token::$constructor(x) = &nt.0 { - let $x = x.clone(); - $p.bump(); - return Ok($e); - } + if let token::Interpolated(nt) = &$p.token.kind + && let token::$constructor(x) = &nt.0 + { + #[allow(unused_mut)] + let mut $x = x.clone(); + $p.bump(); + return Ok($e); } }; } @@ -449,6 +450,7 @@ impl<'a> Parser<'a> { parser } + #[inline] pub fn recovery(mut self, recovery: Recovery) -> Self { self.recovery = recovery; self @@ -461,11 +463,14 @@ impl<'a> Parser<'a> { /// /// Technically, this only needs to restrict eager recovery by doing lookahead at more tokens. /// But making the distinction is very subtle, and simply forbidding all recovery is a lot simpler to uphold. + #[inline] fn may_recover(&self) -> bool { matches!(self.recovery, Recovery::Allowed) } - pub fn unexpected<T>(&mut self) -> PResult<'a, T> { + /// Version of [`unexpected`](Parser::unexpected) that "returns" any type in the `Ok` + /// (both those functions never return "Ok", and so can lie like that in the type). + pub fn unexpected_any<T>(&mut self) -> PResult<'a, T> { match self.expect_one_of(&[], &[]) { Err(e) => Err(e), // We can get `Ok(true)` from `recover_closing_delimiter` @@ -474,6 +479,10 @@ impl<'a> Parser<'a> { } } + pub fn unexpected(&mut self) -> PResult<'a, ()> { + self.unexpected_any() + } + /// Expects and consumes the token `t`. Signals an error if the next token is not `t`. pub fn expect(&mut self, t: &TokenKind) -> PResult<'a, Recovered> { if self.expected_tokens.is_empty() { @@ -542,6 +551,7 @@ impl<'a> Parser<'a> { /// /// This method will automatically add `tok` to `expected_tokens` if `tok` is not /// encountered. + #[inline] fn check(&mut self, tok: &TokenKind) -> bool { let is_present = self.token == *tok; if !is_present { @@ -550,6 +560,7 @@ impl<'a> Parser<'a> { is_present } + #[inline] fn check_noexpect(&self, tok: &TokenKind) -> bool { self.token == *tok } @@ -558,6 +569,7 @@ impl<'a> Parser<'a> { /// /// the main purpose of this function is to reduce the cluttering of the suggestions list /// which using the normal eat method could introduce in some cases. + #[inline] pub fn eat_noexpect(&mut self, tok: &TokenKind) -> bool { let is_present = self.check_noexpect(tok); if is_present { @@ -567,6 +579,7 @@ impl<'a> Parser<'a> { } /// Consumes a token 'tok' if it exists. Returns whether the given token was present. + #[inline] pub fn eat(&mut self, tok: &TokenKind) -> bool { let is_present = self.check(tok); if is_present { @@ -577,11 +590,13 @@ impl<'a> Parser<'a> { /// If the next token is the given keyword, returns `true` without eating it. /// An expectation is also added for diagnostics purposes. + #[inline] fn check_keyword(&mut self, kw: Symbol) -> bool { self.expected_tokens.push(TokenType::Keyword(kw)); self.token.is_keyword(kw) } + #[inline] fn check_keyword_case(&mut self, kw: Symbol, case: Case) -> bool { if self.check_keyword(kw) { return true; @@ -600,6 +615,7 @@ impl<'a> Parser<'a> { /// If the next token is the given keyword, eats it and returns `true`. /// Otherwise, returns `false`. An expectation is also added for diagnostics purposes. // Public for rustfmt usage. + #[inline] pub fn eat_keyword(&mut self, kw: Symbol) -> bool { if self.check_keyword(kw) { self.bump(); @@ -612,6 +628,7 @@ impl<'a> Parser<'a> { /// Eats a keyword, optionally ignoring the case. /// If the case differs (and is ignored) an error is issued. /// This is useful for recovery. + #[inline] fn eat_keyword_case(&mut self, kw: Symbol, case: Case) -> bool { if self.eat_keyword(kw) { return true; @@ -629,6 +646,7 @@ impl<'a> Parser<'a> { false } + #[inline] fn eat_keyword_noexpect(&mut self, kw: Symbol) -> bool { if self.token.is_keyword(kw) { self.bump(); @@ -650,6 +668,7 @@ impl<'a> Parser<'a> { self.token.is_keyword(kw) && self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident()) } + #[inline] fn check_or_expected(&mut self, ok: bool, typ: TokenType) -> bool { if ok { true @@ -697,6 +716,7 @@ impl<'a> Parser<'a> { /// Checks to see if the next token is either `+` or `+=`. /// Otherwise returns `false`. + #[inline] fn check_plus(&mut self) -> bool { self.check_or_expected( self.token.is_like_plus(), @@ -1278,7 +1298,11 @@ impl<'a> Parser<'a> { } fn parse_delim_args(&mut self) -> PResult<'a, P<DelimArgs>> { - if let Some(args) = self.parse_delim_args_inner() { Ok(P(args)) } else { self.unexpected() } + if let Some(args) = self.parse_delim_args_inner() { + Ok(P(args)) + } else { + self.unexpected_any() + } } fn parse_attr_args(&mut self) -> PResult<'a, AttrArgs> { @@ -1384,7 +1408,7 @@ impl<'a> Parser<'a> { /// so emit a proper diagnostic. // Public for rustfmt usage. pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> { - maybe_whole!(self, NtVis, |x| x.into_inner()); + maybe_whole!(self, NtVis, |vis| vis.into_inner()); if !self.eat_keyword(kw::Pub) { // We need a span for our `Spanned<VisibilityKind>`, but there's inherently no @@ -1561,8 +1585,21 @@ pub enum FlatToken { Empty, } -#[derive(Debug)] -pub enum ParseNtResult { - Nt(Nonterminal), +// Metavar captures of various kinds. +#[derive(Clone, Debug)] +pub enum ParseNtResult<NtType> { Tt(TokenTree), + Nt(NtType), +} + +impl<T> ParseNtResult<T> { + pub fn map_nt<F, U>(self, mut f: F) -> ParseNtResult<U> + where + F: FnMut(T) -> U, + { + match self { + ParseNtResult::Tt(tt) => ParseNtResult::Tt(tt), + ParseNtResult::Nt(nt) => ParseNtResult::Nt(f(nt)), + } + } } diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index f1572a18a8b..36a00df7b44 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -1,5 +1,5 @@ use rustc_ast::ptr::P; -use rustc_ast::token::{self, Delimiter, Nonterminal::*, NonterminalKind, Token}; +use rustc_ast::token::{self, Delimiter, Nonterminal, Nonterminal::*, NonterminalKind, Token}; use rustc_ast::HasTokens; use rustc_ast_pretty::pprust; use rustc_errors::PResult; @@ -66,15 +66,14 @@ impl<'a> Parser<'a> { token::Interpolated(nt) => may_be_ident(&nt.0), _ => false, }, - NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr => { - match &token.kind { + NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr => match &token.kind { token::Ident(..) | // box, ref, mut, and other identifiers (can stricten) token::OpenDelim(Delimiter::Parenthesis) | // tuple pattern token::OpenDelim(Delimiter::Bracket) | // slice pattern token::BinOp(token::And) | // reference token::BinOp(token::Minus) | // negative literal token::AndAnd | // double reference - token::Literal(_) | // literal + token::Literal(_) | // literal token::DotDot | // range pattern (future compat) token::DotDotDot | // range pattern (future compat) token::ModSep | // path @@ -84,8 +83,7 @@ impl<'a> Parser<'a> { token::BinOp(token::Or) => matches!(kind, NonterminalKind::PatWithOr), token::Interpolated(nt) => may_be_ident(&nt.0), _ => false, - } - } + }, NonterminalKind::Lifetime => match &token.kind { token::Lifetime(_) => true, token::Interpolated(nt) => { @@ -102,7 +100,10 @@ impl<'a> Parser<'a> { /// Parse a non-terminal (e.g. MBE `:pat` or `:ident`). Inlined because there is only one call /// site. #[inline] - pub fn parse_nonterminal(&mut self, kind: NonterminalKind) -> PResult<'a, ParseNtResult> { + pub fn parse_nonterminal( + &mut self, + kind: NonterminalKind, + ) -> PResult<'a, ParseNtResult<Nonterminal>> { // A `macro_rules!` invocation may pass a captured item/expr to a proc-macro, // which requires having captured tokens available. Since we cannot determine // in advance whether or not a proc-macro will be (transitively) invoked, diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 88ae1b5420f..fbc28859535 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -435,7 +435,7 @@ impl<'a> Parser<'a> { syntax_loc: Option<PatternLocation>, ) -> PResult<'a, P<Pat>> { maybe_recover_from_interpolated_ty_qpath!(self, true); - maybe_whole!(self, NtPat, |x| x); + maybe_whole!(self, NtPat, |pat| pat); let mut lo = self.token.span; @@ -498,11 +498,14 @@ impl<'a> Parser<'a> { } else { PatKind::Lit(const_expr) } + } else if self.is_builtin() { + self.parse_pat_builtin()? + } // Don't eagerly error on semantically invalid tokens when matching // declarative macros, as the input to those doesn't have to be // semantically valid. For attribute/derive proc macros this is not the // case, so doing the recovery for them is fine. - } else if self.can_be_ident_pat() + else if self.can_be_ident_pat() || (self.is_lit_bad_ident().is_some() && self.may_recover()) { // Parse `ident @ pat` @@ -1119,6 +1122,21 @@ impl<'a> Parser<'a> { .contains(&self.token.kind) } + fn parse_pat_builtin(&mut self) -> PResult<'a, PatKind> { + self.parse_builtin(|self_, _lo, ident| { + Ok(match ident.name { + // builtin#deref(PAT) + sym::deref => Some(ast::PatKind::Deref(self_.parse_pat_allow_top_alt( + None, + RecoverComma::Yes, + RecoverColon::Yes, + CommaRecoveryMode::LikelyTuple, + )?)), + _ => None, + }) + }) + } + /// Parses `box pat` fn parse_pat_box(&mut self) -> PResult<'a, PatKind> { let box_span = self.prev_token.span; diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 163d10d03f0..9153f2b9d06 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -660,7 +660,7 @@ impl<'a> Parser<'a> { // Add `>` to the list of expected tokens. self.check(&token::Gt); // Handle `,` to `;` substitution - let mut err = self.unexpected::<()>().unwrap_err(); + let mut err = self.unexpected().unwrap_err(); self.bump(); err.span_suggestion_verbose( self.prev_token.span.until(self.token.span), @@ -731,8 +731,6 @@ impl<'a> Parser<'a> { && matches!(args.output, ast::FnRetTy::Default(..)) { self.psess.gated_spans.gate(sym::return_type_notation, span); - } else { - self.psess.gated_spans.gate(sym::associated_type_bounds, span); } } let constraint = diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index fc907760531..6601011665b 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -40,8 +40,8 @@ impl<'a> Parser<'a> { })) } - /// If `force_collect` is [`ForceCollect::Yes`], forces collection of tokens regardless of whether - /// or not we have attributes + /// If `force_collect` is [`ForceCollect::Yes`], forces collection of tokens regardless of + /// whether or not we have attributes. // Public for `cfg_eval` macro expansion. pub fn parse_stmt_without_recovery( &mut self, @@ -51,18 +51,12 @@ impl<'a> Parser<'a> { let attrs = self.parse_outer_attributes()?; let lo = self.token.span; - // Don't use `maybe_whole` so that we have precise control - // over when we bump the parser - if let token::Interpolated(nt) = &self.token.kind - && let token::NtStmt(stmt) = &nt.0 - { - let mut stmt = stmt.clone(); - self.bump(); + maybe_whole!(self, NtStmt, |stmt| { stmt.visit_attrs(|stmt_attrs| { attrs.prepend_to_nt_inner(stmt_attrs); }); - return Ok(Some(stmt.into_inner())); - } + Some(stmt.into_inner()) + }); if self.token.is_keyword(kw::Mut) && self.is_keyword_ahead(1, &[kw::Let]) { self.bump(); @@ -539,7 +533,7 @@ impl<'a> Parser<'a> { blk_mode: BlockCheckMode, can_be_struct_literal: bool, ) -> PResult<'a, (AttrVec, P<Block>)> { - maybe_whole!(self, NtBlock, |x| (AttrVec::new(), x)); + maybe_whole!(self, NtBlock, |block| (AttrVec::new(), block)); let maybe_ident = self.prev_token.clone(); self.maybe_recover_unexpected_block_label(); @@ -643,7 +637,7 @@ impl<'a> Parser<'a> { recover: AttemptLocalParseRecovery, ) -> PResult<'a, Option<Stmt>> { // Skip looking for a trailing semicolon when we have an interpolated statement. - maybe_whole!(self, NtStmt, |x| Some(x.into_inner())); + maybe_whole!(self, NtStmt, |stmt| Some(stmt.into_inner())); let Some(mut stmt) = self.parse_stmt_without_recovery(true, ForceCollect::No)? else { return Ok(None); diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 2385c18c089..1cea32cb90f 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -250,7 +250,7 @@ impl<'a> Parser<'a> { ) -> PResult<'a, P<Ty>> { let allow_qpath_recovery = recover_qpath == RecoverQPath::Yes; maybe_recover_from_interpolated_ty_qpath!(self, allow_qpath_recovery); - maybe_whole!(self, NtTy, |x| x); + maybe_whole!(self, NtTy, |ty| ty); let lo = self.token.span; let mut impl_dyn_multi = false; diff --git a/compiler/rustc_parse_format/src/lib.rs b/compiler/rustc_parse_format/src/lib.rs index 79aab47fbe7..2bb4b09e337 100644 --- a/compiler/rustc_parse_format/src/lib.rs +++ b/compiler/rustc_parse_format/src/lib.rs @@ -907,25 +907,47 @@ impl<'a> Parser<'a> { let byte_pos = self.to_span_index(end); let start = InnerOffset(byte_pos.0 + 1); let field = self.argument(start); - // We can only parse `foo.bar` field access, any deeper nesting, - // or another type of expression, like method calls, are not supported + // We can only parse simple `foo.bar` field access or `foo.0` tuple index access, any + // deeper nesting, or another type of expression, like method calls, are not supported if !self.consume('}') { return; } if let ArgumentNamed(_) = arg.position { - if let ArgumentNamed(_) = field.position { - self.errors.insert( - 0, - ParseError { - description: "field access isn't supported".to_string(), - note: None, - label: "not supported".to_string(), - span: InnerSpan::new(arg.position_span.start, field.position_span.end), - secondary_label: None, - suggestion: Suggestion::UsePositional, - }, - ); - } + match field.position { + ArgumentNamed(_) => { + self.errors.insert( + 0, + ParseError { + description: "field access isn't supported".to_string(), + note: None, + label: "not supported".to_string(), + span: InnerSpan::new( + arg.position_span.start, + field.position_span.end, + ), + secondary_label: None, + suggestion: Suggestion::UsePositional, + }, + ); + } + ArgumentIs(_) => { + self.errors.insert( + 0, + ParseError { + description: "tuple index access isn't supported".to_string(), + note: None, + label: "not supported".to_string(), + span: InnerSpan::new( + arg.position_span.start, + field.position_span.end, + ), + secondary_label: None, + suggestion: Suggestion::UsePositional, + }, + ); + } + _ => {} + }; } } } diff --git a/compiler/rustc_passes/Cargo.toml b/compiler/rustc_passes/Cargo.toml index 6abfa08c530..b45a8dae277 100644 --- a/compiler/rustc_passes/Cargo.toml +++ b/compiler/rustc_passes/Cargo.toml @@ -18,6 +18,7 @@ rustc_index = { path = "../rustc_index" } rustc_lexer = { path = "../rustc_lexer" } rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } +rustc_privacy = { path = "../rustc_privacy" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } rustc_target = { path = "../rustc_target" } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index eb2399f7a64..1254ae8cfc8 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -609,13 +609,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { && !self.tcx.sess.target.is_like_wasm && !self.tcx.sess.opts.actually_rustdoc { - let hir::Node::Item(item) = self.tcx.hir_node(hir_id) else { - unreachable!(); - }; - let hir::ItemKind::Fn(sig, _, _) = item.kind else { - // target is `Fn` - unreachable!(); - }; + let sig = self.tcx.hir_node(hir_id).fn_sig().unwrap(); self.dcx().emit_err(errors::LangItemWithTargetFeature { attr_span: attr.span, diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs index 30a65d69c4e..4a1a2049083 100644 --- a/compiler/rustc_passes/src/check_const.rs +++ b/compiler/rustc_passes/src/check_const.rs @@ -48,7 +48,7 @@ impl NonConstExpr { Self::Match(TryDesugar(_)) => &[sym::const_try], // All other expressions are allowed. - Self::Loop(Loop | While) | Self::Match(Normal | FormatArgs) => &[], + Self::Loop(Loop | While) | Self::Match(Normal | Postfix | FormatArgs) => &[], }; Some(gates) @@ -155,16 +155,11 @@ impl<'tcx> CheckConstVisitor<'tcx> { // // FIXME(ecstaticmorse): Maybe this could be incorporated into `feature_err`? This // is a pretty narrow case, however. - if tcx.sess.is_nightly_build() { - for gate in missing_secondary { - // FIXME: make this translatable - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] - err.help(format!( - "add `#![feature({gate})]` to the crate attributes to enable" - )); - } - } + tcx.disabled_nightly_features( + &mut err, + def_id.map(|id| tcx.local_def_id_to_hir_id(id)), + missing_secondary.into_iter().map(|gate| (String::new(), *gate)), + ); err.emit(); } diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 350f7e166bf..c3124556648 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -831,7 +831,7 @@ fn create_and_seed_worklist( .collect::<Vec<_>>(); let crate_items = tcx.hir_crate_items(()); - for id in crate_items.items() { + for id in crate_items.free_items() { check_item(tcx, &mut worklist, &mut struct_constructors, &mut unsolved_impl_item, id); } @@ -1084,7 +1084,7 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) { let module_items = tcx.hir_module_items(module); - for item in module_items.items() { + for item in module_items.free_items() { let def_kind = tcx.def_kind(item.owner_id); let mut dead_codes = Vec::new(); diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index 2af5a54a0ca..f34e8d96f05 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -7,7 +7,6 @@ use rustc_hir::{ItemId, Node, CRATE_HIR_ID}; use rustc_middle::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::config::{sigpipe, CrateType, EntryFnType}; -use rustc_session::parse::feature_err; use rustc_span::symbol::sym; use rustc_span::{Span, Symbol}; @@ -133,16 +132,6 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId, return None; } - if main_def.is_import && !tcx.features().imported_main { - let span = main_def.span; - feature_err( - &tcx.sess, - sym::imported_main, - span, - "using an imported function as entry point `main` is experimental", - ) - .emit(); - } return Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx, def_id) })); } no_main_err(tcx, visitor); diff --git a/compiler/rustc_passes/src/hir_stats.rs b/compiler/rustc_passes/src/hir_stats.rs index d742ffc69e4..d0dba938b3b 100644 --- a/compiler/rustc_passes/src/hir_stats.rs +++ b/compiler/rustc_passes/src/hir_stats.rs @@ -300,6 +300,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { Path, Tuple, Box, + Deref, Ref, Lit, Range, @@ -566,6 +567,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { Path, Tuple, Box, + Deref, Ref, Lit, Range, diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 9fbae8f84b4..c2e604b02b3 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -6,6 +6,7 @@ // reachable as well. use hir::def_id::LocalDefIdSet; +use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -15,7 +16,8 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs} use rustc_middle::middle::privacy::{self, Level}; use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc}; use rustc_middle::query::Providers; -use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::ty::{self, ExistentialTraitRef, TyCtxt}; +use rustc_privacy::DefIdVisitor; use rustc_session::config::CrateType; use rustc_target::spec::abi::Abi; @@ -65,23 +67,8 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> { _ => None, }; - if let Some(res) = res - && let Some(def_id) = res.opt_def_id().and_then(|el| el.as_local()) - { - if self.def_id_represents_local_inlined_item(def_id.to_def_id()) { - self.worklist.push(def_id); - } else { - match res { - // Reachable constants and reachable statics can have their contents inlined - // into other crates. Mark them as reachable and recurse into their body. - Res::Def(DefKind::Const | DefKind::AssocConst | DefKind::Static { .. }, _) => { - self.worklist.push(def_id); - } - _ => { - self.reachable_symbols.insert(def_id); - } - } - } + if let Some(res) = res { + self.propagate_item(res); } intravisit::walk_expr(self, expr) @@ -198,17 +185,9 @@ impl<'tcx> ReachableContext<'tcx> { hir::ItemKind::Const(_, _, init) => { self.visit_nested_body(init); } - - // Reachable statics are inlined if read from another constant or static - // in other crates. Additionally anonymous nested statics may be created - // when evaluating a static, so preserve those, too. - hir::ItemKind::Static(_, _, init) => { - // FIXME(oli-obk): remove this body walking and instead walk the evaluated initializer - // to find nested items that end up in the final value instead of also marking symbols - // as reachable that are only needed for evaluation. - self.visit_nested_body(init); + hir::ItemKind::Static(..) => { if let Ok(alloc) = self.tcx.eval_static_initializer(item.owner_id.def_id) { - self.propagate_statics_from_alloc(item.owner_id.def_id, alloc); + self.propagate_from_alloc(alloc); } } @@ -268,7 +247,7 @@ impl<'tcx> ReachableContext<'tcx> { | Node::Field(_) | Node::Ty(_) | Node::Crate(_) - | Node::AssocOpaqueTy(..) => {} + | Node::Synthetic => {} _ => { bug!( "found unexpected node kind in worklist: {} ({:?})", @@ -279,28 +258,89 @@ impl<'tcx> ReachableContext<'tcx> { } } - /// Finds anonymous nested statics created for nested allocations and adds them to `reachable_symbols`. - fn propagate_statics_from_alloc(&mut self, root: LocalDefId, alloc: ConstAllocation<'tcx>) { + /// Finds things to add to `reachable_symbols` within allocations. + /// In contrast to visit_nested_body this ignores things that were only needed to evaluate + /// the allocation. + fn propagate_from_alloc(&mut self, alloc: ConstAllocation<'tcx>) { if !self.any_library { return; } for (_, prov) in alloc.0.provenance().ptrs().iter() { match self.tcx.global_alloc(prov.alloc_id()) { GlobalAlloc::Static(def_id) => { - if let Some(def_id) = def_id.as_local() - && self.tcx.local_parent(def_id) == root - // This is the main purpose of this function: add the def_id we find - // to `reachable_symbols`. - && self.reachable_symbols.insert(def_id) - && let Ok(alloc) = self.tcx.eval_static_initializer(def_id) - { - self.propagate_statics_from_alloc(root, alloc); + self.propagate_item(Res::Def(self.tcx.def_kind(def_id), def_id)) + } + GlobalAlloc::Function(instance) => { + // Manually visit to actually see the instance's `DefId`. Type visitors won't see it + self.propagate_item(Res::Def( + self.tcx.def_kind(instance.def_id()), + instance.def_id(), + )); + self.visit(instance.args); + } + GlobalAlloc::VTable(ty, trait_ref) => { + self.visit(ty); + // Manually visit to actually see the trait's `DefId`. Type visitors won't see it + if let Some(trait_ref) = trait_ref { + let ExistentialTraitRef { def_id, args } = trait_ref.skip_binder(); + self.visit_def_id(def_id, "", &""); + self.visit(args); } } - GlobalAlloc::Function(_) | GlobalAlloc::VTable(_, _) | GlobalAlloc::Memory(_) => {} + GlobalAlloc::Memory(alloc) => self.propagate_from_alloc(alloc), } } } + + fn propagate_item(&mut self, res: Res) { + let Res::Def(kind, def_id) = res else { return }; + let Some(def_id) = def_id.as_local() else { return }; + match kind { + DefKind::Static { nested: true, .. } => { + // This is the main purpose of this function: add the def_id we find + // to `reachable_symbols`. + if self.reachable_symbols.insert(def_id) { + if let Ok(alloc) = self.tcx.eval_static_initializer(def_id) { + // This cannot cause infinite recursion, because we abort by inserting into the + // work list once we hit a normal static. Nested statics, even if they somehow + // become recursive, are also not infinitely recursing, because of the + // `reachable_symbols` check above. + // We still need to protect against stack overflow due to deeply nested statics. + ensure_sufficient_stack(|| self.propagate_from_alloc(alloc)); + } + } + } + // Reachable constants and reachable statics can have their contents inlined + // into other crates. Mark them as reachable and recurse into their body. + DefKind::Const | DefKind::AssocConst | DefKind::Static { .. } => { + self.worklist.push(def_id); + } + _ => { + if self.def_id_represents_local_inlined_item(def_id.to_def_id()) { + self.worklist.push(def_id); + } else { + self.reachable_symbols.insert(def_id); + } + } + } + } +} + +impl<'tcx> DefIdVisitor<'tcx> for ReachableContext<'tcx> { + type Result = (); + + fn tcx(&self) -> TyCtxt<'tcx> { + self.tcx + } + + fn visit_def_id( + &mut self, + def_id: DefId, + _kind: &str, + _descr: &dyn std::fmt::Display, + ) -> Self::Result { + self.propagate_item(Res::Def(self.tcx.def_kind(def_id), def_id)) + } } fn check_item<'tcx>( @@ -397,7 +437,7 @@ fn reachable_set(tcx: TyCtxt<'_>, (): ()) -> LocalDefIdSet { // trait is a lang item. let crate_items = tcx.hir_crate_items(()); - for id in crate_items.items() { + for id in crate_items.free_items() { check_item(tcx, id, &mut reachable_context.worklist, effective_visibilities); } diff --git a/compiler/rustc_pattern_analysis/Cargo.toml b/compiler/rustc_pattern_analysis/Cargo.toml index b9bdcb41929..6357d18b9da 100644 --- a/compiler/rustc_pattern_analysis/Cargo.toml +++ b/compiler/rustc_pattern_analysis/Cargo.toml @@ -22,6 +22,10 @@ smallvec = { version = "1.8.1", features = ["union"] } tracing = "0.1" # tidy-alphabetical-end +[dev-dependencies] +tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "ansi"] } +tracing-tree = "0.2.0" + [features] default = ["rustc"] rustc = [ diff --git a/compiler/rustc_pattern_analysis/src/constructor.rs b/compiler/rustc_pattern_analysis/src/constructor.rs index bbb89576ef7..95c5556410d 100644 --- a/compiler/rustc_pattern_analysis/src/constructor.rs +++ b/compiler/rustc_pattern_analysis/src/constructor.rs @@ -678,15 +678,19 @@ pub enum Constructor<Cx: PatCx> { Or, /// Wildcard pattern. Wildcard, + /// Never pattern. Only used in `WitnessPat`. An actual never pattern should be lowered as + /// `Wildcard`. + Never, /// Fake extra constructor for enums that aren't allowed to be matched exhaustively. Also used - /// for those types for which we cannot list constructors explicitly, like `f64` and `str`. + /// for those types for which we cannot list constructors explicitly, like `f64` and `str`. Only + /// used in `WitnessPat`. NonExhaustive, - /// Fake extra constructor for variants that should not be mentioned in diagnostics. - /// We use this for variants behind an unstable gate as well as - /// `#[doc(hidden)]` ones. + /// Fake extra constructor for variants that should not be mentioned in diagnostics. We use this + /// for variants behind an unstable gate as well as `#[doc(hidden)]` ones. Only used in + /// `WitnessPat`. Hidden, /// Fake extra constructor for constructors that are not seen in the matrix, as explained at the - /// top of the file. + /// top of the file. Only used for specialization. Missing, /// Fake extra constructor that indicates and empty field that is private. When we encounter one /// we skip the column entirely so we don't observe its emptiness. Only used for specialization. @@ -708,6 +712,7 @@ impl<Cx: PatCx> Clone for Constructor<Cx> { Constructor::Str(value) => Constructor::Str(value.clone()), Constructor::Opaque(inner) => Constructor::Opaque(inner.clone()), Constructor::Or => Constructor::Or, + Constructor::Never => Constructor::Never, Constructor::Wildcard => Constructor::Wildcard, Constructor::NonExhaustive => Constructor::NonExhaustive, Constructor::Hidden => Constructor::Hidden, @@ -814,6 +819,81 @@ impl<Cx: PatCx> Constructor<Cx> { } }) } + + pub(crate) fn fmt_fields( + &self, + f: &mut fmt::Formatter<'_>, + ty: &Cx::Ty, + mut fields: impl Iterator<Item = impl fmt::Debug>, + ) -> fmt::Result { + let mut first = true; + let mut start_or_continue = |s| { + if first { + first = false; + "" + } else { + s + } + }; + let mut start_or_comma = || start_or_continue(", "); + + match self { + Struct | Variant(_) | UnionField => { + Cx::write_variant_name(f, self, ty)?; + // Without `cx`, we can't know which field corresponds to which, so we can't + // get the names of the fields. Instead we just display everything as a tuple + // struct, which should be good enough. + write!(f, "(")?; + for p in fields { + write!(f, "{}{:?}", start_or_comma(), p)?; + } + write!(f, ")")?; + } + // Note: given the expansion of `&str` patterns done in `expand_pattern`, we should + // be careful to detect strings here. However a string literal pattern will never + // be reported as a non-exhaustiveness witness, so we can ignore this issue. + Ref => { + write!(f, "&{:?}", &fields.next().unwrap())?; + } + Slice(slice) => { + write!(f, "[")?; + match slice.kind { + SliceKind::FixedLen(_) => { + for p in fields { + write!(f, "{}{:?}", start_or_comma(), p)?; + } + } + SliceKind::VarLen(prefix_len, _) => { + for p in fields.by_ref().take(prefix_len) { + write!(f, "{}{:?}", start_or_comma(), p)?; + } + write!(f, "{}..", start_or_comma())?; + for p in fields { + write!(f, "{}{:?}", start_or_comma(), p)?; + } + } + } + write!(f, "]")?; + } + Bool(b) => write!(f, "{b}")?, + // Best-effort, will render signed ranges incorrectly + IntRange(range) => write!(f, "{range:?}")?, + F32Range(lo, hi, end) => write!(f, "{lo}{end}{hi}")?, + F64Range(lo, hi, end) => write!(f, "{lo}{end}{hi}")?, + Str(value) => write!(f, "{value:?}")?, + Opaque(..) => write!(f, "<constant pattern>")?, + Or => { + for pat in fields { + write!(f, "{}{:?}", start_or_continue(" | "), pat)?; + } + } + Never => write!(f, "!")?, + Wildcard | Missing | NonExhaustive | Hidden | PrivateUninhabited => { + write!(f, "_ : {:?}", ty)? + } + } + Ok(()) + } } #[derive(Debug, Clone, Copy)] @@ -1040,10 +1120,32 @@ impl<Cx: PatCx> ConstructorSet<Cx> { // In a `MaybeInvalid` place even an empty pattern may be reachable. We therefore // add a dummy empty constructor here, which will be ignored if the place is // `ValidOnly`. - missing_empty.push(NonExhaustive); + missing_empty.push(Never); } } SplitConstructorSet { present, missing, missing_empty } } + + /// Whether this set only contains empty constructors. + pub(crate) fn all_empty(&self) -> bool { + match self { + ConstructorSet::Bool + | ConstructorSet::Integers { .. } + | ConstructorSet::Ref + | ConstructorSet::Union + | ConstructorSet::Unlistable => false, + ConstructorSet::NoConstructors => true, + ConstructorSet::Struct { empty } => *empty, + ConstructorSet::Variants { variants, non_exhaustive } => { + !*non_exhaustive + && variants + .iter() + .all(|visibility| matches!(visibility, VariantVisibility::Empty)) + } + ConstructorSet::Slice { array_len, subtype_is_empty } => { + *subtype_is_empty && matches!(array_len, Some(1..)) + } + } + } } diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index 5c57c990323..1a1da5c55f6 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -49,6 +49,12 @@ pub mod index { } } + impl<V> FromIterator<V> for IdxContainer<usize, V> { + fn from_iter<T: IntoIterator<Item = V>>(iter: T) -> Self { + Self(iter.into_iter().enumerate().collect()) + } + } + #[derive(Debug)] pub struct IdxSet<T>(pub rustc_hash::FxHashSet<T>); impl<T: Idx> IdxSet<T> { @@ -120,7 +126,8 @@ pub trait PatCx: Sized + fmt::Debug { /// `DeconstructedPat`. Only invoqued when `pat.ctor()` is `Struct | Variant(_) | UnionField`. fn write_variant_name( f: &mut fmt::Formatter<'_>, - pat: &crate::pat::DeconstructedPat<Self>, + ctor: &crate::constructor::Constructor<Self>, + ty: &Self::Ty, ) -> fmt::Result; /// Raise a bug. diff --git a/compiler/rustc_pattern_analysis/src/pat.rs b/compiler/rustc_pattern_analysis/src/pat.rs index e3667d44bc9..5f388ee9f89 100644 --- a/compiler/rustc_pattern_analysis/src/pat.rs +++ b/compiler/rustc_pattern_analysis/src/pat.rs @@ -138,80 +138,11 @@ impl<Cx: PatCx> DeconstructedPat<Cx> { /// This is best effort and not good enough for a `Display` impl. impl<Cx: PatCx> fmt::Debug for DeconstructedPat<Cx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let pat = self; - let mut first = true; - let mut start_or_continue = |s| { - if first { - first = false; - "" - } else { - s - } - }; - let mut start_or_comma = || start_or_continue(", "); - let mut fields: Vec<_> = (0..self.arity).map(|_| PatOrWild::Wild).collect(); for ipat in self.iter_fields() { fields[ipat.idx] = PatOrWild::Pat(&ipat.pat); } - - match pat.ctor() { - Struct | Variant(_) | UnionField => { - Cx::write_variant_name(f, pat)?; - // Without `cx`, we can't know which field corresponds to which, so we can't - // get the names of the fields. Instead we just display everything as a tuple - // struct, which should be good enough. - write!(f, "(")?; - for p in fields { - write!(f, "{}", start_or_comma())?; - write!(f, "{p:?}")?; - } - write!(f, ")") - } - // Note: given the expansion of `&str` patterns done in `expand_pattern`, we should - // be careful to detect strings here. However a string literal pattern will never - // be reported as a non-exhaustiveness witness, so we can ignore this issue. - Ref => { - write!(f, "&{:?}", &fields[0]) - } - Slice(slice) => { - write!(f, "[")?; - match slice.kind { - SliceKind::FixedLen(_) => { - for p in fields { - write!(f, "{}{:?}", start_or_comma(), p)?; - } - } - SliceKind::VarLen(prefix_len, _) => { - for p in &fields[..prefix_len] { - write!(f, "{}{:?}", start_or_comma(), p)?; - } - write!(f, "{}", start_or_comma())?; - write!(f, "..")?; - for p in &fields[prefix_len..] { - write!(f, "{}{:?}", start_or_comma(), p)?; - } - } - } - write!(f, "]") - } - Bool(b) => write!(f, "{b}"), - // Best-effort, will render signed ranges incorrectly - IntRange(range) => write!(f, "{range:?}"), - F32Range(lo, hi, end) => write!(f, "{lo}{end}{hi}"), - F64Range(lo, hi, end) => write!(f, "{lo}{end}{hi}"), - Str(value) => write!(f, "{value:?}"), - Opaque(..) => write!(f, "<constant pattern>"), - Or => { - for pat in fields { - write!(f, "{}{:?}", start_or_continue(" | "), pat)?; - } - Ok(()) - } - Wildcard | Missing | NonExhaustive | Hidden | PrivateUninhabited => { - write!(f, "_ : {:?}", pat.ty()) - } - } + self.ctor().fmt_fields(f, self.ty(), fields.into_iter()) } } @@ -294,7 +225,6 @@ impl<'p, Cx: PatCx> fmt::Debug for PatOrWild<'p, Cx> { /// Same idea as `DeconstructedPat`, except this is a fictitious pattern built up for diagnostics /// purposes. As such they don't use interning and can be cloned. -#[derive(Debug)] pub struct WitnessPat<Cx: PatCx> { ctor: Constructor<Cx>, pub(crate) fields: Vec<WitnessPat<Cx>>, @@ -311,18 +241,24 @@ impl<Cx: PatCx> WitnessPat<Cx> { pub(crate) fn new(ctor: Constructor<Cx>, fields: Vec<Self>, ty: Cx::Ty) -> Self { Self { ctor, fields, ty } } - pub(crate) fn wildcard(ty: Cx::Ty) -> Self { - Self::new(Wildcard, Vec::new(), ty) + /// Create a wildcard pattern for this type. If the type is empty, we create a `!` pattern. + pub(crate) fn wildcard(cx: &Cx, ty: Cx::Ty) -> Self { + let is_empty = cx.ctors_for_ty(&ty).is_ok_and(|ctors| ctors.all_empty()); + let ctor = if is_empty { Never } else { Wildcard }; + Self::new(ctor, Vec::new(), ty) } /// Construct a pattern that matches everything that starts with this constructor. /// For example, if `ctor` is a `Constructor::Variant` for `Option::Some`, we get the pattern /// `Some(_)`. pub(crate) fn wild_from_ctor(cx: &Cx, ctor: Constructor<Cx>, ty: Cx::Ty) -> Self { + if matches!(ctor, Wildcard) { + return Self::wildcard(cx, ty); + } let fields = cx .ctor_sub_tys(&ctor, &ty) .filter(|(_, PrivateUninhabitedField(skip))| !skip) - .map(|(ty, _)| Self::wildcard(ty)) + .map(|(ty, _)| Self::wildcard(cx, ty)) .collect(); Self::new(ctor, fields, ty) } @@ -334,7 +270,22 @@ impl<Cx: PatCx> WitnessPat<Cx> { &self.ty } + pub fn is_never_pattern(&self) -> bool { + match self.ctor() { + Never => true, + Or => self.fields.iter().all(|p| p.is_never_pattern()), + _ => self.fields.iter().any(|p| p.is_never_pattern()), + } + } + pub fn iter_fields(&self) -> impl Iterator<Item = &WitnessPat<Cx>> { self.fields.iter() } } + +/// This is best effort and not good enough for a `Display` impl. +impl<Cx: PatCx> fmt::Debug for WitnessPat<Cx> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.ctor().fmt_fields(f, self.ty(), self.fields.iter()) + } +} diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index fd51fbedeef..ae3eabe1745 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -247,7 +247,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { _ => bug!("bad slice pattern {:?} {:?}", ctor, ty), }, Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..) - | NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => &[], + | Never | NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => &[], Or => { bug!("called `Fields::wildcards` on an `Or` ctor") } @@ -275,7 +275,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { Ref => 1, Slice(slice) => slice.arity(), Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..) - | NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => 0, + | Never | NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => 0, Or => bug!("The `Or` constructor doesn't have a fixed arity"), } } @@ -462,6 +462,12 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { _ => bug!("pattern has unexpected type: pat: {:?}, ty: {:?}", pat, ty), }; } + PatKind::DerefPattern { .. } => { + // FIXME(deref_patterns): At least detect that `box _` is irrefutable. + fields = vec![]; + arity = 0; + ctor = Opaque(OpaqueId::new()); + } PatKind::Leaf { subpatterns } | PatKind::Variant { subpatterns, .. } => { match ty.kind() { ty::Tuple(fs) => { @@ -824,7 +830,8 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { } } &Str(value) => PatKind::Constant { value }, - Wildcard | NonExhaustive | Hidden | PrivateUninhabited => PatKind::Wild, + Never if self.tcx.features().never_patterns => PatKind::Never, + Never | Wildcard | NonExhaustive | Hidden | PrivateUninhabited => PatKind::Wild, Missing { .. } => bug!( "trying to convert a `Missing` constructor into a `Pat`; this is probably a bug, `Missing` should have been processed in `apply_constructors`" @@ -873,13 +880,14 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { fn write_variant_name( f: &mut fmt::Formatter<'_>, - pat: &crate::pat::DeconstructedPat<Self>, + ctor: &crate::constructor::Constructor<Self>, + ty: &Self::Ty, ) -> fmt::Result { - if let ty::Adt(adt, _) = pat.ty().kind() { + if let ty::Adt(adt, _) = ty.kind() { if adt.is_box() { write!(f, "Box")? } else { - let variant = adt.variant(Self::variant_index_for_adt(pat.ctor(), *adt)); + let variant = adt.variant(Self::variant_index_for_adt(ctor, *adt)); write!(f, "{}", variant.name)?; } } diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs index 3760db8b688..cdc03eaeb37 100644 --- a/compiler/rustc_pattern_analysis/src/usefulness.rs +++ b/compiler/rustc_pattern_analysis/src/usefulness.rs @@ -1042,7 +1042,7 @@ struct MatrixRow<'p, Cx: PatCx> { is_under_guard: bool, /// When we specialize, we remember which row of the original matrix produced a given row of the /// specialized matrix. When we unspecialize, we use this to propagate usefulness back up the - /// callstack. + /// callstack. On creation, this stores the index of the original match arm. parent_row: usize, /// False when the matrix is just built. This is set to `true` by /// [`compute_exhaustiveness_and_usefulness`] if the arm is found to be useful. @@ -1163,10 +1163,10 @@ impl<'p, Cx: PatCx> Matrix<'p, Cx> { place_info: smallvec![place_info], wildcard_row_is_relevant: true, }; - for (row_id, arm) in arms.iter().enumerate() { + for (arm_id, arm) in arms.iter().enumerate() { let v = MatrixRow { pats: PatStack::from_pattern(arm.pat), - parent_row: row_id, // dummy, we don't read it + parent_row: arm_id, is_under_guard: arm.has_guard, useful: false, intersects: BitSet::new_empty(0), // Initialized in `Matrix::expand_and_push`. @@ -1738,6 +1738,9 @@ pub struct UsefulnessReport<'p, Cx: PatCx> { /// If the match is exhaustive, this is empty. If not, this contains witnesses for the lack of /// exhaustiveness. pub non_exhaustiveness_witnesses: Vec<WitnessPat<Cx>>, + /// For each arm, a set of indices of arms above it that have non-empty intersection, i.e. there + /// is a value matched by both arms. This may miss real intersections. + pub arm_intersections: Vec<BitSet<usize>>, } /// Computes whether a match is exhaustive and which of its arms are useful. @@ -1769,5 +1772,19 @@ pub fn compute_match_usefulness<'p, Cx: PatCx>( }) .collect(); - Ok(UsefulnessReport { arm_usefulness, non_exhaustiveness_witnesses }) + let mut arm_intersections: Vec<_> = + arms.iter().enumerate().map(|(i, _)| BitSet::new_empty(i)).collect(); + for row in matrix.rows() { + let arm_id = row.parent_row; + for intersection in row.intersects.iter() { + // Convert the matrix row ids into arm ids (they can differ because we expand or-patterns). + let arm_intersection = matrix.rows[intersection].parent_row; + // Note: self-intersection can happen with or-patterns. + if arm_intersection != arm_id { + arm_intersections[arm_id].insert(arm_intersection); + } + } + } + + Ok(UsefulnessReport { arm_usefulness, non_exhaustiveness_witnesses, arm_intersections }) } diff --git a/compiler/rustc_pattern_analysis/tests/common/mod.rs b/compiler/rustc_pattern_analysis/tests/common/mod.rs new file mode 100644 index 00000000000..e72fddb9e9a --- /dev/null +++ b/compiler/rustc_pattern_analysis/tests/common/mod.rs @@ -0,0 +1,315 @@ +use rustc_pattern_analysis::{ + constructor::{ + Constructor, ConstructorSet, IntRange, MaybeInfiniteInt, RangeEnd, VariantVisibility, + }, + usefulness::{PlaceValidity, UsefulnessReport}, + Captures, MatchArm, PatCx, PrivateUninhabitedField, +}; + +/// Sets up `tracing` for easier debugging. Tries to look like the `rustc` setup. +pub fn init_tracing() { + use tracing_subscriber::layer::SubscriberExt; + use tracing_subscriber::util::SubscriberInitExt; + use tracing_subscriber::Layer; + let _ = tracing_tree::HierarchicalLayer::default() + .with_writer(std::io::stderr) + .with_indent_lines(true) + .with_ansi(true) + .with_targets(true) + .with_indent_amount(2) + .with_subscriber( + tracing_subscriber::Registry::default() + .with(tracing_subscriber::EnvFilter::from_default_env()), + ) + .try_init(); +} + +/// A simple set of types. +#[allow(dead_code)] +#[derive(Debug, Copy, Clone)] +pub enum Ty { + /// Booleans + Bool, + /// 8-bit unsigned integers + U8, + /// Tuples. + Tuple(&'static [Ty]), + /// A struct with `arity` fields of type `ty`. + BigStruct { arity: usize, ty: &'static Ty }, + /// A enum with `arity` variants of type `ty`. + BigEnum { arity: usize, ty: &'static Ty }, +} + +/// The important logic. +impl Ty { + pub fn sub_tys(&self, ctor: &Constructor<Cx>) -> Vec<Self> { + use Constructor::*; + match (ctor, *self) { + (Struct, Ty::Tuple(tys)) => tys.iter().copied().collect(), + (Struct, Ty::BigStruct { arity, ty }) => (0..arity).map(|_| *ty).collect(), + (Variant(_), Ty::BigEnum { ty, .. }) => vec![*ty], + (Bool(..) | IntRange(..) | NonExhaustive | Missing | Wildcard, _) => vec![], + _ => panic!("Unexpected ctor {ctor:?} for type {self:?}"), + } + } + + pub fn ctor_set(&self) -> ConstructorSet<Cx> { + match *self { + Ty::Bool => ConstructorSet::Bool, + Ty::U8 => ConstructorSet::Integers { + range_1: IntRange::from_range( + MaybeInfiniteInt::new_finite_uint(0), + MaybeInfiniteInt::new_finite_uint(255), + RangeEnd::Included, + ), + range_2: None, + }, + Ty::Tuple(..) | Ty::BigStruct { .. } => ConstructorSet::Struct { empty: false }, + Ty::BigEnum { arity, .. } => ConstructorSet::Variants { + variants: (0..arity).map(|_| VariantVisibility::Visible).collect(), + non_exhaustive: false, + }, + } + } + + pub fn write_variant_name( + &self, + f: &mut std::fmt::Formatter<'_>, + ctor: &Constructor<Cx>, + ) -> std::fmt::Result { + match (*self, ctor) { + (Ty::Tuple(..), _) => Ok(()), + (Ty::BigStruct { .. }, _) => write!(f, "BigStruct"), + (Ty::BigEnum { .. }, Constructor::Variant(i)) => write!(f, "BigEnum::Variant{i}"), + _ => write!(f, "{:?}::{:?}", self, ctor), + } + } +} + +/// Compute usefulness in our simple context (and set up tracing for easier debugging). +pub fn compute_match_usefulness<'p>( + arms: &[MatchArm<'p, Cx>], + ty: Ty, + scrut_validity: PlaceValidity, + complexity_limit: Option<usize>, +) -> Result<UsefulnessReport<'p, Cx>, ()> { + init_tracing(); + rustc_pattern_analysis::usefulness::compute_match_usefulness( + &Cx, + arms, + ty, + scrut_validity, + complexity_limit, + ) +} + +#[derive(Debug)] +pub struct Cx; + +/// The context for pattern analysis. Forwards anything interesting to `Ty` methods. +impl PatCx for Cx { + type Ty = Ty; + type Error = (); + type VariantIdx = usize; + type StrLit = (); + type ArmData = (); + type PatData = (); + + fn is_exhaustive_patterns_feature_on(&self) -> bool { + false + } + + fn is_min_exhaustive_patterns_feature_on(&self) -> bool { + false + } + + fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize { + ty.sub_tys(ctor).len() + } + + fn ctor_sub_tys<'a>( + &'a self, + ctor: &'a Constructor<Self>, + ty: &'a Self::Ty, + ) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a> + { + ty.sub_tys(ctor).into_iter().map(|ty| (ty, PrivateUninhabitedField(false))) + } + + fn ctors_for_ty(&self, ty: &Self::Ty) -> Result<ConstructorSet<Self>, Self::Error> { + Ok(ty.ctor_set()) + } + + fn write_variant_name( + f: &mut std::fmt::Formatter<'_>, + ctor: &Constructor<Self>, + ty: &Self::Ty, + ) -> std::fmt::Result { + ty.write_variant_name(f, ctor) + } + + fn bug(&self, fmt: std::fmt::Arguments<'_>) -> Self::Error { + panic!("{}", fmt) + } + + /// Abort when reaching the complexity limit. This is what we'll check in tests. + fn complexity_exceeded(&self) -> Result<(), Self::Error> { + Err(()) + } +} + +/// Construct a single pattern; see `pats!()`. +#[allow(unused_macros)] +macro_rules! pat { + ($($rest:tt)*) => {{ + let mut vec = pats!($($rest)*); + vec.pop().unwrap() + }}; +} + +/// A macro to construct patterns. Called like `pats!(type_expr; pattern, pattern, ..)` and returns +/// a `Vec<DeconstructedPat>`. A pattern can be nested and looks like `Constructor(pat, pat)` or +/// `Constructor { .i: pat, .j: pat }`, where `Constructor` is `Struct`, `Variant.i` (with index +/// `i`), as well as booleans and integer ranges. +/// +/// The general structure of the macro is a tt-muncher with several stages identified with +/// `@something(args)`. The args are a key-value list (the keys ensure we don't mix the arguments +/// around) which is passed down and modified as needed. We then parse token-trees from +/// left-to-right. Non-trivial recursion happens when we parse the arguments to a pattern: we +/// recurse to parse the tokens inside `{..}`/`(..)`, and then we continue parsing anything that +/// follows. +macro_rules! pats { + // Entrypoint + // Parse `type; ..` + ($ty:expr; $($rest:tt)*) => {{ + #[allow(unused_imports)] + use rustc_pattern_analysis::{ + constructor::{Constructor, IntRange, MaybeInfiniteInt, RangeEnd}, + pat::DeconstructedPat, + }; + let ty = $ty; + // The heart of the macro is designed to push `IndexedPat`s into a `Vec`, so we work around + // that. + let sub_tys = ::std::iter::repeat(&ty); + let mut vec = Vec::new(); + pats!(@ctor(vec:vec, sub_tys:sub_tys, idx:0) $($rest)*); + vec.into_iter().map(|ipat| ipat.pat).collect::<Vec<_>>() + }}; + + // Parse `constructor ..` + + (@ctor($($args:tt)*) true $($rest:tt)*) => {{ + let ctor = Constructor::Bool(true); + pats!(@pat($($args)*, ctor:ctor) $($rest)*) + }}; + (@ctor($($args:tt)*) false $($rest:tt)*) => {{ + let ctor = Constructor::Bool(false); + pats!(@pat($($args)*, ctor:ctor) $($rest)*) + }}; + (@ctor($($args:tt)*) Struct $($rest:tt)*) => {{ + let ctor = Constructor::Struct; + pats!(@pat($($args)*, ctor:ctor) $($rest)*) + }}; + (@ctor($($args:tt)*) ( $($fields:tt)* ) $($rest:tt)*) => {{ + let ctor = Constructor::Struct; // tuples + pats!(@pat($($args)*, ctor:ctor) ( $($fields)* ) $($rest)*) + }}; + (@ctor($($args:tt)*) Variant.$variant:ident $($rest:tt)*) => {{ + let ctor = Constructor::Variant($variant); + pats!(@pat($($args)*, ctor:ctor) $($rest)*) + }}; + (@ctor($($args:tt)*) Variant.$variant:literal $($rest:tt)*) => {{ + let ctor = Constructor::Variant($variant); + pats!(@pat($($args)*, ctor:ctor) $($rest)*) + }}; + (@ctor($($args:tt)*) _ $($rest:tt)*) => {{ + let ctor = Constructor::Wildcard; + pats!(@pat($($args)*, ctor:ctor) $($rest)*) + }}; + + // Integers and int ranges + (@ctor($($args:tt)*) $($start:literal)?..$end:literal $($rest:tt)*) => {{ + let ctor = Constructor::IntRange(IntRange::from_range( + pats!(@rangeboundary- $($start)?), + pats!(@rangeboundary+ $end), + RangeEnd::Excluded, + )); + pats!(@pat($($args)*, ctor:ctor) $($rest)*) + }}; + (@ctor($($args:tt)*) $($start:literal)?.. $($rest:tt)*) => {{ + let ctor = Constructor::IntRange(IntRange::from_range( + pats!(@rangeboundary- $($start)?), + pats!(@rangeboundary+), + RangeEnd::Excluded, + )); + pats!(@pat($($args)*, ctor:ctor) $($rest)*) + }}; + (@ctor($($args:tt)*) $($start:literal)?..=$end:literal $($rest:tt)*) => {{ + let ctor = Constructor::IntRange(IntRange::from_range( + pats!(@rangeboundary- $($start)?), + pats!(@rangeboundary+ $end), + RangeEnd::Included, + )); + pats!(@pat($($args)*, ctor:ctor) $($rest)*) + }}; + (@ctor($($args:tt)*) $int:literal $($rest:tt)*) => {{ + let ctor = Constructor::IntRange(IntRange::from_range( + pats!(@rangeboundary- $int), + pats!(@rangeboundary+ $int), + RangeEnd::Included, + )); + pats!(@pat($($args)*, ctor:ctor) $($rest)*) + }}; + // Utility to manage range boundaries. + (@rangeboundary $sign:tt $int:literal) => { MaybeInfiniteInt::new_finite_uint($int) }; + (@rangeboundary -) => { MaybeInfiniteInt::NegInfinity }; + (@rangeboundary +) => { MaybeInfiniteInt::PosInfinity }; + + // Parse subfields: `(..)` or `{..}` + + // Constructor with no fields, e.g. `bool` or `Variant.1`. + (@pat($($args:tt)*) $(,)?) => { + pats!(@pat($($args)*) {}) + }; + (@pat($($args:tt)*) , $($rest:tt)*) => { + pats!(@pat($($args)*) {}, $($rest)*) + }; + // `(..)` and `{..}` are treated the same. + (@pat($($args:tt)*) ( $($subpat:tt)* ) $($rest:tt)*) => {{ + pats!(@pat($($args)*) { $($subpat)* } $($rest)*) + }}; + (@pat(vec:$vec:expr, sub_tys:$sub_tys:expr, idx:$idx:expr, ctor:$ctor:expr) { $($fields:tt)* } $($rest:tt)*) => {{ + let sub_tys = $sub_tys; + let index = $idx; + // Silly dance to work with both a vec and `iter::repeat()`. + let ty = *(&sub_tys).clone().into_iter().nth(index).unwrap(); + let ctor = $ctor; + let ctor_sub_tys = &ty.sub_tys(&ctor); + #[allow(unused_mut)] + let mut fields = Vec::new(); + // Parse subpatterns (note the leading comma). + pats!(@fields(idx:0, vec:fields, sub_tys:ctor_sub_tys) ,$($fields)*); + let arity = ctor_sub_tys.len(); + let pat = DeconstructedPat::new(ctor, fields, arity, ty, ()).at_index(index); + $vec.push(pat); + + // Continue parsing further patterns. + pats!(@fields(idx:index+1, vec:$vec, sub_tys:sub_tys) $($rest)*); + }}; + + // Parse fields one by one. + + // No fields left. + (@fields($($args:tt)*) $(,)?) => {}; + // `.i: pat` sets the current index to `i`. + (@fields(idx:$_idx:expr, $($args:tt)*) , .$idx:literal : $($rest:tt)*) => {{ + pats!(@ctor($($args)*, idx:$idx) $($rest)*); + }}; + (@fields(idx:$_idx:expr, $($args:tt)*) , .$idx:ident : $($rest:tt)*) => {{ + pats!(@ctor($($args)*, idx:$idx) $($rest)*); + }}; + // Field without an explicit index; we use the current index which gets incremented above. + (@fields(idx:$idx:expr, $($args:tt)*) , $($rest:tt)*) => {{ + pats!(@ctor($($args)*, idx:$idx) $($rest)*); + }}; +} diff --git a/compiler/rustc_pattern_analysis/tests/complexity.rs b/compiler/rustc_pattern_analysis/tests/complexity.rs new file mode 100644 index 00000000000..93f455c6257 --- /dev/null +++ b/compiler/rustc_pattern_analysis/tests/complexity.rs @@ -0,0 +1,109 @@ +//! Test the pattern complexity limit. +use common::*; +use rustc_pattern_analysis::{pat::DeconstructedPat, usefulness::PlaceValidity, MatchArm}; + +#[macro_use] +mod common; + +/// Analyze a match made of these patterns. Ignore the report; we only care whether we exceeded the +/// limit or not. +fn check(patterns: &[DeconstructedPat<Cx>], complexity_limit: usize) -> Result<(), ()> { + let ty = *patterns[0].ty(); + let arms: Vec<_> = + patterns.iter().map(|pat| MatchArm { pat, has_guard: false, arm_data: () }).collect(); + compute_match_usefulness(arms.as_slice(), ty, PlaceValidity::ValidOnly, Some(complexity_limit)) + .map(|_report| ()) +} + +/// Asserts that analyzing this match takes exactly `complexity` steps. +#[track_caller] +fn assert_complexity(patterns: Vec<DeconstructedPat<Cx>>, complexity: usize) { + assert!(check(&patterns, complexity).is_ok()); + assert!(check(&patterns, complexity - 1).is_err()); +} + +/// Construct a match like: +/// ```ignore(illustrative) +/// match ... { +/// BigStruct { field01: true, .. } => {} +/// BigStruct { field02: true, .. } => {} +/// BigStruct { field03: true, .. } => {} +/// BigStruct { field04: true, .. } => {} +/// ... +/// _ => {} +/// } +/// ``` +fn diagonal_match(arity: usize) -> Vec<DeconstructedPat<Cx>> { + let struct_ty = Ty::BigStruct { arity, ty: &Ty::Bool }; + let mut patterns = vec![]; + for i in 0..arity { + patterns.push(pat!(struct_ty; Struct { .i: true })); + } + patterns.push(pat!(struct_ty; _)); + patterns +} + +/// Construct a match like: +/// ```ignore(illustrative) +/// match ... { +/// BigStruct { field01: true, .. } => {} +/// BigStruct { field02: true, .. } => {} +/// BigStruct { field03: true, .. } => {} +/// BigStruct { field04: true, .. } => {} +/// ... +/// BigStruct { field01: false, .. } => {} +/// BigStruct { field02: false, .. } => {} +/// BigStruct { field03: false, .. } => {} +/// BigStruct { field04: false, .. } => {} +/// ... +/// _ => {} +/// } +/// ``` +fn diagonal_exponential_match(arity: usize) -> Vec<DeconstructedPat<Cx>> { + let struct_ty = Ty::BigStruct { arity, ty: &Ty::Bool }; + let mut patterns = vec![]; + for i in 0..arity { + patterns.push(pat!(struct_ty; Struct { .i: true })); + } + for i in 0..arity { + patterns.push(pat!(struct_ty; Struct { .i: false })); + } + patterns.push(pat!(struct_ty; _)); + patterns +} + +#[test] +fn test_diagonal_struct_match() { + // These cases are nicely linear: we check `arity` patterns with exactly one `true`, matching + // in 2 branches each, and a final pattern with all `false`, matching only the `_` branch. + assert_complexity(diagonal_match(20), 41); + assert_complexity(diagonal_match(30), 61); + // This case goes exponential. + assert!(check(&diagonal_exponential_match(10), 10000).is_err()); +} + +/// Construct a match like: +/// ```ignore(illustrative) +/// match ... { +/// BigEnum::Variant1(_) => {} +/// BigEnum::Variant2(_) => {} +/// BigEnum::Variant3(_) => {} +/// ... +/// _ => {} +/// } +/// ``` +fn big_enum(arity: usize) -> Vec<DeconstructedPat<Cx>> { + let enum_ty = Ty::BigEnum { arity, ty: &Ty::Bool }; + let mut patterns = vec![]; + for i in 0..arity { + patterns.push(pat!(enum_ty; Variant.i)); + } + patterns.push(pat!(enum_ty; _)); + patterns +} + +#[test] +fn test_big_enum() { + // We try 2 branches per variant. + assert_complexity(big_enum(20), 40); +} diff --git a/compiler/rustc_pattern_analysis/tests/exhaustiveness.rs b/compiler/rustc_pattern_analysis/tests/exhaustiveness.rs new file mode 100644 index 00000000000..4c6c72fa8ec --- /dev/null +++ b/compiler/rustc_pattern_analysis/tests/exhaustiveness.rs @@ -0,0 +1,77 @@ +//! Test exhaustiveness checking. +use common::*; +use rustc_pattern_analysis::{ + pat::{DeconstructedPat, WitnessPat}, + usefulness::PlaceValidity, + MatchArm, +}; + +#[macro_use] +mod common; + +/// Analyze a match made of these patterns. +fn check(patterns: Vec<DeconstructedPat<Cx>>) -> Vec<WitnessPat<Cx>> { + let ty = *patterns[0].ty(); + let arms: Vec<_> = + patterns.iter().map(|pat| MatchArm { pat, has_guard: false, arm_data: () }).collect(); + let report = + compute_match_usefulness(arms.as_slice(), ty, PlaceValidity::ValidOnly, None).unwrap(); + report.non_exhaustiveness_witnesses +} + +#[track_caller] +fn assert_exhaustive(patterns: Vec<DeconstructedPat<Cx>>) { + let witnesses = check(patterns); + if !witnesses.is_empty() { + panic!("non-exaustive match: missing {witnesses:?}"); + } +} + +#[track_caller] +fn assert_non_exhaustive(patterns: Vec<DeconstructedPat<Cx>>) { + let witnesses = check(patterns); + assert!(!witnesses.is_empty()) +} + +#[test] +fn test_int_ranges() { + let ty = Ty::U8; + assert_exhaustive(pats!(ty; + 0..=255, + )); + assert_exhaustive(pats!(ty; + 0.., + )); + assert_non_exhaustive(pats!(ty; + 0..255, + )); + assert_exhaustive(pats!(ty; + 0..255, + 255, + )); + assert_exhaustive(pats!(ty; + ..10, + 10.. + )); +} + +#[test] +fn test_nested() { + let ty = Ty::BigStruct { arity: 2, ty: &Ty::BigEnum { arity: 2, ty: &Ty::Bool } }; + assert_non_exhaustive(pats!(ty; + Struct(Variant.0, _), + )); + assert_exhaustive(pats!(ty; + Struct(Variant.0, _), + Struct(Variant.1, _), + )); + assert_non_exhaustive(pats!(ty; + Struct(Variant.0, _), + Struct(_, Variant.0), + )); + assert_exhaustive(pats!(ty; + Struct(Variant.0, _), + Struct(_, Variant.0), + Struct(Variant.1, Variant.1), + )); +} diff --git a/compiler/rustc_pattern_analysis/tests/intersection.rs b/compiler/rustc_pattern_analysis/tests/intersection.rs new file mode 100644 index 00000000000..4d8a21506d7 --- /dev/null +++ b/compiler/rustc_pattern_analysis/tests/intersection.rs @@ -0,0 +1,69 @@ +//! Test the computation of arm intersections. +use common::*; +use rustc_pattern_analysis::{pat::DeconstructedPat, usefulness::PlaceValidity, MatchArm}; + +#[macro_use] +mod common; + +/// Analyze a match made of these patterns and returns the computed arm intersections. +fn check(patterns: Vec<DeconstructedPat<Cx>>) -> Vec<Vec<usize>> { + let ty = *patterns[0].ty(); + let arms: Vec<_> = + patterns.iter().map(|pat| MatchArm { pat, has_guard: false, arm_data: () }).collect(); + let report = + compute_match_usefulness(arms.as_slice(), ty, PlaceValidity::ValidOnly, None).unwrap(); + report.arm_intersections.into_iter().map(|bitset| bitset.iter().collect()).collect() +} + +#[track_caller] +fn assert_intersects(patterns: Vec<DeconstructedPat<Cx>>, intersects: &[&[usize]]) { + let computed_intersects = check(patterns); + assert_eq!(computed_intersects, intersects); +} + +#[test] +fn test_int_ranges() { + let ty = Ty::U8; + assert_intersects( + pats!(ty; + 0..=100, + 100.., + ), + &[&[], &[0]], + ); + assert_intersects( + pats!(ty; + 0..=101, + 100.., + ), + &[&[], &[0]], + ); + assert_intersects( + pats!(ty; + 0..100, + 100.., + ), + &[&[], &[]], + ); +} + +#[test] +fn test_nested() { + let ty = Ty::Tuple(&[Ty::Bool; 2]); + assert_intersects( + pats!(ty; + (true, true), + (true, _), + (_, true), + ), + &[&[], &[0], &[0, 1]], + ); + // Here we shortcut because `(true, true)` is irrelevant, so we fail to detect the intersection. + assert_intersects( + pats!(ty; + (true, _), + (_, true), + ), + &[&[], &[]], + ); +} diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 9f8cb8fcb41..c73fdd59609 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -67,7 +67,7 @@ impl<'tcx> fmt::Display for LazyDefPathStr<'tcx> { /// First, it doesn't have overridable `fn visit_trait_ref`, so we have to catch trait `DefId`s /// manually. Second, it doesn't visit some type components like signatures of fn types, or traits /// in `impl Trait`, see individual comments in `DefIdVisitorSkeleton::visit_ty`. -trait DefIdVisitor<'tcx> { +pub trait DefIdVisitor<'tcx> { type Result: VisitorResult = (); const SHALLOW: bool = false; const SKIP_ASSOC_TYS: bool = false; @@ -98,7 +98,7 @@ trait DefIdVisitor<'tcx> { } } -struct DefIdVisitorSkeleton<'v, 'tcx, V: ?Sized> { +pub struct DefIdVisitorSkeleton<'v, 'tcx, V: ?Sized> { def_id_visitor: &'v mut V, visited_opaque_tys: FxHashSet<DefId>, dummy: PhantomData<TyCtxt<'tcx>>, @@ -1696,7 +1696,7 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { } } - for id in module.items() { + for id in module.free_items() { if let ItemKind::Impl(i) = tcx.hir().item(id).kind { if let Some(item) = i.of_trait { let trait_ref = tcx.impl_trait_ref(id.owner_id.def_id).unwrap(); diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 6518d9735ae..b24ed573ff9 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -5,8 +5,10 @@ use rustc_middle::bug; use rustc_middle::ty; use rustc_session::lint::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK; use rustc_session::lint::BuiltinLintDiag; +use rustc_session::parse::feature_err; use rustc_span::def_id::LocalDefId; use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext}; +use rustc_span::sym; use rustc_span::symbol::{kw, Ident}; use rustc_span::Span; @@ -598,7 +600,35 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { result } Scope::BuiltinTypes => match this.builtin_types_bindings.get(&ident.name) { - Some(binding) => Ok((*binding, Flags::empty())), + Some(binding) => { + if matches!(ident.name, sym::f16) + && !this.tcx.features().f16 + && !ident.span.allows_unstable(sym::f16) + && finalize.is_some() + { + feature_err( + this.tcx.sess, + sym::f16, + ident.span, + "the type `f16` is unstable", + ) + .emit(); + } + if matches!(ident.name, sym::f128) + && !this.tcx.features().f128 + && !ident.span.allows_unstable(sym::f128) + && finalize.is_some() + { + feature_err( + this.tcx.sess, + sym::f128, + ident.span, + "the type `f128` is unstable", + ) + .emit(); + } + Ok((*binding, Flags::empty())) + } None => Err(Determinacy::Determined), }, }; diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index c9b5c659f0f..b2b339d2521 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -22,11 +22,12 @@ use rustc_errors::{ use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, NonMacroAttrKind, PartialRes, PerNS}; use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE}; -use rustc_hir::{PrimTy, TraitCandidate}; +use rustc_hir::{MissingLifetimeKind, PrimTy, TraitCandidate}; use rustc_middle::middle::resolve_bound_vars::Set1; use rustc_middle::{bug, span_bug}; use rustc_session::config::{CrateType, ResolveDocLinks}; use rustc_session::lint; +use rustc_session::parse::feature_err; use rustc_span::source_map::{respan, Spanned}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{BytePos, Span, SyntaxContext}; @@ -43,9 +44,7 @@ type Res = def::Res<NodeId>; type IdentMap<T> = FxHashMap<Ident, T>; -use diagnostics::{ - ElisionFnParameter, LifetimeElisionCandidate, MissingLifetime, MissingLifetimeKind, -}; +use diagnostics::{ElisionFnParameter, LifetimeElisionCandidate, MissingLifetime}; #[derive(Copy, Clone, Debug)] struct BindingInfo { @@ -1636,22 +1635,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { fn resolve_anonymous_lifetime(&mut self, lifetime: &Lifetime, elided: bool) { debug_assert_eq!(lifetime.ident.name, kw::UnderscoreLifetime); - let missing_lifetime = MissingLifetime { - id: lifetime.id, - span: lifetime.ident.span, - kind: if elided { - MissingLifetimeKind::Ampersand - } else { - MissingLifetimeKind::Underscore - }, - count: 1, - }; + let kind = + if elided { MissingLifetimeKind::Ampersand } else { MissingLifetimeKind::Underscore }; + let missing_lifetime = + MissingLifetime { id: lifetime.id, span: lifetime.ident.span, kind, count: 1 }; let elision_candidate = LifetimeElisionCandidate::Missing(missing_lifetime); for (i, rib) in self.lifetime_ribs.iter().enumerate().rev() { debug!(?rib.kind); match rib.kind { LifetimeRibKind::AnonymousCreateParameter { binder, .. } => { - let res = self.create_fresh_lifetime(lifetime.ident, binder); + let res = self.create_fresh_lifetime(lifetime.ident, binder, kind); self.record_lifetime_res(lifetime.id, res, elision_candidate); return; } @@ -1743,13 +1736,18 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { } #[instrument(level = "debug", skip(self))] - fn create_fresh_lifetime(&mut self, ident: Ident, binder: NodeId) -> LifetimeRes { + fn create_fresh_lifetime( + &mut self, + ident: Ident, + binder: NodeId, + kind: MissingLifetimeKind, + ) -> LifetimeRes { debug_assert_eq!(ident.name, kw::UnderscoreLifetime); debug!(?ident.span); // Leave the responsibility to create the `LocalDefId` to lowering. let param = self.r.next_node_id(); - let res = LifetimeRes::Fresh { param, binder }; + let res = LifetimeRes::Fresh { param, binder, kind }; self.record_lifetime_param(param, res); // Record the created lifetime parameter so lowering can pick it up and add it to HIR. @@ -1843,14 +1841,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { }; let ident = Ident::new(kw::UnderscoreLifetime, elided_lifetime_span); + let kind = if segment.has_generic_args { + MissingLifetimeKind::Comma + } else { + MissingLifetimeKind::Brackets + }; let missing_lifetime = MissingLifetime { id: node_ids.start, span: elided_lifetime_span, - kind: if segment.has_generic_args { - MissingLifetimeKind::Comma - } else { - MissingLifetimeKind::Brackets - }, + kind, count: expected_lifetimes, }; let mut should_lint = true; @@ -1896,7 +1895,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { // Group all suggestions into the first record. let mut candidate = LifetimeElisionCandidate::Missing(missing_lifetime); for id in node_ids { - let res = self.create_fresh_lifetime(ident, binder); + let res = self.create_fresh_lifetime(ident, binder, kind); self.record_lifetime_res( id, res, @@ -4138,6 +4137,25 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { && PrimTy::from_name(path[0].ident.name).is_some() => { let prim = PrimTy::from_name(path[0].ident.name).unwrap(); + let tcx = self.r.tcx(); + + let gate_err_sym_msg = match prim { + PrimTy::Float(FloatTy::F16) if !tcx.features().f16 => { + Some((sym::f16, "the type `f16` is unstable")) + } + PrimTy::Float(FloatTy::F128) if !tcx.features().f128 => { + Some((sym::f128, "the type `f128` is unstable")) + } + _ => None, + }; + + if let Some((sym, msg)) = gate_err_sym_msg { + let span = path[0].ident.span; + if !span.allows_unstable(sym) { + feature_err(tcx.sess, sym, span, msg).emit(); + } + }; + PartialRes::with_unresolved_segments(Res::PrimTy(prim), path.len() - 1) } PathResult::Module(ModuleOrUniformRoot::Module(module)) => { @@ -4645,7 +4663,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { } fn lint_unused_qualifications(&mut self, path: &[Segment], ns: Namespace, finalize: Finalize) { - if path.iter().any(|seg| seg.ident.span.from_expansion()) { + // Don't lint on global paths because the user explicitly wrote out the full path. + if let Some(seg) = path.first() + && seg.ident.name == kw::PathRoot + { + return; + } + + if finalize.path_span.from_expansion() + || path.iter().any(|seg| seg.ident.span.from_expansion()) + { return; } diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 47f8cc56139..bb4294fbcfb 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -24,7 +24,7 @@ use rustc_errors::{ use rustc_hir as hir; use rustc_hir::def::{self, CtorKind, CtorOf, DefKind}; use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; -use rustc_hir::PrimTy; +use rustc_hir::{MissingLifetimeKind, PrimTy}; use rustc_session::lint; use rustc_session::Session; use rustc_span::edit_distance::find_best_match_for_name; @@ -109,18 +109,6 @@ pub(super) struct MissingLifetime { pub count: usize, } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)] -pub(super) enum MissingLifetimeKind { - /// An explicit `'_`. - Underscore, - /// An elided lifetime `&' ty`. - Ampersand, - /// An elided lifetime in brackets with written brackets. - Comma, - /// An elided lifetime with elided brackets. - Brackets, -} - /// Description of the lifetimes appearing in a function parameter. /// This is used to provide a literal explanation to the elision failure. #[derive(Clone, Debug)] @@ -1604,18 +1592,23 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { match (res, source) { ( - Res::Def(DefKind::Macro(MacroKind::Bang), _), + Res::Def(DefKind::Macro(MacroKind::Bang), def_id), PathSource::Expr(Some(Expr { kind: ExprKind::Index(..) | ExprKind::Call(..), .. })) | PathSource::Struct, ) => { + // Don't suggest macro if it's unstable. + let suggestable = def_id.is_local() + || self.r.tcx.lookup_stability(def_id).map_or(true, |s| s.is_stable()); + err.span_label(span, fallback_label.to_string()); // Don't suggest `!` for a macro invocation if there are generic args if path .last() .is_some_and(|segment| !segment.has_generic_args && !segment.has_lifetime_args) + && suggestable { err.span_suggestion_verbose( span.shrink_to_hi(), diff --git a/compiler/rustc_serialize/src/lib.rs b/compiler/rustc_serialize/src/lib.rs index bb822c611a1..b67b7d79d97 100644 --- a/compiler/rustc_serialize/src/lib.rs +++ b/compiler/rustc_serialize/src/lib.rs @@ -8,7 +8,7 @@ #![doc(rust_logo)] #![allow(internal_features)] #![feature(rustdoc_internals)] -#![feature(associated_type_bounds)] +#![cfg_attr(bootstrap, feature(associated_type_bounds))] #![feature(const_option)] #![feature(core_intrinsics)] #![feature(generic_nonzero)] diff --git a/compiler/rustc_session/messages.ftl b/compiler/rustc_session/messages.ftl index 42c681e4961..179fd79bef7 100644 --- a/compiler/rustc_session/messages.ftl +++ b/compiler/rustc_session/messages.ftl @@ -24,6 +24,9 @@ session_feature_diagnostic_for_issue = session_feature_diagnostic_help = add `#![feature({$feature})]` to the crate attributes to enable +session_feature_diagnostic_suggestion = + add `#![feature({$feature})]` to the crate attributes to enable + session_feature_suggest_upgrade_compiler = this compiler was built on {$date}; consider upgrading it if it is out of date diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index b7ee2c98025..a88ae268e27 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -22,7 +22,7 @@ use rustc_span::{FileName, FileNameDisplayPreference, RealFileName, SourceFileHa use rustc_target::abi::Align; use rustc_target::spec::LinkSelfContainedComponents; use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, SplitDebuginfo}; -use rustc_target::spec::{Target, TargetTriple, TargetWarnings, TARGETS}; +use rustc_target::spec::{Target, TargetTriple, TARGETS}; use std::collections::btree_map::{ Iter as BTreeMapIter, Keys as BTreeMapKeysIter, Values as BTreeMapValuesIter, }; @@ -144,18 +144,12 @@ pub enum InstrumentCoverage { } /// Individual flag values controlled by `-Z coverage-options`. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)] pub struct CoverageOptions { /// Add branch coverage instrumentation. pub branch: bool, } -impl Default for CoverageOptions { - fn default() -> Self { - Self { branch: false } - } -} - /// Settings for `-Z instrument-xray` flag. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct InstrumentXRay { @@ -319,7 +313,7 @@ pub struct LocationDetail { } impl LocationDetail { - pub fn all() -> Self { + pub(crate) fn all() -> Self { Self { file: true, line: true, column: true } } } @@ -555,7 +549,7 @@ impl OutputTypes { OutputTypes(BTreeMap::from_iter(entries.iter().map(|&(k, ref v)| (k, v.clone())))) } - pub fn get(&self, key: &OutputType) -> Option<&Option<OutFileName>> { + pub(crate) fn get(&self, key: &OutputType) -> Option<&Option<OutFileName>> { self.0.get(key) } @@ -668,10 +662,6 @@ impl Externs { pub fn iter(&self) -> BTreeMapIter<'_, String, ExternEntry> { self.0.iter() } - - pub fn len(&self) -> usize { - self.0.len() - } } impl ExternEntry { @@ -860,13 +850,13 @@ impl OutFileName { #[derive(Clone, Hash, Debug, HashStable_Generic, Encodable, Decodable)] pub struct OutputFilenames { - pub out_directory: PathBuf, + pub(crate) out_directory: PathBuf, /// Crate name. Never contains '-'. crate_stem: String, /// Typically based on `.rs` input file name. Any '-' is preserved. filestem: String, pub single_output_file: Option<OutFileName>, - pub temps_directory: Option<PathBuf>, + temps_directory: Option<PathBuf>, pub outputs: OutputTypes, } @@ -904,7 +894,7 @@ impl OutputFilenames { /// Gets the output path where a compilation artifact of the given type /// should be placed on disk. - pub fn output_path(&self, flavor: OutputType) -> PathBuf { + fn output_path(&self, flavor: OutputType) -> PathBuf { let extension = flavor.extension(); match flavor { OutputType::Metadata => { @@ -1098,7 +1088,7 @@ impl Options { || self.unstable_opts.query_dep_graph } - pub fn file_path_mapping(&self) -> FilePathMapping { + pub(crate) fn file_path_mapping(&self) -> FilePathMapping { file_path_mapping(self.remap_path_prefix.clone(), &self.unstable_opts) } @@ -1179,14 +1169,14 @@ pub enum Passes { } impl Passes { - pub fn is_empty(&self) -> bool { + fn is_empty(&self) -> bool { match *self { Passes::Some(ref v) => v.is_empty(), Passes::All => false, } } - pub fn extend(&mut self, passes: impl IntoIterator<Item = String>) { + pub(crate) fn extend(&mut self, passes: impl IntoIterator<Item = String>) { match *self { Passes::Some(ref mut v) => v.extend(passes), Passes::All => {} @@ -1212,7 +1202,7 @@ pub struct BranchProtection { pub pac_ret: Option<PacRet>, } -pub const fn default_lib_output() -> CrateType { +pub(crate) const fn default_lib_output() -> CrateType { CrateType::Rlib } @@ -1559,46 +1549,37 @@ pub fn build_configuration(sess: &Session, mut user_cfg: Cfg) -> Cfg { user_cfg } -pub fn build_target_config( - early_dcx: &EarlyDiagCtxt, - opts: &Options, - target_override: Option<Target>, - sysroot: &Path, -) -> Target { - let target_result = target_override.map_or_else( - || Target::search(&opts.target_triple, sysroot), - |t| Ok((t, TargetWarnings::empty())), - ); - let (target, target_warnings) = target_result.unwrap_or_else(|e| { - early_dcx.early_fatal(format!( +pub fn build_target_config(early_dcx: &EarlyDiagCtxt, opts: &Options, sysroot: &Path) -> Target { + match Target::search(&opts.target_triple, sysroot) { + Ok((target, warnings)) => { + for warning in warnings.warning_messages() { + early_dcx.early_warn(warning) + } + if !matches!(target.pointer_width, 16 | 32 | 64) { + early_dcx.early_fatal(format!( + "target specification was invalid: unrecognized target-pointer-width {}", + target.pointer_width + )) + } + target + } + Err(e) => early_dcx.early_fatal(format!( "Error loading target specification: {e}. \ - Run `rustc --print target-list` for a list of built-in targets" - )) - }); - for warning in target_warnings.warning_messages() { - early_dcx.early_warn(warning) - } - - if !matches!(target.pointer_width, 16 | 32 | 64) { - early_dcx.early_fatal(format!( - "target specification was invalid: unrecognized target-pointer-width {}", - target.pointer_width - )) + Run `rustc --print target-list` for a list of built-in targets" + )), } - - target } #[derive(Copy, Clone, PartialEq, Eq, Debug)] -pub enum OptionStability { +enum OptionStability { Stable, Unstable, } pub struct RustcOptGroup { pub apply: Box<dyn Fn(&mut getopts::Options) -> &mut getopts::Options>, - pub name: &'static str, - pub stability: OptionStability, + name: &'static str, + stability: OptionStability, } impl RustcOptGroup { @@ -1634,8 +1615,8 @@ mod opt { use super::RustcOptGroup; - pub type R = RustcOptGroup; - pub type S = &'static str; + type R = RustcOptGroup; + type S = &'static str; fn stable<F>(name: S, f: F) -> R where @@ -1655,32 +1636,34 @@ mod opt { if a.len() > b.len() { a } else { b } } - pub fn opt_s(a: S, b: S, c: S, d: S) -> R { + pub(crate) fn opt_s(a: S, b: S, c: S, d: S) -> R { stable(longer(a, b), move |opts| opts.optopt(a, b, c, d)) } - pub fn multi_s(a: S, b: S, c: S, d: S) -> R { + pub(crate) fn multi_s(a: S, b: S, c: S, d: S) -> R { stable(longer(a, b), move |opts| opts.optmulti(a, b, c, d)) } - pub fn flag_s(a: S, b: S, c: S) -> R { + pub(crate) fn flag_s(a: S, b: S, c: S) -> R { stable(longer(a, b), move |opts| opts.optflag(a, b, c)) } - pub fn flagmulti_s(a: S, b: S, c: S) -> R { + pub(crate) fn flagmulti_s(a: S, b: S, c: S) -> R { stable(longer(a, b), move |opts| opts.optflagmulti(a, b, c)) } - pub fn opt(a: S, b: S, c: S, d: S) -> R { + fn opt(a: S, b: S, c: S, d: S) -> R { unstable(longer(a, b), move |opts| opts.optopt(a, b, c, d)) } - pub fn multi(a: S, b: S, c: S, d: S) -> R { + pub(crate) fn multi(a: S, b: S, c: S, d: S) -> R { unstable(longer(a, b), move |opts| opts.optmulti(a, b, c, d)) } } + static EDITION_STRING: LazyLock<String> = LazyLock::new(|| { format!( "Specify which edition of the compiler to use when compiling code. \ The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE_EDITION}." ) }); + /// Returns the "short" subset of the rustc command line options, /// including metadata for each option, such as whether the option is /// part of the stable long-term interface for rustc. @@ -1870,9 +1853,9 @@ pub fn parse_color(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Col /// Possible json config files pub struct JsonConfig { pub json_rendered: HumanReadableErrorType, - pub json_artifact_notifications: bool, + json_artifact_notifications: bool, pub json_unused_externs: JsonUnusedExterns, - pub json_future_incompat: bool, + json_future_incompat: bool, } /// Report unused externs in event stream @@ -2998,7 +2981,7 @@ pub mod nightly_options { is_nightly_build(matches.opt_str("crate-name").as_deref()) } - pub fn is_nightly_build(krate: Option<&str>) -> bool { + fn is_nightly_build(krate: Option<&str>) -> bool { UnstableFeatures::from_environment(krate).is_nightly_build() } @@ -3205,7 +3188,7 @@ pub(crate) mod dep_tracking { use std::num::NonZero; use std::path::PathBuf; - pub trait DepTrackingHash { + pub(crate) trait DepTrackingHash { fn hash( &self, hasher: &mut DefaultHasher, diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index d523da1ad7e..0a855f87586 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -12,9 +12,9 @@ use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple}; use crate::{config::CrateType, parse::ParseSess}; -pub struct FeatureGateError { - pub span: MultiSpan, - pub explain: DiagMessage, +pub(crate) struct FeatureGateError { + pub(crate) span: MultiSpan, + pub(crate) explain: DiagMessage, } impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for FeatureGateError { @@ -26,22 +26,22 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for FeatureGateError { #[derive(Subdiagnostic)] #[note(session_feature_diagnostic_for_issue)] -pub struct FeatureDiagnosticForIssue { - pub n: NonZero<u32>, +pub(crate) struct FeatureDiagnosticForIssue { + pub(crate) n: NonZero<u32>, } #[derive(Subdiagnostic)] #[note(session_feature_suggest_upgrade_compiler)] -pub struct SuggestUpgradeCompiler { +pub(crate) struct SuggestUpgradeCompiler { date: &'static str, } impl SuggestUpgradeCompiler { - pub fn ui_testing() -> Self { + pub(crate) fn ui_testing() -> Self { Self { date: "YYYY-MM-DD" } } - pub fn new() -> Option<Self> { + pub(crate) fn new() -> Option<Self> { let date = option_env!("CFG_VER_DATE")?; Some(Self { date }) @@ -50,108 +50,120 @@ impl SuggestUpgradeCompiler { #[derive(Subdiagnostic)] #[help(session_feature_diagnostic_help)] -pub struct FeatureDiagnosticHelp { +pub(crate) struct FeatureDiagnosticHelp { + pub(crate) feature: Symbol, +} + +#[derive(Subdiagnostic)] +#[suggestion( + session_feature_diagnostic_suggestion, + applicability = "maybe-incorrect", + code = "#![feature({feature})]\n" +)] +pub struct FeatureDiagnosticSuggestion { pub feature: Symbol, + #[primary_span] + pub span: Span, } #[derive(Subdiagnostic)] #[help(session_cli_feature_diagnostic_help)] -pub struct CliFeatureDiagnosticHelp { - pub feature: Symbol, +pub(crate) struct CliFeatureDiagnosticHelp { + pub(crate) feature: Symbol, } #[derive(Diagnostic)] #[diag(session_not_circumvent_feature)] -pub struct NotCircumventFeature; +pub(crate) struct NotCircumventFeature; #[derive(Diagnostic)] #[diag(session_linker_plugin_lto_windows_not_supported)] -pub struct LinkerPluginToWindowsNotSupported; +pub(crate) struct LinkerPluginToWindowsNotSupported; #[derive(Diagnostic)] #[diag(session_profile_use_file_does_not_exist)] -pub struct ProfileUseFileDoesNotExist<'a> { - pub path: &'a std::path::Path, +pub(crate) struct ProfileUseFileDoesNotExist<'a> { + pub(crate) path: &'a std::path::Path, } #[derive(Diagnostic)] #[diag(session_profile_sample_use_file_does_not_exist)] -pub struct ProfileSampleUseFileDoesNotExist<'a> { - pub path: &'a std::path::Path, +pub(crate) struct ProfileSampleUseFileDoesNotExist<'a> { + pub(crate) path: &'a std::path::Path, } #[derive(Diagnostic)] #[diag(session_target_requires_unwind_tables)] -pub struct TargetRequiresUnwindTables; +pub(crate) struct TargetRequiresUnwindTables; #[derive(Diagnostic)] #[diag(session_instrumentation_not_supported)] -pub struct InstrumentationNotSupported { - pub us: String, +pub(crate) struct InstrumentationNotSupported { + pub(crate) us: String, } #[derive(Diagnostic)] #[diag(session_sanitizer_not_supported)] -pub struct SanitizerNotSupported { - pub us: String, +pub(crate) struct SanitizerNotSupported { + pub(crate) us: String, } #[derive(Diagnostic)] #[diag(session_sanitizers_not_supported)] -pub struct SanitizersNotSupported { - pub us: String, +pub(crate) struct SanitizersNotSupported { + pub(crate) us: String, } #[derive(Diagnostic)] #[diag(session_cannot_mix_and_match_sanitizers)] -pub struct CannotMixAndMatchSanitizers { - pub first: String, - pub second: String, +pub(crate) struct CannotMixAndMatchSanitizers { + pub(crate) first: String, + pub(crate) second: String, } #[derive(Diagnostic)] #[diag(session_cannot_enable_crt_static_linux)] -pub struct CannotEnableCrtStaticLinux; +pub(crate) struct CannotEnableCrtStaticLinux; #[derive(Diagnostic)] #[diag(session_sanitizer_cfi_requires_lto)] -pub struct SanitizerCfiRequiresLto; +pub(crate) struct SanitizerCfiRequiresLto; #[derive(Diagnostic)] #[diag(session_sanitizer_cfi_requires_single_codegen_unit)] -pub struct SanitizerCfiRequiresSingleCodegenUnit; +pub(crate) struct SanitizerCfiRequiresSingleCodegenUnit; #[derive(Diagnostic)] #[diag(session_sanitizer_cfi_canonical_jump_tables_requires_cfi)] -pub struct SanitizerCfiCanonicalJumpTablesRequiresCfi; +pub(crate) struct SanitizerCfiCanonicalJumpTablesRequiresCfi; #[derive(Diagnostic)] #[diag(session_sanitizer_cfi_generalize_pointers_requires_cfi)] -pub struct SanitizerCfiGeneralizePointersRequiresCfi; +pub(crate) struct SanitizerCfiGeneralizePointersRequiresCfi; #[derive(Diagnostic)] #[diag(session_sanitizer_cfi_normalize_integers_requires_cfi)] -pub struct SanitizerCfiNormalizeIntegersRequiresCfi; +pub(crate) struct SanitizerCfiNormalizeIntegersRequiresCfi; #[derive(Diagnostic)] #[diag(session_split_lto_unit_requires_lto)] -pub struct SplitLtoUnitRequiresLto; +pub(crate) struct SplitLtoUnitRequiresLto; #[derive(Diagnostic)] #[diag(session_unstable_virtual_function_elimination)] -pub struct UnstableVirtualFunctionElimination; +pub(crate) struct UnstableVirtualFunctionElimination; #[derive(Diagnostic)] #[diag(session_unsupported_dwarf_version)] -pub struct UnsupportedDwarfVersion { - pub dwarf_version: u32, +pub(crate) struct UnsupportedDwarfVersion { + pub(crate) dwarf_version: u32, } #[derive(Diagnostic)] #[diag(session_target_stack_protector_not_supported)] -pub struct StackProtectorNotSupportedForTarget<'a> { - pub stack_protector: StackProtector, - pub target_triple: &'a TargetTriple, +pub(crate) struct StackProtectorNotSupportedForTarget<'a> { + pub(crate) stack_protector: StackProtector, + pub(crate) target_triple: &'a TargetTriple, } #[derive(Diagnostic)] @@ -160,58 +172,58 @@ pub(crate) struct BranchProtectionRequiresAArch64; #[derive(Diagnostic)] #[diag(session_split_debuginfo_unstable_platform)] -pub struct SplitDebugInfoUnstablePlatform { - pub debuginfo: SplitDebuginfo, +pub(crate) struct SplitDebugInfoUnstablePlatform { + pub(crate) debuginfo: SplitDebuginfo, } #[derive(Diagnostic)] #[diag(session_file_is_not_writeable)] -pub struct FileIsNotWriteable<'a> { - pub file: &'a std::path::Path, +pub(crate) struct FileIsNotWriteable<'a> { + pub(crate) file: &'a std::path::Path, } #[derive(Diagnostic)] #[diag(session_file_write_fail)] pub(crate) struct FileWriteFail<'a> { - pub path: &'a std::path::Path, - pub err: String, + pub(crate) path: &'a std::path::Path, + pub(crate) err: String, } #[derive(Diagnostic)] #[diag(session_crate_name_does_not_match)] -pub struct CrateNameDoesNotMatch { +pub(crate) struct CrateNameDoesNotMatch { #[primary_span] - pub span: Span, - pub s: Symbol, - pub name: Symbol, + pub(crate) span: Span, + pub(crate) s: Symbol, + pub(crate) name: Symbol, } #[derive(Diagnostic)] #[diag(session_crate_name_invalid)] -pub struct CrateNameInvalid<'a> { - pub s: &'a str, +pub(crate) struct CrateNameInvalid<'a> { + pub(crate) s: &'a str, } #[derive(Diagnostic)] #[diag(session_crate_name_empty)] -pub struct CrateNameEmpty { +pub(crate) struct CrateNameEmpty { #[primary_span] - pub span: Option<Span>, + pub(crate) span: Option<Span>, } #[derive(Diagnostic)] #[diag(session_invalid_character_in_create_name)] -pub struct InvalidCharacterInCrateName { +pub(crate) struct InvalidCharacterInCrateName { #[primary_span] - pub span: Option<Span>, - pub character: char, - pub crate_name: Symbol, + pub(crate) span: Option<Span>, + pub(crate) character: char, + pub(crate) crate_name: Symbol, #[subdiagnostic] - pub crate_name_help: Option<InvalidCrateNameHelp>, + pub(crate) crate_name_help: Option<InvalidCrateNameHelp>, } #[derive(Subdiagnostic)] -pub enum InvalidCrateNameHelp { +pub(crate) enum InvalidCrateNameHelp { #[help(session_invalid_character_in_create_name_help)] AddCrateName, } @@ -220,9 +232,9 @@ pub enum InvalidCrateNameHelp { #[multipart_suggestion(session_expr_parentheses_needed, applicability = "machine-applicable")] pub struct ExprParenthesesNeeded { #[suggestion_part(code = "(")] - pub left: Span, + left: Span, #[suggestion_part(code = ")")] - pub right: Span, + right: Span, } impl ExprParenthesesNeeded { @@ -233,13 +245,13 @@ impl ExprParenthesesNeeded { #[derive(Diagnostic)] #[diag(session_skipping_const_checks)] -pub struct SkippingConstChecks { +pub(crate) struct SkippingConstChecks { #[subdiagnostic] - pub unleashed_features: Vec<UnleashedFeatureHelp>, + pub(crate) unleashed_features: Vec<UnleashedFeatureHelp>, } #[derive(Subdiagnostic)] -pub enum UnleashedFeatureHelp { +pub(crate) enum UnleashedFeatureHelp { #[help(session_unleashed_feature_help_named)] Named { #[primary_span] @@ -255,101 +267,101 @@ pub enum UnleashedFeatureHelp { #[derive(Diagnostic)] #[diag(session_invalid_literal_suffix)] -pub(crate) struct InvalidLiteralSuffix<'a> { +struct InvalidLiteralSuffix<'a> { #[primary_span] #[label] - pub span: Span, + span: Span, // FIXME(#100717) - pub kind: &'a str, - pub suffix: Symbol, + kind: &'a str, + suffix: Symbol, } #[derive(Diagnostic)] #[diag(session_invalid_int_literal_width)] #[help] -pub(crate) struct InvalidIntLiteralWidth { +struct InvalidIntLiteralWidth { #[primary_span] - pub span: Span, - pub width: String, + span: Span, + width: String, } #[derive(Diagnostic)] #[diag(session_invalid_num_literal_base_prefix)] #[note] -pub(crate) struct InvalidNumLiteralBasePrefix { +struct InvalidNumLiteralBasePrefix { #[primary_span] #[suggestion(applicability = "maybe-incorrect", code = "{fixed}")] - pub span: Span, - pub fixed: String, + span: Span, + fixed: String, } #[derive(Diagnostic)] #[diag(session_invalid_num_literal_suffix)] #[help] -pub(crate) struct InvalidNumLiteralSuffix { +struct InvalidNumLiteralSuffix { #[primary_span] #[label] - pub span: Span, - pub suffix: String, + span: Span, + suffix: String, } #[derive(Diagnostic)] #[diag(session_invalid_float_literal_width)] #[help] -pub(crate) struct InvalidFloatLiteralWidth { +struct InvalidFloatLiteralWidth { #[primary_span] - pub span: Span, - pub width: String, + span: Span, + width: String, } #[derive(Diagnostic)] #[diag(session_invalid_float_literal_suffix)] #[help] -pub(crate) struct InvalidFloatLiteralSuffix { +struct InvalidFloatLiteralSuffix { #[primary_span] #[label] - pub span: Span, - pub suffix: String, + span: Span, + suffix: String, } #[derive(Diagnostic)] #[diag(session_int_literal_too_large)] #[note] -pub(crate) struct IntLiteralTooLarge { +struct IntLiteralTooLarge { #[primary_span] - pub span: Span, - pub limit: String, + span: Span, + limit: String, } #[derive(Diagnostic)] #[diag(session_hexadecimal_float_literal_not_supported)] -pub(crate) struct HexadecimalFloatLiteralNotSupported { +struct HexadecimalFloatLiteralNotSupported { #[primary_span] #[label(session_not_supported)] - pub span: Span, + span: Span, } #[derive(Diagnostic)] #[diag(session_octal_float_literal_not_supported)] -pub(crate) struct OctalFloatLiteralNotSupported { +struct OctalFloatLiteralNotSupported { #[primary_span] #[label(session_not_supported)] - pub span: Span, + span: Span, } #[derive(Diagnostic)] #[diag(session_binary_float_literal_not_supported)] -pub(crate) struct BinaryFloatLiteralNotSupported { +struct BinaryFloatLiteralNotSupported { #[primary_span] #[label(session_not_supported)] - pub span: Span, + span: Span, } #[derive(Diagnostic)] #[diag(session_unsupported_crate_type_for_target)] -pub struct UnsupportedCrateTypeForTarget<'a> { - pub crate_type: CrateType, - pub target_triple: &'a TargetTriple, +pub(crate) struct UnsupportedCrateTypeForTarget<'a> { + pub(crate) crate_type: CrateType, + pub(crate) target_triple: &'a TargetTriple, } pub fn report_lit_error( @@ -431,16 +443,16 @@ pub fn report_lit_error( #[derive(Diagnostic)] #[diag(session_optimization_fuel_exhausted)] -pub struct OptimisationFuelExhausted { - pub msg: String, +pub(crate) struct OptimisationFuelExhausted { + pub(crate) msg: String, } #[derive(Diagnostic)] #[diag(session_incompatible_linker_flavor)] #[note] -pub struct IncompatibleLinkerFlavor { - pub flavor: &'static str, - pub compatible_list: String, +pub(crate) struct IncompatibleLinkerFlavor { + pub(crate) flavor: &'static str, + pub(crate) compatible_list: String, } #[derive(Diagnostic)] @@ -453,6 +465,6 @@ pub(crate) struct FunctionReturnThunkExternRequiresNonLargeCodeModel; #[derive(Diagnostic)] #[diag(session_failed_to_create_profiler)] -pub struct FailedToCreateProfiler { - pub err: String, +pub(crate) struct FailedToCreateProfiler { + pub(crate) err: String, } diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 398138d7e1f..5434bbe0b98 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -3,8 +3,8 @@ use crate::config::{Cfg, CheckCfg}; use crate::errors::{ - CliFeatureDiagnosticHelp, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError, - SuggestUpgradeCompiler, + CliFeatureDiagnosticHelp, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, + FeatureDiagnosticSuggestion, FeatureGateError, SuggestUpgradeCompiler, }; use crate::lint::{ builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiag, Lint, LintId, @@ -112,7 +112,7 @@ pub fn feature_err_issue( } let mut err = sess.psess.dcx.create_err(FeatureGateError { span, explain: explain.into() }); - add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false); + add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false, None); err } @@ -141,7 +141,7 @@ pub fn feature_warn_issue( explain: &'static str, ) { let mut err = sess.psess.dcx.struct_span_warn(span, explain); - add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false); + add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false, None); // Decorate this as a future-incompatibility lint as in rustc_middle::lint::lint_level let lint = UNSTABLE_SYNTAX_PRE_EXPANSION; @@ -160,7 +160,7 @@ pub fn add_feature_diagnostics<G: EmissionGuarantee>( sess: &Session, feature: Symbol, ) { - add_feature_diagnostics_for_issue(err, sess, feature, GateIssue::Language, false); + add_feature_diagnostics_for_issue(err, sess, feature, GateIssue::Language, false, None); } /// Adds the diagnostics for a feature to an existing error. @@ -175,6 +175,7 @@ pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>( feature: Symbol, issue: GateIssue, feature_from_cli: bool, + inject_span: Option<Span>, ) { if let Some(n) = find_feature_issue(feature, issue) { err.subdiagnostic(sess.dcx(), FeatureDiagnosticForIssue { n }); @@ -184,6 +185,8 @@ pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>( if sess.psess.unstable_features.is_nightly_build() { if feature_from_cli { err.subdiagnostic(sess.dcx(), CliFeatureDiagnosticHelp { feature }); + } else if let Some(span) = inject_span { + err.subdiagnostic(sess.dcx(), FeatureDiagnosticSuggestion { feature, span }); } else { err.subdiagnostic(sess.dcx(), FeatureDiagnosticHelp { feature }); } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 9c94fd7027f..e6d82d6fab3 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1008,7 +1008,7 @@ pub fn build_session( fluent_resources: Vec<&'static str>, driver_lint_caps: FxHashMap<lint::LintId, lint::Level>, file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>, - target_cfg: Target, + target: Target, sysroot: PathBuf, cfg_version: &'static str, ice_file: Option<PathBuf>, @@ -1036,7 +1036,7 @@ pub fn build_session( let loader = file_loader.unwrap_or_else(|| Box::new(RealFileLoader)); let hash_kind = sopts.unstable_opts.src_hash_algorithm.unwrap_or_else(|| { - if target_cfg.is_like_msvc { + if target.is_like_msvc { SourceFileHashAlgorithm::Sha256 } else { SourceFileHashAlgorithm::Md5 @@ -1117,11 +1117,10 @@ pub fn build_session( _ => CtfeBacktrace::Disabled, }); - let asm_arch = - if target_cfg.allow_asm { InlineAsmArch::from_str(&target_cfg.arch).ok() } else { None }; + let asm_arch = if target.allow_asm { InlineAsmArch::from_str(&target.arch).ok() } else { None }; let sess = Session { - target: target_cfg, + target, host, opts: sopts, host_tlib_path, diff --git a/compiler/rustc_smir/src/rustc_internal/internal.rs b/compiler/rustc_smir/src/rustc_internal/internal.rs index 2cc9bc31873..bf7346be31f 100644 --- a/compiler/rustc_smir/src/rustc_internal/internal.rs +++ b/compiler/rustc_smir/src/rustc_internal/internal.rs @@ -10,7 +10,7 @@ use rustc_span::Symbol; use stable_mir::abi::Layout; use stable_mir::mir::alloc::AllocId; use stable_mir::mir::mono::{Instance, MonoItem, StaticDef}; -use stable_mir::mir::{Mutability, Safety}; +use stable_mir::mir::{Mutability, Place, ProjectionElem, Safety}; use stable_mir::ty::{ Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, Const, DynKind, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FloatTy, FnSig, @@ -492,6 +492,50 @@ impl RustcInternal for Layout { } } +impl RustcInternal for Place { + type T<'tcx> = rustc_middle::mir::Place<'tcx>; + + fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> { + rustc_middle::mir::Place { + local: rustc_middle::mir::Local::from_usize(self.local), + projection: tcx.mk_place_elems(&self.projection.internal(tables, tcx)), + } + } +} + +impl RustcInternal for ProjectionElem { + type T<'tcx> = rustc_middle::mir::PlaceElem<'tcx>; + + fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> { + match self { + ProjectionElem::Deref => rustc_middle::mir::PlaceElem::Deref, + ProjectionElem::Field(idx, ty) => { + rustc_middle::mir::PlaceElem::Field((*idx).into(), ty.internal(tables, tcx)) + } + ProjectionElem::Index(idx) => rustc_middle::mir::PlaceElem::Index((*idx).into()), + ProjectionElem::ConstantIndex { offset, min_length, from_end } => { + rustc_middle::mir::PlaceElem::ConstantIndex { + offset: *offset, + min_length: *min_length, + from_end: *from_end, + } + } + ProjectionElem::Subslice { from, to, from_end } => { + rustc_middle::mir::PlaceElem::Subslice { from: *from, to: *to, from_end: *from_end } + } + ProjectionElem::Downcast(idx) => { + rustc_middle::mir::PlaceElem::Downcast(None, idx.internal(tables, tcx)) + } + ProjectionElem::OpaqueCast(ty) => { + rustc_middle::mir::PlaceElem::OpaqueCast(ty.internal(tables, tcx)) + } + ProjectionElem::Subtype(ty) => { + rustc_middle::mir::PlaceElem::Subtype(ty.internal(tables, tcx)) + } + } + } +} + impl<T> RustcInternal for &T where T: RustcInternal, diff --git a/compiler/rustc_smir/src/rustc_internal/pretty.rs b/compiler/rustc_smir/src/rustc_internal/pretty.rs index 3ef2d28ea47..c0dce08b0d3 100644 --- a/compiler/rustc_smir/src/rustc_internal/pretty.rs +++ b/compiler/rustc_smir/src/rustc_internal/pretty.rs @@ -14,7 +14,7 @@ pub fn write_smir_pretty<'tcx, W: io::Write>(tcx: TyCtxt<'tcx>, w: &mut W) -> io )?; let _ = run(tcx, || { let items = stable_mir::all_local_items(); - let _ = items.iter().map(|item| -> io::Result<()> { item.dump(w) }).collect::<Vec<_>>(); + let _ = items.iter().map(|item| -> io::Result<()> { item.emit_mir(w) }).collect::<Vec<_>>(); }); Ok(()) } diff --git a/compiler/rustc_smir/src/rustc_smir/builder.rs b/compiler/rustc_smir/src/rustc_smir/builder.rs index a13262cdcc4..0762016ef75 100644 --- a/compiler/rustc_smir/src/rustc_smir/builder.rs +++ b/compiler/rustc_smir/src/rustc_smir/builder.rs @@ -56,7 +56,7 @@ impl<'tcx> MutVisitor<'tcx> for BodyBuilder<'tcx> { fn visit_constant(&mut self, constant: &mut mir::ConstOperand<'tcx>, location: mir::Location) { let const_ = self.monomorphize(constant.const_); - let val = match const_.eval(self.tcx, ty::ParamEnv::reveal_all(), Some(constant.span)) { + let val = match const_.eval(self.tcx, ty::ParamEnv::reveal_all(), constant.span) { Ok(v) => v, Err(mir::interpret::ErrorHandled::Reported(..)) => return, Err(mir::interpret::ErrorHandled::TooGeneric(..)) => { diff --git a/compiler/rustc_smir/src/rustc_smir/context.rs b/compiler/rustc_smir/src/rustc_smir/context.rs index 509f0def256..d39a3788d4c 100644 --- a/compiler/rustc_smir/src/rustc_smir/context.rs +++ b/compiler/rustc_smir/src/rustc_smir/context.rs @@ -19,7 +19,7 @@ use stable_mir::abi::{FnAbi, Layout, LayoutShape}; use stable_mir::compiler_interface::Context; use stable_mir::mir::alloc::GlobalAlloc; use stable_mir::mir::mono::{InstanceDef, StaticDef}; -use stable_mir::mir::Body; +use stable_mir::mir::{Body, Place}; use stable_mir::target::{MachineInfo, MachineSize}; use stable_mir::ty::{ AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, ForeignDef, @@ -423,7 +423,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> { def_ty.instantiate(tables.tcx, args).stable(&mut *tables) } - fn const_literal(&self, cnst: &stable_mir::ty::Const) -> String { + fn const_pretty(&self, cnst: &stable_mir::ty::Const) -> String { let mut tables = self.0.borrow_mut(); let tcx = tables.tcx; cnst.internal(&mut *tables, tcx).to_string() @@ -434,6 +434,11 @@ impl<'tcx> Context for TablesWrapper<'tcx> { tables.tcx.def_span(tables[def_id]).stable(&mut *tables) } + fn ty_pretty(&self, ty: stable_mir::ty::Ty) -> String { + let tables = self.0.borrow_mut(); + tables.types[ty].to_string() + } + fn ty_kind(&self, ty: stable_mir::ty::Ty) -> TyKind { let mut tables = self.0.borrow_mut(); tables.types[ty].kind().stable(&mut *tables) @@ -566,7 +571,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> { let result = tcx.const_eval_instance( ParamEnv::reveal_all(), instance, - Some(tcx.def_span(instance.def_id())), + tcx.def_span(instance.def_id()), ); result .map(|const_val| { @@ -654,6 +659,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> { let tcx = tables.tcx; id.internal(&mut *tables, tcx).0.stable(&mut *tables) } + + fn place_pretty(&self, place: &Place) -> String { + let mut tables = self.0.borrow_mut(); + let tcx = tables.tcx; + format!("{:?}", place.internal(&mut *tables, tcx)) + } } pub struct TablesWrapper<'tcx>(pub RefCell<Tables<'tcx>>); diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index 527938daae4..37fea6c122c 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -1062,7 +1062,7 @@ pub enum ExpnKind { Macro(MacroKind, Symbol), /// Transform done by the compiler on the AST. AstPass(AstPass), - /// Desugaring done by the compiler during HIR lowering. + /// Desugaring done by the compiler during AST lowering. Desugaring(DesugaringKind), } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 7de0555bb22..b6c07e8737f 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -166,9 +166,8 @@ symbols! { Break, C, CStr, - CallFuture, - CallMutFuture, CallOnceFuture, + CallRefFuture, Capture, Center, Cleanup, @@ -208,6 +207,7 @@ symbols! { FromResidual, FsOpenOptions, FsPermissions, + FusedIterator, Future, FutureOutput, GlobalAlloc, @@ -675,6 +675,7 @@ symbols! { deref_method, deref_mut, deref_mut_method, + deref_patterns, deref_target, derive, derive_const, @@ -690,6 +691,7 @@ symbols! { dispatch_from_dyn, div, div_assign, + diverging_block_default, do_not_recommend, doc, doc_alias, @@ -815,6 +817,7 @@ symbols! { fadd_algebraic, fadd_fast, fake_variadic, + fallback, fdiv_algebraic, fdiv_fast, feature, @@ -883,6 +886,7 @@ symbols! { fsub_algebraic, fsub_fast, fundamental, + fused_iterator, future, future_trait, gdb_script_file, @@ -1225,6 +1229,7 @@ symbols! { new_v1, new_v1_formatted, next, + niko, nll, no, no_builtins, @@ -1330,6 +1335,7 @@ symbols! { poll, poll_next, post_dash_lto: "post-lto", + postfix_match, powerpc_target_feature, powf128, powf16, @@ -1459,7 +1465,6 @@ symbols! { residual, result, resume, - retag_box_to_raw, return_position_impl_trait_in_trait, return_type_notation, rhs, @@ -1551,6 +1556,7 @@ symbols! { rustc_mir, rustc_must_implement_one_of, rustc_never_returns_null_ptr, + rustc_never_type_options, rustc_no_mir_inline, rustc_nonnull_optimization_guaranteed, rustc_nounwind, diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index 83e920e2f8e..1c62ce2d214 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -76,16 +76,10 @@ pub(super) fn mangle<'tcx>( } // FIXME(async_closures): This shouldn't be needed when we fix // `Instance::ty`/`Instance::def_id`. - ty::InstanceDef::ConstructCoroutineInClosureShim { target_kind, .. } - | ty::InstanceDef::CoroutineKindShim { target_kind, .. } => match target_kind { - ty::ClosureKind::Fn => unreachable!(), - ty::ClosureKind::FnMut => { - printer.write_str("{{fn-mut-shim}}").unwrap(); - } - ty::ClosureKind::FnOnce => { - printer.write_str("{{fn-once-shim}}").unwrap(); - } - }, + ty::InstanceDef::ConstructCoroutineInClosureShim { .. } + | ty::InstanceDef::CoroutineKindShim { .. } => { + printer.write_str("{{fn-once-shim}}").unwrap(); + } _ => {} } diff --git a/compiler/rustc_symbol_mangling/src/test.rs b/compiler/rustc_symbol_mangling/src/test.rs index 6766080a54f..f0fb87fe83c 100644 --- a/compiler/rustc_symbol_mangling/src/test.rs +++ b/compiler/rustc_symbol_mangling/src/test.rs @@ -25,7 +25,7 @@ pub fn report_symbol_names(tcx: TyCtxt<'_>) { let mut symbol_names = SymbolNamesTest { tcx }; let crate_items = tcx.hir_crate_items(()); - for id in crate_items.items() { + for id in crate_items.free_items() { symbol_names.process_attrs(id.owner_id.def_id); } diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index 51e2c96120c..69b9fc33166 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -18,7 +18,7 @@ use rustc_middle::ty::{ use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgsRef}; use rustc_span::def_id::DefId; use rustc_span::sym; -use rustc_target::abi::call::{Conv, FnAbi}; +use rustc_target::abi::call::{Conv, FnAbi, PassMode}; use rustc_target::abi::Integer; use rustc_target::spec::abi::Abi; use std::fmt::Write as _; @@ -525,8 +525,8 @@ fn encode_ty<'tcx>( "{}", &len.try_to_scalar() .unwrap() - .to_u64() - .unwrap_or_else(|_| panic!("failed to convert length to u64")) + .to_target_usize(&tcx.data_layout) + .expect("Array lens are defined in usize") ); s.push_str(&encode_ty(tcx, *ty0, dict, options)); compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); @@ -1040,19 +1040,27 @@ pub fn typeid_for_fnabi<'tcx>( typeid.push_str(&encode_ty(tcx, ty, &mut dict, encode_ty_options)); // Encode the parameter types + + // We erase ZSTs as we go if the argument is skipped. This is an implementation detail of how + // MIR is currently treated by rustc, and subject to change in the future. Specifically, MIR + // interpretation today will allow skipped arguments to simply not be passed at a call-site. if !fn_abi.c_variadic { - if !fn_abi.args.is_empty() { - for arg in fn_abi.args.iter() { - let ty = transform_ty(tcx, arg.layout.ty, transform_ty_options); - typeid.push_str(&encode_ty(tcx, ty, &mut dict, encode_ty_options)); - } - } else { + let mut pushed_arg = false; + for arg in fn_abi.args.iter().filter(|arg| arg.mode != PassMode::Ignore) { + pushed_arg = true; + let ty = transform_ty(tcx, arg.layout.ty, transform_ty_options); + typeid.push_str(&encode_ty(tcx, ty, &mut dict, encode_ty_options)); + } + if !pushed_arg { // Empty parameter lists, whether declared as () or conventionally as (void), are // encoded with a void parameter specifier "v". typeid.push('v'); } } else { for n in 0..fn_abi.fixed_count as usize { + if fn_abi.args[n].mode == PassMode::Ignore { + continue; + } let ty = transform_ty(tcx, fn_abi.args[n].layout.ty, transform_ty_options); typeid.push_str(&encode_ty(tcx, ty, &mut dict, encode_ty_options)); } diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index f1b1b4ed2bb..6bc375512ac 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -46,12 +46,8 @@ pub(super) fn mangle<'tcx>( ty::InstanceDef::VTableShim(_) => Some("vtable"), ty::InstanceDef::ReifyShim(_) => Some("reify"), - ty::InstanceDef::ConstructCoroutineInClosureShim { target_kind, .. } - | ty::InstanceDef::CoroutineKindShim { target_kind, .. } => match target_kind { - ty::ClosureKind::Fn => unreachable!(), - ty::ClosureKind::FnMut => Some("fn_mut"), - ty::ClosureKind::FnOnce => Some("fn_once"), - }, + ty::InstanceDef::ConstructCoroutineInClosureShim { .. } + | ty::InstanceDef::CoroutineKindShim { .. } => Some("fn_once"), _ => None, }; diff --git a/compiler/rustc_target/src/lib.rs b/compiler/rustc_target/src/lib.rs index 8019d2b80cd..ba359ac6de1 100644 --- a/compiler/rustc_target/src/lib.rs +++ b/compiler/rustc_target/src/lib.rs @@ -9,13 +9,11 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(rust_logo)] -#![cfg_attr(bootstrap, feature(exhaustive_patterns))] -#![cfg_attr(not(bootstrap), feature(min_exhaustive_patterns))] +#![feature(min_exhaustive_patterns)] #![feature(rustdoc_internals)] #![feature(assert_matches)] #![feature(iter_intersperse)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(min_specialization))] #![feature(rustc_attrs)] #![feature(step_trait)] #![allow(internal_features)] diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 941d767b850..966da2c5eda 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1621,6 +1621,7 @@ supported_targets! { ("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf), ("riscv32im-risc0-zkvm-elf", riscv32im_risc0_zkvm_elf), ("riscv32im-unknown-none-elf", riscv32im_unknown_none_elf), + ("riscv32ima-unknown-none-elf", riscv32ima_unknown_none_elf), ("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf), ("riscv32imc-esp-espidf", riscv32imc_esp_espidf), ("riscv32imac-esp-espidf", riscv32imac_esp_espidf), @@ -2091,6 +2092,9 @@ pub struct TargetOptions { /// compiling `rustc` will be used instead (or llvm if it is not set). /// /// N.B. when *using* the compiler, backend can always be overridden with `-Zcodegen-backend`. + /// + /// This was added by WaffleLapkin in #116793. The motivation is a rustc fork that requires a + /// custom codegen backend for a particular target. pub default_codegen_backend: Option<StaticCow<str>>, /// Whether to generate trap instructions in places where optimization would diff --git a/compiler/rustc_target/src/spec/targets/riscv32ima_unknown_none_elf.rs b/compiler/rustc_target/src/spec/targets/riscv32ima_unknown_none_elf.rs new file mode 100644 index 00000000000..9acf6a3b5a0 --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/riscv32ima_unknown_none_elf.rs @@ -0,0 +1,29 @@ +use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions}; + +pub fn target() -> Target { + Target { + data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(), + llvm_target: "riscv32".into(), + metadata: crate::spec::TargetMetadata { + description: None, + tier: None, + host_tools: None, + std: None, + }, + pointer_width: 32, + arch: "riscv32".into(), + + options: TargetOptions { + linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), + linker: Some("rust-lld".into()), + cpu: "generic-rv32".into(), + max_atomic_width: Some(32), + features: "+m,+a".into(), + panic_strategy: PanicStrategy::Abort, + relocation_model: RelocModel::Static, + emit_debug_gdb_scripts: false, + eh_frame_header: false, + ..Default::default() + }, + } +} diff --git a/compiler/rustc_trait_selection/messages.ftl b/compiler/rustc_trait_selection/messages.ftl index 0dcba0e05f7..f96bd985237 100644 --- a/compiler/rustc_trait_selection/messages.ftl +++ b/compiler/rustc_trait_selection/messages.ftl @@ -19,6 +19,9 @@ trait_selection_closure_kind_mismatch = expected a closure that implements the ` trait_selection_closure_kind_requirement = the requirement to implement `{$trait_prefix}{$expected}` derives from here +trait_selection_disallowed_positional_argument = positional format arguments are not allowed here + .help = only named format arguments with the name of one of the generic types are allowed in this context + trait_selection_dump_vtable_entries = vtable entries for `{$trait_ref}`: {$entries} trait_selection_empty_on_clause_in_rustc_on_unimplemented = empty `on`-clause in `#[rustc_on_unimplemented]` @@ -30,6 +33,9 @@ trait_selection_ignored_diagnostic_option = `{$option_name}` is ignored due to p trait_selection_inherent_projection_normalization_overflow = overflow evaluating associated type `{$ty}` +trait_selection_invalid_format_specifier = invalid format specifier + .help = no format specifier are supported in this position + trait_selection_invalid_on_clause_in_rustc_on_unimplemented = invalid `on`-clause in `#[rustc_on_unimplemented]` .label = invalid on-clause here @@ -60,3 +66,6 @@ trait_selection_unable_to_construct_constant_value = unable to construct a const trait_selection_unknown_format_parameter_for_on_unimplemented_attr = there is no parameter `{$argument_name}` on trait `{$trait_name}` .help = expect either a generic argument name or {"`{Self}`"} as format argument + +trait_selection_wrapped_parser_error = {$description} + .label = {$label} diff --git a/compiler/rustc_trait_selection/src/lib.rs b/compiler/rustc_trait_selection/src/lib.rs index fd3d62d1321..e14fc62cd6f 100644 --- a/compiler/rustc_trait_selection/src/lib.rs +++ b/compiler/rustc_trait_selection/src/lib.rs @@ -17,7 +17,7 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] #![feature(assert_matches)] -#![feature(associated_type_bounds)] +#![cfg_attr(bootstrap, feature(associated_type_bounds))] #![feature(associated_type_defaults)] #![feature(box_patterns)] #![feature(control_flow_enum)] @@ -26,7 +26,6 @@ #![feature(option_take_if)] #![feature(never_type)] #![feature(type_alias_impl_trait)] -#![cfg_attr(bootstrap, feature(min_specialization))] #![recursion_limit = "512"] // For rustdoc #[macro_use] diff --git a/compiler/rustc_trait_selection/src/solve/alias_relate.rs b/compiler/rustc_trait_selection/src/solve/alias_relate.rs index 67657c81cf6..e081a9100e2 100644 --- a/compiler/rustc_trait_selection/src/solve/alias_relate.rs +++ b/compiler/rustc_trait_selection/src/solve/alias_relate.rs @@ -21,8 +21,9 @@ //! However, if `?fresh_var` ends up geteting equated to another type, we retry the //! `NormalizesTo` goal, at which point the opaque is actually defined. -use super::{EvalCtxt, GoalSource}; +use super::EvalCtxt; use rustc_infer::traits::query::NoSolution; +use rustc_infer::traits::solve::GoalSource; use rustc_middle::traits::solve::{Certainty, Goal, QueryResult}; use rustc_middle::ty::{self, Ty}; @@ -121,10 +122,11 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { ty::TermKind::Const(_) => { if let Some(alias) = term.to_alias_ty(self.tcx()) { let term = self.next_term_infer_of_kind(term); - self.add_goal( - GoalSource::Misc, - Goal::new(self.tcx(), param_env, ty::NormalizesTo { alias, term }), - ); + self.add_normalizes_to_goal(Goal::new( + self.tcx(), + param_env, + ty::NormalizesTo { alias, term }, + )); self.try_evaluate_added_goals()?; Ok(Some(self.resolve_vars_if_possible(term))) } else { @@ -145,18 +147,25 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { return None; } - let ty::Alias(_, alias) = *ty.kind() else { + let ty::Alias(kind, alias) = *ty.kind() else { return Some(ty); }; match self.commit_if_ok(|this| { + let tcx = this.tcx(); let normalized_ty = this.next_ty_infer(); - let normalizes_to_goal = Goal::new( - this.tcx(), - param_env, - ty::NormalizesTo { alias, term: normalized_ty.into() }, - ); - this.add_goal(GoalSource::Misc, normalizes_to_goal); + let normalizes_to = ty::NormalizesTo { alias, term: normalized_ty.into() }; + match kind { + ty::AliasKind::Opaque => { + // HACK: Unlike for associated types, `normalizes-to` for opaques + // is currently not treated as a function. We do not erase the + // expected term. + this.add_goal(GoalSource::Misc, Goal::new(tcx, param_env, normalizes_to)); + } + ty::AliasKind::Projection | ty::AliasKind::Inherent | ty::AliasKind::Weak => { + this.add_normalizes_to_goal(Goal::new(tcx, param_env, normalizes_to)) + } + } this.try_evaluate_added_goals()?; Ok(this.resolve_vars_if_possible(normalized_ty)) }) { diff --git a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs index 9c7fa5216d7..d92bae2528f 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs @@ -128,7 +128,7 @@ pub(super) trait GoalKind<'tcx>: goal: Goal<'tcx, Self>, ) -> QueryResult<'tcx>; - /// A type is `Copy` or `Clone` if its components are `Sized`. + /// A type is `Sized` if its tail component is `Sized`. /// /// These components are given by built-in rules from /// [`structural_traits::instantiate_constituent_tys_for_sized_trait`]. @@ -215,6 +215,13 @@ pub(super) trait GoalKind<'tcx>: goal: Goal<'tcx, Self>, ) -> QueryResult<'tcx>; + /// A coroutine (that comes from a `gen` desugaring) is known to implement + /// `FusedIterator` + fn consider_builtin_fused_iterator_candidate( + ecx: &mut EvalCtxt<'_, 'tcx>, + goal: Goal<'tcx, Self>, + ) -> QueryResult<'tcx>; + fn consider_builtin_async_iterator_candidate( ecx: &mut EvalCtxt<'_, 'tcx>, goal: Goal<'tcx, Self>, @@ -497,6 +504,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { G::consider_builtin_future_candidate(self, goal) } else if lang_items.iterator_trait() == Some(trait_def_id) { G::consider_builtin_iterator_candidate(self, goal) + } else if lang_items.fused_iterator_trait() == Some(trait_def_id) { + G::consider_builtin_fused_iterator_candidate(self, goal) } else if lang_items.async_iterator_trait() == Some(trait_def_id) { G::consider_builtin_async_iterator_candidate(self, goal) } else if lang_items.coroutine_trait() == Some(trait_def_id) { diff --git a/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs b/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs index 2bfb86b592b..80c31831462 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs @@ -6,7 +6,7 @@ use rustc_hir::{def_id::DefId, Movability, Mutability}; use rustc_infer::traits::query::NoSolution; use rustc_middle::traits::solve::Goal; use rustc_middle::ty::{ - self, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, + self, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, }; use rustc_span::sym; @@ -73,8 +73,8 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>( ty::CoroutineWitness(def_id, args) => Ok(ecx .tcx() - .coroutine_hidden_types(def_id) - .map(|bty| replace_erased_lifetimes_with_bound_vars(tcx, bty.instantiate(tcx, args))) + .bound_coroutine_hidden_types(def_id) + .map(|bty| bty.instantiate(tcx, args)) .collect()), // For `PhantomData<T>`, we pass `T`. @@ -93,27 +93,6 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>( } } -pub(in crate::solve) fn replace_erased_lifetimes_with_bound_vars<'tcx>( - tcx: TyCtxt<'tcx>, - ty: Ty<'tcx>, -) -> ty::Binder<'tcx, Ty<'tcx>> { - debug_assert!(!ty.has_bound_regions()); - let mut counter = 0; - let ty = tcx.fold_regions(ty, |r, current_depth| match r.kind() { - ty::ReErased => { - let br = ty::BoundRegion { var: ty::BoundVar::from_u32(counter), kind: ty::BrAnon }; - counter += 1; - ty::Region::new_bound(tcx, current_depth, br) - } - // All free regions should be erased here. - r => bug!("unexpected region: {r:?}"), - }); - let bound_vars = tcx.mk_bound_variable_kinds_from_iter( - (0..counter).map(|_| ty::BoundVariableKind::Region(ty::BrAnon)), - ); - ty::Binder::bind_with_vars(ty, bound_vars) -} - #[instrument(level = "debug", skip(ecx), ret)] pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>( ecx: &EvalCtxt<'_, 'tcx>, @@ -154,13 +133,25 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>( bug!("unexpected type `{ty}`") } - // impl Sized for (T1, T2, .., Tn) where T1: Sized, T2: Sized, .. Tn: Sized - ty::Tuple(tys) => Ok(tys.iter().map(ty::Binder::dummy).collect()), - - // impl Sized for Adt where T: Sized forall T in field types + // impl Sized for () + // impl Sized for (T1, T2, .., Tn) where Tn: Sized if n >= 1 + ty::Tuple(tys) => Ok(tys.last().map_or_else(Vec::new, |&ty| vec![ty::Binder::dummy(ty)])), + + // impl Sized for Adt<Args...> where sized_constraint(Adt)<Args...>: Sized + // `sized_constraint(Adt)` is the deepest struct trail that can be determined + // by the definition of `Adt`, independent of the generic args. + // impl Sized for Adt<Args...> if sized_constraint(Adt) == None + // As a performance optimization, `sized_constraint(Adt)` can return `None` + // if the ADTs definition implies that it is sized by for all possible args. + // In this case, the builtin impl will have no nested subgoals. This is a + // "best effort" optimization and `sized_constraint` may return `Some`, even + // if the ADT is sized for all possible args. ty::Adt(def, args) => { - let sized_crit = def.sized_constraint(ecx.tcx()); - Ok(sized_crit.iter_instantiated(ecx.tcx(), args).map(ty::Binder::dummy).collect()) + if let Some(sized_crit) = def.sized_constraint(ecx.tcx()) { + Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.tcx(), args))]) + } else { + Ok(vec![]) + } } } } @@ -229,13 +220,8 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>( // impl Copy/Clone for CoroutineWitness where T: Copy/Clone forall T in coroutine_hidden_types ty::CoroutineWitness(def_id, args) => Ok(ecx .tcx() - .coroutine_hidden_types(def_id) - .map(|bty| { - replace_erased_lifetimes_with_bound_vars( - ecx.tcx(), - bty.instantiate(ecx.tcx(), args), - ) - }) + .bound_coroutine_hidden_types(def_id) + .map(|bty| bty.instantiate(ecx.tcx(), args)) .collect()), } } diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs index 251b0a193f1..619435d2e8d 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs @@ -9,6 +9,7 @@ //! //! [c]: https://rustc-dev-guide.rust-lang.org/solve/canonicalization.html use super::{CanonicalInput, Certainty, EvalCtxt, Goal}; +use crate::solve::eval_ctxt::NestedGoals; use crate::solve::{ inspect, response_no_constraints_raw, CanonicalResponse, QueryResult, Response, }; @@ -19,6 +20,7 @@ use rustc_infer::infer::canonical::CanonicalVarValues; use rustc_infer::infer::canonical::{CanonicalExt, QueryRegionConstraints}; use rustc_infer::infer::resolve::EagerResolver; use rustc_infer::infer::{InferCtxt, InferOk}; +use rustc_infer::traits::solve::NestedNormalizationGoals; use rustc_middle::infer::canonical::Canonical; use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::solve::{ @@ -28,6 +30,7 @@ use rustc_middle::traits::ObligationCause; use rustc_middle::ty::{self, BoundVar, GenericArgKind, Ty, TyCtxt, TypeFoldable}; use rustc_next_trait_solver::canonicalizer::{CanonicalizeMode, Canonicalizer}; use rustc_span::DUMMY_SP; +use std::assert_matches::assert_matches; use std::iter; use std::ops::Deref; @@ -93,13 +96,31 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { previous call to `try_evaluate_added_goals!`" ); - let certainty = certainty.unify_with(goals_certainty); - - let var_values = self.var_values; - let external_constraints = self.compute_external_query_constraints()?; - + // When normalizing, we've replaced the expected term with an unconstrained + // inference variable. This means that we dropped information which could + // have been important. We handle this by instead returning the nested goals + // to the caller, where they are then handled. + // + // As we return all ambiguous nested goals, we can ignore the certainty returned + // by `try_evaluate_added_goals()`. + let (certainty, normalization_nested_goals) = if self.is_normalizes_to_goal { + let NestedGoals { normalizes_to_goals, goals } = std::mem::take(&mut self.nested_goals); + if cfg!(debug_assertions) { + assert!(normalizes_to_goals.is_empty()); + if goals.is_empty() { + assert_matches!(goals_certainty, Certainty::Yes); + } + } + (certainty, NestedNormalizationGoals(goals)) + } else { + let certainty = certainty.unify_with(goals_certainty); + (certainty, NestedNormalizationGoals::empty()) + }; + + let external_constraints = + self.compute_external_query_constraints(normalization_nested_goals)?; let (var_values, mut external_constraints) = - (var_values, external_constraints).fold_with(&mut EagerResolver::new(self.infcx)); + (self.var_values, external_constraints).fold_with(&mut EagerResolver::new(self.infcx)); // Remove any trivial region constraints once we've resolved regions external_constraints .region_constraints @@ -146,6 +167,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { #[instrument(level = "debug", skip(self), ret)] fn compute_external_query_constraints( &self, + normalization_nested_goals: NestedNormalizationGoals<'tcx>, ) -> Result<ExternalConstraintsData<'tcx>, NoSolution> { // We only check for leaks from universes which were entered inside // of the query. @@ -176,7 +198,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { self.predefined_opaques_in_body.opaque_types.iter().all(|(pa, _)| pa != a) }); - Ok(ExternalConstraintsData { region_constraints, opaque_types }) + Ok(ExternalConstraintsData { region_constraints, opaque_types, normalization_nested_goals }) } /// After calling a canonical query, we apply the constraints returned @@ -185,13 +207,14 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { /// This happens in three steps: /// - we instantiate the bound variables of the query response /// - we unify the `var_values` of the response with the `original_values` - /// - we apply the `external_constraints` returned by the query + /// - we apply the `external_constraints` returned by the query, returning + /// the `normalization_nested_goals` pub(super) fn instantiate_and_apply_query_response( &mut self, param_env: ty::ParamEnv<'tcx>, original_values: Vec<ty::GenericArg<'tcx>>, response: CanonicalResponse<'tcx>, - ) -> Certainty { + ) -> (NestedNormalizationGoals<'tcx>, Certainty) { let instantiation = Self::compute_query_response_instantiation_values( self.infcx, &original_values, @@ -203,11 +226,14 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { Self::unify_query_var_values(self.infcx, param_env, &original_values, var_values); - let ExternalConstraintsData { region_constraints, opaque_types } = - external_constraints.deref(); + let ExternalConstraintsData { + region_constraints, + opaque_types, + normalization_nested_goals, + } = external_constraints.deref(); self.register_region_constraints(region_constraints); self.register_new_opaque_types(param_env, opaque_types); - certainty + (normalization_nested_goals.clone(), certainty) } /// This returns the canoncial variable values to instantiate the bound variables of diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt/commit_if_ok.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt/commit_if_ok.rs index 67b6801059a..c8f9a461adf 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt/commit_if_ok.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt/commit_if_ok.rs @@ -11,6 +11,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { infcx: self.infcx, variables: self.variables, var_values: self.var_values, + is_normalizes_to_goal: self.is_normalizes_to_goal, predefined_opaques_in_body: self.predefined_opaques_in_body, max_input_universe: self.max_input_universe, search_graph: self.search_graph, @@ -25,6 +26,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { infcx: _, variables: _, var_values: _, + is_normalizes_to_goal: _, predefined_opaques_in_body: _, max_input_universe: _, search_graph: _, diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs index 3b858cb449f..a0fe6eca0fc 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs @@ -7,14 +7,14 @@ use rustc_infer::infer::{ BoundRegionConversionTime, DefineOpaqueTypes, InferCtxt, InferOk, TyCtxtInferExt, }; use rustc_infer::traits::query::NoSolution; -use rustc_infer::traits::solve::MaybeCause; +use rustc_infer::traits::solve::{MaybeCause, NestedNormalizationGoals}; use rustc_infer::traits::ObligationCause; use rustc_middle::infer::canonical::CanonicalVarInfos; use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_middle::traits::solve::inspect; use rustc_middle::traits::solve::{ - CanonicalInput, CanonicalResponse, Certainty, IsNormalizesToHack, PredefinedOpaques, - PredefinedOpaquesData, QueryResult, + CanonicalInput, CanonicalResponse, Certainty, PredefinedOpaques, PredefinedOpaquesData, + QueryResult, }; use rustc_middle::traits::specialization_graph; use rustc_middle::ty::{ @@ -61,6 +61,14 @@ pub struct EvalCtxt<'a, 'tcx> { /// The variable info for the `var_values`, only used to make an ambiguous response /// with no constraints. variables: CanonicalVarInfos<'tcx>, + /// Whether we're currently computing a `NormalizesTo` goal. Unlike other goals, + /// `NormalizesTo` goals act like functions with the expected term always being + /// fully unconstrained. This would weaken inference however, as the nested goals + /// never get the inference constraints from the actual normalized-to type. Because + /// of this we return any ambiguous nested goals from `NormalizesTo` to the caller + /// when then adds these to its own context. The caller is always an `AliasRelate` + /// goal so this never leaks out of the solver. + is_normalizes_to_goal: bool, pub(super) var_values: CanonicalVarValues<'tcx>, predefined_opaques_in_body: PredefinedOpaques<'tcx>, @@ -91,9 +99,9 @@ pub struct EvalCtxt<'a, 'tcx> { pub(super) inspect: ProofTreeBuilder<'tcx>, } -#[derive(Debug, Clone)] +#[derive(Default, Debug, Clone)] pub(super) struct NestedGoals<'tcx> { - /// This normalizes-to goal that is treated specially during the evaluation + /// These normalizes-to goals are treated specially during the evaluation /// loop. In each iteration we take the RHS of the projection, replace it with /// a fresh inference variable, and only after evaluating that goal do we /// equate the fresh inference variable with the actual RHS of the predicate. @@ -101,26 +109,24 @@ pub(super) struct NestedGoals<'tcx> { /// This is both to improve caching, and to avoid using the RHS of the /// projection predicate to influence the normalizes-to candidate we select. /// - /// This is not a 'real' nested goal. We must not forget to replace the RHS - /// with a fresh inference variable when we evaluate this goal. That can result - /// in a trait solver cycle. This would currently result in overflow but can be - /// can be unsound with more powerful coinduction in the future. - pub(super) normalizes_to_hack_goal: Option<Goal<'tcx, ty::NormalizesTo<'tcx>>>, + /// Forgetting to replace the RHS with a fresh inference variable when we evaluate + /// this goal results in an ICE.. + pub(super) normalizes_to_goals: Vec<Goal<'tcx, ty::NormalizesTo<'tcx>>>, /// The rest of the goals which have not yet processed or remain ambiguous. pub(super) goals: Vec<(GoalSource, Goal<'tcx, ty::Predicate<'tcx>>)>, } impl<'tcx> NestedGoals<'tcx> { pub(super) fn new() -> Self { - Self { normalizes_to_hack_goal: None, goals: Vec::new() } + Self { normalizes_to_goals: Vec::new(), goals: Vec::new() } } pub(super) fn is_empty(&self) -> bool { - self.normalizes_to_hack_goal.is_none() && self.goals.is_empty() + self.normalizes_to_goals.is_empty() && self.goals.is_empty() } pub(super) fn extend(&mut self, other: NestedGoals<'tcx>) { - assert_eq!(other.normalizes_to_hack_goal, None); + self.normalizes_to_goals.extend(other.normalizes_to_goals); self.goals.extend(other.goals) } } @@ -155,6 +161,10 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { self.search_graph.solver_mode() } + pub(super) fn set_is_normalizes_to_goal(&mut self) { + self.is_normalizes_to_goal = true; + } + /// Creates a root evaluation context and search graph. This should only be /// used from outside of any evaluation, and other methods should be preferred /// over using this manually (such as [`InferCtxtEvalExt::evaluate_root_goal`]). @@ -167,8 +177,8 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { let mut search_graph = search_graph::SearchGraph::new(mode); let mut ecx = EvalCtxt { - search_graph: &mut search_graph, infcx, + search_graph: &mut search_graph, nested_goals: NestedGoals::new(), inspect: ProofTreeBuilder::new_maybe_root(infcx.tcx, generate_proof_tree), @@ -180,6 +190,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { max_input_universe: ty::UniverseIndex::ROOT, variables: ty::List::empty(), var_values: CanonicalVarValues::dummy(), + is_normalizes_to_goal: false, tainted: Ok(()), }; let result = f(&mut ecx); @@ -233,6 +244,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { infcx, variables: canonical_input.variables, var_values, + is_normalizes_to_goal: false, predefined_opaques_in_body: input.predefined_opaques_in_body, max_input_universe: canonical_input.max_universe, search_graph, @@ -319,6 +331,27 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { source: GoalSource, goal: Goal<'tcx, ty::Predicate<'tcx>>, ) -> Result<(bool, Certainty), NoSolution> { + let (normalization_nested_goals, has_changed, certainty) = + self.evaluate_goal_raw(goal_evaluation_kind, source, goal)?; + assert!(normalization_nested_goals.is_empty()); + Ok((has_changed, certainty)) + } + + /// Recursively evaluates `goal`, returning the nested goals in case + /// the nested goal is a `NormalizesTo` goal. + /// + /// As all other goal kinds do not return any nested goals and + /// `NormalizesTo` is only used by `AliasRelate`, all other callsites + /// should use [`EvalCtxt::evaluate_goal`] which discards that empty + /// storage. + // FIXME(-Znext-solver=coinduction): `_source` is currently unused but will + // be necessary once we implement the new coinduction approach. + fn evaluate_goal_raw( + &mut self, + goal_evaluation_kind: GoalEvaluationKind, + _source: GoalSource, + goal: Goal<'tcx, ty::Predicate<'tcx>>, + ) -> Result<(NestedNormalizationGoals<'tcx>, bool, Certainty), NoSolution> { let (orig_values, canonical_goal) = self.canonicalize_goal(goal); let mut goal_evaluation = self.inspect.new_goal_evaluation(goal, &orig_values, goal_evaluation_kind); @@ -336,12 +369,12 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { Ok(response) => response, }; - let (certainty, has_changed) = self.instantiate_response_discarding_overflow( - goal.param_env, - source, - orig_values, - canonical_response, - ); + let (normalization_nested_goals, certainty, has_changed) = self + .instantiate_response_discarding_overflow( + goal.param_env, + orig_values, + canonical_response, + ); self.inspect.goal_evaluation(goal_evaluation); // FIXME: We previously had an assert here that checked that recomputing // a goal after applying its constraints did not change its response. @@ -353,47 +386,25 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { // Once we have decided on how to handle trait-system-refactor-initiative#75, // we should re-add an assert here. - Ok((has_changed, certainty)) + Ok((normalization_nested_goals, has_changed, certainty)) } fn instantiate_response_discarding_overflow( &mut self, param_env: ty::ParamEnv<'tcx>, - source: GoalSource, original_values: Vec<ty::GenericArg<'tcx>>, response: CanonicalResponse<'tcx>, - ) -> (Certainty, bool) { - // The old solver did not evaluate nested goals when normalizing. - // It returned the selection constraints allowing a `Projection` - // obligation to not hold in coherence while avoiding the fatal error - // from overflow. - // - // We match this behavior here by considering all constraints - // from nested goals which are not from where-bounds. We will already - // need to track which nested goals are required by impl where-bounds - // for coinductive cycles, so we simply reuse that here. - // - // While we could consider overflow constraints in more cases, this should - // not be necessary for backcompat and results in better perf. It also - // avoids a potential inconsistency which would otherwise require some - // tracking for root goals as well. See #119071 for an example. - let keep_overflow_constraints = || { - self.search_graph.current_goal_is_normalizes_to() - && source != GoalSource::ImplWhereBound - }; - - if let Certainty::Maybe(MaybeCause::Overflow { .. }) = response.value.certainty - && !keep_overflow_constraints() - { - return (response.value.certainty, false); + ) -> (NestedNormalizationGoals<'tcx>, Certainty, bool) { + if let Certainty::Maybe(MaybeCause::Overflow { .. }) = response.value.certainty { + return (NestedNormalizationGoals::empty(), response.value.certainty, false); } let has_changed = !response.value.var_values.is_identity_modulo_regions() || !response.value.external_constraints.opaque_types.is_empty(); - let certainty = + let (normalization_nested_goals, certainty) = self.instantiate_and_apply_query_response(param_env, original_values, response); - (certainty, has_changed) + (normalization_nested_goals, certainty, has_changed) } fn compute_goal(&mut self, goal: Goal<'tcx, ty::Predicate<'tcx>>) -> QueryResult<'tcx> { @@ -496,7 +507,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { /// Goals for the next step get directly added to the nested goals of the `EvalCtxt`. fn evaluate_added_goals_step(&mut self) -> Result<Option<Certainty>, NoSolution> { let tcx = self.tcx(); - let mut goals = core::mem::replace(&mut self.nested_goals, NestedGoals::new()); + let mut goals = core::mem::take(&mut self.nested_goals); self.inspect.evaluate_added_goals_loop_start(); @@ -508,7 +519,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { // If this loop did not result in any progress, what's our final certainty. let mut unchanged_certainty = Some(Certainty::Yes); - if let Some(goal) = goals.normalizes_to_hack_goal.take() { + for goal in goals.normalizes_to_goals { // Replace the goal with an unconstrained infer var, so the // RHS does not affect projection candidate assembly. let unconstrained_rhs = self.next_term_infer_of_kind(goal.predicate.term); @@ -517,11 +528,13 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { ty::NormalizesTo { alias: goal.predicate.alias, term: unconstrained_rhs }, ); - let (_, certainty) = self.evaluate_goal( - GoalEvaluationKind::Nested { is_normalizes_to_hack: IsNormalizesToHack::Yes }, + let (NestedNormalizationGoals(nested_goals), _, certainty) = self.evaluate_goal_raw( + GoalEvaluationKind::Nested, GoalSource::Misc, unconstrained_goal, )?; + // Add the nested goals from normalization to our own nested goals. + goals.goals.extend(nested_goals); // Finally, equate the goal's RHS with the unconstrained var. // We put the nested goals from this into goals instead of @@ -536,27 +549,23 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { // looking at the "has changed" return from evaluate_goal, // because we expect the `unconstrained_rhs` part of the predicate // to have changed -- that means we actually normalized successfully! - if goal.predicate.alias != self.resolve_vars_if_possible(goal.predicate.alias) { + let with_resolved_vars = self.resolve_vars_if_possible(goal); + if goal.predicate.alias != with_resolved_vars.predicate.alias { unchanged_certainty = None; } match certainty { Certainty::Yes => {} Certainty::Maybe(_) => { - // We need to resolve vars here so that we correctly - // deal with `has_changed` in the next iteration. - self.set_normalizes_to_hack_goal(self.resolve_vars_if_possible(goal)); + self.nested_goals.normalizes_to_goals.push(with_resolved_vars); unchanged_certainty = unchanged_certainty.map(|c| c.unify_with(certainty)); } } } - for (source, goal) in goals.goals.drain(..) { - let (has_changed, certainty) = self.evaluate_goal( - GoalEvaluationKind::Nested { is_normalizes_to_hack: IsNormalizesToHack::No }, - source, - goal, - )?; + for (source, goal) in goals.goals { + let (has_changed, certainty) = + self.evaluate_goal(GoalEvaluationKind::Nested, source, goal)?; if has_changed { unchanged_certainty = None; } @@ -968,7 +977,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { ty: Ty<'tcx>, ) -> Option<ty::Const<'tcx>> { use rustc_middle::mir::interpret::ErrorHandled; - match self.infcx.try_const_eval_resolve(param_env, unevaluated, ty, None) { + match self.infcx.try_const_eval_resolve(param_env, unevaluated, ty, DUMMY_SP) { Ok(ct) => Some(ct), Err(ErrorHandled::Reported(e, _)) => { Some(ty::Const::new_error(self.tcx(), e.into(), ty)) diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt/probe.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt/probe.rs index 91fd48807a4..5b1124e8b9f 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt/probe.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt/probe.rs @@ -24,6 +24,7 @@ where infcx: outer_ecx.infcx, variables: outer_ecx.variables, var_values: outer_ecx.var_values, + is_normalizes_to_goal: outer_ecx.is_normalizes_to_goal, predefined_opaques_in_body: outer_ecx.predefined_opaques_in_body, max_input_universe: outer_ecx.max_input_universe, search_graph: outer_ecx.search_graph, diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs index 3262d64cb7d..e0c7804b6db 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs @@ -58,12 +58,13 @@ impl<'tcx> InferCtxt<'tcx> { } let candidate = candidates.pop().unwrap(); - let certainty = ecx.instantiate_and_apply_query_response( - trait_goal.param_env, - orig_values, - candidate.result, - ); - + let (normalization_nested_goals, certainty) = ecx + .instantiate_and_apply_query_response( + trait_goal.param_env, + orig_values, + candidate.result, + ); + assert!(normalization_nested_goals.is_empty()); Ok(Some((candidate, certainty))) }); diff --git a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs index 9e3e6a4676e..cfec2e9bbf3 100644 --- a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs +++ b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs @@ -70,7 +70,19 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> { instantiated_goals.push(goal); } - for &goal in &instantiated_goals { + for goal in instantiated_goals.iter().copied() { + // We need to be careful with `NormalizesTo` goals as the + // expected term has to be replaced with an unconstrained + // inference variable. + if let Some(kind) = goal.predicate.kind().no_bound_vars() + && let ty::PredicateKind::NormalizesTo(predicate) = kind + && !predicate.alias.is_opaque(infcx.tcx) + { + // FIXME: We currently skip these goals as + // `fn evaluate_root_goal` ICEs if there are any + // `NestedNormalizationGoals`. + continue; + }; let (_, proof_tree) = infcx.evaluate_root_goal(goal, GenerateProofTree::Yes); let proof_tree = proof_tree.unwrap(); try_visit!(visitor.visit_goal(&InspectGoal::new( diff --git a/compiler/rustc_trait_selection/src/solve/inspect/build.rs b/compiler/rustc_trait_selection/src/solve/inspect/build.rs index f7b310a7abe..4da999f2406 100644 --- a/compiler/rustc_trait_selection/src/solve/inspect/build.rs +++ b/compiler/rustc_trait_selection/src/solve/inspect/build.rs @@ -7,7 +7,7 @@ use std::mem; use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::solve::{ - CanonicalInput, Certainty, Goal, GoalSource, IsNormalizesToHack, QueryInput, QueryResult, + CanonicalInput, Certainty, Goal, GoalSource, QueryInput, QueryResult, }; use rustc_middle::ty::{self, TyCtxt}; use rustc_session::config::DumpSolverProofTree; @@ -97,9 +97,7 @@ impl<'tcx> WipGoalEvaluation<'tcx> { WipGoalEvaluationKind::Root { orig_values } => { inspect::GoalEvaluationKind::Root { orig_values } } - WipGoalEvaluationKind::Nested { is_normalizes_to_hack } => { - inspect::GoalEvaluationKind::Nested { is_normalizes_to_hack } - } + WipGoalEvaluationKind::Nested => inspect::GoalEvaluationKind::Nested, }, evaluation: self.evaluation.unwrap().finalize(), } @@ -109,7 +107,7 @@ impl<'tcx> WipGoalEvaluation<'tcx> { #[derive(Eq, PartialEq, Debug)] pub(in crate::solve) enum WipGoalEvaluationKind<'tcx> { Root { orig_values: Vec<ty::GenericArg<'tcx>> }, - Nested { is_normalizes_to_hack: IsNormalizesToHack }, + Nested, } #[derive(Eq, PartialEq)] @@ -305,9 +303,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> { solve::GoalEvaluationKind::Root => { WipGoalEvaluationKind::Root { orig_values: orig_values.to_vec() } } - solve::GoalEvaluationKind::Nested { is_normalizes_to_hack } => { - WipGoalEvaluationKind::Nested { is_normalizes_to_hack } - } + solve::GoalEvaluationKind::Nested => WipGoalEvaluationKind::Nested, }, evaluation: None, }) @@ -419,6 +415,17 @@ impl<'tcx> ProofTreeBuilder<'tcx> { } } + pub fn add_normalizes_to_goal( + ecx: &mut EvalCtxt<'_, 'tcx>, + goal: Goal<'tcx, ty::NormalizesTo<'tcx>>, + ) { + if ecx.inspect.is_noop() { + return; + } + + Self::add_goal(ecx, GoalSource::Misc, goal.with(ecx.tcx(), goal.predicate)); + } + pub fn add_goal( ecx: &mut EvalCtxt<'_, 'tcx>, source: GoalSource, diff --git a/compiler/rustc_trait_selection/src/solve/mod.rs b/compiler/rustc_trait_selection/src/solve/mod.rs index 0bf28f520a4..8294a8a67b1 100644 --- a/compiler/rustc_trait_selection/src/solve/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/mod.rs @@ -18,8 +18,7 @@ use rustc_infer::infer::canonical::{Canonical, CanonicalVarValues}; use rustc_infer::traits::query::NoSolution; use rustc_middle::infer::canonical::CanonicalVarInfos; use rustc_middle::traits::solve::{ - CanonicalResponse, Certainty, ExternalConstraintsData, Goal, GoalSource, IsNormalizesToHack, - QueryResult, Response, + CanonicalResponse, Certainty, ExternalConstraintsData, Goal, GoalSource, QueryResult, Response, }; use rustc_middle::ty::{self, AliasRelationDirection, Ty, TyCtxt, UniverseIndex}; use rustc_middle::ty::{ @@ -69,7 +68,7 @@ enum SolverMode { #[derive(Debug, Copy, Clone, PartialEq, Eq)] enum GoalEvaluationKind { Root, - Nested { is_normalizes_to_hack: IsNormalizesToHack }, + Nested, } #[extension(trait CanonicalResponseExt)] @@ -202,12 +201,9 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { impl<'tcx> EvalCtxt<'_, 'tcx> { #[instrument(level = "debug", skip(self))] - fn set_normalizes_to_hack_goal(&mut self, goal: Goal<'tcx, ty::NormalizesTo<'tcx>>) { - assert!( - self.nested_goals.normalizes_to_hack_goal.is_none(), - "attempted to set the projection eq hack goal when one already exists" - ); - self.nested_goals.normalizes_to_hack_goal = Some(goal); + fn add_normalizes_to_goal(&mut self, goal: Goal<'tcx, ty::NormalizesTo<'tcx>>) { + inspect::ProofTreeBuilder::add_normalizes_to_goal(self, goal); + self.nested_goals.normalizes_to_goals.push(goal); } #[instrument(level = "debug", skip(self))] diff --git a/compiler/rustc_trait_selection/src/solve/normalizes_to/anon_const.rs b/compiler/rustc_trait_selection/src/solve/normalizes_to/anon_const.rs index 911462f4b9a..37d56452893 100644 --- a/compiler/rustc_trait_selection/src/solve/normalizes_to/anon_const.rs +++ b/compiler/rustc_trait_selection/src/solve/normalizes_to/anon_const.rs @@ -16,7 +16,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { .no_bound_vars() .expect("const ty should not rely on other generics"), ) { - self.eq(goal.param_env, normalized_const, goal.predicate.term.ct().unwrap())?; + self.instantiate_normalizes_to_term(goal, normalized_const.into()); self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) } else { self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) diff --git a/compiler/rustc_trait_selection/src/solve/normalizes_to/inherent.rs b/compiler/rustc_trait_selection/src/solve/normalizes_to/inherent.rs index 52d2fe1e3ec..439f9eec831 100644 --- a/compiler/rustc_trait_selection/src/solve/normalizes_to/inherent.rs +++ b/compiler/rustc_trait_selection/src/solve/normalizes_to/inherent.rs @@ -1,5 +1,5 @@ //! Computes a normalizes-to (projection) goal for inherent associated types, -//! `#![feature(inherent_associated_type)]`. Since astconv already determines +//! `#![feature(inherent_associated_type)]`. Since HIR ty lowering already determines //! which impl the IAT is being projected from, we just: //! 1. instantiate generic parameters, //! 2. equate the self type, and @@ -16,7 +16,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { ) -> QueryResult<'tcx> { let tcx = self.tcx(); let inherent = goal.predicate.alias; - let expected = goal.predicate.term.ty().expect("inherent consts are treated separately"); let impl_def_id = tcx.parent(inherent.def_id); let impl_args = self.fresh_args_for_item(impl_def_id); @@ -30,12 +29,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { // Equate IAT with the RHS of the project goal let inherent_args = inherent.rebase_inherent_args_onto_impl(impl_args, tcx); - self.eq( - goal.param_env, - expected, - tcx.type_of(inherent.def_id).instantiate(tcx, inherent_args), - ) - .expect("expected goal term to be fully unconstrained"); // Check both where clauses on the impl and IAT // @@ -51,6 +44,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { .map(|(pred, _)| goal.with(tcx, pred)), ); + let normalized = tcx.type_of(inherent.def_id).instantiate(tcx, inherent_args); + self.instantiate_normalizes_to_term(goal, normalized.into()); self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) } } diff --git a/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs b/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs index a45c1c34410..66688893235 100644 --- a/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs @@ -31,32 +31,19 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { goal: Goal<'tcx, NormalizesTo<'tcx>>, ) -> QueryResult<'tcx> { let def_id = goal.predicate.def_id(); + let def_kind = self.tcx().def_kind(def_id); + match def_kind { + DefKind::OpaqueTy => return self.normalize_opaque_type(goal), + _ => self.set_is_normalizes_to_goal(), + } + + debug_assert!(self.term_is_fully_unconstrained(goal)); match self.tcx().def_kind(def_id) { DefKind::AssocTy | DefKind::AssocConst => { match self.tcx().associated_item(def_id).container { ty::AssocItemContainer::TraitContainer => { - // To only compute normalization once for each projection we only - // assemble normalization candidates if the expected term is an - // unconstrained inference variable. - // - // Why: For better cache hits, since if we have an unconstrained RHS then - // there are only as many cache keys as there are (canonicalized) alias - // types in each normalizes-to goal. This also weakens inference in a - // forwards-compatible way so we don't use the value of the RHS term to - // affect candidate assembly for projections. - // - // E.g. for `<T as Trait>::Assoc == u32` we recursively compute the goal - // `exists<U> <T as Trait>::Assoc == U` and then take the resulting type for - // `U` and equate it with `u32`. This means that we don't need a separate - // projection cache in the solver, since we're piggybacking off of regular - // goal caching. - if self.term_is_fully_unconstrained(goal) { - let candidates = self.assemble_and_evaluate_candidates(goal); - self.merge_candidates(candidates) - } else { - self.set_normalizes_to_hack_goal(goal); - self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) - } + let candidates = self.assemble_and_evaluate_candidates(goal); + self.merge_candidates(candidates) } ty::AssocItemContainer::ImplContainer => { self.normalize_inherent_associated_type(goal) @@ -64,9 +51,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { } } DefKind::AnonConst => self.normalize_anon_const(goal), - DefKind::OpaqueTy => self.normalize_opaque_type(goal), DefKind::TyAlias => self.normalize_weak_type(goal), - kind => bug!("unknown DefKind {} in projection goal: {goal:#?}", kind.descr(def_id)), + kind => bug!("unknown DefKind {} in normalizes-to goal: {goal:#?}", kind.descr(def_id)), } } @@ -428,7 +414,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> { ), output_coroutine_ty.into(), ), - sym::CallMutFuture | sym::CallFuture => ( + sym::CallRefFuture => ( ty::AliasTy::new( tcx, goal.predicate.def_id(), @@ -661,6 +647,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> { ) } + fn consider_builtin_fused_iterator_candidate( + _ecx: &mut EvalCtxt<'_, 'tcx>, + goal: Goal<'tcx, Self>, + ) -> QueryResult<'tcx> { + bug!("`FusedIterator` does not have an associated type: {:?}", goal); + } + fn consider_builtin_async_iterator_candidate( ecx: &mut EvalCtxt<'_, 'tcx>, goal: Goal<'tcx, Self>, diff --git a/compiler/rustc_trait_selection/src/solve/normalizes_to/weak_types.rs b/compiler/rustc_trait_selection/src/solve/normalizes_to/weak_types.rs index 9f91c02c1ab..13af5068b6c 100644 --- a/compiler/rustc_trait_selection/src/solve/normalizes_to/weak_types.rs +++ b/compiler/rustc_trait_selection/src/solve/normalizes_to/weak_types.rs @@ -15,10 +15,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { ) -> QueryResult<'tcx> { let tcx = self.tcx(); let weak_ty = goal.predicate.alias; - let expected = goal.predicate.term.ty().expect("no such thing as a const alias"); - - let actual = tcx.type_of(weak_ty.def_id).instantiate(tcx, weak_ty.args); - self.eq(goal.param_env, expected, actual)?; // Check where clauses self.add_goals( @@ -30,6 +26,9 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { .map(|pred| goal.with(tcx, pred)), ); + let actual = tcx.type_of(weak_ty.def_id).instantiate(tcx, weak_ty.args); + self.instantiate_normalizes_to_term(goal, actual.into()); + self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) } } diff --git a/compiler/rustc_trait_selection/src/solve/search_graph.rs b/compiler/rustc_trait_selection/src/solve/search_graph.rs index 07a8aca85a0..a48b2f2478b 100644 --- a/compiler/rustc_trait_selection/src/solve/search_graph.rs +++ b/compiler/rustc_trait_selection/src/solve/search_graph.rs @@ -10,7 +10,6 @@ use rustc_index::IndexVec; use rustc_middle::dep_graph::dep_kinds; use rustc_middle::traits::solve::CacheData; use rustc_middle::traits::solve::{CanonicalInput, Certainty, EvaluationCache, QueryResult}; -use rustc_middle::ty; use rustc_middle::ty::TyCtxt; use rustc_session::Limit; use std::mem; @@ -175,15 +174,6 @@ impl<'tcx> SearchGraph<'tcx> { } } - pub(super) fn current_goal_is_normalizes_to(&self) -> bool { - self.stack.raw.last().map_or(false, |e| { - matches!( - e.input.value.goal.predicate.kind().skip_binder(), - ty::PredicateKind::NormalizesTo(..) - ) - }) - } - /// Returns the remaining depth allowed for nested goals. /// /// This is generally simply one less than the current depth. diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals.rs b/compiler/rustc_trait_selection/src/solve/trait_goals.rs index c252ad76dfe..184ba31f19d 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals.rs @@ -456,6 +456,28 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) } + fn consider_builtin_fused_iterator_candidate( + ecx: &mut EvalCtxt<'_, 'tcx>, + goal: Goal<'tcx, Self>, + ) -> QueryResult<'tcx> { + if goal.predicate.polarity != ty::ImplPolarity::Positive { + return Err(NoSolution); + } + + let ty::Coroutine(def_id, _) = *goal.predicate.self_ty().kind() else { + return Err(NoSolution); + }; + + // Coroutines are not iterators unless they come from `gen` desugaring + let tcx = ecx.tcx(); + if !tcx.coroutine_is_gen(def_id) { + return Err(NoSolution); + } + + // Gen coroutines unconditionally implement `FusedIterator` + ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) + } + fn consider_builtin_async_iterator_candidate( ecx: &mut EvalCtxt<'_, 'tcx>, goal: Goal<'tcx, Self>, diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index fbf96833187..0796ffcbc45 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -786,7 +786,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { match selcx.infcx.const_eval_resolve( obligation.param_env, unevaluated, - Some(obligation.cause.span), + obligation.cause.span, ) { Ok(Some(valtree)) => Ok(ty::Const::new_value(selcx.tcx(),valtree, c.ty())), Ok(None) => { diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 7f0f9a12d6a..9ca1dd4557d 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -68,7 +68,7 @@ pub fn is_const_evaluatable<'tcx>( tcx.dcx().span_bug(span, "evaluating `ConstKind::Expr` is not currently supported"); } ty::ConstKind::Unevaluated(uv) => { - let concrete = infcx.const_eval_resolve(param_env, uv, Some(span)); + let concrete = infcx.const_eval_resolve(param_env, uv, span); match concrete { Err(ErrorHandled::TooGeneric(_)) => { Err(NotConstEvaluatable::Error(infcx.dcx().span_delayed_bug( @@ -99,7 +99,7 @@ pub fn is_const_evaluatable<'tcx>( // and hopefully soon change this to an error. // // See #74595 for more details about this. - let concrete = infcx.const_eval_resolve(param_env, uv, Some(span)); + let concrete = infcx.const_eval_resolve(param_env, uv, span); match concrete { // If we're evaluating a generic foreign constant, under a nightly compiler while // the current crate does not enable `feature(generic_const_exprs)`, abort diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index 745ddfc08af..5fccc769785 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -367,6 +367,23 @@ pub struct UnknownFormatParameterForOnUnimplementedAttr { trait_name: Symbol, } +#[derive(LintDiagnostic)] +#[diag(trait_selection_disallowed_positional_argument)] +#[help] +pub struct DisallowedPositionalArgument; + +#[derive(LintDiagnostic)] +#[diag(trait_selection_invalid_format_specifier)] +#[help] +pub struct InvalidFormatSpecifier; + +#[derive(LintDiagnostic)] +#[diag(trait_selection_wrapped_parser_error)] +pub struct WrappedParserError { + description: String, + label: String, +} + impl<'tcx> OnUnimplementedDirective { fn parse( tcx: TyCtxt<'tcx>, @@ -758,64 +775,108 @@ impl<'tcx> OnUnimplementedFormatString { let trait_name = tcx.item_name(trait_def_id); let generics = tcx.generics_of(item_def_id); let s = self.symbol.as_str(); - let parser = Parser::new(s, None, None, false, ParseMode::Format); + let mut parser = Parser::new(s, None, None, false, ParseMode::Format); let mut result = Ok(()); - for token in parser { + for token in &mut parser { match token { Piece::String(_) => (), // Normal string, no need to check it - Piece::NextArgument(a) => match a.position { - Position::ArgumentNamed(s) => { - match Symbol::intern(s) { - // `{ThisTraitsName}` is allowed - s if s == trait_name && !self.is_diagnostic_namespace_variant => (), - s if ALLOWED_FORMAT_SYMBOLS.contains(&s) - && !self.is_diagnostic_namespace_variant => - { - () - } - // So is `{A}` if A is a type parameter - s if generics.params.iter().any(|param| param.name == s) => (), - s => { - if self.is_diagnostic_namespace_variant { - tcx.emit_node_span_lint( - UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, - tcx.local_def_id_to_hir_id(item_def_id.expect_local()), - self.span, - UnknownFormatParameterForOnUnimplementedAttr { - argument_name: s, - trait_name, - }, - ); - } else { - result = Err(struct_span_code_err!( - tcx.dcx(), - self.span, - E0230, - "there is no parameter `{}` on {}", - s, - if trait_def_id == item_def_id { - format!("trait `{trait_name}`") - } else { - "impl".to_string() - } - ) - .emit()); + Piece::NextArgument(a) => { + let format_spec = a.format; + if self.is_diagnostic_namespace_variant + && (format_spec.ty_span.is_some() + || format_spec.width_span.is_some() + || format_spec.precision_span.is_some() + || format_spec.fill_span.is_some()) + { + tcx.emit_node_span_lint( + UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, + tcx.local_def_id_to_hir_id(item_def_id.expect_local()), + self.span, + InvalidFormatSpecifier, + ); + } + match a.position { + Position::ArgumentNamed(s) => { + match Symbol::intern(s) { + // `{ThisTraitsName}` is allowed + s if s == trait_name && !self.is_diagnostic_namespace_variant => (), + s if ALLOWED_FORMAT_SYMBOLS.contains(&s) + && !self.is_diagnostic_namespace_variant => + { + () + } + // So is `{A}` if A is a type parameter + s if generics.params.iter().any(|param| param.name == s) => (), + s => { + if self.is_diagnostic_namespace_variant { + tcx.emit_node_span_lint( + UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, + tcx.local_def_id_to_hir_id(item_def_id.expect_local()), + self.span, + UnknownFormatParameterForOnUnimplementedAttr { + argument_name: s, + trait_name, + }, + ); + } else { + result = Err(struct_span_code_err!( + tcx.dcx(), + self.span, + E0230, + "there is no parameter `{}` on {}", + s, + if trait_def_id == item_def_id { + format!("trait `{trait_name}`") + } else { + "impl".to_string() + } + ) + .emit()); + } } } } + // `{:1}` and `{}` are not to be used + Position::ArgumentIs(..) | Position::ArgumentImplicitlyIs(_) => { + if self.is_diagnostic_namespace_variant { + tcx.emit_node_span_lint( + UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, + tcx.local_def_id_to_hir_id(item_def_id.expect_local()), + self.span, + DisallowedPositionalArgument, + ); + } else { + let reported = struct_span_code_err!( + tcx.dcx(), + self.span, + E0231, + "only named generic parameters are allowed" + ) + .emit(); + result = Err(reported); + } + } } - // `{:1}` and `{}` are not to be used - Position::ArgumentIs(..) | Position::ArgumentImplicitlyIs(_) => { - let reported = struct_span_code_err!( - tcx.dcx(), - self.span, - E0231, - "only named generic parameters are allowed" - ) - .emit(); - result = Err(reported); - } - }, + } + } + } + // we cannot return errors from processing the format string as hard error here + // as the diagnostic namespace gurantees that malformed input cannot cause an error + // + // if we encounter any error while processing we nevertheless want to show it as warning + // so that users are aware that something is not correct + for e in parser.errors { + if self.is_diagnostic_namespace_variant { + tcx.emit_node_span_lint( + UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, + tcx.local_def_id_to_hir_id(item_def_id.expect_local()), + self.span, + WrappedParserError { description: e.description, label: e.label }, + ); + } else { + let reported = + struct_span_code_err!(tcx.dcx(), self.span, E0231, "{}", e.description,).emit(); + result = Err(reported); } } @@ -853,9 +914,9 @@ impl<'tcx> OnUnimplementedFormatString { let empty_string = String::new(); let s = self.symbol.as_str(); - let parser = Parser::new(s, None, None, false, ParseMode::Format); + let mut parser = Parser::new(s, None, None, false, ParseMode::Format); let item_context = (options.get(&sym::ItemContext)).unwrap_or(&empty_string); - parser + let constructed_message = (&mut parser) .map(|p| match p { Piece::String(s) => s.to_owned(), Piece::NextArgument(a) => match a.position { @@ -895,9 +956,29 @@ impl<'tcx> OnUnimplementedFormatString { } } } + Position::ArgumentImplicitlyIs(_) if self.is_diagnostic_namespace_variant => { + String::from("{}") + } + Position::ArgumentIs(idx) if self.is_diagnostic_namespace_variant => { + format!("{{{idx}}}") + } _ => bug!("broken on_unimplemented {:?} - bad format arg", self.symbol), }, }) - .collect() + .collect(); + // we cannot return errors from processing the format string as hard error here + // as the diagnostic namespace gurantees that malformed input cannot cause an error + // + // if we encounter any error while processing the format string + // we don't want to show the potentially half assembled formated string, + // therefore we fall back to just showing the input string in this case + // + // The actual parser errors are emitted earlier + // as lint warnings in OnUnimplementedFormatString::verify + if self.is_diagnostic_namespace_variant && !parser.errors.is_empty() { + String::from(s) + } else { + constructed_message + } } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 067ca883bd8..00d00496947 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -194,8 +194,7 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>( sugg.extend(ty_spans.into_iter().map(|s| (s, type_param_name.to_string()))); // Suggest `fn foo<T: Trait>(t: T) where <T as Trait>::A: Bound`. - // FIXME: once `#![feature(associated_type_bounds)]` is stabilized, we should suggest - // `fn foo(t: impl Trait<A: Bound>)` instead. + // FIXME: we should suggest `fn foo(t: impl Trait<A: Bound>)` instead. err.multipart_suggestion( "introduce a type parameter with a trait bound instead of using `impl Trait`", sugg, @@ -1099,8 +1098,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { )) } ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { - self.tcx.item_bounds(def_id).instantiate(self.tcx, args).iter().find_map( - |pred| { + self.tcx + .item_super_predicates(def_id) + .instantiate(self.tcx, args) + .iter() + .find_map(|pred| { if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder() && Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() // args tuple will always be args[1] @@ -1114,8 +1116,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } else { None } - }, - ) + }) } ty::Dynamic(data, _, ty::Dyn) => { data.iter().find_map(|pred| { @@ -2954,6 +2955,16 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } } ObligationCauseCode::VariableType(hir_id) => { + if let Some(typeck_results) = &self.typeck_results + && let Some(ty) = typeck_results.node_type_opt(hir_id) + && let ty::Error(_) = ty.kind() + { + err.note(format!( + "`{predicate}` isn't satisfied, but the type of this pattern is \ + `{{type error}}`", + )); + err.downgrade_to_delayed_bug(); + } match tcx.parent_hir_node(hir_id) { Node::Local(hir::Local { ty: Some(ty), .. }) => { err.span_suggestion_verbose( @@ -3200,71 +3211,69 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } }; - // Don't print the tuple of capture types - 'print: { - if !is_upvar_tys_infer_tuple { - let ty_str = tcx.short_ty_string(ty, &mut long_ty_file); - let msg = format!("required because it appears within the type `{ty_str}`"); - match ty.kind() { - ty::Adt(def, _) => match tcx.opt_item_ident(def.did()) { - Some(ident) => err.span_note(ident.span, msg), - None => err.note(msg), - }, - ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { - // If the previous type is async fn, this is the future generated by the body of an async function. - // Avoid printing it twice (it was already printed in the `ty::Coroutine` arm below). - let is_future = tcx.ty_is_opaque_future(ty); - debug!( - ?obligated_types, - ?is_future, - "note_obligation_cause_code: check for async fn" - ); - if is_future - && obligated_types.last().is_some_and(|ty| match ty.kind() { - ty::Coroutine(last_def_id, ..) => { - tcx.coroutine_is_async(*last_def_id) - } - _ => false, - }) - { - break 'print; - } - err.span_note(tcx.def_span(def_id), msg) + if !is_upvar_tys_infer_tuple { + let ty_str = tcx.short_ty_string(ty, &mut long_ty_file); + let msg = format!("required because it appears within the type `{ty_str}`"); + match ty.kind() { + ty::Adt(def, _) => match tcx.opt_item_ident(def.did()) { + Some(ident) => { + err.span_note(ident.span, msg); } - ty::CoroutineWitness(def_id, args) => { - use std::fmt::Write; - - // FIXME: this is kind of an unusual format for rustc, can we make it more clear? - // Maybe we should just remove this note altogether? - // FIXME: only print types which don't meet the trait requirement - let mut msg = - "required because it captures the following types: ".to_owned(); - for bty in tcx.coroutine_hidden_types(*def_id) { - let ty = bty.instantiate(tcx, args); - write!(msg, "`{ty}`, ").unwrap(); - } - err.note(msg.trim_end_matches(", ").to_string()) + None => { + err.note(msg); } - ty::Coroutine(def_id, _) => { - let sp = tcx.def_span(def_id); - - // Special-case this to say "async block" instead of `[static coroutine]`. - let kind = tcx.coroutine_kind(def_id).unwrap(); - err.span_note( - sp, - with_forced_trimmed_paths!(format!( - "required because it's used within this {kind:#}", - )), - ) + }, + ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { + // If the previous type is async fn, this is the future generated by the body of an async function. + // Avoid printing it twice (it was already printed in the `ty::Coroutine` arm below). + let is_future = tcx.ty_is_opaque_future(ty); + debug!( + ?obligated_types, + ?is_future, + "note_obligation_cause_code: check for async fn" + ); + if is_future + && obligated_types.last().is_some_and(|ty| match ty.kind() { + ty::Coroutine(last_def_id, ..) => { + tcx.coroutine_is_async(*last_def_id) + } + _ => false, + }) + { + // See comment above; skip printing twice. + } else { + err.span_note(tcx.def_span(def_id), msg); } - ty::Closure(def_id, _) => err.span_note( + } + ty::Coroutine(def_id, _) => { + let sp = tcx.def_span(def_id); + + // Special-case this to say "async block" instead of `[static coroutine]`. + let kind = tcx.coroutine_kind(def_id).unwrap(); + err.span_note( + sp, + with_forced_trimmed_paths!(format!( + "required because it's used within this {kind:#}", + )), + ); + } + ty::CoroutineWitness(..) => { + // Skip printing coroutine-witnesses, since we'll drill into + // the bad field in another derived obligation cause. + } + ty::Closure(def_id, _) | ty::CoroutineClosure(def_id, _) => { + err.span_note( tcx.def_span(def_id), "required because it's used within this closure", - ), - ty::Str => err.note("`str` is considered to contain a `[u8]` slice for auto trait purposes"), - _ => err.note(msg), - }; - } + ); + } + ty::Str => { + err.note("`str` is considered to contain a `[u8]` slice for auto trait purposes"); + } + _ => { + err.note(msg); + } + }; } obligated_types.push(ty); @@ -3510,9 +3519,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } ObligationCauseCode::TrivialBound => { err.help("see issue #48214"); - if tcx.sess.opts.unstable_features.is_nightly_build() { - err.help("add `#![feature(trivial_bounds)]` to the crate attributes to enable"); - } + tcx.disabled_nightly_features( + err, + Some(tcx.local_def_id_to_hir_id(body_id)), + [(String::new(), sym::trivial_bounds)], + ); } ObligationCauseCode::OpaqueReturnType(expr_info) => { if let Some((expr_ty, expr_span)) = expr_info { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index e8aab236048..4bc3ff92a67 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -3073,29 +3073,29 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let src = trait_ref.args.type_at(1); let err_msg = format!("`{src}` cannot be safely transmuted into `{dst}`"); let safe_transmute_explanation = match reason { - rustc_transmute::Reason::SrcIsUnspecified => { - format!("`{src}` does not have a well-specified layout") + rustc_transmute::Reason::SrcIsNotYetSupported => { + format!("analyzing the transmutability of `{src}` is not yet supported.") } - rustc_transmute::Reason::DstIsUnspecified => { - format!("`{dst}` does not have a well-specified layout") + rustc_transmute::Reason::DstIsNotYetSupported => { + format!("analyzing the transmutability of `{dst}` is not yet supported.") } rustc_transmute::Reason::DstIsBitIncompatible => { - format!("At least one value of `{src}` isn't a bit-valid value of `{dst}`") + format!("at least one value of `{src}` isn't a bit-valid value of `{dst}`") } rustc_transmute::Reason::DstMayHaveSafetyInvariants => { format!("`{dst}` may carry safety invariants") } rustc_transmute::Reason::DstIsTooBig => { - format!("The size of `{src}` is smaller than the size of `{dst}`") + format!("the size of `{src}` is smaller than the size of `{dst}`") } rustc_transmute::Reason::DstRefIsTooBig { src, dst } => { let src_size = src.size; let dst_size = dst.size; format!( - "The referent size of `{src}` ({src_size} bytes) is smaller than that of `{dst}` ({dst_size} bytes)" + "the referent size of `{src}` ({src_size} bytes) is smaller than that of `{dst}` ({dst_size} bytes)" ) } rustc_transmute::Reason::SrcSizeOverflow => { @@ -3113,7 +3113,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { dst_min_align, } => { format!( - "The minimum alignment of `{src}` ({src_min_align}) should be greater than that of `{dst}` ({dst_min_align})" + "the minimum alignment of `{src}` ({src_min_align}) should be greater than that of `{dst}` ({dst_min_align})" ) } rustc_transmute::Reason::DstIsMoreUnique => { diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 2fd64f474d5..34c891d400e 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -600,7 +600,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { obligation.param_env, unevaluated, c.ty(), - Some(obligation.cause.span), + obligation.cause.span, ) { Ok(val) => Ok(val), Err(e) => { diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index cc8b8f72cf3..c875d3da47e 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -46,7 +46,7 @@ pub use self::coherence::{IsFirstInputType, OrphanCheckErr, OverlapResult}; pub use self::engine::{ObligationCtxt, TraitEngineExt}; pub use self::fulfill::{FulfillmentContext, PendingPredicateObligation}; pub use self::normalize::NormalizeExt; -pub use self::object_safety::astconv_object_safety_violations; +pub use self::object_safety::hir_ty_lowering_object_safety_violations; pub use self::object_safety::is_vtable_safe_method; pub use self::object_safety::object_safety_violations_for_assoc_item; pub use self::object_safety::ObjectSafetyViolation; diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 1816b98a636..5efb41f2bd8 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -32,11 +32,13 @@ use std::ops::ControlFlow; pub use crate::traits::{MethodViolationCode, ObjectSafetyViolation}; -/// Returns the object safety violations that affect -/// astconv -- currently, `Self` in supertraits. This is needed +/// Returns the object safety violations that affect HIR ty lowering. +/// +/// Currently that is `Self` in supertraits. This is needed /// because `object_safety_violations` can't be used during /// type collection. -pub fn astconv_object_safety_violations( +#[instrument(level = "debug", skip(tcx))] +pub fn hir_ty_lowering_object_safety_violations( tcx: TyCtxt<'_>, trait_def_id: DefId, ) -> Vec<ObjectSafetyViolation> { @@ -46,9 +48,7 @@ pub fn astconv_object_safety_violations( .filter(|spans| !spans.is_empty()) .map(ObjectSafetyViolation::SupertraitSelf) .collect(); - - debug!("astconv_object_safety_violations(trait_def_id={:?}) = {:?}", trait_def_id, violations); - + debug!(?violations); violations } diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 6756b5dec23..12371155303 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1726,7 +1726,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>( let sig = args.coroutine_closure_sig().skip_binder(); let term = match item_name { - sym::CallOnceFuture | sym::CallMutFuture | sym::CallFuture => { + sym::CallOnceFuture | sym::CallRefFuture => { if let Some(closure_kind) = kind_ty.to_opt_closure_kind() { if !closure_kind.extends(goal_kind) { bug!("we should not be confirming if the closure kind is not met"); @@ -1787,7 +1787,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>( obligation.predicate.def_id, [self_ty, sig.tupled_inputs_ty], ), - sym::CallMutFuture | sym::CallFuture => ty::AliasTy::new( + sym::CallRefFuture => ty::AliasTy::new( tcx, obligation.predicate.def_id, [ty::GenericArg::from(self_ty), sig.tupled_inputs_ty.into(), env_region.into()], @@ -1803,7 +1803,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>( let sig = bound_sig.skip_binder(); let term = match item_name { - sym::CallOnceFuture | sym::CallMutFuture | sym::CallFuture => sig.output(), + sym::CallOnceFuture | sym::CallRefFuture => sig.output(), sym::Output => { let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None); let future_output_def_id = tcx @@ -1822,7 +1822,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>( obligation.predicate.def_id, [self_ty, Ty::new_tup(tcx, sig.inputs())], ), - sym::CallMutFuture | sym::CallFuture => ty::AliasTy::new( + sym::CallRefFuture => ty::AliasTy::new( tcx, obligation.predicate.def_id, [ @@ -1842,7 +1842,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>( let sig = bound_sig.skip_binder(); let term = match item_name { - sym::CallOnceFuture | sym::CallMutFuture | sym::CallFuture => sig.output(), + sym::CallOnceFuture | sym::CallRefFuture => sig.output(), sym::Output => { let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None); let future_output_def_id = tcx @@ -1859,7 +1859,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>( sym::CallOnceFuture | sym::Output => { ty::AliasTy::new(tcx, obligation.predicate.def_id, [self_ty, sig.inputs()[0]]) } - sym::CallMutFuture | sym::CallFuture => ty::AliasTy::new( + sym::CallRefFuture => ty::AliasTy::new( tcx, obligation.predicate.def_id, [ty::GenericArg::from(self_ty), sig.inputs()[0].into(), env_region.into()], diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs index 14f14ae6e2e..63289746f5e 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs @@ -20,14 +20,11 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> { // such cases. if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) = key.value.predicate.kind().skip_binder() + && let Some(sized_def_id) = tcx.lang_items().sized_trait() + && trait_ref.def_id() == sized_def_id + && trait_ref.self_ty().is_trivially_sized(tcx) { - if let Some(sized_def_id) = tcx.lang_items().sized_trait() { - if trait_ref.def_id() == sized_def_id { - if trait_ref.self_ty().is_trivially_sized(tcx) { - return Some(()); - } - } - } + return Some(()); } if let ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(arg)) = diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 49091e53be7..9fb4577fb21 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -118,6 +118,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self.assemble_future_candidates(obligation, &mut candidates); } else if lang_items.iterator_trait() == Some(def_id) { self.assemble_iterator_candidates(obligation, &mut candidates); + } else if lang_items.fused_iterator_trait() == Some(def_id) { + self.assemble_fused_iterator_candidates(obligation, &mut candidates); } else if lang_items.async_iterator_trait() == Some(def_id) { self.assemble_async_iterator_candidates(obligation, &mut candidates); } else if lang_items.async_fn_kind_helper() == Some(def_id) { @@ -302,14 +304,31 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { candidates: &mut SelectionCandidateSet<'tcx>, ) { let self_ty = obligation.self_ty().skip_binder(); - if let ty::Coroutine(did, ..) = self_ty.kind() { - // gen constructs get lowered to a special kind of coroutine that - // should directly `impl Iterator`. - if self.tcx().coroutine_is_gen(*did) { - debug!(?self_ty, ?obligation, "assemble_iterator_candidates",); + // gen constructs get lowered to a special kind of coroutine that + // should directly `impl Iterator`. + if let ty::Coroutine(did, ..) = self_ty.kind() + && self.tcx().coroutine_is_gen(*did) + { + debug!(?self_ty, ?obligation, "assemble_iterator_candidates",); - candidates.vec.push(IteratorCandidate); - } + candidates.vec.push(IteratorCandidate); + } + } + + fn assemble_fused_iterator_candidates( + &mut self, + obligation: &PolyTraitObligation<'tcx>, + candidates: &mut SelectionCandidateSet<'tcx>, + ) { + let self_ty = obligation.self_ty().skip_binder(); + // gen constructs get lowered to a special kind of coroutine that + // should directly `impl FusedIterator`. + if let ty::Coroutine(did, ..) = self_ty.kind() + && self.tcx().coroutine_is_gen(*did) + { + debug!(?self_ty, ?obligation, "assemble_fused_iterator_candidates",); + + candidates.vec.push(BuiltinCandidate { has_nested: false }); } } diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 51fc223a5d1..eca36fc343e 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -14,7 +14,7 @@ use rustc_infer::infer::{DefineOpaqueTypes, InferOk}; use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData}; use rustc_middle::ty::{ self, GenericArgs, GenericArgsRef, GenericParamDefKind, ToPolyTraitRef, ToPredicate, - TraitPredicate, Ty, TyCtxt, TypeVisitableExt, + TraitPredicate, Ty, TyCtxt, }; use rustc_span::def_id::DefId; @@ -267,6 +267,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self.copy_clone_conditions(obligation) } else if Some(trait_def) == lang_items.clone_trait() { self.copy_clone_conditions(obligation) + } else if Some(trait_def) == lang_items.fused_iterator_trait() { + self.fused_iterator_conditions(obligation) } else { bug!("unexpected builtin trait {:?}", trait_def) }; @@ -1262,7 +1264,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Extract `TailField<T>` and `TailField<U>` from `Struct<T>` and `Struct<U>`, // normalizing in the process, since `type_of` returns something directly from - // astconv (which means it's un-normalized). + // HIR ty lowering (which means it's un-normalized). let source_tail = normalize_with_depth_to( self, obligation.param_env, @@ -1438,10 +1440,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } ty::CoroutineWitness(def_id, args) => { let tcx = self.tcx(); - stack.extend(tcx.coroutine_hidden_types(def_id).map(|bty| { - let ty = bty.instantiate(tcx, args); - debug_assert!(!ty.has_bound_regions()); - ty + stack.extend(tcx.bound_coroutine_hidden_types(def_id).map(|bty| { + self.infcx.enter_forall_and_leak_universe(bty.instantiate(tcx, args)) })) } diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index d10fe6a9490..adbc7d12a64 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -949,7 +949,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.param_env, unevaluated, c.ty(), - Some(obligation.cause.span), + obligation.cause.span, ) { Ok(val) => Ok(val), Err(e) => Err(e), @@ -1617,21 +1617,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { _ => return ControlFlow::Continue(()), }; - for bound in - self.tcx().item_bounds(alias_ty.def_id).instantiate(self.tcx(), alias_ty.args) - { - // HACK: On subsequent recursions, we only care about bounds that don't - // share the same type as `self_ty`. This is because for truly rigid - // projections, we will never be able to equate, e.g. `<T as Tr>::A` - // with `<<T as Tr>::A as Tr>::A`. - if in_parent_alias_type { - match bound.kind().skip_binder() { - ty::ClauseKind::Trait(tr) if tr.self_ty() == self_ty => continue, - ty::ClauseKind::Projection(p) if p.self_ty() == self_ty => continue, - _ => {} - } - } + // HACK: On subsequent recursions, we only care about bounds that don't + // share the same type as `self_ty`. This is because for truly rigid + // projections, we will never be able to equate, e.g. `<T as Tr>::A` + // with `<<T as Tr>::A as Tr>::A`. + let relevant_bounds = if in_parent_alias_type { + self.tcx().item_non_self_assumptions(alias_ty.def_id) + } else { + self.tcx().item_super_predicates(alias_ty.def_id) + }; + for bound in relevant_bounds.instantiate(self.tcx(), alias_ty.args) { for_each(self, bound, idx)?; idx += 1; } @@ -2123,13 +2119,14 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ), ty::Adt(def, args) => { - let sized_crit = def.sized_constraint(self.tcx()); - // (*) binder moved here - Where( - obligation - .predicate - .rebind(sized_crit.iter_instantiated(self.tcx(), args).collect()), - ) + if let Some(sized_crit) = def.sized_constraint(self.tcx()) { + // (*) binder moved here + Where( + obligation.predicate.rebind(vec![sized_crit.instantiate(self.tcx(), args)]), + ) + } else { + Where(ty::Binder::dummy(Vec::new())) + } } ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => None, @@ -2262,6 +2259,20 @@ impl<'tcx> SelectionContext<'_, 'tcx> { } } + fn fused_iterator_conditions( + &mut self, + obligation: &PolyTraitObligation<'tcx>, + ) -> BuiltinImplConditions<'tcx> { + let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder()); + if let ty::Coroutine(did, ..) = *self_ty.kind() + && self.tcx().coroutine_is_gen(did) + { + BuiltinImplConditions::Where(ty::Binder::dummy(Vec::new())) + } else { + BuiltinImplConditions::None + } + } + /// For default impls, we need to break apart a type into its /// "constituent types" -- meaning, the types that it contains. /// diff --git a/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs b/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs index 95db9e2092f..1aa65b87f0b 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs @@ -396,7 +396,7 @@ pub(crate) fn assoc_def( // associated type. Normally this situation // could only arise through a compiler bug -- // if the user wrote a bad item name, it - // should have failed in astconv. + // should have failed during HIR ty lowering. bug!( "No associated type `{}` for {}", tcx.item_name(assoc_def_id), diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs index c2fc55542ff..9a43d67d435 100644 --- a/compiler/rustc_transmute/src/layout/tree.rs +++ b/compiler/rustc_transmute/src/layout/tree.rs @@ -186,8 +186,8 @@ pub(crate) mod rustc { #[derive(Debug, Copy, Clone)] pub(crate) enum Err { - /// The layout of the type is unspecified. - Unspecified, + /// The layout of the type is not yet supported. + NotYetSupported, /// This error will be surfaced elsewhere by rustc, so don't surface it. UnknownLayout, /// Overflow size @@ -288,14 +288,14 @@ pub(crate) mod rustc { if members.len() == 0 { Ok(Tree::unit()) } else { - Err(Err::Unspecified) + Err(Err::NotYetSupported) } } ty::Array(ty, len) => { let len = len .try_eval_target_usize(tcx, ParamEnv::reveal_all()) - .ok_or(Err::Unspecified)?; + .ok_or(Err::NotYetSupported)?; let elt = Tree::from_ty(*ty, tcx)?; Ok(std::iter::repeat(elt) .take(len as usize) @@ -307,7 +307,7 @@ pub(crate) mod rustc { // If the layout is ill-specified, halt. if !(adt_def.repr().c() || adt_def.repr().int.is_some()) { - return Err(Err::Unspecified); + return Err(Err::NotYetSupported); } // Compute a summary of the type's layout. @@ -348,7 +348,7 @@ pub(crate) mod rustc { AdtKind::Union => { // is the layout well-defined? if !adt_def.repr().c() { - return Err(Err::Unspecified); + return Err(Err::NotYetSupported); } let ty_layout = layout_of(tcx, ty)?; @@ -384,7 +384,7 @@ pub(crate) mod rustc { })) } - _ => Err(Err::Unspecified), + _ => Err(Err::NotYetSupported), } } diff --git a/compiler/rustc_transmute/src/lib.rs b/compiler/rustc_transmute/src/lib.rs index 8f3af491453..b6f937ebe47 100644 --- a/compiler/rustc_transmute/src/lib.rs +++ b/compiler/rustc_transmute/src/lib.rs @@ -43,10 +43,10 @@ pub enum Condition<R> { /// Answers "why wasn't the source type transmutable into the destination type?" #[derive(Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Clone)] pub enum Reason<T> { - /// The layout of the source type is unspecified. - SrcIsUnspecified, - /// The layout of the destination type is unspecified. - DstIsUnspecified, + /// The layout of the source type is not yet supported. + SrcIsNotYetSupported, + /// The layout of the destination type is not yet supported. + DstIsNotYetSupported, /// The layout of the destination type is bit-incompatible with the source type. DstIsBitIncompatible, /// The destination type may carry safety invariants. @@ -89,6 +89,7 @@ mod rustc { use rustc_middle::ty::Ty; use rustc_middle::ty::TyCtxt; use rustc_middle::ty::ValTree; + use rustc_span::DUMMY_SP; /// The source and destination types of a transmutation. #[derive(TypeVisitable, Debug, Clone, Copy)] @@ -135,7 +136,7 @@ mod rustc { use rustc_middle::ty::ScalarInt; use rustc_span::symbol::sym; - let Ok(cv) = c.eval(tcx, param_env, None) else { + let Ok(cv) = c.eval(tcx, param_env, DUMMY_SP) else { return Some(Self { alignment: true, lifetimes: true, diff --git a/compiler/rustc_transmute/src/maybe_transmutable/mod.rs b/compiler/rustc_transmute/src/maybe_transmutable/mod.rs index e9f425686c4..16d15580a05 100644 --- a/compiler/rustc_transmute/src/maybe_transmutable/mod.rs +++ b/compiler/rustc_transmute/src/maybe_transmutable/mod.rs @@ -56,8 +56,8 @@ mod rustc { } (Err(Err::UnknownLayout), _) => Answer::No(Reason::SrcLayoutUnknown), (_, Err(Err::UnknownLayout)) => Answer::No(Reason::DstLayoutUnknown), - (Err(Err::Unspecified), _) => Answer::No(Reason::SrcIsUnspecified), - (_, Err(Err::Unspecified)) => Answer::No(Reason::DstIsUnspecified), + (Err(Err::NotYetSupported), _) => Answer::No(Reason::SrcIsNotYetSupported), + (_, Err(Err::NotYetSupported)) => Answer::No(Reason::DstIsNotYetSupported), (Err(Err::SizeOverflow), _) => Answer::No(Reason::SrcSizeOverflow), (_, Err(Err::SizeOverflow)) => Answer::No(Reason::DstSizeOverflow), (Ok(src), Ok(dst)) => MaybeTransmutableQuery { src, dst, assume, context }.answer(), diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index a5328baadb5..baf4de768c5 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -102,6 +102,7 @@ fn fn_sig_for_fn_abi<'tcx>( ) } ty::CoroutineClosure(def_id, args) => { + let coroutine_ty = Ty::new_coroutine_closure(tcx, def_id, args); let sig = args.as_coroutine_closure().coroutine_closure_sig(); let bound_vars = tcx.mk_bound_variable_kinds_from_iter( sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))), @@ -111,18 +112,24 @@ fn fn_sig_for_fn_abi<'tcx>( kind: ty::BoundRegionKind::BrEnv, }; let env_region = ty::Region::new_bound(tcx, ty::INNERMOST, br); - // When this `CoroutineClosure` comes from a `ConstructCoroutineInClosureShim`, // make sure we respect the `target_kind` in that shim. // FIXME(async_closures): This shouldn't be needed, and we should be populating // a separate def-id for these bodies. - let mut kind = args.as_coroutine_closure().kind(); - if let InstanceDef::ConstructCoroutineInClosureShim { target_kind, .. } = instance.def { - kind = target_kind; - } + let mut coroutine_kind = args.as_coroutine_closure().kind(); let env_ty = - tcx.closure_env_ty(Ty::new_coroutine_closure(tcx, def_id, args), kind, env_region); + if let InstanceDef::ConstructCoroutineInClosureShim { receiver_by_ref, .. } = + instance.def + { + coroutine_kind = ty::ClosureKind::FnOnce; + + // Implementations of `FnMut` and `Fn` for coroutine-closures + // still take their receiver by ref. + if receiver_by_ref { Ty::new_mut_ptr(tcx, coroutine_ty) } else { coroutine_ty } + } else { + tcx.closure_env_ty(coroutine_ty, coroutine_kind, env_region) + }; let sig = sig.skip_binder(); ty::Binder::bind_with_vars( @@ -132,7 +139,7 @@ fn fn_sig_for_fn_abi<'tcx>( tcx, args.as_coroutine_closure().parent_args(), tcx.coroutine_for_closure(def_id), - kind, + coroutine_kind, env_region, args.as_coroutine_closure().tupled_upvars_ty(), args.as_coroutine_closure().coroutine_captures_by_ref_ty(), @@ -161,7 +168,7 @@ fn fn_sig_for_fn_abi<'tcx>( // make sure we respect the `target_kind` in that shim. // FIXME(async_closures): This shouldn't be needed, and we should be populating // a separate def-id for these bodies. - if let InstanceDef::CoroutineKindShim { target_kind, .. } = instance.def { + if let InstanceDef::CoroutineKindShim { .. } = instance.def { // Grab the parent coroutine-closure. It has the same args for the purposes // of instantiation, so this will be okay to do. let ty::CoroutineClosure(_, coroutine_closure_args) = *tcx @@ -181,7 +188,7 @@ fn fn_sig_for_fn_abi<'tcx>( tcx, coroutine_closure_args.parent_args(), did, - target_kind, + ty::ClosureKind::FnOnce, tcx.lifetimes.re_erased, coroutine_closure_args.tupled_upvars_ty(), coroutine_closure_args.coroutine_captures_by_ref_ty(), diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index 50a8eb869b9..ba75424ec0c 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -1,11 +1,10 @@ use rustc_data_structures::fx::FxIndexSet; +use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId}; use rustc_hir::intravisit::{self, Visitor}; -use rustc_hir::{self as hir, HirId}; -use rustc_index::IndexVec; use rustc_middle::query::Providers; -use rustc_middle::ty::{self, ImplTraitInTraitData, TyCtxt, TyCtxtFeed}; +use rustc_middle::ty::{self, ImplTraitInTraitData, TyCtxt}; use rustc_span::symbol::kw; pub(crate) fn provide(providers: &mut Providers) { @@ -238,28 +237,6 @@ fn associated_types_for_impl_traits_in_associated_fn( } } -fn feed_hir(feed: &TyCtxtFeed<'_, LocalDefId>) { - feed.local_def_id_to_hir_id(HirId::make_owner(feed.def_id())); - - let node = hir::OwnerNode::AssocOpaqueTy(&hir::AssocOpaqueTy {}); - let bodies = Default::default(); - let attrs = hir::AttributeMap::EMPTY; - - let (opt_hash_including_bodies, _) = feed.tcx.hash_owner_nodes(node, &bodies, &attrs.map); - feed.opt_hir_owner_nodes(Some(feed.tcx.arena.alloc(hir::OwnerNodes { - opt_hash_including_bodies, - nodes: IndexVec::from_elem_n( - hir::ParentedNode { - parent: hir::ItemLocalId::INVALID, - node: hir::Node::AssocOpaqueTy(&hir::AssocOpaqueTy {}), - }, - 1, - ), - bodies, - }))); - feed.feed_owner_id().hir_attrs(attrs); -} - /// Given an `opaque_ty_def_id` corresponding to an `impl Trait` in an associated /// function from a trait, synthesize an associated type for that `impl Trait` /// that inherits properties that we infer from the method and the opaque type. @@ -281,7 +258,7 @@ fn associated_type_for_impl_trait_in_trait( let local_def_id = trait_assoc_ty.def_id(); let def_id = local_def_id.to_def_id(); - feed_hir(&trait_assoc_ty); + trait_assoc_ty.feed_hir(); // Copy span of the opaque. trait_assoc_ty.def_ident_span(Some(span)); @@ -335,7 +312,7 @@ fn associated_type_for_impl_trait_in_impl( let local_def_id = impl_assoc_ty.def_id(); let def_id = local_def_id.to_def_id(); - feed_hir(&impl_assoc_ty); + impl_assoc_ty.feed_hir(); // Copy span of the opaque. impl_assoc_ty.def_ident_span(Some(span)); diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 2816bcc888b..a8f9afb87dd 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -282,7 +282,7 @@ fn resolve_associated_item<'tcx>( Some(Instance { def: ty::InstanceDef::ConstructCoroutineInClosureShim { coroutine_closure_def_id, - target_kind: ty::ClosureKind::FnOnce, + receiver_by_ref: target_kind != ty::ClosureKind::FnOnce, }, args, }) @@ -297,25 +297,20 @@ fn resolve_associated_item<'tcx>( { match *rcvr_args.type_at(0).kind() { ty::CoroutineClosure(coroutine_closure_def_id, args) => { - match (target_kind, args.as_coroutine_closure().kind()) { - (ClosureKind::FnOnce | ClosureKind::FnMut, ClosureKind::Fn) - | (ClosureKind::FnOnce, ClosureKind::FnMut) => { - // If we're computing `AsyncFnOnce`/`AsyncFnMut` for a by-ref closure, - // or `AsyncFnOnce` for a by-mut closure, then construct a new body that - // has the right return types. - // - // Specifically, `AsyncFnMut` for a by-ref coroutine-closure just needs - // to have its input and output types fixed (`&mut self` and returning - // `i16` coroutine kind). - Some(Instance { - def: ty::InstanceDef::ConstructCoroutineInClosureShim { - coroutine_closure_def_id, - target_kind, - }, - args, - }) - } - _ => Some(Instance::new(coroutine_closure_def_id, args)), + if target_kind == ClosureKind::FnOnce + && args.as_coroutine_closure().kind() != ClosureKind::FnOnce + { + // If we're computing `AsyncFnOnce` for a by-ref closure then + // construct a new body that has the right return types. + Some(Instance { + def: ty::InstanceDef::ConstructCoroutineInClosureShim { + coroutine_closure_def_id, + receiver_by_ref: false, + }, + args, + }) + } else { + Some(Instance::new(coroutine_closure_def_id, args)) } } ty::Closure(closure_def_id, args) => { diff --git a/compiler/rustc_ty_utils/src/representability.rs b/compiler/rustc_ty_utils/src/representability.rs index bb546cee2dd..a5ffa553c2a 100644 --- a/compiler/rustc_ty_utils/src/representability.rs +++ b/compiler/rustc_ty_utils/src/representability.rs @@ -12,7 +12,7 @@ pub(crate) fn provide(providers: &mut Providers) { macro_rules! rtry { ($e:expr) => { match $e { - e @ Representability::Infinite => return e, + e @ Representability::Infinite(_) => return e, Representability::Representable => {} } }; diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 2b6b91672c3..547a3cb5a8c 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -1,78 +1,56 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def::DefKind; +use rustc_hir::LangItem; use rustc_index::bit_set::BitSet; use rustc_middle::query::Providers; -use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeVisitor}; +use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeVisitableExt, TypeVisitor}; use rustc_middle::ty::{ToPredicate, TypeSuperVisitable, TypeVisitable}; use rustc_span::def_id::{DefId, LocalDefId, CRATE_DEF_ID}; use rustc_span::DUMMY_SP; use rustc_trait_selection::traits; -fn sized_constraint_for_ty<'tcx>( - tcx: TyCtxt<'tcx>, - adtdef: ty::AdtDef<'tcx>, - ty: Ty<'tcx>, -) -> Vec<Ty<'tcx>> { +#[instrument(level = "debug", skip(tcx), ret)] +fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>> { use rustc_type_ir::TyKind::*; - let result = match ty.kind() { - Bool | Char | Int(..) | Uint(..) | Float(..) | RawPtr(..) | Ref(..) | FnDef(..) - | FnPtr(_) | Array(..) | Closure(..) | CoroutineClosure(..) | Coroutine(..) | Never => { - vec![] - } - - Str | Dynamic(..) | Slice(_) | Foreign(..) | Error(_) | CoroutineWitness(..) => { - // these are never sized - return the target type - vec![ty] - } - - Tuple(tys) => match tys.last() { - None => vec![], - Some(&ty) => sized_constraint_for_ty(tcx, adtdef, ty), - }, - - Adt(adt, args) => { - // recursive case - let adt_tys = adt.sized_constraint(tcx); - debug!("sized_constraint_for_ty({:?}) intermediate = {:?}", ty, adt_tys); - adt_tys - .iter_instantiated(tcx, args) - .flat_map(|ty| sized_constraint_for_ty(tcx, adtdef, ty)) - .collect() - } - - Alias(..) => { - // must calculate explicitly. - // FIXME: consider special-casing always-Sized projections - vec![ty] - } - - Param(..) => { - // perf hack: if there is a `T: Sized` bound, then - // we know that `T` is Sized and do not need to check - // it on the impl. - - let Some(sized_trait_def_id) = tcx.lang_items().sized_trait() else { return vec![ty] }; - let predicates = tcx.predicates_of(adtdef.did()).predicates; - if predicates.iter().any(|(p, _)| { - p.as_trait_clause().is_some_and(|trait_pred| { - trait_pred.def_id() == sized_trait_def_id - && trait_pred.self_ty().skip_binder() == ty - }) - }) { - vec![] - } else { - vec![ty] - } - } + match ty.kind() { + // these are always sized + Bool + | Char + | Int(..) + | Uint(..) + | Float(..) + | RawPtr(..) + | Ref(..) + | FnDef(..) + | FnPtr(..) + | Array(..) + | Closure(..) + | CoroutineClosure(..) + | Coroutine(..) + | CoroutineWitness(..) + | Never + | Dynamic(_, _, ty::DynStar) => None, + + // these are never sized + Str | Slice(..) | Dynamic(_, _, ty::Dyn) | Foreign(..) => Some(ty), + + Tuple(tys) => tys.last().and_then(|&ty| sized_constraint_for_ty(tcx, ty)), + + // recursive case + Adt(adt, args) => adt.sized_constraint(tcx).and_then(|intermediate| { + let ty = intermediate.instantiate(tcx, args); + sized_constraint_for_ty(tcx, ty) + }), + + // these can be sized or unsized + Param(..) | Alias(..) | Error(_) => Some(ty), Placeholder(..) | Bound(..) | Infer(..) => { - bug!("unexpected type `{:?}` in sized_constraint_for_ty", ty) + bug!("unexpected type `{ty:?}` in sized_constraint_for_ty") } - }; - debug!("sized_constraint_for_ty({:?}) = {:?}", ty, result); - result + } } fn defaultness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Defaultness { @@ -90,29 +68,45 @@ fn defaultness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Defaultness { /// /// In fact, there are only a few options for the types in the constraint: /// - an obviously-unsized type -/// - a type parameter or projection whose Sizedness can't be known -/// - a tuple of type parameters or projections, if there are multiple -/// such. -/// - an Error, if a type is infinitely sized +/// - a type parameter or projection whose sizedness can't be known +#[instrument(level = "debug", skip(tcx), ret)] fn adt_sized_constraint<'tcx>( tcx: TyCtxt<'tcx>, def_id: DefId, -) -> ty::EarlyBinder<&'tcx ty::List<Ty<'tcx>>> { +) -> Option<ty::EarlyBinder<Ty<'tcx>>> { if let Some(def_id) = def_id.as_local() { - if matches!(tcx.representability(def_id), ty::Representability::Infinite) { - return ty::EarlyBinder::bind(tcx.mk_type_list(&[Ty::new_misc_error(tcx)])); + if let ty::Representability::Infinite(_) = tcx.representability(def_id) { + return None; } } let def = tcx.adt_def(def_id); - let result = - tcx.mk_type_list_from_iter(def.variants().iter().filter_map(|v| v.tail_opt()).flat_map( - |f| sized_constraint_for_ty(tcx, def, tcx.type_of(f.did).instantiate_identity()), - )); + if !def.is_struct() { + bug!("`adt_sized_constraint` called on non-struct type: {def:?}"); + } + + let tail_def = def.non_enum_variant().tail_opt()?; + let tail_ty = tcx.type_of(tail_def.did).instantiate_identity(); - debug!("adt_sized_constraint: {:?} => {:?}", def, result); + let constraint_ty = sized_constraint_for_ty(tcx, tail_ty)?; + if constraint_ty.references_error() { + return None; + } + + // perf hack: if there is a `constraint_ty: Sized` bound, then we know + // that the type is sized and do not need to check it on the impl. + let sized_trait_def_id = tcx.require_lang_item(LangItem::Sized, None); + let predicates = tcx.predicates_of(def.did()).predicates; + if predicates.iter().any(|(p, _)| { + p.as_trait_clause().is_some_and(|trait_pred| { + trait_pred.def_id() == sized_trait_def_id + && trait_pred.self_ty().skip_binder() == constraint_ty + }) + }) { + return None; + } - ty::EarlyBinder::bind(result) + Some(ty::EarlyBinder::bind(constraint_ty)) } /// See `ParamEnv` struct definition for details. diff --git a/compiler/rustc_type_ir/src/flags.rs b/compiler/rustc_type_ir/src/flags.rs index b38ef2ad84d..cd199222d90 100644 --- a/compiler/rustc_type_ir/src/flags.rs +++ b/compiler/rustc_type_ir/src/flags.rs @@ -85,7 +85,7 @@ bitflags! { | TypeFlags::HAS_TY_INHERENT.bits() | TypeFlags::HAS_CT_PROJECTION.bits(); - /// Is an error type/const reachable? + /// Is an error type/lifetime/const reachable? const HAS_ERROR = 1 << 15; /// Does this have any region that "appears free" in the type? diff --git a/compiler/rustc_type_ir/src/predicate_kind.rs b/compiler/rustc_type_ir/src/predicate_kind.rs index a0759f7df7f..112f617fe16 100644 --- a/compiler/rustc_type_ir/src/predicate_kind.rs +++ b/compiler/rustc_type_ir/src/predicate_kind.rs @@ -148,19 +148,20 @@ pub enum PredicateKind<I: Interner> { /// Used for coherence to mark opaque types as possibly equal to each other but ambiguous. Ambiguous, - /// The alias normalizes to `term`. Unlike `Projection`, this always fails if the alias - /// cannot be normalized in the current context. + /// This should only be used inside of the new solver for `AliasRelate` and expects + /// the `term` to be an unconstrained inference variable. /// - /// `Projection(<T as Trait>::Assoc, ?x)` results in `?x == <T as Trait>::Assoc` while - /// `NormalizesTo(<T as Trait>::Assoc, ?x)` results in `NoSolution`. - /// - /// Only used in the new solver. + /// The alias normalizes to `term`. Unlike `Projection`, this always fails if the + /// alias cannot be normalized in the current context. For the rigid alias + /// `T as Trait>::Assoc`, `Projection(<T as Trait>::Assoc, ?x)` constrains `?x` + /// to `<T as Trait>::Assoc` while `NormalizesTo(<T as Trait>::Assoc, ?x)` + /// results in `NoSolution`. NormalizesTo(I::NormalizesTo), /// Separate from `ClauseKind::Projection` which is used for normalization in new solver. /// This predicate requires two terms to be equal to eachother. /// - /// Only used for new solver + /// Only used for new solver. AliasRelate(I::Term, I::Term, AliasRelationDirection), } diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index cf13f066cbf..2e8481df56d 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -223,23 +223,27 @@ impl<I: Interner> DebugWithInfcx<I> for RegionKind<I> { f: &mut core::fmt::Formatter<'_>, ) -> core::fmt::Result { match this.data { - ReEarlyParam(data) => write!(f, "ReEarlyParam({data:?})"), + ReEarlyParam(data) => write!(f, "{data:?}"), ReBound(binder_id, bound_region) => { - write!(f, "ReBound({binder_id:?}, {bound_region:?})") + write!(f, "'")?; + crate::debug_bound_var(f, *binder_id, bound_region) } ReLateParam(fr) => write!(f, "{fr:?}"), - ReStatic => f.write_str("ReStatic"), + ReStatic => f.write_str("'static"), ReVar(vid) => write!(f, "{:?}", &this.wrap(vid)), - RePlaceholder(placeholder) => write!(f, "RePlaceholder({placeholder:?})"), + RePlaceholder(placeholder) => write!(f, "{placeholder:?}"), - ReErased => f.write_str("ReErased"), + // Use `'{erased}` as the output instead of `'erased` so that its more obviously distinct from + // a `ReEarlyParam` named `'erased`. Technically that would print as `'erased/#IDX` so this is + // not strictly necessary but *shrug* + ReErased => f.write_str("'{erased}"), - ReError(_) => f.write_str("ReError"), + ReError(_) => f.write_str("'{region error}"), } } } diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index de8f56618d0..c83428af50a 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -60,7 +60,7 @@ impl AliasKind { /// Defines the kinds of types used by the type system. /// /// Types written by the user start out as `hir::TyKind` and get -/// converted to this representation using `AstConv::ast_ty_to_ty`. +/// converted to this representation using `<dyn HirTyLowerer>::lower_ty`. #[cfg_attr(feature = "nightly", rustc_diagnostic_item = "IrTyKind")] #[derive(derivative::Derivative)] #[derivative( diff --git a/compiler/stable_mir/src/compiler_interface.rs b/compiler/stable_mir/src/compiler_interface.rs index f53dbcfbd96..8ed34fab54d 100644 --- a/compiler/stable_mir/src/compiler_interface.rs +++ b/compiler/stable_mir/src/compiler_interface.rs @@ -8,7 +8,7 @@ use std::cell::Cell; use crate::abi::{FnAbi, Layout, LayoutShape}; use crate::mir::alloc::{AllocId, GlobalAlloc}; use crate::mir::mono::{Instance, InstanceDef, StaticDef}; -use crate::mir::Body; +use crate::mir::{Body, Place}; use crate::target::MachineInfo; use crate::ty::{ AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, ForeignDef, @@ -126,12 +126,15 @@ pub trait Context { fn def_ty_with_args(&self, item: DefId, args: &GenericArgs) -> Ty; /// Returns literal value of a const as a string. - fn const_literal(&self, cnst: &Const) -> String; + fn const_pretty(&self, cnst: &Const) -> String; /// `Span` of an item fn span_of_an_item(&self, def_id: DefId) -> Span; /// Obtain the representation of a type. + fn ty_pretty(&self, ty: Ty) -> String; + + /// Obtain the representation of a type. fn ty_kind(&self, ty: Ty) -> TyKind; // Get the discriminant Ty for this Ty if there's one. @@ -205,6 +208,9 @@ pub trait Context { /// Get the layout shape. fn layout_shape(&self, id: Layout) -> LayoutShape; + + /// Get a debug string representation of a place. + fn place_pretty(&self, place: &Place) -> String; } // A thread local variable that stores a pointer to the tables mapping between TyCtxt diff --git a/compiler/stable_mir/src/lib.rs b/compiler/stable_mir/src/lib.rs index d849c834ae0..d1a2948ea77 100644 --- a/compiler/stable_mir/src/lib.rs +++ b/compiler/stable_mir/src/lib.rs @@ -27,7 +27,6 @@ use crate::compiler_interface::with; pub use crate::crate_def::CrateDef; pub use crate::crate_def::DefId; pub use crate::error::*; -use crate::mir::pretty::function_name; use crate::mir::Body; use crate::mir::Mutability; use crate::ty::{ForeignModuleDef, ImplDef, IndexedVal, Span, TraitDef, Ty}; @@ -148,9 +147,8 @@ impl CrateItem { with(|cx| cx.is_foreign_item(self.0)) } - pub fn dump<W: io::Write>(&self, w: &mut W) -> io::Result<()> { - writeln!(w, "{}", function_name(*self))?; - self.body().dump(w) + pub fn emit_mir<W: io::Write>(&self, w: &mut W) -> io::Result<()> { + self.body().dump(w, &self.name()) } } diff --git a/compiler/stable_mir/src/mir/alloc.rs b/compiler/stable_mir/src/mir/alloc.rs index c780042ff26..66457933438 100644 --- a/compiler/stable_mir/src/mir/alloc.rs +++ b/compiler/stable_mir/src/mir/alloc.rs @@ -57,11 +57,11 @@ pub(crate) fn read_target_uint(mut bytes: &[u8]) -> Result<u128, Error> { let mut buf = [0u8; std::mem::size_of::<u128>()]; match MachineInfo::target_endianess() { Endian::Little => { - bytes.read(&mut buf)?; + bytes.read_exact(&mut buf[..bytes.len()])?; Ok(u128::from_le_bytes(buf)) } Endian::Big => { - bytes.read(&mut buf[16 - bytes.len()..])?; + bytes.read_exact(&mut buf[16 - bytes.len()..])?; Ok(u128::from_be_bytes(buf)) } } @@ -72,11 +72,11 @@ pub(crate) fn read_target_int(mut bytes: &[u8]) -> Result<i128, Error> { let mut buf = [0u8; std::mem::size_of::<i128>()]; match MachineInfo::target_endianess() { Endian::Little => { - bytes.read(&mut buf)?; + bytes.read_exact(&mut buf[..bytes.len()])?; Ok(i128::from_le_bytes(buf)) } Endian::Big => { - bytes.read(&mut buf[16 - bytes.len()..])?; + bytes.read_exact(&mut buf[16 - bytes.len()..])?; Ok(i128::from_be_bytes(buf)) } } diff --git a/compiler/stable_mir/src/mir/body.rs b/compiler/stable_mir/src/mir/body.rs index ae8e71bb950..e4a012d8c47 100644 --- a/compiler/stable_mir/src/mir/body.rs +++ b/compiler/stable_mir/src/mir/body.rs @@ -1,10 +1,11 @@ -use crate::mir::pretty::{function_body, pretty_statement, pretty_terminator}; +use crate::mir::pretty::function_body; use crate::ty::{ AdtDef, ClosureDef, Const, CoroutineDef, GenericArgs, Movability, Region, RigidTy, Ty, TyKind, VariantIdx, }; use crate::{Error, Opaque, Span, Symbol}; use std::io; + /// The SMIR representation of a single function. #[derive(Clone, Debug)] pub struct Body { @@ -90,28 +91,9 @@ impl Body { self.locals.iter().enumerate() } - pub fn dump<W: io::Write>(&self, w: &mut W) -> io::Result<()> { - writeln!(w, "{}", function_body(self))?; - self.blocks - .iter() - .enumerate() - .map(|(index, block)| -> io::Result<()> { - writeln!(w, " bb{}: {{", index)?; - let _ = block - .statements - .iter() - .map(|statement| -> io::Result<()> { - writeln!(w, "{}", pretty_statement(&statement.kind))?; - Ok(()) - }) - .collect::<Vec<_>>(); - pretty_terminator(&block.terminator.kind, w)?; - writeln!(w, "").unwrap(); - writeln!(w, " }}").unwrap(); - Ok(()) - }) - .collect::<Result<Vec<_>, _>>()?; - Ok(()) + /// Emit the body using the provided name for the signature. + pub fn dump<W: io::Write>(&self, w: &mut W, fn_name: &str) -> io::Result<()> { + function_body(w, self, fn_name) } pub fn spread_arg(&self) -> Option<Local> { @@ -674,7 +656,7 @@ pub enum Operand { Constant(Constant), } -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Eq, PartialEq)] pub struct Place { pub local: Local, /// projection out of a place (access a field, deref a pointer, etc) diff --git a/compiler/stable_mir/src/mir/mono.rs b/compiler/stable_mir/src/mir/mono.rs index 38e5776c48c..aafa89c03e0 100644 --- a/compiler/stable_mir/src/mir/mono.rs +++ b/compiler/stable_mir/src/mir/mono.rs @@ -4,6 +4,7 @@ use crate::mir::Body; use crate::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, IndexedVal, Ty}; use crate::{with, CrateItem, DefId, Error, ItemKind, Opaque, Symbol}; use std::fmt::{Debug, Formatter}; +use std::io; #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum MonoItem { @@ -157,6 +158,11 @@ impl Instance { pub fn try_const_eval(&self, const_ty: Ty) -> Result<Allocation, Error> { with(|cx| cx.eval_instance(self.def, const_ty)) } + + /// Emit the body of this instance if it has one. + pub fn emit_mir<W: io::Write>(&self, w: &mut W) -> io::Result<()> { + if let Some(body) = self.body() { body.dump(w, &self.name()) } else { Ok(()) } + } } impl Debug for Instance { diff --git a/compiler/stable_mir/src/mir/pretty.rs b/compiler/stable_mir/src/mir/pretty.rs index 8b7b488d312..4ac4833add7 100644 --- a/compiler/stable_mir/src/mir/pretty.rs +++ b/compiler/stable_mir/src/mir/pretty.rs @@ -1,185 +1,193 @@ -use crate::crate_def::CrateDef; -use crate::mir::{Operand, Rvalue, StatementKind, UnwindAction}; -use crate::ty::{DynKind, FloatTy, IntTy, RigidTy, TyKind, UintTy}; -use crate::{with, Body, CrateItem, Mutability}; +use crate::mir::{Operand, Place, Rvalue, StatementKind, UnwindAction, VarDebugInfoContents}; +use crate::ty::{Const, IndexedVal, Ty}; +use crate::{with, Body, Mutability}; +use fmt::{Display, Formatter}; +use std::fmt::Debug; use std::io::Write; -use std::{io, iter}; +use std::{fmt, io, iter}; use super::{AssertMessage, BinOp, TerminatorKind}; -pub fn function_name(item: CrateItem) -> String { - let mut pretty_name = String::new(); - let body = item.body(); - pretty_name.push_str("fn "); - pretty_name.push_str(item.name().as_str()); - if body.arg_locals().is_empty() { - pretty_name.push_str("()"); - } else { - pretty_name.push_str("("); - } - body.arg_locals().iter().enumerate().for_each(|(index, local)| { - pretty_name.push_str(format!("_{}: ", index).as_str()); - pretty_name.push_str(&pretty_ty(local.ty.kind())); - }); - if !body.arg_locals().is_empty() { - pretty_name.push_str(")"); +use super::BorrowKind; + +impl Display for Ty { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + with(|ctx| write!(f, "{}", ctx.ty_pretty(*self))) } - let return_local = body.ret_local(); - pretty_name.push_str(" -> "); - pretty_name.push_str(&pretty_ty(return_local.ty.kind())); - pretty_name.push_str(" {"); - pretty_name } -pub fn function_body(body: &Body) -> String { - let mut pretty_body = String::new(); - body.inner_locals().iter().enumerate().for_each(|(index, local)| { - pretty_body.push_str(" "); - pretty_body.push_str(format!("let {}", ret_mutability(&local.mutability)).as_str()); - pretty_body.push_str(format!("_{}: ", index).as_str()); - pretty_body.push_str(format!("{}", pretty_ty(local.ty.kind())).as_str()); - pretty_body.push_str(";\n"); - }); - pretty_body.push_str("}"); - pretty_body +impl Debug for Place { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + with(|ctx| write!(f, "{}", ctx.place_pretty(self))) + } } -pub fn ret_mutability(mutability: &Mutability) -> String { - match mutability { - Mutability::Not => "".to_string(), - Mutability::Mut => "mut ".to_string(), - } +pub(crate) fn function_body<W: Write>(writer: &mut W, body: &Body, name: &str) -> io::Result<()> { + write!(writer, "fn {}(", name)?; + body.arg_locals() + .iter() + .enumerate() + .try_for_each(|(index, local)| write!(writer, "_{}: {}", index + 1, local.ty))?; + write!(writer, ")")?; + + let return_local = body.ret_local(); + writeln!(writer, " -> {} {{", return_local.ty)?; + + body.locals().iter().enumerate().try_for_each(|(index, local)| -> io::Result<()> { + if index == 0 || index > body.arg_count { + writeln!(writer, " let {}_{}: {};", pretty_mut(local.mutability), index, local.ty) + } else { + Ok(()) + } + })?; + + body.var_debug_info.iter().try_for_each(|info| { + let content = match &info.value { + VarDebugInfoContents::Place(place) => { + format!("{place:?}") + } + VarDebugInfoContents::Const(constant) => pretty_const(&constant.const_), + }; + writeln!(writer, " debug {} => {};", info.name, content) + })?; + + body.blocks + .iter() + .enumerate() + .map(|(index, block)| -> io::Result<()> { + writeln!(writer, " bb{}: {{", index)?; + let _ = block + .statements + .iter() + .map(|statement| -> io::Result<()> { + pretty_statement(writer, &statement.kind)?; + Ok(()) + }) + .collect::<Vec<_>>(); + pretty_terminator(writer, &block.terminator.kind)?; + writeln!(writer, " }}").unwrap(); + Ok(()) + }) + .collect::<Result<Vec<_>, _>>()?; + writeln!(writer, "}}")?; + Ok(()) } -pub fn pretty_statement(statement: &StatementKind) -> String { - let mut pretty = String::new(); +fn pretty_statement<W: Write>(writer: &mut W, statement: &StatementKind) -> io::Result<()> { match statement { StatementKind::Assign(place, rval) => { - pretty.push_str(format!(" _{} = ", place.local).as_str()); - pretty.push_str(format!("{}", &pretty_rvalue(rval)).as_str()); + write!(writer, " {:?} = ", place)?; + pretty_rvalue(writer, rval)?; + writeln!(writer, ";") } // FIXME: Add rest of the statements - StatementKind::FakeRead(_, _) => { - return String::from("StatementKind::FakeRead:Unimplemented"); + StatementKind::FakeRead(cause, place) => { + writeln!(writer, "FakeRead({cause:?}, {place:?});") } - StatementKind::SetDiscriminant { .. } => { - return String::from("StatementKind::SetDiscriminant:Unimplemented"); + StatementKind::SetDiscriminant { place, variant_index } => { + writeln!(writer, "discriminant({place:?} = {};", variant_index.to_index()) } - StatementKind::Deinit(_) => return String::from("StatementKind::Deinit:Unimplemented"), - StatementKind::StorageLive(_) => { - return String::from("StatementKind::StorageLive:Unimplemented"); + StatementKind::Deinit(place) => writeln!(writer, "Deinit({place:?};"), + StatementKind::StorageLive(local) => { + writeln!(writer, "StorageLive(_{local});") } - StatementKind::StorageDead(_) => { - return String::from("StatementKind::StorageDead:Unimplemented"); + StatementKind::StorageDead(local) => { + writeln!(writer, "StorageDead(_{local});") } - StatementKind::Retag(_, _) => return String::from("StatementKind::Retag:Unimplemented"), - StatementKind::PlaceMention(_) => { - return String::from("StatementKind::PlaceMention:Unimplemented"); - } - StatementKind::AscribeUserType { .. } => { - return String::from("StatementKind::AscribeUserType:Unimplemented"); - } - StatementKind::Coverage(_) => return String::from("StatementKind::Coverage:Unimplemented"), - StatementKind::Intrinsic(_) => { - return String::from("StatementKind::Intrinsic:Unimplemented"); + StatementKind::Retag(kind, place) => writeln!(writer, "Retag({kind:?}, {place:?});"), + StatementKind::PlaceMention(place) => { + writeln!(writer, "PlaceMention({place:?};") } StatementKind::ConstEvalCounter => { - return String::from("StatementKind::ConstEvalCounter:Unimplemented"); + writeln!(writer, "ConstEvalCounter;") + } + StatementKind::Nop => writeln!(writer, "nop;"), + StatementKind::AscribeUserType { .. } + | StatementKind::Coverage(_) + | StatementKind::Intrinsic(_) => { + // FIX-ME: Make them pretty. + writeln!(writer, "{statement:?};") } - StatementKind::Nop => return String::from("StatementKind::Nop:Unimplemented"), } - pretty } -pub fn pretty_terminator<W: io::Write>(terminator: &TerminatorKind, w: &mut W) -> io::Result<()> { - write!(w, "{}", pretty_terminator_head(terminator))?; +fn pretty_terminator<W: Write>(writer: &mut W, terminator: &TerminatorKind) -> io::Result<()> { + pretty_terminator_head(writer, terminator)?; let successors = terminator.successors(); let successor_count = successors.len(); let labels = pretty_successor_labels(terminator); let show_unwind = !matches!(terminator.unwind(), None | Some(UnwindAction::Cleanup(_))); - let fmt_unwind = |fmt: &mut dyn Write| -> io::Result<()> { - write!(fmt, "unwind ")?; + let fmt_unwind = |w: &mut W| -> io::Result<()> { + write!(w, "unwind ")?; match terminator.unwind() { None | Some(UnwindAction::Cleanup(_)) => unreachable!(), - Some(UnwindAction::Continue) => write!(fmt, "continue"), - Some(UnwindAction::Unreachable) => write!(fmt, "unreachable"), - Some(UnwindAction::Terminate) => write!(fmt, "terminate"), + Some(UnwindAction::Continue) => write!(w, "continue"), + Some(UnwindAction::Unreachable) => write!(w, "unreachable"), + Some(UnwindAction::Terminate) => write!(w, "terminate"), } }; match (successor_count, show_unwind) { - (0, false) => Ok(()), + (0, false) => {} (0, true) => { - write!(w, " -> ")?; - fmt_unwind(w)?; - Ok(()) - } - (1, false) => { - write!(w, " -> {:?}", successors[0])?; - Ok(()) + write!(writer, " -> ")?; + fmt_unwind(writer)?; } + (1, false) => write!(writer, " -> bb{:?}", successors[0])?, _ => { - write!(w, " -> [")?; + write!(writer, " -> [")?; for (i, target) in successors.iter().enumerate() { if i > 0 { - write!(w, ", ")?; + write!(writer, ", ")?; } - write!(w, "{}: bb{:?}", labels[i], target)?; + write!(writer, "{}: bb{:?}", labels[i], target)?; } if show_unwind { - write!(w, ", ")?; - fmt_unwind(w)?; + write!(writer, ", ")?; + fmt_unwind(writer)?; } - write!(w, "]") + write!(writer, "]")?; } - }?; + }; - Ok(()) + writeln!(writer, ";") } -pub fn pretty_terminator_head(terminator: &TerminatorKind) -> String { +fn pretty_terminator_head<W: Write>(writer: &mut W, terminator: &TerminatorKind) -> io::Result<()> { use self::TerminatorKind::*; - let mut pretty = String::new(); + const INDENT: &'static str = " "; match terminator { - Goto { .. } => format!(" goto"), + Goto { .. } => write!(writer, "{INDENT}goto"), SwitchInt { discr, .. } => { - format!(" switchInt(_{})", pretty_operand(discr)) + write!(writer, "{INDENT}switchInt({})", pretty_operand(discr)) } - Resume => format!(" resume"), - Abort => format!(" abort"), - Return => format!(" return"), - Unreachable => format!(" unreachable"), - Drop { place, .. } => format!(" drop(_{:?})", place.local), + Resume => write!(writer, "{INDENT}resume"), + Abort => write!(writer, "{INDENT}abort"), + Return => write!(writer, "{INDENT}return"), + Unreachable => write!(writer, "{INDENT}unreachable"), + Drop { place, .. } => write!(writer, "{INDENT}drop({:?})", place), Call { func, args, destination, .. } => { - pretty.push_str(" "); - pretty.push_str(format!("_{} = ", destination.local).as_str()); - pretty.push_str(&pretty_operand(func)); - pretty.push_str("("); - args.iter().enumerate().for_each(|(i, arg)| { - if i > 0 { - pretty.push_str(", "); - } - pretty.push_str(&pretty_operand(arg)); - }); - pretty.push_str(")"); - pretty + write!(writer, "{INDENT}{:?} = {}(", destination, pretty_operand(func))?; + let mut args_iter = args.iter(); + args_iter.next().map_or(Ok(()), |arg| write!(writer, "{}", pretty_operand(arg)))?; + args_iter.try_for_each(|arg| write!(writer, ", {}", pretty_operand(arg)))?; + write!(writer, ")") } Assert { cond, expected, msg, target: _, unwind: _ } => { - pretty.push_str(" assert("); + write!(writer, "{INDENT}assert(")?; if !expected { - pretty.push_str("!"); + write!(writer, "!")?; } - pretty.push_str(format!("{} bool),", &pretty_operand(cond)).as_str()); - pretty.push_str(&pretty_assert_message(msg)); - pretty.push_str(")"); - pretty + write!(writer, "{}, ", &pretty_operand(cond))?; + pretty_assert_message(writer, msg)?; + write!(writer, ")") } - InlineAsm { .. } => todo!(), + InlineAsm { .. } => write!(writer, "{INDENT}InlineAsm"), } } -pub fn pretty_successor_labels(terminator: &TerminatorKind) -> Vec<String> { +fn pretty_successor_labels(terminator: &TerminatorKind) -> Vec<String> { use self::TerminatorKind::*; match terminator { Resume | Abort | Return | Unreachable => vec![], @@ -201,283 +209,174 @@ pub fn pretty_successor_labels(terminator: &TerminatorKind) -> Vec<String> { vec!["success".into(), "unwind".into()] } Assert { unwind: _, .. } => vec!["success".into()], - InlineAsm { .. } => todo!(), + InlineAsm { destination: Some(_), .. } => vec!["goto".into(), "unwind".into()], + InlineAsm { destination: None, .. } => vec!["unwind".into()], } } -pub fn pretty_assert_message(msg: &AssertMessage) -> String { - let mut pretty = String::new(); +fn pretty_assert_message<W: Write>(writer: &mut W, msg: &AssertMessage) -> io::Result<()> { match msg { AssertMessage::BoundsCheck { len, index } => { let pretty_len = pretty_operand(len); let pretty_index = pretty_operand(index); - pretty.push_str(format!("\"index out of bounds: the length is {{}} but the index is {{}}\", {pretty_len}, {pretty_index}").as_str()); - pretty + write!( + writer, + "\"index out of bounds: the length is {{}} but the index is {{}}\", {pretty_len}, {pretty_index}" + ) } AssertMessage::Overflow(BinOp::Add, l, r) => { let pretty_l = pretty_operand(l); let pretty_r = pretty_operand(r); - pretty.push_str(format!("\"attempt to compute `{{}} + {{}}`, which would overflow\", {pretty_l}, {pretty_r}").as_str()); - pretty + write!( + writer, + "\"attempt to compute `{{}} + {{}}`, which would overflow\", {pretty_l}, {pretty_r}" + ) } AssertMessage::Overflow(BinOp::Sub, l, r) => { let pretty_l = pretty_operand(l); let pretty_r = pretty_operand(r); - pretty.push_str(format!("\"attempt to compute `{{}} - {{}}`, which would overflow\", {pretty_l}, {pretty_r}").as_str()); - pretty + write!( + writer, + "\"attempt to compute `{{}} - {{}}`, which would overflow\", {pretty_l}, {pretty_r}" + ) } AssertMessage::Overflow(BinOp::Mul, l, r) => { let pretty_l = pretty_operand(l); let pretty_r = pretty_operand(r); - pretty.push_str(format!("\"attempt to compute `{{}} * {{}}`, which would overflow\", {pretty_l}, {pretty_r}").as_str()); - pretty + write!( + writer, + "\"attempt to compute `{{}} * {{}}`, which would overflow\", {pretty_l}, {pretty_r}" + ) } AssertMessage::Overflow(BinOp::Div, l, r) => { let pretty_l = pretty_operand(l); let pretty_r = pretty_operand(r); - pretty.push_str(format!("\"attempt to compute `{{}} / {{}}`, which would overflow\", {pretty_l}, {pretty_r}").as_str()); - pretty + write!( + writer, + "\"attempt to compute `{{}} / {{}}`, which would overflow\", {pretty_l}, {pretty_r}" + ) } AssertMessage::Overflow(BinOp::Rem, l, r) => { let pretty_l = pretty_operand(l); let pretty_r = pretty_operand(r); - pretty.push_str(format!("\"attempt to compute `{{}} % {{}}`, which would overflow\", {pretty_l}, {pretty_r}").as_str()); - pretty + write!( + writer, + "\"attempt to compute `{{}} % {{}}`, which would overflow\", {pretty_l}, {pretty_r}" + ) } AssertMessage::Overflow(BinOp::Shr, _, r) => { let pretty_r = pretty_operand(r); - pretty.push_str( - format!("\"attempt to shift right by `{{}}`, which would overflow\", {pretty_r}") - .as_str(), - ); - pretty + write!(writer, "\"attempt to shift right by `{{}}`, which would overflow\", {pretty_r}") } AssertMessage::Overflow(BinOp::Shl, _, r) => { let pretty_r = pretty_operand(r); - pretty.push_str( - format!("\"attempt to shift left by `{{}}`, which would overflow\", {pretty_r}") - .as_str(), - ); - pretty + write!(writer, "\"attempt to shift left by `{{}}`, which would overflow\", {pretty_r}") } AssertMessage::Overflow(op, _, _) => unreachable!("`{:?}` cannot overflow", op), AssertMessage::OverflowNeg(op) => { let pretty_op = pretty_operand(op); - pretty.push_str( - format!("\"attempt to negate `{{}}`, which would overflow\", {pretty_op}").as_str(), - ); - pretty + write!(writer, "\"attempt to negate `{{}}`, which would overflow\", {pretty_op}") } AssertMessage::DivisionByZero(op) => { let pretty_op = pretty_operand(op); - pretty.push_str(format!("\"attempt to divide `{{}}` by zero\", {pretty_op}").as_str()); - pretty + write!(writer, "\"attempt to divide `{{}}` by zero\", {pretty_op}") } AssertMessage::RemainderByZero(op) => { let pretty_op = pretty_operand(op); - pretty.push_str( - format!("\"attempt to calculate the remainder of `{{}}` with a divisor of zero\", {pretty_op}").as_str(), - ); - pretty + write!( + writer, + "\"attempt to calculate the remainder of `{{}}` with a divisor of zero\", {pretty_op}" + ) } AssertMessage::MisalignedPointerDereference { required, found } => { let pretty_required = pretty_operand(required); let pretty_found = pretty_operand(found); - pretty.push_str(format!("\"misaligned pointer dereference: address must be a multiple of {{}} but is {{}}\",{pretty_required}, {pretty_found}").as_str()); - pretty + write!( + writer, + "\"misaligned pointer dereference: address must be a multiple of {{}} but is {{}}\",{pretty_required}, {pretty_found}" + ) } AssertMessage::ResumedAfterReturn(_) | AssertMessage::ResumedAfterPanic(_) => { - msg.description().unwrap().to_string() + write!(writer, "{}", msg.description().unwrap()) } } } -pub fn pretty_operand(operand: &Operand) -> String { - let mut pretty = String::new(); +fn pretty_operand(operand: &Operand) -> String { match operand { Operand::Copy(copy) => { - pretty.push_str(""); - pretty.push_str(format!("{}", copy.local).as_str()); + format!("{:?}", copy) } Operand::Move(mv) => { - pretty.push_str("move "); - pretty.push_str(format!("_{}", mv.local).as_str()); - } - Operand::Constant(cnst) => { - pretty.push_str("const "); - pretty.push_str(with(|cx| cx.const_literal(&cnst.literal)).as_str()); + format!("move {:?}", mv) } + Operand::Constant(cnst) => pretty_const(&cnst.literal), } - pretty } -pub fn pretty_rvalue(rval: &Rvalue) -> String { - let mut pretty = String::new(); +fn pretty_const(literal: &Const) -> String { + with(|cx| cx.const_pretty(&literal)) +} + +fn pretty_rvalue<W: Write>(writer: &mut W, rval: &Rvalue) -> io::Result<()> { match rval { - Rvalue::AddressOf(muta, addr) => { - pretty.push_str("&raw "); - pretty.push_str(&ret_mutability(muta)); - pretty.push_str(format!("(*_{})", addr.local).as_str()); - } - Rvalue::Aggregate(aggregatekind, operands) => { - pretty.push_str(format!("{:#?}", aggregatekind).as_str()); - pretty.push_str("("); - operands.iter().enumerate().for_each(|(i, op)| { - pretty.push_str(&pretty_operand(op)); - if i != operands.len() - 1 { - pretty.push_str(", "); - } - }); - pretty.push_str(")"); + Rvalue::AddressOf(mutability, place) => { + write!(writer, "&raw {}(*{:?})", &pretty_mut(*mutability), place) } - Rvalue::BinaryOp(bin, op, op2) => { - pretty.push_str(&pretty_operand(op)); - pretty.push_str(" "); - pretty.push_str(format!("{:#?}", bin).as_str()); - pretty.push_str(" "); - pretty.push_str(&pretty_operand(op2)); + Rvalue::Aggregate(aggregate_kind, operands) => { + // FIXME: Add pretty_aggregate function that returns a pretty string + write!(writer, "{aggregate_kind:?} (")?; + let mut op_iter = operands.iter(); + op_iter.next().map_or(Ok(()), |op| write!(writer, "{}", pretty_operand(op)))?; + op_iter.try_for_each(|op| write!(writer, ", {}", pretty_operand(op)))?; + write!(writer, ")") + } + Rvalue::BinaryOp(bin, op1, op2) => { + write!(writer, "{:?}({}, {})", bin, &pretty_operand(op1), pretty_operand(op2)) } Rvalue::Cast(_, op, ty) => { - pretty.push_str(&pretty_operand(op)); - pretty.push_str(" as "); - pretty.push_str(&pretty_ty(ty.kind())); + write!(writer, "{} as {}", pretty_operand(op), ty) } Rvalue::CheckedBinaryOp(bin, op1, op2) => { - pretty.push_str(&pretty_operand(op1)); - pretty.push_str(" "); - pretty.push_str(format!("{:#?}", bin).as_str()); - pretty.push_str(" "); - pretty.push_str(&pretty_operand(op2)); + write!(writer, "Checked{:?}({}, {})", bin, &pretty_operand(op1), pretty_operand(op2)) } Rvalue::CopyForDeref(deref) => { - pretty.push_str("CopyForDeref"); - pretty.push_str(format!("{}", deref.local).as_str()); + write!(writer, "CopyForDeref({:?})", deref) } Rvalue::Discriminant(place) => { - pretty.push_str("discriminant"); - pretty.push_str(format!("{}", place.local).as_str()); + write!(writer, "discriminant({:?})", place) } Rvalue::Len(len) => { - pretty.push_str("len"); - pretty.push_str(format!("{}", len.local).as_str()); + write!(writer, "len({:?})", len) } Rvalue::Ref(_, borrowkind, place) => { - pretty.push_str("ref"); - pretty.push_str(format!("{:#?}", borrowkind).as_str()); - pretty.push_str(format!("{}", place.local).as_str()); + let kind = match borrowkind { + BorrowKind::Shared => "&", + BorrowKind::Fake => "&fake ", + BorrowKind::Mut { .. } => "&mut ", + }; + write!(writer, "{kind}{:?}", place) } Rvalue::Repeat(op, cnst) => { - pretty.push_str(&pretty_operand(op)); - pretty.push_str(" "); - pretty.push_str(&pretty_ty(cnst.ty().kind())); + write!(writer, "{} \" \" {}", &pretty_operand(op), cnst.ty()) } - Rvalue::ShallowInitBox(_, _) => (), + Rvalue::ShallowInitBox(_, _) => Ok(()), Rvalue::ThreadLocalRef(item) => { - pretty.push_str("thread_local_ref"); - pretty.push_str(format!("{:#?}", item).as_str()); + write!(writer, "thread_local_ref{:?}", item) } Rvalue::NullaryOp(nul, ty) => { - pretty.push_str(format!("{:#?}", nul).as_str()); - pretty.push_str(&pretty_ty(ty.kind())); - pretty.push_str(" "); + write!(writer, "{:?} {} \" \"", nul, ty) } Rvalue::UnaryOp(un, op) => { - pretty.push_str(&pretty_operand(op)); - pretty.push_str(" "); - pretty.push_str(format!("{:#?}", un).as_str()); + write!(writer, "{} \" \" {:?}", pretty_operand(op), un) } - Rvalue::Use(op) => pretty.push_str(&pretty_operand(op)), + Rvalue::Use(op) => write!(writer, "{}", pretty_operand(op)), } - pretty } -pub fn pretty_ty(ty: TyKind) -> String { - let mut pretty = String::new(); - match ty { - TyKind::RigidTy(rigid_ty) => match rigid_ty { - RigidTy::Bool => "bool".to_string(), - RigidTy::Char => "char".to_string(), - RigidTy::Int(i) => match i { - IntTy::Isize => "isize".to_string(), - IntTy::I8 => "i8".to_string(), - IntTy::I16 => "i16".to_string(), - IntTy::I32 => "i32".to_string(), - IntTy::I64 => "i64".to_string(), - IntTy::I128 => "i128".to_string(), - }, - RigidTy::Uint(u) => match u { - UintTy::Usize => "usize".to_string(), - UintTy::U8 => "u8".to_string(), - UintTy::U16 => "u16".to_string(), - UintTy::U32 => "u32".to_string(), - UintTy::U64 => "u64".to_string(), - UintTy::U128 => "u128".to_string(), - }, - RigidTy::Float(f) => match f { - FloatTy::F32 => "f32".to_string(), - FloatTy::F64 => "f64".to_string(), - }, - RigidTy::Adt(def, _) => { - format!("{:#?}", with(|cx| cx.def_ty(def.0))) - } - RigidTy::Str => "str".to_string(), - RigidTy::Array(ty, len) => { - format!("[{}; {}]", pretty_ty(ty.kind()), with(|cx| cx.const_literal(&len))) - } - RigidTy::Slice(ty) => { - format!("[{}]", pretty_ty(ty.kind())) - } - RigidTy::RawPtr(ty, mutability) => { - pretty.push_str("*"); - match mutability { - Mutability::Not => pretty.push_str("const "), - Mutability::Mut => pretty.push_str("mut "), - } - pretty.push_str(&pretty_ty(ty.kind())); - pretty - } - RigidTy::Ref(_, ty, mutability) => match mutability { - Mutability::Not => format!("&{}", pretty_ty(ty.kind())), - Mutability::Mut => format!("&mut {}", pretty_ty(ty.kind())), - }, - RigidTy::FnDef(_, _) => format!("{:#?}", rigid_ty), - RigidTy::FnPtr(_) => format!("{:#?}", rigid_ty), - RigidTy::Closure(_, _) => format!("{:#?}", rigid_ty), - RigidTy::Coroutine(_, _, _) => format!("{:#?}", rigid_ty), - RigidTy::Dynamic(data, region, repr) => { - // FIXME: Fix binder printing, it looks ugly now - pretty.push_str("("); - match repr { - DynKind::Dyn => pretty.push_str("dyn "), - DynKind::DynStar => pretty.push_str("dyn* "), - } - pretty.push_str(format!("{:#?}", data).as_str()); - pretty.push_str(format!(" + {:#?} )", region).as_str()); - pretty - } - RigidTy::Never => "!".to_string(), - RigidTy::Tuple(tuple) => { - if tuple.is_empty() { - "()".to_string() - } else { - let mut tuple_str = String::new(); - tuple_str.push_str("("); - tuple.iter().enumerate().for_each(|(i, ty)| { - tuple_str.push_str(&pretty_ty(ty.kind())); - if i != tuple.len() - 1 { - tuple_str.push_str(", "); - } - }); - tuple_str.push_str(")"); - tuple_str - } - } - _ => format!("{:#?}", rigid_ty), - }, - TyKind::Alias(_, _) => format!("{:#?}", ty), - TyKind::Param(param_ty) => { - format!("{:#?}", param_ty.name) - } - TyKind::Bound(_, _) => format!("{:#?}", ty), +fn pretty_mut(mutability: Mutability) -> &'static str { + match mutability { + Mutability::Not => " ", + Mutability::Mut => "mut ", } } diff --git a/config.example.toml b/config.example.toml index f94553dd63f..b8cdc2ec848 100644 --- a/config.example.toml +++ b/config.example.toml @@ -915,6 +915,6 @@ # Available options: fast, balanced, best #compression-profile = "fast" -# Copy the linker, DLLs, and various libraries from MinGW into the rustc toolchain. +# Copy the linker, DLLs, and various libraries from MinGW into the Rust toolchain. # Only applies when the host or target is pc-windows-gnu. #include-mingw-linker = true diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index a5d28aa5252..6677534eafc 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -51,7 +51,7 @@ extern "Rust" { #[derive(Copy, Clone, Default, Debug)] #[cfg(not(test))] // the compiler needs to know when a Box uses the global allocator vs a custom one -#[cfg_attr(not(bootstrap), lang = "global_alloc_ty")] +#[lang = "global_alloc_ty"] pub struct Global; #[cfg(test)] @@ -387,8 +387,7 @@ pub const fn handle_alloc_error(layout: Layout) -> ! { } #[cfg(not(feature = "panic_immediate_abort"))] - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - unsafe { + { core::intrinsics::const_eval_select((layout,), ct_error, rt_error) } diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 304f607000b..cfaf533088a 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -155,7 +155,6 @@ use core::error::Error; use core::fmt; use core::future::Future; use core::hash::{Hash, Hasher}; -use core::intrinsics::retag_box_to_raw; use core::iter::FusedIterator; use core::marker::Tuple; use core::marker::Unsize; @@ -165,7 +164,7 @@ use core::ops::{ CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut, DispatchFromDyn, Receiver, }; use core::pin::Pin; -use core::ptr::{self, NonNull, Unique}; +use core::ptr::{self, addr_of_mut, NonNull, Unique}; use core::task::{Context, Poll}; #[cfg(not(no_global_oom_handling))] @@ -1111,16 +1110,12 @@ impl<T: ?Sized, A: Allocator> Box<T, A> { #[unstable(feature = "allocator_api", issue = "32838")] #[inline] pub fn into_raw_with_allocator(b: Self) -> (*mut T, A) { - // This is the transition point from `Box` to raw pointers. For Stacked Borrows, these casts - // are relevant -- if this is a global allocator Box and we just get the pointer from `b.0`, - // it will have `Unique` permission, which is not what we want from a raw pointer. We could - // fix that by going through `&mut`, but then if this is *not* a global allocator Box, we'd - // be adding uniqueness assertions that we do not want. So for Miri's sake we pass this - // pointer through an intrinsic for box-to-raw casts, which can do the right thing wrt the - // aliasing model. - let b = mem::ManuallyDrop::new(b); + let mut b = mem::ManuallyDrop::new(b); + // We carefully get the raw pointer out in a way that Miri's aliasing model understands what + // is happening: using the primitive "deref" of `Box`. + let ptr = addr_of_mut!(**b); let alloc = unsafe { ptr::read(&b.1) }; - (unsafe { retag_box_to_raw::<T, A>(b.0.as_ptr()) }, alloc) + (ptr, alloc) } #[unstable( @@ -2047,18 +2042,16 @@ impl<Args: Tuple, F: AsyncFnOnce<Args> + ?Sized, A: Allocator> AsyncFnOnce<Args> #[unstable(feature = "async_fn_traits", issue = "none")] impl<Args: Tuple, F: AsyncFnMut<Args> + ?Sized, A: Allocator> AsyncFnMut<Args> for Box<F, A> { - type CallMutFuture<'a> = F::CallMutFuture<'a> where Self: 'a; + type CallRefFuture<'a> = F::CallRefFuture<'a> where Self: 'a; - extern "rust-call" fn async_call_mut(&mut self, args: Args) -> Self::CallMutFuture<'_> { + extern "rust-call" fn async_call_mut(&mut self, args: Args) -> Self::CallRefFuture<'_> { F::async_call_mut(self, args) } } #[unstable(feature = "async_fn_traits", issue = "none")] impl<Args: Tuple, F: AsyncFn<Args> + ?Sized, A: Allocator> AsyncFn<Args> for Box<F, A> { - type CallFuture<'a> = F::CallFuture<'a> where Self: 'a; - - extern "rust-call" fn async_call(&self, args: Args) -> Self::CallFuture<'_> { + extern "rust-call" fn async_call(&self, args: Args) -> Self::CallRefFuture<'_> { F::async_call(self, args) } } diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index e99c6220e20..3875f61efaf 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -72,7 +72,7 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT; /// `BTreeMap` that observed the logic error and not result in undefined behavior. This could /// include panics, incorrect results, aborts, memory leaks, and non-termination. /// -/// Iterators obtained from functions such as [`BTreeMap::iter`], [`BTreeMap::values`], or +/// Iterators obtained from functions such as [`BTreeMap::iter`], [`BTreeMap::into_iter`], [`BTreeMap::values`], or /// [`BTreeMap::keys`] produce their items in order by key, and take worst-case logarithmic and /// amortized constant time per item returned. /// @@ -415,7 +415,7 @@ impl<'a, K: 'a, V: 'a> Default for IterMut<'a, K, V> { } } -/// An owning iterator over the entries of a `BTreeMap`. +/// An owning iterator over the entries of a `BTreeMap`, sorted by key. /// /// This `struct` is created by the [`into_iter`] method on [`BTreeMap`] /// (provided by the [`IntoIterator`] trait). See its documentation for more. @@ -1637,6 +1637,7 @@ impl<K, V, A: Allocator + Clone> IntoIterator for BTreeMap<K, V, A> { type Item = (K, V); type IntoIter = IntoIter<K, V, A>; + /// Gets an owning iterator over the entries of the map, sorted by key. fn into_iter(self) -> IntoIter<K, V, A> { let mut me = ManuallyDrop::new(self); if let Some(root) = me.root.take() { diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index ed91ae1a66e..7508ae468ae 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -27,7 +27,7 @@ use crate::alloc::{Allocator, Global}; /// `BTreeSet` that observed the logic error and not result in undefined behavior. This could /// include panics, incorrect results, aborts, memory leaks, and non-termination. /// -/// Iterators returned by [`BTreeSet::iter`] produce their items in order, and take worst-case +/// Iterators returned by [`BTreeSet::iter`] and [`BTreeSet::into_iter`] produce their items in order, and take worst-case /// logarithmic and amortized constant time per item returned. /// /// [`Cell`]: core::cell::Cell @@ -140,7 +140,7 @@ impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> { } } -/// An owning iterator over the items of a `BTreeSet`. +/// An owning iterator over the items of a `BTreeSet` in ascending order. /// /// This `struct` is created by the [`into_iter`] method on [`BTreeSet`] /// (provided by the [`IntoIterator`] trait). See its documentation for more. @@ -1237,7 +1237,7 @@ impl<T, A: Allocator + Clone> IntoIterator for BTreeSet<T, A> { type Item = T; type IntoIter = IntoIter<T, A>; - /// Gets an iterator for moving out the `BTreeSet`'s contents. + /// Gets an iterator for moving out the `BTreeSet`'s contents in ascending order. /// /// # Examples /// diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index ca504b05a96..02d155aaf12 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -173,12 +173,12 @@ // // Language features: // tidy-alphabetical-start +#![cfg_attr(bootstrap, feature(associated_type_bounds))] #![cfg_attr(not(test), feature(coroutine_trait))] #![cfg_attr(test, feature(panic_update_hook))] #![cfg_attr(test, feature(test))] #![feature(allocator_internals)] #![feature(allow_internal_unstable)] -#![feature(associated_type_bounds)] #![feature(c_unwind)] #![feature(cfg_sanitize)] #![feature(const_mut_refs)] diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 80f0f2acc99..7e3e2fb38b1 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -233,7 +233,7 @@ macro_rules! acquire { /// let val = Arc::clone(&val); /// /// thread::spawn(move || { -/// let v = val.fetch_add(1, Ordering::SeqCst); +/// let v = val.fetch_add(1, Ordering::Relaxed); /// println!("{v:?}"); /// }); /// } diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index 07eb91c9005..4907a45e881 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -229,96 +229,106 @@ where I: Iterator<Item = T> + InPlaceCollect, <I as SourceIter>::Source: AsVecIntoIter, { - default fn from_iter(mut iterator: I) -> Self { - // See "Layout constraints" section in the module documentation. We rely on const - // optimization here since these conditions currently cannot be expressed as trait bounds - if const { !in_place_collectible::<T, I::Src>(I::MERGE_BY, I::EXPAND_BY) } { - // fallback to more generic implementations - return SpecFromIterNested::from_iter(iterator); - } - - let (src_buf, src_ptr, src_cap, mut dst_buf, dst_end, dst_cap) = unsafe { - let inner = iterator.as_inner().as_into_iter(); - ( - inner.buf.as_ptr(), - inner.ptr, - inner.cap, - inner.buf.as_ptr() as *mut T, - inner.end as *const T, - inner.cap * mem::size_of::<I::Src>() / mem::size_of::<T>(), - ) + default fn from_iter(iterator: I) -> Self { + // Select the implementation in const eval to avoid codegen of the dead branch to improve compile times. + let fun: fn(I) -> Vec<T> = const { + // See "Layout constraints" section in the module documentation. We use const conditions here + // since these conditions currently cannot be expressed as trait bounds + if in_place_collectible::<T, I::Src>(I::MERGE_BY, I::EXPAND_BY) { + from_iter_in_place + } else { + // fallback + SpecFromIterNested::<T, I>::from_iter + } }; - // SAFETY: `dst_buf` and `dst_end` are the start and end of the buffer. - let len = unsafe { SpecInPlaceCollect::collect_in_place(&mut iterator, dst_buf, dst_end) }; + fun(iterator) + } +} - let src = unsafe { iterator.as_inner().as_into_iter() }; - // check if SourceIter contract was upheld - // caveat: if they weren't we might not even make it to this point - debug_assert_eq!(src_buf, src.buf.as_ptr()); - // check InPlaceIterable contract. This is only possible if the iterator advanced the - // source pointer at all. If it uses unchecked access via TrustedRandomAccess - // then the source pointer will stay in its initial position and we can't use it as reference - if src.ptr != src_ptr { - debug_assert!( - unsafe { dst_buf.add(len) as *const _ } <= src.ptr.as_ptr(), - "InPlaceIterable contract violation, write pointer advanced beyond read pointer" - ); - } +fn from_iter_in_place<I, T>(mut iterator: I) -> Vec<T> +where + I: Iterator<Item = T> + InPlaceCollect, + <I as SourceIter>::Source: AsVecIntoIter, +{ + let (src_buf, src_ptr, src_cap, mut dst_buf, dst_end, dst_cap) = unsafe { + let inner = iterator.as_inner().as_into_iter(); + ( + inner.buf.as_ptr(), + inner.ptr, + inner.cap, + inner.buf.as_ptr() as *mut T, + inner.end as *const T, + inner.cap * mem::size_of::<I::Src>() / mem::size_of::<T>(), + ) + }; - // The ownership of the source allocation and the new `T` values is temporarily moved into `dst_guard`. - // This is safe because - // * `forget_allocation_drop_remaining` immediately forgets the allocation - // before any panic can occur in order to avoid any double free, and then proceeds to drop - // any remaining values at the tail of the source. - // * the shrink either panics without invalidating the allocation, aborts or - // succeeds. In the last case we disarm the guard. - // - // Note: This access to the source wouldn't be allowed by the TrustedRandomIteratorNoCoerce - // contract (used by SpecInPlaceCollect below). But see the "O(1) collect" section in the - // module documentation why this is ok anyway. - let dst_guard = - InPlaceDstDataSrcBufDrop { ptr: dst_buf, len, src_cap, src: PhantomData::<I::Src> }; - src.forget_allocation_drop_remaining(); + // SAFETY: `dst_buf` and `dst_end` are the start and end of the buffer. + let len = unsafe { SpecInPlaceCollect::collect_in_place(&mut iterator, dst_buf, dst_end) }; - // Adjust the allocation if the source had a capacity in bytes that wasn't a multiple - // of the destination type size. - // Since the discrepancy should generally be small this should only result in some - // bookkeeping updates and no memmove. - if needs_realloc::<I::Src, T>(src_cap, dst_cap) { - let alloc = Global; - debug_assert_ne!(src_cap, 0); - debug_assert_ne!(dst_cap, 0); - unsafe { - // The old allocation exists, therefore it must have a valid layout. - let src_align = mem::align_of::<I::Src>(); - let src_size = mem::size_of::<I::Src>().unchecked_mul(src_cap); - let old_layout = Layout::from_size_align_unchecked(src_size, src_align); + let src = unsafe { iterator.as_inner().as_into_iter() }; + // check if SourceIter contract was upheld + // caveat: if they weren't we might not even make it to this point + debug_assert_eq!(src_buf, src.buf.as_ptr()); + // check InPlaceIterable contract. This is only possible if the iterator advanced the + // source pointer at all. If it uses unchecked access via TrustedRandomAccess + // then the source pointer will stay in its initial position and we can't use it as reference + if src.ptr != src_ptr { + debug_assert!( + unsafe { dst_buf.add(len) as *const _ } <= src.ptr.as_ptr(), + "InPlaceIterable contract violation, write pointer advanced beyond read pointer" + ); + } - // The allocation must be equal or smaller for in-place iteration to be possible - // therefore the new layout must be ≤ the old one and therefore valid. - let dst_align = mem::align_of::<T>(); - let dst_size = mem::size_of::<T>().unchecked_mul(dst_cap); - let new_layout = Layout::from_size_align_unchecked(dst_size, dst_align); + // The ownership of the source allocation and the new `T` values is temporarily moved into `dst_guard`. + // This is safe because + // * `forget_allocation_drop_remaining` immediately forgets the allocation + // before any panic can occur in order to avoid any double free, and then proceeds to drop + // any remaining values at the tail of the source. + // * the shrink either panics without invalidating the allocation, aborts or + // succeeds. In the last case we disarm the guard. + // + // Note: This access to the source wouldn't be allowed by the TrustedRandomIteratorNoCoerce + // contract (used by SpecInPlaceCollect below). But see the "O(1) collect" section in the + // module documentation why this is ok anyway. + let dst_guard = + InPlaceDstDataSrcBufDrop { ptr: dst_buf, len, src_cap, src: PhantomData::<I::Src> }; + src.forget_allocation_drop_remaining(); - let result = alloc.shrink( - NonNull::new_unchecked(dst_buf as *mut u8), - old_layout, - new_layout, - ); - let Ok(reallocated) = result else { handle_alloc_error(new_layout) }; - dst_buf = reallocated.as_ptr() as *mut T; - } - } else { - debug_assert_eq!(src_cap * mem::size_of::<I::Src>(), dst_cap * mem::size_of::<T>()); + // Adjust the allocation if the source had a capacity in bytes that wasn't a multiple + // of the destination type size. + // Since the discrepancy should generally be small this should only result in some + // bookkeeping updates and no memmove. + if needs_realloc::<I::Src, T>(src_cap, dst_cap) { + let alloc = Global; + debug_assert_ne!(src_cap, 0); + debug_assert_ne!(dst_cap, 0); + unsafe { + // The old allocation exists, therefore it must have a valid layout. + let src_align = mem::align_of::<I::Src>(); + let src_size = mem::size_of::<I::Src>().unchecked_mul(src_cap); + let old_layout = Layout::from_size_align_unchecked(src_size, src_align); + + // The allocation must be equal or smaller for in-place iteration to be possible + // therefore the new layout must be ≤ the old one and therefore valid. + let dst_align = mem::align_of::<T>(); + let dst_size = mem::size_of::<T>().unchecked_mul(dst_cap); + let new_layout = Layout::from_size_align_unchecked(dst_size, dst_align); + + let result = + alloc.shrink(NonNull::new_unchecked(dst_buf as *mut u8), old_layout, new_layout); + let Ok(reallocated) = result else { handle_alloc_error(new_layout) }; + dst_buf = reallocated.as_ptr() as *mut T; } + } else { + debug_assert_eq!(src_cap * mem::size_of::<I::Src>(), dst_cap * mem::size_of::<T>()); + } - mem::forget(dst_guard); + mem::forget(dst_guard); - let vec = unsafe { Vec::from_raw_parts(dst_buf, len, dst_cap) }; + let vec = unsafe { Vec::from_raw_parts(dst_buf, len, dst_cap) }; - vec - } + vec } fn write_in_place_with_drop<T>( diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index f2f42e63d6b..94bed825bb2 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1462,7 +1462,7 @@ impl<T, A: Allocator> Vec<T, A> { /// /// The removed element is replaced by the last element of the vector. /// - /// This does not preserve ordering, but is *O*(1). + /// This does not preserve ordering of the remaining elements, but is *O*(1). /// If you need to preserve the element order, use [`remove`] instead. /// /// [`remove`]: Vec::remove @@ -1541,6 +1541,9 @@ impl<T, A: Allocator> Vec<T, A> { } let len = self.len(); + if index > len { + assert_failed(index, len); + } // space for the new element if len == self.buf.capacity() { @@ -1556,10 +1559,6 @@ impl<T, A: Allocator> Vec<T, A> { // Shift everything over to make space. (Duplicating the // `index`th element into two consecutive places.) ptr::copy(p, p.add(1), len - index); - } else if index == len { - // No elements need shifting. - } else { - assert_failed(index, len); } // Write it in, overwriting the first copy of the `index`th // element. diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index e8496989bcf..f58998fbd79 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -1,3 +1,4 @@ +#![cfg_attr(bootstrap, feature(associated_type_bounds))] #![feature(allocator_api)] #![feature(alloc_layout_extra)] #![feature(iter_array_chunks)] @@ -22,7 +23,6 @@ #![feature(try_reserve_kind)] #![feature(try_with_capacity)] #![feature(unboxed_closures)] -#![feature(associated_type_bounds)] #![feature(binary_heap_into_iter_sorted)] #![feature(binary_heap_drain_sorted)] #![feature(slice_ptr_get)] diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index aa95b4e9770..f1f841fe190 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -2643,3 +2643,44 @@ fn test_vec_from_array_ref() { fn test_vec_from_array_mut_ref() { assert_eq!(Vec::from(&mut [1, 2, 3]), vec![1, 2, 3]); } + +/// This assortment of tests, in combination with miri, verifies we handle UB on fishy arguments +/// in the stdlib. Draining and extending the allocation are fairly well-tested earlier, but +/// `vec.insert(usize::MAX, val)` once slipped by! +/// +/// All code that manipulates the collection types should be tested with "trivially wrong" args. +#[test] +fn max_dont_panic() { + let mut v = vec![0]; + let _ = v.get(usize::MAX); + v.shrink_to(usize::MAX); + v.truncate(usize::MAX); +} + +#[test] +#[should_panic] +fn max_insert() { + let mut v = vec![0]; + v.insert(usize::MAX, 1); +} + +#[test] +#[should_panic] +fn max_remove() { + let mut v = vec![0]; + v.remove(usize::MAX); +} + +#[test] +#[should_panic] +fn max_splice() { + let mut v = vec![0]; + v.splice(usize::MAX.., core::iter::once(1)); +} + +#[test] +#[should_panic] +fn max_swap_remove() { + let mut v = vec![0]; + v.swap_remove(usize::MAX); +} diff --git a/library/core/src/alloc/global.rs b/library/core/src/alloc/global.rs index a1fff6707bd..8df3ace54ff 100644 --- a/library/core/src/alloc/global.rs +++ b/library/core/src/alloc/global.rs @@ -24,10 +24,7 @@ use crate::ptr; /// use std::alloc::{GlobalAlloc, Layout}; /// use std::cell::UnsafeCell; /// use std::ptr::null_mut; -/// use std::sync::atomic::{ -/// AtomicUsize, -/// Ordering::{Acquire, SeqCst}, -/// }; +/// use std::sync::atomic::{AtomicUsize, Ordering::Relaxed}; /// /// const ARENA_SIZE: usize = 128 * 1024; /// const MAX_SUPPORTED_ALIGN: usize = 4096; @@ -61,7 +58,7 @@ use crate::ptr; /// let mut allocated = 0; /// if self /// .remaining -/// .fetch_update(SeqCst, SeqCst, |mut remaining| { +/// .fetch_update(Relaxed, Relaxed, |mut remaining| { /// if size > remaining { /// return None; /// } @@ -81,7 +78,7 @@ use crate::ptr; /// /// fn main() { /// let _s = format!("allocating a string!"); -/// let currently = ALLOCATOR.remaining.load(Acquire); +/// let currently = ALLOCATOR.remaining.load(Relaxed); /// println!("allocated so far: {}", ARENA_SIZE - currently); /// } /// ``` diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index 63fd23ea9a9..432e55e8c9a 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -396,7 +396,7 @@ pub trait AsMut<T: ?Sized> { /// For example, take this code: /// /// ``` -/// # #![cfg_attr(not(bootstrap), allow(non_local_definitions))] +/// # #![allow(non_local_definitions)] /// struct Wrapper<T>(Vec<T>); /// impl<T> From<Wrapper<T>> for Vec<T> { /// fn from(w: Wrapper<T>) -> Vec<T> { diff --git a/library/core/src/default.rs b/library/core/src/default.rs index a1303fcd821..a5075554682 100644 --- a/library/core/src/default.rs +++ b/library/core/src/default.rs @@ -71,6 +71,8 @@ use crate::ascii::Char as AsciiChar; /// /// You cannot use the `#[default]` attribute on non-unit or non-exhaustive variants. /// +/// The `#[default]` attribute was stabilized in Rust 1.62.0. +/// /// ## How can I implement `Default`? /// /// Provide an implementation for the `default()` method that returns the value of diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 30debbffec1..dbdbaccb535 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -438,13 +438,7 @@ impl CStr { unsafe { &*(bytes as *const [u8] as *const CStr) } } - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: The const and runtime versions have identical behavior - // unless the safety contract of `from_bytes_with_nul_unchecked` is - // violated, which is UB. - unsafe { - intrinsics::const_eval_select((bytes,), const_impl, rt_impl) - } + intrinsics::const_eval_select((bytes,), const_impl, rt_impl) } /// Returns the inner pointer to this C string. @@ -759,11 +753,7 @@ const unsafe fn const_strlen(ptr: *const c_char) -> usize { unsafe { strlen(s) } } - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: the two functions always provide equivalent functionality - unsafe { - intrinsics::const_eval_select((ptr,), strlen_ct, strlen_rt) - } + intrinsics::const_eval_select((ptr,), strlen_ct, strlen_rt) } /// An iterator over the bytes of a [`CStr`], without the nul terminator. diff --git a/library/core/src/hash/mod.rs b/library/core/src/hash/mod.rs index bfdd28a7399..ef0793a3e46 100644 --- a/library/core/src/hash/mod.rs +++ b/library/core/src/hash/mod.rs @@ -454,7 +454,7 @@ pub trait Hasher { /// ``` /// #![feature(hasher_prefixfree_extras)] /// # // Stubs to make the `impl` below pass the compiler - /// # #![cfg_attr(not(bootstrap), allow(non_local_definitions))] + /// # #![allow(non_local_definitions)] /// # struct MyCollection<T>(Option<T>); /// # impl<T> MyCollection<T> { /// # fn len(&self) -> usize { todo!() } diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 86b9a39d68a..613d0ab212a 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -84,9 +84,6 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) { unsafe { crate::ptr::drop_in_place(to_drop) } } -#[cfg(bootstrap)] -pub use self::r#try as catch_unwind; - extern "rust-intrinsic" { // N.B., these intrinsics take raw pointers because they mutate aliased // memory, which is not valid for either `&` or `&mut`. @@ -965,8 +962,7 @@ extern "rust-intrinsic" { #[rustc_const_stable(feature = "const_assume", since = "1.77.0")] #[rustc_nounwind] #[unstable(feature = "core_intrinsics", issue = "none")] -#[cfg_attr(not(bootstrap), rustc_intrinsic)] -#[cfg_attr(bootstrap, inline)] +#[rustc_intrinsic] pub const unsafe fn assume(b: bool) { if !b { // SAFETY: the caller must guarantee the argument is never `false` @@ -987,9 +983,8 @@ pub const unsafe fn assume(b: bool) { /// This intrinsic does not have a stable counterpart. #[rustc_const_unstable(feature = "const_likely", issue = "none")] #[unstable(feature = "core_intrinsics", issue = "none")] -#[cfg_attr(not(bootstrap), rustc_intrinsic)] +#[rustc_intrinsic] #[rustc_nounwind] -#[cfg_attr(bootstrap, inline)] pub const fn likely(b: bool) -> bool { b } @@ -1007,9 +1002,8 @@ pub const fn likely(b: bool) -> bool { /// This intrinsic does not have a stable counterpart. #[rustc_const_unstable(feature = "const_likely", issue = "none")] #[unstable(feature = "core_intrinsics", issue = "none")] -#[cfg_attr(not(bootstrap), rustc_intrinsic)] +#[rustc_intrinsic] #[rustc_nounwind] -#[cfg_attr(bootstrap, inline)] pub const fn unlikely(b: bool) -> bool { b } @@ -1919,7 +1913,6 @@ extern "rust-intrinsic" { /// This intrinsic does not have a stable counterpart. #[rustc_nounwind] #[rustc_safe_intrinsic] - #[cfg(not(bootstrap))] pub fn fadd_algebraic<T: Copy>(a: T, b: T) -> T; /// Float subtraction that allows optimizations based on algebraic rules. @@ -1927,7 +1920,6 @@ extern "rust-intrinsic" { /// This intrinsic does not have a stable counterpart. #[rustc_nounwind] #[rustc_safe_intrinsic] - #[cfg(not(bootstrap))] pub fn fsub_algebraic<T: Copy>(a: T, b: T) -> T; /// Float multiplication that allows optimizations based on algebraic rules. @@ -1935,7 +1927,6 @@ extern "rust-intrinsic" { /// This intrinsic does not have a stable counterpart. #[rustc_nounwind] #[rustc_safe_intrinsic] - #[cfg(not(bootstrap))] pub fn fmul_algebraic<T: Copy>(a: T, b: T) -> T; /// Float division that allows optimizations based on algebraic rules. @@ -1943,7 +1934,6 @@ extern "rust-intrinsic" { /// This intrinsic does not have a stable counterpart. #[rustc_nounwind] #[rustc_safe_intrinsic] - #[cfg(not(bootstrap))] pub fn fdiv_algebraic<T: Copy>(a: T, b: T) -> T; /// Float remainder that allows optimizations based on algebraic rules. @@ -1951,7 +1941,6 @@ extern "rust-intrinsic" { /// This intrinsic does not have a stable counterpart. #[rustc_nounwind] #[rustc_safe_intrinsic] - #[cfg(not(bootstrap))] pub fn frem_algebraic<T: Copy>(a: T, b: T) -> T; /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range @@ -2407,14 +2396,8 @@ extern "rust-intrinsic" { /// /// The stable version of this intrinsic is `std::panic::catch_unwind`. #[rustc_nounwind] - #[cfg(not(bootstrap))] pub fn catch_unwind(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32; - /// For bootstrap only, see `catch_unwind`. - #[rustc_nounwind] - #[cfg(bootstrap)] - pub fn r#try(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32; - /// Emits a `!nontemporal` store according to LLVM (see their docs). /// Probably will never become stable. /// @@ -2434,20 +2417,29 @@ extern "rust-intrinsic" { #[rustc_nounwind] pub fn ptr_offset_from_unsigned<T>(ptr: *const T, base: *const T) -> usize; - /// See documentation of `<*const T>::guaranteed_eq` for details. - /// Returns `2` if the result is unknown. - /// Returns `1` if the pointers are guaranteed equal - /// Returns `0` if the pointers are guaranteed inequal - /// - /// Note that, unlike most intrinsics, this is safe to call; - /// it does not require an `unsafe` block. - /// Therefore, implementations must not require the user to uphold - /// any safety invariants. #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")] #[rustc_safe_intrinsic] #[rustc_nounwind] + #[cfg(bootstrap)] pub fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8; +} + +/// See documentation of `<*const T>::guaranteed_eq` for details. +/// Returns `2` if the result is unknown. +/// Returns `1` if the pointers are guaranteed equal +/// Returns `0` if the pointers are guaranteed inequal +#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")] +#[unstable(feature = "core_intrinsics", issue = "none")] +#[rustc_intrinsic] +#[cfg(not(bootstrap))] +#[rustc_nounwind] +#[rustc_do_not_const_check] +#[inline] +pub const fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8 { + (ptr == other) as u8 +} +extern "rust-intrinsic" { /// Determines whether the raw bytes of the two values are equal. /// /// This is particularly handy for arrays, since it allows things like just @@ -2506,66 +2498,12 @@ extern "rust-intrinsic" { /// `ptr` must point to a vtable. /// The intrinsic will return the alignment stored in that vtable. #[rustc_nounwind] + #[cfg(bootstrap)] pub fn vtable_align(ptr: *const ()) -> usize; - /// Selects which function to call depending on the context. - /// - /// If this function is evaluated at compile-time, then a call to this - /// intrinsic will be replaced with a call to `called_in_const`. It gets - /// replaced with a call to `called_at_rt` otherwise. - /// - /// This function is safe to call, but note the stability concerns below. - /// - /// # Type Requirements - /// - /// The two functions must be both function items. They cannot be function - /// pointers or closures. The first function must be a `const fn`. - /// - /// `arg` will be the tupled arguments that will be passed to either one of - /// the two functions, therefore, both functions must accept the same type of - /// arguments. Both functions must return RET. - /// - /// # Stability concerns - /// - /// Rust has not yet decided that `const fn` are allowed to tell whether - /// they run at compile-time or at runtime. Therefore, when using this - /// intrinsic anywhere that can be reached from stable, it is crucial that - /// the end-to-end behavior of the stable `const fn` is the same for both - /// modes of execution. (Here, Undefined Behavior is considered "the same" - /// as any other behavior, so if the function exhibits UB at runtime then - /// it may do whatever it wants at compile-time.) - /// - /// Here is an example of how this could cause a problem: - /// ```no_run - /// #![feature(const_eval_select)] - /// #![feature(core_intrinsics)] - /// # #![allow(internal_features)] - /// # #![cfg_attr(bootstrap, allow(unused))] - /// use std::intrinsics::const_eval_select; - /// - /// // Standard library - /// # #[cfg(not(bootstrap))] - /// pub const fn inconsistent() -> i32 { - /// fn runtime() -> i32 { 1 } - /// const fn compiletime() -> i32 { 2 } - /// - // // ⚠ This code violates the required equivalence of `compiletime` - /// // and `runtime`. - /// const_eval_select((), compiletime, runtime) - /// } - /// # #[cfg(bootstrap)] - /// # pub const fn inconsistent() -> i32 { 0 } - /// - /// // User Crate - /// const X: i32 = inconsistent(); - /// let x = inconsistent(); - /// assert_eq!(x, X); - /// ``` - /// - /// Currently such an assertion would always succeed; until Rust decides - /// otherwise, that principle should not be violated. #[rustc_const_unstable(feature = "const_eval_select", issue = "none")] - #[cfg_attr(not(bootstrap), rustc_safe_intrinsic)] + #[rustc_safe_intrinsic] + #[cfg(bootstrap)] pub fn const_eval_select<ARG: Tuple, F, G, RET>( arg: ARG, called_in_const: F, @@ -2576,6 +2514,79 @@ extern "rust-intrinsic" { F: FnOnce<ARG, Output = RET>; } +/// Selects which function to call depending on the context. +/// +/// If this function is evaluated at compile-time, then a call to this +/// intrinsic will be replaced with a call to `called_in_const`. It gets +/// replaced with a call to `called_at_rt` otherwise. +/// +/// This function is safe to call, but note the stability concerns below. +/// +/// # Type Requirements +/// +/// The two functions must be both function items. They cannot be function +/// pointers or closures. The first function must be a `const fn`. +/// +/// `arg` will be the tupled arguments that will be passed to either one of +/// the two functions, therefore, both functions must accept the same type of +/// arguments. Both functions must return RET. +/// +/// # Stability concerns +/// +/// Rust has not yet decided that `const fn` are allowed to tell whether +/// they run at compile-time or at runtime. Therefore, when using this +/// intrinsic anywhere that can be reached from stable, it is crucial that +/// the end-to-end behavior of the stable `const fn` is the same for both +/// modes of execution. (Here, Undefined Behavior is considered "the same" +/// as any other behavior, so if the function exhibits UB at runtime then +/// it may do whatever it wants at compile-time.) +/// +/// Here is an example of how this could cause a problem: +/// ```no_run +/// #![feature(const_eval_select)] +/// #![feature(core_intrinsics)] +/// # #![allow(internal_features)] +/// # #![cfg_attr(bootstrap, allow(unused))] +/// use std::intrinsics::const_eval_select; +/// +/// // Standard library +/// # #[cfg(not(bootstrap))] +/// pub const fn inconsistent() -> i32 { +/// fn runtime() -> i32 { 1 } +/// const fn compiletime() -> i32 { 2 } +/// +// // ⚠ This code violates the required equivalence of `compiletime` +/// // and `runtime`. +/// const_eval_select((), compiletime, runtime) +/// } +/// # #[cfg(bootstrap)] +/// # pub const fn inconsistent() -> i32 { 0 } +/// +/// // User Crate +/// const X: i32 = inconsistent(); +/// let x = inconsistent(); +/// assert_eq!(x, X); +/// ``` +/// +/// Currently such an assertion would always succeed; until Rust decides +/// otherwise, that principle should not be violated. +#[rustc_const_unstable(feature = "const_eval_select", issue = "none")] +#[unstable(feature = "core_intrinsics", issue = "none")] +#[cfg(not(bootstrap))] +#[rustc_intrinsic] +#[rustc_intrinsic_must_be_overridden] +pub const fn const_eval_select<ARG: Tuple, F, G, RET>( + _arg: ARG, + _called_in_const: F, + _called_at_rt: G, +) -> RET +where + G: FnOnce<ARG, Output = RET>, + F: FnOnce<ARG, Output = RET>, +{ + unreachable!() +} + /// Returns whether the argument's value is statically known at /// compile-time. /// @@ -2622,8 +2633,7 @@ extern "rust-intrinsic" { #[rustc_const_unstable(feature = "is_val_statically_known", issue = "none")] #[rustc_nounwind] #[unstable(feature = "core_intrinsics", issue = "none")] -#[cfg_attr(not(bootstrap), rustc_intrinsic)] -#[cfg_attr(bootstrap, inline)] +#[rustc_intrinsic] pub const fn is_val_statically_known<T: Copy>(_arg: T) -> bool { false } @@ -2642,7 +2652,7 @@ pub const fn is_val_statically_known<T: Copy>(_arg: T) -> bool { #[rustc_const_unstable(feature = "ub_checks", issue = "none")] #[unstable(feature = "core_intrinsics", issue = "none")] #[inline(always)] -#[cfg_attr(not(bootstrap), rustc_intrinsic)] +#[rustc_intrinsic] pub(crate) const fn check_library_ub() -> bool { cfg!(debug_assertions) } @@ -2658,7 +2668,7 @@ pub(crate) const fn check_library_ub() -> bool { #[rustc_const_unstable(feature = "ub_checks", issue = "none")] #[unstable(feature = "core_intrinsics", issue = "none")] #[inline(always)] -#[cfg_attr(not(bootstrap), rustc_intrinsic)] +#[rustc_intrinsic] pub(crate) const fn check_language_ub() -> bool { cfg!(debug_assertions) } @@ -2674,8 +2684,7 @@ pub(crate) const fn check_language_ub() -> bool { #[rustc_const_unstable(feature = "const_heap", issue = "79597")] #[unstable(feature = "core_intrinsics", issue = "none")] #[rustc_nounwind] -#[cfg_attr(not(bootstrap), rustc_intrinsic)] -#[cfg_attr(bootstrap, inline)] +#[rustc_intrinsic] pub const unsafe fn const_allocate(_size: usize, _align: usize) -> *mut u8 { // const eval overrides this function, but runtime code should always just return null pointers. crate::ptr::null_mut() @@ -2694,32 +2703,29 @@ pub const unsafe fn const_allocate(_size: usize, _align: usize) -> *mut u8 { #[rustc_const_unstable(feature = "const_heap", issue = "79597")] #[unstable(feature = "core_intrinsics", issue = "none")] #[rustc_nounwind] -#[cfg_attr(not(bootstrap), rustc_intrinsic)] -#[cfg_attr(bootstrap, inline)] +#[rustc_intrinsic] pub const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {} /// `ptr` must point to a vtable. /// The intrinsic will return the size stored in that vtable. #[rustc_nounwind] #[unstable(feature = "core_intrinsics", issue = "none")] -#[cfg_attr(not(bootstrap), rustc_intrinsic)] -#[cfg_attr(not(bootstrap), rustc_intrinsic_must_be_overridden)] +#[rustc_intrinsic] +#[rustc_intrinsic_must_be_overridden] #[cfg(not(bootstrap))] pub unsafe fn vtable_size(_ptr: *const ()) -> usize { unreachable!() } -/// Retag a box pointer as part of casting it to a raw pointer. This is the `Box` equivalent of -/// `(x: &mut T) as *mut T`. The input pointer must be the pointer of a `Box` (passed as raw pointer -/// to avoid all questions around move semantics and custom allocators), and `A` must be the `Box`'s -/// allocator. -#[unstable(feature = "core_intrinsics", issue = "none")] +/// `ptr` must point to a vtable. +/// The intrinsic will return the alignment stored in that vtable. #[rustc_nounwind] -#[cfg_attr(not(bootstrap), rustc_intrinsic)] -#[cfg_attr(bootstrap, inline)] -pub unsafe fn retag_box_to_raw<T: ?Sized, A>(ptr: *mut T) -> *mut T { - // Miri needs to adjust the provenance, but for regular codegen this is not needed - ptr +#[unstable(feature = "core_intrinsics", issue = "none")] +#[rustc_intrinsic] +#[rustc_intrinsic_must_be_overridden] +#[cfg(not(bootstrap))] +pub unsafe fn vtable_align(_ptr: *const ()) -> usize { + unreachable!() } // Some functions are defined here because they accidentally got made @@ -2773,15 +2779,6 @@ pub unsafe fn retag_box_to_raw<T: ?Sized, A>(ptr: *mut T) -> *mut T { macro_rules! assert_unsafe_precondition { ($kind:ident, $message:expr, ($($name:ident:$ty:ty = $arg:expr),*$(,)?) => $e:expr $(,)?) => { { - // #[cfg(bootstrap)] (this comment) - // When the standard library is compiled with debug assertions, we want the check to inline for better performance. - // This is important when working on the compiler, which is compiled with debug assertions locally. - // When not compiled with debug assertions (so the precompiled std) we outline the check to minimize the compile - // time impact when debug assertions are disabled. - // The proper solution to this is the `#[rustc_no_mir_inline]` below, but we still want decent performance for cfg(bootstrap). - #[cfg_attr(all(debug_assertions, bootstrap), inline(always))] - #[cfg_attr(all(not(debug_assertions), bootstrap), inline(never))] - // This check is inlineable, but not by the MIR inliner. // The reason for this is that the MIR inliner is in an exceptionally bad position // to think about whether or not to inline this. In MIR, this call is gated behind `debug_assertions`, @@ -2790,8 +2787,8 @@ macro_rules! assert_unsafe_precondition { // // LLVM on the other hand sees the constant branch, so if it's `false`, it can immediately delete it without // inlining the check. If it's `true`, it can inline it and get significantly better performance. - #[cfg_attr(not(bootstrap), rustc_no_mir_inline)] - #[cfg_attr(not(bootstrap), inline)] + #[rustc_no_mir_inline] + #[inline] #[rustc_nounwind] #[rustc_const_unstable(feature = "ub_checks", issue = "none")] const fn precondition_check($($name:$ty),*) { @@ -2859,13 +2856,7 @@ pub(crate) const fn is_nonoverlapping( true } - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: This function's precondition is equivalent to that of `const_eval_select`. - // Programs which do not execute UB will only see this function return `true`, which makes the - // const and runtime implementation indistinguishable. - unsafe { - const_eval_select((src, dst, size, count), comptime, runtime) - } + const_eval_select((src, dst, size, count), comptime, runtime) } /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source @@ -3182,9 +3173,5 @@ pub(crate) const fn miri_promise_symbolic_alignment(ptr: *const (), align: usize const fn compiletime(_ptr: *const (), _align: usize) {} - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: the extra behavior at runtime is for UB checks only. - unsafe { - const_eval_select((ptr, align), compiletime, runtime); - } + const_eval_select((ptr, align), compiletime, runtime); } diff --git a/library/core/src/intrinsics/simd.rs b/library/core/src/intrinsics/simd.rs index 2eaca3b6fe4..b69f4f853b9 100644 --- a/library/core/src/intrinsics/simd.rs +++ b/library/core/src/intrinsics/simd.rs @@ -2,11 +2,7 @@ //! //! In this module, a "vector" is any `repr(simd)` type. -// Temporary macro while we switch the ABI from "platform-intrinsics" to "intrinsics". -#[rustfmt::skip] -macro_rules! declare_intrinsics { -($abi:tt) => { -extern $abi { +extern "rust-intrinsic" { /// Insert an element into a vector, returning the updated vector. /// /// `T` must be a vector with element type `U`. @@ -659,10 +655,3 @@ extern $abi { #[rustc_nounwind] pub fn simd_flog<T>(a: T) -> T; } -} -} - -#[cfg(bootstrap)] -declare_intrinsics!("platform-intrinsic"); -#[cfg(not(bootstrap))] -declare_intrinsics!("rust-intrinsic"); diff --git a/library/core/src/iter/traits/marker.rs b/library/core/src/iter/traits/marker.rs index 8bdbca120d7..ad4d63d83b5 100644 --- a/library/core/src/iter/traits/marker.rs +++ b/library/core/src/iter/traits/marker.rs @@ -28,6 +28,7 @@ pub unsafe trait TrustedFused {} #[rustc_unsafe_specialization_marker] // FIXME: this should be a #[marker] and have another blanket impl for T: TrustedFused // but that ICEs iter::Fuse specializations. +#[cfg_attr(not(bootstrap), lang = "fused_iterator")] pub trait FusedIterator: Iterator {} #[stable(feature = "fused", since = "1.26.0")] diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 9b786feba89..2718dd11473 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -112,6 +112,8 @@ // // Library features: // tidy-alphabetical-start +#![cfg_attr(bootstrap, feature(associated_type_bounds))] +#![feature(array_ptr_get)] #![feature(char_indices_offset)] #![feature(const_align_of_val)] #![feature(const_align_of_val_raw)] @@ -202,17 +204,11 @@ // // Language features: // tidy-alphabetical-start -#![cfg_attr(bootstrap, feature(diagnostic_namespace))] -#![cfg_attr(bootstrap, feature(exhaustive_patterns))] -#![cfg_attr(bootstrap, feature(platform_intrinsics))] -#![cfg_attr(not(bootstrap), feature(freeze_impls))] -#![cfg_attr(not(bootstrap), feature(min_exhaustive_patterns))] #![feature(abi_unadjusted)] #![feature(adt_const_params)] #![feature(allow_internal_unsafe)] #![feature(allow_internal_unstable)] #![feature(asm_const)] -#![feature(associated_type_bounds)] #![feature(auto_traits)] #![feature(c_unwind)] #![feature(cfg_sanitize)] @@ -232,6 +228,7 @@ #![feature(doc_notable_trait)] #![feature(effects)] #![feature(extern_types)] +#![feature(freeze_impls)] #![feature(fundamental)] #![feature(generic_arg_infer)] #![feature(if_let_guard)] @@ -242,6 +239,7 @@ #![feature(let_chains)] #![feature(link_llvm_intrinsics)] #![feature(macro_metavar_expr)] +#![feature(min_exhaustive_patterns)] #![feature(min_specialization)] #![feature(multiple_supertrait_upcastable)] #![feature(must_not_suspend)] diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 0ee7e190e3d..a78842c8f8d 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -1704,14 +1704,26 @@ pub(crate) mod builtin { } /// Unstable placeholder for type ascription. - #[rustc_builtin_macro] + #[allow_internal_unstable(builtin_syntax)] #[unstable( feature = "type_ascription", issue = "23416", reason = "placeholder syntax for type ascription" )] pub macro type_ascribe($expr:expr, $ty:ty) { - /* compiler built-in */ + builtin # type_ascribe($expr, $ty) + } + + #[cfg(not(bootstrap))] + /// Unstable placeholder for deref patterns. + #[allow_internal_unstable(builtin_syntax)] + #[unstable( + feature = "deref_patterns", + issue = "87121", + reason = "placeholder syntax for deref patterns" + )] + pub macro deref($pat:pat) { + builtin # deref($pat) } /// Unstable implementation detail of the `rustc` compiler, do not use. diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index e247b9ed83d..d1dc6720271 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -1337,7 +1337,7 @@ impl<T> SizedTypeProperties for T {} /// type B = Wrapper<u8, i8>; /// /// // Not necessarily identical even though `u8` and `i8` have the same layout! -/// // assert!(mem::offset_of!(A, 1), mem::offset_of!(B, 1)); +/// // assert_eq!(mem::offset_of!(A, 1), mem::offset_of!(B, 1)); /// /// #[repr(transparent)] /// struct U8(u8); @@ -1345,12 +1345,12 @@ impl<T> SizedTypeProperties for T {} /// type C = Wrapper<u8, U8>; /// /// // Not necessarily identical even though `u8` and `U8` have the same layout! -/// // assert!(mem::offset_of!(A, 1), mem::offset_of!(C, 1)); +/// // assert_eq!(mem::offset_of!(A, 1), mem::offset_of!(C, 1)); /// /// struct Empty<T>(core::marker::PhantomData<T>); /// /// // Not necessarily identical even though `PhantomData` always has the same layout! -/// // assert!(mem::offset_of!(Empty<u8>, 0), mem::offset_of!(Empty<i8>, 0)); +/// // assert_eq!(mem::offset_of!(Empty<u8>, 0), mem::offset_of!(Empty<i8>, 0)); /// ``` /// /// [explicit `repr` attribute]: https://doc.rust-lang.org/reference/type-layout.html#representations diff --git a/library/core/src/mem/transmutability.rs b/library/core/src/mem/transmutability.rs index 0687874a258..827426b2358 100644 --- a/library/core/src/mem/transmutability.rs +++ b/library/core/src/mem/transmutability.rs @@ -6,7 +6,7 @@ use crate::marker::ConstParamTy; /// any value of type `Self` are safely transmutable into a value of type `Dst`, in a given `Context`, /// notwithstanding whatever safety checks you have asked the compiler to [`Assume`] are satisfied. #[unstable(feature = "transmutability", issue = "99571")] -#[cfg_attr(not(bootstrap), lang = "transmute_trait")] +#[lang = "transmute_trait"] #[rustc_deny_explicit_impl(implement_via_object = false)] #[rustc_coinductive] pub unsafe trait BikeshedIntrinsicFrom<Src, const ASSUME: Assume = { Assume::NOTHING }> diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index abdcb7099ca..2e715fb0bdd 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -1153,11 +1153,7 @@ impl f32 { // Stability concerns. unsafe { mem::transmute(x) } } - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: We use internal implementations that either always work or fail at compile time. - unsafe { - intrinsics::const_eval_select((self,), ct_f32_to_u32, rt_f32_to_u32) - } + intrinsics::const_eval_select((self,), ct_f32_to_u32, rt_f32_to_u32) } /// Raw transmutation from `u32`. @@ -1248,11 +1244,7 @@ impl f32 { // Stability concerns. unsafe { mem::transmute(x) } } - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: We use internal implementations that either always work or fail at compile time. - unsafe { - intrinsics::const_eval_select((v,), ct_u32_to_f32, rt_u32_to_f32) - } + intrinsics::const_eval_select((v,), ct_u32_to_f32, rt_u32_to_f32) } /// Return the memory representation of this floating point number as a byte array in diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index f4d2a4f2167..d56f346d95e 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -1146,11 +1146,7 @@ impl f64 { // Stability concerns. unsafe { mem::transmute::<f64, u64>(rt) } } - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: We use internal implementations that either always work or fail at compile time. - unsafe { - intrinsics::const_eval_select((self,), ct_f64_to_u64, rt_f64_to_u64) - } + intrinsics::const_eval_select((self,), ct_f64_to_u64, rt_f64_to_u64) } /// Raw transmutation from `u64`. @@ -1246,11 +1242,7 @@ impl f64 { // Stability concerns. unsafe { mem::transmute::<u64, f64>(rt) } } - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: We use internal implementations that either always work or fail at compile time. - unsafe { - intrinsics::const_eval_select((v,), ct_u64_to_f64, rt_u64_to_f64) - } + intrinsics::const_eval_select((v,), ct_u64_to_f64, rt_u64_to_f64) } /// Return the memory representation of this floating point number as a byte array in diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 6cbcac20ea1..a8f637280df 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -4,23 +4,15 @@ use crate::cmp::Ordering; use crate::fmt; use crate::hash::{Hash, Hasher}; use crate::intrinsics; -use crate::marker::StructuralPartialEq; -use crate::ops::{BitOr, BitOrAssign, Div, Neg, Rem}; +use crate::marker::{Freeze, StructuralPartialEq}; +use crate::ops::{BitOr, BitOrAssign, Div, DivAssign, Neg, Rem, RemAssign}; +use crate::panic::{RefUnwindSafe, UnwindSafe}; +use crate::ptr; use crate::str::FromStr; use super::from_str_radix; use super::{IntErrorKind, ParseIntError}; -mod private { - #[unstable( - feature = "nonzero_internals", - reason = "implementation detail which may disappear or be replaced at any time", - issue = "none" - )] - #[const_trait] - pub trait Sealed {} -} - /// A marker trait for primitive types which can be zero. /// /// This is an implementation detail for <code>[NonZero]\<T></code> which may disappear or be replaced at any time. @@ -34,38 +26,70 @@ mod private { issue = "none" )] #[const_trait] -pub unsafe trait ZeroablePrimitive: Sized + Copy + private::Sealed {} +pub unsafe trait ZeroablePrimitive: Sized + Copy + private::Sealed { + #[doc(hidden)] + type NonZeroInner: Sized + Copy; +} macro_rules! impl_zeroable_primitive { - ($primitive:ty) => { - #[unstable( - feature = "nonzero_internals", - reason = "implementation detail which may disappear or be replaced at any time", - issue = "none" - )] - impl const private::Sealed for $primitive {} - - #[unstable( - feature = "nonzero_internals", - reason = "implementation detail which may disappear or be replaced at any time", - issue = "none" - )] - unsafe impl const ZeroablePrimitive for $primitive {} + ($($NonZeroInner:ident ( $primitive:ty )),+ $(,)?) => { + mod private { + #[unstable( + feature = "nonzero_internals", + reason = "implementation detail which may disappear or be replaced at any time", + issue = "none" + )] + #[const_trait] + pub trait Sealed {} + + $( + #[derive(Debug, Clone, Copy, PartialEq)] + #[repr(transparent)] + #[rustc_layout_scalar_valid_range_start(1)] + #[rustc_nonnull_optimization_guaranteed] + #[unstable( + feature = "nonzero_internals", + reason = "implementation detail which may disappear or be replaced at any time", + issue = "none" + )] + pub struct $NonZeroInner($primitive); + )+ + } + + $( + #[unstable( + feature = "nonzero_internals", + reason = "implementation detail which may disappear or be replaced at any time", + issue = "none" + )] + impl const private::Sealed for $primitive {} + + #[unstable( + feature = "nonzero_internals", + reason = "implementation detail which may disappear or be replaced at any time", + issue = "none" + )] + unsafe impl const ZeroablePrimitive for $primitive { + type NonZeroInner = private::$NonZeroInner; + } + )+ }; } -impl_zeroable_primitive!(u8); -impl_zeroable_primitive!(u16); -impl_zeroable_primitive!(u32); -impl_zeroable_primitive!(u64); -impl_zeroable_primitive!(u128); -impl_zeroable_primitive!(usize); -impl_zeroable_primitive!(i8); -impl_zeroable_primitive!(i16); -impl_zeroable_primitive!(i32); -impl_zeroable_primitive!(i64); -impl_zeroable_primitive!(i128); -impl_zeroable_primitive!(isize); +impl_zeroable_primitive!( + NonZeroU8Inner(u8), + NonZeroU16Inner(u16), + NonZeroU32Inner(u32), + NonZeroU64Inner(u64), + NonZeroU128Inner(u128), + NonZeroUsizeInner(usize), + NonZeroI8Inner(i8), + NonZeroI16Inner(i16), + NonZeroI32Inner(i32), + NonZeroI64Inner(i64), + NonZeroI128Inner(i128), + NonZeroIsizeInner(isize), +); /// A value that is known not to equal zero. /// @@ -80,10 +104,9 @@ impl_zeroable_primitive!(isize); /// ``` #[unstable(feature = "generic_nonzero", issue = "120257")] #[repr(transparent)] -#[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] #[rustc_diagnostic_item = "NonZero"] -pub struct NonZero<T: ZeroablePrimitive>(T); +pub struct NonZero<T: ZeroablePrimitive>(T::NonZeroInner); macro_rules! impl_nonzero_fmt { ($Trait:ident) => { @@ -107,6 +130,26 @@ impl_nonzero_fmt!(Octal); impl_nonzero_fmt!(LowerHex); impl_nonzero_fmt!(UpperHex); +macro_rules! impl_nonzero_auto_trait { + (unsafe $Trait:ident) => { + #[stable(feature = "nonzero", since = "1.28.0")] + unsafe impl<T> $Trait for NonZero<T> where T: ZeroablePrimitive + $Trait {} + }; + ($Trait:ident) => { + #[stable(feature = "nonzero", since = "1.28.0")] + impl<T> $Trait for NonZero<T> where T: ZeroablePrimitive + $Trait {} + }; +} + +// Implement auto-traits manually based on `T` to avoid docs exposing +// the `ZeroablePrimitive::NonZeroInner` implementation detail. +impl_nonzero_auto_trait!(unsafe Freeze); +impl_nonzero_auto_trait!(RefUnwindSafe); +impl_nonzero_auto_trait!(unsafe Send); +impl_nonzero_auto_trait!(unsafe Sync); +impl_nonzero_auto_trait!(Unpin); +impl_nonzero_auto_trait!(UnwindSafe); + #[stable(feature = "nonzero", since = "1.28.0")] impl<T> Clone for NonZero<T> where @@ -114,8 +157,7 @@ where { #[inline] fn clone(&self) -> Self { - // SAFETY: The contained value is non-zero. - unsafe { Self(self.0) } + Self(self.0) } } @@ -188,19 +230,19 @@ where #[inline] fn max(self, other: Self) -> Self { // SAFETY: The maximum of two non-zero values is still non-zero. - unsafe { Self(self.get().max(other.get())) } + unsafe { Self::new_unchecked(self.get().max(other.get())) } } #[inline] fn min(self, other: Self) -> Self { // SAFETY: The minimum of two non-zero values is still non-zero. - unsafe { Self(self.get().min(other.get())) } + unsafe { Self::new_unchecked(self.get().min(other.get())) } } #[inline] fn clamp(self, min: Self, max: Self) -> Self { // SAFETY: A non-zero value clamped between two non-zero values is still non-zero. - unsafe { Self(self.get().clamp(min.get(), max.get())) } + unsafe { Self::new_unchecked(self.get().clamp(min.get(), max.get())) } } } @@ -240,7 +282,7 @@ where #[inline] fn bitor(self, rhs: Self) -> Self::Output { // SAFETY: Bitwise OR of two non-zero values is still non-zero. - unsafe { Self(self.get() | rhs.get()) } + unsafe { Self::new_unchecked(self.get() | rhs.get()) } } } @@ -254,7 +296,7 @@ where #[inline] fn bitor(self, rhs: T) -> Self::Output { // SAFETY: Bitwise OR of a non-zero value with anything is still non-zero. - unsafe { Self(self.get() | rhs) } + unsafe { Self::new_unchecked(self.get() | rhs) } } } @@ -268,7 +310,7 @@ where #[inline] fn bitor(self, rhs: NonZero<T>) -> Self::Output { // SAFETY: Bitwise OR of anything with a non-zero value is still non-zero. - unsafe { NonZero(self | rhs.get()) } + unsafe { NonZero::new_unchecked(self | rhs.get()) } } } @@ -346,7 +388,7 @@ where pub fn from_mut(n: &mut T) -> Option<&mut Self> { // SAFETY: Memory layout optimization guarantees that `Option<NonZero<T>>` has // the same layout and size as `T`, with `0` representing `None`. - let opt_n = unsafe { &mut *(n as *mut T as *mut Option<Self>) }; + let opt_n = unsafe { &mut *(ptr::from_mut(n).cast::<Option<Self>>()) }; opt_n.as_mut() } @@ -390,12 +432,17 @@ where // memory somewhere. If the value of `self` was from by-value argument // of some not-inlined function, LLVM don't have range metadata // to understand that the value cannot be zero. - match Self::new(self.0) { - Some(Self(n)) => n, + // + // SAFETY: `Self` is guaranteed to have the same layout as `Option<Self>`. + match unsafe { intrinsics::transmute_unchecked(self) } { None => { // SAFETY: `NonZero` is guaranteed to only contain non-zero values, so this is unreachable. unsafe { intrinsics::unreachable() } } + Some(Self(inner)) => { + // SAFETY: `T::NonZeroInner` is guaranteed to have the same layout as `T`. + unsafe { intrinsics::transmute_unchecked(inner) } + } } } } @@ -802,6 +849,16 @@ macro_rules! nonzero_integer_signedness_dependent_impls { } } + #[stable(feature = "nonzero_div_assign", since = "CURRENT_RUSTC_VERSION")] + impl DivAssign<$Ty> for $Int { + /// This operation rounds towards zero, + /// truncating any fractional part of the exact result, and cannot panic. + #[inline] + fn div_assign(&mut self, other: $Ty) { + *self = *self / other; + } + } + #[stable(feature = "nonzero_div", since = "1.51.0")] impl Rem<$Ty> for $Int { type Output = $Int; @@ -814,6 +871,15 @@ macro_rules! nonzero_integer_signedness_dependent_impls { unsafe { intrinsics::unchecked_rem(self, other.get()) } } } + + #[stable(feature = "nonzero_div_assign", since = "CURRENT_RUSTC_VERSION")] + impl RemAssign<$Ty> for $Int { + /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic. + #[inline] + fn rem_assign(&mut self, other: $Ty) { + *self = *self % other; + } + } }; // Impls for signed nonzero types only. diff --git a/library/core/src/ops/async_function.rs b/library/core/src/ops/async_function.rs index d6b06ffb7fc..18bcee5a1c7 100644 --- a/library/core/src/ops/async_function.rs +++ b/library/core/src/ops/async_function.rs @@ -10,15 +10,9 @@ use crate::marker::Tuple; #[must_use = "async closures are lazy and do nothing unless called"] #[lang = "async_fn"] pub trait AsyncFn<Args: Tuple>: AsyncFnMut<Args> { - /// Future returned by [`AsyncFn::async_call`]. - #[unstable(feature = "async_fn_traits", issue = "none")] - type CallFuture<'a>: Future<Output = Self::Output> - where - Self: 'a; - /// Call the [`AsyncFn`], returning a future which may borrow from the called closure. #[unstable(feature = "async_fn_traits", issue = "none")] - extern "rust-call" fn async_call(&self, args: Args) -> Self::CallFuture<'_>; + extern "rust-call" fn async_call(&self, args: Args) -> Self::CallRefFuture<'_>; } /// An async-aware version of the [`FnMut`](crate::ops::FnMut) trait. @@ -30,15 +24,15 @@ pub trait AsyncFn<Args: Tuple>: AsyncFnMut<Args> { #[must_use = "async closures are lazy and do nothing unless called"] #[lang = "async_fn_mut"] pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> { - /// Future returned by [`AsyncFnMut::async_call_mut`]. + /// Future returned by [`AsyncFnMut::async_call_mut`] and [`AsyncFn::async_call`]. #[unstable(feature = "async_fn_traits", issue = "none")] - type CallMutFuture<'a>: Future<Output = Self::Output> + type CallRefFuture<'a>: Future<Output = Self::Output> where Self: 'a; /// Call the [`AsyncFnMut`], returning a future which may borrow from the called closure. #[unstable(feature = "async_fn_traits", issue = "none")] - extern "rust-call" fn async_call_mut(&mut self, args: Args) -> Self::CallMutFuture<'_>; + extern "rust-call" fn async_call_mut(&mut self, args: Args) -> Self::CallRefFuture<'_>; } /// An async-aware version of the [`FnOnce`](crate::ops::FnOnce) trait. @@ -72,9 +66,7 @@ mod impls { where F: AsyncFn<A>, { - type CallFuture<'a> = F::CallFuture<'a> where Self: 'a; - - extern "rust-call" fn async_call(&self, args: A) -> Self::CallFuture<'_> { + extern "rust-call" fn async_call(&self, args: A) -> Self::CallRefFuture<'_> { F::async_call(*self, args) } } @@ -84,9 +76,9 @@ mod impls { where F: AsyncFn<A>, { - type CallMutFuture<'a> = F::CallFuture<'a> where Self: 'a; + type CallRefFuture<'a> = F::CallRefFuture<'a> where Self: 'a; - extern "rust-call" fn async_call_mut(&mut self, args: A) -> Self::CallMutFuture<'_> { + extern "rust-call" fn async_call_mut(&mut self, args: A) -> Self::CallRefFuture<'_> { F::async_call(*self, args) } } @@ -97,7 +89,7 @@ mod impls { F: AsyncFn<A>, { type Output = F::Output; - type CallOnceFuture = F::CallFuture<'a>; + type CallOnceFuture = F::CallRefFuture<'a>; extern "rust-call" fn async_call_once(self, args: A) -> Self::CallOnceFuture { F::async_call(self, args) @@ -109,9 +101,9 @@ mod impls { where F: AsyncFnMut<A>, { - type CallMutFuture<'a> = F::CallMutFuture<'a> where Self: 'a; + type CallRefFuture<'a> = F::CallRefFuture<'a> where Self: 'a; - extern "rust-call" fn async_call_mut(&mut self, args: A) -> Self::CallMutFuture<'_> { + extern "rust-call" fn async_call_mut(&mut self, args: A) -> Self::CallRefFuture<'_> { F::async_call_mut(*self, args) } } @@ -122,7 +114,7 @@ mod impls { F: AsyncFnMut<A>, { type Output = F::Output; - type CallOnceFuture = F::CallMutFuture<'a>; + type CallOnceFuture = F::CallRefFuture<'a>; extern "rust-call" fn async_call_once(self, args: A) -> Self::CallOnceFuture { F::async_call_mut(self, args) @@ -140,7 +132,7 @@ mod internal_implementation_detail { /// and thus either `?0` or `i8`/`i16`/`i32` (see docs for `ClosureKind` /// for an explanation of that). The `GoalKind` is also the same type, but /// representing the kind of the trait that the closure is being called with. - #[cfg_attr(not(bootstrap), lang = "async_fn_kind_helper")] + #[lang = "async_fn_kind_helper"] trait AsyncFnKindHelper<GoalKind> { // Projects a set of closure inputs (arguments), a region, and a set of upvars // (by move and by ref) to the upvars that we expect the coroutine to have diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 5027e326a9d..0083d15efae 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -558,17 +558,16 @@ use crate::panicking::{panic, panic_str}; use crate::pin::Pin; use crate::{ cmp, convert, hint, mem, - num::NonZero, ops::{self, ControlFlow, Deref, DerefMut}, slice, }; /// The `Option` type. See [the module level documentation](self) for more. -#[derive(Copy, PartialOrd, Eq, Ord, Debug, Hash)] +#[derive(Copy, Eq, Debug, Hash)] #[rustc_diagnostic_item = "Option"] #[lang = "Option"] #[stable(feature = "rust1", since = "1.0.0")] -#[allow(clippy::derived_hash_with_manual_eq)] // PartialEq is specialized +#[allow(clippy::derived_hash_with_manual_eq)] // PartialEq is manually implemented equivalently pub enum Option<T> { /// No value. #[lang = "None"] @@ -2146,83 +2145,52 @@ impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T> { } } +// Ideally, LLVM should be able to optimize our derive code to this. +// Once https://github.com/llvm/llvm-project/issues/52622 is fixed, we can +// go back to deriving `PartialEq`. #[stable(feature = "rust1", since = "1.0.0")] impl<T> crate::marker::StructuralPartialEq for Option<T> {} #[stable(feature = "rust1", since = "1.0.0")] impl<T: PartialEq> PartialEq for Option<T> { #[inline] fn eq(&self, other: &Self) -> bool { - SpecOptionPartialEq::eq(self, other) - } -} - -/// This specialization trait is a workaround for LLVM not currently (2023-01) -/// being able to optimize this itself, even though Alive confirms that it would -/// be legal to do so: <https://github.com/llvm/llvm-project/issues/52622> -/// -/// Once that's fixed, `Option` should go back to deriving `PartialEq`, as -/// it used to do before <https://github.com/rust-lang/rust/pull/103556>. -#[unstable(feature = "spec_option_partial_eq", issue = "none", reason = "exposed only for rustc")] -#[doc(hidden)] -pub trait SpecOptionPartialEq: Sized { - fn eq(l: &Option<Self>, other: &Option<Self>) -> bool; -} - -#[unstable(feature = "spec_option_partial_eq", issue = "none", reason = "exposed only for rustc")] -impl<T: PartialEq> SpecOptionPartialEq for T { - #[inline] - default fn eq(l: &Option<T>, r: &Option<T>) -> bool { - match (l, r) { + // Spelling out the cases explicitly optimizes better than + // `_ => false` + match (self, other) { (Some(l), Some(r)) => *l == *r, + (Some(_), None) => false, + (None, Some(_)) => false, (None, None) => true, - _ => false, } } } -macro_rules! non_zero_option { - ( $( #[$stability: meta] $NZ:ty; )+ ) => { - $( - #[$stability] - impl SpecOptionPartialEq for $NZ { - #[inline] - fn eq(l: &Option<Self>, r: &Option<Self>) -> bool { - l.map(Self::get).unwrap_or(0) == r.map(Self::get).unwrap_or(0) - } - } - )+ - }; -} - -non_zero_option! { - #[stable(feature = "nonzero", since = "1.28.0")] NonZero<u8>; - #[stable(feature = "nonzero", since = "1.28.0")] NonZero<u16>; - #[stable(feature = "nonzero", since = "1.28.0")] NonZero<u32>; - #[stable(feature = "nonzero", since = "1.28.0")] NonZero<u64>; - #[stable(feature = "nonzero", since = "1.28.0")] NonZero<u128>; - #[stable(feature = "nonzero", since = "1.28.0")] NonZero<usize>; - #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZero<i8>; - #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZero<i16>; - #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZero<i32>; - #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZero<i64>; - #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZero<i128>; - #[stable(feature = "signed_nonzero", since = "1.34.0")] NonZero<isize>; -} - -#[stable(feature = "nonnull", since = "1.25.0")] -impl<T> SpecOptionPartialEq for crate::ptr::NonNull<T> { +// Manually implementing here somewhat improves codegen for +// https://github.com/rust-lang/rust/issues/49892, although still +// not optimal. +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: PartialOrd> PartialOrd for Option<T> { #[inline] - fn eq(l: &Option<Self>, r: &Option<Self>) -> bool { - l.map(Self::as_ptr).unwrap_or_else(|| crate::ptr::null_mut()) - == r.map(Self::as_ptr).unwrap_or_else(|| crate::ptr::null_mut()) + fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { + match (self, other) { + (Some(l), Some(r)) => l.partial_cmp(r), + (Some(_), None) => Some(cmp::Ordering::Greater), + (None, Some(_)) => Some(cmp::Ordering::Less), + (None, None) => Some(cmp::Ordering::Equal), + } } } #[stable(feature = "rust1", since = "1.0.0")] -impl SpecOptionPartialEq for cmp::Ordering { +impl<T: Ord> Ord for Option<T> { #[inline] - fn eq(l: &Option<Self>, r: &Option<Self>) -> bool { - l.map_or(2, |x| x as i8) == r.map_or(2, |x| x as i8) + fn cmp(&self, other: &Self) -> cmp::Ordering { + match (self, other) { + (Some(l), Some(r)) => l.cmp(r), + (Some(_), None) => cmp::Ordering::Greater, + (None, Some(_)) => cmp::Ordering::Less, + (None, None) => cmp::Ordering::Equal, + } } } diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 9e1184c8f5b..9e8dac88816 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -117,11 +117,7 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: boo panic_fmt(fmt); } - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: const panic does not care about unwinding - unsafe { - super::intrinsics::const_eval_select((fmt, force_no_backtrace), comptime, runtime); - } + super::intrinsics::const_eval_select((fmt, force_no_backtrace), comptime, runtime); } // Next we define a bunch of higher-level wrappers that all bottom out in the two core functions diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs index 10525a16f3a..29f73bb4942 100644 --- a/library/core/src/prelude/v1.rs +++ b/library/core/src/prelude/v1.rs @@ -103,3 +103,11 @@ pub use crate::macros::builtin::cfg_eval; reason = "placeholder syntax for type ascription" )] pub use crate::macros::builtin::type_ascribe; + +#[cfg(not(bootstrap))] +#[unstable( + feature = "deref_patterns", + issue = "87121", + reason = "placeholder syntax for deref patterns" +)] +pub use crate::macros::builtin::deref; diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index a0c04d3f65d..69c61602073 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -48,12 +48,8 @@ impl<T: ?Sized> *const T { } } - // on bootstrap bump, remove unsafe block - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] - // SAFETY: The two versions are equivalent at runtime. - unsafe { - const_eval_select((self as *const u8,), const_impl, runtime_impl) - } + #[allow(unused_unsafe)] + const_eval_select((self as *const u8,), const_impl, runtime_impl) } /// Casts to a pointer of another type. @@ -818,13 +814,8 @@ impl<T: ?Sized> *const T { true } - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] - // on bootstrap bump, remove unsafe block - // SAFETY: This function is only used to provide the same check that the const eval - // interpreter does at runtime. - unsafe { - intrinsics::const_eval_select((this, origin), comptime, runtime) - } + #[allow(unused_unsafe)] + intrinsics::const_eval_select((this, origin), comptime, runtime) } assert_unsafe_precondition!( @@ -1648,11 +1639,7 @@ impl<T: ?Sized> *const T { // The cast to `()` is used to // 1. deal with fat pointers; and // 2. ensure that `align_offset` (in `const_impl`) doesn't actually try to compute an offset. - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: The two versions are equivalent at runtime. - unsafe { - const_eval_select((self.cast::<()>(), align), const_impl, runtime_impl) - } + const_eval_select((self.cast::<()>(), align), const_impl, runtime_impl) } } @@ -1798,6 +1785,46 @@ impl<T> *const [T] { } } +impl<T, const N: usize> *const [T; N] { + /// Returns a raw pointer to the array's buffer. + /// + /// This is equivalent to casting `self` to `*const T`, but more type-safe. + /// + /// # Examples + /// + /// ```rust + /// #![feature(array_ptr_get)] + /// use std::ptr; + /// + /// let arr: *const [i8; 3] = ptr::null(); + /// assert_eq!(arr.as_ptr(), ptr::null()); + /// ``` + #[inline] + #[unstable(feature = "array_ptr_get", issue = "119834")] + #[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")] + pub const fn as_ptr(self) -> *const T { + self as *const T + } + + /// Returns a raw pointer to a slice containing the entire array. + /// + /// # Examples + /// + /// ``` + /// #![feature(array_ptr_get, slice_ptr_len)] + /// + /// let arr: *const [i32; 3] = &[1, 2, 4] as *const [i32; 3]; + /// let slice: *const [i32] = arr.as_slice(); + /// assert_eq!(slice.len(), 3); + /// ``` + #[inline] + #[unstable(feature = "array_ptr_get", issue = "119834")] + #[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")] + pub const fn as_slice(self) -> *const [T] { + self + } +} + // Equality for pointers #[stable(feature = "rust1", since = "1.0.0")] impl<T: ?Sized> PartialEq for *const T { diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 30af7522368..1f0204daf72 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1114,7 +1114,7 @@ const unsafe fn swap_nonoverlapping_simple_untyped<T>(x: *mut T, y: *mut T, coun #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_replace", issue = "83164")] #[rustc_diagnostic_item = "ptr_replace"] -pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T { +pub const unsafe fn replace<T>(dst: *mut T, src: T) -> T { // SAFETY: the caller must guarantee that `dst` is valid to be // cast to a mutable reference (valid for writes, aligned, initialized), // and cannot overlap `src` since `dst` must point to a distinct @@ -1128,9 +1128,8 @@ pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T { align: usize = align_of::<T>(), ) => is_aligned_and_not_null(addr, align) ); - mem::swap(&mut *dst, &mut src); // cannot overlap + mem::replace(&mut *dst, src) } - src } /// Reads the value from `src` without moving it. This leaves the diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 6a9033a144d..1add9ca2311 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -48,11 +48,7 @@ impl<T: ?Sized> *mut T { } } - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: The two versions are equivalent at runtime. - unsafe { - const_eval_select((self as *mut u8,), const_impl, runtime_impl) - } + const_eval_select((self as *mut u8,), const_impl, runtime_impl) } /// Casts to a pointer of another type. @@ -1906,11 +1902,7 @@ impl<T: ?Sized> *mut T { // The cast to `()` is used to // 1. deal with fat pointers; and // 2. ensure that `align_offset` (in `const_impl`) doesn't actually try to compute an offset. - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: The two versions are equivalent at runtime. - unsafe { - const_eval_select((self.cast::<()>(), align), const_impl, runtime_impl) - } + const_eval_select((self.cast::<()>(), align), const_impl, runtime_impl) } } @@ -2209,6 +2201,49 @@ impl<T> *mut [T] { } } +impl<T, const N: usize> *mut [T; N] { + /// Returns a raw pointer to the array's buffer. + /// + /// This is equivalent to casting `self` to `*mut T`, but more type-safe. + /// + /// # Examples + /// + /// ```rust + /// #![feature(array_ptr_get)] + /// use std::ptr; + /// + /// let arr: *mut [i8; 3] = ptr::null_mut(); + /// assert_eq!(arr.as_mut_ptr(), ptr::null_mut()); + /// ``` + #[inline] + #[unstable(feature = "array_ptr_get", issue = "119834")] + #[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")] + pub const fn as_mut_ptr(self) -> *mut T { + self as *mut T + } + + /// Returns a raw pointer to a mutable slice containing the entire array. + /// + /// # Examples + /// + /// ``` + /// #![feature(array_ptr_get)] + /// + /// let mut arr = [1, 2, 5]; + /// let ptr: *mut [i32; 3] = &mut arr; + /// unsafe { + /// (&mut *ptr.as_mut_slice())[..2].copy_from_slice(&[3, 4]); + /// } + /// assert_eq!(arr, [3, 4, 5]); + /// ``` + #[inline] + #[unstable(feature = "array_ptr_get", issue = "119834")] + #[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")] + pub const fn as_mut_slice(self) -> *mut [T] { + self + } +} + // Equality for pointers #[stable(feature = "rust1", since = "1.0.0")] impl<T: ?Sized> PartialEq for *mut T { diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 9c0236c172a..2ac42e20d43 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1575,6 +1575,25 @@ impl<T> NonNull<[T]> { self.as_ptr().len() } + /// Returns `true` if the non-null raw slice has a length of 0. + /// + /// # Examples + /// + /// ```rust + /// #![feature(slice_ptr_is_empty_nonnull)] + /// use std::ptr::NonNull; + /// + /// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3); + /// assert!(!slice.is_empty()); + /// ``` + #[unstable(feature = "slice_ptr_is_empty_nonnull", issue = "71146")] + #[rustc_const_unstable(feature = "const_slice_ptr_is_empty_nonnull", issue = "71146")] + #[must_use] + #[inline] + pub const fn is_empty(self) -> bool { + self.len() == 0 + } + /// Returns a non-null pointer to the slice's buffer. /// /// # Examples diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index 64f1f360821..210118817ab 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -35,15 +35,7 @@ where #[track_caller] #[rustc_const_unstable(feature = "const_slice_index", issue = "none")] const fn slice_start_index_len_fail(index: usize, len: usize) -> ! { - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: we are just panicking here - unsafe { - const_eval_select( - (index, len), - slice_start_index_len_fail_ct, - slice_start_index_len_fail_rt, - ) - } + const_eval_select((index, len), slice_start_index_len_fail_ct, slice_start_index_len_fail_rt) } // FIXME const-hack @@ -64,11 +56,7 @@ const fn slice_start_index_len_fail_ct(_: usize, _: usize) -> ! { #[track_caller] #[rustc_const_unstable(feature = "const_slice_index", issue = "none")] const fn slice_end_index_len_fail(index: usize, len: usize) -> ! { - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: we are just panicking here - unsafe { - const_eval_select((index, len), slice_end_index_len_fail_ct, slice_end_index_len_fail_rt) - } + const_eval_select((index, len), slice_end_index_len_fail_ct, slice_end_index_len_fail_rt) } // FIXME const-hack @@ -89,11 +77,7 @@ const fn slice_end_index_len_fail_ct(_: usize, _: usize) -> ! { #[track_caller] #[rustc_const_unstable(feature = "const_slice_index", issue = "none")] const fn slice_index_order_fail(index: usize, end: usize) -> ! { - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: we are just panicking here - unsafe { - const_eval_select((index, end), slice_index_order_fail_ct, slice_index_order_fail_rt) - } + const_eval_select((index, end), slice_index_order_fail_ct, slice_index_order_fail_rt) } // FIXME const-hack diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 4943bbc45d0..61a60456145 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -86,15 +86,7 @@ use iter::{MatchesInternal, SplitNInternal}; #[rustc_allow_const_fn_unstable(const_eval_select)] #[cfg(not(feature = "panic_immediate_abort"))] const fn slice_error_fail(s: &str, begin: usize, end: usize) -> ! { - #[cfg_attr(not(bootstrap), allow(unused_unsafe))] // on bootstrap bump, remove unsafe block - // SAFETY: panics for both branches - unsafe { - crate::intrinsics::const_eval_select( - (s, begin, end), - slice_error_fail_ct, - slice_error_fail_rt, - ) - } + crate::intrinsics::const_eval_select((s, begin, end), slice_error_fail_ct, slice_error_fail_rt) } #[cfg(feature = "panic_immediate_abort")] diff --git a/library/core/tests/iter/adapters/step_by.rs b/library/core/tests/iter/adapters/step_by.rs index 29adf0b42fa..6f3300e7a88 100644 --- a/library/core/tests/iter/adapters/step_by.rs +++ b/library/core/tests/iter/adapters/step_by.rs @@ -49,7 +49,7 @@ fn test_iterator_step_by_nth() { } #[test] -#[cfg_attr(not(bootstrap), allow(non_local_definitions))] +#[allow(non_local_definitions)] fn test_iterator_step_by_nth_overflow() { #[cfg(target_pointer_width = "16")] type Bigger = u32; diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index c5a7e87c4aa..421062f5873 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -1,5 +1,6 @@ #![feature(alloc_layout_extra)] #![feature(array_chunks)] +#![feature(array_ptr_get)] #![feature(array_windows)] #![feature(ascii_char)] #![feature(ascii_char_variants)] @@ -52,6 +53,7 @@ #![feature(sort_internals)] #![feature(slice_take)] #![feature(slice_from_ptr_range)] +#![feature(slice_ptr_len)] #![feature(slice_split_once)] #![feature(split_as_slice)] #![feature(maybe_uninit_fill)] diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 659fbd255c1..5c518e2d593 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -1141,3 +1141,16 @@ fn test_const_copy() { assert!(*ptr2 == 1); }; } + +#[test] +fn test_null_array_as_slice() { + let arr: *mut [u8; 4] = null_mut(); + let ptr: *mut [u8] = arr.as_mut_slice(); + assert!(ptr.is_null()); + assert_eq!(ptr.len(), 4); + + let arr: *const [u8; 4] = null(); + let ptr: *const [u8] = arr.as_slice(); + assert!(ptr.is_null()); + assert_eq!(ptr.len(), 4); +} diff --git a/library/core/tests/result.rs b/library/core/tests/result.rs index d02dc45da34..a47ef7aa1eb 100644 --- a/library/core/tests/result.rs +++ b/library/core/tests/result.rs @@ -195,7 +195,7 @@ pub fn test_unwrap_or_default() { } #[test] -#[cfg_attr(not(bootstrap), allow(non_local_definitions))] +#[allow(non_local_definitions)] pub fn test_into_ok() { fn infallible_op() -> Result<isize, !> { Ok(666) @@ -218,7 +218,7 @@ pub fn test_into_ok() { } #[test] -#[cfg_attr(not(bootstrap), allow(non_local_definitions))] +#[allow(non_local_definitions)] pub fn test_into_err() { fn until_error_op() -> Result<!, isize> { Err(666) diff --git a/library/panic_unwind/src/emcc.rs b/library/panic_unwind/src/emcc.rs index af18e19337c..fed4c52e83c 100644 --- a/library/panic_unwind/src/emcc.rs +++ b/library/panic_unwind/src/emcc.rs @@ -84,7 +84,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> { super::__rust_foreign_exception(); } - let was_caught = (*adjusted_ptr).caught.swap(true, Ordering::SeqCst); + let was_caught = (*adjusted_ptr).caught.swap(true, Ordering::Relaxed); if was_caught { // Since cleanup() isn't allowed to panic, we just abort instead. intrinsics::abort(); diff --git a/library/proc_macro/src/bridge/handle.rs b/library/proc_macro/src/bridge/handle.rs index 894acae217e..8c53bb609f6 100644 --- a/library/proc_macro/src/bridge/handle.rs +++ b/library/proc_macro/src/bridge/handle.rs @@ -21,7 +21,7 @@ impl<T> OwnedStore<T> { pub(super) fn new(counter: &'static AtomicU32) -> Self { // Ensure the handle counter isn't 0, which would panic later, // when `NonZero::new` (aka `Handle::new`) is called in `alloc`. - assert_ne!(counter.load(Ordering::SeqCst), 0); + assert_ne!(counter.load(Ordering::Relaxed), 0); OwnedStore { counter, data: BTreeMap::new() } } @@ -29,7 +29,7 @@ impl<T> OwnedStore<T> { impl<T> OwnedStore<T> { pub(super) fn alloc(&mut self, x: T) -> Handle { - let counter = self.counter.fetch_add(1, Ordering::SeqCst); + let counter = self.counter.fetch_add(1, Ordering::Relaxed); let handle = Handle::new(counter).expect("`proc_macro` handle counter overflowed"); assert!(self.data.insert(handle, x).is_none()); handle diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index a834b36697c..dc0e302a810 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -329,7 +329,7 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut()); /// ``` #[unstable(feature = "alloc_error_hook", issue = "51245")] pub fn set_alloc_error_hook(hook: fn(Layout)) { - HOOK.store(hook as *mut (), Ordering::SeqCst); + HOOK.store(hook as *mut (), Ordering::Release); } /// Unregisters the current allocation error hook, returning it. @@ -339,7 +339,7 @@ pub fn set_alloc_error_hook(hook: fn(Layout)) { /// If no custom hook is registered, the default hook will be returned. #[unstable(feature = "alloc_error_hook", issue = "51245")] pub fn take_alloc_error_hook() -> fn(Layout) { - let hook = HOOK.swap(ptr::null_mut(), Ordering::SeqCst); + let hook = HOOK.swap(ptr::null_mut(), Ordering::Acquire); if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } } } @@ -362,7 +362,7 @@ fn default_alloc_error_hook(layout: Layout) { #[alloc_error_handler] #[unstable(feature = "alloc_internals", issue = "none")] pub fn rust_oom(layout: Layout) -> ! { - let hook = HOOK.load(Ordering::SeqCst); + let hook = HOOK.load(Ordering::Acquire); let hook: fn(Layout) = if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } }; hook(layout); diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index 627befb63a1..2cc9afe9249 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -1101,7 +1101,7 @@ where /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_confusables("push", "append")] + #[rustc_confusables("push", "append", "put")] pub fn insert(&mut self, k: K, v: V) -> Option<V> { self.base.insert(k, v) } diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 371201ff44c..3910100f212 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -885,7 +885,7 @@ where /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_confusables("push", "append")] + #[rustc_confusables("push", "append", "put")] pub fn insert(&mut self, value: T) -> bool { self.base.insert(value) } diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index a65e78542bf..65dec3863cc 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -1782,6 +1782,7 @@ fn windows_unix_socket_exists() { } let mut addr = c::SOCKADDR_UN { sun_family: c::AF_UNIX, sun_path: mem::zeroed() }; let bytes = socket_path.as_os_str().as_encoded_bytes(); + let bytes = core::slice::from_raw_parts(bytes.as_ptr().cast::<i8>(), bytes.len()); addr.sun_path[..bytes.len()].copy_from_slice(bytes); let len = mem::size_of_val(&addr) as i32; let result = c::bind(socket, ptr::addr_of!(addr).cast::<c::SOCKADDR>(), len); diff --git a/library/std/src/io/buffered/bufreader.rs b/library/std/src/io/buffered/bufreader.rs index 83db332ee25..acaa7e9228e 100644 --- a/library/std/src/io/buffered/bufreader.rs +++ b/library/std/src/io/buffered/bufreader.rs @@ -328,10 +328,9 @@ impl<R: ?Sized + Read> Read for BufReader<R> { self.discard_buffer(); return self.inner.read_vectored(bufs); } - let nread = { - let mut rem = self.fill_buf()?; - rem.read_vectored(bufs)? - }; + let mut rem = self.fill_buf()?; + let nread = rem.read_vectored(bufs)?; + self.consume(nread); Ok(nread) } diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 7ae15e0fd01..85625116d02 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -83,7 +83,7 @@ impl From<alloc::ffi::NulError> for Error { } } -#[stable(feature = "io_error_from_try_reserve", since = "CURRENT_RUSTC_VERSION")] +#[stable(feature = "io_error_from_try_reserve", since = "1.78.0")] impl From<alloc::collections::TryReserveError> for Error { /// Converts `TryReserveError` to an error with [`ErrorKind::OutOfMemory`]. /// diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index ccc2ed91688..8f60b3b1535 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -453,7 +453,7 @@ impl Read for Stdin { } } -#[stable(feature = "read_shared_stdin", since = "CURRENT_RUSTC_VERSION")] +#[stable(feature = "read_shared_stdin", since = "1.78.0")] impl Read for &Stdin { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.lock().read(buf) diff --git a/library/std/src/keyword_docs.rs b/library/std/src/keyword_docs.rs index 873bfb6218b..8415f36eba2 100644 --- a/library/std/src/keyword_docs.rs +++ b/library/std/src/keyword_docs.rs @@ -48,7 +48,7 @@ mod as_keyword {} #[doc(keyword = "break")] // -/// Exit early from a loop. +/// Exit early from a loop or labelled block. /// /// When `break` is encountered, execution of the associated loop body is /// immediately terminated. diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 3db5cda83b7..c457c39e0c1 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -270,9 +270,6 @@ // // Language features: // tidy-alphabetical-start -#![cfg_attr(bootstrap, feature(exhaustive_patterns))] -#![cfg_attr(bootstrap, feature(platform_intrinsics))] -#![cfg_attr(not(bootstrap), feature(min_exhaustive_patterns))] #![feature(alloc_error_handler)] #![feature(allocator_internals)] #![feature(allow_internal_unsafe)] @@ -297,6 +294,7 @@ #![feature(let_chains)] #![feature(link_cfg)] #![feature(linkage)] +#![feature(min_exhaustive_patterns)] #![feature(min_specialization)] #![feature(must_not_suspend)] #![feature(needs_panic_runtime)] diff --git a/library/std/src/net/test.rs b/library/std/src/net/test.rs index 37937b5ea95..d318d457f35 100644 --- a/library/std/src/net/test.rs +++ b/library/std/src/net/test.rs @@ -7,12 +7,12 @@ use crate::sync::atomic::{AtomicUsize, Ordering}; static PORT: AtomicUsize = AtomicUsize::new(0); pub fn next_test_ip4() -> SocketAddr { - let port = PORT.fetch_add(1, Ordering::SeqCst) as u16 + base_port(); + let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + base_port(); SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port)) } pub fn next_test_ip6() -> SocketAddr { - let port = PORT.fetch_add(1, Ordering::SeqCst) as u16 + base_port(); + let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + base_port(); SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), port, 0, 0)) } diff --git a/library/std/src/os/freebsd/net.rs b/library/std/src/os/freebsd/net.rs index 33990d54caa..b7e0fdc0a9a 100644 --- a/library/std/src/os/freebsd/net.rs +++ b/library/std/src/os/freebsd/net.rs @@ -2,6 +2,7 @@ #![unstable(feature = "unix_socket_ancillary_data", issue = "76915")] +use crate::ffi::CStr; use crate::io; use crate::os::unix::net; use crate::sealed::Sealed; @@ -40,6 +41,15 @@ pub trait UnixSocketExt: Sealed { /// ``` #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] fn set_local_creds_persistent(&self, local_creds_persistent: bool) -> io::Result<()>; + + /// Get a filter name if one had been set previously on the socket. + #[unstable(feature = "acceptfilter", issue = "121891")] + fn acceptfilter(&self) -> io::Result<&CStr>; + + /// Set or disable a filter on the socket to filter incoming connections + /// to defer it before accept(2) + #[unstable(feature = "acceptfilter", issue = "121891")] + fn set_acceptfilter(&self, name: &CStr) -> io::Result<()>; } #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] @@ -51,6 +61,14 @@ impl UnixSocketExt for net::UnixDatagram { fn set_local_creds_persistent(&self, local_creds_persistent: bool) -> io::Result<()> { self.as_inner().set_local_creds_persistent(local_creds_persistent) } + + fn acceptfilter(&self) -> io::Result<&CStr> { + self.as_inner().acceptfilter() + } + + fn set_acceptfilter(&self, name: &CStr) -> io::Result<()> { + self.as_inner().set_acceptfilter(name) + } } #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] @@ -62,4 +80,12 @@ impl UnixSocketExt for net::UnixStream { fn set_local_creds_persistent(&self, local_creds_persistent: bool) -> io::Result<()> { self.as_inner().set_local_creds_persistent(local_creds_persistent) } + + fn acceptfilter(&self) -> io::Result<&CStr> { + self.as_inner().acceptfilter() + } + + fn set_acceptfilter(&self, name: &CStr) -> io::Result<()> { + self.as_inner().set_acceptfilter(name) + } } diff --git a/library/std/src/os/netbsd/net.rs b/library/std/src/os/netbsd/net.rs index 5c82f43077d..b9679c7b3af 100644 --- a/library/std/src/os/netbsd/net.rs +++ b/library/std/src/os/netbsd/net.rs @@ -2,6 +2,7 @@ #![unstable(feature = "unix_socket_ancillary_data", issue = "76915")] +use crate::ffi::CStr; use crate::io; use crate::os::unix::net; use crate::sealed::Sealed; @@ -40,6 +41,15 @@ pub trait UnixSocketExt: Sealed { /// ``` #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] fn set_local_creds(&self, local_creds: bool) -> io::Result<()>; + + /// Get a filter name if one had been set previously on the socket. + #[unstable(feature = "acceptfilter", issue = "121891")] + fn acceptfilter(&self) -> io::Result<&CStr>; + + /// Set or disable a filter on the socket to filter incoming connections + /// to defer it before accept(2) + #[unstable(feature = "acceptfilter", issue = "121891")] + fn set_acceptfilter(&self, name: &CStr) -> io::Result<()>; } #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] @@ -51,6 +61,14 @@ impl UnixSocketExt for net::UnixDatagram { fn set_local_creds(&self, local_creds: bool) -> io::Result<()> { self.as_inner().set_local_creds(local_creds) } + + fn acceptfilter(&self) -> io::Result<&CStr> { + self.as_inner().acceptfilter() + } + + fn set_acceptfilter(&self, name: &CStr) -> io::Result<()> { + self.as_inner().set_acceptfilter(name) + } } #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] @@ -62,4 +80,12 @@ impl UnixSocketExt for net::UnixStream { fn set_local_creds(&self, local_creds: bool) -> io::Result<()> { self.as_inner().set_local_creds(local_creds) } + + fn acceptfilter(&self) -> io::Result<&CStr> { + self.as_inner().acceptfilter() + } + + fn set_acceptfilter(&self, name: &CStr) -> io::Result<()> { + self.as_inner().set_acceptfilter(name) + } } diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index d2e23bdee6c..d67493aaf4d 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -8,7 +8,8 @@ target_os = "macos", target_os = "watchos", target_os = "netbsd", - target_os = "openbsd" + target_os = "openbsd", + target_os = "nto" ))] use super::{peer_cred, UCred}; #[cfg(any(doc, target_os = "android", target_os = "linux"))] @@ -234,7 +235,8 @@ impl UnixStream { target_os = "macos", target_os = "watchos", target_os = "netbsd", - target_os = "openbsd" + target_os = "openbsd", + target_os = "nto" ))] pub fn peer_cred(&self) -> io::Result<UCred> { peer_cred(self) diff --git a/library/std/src/os/unix/net/ucred.rs b/library/std/src/os/unix/net/ucred.rs index de09c93840a..4c915c57906 100644 --- a/library/std/src/os/unix/net/ucred.rs +++ b/library/std/src/os/unix/net/ucred.rs @@ -30,7 +30,8 @@ pub(super) use self::impl_linux::peer_cred; target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", - target_os = "netbsd" + target_os = "netbsd", + target_os = "nto" ))] pub(super) use self::impl_bsd::peer_cred; diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 464a46264cb..b0bcab7994c 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -272,7 +272,7 @@ fn default_hook(info: &PanicInfo<'_>) { drop(backtrace::print(err, crate::backtrace_rs::PrintFmt::Full)) } Some(BacktraceStyle::Off) => { - if FIRST_PANIC.swap(false, Ordering::SeqCst) { + if FIRST_PANIC.swap(false, Ordering::Relaxed) { let _ = writeln!( err, "note: run with `RUST_BACKTRACE=1` environment variable to display a \ diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 7a7a7737635..36fa4e88b5b 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -91,6 +91,15 @@ pub use core::prelude::v1::cfg_eval; )] pub use core::prelude::v1::type_ascribe; +#[cfg(not(bootstrap))] +// Do not `doc(no_inline)` either. +#[unstable( + feature = "deref_patterns", + issue = "87121", + reason = "placeholder syntax for deref patterns" +)] +pub use core::prelude::v1::deref; + // The file so far is equivalent to core/src/prelude/v1.rs. It is duplicated // rather than glob imported because we want docs to show these re-exports as // pointing to within `std`. diff --git a/library/std/src/sync/barrier.rs b/library/std/src/sync/barrier.rs index 764fa284794..b4bac081e7a 100644 --- a/library/std/src/sync/barrier.rs +++ b/library/std/src/sync/barrier.rs @@ -81,7 +81,7 @@ impl Barrier { /// let barrier = Barrier::new(10); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_barrier", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "const_barrier", since = "1.78.0")] #[must_use] #[inline] pub const fn new(n: usize) -> Barrier { diff --git a/library/std/src/sync/condvar/tests.rs b/library/std/src/sync/condvar/tests.rs index 24f467f0b03..12d13a6b20b 100644 --- a/library/std/src/sync/condvar/tests.rs +++ b/library/std/src/sync/condvar/tests.rs @@ -170,14 +170,14 @@ fn wait_timeout_wake() { let t = thread::spawn(move || { let _g = m2.lock().unwrap(); thread::sleep(Duration::from_millis(1)); - notified_copy.store(true, Ordering::SeqCst); + notified_copy.store(true, Ordering::Relaxed); c2.notify_one(); }); let (g, timeout_res) = c.wait_timeout(g, Duration::from_millis(u64::MAX)).unwrap(); assert!(!timeout_res.timed_out()); // spurious wakeups mean this isn't necessarily true // so execute test again, if not notified - if !notified.load(Ordering::SeqCst) { + if !notified.load(Ordering::Relaxed) { t.join().unwrap(); continue; } diff --git a/library/std/src/sys/pal/unix/net.rs b/library/std/src/sys/pal/unix/net.rs index 09750b6ffc8..1f140f7844f 100644 --- a/library/std/src/sys/pal/unix/net.rs +++ b/library/std/src/sys/pal/unix/net.rs @@ -453,6 +453,37 @@ impl Socket { Ok(raw as u32) } + #[cfg(any(target_os = "freebsd", target_os = "netbsd"))] + pub fn set_acceptfilter(&self, name: &CStr) -> io::Result<()> { + if !name.to_bytes().is_empty() { + const AF_NAME_MAX: usize = 16; + let mut buf = [0; AF_NAME_MAX]; + for (src, dst) in name.to_bytes().iter().zip(&mut buf[..AF_NAME_MAX - 1]) { + *dst = *src as i8; + } + let mut arg: libc::accept_filter_arg = unsafe { mem::zeroed() }; + arg.af_name = buf; + setsockopt(self, libc::SOL_SOCKET, libc::SO_ACCEPTFILTER, &mut arg) + } else { + setsockopt( + self, + libc::SOL_SOCKET, + libc::SO_ACCEPTFILTER, + core::ptr::null_mut() as *mut c_void, + ) + } + } + + #[cfg(any(target_os = "freebsd", target_os = "netbsd"))] + pub fn acceptfilter(&self) -> io::Result<&CStr> { + let arg: libc::accept_filter_arg = + getsockopt(self, libc::SOL_SOCKET, libc::SO_ACCEPTFILTER)?; + let s: &[u8] = + unsafe { core::slice::from_raw_parts(arg.af_name.as_ptr() as *const u8, 16) }; + let name = CStr::from_bytes_with_nul(s).unwrap(); + Ok(name) + } + #[cfg(any(target_os = "android", target_os = "linux",))] pub fn set_passcred(&self, passcred: bool) -> io::Result<()> { setsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED, passcred as libc::c_int) diff --git a/library/std/src/sys/pal/unix/thread_parking/pthread.rs b/library/std/src/sys/pal/unix/thread_parking/pthread.rs index ae805d84399..bb79cf9548e 100644 --- a/library/std/src/sys/pal/unix/thread_parking/pthread.rs +++ b/library/std/src/sys/pal/unix/thread_parking/pthread.rs @@ -5,7 +5,7 @@ use crate::marker::PhantomPinned; use crate::pin::Pin; use crate::ptr::addr_of_mut; use crate::sync::atomic::AtomicUsize; -use crate::sync::atomic::Ordering::SeqCst; +use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release}; #[cfg(not(target_os = "nto"))] use crate::sys::time::TIMESPEC_MAX; #[cfg(target_os = "nto")] @@ -150,16 +150,18 @@ impl Parker { // This implementation doesn't require `unsafe`, but other implementations // may assume this is only called by the thread that owns the Parker. + // + // For memory ordering, see std/src/sys_common/thread_parking/futex.rs pub unsafe fn park(self: Pin<&Self>) { // If we were previously notified then we consume this notification and // return quickly. - if self.state.compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst).is_ok() { + if self.state.compare_exchange(NOTIFIED, EMPTY, Acquire, Relaxed).is_ok() { return; } // Otherwise we need to coordinate going to sleep lock(self.lock.get()); - match self.state.compare_exchange(EMPTY, PARKED, SeqCst, SeqCst) { + match self.state.compare_exchange(EMPTY, PARKED, Relaxed, Relaxed) { Ok(_) => {} Err(NOTIFIED) => { // We must read here, even though we know it will be `NOTIFIED`. @@ -168,7 +170,7 @@ impl Parker { // acquire operation that synchronizes with that `unpark` to observe // any writes it made before the call to unpark. To do that we must // read from the write it made to `state`. - let old = self.state.swap(EMPTY, SeqCst); + let old = self.state.swap(EMPTY, Acquire); unlock(self.lock.get()); @@ -185,7 +187,7 @@ impl Parker { loop { wait(self.cvar.get(), self.lock.get()); - match self.state.compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst) { + match self.state.compare_exchange(NOTIFIED, EMPTY, Acquire, Relaxed) { Ok(_) => break, // got a notification Err(_) => {} // spurious wakeup, go back to sleep } @@ -201,16 +203,16 @@ impl Parker { // Like `park` above we have a fast path for an already-notified thread, and // afterwards we start coordinating for a sleep. // return quickly. - if self.state.compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst).is_ok() { + if self.state.compare_exchange(NOTIFIED, EMPTY, Acquire, Relaxed).is_ok() { return; } lock(self.lock.get()); - match self.state.compare_exchange(EMPTY, PARKED, SeqCst, SeqCst) { + match self.state.compare_exchange(EMPTY, PARKED, Relaxed, Relaxed) { Ok(_) => {} Err(NOTIFIED) => { // We must read again here, see `park`. - let old = self.state.swap(EMPTY, SeqCst); + let old = self.state.swap(EMPTY, Acquire); unlock(self.lock.get()); assert_eq!(old, NOTIFIED, "park state changed unexpectedly"); @@ -228,7 +230,7 @@ impl Parker { // parked. wait_timeout(self.cvar.get(), self.lock.get(), dur); - match self.state.swap(EMPTY, SeqCst) { + match self.state.swap(EMPTY, Acquire) { NOTIFIED => unlock(self.lock.get()), // got a notification, hurray! PARKED => unlock(self.lock.get()), // no notification, alas n => { @@ -245,7 +247,7 @@ impl Parker { // `state` is already `NOTIFIED`. That is why this must be a swap // rather than a compare-and-swap that returns if it reads `NOTIFIED` // on failure. - match self.state.swap(NOTIFIED, SeqCst) { + match self.state.swap(NOTIFIED, Release) { EMPTY => return, // no one was waiting NOTIFIED => return, // already unparked PARKED => {} // gotta go wake someone up diff --git a/library/std/src/sys/pal/wasm/alloc.rs b/library/std/src/sys/pal/wasm/alloc.rs index 6dceb1689a8..b74ce0d4742 100644 --- a/library/std/src/sys/pal/wasm/alloc.rs +++ b/library/std/src/sys/pal/wasm/alloc.rs @@ -57,7 +57,10 @@ unsafe impl GlobalAlloc for System { #[cfg(target_feature = "atomics")] mod lock { - use crate::sync::atomic::{AtomicI32, Ordering::SeqCst}; + use crate::sync::atomic::{ + AtomicI32, + Ordering::{Acquire, Release}, + }; static LOCKED: AtomicI32 = AtomicI32::new(0); @@ -65,7 +68,7 @@ mod lock { pub fn lock() -> DropLock { loop { - if LOCKED.swap(1, SeqCst) == 0 { + if LOCKED.swap(1, Acquire) == 0 { return DropLock; } // Ok so here's where things get a little depressing. At this point @@ -143,7 +146,7 @@ mod lock { impl Drop for DropLock { fn drop(&mut self) { - let r = LOCKED.swap(0, SeqCst); + let r = LOCKED.swap(0, Release); debug_assert_eq!(r, 1); // Note that due to the above logic we don't actually need to wake diff --git a/library/std/src/sys/pal/windows/c/windows_sys.rs b/library/std/src/sys/pal/windows/c/windows_sys.rs index baaa8257d84..d180122d735 100644 --- a/library/std/src/sys/pal/windows/c/windows_sys.rs +++ b/library/std/src/sys/pal/windows/c/windows_sys.rs @@ -1,4 +1,4 @@ -// Bindings generated by `windows-bindgen` 0.52.0 +// Bindings generated by `windows-bindgen` 0.55.0 #![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, clippy::all)] #[link(name = "advapi32")] @@ -12,16 +12,15 @@ extern "system" { #[link(name = "advapi32")] extern "system" { #[link_name = "SystemFunction036"] - pub fn RtlGenRandom(randombuffer: *mut ::core::ffi::c_void, randombufferlength: u32) - -> BOOLEAN; + pub fn RtlGenRandom(randombuffer: *mut core::ffi::c_void, randombufferlength: u32) -> BOOLEAN; } #[link(name = "kernel32")] extern "system" { - pub fn AcquireSRWLockExclusive(srwlock: *mut SRWLOCK) -> (); + pub fn AcquireSRWLockExclusive(srwlock: *mut SRWLOCK); } #[link(name = "kernel32")] extern "system" { - pub fn AcquireSRWLockShared(srwlock: *mut SRWLOCK) -> (); + pub fn AcquireSRWLockShared(srwlock: *mut SRWLOCK); } #[link(name = "kernel32")] extern "system" { @@ -47,7 +46,7 @@ extern "system" { lpexistingfilename: PCWSTR, lpnewfilename: PCWSTR, lpprogressroutine: LPPROGRESS_ROUTINE, - lpdata: *const ::core::ffi::c_void, + lpdata: *const core::ffi::c_void, pbcancel: *mut BOOL, dwcopyflags: u32, ) -> BOOL; @@ -110,7 +109,7 @@ extern "system" { lpthreadattributes: *const SECURITY_ATTRIBUTES, binherithandles: BOOL, dwcreationflags: PROCESS_CREATION_FLAGS, - lpenvironment: *const ::core::ffi::c_void, + lpenvironment: *const core::ffi::c_void, lpcurrentdirectory: PCWSTR, lpstartupinfo: *const STARTUPINFOW, lpprocessinformation: *mut PROCESS_INFORMATION, @@ -130,7 +129,7 @@ extern "system" { lpthreadattributes: *const SECURITY_ATTRIBUTES, dwstacksize: usize, lpstartaddress: LPTHREAD_START_ROUTINE, - lpparameter: *const ::core::ffi::c_void, + lpparameter: *const core::ffi::c_void, dwcreationflags: THREAD_CREATION_FLAGS, lpthreadid: *mut u32, ) -> HANDLE; @@ -150,16 +149,16 @@ extern "system" { } #[link(name = "kernel32")] extern "system" { - pub fn DeleteProcThreadAttributeList(lpattributelist: LPPROC_THREAD_ATTRIBUTE_LIST) -> (); + pub fn DeleteProcThreadAttributeList(lpattributelist: LPPROC_THREAD_ATTRIBUTE_LIST); } #[link(name = "kernel32")] extern "system" { pub fn DeviceIoControl( hdevice: HANDLE, dwiocontrolcode: u32, - lpinbuffer: *const ::core::ffi::c_void, + lpinbuffer: *const core::ffi::c_void, ninbuffersize: u32, - lpoutbuffer: *mut ::core::ffi::c_void, + lpoutbuffer: *mut core::ffi::c_void, noutbuffersize: u32, lpbytesreturned: *mut u32, lpoverlapped: *mut OVERLAPPED, @@ -201,7 +200,7 @@ extern "system" { extern "system" { pub fn FormatMessageW( dwflags: FORMAT_MESSAGE_OPTIONS, - lpsource: *const ::core::ffi::c_void, + lpsource: *const core::ffi::c_void, dwmessageid: u32, dwlanguageid: u32, lpbuffer: PWSTR, @@ -269,7 +268,7 @@ extern "system" { pub fn GetFileInformationByHandleEx( hfile: HANDLE, fileinformationclass: FILE_INFO_BY_HANDLE_CLASS, - lpfileinformation: *mut ::core::ffi::c_void, + lpfileinformation: *mut core::ffi::c_void, dwbuffersize: u32, ) -> BOOL; } @@ -338,11 +337,11 @@ extern "system" { } #[link(name = "kernel32")] extern "system" { - pub fn GetSystemInfo(lpsysteminfo: *mut SYSTEM_INFO) -> (); + pub fn GetSystemInfo(lpsysteminfo: *mut SYSTEM_INFO); } #[link(name = "kernel32")] extern "system" { - pub fn GetSystemTimeAsFileTime(lpsystemtimeasfiletime: *mut FILETIME) -> (); + pub fn GetSystemTimeAsFileTime(lpsystemtimeasfiletime: *mut FILETIME); } #[link(name = "kernel32")] extern "system" { @@ -362,7 +361,7 @@ extern "system" { lpinitonce: *mut INIT_ONCE, dwflags: u32, fpending: *mut BOOL, - lpcontext: *mut *mut ::core::ffi::c_void, + lpcontext: *mut *mut core::ffi::c_void, ) -> BOOL; } #[link(name = "kernel32")] @@ -370,7 +369,7 @@ extern "system" { pub fn InitOnceComplete( lpinitonce: *mut INIT_ONCE, dwflags: u32, - lpcontext: *const ::core::ffi::c_void, + lpcontext: *const core::ffi::c_void, ) -> BOOL; } #[link(name = "kernel32")] @@ -417,7 +416,7 @@ extern "system" { extern "system" { pub fn ReadConsoleW( hconsoleinput: HANDLE, - lpbuffer: *mut ::core::ffi::c_void, + lpbuffer: *mut core::ffi::c_void, nnumberofcharstoread: u32, lpnumberofcharsread: *mut u32, pinputcontrol: *const CONSOLE_READCONSOLE_CONTROL, @@ -445,11 +444,11 @@ extern "system" { } #[link(name = "kernel32")] extern "system" { - pub fn ReleaseSRWLockExclusive(srwlock: *mut SRWLOCK) -> (); + pub fn ReleaseSRWLockExclusive(srwlock: *mut SRWLOCK); } #[link(name = "kernel32")] extern "system" { - pub fn ReleaseSRWLockShared(srwlock: *mut SRWLOCK) -> (); + pub fn ReleaseSRWLockShared(srwlock: *mut SRWLOCK); } #[link(name = "kernel32")] extern "system" { @@ -475,7 +474,7 @@ extern "system" { pub fn SetFileInformationByHandle( hfile: HANDLE, fileinformationclass: FILE_INFO_BY_HANDLE_CLASS, - lpfileinformation: *const ::core::ffi::c_void, + lpfileinformation: *const core::ffi::c_void, dwbuffersize: u32, ) -> BOOL; } @@ -503,7 +502,7 @@ extern "system" { } #[link(name = "kernel32")] extern "system" { - pub fn SetLastError(dwerrcode: WIN32_ERROR) -> (); + pub fn SetLastError(dwerrcode: WIN32_ERROR); } #[link(name = "kernel32")] extern "system" { @@ -516,13 +515,13 @@ extern "system" { lpduetime: *const i64, lperiod: i32, pfncompletionroutine: PTIMERAPCROUTINE, - lpargtocompletionroutine: *const ::core::ffi::c_void, + lpargtocompletionroutine: *const core::ffi::c_void, fresume: BOOL, ) -> BOOL; } #[link(name = "kernel32")] extern "system" { - pub fn Sleep(dwmilliseconds: u32) -> (); + pub fn Sleep(dwmilliseconds: u32); } #[link(name = "kernel32")] extern "system" { @@ -555,11 +554,11 @@ extern "system" { } #[link(name = "kernel32")] extern "system" { - pub fn TlsGetValue(dwtlsindex: u32) -> *mut ::core::ffi::c_void; + pub fn TlsGetValue(dwtlsindex: u32) -> *mut core::ffi::c_void; } #[link(name = "kernel32")] extern "system" { - pub fn TlsSetValue(dwtlsindex: u32, lptlsvalue: *const ::core::ffi::c_void) -> BOOL; + pub fn TlsSetValue(dwtlsindex: u32, lptlsvalue: *const core::ffi::c_void) -> BOOL; } #[link(name = "kernel32")] extern "system" { @@ -575,9 +574,9 @@ extern "system" { lpattributelist: LPPROC_THREAD_ATTRIBUTE_LIST, dwflags: u32, attribute: usize, - lpvalue: *const ::core::ffi::c_void, + lpvalue: *const core::ffi::c_void, cbsize: usize, - lppreviousvalue: *mut ::core::ffi::c_void, + lppreviousvalue: *mut core::ffi::c_void, lpreturnsize: *const usize, ) -> BOOL; } @@ -596,11 +595,11 @@ extern "system" { } #[link(name = "kernel32")] extern "system" { - pub fn WakeAllConditionVariable(conditionvariable: *mut CONDITION_VARIABLE) -> (); + pub fn WakeAllConditionVariable(conditionvariable: *mut CONDITION_VARIABLE); } #[link(name = "kernel32")] extern "system" { - pub fn WakeConditionVariable(conditionvariable: *mut CONDITION_VARIABLE) -> (); + pub fn WakeConditionVariable(conditionvariable: *mut CONDITION_VARIABLE); } #[link(name = "kernel32")] extern "system" { @@ -619,10 +618,10 @@ extern "system" { extern "system" { pub fn WriteConsoleW( hconsoleoutput: HANDLE, - lpbuffer: *const ::core::ffi::c_void, + lpbuffer: *const core::ffi::c_void, nnumberofcharstowrite: u32, lpnumberofcharswritten: *mut u32, - lpreserved: *const ::core::ffi::c_void, + lpreserved: *const core::ffi::c_void, ) -> BOOL; } #[link(name = "kernel32")] @@ -647,7 +646,7 @@ extern "system" { shareaccess: FILE_SHARE_MODE, createdisposition: NTCREATEFILE_CREATE_DISPOSITION, createoptions: NTCREATEFILE_CREATE_OPTIONS, - eabuffer: *const ::core::ffi::c_void, + eabuffer: *const core::ffi::c_void, ealength: u32, ) -> NTSTATUS; } @@ -657,9 +656,9 @@ extern "system" { filehandle: HANDLE, event: HANDLE, apcroutine: PIO_APC_ROUTINE, - apccontext: *const ::core::ffi::c_void, + apccontext: *const core::ffi::c_void, iostatusblock: *mut IO_STATUS_BLOCK, - buffer: *mut ::core::ffi::c_void, + buffer: *mut core::ffi::c_void, length: u32, byteoffset: *const i64, key: *const u32, @@ -671,9 +670,9 @@ extern "system" { filehandle: HANDLE, event: HANDLE, apcroutine: PIO_APC_ROUTINE, - apccontext: *const ::core::ffi::c_void, + apccontext: *const core::ffi::c_void, iostatusblock: *mut IO_STATUS_BLOCK, - buffer: *const ::core::ffi::c_void, + buffer: *const core::ffi::c_void, length: u32, byteoffset: *const i64, key: *const u32, @@ -760,7 +759,7 @@ extern "system" { } #[link(name = "ws2_32")] extern "system" { - pub fn freeaddrinfo(paddrinfo: *const ADDRINFOA) -> (); + pub fn freeaddrinfo(paddrinfo: *const ADDRINFOA); } #[link(name = "ws2_32")] extern "system" { @@ -852,8 +851,8 @@ pub struct ADDRINFOA { pub ai_addr: *mut SOCKADDR, pub ai_next: *mut ADDRINFOA, } -impl ::core::marker::Copy for ADDRINFOA {} -impl ::core::clone::Clone for ADDRINFOA { +impl Copy for ADDRINFOA {} +impl Clone for ADDRINFOA { fn clone(&self) -> Self { *self } @@ -871,8 +870,8 @@ pub union ARM64_NT_NEON128 { pub H: [u16; 8], pub B: [u8; 16], } -impl ::core::marker::Copy for ARM64_NT_NEON128 {} -impl ::core::clone::Clone for ARM64_NT_NEON128 { +impl Copy for ARM64_NT_NEON128 {} +impl Clone for ARM64_NT_NEON128 { fn clone(&self) -> Self { *self } @@ -882,8 +881,8 @@ pub struct ARM64_NT_NEON128_0 { pub Low: u64, pub High: i64, } -impl ::core::marker::Copy for ARM64_NT_NEON128_0 {} -impl ::core::clone::Clone for ARM64_NT_NEON128_0 { +impl Copy for ARM64_NT_NEON128_0 {} +impl Clone for ARM64_NT_NEON128_0 { fn clone(&self) -> Self { *self } @@ -904,8 +903,8 @@ pub struct BY_HANDLE_FILE_INFORMATION { pub nFileIndexHigh: u32, pub nFileIndexLow: u32, } -impl ::core::marker::Copy for BY_HANDLE_FILE_INFORMATION {} -impl ::core::clone::Clone for BY_HANDLE_FILE_INFORMATION { +impl Copy for BY_HANDLE_FILE_INFORMATION {} +impl Clone for BY_HANDLE_FILE_INFORMATION { fn clone(&self) -> Self { *self } @@ -915,10 +914,10 @@ pub const CALLBACK_STREAM_SWITCH: LPPROGRESS_ROUTINE_CALLBACK_REASON = 1u32; pub type COMPARESTRING_RESULT = i32; #[repr(C)] pub struct CONDITION_VARIABLE { - pub Ptr: *mut ::core::ffi::c_void, + pub Ptr: *mut core::ffi::c_void, } -impl ::core::marker::Copy for CONDITION_VARIABLE {} -impl ::core::clone::Clone for CONDITION_VARIABLE { +impl Copy for CONDITION_VARIABLE {} +impl Clone for CONDITION_VARIABLE { fn clone(&self) -> Self { *self } @@ -931,8 +930,8 @@ pub struct CONSOLE_READCONSOLE_CONTROL { pub dwCtrlWakeupMask: u32, pub dwControlKeyState: u32, } -impl ::core::marker::Copy for CONSOLE_READCONSOLE_CONTROL {} -impl ::core::clone::Clone for CONSOLE_READCONSOLE_CONTROL { +impl Copy for CONSOLE_READCONSOLE_CONTROL {} +impl Clone for CONSOLE_READCONSOLE_CONTROL { fn clone(&self) -> Self { *self } @@ -954,9 +953,9 @@ pub struct CONTEXT { pub Wvr: [u64; 2], } #[cfg(target_arch = "aarch64")] -impl ::core::marker::Copy for CONTEXT {} +impl Copy for CONTEXT {} #[cfg(target_arch = "aarch64")] -impl ::core::clone::Clone for CONTEXT { +impl Clone for CONTEXT { fn clone(&self) -> Self { *self } @@ -968,9 +967,9 @@ pub union CONTEXT_0 { pub X: [u64; 31], } #[cfg(target_arch = "aarch64")] -impl ::core::marker::Copy for CONTEXT_0 {} +impl Copy for CONTEXT_0 {} #[cfg(target_arch = "aarch64")] -impl ::core::clone::Clone for CONTEXT_0 { +impl Clone for CONTEXT_0 { fn clone(&self) -> Self { *self } @@ -1011,9 +1010,9 @@ pub struct CONTEXT_0_0 { pub Lr: u64, } #[cfg(target_arch = "aarch64")] -impl ::core::marker::Copy for CONTEXT_0_0 {} +impl Copy for CONTEXT_0_0 {} #[cfg(target_arch = "aarch64")] -impl ::core::clone::Clone for CONTEXT_0_0 { +impl Clone for CONTEXT_0_0 { fn clone(&self) -> Self { *self } @@ -1069,9 +1068,9 @@ pub struct CONTEXT { pub LastExceptionFromRip: u64, } #[cfg(target_arch = "x86_64")] -impl ::core::marker::Copy for CONTEXT {} +impl Copy for CONTEXT {} #[cfg(target_arch = "x86_64")] -impl ::core::clone::Clone for CONTEXT { +impl Clone for CONTEXT { fn clone(&self) -> Self { *self } @@ -1083,9 +1082,9 @@ pub union CONTEXT_0 { pub Anonymous: CONTEXT_0_0, } #[cfg(target_arch = "x86_64")] -impl ::core::marker::Copy for CONTEXT_0 {} +impl Copy for CONTEXT_0 {} #[cfg(target_arch = "x86_64")] -impl ::core::clone::Clone for CONTEXT_0 { +impl Clone for CONTEXT_0 { fn clone(&self) -> Self { *self } @@ -1113,9 +1112,9 @@ pub struct CONTEXT_0_0 { pub Xmm15: M128A, } #[cfg(target_arch = "x86_64")] -impl ::core::marker::Copy for CONTEXT_0_0 {} +impl Copy for CONTEXT_0_0 {} #[cfg(target_arch = "x86_64")] -impl ::core::clone::Clone for CONTEXT_0_0 { +impl Clone for CONTEXT_0_0 { fn clone(&self) -> Self { *self } @@ -1150,9 +1149,9 @@ pub struct CONTEXT { pub ExtendedRegisters: [u8; 512], } #[cfg(target_arch = "x86")] -impl ::core::marker::Copy for CONTEXT {} +impl Copy for CONTEXT {} #[cfg(target_arch = "x86")] -impl ::core::clone::Clone for CONTEXT { +impl Clone for CONTEXT { fn clone(&self) -> Self { *self } @@ -3073,19 +3072,19 @@ pub struct EXCEPTION_RECORD { pub ExceptionCode: NTSTATUS, pub ExceptionFlags: u32, pub ExceptionRecord: *mut EXCEPTION_RECORD, - pub ExceptionAddress: *mut ::core::ffi::c_void, + pub ExceptionAddress: *mut core::ffi::c_void, pub NumberParameters: u32, pub ExceptionInformation: [usize; 15], } -impl ::core::marker::Copy for EXCEPTION_RECORD {} -impl ::core::clone::Clone for EXCEPTION_RECORD { +impl Copy for EXCEPTION_RECORD {} +impl Clone for EXCEPTION_RECORD { fn clone(&self) -> Self { *self } } -pub const EXCEPTION_STACK_OVERFLOW: NTSTATUS = -1073741571i32; +pub const EXCEPTION_STACK_OVERFLOW: NTSTATUS = 0xC00000FD_u32 as _; pub const EXTENDED_STARTUPINFO_PRESENT: PROCESS_CREATION_FLAGS = 524288u32; -pub const E_NOTIMPL: HRESULT = -2147467263i32; +pub const E_NOTIMPL: HRESULT = 0x80004001_u32 as _; pub const ExceptionCollidedUnwind: EXCEPTION_DISPOSITION = 3i32; pub const ExceptionContinueExecution: EXCEPTION_DISPOSITION = 0i32; pub const ExceptionContinueSearch: EXCEPTION_DISPOSITION = 1i32; @@ -3093,15 +3092,15 @@ pub const ExceptionNestedException: EXCEPTION_DISPOSITION = 2i32; pub type FACILITY_CODE = u32; pub const FACILITY_NT_BIT: FACILITY_CODE = 268435456u32; pub const FALSE: BOOL = 0i32; -pub type FARPROC = ::core::option::Option<unsafe extern "system" fn() -> isize>; +pub type FARPROC = Option<unsafe extern "system" fn() -> isize>; pub const FAST_FAIL_FATAL_APP_EXIT: u32 = 7u32; #[repr(C)] pub struct FD_SET { pub fd_count: u32, pub fd_array: [SOCKET; 64], } -impl ::core::marker::Copy for FD_SET {} -impl ::core::clone::Clone for FD_SET { +impl Copy for FD_SET {} +impl Clone for FD_SET { fn clone(&self) -> Self { *self } @@ -3111,8 +3110,8 @@ pub struct FILETIME { pub dwLowDateTime: u32, pub dwHighDateTime: u32, } -impl ::core::marker::Copy for FILETIME {} -impl ::core::clone::Clone for FILETIME { +impl Copy for FILETIME {} +impl Clone for FILETIME { fn clone(&self) -> Self { *self } @@ -3124,8 +3123,8 @@ pub const FILE_ADD_SUBDIRECTORY: FILE_ACCESS_RIGHTS = 4u32; pub struct FILE_ALLOCATION_INFO { pub AllocationSize: i64, } -impl ::core::marker::Copy for FILE_ALLOCATION_INFO {} -impl ::core::clone::Clone for FILE_ALLOCATION_INFO { +impl Copy for FILE_ALLOCATION_INFO {} +impl Clone for FILE_ALLOCATION_INFO { fn clone(&self) -> Self { *self } @@ -3156,8 +3155,8 @@ pub struct FILE_ATTRIBUTE_TAG_INFO { pub FileAttributes: u32, pub ReparseTag: u32, } -impl ::core::marker::Copy for FILE_ATTRIBUTE_TAG_INFO {} -impl ::core::clone::Clone for FILE_ATTRIBUTE_TAG_INFO { +impl Copy for FILE_ATTRIBUTE_TAG_INFO {} +impl Clone for FILE_ATTRIBUTE_TAG_INFO { fn clone(&self) -> Self { *self } @@ -3173,8 +3172,8 @@ pub struct FILE_BASIC_INFO { pub ChangeTime: i64, pub FileAttributes: u32, } -impl ::core::marker::Copy for FILE_BASIC_INFO {} -impl ::core::clone::Clone for FILE_BASIC_INFO { +impl Copy for FILE_BASIC_INFO {} +impl Clone for FILE_BASIC_INFO { fn clone(&self) -> Self { *self } @@ -3201,8 +3200,8 @@ pub const FILE_DISPOSITION_FLAG_POSIX_SEMANTICS: FILE_DISPOSITION_INFO_EX_FLAGS pub struct FILE_DISPOSITION_INFO { pub DeleteFile: BOOLEAN, } -impl ::core::marker::Copy for FILE_DISPOSITION_INFO {} -impl ::core::clone::Clone for FILE_DISPOSITION_INFO { +impl Copy for FILE_DISPOSITION_INFO {} +impl Clone for FILE_DISPOSITION_INFO { fn clone(&self) -> Self { *self } @@ -3211,8 +3210,8 @@ impl ::core::clone::Clone for FILE_DISPOSITION_INFO { pub struct FILE_DISPOSITION_INFO_EX { pub Flags: FILE_DISPOSITION_INFO_EX_FLAGS, } -impl ::core::marker::Copy for FILE_DISPOSITION_INFO_EX {} -impl ::core::clone::Clone for FILE_DISPOSITION_INFO_EX { +impl Copy for FILE_DISPOSITION_INFO_EX {} +impl Clone for FILE_DISPOSITION_INFO_EX { fn clone(&self) -> Self { *self } @@ -3223,8 +3222,8 @@ pub const FILE_END: SET_FILE_POINTER_MOVE_METHOD = 2u32; pub struct FILE_END_OF_FILE_INFO { pub EndOfFile: i64, } -impl ::core::marker::Copy for FILE_END_OF_FILE_INFO {} -impl ::core::clone::Clone for FILE_END_OF_FILE_INFO { +impl Copy for FILE_END_OF_FILE_INFO {} +impl Clone for FILE_END_OF_FILE_INFO { fn clone(&self) -> Self { *self } @@ -3264,8 +3263,8 @@ pub struct FILE_ID_BOTH_DIR_INFO { pub FileId: i64, pub FileName: [u16; 1], } -impl ::core::marker::Copy for FILE_ID_BOTH_DIR_INFO {} -impl ::core::clone::Clone for FILE_ID_BOTH_DIR_INFO { +impl Copy for FILE_ID_BOTH_DIR_INFO {} +impl Clone for FILE_ID_BOTH_DIR_INFO { fn clone(&self) -> Self { *self } @@ -3275,8 +3274,8 @@ pub type FILE_INFO_BY_HANDLE_CLASS = i32; pub struct FILE_IO_PRIORITY_HINT_INFO { pub PriorityHint: PRIORITY_HINT, } -impl ::core::marker::Copy for FILE_IO_PRIORITY_HINT_INFO {} -impl ::core::clone::Clone for FILE_IO_PRIORITY_HINT_INFO { +impl Copy for FILE_IO_PRIORITY_HINT_INFO {} +impl Clone for FILE_IO_PRIORITY_HINT_INFO { fn clone(&self) -> Self { *self } @@ -3318,8 +3317,8 @@ pub struct FILE_STANDARD_INFO { pub DeletePending: BOOLEAN, pub Directory: BOOLEAN, } -impl ::core::marker::Copy for FILE_STANDARD_INFO {} -impl ::core::clone::Clone for FILE_STANDARD_INFO { +impl Copy for FILE_STANDARD_INFO {} +impl Clone for FILE_STANDARD_INFO { fn clone(&self) -> Self { *self } @@ -3353,9 +3352,9 @@ pub struct FLOATING_SAVE_AREA { pub Cr0NpxState: u32, } #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] -impl ::core::marker::Copy for FLOATING_SAVE_AREA {} +impl Copy for FLOATING_SAVE_AREA {} #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] -impl ::core::clone::Clone for FLOATING_SAVE_AREA { +impl Clone for FLOATING_SAVE_AREA { fn clone(&self) -> Self { *self } @@ -3374,9 +3373,9 @@ pub struct FLOATING_SAVE_AREA { pub Spare0: u32, } #[cfg(target_arch = "x86")] -impl ::core::marker::Copy for FLOATING_SAVE_AREA {} +impl Copy for FLOATING_SAVE_AREA {} #[cfg(target_arch = "x86")] -impl ::core::clone::Clone for FLOATING_SAVE_AREA { +impl Clone for FLOATING_SAVE_AREA { fn clone(&self) -> Self { *self } @@ -3429,8 +3428,8 @@ pub struct GUID { pub data3: u16, pub data4: [u8; 8], } -impl ::core::marker::Copy for GUID {} -impl ::core::clone::Clone for GUID { +impl Copy for GUID {} +impl Clone for GUID { fn clone(&self) -> Self { *self } @@ -3445,21 +3444,21 @@ impl GUID { } } } -pub type HANDLE = *mut ::core::ffi::c_void; +pub type HANDLE = *mut core::ffi::c_void; pub type HANDLE_FLAGS = u32; pub const HANDLE_FLAG_INHERIT: HANDLE_FLAGS = 1u32; pub const HANDLE_FLAG_PROTECT_FROM_CLOSE: HANDLE_FLAGS = 2u32; pub const HIGH_PRIORITY_CLASS: PROCESS_CREATION_FLAGS = 128u32; -pub type HLOCAL = *mut ::core::ffi::c_void; -pub type HMODULE = *mut ::core::ffi::c_void; +pub type HLOCAL = *mut core::ffi::c_void; +pub type HMODULE = *mut core::ffi::c_void; pub type HRESULT = i32; pub const IDLE_PRIORITY_CLASS: PROCESS_CREATION_FLAGS = 64u32; #[repr(C)] pub struct IN6_ADDR { pub u: IN6_ADDR_0, } -impl ::core::marker::Copy for IN6_ADDR {} -impl ::core::clone::Clone for IN6_ADDR { +impl Copy for IN6_ADDR {} +impl Clone for IN6_ADDR { fn clone(&self) -> Self { *self } @@ -3469,8 +3468,8 @@ pub union IN6_ADDR_0 { pub Byte: [u8; 16], pub Word: [u16; 8], } -impl ::core::marker::Copy for IN6_ADDR_0 {} -impl ::core::clone::Clone for IN6_ADDR_0 { +impl Copy for IN6_ADDR_0 {} +impl Clone for IN6_ADDR_0 { fn clone(&self) -> Self { *self } @@ -3480,10 +3479,10 @@ pub const INHERIT_CALLER_PRIORITY: PROCESS_CREATION_FLAGS = 131072u32; pub const INHERIT_PARENT_AFFINITY: PROCESS_CREATION_FLAGS = 65536u32; #[repr(C)] pub union INIT_ONCE { - pub Ptr: *mut ::core::ffi::c_void, + pub Ptr: *mut core::ffi::c_void, } -impl ::core::marker::Copy for INIT_ONCE {} -impl ::core::clone::Clone for INIT_ONCE { +impl Copy for INIT_ONCE {} +impl Clone for INIT_ONCE { fn clone(&self) -> Self { *self } @@ -3495,8 +3494,8 @@ pub const INVALID_SOCKET: SOCKET = -1i32 as _; pub struct IN_ADDR { pub S_un: IN_ADDR_0, } -impl ::core::marker::Copy for IN_ADDR {} -impl ::core::clone::Clone for IN_ADDR { +impl Copy for IN_ADDR {} +impl Clone for IN_ADDR { fn clone(&self) -> Self { *self } @@ -3507,8 +3506,8 @@ pub union IN_ADDR_0 { pub S_un_w: IN_ADDR_0_1, pub S_addr: u32, } -impl ::core::marker::Copy for IN_ADDR_0 {} -impl ::core::clone::Clone for IN_ADDR_0 { +impl Copy for IN_ADDR_0 {} +impl Clone for IN_ADDR_0 { fn clone(&self) -> Self { *self } @@ -3520,8 +3519,8 @@ pub struct IN_ADDR_0_0 { pub s_b3: u8, pub s_b4: u8, } -impl ::core::marker::Copy for IN_ADDR_0_0 {} -impl ::core::clone::Clone for IN_ADDR_0_0 { +impl Copy for IN_ADDR_0_0 {} +impl Clone for IN_ADDR_0_0 { fn clone(&self) -> Self { *self } @@ -3531,8 +3530,8 @@ pub struct IN_ADDR_0_1 { pub s_w1: u16, pub s_w2: u16, } -impl ::core::marker::Copy for IN_ADDR_0_1 {} -impl ::core::clone::Clone for IN_ADDR_0_1 { +impl Copy for IN_ADDR_0_1 {} +impl Clone for IN_ADDR_0_1 { fn clone(&self) -> Self { *self } @@ -3544,8 +3543,8 @@ pub struct IO_STATUS_BLOCK { pub Anonymous: IO_STATUS_BLOCK_0, pub Information: usize, } -impl ::core::marker::Copy for IO_STATUS_BLOCK {} -impl ::core::clone::Clone for IO_STATUS_BLOCK { +impl Copy for IO_STATUS_BLOCK {} +impl Clone for IO_STATUS_BLOCK { fn clone(&self) -> Self { *self } @@ -3553,10 +3552,10 @@ impl ::core::clone::Clone for IO_STATUS_BLOCK { #[repr(C)] pub union IO_STATUS_BLOCK_0 { pub Status: NTSTATUS, - pub Pointer: *mut ::core::ffi::c_void, + pub Pointer: *mut core::ffi::c_void, } -impl ::core::marker::Copy for IO_STATUS_BLOCK_0 {} -impl ::core::clone::Clone for IO_STATUS_BLOCK_0 { +impl Copy for IO_STATUS_BLOCK_0 {} +impl Clone for IO_STATUS_BLOCK_0 { fn clone(&self) -> Self { *self } @@ -3606,8 +3605,8 @@ pub struct IPV6_MREQ { pub ipv6mr_multiaddr: IN6_ADDR, pub ipv6mr_interface: u32, } -impl ::core::marker::Copy for IPV6_MREQ {} -impl ::core::clone::Clone for IPV6_MREQ { +impl Copy for IPV6_MREQ {} +impl Clone for IPV6_MREQ { fn clone(&self) -> Self { *self } @@ -3621,8 +3620,8 @@ pub struct IP_MREQ { pub imr_multiaddr: IN_ADDR, pub imr_interface: IN_ADDR, } -impl ::core::marker::Copy for IP_MREQ {} -impl ::core::clone::Clone for IP_MREQ { +impl Copy for IP_MREQ {} +impl Clone for IP_MREQ { fn clone(&self) -> Self { *self } @@ -3635,21 +3634,21 @@ pub struct LINGER { pub l_onoff: u16, pub l_linger: u16, } -impl ::core::marker::Copy for LINGER {} -impl ::core::clone::Clone for LINGER { +impl Copy for LINGER {} +impl Clone for LINGER { fn clone(&self) -> Self { *self } } -pub type LPOVERLAPPED_COMPLETION_ROUTINE = ::core::option::Option< +pub type LPOVERLAPPED_COMPLETION_ROUTINE = Option< unsafe extern "system" fn( dwerrorcode: u32, dwnumberofbytestransfered: u32, lpoverlapped: *mut OVERLAPPED, - ) -> (), + ), >; -pub type LPPROC_THREAD_ATTRIBUTE_LIST = *mut ::core::ffi::c_void; -pub type LPPROGRESS_ROUTINE = ::core::option::Option< +pub type LPPROC_THREAD_ATTRIBUTE_LIST = *mut core::ffi::c_void; +pub type LPPROGRESS_ROUTINE = Option< unsafe extern "system" fn( totalfilesize: i64, totalbytestransferred: i64, @@ -3659,28 +3658,27 @@ pub type LPPROGRESS_ROUTINE = ::core::option::Option< dwcallbackreason: LPPROGRESS_ROUTINE_CALLBACK_REASON, hsourcefile: HANDLE, hdestinationfile: HANDLE, - lpdata: *const ::core::ffi::c_void, + lpdata: *const core::ffi::c_void, ) -> u32, >; pub type LPPROGRESS_ROUTINE_CALLBACK_REASON = u32; -pub type LPTHREAD_START_ROUTINE = ::core::option::Option< - unsafe extern "system" fn(lpthreadparameter: *mut ::core::ffi::c_void) -> u32, ->; -pub type LPWSAOVERLAPPED_COMPLETION_ROUTINE = ::core::option::Option< +pub type LPTHREAD_START_ROUTINE = + Option<unsafe extern "system" fn(lpthreadparameter: *mut core::ffi::c_void) -> u32>; +pub type LPWSAOVERLAPPED_COMPLETION_ROUTINE = Option< unsafe extern "system" fn( dwerror: u32, cbtransferred: u32, lpoverlapped: *mut OVERLAPPED, dwflags: u32, - ) -> (), + ), >; #[repr(C)] pub struct M128A { pub Low: u64, pub High: i64, } -impl ::core::marker::Copy for M128A {} -impl ::core::clone::Clone for M128A { +impl Copy for M128A {} +impl Clone for M128A { fn clone(&self) -> Self { *self } @@ -3717,11 +3715,11 @@ pub struct OBJECT_ATTRIBUTES { pub RootDirectory: HANDLE, pub ObjectName: *const UNICODE_STRING, pub Attributes: u32, - pub SecurityDescriptor: *const ::core::ffi::c_void, - pub SecurityQualityOfService: *const ::core::ffi::c_void, + pub SecurityDescriptor: *const core::ffi::c_void, + pub SecurityQualityOfService: *const core::ffi::c_void, } -impl ::core::marker::Copy for OBJECT_ATTRIBUTES {} -impl ::core::clone::Clone for OBJECT_ATTRIBUTES { +impl Copy for OBJECT_ATTRIBUTES {} +impl Clone for OBJECT_ATTRIBUTES { fn clone(&self) -> Self { *self } @@ -3736,8 +3734,8 @@ pub struct OVERLAPPED { pub Anonymous: OVERLAPPED_0, pub hEvent: HANDLE, } -impl ::core::marker::Copy for OVERLAPPED {} -impl ::core::clone::Clone for OVERLAPPED { +impl Copy for OVERLAPPED {} +impl Clone for OVERLAPPED { fn clone(&self) -> Self { *self } @@ -3745,10 +3743,10 @@ impl ::core::clone::Clone for OVERLAPPED { #[repr(C)] pub union OVERLAPPED_0 { pub Anonymous: OVERLAPPED_0_0, - pub Pointer: *mut ::core::ffi::c_void, + pub Pointer: *mut core::ffi::c_void, } -impl ::core::marker::Copy for OVERLAPPED_0 {} -impl ::core::clone::Clone for OVERLAPPED_0 { +impl Copy for OVERLAPPED_0 {} +impl Clone for OVERLAPPED_0 { fn clone(&self) -> Self { *self } @@ -3758,20 +3756,20 @@ pub struct OVERLAPPED_0_0 { pub Offset: u32, pub OffsetHigh: u32, } -impl ::core::marker::Copy for OVERLAPPED_0_0 {} -impl ::core::clone::Clone for OVERLAPPED_0_0 { +impl Copy for OVERLAPPED_0_0 {} +impl Clone for OVERLAPPED_0_0 { fn clone(&self) -> Self { *self } } pub type PCSTR = *const u8; pub type PCWSTR = *const u16; -pub type PIO_APC_ROUTINE = ::core::option::Option< +pub type PIO_APC_ROUTINE = Option< unsafe extern "system" fn( - apccontext: *mut ::core::ffi::c_void, + apccontext: *mut core::ffi::c_void, iostatusblock: *mut IO_STATUS_BLOCK, reserved: u32, - ) -> (), + ), >; pub const PIPE_ACCEPT_REMOTE_CLIENTS: NAMED_PIPE_MODE = 0u32; pub const PIPE_ACCESS_DUPLEX: FILE_FLAGS_AND_ATTRIBUTES = 3u32; @@ -3796,8 +3794,8 @@ pub struct PROCESS_INFORMATION { pub dwProcessId: u32, pub dwThreadId: u32, } -impl ::core::marker::Copy for PROCESS_INFORMATION {} -impl ::core::clone::Clone for PROCESS_INFORMATION { +impl Copy for PROCESS_INFORMATION {} +impl Clone for PROCESS_INFORMATION { fn clone(&self) -> Self { *self } @@ -3809,12 +3807,12 @@ pub const PROFILE_SERVER: PROCESS_CREATION_FLAGS = 1073741824u32; pub const PROFILE_USER: PROCESS_CREATION_FLAGS = 268435456u32; pub const PROGRESS_CONTINUE: u32 = 0u32; pub type PSTR = *mut u8; -pub type PTIMERAPCROUTINE = ::core::option::Option< +pub type PTIMERAPCROUTINE = Option< unsafe extern "system" fn( - lpargtocompletionroutine: *const ::core::ffi::c_void, + lpargtocompletionroutine: *const core::ffi::c_void, dwtimerlowvalue: u32, dwtimerhighvalue: u32, - ) -> (), + ), >; pub type PWSTR = *mut u16; pub const READ_CONTROL: FILE_ACCESS_RIGHTS = 131072u32; @@ -3826,11 +3824,11 @@ pub const SECURITY_ANONYMOUS: FILE_FLAGS_AND_ATTRIBUTES = 0u32; #[repr(C)] pub struct SECURITY_ATTRIBUTES { pub nLength: u32, - pub lpSecurityDescriptor: *mut ::core::ffi::c_void, + pub lpSecurityDescriptor: *mut core::ffi::c_void, pub bInheritHandle: BOOL, } -impl ::core::marker::Copy for SECURITY_ATTRIBUTES {} -impl ::core::clone::Clone for SECURITY_ATTRIBUTES { +impl Copy for SECURITY_ATTRIBUTES {} +impl Clone for SECURITY_ATTRIBUTES { fn clone(&self) -> Self { *self } @@ -3847,10 +3845,10 @@ pub type SET_FILE_POINTER_MOVE_METHOD = u32; #[repr(C)] pub struct SOCKADDR { pub sa_family: ADDRESS_FAMILY, - pub sa_data: [u8; 14], + pub sa_data: [i8; 14], } -impl ::core::marker::Copy for SOCKADDR {} -impl ::core::clone::Clone for SOCKADDR { +impl Copy for SOCKADDR {} +impl Clone for SOCKADDR { fn clone(&self) -> Self { *self } @@ -3858,10 +3856,10 @@ impl ::core::clone::Clone for SOCKADDR { #[repr(C)] pub struct SOCKADDR_UN { pub sun_family: ADDRESS_FAMILY, - pub sun_path: [u8; 108], + pub sun_path: [i8; 108], } -impl ::core::marker::Copy for SOCKADDR_UN {} -impl ::core::clone::Clone for SOCKADDR_UN { +impl Copy for SOCKADDR_UN {} +impl Clone for SOCKADDR_UN { fn clone(&self) -> Self { *self } @@ -3882,10 +3880,10 @@ pub const SO_SNDTIMEO: i32 = 4101i32; pub const SPECIFIC_RIGHTS_ALL: FILE_ACCESS_RIGHTS = 65535u32; #[repr(C)] pub struct SRWLOCK { - pub Ptr: *mut ::core::ffi::c_void, + pub Ptr: *mut core::ffi::c_void, } -impl ::core::marker::Copy for SRWLOCK {} -impl ::core::clone::Clone for SRWLOCK { +impl Copy for SRWLOCK {} +impl Clone for SRWLOCK { fn clone(&self) -> Self { *self } @@ -3915,8 +3913,8 @@ pub struct STARTUPINFOEXW { pub StartupInfo: STARTUPINFOW, pub lpAttributeList: LPPROC_THREAD_ATTRIBUTE_LIST, } -impl ::core::marker::Copy for STARTUPINFOEXW {} -impl ::core::clone::Clone for STARTUPINFOEXW { +impl Copy for STARTUPINFOEXW {} +impl Clone for STARTUPINFOEXW { fn clone(&self) -> Self { *self } @@ -3942,19 +3940,19 @@ pub struct STARTUPINFOW { pub hStdOutput: HANDLE, pub hStdError: HANDLE, } -impl ::core::marker::Copy for STARTUPINFOW {} -impl ::core::clone::Clone for STARTUPINFOW { +impl Copy for STARTUPINFOW {} +impl Clone for STARTUPINFOW { fn clone(&self) -> Self { *self } } pub type STARTUPINFOW_FLAGS = u32; -pub const STATUS_DELETE_PENDING: NTSTATUS = -1073741738i32; -pub const STATUS_END_OF_FILE: NTSTATUS = -1073741807i32; -pub const STATUS_INVALID_PARAMETER: NTSTATUS = -1073741811i32; -pub const STATUS_NOT_IMPLEMENTED: NTSTATUS = -1073741822i32; -pub const STATUS_PENDING: NTSTATUS = 259i32; -pub const STATUS_SUCCESS: NTSTATUS = 0i32; +pub const STATUS_DELETE_PENDING: NTSTATUS = 0xC0000056_u32 as _; +pub const STATUS_END_OF_FILE: NTSTATUS = 0xC0000011_u32 as _; +pub const STATUS_INVALID_PARAMETER: NTSTATUS = 0xC000000D_u32 as _; +pub const STATUS_NOT_IMPLEMENTED: NTSTATUS = 0xC0000002_u32 as _; +pub const STATUS_PENDING: NTSTATUS = 0x103_u32 as _; +pub const STATUS_SUCCESS: NTSTATUS = 0x0_u32 as _; pub const STD_ERROR_HANDLE: STD_HANDLE = 4294967284u32; pub type STD_HANDLE = u32; pub const STD_INPUT_HANDLE: STD_HANDLE = 4294967286u32; @@ -3969,8 +3967,8 @@ pub const SYNCHRONIZE: FILE_ACCESS_RIGHTS = 1048576u32; pub struct SYSTEM_INFO { pub Anonymous: SYSTEM_INFO_0, pub dwPageSize: u32, - pub lpMinimumApplicationAddress: *mut ::core::ffi::c_void, - pub lpMaximumApplicationAddress: *mut ::core::ffi::c_void, + pub lpMinimumApplicationAddress: *mut core::ffi::c_void, + pub lpMaximumApplicationAddress: *mut core::ffi::c_void, pub dwActiveProcessorMask: usize, pub dwNumberOfProcessors: u32, pub dwProcessorType: u32, @@ -3978,8 +3976,8 @@ pub struct SYSTEM_INFO { pub wProcessorLevel: u16, pub wProcessorRevision: u16, } -impl ::core::marker::Copy for SYSTEM_INFO {} -impl ::core::clone::Clone for SYSTEM_INFO { +impl Copy for SYSTEM_INFO {} +impl Clone for SYSTEM_INFO { fn clone(&self) -> Self { *self } @@ -3989,8 +3987,8 @@ pub union SYSTEM_INFO_0 { pub dwOemId: u32, pub Anonymous: SYSTEM_INFO_0_0, } -impl ::core::marker::Copy for SYSTEM_INFO_0 {} -impl ::core::clone::Clone for SYSTEM_INFO_0 { +impl Copy for SYSTEM_INFO_0 {} +impl Clone for SYSTEM_INFO_0 { fn clone(&self) -> Self { *self } @@ -4000,8 +3998,8 @@ pub struct SYSTEM_INFO_0_0 { pub wProcessorArchitecture: PROCESSOR_ARCHITECTURE, pub wReserved: u16, } -impl ::core::marker::Copy for SYSTEM_INFO_0_0 {} -impl ::core::clone::Clone for SYSTEM_INFO_0_0 { +impl Copy for SYSTEM_INFO_0_0 {} +impl Clone for SYSTEM_INFO_0_0 { fn clone(&self) -> Self { *self } @@ -4017,8 +4015,8 @@ pub struct TIMEVAL { pub tv_sec: i32, pub tv_usec: i32, } -impl ::core::marker::Copy for TIMEVAL {} -impl ::core::clone::Clone for TIMEVAL { +impl Copy for TIMEVAL {} +impl Clone for TIMEVAL { fn clone(&self) -> Self { *self } @@ -4054,8 +4052,8 @@ pub struct UNICODE_STRING { pub MaximumLength: u16, pub Buffer: PWSTR, } -impl ::core::marker::Copy for UNICODE_STRING {} -impl ::core::clone::Clone for UNICODE_STRING { +impl Copy for UNICODE_STRING {} +impl Clone for UNICODE_STRING { fn clone(&self) -> Self { *self } @@ -4085,8 +4083,8 @@ pub struct WIN32_FIND_DATAW { pub cFileName: [u16; 260], pub cAlternateFileName: [u16; 14], } -impl ::core::marker::Copy for WIN32_FIND_DATAW {} -impl ::core::clone::Clone for WIN32_FIND_DATAW { +impl Copy for WIN32_FIND_DATAW {} +impl Clone for WIN32_FIND_DATAW { fn clone(&self) -> Self { *self } @@ -4101,8 +4099,8 @@ pub struct WSABUF { pub len: u32, pub buf: PSTR, } -impl ::core::marker::Copy for WSABUF {} -impl ::core::clone::Clone for WSABUF { +impl Copy for WSABUF {} +impl Clone for WSABUF { fn clone(&self) -> Self { *self } @@ -4115,13 +4113,13 @@ pub struct WSADATA { pub iMaxSockets: u16, pub iMaxUdpDg: u16, pub lpVendorInfo: PSTR, - pub szDescription: [u8; 257], - pub szSystemStatus: [u8; 129], + pub szDescription: [i8; 257], + pub szSystemStatus: [i8; 129], } #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] -impl ::core::marker::Copy for WSADATA {} +impl Copy for WSADATA {} #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] -impl ::core::clone::Clone for WSADATA { +impl Clone for WSADATA { fn clone(&self) -> Self { *self } @@ -4131,16 +4129,16 @@ impl ::core::clone::Clone for WSADATA { pub struct WSADATA { pub wVersion: u16, pub wHighVersion: u16, - pub szDescription: [u8; 257], - pub szSystemStatus: [u8; 129], + pub szDescription: [i8; 257], + pub szSystemStatus: [i8; 129], pub iMaxSockets: u16, pub iMaxUdpDg: u16, pub lpVendorInfo: PSTR, } #[cfg(target_arch = "x86")] -impl ::core::marker::Copy for WSADATA {} +impl Copy for WSADATA {} #[cfg(target_arch = "x86")] -impl ::core::clone::Clone for WSADATA { +impl Clone for WSADATA { fn clone(&self) -> Self { *self } @@ -4204,8 +4202,8 @@ pub struct WSAPROTOCOLCHAIN { pub ChainLen: i32, pub ChainEntries: [u32; 7], } -impl ::core::marker::Copy for WSAPROTOCOLCHAIN {} -impl ::core::clone::Clone for WSAPROTOCOLCHAIN { +impl Copy for WSAPROTOCOLCHAIN {} +impl Clone for WSAPROTOCOLCHAIN { fn clone(&self) -> Self { *self } @@ -4233,8 +4231,8 @@ pub struct WSAPROTOCOL_INFOW { pub dwProviderReserved: u32, pub szProtocol: [u16; 256], } -impl ::core::marker::Copy for WSAPROTOCOL_INFOW {} -impl ::core::clone::Clone for WSAPROTOCOL_INFOW { +impl Copy for WSAPROTOCOL_INFOW {} +impl Clone for WSAPROTOCOL_INFOW { fn clone(&self) -> Self { *self } @@ -4308,9 +4306,9 @@ pub struct XSAVE_FORMAT { pub Reserved4: [u8; 96], } #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] -impl ::core::marker::Copy for XSAVE_FORMAT {} +impl Copy for XSAVE_FORMAT {} #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] -impl ::core::clone::Clone for XSAVE_FORMAT { +impl Clone for XSAVE_FORMAT { fn clone(&self) -> Self { *self } @@ -4336,9 +4334,9 @@ pub struct XSAVE_FORMAT { pub Reserved4: [u8; 224], } #[cfg(target_arch = "x86")] -impl ::core::marker::Copy for XSAVE_FORMAT {} +impl Copy for XSAVE_FORMAT {} #[cfg(target_arch = "x86")] -impl ::core::clone::Clone for XSAVE_FORMAT { +impl Clone for XSAVE_FORMAT { fn clone(&self) -> Self { *self } diff --git a/library/std/src/sys/pal/windows/pipe.rs b/library/std/src/sys/pal/windows/pipe.rs index 013f588676a..dfa938d4d57 100644 --- a/library/std/src/sys/pal/windows/pipe.rs +++ b/library/std/src/sys/pal/windows/pipe.rs @@ -7,7 +7,7 @@ use crate::path::Path; use crate::ptr; use crate::slice; use crate::sync::atomic::AtomicUsize; -use crate::sync::atomic::Ordering::SeqCst; +use crate::sync::atomic::Ordering::Relaxed; use crate::sys::c; use crate::sys::fs::{File, OpenOptions}; use crate::sys::handle::Handle; @@ -214,11 +214,11 @@ pub fn spawn_pipe_relay( fn random_number() -> usize { static N: AtomicUsize = AtomicUsize::new(0); loop { - if N.load(SeqCst) != 0 { - return N.fetch_add(1, SeqCst); + if N.load(Relaxed) != 0 { + return N.fetch_add(1, Relaxed); } - N.store(hashmap_random_keys().0 as usize, SeqCst); + N.store(hashmap_random_keys().0 as usize, Relaxed); } } diff --git a/library/std/src/sys/pal/xous/alloc.rs b/library/std/src/sys/pal/xous/alloc.rs index 0d540e95520..601411173aa 100644 --- a/library/std/src/sys/pal/xous/alloc.rs +++ b/library/std/src/sys/pal/xous/alloc.rs @@ -46,7 +46,10 @@ unsafe impl GlobalAlloc for System { } mod lock { - use crate::sync::atomic::{AtomicI32, Ordering::SeqCst}; + use crate::sync::atomic::{ + AtomicI32, + Ordering::{Acquire, Release}, + }; static LOCKED: AtomicI32 = AtomicI32::new(0); @@ -54,7 +57,7 @@ mod lock { pub fn lock() -> DropLock { loop { - if LOCKED.swap(1, SeqCst) == 0 { + if LOCKED.swap(1, Acquire) == 0 { return DropLock; } crate::os::xous::ffi::do_yield(); @@ -63,7 +66,7 @@ mod lock { impl Drop for DropLock { fn drop(&mut self) { - let r = LOCKED.swap(0, SeqCst); + let r = LOCKED.swap(0, Release); debug_assert_eq!(r, 1); } } diff --git a/library/std/src/sys/pal/xous/net/tcpstream.rs b/library/std/src/sys/pal/xous/net/tcpstream.rs index 7149678118a..aebef02acda 100644 --- a/library/std/src/sys/pal/xous/net/tcpstream.rs +++ b/library/std/src/sys/pal/xous/net/tcpstream.rs @@ -406,7 +406,7 @@ impl TcpStream { } pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { - self.nonblocking.store(nonblocking, Ordering::SeqCst); + self.nonblocking.store(nonblocking, Ordering::Relaxed); Ok(()) } } diff --git a/library/std/src/sys/pal/xous/thread_local_key.rs b/library/std/src/sys/pal/xous/thread_local_key.rs index 59a668c3df6..2aaf46d0244 100644 --- a/library/std/src/sys/pal/xous/thread_local_key.rs +++ b/library/std/src/sys/pal/xous/thread_local_key.rs @@ -2,7 +2,7 @@ use crate::mem::ManuallyDrop; use crate::ptr; use crate::sync::atomic::AtomicPtr; use crate::sync::atomic::AtomicUsize; -use crate::sync::atomic::Ordering::SeqCst; +use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release}; use core::arch::asm; use crate::os::xous::ffi::{map_memory, unmap_memory, MemoryFlags}; @@ -92,7 +92,7 @@ fn tls_table() -> &'static mut [*mut u8] { pub unsafe fn create(dtor: Option<Dtor>) -> Key { // Allocate a new TLS key. These keys are shared among all threads. #[allow(unused_unsafe)] - let key = unsafe { TLS_KEY_INDEX.fetch_add(1, SeqCst) }; + let key = unsafe { TLS_KEY_INDEX.fetch_add(1, Relaxed) }; if let Some(f) = dtor { unsafe { register_dtor(key, f) }; } @@ -154,11 +154,11 @@ unsafe fn register_dtor(key: Key, dtor: Dtor) { let mut node = ManuallyDrop::new(Box::new(Node { key, dtor, next: ptr::null_mut() })); #[allow(unused_unsafe)] - let mut head = unsafe { DTORS.load(SeqCst) }; + let mut head = unsafe { DTORS.load(Acquire) }; loop { node.next = head; #[allow(unused_unsafe)] - match unsafe { DTORS.compare_exchange(head, &mut **node, SeqCst, SeqCst) } { + match unsafe { DTORS.compare_exchange(head, &mut **node, Release, Acquire) } { Ok(_) => return, // nothing to drop, we successfully added the node to the list Err(cur) => head = cur, } @@ -199,7 +199,7 @@ unsafe fn run_dtors() { } any_run = false; #[allow(unused_unsafe)] - let mut cur = unsafe { DTORS.load(SeqCst) }; + let mut cur = unsafe { DTORS.load(Acquire) }; while !cur.is_null() { let ptr = unsafe { get((*cur).key) }; diff --git a/library/std/src/sys/sync/mutex/xous.rs b/library/std/src/sys/sync/mutex/xous.rs index a8c9518ff0b..1426e48f8b7 100644 --- a/library/std/src/sys/sync/mutex/xous.rs +++ b/library/std/src/sys/sync/mutex/xous.rs @@ -1,6 +1,9 @@ use crate::os::xous::ffi::{blocking_scalar, do_yield}; use crate::os::xous::services::{ticktimer_server, TicktimerScalar}; -use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering::Relaxed, Ordering::SeqCst}; +use crate::sync::atomic::{ + AtomicBool, AtomicUsize, + Ordering::{Acquire, Relaxed, Release}, +}; pub struct Mutex { /// The "locked" value indicates how many threads are waiting on this @@ -68,7 +71,7 @@ impl Mutex { #[inline] pub unsafe fn unlock(&self) { - let prev = self.locked.fetch_sub(1, SeqCst); + let prev = self.locked.fetch_sub(1, Release); // If the previous value was 1, then this was a "fast path" unlock, so no // need to involve the Ticktimer server @@ -89,12 +92,12 @@ impl Mutex { #[inline] pub unsafe fn try_lock(&self) -> bool { - self.locked.compare_exchange(0, 1, SeqCst, SeqCst).is_ok() + self.locked.compare_exchange(0, 1, Acquire, Relaxed).is_ok() } #[inline] pub unsafe fn try_lock_or_poison(&self) -> bool { - self.locked.fetch_add(1, SeqCst) == 0 + self.locked.fetch_add(1, Acquire) == 0 } } diff --git a/library/std/src/sys/thread_local/fast_local.rs b/library/std/src/sys/thread_local/fast_local.rs index 646dcd7f3a3..69ee70de30c 100644 --- a/library/std/src/sys/thread_local/fast_local.rs +++ b/library/std/src/sys/thread_local/fast_local.rs @@ -13,22 +13,21 @@ pub macro thread_local_inner { (@key $t:ty, const $init:expr) => {{ #[inline] #[deny(unsafe_op_in_unsafe_fn)] - // FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint - #[cfg_attr(bootstrap, allow(static_mut_ref))] - #[cfg_attr(not(bootstrap), allow(static_mut_refs))] unsafe fn __getit( _init: $crate::option::Option<&mut $crate::option::Option<$t>>, ) -> $crate::option::Option<&'static $t> { const INIT_EXPR: $t = $init; // If the platform has support for `#[thread_local]`, use it. #[thread_local] - static mut VAL: $t = INIT_EXPR; + // We use `UnsafeCell` here instead of `static mut` to ensure any generated TLS shims + // have a nonnull attribute on their return value. + static VAL: $crate::cell::UnsafeCell<$t> = $crate::cell::UnsafeCell::new(INIT_EXPR); // If a dtor isn't needed we can do something "very raw" and // just get going. if !$crate::mem::needs_drop::<$t>() { unsafe { - return $crate::option::Option::Some(&VAL) + return $crate::option::Option::Some(&*VAL.get()) } } @@ -55,15 +54,15 @@ pub macro thread_local_inner { // so now. 0 => { $crate::thread::local_impl::Key::<$t>::register_dtor( - $crate::ptr::addr_of_mut!(VAL) as *mut $crate::primitive::u8, + VAL.get() as *mut $crate::primitive::u8, destroy, ); STATE.set(1); - $crate::option::Option::Some(&VAL) + $crate::option::Option::Some(&*VAL.get()) } // 1 == the destructor is registered and the value // is valid, so return the pointer. - 1 => $crate::option::Option::Some(&VAL), + 1 => $crate::option::Option::Some(&*VAL.get()), // otherwise the destructor has already run, so we // can't give access. _ => $crate::option::Option::None, diff --git a/library/std/src/sys/thread_local/static_local.rs b/library/std/src/sys/thread_local/static_local.rs index 4f2b6868962..206e62bb5e2 100644 --- a/library/std/src/sys/thread_local/static_local.rs +++ b/library/std/src/sys/thread_local/static_local.rs @@ -12,8 +12,7 @@ pub macro thread_local_inner { #[inline] // see comments below #[deny(unsafe_op_in_unsafe_fn)] // FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint - #[cfg_attr(bootstrap, allow(static_mut_ref))] - #[cfg_attr(not(bootstrap), allow(static_mut_refs))] + #[allow(static_mut_refs)] unsafe fn __getit( _init: $crate::option::Option<&mut $crate::option::Option<$t>>, ) -> $crate::option::Option<&'static $t> { diff --git a/library/std/src/sys_common/thread_local_key.rs b/library/std/src/sys_common/thread_local_key.rs index 204834984a2..7dcc1141099 100644 --- a/library/std/src/sys_common/thread_local_key.rs +++ b/library/std/src/sys_common/thread_local_key.rs @@ -128,7 +128,7 @@ impl StaticKey { #[inline] unsafe fn key(&self) -> imp::Key { - match self.key.load(Ordering::Relaxed) { + match self.key.load(Ordering::Acquire) { KEY_SENTVAL => self.lazy_init() as imp::Key, n => n as imp::Key, } @@ -156,8 +156,8 @@ impl StaticKey { match self.key.compare_exchange( KEY_SENTVAL, key as usize, - Ordering::SeqCst, - Ordering::SeqCst, + Ordering::Release, + Ordering::Acquire, ) { // The CAS succeeded, so we've created the actual key Ok(_) => key as usize, diff --git a/library/std/src/thread/local/tests.rs b/library/std/src/thread/local/tests.rs index 964c7fc5b0c..25019b554bb 100644 --- a/library/std/src/thread/local/tests.rs +++ b/library/std/src/thread/local/tests.rs @@ -255,6 +255,9 @@ fn join_orders_after_tls_destructors() { // observe the channel in the `THREAD1_WAITING` state. If this does occur, // we switch to the “poison” state `THREAD2_JOINED` and panic all around. // (This is equivalent to “sending” from an alternate producer thread.) + // + // Relaxed memory ordering is fine because and spawn()/join() already provide all the + // synchronization we need here. const FRESH: u8 = 0; const THREAD2_LAUNCHED: u8 = 1; const THREAD1_WAITING: u8 = 2; @@ -263,7 +266,7 @@ fn join_orders_after_tls_destructors() { static SYNC_STATE: AtomicU8 = AtomicU8::new(FRESH); for _ in 0..10 { - SYNC_STATE.store(FRESH, Ordering::SeqCst); + SYNC_STATE.store(FRESH, Ordering::Relaxed); let jh = thread::Builder::new() .name("thread1".into()) @@ -272,7 +275,7 @@ fn join_orders_after_tls_destructors() { impl Drop for TlDrop { fn drop(&mut self) { - let mut sync_state = SYNC_STATE.swap(THREAD1_WAITING, Ordering::SeqCst); + let mut sync_state = SYNC_STATE.swap(THREAD1_WAITING, Ordering::Relaxed); loop { match sync_state { THREAD2_LAUNCHED | THREAD1_WAITING => thread::yield_now(), @@ -282,7 +285,7 @@ fn join_orders_after_tls_destructors() { ), v => unreachable!("sync state: {}", v), } - sync_state = SYNC_STATE.load(Ordering::SeqCst); + sync_state = SYNC_STATE.load(Ordering::Relaxed); } } } @@ -294,7 +297,7 @@ fn join_orders_after_tls_destructors() { TL_DROP.with(|_| {}); loop { - match SYNC_STATE.load(Ordering::SeqCst) { + match SYNC_STATE.load(Ordering::Relaxed) { FRESH => thread::yield_now(), THREAD2_LAUNCHED => break, v => unreachable!("sync state: {}", v), @@ -306,9 +309,9 @@ fn join_orders_after_tls_destructors() { let jh2 = thread::Builder::new() .name("thread2".into()) .spawn(move || { - assert_eq!(SYNC_STATE.swap(THREAD2_LAUNCHED, Ordering::SeqCst), FRESH); + assert_eq!(SYNC_STATE.swap(THREAD2_LAUNCHED, Ordering::Relaxed), FRESH); jh.join().unwrap(); - match SYNC_STATE.swap(THREAD2_JOINED, Ordering::SeqCst) { + match SYNC_STATE.swap(THREAD2_JOINED, Ordering::Relaxed) { MAIN_THREAD_RENDEZVOUS => return, THREAD2_LAUNCHED | THREAD1_WAITING => { panic!("Thread 2 running after thread 1 join before main thread rendezvous") @@ -322,8 +325,8 @@ fn join_orders_after_tls_destructors() { match SYNC_STATE.compare_exchange( THREAD1_WAITING, MAIN_THREAD_RENDEZVOUS, - Ordering::SeqCst, - Ordering::SeqCst, + Ordering::Relaxed, + Ordering::Relaxed, ) { Ok(_) => break, Err(FRESH) => thread::yield_now(), diff --git a/library/unwind/src/lib.rs b/library/unwind/src/lib.rs index 45aa0ea4fbb..25bb5938b4c 100644 --- a/library/unwind/src/lib.rs +++ b/library/unwind/src/lib.rs @@ -3,7 +3,6 @@ #![feature(link_cfg)] #![feature(staged_api)] #![feature(c_unwind)] -#![cfg_attr(bootstrap, feature(cfg_target_abi))] #![feature(strict_provenance)] #![cfg_attr(not(target_env = "msvc"), feature(libc))] #![cfg_attr( diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 9c43160d455..818a7daadca 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -131,6 +131,8 @@ v("musl-root-riscv32gc", "target.riscv32gc-unknown-linux-musl.musl-root", "riscv32gc-unknown-linux-musl install directory") v("musl-root-riscv64gc", "target.riscv64gc-unknown-linux-musl.musl-root", "riscv64gc-unknown-linux-musl install directory") +v("musl-root-loongarch64", "target.loongarch64-unknown-linux-musl.musl-root", + "loongarch64-unknown-linux-musl install directory") v("qemu-armhf-rootfs", "target.arm-unknown-linux-gnueabihf.qemu-rootfs", "rootfs in qemu testing, you probably don't want to use this") v("qemu-aarch64-rootfs", "target.aarch64-unknown-linux-gnu.qemu-rootfs", diff --git a/src/bootstrap/src/bin/main.rs b/src/bootstrap/src/bin/main.rs index 070d951dba9..340a5c87f0b 100644 --- a/src/bootstrap/src/bin/main.rs +++ b/src/bootstrap/src/bin/main.rs @@ -7,6 +7,7 @@ use std::io::Write; use std::process; +use std::str::FromStr; use std::{ env, fs::{self, OpenOptions}, @@ -14,7 +15,8 @@ use std::{ }; use bootstrap::{ - find_recent_config_change_ids, t, Build, Config, Subcommand, CONFIG_CHANGE_HISTORY, + find_recent_config_change_ids, human_readable_changes, t, Build, Config, Subcommand, + CONFIG_CHANGE_HISTORY, }; fn main() { @@ -136,16 +138,25 @@ fn check_version(config: &Config) -> Option<String> { let latest_change_id = CONFIG_CHANGE_HISTORY.last().unwrap().change_id; let warned_id_path = config.out.join("bootstrap").join(".last-warned-change-id"); - if let Some(id) = config.change_id { + if let Some(mut id) = config.change_id { if id == latest_change_id { return None; } - if let Ok(last_warned_id) = fs::read_to_string(&warned_id_path) { - if latest_change_id.to_string() == last_warned_id { - return None; + // Always try to use `change-id` from .last-warned-change-id first. If it doesn't exist, + // then use the one from the config.toml. This way we never show the same warnings + // more than once. + if let Ok(t) = fs::read_to_string(&warned_id_path) { + let last_warned_id = + usize::from_str(&t).expect(&format!("{} is corrupted.", warned_id_path.display())); + + // We only use the last_warned_id if it exists in `CONFIG_CHANGE_HISTORY`. + // Otherwise, we may retrieve all the changes if it's not the highest value. + // For better understanding, refer to `change_tracker::find_recent_config_change_ids`. + if CONFIG_CHANGE_HISTORY.iter().any(|config| config.change_id == last_warned_id) { + id = last_warned_id; } - } + }; let changes = find_recent_config_change_ids(id); @@ -154,14 +165,7 @@ fn check_version(config: &Config) -> Option<String> { } msg.push_str("There have been changes to x.py since you last updated:\n"); - - for change in changes { - msg.push_str(&format!(" [{}] {}\n", change.severity, change.summary)); - msg.push_str(&format!( - " - PR Link https://github.com/rust-lang/rust/pull/{}\n", - change.change_id - )); - } + msg.push_str(&human_readable_changes(&changes)); msg.push_str("NOTE: to silence this warning, "); msg.push_str(&format!( diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index a90139a070a..55180a82885 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -61,14 +61,16 @@ fn args(builder: &Builder<'_>) -> Vec<String> { } } - args.extend(strings(&["--", "--cap-lints", "warn"])); + args.extend(strings(&["--"])); + + if deny.is_empty() && forbid.is_empty() { + args.extend(strings(&["--cap-lints", "warn"])); + } + + let all_args = std::env::args().collect::<Vec<_>>(); + args.extend(get_clippy_rules_in_order(&all_args, allow, deny, warn, forbid)); + args.extend(ignored_lints.iter().map(|lint| format!("-Aclippy::{}", lint))); - let mut clippy_lint_levels: Vec<String> = Vec::new(); - allow.iter().for_each(|v| clippy_lint_levels.push(format!("-A{}", v))); - deny.iter().for_each(|v| clippy_lint_levels.push(format!("-D{}", v))); - warn.iter().for_each(|v| clippy_lint_levels.push(format!("-W{}", v))); - forbid.iter().for_each(|v| clippy_lint_levels.push(format!("-F{}", v))); - args.extend(clippy_lint_levels); args.extend(builder.config.free_args.clone()); args } else { @@ -76,6 +78,32 @@ fn args(builder: &Builder<'_>) -> Vec<String> { } } +/// We need to keep the order of the given clippy lint rules before passing them. +/// Since clap doesn't offer any useful interface for this purpose out of the box, +/// we have to handle it manually. +pub(crate) fn get_clippy_rules_in_order( + all_args: &[String], + allow_rules: &[String], + deny_rules: &[String], + warn_rules: &[String], + forbid_rules: &[String], +) -> Vec<String> { + let mut result = vec![]; + + for (prefix, item) in + [("-A", allow_rules), ("-D", deny_rules), ("-W", warn_rules), ("-F", forbid_rules)] + { + item.iter().for_each(|v| { + let rule = format!("{prefix}{v}"); + let position = all_args.iter().position(|t| t == &rule).unwrap(); + result.push((position, rule)); + }); + } + + result.sort_by_key(|&(position, _)| position); + result.into_iter().map(|v| v.1).collect() +} + fn cargo_subcommand(kind: Kind) -> &'static str { match kind { Kind::Check => "check", diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 94ea2a01a40..2076444ca0c 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -231,7 +231,7 @@ impl Step for Std { let target_sysroot_bin = builder.sysroot_libdir(compiler, target).parent().unwrap().join("bin"); t!(fs::create_dir_all(&target_sysroot_bin)); - builder.cp_r(&src_sysroot_bin, &target_sysroot_bin); + builder.cp_link_r(&src_sysroot_bin, &target_sysroot_bin); } } @@ -307,7 +307,7 @@ fn copy_and_stamp( dependency_type: DependencyType, ) { let target = libdir.join(name); - builder.copy(&sourcedir.join(name), &target); + builder.copy_link(&sourcedir.join(name), &target); target_deps.push((target, dependency_type)); } @@ -316,7 +316,7 @@ fn copy_llvm_libunwind(builder: &Builder<'_>, target: TargetSelection, libdir: & let libunwind_path = builder.ensure(llvm::Libunwind { target }); let libunwind_source = libunwind_path.join("libunwind.a"); let libunwind_target = libdir.join("libunwind.a"); - builder.copy(&libunwind_source, &libunwind_target); + builder.copy_link(&libunwind_source, &libunwind_target); libunwind_target } @@ -385,7 +385,7 @@ fn copy_self_contained_objects( for &obj in &["crtbegin.o", "crtbeginS.o", "crtend.o", "crtendS.o"] { let src = crt_path.join(obj); let target = libdir_self_contained.join(obj); - builder.copy(&src, &target); + builder.copy_link(&src, &target); target_deps.push((target, DependencyType::TargetSelfContained)); } @@ -418,7 +418,7 @@ fn copy_self_contained_objects( for obj in ["crt2.o", "dllcrt2.o"].iter() { let src = compiler_file(builder, &builder.cc(target), target, CLang::C, obj); let target = libdir_self_contained.join(obj); - builder.copy(&src, &target); + builder.copy_link(&src, &target); target_deps.push((target, DependencyType::TargetSelfContained)); } } @@ -550,6 +550,10 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car cargo.rustflag("-Cforce-unwind-tables=yes"); } + // Enable frame pointers by default for the library. Note that they are still controlled by a + // separate setting for the compiler. + cargo.rustflag("-Cforce-frame-pointers=yes"); + let html_root = format!("-Zcrate-attr=doc(html_root_url=\"{}/\")", builder.doc_rust_lang_org_channel(),); cargo.rustflag(&html_root); @@ -637,7 +641,7 @@ impl Step for StdLink { let stage0_bin_dir = builder.out.join(host).join("stage0/bin"); let sysroot_bin_dir = sysroot.join("bin"); t!(fs::create_dir_all(&sysroot_bin_dir)); - builder.cp_r(&stage0_bin_dir, &sysroot_bin_dir); + builder.cp_link_r(&stage0_bin_dir, &sysroot_bin_dir); // Copy all *.so files from stage0/lib to stage0-sysroot/lib let stage0_lib_dir = builder.out.join(host).join("stage0/lib"); @@ -646,7 +650,8 @@ impl Step for StdLink { let file = t!(file); let path = file.path(); if path.is_file() && is_dylib(&file.file_name().into_string().unwrap()) { - builder.copy(&path, &sysroot.join("lib").join(path.file_name().unwrap())); + builder + .copy_link(&path, &sysroot.join("lib").join(path.file_name().unwrap())); } } } @@ -661,7 +666,7 @@ impl Step for StdLink { .join(host) .join("codegen-backends"); if stage0_codegen_backends.exists() { - builder.cp_r(&stage0_codegen_backends, &sysroot_codegen_backends); + builder.cp_link_r(&stage0_codegen_backends, &sysroot_codegen_backends); } } } @@ -684,7 +689,7 @@ fn copy_sanitizers( for runtime in &runtimes { let dst = libdir.join(&runtime.name); - builder.copy(&runtime.path, &dst); + builder.copy_link(&runtime.path, &dst); // The `aarch64-apple-ios-macabi` and `x86_64-apple-ios-macabi` are also supported for // sanitizers, but they share a sanitizer runtime with `${arch}-apple-darwin`, so we do @@ -790,7 +795,7 @@ impl Step for StartupObjects { } let target = sysroot_dir.join((*file).to_string() + ".o"); - builder.copy(dst_file, &target); + builder.copy_link(dst_file, &target); target_deps.push((target, DependencyType::Target)); } @@ -812,7 +817,7 @@ fn cp_rustc_component_to_ci_sysroot( if src.is_dir() { t!(fs::create_dir_all(dst)); } else { - builder.copy(&src, &dst); + builder.copy_link(&src, &dst); } } } @@ -1443,7 +1448,7 @@ fn copy_codegen_backends_to_sysroot( let dot = filename.find('.').unwrap(); format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..]) }; - builder.copy(file, &dst.join(target_filename)); + builder.copy_link(file, &dst.join(target_filename)); } } @@ -1599,7 +1604,7 @@ impl Step for Sysroot { OsStr::new(std::env::consts::DLL_EXTENSION), ]; let ci_rustc_dir = builder.config.ci_rustc_dir(); - builder.cp_filtered(&ci_rustc_dir, &sysroot, &|path| { + builder.cp_link_filtered(&ci_rustc_dir, &sysroot, &|path| { if path.extension().map_or(true, |ext| !filtered_extensions.contains(&ext)) { return true; } @@ -1791,7 +1796,7 @@ impl Step for Assemble { let filename = f.file_name().into_string().unwrap(); if (is_dylib(&filename) || is_debug_info(&filename)) && !proc_macros.contains(&filename) { - builder.copy(&f.path(), &rustc_libdir.join(&filename)); + builder.copy_link(&f.path(), &rustc_libdir.join(&filename)); } } @@ -1805,7 +1810,7 @@ impl Step for Assemble { if let Some(lld_install) = lld_install { let src_exe = exe("lld", target_compiler.host); let dst_exe = exe("rust-lld", target_compiler.host); - builder.copy(&lld_install.join("bin").join(src_exe), &libdir_bin.join(dst_exe)); + builder.copy_link(&lld_install.join("bin").join(src_exe), &libdir_bin.join(dst_exe)); let self_contained_lld_dir = libdir_bin.join("gcc-ld"); t!(fs::create_dir_all(&self_contained_lld_dir)); let lld_wrapper_exe = builder.ensure(crate::core::build_steps::tool::LldWrapper { @@ -1813,7 +1818,7 @@ impl Step for Assemble { target: target_compiler.host, }); for name in crate::LLD_FILE_NAMES { - builder.copy( + builder.copy_link( &lld_wrapper_exe, &self_contained_lld_dir.join(exe(name, target_compiler.host)), ); @@ -1838,7 +1843,7 @@ impl Step for Assemble { // When using `download-ci-llvm`, some of the tools // may not exist, so skip trying to copy them. if src_path.exists() { - builder.copy(&src_path, &libdir_bin.join(&tool_exe)); + builder.copy_link(&src_path, &libdir_bin.join(&tool_exe)); } } } @@ -1851,7 +1856,7 @@ impl Step for Assemble { extra_features: vec![], }); let tool_exe = exe("llvm-bitcode-linker", target_compiler.host); - builder.copy(&src_path, &libdir_bin.join(&tool_exe)); + builder.copy_link(&src_path, &libdir_bin.join(&tool_exe)); } // Ensure that `libLLVM.so` ends up in the newly build compiler directory, @@ -1865,7 +1870,7 @@ impl Step for Assemble { let bindir = sysroot.join("bin"); t!(fs::create_dir_all(bindir)); let compiler = builder.rustc(target_compiler); - builder.copy(&rustc, &compiler); + builder.copy_link(&rustc, &compiler); target_compiler } @@ -1891,7 +1896,7 @@ pub fn add_to_sysroot( DependencyType::Target => sysroot_dst, DependencyType::TargetSelfContained => self_contained_dst, }; - builder.copy(&path, &dst.join(path.file_name().unwrap())); + builder.copy_link(&path, &dst.join(path.file_name().unwrap())); } } diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 3efdfc324b8..012d64e5344 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -272,7 +272,7 @@ fn make_win_dist( let dist_bin_dir = rust_root.join("bin/"); fs::create_dir_all(&dist_bin_dir).expect("creating dist_bin_dir failed"); for src in rustc_dlls { - builder.copy_to_folder(&src, &dist_bin_dir); + builder.copy_link_to_folder(&src, &dist_bin_dir); } //Copy platform tools to platform-specific bin directory @@ -284,7 +284,7 @@ fn make_win_dist( .join("self-contained"); fs::create_dir_all(&target_bin_dir).expect("creating target_bin_dir failed"); for src in target_tools { - builder.copy_to_folder(&src, &target_bin_dir); + builder.copy_link_to_folder(&src, &target_bin_dir); } // Warn windows-gnu users that the bundled GCC cannot compile C files @@ -304,7 +304,7 @@ fn make_win_dist( .join("self-contained"); fs::create_dir_all(&target_lib_dir).expect("creating target_lib_dir failed"); for src in target_libs { - builder.copy_to_folder(&src, &target_lib_dir); + builder.copy_link_to_folder(&src, &target_lib_dir); } } @@ -400,7 +400,7 @@ impl Step for Rustc { // Copy rustc binary t!(fs::create_dir_all(image.join("bin"))); - builder.cp_r(&src.join("bin"), &image.join("bin")); + builder.cp_link_r(&src.join("bin"), &image.join("bin")); // If enabled, copy rustdoc binary if builder @@ -458,13 +458,13 @@ impl Step for Rustc { if builder.config.lld_enabled { let src_dir = builder.sysroot_libdir(compiler, host).parent().unwrap().join("bin"); let rust_lld = exe("rust-lld", compiler.host); - builder.copy(&src_dir.join(&rust_lld), &dst_dir.join(&rust_lld)); + builder.copy_link(&src_dir.join(&rust_lld), &dst_dir.join(&rust_lld)); let self_contained_lld_src_dir = src_dir.join("gcc-ld"); let self_contained_lld_dst_dir = dst_dir.join("gcc-ld"); t!(fs::create_dir(&self_contained_lld_dst_dir)); for name in crate::LLD_FILE_NAMES { let exe_name = exe(name, compiler.host); - builder.copy( + builder.copy_link( &self_contained_lld_src_dir.join(&exe_name), &self_contained_lld_dst_dir.join(&exe_name), ); @@ -609,9 +609,9 @@ fn copy_target_libs(builder: &Builder<'_>, target: TargetSelection, image: &Path t!(fs::create_dir_all(&self_contained_dst)); for (path, dependency_type) in builder.read_stamp_file(stamp) { if dependency_type == DependencyType::TargetSelfContained { - builder.copy(&path, &self_contained_dst.join(path.file_name().unwrap())); + builder.copy_link(&path, &self_contained_dst.join(path.file_name().unwrap())); } else if dependency_type == DependencyType::Target || builder.config.build == target { - builder.copy(&path, &dst.join(path.file_name().unwrap())); + builder.copy_link(&path, &dst.join(path.file_name().unwrap())); } } } @@ -865,7 +865,8 @@ fn copy_src_dirs( for item in src_dirs { let dst = &dst_dir.join(item); t!(fs::create_dir_all(dst)); - builder.cp_filtered(&base.join(item), dst, &|path| filter_fn(exclude_dirs, item, path)); + builder + .cp_link_filtered(&base.join(item), dst, &|path| filter_fn(exclude_dirs, item, path)); } } @@ -923,7 +924,7 @@ impl Step for Src { &dst_src, ); for file in src_files.iter() { - builder.copy(&builder.src.join(file), &dst_src.join(file)); + builder.copy_link(&builder.src.join(file), &dst_src.join(file)); } tarball.generate() @@ -979,7 +980,7 @@ impl Step for PlainSourceTarball { // Copy the files normally for item in &src_files { - builder.copy(&builder.src.join(item), &plain_dst_src.join(item)); + builder.copy_link(&builder.src.join(item), &plain_dst_src.join(item)); } // Create the version file @@ -1608,7 +1609,7 @@ impl Step for Extended { let prepare = |name: &str| { builder.create_dir(&pkg.join(name)); - builder.cp_r( + builder.cp_link_r( &work.join(format!("{}-{}", pkgname(builder, name), target.triple)), &pkg.join(name), ); @@ -1672,7 +1673,7 @@ impl Step for Extended { } else { name.to_string() }; - builder.cp_r( + builder.cp_link_r( &work.join(format!("{}-{}", pkgname(builder, name), target.triple)).join(dir), &exe.join(name), ); @@ -2040,7 +2041,7 @@ fn install_llvm_file( if install_symlink { // For download-ci-llvm, also install the symlink, to match what LLVM does. Using a // symlink is fine here, as this is not a rustup component. - builder.copy(&source, &full_dest); + builder.copy_link(&source, &full_dest); } else { // Otherwise, replace the symlink with an equivalent linker script. This is used when // projects like miri link against librustc_driver.so. We don't use a symlink, as diff --git a/src/bootstrap/src/core/build_steps/doc.rs b/src/bootstrap/src/core/build_steps/doc.rs index 1d4d9d4c2e1..51b5cdc0565 100644 --- a/src/bootstrap/src/core/build_steps/doc.rs +++ b/src/bootstrap/src/core/build_steps/doc.rs @@ -520,7 +520,10 @@ impl Step for SharedAssets { t!(fs::write(&version_info, info)); } - builder.copy(&builder.src.join("src").join("doc").join("rust.css"), &out.join("rust.css")); + builder.copy_link( + &builder.src.join("src").join("doc").join("rust.css"), + &out.join("rust.css"), + ); SharedAssetsPaths { version_info } } @@ -718,7 +721,7 @@ fn doc_std( let _guard = builder.msg_doc(compiler, description, target); builder.run(&mut cargo.into()); - builder.cp_r(&out_dir, out); + builder.cp_link_r(&out_dir, out); } #[derive(Debug, Clone, Hash, PartialEq, Eq)] @@ -1151,7 +1154,7 @@ impl Step for RustcBook { let out_base = builder.md_doc_out(self.target).join("rustc"); t!(fs::create_dir_all(&out_base)); let out_listing = out_base.join("src/lints"); - builder.cp_r(&builder.src.join("src/doc/rustc"), &out_base); + builder.cp_link_r(&builder.src.join("src/doc/rustc"), &out_base); builder.info(&format!("Generating lint docs ({})", self.target)); let rustc = builder.rustc(self.compiler); diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 701bd585eee..3da927b5fa0 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -564,11 +564,11 @@ fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) { let version = output(cmd.arg("--version")); let mut parts = version.split('.').take(2).filter_map(|s| s.parse::<u32>().ok()); if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) { - if major >= 16 { + if major >= 17 { return; } } - panic!("\n\nbad LLVM version: {version}, need >=16.0\n\n") + panic!("\n\nbad LLVM version: {version}, need >=17.0\n\n") } fn configure_cmake( diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index e9e2a881d11..6d3163b90b1 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -1367,7 +1367,7 @@ impl Step for RunMakeSupport { let cargo_out = builder.cargo_out(self.compiler, Mode::ToolStd, self.target).join(&lib_name); - builder.copy(&cargo_out, &lib); + builder.copy_link(&cargo_out, &lib); lib } } @@ -1548,6 +1548,10 @@ impl Step for MirOpt { }) }; + run(self.target); + + // Run more targets with `--bless`. But we always run the host target first, since some + // tests use very specific `only` clauses that are not covered by the target set below. if builder.config.cmd.bless() { // All that we really need to do is cover all combinations of 32/64-bit and unwind/abort, // but while we're at it we might as well flex our cross-compilation support. This @@ -1566,8 +1570,6 @@ impl Step for MirOpt { }); run(panic_abort_target); } - } else { - run(self.target); } } } diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 53dc1cff0ae..deab3fce54c 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -127,7 +127,7 @@ impl Step for ToolBuild { } let cargo_out = builder.cargo_out(compiler, self.mode, target).join(exe(tool, target)); let bin = builder.tools_dir(compiler).join(exe(tool, target)); - builder.copy(&cargo_out, &bin); + builder.copy_link(&cargo_out, &bin); bin } } @@ -507,7 +507,7 @@ impl Step for Rustdoc { t!(fs::create_dir_all(&bindir)); let bin_rustdoc = bindir.join(exe("rustdoc", target_compiler.host)); let _ = fs::remove_file(&bin_rustdoc); - builder.copy(&tool_rustdoc, &bin_rustdoc); + builder.copy_link(&tool_rustdoc, &bin_rustdoc); bin_rustdoc } else { tool_rustdoc @@ -686,12 +686,85 @@ impl Step for RustAnalyzerProcMacroSrv { // so that r-a can use it. let libexec_path = builder.sysroot(self.compiler).join("libexec"); t!(fs::create_dir_all(&libexec_path)); - builder.copy(&path, &libexec_path.join("rust-analyzer-proc-macro-srv")); + builder.copy_link(&path, &libexec_path.join("rust-analyzer-proc-macro-srv")); Some(path) } } +#[derive(Debug, Clone, Hash, PartialEq, Eq)] +pub struct LlvmBitcodeLinker { + pub compiler: Compiler, + pub target: TargetSelection, + pub extra_features: Vec<String>, +} + +impl Step for LlvmBitcodeLinker { + type Output = PathBuf; + const DEFAULT: bool = true; + const ONLY_HOSTS: bool = true; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + let builder = run.builder; + run.path("src/tools/llvm-bitcode-linker").default_condition( + builder.config.extended + && builder + .config + .tools + .as_ref() + .map_or(builder.build.unstable_features(), |tools| { + tools.iter().any(|tool| tool == "llvm-bitcode-linker") + }), + ) + } + + fn make_run(run: RunConfig<'_>) { + run.builder.ensure(LlvmBitcodeLinker { + compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build), + extra_features: Vec::new(), + target: run.target, + }); + } + + fn run(self, builder: &Builder<'_>) -> PathBuf { + let bin_name = "llvm-bitcode-linker"; + + builder.ensure(compile::Std::new(self.compiler, self.compiler.host)); + builder.ensure(compile::Rustc::new(self.compiler, self.target)); + + let mut cargo = prepare_tool_cargo( + builder, + self.compiler, + Mode::ToolRustc, + self.target, + "build", + "src/tools/llvm-bitcode-linker", + SourceType::InTree, + &self.extra_features, + ); + + if builder.config.rustc_parallel { + cargo.rustflag("--cfg=parallel_compiler"); + } + + builder.run(&mut cargo.into()); + + let tool_out = builder + .cargo_out(self.compiler, Mode::ToolRustc, self.target) + .join(exe(bin_name, self.compiler.host)); + + if self.compiler.stage > 0 { + let bindir = builder.sysroot(self.compiler).join("bin"); + t!(fs::create_dir_all(&bindir)); + let bin_destination = bindir.join(exe(bin_name, self.compiler.host)); + builder.copy_link(&tool_out, &bin_destination); + bin_destination + } else { + tool_out + } + } +} + macro_rules! tool_extended { (($sel:ident, $builder:ident), $($name:ident, @@ -765,7 +838,7 @@ macro_rules! tool_extended { $(for add_bin in $add_bins_to_sysroot { let bin_source = tools_out.join(exe(add_bin, $sel.target)); let bin_destination = bindir.join(exe(add_bin, $sel.compiler.host)); - $builder.copy(&bin_source, &bin_destination); + $builder.copy_link(&bin_source, &bin_destination); })? let tool = bindir.join(exe($tool_name, $sel.compiler.host)); @@ -795,7 +868,6 @@ tool_extended!((self, builder), Rls, "src/tools/rls", "rls", stable=true, tool_std=true; RustDemangler, "src/tools/rust-demangler", "rust-demangler", stable=false, tool_std=true; Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, add_bins_to_sysroot = ["rustfmt", "cargo-fmt"]; - LlvmBitcodeLinker, "src/tools/llvm-bitcode-linker", "llvm-bitcode-linker", stable=false, add_bins_to_sysroot = ["llvm-bitcode-linker"]; ); impl<'a> Builder<'a> { diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 7739303aca1..0f977640559 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1,6 +1,6 @@ use super::*; use crate::core::build_steps::doc::DocumentationFormat; -use crate::core::config::{Config, DryRun, TargetSelection}; +use crate::core::config::Config; use std::thread; fn configure(cmd: &str, host: &[&str], target: &[&str]) -> Config { diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 3e1bc9a9acd..67cde01ccdb 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -606,7 +606,8 @@ impl Target { #[serde(deny_unknown_fields, rename_all = "kebab-case")] pub(crate) struct TomlConfig { changelog_seen: Option<usize>, // FIXME: Deprecated field. Remove it at 2024. - change_id: Option<usize>, + #[serde(flatten)] + change_id: ChangeIdWrapper, build: Option<Build>, install: Option<Install>, llvm: Option<Llvm>, @@ -616,6 +617,16 @@ pub(crate) struct TomlConfig { profile: Option<String>, } +/// Since we use `#[serde(deny_unknown_fields)]` on `TomlConfig`, we need a wrapper type +/// for the "change-id" field to parse it even if other fields are invalid. This ensures +/// that if deserialization fails due to other fields, we can still provide the changelogs +/// to allow developers to potentially find the reason for the failure in the logs.. +#[derive(Deserialize, Default)] +pub(crate) struct ChangeIdWrapper { + #[serde(alias = "change-id")] + pub(crate) inner: Option<usize>, +} + /// Describes how to handle conflicts in merging two [`TomlConfig`] #[derive(Copy, Clone, Debug)] enum ReplaceOpt { @@ -657,7 +668,7 @@ impl Merge for TomlConfig { } } self.changelog_seen.merge(changelog_seen, replace); - self.change_id.merge(change_id, replace); + self.change_id.inner.merge(change_id.inner, replace); do_merge(&mut self.build, build, replace); do_merge(&mut self.install, install, replace); do_merge(&mut self.llvm, llvm, replace); @@ -1210,6 +1221,20 @@ impl Config { toml::from_str(&contents) .and_then(|table: toml::Value| TomlConfig::deserialize(table)) .unwrap_or_else(|err| { + if let Ok(Some(changes)) = toml::from_str(&contents) + .and_then(|table: toml::Value| ChangeIdWrapper::deserialize(table)) + .and_then(|change_id| { + Ok(change_id.inner.map(|id| crate::find_recent_config_change_ids(id))) + }) + { + if !changes.is_empty() { + println!( + "WARNING: There have been changes to x.py since you last updated:\n{}", + crate::human_readable_changes(&changes) + ); + } + } + eprintln!("failed to parse TOML configuration '{}': {err}", file.display()); exit!(2); }) @@ -1376,7 +1401,7 @@ impl Config { toml.merge(override_toml, ReplaceOpt::Override); config.changelog_seen = toml.changelog_seen; - config.change_id = toml.change_id; + config.change_id = toml.change_id.inner; let Build { build, diff --git a/src/bootstrap/src/core/config/tests.rs b/src/bootstrap/src/core/config/tests.rs index 6ac573c68df..8cd538953c5 100644 --- a/src/bootstrap/src/core/config/tests.rs +++ b/src/bootstrap/src/core/config/tests.rs @@ -1,4 +1,5 @@ -use super::{flags::Flags, Config}; +use super::{flags::Flags, ChangeIdWrapper, Config}; +use crate::core::build_steps::check::get_clippy_rules_in_order; use crate::core::config::{LldMode, TomlConfig}; use clap::CommandFactory; @@ -11,12 +12,13 @@ use std::{ }; fn parse(config: &str) -> Config { - let config = format!("{config} \r\n build.rustc = \"/does-not-exists\" "); Config::parse_inner( &[ - "check".to_owned(), - "--config=/does/not/exist".to_owned(), - "--skip-stage0-validation".to_owned(), + "check".to_string(), + "--set=build.rustc=/does/not/exist".to_string(), + "--set=build.cargo=/does/not/exist".to_string(), + "--config=/does/not/exist".to_string(), + "--skip-stage0-validation".to_string(), ], |&_| toml::from_str(&config).unwrap(), ) @@ -169,7 +171,10 @@ fn override_toml_duplicate() { Config::parse_inner( &[ "check".to_owned(), + "--set=build.rustc=/does/not/exist".to_string(), + "--set=build.cargo=/does/not/exist".to_string(), "--config=/does/not/exist".to_owned(), + "--skip-stage0-validation".to_owned(), "--set=change-id=1".to_owned(), "--set=change-id=2".to_owned(), ], @@ -192,7 +197,15 @@ fn profile_user_dist() { .and_then(|table: toml::Value| TomlConfig::deserialize(table)) .unwrap() } - Config::parse_inner(&["check".to_owned()], get_toml); + Config::parse_inner( + &[ + "check".to_owned(), + "--set=build.rustc=/does/not/exist".to_string(), + "--set=build.cargo=/does/not/exist".to_string(), + "--skip-stage0-validation".to_string(), + ], + get_toml, + ); } #[test] @@ -237,3 +250,51 @@ fn rust_lld() { assert!(matches!(parse("rust.use-lld = true").lld_mode, LldMode::External)); assert!(matches!(parse("rust.use-lld = false").lld_mode, LldMode::Unused)); } + +#[test] +#[should_panic] +fn parse_config_with_unknown_field() { + parse("unknown-key = 1"); +} + +#[test] +fn parse_change_id_with_unknown_field() { + let config = r#" + change-id = 3461 + unknown-key = 1 + "#; + + let change_id_wrapper: ChangeIdWrapper = toml::from_str(config).unwrap(); + assert_eq!(change_id_wrapper.inner, Some(3461)); +} + +#[test] +fn order_of_clippy_rules() { + let args = vec![ + "clippy".to_string(), + "--fix".to_string(), + "--allow-dirty".to_string(), + "--allow-staged".to_string(), + "-Aclippy:all".to_string(), + "-Wclippy::style".to_string(), + "-Aclippy::foo1".to_string(), + "-Aclippy::foo2".to_string(), + ]; + let config = Config::parse(&args); + + let actual = match &config.cmd { + crate::Subcommand::Clippy { allow, deny, warn, forbid, .. } => { + get_clippy_rules_in_order(&args, &allow, &deny, &warn, &forbid) + } + _ => panic!("invalid subcommand"), + }; + + let expected = vec![ + "-Aclippy:all".to_string(), + "-Wclippy::style".to_string(), + "-Aclippy::foo1".to_string(), + "-Aclippy::foo2".to_string(), + ]; + + assert_eq!(expected, actual); +} diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 85211aabb74..d8397ab51de 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -50,7 +50,9 @@ mod utils; pub use core::builder::PathSet; pub use core::config::flags::Subcommand; pub use core::config::Config; -pub use utils::change_tracker::{find_recent_config_change_ids, CONFIG_CHANGE_HISTORY}; +pub use utils::change_tracker::{ + find_recent_config_change_ids, human_readable_changes, CONFIG_CHANGE_HISTORY, +}; const LLVM_TOOLS: &[&str] = &[ "llvm-cov", // used to generate coverage report @@ -1007,15 +1009,23 @@ impl Build { let result = if !output.status.success() { if print_error { println!( - "\n\ncommand did not execute successfully: {:?}\n\ - expected success, got: {}\n\n\ - stdout ----\n{}\n\ - stderr ----\n{}\n\n", - command.command, + "\n\nCommand did not execute successfully.\ + \nExpected success, got: {}", output.status, - String::from_utf8_lossy(&output.stdout), - String::from_utf8_lossy(&output.stderr) ); + + if !self.is_verbose() { + println!("Add `-v` to see more details.\n"); + } + + self.verbose(|| { + println!( + "\nSTDOUT ----\n{}\n\ + STDERR ----\n{}\n", + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr) + ) + }); } Err(()) } else { @@ -1387,6 +1397,13 @@ impl Build { if let Some(path) = finder.maybe_have("wasmtime") { if let Ok(mut path) = path.into_os_string().into_string() { path.push_str(" run -C cache=n --dir ."); + // Make sure that tests have access to RUSTC_BOOTSTRAP. This (for example) is + // required for libtest to work on beta/stable channels. + // + // NB: with Wasmtime 20 this can change to `-S inherit-env` to + // inherit the entire environment rather than just this single + // environment variable. + path.push_str(" --env RUSTC_BOOTSTRAP"); return Some(path); } } @@ -1646,16 +1663,19 @@ impl Build { paths } - /// Copies a file from `src` to `dst` - pub fn copy(&self, src: &Path, dst: &Path) { - self.copy_internal(src, dst, false); + /// Links a file from `src` to `dst`. + /// Attempts to use hard links if possible, falling back to copying. + /// You can neither rely on this being a copy nor it being a link, + /// so do not write to dst. + pub fn copy_link(&self, src: &Path, dst: &Path) { + self.copy_link_internal(src, dst, false); } - fn copy_internal(&self, src: &Path, dst: &Path, dereference_symlinks: bool) { + fn copy_link_internal(&self, src: &Path, dst: &Path, dereference_symlinks: bool) { if self.config.dry_run() { return; } - self.verbose_than(1, || println!("Copy {src:?} to {dst:?}")); + self.verbose_than(1, || println!("Copy/Link {src:?} to {dst:?}")); if src == dst { return; } @@ -1686,9 +1706,10 @@ impl Build { } } - /// Copies the `src` directory recursively to `dst`. Both are assumed to exist + /// Links the `src` directory recursively to `dst`. Both are assumed to exist /// when this function is called. - pub fn cp_r(&self, src: &Path, dst: &Path) { + /// Will attempt to use hard links if possible and fall back to copying. + pub fn cp_link_r(&self, src: &Path, dst: &Path) { if self.config.dry_run() { return; } @@ -1698,24 +1719,31 @@ impl Build { let dst = dst.join(name); if t!(f.file_type()).is_dir() { t!(fs::create_dir_all(&dst)); - self.cp_r(&path, &dst); + self.cp_link_r(&path, &dst); } else { - let _ = fs::remove_file(&dst); - self.copy(&path, &dst); + self.copy_link(&path, &dst); } } } /// Copies the `src` directory recursively to `dst`. Both are assumed to exist - /// when this function is called. Unwanted files or directories can be skipped + /// when this function is called. + /// Will attempt to use hard links if possible and fall back to copying. + /// Unwanted files or directories can be skipped /// by returning `false` from the filter function. - pub fn cp_filtered(&self, src: &Path, dst: &Path, filter: &dyn Fn(&Path) -> bool) { + pub fn cp_link_filtered(&self, src: &Path, dst: &Path, filter: &dyn Fn(&Path) -> bool) { // Immediately recurse with an empty relative path - self.recurse_(src, dst, Path::new(""), filter) + self.cp_link_filtered_recurse(src, dst, Path::new(""), filter) } // Inner function does the actual work - fn recurse_(&self, src: &Path, dst: &Path, relative: &Path, filter: &dyn Fn(&Path) -> bool) { + fn cp_link_filtered_recurse( + &self, + src: &Path, + dst: &Path, + relative: &Path, + filter: &dyn Fn(&Path) -> bool, + ) { for f in self.read_dir(src) { let path = f.path(); let name = path.file_name().unwrap(); @@ -1726,19 +1754,19 @@ impl Build { if t!(f.file_type()).is_dir() { let _ = fs::remove_dir_all(&dst); self.create_dir(&dst); - self.recurse_(&path, &dst, &relative, filter); + self.cp_link_filtered_recurse(&path, &dst, &relative, filter); } else { let _ = fs::remove_file(&dst); - self.copy(&path, &dst); + self.copy_link(&path, &dst); } } } } - fn copy_to_folder(&self, src: &Path, dest_folder: &Path) { + fn copy_link_to_folder(&self, src: &Path, dest_folder: &Path) { let file_name = src.file_name().unwrap(); let dest = dest_folder.join(file_name); - self.copy(src, &dest); + self.copy_link(src, &dest); } fn install(&self, src: &Path, dstdir: &Path, perms: u32) { @@ -1751,7 +1779,7 @@ impl Build { if !src.exists() { panic!("ERROR: File \"{}\" not found!", src.display()); } - self.copy_internal(src, &dst, true); + self.copy_link_internal(src, &dst, true); chmod(&dst, perms); } diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index 14c1dc07306..277ec00fa62 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -60,6 +60,20 @@ pub fn find_recent_config_change_ids(current_id: usize) -> Vec<ChangeInfo> { .collect() } +pub fn human_readable_changes(changes: &[ChangeInfo]) -> String { + let mut message = String::new(); + + for change in changes { + message.push_str(&format!(" [{}] {}\n", change.severity, change.summary)); + message.push_str(&format!( + " - PR Link https://github.com/rust-lang/rust/pull/{}\n", + change.change_id + )); + } + + message +} + /// Keeps track of major changes made to the bootstrap configuration. /// /// If you make any major changes (such as adding new values or changing default values), diff --git a/src/bootstrap/src/utils/tarball.rs b/src/bootstrap/src/utils/tarball.rs index 03f56cba29d..4f99079a57f 100644 --- a/src/bootstrap/src/utils/tarball.rs +++ b/src/bootstrap/src/utils/tarball.rs @@ -197,7 +197,7 @@ impl<'a> Tarball<'a> { ) { let destdir = self.image_dir.join(destdir.as_ref()); t!(std::fs::create_dir_all(&destdir)); - self.builder.copy(src.as_ref(), &destdir.join(new_name)); + self.builder.copy_link(src.as_ref(), &destdir.join(new_name)); } pub(crate) fn add_legal_and_readme_to(&self, destdir: impl AsRef<Path>) { @@ -210,7 +210,7 @@ impl<'a> Tarball<'a> { let dest = self.image_dir.join(dest.as_ref()); t!(std::fs::create_dir_all(&dest)); - self.builder.cp_r(src.as_ref(), &dest); + self.builder.cp_link_r(src.as_ref(), &dest); } pub(crate) fn add_bulk_dir(&mut self, src: impl AsRef<Path>, dest: impl AsRef<Path>) { diff --git a/src/ci/docker/host-x86_64/mingw-check/Dockerfile b/src/ci/docker/host-x86_64/mingw-check/Dockerfile index 30d3a52d82b..e5aa81d83d5 100644 --- a/src/ci/docker/host-x86_64/mingw-check/Dockerfile +++ b/src/ci/docker/host-x86_64/mingw-check/Dockerfile @@ -41,6 +41,10 @@ COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/ ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1 ENV SCRIPT python3 ../x.py --stage 2 test src/tools/expand-yaml-anchors && \ + # Check library crates on all tier 1 targets. + # We disable optimized compiler built-ins because that requires a C toolchain for the target. + # We also skip the x86_64-unknown-linux-gnu target as it is well-tested by other jobs. + python3 ../x.py check --stage 0 --set build.optimized-compiler-builtins=false core alloc std --target=aarch64-unknown-linux-gnu,i686-pc-windows-msvc,i686-unknown-linux-gnu,x86_64-apple-darwin,x86_64-pc-windows-gnu,x86_64-pc-windows-msvc && \ python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \ python3 ../x.py clippy compiler -Aclippy::all -Dclippy::correctness && \ python3 ../x.py build --stage 0 src/tools/build-manifest && \ diff --git a/src/ci/docker/host-x86_64/test-various/Dockerfile b/src/ci/docker/host-x86_64/test-various/Dockerfile index 944d9aed319..4de9afdb171 100644 --- a/src/ci/docker/host-x86_64/test-various/Dockerfile +++ b/src/ci/docker/host-x86_64/test-various/Dockerfile @@ -55,9 +55,9 @@ ENV RUST_CONFIGURE_ARGS \ ENV NO_DEBUG_ASSERTIONS=1 ENV NO_OVERFLOW_CHECKS=1 -RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v18.0.2/wasmtime-v18.0.2-x86_64-linux.tar.xz | \ +RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v19.0.0/wasmtime-v19.0.0-x86_64-linux.tar.xz | \ tar -xJ -ENV PATH "$PATH:/wasmtime-v18.0.2-x86_64-linux" +ENV PATH "$PATH:/wasmtime-v19.0.0-x86_64-linux" ENV WASM_TARGETS=wasm32-wasip1 ENV WASM_SCRIPT python3 /checkout/x.py --stage 2 test --host='' --target $WASM_TARGETS \ diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-16/Dockerfile b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-16/Dockerfile deleted file mode 100644 index 4fc2b2e507e..00000000000 --- a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-16/Dockerfile +++ /dev/null @@ -1,67 +0,0 @@ -FROM ubuntu:23.04 - -ARG DEBIAN_FRONTEND=noninteractive - -RUN apt-get update && apt-get install -y --no-install-recommends \ - g++ \ - gcc-multilib \ - make \ - ninja-build \ - file \ - curl \ - ca-certificates \ - python3 \ - git \ - cmake \ - sudo \ - gdb \ - llvm-16-tools \ - llvm-16-dev \ - libedit-dev \ - libssl-dev \ - pkg-config \ - zlib1g-dev \ - xz-utils \ - nodejs \ - mingw-w64 \ - # libgccjit dependencies - flex \ - libmpfr-dev \ - libgmp-dev \ - libmpc3 \ - libmpc-dev \ - && rm -rf /var/lib/apt/lists/* - -# Note: libgccjit needs to match the default gcc version for the linker to find it. - -# Install powershell (universal package) so we can test x.ps1 on Linux -RUN curl -sL "https://github.com/PowerShell/PowerShell/releases/download/v7.3.1/powershell_7.3.1-1.deb_amd64.deb" > powershell.deb && \ - dpkg -i powershell.deb && \ - rm -f powershell.deb - -COPY scripts/sccache.sh /scripts/ -RUN sh /scripts/sccache.sh - -# We are disabling CI LLVM since this builder is intentionally using a host -# LLVM, rather than the typical src/llvm-project LLVM. -ENV NO_DOWNLOAD_CI_LLVM 1 - -# This is not the latest LLVM version, so some components required by tests may -# be missing. -ENV IS_NOT_LATEST_LLVM 1 - -# Using llvm-link-shared due to libffi issues -- see #34486 -ENV RUST_CONFIGURE_ARGS \ - --build=x86_64-unknown-linux-gnu \ - --llvm-root=/usr/lib/llvm-16 \ - --enable-llvm-link-shared \ - --set rust.thin-lto-import-instr-limit=10 - -COPY host-x86_64/x86_64-gnu-llvm-16/script.sh /tmp/ - -COPY host-x86_64/dist-x86_64-linux/shared.sh /scripts/ -COPY host-x86_64/dist-x86_64-linux/build-gccjit.sh /scripts/ - -RUN /scripts/build-gccjit.sh /scripts - -ENV SCRIPT /tmp/script.sh diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-17/Dockerfile b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-17/Dockerfile index 7c2ecd198e2..538962802c9 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-17/Dockerfile +++ b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-17/Dockerfile @@ -56,11 +56,10 @@ ENV RUST_CONFIGURE_ARGS \ --enable-llvm-link-shared \ --set rust.thin-lto-import-instr-limit=10 -COPY host-x86_64/x86_64-gnu-llvm-16/script.sh /tmp/ - COPY host-x86_64/dist-x86_64-linux/shared.sh /scripts/ COPY host-x86_64/dist-x86_64-linux/build-gccjit.sh /scripts/ RUN /scripts/build-gccjit.sh /scripts +COPY scripts/x86_64-gnu-llvm.sh /tmp/script.sh ENV SCRIPT /tmp/script.sh diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-18/Dockerfile b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-18/Dockerfile index e8383500dfc..3476b10a3ad 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-18/Dockerfile +++ b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-18/Dockerfile @@ -24,11 +24,14 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ xz-utils \ nodejs \ mingw-w64 \ - libgccjit-13-dev \ + # libgccjit dependencies + flex \ + libmpfr-dev \ + libgmp-dev \ + libmpc3 \ + libmpc-dev \ && rm -rf /var/lib/apt/lists/* -# Note: libgccjit needs to match the default gcc version for the linker to find it. - # Install powershell (universal package) so we can test x.ps1 on Linux # FIXME: need a "universal" version that supports libicu74, but for now it still works to ignore that dep. RUN curl -sL "https://github.com/PowerShell/PowerShell/releases/download/v7.3.1/powershell_7.3.1-1.deb_amd64.deb" > powershell.deb && \ @@ -50,6 +53,10 @@ ENV RUST_CONFIGURE_ARGS \ --enable-llvm-link-shared \ --set rust.thin-lto-import-instr-limit=10 -COPY host-x86_64/x86_64-gnu-llvm-16/script.sh /tmp/ +COPY host-x86_64/dist-x86_64-linux/shared.sh /scripts/ +COPY host-x86_64/dist-x86_64-linux/build-gccjit.sh /scripts/ + +RUN /scripts/build-gccjit.sh /scripts +COPY scripts/x86_64-gnu-llvm.sh /tmp/script.sh ENV SCRIPT /tmp/script.sh diff --git a/src/ci/docker/run.sh b/src/ci/docker/run.sh index bd5447ac835..740eb7504f8 100755 --- a/src/ci/docker/run.sh +++ b/src/ci/docker/run.sh @@ -92,21 +92,38 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then # Print docker version docker --version - # On non-CI or PR jobs, we don't have permissions to write to the registry cache, so we should - # not use `docker login` nor caching. - if [[ "$CI" == "" ]] || [[ "$PR_CI_JOB" == "1" ]]; + REGISTRY=ghcr.io + # PR CI runs on rust-lang, but we want to use the cache from rust-lang-ci + REGISTRY_USERNAME=rust-lang-ci + # Tag used to push the final Docker image, so that it can be pulled by e.g. rustup + IMAGE_TAG=${REGISTRY}/${REGISTRY_USERNAME}/rust-ci:${cksum} + # Tag used to cache the Docker build + # It seems that it cannot be the same as $IMAGE_TAG, otherwise it overwrites the cache + CACHE_IMAGE_TAG=${REGISTRY}/${REGISTRY_USERNAME}/rust-ci-cache:${cksum} + + # On non-CI jobs, we don't do any caching. + if [[ "$CI" == "" ]]; then retry docker build --rm -t rust-ci -f "$dockerfile" "$context" - else - REGISTRY=ghcr.io - # Most probably rust-lang-ci, but in general the owner of the repository where CI runs - REGISTRY_USERNAME=${GITHUB_REPOSITORY_OWNER} - # Tag used to push the final Docker image, so that it can be pulled by e.g. rustup - IMAGE_TAG=${REGISTRY}/${REGISTRY_USERNAME}/rust-ci:${cksum} - # Tag used to cache the Docker build - # It seems that it cannot be the same as $IMAGE_TAG, otherwise it overwrites the cache - CACHE_IMAGE_TAG=${REGISTRY}/${REGISTRY_USERNAME}/rust-ci-cache:${cksum} + # On PR CI jobs, we don't have permissions to write to the registry cache, + # but we can still read from it. + elif [[ "$PR_CI_JOB" == "1" ]]; + then + # Enable a new Docker driver so that --cache-from works with a registry backend + docker buildx create --use --driver docker-container + # Build the image using registry caching backend + retry docker \ + buildx \ + build \ + --rm \ + -t rust-ci \ + -f "$dockerfile" \ + --cache-from type=registry,ref=${CACHE_IMAGE_TAG} \ + --output=type=docker \ + "$context" + # On auto/try builds, we can also write to the cache. + else # Log into the Docker registry, so that we can read/write cache and the final image echo ${DOCKER_TOKEN} | docker login ${REGISTRY} \ --username ${REGISTRY_USERNAME} \ diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-16/script.sh b/src/ci/docker/scripts/x86_64-gnu-llvm.sh index 2eb751ca376..2eb751ca376 100755 --- a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-16/script.sh +++ b/src/ci/docker/scripts/x86_64-gnu-llvm.sh diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index bc81b1e04a7..972ef359337 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -357,7 +357,7 @@ jobs: - name: mingw-check-tidy <<: *job-linux-4c - - name: x86_64-gnu-llvm-16 + - name: x86_64-gnu-llvm-17 env: ENABLE_GCC_CODEGEN: "1" <<: *job-linux-16c @@ -520,11 +520,6 @@ jobs: RUST_BACKTRACE: 1 <<: *job-linux-8c - - name: x86_64-gnu-llvm-16 - env: - RUST_BACKTRACE: 1 - <<: *job-linux-8c - - name: x86_64-gnu-nopt <<: *job-linux-4c diff --git a/src/ci/scripts/install-msys2.sh b/src/ci/scripts/install-msys2.sh index e3f76744cbe..2ae78235604 100755 --- a/src/ci/scripts/install-msys2.sh +++ b/src/ci/scripts/install-msys2.sh @@ -28,16 +28,19 @@ if isWindows; then # Install pacboy for easily installing packages pacman -S --noconfirm pactoys - # Delete these pre-installed tools so we can't accidentally use them, because we are using the - # MSYS2 setup action versions instead. - # Delete pre-installed version of MSYS2 - echo "Cleaning up tools in PATH" - rm -r "/c/msys64/" - # Delete Strawberry Perl, which contains a version of mingw - rm -r "/c/Strawberry/" - # Delete these other copies of mingw, I don't even know where they come from. - rm -r "/c/mingw64/" - rm -r "/c/mingw32/" + # Remove these pre-installed tools so we can't accidentally use them, because we are using the + # MSYS2 setup action versions instead. Because `rm -r`-ing them is slow, we mv them off path + # instead. + # Remove pre-installed version of MSYS2 + echo "Cleaning up existing tools in PATH" + notpath="/c/NOT/ON/PATH/" + mkdir --parents "$notpath" + mv -t "$notpath" "/c/msys64/" + # Remove Strawberry Perl, which contains a version of mingw + mv -t "$notpath" "/c/Strawberry/" + # Remove these other copies of mingw, I don't even know where they come from. + mv -t "$notpath" "/c/mingw64/" + mv -t "$notpath" "/c/mingw32/" echo "Finished cleaning up tools in PATH" if isKnownToBeMingwBuild; then diff --git a/src/doc/rust.css b/src/doc/rust.css index bd2e0b94518..9e51f03085f 100644 --- a/src/doc/rust.css +++ b/src/doc/rust.css @@ -136,6 +136,28 @@ h1 a:link, h1 a:visited, h2 a:link, h2 a:visited, h3 a:link, h3 a:visited, h4 a:link, h4 a:visited, h5 a:link, h5 a:visited {color: black;} +h1, h2, h3, h4, h5 { + /* This is needed to be able to position the doc-anchor. Ideally there + would be a <div> around the whole document, but we don't have that. */ + position: relative; +} + +a.doc-anchor { + color: black; + display: none; + position: absolute; + left: -20px; + /* We add this padding so that when the cursor moves from the heading's text to the anchor, + the anchor doesn't disappear. */ + padding-right: 5px; + /* And this padding is used to make the anchor larger and easier to click on. */ + padding-left: 3px; +} +*:hover > .doc-anchor { + display: block; +} + + /* Code */ pre, code { diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 12a421f3c45..83acce80f96 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -52,7 +52,7 @@ - [powerpc64-ibm-aix](platform-support/aix.md) - [riscv32im-risc0-zkvm-elf](platform-support/riscv32im-risc0-zkvm-elf.md) - [riscv32imac-unknown-xous-elf](platform-support/riscv32imac-unknown-xous-elf.md) - - [riscv32*-unknown-none-elf](platform-support/riscv32imac-unknown-none-elf.md) + - [riscv32*-unknown-none-elf](platform-support/riscv32-unknown-none-elf.md) - [sparc-unknown-none-elf](./platform-support/sparc-unknown-none-elf.md) - [*-pc-windows-gnullvm](platform-support/pc-windows-gnullvm.md) - [\*-nto-qnx-\*](platform-support/nto-qnx.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 285c773afa2..75d38dd20bd 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -33,16 +33,14 @@ All tier 1 targets with host tools support the full standard library. target | notes -------|------- `aarch64-unknown-linux-gnu` | ARM64 Linux (kernel 4.1, glibc 2.17+) -`i686-pc-windows-gnu` | 32-bit MinGW (Windows 10+) [^windows-support] [^x86_32-floats-return-ABI] -`i686-pc-windows-msvc` | 32-bit MSVC (Windows 10+) [^windows-support] [^x86_32-floats-return-ABI] +`i686-pc-windows-gnu` | 32-bit MinGW (Windows 10+) [^x86_32-floats-return-ABI] +`i686-pc-windows-msvc` | 32-bit MSVC (Windows 10+) [^x86_32-floats-return-ABI] `i686-unknown-linux-gnu` | 32-bit Linux (kernel 3.2+, glibc 2.17+) [^x86_32-floats-return-ABI] `x86_64-apple-darwin` | 64-bit macOS (10.12+, Sierra+) -`x86_64-pc-windows-gnu` | 64-bit MinGW (Windows 10+) [^windows-support] -`x86_64-pc-windows-msvc` | 64-bit MSVC (Windows 10+) [^windows-support] +`x86_64-pc-windows-gnu` | 64-bit MinGW (Windows 10+) +`x86_64-pc-windows-msvc` | 64-bit MSVC (Windows 10+) `x86_64-unknown-linux-gnu` | 64-bit Linux (kernel 3.2+, glibc 2.17+) -[^windows-support]: Only Windows 10 currently undergoes automated testing. Earlier versions of Windows rely on testing and support from the community. - [^x86_32-floats-return-ABI]: Due to limitations of the C ABI, floating-point support on `i686` targets is non-compliant: floating-point return values are passed via an x87 register, so NaN payload bits can be lost. See [issue #114479][x86-32-float-issue]. [77071]: https://github.com/rust-lang/rust/issues/77071 @@ -120,6 +118,7 @@ The `std` column in the table below has the following meanings: * ✓ indicates the full standard library is available. * \* indicates the target only supports [`no_std`] development. +* ? indicates the standard library support is unknown or a work-in-progress. [`no_std`]: https://rust-embedded.github.io/book/intro/no-std.html @@ -142,7 +141,7 @@ target | std | notes [`aarch64-unknown-linux-ohos`](platform-support/openharmony.md) | ✓ | ARM64 OpenHarmony `aarch64-unknown-none-softfloat` | * | Bare ARM64, softfloat `aarch64-unknown-none` | * | Bare ARM64, hardfloat -[`aarch64-unknown-uefi`](platform-support/unknown-uefi.md) | * | ARM64 UEFI +[`aarch64-unknown-uefi`](platform-support/unknown-uefi.md) | ? | ARM64 UEFI [`arm-linux-androideabi`](platform-support/android.md) | ✓ | ARMv6 Android `arm-unknown-linux-musleabi` | ✓ | ARMv6 Linux with musl 1.2.3 `arm-unknown-linux-musleabihf` | ✓ | ARMv6 Linux with musl 1.2.3, hardfloat @@ -164,15 +163,15 @@ target | std | notes [`i686-linux-android`](platform-support/android.md) | ✓ | 32-bit x86 Android [^x86_32-floats-return-ABI] `i686-unknown-freebsd` | ✓ | 32-bit FreeBSD [^x86_32-floats-return-ABI] `i686-unknown-linux-musl` | ✓ | 32-bit Linux with musl 1.2.3 [^x86_32-floats-return-ABI] -[`i686-unknown-uefi`](platform-support/unknown-uefi.md) | * | 32-bit UEFI +[`i686-unknown-uefi`](platform-support/unknown-uefi.md) | ? | 32-bit UEFI [`loongarch64-unknown-none`](platform-support/loongarch-none.md) | * | | LoongArch64 Bare-metal (LP64D ABI) [`loongarch64-unknown-none-softfloat`](platform-support/loongarch-none.md) | * | | LoongArch64 Bare-metal (LP64S ABI) [`nvptx64-nvidia-cuda`](platform-support/nvptx64-nvidia-cuda.md) | * | --emit=asm generates PTX code that [runs on NVIDIA GPUs] -[`riscv32imac-unknown-none-elf`](platform-support/riscv32imac-unknown-none-elf.md) | * | Bare RISC-V (RV32IMAC ISA) -[`riscv32i-unknown-none-elf`](platform-support/riscv32imac-unknown-none-elf.md) | * | Bare RISC-V (RV32I ISA) -[`riscv32im-unknown-none-elf`](platform-support/riscv32imac-unknown-none-elf.md) | * | | Bare RISC-V (RV32IM ISA) -[`riscv32imc-unknown-none-elf`](platform-support/riscv32imac-unknown-none-elf.md) | * | Bare RISC-V (RV32IMC ISA) -[`riscv32imafc-unknown-none-elf`](platform-support/riscv32imac-unknown-none-elf.md) | * | Bare RISC-V (RV32IMAFC ISA) +[`riscv32imac-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | Bare RISC-V (RV32IMAC ISA) +[`riscv32i-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | Bare RISC-V (RV32I ISA) +[`riscv32im-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | | Bare RISC-V (RV32IM ISA) +[`riscv32imc-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | Bare RISC-V (RV32IMC ISA) +[`riscv32imafc-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | Bare RISC-V (RV32IMAFC ISA) `riscv64gc-unknown-none-elf` | * | Bare RISC-V (RV64IMAFDC ISA) `riscv64imac-unknown-none-elf` | * | Bare RISC-V (RV64IMAC ISA) `sparc64-unknown-linux-gnu` | ✓ | SPARC Linux (kernel 4.4, glibc 2.23) @@ -201,7 +200,7 @@ target | std | notes [`x86_64-unknown-linux-ohos`](platform-support/openharmony.md) | ✓ | x86_64 OpenHarmony [`x86_64-unknown-none`](platform-support/x86_64-unknown-none.md) | * | Freestanding/bare-metal x86_64, softfloat `x86_64-unknown-redox` | ✓ | Redox OS -[`x86_64-unknown-uefi`](platform-support/unknown-uefi.md) | * | 64-bit UEFI +[`x86_64-unknown-uefi`](platform-support/unknown-uefi.md) | ? | 64-bit UEFI [^x86_32-floats-x87]: Floating-point support on `i586` targets is non-compliant: the `x87` registers and instructions used for these targets do not provide IEEE-754-compliant behavior, in particular when it comes to rounding and NaN payload bits. See [issue #114479][x86-32-float-issue]. [wasi-rename]: https://github.com/rust-lang/compiler-team/issues/607 @@ -340,6 +339,7 @@ target | std | host | notes `riscv32gc-unknown-linux-gnu` | | | RISC-V Linux (kernel 5.4, glibc 2.33) `riscv32gc-unknown-linux-musl` | | | RISC-V Linux (kernel 5.4, musl 1.2.3 + RISCV32 support patches) [`riscv32im-risc0-zkvm-elf`](platform-support/riscv32im-risc0-zkvm-elf.md) | ? | | RISC Zero's zero-knowledge Virtual Machine (RV32IM ISA) +[`riscv32ima-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | | Bare RISC-V (RV32IMA ISA) [`riscv32imac-unknown-xous-elf`](platform-support/riscv32imac-unknown-xous-elf.md) | ? | | RISC-V Xous (RV32IMAC ISA) [`riscv32imc-esp-espidf`](platform-support/esp-idf.md) | ✓ | | RISC-V ESP-IDF [`riscv32imac-esp-espidf`](platform-support/esp-idf.md) | ✓ | | RISC-V ESP-IDF diff --git a/src/doc/rustc/src/platform-support/riscv32imac-unknown-none-elf.md b/src/doc/rustc/src/platform-support/riscv32-unknown-none-elf.md index 739b12bad8b..9a27a568b57 100644 --- a/src/doc/rustc/src/platform-support/riscv32imac-unknown-none-elf.md +++ b/src/doc/rustc/src/platform-support/riscv32-unknown-none-elf.md @@ -1,9 +1,13 @@ -# `riscv32{i,im,imc,imac,imafc}-unknown-none-elf` +# `riscv32{i,im,ima,imc,imac,imafc}-unknown-none-elf` **Tier: 2** Bare-metal target for RISC-V CPUs with the RV32I, RV32IM, RV32IMC, RV32IMAFC and RV32IMAC ISAs. +**Tier: 3** + +Bare-metal target for RISC-V CPUs with the RV32IMA ISA. + ## Target maintainers * Rust Embedded Working Group, [RISC-V team](https://github.com/rust-embedded/wg#the-risc-v-team) diff --git a/src/doc/rustc/src/platform-support/riscv32i-unknown-none-elf.md b/src/doc/rustc/src/platform-support/riscv32i-unknown-none-elf.md deleted file mode 100644 index edfe07fc053..00000000000 --- a/src/doc/rustc/src/platform-support/riscv32i-unknown-none-elf.md +++ /dev/null @@ -1 +0,0 @@ -riscv32imac-unknown-none-elf.md diff --git a/src/doc/rustc/src/platform-support/riscv32im-unknown-none-elf.md b/src/doc/rustc/src/platform-support/riscv32im-unknown-none-elf.md deleted file mode 100644 index edfe07fc053..00000000000 --- a/src/doc/rustc/src/platform-support/riscv32im-unknown-none-elf.md +++ /dev/null @@ -1 +0,0 @@ -riscv32imac-unknown-none-elf.md diff --git a/src/doc/rustc/src/platform-support/riscv32imafc-unknown-none-elf.md b/src/doc/rustc/src/platform-support/riscv32imafc-unknown-none-elf.md deleted file mode 100644 index edfe07fc053..00000000000 --- a/src/doc/rustc/src/platform-support/riscv32imafc-unknown-none-elf.md +++ /dev/null @@ -1 +0,0 @@ -riscv32imac-unknown-none-elf.md diff --git a/src/doc/rustc/src/platform-support/riscv32imc-unknown-none-elf.md b/src/doc/rustc/src/platform-support/riscv32imc-unknown-none-elf.md deleted file mode 100644 index edfe07fc053..00000000000 --- a/src/doc/rustc/src/platform-support/riscv32imc-unknown-none-elf.md +++ /dev/null @@ -1 +0,0 @@ -riscv32imac-unknown-none-elf.md diff --git a/src/doc/unstable-book/src/language-features/f128.md b/src/doc/unstable-book/src/language-features/f128.md new file mode 100644 index 00000000000..0cc5f677230 --- /dev/null +++ b/src/doc/unstable-book/src/language-features/f128.md @@ -0,0 +1,9 @@ +# `f128` + +The tracking issue for this feature is: [#116909] + +[#116909]: https://github.com/rust-lang/rust/issues/116909 + +--- + +Enable the `f128` type for IEEE 128-bit floating numbers (quad precision). diff --git a/src/doc/unstable-book/src/language-features/f16.md b/src/doc/unstable-book/src/language-features/f16.md new file mode 100644 index 00000000000..efb07a5146d --- /dev/null +++ b/src/doc/unstable-book/src/language-features/f16.md @@ -0,0 +1,9 @@ +# `f16` + +The tracking issue for this feature is: [#116909] + +[#116909]: https://github.com/rust-lang/rust/issues/116909 + +--- + +Enable the `f16` type for IEEE 16-bit floating numbers (half precision). diff --git a/src/doc/unstable-book/src/language-features/postfix-match.md b/src/doc/unstable-book/src/language-features/postfix-match.md new file mode 100644 index 00000000000..cd6b6a7442c --- /dev/null +++ b/src/doc/unstable-book/src/language-features/postfix-match.md @@ -0,0 +1,22 @@ +# `postfix-match` + +`postfix-match` adds the feature for matching upon values postfix +the expressions that generate the values. + +```rust,edition2021 +#![feature(postfix_match)] + +enum Foo { + Bar, + Baz +} + +fn get_foo() -> Foo { + Foo::Bar +} + +get_foo().match { + Foo::Bar => {}, + Foo::Baz => panic!(), +} +``` diff --git a/src/doc/unstable-book/src/library-features/async-fn-traits.md b/src/doc/unstable-book/src/library-features/async-fn-traits.md index e1c3f067e5b..a0edb3c7dd2 100644 --- a/src/doc/unstable-book/src/library-features/async-fn-traits.md +++ b/src/doc/unstable-book/src/library-features/async-fn-traits.md @@ -10,4 +10,4 @@ for creating custom closure-like types that return futures. [`AsyncFn*`]: ../../std/ops/trait.AsyncFn.html The main difference to the `Fn*` family of traits is that `AsyncFn` can return a future -that borrows from itself (`FnOnce::Output` has no lifetime parameters, while `AsyncFn::CallFuture` does). +that borrows from itself (`FnOnce::Output` has no lifetime parameters, while `AsyncFnMut::CallRefFuture` does). diff --git a/src/etc/gdb_providers.py b/src/etc/gdb_providers.py index 7d7277d2408..227695cdadd 100644 --- a/src/etc/gdb_providers.py +++ b/src/etc/gdb_providers.py @@ -245,7 +245,14 @@ class StdNonZeroNumberProvider(printer_base): fields = valobj.type.fields() assert len(fields) == 1 field = list(fields)[0] - self._value = str(valobj[field.name]) + + inner_valobj = valobj[field.name] + + inner_fields = inner_valobj.type.fields() + assert len(inner_fields) == 1 + inner_field = list(inner_fields)[0] + + self._value = str(inner_valobj[inner_field.name]) def to_string(self): return self._value diff --git a/src/etc/lldb_commands b/src/etc/lldb_commands index ed66ecf3072..615d13ccd0f 100644 --- a/src/etc/lldb_commands +++ b/src/etc/lldb_commands @@ -15,5 +15,5 @@ type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)C type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)Ref<.+>$" --category Rust type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefMut<.+>$" --category Rust type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefCell<.+>$" --category Rust -type summary add -F lldb_lookup.summary_lookup -e -x -h "^core::num::([a-z_]+::)*NonZero.+$" --category Rust +type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)NonZero<.+>$" --category Rust type category enable Rust diff --git a/src/etc/lldb_providers.py b/src/etc/lldb_providers.py index cfb3f0a4eae..5d2b6fd525c 100644 --- a/src/etc/lldb_providers.py +++ b/src/etc/lldb_providers.py @@ -743,7 +743,12 @@ class StdRefSyntheticProvider: def StdNonZeroNumberSummaryProvider(valobj, _dict): # type: (SBValue, dict) -> str - objtype = valobj.GetType() - field = objtype.GetFieldAtIndex(0) - element = valobj.GetChildMemberWithName(field.name) - return element.GetValue() + inner = valobj.GetChildAtIndex(0) + inner_inner = inner.GetChildAtIndex(0) + + # FIXME: Avoid printing as character literal, + # see https://github.com/llvm/llvm-project/issues/65076. + if inner_inner.GetTypeName() in ['char', 'unsigned char']: + return str(inner_inner.GetValueAsSigned()) + else: + return inner_inner.GetValue() diff --git a/src/etc/natvis/libcore.natvis b/src/etc/natvis/libcore.natvis index 5e0c21a13a9..8a441cf2093 100644 --- a/src/etc/natvis/libcore.natvis +++ b/src/etc/natvis/libcore.natvis @@ -42,7 +42,10 @@ </Type> <Type Name="core::num::nonzero::NonZero<*>"> - <DisplayString>{__0}</DisplayString> + <DisplayString>{__0.__0}</DisplayString> + <Expand> + <ExpandedItem>__0.__0</ExpandedItem> + </Expand> </Type> <Type Name="core::num::wrapping::Wrapping<*>"> diff --git a/src/etc/rust_types.py b/src/etc/rust_types.py index bf512bc99b8..2b06683ef93 100644 --- a/src/etc/rust_types.py +++ b/src/etc/rust_types.py @@ -34,23 +34,23 @@ class RustType(object): STD_NONZERO_NUMBER = "StdNonZeroNumber" -STD_STRING_REGEX = re.compile(r"^(alloc::(\w+::)+)String$") +STD_STRING_REGEX = re.compile(r"^(alloc::([a-z_]+::)+)String$") STD_STR_REGEX = re.compile(r"^&(mut )?str$") STD_SLICE_REGEX = re.compile(r"^&(mut )?\[.+\]$") -STD_OS_STRING_REGEX = re.compile(r"^(std::ffi::(\w+::)+)OsString$") -STD_VEC_REGEX = re.compile(r"^(alloc::(\w+::)+)Vec<.+>$") -STD_VEC_DEQUE_REGEX = re.compile(r"^(alloc::(\w+::)+)VecDeque<.+>$") -STD_BTREE_SET_REGEX = re.compile(r"^(alloc::(\w+::)+)BTreeSet<.+>$") -STD_BTREE_MAP_REGEX = re.compile(r"^(alloc::(\w+::)+)BTreeMap<.+>$") -STD_HASH_MAP_REGEX = re.compile(r"^(std::collections::(\w+::)+)HashMap<.+>$") -STD_HASH_SET_REGEX = re.compile(r"^(std::collections::(\w+::)+)HashSet<.+>$") -STD_RC_REGEX = re.compile(r"^(alloc::(\w+::)+)Rc<.+>$") -STD_ARC_REGEX = re.compile(r"^(alloc::(\w+::)+)Arc<.+>$") -STD_CELL_REGEX = re.compile(r"^(core::(\w+::)+)Cell<.+>$") -STD_REF_REGEX = re.compile(r"^(core::(\w+::)+)Ref<.+>$") -STD_REF_MUT_REGEX = re.compile(r"^(core::(\w+::)+)RefMut<.+>$") -STD_REF_CELL_REGEX = re.compile(r"^(core::(\w+::)+)RefCell<.+>$") -STD_NONZERO_NUMBER_REGEX = re.compile(r"^core::num::([a-z_]+::)*NonZero.+$") +STD_OS_STRING_REGEX = re.compile(r"^(std::ffi::([a-z_]+::)+)OsString$") +STD_VEC_REGEX = re.compile(r"^(alloc::([a-z_]+::)+)Vec<.+>$") +STD_VEC_DEQUE_REGEX = re.compile(r"^(alloc::([a-z_]+::)+)VecDeque<.+>$") +STD_BTREE_SET_REGEX = re.compile(r"^(alloc::([a-z_]+::)+)BTreeSet<.+>$") +STD_BTREE_MAP_REGEX = re.compile(r"^(alloc::([a-z_]+::)+)BTreeMap<.+>$") +STD_HASH_MAP_REGEX = re.compile(r"^(std::collections::([a-z_]+::)+)HashMap<.+>$") +STD_HASH_SET_REGEX = re.compile(r"^(std::collections::([a-z_]+::)+)HashSet<.+>$") +STD_RC_REGEX = re.compile(r"^(alloc::([a-z_]+::)+)Rc<.+>$") +STD_ARC_REGEX = re.compile(r"^(alloc::([a-z_]+::)+)Arc<.+>$") +STD_CELL_REGEX = re.compile(r"^(core::([a-z_]+::)+)Cell<.+>$") +STD_REF_REGEX = re.compile(r"^(core::([a-z_]+::)+)Ref<.+>$") +STD_REF_MUT_REGEX = re.compile(r"^(core::([a-z_]+::)+)RefMut<.+>$") +STD_REF_CELL_REGEX = re.compile(r"^(core::([a-z_]+::)+)RefCell<.+>$") +STD_NONZERO_NUMBER_REGEX = re.compile(r"^(core::([a-z_]+::)+)NonZero<.+>$") TUPLE_ITEM_REGEX = re.compile(r"__\d+$") diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 77a78f57e95..6f86c6450d9 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -62,6 +62,9 @@ pub(crate) fn try_inline( attrs_without_docs.as_ref().map(|(attrs, def_id)| (&attrs[..], *def_id)); let import_def_id = attrs.and_then(|(_, def_id)| def_id); + + let (attrs, cfg) = merge_attrs(cx, load_attrs(cx, did), attrs); + let kind = match res { Res::Def(DefKind::Trait, did) => { record_extern_fqn(cx, did, ItemType::Trait); @@ -131,7 +134,7 @@ pub(crate) fn try_inline( cx.with_param_env(did, |cx| clean::ConstantItem(build_const(cx, did))) } Res::Def(DefKind::Macro(kind), did) => { - let mac = build_macro(cx, did, name, import_def_id, kind); + let mac = build_macro(cx, did, name, import_def_id, kind, attrs.is_doc_hidden()); let type_kind = match kind { MacroKind::Bang => ItemType::Macro, @@ -144,7 +147,6 @@ pub(crate) fn try_inline( _ => return None, }; - let (attrs, cfg) = merge_attrs(cx, load_attrs(cx, did), attrs); cx.inlined.insert(did.into()); let mut item = clean::Item::from_def_id_and_attrs_and_parts(did, Some(name), kind, Box::new(attrs), cfg); @@ -751,6 +753,7 @@ fn build_macro( name: Symbol, import_def_id: Option<DefId>, macro_kind: MacroKind, + is_doc_hidden: bool, ) -> clean::ItemKind { match CStore::from_tcx(cx.tcx).load_macro_untracked(def_id, cx.tcx) { LoadedMacro::MacroDef(item_def, _) => match macro_kind { @@ -758,7 +761,14 @@ fn build_macro( if let ast::ItemKind::MacroDef(ref def) = item_def.kind { let vis = cx.tcx.visibility(import_def_id.unwrap_or(def_id)); clean::MacroItem(clean::Macro { - source: utils::display_macro_source(cx, name, def, def_id, vis), + source: utils::display_macro_source( + cx, + name, + def, + def_id, + vis, + is_doc_hidden, + ), }) } else { unreachable!() diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b28e57a9359..cd0a7d68437 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -20,7 +20,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LocalDefId, LOCAL_CRATE}; use rustc_hir::PredicateOrigin; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData}; use rustc_middle::metadata::Reexport; use rustc_middle::middle::resolve_bound_vars as rbv; @@ -626,7 +626,10 @@ fn is_impl_trait(param: &hir::GenericParam<'_>) -> bool { /// /// See `lifetime_to_generic_param` in `rustc_ast_lowering` for more information. fn is_elided_lifetime(param: &hir::GenericParam<'_>) -> bool { - matches!(param.kind, hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Elided }) + matches!( + param.kind, + hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Elided(_) } + ) } pub(crate) fn clean_generics<'tcx>( @@ -1257,12 +1260,8 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext hir::TraitItemKind::Type(bounds, Some(default)) => { let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)); let bounds = bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(); - let item_type = clean_middle_ty( - ty::Binder::dummy(hir_ty_to_ty(cx.tcx, default)), - cx, - None, - None, - ); + let item_type = + clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, default)), cx, None, None); AssocTypeItem( Box::new(TypeAlias { type_: clean_ty(default, cx), @@ -1303,12 +1302,8 @@ pub(crate) fn clean_impl_item<'tcx>( hir::ImplItemKind::Type(hir_ty) => { let type_ = clean_ty(hir_ty, cx); let generics = clean_generics(impl_.generics, cx); - let item_type = clean_middle_ty( - ty::Binder::dummy(hir_ty_to_ty(cx.tcx, hir_ty)), - cx, - None, - None, - ); + let item_type = + clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, hir_ty)), cx, None, None); AssocTypeItem( Box::new(TypeAlias { type_, @@ -1572,7 +1567,7 @@ fn first_non_private<'tcx>( path: &hir::Path<'tcx>, ) -> Option<Path> { let target_def_id = path.res.opt_def_id()?; - let (parent_def_id, ident) = match &path.segments[..] { + let (parent_def_id, ident) = match &path.segments { [] => return None, // Relative paths are available in the same scope as the owner. [leaf] => (cx.tcx.local_parent(hir_id.owner.def_id), leaf.ident), @@ -1687,7 +1682,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type } hir::QPath::Resolved(Some(qself), p) => { // Try to normalize `<X as Y>::T` to a type - let ty = hir_ty_to_ty(cx.tcx, hir_ty); + let ty = lower_ty(cx.tcx, hir_ty); // `hir_to_ty` can return projection types with escaping vars for GATs, e.g. `<() as Trait>::Gat<'_>` if !ty.has_escaping_bound_vars() && let Some(normalized_value) = normalize(cx, ty::Binder::dummy(ty)) @@ -1713,7 +1708,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type })) } hir::QPath::TypeRelative(qself, segment) => { - let ty = hir_ty_to_ty(cx.tcx, hir_ty); + let ty = lower_ty(cx.tcx, hir_ty); let self_type = clean_ty(qself, cx); let (trait_, should_show_cast) = match ty.kind() { @@ -2739,12 +2734,8 @@ fn clean_maybe_renamed_item<'tcx>( ItemKind::TyAlias(hir_ty, generics) => { *cx.current_type_aliases.entry(def_id).or_insert(0) += 1; let rustdoc_ty = clean_ty(hir_ty, cx); - let type_ = clean_middle_ty( - ty::Binder::dummy(hir_ty_to_ty(cx.tcx, hir_ty)), - cx, - None, - None, - ); + let type_ = + clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, hir_ty)), cx, None, None); let generics = clean_generics(generics, cx); if let Some(count) = cx.current_type_aliases.get_mut(&def_id) { *count -= 1; @@ -2794,7 +2785,8 @@ fn clean_maybe_renamed_item<'tcx>( ItemKind::Macro(ref macro_def, MacroKind::Bang) => { let ty_vis = cx.tcx.visibility(def_id); MacroItem(Macro { - source: display_macro_source(cx, name, macro_def, def_id, ty_vis), + // FIXME this shouldn't be false + source: display_macro_source(cx, name, macro_def, def_id, ty_vis, false), }) } ItemKind::Macro(_, macro_kind) => clean_proc_macro(item, &mut name, macro_kind, cx), diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index c35baeb4cf5..a51f6360df2 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1161,7 +1161,7 @@ impl Attributes { false } - fn is_doc_hidden(&self) -> bool { + pub(crate) fn is_doc_hidden(&self) -> bool { self.has_doc_flag(sym::hidden) } diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index aed1d9c5a83..977b4bb45b6 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -329,6 +329,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { elts.iter().map(|p| name_from_pat(p).to_string()).collect::<Vec<String>>().join(", ") ), PatKind::Box(p) => return name_from_pat(&*p), + PatKind::Deref(p) => format!("deref!({})", name_from_pat(&*p)), PatKind::Ref(p, _) => return name_from_pat(&*p), PatKind::Lit(..) => { warn!( @@ -598,7 +599,7 @@ pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool { /// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable. pub(crate) const DOC_RUST_LANG_ORG_CHANNEL: &str = env!("DOC_RUST_LANG_ORG_CHANNEL"); pub(crate) static DOC_CHANNEL: Lazy<&'static str> = - Lazy::new(|| DOC_RUST_LANG_ORG_CHANNEL.rsplit('/').filter(|c| !c.is_empty()).next().unwrap()); + Lazy::new(|| DOC_RUST_LANG_ORG_CHANNEL.rsplit('/').find(|c| !c.is_empty()).unwrap()); /// Render a sequence of macro arms in a format suitable for displaying to the user /// as part of an item declaration. @@ -625,6 +626,7 @@ pub(super) fn display_macro_source( def: &ast::MacroDef, def_id: DefId, vis: ty::Visibility<DefId>, + is_doc_hidden: bool, ) -> String { // Extract the spans of all matchers. They represent the "interface" of the macro. let matchers = def.body.tokens.chunks(4).map(|arm| &arm[0]); @@ -635,7 +637,7 @@ pub(super) fn display_macro_source( if matchers.len() <= 1 { format!( "{vis}macro {name}{matchers} {{\n ...\n}}", - vis = visibility_to_src_with_space(Some(vis), cx.tcx, def_id), + vis = visibility_to_src_with_space(Some(vis), cx.tcx, def_id, is_doc_hidden), matchers = matchers .map(|matcher| render_macro_matcher(cx.tcx, matcher)) .collect::<String>(), @@ -643,7 +645,7 @@ pub(super) fn display_macro_source( } else { format!( "{vis}macro {name} {{\n{arms}}}", - vis = visibility_to_src_with_space(Some(vis), cx.tcx, def_id), + vis = visibility_to_src_with_space(Some(vis), cx.tcx, def_id, is_doc_hidden), arms = render_macro_arms(cx.tcx, matchers, ","), ) } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index afd5eb42d01..312765d3e6d 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -29,8 +29,7 @@ use rustc_target::spec::abi::Abi; use itertools::Itertools; use crate::clean::{ - self, types::ExternalLocation, utils::find_nearest_parent_module, ExternalCrate, ItemId, - PrimitiveType, + self, types::ExternalLocation, utils::find_nearest_parent_module, ExternalCrate, PrimitiveType, }; use crate::formats::cache::Cache; use crate::formats::item_type::ItemType; @@ -1506,20 +1505,18 @@ impl clean::FnDecl { } pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>( - visibility: Option<ty::Visibility<DefId>>, - item_did: ItemId, + item: &clean::Item, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { use std::fmt::Write as _; - - let to_print: Cow<'static, str> = match visibility { + let vis: Cow<'static, str> = match item.visibility(cx.tcx()) { None => "".into(), Some(ty::Visibility::Public) => "pub ".into(), Some(ty::Visibility::Restricted(vis_did)) => { // FIXME(camelid): This may not work correctly if `item_did` is a module. // However, rustdoc currently never displays a module's // visibility, so it shouldn't matter. - let parent_module = find_nearest_parent_module(cx.tcx(), item_did.expect_def_id()); + let parent_module = find_nearest_parent_module(cx.tcx(), item.item_id.expect_def_id()); if vis_did.is_crate_root() { "pub(crate) ".into() @@ -1547,7 +1544,15 @@ pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>( } } }; - display_fn(move |f| f.write_str(&to_print)) + + let is_doc_hidden = item.is_doc_hidden(); + display_fn(move |f| { + if is_doc_hidden { + f.write_str("#[doc(hidden)] ")?; + } + + f.write_str(&vis) + }) } /// This function is the same as print_with_space, except that it renders no links. @@ -1557,8 +1562,9 @@ pub(crate) fn visibility_to_src_with_space<'a, 'tcx: 'a>( visibility: Option<ty::Visibility<DefId>>, tcx: TyCtxt<'tcx>, item_did: DefId, + is_doc_hidden: bool, ) -> impl Display + 'a + Captures<'tcx> { - let to_print: Cow<'static, str> = match visibility { + let vis: Cow<'static, str> = match visibility { None => "".into(), Some(ty::Visibility::Public) => "pub ".into(), Some(ty::Visibility::Restricted(vis_did)) => { @@ -1582,7 +1588,12 @@ pub(crate) fn visibility_to_src_with_space<'a, 'tcx: 'a>( } } }; - display_fn(move |f| f.write_str(&to_print)) + display_fn(move |f| { + if is_doc_hidden { + f.write_str("#[doc(hidden)] ")?; + } + f.write_str(&vis) + }) } pub(crate) trait PrintWithSpace { diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index bfd67ccbd3f..f1887684797 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -150,13 +150,13 @@ impl RenderType { string.push('{'); write_optional_id(self.id, string); string.push('{'); - for generic in &self.generics.as_ref().map(Vec::as_slice).unwrap_or_default()[..] { + for generic in &self.generics.as_deref().unwrap_or_default()[..] { generic.write_to_string(string); } string.push('}'); if self.bindings.is_some() { string.push('{'); - for binding in &self.bindings.as_ref().map(Vec::as_slice).unwrap_or_default()[..] { + for binding in &self.bindings.as_deref().unwrap_or_default()[..] { string.push('{'); binding.0.write_to_string(string); string.push('{'); @@ -883,7 +883,7 @@ fn assoc_const( w, "{indent}{vis}const <a{href} class=\"constant\">{name}</a>{generics}: {ty}", indent = " ".repeat(indent), - vis = visibility_print_with_space(it.visibility(tcx), it.item_id, cx), + vis = visibility_print_with_space(it, cx), href = assoc_href_attr(it, link, cx), name = it.name.as_ref().unwrap(), generics = generics.print(cx), @@ -912,12 +912,11 @@ fn assoc_type( indent: usize, cx: &Context<'_>, ) { - let tcx = cx.tcx(); write!( w, "{indent}{vis}type <a{href} class=\"associatedtype\">{name}</a>{generics}", indent = " ".repeat(indent), - vis = visibility_print_with_space(it.visibility(tcx), it.item_id, cx), + vis = visibility_print_with_space(it, cx), href = assoc_href_attr(it, link, cx), name = it.name.as_ref().unwrap(), generics = generics.print(cx), @@ -945,7 +944,7 @@ fn assoc_method( let tcx = cx.tcx(); let header = meth.fn_header(tcx).expect("Trying to get header from a non-function item"); let name = meth.name.as_ref().unwrap(); - let vis = visibility_print_with_space(meth.visibility(tcx), meth.item_id, cx).to_string(); + let vis = visibility_print_with_space(meth, cx).to_string(); let defaultness = print_default_space(meth.is_default()); // FIXME: Once https://github.com/rust-lang/rust/issues/67792 is implemented, we can remove // this condition. diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index d588f219739..5d4f1acc4b1 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -445,14 +445,14 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: Some(src) => write!( w, "<div class=\"item-name\"><code>{}extern crate {} as {};", - visibility_print_with_space(myitem.visibility(tcx), myitem.item_id, cx), + visibility_print_with_space(myitem, cx), anchor(myitem.item_id.expect_def_id(), src, cx), myitem.name.unwrap(), ), None => write!( w, "<div class=\"item-name\"><code>{}extern crate {};", - visibility_print_with_space(myitem.visibility(tcx), myitem.item_id, cx), + visibility_print_with_space(myitem, cx), anchor(myitem.item_id.expect_def_id(), myitem.name.unwrap(), cx), ), } @@ -491,7 +491,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: <code>{vis}{imp}</code>\ </div>\ {stab_tags_before}{stab_tags}{stab_tags_after}", - vis = visibility_print_with_space(myitem.visibility(tcx), myitem.item_id, cx), + vis = visibility_print_with_space(myitem, cx), imp = import.print(cx), ); w.write_str(ITEM_TABLE_ROW_CLOSE); @@ -511,10 +511,16 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: _ => "", }; - let visibility_emoji = match myitem.visibility(tcx) { + let visibility_and_hidden = match myitem.visibility(tcx) { Some(ty::Visibility::Restricted(_)) => { - "<span title=\"Restricted Visibility\"> 🔒</span> " + if myitem.is_doc_hidden() { + // Don't separate with a space when there are two of them + "<span title=\"Restricted Visibility\"> 🔒</span><span title=\"Hidden item\">👻</span> " + } else { + "<span title=\"Restricted Visibility\"> 🔒</span> " + } } + _ if myitem.is_doc_hidden() => "<span title=\"Hidden item\"> 👻</span> ", _ => "", }; @@ -530,13 +536,13 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: w, "<div class=\"item-name\">\ <a class=\"{class}\" href=\"{href}\" title=\"{title}\">{name}</a>\ - {visibility_emoji}\ + {visibility_and_hidden}\ {unsafety_flag}\ {stab_tags}\ </div>\ {docs_before}{docs}{docs_after}", name = myitem.name.unwrap(), - visibility_emoji = visibility_emoji, + visibility_and_hidden = visibility_and_hidden, stab_tags = extra_info_tags(myitem, item, tcx), class = myitem.type_(), unsafety_flag = unsafety_flag, @@ -625,7 +631,7 @@ fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &cle let unsafety = header.unsafety.print_with_space(); let abi = print_abi_with_space(header.abi).to_string(); let asyncness = header.asyncness.print_with_space(); - let visibility = visibility_print_with_space(it.visibility(tcx), it.item_id, cx).to_string(); + let visibility = visibility_print_with_space(it, cx).to_string(); let name = it.name.unwrap(); let generics_len = format!("{:#}", f.generics.print(cx)).len(); @@ -682,7 +688,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean: w, "{attrs}{vis}{unsafety}{is_auto}trait {name}{generics}{bounds}", attrs = render_attributes_in_pre(it, "", cx), - vis = visibility_print_with_space(it.visibility(tcx), it.item_id, cx), + vis = visibility_print_with_space(it, cx), unsafety = t.unsafety(tcx).print_with_space(), is_auto = if t.is_auto(tcx) { "auto " } else { "" }, name = it.name.unwrap(), @@ -1237,7 +1243,7 @@ fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &c w, "{attrs}{vis}type {name}{generics}{where_clause} = {type_};", attrs = render_attributes_in_pre(it, "", cx), - vis = visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx), + vis = visibility_print_with_space(it, cx), name = it.name.unwrap(), generics = t.generics.print(cx), where_clause = print_where_clause(&t.generics, cx, 0, Ending::Newline), @@ -1516,14 +1522,13 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>( } fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::Enum) { - let tcx = cx.tcx(); let count_variants = e.variants().count(); wrap_item(w, |w| { render_attributes_in_code(w, it, cx); write!( w, "{}enum {}{}", - visibility_print_with_space(it.visibility(tcx), it.item_id, cx), + visibility_print_with_space(it, cx), it.name.unwrap(), e.generics.print(cx), ); @@ -1854,7 +1859,7 @@ fn item_constant(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, c: &cle write!( w, "{vis}const {name}{generics}: {typ}{where_clause}", - vis = visibility_print_with_space(it.visibility(tcx), it.item_id, cx), + vis = visibility_print_with_space(it, cx), name = it.name.unwrap(), generics = c.generics.print(cx), typ = c.type_.print(cx), @@ -1958,7 +1963,7 @@ fn item_static(w: &mut impl fmt::Write, cx: &mut Context<'_>, it: &clean::Item, write!( buffer, "{vis}static {mutability}{name}: {typ}", - vis = visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx), + vis = visibility_print_with_space(it, cx), mutability = s.mutability.print_with_space(), name = it.name.unwrap(), typ = s.type_.print(cx) @@ -1976,7 +1981,7 @@ fn item_foreign_type(w: &mut impl fmt::Write, cx: &mut Context<'_>, it: &clean:: write!( buffer, " {}type {};\n}}", - visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx), + visibility_print_with_space(it, cx), it.name.unwrap(), ) .unwrap(); @@ -2133,13 +2138,7 @@ fn render_union<'a, 'cx: 'a>( cx: &'a Context<'cx>, ) -> impl fmt::Display + 'a + Captures<'cx> { display_fn(move |mut f| { - let tcx = cx.tcx(); - write!( - f, - "{}union {}", - visibility_print_with_space(it.visibility(tcx), it.item_id, cx), - it.name.unwrap(), - )?; + write!(f, "{}union {}", visibility_print_with_space(it, cx), it.name.unwrap(),)?; let where_displayed = g .map(|g| { @@ -2169,7 +2168,7 @@ fn render_union<'a, 'cx: 'a>( write!( f, " {}{}: {},\n", - visibility_print_with_space(field.visibility(tcx), field.item_id, cx), + visibility_print_with_space(field, cx), field.name.unwrap(), ty.print(cx) )?; @@ -2197,11 +2196,10 @@ fn render_struct( structhead: bool, cx: &Context<'_>, ) { - let tcx = cx.tcx(); write!( w, "{}{}{}", - visibility_print_with_space(it.visibility(tcx), it.item_id, cx), + visibility_print_with_space(it, cx), if structhead { "struct " } else { "" }, it.name.unwrap() ); @@ -2230,7 +2228,6 @@ fn render_struct_fields( has_stripped_entries: bool, cx: &Context<'_>, ) { - let tcx = cx.tcx(); match ty { None => { let where_displayed = @@ -2254,7 +2251,7 @@ fn render_struct_fields( write!( w, "\n{tab} {vis}{name}: {ty},", - vis = visibility_print_with_space(field.visibility(tcx), field.item_id, cx), + vis = visibility_print_with_space(field, cx), name = field.name.unwrap(), ty = ty.print(cx), ); @@ -2290,16 +2287,7 @@ fn render_struct_fields( match *field.kind { clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"), clean::StructFieldItem(ref ty) => { - write!( - w, - "{}{}", - visibility_print_with_space( - field.visibility(tcx), - field.item_id, - cx - ), - ty.print(cx), - ) + write!(w, "{}{}", visibility_print_with_space(field, cx), ty.print(cx),) } _ => unreachable!(), } diff --git a/src/librustdoc/passes/check_custom_code_classes.rs b/src/librustdoc/passes/check_custom_code_classes.rs index 451a44cd53a..524795ed77c 100644 --- a/src/librustdoc/passes/check_custom_code_classes.rs +++ b/src/librustdoc/passes/check_custom_code_classes.rs @@ -75,6 +75,7 @@ pub(crate) fn look_for_custom_classes<'tcx>(cx: &DocContext<'tcx>, item: &Item) sym::custom_code_classes_in_docs, GateIssue::Language, false, + None, ); err.note( diff --git a/src/llvm-project b/src/llvm-project -Subproject 7973f3560287d750500718314a0fd4025bd8ac0 +Subproject 0af6c732ec6ca189cd7725e4a7d4290793046e8 diff --git a/src/stage0.json b/src/stage0.json index 0b6d6e2a138..a85fbf254fc 100644 --- a/src/stage0.json +++ b/src/stage0.json @@ -18,423 +18,431 @@ "tool is executed." ], "compiler": { - "date": "2024-02-04", + "date": "2024-03-19", "version": "beta" }, "rustfmt": { - "date": "2024-02-04", + "date": "2024-03-19", "version": "nightly" }, "checksums_sha256": { - "dist/2024-02-04/cargo-beta-aarch64-apple-darwin.tar.gz": "f39e4ae0a2e69b1cc1bca0910287974025fa70398e278083d5be71a6397f6e7d", - "dist/2024-02-04/cargo-beta-aarch64-apple-darwin.tar.xz": "52f51e11e352d96e6350c0860576dc088681a135ded0bc04e943ba95421b52a4", - "dist/2024-02-04/cargo-beta-aarch64-pc-windows-msvc.tar.gz": "60cd2c54379b2d0287072dfe7cff5b81bf51beb69ecb296d6f3036f2a2526f8b", - "dist/2024-02-04/cargo-beta-aarch64-pc-windows-msvc.tar.xz": "cdc5d36196fa99c6c3641000e66ff68be9f2cc95bf00cafa87ae8386400b8ee0", - "dist/2024-02-04/cargo-beta-aarch64-unknown-linux-gnu.tar.gz": "e78c45f00e9a88647e8829fc248739aff1f0ed0ab6ec60a3da5ce6d2c1f02cbf", - "dist/2024-02-04/cargo-beta-aarch64-unknown-linux-gnu.tar.xz": "541754f83b39db95b62c5a0d2f9650b53212e0d6c2989429323c79a27d96d8c7", - "dist/2024-02-04/cargo-beta-aarch64-unknown-linux-musl.tar.gz": "6ec7f1ee3284ae3e27da9667fe976d459262233bdf1a7692f8c72f467aeb5ff6", - "dist/2024-02-04/cargo-beta-aarch64-unknown-linux-musl.tar.xz": "89c46d7e3826e6ca21cd2b992492c08e7a1d261ef347cf29f018480956fcaf98", - "dist/2024-02-04/cargo-beta-arm-unknown-linux-gnueabi.tar.gz": "9af1091ed9deee05e3c1b590dccc88e3834f47c43193acc29d5539ec7922a7f3", - "dist/2024-02-04/cargo-beta-arm-unknown-linux-gnueabi.tar.xz": "14a55b1aa26cc7ced03857a4848c91eb25bc1735b1e314b453efb8856b96105e", - "dist/2024-02-04/cargo-beta-arm-unknown-linux-gnueabihf.tar.gz": "3104665d24262b8b7586777331e63ee1732fbf7656f05b7dd85a71534e7b47eb", - "dist/2024-02-04/cargo-beta-arm-unknown-linux-gnueabihf.tar.xz": "610486cfcb5022c6f99494b9f58f3494438c7d9af4e0a949d0c5d366d13acd74", - "dist/2024-02-04/cargo-beta-armv7-unknown-linux-gnueabihf.tar.gz": "bdeeb3b50477fb57f5d02796af0543deeff9d274e6c12dcef1a11f7517dd2ceb", - "dist/2024-02-04/cargo-beta-armv7-unknown-linux-gnueabihf.tar.xz": "95a5beba76cf3ceb27378f1f2f9ab92359ff5627603ce2f6a8f86bed6ecf61d8", - "dist/2024-02-04/cargo-beta-i686-pc-windows-gnu.tar.gz": "65d4fecddca8b303f062fa119af9a7eb145c4c91adf5d5ec045325f2f48c906a", - "dist/2024-02-04/cargo-beta-i686-pc-windows-gnu.tar.xz": "38e766e4d90270c8a5f82cd4d0a50c1c143987201194c9132b86bf7a1a969036", - "dist/2024-02-04/cargo-beta-i686-pc-windows-msvc.tar.gz": "ed2ade2a28c469f9b488a675054494f4f26b4c3bde90c17eea34454562262d08", - "dist/2024-02-04/cargo-beta-i686-pc-windows-msvc.tar.xz": "05c6dcfe9e14bc2ede72863fef1814feceb063044af7a31baba5961e29aaf1d5", - "dist/2024-02-04/cargo-beta-i686-unknown-linux-gnu.tar.gz": "5954537bd942311649da6daf95ff60afc7e9b03fd3fae0d1a97244338309786e", - "dist/2024-02-04/cargo-beta-i686-unknown-linux-gnu.tar.xz": "9148aed468ae49b94b14786eaf58f963e2c58e2a99a93afa481be0a9244b86d4", - "dist/2024-02-04/cargo-beta-loongarch64-unknown-linux-gnu.tar.gz": "213b7f752395db016555825664e3e4a3bd5da8943e8bd56ed5bd94380e92181a", - "dist/2024-02-04/cargo-beta-loongarch64-unknown-linux-gnu.tar.xz": "8d146499b36f2d08389ff7888d74daa9f18a7e43cc2283c5410dd5c386c9caec", - "dist/2024-02-04/cargo-beta-powerpc-unknown-linux-gnu.tar.gz": "12a828172bb26f88c1a11a6d68aed6f87c3dc47961f74c8eeb6451b38c204b90", - "dist/2024-02-04/cargo-beta-powerpc-unknown-linux-gnu.tar.xz": "3905b493ee8ed0bd4961739b91a0dc14340082a811ec5be6e44dd8194ffaa38d", - "dist/2024-02-04/cargo-beta-powerpc64-unknown-linux-gnu.tar.gz": "63eb2e4303af8f77ebd8d22c08fd7d6f209abec1dd9f19f5afd2c4b281e765cf", - "dist/2024-02-04/cargo-beta-powerpc64-unknown-linux-gnu.tar.xz": "5be0627e2aeb33a7888c9a884e019d65d53a463e5b2dbb23a11ac5a89cc175c3", - "dist/2024-02-04/cargo-beta-powerpc64le-unknown-linux-gnu.tar.gz": "12bd938eab15063da78bda1b5f0918b567f55587c494c85fe8b11b36f305e397", - "dist/2024-02-04/cargo-beta-powerpc64le-unknown-linux-gnu.tar.xz": "0a6247ab66282beac406aa0c25affb51dc43a0b2a40fc71a1d98efc680a6f67b", - "dist/2024-02-04/cargo-beta-riscv64gc-unknown-linux-gnu.tar.gz": "6e9a6b49a58ef886bf668c9827c31d3f9beb2ee227b8c7a017071bff7e1efb6a", - "dist/2024-02-04/cargo-beta-riscv64gc-unknown-linux-gnu.tar.xz": "f56cab3cbbf6dc2e605124b8edd6c9a7d7592d001e9b2f4ea04af890b6fe6335", - "dist/2024-02-04/cargo-beta-s390x-unknown-linux-gnu.tar.gz": "be35d6d6923da0a5c8599760a72b584cf9e131bf16effa184d79786e9613f8a6", - "dist/2024-02-04/cargo-beta-s390x-unknown-linux-gnu.tar.xz": "81cd24ac13498570894a98a69ffc552ad282dfe4a076018841881f65ed387e09", - "dist/2024-02-04/cargo-beta-x86_64-apple-darwin.tar.gz": "e828aeffa6c832ff7a1e71ae12d275f75df9c3087aa08959dc0b93d0f37f9f76", - "dist/2024-02-04/cargo-beta-x86_64-apple-darwin.tar.xz": "546c56de1500061d5a133e05662d2659e3e96619f20757750ae8865498b71eb6", - "dist/2024-02-04/cargo-beta-x86_64-pc-windows-gnu.tar.gz": "c10b9f15a31a05ba6f865d1a853ca3f9b178a3c886ab73b9577f8db0b870c592", - "dist/2024-02-04/cargo-beta-x86_64-pc-windows-gnu.tar.xz": "65c5941965768e31abcba7c57e660cd6fcf909157b6aca1bf2ea0983e5a844da", - "dist/2024-02-04/cargo-beta-x86_64-pc-windows-msvc.tar.gz": "14bf2ac915ba94f172bd2a569bb669101d877fbce5262071b5ebb8f8d81752a9", - "dist/2024-02-04/cargo-beta-x86_64-pc-windows-msvc.tar.xz": "b2ce5dce49edc9a872ec63251b00ce4bc7c232984fee8b8ee534d8bc04f2084d", - "dist/2024-02-04/cargo-beta-x86_64-unknown-freebsd.tar.gz": "d408172c12e290bf27828a2e806670c750428182d0caa5f1aa88b9a4d3fe1bc9", - "dist/2024-02-04/cargo-beta-x86_64-unknown-freebsd.tar.xz": "46a7ce49382615f896276eb1966b7815353d19927a9e54feac902777fc7de10e", - "dist/2024-02-04/cargo-beta-x86_64-unknown-illumos.tar.gz": "a28eccf6cc23b580980fba900943c93a71594ed0a8120c239ce882e02c1f4a6e", - "dist/2024-02-04/cargo-beta-x86_64-unknown-illumos.tar.xz": "950a9a326bf80c65b0cb0073c5b712368a7358b993b8850cf4ae2bfc6644671c", - "dist/2024-02-04/cargo-beta-x86_64-unknown-linux-gnu.tar.gz": "0676c47123c0292b2e4f18592801383bf73ade1069cf6d160f27a39d86641b4c", - "dist/2024-02-04/cargo-beta-x86_64-unknown-linux-gnu.tar.xz": "a3dda924031f949cd7b5ada8e67b506efa94fbd4201e00d9c1e1e589223a039f", - "dist/2024-02-04/cargo-beta-x86_64-unknown-linux-musl.tar.gz": "b00be1a9ea0d0ca1c81181d2e1263594c8654036d050e8417772bb10021a0018", - "dist/2024-02-04/cargo-beta-x86_64-unknown-linux-musl.tar.xz": "bc464a4758ba8d585b2a6d7ba1f0f76c5bc8e21ffb699b4311cd54c702ab2295", - "dist/2024-02-04/cargo-beta-x86_64-unknown-netbsd.tar.gz": "4c165157f0fe6c96b3e54a73f795792cfc69aa979c71093eec918ddbce9a6c08", - "dist/2024-02-04/cargo-beta-x86_64-unknown-netbsd.tar.xz": "05cd0538b71c90f3e665b2feef453a0c4f4f6b1b68e4c8fe2339bd3d9c071af0", - "dist/2024-02-04/clippy-beta-aarch64-apple-darwin.tar.gz": "93cf112cfedead61356eb102bc55c811a23f67e13cf3933665de95f306c5a3ef", - "dist/2024-02-04/clippy-beta-aarch64-apple-darwin.tar.xz": "5389da6bb96c8928f18d018a25cd5d104d1c4ff9478ecf7c289434de3253d2cc", - "dist/2024-02-04/clippy-beta-aarch64-pc-windows-msvc.tar.gz": "5403e94f79d7295bf565b061b6fa9e5d500068005a7012c47dd1f0422cadcc99", - "dist/2024-02-04/clippy-beta-aarch64-pc-windows-msvc.tar.xz": "a285d22b4555524d94107292c45300129774448f2c1112e1744564e480ba07f1", - "dist/2024-02-04/clippy-beta-aarch64-unknown-linux-gnu.tar.gz": "4a6a2bc13f589b4de7a42d71517286740fc5670ad8247263338ebf13f021f5f1", - "dist/2024-02-04/clippy-beta-aarch64-unknown-linux-gnu.tar.xz": "6a007ff2a433dcd4a07efa6d55ae829cbbf4518dd5a5e52570bf70bee1876a22", - "dist/2024-02-04/clippy-beta-aarch64-unknown-linux-musl.tar.gz": "b4ff74cdef7ddbaa97ce031fce580ef235dc890c08a65f334b7f9bd61fa7fae5", - "dist/2024-02-04/clippy-beta-aarch64-unknown-linux-musl.tar.xz": "80bb641d57cd9077121640aa989a2a1b2c7ad802219b623d7b98527181061056", - "dist/2024-02-04/clippy-beta-arm-unknown-linux-gnueabi.tar.gz": "9f5a8c09e02bbfde36522f6b98ac19c6758f04a6fbb76cfafda357fabba20819", - "dist/2024-02-04/clippy-beta-arm-unknown-linux-gnueabi.tar.xz": "03aadb465c7761f000cb1515c98998afeb7557d1b20443c6b444949620290fc8", - "dist/2024-02-04/clippy-beta-arm-unknown-linux-gnueabihf.tar.gz": "694c756a8df76057982652a6dd31406e52f46f1bb9af29e9e1221ee90b966713", - "dist/2024-02-04/clippy-beta-arm-unknown-linux-gnueabihf.tar.xz": "224cdd5c675e68b5d0094a1b0d9cc08411b168dba5c3a8b6be15223ecce542e6", - "dist/2024-02-04/clippy-beta-armv7-unknown-linux-gnueabihf.tar.gz": "95c385adf93104d0ee31c59c10cdac2c7dbe073c40eec9a213d528109659e5e3", - "dist/2024-02-04/clippy-beta-armv7-unknown-linux-gnueabihf.tar.xz": "f649540bf91a48a9c8b58ed161b9665747a04054839bd21225d5d01d6abb6809", - "dist/2024-02-04/clippy-beta-i686-pc-windows-gnu.tar.gz": "b7597b2bf5e1a3b6041cc3e7773ef9385b3d1e0323411ee81eedad07ddec64a2", - "dist/2024-02-04/clippy-beta-i686-pc-windows-gnu.tar.xz": "a21cacbc47c6e9eb16e356e7724b1b71214a2b5fc513a50e8f4ce79060ddcd4d", - "dist/2024-02-04/clippy-beta-i686-pc-windows-msvc.tar.gz": "d71c3d482b328a01168f1cb8136f2ab76f5d55468984fad27039ea65f462fbfb", - "dist/2024-02-04/clippy-beta-i686-pc-windows-msvc.tar.xz": "e1f4ca9fa2dadc238126a995891da9bdb75dce196daf3f95a697653004fc2d4b", - "dist/2024-02-04/clippy-beta-i686-unknown-linux-gnu.tar.gz": "c2763fd5984be3105f649f5587cdb5af6ffd53fc3032ffce751730051a901e36", - "dist/2024-02-04/clippy-beta-i686-unknown-linux-gnu.tar.xz": "92a53f012b6770bf505082e27ccc182b20c0ae4954788c8ba51c140ec8981c8b", - "dist/2024-02-04/clippy-beta-loongarch64-unknown-linux-gnu.tar.gz": "c39b59c5e347bbd169cd1c08c087db4f7ddf243416c9d0a144da620ffd99283e", - "dist/2024-02-04/clippy-beta-loongarch64-unknown-linux-gnu.tar.xz": "1a973d60048b8a8541ab217cb00d5aa74fcb799b1f4f491666b07d4960aa8fa4", - "dist/2024-02-04/clippy-beta-powerpc-unknown-linux-gnu.tar.gz": "e40718072e3dde6e01bb9881a024a362057a8c22601d58273cbfa757999311e8", - "dist/2024-02-04/clippy-beta-powerpc-unknown-linux-gnu.tar.xz": "b47d5c9c7eb3351e7afc3648069e0e5d3eaf9f61b1ba2074f91f1b4a114cf6c0", - "dist/2024-02-04/clippy-beta-powerpc64-unknown-linux-gnu.tar.gz": "ab30688d5eab3f7fdddf665ae00e23a168259da3bd9ef583e56c80800e20256c", - "dist/2024-02-04/clippy-beta-powerpc64-unknown-linux-gnu.tar.xz": "4c08b61a36d8901e8c8fc397f7919b63264f9709b0b513683582da4378e4586c", - "dist/2024-02-04/clippy-beta-powerpc64le-unknown-linux-gnu.tar.gz": "88af713a59ad27e04a315a9887e0af3afaa118ef103b235a6874e7665e270f55", - "dist/2024-02-04/clippy-beta-powerpc64le-unknown-linux-gnu.tar.xz": "e6aac345a1a8c12168af05697379e885e896f1ecb51846a5183aff5f1efc321b", - "dist/2024-02-04/clippy-beta-riscv64gc-unknown-linux-gnu.tar.gz": "b57db645be80fe0ae5a8d3a496f4d00ff7af3bb0ff1032538a051da3b012cab7", - "dist/2024-02-04/clippy-beta-riscv64gc-unknown-linux-gnu.tar.xz": "be6d3d5cece8442b016be55ee46f4278797a7842d023af9d03edac6e528b6e8f", - "dist/2024-02-04/clippy-beta-s390x-unknown-linux-gnu.tar.gz": "5f58a7aec4c2b9311cba0c11c88879e60fa9bdf541324f08b203ad739d4dc8a7", - "dist/2024-02-04/clippy-beta-s390x-unknown-linux-gnu.tar.xz": "3b7e417060b91bd08e28d88f531947461c18a2aeeb3ceb7774171be7e55758c3", - "dist/2024-02-04/clippy-beta-x86_64-apple-darwin.tar.gz": "1806b225fd6b163ca5ff2fafe34b9fa085724f3c46133757b6a19fae3e253c69", - "dist/2024-02-04/clippy-beta-x86_64-apple-darwin.tar.xz": "bed30af2131873d94784ff69fedb51c80e0c0ffc5474c6ebb06d00292082d2b8", - "dist/2024-02-04/clippy-beta-x86_64-pc-windows-gnu.tar.gz": "7a7c7e2b67105712265e776086c9dcb8fc84c1ad64c6cd3175b8235ea85f1287", - "dist/2024-02-04/clippy-beta-x86_64-pc-windows-gnu.tar.xz": "9aa2a44e40c3221df88738db9fb9729989ce618c8a73e109f04ed758da044ef0", - "dist/2024-02-04/clippy-beta-x86_64-pc-windows-msvc.tar.gz": "32f2acc1fb292a7f8af43e7eaf0e5cc57f21ce51ddb209ee5d9c4db50bedfa17", - "dist/2024-02-04/clippy-beta-x86_64-pc-windows-msvc.tar.xz": "6e521228076657cdd451d924c3d0d48ae703f6a3ac1b6c64fc2b56553c924f11", - "dist/2024-02-04/clippy-beta-x86_64-unknown-freebsd.tar.gz": "cdf2ea498ea64ce119a861c4b4ed198f1971ff4562f239e1ae982a6bd50a8169", - "dist/2024-02-04/clippy-beta-x86_64-unknown-freebsd.tar.xz": "8716ccf9eb52a71fadfc177abd5dc75b1d9b1f14f7c523d12aefe5407d5380ee", - "dist/2024-02-04/clippy-beta-x86_64-unknown-illumos.tar.gz": "b845e1e8e0912abc1c165e757b28a569117ac7363282e691cad7dfbf2fbbebe9", - "dist/2024-02-04/clippy-beta-x86_64-unknown-illumos.tar.xz": "8a5577421bbcb6bf4ff052bfa0db9e22d65eeed578be3fb14946bddcf78aaf8d", - "dist/2024-02-04/clippy-beta-x86_64-unknown-linux-gnu.tar.gz": "730dced7639da52fe031ea9142012cd1c6f4a195312d99ce08f8b948ac317f78", - "dist/2024-02-04/clippy-beta-x86_64-unknown-linux-gnu.tar.xz": "4de9e4acf49f34cf7e99bee718d15081ea7e5b3cce56b1d180e125832126934e", - "dist/2024-02-04/clippy-beta-x86_64-unknown-linux-musl.tar.gz": "b5ce09b95d2a77ba605d2083573c1d4832fe42c8ff6b5bd8507f1ccddf87a10a", - "dist/2024-02-04/clippy-beta-x86_64-unknown-linux-musl.tar.xz": "fcf7c128a344f7b55481b82223b971fd5565db4023d443b315349a5ac5f5937d", - "dist/2024-02-04/clippy-beta-x86_64-unknown-netbsd.tar.gz": "8abaefeaf4d884e3214f657d8896bb440d93b3cd5f4e355fb8ae728d84713f40", - "dist/2024-02-04/clippy-beta-x86_64-unknown-netbsd.tar.xz": "a4b5e4b73c7a613f34ed592af4a73e50c4fe6f0f841f9749cab57530dea6033d", - "dist/2024-02-04/rust-std-beta-aarch64-apple-darwin.tar.gz": "54c24b06cf7b1cce6d74d0cf2ef38c0df0296e9b417116ef6bb340cf9a864f20", - "dist/2024-02-04/rust-std-beta-aarch64-apple-darwin.tar.xz": "17034b0eae96813fcfd0d8883fb7f4805b713404e15169e8c3de32801e4ca3bc", - "dist/2024-02-04/rust-std-beta-aarch64-apple-ios-sim.tar.gz": "477879218f052b6f20b40d34b72a9fdb900a64fcd4a1392faa187eac44576456", - "dist/2024-02-04/rust-std-beta-aarch64-apple-ios-sim.tar.xz": "5fae8e638f4c6b61683db07c0de485a1cb677e4384c593f32c089d77ea5dfbd9", - "dist/2024-02-04/rust-std-beta-aarch64-apple-ios.tar.gz": "4cc45742a06693a713d72820c6ee830ed8bd4f6f5ddd3be1e32bca4f5f88fd4d", - "dist/2024-02-04/rust-std-beta-aarch64-apple-ios.tar.xz": "7d9adce8808f0f5f7b9c65091791107afd63f26de02fe156821a6125486f2255", - "dist/2024-02-04/rust-std-beta-aarch64-linux-android.tar.gz": "893a0befa7f506cf3a07712d7a731ce551209c97708cd7f0ab12fa6ff3f1da39", - "dist/2024-02-04/rust-std-beta-aarch64-linux-android.tar.xz": "b647047d64f2fded2e393f226a7d131c96e84f2cb0ea6ed8259f25648b56bc6f", - "dist/2024-02-04/rust-std-beta-aarch64-pc-windows-msvc.tar.gz": "74917077da50bff4ceaad96a8acd1e90f9ccef32aea2b2f5f48406ebafff4c35", - "dist/2024-02-04/rust-std-beta-aarch64-pc-windows-msvc.tar.xz": "08210e2b802cda619854608e361a08388b51b9fce1551c13e5068ddc22d0773c", - "dist/2024-02-04/rust-std-beta-aarch64-unknown-fuchsia.tar.gz": "a51887dde95a5102eba99a754016900dd679e2cc6f65b7173a3d31c8d0f0148a", - "dist/2024-02-04/rust-std-beta-aarch64-unknown-fuchsia.tar.xz": "57f7120e830dcbe8c95be39f00342f2fbbd8ccdb20f431e8bc940eccc4002864", - "dist/2024-02-04/rust-std-beta-aarch64-unknown-linux-gnu.tar.gz": "6a79090eae406437761523e43e5a72b0ed040deb97db82da62718ee502573770", - "dist/2024-02-04/rust-std-beta-aarch64-unknown-linux-gnu.tar.xz": "00f3df2addefb8968d668200a890593481587536d0628e4d8def08b77e79caaa", - "dist/2024-02-04/rust-std-beta-aarch64-unknown-linux-musl.tar.gz": "42f0afcf90ffe70388c53d7642b035700af71b99e8382c5e95a94c6aec166e99", - "dist/2024-02-04/rust-std-beta-aarch64-unknown-linux-musl.tar.xz": "337984596f0d3cfc5776830cf7cb36ec8d564041761666fe340ecb0a62332348", - "dist/2024-02-04/rust-std-beta-aarch64-unknown-none-softfloat.tar.gz": "913e2255837674cd672c4959d567ccd786242acdbe78fa76119ceb8ede9b9846", - "dist/2024-02-04/rust-std-beta-aarch64-unknown-none-softfloat.tar.xz": "660f879a8a3e19686cb944766b0e70b19d0a9fd344047ceaf5e8959bc019f36c", - "dist/2024-02-04/rust-std-beta-aarch64-unknown-none.tar.gz": "4a210eefe84dbfe4e75fbc3a5475e58d86983e1f5c195e7c8b9f096e46ebfaeb", - "dist/2024-02-04/rust-std-beta-aarch64-unknown-none.tar.xz": "ad03045b5fe2b25806b4b44f5920e75008234954318cdc9cac8159782f6fc314", - "dist/2024-02-04/rust-std-beta-aarch64-unknown-uefi.tar.gz": "0c2988780468ff39ffe65cae5443bbdbb441aad18bf88312c14df76fefc748fd", - "dist/2024-02-04/rust-std-beta-aarch64-unknown-uefi.tar.xz": "0e4efbb711bd74cb280535ca424be4519f8e273b482eff4b5c4cfb7f0c142a74", - "dist/2024-02-04/rust-std-beta-arm-linux-androideabi.tar.gz": "6e6a0140c52670d962db55be6aa607618fbd4094828f27129cc94540ac94d893", - "dist/2024-02-04/rust-std-beta-arm-linux-androideabi.tar.xz": "fae70ac3c0be0a83c98eeac49e651c392c5962e10b4876120959d95209cff4ac", - "dist/2024-02-04/rust-std-beta-arm-unknown-linux-gnueabi.tar.gz": "48f73e51726a7685cee917fbf42464c13b77e3c4c36730477ce8a5213d0c8068", - "dist/2024-02-04/rust-std-beta-arm-unknown-linux-gnueabi.tar.xz": "03c4fdb9ab6737d48e9d1573188badf126acdfb96c4dd88c36d45fd7d61845c6", - "dist/2024-02-04/rust-std-beta-arm-unknown-linux-gnueabihf.tar.gz": "d17985406a6d241ae2e1f5c5571795ab712cc47fc2434fe78d69d3e581a768c8", - "dist/2024-02-04/rust-std-beta-arm-unknown-linux-gnueabihf.tar.xz": "ef29cc16781ad2422b78708634684f9310cf7783c2c88fef6cc378c1b21f86d1", - "dist/2024-02-04/rust-std-beta-arm-unknown-linux-musleabi.tar.gz": "df8bf07f5270c91bcdda1568fc870c128594a558d5fd26ebd8f4e9e1c7c026c8", - "dist/2024-02-04/rust-std-beta-arm-unknown-linux-musleabi.tar.xz": "114b42345f30ff26ac42044825209f7d1ae4b8b9a59c535ad199a78e8e2be1b8", - "dist/2024-02-04/rust-std-beta-arm-unknown-linux-musleabihf.tar.gz": "5b05057ef84727d0d62a575b1a4d8f87ea7b06cf242d294912bf97b52137a0ca", - "dist/2024-02-04/rust-std-beta-arm-unknown-linux-musleabihf.tar.xz": "a87b55c984fef378be2f50db63c0a66f715949e4365d467211b5c13839320cc3", - "dist/2024-02-04/rust-std-beta-armebv7r-none-eabi.tar.gz": "e8ac0f9c5f699c88a8da799b08111bee35719426ce6c0e2f53d0db14fb9b96d7", - "dist/2024-02-04/rust-std-beta-armebv7r-none-eabi.tar.xz": "7875d407748e983536bc0d3a385313a124de94390b780557d48fce9564a3754e", - "dist/2024-02-04/rust-std-beta-armebv7r-none-eabihf.tar.gz": "70415c0c7c4e9e53b12b1cbb0101398addb6b4aec59235011c2d73c059d0336e", - "dist/2024-02-04/rust-std-beta-armebv7r-none-eabihf.tar.xz": "2c9f18fc935938d5b9f9cb7915dab5aa6ca96032abf5a9e3313a63136c4cb11f", - "dist/2024-02-04/rust-std-beta-armv5te-unknown-linux-gnueabi.tar.gz": "b00b34a021c2d80574bbb764b08e291ffd8db0f346b8c3486789c86f008b5d98", - "dist/2024-02-04/rust-std-beta-armv5te-unknown-linux-gnueabi.tar.xz": "b47a6f55b44add99ca66d06fa910259c809c5f4f01feb809e2a6b8513626e3fb", - "dist/2024-02-04/rust-std-beta-armv5te-unknown-linux-musleabi.tar.gz": "caa8182c95035b62ba22e23d3989ba2733b90f599276a7c1f79b911e19d97850", - "dist/2024-02-04/rust-std-beta-armv5te-unknown-linux-musleabi.tar.xz": "1dd6c111f945d727eb28c9005efaa367ee2de8b15c771d27cbcb9709202f85b2", - "dist/2024-02-04/rust-std-beta-armv7-linux-androideabi.tar.gz": "b4176be56ab844c0f3d652d5023b927b672173f96319f685a85e57742b713102", - "dist/2024-02-04/rust-std-beta-armv7-linux-androideabi.tar.xz": "3d3d96f5cec355401e3eee94e5a9b68e070f441090f691f1de15a13d6194154e", - "dist/2024-02-04/rust-std-beta-armv7-unknown-linux-gnueabi.tar.gz": "ee5fcd9e0a661d08a1cb752cbfdce62b01faa4c4bbc607d09bb0d39a2c598899", - "dist/2024-02-04/rust-std-beta-armv7-unknown-linux-gnueabi.tar.xz": "a2e7ab719dee92b6c2132a902045c0bb2688851243fc530eed6b1fbe1a053333", - "dist/2024-02-04/rust-std-beta-armv7-unknown-linux-gnueabihf.tar.gz": "59ca2bacdca9b46e6e0b1803813d4021b685f676e53393e18b4497853a452d85", - "dist/2024-02-04/rust-std-beta-armv7-unknown-linux-gnueabihf.tar.xz": "f1b5b8843f804aef664a96896235384b1389de7084ba30be234c770dc9ab0517", - "dist/2024-02-04/rust-std-beta-armv7-unknown-linux-musleabi.tar.gz": "3825bb169e5d7abc0981f6a5179b143e2a695e395d0baa7cf181e8b752988ac7", - "dist/2024-02-04/rust-std-beta-armv7-unknown-linux-musleabi.tar.xz": "9aca61705d683d384e1d7e2392bdece52791d77edde6f45e2772bae766765434", - "dist/2024-02-04/rust-std-beta-armv7-unknown-linux-musleabihf.tar.gz": "46162ba65beed4d4ff70695870d02a39dba5ea4e1a71887140077e12847a3206", - "dist/2024-02-04/rust-std-beta-armv7-unknown-linux-musleabihf.tar.xz": "70841fa160053edb31d440eb47c54c58f4635bf4a95eac5624861b9d1e5dbbfe", - "dist/2024-02-04/rust-std-beta-armv7a-none-eabi.tar.gz": "ebc2f71d8486401144a193768cee0fdda3d43ec4ba7cb57434d3ec0ca9ee64dd", - "dist/2024-02-04/rust-std-beta-armv7a-none-eabi.tar.xz": "c8d54ac916b6c0651e8289deeee3dec76a06db7086957bca8c6039f4d10aef2a", - "dist/2024-02-04/rust-std-beta-armv7r-none-eabi.tar.gz": "b25ff694d355fafb41aaa7021c09c359b0af43a0217e1ee9d897f8f2e6ece91b", - "dist/2024-02-04/rust-std-beta-armv7r-none-eabi.tar.xz": "c22f40104c14a127d8df29f87fdb63db7aa919e11507c0bb8907dccd2d254f17", - "dist/2024-02-04/rust-std-beta-armv7r-none-eabihf.tar.gz": "3f73a17c6685760c30baed31cb746389b4b228704786a3a386ab432e933daae4", - "dist/2024-02-04/rust-std-beta-armv7r-none-eabihf.tar.xz": "fd8470f854538c8314d15d35b9a5159cf9b431ad7ccb79ea0542ba39d6e8a8dd", - "dist/2024-02-04/rust-std-beta-i586-pc-windows-msvc.tar.gz": "1377b2c1bc7a7066d7ae96316bc0a0339489cb71ef7f9f055731465df97ba8a0", - "dist/2024-02-04/rust-std-beta-i586-pc-windows-msvc.tar.xz": "77b22f2e94a3e1cefd057f051e568a6c8f4b17845272924dfbc193d8a290d96d", - "dist/2024-02-04/rust-std-beta-i586-unknown-linux-gnu.tar.gz": "222337a479e3d680d95c5189026890bdb3cae7eca78000f231e6747b9b403f22", - "dist/2024-02-04/rust-std-beta-i586-unknown-linux-gnu.tar.xz": "91447a0543f07bb36c71822ac4e8148e2e5982d1dd98fce7ba4171d7f418ff16", - "dist/2024-02-04/rust-std-beta-i586-unknown-linux-musl.tar.gz": "e2aa15ebd2a903f754fc9a46584b444b3fbbb9e42f2647ebe615f68711a0a27c", - "dist/2024-02-04/rust-std-beta-i586-unknown-linux-musl.tar.xz": "65f6975a8c06967f734bbd15589b14c5eb23951f10a79097f262083975654dd4", - "dist/2024-02-04/rust-std-beta-i686-linux-android.tar.gz": "073d7697a80e99cda4625f0bf1205744af9cab1a10456e44050fa8e6987007ab", - "dist/2024-02-04/rust-std-beta-i686-linux-android.tar.xz": "f142ffc490821bfc4bec5d69fb82c94aece9e379168f86b494b13289a597f23e", - "dist/2024-02-04/rust-std-beta-i686-pc-windows-gnu.tar.gz": "aaad81222f76855ffe5d2f6c5eadfe95562e9dfdf72a92531dd85b38568420f5", - "dist/2024-02-04/rust-std-beta-i686-pc-windows-gnu.tar.xz": "69923e0455f7b8f2cd28ef812118e359ce64789059d45e91ca5f8e382f1de1b8", - "dist/2024-02-04/rust-std-beta-i686-pc-windows-msvc.tar.gz": "1d66564ac675d5ca8c97ea7feb2b8e2fe606a560d27a137d996ce9814338cbba", - "dist/2024-02-04/rust-std-beta-i686-pc-windows-msvc.tar.xz": "8badfa48e9a654a48095026903e17392f7b4cae3501362579d345c541ddeb6bb", - "dist/2024-02-04/rust-std-beta-i686-unknown-freebsd.tar.gz": "3d45f7e407668cae7fae8cd8dc4e8ff8ca5f5a01baa4eb9401b81255d1e8947b", - "dist/2024-02-04/rust-std-beta-i686-unknown-freebsd.tar.xz": "c1788c7bbf8f4ee61c2d4623ed4efa8a8d15acc2963f3c146b48ed7d6f6010b7", - "dist/2024-02-04/rust-std-beta-i686-unknown-linux-gnu.tar.gz": "2e4434cad302be51543916055c8ba76b8c0c072476f6c491754b1a750aac8800", - "dist/2024-02-04/rust-std-beta-i686-unknown-linux-gnu.tar.xz": "5ac0bb47b9b6349a34ac1526f16714cdd580bd3aafcc3811001c69d8be21d0c4", - "dist/2024-02-04/rust-std-beta-i686-unknown-linux-musl.tar.gz": "21b1323043707f685bedd699a169e8acb189ca7431c1a3dc0ec7f56b27c2fec2", - "dist/2024-02-04/rust-std-beta-i686-unknown-linux-musl.tar.xz": "8fe2e260084c960bd29bede4be32371a34b1f801447628bbc32e7dae2d603784", - "dist/2024-02-04/rust-std-beta-i686-unknown-uefi.tar.gz": "4fc958f2c26ed27bd4537a31d2eee9a5b02bb5b0433402151e84756f470aebdc", - "dist/2024-02-04/rust-std-beta-i686-unknown-uefi.tar.xz": "a2c8235767448796d80f5408694d8ebbd6fa3b67d7c4fa03b7074836b4966114", - "dist/2024-02-04/rust-std-beta-loongarch64-unknown-linux-gnu.tar.gz": "a8689d5d7454dfe00acb84535813b47065cc09e17cc8006d5fc02da5f02f1cb0", - "dist/2024-02-04/rust-std-beta-loongarch64-unknown-linux-gnu.tar.xz": "d0eb4684222b53cac2eb84242a4e145f3f31ca855c296836b75340a0d432391e", - "dist/2024-02-04/rust-std-beta-loongarch64-unknown-none-softfloat.tar.gz": "6ee4ad6d9022bc69120709064dd93ff70cd3beb14ea28e82f3d4fed24ab07426", - "dist/2024-02-04/rust-std-beta-loongarch64-unknown-none-softfloat.tar.xz": "57ad740ec9ebf9b5bd3f082d89d63ff388523cb4d38e2cdf0b601bc7f07c6820", - "dist/2024-02-04/rust-std-beta-loongarch64-unknown-none.tar.gz": "a7400a7bbb873aac5c92339c8242966d1fa9553054f922193a2a8023b98a97ef", - "dist/2024-02-04/rust-std-beta-loongarch64-unknown-none.tar.xz": "7cd77b7c8a8b7c7c53d2ed454515766da3e02c7d6c63d880de9bc1c313f396a8", - "dist/2024-02-04/rust-std-beta-nvptx64-nvidia-cuda.tar.gz": "3b65431258133a690c976db006ad7b545cc980ff0352dcd03304741f5e82881e", - "dist/2024-02-04/rust-std-beta-nvptx64-nvidia-cuda.tar.xz": "87eaf905c3c189e9fca5a3f1dea6a0b53b7c4a84aa22c1ecf8b782c54c360a80", - "dist/2024-02-04/rust-std-beta-powerpc-unknown-linux-gnu.tar.gz": "97c12900755f780e32facd9ee3641394a3a7e32fe6e6a1cadd342ee367c95b6d", - "dist/2024-02-04/rust-std-beta-powerpc-unknown-linux-gnu.tar.xz": "a7c482e83c0ce07164921cc8ae48d02db9b795a5ea2e82c2948f598f68519289", - "dist/2024-02-04/rust-std-beta-powerpc64-unknown-linux-gnu.tar.gz": "9c1018fcdf362d891b6b1a63c36d5123917b2478bf010a0b32691c44480abcc7", - "dist/2024-02-04/rust-std-beta-powerpc64-unknown-linux-gnu.tar.xz": "fb93344ade418630bf610f9555babb0356ebbd369db73ea3edd88e96a48171f0", - "dist/2024-02-04/rust-std-beta-powerpc64le-unknown-linux-gnu.tar.gz": "4c24f19b83a528af2ad0935d775106415708a03212092ba86bb271db38bd604e", - "dist/2024-02-04/rust-std-beta-powerpc64le-unknown-linux-gnu.tar.xz": "804bc2c1c51570cdc102c80c1514b773d0a05a8f2fdeff9f789b525b042a5071", - "dist/2024-02-04/rust-std-beta-riscv32i-unknown-none-elf.tar.gz": "8ef9ed0ff32193e46617bf2aab368bbc4b268175acae604e26db8a1a92c15983", - "dist/2024-02-04/rust-std-beta-riscv32i-unknown-none-elf.tar.xz": "3b0450f332e258d1bbeee5c78628349cb1a6fad9d7058e0f2137709c46d90713", - "dist/2024-02-04/rust-std-beta-riscv32imac-unknown-none-elf.tar.gz": "47cba66e90e6310139a511083eeac727a6c55e66533157a662cd613730df7123", - "dist/2024-02-04/rust-std-beta-riscv32imac-unknown-none-elf.tar.xz": "ce19df99deffaf9002272d8c8b8c51f6d1dda93fc2babe8d786494add2607b27", - "dist/2024-02-04/rust-std-beta-riscv32imafc-unknown-none-elf.tar.gz": "fb8842df07fe5d0c782c9a4b260de7cf71835f7c4ca18f5241c9dc245c75bc7e", - "dist/2024-02-04/rust-std-beta-riscv32imafc-unknown-none-elf.tar.xz": "5b14d80923b4561c3147d5a6a45ad73f0c187f8ff38ce51c7f54a95f17d0e3f0", - "dist/2024-02-04/rust-std-beta-riscv32imc-unknown-none-elf.tar.gz": "19f2c43070c2cd477a07d9ab2e0a9fe8e3d41aaff75e09b5bcb89e6dbf8d0d12", - "dist/2024-02-04/rust-std-beta-riscv32imc-unknown-none-elf.tar.xz": "f5d413c8763e72aea96ca97a71927fd81fcd6341a8d7cacd070898b255f6d8ea", - "dist/2024-02-04/rust-std-beta-riscv64gc-unknown-linux-gnu.tar.gz": "227a42a01e2bfe5089afb478f3c78385ee989fe70199110ae8e5fb8f7d9c899a", - "dist/2024-02-04/rust-std-beta-riscv64gc-unknown-linux-gnu.tar.xz": "9a09c50ae0773469186754b6d14638a0d2d170f3cbac9dc36f4911a248480ea3", - "dist/2024-02-04/rust-std-beta-riscv64gc-unknown-none-elf.tar.gz": "70b168b86fb960124e9b4ed510848f5420647dcb82d36cce887aacbb7bf2783e", - "dist/2024-02-04/rust-std-beta-riscv64gc-unknown-none-elf.tar.xz": "db3a0c4e36a182926360317694053b9ee7e24d6f77f3c15eb9ff79482b3d129a", - "dist/2024-02-04/rust-std-beta-riscv64imac-unknown-none-elf.tar.gz": "127cb67bac139a8621b87a475be07dda3fc92616f15068145ebebd7087230815", - "dist/2024-02-04/rust-std-beta-riscv64imac-unknown-none-elf.tar.xz": "07e2ca92ade33338a800f3b9c0b8aad2ddc1c699247a3144bd70b3f2d93e84ec", - "dist/2024-02-04/rust-std-beta-s390x-unknown-linux-gnu.tar.gz": "6fc83881b97579aeb2c2873f18a5e63ac06a4b94889e0054a8515e2f23b8b1c7", - "dist/2024-02-04/rust-std-beta-s390x-unknown-linux-gnu.tar.xz": "b85f994c59b82db877fb42e2e06ac193de136e8b362284d211c66607a7272328", - "dist/2024-02-04/rust-std-beta-sparc64-unknown-linux-gnu.tar.gz": "d3188ab7fc2cba5474cb6c1cb0edeffe20ab90beb05cb42e83c4eeaff3c66d9f", - "dist/2024-02-04/rust-std-beta-sparc64-unknown-linux-gnu.tar.xz": "3e40bcf0c16e96fa81d814d81631e99069026d8b27b10c905ed22218d5842cbe", - "dist/2024-02-04/rust-std-beta-sparcv9-sun-solaris.tar.gz": "cde8e5c30725da66f9c6d6c67283e2d55cb22c1b65c4a0ac8157e3b7c79ae567", - "dist/2024-02-04/rust-std-beta-sparcv9-sun-solaris.tar.xz": "4832c0e385467bb0c5276971d5ecf4bf0e77247e54f90480be635a6a4a43ddb6", - "dist/2024-02-04/rust-std-beta-thumbv6m-none-eabi.tar.gz": "5ee43f29701f44060770a8be635708ace9143eb77926f6a6c946a3e02c56bf92", - "dist/2024-02-04/rust-std-beta-thumbv6m-none-eabi.tar.xz": "0af4c3a0270c53648b88a915466b592ab6a29aa959a014748fa95b9f511140e8", - "dist/2024-02-04/rust-std-beta-thumbv7em-none-eabi.tar.gz": "e57337af619b9e2de45d5268944d9ba3ea7ef19d8413a3e13a72c9ce08fe252b", - "dist/2024-02-04/rust-std-beta-thumbv7em-none-eabi.tar.xz": "26bbe4aa8ea10b4dbdd21da2f62118d42adbb852bd01bedab9cff47d79ac3887", - "dist/2024-02-04/rust-std-beta-thumbv7em-none-eabihf.tar.gz": "ac22acf98402d2091d60e4d6e934ef474d0ca40882121d595f7a809fa575264a", - "dist/2024-02-04/rust-std-beta-thumbv7em-none-eabihf.tar.xz": "3f0623d888b00d6ef243888322f9ef1781927c304e1ebd93b0d68457e0a551db", - "dist/2024-02-04/rust-std-beta-thumbv7m-none-eabi.tar.gz": "c23866c57b3781b12fa372d8a1a98626be669dfc86eb568aeafc9bbefe5c2fd5", - "dist/2024-02-04/rust-std-beta-thumbv7m-none-eabi.tar.xz": "64d2e9a717e0d6dc1bcdb3ba76937ced9d941ed1aa367fd2ebc9d6056b527a26", - "dist/2024-02-04/rust-std-beta-thumbv7neon-linux-androideabi.tar.gz": "864689308f8f72faad3b1812dbb67de254f4f0acbbc28302665b29f8e6aec9c8", - "dist/2024-02-04/rust-std-beta-thumbv7neon-linux-androideabi.tar.xz": "737ca7c2c4f8a1ec87ab0819676926a7d13ee4c074359530e02fdaa11a51cace", - "dist/2024-02-04/rust-std-beta-thumbv7neon-unknown-linux-gnueabihf.tar.gz": "68f0aee311b2fa12686249a4ace1f1f1fe254e4ee9aafbe6e7f429c98fd024c9", - "dist/2024-02-04/rust-std-beta-thumbv7neon-unknown-linux-gnueabihf.tar.xz": "cfe3bdbf666576340a7a6ba22422b88389356c21bccce60f31540a1a18095e74", - "dist/2024-02-04/rust-std-beta-thumbv8m.base-none-eabi.tar.gz": "bb0a27b78f4c006c5e9d04f7446433e13908837d947c8c73ede878219a189a52", - "dist/2024-02-04/rust-std-beta-thumbv8m.base-none-eabi.tar.xz": "271d1471e2ec7901582911bd341896e07d38ac7a762ee3000964cf8cc9f3d73e", - "dist/2024-02-04/rust-std-beta-thumbv8m.main-none-eabi.tar.gz": "e875ae5276bcf3bf112815ddcb8320d9b3e67f7d65ffda9bf194f54c49b55758", - "dist/2024-02-04/rust-std-beta-thumbv8m.main-none-eabi.tar.xz": "4f38da22bce7fdfd9cf0b0f24cce08b298af54dd2c20d8a6a10b888b66a5f120", - "dist/2024-02-04/rust-std-beta-thumbv8m.main-none-eabihf.tar.gz": "28ec4144e3ac2fd74fb5f59844b29623b6286173893d5b487157c7103d0e59b9", - "dist/2024-02-04/rust-std-beta-thumbv8m.main-none-eabihf.tar.xz": "c870d0ab781cffbf6bf7d0d0484b0a484eb4c4102d36f32d823b9c20c2886078", - "dist/2024-02-04/rust-std-beta-wasm32-unknown-emscripten.tar.gz": "23f8c320114c329109f081a868e5ec464d766883fe947538b26c31757b6305b9", - "dist/2024-02-04/rust-std-beta-wasm32-unknown-emscripten.tar.xz": "41c3cf36b6dab93202e792c4da186f5aef0ef5499d425a33ebafd1b4a7c5ff3f", - "dist/2024-02-04/rust-std-beta-wasm32-unknown-unknown.tar.gz": "09670117cb42829fcd871ed702652744d0599f715db8f1dd82ed462f01de87c0", - "dist/2024-02-04/rust-std-beta-wasm32-unknown-unknown.tar.xz": "5c04dc908e258dfce00306b6b6bdc5b5ee48031a6b5d602e7326e670f594fbd2", - "dist/2024-02-04/rust-std-beta-wasm32-wasi-preview1-threads.tar.gz": "09b5f40f1a449bb7cb6ef868bb3998f3ae4bd4f85ca594cca8b934166931a549", - "dist/2024-02-04/rust-std-beta-wasm32-wasi-preview1-threads.tar.xz": "b4de2d6ca31aafaa24871d15f4e0297064da72db884609223462232571df6ec2", - "dist/2024-02-04/rust-std-beta-wasm32-wasi.tar.gz": "194999685f52e9c489bd7e46cc1ab24fa2e37559a987d4fd90453b30b7e8b152", - "dist/2024-02-04/rust-std-beta-wasm32-wasi.tar.xz": "6f251f32b9959e7a602d6d9ddb89647970c79f129911084756550697c9e93893", - "dist/2024-02-04/rust-std-beta-x86_64-apple-darwin.tar.gz": "bc4f9b694c886df968db188f4687281d701f6fc4e19a1b59abaea247097dcd9d", - "dist/2024-02-04/rust-std-beta-x86_64-apple-darwin.tar.xz": "18530dddf369372f1f3543f8f7f34200c278cffbb2de148ec4016b07b96ae683", - "dist/2024-02-04/rust-std-beta-x86_64-apple-ios.tar.gz": "ac0ed15c9d62aaf8ae298def444cd5cd06a1701564fab564d4a4c767c294c1a1", - "dist/2024-02-04/rust-std-beta-x86_64-apple-ios.tar.xz": "57171af9b001f9b0ebd66c7643cb0a93e752320f188b6948b261abf27179360d", - "dist/2024-02-04/rust-std-beta-x86_64-fortanix-unknown-sgx.tar.gz": "29efc21fac21062e5a0af8f2431be998cd949b12e1f73b569967e9aee68bcefa", - "dist/2024-02-04/rust-std-beta-x86_64-fortanix-unknown-sgx.tar.xz": "d1d290ac8ddf7ec133fe1de3e5307855a86dd5780a434091198294d18194869b", - "dist/2024-02-04/rust-std-beta-x86_64-linux-android.tar.gz": "1f3a99d4d9f9283e62d9922145b63bb6ca58744eca51d3ba28277b6ae2581fdf", - "dist/2024-02-04/rust-std-beta-x86_64-linux-android.tar.xz": "34f8d2ef07c40b34d8893f93f42d9f06bde8d56c146ec1b6518a497fd68e6ca0", - "dist/2024-02-04/rust-std-beta-x86_64-pc-solaris.tar.gz": "e15b87f78925ee15b3c71c6f3cdc0cff12dd06369be53402d7115300c07e316d", - "dist/2024-02-04/rust-std-beta-x86_64-pc-solaris.tar.xz": "4f5a353057ec31568f3403c01d30d1d3aa22721be942c61928634c5e10332ce0", - "dist/2024-02-04/rust-std-beta-x86_64-pc-windows-gnu.tar.gz": "898e9bacfd9fc7f34a7543066304f4f5dd3596ef37d4a3b3bac5524ffd6ef236", - "dist/2024-02-04/rust-std-beta-x86_64-pc-windows-gnu.tar.xz": "3a4cf02b56049bb998aea963651c0c26e8084bb4232c2efa8be14740836c4da1", - "dist/2024-02-04/rust-std-beta-x86_64-pc-windows-msvc.tar.gz": "3d2d2896d535374396e3cd5b71b4135baf5a5ae2aaecc591981127dcb7717555", - "dist/2024-02-04/rust-std-beta-x86_64-pc-windows-msvc.tar.xz": "2b3a4329cd34ae5d61f0ce8712e5e73cfa9e11a6b861f7e796a2055533f8e1a1", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-freebsd.tar.gz": "a89890d16282ba9c030e32c5904117be8317c69fce09611bf8ebff440d13a1fb", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-freebsd.tar.xz": "a02a5962c65cbe60667a45d5ad5ec28f1dc86d18344c619fba00f9afd96519e1", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-fuchsia.tar.gz": "1dc8c719ac47a37c47993b75e1b1280579504bb01bf3feb39b30a10b947b75ff", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-fuchsia.tar.xz": "106c9d4fd1072dfbacb67674a2b0753c9742fb87e83ff32cf3ad3ce1f8d94874", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-illumos.tar.gz": "a004aab7ce4f922afa7248af5fa17fd1966a9e79b472ae4ea9496e7915bbf0f3", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-illumos.tar.xz": "0f3df2ea274c6bf201617c5b385b0e7752077e6497a3dd49f45f2431e3f2af38", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-linux-gnu.tar.gz": "b929350cb8aef37ac3a32f06c144cbd75884f60b26ec9316c1f675a472f1c522", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-linux-gnu.tar.xz": "20fffbd0d4e5bb19a428c2c808aa47f6d7a285291df204fe73a45f7d3720c3a4", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-linux-gnux32.tar.gz": "383746f4d90d7dbca5297928bf5705d50f974ac3c97fe4dadd6ec33b5aa65059", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-linux-gnux32.tar.xz": "60372cc7f84c6727272360ae1fdc316376ec12f632365a8deb9420f953cece2f", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-linux-musl.tar.gz": "2fb0649206c57187b216464d6db86cbb4385e061098348181d654976570f74c4", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-linux-musl.tar.xz": "6a22fa944f66afdc4af68d25f37b88f80dec10211e808965e0f9a41f7a5e18b6", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-netbsd.tar.gz": "3700739a966b4e9e12088518d22ff535065f666c6f8c74fc8384fb183f4e8fe5", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-netbsd.tar.xz": "b6561834aa28caad3b68248863834e8320ee43916488336f575a6860efb1a509", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-none.tar.gz": "7a56f666a6b42b666afc12555f3b82c0877c2c3beedba53037d8a66ea0ab2c8e", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-none.tar.xz": "3f8a61eb7a7015b639769d9cee9b78653b0efe4da1333b315a67982e88ed2f54", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-redox.tar.gz": "4b3aebbaced9a09de3d2b1d745d53feec2b927e0ae15ee822cc57b003f4cdb6b", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-redox.tar.xz": "69d286adaba6f18daf052156cf88e994bee40b3e8a9c467d51b3f7264e8c5882", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-uefi.tar.gz": "0dc258a276435d1a689d1067913573a4454d5b0e54e90304338f07b0cb6b7c68", - "dist/2024-02-04/rust-std-beta-x86_64-unknown-uefi.tar.xz": "ca131284758bfd1defac4e95b68dba9bdb496b2a1ed4312b05ce996308d870b1", - "dist/2024-02-04/rustc-beta-aarch64-apple-darwin.tar.gz": "f874ba6539750fc510fa67749f6a341c80497a0ea7ace5b8366849fb3a304973", - "dist/2024-02-04/rustc-beta-aarch64-apple-darwin.tar.xz": "8a1a9359e59c7057a39eeaaa6bbb180b61e00993d534b63b52ac447b31345886", - "dist/2024-02-04/rustc-beta-aarch64-pc-windows-msvc.tar.gz": "449e0a684783ba2ad04e4aa18761da9ee4144333426335b0503526d7d0c23f3e", - "dist/2024-02-04/rustc-beta-aarch64-pc-windows-msvc.tar.xz": "4075cbd97eceae6ba41a2862a6149f72c33ddd351c6cdf8e401de19b485ae3e2", - "dist/2024-02-04/rustc-beta-aarch64-unknown-linux-gnu.tar.gz": "99a1c8fcc434905b80086d276dbb162105d7803f8594a44b518245877320e387", - "dist/2024-02-04/rustc-beta-aarch64-unknown-linux-gnu.tar.xz": "32ab0d6814abbb16724ea6d7d422fea587fa8d4fb7e49d04c418e9f58c380464", - "dist/2024-02-04/rustc-beta-aarch64-unknown-linux-musl.tar.gz": "04dec9fdfa8429ed3b53aac9445a54a4a486d1c4439d91e3c5214c62207163c8", - "dist/2024-02-04/rustc-beta-aarch64-unknown-linux-musl.tar.xz": "797f8ed5112414d258de8b28f0d1d85661fa35ae0699ad89a868d7f16123e5e0", - "dist/2024-02-04/rustc-beta-arm-unknown-linux-gnueabi.tar.gz": "31c3ad00fd019cdda335630da3791633f28b79a84d847404e877efa1d963b700", - "dist/2024-02-04/rustc-beta-arm-unknown-linux-gnueabi.tar.xz": "265de8a5d1317fd686497ddcbd47adc96270b9318333296edbe57247907cea87", - "dist/2024-02-04/rustc-beta-arm-unknown-linux-gnueabihf.tar.gz": "080f20064ce64e26b35d15c0bcefd20edc37f0f4627eec997fefb99932635687", - "dist/2024-02-04/rustc-beta-arm-unknown-linux-gnueabihf.tar.xz": "aa144f7121a29087a6b6e057a646fa091ec7af5b48b2701c7bb514c698d510e4", - "dist/2024-02-04/rustc-beta-armv7-unknown-linux-gnueabihf.tar.gz": "bf1f0a9764e04d9d07702ba7563c93ec17ae527332d72b4e21d8de9bd176c4c5", - "dist/2024-02-04/rustc-beta-armv7-unknown-linux-gnueabihf.tar.xz": "17ed4d2cac212fcfbe1c75c482f195100ee2fabcdd85cedf78b5ea8f1355148b", - "dist/2024-02-04/rustc-beta-i686-pc-windows-gnu.tar.gz": "fa0e1ad64cf3b59682df001192c91c26edf1d41fda8f0fb3a6c535fa1597098f", - "dist/2024-02-04/rustc-beta-i686-pc-windows-gnu.tar.xz": "3f5eb74282649ed398d8a60bda4098ea8ec10b81a00cc48c65976f68d064ba6a", - "dist/2024-02-04/rustc-beta-i686-pc-windows-msvc.tar.gz": "188f1c8c1b38ece4b50db74422ab7d4b8dc40d5ee2f9a10ad2a797ea748f4ce0", - "dist/2024-02-04/rustc-beta-i686-pc-windows-msvc.tar.xz": "b9768ef55563ba4008b5886e6b20b7dfb81668452f264cf4cf9809e6fa3e1d84", - "dist/2024-02-04/rustc-beta-i686-unknown-linux-gnu.tar.gz": "c369728545e027cdaf9b92243f98979e66684d79159192ee7a22a62603905942", - "dist/2024-02-04/rustc-beta-i686-unknown-linux-gnu.tar.xz": "ec946c31d336a69912f6f0effa0986532dbdd915a1b268c419e5ba68365671fe", - "dist/2024-02-04/rustc-beta-loongarch64-unknown-linux-gnu.tar.gz": "f49cac3db11d02f6b197354b25e2181ae7afd13837df3bccca8cda135373ae6d", - "dist/2024-02-04/rustc-beta-loongarch64-unknown-linux-gnu.tar.xz": "b4ffc655994a64dd5644a30363e0518a2958337f187da7e4a9285658c899ab6b", - "dist/2024-02-04/rustc-beta-powerpc-unknown-linux-gnu.tar.gz": "b29c64744cc8154e1eb89ec525fbc92187b666d1f7d013523d0f7e6c089b5be9", - "dist/2024-02-04/rustc-beta-powerpc-unknown-linux-gnu.tar.xz": "5534dba963a2ae299f16b85c1fb76bfd62e94e4c9da16a97aaec26572b61f217", - "dist/2024-02-04/rustc-beta-powerpc64-unknown-linux-gnu.tar.gz": "a432e73044ffa25fb6c104a82156048519f79faa6e1845e5e0d5ef448d1d682d", - "dist/2024-02-04/rustc-beta-powerpc64-unknown-linux-gnu.tar.xz": "aa1688326584956677dd76c0e3620e34a3287c077b882b5b159e0d756cbf189b", - "dist/2024-02-04/rustc-beta-powerpc64le-unknown-linux-gnu.tar.gz": "8534f8087cbbf9f4f44f43cc8c276dba304aa0b5f9ea437cfa162d667aef1774", - "dist/2024-02-04/rustc-beta-powerpc64le-unknown-linux-gnu.tar.xz": "12bcba399fbff493b114bb4726a6b3fe32936a1f42134b1496b6ce44baea52dc", - "dist/2024-02-04/rustc-beta-riscv64gc-unknown-linux-gnu.tar.gz": "5ca25bc3c268c3df4de1740fd62f5dfb62482833be38180aa34bf220b9ec3021", - "dist/2024-02-04/rustc-beta-riscv64gc-unknown-linux-gnu.tar.xz": "e7187288ac175404c2a3e78776324e70c2a0d3b6fb673366eac881a48f11ab74", - "dist/2024-02-04/rustc-beta-s390x-unknown-linux-gnu.tar.gz": "31735567bd85a94325af81e5029c652c8b1b2e5824c4f65fa48f864aca65393e", - "dist/2024-02-04/rustc-beta-s390x-unknown-linux-gnu.tar.xz": "916afb19bb784d80093a372fa6316c72d2fa1aee3aa038554a3335ae3f62f773", - "dist/2024-02-04/rustc-beta-x86_64-apple-darwin.tar.gz": "d1445ab2c427e1e504521047c5e1e8d43b43dc4bb9dcf859e3d8b0110a6de257", - "dist/2024-02-04/rustc-beta-x86_64-apple-darwin.tar.xz": "cafb899caeec207a7e2842f03210b85d50d09f152468ab9ec1e53fa8c7511da1", - "dist/2024-02-04/rustc-beta-x86_64-pc-windows-gnu.tar.gz": "eab3692edecd9957cbd0e2f8fe148ee81600ddde9d07e7693859bd2943784b49", - "dist/2024-02-04/rustc-beta-x86_64-pc-windows-gnu.tar.xz": "4b711b2375c16990d9f22ca32baedf8b0d57073d914ea392028944a019a7e4cb", - "dist/2024-02-04/rustc-beta-x86_64-pc-windows-msvc.tar.gz": "80de1f677bbf1d1c51fcabe130b81dd97cc49fcacc96bc9dbda94da1acf4d504", - "dist/2024-02-04/rustc-beta-x86_64-pc-windows-msvc.tar.xz": "912e3ab500ed82ecca7688bbb7c5c40555cbb4d5ea9ec059a9287f69ca7241ab", - "dist/2024-02-04/rustc-beta-x86_64-unknown-freebsd.tar.gz": "632ba8e019403eddde89653cd4bf1864fd0b274603399371871cd1ded296d1d9", - "dist/2024-02-04/rustc-beta-x86_64-unknown-freebsd.tar.xz": "b5de56f1f686befd7d225c4fc0636132119a28e6ed22e56300347e8c8fd4388b", - "dist/2024-02-04/rustc-beta-x86_64-unknown-illumos.tar.gz": "f906f3492094d609d8d5fb5a563a8f2201dc21c65228c7d214a57ea795e8bca5", - "dist/2024-02-04/rustc-beta-x86_64-unknown-illumos.tar.xz": "4f29c6a41a993794dfdca0502c33ef77a3a888281c3b9e368f1befdfecc643e2", - "dist/2024-02-04/rustc-beta-x86_64-unknown-linux-gnu.tar.gz": "ce323665ebe9bc3d96e7016af21e18788e42e94c647ff1c08cdeb6ad9acc3b1c", - "dist/2024-02-04/rustc-beta-x86_64-unknown-linux-gnu.tar.xz": "6db29020afc7fb486f305e3508ee978c2ce44ce9b844ec6fe0102a16c798dc13", - "dist/2024-02-04/rustc-beta-x86_64-unknown-linux-musl.tar.gz": "b5b5dd243653e8f1073542774c918152eeb73020859dcc3229045b1980d50bae", - "dist/2024-02-04/rustc-beta-x86_64-unknown-linux-musl.tar.xz": "f8127a732817b1d5c091f7a508c3d5367b33e57ea6be023161be1bcc35b3b62d", - "dist/2024-02-04/rustc-beta-x86_64-unknown-netbsd.tar.gz": "73b19bc4dc2f44a04cae327ddc4740915bffb0a2182ff94438c614dce3b5ddf2", - "dist/2024-02-04/rustc-beta-x86_64-unknown-netbsd.tar.xz": "d72e53f0a99a897d5f36999957fee251d67030fbf711b1b8d554011ad0a7e559", - "dist/2024-02-04/rustc-nightly-aarch64-apple-darwin.tar.gz": "f81993a7d1c0677779a6a44ec1f475abb03e8c79ec493cb22ff194b0d6edfc2b", - "dist/2024-02-04/rustc-nightly-aarch64-apple-darwin.tar.xz": "a6247fae04e79529097f2ff5b9c8110ce4f015ba5f9503fbcd0c15c8ba84eb9e", - "dist/2024-02-04/rustc-nightly-aarch64-pc-windows-msvc.tar.gz": "012a0b1eff9a277c8b7dc01204346922f64099450269716dafe8c7d257bdc043", - "dist/2024-02-04/rustc-nightly-aarch64-pc-windows-msvc.tar.xz": "d16d3c5da39586678fa34932f597294277d1949ff57b99e67ce5b4dcfda9ffc6", - "dist/2024-02-04/rustc-nightly-aarch64-unknown-linux-gnu.tar.gz": "defca5334cffc68e2b79917455ac7e8e210870794f23189ac0a8fdab7cfd7364", - "dist/2024-02-04/rustc-nightly-aarch64-unknown-linux-gnu.tar.xz": "2c0af5b6a06fc2e539ad0774b95f021dfbd75730d900d13567ea8ee757f9ecb1", - "dist/2024-02-04/rustc-nightly-aarch64-unknown-linux-musl.tar.gz": "93bebac9baaf10f90b535a46f8a33abe55b2d468d7ec27ae53ac6ff31afe2833", - "dist/2024-02-04/rustc-nightly-aarch64-unknown-linux-musl.tar.xz": "937f84bf311714bccc88ef1e982e3261e04e5fc5419de098fbc65df15df3975c", - "dist/2024-02-04/rustc-nightly-arm-unknown-linux-gnueabi.tar.gz": "87d8a6dc5ad4103eea1cf5ee76858b4e78188302fbb6e0ac846f284b388f8e7a", - "dist/2024-02-04/rustc-nightly-arm-unknown-linux-gnueabi.tar.xz": "74878a2b70a1476588a5638b953711bd62c25027a9555d10e6fd4e5218a7d817", - "dist/2024-02-04/rustc-nightly-arm-unknown-linux-gnueabihf.tar.gz": "1fb50fa12f3c412e30df241ac6215a19bb600a04a1fb3332434f9c73bc7d2b74", - "dist/2024-02-04/rustc-nightly-arm-unknown-linux-gnueabihf.tar.xz": "85807b419b6f45493c60f3ab3f5d00fe7ffaca6366e6a0ec57227a30ffae2f22", - "dist/2024-02-04/rustc-nightly-armv7-unknown-linux-gnueabihf.tar.gz": "63d233d9ac741f842c21762032ec4f0139a9b46cc8a4785bfc1b9ad6b586a128", - "dist/2024-02-04/rustc-nightly-armv7-unknown-linux-gnueabihf.tar.xz": "199b00d4bb829f9688cbc9e8fa065d80ef4d20c1723c39f4b1a61ebfc544bc88", - "dist/2024-02-04/rustc-nightly-i686-pc-windows-gnu.tar.gz": "e66c39fbd427b6cfd027095110c954035e5a3d117b848c7cc072ca93f41bcbcb", - "dist/2024-02-04/rustc-nightly-i686-pc-windows-gnu.tar.xz": "9974067580a9d77f4722914c0d60dcb2e451cdb9c059514982bbf4721bd62ce5", - "dist/2024-02-04/rustc-nightly-i686-pc-windows-msvc.tar.gz": "e8189dd6c054dc1cba690a9805593d173de64009166b4542c30cd902cb82537a", - "dist/2024-02-04/rustc-nightly-i686-pc-windows-msvc.tar.xz": "5b9bc862dbf5bf00accf769fd70b9915c4a0faad7fc8ca648789aeefbb7f5ba6", - "dist/2024-02-04/rustc-nightly-i686-unknown-linux-gnu.tar.gz": "b0eebf6d08c9f730458f444afd15d405465adbf2dffe93bf9a042f28d11851e4", - "dist/2024-02-04/rustc-nightly-i686-unknown-linux-gnu.tar.xz": "248c1ecddaddee7dbdf3eabcb4a1b645005103b0ee0659d1bc71b5a59c1c9e4b", - "dist/2024-02-04/rustc-nightly-loongarch64-unknown-linux-gnu.tar.gz": "ea139b005b21e1baed7f79944af6cb2d8f24ac8c7bb009474e3a578250c6a65a", - "dist/2024-02-04/rustc-nightly-loongarch64-unknown-linux-gnu.tar.xz": "a3601a3bdc6bb998fe8a6a9ade212179addbbb684c0c47c46cb1c0632ab9fe41", - "dist/2024-02-04/rustc-nightly-powerpc-unknown-linux-gnu.tar.gz": "d64bffffff505541789ab0395187506c916f5b239ef3d0875dbb0f0c79c575e8", - "dist/2024-02-04/rustc-nightly-powerpc-unknown-linux-gnu.tar.xz": "5e1c528da9fa9818e5f581342346fa30b99d073dbce2241b4ebecfb7cf9674a7", - "dist/2024-02-04/rustc-nightly-powerpc64-unknown-linux-gnu.tar.gz": "0603be408a0bc368f669eb193c115bca687d7d6d1026fca6de5d317acb3597da", - "dist/2024-02-04/rustc-nightly-powerpc64-unknown-linux-gnu.tar.xz": "f61303e16f16c61f89e8dda24a5706808ef79f5fce7da8ee36b7aa3ec70f66f1", - "dist/2024-02-04/rustc-nightly-powerpc64le-unknown-linux-gnu.tar.gz": "288e7b6b31aff284f06b14f1eb4ea0b2547aa019e8865d05710a64fe9993ddb2", - "dist/2024-02-04/rustc-nightly-powerpc64le-unknown-linux-gnu.tar.xz": "885ef5324a55e78557b290bdf10501e27763daec209ad56f2e1840435a6e944b", - "dist/2024-02-04/rustc-nightly-riscv64gc-unknown-linux-gnu.tar.gz": "3ccf5a674d290e1ede918516002d0b626828299edb7fe87dfc128cc9afa9770c", - "dist/2024-02-04/rustc-nightly-riscv64gc-unknown-linux-gnu.tar.xz": "374a74c1b950f4be741f69d7f2670ac0d037a2a657361b94cd1c32892481edec", - "dist/2024-02-04/rustc-nightly-s390x-unknown-linux-gnu.tar.gz": "f21d304ea482d889319f285b5246f44461acdf6dabe288962065441bea82186b", - "dist/2024-02-04/rustc-nightly-s390x-unknown-linux-gnu.tar.xz": "d617d2b45de255f4588c2a9dc9686be554113b2683b8d8b149d1ce128da2dcc3", - "dist/2024-02-04/rustc-nightly-x86_64-apple-darwin.tar.gz": "26c662009b90638796c48a72de57e64e994491754112c5d6af0a65d24f4ef149", - "dist/2024-02-04/rustc-nightly-x86_64-apple-darwin.tar.xz": "811acb173348408b59b1ad63e0d2f8cbeccb91a86f13b432a6b70e8d6ebae937", - "dist/2024-02-04/rustc-nightly-x86_64-pc-windows-gnu.tar.gz": "3cd84e215365e8eba1aec1c6ed630e8899b1dcb36d04d52f1fbb713150eb60cd", - "dist/2024-02-04/rustc-nightly-x86_64-pc-windows-gnu.tar.xz": "454f0b75e6dd0bd893413dc7e2f36170d3af041e1e2b7d4792cc61f7cd7f27e2", - "dist/2024-02-04/rustc-nightly-x86_64-pc-windows-msvc.tar.gz": "512a0922ee16c4d5264b7ea398788651d04910dcdb3edd87bd8fc3914855c29c", - "dist/2024-02-04/rustc-nightly-x86_64-pc-windows-msvc.tar.xz": "e5a43c30c0016728aaff405ef3e28eefd8b60eb878fc31a5038aa056ae8cfb1f", - "dist/2024-02-04/rustc-nightly-x86_64-unknown-freebsd.tar.gz": "0330724ffe7c0d4b3ed38514c303b1cbed3deb0e074e8d36f7de96c469c0c51d", - "dist/2024-02-04/rustc-nightly-x86_64-unknown-freebsd.tar.xz": "5159bb4b9e32f64ed4712ab52dcc373e4838cec0f8e5bc16b281481a828dc84e", - "dist/2024-02-04/rustc-nightly-x86_64-unknown-illumos.tar.gz": "d8bdb12e09d76f4b4ebe9f089a6bc11f501e994ef23aefe7574b5c5a583fd2fc", - "dist/2024-02-04/rustc-nightly-x86_64-unknown-illumos.tar.xz": "301584763ea946532eca1e5be8ff7b7587ac9066c8f047f90598158e1ae6f5cf", - "dist/2024-02-04/rustc-nightly-x86_64-unknown-linux-gnu.tar.gz": "3f4d36a06c74d62bb097e4b94b4ab1caf3d8d63650e0e4ef038748dab13c4413", - "dist/2024-02-04/rustc-nightly-x86_64-unknown-linux-gnu.tar.xz": "33446798bf2f60451e31376286da2ad62372ef5ec048453900f6e6b3c4f0f0ee", - "dist/2024-02-04/rustc-nightly-x86_64-unknown-linux-musl.tar.gz": "9a1fc786d418a927a63ceae0999e641767de5cc8821fc57dbe0546f495d21600", - "dist/2024-02-04/rustc-nightly-x86_64-unknown-linux-musl.tar.xz": "0a36838259d73d577126cdee909b6446d62730d0d13655442312fca9cd13ce84", - "dist/2024-02-04/rustc-nightly-x86_64-unknown-netbsd.tar.gz": "30e91ca5a0389898d9eea8a063b52dc4dd5e7f8cafba1024fbbf1d80ab28c590", - "dist/2024-02-04/rustc-nightly-x86_64-unknown-netbsd.tar.xz": "49238b11b1626dcfc8bebf02912935922585bfdce777c8eb7bf5abfabe664af0", - "dist/2024-02-04/rustfmt-nightly-aarch64-apple-darwin.tar.gz": "4e7d77d6a66ff3bf1de608913429e78a87ff80d8260e078d7e866a09b6ed74cc", - "dist/2024-02-04/rustfmt-nightly-aarch64-apple-darwin.tar.xz": "ebb64953e7919ff371b1625e48cd7c9063fc7fc72f085603831ed7a1eef371d3", - "dist/2024-02-04/rustfmt-nightly-aarch64-pc-windows-msvc.tar.gz": "44bb652d0268e03bc333ccc90f96107e249ee3d96a688aac1f3a27161c62a176", - "dist/2024-02-04/rustfmt-nightly-aarch64-pc-windows-msvc.tar.xz": "e272d2633828e00ebf0a1708b807fa958cac2673b162637c4983a40f191574e7", - "dist/2024-02-04/rustfmt-nightly-aarch64-unknown-linux-gnu.tar.gz": "aa9b56b48fda4844f56bd7a0073c91b5aa79215f61444346e9849036ba003252", - "dist/2024-02-04/rustfmt-nightly-aarch64-unknown-linux-gnu.tar.xz": "b23367c99e79d2db72b16d9d77addd3790ddf0889987beb24c917e4e54bcf511", - "dist/2024-02-04/rustfmt-nightly-aarch64-unknown-linux-musl.tar.gz": "c001dba171255113d25c2e2743ca2b4cb36aa0a628da333911b92474ae8e6603", - "dist/2024-02-04/rustfmt-nightly-aarch64-unknown-linux-musl.tar.xz": "14a2b8a352b1fc0c6c993c5a51cf4d23ed50b6b14b092f78917808861dc4ac49", - "dist/2024-02-04/rustfmt-nightly-arm-unknown-linux-gnueabi.tar.gz": "ec2e8f55671b1d9643d338530263feb47f99d81ff7c862ac46ad32b8459b6435", - "dist/2024-02-04/rustfmt-nightly-arm-unknown-linux-gnueabi.tar.xz": "10b957fc066da91fa81eeeca66e2f7c97c7e7fc9d496471fd22b086a9e2bb62e", - "dist/2024-02-04/rustfmt-nightly-arm-unknown-linux-gnueabihf.tar.gz": "1dd859841cea9ac9d09a1521c57ddbe042bdc693c7df60ff34c876a8faca3745", - "dist/2024-02-04/rustfmt-nightly-arm-unknown-linux-gnueabihf.tar.xz": "b11ca576f29df7c81496c4b379435853a0bfee8ff838d2c57e1e3cded6f889eb", - "dist/2024-02-04/rustfmt-nightly-armv7-unknown-linux-gnueabihf.tar.gz": "e0c53737686587010f4fd299430a0d48e47ad0f3d12e29a5d6810dceabd09b09", - "dist/2024-02-04/rustfmt-nightly-armv7-unknown-linux-gnueabihf.tar.xz": "f70dc356985081a43f19c2cc6e599f2967d9c0a60b2d9be0a3939a04a88b768a", - "dist/2024-02-04/rustfmt-nightly-i686-pc-windows-gnu.tar.gz": "159c4a6ebbce05142bf6e844c4e6cfc9a90eb298f581db7521ea5fb1fd303731", - "dist/2024-02-04/rustfmt-nightly-i686-pc-windows-gnu.tar.xz": "8cb69a4ff1207c0b7944dd71e1af666e12be5c8ec0d0ec244b2e4d9b99535f29", - "dist/2024-02-04/rustfmt-nightly-i686-pc-windows-msvc.tar.gz": "0eb4218c6d271c194282ca11af2436e2ed2e51ee3b62725a04a995afb3bc6ff9", - "dist/2024-02-04/rustfmt-nightly-i686-pc-windows-msvc.tar.xz": "2f9e4d03968cf07b950d188135d231d1183d92520c76a4ded3973acb374bdefc", - "dist/2024-02-04/rustfmt-nightly-i686-unknown-linux-gnu.tar.gz": "b6648b637564ffe5cf79da7c7eb73df377a2d0e0e0c66a05806af4fc87f61afa", - "dist/2024-02-04/rustfmt-nightly-i686-unknown-linux-gnu.tar.xz": "09e2aae1c73f874ce4dbdb84d532264cc21d99444e0b7b1e9239a002fe0c2466", - "dist/2024-02-04/rustfmt-nightly-loongarch64-unknown-linux-gnu.tar.gz": "87bfeb0da3af4ad9f341482325b81d13691e749b73627eabe7c73ac5bcd126e3", - "dist/2024-02-04/rustfmt-nightly-loongarch64-unknown-linux-gnu.tar.xz": "2bf074d90957c17e3d8962dd8ab68d0a76f4deaf86f1104cce56d2748fc21b3a", - "dist/2024-02-04/rustfmt-nightly-powerpc-unknown-linux-gnu.tar.gz": "7fe5ee7ce30a1fbe5c5c0f20ef311f5840eebc9466e7c4bb2082a12bad2d987c", - "dist/2024-02-04/rustfmt-nightly-powerpc-unknown-linux-gnu.tar.xz": "43c3d64ed01e56c1961dbcde4d9c2c14a799d141d6c00ac72500ac84aafaf696", - "dist/2024-02-04/rustfmt-nightly-powerpc64-unknown-linux-gnu.tar.gz": "d6a54980ef61acb4f2422f0f621a6168055df95720fd864b58748884606e8a6b", - "dist/2024-02-04/rustfmt-nightly-powerpc64-unknown-linux-gnu.tar.xz": "d0d9fa1a65ef6dcf0d1fa1496d1682ca627cb978a8bf4a68ab3f27060daa37ed", - "dist/2024-02-04/rustfmt-nightly-powerpc64le-unknown-linux-gnu.tar.gz": "fcd0539279be6ee5f2ed11f1ae0879596a29804d2415398a016b26aa1683f08a", - "dist/2024-02-04/rustfmt-nightly-powerpc64le-unknown-linux-gnu.tar.xz": "cfceea6563230c64b4e77110e98dc41208c6d50b3d4bce3133abd7f66db5ce29", - "dist/2024-02-04/rustfmt-nightly-riscv64gc-unknown-linux-gnu.tar.gz": "6559653ef0a9b2d52baa94f6fd14433769b3001401daac03536ad0d1528418c1", - "dist/2024-02-04/rustfmt-nightly-riscv64gc-unknown-linux-gnu.tar.xz": "ac1c4f99a801e853c175735338a5485de2ad21ff633da75ced8b11ccd86ecd68", - "dist/2024-02-04/rustfmt-nightly-s390x-unknown-linux-gnu.tar.gz": "33835f14d65e2c21c1b69a45c70c89939a37b4d5b07660ef2acbba033c7bc8a1", - "dist/2024-02-04/rustfmt-nightly-s390x-unknown-linux-gnu.tar.xz": "46b8eb78bc1842b66e14e1995359cd85349ad2fd30a5b5c3a369de346dad8fa1", - "dist/2024-02-04/rustfmt-nightly-x86_64-apple-darwin.tar.gz": "d7f0bb3f2e4d6cd6c68817cd99ef7cdd95ca274e86866edb9b76bfad071ccf37", - "dist/2024-02-04/rustfmt-nightly-x86_64-apple-darwin.tar.xz": "7d86a0aeba42a5571b01ca7008c38854e17c067c53794c34d18ebc1cad536ae8", - "dist/2024-02-04/rustfmt-nightly-x86_64-pc-windows-gnu.tar.gz": "5b788121f69bc0e16dabb014d7efaef4855d20016d2d710e6bf0e35dfc16d5b0", - "dist/2024-02-04/rustfmt-nightly-x86_64-pc-windows-gnu.tar.xz": "b4b4ad7ecd280001aff71cf264f465e47effe52260c95fb23c884ab5fe4d51a8", - "dist/2024-02-04/rustfmt-nightly-x86_64-pc-windows-msvc.tar.gz": "6075688bb91902af0c114fe9619a0102f57641bf88b8902eb950f9d324bf5a25", - "dist/2024-02-04/rustfmt-nightly-x86_64-pc-windows-msvc.tar.xz": "908068a7088b20c1dc52eaefb9aa4314233536c40520b491e55a555283b243ce", - "dist/2024-02-04/rustfmt-nightly-x86_64-unknown-freebsd.tar.gz": "5a9af3515b1b142127a9686b4f41d4c8050a496e0387a2a2703fe092bffaeb68", - "dist/2024-02-04/rustfmt-nightly-x86_64-unknown-freebsd.tar.xz": "6796dbdeadd39bc66686bbdf9966fc488684543f806c25315c3a682c4c989c58", - "dist/2024-02-04/rustfmt-nightly-x86_64-unknown-illumos.tar.gz": "4f763f33318529e1d400d2058b8ff8de6d29e37de0744a8e0ae17ae677465c81", - "dist/2024-02-04/rustfmt-nightly-x86_64-unknown-illumos.tar.xz": "18aa04c9e8d00593f11b5e593a64875197e3db7de752215882d247a39c71ef0d", - "dist/2024-02-04/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.gz": "5be7c353d1e1f8445936f1572b5d99ca190a914c71341bb855048c5003c0cda2", - "dist/2024-02-04/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz": "1342bf737bba2e9787203da78d859f40739af4c57e9ec5bc0e07966e91388813", - "dist/2024-02-04/rustfmt-nightly-x86_64-unknown-linux-musl.tar.gz": "0776b76ae5338f186f631a1f0e6f755d03612892399d96f3c2d9c59ba9f094c3", - "dist/2024-02-04/rustfmt-nightly-x86_64-unknown-linux-musl.tar.xz": "36d491cc2eb35250536d3b053d180835c8041d9f6ed96f243c04e9644d040c96", - "dist/2024-02-04/rustfmt-nightly-x86_64-unknown-netbsd.tar.gz": "185e2dee21941bc4c3e8edcf5f12d334b2c339f3f388f182a8ae519928e907e4", - "dist/2024-02-04/rustfmt-nightly-x86_64-unknown-netbsd.tar.xz": "d770b13ad43852d6e91bea1747b6e82b1cddc716307f8df4dd95941df76a1355" + "dist/2024-03-19/cargo-beta-aarch64-apple-darwin.tar.gz": "d8aeeb8d427c346112020b84de85c1498d1ea043a01a45dd63d38da8ae0d35d1", + "dist/2024-03-19/cargo-beta-aarch64-apple-darwin.tar.xz": "f4c3aec8e916a93412c6c798c43dab1dd64c0095509a2a255191751a230730ad", + "dist/2024-03-19/cargo-beta-aarch64-pc-windows-msvc.tar.gz": "d6161a55f808b6d54a061f9ffd9c33489b844f450f07a40e2f6cdb7def75792b", + "dist/2024-03-19/cargo-beta-aarch64-pc-windows-msvc.tar.xz": "cba6e510866f9d920ee40e66069e8d152c0bfdabcc280ba0175a103460614839", + "dist/2024-03-19/cargo-beta-aarch64-unknown-linux-gnu.tar.gz": "e99299705d9b596554a4156ca7e8cd1bab95d926b519fd79e24d7b4c00bf4bbe", + "dist/2024-03-19/cargo-beta-aarch64-unknown-linux-gnu.tar.xz": "d006ecc2215a0b7b1d3040c64d72094589bfe11f1ffd34f63e5aaa8fb52ee4b2", + "dist/2024-03-19/cargo-beta-aarch64-unknown-linux-musl.tar.gz": "9f6b9bd599948b48085bf592630963a5b69608abff67dd3674327d7efdcbf695", + "dist/2024-03-19/cargo-beta-aarch64-unknown-linux-musl.tar.xz": "e3bd8ad798b098f1e03333bece43fe163f4d4b613bf38de4809106ca98b99c05", + "dist/2024-03-19/cargo-beta-arm-unknown-linux-gnueabi.tar.gz": "5ec13385ad03d14fa8fd48fd3f92df123a1626bb8a594df33c0bdee02d5a811c", + "dist/2024-03-19/cargo-beta-arm-unknown-linux-gnueabi.tar.xz": "bf201ad295272ee9435da1afcd4888c31bb14e467edb9638fdfe95b071bc869d", + "dist/2024-03-19/cargo-beta-arm-unknown-linux-gnueabihf.tar.gz": "0e09177180c2822378bdb66dca69fb8bc7e7d5c51f414bdd95b9497c683d466f", + "dist/2024-03-19/cargo-beta-arm-unknown-linux-gnueabihf.tar.xz": "5815c1421d474d8cd238fff80db5ba5231155abbd8642eeced84842d34f49ba9", + "dist/2024-03-19/cargo-beta-armv7-unknown-linux-gnueabihf.tar.gz": "36967ecac443fdcace710bae63eedcf65a4c2015793ed30ea3edae3d93f24707", + "dist/2024-03-19/cargo-beta-armv7-unknown-linux-gnueabihf.tar.xz": "1932898203f99c2aee95e71226c66b48d8dcbe40aa3a8b0782856fedcd291b13", + "dist/2024-03-19/cargo-beta-i686-pc-windows-gnu.tar.gz": "948157661b4b54b4c963933d97d4721efb6c8134242b96a82b86ee4be8dfe043", + "dist/2024-03-19/cargo-beta-i686-pc-windows-gnu.tar.xz": "26afbb06b1a47945172cee64470803670d1e41529f4e0f357f48633565efc489", + "dist/2024-03-19/cargo-beta-i686-pc-windows-msvc.tar.gz": "82e81f26ba6a207ac891a13bd9eb58c2cc33d31e78d354a210c4518b2d2b4dfd", + "dist/2024-03-19/cargo-beta-i686-pc-windows-msvc.tar.xz": "2b697674c4535bb58910dea6fdb9948a3b06ecdb723a638c01558615cbbf3fb0", + "dist/2024-03-19/cargo-beta-i686-unknown-linux-gnu.tar.gz": "2273118fc50fe605d53b078b5859d2694555f6c9ce2a61478f5af1765cffb997", + "dist/2024-03-19/cargo-beta-i686-unknown-linux-gnu.tar.xz": "53ae185d70ead1a251aac0793cbc784858d7a666530cacb63404541bef2a8bbd", + "dist/2024-03-19/cargo-beta-loongarch64-unknown-linux-gnu.tar.gz": "f37429c8406938888600b180b60db99a5343866e8ba6c595350c60a631d6cc2e", + "dist/2024-03-19/cargo-beta-loongarch64-unknown-linux-gnu.tar.xz": "ca49cac7f00c94ab5ac936c500a96092fc44a2cf9f1e10d52aa877ad9a57c548", + "dist/2024-03-19/cargo-beta-powerpc-unknown-linux-gnu.tar.gz": "262a48b6cfe9ebc8e19847e5ffa22459398395a9f9c9bb0891bf7b247b9d800a", + "dist/2024-03-19/cargo-beta-powerpc-unknown-linux-gnu.tar.xz": "6300c528f7457e0349eb2ff25e24122e5448855a4f05f265b810b328d4310516", + "dist/2024-03-19/cargo-beta-powerpc64-unknown-linux-gnu.tar.gz": "e0dd3b037664c468eee9340235454b0a01310eae6025d5e2fb142027ff079cd5", + "dist/2024-03-19/cargo-beta-powerpc64-unknown-linux-gnu.tar.xz": "36de5c67fdbc1eacdf00a51e2b44df5c1ee50ecd83755e893b6cb41bf49f30b5", + "dist/2024-03-19/cargo-beta-powerpc64le-unknown-linux-gnu.tar.gz": "cb5cdabb2d9d0398895b491f3cd128bd16488464fb3b8bc24f8e2e115154bbbf", + "dist/2024-03-19/cargo-beta-powerpc64le-unknown-linux-gnu.tar.xz": "e597718951b6f2973a68d587b84b6d4ce51e180e74b1060fdcbc3cfd05e04291", + "dist/2024-03-19/cargo-beta-riscv64gc-unknown-linux-gnu.tar.gz": "0a860fccb3f7ca44ca94ed76b1b81a2033e9c6806b32b428b49794508529e5be", + "dist/2024-03-19/cargo-beta-riscv64gc-unknown-linux-gnu.tar.xz": "10eaa329dc9a40337df22edd21a7396fd87852afcd0e68f1334cb374a56aa5bf", + "dist/2024-03-19/cargo-beta-s390x-unknown-linux-gnu.tar.gz": "2f511c9d6ba6b489d96f531778af89baa3cce98ddc2e015198a0fbda95c0077a", + "dist/2024-03-19/cargo-beta-s390x-unknown-linux-gnu.tar.xz": "d510515fa11961e56c05a946fb7200ce42b3831280177fda78260915f9b0192f", + "dist/2024-03-19/cargo-beta-x86_64-apple-darwin.tar.gz": "e4d542ce10c993bbdd1103d605c5c15771629750f204c5de76af93b0f0278391", + "dist/2024-03-19/cargo-beta-x86_64-apple-darwin.tar.xz": "36ff8a7806bd8bcb2c0054f994ec32bc5b30907c3ea2dd3cd07a440b6ee031c3", + "dist/2024-03-19/cargo-beta-x86_64-pc-windows-gnu.tar.gz": "d3daaa2be8f7b761c37cfca9a1a242e2b0231795e1cb868246ed1e379c3969d8", + "dist/2024-03-19/cargo-beta-x86_64-pc-windows-gnu.tar.xz": "1cda9d7c448336878071e6eb27338bd0346ec5ea28a8d29a6dcb3caa9b96fc54", + "dist/2024-03-19/cargo-beta-x86_64-pc-windows-msvc.tar.gz": "cd1539eca02777df1ff8bf70d4f4abe59ea3a2d1cc625fb714b941502f863198", + "dist/2024-03-19/cargo-beta-x86_64-pc-windows-msvc.tar.xz": "e97a05c1ba1a4aec2d424845b0b874712f15568c2e9cd61222663b96b759bb3f", + "dist/2024-03-19/cargo-beta-x86_64-unknown-freebsd.tar.gz": "aa2de3a607bc0fd4b4f99b2a6c8c024a75823d7ebea553748d24ad2841f3c919", + "dist/2024-03-19/cargo-beta-x86_64-unknown-freebsd.tar.xz": "6546733a7b4a34b5739b9a1d1cfac8eb7ae320a14a242e8298564e33b2b4208e", + "dist/2024-03-19/cargo-beta-x86_64-unknown-illumos.tar.gz": "e48ad6cfa052ee84226e79cd037b4ff02d6974139225a69edac26db10f894c12", + "dist/2024-03-19/cargo-beta-x86_64-unknown-illumos.tar.xz": "2a55ac5d8aecb87d7625a90a5f1560859f516a44825b189b7d0cbbe0de787bd6", + "dist/2024-03-19/cargo-beta-x86_64-unknown-linux-gnu.tar.gz": "19db36d6b51c3e16869fc4be4133e321b103211fa8fd7a072dfb8dfa5dd108b6", + "dist/2024-03-19/cargo-beta-x86_64-unknown-linux-gnu.tar.xz": "97a90f062125ed14fc9723ecf3e68e12fc5853efb83e0afeef97dadd1b0e032f", + "dist/2024-03-19/cargo-beta-x86_64-unknown-linux-musl.tar.gz": "231529bb7dbefbdba9b741a03ed210963966e217b684b05bfe8ff61af46577c9", + "dist/2024-03-19/cargo-beta-x86_64-unknown-linux-musl.tar.xz": "b5e82d094176f729dc500d67ef5f4102df558718020f43536155ac4a74d6a01b", + "dist/2024-03-19/cargo-beta-x86_64-unknown-netbsd.tar.gz": "c6b836aa6f7cd086a7316fbcaf9e3de080d310db60eacc0910a3b90bbf5c224e", + "dist/2024-03-19/cargo-beta-x86_64-unknown-netbsd.tar.xz": "dcb398fb25568a0e5374be22be14f8dc1c0a7221fc5e60dc9258d4767f774058", + "dist/2024-03-19/clippy-beta-aarch64-apple-darwin.tar.gz": "7f4cf1177f0f22f471b8bf219d13b59b626089b3c2a563b3559dc66a573c8375", + "dist/2024-03-19/clippy-beta-aarch64-apple-darwin.tar.xz": "78d5efca461180bfdcde7e4672ac06221a0809386624b4f6892e0037df8be572", + "dist/2024-03-19/clippy-beta-aarch64-pc-windows-msvc.tar.gz": "8d3443465b4f0cbd6ba7e5bd8614071ce826798f80d7c6e35cc71ef463675952", + "dist/2024-03-19/clippy-beta-aarch64-pc-windows-msvc.tar.xz": "4ea23f92b8f36a271c36df93008a00e0a0519dfdc0da69cc920f7edf317b4ae9", + "dist/2024-03-19/clippy-beta-aarch64-unknown-linux-gnu.tar.gz": "1eabd5f5bce761972022f52dc86cd408f7106a7df2a0d9b1701afc1bcb39ed39", + "dist/2024-03-19/clippy-beta-aarch64-unknown-linux-gnu.tar.xz": "05feb29e8c526ed85e331f091b046767c4a01d68129c6a873536703dee529323", + "dist/2024-03-19/clippy-beta-aarch64-unknown-linux-musl.tar.gz": "c023d628e7d23ad3d94791e595b0ce4033c24b5e53f806947b88a6cddd93e1b8", + "dist/2024-03-19/clippy-beta-aarch64-unknown-linux-musl.tar.xz": "96b29dba180d5bf4caa40b5c8538248b0b820991d91eab819b2ce0fe093640b9", + "dist/2024-03-19/clippy-beta-arm-unknown-linux-gnueabi.tar.gz": "5d9a8237c5d2258e7ff18cee7cad2308e6ce3935251c8fb74932ed84b1e23a52", + "dist/2024-03-19/clippy-beta-arm-unknown-linux-gnueabi.tar.xz": "625f0415d85c08281efb4cdd6d362636876360774297487ed92337e72058c896", + "dist/2024-03-19/clippy-beta-arm-unknown-linux-gnueabihf.tar.gz": "5d9e03efe64eb1a60dfa011b1641a74979295cf6540e081672deed82fd130132", + "dist/2024-03-19/clippy-beta-arm-unknown-linux-gnueabihf.tar.xz": "e9bed26481e7678e7e4388c0e6885ab323b9cecc270a3044b08cb681eed5333d", + "dist/2024-03-19/clippy-beta-armv7-unknown-linux-gnueabihf.tar.gz": "26e0a630657c7abe765132bfab93aa39013ff19aec1978e41968cb53e6c46693", + "dist/2024-03-19/clippy-beta-armv7-unknown-linux-gnueabihf.tar.xz": "30abee9b263f4ff6f7e696a41f5356957daae5953c224fcd1f253ce41dcd94ea", + "dist/2024-03-19/clippy-beta-i686-pc-windows-gnu.tar.gz": "845732a863b79922ed5057ddf7c911bae71381082bdcf68799c8f79c0f48d192", + "dist/2024-03-19/clippy-beta-i686-pc-windows-gnu.tar.xz": "75f1abca075af64656d176ac1ea37e24c000378f1750a708924b44fdc223c389", + "dist/2024-03-19/clippy-beta-i686-pc-windows-msvc.tar.gz": "e5a7d0ff6d1f8d9bfeaab8f8aaf1c18528c1eb447169454c965838a2b836c201", + "dist/2024-03-19/clippy-beta-i686-pc-windows-msvc.tar.xz": "ad5a7313ca6fbd8051c0db761bbae67d3405cc5a98ec20891f26c15b31b5b2b0", + "dist/2024-03-19/clippy-beta-i686-unknown-linux-gnu.tar.gz": "cf67172fcc26b9b45138f0ac12721c1fe226a892346145b4a0ff1931d60fb756", + "dist/2024-03-19/clippy-beta-i686-unknown-linux-gnu.tar.xz": "3adb4d8a782a80d85f4cdfc433f63656449a06dddc67f0b11bf399d9a8aae97a", + "dist/2024-03-19/clippy-beta-loongarch64-unknown-linux-gnu.tar.gz": "175d58f41d0b08bc1ac733bee1d16db31a4a64f7703a87ea1f13ec72b19be4d7", + "dist/2024-03-19/clippy-beta-loongarch64-unknown-linux-gnu.tar.xz": "73925325e092d84ba3a8aff695953142962221fecaab9d57dc61b4d03338bb12", + "dist/2024-03-19/clippy-beta-powerpc-unknown-linux-gnu.tar.gz": "cec90ecbdfd252e49de68fa69806f5662bd4f4ab093708104e19b228564c0ee4", + "dist/2024-03-19/clippy-beta-powerpc-unknown-linux-gnu.tar.xz": "eb085114c178c8e16ec77657fb658b537eff1125f3de5d7e07f1ccd62e8b834e", + "dist/2024-03-19/clippy-beta-powerpc64-unknown-linux-gnu.tar.gz": "b599d42a4100a7b1304eee34571abe1e6e38e873f8197e46d0d4d92dbb0ccd27", + "dist/2024-03-19/clippy-beta-powerpc64-unknown-linux-gnu.tar.xz": "57338b860b283cfed3cf1eb38083113f026cfc91135e439b75de1a3acc9e42b3", + "dist/2024-03-19/clippy-beta-powerpc64le-unknown-linux-gnu.tar.gz": "00f756d858949ad83ad32dca5c5a93cd283da3c91f4976564afd5be3b4f5927b", + "dist/2024-03-19/clippy-beta-powerpc64le-unknown-linux-gnu.tar.xz": "4a8d250c30312dfd4f8d259ca4376555bbc6cf290a884aff92e6b06a852acf6d", + "dist/2024-03-19/clippy-beta-riscv64gc-unknown-linux-gnu.tar.gz": "992a77181709bf235c1e0a335a82b0ee01fe8f749956f2aad52a386685aeae6b", + "dist/2024-03-19/clippy-beta-riscv64gc-unknown-linux-gnu.tar.xz": "b523cf81d4ffbcc0bb9f4f5805eeb39624901eea591c852f9594690350848c54", + "dist/2024-03-19/clippy-beta-s390x-unknown-linux-gnu.tar.gz": "5f22463a8c138fb3934a405bc0f7de4b5ea51c86b75f7739eccd7181fbeb4e9a", + "dist/2024-03-19/clippy-beta-s390x-unknown-linux-gnu.tar.xz": "2b507322b80e562a0dfaba16210a2f1d65051a740869ce5a952bf83a9099e0f2", + "dist/2024-03-19/clippy-beta-x86_64-apple-darwin.tar.gz": "6873e1a437b6783e349d4fe1cd69f996f579b623c231d55933ec194de19d0a15", + "dist/2024-03-19/clippy-beta-x86_64-apple-darwin.tar.xz": "4b8f43b267b25bc5f60541fe6b98254c2731f0ee55129cc132e28c4f3b2bbc24", + "dist/2024-03-19/clippy-beta-x86_64-pc-windows-gnu.tar.gz": "e697e4c34422519db58b44bf8ed164fc45dadf4ac114c3e662f6990d4d9a5522", + "dist/2024-03-19/clippy-beta-x86_64-pc-windows-gnu.tar.xz": "5ffd1038684dc68bf97f9a74c08beca4c3eb66b39b11e32e7da45b763fe1f7f2", + "dist/2024-03-19/clippy-beta-x86_64-pc-windows-msvc.tar.gz": "7e334464dbbe5be014de9ef6872a1b2066016204e7ae8c11e55fbf64bedb93da", + "dist/2024-03-19/clippy-beta-x86_64-pc-windows-msvc.tar.xz": "55b4aaa0a64d9e3cc2489a678935277d91b1f8223186c52b59bd33dbd403d52a", + "dist/2024-03-19/clippy-beta-x86_64-unknown-freebsd.tar.gz": "6fa2e2bdd09242ab44ad35853cf9493ad57d602536406ecd3504db5af87b827a", + "dist/2024-03-19/clippy-beta-x86_64-unknown-freebsd.tar.xz": "b1b79f8130d61c92d3d101a4d24416ef37fd446f18de0745be2c1fed7b276b57", + "dist/2024-03-19/clippy-beta-x86_64-unknown-illumos.tar.gz": "ee1af20cc23288fecf8ebe33e877e1de3184711a38ea378a6f4da158919b4059", + "dist/2024-03-19/clippy-beta-x86_64-unknown-illumos.tar.xz": "af724f142b19b7436547a5eb2b2b40d1acf959a73feca03efd9178948af9326a", + "dist/2024-03-19/clippy-beta-x86_64-unknown-linux-gnu.tar.gz": "376cf1787e41ba9d231191f6cae260895be18c3ececc2f2e934e850de7f1cbda", + "dist/2024-03-19/clippy-beta-x86_64-unknown-linux-gnu.tar.xz": "8d7af83d3594a151564f351eed4cdfd1c7eb5b07e073e12c6d7b7ef9ad597007", + "dist/2024-03-19/clippy-beta-x86_64-unknown-linux-musl.tar.gz": "218168e4817f70f65651f3b9561ba8e8dd3e0d8c8a33a88ba9ad0a4a501468bd", + "dist/2024-03-19/clippy-beta-x86_64-unknown-linux-musl.tar.xz": "f55143ece3326ac8c004b77e59c1a60a70b3f1189c7e2e442183097f1cf639c2", + "dist/2024-03-19/clippy-beta-x86_64-unknown-netbsd.tar.gz": "9a5c08d2e00d2f38de5a9882fe7dcadd6307a333b8caf5826687301f8d97d09a", + "dist/2024-03-19/clippy-beta-x86_64-unknown-netbsd.tar.xz": "7be02599b4c2cd26365075ebfbb1534f6875d85501fe5a300895506e41ad0824", + "dist/2024-03-19/rust-std-beta-aarch64-apple-darwin.tar.gz": "7238015aa0e8553b6e820483e15f08119fa0b6c074abe127be99fa990f132c8f", + "dist/2024-03-19/rust-std-beta-aarch64-apple-darwin.tar.xz": "0dc783f3865ddf6512721abcd9c668f6d8533c3581015cfd4740b40cb09ce199", + "dist/2024-03-19/rust-std-beta-aarch64-apple-ios-sim.tar.gz": "90541bf8f4c1fb838fff2620b55addee59687b16d3f10f92b59a41936ffa143d", + "dist/2024-03-19/rust-std-beta-aarch64-apple-ios-sim.tar.xz": "b0d14d73d404197994e41deb2d92049ec043c875a81dda52c4e4fc64e53c8065", + "dist/2024-03-19/rust-std-beta-aarch64-apple-ios.tar.gz": "3105f19fd78bcdc5171cf4041aca9da236150e43ef9c32ee1163aafbc79d311f", + "dist/2024-03-19/rust-std-beta-aarch64-apple-ios.tar.xz": "13629cec9404312c6b42fd7aac14edc5eee98947be5152ae5708db899d2ebb4e", + "dist/2024-03-19/rust-std-beta-aarch64-linux-android.tar.gz": "3fb671809fafdabcb4cd8ea6c00caf3cfa2da3421770c08abf761456f079c425", + "dist/2024-03-19/rust-std-beta-aarch64-linux-android.tar.xz": "8f8f22bd89a29db1a549414440da19f3100abb689fb095c3e09ef28a223ee3cd", + "dist/2024-03-19/rust-std-beta-aarch64-pc-windows-msvc.tar.gz": "2326cc5061a6acc3cfea5a0e2ea965e07a0103052cfb4435e5dc947573b62e11", + "dist/2024-03-19/rust-std-beta-aarch64-pc-windows-msvc.tar.xz": "87327aa9f683ef9f574348cc0ec58b0f88fdcd6563d51b69664b3588897783ca", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-fuchsia.tar.gz": "5f589736703a21a17366dd93c36ee6f597a40999ce6c305ff1e007918fe6aaef", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-fuchsia.tar.xz": "65386ce4aa697b74c463e1c8d793ded996f6dbf1327242aaf61471968212c1e7", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-linux-gnu.tar.gz": "590b12f5fdf32251c1e0ad2af619b70b73a888d3a33a705f023b81369bcbbfa8", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-linux-gnu.tar.xz": "c22e0e88e1fd0041c95317bbc0e39e7d4e4e6a8d73eedc141628ec9e41d844f5", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-linux-musl.tar.gz": "7e8e04e2bd58ac03c5dcf017562d3ad92993896a5f5a31e199990685adb206b7", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-linux-musl.tar.xz": "8d0c5b70230122904e36731290f62dcf24fca2390d4c892aeb9b8f241d380563", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-linux-ohos.tar.gz": "89d476e9654dce23fb77cef86831813d143435e4e1a9547936f5eabb9a7e649b", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-linux-ohos.tar.xz": "b1b5c25e682961301e60f115eba6177a1be97b3157a0671c0ec64563765ddfdd", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-none-softfloat.tar.gz": "e8b2b4cd75800e5cd5b8f5ad97d6ef9fef8e6a7852a227406e89a3f7f50d33d2", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-none-softfloat.tar.xz": "e5c603df1515777eb1af5c9532194fde8ea3554abfefb93499025a9a98fdc182", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-none.tar.gz": "55605666a2bde23365937c811899f9e61855a28668d4b050834b83f5af8b03b5", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-none.tar.xz": "f68fa43e4ee4d86b7bba6c316efba5ef6e3d500b0659ba4a0295df814beca459", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-uefi.tar.gz": "5b9dbe42c686670836ba26acab3afa218fa70b616d3a7951298ce5cf2eff88bd", + "dist/2024-03-19/rust-std-beta-aarch64-unknown-uefi.tar.xz": "fcc8316db3cef3a3c3240a490d18162cf724fceecb595a0c40067c6a20a53caf", + "dist/2024-03-19/rust-std-beta-arm-linux-androideabi.tar.gz": "abdd4c98992cf2f9a9a558c5c74283826de3bb48d7743e67ef1f9d1dbc40f534", + "dist/2024-03-19/rust-std-beta-arm-linux-androideabi.tar.xz": "c597c457071b82c8842958c6ad383db30741952b06b40f138a5bed3bbca62c70", + "dist/2024-03-19/rust-std-beta-arm-unknown-linux-gnueabi.tar.gz": "2a11714a2e5d18f7f255feece850a4c8ab7e1b14f6eb116c47eb972825abfdc2", + "dist/2024-03-19/rust-std-beta-arm-unknown-linux-gnueabi.tar.xz": "5a6f054ebf50bf4bb196a32019276bed1cbcb74cbd3d46877a48ed77c09638c9", + "dist/2024-03-19/rust-std-beta-arm-unknown-linux-gnueabihf.tar.gz": "422d4d3a2f32a1739d18c208e89e5c490ce9b85c771726b21d265cb7632ffd49", + "dist/2024-03-19/rust-std-beta-arm-unknown-linux-gnueabihf.tar.xz": "d9fb3be5b4d577a469f4dc9cce5e4631741d6661a994d15cc1db847ab4edcaed", + "dist/2024-03-19/rust-std-beta-arm-unknown-linux-musleabi.tar.gz": "6a9c25b659a7d16f01148144883e47bddb29e2d79f7b590f58efd4b002abe38e", + "dist/2024-03-19/rust-std-beta-arm-unknown-linux-musleabi.tar.xz": "2c797105730a6a2a9d8ec5506f2028d42aef48d7ae09fad11e1ef3a0dc3c9a81", + "dist/2024-03-19/rust-std-beta-arm-unknown-linux-musleabihf.tar.gz": "4f58e423159b7b5a8d546c288572dc644e73cfd5e22eb87f98670e1bdd4cfb42", + "dist/2024-03-19/rust-std-beta-arm-unknown-linux-musleabihf.tar.xz": "d549997c4be8efe2feee163096b370ca6ddb0884dbf82af0c1d08e5f652a3b26", + "dist/2024-03-19/rust-std-beta-armebv7r-none-eabi.tar.gz": "2e199f5246edf22faf1b8876bec5290a7a111a38cffb831fedef3f4d4e57dded", + "dist/2024-03-19/rust-std-beta-armebv7r-none-eabi.tar.xz": "ffc4118d0520df6d4101c05c4df31bdbe91ce302b37d9d41e3dfdfd8fcb5b49a", + "dist/2024-03-19/rust-std-beta-armebv7r-none-eabihf.tar.gz": "39e2a7464ef3e48104873f59b6198cad8333835a0fe46805b00f2a3a8f1989aa", + "dist/2024-03-19/rust-std-beta-armebv7r-none-eabihf.tar.xz": "ff22a6f9b7c7873fe84943bbcffabba04e2632166ce63e405056ca0ee8fcdb62", + "dist/2024-03-19/rust-std-beta-armv5te-unknown-linux-gnueabi.tar.gz": "51128c12bcd8935bed76a555da1e403e1b374155278ed957d078a2c887512a15", + "dist/2024-03-19/rust-std-beta-armv5te-unknown-linux-gnueabi.tar.xz": "5370c2da10bc8efe00f0840d8ea6f664d38518288ed402a4ac164ae71cf1dfe9", + "dist/2024-03-19/rust-std-beta-armv5te-unknown-linux-musleabi.tar.gz": "ba104dbdcc3c8689dadb75c6a85d83419e32fe78f43039f5294020da2ab3b73a", + "dist/2024-03-19/rust-std-beta-armv5te-unknown-linux-musleabi.tar.xz": "7bb849dae31f472febd722dc7dd324f073b2739dc57c40a6590b10f61c26133e", + "dist/2024-03-19/rust-std-beta-armv7-linux-androideabi.tar.gz": "c44211a45a1ecb9b5800fb7a3b7fa88de4562845888588012b34e282e26cb4f8", + "dist/2024-03-19/rust-std-beta-armv7-linux-androideabi.tar.xz": "3a92cdd368559d06d290af58fda93eac98e6d4bfd4e6ad03db0f91fe01789504", + "dist/2024-03-19/rust-std-beta-armv7-unknown-linux-gnueabi.tar.gz": "f00db0fd04a921cebe68a21d3c923e44f8a1828cdfffa201826d333feb0b9bd6", + "dist/2024-03-19/rust-std-beta-armv7-unknown-linux-gnueabi.tar.xz": "af5ec7e114c8558080b8891269cca098b530809085577485ea96435d5f664e4b", + "dist/2024-03-19/rust-std-beta-armv7-unknown-linux-gnueabihf.tar.gz": "5b2aa8f0c2a005a5c98dd08a6d4d231a11992356f857b706a19cefa66d62dc9a", + "dist/2024-03-19/rust-std-beta-armv7-unknown-linux-gnueabihf.tar.xz": "7ab1a7cda6ae70836df20a70283af166ad2d5413755485d818d8760f3bf69f6c", + "dist/2024-03-19/rust-std-beta-armv7-unknown-linux-musleabi.tar.gz": "9b970f2b3e0a01ecf56a9d32cdfbc47d76a2518838bc231d4488c2f4a9426fa7", + "dist/2024-03-19/rust-std-beta-armv7-unknown-linux-musleabi.tar.xz": "934272fbb78cd09728ef03557fad7e2b1b9302f88579dee8a5a1f58c8f4b15bd", + "dist/2024-03-19/rust-std-beta-armv7-unknown-linux-musleabihf.tar.gz": "f70a1adf38b2d22b1706af807023154b626f656efb8d91c8ed7235bfe0855edf", + "dist/2024-03-19/rust-std-beta-armv7-unknown-linux-musleabihf.tar.xz": "a665e05bb8dff2e8dd0479cb8a63460c73ee3e86ec7e1b6f48fece2985c85e52", + "dist/2024-03-19/rust-std-beta-armv7-unknown-linux-ohos.tar.gz": "e0ec71714bceee0df1bcdb85e094b58359d41f273dc9abab7ac05346fcd3f4b9", + "dist/2024-03-19/rust-std-beta-armv7-unknown-linux-ohos.tar.xz": "afbcd9b7ecc92f69801d77185af0139136ba6c352d14a6c8ed76de64a87645f5", + "dist/2024-03-19/rust-std-beta-armv7a-none-eabi.tar.gz": "a0e55f17c1bab81bf836c1e373f77d25c42fbd05f04b8b0e96f66f1f744481d2", + "dist/2024-03-19/rust-std-beta-armv7a-none-eabi.tar.xz": "f2dd0221e76d7b9f51e9efdee2e40c8d7539b1d5f52257f89431f29931394510", + "dist/2024-03-19/rust-std-beta-armv7r-none-eabi.tar.gz": "e97324f421bb354bc841a20e8b1c0357e633595bec4fca510f06e56fb89b2a6a", + "dist/2024-03-19/rust-std-beta-armv7r-none-eabi.tar.xz": "1ce1ca60b9536ede90452621ba91539b8ca6b6bdf7cbda3bd6d0b04a28c09580", + "dist/2024-03-19/rust-std-beta-armv7r-none-eabihf.tar.gz": "9bffa04e8cd3f67d8892f851b269f9cd91f6c9e5f2c87c641e9f6ef24bf7b644", + "dist/2024-03-19/rust-std-beta-armv7r-none-eabihf.tar.xz": "2a3cd2ab92cc37698057629167a553d0654f7882bfc1eb46687e1014b4b8e379", + "dist/2024-03-19/rust-std-beta-i586-pc-windows-msvc.tar.gz": "284f13947d990587090beb32262e4a83089c56ce2c3a1ffb89ed0fc5f4661eb3", + "dist/2024-03-19/rust-std-beta-i586-pc-windows-msvc.tar.xz": "22e641bdd54b3a7030c2eda0ff20a5517607fb6e60ea6d3195a2cd3afb0e984a", + "dist/2024-03-19/rust-std-beta-i586-unknown-linux-gnu.tar.gz": "adaaf6d3a291640ddaa3d522d8331cb27ea899999681d57713b57c879b55de96", + "dist/2024-03-19/rust-std-beta-i586-unknown-linux-gnu.tar.xz": "ebe80c2420c0eedd219cd539b87de75ffc0ed3b1656284cb81e2b2e8a927c738", + "dist/2024-03-19/rust-std-beta-i586-unknown-linux-musl.tar.gz": "c2e4691bf6956f97a214ef80f015a77ec4ece4ee32e9bc73300fe1c0267dcabe", + "dist/2024-03-19/rust-std-beta-i586-unknown-linux-musl.tar.xz": "e67059e579532ceb06a46702cc561acbeb3ba6258eda47418da587ec45759e26", + "dist/2024-03-19/rust-std-beta-i686-linux-android.tar.gz": "f112053adbcce7710383afe1681bd0096444a516f78f576e29f2f3c76468e7f0", + "dist/2024-03-19/rust-std-beta-i686-linux-android.tar.xz": "e63ae04fc20519fb5a56c2bae49f767807cb1ae1c01cab34dee1d129b34c4dee", + "dist/2024-03-19/rust-std-beta-i686-pc-windows-gnu.tar.gz": "14b36d2952ebaa84bf24645cd5d3464ae2b9df4d3ffee4bd48fedb07a4fdb09d", + "dist/2024-03-19/rust-std-beta-i686-pc-windows-gnu.tar.xz": "fef8c1bd4e1ceab680e1856b35f4ed426d07c224fa60c92d12efe0dfe700abc9", + "dist/2024-03-19/rust-std-beta-i686-pc-windows-msvc.tar.gz": "b42794fb8feda98c99d36dd978373afbfab56fd374fe42318107c453ab4d0fb7", + "dist/2024-03-19/rust-std-beta-i686-pc-windows-msvc.tar.xz": "855ed5996d9d8e4bc2424ce5ea6da6155b23357d700f1fc07d69d0bd12672a8f", + "dist/2024-03-19/rust-std-beta-i686-unknown-freebsd.tar.gz": "0ac04b35b62c7d8fe42ee29854b6a40b7dcf0d3deb174031a7620d2c87a8b206", + "dist/2024-03-19/rust-std-beta-i686-unknown-freebsd.tar.xz": "0287daaa3042c644d3190c6262b60b580a0cdfd80c64c299a36e0636d38e5674", + "dist/2024-03-19/rust-std-beta-i686-unknown-linux-gnu.tar.gz": "647dd5ba2f4d842d6bd6377e99b67b3d65d3ee47ea800ace9d172e9d24f63eb0", + "dist/2024-03-19/rust-std-beta-i686-unknown-linux-gnu.tar.xz": "d705b0cce3492e863c5d8fb28b4f2bedce68637fd7093d24a9e86ff6d2d0ca56", + "dist/2024-03-19/rust-std-beta-i686-unknown-linux-musl.tar.gz": "561ca95399cbd2f6692e5194ab550e9e0f0f5016aa2802522131c1361d3ef467", + "dist/2024-03-19/rust-std-beta-i686-unknown-linux-musl.tar.xz": "d4751c26585e512211157e162f0d1504a1854249dd6eff7262a55b09834d29fd", + "dist/2024-03-19/rust-std-beta-i686-unknown-uefi.tar.gz": "4e0a84f3dbc742d589d35cd58980157072f17090472c31ed0e306dad049a75ec", + "dist/2024-03-19/rust-std-beta-i686-unknown-uefi.tar.xz": "e11820072ae90861c96b0c1c931d691a157cccbf5d44685e3d5ff9b075aa7500", + "dist/2024-03-19/rust-std-beta-loongarch64-unknown-linux-gnu.tar.gz": "4357b6646ed0f379d9d74358457db1a18289967a880567b9bbff480e72f13711", + "dist/2024-03-19/rust-std-beta-loongarch64-unknown-linux-gnu.tar.xz": "3ffb178cb4c24b3b6df4aacbfaa4280eb6e781cd471fe52ed0b9be8fa555617b", + "dist/2024-03-19/rust-std-beta-loongarch64-unknown-none-softfloat.tar.gz": "bc32e2189cfb3efd8365bcd31fad504cab0fdf62c9fe04a6a0389ff23486cc2b", + "dist/2024-03-19/rust-std-beta-loongarch64-unknown-none-softfloat.tar.xz": "0d2894fe5fa5360cb31e5267e980faddd8d9f7adc415747991381aae535210eb", + "dist/2024-03-19/rust-std-beta-loongarch64-unknown-none.tar.gz": "16c134291f43694fb92d3efd92abc9c957d3ffa8ba8dee0c792d77f3b4d2cdd7", + "dist/2024-03-19/rust-std-beta-loongarch64-unknown-none.tar.xz": "ca06f72e2bd7309831464152cc7532a27406c18e2d6cd02918109aa65896be1e", + "dist/2024-03-19/rust-std-beta-nvptx64-nvidia-cuda.tar.gz": "a2d4f9671514673abc87ade8237508bd41df1bb6b75b0ea92bb27dd7ab75303e", + "dist/2024-03-19/rust-std-beta-nvptx64-nvidia-cuda.tar.xz": "69a8f2751d0a86878b92bb052ca0d3394f5bc0545fd3f2c1ce7e03e1ecc6d0b5", + "dist/2024-03-19/rust-std-beta-powerpc-unknown-linux-gnu.tar.gz": "95c4f0f944b4b8ad08c4d0350a09be233796991b8790fc0d48dbae895953d73d", + "dist/2024-03-19/rust-std-beta-powerpc-unknown-linux-gnu.tar.xz": "8ae7b77e0c7be184f4f279365eb2d9b7e9182ec9ea10f987814d4f4b50937f95", + "dist/2024-03-19/rust-std-beta-powerpc64-unknown-linux-gnu.tar.gz": "4f886546746f227bff157959a9982529895d52737b6137bf44545e82fe522672", + "dist/2024-03-19/rust-std-beta-powerpc64-unknown-linux-gnu.tar.xz": "b9fd4eda7aa2d5eb70e47405ba5fac8d5d3d15d1de76bb5d2f9d0ba8da4a2115", + "dist/2024-03-19/rust-std-beta-powerpc64le-unknown-linux-gnu.tar.gz": "8e81b39b1d7cbc180fe9540e9420f68216aa9b3bd46d6cc6f758f473d8d54ae7", + "dist/2024-03-19/rust-std-beta-powerpc64le-unknown-linux-gnu.tar.xz": "29d4e64b6e2a326bb695e42354e4f8a21382c63cd8a93fae64a44f3398de0a96", + "dist/2024-03-19/rust-std-beta-riscv32i-unknown-none-elf.tar.gz": "66eb8d049d50532512d442efef67993fa3da0fc0a585e549559d2e843c7e3c89", + "dist/2024-03-19/rust-std-beta-riscv32i-unknown-none-elf.tar.xz": "1919690c47b603ff6ddcf6d8f16573cc3acd960d27dfb97358dd9c92a907c766", + "dist/2024-03-19/rust-std-beta-riscv32imac-unknown-none-elf.tar.gz": "e66c025f225b3cfc3399992b0dc3e5f6829ef03b6527656376a0575c970dd43a", + "dist/2024-03-19/rust-std-beta-riscv32imac-unknown-none-elf.tar.xz": "75373475011adc1d3340dcf222e594be505116fa4c1099b493a6eb1018dc5f92", + "dist/2024-03-19/rust-std-beta-riscv32imafc-unknown-none-elf.tar.gz": "2dc076319958052445c0de0d34567162745d9a6de18edff2edbf6afa05feb124", + "dist/2024-03-19/rust-std-beta-riscv32imafc-unknown-none-elf.tar.xz": "f1225e56a378ac5b8790e9299815987c618f5d712a11e2a039580965679119a1", + "dist/2024-03-19/rust-std-beta-riscv32imc-unknown-none-elf.tar.gz": "26bb1e505811310fecd47e7aa5b75cbbaf6794ce209df200ac554ff84a353392", + "dist/2024-03-19/rust-std-beta-riscv32imc-unknown-none-elf.tar.xz": "35b4799e26da0d6220c0372bce45e6b3b18a4035b82a36505c052e0990cba754", + "dist/2024-03-19/rust-std-beta-riscv64gc-unknown-linux-gnu.tar.gz": "5a79d8992906ab3db7be9716de2c6434e1c8d81c1ebf725a1b413af13f9c9091", + "dist/2024-03-19/rust-std-beta-riscv64gc-unknown-linux-gnu.tar.xz": "7d63304af691b1ade5f9d6e50bf82eb9958f8b3da977fbf894f3c5dab15d0ff5", + "dist/2024-03-19/rust-std-beta-riscv64gc-unknown-none-elf.tar.gz": "1a93efe919bcb44cae9fea48aa22a1591f041041e7c59e64461ddc3298ec954b", + "dist/2024-03-19/rust-std-beta-riscv64gc-unknown-none-elf.tar.xz": "0e17193cec07704e02fec9f4393a457f0f57082c86d4833f687a72be0a439008", + "dist/2024-03-19/rust-std-beta-riscv64imac-unknown-none-elf.tar.gz": "3ccd73bfa0926858f95f1535f1297d6adf8be62afe0a94581d267782b4e8803c", + "dist/2024-03-19/rust-std-beta-riscv64imac-unknown-none-elf.tar.xz": "e7b4ef2f7a7d9bee1b0dd6a12aec4d52150db2fed29af2668ef5a65b727f6ce8", + "dist/2024-03-19/rust-std-beta-s390x-unknown-linux-gnu.tar.gz": "3e755b9a8fc8b66da6795ef57d9d80ed239e10adb17c23a8a64ba96f0d0b6296", + "dist/2024-03-19/rust-std-beta-s390x-unknown-linux-gnu.tar.xz": "936807926232e6fdbd2e93a646460ca9d8850367afd82bb56d21245936f73b17", + "dist/2024-03-19/rust-std-beta-sparc64-unknown-linux-gnu.tar.gz": "168c1fb8b6f633abb699c905eaf4e970ea94c789746d7cc3a7984ffb046df446", + "dist/2024-03-19/rust-std-beta-sparc64-unknown-linux-gnu.tar.xz": "d64b6a01542d504fe2d4ccdba0e7574e5521841a0a4fffc3d66e78086e0343a3", + "dist/2024-03-19/rust-std-beta-sparcv9-sun-solaris.tar.gz": "34992b0a74cedbaf58057f965858cf26ffdff8bece7b2b0e167c8a1d61b6651d", + "dist/2024-03-19/rust-std-beta-sparcv9-sun-solaris.tar.xz": "957c38d5485d96d62fe46c4dff5726233d7c402708c4dbb0337cd740ad759a10", + "dist/2024-03-19/rust-std-beta-thumbv6m-none-eabi.tar.gz": "7eab40ea23f0758c5ace93224e1268e2929fb7d165b7877ea2540cc2b45664ce", + "dist/2024-03-19/rust-std-beta-thumbv6m-none-eabi.tar.xz": "d0c428c5a1aae6e78842577a5e8f3e4b393d4d3ec9c240ed3c3a0a36d4c0b19a", + "dist/2024-03-19/rust-std-beta-thumbv7em-none-eabi.tar.gz": "450b39802145dc6ebcaad6fdf99b606fda18d3f272f18d0a5e21bffa930ec877", + "dist/2024-03-19/rust-std-beta-thumbv7em-none-eabi.tar.xz": "649532a1c17da2afbcf0fb9395305bb46a76846bbc8c4fd5c153a170b525d35d", + "dist/2024-03-19/rust-std-beta-thumbv7em-none-eabihf.tar.gz": "8068584665ce0468bd420d146cfb4643e745c4ee782b352bfc16c9e7f18ed25d", + "dist/2024-03-19/rust-std-beta-thumbv7em-none-eabihf.tar.xz": "04c1d047e2ec0347cac5ab5591ae0eda6f52c6f9281aaa4d2f4ffcd8c5af11c8", + "dist/2024-03-19/rust-std-beta-thumbv7m-none-eabi.tar.gz": "6e954aeddadbbaf088fc8d671e590eba87d4317f8716a7cca286c764131c0d73", + "dist/2024-03-19/rust-std-beta-thumbv7m-none-eabi.tar.xz": "15f8ea37798f20559f5c6c91c42acd4c883852e14228bbfe5b65865d998beba7", + "dist/2024-03-19/rust-std-beta-thumbv7neon-linux-androideabi.tar.gz": "1c7b6e92d8727602b8e41d44b66369ddf8e65937fb1a934b2115c18816cd66eb", + "dist/2024-03-19/rust-std-beta-thumbv7neon-linux-androideabi.tar.xz": "5679ddb9d7404a776861195ca708fc6132ce1e35fc5994946ba7a17ce61afa9c", + "dist/2024-03-19/rust-std-beta-thumbv7neon-unknown-linux-gnueabihf.tar.gz": "44280bcc42edb6ff3f2d91c8a3e7005703150e7be749480577df96100d516b1c", + "dist/2024-03-19/rust-std-beta-thumbv7neon-unknown-linux-gnueabihf.tar.xz": "abf86ce8dfd3bd5548cbc8c9c958eb75fbbff77cb7ae8a5e231e5ac9d46d3876", + "dist/2024-03-19/rust-std-beta-thumbv8m.base-none-eabi.tar.gz": "ca4fc4970411a503d11a30bbea94487a10dc5925cdf7b1dc3bea095c72e5d381", + "dist/2024-03-19/rust-std-beta-thumbv8m.base-none-eabi.tar.xz": "9752a30a7a2dbf64092cfb1901ef4e49e9521b794644710060eaf62c8acd1d5c", + "dist/2024-03-19/rust-std-beta-thumbv8m.main-none-eabi.tar.gz": "14d29c09f788bdc63550cb9cc0ecb8040b0e28e6e5a5bc65c06dca6a0fb34821", + "dist/2024-03-19/rust-std-beta-thumbv8m.main-none-eabi.tar.xz": "201eff5b741c735547226e9a4d22aed0e09f1c31a48673ce7fc094fb7fc95ba7", + "dist/2024-03-19/rust-std-beta-thumbv8m.main-none-eabihf.tar.gz": "1a641bcc8c904a0c5b4e7ff0d52d105a1ce45c24d10bb1cdc1dc284222851d6d", + "dist/2024-03-19/rust-std-beta-thumbv8m.main-none-eabihf.tar.xz": "48f8abb5d1dae87c22e4d24610be6a98d646150d7bddc1ca471a6a27976090e0", + "dist/2024-03-19/rust-std-beta-wasm32-unknown-emscripten.tar.gz": "102f692ecc5233a2e8063c305a0d37ffb9689fc1a4927dcd8f4fa14501a04a0b", + "dist/2024-03-19/rust-std-beta-wasm32-unknown-emscripten.tar.xz": "cd0407c881219b7586500c05b711ed78de9356d7c0db1065baab3833b5d2b738", + "dist/2024-03-19/rust-std-beta-wasm32-unknown-unknown.tar.gz": "3e588580f9298626c4bc3e4b0ad52495d97e4dfc61ca8778e97da3e67c624266", + "dist/2024-03-19/rust-std-beta-wasm32-unknown-unknown.tar.xz": "665dd07fe6ab4d2bcbdc7e88b674e90ff4ea8caff9251d572ff0a7edb32a509d", + "dist/2024-03-19/rust-std-beta-wasm32-wasi.tar.gz": "c0249f7a3e1f8275323adc2a49840cfc677ce8ac3365886753135703a9276572", + "dist/2024-03-19/rust-std-beta-wasm32-wasi.tar.xz": "aad18dde6feaf251af10398b9e7ba2e39828a4640a8f30cc66ee72cd2b1278b3", + "dist/2024-03-19/rust-std-beta-wasm32-wasip1-threads.tar.gz": "95f5700c74feeecea7705d90d3022637e4fa96ee5db165d8fc76d4db05101005", + "dist/2024-03-19/rust-std-beta-wasm32-wasip1-threads.tar.xz": "6787b24af02a7216a524104379517a158938bc2c940b56a60be2ac143d3de7f8", + "dist/2024-03-19/rust-std-beta-wasm32-wasip1.tar.gz": "38d2130daea2bd3c71a456e4dfc44ad900838d15a18af123bfe971f036b43951", + "dist/2024-03-19/rust-std-beta-wasm32-wasip1.tar.xz": "a766d6af0392e913f42930a02fbe5c7b481120ebceadf6b33c7c21ba6067c7f0", + "dist/2024-03-19/rust-std-beta-x86_64-apple-darwin.tar.gz": "3de58d464ee9cfd01d245016b752d1740f9b3feca7c84dddcfeeefd288a4966e", + "dist/2024-03-19/rust-std-beta-x86_64-apple-darwin.tar.xz": "8854dbc047727f11dcdc2f243536a5a6c5e7d8986c4ecea026820630aa2cce59", + "dist/2024-03-19/rust-std-beta-x86_64-apple-ios.tar.gz": "79477ea1afc524ed9d4f3ae57df132affe03a3fa7a14b17214181543918b2391", + "dist/2024-03-19/rust-std-beta-x86_64-apple-ios.tar.xz": "b830688a420e5631406b00d40756739d71a5f8f9789a4b6f4a601db167893814", + "dist/2024-03-19/rust-std-beta-x86_64-fortanix-unknown-sgx.tar.gz": "ceb9ac35511e08cbd14dcf6c4faed57107f0facd5ebe1b1634f2ce2b41781c27", + "dist/2024-03-19/rust-std-beta-x86_64-fortanix-unknown-sgx.tar.xz": "532b77cbb488b445e0291997a21d0a94c44970c5793ecca07eedca2dc4b02be7", + "dist/2024-03-19/rust-std-beta-x86_64-linux-android.tar.gz": "5333bf0c8ea592ed316e21bb2938ed07d247f0f873b45f34abcaa62f2e33f741", + "dist/2024-03-19/rust-std-beta-x86_64-linux-android.tar.xz": "ab18128d48a1eac2e8577e4268d95efe9619a4789cf4ee322d5bd651f33c24c1", + "dist/2024-03-19/rust-std-beta-x86_64-pc-solaris.tar.gz": "6976af5df3468680d83f54e87f57b94ac121ee82d7887e3e21200434b993a219", + "dist/2024-03-19/rust-std-beta-x86_64-pc-solaris.tar.xz": "932ffbff886919acb32f77ab70560a0262bbf5ee83a78679598ec13fcad39e3b", + "dist/2024-03-19/rust-std-beta-x86_64-pc-windows-gnu.tar.gz": "0429be318b55a9c36bc2fdb0b9654a3cf39527cb05d75f46890f6fcc2ed003a3", + "dist/2024-03-19/rust-std-beta-x86_64-pc-windows-gnu.tar.xz": "7e3f64dc9b5b6653e6adbc58499857c0df8f1765d8fb777f6cb2ada3f40543d4", + "dist/2024-03-19/rust-std-beta-x86_64-pc-windows-msvc.tar.gz": "07a7bb2d07bb72693e0bf0ddc365394dde55063ad572259a5d171e08cda592f2", + "dist/2024-03-19/rust-std-beta-x86_64-pc-windows-msvc.tar.xz": "efc20d952b248815bda4ab3950b2998b5326e2c5008e72ede921eacb79b3b504", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-freebsd.tar.gz": "04a46c5cbfe620dc5d3d05134e0501aa466c081f848df679c554d51ecc6e8bb6", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-freebsd.tar.xz": "9ed41c7d0c09409fbecf33eab630ec847a4af7ea5bcaf42d8e14e1074ed30bf4", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-fuchsia.tar.gz": "de0c88a91d325087e5c28e9ca5d3092443c875b55ed08b8486e8fd1c01c7b7e8", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-fuchsia.tar.xz": "e403921f889381097628bcb2c431e3b8a8c0773c0d5062d4d1a9ec8e7f88fa45", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-illumos.tar.gz": "ee045b5102673d085fbeead4d5b9daeb9497f90d341bd51c8ac85b666e9c9821", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-illumos.tar.xz": "bd24fda28c9b69cc68c90b910a75cd652ad3b4d4430f802d8a2354c2cd5d19e7", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-linux-gnu.tar.gz": "8c70c2d12202054329cf6fca88adf20d9d9f493cb057c30211454a49f96ad4e5", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-linux-gnu.tar.xz": "ea6673ea519a6eba60836b810c0531cac858ca74d0d756538a45a375ffb7db9f", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-linux-gnux32.tar.gz": "52e104ce39ac5e8e44fbb332bc08f7ac3d564408f48a459f79ba2149caf47b32", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-linux-gnux32.tar.xz": "fa098772e186acba6e85ea2f4d0270f01e00cbdd27eec1e92cbda808b7807284", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-linux-musl.tar.gz": "d6785e6574b4a7ba61f66c1e7938a46a02f9430983a7aee1c3400eb5f8b57f0f", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-linux-musl.tar.xz": "17c3e8254fbfed0f0a9b3209976e44a136d0f581d0713ddf7114753cfd0b983d", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-linux-ohos.tar.gz": "407f9c2d5d3bd76698af04711d9a06b7aa86d4c55cee9d8ed1ce3aa37055068e", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-linux-ohos.tar.xz": "5e0869bf268c9824c284e841b2bf5a13a6dc1bd2e55ce3b7b09788ba5608c9dc", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-netbsd.tar.gz": "9b5aa240c2a696af0d342ec26a6b6ea4f5888070e8b590122379302910a978f8", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-netbsd.tar.xz": "064c1925a8ac82d1474c240c6c9414b422a7b04211a49a7660625193a0c21c64", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-none.tar.gz": "8e48a645b2b8dda6deb5b706e415697d303830775032b69521265acfc9f8608e", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-none.tar.xz": "a3d28304c75a71680d7d40aca43bf638bb4def5ec10f873aca5261692b114743", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-redox.tar.gz": "e645a81d4884f09c9d7da242ae448cadaf7a9232475707ece014a57d02a23527", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-redox.tar.xz": "0cf089464b1949a4f24092e2782b306e9530489cc415df69ae433c23a438518e", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-uefi.tar.gz": "ba7eec56d4e8a5f8a6c206b6a12fcae77da9a24ffea824c1db128dcd4a7d9fbe", + "dist/2024-03-19/rust-std-beta-x86_64-unknown-uefi.tar.xz": "76aa9bf6ed668667d1d47feb2fb8e941f5446f2ce5b4e94aacf34f964ebb3171", + "dist/2024-03-19/rustc-beta-aarch64-apple-darwin.tar.gz": "e40614daaa2b0270d5f3153c8216f68419b96dd167632dc67c1fd641ac0a21ff", + "dist/2024-03-19/rustc-beta-aarch64-apple-darwin.tar.xz": "7c2106ea1a3d358e2893a62fcc2162e041ecbdd9143f2dabbe0fa7a6b5827aaa", + "dist/2024-03-19/rustc-beta-aarch64-pc-windows-msvc.tar.gz": "7eb0678bc1b4dfcf366641dbb02390262e47ecade1db9007ae1d5bbc39b6c7c6", + "dist/2024-03-19/rustc-beta-aarch64-pc-windows-msvc.tar.xz": "0caef4825f0a6e51fd05c5c32365fb3a80a2b7692de71ff0af10ce9aea1ecafe", + "dist/2024-03-19/rustc-beta-aarch64-unknown-linux-gnu.tar.gz": "bbf59310c1e60725aebed09a09f0df4b1c21c2d0744f34734472e46cd7248fee", + "dist/2024-03-19/rustc-beta-aarch64-unknown-linux-gnu.tar.xz": "a7687c89bf94d64119ee76029ed12d27d594d7716fbf542852333185385a5b44", + "dist/2024-03-19/rustc-beta-aarch64-unknown-linux-musl.tar.gz": "d2bda016eaf8b988e3b5899ab1239c582ef9119c40267b79be2efa453ceb9ee1", + "dist/2024-03-19/rustc-beta-aarch64-unknown-linux-musl.tar.xz": "940f0611384175521401f352f4fc18a587b3816f99c88a0e130b895918c340a9", + "dist/2024-03-19/rustc-beta-arm-unknown-linux-gnueabi.tar.gz": "3ef861f5980f899b6575e50844c14ad30fe739f80538118acc8e29fd8b00cbed", + "dist/2024-03-19/rustc-beta-arm-unknown-linux-gnueabi.tar.xz": "191a2bb6966e05d1db83acafeb3caf0e0421eec539e221837e3dcff5e9db4152", + "dist/2024-03-19/rustc-beta-arm-unknown-linux-gnueabihf.tar.gz": "9999f60a513864257a14ee58ac3b87d9e557e0c2fe720a5d4ba31d250debc378", + "dist/2024-03-19/rustc-beta-arm-unknown-linux-gnueabihf.tar.xz": "7c824f67a45aaeb7cf4c7519aa72ce8a81013cf2edec2fb5600f68aaf6eaf84e", + "dist/2024-03-19/rustc-beta-armv7-unknown-linux-gnueabihf.tar.gz": "83fa3927f92945845c6cc5a6f123ce5301a24af81c9371e5c6bcc8964a182688", + "dist/2024-03-19/rustc-beta-armv7-unknown-linux-gnueabihf.tar.xz": "3469f087248e671351dc0bdda06c1a9b8d12fc64854148cc9404d419db8fdb02", + "dist/2024-03-19/rustc-beta-i686-pc-windows-gnu.tar.gz": "a219c9829d7e33a822947faeb3f8826d7f2f5c46aeaa9c338bc27bf7b1561395", + "dist/2024-03-19/rustc-beta-i686-pc-windows-gnu.tar.xz": "ee5f30b90bc43738eb9c9a3678a09768bcffd3bed413c50ec23fa14fea1157ac", + "dist/2024-03-19/rustc-beta-i686-pc-windows-msvc.tar.gz": "acdc6345b76ed52b5b58d2832ae61c904aa6d74955f2e31432ab363f217397ec", + "dist/2024-03-19/rustc-beta-i686-pc-windows-msvc.tar.xz": "13161baa6a6e0771fcfb65b0e26f77a1ce07c5dcdb029a624723231d5d3c1012", + "dist/2024-03-19/rustc-beta-i686-unknown-linux-gnu.tar.gz": "7188f7c598cd4f1579ca06819cac5461679513ff648f03b7f28e15fd5636467e", + "dist/2024-03-19/rustc-beta-i686-unknown-linux-gnu.tar.xz": "42e03380ac0070f1cbf47c674c1d529cb065960f5e8c0f92e24a5f994dfeca83", + "dist/2024-03-19/rustc-beta-loongarch64-unknown-linux-gnu.tar.gz": "67a57b0a8a057a1d39b99e5232145d7c5a48b9e3ff0e97b9ad1f4cbda004587b", + "dist/2024-03-19/rustc-beta-loongarch64-unknown-linux-gnu.tar.xz": "1c85e17bd524294ac64c2defce82eae336cc3c5d9795dab68e0d7419ede35a6a", + "dist/2024-03-19/rustc-beta-powerpc-unknown-linux-gnu.tar.gz": "1c243f95e823164a4b112fef4a70bd3cb0f368dfbff7efd106b7ec3a718f49dc", + "dist/2024-03-19/rustc-beta-powerpc-unknown-linux-gnu.tar.xz": "318d69391381a142b72a27c6e53be624691e465ffec2497676c2454bdc06f856", + "dist/2024-03-19/rustc-beta-powerpc64-unknown-linux-gnu.tar.gz": "f8423ac9a207c9a43746b9299dab7ff55a747aba1980313f98b5aef67e489d66", + "dist/2024-03-19/rustc-beta-powerpc64-unknown-linux-gnu.tar.xz": "f6e3552a9ad8a90dc0830f7c8beaaf10c90e4760bcb48904d4197c53a54a8b1e", + "dist/2024-03-19/rustc-beta-powerpc64le-unknown-linux-gnu.tar.gz": "3ab2d798cf0812b874198691993686e9c884d24806628242110dacfa5bc3446a", + "dist/2024-03-19/rustc-beta-powerpc64le-unknown-linux-gnu.tar.xz": "6cae9a4e5e88054800f11f028b92211173de4038ad1bb0a871cdd05bc6a0b8c1", + "dist/2024-03-19/rustc-beta-riscv64gc-unknown-linux-gnu.tar.gz": "368351e98c1e71b3fe40c687f478d52a43ba388811521e7807b314d750cb4f65", + "dist/2024-03-19/rustc-beta-riscv64gc-unknown-linux-gnu.tar.xz": "116171252c2f153066e9f8fa6eb1e63962aebdd67d14368560200c984ae38ccf", + "dist/2024-03-19/rustc-beta-s390x-unknown-linux-gnu.tar.gz": "0445ba1954a7e6bbaf64561a33c01988a4f48aa8401669acd7c5e8ac11d27696", + "dist/2024-03-19/rustc-beta-s390x-unknown-linux-gnu.tar.xz": "23aeed13a2c0143d14ab9fb26be47314318ee3014190ba08f5889bed14205799", + "dist/2024-03-19/rustc-beta-x86_64-apple-darwin.tar.gz": "91a1040d4b0d309fadae1b180c5cdf30c9c073245599064a075849795a8c84d6", + "dist/2024-03-19/rustc-beta-x86_64-apple-darwin.tar.xz": "996bb8bf522509e5ddf5e2d4fdfe0c19d4198605107575faba4a80e1f4de616c", + "dist/2024-03-19/rustc-beta-x86_64-pc-windows-gnu.tar.gz": "82024a5d02148c7a0a0309105114f54dcdc6b9bb763d1e0456f0c18f96b16f57", + "dist/2024-03-19/rustc-beta-x86_64-pc-windows-gnu.tar.xz": "b6c00535af0ef5815cfaf88bcf21b83935539785345b22abeb9d4fa97e2cc445", + "dist/2024-03-19/rustc-beta-x86_64-pc-windows-msvc.tar.gz": "409a22e9a1ae89640059cb33d614abe84eef4096817b0fa750b3a38e0a153061", + "dist/2024-03-19/rustc-beta-x86_64-pc-windows-msvc.tar.xz": "8fcc030bcbafdcfbd894653ce935ecb82fc04b3717718d34dd6b2a4e8d553889", + "dist/2024-03-19/rustc-beta-x86_64-unknown-freebsd.tar.gz": "79d39890188af98e9eaa1b5a15606517ad7e0b3c493bad09a59c5400bfff3d9d", + "dist/2024-03-19/rustc-beta-x86_64-unknown-freebsd.tar.xz": "b69b370559cdf73f26b83a4b5276d10988f44d39d57608c44defa6b79f92121d", + "dist/2024-03-19/rustc-beta-x86_64-unknown-illumos.tar.gz": "f4bc2b510a230a09bae4b243f1297863907c9239a94bdf739f43c31a76238a04", + "dist/2024-03-19/rustc-beta-x86_64-unknown-illumos.tar.xz": "131b02eab07b50d8a99e0185090afd6c3fd1bd20b98fc0a4830910fea5b12ec5", + "dist/2024-03-19/rustc-beta-x86_64-unknown-linux-gnu.tar.gz": "ed9d98b20a4868330c88563ec367078a4c5ed7bca497680ea690cb9da2d6ddbc", + "dist/2024-03-19/rustc-beta-x86_64-unknown-linux-gnu.tar.xz": "b6c0fec4e295b8eec2b7c8bbddec48aaba1d3c4d73803eaf887554d368b4efa5", + "dist/2024-03-19/rustc-beta-x86_64-unknown-linux-musl.tar.gz": "e972c5ec3f9cc2661845bbb2e7153b9e90e59af2d4fcd74c588e3f326bbe9e6c", + "dist/2024-03-19/rustc-beta-x86_64-unknown-linux-musl.tar.xz": "d576799dcd59b48ddb6d96545ec48ef517b5a7d9875033de6583387fc1d4b79a", + "dist/2024-03-19/rustc-beta-x86_64-unknown-netbsd.tar.gz": "39f5a43f70692f1bcfc6b82ef901fa86be82aa7db0f6161ea5025577976a0780", + "dist/2024-03-19/rustc-beta-x86_64-unknown-netbsd.tar.xz": "596e6681bb15420754ab1a7210157884f5e31b34a885b1d1cfcb8838ba5c28b3", + "dist/2024-03-19/rustc-nightly-aarch64-apple-darwin.tar.gz": "f91204bc62d9236adc75e2a7ba4ae41e0d9ea9c6b6bcaf0d211459cfc7d17d21", + "dist/2024-03-19/rustc-nightly-aarch64-apple-darwin.tar.xz": "7562f89f9bc9f2968ddcef0258cd5a1435855d87a1c40b9ead6b82c1cb5c58c3", + "dist/2024-03-19/rustc-nightly-aarch64-pc-windows-msvc.tar.gz": "2f1ab532837469eba7dca3cb4b45ce983384e30917b0af3108d2a8c7c88f38c5", + "dist/2024-03-19/rustc-nightly-aarch64-pc-windows-msvc.tar.xz": "fa69006e8189b1e624e0d9a9a212c15423fc1b428785f651a309eae045199f11", + "dist/2024-03-19/rustc-nightly-aarch64-unknown-linux-gnu.tar.gz": "21905a47c616e3e43b05135621c17db635dfa897e2e64b124c03b042f74dff00", + "dist/2024-03-19/rustc-nightly-aarch64-unknown-linux-gnu.tar.xz": "1efea63747a88b3baefe6602e047e84323867a3eeb77093b9e662ff254a85f28", + "dist/2024-03-19/rustc-nightly-aarch64-unknown-linux-musl.tar.gz": "1b693de287b60428bc1a0a23088c08680db2d0fbf4f7cf0d6e3f413cd9cfb150", + "dist/2024-03-19/rustc-nightly-aarch64-unknown-linux-musl.tar.xz": "7803e124610ad092f88b7cf4b65cd3fa1a80cb2cf5a36fe4391535ca4f3d9369", + "dist/2024-03-19/rustc-nightly-arm-unknown-linux-gnueabi.tar.gz": "744bef406b6df5c610b605234375d8520abe24d8407b8bd22a0fe15de41d62b6", + "dist/2024-03-19/rustc-nightly-arm-unknown-linux-gnueabi.tar.xz": "b90dc87a68c134e6fcdaa3ea20e9d0fc33b0422e4dc989c1cf0c85c8140fdfce", + "dist/2024-03-19/rustc-nightly-arm-unknown-linux-gnueabihf.tar.gz": "e235fd3258b7d1e42ff6609f1660a94aaafc00875c371543ad2b12ae226dd8c7", + "dist/2024-03-19/rustc-nightly-arm-unknown-linux-gnueabihf.tar.xz": "b37ea15820c88ae1ab534277f8f7a7ad18b3d365f1d2d499a887665b715c6c21", + "dist/2024-03-19/rustc-nightly-armv7-unknown-linux-gnueabihf.tar.gz": "bf7cb8f0b21f2b0b8b067f88e31a2ce9e5754044b68437d4d52324fd95010161", + "dist/2024-03-19/rustc-nightly-armv7-unknown-linux-gnueabihf.tar.xz": "3595940730b4cbcb00e0441458b07253677d148f4850b464d6df7706c203d1aa", + "dist/2024-03-19/rustc-nightly-i686-pc-windows-gnu.tar.gz": "3135f03a8388c13c6439ef0464e2086949a528cee7bebdfb955defd59e55952d", + "dist/2024-03-19/rustc-nightly-i686-pc-windows-gnu.tar.xz": "54b6ca29f64e454189f27135f9a40f0bc0d0b5abf4d2912aeb857f733721005e", + "dist/2024-03-19/rustc-nightly-i686-pc-windows-msvc.tar.gz": "d3b70b07c8c9cedd30dbebfff2bfe45316752a13d49c9feedfdae4f71bb74865", + "dist/2024-03-19/rustc-nightly-i686-pc-windows-msvc.tar.xz": "653a821d9a7789e19fdd32f82466e906c23e03e42752f7277c05b692c1459e20", + "dist/2024-03-19/rustc-nightly-i686-unknown-linux-gnu.tar.gz": "4a37e87a3280997bb09deb6a3617395b1e898ecd07f0bd5469cb21e55c3c5f81", + "dist/2024-03-19/rustc-nightly-i686-unknown-linux-gnu.tar.xz": "a66bd9287cc958a61f9989d5efb6162255f7eb9211af9a4ea98769971350384b", + "dist/2024-03-19/rustc-nightly-loongarch64-unknown-linux-gnu.tar.gz": "3ce931c54c96c72034392efcbcd73061d6f8a7c7f40f1e86c14ae6fd5248d2a6", + "dist/2024-03-19/rustc-nightly-loongarch64-unknown-linux-gnu.tar.xz": "cab19b60b91cd6549f89398f46b31fe440323c9669606f48a4029e8d3cdc1ee5", + "dist/2024-03-19/rustc-nightly-powerpc-unknown-linux-gnu.tar.gz": "3d50b95e8f9ce5a2721e1ba0649378e8426fc4ba531bfa13bd9b96ef627aa46d", + "dist/2024-03-19/rustc-nightly-powerpc-unknown-linux-gnu.tar.xz": "9286d55547a438008574267cc3a067ca50005a9397bf8aeccd76ea27233de2fe", + "dist/2024-03-19/rustc-nightly-powerpc64-unknown-linux-gnu.tar.gz": "61843b55a45909408b3005cee338de42d31aef852155c8bcd8f6cf9aa3077dfa", + "dist/2024-03-19/rustc-nightly-powerpc64-unknown-linux-gnu.tar.xz": "2de14af7b540c3302e6b1a0f77472362429c0a1a0026c2fc799b263817e3c942", + "dist/2024-03-19/rustc-nightly-powerpc64le-unknown-linux-gnu.tar.gz": "816575061e2879d6855fa497b3bbced57f3201d64c6649c89ba9020c69889fd6", + "dist/2024-03-19/rustc-nightly-powerpc64le-unknown-linux-gnu.tar.xz": "58962496e51cdc60f9a98fb2fdbbb2f4124beb3fdbb065cc6b52871eb4bdc2f9", + "dist/2024-03-19/rustc-nightly-riscv64gc-unknown-linux-gnu.tar.gz": "cd649970e9b8a98e9dd0c1f506624832cb08516aa9cfd001381ad265cc42ee66", + "dist/2024-03-19/rustc-nightly-riscv64gc-unknown-linux-gnu.tar.xz": "1a9a2bcdd263a205bd85c8fbb9733711ceeee372953a7573420fcb55d59d59b0", + "dist/2024-03-19/rustc-nightly-s390x-unknown-linux-gnu.tar.gz": "98d6631c6dbca97491d5f518dceddc07c53aa309c7db8da0a919eed96f9e45bd", + "dist/2024-03-19/rustc-nightly-s390x-unknown-linux-gnu.tar.xz": "ee1fcc2a1d3181c2a7b97df8525363159c47b1348c0db78f74c7181ad6c44166", + "dist/2024-03-19/rustc-nightly-x86_64-apple-darwin.tar.gz": "c2768511ca6e9c228e13815040eb56f43ba1ec223c7753ea0e613400989a20d9", + "dist/2024-03-19/rustc-nightly-x86_64-apple-darwin.tar.xz": "6c10e9e824d1bc7a3c75172375e3490e33627bcaef6315552147b89b81ecf328", + "dist/2024-03-19/rustc-nightly-x86_64-pc-windows-gnu.tar.gz": "6d3a1f7c97fd4115b524f990426b795be1b9ca9a10fc6fd68db1cf4355d3953b", + "dist/2024-03-19/rustc-nightly-x86_64-pc-windows-gnu.tar.xz": "86fbb08c51664be63b234b82894b1b8012d8f6bbbbd96b6fc7188c22b887049e", + "dist/2024-03-19/rustc-nightly-x86_64-pc-windows-msvc.tar.gz": "39b673d694aee6c5d25ba88ba7e9f38b6264f01ed6a5785ea44e07594b9a7d1a", + "dist/2024-03-19/rustc-nightly-x86_64-pc-windows-msvc.tar.xz": "43ebc08539300d736d1d41af2306b1bbcb0d9e04795033725807d4c9c06d590a", + "dist/2024-03-19/rustc-nightly-x86_64-unknown-freebsd.tar.gz": "cd263eb4b6e027b834723f3748139db6f1742f885c2cfa2a4842c23c806b48fc", + "dist/2024-03-19/rustc-nightly-x86_64-unknown-freebsd.tar.xz": "22fc109ec6293b799fd52398b72f90966b9efb95c433f826e31f54fe643132cb", + "dist/2024-03-19/rustc-nightly-x86_64-unknown-illumos.tar.gz": "20b01c262d54731c471d6dd856fbe8c9a58674f88d0dea19c7e9b7adff6b5474", + "dist/2024-03-19/rustc-nightly-x86_64-unknown-illumos.tar.xz": "584d1e3b9e6e2006767a6a1a46aacff34a2042b4094e51be0a1a82a50a4ab27e", + "dist/2024-03-19/rustc-nightly-x86_64-unknown-linux-gnu.tar.gz": "71b98f184c4b3f3a40c5ab7cf6bdae6947a39c2a7e36e590750a37806cd98a2f", + "dist/2024-03-19/rustc-nightly-x86_64-unknown-linux-gnu.tar.xz": "44510c19128801a465c70fbb4d1fa0250edd7c1ff0a67f1c374f1d921e1a4bb8", + "dist/2024-03-19/rustc-nightly-x86_64-unknown-linux-musl.tar.gz": "897728aae12523d33bad792c4275512383ae5cff008860406882ebeb273cca5a", + "dist/2024-03-19/rustc-nightly-x86_64-unknown-linux-musl.tar.xz": "b027abf370ef289d6b2e615dcafac3eda20c147dd2ac4a3c113e8689f6936655", + "dist/2024-03-19/rustc-nightly-x86_64-unknown-netbsd.tar.gz": "97360bb700ee986b0a36ac4ed4f0fbcf3c875907bb6cfdbe4bfa0274893109f5", + "dist/2024-03-19/rustc-nightly-x86_64-unknown-netbsd.tar.xz": "e8414dc178f2d1939b2d6411beda7bc6f8e9b7f500ccb30fc8a8659ddc0f945f", + "dist/2024-03-19/rustfmt-nightly-aarch64-apple-darwin.tar.gz": "8515050a52addca9d5c0ea8b9f4e5c536d32ed275fd0922cbe567fbf7d5adcb6", + "dist/2024-03-19/rustfmt-nightly-aarch64-apple-darwin.tar.xz": "97c68112bd8f4cd67eef50c994dd13967482ac1e55170dfd11d8505c582c689d", + "dist/2024-03-19/rustfmt-nightly-aarch64-pc-windows-msvc.tar.gz": "b3ff60427dfa13e3c9d4965e0f197ac2a0625fe64cb1e23ec46604adbafdc847", + "dist/2024-03-19/rustfmt-nightly-aarch64-pc-windows-msvc.tar.xz": "848938bd1436276ba813104cde9d969cbcd79d295eb045ced1d82080cdbae29f", + "dist/2024-03-19/rustfmt-nightly-aarch64-unknown-linux-gnu.tar.gz": "063f25121c6a8055228763240f178b7f1e9b55f20b305b8e2ebc1b0a080e432d", + "dist/2024-03-19/rustfmt-nightly-aarch64-unknown-linux-gnu.tar.xz": "89ab3a28357f3926fa4880010d0ec6b6fce06476050f42c71416c60528490f7b", + "dist/2024-03-19/rustfmt-nightly-aarch64-unknown-linux-musl.tar.gz": "6ece90be16f59b3a5871d8cee8638e18c233eb0e59253875e71bd16ee4c7eb76", + "dist/2024-03-19/rustfmt-nightly-aarch64-unknown-linux-musl.tar.xz": "7272af79200e1da8ab80b2e4408501ef8a54c24ba44420aaab0fb03653933ad6", + "dist/2024-03-19/rustfmt-nightly-arm-unknown-linux-gnueabi.tar.gz": "7ba3404ab333e43dbacfda6d8860d800721a7f894c672d3ea88cb88127128c90", + "dist/2024-03-19/rustfmt-nightly-arm-unknown-linux-gnueabi.tar.xz": "bd4087d9e70c0246c0606015c1e6d6b974c068118e50e2720c7ac75a6d338709", + "dist/2024-03-19/rustfmt-nightly-arm-unknown-linux-gnueabihf.tar.gz": "f87c7036539d18881cc0ad5647b523dd07cd29cd38c36665aacbdb37de316231", + "dist/2024-03-19/rustfmt-nightly-arm-unknown-linux-gnueabihf.tar.xz": "cd1b05cde5ccfc389df6d146f467a18455f22c7f23e508537c8de11b8d7aea4f", + "dist/2024-03-19/rustfmt-nightly-armv7-unknown-linux-gnueabihf.tar.gz": "66b0bdfb271448861ccc403d7549b49316c5cda81bbdaa396ff66c01dfb052df", + "dist/2024-03-19/rustfmt-nightly-armv7-unknown-linux-gnueabihf.tar.xz": "40e3df123160c8948ed06c8228df90de1368d286f9849a0a14de0725167dc8dc", + "dist/2024-03-19/rustfmt-nightly-i686-pc-windows-gnu.tar.gz": "da09c72f472b6bdbf7e794d84990153936ad1c7d275daa75b506ab72444b51a0", + "dist/2024-03-19/rustfmt-nightly-i686-pc-windows-gnu.tar.xz": "c9e2ea2216c4f7737919c63ed0e5ca362f6c3c9f227f1b3e6a243a870f229a52", + "dist/2024-03-19/rustfmt-nightly-i686-pc-windows-msvc.tar.gz": "ba468a1251b4bdb685cf5437222ccea45ba1f4d1b25ca65b82a9fae4ba93d6d9", + "dist/2024-03-19/rustfmt-nightly-i686-pc-windows-msvc.tar.xz": "64781d2017662c9973a22d322c92b242703a90895cefa584035b0d80ac966541", + "dist/2024-03-19/rustfmt-nightly-i686-unknown-linux-gnu.tar.gz": "595fcdf3cf5b2511ec828936119334516d535c4dea95f60a04eaf1724a90a276", + "dist/2024-03-19/rustfmt-nightly-i686-unknown-linux-gnu.tar.xz": "42f2537e87adc2cadee67e5dc1fd7fee4c7bf4347f88501752080a65b9e7fd89", + "dist/2024-03-19/rustfmt-nightly-loongarch64-unknown-linux-gnu.tar.gz": "3ecbee26e0b0cc43189dbd8d69a563bf71292974d0c5d313528a32012f38fb56", + "dist/2024-03-19/rustfmt-nightly-loongarch64-unknown-linux-gnu.tar.xz": "7a0918c6ad0dcdddac757c7f4580fa57ca188ff2edbf7eac07ce01626666bc95", + "dist/2024-03-19/rustfmt-nightly-powerpc-unknown-linux-gnu.tar.gz": "08197220ca270180ff4d7f484000f6b7a52800e932937238cbf1f47ce3f1080f", + "dist/2024-03-19/rustfmt-nightly-powerpc-unknown-linux-gnu.tar.xz": "dc7f03fa39872e59fab5f4d663ed092409849c62c8e4c958c6cd4ed59bc05902", + "dist/2024-03-19/rustfmt-nightly-powerpc64-unknown-linux-gnu.tar.gz": "c7744b4c88a5ac7ddbaa1b61b66b39f2799863c50b6e18c18874d5774d11fe53", + "dist/2024-03-19/rustfmt-nightly-powerpc64-unknown-linux-gnu.tar.xz": "0ed8aa4704e7d665843ea1ac532b1631cbf449180331d880466fc69483d4cd23", + "dist/2024-03-19/rustfmt-nightly-powerpc64le-unknown-linux-gnu.tar.gz": "e67d83663cb54168fded400385a5cdf8b74c6483d91fd16d03846a6411ab1afb", + "dist/2024-03-19/rustfmt-nightly-powerpc64le-unknown-linux-gnu.tar.xz": "fe4c2401281c07d1c3ed335575bd192ac57396973a3676226d57e5de32a63e3d", + "dist/2024-03-19/rustfmt-nightly-riscv64gc-unknown-linux-gnu.tar.gz": "39c4739ef0281bb1eeade5c8f7360ee8dde5a8a7ae148b0f263ba650d092cced", + "dist/2024-03-19/rustfmt-nightly-riscv64gc-unknown-linux-gnu.tar.xz": "ea26063a71a4403a4aa49098a96a29b48aab5f9b9177e57b1790b92ed749ae1b", + "dist/2024-03-19/rustfmt-nightly-s390x-unknown-linux-gnu.tar.gz": "49591c34bcb82d6cc5c08c662c4c89aca07b406fa1b48b78c7dbcb63cbe6fb5c", + "dist/2024-03-19/rustfmt-nightly-s390x-unknown-linux-gnu.tar.xz": "df664d781e8104015c506178df751ba7130c677f050cae695428fbb6180b1af8", + "dist/2024-03-19/rustfmt-nightly-x86_64-apple-darwin.tar.gz": "ff20c34ab85505c1957a677eb8123622c98f5e19e87cfa38eae76232e200242b", + "dist/2024-03-19/rustfmt-nightly-x86_64-apple-darwin.tar.xz": "c4e8b76738bbfddf94defb88e9b0c0d0c488d9a5868f2be629322c041391b43c", + "dist/2024-03-19/rustfmt-nightly-x86_64-pc-windows-gnu.tar.gz": "8e0367ab0700e916956db6041e1c6a35b0c6fbd1127a17f9482691a103dc8d70", + "dist/2024-03-19/rustfmt-nightly-x86_64-pc-windows-gnu.tar.xz": "1aad45bb09a907effb39378acf5c57c741d7b0e29eec957d8be31eb1bf47ab23", + "dist/2024-03-19/rustfmt-nightly-x86_64-pc-windows-msvc.tar.gz": "f5fa93652040ba991c429d11c5e9ae2e76aa6f21f6850a777f2ba1b065e943fe", + "dist/2024-03-19/rustfmt-nightly-x86_64-pc-windows-msvc.tar.xz": "7d448e8ae9090467197d9bfc7ac3d8f7ab81cfdfd0be140afdbbbc6c3cf65295", + "dist/2024-03-19/rustfmt-nightly-x86_64-unknown-freebsd.tar.gz": "8ea5bc3f374b5b63432151541715ab41d00f265e6cc8e57c61e175304363ca5e", + "dist/2024-03-19/rustfmt-nightly-x86_64-unknown-freebsd.tar.xz": "666deba3f55f30e302642b3e2d3c86bdce12626ae78bb7134c7d90b1c7179592", + "dist/2024-03-19/rustfmt-nightly-x86_64-unknown-illumos.tar.gz": "edf75305baace32ab2955131357e30c73c736d823d6426125e5fde213c8f4c61", + "dist/2024-03-19/rustfmt-nightly-x86_64-unknown-illumos.tar.xz": "5b3ebd05d571474002c032aa2fedc788650d374b388eff9f6c00cf5bcdd10c08", + "dist/2024-03-19/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.gz": "e795bb7cfde3d71f9e964dbc9efd930251eb3209686d5c9348f24deecb01fcde", + "dist/2024-03-19/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz": "8e1c06e91fe7cd1ffa80f043b8342c611d8f923cc9b563fda0155855d8799660", + "dist/2024-03-19/rustfmt-nightly-x86_64-unknown-linux-musl.tar.gz": "a8a51ce3eceed87d192701abb699dc60dd3c28c86622b9aa3dae833feb8207ef", + "dist/2024-03-19/rustfmt-nightly-x86_64-unknown-linux-musl.tar.xz": "389cd5d4c0decb87eb24b9ce88d5e5f33a7292153e2eb37ca2a106e4f8a4e256", + "dist/2024-03-19/rustfmt-nightly-x86_64-unknown-netbsd.tar.gz": "cbbdca68aa3ff10fb28d431ddd08b56bb4f0a0f85ebaf7c094b9740c8e2d1aa2", + "dist/2024-03-19/rustfmt-nightly-x86_64-unknown-netbsd.tar.xz": "e1c1793bfd102241338f801ba8c28f83d15fafef09046b231e30d1ac42b5e372" } } diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index eab9138b8fe..392a5a11967 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -126,6 +126,7 @@ static TARGETS: &[&str] = &[ "riscv32i-unknown-none-elf", "riscv32im-risc0-zkvm-elf", "riscv32im-unknown-none-elf", + "riscv32ima-unknown-none-elf", "riscv32imc-unknown-none-elf", "riscv32imac-unknown-none-elf", "riscv32imafc-unknown-none-elf", diff --git a/src/tools/cargo b/src/tools/cargo -Subproject 7065f0ef4aa267a7455e1c478b5ccacb7baea59 +Subproject d438c80c45c24be676ef5867edc79d0a14910ef diff --git a/src/tools/clippy/.github/workflows/clippy.yml b/src/tools/clippy/.github/workflows/clippy.yml index 603f91a910b..8179e3e65b5 100644 --- a/src/tools/clippy/.github/workflows/clippy.yml +++ b/src/tools/clippy/.github/workflows/clippy.yml @@ -26,6 +26,12 @@ env: NO_FMT_TEST: 1 CARGO_INCREMENTAL: 0 +concurrency: + # For a given workflow, if we push to the same PR, cancel all previous builds on that PR. + # If the push is not attached to a PR, we will cancel all builds on the same branch. + group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}" + cancel-in-progress: true + jobs: base: # NOTE: If you modify this job, make sure you copy the changes to clippy_bors.yml @@ -33,10 +39,6 @@ jobs: steps: # Setup - - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master - with: - github_token: "${{ secrets.github_token }}" - - name: Checkout uses: actions/checkout@v4 diff --git a/src/tools/clippy/.github/workflows/clippy_bors.yml b/src/tools/clippy/.github/workflows/clippy_bors.yml index 0bc28c1f9d9..94515987eba 100644 --- a/src/tools/clippy/.github/workflows/clippy_bors.yml +++ b/src/tools/clippy/.github/workflows/clippy_bors.yml @@ -12,6 +12,11 @@ env: NO_FMT_TEST: 1 CARGO_INCREMENTAL: 0 +concurrency: + # For a given workflow, if we push to the same branch, cancel all previous builds on that branch. + group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}" + cancel-in-progress: true + defaults: run: shell: bash @@ -21,10 +26,6 @@ jobs: runs-on: ubuntu-latest steps: - - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master - with: - github_token: "${{ secrets.github_token }}" - - name: Checkout uses: actions/checkout@v4 with: @@ -67,10 +68,6 @@ jobs: # NOTE: If you modify this job, make sure you copy the changes to clippy.yml steps: # Setup - - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master - with: - github_token: "${{ secrets.github_token }}" - - name: Checkout uses: actions/checkout@v4 @@ -131,10 +128,6 @@ jobs: steps: # Setup - - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master - with: - github_token: "${{ secrets.github_token }}" - - name: Checkout uses: actions/checkout@v4 @@ -155,10 +148,6 @@ jobs: steps: # Setup - - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master - with: - github_token: "${{ secrets.github_token }}" - - name: Checkout uses: actions/checkout@v4 @@ -211,10 +200,6 @@ jobs: steps: # Setup - - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master - with: - github_token: "${{ secrets.github_token }}" - - name: Checkout uses: actions/checkout@v4 diff --git a/src/tools/clippy/CHANGELOG.md b/src/tools/clippy/CHANGELOG.md index d3b2c0a7bf6..76ef84a48b8 100644 --- a/src/tools/clippy/CHANGELOG.md +++ b/src/tools/clippy/CHANGELOG.md @@ -6,11 +6,65 @@ document. ## Unreleased / Beta / In Rust Nightly -[a859e5cc...master](https://github.com/rust-lang/rust-clippy/compare/a859e5cc...master) +[66c29b97...master](https://github.com/rust-lang/rust-clippy/compare/66c29b97...master) + +## Rust 1.77 + +Current stable, released 2024-03-18 + +[View all 93 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-12-16T18%3A20%3A00Z..2024-01-25T18%3A15%3A56Z+base%3Amaster) + +### New Lints + +* [`suspicious_open_options`] + [#11608](https://github.com/rust-lang/rust-clippy/pull/11608) +* [`option_as_ref_cloned`] + [#12051](https://github.com/rust-lang/rust-clippy/pull/12051) +* [`thread_local_initializer_can_be_made_const`] + [#12026](https://github.com/rust-lang/rust-clippy/pull/12026) +* [`str_split_at_newline`] + [#11987](https://github.com/rust-lang/rust-clippy/pull/11987) +* [`empty_enum_variants_with_brackets`] + [#12047](https://github.com/rust-lang/rust-clippy/pull/12047) +* [`manual_is_variant_and`] + [#11865](https://github.com/rust-lang/rust-clippy/pull/11865) +* [`pub_underscore_fields`] + [#10283](https://github.com/rust-lang/rust-clippy/pull/10283) +* [`eager_transmute`] + [#11981](https://github.com/rust-lang/rust-clippy/pull/11981) +* [`iter_filter_is_some`] + [#12004](https://github.com/rust-lang/rust/pull/12004) +* [`iter_filter_is_ok`] + [#12004](https://github.com/rust-lang/rust/pull/12004) +* [`result_filter_map`] + [#11869](https://github.com/rust-lang/rust-clippy/pull/11869) +* [`unconditional_recursion`] + [#11938](https://github.com/rust-lang/rust-clippy/pull/11938) + +### Enhancements + +* [`multiple_crate_versions`]: Added the [`allowed-duplicate-crates`] configuration to allow specific crates + [#12179](https://github.com/rust-lang/rust-clippy/pull/12179) +* [`single_call_fn`]: No longer ignores `#[allow]` attributes + [#12183](https://github.com/rust-lang/rust-clippy/pull/12183) +* [`read_zero_byte_vec`]: Updated the heuristics used for linting + [#11766](https://github.com/rust-lang/rust-clippy/pull/11766) + +### ICE Fixes + +* [`unit_arg`]: No longer crashes when checking for const in nested bodies + [#11977](https://github.com/rust-lang/rust-clippy/pull/11977) +* [`indexing_slicing`]: No longer crashes when the array index exceeds `usize` + [#12266](https://github.com/rust-lang/rust-clippy/pull/12266) + +### Others + +* Warnings about invalid fields inside `clippy.toml` files now include suggestions for existing fields + [#12180](https://github.com/rust-lang/rust-clippy/pull/12180) ## Rust 1.76 -Current stable, released 2024-02-08 +Released 2024-02-08 [View all 85 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-11-02T20%3A23%3A40Z..2023-12-16T13%3A11%3A08Z+base%3Amaster) @@ -5110,6 +5164,7 @@ Released 2018-09-13 [`collection_is_never_read`]: https://rust-lang.github.io/rust-clippy/master/index.html#collection_is_never_read [`comparison_chain`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain [`comparison_to_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_to_empty +[`const_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_is_empty [`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime [`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator [`crate_in_macro_def`]: https://rust-lang.github.io/rust-clippy/master/index.html#crate_in_macro_def @@ -5156,6 +5211,7 @@ Released 2018-09-13 [`drop_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_ref [`duplicate_mod`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicate_mod [`duplicate_underscore_argument`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicate_underscore_argument +[`duplicated_attributes`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes [`duration_subsec`]: https://rust-lang.github.io/rust-clippy/master/index.html#duration_subsec [`eager_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#eager_transmute [`else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else @@ -5279,6 +5335,7 @@ Released 2018-09-13 [`int_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#int_plus_one [`integer_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_arithmetic [`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division +[`integer_division_remainder_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division_remainder_used [`into_iter_on_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_array [`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref [`into_iter_without_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_without_iter @@ -5376,6 +5433,7 @@ Released 2018-09-13 [`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap [`manual_try_fold`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold [`manual_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or +[`manual_unwrap_or_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or_default [`manual_while_let_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_while_let_some [`many_single_char_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names [`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone @@ -5813,6 +5871,7 @@ Released 2018-09-13 [`zero_divided_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_divided_by_zero [`zero_prefixed_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_prefixed_literal [`zero_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_ptr +[`zero_repeat_side_effects`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_repeat_side_effects [`zero_sized_map_values`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_sized_map_values [`zero_width_space`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_width_space [`zst_offset`]: https://rust-lang.github.io/rust-clippy/master/index.html#zst_offset diff --git a/src/tools/clippy/Cargo.toml b/src/tools/clippy/Cargo.toml index 5d1d0ce2c42..2b37b54c004 100644 --- a/src/tools/clippy/Cargo.toml +++ b/src/tools/clippy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.1.78" +version = "0.1.79" description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" @@ -24,7 +24,7 @@ path = "src/driver.rs" clippy_config = { path = "clippy_config" } clippy_lints = { path = "clippy_lints" } rustc_tools_util = "0.3.0" -tempfile = { version = "3.2", optional = true } +tempfile = { version = "3.3", optional = true } termize = "0.1" color-print = "0.3.4" anstream = "0.6.0" @@ -32,18 +32,18 @@ anstream = "0.6.0" [dev-dependencies] ui_test = "0.22.2" tester = "0.9" -regex = "1.5" +regex = "1.5.5" toml = "0.7.3" walkdir = "2.3" # This is used by the `collect-metadata` alias. -filetime = "0.2" +filetime = "0.2.9" itertools = "0.12" # UI test dependencies clippy_utils = { path = "clippy_utils" } if_chain = "1.0" -quote = "1.0" -serde = { version = "1.0.125", features = ["derive"] } +quote = "1.0.25" +serde = { version = "1.0.145", features = ["derive"] } syn = { version = "2.0", features = ["full"] } futures = "0.3" parking_lot = "0.12" diff --git a/src/tools/clippy/book/src/development/macro_expansions.md b/src/tools/clippy/book/src/development/macro_expansions.md index aecca9ef72e..125b6c4bc5b 100644 --- a/src/tools/clippy/book/src/development/macro_expansions.md +++ b/src/tools/clippy/book/src/development/macro_expansions.md @@ -52,7 +52,7 @@ if expr.span.from_expansion() { ### `Span.ctxt` method -The `span`'s context, given by the method [`ctxt`] and returning [SpanContext], +The `span`'s context, given by the method [`ctxt`] and returning [SyntaxContext], represents if the span is from a macro expansion and, if it is, which macro call expanded this span. @@ -155,4 +155,4 @@ if in_external_macro(cx.sess(), foo_span) { [`from_expansion`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.from_expansion [`in_external_macro`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/lint/fn.in_external_macro.html [Span]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html -[SpanContext]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/hygiene/struct.SyntaxContext.html +[SyntaxContext]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/hygiene/struct.SyntaxContext.html diff --git a/src/tools/clippy/book/src/development/type_checking.md b/src/tools/clippy/book/src/development/type_checking.md index 136b3fd0270..e6da4322a17 100644 --- a/src/tools/clippy/book/src/development/type_checking.md +++ b/src/tools/clippy/book/src/development/type_checking.md @@ -118,10 +118,10 @@ Here the HIR sees the types without "thinking" about them, it knows that the fun an `u32`. As far as `hir::Ty` is concerned those might be different types. But at the `ty::Ty` level the compiler understands that they're the same type, in-depth lifetimes, etc... -To get from a `hir::Ty` to a `ty::Ty`, you can use the [`hir_ty_to_ty`][hir_ty_to_ty] function outside of bodies or +To get from a `hir::Ty` to a `ty::Ty`, you can use the [`lower_ty`][lower_ty] function outside of bodies or the [`TypeckResults::node_type()`][node_type] method inside of bodies. -> **Warning**: Don't use `hir_ty_to_ty` inside of bodies, because this can cause ICEs. +> **Warning**: Don't use `lower_ty` inside of bodies, because this can cause ICEs. ## Creating Types programmatically @@ -162,6 +162,6 @@ in this chapter: [Ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html [TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/ty_kind/enum.TyKind.html [TypeckResults]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html -[middle_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/ty/struct.Ty.html -[hir_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/struct.Ty.html -[hir_ty_to_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir_analysis/fn.hir_ty_to_ty.html +[middle_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html +[hir_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.Ty.html +[lower_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/fn.lower_ty.html diff --git a/src/tools/clippy/book/src/lint_configuration.md b/src/tools/clippy/book/src/lint_configuration.md index a985346b3c0..a9234899746 100644 --- a/src/tools/clippy/book/src/lint_configuration.md +++ b/src/tools/clippy/book/src/lint_configuration.md @@ -602,6 +602,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio **Affected lints:** * [`almost_complete_range`](https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_range) * [`approx_constant`](https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant) +* [`assigning_clones`](https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones) * [`borrow_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr) * [`cast_abs_to_unsigned`](https://rust-lang.github.io/rust-clippy/master/index.html#cast_abs_to_unsigned) * [`checked_conversions`](https://rust-lang.github.io/rust-clippy/master/index.html#checked_conversions) diff --git a/src/tools/clippy/clippy.toml b/src/tools/clippy/clippy.toml index 8c405ac6a4e..62ed55beb1f 100644 --- a/src/tools/clippy/clippy.toml +++ b/src/tools/clippy/clippy.toml @@ -1,7 +1,10 @@ avoid-breaking-exported-api = false -# use the various `span_lint_*` methods instead, which also add a link to the docs -disallowed-methods = [ - "rustc_lint::context::LintContext::span_lint", - "rustc_middle::ty::context::TyCtxt::node_span_lint" -] +[[disallowed-methods]] +path = "rustc_lint::context::LintContext::span_lint" +reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint*` functions instead" + + +[[disallowed-methods]] +path = "rustc_middle::ty::context::TyCtxt::node_span_lint" +reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint_hir*` functions instead" diff --git a/src/tools/clippy/clippy_config/Cargo.toml b/src/tools/clippy/clippy_config/Cargo.toml index 2edc5ed592c..8ba2ab56625 100644 --- a/src/tools/clippy/clippy_config/Cargo.toml +++ b/src/tools/clippy/clippy_config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy_config" -version = "0.1.78" +version = "0.1.79" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/tools/clippy/clippy_config/src/conf.rs b/src/tools/clippy/clippy_config/src/conf.rs index 673b6328b39..3218fe7f456 100644 --- a/src/tools/clippy/clippy_config/src/conf.rs +++ b/src/tools/clippy/clippy_config/src/conf.rs @@ -262,7 +262,7 @@ define_Conf! { /// /// Suppress lints whenever the suggested change would cause breakage for other crates. (avoid_breaking_exported_api: bool = true), - /// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE, ITER_KV_MAP, MANUAL_C_STR_LITERALS. + /// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE, ITER_KV_MAP, MANUAL_C_STR_LITERALS, ASSIGNING_CLONES. /// /// The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml` #[default_text = ""] diff --git a/src/tools/clippy/clippy_config/src/msrvs.rs b/src/tools/clippy/clippy_config/src/msrvs.rs index a8a32f7ed20..bf4da5f14fe 100644 --- a/src/tools/clippy/clippy_config/src/msrvs.rs +++ b/src/tools/clippy/clippy_config/src/msrvs.rs @@ -23,6 +23,7 @@ msrv_aliases! { 1,70,0 { OPTION_RESULT_IS_VARIANT_AND, BINARY_HEAP_RETAIN } 1,68,0 { PATH_MAIN_SEPARATOR_STR } 1,65,0 { LET_ELSE, POINTER_CAST_CONSTNESS } + 1,63,0 { ASSIGNING_CLONES } 1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE } 1,59,0 { THREAD_LOCAL_INITIALIZER_CAN_BE_MADE_CONST } 1,58,0 { FORMAT_ARGS_CAPTURE, PATTERN_TRAIT_CHAR_ARRAY } diff --git a/src/tools/clippy/clippy_dev/src/update_lints.rs b/src/tools/clippy/clippy_dev/src/update_lints.rs index 2222abff7ad..76ae26dddf4 100644 --- a/src/tools/clippy/clippy_dev/src/update_lints.rs +++ b/src/tools/clippy/clippy_dev/src/update_lints.rs @@ -689,6 +689,8 @@ fn gen_deprecated_lints_test(lints: &[DeprecatedLint]) -> String { fn gen_renamed_lints_test(lints: &[RenamedLint]) -> String { let mut seen_lints = HashSet::new(); let mut res: String = GENERATED_FILE_COMMENT.into(); + + res.push_str("#![allow(clippy::duplicated_attributes)]\n"); for lint in lints { if seen_lints.insert(&lint.new_name) { writeln!(res, "#![allow({})]", lint.new_name).unwrap(); diff --git a/src/tools/clippy/clippy_lints/Cargo.toml b/src/tools/clippy/clippy_lints/Cargo.toml index 6ae089b3e03..1d954607eee 100644 --- a/src/tools/clippy/clippy_lints/Cargo.toml +++ b/src/tools/clippy/clippy_lints/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy_lints" -version = "0.1.78" +version = "0.1.79" description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" diff --git a/src/tools/clippy/clippy_lints/src/assigning_clones.rs b/src/tools/clippy/clippy_lints/src/assigning_clones.rs index b1c552c7a8d..88d9f762a87 100644 --- a/src/tools/clippy/clippy_lints/src/assigning_clones.rs +++ b/src/tools/clippy/clippy_lints/src/assigning_clones.rs @@ -1,3 +1,4 @@ +use clippy_config::msrvs::{self, Msrv}; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::macros::HirNode; use clippy_utils::sugg::Sugg; @@ -6,7 +7,7 @@ use rustc_errors::Applicability; use rustc_hir::{self as hir, Expr, ExprKind, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, Instance, Mutability}; -use rustc_session::declare_lint_pass; +use rustc_session::impl_lint_pass; use rustc_span::def_id::DefId; use rustc_span::symbol::sym; use rustc_span::ExpnKind; @@ -49,7 +50,19 @@ declare_clippy_lint! { perf, "assigning the result of cloning may be inefficient" } -declare_lint_pass!(AssigningClones => [ASSIGNING_CLONES]); + +pub struct AssigningClones { + msrv: Msrv, +} + +impl AssigningClones { + #[must_use] + pub fn new(msrv: Msrv) -> Self { + Self { msrv } + } +} + +impl_lint_pass!(AssigningClones => [ASSIGNING_CLONES]); impl<'tcx> LateLintPass<'tcx> for AssigningClones { fn check_expr(&mut self, cx: &LateContext<'tcx>, assign_expr: &'tcx hir::Expr<'_>) { @@ -68,10 +81,12 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones { return; }; - if is_ok_to_suggest(cx, lhs, &call) { + if is_ok_to_suggest(cx, lhs, &call, &self.msrv) { suggest(cx, assign_expr, lhs, &call); } } + + extract_msrv_attr!(LateContext); } // Try to resolve the call to `Clone::clone` or `ToOwned::to_owned`. @@ -135,7 +150,13 @@ fn extract_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option< // Return true if we find that the called method has a custom implementation and isn't derived or // provided by default by the corresponding trait. -fn is_ok_to_suggest<'tcx>(cx: &LateContext<'tcx>, lhs: &Expr<'tcx>, call: &CallCandidate<'tcx>) -> bool { +fn is_ok_to_suggest<'tcx>(cx: &LateContext<'tcx>, lhs: &Expr<'tcx>, call: &CallCandidate<'tcx>, msrv: &Msrv) -> bool { + // For calls to .to_owned we suggest using .clone_into(), which was only stablilized in 1.63. + // If the current MSRV is below that, don't suggest the lint. + if !msrv.meets(msrvs::ASSIGNING_CLONES) && matches!(call.target, TargetTrait::ToOwned) { + return false; + } + // If the left-hand side is a local variable, it might be uninitialized at this point. // In that case we do not want to suggest the lint. if let Some(local) = path_to_local(lhs) { diff --git a/src/tools/clippy/clippy_lints/src/attrs/duplicated_attributes.rs b/src/tools/clippy/clippy_lints/src/attrs/duplicated_attributes.rs new file mode 100644 index 00000000000..3c5ac597fd5 --- /dev/null +++ b/src/tools/clippy/clippy_lints/src/attrs/duplicated_attributes.rs @@ -0,0 +1,64 @@ +use super::DUPLICATED_ATTRIBUTES; +use clippy_utils::diagnostics::span_lint_and_then; +use rustc_ast::{Attribute, MetaItem}; +use rustc_data_structures::fx::FxHashMap; +use rustc_lint::EarlyContext; +use rustc_span::{sym, Span}; +use std::collections::hash_map::Entry; + +fn emit_if_duplicated( + cx: &EarlyContext<'_>, + attr: &MetaItem, + attr_paths: &mut FxHashMap<String, Span>, + complete_path: String, +) { + match attr_paths.entry(complete_path) { + Entry::Vacant(v) => { + v.insert(attr.span); + }, + Entry::Occupied(o) => { + span_lint_and_then(cx, DUPLICATED_ATTRIBUTES, attr.span, "duplicated attribute", |diag| { + diag.span_note(*o.get(), "first defined here"); + diag.span_help(attr.span, "remove this attribute"); + }); + }, + } +} + +fn check_duplicated_attr( + cx: &EarlyContext<'_>, + attr: &MetaItem, + attr_paths: &mut FxHashMap<String, Span>, + parent: &mut Vec<String>, +) { + let Some(ident) = attr.ident() else { return }; + let name = ident.name; + if name == sym::doc || name == sym::cfg_attr { + // FIXME: Would be nice to handle `cfg_attr` as well. Only problem is to check that cfg + // conditions are the same. + return; + } + if let Some(value) = attr.value_str() { + emit_if_duplicated(cx, attr, attr_paths, format!("{}:{name}={value}", parent.join(":"))); + } else if let Some(sub_attrs) = attr.meta_item_list() { + parent.push(name.as_str().to_string()); + for sub_attr in sub_attrs { + if let Some(meta) = sub_attr.meta_item() { + check_duplicated_attr(cx, meta, attr_paths, parent); + } + } + parent.pop(); + } else { + emit_if_duplicated(cx, attr, attr_paths, format!("{}:{name}", parent.join(":"))); + } +} + +pub fn check(cx: &EarlyContext<'_>, attrs: &[Attribute]) { + let mut attr_paths = FxHashMap::default(); + + for attr in attrs { + if let Some(meta) = attr.meta() { + check_duplicated_attr(cx, &meta, &mut attr_paths, &mut Vec::new()); + } + } +} diff --git a/src/tools/clippy/clippy_lints/src/attrs/mod.rs b/src/tools/clippy/clippy_lints/src/attrs/mod.rs index c4c65d3248a..675c428948f 100644 --- a/src/tools/clippy/clippy_lints/src/attrs/mod.rs +++ b/src/tools/clippy/clippy_lints/src/attrs/mod.rs @@ -4,6 +4,7 @@ mod allow_attributes_without_reason; mod blanket_clippy_restriction_lints; mod deprecated_cfg_attr; mod deprecated_semver; +mod duplicated_attributes; mod empty_line_after; mod inline_always; mod maybe_misused_cfg; @@ -16,7 +17,7 @@ mod useless_attribute; mod utils; use clippy_config::msrvs::Msrv; -use rustc_ast::{Attribute, MetaItemKind, NestedMetaItem}; +use rustc_ast::{Attribute, Crate, MetaItemKind, NestedMetaItem}; use rustc_hir::{ImplItem, Item, ItemKind, TraitItem}; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, impl_lint_pass}; @@ -489,6 +490,32 @@ declare_clippy_lint! { "item has both inner and outer attributes" } +declare_clippy_lint! { + /// ### What it does + /// Checks for attributes that appear two or more times. + /// + /// ### Why is this bad? + /// Repeating an attribute on the same item (or globally on the same crate) + /// is unnecessary and doesn't have an effect. + /// + /// ### Example + /// ```no_run + /// #[allow(dead_code)] + /// #[allow(dead_code)] + /// fn foo() {} + /// ``` + /// + /// Use instead: + /// ```no_run + /// #[allow(dead_code)] + /// fn foo() {} + /// ``` + #[clippy::version = "1.78.0"] + pub DUPLICATED_ATTRIBUTES, + suspicious, + "duplicated attribute" +} + declare_lint_pass!(Attributes => [ ALLOW_ATTRIBUTES_WITHOUT_REASON, INLINE_ALWAYS, @@ -568,12 +595,18 @@ impl_lint_pass!(EarlyAttributes => [ DEPRECATED_CLIPPY_CFG_ATTR, UNNECESSARY_CLIPPY_CFG, MIXED_ATTRIBUTES_STYLE, + DUPLICATED_ATTRIBUTES, ]); impl EarlyLintPass for EarlyAttributes { + fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &Crate) { + duplicated_attributes::check(cx, &krate.attrs); + } + fn check_item(&mut self, cx: &EarlyContext<'_>, item: &rustc_ast::Item) { empty_line_after::check(cx, item); mixed_attributes_style::check(cx, item); + duplicated_attributes::check(cx, &item.attrs); } fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) { diff --git a/src/tools/clippy/clippy_lints/src/box_default.rs b/src/tools/clippy/clippy_lints/src/box_default.rs index 779ae03c464..66206d1a059 100644 --- a/src/tools/clippy/clippy_lints/src/box_default.rs +++ b/src/tools/clippy/clippy_lints/src/box_default.rs @@ -70,7 +70,9 @@ impl LateLintPass<'_> for BoxDefault { "try", if is_plain_default(cx, arg_path) || given_type(cx, expr) { "Box::default()".into() - } else if let Some(arg_ty) = cx.typeck_results().expr_ty(arg).make_suggestable(cx.tcx, true) { + } else if let Some(arg_ty) = + cx.typeck_results().expr_ty(arg).make_suggestable(cx.tcx, true, None) + { // Check if we can copy from the source expression in the replacement. // We need the call to have no argument (see `explicit_default_type`). if inner_call_args.is_empty() diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_lossless.rs b/src/tools/clippy/clippy_lints/src/casts/cast_lossless.rs index fe2455f4b23..86f4332d05a 100644 --- a/src/tools/clippy/clippy_lints/src/casts/cast_lossless.rs +++ b/src/tools/clippy/clippy_lints/src/casts/cast_lossless.rs @@ -1,12 +1,12 @@ use clippy_config::msrvs::{self, Msrv}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::in_constant; -use clippy_utils::source::snippet_opt; +use clippy_utils::source::{snippet_opt, snippet_with_applicability}; use clippy_utils::ty::is_isize_or_usize; use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind}; +use rustc_hir::{Expr, ExprKind, QPath, TyKind}; use rustc_lint::LateContext; -use rustc_middle::ty::{self, FloatTy, Ty}; +use rustc_middle::ty::{self, FloatTy, Ty, UintTy}; use super::{utils, CAST_LOSSLESS}; @@ -16,6 +16,7 @@ pub(super) fn check( cast_op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, + cast_to_hir: &rustc_hir::Ty<'_>, msrv: &Msrv, ) { if !should_lint(cx, expr, cast_from, cast_to, msrv) { @@ -24,11 +25,11 @@ pub(super) fn check( // The suggestion is to use a function call, so if the original expression // has parens on the outside, they are no longer needed. - let mut applicability = Applicability::MachineApplicable; + let mut app = Applicability::MachineApplicable; let opt = snippet_opt(cx, cast_op.span.source_callsite()); let sugg = opt.as_ref().map_or_else( || { - applicability = Applicability::HasPlaceholders; + app = Applicability::HasPlaceholders; ".." }, |snip| { @@ -40,10 +41,27 @@ pub(super) fn check( }, ); + // Display the type alias instead of the aliased type. Fixes #11285 + // + // FIXME: Once `lazy_type_alias` is stabilized(?) we should use `rustc_middle` types instead, + // this will allow us to display the right type with `cast_from` as well. + let cast_to_fmt = if let TyKind::Path(QPath::Resolved(None, path)) = cast_to_hir.kind + // It's a bit annoying but the turbofish is optional for types. A type in an `as` cast + // shouldn't have these if they're primitives, which are the only things we deal with. + // + // This could be removed for performance if this check is determined to have a pretty major + // effect. + && path.segments.iter().all(|segment| segment.args.is_none()) + { + snippet_with_applicability(cx, cast_to_hir.span, "..", &mut app) + } else { + cast_to.to_string().into() + }; + let message = if cast_from.is_bool() { - format!("casting `{cast_from:}` to `{cast_to:}` is more cleanly stated with `{cast_to:}::from(_)`") + format!("casting `{cast_from}` to `{cast_to_fmt}` is more cleanly stated with `{cast_to_fmt}::from(_)`") } else { - format!("casting `{cast_from}` to `{cast_to}` may become silently lossy if you later change the type") + format!("casting `{cast_from}` to `{cast_to_fmt}` may become silently lossy if you later change the type") }; span_lint_and_sugg( @@ -52,14 +70,17 @@ pub(super) fn check( expr.span, &message, "try", - format!("{cast_to}::from({sugg})"), - applicability, + format!("{cast_to_fmt}::from({sugg})"), + app, ); } fn should_lint(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>, msrv: &Msrv) -> bool { // Do not suggest using From in consts/statics until it is valid to do so (see #2267). - if in_constant(cx, expr.hir_id) { + // + // If destination is u128, do not lint because source type cannot be larger + // If source is bool, still lint due to the lint message differing (refers to style) + if in_constant(cx, expr.hir_id) || (!cast_from.is_bool() && matches!(cast_to.kind(), ty::Uint(UintTy::U128))) { return false; } diff --git a/src/tools/clippy/clippy_lints/src/casts/mod.rs b/src/tools/clippy/clippy_lints/src/casts/mod.rs index 14f2f4a7f59..063aab28238 100644 --- a/src/tools/clippy/clippy_lints/src/casts/mod.rs +++ b/src/tools/clippy/clippy_lints/src/casts/mod.rs @@ -791,7 +791,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts { cast_abs_to_unsigned::check(cx, expr, cast_expr, cast_from, cast_to, &self.msrv); cast_nan_to_int::check(cx, expr, cast_expr, cast_from, cast_to); } - cast_lossless::check(cx, expr, cast_expr, cast_from, cast_to, &self.msrv); + cast_lossless::check(cx, expr, cast_expr, cast_from, cast_to, cast_to_hir, &self.msrv); cast_enum_constructor::check(cx, expr, cast_expr, cast_from); } diff --git a/src/tools/clippy/clippy_lints/src/dbg_macro.rs b/src/tools/clippy/clippy_lints/src/dbg_macro.rs index ec66556cebf..e2296767431 100644 --- a/src/tools/clippy/clippy_lints/src/dbg_macro.rs +++ b/src/tools/clippy/clippy_lints/src/dbg_macro.rs @@ -1,12 +1,14 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::macros::root_macro_call_first_node; +use clippy_utils::macros::{macro_backtrace, MacroCall}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{is_in_cfg_test, is_in_test_function}; +use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; -use rustc_hir::{Expr, ExprKind, Node}; +use rustc_hir::{Expr, ExprKind, HirId, Node}; use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_middle::lint::in_external_macro; use rustc_session::impl_lint_pass; -use rustc_span::sym; +use rustc_span::{sym, Span, SyntaxContext}; declare_clippy_lint! { /// ### What it does @@ -31,31 +33,38 @@ declare_clippy_lint! { "`dbg!` macro is intended as a debugging tool" } -#[derive(Copy, Clone)] +#[derive(Clone)] pub struct DbgMacro { allow_dbg_in_tests: bool, + /// Tracks the `dbg!` macro callsites that are already checked. + checked_dbg_call_site: FxHashSet<Span>, + /// Tracks the previous `SyntaxContext`, to avoid walking the same context chain. + prev_ctxt: SyntaxContext, } impl_lint_pass!(DbgMacro => [DBG_MACRO]); impl DbgMacro { pub fn new(allow_dbg_in_tests: bool) -> Self { - DbgMacro { allow_dbg_in_tests } + DbgMacro { + allow_dbg_in_tests, + checked_dbg_call_site: FxHashSet::default(), + prev_ctxt: SyntaxContext::root(), + } } } impl LateLintPass<'_> for DbgMacro { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - let Some(macro_call) = root_macro_call_first_node(cx, expr) else { - return; - }; - if cx.tcx.is_diagnostic_item(sym::dbg_macro, macro_call.def_id) { + let cur_syntax_ctxt = expr.span.ctxt(); + + if cur_syntax_ctxt != self.prev_ctxt && + let Some(macro_call) = first_dbg_macro_in_expansion(cx, expr.span) && + !in_external_macro(cx.sess(), macro_call.span) && + self.checked_dbg_call_site.insert(macro_call.span) && // allows `dbg!` in test code if allow-dbg-in-test is set to true in clippy.toml - if self.allow_dbg_in_tests - && (is_in_test_function(cx.tcx, expr.hir_id) || is_in_cfg_test(cx.tcx, expr.hir_id)) - { - return; - } + !(self.allow_dbg_in_tests && is_in_test(cx, expr.hir_id)) + { let mut applicability = Applicability::MachineApplicable; let (sugg_span, suggestion) = match expr.peel_drop_temps().kind { @@ -101,6 +110,8 @@ impl LateLintPass<'_> for DbgMacro { _ => return, }; + self.prev_ctxt = cur_syntax_ctxt; + span_lint_and_sugg( cx, DBG_MACRO, @@ -112,4 +123,16 @@ impl LateLintPass<'_> for DbgMacro { ); } } + + fn check_crate_post(&mut self, _: &LateContext<'_>) { + self.checked_dbg_call_site = FxHashSet::default(); + } +} + +fn is_in_test(cx: &LateContext<'_>, hir_id: HirId) -> bool { + is_in_test_function(cx.tcx, hir_id) || is_in_cfg_test(cx.tcx, hir_id) +} + +fn first_dbg_macro_in_expansion(cx: &LateContext<'_>, span: Span) -> Option<MacroCall> { + macro_backtrace(span).find(|mc| cx.tcx.is_diagnostic_item(sym::dbg_macro, mc.def_id)) } diff --git a/src/tools/clippy/clippy_lints/src/declared_lints.rs b/src/tools/clippy/clippy_lints/src/declared_lints.rs index 2b324f5f96e..c8e148598a2 100644 --- a/src/tools/clippy/clippy_lints/src/declared_lints.rs +++ b/src/tools/clippy/clippy_lints/src/declared_lints.rs @@ -54,6 +54,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::attrs::DEPRECATED_CFG_ATTR_INFO, crate::attrs::DEPRECATED_CLIPPY_CFG_ATTR_INFO, crate::attrs::DEPRECATED_SEMVER_INFO, + crate::attrs::DUPLICATED_ATTRIBUTES_INFO, crate::attrs::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO, crate::attrs::EMPTY_LINE_AFTER_OUTER_ATTR_INFO, crate::attrs::INLINE_ALWAYS_INFO, @@ -235,6 +236,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::instant_subtraction::MANUAL_INSTANT_ELAPSED_INFO, crate::instant_subtraction::UNCHECKED_DURATION_SUBTRACTION_INFO, crate::int_plus_one::INT_PLUS_ONE_INFO, + crate::integer_division_remainder_used::INTEGER_DIVISION_REMAINDER_USED_INFO, crate::invalid_upcast_comparisons::INVALID_UPCAST_COMPARISONS_INFO, crate::item_name_repetitions::ENUM_VARIANT_NAMES_INFO, crate::item_name_repetitions::MODULE_INCEPTION_INFO, @@ -310,6 +312,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::manual_slice_size_calculation::MANUAL_SLICE_SIZE_CALCULATION_INFO, crate::manual_string_new::MANUAL_STRING_NEW_INFO, crate::manual_strip::MANUAL_STRIP_INFO, + crate::manual_unwrap_or_default::MANUAL_UNWRAP_OR_DEFAULT_INFO, crate::map_unit_fn::OPTION_MAP_UNIT_FN_INFO, crate::map_unit_fn::RESULT_MAP_UNIT_FN_INFO, crate::match_result_ok::MATCH_RESULT_OK_INFO, @@ -353,6 +356,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::methods::CLONE_ON_COPY_INFO, crate::methods::CLONE_ON_REF_PTR_INFO, crate::methods::COLLAPSIBLE_STR_REPLACE_INFO, + crate::methods::CONST_IS_EMPTY_INFO, crate::methods::DRAIN_COLLECT_INFO, crate::methods::ERR_EXPECT_INFO, crate::methods::EXPECT_FUN_CALL_INFO, @@ -750,5 +754,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::write::WRITE_LITERAL_INFO, crate::write::WRITE_WITH_NEWLINE_INFO, crate::zero_div_zero::ZERO_DIVIDED_BY_ZERO_INFO, + crate::zero_repeat_side_effects::ZERO_REPEAT_SIDE_EFFECTS_INFO, crate::zero_sized_map_values::ZERO_SIZED_MAP_VALUES_INFO, ]; diff --git a/src/tools/clippy/clippy_lints/src/doc/markdown.rs b/src/tools/clippy/clippy_lints/src/doc/markdown.rs index d2f14756591..1add02af310 100644 --- a/src/tools/clippy/clippy_lints/src/doc/markdown.rs +++ b/src/tools/clippy/clippy_lints/src/doc/markdown.rs @@ -8,7 +8,14 @@ use url::Url; use crate::doc::DOC_MARKDOWN; -pub fn check(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, text: &str, span: Span, code_level: isize) { +pub fn check( + cx: &LateContext<'_>, + valid_idents: &FxHashSet<String>, + text: &str, + span: Span, + code_level: isize, + blockquote_level: isize, +) { for orig_word in text.split(|c: char| c.is_whitespace() || c == '\'') { // Trim punctuation as in `some comment (see foo::bar).` // ^^ @@ -46,11 +53,11 @@ pub fn check(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, text: &str, span.parent(), ); - check_word(cx, word, span, code_level); + check_word(cx, word, span, code_level, blockquote_level); } } -fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize) { +fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize, blockquote_level: isize) { /// Checks if a string is upper-camel-case, i.e., starts with an uppercase and /// contains at least two uppercase letters (`Clippy` is ok) and one lower-case /// letter (`NASA` is ok). @@ -97,7 +104,9 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize) { } // We assume that mixed-case words are not meant to be put inside backticks. (Issue #2343) - if code_level > 0 || (has_underscore(word) && has_hyphen(word)) { + // + // We also assume that backticks are not necessary if inside a quote. (Issue #10262) + if code_level > 0 || blockquote_level > 0 || (has_underscore(word) && has_hyphen(word)) { return; } diff --git a/src/tools/clippy/clippy_lints/src/doc/mod.rs b/src/tools/clippy/clippy_lints/src/doc/mod.rs index 003d26b7b89..b135e4e3577 100644 --- a/src/tools/clippy/clippy_lints/src/doc/mod.rs +++ b/src/tools/clippy/clippy_lints/src/doc/mod.rs @@ -7,14 +7,14 @@ use clippy_utils::{is_entrypoint_fn, method_chain_args}; use pulldown_cmark::Event::{ Code, End, FootnoteReference, HardBreak, Html, Rule, SoftBreak, Start, TaskListMarker, Text, }; -use pulldown_cmark::Tag::{CodeBlock, Heading, Item, Link, Paragraph}; +use pulldown_cmark::Tag::{BlockQuote, CodeBlock, Heading, Item, Link, Paragraph}; use pulldown_cmark::{BrokenLink, CodeBlockKind, CowStr, Options}; use rustc_ast::ast::Attribute; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{AnonConst, Expr}; -use rustc_lint::{LateContext, LateLintPass}; +use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::in_external_macro; use rustc_middle::ty; @@ -538,7 +538,16 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[ suspicious_doc_comments::check(cx, attrs); - let (fragments, _) = attrs_to_doc_fragments(attrs.iter().map(|attr| (attr, None)), true); + let (fragments, _) = attrs_to_doc_fragments( + attrs.iter().filter_map(|attr| { + if in_external_macro(cx.sess(), attr.span) { + None + } else { + Some((attr, None)) + } + }), + true, + ); let mut doc = fragments.iter().fold(String::new(), |mut acc, fragment| { add_doc_fragment(&mut acc, fragment); acc @@ -602,6 +611,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize let mut text_to_check: Vec<(CowStr<'_>, Range<usize>, isize)> = Vec::new(); let mut paragraph_range = 0..0; let mut code_level = 0; + let mut blockquote_level = 0; for (event, range) in events { match event { @@ -610,8 +620,14 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize code_level += 1; } else if tag.starts_with("</code") { code_level -= 1; + } else if tag.starts_with("<blockquote") || tag.starts_with("<q") { + blockquote_level += 1; + } else if tag.starts_with("</blockquote") || tag.starts_with("</q") { + blockquote_level -= 1; } }, + Start(BlockQuote) => blockquote_level += 1, + End(BlockQuote) => blockquote_level -= 1, Start(CodeBlock(ref kind)) => { in_code = true; if let CodeBlockKind::Fenced(lang) = kind { @@ -663,7 +679,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize } else { for (text, range, assoc_code_level) in text_to_check { if let Some(span) = fragments.span(cx, range) { - markdown::check(cx, valid_idents, &text, span, assoc_code_level); + markdown::check(cx, valid_idents, &text, span, assoc_code_level, blockquote_level); } } } diff --git a/src/tools/clippy/clippy_lints/src/else_if_without_else.rs b/src/tools/clippy/clippy_lints/src/else_if_without_else.rs index 47780cab9ed..a6ca7fe9e0b 100644 --- a/src/tools/clippy/clippy_lints/src/else_if_without_else.rs +++ b/src/tools/clippy/clippy_lints/src/else_if_without_else.rs @@ -49,24 +49,22 @@ declare_clippy_lint! { declare_lint_pass!(ElseIfWithoutElse => [ELSE_IF_WITHOUT_ELSE]); impl EarlyLintPass for ElseIfWithoutElse { - fn check_expr(&mut self, cx: &EarlyContext<'_>, mut item: &Expr) { + fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) { if in_external_macro(cx.sess(), item.span) { return; } - while let ExprKind::If(_, _, Some(ref els)) = item.kind { - if let ExprKind::If(_, _, None) = els.kind { - span_lint_and_help( - cx, - ELSE_IF_WITHOUT_ELSE, - els.span, - "`if` expression with an `else if`, but without a final `else`", - None, - "add an `else` block here", - ); - } - - item = els; + if let ExprKind::If(_, _, Some(ref els)) = item.kind + && let ExprKind::If(_, _, None) = els.kind + { + span_lint_and_help( + cx, + ELSE_IF_WITHOUT_ELSE, + els.span, + "`if` expression with an `else if`, but without a final `else`", + None, + "add an `else` block here", + ); } } } diff --git a/src/tools/clippy/clippy_lints/src/entry.rs b/src/tools/clippy/clippy_lints/src/entry.rs index ebda2ad8387..dafbf6c8846 100644 --- a/src/tools/clippy/clippy_lints/src/entry.rs +++ b/src/tools/clippy/clippy_lints/src/entry.rs @@ -358,7 +358,7 @@ struct InsertSearcher<'cx, 'tcx> { can_use_entry: bool, /// Whether this expression is the final expression in this code path. This may be a statement. in_tail_pos: bool, - // Is this expression a single insert. A slightly better suggestion can be made in this case. + /// Is this expression a single insert. A slightly better suggestion can be made in this case. is_single_insert: bool, /// If the visitor has seen the map being used. is_map_used: bool, @@ -431,6 +431,9 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> { self.is_single_insert = false; self.visit_expr(e); } + if let Some(els) = &l.els { + self.visit_block(els); + } }, StmtKind::Item(_) => { self.allow_insert_closure &= !self.in_tail_pos; diff --git a/src/tools/clippy/clippy_lints/src/equatable_if_let.rs b/src/tools/clippy/clippy_lints/src/equatable_if_let.rs index 4e728d61b85..37442bf3e28 100644 --- a/src/tools/clippy/clippy_lints/src/equatable_if_let.rs +++ b/src/tools/clippy/clippy_lints/src/equatable_if_let.rs @@ -55,7 +55,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool { | PatKind::Err(_) => false, PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)), PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a), - PatKind::Ref(x, _) | PatKind::Box(x) => unary_pattern(x), + PatKind::Ref(x, _) | PatKind::Box(x) | PatKind::Deref(x) => unary_pattern(x), PatKind::Path(_) | PatKind::Lit(_) => true, } } diff --git a/src/tools/clippy/clippy_lints/src/functions/mod.rs b/src/tools/clippy/clippy_lints/src/functions/mod.rs index 96da2ec2a1a..9cc51fa8cd5 100644 --- a/src/tools/clippy/clippy_lints/src/functions/mod.rs +++ b/src/tools/clippy/clippy_lints/src/functions/mod.rs @@ -250,7 +250,7 @@ declare_clippy_lint! { /// /// ### Why is this bad? /// A `Result` is at least as large as the `Err`-variant. While we - /// expect that variant to be seldomly used, the compiler needs to reserve + /// expect that variant to be seldom used, the compiler needs to reserve /// and move that much memory every single time. /// Furthermore, errors are often simply passed up the call-stack, making /// use of the `?`-operator and its type-conversion mechanics. If the diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index 9fb59a320d4..18f4e51ebd6 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { } let ret_ty = return_ty(cx, cx.tcx.local_def_id_to_hir_id(fn_def_id).expect_owner()); if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind() { - let preds = cx.tcx.explicit_item_bounds(def_id); + let preds = cx.tcx.explicit_item_super_predicates(def_id); let mut is_future = false; for (p, _span) in preds.iter_instantiated_copied(cx.tcx, args) { if let Some(trait_pred) = p.as_trait_clause() { diff --git a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs index a79bf66ae01..8acb138332c 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs @@ -5,7 +5,7 @@ use rustc_errors::Diag; use rustc_hir as hir; use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor}; use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{Ty, TypeckResults}; @@ -227,7 +227,7 @@ impl<'tcx> ImplicitHasherType<'tcx> { .collect(); let params_len = params.len(); - let ty = hir_ty_to_ty(cx.tcx, hir_ty); + let ty = lower_ty(cx.tcx, hir_ty); if is_type_diagnostic_item(cx, ty, sym::HashMap) && params_len == 2 { Some(ImplicitHasherType::HashMap( diff --git a/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs b/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs index 74582f7f1de..9f4d7b51271 100644 --- a/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs +++ b/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs @@ -6,7 +6,7 @@ use rustc_hir::{ GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier, TyKind, TypeBinding, WherePredicate, }; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, ClauseKind, Generics, Ty, TyCtxt}; use rustc_session::declare_lint_pass; @@ -146,7 +146,7 @@ fn try_resolve_type<'tcx>( index: usize, ) -> Option<Ty<'tcx>> { match args.get(index - 1) { - Some(GenericArg::Type(ty)) => Some(hir_ty_to_ty(tcx, ty)), + Some(GenericArg::Type(ty)) => Some(lower_ty(tcx, ty)), Some(_) => None, None => Some(tcx.type_of(generics.params[index].def_id).skip_binder()), } diff --git a/src/tools/clippy/clippy_lints/src/integer_division_remainder_used.rs b/src/tools/clippy/clippy_lints/src/integer_division_remainder_used.rs new file mode 100644 index 00000000000..36dc45ca788 --- /dev/null +++ b/src/tools/clippy/clippy_lints/src/integer_division_remainder_used.rs @@ -0,0 +1,50 @@ +use clippy_utils::diagnostics::span_lint; +use rustc_ast::BinOpKind; +use rustc_hir::{Expr, ExprKind}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty::{self}; +use rustc_session::declare_lint_pass; + +declare_clippy_lint! { + /// ### What it does + /// Checks for the usage of division (/) and remainder (%) operations + /// when performed on any integer types using the default Div and Rem trait implementations. + /// + /// ### Why is this bad? + /// In cryptographic contexts, division can result in timing sidechannel vulnerabilities, + /// and needs to be replaced with constant-time code instead (e.g. Barrett reduction). + /// + /// ### Example + /// ```no_run + /// let my_div = 10 / 2; + /// ``` + /// Use instead: + /// ```no_run + /// let my_div = 10 >> 1; + /// ``` + #[clippy::version = "1.78.0"] + pub INTEGER_DIVISION_REMAINDER_USED, + restriction, + "use of disallowed default division and remainder operations" +} + +declare_lint_pass!(IntegerDivisionRemainderUsed => [INTEGER_DIVISION_REMAINDER_USED]); + +impl LateLintPass<'_> for IntegerDivisionRemainderUsed { + fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { + if let ExprKind::Binary(op, lhs, rhs) = &expr.kind + && let BinOpKind::Div | BinOpKind::Rem = op.node + && let lhs_ty = cx.typeck_results().expr_ty(lhs) + && let rhs_ty = cx.typeck_results().expr_ty(rhs) + && let ty::Int(_) | ty::Uint(_) = lhs_ty.peel_refs().kind() + && let ty::Int(_) | ty::Uint(_) = rhs_ty.peel_refs().kind() + { + span_lint( + cx, + INTEGER_DIVISION_REMAINDER_USED, + expr.span.source_callsite(), + &format!("use of {} has been disallowed in this context", op.node.as_str()), + ); + } + } +} diff --git a/src/tools/clippy/clippy_lints/src/let_if_seq.rs b/src/tools/clippy/clippy_lints/src/let_if_seq.rs index f084d89ccc2..d4ddf76fb8a 100644 --- a/src/tools/clippy/clippy_lints/src/let_if_seq.rs +++ b/src/tools/clippy/clippy_lints/src/let_if_seq.rs @@ -1,4 +1,4 @@ -use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::path_to_local_id; use clippy_utils::source::snippet; use clippy_utils::visitors::is_local_used; @@ -122,9 +122,10 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq { value=snippet(cx, value.span, "<value>"), default=snippet(cx, default.span, "<default>"), ); - span_lint_and_then( + span_lint_hir_and_then( cx, USELESS_LET_IF_SEQ, + local.hir_id, span, "`if _ { .. } else { .. }` is an expression", |diag| { diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs index b930175c4d8..57fac351042 100644 --- a/src/tools/clippy/clippy_lints/src/lib.rs +++ b/src/tools/clippy/clippy_lints/src/lib.rs @@ -172,6 +172,7 @@ mod init_numbered_fields; mod inline_fn_without_body; mod instant_subtraction; mod int_plus_one; +mod integer_division_remainder_used; mod invalid_upcast_comparisons; mod item_name_repetitions; mod items_after_statements; @@ -211,6 +212,7 @@ mod manual_retain; mod manual_slice_size_calculation; mod manual_string_new; mod manual_strip; +mod manual_unwrap_or_default; mod map_unit_fn; mod match_result_ok; mod matches; @@ -373,6 +375,7 @@ mod visibility; mod wildcard_imports; mod write; mod zero_div_zero; +mod zero_repeat_side_effects; mod zero_sized_map_values; // end lints modules, do not remove this comment, it’s used in `update_lints` @@ -1119,7 +1122,10 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(move |_| Box::new(incompatible_msrv::IncompatibleMsrv::new(msrv()))); store.register_late_pass(|_| Box::new(to_string_trait_impl::ToStringTraitImpl)); store.register_early_pass(|| Box::new(multiple_bound_locations::MultipleBoundLocations)); - store.register_late_pass(|_| Box::new(assigning_clones::AssigningClones)); + store.register_late_pass(move |_| Box::new(assigning_clones::AssigningClones::new(msrv()))); + store.register_late_pass(|_| Box::new(zero_repeat_side_effects::ZeroRepeatSideEffects)); + store.register_late_pass(|_| Box::new(manual_unwrap_or_default::ManualUnwrapOrDefault)); + store.register_late_pass(|_| Box::new(integer_division_remainder_used::IntegerDivisionRemainderUsed)); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs index 47dc3807e62..cf34c904dfe 100644 --- a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs @@ -273,7 +273,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> { } return false; // no need to walk further *on the variable* }, - Res::Def(DefKind::Static{..} | DefKind::Const, ..) => { + Res::Def(DefKind::Static { .. } | DefKind::Const, ..) => { if index_used_directly { self.indexed_directly.insert( seqvar.segments[0].ident.name, diff --git a/src/tools/clippy/clippy_lints/src/loops/never_loop.rs b/src/tools/clippy/clippy_lints/src/loops/never_loop.rs index 6cc79440f39..8aae7be4593 100644 --- a/src/tools/clippy/clippy_lints/src/loops/never_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/never_loop.rs @@ -255,9 +255,7 @@ fn never_loop_expr<'tcx>( InlineAsmOperand::Const { .. } | InlineAsmOperand::SymFn { .. } | InlineAsmOperand::SymStatic { .. } => { NeverLoopResult::Normal }, - InlineAsmOperand::Label { block } => { - never_loop_block(cx, block, local_labels, main_loop_id) - } + InlineAsmOperand::Label { block } => never_loop_block(cx, block, local_labels, main_loop_id), })), ExprKind::OffsetOf(_, _) | ExprKind::Yield(_, _) diff --git a/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs b/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs index dd7fae79d9b..31f0f1cfeba 100644 --- a/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs +++ b/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs @@ -1,62 +1,41 @@ use super::UNUSED_ENUMERATE_INDEX; use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then}; use clippy_utils::source::snippet; -use clippy_utils::{pat_is_wild, sugg}; +use clippy_utils::{match_def_path, pat_is_wild, sugg}; use rustc_hir::def::DefKind; use rustc_hir::{Expr, ExprKind, Pat, PatKind}; use rustc_lint::LateContext; use rustc_middle::ty; /// Checks for the `UNUSED_ENUMERATE_INDEX` lint. -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>) { - let PatKind::Tuple([index, elem], _) = pat.kind else { - return; - }; - - let ExprKind::MethodCall(_method, self_arg, [], _) = arg.kind else { - return; - }; - - let ty = cx.typeck_results().expr_ty(arg); - - if !pat_is_wild(cx, &index.kind, body) { - return; - } - - let name = match *ty.kind() { - ty::Adt(base, _substs) => cx.tcx.def_path_str(base.did()), - _ => return, - }; - - if name != "std::iter::Enumerate" && name != "core::iter::Enumerate" { - return; +/// +/// The lint is also partially implemented in `clippy_lints/src/methods/unused_enumerate_index.rs`. +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'tcx>, arg: &Expr<'_>, body: &'tcx Expr<'tcx>) { + if let PatKind::Tuple([index, elem], _) = pat.kind + && let ExprKind::MethodCall(_method, self_arg, [], _) = arg.kind + && let ty = cx.typeck_results().expr_ty(arg) + && pat_is_wild(cx, &index.kind, body) + && let ty::Adt(base, _) = *ty.kind() + && match_def_path(cx, base.did(), &clippy_utils::paths::CORE_ITER_ENUMERATE_STRUCT) + && let Some((DefKind::AssocFn, call_id)) = cx.typeck_results().type_dependent_def(arg.hir_id) + && match_def_path(cx, call_id, &clippy_utils::paths::CORE_ITER_ENUMERATE_METHOD) + { + span_lint_and_then( + cx, + UNUSED_ENUMERATE_INDEX, + arg.span, + "you seem to use `.enumerate()` and immediately discard the index", + |diag| { + let base_iter = sugg::Sugg::hir(cx, self_arg, "base iter"); + multispan_sugg( + diag, + "remove the `.enumerate()` call", + vec![ + (pat.span, snippet(cx, elem.span, "..").into_owned()), + (arg.span, base_iter.to_string()), + ], + ); + }, + ); } - - let Some((DefKind::AssocFn, call_id)) = cx.typeck_results().type_dependent_def(arg.hir_id) else { - return; - }; - - let call_name = cx.tcx.def_path_str(call_id); - - if call_name != "std::iter::Iterator::enumerate" && call_name != "core::iter::Iterator::enumerate" { - return; - } - - span_lint_and_then( - cx, - UNUSED_ENUMERATE_INDEX, - arg.span, - "you seem to use `.enumerate()` and immediately discard the index", - |diag| { - let base_iter = sugg::Sugg::hir(cx, self_arg, "base iter"); - multispan_sugg( - diag, - "remove the `.enumerate()` call", - vec![ - (pat.span, snippet(cx, elem.span, "..").into_owned()), - (arg.span, base_iter.to_string()), - ], - ); - }, - ); } diff --git a/src/tools/clippy/clippy_lints/src/loops/while_immutable_condition.rs b/src/tools/clippy/clippy_lints/src/loops/while_immutable_condition.rs index 3511d24e813..3dff826cb85 100644 --- a/src/tools/clippy/clippy_lints/src/loops/while_immutable_condition.rs +++ b/src/tools/clippy/clippy_lints/src/loops/while_immutable_condition.rs @@ -101,7 +101,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> { Res::Local(hir_id) => { self.ids.insert(hir_id); }, - Res::Def(DefKind::Static{..}, def_id) => { + Res::Def(DefKind::Static { .. }, def_id) => { let mutable = self.cx.tcx.is_mutable_static(def_id); self.def_ids.insert(def_id, mutable); }, diff --git a/src/tools/clippy/clippy_lints/src/manual_retain.rs b/src/tools/clippy/clippy_lints/src/manual_retain.rs index 6f15fca089e..3ddb06a1e08 100644 --- a/src/tools/clippy/clippy_lints/src/manual_retain.rs +++ b/src/tools/clippy/clippy_lints/src/manual_retain.rs @@ -2,7 +2,7 @@ use clippy_config::msrvs::{self, Msrv}; use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet; use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item}; -use clippy_utils::{get_parent_expr, match_def_path, paths, SpanlessEq}; +use clippy_utils::{match_def_path, paths, SpanlessEq}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -69,17 +69,16 @@ impl_lint_pass!(ManualRetain => [MANUAL_RETAIN]); impl<'tcx> LateLintPass<'tcx> for ManualRetain { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if let Some(parent_expr) = get_parent_expr(cx, expr) - && let Assign(left_expr, collect_expr, _) = &parent_expr.kind + if let Assign(left_expr, collect_expr, _) = &expr.kind && let hir::ExprKind::MethodCall(seg, ..) = &collect_expr.kind && seg.args.is_none() && let hir::ExprKind::MethodCall(_, target_expr, [], _) = &collect_expr.kind && let Some(collect_def_id) = cx.typeck_results().type_dependent_def_id(collect_expr.hir_id) && cx.tcx.is_diagnostic_item(sym::iterator_collect_fn, collect_def_id) { - check_into_iter(cx, left_expr, target_expr, parent_expr.span, &self.msrv); - check_iter(cx, left_expr, target_expr, parent_expr.span, &self.msrv); - check_to_owned(cx, left_expr, target_expr, parent_expr.span, &self.msrv); + check_into_iter(cx, left_expr, target_expr, expr.span, &self.msrv); + check_iter(cx, left_expr, target_expr, expr.span, &self.msrv); + check_to_owned(cx, left_expr, target_expr, expr.span, &self.msrv); } } diff --git a/src/tools/clippy/clippy_lints/src/manual_unwrap_or_default.rs b/src/tools/clippy/clippy_lints/src/manual_unwrap_or_default.rs new file mode 100644 index 00000000000..ddaf97c463a --- /dev/null +++ b/src/tools/clippy/clippy_lints/src/manual_unwrap_or_default.rs @@ -0,0 +1,181 @@ +use rustc_errors::Applicability; +use rustc_hir::def::Res; +use rustc_hir::{Arm, Expr, ExprKind, HirId, LangItem, MatchSource, Pat, PatKind, QPath}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_session::declare_lint_pass; +use rustc_span::sym; + +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::is_default_equivalent; +use clippy_utils::source::snippet_opt; +use clippy_utils::ty::implements_trait; + +declare_clippy_lint! { + /// ### What it does + /// Checks if a `match` or `if let` expression can be simplified using + /// `.unwrap_or_default()`. + /// + /// ### Why is this bad? + /// It can be done in one call with `.unwrap_or_default()`. + /// + /// ### Example + /// ```no_run + /// let x: Option<String> = Some(String::new()); + /// let y: String = match x { + /// Some(v) => v, + /// None => String::new(), + /// }; + /// + /// let x: Option<Vec<String>> = Some(Vec::new()); + /// let y: Vec<String> = if let Some(v) = x { + /// v + /// } else { + /// Vec::new() + /// }; + /// ``` + /// Use instead: + /// ```no_run + /// let x: Option<String> = Some(String::new()); + /// let y: String = x.unwrap_or_default(); + /// + /// let x: Option<Vec<String>> = Some(Vec::new()); + /// let y: Vec<String> = x.unwrap_or_default(); + /// ``` + #[clippy::version = "1.78.0"] + pub MANUAL_UNWRAP_OR_DEFAULT, + suspicious, + "check if a `match` or `if let` can be simplified with `unwrap_or_default`" +} + +declare_lint_pass!(ManualUnwrapOrDefault => [MANUAL_UNWRAP_OR_DEFAULT]); + +fn get_some<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'tcx>) -> Option<HirId> { + if let PatKind::TupleStruct(QPath::Resolved(_, path), &[pat], _) = pat.kind + && let Some(def_id) = path.res.opt_def_id() + // Since it comes from a pattern binding, we need to get the parent to actually match + // against it. + && let Some(def_id) = cx.tcx.opt_parent(def_id) + && cx.tcx.lang_items().get(LangItem::OptionSome) == Some(def_id) + { + let mut bindings = Vec::new(); + pat.each_binding(|_, id, _, _| bindings.push(id)); + if let &[id] = bindings.as_slice() { + Some(id) + } else { + None + } + } else { + None + } +} + +fn get_none<'tcx>(cx: &LateContext<'tcx>, arm: &Arm<'tcx>) -> Option<&'tcx Expr<'tcx>> { + if let PatKind::Path(QPath::Resolved(_, path)) = arm.pat.kind + && let Some(def_id) = path.res.opt_def_id() + // Since it comes from a pattern binding, we need to get the parent to actually match + // against it. + && let Some(def_id) = cx.tcx.opt_parent(def_id) + && cx.tcx.lang_items().get(LangItem::OptionNone) == Some(def_id) + { + Some(arm.body) + } else if let PatKind::Wild = arm.pat.kind { + // We consider that the `Some` check will filter it out if it's not right. + Some(arm.body) + } else { + None + } +} + +fn get_some_and_none_bodies<'tcx>( + cx: &LateContext<'tcx>, + arm1: &'tcx Arm<'tcx>, + arm2: &'tcx Arm<'tcx>, +) -> Option<((&'tcx Expr<'tcx>, HirId), &'tcx Expr<'tcx>)> { + if let Some(binding_id) = get_some(cx, arm1.pat) + && let Some(body_none) = get_none(cx, arm2) + { + Some(((arm1.body, binding_id), body_none)) + } else if let Some(binding_id) = get_some(cx, arm2.pat) + && let Some(body_none) = get_none(cx, arm1) + { + Some(((arm2.body, binding_id), body_none)) + } else { + None + } +} + +fn handle_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { + let ExprKind::Match(match_expr, [arm1, arm2], MatchSource::Normal | MatchSource::ForLoopDesugar) = expr.kind else { + return false; + }; + // We don't want conditions on the arms to simplify things. + if arm1.guard.is_none() + && arm2.guard.is_none() + // We check that the returned type implements the `Default` trait. + && let match_ty = cx.typeck_results().expr_ty(expr) + && let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default) + && implements_trait(cx, match_ty, default_trait_id, &[]) + // We now get the bodies for both the `Some` and `None` arms. + && let Some(((body_some, binding_id), body_none)) = get_some_and_none_bodies(cx, arm1, arm2) + // We check that the `Some(x) => x` doesn't do anything apart "returning" the value in `Some`. + && let ExprKind::Path(QPath::Resolved(_, path)) = body_some.peel_blocks().kind + && let Res::Local(local_id) = path.res + && local_id == binding_id + // We now check the `None` arm is calling a method equivalent to `Default::default`. + && let body_none = body_none.peel_blocks() + && is_default_equivalent(cx, body_none) + && let Some(match_expr_snippet) = snippet_opt(cx, match_expr.span) + { + span_lint_and_sugg( + cx, + MANUAL_UNWRAP_OR_DEFAULT, + expr.span, + "match can be simplified with `.unwrap_or_default()`", + "replace it with", + format!("{match_expr_snippet}.unwrap_or_default()"), + Applicability::MachineApplicable, + ); + } + true +} + +fn handle_if_let<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { + if let ExprKind::If(cond, if_block, Some(else_expr)) = expr.kind + && let ExprKind::Let(let_) = cond.kind + && let ExprKind::Block(_, _) = else_expr.kind + // We check that the returned type implements the `Default` trait. + && let match_ty = cx.typeck_results().expr_ty(expr) + && let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default) + && implements_trait(cx, match_ty, default_trait_id, &[]) + && let Some(binding_id) = get_some(cx, let_.pat) + // We check that the `Some(x) => x` doesn't do anything apart "returning" the value in `Some`. + && let ExprKind::Path(QPath::Resolved(_, path)) = if_block.peel_blocks().kind + && let Res::Local(local_id) = path.res + && local_id == binding_id + // We now check the `None` arm is calling a method equivalent to `Default::default`. + && let body_else = else_expr.peel_blocks() + && is_default_equivalent(cx, body_else) + && let Some(if_let_expr_snippet) = snippet_opt(cx, let_.init.span) + { + span_lint_and_sugg( + cx, + MANUAL_UNWRAP_OR_DEFAULT, + expr.span, + "if let can be simplified with `.unwrap_or_default()`", + "replace it with", + format!("{if_let_expr_snippet}.unwrap_or_default()"), + Applicability::MachineApplicable, + ); + } +} + +impl<'tcx> LateLintPass<'tcx> for ManualUnwrapOrDefault { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { + if expr.span.from_expansion() { + return; + } + if !handle_match(cx, expr) { + handle_if_let(cx, expr); + } + } +} diff --git a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs b/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs index c7c453b7f6e..cd61e733694 100644 --- a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs +++ b/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs @@ -243,7 +243,7 @@ impl<'a> NormalizedPat<'a> { fn from_pat(cx: &LateContext<'_>, arena: &'a DroplessArena, pat: &'a Pat<'_>) -> Self { match pat.kind { PatKind::Wild | PatKind::Binding(.., None) => Self::Wild, - PatKind::Binding(.., Some(pat)) | PatKind::Box(pat) | PatKind::Ref(pat, _) => { + PatKind::Binding(.., Some(pat)) | PatKind::Box(pat) | PatKind::Deref(pat) | PatKind::Ref(pat, _) => { Self::from_pat(cx, arena, pat) }, PatKind::Never => Self::Never, diff --git a/src/tools/clippy/clippy_lints/src/matches/single_match.rs b/src/tools/clippy/clippy_lints/src/matches/single_match.rs index 86c414dafcc..a0db8e2db1f 100644 --- a/src/tools/clippy/clippy_lints/src/matches/single_match.rs +++ b/src/tools/clippy/clippy_lints/src/matches/single_match.rs @@ -55,23 +55,15 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: }; let ty = cx.typeck_results().expr_ty(ex); - if *ty.kind() != ty::Bool || is_lint_allowed(cx, MATCH_BOOL, ex.hir_id) { - check_single_pattern(cx, ex, arms, expr, els); - check_opt_like(cx, ex, arms, expr, ty, els); + if (*ty.kind() != ty::Bool || is_lint_allowed(cx, MATCH_BOOL, ex.hir_id)) && + (check_single_pattern(arms) || check_opt_like(cx, arms, ty)) { + report_single_pattern(cx, ex, arms, expr, els); } } } -fn check_single_pattern( - cx: &LateContext<'_>, - ex: &Expr<'_>, - arms: &[Arm<'_>], - expr: &Expr<'_>, - els: Option<&Expr<'_>>, -) { - if is_wild(arms[1].pat) { - report_single_pattern(cx, ex, arms, expr, els); - } +fn check_single_pattern(arms: &[Arm<'_>]) -> bool { + is_wild(arms[1].pat) } fn report_single_pattern( @@ -140,19 +132,10 @@ fn report_single_pattern( span_lint_and_sugg(cx, lint, expr.span, msg, "try", sugg, app); } -fn check_opt_like<'a>( - cx: &LateContext<'a>, - ex: &Expr<'_>, - arms: &[Arm<'_>], - expr: &Expr<'_>, - ty: Ty<'a>, - els: Option<&Expr<'_>>, -) { +fn check_opt_like<'a>(cx: &LateContext<'a>, arms: &[Arm<'_>], ty: Ty<'a>) -> bool { // We don't want to lint if the second arm contains an enum which could // have more variants in the future. - if form_exhaustive_matches(cx, ty, arms[0].pat, arms[1].pat) { - report_single_pattern(cx, ex, arms, expr, els); - } + form_exhaustive_matches(cx, ty, arms[0].pat, arms[1].pat) } /// Returns `true` if all of the types in the pattern are enums which we know diff --git a/src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs b/src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs index e2c2997594a..4d8fb217f7f 100644 --- a/src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs +++ b/src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs @@ -91,7 +91,7 @@ pub(super) fn check<'tcx>( }, hir::ExprKind::Path(ref p) => matches!( cx.qpath_res(p, arg.hir_id), - hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static{..}, _) + hir::def::Res::Def(hir::def::DefKind::Const | hir::def::DefKind::Static { .. }, _) ), _ => false, } diff --git a/src/tools/clippy/clippy_lints/src/methods/is_empty.rs b/src/tools/clippy/clippy_lints/src/methods/is_empty.rs new file mode 100644 index 00000000000..7fe66062251 --- /dev/null +++ b/src/tools/clippy/clippy_lints/src/methods/is_empty.rs @@ -0,0 +1,49 @@ +use clippy_utils::consts::constant_is_empty; +use clippy_utils::diagnostics::span_lint; +use clippy_utils::{find_binding_init, path_to_local}; +use rustc_hir::{Expr, HirId}; +use rustc_lint::{LateContext, LintContext}; +use rustc_middle::lint::in_external_macro; +use rustc_span::sym; + +use super::CONST_IS_EMPTY; + +/// Expression whose initialization depend on a constant conditioned by a `#[cfg(…)]` directive will +/// not trigger the lint. +pub(super) fn check(cx: &LateContext<'_>, expr: &'_ Expr<'_>, receiver: &Expr<'_>) { + if in_external_macro(cx.sess(), expr.span) || !receiver.span.eq_ctxt(expr.span) { + return; + } + let init_expr = expr_or_init(cx, receiver); + if !receiver.span.eq_ctxt(init_expr.span) { + return; + } + if let Some(init_is_empty) = constant_is_empty(cx, init_expr) { + span_lint( + cx, + CONST_IS_EMPTY, + expr.span, + &format!("this expression always evaluates to {init_is_empty:?}"), + ); + } +} + +fn is_under_cfg(cx: &LateContext<'_>, id: HirId) -> bool { + cx.tcx + .hir() + .parent_id_iter(id) + .any(|id| cx.tcx.hir().attrs(id).iter().any(|attr| attr.has_name(sym::cfg))) +} + +/// Similar to [`clippy_utils::expr_or_init`], but does not go up the chain if the initialization +/// value depends on a `#[cfg(…)]` directive. +fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr<'b>) -> &'a Expr<'b> { + while let Some(init) = path_to_local(expr) + .and_then(|id| find_binding_init(cx, id)) + .filter(|init| cx.typeck_results().expr_adjustments(init).is_empty()) + .filter(|init| !is_under_cfg(cx, init.hir_id)) + { + expr = init; + } + expr +} diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_nth.rs b/src/tools/clippy/clippy_lints/src/methods/iter_nth.rs index 12104310405..5b0b70b4b96 100644 --- a/src/tools/clippy/clippy_lints/src/methods/iter_nth.rs +++ b/src/tools/clippy/clippy_lints/src/methods/iter_nth.rs @@ -1,10 +1,10 @@ -use super::utils::derefs_to_slice; -use crate::methods::iter_nth_zero; -use clippy_utils::diagnostics::span_lint_and_help; -use clippy_utils::ty::is_type_diagnostic_item; +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::ty::get_type_diagnostic_name; +use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_span::symbol::sym; +use rustc_span::Span; use super::ITER_NTH; @@ -12,28 +12,33 @@ pub(super) fn check<'tcx>( cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, iter_recv: &'tcx hir::Expr<'tcx>, - nth_recv: &hir::Expr<'_>, - nth_arg: &hir::Expr<'_>, - is_mut: bool, -) { - let mut_str = if is_mut { "_mut" } else { "" }; - let caller_type = if derefs_to_slice(cx, iter_recv, cx.typeck_results().expr_ty(iter_recv)).is_some() { - "slice" - } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(iter_recv), sym::Vec) { - "`Vec`" - } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(iter_recv), sym::VecDeque) { - "`VecDeque`" - } else { - iter_nth_zero::check(cx, expr, nth_recv, nth_arg); - return; // caller is not a type that we want to lint + iter_method: &str, + iter_span: Span, + nth_span: Span, +) -> bool { + let caller_type = match get_type_diagnostic_name(cx, cx.typeck_results().expr_ty(iter_recv).peel_refs()) { + Some(sym::Vec) => "`Vec`", + Some(sym::VecDeque) => "`VecDeque`", + _ if cx.typeck_results().expr_ty_adjusted(iter_recv).peel_refs().is_slice() => "slice", + // caller is not a type that we want to lint + _ => return false, }; - span_lint_and_help( + span_lint_and_then( cx, ITER_NTH, expr.span, - &format!("called `.iter{mut_str}().nth()` on a {caller_type}"), - None, - &format!("calling `.get{mut_str}()` is both faster and more readable"), + &format!("called `.{iter_method}().nth()` on a {caller_type}"), + |diag| { + let get_method = if iter_method == "iter_mut" { "get_mut" } else { "get" }; + diag.span_suggestion_verbose( + iter_span.to(nth_span), + format!("`{get_method}` is equivalent but more concise"), + get_method, + Applicability::MachineApplicable, + ); + }, ); + + true } diff --git a/src/tools/clippy/clippy_lints/src/methods/map_clone.rs b/src/tools/clippy/clippy_lints/src/methods/map_clone.rs index 27e17b43b01..c3c7a3a0033 100644 --- a/src/tools/clippy/clippy_lints/src/methods/map_clone.rs +++ b/src/tools/clippy/clippy_lints/src/methods/map_clone.rs @@ -86,8 +86,11 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_ } } }, - hir::ExprKind::Call(call, [_]) => { - if let hir::ExprKind::Path(qpath) = call.kind { + hir::ExprKind::Call(call, args) => { + if let hir::ExprKind::Path(qpath) = call.kind + && let [arg] = args + && ident_eq(name, arg) + { handle_path(cx, call, &qpath, e, recv); } }, @@ -118,7 +121,9 @@ fn handle_path( if let ty::Adt(_, args) = cx.typeck_results().expr_ty(recv).kind() && let args = args.as_slice() && let Some(ty) = args.iter().find_map(|generic_arg| generic_arg.as_type()) - && ty.is_ref() + && let ty::Ref(_, ty, Mutability::Not) = ty.kind() + && let ty::FnDef(_, lst) = cx.typeck_results().expr_ty(arg).kind() + && lst.iter().all(|l| l.as_type() == Some(*ty)) { lint_path(cx, e.span, recv.span, is_copy(cx, ty.peel_refs())); } diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index 8a24ccea3a1..b6c474212cd 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -36,6 +36,7 @@ mod inefficient_to_string; mod inspect_for_each; mod into_iter_on_ref; mod is_digit_ascii_radix; +mod is_empty; mod iter_cloned_collect; mod iter_count; mod iter_filter; @@ -118,6 +119,7 @@ mod unnecessary_literal_unwrap; mod unnecessary_result_map_or_else; mod unnecessary_sort_by; mod unnecessary_to_owned; +mod unused_enumerate_index; mod unwrap_expect_used; mod useless_asref; mod utils; @@ -1235,12 +1237,11 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for usage of `.iter().nth()` (and the related - /// `.iter_mut().nth()`) on standard library types with *O*(1) element access. + /// Checks for usage of `.iter().nth()`/`.iter_mut().nth()` on standard library types that have + /// equivalent `.get()`/`.get_mut()` methods. /// /// ### Why is this bad? - /// `.get()` and `.get_mut()` are more efficient and more - /// readable. + /// `.get()` and `.get_mut()` are equivalent but more concise. /// /// ### Example /// ```no_run @@ -1256,7 +1257,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "pre 1.29.0"] pub ITER_NTH, - perf, + style, "using `.iter().nth()` on a standard library type with O(1) element access" } @@ -2848,7 +2849,7 @@ declare_clippy_lint! { /// the file is created from scratch, or ensure `truncate` is /// called so that the truncation behaviour is explicit. `truncate(true)` /// will ensure the file is entirely overwritten with new data, whereas - /// `truncate(false)` will explicitely keep the default behavior. + /// `truncate(false)` will explicitly keep the default behavior. /// /// ### Example /// ```rust,no_run @@ -2862,7 +2863,7 @@ declare_clippy_lint! { /// /// OpenOptions::new().create(true).truncate(true); /// ``` - #[clippy::version = "1.75.0"] + #[clippy::version = "1.77.0"] pub SUSPICIOUS_OPEN_OPTIONS, suspicious, "suspicious combination of options for opening a file" @@ -3182,8 +3183,8 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does /// - /// Checks an argument of `seek` method of `Seek` trait - /// and if it start seek from `SeekFrom::Current(0)`, suggests `stream_position` instead. + /// Checks if the `seek` method of the `Seek` trait is called with `SeekFrom::Current(0)`, + /// and if it is, suggests using `stream_position` instead. /// /// ### Why is this bad? /// @@ -3590,7 +3591,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.73.0"] pub READONLY_WRITE_LOCK, - nursery, + perf, "acquiring a write lock when a read lock would work" } @@ -3816,7 +3817,7 @@ declare_clippy_lint! { /// ```no_run /// let _ = std::iter::empty::<Result<i32, ()>>().flatten(); /// ``` - #[clippy::version = "1.76.0"] + #[clippy::version = "1.77.0"] pub RESULT_FILTER_MAP, complexity, "filtering `Result` for `Ok` then force-unwrapping, which can be one type-safe operation" @@ -3825,7 +3826,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does /// Checks for usage of `.filter(Option::is_some)` that may be replaced with a `.flatten()` call. - /// This lint will require additional changes to the follow-up calls as it appects the type. + /// This lint will require additional changes to the follow-up calls as it affects the type. /// /// ### Why is this bad? /// This pattern is often followed by manual unwrapping of the `Option`. The simplification @@ -3842,7 +3843,7 @@ declare_clippy_lint! { /// // example code which does not raise clippy warning /// vec![Some(1)].into_iter().flatten(); /// ``` - #[clippy::version = "1.76.0"] + #[clippy::version = "1.77.0"] pub ITER_FILTER_IS_SOME, pedantic, "filtering an iterator over `Option`s for `Some` can be achieved with `flatten`" @@ -3851,7 +3852,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does /// Checks for usage of `.filter(Result::is_ok)` that may be replaced with a `.flatten()` call. - /// This lint will require additional changes to the follow-up calls as it appects the type. + /// This lint will require additional changes to the follow-up calls as it affects the type. /// /// ### Why is this bad? /// This pattern is often followed by manual unwrapping of `Result`. The simplification @@ -3868,7 +3869,7 @@ declare_clippy_lint! { /// // example code which does not raise clippy warning /// vec![Ok::<i32, String>(1)].into_iter().flatten(); /// ``` - #[clippy::version = "1.76.0"] + #[clippy::version = "1.77.0"] pub ITER_FILTER_IS_OK, pedantic, "filtering an iterator over `Result`s for `Ok` can be achieved with `flatten`" @@ -3895,7 +3896,7 @@ declare_clippy_lint! { /// option.is_some_and(|a| a > 10); /// result.is_ok_and(|a| a > 10); /// ``` - #[clippy::version = "1.76.0"] + #[clippy::version = "1.77.0"] pub MANUAL_IS_VARIANT_AND, pedantic, "using `.map(f).unwrap_or_default()`, which is more succinctly expressed as `is_some_and(f)` or `is_ok_and(f)`" @@ -3925,7 +3926,7 @@ declare_clippy_lint! { /// `"\r\n"`), for example during the parsing of a specific file format in which precisely one newline type is /// valid. /// ``` - #[clippy::version = "1.76.0"] + #[clippy::version = "1.77.0"] pub STR_SPLIT_AT_NEWLINE, pedantic, "splitting a trimmed string at hard-coded newlines" @@ -4044,6 +4045,31 @@ declare_clippy_lint! { "calling `.get().is_some()` or `.get().is_none()` instead of `.contains()` or `.contains_key()`" } +declare_clippy_lint! { + /// ### What it does + /// It identifies calls to `.is_empty()` on constant values. + /// + /// ### Why is this bad? + /// String literals and constant values are known at compile time. Checking if they + /// are empty will always return the same value. This might not be the intention of + /// the expression. + /// + /// ### Example + /// ```no_run + /// let value = ""; + /// if value.is_empty() { + /// println!("the string is empty"); + /// } + /// ``` + /// Use instead: + /// ```no_run + /// println!("the string is empty"); + /// ``` + #[clippy::version = "1.78.0"] + pub CONST_IS_EMPTY, + suspicious, + "is_empty() called on strings known at compile time" +} pub struct Methods { avoid_breaking_exported_api: bool, msrv: Msrv, @@ -4092,6 +4118,7 @@ impl_lint_pass!(Methods => [ CLONE_ON_COPY, CLONE_ON_REF_PTR, COLLAPSIBLE_STR_REPLACE, + CONST_IS_EMPTY, ITER_OVEREAGER_CLONED, CLONED_INSTEAD_OF_COPIED, FLAT_MAP_OPTION, @@ -4403,6 +4430,7 @@ impl Methods { zst_offset::check(cx, expr, recv); }, ("all", [arg]) => { + unused_enumerate_index::check(cx, expr, recv, arg); if let Some(("cloned", recv2, [], _, _)) = method_call(recv) { iter_overeager_cloned::check( cx, @@ -4421,23 +4449,26 @@ impl Methods { unnecessary_lazy_eval::check(cx, expr, recv, arg, "and"); } }, - ("any", [arg]) => match method_call(recv) { - Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check( - cx, - expr, - recv, - recv2, - iter_overeager_cloned::Op::NeedlessMove(arg), - false, - ), - Some(("chars", recv, _, _, _)) - if let ExprKind::Closure(arg) = arg.kind - && let body = cx.tcx.hir().body(arg.body) - && let [param] = body.params => - { - string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(body.value), &self.msrv); - }, - _ => {}, + ("any", [arg]) => { + unused_enumerate_index::check(cx, expr, recv, arg); + match method_call(recv) { + Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check( + cx, + expr, + recv, + recv2, + iter_overeager_cloned::Op::NeedlessMove(arg), + false, + ), + Some(("chars", recv, _, _, _)) + if let ExprKind::Closure(arg) = arg.kind + && let body = cx.tcx.hir().body(arg.body) + && let [param] = body.params => + { + string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(body.value), &self.msrv); + }, + _ => {}, + } }, ("arg", [arg]) => { suspicious_command_arg_space::check(cx, recv, arg, span); @@ -4445,7 +4476,7 @@ impl Methods { ("as_deref" | "as_deref_mut", []) => { needless_option_as_deref::check(cx, expr, recv, name); }, - ("as_bytes" | "is_empty", []) => { + ("as_bytes", []) => { if let Some(("as_str", recv, [], as_str_span, _)) = method_call(recv) { redundant_as_str::check(cx, expr, recv, as_str_span, span); } @@ -4570,14 +4601,17 @@ impl Methods { } }, ("filter_map", [arg]) => { + unused_enumerate_index::check(cx, expr, recv, arg); unnecessary_filter_map::check(cx, expr, arg, name); filter_map_bool_then::check(cx, expr, arg, call_span); filter_map_identity::check(cx, expr, arg, span); }, ("find_map", [arg]) => { + unused_enumerate_index::check(cx, expr, recv, arg); unnecessary_filter_map::check(cx, expr, arg, name); }, ("flat_map", [arg]) => { + unused_enumerate_index::check(cx, expr, recv, arg); flat_map_identity::check(cx, expr, arg, span); flat_map_option::check(cx, expr, arg, span); }, @@ -4599,17 +4633,20 @@ impl Methods { manual_try_fold::check(cx, expr, init, acc, call_span, &self.msrv); unnecessary_fold::check(cx, expr, init, acc, span); }, - ("for_each", [arg]) => match method_call(recv) { - Some(("inspect", _, [_], span2, _)) => inspect_for_each::check(cx, expr, span2), - Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check( - cx, - expr, - recv, - recv2, - iter_overeager_cloned::Op::NeedlessMove(arg), - false, - ), - _ => {}, + ("for_each", [arg]) => { + unused_enumerate_index::check(cx, expr, recv, arg); + match method_call(recv) { + Some(("inspect", _, [_], span2, _)) => inspect_for_each::check(cx, expr, span2), + Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check( + cx, + expr, + recv, + recv2, + iter_overeager_cloned::Op::NeedlessMove(arg), + false, + ), + _ => {}, + } }, ("get", [arg]) => { get_first::check(cx, expr, recv, arg); @@ -4619,6 +4656,12 @@ impl Methods { ("hash", [arg]) => { unit_hash::check(cx, expr, recv, arg); }, + ("is_empty", []) => { + if let Some(("as_str", recv, [], as_str_span, _)) = method_call(recv) { + redundant_as_str::check(cx, expr, recv, as_str_span, span); + } + is_empty::check(cx, expr, recv); + }, ("is_file", []) => filetype_is_file::check(cx, expr, recv), ("is_digit", [radix]) => is_digit_ascii_radix::check(cx, expr, recv, radix, &self.msrv), ("is_none", []) => check_is_some_is_none(cx, expr, recv, call_span, false), @@ -4650,6 +4693,7 @@ impl Methods { }, (name @ ("map" | "map_err"), [m_arg]) => { if name == "map" { + unused_enumerate_index::check(cx, expr, recv, m_arg); map_clone::check(cx, expr, recv, m_arg, &self.msrv); match method_call(recv) { Some((map_name @ ("iter" | "into_iter"), recv2, _, _, _)) => { @@ -4723,8 +4767,11 @@ impl Methods { iter_overeager_cloned::Op::LaterCloned, false, ), - Some(("iter", recv2, [], _, _)) => iter_nth::check(cx, expr, recv2, recv, n_arg, false), - Some(("iter_mut", recv2, [], _, _)) => iter_nth::check(cx, expr, recv2, recv, n_arg, true), + Some((iter_method @ ("iter" | "iter_mut"), iter_recv, [], iter_span, _)) => { + if !iter_nth::check(cx, expr, iter_recv, iter_method, iter_span, span) { + iter_nth_zero::check(cx, expr, recv, n_arg); + } + }, _ => iter_nth_zero::check(cx, expr, recv, n_arg), }, ("ok_or_else", [arg]) => unnecessary_lazy_eval::check(cx, expr, recv, arg, "ok_or"), diff --git a/src/tools/clippy/clippy_lints/src/methods/no_effect_replace.rs b/src/tools/clippy/clippy_lints/src/methods/no_effect_replace.rs index 81df32bdee2..a301a5f7d65 100644 --- a/src/tools/clippy/clippy_lints/src/methods/no_effect_replace.rs +++ b/src/tools/clippy/clippy_lints/src/methods/no_effect_replace.rs @@ -25,6 +25,7 @@ pub(super) fn check<'tcx>( && param1 == param2.as_str() { span_lint(cx, NO_EFFECT_REPLACE, expr.span, "replacing text with itself"); + return; } if SpanlessEq::new(cx).eq_expr(arg1, arg2) { diff --git a/src/tools/clippy/clippy_lints/src/methods/unused_enumerate_index.rs b/src/tools/clippy/clippy_lints/src/methods/unused_enumerate_index.rs new file mode 100644 index 00000000000..e5cc898612e --- /dev/null +++ b/src/tools/clippy/clippy_lints/src/methods/unused_enumerate_index.rs @@ -0,0 +1,135 @@ +use clippy_utils::diagnostics::{multispan_sugg_with_applicability, span_lint_hir_and_then}; +use clippy_utils::paths::{CORE_ITER_ENUMERATE_METHOD, CORE_ITER_ENUMERATE_STRUCT}; +use clippy_utils::source::{snippet, snippet_opt}; +use clippy_utils::{expr_or_init, is_trait_method, match_def_path, pat_is_wild}; +use rustc_errors::Applicability; +use rustc_hir::{Expr, ExprKind, FnDecl, PatKind, TyKind}; +use rustc_lint::LateContext; +use rustc_middle::ty::AdtDef; +use rustc_span::{sym, Span}; + +use crate::loops::UNUSED_ENUMERATE_INDEX; + +/// Check for the `UNUSED_ENUMERATE_INDEX` lint outside of loops. +/// +/// The lint is declared in `clippy_lints/src/loops/mod.rs`. There, the following pattern is +/// checked: +/// ```ignore +/// for (_, x) in some_iter.enumerate() { +/// // Index is ignored +/// } +/// ``` +/// +/// This `check` function checks for chained method calls constructs where we can detect that the +/// index is unused. Currently, this checks only for the following patterns: +/// ```ignore +/// some_iter.enumerate().map_function(|(_, x)| ..) +/// let x = some_iter.enumerate(); +/// x.map_function(|(_, x)| ..) +/// ``` +/// where `map_function` is one of `all`, `any`, `filter_map`, `find_map`, `flat_map`, `for_each` or +/// `map`. +/// +/// # Preconditions +/// This function must be called not on the `enumerate` call expression itself, but on any of the +/// map functions listed above. It will ensure that `recv` is a `std::iter::Enumerate` instance and +/// that the method call is one of the `std::iter::Iterator` trait. +/// +/// * `call_expr`: The map function call expression +/// * `recv`: The receiver of the call +/// * `closure_arg`: The argument to the map function call containing the closure/function to apply +pub(super) fn check(cx: &LateContext<'_>, call_expr: &Expr<'_>, recv: &Expr<'_>, closure_arg: &Expr<'_>) { + let recv_ty = cx.typeck_results().expr_ty(recv); + if let Some(recv_ty_defid) = recv_ty.ty_adt_def().map(AdtDef::did) + // If we call a method on a `std::iter::Enumerate` instance + && match_def_path(cx, recv_ty_defid, &CORE_ITER_ENUMERATE_STRUCT) + // If we are calling a method of the `Iterator` trait + && is_trait_method(cx, call_expr, sym::Iterator) + // And the map argument is a closure + && let ExprKind::Closure(closure) = closure_arg.kind + && let closure_body = cx.tcx.hir().body(closure.body) + // And that closure has one argument ... + && let [closure_param] = closure_body.params + // .. which is a tuple of 2 elements + && let PatKind::Tuple([index, elem], ..) = closure_param.pat.kind + // And that the first element (the index) is either `_` or unused in the body + && pat_is_wild(cx, &index.kind, closure_body) + // Try to find the initializer for `recv`. This is needed in case `recv` is a local_binding. In the + // first example below, `expr_or_init` would return `recv`. + // ``` + // iter.enumerate().map(|(_, x)| x) + // ^^^^^^^^^^^^^^^^ `recv`, a call to `std::iter::Iterator::enumerate` + // + // let binding = iter.enumerate(); + // ^^^^^^^^^^^^^^^^ `recv_init_expr` + // binding.map(|(_, x)| x) + // ^^^^^^^ `recv`, not a call to `std::iter::Iterator::enumerate` + // ``` + && let recv_init_expr = expr_or_init(cx, recv) + // Make sure the initializer is a method call. It may be that the `Enumerate` comes from something + // that we cannot control. + // This would for instance happen with: + // ``` + // external_lib::some_function_returning_enumerate().map(|(_, x)| x) + // ``` + && let ExprKind::MethodCall(_, enumerate_recv, _, enumerate_span) = recv_init_expr.kind + && let Some(enumerate_defid) = cx.typeck_results().type_dependent_def_id(recv_init_expr.hir_id) + // Make sure the method call is `std::iter::Iterator::enumerate`. + && match_def_path(cx, enumerate_defid, &CORE_ITER_ENUMERATE_METHOD) + { + // Check if the tuple type was explicit. It may be the type system _needs_ the type of the element + // that would be explicited in the closure. + let new_closure_param = match find_elem_explicit_type_span(closure.fn_decl) { + // We have an explicit type. Get its snippet, that of the binding name, and do `binding: ty`. + // Fallback to `..` if we fail getting either snippet. + Some(ty_span) => snippet_opt(cx, elem.span) + .and_then(|binding_name| snippet_opt(cx, ty_span).map(|ty_name| format!("{binding_name}: {ty_name}"))) + .unwrap_or_else(|| "..".to_string()), + // Otherwise, we have no explicit type. We can replace with the binding name of the element. + None => snippet(cx, elem.span, "..").into_owned(), + }; + + // Suggest removing the tuple from the closure and the preceding call to `enumerate`, whose span we + // can get from the `MethodCall`. + span_lint_hir_and_then( + cx, + UNUSED_ENUMERATE_INDEX, + recv_init_expr.hir_id, + enumerate_span, + "you seem to use `.enumerate()` and immediately discard the index", + |diag| { + multispan_sugg_with_applicability( + diag, + "remove the `.enumerate()` call", + Applicability::MachineApplicable, + vec![ + (closure_param.span, new_closure_param), + ( + enumerate_span.with_lo(enumerate_recv.span.source_callsite().hi()), + String::new(), + ), + ], + ); + }, + ); + } +} + +/// Find the span of the explicit type of the element. +/// +/// # Returns +/// If the tuple argument: +/// * Has no explicit type, returns `None` +/// * Has an explicit tuple type with an implicit element type (`(usize, _)`), returns `None` +/// * Has an explicit tuple type with an explicit element type (`(_, i32)`), returns the span for +/// the element type. +fn find_elem_explicit_type_span(fn_decl: &FnDecl<'_>) -> Option<Span> { + if let [tuple_ty] = fn_decl.inputs + && let TyKind::Tup([_idx_ty, elem_ty]) = tuple_ty.kind + && !matches!(elem_ty.kind, TyKind::Err(..) | TyKind::Infer) + { + Some(elem_ty.span) + } else { + None + } +} diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index bf4af7946f4..6878fb3349d 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -8,6 +8,7 @@ use clippy_utils::attrs::is_doc_hidden; use clippy_utils::diagnostics::span_lint; use clippy_utils::is_from_proc_macro; +use clippy_utils::source::snippet_opt; use rustc_ast::ast::{self, MetaItem, MetaItemKind}; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; @@ -32,6 +33,13 @@ declare_clippy_lint! { "detects missing documentation for private members" } +macro_rules! note_prev_span_then_ret { + ($prev_span:expr, $span:expr) => {{ + $prev_span = Some($span); + return; + }}; +} + pub struct MissingDoc { /// Whether to **only** check for missing documentation in items visible within the current /// crate. For example, `pub(crate)` items. @@ -39,6 +47,8 @@ pub struct MissingDoc { /// Stack of whether #[doc(hidden)] is set /// at each level which has lint attributes. doc_hidden_stack: Vec<bool>, + /// Used to keep tracking of the previous item, field or variants etc, to get the search span. + prev_span: Option<Span>, } impl Default for MissingDoc { @@ -54,6 +64,7 @@ impl MissingDoc { Self { crate_items_only, doc_hidden_stack: vec![false], + prev_span: None, } } @@ -108,7 +119,8 @@ impl MissingDoc { let has_doc = attrs .iter() - .any(|a| a.doc_str().is_some() || Self::has_include(a.meta())); + .any(|a| a.doc_str().is_some() || Self::has_include(a.meta())) + || matches!(self.search_span(sp), Some(span) if span_to_snippet_contains_docs(cx, span)); if !has_doc { span_lint( @@ -119,6 +131,32 @@ impl MissingDoc { ); } } + + /// Return a span to search for doc comments manually. + /// + /// # Example + /// ```ignore + /// fn foo() { ... } + /// ^^^^^^^^^^^^^^^^ prev_span + /// ↑ + /// | search_span | + /// ↓ + /// fn bar() { ... } + /// ^^^^^^^^^^^^^^^^ cur_span + /// ``` + fn search_span(&self, cur_span: Span) -> Option<Span> { + let prev_span = self.prev_span?; + let start_pos = if prev_span.contains(cur_span) { + // In case when the prev_span is an entire struct, or enum, + // and the current span is a field, or variant, we need to search from + // the starting pos of the previous span. + prev_span.lo() + } else { + prev_span.hi() + }; + let search_span = cur_span.with_lo(start_pos).with_hi(cur_span.lo()); + Some(search_span) + } } impl_lint_pass!(MissingDoc => [MISSING_DOCS_IN_PRIVATE_ITEMS]); @@ -138,6 +176,10 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { self.check_missing_docs_attrs(cx, CRATE_DEF_ID, attrs, cx.tcx.def_span(CRATE_DEF_ID), "the", "crate"); } + fn check_crate_post(&mut self, _: &LateContext<'tcx>) { + self.prev_span = None; + } + fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) { match it.kind { hir::ItemKind::Fn(..) => { @@ -145,7 +187,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { if it.ident.name == sym::main { let at_root = cx.tcx.local_parent(it.owner_id.def_id) == CRATE_DEF_ID; if at_root { - return; + note_prev_span_then_ret!(self.prev_span, it.span); } } }, @@ -164,7 +206,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::GlobalAsm(..) | hir::ItemKind::Impl { .. } - | hir::ItemKind::Use(..) => return, + | hir::ItemKind::Use(..) => note_prev_span_then_ret!(self.prev_span, it.span), }; let (article, desc) = cx.tcx.article_and_description(it.owner_id.to_def_id()); @@ -173,6 +215,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { if !is_from_proc_macro(cx, it) { self.check_missing_docs_attrs(cx, it.owner_id.def_id, attrs, it.span, article, desc); } + self.prev_span = Some(it.span); } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) { @@ -182,16 +225,17 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { if !is_from_proc_macro(cx, trait_item) { self.check_missing_docs_attrs(cx, trait_item.owner_id.def_id, attrs, trait_item.span, article, desc); } + self.prev_span = Some(trait_item.span); } fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { // If the method is an impl for a trait, don't doc. if let Some(cid) = cx.tcx.associated_item(impl_item.owner_id).impl_container(cx.tcx) { if cx.tcx.impl_trait_ref(cid).is_some() { - return; + note_prev_span_then_ret!(self.prev_span, impl_item.span); } } else { - return; + note_prev_span_then_ret!(self.prev_span, impl_item.span); } let (article, desc) = cx.tcx.article_and_description(impl_item.owner_id.to_def_id()); @@ -199,6 +243,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { if !is_from_proc_macro(cx, impl_item) { self.check_missing_docs_attrs(cx, impl_item.owner_id.def_id, attrs, impl_item.span, article, desc); } + self.prev_span = Some(impl_item.span); } fn check_field_def(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::FieldDef<'_>) { @@ -208,6 +253,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { self.check_missing_docs_attrs(cx, sf.def_id, attrs, sf.span, "a", "struct field"); } } + self.prev_span = Some(sf.span); } fn check_variant(&mut self, cx: &LateContext<'tcx>, v: &'tcx hir::Variant<'_>) { @@ -215,5 +261,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { if !is_from_proc_macro(cx, v) { self.check_missing_docs_attrs(cx, v.def_id, attrs, v.span, "a", "variant"); } + self.prev_span = Some(v.span); } } + +fn span_to_snippet_contains_docs(cx: &LateContext<'_>, search_span: Span) -> bool { + let Some(snippet) = snippet_opt(cx, search_span) else { + return false; + }; + snippet.lines().rev().any(|line| line.trim().starts_with("///")) +} diff --git a/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs index 70fd07cd93c..648d780ac09 100644 --- a/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs +++ b/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs @@ -109,7 +109,14 @@ fn collect_unsafe_exprs<'tcx>( ExprKind::Path(QPath::Resolved( _, hir::Path { - res: Res::Def(DefKind::Static{mutability:Mutability::Mut, ..}, _), + res: + Res::Def( + DefKind::Static { + mutability: Mutability::Mut, + .. + }, + _, + ), .. }, )) => { @@ -149,7 +156,13 @@ fn collect_unsafe_exprs<'tcx>( ExprKind::Path(QPath::Resolved( _, hir::Path { - res: Res::Def(DefKind::Static{mutability:Mutability::Mut, ..}, _), + res: Res::Def( + DefKind::Static { + mutability: Mutability::Mut, + .. + }, + _ + ), .. } )) diff --git a/src/tools/clippy/clippy_lints/src/mut_mut.rs b/src/tools/clippy/clippy_lints/src/mut_mut.rs index 72a2cca1e40..bc7b2c6b7c1 100644 --- a/src/tools/clippy/clippy_lints/src/mut_mut.rs +++ b/src/tools/clippy/clippy_lints/src/mut_mut.rs @@ -1,4 +1,4 @@ -use clippy_utils::diagnostics::span_lint; +use clippy_utils::diagnostics::{span_lint, span_lint_hir}; use clippy_utils::higher; use rustc_hir as hir; use rustc_hir::intravisit; @@ -35,9 +35,34 @@ impl<'tcx> LateLintPass<'tcx> for MutMut { } fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'_>) { - use rustc_hir::intravisit::Visitor; + if in_external_macro(cx.sess(), ty.span) { + return; + } - MutVisitor { cx }.visit_ty(ty); + if let hir::TyKind::Ref( + _, + hir::MutTy { + ty: pty, + mutbl: hir::Mutability::Mut, + }, + ) = ty.kind + { + if let hir::TyKind::Ref( + _, + hir::MutTy { + mutbl: hir::Mutability::Mut, + .. + }, + ) = pty.kind + { + span_lint( + cx, + MUT_MUT, + ty.span, + "generally you want to avoid `&mut &mut _` if possible", + ); + } + } } } @@ -62,17 +87,19 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { intravisit::walk_expr(self, body); } else if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, e) = expr.kind { if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, _) = e.kind { - span_lint( + span_lint_hir( self.cx, MUT_MUT, + expr.hir_id, expr.span, "generally you want to avoid `&mut &mut _` if possible", ); } else if let ty::Ref(_, ty, hir::Mutability::Mut) = self.cx.typeck_results().expr_ty(e).kind() { if ty.peel_refs().is_sized(self.cx.tcx, self.cx.param_env) { - span_lint( + span_lint_hir( self.cx, MUT_MUT, + expr.hir_id, expr.span, "this expression mutably borrows a mutable reference. Consider reborrowing", ); @@ -80,37 +107,4 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { } } } - - fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) { - if in_external_macro(self.cx.sess(), ty.span) { - return; - } - - if let hir::TyKind::Ref( - _, - hir::MutTy { - ty: pty, - mutbl: hir::Mutability::Mut, - }, - ) = ty.kind - { - if let hir::TyKind::Ref( - _, - hir::MutTy { - mutbl: hir::Mutability::Mut, - .. - }, - ) = pty.kind - { - span_lint( - self.cx, - MUT_MUT, - ty.span, - "generally you want to avoid `&mut &mut _` if possible", - ); - } - } - - intravisit::walk_ty(self, ty); - } } diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs index a450dee3050..30d3e86dc4e 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -13,7 +13,6 @@ use rustc_hir::{ use rustc_hir_typeck::expr_use_visitor as euv; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::hir::map::associated_body; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::{self, Ty, TyCtxt, UpvarId, UpvarPath}; use rustc_session::impl_lint_pass; @@ -112,7 +111,10 @@ fn check_closures<'tcx>( } ctx.prev_bind = None; ctx.prev_move_to_closure.clear(); - if let Some(body) = associated_body(cx.tcx.hir_node_by_def_id(closure)) + if let Some(body) = cx + .tcx + .hir_node_by_def_id(closure) + .associated_body() .map(|(_, body_id)| hir.body(body_id)) { euv::ExprUseVisitor::new(ctx, infcx, closure, cx.param_env, cx.typeck_results()).consume_body(body); diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index ea73d9afa2e..6cb84bb78b6 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -290,14 +290,21 @@ impl NonCopyConst { promoted: None, }; let param_env = cx.tcx.param_env(def_id).with_reveal_all_normalized(cx.tcx); - let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, None); + let result = cx + .tcx + .const_eval_global_id_for_typeck(param_env, cid, rustc_span::DUMMY_SP); self.is_value_unfrozen_raw(cx, result, ty) } fn is_value_unfrozen_expr<'tcx>(&self, cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool { let args = cx.typeck_results().node_args(hir_id); - let result = Self::const_eval_resolve(cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, args), None); + let result = Self::const_eval_resolve( + cx.tcx, + cx.param_env, + ty::UnevaluatedConst::new(def_id, args), + rustc_span::DUMMY_SP, + ); self.is_value_unfrozen_raw(cx, result, ty) } @@ -305,7 +312,7 @@ impl NonCopyConst { tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, ct: ty::UnevaluatedConst<'tcx>, - span: Option<Span>, + span: Span, ) -> EvalToValTreeResult<'tcx> { match ty::Instance::resolve(tcx, param_env, ct.def, ct.args) { Ok(Some(instance)) => { @@ -315,8 +322,8 @@ impl NonCopyConst { }; tcx.const_eval_global_id_for_typeck(param_env, cid, span) }, - Ok(None) => Err(ErrorHandled::TooGeneric(span.unwrap_or(rustc_span::DUMMY_SP))), - Err(err) => Err(ErrorHandled::Reported(err.into(), span.unwrap_or(rustc_span::DUMMY_SP))), + Ok(None) => Err(ErrorHandled::TooGeneric(span)), + Err(err) => Err(ErrorHandled::Reported(err.into(), span)), } } } diff --git a/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs b/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs index fbca4329342..127801de7de 100644 --- a/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs +++ b/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_help; -use rustc_hir::{intravisit, Body, Expr, ExprKind, FnDecl, Let, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind}; +use rustc_hir::{intravisit, Body, Expr, ExprKind, FnDecl, LetExpr, LocalSource, Mutability, Pat, PatKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty; @@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for PatternTypeMismatch { } } } - if let ExprKind::Let(Let { pat, .. }) = expr.kind { + if let ExprKind::Let(LetExpr { pat, .. }) = expr.kind { apply_lint(cx, pat, DerefPossible::Possible); } } diff --git a/src/tools/clippy/clippy_lints/src/read_zero_byte_vec.rs b/src/tools/clippy/clippy_lints/src/read_zero_byte_vec.rs index d0b37cd92e0..0ebdb031d5a 100644 --- a/src/tools/clippy/clippy_lints/src/read_zero_byte_vec.rs +++ b/src/tools/clippy/clippy_lints/src/read_zero_byte_vec.rs @@ -1,4 +1,4 @@ -use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg}; +use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then}; use clippy_utils::get_enclosing_block; use clippy_utils::higher::{get_vec_init_kind, VecInitKind}; use clippy_utils::source::snippet; @@ -77,37 +77,53 @@ impl<'tcx> LateLintPass<'tcx> for ReadZeroByteVec { if let Some(expr) = visitor.read_zero_expr { let applicability = Applicability::MaybeIncorrect; match vec_init_kind { - VecInitKind::WithConstCapacity(len) => { - span_lint_and_sugg( + VecInitKind::WithConstCapacity(len) => span_lint_hir_and_then( + cx, + READ_ZERO_BYTE_VEC, + expr.hir_id, + expr.span, + "reading zero byte data to `Vec`", + |diag| { + diag.span_suggestion( + expr.span, + "try", + format!("{}.resize({len}, 0); {}", ident.as_str(), snippet(cx, expr.span, "..")), + applicability, + ); + }, + ), + VecInitKind::WithExprCapacity(hir_id) => { + let e = cx.tcx.hir().expect_expr(hir_id); + span_lint_hir_and_then( cx, READ_ZERO_BYTE_VEC, + expr.hir_id, expr.span, "reading zero byte data to `Vec`", - "try", - format!("{}.resize({len}, 0); {}", ident.as_str(), snippet(cx, expr.span, "..")), - applicability, + |diag| { + diag.span_suggestion( + expr.span, + "try", + format!( + "{}.resize({}, 0); {}", + ident.as_str(), + snippet(cx, e.span, ".."), + snippet(cx, expr.span, "..") + ), + applicability, + ); + }, ); }, - VecInitKind::WithExprCapacity(hir_id) => { - let e = cx.tcx.hir().expect_expr(hir_id); - span_lint_and_sugg( + _ => { + span_lint_hir( cx, READ_ZERO_BYTE_VEC, + expr.hir_id, expr.span, "reading zero byte data to `Vec`", - "try", - format!( - "{}.resize({}, 0); {}", - ident.as_str(), - snippet(cx, e.span, ".."), - snippet(cx, expr.span, "..") - ), - applicability, ); }, - _ => { - span_lint(cx, READ_ZERO_BYTE_VEC, expr.span, "reading zero byte data to `Vec`"); - }, } } } diff --git a/src/tools/clippy/clippy_lints/src/redundant_closure_call.rs b/src/tools/clippy/clippy_lints/src/redundant_closure_call.rs index c2673bc409f..435899ddaa7 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_closure_call.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_closure_call.rs @@ -1,5 +1,5 @@ use crate::rustc_lint::LintContext; -use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; +use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir}; use clippy_utils::get_parent_expr; use clippy_utils::sugg::Sugg; use hir::Param; @@ -273,9 +273,10 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { && ident == path.segments[0].ident && count_closure_usage(cx, block, path) == 1 { - span_lint( + span_lint_hir( cx, REDUNDANT_CLOSURE_CALL, + second.hir_id, second.span, "closure called just once immediately after it was declared", ); diff --git a/src/tools/clippy/clippy_lints/src/redundant_else.rs b/src/tools/clippy/clippy_lints/src/redundant_else.rs index fb434fb7450..3bdf13dbbea 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_else.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_else.rs @@ -105,7 +105,7 @@ impl<'ast> Visitor<'ast> for BreakVisitor { fn visit_expr(&mut self, expr: &'ast Expr) { self.is_break = match expr.kind { ExprKind::Break(..) | ExprKind::Continue(..) | ExprKind::Ret(..) => true, - ExprKind::Match(_, ref arms) => arms.iter().all(|arm| + ExprKind::Match(_, ref arms, _) => arms.iter().all(|arm| arm.body.is_none() || arm.body.as_deref().is_some_and(|body| self.check_expr(body)) ), ExprKind::If(_, ref then, Some(ref els)) => self.check_block(then) && self.check_expr(els), diff --git a/src/tools/clippy/clippy_lints/src/returns.rs b/src/tools/clippy/clippy_lints/src/returns.rs index 19697527467..8bc24eda465 100644 --- a/src/tools/clippy/clippy_lints/src/returns.rs +++ b/src/tools/clippy/clippy_lints/src/returns.rs @@ -1,4 +1,4 @@ -use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then}; +use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then}; use clippy_utils::source::{snippet_opt, snippet_with_context}; use clippy_utils::sugg::has_enclosing_paren; use clippy_utils::visitors::{for_each_expr_with_closures, Descend}; @@ -380,7 +380,7 @@ fn check_final_expr<'tcx>( return; } - emit_return_lint(cx, ret_span, semi_spans, &replacement); + emit_return_lint(cx, ret_span, semi_spans, &replacement, expr.hir_id); }, ExprKind::If(_, then, else_clause_opt) => { check_block_return(cx, &then.kind, peeled_drop_expr.span, semi_spans.clone()); @@ -415,18 +415,31 @@ fn expr_contains_conjunctive_ifs<'tcx>(expr: &'tcx Expr<'tcx>) -> bool { contains_if(expr, false) } -fn emit_return_lint(cx: &LateContext<'_>, ret_span: Span, semi_spans: Vec<Span>, replacement: &RetReplacement<'_>) { +fn emit_return_lint( + cx: &LateContext<'_>, + ret_span: Span, + semi_spans: Vec<Span>, + replacement: &RetReplacement<'_>, + at: HirId, +) { if ret_span.from_expansion() { return; } - span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded `return` statement", |diag| { - let suggestions = std::iter::once((ret_span, replacement.to_string())) - .chain(semi_spans.into_iter().map(|span| (span, String::new()))) - .collect(); + span_lint_hir_and_then( + cx, + NEEDLESS_RETURN, + at, + ret_span, + "unneeded `return` statement", + |diag| { + let suggestions = std::iter::once((ret_span, replacement.to_string())) + .chain(semi_spans.into_iter().map(|span| (span, String::new()))) + .collect(); - diag.multipart_suggestion_verbose(replacement.sugg_help(), suggestions, replacement.applicability()); - }); + diag.multipart_suggestion_verbose(replacement.sugg_help(), suggestions, replacement.applicability()); + }, + ); } fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { @@ -452,8 +465,8 @@ fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) // Go backwards while encountering whitespace and extend the given Span to that point. fn extend_span_to_previous_non_ws(cx: &LateContext<'_>, sp: Span) -> Span { if let Ok(prev_source) = cx.sess().source_map().span_to_prev_source(sp) { - let ws = [' ', '\t', '\n']; - if let Some(non_ws_pos) = prev_source.rfind(|c| !ws.contains(&c)) { + let ws = [b' ', b'\t', b'\n']; + if let Some(non_ws_pos) = prev_source.bytes().rposition(|c| !ws.contains(&c)) { let len = prev_source.len() - non_ws_pos - 1; return sp.with_lo(sp.lo() - BytePos::from_usize(len)); } diff --git a/src/tools/clippy/clippy_lints/src/shadow.rs b/src/tools/clippy/clippy_lints/src/shadow.rs index c74364d89d6..df7bd4c8d1d 100644 --- a/src/tools/clippy/clippy_lints/src/shadow.rs +++ b/src/tools/clippy/clippy_lints/src/shadow.rs @@ -5,7 +5,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir::def::Res; use rustc_hir::def_id::LocalDefId; use rustc_hir::hir_id::ItemLocalId; -use rustc_hir::{Block, Body, BodyOwnerKind, Expr, ExprKind, HirId, Let, Node, Pat, PatKind, QPath, UnOp}; +use rustc_hir::{Block, Body, BodyOwnerKind, Expr, ExprKind, HirId, LetExpr, Node, Pat, PatKind, QPath, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; use rustc_span::{Span, Symbol}; @@ -238,7 +238,7 @@ fn find_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<' let init = match node { Node::Arm(_) | Node::Pat(_) => continue, Node::Expr(expr) => match expr.kind { - ExprKind::Match(e, _, _) | ExprKind::Let(&Let { init: e, .. }) => Some(e), + ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some(e), _ => None, }, Node::Local(local) => local.init, diff --git a/src/tools/clippy/clippy_lints/src/std_instead_of_core.rs b/src/tools/clippy/clippy_lints/src/std_instead_of_core.rs index c0e4f3c368a..cf839941123 100644 --- a/src/tools/clippy/clippy_lints/src/std_instead_of_core.rs +++ b/src/tools/clippy/clippy_lints/src/std_instead_of_core.rs @@ -109,6 +109,7 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports { sym::core => (STD_INSTEAD_OF_CORE, "std", "core"), sym::alloc => (STD_INSTEAD_OF_ALLOC, "std", "alloc"), _ => { + self.prev_span = first_segment.ident.span; return; }, }, @@ -116,6 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports { if cx.tcx.crate_name(def_id.krate) == sym::core { (ALLOC_INSTEAD_OF_CORE, "alloc", "core") } else { + self.prev_span = first_segment.ident.span; return; } }, diff --git a/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs b/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs index 60e9d262e7e..ab1b3043f0c 100644 --- a/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs +++ b/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs @@ -552,7 +552,7 @@ fn ident_difference_expr_with_base_location( | (Gen(_, _, _), Gen(_, _, _)) | (Block(_, _), Block(_, _)) | (Closure(_), Closure(_)) - | (Match(_, _), Match(_, _)) + | (Match(_, _, _), Match(_, _, _)) | (Loop(_, _, _), Loop(_, _, _)) | (ForLoop { .. }, ForLoop { .. }) | (While(_, _, _), While(_, _, _)) diff --git a/src/tools/clippy/clippy_lints/src/thread_local_initializer_can_be_made_const.rs b/src/tools/clippy/clippy_lints/src/thread_local_initializer_can_be_made_const.rs index 1af3733ebfa..f8bdb866ca3 100644 --- a/src/tools/clippy/clippy_lints/src/thread_local_initializer_can_be_made_const.rs +++ b/src/tools/clippy/clippy_lints/src/thread_local_initializer_can_be_made_const.rs @@ -37,7 +37,7 @@ declare_clippy_lint! { /// static BUF: String = const { String::new() }; /// } /// ``` - #[clippy::version = "1.76.0"] + #[clippy::version = "1.77.0"] pub THREAD_LOCAL_INITIALIZER_CAN_BE_MADE_CONST, perf, "suggest using `const` in `thread_local!` macro" diff --git a/src/tools/clippy/clippy_lints/src/transmute/mod.rs b/src/tools/clippy/clippy_lints/src/transmute/mod.rs index e47b14bf63b..3c11b481310 100644 --- a/src/tools/clippy/clippy_lints/src/transmute/mod.rs +++ b/src/tools/clippy/clippy_lints/src/transmute/mod.rs @@ -514,7 +514,7 @@ declare_clippy_lint! { /// ^^^^ ^^ `bool::then` only executes the closure if the condition is true! /// } /// ``` - #[clippy::version = "1.76.0"] + #[clippy::version = "1.77.0"] pub EAGER_TRANSMUTE, correctness, "eager evaluation of `transmute`" diff --git a/src/tools/clippy/clippy_lints/src/types/mod.rs b/src/tools/clippy/clippy_lints/src/types/mod.rs index bdef82e9c5e..2ad15ac8312 100644 --- a/src/tools/clippy/clippy_lints/src/types/mod.rs +++ b/src/tools/clippy/clippy_lints/src/types/mod.rs @@ -392,6 +392,10 @@ impl<'tcx> LateLintPass<'tcx> for Types { } fn check_field_def(&mut self, cx: &LateContext<'tcx>, field: &hir::FieldDef<'tcx>) { + if field.span.from_expansion() { + return; + } + let is_exported = cx.effective_visibilities.is_exported(field.def_id); self.check_ty( diff --git a/src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs b/src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs index a0d609501a0..37437cbfbec 100644 --- a/src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs +++ b/src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs @@ -4,7 +4,7 @@ use clippy_utils::{path_def_id, qpath_generic_tys}; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, QPath, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::LateContext; use rustc_middle::ty::TypeVisitableExt; use rustc_span::symbol::sym; @@ -56,10 +56,10 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>, qpath: }; let inner_span = match qpath_generic_tys(inner_qpath).next() { Some(hir_ty) => { - // Reallocation of a fat pointer causes it to become thin. `hir_ty_to_ty` is safe to use + // Reallocation of a fat pointer causes it to become thin. `lower_ty` is safe to use // here because `mod.rs` guarantees this lint is only run on types outside of bodies and // is not run on locals. - let ty = hir_ty_to_ty(cx.tcx, hir_ty); + let ty = lower_ty(cx.tcx, hir_ty); if ty.has_escaping_bound_vars() || !ty.is_sized(cx.tcx, cx.param_env) { return false; } diff --git a/src/tools/clippy/clippy_lints/src/types/vec_box.rs b/src/tools/clippy/clippy_lints/src/types/vec_box.rs index 7926738d68f..29996a6f783 100644 --- a/src/tools/clippy/clippy_lints/src/types/vec_box.rs +++ b/src/tools/clippy/clippy_lints/src/types/vec_box.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, GenericArg, LangItem, QPath, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::LateContext; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::TypeVisitableExt; @@ -35,7 +35,7 @@ pub(super) fn check<'tcx>( && let Some(GenericArg::Type(boxed_ty)) = last.args.first() // extract allocator from the Box for later && let boxed_alloc_ty = last.args.get(1) - && let ty_ty = hir_ty_to_ty(cx.tcx, boxed_ty) + && let ty_ty = lower_ty(cx.tcx, boxed_ty) && !ty_ty.has_escaping_bound_vars() && ty_ty.is_sized(cx.tcx, cx.param_env) && let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes()) @@ -55,7 +55,7 @@ pub(super) fn check<'tcx>( } }, (Some(GenericArg::Type(l)), Some(GenericArg::Type(r))) => - hir_ty_to_ty(cx.tcx, l) == hir_ty_to_ty(cx.tcx, r), + lower_ty(cx.tcx, l) == lower_ty(cx.tcx, r), _ => false } { diff --git a/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs b/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs index 224ec475c51..8764e3006c6 100644 --- a/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs +++ b/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::{expr_or_init, get_trait_def_id, path_def_id}; +use clippy_utils::{expr_or_init, fn_def_id_with_node_args, path_def_id}; use rustc_ast::BinOpKind; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; @@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{walk_body, walk_expr, FnKind, Visitor}; use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Node, QPath, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_middle::hir::nested_filter; @@ -19,11 +19,11 @@ use rustc_trait_selection::traits::error_reporting::suggestions::ReturnsVisitor; declare_clippy_lint! { /// ### What it does - /// Checks that there isn't an infinite recursion in `PartialEq` trait - /// implementation. + /// Checks that there isn't an infinite recursion in trait + /// implementations. /// /// ### Why is this bad? - /// This is a hard to find infinite recursion which will crashing any code + /// This is a hard to find infinite recursion that will crash any code. /// using it. /// /// ### Example @@ -42,7 +42,7 @@ declare_clippy_lint! { /// Use instead: /// /// In such cases, either use `#[derive(PartialEq)]` or don't implement it. - #[clippy::version = "1.76.0"] + #[clippy::version = "1.77.0"] pub UNCONDITIONAL_RECURSION, suspicious, "detect unconditional recursion in some traits implementation" @@ -74,7 +74,7 @@ fn get_hir_ty_def_id<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: rustc_hir::Ty<'tcx>) -> Op match qpath { QPath::Resolved(_, path) => path.res.opt_def_id(), QPath::TypeRelative(_, _) => { - let ty = hir_ty_to_ty(tcx, &hir_ty); + let ty = lower_ty(tcx, &hir_ty); match ty.kind() { ty::Alias(ty::Projection, proj) => { @@ -201,7 +201,6 @@ fn check_partial_eq(cx: &LateContext<'_>, method_span: Span, method_def_id: Loca } } -#[allow(clippy::unnecessary_def_path)] fn check_to_string(cx: &LateContext<'_>, method_span: Span, method_def_id: LocalDefId, name: Ident, expr: &Expr<'_>) { let args = cx .tcx @@ -224,7 +223,7 @@ fn check_to_string(cx: &LateContext<'_>, method_span: Span, method_def_id: Local && let Some(trait_) = impl_.of_trait && let Some(trait_def_id) = trait_.trait_def_id() // The trait is `ToString`. - && Some(trait_def_id) == get_trait_def_id(cx, &["alloc", "string", "ToString"]) + && cx.tcx.is_diagnostic_item(sym::ToString, trait_def_id) { let is_bad = match expr.kind { ExprKind::MethodCall(segment, _receiver, &[_arg], _) if segment.ident.name == name.name => { @@ -291,7 +290,6 @@ where self.map } - #[allow(clippy::unnecessary_def_path)] fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { if self.found_default_call { return; @@ -303,7 +301,7 @@ where && is_default_method_on_current_ty(self.cx.tcx, qpath, self.implemented_ty_id) && let Some(method_def_id) = path_def_id(self.cx, f) && let Some(trait_def_id) = self.cx.tcx.trait_of_item(method_def_id) - && Some(trait_def_id) == get_trait_def_id(self.cx, &["core", "default", "Default"]) + && self.cx.tcx.is_diagnostic_item(sym::Default, trait_def_id) { self.found_default_call = true; span_error(self.cx, self.method_span, expr); @@ -312,10 +310,9 @@ where } impl UnconditionalRecursion { - #[allow(clippy::unnecessary_def_path)] fn init_default_impl_for_type_if_needed(&mut self, cx: &LateContext<'_>) { if self.default_impl_for_type.is_empty() - && let Some(default_trait_id) = get_trait_def_id(cx, &["core", "default", "Default"]) + && let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default) { let impls = cx.tcx.trait_impls_of(default_trait_id); for (ty, impl_def_ids) in impls.non_blanket_impls() { @@ -394,6 +391,34 @@ impl UnconditionalRecursion { } } +fn check_from(cx: &LateContext<'_>, method_span: Span, method_def_id: LocalDefId, expr: &Expr<'_>) { + let Some(sig) = cx + .typeck_results() + .liberated_fn_sigs() + .get(cx.tcx.local_def_id_to_hir_id(method_def_id)) + else { + return; + }; + + // Check if we are calling `Into::into` where the node args match with our `From::from` signature: + // From::from signature: fn(S1) -> S2 + // <S1 as Into<S2>>::into(s1), node_args=[S1, S2] + // If they do match, then it must mean that it is the blanket impl, + // which calls back into our `From::from` again (`Into` is not specializable). + // rustc's unconditional_recursion already catches calling `From::from` directly + if let Some((fn_def_id, node_args)) = fn_def_id_with_node_args(cx, expr) + && let [s1, s2] = **node_args + && let (Some(s1), Some(s2)) = (s1.as_type(), s2.as_type()) + && let Some(trait_def_id) = cx.tcx.trait_of_item(fn_def_id) + && cx.tcx.is_diagnostic_item(sym::Into, trait_def_id) + && get_impl_trait_def_id(cx, method_def_id) == cx.tcx.get_diagnostic_item(sym::From) + && s1 == sig.inputs()[0] + && s2 == sig.output() + { + span_error(cx, method_span, expr); + } +} + impl<'tcx> LateLintPass<'tcx> for UnconditionalRecursion { fn check_fn( &mut self, @@ -410,10 +435,11 @@ impl<'tcx> LateLintPass<'tcx> for UnconditionalRecursion { // Doesn't have a conditional return. && !has_conditional_return(body, expr) { - if name.name == sym::eq || name.name == sym::ne { - check_partial_eq(cx, method_span, method_def_id, name, expr); - } else if name.name == sym::to_string { - check_to_string(cx, method_span, method_def_id, name, expr); + match name.name { + sym::eq | sym::ne => check_partial_eq(cx, method_span, method_def_id, name, expr), + sym::to_string => check_to_string(cx, method_span, method_def_id, name, expr), + sym::from => check_from(cx, method_span, method_def_id, expr), + _ => {}, } self.check_default_new(cx, decl, body, method_span, method_def_id); } diff --git a/src/tools/clippy/clippy_lints/src/uninhabited_references.rs b/src/tools/clippy/clippy_lints/src/uninhabited_references.rs index 6732a43a19e..88039372ebd 100644 --- a/src/tools/clippy/clippy_lints/src/uninhabited_references.rs +++ b/src/tools/clippy/clippy_lints/src/uninhabited_references.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnRetTy, TyKind, UnOp}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_session::declare_lint_pass; @@ -71,7 +71,7 @@ impl LateLintPass<'_> for UninhabitedReferences { } if let FnRetTy::Return(hir_ty) = fndecl.output && let TyKind::Ref(_, mut_ty) = hir_ty.kind - && hir_ty_to_ty(cx.tcx, mut_ty.ty).is_privately_uninhabited(cx.tcx, cx.param_env) + && lower_ty(cx.tcx, mut_ty.ty).is_privately_uninhabited(cx.tcx, cx.param_env) { span_lint( cx, diff --git a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs index 7246214f9bf..d4dd31e1178 100644 --- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs +++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs @@ -242,6 +242,8 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec<P<Pat>>, focus_idx: us |k| matches!(k, Box(_)), |k| always_pat!(k, Box(p) => p), ), + // FIXME(deref_patterns): Should we merge patterns here? + Deref(_) => false, // Transform `&mut x | ... | &mut y` into `&mut (x | y)`. Ref(target, Mutability::Mut) => extend_with_matching( target, start, alternatives, diff --git a/src/tools/clippy/clippy_lints/src/unused_io_amount.rs b/src/tools/clippy/clippy_lints/src/unused_io_amount.rs index eb64dd633f6..d8c5f1b7382 100644 --- a/src/tools/clippy/clippy_lints/src/unused_io_amount.rs +++ b/src/tools/clippy/clippy_lints/src/unused_io_amount.rs @@ -1,7 +1,7 @@ -use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::macros::{is_panic, root_macro_call_first_node}; use clippy_utils::{is_res_lang_ctor, is_trait_method, match_trait_method, paths, peel_blocks}; -use hir::{ExprKind, PatKind}; +use hir::{ExprKind, HirId, PatKind}; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; @@ -131,26 +131,26 @@ fn non_consuming_ok_arm<'a>(cx: &LateContext<'a>, arm: &hir::Arm<'a>) -> bool { fn check_expr<'a>(cx: &LateContext<'a>, expr: &'a hir::Expr<'a>) { match expr.kind { hir::ExprKind::If(cond, _, _) - if let ExprKind::Let(hir::Let { pat, init, .. }) = cond.kind + if let ExprKind::Let(hir::LetExpr { pat, init, .. }) = cond.kind && is_ok_wild_or_dotdot_pattern(cx, pat) && let Some(op) = should_lint(cx, init) => { - emit_lint(cx, cond.span, op, &[pat.span]); + emit_lint(cx, cond.span, cond.hir_id, op, &[pat.span]); }, // we will capture only the case where the match is Ok( ) or Err( ) // prefer to match the minimum possible, and expand later if needed // to avoid false positives on something as used as this hir::ExprKind::Match(expr, [arm1, arm2], hir::MatchSource::Normal) if let Some(op) = should_lint(cx, expr) => { if non_consuming_ok_arm(cx, arm1) && non_consuming_err_arm(cx, arm2) { - emit_lint(cx, expr.span, op, &[arm1.pat.span]); + emit_lint(cx, expr.span, expr.hir_id, op, &[arm1.pat.span]); } if non_consuming_ok_arm(cx, arm2) && non_consuming_err_arm(cx, arm1) { - emit_lint(cx, expr.span, op, &[arm2.pat.span]); + emit_lint(cx, expr.span, expr.hir_id, op, &[arm2.pat.span]); } }, hir::ExprKind::Match(_, _, hir::MatchSource::Normal) => {}, _ if let Some(op) = should_lint(cx, expr) => { - emit_lint(cx, expr.span, op, &[]); + emit_lint(cx, expr.span, expr.hir_id, op, &[]); }, _ => {}, }; @@ -279,7 +279,7 @@ fn check_io_mode(cx: &LateContext<'_>, call: &hir::Expr<'_>) -> Option<IoOp> { } } -fn emit_lint(cx: &LateContext<'_>, span: Span, op: IoOp, wild_cards: &[Span]) { +fn emit_lint(cx: &LateContext<'_>, span: Span, at: HirId, op: IoOp, wild_cards: &[Span]) { let (msg, help) = match op { IoOp::AsyncRead(false) => ( "read amount is not handled", @@ -301,7 +301,7 @@ fn emit_lint(cx: &LateContext<'_>, span: Span, op: IoOp, wild_cards: &[Span]) { IoOp::SyncWrite(true) | IoOp::AsyncWrite(true) => ("written amount is not handled", None), }; - span_lint_and_then(cx, UNUSED_IO_AMOUNT, span, msg, |diag| { + span_lint_hir_and_then(cx, UNUSED_IO_AMOUNT, at, span, msg, |diag| { if let Some(help_str) = help { diag.help(help_str); } diff --git a/src/tools/clippy/clippy_lints/src/unused_peekable.rs b/src/tools/clippy/clippy_lints/src/unused_peekable.rs index f1d0c22b1ae..3f4ab3e31cf 100644 --- a/src/tools/clippy/clippy_lints/src/unused_peekable.rs +++ b/src/tools/clippy/clippy_lints/src/unused_peekable.rs @@ -1,4 +1,4 @@ -use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::ty::{is_type_diagnostic_item, peel_mid_ty_refs_is_mutable}; use clippy_utils::{fn_def_id, is_trait_method, path_to_local_id, peel_ref_operators}; use rustc_ast::Mutability; @@ -79,13 +79,15 @@ impl<'tcx> LateLintPass<'tcx> for UnusedPeekable { } if !vis.found_peek_call { - span_lint_and_help( + span_lint_hir_and_then( cx, UNUSED_PEEKABLE, + local.hir_id, ident.span, "`peek` never called on `Peekable` iterator", - None, - "consider removing the call to `peekable`", + |diag| { + diag.help("consider removing the call to `peekable`"); + }, ); } } diff --git a/src/tools/clippy/clippy_lints/src/use_self.rs b/src/tools/clippy/clippy_lints/src/use_self.rs index a1b08d105b9..a6b411d6c0f 100644 --- a/src/tools/clippy/clippy_lints/src/use_self.rs +++ b/src/tools/clippy/clippy_lints/src/use_self.rs @@ -8,11 +8,12 @@ use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{walk_inf, walk_ty, Visitor}; use rustc_hir::{ - self as hir, Expr, ExprKind, FnRetTy, FnSig, GenericArg, GenericArgsParentheses, GenericParam, GenericParamKind, - HirId, Impl, ImplItemKind, Item, ItemKind, Pat, PatKind, Path, QPath, Ty, TyKind, + self as hir, Expr, ExprKind, FnRetTy, FnSig, GenericArgsParentheses, GenericParam, GenericParamKind, HirId, Impl, + ImplItemKind, Item, ItemKind, Pat, PatKind, Path, QPath, Ty, TyKind, }; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty::Ty as MiddleTy; use rustc_session::impl_lint_pass; use rustc_span::Span; @@ -95,10 +96,9 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { let stack_item = if let ItemKind::Impl(Impl { self_ty, generics, .. }) = item.kind && let TyKind::Path(QPath::Resolved(_, item_path)) = self_ty.kind && let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).args - && parameters.as_ref().map_or(true, |params| { - params.parenthesized == GenericArgsParentheses::No - && !params.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_))) - }) + && parameters + .as_ref() + .map_or(true, |params| params.parenthesized == GenericArgsParentheses::No) && !item.span.from_expansion() && !is_from_proc_macro(cx, item) // expensive, should be last check @@ -193,7 +193,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } fn check_body(&mut self, _: &LateContext<'_>, _: &hir::Body<'_>) { - // `hir_ty_to_ty` cannot be called in `Body`s or it will panic (sometimes). But in bodies + // `lower_ty` cannot be called in `Body`s or it will panic (sometimes). But in bodies // we can use `cx.typeck_results.node_type(..)` to get the `ty::Ty` from a `hir::Ty`. // However the `node_type()` method can *only* be called in bodies. if let Some(&mut StackItem::Check { ref mut in_body, .. }) = self.stack.last_mut() { @@ -224,9 +224,14 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { && let ty = if in_body > 0 { cx.typeck_results().node_type(hir_ty.hir_id) } else { - hir_ty_to_ty(cx.tcx, hir_ty) + lower_ty(cx.tcx, hir_ty) } - && same_type_and_consts(ty, cx.tcx.type_of(impl_id).instantiate_identity()) + && let impl_ty = cx.tcx.type_of(impl_id).instantiate_identity() + && same_type_and_consts(ty, impl_ty) + // Ensure the type we encounter and the one from the impl have the same lifetime parameters. It may be that + // the lifetime parameters of `ty` are ellided (`impl<'a> Foo<'a> { fn new() -> Self { Foo{..} } }`, in + // which case we must still trigger the lint. + && (has_no_lifetime(ty) || same_lifetimes(ty, impl_ty)) { span_lint(cx, hir_ty.span); } @@ -318,3 +323,37 @@ fn lint_path_to_variant(cx: &LateContext<'_>, path: &Path<'_>) { span_lint(cx, span); } } + +/// Returns `true` if types `a` and `b` have the same lifetime parameters, otherwise returns +/// `false`. +/// +/// This function does not check that types `a` and `b` are the same types. +fn same_lifetimes<'tcx>(a: MiddleTy<'tcx>, b: MiddleTy<'tcx>) -> bool { + use rustc_middle::ty::{Adt, GenericArgKind}; + match (&a.kind(), &b.kind()) { + (&Adt(_, args_a), &Adt(_, args_b)) => { + args_a + .iter() + .zip(args_b.iter()) + .all(|(arg_a, arg_b)| match (arg_a.unpack(), arg_b.unpack()) { + // TODO: Handle inferred lifetimes + (GenericArgKind::Lifetime(inner_a), GenericArgKind::Lifetime(inner_b)) => inner_a == inner_b, + (GenericArgKind::Type(type_a), GenericArgKind::Type(type_b)) => same_lifetimes(type_a, type_b), + _ => true, + }) + }, + _ => a == b, + } +} + +/// Returns `true` if `ty` has no lifetime parameter, otherwise returns `false`. +fn has_no_lifetime(ty: MiddleTy<'_>) -> bool { + use rustc_middle::ty::{Adt, GenericArgKind}; + match ty.kind() { + &Adt(_, args) => !args + .iter() + // TODO: Handle inferred lifetimes + .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(..))), + _ => true, + } +} diff --git a/src/tools/clippy/clippy_lints/src/utils/author.rs b/src/tools/clippy/clippy_lints/src/utils/author.rs index 187bfda129c..5319915b2ea 100644 --- a/src/tools/clippy/clippy_lints/src/utils/author.rs +++ b/src/tools/clippy/clippy_lints/src/utils/author.rs @@ -689,6 +689,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { kind!("Box({pat})"); self.pat(pat); }, + PatKind::Deref(pat) => { + bind!(self, pat); + kind!("Deref({pat})"); + self.pat(pat); + }, PatKind::Ref(pat, muta) => { bind!(self, pat); kind!("Ref({pat}, Mutability::{muta:?})"); diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 97b509a84f9..1ebe1d6a2c4 100644 --- a/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -925,7 +925,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for LintResolver<'a, 'hir> { && let (expr_ty, _) = walk_ptrs_ty_depth(self.cx.typeck_results().expr_ty(expr)) && match_type(self.cx, expr_ty, &paths::LINT) { - if let hir::def::Res::Def(DefKind::Static(..), _) = path.res { + if let hir::def::Res::Def(DefKind::Static { .. }, _) = path.res { let lint_name = last_path_segment(qpath).ident.name; self.lints.push(sym_to_string(lint_name).to_ascii_lowercase()); } else if let Some(local) = get_parent_local(self.cx, expr) { diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs index 38c832931fc..f4e277fd0c4 100644 --- a/src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs +++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs @@ -223,7 +223,7 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<Ve None } }, - Res::Def(DefKind::Static(_), def_id) => read_mir_alloc_def_path( + Res::Def(DefKind::Static { .. }, def_id) => read_mir_alloc_def_path( cx, cx.tcx.eval_static_initializer(def_id).ok()?.inner(), cx.tcx.type_of(def_id).instantiate_identity(), diff --git a/src/tools/clippy/clippy_lints/src/wildcard_imports.rs b/src/tools/clippy/clippy_lints/src/wildcard_imports.rs index 5410e8ac117..436f0cb79fb 100644 --- a/src/tools/clippy/clippy_lints/src/wildcard_imports.rs +++ b/src/tools/clippy/clippy_lints/src/wildcard_imports.rs @@ -213,7 +213,7 @@ fn is_super_only_import(segments: &[PathSegment<'_>]) -> bool { // Allow skipping imports containing user configured segments, // i.e. "...::utils::...::*" if user put `allowed-wildcard-imports = ["utils"]` in `Clippy.toml` fn is_allowed_via_config(segments: &[PathSegment<'_>], allowed_segments: &FxHashSet<String>) -> bool { - // segment matching need to be exact instead of using 'contains', in case user unintentionaly put + // segment matching need to be exact instead of using 'contains', in case user unintentionally put // a single character in the config thus skipping most of the warnings. segments.iter().any(|seg| allowed_segments.contains(seg.ident.as_str())) } diff --git a/src/tools/clippy/clippy_lints/src/zero_repeat_side_effects.rs b/src/tools/clippy/clippy_lints/src/zero_repeat_side_effects.rs new file mode 100644 index 00000000000..852d04cd21b --- /dev/null +++ b/src/tools/clippy/clippy_lints/src/zero_repeat_side_effects.rs @@ -0,0 +1,154 @@ +use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::higher::VecArgs; +use clippy_utils::source::snippet; +use clippy_utils::visitors::for_each_expr; +use rustc_ast::LitKind; +use rustc_errors::Applicability; +use rustc_hir::{ExprKind, Node}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty::{self, ConstKind, Ty}; +use rustc_session::declare_lint_pass; +use rustc_span::Span; + +declare_clippy_lint! { + /// ### What it does + /// Checks for array or vec initializations which call a function or method, + /// but which have a repeat count of zero. + /// + /// ### Why is this bad? + /// Such an initialization, despite having a repeat length of 0, will still call the inner function. + /// This may not be obvious and as such there may be unintended side effects in code. + /// + /// ### Example + /// ```no_run + /// fn side_effect() -> i32 { + /// println!("side effect"); + /// 10 + /// } + /// let a = [side_effect(); 0]; + /// ``` + /// Use instead: + /// ```no_run + /// fn side_effect() -> i32 { + /// println!("side effect"); + /// 10 + /// } + /// side_effect(); + /// let a: [i32; 0] = []; + /// ``` + #[clippy::version = "1.75.0"] + pub ZERO_REPEAT_SIDE_EFFECTS, + suspicious, + "usage of zero-sized initializations of arrays or vecs causing side effects" +} + +declare_lint_pass!(ZeroRepeatSideEffects => [ZERO_REPEAT_SIDE_EFFECTS]); + +impl LateLintPass<'_> for ZeroRepeatSideEffects { + fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ rustc_hir::Expr<'_>) { + if let Some(args) = VecArgs::hir(cx, expr) + && let VecArgs::Repeat(inner_expr, len) = args + && let ExprKind::Lit(l) = len.kind + && let LitKind::Int(i, _) = l.node + && i.0 == 0 + { + inner_check(cx, expr, inner_expr, true); + } else if let ExprKind::Repeat(inner_expr, _) = expr.kind + && let ty::Array(_, cst) = cx.typeck_results().expr_ty(expr).kind() + && let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind() + && let Ok(element_count) = element_count.try_to_target_usize(cx.tcx) + && element_count == 0 + { + inner_check(cx, expr, inner_expr, false); + } + } +} + +fn inner_check(cx: &LateContext<'_>, expr: &'_ rustc_hir::Expr<'_>, inner_expr: &'_ rustc_hir::Expr<'_>, is_vec: bool) { + // check if expr is a call or has a call inside it + if for_each_expr(inner_expr, |x| { + if let ExprKind::Call(_, _) | ExprKind::MethodCall(_, _, _, _) = x.kind { + std::ops::ControlFlow::Break(()) + } else { + std::ops::ControlFlow::Continue(()) + } + }) + .is_some() + { + let parent_hir_node = cx.tcx.parent_hir_node(expr.hir_id); + let return_type = cx.typeck_results().expr_ty(expr); + + if let Node::Local(l) = parent_hir_node { + array_span_lint( + cx, + l.span, + inner_expr.span, + l.pat.span, + Some(return_type), + is_vec, + false, + ); + } else if let Node::Expr(x) = parent_hir_node + && let ExprKind::Assign(l, _, _) = x.kind + { + array_span_lint(cx, x.span, inner_expr.span, l.span, Some(return_type), is_vec, true); + } else { + span_lint_and_sugg( + cx, + ZERO_REPEAT_SIDE_EFFECTS, + expr.span.source_callsite(), + "function or method calls as the initial value in zero-sized array initializers may cause side effects", + "consider using", + format!( + "{{ {}; {}[] as {return_type} }}", + snippet(cx, inner_expr.span.source_callsite(), ".."), + if is_vec { "vec!" } else { "" }, + ), + Applicability::Unspecified, + ); + } + } +} + +fn array_span_lint( + cx: &LateContext<'_>, + expr_span: Span, + func_call_span: Span, + variable_name_span: Span, + expr_ty: Option<Ty<'_>>, + is_vec: bool, + is_assign: bool, +) { + let has_ty = expr_ty.is_some(); + + span_lint_and_sugg( + cx, + ZERO_REPEAT_SIDE_EFFECTS, + expr_span.source_callsite(), + "function or method calls as the initial value in zero-sized array initializers may cause side effects", + "consider using", + format!( + "{}; {}{}{} = {}[]{}{}", + snippet(cx, func_call_span.source_callsite(), ".."), + if has_ty && !is_assign { "let " } else { "" }, + snippet(cx, variable_name_span.source_callsite(), ".."), + if let Some(ty) = expr_ty + && !is_assign + { + format!(": {ty}") + } else { + String::new() + }, + if is_vec { "vec!" } else { "" }, + if let Some(ty) = expr_ty + && is_assign + { + format!(" as {ty}") + } else { + String::new() + }, + if is_assign { "" } else { ";" } + ), + Applicability::Unspecified, + ); +} diff --git a/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs b/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs index 4aaf3b0a0b6..d1f7c6417c7 100644 --- a/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs +++ b/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item}; use rustc_hir::{self as hir, HirId, ItemKind, Node}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{Adt, Ty, TypeVisitableExt}; @@ -91,5 +91,5 @@ fn ty_from_hir_ty<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'t None } }) - .unwrap_or_else(|| hir_ty_to_ty(cx.tcx, hir_ty)) + .unwrap_or_else(|| lower_ty(cx.tcx, hir_ty)) } diff --git a/src/tools/clippy/clippy_utils/Cargo.toml b/src/tools/clippy/clippy_utils/Cargo.toml index bf55040ddbc..d2bb719a517 100644 --- a/src/tools/clippy/clippy_utils/Cargo.toml +++ b/src/tools/clippy/clippy_utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy_utils" -version = "0.1.78" +version = "0.1.79" edition = "2021" publish = false diff --git a/src/tools/clippy/clippy_utils/src/ast_utils.rs b/src/tools/clippy/clippy_utils/src/ast_utils.rs index 3874c1169e4..f7532121aeb 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils.rs @@ -198,7 +198,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { }, (AssignOp(lo, lp, lv), AssignOp(ro, rp, rv)) => lo.node == ro.node && eq_expr(lp, rp) && eq_expr(lv, rv), (Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp), - (Match(ls, la), Match(rs, ra)) => eq_expr(ls, rs) && over(la, ra, eq_arm), + (Match(ls, la, lkind), Match(rs, ra, rkind)) => (lkind == rkind) && eq_expr(ls, rs) && over(la, ra, eq_arm), ( Closure(box ast::Closure { binder: lb, diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs index 07ed4fbbf8e..046087d3298 100644 --- a/src/tools/clippy/clippy_utils/src/consts.rs +++ b/src/tools/clippy/clippy_utils/src/consts.rs @@ -10,8 +10,10 @@ use rustc_hir::{BinOp, BinOpKind, Block, ConstBlock, Expr, ExprKind, HirId, Item use rustc_lexer::tokenize; use rustc_lint::LateContext; use rustc_middle::mir::interpret::{alloc_range, Scalar}; +use rustc_middle::mir::ConstValue; use rustc_middle::ty::{self, EarlyBinder, FloatTy, GenericArgsRef, IntTy, List, ScalarInt, Ty, TyCtxt, UintTy}; use rustc_middle::{bug, mir, span_bug}; +use rustc_span::def_id::DefId; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::SyntaxContext; use rustc_target::abi::Size; @@ -307,6 +309,12 @@ impl ConstantSource { } } +/// Attempts to check whether the expression is a constant representing an empty slice, str, array, +/// etc… +pub fn constant_is_empty(lcx: &LateContext<'_>, e: &Expr<'_>) -> Option<bool> { + ConstEvalLateContext::new(lcx, lcx.typeck_results()).expr_is_empty(e) +} + /// Attempts to evaluate the expression as a constant. pub fn constant<'tcx>( lcx: &LateContext<'tcx>, @@ -406,7 +414,13 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { match e.kind { ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.lcx.tcx.hir().body(body).value), ExprKind::DropTemps(e) => self.expr(e), - ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.typeck_results.expr_ty(e)), + ExprKind::Path(ref qpath) => { + self.fetch_path_and_apply(qpath, e.hir_id, self.typeck_results.expr_ty(e), |this, result| { + let result = mir_to_const(this.lcx, result)?; + this.source = ConstantSource::Constant; + Some(result) + }) + }, ExprKind::Block(block, _) => self.block(block), ExprKind::Lit(lit) => { if is_direct_expn_of(e.span, "cfg").is_some() { @@ -472,6 +486,49 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { } } + /// Simple constant folding to determine if an expression is an empty slice, str, array, … + /// `None` will be returned if the constness cannot be determined, or if the resolution + /// leaves the local crate. + pub fn expr_is_empty(&mut self, e: &Expr<'_>) -> Option<bool> { + match e.kind { + ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr_is_empty(self.lcx.tcx.hir().body(body).value), + ExprKind::DropTemps(e) => self.expr_is_empty(e), + ExprKind::Path(ref qpath) => { + if !self + .typeck_results + .qpath_res(qpath, e.hir_id) + .opt_def_id() + .is_some_and(DefId::is_local) + { + return None; + } + self.fetch_path_and_apply(qpath, e.hir_id, self.typeck_results.expr_ty(e), |this, result| { + mir_is_empty(this.lcx, result) + }) + }, + ExprKind::Lit(lit) => { + if is_direct_expn_of(e.span, "cfg").is_some() { + None + } else { + match &lit.node { + LitKind::Str(is, _) => Some(is.is_empty()), + LitKind::ByteStr(s, _) | LitKind::CStr(s, _) => Some(s.is_empty()), + _ => None, + } + } + }, + ExprKind::Array(vec) => self.multi(vec).map(|v| v.is_empty()), + ExprKind::Repeat(..) => { + if let ty::Array(_, n) = self.typeck_results.expr_ty(e).kind() { + Some(n.try_eval_target_usize(self.lcx.tcx, self.lcx.param_env)? == 0) + } else { + span_bug!(e.span, "typeck error"); + } + }, + _ => None, + } + } + #[expect(clippy::cast_possible_wrap)] fn constant_not(&self, o: &Constant<'tcx>, ty: Ty<'_>) -> Option<Constant<'tcx>> { use self::Constant::{Bool, Int}; @@ -519,8 +576,11 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { vec.iter().map(|elem| self.expr(elem)).collect::<Option<_>>() } - /// Lookup a possibly constant expression from an `ExprKind::Path`. - fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>) -> Option<Constant<'tcx>> { + /// Lookup a possibly constant expression from an `ExprKind::Path` and apply a function on it. + fn fetch_path_and_apply<T, F>(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>, f: F) -> Option<T> + where + F: FnOnce(&mut Self, rustc_middle::mir::Const<'tcx>) -> Option<T>, + { let res = self.typeck_results.qpath_res(qpath, id); match res { Res::Def(DefKind::Const | DefKind::AssocConst, def_id) => { @@ -550,12 +610,10 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let result = self .lcx .tcx - .const_eval_resolve(self.param_env, mir::UnevaluatedConst::new(def_id, args), None) + .const_eval_resolve(self.param_env, mir::UnevaluatedConst::new(def_id, args), qpath.span()) .ok() .map(|val| rustc_middle::mir::Const::from_value(val, ty))?; - let result = mir_to_const(self.lcx, result)?; - self.source = ConstantSource::Constant; - Some(result) + f(self, result) }, _ => None, } @@ -746,7 +804,6 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { } pub fn mir_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::Const<'tcx>) -> Option<Constant<'tcx>> { - use rustc_middle::mir::ConstValue; let mir::Const::Val(val, _) = result else { // We only work on evaluated consts. return None; @@ -794,6 +851,42 @@ pub fn mir_to_const<'tcx>(lcx: &LateContext<'tcx>, result: mir::Const<'tcx>) -> } } +fn mir_is_empty<'tcx>(lcx: &LateContext<'tcx>, result: mir::Const<'tcx>) -> Option<bool> { + let mir::Const::Val(val, _) = result else { + // We only work on evaluated consts. + return None; + }; + match (val, result.ty().kind()) { + (_, ty::Ref(_, inner_ty, _)) => match inner_ty.kind() { + ty::Str | ty::Slice(_) => { + if let ConstValue::Indirect { alloc_id, offset } = val { + // Get the length from the slice, using the same formula as + // [`ConstValue::try_get_slice_bytes_for_diagnostics`]. + let a = lcx.tcx.global_alloc(alloc_id).unwrap_memory().inner(); + let ptr_size = lcx.tcx.data_layout.pointer_size; + if a.size() < offset + 2 * ptr_size { + // (partially) dangling reference + return None; + } + let len = a + .read_scalar(&lcx.tcx, alloc_range(offset + ptr_size, ptr_size), false) + .ok()? + .to_target_usize(&lcx.tcx) + .ok()?; + Some(len == 0) + } else { + None + } + }, + ty::Array(_, len) => Some(len.try_to_target_usize(lcx.tcx)? == 0), + _ => None, + }, + (ConstValue::Indirect { .. }, ty::Array(_, len)) => Some(len.try_to_target_usize(lcx.tcx)? == 0), + (ConstValue::ZeroSized, _) => Some(true), + _ => None, + } +} + fn field_of_struct<'tcx>( adt_def: ty::AdtDef<'tcx>, lcx: &LateContext<'tcx>, diff --git a/src/tools/clippy/clippy_utils/src/diagnostics.rs b/src/tools/clippy/clippy_utils/src/diagnostics.rs index 6ed46e5dde0..0352696f93e 100644 --- a/src/tools/clippy/clippy_utils/src/diagnostics.rs +++ b/src/tools/clippy/clippy_utils/src/diagnostics.rs @@ -36,6 +36,20 @@ fn docs_link(diag: &mut Diag<'_, ()>, lint: &'static Lint) { /// Usually it's nicer to provide more context for lint messages. /// Be sure the output is understandable when you use this method. /// +/// NOTE: Lint emissions are always bound to a node in the HIR, which is used to determine +/// the lint level. +/// For the `span_lint` function, the node that was passed into the `LintPass::check_*` function is +/// used. +/// +/// If you're emitting the lint at the span of a different node than the one provided by the +/// `LintPass::check_*` function, consider using [`span_lint_hir`] instead. +/// This is needed for `#[allow]` and `#[expect]` attributes to work on the node +/// highlighted in the displayed warning. +/// +/// If you're unsure which function you should use, you can test if the `#[allow]` attribute works +/// where you would expect it to. +/// If it doesn't, you likely need to use [`span_lint_hir`] instead. +/// /// # Example /// /// ```ignore @@ -61,6 +75,20 @@ pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<Mult /// /// If you change the signature, remember to update the internal lint `CollapsibleCalls` /// +/// NOTE: Lint emissions are always bound to a node in the HIR, which is used to determine +/// the lint level. +/// For the `span_lint_and_help` function, the node that was passed into the `LintPass::check_*` +/// function is used. +/// +/// If you're emitting the lint at the span of a different node than the one provided by the +/// `LintPass::check_*` function, consider using [`span_lint_hir_and_then`] instead. +/// This is needed for `#[allow]` and `#[expect]` attributes to work on the node +/// highlighted in the displayed warning. +/// +/// If you're unsure which function you should use, you can test if the `#[allow]` attribute works +/// where you would expect it to. +/// If it doesn't, you likely need to use [`span_lint_hir_and_then`] instead. +/// /// # Example /// /// ```text @@ -99,6 +127,20 @@ pub fn span_lint_and_help<T: LintContext>( /// /// If you change the signature, remember to update the internal lint `CollapsibleCalls` /// +/// NOTE: Lint emissions are always bound to a node in the HIR, which is used to determine +/// the lint level. +/// For the `span_lint_and_note` function, the node that was passed into the `LintPass::check_*` +/// function is used. +/// +/// If you're emitting the lint at the span of a different node than the one provided by the +/// `LintPass::check_*` function, consider using [`span_lint_hir_and_then`] instead. +/// This is needed for `#[allow]` and `#[expect]` attributes to work on the node +/// highlighted in the displayed warning. +/// +/// If you're unsure which function you should use, you can test if the `#[allow]` attribute works +/// where you would expect it to. +/// If it doesn't, you likely need to use [`span_lint_hir_and_then`] instead. +/// /// # Example /// /// ```text @@ -139,6 +181,20 @@ pub fn span_lint_and_note<T: LintContext>( /// /// If you need to customize your lint output a lot, use this function. /// If you change the signature, remember to update the internal lint `CollapsibleCalls` +/// +/// NOTE: Lint emissions are always bound to a node in the HIR, which is used to determine +/// the lint level. +/// For the `span_lint_and_then` function, the node that was passed into the `LintPass::check_*` +/// function is used. +/// +/// If you're emitting the lint at the span of a different node than the one provided by the +/// `LintPass::check_*` function, consider using [`span_lint_hir_and_then`] instead. +/// This is needed for `#[allow]` and `#[expect]` attributes to work on the node +/// highlighted in the displayed warning. +/// +/// If you're unsure which function you should use, you can test if the `#[allow]` attribute works +/// where you would expect it to. +/// If it doesn't, you likely need to use [`span_lint_hir_and_then`] instead. pub fn span_lint_and_then<C, S, F>(cx: &C, lint: &'static Lint, sp: S, msg: &str, f: F) where C: LintContext, @@ -152,6 +208,30 @@ where }); } +/// Like [`span_lint`], but emits the lint at the node identified by the given `HirId`. +/// +/// This is in contrast to [`span_lint`], which always emits the lint at the node that was last +/// passed to the `LintPass::check_*` function. +/// +/// The `HirId` is used for checking lint level attributes and to fulfill lint expectations defined +/// via the `#[expect]` attribute. +/// +/// For example: +/// ```ignore +/// fn f() { /* <node_1> */ +/// +/// #[allow(clippy::some_lint)] +/// let _x = /* <expr_1> */; +/// } +/// ``` +/// If `some_lint` does its analysis in `LintPass::check_fn` (at `<node_1>`) and emits a lint at +/// `<expr_1>` using [`span_lint`], then allowing the lint at `<expr_1>` as attempted in the snippet +/// will not work! +/// Even though that is where the warning points at, which would be confusing to users. +/// +/// Instead, use this function and also pass the `HirId` of `<expr_1>`, which will let +/// the compiler check lint level attributes at the place of the expression and +/// the `#[allow]` will work. pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) { #[expect(clippy::disallowed_methods)] cx.tcx.node_span_lint(lint, hir_id, sp, msg.to_string(), |diag| { @@ -159,6 +239,30 @@ pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, s }); } +/// Like [`span_lint_and_then`], but emits the lint at the node identified by the given `HirId`. +/// +/// This is in contrast to [`span_lint_and_then`], which always emits the lint at the node that was +/// last passed to the `LintPass::check_*` function. +/// +/// The `HirId` is used for checking lint level attributes and to fulfill lint expectations defined +/// via the `#[expect]` attribute. +/// +/// For example: +/// ```ignore +/// fn f() { /* <node_1> */ +/// +/// #[allow(clippy::some_lint)] +/// let _x = /* <expr_1> */; +/// } +/// ``` +/// If `some_lint` does its analysis in `LintPass::check_fn` (at `<node_1>`) and emits a lint at +/// `<expr_1>` using [`span_lint`], then allowing the lint at `<expr_1>` as attempted in the snippet +/// will not work! +/// Even though that is where the warning points at, which would be confusing to users. +/// +/// Instead, use this function and also pass the `HirId` of `<expr_1>`, which will let +/// the compiler check lint level attributes at the place of the expression and +/// the `#[allow]` will work. pub fn span_lint_hir_and_then( cx: &LateContext<'_>, lint: &'static Lint, @@ -182,6 +286,20 @@ pub fn span_lint_hir_and_then( /// /// If you change the signature, remember to update the internal lint `CollapsibleCalls` /// +/// NOTE: Lint emissions are always bound to a node in the HIR, which is used to determine +/// the lint level. +/// For the `span_lint_and_sugg` function, the node that was passed into the `LintPass::check_*` +/// function is used. +/// +/// If you're emitting the lint at the span of a different node than the one provided by the +/// `LintPass::check_*` function, consider using [`span_lint_hir_and_then`] instead. +/// This is needed for `#[allow]` and `#[expect]` attributes to work on the node +/// highlighted in the displayed warning. +/// +/// If you're unsure which function you should use, you can test if the `#[allow]` attribute works +/// where you would expect it to. +/// If it doesn't, you likely need to use [`span_lint_hir_and_then`] instead. +/// /// # Example /// /// ```text diff --git a/src/tools/clippy/clippy_utils/src/higher.rs b/src/tools/clippy/clippy_utils/src/higher.rs index ba682813dad..8ce19998a08 100644 --- a/src/tools/clippy/clippy_utils/src/higher.rs +++ b/src/tools/clippy/clippy_utils/src/higher.rs @@ -102,7 +102,7 @@ impl<'hir> IfLet<'hir> { if let ExprKind::If( Expr { kind: - ExprKind::Let(&hir::Let { + ExprKind::Let(&hir::LetExpr { pat: let_pat, init: let_expr, span: let_span, @@ -379,7 +379,7 @@ impl<'hir> WhileLet<'hir> { ExprKind::If( Expr { kind: - ExprKind::Let(&hir::Let { + ExprKind::Let(&hir::LetExpr { pat: let_pat, init: let_expr, span: let_span, diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index 106d1d0d77f..7a4eba9790e 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -8,7 +8,7 @@ use rustc_hir::def::Res; use rustc_hir::MatchSource::TryDesugar; use rustc_hir::{ ArrayLen, BinOpKind, BindingAnnotation, Block, BodyId, Closure, Expr, ExprField, ExprKind, FnRetTy, GenericArg, - GenericArgs, HirId, HirIdMap, InlineAsmOperand, Let, Lifetime, LifetimeName, Pat, PatField, PatKind, Path, + GenericArgs, HirId, HirIdMap, InlineAsmOperand, LetExpr, Lifetime, LifetimeName, Pat, PatField, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; use rustc_lexer::{tokenize, TokenKind}; @@ -837,7 +837,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } } }, - ExprKind::Let(Let { pat, init, ty, .. }) => { + ExprKind::Let(LetExpr { pat, init, ty, .. }) => { self.hash_expr(init); if let Some(ty) = ty { self.hash_ty(ty); @@ -955,6 +955,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { } }, PatKind::Box(pat) => self.hash_pat(pat), + PatKind::Deref(pat) => self.hash_pat(pat), PatKind::Lit(expr) => self.hash_expr(expr), PatKind::Or(pats) => { for pat in pats { diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index a38db0ebec0..11b56ed47de 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -1678,7 +1678,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { match pat.kind { PatKind::Wild | PatKind::Never => false, // If `!` typechecked then the type is empty, so not refutable. PatKind::Binding(_, _, _, pat) => pat.map_or(false, |pat| is_refutable(cx, pat)), - PatKind::Box(pat) | PatKind::Ref(pat, _) => is_refutable(cx, pat), + PatKind::Box(pat) | PatKind::Deref(pat) | PatKind::Ref(pat, _) => is_refutable(cx, pat), PatKind::Path(ref qpath) => is_enum_variant(cx, qpath, pat.hir_id), PatKind::Or(pats) => { // TODO: should be the honest check, that pats is exhaustive set @@ -2246,8 +2246,21 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool { /// Returns the `DefId` of the callee if the given expression is a function or method call. pub fn fn_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<DefId> { + fn_def_id_with_node_args(cx, expr).map(|(did, _)| did) +} + +/// Returns the `DefId` of the callee if the given expression is a function or method call, +/// as well as its node args. +pub fn fn_def_id_with_node_args<'tcx>( + cx: &LateContext<'tcx>, + expr: &Expr<'_>, +) -> Option<(DefId, rustc_ty::GenericArgsRef<'tcx>)> { + let typeck = cx.typeck_results(); match &expr.kind { - ExprKind::MethodCall(..) => cx.typeck_results().type_dependent_def_id(expr.hir_id), + ExprKind::MethodCall(..) => Some(( + typeck.type_dependent_def_id(expr.hir_id)?, + typeck.node_args(expr.hir_id), + )), ExprKind::Call( Expr { kind: ExprKind::Path(qpath), @@ -2259,9 +2272,9 @@ pub fn fn_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<DefId> { // Only return Fn-like DefIds, not the DefIds of statics/consts/etc that contain or // deref to fn pointers, dyn Fn, impl Fn - #8850 if let Res::Def(DefKind::Fn | DefKind::Ctor(..) | DefKind::AssocFn, id) = - cx.typeck_results().qpath_res(qpath, *path_hir_id) + typeck.qpath_res(qpath, *path_hir_id) { - Some(id) + Some((id, typeck.node_args(*path_hir_id))) } else { None } diff --git a/src/tools/clippy/clippy_utils/src/paths.rs b/src/tools/clippy/clippy_utils/src/paths.rs index 987f28192a8..456b8019e95 100644 --- a/src/tools/clippy/clippy_utils/src/paths.rs +++ b/src/tools/clippy/clippy_utils/src/paths.rs @@ -19,6 +19,8 @@ pub const BTREESET_ITER: [&str; 6] = ["alloc", "collections", "btree", "set", "B pub const CLONE_TRAIT_METHOD: [&str; 4] = ["core", "clone", "Clone", "clone"]; pub const CORE_ITER_CLONED: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "cloned"]; pub const CORE_ITER_COPIED: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "copied"]; +pub const CORE_ITER_ENUMERATE_METHOD: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "enumerate"]; +pub const CORE_ITER_ENUMERATE_STRUCT: [&str; 5] = ["core", "iter", "adapters", "enumerate", "Enumerate"]; pub const CORE_ITER_FILTER: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "filter"]; pub const CORE_RESULT_OK_METHOD: [&str; 4] = ["core", "result", "Result", "ok"]; pub const CSTRING_AS_C_STR: [&str; 5] = ["alloc", "ffi", "c_str", "CString", "as_c_str"]; diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index 6e011a28bb7..801452e444c 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -96,7 +96,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return false; } - for (predicate, _span) in cx.tcx.explicit_item_bounds(def_id).instantiate_identity_iter_copied() { + for (predicate, _span) in cx.tcx.explicit_item_super_predicates(def_id).instantiate_identity_iter_copied() { match predicate.kind().skip_binder() { // For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through // and check substitutions to find `U`. @@ -328,7 +328,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { }, ty::Tuple(args) => args.iter().any(|ty| is_must_use_ty(cx, ty)), ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { - for (predicate, _) in cx.tcx.explicit_item_bounds(def_id).skip_binder() { + for (predicate, _) in cx.tcx.explicit_item_super_predicates(def_id).skip_binder() { if let ty::ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { return true; @@ -729,7 +729,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => sig_from_bounds( cx, ty, - cx.tcx.item_bounds(def_id).iter_instantiated(cx.tcx, args), + cx.tcx.item_super_predicates(def_id).iter_instantiated(cx.tcx, args), cx.tcx.opt_parent(def_id), ), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), @@ -807,7 +807,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option for (pred, _) in cx .tcx - .explicit_item_bounds(ty.def_id) + .explicit_item_super_predicates(ty.def_id) .iter_instantiated_copied(cx.tcx, ty.args) { match pred.kind().skip_binder() { diff --git a/src/tools/clippy/clippy_utils/src/visitors.rs b/src/tools/clippy/clippy_utils/src/visitors.rs index ebc38e531fe..0a05ac029ea 100644 --- a/src/tools/clippy/clippy_utils/src/visitors.rs +++ b/src/tools/clippy/clippy_utils/src/visitors.rs @@ -5,7 +5,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::intravisit::{self, walk_block, walk_expr, Visitor}; use rustc_hir::{ - AnonConst, Arm, Block, BlockCheckMode, Body, BodyId, Expr, ExprKind, HirId, ItemId, ItemKind, Let, Pat, QPath, + AnonConst, Arm, Block, BlockCheckMode, Body, BodyId, Expr, ExprKind, HirId, ItemId, ItemKind, LetExpr, Pat, QPath, Stmt, UnOp, UnsafeSource, Unsafety, }; use rustc_lint::LateContext; @@ -624,7 +624,7 @@ pub fn for_each_unconsumed_temporary<'tcx, B>( | ExprKind::Field(e, _) | ExprKind::Unary(UnOp::Deref, e) | ExprKind::Match(e, ..) - | ExprKind::Let(&Let { init: e, .. }) => { + | ExprKind::Let(&LetExpr { init: e, .. }) => { helper(typeck, false, e, f)?; }, ExprKind::Block(&Block { expr: Some(e), .. }, _) | ExprKind::Cast(e, _) | ExprKind::Unary(_, e) => { diff --git a/src/tools/clippy/declare_clippy_lint/Cargo.toml b/src/tools/clippy/declare_clippy_lint/Cargo.toml index 296eb8dd340..9a3a41e1d1e 100644 --- a/src/tools/clippy/declare_clippy_lint/Cargo.toml +++ b/src/tools/clippy/declare_clippy_lint/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "declare_clippy_lint" -version = "0.1.78" +version = "0.1.79" edition = "2021" publish = false diff --git a/src/tools/clippy/rust-toolchain b/src/tools/clippy/rust-toolchain index 070b62887d5..a63e66f3214 100644 --- a/src/tools/clippy/rust-toolchain +++ b/src/tools/clippy/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-03-07" +channel = "nightly-2024-03-21" components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"] diff --git a/src/tools/clippy/tests/ui-internal/disallow_span_lint.stderr b/src/tools/clippy/tests/ui-internal/disallow_span_lint.stderr index ae5d6843406..cfc590bed36 100644 --- a/src/tools/clippy/tests/ui-internal/disallow_span_lint.stderr +++ b/src/tools/clippy/tests/ui-internal/disallow_span_lint.stderr @@ -4,6 +4,7 @@ error: use of a disallowed method `rustc_lint::context::LintContext::span_lint` LL | cx.span_lint(lint, span, msg, |_| {}); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint*` functions instead (from clippy.toml) = note: `-D clippy::disallowed-methods` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]` @@ -12,6 +13,8 @@ error: use of a disallowed method `rustc_middle::ty::context::TyCtxt::node_span_ | LL | tcx.node_span_lint(lint, hir_id, span, msg, |_| {}); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint_hir*` functions instead (from clippy.toml) error: aborting due to 2 previous errors diff --git a/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.fixed b/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.fixed new file mode 100644 index 00000000000..d42b29ba21a --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.fixed @@ -0,0 +1,38 @@ +//@compile-flags: --test +#![warn(clippy::dbg_macro)] +#![allow(clippy::unnecessary_operation, clippy::no_effect)] + +fn foo(n: u32) -> u32 { + if let Some(n) = n.checked_sub(4) { n } else { n } +} + +fn factorial(n: u32) -> u32 { + if n <= 1 { + 1 + } else { + n * factorial(n - 1) + } +} + +fn main() { + 42; + foo(3) + factorial(4); + (1, 2, 3, 4, 5); +} + +#[test] +pub fn issue8481() { + dbg!(1); +} + +#[cfg(test)] +fn foo2() { + dbg!(1); +} + +#[cfg(test)] +mod mod1 { + fn func() { + dbg!(1); + } +} diff --git a/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs b/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs index 67129e62477..bd189b1576f 100644 --- a/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs +++ b/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs @@ -1,6 +1,7 @@ //@compile-flags: --test #![warn(clippy::dbg_macro)] -//@no-rustfix +#![allow(clippy::unnecessary_operation, clippy::no_effect)] + fn foo(n: u32) -> u32 { if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } } @@ -15,9 +16,7 @@ fn factorial(n: u32) -> u32 { fn main() { dbg!(42); - dbg!(dbg!(dbg!(42))); foo(3) + dbg!(factorial(4)); - dbg!(1, 2, dbg!(3, 4)); dbg!(1, 2, 3, 4, 5); } diff --git a/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.stderr b/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.stderr index 8ffc426be2d..129fab5ff97 100644 --- a/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.stderr +++ b/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.stderr @@ -1,5 +1,5 @@ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:5:22 + --> tests/ui-toml/dbg_macro/dbg_macro.rs:6:22 | LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } | ^^^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL | if let Some(n) = n.checked_sub(4) { n } else { n } | ~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:9:8 + --> tests/ui-toml/dbg_macro/dbg_macro.rs:10:8 | LL | if dbg!(n <= 1) { | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | if n <= 1 { | ~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:10:9 + --> tests/ui-toml/dbg_macro/dbg_macro.rs:11:9 | LL | dbg!(1) | ^^^^^^^ @@ -34,7 +34,7 @@ LL | 1 | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:12:9 + --> tests/ui-toml/dbg_macro/dbg_macro.rs:13:9 | LL | dbg!(n * factorial(n - 1)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +45,7 @@ LL | n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:17:5 + --> tests/ui-toml/dbg_macro/dbg_macro.rs:18:5 | LL | dbg!(42); | ^^^^^^^^ @@ -56,17 +56,6 @@ LL | 42; | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:18:5 - | -LL | dbg!(dbg!(dbg!(42))); - | ^^^^^^^^^^^^^^^^^^^^ - | -help: remove the invocation before committing it to a version control system - | -LL | dbg!(dbg!(42)); - | ~~~~~~~~~~~~~~ - -error: the `dbg!` macro is intended as a debugging tool --> tests/ui-toml/dbg_macro/dbg_macro.rs:19:14 | LL | foo(3) + dbg!(factorial(4)); @@ -80,17 +69,6 @@ LL | foo(3) + factorial(4); error: the `dbg!` macro is intended as a debugging tool --> tests/ui-toml/dbg_macro/dbg_macro.rs:20:5 | -LL | dbg!(1, 2, dbg!(3, 4)); - | ^^^^^^^^^^^^^^^^^^^^^^ - | -help: remove the invocation before committing it to a version control system - | -LL | (1, 2, dbg!(3, 4)); - | ~~~~~~~~~~~~~~~~~~ - -error: the `dbg!` macro is intended as a debugging tool - --> tests/ui-toml/dbg_macro/dbg_macro.rs:21:5 - | LL | dbg!(1, 2, 3, 4, 5); | ^^^^^^^^^^^^^^^^^^^ | @@ -99,5 +77,5 @@ help: remove the invocation before committing it to a version control system LL | (1, 2, 3, 4, 5); | ~~~~~~~~~~~~~~~ -error: aborting due to 9 previous errors +error: aborting due to 7 previous errors diff --git a/src/tools/clippy/tests/ui/allow_attributes_without_reason.rs b/src/tools/clippy/tests/ui/allow_attributes_without_reason.rs index 663c2eb2c37..523148d6586 100644 --- a/src/tools/clippy/tests/ui/allow_attributes_without_reason.rs +++ b/src/tools/clippy/tests/ui/allow_attributes_without_reason.rs @@ -1,7 +1,7 @@ //@aux-build:proc_macros.rs #![feature(lint_reasons)] #![deny(clippy::allow_attributes_without_reason)] -#![allow(unfulfilled_lint_expectations)] +#![allow(unfulfilled_lint_expectations, clippy::duplicated_attributes)] extern crate proc_macros; use proc_macros::{external, with_span}; diff --git a/src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr b/src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr index 3c81233bf77..770a771ec3d 100644 --- a/src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr +++ b/src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr @@ -1,8 +1,8 @@ error: `allow` attribute without specifying a reason --> tests/ui/allow_attributes_without_reason.rs:4:1 | -LL | #![allow(unfulfilled_lint_expectations)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![allow(unfulfilled_lint_expectations, clippy::duplicated_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: try adding a reason at the end with `, reason = ".."` note: the lint level is defined here diff --git a/src/tools/clippy/tests/ui/assigning_clones.fixed b/src/tools/clippy/tests/ui/assigning_clones.fixed index c66e0c1f602..160f3b94663 100644 --- a/src/tools/clippy/tests/ui/assigning_clones.fixed +++ b/src/tools/clippy/tests/ui/assigning_clones.fixed @@ -128,6 +128,19 @@ fn ignore_generic_clone<T: Clone>(a: &mut T, b: &T) { *a = b.clone(); } +#[clippy::msrv = "1.62"] +fn msrv_1_62(mut a: String, b: String, c: &str) { + a.clone_from(&b); + // Should not be linted, as clone_into wasn't stabilized until 1.63 + a = c.to_owned(); +} + +#[clippy::msrv = "1.63"] +fn msrv_1_63(mut a: String, b: String, c: &str) { + a.clone_from(&b); + c.clone_into(&mut a); +} + macro_rules! clone_inside { ($a:expr, $b: expr) => { $a = $b.clone(); diff --git a/src/tools/clippy/tests/ui/assigning_clones.rs b/src/tools/clippy/tests/ui/assigning_clones.rs index b9f994d3e03..14ba1d4db9a 100644 --- a/src/tools/clippy/tests/ui/assigning_clones.rs +++ b/src/tools/clippy/tests/ui/assigning_clones.rs @@ -128,6 +128,19 @@ fn ignore_generic_clone<T: Clone>(a: &mut T, b: &T) { *a = b.clone(); } +#[clippy::msrv = "1.62"] +fn msrv_1_62(mut a: String, b: String, c: &str) { + a = b.clone(); + // Should not be linted, as clone_into wasn't stabilized until 1.63 + a = c.to_owned(); +} + +#[clippy::msrv = "1.63"] +fn msrv_1_63(mut a: String, b: String, c: &str) { + a = b.clone(); + a = c.to_owned(); +} + macro_rules! clone_inside { ($a:expr, $b: expr) => { $a = $b.clone(); diff --git a/src/tools/clippy/tests/ui/assigning_clones.stderr b/src/tools/clippy/tests/ui/assigning_clones.stderr index b76323f3606..ba59f067431 100644 --- a/src/tools/clippy/tests/ui/assigning_clones.stderr +++ b/src/tools/clippy/tests/ui/assigning_clones.stderr @@ -67,41 +67,59 @@ error: assigning the result of `Clone::clone()` may be inefficient LL | a = b.clone(); | ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)` +error: assigning the result of `Clone::clone()` may be inefficient + --> tests/ui/assigning_clones.rs:133:5 + | +LL | a = b.clone(); + | ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)` + +error: assigning the result of `Clone::clone()` may be inefficient + --> tests/ui/assigning_clones.rs:140:5 + | +LL | a = b.clone(); + | ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)` + +error: assigning the result of `ToOwned::to_owned()` may be inefficient + --> tests/ui/assigning_clones.rs:141:5 + | +LL | a = c.to_owned(); + | ^^^^^^^^^^^^^^^^ help: use `clone_into()`: `c.clone_into(&mut a)` + error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:145:5 + --> tests/ui/assigning_clones.rs:158:5 | LL | *mut_string = ref_str.to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(mut_string)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:149:5 + --> tests/ui/assigning_clones.rs:162:5 | LL | mut_string = ref_str.to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut mut_string)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:170:5 + --> tests/ui/assigning_clones.rs:183:5 | LL | **mut_box_string = ref_str.to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:174:5 + --> tests/ui/assigning_clones.rs:187:5 | LL | **mut_box_string = ref_str.to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:178:5 + --> tests/ui/assigning_clones.rs:191:5 | LL | *mut_thing = ToOwned::to_owned(ref_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, mut_thing)` error: assigning the result of `ToOwned::to_owned()` may be inefficient - --> tests/ui/assigning_clones.rs:182:5 + --> tests/ui/assigning_clones.rs:195:5 | LL | mut_thing = ToOwned::to_owned(ref_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, &mut mut_thing)` -error: aborting due to 17 previous errors +error: aborting due to 20 previous errors diff --git a/src/tools/clippy/tests/ui/async_yields_async.stderr b/src/tools/clippy/tests/ui/async_yields_async.stderr index f1fae6549de..991ad7ae0ae 100644 --- a/src/tools/clippy/tests/ui/async_yields_async.stderr +++ b/src/tools/clippy/tests/ui/async_yields_async.stderr @@ -81,8 +81,7 @@ LL | let _m = async || { | _______________________- LL | | println!("I'm bored"); LL | | // Some more stuff -LL | | -LL | | // Finally something to await +... | LL | | CustomFutureType | | ^^^^^^^^^^^^^^^^ | | | diff --git a/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs b/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs index 75f7a20f961..a6f3b164c9b 100644 --- a/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs +++ b/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs @@ -11,8 +11,8 @@ use quote::{quote, quote_spanned}; use syn::spanned::Spanned; use syn::token::Star; use syn::{ - parse_macro_input, parse_quote, FnArg, ImplItem, ItemFn, ItemImpl, ItemTrait, Lifetime, Pat, PatIdent, PatType, - Signature, TraitItem, Type, + parse_macro_input, parse_quote, FnArg, ImplItem, ItemFn, ItemImpl, ItemStruct, ItemTrait, Lifetime, Pat, PatIdent, + PatType, Signature, TraitItem, Type, Visibility, }; #[proc_macro_attribute] @@ -101,9 +101,7 @@ pub fn fake_main(_attr: TokenStream, item: TokenStream) -> TokenStream { let mut item = parse_macro_input!(item as ItemFn); let span = item.block.brace_token.span; - if item.sig.asyncness.is_some() { - item.sig.asyncness = None; - } + item.sig.asyncness = None; let crate_name = quote! { fake_crate }; let block = item.block; @@ -128,7 +126,7 @@ pub fn fake_main(_attr: TokenStream, item: TokenStream) -> TokenStream { #[proc_macro_attribute] pub fn fake_desugar_await(_args: TokenStream, input: TokenStream) -> TokenStream { - let mut async_fn = syn::parse_macro_input!(input as syn::ItemFn); + let mut async_fn = parse_macro_input!(input as syn::ItemFn); for stmt in &mut async_fn.block.stmts { if let syn::Stmt::Expr(syn::Expr::Match(syn::ExprMatch { expr: scrutinee, .. }), _) = stmt { @@ -145,3 +143,36 @@ pub fn fake_desugar_await(_args: TokenStream, input: TokenStream) -> TokenStream quote!(#async_fn).into() } + +#[proc_macro_attribute] +pub fn rewrite_struct(_args: TokenStream, input: TokenStream) -> TokenStream { + let mut item_struct = parse_macro_input!(input as syn::ItemStruct); + // remove struct attributes including doc comments. + item_struct.attrs = vec![]; + if let Visibility::Public(token) = item_struct.vis { + // set vis to `pub(crate)` to trigger `missing_docs_in_private_items` lint. + let new_vis: Visibility = syn::parse_quote_spanned!(token.span() => pub(crate)); + item_struct.vis = new_vis; + } + if let syn::Fields::Named(fields) = &mut item_struct.fields { + for field in &mut fields.named { + // remove all attributes from fields as well. + field.attrs = vec![]; + } + } + + quote!(#item_struct).into() +} + +#[proc_macro_attribute] +pub fn with_empty_docs(_attr: TokenStream, input: TokenStream) -> TokenStream { + let item = parse_macro_input!(input as syn::Item); + let attrs: Vec<syn::Attribute> = vec![]; + let doc_comment = ""; + quote! { + #(#attrs)* + #[doc = #doc_comment] + #item + } + .into() +} diff --git a/src/tools/clippy/tests/ui/await_holding_lock.rs b/src/tools/clippy/tests/ui/await_holding_lock.rs index 27b57b64813..8e5510e6cd0 100644 --- a/src/tools/clippy/tests/ui/await_holding_lock.rs +++ b/src/tools/clippy/tests/ui/await_holding_lock.rs @@ -1,4 +1,5 @@ #![warn(clippy::await_holding_lock)] +#![allow(clippy::readonly_write_lock)] // When adding or modifying a test, please do the same for parking_lot::Mutex. mod std_mutex { diff --git a/src/tools/clippy/tests/ui/await_holding_lock.stderr b/src/tools/clippy/tests/ui/await_holding_lock.stderr index e58436345b5..0af48a36acc 100644 --- a/src/tools/clippy/tests/ui/await_holding_lock.stderr +++ b/src/tools/clippy/tests/ui/await_holding_lock.stderr @@ -1,12 +1,12 @@ error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:9:13 + --> tests/ui/await_holding_lock.rs:10:13 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:11:15 + --> tests/ui/await_holding_lock.rs:12:15 | LL | baz().await | ^^^^^ @@ -14,40 +14,40 @@ LL | baz().await = help: to override `-D warnings` add `#[allow(clippy::await_holding_lock)]` error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:25:13 + --> tests/ui/await_holding_lock.rs:26:13 | LL | let guard = x.read().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:27:15 + --> tests/ui/await_holding_lock.rs:28:15 | LL | baz().await | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:31:13 + --> tests/ui/await_holding_lock.rs:32:13 | LL | let mut guard = x.write().unwrap(); | ^^^^^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:33:15 + --> tests/ui/await_holding_lock.rs:34:15 | LL | baz().await | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:53:13 + --> tests/ui/await_holding_lock.rs:54:13 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:56:28 + --> tests/ui/await_holding_lock.rs:57:28 | LL | let second = baz().await; | ^^^^^ @@ -56,79 +56,79 @@ LL | let third = baz().await; | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:67:17 + --> tests/ui/await_holding_lock.rs:68:17 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:69:19 + --> tests/ui/await_holding_lock.rs:70:19 | LL | baz().await | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:80:17 + --> tests/ui/await_holding_lock.rs:81:17 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:82:19 + --> tests/ui/await_holding_lock.rs:83:19 | LL | baz().await | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:93:13 + --> tests/ui/await_holding_lock.rs:94:13 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:95:15 + --> tests/ui/await_holding_lock.rs:96:15 | LL | baz().await | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:109:13 + --> tests/ui/await_holding_lock.rs:110:13 | LL | let guard = x.read(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:111:15 + --> tests/ui/await_holding_lock.rs:112:15 | LL | baz().await | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:115:13 + --> tests/ui/await_holding_lock.rs:116:13 | LL | let mut guard = x.write(); | ^^^^^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:117:15 + --> tests/ui/await_holding_lock.rs:118:15 | LL | baz().await | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:137:13 + --> tests/ui/await_holding_lock.rs:138:13 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:140:28 + --> tests/ui/await_holding_lock.rs:141:28 | LL | let second = baz().await; | ^^^^^ @@ -137,40 +137,40 @@ LL | let third = baz().await; | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:151:17 + --> tests/ui/await_holding_lock.rs:152:17 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:153:19 + --> tests/ui/await_holding_lock.rs:154:19 | LL | baz().await | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:164:17 + --> tests/ui/await_holding_lock.rs:165:17 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:166:19 + --> tests/ui/await_holding_lock.rs:167:19 | LL | baz().await | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> tests/ui/await_holding_lock.rs:185:9 + --> tests/ui/await_holding_lock.rs:186:9 | LL | let mut guard = x.lock().unwrap(); | ^^^^^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> tests/ui/await_holding_lock.rs:189:11 + --> tests/ui/await_holding_lock.rs:190:11 | LL | baz().await; | ^^^^^ diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.fixed b/src/tools/clippy/tests/ui/bool_assert_comparison.fixed index 63b8e27e1c6..b05166a055e 100644 --- a/src/tools/clippy/tests/ui/bool_assert_comparison.fixed +++ b/src/tools/clippy/tests/ui/bool_assert_comparison.fixed @@ -1,4 +1,4 @@ -#![allow(unused, clippy::assertions_on_constants)] +#![allow(unused, clippy::assertions_on_constants, clippy::const_is_empty)] #![warn(clippy::bool_assert_comparison)] use std::ops::Not; diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.rs b/src/tools/clippy/tests/ui/bool_assert_comparison.rs index 58f81fedb79..dc51fcf1d36 100644 --- a/src/tools/clippy/tests/ui/bool_assert_comparison.rs +++ b/src/tools/clippy/tests/ui/bool_assert_comparison.rs @@ -1,4 +1,4 @@ -#![allow(unused, clippy::assertions_on_constants)] +#![allow(unused, clippy::assertions_on_constants, clippy::const_is_empty)] #![warn(clippy::bool_assert_comparison)] use std::ops::Not; diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.fixed b/src/tools/clippy/tests/ui/cast_lossless_bool.fixed index a4ce1c6f928..51a38a60cf6 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_bool.fixed +++ b/src/tools/clippy/tests/ui/cast_lossless_bool.fixed @@ -1,6 +1,8 @@ #![allow(dead_code)] #![warn(clippy::cast_lossless)] +type U8 = u8; + fn main() { // Test clippy::cast_lossless with casts to integer types let _ = u8::from(true); @@ -19,6 +21,8 @@ fn main() { // Test with an expression wrapped in parens let _ = u16::from(true | false); + + let _ = U8::from(true); } // The lint would suggest using `u32::from(input)` here but the `XX::from` function is not const, diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.rs b/src/tools/clippy/tests/ui/cast_lossless_bool.rs index e5b1c30c103..cb307bd68e4 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_bool.rs +++ b/src/tools/clippy/tests/ui/cast_lossless_bool.rs @@ -1,6 +1,8 @@ #![allow(dead_code)] #![warn(clippy::cast_lossless)] +type U8 = u8; + fn main() { // Test clippy::cast_lossless with casts to integer types let _ = true as u8; @@ -19,6 +21,8 @@ fn main() { // Test with an expression wrapped in parens let _ = (true | false) as u16; + + let _ = true as U8; } // The lint would suggest using `u32::from(input)` here but the `XX::from` function is not const, diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.stderr b/src/tools/clippy/tests/ui/cast_lossless_bool.stderr index 792b30b7a38..b47b35461f6 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_bool.stderr +++ b/src/tools/clippy/tests/ui/cast_lossless_bool.stderr @@ -1,5 +1,5 @@ error: casting `bool` to `u8` is more cleanly stated with `u8::from(_)` - --> tests/ui/cast_lossless_bool.rs:6:13 + --> tests/ui/cast_lossless_bool.rs:8:13 | LL | let _ = true as u8; | ^^^^^^^^^^ help: try: `u8::from(true)` @@ -8,82 +8,88 @@ LL | let _ = true as u8; = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)` - --> tests/ui/cast_lossless_bool.rs:7:13 + --> tests/ui/cast_lossless_bool.rs:9:13 | LL | let _ = true as u16; | ^^^^^^^^^^^ help: try: `u16::from(true)` error: casting `bool` to `u32` is more cleanly stated with `u32::from(_)` - --> tests/ui/cast_lossless_bool.rs:8:13 + --> tests/ui/cast_lossless_bool.rs:10:13 | LL | let _ = true as u32; | ^^^^^^^^^^^ help: try: `u32::from(true)` error: casting `bool` to `u64` is more cleanly stated with `u64::from(_)` - --> tests/ui/cast_lossless_bool.rs:9:13 + --> tests/ui/cast_lossless_bool.rs:11:13 | LL | let _ = true as u64; | ^^^^^^^^^^^ help: try: `u64::from(true)` error: casting `bool` to `u128` is more cleanly stated with `u128::from(_)` - --> tests/ui/cast_lossless_bool.rs:10:13 + --> tests/ui/cast_lossless_bool.rs:12:13 | LL | let _ = true as u128; | ^^^^^^^^^^^^ help: try: `u128::from(true)` error: casting `bool` to `usize` is more cleanly stated with `usize::from(_)` - --> tests/ui/cast_lossless_bool.rs:11:13 + --> tests/ui/cast_lossless_bool.rs:13:13 | LL | let _ = true as usize; | ^^^^^^^^^^^^^ help: try: `usize::from(true)` error: casting `bool` to `i8` is more cleanly stated with `i8::from(_)` - --> tests/ui/cast_lossless_bool.rs:13:13 + --> tests/ui/cast_lossless_bool.rs:15:13 | LL | let _ = true as i8; | ^^^^^^^^^^ help: try: `i8::from(true)` error: casting `bool` to `i16` is more cleanly stated with `i16::from(_)` - --> tests/ui/cast_lossless_bool.rs:14:13 + --> tests/ui/cast_lossless_bool.rs:16:13 | LL | let _ = true as i16; | ^^^^^^^^^^^ help: try: `i16::from(true)` error: casting `bool` to `i32` is more cleanly stated with `i32::from(_)` - --> tests/ui/cast_lossless_bool.rs:15:13 + --> tests/ui/cast_lossless_bool.rs:17:13 | LL | let _ = true as i32; | ^^^^^^^^^^^ help: try: `i32::from(true)` error: casting `bool` to `i64` is more cleanly stated with `i64::from(_)` - --> tests/ui/cast_lossless_bool.rs:16:13 + --> tests/ui/cast_lossless_bool.rs:18:13 | LL | let _ = true as i64; | ^^^^^^^^^^^ help: try: `i64::from(true)` error: casting `bool` to `i128` is more cleanly stated with `i128::from(_)` - --> tests/ui/cast_lossless_bool.rs:17:13 + --> tests/ui/cast_lossless_bool.rs:19:13 | LL | let _ = true as i128; | ^^^^^^^^^^^^ help: try: `i128::from(true)` error: casting `bool` to `isize` is more cleanly stated with `isize::from(_)` - --> tests/ui/cast_lossless_bool.rs:18:13 + --> tests/ui/cast_lossless_bool.rs:20:13 | LL | let _ = true as isize; | ^^^^^^^^^^^^^ help: try: `isize::from(true)` error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)` - --> tests/ui/cast_lossless_bool.rs:21:13 + --> tests/ui/cast_lossless_bool.rs:23:13 | LL | let _ = (true | false) as u16; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::from(true | false)` +error: casting `bool` to `U8` is more cleanly stated with `U8::from(_)` + --> tests/ui/cast_lossless_bool.rs:25:13 + | +LL | let _ = true as U8; + | ^^^^^^^^^^ help: try: `U8::from(true)` + error: casting `bool` to `u8` is more cleanly stated with `u8::from(_)` - --> tests/ui/cast_lossless_bool.rs:49:13 + --> tests/ui/cast_lossless_bool.rs:53:13 | LL | let _ = true as u8; | ^^^^^^^^^^ help: try: `u8::from(true)` -error: aborting due to 14 previous errors +error: aborting due to 15 previous errors diff --git a/src/tools/clippy/tests/ui/cast_lossless_float.fixed b/src/tools/clippy/tests/ui/cast_lossless_float.fixed index f4f2e4773a5..96a67b1945c 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_float.fixed +++ b/src/tools/clippy/tests/ui/cast_lossless_float.fixed @@ -1,11 +1,16 @@ #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] +type F32 = f32; +type F64 = f64; + fn main() { // Test clippy::cast_lossless with casts to floating-point types let x0 = 1i8; let _ = f32::from(x0); let _ = f64::from(x0); + let _ = F32::from(x0); + let _ = F64::from(x0); let x1 = 1u8; let _ = f32::from(x1); let _ = f64::from(x1); diff --git a/src/tools/clippy/tests/ui/cast_lossless_float.rs b/src/tools/clippy/tests/ui/cast_lossless_float.rs index fdd88ed36fc..d37b2c1d920 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_float.rs +++ b/src/tools/clippy/tests/ui/cast_lossless_float.rs @@ -1,11 +1,16 @@ #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] +type F32 = f32; +type F64 = f64; + fn main() { // Test clippy::cast_lossless with casts to floating-point types let x0 = 1i8; let _ = x0 as f32; let _ = x0 as f64; + let _ = x0 as F32; + let _ = x0 as F64; let x1 = 1u8; let _ = x1 as f32; let _ = x1 as f64; diff --git a/src/tools/clippy/tests/ui/cast_lossless_float.stderr b/src/tools/clippy/tests/ui/cast_lossless_float.stderr index e70f81eb91f..ad7de760adf 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_float.stderr +++ b/src/tools/clippy/tests/ui/cast_lossless_float.stderr @@ -1,5 +1,5 @@ error: casting `i8` to `f32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:7:13 + --> tests/ui/cast_lossless_float.rs:10:13 | LL | let _ = x0 as f32; | ^^^^^^^^^ help: try: `f32::from(x0)` @@ -8,64 +8,76 @@ LL | let _ = x0 as f32; = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` error: casting `i8` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:8:13 + --> tests/ui/cast_lossless_float.rs:11:13 | LL | let _ = x0 as f64; | ^^^^^^^^^ help: try: `f64::from(x0)` +error: casting `i8` to `F32` may become silently lossy if you later change the type + --> tests/ui/cast_lossless_float.rs:12:13 + | +LL | let _ = x0 as F32; + | ^^^^^^^^^ help: try: `F32::from(x0)` + +error: casting `i8` to `F64` may become silently lossy if you later change the type + --> tests/ui/cast_lossless_float.rs:13:13 + | +LL | let _ = x0 as F64; + | ^^^^^^^^^ help: try: `F64::from(x0)` + error: casting `u8` to `f32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:10:13 + --> tests/ui/cast_lossless_float.rs:15:13 | LL | let _ = x1 as f32; | ^^^^^^^^^ help: try: `f32::from(x1)` error: casting `u8` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:11:13 + --> tests/ui/cast_lossless_float.rs:16:13 | LL | let _ = x1 as f64; | ^^^^^^^^^ help: try: `f64::from(x1)` error: casting `i16` to `f32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:13:13 + --> tests/ui/cast_lossless_float.rs:18:13 | LL | let _ = x2 as f32; | ^^^^^^^^^ help: try: `f32::from(x2)` error: casting `i16` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:14:13 + --> tests/ui/cast_lossless_float.rs:19:13 | LL | let _ = x2 as f64; | ^^^^^^^^^ help: try: `f64::from(x2)` error: casting `u16` to `f32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:16:13 + --> tests/ui/cast_lossless_float.rs:21:13 | LL | let _ = x3 as f32; | ^^^^^^^^^ help: try: `f32::from(x3)` error: casting `u16` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:17:13 + --> tests/ui/cast_lossless_float.rs:22:13 | LL | let _ = x3 as f64; | ^^^^^^^^^ help: try: `f64::from(x3)` error: casting `i32` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:19:13 + --> tests/ui/cast_lossless_float.rs:24:13 | LL | let _ = x4 as f64; | ^^^^^^^^^ help: try: `f64::from(x4)` error: casting `u32` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:21:13 + --> tests/ui/cast_lossless_float.rs:26:13 | LL | let _ = x5 as f64; | ^^^^^^^^^ help: try: `f64::from(x5)` error: casting `f32` to `f64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_float.rs:24:13 + --> tests/ui/cast_lossless_float.rs:29:13 | LL | let _ = 1.0f32 as f64; | ^^^^^^^^^^^^^ help: try: `f64::from(1.0f32)` -error: aborting due to 11 previous errors +error: aborting due to 13 previous errors diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.fixed b/src/tools/clippy/tests/ui/cast_lossless_integer.fixed index 5e7e545e764..291556a9774 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_integer.fixed +++ b/src/tools/clippy/tests/ui/cast_lossless_integer.fixed @@ -1,6 +1,9 @@ #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] +type I64 = i64; +type U128 = u128; + fn main() { // Test clippy::cast_lossless with casts to integer types let _ = i16::from(1i8); @@ -24,6 +27,13 @@ fn main() { // Test with an expression wrapped in parens let _ = u16::from(1u8 + 1u8); + + let _ = I64::from(1i8); + + // Do not lint if destination type is u128 + // see https://github.com/rust-lang/rust-clippy/issues/12492 + let _ = 1u8 as u128; + let _ = 1u8 as U128; } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.rs b/src/tools/clippy/tests/ui/cast_lossless_integer.rs index 0d69ddbd586..a917c7a371d 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_integer.rs +++ b/src/tools/clippy/tests/ui/cast_lossless_integer.rs @@ -1,6 +1,9 @@ #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] +type I64 = i64; +type U128 = u128; + fn main() { // Test clippy::cast_lossless with casts to integer types let _ = 1i8 as i16; @@ -24,6 +27,13 @@ fn main() { // Test with an expression wrapped in parens let _ = (1u8 + 1u8) as u16; + + let _ = 1i8 as I64; + + // Do not lint if destination type is u128 + // see https://github.com/rust-lang/rust-clippy/issues/12492 + let _ = 1u8 as u128; + let _ = 1u8 as U128; } // The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const, diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.stderr b/src/tools/clippy/tests/ui/cast_lossless_integer.stderr index 43d4ce3ce91..aaece939285 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_integer.stderr +++ b/src/tools/clippy/tests/ui/cast_lossless_integer.stderr @@ -1,5 +1,5 @@ error: casting `i8` to `i16` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:6:13 + --> tests/ui/cast_lossless_integer.rs:9:13 | LL | let _ = 1i8 as i16; | ^^^^^^^^^^ help: try: `i16::from(1i8)` @@ -8,124 +8,130 @@ LL | let _ = 1i8 as i16; = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` error: casting `i8` to `i32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:7:13 + --> tests/ui/cast_lossless_integer.rs:10:13 | LL | let _ = 1i8 as i32; | ^^^^^^^^^^ help: try: `i32::from(1i8)` error: casting `i8` to `i64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:8:13 + --> tests/ui/cast_lossless_integer.rs:11:13 | LL | let _ = 1i8 as i64; | ^^^^^^^^^^ help: try: `i64::from(1i8)` error: casting `u8` to `i16` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:9:13 + --> tests/ui/cast_lossless_integer.rs:12:13 | LL | let _ = 1u8 as i16; | ^^^^^^^^^^ help: try: `i16::from(1u8)` error: casting `u8` to `i32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:10:13 + --> tests/ui/cast_lossless_integer.rs:13:13 | LL | let _ = 1u8 as i32; | ^^^^^^^^^^ help: try: `i32::from(1u8)` error: casting `u8` to `i64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:11:13 + --> tests/ui/cast_lossless_integer.rs:14:13 | LL | let _ = 1u8 as i64; | ^^^^^^^^^^ help: try: `i64::from(1u8)` error: casting `u8` to `u16` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:12:13 + --> tests/ui/cast_lossless_integer.rs:15:13 | LL | let _ = 1u8 as u16; | ^^^^^^^^^^ help: try: `u16::from(1u8)` error: casting `u8` to `u32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:13:13 + --> tests/ui/cast_lossless_integer.rs:16:13 | LL | let _ = 1u8 as u32; | ^^^^^^^^^^ help: try: `u32::from(1u8)` error: casting `u8` to `u64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:14:13 + --> tests/ui/cast_lossless_integer.rs:17:13 | LL | let _ = 1u8 as u64; | ^^^^^^^^^^ help: try: `u64::from(1u8)` error: casting `i16` to `i32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:15:13 + --> tests/ui/cast_lossless_integer.rs:18:13 | LL | let _ = 1i16 as i32; | ^^^^^^^^^^^ help: try: `i32::from(1i16)` error: casting `i16` to `i64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:16:13 + --> tests/ui/cast_lossless_integer.rs:19:13 | LL | let _ = 1i16 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1i16)` error: casting `u16` to `i32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:17:13 + --> tests/ui/cast_lossless_integer.rs:20:13 | LL | let _ = 1u16 as i32; | ^^^^^^^^^^^ help: try: `i32::from(1u16)` error: casting `u16` to `i64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:18:13 + --> tests/ui/cast_lossless_integer.rs:21:13 | LL | let _ = 1u16 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1u16)` error: casting `u16` to `u32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:19:13 + --> tests/ui/cast_lossless_integer.rs:22:13 | LL | let _ = 1u16 as u32; | ^^^^^^^^^^^ help: try: `u32::from(1u16)` error: casting `u16` to `u64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:20:13 + --> tests/ui/cast_lossless_integer.rs:23:13 | LL | let _ = 1u16 as u64; | ^^^^^^^^^^^ help: try: `u64::from(1u16)` error: casting `i32` to `i64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:21:13 + --> tests/ui/cast_lossless_integer.rs:24:13 | LL | let _ = 1i32 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1i32)` error: casting `u32` to `i64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:22:13 + --> tests/ui/cast_lossless_integer.rs:25:13 | LL | let _ = 1u32 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1u32)` error: casting `u32` to `u64` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:23:13 + --> tests/ui/cast_lossless_integer.rs:26:13 | LL | let _ = 1u32 as u64; | ^^^^^^^^^^^ help: try: `u64::from(1u32)` error: casting `u8` to `u16` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:26:13 + --> tests/ui/cast_lossless_integer.rs:29:13 | LL | let _ = (1u8 + 1u8) as u16; | ^^^^^^^^^^^^^^^^^^ help: try: `u16::from(1u8 + 1u8)` +error: casting `i8` to `I64` may become silently lossy if you later change the type + --> tests/ui/cast_lossless_integer.rs:31:13 + | +LL | let _ = 1i8 as I64; + | ^^^^^^^^^^ help: try: `I64::from(1i8)` + error: casting `i8` to `i32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:60:13 + --> tests/ui/cast_lossless_integer.rs:70:13 | LL | let _ = sign_cast!(x, u8, i8) as i32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::from(sign_cast!(x, u8, i8))` error: casting `i8` to `i32` may become silently lossy if you later change the type - --> tests/ui/cast_lossless_integer.rs:61:13 + --> tests/ui/cast_lossless_integer.rs:71:13 | LL | let _ = (sign_cast!(x, u8, i8) + 1) as i32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::from(sign_cast!(x, u8, i8) + 1)` -error: aborting due to 21 previous errors +error: aborting due to 22 previous errors diff --git a/src/tools/clippy/tests/ui/const_is_empty.rs b/src/tools/clippy/tests/ui/const_is_empty.rs new file mode 100644 index 00000000000..ae37a82e4f9 --- /dev/null +++ b/src/tools/clippy/tests/ui/const_is_empty.rs @@ -0,0 +1,174 @@ +#![feature(inline_const)] +#![warn(clippy::const_is_empty)] +#![allow(clippy::needless_late_init, unused_must_use)] + +fn test_literal() { + if "".is_empty() { + //~^ERROR: this expression always evaluates to true + } + if "foobar".is_empty() { + //~^ERROR: this expression always evaluates to false + } +} + +fn test_byte_literal() { + if b"".is_empty() { + //~^ERROR: this expression always evaluates to true + } + if b"foobar".is_empty() { + //~^ERROR: this expression always evaluates to false + } +} + +fn test_no_mut() { + let mut empty = ""; + if empty.is_empty() { + // No lint because it is mutable + } +} + +fn test_propagated() { + let empty = ""; + let non_empty = "foobar"; + let empty2 = empty; + let non_empty2 = non_empty; + if empty2.is_empty() { + //~^ERROR: this expression always evaluates to true + } + if non_empty2.is_empty() { + //~^ERROR: this expression always evaluates to false + } +} + +const EMPTY_STR: &str = ""; +const NON_EMPTY_STR: &str = "foo"; +const EMPTY_BSTR: &[u8] = b""; +const NON_EMPTY_BSTR: &[u8] = b"foo"; +const EMPTY_U8_SLICE: &[u8] = &[]; +const NON_EMPTY_U8_SLICE: &[u8] = &[1, 2]; +const EMPTY_SLICE: &[u32] = &[]; +const NON_EMPTY_SLICE: &[u32] = &[1, 2]; +const NON_EMPTY_SLICE_REPEAT: &[u32] = &[1; 2]; +const EMPTY_ARRAY: [u32; 0] = []; +const EMPTY_ARRAY_REPEAT: [u32; 0] = [1; 0]; +const NON_EMPTY_ARRAY: [u32; 2] = [1, 2]; +const NON_EMPTY_ARRAY_REPEAT: [u32; 2] = [1; 2]; +const EMPTY_REF_ARRAY: &[u32; 0] = &[]; +const NON_EMPTY_REF_ARRAY: &[u32; 3] = &[1, 2, 3]; + +fn test_from_const() { + let _ = EMPTY_STR.is_empty(); + //~^ ERROR: this expression always evaluates to true + let _ = NON_EMPTY_STR.is_empty(); + //~^ ERROR: this expression always evaluates to false + let _ = EMPTY_BSTR.is_empty(); + //~^ ERROR: this expression always evaluates to true + let _ = NON_EMPTY_BSTR.is_empty(); + //~^ ERROR: this expression always evaluates to false + let _ = EMPTY_ARRAY.is_empty(); + //~^ ERROR: this expression always evaluates to true + let _ = EMPTY_ARRAY_REPEAT.is_empty(); + //~^ ERROR: this expression always evaluates to true + let _ = EMPTY_U8_SLICE.is_empty(); + //~^ ERROR: this expression always evaluates to true + let _ = NON_EMPTY_U8_SLICE.is_empty(); + //~^ ERROR: this expression always evaluates to false + let _ = NON_EMPTY_ARRAY.is_empty(); + //~^ ERROR: this expression always evaluates to false + let _ = NON_EMPTY_ARRAY_REPEAT.is_empty(); + //~^ ERROR: this expression always evaluates to false + let _ = EMPTY_REF_ARRAY.is_empty(); + //~^ ERROR: this expression always evaluates to true + let _ = NON_EMPTY_REF_ARRAY.is_empty(); + //~^ ERROR: this expression always evaluates to false + let _ = EMPTY_SLICE.is_empty(); + //~^ ERROR: this expression always evaluates to true + let _ = NON_EMPTY_SLICE.is_empty(); + //~^ ERROR: this expression always evaluates to false + let _ = NON_EMPTY_SLICE_REPEAT.is_empty(); + //~^ ERROR: this expression always evaluates to false +} + +fn main() { + let value = "foobar"; + let _ = value.is_empty(); + //~^ ERROR: this expression always evaluates to false + let x = value; + let _ = x.is_empty(); + //~^ ERROR: this expression always evaluates to false + let _ = "".is_empty(); + //~^ ERROR: this expression always evaluates to true + let _ = b"".is_empty(); + //~^ ERROR: this expression always evaluates to true +} + +fn str_from_arg(var: &str) { + var.is_empty(); + // Do not lint, we know nothiny about var +} + +fn update_str() { + let mut value = "duck"; + value = "penguin"; + + let _ = value.is_empty(); + // Do not lint since value is mutable +} + +fn macros() { + // Content from Macro + let file = include_str!("const_is_empty.rs"); + let _ = file.is_empty(); + // No lint because initializer comes from a macro result + + let var = env!("PATH"); + let _ = var.is_empty(); + // No lint because initializer comes from a macro result +} + +fn conditional_value() { + let value; + + if true { + value = "hey"; + } else { + value = "hej"; + } + + let _ = value.is_empty(); + // Do not lint, current constant folding is too simple to detect this +} + +fn cfg_conditioned() { + #[cfg(test)] + let val = ""; + #[cfg(not(test))] + let val = "foo"; + + let _ = val.is_empty(); + // Do not lint, value depend on a #[cfg(…)] directive +} + +fn not_cfg_conditioned() { + let val = ""; + #[cfg(not(target_os = "inexistent"))] + let _ = val.is_empty(); + //~^ ERROR: this expression always evaluates to true +} + +const fn const_rand() -> &'static str { + "17" +} + +fn const_expressions() { + let _ = const { if true { "1" } else { "2" } }.is_empty(); + // Do not lint, we do not recurse into boolean expressions + + let _ = const_rand().is_empty(); + // Do not lint, we do not recurse into functions +} + +fn constant_from_external_crate() { + let _ = std::env::consts::EXE_EXTENSION.is_empty(); + // Do not lint, `exe_ext` comes from the `std` crate +} diff --git a/src/tools/clippy/tests/ui/const_is_empty.stderr b/src/tools/clippy/tests/ui/const_is_empty.stderr new file mode 100644 index 00000000000..0e09da77bb4 --- /dev/null +++ b/src/tools/clippy/tests/ui/const_is_empty.stderr @@ -0,0 +1,161 @@ +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:6:8 + | +LL | if "".is_empty() { + | ^^^^^^^^^^^^^ + | + = note: `-D clippy::const-is-empty` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::const_is_empty)]` + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:9:8 + | +LL | if "foobar".is_empty() { + | ^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:15:8 + | +LL | if b"".is_empty() { + | ^^^^^^^^^^^^^^ + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:18:8 + | +LL | if b"foobar".is_empty() { + | ^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:35:8 + | +LL | if empty2.is_empty() { + | ^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:38:8 + | +LL | if non_empty2.is_empty() { + | ^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:60:13 + | +LL | let _ = EMPTY_STR.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:62:13 + | +LL | let _ = NON_EMPTY_STR.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:64:13 + | +LL | let _ = EMPTY_BSTR.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:66:13 + | +LL | let _ = NON_EMPTY_BSTR.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:68:13 + | +LL | let _ = EMPTY_ARRAY.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:70:13 + | +LL | let _ = EMPTY_ARRAY_REPEAT.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:72:13 + | +LL | let _ = EMPTY_U8_SLICE.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:74:13 + | +LL | let _ = NON_EMPTY_U8_SLICE.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:76:13 + | +LL | let _ = NON_EMPTY_ARRAY.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:78:13 + | +LL | let _ = NON_EMPTY_ARRAY_REPEAT.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:80:13 + | +LL | let _ = EMPTY_REF_ARRAY.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:82:13 + | +LL | let _ = NON_EMPTY_REF_ARRAY.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:84:13 + | +LL | let _ = EMPTY_SLICE.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:86:13 + | +LL | let _ = NON_EMPTY_SLICE.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:88:13 + | +LL | let _ = NON_EMPTY_SLICE_REPEAT.is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:94:13 + | +LL | let _ = value.is_empty(); + | ^^^^^^^^^^^^^^^^ + +error: this expression always evaluates to false + --> tests/ui/const_is_empty.rs:97:13 + | +LL | let _ = x.is_empty(); + | ^^^^^^^^^^^^ + +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:99:13 + | +LL | let _ = "".is_empty(); + | ^^^^^^^^^^^^^ + +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:101:13 + | +LL | let _ = b"".is_empty(); + | ^^^^^^^^^^^^^^ + +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:155:13 + | +LL | let _ = val.is_empty(); + | ^^^^^^^^^^^^^^ + +error: aborting due to 26 previous errors + diff --git a/src/tools/clippy/tests/ui/crashes/ice-12491.fixed b/src/tools/clippy/tests/ui/crashes/ice-12491.fixed new file mode 100644 index 00000000000..4ea480b0663 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-12491.fixed @@ -0,0 +1,7 @@ +#![warn(clippy::needless_return)] + +fn main() { + if (true) { + // anything一些中文 + } +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-12491.rs b/src/tools/clippy/tests/ui/crashes/ice-12491.rs new file mode 100644 index 00000000000..60add6afa2c --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-12491.rs @@ -0,0 +1,8 @@ +#![warn(clippy::needless_return)] + +fn main() { + if (true) { + // anything一些中文 + return; + } +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-12491.stderr b/src/tools/clippy/tests/ui/crashes/ice-12491.stderr new file mode 100644 index 00000000000..7cc418898e8 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-12491.stderr @@ -0,0 +1,19 @@ +error: unneeded `return` statement + --> tests/ui/crashes/ice-12491.rs:5:24 + | +LL | // anything一些中文 + | ____________________________^ +LL | | return; + | |______________^ + | + = note: `-D clippy::needless-return` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_return)]` +help: remove `return` + | +LL - // anything一些中文 +LL - return; +LL + // anything一些中文 + | + +error: aborting due to 1 previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-6179.rs b/src/tools/clippy/tests/ui/crashes/ice-6179.rs index fffc0f7d0d4..91160eef03d 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6179.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-6179.rs @@ -1,5 +1,5 @@ //! This is a minimal reproducer for the ICE in https://github.com/rust-lang/rust-clippy/pull/6179. -//! The ICE is mainly caused by using `hir_ty_to_ty`. See the discussion in the PR for details. +//! The ICE is mainly caused by using `lower_ty`. See the discussion in the PR for details. #![warn(clippy::use_self)] #![allow(dead_code, clippy::let_with_type_underscore)] diff --git a/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.fixed b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.fixed new file mode 100644 index 00000000000..e3525191423 --- /dev/null +++ b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.fixed @@ -0,0 +1,111 @@ +#![warn(clippy::dbg_macro)] +#![allow(clippy::unnecessary_operation, clippy::no_effect)] + +fn foo(n: u32) -> u32 { + if let Some(n) = n.checked_sub(4) { n } else { n } + //~^ ERROR: the `dbg!` macro is intended as a debugging tool +} +fn bar(_: ()) {} + +fn factorial(n: u32) -> u32 { + if n <= 1 { + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + 1 + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + } else { + n * factorial(n - 1) + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + } +} + +fn main() { + 42; + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + foo(3) + factorial(4); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + (1, 2, 3, 4, 5); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool +} + +fn issue9914() { + macro_rules! foo { + ($x:expr) => { + $x; + }; + } + macro_rules! foo2 { + ($x:expr) => { + $x; + }; + } + macro_rules! expand_to_dbg { + () => { + + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + }; + } + + + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + #[allow(clippy::let_unit_value)] + let _ = (); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + bar(()); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + foo!(()); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + foo2!(foo!(())); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + expand_to_dbg!(); +} + +mod issue7274 { + trait Thing<'b> { + fn foo(&self); + } + + macro_rules! define_thing { + ($thing:ident, $body:expr) => { + impl<'a> Thing<'a> for $thing { + fn foo<'b>(&self) { + $body + } + } + }; + } + + struct MyThing; + define_thing!(MyThing, { + 2; + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + }); +} + +#[test] +pub fn issue8481() { + 1; + //~^ ERROR: the `dbg!` macro is intended as a debugging tool +} + +#[cfg(test)] +fn foo2() { + 1; + //~^ ERROR: the `dbg!` macro is intended as a debugging tool +} + +#[cfg(test)] +mod mod1 { + fn func() { + 1; + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + } +} + +mod issue12131 { + fn dbg_in_print(s: &str) { + println!("dbg: {:?}", s); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + print!("{}", s); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + } +} diff --git a/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.rs b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.rs index 3f4770c63d0..80606c2db05 100644 --- a/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.rs +++ b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.rs @@ -1,9 +1,5 @@ -//@no-rustfix - #![warn(clippy::dbg_macro)] - -#[path = "auxiliary/submodule.rs"] -mod submodule; +#![allow(clippy::unnecessary_operation, clippy::no_effect)] fn foo(n: u32) -> u32 { if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } @@ -25,12 +21,8 @@ fn factorial(n: u32) -> u32 { fn main() { dbg!(42); //~^ ERROR: the `dbg!` macro is intended as a debugging tool - dbg!(dbg!(dbg!(42))); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool foo(3) + dbg!(factorial(4)); //~^ ERROR: the `dbg!` macro is intended as a debugging tool - dbg!(1, 2, dbg!(3, 4)); - //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(1, 2, 3, 4, 5); //~^ ERROR: the `dbg!` macro is intended as a debugging tool } @@ -49,6 +41,7 @@ fn issue9914() { macro_rules! expand_to_dbg { () => { dbg!(); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool }; } @@ -107,3 +100,12 @@ mod mod1 { //~^ ERROR: the `dbg!` macro is intended as a debugging tool } } + +mod issue12131 { + fn dbg_in_print(s: &str) { + println!("dbg: {:?}", dbg!(s)); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + print!("{}", dbg!(s)); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + } +} diff --git a/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.stderr b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.stderr index 5ad0bbfed94..86667701da0 100644 --- a/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.stderr +++ b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro.stderr @@ -1,30 +1,18 @@ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/auxiliary/submodule.rs:2:5 - | -LL | dbg!(); - | ^^^^^^^ - | - = note: `-D clippy::dbg-macro` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]` -help: remove the invocation before committing it to a version control system - | -LL - dbg!(); -LL + - | - -error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:9:22 + --> tests/ui/dbg_macro/dbg_macro.rs:5:22 | LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } | ^^^^^^^^^^^^^^^^^^^^^^ | + = note: `-D clippy::dbg-macro` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]` help: remove the invocation before committing it to a version control system | LL | if let Some(n) = n.checked_sub(4) { n } else { n } | ~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:15:8 + --> tests/ui/dbg_macro/dbg_macro.rs:11:8 | LL | if dbg!(n <= 1) { | ^^^^^^^^^^^^ @@ -35,7 +23,7 @@ LL | if n <= 1 { | ~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:17:9 + --> tests/ui/dbg_macro/dbg_macro.rs:13:9 | LL | dbg!(1) | ^^^^^^^ @@ -46,7 +34,7 @@ LL | 1 | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:20:9 + --> tests/ui/dbg_macro/dbg_macro.rs:16:9 | LL | dbg!(n * factorial(n - 1)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +45,7 @@ LL | n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:26:5 + --> tests/ui/dbg_macro/dbg_macro.rs:22:5 | LL | dbg!(42); | ^^^^^^^^ @@ -68,18 +56,7 @@ LL | 42; | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:28:5 - | -LL | dbg!(dbg!(dbg!(42))); - | ^^^^^^^^^^^^^^^^^^^^ - | -help: remove the invocation before committing it to a version control system - | -LL | dbg!(dbg!(42)); - | ~~~~~~~~~~~~~~ - -error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:30:14 + --> tests/ui/dbg_macro/dbg_macro.rs:24:14 | LL | foo(3) + dbg!(factorial(4)); | ^^^^^^^^^^^^^^^^^^ @@ -90,18 +67,7 @@ LL | foo(3) + factorial(4); | ~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:32:5 - | -LL | dbg!(1, 2, dbg!(3, 4)); - | ^^^^^^^^^^^^^^^^^^^^^^ - | -help: remove the invocation before committing it to a version control system - | -LL | (1, 2, dbg!(3, 4)); - | ~~~~~~~~~~~~~~~~~~ - -error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:34:5 + --> tests/ui/dbg_macro/dbg_macro.rs:26:5 | LL | dbg!(1, 2, 3, 4, 5); | ^^^^^^^^^^^^^^^^^^^ @@ -112,7 +78,7 @@ LL | (1, 2, 3, 4, 5); | ~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:55:5 + --> tests/ui/dbg_macro/dbg_macro.rs:48:5 | LL | dbg!(); | ^^^^^^^ @@ -124,7 +90,7 @@ LL + | error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:58:13 + --> tests/ui/dbg_macro/dbg_macro.rs:51:13 | LL | let _ = dbg!(); | ^^^^^^ @@ -135,7 +101,7 @@ LL | let _ = (); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:60:9 + --> tests/ui/dbg_macro/dbg_macro.rs:53:9 | LL | bar(dbg!()); | ^^^^^^ @@ -146,7 +112,7 @@ LL | bar(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:62:10 + --> tests/ui/dbg_macro/dbg_macro.rs:55:10 | LL | foo!(dbg!()); | ^^^^^^ @@ -157,7 +123,7 @@ LL | foo!(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:64:16 + --> tests/ui/dbg_macro/dbg_macro.rs:57:16 | LL | foo2!(foo!(dbg!())); | ^^^^^^ @@ -168,7 +134,23 @@ LL | foo2!(foo!(())); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:86:9 + --> tests/ui/dbg_macro/dbg_macro.rs:43:13 + | +LL | dbg!(); + | ^^^^^^^ +... +LL | expand_to_dbg!(); + | ---------------- in this macro invocation + | + = note: this error originates in the macro `expand_to_dbg` (in Nightly builds, run with -Z macro-backtrace for more info) +help: remove the invocation before committing it to a version control system + | +LL - dbg!(); +LL + + | + +error: the `dbg!` macro is intended as a debugging tool + --> tests/ui/dbg_macro/dbg_macro.rs:79:9 | LL | dbg!(2); | ^^^^^^^ @@ -179,7 +161,7 @@ LL | 2; | ~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:93:5 + --> tests/ui/dbg_macro/dbg_macro.rs:86:5 | LL | dbg!(1); | ^^^^^^^ @@ -190,7 +172,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:99:5 + --> tests/ui/dbg_macro/dbg_macro.rs:92:5 | LL | dbg!(1); | ^^^^^^^ @@ -201,7 +183,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> tests/ui/dbg_macro/dbg_macro.rs:106:9 + --> tests/ui/dbg_macro/dbg_macro.rs:99:9 | LL | dbg!(1); | ^^^^^^^ @@ -211,5 +193,27 @@ help: remove the invocation before committing it to a version control system LL | 1; | ~ +error: the `dbg!` macro is intended as a debugging tool + --> tests/ui/dbg_macro/dbg_macro.rs:106:31 + | +LL | println!("dbg: {:?}", dbg!(s)); + | ^^^^^^^ + | +help: remove the invocation before committing it to a version control system + | +LL | println!("dbg: {:?}", s); + | ~ + +error: the `dbg!` macro is intended as a debugging tool + --> tests/ui/dbg_macro/dbg_macro.rs:108:22 + | +LL | print!("{}", dbg!(s)); + | ^^^^^^^ + | +help: remove the invocation before committing it to a version control system + | +LL | print!("{}", s); + | ~ + error: aborting due to 19 previous errors diff --git a/src/tools/clippy/tests/ui/dbg_macro/dbg_macro_unfixable.rs b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro_unfixable.rs new file mode 100644 index 00000000000..0e83766ccae --- /dev/null +++ b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro_unfixable.rs @@ -0,0 +1,12 @@ +//@no-rustfix +#![warn(clippy::dbg_macro)] + +#[path = "auxiliary/submodule.rs"] +mod submodule; + +fn main() { + dbg!(dbg!(dbg!(42))); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + dbg!(1, 2, dbg!(3, 4)); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool +} diff --git a/src/tools/clippy/tests/ui/dbg_macro/dbg_macro_unfixable.stderr b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro_unfixable.stderr new file mode 100644 index 00000000000..d21595c2fcd --- /dev/null +++ b/src/tools/clippy/tests/ui/dbg_macro/dbg_macro_unfixable.stderr @@ -0,0 +1,71 @@ +error: the `dbg!` macro is intended as a debugging tool + --> tests/ui/dbg_macro/auxiliary/submodule.rs:2:5 + | +LL | dbg!(); + | ^^^^^^^ + | + = note: `-D clippy::dbg-macro` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]` +help: remove the invocation before committing it to a version control system + | +LL - dbg!(); +LL + + | + +error: the `dbg!` macro is intended as a debugging tool + --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:8:5 + | +LL | dbg!(dbg!(dbg!(42))); + | ^^^^^^^^^^^^^^^^^^^^ + | +help: remove the invocation before committing it to a version control system + | +LL | dbg!(dbg!(42)); + | ~~~~~~~~~~~~~~ + +error: the `dbg!` macro is intended as a debugging tool + --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:8:10 + | +LL | dbg!(dbg!(dbg!(42))); + | ^^^^^^^^^^^^^^ + | +help: remove the invocation before committing it to a version control system + | +LL | dbg!(dbg!(42)); + | ~~~~~~~~ + +error: the `dbg!` macro is intended as a debugging tool + --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:8:15 + | +LL | dbg!(dbg!(dbg!(42))); + | ^^^^^^^^ + | +help: remove the invocation before committing it to a version control system + | +LL | dbg!(dbg!(42)); + | ~~ + +error: the `dbg!` macro is intended as a debugging tool + --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:10:5 + | +LL | dbg!(1, 2, dbg!(3, 4)); + | ^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove the invocation before committing it to a version control system + | +LL | (1, 2, dbg!(3, 4)); + | ~~~~~~~~~~~~~~~~~~ + +error: the `dbg!` macro is intended as a debugging tool + --> tests/ui/dbg_macro/dbg_macro_unfixable.rs:10:16 + | +LL | dbg!(1, 2, dbg!(3, 4)); + | ^^^^^^^^^^ + | +help: remove the invocation before committing it to a version control system + | +LL | dbg!(1, 2, (3, 4)); + | ~~~~~~ + +error: aborting due to 6 previous errors + diff --git a/src/tools/clippy/tests/ui/doc/issue_10262.fixed b/src/tools/clippy/tests/ui/doc/issue_10262.fixed new file mode 100644 index 00000000000..5d067736d55 --- /dev/null +++ b/src/tools/clippy/tests/ui/doc/issue_10262.fixed @@ -0,0 +1,12 @@ +#![warn(clippy::doc_markdown)] + +// Should only warn for the first line! +/// `AviSynth` documentation: +//~^ ERROR: item in documentation is missing backticks +/// +/// > AvisynthPluginInit3 may be called more than once with different IScriptEnvironments. +/// +/// <blockquote>bla AvisynthPluginInit3 bla</blockquote> +/// +/// <q>bla AvisynthPluginInit3 bla</q> +pub struct Foo; diff --git a/src/tools/clippy/tests/ui/doc/issue_10262.rs b/src/tools/clippy/tests/ui/doc/issue_10262.rs new file mode 100644 index 00000000000..e2cbd938d5d --- /dev/null +++ b/src/tools/clippy/tests/ui/doc/issue_10262.rs @@ -0,0 +1,12 @@ +#![warn(clippy::doc_markdown)] + +// Should only warn for the first line! +/// AviSynth documentation: +//~^ ERROR: item in documentation is missing backticks +/// +/// > AvisynthPluginInit3 may be called more than once with different IScriptEnvironments. +/// +/// <blockquote>bla AvisynthPluginInit3 bla</blockquote> +/// +/// <q>bla AvisynthPluginInit3 bla</q> +pub struct Foo; diff --git a/src/tools/clippy/tests/ui/doc/issue_10262.stderr b/src/tools/clippy/tests/ui/doc/issue_10262.stderr new file mode 100644 index 00000000000..f43d9551e94 --- /dev/null +++ b/src/tools/clippy/tests/ui/doc/issue_10262.stderr @@ -0,0 +1,15 @@ +error: item in documentation is missing backticks + --> tests/ui/doc/issue_10262.rs:4:5 + | +LL | /// AviSynth documentation: + | ^^^^^^^^ + | + = note: `-D clippy::doc-markdown` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` +help: try + | +LL | /// `AviSynth` documentation: + | ~~~~~~~~~~ + +error: aborting due to 1 previous error + diff --git a/src/tools/clippy/tests/ui/duplicated_attributes.rs b/src/tools/clippy/tests/ui/duplicated_attributes.rs new file mode 100644 index 00000000000..0f036c684c1 --- /dev/null +++ b/src/tools/clippy/tests/ui/duplicated_attributes.rs @@ -0,0 +1,17 @@ +#![warn(clippy::duplicated_attributes)] +#![cfg(any(unix, windows))] +#![allow(dead_code)] +#![allow(dead_code)] //~ ERROR: duplicated attribute +#![cfg(any(unix, windows))] +//~^ ERROR: duplicated attribute +//~| ERROR: duplicated attribute + +#[cfg(any(unix, windows, target_os = "linux"))] +#[allow(dead_code)] +#[allow(dead_code)] //~ ERROR: duplicated attribute +#[cfg(any(unix, windows, target_os = "linux"))] +//~^ ERROR: duplicated attribute +//~| ERROR: duplicated attribute +fn foo() {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/duplicated_attributes.stderr b/src/tools/clippy/tests/ui/duplicated_attributes.stderr new file mode 100644 index 00000000000..1c6578dbb43 --- /dev/null +++ b/src/tools/clippy/tests/ui/duplicated_attributes.stderr @@ -0,0 +1,123 @@ +error: duplicated attribute + --> tests/ui/duplicated_attributes.rs:4:10 + | +LL | #![allow(dead_code)] + | ^^^^^^^^^ + | +note: first defined here + --> tests/ui/duplicated_attributes.rs:3:10 + | +LL | #![allow(dead_code)] + | ^^^^^^^^^ +help: remove this attribute + --> tests/ui/duplicated_attributes.rs:4:10 + | +LL | #![allow(dead_code)] + | ^^^^^^^^^ + = note: `-D clippy::duplicated-attributes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]` + +error: duplicated attribute + --> tests/ui/duplicated_attributes.rs:5:12 + | +LL | #![cfg(any(unix, windows))] + | ^^^^ + | +note: first defined here + --> tests/ui/duplicated_attributes.rs:2:12 + | +LL | #![cfg(any(unix, windows))] + | ^^^^ +help: remove this attribute + --> tests/ui/duplicated_attributes.rs:5:12 + | +LL | #![cfg(any(unix, windows))] + | ^^^^ + +error: duplicated attribute + --> tests/ui/duplicated_attributes.rs:5:18 + | +LL | #![cfg(any(unix, windows))] + | ^^^^^^^ + | +note: first defined here + --> tests/ui/duplicated_attributes.rs:2:18 + | +LL | #![cfg(any(unix, windows))] + | ^^^^^^^ +help: remove this attribute + --> tests/ui/duplicated_attributes.rs:5:18 + | +LL | #![cfg(any(unix, windows))] + | ^^^^^^^ + +error: duplicated attribute + --> tests/ui/duplicated_attributes.rs:11:9 + | +LL | #[allow(dead_code)] + | ^^^^^^^^^ + | +note: first defined here + --> tests/ui/duplicated_attributes.rs:10:9 + | +LL | #[allow(dead_code)] + | ^^^^^^^^^ +help: remove this attribute + --> tests/ui/duplicated_attributes.rs:11:9 + | +LL | #[allow(dead_code)] + | ^^^^^^^^^ + +error: duplicated attribute + --> tests/ui/duplicated_attributes.rs:12:11 + | +LL | #[cfg(any(unix, windows, target_os = "linux"))] + | ^^^^ + | +note: first defined here + --> tests/ui/duplicated_attributes.rs:9:11 + | +LL | #[cfg(any(unix, windows, target_os = "linux"))] + | ^^^^ +help: remove this attribute + --> tests/ui/duplicated_attributes.rs:12:11 + | +LL | #[cfg(any(unix, windows, target_os = "linux"))] + | ^^^^ + +error: duplicated attribute + --> tests/ui/duplicated_attributes.rs:12:17 + | +LL | #[cfg(any(unix, windows, target_os = "linux"))] + | ^^^^^^^ + | +note: first defined here + --> tests/ui/duplicated_attributes.rs:9:17 + | +LL | #[cfg(any(unix, windows, target_os = "linux"))] + | ^^^^^^^ +help: remove this attribute + --> tests/ui/duplicated_attributes.rs:12:17 + | +LL | #[cfg(any(unix, windows, target_os = "linux"))] + | ^^^^^^^ + +error: duplicated attribute + --> tests/ui/duplicated_attributes.rs:12:26 + | +LL | #[cfg(any(unix, windows, target_os = "linux"))] + | ^^^^^^^^^^^^^^^^^^^ + | +note: first defined here + --> tests/ui/duplicated_attributes.rs:9:26 + | +LL | #[cfg(any(unix, windows, target_os = "linux"))] + | ^^^^^^^^^^^^^^^^^^^ +help: remove this attribute + --> tests/ui/duplicated_attributes.rs:12:26 + | +LL | #[cfg(any(unix, windows, target_os = "linux"))] + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors + diff --git a/src/tools/clippy/tests/ui/else_if_without_else.rs b/src/tools/clippy/tests/ui/else_if_without_else.rs index e7786f7dd27..b04c22fa2ae 100644 --- a/src/tools/clippy/tests/ui/else_if_without_else.rs +++ b/src/tools/clippy/tests/ui/else_if_without_else.rs @@ -1,7 +1,5 @@ -//@compile-flags: -Zdeduplicate-diagnostics=yes - -#![warn(clippy::all)] #![warn(clippy::else_if_without_else)] +#![allow(clippy::collapsible_else_if)] fn bla1() -> bool { unimplemented!() @@ -12,6 +10,12 @@ fn bla2() -> bool { fn bla3() -> bool { unimplemented!() } +fn bla4() -> bool { + unimplemented!() +} +fn bla5() -> bool { + unimplemented!() +} fn main() { if bla1() { @@ -57,4 +61,62 @@ fn main() { //~^ ERROR: `if` expression with an `else if`, but without a final `else` println!("else if 2"); } + + if bla1() { + println!("if"); + } else if bla2() { + println!("else if 1"); + } else if bla3() { + println!("else if 2"); + } else if bla4() { + println!("else if 3"); + } else if bla5() { + println!("else if 4"); + } else { + println!("else"); + } + + if bla1() { + println!("if"); + } else if bla2() { + println!("else if 1"); + } else if bla3() { + println!("else if 2"); + } else if bla4() { + println!("else if 3"); + } else if bla5() { + //~^ ERROR: `if` expression with an `else if`, but without a final `else` + println!("else if 4"); + } + + if bla1() { + println!("if"); + } else if bla2() { + println!("else if 1"); + } else { + if bla3() { + println!("else if 2"); + } else if bla4() { + println!("else if 3"); + } else if bla5() { + println!("else if 4"); + } else { + println!("else"); + } + } + + if bla1() { + println!("if"); + } else if bla2() { + println!("else if 1"); + } else { + if bla3() { + println!("else if 2"); + } else if bla4() { + println!("else if 3"); + } else if bla5() { + //~^ ERROR: `if` expression with an `else if`, but without a final `else` + println!("else if 4"); + } + } } diff --git a/src/tools/clippy/tests/ui/else_if_without_else.stderr b/src/tools/clippy/tests/ui/else_if_without_else.stderr index 3bb840f39e7..bc717485229 100644 --- a/src/tools/clippy/tests/ui/else_if_without_else.stderr +++ b/src/tools/clippy/tests/ui/else_if_without_else.stderr @@ -1,5 +1,5 @@ error: `if` expression with an `else if`, but without a final `else` - --> tests/ui/else_if_without_else.rs:47:12 + --> tests/ui/else_if_without_else.rs:51:12 | LL | } else if bla2() { | ____________^ @@ -13,7 +13,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::else_if_without_else)]` error: `if` expression with an `else if`, but without a final `else` - --> tests/ui/else_if_without_else.rs:56:12 + --> tests/ui/else_if_without_else.rs:60:12 | LL | } else if bla3() { | ____________^ @@ -24,5 +24,29 @@ LL | | } | = help: add an `else` block here -error: aborting due to 2 previous errors +error: `if` expression with an `else if`, but without a final `else` + --> tests/ui/else_if_without_else.rs:87:12 + | +LL | } else if bla5() { + | ____________^ +LL | | +LL | | println!("else if 4"); +LL | | } + | |_____^ + | + = help: add an `else` block here + +error: `if` expression with an `else if`, but without a final `else` + --> tests/ui/else_if_without_else.rs:117:16 + | +LL | } else if bla5() { + | ________________^ +LL | | +LL | | println!("else if 4"); +LL | | } + | |_________^ + | + = help: add an `else` block here + +error: aborting due to 4 previous errors diff --git a/src/tools/clippy/tests/ui/empty_docs.rs b/src/tools/clippy/tests/ui/empty_docs.rs index 272fab7d5ca..00e64eebc5f 100644 --- a/src/tools/clippy/tests/ui/empty_docs.rs +++ b/src/tools/clippy/tests/ui/empty_docs.rs @@ -1,6 +1,9 @@ +//@aux-build:proc_macro_attr.rs + #![allow(unused)] #![warn(clippy::empty_docs)] #![allow(clippy::mixed_attributes_style)] +#![feature(extern_types)] mod outer { //! @@ -67,3 +70,17 @@ mod outer { y: i32, } } + +mod issue_12377 { + use proc_macro_attr::with_empty_docs; + + #[with_empty_docs] + extern "C" { + type Test; + } + + #[with_empty_docs] + struct Foo { + a: u8, + } +} diff --git a/src/tools/clippy/tests/ui/empty_docs.stderr b/src/tools/clippy/tests/ui/empty_docs.stderr index f12aead6aa7..28ebea22c5d 100644 --- a/src/tools/clippy/tests/ui/empty_docs.stderr +++ b/src/tools/clippy/tests/ui/empty_docs.stderr @@ -1,5 +1,5 @@ error: empty doc comment - --> tests/ui/empty_docs.rs:6:5 + --> tests/ui/empty_docs.rs:9:5 | LL | //! | ^^^ @@ -9,7 +9,7 @@ LL | //! = help: to override `-D warnings` add `#[allow(clippy::empty_docs)]` error: empty doc comment - --> tests/ui/empty_docs.rs:14:5 + --> tests/ui/empty_docs.rs:17:5 | LL | /// | ^^^ @@ -17,7 +17,7 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:16:9 + --> tests/ui/empty_docs.rs:19:9 | LL | /// | ^^^ @@ -25,7 +25,7 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:27:5 + --> tests/ui/empty_docs.rs:30:5 | LL | #[doc = ""] | ^^^^^^^^^^^ @@ -33,7 +33,7 @@ LL | #[doc = ""] = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:30:5 + --> tests/ui/empty_docs.rs:33:5 | LL | / #[doc = ""] LL | | #[doc = ""] @@ -42,7 +42,7 @@ LL | | #[doc = ""] = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:37:5 + --> tests/ui/empty_docs.rs:40:5 | LL | /// | ^^^ @@ -50,7 +50,7 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:50:13 + --> tests/ui/empty_docs.rs:53:13 | LL | /*! */ | ^^^^^^ @@ -58,7 +58,7 @@ LL | /*! */ = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:58:13 + --> tests/ui/empty_docs.rs:61:13 | LL | /// | ^^^ @@ -66,7 +66,7 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:66:9 + --> tests/ui/empty_docs.rs:69:9 | LL | /// | ^^^ diff --git a/src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs b/src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs index e843770f578..dd78491749c 100644 --- a/src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs +++ b/src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macro_attr.rs #![warn(clippy::empty_line_after_doc_comments)] -#![allow(clippy::assertions_on_constants)] +#![allow(clippy::assertions_on_constants, clippy::duplicated_attributes)] #![feature(custom_inner_attributes)] #![rustfmt::skip] diff --git a/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs index 269e66ea0a8..f147cf2cd5d 100644 --- a/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs +++ b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macro_attr.rs #![warn(clippy::empty_line_after_outer_attr)] -#![allow(clippy::assertions_on_constants)] +#![allow(clippy::assertions_on_constants, clippy::duplicated_attributes)] #![feature(custom_inner_attributes)] #![rustfmt::skip] diff --git a/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr index 1b5b00a4a83..b43e6e30da2 100644 --- a/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr +++ b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr @@ -22,8 +22,7 @@ error: found an empty line after an outer attribute. Perhaps you forgot to add a --> tests/ui/empty_line_after_outer_attribute.rs:28:1 | LL | / #[crate_type = "lib"] -LL | | -LL | | +... | LL | | fn with_two_newlines() { assert!(true) } | |_ diff --git a/src/tools/clippy/tests/ui/entry.fixed b/src/tools/clippy/tests/ui/entry.fixed index 71ec13f4610..abdfae2a3e1 100644 --- a/src/tools/clippy/tests/ui/entry.fixed +++ b/src/tools/clippy/tests/ui/entry.fixed @@ -176,4 +176,14 @@ pub fn issue_11935() { } } +fn issue12489(map: &mut HashMap<u64, u64>) -> Option<()> { + if let std::collections::hash_map::Entry::Vacant(e) = map.entry(1) { + let Some(1) = Some(2) else { + return None; + }; + e.insert(42); + } + Some(()) +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/entry.rs b/src/tools/clippy/tests/ui/entry.rs index 86092b7c055..7774f99a2a2 100644 --- a/src/tools/clippy/tests/ui/entry.rs +++ b/src/tools/clippy/tests/ui/entry.rs @@ -180,4 +180,14 @@ pub fn issue_11935() { } } +fn issue12489(map: &mut HashMap<u64, u64>) -> Option<()> { + if !map.contains_key(&1) { + let Some(1) = Some(2) else { + return None; + }; + map.insert(1, 42); + } + Some(()) +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/entry.stderr b/src/tools/clippy/tests/ui/entry.stderr index ef4c36bcf54..fb467676606 100644 --- a/src/tools/clippy/tests/ui/entry.stderr +++ b/src/tools/clippy/tests/ui/entry.stderr @@ -214,5 +214,26 @@ LL + v LL + }); | -error: aborting due to 10 previous errors +error: usage of `contains_key` followed by `insert` on a `HashMap` + --> tests/ui/entry.rs:184:5 + | +LL | / if !map.contains_key(&1) { +LL | | let Some(1) = Some(2) else { +LL | | return None; +LL | | }; +LL | | map.insert(1, 42); +LL | | } + | |_____^ + | +help: try + | +LL ~ if let std::collections::hash_map::Entry::Vacant(e) = map.entry(1) { +LL + let Some(1) = Some(2) else { +LL + return None; +LL + }; +LL + e.insert(42); +LL + } + | + +error: aborting due to 11 previous errors diff --git a/src/tools/clippy/tests/ui/integer_division_remainder_used.rs b/src/tools/clippy/tests/ui/integer_division_remainder_used.rs new file mode 100644 index 00000000000..5d1b02095d1 --- /dev/null +++ b/src/tools/clippy/tests/ui/integer_division_remainder_used.rs @@ -0,0 +1,41 @@ +#![warn(clippy::integer_division_remainder_used)] +#![allow(unused_variables)] +#![allow(clippy::op_ref)] + +struct CustomOps(pub i32); +impl std::ops::Div for CustomOps { + type Output = Self; + + fn div(self, rhs: Self) -> Self::Output { + Self(self.0 / rhs.0) + } +} +impl std::ops::Rem for CustomOps { + type Output = Self; + + fn rem(self, rhs: Self) -> Self::Output { + Self(self.0 % rhs.0) + } +} + +fn main() { + // should trigger + let a = 10; + let b = 5; + let c = a / b; + let d = a % b; + let e = &a / b; + let f = a % &b; + let g = &a / &b; + let h = &10 % b; + let i = a / &4; + + // should not trigger on custom Div and Rem + let w = CustomOps(3); + let x = CustomOps(4); + let y = w / x; + + let w = CustomOps(3); + let x = CustomOps(4); + let z = w % x; +} diff --git a/src/tools/clippy/tests/ui/integer_division_remainder_used.stderr b/src/tools/clippy/tests/ui/integer_division_remainder_used.stderr new file mode 100644 index 00000000000..8adfda28893 --- /dev/null +++ b/src/tools/clippy/tests/ui/integer_division_remainder_used.stderr @@ -0,0 +1,59 @@ +error: use of / has been disallowed in this context + --> tests/ui/integer_division_remainder_used.rs:10:14 + | +LL | Self(self.0 / rhs.0) + | ^^^^^^^^^^^^^^ + | + = note: `-D clippy::integer-division-remainder-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::integer_division_remainder_used)]` + +error: use of % has been disallowed in this context + --> tests/ui/integer_division_remainder_used.rs:17:14 + | +LL | Self(self.0 % rhs.0) + | ^^^^^^^^^^^^^^ + +error: use of / has been disallowed in this context + --> tests/ui/integer_division_remainder_used.rs:25:13 + | +LL | let c = a / b; + | ^^^^^ + +error: use of % has been disallowed in this context + --> tests/ui/integer_division_remainder_used.rs:26:13 + | +LL | let d = a % b; + | ^^^^^ + +error: use of / has been disallowed in this context + --> tests/ui/integer_division_remainder_used.rs:27:13 + | +LL | let e = &a / b; + | ^^^^^^ + +error: use of % has been disallowed in this context + --> tests/ui/integer_division_remainder_used.rs:28:13 + | +LL | let f = a % &b; + | ^^^^^^ + +error: use of / has been disallowed in this context + --> tests/ui/integer_division_remainder_used.rs:29:13 + | +LL | let g = &a / &b; + | ^^^^^^^ + +error: use of % has been disallowed in this context + --> tests/ui/integer_division_remainder_used.rs:30:13 + | +LL | let h = &10 % b; + | ^^^^^^^ + +error: use of / has been disallowed in this context + --> tests/ui/integer_division_remainder_used.rs:31:13 + | +LL | let i = a / &4; + | ^^^^^^ + +error: aborting due to 9 previous errors + diff --git a/src/tools/clippy/tests/ui/iter_nth.fixed b/src/tools/clippy/tests/ui/iter_nth.fixed new file mode 100644 index 00000000000..aff3731a883 --- /dev/null +++ b/src/tools/clippy/tests/ui/iter_nth.fixed @@ -0,0 +1,60 @@ +//@aux-build:option_helpers.rs + +#![warn(clippy::iter_nth)] +#![allow(clippy::useless_vec)] + +#[macro_use] +extern crate option_helpers; + +use option_helpers::IteratorFalsePositives; +use std::collections::VecDeque; + +/// Struct to generate false positives for things with `.iter()`. +#[derive(Copy, Clone)] +struct HasIter; + +impl HasIter { + fn iter(self) -> IteratorFalsePositives { + IteratorFalsePositives { foo: 0 } + } + + fn iter_mut(self) -> IteratorFalsePositives { + IteratorFalsePositives { foo: 0 } + } +} + +/// Checks implementation of `ITER_NTH` lint. +fn iter_nth() { + let mut some_vec = vec![0, 1, 2, 3]; + let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); + let mut some_vec_deque: VecDeque<_> = some_vec.iter().cloned().collect(); + + { + // Make sure we lint `.iter()` for relevant types. + let bad_vec = some_vec.get(3); + let bad_slice = &some_vec[..].get(3); + let bad_boxed_slice = boxed_slice.get(3); + let bad_vec_deque = some_vec_deque.get(3); + } + + { + // Make sure we lint `.iter_mut()` for relevant types. + let bad_vec = some_vec.get_mut(3); + } + { + let bad_slice = &some_vec[..].get_mut(3); + } + { + let bad_vec_deque = some_vec_deque.get_mut(3); + } + + let vec_ref = &Vec::<String>::new(); + vec_ref.get(3); + + // Make sure we don't lint for non-relevant types. + let false_positive = HasIter; + let ok = false_positive.iter().nth(3); + let ok_mut = false_positive.iter_mut().nth(3); +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/iter_nth.rs b/src/tools/clippy/tests/ui/iter_nth.rs index 7c567bb81d8..89d68044ddd 100644 --- a/src/tools/clippy/tests/ui/iter_nth.rs +++ b/src/tools/clippy/tests/ui/iter_nth.rs @@ -48,6 +48,9 @@ fn iter_nth() { let bad_vec_deque = some_vec_deque.iter_mut().nth(3); } + let vec_ref = &Vec::<String>::new(); + vec_ref.iter().nth(3); + // Make sure we don't lint for non-relevant types. let false_positive = HasIter; let ok = false_positive.iter().nth(3); diff --git a/src/tools/clippy/tests/ui/iter_nth.stderr b/src/tools/clippy/tests/ui/iter_nth.stderr index c5dd0c99727..178463f5347 100644 --- a/src/tools/clippy/tests/ui/iter_nth.stderr +++ b/src/tools/clippy/tests/ui/iter_nth.stderr @@ -4,9 +4,12 @@ error: called `.iter().nth()` on a `Vec` LL | let bad_vec = some_vec.iter().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^ | - = help: calling `.get()` is both faster and more readable = note: `-D clippy::iter-nth` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::iter_nth)]` +help: `get` is equivalent but more concise + | +LL | let bad_vec = some_vec.get(3); + | ~~~ error: called `.iter().nth()` on a slice --> tests/ui/iter_nth.rs:35:26 @@ -14,7 +17,10 @@ error: called `.iter().nth()` on a slice LL | let bad_slice = &some_vec[..].iter().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: calling `.get()` is both faster and more readable +help: `get` is equivalent but more concise + | +LL | let bad_slice = &some_vec[..].get(3); + | ~~~ error: called `.iter().nth()` on a slice --> tests/ui/iter_nth.rs:36:31 @@ -22,7 +28,10 @@ error: called `.iter().nth()` on a slice LL | let bad_boxed_slice = boxed_slice.iter().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: calling `.get()` is both faster and more readable +help: `get` is equivalent but more concise + | +LL | let bad_boxed_slice = boxed_slice.get(3); + | ~~~ error: called `.iter().nth()` on a `VecDeque` --> tests/ui/iter_nth.rs:37:29 @@ -30,7 +39,10 @@ error: called `.iter().nth()` on a `VecDeque` LL | let bad_vec_deque = some_vec_deque.iter().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: calling `.get()` is both faster and more readable +help: `get` is equivalent but more concise + | +LL | let bad_vec_deque = some_vec_deque.get(3); + | ~~~ error: called `.iter_mut().nth()` on a `Vec` --> tests/ui/iter_nth.rs:42:23 @@ -38,7 +50,10 @@ error: called `.iter_mut().nth()` on a `Vec` LL | let bad_vec = some_vec.iter_mut().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: calling `.get_mut()` is both faster and more readable +help: `get_mut` is equivalent but more concise + | +LL | let bad_vec = some_vec.get_mut(3); + | ~~~~~~~ error: called `.iter_mut().nth()` on a slice --> tests/ui/iter_nth.rs:45:26 @@ -46,7 +61,10 @@ error: called `.iter_mut().nth()` on a slice LL | let bad_slice = &some_vec[..].iter_mut().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: calling `.get_mut()` is both faster and more readable +help: `get_mut` is equivalent but more concise + | +LL | let bad_slice = &some_vec[..].get_mut(3); + | ~~~~~~~ error: called `.iter_mut().nth()` on a `VecDeque` --> tests/ui/iter_nth.rs:48:29 @@ -54,7 +72,21 @@ error: called `.iter_mut().nth()` on a `VecDeque` LL | let bad_vec_deque = some_vec_deque.iter_mut().nth(3); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: calling `.get_mut()` is both faster and more readable +help: `get_mut` is equivalent but more concise + | +LL | let bad_vec_deque = some_vec_deque.get_mut(3); + | ~~~~~~~ + +error: called `.iter().nth()` on a `Vec` + --> tests/ui/iter_nth.rs:52:5 + | +LL | vec_ref.iter().nth(3); + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: `get` is equivalent but more concise + | +LL | vec_ref.get(3); + | ~~~ -error: aborting due to 7 previous errors +error: aborting due to 8 previous errors diff --git a/src/tools/clippy/tests/ui/len_zero.fixed b/src/tools/clippy/tests/ui/len_zero.fixed index 745fc7e1a8b..c16d7a26616 100644 --- a/src/tools/clippy/tests/ui/len_zero.fixed +++ b/src/tools/clippy/tests/ui/len_zero.fixed @@ -1,5 +1,11 @@ #![warn(clippy::len_zero)] -#![allow(dead_code, unused, clippy::needless_if, clippy::len_without_is_empty)] +#![allow( + dead_code, + unused, + clippy::needless_if, + clippy::len_without_is_empty, + clippy::const_is_empty +)] extern crate core; use core::ops::Deref; diff --git a/src/tools/clippy/tests/ui/len_zero.rs b/src/tools/clippy/tests/ui/len_zero.rs index 048ad2f4fd3..5c49a5abf81 100644 --- a/src/tools/clippy/tests/ui/len_zero.rs +++ b/src/tools/clippy/tests/ui/len_zero.rs @@ -1,5 +1,11 @@ #![warn(clippy::len_zero)] -#![allow(dead_code, unused, clippy::needless_if, clippy::len_without_is_empty)] +#![allow( + dead_code, + unused, + clippy::needless_if, + clippy::len_without_is_empty, + clippy::const_is_empty +)] extern crate core; use core::ops::Deref; diff --git a/src/tools/clippy/tests/ui/len_zero.stderr b/src/tools/clippy/tests/ui/len_zero.stderr index b1f04c94de6..dd07a85d62c 100644 --- a/src/tools/clippy/tests/ui/len_zero.stderr +++ b/src/tools/clippy/tests/ui/len_zero.stderr @@ -1,5 +1,5 @@ error: length comparison to zero - --> tests/ui/len_zero.rs:82:8 + --> tests/ui/len_zero.rs:88:8 | LL | if x.len() == 0 { | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `x.is_empty()` @@ -8,13 +8,13 @@ LL | if x.len() == 0 { = help: to override `-D warnings` add `#[allow(clippy::len_zero)]` error: length comparison to zero - --> tests/ui/len_zero.rs:86:8 + --> tests/ui/len_zero.rs:92:8 | LL | if "".len() == 0 {} | ^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `"".is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:95:20 + --> tests/ui/len_zero.rs:101:20 | LL | println!("{}", *s1 == ""); | ^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s1.is_empty()` @@ -23,121 +23,121 @@ LL | println!("{}", *s1 == ""); = help: to override `-D warnings` add `#[allow(clippy::comparison_to_empty)]` error: comparison to empty slice - --> tests/ui/len_zero.rs:96:20 + --> tests/ui/len_zero.rs:102:20 | LL | println!("{}", **s2 == ""); | ^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s2.is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:97:20 + --> tests/ui/len_zero.rs:103:20 | LL | println!("{}", ***s3 == ""); | ^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s3.is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:98:20 + --> tests/ui/len_zero.rs:104:20 | LL | println!("{}", ****s4 == ""); | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s4.is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:99:20 + --> tests/ui/len_zero.rs:105:20 | LL | println!("{}", *****s5 == ""); | ^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s5.is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:100:20 + --> tests/ui/len_zero.rs:106:20 | LL | println!("{}", ******(s6) == ""); | ^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(s6).is_empty()` error: comparison to empty slice - --> tests/ui/len_zero.rs:103:20 + --> tests/ui/len_zero.rs:109:20 | LL | println!("{}", &**d2s == ""); | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(**d2s).is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:118:8 + --> tests/ui/len_zero.rs:124:8 | LL | if has_is_empty.len() == 0 { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:121:8 + --> tests/ui/len_zero.rs:127:8 | LL | if has_is_empty.len() != 0 { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:124:8 + --> tests/ui/len_zero.rs:130:8 | LL | if has_is_empty.len() > 0 { | ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to one - --> tests/ui/len_zero.rs:127:8 + --> tests/ui/len_zero.rs:133:8 | LL | if has_is_empty.len() < 1 { | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to one - --> tests/ui/len_zero.rs:130:8 + --> tests/ui/len_zero.rs:136:8 | LL | if has_is_empty.len() >= 1 { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:141:8 + --> tests/ui/len_zero.rs:147:8 | LL | if 0 == has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:144:8 + --> tests/ui/len_zero.rs:150:8 | LL | if 0 != has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:147:8 + --> tests/ui/len_zero.rs:153:8 | LL | if 0 < has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to one - --> tests/ui/len_zero.rs:150:8 + --> tests/ui/len_zero.rs:156:8 | LL | if 1 <= has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to one - --> tests/ui/len_zero.rs:153:8 + --> tests/ui/len_zero.rs:159:8 | LL | if 1 > has_is_empty.len() { | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:167:8 + --> tests/ui/len_zero.rs:173:8 | LL | if with_is_empty.len() == 0 { | ^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `with_is_empty.is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:179:6 + --> tests/ui/len_zero.rs:185:6 | LL | (has_is_empty.len() > 0).then(|| println!("This can happen.")); | ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:180:6 + --> tests/ui/len_zero.rs:186:6 | LL | (has_is_empty.len() == 0).then(|| println!("Or this!")); | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()` error: length comparison to zero - --> tests/ui/len_zero.rs:184:8 + --> tests/ui/len_zero.rs:190:8 | LL | if b.len() != 0 {} | ^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!b.is_empty()` diff --git a/src/tools/clippy/tests/ui/let_if_seq.rs b/src/tools/clippy/tests/ui/let_if_seq.rs index 9869d945299..a29d35880b8 100644 --- a/src/tools/clippy/tests/ui/let_if_seq.rs +++ b/src/tools/clippy/tests/ui/let_if_seq.rs @@ -57,6 +57,17 @@ fn early_return() -> u8 { foo } +fn allow_works() -> i32 { + #[allow(clippy::useless_let_if_seq)] + let x; + if true { + x = 1; + } else { + x = 2; + } + x +} + fn main() { early_return(); issue975(); diff --git a/src/tools/clippy/tests/ui/let_if_seq.stderr b/src/tools/clippy/tests/ui/let_if_seq.stderr index 87ad20dc27e..41930108fb1 100644 --- a/src/tools/clippy/tests/ui/let_if_seq.stderr +++ b/src/tools/clippy/tests/ui/let_if_seq.stderr @@ -1,5 +1,5 @@ error: `if _ { .. } else { .. }` is an expression - --> tests/ui/let_if_seq.rs:66:5 + --> tests/ui/let_if_seq.rs:77:5 | LL | / let mut foo = 0; LL | | @@ -14,7 +14,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::useless_let_if_seq)]` error: `if _ { .. } else { .. }` is an expression - --> tests/ui/let_if_seq.rs:73:5 + --> tests/ui/let_if_seq.rs:84:5 | LL | / let mut bar = 0; LL | | @@ -28,7 +28,7 @@ LL | | } = note: you might not need `mut` at all error: `if _ { .. } else { .. }` is an expression - --> tests/ui/let_if_seq.rs:83:5 + --> tests/ui/let_if_seq.rs:94:5 | LL | / let quz; LL | | @@ -40,7 +40,7 @@ LL | | } | |_____^ help: it is more idiomatic to write: `let quz = if f() { 42 } else { 0 };` error: `if _ { .. } else { .. }` is an expression - --> tests/ui/let_if_seq.rs:113:5 + --> tests/ui/let_if_seq.rs:124:5 | LL | / let mut baz = 0; LL | | diff --git a/src/tools/clippy/tests/ui/manual_let_else.rs b/src/tools/clippy/tests/ui/manual_let_else.rs index 1fb252e3f97..2b36c3f3c2f 100644 --- a/src/tools/clippy/tests/ui/manual_let_else.rs +++ b/src/tools/clippy/tests/ui/manual_let_else.rs @@ -8,7 +8,8 @@ clippy::never_loop, clippy::needless_if, clippy::diverging_sub_expression, - clippy::single_match + clippy::single_match, + clippy::manual_unwrap_or_default )] #![warn(clippy::manual_let_else)] //@no-rustfix diff --git a/src/tools/clippy/tests/ui/manual_let_else.stderr b/src/tools/clippy/tests/ui/manual_let_else.stderr index 7012c6b8891..55a410982ad 100644 --- a/src/tools/clippy/tests/ui/manual_let_else.stderr +++ b/src/tools/clippy/tests/ui/manual_let_else.stderr @@ -1,5 +1,5 @@ error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:28:5 + --> tests/ui/manual_let_else.rs:29:5 | LL | let v = if let Some(v_some) = g() { v_some } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return };` @@ -8,7 +8,7 @@ LL | let v = if let Some(v_some) = g() { v_some } else { return }; = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:31:5 + --> tests/ui/manual_let_else.rs:32:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -26,7 +26,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:38:5 + --> tests/ui/manual_let_else.rs:39:5 | LL | / let v = if let Some(v) = g() { LL | | @@ -47,25 +47,25 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:50:9 + --> tests/ui/manual_let_else.rs:51:9 | LL | let v = if let Some(v_some) = g() { v_some } else { continue }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { continue };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:52:9 + --> tests/ui/manual_let_else.rs:53:9 | LL | let v = if let Some(v_some) = g() { v_some } else { break }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { break };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:57:5 + --> tests/ui/manual_let_else.rs:58:5 | LL | let v = if let Some(v_some) = g() { v_some } else { panic!() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { panic!() };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:61:5 + --> tests/ui/manual_let_else.rs:62:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -83,7 +83,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:69:5 + --> tests/ui/manual_let_else.rs:70:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -101,7 +101,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:77:5 + --> tests/ui/manual_let_else.rs:78:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -121,7 +121,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:86:5 + --> tests/ui/manual_let_else.rs:87:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -141,7 +141,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:95:5 + --> tests/ui/manual_let_else.rs:96:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -168,7 +168,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:111:5 + --> tests/ui/manual_let_else.rs:112:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -190,7 +190,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:122:5 + --> tests/ui/manual_let_else.rs:123:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -217,7 +217,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:138:5 + --> tests/ui/manual_let_else.rs:139:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -239,7 +239,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:149:5 + --> tests/ui/manual_let_else.rs:150:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -257,7 +257,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:157:5 + --> tests/ui/manual_let_else.rs:158:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -278,7 +278,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:167:5 + --> tests/ui/manual_let_else.rs:168:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -299,7 +299,7 @@ LL + } }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:177:5 + --> tests/ui/manual_let_else.rs:178:5 | LL | / let v = if let Some(v_some) = g() { LL | | @@ -328,7 +328,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:195:5 + --> tests/ui/manual_let_else.rs:196:5 | LL | / let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) { LL | | @@ -346,7 +346,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:203:5 + --> tests/ui/manual_let_else.rs:204:5 | LL | / let (w, S { v }) = if let (Some(v_some), w_some) = (g().map(|_| S { v: 0 }), 0) { LL | | @@ -364,7 +364,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:213:13 + --> tests/ui/manual_let_else.rs:214:13 | LL | let $n = if let Some(v) = $e { v } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some($n) = g() else { return };` @@ -375,19 +375,19 @@ LL | create_binding_if_some!(w, g()); = note: this error originates in the macro `create_binding_if_some` (in Nightly builds, run with -Z macro-backtrace for more info) error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:222:5 + --> tests/ui/manual_let_else.rs:223:5 | LL | let v = if let Variant::A(a, 0) = e() { a } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::A(v, 0) = e() else { return };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:226:5 + --> tests/ui/manual_let_else.rs:227:5 | LL | let mut v = if let Variant::B(b) = e() { b } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::B(mut v) = e() else { return };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:231:5 + --> tests/ui/manual_let_else.rs:232:5 | LL | / let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested { LL | | @@ -405,19 +405,19 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:238:5 + --> tests/ui/manual_let_else.rs:239:5 | LL | let v = if let Variant::A(.., a) = e() { a } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::A(.., v) = e() else { return };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:242:5 + --> tests/ui/manual_let_else.rs:243:5 | LL | let w = if let (Some(v), ()) = (g(), ()) { v } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let (Some(w), ()) = (g(), ()) else { return };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:246:5 + --> tests/ui/manual_let_else.rs:247:5 | LL | / let w = if let Some(S { v: x }) = Some(S { v: 0 }) { LL | | @@ -435,7 +435,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:254:5 + --> tests/ui/manual_let_else.rs:255:5 | LL | / let v = if let Some(S { v: x }) = Some(S { v: 0 }) { LL | | @@ -453,7 +453,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:262:5 + --> tests/ui/manual_let_else.rs:263:5 | LL | / let (x, S { v }, w) = if let Some(U { v, w, x }) = None::<U<S<()>>> { LL | | @@ -471,7 +471,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:379:5 + --> tests/ui/manual_let_else.rs:380:5 | LL | / let _ = match ff { LL | | @@ -481,7 +481,7 @@ LL | | }; | |______^ help: consider writing: `let Some(_) = ff else { macro_call!() };` error: this could be rewritten as `let...else` - --> tests/ui/manual_let_else.rs:456:9 + --> tests/ui/manual_let_else.rs:457:9 | LL | let v = if let Some(v_some) = g() { v_some } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return };` diff --git a/src/tools/clippy/tests/ui/manual_retain.fixed b/src/tools/clippy/tests/ui/manual_retain.fixed index e359dfbb98c..5540029bf6b 100644 --- a/src/tools/clippy/tests/ui/manual_retain.fixed +++ b/src/tools/clippy/tests/ui/manual_retain.fixed @@ -1,5 +1,3 @@ -//@compile-flags: -Zdeduplicate-diagnostics=yes - #![warn(clippy::manual_retain)] #![allow(unused, clippy::redundant_clone)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; diff --git a/src/tools/clippy/tests/ui/manual_retain.rs b/src/tools/clippy/tests/ui/manual_retain.rs index 931814f08b7..cee641d9d65 100644 --- a/src/tools/clippy/tests/ui/manual_retain.rs +++ b/src/tools/clippy/tests/ui/manual_retain.rs @@ -1,5 +1,3 @@ -//@compile-flags: -Zdeduplicate-diagnostics=yes - #![warn(clippy::manual_retain)] #![allow(unused, clippy::redundant_clone)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; diff --git a/src/tools/clippy/tests/ui/manual_retain.stderr b/src/tools/clippy/tests/ui/manual_retain.stderr index fdbbc53e4df..c25c804df75 100644 --- a/src/tools/clippy/tests/ui/manual_retain.stderr +++ b/src/tools/clippy/tests/ui/manual_retain.stderr @@ -1,5 +1,5 @@ error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:27:5 + --> tests/ui/manual_retain.rs:25:5 | LL | binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `binary_heap.retain(|x| x % 2 == 0)` @@ -8,43 +8,43 @@ LL | binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); = help: to override `-D warnings` add `#[allow(clippy::manual_retain)]` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:28:5 + --> tests/ui/manual_retain.rs:26:5 | LL | binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `binary_heap.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:29:5 + --> tests/ui/manual_retain.rs:27:5 | LL | binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `binary_heap.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:33:5 + --> tests/ui/manual_retain.rs:31:5 | LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:34:5 + --> tests/ui/manual_retain.rs:32:5 | LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:64:5 + --> tests/ui/manual_retain.rs:62:5 | LL | btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|k, _| k % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:65:5 + --> tests/ui/manual_retain.rs:63:5 | LL | btree_map = btree_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|_, &mut v| v % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:66:5 + --> tests/ui/manual_retain.rs:64:5 | LL | / btree_map = btree_map LL | | .into_iter() @@ -53,49 +53,49 @@ LL | | .collect(); | |__________________^ help: consider calling `.retain()` instead: `btree_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0))` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:91:5 + --> tests/ui/manual_retain.rs:89:5 | LL | btree_set = btree_set.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:92:5 + --> tests/ui/manual_retain.rs:90:5 | LL | btree_set = btree_set.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:93:5 + --> tests/ui/manual_retain.rs:91:5 | LL | btree_set = btree_set.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:97:5 + --> tests/ui/manual_retain.rs:95:5 | LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:98:5 + --> tests/ui/manual_retain.rs:96:5 | LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:128:5 + --> tests/ui/manual_retain.rs:126:5 | LL | hash_map = hash_map.into_iter().filter(|(k, _)| k % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_map.retain(|k, _| k % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:129:5 + --> tests/ui/manual_retain.rs:127:5 | LL | hash_map = hash_map.into_iter().filter(|(_, v)| v % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_map.retain(|_, &mut v| v % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:130:5 + --> tests/ui/manual_retain.rs:128:5 | LL | / hash_map = hash_map LL | | .into_iter() @@ -104,133 +104,133 @@ LL | | .collect(); | |__________________^ help: consider calling `.retain()` instead: `hash_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0))` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:154:5 + --> tests/ui/manual_retain.rs:152:5 | LL | hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:155:5 + --> tests/ui/manual_retain.rs:153:5 | LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:156:5 + --> tests/ui/manual_retain.rs:154:5 | LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:160:5 + --> tests/ui/manual_retain.rs:158:5 | LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:161:5 + --> tests/ui/manual_retain.rs:159:5 | LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:190:5 + --> tests/ui/manual_retain.rs:188:5 | LL | s = s.chars().filter(|&c| c != 'o').to_owned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `s.retain(|c| c != 'o')` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:202:5 + --> tests/ui/manual_retain.rs:200:5 | LL | vec = vec.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:203:5 + --> tests/ui/manual_retain.rs:201:5 | LL | vec = vec.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:204:5 + --> tests/ui/manual_retain.rs:202:5 | LL | vec = vec.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:208:5 + --> tests/ui/manual_retain.rs:206:5 | LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:209:5 + --> tests/ui/manual_retain.rs:207:5 | LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:231:5 + --> tests/ui/manual_retain.rs:229:5 | LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:232:5 + --> tests/ui/manual_retain.rs:230:5 | LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:233:5 + --> tests/ui/manual_retain.rs:231:5 | LL | vec_deque = vec_deque.into_iter().filter(|x| x % 2 == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:290:5 + --> tests/ui/manual_retain.rs:288:5 | LL | vec = vec.into_iter().filter(|(x, y)| *x == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|(x, y)| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:294:5 + --> tests/ui/manual_retain.rs:292:5 | LL | tuples = tuples.into_iter().filter(|(_, n)| *n > 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(_, n)| *n > 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:311:5 + --> tests/ui/manual_retain.rs:309:5 | LL | vec = vec.iter().filter(|&&x| x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:312:5 + --> tests/ui/manual_retain.rs:310:5 | LL | vec = vec.iter().filter(|&&x| x == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:313:5 + --> tests/ui/manual_retain.rs:311:5 | LL | vec = vec.into_iter().filter(|&x| x == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:316:5 + --> tests/ui/manual_retain.rs:314:5 | LL | vec = vec.iter().filter(|&x| *x == 0).copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:317:5 + --> tests/ui/manual_retain.rs:315:5 | LL | vec = vec.iter().filter(|&x| *x == 0).cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)` error: this expression can be written more simply using `.retain()` - --> tests/ui/manual_retain.rs:318:5 + --> tests/ui/manual_retain.rs:316:5 | LL | vec = vec.into_iter().filter(|x| *x == 0).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)` diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or.fixed b/src/tools/clippy/tests/ui/manual_unwrap_or.fixed index 737d4c90dca..dffd44b6a7c 100644 --- a/src/tools/clippy/tests/ui/manual_unwrap_or.fixed +++ b/src/tools/clippy/tests/ui/manual_unwrap_or.fixed @@ -1,5 +1,10 @@ #![allow(dead_code)] -#![allow(unused_variables, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)] +#![allow( + unused_variables, + clippy::unnecessary_wraps, + clippy::unnecessary_literal_unwrap, + clippy::manual_unwrap_or_default +)] fn option_unwrap_or() { // int case diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or.rs b/src/tools/clippy/tests/ui/manual_unwrap_or.rs index f59fb87529f..67427132c1a 100644 --- a/src/tools/clippy/tests/ui/manual_unwrap_or.rs +++ b/src/tools/clippy/tests/ui/manual_unwrap_or.rs @@ -1,5 +1,10 @@ #![allow(dead_code)] -#![allow(unused_variables, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)] +#![allow( + unused_variables, + clippy::unnecessary_wraps, + clippy::unnecessary_literal_unwrap, + clippy::manual_unwrap_or_default +)] fn option_unwrap_or() { // int case diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or.stderr b/src/tools/clippy/tests/ui/manual_unwrap_or.stderr index 511b79881ac..33a099680ce 100644 --- a/src/tools/clippy/tests/ui/manual_unwrap_or.stderr +++ b/src/tools/clippy/tests/ui/manual_unwrap_or.stderr @@ -1,5 +1,5 @@ error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:6:5 + --> tests/ui/manual_unwrap_or.rs:11:5 | LL | / match Some(1) { LL | | Some(i) => i, @@ -11,7 +11,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or)]` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:12:5 + --> tests/ui/manual_unwrap_or.rs:17:5 | LL | / match Some(1) { LL | | None => 42, @@ -20,7 +20,7 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:18:5 + --> tests/ui/manual_unwrap_or.rs:23:5 | LL | / match Some(1) { LL | | Some(i) => i, @@ -29,7 +29,7 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(1 + 42)` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:25:5 + --> tests/ui/manual_unwrap_or.rs:30:5 | LL | / match Some(1) { LL | | Some(i) => i, @@ -50,7 +50,7 @@ LL ~ }); | error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:35:5 + --> tests/ui/manual_unwrap_or.rs:40:5 | LL | / match Some("Bob") { LL | | Some(i) => i, @@ -59,7 +59,7 @@ LL | | }; | |_____^ help: replace with: `Some("Bob").unwrap_or("Alice")` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:85:5 + --> tests/ui/manual_unwrap_or.rs:90:5 | LL | / match Ok::<i32, &str>(1) { LL | | Ok(i) => i, @@ -68,7 +68,7 @@ LL | | }; | |_____^ help: replace with: `Ok::<i32, &str>(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:92:5 + --> tests/ui/manual_unwrap_or.rs:97:5 | LL | / match a { LL | | Ok(i) => i, @@ -77,7 +77,7 @@ LL | | }; | |_____^ help: replace with: `a.unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:98:5 + --> tests/ui/manual_unwrap_or.rs:103:5 | LL | / match Ok(1) as Result<i32, &str> { LL | | Ok(i) => i, @@ -86,7 +86,7 @@ LL | | }; | |_____^ help: replace with: `(Ok(1) as Result<i32, &str>).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:111:5 + --> tests/ui/manual_unwrap_or.rs:116:5 | LL | / match s.method() { LL | | Some(i) => i, @@ -95,7 +95,7 @@ LL | | }; | |_____^ help: replace with: `s.method().unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:117:5 + --> tests/ui/manual_unwrap_or.rs:122:5 | LL | / match Ok::<i32, &str>(1) { LL | | Err(_) => 42, @@ -104,7 +104,7 @@ LL | | }; | |_____^ help: replace with: `Ok::<i32, &str>(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:123:5 + --> tests/ui/manual_unwrap_or.rs:128:5 | LL | / match Ok::<i32, &str>(1) { LL | | Ok(i) => i, @@ -113,7 +113,7 @@ LL | | }; | |_____^ help: replace with: `Ok::<i32, &str>(1).unwrap_or(1 + 42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:130:5 + --> tests/ui/manual_unwrap_or.rs:135:5 | LL | / match Ok::<i32, &str>(1) { LL | | Ok(i) => i, @@ -134,7 +134,7 @@ LL ~ }); | error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:140:5 + --> tests/ui/manual_unwrap_or.rs:145:5 | LL | / match Ok::<&str, &str>("Bob") { LL | | Ok(i) => i, @@ -143,7 +143,7 @@ LL | | }; | |_____^ help: replace with: `Ok::<&str, &str>("Bob").unwrap_or("Alice")` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:200:17 + --> tests/ui/manual_unwrap_or.rs:205:17 | LL | let _ = match some_macro!() { | _________________^ diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or_default.fixed b/src/tools/clippy/tests/ui/manual_unwrap_or_default.fixed new file mode 100644 index 00000000000..c8456805ee6 --- /dev/null +++ b/src/tools/clippy/tests/ui/manual_unwrap_or_default.fixed @@ -0,0 +1,19 @@ +#![warn(clippy::manual_unwrap_or_default)] +#![allow(clippy::unnecessary_literal_unwrap)] + +fn main() { + let x: Option<Vec<String>> = None; + x.unwrap_or_default(); + + let x: Option<Vec<String>> = None; + x.unwrap_or_default(); + + let x: Option<String> = None; + x.unwrap_or_default(); + + let x: Option<Vec<String>> = None; + x.unwrap_or_default(); + + let x: Option<Vec<String>> = None; + x.unwrap_or_default(); +} diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or_default.rs b/src/tools/clippy/tests/ui/manual_unwrap_or_default.rs new file mode 100644 index 00000000000..820717be53a --- /dev/null +++ b/src/tools/clippy/tests/ui/manual_unwrap_or_default.rs @@ -0,0 +1,40 @@ +#![warn(clippy::manual_unwrap_or_default)] +#![allow(clippy::unnecessary_literal_unwrap)] + +fn main() { + let x: Option<Vec<String>> = None; + match x { + //~^ ERROR: match can be simplified with `.unwrap_or_default()` + Some(v) => v, + None => Vec::default(), + }; + + let x: Option<Vec<String>> = None; + match x { + //~^ ERROR: match can be simplified with `.unwrap_or_default()` + Some(v) => v, + _ => Vec::default(), + }; + + let x: Option<String> = None; + match x { + //~^ ERROR: match can be simplified with `.unwrap_or_default()` + Some(v) => v, + None => String::new(), + }; + + let x: Option<Vec<String>> = None; + match x { + //~^ ERROR: match can be simplified with `.unwrap_or_default()` + None => Vec::default(), + Some(v) => v, + }; + + let x: Option<Vec<String>> = None; + if let Some(v) = x { + //~^ ERROR: if let can be simplified with `.unwrap_or_default()` + v + } else { + Vec::default() + }; +} diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or_default.stderr b/src/tools/clippy/tests/ui/manual_unwrap_or_default.stderr new file mode 100644 index 00000000000..f4eb6583588 --- /dev/null +++ b/src/tools/clippy/tests/ui/manual_unwrap_or_default.stderr @@ -0,0 +1,56 @@ +error: match can be simplified with `.unwrap_or_default()` + --> tests/ui/manual_unwrap_or_default.rs:6:5 + | +LL | / match x { +LL | | +LL | | Some(v) => v, +LL | | None => Vec::default(), +LL | | }; + | |_____^ help: replace it with: `x.unwrap_or_default()` + | + = note: `-D clippy::manual-unwrap-or-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or_default)]` + +error: match can be simplified with `.unwrap_or_default()` + --> tests/ui/manual_unwrap_or_default.rs:13:5 + | +LL | / match x { +LL | | +LL | | Some(v) => v, +LL | | _ => Vec::default(), +LL | | }; + | |_____^ help: replace it with: `x.unwrap_or_default()` + +error: match can be simplified with `.unwrap_or_default()` + --> tests/ui/manual_unwrap_or_default.rs:20:5 + | +LL | / match x { +LL | | +LL | | Some(v) => v, +LL | | None => String::new(), +LL | | }; + | |_____^ help: replace it with: `x.unwrap_or_default()` + +error: match can be simplified with `.unwrap_or_default()` + --> tests/ui/manual_unwrap_or_default.rs:27:5 + | +LL | / match x { +LL | | +LL | | None => Vec::default(), +LL | | Some(v) => v, +LL | | }; + | |_____^ help: replace it with: `x.unwrap_or_default()` + +error: if let can be simplified with `.unwrap_or_default()` + --> tests/ui/manual_unwrap_or_default.rs:34:5 + | +LL | / if let Some(v) = x { +LL | | +LL | | v +LL | | } else { +LL | | Vec::default() +LL | | }; + | |_____^ help: replace it with: `x.unwrap_or_default()` + +error: aborting due to 5 previous errors + diff --git a/src/tools/clippy/tests/ui/map_clone.fixed b/src/tools/clippy/tests/ui/map_clone.fixed index 395eea69294..e58b6b2f19e 100644 --- a/src/tools/clippy/tests/ui/map_clone.fixed +++ b/src/tools/clippy/tests/ui/map_clone.fixed @@ -6,7 +6,8 @@ clippy::redundant_clone, clippy::redundant_closure, clippy::useless_asref, - clippy::useless_vec + clippy::useless_vec, + clippy::empty_loop )] fn main() { @@ -117,4 +118,17 @@ fn main() { let y = x.as_ref().map(|x| String::clone(x)); let x: Result<String, ()> = Ok(String::new()); let y = x.as_ref().map(|x| String::clone(x)); + + // Issue #12271 + { + // Don't lint these + let x: Option<&u8> = None; + let y = x.map(|x| String::clone(loop {})); + let x: Option<&u8> = None; + let y = x.map(|x| u8::clone(loop {})); + let x: Vec<&u8> = vec![]; + let y = x.into_iter().map(|x| String::clone(loop {})); + let x: Vec<&u8> = vec![]; + let y = x.into_iter().map(|x| u8::clone(loop {})); + } } diff --git a/src/tools/clippy/tests/ui/map_clone.rs b/src/tools/clippy/tests/ui/map_clone.rs index 82a103edf5a..e642e4046f8 100644 --- a/src/tools/clippy/tests/ui/map_clone.rs +++ b/src/tools/clippy/tests/ui/map_clone.rs @@ -6,7 +6,8 @@ clippy::redundant_clone, clippy::redundant_closure, clippy::useless_asref, - clippy::useless_vec + clippy::useless_vec, + clippy::empty_loop )] fn main() { @@ -117,4 +118,17 @@ fn main() { let y = x.as_ref().map(|x| String::clone(x)); let x: Result<String, ()> = Ok(String::new()); let y = x.as_ref().map(|x| String::clone(x)); + + // Issue #12271 + { + // Don't lint these + let x: Option<&u8> = None; + let y = x.map(|x| String::clone(loop {})); + let x: Option<&u8> = None; + let y = x.map(|x| u8::clone(loop {})); + let x: Vec<&u8> = vec![]; + let y = x.into_iter().map(|x| String::clone(loop {})); + let x: Vec<&u8> = vec![]; + let y = x.into_iter().map(|x| u8::clone(loop {})); + } } diff --git a/src/tools/clippy/tests/ui/map_clone.stderr b/src/tools/clippy/tests/ui/map_clone.stderr index 1a26a26a4ca..d9e025de4ab 100644 --- a/src/tools/clippy/tests/ui/map_clone.stderr +++ b/src/tools/clippy/tests/ui/map_clone.stderr @@ -1,5 +1,5 @@ error: you are using an explicit closure for copying elements - --> tests/ui/map_clone.rs:13:22 + --> tests/ui/map_clone.rs:14:22 | LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![5_i8; 6].iter().copied()` @@ -8,85 +8,85 @@ LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect(); = help: to override `-D warnings` add `#[allow(clippy::map_clone)]` error: you are using an explicit closure for cloning elements - --> tests/ui/map_clone.rs:14:26 + --> tests/ui/map_clone.rs:15:26 | LL | let _: Vec<String> = vec![String::new()].iter().map(|x| x.clone()).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `vec![String::new()].iter().cloned()` error: you are using an explicit closure for copying elements - --> tests/ui/map_clone.rs:15:23 + --> tests/ui/map_clone.rs:16:23 | LL | let _: Vec<u32> = vec![42, 43].iter().map(|&x| x).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![42, 43].iter().copied()` error: you are using an explicit closure for copying elements - --> tests/ui/map_clone.rs:17:26 + --> tests/ui/map_clone.rs:18:26 | LL | let _: Option<u64> = Some(&16).map(|b| *b); | ^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&16).copied()` error: you are using an explicit closure for copying elements - --> tests/ui/map_clone.rs:18:25 + --> tests/ui/map_clone.rs:19:25 | LL | let _: Option<u8> = Some(&1).map(|x| x.clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&1).copied()` error: you are needlessly cloning iterator elements - --> tests/ui/map_clone.rs:29:29 + --> tests/ui/map_clone.rs:30:29 | LL | let _ = std::env::args().map(|v| v.clone()); | ^^^^^^^^^^^^^^^^^^^ help: remove the `map` call error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:68:13 + --> tests/ui/map_clone.rs:69:13 | LL | let y = x.map(|x| String::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:70:13 + --> tests/ui/map_clone.rs:71:13 | LL | let y = x.map(Clone::clone); | ^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:73:13 + --> tests/ui/map_clone.rs:74:13 | LL | let y = x.map(String::clone); | ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:79:13 + --> tests/ui/map_clone.rs:80:13 | LL | let y = x.map(|x| u32::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:82:13 + --> tests/ui/map_clone.rs:83:13 | LL | let y = x.map(|x| Clone::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:94:13 + --> tests/ui/map_clone.rs:95:13 | LL | let y = x.map(|x| String::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:97:13 + --> tests/ui/map_clone.rs:98:13 | LL | let y = x.map(|x| Clone::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.cloned()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:103:13 + --> tests/ui/map_clone.rs:104:13 | LL | let y = x.map(|x| u32::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` error: you are explicitly cloning with `.map()` - --> tests/ui/map_clone.rs:106:13 + --> tests/ui/map_clone.rs:107:13 | LL | let y = x.map(|x| Clone::clone(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.copied()` diff --git a/src/tools/clippy/tests/ui/match_result_ok.fixed b/src/tools/clippy/tests/ui/match_result_ok.fixed index 8d7cddc0ad7..76b26f5e438 100644 --- a/src/tools/clippy/tests/ui/match_result_ok.fixed +++ b/src/tools/clippy/tests/ui/match_result_ok.fixed @@ -1,6 +1,6 @@ #![warn(clippy::match_result_ok)] #![allow(dead_code)] -#![allow(clippy::boxed_local, clippy::uninlined_format_args)] +#![allow(clippy::boxed_local, clippy::uninlined_format_args, clippy::manual_unwrap_or_default)] // Checking `if` cases diff --git a/src/tools/clippy/tests/ui/match_result_ok.rs b/src/tools/clippy/tests/ui/match_result_ok.rs index 9a18b813aca..d6f2475ba79 100644 --- a/src/tools/clippy/tests/ui/match_result_ok.rs +++ b/src/tools/clippy/tests/ui/match_result_ok.rs @@ -1,6 +1,6 @@ #![warn(clippy::match_result_ok)] #![allow(dead_code)] -#![allow(clippy::boxed_local, clippy::uninlined_format_args)] +#![allow(clippy::boxed_local, clippy::uninlined_format_args, clippy::manual_unwrap_or_default)] // Checking `if` cases diff --git a/src/tools/clippy/tests/ui/missing_doc.rs b/src/tools/clippy/tests/ui/missing_doc.rs index 9bfad3b96cf..9c936d7fa23 100644 --- a/src/tools/clippy/tests/ui/missing_doc.rs +++ b/src/tools/clippy/tests/ui/missing_doc.rs @@ -1,5 +1,6 @@ //@needs-asm-support //@aux-build: proc_macros.rs +//@aux-build: proc_macro_attr.rs #![warn(clippy::missing_docs_in_private_items)] // When denying at the crate level, be sure to not get random warnings from the @@ -8,6 +9,8 @@ //! Some garbage docs for the crate here #![doc = "More garbage"] +#[macro_use] +extern crate proc_macro_attr; extern crate proc_macros; use proc_macros::with_span; @@ -112,3 +115,12 @@ with_span!(span pub enum FooPm3 { A, B(u32), C { field: u32 }}); with_span!(span pub fn foo_pm() {}); with_span!(span pub static FOO_PM: u32 = 0;); with_span!(span pub const FOO2_PM: u32 = 0;); + +// issue #12197 +// Undocumented field originated inside of spanned proc-macro attribute +/// Some dox for struct. +#[rewrite_struct] +pub struct Test { + /// Dox + a: u8, +} diff --git a/src/tools/clippy/tests/ui/missing_doc.stderr b/src/tools/clippy/tests/ui/missing_doc.stderr index 7e66e2097e9..ef0f96a5b71 100644 --- a/src/tools/clippy/tests/ui/missing_doc.stderr +++ b/src/tools/clippy/tests/ui/missing_doc.stderr @@ -1,5 +1,5 @@ error: missing documentation for a type alias - --> tests/ui/missing_doc.rs:16:1 + --> tests/ui/missing_doc.rs:19:1 | LL | type Typedef = String; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -8,19 +8,19 @@ LL | type Typedef = String; = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: missing documentation for a module - --> tests/ui/missing_doc.rs:19:1 + --> tests/ui/missing_doc.rs:22:1 | LL | mod module_no_dox {} | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> tests/ui/missing_doc.rs:25:1 + --> tests/ui/missing_doc.rs:28:1 | LL | fn foo3() {} | ^^^^^^^^^^^^ error: missing documentation for an enum - --> tests/ui/missing_doc.rs:39:1 + --> tests/ui/missing_doc.rs:42:1 | LL | / enum Baz { LL | | BazA { a: isize, b: isize }, @@ -29,43 +29,43 @@ LL | | } | |_^ error: missing documentation for a variant - --> tests/ui/missing_doc.rs:40:5 + --> tests/ui/missing_doc.rs:43:5 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a struct field - --> tests/ui/missing_doc.rs:40:12 + --> tests/ui/missing_doc.rs:43:12 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^ error: missing documentation for a struct field - --> tests/ui/missing_doc.rs:40:22 + --> tests/ui/missing_doc.rs:43:22 | LL | BazA { a: isize, b: isize }, | ^^^^^^^^ error: missing documentation for a variant - --> tests/ui/missing_doc.rs:41:5 + --> tests/ui/missing_doc.rs:44:5 | LL | BarB, | ^^^^ error: missing documentation for a constant - --> tests/ui/missing_doc.rs:65:1 + --> tests/ui/missing_doc.rs:68:1 | LL | const FOO: u32 = 0; | ^^^^^^^^^^^^^^^^^^^ error: missing documentation for a static - --> tests/ui/missing_doc.rs:74:1 + --> tests/ui/missing_doc.rs:77:1 | LL | static BAR: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a module - --> tests/ui/missing_doc.rs:83:1 + --> tests/ui/missing_doc.rs:86:1 | LL | / mod internal_impl { LL | | /// dox @@ -77,13 +77,13 @@ LL | | } | |_^ error: missing documentation for a function - --> tests/ui/missing_doc.rs:88:5 + --> tests/ui/missing_doc.rs:91:5 | LL | fn undocumented3() {} | ^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function - --> tests/ui/missing_doc.rs:94:9 + --> tests/ui/missing_doc.rs:97:9 | LL | fn also_undocumented2() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/mixed_attributes_style.rs b/src/tools/clippy/tests/ui/mixed_attributes_style.rs index ad93e3019fa..4f89aa8a5e5 100644 --- a/src/tools/clippy/tests/ui/mixed_attributes_style.rs +++ b/src/tools/clippy/tests/ui/mixed_attributes_style.rs @@ -1,4 +1,5 @@ #![warn(clippy::mixed_attributes_style)] +#![allow(clippy::duplicated_attributes)] #[allow(unused)] //~ ERROR: item has both inner and outer attributes fn foo1() { diff --git a/src/tools/clippy/tests/ui/mixed_attributes_style.stderr b/src/tools/clippy/tests/ui/mixed_attributes_style.stderr index d1d5cd3f47f..ed798073cb7 100644 --- a/src/tools/clippy/tests/ui/mixed_attributes_style.stderr +++ b/src/tools/clippy/tests/ui/mixed_attributes_style.stderr @@ -1,5 +1,5 @@ error: item has both inner and outer attributes - --> tests/ui/mixed_attributes_style.rs:3:1 + --> tests/ui/mixed_attributes_style.rs:4:1 | LL | / #[allow(unused)] LL | | fn foo1() { @@ -10,7 +10,7 @@ LL | | #![allow(unused)] = help: to override `-D warnings` add `#[allow(clippy::mixed_attributes_style)]` error: item has both inner and outer attributes - --> tests/ui/mixed_attributes_style.rs:17:1 + --> tests/ui/mixed_attributes_style.rs:18:1 | LL | / /// linux LL | | @@ -19,7 +19,7 @@ LL | | //! windows | |_______________^ error: item has both inner and outer attributes - --> tests/ui/mixed_attributes_style.rs:32:1 + --> tests/ui/mixed_attributes_style.rs:33:1 | LL | / #[allow(unused)] LL | | mod bar { diff --git a/src/tools/clippy/tests/ui/mut_mut.rs b/src/tools/clippy/tests/ui/mut_mut.rs index 288b003405d..4c45bc98026 100644 --- a/src/tools/clippy/tests/ui/mut_mut.rs +++ b/src/tools/clippy/tests/ui/mut_mut.rs @@ -1,5 +1,4 @@ //@aux-build:proc_macros.rs -//@compile-flags: -Zdeduplicate-diagnostics=yes #![warn(clippy::mut_mut)] #![allow(unused)] @@ -82,3 +81,8 @@ mod issue9035 { fn bar(_: &mut impl Display) {} } + +fn allow_works() { + #[allow(clippy::mut_mut)] + let _ = &mut &mut 1; +} diff --git a/src/tools/clippy/tests/ui/mut_mut.stderr b/src/tools/clippy/tests/ui/mut_mut.stderr index 73f2410a252..42853fdc008 100644 --- a/src/tools/clippy/tests/ui/mut_mut.stderr +++ b/src/tools/clippy/tests/ui/mut_mut.stderr @@ -1,5 +1,5 @@ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:16:11 + --> tests/ui/mut_mut.rs:15:11 | LL | fn fun(x: &mut &mut u32) -> bool { | ^^^^^^^^^^^^^ @@ -8,13 +8,13 @@ LL | fn fun(x: &mut &mut u32) -> bool { = help: to override `-D warnings` add `#[allow(clippy::mut_mut)]` error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:33:17 + --> tests/ui/mut_mut.rs:32:17 | LL | let mut x = &mut &mut 1u32; | ^^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:48:25 + --> tests/ui/mut_mut.rs:47:25 | LL | let mut z = inline!(&mut $(&mut 3u32)); | ^ @@ -22,37 +22,37 @@ LL | let mut z = inline!(&mut $(&mut 3u32)); = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: this expression mutably borrows a mutable reference. Consider reborrowing - --> tests/ui/mut_mut.rs:35:21 + --> tests/ui/mut_mut.rs:34:21 | LL | let mut y = &mut x; | ^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:39:32 + --> tests/ui/mut_mut.rs:38:32 | LL | let y: &mut &mut u32 = &mut &mut 2; | ^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:39:16 + --> tests/ui/mut_mut.rs:38:16 | LL | let y: &mut &mut u32 = &mut &mut 2; | ^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:44:37 + --> tests/ui/mut_mut.rs:43:37 | LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; | ^^^^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:44:16 + --> tests/ui/mut_mut.rs:43:16 | LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; | ^^^^^^^^^^^^^^^^^^ error: generally you want to avoid `&mut &mut _` if possible - --> tests/ui/mut_mut.rs:44:21 + --> tests/ui/mut_mut.rs:43:21 | LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; | ^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed b/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed index 201f8a4c19d..a8176618c1f 100644 --- a/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed +++ b/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed @@ -1,4 +1,5 @@ #![warn(clippy::needless_bitwise_bool)] +#![allow(clippy::const_is_empty)] fn returns_bool() -> bool { true diff --git a/src/tools/clippy/tests/ui/needless_bitwise_bool.rs b/src/tools/clippy/tests/ui/needless_bitwise_bool.rs index b0e5014b74b..f190eb2b76e 100644 --- a/src/tools/clippy/tests/ui/needless_bitwise_bool.rs +++ b/src/tools/clippy/tests/ui/needless_bitwise_bool.rs @@ -1,4 +1,5 @@ #![warn(clippy::needless_bitwise_bool)] +#![allow(clippy::const_is_empty)] fn returns_bool() -> bool { true diff --git a/src/tools/clippy/tests/ui/needless_bitwise_bool.stderr b/src/tools/clippy/tests/ui/needless_bitwise_bool.stderr index f29d4492540..9f14646c3e5 100644 --- a/src/tools/clippy/tests/ui/needless_bitwise_bool.stderr +++ b/src/tools/clippy/tests/ui/needless_bitwise_bool.stderr @@ -1,5 +1,5 @@ error: use of bitwise operator instead of lazy operator between booleans - --> tests/ui/needless_bitwise_bool.rs:22:8 + --> tests/ui/needless_bitwise_bool.rs:23:8 | LL | if y & !x { | ^^^^^^ help: try: `y && !x` diff --git a/src/tools/clippy/tests/ui/needless_return.fixed b/src/tools/clippy/tests/ui/needless_return.fixed index f9eb39d4938..2575f2449e1 100644 --- a/src/tools/clippy/tests/ui/needless_return.fixed +++ b/src/tools/clippy/tests/ui/needless_return.fixed @@ -316,4 +316,11 @@ fn test_match_as_stmt() { }; } +fn allow_works() -> i32 { + #[allow(clippy::needless_return, clippy::match_single_binding)] + match () { + () => return 42, + } +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/needless_return.rs b/src/tools/clippy/tests/ui/needless_return.rs index 4dd2e22ea9f..04f21834d88 100644 --- a/src/tools/clippy/tests/ui/needless_return.rs +++ b/src/tools/clippy/tests/ui/needless_return.rs @@ -326,4 +326,11 @@ fn test_match_as_stmt() { }; } +fn allow_works() -> i32 { + #[allow(clippy::needless_return, clippy::match_single_binding)] + match () { + () => return 42, + } +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/no_effect_replace.rs b/src/tools/clippy/tests/ui/no_effect_replace.rs index 2a940d87fb9..e4fd5caae2a 100644 --- a/src/tools/clippy/tests/ui/no_effect_replace.rs +++ b/src/tools/clippy/tests/ui/no_effect_replace.rs @@ -1,5 +1,3 @@ -//@compile-flags: -Zdeduplicate-diagnostics=yes - #![warn(clippy::no_effect_replace)] fn main() { diff --git a/src/tools/clippy/tests/ui/no_effect_replace.stderr b/src/tools/clippy/tests/ui/no_effect_replace.stderr index ad2dcd2cc9b..ded86c5c5b8 100644 --- a/src/tools/clippy/tests/ui/no_effect_replace.stderr +++ b/src/tools/clippy/tests/ui/no_effect_replace.stderr @@ -1,5 +1,5 @@ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:6:13 + --> tests/ui/no_effect_replace.rs:4:13 | LL | let _ = "12345".replace('1', "1"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,43 +8,43 @@ LL | let _ = "12345".replace('1', "1"); = help: to override `-D warnings` add `#[allow(clippy::no_effect_replace)]` error: replacing text with itself - --> tests/ui/no_effect_replace.rs:9:13 + --> tests/ui/no_effect_replace.rs:7:13 | LL | let _ = "12345".replace("12", "12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:11:13 + --> tests/ui/no_effect_replace.rs:9:13 | LL | let _ = String::new().replace("12", "12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:14:13 + --> tests/ui/no_effect_replace.rs:12:13 | LL | let _ = "12345".replacen('1', "1", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:16:13 + --> tests/ui/no_effect_replace.rs:14:13 | LL | let _ = "12345".replacen("12", "12", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:18:13 + --> tests/ui/no_effect_replace.rs:16:13 | LL | let _ = String::new().replacen("12", "12", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:25:13 + --> tests/ui/no_effect_replace.rs:23:13 | LL | let _ = "hello".replace(&x.f(), &x.f()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> tests/ui/no_effect_replace.rs:29:13 + --> tests/ui/no_effect_replace.rs:27:13 | LL | let _ = "hello".replace(&y(), &y()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/option_if_let_else.fixed b/src/tools/clippy/tests/ui/option_if_let_else.fixed index d443334bb05..eeab801b7da 100644 --- a/src/tools/clippy/tests/ui/option_if_let_else.fixed +++ b/src/tools/clippy/tests/ui/option_if_let_else.fixed @@ -3,7 +3,8 @@ clippy::ref_option_ref, clippy::equatable_if_let, clippy::let_unit_value, - clippy::redundant_locals + clippy::redundant_locals, + clippy::manual_unwrap_or_default )] fn bad1(string: Option<&str>) -> (bool, &str) { diff --git a/src/tools/clippy/tests/ui/option_if_let_else.rs b/src/tools/clippy/tests/ui/option_if_let_else.rs index 317c35bf842..3e5b96d7c31 100644 --- a/src/tools/clippy/tests/ui/option_if_let_else.rs +++ b/src/tools/clippy/tests/ui/option_if_let_else.rs @@ -3,7 +3,8 @@ clippy::ref_option_ref, clippy::equatable_if_let, clippy::let_unit_value, - clippy::redundant_locals + clippy::redundant_locals, + clippy::manual_unwrap_or_default )] fn bad1(string: Option<&str>) -> (bool, &str) { diff --git a/src/tools/clippy/tests/ui/option_if_let_else.stderr b/src/tools/clippy/tests/ui/option_if_let_else.stderr index a794dca762f..f5359a0c34f 100644 --- a/src/tools/clippy/tests/ui/option_if_let_else.stderr +++ b/src/tools/clippy/tests/ui/option_if_let_else.stderr @@ -1,5 +1,5 @@ error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:10:5 + --> tests/ui/option_if_let_else.rs:11:5 | LL | / if let Some(x) = string { LL | | (true, x) @@ -12,19 +12,19 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::option_if_let_else)]` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:28:13 + --> tests/ui/option_if_let_else.rs:29:13 | LL | let _ = if let Some(s) = *string { s.len() } else { 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:29:13 + --> tests/ui/option_if_let_else.rs:30:13 | LL | let _ = if let Some(s) = &num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:30:13 + --> tests/ui/option_if_let_else.rs:31:13 | LL | let _ = if let Some(s) = &mut num { | _____________^ @@ -44,13 +44,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:36:13 + --> tests/ui/option_if_let_else.rs:37:13 | LL | let _ = if let Some(ref s) = num { s } else { &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:37:13 + --> tests/ui/option_if_let_else.rs:38:13 | LL | let _ = if let Some(mut s) = num { | _____________^ @@ -70,7 +70,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:43:13 + --> tests/ui/option_if_let_else.rs:44:13 | LL | let _ = if let Some(ref mut s) = num { | _____________^ @@ -90,7 +90,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:52:5 + --> tests/ui/option_if_let_else.rs:53:5 | LL | / if let Some(x) = arg { LL | | let y = x * x; @@ -109,7 +109,7 @@ LL + }) | error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:65:13 + --> tests/ui/option_if_let_else.rs:66:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -121,7 +121,7 @@ LL | | }; | |_____^ help: try: `arg.map_or_else(side_effect, |x| x)` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:74:13 + --> tests/ui/option_if_let_else.rs:75:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -144,7 +144,7 @@ LL ~ }, |x| x * x * x * x); | error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:107:13 + --> tests/ui/option_if_let_else.rs:108:13 | LL | / if let Some(idx) = s.find('.') { LL | | vec![s[..idx].to_string(), s[idx..].to_string()] @@ -154,7 +154,7 @@ LL | | } | |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:118:5 + --> tests/ui/option_if_let_else.rs:119:5 | LL | / if let Ok(binding) = variable { LL | | println!("Ok {binding}"); @@ -177,13 +177,13 @@ LL + }) | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:142:13 + --> tests/ui/option_if_let_else.rs:143:13 | LL | let _ = if let Some(x) = optional { x + 2 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:152:13 + --> tests/ui/option_if_let_else.rs:153:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -205,13 +205,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:180:13 + --> tests/ui/option_if_let_else.rs:181:13 | LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:184:13 + --> tests/ui/option_if_let_else.rs:185:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -231,7 +231,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:223:13 + --> tests/ui/option_if_let_else.rs:224:13 | LL | let _ = match s { | _____________^ @@ -241,7 +241,7 @@ LL | | }; | |_____^ help: try: `s.map_or(1, |string| string.len())` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:227:13 + --> tests/ui/option_if_let_else.rs:228:13 | LL | let _ = match Some(10) { | _____________^ @@ -251,7 +251,7 @@ LL | | }; | |_____^ help: try: `Some(10).map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:233:13 + --> tests/ui/option_if_let_else.rs:234:13 | LL | let _ = match res { | _____________^ @@ -261,7 +261,7 @@ LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:237:13 + --> tests/ui/option_if_let_else.rs:238:13 | LL | let _ = match res { | _____________^ @@ -271,13 +271,13 @@ LL | | }; | |_____^ help: try: `res.map_or(1, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:241:13 + --> tests/ui/option_if_let_else.rs:242:13 | LL | let _ = if let Ok(a) = res { a + 1 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or(5, |a| a + 1)` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:258:17 + --> tests/ui/option_if_let_else.rs:259:17 | LL | let _ = match initial { | _________________^ @@ -287,7 +287,7 @@ LL | | }; | |_________^ help: try: `initial.as_ref().map_or(42, |value| do_something(value))` error: use Option::map_or instead of an if let/else - --> tests/ui/option_if_let_else.rs:265:17 + --> tests/ui/option_if_let_else.rs:266:17 | LL | let _ = match initial { | _________________^ @@ -297,7 +297,7 @@ LL | | }; | |_________^ help: try: `initial.as_mut().map_or(42, |value| do_something2(value))` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:288:24 + --> tests/ui/option_if_let_else.rs:289:24 | LL | let mut _hashmap = if let Some(hm) = &opt { | ________________________^ @@ -308,7 +308,7 @@ LL | | }; | |_____^ help: try: `opt.as_ref().map_or_else(HashMap::new, |hm| hm.clone())` error: use Option::map_or_else instead of an if let/else - --> tests/ui/option_if_let_else.rs:294:19 + --> tests/ui/option_if_let_else.rs:295:19 | LL | let mut _hm = if let Some(hm) = &opt { hm.clone() } else { new_map!() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.as_ref().map_or_else(|| new_map!(), |hm| hm.clone())` diff --git a/src/tools/clippy/tests/ui/option_option.rs b/src/tools/clippy/tests/ui/option_option.rs index 2f6e4d76145..42f03aae7bb 100644 --- a/src/tools/clippy/tests/ui/option_option.rs +++ b/src/tools/clippy/tests/ui/option_option.rs @@ -1,7 +1,5 @@ -//@compile-flags: -Zdeduplicate-diagnostics=yes - #![deny(clippy::option_option)] -#![allow(clippy::unnecessary_wraps)] +#![allow(clippy::unnecessary_wraps, clippy::manual_unwrap_or_default)] const C: Option<Option<i32>> = None; //~^ ERROR: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if diff --git a/src/tools/clippy/tests/ui/option_option.stderr b/src/tools/clippy/tests/ui/option_option.stderr index 76cb9ae944c..0cd048e400e 100644 --- a/src/tools/clippy/tests/ui/option_option.stderr +++ b/src/tools/clippy/tests/ui/option_option.stderr @@ -1,77 +1,77 @@ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases - --> tests/ui/option_option.rs:6:10 + --> tests/ui/option_option.rs:4:10 | LL | const C: Option<Option<i32>> = None; | ^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> tests/ui/option_option.rs:3:9 + --> tests/ui/option_option.rs:1:9 | LL | #![deny(clippy::option_option)] | ^^^^^^^^^^^^^^^^^^^^^ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases - --> tests/ui/option_option.rs:8:11 + --> tests/ui/option_option.rs:6:11 | LL | static S: Option<Option<i32>> = None; | ^^^^^^^^^^^^^^^^^^^ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases - --> tests/ui/option_option.rs:11:13 + --> tests/ui/option_option.rs:9:13 | LL | fn input(_: Option<Option<u8>>) {} | ^^^^^^^^^^^^^^^^^^ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases - --> tests/ui/option_option.rs:14:16 + --> tests/ui/option_option.rs:12:16 | LL | fn output() -> Option<Option<u8>> { | ^^^^^^^^^^^^^^^^^^ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases - --> tests/ui/option_option.rs:19:27 + --> tests/ui/option_option.rs:17:27 | LL | fn output_nested() -> Vec<Option<Option<u8>>> { | ^^^^^^^^^^^^^^^^^^ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases - --> tests/ui/option_option.rs:25:30 + --> tests/ui/option_option.rs:23:30 | LL | fn output_nested_nested() -> Option<Option<Option<u8>>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases - --> tests/ui/option_option.rs:31:8 + --> tests/ui/option_option.rs:29:8 | LL | x: Option<Option<u8>>, | ^^^^^^^^^^^^^^^^^^ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases - --> tests/ui/option_option.rs:36:23 + --> tests/ui/option_option.rs:34:23 | LL | fn struct_fn() -> Option<Option<u8>> { | ^^^^^^^^^^^^^^^^^^ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases - --> tests/ui/option_option.rs:43:22 + --> tests/ui/option_option.rs:41:22 | LL | fn trait_fn() -> Option<Option<u8>>; | ^^^^^^^^^^^^^^^^^^ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases - --> tests/ui/option_option.rs:48:11 + --> tests/ui/option_option.rs:46:11 | LL | Tuple(Option<Option<u8>>), | ^^^^^^^^^^^^^^^^^^ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases - --> tests/ui/option_option.rs:50:17 + --> tests/ui/option_option.rs:48:17 | LL | Struct { x: Option<Option<u8>> }, | ^^^^^^^^^^^^^^^^^^ error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases - --> tests/ui/option_option.rs:92:14 + --> tests/ui/option_option.rs:90:14 | LL | foo: Option<Option<Cow<'a, str>>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/read_zero_byte_vec.rs b/src/tools/clippy/tests/ui/read_zero_byte_vec.rs index fd5a88a37a6..68acf433469 100644 --- a/src/tools/clippy/tests/ui/read_zero_byte_vec.rs +++ b/src/tools/clippy/tests/ui/read_zero_byte_vec.rs @@ -112,4 +112,10 @@ async fn test_tokio<R: TokioAsyncRead + Unpin>(r: &mut R) { //~^ ERROR: reading zero byte data to `Vec` } +fn allow_works<F: std::io::Read>(mut f: F) { + let mut data = Vec::with_capacity(100); + #[allow(clippy::read_zero_byte_vec)] + f.read(&mut data).unwrap(); +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/redundant_as_str.fixed b/src/tools/clippy/tests/ui/redundant_as_str.fixed index 4185b402226..708a1cc9150 100644 --- a/src/tools/clippy/tests/ui/redundant_as_str.fixed +++ b/src/tools/clippy/tests/ui/redundant_as_str.fixed @@ -1,4 +1,5 @@ #![warn(clippy::redundant_as_str)] +#![allow(clippy::const_is_empty)] fn main() { let string = "Hello, world!".to_owned(); diff --git a/src/tools/clippy/tests/ui/redundant_as_str.rs b/src/tools/clippy/tests/ui/redundant_as_str.rs index 7a74d8a55de..257af591cef 100644 --- a/src/tools/clippy/tests/ui/redundant_as_str.rs +++ b/src/tools/clippy/tests/ui/redundant_as_str.rs @@ -1,4 +1,5 @@ #![warn(clippy::redundant_as_str)] +#![allow(clippy::const_is_empty)] fn main() { let string = "Hello, world!".to_owned(); diff --git a/src/tools/clippy/tests/ui/redundant_as_str.stderr b/src/tools/clippy/tests/ui/redundant_as_str.stderr index f086de5fede..f5379d701db 100644 --- a/src/tools/clippy/tests/ui/redundant_as_str.stderr +++ b/src/tools/clippy/tests/ui/redundant_as_str.stderr @@ -1,5 +1,5 @@ error: this `as_str` is redundant and can be removed as the method immediately following exists on `String` too - --> tests/ui/redundant_as_str.rs:7:29 + --> tests/ui/redundant_as_str.rs:8:29 | LL | let _redundant = string.as_str().as_bytes(); | ^^^^^^^^^^^^^^^^^ help: try: `as_bytes` @@ -8,7 +8,7 @@ LL | let _redundant = string.as_str().as_bytes(); = help: to override `-D warnings` add `#[allow(clippy::redundant_as_str)]` error: this `as_str` is redundant and can be removed as the method immediately following exists on `String` too - --> tests/ui/redundant_as_str.rs:8:29 + --> tests/ui/redundant_as_str.rs:9:29 | LL | let _redundant = string.as_str().is_empty(); | ^^^^^^^^^^^^^^^^^ help: try: `is_empty` diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed index f4ff0f0b88b..24d0f797542 100644 --- a/src/tools/clippy/tests/ui/rename.fixed +++ b/src/tools/clippy/tests/ui/rename.fixed @@ -2,6 +2,7 @@ // Use that command to update this file and do not edit by hand. // Manual edits will be overwritten. +#![allow(clippy::duplicated_attributes)] #![allow(clippy::almost_complete_range)] #![allow(clippy::disallowed_names)] #![allow(clippy::blocks_in_conditions)] diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs index 0df1098f5fb..be8da2fa1a3 100644 --- a/src/tools/clippy/tests/ui/rename.rs +++ b/src/tools/clippy/tests/ui/rename.rs @@ -2,6 +2,7 @@ // Use that command to update this file and do not edit by hand. // Manual edits will be overwritten. +#![allow(clippy::duplicated_attributes)] #![allow(clippy::almost_complete_range)] #![allow(clippy::disallowed_names)] #![allow(clippy::blocks_in_conditions)] diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr index e6659b109e5..777ac20153d 100644 --- a/src/tools/clippy/tests/ui/rename.stderr +++ b/src/tools/clippy/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> tests/ui/rename.rs:55:9 + --> tests/ui/rename.rs:56:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -8,343 +8,343 @@ LL | #![warn(clippy::almost_complete_letter_range)] = help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> tests/ui/rename.rs:56:9 + --> tests/ui/rename.rs:57:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_conditions` - --> tests/ui/rename.rs:57:9 + --> tests/ui/rename.rs:58:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_conditions` - --> tests/ui/rename.rs:58:9 + --> tests/ui/rename.rs:59:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_conditions` error: lint `clippy::blocks_in_if_conditions` has been renamed to `clippy::blocks_in_conditions` - --> tests/ui/rename.rs:59:9 + --> tests/ui/rename.rs:60:9 | LL | #![warn(clippy::blocks_in_if_conditions)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> tests/ui/rename.rs:60:9 + --> tests/ui/rename.rs:61:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> tests/ui/rename.rs:61:9 + --> tests/ui/rename.rs:62:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> tests/ui/rename.rs:62:9 + --> tests/ui/rename.rs:63:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> tests/ui/rename.rs:63:9 + --> tests/ui/rename.rs:64:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> tests/ui/rename.rs:64:9 + --> tests/ui/rename.rs:65:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> tests/ui/rename.rs:65:9 + --> tests/ui/rename.rs:66:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> tests/ui/rename.rs:66:9 + --> tests/ui/rename.rs:67:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> tests/ui/rename.rs:67:9 + --> tests/ui/rename.rs:68:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> tests/ui/rename.rs:68:9 + --> tests/ui/rename.rs:69:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::incorrect_clone_impl_on_copy_type` has been renamed to `clippy::non_canonical_clone_impl` - --> tests/ui/rename.rs:69:9 + --> tests/ui/rename.rs:70:9 | LL | #![warn(clippy::incorrect_clone_impl_on_copy_type)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::non_canonical_clone_impl` error: lint `clippy::incorrect_partial_ord_impl_on_ord_type` has been renamed to `clippy::non_canonical_partial_ord_impl` - --> tests/ui/rename.rs:70:9 + --> tests/ui/rename.rs:71:9 | LL | #![warn(clippy::incorrect_partial_ord_impl_on_ord_type)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::non_canonical_partial_ord_impl` error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects` - --> tests/ui/rename.rs:71:9 + --> tests/ui/rename.rs:72:9 | LL | #![warn(clippy::integer_arithmetic)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::arithmetic_side_effects` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> tests/ui/rename.rs:72:9 + --> tests/ui/rename.rs:73:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> tests/ui/rename.rs:73:9 + --> tests/ui/rename.rs:74:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> tests/ui/rename.rs:74:9 + --> tests/ui/rename.rs:75:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> tests/ui/rename.rs:75:9 + --> tests/ui/rename.rs:76:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> tests/ui/rename.rs:76:9 + --> tests/ui/rename.rs:77:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> tests/ui/rename.rs:77:9 + --> tests/ui/rename.rs:78:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> tests/ui/rename.rs:78:9 + --> tests/ui/rename.rs:79:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> tests/ui/rename.rs:79:9 + --> tests/ui/rename.rs:80:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> tests/ui/rename.rs:80:9 + --> tests/ui/rename.rs:81:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> tests/ui/rename.rs:81:9 + --> tests/ui/rename.rs:82:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> tests/ui/rename.rs:82:9 + --> tests/ui/rename.rs:83:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> tests/ui/rename.rs:83:9 + --> tests/ui/rename.rs:84:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> tests/ui/rename.rs:84:9 + --> tests/ui/rename.rs:85:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> tests/ui/rename.rs:85:9 + --> tests/ui/rename.rs:86:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::unwrap_or_else_default` has been renamed to `clippy::unwrap_or_default` - --> tests/ui/rename.rs:86:9 + --> tests/ui/rename.rs:87:9 | LL | #![warn(clippy::unwrap_or_else_default)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_or_default` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> tests/ui/rename.rs:87:9 + --> tests/ui/rename.rs:88:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::cast_ref_to_mut` has been renamed to `invalid_reference_casting` - --> tests/ui/rename.rs:88:9 + --> tests/ui/rename.rs:89:9 | LL | #![warn(clippy::cast_ref_to_mut)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_reference_casting` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> tests/ui/rename.rs:89:9 + --> tests/ui/rename.rs:90:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::cmp_nan` has been renamed to `invalid_nan_comparisons` - --> tests/ui/rename.rs:90:9 + --> tests/ui/rename.rs:91:9 | LL | #![warn(clippy::cmp_nan)] | ^^^^^^^^^^^^^^^ help: use the new name: `invalid_nan_comparisons` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> tests/ui/rename.rs:91:9 + --> tests/ui/rename.rs:92:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types` - --> tests/ui/rename.rs:92:9 + --> tests/ui/rename.rs:93:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types` error: lint `clippy::drop_ref` has been renamed to `dropping_references` - --> tests/ui/rename.rs:93:9 + --> tests/ui/rename.rs:94:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references` error: lint `clippy::fn_null_check` has been renamed to `useless_ptr_null_checks` - --> tests/ui/rename.rs:94:9 + --> tests/ui/rename.rs:95:9 | LL | #![warn(clippy::fn_null_check)] | ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `useless_ptr_null_checks` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> tests/ui/rename.rs:95:9 + --> tests/ui/rename.rs:96:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> tests/ui/rename.rs:96:9 + --> tests/ui/rename.rs:97:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> tests/ui/rename.rs:97:9 + --> tests/ui/rename.rs:98:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types` - --> tests/ui/rename.rs:98:9 + --> tests/ui/rename.rs:99:9 | LL | #![warn(clippy::forget_copy)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types` error: lint `clippy::forget_ref` has been renamed to `forgetting_references` - --> tests/ui/rename.rs:99:9 + --> tests/ui/rename.rs:100:9 | LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> tests/ui/rename.rs:100:9 + --> tests/ui/rename.rs:101:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> tests/ui/rename.rs:101:9 + --> tests/ui/rename.rs:102:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> tests/ui/rename.rs:102:9 + --> tests/ui/rename.rs:103:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::invalid_utf8_in_unchecked` has been renamed to `invalid_from_utf8_unchecked` - --> tests/ui/rename.rs:103:9 + --> tests/ui/rename.rs:104:9 | LL | #![warn(clippy::invalid_utf8_in_unchecked)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_from_utf8_unchecked` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> tests/ui/rename.rs:104:9 + --> tests/ui/rename.rs:105:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> tests/ui/rename.rs:105:9 + --> tests/ui/rename.rs:106:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> tests/ui/rename.rs:106:9 + --> tests/ui/rename.rs:107:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> tests/ui/rename.rs:107:9 + --> tests/ui/rename.rs:108:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> tests/ui/rename.rs:108:9 + --> tests/ui/rename.rs:109:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::undropped_manually_drops` has been renamed to `undropped_manually_drops` - --> tests/ui/rename.rs:109:9 + --> tests/ui/rename.rs:110:9 | LL | #![warn(clippy::undropped_manually_drops)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `undropped_manually_drops` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> tests/ui/rename.rs:110:9 + --> tests/ui/rename.rs:111:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> tests/ui/rename.rs:111:9 + --> tests/ui/rename.rs:112:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` error: lint `clippy::vtable_address_comparisons` has been renamed to `ambiguous_wide_pointer_comparisons` - --> tests/ui/rename.rs:112:9 + --> tests/ui/rename.rs:113:9 | LL | #![warn(clippy::vtable_address_comparisons)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `ambiguous_wide_pointer_comparisons` diff --git a/src/tools/clippy/tests/ui/single_match.fixed b/src/tools/clippy/tests/ui/single_match.fixed index 6df64eb4053..acd70416d8b 100644 --- a/src/tools/clippy/tests/ui/single_match.fixed +++ b/src/tools/clippy/tests/ui/single_match.fixed @@ -1,12 +1,11 @@ -//@compile-flags: -Zdeduplicate-diagnostics=yes - #![warn(clippy::single_match)] #![allow( unused, clippy::uninlined_format_args, clippy::needless_if, clippy::redundant_guards, - clippy::redundant_pattern_matching + clippy::redundant_pattern_matching, + clippy::manual_unwrap_or_default )] fn dummy() {} diff --git a/src/tools/clippy/tests/ui/single_match.rs b/src/tools/clippy/tests/ui/single_match.rs index 4f005f4e04f..bde78199810 100644 --- a/src/tools/clippy/tests/ui/single_match.rs +++ b/src/tools/clippy/tests/ui/single_match.rs @@ -1,12 +1,11 @@ -//@compile-flags: -Zdeduplicate-diagnostics=yes - #![warn(clippy::single_match)] #![allow( unused, clippy::uninlined_format_args, clippy::needless_if, clippy::redundant_guards, - clippy::redundant_pattern_matching + clippy::redundant_pattern_matching, + clippy::manual_unwrap_or_default )] fn dummy() {} diff --git a/src/tools/clippy/tests/ui/single_match.stderr b/src/tools/clippy/tests/ui/single_match.stderr index 651d0b4911d..a249c120ee4 100644 --- a/src/tools/clippy/tests/ui/single_match.stderr +++ b/src/tools/clippy/tests/ui/single_match.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:16:5 + --> tests/ui/single_match.rs:15:5 | LL | / match x { LL | | Some(y) => { @@ -19,7 +19,7 @@ LL ~ }; | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:24:5 + --> tests/ui/single_match.rs:23:5 | LL | / match x { LL | | // Note the missing block braces. @@ -31,7 +31,7 @@ LL | | } | |_____^ help: try: `if let Some(y) = x { println!("{:?}", y) }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:33:5 + --> tests/ui/single_match.rs:32:5 | LL | / match z { LL | | (2..=3, 7..=9) => dummy(), @@ -40,7 +40,7 @@ LL | | }; | |_____^ help: try: `if let (2..=3, 7..=9) = z { dummy() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:62:5 + --> tests/ui/single_match.rs:61:5 | LL | / match x { LL | | Some(y) => dummy(), @@ -49,7 +49,7 @@ LL | | }; | |_____^ help: try: `if let Some(y) = x { dummy() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:67:5 + --> tests/ui/single_match.rs:66:5 | LL | / match y { LL | | Ok(y) => dummy(), @@ -58,7 +58,7 @@ LL | | }; | |_____^ help: try: `if let Ok(y) = y { dummy() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:74:5 + --> tests/ui/single_match.rs:73:5 | LL | / match c { LL | | Cow::Borrowed(..) => dummy(), @@ -67,7 +67,7 @@ LL | | }; | |_____^ help: try: `if let Cow::Borrowed(..) = c { dummy() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:95:5 + --> tests/ui/single_match.rs:94:5 | LL | / match x { LL | | "test" => println!(), @@ -76,7 +76,7 @@ LL | | } | |_____^ help: try: `if x == "test" { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:108:5 + --> tests/ui/single_match.rs:107:5 | LL | / match x { LL | | Foo::A => println!(), @@ -85,7 +85,7 @@ LL | | } | |_____^ help: try: `if x == Foo::A { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:114:5 + --> tests/ui/single_match.rs:113:5 | LL | / match x { LL | | FOO_C => println!(), @@ -94,7 +94,7 @@ LL | | } | |_____^ help: try: `if x == FOO_C { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:119:5 + --> tests/ui/single_match.rs:118:5 | LL | / match &&x { LL | | Foo::A => println!(), @@ -103,7 +103,7 @@ LL | | } | |_____^ help: try: `if x == Foo::A { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:125:5 + --> tests/ui/single_match.rs:124:5 | LL | / match &x { LL | | Foo::A => println!(), @@ -112,7 +112,7 @@ LL | | } | |_____^ help: try: `if x == &Foo::A { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:142:5 + --> tests/ui/single_match.rs:141:5 | LL | / match x { LL | | Bar::A => println!(), @@ -121,7 +121,7 @@ LL | | } | |_____^ help: try: `if let Bar::A = x { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:150:5 + --> tests/ui/single_match.rs:149:5 | LL | / match x { LL | | None => println!(), @@ -130,7 +130,7 @@ LL | | }; | |_____^ help: try: `if let None = x { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:172:5 + --> tests/ui/single_match.rs:171:5 | LL | / match x { LL | | (Some(_), _) => {}, @@ -139,7 +139,7 @@ LL | | } | |_____^ help: try: `if let (Some(_), _) = x {}` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:178:5 + --> tests/ui/single_match.rs:177:5 | LL | / match x { LL | | (Some(E::V), _) => todo!(), @@ -148,7 +148,7 @@ LL | | } | |_____^ help: try: `if let (Some(E::V), _) = x { todo!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:184:5 + --> tests/ui/single_match.rs:183:5 | LL | / match (Some(42), Some(E::V), Some(42)) { LL | | (.., Some(E::V), _) => {}, @@ -157,7 +157,7 @@ LL | | } | |_____^ help: try: `if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {}` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:256:5 + --> tests/ui/single_match.rs:255:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -177,7 +177,7 @@ LL + } } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:264:5 + --> tests/ui/single_match.rs:263:5 | LL | / match bar { LL | | #[rustfmt::skip] diff --git a/src/tools/clippy/tests/ui/single_match_else.fixed b/src/tools/clippy/tests/ui/single_match_else.fixed index 2970f5485fa..e840adf0fa3 100644 --- a/src/tools/clippy/tests/ui/single_match_else.fixed +++ b/src/tools/clippy/tests/ui/single_match_else.fixed @@ -1,5 +1,4 @@ //@aux-build: proc_macros.rs -//@compile-flags: -Zdeduplicate-diagnostics=yes #![warn(clippy::single_match_else)] #![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/single_match_else.rs b/src/tools/clippy/tests/ui/single_match_else.rs index 26974b2a48a..430c4da20f1 100644 --- a/src/tools/clippy/tests/ui/single_match_else.rs +++ b/src/tools/clippy/tests/ui/single_match_else.rs @@ -1,5 +1,4 @@ //@aux-build: proc_macros.rs -//@compile-flags: -Zdeduplicate-diagnostics=yes #![warn(clippy::single_match_else)] #![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/single_match_else.stderr b/src/tools/clippy/tests/ui/single_match_else.stderr index 48c74c0caea..f8f88379d6d 100644 --- a/src/tools/clippy/tests/ui/single_match_else.stderr +++ b/src/tools/clippy/tests/ui/single_match_else.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:18:13 + --> tests/ui/single_match_else.rs:17:13 | LL | let _ = match ExprNode::Butterflies { | _____________^ @@ -22,7 +22,7 @@ LL ~ }; | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:83:5 + --> tests/ui/single_match_else.rs:82:5 | LL | / match Some(1) { LL | | Some(a) => println!("${:?}", a), @@ -42,7 +42,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:92:5 + --> tests/ui/single_match_else.rs:91:5 | LL | / match Some(1) { LL | | Some(a) => println!("${:?}", a), @@ -62,7 +62,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:102:5 + --> tests/ui/single_match_else.rs:101:5 | LL | / match Result::<i32, Infallible>::Ok(1) { LL | | Ok(a) => println!("${:?}", a), @@ -82,7 +82,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:111:5 + --> tests/ui/single_match_else.rs:110:5 | LL | / match Cow::from("moo") { LL | | Cow::Owned(a) => println!("${:?}", a), @@ -102,7 +102,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:121:5 + --> tests/ui/single_match_else.rs:120:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -125,7 +125,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:132:5 + --> tests/ui/single_match_else.rs:131:5 | LL | / match bar { LL | | Some(v) => { @@ -149,7 +149,7 @@ LL + } } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:144:5 + --> tests/ui/single_match_else.rs:143:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -173,7 +173,7 @@ LL + } } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match_else.rs:156:5 + --> tests/ui/single_match_else.rs:155:5 | LL | / match bar { LL | | #[rustfmt::skip] diff --git a/src/tools/clippy/tests/ui/std_instead_of_core.fixed b/src/tools/clippy/tests/ui/std_instead_of_core.fixed index 0a734a65d29..ec4ae2ea13c 100644 --- a/src/tools/clippy/tests/ui/std_instead_of_core.fixed +++ b/src/tools/clippy/tests/ui/std_instead_of_core.fixed @@ -17,7 +17,7 @@ fn std_instead_of_core() { use ::core::hash::Hash; //~^ ERROR: used import from `std` instead of `core` // Don't lint on `env` macro - use core::env; + use std::env; // Multiple imports use core::fmt::{Debug, Result}; diff --git a/src/tools/clippy/tests/ui/std_instead_of_core.stderr b/src/tools/clippy/tests/ui/std_instead_of_core.stderr index ee42b474a32..8f920511cc5 100644 --- a/src/tools/clippy/tests/ui/std_instead_of_core.stderr +++ b/src/tools/clippy/tests/ui/std_instead_of_core.stderr @@ -14,12 +14,6 @@ LL | use ::std::hash::Hash; | ^^^ help: consider importing the item from `core`: `core` error: used import from `std` instead of `core` - --> tests/ui/std_instead_of_core.rs:20:9 - | -LL | use std::env; - | ^^^ help: consider importing the item from `core`: `core` - -error: used import from `std` instead of `core` --> tests/ui/std_instead_of_core.rs:23:9 | LL | use std::fmt::{Debug, Result}; @@ -85,5 +79,5 @@ LL | use alloc::slice::from_ref; = note: `-D clippy::alloc-instead-of-core` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::alloc_instead_of_core)]` -error: aborting due to 13 previous errors +error: aborting due to 12 previous errors diff --git a/src/tools/clippy/tests/ui/unconditional_recursion.rs b/src/tools/clippy/tests/ui/unconditional_recursion.rs index 35275e81ded..70b390b00e2 100644 --- a/src/tools/clippy/tests/ui/unconditional_recursion.rs +++ b/src/tools/clippy/tests/ui/unconditional_recursion.rs @@ -1,7 +1,11 @@ //@no-rustfix #![warn(clippy::unconditional_recursion)] -#![allow(clippy::partialeq_ne_impl, clippy::default_constructed_unit_structs)] +#![allow( + clippy::partialeq_ne_impl, + clippy::default_constructed_unit_structs, + clippy::only_used_in_recursion +)] enum Foo { A, @@ -350,4 +354,48 @@ mod issue12154 { } } +// From::from -> Into::into -> From::from +struct BadFromTy1<'a>(&'a ()); +struct BadIntoTy1<'b>(&'b ()); +impl<'a> From<BadFromTy1<'a>> for BadIntoTy1<'static> { + fn from(f: BadFromTy1<'a>) -> Self { + f.into() + } +} + +// Using UFCS syntax +struct BadFromTy2<'a>(&'a ()); +struct BadIntoTy2<'b>(&'b ()); +impl<'a> From<BadFromTy2<'a>> for BadIntoTy2<'static> { + fn from(f: BadFromTy2<'a>) -> Self { + Into::into(f) + } +} + +// Different Into impl (<i16 as Into<i32>>), so no infinite recursion +struct BadFromTy3; +impl From<BadFromTy3> for i32 { + fn from(f: BadFromTy3) -> Self { + Into::into(1i16) + } +} + +// A conditional return that ends the recursion +struct BadFromTy4; +impl From<BadFromTy4> for i32 { + fn from(f: BadFromTy4) -> Self { + if true { + return 42; + } + f.into() + } +} + +// Types differ in refs, don't lint +impl From<&BadFromTy4> for i32 { + fn from(f: &BadFromTy4) -> Self { + BadFromTy4.into() + } +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/unconditional_recursion.stderr b/src/tools/clippy/tests/ui/unconditional_recursion.stderr index 3fd6c91000e..03c27bd8ed8 100644 --- a/src/tools/clippy/tests/ui/unconditional_recursion.stderr +++ b/src/tools/clippy/tests/ui/unconditional_recursion.stderr @@ -1,5 +1,5 @@ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:42:5 + --> tests/ui/unconditional_recursion.rs:46:5 | LL | fn ne(&self, other: &Self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -12,7 +12,7 @@ LL | self.ne(other) = help: to override `-D warnings` add `#[allow(unconditional_recursion)]` error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:46:5 + --> tests/ui/unconditional_recursion.rs:50:5 | LL | fn eq(&self, other: &Self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -23,7 +23,7 @@ LL | self.eq(other) = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:211:5 + --> tests/ui/unconditional_recursion.rs:215:5 | LL | fn to_string(&self) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -34,7 +34,7 @@ LL | self.to_string() = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:221:5 + --> tests/ui/unconditional_recursion.rs:225:5 | LL | fn to_string(&self) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -45,7 +45,7 @@ LL | x.to_string() = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:232:5 + --> tests/ui/unconditional_recursion.rs:236:5 | LL | fn to_string(&self) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -56,7 +56,7 @@ LL | (self as &Self).to_string() = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:12:5 + --> tests/ui/unconditional_recursion.rs:16:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | @@ -65,7 +65,7 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:14:9 + --> tests/ui/unconditional_recursion.rs:18:9 | LL | self != other | ^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | self != other = help: to override `-D warnings` add `#[allow(clippy::unconditional_recursion)]` error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:16:5 + --> tests/ui/unconditional_recursion.rs:20:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -82,13 +82,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:18:9 + --> tests/ui/unconditional_recursion.rs:22:9 | LL | self == other | ^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:28:5 + --> tests/ui/unconditional_recursion.rs:32:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | self != &Foo2::B // no error here @@ -96,13 +96,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:29:9 + --> tests/ui/unconditional_recursion.rs:33:9 | LL | self != &Foo2::B // no error here | ^^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:31:5 + --> tests/ui/unconditional_recursion.rs:35:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | self == &Foo2::B // no error here @@ -110,13 +110,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:32:9 + --> tests/ui/unconditional_recursion.rs:36:9 | LL | self == &Foo2::B // no error here | ^^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:42:5 + --> tests/ui/unconditional_recursion.rs:46:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | @@ -125,27 +125,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:44:9 + --> tests/ui/unconditional_recursion.rs:48:9 | LL | self.ne(other) | ^^^^^^^^^^^^^^ -error: parameter is only used in recursion - --> tests/ui/unconditional_recursion.rs:42:18 - | -LL | fn ne(&self, other: &Self) -> bool { - | ^^^^^ help: if this is intentional, prefix it with an underscore: `_other` - | -note: parameter used here - --> tests/ui/unconditional_recursion.rs:44:17 - | -LL | self.ne(other) - | ^^^^^ - = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::only_used_in_recursion)]` - error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:46:5 + --> tests/ui/unconditional_recursion.rs:50:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -154,25 +140,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:48:9 + --> tests/ui/unconditional_recursion.rs:52:9 | LL | self.eq(other) | ^^^^^^^^^^^^^^ -error: parameter is only used in recursion - --> tests/ui/unconditional_recursion.rs:46:18 - | -LL | fn eq(&self, other: &Self) -> bool { - | ^^^^^ help: if this is intentional, prefix it with an underscore: `_other` - | -note: parameter used here - --> tests/ui/unconditional_recursion.rs:48:17 - | -LL | self.eq(other) - | ^^^^^ - error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:90:5 + --> tests/ui/unconditional_recursion.rs:94:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | @@ -181,13 +155,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:92:9 + --> tests/ui/unconditional_recursion.rs:96:9 | LL | other != self | ^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:94:5 + --> tests/ui/unconditional_recursion.rs:98:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -196,13 +170,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:96:9 + --> tests/ui/unconditional_recursion.rs:100:9 | LL | other == self | ^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:104:5 + --> tests/ui/unconditional_recursion.rs:108:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | @@ -211,13 +185,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:106:9 + --> tests/ui/unconditional_recursion.rs:110:9 | LL | other != other | ^^^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/unconditional_recursion.rs:106:9 + --> tests/ui/unconditional_recursion.rs:110:9 | LL | other != other | ^^^^^^^^^^^^^^ @@ -225,7 +199,7 @@ LL | other != other = note: `#[deny(clippy::eq_op)]` on by default error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:108:5 + --> tests/ui/unconditional_recursion.rs:112:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -234,19 +208,19 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:110:9 + --> tests/ui/unconditional_recursion.rs:114:9 | LL | other == other | ^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/unconditional_recursion.rs:110:9 + --> tests/ui/unconditional_recursion.rs:114:9 | LL | other == other | ^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:117:5 + --> tests/ui/unconditional_recursion.rs:121:5 | LL | / fn ne(&self, _other: &Self) -> bool { LL | | @@ -255,19 +229,19 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:119:9 + --> tests/ui/unconditional_recursion.rs:123:9 | LL | self != self | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/unconditional_recursion.rs:119:9 + --> tests/ui/unconditional_recursion.rs:123:9 | LL | self != self | ^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:121:5 + --> tests/ui/unconditional_recursion.rs:125:5 | LL | / fn eq(&self, _other: &Self) -> bool { LL | | @@ -276,19 +250,19 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:123:9 + --> tests/ui/unconditional_recursion.rs:127:9 | LL | self == self | ^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/unconditional_recursion.rs:123:9 + --> tests/ui/unconditional_recursion.rs:127:9 | LL | self == self | ^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:149:13 + --> tests/ui/unconditional_recursion.rs:153:13 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -300,7 +274,7 @@ LL | impl_partial_eq!(S5); | -------------------- in this macro invocation | note: recursive call site - --> tests/ui/unconditional_recursion.rs:151:17 + --> tests/ui/unconditional_recursion.rs:155:17 | LL | self == other | ^^^^^^^^^^^^^ @@ -310,7 +284,7 @@ LL | impl_partial_eq!(S5); = note: this error originates in the macro `impl_partial_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:178:5 + --> tests/ui/unconditional_recursion.rs:182:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -321,13 +295,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:182:9 + --> tests/ui/unconditional_recursion.rs:186:9 | LL | mine == theirs | ^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:247:5 + --> tests/ui/unconditional_recursion.rs:251:5 | LL | / fn new() -> Self { LL | | @@ -336,13 +310,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:249:9 + --> tests/ui/unconditional_recursion.rs:253:9 | LL | Self::default() | ^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:286:5 + --> tests/ui/unconditional_recursion.rs:290:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -353,10 +327,38 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:290:9 + --> tests/ui/unconditional_recursion.rs:294:9 | LL | mine.eq(theirs) | ^^^^^^^^^^^^^^^ +error: function cannot return without recursing + --> tests/ui/unconditional_recursion.rs:361:5 + | +LL | / fn from(f: BadFromTy1<'a>) -> Self { +LL | | f.into() +LL | | } + | |_____^ + | +note: recursive call site + --> tests/ui/unconditional_recursion.rs:362:9 + | +LL | f.into() + | ^^^^^^^^ + +error: function cannot return without recursing + --> tests/ui/unconditional_recursion.rs:370:5 + | +LL | / fn from(f: BadFromTy2<'a>) -> Self { +LL | | Into::into(f) +LL | | } + | |_____^ + | +note: recursive call site + --> tests/ui/unconditional_recursion.rs:371:9 + | +LL | Into::into(f) + | ^^^^^^^^^^^^^ + error: aborting due to 27 previous errors diff --git a/src/tools/clippy/tests/ui/unused_enumerate_index.fixed b/src/tools/clippy/tests/ui/unused_enumerate_index.fixed index d079807ab58..cffd02b0acc 100644 --- a/src/tools/clippy/tests/ui/unused_enumerate_index.fixed +++ b/src/tools/clippy/tests/ui/unused_enumerate_index.fixed @@ -1,8 +1,12 @@ -#![allow(unused)] +#![allow(unused, clippy::map_identity)] #![warn(clippy::unused_enumerate_index)] use std::iter::Enumerate; +fn get_enumerate() -> Enumerate<std::vec::IntoIter<i32>> { + vec![1].into_iter().enumerate() +} + fn main() { let v = [1, 2, 3]; for x in v.iter() { @@ -55,4 +59,48 @@ fn main() { for x in dummy { println!("{x}"); } + + let _ = vec![1, 2, 3].into_iter().map(|x| println!("{x}")); + + let p = vec![1, 2, 3].into_iter(); + p.map(|x| println!("{x}")); + + // This shouldn't trigger the lint. `get_enumerate` may come from an external library on which we + // have no control. + let p = get_enumerate(); + p.map(|(_, x)| println!("{x}")); + + // This shouldn't trigger the lint. The `enumerate` call is in a different context. + macro_rules! mac { + () => { + [1].iter().enumerate() + }; + } + _ = mac!().map(|(_, v)| v); + + macro_rules! mac2 { + () => { + [1].iter() + }; + } + _ = mac2!().map(|_v| {}); + + // This shouldn't trigger the lint because of the `allow`. + #[allow(clippy::unused_enumerate_index)] + let v = [1].iter().enumerate(); + v.map(|(_, _x)| {}); + + // This should keep the explicit type of `x`. + let v = [1, 2, 3].iter().copied(); + let x = v.map(|x: i32| x).sum::<i32>(); + assert_eq!(x, 6); + + // This should keep the explicit type of `x`. + let v = [1, 2, 3].iter().copied(); + let x = v.map(|x: i32| x).sum::<i32>(); + assert_eq!(x, 6); + + let v = [1, 2, 3].iter().copied(); + let x = v.map(|x| x).sum::<i32>(); + assert_eq!(x, 6); } diff --git a/src/tools/clippy/tests/ui/unused_enumerate_index.rs b/src/tools/clippy/tests/ui/unused_enumerate_index.rs index 2d524da7632..f2b5f8b9124 100644 --- a/src/tools/clippy/tests/ui/unused_enumerate_index.rs +++ b/src/tools/clippy/tests/ui/unused_enumerate_index.rs @@ -1,8 +1,12 @@ -#![allow(unused)] +#![allow(unused, clippy::map_identity)] #![warn(clippy::unused_enumerate_index)] use std::iter::Enumerate; +fn get_enumerate() -> Enumerate<std::vec::IntoIter<i32>> { + vec![1].into_iter().enumerate() +} + fn main() { let v = [1, 2, 3]; for (_, x) in v.iter().enumerate() { @@ -55,4 +59,48 @@ fn main() { for (_, x) in dummy.enumerate() { println!("{x}"); } + + let _ = vec![1, 2, 3].into_iter().enumerate().map(|(_, x)| println!("{x}")); + + let p = vec![1, 2, 3].into_iter().enumerate(); + p.map(|(_, x)| println!("{x}")); + + // This shouldn't trigger the lint. `get_enumerate` may come from an external library on which we + // have no control. + let p = get_enumerate(); + p.map(|(_, x)| println!("{x}")); + + // This shouldn't trigger the lint. The `enumerate` call is in a different context. + macro_rules! mac { + () => { + [1].iter().enumerate() + }; + } + _ = mac!().map(|(_, v)| v); + + macro_rules! mac2 { + () => { + [1].iter() + }; + } + _ = mac2!().enumerate().map(|(_, _v)| {}); + + // This shouldn't trigger the lint because of the `allow`. + #[allow(clippy::unused_enumerate_index)] + let v = [1].iter().enumerate(); + v.map(|(_, _x)| {}); + + // This should keep the explicit type of `x`. + let v = [1, 2, 3].iter().copied().enumerate(); + let x = v.map(|(_, x): (usize, i32)| x).sum::<i32>(); + assert_eq!(x, 6); + + // This should keep the explicit type of `x`. + let v = [1, 2, 3].iter().copied().enumerate(); + let x = v.map(|(_, x): (_, i32)| x).sum::<i32>(); + assert_eq!(x, 6); + + let v = [1, 2, 3].iter().copied().enumerate(); + let x = v.map(|(_, x)| x).sum::<i32>(); + assert_eq!(x, 6); } diff --git a/src/tools/clippy/tests/ui/unused_enumerate_index.stderr b/src/tools/clippy/tests/ui/unused_enumerate_index.stderr index 7bd7d29117e..6ec07dcbff0 100644 --- a/src/tools/clippy/tests/ui/unused_enumerate_index.stderr +++ b/src/tools/clippy/tests/ui/unused_enumerate_index.stderr @@ -1,5 +1,5 @@ error: you seem to use `.enumerate()` and immediately discard the index - --> tests/ui/unused_enumerate_index.rs:8:19 + --> tests/ui/unused_enumerate_index.rs:12:19 | LL | for (_, x) in v.iter().enumerate() { | ^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL | for x in v.iter() { | ~ ~~~~~~~~ error: you seem to use `.enumerate()` and immediately discard the index - --> tests/ui/unused_enumerate_index.rs:55:19 + --> tests/ui/unused_enumerate_index.rs:59:19 | LL | for (_, x) in dummy.enumerate() { | ^^^^^^^^^^^^^^^^^ @@ -22,5 +22,77 @@ help: remove the `.enumerate()` call LL | for x in dummy { | ~ ~~~~~ -error: aborting due to 2 previous errors +error: you seem to use `.enumerate()` and immediately discard the index + --> tests/ui/unused_enumerate_index.rs:63:39 + | +LL | let _ = vec![1, 2, 3].into_iter().enumerate().map(|(_, x)| println!("{x}")); + | ^^^^^^^^^^^ + | +help: remove the `.enumerate()` call + | +LL - let _ = vec![1, 2, 3].into_iter().enumerate().map(|(_, x)| println!("{x}")); +LL + let _ = vec![1, 2, 3].into_iter().map(|x| println!("{x}")); + | + +error: you seem to use `.enumerate()` and immediately discard the index + --> tests/ui/unused_enumerate_index.rs:65:39 + | +LL | let p = vec![1, 2, 3].into_iter().enumerate(); + | ^^^^^^^^^^^ + | +help: remove the `.enumerate()` call + | +LL ~ let p = vec![1, 2, 3].into_iter(); +LL ~ p.map(|x| println!("{x}")); + | + +error: you seem to use `.enumerate()` and immediately discard the index + --> tests/ui/unused_enumerate_index.rs:86:17 + | +LL | _ = mac2!().enumerate().map(|(_, _v)| {}); + | ^^^^^^^^^^^ + | +help: remove the `.enumerate()` call + | +LL - _ = mac2!().enumerate().map(|(_, _v)| {}); +LL + _ = mac2!().map(|_v| {}); + | + +error: you seem to use `.enumerate()` and immediately discard the index + --> tests/ui/unused_enumerate_index.rs:94:39 + | +LL | let v = [1, 2, 3].iter().copied().enumerate(); + | ^^^^^^^^^^^ + | +help: remove the `.enumerate()` call + | +LL ~ let v = [1, 2, 3].iter().copied(); +LL ~ let x = v.map(|x: i32| x).sum::<i32>(); + | + +error: you seem to use `.enumerate()` and immediately discard the index + --> tests/ui/unused_enumerate_index.rs:99:39 + | +LL | let v = [1, 2, 3].iter().copied().enumerate(); + | ^^^^^^^^^^^ + | +help: remove the `.enumerate()` call + | +LL ~ let v = [1, 2, 3].iter().copied(); +LL ~ let x = v.map(|x: i32| x).sum::<i32>(); + | + +error: you seem to use `.enumerate()` and immediately discard the index + --> tests/ui/unused_enumerate_index.rs:103:39 + | +LL | let v = [1, 2, 3].iter().copied().enumerate(); + | ^^^^^^^^^^^ + | +help: remove the `.enumerate()` call + | +LL ~ let v = [1, 2, 3].iter().copied(); +LL ~ let x = v.map(|x| x).sum::<i32>(); + | + +error: aborting due to 8 previous errors diff --git a/src/tools/clippy/tests/ui/unused_io_amount.rs b/src/tools/clippy/tests/ui/unused_io_amount.rs index 7e5a10c911b..f5b200d5ffe 100644 --- a/src/tools/clippy/tests/ui/unused_io_amount.rs +++ b/src/tools/clippy/tests/ui/unused_io_amount.rs @@ -271,5 +271,10 @@ pub fn wildcards(rdr: &mut dyn std::io::Read) { } } } +fn allow_works<F: std::io::Read>(mut f: F) { + let mut data = Vec::with_capacity(100); + #[allow(clippy::unused_io_amount)] + f.read(&mut data).unwrap(); +} fn main() {} diff --git a/src/tools/clippy/tests/ui/unused_peekable.rs b/src/tools/clippy/tests/ui/unused_peekable.rs index 131b51e01b6..5865bba4350 100644 --- a/src/tools/clippy/tests/ui/unused_peekable.rs +++ b/src/tools/clippy/tests/ui/unused_peekable.rs @@ -174,3 +174,9 @@ fn valid() { let mut peekable = std::iter::empty::<u32>().peekable(); takes_dyn(&mut peekable); } + +fn allow_works() { + #[allow(clippy::unused_peekable)] + let iter = [1, 2, 3].iter().peekable(); + iter; +} diff --git a/src/tools/clippy/tests/ui/use_self.fixed b/src/tools/clippy/tests/ui/use_self.fixed index 787dd3ec7e6..6ea7857a238 100644 --- a/src/tools/clippy/tests/ui/use_self.fixed +++ b/src/tools/clippy/tests/ui/use_self.fixed @@ -6,7 +6,8 @@ clippy::should_implement_trait, clippy::upper_case_acronyms, clippy::from_over_into, - clippy::self_named_constructors + clippy::self_named_constructors, + clippy::needless_lifetimes )] #[macro_use] @@ -53,6 +54,7 @@ mod better { } mod lifetimes { + #[derive(Clone, Copy)] struct Foo<'a> { foo_str: &'a str, } @@ -68,11 +70,19 @@ mod lifetimes { Foo { foo_str: "foo" } } - // FIXME: the lint does not handle lifetimed struct - // `Self` should be applicable here - fn clone(&self) -> Foo<'a> { + fn clone(&self) -> Self { Foo { foo_str: self.foo_str } } + + // Cannot replace with `Self` because the lifetime is not `'a`. + fn eq<'b>(&self, other: Foo<'b>) -> bool { + let x: Foo<'_> = other; + self.foo_str == other.foo_str + } + + fn f(&self) -> Foo<'_> { + *self + } } } diff --git a/src/tools/clippy/tests/ui/use_self.rs b/src/tools/clippy/tests/ui/use_self.rs index 39e182faea6..338cc00e45a 100644 --- a/src/tools/clippy/tests/ui/use_self.rs +++ b/src/tools/clippy/tests/ui/use_self.rs @@ -6,7 +6,8 @@ clippy::should_implement_trait, clippy::upper_case_acronyms, clippy::from_over_into, - clippy::self_named_constructors + clippy::self_named_constructors, + clippy::needless_lifetimes )] #[macro_use] @@ -53,6 +54,7 @@ mod better { } mod lifetimes { + #[derive(Clone, Copy)] struct Foo<'a> { foo_str: &'a str, } @@ -68,11 +70,19 @@ mod lifetimes { Foo { foo_str: "foo" } } - // FIXME: the lint does not handle lifetimed struct - // `Self` should be applicable here fn clone(&self) -> Foo<'a> { Foo { foo_str: self.foo_str } } + + // Cannot replace with `Self` because the lifetime is not `'a`. + fn eq<'b>(&self, other: Foo<'b>) -> bool { + let x: Foo<'_> = other; + self.foo_str == other.foo_str + } + + fn f(&self) -> Foo<'_> { + *self + } } } diff --git a/src/tools/clippy/tests/ui/use_self.stderr b/src/tools/clippy/tests/ui/use_self.stderr index 8d045f05ed2..d7aa8410a47 100644 --- a/src/tools/clippy/tests/ui/use_self.stderr +++ b/src/tools/clippy/tests/ui/use_self.stderr @@ -1,5 +1,5 @@ error: unnecessary structure name repetition - --> tests/ui/use_self.rs:21:21 + --> tests/ui/use_self.rs:22:21 | LL | fn new() -> Foo { | ^^^ help: use the applicable keyword: `Self` @@ -8,250 +8,256 @@ LL | fn new() -> Foo { = help: to override `-D warnings` add `#[allow(clippy::use_self)]` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:22:13 + --> tests/ui/use_self.rs:23:13 | LL | Foo {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:24:22 + --> tests/ui/use_self.rs:25:22 | LL | fn test() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:25:13 + --> tests/ui/use_self.rs:26:13 | LL | Foo::new() | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:30:25 + --> tests/ui/use_self.rs:31:25 | LL | fn default() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:31:13 + --> tests/ui/use_self.rs:32:13 | LL | Foo::new() | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:96:24 + --> tests/ui/use_self.rs:73:28 + | +LL | fn clone(&self) -> Foo<'a> { + | ^^^^^^^ help: use the applicable keyword: `Self` + +error: unnecessary structure name repetition + --> tests/ui/use_self.rs:106:24 | LL | fn bad(foos: &[Foo]) -> impl Iterator<Item = &Foo> { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:96:55 + --> tests/ui/use_self.rs:106:55 | LL | fn bad(foos: &[Foo]) -> impl Iterator<Item = &Foo> { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:111:13 + --> tests/ui/use_self.rs:121:13 | LL | TS(0) | ^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:146:29 + --> tests/ui/use_self.rs:156:29 | LL | fn bar() -> Bar { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:147:21 + --> tests/ui/use_self.rs:157:21 | LL | Bar { foo: Foo {} } | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:158:21 + --> tests/ui/use_self.rs:168:21 | LL | fn baz() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:159:13 + --> tests/ui/use_self.rs:169:13 | LL | Foo {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:176:21 + --> tests/ui/use_self.rs:186:21 | LL | let _ = Enum::B(42); | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:177:21 + --> tests/ui/use_self.rs:187:21 | LL | let _ = Enum::C { field: true }; | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:178:21 + --> tests/ui/use_self.rs:188:21 | LL | let _ = Enum::A; | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:220:13 + --> tests/ui/use_self.rs:230:13 | LL | nested::A::fun_1(); | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:221:13 + --> tests/ui/use_self.rs:231:13 | LL | nested::A::A; | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:223:13 + --> tests/ui/use_self.rs:233:13 | LL | nested::A {}; | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:242:13 + --> tests/ui/use_self.rs:252:13 | LL | TestStruct::from_something() | ^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:256:25 + --> tests/ui/use_self.rs:266:25 | LL | async fn g() -> S { | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:257:13 + --> tests/ui/use_self.rs:267:13 | LL | S {} | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:261:16 + --> tests/ui/use_self.rs:271:16 | LL | &p[S::A..S::B] | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:261:22 + --> tests/ui/use_self.rs:271:22 | LL | &p[S::A..S::B] | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:284:29 + --> tests/ui/use_self.rs:294:29 | LL | fn foo(value: T) -> Foo<T> { | ^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:285:13 + --> tests/ui/use_self.rs:295:13 | LL | Foo::<T> { value } | ^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:457:13 + --> tests/ui/use_self.rs:467:13 | LL | A::new::<submod::B>(submod::B {}) | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:494:13 + --> tests/ui/use_self.rs:504:13 | LL | S2::new() | ^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:531:17 + --> tests/ui/use_self.rs:541:17 | LL | Foo::Bar => unimplemented!(), | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:532:17 + --> tests/ui/use_self.rs:542:17 | LL | Foo::Baz => unimplemented!(), | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:538:20 + --> tests/ui/use_self.rs:548:20 | LL | if let Foo::Bar = self { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:562:17 + --> tests/ui/use_self.rs:572:17 | LL | Something::Num(n) => *n, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:563:17 + --> tests/ui/use_self.rs:573:17 | LL | Something::TupleNums(n, _m) => *n, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:564:17 + --> tests/ui/use_self.rs:574:17 | LL | Something::StructNums { one, two: _ } => *one, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:570:17 + --> tests/ui/use_self.rs:580:17 | LL | crate::issue8845::Something::Num(n) => *n, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:571:17 + --> tests/ui/use_self.rs:581:17 | LL | crate::issue8845::Something::TupleNums(n, _m) => *n, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:572:17 + --> tests/ui/use_self.rs:582:17 | LL | crate::issue8845::Something::StructNums { one, two: _ } => *one, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:588:17 + --> tests/ui/use_self.rs:598:17 | LL | let Foo(x) = self; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:593:17 + --> tests/ui/use_self.rs:603:17 | LL | let crate::issue8845::Foo(x) = self; | ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:600:17 + --> tests/ui/use_self.rs:610:17 | LL | let Bar { x, .. } = self; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:605:17 + --> tests/ui/use_self.rs:615:17 | LL | let crate::issue8845::Bar { x, .. } = self; | ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> tests/ui/use_self.rs:644:17 + --> tests/ui/use_self.rs:654:17 | LL | E::A => {}, | ^ help: use the applicable keyword: `Self` -error: aborting due to 42 previous errors +error: aborting due to 43 previous errors diff --git a/src/tools/clippy/tests/ui/zero_repeat_side_effects.fixed b/src/tools/clippy/tests/ui/zero_repeat_side_effects.fixed new file mode 100644 index 00000000000..6f132521926 --- /dev/null +++ b/src/tools/clippy/tests/ui/zero_repeat_side_effects.fixed @@ -0,0 +1,60 @@ +#![warn(clippy::zero_repeat_side_effects)] +#![allow(clippy::unnecessary_operation)] +#![allow(clippy::useless_vec)] +#![allow(clippy::needless_late_init)] + +fn f() -> i32 { + println!("side effect"); + 10 +} + +fn main() { + const N: usize = 0; + const M: usize = 1; + + // should trigger + + // on arrays + f(); let a: [i32; 0] = []; + f(); let a: [i32; 0] = []; + let mut b; + f(); b = [] as [i32; 0]; + f(); b = [] as [i32; 0]; + + // on vecs + // vecs dont support infering value of consts + f(); let c: std::vec::Vec<i32> = vec![]; + let d; + f(); d = vec![] as std::vec::Vec<i32>; + + // for macros + println!("side effect"); let e: [(); 0] = []; + + // for nested calls + { f() }; let g: [i32; 0] = []; + + // as function param + drop({ f(); vec![] as std::vec::Vec<i32> }); + + // when singled out/not part of assignment/local + { f(); vec![] as std::vec::Vec<i32> }; + { f(); [] as [i32; 0] }; + { f(); [] as [i32; 0] }; + + // should not trigger + + // on arrays with > 0 repeat + let a = [f(); 1]; + let a = [f(); M]; + let mut b; + b = [f(); 1]; + b = [f(); M]; + + // on vecs with > 0 repeat + let c = vec![f(); 1]; + let d; + d = vec![f(); 1]; + + // as function param + drop(vec![f(); 1]); +} diff --git a/src/tools/clippy/tests/ui/zero_repeat_side_effects.rs b/src/tools/clippy/tests/ui/zero_repeat_side_effects.rs new file mode 100644 index 00000000000..9d9c367375a --- /dev/null +++ b/src/tools/clippy/tests/ui/zero_repeat_side_effects.rs @@ -0,0 +1,60 @@ +#![warn(clippy::zero_repeat_side_effects)] +#![allow(clippy::unnecessary_operation)] +#![allow(clippy::useless_vec)] +#![allow(clippy::needless_late_init)] + +fn f() -> i32 { + println!("side effect"); + 10 +} + +fn main() { + const N: usize = 0; + const M: usize = 1; + + // should trigger + + // on arrays + let a = [f(); 0]; + let a = [f(); N]; + let mut b; + b = [f(); 0]; + b = [f(); N]; + + // on vecs + // vecs dont support infering value of consts + let c = vec![f(); 0]; + let d; + d = vec![f(); 0]; + + // for macros + let e = [println!("side effect"); 0]; + + // for nested calls + let g = [{ f() }; 0]; + + // as function param + drop(vec![f(); 0]); + + // when singled out/not part of assignment/local + vec![f(); 0]; + [f(); 0]; + [f(); N]; + + // should not trigger + + // on arrays with > 0 repeat + let a = [f(); 1]; + let a = [f(); M]; + let mut b; + b = [f(); 1]; + b = [f(); M]; + + // on vecs with > 0 repeat + let c = vec![f(); 1]; + let d; + d = vec![f(); 1]; + + // as function param + drop(vec![f(); 1]); +} diff --git a/src/tools/clippy/tests/ui/zero_repeat_side_effects.stderr b/src/tools/clippy/tests/ui/zero_repeat_side_effects.stderr new file mode 100644 index 00000000000..afdc6054253 --- /dev/null +++ b/src/tools/clippy/tests/ui/zero_repeat_side_effects.stderr @@ -0,0 +1,77 @@ +error: function or method calls as the initial value in zero-sized array initializers may cause side effects + --> tests/ui/zero_repeat_side_effects.rs:18:5 + | +LL | let a = [f(); 0]; + | ^^^^^^^^^^^^^^^^^ help: consider using: `f(); let a: [i32; 0] = [];` + | + = note: `-D clippy::zero-repeat-side-effects` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::zero_repeat_side_effects)]` + +error: function or method calls as the initial value in zero-sized array initializers may cause side effects + --> tests/ui/zero_repeat_side_effects.rs:19:5 + | +LL | let a = [f(); N]; + | ^^^^^^^^^^^^^^^^^ help: consider using: `f(); let a: [i32; 0] = [];` + +error: function or method calls as the initial value in zero-sized array initializers may cause side effects + --> tests/ui/zero_repeat_side_effects.rs:21:5 + | +LL | b = [f(); 0]; + | ^^^^^^^^^^^^ help: consider using: `f(); b = [] as [i32; 0]` + +error: function or method calls as the initial value in zero-sized array initializers may cause side effects + --> tests/ui/zero_repeat_side_effects.rs:22:5 + | +LL | b = [f(); N]; + | ^^^^^^^^^^^^ help: consider using: `f(); b = [] as [i32; 0]` + +error: function or method calls as the initial value in zero-sized array initializers may cause side effects + --> tests/ui/zero_repeat_side_effects.rs:26:5 + | +LL | let c = vec![f(); 0]; + | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f(); let c: std::vec::Vec<i32> = vec![];` + +error: function or method calls as the initial value in zero-sized array initializers may cause side effects + --> tests/ui/zero_repeat_side_effects.rs:28:5 + | +LL | d = vec![f(); 0]; + | ^^^^^^^^^^^^^^^^ help: consider using: `f(); d = vec![] as std::vec::Vec<i32>` + +error: function or method calls as the initial value in zero-sized array initializers may cause side effects + --> tests/ui/zero_repeat_side_effects.rs:31:5 + | +LL | let e = [println!("side effect"); 0]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `println!("side effect"); let e: [(); 0] = [];` + +error: function or method calls as the initial value in zero-sized array initializers may cause side effects + --> tests/ui/zero_repeat_side_effects.rs:34:5 + | +LL | let g = [{ f() }; 0]; + | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `{ f() }; let g: [i32; 0] = [];` + +error: function or method calls as the initial value in zero-sized array initializers may cause side effects + --> tests/ui/zero_repeat_side_effects.rs:37:10 + | +LL | drop(vec![f(); 0]); + | ^^^^^^^^^^^^ help: consider using: `{ f(); vec![] as std::vec::Vec<i32> }` + +error: function or method calls as the initial value in zero-sized array initializers may cause side effects + --> tests/ui/zero_repeat_side_effects.rs:40:5 + | +LL | vec![f(); 0]; + | ^^^^^^^^^^^^ help: consider using: `{ f(); vec![] as std::vec::Vec<i32> }` + +error: function or method calls as the initial value in zero-sized array initializers may cause side effects + --> tests/ui/zero_repeat_side_effects.rs:41:5 + | +LL | [f(); 0]; + | ^^^^^^^^ help: consider using: `{ f(); [] as [i32; 0] }` + +error: function or method calls as the initial value in zero-sized array initializers may cause side effects + --> tests/ui/zero_repeat_side_effects.rs:42:5 + | +LL | [f(); N]; + | ^^^^^^^^ help: consider using: `{ f(); [] as [i32; 0] }` + +error: aborting due to 12 previous errors + diff --git a/src/tools/clippy/triagebot.toml b/src/tools/clippy/triagebot.toml index 1a81394af10..d455d967e30 100644 --- a/src/tools/clippy/triagebot.toml +++ b/src/tools/clippy/triagebot.toml @@ -19,7 +19,7 @@ new_pr = true [assign] contributing_url = "https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md" -users_on_vacation = ["xFrednet"] +users_on_vacation = [] [assign.owners] "/.github" = ["@flip1995"] diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index a512599f723..6ff47dbffbc 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -36,6 +36,7 @@ impl HeadersCache { #[derive(Default)] pub struct EarlyProps { pub aux: Vec<String>, + pub aux_bin: Vec<String>, pub aux_crate: Vec<(String, String)>, pub revisions: Vec<String>, } @@ -61,6 +62,12 @@ impl EarlyProps { }); config.push_name_value_directive( ln, + directives::AUX_BIN, + &mut props.aux_bin, + |r| r.trim().to_string(), + ); + config.push_name_value_directive( + ln, directives::AUX_CRATE, &mut props.aux_crate, Config::parse_aux_crate, @@ -95,6 +102,8 @@ pub struct TestProps { // directory as the test, but for backwards compatibility reasons // we also check the auxiliary directory) pub aux_builds: Vec<String>, + // Auxiliary crates that should be compiled as `#![crate_type = "bin"]`. + pub aux_bins: Vec<String>, // Similar to `aux_builds`, but a list of NAME=somelib.rs of dependencies // to build and pass with the `--extern` flag. pub aux_crates: Vec<(String, String)>, @@ -217,6 +226,7 @@ mod directives { pub const PRETTY_EXPANDED: &'static str = "pretty-expanded"; pub const PRETTY_MODE: &'static str = "pretty-mode"; pub const PRETTY_COMPARE_ONLY: &'static str = "pretty-compare-only"; + pub const AUX_BIN: &'static str = "aux-bin"; pub const AUX_BUILD: &'static str = "aux-build"; pub const AUX_CRATE: &'static str = "aux-crate"; pub const EXEC_ENV: &'static str = "exec-env"; @@ -252,6 +262,7 @@ impl TestProps { run_flags: None, pp_exact: None, aux_builds: vec![], + aux_bins: vec![], aux_crates: vec![], revisions: vec![], rustc_env: vec![("RUSTC_ICE".to_string(), "0".to_string())], @@ -417,6 +428,9 @@ impl TestProps { config.push_name_value_directive(ln, AUX_BUILD, &mut self.aux_builds, |r| { r.trim().to_string() }); + config.push_name_value_directive(ln, AUX_BIN, &mut self.aux_bins, |r| { + r.trim().to_string() + }); config.push_name_value_directive( ln, AUX_CRATE, @@ -683,6 +697,7 @@ pub fn line_directive<'line>( const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ // tidy-alphabetical-start "assembly-output", + "aux-bin", "aux-build", "aux-crate", "build-aux-docs", diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index cf300fbe74f..83f0755b5c8 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -537,15 +537,9 @@ fn wasm_special() { ("wasm32-wasi", "wasm32", true), ("wasm32-wasi", "wasm32-bare", false), ("wasm32-wasi", "wasi", true), - // NB: the wasm32-wasip1 target is new so this isn't tested for - // the bootstrap compiler. - #[cfg(not(bootstrap))] ("wasm32-wasip1", "emscripten", false), - #[cfg(not(bootstrap))] ("wasm32-wasip1", "wasm32", true), - #[cfg(not(bootstrap))] ("wasm32-wasip1", "wasm32-bare", false), - #[cfg(not(bootstrap))] ("wasm32-wasip1", "wasi", true), ("wasm64-unknown-unknown", "emscripten", false), ("wasm64-unknown-unknown", "wasm32", false), @@ -604,11 +598,8 @@ fn threads_support() { ("aarch64-apple-darwin", true), ("wasm32-unknown-unknown", false), ("wasm64-unknown-unknown", false), - #[cfg(not(bootstrap))] ("wasm32-wasip1", false), - #[cfg(not(bootstrap))] ("wasm32-wasip1-threads", true), - ("wasm32-wasi-preview1-threads", true), ]; for (target, has_threads) in threads { let config = cfg().target(target).build(); diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 7be0571b111..bd2f65925bb 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -82,21 +82,21 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R { } /// The platform-specific library name -pub fn get_lib_name(lib: &str, dylib: bool) -> String { - // In some casess (e.g. MUSL), we build a static - // library, rather than a dynamic library. - // In this case, the only path we can pass - // with '--extern-meta' is the '.lib' file - if !dylib { - return format!("lib{}.rlib", lib); - } - - if cfg!(windows) { - format!("{}.dll", lib) - } else if cfg!(target_os = "macos") { - format!("lib{}.dylib", lib) - } else { - format!("lib{}.so", lib) +fn get_lib_name(lib: &str, aux_type: AuxType) -> Option<String> { + match aux_type { + AuxType::Bin => None, + // In some cases (e.g. MUSL), we build a static + // library, rather than a dynamic library. + // In this case, the only path we can pass + // with '--extern-meta' is the '.rlib' file + AuxType::Lib => Some(format!("lib{}.rlib", lib)), + AuxType::Dylib => Some(if cfg!(windows) { + format!("{}.dll", lib) + } else if cfg!(target_os = "macos") { + format!("lib{}.dylib", lib) + } else { + format!("lib{}.so", lib) + }), } } @@ -198,6 +198,11 @@ pub fn compute_stamp_hash(config: &Config) -> String { format!("{:x}", hash.finish()) } +fn remove_and_create_dir_all(path: &Path) { + let _ = fs::remove_dir_all(path); + fs::create_dir_all(path).unwrap(); +} + #[derive(Copy, Clone)] struct TestCx<'test> { config: &'test Config, @@ -998,8 +1003,7 @@ impl<'test> TestCx<'test> { let mut rustc = Command::new(&self.config.rustc_path); let out_dir = self.output_base_name().with_extension("pretty-out"); - let _ = fs::remove_dir_all(&out_dir); - create_dir_all(&out_dir).unwrap(); + remove_and_create_dir_all(&out_dir); let target = if self.props.force_host { &*self.config.host } else { &*self.config.target }; @@ -1466,49 +1470,16 @@ impl<'test> TestCx<'test> { // Switch LLDB into "Rust mode" let rust_src_root = self.config.find_rust_src_root().expect("Could not find Rust source root"); - let rust_pp_module_rel_path = Path::new("./src/etc/lldb_lookup.py"); - let rust_pp_module_abs_path = - rust_src_root.join(rust_pp_module_rel_path).to_str().unwrap().to_owned(); - - let rust_type_regexes = vec![ - "^(alloc::([a-z_]+::)+)String$", - "^&(mut )?str$", - "^&(mut )?\\[.+\\]$", - "^(std::ffi::([a-z_]+::)+)OsString$", - "^(alloc::([a-z_]+::)+)Vec<.+>$", - "^(alloc::([a-z_]+::)+)VecDeque<.+>$", - "^(alloc::([a-z_]+::)+)BTreeSet<.+>$", - "^(alloc::([a-z_]+::)+)BTreeMap<.+>$", - "^(std::collections::([a-z_]+::)+)HashMap<.+>$", - "^(std::collections::([a-z_]+::)+)HashSet<.+>$", - "^(alloc::([a-z_]+::)+)Rc<.+>$", - "^(alloc::([a-z_]+::)+)Arc<.+>$", - "^(core::([a-z_]+::)+)Cell<.+>$", - "^(core::([a-z_]+::)+)Ref<.+>$", - "^(core::([a-z_]+::)+)RefMut<.+>$", - "^(core::([a-z_]+::)+)RefCell<.+>$", - "^core::num::([a-z_]+::)*NonZero.+$", - ]; + let rust_pp_module_rel_path = Path::new("./src/etc"); + let rust_pp_module_abs_path = rust_src_root.join(rust_pp_module_rel_path); - // In newer versions of lldb, persistent results (the `$N =` part at the start of - // expressions you have evaluated that let you re-use the result) aren't printed, but lots - // of rustc's debuginfo tests rely on these, so re-enable this. - // See <https://reviews.llvm.org/rG385496385476fc9735da5fa4acabc34654e8b30d>. - script_str.push_str("command unalias print\n"); - script_str.push_str("command alias print expr --\n"); - script_str.push_str("command unalias p\n"); - script_str.push_str("command alias p expr --\n"); - - script_str - .push_str(&format!("command script import {}\n", &rust_pp_module_abs_path[..])[..]); - script_str.push_str("type synthetic add -l lldb_lookup.synthetic_lookup -x '.*' "); - script_str.push_str("--category Rust\n"); - for type_regex in rust_type_regexes { - script_str.push_str("type summary add -F lldb_lookup.summary_lookup -e -x -h "); - script_str.push_str(&format!("'{}' ", type_regex)); - script_str.push_str("--category Rust\n"); - } - script_str.push_str("type category enable Rust\n"); + script_str.push_str(&format!( + "command script import {}/lldb_lookup.py\n", + rust_pp_module_abs_path.to_str().unwrap() + )); + File::open(rust_pp_module_abs_path.join("lldb_commands")) + .and_then(|mut file| file.read_to_string(&mut script_str)) + .expect("Failed to read lldb_commands"); // Set breakpoints on every line that contains the string "#break" let source_file_name = self.testpaths.file.file_name().unwrap().to_string_lossy(); @@ -2127,8 +2098,12 @@ impl<'test> TestCx<'test> { let aux_dir = self.aux_output_dir_name(); if !self.props.aux_builds.is_empty() { - let _ = fs::remove_dir_all(&aux_dir); - create_dir_all(&aux_dir).unwrap(); + remove_and_create_dir_all(&aux_dir); + } + + if !self.props.aux_bins.is_empty() { + let aux_bin_dir = self.aux_bin_output_dir_name(); + remove_and_create_dir_all(&aux_bin_dir); } aux_dir @@ -2136,14 +2111,25 @@ impl<'test> TestCx<'test> { fn build_all_auxiliary(&self, of: &TestPaths, aux_dir: &Path, rustc: &mut Command) { for rel_ab in &self.props.aux_builds { - self.build_auxiliary(of, rel_ab, &aux_dir); + self.build_auxiliary(of, rel_ab, &aux_dir, false /* is_bin */); + } + + for rel_ab in &self.props.aux_bins { + self.build_auxiliary(of, rel_ab, &aux_dir, true /* is_bin */); } for (aux_name, aux_path) in &self.props.aux_crates { - let is_dylib = self.build_auxiliary(of, &aux_path, &aux_dir); + let aux_type = self.build_auxiliary(of, &aux_path, &aux_dir, false /* is_bin */); let lib_name = - get_lib_name(&aux_path.trim_end_matches(".rs").replace('-', "_"), is_dylib); - rustc.arg("--extern").arg(format!("{}={}/{}", aux_name, aux_dir.display(), lib_name)); + get_lib_name(&aux_path.trim_end_matches(".rs").replace('-', "_"), aux_type); + if let Some(lib_name) = lib_name { + rustc.arg("--extern").arg(format!( + "{}={}/{}", + aux_name, + aux_dir.display(), + lib_name + )); + } } } @@ -2162,12 +2148,23 @@ impl<'test> TestCx<'test> { } /// Builds an aux dependency. - /// - /// Returns whether or not it is a dylib. - fn build_auxiliary(&self, of: &TestPaths, source_path: &str, aux_dir: &Path) -> bool { + fn build_auxiliary( + &self, + of: &TestPaths, + source_path: &str, + aux_dir: &Path, + is_bin: bool, + ) -> AuxType { let aux_testpaths = self.compute_aux_test_paths(of, source_path); let aux_props = self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config); - let aux_output = TargetLocation::ThisDirectory(aux_dir.to_path_buf()); + let mut aux_dir = aux_dir.to_path_buf(); + if is_bin { + // On unix, the binary of `auxiliary/foo.rs` will be named + // `auxiliary/foo` which clashes with the _dir_ `auxiliary/foo`, so + // put bins in a `bin` subfolder. + aux_dir.push("bin"); + } + let aux_output = TargetLocation::ThisDirectory(aux_dir.clone()); let aux_cx = TestCx { config: self.config, props: &aux_props, @@ -2185,15 +2182,17 @@ impl<'test> TestCx<'test> { LinkToAux::No, Vec::new(), ); - aux_cx.build_all_auxiliary(of, aux_dir, &mut aux_rustc); + aux_cx.build_all_auxiliary(of, &aux_dir, &mut aux_rustc); for key in &aux_props.unset_rustc_env { aux_rustc.env_remove(key); } aux_rustc.envs(aux_props.rustc_env.clone()); - let (dylib, crate_type) = if aux_props.no_prefer_dynamic { - (true, None) + let (aux_type, crate_type) = if is_bin { + (AuxType::Bin, Some("bin")) + } else if aux_props.no_prefer_dynamic { + (AuxType::Dylib, None) } else if self.config.target.contains("emscripten") || (self.config.target.contains("musl") && !aux_props.force_host @@ -2218,9 +2217,9 @@ impl<'test> TestCx<'test> { // Coverage tests want static linking by default so that coverage // mappings in auxiliary libraries can be merged into the final // executable. - (false, Some("lib")) + (AuxType::Lib, Some("lib")) } else { - (true, Some("dylib")) + (AuxType::Dylib, Some("dylib")) }; if let Some(crate_type) = crate_type { @@ -2244,7 +2243,7 @@ impl<'test> TestCx<'test> { &auxres, ); } - dylib + aux_type } fn read2_abbreviated(&self, child: Child) -> (Output, Truncated) { @@ -2472,8 +2471,7 @@ impl<'test> TestCx<'test> { } let mir_dump_dir = self.get_mir_dump_dir(); - let _ = fs::remove_dir_all(&mir_dump_dir); - create_dir_all(mir_dump_dir.as_path()).unwrap(); + remove_and_create_dir_all(&mir_dump_dir); let mut dir_opt = "-Zdump-mir-dir=".to_string(); dir_opt.push_str(mir_dump_dir.to_str().unwrap()); debug!("dir_opt: {:?}", dir_opt); @@ -2710,6 +2708,12 @@ impl<'test> TestCx<'test> { .with_extra_extension(self.config.mode.aux_dir_disambiguator()) } + /// Gets the directory where auxiliary binaries are written. + /// E.g., `/.../testname.revision.mode/auxiliary/bin`. + fn aux_bin_output_dir_name(&self) -> PathBuf { + self.aux_output_dir_name().join("bin") + } + /// Generates a unique name for the test, such as `testname.revision.mode`. fn output_testname_unique(&self) -> PathBuf { output_testname_unique(self.config, self.testpaths, self.safe_revision()) @@ -2948,8 +2952,7 @@ impl<'test> TestCx<'test> { assert!(self.revision.is_none(), "revisions not relevant here"); let out_dir = self.output_base_dir(); - let _ = fs::remove_dir_all(&out_dir); - create_dir_all(&out_dir).unwrap(); + remove_and_create_dir_all(&out_dir); let proc_res = self.document(&out_dir); if !proc_res.status.success() { @@ -2983,9 +2986,7 @@ impl<'test> TestCx<'test> { let suffix = self.safe_revision().map_or("nightly".into(), |path| path.to_owned() + "-nightly"); let compare_dir = output_base_dir(self.config, self.testpaths, Some(&suffix)); - // Don't give an error if the directory didn't already exist - let _ = fs::remove_dir_all(&compare_dir); - create_dir_all(&compare_dir).unwrap(); + remove_and_create_dir_all(&compare_dir); // We need to create a new struct for the lifetimes on `config` to work. let new_rustdoc = TestCx { @@ -3134,8 +3135,7 @@ impl<'test> TestCx<'test> { assert!(self.revision.is_none(), "revisions not relevant here"); let out_dir = self.output_base_dir(); - let _ = fs::remove_dir_all(&out_dir); - create_dir_all(&out_dir).unwrap(); + remove_and_create_dir_all(&out_dir); let proc_res = self.document(&out_dir); if !proc_res.status.success() { @@ -3767,36 +3767,42 @@ impl<'test> TestCx<'test> { debug!(?support_lib_deps); debug!(?support_lib_deps_deps); - let res = self.cmd2procres( - Command::new(&self.config.rustc_path) - .arg("-o") - .arg(&recipe_bin) - .arg(format!( - "-Ldependency={}", - &support_lib_path.parent().unwrap().to_string_lossy() - )) - .arg(format!("-Ldependency={}", &support_lib_deps.to_string_lossy())) - .arg(format!("-Ldependency={}", &support_lib_deps_deps.to_string_lossy())) - .arg("--extern") - .arg(format!("run_make_support={}", &support_lib_path.to_string_lossy())) - .arg(&self.testpaths.file.join("rmake.rs")) - .env("TARGET", &self.config.target) - .env("PYTHON", &self.config.python) - .env("S", &src_root) - .env("RUST_BUILD_STAGE", &self.config.stage_id) - .env("RUSTC", cwd.join(&self.config.rustc_path)) - .env("TMPDIR", &tmpdir) - .env("LD_LIB_PATH_ENVVAR", dylib_env_var()) - .env("HOST_RPATH_DIR", cwd.join(&self.config.compile_lib_path)) - .env("TARGET_RPATH_DIR", cwd.join(&self.config.run_lib_path)) - .env("LLVM_COMPONENTS", &self.config.llvm_components) - // We for sure don't want these tests to run in parallel, so make - // sure they don't have access to these vars if we run via `make` - // at the top level - .env_remove("MAKEFLAGS") - .env_remove("MFLAGS") - .env_remove("CARGO_MAKEFLAGS"), - ); + let mut cmd = Command::new(&self.config.rustc_path); + cmd.arg("-o") + .arg(&recipe_bin) + .arg(format!("-Ldependency={}", &support_lib_path.parent().unwrap().to_string_lossy())) + .arg(format!("-Ldependency={}", &support_lib_deps.to_string_lossy())) + .arg(format!("-Ldependency={}", &support_lib_deps_deps.to_string_lossy())) + .arg("--extern") + .arg(format!("run_make_support={}", &support_lib_path.to_string_lossy())) + .arg(&self.testpaths.file.join("rmake.rs")) + .env("TARGET", &self.config.target) + .env("PYTHON", &self.config.python) + .env("S", &src_root) + .env("RUST_BUILD_STAGE", &self.config.stage_id) + .env("RUSTC", cwd.join(&self.config.rustc_path)) + .env("TMPDIR", &tmpdir) + .env("LD_LIB_PATH_ENVVAR", dylib_env_var()) + .env("HOST_RPATH_DIR", cwd.join(&self.config.compile_lib_path)) + .env("TARGET_RPATH_DIR", cwd.join(&self.config.run_lib_path)) + .env("LLVM_COMPONENTS", &self.config.llvm_components) + // We for sure don't want these tests to run in parallel, so make + // sure they don't have access to these vars if we run via `make` + // at the top level + .env_remove("MAKEFLAGS") + .env_remove("MFLAGS") + .env_remove("CARGO_MAKEFLAGS"); + + if std::env::var_os("COMPILETEST_FORCE_STAGE0").is_some() { + let mut stage0_sysroot = build_root.clone(); + stage0_sysroot.push("stage0-sysroot"); + debug!(?stage0_sysroot); + debug!(exists = stage0_sysroot.exists()); + + cmd.arg("--sysroot").arg(&stage0_sysroot); + } + + let res = self.cmd2procres(&mut cmd); if !res.status.success() { self.fatal_proc_rec("run-make test failed: could not build `rmake.rs` recipe", &res); } @@ -3973,6 +3979,10 @@ impl<'test> TestCx<'test> { } } + fn force_color_svg(&self) -> bool { + self.props.compile_flags.iter().any(|s| s.contains("--color=always")) + } + fn load_compare_outputs( &self, proc_res: &ProcRes, @@ -3980,10 +3990,9 @@ impl<'test> TestCx<'test> { explicit_format: bool, ) -> usize { let stderr_bits = format!("{}bit.stderr", self.config.get_pointer_width()); - let force_color_svg = self.props.compile_flags.iter().any(|s| s.contains("--color=always")); let (stderr_kind, stdout_kind) = match output_kind { TestOutput::Compile => ( - if force_color_svg { + if self.force_color_svg() { if self.config.target.contains("windows") { // We single out Windows here because some of the CLI coloring is // specifically changed for Windows. @@ -4030,7 +4039,7 @@ impl<'test> TestCx<'test> { _ => {} }; - let stderr = if force_color_svg { + let stderr = if self.force_color_svg() { anstyle_svg::Term::new().render_svg(&proc_res.stderr) } else if explicit_format { proc_res.stderr.clone() @@ -4643,7 +4652,13 @@ impl<'test> TestCx<'test> { } fn compare_output(&self, kind: &str, actual: &str, expected: &str) -> usize { - if actual == expected { + let are_different = match (self.force_color_svg(), expected.find('\n'), actual.find('\n')) { + // FIXME: We ignore the first line of SVG files + // because the width parameter is non-deterministic. + (true, Some(nl_e), Some(nl_a)) => expected[nl_e..] != actual[nl_a..], + _ => expected != actual, + }; + if !are_different { return 0; } @@ -4853,3 +4868,9 @@ enum LinkToAux { Yes, No, } + +enum AuxType { + Bin, + Lib, + Dylib, +} diff --git a/src/tools/generate-windows-sys/Cargo.toml b/src/tools/generate-windows-sys/Cargo.toml index d8a7a06efc6..9ea26defdc4 100644 --- a/src/tools/generate-windows-sys/Cargo.toml +++ b/src/tools/generate-windows-sys/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies.windows-bindgen] -version = "0.52.0" +version = "0.55.0" diff --git a/src/tools/jsondoclint/src/validator/tests.rs b/src/tools/jsondoclint/src/validator/tests.rs index 95a56a9dfac..ba0fe11ea26 100644 --- a/src/tools/jsondoclint/src/validator/tests.rs +++ b/src/tools/jsondoclint/src/validator/tests.rs @@ -1,5 +1,5 @@ use rustc_hash::FxHashMap; -use rustdoc_json_types::{Crate, Item, ItemKind, ItemSummary, Visibility, FORMAT_VERSION}; +use rustdoc_json_types::{Item, ItemKind, Visibility, FORMAT_VERSION}; use crate::json_find::SelectorPart; diff --git a/src/tools/lint-docs/src/groups.rs b/src/tools/lint-docs/src/groups.rs index c5cd30ccc34..0c39f2fa601 100644 --- a/src/tools/lint-docs/src/groups.rs +++ b/src/tools/lint-docs/src/groups.rs @@ -16,6 +16,10 @@ static GROUP_DESCRIPTIONS: &[(&str, &str)] = &[ ("rust-2018-compatibility", "Lints used to transition code from the 2015 edition to 2018"), ("rust-2021-compatibility", "Lints used to transition code from the 2018 edition to 2021"), ("rust-2024-compatibility", "Lints used to transition code from the 2021 edition to 2024"), + ( + "refining-impl-trait", + "Detects refinement of `impl Trait` return types by trait implementations", + ), ]; type LintGroups = BTreeMap<String, BTreeSet<String>>; diff --git a/src/tools/miri/src/borrow_tracker/mod.rs b/src/tools/miri/src/borrow_tracker/mod.rs index 0f7200fb407..8d76a488269 100644 --- a/src/tools/miri/src/borrow_tracker/mod.rs +++ b/src/tools/miri/src/borrow_tracker/mod.rs @@ -5,7 +5,7 @@ use std::num::NonZero; use smallvec::SmallVec; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_middle::{mir::RetagKind, ty::Ty}; +use rustc_middle::mir::RetagKind; use rustc_target::abi::Size; use crate::*; @@ -291,19 +291,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { } } - fn retag_box_to_raw( - &mut self, - val: &ImmTy<'tcx, Provenance>, - alloc_ty: Ty<'tcx>, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { - let this = self.eval_context_mut(); - let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method; - match method { - BorrowTrackerMethod::StackedBorrows => this.sb_retag_box_to_raw(val, alloc_ty), - BorrowTrackerMethod::TreeBorrows => this.tb_retag_box_to_raw(val, alloc_ty), - } - } - fn retag_place_contents( &mut self, kind: RetagKind, diff --git a/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs index 9130601bbdd..7a6a85a2f79 100644 --- a/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs @@ -865,24 +865,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { this.sb_retag_reference(val, new_perm, RetagInfo { cause, in_field: false }) } - fn sb_retag_box_to_raw( - &mut self, - val: &ImmTy<'tcx, Provenance>, - alloc_ty: Ty<'tcx>, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { - let this = self.eval_context_mut(); - let is_global_alloc = alloc_ty.ty_adt_def().is_some_and(|adt| { - let global_alloc = this.tcx.require_lang_item(rustc_hir::LangItem::GlobalAlloc, None); - adt.did() == global_alloc - }); - if is_global_alloc { - // Retag this as-if it was a mutable reference. - this.sb_retag_ptr_value(RetagKind::Raw, val) - } else { - Ok(val.clone()) - } - } - fn sb_retag_place_contents( &mut self, kind: RetagKind, @@ -891,9 +873,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { let this = self.eval_context_mut(); let retag_fields = this.machine.borrow_tracker.as_mut().unwrap().get_mut().retag_fields; let retag_cause = match kind { - RetagKind::Raw | RetagKind::TwoPhase { .. } => unreachable!(), // these can only happen in `retag_ptr_value` + RetagKind::TwoPhase { .. } => unreachable!(), // can only happen in `retag_ptr_value` RetagKind::FnEntry => RetagCause::FnEntry, - RetagKind::Default => RetagCause::Normal, + RetagKind::Default | RetagKind::Raw => RetagCause::Normal, }; let mut visitor = RetagVisitor { ecx: this, kind, retag_cause, retag_fields, in_field: false }; @@ -959,14 +941,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { // Check the type of this value to see what to do with it (retag, or recurse). match place.layout.ty.kind() { - ty::Ref(..) => { - let new_perm = - NewPermission::from_ref_ty(place.layout.ty, self.kind, self.ecx); - self.retag_ptr_inplace(place, new_perm)?; - } - ty::RawPtr(..) => { - // We do *not* want to recurse into raw pointers -- wide raw pointers have - // fields, and for dyn Trait pointees those can have reference type! + ty::Ref(..) | ty::RawPtr(..) => { + if matches!(place.layout.ty.kind(), ty::Ref(..)) + || self.kind == RetagKind::Raw + { + let new_perm = + NewPermission::from_ref_ty(place.layout.ty, self.kind, self.ecx); + self.retag_ptr_inplace(place, new_perm)?; + } } ty::Adt(adt, _) if adt.is_box() => { // Recurse for boxes, they require some tricky handling and will end up in `visit_box` above. diff --git a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs index 9eb78b08ef7..80bdcbb7559 100644 --- a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs @@ -392,15 +392,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { } } - fn tb_retag_box_to_raw( - &mut self, - val: &ImmTy<'tcx, Provenance>, - _alloc_ty: Ty<'tcx>, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { - // Casts to raw pointers are NOPs in Tree Borrows. - Ok(val.clone()) - } - /// Retag all pointers that are stored in this place. fn tb_retag_place_contents( &mut self, diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 7e5518392d8..3a4ab32e4ab 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -1503,7 +1503,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> { fn eval_mir_constant<F>( ecx: &InterpCx<'mir, 'tcx, Self>, val: mir::Const<'tcx>, - span: Option<Span>, + span: Span, layout: Option<TyAndLayout<'tcx>>, eval: F, ) -> InterpResult<'tcx, OpTy<'tcx, Self::Provenance>> @@ -1511,7 +1511,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> { F: Fn( &InterpCx<'mir, 'tcx, Self>, mir::Const<'tcx>, - Option<Span>, + Span, Option<TyAndLayout<'tcx>>, ) -> InterpResult<'tcx, OpTy<'tcx, Self::Provenance>>, { diff --git a/src/tools/miri/src/shims/intrinsics/mod.rs b/src/tools/miri/src/shims/intrinsics/mod.rs index 976d4b4de55..d16d5d99e9c 100644 --- a/src/tools/miri/src/shims/intrinsics/mod.rs +++ b/src/tools/miri/src/shims/intrinsics/mod.rs @@ -140,18 +140,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { this.write_pointer(Pointer::new(ptr.provenance, masked_addr), dest)?; } - "retag_box_to_raw" => { - let [ptr] = check_arg_count(args)?; - let alloc_ty = generic_args[1].expect_ty(); - - let val = this.read_immediate(ptr)?; - let new_val = if this.machine.borrow_tracker.is_some() { - this.retag_box_to_raw(&val, alloc_ty)? - } else { - val - }; - this.write_immediate(*new_val, dest)?; - } // We want to return either `true` or `false` at random, or else something like // ``` diff --git a/src/tools/miri/src/shims/intrinsics/simd.rs b/src/tools/miri/src/shims/intrinsics/simd.rs index ddddcdcebd2..c97a052f517 100644 --- a/src/tools/miri/src/shims/intrinsics/simd.rs +++ b/src/tools/miri/src/shims/intrinsics/simd.rs @@ -549,7 +549,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { let index = generic_args[2] .expect_const() - .eval(*this.tcx, this.param_env(), Some(this.tcx.span)) + .eval(*this.tcx, this.param_env(), this.tcx.span) .unwrap() .unwrap_branch(); let index_len = index.len(); diff --git a/src/tools/miri/test-cargo-miri/tests/main.rs b/src/tools/miri/test-cargo-miri/tests/main.rs index bb94c8f3787..72224e29619 100644 --- a/src/tools/miri/test-cargo-miri/tests/main.rs +++ b/src/tools/miri/test-cargo-miri/tests/main.rs @@ -1,3 +1 @@ -#![feature(imported_main)] - use cargo_miri_test::main; diff --git a/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.stack.stderr b/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.stack.stderr index c26c7f397b0..867907e98e6 100644 --- a/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.stack.stderr +++ b/src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.stack.stderr @@ -6,7 +6,7 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc) | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information -help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4] +help: <TAG> was created by a Unique retag at offsets [0x0..0x4] --> $DIR/newtype_pair_retagging.rs:LL:CC | LL | let ptr = Box::into_raw(Box::new(0i32)); diff --git a/src/tools/miri/tests/fail/both_borrows/newtype_retagging.stack.stderr b/src/tools/miri/tests/fail/both_borrows/newtype_retagging.stack.stderr index ae54da70fe2..56715938e97 100644 --- a/src/tools/miri/tests/fail/both_borrows/newtype_retagging.stack.stderr +++ b/src/tools/miri/tests/fail/both_borrows/newtype_retagging.stack.stderr @@ -6,7 +6,7 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc) | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information -help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4] +help: <TAG> was created by a Unique retag at offsets [0x0..0x4] --> $DIR/newtype_retagging.rs:LL:CC | LL | let ptr = Box::into_raw(Box::new(0i32)); diff --git a/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_callee_ret.stderr b/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_callee_ret.stderr index 7d481940ace..35de4535222 100644 --- a/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_callee_ret.stderr +++ b/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_callee_ret.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: constructing invalid value: encountered 0, but expected something greater or equal to 1 +error: Undefined Behavior: constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 --> $DIR/cast_fn_ptr_invalid_callee_ret.rs:LL:CC | LL | f(); - | ^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 + | ^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr b/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr index b1a2bd2c79a..81d775f6d7f 100644 --- a/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr +++ b/src/tools/miri/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: constructing invalid value: encountered 0, but expected something greater or equal to 1 +error: Undefined Behavior: constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 --> $DIR/cast_fn_ptr_invalid_caller_arg.rs:LL:CC | LL | Call(_res = f(*ptr), ReturnTo(retblock), UnwindContinue()) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/src/tools/miri/tests/pass/imported_main.rs b/src/tools/miri/tests/pass/imported_main.rs index 32b39152f78..eb93cd11d38 100644 --- a/src/tools/miri/tests/pass/imported_main.rs +++ b/src/tools/miri/tests/pass/imported_main.rs @@ -1,5 +1,3 @@ -#![feature(imported_main)] - pub mod foo { pub fn mymain() { println!("Hello, world!"); diff --git a/src/tools/miri/tests/pass/main_fn.rs b/src/tools/miri/tests/pass/main_fn.rs index 3b84d1abe6f..4cdd034f30e 100644 --- a/src/tools/miri/tests/pass/main_fn.rs +++ b/src/tools/miri/tests/pass/main_fn.rs @@ -1,5 +1,3 @@ -#![feature(imported_main)] - mod foo { pub(crate) fn bar() {} } diff --git a/src/tools/opt-dist/src/bolt.rs b/src/tools/opt-dist/src/bolt.rs index f694c08f9b9..eb10426f060 100644 --- a/src/tools/opt-dist/src/bolt.rs +++ b/src/tools/opt-dist/src/bolt.rs @@ -62,9 +62,11 @@ pub fn bolt_optimize(path: &Utf8Path, profile: &BoltProfile) -> anyhow::Result<( // Reorder basic blocks within functions .arg("-reorder-blocks=ext-tsp") // Reorder functions within the binary - .arg("-reorder-functions=hfsort+") + .arg("-reorder-functions=cdsort") // Split function code into hot and code regions .arg("-split-functions") + // Split using best available strategy (three-way splitting, Cache-Directed Sort) + .arg("-split-strategy=cdsplit") // Split as many basic blocks as possible .arg("-split-all-cold") // Move jump tables to a separate section diff --git a/src/tools/rust-analyzer/.github/workflows/release.yaml b/src/tools/rust-analyzer/.github/workflows/release.yaml index ac536d0fdde..dc0a6c2d91f 100644 --- a/src/tools/rust-analyzer/.github/workflows/release.yaml +++ b/src/tools/rust-analyzer/.github/workflows/release.yaml @@ -36,7 +36,6 @@ jobs: - os: ubuntu-20.04 target: x86_64-unknown-linux-gnu code-target: linux-x64 - container: ubuntu:18.04 - os: ubuntu-20.04 target: aarch64-unknown-linux-gnu code-target: linux-arm64 @@ -63,14 +62,6 @@ jobs: with: fetch-depth: ${{ env.FETCH_DEPTH }} - - name: Install toolchain dependencies - if: matrix.container == 'ubuntu:18.04' - shell: bash - run: | - apt-get update && apt-get install -y build-essential curl - curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --profile minimal --default-toolchain none -y - echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH - - name: Install Rust toolchain run: | rustup update --no-self-update stable diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock index 903141eee9a..68ed32391b7 100644 --- a/src/tools/rust-analyzer/Cargo.lock +++ b/src/tools/rust-analyzer/Cargo.lock @@ -71,6 +71,7 @@ version = "0.0.0" dependencies = [ "cfg", "la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lz4_flex", "rustc-hash", "salsa", "semver", @@ -134,9 +135,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.89" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0ba8f7aaa012f30d5b2861462f6708eccd49c3c39863fe083a308035f63d723" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" [[package]] name = "cfg" @@ -874,9 +875,9 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libloading" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2caa5afb8bf9f3a2652760ce7d4f62d21c4d5a423e68466fca30df82f2330164" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", "windows-targets 0.52.4", @@ -993,6 +994,12 @@ dependencies = [ ] [[package]] +name = "lz4_flex" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "912b45c753ff5f7f5208307e8ace7d2a2e30d024e26d3509f3dce546c044ce15" + +[[package]] name = "mbe" version = "0.0.0" dependencies = [ @@ -1597,6 +1604,7 @@ dependencies = [ "rayon", "rustc-hash", "scip", + "semver", "serde", "serde_json", "sourcegen", diff --git a/src/tools/rust-analyzer/Cargo.toml b/src/tools/rust-analyzer/Cargo.toml index 440f46a938b..0679522efd6 100644 --- a/src/tools/rust-analyzer/Cargo.toml +++ b/src/tools/rust-analyzer/Cargo.toml @@ -105,6 +105,10 @@ anyhow = "1.0.75" arrayvec = "0.7.4" bitflags = "2.4.1" cargo_metadata = "0.18.1" +chalk-solve = { version = "0.96.0", default-features = false } +chalk-ir = "0.96.0" +chalk-recursive = { version = "0.96.0", default-features = false } +chalk-derive = "0.96.0" command-group = "2.0.1" crossbeam-channel = "0.5.8" dissimilar = "1.0.7" diff --git a/src/tools/rust-analyzer/crates/base-db/Cargo.toml b/src/tools/rust-analyzer/crates/base-db/Cargo.toml index 118abf5d6eb..4ab99fc33c4 100644 --- a/src/tools/rust-analyzer/crates/base-db/Cargo.toml +++ b/src/tools/rust-analyzer/crates/base-db/Cargo.toml @@ -12,6 +12,8 @@ rust-version.workspace = true doctest = false [dependencies] +lz4_flex = { version = "0.11", default-features = false } + la-arena.workspace = true salsa.workspace = true rustc-hash.workspace = true diff --git a/src/tools/rust-analyzer/crates/base-db/src/change.rs b/src/tools/rust-analyzer/crates/base-db/src/change.rs index 003ffb24d9d..f202a885e27 100644 --- a/src/tools/rust-analyzer/crates/base-db/src/change.rs +++ b/src/tools/rust-analyzer/crates/base-db/src/change.rs @@ -7,13 +7,13 @@ use salsa::Durability; use triomphe::Arc; use vfs::FileId; -use crate::{CrateGraph, SourceDatabaseExt, SourceRoot, SourceRootId}; +use crate::{CrateGraph, SourceDatabaseExt, SourceDatabaseExt2, SourceRoot, SourceRootId}; /// Encapsulate a bunch of raw `.set` calls on the database. #[derive(Default)] pub struct FileChange { pub roots: Option<Vec<SourceRoot>>, - pub files_changed: Vec<(FileId, Option<Arc<str>>)>, + pub files_changed: Vec<(FileId, Option<String>)>, pub crate_graph: Option<CrateGraph>, } @@ -42,7 +42,7 @@ impl FileChange { self.roots = Some(roots); } - pub fn change_file(&mut self, file_id: FileId, new_text: Option<Arc<str>>) { + pub fn change_file(&mut self, file_id: FileId, new_text: Option<String>) { self.files_changed.push((file_id, new_text)) } @@ -68,8 +68,8 @@ impl FileChange { let source_root = db.source_root(source_root_id); let durability = durability(&source_root); // XXX: can't actually remove the file, just reset the text - let text = text.unwrap_or_else(|| Arc::from("")); - db.set_file_text_with_durability(file_id, text, durability) + let text = text.unwrap_or_default(); + db.set_file_text_with_durability(file_id, &text, durability) } if let Some(crate_graph) = self.crate_graph { db.set_crate_graph_with_durability(Arc::new(crate_graph), Durability::HIGH); diff --git a/src/tools/rust-analyzer/crates/base-db/src/lib.rs b/src/tools/rust-analyzer/crates/base-db/src/lib.rs index 758d2a45c8f..5dcb580723f 100644 --- a/src/tools/rust-analyzer/crates/base-db/src/lib.rs +++ b/src/tools/rust-analyzer/crates/base-db/src/lib.rs @@ -7,6 +7,7 @@ mod input; use std::panic; +use salsa::Durability; use syntax::{ast, Parse, SourceFile}; use triomphe::Arc; @@ -42,6 +43,7 @@ pub trait Upcast<T: ?Sized> { fn upcast(&self) -> &T; } +pub const DEFAULT_FILE_TEXT_LRU_CAP: usize = 16; pub const DEFAULT_PARSE_LRU_CAP: usize = 128; pub const DEFAULT_BORROWCK_LRU_CAP: usize = 1024; @@ -89,7 +91,10 @@ fn parse(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> { #[salsa::query_group(SourceDatabaseExtStorage)] pub trait SourceDatabaseExt: SourceDatabase { #[salsa::input] + fn compressed_file_text(&self, file_id: FileId) -> Arc<[u8]>; + fn file_text(&self, file_id: FileId) -> Arc<str>; + /// Path to a file, relative to the root of its source root. /// Source root of the file. #[salsa::input] @@ -101,6 +106,44 @@ pub trait SourceDatabaseExt: SourceDatabase { fn source_root_crates(&self, id: SourceRootId) -> Arc<[CrateId]>; } +fn file_text(db: &dyn SourceDatabaseExt, file_id: FileId) -> Arc<str> { + let bytes = db.compressed_file_text(file_id); + let bytes = + lz4_flex::decompress_size_prepended(&bytes).expect("lz4 decompression should not fail"); + let text = std::str::from_utf8(&bytes).expect("file contents should be valid UTF-8"); + Arc::from(text) +} + +pub trait SourceDatabaseExt2 { + fn set_file_text(&mut self, file_id: FileId, text: &str) { + self.set_file_text_with_durability(file_id, text, Durability::LOW); + } + + fn set_file_text_with_durability( + &mut self, + file_id: FileId, + text: &str, + durability: Durability, + ); +} + +impl<Db: ?Sized + SourceDatabaseExt> SourceDatabaseExt2 for Db { + fn set_file_text_with_durability( + &mut self, + file_id: FileId, + text: &str, + durability: Durability, + ) { + let bytes = text.as_bytes(); + let compressed = lz4_flex::compress_prepend_size(bytes); + self.set_compressed_file_text_with_durability( + file_id, + Arc::from(compressed.as_slice()), + durability, + ) + } +} + fn source_root_crates(db: &dyn SourceDatabaseExt, id: SourceRootId) -> Arc<[CrateId]> { let graph = db.crate_graph(); let mut crates = graph diff --git a/src/tools/rust-analyzer/crates/cfg/Cargo.toml b/src/tools/rust-analyzer/crates/cfg/Cargo.toml index fbda065b10f..9b3a5026ac8 100644 --- a/src/tools/rust-analyzer/crates/cfg/Cargo.toml +++ b/src/tools/rust-analyzer/crates/cfg/Cargo.toml @@ -31,4 +31,4 @@ mbe.workspace = true syntax.workspace = true [lints] -workspace = true \ No newline at end of file +workspace = true diff --git a/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs b/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs index 4be6ae7481d..b7dbb7b5fdd 100644 --- a/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs +++ b/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs @@ -47,6 +47,7 @@ impl CfgExpr { pub fn parse<S>(tt: &tt::Subtree<S>) -> CfgExpr { next_cfg_expr(&mut tt.token_trees.iter()).unwrap_or(CfgExpr::Invalid) } + /// Fold the cfg by querying all basic `Atom` and `KeyValue` predicates. pub fn fold(&self, query: &dyn Fn(&CfgAtom) -> bool) -> Option<bool> { match self { @@ -62,7 +63,6 @@ impl CfgExpr { } } } - fn next_cfg_expr<S>(it: &mut SliceIter<'_, tt::TokenTree<S>>) -> Option<CfgExpr> { let name = match it.next() { None => return None, diff --git a/src/tools/rust-analyzer/crates/flycheck/src/test_runner.rs b/src/tools/rust-analyzer/crates/flycheck/src/test_runner.rs index 6dac5899ee3..31378716b3e 100644 --- a/src/tools/rust-analyzer/crates/flycheck/src/test_runner.rs +++ b/src/tools/rust-analyzer/crates/flycheck/src/test_runner.rs @@ -28,19 +28,20 @@ pub enum CargoTestMessage { }, Suite, Finished, + Custom { + text: String, + }, } impl ParseFromLine for CargoTestMessage { - fn from_line(line: &str, error: &mut String) -> Option<Self> { + fn from_line(line: &str, _: &mut String) -> Option<Self> { let mut deserializer = serde_json::Deserializer::from_str(line); deserializer.disable_recursion_limit(); if let Ok(message) = CargoTestMessage::deserialize(&mut deserializer) { return Some(message); } - error.push_str(line); - error.push('\n'); - None + Some(CargoTestMessage::Custom { text: line.to_owned() }) } fn from_eof() -> Option<Self> { diff --git a/src/tools/rust-analyzer/crates/hir-def/src/body.rs b/src/tools/rust-analyzer/crates/hir-def/src/body.rs index 37d37fd3311..c9f1add2751 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/body.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/body.rs @@ -10,7 +10,6 @@ use std::ops::Index; use base_db::CrateId; use cfg::{CfgExpr, CfgOptions}; -use either::Either; use hir_expand::{name::Name, HirFileId, InFile}; use la_arena::{Arena, ArenaMap}; use rustc_hash::FxHashMap; @@ -45,7 +44,8 @@ pub struct Body { /// /// If this `Body` is for the body of a constant, this will just be /// empty. - pub params: Vec<PatId>, + pub params: Box<[PatId]>, + pub self_param: Option<BindingId>, /// The `ExprId` of the actual body expression. pub body_expr: ExprId, /// Block expressions in this body that may contain inner items. @@ -55,7 +55,7 @@ pub struct Body { pub type ExprPtr = AstPtr<ast::Expr>; pub type ExprSource = InFile<ExprPtr>; -pub type PatPtr = AstPtr<Either<ast::Pat, ast::SelfParam>>; +pub type PatPtr = AstPtr<ast::Pat>; pub type PatSource = InFile<PatPtr>; pub type LabelPtr = AstPtr<ast::Label>; @@ -63,6 +63,7 @@ pub type LabelSource = InFile<LabelPtr>; pub type FieldPtr = AstPtr<ast::RecordExprField>; pub type FieldSource = InFile<FieldPtr>; + pub type PatFieldPtr = AstPtr<ast::RecordPatField>; pub type PatFieldSource = InFile<PatFieldPtr>; @@ -88,6 +89,8 @@ pub struct BodySourceMap { label_map: FxHashMap<LabelSource, LabelId>, label_map_back: ArenaMap<LabelId, LabelSource>, + self_param: Option<InFile<AstPtr<ast::SelfParam>>>, + /// We don't create explicit nodes for record fields (`S { record_field: 92 }`). /// Instead, we use id of expression (`92`) to identify the field. field_map_back: FxHashMap<ExprId, FieldSource>, @@ -215,10 +218,11 @@ impl Body { fn shrink_to_fit(&mut self) { let Self { body_expr: _, + params: _, + self_param: _, block_scopes, exprs, labels, - params, pats, bindings, binding_owners, @@ -226,7 +230,6 @@ impl Body { block_scopes.shrink_to_fit(); exprs.shrink_to_fit(); labels.shrink_to_fit(); - params.shrink_to_fit(); pats.shrink_to_fit(); bindings.shrink_to_fit(); binding_owners.shrink_to_fit(); @@ -297,6 +300,7 @@ impl Default for Body { params: Default::default(), block_scopes: Default::default(), binding_owners: Default::default(), + self_param: Default::default(), } } } @@ -354,14 +358,12 @@ impl BodySourceMap { self.pat_map_back.get(pat).cloned().ok_or(SyntheticSyntax) } - pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> { - let src = node.map(|it| AstPtr::new(it).wrap_left()); - self.pat_map.get(&src).cloned() + pub fn self_param_syntax(&self) -> Option<InFile<AstPtr<ast::SelfParam>>> { + self.self_param } - pub fn node_self_param(&self, node: InFile<&ast::SelfParam>) -> Option<PatId> { - let src = node.map(|it| AstPtr::new(it).wrap_right()); - self.pat_map.get(&src).cloned() + pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> { + self.pat_map.get(&node.map(AstPtr::new)).cloned() } pub fn label_syntax(&self, label: LabelId) -> LabelSource { @@ -401,6 +403,7 @@ impl BodySourceMap { fn shrink_to_fit(&mut self) { let Self { + self_param: _, expr_map, expr_map_back, pat_map, diff --git a/src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs b/src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs index 66691277894..340e95dbc2f 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs @@ -4,7 +4,6 @@ use std::mem; use base_db::CrateId; -use either::Either; use hir_expand::{ name::{name, AsName, Name}, ExpandError, InFile, @@ -29,7 +28,6 @@ use crate::{ db::DefDatabase, expander::Expander, hir::{ - dummy_expr_id, format_args::{ self, FormatAlignment, FormatArgs, FormatArgsPiece, FormatArgument, FormatArgumentKind, FormatArgumentsCollector, FormatCount, FormatDebugHex, FormatOptions, @@ -66,16 +64,7 @@ pub(super) fn lower( def_map: expander.module.def_map(db), source_map: BodySourceMap::default(), ast_id_map: db.ast_id_map(expander.current_file_id()), - body: Body { - exprs: Default::default(), - pats: Default::default(), - bindings: Default::default(), - binding_owners: Default::default(), - labels: Default::default(), - params: Vec::new(), - body_expr: dummy_expr_id(), - block_scopes: Vec::new(), - }, + body: Body::default(), expander, current_try_block_label: None, is_lowering_assignee_expr: false, @@ -191,35 +180,35 @@ impl ExprCollector<'_> { is_async_fn: bool, ) -> (Body, BodySourceMap) { if let Some((param_list, mut attr_enabled)) = param_list { + let mut params = vec![]; if let Some(self_param) = param_list.self_param().filter(|_| attr_enabled.next().unwrap_or(false)) { let is_mutable = self_param.mut_token().is_some() && self_param.amp_token().is_none(); - let ptr = AstPtr::new(&Either::Right(self_param)); let binding_id: la_arena::Idx<Binding> = self.alloc_binding(name![self], BindingAnnotation::new(is_mutable, false)); - let param_pat = self.alloc_pat(Pat::Bind { id: binding_id, subpat: None }, ptr); - self.add_definition_to_binding(binding_id, param_pat); - self.body.params.push(param_pat); + self.body.self_param = Some(binding_id); + self.source_map.self_param = Some(self.expander.in_file(AstPtr::new(&self_param))); } for (param, _) in param_list.params().zip(attr_enabled).filter(|(_, enabled)| *enabled) { let param_pat = self.collect_pat_top(param.pat()); - self.body.params.push(param_pat); + params.push(param_pat); } + self.body.params = params.into_boxed_slice(); }; self.body.body_expr = self.with_label_rib(RibKind::Closure, |this| { if is_async_fn { match body { Some(e) => { + let syntax_ptr = AstPtr::new(&e); let expr = this.collect_expr(e); - this.alloc_expr_desugared(Expr::Async { - id: None, - statements: Box::new([]), - tail: Some(expr), - }) + this.alloc_expr_desugared_with_ptr( + Expr::Async { id: None, statements: Box::new([]), tail: Some(expr) }, + syntax_ptr, + ) } None => this.missing_expr(), } @@ -405,7 +394,7 @@ impl ExprCollector<'_> { } ast::Expr::ParenExpr(e) => { let inner = self.collect_expr_opt(e.expr()); - // make the paren expr point to the inner expression as well + // make the paren expr point to the inner expression as well for IDE resolution let src = self.expander.in_file(syntax_ptr); self.source_map.expr_map.insert(src, inner); inner @@ -707,6 +696,7 @@ impl ExprCollector<'_> { .alloc_label_desugared(Label { name: Name::generate_new_name(self.body.labels.len()) }); let old_label = self.current_try_block_label.replace(label); + let ptr = AstPtr::new(&e).upcast(); let (btail, expr_id) = self.with_labeled_rib(label, |this| { let mut btail = None; let block = this.collect_block_(e, |id, statements, tail| { @@ -716,23 +706,21 @@ impl ExprCollector<'_> { (btail, block) }); - let callee = self.alloc_expr_desugared(Expr::Path(try_from_output)); + let callee = self.alloc_expr_desugared_with_ptr(Expr::Path(try_from_output), ptr); let next_tail = match btail { - Some(tail) => self.alloc_expr_desugared(Expr::Call { - callee, - args: Box::new([tail]), - is_assignee_expr: false, - }), + Some(tail) => self.alloc_expr_desugared_with_ptr( + Expr::Call { callee, args: Box::new([tail]), is_assignee_expr: false }, + ptr, + ), None => { - let unit = self.alloc_expr_desugared(Expr::Tuple { - exprs: Box::new([]), - is_assignee_expr: false, - }); - self.alloc_expr_desugared(Expr::Call { - callee, - args: Box::new([unit]), - is_assignee_expr: false, - }) + let unit = self.alloc_expr_desugared_with_ptr( + Expr::Tuple { exprs: Box::new([]), is_assignee_expr: false }, + ptr, + ); + self.alloc_expr_desugared_with_ptr( + Expr::Call { callee, args: Box::new([unit]), is_assignee_expr: false }, + ptr, + ) } }; let Expr::Block { tail, .. } = &mut self.body.exprs[expr_id] else { @@ -1067,16 +1055,12 @@ impl ExprCollector<'_> { None => None, }, ); - match expansion { - Some(tail) => { - // Make the macro-call point to its expanded expression so we can query - // semantics on syntax pointers to the macro - let src = self.expander.in_file(syntax_ptr); - self.source_map.expr_map.insert(src, tail); - Some(tail) - } - None => None, - } + expansion.inspect(|&tail| { + // Make the macro-call point to its expanded expression so we can query + // semantics on syntax pointers to the macro + let src = self.expander.in_file(syntax_ptr); + self.source_map.expr_map.insert(src, tail); + }) } fn collect_stmt(&mut self, statements: &mut Vec<Statement>, s: ast::Stmt) { @@ -1261,7 +1245,7 @@ impl ExprCollector<'_> { (Some(id), Pat::Bind { id, subpat }) }; - let ptr = AstPtr::new(&Either::Left(pat)); + let ptr = AstPtr::new(&pat); let pat = self.alloc_pat(pattern, ptr); if let Some(binding_id) = binding { self.add_definition_to_binding(binding_id, pat); @@ -1359,9 +1343,10 @@ impl ExprCollector<'_> { suffix: suffix.into_iter().map(|p| self.collect_pat(p, binding_list)).collect(), } } - #[rustfmt::skip] // https://github.com/rust-lang/rustfmt/issues/5676 ast::Pat::LiteralPat(lit) => 'b: { - let Some((hir_lit, ast_lit)) = pat_literal_to_hir(lit) else { break 'b Pat::Missing }; + let Some((hir_lit, ast_lit)) = pat_literal_to_hir(lit) else { + break 'b Pat::Missing; + }; let expr = Expr::Literal(hir_lit); let expr_ptr = AstPtr::new(&ast::Expr::Literal(ast_lit)); let expr_id = self.alloc_expr(expr, expr_ptr); @@ -1397,7 +1382,7 @@ impl ExprCollector<'_> { ast::Pat::MacroPat(mac) => match mac.macro_call() { Some(call) => { let macro_ptr = AstPtr::new(&call); - let src = self.expander.in_file(AstPtr::new(&Either::Left(pat))); + let src = self.expander.in_file(AstPtr::new(&pat)); let pat = self.collect_macro_call(call, macro_ptr, true, |this, expanded_pat| { this.collect_pat_opt(expanded_pat, binding_list) @@ -1426,7 +1411,7 @@ impl ExprCollector<'_> { Pat::Range { start, end } } }; - let ptr = AstPtr::new(&Either::Left(pat)); + let ptr = AstPtr::new(&pat); self.alloc_pat(pattern, ptr) } @@ -1987,10 +1972,19 @@ impl ExprCollector<'_> { self.source_map.expr_map.insert(src, id); id } - // FIXME: desugared exprs don't have ptr, that's wrong and should be fixed somehow. + // FIXME: desugared exprs don't have ptr, that's wrong and should be fixed. + // Migrate to alloc_expr_desugared_with_ptr and then rename back fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId { self.body.exprs.alloc(expr) } + fn alloc_expr_desugared_with_ptr(&mut self, expr: Expr, ptr: ExprPtr) -> ExprId { + let src = self.expander.in_file(ptr); + let id = self.body.exprs.alloc(expr); + self.source_map.expr_map_back.insert(id, src); + // We intentionally don't fill this as it could overwrite a non-desugared entry + // self.source_map.expr_map.insert(src, id); + id + } fn missing_expr(&mut self) -> ExprId { self.alloc_expr_desugared(Expr::Missing) } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs b/src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs index b2aab55a6a8..cbb5ca887f4 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs @@ -48,7 +48,16 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo let mut p = Printer { db, body, buf: header, indent_level: 0, needs_indent: false }; if let DefWithBodyId::FunctionId(it) = owner { p.buf.push('('); - body.params.iter().zip(db.function_data(it).params.iter()).for_each(|(¶m, ty)| { + let params = &db.function_data(it).params; + let mut params = params.iter(); + if let Some(self_param) = body.self_param { + p.print_binding(self_param); + p.buf.push(':'); + if let Some(ty) = params.next() { + p.print_type_ref(ty); + } + } + body.params.iter().zip(params).for_each(|(¶m, ty)| { p.print_pat(param); p.buf.push(':'); p.print_type_ref(ty); diff --git a/src/tools/rust-analyzer/crates/hir-def/src/body/scope.rs b/src/tools/rust-analyzer/crates/hir-def/src/body/scope.rs index 69b82ae871a..0020e4eac30 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/body/scope.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/body/scope.rs @@ -96,6 +96,9 @@ impl ExprScopes { scope_by_expr: ArenaMap::with_capacity(body.exprs.len()), }; let mut root = scopes.root_scope(); + if let Some(self_param) = body.self_param { + scopes.add_bindings(body, root, self_param); + } scopes.add_params_bindings(body, root, &body.params); compute_expr_scopes(body.body_expr, body, &mut scopes, &mut root); scopes diff --git a/src/tools/rust-analyzer/crates/hir-def/src/child_by_source.rs b/src/tools/rust-analyzer/crates/hir-def/src/child_by_source.rs index f1c6b3b89fc..0b41984bdd8 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/child_by_source.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/child_by_source.rs @@ -76,7 +76,7 @@ impl ChildBySource for ItemScope { self.extern_crate_decls() .for_each(|ext| insert_item_loc(db, res, file_id, ext, keys::EXTERN_CRATE)); self.use_decls().for_each(|ext| insert_item_loc(db, res, file_id, ext, keys::USE)); - self.unnamed_consts(db) + self.unnamed_consts() .for_each(|konst| insert_item_loc(db, res, file_id, konst, keys::CONST)); self.attr_macro_invocs().filter(|(id, _)| id.file_id == file_id).for_each( |(ast_id, call_id)| { diff --git a/src/tools/rust-analyzer/crates/hir-def/src/data.rs b/src/tools/rust-analyzer/crates/hir-def/src/data.rs index d4c1db8b95b..b815c9b73ef 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/data.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/data.rs @@ -715,7 +715,7 @@ impl<'a> AssocItemCollector<'a> { } AssocItem::MacroCall(call) => { let file_id = self.expander.current_file_id(); - let MacroCall { ast_id, expand_to, call_site, ref path } = item_tree[call]; + let MacroCall { ast_id, expand_to, ctxt, ref path } = item_tree[call]; let module = self.expander.module.local_id; let resolver = |path| { @@ -734,7 +734,7 @@ impl<'a> AssocItemCollector<'a> { match macro_call_as_call_id( self.db.upcast(), &AstIdWithPath::new(file_id, ast_id, Clone::clone(path)), - call_site, + ctxt, expand_to, self.expander.module.krate(), resolver, @@ -745,6 +745,7 @@ impl<'a> AssocItemCollector<'a> { self.collect_macro_items(res, &|| hir_expand::MacroCallKind::FnLike { ast_id: InFile::new(file_id, ast_id), expand_to: hir_expand::ExpandTo::Items, + eager: None, }); } Ok(None) => (), @@ -754,6 +755,7 @@ impl<'a> AssocItemCollector<'a> { MacroCallKind::FnLike { ast_id: InFile::new(file_id, ast_id), expand_to, + eager: None, }, Clone::clone(path), )); diff --git a/src/tools/rust-analyzer/crates/hir-def/src/data/adt.rs b/src/tools/rust-analyzer/crates/hir-def/src/data/adt.rs index 5790e600f63..a7461b78af1 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/data/adt.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/data/adt.rs @@ -191,9 +191,9 @@ impl StructData { let krate = loc.container.krate; let item_tree = loc.id.item_tree(db); let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); - let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone(); + let cfg_options = db.crate_graph()[krate].cfg_options.clone(); - let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into()); + let attrs = item_tree.attrs(db, krate, ModItem::from(loc.id.value).into()); let mut flags = StructFlags::NO_FLAGS; if attrs.by_key("rustc_has_incoherent_inherent_impls").exists() { @@ -248,9 +248,9 @@ impl StructData { let krate = loc.container.krate; let item_tree = loc.id.item_tree(db); let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); - let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone(); + let cfg_options = db.crate_graph()[krate].cfg_options.clone(); - let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into()); + let attrs = item_tree.attrs(db, krate, ModItem::from(loc.id.value).into()); let mut flags = StructFlags::NO_FLAGS; if attrs.by_key("rustc_has_incoherent_inherent_impls").exists() { flags |= StructFlags::IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPL; diff --git a/src/tools/rust-analyzer/crates/hir-def/src/db.rs b/src/tools/rust-analyzer/crates/hir-def/src/db.rs index 544ed6bc347..30d52d87f19 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/db.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/db.rs @@ -309,13 +309,9 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId { kind: kind(loc.expander, loc.id.file_id(), makro.ast_id.upcast()), local_inner: false, allow_internal_unsafe: loc.allow_internal_unsafe, - span: db - .span_map(loc.id.file_id()) - .span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()), edition: loc.edition, } } - MacroId::MacroRulesId(it) => { let loc: MacroRulesLoc = it.lookup(db); @@ -328,9 +324,6 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId { allow_internal_unsafe: loc .flags .contains(MacroRulesLocFlags::ALLOW_INTERNAL_UNSAFE), - span: db - .span_map(loc.id.file_id()) - .span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()), edition: loc.edition, } } @@ -348,9 +341,6 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId { ), local_inner: false, allow_internal_unsafe: false, - span: db - .span_map(loc.id.file_id()) - .span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()), edition: loc.edition, } } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs index 0e6826a75a6..2b059d1f8dc 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs @@ -241,30 +241,8 @@ impl ItemScope { }) } - pub fn unnamed_consts<'a>( - &'a self, - db: &'a dyn DefDatabase, - ) -> impl Iterator<Item = ConstId> + 'a { - // FIXME: Also treat consts named `_DERIVE_*` as unnamed, since synstructure generates those. - // Should be removed once synstructure stops doing that. - let synstructure_hack_consts = self.values.values().filter_map(|(item, _, _)| match item { - &ModuleDefId::ConstId(id) => { - let loc = id.lookup(db); - let item_tree = loc.id.item_tree(db); - if item_tree[loc.id.value] - .name - .as_ref() - .map_or(false, |n| n.to_smol_str().starts_with("_DERIVE_")) - { - Some(id) - } else { - None - } - } - _ => None, - }); - - self.unnamed_consts.iter().copied().chain(synstructure_hack_consts) + pub fn unnamed_consts(&self) -> impl Iterator<Item = ConstId> + '_ { + self.unnamed_consts.iter().copied() } /// Iterate over all module scoped macros diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs index bd3d377ec08..585e93ce21e 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs @@ -49,7 +49,7 @@ use intern::Interned; use la_arena::{Arena, Idx, IdxRange, RawIdx}; use rustc_hash::FxHashMap; use smallvec::SmallVec; -use span::{AstIdNode, FileAstId, Span}; +use span::{AstIdNode, FileAstId, SyntaxContextId}; use stdx::never; use syntax::{ast, match_ast, SyntaxKind}; use triomphe::Arc; @@ -790,8 +790,7 @@ pub struct MacroCall { pub path: Interned<ModPath>, pub ast_id: FileAstId<ast::MacroCall>, pub expand_to: ExpandTo, - // FIXME: We need to move this out. It invalidates the item tree when typing inside the macro call. - pub call_site: Span, + pub ctxt: SyntaxContextId, } #[derive(Debug, Clone, Eq, PartialEq)] diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs index bf3d54f4caf..f02163cbe44 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs @@ -560,35 +560,32 @@ impl<'a> Ctx<'a> { fn lower_macro_call(&mut self, m: &ast::MacroCall) -> Option<FileItemTreeId<MacroCall>> { let span_map = self.span_map(); - let path = Interned::new(ModPath::from_src(self.db.upcast(), m.path()?, &mut |range| { + let path = m.path()?; + let range = path.syntax().text_range(); + let path = Interned::new(ModPath::from_src(self.db.upcast(), path, &mut |range| { span_map.span_for_range(range).ctx })?); let ast_id = self.source_ast_id_map.ast_id(m); let expand_to = hir_expand::ExpandTo::from_call_site(m); - let res = MacroCall { - path, - ast_id, - expand_to, - call_site: span_map.span_for_range(m.syntax().text_range()), - }; + let res = MacroCall { path, ast_id, expand_to, ctxt: span_map.span_for_range(range).ctx }; Some(id(self.data().macro_calls.alloc(res))) } fn lower_macro_rules(&mut self, m: &ast::MacroRules) -> Option<FileItemTreeId<MacroRules>> { - let name = m.name().map(|it| it.as_name())?; + let name = m.name()?; let ast_id = self.source_ast_id_map.ast_id(m); - let res = MacroRules { name, ast_id }; + let res = MacroRules { name: name.as_name(), ast_id }; Some(id(self.data().macro_rules.alloc(res))) } fn lower_macro_def(&mut self, m: &ast::MacroDef) -> Option<FileItemTreeId<Macro2>> { - let name = m.name().map(|it| it.as_name())?; + let name = m.name()?; let ast_id = self.source_ast_id_map.ast_id(m); let visibility = self.lower_visibility(m); - let res = Macro2 { name, ast_id, visibility }; + let res = Macro2 { name: name.as_name(), ast_id, visibility }; Some(id(self.data().macro_defs.alloc(res))) } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_tree/pretty.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_tree/pretty.rs index 87c90a4c6ab..953bf6b85d6 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/item_tree/pretty.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/item_tree/pretty.rs @@ -487,12 +487,12 @@ impl Printer<'_> { } } ModItem::MacroCall(it) => { - let MacroCall { path, ast_id, expand_to, call_site } = &self.tree[it]; + let MacroCall { path, ast_id, expand_to, ctxt } = &self.tree[it]; let _ = writeln!( self, - "// AstId: {:?}, Span: {}, ExpandTo: {:?}", + "// AstId: {:?}, SyntaxContext: {}, ExpandTo: {:?}", ast_id.erase().into_raw(), - call_site, + ctxt, expand_to ); wln!(self, "{}!(...);", path.display(self.db.upcast())); diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_tree/tests.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_tree/tests.rs index 26f7b41c77a..48da876ac15 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/item_tree/tests.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/item_tree/tests.rs @@ -278,7 +278,7 @@ m!(); // AstId: 2 pub macro m2 { ... } - // AstId: 3, Span: 0:3@0..5#0, ExpandTo: Items + // AstId: 3, SyntaxContext: 0, ExpandTo: Items m!(...); "#]], ); diff --git a/src/tools/rust-analyzer/crates/hir-def/src/lib.rs b/src/tools/rust-analyzer/crates/hir-def/src/lib.rs index d63f2268aa4..828842de7e8 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/lib.rs @@ -90,7 +90,7 @@ use hir_expand::{ use item_tree::ExternBlock; use la_arena::Idx; use nameres::DefMap; -use span::{AstIdNode, FileAstId, FileId, Span}; +use span::{AstIdNode, FileAstId, FileId, SyntaxContextId}; use stdx::impl_from; use syntax::{ast, AstNode}; @@ -1342,21 +1342,22 @@ impl AsMacroCall for InFile<&ast::MacroCall> { let ast_id = AstId::new(self.file_id, db.ast_id_map(self.file_id).ast_id(self.value)); let span_map = db.span_map(self.file_id); let path = self.value.path().and_then(|path| { - path::ModPath::from_src(db, path, &mut |range| { + let range = path.syntax().text_range(); + let mod_path = path::ModPath::from_src(db, path, &mut |range| { span_map.as_ref().span_for_range(range).ctx - }) + })?; + let call_site = span_map.span_for_range(range); + Some((call_site, mod_path)) }); - let Some(path) = path else { + let Some((call_site, path)) = path else { return Ok(ExpandResult::only_err(ExpandError::other("malformed macro invocation"))); }; - let call_site = span_map.span_for_range(self.value.syntax().text_range()); - macro_call_as_call_id_with_eager( db, &AstIdWithPath::new(ast_id.file_id, ast_id.value, path), - call_site, + call_site.ctx, expands_to, krate, resolver, @@ -1381,7 +1382,7 @@ impl<T: AstIdNode> AstIdWithPath<T> { fn macro_call_as_call_id( db: &dyn ExpandDatabase, call: &AstIdWithPath<ast::MacroCall>, - call_site: Span, + call_site: SyntaxContextId, expand_to: ExpandTo, krate: CrateId, resolver: impl Fn(path::ModPath) -> Option<MacroDefId> + Copy, @@ -1393,7 +1394,7 @@ fn macro_call_as_call_id( fn macro_call_as_call_id_with_eager( db: &dyn ExpandDatabase, call: &AstIdWithPath<ast::MacroCall>, - call_site: Span, + call_site: SyntaxContextId, expand_to: ExpandTo, krate: CrateId, resolver: impl FnOnce(path::ModPath) -> Option<MacroDefId>, @@ -1403,17 +1404,20 @@ fn macro_call_as_call_id_with_eager( resolver(call.path.clone()).ok_or_else(|| UnresolvedMacro { path: call.path.clone() })?; let res = match def.kind { - MacroDefKind::BuiltInEager(..) => { - let macro_call = InFile::new(call.ast_id.file_id, call.ast_id.to_node(db)); - expand_eager_macro_input(db, krate, macro_call, def, call_site, &|path| { - eager_resolver(path).filter(MacroDefId::is_fn_like) - }) - } + MacroDefKind::BuiltInEager(..) => expand_eager_macro_input( + db, + krate, + &call.ast_id.to_node(db), + call.ast_id, + def, + call_site, + &|path| eager_resolver(path).filter(MacroDefId::is_fn_like), + ), _ if def.is_fn_like() => ExpandResult { - value: Some(def.as_lazy_macro( + value: Some(def.make_call( db, krate, - MacroCallKind::FnLike { ast_id: call.ast_id, expand_to }, + MacroCallKind::FnLike { ast_id: call.ast_id, expand_to, eager: None }, call_site, )), err: None, diff --git a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs index 86b4466153a..89c1b446081 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs @@ -528,3 +528,121 @@ impl < > $crate::fmt::Debug for Command< > where { }"#]], ); } +#[test] +fn test_debug_expand_with_cfg() { + check( + r#" + //- minicore: derive, fmt + use core::fmt::Debug; + + #[derive(Debug)] + struct HideAndShow { + #[cfg(never)] + always_hide: u32, + #[cfg(not(never))] + always_show: u32, + } + #[derive(Debug)] + enum HideAndShowEnum { + #[cfg(never)] + AlwaysHide, + #[cfg(not(never))] + AlwaysShow{ + #[cfg(never)] + always_hide: u32, + #[cfg(not(never))] + always_show: u32, + } + } + "#, + expect![[r#" +use core::fmt::Debug; + +#[derive(Debug)] +struct HideAndShow { + #[cfg(never)] + always_hide: u32, + #[cfg(not(never))] + always_show: u32, +} +#[derive(Debug)] +enum HideAndShowEnum { + #[cfg(never)] + AlwaysHide, + #[cfg(not(never))] + AlwaysShow{ + #[cfg(never)] + always_hide: u32, + #[cfg(not(never))] + always_show: u32, + } +} + +impl < > $crate::fmt::Debug for HideAndShow< > where { + fn fmt(&self , f: &mut $crate::fmt::Formatter) -> $crate::fmt::Result { + match self { + HideAndShow { + always_show: always_show, + } + =>f.debug_struct("HideAndShow").field("always_show", &always_show).finish() + } + } +} +impl < > $crate::fmt::Debug for HideAndShowEnum< > where { + fn fmt(&self , f: &mut $crate::fmt::Formatter) -> $crate::fmt::Result { + match self { + HideAndShowEnum::AlwaysShow { + always_show: always_show, + } + =>f.debug_struct("AlwaysShow").field("always_show", &always_show).finish(), + } + } +}"#]], + ); +} +#[test] +fn test_default_expand_with_cfg() { + check( + r#" +//- minicore: derive, default +#[derive(Default)] +struct Foo { + field1: i32, + #[cfg(never)] + field2: (), +} +#[derive(Default)] +enum Bar { + Foo, + #[cfg_attr(not(never), default)] + Bar, +} +"#, + expect![[r#" +#[derive(Default)] +struct Foo { + field1: i32, + #[cfg(never)] + field2: (), +} +#[derive(Default)] +enum Bar { + Foo, + #[cfg_attr(not(never), default)] + Bar, +} + +impl < > $crate::default::Default for Foo< > where { + fn default() -> Self { + Foo { + field1: $crate::default::Default::default(), + } + } +} +impl < > $crate::default::Default for Bar< > where { + fn default() -> Self { + Bar::Bar + } +}"#]], + ); +} diff --git a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe.rs b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe.rs index edc8247f166..965f329acb9 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe.rs @@ -171,7 +171,7 @@ fn main(foo: ()) { } fn main(foo: ()) { - /* error: unresolved macro unresolved */"helloworld!"#0:3@207..323#2#; + /* error: unresolved macro unresolved */"helloworld!"#0:3@236..321#0#; } } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe/matching.rs b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe/matching.rs index 63f211022c9..23d8b023b8b 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe/matching.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe/matching.rs @@ -33,7 +33,7 @@ m!(&k"); "#, expect![[r#" macro_rules! m { ($i:literal) => {}; } -/* error: mismatched delimiters */"#]], +/* error: expected literal */"#]], ); } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe/tt_conversion.rs b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe/tt_conversion.rs index 362c189f6a7..fb5797d6e53 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe/tt_conversion.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe/tt_conversion.rs @@ -98,7 +98,7 @@ macro_rules! m1 { ($x:ident) => { ($x } } macro_rules! m2 { ($x:ident) => {} } /* error: macro definition has parse errors */ -/* error: mismatched delimiters */ +/* error: expected ident */ "#]], ) } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres.rs index 764617eafb7..b56dee3efb5 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres.rs @@ -61,15 +61,16 @@ use std::ops::Deref; use base_db::{CrateId, Edition, FileId}; use hir_expand::{ - name::Name, proc_macro::ProcMacroKind, HirFileId, InFile, MacroCallId, MacroDefId, + name::Name, proc_macro::ProcMacroKind, ErasedAstId, HirFileId, InFile, MacroCallId, MacroDefId, }; use itertools::Itertools; use la_arena::Arena; use rustc_hash::{FxHashMap, FxHashSet}; -use span::FileAstId; +use span::{FileAstId, ROOT_ERASED_FILE_AST_ID}; use stdx::format_to; use syntax::{ast, SmolStr}; use triomphe::Arc; +use tt::TextRange; use crate::{ db::DefDatabase, @@ -677,6 +678,25 @@ impl ModuleData { } } + pub fn definition_source_range(&self, db: &dyn DefDatabase) -> InFile<TextRange> { + match &self.origin { + &ModuleOrigin::File { definition, .. } | &ModuleOrigin::CrateRoot { definition } => { + InFile::new( + definition.into(), + ErasedAstId::new(definition.into(), ROOT_ERASED_FILE_AST_ID) + .to_range(db.upcast()), + ) + } + &ModuleOrigin::Inline { definition, definition_tree_id } => InFile::new( + definition_tree_id.file_id(), + AstId::new(definition_tree_id.file_id(), definition).to_range(db.upcast()), + ), + ModuleOrigin::BlockExpr { block, .. } => { + InFile::new(block.file_id, block.to_range(db.upcast())) + } + } + } + /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. /// `None` for the crate root or block. pub fn declaration_source(&self, db: &dyn DefDatabase) -> Option<InFile<ast::Module>> { @@ -684,6 +704,13 @@ impl ModuleData { let value = decl.to_node(db.upcast()); Some(InFile { file_id: decl.file_id, value }) } + + /// Returns the range which declares this module, either a `mod foo;` or a `mod foo {}`. + /// `None` for the crate root or block. + pub fn declaration_source_range(&self, db: &dyn DefDatabase) -> Option<InFile<TextRange>> { + let decl = self.origin.declaration()?; + Some(InFile { file_id: decl.file_id, value: decl.to_range(db.upcast()) }) + } } #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/attr_resolution.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/attr_resolution.rs index 1cadae8c87c..662c80edf32 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/attr_resolution.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/attr_resolution.rs @@ -5,7 +5,7 @@ use hir_expand::{ attrs::{Attr, AttrId, AttrInput}, MacroCallId, MacroCallKind, MacroDefId, }; -use span::Span; +use span::SyntaxContextId; use syntax::{ast, SmolStr}; use triomphe::Arc; @@ -109,14 +109,14 @@ pub(super) fn attr_macro_as_call_id( let arg = match macro_attr.input.as_deref() { Some(AttrInput::TokenTree(tt)) => { let mut tt = tt.as_ref().clone(); - tt.delimiter = tt::Delimiter::invisible_spanned(macro_attr.span); + tt.delimiter.kind = tt::DelimiterKind::Invisible; Some(tt) } _ => None, }; - def.as_lazy_macro( + def.make_call( db.upcast(), krate, MacroCallKind::Attr { @@ -124,7 +124,7 @@ pub(super) fn attr_macro_as_call_id( attr_args: arg.map(Arc::new), invoc_attr_index: macro_attr.id, }, - macro_attr.span, + macro_attr.ctxt, ) } @@ -133,14 +133,14 @@ pub(super) fn derive_macro_as_call_id( item_attr: &AstIdWithPath<ast::Adt>, derive_attr_index: AttrId, derive_pos: u32, - call_site: Span, + call_site: SyntaxContextId, krate: CrateId, resolver: impl Fn(path::ModPath) -> Option<(MacroId, MacroDefId)>, ) -> Result<(MacroId, MacroDefId, MacroCallId), UnresolvedMacro> { let (macro_id, def_id) = resolver(item_attr.path.clone()) .filter(|(_, def_id)| def_id.is_derive()) .ok_or_else(|| UnresolvedMacro { path: item_attr.path.clone() })?; - let call_id = def_id.as_lazy_macro( + let call_id = def_id.make_call( db.upcast(), krate, MacroCallKind::Derive { diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs index f9fe6d3b903..3d026447fb7 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs @@ -230,13 +230,13 @@ enum MacroDirectiveKind { FnLike { ast_id: AstIdWithPath<ast::MacroCall>, expand_to: ExpandTo, - call_site: Span, + ctxt: SyntaxContextId, }, Derive { ast_id: AstIdWithPath<ast::Adt>, derive_attr: AttrId, derive_pos: usize, - call_site: Span, + ctxt: SyntaxContextId, }, Attr { ast_id: AstIdWithPath<ast::Item>, @@ -1126,7 +1126,7 @@ impl DefCollector<'_> { let resolver_def_id = |path| resolver(path).map(|(_, it)| it); match &directive.kind { - MacroDirectiveKind::FnLike { ast_id, expand_to, call_site } => { + MacroDirectiveKind::FnLike { ast_id, expand_to, ctxt: call_site } => { let call_id = macro_call_as_call_id( self.db.upcast(), ast_id, @@ -1146,7 +1146,7 @@ impl DefCollector<'_> { return Resolved::Yes; } } - MacroDirectiveKind::Derive { ast_id, derive_attr, derive_pos, call_site } => { + MacroDirectiveKind::Derive { ast_id, derive_attr, derive_pos, ctxt: call_site } => { let id = derive_macro_as_call_id( self.db, ast_id, @@ -1266,7 +1266,7 @@ impl DefCollector<'_> { ast_id, derive_attr: attr.id, derive_pos: idx, - call_site, + ctxt: call_site.ctx, }, container: directive.container, }); @@ -1428,7 +1428,7 @@ impl DefCollector<'_> { for directive in &self.unresolved_macros { match &directive.kind { - MacroDirectiveKind::FnLike { ast_id, expand_to, call_site } => { + MacroDirectiveKind::FnLike { ast_id, expand_to, ctxt: call_site } => { // FIXME: we shouldn't need to re-resolve the macro here just to get the unresolved error! let macro_call_as_call_id = macro_call_as_call_id( self.db.upcast(), @@ -1451,12 +1451,16 @@ impl DefCollector<'_> { if let Err(UnresolvedMacro { path }) = macro_call_as_call_id { self.def_map.diagnostics.push(DefDiagnostic::unresolved_macro_call( directive.module_id, - MacroCallKind::FnLike { ast_id: ast_id.ast_id, expand_to: *expand_to }, + MacroCallKind::FnLike { + ast_id: ast_id.ast_id, + expand_to: *expand_to, + eager: None, + }, path, )); } } - MacroDirectiveKind::Derive { ast_id, derive_attr, derive_pos, call_site: _ } => { + MacroDirectiveKind::Derive { ast_id, derive_attr, derive_pos, ctxt: _ } => { self.def_map.diagnostics.push(DefDiagnostic::unresolved_macro_call( directive.module_id, MacroCallKind::Derive { @@ -2285,7 +2289,7 @@ impl ModCollector<'_, '_> { fn collect_macro_call( &mut self, - &MacroCall { ref path, ast_id, expand_to, call_site }: &MacroCall, + &MacroCall { ref path, ast_id, expand_to, ctxt }: &MacroCall, container: ItemContainerId, ) { let ast_id = AstIdWithPath::new(self.file_id(), ast_id, ModPath::clone(path)); @@ -2299,7 +2303,7 @@ impl ModCollector<'_, '_> { if let Ok(res) = macro_call_as_call_id_with_eager( db.upcast(), &ast_id, - call_site, + ctxt, expand_to, self.def_collector.def_map.krate, |path| { @@ -2357,7 +2361,7 @@ impl ModCollector<'_, '_> { self.def_collector.unresolved_macros.push(MacroDirective { module_id: self.module_id, depth: self.macro_depth + 1, - kind: MacroDirectiveKind::FnLike { ast_id, expand_to, call_site }, + kind: MacroDirectiveKind::FnLike { ast_id, expand_to, ctxt }, container, }); } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/incremental.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/incremental.rs index 6efced02718..be41634eb57 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/incremental.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/incremental.rs @@ -1,6 +1,5 @@ -use base_db::{SourceDatabase, SourceDatabaseExt}; +use base_db::{SourceDatabase, SourceDatabaseExt2 as _}; use test_fixture::WithFixture; -use triomphe::Arc; use crate::{db::DefDatabase, nameres::tests::TestDB, AdtId, ModuleDefId}; @@ -17,7 +16,7 @@ fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change: }); assert!(format!("{events:?}").contains("crate_def_map"), "{events:#?}") } - db.set_file_text(pos.file_id, Arc::from(ra_fixture_change)); + db.set_file_text(pos.file_id, ra_fixture_change); { let events = db.log_executed(|| { @@ -267,7 +266,7 @@ fn quux() { 92 } m!(Y); m!(Z); "#; - db.set_file_text(pos.file_id, Arc::from(new_text)); + db.set_file_text(pos.file_id, new_text); { let events = db.log_executed(|| { diff --git a/src/tools/rust-analyzer/crates/hir-def/src/src.rs b/src/tools/rust-analyzer/crates/hir-def/src/src.rs index 4283f003f89..2b1da8c34e1 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/src.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/src.rs @@ -3,7 +3,7 @@ use either::Either; use hir_expand::InFile; use la_arena::ArenaMap; -use syntax::ast; +use syntax::{ast, AstNode, AstPtr}; use crate::{ data::adt::lower_struct, db::DefDatabase, item_tree::ItemTreeNode, trace::Trace, GenericDefId, @@ -12,8 +12,12 @@ use crate::{ }; pub trait HasSource { - type Value; - fn source(&self, db: &dyn DefDatabase) -> InFile<Self::Value>; + type Value: AstNode; + fn source(&self, db: &dyn DefDatabase) -> InFile<Self::Value> { + let InFile { file_id, value } = self.ast_ptr(db); + InFile::new(file_id, value.to_node(&db.parse_or_expand(file_id))) + } + fn ast_ptr(&self, db: &dyn DefDatabase) -> InFile<AstPtr<Self::Value>>; } impl<T> HasSource for T @@ -22,16 +26,14 @@ where T::Id: ItemTreeNode, { type Value = <T::Id as ItemTreeNode>::Source; - - fn source(&self, db: &dyn DefDatabase) -> InFile<Self::Value> { + fn ast_ptr(&self, db: &dyn DefDatabase) -> InFile<AstPtr<Self::Value>> { let id = self.item_tree_id(); let file_id = id.file_id(); let tree = id.item_tree(db); let ast_id_map = db.ast_id_map(file_id); - let root = db.parse_or_expand(file_id); let node = &tree[id.value]; - InFile::new(file_id, ast_id_map.get(node.ast_id()).to_node(&root)) + InFile::new(file_id, ast_id_map.get(node.ast_id())) } } diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/attrs.rs b/src/tools/rust-analyzer/crates/hir-expand/src/attrs.rs index 7793e995323..af3ecdcd5e3 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/attrs.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/attrs.rs @@ -7,7 +7,7 @@ use either::Either; use intern::Interned; use mbe::{syntax_node_to_token_tree, DelimiterKind, Punct}; use smallvec::{smallvec, SmallVec}; -use span::Span; +use span::{Span, SyntaxContextId}; use syntax::{ast, match_ast, AstNode, AstToken, SmolStr, SyntaxNode}; use triomphe::Arc; @@ -53,7 +53,7 @@ impl RawAttrs { id, input: Some(Interned::new(AttrInput::Literal(SmolStr::new(doc)))), path: Interned::new(ModPath::from(crate::name!(doc))), - span: span_map.span_for_range(comment.syntax().text_range()), + ctxt: span_map.span_for_range(comment.syntax().text_range()).ctx, }), }); let entries: Arc<[Attr]> = Arc::from_iter(entries); @@ -173,7 +173,7 @@ pub struct Attr { pub id: AttrId, pub path: Interned<ModPath>, pub input: Option<Interned<AttrInput>>, - pub span: Span, + pub ctxt: SyntaxContextId, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -201,10 +201,12 @@ impl Attr { span_map: SpanMapRef<'_>, id: AttrId, ) -> Option<Attr> { - let path = Interned::new(ModPath::from_src(db, ast.path()?, &mut |range| { + let path = ast.path()?; + let range = path.syntax().text_range(); + let path = Interned::new(ModPath::from_src(db, path, &mut |range| { span_map.span_for_range(range).ctx })?); - let span = span_map.span_for_range(ast.syntax().text_range()); + let span = span_map.span_for_range(range); let input = if let Some(ast::Expr::Literal(lit)) = ast.expr() { let value = match lit.kind() { ast::LiteralKind::String(string) => string.value()?.into(), @@ -217,11 +219,11 @@ impl Attr { } else { None }; - Some(Attr { id, path, input, span }) + Some(Attr { id, path, input, ctxt: span.ctx }) } fn from_tt(db: &dyn ExpandDatabase, tt: &[tt::TokenTree], id: AttrId) -> Option<Attr> { - let span = tt.first()?.first_span(); + let ctxt = tt.first()?.first_span().ctx; let path_end = tt .iter() .position(|tt| { @@ -253,7 +255,7 @@ impl Attr { } _ => None, }; - Some(Attr { id, path, input, span }) + Some(Attr { id, path, input, ctxt }) } pub fn path(&self) -> &ModPath { diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/builtin_attr_macro.rs b/src/tools/rust-analyzer/crates/hir-expand/src/builtin_attr_macro.rs index a0102f36aff..9ff29b484d3 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/builtin_attr_macro.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/builtin_attr_macro.rs @@ -11,7 +11,7 @@ macro_rules! register_builtin { } impl BuiltinAttrExpander { - pub fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::Subtree) -> ExpandResult<tt::Subtree> { + pub fn expander(&self) -> fn (&dyn ExpandDatabase, MacroCallId, &tt::Subtree, Span) -> ExpandResult<tt::Subtree> { match *self { $( BuiltinAttrExpander::$variant => $expand, )* } @@ -34,8 +34,9 @@ impl BuiltinAttrExpander { db: &dyn ExpandDatabase, id: MacroCallId, tt: &tt::Subtree, + span: Span, ) -> ExpandResult<tt::Subtree> { - self.expander()(db, id, tt) + self.expander()(db, id, tt, span) } pub fn is_derive(self) -> bool { @@ -71,6 +72,7 @@ fn dummy_attr_expand( _db: &dyn ExpandDatabase, _id: MacroCallId, tt: &tt::Subtree, + _span: Span, ) -> ExpandResult<tt::Subtree> { ExpandResult::ok(tt.clone()) } @@ -100,6 +102,7 @@ fn derive_expand( db: &dyn ExpandDatabase, id: MacroCallId, tt: &tt::Subtree, + span: Span, ) -> ExpandResult<tt::Subtree> { let loc = db.lookup_intern_macro_call(id); let derives = match &loc.kind { @@ -107,17 +110,14 @@ fn derive_expand( attr_args } _ => { - return ExpandResult::ok(tt::Subtree::empty(tt::DelimSpan { - open: loc.call_site, - close: loc.call_site, - })) + return ExpandResult::ok(tt::Subtree::empty(tt::DelimSpan { open: span, close: span })) } }; - pseudo_derive_attr_expansion(tt, derives, loc.call_site) + pseudo_derive_attr_expansion(tt, derives, span) } pub fn pseudo_derive_attr_expansion( - tt: &tt::Subtree, + _: &tt::Subtree, args: &tt::Subtree, call_site: Span, ) -> ExpandResult<tt::Subtree> { @@ -141,7 +141,7 @@ pub fn pseudo_derive_attr_expansion( token_trees.push(mk_leaf(']')); } ExpandResult::ok(tt::Subtree { - delimiter: tt.delimiter, + delimiter: args.delimiter, token_trees: token_trees.into_boxed_slice(), }) } diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/builtin_derive_macro.rs b/src/tools/rust-analyzer/crates/hir-expand/src/builtin_derive_macro.rs index 66dec7d89e5..528038a9ccf 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/builtin_derive_macro.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/builtin_derive_macro.rs @@ -50,8 +50,8 @@ impl BuiltinDeriveExpander { db: &dyn ExpandDatabase, id: MacroCallId, tt: &tt::Subtree, + span: Span, ) -> ExpandResult<tt::Subtree> { - let span = db.lookup_intern_macro_call(id).call_site; let span = span_with_def_site_ctxt(db, span, id); self.expander()(span, tt) } diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/builtin_fn_macro.rs b/src/tools/rust-analyzer/crates/hir-expand/src/builtin_fn_macro.rs index 0fd0c25dcce..9fb6a0b2346 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/builtin_fn_macro.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/builtin_fn_macro.rs @@ -19,14 +19,14 @@ use crate::{ }; macro_rules! register_builtin { - ( LAZY: $(($name:ident, $kind: ident) => $expand:ident),* , EAGER: $(($e_name:ident, $e_kind: ident) => $e_expand:ident),* ) => { + ( $LAZY:ident: $(($name:ident, $kind: ident) => $expand:ident),* , $EAGER:ident: $(($e_name:ident, $e_kind: ident) => $e_expand:ident),* ) => { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] - pub enum BuiltinFnLikeExpander { + pub enum $LAZY { $($kind),* } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] - pub enum EagerExpander { + pub enum $EAGER { $($e_kind),* } @@ -62,8 +62,8 @@ impl BuiltinFnLikeExpander { db: &dyn ExpandDatabase, id: MacroCallId, tt: &tt::Subtree, + span: Span, ) -> ExpandResult<tt::Subtree> { - let span = db.lookup_intern_macro_call(id).call_site; let span = span_with_def_site_ctxt(db, span, id); self.expander()(db, id, tt, span) } @@ -75,8 +75,8 @@ impl EagerExpander { db: &dyn ExpandDatabase, id: MacroCallId, tt: &tt::Subtree, + span: Span, ) -> ExpandResult<tt::Subtree> { - let span = db.lookup_intern_macro_call(id).call_site; let span = span_with_def_site_ctxt(db, span, id); self.expander()(db, id, tt, span) } @@ -84,6 +84,17 @@ impl EagerExpander { pub fn is_include(&self) -> bool { matches!(self, EagerExpander::Include) } + + pub fn is_include_like(&self) -> bool { + matches!( + self, + EagerExpander::Include | EagerExpander::IncludeStr | EagerExpander::IncludeBytes + ) + } + + pub fn is_env_or_option_env(&self) -> bool { + matches!(self, EagerExpander::Env | EagerExpander::OptionEnv) + } } pub fn find_builtin_macro( @@ -93,7 +104,7 @@ pub fn find_builtin_macro( } register_builtin! { - LAZY: + BuiltinFnLikeExpander: (column, Column) => line_expand, (file, File) => file_expand, (line, Line) => line_expand, @@ -114,7 +125,7 @@ register_builtin! { (format_args_nl, FormatArgsNl) => format_args_nl_expand, (quote, Quote) => quote_expand, - EAGER: + EagerExpander: (compile_error, CompileError) => compile_error_expand, (concat, Concat) => concat_expand, (concat_idents, ConcatIdents) => concat_idents_expand, @@ -426,22 +437,25 @@ fn use_panic_2021(db: &dyn ExpandDatabase, span: Span) -> bool { } } -fn unquote_str(lit: &tt::Literal) -> Option<String> { +fn unquote_str(lit: &tt::Literal) -> Option<(String, Span)> { + let span = lit.span; let lit = ast::make::tokens::literal(&lit.to_string()); let token = ast::String::cast(lit)?; - token.value().map(|it| it.into_owned()) + token.value().map(|it| (it.into_owned(), span)) } -fn unquote_char(lit: &tt::Literal) -> Option<char> { +fn unquote_char(lit: &tt::Literal) -> Option<(char, Span)> { + let span = lit.span; let lit = ast::make::tokens::literal(&lit.to_string()); let token = ast::Char::cast(lit)?; - token.value() + token.value().zip(Some(span)) } -fn unquote_byte_string(lit: &tt::Literal) -> Option<Vec<u8>> { +fn unquote_byte_string(lit: &tt::Literal) -> Option<(Vec<u8>, Span)> { + let span = lit.span; let lit = ast::make::tokens::literal(&lit.to_string()); let token = ast::ByteString::cast(lit)?; - token.value().map(|it| it.into_owned()) + token.value().map(|it| (it.into_owned(), span)) } fn compile_error_expand( @@ -452,7 +466,7 @@ fn compile_error_expand( ) -> ExpandResult<tt::Subtree> { let err = match &*tt.token_trees { [tt::TokenTree::Leaf(tt::Leaf::Literal(it))] => match unquote_str(it) { - Some(unquoted) => ExpandError::other(unquoted.into_boxed_str()), + Some((unquoted, _)) => ExpandError::other(unquoted.into_boxed_str()), None => ExpandError::other("`compile_error!` argument must be a string"), }, _ => ExpandError::other("`compile_error!` argument must be a string"), @@ -465,10 +479,16 @@ fn concat_expand( _db: &dyn ExpandDatabase, _arg_id: MacroCallId, tt: &tt::Subtree, - span: Span, + _: Span, ) -> ExpandResult<tt::Subtree> { let mut err = None; let mut text = String::new(); + let mut span: Option<Span> = None; + let mut record_span = |s: Span| match &mut span { + Some(span) if span.anchor == s.anchor => span.range = span.range.cover(s.range), + Some(_) => (), + None => span = Some(s), + }; for (i, mut t) in tt.token_trees.iter().enumerate() { // FIXME: hack on top of a hack: `$e:expr` captures get surrounded in parentheses // to ensure the right parsing order, so skip the parentheses here. Ideally we'd @@ -486,11 +506,14 @@ fn concat_expand( // concat works with string and char literals, so remove any quotes. // It also works with integer, float and boolean literals, so just use the rest // as-is. - if let Some(c) = unquote_char(it) { + if let Some((c, span)) = unquote_char(it) { text.push(c); + record_span(span); } else { - let component = unquote_str(it).unwrap_or_else(|| it.text.to_string()); + let (component, span) = + unquote_str(it).unwrap_or_else(|| (it.text.to_string(), it.span)); text.push_str(&component); + record_span(span); } } // handle boolean literals @@ -498,6 +521,7 @@ fn concat_expand( if i % 2 == 0 && (id.text == "true" || id.text == "false") => { text.push_str(id.text.as_str()); + record_span(id.span); } tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) if i % 2 == 1 && punct.char == ',' => (), _ => { @@ -505,6 +529,7 @@ fn concat_expand( } } } + let span = span.unwrap_or(tt.delimiter.open); ExpandResult { value: quote!(span =>#text), err } } @@ -512,18 +537,25 @@ fn concat_bytes_expand( _db: &dyn ExpandDatabase, _arg_id: MacroCallId, tt: &tt::Subtree, - span: Span, + call_site: Span, ) -> ExpandResult<tt::Subtree> { let mut bytes = Vec::new(); let mut err = None; + let mut span: Option<Span> = None; + let mut record_span = |s: Span| match &mut span { + Some(span) if span.anchor == s.anchor => span.range = span.range.cover(s.range), + Some(_) => (), + None => span = Some(s), + }; for (i, t) in tt.token_trees.iter().enumerate() { match t { tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) => { let token = ast::make::tokens::literal(&lit.to_string()); + record_span(lit.span); match token.kind() { syntax::SyntaxKind::BYTE => bytes.push(token.text().to_owned()), syntax::SyntaxKind::BYTE_STRING => { - let components = unquote_byte_string(lit).unwrap_or_default(); + let components = unquote_byte_string(lit).map_or(vec![], |(it, _)| it); components.into_iter().for_each(|it| bytes.push(it.to_string())); } _ => { @@ -534,7 +566,7 @@ fn concat_bytes_expand( } tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) if i % 2 == 1 && punct.char == ',' => (), tt::TokenTree::Subtree(tree) if tree.delimiter.kind == tt::DelimiterKind::Bracket => { - if let Err(e) = concat_bytes_expand_subtree(tree, &mut bytes) { + if let Err(e) = concat_bytes_expand_subtree(tree, &mut bytes, &mut record_span) { err.get_or_insert(e); break; } @@ -546,17 +578,24 @@ fn concat_bytes_expand( } } let value = tt::Subtree { - delimiter: tt::Delimiter { open: span, close: span, kind: tt::DelimiterKind::Bracket }, + delimiter: tt::Delimiter { + open: call_site, + close: call_site, + kind: tt::DelimiterKind::Bracket, + }, token_trees: { Itertools::intersperse_with( bytes.into_iter().map(|it| { - tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal { text: it.into(), span })) + tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal { + text: it.into(), + span: span.unwrap_or(call_site), + })) }), || { tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: ',', spacing: tt::Spacing::Alone, - span, + span: call_site, })) }, ) @@ -569,13 +608,15 @@ fn concat_bytes_expand( fn concat_bytes_expand_subtree( tree: &tt::Subtree, bytes: &mut Vec<String>, + mut record_span: impl FnMut(Span), ) -> Result<(), ExpandError> { for (ti, tt) in tree.token_trees.iter().enumerate() { match tt { - tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) => { - let lit = ast::make::tokens::literal(&lit.to_string()); + tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => { + let lit = ast::make::tokens::literal(&it.to_string()); match lit.kind() { syntax::SyntaxKind::BYTE | syntax::SyntaxKind::INT_NUMBER => { + record_span(it.span); bytes.push(lit.text().to_owned()) } _ => { @@ -635,7 +676,7 @@ fn relative_file( } } -fn parse_string(tt: &tt::Subtree) -> Result<String, ExpandError> { +fn parse_string(tt: &tt::Subtree) -> Result<(String, Span), ExpandError> { tt.token_trees .first() .and_then(|tt| match tt { @@ -675,7 +716,7 @@ pub fn include_input_to_file_id( arg_id: MacroCallId, arg: &tt::Subtree, ) -> Result<FileId, ExpandError> { - relative_file(db, arg_id, &parse_string(arg)?, false) + relative_file(db, arg_id, &parse_string(arg)?.0, false) } fn include_bytes_expand( @@ -701,7 +742,7 @@ fn include_str_expand( tt: &tt::Subtree, span: Span, ) -> ExpandResult<tt::Subtree> { - let path = match parse_string(tt) { + let (path, span) = match parse_string(tt) { Ok(it) => it, Err(e) => { return ExpandResult::new(tt::Subtree::empty(DelimSpan { open: span, close: span }), e) @@ -736,7 +777,7 @@ fn env_expand( tt: &tt::Subtree, span: Span, ) -> ExpandResult<tt::Subtree> { - let key = match parse_string(tt) { + let (key, span) = match parse_string(tt) { Ok(it) => it, Err(e) => { return ExpandResult::new(tt::Subtree::empty(DelimSpan { open: span, close: span }), e) @@ -766,18 +807,24 @@ fn option_env_expand( db: &dyn ExpandDatabase, arg_id: MacroCallId, tt: &tt::Subtree, - span: Span, + call_site: Span, ) -> ExpandResult<tt::Subtree> { - let key = match parse_string(tt) { + let (key, span) = match parse_string(tt) { Ok(it) => it, Err(e) => { - return ExpandResult::new(tt::Subtree::empty(DelimSpan { open: span, close: span }), e) + return ExpandResult::new( + tt::Subtree::empty(DelimSpan { open: call_site, close: call_site }), + e, + ) } }; - let dollar_crate = dollar_crate(span); + let dollar_crate = dollar_crate(call_site); let expanded = match get_env_inner(db, arg_id, &key) { - None => quote! {span => #dollar_crate::option::Option::None::<&str> }, - Some(s) => quote! {span => #dollar_crate::option::Option::Some(#s) }, + None => quote! {call_site => #dollar_crate::option::Option::None::<&str> }, + Some(s) => { + let s = quote! (span => #s); + quote! {call_site => #dollar_crate::option::Option::Some(#s) } + } }; ExpandResult::ok(expanded) diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/cfg_process.rs b/src/tools/rust-analyzer/crates/hir-expand/src/cfg_process.rs new file mode 100644 index 00000000000..c74c13a6fd3 --- /dev/null +++ b/src/tools/rust-analyzer/crates/hir-expand/src/cfg_process.rs @@ -0,0 +1,327 @@ +//! Processes out #[cfg] and #[cfg_attr] attributes from the input for the derive macro +use std::iter::Peekable; + +use cfg::{CfgAtom, CfgExpr}; +use rustc_hash::FxHashSet; +use syntax::{ + ast::{self, Attr, HasAttrs, Meta, VariantList}, + AstNode, NodeOrToken, SyntaxElement, SyntaxNode, T, +}; +use tracing::{debug, warn}; +use tt::SmolStr; + +use crate::{db::ExpandDatabase, MacroCallKind, MacroCallLoc}; + +fn check_cfg_attr(attr: &Attr, loc: &MacroCallLoc, db: &dyn ExpandDatabase) -> Option<bool> { + if !attr.simple_name().as_deref().map(|v| v == "cfg")? { + return None; + } + debug!("Evaluating cfg {}", attr); + let cfg = parse_from_attr_meta(attr.meta()?)?; + debug!("Checking cfg {:?}", cfg); + let enabled = db.crate_graph()[loc.krate].cfg_options.check(&cfg) != Some(false); + Some(enabled) +} + +fn check_cfg_attr_attr(attr: &Attr, loc: &MacroCallLoc, db: &dyn ExpandDatabase) -> Option<bool> { + if !attr.simple_name().as_deref().map(|v| v == "cfg_attr")? { + return None; + } + debug!("Evaluating cfg_attr {}", attr); + let cfg_expr = parse_from_attr_meta(attr.meta()?)?; + debug!("Checking cfg_attr {:?}", cfg_expr); + let enabled = db.crate_graph()[loc.krate].cfg_options.check(&cfg_expr) != Some(false); + Some(enabled) +} + +fn process_has_attrs_with_possible_comma<I: HasAttrs>( + items: impl Iterator<Item = I>, + loc: &MacroCallLoc, + db: &dyn ExpandDatabase, + remove: &mut FxHashSet<SyntaxElement>, +) -> Option<()> { + for item in items { + let field_attrs = item.attrs(); + 'attrs: for attr in field_attrs { + if check_cfg_attr(&attr, loc, db).map(|enabled| !enabled).unwrap_or_default() { + debug!("censoring type {:?}", item.syntax()); + remove.insert(item.syntax().clone().into()); + // We need to remove the , as well + remove_possible_comma(&item, remove); + break 'attrs; + } + + if let Some(enabled) = check_cfg_attr_attr(&attr, loc, db) { + if enabled { + debug!("Removing cfg_attr tokens {:?}", attr); + let meta = attr.meta()?; + let removes_from_cfg_attr = remove_tokens_within_cfg_attr(meta)?; + remove.extend(removes_from_cfg_attr); + } else { + debug!("censoring type cfg_attr {:?}", item.syntax()); + remove.insert(attr.syntax().clone().into()); + continue; + } + } + } + } + Some(()) +} +#[derive(Debug, PartialEq, Eq, Clone, Copy)] +enum CfgExprStage { + /// Stripping the CFGExpr part of the attribute + StrippigCfgExpr, + /// Found the comma after the CFGExpr. Will keep all tokens until the next comma or the end of the attribute + FoundComma, + /// Everything following the attribute. This could be another attribute or the end of the attribute. + // FIXME: cfg_attr with multiple attributes will not be handled correctly. We will only keep the first attribute + // Related Issue: https://github.com/rust-lang/rust-analyzer/issues/10110 + EverythingElse, +} +/// This function creates its own set of tokens to remove. To help prevent malformed syntax as input. +fn remove_tokens_within_cfg_attr(meta: Meta) -> Option<FxHashSet<SyntaxElement>> { + let mut remove: FxHashSet<SyntaxElement> = FxHashSet::default(); + debug!("Enabling attribute {}", meta); + let meta_path = meta.path()?; + debug!("Removing {:?}", meta_path.syntax()); + remove.insert(meta_path.syntax().clone().into()); + + let meta_tt = meta.token_tree()?; + debug!("meta_tt {}", meta_tt); + let mut stage = CfgExprStage::StrippigCfgExpr; + for tt in meta_tt.token_trees_and_tokens() { + debug!("Checking {:?}. Stage: {:?}", tt, stage); + match (stage, tt) { + (CfgExprStage::StrippigCfgExpr, syntax::NodeOrToken::Node(node)) => { + remove.insert(node.syntax().clone().into()); + } + (CfgExprStage::StrippigCfgExpr, syntax::NodeOrToken::Token(token)) => { + if token.kind() == T![,] { + stage = CfgExprStage::FoundComma; + } + remove.insert(token.into()); + } + (CfgExprStage::FoundComma, syntax::NodeOrToken::Token(token)) + if (token.kind() == T![,] || token.kind() == T![')']) => + { + // The end of the attribute or separator for the next attribute + stage = CfgExprStage::EverythingElse; + remove.insert(token.into()); + } + (CfgExprStage::EverythingElse, syntax::NodeOrToken::Node(node)) => { + remove.insert(node.syntax().clone().into()); + } + (CfgExprStage::EverythingElse, syntax::NodeOrToken::Token(token)) => { + remove.insert(token.into()); + } + // This is an actual attribute + _ => {} + } + } + if stage != CfgExprStage::EverythingElse { + warn!("Invalid cfg_attr attribute. {:?}", meta_tt); + return None; + } + Some(remove) +} +/// Removes a possible comma after the [AstNode] +fn remove_possible_comma(item: &impl AstNode, res: &mut FxHashSet<SyntaxElement>) { + if let Some(comma) = item.syntax().next_sibling_or_token().filter(|it| it.kind() == T![,]) { + res.insert(comma); + } +} +fn process_enum( + variants: VariantList, + loc: &MacroCallLoc, + db: &dyn ExpandDatabase, + remove: &mut FxHashSet<SyntaxElement>, +) -> Option<()> { + 'variant: for variant in variants.variants() { + for attr in variant.attrs() { + if check_cfg_attr(&attr, loc, db).map(|enabled| !enabled).unwrap_or_default() { + // Rustc does not strip the attribute if it is enabled. So we will will leave it + debug!("censoring type {:?}", variant.syntax()); + remove.insert(variant.syntax().clone().into()); + // We need to remove the , as well + remove_possible_comma(&variant, remove); + continue 'variant; + }; + + if let Some(enabled) = check_cfg_attr_attr(&attr, loc, db) { + if enabled { + debug!("Removing cfg_attr tokens {:?}", attr); + let meta = attr.meta()?; + let removes_from_cfg_attr = remove_tokens_within_cfg_attr(meta)?; + remove.extend(removes_from_cfg_attr); + } else { + debug!("censoring type cfg_attr {:?}", variant.syntax()); + remove.insert(attr.syntax().clone().into()); + continue; + } + } + } + if let Some(fields) = variant.field_list() { + match fields { + ast::FieldList::RecordFieldList(fields) => { + process_has_attrs_with_possible_comma(fields.fields(), loc, db, remove)?; + } + ast::FieldList::TupleFieldList(fields) => { + process_has_attrs_with_possible_comma(fields.fields(), loc, db, remove)?; + } + } + } + } + Some(()) +} + +pub(crate) fn process_cfg_attrs( + node: &SyntaxNode, + loc: &MacroCallLoc, + db: &dyn ExpandDatabase, +) -> Option<FxHashSet<SyntaxElement>> { + // FIXME: #[cfg_eval] is not implemented. But it is not stable yet + if !matches!(loc.kind, MacroCallKind::Derive { .. }) { + return None; + } + let mut remove = FxHashSet::default(); + + let item = ast::Item::cast(node.clone())?; + for attr in item.attrs() { + if let Some(enabled) = check_cfg_attr_attr(&attr, loc, db) { + if enabled { + debug!("Removing cfg_attr tokens {:?}", attr); + let meta = attr.meta()?; + let removes_from_cfg_attr = remove_tokens_within_cfg_attr(meta)?; + remove.extend(removes_from_cfg_attr); + } else { + debug!("censoring type cfg_attr {:?}", item.syntax()); + remove.insert(attr.syntax().clone().into()); + continue; + } + } + } + match item { + ast::Item::Struct(it) => match it.field_list()? { + ast::FieldList::RecordFieldList(fields) => { + process_has_attrs_with_possible_comma(fields.fields(), loc, db, &mut remove)?; + } + ast::FieldList::TupleFieldList(fields) => { + process_has_attrs_with_possible_comma(fields.fields(), loc, db, &mut remove)?; + } + }, + ast::Item::Enum(it) => { + process_enum(it.variant_list()?, loc, db, &mut remove)?; + } + ast::Item::Union(it) => { + process_has_attrs_with_possible_comma( + it.record_field_list()?.fields(), + loc, + db, + &mut remove, + )?; + } + // FIXME: Implement for other items if necessary. As we do not support #[cfg_eval] yet, we do not need to implement it for now + _ => {} + } + Some(remove) +} +/// Parses a `cfg` attribute from the meta +fn parse_from_attr_meta(meta: Meta) -> Option<CfgExpr> { + let tt = meta.token_tree()?; + let mut iter = tt.token_trees_and_tokens().skip(1).peekable(); + next_cfg_expr_from_syntax(&mut iter) +} + +fn next_cfg_expr_from_syntax<I>(iter: &mut Peekable<I>) -> Option<CfgExpr> +where + I: Iterator<Item = NodeOrToken<ast::TokenTree, syntax::SyntaxToken>>, +{ + let name = match iter.next() { + None => return None, + Some(NodeOrToken::Token(element)) => match element.kind() { + syntax::T![ident] => SmolStr::new(element.text()), + _ => return Some(CfgExpr::Invalid), + }, + Some(_) => return Some(CfgExpr::Invalid), + }; + let result = match name.as_str() { + "all" | "any" | "not" => { + let mut preds = Vec::new(); + let Some(NodeOrToken::Node(tree)) = iter.next() else { + return Some(CfgExpr::Invalid); + }; + let mut tree_iter = tree.token_trees_and_tokens().skip(1).peekable(); + while tree_iter + .peek() + .filter( + |element| matches!(element, NodeOrToken::Token(token) if (token.kind() != syntax::T![')'])), + ) + .is_some() + { + let pred = next_cfg_expr_from_syntax(&mut tree_iter); + if let Some(pred) = pred { + preds.push(pred); + } + } + let group = match name.as_str() { + "all" => CfgExpr::All(preds), + "any" => CfgExpr::Any(preds), + "not" => CfgExpr::Not(Box::new(preds.pop().unwrap_or(CfgExpr::Invalid))), + _ => unreachable!(), + }; + Some(group) + } + _ => match iter.peek() { + Some(NodeOrToken::Token(element)) if (element.kind() == syntax::T![=]) => { + iter.next(); + match iter.next() { + Some(NodeOrToken::Token(value_token)) + if (value_token.kind() == syntax::SyntaxKind::STRING) => + { + let value = value_token.text(); + let value = SmolStr::new(value.trim_matches('"')); + Some(CfgExpr::Atom(CfgAtom::KeyValue { key: name, value })) + } + _ => None, + } + } + _ => Some(CfgExpr::Atom(CfgAtom::Flag(name))), + }, + }; + if let Some(NodeOrToken::Token(element)) = iter.peek() { + if element.kind() == syntax::T![,] { + iter.next(); + } + } + result +} +#[cfg(test)] +mod tests { + use cfg::DnfExpr; + use expect_test::{expect, Expect}; + use syntax::{ast::Attr, AstNode, SourceFile}; + + use crate::cfg_process::parse_from_attr_meta; + + fn check_dnf_from_syntax(input: &str, expect: Expect) { + let parse = SourceFile::parse(input); + let node = match parse.tree().syntax().descendants().find_map(Attr::cast) { + Some(it) => it, + None => { + let node = std::any::type_name::<Attr>(); + panic!("Failed to make ast node `{node}` from text {input}") + } + }; + let node = node.clone_subtree(); + assert_eq!(node.syntax().text_range().start(), 0.into()); + + let cfg = parse_from_attr_meta(node.meta().unwrap()).unwrap(); + let actual = format!("#![cfg({})]", DnfExpr::new(cfg)); + expect.assert_eq(&actual); + } + #[test] + fn cfg_from_attr() { + check_dnf_from_syntax(r#"#[cfg(test)]"#, expect![[r#"#![cfg(test)]"#]]); + check_dnf_from_syntax(r#"#[cfg(not(never))]"#, expect![[r#"#![cfg(not(never))]"#]]); + } +} diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/change.rs b/src/tools/rust-analyzer/crates/hir-expand/src/change.rs index 8b9e5a59df8..1a3dd0e7ddb 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/change.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/change.rs @@ -48,7 +48,7 @@ impl ChangeWithProcMacros { } } - pub fn change_file(&mut self, file_id: FileId, new_text: Option<Arc<str>>) { + pub fn change_file(&mut self, file_id: FileId, new_text: Option<String>) { self.source_change.change_file(file_id, new_text) } diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/db.rs b/src/tools/rust-analyzer/crates/hir-expand/src/db.rs index 6f69ee15aca..ec68f2f96e5 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/db.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/db.rs @@ -3,21 +3,19 @@ use base_db::{salsa, CrateId, FileId, SourceDatabase}; use either::Either; use limit::Limit; -use mbe::{syntax_node_to_token_tree, ValueResult}; +use mbe::syntax_node_to_token_tree; use rustc_hash::FxHashSet; -use span::{AstIdMap, SyntaxContextData, SyntaxContextId}; -use syntax::{ - ast::{self, HasAttrs}, - AstNode, Parse, SyntaxError, SyntaxNode, SyntaxToken, T, -}; +use span::{AstIdMap, Span, SyntaxContextData, SyntaxContextId}; +use syntax::{ast, AstNode, Parse, SyntaxElement, SyntaxError, SyntaxNode, SyntaxToken, T}; use triomphe::Arc; use crate::{ - attrs::collect_attrs, + attrs::{collect_attrs, AttrId}, builtin_attr_macro::pseudo_derive_attr_expansion, builtin_fn_macro::EagerExpander, + cfg_process, declarative::DeclarativeMacroExpander, - fixup::{self, reverse_fixups, SyntaxFixupUndoInfo}, + fixup::{self, SyntaxFixupUndoInfo}, hygiene::{span_with_call_site_ctxt, span_with_def_site_ctxt, span_with_mixed_site_ctxt}, proc_macro::ProcMacros, span_map::{RealSpanMap, SpanMap, SpanMapRef}, @@ -100,10 +98,7 @@ pub trait ExpandDatabase: SourceDatabase { /// Lowers syntactic macro call to a token tree representation. That's a firewall /// query, only typing in the macro call itself changes the returned /// subtree. - fn macro_arg( - &self, - id: MacroCallId, - ) -> ValueResult<(Arc<tt::Subtree>, SyntaxFixupUndoInfo), Arc<Box<[SyntaxError]>>>; + fn macro_arg(&self, id: MacroCallId) -> (Arc<tt::Subtree>, SyntaxFixupUndoInfo, Span); /// Fetches the expander for this macro. #[salsa::transparent] #[salsa::invoke(TokenExpander::macro_expander)] @@ -120,6 +115,12 @@ pub trait ExpandDatabase: SourceDatabase { /// non-determinism breaks salsa in a very, very, very bad way. /// @edwin0cheng heroically debugged this once! See #4315 for details fn expand_proc_macro(&self, call: MacroCallId) -> ExpandResult<Arc<tt::Subtree>>; + /// Retrieves the span to be used for a proc-macro expansions spans. + /// This is a firewall query as it requires parsing the file, which we don't want proc-macros to + /// directly depend on as that would cause to frequent invalidations, mainly because of the + /// parse queries being LRU cached. If they weren't the invalidations would only happen if the + /// user wrote in the file that defines the proc-macro. + fn proc_macro_span(&self, fun: AstId<ast::Fn>) -> Span; /// Firewall query that returns the errors from the `parse_macro_expansion` query. fn parse_macro_expansion_error( &self, @@ -139,30 +140,50 @@ pub fn expand_speculative( ) -> Option<(SyntaxNode, SyntaxToken)> { let loc = db.lookup_intern_macro_call(actual_macro_call); + // FIXME: This BOGUS here is dangerous once the proc-macro server can call back into the database! let span_map = RealSpanMap::absolute(FileId::BOGUS); let span_map = SpanMapRef::RealSpanMap(&span_map); + let (_, _, span) = db.macro_arg(actual_macro_call); + // Build the subtree and token mapping for the speculative args let (mut tt, undo_info) = match loc.kind { MacroCallKind::FnLike { .. } => ( - mbe::syntax_node_to_token_tree(speculative_args, span_map, loc.call_site), + mbe::syntax_node_to_token_tree(speculative_args, span_map, span), + SyntaxFixupUndoInfo::NONE, + ), + MacroCallKind::Attr { .. } if loc.def.is_attribute_derive() => ( + mbe::syntax_node_to_token_tree(speculative_args, span_map, span), SyntaxFixupUndoInfo::NONE, ), - MacroCallKind::Derive { .. } | MacroCallKind::Attr { .. } => { - let censor = censor_for_macro_input(&loc, speculative_args); - let mut fixups = fixup::fixup_syntax(span_map, speculative_args, loc.call_site); + MacroCallKind::Derive { derive_attr_index: index, .. } + | MacroCallKind::Attr { invoc_attr_index: index, .. } => { + let censor = if let MacroCallKind::Derive { .. } = loc.kind { + censor_derive_input(index, &ast::Adt::cast(speculative_args.clone())?) + } else { + attr_source(index, &ast::Item::cast(speculative_args.clone())?) + .into_iter() + .map(|it| it.syntax().clone().into()) + .collect() + }; + + let censor_cfg = + cfg_process::process_cfg_attrs(speculative_args, &loc, db).unwrap_or_default(); + let mut fixups = fixup::fixup_syntax(span_map, speculative_args, span); fixups.append.retain(|it, _| match it { - syntax::NodeOrToken::Node(it) => !censor.contains(it), syntax::NodeOrToken::Token(_) => true, + it => !censor.contains(it) && !censor_cfg.contains(it), }); fixups.remove.extend(censor); + fixups.remove.extend(censor_cfg); + ( mbe::syntax_node_to_token_tree_modified( speculative_args, span_map, fixups.append, fixups.remove, - loc.call_site, + span, ), fixups.undo_info, ) @@ -184,9 +205,8 @@ pub fn expand_speculative( }?; match attr.token_tree() { Some(token_tree) => { - let mut tree = - syntax_node_to_token_tree(token_tree.syntax(), span_map, loc.call_site); - tree.delimiter = tt::Delimiter::invisible_spanned(loc.call_site); + let mut tree = syntax_node_to_token_tree(token_tree.syntax(), span_map, span); + tree.delimiter = tt::Delimiter::invisible_spanned(span); Some(tree) } @@ -199,36 +219,36 @@ pub fn expand_speculative( // Do the actual expansion, we need to directly expand the proc macro due to the attribute args // Otherwise the expand query will fetch the non speculative attribute args and pass those instead. let mut speculative_expansion = match loc.def.kind { - MacroDefKind::ProcMacro(expander, ..) => { - tt.delimiter = tt::Delimiter::invisible_spanned(loc.call_site); + MacroDefKind::ProcMacro(expander, _, ast) => { + let span = db.proc_macro_span(ast); + tt.delimiter = tt::Delimiter::invisible_spanned(span); expander.expand( db, loc.def.krate, loc.krate, &tt, attr_arg.as_ref(), - span_with_def_site_ctxt(db, loc.def.span, actual_macro_call), - span_with_call_site_ctxt(db, loc.def.span, actual_macro_call), - span_with_mixed_site_ctxt(db, loc.def.span, actual_macro_call), + span_with_def_site_ctxt(db, span, actual_macro_call), + span_with_call_site_ctxt(db, span, actual_macro_call), + span_with_mixed_site_ctxt(db, span, actual_macro_call), ) } MacroDefKind::BuiltInAttr(BuiltinAttrExpander::Derive, _) => { - pseudo_derive_attr_expansion(&tt, attr_arg.as_ref()?, loc.call_site) + pseudo_derive_attr_expansion(&tt, attr_arg.as_ref()?, span) + } + MacroDefKind::Declarative(it) => { + db.decl_macro_expander(loc.krate, it).expand_unhygienic(db, tt, loc.def.krate, span) + } + MacroDefKind::BuiltIn(it, _) => { + it.expand(db, actual_macro_call, &tt, span).map_err(Into::into) } - MacroDefKind::Declarative(it) => db.decl_macro_expander(loc.krate, it).expand_unhygienic( - db, - tt, - loc.def.krate, - loc.call_site, - ), - MacroDefKind::BuiltIn(it, _) => it.expand(db, actual_macro_call, &tt).map_err(Into::into), MacroDefKind::BuiltInDerive(it, ..) => { - it.expand(db, actual_macro_call, &tt).map_err(Into::into) + it.expand(db, actual_macro_call, &tt, span).map_err(Into::into) } MacroDefKind::BuiltInEager(it, _) => { - it.expand(db, actual_macro_call, &tt).map_err(Into::into) + it.expand(db, actual_macro_call, &tt, span).map_err(Into::into) } - MacroDefKind::BuiltInAttr(it, _) => it.expand(db, actual_macro_call, &tt), + MacroDefKind::BuiltInAttr(it, _) => it.expand(db, actual_macro_call, &tt, span), }; let expand_to = loc.expand_to(); @@ -319,181 +339,161 @@ pub(crate) fn parse_with_map( } } -// FIXME: for derive attributes, this will return separate copies of the same structures! +// FIXME: for derive attributes, this will return separate copies of the same structures! Though +// they may differ in spans due to differing call sites... fn macro_arg( db: &dyn ExpandDatabase, id: MacroCallId, - // FIXME: consider the following by putting fixup info into eager call info args - // ) -> ValueResult<Arc<(tt::Subtree, SyntaxFixupUndoInfo)>, Arc<Box<[SyntaxError]>>> { -) -> ValueResult<(Arc<tt::Subtree>, SyntaxFixupUndoInfo), Arc<Box<[SyntaxError]>>> { +) -> (Arc<tt::Subtree>, SyntaxFixupUndoInfo, Span) { let loc = db.lookup_intern_macro_call(id); - if let Some(EagerCallInfo { arg, .. }) = matches!(loc.def.kind, MacroDefKind::BuiltInEager(..)) - .then(|| loc.eager.as_deref()) - .flatten() + + if let MacroCallLoc { + def: MacroDefId { kind: MacroDefKind::BuiltInEager(..), .. }, + kind: MacroCallKind::FnLike { eager: Some(eager), .. }, + .. + } = &loc { - ValueResult::ok((arg.clone(), SyntaxFixupUndoInfo::NONE)) - } else { - let (parse, map) = parse_with_map(db, loc.kind.file_id()); - let root = parse.syntax_node(); - - let syntax = match loc.kind { - MacroCallKind::FnLike { ast_id, .. } => { - let dummy_tt = |kind| { - ( - Arc::new(tt::Subtree { - delimiter: tt::Delimiter { - open: loc.call_site, - close: loc.call_site, - kind, - }, - token_trees: Box::default(), - }), - SyntaxFixupUndoInfo::default(), - ) - }; + return (eager.arg.clone(), SyntaxFixupUndoInfo::NONE, eager.span); + } - let node = &ast_id.to_ptr(db).to_node(&root); - let offset = node.syntax().text_range().start(); - let Some(tt) = node.token_tree() else { - return ValueResult::new( - dummy_tt(tt::DelimiterKind::Invisible), - Arc::new(Box::new([SyntaxError::new_at_offset( - "missing token tree".to_owned(), - offset, - )])), - ); - }; - let first = tt.left_delimiter_token().map(|it| it.kind()).unwrap_or(T!['(']); - let last = tt.right_delimiter_token().map(|it| it.kind()).unwrap_or(T![.]); - - let mismatched_delimiters = !matches!( - (first, last), - (T!['('], T![')']) | (T!['['], T![']']) | (T!['{'], T!['}']) - ); - if mismatched_delimiters { - // Don't expand malformed (unbalanced) macro invocations. This is - // less than ideal, but trying to expand unbalanced macro calls - // sometimes produces pathological, deeply nested code which breaks - // all kinds of things. - // - // So instead, we'll return an empty subtree here - cov_mark::hit!(issue9358_bad_macro_stack_overflow); - - let kind = match first { - _ if loc.def.is_proc_macro() => tt::DelimiterKind::Invisible, - T!['('] => tt::DelimiterKind::Parenthesis, - T!['['] => tt::DelimiterKind::Bracket, - T!['{'] => tt::DelimiterKind::Brace, - _ => tt::DelimiterKind::Invisible, - }; - return ValueResult::new( - dummy_tt(kind), - Arc::new(Box::new([SyntaxError::new_at_offset( - "mismatched delimiters".to_owned(), - offset, - )])), - ); - } - tt.syntax().clone() - } - MacroCallKind::Derive { ast_id, .. } => { - ast_id.to_ptr(db).to_node(&root).syntax().clone() - } - MacroCallKind::Attr { ast_id, .. } => ast_id.to_ptr(db).to_node(&root).syntax().clone(), - }; - let (mut tt, undo_info) = match loc.kind { - MacroCallKind::FnLike { .. } => ( - mbe::syntax_node_to_token_tree(&syntax, map.as_ref(), loc.call_site), - SyntaxFixupUndoInfo::NONE, - ), - MacroCallKind::Derive { .. } | MacroCallKind::Attr { .. } => { - let censor = censor_for_macro_input(&loc, &syntax); - let mut fixups = fixup::fixup_syntax(map.as_ref(), &syntax, loc.call_site); - fixups.append.retain(|it, _| match it { - syntax::NodeOrToken::Node(it) => !censor.contains(it), - syntax::NodeOrToken::Token(_) => true, - }); - fixups.remove.extend(censor); - { - let mut tt = mbe::syntax_node_to_token_tree_modified( - &syntax, - map.as_ref(), - fixups.append.clone(), - fixups.remove.clone(), - loc.call_site, - ); - reverse_fixups(&mut tt, &fixups.undo_info); - } + let (parse, map) = parse_with_map(db, loc.kind.file_id()); + let root = parse.syntax_node(); + + let (censor, item_node, span) = match loc.kind { + MacroCallKind::FnLike { ast_id, .. } => { + let node = &ast_id.to_ptr(db).to_node(&root); + let path_range = node + .path() + .map_or_else(|| node.syntax().text_range(), |path| path.syntax().text_range()); + let span = map.span_for_range(path_range); + + let dummy_tt = |kind| { ( - mbe::syntax_node_to_token_tree_modified( - &syntax, - map, - fixups.append, - fixups.remove, - loc.call_site, - ), - fixups.undo_info, + Arc::new(tt::Subtree { + delimiter: tt::Delimiter { open: span, close: span, kind }, + token_trees: Box::default(), + }), + SyntaxFixupUndoInfo::default(), + span, ) - } - }; + }; - if loc.def.is_proc_macro() { - // proc macros expect their inputs without parentheses, MBEs expect it with them included - tt.delimiter.kind = tt::DelimiterKind::Invisible; - } + let Some(tt) = node.token_tree() else { + return dummy_tt(tt::DelimiterKind::Invisible); + }; + let first = tt.left_delimiter_token().map(|it| it.kind()).unwrap_or(T!['(']); + let last = tt.right_delimiter_token().map(|it| it.kind()).unwrap_or(T![.]); + + let mismatched_delimiters = !matches!( + (first, last), + (T!['('], T![')']) | (T!['['], T![']']) | (T!['{'], T!['}']) + ); + if mismatched_delimiters { + // Don't expand malformed (unbalanced) macro invocations. This is + // less than ideal, but trying to expand unbalanced macro calls + // sometimes produces pathological, deeply nested code which breaks + // all kinds of things. + // + // So instead, we'll return an empty subtree here + cov_mark::hit!(issue9358_bad_macro_stack_overflow); + + let kind = match first { + _ if loc.def.is_proc_macro() => tt::DelimiterKind::Invisible, + T!['('] => tt::DelimiterKind::Parenthesis, + T!['['] => tt::DelimiterKind::Bracket, + T!['{'] => tt::DelimiterKind::Brace, + _ => tt::DelimiterKind::Invisible, + }; + return dummy_tt(kind); + } - if matches!(loc.def.kind, MacroDefKind::BuiltInEager(..)) { - match parse.errors() { - errors if errors.is_empty() => ValueResult::ok((Arc::new(tt), undo_info)), - errors => ValueResult::new( - (Arc::new(tt), undo_info), - // Box::<[_]>::from(res.errors()), not stable yet - Arc::new(errors.to_vec().into_boxed_slice()), - ), + let mut tt = mbe::syntax_node_to_token_tree(tt.syntax(), map.as_ref(), span); + if loc.def.is_proc_macro() { + // proc macros expect their inputs without parentheses, MBEs expect it with them included + tt.delimiter.kind = tt::DelimiterKind::Invisible; } - } else { - ValueResult::ok((Arc::new(tt), undo_info)) + return (Arc::new(tt), SyntaxFixupUndoInfo::NONE, span); + } + MacroCallKind::Derive { ast_id, derive_attr_index, .. } => { + let node = ast_id.to_ptr(db).to_node(&root); + let censor_derive_input = censor_derive_input(derive_attr_index, &node); + let item_node = node.into(); + let attr_source = attr_source(derive_attr_index, &item_node); + // FIXME: This is wrong, this should point to the path of the derive attribute` + let span = + map.span_for_range(attr_source.as_ref().and_then(|it| it.path()).map_or_else( + || item_node.syntax().text_range(), + |it| it.syntax().text_range(), + )); + (censor_derive_input, item_node, span) + } + MacroCallKind::Attr { ast_id, invoc_attr_index, .. } => { + let node = ast_id.to_ptr(db).to_node(&root); + let attr_source = attr_source(invoc_attr_index, &node); + let span = map.span_for_range( + attr_source + .as_ref() + .and_then(|it| it.path()) + .map_or_else(|| node.syntax().text_range(), |it| it.syntax().text_range()), + ); + (attr_source.into_iter().map(|it| it.syntax().clone().into()).collect(), node, span) } + }; + + let (mut tt, undo_info) = { + let syntax = item_node.syntax(); + let censor_cfg = cfg_process::process_cfg_attrs(syntax, &loc, db).unwrap_or_default(); + let mut fixups = fixup::fixup_syntax(map.as_ref(), syntax, span); + fixups.append.retain(|it, _| match it { + syntax::NodeOrToken::Token(_) => true, + it => !censor.contains(it) && !censor_cfg.contains(it), + }); + fixups.remove.extend(censor); + fixups.remove.extend(censor_cfg); + + ( + mbe::syntax_node_to_token_tree_modified( + syntax, + map, + fixups.append, + fixups.remove, + span, + ), + fixups.undo_info, + ) + }; + + if loc.def.is_proc_macro() { + // proc macros expect their inputs without parentheses, MBEs expect it with them included + tt.delimiter.kind = tt::DelimiterKind::Invisible; } + + (Arc::new(tt), undo_info, span) } // FIXME: Censoring info should be calculated by the caller! Namely by name resolution -/// Certain macro calls expect some nodes in the input to be preprocessed away, namely: -/// - derives expect all `#[derive(..)]` invocations up to the currently invoked one to be stripped -/// - attributes expect the invoking attribute to be stripped -fn censor_for_macro_input(loc: &MacroCallLoc, node: &SyntaxNode) -> FxHashSet<SyntaxNode> { +/// Derives expect all `#[derive(..)]` invocations up to (and including) the currently invoked one to be stripped +fn censor_derive_input(derive_attr_index: AttrId, node: &ast::Adt) -> FxHashSet<SyntaxElement> { // FIXME: handle `cfg_attr` - (|| { - let censor = match loc.kind { - MacroCallKind::FnLike { .. } => return None, - MacroCallKind::Derive { derive_attr_index, .. } => { - cov_mark::hit!(derive_censoring); - ast::Item::cast(node.clone())? - .attrs() - .take(derive_attr_index.ast_index() + 1) - // FIXME, this resolution should not be done syntactically - // derive is a proper macro now, no longer builtin - // But we do not have resolution at this stage, this means - // we need to know about all macro calls for the given ast item here - // so we require some kind of mapping... - .filter(|attr| attr.simple_name().as_deref() == Some("derive")) - .map(|it| it.syntax().clone()) - .collect() - } - MacroCallKind::Attr { .. } if loc.def.is_attribute_derive() => return None, - MacroCallKind::Attr { invoc_attr_index, .. } => { - cov_mark::hit!(attribute_macro_attr_censoring); - collect_attrs(&ast::Item::cast(node.clone())?) - .nth(invoc_attr_index.ast_index()) - .and_then(|x| Either::left(x.1)) - .map(|attr| attr.syntax().clone()) - .into_iter() - .collect() - } - }; - Some(censor) - })() - .unwrap_or_default() + cov_mark::hit!(derive_censoring); + collect_attrs(node) + .take(derive_attr_index.ast_index() + 1) + .filter_map(|(_, attr)| Either::left(attr)) + // FIXME, this resolution should not be done syntactically + // derive is a proper macro now, no longer builtin + // But we do not have resolution at this stage, this means + // we need to know about all macro calls for the given ast item here + // so we require some kind of mapping... + .filter(|attr| attr.simple_name().as_deref() == Some("derive")) + .map(|it| it.syntax().clone().into()) + .collect() +} + +/// Attributes expect the invoking attribute to be stripped +fn attr_source(invoc_attr_index: AttrId, node: &ast::Item) -> Option<ast::Attr> { + // FIXME: handle `cfg_attr` + cov_mark::hit!(attribute_macro_attr_censoring); + collect_attrs(node).nth(invoc_attr_index.ast_index()).and_then(|(_, attr)| Either::left(attr)) } impl TokenExpander { @@ -523,74 +523,64 @@ fn macro_expand( ) -> ExpandResult<CowArc<tt::Subtree>> { let _p = tracing::span!(tracing::Level::INFO, "macro_expand").entered(); - let ExpandResult { value: tt, mut err } = match loc.def.kind { + let (ExpandResult { value: tt, err }, span) = match loc.def.kind { MacroDefKind::ProcMacro(..) => return db.expand_proc_macro(macro_call_id).map(CowArc::Arc), _ => { - let ValueResult { value: (macro_arg, undo_info), err } = db.macro_arg(macro_call_id); - let format_parse_err = |err: Arc<Box<[SyntaxError]>>| { - let mut buf = String::new(); - for err in &**err { - use std::fmt::Write; - _ = write!(buf, "{}, ", err); - } - buf.pop(); - buf.pop(); - ExpandError::other(buf) - }; + let (macro_arg, undo_info, span) = db.macro_arg(macro_call_id); let arg = &*macro_arg; - let res = match loc.def.kind { - MacroDefKind::Declarative(id) => { - db.decl_macro_expander(loc.def.krate, id).expand(db, arg.clone(), macro_call_id) - } - MacroDefKind::BuiltIn(it, _) => { - it.expand(db, macro_call_id, arg).map_err(Into::into) - } - // This might look a bit odd, but we do not expand the inputs to eager macros here. - // Eager macros inputs are expanded, well, eagerly when we collect the macro calls. - // That kind of expansion uses the ast id map of an eager macros input though which goes through - // the HirFileId machinery. As eager macro inputs are assigned a macro file id that query - // will end up going through here again, whereas we want to just want to inspect the raw input. - // As such we just return the input subtree here. - MacroDefKind::BuiltInEager(..) if loc.eager.is_none() => { - return ExpandResult { - value: CowArc::Arc(macro_arg.clone()), - err: err.map(format_parse_err), - }; - } - MacroDefKind::BuiltInDerive(it, _) => { - it.expand(db, macro_call_id, arg).map_err(Into::into) - } - MacroDefKind::BuiltInEager(it, _) => { - it.expand(db, macro_call_id, arg).map_err(Into::into) - } - MacroDefKind::BuiltInAttr(it, _) => { - let mut res = it.expand(db, macro_call_id, arg); - fixup::reverse_fixups(&mut res.value, &undo_info); - res - } - _ => unreachable!(), - }; - ExpandResult { - value: res.value, - // if the arg had parse errors, show them instead of the expansion errors - err: err.map(format_parse_err).or(res.err), - } + let res = + match loc.def.kind { + MacroDefKind::Declarative(id) => db + .decl_macro_expander(loc.def.krate, id) + .expand(db, arg.clone(), macro_call_id, span), + MacroDefKind::BuiltIn(it, _) => { + it.expand(db, macro_call_id, arg, span).map_err(Into::into) + } + MacroDefKind::BuiltInDerive(it, _) => { + it.expand(db, macro_call_id, arg, span).map_err(Into::into) + } + MacroDefKind::BuiltInEager(it, _) => { + // This might look a bit odd, but we do not expand the inputs to eager macros here. + // Eager macros inputs are expanded, well, eagerly when we collect the macro calls. + // That kind of expansion uses the ast id map of an eager macros input though which goes through + // the HirFileId machinery. As eager macro inputs are assigned a macro file id that query + // will end up going through here again, whereas we want to just want to inspect the raw input. + // As such we just return the input subtree here. + let eager = match &loc.kind { + MacroCallKind::FnLike { eager: None, .. } => { + return ExpandResult::ok(CowArc::Arc(macro_arg.clone())); + } + MacroCallKind::FnLike { eager: Some(eager), .. } => Some(&**eager), + _ => None, + }; + + let mut res = it.expand(db, macro_call_id, arg, span).map_err(Into::into); + + if let Some(EagerCallInfo { error, .. }) = eager { + // FIXME: We should report both errors! + res.err = error.clone().or(res.err); + } + res + } + MacroDefKind::BuiltInAttr(it, _) => { + let mut res = it.expand(db, macro_call_id, arg, span); + fixup::reverse_fixups(&mut res.value, &undo_info); + res + } + _ => unreachable!(), + }; + (ExpandResult { value: res.value, err: res.err }, span) } }; - if let Some(EagerCallInfo { error, .. }) = loc.eager.as_deref() { - // FIXME: We should report both errors! - err = error.clone().or(err); - } - // Skip checking token tree limit for include! macro call if !loc.def.is_include() { // Set a hard limit for the expanded tt if let Err(value) = check_tt_count(&tt) { return value.map(|()| { CowArc::Owned(tt::Subtree { - delimiter: tt::Delimiter::invisible_spanned(loc.call_site), + delimiter: tt::Delimiter::invisible_spanned(span), token_trees: Box::new([]), }) }); @@ -600,12 +590,23 @@ fn macro_expand( ExpandResult { value: CowArc::Owned(tt), err } } +fn proc_macro_span(db: &dyn ExpandDatabase, ast: AstId<ast::Fn>) -> Span { + let root = db.parse_or_expand(ast.file_id); + let ast_id_map = &db.ast_id_map(ast.file_id); + let span_map = &db.span_map(ast.file_id); + + let node = ast_id_map.get(ast.value).to_node(&root); + let range = ast::HasName::name(&node) + .map_or_else(|| node.syntax().text_range(), |name| name.syntax().text_range()); + span_map.span_for_range(range) +} + fn expand_proc_macro(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<Arc<tt::Subtree>> { let loc = db.lookup_intern_macro_call(id); - let (macro_arg, undo_info) = db.macro_arg(id).value; + let (macro_arg, undo_info, span) = db.macro_arg(id); - let expander = match loc.def.kind { - MacroDefKind::ProcMacro(expander, ..) => expander, + let (expander, ast) = match loc.def.kind { + MacroDefKind::ProcMacro(expander, _, ast) => (expander, ast), _ => unreachable!(), }; @@ -614,22 +615,25 @@ fn expand_proc_macro(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<A _ => None, }; - let ExpandResult { value: mut tt, err } = expander.expand( - db, - loc.def.krate, - loc.krate, - ¯o_arg, - attr_arg, - span_with_def_site_ctxt(db, loc.def.span, id), - span_with_call_site_ctxt(db, loc.def.span, id), - span_with_mixed_site_ctxt(db, loc.def.span, id), - ); + let ExpandResult { value: mut tt, err } = { + let span = db.proc_macro_span(ast); + expander.expand( + db, + loc.def.krate, + loc.krate, + ¯o_arg, + attr_arg, + span_with_def_site_ctxt(db, span, id), + span_with_call_site_ctxt(db, span, id), + span_with_mixed_site_ctxt(db, span, id), + ) + }; // Set a hard limit for the expanded tt if let Err(value) = check_tt_count(&tt) { return value.map(|()| { Arc::new(tt::Subtree { - delimiter: tt::Delimiter::invisible_spanned(loc.call_site), + delimiter: tt::Delimiter::invisible_spanned(span), token_trees: Box::new([]), }) }); diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/declarative.rs b/src/tools/rust-analyzer/crates/hir-expand/src/declarative.rs index 6874336cd2d..33643c02724 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/declarative.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/declarative.rs @@ -29,6 +29,7 @@ impl DeclarativeMacroExpander { db: &dyn ExpandDatabase, tt: tt::Subtree, call_id: MacroCallId, + span: Span, ) -> ExpandResult<tt::Subtree> { let loc = db.lookup_intern_macro_call(call_id); let toolchain = db.toolchain(loc.def.krate); @@ -45,7 +46,7 @@ impl DeclarativeMacroExpander { }); match self.mac.err() { Some(_) => ExpandResult::new( - tt::Subtree::empty(tt::DelimSpan { open: loc.call_site, close: loc.call_site }), + tt::Subtree::empty(tt::DelimSpan { open: span, close: span }), ExpandError::MacroDefinition, ), None => self @@ -54,7 +55,7 @@ impl DeclarativeMacroExpander { &tt, |s| s.ctx = apply_mark(db, s.ctx, call_id, self.transparency), new_meta_vars, - loc.call_site, + span, ) .map_err(Into::into), } diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/eager.rs b/src/tools/rust-analyzer/crates/hir-expand/src/eager.rs index 5337a5bb028..8b147c88c13 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/eager.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/eager.rs @@ -19,7 +19,7 @@ //! //! See the full discussion : <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Eager.20expansion.20of.20built-in.20macros> use base_db::CrateId; -use span::Span; +use span::SyntaxContextId; use syntax::{ted, Parse, SyntaxElement, SyntaxNode, TextSize, WalkEvent}; use triomphe::Arc; @@ -27,22 +27,20 @@ use crate::{ ast::{self, AstNode}, db::ExpandDatabase, mod_path::ModPath, - EagerCallInfo, ExpandError, ExpandResult, ExpandTo, ExpansionSpanMap, InFile, Intern, + AstId, EagerCallInfo, ExpandError, ExpandResult, ExpandTo, ExpansionSpanMap, InFile, Intern, MacroCallId, MacroCallKind, MacroCallLoc, MacroDefId, MacroDefKind, }; pub fn expand_eager_macro_input( db: &dyn ExpandDatabase, krate: CrateId, - macro_call: InFile<ast::MacroCall>, + macro_call: &ast::MacroCall, + ast_id: AstId<ast::MacroCall>, def: MacroDefId, - call_site: Span, + call_site: SyntaxContextId, resolver: &dyn Fn(ModPath) -> Option<MacroDefId>, ) -> ExpandResult<Option<MacroCallId>> { - let ast_map = db.ast_id_map(macro_call.file_id); - // the expansion which the ast id map is built upon has no whitespace, so the offsets are wrong as macro_call is from the token tree that has whitespace! - let call_id = InFile::new(macro_call.file_id, ast_map.ast_id(¯o_call.value)); - let expand_to = ExpandTo::from_call_site(¯o_call.value); + let expand_to = ExpandTo::from_call_site(macro_call); // Note: // When `lazy_expand` is called, its *parent* file must already exist. @@ -51,11 +49,11 @@ pub fn expand_eager_macro_input( let arg_id = MacroCallLoc { def, krate, - eager: None, - kind: MacroCallKind::FnLike { ast_id: call_id, expand_to: ExpandTo::Expr }, - call_site, + kind: MacroCallKind::FnLike { ast_id, expand_to: ExpandTo::Expr, eager: None }, + ctxt: call_site, } .intern(db); + let (_, _, span) = db.macro_arg(arg_id); let ExpandResult { value: (arg_exp, arg_exp_map), err: parse_err } = db.parse_macro_expansion(arg_id.as_macro_file()); @@ -82,16 +80,24 @@ pub fn expand_eager_macro_input( return ExpandResult { value: None, err }; }; - let mut subtree = mbe::syntax_node_to_token_tree(&expanded_eager_input, arg_map, call_site); + let mut subtree = mbe::syntax_node_to_token_tree(&expanded_eager_input, arg_map, span); subtree.delimiter.kind = crate::tt::DelimiterKind::Invisible; let loc = MacroCallLoc { def, krate, - eager: Some(Arc::new(EagerCallInfo { arg: Arc::new(subtree), arg_id, error: err.clone() })), - kind: MacroCallKind::FnLike { ast_id: call_id, expand_to }, - call_site, + kind: MacroCallKind::FnLike { + ast_id, + expand_to, + eager: Some(Arc::new(EagerCallInfo { + arg: Arc::new(subtree), + arg_id, + error: err.clone(), + span, + })), + }, + ctxt: call_site, }; ExpandResult { value: Some(loc.intern(db)), err } @@ -100,15 +106,18 @@ pub fn expand_eager_macro_input( fn lazy_expand( db: &dyn ExpandDatabase, def: &MacroDefId, - macro_call: InFile<ast::MacroCall>, + macro_call: &ast::MacroCall, + ast_id: AstId<ast::MacroCall>, krate: CrateId, - call_site: Span, + call_site: SyntaxContextId, ) -> ExpandResult<(InFile<Parse<SyntaxNode>>, Arc<ExpansionSpanMap>)> { - let ast_id = db.ast_id_map(macro_call.file_id).ast_id(¯o_call.value); - - let expand_to = ExpandTo::from_call_site(¯o_call.value); - let ast_id = macro_call.with_value(ast_id); - let id = def.as_lazy_macro(db, krate, MacroCallKind::FnLike { ast_id, expand_to }, call_site); + let expand_to = ExpandTo::from_call_site(macro_call); + let id = def.make_call( + db, + krate, + MacroCallKind::FnLike { ast_id, expand_to, eager: None }, + call_site, + ); let macro_file = id.as_macro_file(); db.parse_macro_expansion(macro_file) @@ -122,7 +131,7 @@ fn eager_macro_recur( mut offset: TextSize, curr: InFile<SyntaxNode>, krate: CrateId, - call_site: Span, + call_site: SyntaxContextId, macro_resolver: &dyn Fn(ModPath) -> Option<MacroDefId>, ) -> ExpandResult<Option<(SyntaxNode, TextSize)>> { let original = curr.value.clone_for_update(); @@ -172,12 +181,14 @@ fn eager_macro_recur( continue; } }; + let ast_id = db.ast_id_map(curr.file_id).ast_id(&call); let ExpandResult { value, err } = match def.kind { MacroDefKind::BuiltInEager(..) => { let ExpandResult { value, err } = expand_eager_macro_input( db, krate, - curr.with_value(call.clone()), + &call, + curr.with_value(ast_id), def, call_site, macro_resolver, @@ -207,7 +218,7 @@ fn eager_macro_recur( | MacroDefKind::BuiltInDerive(..) | MacroDefKind::ProcMacro(..) => { let ExpandResult { value: (parse, tm), err } = - lazy_expand(db, &def, curr.with_value(call.clone()), krate, call_site); + lazy_expand(db, &def, &call, curr.with_value(ast_id), krate, call_site); // replace macro inside let ExpandResult { value, err: error } = eager_macro_recur( diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/files.rs b/src/tools/rust-analyzer/crates/hir-expand/src/files.rs index a500c24ce88..04a4851ddb7 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/files.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/files.rs @@ -10,7 +10,7 @@ use syntax::{AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, use crate::{ db::{self, ExpandDatabase}, - map_node_range_up, span_for_offset, MacroFileIdExt, + map_node_range_up, map_node_range_up_rooted, span_for_offset, MacroFileIdExt, }; /// `InFile<T>` stores a value of `T` inside a particular file/syntax tree. @@ -38,6 +38,9 @@ impl<N: AstIdNode> AstId<N> { pub fn to_node(&self, db: &dyn ExpandDatabase) -> N { self.to_ptr(db).to_node(&db.parse_or_expand(self.file_id)) } + pub fn to_range(&self, db: &dyn ExpandDatabase) -> TextRange { + self.to_ptr(db).text_range() + } pub fn to_in_file_node(&self, db: &dyn ExpandDatabase) -> crate::InFile<N> { crate::InFile::new(self.file_id, self.to_ptr(db).to_node(&db.parse_or_expand(self.file_id))) } @@ -49,6 +52,9 @@ impl<N: AstIdNode> AstId<N> { pub type ErasedAstId = crate::InFile<ErasedFileAstId>; impl ErasedAstId { + pub fn to_range(&self, db: &dyn ExpandDatabase) -> TextRange { + self.to_ptr(db).text_range() + } pub fn to_ptr(&self, db: &dyn ExpandDatabase) -> SyntaxNodePtr { db.ast_id_map(self.file_id).get_erased(self.value) } @@ -173,24 +179,8 @@ impl InFile<&SyntaxNode> { /// /// For attributes and derives, this will point back to the attribute only. /// For the entire item use [`InFile::original_file_range_full`]. - pub fn original_file_range(self, db: &dyn db::ExpandDatabase) -> FileRange { - match self.file_id.repr() { - HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() }, - HirFileIdRepr::MacroFile(mac_file) => { - if let Some((res, ctxt)) = - map_node_range_up(db, &db.expansion_span_map(mac_file), self.value.text_range()) - { - // FIXME: Figure out an API that makes proper use of ctx, this only exists to - // keep pre-token map rewrite behaviour. - if ctxt.is_root() { - return res; - } - } - // Fall back to whole macro call. - let loc = db.lookup_intern_macro_call(mac_file.macro_call_id); - loc.kind.original_call_range(db) - } - } + pub fn original_file_range_rooted(self, db: &dyn db::ExpandDatabase) -> FileRange { + self.map(SyntaxNode::text_range).original_node_file_range_rooted(db) } /// Falls back to the macro call range if the node cannot be mapped up fully. @@ -198,23 +188,7 @@ impl InFile<&SyntaxNode> { self, db: &dyn db::ExpandDatabase, ) -> FileRange { - match self.file_id.repr() { - HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() }, - HirFileIdRepr::MacroFile(mac_file) => { - if let Some((res, ctxt)) = - map_node_range_up(db, &db.expansion_span_map(mac_file), self.value.text_range()) - { - // FIXME: Figure out an API that makes proper use of ctx, this only exists to - // keep pre-token map rewrite behaviour. - if ctxt.is_root() { - return res; - } - } - // Fall back to whole macro call. - let loc = db.lookup_intern_macro_call(mac_file.macro_call_id); - loc.kind.original_call_range_with_body(db) - } - } + self.map(SyntaxNode::text_range).original_node_file_range_with_macro_call_body(db) } /// Attempts to map the syntax node back up its macro calls. @@ -222,17 +196,10 @@ impl InFile<&SyntaxNode> { self, db: &dyn db::ExpandDatabase, ) -> Option<(FileRange, SyntaxContextId)> { - match self.file_id.repr() { - HirFileIdRepr::FileId(file_id) => { - Some((FileRange { file_id, range: self.value.text_range() }, SyntaxContextId::ROOT)) - } - HirFileIdRepr::MacroFile(mac_file) => { - map_node_range_up(db, &db.expansion_span_map(mac_file), self.value.text_range()) - } - } + self.map(SyntaxNode::text_range).original_node_file_range_opt(db) } - pub fn original_syntax_node( + pub fn original_syntax_node_rooted( self, db: &dyn db::ExpandDatabase, ) -> Option<InRealFile<SyntaxNode>> { @@ -242,25 +209,21 @@ impl InFile<&SyntaxNode> { HirFileIdRepr::FileId(file_id) => { return Some(InRealFile { file_id, value: self.value.clone() }) } - HirFileIdRepr::MacroFile(m) => m, + HirFileIdRepr::MacroFile(m) if m.is_attr_macro(db) => m, + _ => return None, }; - if !file_id.is_attr_macro(db) { - return None; - } - let (FileRange { file_id, range }, ctx) = - map_node_range_up(db, &db.expansion_span_map(file_id), self.value.text_range())?; + let FileRange { file_id, range } = + map_node_range_up_rooted(db, &db.expansion_span_map(file_id), self.value.text_range())?; - // FIXME: Figure out an API that makes proper use of ctx, this only exists to - // keep pre-token map rewrite behavior. - if !ctx.is_root() { - return None; - } - - let anc = db.parse(file_id).syntax_node().covering_element(range); let kind = self.value.kind(); - // FIXME: This heuristic is brittle and with the right macro may select completely unrelated nodes? - let value = anc.ancestors().find(|it| it.kind() == kind)?; + let value = db + .parse(file_id) + .syntax_node() + .covering_element(range) + .ancestors() + .take_while(|it| it.text_range() == range) + .find(|it| it.kind() == kind)?; Some(InRealFile::new(file_id, value)) } } @@ -355,8 +318,8 @@ impl InFile<TextRange> { match self.file_id.repr() { HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value }, HirFileIdRepr::MacroFile(mac_file) => { - match map_node_range_up(db, &db.expansion_span_map(mac_file), self.value) { - Some((it, SyntaxContextId::ROOT)) => it, + match map_node_range_up_rooted(db, &db.expansion_span_map(mac_file), self.value) { + Some(it) => it, _ => { let loc = db.lookup_intern_macro_call(mac_file.macro_call_id); loc.kind.original_call_range(db) @@ -366,6 +329,24 @@ impl InFile<TextRange> { } } + pub fn original_node_file_range_with_macro_call_body( + self, + db: &dyn db::ExpandDatabase, + ) -> FileRange { + match self.file_id.repr() { + HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value }, + HirFileIdRepr::MacroFile(mac_file) => { + match map_node_range_up_rooted(db, &db.expansion_span_map(mac_file), self.value) { + Some(it) => it, + _ => { + let loc = db.lookup_intern_macro_call(mac_file.macro_call_id); + loc.kind.original_call_range_with_body(db) + } + } + } + } + } + pub fn original_node_file_range_opt( self, db: &dyn db::ExpandDatabase, @@ -395,18 +376,12 @@ impl<N: AstNode> InFile<N> { return None; } - let (FileRange { file_id, range }, ctx) = map_node_range_up( + let FileRange { file_id, range } = map_node_range_up_rooted( db, &db.expansion_span_map(file_id), self.value.syntax().text_range(), )?; - // FIXME: Figure out an API that makes proper use of ctx, this only exists to - // keep pre-token map rewrite behaviour. - if !ctx.is_root() { - return None; - } - // FIXME: This heuristic is brittle and with the right macro may select completely unrelated nodes? let anc = db.parse(file_id).syntax_node().covering_element(range); let value = anc.ancestors().find_map(N::cast)?; diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs b/src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs index a3b2c700ffe..959595afb57 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs @@ -3,7 +3,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; use smallvec::SmallVec; -use span::{ErasedFileAstId, Span, SpanAnchor, SpanData, FIXUP_ERASED_FILE_AST_ID_MARKER}; +use span::{ErasedFileAstId, Span, SpanAnchor, FIXUP_ERASED_FILE_AST_ID_MARKER}; use stdx::never; use syntax::{ ast::{self, AstNode, HasLoopBody}, @@ -23,7 +23,7 @@ use crate::{ #[derive(Debug, Default)] pub(crate) struct SyntaxFixups { pub(crate) append: FxHashMap<SyntaxElement, Vec<Leaf>>, - pub(crate) remove: FxHashSet<SyntaxNode>, + pub(crate) remove: FxHashSet<SyntaxElement>, pub(crate) undo_info: SyntaxFixupUndoInfo, } @@ -51,13 +51,13 @@ pub(crate) fn fixup_syntax( call_site: Span, ) -> SyntaxFixups { let mut append = FxHashMap::<SyntaxElement, _>::default(); - let mut remove = FxHashSet::<SyntaxNode>::default(); + let mut remove = FxHashSet::<SyntaxElement>::default(); let mut preorder = node.preorder(); let mut original = Vec::new(); let dummy_range = FIXUP_DUMMY_RANGE; let fake_span = |range| { let span = span_map.span_for_range(range); - SpanData { + Span { range: dummy_range, anchor: SpanAnchor { ast_id: FIXUP_DUMMY_AST_ID, ..span.anchor }, ctx: span.ctx, @@ -68,7 +68,7 @@ pub(crate) fn fixup_syntax( let node_range = node.text_range(); if can_handle_error(&node) && has_error_to_handle(&node) { - remove.insert(node.clone()); + remove.insert(node.clone().into()); // the node contains an error node, we have to completely replace it by something valid let original_tree = mbe::syntax_node_to_token_tree(&node, span_map, call_site); let idx = original.len() as u32; @@ -76,7 +76,7 @@ pub(crate) fn fixup_syntax( let span = span_map.span_for_range(node_range); let replacement = Leaf::Ident(Ident { text: "__ra_fixup".into(), - span: SpanData { + span: Span { range: TextRange::new(TextSize::new(idx), FIXUP_DUMMY_RANGE_END), anchor: SpanAnchor { ast_id: FIXUP_DUMMY_AST_ID, ..span.anchor }, ctx: span.ctx, @@ -305,8 +305,8 @@ pub(crate) fn reverse_fixups(tt: &mut Subtree, undo_info: &SyntaxFixupUndoInfo) tt.delimiter.close.anchor.ast_id == FIXUP_DUMMY_AST_ID || tt.delimiter.open.anchor.ast_id == FIXUP_DUMMY_AST_ID ) { - tt.delimiter.close = SpanData::DUMMY; - tt.delimiter.open = SpanData::DUMMY; + tt.delimiter.close = Span::DUMMY; + tt.delimiter.open = Span::DUMMY; } reverse_fixups_(tt, undo_info); } diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/hygiene.rs b/src/tools/rust-analyzer/crates/hir-expand/src/hygiene.rs index ac2bab280d5..097e760c70a 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/hygiene.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/hygiene.rs @@ -65,7 +65,7 @@ pub(super) fn apply_mark( return apply_mark_internal(db, ctxt, call_id, transparency); } - let call_site_ctxt = db.lookup_intern_macro_call(call_id).call_site.ctx; + let call_site_ctxt = db.lookup_intern_macro_call(call_id).ctxt; let mut call_site_ctxt = if transparency == Transparency::SemiTransparent { call_site_ctxt.normalize_to_macros_2_0(db) } else { @@ -205,11 +205,10 @@ pub(crate) fn dump_syntax_contexts(db: &dyn ExpandDatabase) -> String { let id = e.key; let expn_data = e.value.as_ref().unwrap(); s.push_str(&format!( - "\n{:?}: parent: {:?}, call_site_ctxt: {:?}, def_site_ctxt: {:?}, kind: {:?}", + "\n{:?}: parent: {:?}, call_site_ctxt: {:?}, kind: {:?}", id, expn_data.kind.file_id(), - expn_data.call_site, - SyntaxContextId::ROOT, // FIXME expn_data.def_site, + expn_data.ctxt, expn_data.kind.descr(), )); } diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs b/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs index 42dc8c12d60..5d4f7dc1462 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs @@ -22,16 +22,19 @@ pub mod proc_macro; pub mod quote; pub mod span_map; +mod cfg_process; mod fixup; - use attrs::collect_attrs; +use rustc_hash::FxHashMap; use triomphe::Arc; use std::{fmt, hash::Hash}; use base_db::{salsa::impl_intern_value_trivial, CrateId, Edition, FileId}; use either::Either; -use span::{ErasedFileAstId, FileRange, HirFileIdRepr, Span, SyntaxContextData, SyntaxContextId}; +use span::{ + ErasedFileAstId, FileRange, HirFileIdRepr, Span, SpanAnchor, SyntaxContextData, SyntaxContextId, +}; use syntax::{ ast::{self, AstNode}, SyntaxNode, SyntaxToken, TextRange, TextSize, @@ -167,13 +170,8 @@ impl fmt::Display for ExpandError { pub struct MacroCallLoc { pub def: MacroDefId, pub krate: CrateId, - /// Some if this is a macro call for an eager macro. Note that this is `None` - /// for the eager input macro file. - // FIXME: This is being interned, subtrees can vary quickly differ just slightly causing - // leakage problems here - eager: Option<Arc<EagerCallInfo>>, pub kind: MacroCallKind, - pub call_site: Span, + pub ctxt: SyntaxContextId, } impl_intern_value_trivial!(MacroCallLoc); @@ -184,7 +182,6 @@ pub struct MacroDefId { pub kind: MacroDefKind, pub local_inner: bool, pub allow_internal_unsafe: bool, - pub span: Span, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -204,6 +201,8 @@ pub struct EagerCallInfo { /// Call id of the eager macro's input file (this is the macro file for its fully expanded input). arg_id: MacroCallId, error: Option<ExpandError>, + /// TODO: Doc + span: Span, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -211,6 +210,11 @@ pub enum MacroCallKind { FnLike { ast_id: AstId<ast::MacroCall>, expand_to: ExpandTo, + /// Some if this is a macro call for an eager macro. Note that this is `None` + /// for the eager input macro file. + // FIXME: This is being interned, subtrees can vary quickly differ just slightly causing + // leakage problems here + eager: Option<Arc<EagerCallInfo>>, }, Derive { ast_id: AstId<ast::Adt>, @@ -272,7 +276,7 @@ impl HirFileIdExt for HirFileId { HirFileIdRepr::MacroFile(file) => { let loc = db.lookup_intern_macro_call(file.macro_call_id); if loc.def.is_include() { - if let Some(eager) = &loc.eager { + if let MacroCallKind::FnLike { eager: Some(eager), .. } = &loc.kind { if let Ok(it) = builtin_fn_macro::include_input_to_file_id( db, file.macro_call_id, @@ -319,6 +323,9 @@ impl HirFileIdExt for HirFileId { } pub trait MacroFileIdExt { + fn is_env_or_option_env(&self, db: &dyn ExpandDatabase) -> bool; + fn is_include_like_macro(&self, db: &dyn ExpandDatabase) -> bool; + fn eager_arg(&self, db: &dyn ExpandDatabase) -> Option<MacroCallId>; fn expansion_level(self, db: &dyn ExpandDatabase) -> u32; /// If this is a macro call, returns the syntax node of the call. fn call_node(self, db: &dyn ExpandDatabase) -> InFile<SyntaxNode>; @@ -385,31 +392,47 @@ impl MacroFileIdExt for MacroFileId { db.lookup_intern_macro_call(self.macro_call_id).def.is_include() } + fn is_include_like_macro(&self, db: &dyn ExpandDatabase) -> bool { + db.lookup_intern_macro_call(self.macro_call_id).def.is_include_like() + } + + fn is_env_or_option_env(&self, db: &dyn ExpandDatabase) -> bool { + db.lookup_intern_macro_call(self.macro_call_id).def.is_env_or_option_env() + } + fn is_eager(&self, db: &dyn ExpandDatabase) -> bool { - let loc: MacroCallLoc = db.lookup_intern_macro_call(self.macro_call_id); + let loc = db.lookup_intern_macro_call(self.macro_call_id); matches!(loc.def.kind, MacroDefKind::BuiltInEager(..)) } + fn eager_arg(&self, db: &dyn ExpandDatabase) -> Option<MacroCallId> { + let loc = db.lookup_intern_macro_call(self.macro_call_id); + match &loc.kind { + MacroCallKind::FnLike { eager, .. } => eager.as_ref().map(|it| it.arg_id), + _ => None, + } + } + fn is_attr_macro(&self, db: &dyn ExpandDatabase) -> bool { - let loc: MacroCallLoc = db.lookup_intern_macro_call(self.macro_call_id); + let loc = db.lookup_intern_macro_call(self.macro_call_id); matches!(loc.kind, MacroCallKind::Attr { .. }) } fn is_derive_attr_pseudo_expansion(&self, db: &dyn ExpandDatabase) -> bool { - let loc: MacroCallLoc = db.lookup_intern_macro_call(self.macro_call_id); + let loc = db.lookup_intern_macro_call(self.macro_call_id); loc.def.is_attribute_derive() } } impl MacroDefId { - pub fn as_lazy_macro( + pub fn make_call( self, db: &dyn ExpandDatabase, krate: CrateId, kind: MacroCallKind, - call_site: Span, + ctxt: SyntaxContextId, ) -> MacroCallId { - MacroCallLoc { def: self, krate, eager: None, kind, call_site }.intern(db) + MacroCallLoc { def: self, krate, kind, ctxt }.intern(db) } pub fn definition_range(&self, db: &dyn ExpandDatabase) -> InFile<TextRange> { @@ -474,6 +497,14 @@ impl MacroDefId { pub fn is_include(&self) -> bool { matches!(self.kind, MacroDefKind::BuiltInEager(expander, ..) if expander.is_include()) } + + pub fn is_include_like(&self) -> bool { + matches!(self.kind, MacroDefKind::BuiltInEager(expander, ..) if expander.is_include_like()) + } + + pub fn is_env_or_option_env(&self) -> bool { + matches!(self.kind, MacroDefKind::BuiltInEager(expander, ..) if expander.is_env_or_option_env()) + } } impl MacroCallLoc { @@ -531,7 +562,7 @@ impl MacroCallLoc { macro_call_id: MacroCallId, ) -> Option<FileId> { if self.def.is_include() { - if let Some(eager) = &self.eager { + if let MacroCallKind::FnLike { eager: Some(eager), .. } = &self.kind { if let Ok(it) = builtin_fn_macro::include_input_to_file_id(db, macro_call_id, &eager.arg) { @@ -655,7 +686,7 @@ impl MacroCallKind { /// ExpansionInfo mainly describes how to map text range between src and expanded macro // FIXME: can be expensive to create, we should check the use sites and maybe replace them with // simpler function calls if the map is only used once -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct ExpansionInfo { pub expanded: InMacroFile<SyntaxNode>, /// The argument TokenTree or item for attributes @@ -683,6 +714,24 @@ impl ExpansionInfo { } /// Maps the passed in file range down into a macro expansion if it is the input to a macro call. + /// + /// Note this does a linear search through the entire backing vector of the spanmap. + pub fn map_range_down_exact( + &self, + span: Span, + ) -> Option<InMacroFile<impl Iterator<Item = SyntaxToken> + '_>> { + let tokens = self + .exp_map + .ranges_with_span_exact(span) + .flat_map(move |range| self.expanded.value.covering_element(range).into_token()); + + Some(InMacroFile::new(self.expanded.file_id, tokens)) + } + + /// Maps the passed in file range down into a macro expansion if it is the input to a macro call. + /// Unlike [`map_range_down_exact`], this will consider spans that contain the given span. + /// + /// Note this does a linear search through the entire backing vector of the spanmap. pub fn map_range_down( &self, span: Span, @@ -739,7 +788,7 @@ impl ExpansionInfo { InFile::new( self.arg.file_id, arg_map - .ranges_with_span(span) + .ranges_with_span_exact(span) .filter(|range| range.intersect(arg_range).is_some()) .collect(), ) @@ -757,7 +806,7 @@ impl ExpansionInfo { let (parse, exp_map) = db.parse_macro_expansion(macro_file).value; let expanded = InMacroFile { file_id: macro_file, value: parse.syntax_node() }; - let (macro_arg, _) = db.macro_arg(macro_file.macro_call_id).value; + let (macro_arg, _, _) = db.macro_arg(macro_file.macro_call_id); let def = loc.def.ast_id().left().and_then(|id| { let def_tt = match id.to_node(db) { @@ -793,7 +842,34 @@ impl ExpansionInfo { } } +/// Maps up the text range out of the expansion hierarchy back into the original file its from only +/// considering the root spans contained. +/// Unlike [`map_node_range_up`], this will not return `None` if any anchors or syntax contexts differ. +pub fn map_node_range_up_rooted( + db: &dyn ExpandDatabase, + exp_map: &ExpansionSpanMap, + range: TextRange, +) -> Option<FileRange> { + let mut spans = exp_map.spans_for_range(range).filter(|span| span.ctx.is_root()); + let Span { range, anchor, ctx: _ } = spans.next()?; + let mut start = range.start(); + let mut end = range.end(); + + for span in spans { + if span.anchor != anchor { + return None; + } + start = start.min(span.range.start()); + end = end.max(span.range.end()); + } + let anchor_offset = + db.ast_id_map(anchor.file_id.into()).get_erased(anchor.ast_id).text_range().start(); + Some(FileRange { file_id: anchor.file_id, range: TextRange::new(start, end) + anchor_offset }) +} + /// Maps up the text range out of the expansion hierarchy back into the original file its from. +/// +/// this will return `None` if any anchors or syntax contexts differ. pub fn map_node_range_up( db: &dyn ExpandDatabase, exp_map: &ExpansionSpanMap, @@ -819,6 +895,29 @@ pub fn map_node_range_up( )) } +/// Maps up the text range out of the expansion hierarchy back into the original file its from. +/// This version will aggregate the ranges of all spans with the same anchor and syntax context. +pub fn map_node_range_up_aggregated( + db: &dyn ExpandDatabase, + exp_map: &ExpansionSpanMap, + range: TextRange, +) -> FxHashMap<(SpanAnchor, SyntaxContextId), TextRange> { + let mut map = FxHashMap::default(); + for span in exp_map.spans_for_range(range) { + let range = map.entry((span.anchor, span.ctx)).or_insert_with(|| span.range); + *range = TextRange::new( + range.start().min(span.range.start()), + range.end().max(span.range.end()), + ); + } + for ((anchor, _), range) in &mut map { + let anchor_offset = + db.ast_id_map(anchor.file_id.into()).get_erased(anchor.ast_id).text_range().start(); + *range += anchor_offset; + } + map +} + /// Looks up the span at the given offset. pub fn span_for_offset( db: &dyn ExpandDatabase, diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/quote.rs b/src/tools/rust-analyzer/crates/hir-expand/src/quote.rs index c1930c94f5c..a31a111c911 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/quote.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/quote.rs @@ -266,10 +266,11 @@ mod tests { let quoted = quote!(DUMMY =>#a); assert_eq!(quoted.to_string(), "hello"); - let t = format!("{quoted:?}"); + let t = format!("{quoted:#?}"); expect![[r#" - SUBTREE $$ SpanData { range: 0..0, anchor: SpanAnchor(FileId(937550), 0), ctx: SyntaxContextId(0) } SpanData { range: 0..0, anchor: SpanAnchor(FileId(937550), 0), ctx: SyntaxContextId(0) } - IDENT hello SpanData { range: 0..0, anchor: SpanAnchor(FileId(937550), 0), ctx: SyntaxContextId(0) }"#]].assert_eq(&t); + SUBTREE $$ 937550:0@0..0#0 937550:0@0..0#0 + IDENT hello 937550:0@0..0#0"#]] + .assert_eq(&t); } #[test] diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/span_map.rs b/src/tools/rust-analyzer/crates/hir-expand/src/span_map.rs index ef86be67096..eae2c8fb632 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/span_map.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/span_map.rs @@ -1,13 +1,15 @@ //! Span maps for real files and macro expansions. -use span::{FileId, HirFileId, HirFileIdRepr, MacroFileId, Span}; -use syntax::{AstNode, TextRange}; + +use span::{FileId, HirFileId, HirFileIdRepr, MacroFileId, Span, SyntaxContextId}; +use stdx::TupleExt; +use syntax::{ast, AstNode, TextRange}; use triomphe::Arc; pub use span::RealSpanMap; -use crate::db::ExpandDatabase; +use crate::{attrs::collect_attrs, db::ExpandDatabase}; -pub type ExpansionSpanMap = span::SpanMap<Span>; +pub type ExpansionSpanMap = span::SpanMap<SyntaxContextId>; /// Spanmap for a macro file or a real file #[derive(Clone, Debug, PartialEq, Eq)] @@ -82,13 +84,54 @@ pub(crate) fn real_span_map(db: &dyn ExpandDatabase, file_id: FileId) -> Arc<Rea let mut pairs = vec![(syntax::TextSize::new(0), span::ROOT_ERASED_FILE_AST_ID)]; let ast_id_map = db.ast_id_map(file_id.into()); let tree = db.parse(file_id).tree(); - // FIXME: Descend into modules and other item containing items that are not annotated with attributes - // and allocate pairs for those as well. This gives us finer grained span anchors resulting in - // better incrementality - pairs.extend( - tree.items() - .map(|item| (item.syntax().text_range().start(), ast_id_map.ast_id(&item).erase())), - ); + // This is an incrementality layer. Basically we can't use absolute ranges for our spans as that + // would mean we'd invalidate everything whenever we type. So instead we make the text ranges + // relative to some AstIds reducing the risk of invalidation as typing somewhere no longer + // affects all following spans in the file. + // There is some stuff to bear in mind here though, for one, the more "anchors" we create, the + // easier it gets to invalidate things again as spans are as stable as their anchor's ID. + // The other problem is proc-macros. Proc-macros have a `Span::join` api that allows them + // to join two spans that come from the same file. rust-analyzer's proc-macro server + // can only join two spans if they belong to the same anchor though, as the spans are relative + // to that anchor. To do cross anchor joining we'd need to access to the ast id map to resolve + // them again, something we might get access to in the future. But even then, proc-macros doing + // this kind of joining makes them as stable as the AstIdMap (which is basically changing on + // every input of the file)… + + let item_to_entry = + |item: ast::Item| (item.syntax().text_range().start(), ast_id_map.ast_id(&item).erase()); + // Top level items make for great anchors as they are the most stable and a decent boundary + pairs.extend(tree.items().map(item_to_entry)); + // Unfortunately, assoc items are very common in Rust, so descend into those as well and make + // them anchors too, but only if they have no attributes attached, as those might be proc-macros + // and using different anchors inside of them will prevent spans from being joinable. + tree.items().for_each(|item| match &item { + ast::Item::ExternBlock(it) + if !collect_attrs(it).map(TupleExt::tail).any(|it| it.is_left()) => + { + if let Some(extern_item_list) = it.extern_item_list() { + pairs.extend( + extern_item_list.extern_items().map(ast::Item::from).map(item_to_entry), + ); + } + } + ast::Item::Impl(it) if !collect_attrs(it).map(TupleExt::tail).any(|it| it.is_left()) => { + if let Some(assoc_item_list) = it.assoc_item_list() { + pairs.extend(assoc_item_list.assoc_items().map(ast::Item::from).map(item_to_entry)); + } + } + ast::Item::Module(it) if !collect_attrs(it).map(TupleExt::tail).any(|it| it.is_left()) => { + if let Some(item_list) = it.item_list() { + pairs.extend(item_list.items().map(item_to_entry)); + } + } + ast::Item::Trait(it) if !collect_attrs(it).map(TupleExt::tail).any(|it| it.is_left()) => { + if let Some(assoc_item_list) = it.assoc_item_list() { + pairs.extend(assoc_item_list.assoc_items().map(ast::Item::from).map(item_to_entry)); + } + } + _ => (), + }); Arc::new(RealSpanMap::from_file( file_id, diff --git a/src/tools/rust-analyzer/crates/hir-ty/Cargo.toml b/src/tools/rust-analyzer/crates/hir-ty/Cargo.toml index 41e2f7ad73c..3cfedcdcb4d 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/Cargo.toml +++ b/src/tools/rust-analyzer/crates/hir-ty/Cargo.toml @@ -23,10 +23,10 @@ oorandom = "11.1.3" tracing.workspace = true rustc-hash.workspace = true scoped-tls = "1.0.0" -chalk-solve = { version = "0.96.0", default-features = false } -chalk-ir = "0.96.0" -chalk-recursive = { version = "0.96.0", default-features = false } -chalk-derive = "0.96.0" +chalk-solve.workspace = true +chalk-ir.workspace = true +chalk-recursive.workspace = true +chalk-derive.workspace = true la-arena.workspace = true once_cell = "1.17.0" triomphe.workspace = true diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs b/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs index 8d819e41aa2..e2446c34254 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs @@ -113,7 +113,7 @@ pub(crate) fn autoderef_step( ty: Ty, explicit: bool, ) -> Option<(AutoderefKind, Ty)> { - if let Some(derefed) = builtin_deref(table, &ty, explicit) { + if let Some(derefed) = builtin_deref(table.db, &ty, explicit) { Some((AutoderefKind::Builtin, table.resolve_ty_shallow(derefed))) } else { Some((AutoderefKind::Overloaded, deref_by_trait(table, ty)?)) @@ -121,7 +121,7 @@ pub(crate) fn autoderef_step( } pub(crate) fn builtin_deref<'ty>( - table: &mut InferenceTable<'_>, + db: &dyn HirDatabase, ty: &'ty Ty, explicit: bool, ) -> Option<&'ty Ty> { @@ -129,7 +129,7 @@ pub(crate) fn builtin_deref<'ty>( TyKind::Ref(.., ty) => Some(ty), TyKind::Raw(.., ty) if explicit => Some(ty), &TyKind::Adt(chalk_ir::AdtId(adt), ref substs) => { - if crate::lang_items::is_box(table.db, adt) { + if crate::lang_items::is_box(db, adt) { substs.at(Interner, 0).ty(Interner) } else { None diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer.rs index 9cea414e1a0..34ba17f145e 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer.rs @@ -22,7 +22,7 @@ mod pat; mod path; pub(crate) mod unify; -use std::{convert::identity, ops::Index}; +use std::{convert::identity, iter, ops::Index}; use chalk_ir::{ cast::Cast, fold::TypeFoldable, interner::HasInterner, DebruijnIndex, Mutability, Safety, @@ -777,7 +777,15 @@ impl<'a> InferenceContext<'a> { param_tys.push(va_list_ty) } - for (ty, pat) in param_tys.into_iter().zip(self.body.params.iter()) { + let mut param_tys = param_tys.into_iter().chain(iter::repeat(self.table.new_type_var())); + if let Some(self_param) = self.body.self_param { + if let Some(ty) = param_tys.next() { + let ty = self.insert_type_vars(ty); + let ty = self.normalize_associated_types_in(ty); + self.write_binding_ty(self_param, ty); + } + } + for (ty, pat) in param_tys.zip(&*self.body.params) { let ty = self.insert_type_vars(ty); let ty = self.normalize_associated_types_in(ty); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs index 61638c43d9c..ff6de61ba64 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs @@ -647,7 +647,7 @@ impl InferenceTable<'_> { let goal: InEnvironment<DomainGoal> = InEnvironment::new(&self.trait_env.env, coerce_unsized_tref.cast(Interner)); - let canonicalized = self.canonicalize(goal); + let canonicalized = self.canonicalize_with_free_vars(goal); // FIXME: rustc's coerce_unsized is more specialized -- it only tries to // solve `CoerceUnsized` and `Unsize` goals at this point and leaves the diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs index c377a51e7d3..a3dab1fd9d5 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs @@ -312,15 +312,13 @@ impl InferenceContext<'_> { Expr::Call { callee, args, .. } => { let callee_ty = self.infer_expr(*callee, &Expectation::none()); let mut derefs = Autoderef::new(&mut self.table, callee_ty.clone(), false); - let (res, derefed_callee) = 'b: { - // manual loop to be able to access `derefs.table` - while let Some((callee_deref_ty, _)) = derefs.next() { - let res = derefs.table.callable_sig(&callee_deref_ty, args.len()); - if res.is_some() { - break 'b (res, callee_deref_ty); - } + let (res, derefed_callee) = loop { + let Some((callee_deref_ty, _)) = derefs.next() else { + break (None, callee_ty.clone()); + }; + if let Some(res) = derefs.table.callable_sig(&callee_deref_ty, args.len()) { + break (Some(res), callee_deref_ty); } - (None, callee_ty.clone()) }; // if the function is unresolved, we use is_varargs=true to // suppress the arg count diagnostic here @@ -657,7 +655,7 @@ impl InferenceContext<'_> { ); } } - if let Some(derefed) = builtin_deref(&mut self.table, &inner_ty, true) { + if let Some(derefed) = builtin_deref(self.table.db, &inner_ty, true) { self.resolve_ty_shallow(derefed) } else { deref_by_trait(&mut self.table, inner_ty) @@ -774,7 +772,7 @@ impl InferenceContext<'_> { let receiver_adjustments = method_resolution::resolve_indexing_op( self.db, self.table.trait_env.clone(), - canonicalized.value, + canonicalized, index_trait, ); let (self_ty, mut adj) = receiver_adjustments @@ -1559,7 +1557,7 @@ impl InferenceContext<'_> { let canonicalized_receiver = self.canonicalize(receiver_ty.clone()); let resolved = method_resolution::lookup_method( self.db, - &canonicalized_receiver.value, + &canonicalized_receiver, self.table.trait_env.clone(), self.get_traits_in_scope().as_ref().left_or_else(|&it| it), VisibleFromModule::Filter(self.resolver.module()), @@ -1608,7 +1606,7 @@ impl InferenceContext<'_> { let resolved = method_resolution::lookup_method( self.db, - &canonicalized_receiver.value, + &canonicalized_receiver, self.table.trait_env.clone(), self.get_traits_in_scope().as_ref().left_or_else(|&it| it), VisibleFromModule::Filter(self.resolver.module()), @@ -1641,7 +1639,7 @@ impl InferenceContext<'_> { }; let assoc_func_with_same_name = method_resolution::iterate_method_candidates( - &canonicalized_receiver.value, + &canonicalized_receiver, self.db, self.table.trait_env.clone(), self.get_traits_in_scope().as_ref().left_or_else(|&it| it), diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs index 16ae028427d..8f537bb448b 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs @@ -321,7 +321,7 @@ impl InferenceContext<'_> { let mut not_visible = None; let res = method_resolution::iterate_method_candidates( - &canonical_ty.value, + &canonical_ty, self.db, self.table.trait_env.clone(), self.get_traits_in_scope().as_ref().left_or_else(|&it| it), diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs index 1d0150d850f..be7547f9bae 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs @@ -23,12 +23,9 @@ use crate::{ }; impl InferenceContext<'_> { - pub(super) fn canonicalize<T: TypeFoldable<Interner> + HasInterner<Interner = Interner>>( - &mut self, - t: T, - ) -> Canonicalized<T> + pub(super) fn canonicalize<T>(&mut self, t: T) -> Canonical<T> where - T: HasInterner<Interner = Interner>, + T: TypeFoldable<Interner> + HasInterner<Interner = Interner>, { self.table.canonicalize(t) } @@ -128,14 +125,14 @@ impl<T: HasInterner<Interner = Interner>> Canonicalized<T> { }), ); for (i, v) in solution.value.iter(Interner).enumerate() { - let var = self.free_vars[i].clone(); + let var = &self.free_vars[i]; if let Some(ty) = v.ty(Interner) { // eagerly replace projections in the type; we may be getting types // e.g. from where clauses where this hasn't happened yet let ty = ctx.normalize_associated_types_in(new_vars.apply(ty.clone(), Interner)); ctx.unify(var.assert_ty_ref(Interner), &ty); } else { - let _ = ctx.try_unify(&var, &new_vars.apply(v.clone(), Interner)); + let _ = ctx.try_unify(var, &new_vars.apply(v.clone(), Interner)); } } } @@ -243,7 +240,7 @@ pub(crate) struct InferenceTable<'a> { pub(crate) db: &'a dyn HirDatabase, pub(crate) trait_env: Arc<TraitEnvironment>, var_unification_table: ChalkInferenceTable, - type_variable_table: Vec<TypeVariableFlags>, + type_variable_table: SmallVec<[TypeVariableFlags; 16]>, pending_obligations: Vec<Canonicalized<InEnvironment<Goal>>>, /// Double buffer used in [`Self::resolve_obligations_as_possible`] to cut down on /// temporary allocations. @@ -252,8 +249,8 @@ pub(crate) struct InferenceTable<'a> { pub(crate) struct InferenceTableSnapshot { var_table_snapshot: chalk_solve::infer::InferenceSnapshot<Interner>, + type_variable_table: SmallVec<[TypeVariableFlags; 16]>, pending_obligations: Vec<Canonicalized<InEnvironment<Goal>>>, - type_variable_table_snapshot: Vec<TypeVariableFlags>, } impl<'a> InferenceTable<'a> { @@ -262,7 +259,7 @@ impl<'a> InferenceTable<'a> { db, trait_env, var_unification_table: ChalkInferenceTable::new(), - type_variable_table: Vec::new(), + type_variable_table: SmallVec::new(), pending_obligations: Vec::new(), resolve_obligations_buffer: Vec::new(), } @@ -292,14 +289,14 @@ impl<'a> InferenceTable<'a> { } fn fallback_value(&self, iv: InferenceVar, kind: TyVariableKind) -> Ty { + let is_diverging = self + .type_variable_table + .get(iv.index() as usize) + .map_or(false, |data| data.contains(TypeVariableFlags::DIVERGING)); + if is_diverging { + return TyKind::Never.intern(Interner); + } match kind { - _ if self - .type_variable_table - .get(iv.index() as usize) - .map_or(false, |data| data.contains(TypeVariableFlags::DIVERGING)) => - { - TyKind::Never - } TyVariableKind::General => TyKind::Error, TyVariableKind::Integer => TyKind::Scalar(Scalar::Int(IntTy::I32)), TyVariableKind::Float => TyKind::Scalar(Scalar::Float(FloatTy::F64)), @@ -307,12 +304,9 @@ impl<'a> InferenceTable<'a> { .intern(Interner) } - pub(crate) fn canonicalize<T: TypeFoldable<Interner> + HasInterner<Interner = Interner>>( - &mut self, - t: T, - ) -> Canonicalized<T> + pub(crate) fn canonicalize_with_free_vars<T>(&mut self, t: T) -> Canonicalized<T> where - T: HasInterner<Interner = Interner>, + T: TypeFoldable<Interner> + HasInterner<Interner = Interner>, { // try to resolve obligations before canonicalizing, since this might // result in new knowledge about variables @@ -326,6 +320,16 @@ impl<'a> InferenceTable<'a> { Canonicalized { value: result.quantified, free_vars } } + pub(crate) fn canonicalize<T>(&mut self, t: T) -> Canonical<T> + where + T: TypeFoldable<Interner> + HasInterner<Interner = Interner>, + { + // try to resolve obligations before canonicalizing, since this might + // result in new knowledge about variables + self.resolve_obligations_as_possible(); + self.var_unification_table.canonicalize(Interner, t).quantified + } + /// Recurses through the given type, normalizing associated types mentioned /// in it by replacing them by type variables and registering obligations to /// resolve later. This should be done once for every type we get from some @@ -541,7 +545,7 @@ impl<'a> InferenceTable<'a> { Err(_) => return false, }; result.goals.iter().all(|goal| { - let canonicalized = self.canonicalize(goal.clone()); + let canonicalized = self.canonicalize_with_free_vars(goal.clone()); self.try_resolve_obligation(&canonicalized).is_some() }) } @@ -575,19 +579,15 @@ impl<'a> InferenceTable<'a> { pub(crate) fn snapshot(&mut self) -> InferenceTableSnapshot { let var_table_snapshot = self.var_unification_table.snapshot(); - let type_variable_table_snapshot = self.type_variable_table.clone(); + let type_variable_table = self.type_variable_table.clone(); let pending_obligations = self.pending_obligations.clone(); - InferenceTableSnapshot { - var_table_snapshot, - pending_obligations, - type_variable_table_snapshot, - } + InferenceTableSnapshot { var_table_snapshot, pending_obligations, type_variable_table } } #[tracing::instrument(skip_all)] pub(crate) fn rollback_to(&mut self, snapshot: InferenceTableSnapshot) { self.var_unification_table.rollback_to(snapshot.var_table_snapshot); - self.type_variable_table = snapshot.type_variable_table_snapshot; + self.type_variable_table = snapshot.type_variable_table; self.pending_obligations = snapshot.pending_obligations; } @@ -606,7 +606,7 @@ impl<'a> InferenceTable<'a> { let in_env = InEnvironment::new(&self.trait_env.env, goal); let canonicalized = self.canonicalize(in_env); - self.db.trait_solve(self.trait_env.krate, self.trait_env.block, canonicalized.value) + self.db.trait_solve(self.trait_env.krate, self.trait_env.block, canonicalized) } pub(crate) fn register_obligation(&mut self, goal: Goal) { @@ -615,7 +615,7 @@ impl<'a> InferenceTable<'a> { } fn register_obligation_in_env(&mut self, goal: InEnvironment<Goal>) { - let canonicalized = self.canonicalize(goal); + let canonicalized = self.canonicalize_with_free_vars(goal); let solution = self.try_resolve_obligation(&canonicalized); if matches!(solution, Some(Solution::Ambig(_))) { self.pending_obligations.push(canonicalized); @@ -798,7 +798,7 @@ impl<'a> InferenceTable<'a> { let trait_data = self.db.trait_data(fn_once_trait); let output_assoc_type = trait_data.associated_type_by_name(&name![Output])?; - let mut arg_tys = vec![]; + let mut arg_tys = Vec::with_capacity(num_args); let arg_ty = TyBuilder::tuple(num_args) .fill(|it| { let arg = match it { @@ -828,11 +828,7 @@ impl<'a> InferenceTable<'a> { environment: trait_env.clone(), }; let canonical = self.canonicalize(obligation.clone()); - if self - .db - .trait_solve(krate, self.trait_env.block, canonical.value.cast(Interner)) - .is_some() - { + if self.db.trait_solve(krate, self.trait_env.block, canonical.cast(Interner)).is_some() { self.register_obligation(obligation.goal); let return_ty = self.normalize_projection_ty(projection); for fn_x in [FnTrait::Fn, FnTrait::FnMut, FnTrait::FnOnce] { @@ -845,7 +841,7 @@ impl<'a> InferenceTable<'a> { let canonical = self.canonicalize(obligation.clone()); if self .db - .trait_solve(krate, self.trait_env.block, canonical.value.cast(Interner)) + .trait_solve(krate, self.trait_env.block, canonical.cast(Interner)) .is_some() { return Some((fn_x, arg_tys, return_ty)); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs b/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs index dea292711d8..9655981cc9c 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs @@ -371,8 +371,8 @@ pub fn layout_of_ty_query( TyKind::Never => cx.layout_of_never_type(), TyKind::Dyn(_) | TyKind::Foreign(_) => { let mut unit = layout_of_unit(&cx, dl)?; - match unit.abi { - Abi::Aggregate { ref mut sized } => *sized = false, + match &mut unit.abi { + Abi::Aggregate { sized } => *sized = false, _ => return Err(LayoutError::Unknown), } unit diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs index e68dbe7b02e..a679a114b4b 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs @@ -213,7 +213,7 @@ impl TraitImpls { // To better support custom derives, collect impls in all unnamed const items. // const _: () = { ... }; - for konst in module_data.scope.unnamed_consts(db.upcast()) { + for konst in module_data.scope.unnamed_consts() { let body = db.body(konst.into()); for (_, block_def_map) in body.blocks(db.upcast()) { Self::collect_def_map(db, map, &block_def_map); @@ -337,7 +337,7 @@ impl InherentImpls { // To better support custom derives, collect impls in all unnamed const items. // const _: () = { ... }; - for konst in module_data.scope.unnamed_consts(db.upcast()) { + for konst in module_data.scope.unnamed_consts() { let body = db.body(konst.into()); for (_, block_def_map) in body.blocks(db.upcast()) { self.collect_def_map(db, &block_def_map); @@ -972,10 +972,9 @@ pub fn iterate_method_candidates_dyn( deref_chain.into_iter().try_for_each(|(receiver_ty, adj)| { iterate_method_candidates_with_autoref( - &receiver_ty, + &mut table, + receiver_ty, adj, - db, - env.clone(), traits_in_scope, visible_from_module, name, @@ -1000,10 +999,9 @@ pub fn iterate_method_candidates_dyn( #[tracing::instrument(skip_all, fields(name = ?name))] fn iterate_method_candidates_with_autoref( - receiver_ty: &Canonical<Ty>, + table: &mut InferenceTable<'_>, + receiver_ty: Canonical<Ty>, first_adjustment: ReceiverAdjustments, - db: &dyn HirDatabase, - env: Arc<TraitEnvironment>, traits_in_scope: &FxHashSet<TraitId>, visible_from_module: VisibleFromModule, name: Option<&Name>, @@ -1016,10 +1014,9 @@ fn iterate_method_candidates_with_autoref( let mut iterate_method_candidates_by_receiver = move |receiver_ty, first_adjustment| { iterate_method_candidates_by_receiver( + table, receiver_ty, first_adjustment, - db, - env.clone(), traits_in_scope, visible_from_module, name, @@ -1034,7 +1031,7 @@ fn iterate_method_candidates_with_autoref( maybe_reborrowed.autoderefs += 1; } - iterate_method_candidates_by_receiver(receiver_ty, maybe_reborrowed)?; + iterate_method_candidates_by_receiver(receiver_ty.clone(), maybe_reborrowed)?; let refed = Canonical { value: TyKind::Ref(Mutability::Not, static_lifetime(), receiver_ty.value.clone()) @@ -1042,7 +1039,7 @@ fn iterate_method_candidates_with_autoref( binders: receiver_ty.binders.clone(), }; - iterate_method_candidates_by_receiver(&refed, first_adjustment.with_autoref(Mutability::Not))?; + iterate_method_candidates_by_receiver(refed, first_adjustment.with_autoref(Mutability::Not))?; let ref_muted = Canonical { value: TyKind::Ref(Mutability::Mut, static_lifetime(), receiver_ty.value.clone()) @@ -1050,58 +1047,53 @@ fn iterate_method_candidates_with_autoref( binders: receiver_ty.binders.clone(), }; - iterate_method_candidates_by_receiver( - &ref_muted, - first_adjustment.with_autoref(Mutability::Mut), - ) + iterate_method_candidates_by_receiver(ref_muted, first_adjustment.with_autoref(Mutability::Mut)) } #[tracing::instrument(skip_all, fields(name = ?name))] fn iterate_method_candidates_by_receiver( - receiver_ty: &Canonical<Ty>, + table: &mut InferenceTable<'_>, + receiver_ty: Canonical<Ty>, receiver_adjustments: ReceiverAdjustments, - db: &dyn HirDatabase, - env: Arc<TraitEnvironment>, traits_in_scope: &FxHashSet<TraitId>, visible_from_module: VisibleFromModule, name: Option<&Name>, mut callback: &mut dyn FnMut(ReceiverAdjustments, AssocItemId, bool) -> ControlFlow<()>, ) -> ControlFlow<()> { - let mut table = InferenceTable::new(db, env); let receiver_ty = table.instantiate_canonical(receiver_ty.clone()); - let snapshot = table.snapshot(); // We're looking for methods with *receiver* type receiver_ty. These could // be found in any of the derefs of receiver_ty, so we have to go through // that, including raw derefs. - let mut autoderef = autoderef::Autoderef::new(&mut table, receiver_ty.clone(), true); - while let Some((self_ty, _)) = autoderef.next() { - iterate_inherent_methods( - &self_ty, - autoderef.table, - name, - Some(&receiver_ty), - Some(receiver_adjustments.clone()), - visible_from_module, - &mut callback, - )? - } - - table.rollback_to(snapshot); - - let mut autoderef = autoderef::Autoderef::new(&mut table, receiver_ty.clone(), true); - while let Some((self_ty, _)) = autoderef.next() { - iterate_trait_method_candidates( - &self_ty, - autoderef.table, - traits_in_scope, - name, - Some(&receiver_ty), - Some(receiver_adjustments.clone()), - &mut callback, - )? - } - - ControlFlow::Continue(()) + table.run_in_snapshot(|table| { + let mut autoderef = autoderef::Autoderef::new(table, receiver_ty.clone(), true); + while let Some((self_ty, _)) = autoderef.next() { + iterate_inherent_methods( + &self_ty, + autoderef.table, + name, + Some(&receiver_ty), + Some(receiver_adjustments.clone()), + visible_from_module, + &mut callback, + )? + } + ControlFlow::Continue(()) + })?; + table.run_in_snapshot(|table| { + let mut autoderef = autoderef::Autoderef::new(table, receiver_ty.clone(), true); + while let Some((self_ty, _)) = autoderef.next() { + iterate_trait_method_candidates( + &self_ty, + autoderef.table, + traits_in_scope, + name, + Some(&receiver_ty), + Some(receiver_adjustments.clone()), + &mut callback, + )? + } + ControlFlow::Continue(()) + }) } #[tracing::instrument(skip_all, fields(name = ?name))] @@ -1147,9 +1139,9 @@ fn iterate_trait_method_candidates( callback: &mut dyn FnMut(ReceiverAdjustments, AssocItemId, bool) -> ControlFlow<()>, ) -> ControlFlow<()> { let db = table.db; - let env = table.trait_env.clone(); - let canonical_self_ty = table.canonicalize(self_ty.clone()).value; + let canonical_self_ty = table.canonicalize(self_ty.clone()); + let TraitEnvironment { krate, block, .. } = *table.trait_env; 'traits: for &t in traits_in_scope { let data = db.trait_data(t); @@ -1164,7 +1156,7 @@ fn iterate_trait_method_candidates( { // FIXME: this should really be using the edition of the method name's span, in case it // comes from a macro - if db.crate_graph()[env.krate].edition < Edition::Edition2021 { + if db.crate_graph()[krate].edition < Edition::Edition2021 { continue; } } @@ -1183,8 +1175,8 @@ fn iterate_trait_method_candidates( IsValidCandidate::No => continue, }; if !known_implemented { - let goal = generic_implements_goal(db, env.clone(), t, &canonical_self_ty); - if db.trait_solve(env.krate, env.block, goal.cast(Interner)).is_none() { + let goal = generic_implements_goal(db, &table.trait_env, t, &canonical_self_ty); + if db.trait_solve(krate, block, goal.cast(Interner)).is_none() { continue 'traits; } } @@ -1365,7 +1357,7 @@ pub(crate) fn resolve_indexing_op( let ty = table.instantiate_canonical(ty); let deref_chain = autoderef_method_receiver(&mut table, ty); for (ty, adj) in deref_chain { - let goal = generic_implements_goal(db, table.trait_env.clone(), index_trait, &ty); + let goal = generic_implements_goal(db, &table.trait_env, index_trait, &ty); if db .trait_solve(table.trait_env.krate, table.trait_env.block, goal.cast(Interner)) .is_some() @@ -1548,7 +1540,7 @@ fn is_valid_impl_fn_candidate( for goal in goals.clone() { let in_env = InEnvironment::new(&table.trait_env.env, goal); - let canonicalized = table.canonicalize(in_env); + let canonicalized = table.canonicalize_with_free_vars(in_env); let solution = table.db.trait_solve( table.trait_env.krate, table.trait_env.block, @@ -1586,10 +1578,10 @@ fn is_valid_impl_fn_candidate( pub fn implements_trait( ty: &Canonical<Ty>, db: &dyn HirDatabase, - env: Arc<TraitEnvironment>, + env: &TraitEnvironment, trait_: TraitId, ) -> bool { - let goal = generic_implements_goal(db, env.clone(), trait_, ty); + let goal = generic_implements_goal(db, env, trait_, ty); let solution = db.trait_solve(env.krate, env.block, goal.cast(Interner)); solution.is_some() @@ -1598,10 +1590,10 @@ pub fn implements_trait( pub fn implements_trait_unique( ty: &Canonical<Ty>, db: &dyn HirDatabase, - env: Arc<TraitEnvironment>, + env: &TraitEnvironment, trait_: TraitId, ) -> bool { - let goal = generic_implements_goal(db, env.clone(), trait_, ty); + let goal = generic_implements_goal(db, env, trait_, ty); let solution = db.trait_solve(env.krate, env.block, goal.cast(Interner)); matches!(solution, Some(crate::Solution::Unique(_))) @@ -1612,32 +1604,34 @@ pub fn implements_trait_unique( #[tracing::instrument(skip_all)] fn generic_implements_goal( db: &dyn HirDatabase, - env: Arc<TraitEnvironment>, + env: &TraitEnvironment, trait_: TraitId, self_ty: &Canonical<Ty>, ) -> Canonical<InEnvironment<super::DomainGoal>> { - let mut kinds = self_ty.binders.interned().to_vec(); + let binders = self_ty.binders.interned(); let trait_ref = TyBuilder::trait_ref(db, trait_) .push(self_ty.value.clone()) - .fill_with_bound_vars(DebruijnIndex::INNERMOST, kinds.len()) + .fill_with_bound_vars(DebruijnIndex::INNERMOST, binders.len()) .build(); - kinds.extend(trait_ref.substitution.iter(Interner).skip(1).map(|it| { - let vk = match it.data(Interner) { - chalk_ir::GenericArgData::Ty(_) => { - chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General) - } - chalk_ir::GenericArgData::Lifetime(_) => chalk_ir::VariableKind::Lifetime, - chalk_ir::GenericArgData::Const(c) => { - chalk_ir::VariableKind::Const(c.data(Interner).ty.clone()) - } - }; - chalk_ir::WithKind::new(vk, UniverseIndex::ROOT) - })); + + let kinds = + binders.iter().cloned().chain(trait_ref.substitution.iter(Interner).skip(1).map(|it| { + let vk = match it.data(Interner) { + chalk_ir::GenericArgData::Ty(_) => { + chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General) + } + chalk_ir::GenericArgData::Lifetime(_) => chalk_ir::VariableKind::Lifetime, + chalk_ir::GenericArgData::Const(c) => { + chalk_ir::VariableKind::Const(c.data(Interner).ty.clone()) + } + }; + chalk_ir::WithKind::new(vk, UniverseIndex::ROOT) + })); + let binders = CanonicalVarKinds::from_iter(Interner, kinds); + let obligation = trait_ref.cast(Interner); - Canonical { - binders: CanonicalVarKinds::from_iter(Interner, kinds), - value: InEnvironment::new(&env.env, obligation), - } + let value = InEnvironment::new(&env.env, obligation); + Canonical { binders, value } } fn autoderef_method_receiver( @@ -1648,7 +1642,7 @@ fn autoderef_method_receiver( let mut autoderef = autoderef::Autoderef::new(table, ty, false); while let Some((ty, derefs)) = autoderef.next() { deref_chain.push(( - autoderef.table.canonicalize(ty).value, + autoderef.table.canonicalize(ty), ReceiverAdjustments { autoref: None, autoderefs: derefs, unsize_array: false }, )); } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/mir.rs b/src/tools/rust-analyzer/crates/hir-ty/src/mir.rs index cfaef2a392c..d5133550377 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/mir.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/mir.rs @@ -1165,6 +1165,7 @@ impl MirBody { pub enum MirSpan { ExprId(ExprId), PatId(PatId), + SelfParam, Unknown, } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs b/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs index 2428678d72b..fd98141af63 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs @@ -376,6 +376,10 @@ impl MirEvalError { Ok(s) => s.map(|it| it.syntax_node_ptr()), Err(_) => continue, }, + MirSpan::SelfParam => match source_map.self_param_syntax() { + Some(s) => s.map(|it| it.syntax_node_ptr()), + None => continue, + }, MirSpan::Unknown => continue, }; let file_id = span.file_id.original_file(db.upcast()); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/mir/lower.rs b/src/tools/rust-analyzer/crates/hir-ty/src/mir/lower.rs index d0f739e6ac6..7e582c03efc 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/mir/lower.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/mir/lower.rs @@ -1810,9 +1810,20 @@ impl<'ctx> MirLowerCtx<'ctx> { fn lower_params_and_bindings( &mut self, params: impl Iterator<Item = (PatId, Ty)> + Clone, + self_binding: Option<(BindingId, Ty)>, pick_binding: impl Fn(BindingId) -> bool, ) -> Result<BasicBlockId> { let base_param_count = self.result.param_locals.len(); + let self_binding = match self_binding { + Some((self_binding, ty)) => { + let local_id = self.result.locals.alloc(Local { ty }); + self.drop_scopes.last_mut().unwrap().locals.push(local_id); + self.result.binding_locals.insert(self_binding, local_id); + self.result.param_locals.push(local_id); + Some(self_binding) + } + None => None, + }; self.result.param_locals.extend(params.clone().map(|(it, ty)| { let local_id = self.result.locals.alloc(Local { ty }); self.drop_scopes.last_mut().unwrap().locals.push(local_id); @@ -1838,9 +1849,23 @@ impl<'ctx> MirLowerCtx<'ctx> { } } let mut current = self.result.start_block; - for ((param, _), local) in - params.zip(self.result.param_locals.clone().into_iter().skip(base_param_count)) - { + if let Some(self_binding) = self_binding { + let local = self.result.param_locals.clone()[base_param_count]; + if local != self.binding_local(self_binding)? { + let r = self.match_self_param(self_binding, current, local)?; + if let Some(b) = r.1 { + self.set_terminator(b, TerminatorKind::Unreachable, MirSpan::SelfParam); + } + current = r.0; + } + } + let local_params = self + .result + .param_locals + .clone() + .into_iter() + .skip(base_param_count + self_binding.is_some() as usize); + for ((param, _), local) in params.zip(local_params) { if let Pat::Bind { id, .. } = self.body[param] { if local == self.binding_local(id)? { continue; @@ -2019,6 +2044,7 @@ pub fn mir_body_for_closure_query( }; let current = ctx.lower_params_and_bindings( args.iter().zip(sig.params().iter()).map(|(it, y)| (*it, y.clone())), + None, |_| true, )?; if let Some(current) = ctx.lower_expr_to_place(*root, return_slot().into(), current)? { @@ -2149,16 +2175,16 @@ pub fn lower_to_mir( let substs = TyBuilder::placeholder_subst(db, fid); let callable_sig = db.callable_item_signature(fid.into()).substitute(Interner, &substs); + let mut params = callable_sig.params().iter(); + let self_param = body.self_param.and_then(|id| Some((id, params.next()?.clone()))); break 'b ctx.lower_params_and_bindings( - body.params - .iter() - .zip(callable_sig.params().iter()) - .map(|(it, y)| (*it, y.clone())), + body.params.iter().zip(params).map(|(it, y)| (*it, y.clone())), + self_param, binding_picker, )?; } } - ctx.lower_params_and_bindings([].into_iter(), binding_picker)? + ctx.lower_params_and_bindings([].into_iter(), None, binding_picker)? }; if let Some(current) = ctx.lower_expr_to_place(root_expr, return_slot().into(), current)? { let current = ctx.pop_drop_scope_assert_finished(current, root_expr.into())?; diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/mir/lower/pattern_matching.rs b/src/tools/rust-analyzer/crates/hir-ty/src/mir/lower/pattern_matching.rs index 90cbd13a6c6..75969067943 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/mir/lower/pattern_matching.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/mir/lower/pattern_matching.rs @@ -11,7 +11,7 @@ use crate::{ Substitution, SwitchTargets, TerminatorKind, TupleFieldId, TupleId, TyBuilder, TyKind, ValueNs, VariantData, VariantId, }, - MutBorrowKind, + LocalId, MutBorrowKind, }, BindingMode, }; @@ -82,6 +82,22 @@ impl MirLowerCtx<'_> { Ok((current, current_else)) } + pub(super) fn match_self_param( + &mut self, + id: BindingId, + current: BasicBlockId, + local: LocalId, + ) -> Result<(BasicBlockId, Option<BasicBlockId>)> { + self.pattern_match_binding( + id, + BindingMode::Move, + local.into(), + MirSpan::SelfParam, + current, + None, + ) + } + fn pattern_match_inner( &mut self, mut current: BasicBlockId, @@ -283,9 +299,9 @@ impl MirLowerCtx<'_> { (current, current_else) = self.pattern_match_inner(current, current_else, next_place, pat, mode)?; } - if let Some(slice) = slice { + if let &Some(slice) = slice { if mode == MatchingMode::Bind { - if let Pat::Bind { id, subpat: _ } = self.body[*slice] { + if let Pat::Bind { id, subpat: _ } = self.body[slice] { let next_place = cond_place.project( ProjectionElem::Subslice { from: prefix.len() as u64, @@ -293,11 +309,12 @@ impl MirLowerCtx<'_> { }, &mut self.result.projection_store, ); + let mode = self.infer.binding_modes[slice]; (current, current_else) = self.pattern_match_binding( id, - *slice, + mode, next_place, - (*slice).into(), + (slice).into(), current, current_else, )?; @@ -398,9 +415,10 @@ impl MirLowerCtx<'_> { self.pattern_match_inner(current, current_else, cond_place, *subpat, mode)? } if mode == MatchingMode::Bind { + let mode = self.infer.binding_modes[pattern]; self.pattern_match_binding( *id, - pattern, + mode, cond_place, pattern.into(), current, @@ -437,14 +455,13 @@ impl MirLowerCtx<'_> { fn pattern_match_binding( &mut self, id: BindingId, - pat: PatId, + mode: BindingMode, cond_place: Place, span: MirSpan, current: BasicBlockId, current_else: Option<BasicBlockId>, ) -> Result<(BasicBlockId, Option<BasicBlockId>)> { let target_place = self.binding_local(id)?; - let mode = self.infer.binding_modes[pat]; self.push_storage_live(id, current)?; self.push_assignment( current, diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests.rs index 5e159236f48..d699067b5a6 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/tests.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests.rs @@ -12,7 +12,7 @@ mod traits; use std::env; -use base_db::{FileRange, SourceDatabaseExt}; +use base_db::{FileRange, SourceDatabaseExt2 as _}; use expect_test::Expect; use hir_def::{ body::{Body, BodySourceMap, SyntheticSyntax}, @@ -164,7 +164,7 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour Some(value) => value, None => continue, }; - let range = node.as_ref().original_file_range(&db); + let range = node.as_ref().original_file_range_rooted(&db); if let Some(expected) = types.remove(&range) { let actual = if display_source { ty.display_source_code(&db, def.module(&db), true).unwrap() @@ -180,7 +180,7 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour Some(value) => value, None => continue, }; - let range = node.as_ref().original_file_range(&db); + let range = node.as_ref().original_file_range_rooted(&db); if let Some(expected) = types.remove(&range) { let actual = if display_source { ty.display_source_code(&db, def.module(&db), true).unwrap() @@ -211,7 +211,7 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour }) else { continue; }; - let range = node.as_ref().original_file_range(&db); + let range = node.as_ref().original_file_range_rooted(&db); let actual = format!( "expected {}, got {}", mismatch.expected.display_test(&db), @@ -293,20 +293,29 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { let mut types: Vec<(InFile<SyntaxNode>, &Ty)> = Vec::new(); let mut mismatches: Vec<(InFile<SyntaxNode>, &TypeMismatch)> = Vec::new(); + if let Some(self_param) = body.self_param { + let ty = &inference_result.type_of_binding[self_param]; + if let Some(syntax_ptr) = body_source_map.self_param_syntax() { + let root = db.parse_or_expand(syntax_ptr.file_id); + let node = syntax_ptr.map(|ptr| ptr.to_node(&root).syntax().clone()); + types.push((node.clone(), ty)); + } + } + for (pat, mut ty) in inference_result.type_of_pat.iter() { if let Pat::Bind { id, .. } = body.pats[pat] { ty = &inference_result.type_of_binding[id]; } - let syntax_ptr = match body_source_map.pat_syntax(pat) { + let node = match body_source_map.pat_syntax(pat) { Ok(sp) => { let root = db.parse_or_expand(sp.file_id); sp.map(|ptr| ptr.to_node(&root).syntax().clone()) } Err(SyntheticSyntax) => continue, }; - types.push((syntax_ptr.clone(), ty)); + types.push((node.clone(), ty)); if let Some(mismatch) = inference_result.type_mismatch_for_pat(pat) { - mismatches.push((syntax_ptr, mismatch)); + mismatches.push((node, mismatch)); } } @@ -575,7 +584,7 @@ fn salsa_bug() { } "; - db.set_file_text(pos.file_id, Arc::from(new_text)); + db.set_file_text(pos.file_id, new_text); let module = db.module_for_file(pos.file_id); let crate_def_map = module.def_map(&db); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/incremental.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/incremental.rs index 82d934009f3..6066ec69c9a 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/incremental.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/incremental.rs @@ -1,6 +1,5 @@ -use base_db::SourceDatabaseExt; +use base_db::SourceDatabaseExt2 as _; use test_fixture::WithFixture; -use triomphe::Arc; use crate::{db::HirDatabase, test_db::TestDB}; @@ -33,7 +32,7 @@ fn foo() -> i32 { 1 }"; - db.set_file_text(pos.file_id, Arc::from(new_text)); + db.set_file_text(pos.file_id, new_text); { let events = db.log_executed(|| { @@ -85,7 +84,7 @@ fn baz() -> i32 { } "; - db.set_file_text(pos.file_id, Arc::from(new_text)); + db.set_file_text(pos.file_id, new_text); { let events = db.log_executed(|| { diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs index c837fae3fef..8609ba41039 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs @@ -1462,28 +1462,6 @@ fn f() { } #[test] -fn trait_impl_in_synstructure_const() { - check_types( - r#" -struct S; - -trait Tr { - fn method(&self) -> u16; -} - -const _DERIVE_Tr_: () = { - impl Tr for S {} -}; - -fn f() { - S.method(); - //^^^^^^^^^^ u16 -} - "#, - ); -} - -#[test] fn inherent_impl_in_unnamed_const() { check_types( r#" @@ -1796,6 +1774,21 @@ fn test() { } #[test] +fn deref_into_inference_var() { + check_types( + r#" +//- minicore:deref +struct A<T>(T); +impl core::ops::Deref for A<u32> {} +impl A<i32> { fn foo(&self) {} } +fn main() { + A(0).foo(); + //^^^^^^^^^^ () +} +"#, + ); +} +#[test] fn receiver_adjustment_autoref() { check( r#" diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs index ffd6a6051b9..917e9f44085 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs @@ -2121,6 +2121,7 @@ async fn main() { "#, expect![[r#" 16..193 '{ ...2 }; }': () + 16..193 '{ ...2 }; }': impl Future<Output = ()> 26..27 'x': i32 30..43 'unsafe { 92 }': i32 39..41 '92': i32 @@ -2131,6 +2132,8 @@ async fn main() { 73..75 '()': () 95..96 'z': ControlFlow<(), ()> 130..140 'try { () }': ControlFlow<(), ()> + 130..140 'try { () }': fn from_output<ControlFlow<(), ()>>(<ControlFlow<(), ()> as Try>::Output) -> ControlFlow<(), ()> + 130..140 'try { () }': ControlFlow<(), ()> 136..138 '()': () 150..151 'w': i32 154..166 'const { 92 }': i32 diff --git a/src/tools/rust-analyzer/crates/hir/src/diagnostics.rs b/src/tools/rust-analyzer/crates/hir/src/diagnostics.rs index fa9fe4953ed..4518422d27e 100644 --- a/src/tools/rust-analyzer/crates/hir/src/diagnostics.rs +++ b/src/tools/rust-analyzer/crates/hir/src/diagnostics.rs @@ -204,7 +204,7 @@ pub struct NoSuchField { #[derive(Debug)] pub struct PrivateAssocItem { - pub expr_or_pat: InFile<AstPtr<Either<ast::Expr, Either<ast::Pat, ast::SelfParam>>>>, + pub expr_or_pat: InFile<AstPtr<Either<ast::Expr, ast::Pat>>>, pub item: AssocItem, } @@ -240,7 +240,7 @@ pub struct UnresolvedMethodCall { #[derive(Debug)] pub struct UnresolvedAssocItem { - pub expr_or_pat: InFile<AstPtr<Either<ast::Expr, Either<ast::Pat, ast::SelfParam>>>>, + pub expr_or_pat: InFile<AstPtr<Either<ast::Expr, ast::Pat>>>, } #[derive(Debug)] diff --git a/src/tools/rust-analyzer/crates/hir/src/display.rs b/src/tools/rust-analyzer/crates/hir/src/display.rs index cdc0db8653c..c5d44c11f2c 100644 --- a/src/tools/rust-analyzer/crates/hir/src/display.rs +++ b/src/tools/rust-analyzer/crates/hir/src/display.rs @@ -159,6 +159,7 @@ impl HirDisplay for Adt { impl HirDisplay for Struct { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { let module_id = self.module(f.db).id; + // FIXME: Render repr if its set explicitly? write_visibility(module_id, self.visibility(f.db), f)?; f.write_str("struct ")?; write!(f, "{}", self.name(f.db).display(f.db.upcast()))?; @@ -166,37 +167,40 @@ impl HirDisplay for Struct { write_generic_params(def_id, f)?; let variant_data = self.variant_data(f.db); - if let StructKind::Tuple = variant_data.kind() { - f.write_char('(')?; - let mut it = variant_data.fields().iter().peekable(); - - while let Some((id, _)) = it.next() { - let field = Field { parent: (*self).into(), id }; - write_visibility(module_id, field.visibility(f.db), f)?; - field.ty(f.db).hir_fmt(f)?; - if it.peek().is_some() { - f.write_str(", ")?; - } - } - - f.write_str(");")?; - } + match variant_data.kind() { + StructKind::Tuple => { + f.write_char('(')?; + let mut it = variant_data.fields().iter().peekable(); - write_where_clause(def_id, f)?; + while let Some((id, _)) = it.next() { + let field = Field { parent: (*self).into(), id }; + write_visibility(module_id, field.visibility(f.db), f)?; + field.ty(f.db).hir_fmt(f)?; + if it.peek().is_some() { + f.write_str(", ")?; + } + } - if let StructKind::Record = variant_data.kind() { - let fields = self.fields(f.db); - if fields.is_empty() { - f.write_str(" {}")?; - } else { - f.write_str(" {\n")?; - for field in self.fields(f.db) { - f.write_str(" ")?; - field.hir_fmt(f)?; - f.write_str(",\n")?; + f.write_char(')')?; + write_where_clause(def_id, f)?; + } + StructKind::Record => { + let has_where_clause = write_where_clause(def_id, f)?; + let fields = self.fields(f.db); + f.write_char(if !has_where_clause { ' ' } else { '\n' })?; + if fields.is_empty() { + f.write_str("{}")?; + } else { + f.write_str("{\n")?; + for field in self.fields(f.db) { + f.write_str(" ")?; + field.hir_fmt(f)?; + f.write_str(",\n")?; + } + f.write_str("}")?; } - f.write_str("}")?; } + StructKind::Unit => _ = write_where_clause(def_id, f)?, } Ok(()) @@ -210,11 +214,12 @@ impl HirDisplay for Enum { write!(f, "{}", self.name(f.db).display(f.db.upcast()))?; let def_id = GenericDefId::AdtId(AdtId::EnumId(self.id)); write_generic_params(def_id, f)?; - write_where_clause(def_id, f)?; + let has_where_clause = write_where_clause(def_id, f)?; let variants = self.variants(f.db); if !variants.is_empty() { - f.write_str(" {\n")?; + f.write_char(if !has_where_clause { ' ' } else { '\n' })?; + f.write_str("{\n")?; for variant in variants { f.write_str(" ")?; variant.hir_fmt(f)?; @@ -234,11 +239,12 @@ impl HirDisplay for Union { write!(f, "{}", self.name(f.db).display(f.db.upcast()))?; let def_id = GenericDefId::AdtId(AdtId::UnionId(self.id)); write_generic_params(def_id, f)?; - write_where_clause(def_id, f)?; + let has_where_clause = write_where_clause(def_id, f)?; let fields = self.fields(f.db); if !fields.is_empty() { - f.write_str(" {\n")?; + f.write_char(if !has_where_clause { ' ' } else { '\n' })?; + f.write_str("{\n")?; for field in self.fields(f.db) { f.write_str(" ")?; field.hir_fmt(f)?; @@ -446,7 +452,10 @@ fn write_generic_params( Ok(()) } -fn write_where_clause(def: GenericDefId, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { +fn write_where_clause( + def: GenericDefId, + f: &mut HirFormatter<'_>, +) -> Result<bool, HirDisplayError> { let params = f.db.generic_params(def); // unnamed type targets are displayed inline with the argument itself, e.g. `f: impl Y`. @@ -465,7 +474,7 @@ fn write_where_clause(def: GenericDefId, f: &mut HirFormatter<'_>) -> Result<(), }); if !has_displayable_predicate { - return Ok(()); + return Ok(false); } let write_target = |target: &WherePredicateTypeTarget, f: &mut HirFormatter<'_>| match target { @@ -543,7 +552,7 @@ fn write_where_clause(def: GenericDefId, f: &mut HirFormatter<'_>) -> Result<(), // End of final predicate. There must be at least one predicate here. f.write_char(',')?; - Ok(()) + Ok(true) } impl HirDisplay for Const { @@ -594,19 +603,20 @@ impl HirDisplay for Trait { write!(f, "trait {}", data.name.display(f.db.upcast()))?; let def_id = GenericDefId::TraitId(self.id); write_generic_params(def_id, f)?; - write_where_clause(def_id, f)?; + let has_where_clause = write_where_clause(def_id, f)?; if let Some(limit) = f.entity_limit { let assoc_items = self.items(f.db); let count = assoc_items.len().min(limit); + f.write_char(if !has_where_clause { ' ' } else { '\n' })?; if count == 0 { if assoc_items.is_empty() { - f.write_str(" {}")?; + f.write_str("{}")?; } else { - f.write_str(" { /* … */ }")?; + f.write_str("{ /* … */ }")?; } } else { - f.write_str(" {\n")?; + f.write_str("{\n")?; for item in &assoc_items[..count] { f.write_str(" ")?; match item { @@ -651,7 +661,6 @@ impl HirDisplay for TypeAlias { write!(f, "type {}", data.name.display(f.db.upcast()))?; let def_id = GenericDefId::TypeAliasId(self.id); write_generic_params(def_id, f)?; - write_where_clause(def_id, f)?; if !data.bounds.is_empty() { f.write_str(": ")?; f.write_joined(data.bounds.iter(), " + ")?; @@ -660,6 +669,7 @@ impl HirDisplay for TypeAlias { f.write_str(" = ")?; ty.hir_fmt(f)?; } + write_where_clause(def_id, f)?; Ok(()) } } diff --git a/src/tools/rust-analyzer/crates/hir/src/has_source.rs b/src/tools/rust-analyzer/crates/hir/src/has_source.rs index d10884517f9..7cdcdd76d18 100644 --- a/src/tools/rust-analyzer/crates/hir/src/has_source.rs +++ b/src/tools/rust-analyzer/crates/hir/src/has_source.rs @@ -9,6 +9,7 @@ use hir_def::{ }; use hir_expand::{HirFileId, InFile}; use syntax::ast; +use tt::TextRange; use crate::{ db::HirDatabase, Adt, Const, Enum, ExternCrateDecl, Field, FieldSource, Function, Impl, @@ -37,6 +38,12 @@ impl Module { def_map[self.id.local_id].definition_source(db.upcast()) } + /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. + pub fn definition_source_range(self, db: &dyn HirDatabase) -> InFile<TextRange> { + let def_map = self.id.def_map(db.upcast()); + def_map[self.id.local_id].definition_source_range(db.upcast()) + } + pub fn definition_source_file_id(self, db: &dyn HirDatabase) -> HirFileId { let def_map = self.id.def_map(db.upcast()); def_map[self.id.local_id].definition_source_file_id() @@ -71,6 +78,13 @@ impl Module { let def_map = self.id.def_map(db.upcast()); def_map[self.id.local_id].declaration_source(db.upcast()) } + + /// Returns a text range which declares this module, either a `mod foo;` or a `mod foo {}`. + /// `None` for the crate root. + pub fn declaration_source_range(self, db: &dyn HirDatabase) -> Option<InFile<TextRange>> { + let def_map = self.id.def_map(db.upcast()); + def_map[self.id.local_id].declaration_source_range(db.upcast()) + } } impl HasSource for Field { diff --git a/src/tools/rust-analyzer/crates/hir/src/lib.rs b/src/tools/rust-analyzer/crates/hir/src/lib.rs index 5eed7ecd5b2..b922aa8e46d 100644 --- a/src/tools/rust-analyzer/crates/hir/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir/src/lib.rs @@ -56,8 +56,8 @@ use hir_def::{ AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId, CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId, ExternCrateId, FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, InTypeConstId, ItemContainerId, LifetimeParamId, LocalFieldId, Lookup, MacroExpander, - MacroId, ModuleId, StaticId, StructId, TraitAliasId, TraitId, TupleId, TypeAliasId, - TypeOrConstParamId, TypeParamId, UnionId, + ModuleId, StaticId, StructId, TraitAliasId, TraitId, TupleId, TypeAliasId, TypeOrConstParamId, + TypeParamId, UnionId, }; use hir_expand::{attrs::collect_attrs, name::name, proc_macro::ProcMacroKind, MacroCallKind}; use hir_ty::{ @@ -122,7 +122,7 @@ pub use { visibility::Visibility, // FIXME: This is here since some queries take it as input that are used // outside of hir. - {AdtId, ModuleDefId}, + {AdtId, MacroId, ModuleDefId}, }, hir_expand::{ attrs::{Attr, AttrId}, @@ -754,7 +754,7 @@ impl Module { scope .declarations() .map(ModuleDef::from) - .chain(scope.unnamed_consts(db.upcast()).map(|id| ModuleDef::Const(Const::from(id)))) + .chain(scope.unnamed_consts().map(|id| ModuleDef::Const(Const::from(id)))) .collect() } @@ -1725,6 +1725,10 @@ impl DefWithBody { Ok(s) => s.map(|it| it.into()), Err(_) => continue, }, + mir::MirSpan::SelfParam => match source_map.self_param_syntax() { + Some(s) => s.map(|it| it.into()), + None => continue, + }, mir::MirSpan::Unknown => continue, }; acc.push( @@ -1776,6 +1780,11 @@ impl DefWithBody { Ok(s) => s.map(|it| it.into()), Err(_) => continue, }, + mir::MirSpan::SelfParam => match source_map.self_param_syntax() + { + Some(s) => s.map(|it| it.into()), + None => continue, + }, mir::MirSpan::Unknown => continue, }; acc.push(NeedMut { local, span }.into()); @@ -2127,8 +2136,11 @@ impl Param { pub fn as_local(&self, db: &dyn HirDatabase) -> Option<Local> { let parent = DefWithBodyId::FunctionId(self.func.into()); let body = db.body(parent); - let pat_id = body.params[self.idx]; - if let Pat::Bind { id, .. } = &body[pat_id] { + if let Some(self_param) = body.self_param.filter(|_| self.idx == 0) { + Some(Local { parent, binding_id: self_param }) + } else if let Pat::Bind { id, .. } = + &body[body.params[self.idx - body.self_param.is_some() as usize]] + { Some(Local { parent, binding_id: *id }) } else { None @@ -2143,7 +2155,7 @@ impl Param { let InFile { file_id, value } = self.func.source(db)?; let params = value.param_list()?; if params.self_param().is_some() { - params.params().nth(self.idx.checked_sub(1)?) + params.params().nth(self.idx.checked_sub(params.self_param().is_some() as usize)?) } else { params.params().nth(self.idx) } @@ -2605,6 +2617,15 @@ impl Macro { } } + pub fn is_env_or_option_env(&self, db: &dyn HirDatabase) -> bool { + match self.id { + MacroId::Macro2Id(it) => { + matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltInEager(eager) if eager.is_env_or_option_env()) + } + MacroId::MacroRulesId(_) | MacroId::ProcMacroId(_) => false, + } + } + pub fn is_attr(&self, db: &dyn HirDatabase) -> bool { matches!(self.kind(db), MacroKind::Attr) } @@ -3134,35 +3155,59 @@ impl Local { /// All definitions for this local. Example: `let (a$0, _) | (_, a$0) = it;` pub fn sources(self, db: &dyn HirDatabase) -> Vec<LocalSource> { let (body, source_map) = db.body_with_source_map(self.parent); - self.sources_(db, &body, &source_map).collect() + match body.self_param.zip(source_map.self_param_syntax()) { + Some((param, source)) if param == self.binding_id => { + let root = source.file_syntax(db.upcast()); + vec![LocalSource { + local: self, + source: source.map(|ast| Either::Right(ast.to_node(&root))), + }] + } + _ => body[self.binding_id] + .definitions + .iter() + .map(|&definition| { + let src = source_map.pat_syntax(definition).unwrap(); // Hmm... + let root = src.file_syntax(db.upcast()); + LocalSource { + local: self, + source: src.map(|ast| match ast.to_node(&root) { + ast::Pat::IdentPat(it) => Either::Left(it), + _ => unreachable!("local with non ident-pattern"), + }), + } + }) + .collect(), + } } /// The leftmost definition for this local. Example: `let (a$0, _) | (_, a) = it;` pub fn primary_source(self, db: &dyn HirDatabase) -> LocalSource { let (body, source_map) = db.body_with_source_map(self.parent); - let src = self.sources_(db, &body, &source_map).next().unwrap(); - src - } - - fn sources_<'a>( - self, - db: &'a dyn HirDatabase, - body: &'a hir_def::body::Body, - source_map: &'a hir_def::body::BodySourceMap, - ) -> impl Iterator<Item = LocalSource> + 'a { - body[self.binding_id] - .definitions - .iter() - .map(|&definition| { - let src = source_map.pat_syntax(definition).unwrap(); // Hmm... - let root = src.file_syntax(db.upcast()); - src.map(|ast| match ast.to_node(&root) { - Either::Left(ast::Pat::IdentPat(it)) => Either::Left(it), - Either::Left(_) => unreachable!("local with non ident-pattern"), - Either::Right(it) => Either::Right(it), + match body.self_param.zip(source_map.self_param_syntax()) { + Some((param, source)) if param == self.binding_id => { + let root = source.file_syntax(db.upcast()); + LocalSource { + local: self, + source: source.map(|ast| Either::Right(ast.to_node(&root))), + } + } + _ => body[self.binding_id] + .definitions + .first() + .map(|&definition| { + let src = source_map.pat_syntax(definition).unwrap(); // Hmm... + let root = src.file_syntax(db.upcast()); + LocalSource { + local: self, + source: src.map(|ast| match ast.to_node(&root) { + ast::Pat::IdentPat(it) => Either::Left(it), + _ => unreachable!("local with non ident-pattern"), + }), + } }) - }) - .map(move |source| LocalSource { local: self, source }) + .unwrap(), + } } } @@ -4037,7 +4082,7 @@ impl Type { let canonical_ty = Canonical { value: self.ty.clone(), binders: CanonicalVarKinds::empty(Interner) }; - method_resolution::implements_trait(&canonical_ty, db, self.env.clone(), trait_) + method_resolution::implements_trait(&canonical_ty, db, &self.env, trait_) } /// Checks that particular type `ty` implements `std::ops::FnOnce`. @@ -4052,12 +4097,7 @@ impl Type { let canonical_ty = Canonical { value: self.ty.clone(), binders: CanonicalVarKinds::empty(Interner) }; - method_resolution::implements_trait_unique( - &canonical_ty, - db, - self.env.clone(), - fnonce_trait, - ) + method_resolution::implements_trait_unique(&canonical_ty, db, &self.env, fnonce_trait) } // FIXME: Find better API that also handles const generics diff --git a/src/tools/rust-analyzer/crates/hir/src/semantics.rs b/src/tools/rust-analyzer/crates/hir/src/semantics.rs index 99907ea15b5..9796009cb45 100644 --- a/src/tools/rust-analyzer/crates/hir/src/semantics.rs +++ b/src/tools/rust-analyzer/crates/hir/src/semantics.rs @@ -681,28 +681,29 @@ impl<'db> SemanticsImpl<'db> { .filter(|&(_, include_file_id)| include_file_id == file_id) { let macro_file = invoc.as_macro_file(); - let expansion_info = cache - .entry(macro_file) - .or_insert_with(|| macro_file.expansion_info(self.db.upcast())); + let expansion_info = cache.entry(macro_file).or_insert_with(|| { + let exp_info = macro_file.expansion_info(self.db.upcast()); + + let InMacroFile { file_id, value } = exp_info.expanded(); + self.cache(value, file_id.into()); + + exp_info + }); // Create the source analyzer for the macro call scope let Some(sa) = self.analyze_no_infer(&self.parse_or_expand(expansion_info.call_file())) else { continue; }; - { - let InMacroFile { file_id: macro_file, value } = expansion_info.expanded(); - self.cache(value, macro_file.into()); - } // get mapped token in the include! macro file - let span = span::SpanData { + let span = span::Span { range: token.text_range(), anchor: span::SpanAnchor { file_id, ast_id: ROOT_ERASED_FILE_AST_ID }, ctx: SyntaxContextId::ROOT, }; let Some(InMacroFile { file_id, value: mut mapped_tokens }) = - expansion_info.map_range_down(span) + expansion_info.map_range_down_exact(span) else { continue; }; @@ -753,22 +754,20 @@ impl<'db> SemanticsImpl<'db> { let def_map = sa.resolver.def_map(); let mut stack: Vec<(_, SmallVec<[_; 2]>)> = vec![(file_id, smallvec![token])]; - let mut process_expansion_for_token = |stack: &mut Vec<_>, macro_file| { - let expansion_info = cache - .entry(macro_file) - .or_insert_with(|| macro_file.expansion_info(self.db.upcast())); + let exp_info = cache.entry(macro_file).or_insert_with(|| { + let exp_info = macro_file.expansion_info(self.db.upcast()); - { - let InMacroFile { file_id, value } = expansion_info.expanded(); + let InMacroFile { file_id, value } = exp_info.expanded(); self.cache(value, file_id.into()); - } - let InMacroFile { file_id, value: mapped_tokens } = - expansion_info.map_range_down(span)?; + exp_info + }); + + let InMacroFile { file_id, value: mapped_tokens } = exp_info.map_range_down(span)?; let mapped_tokens: SmallVec<[_; 2]> = mapped_tokens.collect(); - // if the length changed we have found a mapping for the token + // we have found a mapping for the token if the vec is non-empty let res = mapped_tokens.is_empty().not().then_some(()); // requeue the tokens we got from mapping our current token down stack.push((HirFileId::from(file_id), mapped_tokens)); @@ -851,7 +850,13 @@ impl<'db> SemanticsImpl<'db> { // remove any other token in this macro input, all their mappings are the // same as this one tokens.retain(|t| !text_range.contains_range(t.text_range())); - process_expansion_for_token(&mut stack, file_id) + + process_expansion_for_token(&mut stack, file_id).or(file_id + .eager_arg(self.db.upcast()) + .and_then(|arg| { + // also descend into eager expansions + process_expansion_for_token(&mut stack, arg.as_macro_file()) + })) } else if let Some(meta) = ast::Meta::cast(parent) { // attribute we failed expansion for earlier, this might be a derive invocation // or derive helper attribute @@ -960,7 +965,7 @@ impl<'db> SemanticsImpl<'db> { /// macro file the node resides in. pub fn original_range(&self, node: &SyntaxNode) -> FileRange { let node = self.find_file(node); - node.original_file_range(self.db.upcast()) + node.original_file_range_rooted(self.db.upcast()) } /// Attempts to map the node out of macro expanded files returning the original file range. @@ -984,9 +989,9 @@ impl<'db> SemanticsImpl<'db> { /// Attempts to map the node out of macro expanded files. /// This only work for attribute expansions, as other ones do not have nodes as input. - pub fn original_syntax_node(&self, node: &SyntaxNode) -> Option<SyntaxNode> { + pub fn original_syntax_node_rooted(&self, node: &SyntaxNode) -> Option<SyntaxNode> { let InFile { file_id, .. } = self.find_file(node); - InFile::new(file_id, node).original_syntax_node(self.db.upcast()).map( + InFile::new(file_id, node).original_syntax_node_rooted(self.db.upcast()).map( |InRealFile { file_id, value }| { self.cache(find_root(&value), file_id.into()); value @@ -997,7 +1002,7 @@ impl<'db> SemanticsImpl<'db> { pub fn diagnostics_display_range(&self, src: InFile<SyntaxNodePtr>) -> FileRange { let root = self.parse_or_expand(src.file_id); let node = src.map(|it| it.to_node(&root)); - node.as_ref().original_file_range(self.db.upcast()) + node.as_ref().original_file_range_rooted(self.db.upcast()) } fn token_ancestors_with_macros( @@ -1236,6 +1241,11 @@ impl<'db> SemanticsImpl<'db> { sa.resolve_macro_call(self.db, macro_call) } + pub fn is_proc_macro_call(&self, macro_call: &ast::MacroCall) -> bool { + self.resolve_macro_call(macro_call) + .map_or(false, |m| matches!(m.id, MacroId::ProcMacroId(..))) + } + pub fn is_unsafe_macro_call(&self, macro_call: &ast::MacroCall) -> bool { let sa = match self.analyze(macro_call.syntax()) { Some(it) => it, diff --git a/src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs b/src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs index 4733ea5a35b..d4d6f0b243f 100644 --- a/src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs +++ b/src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs @@ -101,7 +101,7 @@ use hir_def::{ use hir_expand::{attrs::AttrId, name::AsName, HirFileId, HirFileIdExt, MacroCallId}; use rustc_hash::FxHashMap; use smallvec::SmallVec; -use stdx::{impl_from, never}; +use stdx::impl_from; use syntax::{ ast::{self, HasName}, AstNode, SyntaxNode, @@ -253,14 +253,8 @@ impl SourceToDefCtx<'_, '_> { src: InFile<ast::SelfParam>, ) -> Option<(DefWithBodyId, BindingId)> { let container = self.find_pat_or_label_container(src.syntax())?; - let (body, source_map) = self.db.body_with_source_map(container); - let pat_id = source_map.node_self_param(src.as_ref())?; - if let crate::Pat::Bind { id, .. } = body[pat_id] { - Some((container, id)) - } else { - never!(); - None - } + let body = self.db.body(container); + Some((container, body.self_param?)) } pub(super) fn label_to_def( &mut self, diff --git a/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs b/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs index f87e0a3897a..dc96a1b03d0 100644 --- a/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs +++ b/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs @@ -219,11 +219,10 @@ impl SourceAnalyzer { pub(crate) fn type_of_self( &self, db: &dyn HirDatabase, - param: &ast::SelfParam, + _param: &ast::SelfParam, ) -> Option<Type> { - let src = InFile { file_id: self.file_id, value: param }; - let pat_id = self.body_source_map()?.node_self_param(src)?; - let ty = self.infer.as_ref()?[pat_id].clone(); + let binding = self.body()?.self_param?; + let ty = self.infer.as_ref()?[binding].clone(); Some(Type::new_with_resolver(db, &self.resolver, ty)) } diff --git a/src/tools/rust-analyzer/crates/hir/src/symbols.rs b/src/tools/rust-analyzer/crates/hir/src/symbols.rs index 28ac5940e69..3b88836c24b 100644 --- a/src/tools/rust-analyzer/crates/hir/src/symbols.rs +++ b/src/tools/rust-analyzer/crates/hir/src/symbols.rs @@ -49,7 +49,7 @@ impl DeclarationLocation { return FileRange { file_id, range: self.ptr.text_range() }; } let node = resolve_node(db, self.hir_file_id, &self.ptr); - node.as_ref().original_file_range(db.upcast()) + node.as_ref().original_file_range_rooted(db.upcast()) } } @@ -165,7 +165,6 @@ impl<'a> SymbolCollector<'a> { // Record renamed imports. // FIXME: In case it imports multiple items under different namespaces we just pick one arbitrarily // for now. - // FIXME: This parses! for id in scope.imports() { let source = id.import.child_source(self.db.upcast()); let Some(use_tree_src) = source.value.get(id.idx) else { continue }; @@ -196,7 +195,7 @@ impl<'a> SymbolCollector<'a> { }); } - for const_id in scope.unnamed_consts(self.db.upcast()) { + for const_id in scope.unnamed_consts() { self.collect_from_body(const_id); } diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_module.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_module.rs index af834c8a53d..42f935651cf 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_module.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_module.rs @@ -1,5 +1,6 @@ use std::iter; +use either::Either; use hir::{HasSource, HirFileIdExt, ModuleSource}; use ide_db::{ assists::{AssistId, AssistKind}, @@ -10,17 +11,16 @@ use ide_db::{ }; use itertools::Itertools; use smallvec::SmallVec; -use stdx::format_to; use syntax::{ algo::find_node_at_range, ast::{ self, edit::{AstNodeEdit, IndentLevel}, - make, HasName, HasVisibility, + make, HasVisibility, }, - match_ast, ted, AstNode, SourceFile, + match_ast, ted, AstNode, SyntaxKind::{self, WHITESPACE}, - SyntaxNode, TextRange, + SyntaxNode, TextRange, TextSize, }; use crate::{AssistContext, Assists}; @@ -109,76 +109,35 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti //We are getting item usages and record_fields together, record_fields //for change_visibility and usages for first point mentioned above in the process - let (usages_to_be_processed, record_fields) = module.get_usages_and_record_fields(ctx); - let import_paths_to_be_removed = module.resolve_imports(curr_parent_module, ctx); - module.change_visibility(record_fields); - - let mut body_items: Vec<String> = Vec::new(); - let mut items_to_be_processed: Vec<ast::Item> = module.body_items.clone(); - - let new_item_indent = if impl_parent.is_some() { - old_item_indent + 2 - } else { - items_to_be_processed = [module.use_items.clone(), items_to_be_processed].concat(); - old_item_indent + 1 - }; - - for item in items_to_be_processed { - let item = item.indent(IndentLevel(1)); - let mut indented_item = String::new(); - format_to!(indented_item, "{new_item_indent}{item}"); - body_items.push(indented_item); - } - - let mut body = body_items.join("\n\n"); - - if let Some(impl_) = &impl_parent { - let mut impl_body_def = String::new(); - - if let Some(self_ty) = impl_.self_ty() { - { - let impl_indent = old_item_indent + 1; - format_to!( - impl_body_def, - "{impl_indent}impl {self_ty} {{\n{body}\n{impl_indent}}}", - ); - } - body = impl_body_def; + let (usages_to_be_processed, record_fields, use_stmts_to_be_inserted) = + module.get_usages_and_record_fields(ctx); - // Add the import for enum/struct corresponding to given impl block - module.make_use_stmt_of_node_with_super(self_ty.syntax()); - for item in module.use_items { - let item_indent = old_item_indent + 1; - body = format!("{item_indent}{item}\n\n{body}"); - } - } - } + builder.edit_file(ctx.file_id()); + use_stmts_to_be_inserted.into_iter().for_each(|(_, use_stmt)| { + builder.insert(ctx.selection_trimmed().end(), format!("\n{use_stmt}")); + }); - let mut module_def = String::new(); + let import_paths_to_be_removed = module.resolve_imports(curr_parent_module, ctx); + module.change_visibility(record_fields); - let module_name = module.name; - format_to!(module_def, "mod {module_name} {{\n{body}\n{old_item_indent}}}"); + let module_def = generate_module_def(&impl_parent, &mut module, old_item_indent); - let mut usages_to_be_updated_for_curr_file = vec![]; - for usages_to_be_updated_for_file in usages_to_be_processed { - if usages_to_be_updated_for_file.0 == ctx.file_id() { - usages_to_be_updated_for_curr_file = usages_to_be_updated_for_file.1; + let mut usages_to_be_processed_for_cur_file = vec![]; + for (file_id, usages) in usages_to_be_processed { + if file_id == ctx.file_id() { + usages_to_be_processed_for_cur_file = usages; continue; } - builder.edit_file(usages_to_be_updated_for_file.0); - for usage_to_be_processed in usages_to_be_updated_for_file.1 { - builder.replace(usage_to_be_processed.0, usage_to_be_processed.1) + builder.edit_file(file_id); + for (text_range, usage) in usages { + builder.replace(text_range, usage) } } builder.edit_file(ctx.file_id()); - for usage_to_be_processed in usages_to_be_updated_for_curr_file { - builder.replace(usage_to_be_processed.0, usage_to_be_processed.1) - } - - for import_path_text_range in import_paths_to_be_removed { - builder.delete(import_path_text_range); + for (text_range, usage) in usages_to_be_processed_for_cur_file { + builder.replace(text_range, usage); } if let Some(impl_) = impl_parent { @@ -199,12 +158,51 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti builder.insert(impl_.syntax().text_range().end(), format!("\n\n{module_def}")); } else { + for import_path_text_range in import_paths_to_be_removed { + if module.text_range.intersect(import_path_text_range).is_some() { + module.text_range = module.text_range.cover(import_path_text_range); + } else { + builder.delete(import_path_text_range); + } + } + builder.replace(module.text_range, module_def) } }, ) } +fn generate_module_def( + parent_impl: &Option<ast::Impl>, + module: &mut Module, + old_indent: IndentLevel, +) -> String { + let (items_to_be_processed, new_item_indent) = if parent_impl.is_some() { + (Either::Left(module.body_items.iter()), old_indent + 2) + } else { + (Either::Right(module.use_items.iter().chain(module.body_items.iter())), old_indent + 1) + }; + + let mut body = items_to_be_processed + .map(|item| item.indent(IndentLevel(1))) + .map(|item| format!("{new_item_indent}{item}")) + .join("\n\n"); + + if let Some(self_ty) = parent_impl.as_ref().and_then(|imp| imp.self_ty()) { + let impl_indent = old_indent + 1; + body = format!("{impl_indent}impl {self_ty} {{\n{body}\n{impl_indent}}}"); + + // Add the import for enum/struct corresponding to given impl block + module.make_use_stmt_of_node_with_super(self_ty.syntax()); + for item in module.use_items.iter() { + body = format!("{impl_indent}{item}\n\n{body}"); + } + } + + let module_name = module.name; + format!("mod {module_name} {{\n{body}\n{old_indent}}}") +} + #[derive(Debug)] struct Module { text_range: TextRange, @@ -233,20 +231,24 @@ impl Module { fn get_usages_and_record_fields( &self, ctx: &AssistContext<'_>, - ) -> (FxHashMap<FileId, Vec<(TextRange, String)>>, Vec<SyntaxNode>) { + ) -> (FxHashMap<FileId, Vec<(TextRange, String)>>, Vec<SyntaxNode>, FxHashMap<TextSize, ast::Use>) + { let mut adt_fields = Vec::new(); let mut refs: FxHashMap<FileId, Vec<(TextRange, String)>> = FxHashMap::default(); + // use `TextSize` as key to avoid repeated use stmts + let mut use_stmts_to_be_inserted = FxHashMap::default(); //Here impl is not included as each item inside impl will be tied to the parent of //implementing block(a struct, enum, etc), if the parent is in selected module, it will //get updated by ADT section given below or if it is not, then we dont need to do any operation + for item in &self.body_items { match_ast! { match (item.syntax()) { ast::Adt(it) => { if let Some( nod ) = ctx.sema.to_def(&it) { let node_def = Definition::Adt(nod); - self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs); + self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs, &mut use_stmts_to_be_inserted); //Enum Fields are not allowed to explicitly specify pub, it is implied match it { @@ -280,30 +282,30 @@ impl Module { ast::TypeAlias(it) => { if let Some( nod ) = ctx.sema.to_def(&it) { let node_def = Definition::TypeAlias(nod); - self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs); + self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs, &mut use_stmts_to_be_inserted); } }, ast::Const(it) => { if let Some( nod ) = ctx.sema.to_def(&it) { let node_def = Definition::Const(nod); - self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs); + self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs, &mut use_stmts_to_be_inserted); } }, ast::Static(it) => { if let Some( nod ) = ctx.sema.to_def(&it) { let node_def = Definition::Static(nod); - self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs); + self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs, &mut use_stmts_to_be_inserted); } }, ast::Fn(it) => { if let Some( nod ) = ctx.sema.to_def(&it) { let node_def = Definition::Function(nod); - self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs); + self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs, &mut use_stmts_to_be_inserted); } }, ast::Macro(it) => { if let Some(nod) = ctx.sema.to_def(&it) { - self.expand_and_group_usages_file_wise(ctx, Definition::Macro(nod), &mut refs); + self.expand_and_group_usages_file_wise(ctx, Definition::Macro(nod), &mut refs, &mut use_stmts_to_be_inserted); } }, _ => (), @@ -311,7 +313,7 @@ impl Module { } } - (refs, adt_fields) + (refs, adt_fields, use_stmts_to_be_inserted) } fn expand_and_group_usages_file_wise( @@ -319,49 +321,62 @@ impl Module { ctx: &AssistContext<'_>, node_def: Definition, refs_in_files: &mut FxHashMap<FileId, Vec<(TextRange, String)>>, + use_stmts_to_be_inserted: &mut FxHashMap<TextSize, ast::Use>, ) { - for (file_id, references) in node_def.usages(&ctx.sema).all() { + let mod_name = self.name; + let covering_node = match ctx.covering_element() { + syntax::NodeOrToken::Node(node) => node, + syntax::NodeOrToken::Token(tok) => tok.parent().unwrap(), // won't panic + }; + let out_of_sel = |node: &SyntaxNode| !self.text_range.contains_range(node.text_range()); + let mut use_stmts_set = FxHashSet::default(); + + for (file_id, refs) in node_def.usages(&ctx.sema).all() { let source_file = ctx.sema.parse(file_id); - let usages_in_file = references - .into_iter() - .filter_map(|usage| self.get_usage_to_be_processed(&source_file, usage)); - refs_in_files.entry(file_id).or_default().extend(usages_in_file); - } - } - - fn get_usage_to_be_processed( - &self, - source_file: &SourceFile, - FileReference { range, name, .. }: FileReference, - ) -> Option<(TextRange, String)> { - let path: ast::Path = find_node_at_range(source_file.syntax(), range)?; - - for desc in path.syntax().descendants() { - if desc.to_string() == name.syntax().to_string() - && !self.text_range.contains_range(desc.text_range()) - { - if let Some(name_ref) = ast::NameRef::cast(desc) { - let mod_name = self.name; - return Some(( - name_ref.syntax().text_range(), - format!("{mod_name}::{name_ref}"), - )); + let usages = refs.into_iter().filter_map(|FileReference { range, .. }| { + // handle normal usages + let name_ref = find_node_at_range::<ast::NameRef>(source_file.syntax(), range)?; + + if out_of_sel(name_ref.syntax()) { + let new_ref = format!("{mod_name}::{name_ref}"); + return Some((range, new_ref)); + } else if let Some(use_) = name_ref.syntax().ancestors().find_map(ast::Use::cast) { + // handle usages in use_stmts which is in_sel + // check if `use` is top stmt in selection + if use_.syntax().parent().is_some_and(|parent| parent == covering_node) + && use_stmts_set.insert(use_.syntax().text_range().start()) + { + let use_ = use_stmts_to_be_inserted + .entry(use_.syntax().text_range().start()) + .or_insert_with(|| use_.clone_subtree().clone_for_update()); + for seg in use_ + .syntax() + .descendants() + .filter_map(ast::NameRef::cast) + .filter(|seg| seg.syntax().to_string() == name_ref.to_string()) + { + let new_ref = make::path_from_text(&format!("{mod_name}::{seg}")) + .clone_for_update(); + ted::replace(seg.syntax().parent()?, new_ref.syntax()); + } + } } - } - } - None + None + }); + refs_in_files.entry(file_id).or_default().extend(usages); + } } fn change_visibility(&mut self, record_fields: Vec<SyntaxNode>) { let (mut replacements, record_field_parents, impls) = get_replacements_for_visibility_change(&mut self.body_items, false); - let mut impl_items: Vec<ast::Item> = impls + let mut impl_items = impls .into_iter() .flat_map(|impl_| impl_.syntax().descendants()) .filter_map(ast::Item::cast) - .collect(); + .collect_vec(); let (mut impl_item_replacements, _, _) = get_replacements_for_visibility_change(&mut impl_items, true); @@ -394,133 +409,88 @@ impl Module { fn resolve_imports( &mut self, - curr_parent_module: Option<ast::Module>, + module: Option<ast::Module>, ctx: &AssistContext<'_>, ) -> Vec<TextRange> { - let mut import_paths_to_be_removed: Vec<TextRange> = vec![]; - let mut node_set: FxHashSet<String> = FxHashSet::default(); + let mut imports_to_remove = vec![]; + let mut node_set = FxHashSet::default(); for item in self.body_items.clone() { - for x in item.syntax().descendants() { - if let Some(name) = ast::Name::cast(x.clone()) { - if let Some(name_classify) = NameClass::classify(&ctx.sema, &name) { - //Necessary to avoid two same names going through - if !node_set.contains(&name.syntax().to_string()) { - node_set.insert(name.syntax().to_string()); - let def_opt: Option<Definition> = match name_classify { - NameClass::Definition(def) => Some(def), - _ => None, - }; - - if let Some(def) = def_opt { - if let Some(import_path) = self - .process_names_and_namerefs_for_import_resolve( - def, - name.syntax(), - &curr_parent_module, - ctx, - ) - { - check_intersection_and_push( - &mut import_paths_to_be_removed, - import_path, - ); - } - } - } + item.syntax() + .descendants() + .filter_map(|x| { + if let Some(name) = ast::Name::cast(x.clone()) { + NameClass::classify(&ctx.sema, &name).and_then(|nc| match nc { + NameClass::Definition(def) => Some((name.syntax().clone(), def)), + _ => None, + }) + } else if let Some(name_ref) = ast::NameRef::cast(x) { + NameRefClass::classify(&ctx.sema, &name_ref).and_then(|nc| match nc { + NameRefClass::Definition(def) => Some((name_ref.syntax().clone(), def)), + _ => None, + }) + } else { + None } - } - - if let Some(name_ref) = ast::NameRef::cast(x) { - if let Some(name_classify) = NameRefClass::classify(&ctx.sema, &name_ref) { - //Necessary to avoid two same names going through - if !node_set.contains(&name_ref.syntax().to_string()) { - node_set.insert(name_ref.syntax().to_string()); - let def_opt: Option<Definition> = match name_classify { - NameRefClass::Definition(def) => Some(def), - _ => None, - }; - - if let Some(def) = def_opt { - if let Some(import_path) = self - .process_names_and_namerefs_for_import_resolve( - def, - name_ref.syntax(), - &curr_parent_module, - ctx, - ) - { - check_intersection_and_push( - &mut import_paths_to_be_removed, - import_path, - ); - } - } + }) + .for_each(|(node, def)| { + if node_set.insert(node.to_string()) { + if let Some(import) = self.process_def_in_sel(def, &node, &module, ctx) { + check_intersection_and_push(&mut imports_to_remove, import); } } - } - } + }) } - import_paths_to_be_removed + imports_to_remove } - fn process_names_and_namerefs_for_import_resolve( + fn process_def_in_sel( &mut self, def: Definition, - node_syntax: &SyntaxNode, + use_node: &SyntaxNode, curr_parent_module: &Option<ast::Module>, ctx: &AssistContext<'_>, ) -> Option<TextRange> { //We only need to find in the current file let selection_range = ctx.selection_trimmed(); - let curr_file_id = ctx.file_id(); - let search_scope = SearchScope::single_file(curr_file_id); - let usage_res = def.usages(&ctx.sema).in_scope(&search_scope).all(); - let file = ctx.sema.parse(curr_file_id); - - let mut exists_inside_sel = false; - let mut exists_outside_sel = false; - for (_, refs) in usage_res.iter() { - let mut non_use_nodes_itr = refs.iter().filter_map(|x| { - if find_node_at_range::<ast::Use>(file.syntax(), x.range).is_none() { - let path_opt = find_node_at_range::<ast::Path>(file.syntax(), x.range); - return path_opt; - } - - None - }); - - if non_use_nodes_itr - .clone() - .any(|x| !selection_range.contains_range(x.syntax().text_range())) + let file_id = ctx.file_id(); + let usage_res = def.usages(&ctx.sema).in_scope(&SearchScope::single_file(file_id)).all(); + let file = ctx.sema.parse(file_id); + + // track uses which does not exists in `Use` + let mut uses_exist_in_sel = false; + let mut uses_exist_out_sel = false; + 'outside: for (_, refs) in usage_res.iter() { + for x in refs + .iter() + .filter(|x| find_node_at_range::<ast::Use>(file.syntax(), x.range).is_none()) + .filter_map(|x| find_node_at_range::<ast::Path>(file.syntax(), x.range)) { - exists_outside_sel = true; - } - if non_use_nodes_itr.any(|x| selection_range.contains_range(x.syntax().text_range())) { - exists_inside_sel = true; + let in_selection = selection_range.contains_range(x.syntax().text_range()); + uses_exist_in_sel |= in_selection; + uses_exist_out_sel |= !in_selection; + + if uses_exist_in_sel && uses_exist_out_sel { + break 'outside; + } } } - let source_exists_outside_sel_in_same_mod = does_source_exists_outside_sel_in_same_mod( - def, - ctx, - curr_parent_module, - selection_range, - curr_file_id, - ); + let (def_in_mod, def_out_sel) = + check_def_in_mod_and_out_sel(def, ctx, curr_parent_module, selection_range, file_id); - let use_stmt_opt: Option<ast::Use> = usage_res.into_iter().find_map(|(file_id, refs)| { - if file_id == curr_file_id { - refs.into_iter() - .rev() - .find_map(|fref| find_node_at_range(file.syntax(), fref.range)) - } else { - None - } + // Find use stmt that use def in current file + let use_stmt: Option<ast::Use> = usage_res + .into_iter() + .filter(|(use_file_id, _)| *use_file_id == file_id) + .flat_map(|(_, refs)| refs.into_iter().rev()) + .find_map(|fref| find_node_at_range(file.syntax(), fref.range)); + let use_stmt_not_in_sel = use_stmt.as_ref().is_some_and(|use_stmt| { + !selection_range.contains_range(use_stmt.syntax().text_range()) }); - let mut use_tree_str_opt: Option<Vec<ast::Path>> = None; + let mut use_tree_paths: Option<Vec<ast::Path>> = None; //Exists inside and outside selection // - Use stmt for item is present -> get the use_tree_str and reconstruct the path in new // module @@ -534,37 +504,37 @@ impl Module { //get the use_tree_str, reconstruct the use stmt in new module let mut import_path_to_be_removed: Option<TextRange> = None; - if exists_inside_sel && exists_outside_sel { + if uses_exist_in_sel && uses_exist_out_sel { //Changes to be made only inside new module //If use_stmt exists, find the use_tree_str, reconstruct it inside new module //If not, insert a use stmt with super and the given nameref - if let Some((use_tree_str, _)) = - self.process_use_stmt_for_import_resolve(use_stmt_opt, node_syntax) - { - use_tree_str_opt = Some(use_tree_str); - } else if source_exists_outside_sel_in_same_mod { - //Considered only after use_stmt is not present - //source_exists_outside_sel_in_same_mod | exists_outside_sel(exists_inside_sel = - //true for all cases) - // false | false -> Do nothing - // false | true -> If source is in selection -> nothing to do, If source is outside - // mod -> ust_stmt transversal - // true | false -> super import insertion - // true | true -> super import insertion - self.make_use_stmt_of_node_with_super(node_syntax); + match self.process_use_stmt_for_import_resolve(use_stmt, use_node) { + Some((use_tree_str, _)) => use_tree_paths = Some(use_tree_str), + None if def_in_mod && def_out_sel => { + //Considered only after use_stmt is not present + //def_in_mod && def_out_sel | exists_outside_sel(exists_inside_sel = + //true for all cases) + // false | false -> Do nothing + // false | true -> If source is in selection -> nothing to do, If source is outside + // mod -> ust_stmt transversal + // true | false -> super import insertion + // true | true -> super import insertion + self.make_use_stmt_of_node_with_super(use_node); + } + None => {} } - } else if exists_inside_sel && !exists_outside_sel { + } else if uses_exist_in_sel && !uses_exist_out_sel { //Changes to be made inside new module, and remove import from outside if let Some((mut use_tree_str, text_range_opt)) = - self.process_use_stmt_for_import_resolve(use_stmt_opt, node_syntax) + self.process_use_stmt_for_import_resolve(use_stmt, use_node) { if let Some(text_range) = text_range_opt { import_path_to_be_removed = Some(text_range); } - if source_exists_outside_sel_in_same_mod { + if def_in_mod && def_out_sel { if let Some(first_path_in_use_tree) = use_tree_str.last() { let first_path_in_use_tree_str = first_path_in_use_tree.to_string(); if !first_path_in_use_tree_str.contains("super") @@ -576,31 +546,43 @@ impl Module { } } - use_tree_str_opt = Some(use_tree_str); - } else if source_exists_outside_sel_in_same_mod { - self.make_use_stmt_of_node_with_super(node_syntax); + use_tree_paths = Some(use_tree_str); + } else if def_in_mod && def_out_sel { + self.make_use_stmt_of_node_with_super(use_node); } } - if let Some(use_tree_str) = use_tree_str_opt { - let mut use_tree_str = use_tree_str; - use_tree_str.reverse(); + if let Some(mut use_tree_paths) = use_tree_paths { + use_tree_paths.reverse(); - if !(!exists_outside_sel && exists_inside_sel && source_exists_outside_sel_in_same_mod) - { - if let Some(first_path_in_use_tree) = use_tree_str.first() { - let first_path_in_use_tree_str = first_path_in_use_tree.to_string(); - if first_path_in_use_tree_str.contains("super") { - let super_path = make::ext::ident_path("super"); - use_tree_str.insert(0, super_path) + if uses_exist_out_sel || !uses_exist_in_sel || !def_in_mod || !def_out_sel { + if let Some(first_path_in_use_tree) = use_tree_paths.first() { + if first_path_in_use_tree.to_string().contains("super") { + use_tree_paths.insert(0, make::ext::ident_path("super")); } } } - let use_ = - make::use_(None, make::use_tree(make::join_paths(use_tree_str), None, None, false)); - let item = ast::Item::from(use_); - self.use_items.insert(0, item); + let is_item = matches!( + def, + Definition::Macro(_) + | Definition::Module(_) + | Definition::Function(_) + | Definition::Adt(_) + | Definition::Const(_) + | Definition::Static(_) + | Definition::Trait(_) + | Definition::TraitAlias(_) + | Definition::TypeAlias(_) + ); + + if (def_out_sel || !is_item) && use_stmt_not_in_sel { + let use_ = make::use_( + None, + make::use_tree(make::join_paths(use_tree_paths), None, None, false), + ); + self.use_items.insert(0, ast::Item::from(use_)); + } } import_path_to_be_removed @@ -621,33 +603,26 @@ impl Module { fn process_use_stmt_for_import_resolve( &self, - use_stmt_opt: Option<ast::Use>, + use_stmt: Option<ast::Use>, node_syntax: &SyntaxNode, ) -> Option<(Vec<ast::Path>, Option<TextRange>)> { - if let Some(use_stmt) = use_stmt_opt { - for desc in use_stmt.syntax().descendants() { - if let Some(path_seg) = ast::PathSegment::cast(desc) { - if path_seg.syntax().to_string() == node_syntax.to_string() { - let mut use_tree_str = vec![path_seg.parent_path()]; - get_use_tree_paths_from_path(path_seg.parent_path(), &mut use_tree_str); - for ancs in path_seg.syntax().ancestors() { - //Here we are looking for use_tree with same string value as node - //passed above as the range_to_remove function looks for a comma and - //then includes it in the text range to remove it. But the comma only - //appears at the use_tree level - if let Some(use_tree) = ast::UseTree::cast(ancs) { - if use_tree.syntax().to_string() == node_syntax.to_string() { - return Some(( - use_tree_str, - Some(range_to_remove(use_tree.syntax())), - )); - } - } - } - - return Some((use_tree_str, None)); + let use_stmt = use_stmt?; + for path_seg in use_stmt.syntax().descendants().filter_map(ast::PathSegment::cast) { + if path_seg.syntax().to_string() == node_syntax.to_string() { + let mut use_tree_str = vec![path_seg.parent_path()]; + get_use_tree_paths_from_path(path_seg.parent_path(), &mut use_tree_str); + + //Here we are looking for use_tree with same string value as node + //passed above as the range_to_remove function looks for a comma and + //then includes it in the text range to remove it. But the comma only + //appears at the use_tree level + for use_tree in path_seg.syntax().ancestors().filter_map(ast::UseTree::cast) { + if use_tree.syntax().to_string() == node_syntax.to_string() { + return Some((use_tree_str, Some(range_to_remove(use_tree.syntax())))); } } + + return Some((use_tree_str, None)); } } @@ -676,145 +651,58 @@ fn check_intersection_and_push( import_paths_to_be_removed.push(import_path); } -fn does_source_exists_outside_sel_in_same_mod( +fn check_def_in_mod_and_out_sel( def: Definition, ctx: &AssistContext<'_>, curr_parent_module: &Option<ast::Module>, selection_range: TextRange, curr_file_id: FileId, -) -> bool { - let mut source_exists_outside_sel_in_same_mod = false; - match def { - Definition::Module(x) => { - let source = x.definition_source(ctx.db()); - let have_same_parent = if let Some(ast_module) = &curr_parent_module { - if let Some(hir_module) = x.parent(ctx.db()) { - compare_hir_and_ast_module(ast_module, hir_module, ctx).is_some() - } else { - let source_file_id = source.file_id.original_file(ctx.db()); - source_file_id == curr_file_id - } - } else { - let source_file_id = source.file_id.original_file(ctx.db()); - source_file_id == curr_file_id - }; - - if have_same_parent { - if let ModuleSource::Module(module_) = source.value { - source_exists_outside_sel_in_same_mod = - !selection_range.contains_range(module_.syntax().text_range()); - } - } - } - Definition::Function(x) => { - if let Some(source) = x.source(ctx.db()) { - let have_same_parent = if let Some(ast_module) = &curr_parent_module { - compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some() - } else { - let source_file_id = source.file_id.original_file(ctx.db()); - source_file_id == curr_file_id - }; - - if have_same_parent { - source_exists_outside_sel_in_same_mod = - !selection_range.contains_range(source.value.syntax().text_range()); - } - } - } - Definition::Adt(x) => { - if let Some(source) = x.source(ctx.db()) { +) -> (bool, bool) { + macro_rules! check_item { + ($x:ident) => { + if let Some(source) = $x.source(ctx.db()) { let have_same_parent = if let Some(ast_module) = &curr_parent_module { - compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some() + ctx.sema.to_module_def(ast_module).is_some_and(|it| it == $x.module(ctx.db())) } else { - let source_file_id = source.file_id.original_file(ctx.db()); - source_file_id == curr_file_id + source.file_id.original_file(ctx.db()) == curr_file_id }; - if have_same_parent { - source_exists_outside_sel_in_same_mod = - !selection_range.contains_range(source.value.syntax().text_range()); - } + let in_sel = !selection_range.contains_range(source.value.syntax().text_range()); + return (have_same_parent, in_sel); } - } - Definition::Variant(x) => { - if let Some(source) = x.source(ctx.db()) { - let have_same_parent = if let Some(ast_module) = &curr_parent_module { - compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some() - } else { - let source_file_id = source.file_id.original_file(ctx.db()); - source_file_id == curr_file_id - }; - - if have_same_parent { - source_exists_outside_sel_in_same_mod = - !selection_range.contains_range(source.value.syntax().text_range()); - } - } - } - Definition::Const(x) => { - if let Some(source) = x.source(ctx.db()) { - let have_same_parent = if let Some(ast_module) = &curr_parent_module { - compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some() - } else { - let source_file_id = source.file_id.original_file(ctx.db()); - source_file_id == curr_file_id - }; + }; + } - if have_same_parent { - source_exists_outside_sel_in_same_mod = - !selection_range.contains_range(source.value.syntax().text_range()); + match def { + Definition::Module(x) => { + let source = x.definition_source(ctx.db()); + let have_same_parent = match (&curr_parent_module, x.parent(ctx.db())) { + (Some(ast_module), Some(hir_module)) => { + ctx.sema.to_module_def(ast_module).is_some_and(|it| it == hir_module) } - } - } - Definition::Static(x) => { - if let Some(source) = x.source(ctx.db()) { - let have_same_parent = if let Some(ast_module) = &curr_parent_module { - compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some() - } else { - let source_file_id = source.file_id.original_file(ctx.db()); - source_file_id == curr_file_id - }; + _ => source.file_id.original_file(ctx.db()) == curr_file_id, + }; - if have_same_parent { - source_exists_outside_sel_in_same_mod = - !selection_range.contains_range(source.value.syntax().text_range()); + if have_same_parent { + if let ModuleSource::Module(module_) = source.value { + let in_sel = !selection_range.contains_range(module_.syntax().text_range()); + return (have_same_parent, in_sel); } } - } - Definition::Trait(x) => { - if let Some(source) = x.source(ctx.db()) { - let have_same_parent = if let Some(ast_module) = &curr_parent_module { - compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some() - } else { - let source_file_id = source.file_id.original_file(ctx.db()); - source_file_id == curr_file_id - }; - if have_same_parent { - source_exists_outside_sel_in_same_mod = - !selection_range.contains_range(source.value.syntax().text_range()); - } - } - } - Definition::TypeAlias(x) => { - if let Some(source) = x.source(ctx.db()) { - let have_same_parent = if let Some(ast_module) = &curr_parent_module { - compare_hir_and_ast_module(ast_module, x.module(ctx.db()), ctx).is_some() - } else { - let source_file_id = source.file_id.original_file(ctx.db()); - source_file_id == curr_file_id - }; - - if have_same_parent { - source_exists_outside_sel_in_same_mod = - !selection_range.contains_range(source.value.syntax().text_range()); - } - } + return (have_same_parent, false); } + Definition::Function(x) => check_item!(x), + Definition::Adt(x) => check_item!(x), + Definition::Variant(x) => check_item!(x), + Definition::Const(x) => check_item!(x), + Definition::Static(x) => check_item!(x), + Definition::Trait(x) => check_item!(x), + Definition::TypeAlias(x) => check_item!(x), _ => {} } - source_exists_outside_sel_in_same_mod + (false, false) } fn get_replacements_for_visibility_change( @@ -834,24 +722,30 @@ fn get_replacements_for_visibility_change( *item = item.clone_for_update(); } //Use stmts are ignored + macro_rules! push_to_replacement { + ($it:ident) => { + replacements.push(($it.visibility(), $it.syntax().clone())) + }; + } + match item { - ast::Item::Const(it) => replacements.push((it.visibility(), it.syntax().clone())), - ast::Item::Enum(it) => replacements.push((it.visibility(), it.syntax().clone())), - ast::Item::ExternCrate(it) => replacements.push((it.visibility(), it.syntax().clone())), - ast::Item::Fn(it) => replacements.push((it.visibility(), it.syntax().clone())), + ast::Item::Const(it) => push_to_replacement!(it), + ast::Item::Enum(it) => push_to_replacement!(it), + ast::Item::ExternCrate(it) => push_to_replacement!(it), + ast::Item::Fn(it) => push_to_replacement!(it), //Associated item's visibility should not be changed ast::Item::Impl(it) if it.for_token().is_none() => impls.push(it.clone()), - ast::Item::MacroDef(it) => replacements.push((it.visibility(), it.syntax().clone())), - ast::Item::Module(it) => replacements.push((it.visibility(), it.syntax().clone())), - ast::Item::Static(it) => replacements.push((it.visibility(), it.syntax().clone())), + ast::Item::MacroDef(it) => push_to_replacement!(it), + ast::Item::Module(it) => push_to_replacement!(it), + ast::Item::Static(it) => push_to_replacement!(it), ast::Item::Struct(it) => { - replacements.push((it.visibility(), it.syntax().clone())); + push_to_replacement!(it); record_field_parents.push((it.visibility(), it.syntax().clone())); } - ast::Item::Trait(it) => replacements.push((it.visibility(), it.syntax().clone())), - ast::Item::TypeAlias(it) => replacements.push((it.visibility(), it.syntax().clone())), + ast::Item::Trait(it) => push_to_replacement!(it), + ast::Item::TypeAlias(it) => push_to_replacement!(it), ast::Item::Union(it) => { - replacements.push((it.visibility(), it.syntax().clone())); + push_to_replacement!(it); record_field_parents.push((it.visibility(), it.syntax().clone())); } _ => (), @@ -865,8 +759,11 @@ fn get_use_tree_paths_from_path( path: ast::Path, use_tree_str: &mut Vec<ast::Path>, ) -> Option<&mut Vec<ast::Path>> { - path.syntax().ancestors().filter(|x| x.to_string() != path.to_string()).find_map(|x| { - if let Some(use_tree) = ast::UseTree::cast(x) { + path.syntax() + .ancestors() + .filter(|x| x.to_string() != path.to_string()) + .filter_map(ast::UseTree::cast) + .find_map(|use_tree| { if let Some(upper_tree_path) = use_tree.path() { if upper_tree_path.to_string() != path.to_string() { use_tree_str.push(upper_tree_path.clone()); @@ -874,9 +771,8 @@ fn get_use_tree_paths_from_path( return Some(use_tree); } } - } - None - })?; + None + })?; Some(use_tree_str) } @@ -890,20 +786,6 @@ fn add_change_vis(vis: Option<ast::Visibility>, node_or_token_opt: Option<syntax } } -fn compare_hir_and_ast_module( - ast_module: &ast::Module, - hir_module: hir::Module, - ctx: &AssistContext<'_>, -) -> Option<()> { - let hir_mod_name = hir_module.name(ctx.db())?; - let ast_mod_name = ast_module.name()?; - if hir_mod_name.display(ctx.db()).to_string() != ast_mod_name.to_string() { - return None; - } - - Some(()) -} - fn indent_range_before_given_node(node: &SyntaxNode) -> Option<TextRange> { node.siblings_with_tokens(syntax::Direction::Prev) .find(|x| x.kind() == WHITESPACE) @@ -1802,4 +1684,52 @@ mod modname { "#, ); } + + #[test] + fn test_remove_import_path_inside_selection() { + check_assist( + extract_module, + r#" +$0struct Point; +impl Point { + pub const fn direction(self, other: Self) -> Option<Direction> { + Some(Vertical) + } +} + +pub enum Direction { + Horizontal, + Vertical, +} +use Direction::{Horizontal, Vertical};$0 + +fn main() { + let x = Vertical; +} +"#, + r#" +mod modname { + use Direction::{Horizontal, Vertical}; + + pub(crate) struct Point; + + impl Point { + pub const fn direction(self, other: Self) -> Option<Direction> { + Some(Vertical) + } + } + + pub enum Direction { + Horizontal, + Vertical, + } +} +use modname::Direction::{Horizontal, Vertical}; + +fn main() { + let x = Vertical; +} +"#, + ); + } } diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs index fe2f8ed6417..ff051fa870f 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs @@ -198,7 +198,7 @@ fn get_adt_source( adt: &hir::Adt, fn_name: &str, ) -> Option<(Option<ast::Impl>, FileId)> { - let range = adt.source(ctx.sema.db)?.syntax().original_file_range(ctx.sema.db); + let range = adt.source(ctx.sema.db)?.syntax().original_file_range_rooted(ctx.sema.db); let file = ctx.sema.parse(range.file_id); let adt_source = ctx.sema.find_node_at_offset_with_macros(file.syntax(), range.range.start())?; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_call.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_call.rs index 50ec4347dc2..a90fe83857e 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_call.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/inline_call.rs @@ -206,7 +206,7 @@ pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option< let fn_body = fn_source.value.body()?; let param_list = fn_source.value.param_list()?; - let FileRange { file_id, range } = fn_source.syntax().original_file_range(ctx.sema.db); + let FileRange { file_id, range } = fn_source.syntax().original_file_range_rooted(ctx.sema.db); if file_id == ctx.file_id() && range.contains(ctx.offset()) { cov_mark::hit!(inline_call_recursive); return None; diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/env_vars.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/env_vars.rs index 35e6b97eb78..4005753773c 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/env_vars.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/env_vars.rs @@ -1,7 +1,10 @@ //! Completes environment variables defined by Cargo (https://doc.rust-lang.org/cargo/reference/environment-variables.html) -use hir::Semantics; -use ide_db::{syntax_helpers::node_ext::macro_call_for_string_token, RootDatabase}; -use syntax::ast::{self, IsString}; +use hir::MacroFileIdExt; +use ide_db::syntax_helpers::node_ext::macro_call_for_string_token; +use syntax::{ + ast::{self, IsString}, + AstToken, +}; use crate::{ completions::Completions, context::CompletionContext, CompletionItem, CompletionItemKind, @@ -32,10 +35,24 @@ const CARGO_DEFINED_VARS: &[(&str, &str)] = &[ pub(crate) fn complete_cargo_env_vars( acc: &mut Completions, ctx: &CompletionContext<'_>, + original: &ast::String, expanded: &ast::String, ) -> Option<()> { - guard_env_macro(expanded, &ctx.sema)?; - let range = expanded.text_range_between_quotes()?; + let is_in_env_expansion = ctx + .sema + .hir_file_for(&expanded.syntax().parent()?) + .macro_file() + .map_or(false, |it| it.is_env_or_option_env(ctx.sema.db)); + if !is_in_env_expansion { + let call = macro_call_for_string_token(expanded)?; + let makro = ctx.sema.resolve_macro_call(&call)?; + // We won't map into `option_env` as that generates `None` for non-existent env vars + // so fall back to this lookup + if !makro.is_env_or_option_env(ctx.sema.db) { + return None; + } + } + let range = original.text_range_between_quotes()?; CARGO_DEFINED_VARS.iter().for_each(|&(var, detail)| { let mut item = CompletionItem::new(CompletionItemKind::Keyword, range, var); @@ -46,18 +63,6 @@ pub(crate) fn complete_cargo_env_vars( Some(()) } -fn guard_env_macro(string: &ast::String, semantics: &Semantics<'_, RootDatabase>) -> Option<()> { - let call = macro_call_for_string_token(string)?; - let name = call.path()?.segment()?.name_ref()?; - let makro = semantics.resolve_macro_call(&call)?; - let db = semantics.db; - - match name.text().as_str() { - "env" | "option_env" if makro.kind(db) == hir::MacroKind::BuiltIn => Some(()), - _ => None, - } -} - #[cfg(test)] mod tests { use crate::tests::{check_edit, completion_list}; @@ -68,7 +73,7 @@ mod tests { &format!( r#" #[rustc_builtin_macro] - macro_rules! {macro_name} {{ + macro {macro_name} {{ ($var:literal) => {{ 0 }} }} @@ -80,7 +85,7 @@ mod tests { &format!( r#" #[rustc_builtin_macro] - macro_rules! {macro_name} {{ + macro {macro_name} {{ ($var:literal) => {{ 0 }} }} diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs index 7394d63be58..79467841502 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs @@ -96,7 +96,7 @@ fn complete_trait_impl_name( .parent() } }?; - let item = ctx.sema.original_syntax_node(&item)?; + let item = ctx.sema.original_syntax_node_rooted(&item)?; // item -> ASSOC_ITEM_LIST -> IMPL let impl_def = ast::Impl::cast(item.parent()?.parent()?)?; let replacement_range = { diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/mod_.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/mod_.rs index ecf5b29e2c0..c2faa2d939d 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/mod_.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/mod_.rs @@ -2,7 +2,7 @@ use std::iter; -use hir::{HirFileIdExt, Module, ModuleSource}; +use hir::{HirFileIdExt, Module}; use ide_db::{ base_db::{SourceDatabaseExt, VfsPath}, FxHashSet, RootDatabase, SymbolKind, @@ -57,7 +57,7 @@ pub(crate) fn complete_mod( .collect::<FxHashSet<_>>(); let module_declaration_file = - current_module.declaration_source(ctx.db).map(|module_declaration_source_file| { + current_module.declaration_source_range(ctx.db).map(|module_declaration_source_file| { module_declaration_source_file.file_id.original_file(ctx.db) }); @@ -148,9 +148,7 @@ fn module_chain_to_containing_module_file( ) -> Vec<Module> { let mut path = iter::successors(Some(current_module), |current_module| current_module.parent(db)) - .take_while(|current_module| { - matches!(current_module.definition_source(db).value, ModuleSource::Module(_)) - }) + .take_while(|current_module| current_module.is_inline(db)) .collect::<Vec<_>>(); path.reverse(); path diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/item.rs b/src/tools/rust-analyzer/crates/ide-completion/src/item.rs index 4bab2886851..357060817c7 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/item.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/item.rs @@ -369,6 +369,7 @@ impl CompletionItemKind { SymbolKind::LifetimeParam => "lt", SymbolKind::Local => "lc", SymbolKind::Macro => "ma", + SymbolKind::ProcMacro => "pm", SymbolKind::Module => "md", SymbolKind::SelfParam => "sp", SymbolKind::SelfType => "sy", diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/lib.rs b/src/tools/rust-analyzer/crates/ide-completion/src/lib.rs index 912f2fba2b3..d89cfc8b6cb 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/lib.rs @@ -207,7 +207,7 @@ pub fn completions( CompletionAnalysis::String { original, expanded: Some(expanded) } => { completions::extern_abi::complete_extern_abi(acc, ctx, expanded); completions::format_string::format_string(acc, ctx, original, expanded); - completions::env_vars::complete_cargo_env_vars(acc, ctx, expanded); + completions::env_vars::complete_cargo_env_vars(acc, ctx, original, expanded); } CompletionAnalysis::UnexpandedAttrTT { colon_prefix, diff --git a/src/tools/rust-analyzer/crates/ide-db/src/apply_change.rs b/src/tools/rust-analyzer/crates/ide-db/src/apply_change.rs index 017635d88e7..ec05f6d13d1 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/apply_change.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/apply_change.rs @@ -205,6 +205,7 @@ impl RootDatabase { // SourceDatabaseExt base_db::FileTextQuery + base_db::CompressedFileTextQuery base_db::FileSourceRootQuery base_db::SourceRootQuery base_db::SourceRootCratesQuery diff --git a/src/tools/rust-analyzer/crates/ide-db/src/defs.rs b/src/tools/rust-analyzer/crates/ide-db/src/defs.rs index 33970de1e4b..c0f0faba35c 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/defs.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/defs.rs @@ -407,7 +407,7 @@ impl NameClass { } pub fn classify(sema: &Semantics<'_, RootDatabase>, name: &ast::Name) -> Option<NameClass> { - let _p = tracing::span!(tracing::Level::INFO, "classify_name").entered(); + let _p = tracing::span!(tracing::Level::INFO, "NameClass::classify").entered(); let parent = name.syntax().parent()?; @@ -499,7 +499,8 @@ impl NameClass { sema: &Semantics<'_, RootDatabase>, lifetime: &ast::Lifetime, ) -> Option<NameClass> { - let _p = tracing::span!(tracing::Level::INFO, "classify_lifetime", ?lifetime).entered(); + let _p = tracing::span!(tracing::Level::INFO, "NameClass::classify_lifetime", ?lifetime) + .entered(); let parent = lifetime.syntax().parent()?; if let Some(it) = ast::LifetimeParam::cast(parent.clone()) { @@ -590,7 +591,8 @@ impl NameRefClass { sema: &Semantics<'_, RootDatabase>, name_ref: &ast::NameRef, ) -> Option<NameRefClass> { - let _p = tracing::span!(tracing::Level::INFO, "classify_name_ref", ?name_ref).entered(); + let _p = + tracing::span!(tracing::Level::INFO, "NameRefClass::classify", ?name_ref).entered(); let parent = name_ref.syntax().parent()?; @@ -689,7 +691,8 @@ impl NameRefClass { sema: &Semantics<'_, RootDatabase>, lifetime: &ast::Lifetime, ) -> Option<NameRefClass> { - let _p = tracing::span!(tracing::Level::INFO, "classify_lifetime_ref", ?lifetime).entered(); + let _p = tracing::span!(tracing::Level::INFO, "NameRefClass::classify_lifetime", ?lifetime) + .entered(); let parent = lifetime.syntax().parent()?; match parent.kind() { SyntaxKind::BREAK_EXPR | SyntaxKind::CONTINUE_EXPR => { diff --git a/src/tools/rust-analyzer/crates/ide-db/src/helpers.rs b/src/tools/rust-analyzer/crates/ide-db/src/helpers.rs index 4ac8a7c4c4a..db44b1e7232 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/helpers.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/helpers.rs @@ -71,7 +71,7 @@ pub fn visit_file_defs( let mut defs: VecDeque<_> = module.declarations(db).into(); while let Some(def) = defs.pop_front() { if let ModuleDef::Module(submodule) = def { - if let hir::ModuleSource::Module(_) = submodule.definition_source(db).value { + if submodule.is_inline(db) { defs.extend(submodule.declarations(db)); submodule.impl_defs(db).into_iter().for_each(|impl_| cb(impl_.into())); } diff --git a/src/tools/rust-analyzer/crates/ide-db/src/lib.rs b/src/tools/rust-analyzer/crates/ide-db/src/lib.rs index be08b37bac3..0d5a93f7b8e 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/lib.rs @@ -51,6 +51,7 @@ use std::{fmt, mem::ManuallyDrop}; use base_db::{ salsa::{self, Durability}, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast, + DEFAULT_FILE_TEXT_LRU_CAP, }; use hir::db::{DefDatabase, ExpandDatabase, HirDatabase}; use triomphe::Arc; @@ -157,6 +158,7 @@ impl RootDatabase { pub fn update_base_query_lru_capacities(&mut self, lru_capacity: Option<usize>) { let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_PARSE_LRU_CAP); + base_db::FileTextQuery.in_db_mut(self).set_lru_capacity(DEFAULT_FILE_TEXT_LRU_CAP); base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity); // macro expansions are usually rather small, so we can afford to keep more of them alive hir::db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(4 * lru_capacity); @@ -166,6 +168,7 @@ impl RootDatabase { pub fn update_lru_capacities(&mut self, lru_capacities: &FxHashMap<Box<str>, usize>) { use hir::db as hir_db; + base_db::FileTextQuery.in_db_mut(self).set_lru_capacity(DEFAULT_FILE_TEXT_LRU_CAP); base_db::ParseQuery.in_db_mut(self).set_lru_capacity( lru_capacities .get(stringify!(ParseQuery)) @@ -199,7 +202,7 @@ impl RootDatabase { // base_db::ProcMacrosQuery // SourceDatabaseExt - // base_db::FileTextQuery + base_db::FileTextQuery // base_db::FileSourceRootQuery // base_db::SourceRootQuery base_db::SourceRootCratesQuery @@ -348,6 +351,7 @@ pub enum SymbolKind { LifetimeParam, Local, Macro, + ProcMacro, Module, SelfParam, SelfType, @@ -366,9 +370,8 @@ pub enum SymbolKind { impl From<hir::MacroKind> for SymbolKind { fn from(it: hir::MacroKind) -> Self { match it { - hir::MacroKind::Declarative | hir::MacroKind::BuiltIn | hir::MacroKind::ProcMacro => { - SymbolKind::Macro - } + hir::MacroKind::Declarative | hir::MacroKind::BuiltIn => SymbolKind::Macro, + hir::MacroKind::ProcMacro => SymbolKind::ProcMacro, hir::MacroKind::Derive => SymbolKind::Derive, hir::MacroKind::Attr => SymbolKind::Attribute, } @@ -381,6 +384,7 @@ impl From<hir::ModuleDefId> for SymbolKind { hir::ModuleDefId::ConstId(..) => SymbolKind::Const, hir::ModuleDefId::EnumVariantId(..) => SymbolKind::Variant, hir::ModuleDefId::FunctionId(..) => SymbolKind::Function, + hir::ModuleDefId::MacroId(hir::MacroId::ProcMacroId(..)) => SymbolKind::ProcMacro, hir::ModuleDefId::MacroId(..) => SymbolKind::Macro, hir::ModuleDefId::ModuleId(..) => SymbolKind::Module, hir::ModuleDefId::StaticId(..) => SymbolKind::Static, diff --git a/src/tools/rust-analyzer/crates/ide-db/src/search.rs b/src/tools/rust-analyzer/crates/ide-db/src/search.rs index 006d8882c11..a3ecc103605 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/search.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/search.rs @@ -190,22 +190,15 @@ impl SearchScope { let mut entries = IntMap::default(); let (file_id, range) = { - let InFile { file_id, value } = module.definition_source(db); + let InFile { file_id, value } = module.definition_source_range(db); if let Some(InRealFile { file_id, value: call_source }) = file_id.original_call_node(db) { (file_id, Some(call_source.text_range())) } else { - ( - file_id.original_file(db), - match value { - ModuleSource::SourceFile(_) => None, - ModuleSource::Module(it) => Some(it.syntax().text_range()), - ModuleSource::BlockExpr(it) => Some(it.syntax().text_range()), - }, - ) + (file_id.original_file(db), Some(value)) } }; - entries.insert(file_id, range); + entries.entry(file_id).or_insert(range); let mut to_visit: Vec<_> = module.children(db).collect(); while let Some(module) = to_visit.pop() { diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/incorrect_case.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/incorrect_case.rs index db28928a24e..a0fad7c850c 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/incorrect_case.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/incorrect_case.rs @@ -38,7 +38,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCase) -> Option<Vec<Ass let def = NameClass::classify(&ctx.sema, &name_node)?.defined()?; let name_node = InFile::new(d.file, name_node.syntax()); - let frange = name_node.original_file_range(ctx.sema.db); + let frange = name_node.original_file_range_rooted(ctx.sema.db); let label = format!("Rename to {}", d.suggested_text); let mut res = unresolved_fix("change_case", &label, frange.range); diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/mutability_errors.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/mutability_errors.rs index 91f1058d65b..34a0038295f 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/mutability_errors.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/mutability_errors.rs @@ -413,7 +413,7 @@ fn main() { fn main() { return; let mut x = 2; - //^^^^^ warn: unused variable + //^^^^^ 💡 warn: unused variable &mut x; } "#, @@ -423,7 +423,7 @@ fn main() { fn main() { loop {} let mut x = 2; - //^^^^^ warn: unused variable + //^^^^^ 💡 warn: unused variable &mut x; } "#, @@ -444,7 +444,7 @@ fn main(b: bool) { g(); } let mut x = 2; - //^^^^^ warn: unused variable + //^^^^^ 💡 warn: unused variable &mut x; } "#, @@ -459,7 +459,7 @@ fn main(b: bool) { return; } let mut x = 2; - //^^^^^ warn: unused variable + //^^^^^ 💡 warn: unused variable &mut x; } "#, @@ -789,7 +789,7 @@ fn f() { //^^ 💡 error: cannot mutate immutable variable `x` _ = (x, y); let x = Foo; - //^ warn: unused variable + //^ 💡 warn: unused variable let x = Foo; let y: &mut (i32, u8) = &mut x; //^^^^^^ 💡 error: cannot mutate immutable variable `x` diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_field.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_field.rs index 4c01a2d155a..7a03f176ac2 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_field.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_field.rs @@ -1,11 +1,22 @@ -use hir::{db::ExpandDatabase, HirDisplay, InFile}; +use std::iter; + +use hir::{db::ExpandDatabase, Adt, HasSource, HirDisplay, InFile, Struct, Union}; use ide_db::{ assists::{Assist, AssistId, AssistKind}, base_db::FileRange, + helpers::is_editable_crate, label::Label, - source_change::SourceChange, + source_change::{SourceChange, SourceChangeBuilder}, +}; +use syntax::{ + algo, + ast::{self, edit::IndentLevel, make, FieldList, Name, Visibility}, + AstNode, AstPtr, Direction, SyntaxKind, TextSize, +}; +use syntax::{ + ast::{edit::AstNodeEdit, Type}, + SyntaxNode, }; -use syntax::{ast, AstNode, AstPtr}; use text_edit::TextEdit; use crate::{adjusted_display_range, Diagnostic, DiagnosticCode, DiagnosticsContext}; @@ -46,24 +57,206 @@ pub(crate) fn unresolved_field( } fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedField) -> Option<Vec<Assist>> { + let mut fixes = Vec::new(); if d.method_with_same_name_exists { - method_fix(ctx, &d.expr) + fixes.extend(method_fix(ctx, &d.expr)); + } + fixes.extend(field_fix(ctx, d)); + if fixes.is_empty() { + None } else { - // FIXME: add quickfix + Some(fixes) + } +} - None +// FIXME: Add Snippet Support +fn field_fix(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedField) -> Option<Assist> { + // Get the FileRange of the invalid field access + let root = ctx.sema.db.parse_or_expand(d.expr.file_id); + let expr = d.expr.value.to_node(&root); + + let error_range = ctx.sema.original_range_opt(expr.syntax())?; + let field_name = d.name.as_str()?; + // Convert the receiver to an ADT + let adt = d.receiver.strip_references().as_adt()?; + let target_module = adt.module(ctx.sema.db); + + let suggested_type = + if let Some(new_field_type) = ctx.sema.type_of_expr(&expr).map(|v| v.adjusted()) { + let display = + new_field_type.display_source_code(ctx.sema.db, target_module.into(), false).ok(); + make::ty(display.as_deref().unwrap_or("()")) + } else { + make::ty("()") + }; + + if !is_editable_crate(target_module.krate(), ctx.sema.db) { + return None; + } + + match adt { + Adt::Struct(adt_struct) => { + add_field_to_struct_fix(ctx, adt_struct, field_name, suggested_type, error_range) + } + Adt::Union(adt_union) => { + add_variant_to_union(ctx, adt_union, field_name, suggested_type, error_range) + } + _ => None, } } +fn add_variant_to_union( + ctx: &DiagnosticsContext<'_>, + adt_union: Union, + field_name: &str, + suggested_type: Type, + error_range: FileRange, +) -> Option<Assist> { + let adt_source = adt_union.source(ctx.sema.db)?; + let adt_syntax = adt_source.syntax(); + let field_list = adt_source.value.record_field_list()?; + let range = adt_syntax.original_file_range_rooted(ctx.sema.db); + let field_name = make::name(field_name); + + let (offset, record_field) = + record_field_layout(None, field_name, suggested_type, field_list, adt_syntax.value)?; + + let mut src_change_builder = SourceChangeBuilder::new(range.file_id); + src_change_builder.insert(offset, record_field); + Some(Assist { + id: AssistId("add-variant-to-union", AssistKind::QuickFix), + label: Label::new("Add field to union".to_owned()), + group: None, + target: error_range.range, + source_change: Some(src_change_builder.finish()), + trigger_signature_help: false, + }) +} + +fn add_field_to_struct_fix( + ctx: &DiagnosticsContext<'_>, + adt_struct: Struct, + field_name: &str, + suggested_type: Type, + error_range: FileRange, +) -> Option<Assist> { + let struct_source = adt_struct.source(ctx.sema.db)?; + let struct_syntax = struct_source.syntax(); + let struct_range = struct_syntax.original_file_range_rooted(ctx.sema.db); + let field_list = struct_source.value.field_list(); + match field_list { + Some(FieldList::RecordFieldList(field_list)) => { + // Get range of final field in the struct + let visibility = if error_range.file_id == struct_range.file_id { + None + } else { + Some(make::visibility_pub_crate()) + }; + let field_name = make::name(field_name); + + let (offset, record_field) = record_field_layout( + visibility, + field_name, + suggested_type, + field_list, + struct_syntax.value, + )?; + + let mut src_change_builder = SourceChangeBuilder::new(struct_range.file_id); + + // FIXME: Allow for choosing a visibility modifier see https://github.com/rust-lang/rust-analyzer/issues/11563 + src_change_builder.insert(offset, record_field); + Some(Assist { + id: AssistId("add-field-to-record-struct", AssistKind::QuickFix), + label: Label::new("Add field to Record Struct".to_owned()), + group: None, + target: error_range.range, + source_change: Some(src_change_builder.finish()), + trigger_signature_help: false, + }) + } + None => { + // Add a field list to the Unit Struct + let mut src_change_builder = SourceChangeBuilder::new(struct_range.file_id); + let field_name = make::name(field_name); + let visibility = if error_range.file_id == struct_range.file_id { + None + } else { + Some(make::visibility_pub_crate()) + }; + // FIXME: Allow for choosing a visibility modifier see https://github.com/rust-lang/rust-analyzer/issues/11563 + let indent = IndentLevel::from_node(struct_syntax.value) + 1; + + let field = make::record_field(visibility, field_name, suggested_type).indent(indent); + let record_field_list = make::record_field_list(iter::once(field)); + // A Unit Struct with no `;` is invalid syntax. We should not suggest this fix. + let semi_colon = + algo::skip_trivia_token(struct_syntax.value.last_token()?, Direction::Prev)?; + if semi_colon.kind() != SyntaxKind::SEMICOLON { + return None; + } + src_change_builder.replace(semi_colon.text_range(), record_field_list.to_string()); + + Some(Assist { + id: AssistId("convert-unit-struct-to-record-struct", AssistKind::QuickFix), + label: Label::new("Convert Unit Struct to Record Struct and add field".to_owned()), + group: None, + target: error_range.range, + source_change: Some(src_change_builder.finish()), + trigger_signature_help: false, + }) + } + Some(FieldList::TupleFieldList(_tuple)) => { + // FIXME: Add support for Tuple Structs. Tuple Structs are not sent to this diagnostic + None + } + } +} + +/// Used to determine the layout of the record field in the struct. +fn record_field_layout( + visibility: Option<Visibility>, + name: Name, + suggested_type: Type, + field_list: ast::RecordFieldList, + struct_syntax: &SyntaxNode, +) -> Option<(TextSize, String)> { + let (offset, needs_comma, trailing_new_line, indent) = match field_list.fields().last() { + Some(record_field) => { + let syntax = algo::skip_trivia_token(field_list.r_curly_token()?, Direction::Prev)?; + + let last_field_syntax = record_field.syntax(); + let last_field_indent = IndentLevel::from_node(last_field_syntax); + ( + last_field_syntax.text_range().end(), + syntax.kind() != SyntaxKind::COMMA, + false, + last_field_indent, + ) + } + // Empty Struct. Add a field right before the closing brace + None => { + let indent = IndentLevel::from_node(struct_syntax) + 1; + let offset = field_list.r_curly_token()?.text_range().start(); + (offset, false, true, indent) + } + }; + let comma = if needs_comma { ",\n" } else { "" }; + let trailing_new_line = if trailing_new_line { "\n" } else { "" }; + let record_field = make::record_field(visibility, name, suggested_type); + + Some((offset, format!("{comma}{indent}{record_field}{trailing_new_line}"))) +} + // FIXME: We should fill out the call here, move the cursor and trigger signature help fn method_fix( ctx: &DiagnosticsContext<'_>, expr_ptr: &InFile<AstPtr<ast::Expr>>, -) -> Option<Vec<Assist>> { +) -> Option<Assist> { let root = ctx.sema.db.parse_or_expand(expr_ptr.file_id); let expr = expr_ptr.value.to_node(&root); let FileRange { range, file_id } = ctx.sema.original_range_opt(expr.syntax())?; - Some(vec![Assist { + Some(Assist { id: AssistId("expected-field-found-method-call-fix", AssistKind::QuickFix), label: Label::new("Use parentheses to call the method".to_owned()), group: None, @@ -73,13 +266,15 @@ fn method_fix( TextEdit::insert(range.end(), "()".to_owned()), )), trigger_signature_help: false, - }]) + }) } #[cfg(test)] mod tests { + use crate::{ tests::{ check_diagnostics, check_diagnostics_with_config, check_diagnostics_with_disabled, + check_fix, }, DiagnosticsConfig, }; @@ -168,4 +363,100 @@ fn foo() { config.disabled.insert("syntax-error".to_owned()); check_diagnostics_with_config(config, "fn foo() { (). }"); } + + #[test] + fn unresolved_field_fix_on_unit() { + check_fix( + r#" + struct Foo; + + fn foo() { + Foo.bar$0; + } + "#, + r#" + struct Foo{ bar: () } + + fn foo() { + Foo.bar; + } + "#, + ); + } + #[test] + fn unresolved_field_fix_on_empty() { + check_fix( + r#" + struct Foo{ + } + + fn foo() { + let foo = Foo{}; + foo.bar$0; + } + "#, + r#" + struct Foo{ + bar: () + } + + fn foo() { + let foo = Foo{}; + foo.bar; + } + "#, + ); + } + #[test] + fn unresolved_field_fix_on_struct() { + check_fix( + r#" + struct Foo{ + a: i32 + } + + fn foo() { + let foo = Foo{a: 0}; + foo.bar$0; + } + "#, + r#" + struct Foo{ + a: i32, + bar: () + } + + fn foo() { + let foo = Foo{a: 0}; + foo.bar; + } + "#, + ); + } + #[test] + fn unresolved_field_fix_on_union() { + check_fix( + r#" + union Foo{ + a: i32 + } + + fn foo() { + let foo = Foo{a: 0}; + foo.bar$0; + } + "#, + r#" + union Foo{ + a: i32, + bar: () + } + + fn foo() { + let foo = Foo{a: 0}; + foo.bar; + } + "#, + ); + } } diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unused_variables.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unused_variables.rs index 28ccf474b40..a9e1d07d7c5 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unused_variables.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unused_variables.rs @@ -1,3 +1,11 @@ +use ide_db::{ + assists::{Assist, AssistId, AssistKind}, + base_db::FileRange, + label::Label, + source_change::SourceChange, +}; +use text_edit::TextEdit; + use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext}; // Diagnostic: unused-variables @@ -8,18 +16,38 @@ pub(crate) fn unused_variables( d: &hir::UnusedVariable, ) -> Diagnostic { let ast = d.local.primary_source(ctx.sema.db).syntax_ptr(); + let diagnostic_range = ctx.sema.diagnostics_display_range(ast); + let var_name = d.local.primary_source(ctx.sema.db).syntax().to_string(); Diagnostic::new_with_syntax_node_ptr( ctx, DiagnosticCode::RustcLint("unused_variables"), "unused variable", ast, ) + .with_fixes(fixes(&var_name, diagnostic_range, ast.file_id.is_macro())) .experimental() } +fn fixes(var_name: &String, diagnostic_range: FileRange, is_in_marco: bool) -> Option<Vec<Assist>> { + if is_in_marco { + return None; + } + Some(vec![Assist { + id: AssistId("unscore_unused_variable_name", AssistKind::QuickFix), + label: Label::new(format!("Rename unused {} to _{}", var_name, var_name)), + group: None, + target: diagnostic_range.range, + source_change: Some(SourceChange::from_text_edit( + diagnostic_range.file_id, + TextEdit::replace(diagnostic_range.range, format!("_{}", var_name)), + )), + trigger_signature_help: false, + }]) +} + #[cfg(test)] mod tests { - use crate::tests::check_diagnostics; + use crate::tests::{check_diagnostics, check_fix, check_no_fix}; #[test] fn unused_variables_simple() { @@ -29,23 +57,23 @@ mod tests { struct Foo { f1: i32, f2: i64 } fn f(kkk: i32) {} - //^^^ warn: unused variable + //^^^ 💡 warn: unused variable fn main() { let a = 2; - //^ warn: unused variable + //^ 💡 warn: unused variable let b = 5; // note: `unused variable` implies `unused mut`, so we should not emit both at the same time. let mut c = f(b); - //^^^^^ warn: unused variable + //^^^^^ 💡 warn: unused variable let (d, e) = (3, 5); - //^ warn: unused variable + //^ 💡 warn: unused variable let _ = e; let f1 = 2; let f2 = 5; let f = Foo { f1, f2 }; match f { Foo { f1, f2 } => { - //^^ warn: unused variable + //^^ 💡 warn: unused variable _ = f2; } } @@ -53,7 +81,7 @@ fn main() { if g {} let h: fn() -> i32 = || 2; let i = h(); - //^ warn: unused variable + //^ 💡 warn: unused variable } "#, ); @@ -67,11 +95,11 @@ struct S { } impl S { fn owned_self(self, u: i32) {} - //^ warn: unused variable + //^ 💡 warn: unused variable fn ref_self(&self, u: i32) {} - //^ warn: unused variable + //^ 💡 warn: unused variable fn ref_mut_self(&mut self, u: i32) {} - //^ warn: unused variable + //^ 💡 warn: unused variable fn owned_mut_self(mut self) {} //^^^^^^^^ 💡 warn: variable does not need to be mutable @@ -103,7 +131,78 @@ fn main() { #[deny(unused)] fn main2() { let x = 2; - //^ error: unused variable + //^ 💡 error: unused variable +} +"#, + ); + } + + #[test] + fn fix_unused_variable() { + check_fix( + r#" +fn main() { + let x$0 = 2; +} +"#, + r#" +fn main() { + let _x = 2; +} +"#, + ); + + check_fix( + r#" +fn main() { + let ($0d, _e) = (3, 5); +} +"#, + r#" +fn main() { + let (_d, _e) = (3, 5); +} +"#, + ); + + check_fix( + r#" +struct Foo { f1: i32, f2: i64 } +fn main() { + let f = Foo { f1: 0, f2: 0 }; + match f { + Foo { f1$0, f2 } => { + _ = f2; + } + } +} +"#, + r#" +struct Foo { f1: i32, f2: i64 } +fn main() { + let f = Foo { f1: 0, f2: 0 }; + match f { + Foo { _f1, f2 } => { + _ = f2; + } + } +} +"#, + ); + } + + #[test] + fn no_fix_for_marco() { + check_no_fix( + r#" +macro_rules! my_macro { + () => { + let x = 3; + }; +} + +fn main() { + $0my_macro!(); } "#, ); diff --git a/src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs b/src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs index fb98e956847..cfda1c692ae 100644 --- a/src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs +++ b/src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs @@ -125,9 +125,12 @@ impl<'db, 'sema> Matcher<'db, 'sema> { let match_state = Matcher { sema, restrict_range: *restrict_range, rule }; // First pass at matching, where we check that node types and idents match. match_state.attempt_match_node(&mut Phase::First, &rule.pattern.node, code)?; - match_state.validate_range(&sema.original_range(code))?; + let file_range = sema + .original_range_opt(code) + .ok_or(MatchFailed { reason: Some("def site definition".to_owned()) })?; + match_state.validate_range(&file_range)?; let mut the_match = Match { - range: sema.original_range(code), + range: file_range, matched_node: code.clone(), placeholder_values: FxHashMap::default(), ignored_comments: Vec::new(), @@ -175,7 +178,10 @@ impl<'db, 'sema> Matcher<'db, 'sema> { self.check_constraint(constraint, code)?; } if let Phase::Second(matches_out) = phase { - let original_range = self.sema.original_range(code); + let original_range = self + .sema + .original_range_opt(code) + .ok_or(MatchFailed { reason: Some("def site definition".to_owned()) })?; // We validated the range for the node when we started the match, so the placeholder // probably can't fail range validation, but just to be safe... self.validate_range(&original_range)?; @@ -487,7 +493,13 @@ impl<'db, 'sema> Matcher<'db, 'sema> { match_out.placeholder_values.insert( placeholder.ident.clone(), PlaceholderMatch::from_range(FileRange { - file_id: self.sema.original_range(code).file_id, + file_id: self + .sema + .original_range_opt(code) + .ok_or(MatchFailed { + reason: Some("def site definition".to_owned()), + })? + .file_id, range: first_matched_token .text_range() .cover(last_matched_token.text_range()), diff --git a/src/tools/rust-analyzer/crates/ide-ssr/src/search.rs b/src/tools/rust-analyzer/crates/ide-ssr/src/search.rs index 8d2d796122a..55a49da2424 100644 --- a/src/tools/rust-analyzer/crates/ide-ssr/src/search.rs +++ b/src/tools/rust-analyzer/crates/ide-ssr/src/search.rs @@ -190,12 +190,9 @@ impl MatchFinder<'_> { // When matching within a macro expansion, we only want to allow matches of // nodes that originated entirely from within the token tree of the macro call. // i.e. we don't want to match something that came from the macro itself. - self.slow_scan_node( - &expanded, - rule, - &Some(self.sema.original_range(tt.syntax())), - matches_out, - ); + if let Some(range) = self.sema.original_range_opt(tt.syntax()) { + self.slow_scan_node(&expanded, rule, &Some(range), matches_out); + } } } } @@ -227,7 +224,7 @@ impl MatchFinder<'_> { // There is no range restriction. return true; } - let node_range = self.sema.original_range(code); + let Some(node_range) = self.sema.original_range_opt(code) else { return false }; for range in &self.restrict_ranges { if range.file_id == node_range.file_id && range.range.contains_range(node_range.range) { return true; diff --git a/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs b/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs index 1bda15255dc..ddeeca5f7b3 100644 --- a/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs +++ b/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs @@ -1,10 +1,10 @@ -use std::mem::discriminant; +use std::{iter, mem::discriminant}; use crate::{ doc_links::token_as_doc_comment, navigation_target::ToNav, FilePosition, NavigationTarget, RangeInfo, TryToNav, }; -use hir::{AsAssocItem, AssocItem, DescendPreference, ModuleDef, Semantics}; +use hir::{AsAssocItem, AssocItem, DescendPreference, MacroFileIdExt, ModuleDef, Semantics}; use ide_db::{ base_db::{AnchoredPath, FileId, FileLoader}, defs::{Definition, IdentClass}, @@ -74,11 +74,13 @@ pub(crate) fn goto_definition( .filter_map(|token| { let parent = token.parent()?; - if let Some(tt) = ast::TokenTree::cast(parent.clone()) { - if let Some(x) = try_lookup_include_path(sema, tt, token.clone(), file_id) { + if let Some(token) = ast::String::cast(token.clone()) { + if let Some(x) = try_lookup_include_path(sema, token, file_id) { return Some(vec![x]); } + } + if ast::TokenTree::can_cast(parent.kind()) { if let Some(x) = try_lookup_macro_def_in_macro_use(sema, token) { return Some(vec![x]); } @@ -111,24 +113,17 @@ pub(crate) fn goto_definition( fn try_lookup_include_path( sema: &Semantics<'_, RootDatabase>, - tt: ast::TokenTree, - token: SyntaxToken, + token: ast::String, file_id: FileId, ) -> Option<NavigationTarget> { - let token = ast::String::cast(token)?; - let path = token.value()?.into_owned(); - let macro_call = tt.syntax().parent().and_then(ast::MacroCall::cast)?; - let name = macro_call.path()?.segment()?.name_ref()?; - if !matches!(&*name.text(), "include" | "include_str" | "include_bytes") { + let file = sema.hir_file_for(&token.syntax().parent()?).macro_file()?; + if !iter::successors(Some(file), |file| file.parent(sema.db).macro_file()) + // Check that we are in the eager argument expansion of an include macro + .any(|file| file.is_include_like_macro(sema.db) && file.eager_arg(sema.db).is_none()) + { return None; } - - // Ignore non-built-in macros to account for shadowing - if let Some(it) = sema.resolve_macro_call(¯o_call) { - if !matches!(it.kind(sema.db), hir::MacroKind::BuiltIn) { - return None; - } - } + let path = token.value()?; let file_id = sema.db.resolve_path(AnchoredPath { anchor: file_id, path: &path })?; let size = sema.db.file_text(file_id).len().try_into().ok()?; @@ -1532,6 +1527,26 @@ fn main() { } #[test] + fn goto_include_has_eager_input() { + check( + r#" +//- /main.rs +#[rustc_builtin_macro] +macro_rules! include_str {} +#[rustc_builtin_macro] +macro_rules! concat {} + +fn main() { + let str = include_str!(concat!("foo", ".tx$0t")); +} +//- /foo.txt +// empty +//^file +"#, + ); + } + + #[test] fn goto_doc_include_str() { check( r#" diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/render.rs b/src/tools/rust-analyzer/crates/ide/src/hover/render.rs index d1d039534d5..63777d49105 100644 --- a/src/tools/rust-analyzer/crates/ide/src/hover/render.rs +++ b/src/tools/rust-analyzer/crates/ide/src/hover/render.rs @@ -510,7 +510,7 @@ fn render_notable_trait_comment( let mut needs_impl_header = true; for (trait_, assoc_types) in notable_traits { desc.push_str(if mem::take(&mut needs_impl_header) { - " // Implements notable traits: " + "// Implements notable traits: " } else { ", " }); @@ -661,7 +661,7 @@ fn closure_ty( if let Some(layout) = render_memory_layout(config.memory_layout, || original.layout(sema.db), |_| None, |_| None) { - format_to!(markup, "{layout}"); + format_to!(markup, " {layout}"); } if let Some(trait_) = c.fn_trait(sema.db).get_id(sema.db, original.krate(sema.db).into()) { push_new_def(hir::Trait::from(trait_).into()) @@ -730,7 +730,7 @@ fn render_memory_layout( let config = config?; let layout = layout().ok()?; - let mut label = String::from(" // "); + let mut label = String::from("// "); if let Some(render) = config.size { let size = match tag(&layout) { diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs index c3cd6513dc6..4451e31870f 100644 --- a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs +++ b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs @@ -180,7 +180,7 @@ fn foo() { *local* ```rust - // size = 4, align = 4 + // size = 4, align = 4 let local: i32 ``` "#]], @@ -471,7 +471,7 @@ fn main() { *iter* ```rust - // size = 8, align = 4 + // size = 8, align = 4 let mut iter: Iter<Scan<OtherStruct<OtherStruct<i32>>, impl Fn(&mut u32, &u32, &mut u32) -> Option<u32>, u32>> ``` "#]], @@ -713,7 +713,7 @@ struct Foo { fiel$0d_a: u8, field_b: i32, field_c: i16 } ``` ```rust - // size = 1, align = 1, offset = 6 + // size = 1, align = 1, offset = 6 field_a: u8 ``` "#]], @@ -739,7 +739,7 @@ fn main() { ``` ```rust - // size = 4, align = 4, offset = 0 + // size = 4, align = 4, offset = 0 pub field_a: u32 ``` "#]], @@ -762,7 +762,7 @@ fn main() { ``` ```rust - // size = 4, align = 4, offset = 0 + // size = 4, align = 4, offset = 0 pub field_a: u32 ``` "#]], @@ -787,7 +787,7 @@ fn main() { ``` ```rust - // size = 4, align = 4, offset = 0 + // size = 4, align = 4, offset = 0 pub 0: u32 ``` "#]], @@ -808,7 +808,7 @@ fn foo(foo: Foo) { ``` ```rust - // size = 4, align = 4, offset = 0 + // size = 4, align = 4, offset = 0 pub 0: u32 ``` "#]], @@ -819,7 +819,7 @@ fn foo(foo: Foo) { fn hover_tuple_struct() { check( r#" -struct Foo$0(pub u32) +struct Foo$0(pub u32) where u32: Copy; "#, expect![[r#" *Foo* @@ -829,8 +829,100 @@ struct Foo$0(pub u32) ``` ```rust - // size = 4, align = 4 - struct Foo(pub u32); + // size = 4, align = 4 + struct Foo(pub u32) + where + u32: Copy, + ``` + "#]], + ); +} + +#[test] +fn hover_record_struct() { + check( + r#" +struct Foo$0 { field: u32 } +"#, + expect![[r#" + *Foo* + + ```rust + test + ``` + + ```rust + // size = 4, align = 4 + struct Foo { + field: u32, + } + ``` + "#]], + ); + check( + r#" +struct Foo$0 where u32: Copy { field: u32 } +"#, + expect![[r#" + *Foo* + + ```rust + test + ``` + + ```rust + // size = 4, align = 4 + struct Foo + where + u32: Copy, + { + field: u32, + } + ``` + "#]], + ); +} + +#[test] +fn hover_unit_struct() { + check( + r#" +struct Foo$0 where u32: Copy; +"#, + expect![[r#" + *Foo* + + ```rust + test + ``` + + ```rust + // size = 0, align = 1 + struct Foo + where + u32: Copy, + ``` + "#]], + ); +} + +#[test] +fn hover_type_alias() { + check( + r#" +type Fo$0o: Trait = S where T: Trait; +"#, + expect![[r#" + *Foo* + + ```rust + test + ``` + + ```rust + type Foo: Trait = S + where + T: Trait, ``` "#]], ); @@ -957,7 +1049,7 @@ fn main() { *zz* ```rust - // size = 8, align = 4 + // size = 8, align = 4 let zz: Test<i32> ``` "#]], @@ -1009,7 +1101,7 @@ fn main() { let b$0ar = Some(12); } *bar* ```rust - // size = 4, align = 4 + // size = 4, align = 4 let bar: Option<i32> ``` "#]], @@ -1079,7 +1171,7 @@ fn hover_for_local_variable() { *foo* ```rust - // size = 4, align = 4 + // size = 4, align = 4 foo: i32 ``` "#]], @@ -1094,7 +1186,7 @@ fn hover_for_local_variable_pat() { *foo* ```rust - // size = 4, align = 4 + // size = 4, align = 4 foo: i32 ``` "#]], @@ -1109,7 +1201,7 @@ fn hover_local_var_edge() { *foo* ```rust - // size = 4, align = 4 + // size = 4, align = 4 foo: i32 ``` "#]], @@ -1124,7 +1216,7 @@ fn hover_for_param_edge() { *foo* ```rust - // size = 4, align = 4 + // size = 4, align = 4 foo: i32 ``` "#]], @@ -1169,7 +1261,7 @@ fn main() { let foo_$0test = Thing::new(); } *foo_test* ```rust - // size = 4, align = 4 + // size = 4, align = 4 let foo_test: Thing ``` "#]], @@ -1374,7 +1466,7 @@ fn y() { *x* ```rust - // size = 4, align = 4 + // size = 4, align = 4 let x: i32 ``` "#]], @@ -1505,7 +1597,7 @@ fn foo(bar:u32) { let a = id!(ba$0r); } *bar* ```rust - // size = 4, align = 4 + // size = 4, align = 4 bar: u32 ``` "#]], @@ -1524,7 +1616,7 @@ fn foo(bar:u32) { let a = id!(ba$0r); } *bar* ```rust - // size = 4, align = 4 + // size = 4, align = 4 bar: u32 ``` "#]], @@ -1760,7 +1852,7 @@ fn test_hover_function_pointer_show_identifiers() { ``` ```rust - // size = 8, align = 8, niches = 1 + // size = 8, align = 8, niches = 1 type foo = fn(a: i32, b: i32) -> i32 ``` "#]], @@ -1779,7 +1871,7 @@ fn test_hover_function_pointer_no_identifier() { ``` ```rust - // size = 8, align = 8, niches = 1 + // size = 8, align = 8, niches = 1 type foo = fn(i32, i32) -> i32 ``` "#]], @@ -1926,7 +2018,7 @@ fn foo() { let bar = Ba$0r; } ``` ```rust - // size = 0, align = 1 + // size = 0, align = 1 struct Bar ``` @@ -1963,7 +2055,7 @@ fn foo() { let bar = Ba$0r; } ``` ```rust - // size = 0, align = 1 + // size = 0, align = 1 struct Bar ``` @@ -1993,7 +2085,7 @@ fn foo() { let bar = Ba$0r; } ``` ```rust - // size = 0, align = 1 + // size = 0, align = 1 struct Bar ``` @@ -2022,7 +2114,7 @@ pub struct B$0ar ``` ```rust - // size = 0, align = 1 + // size = 0, align = 1 pub struct Bar ``` @@ -2050,7 +2142,7 @@ pub struct B$0ar ``` ```rust - // size = 0, align = 1 + // size = 0, align = 1 pub struct Bar ``` @@ -2140,7 +2232,7 @@ fn test_hover_layout_of_variant() { ``` ```rust - // size = 4, align = 2 + // size = 4, align = 2 Variant1(u8, u16) ``` "#]], @@ -2162,7 +2254,7 @@ fn test_hover_layout_of_enum() { ``` ```rust - // size = 16 (0x10), align = 8, niches = 254 + // size = 16 (0x10), align = 8, niches = 254 enum Foo { Variant1(u8, u16), Variant2(i32, u8, i64), @@ -2540,7 +2632,7 @@ fn main() { let s$0t = S{ f1:Arg(0) }; } focus_range: 7..10, name: "Arg", kind: Struct, - description: "struct Arg(u32);", + description: "struct Arg(u32)", }, }, HoverGotoTypeData { @@ -2599,7 +2691,7 @@ fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; } focus_range: 7..10, name: "Arg", kind: Struct, - description: "struct Arg(u32);", + description: "struct Arg(u32)", }, }, HoverGotoTypeData { @@ -2648,7 +2740,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); } focus_range: 7..8, name: "A", kind: Struct, - description: "struct A(u32);", + description: "struct A(u32)", }, }, HoverGotoTypeData { @@ -2661,7 +2753,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); } focus_range: 22..23, name: "B", kind: Struct, - description: "struct B(u32);", + description: "struct B(u32)", }, }, HoverGotoTypeData { @@ -2675,7 +2767,7 @@ fn main() { let s$0t = (A(1), B(2), M::C(3) ); } name: "C", kind: Struct, container_name: "M", - description: "pub struct C(u32);", + description: "pub struct C(u32)", }, }, ], @@ -3331,26 +3423,26 @@ struct Foo<const BAR: Bar>; impl<const BAR: Bar> Foo<BAR$0> {} "#, expect![[r#" - [ - GoToType( - [ - HoverGotoTypeData { - mod_path: "test::Bar", - nav: NavigationTarget { - file_id: FileId( - 0, - ), - full_range: 0..11, - focus_range: 7..10, - name: "Bar", - kind: Struct, - description: "struct Bar", - }, + [ + GoToType( + [ + HoverGotoTypeData { + mod_path: "test::Bar", + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 0..11, + focus_range: 7..10, + name: "Bar", + kind: Struct, + description: "struct Bar", }, - ], - ), - ] - "#]], + }, + ], + ), + ] + "#]], ); } @@ -3396,26 +3488,26 @@ impl Foo { } "#, expect![[r#" - [ - GoToType( - [ - HoverGotoTypeData { - mod_path: "test::Foo", - nav: NavigationTarget { - file_id: FileId( - 0, - ), - full_range: 0..11, - focus_range: 7..10, - name: "Foo", - kind: Struct, - description: "struct Foo", - }, + [ + GoToType( + [ + HoverGotoTypeData { + mod_path: "test::Foo", + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 0..11, + focus_range: 7..10, + name: "Foo", + kind: Struct, + description: "struct Foo", }, - ], - ), - ] - "#]], + }, + ], + ), + ] + "#]], ); } @@ -3466,7 +3558,7 @@ fn main() { *f* ```rust - // size = 8, align = 8, niches = 1 + // size = 8, align = 8, niches = 1 let f: &i32 ``` --- @@ -3476,7 +3568,7 @@ fn main() { ``` ```rust - // size = 4, align = 4, offset = 0 + // size = 4, align = 4, offset = 0 f: i32 ``` "#]], @@ -3498,7 +3590,7 @@ struct S$0T<const C: usize = 1, T = Foo>(T); ``` ```rust - struct ST<const C: usize = 1, T = Foo>(T); + struct ST<const C: usize = 1, T = Foo>(T) ``` "#]], ); @@ -3519,7 +3611,7 @@ struct S$0T<const C: usize = {40 + 2}, T = Foo>(T); ``` ```rust - struct ST<const C: usize = {const}, T = Foo>(T); + struct ST<const C: usize = {const}, T = Foo>(T) ``` "#]], ); @@ -3541,7 +3633,7 @@ struct S$0T<const C: usize = VAL, T = Foo>(T); ``` ```rust - struct ST<const C: usize = VAL, T = Foo>(T); + struct ST<const C: usize = VAL, T = Foo>(T) ``` "#]], ); @@ -3561,7 +3653,7 @@ fn main() { *value* ```rust - // size = 0, align = 1 + // size = 0, align = 1 let value: Const<1> ``` "#]], @@ -3582,7 +3674,7 @@ fn main() { *value* ```rust - // size = 0, align = 1 + // size = 0, align = 1 let value: Const<0> ``` "#]], @@ -3603,7 +3695,7 @@ fn main() { *value* ```rust - // size = 0, align = 1 + // size = 0, align = 1 let value: Const<-1> ``` "#]], @@ -3624,7 +3716,7 @@ fn main() { *value* ```rust - // size = 0, align = 1 + // size = 0, align = 1 let value: Const<true> ``` "#]], @@ -3645,7 +3737,7 @@ fn main() { *value* ```rust - // size = 0, align = 1 + // size = 0, align = 1 let value: Const<'🦀'> ``` "#]], @@ -3665,7 +3757,7 @@ impl Foo { *self* ```rust - // size = 8, align = 8, niches = 1 + // size = 8, align = 8, niches = 1 self: &Foo ``` "#]], @@ -3686,7 +3778,7 @@ impl Foo { *self* ```rust - // size = 0, align = 1 + // size = 0, align = 1 self: Arc<Foo> ``` "#]], @@ -4072,7 +4164,7 @@ type Fo$0o2 = Foo<2>; ``` ```rust - // size = 0, align = 1 + // size = 0, align = 1 type Foo2 = Foo<2> ``` "#]], @@ -4115,7 +4207,7 @@ enum E { ``` ```rust - // size = 1, align = 1 + // size = 1, align = 1 A = 8 ``` @@ -4141,7 +4233,7 @@ enum E { ``` ```rust - // size = 1, align = 1 + // size = 1, align = 1 A = 12 (0xC) ``` @@ -4168,7 +4260,7 @@ enum E { ``` ```rust - // size = 1, align = 1 + // size = 1, align = 1 B = 2 ``` @@ -4195,7 +4287,7 @@ enum E { ``` ```rust - // size = 1, align = 1 + // size = 1, align = 1 B = 5 ``` @@ -5002,7 +5094,7 @@ fn foo(e: E) { ``` ```rust - // size = 0, align = 1 + // size = 0, align = 1 A = 3 ``` @@ -5025,7 +5117,7 @@ fn main() { *tile4* ```rust - // size = 32 (0x20), align = 4 + // size = 32 (0x20), align = 4 let tile4: [u32; 8] ``` "#]], @@ -5262,7 +5354,7 @@ pub fn gimme() -> theitem::TheItem { ``` ```rust - // size = 0, align = 1 + // size = 0, align = 1 pub struct TheItem ``` @@ -5411,7 +5503,7 @@ mod string { ``` ```rust - // size = 0, align = 1 + // size = 0, align = 1 struct String ``` @@ -5931,26 +6023,26 @@ fn foo() { } "#, expect![[r#" - [ - GoToType( - [ - HoverGotoTypeData { - mod_path: "test::Foo", - nav: NavigationTarget { - file_id: FileId( - 0, - ), - full_range: 0..11, - focus_range: 7..10, - name: "Foo", - kind: Struct, - description: "struct Foo", - }, + [ + GoToType( + [ + HoverGotoTypeData { + mod_path: "test::Foo", + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 0..11, + focus_range: 7..10, + name: "Foo", + kind: Struct, + description: "struct Foo", }, - ], - ), - ] - "#]], + }, + ], + ), + ] + "#]], ); } @@ -6139,7 +6231,7 @@ foo_macro!( ``` ```rust - // size = 0, align = 1 + // size = 0, align = 1 pub struct Foo ``` @@ -6165,8 +6257,8 @@ pub struct Foo(i32); ``` ```rust - // size = 4, align = 4 - pub struct Foo(i32); + // size = 4, align = 4 + pub struct Foo(i32) ``` --- @@ -6191,7 +6283,7 @@ pub struct Foo<T>(T); ``` ```rust - pub struct Foo<T>(T); + pub struct Foo<T>(T) ``` --- @@ -6290,7 +6382,7 @@ enum Enum { ``` ```rust - // size = 4, align = 4 + // size = 4, align = 4 RecordV { field: u32 } ``` "#]], @@ -6313,7 +6405,7 @@ enum Enum { ``` ```rust - // size = 4, align = 4 + // size = 4, align = 4 field: u32 ``` "#]], @@ -6961,7 +7053,7 @@ fn test() { ``` ```rust - // size = 4, align = 4, offset = 0 + // size = 4, align = 4, offset = 0 f: u32 ``` "#]], @@ -6981,7 +7073,7 @@ fn test() { *s* ```rust - // size = 0, align = 1 + // size = 0, align = 1 let s: S ``` "#]], @@ -7002,7 +7094,7 @@ fn test() { *foo* ```rust - // size = 4, align = 4 + // size = 4, align = 4 let foo: i32 ``` "#]], @@ -7023,7 +7115,7 @@ format_args!("{aaaaa$0}"); *aaaaa* ```rust - // size = 16 (0x10), align = 8, niches = 1 + // size = 16 (0x10), align = 8, niches = 1 let aaaaa: &str ``` "#]], @@ -7044,7 +7136,7 @@ format_args!("{$0aaaaa}"); *aaaaa* ```rust - // size = 16 (0x10), align = 8, niches = 1 + // size = 16 (0x10), align = 8, niches = 1 let aaaaa: &str ``` "#]], @@ -7065,7 +7157,7 @@ format_args!(r"{$0aaaaa}"); *aaaaa* ```rust - // size = 16 (0x10), align = 8, niches = 1 + // size = 16 (0x10), align = 8, niches = 1 let aaaaa: &str ``` "#]], @@ -7091,7 +7183,7 @@ foo!(r"{$0aaaaa}"); *aaaaa* ```rust - // size = 16 (0x10), align = 8, niches = 1 + // size = 16 (0x10), align = 8, niches = 1 let aaaaa: &str ``` "#]], @@ -7440,8 +7532,8 @@ fn main(notable$0: u32) {} *notable* ```rust - // Implements notable traits: Notable<Assoc = &str, Assoc2 = char> - // size = 4, align = 4 + // Implements notable traits: Notable<Assoc = &str, Assoc2 = char> + // size = 4, align = 4 notable: u32 ``` "#]], @@ -7472,8 +7564,8 @@ impl Iterator for S { ``` ```rust - // Implements notable traits: Notable, Future<Output = u32>, Iterator<Item = S> - // size = 0, align = 1 + // Implements notable traits: Notable, Future<Output = u32>, Iterator<Item = S> + // size = 0, align = 1 struct S ``` "#]], @@ -7532,7 +7624,7 @@ extern "C" { ``` ```rust - // size = 0, align = 1 + // size = 0, align = 1 type Ty ``` "#]], @@ -7560,7 +7652,7 @@ fn main() { "#, expect![[r#" ```rust - // Implements notable traits: Notable, Future<Output = u32>, Iterator<Item = S> + // Implements notable traits: Notable, Future<Output = u32>, Iterator<Item = S> S ```"#]], ); diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/implicit_drop.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/implicit_drop.rs index 8d9ad5bda14..5ba4e514e1f 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/implicit_drop.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/implicit_drop.rs @@ -74,6 +74,10 @@ pub(super) fn hints( Ok(s) => s.value.text_range(), Err(_) => continue, }, + MirSpan::SelfParam => match source_map.self_param_syntax() { + Some(s) => s.value.text_range(), + None => continue, + }, MirSpan::Unknown => continue, }; let binding = &hir.bindings[*binding]; diff --git a/src/tools/rust-analyzer/crates/ide/src/lib.rs b/src/tools/rust-analyzer/crates/ide/src/lib.rs index 59a7df14fd5..6955e14a10a 100644 --- a/src/tools/rust-analyzer/crates/ide/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide/src/lib.rs @@ -259,7 +259,7 @@ impl Analysis { false, CrateOrigin::Local { repo: None, name: None }, ); - change.change_file(file_id, Some(Arc::from(text))); + change.change_file(file_id, Some(text)); change.set_crate_graph(crate_graph); change.set_target_data_layouts(vec![Err("fixture has no layout".into())]); change.set_toolchains(vec![None]); diff --git a/src/tools/rust-analyzer/crates/ide/src/navigation_target.rs b/src/tools/rust-analyzer/crates/ide/src/navigation_target.rs index 674ce6d52bf..2123c98605d 100644 --- a/src/tools/rust-analyzer/crates/ide/src/navigation_target.rs +++ b/src/tools/rust-analyzer/crates/ide/src/navigation_target.rs @@ -176,14 +176,12 @@ impl NavigationTarget { impl TryToNav for FileSymbol { fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> { - let root = db.parse_or_expand(self.loc.hir_file_id); - self.loc.ptr.to_node(&root); Some( - orig_range_with_focus( + orig_range_with_focus_r( db, self.loc.hir_file_id, - &self.loc.ptr.to_node(&root), - Some(self.loc.name_ptr.to_node(&root)), + self.loc.ptr.text_range(), + Some(self.loc.name_ptr.text_range()), ) .map(|(FileRange { file_id, range: full_range }, focus_range)| { NavigationTarget { @@ -722,7 +720,21 @@ fn orig_range_with_focus( value: &SyntaxNode, name: Option<impl AstNode>, ) -> UpmappingResult<(FileRange, Option<TextRange>)> { - let Some(name) = name else { return orig_range(db, hir_file, value) }; + orig_range_with_focus_r( + db, + hir_file, + value.text_range(), + name.map(|it| it.syntax().text_range()), + ) +} + +fn orig_range_with_focus_r( + db: &RootDatabase, + hir_file: HirFileId, + value: TextRange, + name: Option<TextRange>, +) -> UpmappingResult<(FileRange, Option<TextRange>)> { + let Some(name) = name else { return orig_range_r(db, hir_file, value) }; let call_kind = || db.lookup_intern_macro_call(hir_file.macro_file().unwrap().macro_call_id).kind; @@ -733,9 +745,9 @@ fn orig_range_with_focus( .definition_range(db) }; - let value_range = InFile::new(hir_file, value).original_file_range_opt(db); + let value_range = InFile::new(hir_file, value).original_node_file_range_opt(db); let ((call_site_range, call_site_focus), def_site) = - match InFile::new(hir_file, name.syntax()).original_file_range_opt(db) { + match InFile::new(hir_file, name).original_node_file_range_opt(db) { // call site name Some((focus_range, ctxt)) if ctxt.is_root() => { // Try to upmap the node as well, if it ends up in the def site, go back to the call site @@ -802,7 +814,7 @@ fn orig_range_with_focus( } } // lost name? can't happen for single tokens - None => return orig_range(db, hir_file, value), + None => return orig_range_r(db, hir_file, value), }; UpmappingResult { @@ -840,7 +852,18 @@ fn orig_range( value: &SyntaxNode, ) -> UpmappingResult<(FileRange, Option<TextRange>)> { UpmappingResult { - call_site: (InFile::new(hir_file, value).original_file_range(db), None), + call_site: (InFile::new(hir_file, value).original_file_range_rooted(db), None), + def_site: None, + } +} + +fn orig_range_r( + db: &RootDatabase, + hir_file: HirFileId, + value: TextRange, +) -> UpmappingResult<(FileRange, Option<TextRange>)> { + UpmappingResult { + call_site: (InFile::new(hir_file, value).original_node_file_range(db).0, None), def_site: None, } } diff --git a/src/tools/rust-analyzer/crates/ide/src/references.rs b/src/tools/rust-analyzer/crates/ide/src/references.rs index dcdc6118a34..fef2aba3c61 100644 --- a/src/tools/rust-analyzer/crates/ide/src/references.rs +++ b/src/tools/rust-analyzer/crates/ide/src/references.rs @@ -1710,7 +1710,7 @@ use proc_macros::mirror; mirror$0! {} "#, expect![[r#" - mirror Macro FileId(1) 1..77 22..28 + mirror ProcMacro FileId(1) 1..77 22..28 FileId(0) 26..32 "#]], diff --git a/src/tools/rust-analyzer/crates/ide/src/runnables.rs b/src/tools/rust-analyzer/crates/ide/src/runnables.rs index 5fe46444ff4..79324bf3877 100644 --- a/src/tools/rust-analyzer/crates/ide/src/runnables.rs +++ b/src/tools/rust-analyzer/crates/ide/src/runnables.rs @@ -138,7 +138,9 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> { }) { if let Some(def) = def { let file_id = match def { - Definition::Module(it) => it.declaration_source(db).map(|src| src.file_id), + Definition::Module(it) => { + it.declaration_source_range(db).map(|src| src.file_id) + } Definition::Function(it) => it.source(db).map(|src| src.file_id), _ => None, }; @@ -269,15 +271,10 @@ fn find_related_tests_in_module( Some(it) => it, _ => return, }; - let mod_source = parent_module.definition_source(sema.db); - let range = match &mod_source.value { - hir::ModuleSource::Module(m) => m.syntax().text_range(), - hir::ModuleSource::BlockExpr(b) => b.syntax().text_range(), - hir::ModuleSource::SourceFile(f) => f.syntax().text_range(), - }; + let mod_source = parent_module.definition_source_range(sema.db); let file_id = mod_source.file_id.original_file(sema.db); - let mod_scope = SearchScope::file_range(FileRange { file_id, range }); + let mod_scope = SearchScope::file_range(FileRange { file_id, range: mod_source.value }); let fn_pos = FilePosition { file_id, offset: fn_name.syntax().text_range().start() }; find_related_tests(sema, syntax, fn_pos, Some(mod_scope), tests) } @@ -405,14 +402,15 @@ fn runnable_mod_outline_definition( let attrs = def.attrs(sema.db); let cfg = attrs.cfg(); - match def.definition_source(sema.db).value { - hir::ModuleSource::SourceFile(_) => Some(Runnable { + if def.as_source_file_id(sema.db).is_some() { + Some(Runnable { use_name_in_title: false, nav: def.to_nav(sema.db).call_site(), kind: RunnableKind::TestMod { path }, cfg, - }), - _ => None, + }) + } else { + None } } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs index d2bd3bab14e..6aaf8f8e779 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting.rs @@ -248,6 +248,7 @@ fn traverse( // an attribute nested in a macro call will not emit `inside_attribute` let mut inside_attribute = false; let mut inside_macro_call = false; + let mut inside_proc_macro_call = false; // Walk all nodes, keeping track of whether we are inside a macro or not. // If in macro, expand it first and highlight the expanded code. @@ -298,8 +299,9 @@ fn traverse( ast::Item::Fn(_) | ast::Item::Const(_) | ast::Item::Static(_) => { bindings_shadow_count.clear() } - ast::Item::MacroCall(_) => { + ast::Item::MacroCall(ref macro_call) => { inside_macro_call = true; + inside_proc_macro_call = sema.is_proc_macro_call(macro_call); } _ => (), } @@ -344,6 +346,7 @@ fn traverse( } Some(ast::Item::MacroCall(_)) => { inside_macro_call = false; + inside_proc_macro_call = false; } _ => (), } @@ -519,6 +522,9 @@ fn traverse( highlight |= HlMod::Attribute } if inside_macro_call && tt_level > 0 { + if inside_proc_macro_call { + highlight |= HlMod::ProcMacro + } highlight |= HlMod::Macro } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/html.rs b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/html.rs index bbc6b55a642..a6dca0541e5 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/html.rs +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/html.rs @@ -98,6 +98,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/tags.rs b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/tags.rs index 6d4cdd0efe2..5163a0de417 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/tags.rs +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/tags.rs @@ -75,6 +75,7 @@ pub enum HlMod { Library, /// Used to differentiate individual elements within macro calls. Macro, + ProcMacro, /// Mutable binding. Mutable, /// Used for public items. @@ -146,6 +147,7 @@ impl HlTag { SymbolKind::LifetimeParam => "lifetime", SymbolKind::Local => "variable", SymbolKind::Macro => "macro", + SymbolKind::ProcMacro => "proc_macro", SymbolKind::Module => "module", SymbolKind::SelfParam => "self_keyword", SymbolKind::SelfType => "self_type_keyword", @@ -219,6 +221,7 @@ impl HlMod { HlMod::IntraDocLink, HlMod::Library, HlMod::Macro, + HlMod::ProcMacro, HlMod::Mutable, HlMod::Public, HlMod::Reference, @@ -243,6 +246,7 @@ impl HlMod { HlMod::IntraDocLink => "intra_doc_link", HlMod::Library => "library", HlMod::Macro => "macro", + HlMod::ProcMacro => "proc_macro", HlMod::Mutable => "mutable", HlMod::Public => "public", HlMod::Reference => "reference", diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html index 4dcbfe4eb62..6994cb3d5c5 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html index bf5505caf37..dc2d103b581 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_block_mod_items.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_block_mod_items.html index 977d18c6b73..093cc2358a6 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_block_mod_items.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_block_mod_items.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_crate_root.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_crate_root.html index 0d1b3c1f183..154b823fffb 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_crate_root.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_crate_root.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_default_library.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_default_library.html index dd1528ed03f..58613bf1510 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_default_library.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_default_library.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html index d5f92aa5d47..34274932afc 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html index 88a008796b3..729e4791f55 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_general.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_general.html index bdeb09d2f83..066fcfb1dfe 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_general.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_general.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html index f9c33b8a601..58a147dd80a 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_keywords.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_keywords.html index 2043752bc74..22ae5c82a4b 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_keywords.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_keywords.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html index ec39998de26..af779996593 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_macros.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_macros.html index 4063cf9f757..32ac6a94d86 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_macros.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_macros.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } @@ -45,12 +46,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd </style> <pre><code><span class="keyword">use</span> <span class="module crate_root library">proc_macros</span><span class="operator">::</span><span class="brace">{</span><span class="function library">mirror</span><span class="comma">,</span> <span class="function library">identity</span><span class="comma">,</span> <span class="derive library">DeriveIdentity</span><span class="brace">}</span><span class="semicolon">;</span> -<span class="macro library">mirror</span><span class="macro_bang">!</span> <span class="brace macro">{</span> - <span class="brace macro">{</span> - <span class="comma macro">,</span><span class="builtin_type macro">i32</span> <span class="colon macro">:</span><span class="field declaration macro public">x</span> <span class="keyword macro">pub</span> - <span class="comma macro">,</span><span class="builtin_type macro">i32</span> <span class="colon macro">:</span><span class="field declaration macro public">y</span> <span class="keyword macro">pub</span> - <span class="brace macro">}</span> <span class="struct declaration macro">Foo</span> <span class="keyword macro">struct</span> -<span class="brace macro">}</span> +<span class="proc_macro library">mirror</span><span class="macro_bang">!</span> <span class="brace macro proc_macro">{</span> + <span class="brace macro proc_macro">{</span> + <span class="comma macro proc_macro">,</span><span class="builtin_type macro proc_macro">i32</span> <span class="colon macro proc_macro">:</span><span class="field declaration macro proc_macro public">x</span> <span class="keyword macro proc_macro">pub</span> + <span class="comma macro proc_macro">,</span><span class="builtin_type macro proc_macro">i32</span> <span class="colon macro proc_macro">:</span><span class="field declaration macro proc_macro public">y</span> <span class="keyword macro proc_macro">pub</span> + <span class="brace macro proc_macro">}</span> <span class="struct declaration macro proc_macro">Foo</span> <span class="keyword macro proc_macro">struct</span> +<span class="brace macro proc_macro">}</span> <span class="keyword">macro_rules</span><span class="macro_bang">!</span> <span class="macro declaration">def_fn</span> <span class="brace">{</span> <span class="parenthesis">(</span><span class="punctuation">$</span><span class="parenthesis">(</span><span class="punctuation">$</span>tt<span class="colon">:</span>tt<span class="parenthesis">)</span><span class="punctuation">*</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">></span> <span class="brace">{</span><span class="punctuation">$</span><span class="parenthesis">(</span><span class="punctuation">$</span>tt<span class="parenthesis">)</span><span class="punctuation">*</span><span class="brace">}</span> <span class="brace">}</span> @@ -93,7 +94,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd <span class="brace">}</span> -<span class="macro default_library library">include</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="none macro">concat</span><span class="punctuation macro">!</span><span class="parenthesis macro">(</span><span class="string_literal macro">"foo/"</span><span class="comma macro">,</span> <span class="string_literal macro">"foo.rs"</span><span class="parenthesis macro">)</span><span class="parenthesis macro">)</span><span class="semicolon">;</span> +<span class="macro default_library library">include</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="macro default_library library macro">concat</span><span class="macro_bang macro">!</span><span class="parenthesis macro">(</span><span class="string_literal macro">"foo/"</span><span class="string_literal macro">,</span> <span class="string_literal macro">"foo.rs"</span><span class="parenthesis macro">)</span><span class="parenthesis macro">)</span><span class="semicolon">;</span> <span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span> <span class="macro default_library library">format_args</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="string_literal macro">"Hello, </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal macro">!"</span><span class="comma macro">,</span> <span class="parenthesis macro">(</span><span class="numeric_literal macro">92</span><span class="comma macro">,</span><span class="parenthesis macro">)</span><span class="operator macro">.</span><span class="field library macro">0</span><span class="parenthesis macro">)</span><span class="semicolon">;</span> diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_module_docs_inline.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_module_docs_inline.html index 4dcf8e5f01f..ef8a48ca1c1 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_module_docs_inline.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_module_docs_inline.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_module_docs_outline.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_module_docs_outline.html index 084bbf2f742..a2ded15fd1b 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_module_docs_outline.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_module_docs_outline.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_operators.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_operators.html index 1af4bcfbd9d..d123ee04976 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_operators.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_operators.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_rainbow.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_rainbow.html index 7ee7b338c19..4429e5d933a 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_rainbow.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_rainbow.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html index 84a823363f6..b6458fa7ca0 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html index c72ea54e948..49b588baa58 100644 --- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html +++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html @@ -29,6 +29,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .numeric_literal { color: #BFEBBF; } .bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } +.proc_macro { color: #94BFF3; text-decoration: underline; } .derive { color: #94BFF3; font-style: italic; } .module { color: #AFD8AF; } .value_param { color: #DCDCCC; } diff --git a/src/tools/rust-analyzer/crates/ide/src/test_explorer.rs b/src/tools/rust-analyzer/crates/ide/src/test_explorer.rs index 2e741021ea8..ca471399703 100644 --- a/src/tools/rust-analyzer/crates/ide/src/test_explorer.rs +++ b/src/tools/rust-analyzer/crates/ide/src/test_explorer.rs @@ -11,7 +11,7 @@ use crate::{navigation_target::ToNav, runnables::runnable_fn, Runnable, TryToNav #[derive(Debug)] pub enum TestItemKind { - Crate, + Crate(CrateId), Module, Function, } @@ -32,15 +32,17 @@ pub(crate) fn discover_test_roots(db: &RootDatabase) -> Vec<TestItem> { crate_graph .iter() .filter(|&id| crate_graph[id].origin.is_local()) - .filter_map(|id| Some(crate_graph[id].display_name.as_ref()?.to_string())) - .map(|id| TestItem { - kind: TestItemKind::Crate, - label: id.clone(), - id, - parent: None, - file: None, - text_range: None, - runnable: None, + .filter_map(|id| { + let test_id = crate_graph[id].display_name.as_ref()?.to_string(); + Some(TestItem { + kind: TestItemKind::Crate(id), + label: test_id.clone(), + id: test_id, + parent: None, + file: None, + text_range: None, + runnable: None, + }) }) .collect() } @@ -118,12 +120,13 @@ pub(crate) fn discover_tests_in_crate(db: &RootDatabase, crate_id: CrateId) -> V let Some(crate_test_id) = &crate_graph[crate_id].display_name else { return vec![]; }; + let kind = TestItemKind::Crate(crate_id); let crate_test_id = crate_test_id.to_string(); let crate_id: Crate = crate_id.into(); let module = crate_id.root_module(); let mut r = vec![TestItem { id: crate_test_id.clone(), - kind: TestItemKind::Crate, + kind, label: crate_test_id.clone(), parent: None, file: None, diff --git a/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs b/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs index a1c089520da..fe680e47fef 100644 --- a/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs +++ b/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs @@ -361,8 +361,8 @@ fn load_crate_graph( let changes = vfs.take_changes(); for file in changes { if let vfs::Change::Create(v) | vfs::Change::Modify(v) = file.change { - if let Ok(text) = std::str::from_utf8(&v) { - analysis_change.change_file(file.file_id, Some(text.into())) + if let Ok(text) = String::from_utf8(v) { + analysis_change.change_file(file.file_id, Some(text)) } } } @@ -419,14 +419,10 @@ impl ProcMacroExpander for Expander { #[cfg(test)] mod tests { use ide_db::base_db::SourceDatabase; + use vfs::file_set::FileSetConfigBuilder; use super::*; - use ide_db::base_db::SourceRootId; - use vfs::{file_set::FileSetConfigBuilder, VfsPath}; - - use crate::SourceRootConfig; - #[test] fn test_loading_rust_analyzer() { let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap(); diff --git a/src/tools/rust-analyzer/crates/mbe/src/benchmark.rs b/src/tools/rust-analyzer/crates/mbe/src/benchmark.rs index d946ecc1caf..ac7f0711784 100644 --- a/src/tools/rust-analyzer/crates/mbe/src/benchmark.rs +++ b/src/tools/rust-analyzer/crates/mbe/src/benchmark.rs @@ -1,6 +1,7 @@ //! This module add real world mbe example for benchmark tests use rustc_hash::FxHashMap; +use span::Span; use syntax::{ ast::{self, HasName}, AstNode, SmolStr, @@ -9,7 +10,7 @@ use test_utils::{bench, bench_fixture, skip_slow_tests}; use crate::{ parser::{MetaVarKind, Op, RepeatKind, Separator}, - syntax_node_to_token_tree, DeclarativeMacro, DummyTestSpanData, DummyTestSpanMap, DUMMY, + syntax_node_to_token_tree, DeclarativeMacro, DummyTestSpanMap, DUMMY, }; #[test] @@ -50,14 +51,14 @@ fn benchmark_expand_macro_rules() { assert_eq!(hash, 69413); } -fn macro_rules_fixtures() -> FxHashMap<String, DeclarativeMacro<DummyTestSpanData>> { +fn macro_rules_fixtures() -> FxHashMap<String, DeclarativeMacro<Span>> { macro_rules_fixtures_tt() .into_iter() .map(|(id, tt)| (id, DeclarativeMacro::parse_macro_rules(&tt, true, true))) .collect() } -fn macro_rules_fixtures_tt() -> FxHashMap<String, tt::Subtree<DummyTestSpanData>> { +fn macro_rules_fixtures_tt() -> FxHashMap<String, tt::Subtree<Span>> { let fixture = bench_fixture::numerous_macro_rules(); let source_file = ast::SourceFile::parse(&fixture).ok().unwrap(); @@ -79,8 +80,8 @@ fn macro_rules_fixtures_tt() -> FxHashMap<String, tt::Subtree<DummyTestSpanData> /// Generate random invocation fixtures from rules fn invocation_fixtures( - rules: &FxHashMap<String, DeclarativeMacro<DummyTestSpanData>>, -) -> Vec<(String, tt::Subtree<DummyTestSpanData>)> { + rules: &FxHashMap<String, DeclarativeMacro<Span>>, +) -> Vec<(String, tt::Subtree<Span>)> { let mut seed = 123456789; let mut res = Vec::new(); @@ -128,8 +129,8 @@ fn invocation_fixtures( return res; fn collect_from_op( - op: &Op<DummyTestSpanData>, - token_trees: &mut Vec<tt::TokenTree<DummyTestSpanData>>, + op: &Op<Span>, + token_trees: &mut Vec<tt::TokenTree<Span>>, seed: &mut usize, ) { return match op { @@ -221,19 +222,19 @@ fn invocation_fixtures( *seed = usize::wrapping_add(usize::wrapping_mul(*seed, a), c); *seed } - fn make_ident(ident: &str) -> tt::TokenTree<DummyTestSpanData> { + fn make_ident(ident: &str) -> tt::TokenTree<Span> { tt::Leaf::Ident(tt::Ident { span: DUMMY, text: SmolStr::new(ident) }).into() } - fn make_punct(char: char) -> tt::TokenTree<DummyTestSpanData> { + fn make_punct(char: char) -> tt::TokenTree<Span> { tt::Leaf::Punct(tt::Punct { span: DUMMY, char, spacing: tt::Spacing::Alone }).into() } - fn make_literal(lit: &str) -> tt::TokenTree<DummyTestSpanData> { + fn make_literal(lit: &str) -> tt::TokenTree<Span> { tt::Leaf::Literal(tt::Literal { span: DUMMY, text: SmolStr::new(lit) }).into() } fn make_subtree( kind: tt::DelimiterKind, - token_trees: Option<Vec<tt::TokenTree<DummyTestSpanData>>>, - ) -> tt::TokenTree<DummyTestSpanData> { + token_trees: Option<Vec<tt::TokenTree<Span>>>, + ) -> tt::TokenTree<Span> { tt::Subtree { delimiter: tt::Delimiter { open: DUMMY, close: DUMMY, kind }, token_trees: token_trees.map(Vec::into_boxed_slice).unwrap_or_default(), diff --git a/src/tools/rust-analyzer/crates/mbe/src/syntax_bridge.rs b/src/tools/rust-analyzer/crates/mbe/src/syntax_bridge.rs index 3c270e30a9b..57d6082dd70 100644 --- a/src/tools/rust-analyzer/crates/mbe/src/syntax_bridge.rs +++ b/src/tools/rust-analyzer/crates/mbe/src/syntax_bridge.rs @@ -23,8 +23,11 @@ pub trait SpanMapper<S: Span> { fn span_for(&self, range: TextRange) -> S; } -impl<S: Span> SpanMapper<S> for SpanMap<S> { - fn span_for(&self, range: TextRange) -> S { +impl<S> SpanMapper<SpanData<S>> for SpanMap<S> +where + SpanData<S>: Span, +{ + fn span_for(&self, range: TextRange) -> SpanData<S> { self.span_at(range.start()) } } @@ -38,32 +41,30 @@ impl<S: Span, SM: SpanMapper<S>> SpanMapper<S> for &SM { /// Dummy things for testing where spans don't matter. pub(crate) mod dummy_test_span_utils { + use span::{Span, SyntaxContextId}; + use super::*; - pub type DummyTestSpanData = span::SpanData<DummyTestSyntaxContext>; - pub const DUMMY: DummyTestSpanData = span::SpanData { + pub const DUMMY: Span = Span { range: TextRange::empty(TextSize::new(0)), anchor: span::SpanAnchor { file_id: span::FileId::BOGUS, ast_id: span::ROOT_ERASED_FILE_AST_ID, }, - ctx: DummyTestSyntaxContext, + ctx: SyntaxContextId::ROOT, }; - #[derive(Debug, Copy, Clone, PartialEq, Eq)] - pub struct DummyTestSyntaxContext; - pub struct DummyTestSpanMap; - impl SpanMapper<span::SpanData<DummyTestSyntaxContext>> for DummyTestSpanMap { - fn span_for(&self, range: syntax::TextRange) -> span::SpanData<DummyTestSyntaxContext> { - span::SpanData { + impl SpanMapper<Span> for DummyTestSpanMap { + fn span_for(&self, range: syntax::TextRange) -> Span { + Span { range, anchor: span::SpanAnchor { file_id: span::FileId::BOGUS, ast_id: span::ROOT_ERASED_FILE_AST_ID, }, - ctx: DummyTestSyntaxContext, + ctx: SyntaxContextId::ROOT, } } } @@ -92,7 +93,7 @@ pub fn syntax_node_to_token_tree_modified<Ctx, SpanMap>( node: &SyntaxNode, map: SpanMap, append: FxHashMap<SyntaxElement, Vec<tt::Leaf<SpanData<Ctx>>>>, - remove: FxHashSet<SyntaxNode>, + remove: FxHashSet<SyntaxElement>, call_site: SpanData<Ctx>, ) -> tt::Subtree<SpanData<Ctx>> where @@ -121,7 +122,7 @@ where pub fn token_tree_to_syntax_node<Ctx>( tt: &tt::Subtree<SpanData<Ctx>>, entry_point: parser::TopEntryPoint, -) -> (Parse<SyntaxNode>, SpanMap<SpanData<Ctx>>) +) -> (Parse<SyntaxNode>, SpanMap<Ctx>) where SpanData<Ctx>: Span, Ctx: Copy, @@ -629,7 +630,7 @@ struct Converter<SpanMap, S> { /// Used to make the emitted text ranges in the spans relative to the span anchor. map: SpanMap, append: FxHashMap<SyntaxElement, Vec<tt::Leaf<S>>>, - remove: FxHashSet<SyntaxNode>, + remove: FxHashSet<SyntaxElement>, call_site: S, } @@ -638,7 +639,7 @@ impl<SpanMap, S> Converter<SpanMap, S> { node: &SyntaxNode, map: SpanMap, append: FxHashMap<SyntaxElement, Vec<tt::Leaf<S>>>, - remove: FxHashSet<SyntaxNode>, + remove: FxHashSet<SyntaxElement>, call_site: S, ) -> Self { let mut this = Converter { @@ -660,16 +661,25 @@ impl<SpanMap, S> Converter<SpanMap, S> { fn next_token(&mut self) -> Option<SyntaxToken> { while let Some(ev) = self.preorder.next() { match ev { - WalkEvent::Enter(SyntaxElement::Token(t)) => return Some(t), - WalkEvent::Enter(SyntaxElement::Node(n)) if self.remove.contains(&n) => { - self.preorder.skip_subtree(); - if let Some(mut v) = self.append.remove(&n.into()) { - v.reverse(); - self.current_leaves.extend(v); - return None; + WalkEvent::Enter(token) => { + if self.remove.contains(&token) { + match token { + syntax::NodeOrToken::Token(_) => { + continue; + } + node => { + self.preorder.skip_subtree(); + if let Some(mut v) = self.append.remove(&node) { + v.reverse(); + self.current_leaves.extend(v); + return None; + } + } + } + } else if let syntax::NodeOrToken::Token(token) = token { + return Some(token); } } - WalkEvent::Enter(SyntaxElement::Node(_)) => (), WalkEvent::Leave(ele) => { if let Some(mut v) = self.append.remove(&ele) { v.reverse(); @@ -824,7 +834,7 @@ where cursor: Cursor<'a, SpanData<Ctx>>, text_pos: TextSize, inner: SyntaxTreeBuilder, - token_map: SpanMap<SpanData<Ctx>>, + token_map: SpanMap<Ctx>, } impl<'a, Ctx> TtTreeSink<'a, Ctx> @@ -841,7 +851,7 @@ where } } - fn finish(mut self) -> (Parse<SyntaxNode>, SpanMap<SpanData<Ctx>>) { + fn finish(mut self) -> (Parse<SyntaxNode>, SpanMap<Ctx>) { self.token_map.finish(); (self.inner.finish(), self.token_map) } diff --git a/src/tools/rust-analyzer/crates/mbe/src/syntax_bridge/tests.rs b/src/tools/rust-analyzer/crates/mbe/src/syntax_bridge/tests.rs index 11d1a728799..a261b1d4319 100644 --- a/src/tools/rust-analyzer/crates/mbe/src/syntax_bridge/tests.rs +++ b/src/tools/rust-analyzer/crates/mbe/src/syntax_bridge/tests.rs @@ -1,4 +1,5 @@ use rustc_hash::FxHashMap; +use span::Span; use syntax::{ast, AstNode}; use test_utils::extract_annotations; use tt::{ @@ -6,7 +7,7 @@ use tt::{ Leaf, Punct, Spacing, }; -use crate::{syntax_node_to_token_tree, DummyTestSpanData, DummyTestSpanMap, DUMMY}; +use crate::{syntax_node_to_token_tree, DummyTestSpanMap, DUMMY}; fn check_punct_spacing(fixture: &str) { let source_file = ast::SourceFile::parse(fixture).ok().unwrap(); @@ -28,7 +29,7 @@ fn check_punct_spacing(fixture: &str) { while !cursor.eof() { while let Some(token_tree) = cursor.token_tree() { if let TokenTreeRef::Leaf( - Leaf::Punct(Punct { spacing, span: DummyTestSpanData { range, .. }, .. }), + Leaf::Punct(Punct { spacing, span: Span { range, .. }, .. }), _, ) = token_tree { diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs index 54a20357d26..11b008fc0b4 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs @@ -8,7 +8,12 @@ use expect_test::expect; #[test] fn test_derive_empty() { - assert_expand("DeriveEmpty", r#"struct S;"#, expect!["SUBTREE $$ 1 1"], expect!["SUBTREE $$ SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) }"]); + assert_expand( + "DeriveEmpty", + r#"struct S;"#, + expect!["SUBTREE $$ 1 1"], + expect!["SUBTREE $$ 42:2@0..100#0 42:2@0..100#0"], + ); } #[test] @@ -21,15 +26,15 @@ fn test_derive_error() { IDENT compile_error 1 PUNCH ! [alone] 1 SUBTREE () 1 1 - LITERAL "#[derive(DeriveError)] struct S ;" 1 + LITERAL "#[derive(DeriveError)] struct S ;"1 PUNCH ; [alone] 1"##]], expect![[r##" - SUBTREE $$ SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - IDENT compile_error SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH ! [alone] SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - SUBTREE () SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL "#[derive(DeriveError)] struct S ;" SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH ; [alone] SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) }"##]], + SUBTREE $$ 42:2@0..100#0 42:2@0..100#0 + IDENT compile_error 42:2@0..100#0 + PUNCH ! [alone] 42:2@0..100#0 + SUBTREE () 42:2@0..100#0 42:2@0..100#0 + LITERAL "#[derive(DeriveError)] struct S ;"42:2@0..100#0 + PUNCH ; [alone] 42:2@0..100#0"##]], ); } @@ -42,20 +47,20 @@ fn test_fn_like_macro_noop() { SUBTREE $$ 1 1 IDENT ident 1 PUNCH , [alone] 1 - LITERAL 0 1 + LITERAL 01 PUNCH , [alone] 1 - LITERAL 1 1 + LITERAL 11 PUNCH , [alone] 1 SUBTREE [] 1 1"#]], expect![[r#" - SUBTREE $$ SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - IDENT ident SpanData { range: 0..5, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 5..6, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL 0 SpanData { range: 7..8, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 8..9, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL 1 SpanData { range: 10..11, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 11..12, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - SUBTREE [] SpanData { range: 13..14, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 14..15, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) }"#]], + SUBTREE $$ 42:2@0..100#0 42:2@0..100#0 + IDENT ident 42:2@0..5#0 + PUNCH , [alone] 42:2@5..6#0 + LITERAL 042:2@7..8#0 + PUNCH , [alone] 42:2@8..9#0 + LITERAL 142:2@10..11#0 + PUNCH , [alone] 42:2@11..12#0 + SUBTREE [] 42:2@13..14#0 42:2@14..15#0"#]], ); } @@ -70,10 +75,10 @@ fn test_fn_like_macro_clone_ident_subtree() { PUNCH , [alone] 1 SUBTREE [] 1 1"#]], expect![[r#" - SUBTREE $$ SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - IDENT ident SpanData { range: 0..5, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 5..6, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - SUBTREE [] SpanData { range: 7..8, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 7..8, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) }"#]], + SUBTREE $$ 42:2@0..100#0 42:2@0..100#0 + IDENT ident 42:2@0..5#0 + PUNCH , [alone] 42:2@5..6#0 + SUBTREE [] 42:2@7..8#0 42:2@7..8#0"#]], ); } @@ -86,8 +91,8 @@ fn test_fn_like_macro_clone_raw_ident() { SUBTREE $$ 1 1 IDENT r#async 1"#]], expect![[r#" - SUBTREE $$ SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - IDENT r#async SpanData { range: 0..7, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) }"#]], + SUBTREE $$ 42:2@0..100#0 42:2@0..100#0 + IDENT r#async 42:2@0..7#0"#]], ); } @@ -100,8 +105,8 @@ fn test_fn_like_fn_like_span_join() { SUBTREE $$ 1 1 IDENT r#joined 1"#]], expect![[r#" - SUBTREE $$ SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - IDENT r#joined SpanData { range: 0..11, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) }"#]], + SUBTREE $$ 42:2@0..100#0 42:2@0..100#0 + IDENT r#joined 42:2@0..11#0"#]], ); } @@ -116,10 +121,10 @@ fn test_fn_like_fn_like_span_ops() { IDENT resolved_at_def_site 1 IDENT start_span 1"#]], expect![[r#" - SUBTREE $$ SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - IDENT set_def_site SpanData { range: 0..150, anchor: SpanAnchor(FileId(41), 1), ctx: SyntaxContextId(0) } - IDENT resolved_at_def_site SpanData { range: 13..33, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - IDENT start_span SpanData { range: 34..34, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) }"#]], + SUBTREE $$ 42:2@0..100#0 42:2@0..100#0 + IDENT set_def_site 41:1@0..150#0 + IDENT resolved_at_def_site 42:2@13..33#0 + IDENT start_span 42:2@34..34#0"#]], ); } @@ -130,22 +135,22 @@ fn test_fn_like_mk_literals() { r#""#, expect![[r#" SUBTREE $$ 1 1 - LITERAL b"byte_string" 1 - LITERAL 'c' 1 - LITERAL "string" 1 - LITERAL 3.14f64 1 - LITERAL 3.14 1 - LITERAL 123i64 1 - LITERAL 123 1"#]], + LITERAL b"byte_string"1 + LITERAL 'c'1 + LITERAL "string"1 + LITERAL 3.14f641 + LITERAL 3.141 + LITERAL 123i641 + LITERAL 1231"#]], expect![[r#" - SUBTREE $$ SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL b"byte_string" SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL 'c' SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL "string" SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL 3.14f64 SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL 3.14 SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL 123i64 SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL 123 SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) }"#]], + SUBTREE $$ 42:2@0..100#0 42:2@0..100#0 + LITERAL b"byte_string"42:2@0..100#0 + LITERAL 'c'42:2@0..100#0 + LITERAL "string"42:2@0..100#0 + LITERAL 3.14f6442:2@0..100#0 + LITERAL 3.1442:2@0..100#0 + LITERAL 123i6442:2@0..100#0 + LITERAL 12342:2@0..100#0"#]], ); } @@ -159,9 +164,9 @@ fn test_fn_like_mk_idents() { IDENT standard 1 IDENT r#raw 1"#]], expect![[r#" - SUBTREE $$ SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - IDENT standard SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - IDENT r#raw SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) }"#]], + SUBTREE $$ 42:2@0..100#0 42:2@0..100#0 + IDENT standard 42:2@0..100#0 + IDENT r#raw 42:2@0..100#0"#]], ); } @@ -172,48 +177,48 @@ fn test_fn_like_macro_clone_literals() { r###"1u16, 2_u32, -4i64, 3.14f32, "hello bridge", "suffixed"suffix, r##"raw"##, 'a', b'b', c"null""###, expect![[r###" SUBTREE $$ 1 1 - LITERAL 1u16 1 + LITERAL 1u161 PUNCH , [alone] 1 - LITERAL 2_u32 1 + LITERAL 2_u321 PUNCH , [alone] 1 PUNCH - [alone] 1 - LITERAL 4i64 1 + LITERAL 4i641 PUNCH , [alone] 1 - LITERAL 3.14f32 1 + LITERAL 3.14f321 PUNCH , [alone] 1 - LITERAL "hello bridge" 1 + LITERAL "hello bridge"1 PUNCH , [alone] 1 - LITERAL "suffixed"suffix 1 + LITERAL "suffixed"suffix1 PUNCH , [alone] 1 - LITERAL r##"raw"## 1 + LITERAL r##"raw"##1 PUNCH , [alone] 1 - LITERAL 'a' 1 + LITERAL 'a'1 PUNCH , [alone] 1 - LITERAL b'b' 1 + LITERAL b'b'1 PUNCH , [alone] 1 - LITERAL c"null" 1"###]], + LITERAL c"null"1"###]], expect![[r###" - SUBTREE $$ SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL 1u16 SpanData { range: 0..4, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 4..5, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL 2_u32 SpanData { range: 6..11, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 11..12, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH - [alone] SpanData { range: 13..14, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL 4i64 SpanData { range: 14..18, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 18..19, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL 3.14f32 SpanData { range: 20..27, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 27..28, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL "hello bridge" SpanData { range: 29..43, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 43..44, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL "suffixed"suffix SpanData { range: 45..61, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 61..62, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL r##"raw"## SpanData { range: 63..73, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 73..74, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL 'a' SpanData { range: 75..78, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 78..79, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL b'b' SpanData { range: 80..84, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH , [alone] SpanData { range: 84..85, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL c"null" SpanData { range: 86..93, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) }"###]], + SUBTREE $$ 42:2@0..100#0 42:2@0..100#0 + LITERAL 1u1642:2@0..4#0 + PUNCH , [alone] 42:2@4..5#0 + LITERAL 2_u3242:2@6..11#0 + PUNCH , [alone] 42:2@11..12#0 + PUNCH - [alone] 42:2@13..14#0 + LITERAL 4i6442:2@14..18#0 + PUNCH , [alone] 42:2@18..19#0 + LITERAL 3.14f3242:2@20..27#0 + PUNCH , [alone] 42:2@27..28#0 + LITERAL "hello bridge"42:2@29..43#0 + PUNCH , [alone] 42:2@43..44#0 + LITERAL "suffixed"suffix42:2@45..61#0 + PUNCH , [alone] 42:2@61..62#0 + LITERAL r##"raw"##42:2@63..73#0 + PUNCH , [alone] 42:2@73..74#0 + LITERAL 'a'42:2@75..78#0 + PUNCH , [alone] 42:2@78..79#0 + LITERAL b'b'42:2@80..84#0 + PUNCH , [alone] 42:2@84..85#0 + LITERAL c"null"42:2@86..93#0"###]], ); } @@ -231,15 +236,15 @@ fn test_attr_macro() { IDENT compile_error 1 PUNCH ! [alone] 1 SUBTREE () 1 1 - LITERAL "#[attr_error(some arguments)] mod m {}" 1 + LITERAL "#[attr_error(some arguments)] mod m {}"1 PUNCH ; [alone] 1"##]], expect![[r##" - SUBTREE $$ SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - IDENT compile_error SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH ! [alone] SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - SUBTREE () SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - LITERAL "#[attr_error(some arguments)] mod m {}" SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) } - PUNCH ; [alone] SpanData { range: 0..100, anchor: SpanAnchor(FileId(42), 2), ctx: SyntaxContextId(0) }"##]], + SUBTREE $$ 42:2@0..100#0 42:2@0..100#0 + IDENT compile_error 42:2@0..100#0 + PUNCH ! [alone] 42:2@0..100#0 + SUBTREE () 42:2@0..100#0 42:2@0..100#0 + LITERAL "#[attr_error(some arguments)] mod m {}"42:2@0..100#0 + PUNCH ; [alone] 42:2@0..100#0"##]], ); } diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs index 9a1311d9550..6050bc9e36e 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs @@ -91,7 +91,7 @@ fn assert_expand_impl( let res = expander .expand(macro_name, fixture.into_subtree(call_site), attr, def_site, call_site, mixed_site) .unwrap(); - expect_s.assert_eq(&format!("{res:?}")); + expect_s.assert_eq(&format!("{res:#?}")); } pub(crate) fn list() -> Vec<String> { diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml index 766606be7be..e6984d6f41b 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml +++ b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml @@ -42,6 +42,7 @@ triomphe.workspace = true nohash-hasher.workspace = true always-assert = "0.2.0" walkdir = "2.3.2" +semver.workspace = true cfg.workspace = true flycheck.workspace = true diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs index 07e04a83661..e747ec87b1c 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs @@ -16,6 +16,7 @@ use std::{env, fs, path::PathBuf, process::ExitCode, sync::Arc}; use anyhow::Context; use lsp_server::Connection; use rust_analyzer::{cli::flags, config::Config, from_json}; +use semver::Version; use tracing_subscriber::fmt::writer::BoxMakeWriter; use vfs::AbsPathBuf; @@ -193,10 +194,18 @@ fn run_server() -> anyhow::Result<()> { } }; - let mut is_visual_studio_code = false; + let mut visual_studio_code_version = None; if let Some(client_info) = client_info { - tracing::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default()); - is_visual_studio_code = client_info.name.starts_with("Visual Studio Code"); + tracing::info!( + "Client '{}' {}", + client_info.name, + client_info.version.as_deref().unwrap_or_default() + ); + visual_studio_code_version = client_info + .name + .starts_with("Visual Studio Code") + .then(|| client_info.version.as_deref().map(Version::parse).and_then(Result::ok)) + .flatten(); } let workspace_roots = workspace_folders @@ -210,7 +219,8 @@ fn run_server() -> anyhow::Result<()> { }) .filter(|workspaces| !workspaces.is_empty()) .unwrap_or_else(|| vec![root_path.clone()]); - let mut config = Config::new(root_path, capabilities, workspace_roots, is_visual_studio_code); + let mut config = + Config::new(root_path, capabilities, workspace_roots, visual_studio_code_version); if let Some(json) = initialization_options { if let Err(e) = config.update(json) { use lsp_types::{ diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs index ef184032bfb..5c474908e7a 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -1053,7 +1053,7 @@ fn location_csv_expr(db: &RootDatabase, vfs: &Vfs, sm: &BodySourceMap, expr_id: }; let root = db.parse_or_expand(src.file_id); let node = src.map(|e| e.to_node(&root).syntax().clone()); - let original_range = node.as_ref().original_file_range(db); + let original_range = node.as_ref().original_file_range_rooted(db); let path = vfs.file_path(original_range.file_id); let line_index = db.line_index(original_range.file_id); let text_range = original_range.range; @@ -1069,7 +1069,7 @@ fn location_csv_pat(db: &RootDatabase, vfs: &Vfs, sm: &BodySourceMap, pat_id: Pa }; let root = db.parse_or_expand(src.file_id); let node = src.map(|e| e.to_node(&root).syntax().clone()); - let original_range = node.as_ref().original_file_range(db); + let original_range = node.as_ref().original_file_range_rooted(db); let path = vfs.file_path(original_range.file_id); let line_index = db.line_index(original_range.file_id); let text_range = original_range.range; @@ -1088,7 +1088,7 @@ fn expr_syntax_range<'a>( if let Ok(src) = src { let root = db.parse_or_expand(src.file_id); let node = src.map(|e| e.to_node(&root).syntax().clone()); - let original_range = node.as_ref().original_file_range(db); + let original_range = node.as_ref().original_file_range_rooted(db); let path = vfs.file_path(original_range.file_id); let line_index = db.line_index(original_range.file_id); let text_range = original_range.range; @@ -1109,7 +1109,7 @@ fn pat_syntax_range<'a>( if let Ok(src) = src { let root = db.parse_or_expand(src.file_id); let node = src.map(|e| e.to_node(&root).syntax().clone()); - let original_range = node.as_ref().original_file_range(db); + let original_range = node.as_ref().original_file_range_rooted(db); let path = vfs.file_path(original_range.file_id); let line_index = db.line_index(original_range.file_id); let text_range = original_range.range; diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/rustc_tests.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/rustc_tests.rs index 7ad87ab97fc..84f2e600874 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/rustc_tests.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/rustc_tests.rs @@ -134,7 +134,7 @@ impl Tester { let should_have_no_error = text.contains("// check-pass") || text.contains("// build-pass") || text.contains("// run-pass"); - change.change_file(self.root_file, Some(Arc::from(text))); + change.change_file(self.root_file, Some(text)); self.host.apply_change(change); let diagnostic_config = DiagnosticsConfig::test_sample(); diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs index 8fd59d159c9..1061a433a58 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs @@ -32,8 +32,8 @@ impl flags::Scip { let mut config = crate::config::Config::new( root.clone(), lsp_types::ClientCapabilities::default(), - /* workspace_roots = */ vec![], - /* is_visual_studio_code = */ false, + vec![], + None, ); if let Some(p) = self.config_path { diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs index 9e81c8dd665..cbf15246590 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs @@ -31,6 +31,7 @@ use project_model::{ CargoConfig, CargoFeatures, ProjectJson, ProjectJsonData, ProjectManifest, RustLibSource, }; use rustc_hash::{FxHashMap, FxHashSet}; +use semver::Version; use serde::{de::DeserializeOwned, Deserialize}; use stdx::format_to_acc; use vfs::{AbsPath, AbsPathBuf}; @@ -624,7 +625,7 @@ pub struct Config { data: ConfigData, detached_files: Vec<AbsPathBuf>, snippets: Vec<Snippet>, - is_visual_studio_code: bool, + visual_studio_code_version: Option<Version>, } type ParallelCachePrimingNumThreads = u8; @@ -823,7 +824,7 @@ impl Config { root_path: AbsPathBuf, caps: ClientCapabilities, workspace_roots: Vec<AbsPathBuf>, - is_visual_studio_code: bool, + visual_studio_code_version: Option<Version>, ) -> Self { Config { caps, @@ -833,7 +834,7 @@ impl Config { root_path, snippets: Default::default(), workspace_roots, - is_visual_studio_code, + visual_studio_code_version, } } @@ -1778,10 +1779,10 @@ impl Config { self.data.typing_autoClosingAngleBrackets_enable } - // FIXME: VSCode seems to work wrong sometimes, see https://github.com/microsoft/vscode/issues/193124 - // hence, distinguish it for now. - pub fn is_visual_studio_code(&self) -> bool { - self.is_visual_studio_code + // VSCode is our reference implementation, so we allow ourselves to work around issues by + // special casing certain versions + pub fn visual_studio_code_version(&self) -> Option<&Version> { + self.visual_studio_code_version.as_ref() } } // Deserialization definitions @@ -2694,7 +2695,7 @@ mod tests { AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![], - false, + None, ); config .update(serde_json::json!({ @@ -2710,7 +2711,7 @@ mod tests { AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![], - false, + None, ); config .update(serde_json::json!({ @@ -2726,7 +2727,7 @@ mod tests { AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![], - false, + None, ); config .update(serde_json::json!({ @@ -2745,7 +2746,7 @@ mod tests { AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![], - false, + None, ); config .update(serde_json::json!({ @@ -2764,7 +2765,7 @@ mod tests { AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![], - false, + None, ); config .update(serde_json::json!({ @@ -2783,7 +2784,7 @@ mod tests { AbsPathBuf::try_from(project_root()).unwrap(), Default::default(), vec![], - false, + None, ); config .update(serde_json::json!({ diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics/to_proto.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics/to_proto.rs index e900f2601d8..6e6cc53c251 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics/to_proto.rs @@ -542,7 +542,7 @@ mod tests { workspace_root.to_path_buf(), ClientCapabilities::default(), Vec::new(), - false, + None, ), ); let snap = state.snapshot(); diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs index 0e560e54eda..1b4c33d8586 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs @@ -330,7 +330,7 @@ impl GlobalState { // FIXME: Consider doing normalization in the `vfs` instead? That allows // getting rid of some locking let (text, line_endings) = LineEndings::normalize(text); - (Arc::from(text), line_endings) + (text, line_endings) }) } else { None diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/integrated_benchmarks.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/integrated_benchmarks.rs index 3bba4847f92..1c5a862c703 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/integrated_benchmarks.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/integrated_benchmarks.rs @@ -20,7 +20,6 @@ use ide_db::{ }; use project_model::CargoConfig; use test_utils::project_root; -use triomphe::Arc; use vfs::{AbsPathBuf, VfsPath}; use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice}; @@ -57,8 +56,6 @@ fn integrated_highlighting_benchmark() { vfs.file_id(&path).unwrap_or_else(|| panic!("can't find virtual file for {path}")) }; - let _g = crate::tracing::hprof::init("*>150"); - { let _it = stdx::timeit("initial"); let analysis = host.analysis(); @@ -68,13 +65,16 @@ fn integrated_highlighting_benchmark() { { let _it = stdx::timeit("change"); let mut text = host.analysis().file_text(file_id).unwrap().to_string(); - text.push_str("\npub fn _dummy() {}\n"); + text = text.replace( + "self.data.cargo_buildScripts_rebuildOnSave", + "self. data. cargo_buildScripts_rebuildOnSave", + ); let mut change = ChangeWithProcMacros::new(); - change.change_file(file_id, Some(Arc::from(text))); + change.change_file(file_id, Some(text)); host.apply_change(change); } - let _g = crate::tracing::hprof::init("*>50"); + let _g = crate::tracing::hprof::init("*>20"); { let _it = stdx::timeit("after change"); @@ -125,7 +125,7 @@ fn integrated_completion_benchmark() { patch(&mut text, "db.struct_data(self.id)", "sel;\ndb.struct_data(self.id)") + "sel".len(); let mut change = ChangeWithProcMacros::new(); - change.change_file(file_id, Some(Arc::from(text))); + change.change_file(file_id, Some(text)); host.apply_change(change); completion_offset }; @@ -168,7 +168,7 @@ fn integrated_completion_benchmark() { patch(&mut text, "sel;\ndb.struct_data(self.id)", ";sel;\ndb.struct_data(self.id)") + ";sel".len(); let mut change = ChangeWithProcMacros::new(); - change.change_file(file_id, Some(Arc::from(text))); + change.change_file(file_id, Some(text)); host.apply_change(change); completion_offset }; @@ -210,7 +210,7 @@ fn integrated_completion_benchmark() { patch(&mut text, "sel;\ndb.struct_data(self.id)", "self.;\ndb.struct_data(self.id)") + "self.".len(); let mut change = ChangeWithProcMacros::new(); - change.change_file(file_id, Some(Arc::from(text))); + change.change_file(file_id, Some(text)); host.apply_change(change); completion_offset }; @@ -307,7 +307,7 @@ fn integrated_diagnostics_benchmark() { let mut text = host.analysis().file_text(file_id).unwrap().to_string(); patch(&mut text, "db.struct_data(self.id)", "();\ndb.struct_data(self.id)"); let mut change = ChangeWithProcMacros::new(); - change.change_file(file_id, Some(Arc::from(text))); + change.change_file(file_id, Some(text)); host.apply_change(change); }; diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs index 86ab652f8ef..710ce7f8acb 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs @@ -234,6 +234,13 @@ impl Notification for EndRunTest { const METHOD: &'static str = "experimental/endRunTest"; } +pub enum AppendOutputToRunTest {} + +impl Notification for AppendOutputToRunTest { + type Params = String; + const METHOD: &'static str = "experimental/appendOutputToRunTest"; +} + pub enum AbortRunTest {} impl Notification for AbortRunTest { diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/semantic_tokens.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/semantic_tokens.rs index dd7dcf52778..c5081c4bea0 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/semantic_tokens.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/semantic_tokens.rs @@ -85,6 +85,7 @@ define_semantic_token_types![ (LIFETIME, "lifetime"), (LOGICAL, "logical") => OPERATOR, (MACRO_BANG, "macroBang") => MACRO, + (PROC_MACRO, "procMacro") => MACRO, (PARENTHESIS, "parenthesis"), (PUNCTUATION, "punctuation"), (SELF_KEYWORD, "selfKeyword") => KEYWORD, @@ -143,6 +144,7 @@ define_semantic_token_modifiers![ (INTRA_DOC_LINK, "intraDocLink"), (LIBRARY, "library"), (MACRO_MODIFIER, "macro"), + (PROC_MACRO_MODIFIER, "proc_macro"), (MUTABLE, "mutable"), (PUBLIC, "public"), (REFERENCE, "reference"), diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs index e2b55f4a5c5..e77d0c13bf2 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs @@ -15,6 +15,7 @@ use ide::{ }; use ide_db::rust_doc::format_docs; use itertools::Itertools; +use semver::VersionReq; use serde_json::to_value; use vfs::AbsPath; @@ -56,6 +57,7 @@ pub(crate) fn symbol_kind(symbol_kind: SymbolKind) -> lsp_types::SymbolKind { SymbolKind::Variant => lsp_types::SymbolKind::ENUM_MEMBER, SymbolKind::Trait | SymbolKind::TraitAlias => lsp_types::SymbolKind::INTERFACE, SymbolKind::Macro + | SymbolKind::ProcMacro | SymbolKind::BuiltinAttr | SymbolKind::Attribute | SymbolKind::Derive @@ -138,6 +140,7 @@ pub(crate) fn completion_item_kind( SymbolKind::LifetimeParam => lsp_types::CompletionItemKind::TYPE_PARAMETER, SymbolKind::Local => lsp_types::CompletionItemKind::VARIABLE, SymbolKind::Macro => lsp_types::CompletionItemKind::FUNCTION, + SymbolKind::ProcMacro => lsp_types::CompletionItemKind::FUNCTION, SymbolKind::Module => lsp_types::CompletionItemKind::MODULE, SymbolKind::SelfParam => lsp_types::CompletionItemKind::VALUE, SymbolKind::SelfType => lsp_types::CompletionItemKind::TYPE_PARAMETER, @@ -443,17 +446,24 @@ pub(crate) fn inlay_hint( file_id: FileId, inlay_hint: InlayHint, ) -> Cancellable<lsp_types::InlayHint> { - let is_visual_studio_code = snap.config.is_visual_studio_code(); let needs_resolve = inlay_hint.needs_resolve; let (label, tooltip, mut something_to_resolve) = inlay_hint_label(snap, fields_to_resolve, needs_resolve, inlay_hint.label)?; - let text_edits = - if !is_visual_studio_code && needs_resolve && fields_to_resolve.resolve_text_edits { - something_to_resolve |= inlay_hint.text_edit.is_some(); - None - } else { - inlay_hint.text_edit.map(|it| text_edit_vec(line_index, it)) - }; + + let text_edits = if snap + .config + .visual_studio_code_version() + // https://github.com/microsoft/vscode/issues/193124 + .map_or(true, |version| VersionReq::parse(">=1.86.0").unwrap().matches(version)) + && needs_resolve + && fields_to_resolve.resolve_text_edits + { + something_to_resolve |= inlay_hint.text_edit.is_some(); + None + } else { + inlay_hint.text_edit.map(|it| text_edit_vec(line_index, it)) + }; + let data = if needs_resolve && something_to_resolve { Some(to_value(lsp_ext::InlayHintResolveData { file_id: file_id.index() }).unwrap()) } else { @@ -667,6 +677,7 @@ fn semantic_token_type_and_modifiers( SymbolKind::Trait => semantic_tokens::INTERFACE, SymbolKind::TraitAlias => semantic_tokens::INTERFACE, SymbolKind::Macro => semantic_tokens::MACRO, + SymbolKind::ProcMacro => semantic_tokens::PROC_MACRO, SymbolKind::BuiltinAttr => semantic_tokens::BUILTIN_ATTRIBUTE, SymbolKind::ToolModule => semantic_tokens::TOOL_MODULE, }, @@ -720,6 +731,7 @@ fn semantic_token_type_and_modifiers( HlMod::IntraDocLink => semantic_tokens::INTRA_DOC_LINK, HlMod::Library => semantic_tokens::LIBRARY, HlMod::Macro => semantic_tokens::MACRO_MODIFIER, + HlMod::ProcMacro => semantic_tokens::PROC_MACRO_MODIFIER, HlMod::Mutable => semantic_tokens::MUTABLE, HlMod::Public => semantic_tokens::PUBLIC, HlMod::Reference => semantic_tokens::REFERENCE, @@ -1507,13 +1519,28 @@ pub(crate) fn test_item( id: test_item.id, label: test_item.label, kind: match test_item.kind { - ide::TestItemKind::Crate => lsp_ext::TestItemKind::Package, + ide::TestItemKind::Crate(id) => 'b: { + let Some((cargo_ws, target)) = snap.cargo_target_for_crate_root(id) else { + break 'b lsp_ext::TestItemKind::Package; + }; + let target = &cargo_ws[target]; + match target.kind { + project_model::TargetKind::Bin + | project_model::TargetKind::Lib { .. } + | project_model::TargetKind::Example + | project_model::TargetKind::BuildScript + | project_model::TargetKind::Other => lsp_ext::TestItemKind::Package, + project_model::TargetKind::Test | project_model::TargetKind::Bench => { + lsp_ext::TestItemKind::Test + } + } + } ide::TestItemKind::Module => lsp_ext::TestItemKind::Module, ide::TestItemKind::Function => lsp_ext::TestItemKind::Test, }, can_resolve_children: matches!( test_item.kind, - ide::TestItemKind::Crate | ide::TestItemKind::Module + ide::TestItemKind::Crate(_) | ide::TestItemKind::Module ), parent: test_item.parent, text_document: test_item diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs index bca6db19dcf..ffe56e41435 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs @@ -488,20 +488,22 @@ impl GlobalState { fn update_diagnostics(&mut self) { let db = self.analysis_host.raw_database(); - let subscriptions = self - .mem_docs - .iter() - .map(|path| self.vfs.read().0.file_id(path).unwrap()) - .filter(|&file_id| { - let source_root = db.file_source_root(file_id); - // Only publish diagnostics for files in the workspace, not from crates.io deps - // or the sysroot. - // While theoretically these should never have errors, we have quite a few false - // positives particularly in the stdlib, and those diagnostics would stay around - // forever if we emitted them here. - !db.source_root(source_root).is_library - }) - .collect::<Vec<_>>(); + let subscriptions = { + let vfs = &self.vfs.read().0; + self.mem_docs + .iter() + .map(|path| vfs.file_id(path).unwrap()) + .filter(|&file_id| { + let source_root = db.file_source_root(file_id); + // Only publish diagnostics for files in the workspace, not from crates.io deps + // or the sysroot. + // While theoretically these should never have errors, we have quite a few false + // positives particularly in the stdlib, and those diagnostics would stay around + // forever if we emitted them here. + !db.source_root(source_root).is_library + }) + .collect::<Vec<_>>() + }; tracing::trace!("updating notifications for {:?}", subscriptions); // Diagnostics are triggered by the user typing @@ -797,6 +799,9 @@ impl GlobalState { self.send_notification::<lsp_ext::EndRunTest>(()); self.test_run_session = None; } + flycheck::CargoTestMessage::Custom { text } => { + self.send_notification::<lsp_ext::AppendOutputToRunTest>(text); + } } } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs index dfd25abc70f..1d831b8b105 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs @@ -171,7 +171,7 @@ impl Project<'_> { ..Default::default() }, roots, - false, + None, ); config.update(self.config).expect("invalid config"); config.rediscover_workspaces(); diff --git a/src/tools/rust-analyzer/crates/span/src/hygiene.rs b/src/tools/rust-analyzer/crates/span/src/hygiene.rs index 4f6d792201b..e4b0a26a6ff 100644 --- a/src/tools/rust-analyzer/crates/span/src/hygiene.rs +++ b/src/tools/rust-analyzer/crates/span/src/hygiene.rs @@ -26,9 +26,19 @@ use salsa::{InternId, InternValue}; use crate::MacroCallId; /// Interned [`SyntaxContextData`]. -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SyntaxContextId(InternId); +impl fmt::Debug for SyntaxContextId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if f.alternate() { + write!(f, "{}", self.0.as_u32()) + } else { + f.debug_tuple("SyntaxContextId").field(&self.0).finish() + } + } +} + impl salsa::InternKey for SyntaxContextId { fn from_intern_id(v: salsa::InternId) -> Self { SyntaxContextId(v) diff --git a/src/tools/rust-analyzer/crates/span/src/lib.rs b/src/tools/rust-analyzer/crates/span/src/lib.rs index 0fe3275863d..6b849ce3738 100644 --- a/src/tools/rust-analyzer/crates/span/src/lib.rs +++ b/src/tools/rust-analyzer/crates/span/src/lib.rs @@ -44,7 +44,10 @@ pub const FIXUP_ERASED_FILE_AST_ID_MARKER: ErasedFileAstId = pub type Span = SpanData<SyntaxContextId>; -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +/// Spans represent a region of code, used by the IDE to be able link macro inputs and outputs +/// together. Positions in spans are relative to some [`SpanAnchor`] to make them more incremental +/// friendly. +#[derive(Clone, Copy, PartialEq, Eq, Hash)] pub struct SpanData<Ctx> { /// The text range of this span, relative to the anchor. /// We need the anchor for incrementality, as storing absolute ranges will require @@ -56,9 +59,35 @@ pub struct SpanData<Ctx> { pub ctx: Ctx, } +impl<Ctx: fmt::Debug> fmt::Debug for SpanData<Ctx> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if f.alternate() { + fmt::Debug::fmt(&self.anchor.file_id.index(), f)?; + f.write_char(':')?; + fmt::Debug::fmt(&self.anchor.ast_id.into_raw(), f)?; + f.write_char('@')?; + fmt::Debug::fmt(&self.range, f)?; + f.write_char('#')?; + self.ctx.fmt(f) + } else { + f.debug_struct("SpanData") + .field("range", &self.range) + .field("anchor", &self.anchor) + .field("ctx", &self.ctx) + .finish() + } + } +} + +impl<Ctx: Copy> SpanData<Ctx> { + pub fn eq_ignoring_ctx(self, other: Self) -> bool { + self.anchor == other.anchor && self.range == other.range + } +} + impl Span { #[deprecated = "dummy spans will panic if surfaced incorrectly, as such they should be replaced appropriately"] - pub const DUMMY: Self = SpanData { + pub const DUMMY: Self = Self { range: TextRange::empty(TextSize::new(0)), anchor: SpanAnchor { file_id: FileId::BOGUS, ast_id: ROOT_ERASED_FILE_AST_ID }, ctx: SyntaxContextId::ROOT, diff --git a/src/tools/rust-analyzer/crates/span/src/map.rs b/src/tools/rust-analyzer/crates/span/src/map.rs index 9f8101c816e..1f396a1e97b 100644 --- a/src/tools/rust-analyzer/crates/span/src/map.rs +++ b/src/tools/rust-analyzer/crates/span/src/map.rs @@ -1,23 +1,26 @@ //! A map that maps a span to every position in a file. Usually maps a span to some range of positions. //! Allows bidirectional lookup. -use std::hash::Hash; +use std::{fmt, hash::Hash}; use stdx::{always, itertools::Itertools}; use syntax::{TextRange, TextSize}; use vfs::FileId; -use crate::{ErasedFileAstId, Span, SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID}; +use crate::{ + ErasedFileAstId, Span, SpanAnchor, SpanData, SyntaxContextId, ROOT_ERASED_FILE_AST_ID, +}; /// Maps absolute text ranges for the corresponding file to the relevant span data. #[derive(Debug, PartialEq, Eq, Clone, Hash)] pub struct SpanMap<S> { - spans: Vec<(TextSize, S)>, - // FIXME: Should be - // spans: Vec<(TextSize, crate::SyntaxContextId)>, + spans: Vec<(TextSize, SpanData<S>)>, } -impl<S: Copy> SpanMap<S> { +impl<S> SpanMap<S> +where + SpanData<S>: Copy, +{ /// Creates a new empty [`SpanMap`]. pub fn empty() -> Self { Self { spans: Vec::new() } @@ -34,7 +37,7 @@ impl<S: Copy> SpanMap<S> { } /// Pushes a new span onto the [`SpanMap`]. - pub fn push(&mut self, offset: TextSize, span: S) { + pub fn push(&mut self, offset: TextSize, span: SpanData<S>) { if cfg!(debug_assertions) { if let Some(&(last_offset, _)) = self.spans.last() { assert!( @@ -49,13 +52,31 @@ impl<S: Copy> SpanMap<S> { /// Returns all [`TextRange`]s that correspond to the given span. /// /// Note this does a linear search through the entire backing vector. - pub fn ranges_with_span(&self, span: S) -> impl Iterator<Item = TextRange> + '_ + pub fn ranges_with_span_exact(&self, span: SpanData<S>) -> impl Iterator<Item = TextRange> + '_ where - S: Eq, + S: Copy, { - // FIXME: This should ignore the syntax context! self.spans.iter().enumerate().filter_map(move |(idx, &(end, s))| { - if s != span { + if !s.eq_ignoring_ctx(span) { + return None; + } + let start = idx.checked_sub(1).map_or(TextSize::new(0), |prev| self.spans[prev].0); + Some(TextRange::new(start, end)) + }) + } + + /// Returns all [`TextRange`]s whose spans contain the given span. + /// + /// Note this does a linear search through the entire backing vector. + pub fn ranges_with_span(&self, span: SpanData<S>) -> impl Iterator<Item = TextRange> + '_ + where + S: Copy, + { + self.spans.iter().enumerate().filter_map(move |(idx, &(end, s))| { + if s.anchor != span.anchor { + return None; + } + if !s.range.contains_range(span.range) { return None; } let start = idx.checked_sub(1).map_or(TextSize::new(0), |prev| self.spans[prev].0); @@ -64,21 +85,21 @@ impl<S: Copy> SpanMap<S> { } /// Returns the span at the given position. - pub fn span_at(&self, offset: TextSize) -> S { + pub fn span_at(&self, offset: TextSize) -> SpanData<S> { let entry = self.spans.partition_point(|&(it, _)| it <= offset); self.spans[entry].1 } /// Returns the spans associated with the given range. /// In other words, this will return all spans that correspond to all offsets within the given range. - pub fn spans_for_range(&self, range: TextRange) -> impl Iterator<Item = S> + '_ { + pub fn spans_for_range(&self, range: TextRange) -> impl Iterator<Item = SpanData<S>> + '_ { let (start, end) = (range.start(), range.end()); let start_entry = self.spans.partition_point(|&(it, _)| it <= start); let end_entry = self.spans[start_entry..].partition_point(|&(it, _)| it <= end); // FIXME: this might be wrong? self.spans[start_entry..][..end_entry].iter().map(|&(_, s)| s) } - pub fn iter(&self) -> impl Iterator<Item = (TextSize, S)> + '_ { + pub fn iter(&self) -> impl Iterator<Item = (TextSize, SpanData<S>)> + '_ { self.spans.iter().copied() } } @@ -92,6 +113,16 @@ pub struct RealSpanMap { end: TextSize, } +impl fmt::Display for RealSpanMap { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + writeln!(f, "RealSpanMap({:?}):", self.file_id)?; + for span in self.pairs.iter() { + writeln!(f, "{}: {}", u32::from(span.0), span.1.into_raw().into_u32())?; + } + Ok(()) + } +} + impl RealSpanMap { /// Creates a real file span map that returns absolute ranges (relative ranges to the root ast id). pub fn absolute(file_id: FileId) -> Self { diff --git a/src/tools/rust-analyzer/crates/stdx/src/anymap.rs b/src/tools/rust-analyzer/crates/stdx/src/anymap.rs index 899cd8ac6bb..d47b3d1647e 100644 --- a/src/tools/rust-analyzer/crates/stdx/src/anymap.rs +++ b/src/tools/rust-analyzer/crates/stdx/src/anymap.rs @@ -194,21 +194,6 @@ impl<'a, A: ?Sized + Downcast, V: IntoBox<A>> VacantEntry<'a, A, V> { mod tests { use super::*; - #[derive(Clone, Debug, PartialEq)] - struct A(i32); - #[derive(Clone, Debug, PartialEq)] - struct B(i32); - #[derive(Clone, Debug, PartialEq)] - struct C(i32); - #[derive(Clone, Debug, PartialEq)] - struct D(i32); - #[derive(Clone, Debug, PartialEq)] - struct E(i32); - #[derive(Clone, Debug, PartialEq)] - struct F(i32); - #[derive(Clone, Debug, PartialEq)] - struct J(i32); - #[test] fn test_varieties() { fn assert_send<T: Send>() {} diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs index 1bc1ef8434f..c3d6f50e6b0 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs @@ -139,6 +139,17 @@ impl From<ast::AssocItem> for ast::Item { } } +impl From<ast::ExternItem> for ast::Item { + fn from(extern_item: ast::ExternItem) -> Self { + match extern_item { + ast::ExternItem::Static(it) => ast::Item::Static(it), + ast::ExternItem::Fn(it) => ast::Item::Fn(it), + ast::ExternItem::MacroCall(it) => ast::Item::MacroCall(it), + ast::ExternItem::TypeAlias(it) => ast::Item::TypeAlias(it), + } + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum AttrKind { Inner, diff --git a/src/tools/rust-analyzer/crates/test-fixture/src/lib.rs b/src/tools/rust-analyzer/crates/test-fixture/src/lib.rs index a654366c62a..8cf65d11c6c 100644 --- a/src/tools/rust-analyzer/crates/test-fixture/src/lib.rs +++ b/src/tools/rust-analyzer/crates/test-fixture/src/lib.rs @@ -149,12 +149,12 @@ impl ChangeFixture { for entry in fixture { let text = if entry.text.contains(CURSOR_MARKER) { if entry.text.contains(ESCAPED_CURSOR_MARKER) { - entry.text.replace(ESCAPED_CURSOR_MARKER, CURSOR_MARKER).into() + entry.text.replace(ESCAPED_CURSOR_MARKER, CURSOR_MARKER) } else { let (range_or_offset, text) = extract_range_or_offset(&entry.text); assert!(file_position.is_none()); file_position = Some((file_id, range_or_offset)); - text.into() + text } } else { entry.text.as_str().into() @@ -251,7 +251,7 @@ impl ChangeFixture { fs.insert(core_file, VfsPath::new_virtual_path("/sysroot/core/lib.rs".to_owned())); roots.push(SourceRoot::new_library(fs)); - source_change.change_file(core_file, Some(mini_core.source_code().into())); + source_change.change_file(core_file, Some(mini_core.source_code())); let all_crates = crate_graph.crates_in_topological_order(); @@ -287,7 +287,7 @@ impl ChangeFixture { ); roots.push(SourceRoot::new_library(fs)); - source_change.change_file(proc_lib_file, Some(source.into())); + source_change.change_file(proc_lib_file, Some(source)); let all_crates = crate_graph.crates_in_topological_order(); diff --git a/src/tools/rust-analyzer/crates/tt/src/lib.rs b/src/tools/rust-analyzer/crates/tt/src/lib.rs index eec88f80688..28289a6431e 100644 --- a/src/tools/rust-analyzer/crates/tt/src/lib.rs +++ b/src/tools/rust-analyzer/crates/tt/src/lib.rs @@ -177,17 +177,19 @@ fn print_debug_subtree<S: fmt::Debug>( let align = " ".repeat(level); let Delimiter { kind, open, close } = &subtree.delimiter; - let aux = match kind { - DelimiterKind::Invisible => format!("$$ {:?} {:?}", open, close), - DelimiterKind::Parenthesis => format!("() {:?} {:?}", open, close), - DelimiterKind::Brace => format!("{{}} {:?} {:?}", open, close), - DelimiterKind::Bracket => format!("[] {:?} {:?}", open, close), + let delim = match kind { + DelimiterKind::Invisible => "$$", + DelimiterKind::Parenthesis => "()", + DelimiterKind::Brace => "{}", + DelimiterKind::Bracket => "[]", }; - if subtree.token_trees.is_empty() { - write!(f, "{align}SUBTREE {aux}")?; - } else { - writeln!(f, "{align}SUBTREE {aux}")?; + write!(f, "{align}SUBTREE {delim} ",)?; + fmt::Debug::fmt(&open, f)?; + write!(f, " ")?; + fmt::Debug::fmt(&close, f)?; + if !subtree.token_trees.is_empty() { + writeln!(f)?; for (idx, child) in subtree.token_trees.iter().enumerate() { print_debug_token(f, child, level + 1)?; if idx != subtree.token_trees.len() - 1 { @@ -208,16 +210,24 @@ fn print_debug_token<S: fmt::Debug>( match tkn { TokenTree::Leaf(leaf) => match leaf { - Leaf::Literal(lit) => write!(f, "{}LITERAL {} {:?}", align, lit.text, lit.span)?, - Leaf::Punct(punct) => write!( - f, - "{}PUNCH {} [{}] {:?}", - align, - punct.char, - if punct.spacing == Spacing::Alone { "alone" } else { "joint" }, - punct.span - )?, - Leaf::Ident(ident) => write!(f, "{}IDENT {} {:?}", align, ident.text, ident.span)?, + Leaf::Literal(lit) => { + write!(f, "{}LITERAL {}", align, lit.text)?; + fmt::Debug::fmt(&lit.span, f)?; + } + Leaf::Punct(punct) => { + write!( + f, + "{}PUNCH {} [{}] ", + align, + punct.char, + if punct.spacing == Spacing::Alone { "alone" } else { "joint" }, + )?; + fmt::Debug::fmt(&punct.span, f)?; + } + Leaf::Ident(ident) => { + write!(f, "{}IDENT {} ", align, ident.text)?; + fmt::Debug::fmt(&ident.span, f)?; + } }, TokenTree::Subtree(subtree) => { print_debug_subtree(f, subtree, level)?; diff --git a/src/tools/rust-analyzer/docs/dev/lsp-extensions.md b/src/tools/rust-analyzer/docs/dev/lsp-extensions.md index af5b4e51ef3..cf9ad5fe04d 100644 --- a/src/tools/rust-analyzer/docs/dev/lsp-extensions.md +++ b/src/tools/rust-analyzer/docs/dev/lsp-extensions.md @@ -1,5 +1,5 @@ <!--- -lsp/ext.rs hash: 6bc140531b403717 +lsp/ext.rs hash: 61f485497d6e8e88 If you need to change the above hash to make the test pass, please check if you need to adjust this doc as well and ping this issue: @@ -509,6 +509,13 @@ interface ChangeTestStateParams { } ``` +**Method:** `experimental/appendOutputToRunTest` + +**Notification:** `string` + +This notification is used for reporting messages independent of any single test and related to the run session +in general, e.g. cargo compiling progress messages or warnings. + ## Open External Documentation This request is sent from the client to the server to obtain web and local URL(s) for documentation related to the symbol under the cursor, if available. diff --git a/src/tools/rust-analyzer/editors/code/language-configuration.json b/src/tools/rust-analyzer/editors/code/language-configuration.json index 1c348b63f1a..bdae0e6ba9b 100644 --- a/src/tools/rust-analyzer/editors/code/language-configuration.json +++ b/src/tools/rust-analyzer/editors/code/language-configuration.json @@ -18,7 +18,7 @@ { "open": "[", "close": "]" }, { "open": "(", "close": ")" }, { "open": "\"", "close": "\"", "notIn": ["string"] }, - { "open": "/*", "close": " */" }, + { "open": "/*", "close": " */", "notIn": ["string"] }, { "open": "`", "close": "`", "notIn": ["string"] } ], "autoCloseBefore": ";:.,=}])> \n\t", diff --git a/src/tools/rust-analyzer/editors/code/package-lock.json b/src/tools/rust-analyzer/editors/code/package-lock.json index 291cef926f8..bd8b0e9c4e0 100644 --- a/src/tools/rust-analyzer/editors/code/package-lock.json +++ b/src/tools/rust-analyzer/editors/code/package-lock.json @@ -2290,9 +2290,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.15.4", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", - "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "dev": true, "funding": [ { diff --git a/src/tools/rust-analyzer/editors/code/src/lsp_ext.ts b/src/tools/rust-analyzer/editors/code/src/lsp_ext.ts index 31ac3d9413e..ca8106371b0 100644 --- a/src/tools/rust-analyzer/editors/code/src/lsp_ext.ts +++ b/src/tools/rust-analyzer/editors/code/src/lsp_ext.ts @@ -100,6 +100,9 @@ export const discoveredTests = new lc.NotificationType<DiscoverTestResults>( export const runTest = new lc.RequestType<RunTestParams, void, void>("experimental/runTest"); export const abortRunTest = new lc.NotificationType0("experimental/abortRunTest"); export const endRunTest = new lc.NotificationType0("experimental/endRunTest"); +export const appendOutputToRunTest = new lc.NotificationType<string>( + "experimental/appendOutputToRunTest", +); export const changeTestState = new lc.NotificationType<ChangeTestStateParams>( "experimental/changeTestState", ); diff --git a/src/tools/rust-analyzer/editors/code/src/test_explorer.ts b/src/tools/rust-analyzer/editors/code/src/test_explorer.ts index 2f0b4d5b5cf..ac4ffb19263 100644 --- a/src/tools/rust-analyzer/editors/code/src/test_explorer.ts +++ b/src/tools/rust-analyzer/editors/code/src/test_explorer.ts @@ -142,6 +142,12 @@ export const prepareTestExplorer = ( ); ctx.pushClientCleanup( + client.onNotification(ra.appendOutputToRunTest, (output) => { + currentTestRun!.appendOutput(`${output}\r\n`); + }), + ); + + ctx.pushClientCleanup( client.onNotification(ra.changeTestState, (results) => { const test = idToTestMap.get(results.testId)!; if (results.state.tag === "failed") { diff --git a/src/tools/rustfmt/src/expr.rs b/src/tools/rustfmt/src/expr.rs index c500b30b998..053afcc52d4 100644 --- a/src/tools/rustfmt/src/expr.rs +++ b/src/tools/rustfmt/src/expr.rs @@ -3,7 +3,7 @@ use std::cmp::min; use itertools::Itertools; use rustc_ast::token::{Delimiter, Lit, LitKind}; -use rustc_ast::{ast, ptr, token, ForLoopKind}; +use rustc_ast::{ast, ptr, token, ForLoopKind, MatchKind}; use rustc_span::{BytePos, Span}; use crate::chains::rewrite_chain; @@ -170,8 +170,8 @@ pub(crate) fn format_expr( } } } - ast::ExprKind::Match(ref cond, ref arms) => { - rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs) + ast::ExprKind::Match(ref cond, ref arms, kind) => { + rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs, kind) } ast::ExprKind::Path(ref qself, ref path) => { rewrite_path(context, PathContext::Expr, qself, path, shape) @@ -625,7 +625,7 @@ pub(crate) fn rewrite_cond( shape: Shape, ) -> Option<String> { match expr.kind { - ast::ExprKind::Match(ref cond, _) => { + ast::ExprKind::Match(ref cond, _, MatchKind::Prefix) => { // `match `cond` {` let cond_shape = match context.config.indent_style() { IndentStyle::Visual => shape.shrink_left(6).and_then(|s| s.sub_width(2))?, diff --git a/src/tools/rustfmt/src/matches.rs b/src/tools/rustfmt/src/matches.rs index 5a00984d4c0..e68903c8715 100644 --- a/src/tools/rustfmt/src/matches.rs +++ b/src/tools/rustfmt/src/matches.rs @@ -2,7 +2,7 @@ use std::iter::repeat; -use rustc_ast::{ast, ptr}; +use rustc_ast::{ast, ptr, MatchKind}; use rustc_span::{BytePos, Span}; use crate::comment::{combine_strs_with_missing_comments, rewrite_comment}; @@ -72,6 +72,7 @@ pub(crate) fn rewrite_match( shape: Shape, span: Span, attrs: &[ast::Attribute], + match_kind: MatchKind, ) -> Option<String> { // Do not take the rhs overhead from the upper expressions into account // when rewriting match condition. @@ -131,15 +132,27 @@ pub(crate) fn rewrite_match( } } else { let span_after_cond = mk_sp(cond.span.hi(), span.hi()); - Some(format!( - "match {}{}{{\n{}{}{}\n{}}}", - cond_str, - block_sep, - inner_attrs_str, - nested_indent_str, - rewrite_match_arms(context, arms, shape, span_after_cond, open_brace_pos)?, - shape.indent.to_string(context.config), - )) + + match match_kind { + MatchKind::Prefix => Some(format!( + "match {}{}{{\n{}{}{}\n{}}}", + cond_str, + block_sep, + inner_attrs_str, + nested_indent_str, + rewrite_match_arms(context, arms, shape, span_after_cond, open_brace_pos)?, + shape.indent.to_string(context.config), + )), + MatchKind::Postfix => Some(format!( + "{}.match{}{{\n{}{}{}\n{}}}", + cond_str, + block_sep, + inner_attrs_str, + nested_indent_str, + rewrite_match_arms(context, arms, shape, span_after_cond, open_brace_pos)?, + shape.indent.to_string(context.config), + )), + } } } diff --git a/src/tools/rustfmt/src/patterns.rs b/src/tools/rustfmt/src/patterns.rs index 7f576279432..47b48468a24 100644 --- a/src/tools/rustfmt/src/patterns.rs +++ b/src/tools/rustfmt/src/patterns.rs @@ -55,9 +55,10 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool { ast::PatKind::TupleStruct(_, ref path, ref subpats) => { path.segments.len() <= 1 && subpats.len() <= 1 } - ast::PatKind::Box(ref p) | ast::PatKind::Ref(ref p, _) | ast::PatKind::Paren(ref p) => { - is_short_pattern_inner(&*p) - } + ast::PatKind::Box(ref p) + | PatKind::Deref(ref p) + | ast::PatKind::Ref(ref p, _) + | ast::PatKind::Paren(ref p) => is_short_pattern_inner(&*p), PatKind::Or(ref pats) => pats.iter().all(|p| is_short_pattern_inner(p)), } } @@ -277,6 +278,7 @@ impl Rewrite for Pat { .rewrite(context, shape.offset_left(1)?.sub_width(1)?) .map(|inner_pat| format!("({})", inner_pat)), PatKind::Err(_) => None, + PatKind::Deref(_) => None, } } } diff --git a/src/tools/rustfmt/src/source_file.rs b/src/tools/rustfmt/src/source_file.rs index 6376bc49b69..2b43ec94b6b 100644 --- a/src/tools/rustfmt/src/source_file.rs +++ b/src/tools/rustfmt/src/source_file.rs @@ -66,7 +66,7 @@ where } } - #[cfg_attr(not(bootstrap), allow(non_local_definitions))] + #[allow(non_local_definitions)] impl From<&FileName> for rustc_span::FileName { fn from(filename: &FileName) -> rustc_span::FileName { match filename { diff --git a/src/tools/rustfmt/tests/source/postfix-match/pf-match.rs b/src/tools/rustfmt/tests/source/postfix-match/pf-match.rs new file mode 100644 index 00000000000..b2366723631 --- /dev/null +++ b/src/tools/rustfmt/tests/source/postfix-match/pf-match.rs @@ -0,0 +1,20 @@ +#![feature(postfix_match)] + +fn main() { + let val = Some(42); + + val.match { + Some(_) => 2, + _ => 1 + }; + + Some(2).match { + Some(_) => true, + None => false + }.match { + false => "ferris is cute", + true => "I turn cats in to petted cats", + }.match { + _ => (), + } +} \ No newline at end of file diff --git a/src/tools/rustfmt/tests/target/postfix-match/pf-match.rs b/src/tools/rustfmt/tests/target/postfix-match/pf-match.rs new file mode 100644 index 00000000000..f439f272623 --- /dev/null +++ b/src/tools/rustfmt/tests/target/postfix-match/pf-match.rs @@ -0,0 +1,20 @@ +#![feature(postfix_match)] + +fn main() { + let val = Some(42); + + val.match { + Some(_) => 2, + _ => 1, + }; + + Some(2).match { + Some(_) => true, + None => false, + }.match { + false => "ferris is cute", + true => "I turn cats in to petted cats", + }.match { + _ => (), + } +} diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 0ef962c2df8..f6b1d45ee94 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -968,8 +968,6 @@ "ui/errors/issue-89280-emitter-overflow-splice-lines.rs", "ui/errors/issue-99572-impl-trait-on-pointer.rs", "ui/expr/if/issue-4201.rs", -"ui/extenv/issue-110547.rs", -"ui/extenv/issue-55897.rs", "ui/extern/auxiliary/issue-80074-macro-2.rs", "ui/extern/auxiliary/issue-80074-macro.rs", "ui/extern/issue-10025.rs", @@ -1206,7 +1204,6 @@ "ui/impl-trait/issue-56445.rs", "ui/impl-trait/issue-68532.rs", "ui/impl-trait/issue-72911.rs", -"ui/impl-trait/issue-86465.rs", "ui/impl-trait/issue-87450.rs", "ui/impl-trait/issue-99073-2.rs", "ui/impl-trait/issue-99073.rs", @@ -3465,7 +3462,6 @@ "ui/pattern/issue-106552.rs", "ui/pattern/issue-106862.rs", "ui/pattern/issue-110508.rs", -"ui/pattern/issue-114896.rs", "ui/pattern/issue-115599.rs", "ui/pattern/issue-11577.rs", "ui/pattern/issue-117626.rs", diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index c946554b98f..fa24447f699 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -18,7 +18,7 @@ const ENTRY_LIMIT: usize = 900; // FIXME: The following limits should be reduced eventually. const ISSUES_ENTRY_LIMIT: usize = 1750; -const ROOT_ENTRY_LIMIT: usize = 866; +const ROOT_ENTRY_LIMIT: usize = 859; const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[ "rs", // test source files @@ -183,9 +183,10 @@ pub fn check(root_path: &Path, bless: bool, bad: &mut bool) { } }); - // if an excluded file is renamed, it must be removed from this list + // if there are any file names remaining, they were moved on the fs. + // our data must remain up to date, so it must be removed from issues.txt // do this automatically on bless, otherwise issue a tidy error - if bless { + if bless && !remaining_issue_names.is_empty() { let issues_txt_header = r#" /* ============================================================ diff --git a/src/version b/src/version index 54227249d1f..b3a8c61e6a8 100644 --- a/src/version +++ b/src/version @@ -1 +1 @@ -1.78.0 +1.79.0 diff --git a/tests/assembly/option-nonzero-eq.rs b/tests/assembly/option-nonzero-eq.rs deleted file mode 100644 index b04cf63fd78..00000000000 --- a/tests/assembly/option-nonzero-eq.rs +++ /dev/null @@ -1,27 +0,0 @@ -//@ revisions: WIN LIN -//@ [WIN] only-windows -//@ [LIN] only-linux -//@ assembly-output: emit-asm -//@ compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel -//@ only-x86_64 -//@ ignore-sgx - -use std::cmp::Ordering; - -// CHECK-lABEL: ordering_eq: -#[no_mangle] -pub fn ordering_eq(l: Option<Ordering>, r: Option<Ordering>) -> bool { - // Linux (System V): first two arguments are rdi then rsi - // Windows: first two arguments are rcx then rdx - // Both use rax for the return value. - - // CHECK-NOT: mov - // CHECK-NOT: test - // CHECK-NOT: cmp - - // LIN: cmp dil, sil - // WIN: cmp cl, dl - // CHECK-NEXT: sete al - // CHECK-NEXT: ret - l == r -} diff --git a/tests/assembly/targets/targets-elf.rs b/tests/assembly/targets/targets-elf.rs index bda77b5f09b..3563aec6d80 100644 --- a/tests/assembly/targets/targets-elf.rs +++ b/tests/assembly/targets/targets-elf.rs @@ -369,6 +369,9 @@ //@ revisions: riscv32im_unknown_none_elf //@ [riscv32im_unknown_none_elf] compile-flags: --target riscv32im-unknown-none-elf //@ [riscv32im_unknown_none_elf] needs-llvm-components: riscv +//@ revisions: riscv32ima_unknown_none_elf +//@ [riscv32ima_unknown_none_elf] compile-flags: --target riscv32ima-unknown-none-elf +//@ [riscv32ima_unknown_none_elf] needs-llvm-components: riscv //@ revisions: riscv32imac_esp_espidf //@ [riscv32imac_esp_espidf] compile-flags: --target riscv32imac-esp-espidf //@ [riscv32imac_esp_espidf] needs-llvm-components: riscv diff --git a/tests/codegen/dont_codegen_private_const_fn_only_used_in_const_eval.rs b/tests/codegen/dont_codegen_private_const_fn_only_used_in_const_eval.rs new file mode 100644 index 00000000000..eeeaebe52dd --- /dev/null +++ b/tests/codegen/dont_codegen_private_const_fn_only_used_in_const_eval.rs @@ -0,0 +1,10 @@ +//! This test checks that we do not monomorphize functions that are only +//! used to evaluate static items, but never used in runtime code. + +//@compile-flags: --crate-type=lib -Copt-level=0 + +const fn foo() {} + +pub static FOO: () = foo(); + +// CHECK-NOT: define{{.*}}foo{{.*}} diff --git a/tests/codegen/issues/issue-114312.rs b/tests/codegen/issues/issue-114312.rs index 54fa40dcf0d..be5b999afd0 100644 --- a/tests/codegen/issues/issue-114312.rs +++ b/tests/codegen/issues/issue-114312.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ min-llvm-version: 17 //@ only-x86_64-unknown-linux-gnu // We want to check that this function does not mis-optimize to loop jumping. diff --git a/tests/codegen/move-before-nocapture-ref-arg.rs b/tests/codegen/move-before-nocapture-ref-arg.rs index a530bc26672..c3448192ea1 100644 --- a/tests/codegen/move-before-nocapture-ref-arg.rs +++ b/tests/codegen/move-before-nocapture-ref-arg.rs @@ -1,7 +1,6 @@ // Verify that move before the call of the function with noalias, nocapture, readonly. // #107436 //@ compile-flags: -O -//@ min-llvm-version: 17 #![crate_type = "lib"] diff --git a/tests/codegen/option-as-slice.rs b/tests/codegen/option-as-slice.rs index 14a39243607..c5b1eafaccb 100644 --- a/tests/codegen/option-as-slice.rs +++ b/tests/codegen/option-as-slice.rs @@ -1,7 +1,5 @@ //@ compile-flags: -O -Z randomize-layout=no //@ only-x86_64 -//@ ignore-llvm-version: 16.0.0 -// ^-- needs https://reviews.llvm.org/D146149 in 16.0.1 #![crate_type = "lib"] #![feature(generic_nonzero)] diff --git a/tests/codegen/option-nonzero-eq.rs b/tests/codegen/option-niche-eq.rs index f637b1aef97..8b8044e9b75 100644 --- a/tests/codegen/option-nonzero-eq.rs +++ b/tests/codegen/option-niche-eq.rs @@ -1,4 +1,5 @@ //@ compile-flags: -O -Zmerge-functions=disabled +//@ min-llvm-version: 18 #![crate_type = "lib"] #![feature(generic_nonzero)] @@ -7,9 +8,6 @@ use core::cmp::Ordering; use core::ptr::NonNull; use core::num::NonZero; -// See also tests/assembly/option-nonzero-eq.rs, for cases with `assume`s in the -// LLVM and thus don't optimize down clearly here, but do in assembly. - // CHECK-lABEL: @non_zero_eq #[no_mangle] pub fn non_zero_eq(l: Option<NonZero<u32>>, r: Option<NonZero<u32>>) -> bool { @@ -36,3 +34,42 @@ pub fn non_null_eq(l: Option<NonNull<u8>>, r: Option<NonNull<u8>>) -> bool { // CHECK-NEXT: ret i1 l == r } + +// CHECK-lABEL: @ordering_eq +#[no_mangle] +pub fn ordering_eq(l: Option<Ordering>, r: Option<Ordering>) -> bool { + // CHECK: start: + // CHECK-NEXT: icmp eq i8 + // CHECK-NEXT: ret i1 + l == r +} + +#[derive(PartialEq)] +pub enum EnumWithNiche { + A, + B, + C, + D, + E, + F, + G, +} + +// CHECK-lABEL: @niche_eq +#[no_mangle] +pub fn niche_eq(l: Option<EnumWithNiche>, r: Option<EnumWithNiche>) -> bool { + // CHECK: start: + // CHECK-NEXT: icmp eq i8 + // CHECK-NEXT: ret i1 + l == r +} + +// FIXME: This should work too +// // FIXME-CHECK-lABEL: @bool_eq +// #[no_mangle] +// pub fn bool_eq(l: Option<bool>, r: Option<bool>) -> bool { +// // FIXME-CHECK: start: +// // FIXME-CHECK-NEXT: icmp eq i8 +// // FIXME-CHECK-NEXT: ret i1 +// l == r +// } diff --git a/tests/codegen/sanitizer/cfi-emit-type-metadata-id-itanium-cxx-abi.rs b/tests/codegen/sanitizer/cfi-emit-type-metadata-id-itanium-cxx-abi.rs deleted file mode 100644 index 5f49909712f..00000000000 --- a/tests/codegen/sanitizer/cfi-emit-type-metadata-id-itanium-cxx-abi.rs +++ /dev/null @@ -1,604 +0,0 @@ -// Verifies that type metadata identifiers for functions are emitted correctly. -// -//@ needs-sanitizer-cfi -//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Copt-level=0 - -#![crate_type="lib"] -#![allow(dead_code)] -#![allow(incomplete_features)] -#![allow(unused_must_use)] -#![feature(adt_const_params, extern_types, inline_const, type_alias_impl_trait)] - -extern crate core; -use core::ffi::*; -use std::marker::PhantomData; - -// User-defined type (structure) -pub struct Struct1<T> { - member1: T, -} - -// User-defined type (enum) -pub enum Enum1<T> { - Variant1(T), -} - -// User-defined type (union) -pub union Union1<T> { - member1: std::mem::ManuallyDrop<T>, -} - -// Extern type -extern { - pub type type1; -} - -// Trait -pub trait Trait1<T> { - fn foo(&self) { } -} - -// Trait implementation -impl<T> Trait1<T> for i32 { - fn foo(&self) { } -} - -// Trait implementation -impl<T, U> Trait1<T> for Struct1<U> { - fn foo(&self) { } -} - -// impl Trait type aliases for helping with defining other types (see below) -pub type Type1 = impl Send; -pub type Type2 = impl Send; -pub type Type3 = impl Send; -pub type Type4 = impl Send; -pub type Type5 = impl Send; -pub type Type6 = impl Send; -pub type Type7 = impl Send; -pub type Type8 = impl Send; -pub type Type9 = impl Send; -pub type Type10 = impl Send; -pub type Type11 = impl Send; - -pub fn fn1<'a>() where - Type1: 'static, - Type2: 'static, - Type3: 'static, - Type4: 'static, - Type5: 'static, - Type6: 'static, - Type7: 'static, - Type8: 'static, - Type9: 'static, - Type10: 'static, - Type11: 'static, -{ - // Closure - let closure1 = || { }; - let _: Type1 = closure1; - - // Constructor - pub struct Foo(i32); - let _: Type2 = Foo; - - // Type in extern path - extern { - fn foo(); - } - let _: Type3 = foo; - - // Type in closure path - || { - pub struct Foo; - let _: Type4 = Foo; - }; - - // Type in const path - const { - pub struct Foo; - fn foo() -> Type5 { Foo } - }; - - // Type in impl path - impl<T> Struct1<T> { - fn foo(&self) { } - } - let _: Type6 = <Struct1<i32>>::foo; - - // Trait method - let _: Type7 = <dyn Trait1<i32>>::foo; - - // Trait method - let _: Type8 = <i32 as Trait1<i32>>::foo; - - // Trait method - let _: Type9 = <Struct1<i32> as Trait1<i32>>::foo; - - // Const generics - pub struct Qux<T, const N: usize>([T; N]); - let _: Type10 = Qux([0; 32]); - - // Lifetimes/regions - pub struct Quux<'a>(&'a i32); - pub struct Quuux<'a, 'b>(&'a i32, &'b Quux<'b>); - let _: Type11 = Quuux; -} - -// Helper type to make Type12 have an unique id -struct Foo(i32); - -// repr(transparent) user-defined type -#[repr(transparent)] -pub struct Type12 { - member1: (), - member2: PhantomData<i32>, - member3: Foo, -} - -// Self-referencing repr(transparent) user-defined type -#[repr(transparent)] -pub struct Type13<'a> { - member1: (), - member2: PhantomData<i32>, - member3: &'a Type13<'a>, -} - -// Helper type to make Type14 have an unique id -pub struct Bar; - -// repr(transparent) user-defined generic type -#[repr(transparent)] -pub struct Type14<T>(T); - -pub fn foo0(_: ()) { } -// CHECK: define{{.*}}foo0{{.*}}!type ![[TYPE0:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo1(_: (), _: c_void) { } -// CHECK: define{{.*}}foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo2(_: (), _: c_void, _: c_void) { } -// CHECK: define{{.*}}foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo3(_: *mut ()) { } -// CHECK: define{{.*}}foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo4(_: *mut (), _: *mut c_void) { } -// CHECK: define{{.*}}foo4{{.*}}!type ![[TYPE4:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo5(_: *mut (), _: *mut c_void, _: *mut c_void) { } -// CHECK: define{{.*}}foo5{{.*}}!type ![[TYPE5:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo6(_: *const ()) { } -// CHECK: define{{.*}}foo6{{.*}}!type ![[TYPE6:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo7(_: *const (), _: *const c_void) { } -// CHECK: define{{.*}}foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo8(_: *const (), _: *const c_void, _: *const c_void) { } -// CHECK: define{{.*}}foo8{{.*}}!type ![[TYPE8:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo9(_: bool) { } -// CHECK: define{{.*}}foo9{{.*}}!type ![[TYPE9:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo10(_: bool, _: bool) { } -// CHECK: define{{.*}}foo10{{.*}}!type ![[TYPE10:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo11(_: bool, _: bool, _: bool) { } -// CHECK: define{{.*}}foo11{{.*}}!type ![[TYPE11:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo12(_: i8) { } -// CHECK: define{{.*}}foo12{{.*}}!type ![[TYPE12:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo13(_: i8, _: i8) { } -// CHECK: define{{.*}}foo13{{.*}}!type ![[TYPE13:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo14(_: i8, _: i8, _: i8) { } -// CHECK: define{{.*}}foo14{{.*}}!type ![[TYPE14:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo15(_: i16) { } -// CHECK: define{{.*}}foo15{{.*}}!type ![[TYPE15:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo16(_: i16, _: i16) { } -// CHECK: define{{.*}}foo16{{.*}}!type ![[TYPE16:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo17(_: i16, _: i16, _: i16) { } -// CHECK: define{{.*}}foo17{{.*}}!type ![[TYPE17:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo18(_: i32) { } -// CHECK: define{{.*}}foo18{{.*}}!type ![[TYPE18:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo19(_: i32, _: i32) { } -// CHECK: define{{.*}}foo19{{.*}}!type ![[TYPE19:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo20(_: i32, _: i32, _: i32) { } -// CHECK: define{{.*}}foo20{{.*}}!type ![[TYPE20:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo21(_: i64) { } -// CHECK: define{{.*}}foo21{{.*}}!type ![[TYPE21:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo22(_: i64, _: i64) { } -// CHECK: define{{.*}}foo22{{.*}}!type ![[TYPE22:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo23(_: i64, _: i64, _: i64) { } -// CHECK: define{{.*}}foo23{{.*}}!type ![[TYPE23:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo24(_: i128) { } -// CHECK: define{{.*}}foo24{{.*}}!type ![[TYPE24:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo25(_: i128, _: i128) { } -// CHECK: define{{.*}}foo25{{.*}}!type ![[TYPE25:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo26(_: i128, _: i128, _: i128) { } -// CHECK: define{{.*}}foo26{{.*}}!type ![[TYPE26:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo27(_: isize) { } -// CHECK: define{{.*}}foo27{{.*}}!type ![[TYPE27:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo28(_: isize, _: isize) { } -// CHECK: define{{.*}}foo28{{.*}}!type ![[TYPE28:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo29(_: isize, _: isize, _: isize) { } -// CHECK: define{{.*}}foo29{{.*}}!type ![[TYPE29:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo30(_: u8) { } -// CHECK: define{{.*}}foo30{{.*}}!type ![[TYPE30:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo31(_: u8, _: u8) { } -// CHECK: define{{.*}}foo31{{.*}}!type ![[TYPE31:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo32(_: u8, _: u8, _: u8) { } -// CHECK: define{{.*}}foo32{{.*}}!type ![[TYPE32:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo33(_: u16) { } -// CHECK: define{{.*}}foo33{{.*}}!type ![[TYPE33:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo34(_: u16, _: u16) { } -// CHECK: define{{.*}}foo34{{.*}}!type ![[TYPE34:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo35(_: u16, _: u16, _: u16) { } -// CHECK: define{{.*}}foo35{{.*}}!type ![[TYPE35:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo36(_: u32) { } -// CHECK: define{{.*}}foo36{{.*}}!type ![[TYPE36:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo37(_: u32, _: u32) { } -// CHECK: define{{.*}}foo37{{.*}}!type ![[TYPE37:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo38(_: u32, _: u32, _: u32) { } -// CHECK: define{{.*}}foo38{{.*}}!type ![[TYPE38:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo39(_: u64) { } -// CHECK: define{{.*}}foo39{{.*}}!type ![[TYPE39:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo40(_: u64, _: u64) { } -// CHECK: define{{.*}}foo40{{.*}}!type ![[TYPE40:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo41(_: u64, _: u64, _: u64) { } -// CHECK: define{{.*}}foo41{{.*}}!type ![[TYPE41:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo42(_: u128) { } -// CHECK: define{{.*}}foo42{{.*}}!type ![[TYPE42:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo43(_: u128, _: u128) { } -// CHECK: define{{.*}}foo43{{.*}}!type ![[TYPE43:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo44(_: u128, _: u128, _: u128) { } -// CHECK: define{{.*}}foo44{{.*}}!type ![[TYPE44:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo45(_: usize) { } -// CHECK: define{{.*}}foo45{{.*}}!type ![[TYPE45:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo46(_: usize, _: usize) { } -// CHECK: define{{.*}}foo46{{.*}}!type ![[TYPE46:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo47(_: usize, _: usize, _: usize) { } -// CHECK: define{{.*}}foo47{{.*}}!type ![[TYPE47:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo48(_: f32) { } -// CHECK: define{{.*}}foo48{{.*}}!type ![[TYPE48:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo49(_: f32, _: f32) { } -// CHECK: define{{.*}}foo49{{.*}}!type ![[TYPE49:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo50(_: f32, _: f32, _: f32) { } -// CHECK: define{{.*}}foo50{{.*}}!type ![[TYPE50:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo51(_: f64) { } -// CHECK: define{{.*}}foo51{{.*}}!type ![[TYPE51:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo52(_: f64, _: f64) { } -// CHECK: define{{.*}}foo52{{.*}}!type ![[TYPE52:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo53(_: f64, _: f64, _: f64) { } -// CHECK: define{{.*}}foo53{{.*}}!type ![[TYPE53:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo54(_: char) { } -// CHECK: define{{.*}}foo54{{.*}}!type ![[TYPE54:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo55(_: char, _: char) { } -// CHECK: define{{.*}}foo55{{.*}}!type ![[TYPE55:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo56(_: char, _: char, _: char) { } -// CHECK: define{{.*}}foo56{{.*}}!type ![[TYPE56:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo57(_: &str) { } -// CHECK: define{{.*}}foo57{{.*}}!type ![[TYPE57:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo58(_: &str, _: &str) { } -// CHECK: define{{.*}}foo58{{.*}}!type ![[TYPE58:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo59(_: &str, _: &str, _: &str) { } -// CHECK: define{{.*}}foo59{{.*}}!type ![[TYPE59:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo60(_: (i32, i32)) { } -// CHECK: define{{.*}}foo60{{.*}}!type ![[TYPE60:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo61(_: (i32, i32), _: (i32, i32)) { } -// CHECK: define{{.*}}foo61{{.*}}!type ![[TYPE61:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo62(_: (i32, i32), _: (i32, i32), _: (i32, i32)) { } -// CHECK: define{{.*}}foo62{{.*}}!type ![[TYPE62:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo63(_: [i32; 32]) { } -// CHECK: define{{.*}}foo63{{.*}}!type ![[TYPE63:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo64(_: [i32; 32], _: [i32; 32]) { } -// CHECK: define{{.*}}foo64{{.*}}!type ![[TYPE64:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo65(_: [i32; 32], _: [i32; 32], _: [i32; 32]) { } -// CHECK: define{{.*}}foo65{{.*}}!type ![[TYPE65:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo66(_: &[i32]) { } -// CHECK: define{{.*}}foo66{{.*}}!type ![[TYPE66:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo67(_: &[i32], _: &[i32]) { } -// CHECK: define{{.*}}foo67{{.*}}!type ![[TYPE67:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo68(_: &[i32], _: &[i32], _: &[i32]) { } -// CHECK: define{{.*}}foo68{{.*}}!type ![[TYPE68:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo69(_: &Struct1::<i32>) { } -// CHECK: define{{.*}}foo69{{.*}}!type ![[TYPE69:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo70(_: &Struct1::<i32>, _: &Struct1::<i32>) { } -// CHECK: define{{.*}}foo70{{.*}}!type ![[TYPE70:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo71(_: &Struct1::<i32>, _: &Struct1::<i32>, _: &Struct1::<i32>) { } -// CHECK: define{{.*}}foo71{{.*}}!type ![[TYPE71:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo72(_: &Enum1::<i32>) { } -// CHECK: define{{.*}}foo72{{.*}}!type ![[TYPE72:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo73(_: &Enum1::<i32>, _: &Enum1::<i32>) { } -// CHECK: define{{.*}}foo73{{.*}}!type ![[TYPE73:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo74(_: &Enum1::<i32>, _: &Enum1::<i32>, _: &Enum1::<i32>) { } -// CHECK: define{{.*}}foo74{{.*}}!type ![[TYPE74:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo75(_: &Union1::<i32>) { } -// CHECK: define{{.*}}foo75{{.*}}!type ![[TYPE75:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo76(_: &Union1::<i32>, _: &Union1::<i32>) { } -// CHECK: define{{.*}}foo76{{.*}}!type ![[TYPE76:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo77(_: &Union1::<i32>, _: &Union1::<i32>, _: &Union1::<i32>) { } -// CHECK: define{{.*}}foo77{{.*}}!type ![[TYPE77:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo78(_: *mut type1) { } -// CHECK: define{{.*}}foo78{{.*}}!type ![[TYPE78:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo79(_: *mut type1, _: *mut type1) { } -// CHECK: define{{.*}}foo79{{.*}}!type ![[TYPE79:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo80(_: *mut type1, _: *mut type1, _: *mut type1) { } -// CHECK: define{{.*}}foo80{{.*}}!type ![[TYPE80:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo81(_: &mut i32) { } -// CHECK: define{{.*}}foo81{{.*}}!type ![[TYPE81:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo82(_: &mut i32, _: &i32) { } -// CHECK: define{{.*}}foo82{{.*}}!type ![[TYPE82:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo83(_: &mut i32, _: &i32, _: &i32) { } -// CHECK: define{{.*}}foo83{{.*}}!type ![[TYPE83:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo84(_: &i32) { } -// CHECK: define{{.*}}foo84{{.*}}!type ![[TYPE84:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo85(_: &i32, _: &mut i32) { } -// CHECK: define{{.*}}foo85{{.*}}!type ![[TYPE85:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo86(_: &i32, _: &mut i32, _: &mut i32) { } -// CHECK: define{{.*}}foo86{{.*}}!type ![[TYPE86:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo87(_: *mut i32) { } -// CHECK: define{{.*}}foo87{{.*}}!type ![[TYPE87:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo88(_: *mut i32, _: *const i32) { } -// CHECK: define{{.*}}foo88{{.*}}!type ![[TYPE88:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo89(_: *mut i32, _: *const i32, _: *const i32) { } -// CHECK: define{{.*}}foo89{{.*}}!type ![[TYPE89:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo90(_: *const i32) { } -// CHECK: define{{.*}}foo90{{.*}}!type ![[TYPE90:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo91(_: *const i32, _: *mut i32) { } -// CHECK: define{{.*}}foo91{{.*}}!type ![[TYPE91:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo92(_: *const i32, _: *mut i32, _: *mut i32) { } -// CHECK: define{{.*}}foo92{{.*}}!type ![[TYPE92:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo93(_: fn(i32) -> i32) { } -// CHECK: define{{.*}}foo93{{.*}}!type ![[TYPE93:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo94(_: fn(i32) -> i32, _: fn(i32) -> i32) { } -// CHECK: define{{.*}}foo94{{.*}}!type ![[TYPE94:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo95(_: fn(i32) -> i32, _: fn(i32) -> i32, _: fn(i32) -> i32) { } -// CHECK: define{{.*}}foo95{{.*}}!type ![[TYPE95:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo96(_: &dyn Fn(i32) -> i32) { } -// CHECK: define{{.*}}foo96{{.*}}!type ![[TYPE96:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo97(_: &dyn Fn(i32) -> i32, _: &dyn Fn(i32) -> i32) { } -// CHECK: define{{.*}}foo97{{.*}}!type ![[TYPE97:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo98(_: &dyn Fn(i32) -> i32, _: &dyn Fn(i32) -> i32, _: &dyn Fn(i32) -> i32) { } -// CHECK: define{{.*}}foo98{{.*}}!type ![[TYPE98:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo99(_: &dyn FnMut(i32) -> i32) { } -// CHECK: define{{.*}}foo99{{.*}}!type ![[TYPE99:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo100(_: &dyn FnMut(i32) -> i32, _: &dyn FnMut(i32) -> i32) { } -// CHECK: define{{.*}}foo100{{.*}}!type ![[TYPE100:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo101(_: &dyn FnMut(i32) -> i32, _: &dyn FnMut(i32) -> i32, _: &dyn FnMut(i32) -> i32) { } -// CHECK: define{{.*}}foo101{{.*}}!type ![[TYPE101:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo102(_: &dyn FnOnce(i32) -> i32) { } -// CHECK: define{{.*}}foo102{{.*}}!type ![[TYPE102:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo103(_: &dyn FnOnce(i32) -> i32, _: &dyn FnOnce(i32) -> i32) { } -// CHECK: define{{.*}}foo103{{.*}}!type ![[TYPE103:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo104(_: &dyn FnOnce(i32) -> i32, _: &dyn FnOnce(i32) -> i32, _: &dyn FnOnce(i32) -> i32) {} -// CHECK: define{{.*}}foo104{{.*}}!type ![[TYPE104:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo105(_: &dyn Send) { } -// CHECK: define{{.*}}foo105{{.*}}!type ![[TYPE105:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo106(_: &dyn Send, _: &dyn Send) { } -// CHECK: define{{.*}}foo106{{.*}}!type ![[TYPE106:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo107(_: &dyn Send, _: &dyn Send, _: &dyn Send) { } -// CHECK: define{{.*}}foo107{{.*}}!type ![[TYPE107:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo108(_: Type1) { } -// CHECK: define{{.*}}foo108{{.*}}!type ![[TYPE108:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo109(_: Type1, _: Type1) { } -// CHECK: define{{.*}}foo109{{.*}}!type ![[TYPE109:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo110(_: Type1, _: Type1, _: Type1) { } -// CHECK: define{{.*}}foo110{{.*}}!type ![[TYPE110:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo111(_: Type2) { } -// CHECK: define{{.*}}foo111{{.*}}!type ![[TYPE111:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo112(_: Type2, _: Type2) { } -// CHECK: define{{.*}}foo112{{.*}}!type ![[TYPE112:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo113(_: Type2, _: Type2, _: Type2) { } -// CHECK: define{{.*}}foo113{{.*}}!type ![[TYPE113:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo114(_: Type3) { } -// CHECK: define{{.*}}foo114{{.*}}!type ![[TYPE114:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo115(_: Type3, _: Type3) { } -// CHECK: define{{.*}}foo115{{.*}}!type ![[TYPE115:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo116(_: Type3, _: Type3, _: Type3) { } -// CHECK: define{{.*}}foo116{{.*}}!type ![[TYPE116:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo117(_: Type4) { } -// CHECK: define{{.*}}foo117{{.*}}!type ![[TYPE117:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo118(_: Type4, _: Type4) { } -// CHECK: define{{.*}}foo118{{.*}}!type ![[TYPE118:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo119(_: Type4, _: Type4, _: Type4) { } -// CHECK: define{{.*}}foo119{{.*}}!type ![[TYPE119:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo120(_: Type5) { } -// CHECK: define{{.*}}foo120{{.*}}!type ![[TYPE120:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo121(_: Type5, _: Type5) { } -// CHECK: define{{.*}}foo121{{.*}}!type ![[TYPE121:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo122(_: Type5, _: Type5, _: Type5) { } -// CHECK: define{{.*}}foo122{{.*}}!type ![[TYPE122:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo123(_: Type6) { } -// CHECK: define{{.*}}foo123{{.*}}!type ![[TYPE123:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo124(_: Type6, _: Type6) { } -// CHECK: define{{.*}}foo124{{.*}}!type ![[TYPE124:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo125(_: Type6, _: Type6, _: Type6) { } -// CHECK: define{{.*}}foo125{{.*}}!type ![[TYPE125:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo126(_: Type7) { } -// CHECK: define{{.*}}foo126{{.*}}!type ![[TYPE126:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo127(_: Type7, _: Type7) { } -// CHECK: define{{.*}}foo127{{.*}}!type ![[TYPE127:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo128(_: Type7, _: Type7, _: Type7) { } -// CHECK: define{{.*}}foo128{{.*}}!type ![[TYPE128:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo129(_: Type8) { } -// CHECK: define{{.*}}foo129{{.*}}!type ![[TYPE129:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo130(_: Type8, _: Type8) { } -// CHECK: define{{.*}}foo130{{.*}}!type ![[TYPE130:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo131(_: Type8, _: Type8, _: Type8) { } -// CHECK: define{{.*}}foo131{{.*}}!type ![[TYPE131:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo132(_: Type9) { } -// CHECK: define{{.*}}foo132{{.*}}!type ![[TYPE132:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo133(_: Type9, _: Type9) { } -// CHECK: define{{.*}}foo133{{.*}}!type ![[TYPE133:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo134(_: Type9, _: Type9, _: Type9) { } -// CHECK: define{{.*}}foo134{{.*}}!type ![[TYPE134:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo135(_: Type10) { } -// CHECK: define{{.*}}foo135{{.*}}!type ![[TYPE135:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo136(_: Type10, _: Type10) { } -// CHECK: define{{.*}}foo136{{.*}}!type ![[TYPE136:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo137(_: Type10, _: Type10, _: Type10) { } -// CHECK: define{{.*}}foo137{{.*}}!type ![[TYPE137:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo138(_: Type11) { } -// CHECK: define{{.*}}foo138{{.*}}!type ![[TYPE138:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo139(_: Type11, _: Type11) { } -// CHECK: define{{.*}}foo139{{.*}}!type ![[TYPE139:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo140(_: Type11, _: Type11, _: Type11) { } -// CHECK: define{{.*}}foo140{{.*}}!type ![[TYPE140:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo141(_: Type12) { } -// CHECK: define{{.*}}foo141{{.*}}!type ![[TYPE141:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo142(_: Type12, _: Type12) { } -// CHECK: define{{.*}}foo142{{.*}}!type ![[TYPE142:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo143(_: Type12, _: Type12, _: Type12) { } -// CHECK: define{{.*}}foo143{{.*}}!type ![[TYPE143:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo144(_: Type13) { } -// CHECK: define{{.*}}foo144{{.*}}!type ![[TYPE144:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo145(_: Type13, _: Type13) { } -// CHECK: define{{.*}}foo145{{.*}}!type ![[TYPE145:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo146(_: Type13, _: Type13, _: Type13) { } -// CHECK: define{{.*}}foo146{{.*}}!type ![[TYPE146:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo147(_: Type14<Bar>) { } -// CHECK: define{{.*}}foo147{{.*}}!type ![[TYPE147:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo148(_: Type14<Bar>, _: Type14<Bar>) { } -// CHECK: define{{.*}}foo148{{.*}}!type ![[TYPE148:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} -pub fn foo149(_: Type14<Bar>, _: Type14<Bar>, _: Type14<Bar>) { } -// CHECK: define{{.*}}foo149{{.*}}!type ![[TYPE149:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} - -// CHECK: ![[TYPE0]] = !{i64 0, !"_ZTSFvvE"} -// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvvvE"} -// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvvvvE"} -// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvPvE"} -// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvPvS_E"} -// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvPvS_S_E"} -// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvPKvE"} -// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvPKvS0_E"} -// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvPKvS0_S0_E"} -// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvbE"} -// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvbbE"} -// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvbbbE"} -// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvu2i8E"} -// CHECK: ![[TYPE13]] = !{i64 0, !"_ZTSFvu2i8S_E"} -// CHECK: ![[TYPE14]] = !{i64 0, !"_ZTSFvu2i8S_S_E"} -// CHECK: ![[TYPE15]] = !{i64 0, !"_ZTSFvu3i16E"} -// CHECK: ![[TYPE16]] = !{i64 0, !"_ZTSFvu3i16S_E"} -// CHECK: ![[TYPE17]] = !{i64 0, !"_ZTSFvu3i16S_S_E"} -// CHECK: ![[TYPE18]] = !{i64 0, !"_ZTSFvu3i32E"} -// CHECK: ![[TYPE19]] = !{i64 0, !"_ZTSFvu3i32S_E"} -// CHECK: ![[TYPE20]] = !{i64 0, !"_ZTSFvu3i32S_S_E"} -// CHECK: ![[TYPE21]] = !{i64 0, !"_ZTSFvu3i64E"} -// CHECK: ![[TYPE22]] = !{i64 0, !"_ZTSFvu3i64S_E"} -// CHECK: ![[TYPE23]] = !{i64 0, !"_ZTSFvu3i64S_S_E"} -// CHECK: ![[TYPE24]] = !{i64 0, !"_ZTSFvu4i128E"} -// CHECK: ![[TYPE25]] = !{i64 0, !"_ZTSFvu4i128S_E"} -// CHECK: ![[TYPE26]] = !{i64 0, !"_ZTSFvu4i128S_S_E"} -// CHECK: ![[TYPE27]] = !{i64 0, !"_ZTSFvu5isizeE"} -// CHECK: ![[TYPE28]] = !{i64 0, !"_ZTSFvu5isizeS_E"} -// CHECK: ![[TYPE29]] = !{i64 0, !"_ZTSFvu5isizeS_S_E"} -// CHECK: ![[TYPE30]] = !{i64 0, !"_ZTSFvu2u8E"} -// CHECK: ![[TYPE31]] = !{i64 0, !"_ZTSFvu2u8S_E"} -// CHECK: ![[TYPE32]] = !{i64 0, !"_ZTSFvu2u8S_S_E"} -// CHECK: ![[TYPE33]] = !{i64 0, !"_ZTSFvu3u16E"} -// CHECK: ![[TYPE34]] = !{i64 0, !"_ZTSFvu3u16S_E"} -// CHECK: ![[TYPE35]] = !{i64 0, !"_ZTSFvu3u16S_S_E"} -// CHECK: ![[TYPE36]] = !{i64 0, !"_ZTSFvu3u32E"} -// CHECK: ![[TYPE37]] = !{i64 0, !"_ZTSFvu3u32S_E"} -// CHECK: ![[TYPE38]] = !{i64 0, !"_ZTSFvu3u32S_S_E"} -// CHECK: ![[TYPE39]] = !{i64 0, !"_ZTSFvu3u64E"} -// CHECK: ![[TYPE40]] = !{i64 0, !"_ZTSFvu3u64S_E"} -// CHECK: ![[TYPE41]] = !{i64 0, !"_ZTSFvu3u64S_S_E"} -// CHECK: ![[TYPE42]] = !{i64 0, !"_ZTSFvu4u128E"} -// CHECK: ![[TYPE43]] = !{i64 0, !"_ZTSFvu4u128S_E"} -// CHECK: ![[TYPE44]] = !{i64 0, !"_ZTSFvu4u128S_S_E"} -// CHECK: ![[TYPE45]] = !{i64 0, !"_ZTSFvu5usizeE"} -// CHECK: ![[TYPE46]] = !{i64 0, !"_ZTSFvu5usizeS_E"} -// CHECK: ![[TYPE47]] = !{i64 0, !"_ZTSFvu5usizeS_S_E"} -// CHECK: ![[TYPE48]] = !{i64 0, !"_ZTSFvfE"} -// CHECK: ![[TYPE49]] = !{i64 0, !"_ZTSFvffE"} -// CHECK: ![[TYPE50]] = !{i64 0, !"_ZTSFvfffE"} -// CHECK: ![[TYPE51]] = !{i64 0, !"_ZTSFvdE"} -// CHECK: ![[TYPE52]] = !{i64 0, !"_ZTSFvddE"} -// CHECK: ![[TYPE53]] = !{i64 0, !"_ZTSFvdddE"} -// CHECK: ![[TYPE54]] = !{i64 0, !"_ZTSFvu4charE"} -// CHECK: ![[TYPE55]] = !{i64 0, !"_ZTSFvu4charS_E"} -// CHECK: ![[TYPE56]] = !{i64 0, !"_ZTSFvu4charS_S_E"} -// CHECK: ![[TYPE57]] = !{i64 0, !"_ZTSFvu3refIu3strEE"} -// CHECK: ![[TYPE58]] = !{i64 0, !"_ZTSFvu3refIu3strES0_E"} -// CHECK: ![[TYPE59]] = !{i64 0, !"_ZTSFvu3refIu3strES0_S0_E"} -// CHECK: ![[TYPE60]] = !{i64 0, !"_ZTSFvu5tupleIu3i32S_EE"} -// CHECK: ![[TYPE61]] = !{i64 0, !"_ZTSFvu5tupleIu3i32S_ES0_E"} -// CHECK: ![[TYPE62]] = !{i64 0, !"_ZTSFvu5tupleIu3i32S_ES0_S0_E"} -// CHECK: ![[TYPE63]] = !{i64 0, !"_ZTSFvA32u3i32E"} -// CHECK: ![[TYPE64]] = !{i64 0, !"_ZTSFvA32u3i32S0_E"} -// CHECK: ![[TYPE65]] = !{i64 0, !"_ZTSFvA32u3i32S0_S0_E"} -// CHECK: ![[TYPE66]] = !{i64 0, !"_ZTSFvu3refIu5sliceIu3i32EEE"} -// CHECK: ![[TYPE67]] = !{i64 0, !"_ZTSFvu3refIu5sliceIu3i32EES1_E"} -// CHECK: ![[TYPE68]] = !{i64 0, !"_ZTSFvu3refIu5sliceIu3i32EES1_S1_E"} -// CHECK: ![[TYPE69]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME:[0-9]{1,2}[a-z_]{1,99}]]7Struct1Iu3i32EEE"} -// CHECK: ![[TYPE70]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7Struct1Iu3i32EES1_E"} -// CHECK: ![[TYPE71]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7Struct1Iu3i32EES1_S1_E"} -// CHECK: ![[TYPE72]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]5Enum1Iu3i32EEE"} -// CHECK: ![[TYPE73]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]5Enum1Iu3i32EES1_E"} -// CHECK: ![[TYPE74]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]5Enum1Iu3i32EES1_S1_E"} -// CHECK: ![[TYPE75]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Union1Iu3i32EEE"} -// CHECK: ![[TYPE76]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Union1Iu3i32EES1_E"} -// CHECK: ![[TYPE77]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Union1Iu3i32EES1_S1_E"} -// CHECK: ![[TYPE78]] = !{i64 0, !"_ZTSFvP5type1E"} -// CHECK: ![[TYPE79]] = !{i64 0, !"_ZTSFvP5type1S0_E"} -// CHECK: ![[TYPE80]] = !{i64 0, !"_ZTSFvP5type1S0_S0_E"} -// CHECK: ![[TYPE81]] = !{i64 0, !"_ZTSFvU3mutu3refIu3i32EE"} -// CHECK: ![[TYPE82]] = !{i64 0, !"_ZTSFvU3mutu3refIu3i32ES0_E"} -// CHECK: ![[TYPE83]] = !{i64 0, !"_ZTSFvU3mutu3refIu3i32ES0_S0_E"} -// CHECK: ![[TYPE84]] = !{i64 0, !"_ZTSFvu3refIu3i32EE"} -// CHECK: ![[TYPE85]] = !{i64 0, !"_ZTSFvu3refIu3i32EU3mutS0_E"} -// CHECK: ![[TYPE86]] = !{i64 0, !"_ZTSFvu3refIu3i32EU3mutS0_S1_E"} -// CHECK: ![[TYPE87]] = !{i64 0, !"_ZTSFvPu3i32E"} -// CHECK: ![[TYPE88]] = !{i64 0, !"_ZTSFvPu3i32PKS_E"} -// CHECK: ![[TYPE89]] = !{i64 0, !"_ZTSFvPu3i32PKS_S2_E"} -// CHECK: ![[TYPE90]] = !{i64 0, !"_ZTSFvPKu3i32E"} -// CHECK: ![[TYPE91]] = !{i64 0, !"_ZTSFvPKu3i32PS_E"} -// CHECK: ![[TYPE92]] = !{i64 0, !"_ZTSFvPKu3i32PS_S2_E"} -// CHECK: ![[TYPE93]] = !{i64 0, !"_ZTSFvPFu3i32S_EE"} -// CHECK: ![[TYPE94]] = !{i64 0, !"_ZTSFvPFu3i32S_ES0_E"} -// CHECK: ![[TYPE95]] = !{i64 0, !"_ZTSFvPFu3i32S_ES0_S0_E"} -// CHECK: ![[TYPE96]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function2FnIu5paramEu6regionEEE"} -// CHECK: ![[TYPE97]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function2FnIu5paramEu6regionEES3_E"} -// CHECK: ![[TYPE98]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function2FnIu5paramEu6regionEES3_S3_E"} -// CHECK: ![[TYPE99]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function5FnMutIu5paramEu6regionEEE"} -// CHECK: ![[TYPE100]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function5FnMutIu5paramEu6regionEES3_E"} -// CHECK: ![[TYPE101]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function5FnMutIu5paramEu6regionEES3_S3_E"} -// CHECK: ![[TYPE102]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnceIu5paramEu6regionEEE"} -// CHECK: ![[TYPE103]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnceIu5paramEu6regionEES3_E"} -// CHECK: ![[TYPE104]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnceIu5paramEu6regionEES3_S3_E"} -// CHECK: ![[TYPE105]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEEE"} -// CHECK: ![[TYPE106]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEES2_E"} -// CHECK: ![[TYPE107]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEES2_S2_E"} -// CHECK: ![[TYPE108]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NCNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn111{{[{}][{}]}}closure{{[}][}]}}Iu2i8PFvvEvEE"} -// CHECK: ![[TYPE109]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NCNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn111{{[{}][{}]}}closure{{[}][}]}}Iu2i8PFvvEvES1_E"} -// CHECK: ![[TYPE110]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NCNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn111{{[{}][{}]}}closure{{[}][}]}}Iu2i8PFvvEvES1_S1_E"} -// CHECK: ![[TYPE111]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn13Foo15{{[{}][{}]}}constructor{{[}][}]}}E"} -// CHECK: ![[TYPE112]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn13Foo15{{[{}][{}]}}constructor{{[}][}]}}S_E"} -// CHECK: ![[TYPE113]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn13Foo15{{[{}][{}]}}constructor{{[}][}]}}S_S_E"} -// CHECK: ![[TYPE114]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNFNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn110{{[{}][{}]}}extern{{[}][}]}}3fooE"} -// CHECK: ![[TYPE115]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNFNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn110{{[{}][{}]}}extern{{[}][}]}}3fooS_E"} -// CHECK: ![[TYPE116]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNFNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn110{{[{}][{}]}}extern{{[}][}]}}3fooS_S_E"} -// CHECK: ![[TYPE117]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn1s0_11{{[{}][{}]}}closure{{[}][}]}}3FooE"} -// CHECK: ![[TYPE118]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn1s0_11{{[{}][{}]}}closure{{[}][}]}}3FooS_E"} -// CHECK: ![[TYPE119]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn1s0_11{{[{}][{}]}}closure{{[}][}]}}3FooS_S_E"} -// CHECK: ![[TYPE120]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn112{{[{}][{}]}}constant{{[}][}]}}3FooE"} -// CHECK: ![[TYPE121]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn112{{[{}][{}]}}constant{{[}][}]}}3FooS_E"} -// CHECK: ![[TYPE122]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn112{{[{}][{}]}}constant{{[}][}]}}3FooS_S_E"} -// CHECK: ![[TYPE123]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn18{{[{}][{}]}}impl{{[}][}]}}3fooIu3i32EE"} -// CHECK: ![[TYPE124]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn18{{[{}][{}]}}impl{{[}][}]}}3fooIu3i32ES0_E"} -// CHECK: ![[TYPE125]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn18{{[{}][{}]}}impl{{[}][}]}}3fooIu3i32ES0_S0_E"} -// CHECK: ![[TYPE126]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait1Iu5paramEu6regionEu3i32EE"} -// CHECK: ![[TYPE127]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait1Iu5paramEu6regionEu3i32ES4_E"} -// CHECK: ![[TYPE128]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait1Iu5paramEu6regionEu3i32ES4_S4_E"} -// CHECK: ![[TYPE129]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu3i32S_EE"} -// CHECK: ![[TYPE130]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu3i32S_ES0_E"} -// CHECK: ![[TYPE131]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu3i32S_ES0_S0_E"} -// CHECK: ![[TYPE132]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7Struct1Iu3i32ES_EE"} -// CHECK: ![[TYPE133]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7Struct1Iu3i32ES_ES1_E"} -// CHECK: ![[TYPE134]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7Struct1Iu3i32ES_ES1_S1_E"} -// CHECK: ![[TYPE135]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn13QuxIu3i32Lu5usize32EEE"} -// CHECK: ![[TYPE136]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn13QuxIu3i32Lu5usize32EES2_E"} -// CHECK: ![[TYPE137]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn13QuxIu3i32Lu5usize32EES2_S2_E"} -// CHECK: ![[TYPE138]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn15Quuux15{{[{}][{}]}}constructor{{[}][}]}}Iu6regionS_EE"} -// CHECK: ![[TYPE139]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn15Quuux15{{[{}][{}]}}constructor{{[}][}]}}Iu6regionS_ES0_E"} -// CHECK: ![[TYPE140]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn15Quuux15{{[{}][{}]}}constructor{{[}][}]}}Iu6regionS_ES0_S0_E"} -// CHECK: ![[TYPE141]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3FooE"} -// CHECK: ![[TYPE142]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3FooS_E"} -// CHECK: ![[TYPE143]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3FooS_S_E"} -// CHECK: ![[TYPE144]] = !{i64 0, !"_ZTSFvu3refIvEE"} -// CHECK: ![[TYPE145]] = !{i64 0, !"_ZTSFvu3refIvES_E"} -// CHECK: ![[TYPE146]] = !{i64 0, !"_ZTSFvu3refIvES_S_E"} -// CHECK: ![[TYPE147]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3BarE"} -// CHECK: ![[TYPE148]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3BarS_E"} -// CHECK: ![[TYPE149]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3BarS_S_E"} diff --git a/tests/codegen/sanitizer/cfi-add-canonical-jump-tables-flag.rs b/tests/codegen/sanitizer/cfi/add-canonical-jump-tables-flag.rs index f122fbdc086..f122fbdc086 100644 --- a/tests/codegen/sanitizer/cfi-add-canonical-jump-tables-flag.rs +++ b/tests/codegen/sanitizer/cfi/add-canonical-jump-tables-flag.rs diff --git a/tests/codegen/sanitizer/cfi-add-enable-split-lto-unit-flag.rs b/tests/codegen/sanitizer/cfi/add-enable-split-lto-unit-flag.rs index 05eea13c6ee..05eea13c6ee 100644 --- a/tests/codegen/sanitizer/cfi-add-enable-split-lto-unit-flag.rs +++ b/tests/codegen/sanitizer/cfi/add-enable-split-lto-unit-flag.rs diff --git a/tests/codegen/sanitizer/cfi-emit-type-checks-attr-no-sanitize.rs b/tests/codegen/sanitizer/cfi/emit-type-checks-attr-no-sanitize.rs index 9e0cc346afb..9f72de2ebcc 100644 --- a/tests/codegen/sanitizer/cfi-emit-type-checks-attr-no-sanitize.rs +++ b/tests/codegen/sanitizer/cfi/emit-type-checks-attr-no-sanitize.rs @@ -8,7 +8,7 @@ #[no_sanitize(cfi)] pub fn foo(f: fn(i32) -> i32, arg: i32) -> i32 { - // CHECK-LABEL: cfi_emit_type_checks_attr_no_sanitize::foo + // CHECK-LABEL: emit_type_checks_attr_no_sanitize::foo // CHECK: Function Attrs: {{.*}} // CHECK-LABEL: define{{.*}}foo{{.*}}!type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} // CHECK: start: diff --git a/tests/codegen/sanitizer/cfi-emit-type-checks.rs b/tests/codegen/sanitizer/cfi/emit-type-checks.rs index 6ec6f0e5476..6ec6f0e5476 100644 --- a/tests/codegen/sanitizer/cfi-emit-type-checks.rs +++ b/tests/codegen/sanitizer/cfi/emit-type-checks.rs diff --git a/tests/codegen/sanitizer/cfi-emit-type-metadata-attr-cfi-encoding.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-attr-cfi-encoding.rs index be4af9b7962..be4af9b7962 100644 --- a/tests/codegen/sanitizer/cfi-emit-type-metadata-attr-cfi-encoding.rs +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-attr-cfi-encoding.rs diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-const-generics.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-const-generics.rs new file mode 100644 index 00000000000..6608caca8af --- /dev/null +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-const-generics.rs @@ -0,0 +1,30 @@ +// Verifies that type metadata identifiers for functions are emitted correctly +// for const generics. +// +//@ needs-sanitizer-cfi +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Copt-level=0 + +#![crate_type="lib"] +#![feature(type_alias_impl_trait)] + +extern crate core; + +pub type Type1 = impl Send; + +pub fn foo() where + Type1: 'static, +{ + pub struct Foo<T, const N: usize>([T; N]); + let _: Type1 = Foo([0; 32]); +} + +pub fn foo1(_: Type1) { } +// CHECK: define{{.*}}4foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo2(_: Type1, _: Type1) { } +// CHECK: define{{.*}}4foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo3(_: Type1, _: Type1, _: Type1) { } +// CHECK: define{{.*}}4foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} + +// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo3FooIu3i32Lu5usize32EEE"} +// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo3FooIu3i32Lu5usize32EES2_E"} +// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo3FooIu3i32Lu5usize32EES2_S2_E"} diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-function-types.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-function-types.rs new file mode 100644 index 00000000000..ab3d339989b --- /dev/null +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-function-types.rs @@ -0,0 +1,45 @@ +// Verifies that type metadata identifiers for functions are emitted correctly +// for function types. +// +//@ needs-sanitizer-cfi +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static + +#![crate_type="lib"] + +pub fn foo1(_: fn(i32) -> i32) { } +// CHECK: define{{.*}}4foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo2(_: fn(i32) -> i32, _: fn(i32) -> i32) { } +// CHECK: define{{.*}}4foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo3(_: fn(i32) -> i32, _: fn(i32) -> i32, _: fn(i32) -> i32) { } +// CHECK: define{{.*}}4foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo4(_: &dyn Fn(i32) -> i32) { } +// CHECK: define{{.*}}4foo4{{.*}}!type ![[TYPE4:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo5(_: &dyn Fn(i32) -> i32, _: &dyn Fn(i32) -> i32) { } +// CHECK: define{{.*}}4foo5{{.*}}!type ![[TYPE5:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo6(_: &dyn Fn(i32) -> i32, _: &dyn Fn(i32) -> i32, _: &dyn Fn(i32) -> i32) { } +// CHECK: define{{.*}}4foo6{{.*}}!type ![[TYPE6:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo7(_: &dyn FnMut(i32) -> i32) { } +// CHECK: define{{.*}}4foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo8(_: &dyn FnMut(i32) -> i32, _: &dyn FnMut(i32) -> i32) { } +// CHECK: define{{.*}}4foo8{{.*}}!type ![[TYPE8:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo9(_: &dyn FnMut(i32) -> i32, _: &dyn FnMut(i32) -> i32, _: &dyn FnMut(i32) -> i32) { } +// CHECK: define{{.*}}4foo9{{.*}}!type ![[TYPE9:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo10(_: &dyn FnOnce(i32) -> i32) { } +// CHECK: define{{.*}}5foo10{{.*}}!type ![[TYPE10:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo11(_: &dyn FnOnce(i32) -> i32, _: &dyn FnOnce(i32) -> i32) { } +// CHECK: define{{.*}}5foo11{{.*}}!type ![[TYPE11:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo12(_: &dyn FnOnce(i32) -> i32, _: &dyn FnOnce(i32) -> i32, _: &dyn FnOnce(i32) -> i32) {} +// CHECK: define{{.*}}5foo12{{.*}}!type ![[TYPE12:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} + +// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvPFu3i32S_EE"} +// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvPFu3i32S_ES0_E"} +// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvPFu3i32S_ES0_S0_E"} +// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function2FnIu5paramEu6regionEEE"} +// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function2FnIu5paramEu6regionEES3_E"} +// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function2FnIu5paramEu6regionEES3_S3_E"} +// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function5FnMutIu5paramEu6regionEEE"} +// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function5FnMutIu5paramEu6regionEES3_E"} +// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function5FnMutIu5paramEu6regionEES3_S3_E"} +// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnceIu5paramEu6regionEEE"} +// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnceIu5paramEu6regionEES3_E"} +// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnceIu5paramEu6regionEES3_S3_E"} diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-lifetimes.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-lifetimes.rs new file mode 100644 index 00000000000..4d08c0c3039 --- /dev/null +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-lifetimes.rs @@ -0,0 +1,27 @@ +// Verifies that type metadata identifiers for functions are emitted correctly +// for lifetimes/regions. +// +//@ needs-sanitizer-cfi +//@ compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Copt-level=0 + +#![crate_type="lib"] +#![feature(type_alias_impl_trait)] + +extern crate core; + +pub type Type1 = impl Send; + +pub fn foo<'a>() where + Type1: 'static, +{ + pub struct Foo<'a>(&'a i32); + pub struct Bar<'a, 'b>(&'a i32, &'b Foo<'b>); + let _: Type1 = Bar; +} + +pub fn foo1(_: Type1) { } +// CHECK: define{{.*}}4foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo2(_: Type1, _: Type1) { } +// CHECK: define{{.*}}4foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo3(_: Type1, _: Type1, _: Type1) { } +// CHECK: define{{.*}}4foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs new file mode 100644 index 00000000000..ca781a99296 --- /dev/null +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs @@ -0,0 +1,88 @@ +// Verifies that type metadata identifiers for functions are emitted correctly +// for paths. +// +//@ needs-sanitizer-cfi +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static + +#![crate_type="lib"] +#![feature(inline_const, type_alias_impl_trait)] + +extern crate core; + +pub type Type1 = impl Send; +pub type Type2 = impl Send; +pub type Type3 = impl Send; +pub type Type4 = impl Send; + +pub fn foo() where + Type1: 'static, + Type2: 'static, + Type3: 'static, + Type4: 'static, +{ + // Type in extern path + extern { + fn bar(); + } + let _: Type1 = bar; + + // Type in closure path + || { + pub struct Foo; + let _: Type2 = Foo; + }; + + // Type in const path + const { + pub struct Foo; + fn bar() -> Type3 { Foo } + }; + + + // Type in impl path + struct Foo; + impl Foo { + fn bar(&self) { } + } + let _: Type4 = <Foo>::bar; +} + +// Force arguments to be passed by using a reference. Otherwise, they may end up PassMode::Ignore + +pub fn foo1(_: &Type1) { } +// CHECK: define{{.*}}4foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo2(_: &Type1, _: &Type1) { } +// CHECK: define{{.*}}4foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo3(_: &Type1, _: &Type1, _: &Type1) { } +// CHECK: define{{.*}}4foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo4(_: &Type2) { } +// CHECK: define{{.*}}4foo4{{.*}}!type ![[TYPE4:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo5(_: &Type2, _: &Type2) { } +// CHECK: define{{.*}}4foo5{{.*}}!type ![[TYPE5:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo6(_: &Type2, _: &Type2, _: &Type2) { } +// CHECK: define{{.*}}4foo6{{.*}}!type ![[TYPE6:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo7(_: &Type3) { } +// CHECK: define{{.*}}4foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo8(_: &Type3, _: &Type3) { } +// CHECK: define{{.*}}4foo8{{.*}}!type ![[TYPE8:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo9(_: &Type3, _: &Type3, _: &Type3) { } +// CHECK: define{{.*}}4foo9{{.*}}!type ![[TYPE9:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo10(_: &Type4) { } +// CHECK: define{{.*}}5foo10{{.*}}!type ![[TYPE10:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo11(_: &Type4, _: &Type4) { } +// CHECK: define{{.*}}5foo11{{.*}}!type ![[TYPE11:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo12(_: &Type4, _: &Type4, _: &Type4) { } +// CHECK: define{{.*}}5foo12{{.*}}!type ![[TYPE12:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} + +// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNFNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo10{{[{}][{}]}}extern{{[}][}]}}3barEE"} +// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNFNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo10{{[{}][{}]}}extern{{[}][}]}}3barES0_E"} +// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNFNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo10{{[{}][{}]}}extern{{[}][}]}}3barES0_S0_E"} +// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo11{{[{}][{}]}}closure{{[}][}]}}3FooEE"} +// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo11{{[{}][{}]}}closure{{[}][}]}}3FooES0_E"} +// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo11{{[{}][{}]}}closure{{[}][}]}}3FooES0_S0_E"} +// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooEE"} +// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_E"} +// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_S0_E"} +// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo8{{[{}][{}]}}impl{{[}][}]}}3barEE"} +// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo8{{[{}][{}]}}impl{{[}][}]}}3barES0_E"} +// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo8{{[{}][{}]}}impl{{[}][}]}}3barES0_S0_E"} diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-pointer-types.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-pointer-types.rs new file mode 100644 index 00000000000..6ad6f3ac348 --- /dev/null +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-pointer-types.rs @@ -0,0 +1,54 @@ +// Verifies that type metadata identifiers for functions are emitted correctly +// for pointer types. +// +//@ needs-sanitizer-cfi +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static + +#![crate_type="lib"] + +pub fn foo1(_: &mut i32) { } +// CHECK: define{{.*}}4foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo2(_: &mut i32, _: &i32) { } +// CHECK: define{{.*}}4foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo3(_: &mut i32, _: &i32, _: &i32) { } +// CHECK: define{{.*}}4foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo4(_: &i32) { } +// CHECK: define{{.*}}4foo4{{.*}}!type ![[TYPE4:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo5(_: &i32, _: &mut i32) { } +// CHECK: define{{.*}}4foo5{{.*}}!type ![[TYPE5:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo6(_: &i32, _: &mut i32, _: &mut i32) { } +// CHECK: define{{.*}}4foo6{{.*}}!type ![[TYPE6:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo7(_: *mut i32) { } +// CHECK: define{{.*}}4foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo8(_: *mut i32, _: *const i32) { } +// CHECK: define{{.*}}4foo8{{.*}}!type ![[TYPE8:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo9(_: *mut i32, _: *const i32, _: *const i32) { } +// CHECK: define{{.*}}4foo9{{.*}}!type ![[TYPE9:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo10(_: *const i32) { } +// CHECK: define{{.*}}5foo10{{.*}}!type ![[TYPE10:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo11(_: *const i32, _: *mut i32) { } +// CHECK: define{{.*}}5foo11{{.*}}!type ![[TYPE11:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo12(_: *const i32, _: *mut i32, _: *mut i32) { } +// CHECK: define{{.*}}5foo12{{.*}}!type ![[TYPE12:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo13(_: fn(i32) -> i32) { } +// CHECK: define{{.*}}5foo13{{.*}}!type ![[TYPE13:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo14(_: fn(i32) -> i32, _: fn(i32) -> i32) { } +// CHECK: define{{.*}}5foo14{{.*}}!type ![[TYPE14:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo15(_: fn(i32) -> i32, _: fn(i32) -> i32, _: fn(i32) -> i32) { } +// CHECK: define{{.*}}5foo15{{.*}}!type ![[TYPE15:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} + +// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvU3mutu3refIu3i32EE"} +// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvU3mutu3refIu3i32ES0_E"} +// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvU3mutu3refIu3i32ES0_S0_E"} +// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3refIu3i32EE"} +// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3refIu3i32EU3mutS0_E"} +// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvu3refIu3i32EU3mutS0_S1_E"} +// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvPu3i32E"} +// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvPu3i32PKS_E"} +// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvPu3i32PKS_S2_E"} +// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvPKu3i32E"} +// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvPKu3i32PS_E"} +// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvPKu3i32PS_S2_E"} +// CHECK: ![[TYPE13]] = !{i64 0, !"_ZTSFvPFu3i32S_EE"} +// CHECK: ![[TYPE14]] = !{i64 0, !"_ZTSFvPFu3i32S_ES0_E"} +// CHECK: ![[TYPE15]] = !{i64 0, !"_ZTSFvPFu3i32S_ES0_S0_E"} diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-primitive-types.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-primitive-types.rs new file mode 100644 index 00000000000..38f507856bd --- /dev/null +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-primitive-types.rs @@ -0,0 +1,190 @@ +// Verifies that type metadata identifiers for functions are emitted correctly +// for primitive types. +// +//@ needs-sanitizer-cfi +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static + +#![crate_type="lib"] + +extern crate core; +use core::ffi::*; + +pub fn foo1(_: ()) { } +// CHECK: define{{.*}}4foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo2(_: (), _: c_void) { } +// CHECK: define{{.*}}4foo2{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo3(_: (), _: c_void, _: c_void) { } +// CHECK: define{{.*}}4foo3{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo4(_: *mut ()) { } +// CHECK: define{{.*}}4foo4{{.*}}!type ![[TYPE4:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo5(_: *mut (), _: *mut c_void) { } +// CHECK: define{{.*}}4foo5{{.*}}!type ![[TYPE5:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo6(_: *mut (), _: *mut c_void, _: *mut c_void) { } +// CHECK: define{{.*}}4foo6{{.*}}!type ![[TYPE6:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo7(_: *const ()) { } +// CHECK: define{{.*}}4foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo8(_: *const (), _: *const c_void) { } +// CHECK: define{{.*}}4foo8{{.*}}!type ![[TYPE8:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo9(_: *const (), _: *const c_void, _: *const c_void) { } +// CHECK: define{{.*}}4foo9{{.*}}!type ![[TYPE9:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo10(_: bool) { } +// CHECK: define{{.*}}5foo10{{.*}}!type ![[TYPE10:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo11(_: bool, _: bool) { } +// CHECK: define{{.*}}5foo11{{.*}}!type ![[TYPE11:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo12(_: bool, _: bool, _: bool) { } +// CHECK: define{{.*}}5foo12{{.*}}!type ![[TYPE12:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo13(_: i8) { } +// CHECK: define{{.*}}5foo13{{.*}}!type ![[TYPE13:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo14(_: i8, _: i8) { } +// CHECK: define{{.*}}5foo14{{.*}}!type ![[TYPE14:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo15(_: i8, _: i8, _: i8) { } +// CHECK: define{{.*}}5foo15{{.*}}!type ![[TYPE15:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo16(_: i16) { } +// CHECK: define{{.*}}5foo16{{.*}}!type ![[TYPE16:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo17(_: i16, _: i16) { } +// CHECK: define{{.*}}5foo17{{.*}}!type ![[TYPE17:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo18(_: i16, _: i16, _: i16) { } +// CHECK: define{{.*}}5foo18{{.*}}!type ![[TYPE18:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo19(_: i32) { } +// CHECK: define{{.*}}5foo19{{.*}}!type ![[TYPE19:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo20(_: i32, _: i32) { } +// CHECK: define{{.*}}5foo20{{.*}}!type ![[TYPE20:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo21(_: i32, _: i32, _: i32) { } +// CHECK: define{{.*}}5foo21{{.*}}!type ![[TYPE21:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo22(_: i64) { } +// CHECK: define{{.*}}5foo22{{.*}}!type ![[TYPE22:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo23(_: i64, _: i64) { } +// CHECK: define{{.*}}5foo23{{.*}}!type ![[TYPE23:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo24(_: i64, _: i64, _: i64) { } +// CHECK: define{{.*}}5foo24{{.*}}!type ![[TYPE24:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo25(_: i128) { } +// CHECK: define{{.*}}5foo25{{.*}}!type ![[TYPE25:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo26(_: i128, _: i128) { } +// CHECK: define{{.*}}5foo26{{.*}}!type ![[TYPE26:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo27(_: i128, _: i128, _: i128) { } +// CHECK: define{{.*}}5foo27{{.*}}!type ![[TYPE27:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo28(_: isize) { } +// CHECK: define{{.*}}5foo28{{.*}}!type ![[TYPE28:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo29(_: isize, _: isize) { } +// CHECK: define{{.*}}5foo29{{.*}}!type ![[TYPE29:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo30(_: isize, _: isize, _: isize) { } +// CHECK: define{{.*}}5foo30{{.*}}!type ![[TYPE30:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo31(_: u8) { } +// CHECK: define{{.*}}5foo31{{.*}}!type ![[TYPE31:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo32(_: u8, _: u8) { } +// CHECK: define{{.*}}5foo32{{.*}}!type ![[TYPE32:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo33(_: u8, _: u8, _: u8) { } +// CHECK: define{{.*}}5foo33{{.*}}!type ![[TYPE33:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo34(_: u16) { } +// CHECK: define{{.*}}5foo34{{.*}}!type ![[TYPE34:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo35(_: u16, _: u16) { } +// CHECK: define{{.*}}5foo35{{.*}}!type ![[TYPE35:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo36(_: u16, _: u16, _: u16) { } +// CHECK: define{{.*}}5foo36{{.*}}!type ![[TYPE36:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo37(_: u32) { } +// CHECK: define{{.*}}5foo37{{.*}}!type ![[TYPE37:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo38(_: u32, _: u32) { } +// CHECK: define{{.*}}5foo38{{.*}}!type ![[TYPE38:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo39(_: u32, _: u32, _: u32) { } +// CHECK: define{{.*}}5foo39{{.*}}!type ![[TYPE39:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo40(_: u64) { } +// CHECK: define{{.*}}5foo40{{.*}}!type ![[TYPE40:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo41(_: u64, _: u64) { } +// CHECK: define{{.*}}5foo41{{.*}}!type ![[TYPE41:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo42(_: u64, _: u64, _: u64) { } +// CHECK: define{{.*}}5foo42{{.*}}!type ![[TYPE42:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo43(_: u128) { } +// CHECK: define{{.*}}5foo43{{.*}}!type ![[TYPE43:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo44(_: u128, _: u128) { } +// CHECK: define{{.*}}5foo44{{.*}}!type ![[TYPE44:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo45(_: u128, _: u128, _: u128) { } +// CHECK: define{{.*}}5foo45{{.*}}!type ![[TYPE45:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo46(_: usize) { } +// CHECK: define{{.*}}5foo46{{.*}}!type ![[TYPE46:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo47(_: usize, _: usize) { } +// CHECK: define{{.*}}5foo47{{.*}}!type ![[TYPE47:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo48(_: usize, _: usize, _: usize) { } +// CHECK: define{{.*}}5foo48{{.*}}!type ![[TYPE48:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo49(_: f32) { } +// CHECK: define{{.*}}5foo49{{.*}}!type ![[TYPE49:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo50(_: f32, _: f32) { } +// CHECK: define{{.*}}5foo50{{.*}}!type ![[TYPE50:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo51(_: f32, _: f32, _: f32) { } +// CHECK: define{{.*}}5foo51{{.*}}!type ![[TYPE51:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo52(_: f64) { } +// CHECK: define{{.*}}5foo52{{.*}}!type ![[TYPE52:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo53(_: f64, _: f64) { } +// CHECK: define{{.*}}5foo53{{.*}}!type ![[TYPE53:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo54(_: f64, _: f64, _: f64) { } +// CHECK: define{{.*}}5foo54{{.*}}!type ![[TYPE54:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo55(_: char) { } +// CHECK: define{{.*}}5foo55{{.*}}!type ![[TYPE55:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo56(_: char, _: char) { } +// CHECK: define{{.*}}5foo56{{.*}}!type ![[TYPE56:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo57(_: char, _: char, _: char) { } +// CHECK: define{{.*}}5foo57{{.*}}!type ![[TYPE57:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo58(_: &str) { } +// CHECK: define{{.*}}5foo58{{.*}}!type ![[TYPE58:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo59(_: &str, _: &str) { } +// CHECK: define{{.*}}5foo59{{.*}}!type ![[TYPE59:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo60(_: &str, _: &str, _: &str) { } +// CHECK: define{{.*}}5foo60{{.*}}!type ![[TYPE60:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} + +// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvvE"} +// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvPvE"} +// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvPvS_E"} +// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvPvS_S_E"} +// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvPKvE"} +// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvPKvS0_E"} +// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvPKvS0_S0_E"} +// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvbE"} +// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvbbE"} +// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvbbbE"} +// CHECK: ![[TYPE13]] = !{i64 0, !"_ZTSFvu2i8E"} +// CHECK: ![[TYPE14]] = !{i64 0, !"_ZTSFvu2i8S_E"} +// CHECK: ![[TYPE15]] = !{i64 0, !"_ZTSFvu2i8S_S_E"} +// CHECK: ![[TYPE16]] = !{i64 0, !"_ZTSFvu3i16E"} +// CHECK: ![[TYPE17]] = !{i64 0, !"_ZTSFvu3i16S_E"} +// CHECK: ![[TYPE18]] = !{i64 0, !"_ZTSFvu3i16S_S_E"} +// CHECK: ![[TYPE19]] = !{i64 0, !"_ZTSFvu3i32E"} +// CHECK: ![[TYPE20]] = !{i64 0, !"_ZTSFvu3i32S_E"} +// CHECK: ![[TYPE21]] = !{i64 0, !"_ZTSFvu3i32S_S_E"} +// CHECK: ![[TYPE22]] = !{i64 0, !"_ZTSFvu3i64E"} +// CHECK: ![[TYPE23]] = !{i64 0, !"_ZTSFvu3i64S_E"} +// CHECK: ![[TYPE24]] = !{i64 0, !"_ZTSFvu3i64S_S_E"} +// CHECK: ![[TYPE25]] = !{i64 0, !"_ZTSFvu4i128E"} +// CHECK: ![[TYPE26]] = !{i64 0, !"_ZTSFvu4i128S_E"} +// CHECK: ![[TYPE27]] = !{i64 0, !"_ZTSFvu4i128S_S_E"} +// CHECK: ![[TYPE28]] = !{i64 0, !"_ZTSFvu5isizeE"} +// CHECK: ![[TYPE29]] = !{i64 0, !"_ZTSFvu5isizeS_E"} +// CHECK: ![[TYPE30]] = !{i64 0, !"_ZTSFvu5isizeS_S_E"} +// CHECK: ![[TYPE31]] = !{i64 0, !"_ZTSFvu2u8E"} +// CHECK: ![[TYPE32]] = !{i64 0, !"_ZTSFvu2u8S_E"} +// CHECK: ![[TYPE33]] = !{i64 0, !"_ZTSFvu2u8S_S_E"} +// CHECK: ![[TYPE34]] = !{i64 0, !"_ZTSFvu3u16E"} +// CHECK: ![[TYPE35]] = !{i64 0, !"_ZTSFvu3u16S_E"} +// CHECK: ![[TYPE36]] = !{i64 0, !"_ZTSFvu3u16S_S_E"} +// CHECK: ![[TYPE37]] = !{i64 0, !"_ZTSFvu3u32E"} +// CHECK: ![[TYPE38]] = !{i64 0, !"_ZTSFvu3u32S_E"} +// CHECK: ![[TYPE39]] = !{i64 0, !"_ZTSFvu3u32S_S_E"} +// CHECK: ![[TYPE40]] = !{i64 0, !"_ZTSFvu3u64E"} +// CHECK: ![[TYPE41]] = !{i64 0, !"_ZTSFvu3u64S_E"} +// CHECK: ![[TYPE42]] = !{i64 0, !"_ZTSFvu3u64S_S_E"} +// CHECK: ![[TYPE43]] = !{i64 0, !"_ZTSFvu4u128E"} +// CHECK: ![[TYPE44]] = !{i64 0, !"_ZTSFvu4u128S_E"} +// CHECK: ![[TYPE45]] = !{i64 0, !"_ZTSFvu4u128S_S_E"} +// CHECK: ![[TYPE46]] = !{i64 0, !"_ZTSFvu5usizeE"} +// CHECK: ![[TYPE47]] = !{i64 0, !"_ZTSFvu5usizeS_E"} +// CHECK: ![[TYPE48]] = !{i64 0, !"_ZTSFvu5usizeS_S_E"} +// CHECK: ![[TYPE49]] = !{i64 0, !"_ZTSFvfE"} +// CHECK: ![[TYPE50]] = !{i64 0, !"_ZTSFvffE"} +// CHECK: ![[TYPE51]] = !{i64 0, !"_ZTSFvfffE"} +// CHECK: ![[TYPE52]] = !{i64 0, !"_ZTSFvdE"} +// CHECK: ![[TYPE53]] = !{i64 0, !"_ZTSFvddE"} +// CHECK: ![[TYPE54]] = !{i64 0, !"_ZTSFvdddE"} +// CHECK: ![[TYPE55]] = !{i64 0, !"_ZTSFvu4charE"} +// CHECK: ![[TYPE56]] = !{i64 0, !"_ZTSFvu4charS_E"} +// CHECK: ![[TYPE57]] = !{i64 0, !"_ZTSFvu4charS_S_E"} +// CHECK: ![[TYPE58]] = !{i64 0, !"_ZTSFvu3refIu3strEE"} +// CHECK: ![[TYPE59]] = !{i64 0, !"_ZTSFvu3refIu3strES0_E"} +// CHECK: ![[TYPE60]] = !{i64 0, !"_ZTSFvu3refIu3strES0_S0_E"} diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-repr-transparent-types.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-repr-transparent-types.rs new file mode 100644 index 00000000000..6f47f5e3355 --- /dev/null +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-repr-transparent-types.rs @@ -0,0 +1,64 @@ +// Verifies that type metadata identifiers for functions are emitted correctly +// for repr transparent types. +// +//@ needs-sanitizer-cfi +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static + +#![crate_type="lib"] + +extern crate core; +use core::ffi::*; +use std::marker::PhantomData; + +struct Foo(i32); + +// repr(transparent) user-defined type +#[repr(transparent)] +pub struct Type1 { + member1: (), + member2: PhantomData<i32>, + member3: Foo, +} + +// Self-referencing repr(transparent) user-defined type +#[repr(transparent)] +pub struct Type2<'a> { + member1: (), + member2: PhantomData<i32>, + member3: &'a Type2<'a>, +} + +pub struct Bar(i32); + +// repr(transparent) user-defined generic type +#[repr(transparent)] +pub struct Type3<T>(T); + +pub fn foo1(_: Type1) { } +// CHECK: define{{.*}}4foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo2(_: Type1, _: Type1) { } +// CHECK: define{{.*}}4foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo3(_: Type1, _: Type1, _: Type1) { } +// CHECK: define{{.*}}4foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo4(_: Type2) { } +// CHECK: define{{.*}}4foo4{{.*}}!type ![[TYPE4:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo5(_: Type2, _: Type2) { } +// CHECK: define{{.*}}4foo5{{.*}}!type ![[TYPE5:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo6(_: Type2, _: Type2, _: Type2) { } +// CHECK: define{{.*}}4foo6{{.*}}!type ![[TYPE6:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo7(_: Type3<Bar>) { } +// CHECK: define{{.*}}4foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo8(_: Type3<Bar>, _: Type3<Bar>) { } +// CHECK: define{{.*}}4foo8{{.*}}!type ![[TYPE8:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo9(_: Type3<Bar>, _: Type3<Bar>, _: Type3<Bar>) { } +// CHECK: define{{.*}}4foo9{{.*}}!type ![[TYPE9:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} + +// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}3FooE"} +// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}3FooS_E"} +// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}3FooS_S_E"} +// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3refIvEE"} +// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3refIvES_E"} +// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvu3refIvES_S_E"} +// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}3BarE"} +// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}3BarS_E"} +// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}3BarS_S_E"} diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-sequence-types.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-sequence-types.rs new file mode 100644 index 00000000000..dd2e05dd2ec --- /dev/null +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-sequence-types.rs @@ -0,0 +1,36 @@ +// Verifies that type metadata identifiers for functions are emitted correctly +// for sequence types. +// +//@ needs-sanitizer-cfi +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static + +#![crate_type="lib"] + +pub fn foo1(_: (i32, i32)) { } +// CHECK: define{{.*}}4foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo2(_: (i32, i32), _: (i32, i32)) { } +// CHECK: define{{.*}}4foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo3(_: (i32, i32), _: (i32, i32), _: (i32, i32)) { } +// CHECK: define{{.*}}4foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo4(_: [i32; 32]) { } +// CHECK: define{{.*}}4foo4{{.*}}!type ![[TYPE4:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo5(_: [i32; 32], _: [i32; 32]) { } +// CHECK: define{{.*}}4foo5{{.*}}!type ![[TYPE5:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo6(_: [i32; 32], _: [i32; 32], _: [i32; 32]) { } +// CHECK: define{{.*}}4foo6{{.*}}!type ![[TYPE6:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo7(_: &[i32]) { } +// CHECK: define{{.*}}4foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo8(_: &[i32], _: &[i32]) { } +// CHECK: define{{.*}}4foo8{{.*}}!type ![[TYPE8:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo9(_: &[i32], _: &[i32], _: &[i32]) { } +// CHECK: define{{.*}}4foo9{{.*}}!type ![[TYPE9:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} + +// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu5tupleIu3i32S_EE"} +// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu5tupleIu3i32S_ES0_E"} +// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvu5tupleIu3i32S_ES0_S0_E"} +// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvA32u3i32E"} +// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvA32u3i32S0_E"} +// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvA32u3i32S0_S0_E"} +// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu5sliceIu3i32EEE"} +// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu5sliceIu3i32EES1_E"} +// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu5sliceIu3i32EES1_S1_E"} diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-trait-types.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-trait-types.rs new file mode 100644 index 00000000000..cc7178e41c7 --- /dev/null +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-trait-types.rs @@ -0,0 +1,161 @@ +// Verifies that type metadata identifiers for functions are emitted correctly +// for trait types. +// +//@ needs-sanitizer-cfi +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static + +#![crate_type="lib"] + +extern crate core; + +pub trait Trait1 { + fn foo(&self); +} + +#[derive(Clone, Copy)] +pub struct Type1; + +impl Trait1 for Type1 { + fn foo(&self) { + } +} + +pub trait Trait2<T> { + fn bar(&self); +} + +pub struct Type2; + +impl Trait2<i32> for Type2 { + fn bar(&self) { + } +} + +pub trait Trait3<T> { + fn baz(&self, _: &T); +} + +pub struct Type3; + +impl<T, U> Trait3<U> for T { + fn baz(&self, _: &U) { + } +} + +pub trait Trait4<'a, T> { + type Output: 'a; + fn qux(&self, _: &T) -> Self::Output; +} + +pub struct Type4; + +impl<'a, T, U> Trait4<'a, U> for T { + type Output = &'a i32; + fn qux(&self, _: &U) -> Self::Output { + &0 + } +} + +pub trait Trait5<T, const N: usize> { + fn quux(&self, _: &[T; N]); +} + +#[derive(Copy, Clone)] +pub struct Type5; + +impl<T, U, const N: usize> Trait5<U, N> for T { + fn quux(&self, _: &[U; N]) { + } +} + +pub fn foo1(_: &dyn Send) { } +// CHECK: define{{.*}}4foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo2(_: &dyn Send, _: &dyn Send) { } +// CHECK: define{{.*}}4foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo3(_: &dyn Send, _: &dyn Send, _: &dyn Send) { } +// CHECK: define{{.*}}4foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo4(_: &(dyn Send + Sync)) { } +// CHECK: define{{.*}}4foo4{{.*}}!type ![[TYPE4:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo5(_: &(dyn Send + Sync), _: &(dyn Sync + Send)) { } +// CHECK: define{{.*}}4foo5{{.*}}!type ![[TYPE5:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo6(_: &(dyn Send + Sync), _: &(dyn Sync + Send), _: &(dyn Sync + Send)) { } +// CHECK: define{{.*}}4foo6{{.*}}!type ![[TYPE6:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo7(_: &(dyn Trait1 + Send)) { } +// CHECK: define{{.*}}4foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo8(_: &(dyn Trait1 + Send), _: &(dyn Trait1 + Send)) { } +// CHECK: define{{.*}}4foo8{{.*}}!type ![[TYPE8:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo9(_: &(dyn Trait1 + Send), _: &(dyn Trait1 + Send), _: &(dyn Trait1 + Send)) { } +// CHECK: define{{.*}}4foo9{{.*}}!type ![[TYPE9:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo10(_: &(dyn Trait1 + Send + Sync)) { } +// CHECK: define{{.*}}5foo10{{.*}}!type ![[TYPE10:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo11(_: &(dyn Trait1 + Send + Sync), _: &(dyn Trait1 + Sync + Send)) { } +// CHECK: define{{.*}}5foo11{{.*}}!type ![[TYPE11:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo12(_: &(dyn Trait1 + Send + Sync), + _: &(dyn Trait1 + Sync + Send), + _: &(dyn Trait1 + Sync + Send)) { } +// CHECK: define{{.*}}5foo12{{.*}}!type ![[TYPE12:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo13(_: &dyn Trait1) { } +// CHECK: define{{.*}}5foo13{{.*}}!type ![[TYPE13:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo14(_: &dyn Trait1, _: &dyn Trait1) { } +// CHECK: define{{.*}}5foo14{{.*}}!type ![[TYPE14:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo15(_: &dyn Trait1, _: &dyn Trait1, _: &dyn Trait1) { } +// CHECK: define{{.*}}5foo15{{.*}}!type ![[TYPE15:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo16<T>(_: &dyn Trait2<T>) { } +pub fn bar16() { let a = Type2; foo16(&a); } +// CHECK: define{{.*}}5foo16{{.*}}!type ![[TYPE16:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo17<T>(_: &dyn Trait2<T>, _: &dyn Trait2<T>) { } +pub fn bar17() { let a = Type2; foo17(&a, &a); } +// CHECK: define{{.*}}5foo17{{.*}}!type ![[TYPE17:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo18<T>(_: &dyn Trait2<T>, _: &dyn Trait2<T>, _: &dyn Trait2<T>) { } +pub fn bar18() { let a = Type2; foo18(&a, &a, &a); } +// CHECK: define{{.*}}5foo18{{.*}}!type ![[TYPE18:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo19(_: &dyn Trait3<Type3>) { } +// CHECK: define{{.*}}5foo19{{.*}}!type ![[TYPE19:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo20(_: &dyn Trait3<Type3>, _: &dyn Trait3<Type3>) { } +// CHECK: define{{.*}}5foo20{{.*}}!type ![[TYPE20:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo21(_: &dyn Trait3<Type3>, _: &dyn Trait3<Type3>, _: &dyn Trait3<Type3>) { } +// CHECK: define{{.*}}5foo21{{.*}}!type ![[TYPE21:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo22<'a>(_: &dyn Trait4<'a, Type4, Output = &'a i32>) { } +// CHECK: define{{.*}}5foo22{{.*}}!type ![[TYPE22:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo23<'a>(_: &dyn Trait4<'a, Type4, Output = &'a i32>, + _: &dyn Trait4<'a, Type4, Output = &'a i32>) { } +// CHECK: define{{.*}}5foo23{{.*}}!type ![[TYPE23:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo24<'a>(_: &dyn Trait4<'a, Type4, Output = &'a i32>, + _: &dyn Trait4<'a, Type4, Output = &'a i32>, + _: &dyn Trait4<'a, Type4, Output = &'a i32>) { } +// CHECK: define{{.*}}5foo24{{.*}}!type ![[TYPE24:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo25(_: &dyn Trait5<Type5, 32>) { } +// CHECK: define{{.*}}5foo25{{.*}}!type ![[TYPE25:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo26(_: &dyn Trait5<Type5, 32>, _: &dyn Trait5<Type5, 32>) { } +// CHECK: define{{.*}}5foo26{{.*}}!type ![[TYPE26:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo27(_: &dyn Trait5<Type5, 32>, _: &dyn Trait5<Type5, 32>, _: &dyn Trait5<Type5, 32>) { } +// CHECK: define{{.*}}5foo27{{.*}}!type ![[TYPE27:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} + +// CHECK: ![[TYPE13]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u6regionEEE"} +// CHECK: ![[TYPE16]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait2Iu5paramEu6regionEEE"} +// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEEE"} +// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEES2_E"} +// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEES2_S2_E"} +// FIXME(rcvalle): Enforce autotraits ordering when encoding (e.g., alphabetical order) +// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u6regionEEE"} +// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u6regionEES3_E"} +// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u6regionEES3_S3_E"} +// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEEE"} +// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEES3_E"} +// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEES3_S3_E"} +// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u6regionEEE"} +// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u6regionEES4_E"} +// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u6regionEES4_S4_E"} +// CHECK: ![[TYPE14]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u6regionEES2_E"} +// CHECK: ![[TYPE15]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u6regionEES2_S2_E"} +// CHECK: ![[TYPE17]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait2Iu5paramEu6regionEES3_E"} +// CHECK: ![[TYPE18]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait2Iu5paramEu6regionEES3_S3_E"} +// CHECK: ![[TYPE19]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait3Iu5paramEu6regionEEE"} +// CHECK: ![[TYPE20]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait3Iu5paramEu6regionEES3_E"} +// CHECK: ![[TYPE21]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait3Iu5paramEu6regionEES3_S3_E"} +// CHECK: ![[TYPE22]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait4Iu6regionu5paramEu6regionEEE"} +// CHECK: ![[TYPE23]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait4Iu6regionu5paramEu6regionEES4_E"} +// CHECK: ![[TYPE24]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait4Iu6regionu5paramEu6regionEES4_S4_E"} +// CHECK: ![[TYPE25]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait5Iu5paramLu5usizeEEu6regionEEE"} +// CHECK: ![[TYPE26]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait5Iu5paramLu5usizeEEu6regionEES5_E"} +// CHECK: ![[TYPE27]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait5Iu5paramLu5usizeEEu6regionEES5_S5_E"} diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-user-defined-types.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-user-defined-types.rs new file mode 100644 index 00000000000..4eaf42bf87d --- /dev/null +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-user-defined-types.rs @@ -0,0 +1,62 @@ +// Verifies that type metadata identifiers for functions are emitted correctly +// for user-defined types. +// +//@ needs-sanitizer-cfi +//@ compile-flags: -Clto -Cno-prepopulate-passes -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static + +#![crate_type="lib"] +#![feature(extern_types)] + +pub struct Struct1<T> { + member1: T, +} + +pub enum Enum1<T> { + Variant1(T), +} + +pub union Union1<T> { + member1: std::mem::ManuallyDrop<T>, +} + +extern { + pub type type1; +} + +pub fn foo1(_: &Struct1::<i32>) { } +// CHECK: define{{.*}}4foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo2(_: &Struct1::<i32>, _: &Struct1::<i32>) { } +// CHECK: define{{.*}}4foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo3(_: &Struct1::<i32>, _: &Struct1::<i32>, _: &Struct1::<i32>) { } +// CHECK: define{{.*}}4foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo4(_: &Enum1::<i32>) { } +// CHECK: define{{.*}}4foo4{{.*}}!type ![[TYPE4:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo5(_: &Enum1::<i32>, _: &Enum1::<i32>) { } +// CHECK: define{{.*}}4foo5{{.*}}!type ![[TYPE5:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo6(_: &Enum1::<i32>, _: &Enum1::<i32>, _: &Enum1::<i32>) { } +// CHECK: define{{.*}}4foo6{{.*}}!type ![[TYPE6:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo7(_: &Union1::<i32>) { } +// CHECK: define{{.*}}4foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo8(_: &Union1::<i32>, _: &Union1::<i32>) { } +// CHECK: define{{.*}}4foo8{{.*}}!type ![[TYPE8:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo9(_: &Union1::<i32>, _: &Union1::<i32>, _: &Union1::<i32>) { } +// CHECK: define{{.*}}4foo9{{.*}}!type ![[TYPE9:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo10(_: *mut type1) { } +// CHECK: define{{.*}}5foo10{{.*}}!type ![[TYPE10:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo11(_: *mut type1, _: *mut type1) { } +// CHECK: define{{.*}}5foo11{{.*}}!type ![[TYPE11:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} +pub fn foo12(_: *mut type1, _: *mut type1, _: *mut type1) { } +// CHECK: define{{.*}}5foo12{{.*}}!type ![[TYPE12:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} + +// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}7Struct1Iu3i32EEE"} +// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}7Struct1Iu3i32EES1_E"} +// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}7Struct1Iu3i32EES1_S1_E"} +// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Enum1Iu3i32EEE"} +// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Enum1Iu3i32EES1_E"} +// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Enum1Iu3i32EES1_S1_E"} +// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Union1Iu3i32EEE"} +// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Union1Iu3i32EES1_E"} +// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Union1Iu3i32EES1_S1_E"} +// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvP5type1E"} +// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvP5type1S0_E"} +// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvP5type1S0_S0_E"} diff --git a/tests/codegen/sanitizer/cfi-emit-type-metadata-itanium-cxx-abi-generalized.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-generalized.rs index ccd7ee93ca1..ccd7ee93ca1 100644 --- a/tests/codegen/sanitizer/cfi-emit-type-metadata-itanium-cxx-abi-generalized.rs +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-generalized.rs diff --git a/tests/codegen/sanitizer/cfi-emit-type-metadata-itanium-cxx-abi-normalized-generalized.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-normalized-generalized.rs index d4130034178..d4130034178 100644 --- a/tests/codegen/sanitizer/cfi-emit-type-metadata-itanium-cxx-abi-normalized-generalized.rs +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-normalized-generalized.rs diff --git a/tests/codegen/sanitizer/cfi-emit-type-metadata-itanium-cxx-abi-normalized.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-normalized.rs index ac18379165d..ac18379165d 100644 --- a/tests/codegen/sanitizer/cfi-emit-type-metadata-itanium-cxx-abi-normalized.rs +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi-normalized.rs diff --git a/tests/codegen/sanitizer/cfi-emit-type-metadata-itanium-cxx-abi.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi.rs index 526ba62c264..526ba62c264 100644 --- a/tests/codegen/sanitizer/cfi-emit-type-metadata-itanium-cxx-abi.rs +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-itanium-cxx-abi.rs diff --git a/tests/codegen/sanitizer/cfi-emit-type-metadata-trait-objects.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-trait-objects.rs index 318aad9291c..318aad9291c 100644 --- a/tests/codegen/sanitizer/cfi-emit-type-metadata-trait-objects.rs +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-trait-objects.rs diff --git a/tests/codegen/sanitizer/cfi-generalize-pointers.rs b/tests/codegen/sanitizer/cfi/generalize-pointers.rs index eaf3dad1909..eaf3dad1909 100644 --- a/tests/codegen/sanitizer/cfi-generalize-pointers.rs +++ b/tests/codegen/sanitizer/cfi/generalize-pointers.rs diff --git a/tests/codegen/sanitizer/cfi-normalize-integers.rs b/tests/codegen/sanitizer/cfi/normalize-integers.rs index 210814eb9ae..801ed312be5 100644 --- a/tests/codegen/sanitizer/cfi-normalize-integers.rs +++ b/tests/codegen/sanitizer/cfi/normalize-integers.rs @@ -41,6 +41,6 @@ pub fn foo11(_: (), _: usize, _: usize, _: usize) { } // CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFv{{u3i16|u3i32|u3i64|u4i128}}E.normalized"} // CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFv{{u3i16|u3i32|u3i64|u4i128}}S_E.normalized"} // CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFv{{u3i16|u3i32|u3i64|u4i128}}S_S_E.normalized"} -// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvv{{u3u16|u3u32|u3u64|u4u128}}E.normalized"} -// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvv{{u3u16|u3u32|u3u64|u4u128}}S_E.normalized"} -// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvv{{u3u16|u3u32|u3u64|u4u128}}S_S_E.normalized"} +// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFv{{u3u16|u3u32|u3u64|u4u128}}E.normalized"} +// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFv{{u3u16|u3u32|u3u64|u4u128}}S_E.normalized"} +// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFv{{u3u16|u3u32|u3u64|u4u128}}S_S_E.normalized"} diff --git a/tests/codegen/sanitizer/kcfi-add-kcfi-flag.rs b/tests/codegen/sanitizer/kcfi/add-kcfi-flag.rs index 7751d3baf79..7751d3baf79 100644 --- a/tests/codegen/sanitizer/kcfi-add-kcfi-flag.rs +++ b/tests/codegen/sanitizer/kcfi/add-kcfi-flag.rs diff --git a/tests/codegen/sanitizer/kcfi-emit-kcfi-operand-bundle-attr-no-sanitize.rs b/tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-attr-no-sanitize.rs index 50e591ba06b..8055c63a2f8 100644 --- a/tests/codegen/sanitizer/kcfi-emit-kcfi-operand-bundle-attr-no-sanitize.rs +++ b/tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-attr-no-sanitize.rs @@ -20,7 +20,7 @@ impl Copy for i32 {} #[no_sanitize(kcfi)] pub fn foo(f: fn(i32) -> i32, arg: i32) -> i32 { - // CHECK-LABEL: kcfi_emit_kcfi_operand_bundle_attr_no_sanitize::foo + // CHECK-LABEL: emit_kcfi_operand_bundle_attr_no_sanitize::foo // CHECK: Function Attrs: {{.*}} // CHECK-LABEL: define{{.*}}foo{{.*}}!{{<unknown kind #36>|kcfi_type}} !{{[0-9]+}} // CHECK: start: diff --git a/tests/codegen/sanitizer/kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi-generalized.rs b/tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-generalized.rs index bd1dfc4c413..bd1dfc4c413 100644 --- a/tests/codegen/sanitizer/kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi-generalized.rs +++ b/tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-generalized.rs diff --git a/tests/codegen/sanitizer/kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi-normalized-generalized.rs b/tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized-generalized.rs index b8275f44fac..b8275f44fac 100644 --- a/tests/codegen/sanitizer/kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi-normalized-generalized.rs +++ b/tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized-generalized.rs diff --git a/tests/codegen/sanitizer/kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi-normalized.rs b/tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized.rs index cd1b0c5efb0..cd1b0c5efb0 100644 --- a/tests/codegen/sanitizer/kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi-normalized.rs +++ b/tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi-normalized.rs diff --git a/tests/codegen/sanitizer/kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi.rs b/tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi.rs index 12690577da7..12690577da7 100644 --- a/tests/codegen/sanitizer/kcfi-emit-kcfi-operand-bundle-itanium-cxx-abi.rs +++ b/tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle-itanium-cxx-abi.rs diff --git a/tests/codegen/sanitizer/kcfi-emit-kcfi-operand-bundle.rs b/tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle.rs index f4b3e48638e..f4b3e48638e 100644 --- a/tests/codegen/sanitizer/kcfi-emit-kcfi-operand-bundle.rs +++ b/tests/codegen/sanitizer/kcfi/emit-kcfi-operand-bundle.rs diff --git a/tests/codegen/sanitizer/kcfi-emit-type-metadata-trait-objects.rs b/tests/codegen/sanitizer/kcfi/emit-type-metadata-trait-objects.rs index f08c9e6702e..f08c9e6702e 100644 --- a/tests/codegen/sanitizer/kcfi-emit-type-metadata-trait-objects.rs +++ b/tests/codegen/sanitizer/kcfi/emit-type-metadata-trait-objects.rs diff --git a/tests/codegen/trailing_zeros.rs b/tests/codegen/trailing_zeros.rs index 66560c0d4fc..b659e061821 100644 --- a/tests/codegen/trailing_zeros.rs +++ b/tests/codegen/trailing_zeros.rs @@ -1,5 +1,4 @@ //@ compile-flags: -O -//@ min-llvm-version: 17 #![crate_type = "lib"] diff --git a/tests/codegen/vec-shrink-panik.rs b/tests/codegen/vec-shrink-panik.rs index 4e996b234f9..4b798fe6c9c 100644 --- a/tests/codegen/vec-shrink-panik.rs +++ b/tests/codegen/vec-shrink-panik.rs @@ -1,8 +1,5 @@ -//@ revisions: old new // LLVM 17 realizes double panic is not possible and doesn't generate calls // to panic_cannot_unwind. -//@ [old]ignore-llvm-version: 17 - 99 -//@ [new]min-llvm-version: 17 //@ compile-flags: -O //@ ignore-debug: plain old debug assertions //@ needs-unwind @@ -23,14 +20,6 @@ pub fn shrink_to_fit(vec: &mut Vec<u32>) { #[no_mangle] pub fn issue71861(vec: Vec<u32>) -> Box<[u32]> { // CHECK-NOT: panic - - // Call to panic_cannot_unwind in case of double-panic is expected - // on LLVM 16 and older, but other panics are not. - // old: filter - // old-NEXT: ; call core::panicking::panic_cannot_unwind - // old-NEXT: panic_cannot_unwind - - // CHECK-NOT: panic vec.into_boxed_slice() } @@ -40,6 +29,3 @@ pub fn issue75636<'a>(iter: &[&'a str]) -> Box<[&'a str]> { // CHECK-NOT: panic iter.iter().copied().collect() } - -// old: ; core::panicking::panic_cannot_unwind -// old: declare void @{{.*}}panic_cannot_unwind diff --git a/tests/coverage/let_else_loop.cov-map b/tests/coverage/let_else_loop.cov-map new file mode 100644 index 00000000000..b0cee300522 --- /dev/null +++ b/tests/coverage/let_else_loop.cov-map @@ -0,0 +1,30 @@ +Function name: let_else_loop::_if (unused) +Raw bytes (19): 0x[01, 01, 00, 03, 00, 16, 01, 01, 0c, 00, 02, 09, 00, 10, 00, 02, 09, 00, 10] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 3 +- Code(Zero) at (prev + 22, 1) to (start + 1, 12) +- Code(Zero) at (prev + 2, 9) to (start + 0, 16) +- Code(Zero) at (prev + 2, 9) to (start + 0, 16) + +Function name: let_else_loop::_loop_either_way (unused) +Raw bytes (19): 0x[01, 01, 00, 03, 00, 0f, 01, 01, 14, 00, 01, 1c, 00, 23, 00, 01, 05, 00, 0c] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 3 +- Code(Zero) at (prev + 15, 1) to (start + 1, 20) +- Code(Zero) at (prev + 1, 28) to (start + 0, 35) +- Code(Zero) at (prev + 1, 5) to (start + 0, 12) + +Function name: let_else_loop::loopy +Raw bytes (19): 0x[01, 01, 00, 03, 01, 09, 01, 01, 14, 00, 01, 1c, 00, 23, 05, 01, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 3 +- Code(Counter(0)) at (prev + 9, 1) to (start + 1, 20) +- Code(Zero) at (prev + 1, 28) to (start + 0, 35) +- Code(Counter(1)) at (prev + 1, 1) to (start + 0, 2) + diff --git a/tests/coverage/let_else_loop.coverage b/tests/coverage/let_else_loop.coverage new file mode 100644 index 00000000000..d193c8ca1b5 --- /dev/null +++ b/tests/coverage/let_else_loop.coverage @@ -0,0 +1,35 @@ + LL| |#![feature(coverage_attribute)] + LL| |//@ edition: 2021 + LL| | + LL| |// Regression test for <https://github.com/rust-lang/rust/issues/122738>. + LL| |// These code patterns should not trigger an ICE when allocating a physical + LL| |// counter to a node and also one of its in-edges, because that is allowed + LL| |// when the node contains a tight loop to itself. + LL| | + LL| 1|fn loopy(cond: bool) { + LL| 1| let true = cond else { loop {} }; + ^0 + LL| 1|} + LL| | + LL| |// Variant that also has `loop {}` on the success path. + LL| |// This isn't needed to catch the original ICE, but might help detect regressions. + LL| 0|fn _loop_either_way(cond: bool) { + LL| 0| let true = cond else { loop {} }; + LL| 0| loop {} + LL| |} + LL| | + LL| |// Variant using regular `if` instead of let-else. + LL| |// This doesn't trigger the original ICE, but might help detect regressions. + LL| 0|fn _if(cond: bool) { + LL| 0| if cond { + LL| 0| loop {} + LL| | } else { + LL| 0| loop {} + LL| | } + LL| |} + LL| | + LL| |#[coverage(off)] + LL| |fn main() { + LL| | loopy(true); + LL| |} + diff --git a/tests/coverage/let_else_loop.rs b/tests/coverage/let_else_loop.rs new file mode 100644 index 00000000000..12e0aeabcab --- /dev/null +++ b/tests/coverage/let_else_loop.rs @@ -0,0 +1,33 @@ +#![feature(coverage_attribute)] +//@ edition: 2021 + +// Regression test for <https://github.com/rust-lang/rust/issues/122738>. +// These code patterns should not trigger an ICE when allocating a physical +// counter to a node and also one of its in-edges, because that is allowed +// when the node contains a tight loop to itself. + +fn loopy(cond: bool) { + let true = cond else { loop {} }; +} + +// Variant that also has `loop {}` on the success path. +// This isn't needed to catch the original ICE, but might help detect regressions. +fn _loop_either_way(cond: bool) { + let true = cond else { loop {} }; + loop {} +} + +// Variant using regular `if` instead of let-else. +// This doesn't trigger the original ICE, but might help detect regressions. +fn _if(cond: bool) { + if cond { + loop {} + } else { + loop {} + } +} + +#[coverage(off)] +fn main() { + loopy(true); +} diff --git a/tests/debuginfo/associated-types.rs b/tests/debuginfo/associated-types.rs index ab41073b7c4..d1d4e320b05 100644 --- a/tests/debuginfo/associated-types.rs +++ b/tests/debuginfo/associated-types.rs @@ -42,42 +42,42 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print arg -// lldbg-check:[...]$0 = { b = -1, b1 = 0 } +// lldb-command:v arg +// lldbg-check:[...] { b = -1, b1 = 0 } // lldbr-check:(associated_types::Struct<i32>) arg = { b = -1, b1 = 0 } // lldb-command:continue -// lldb-command:print inferred -// lldbg-check:[...]$1 = 1 +// lldb-command:v inferred +// lldbg-check:[...] 1 // lldbr-check:(i64) inferred = 1 -// lldb-command:print explicitly -// lldbg-check:[...]$2 = 1 +// lldb-command:v explicitly +// lldbg-check:[...] 1 // lldbr-check:(i64) explicitly = 1 // lldb-command:continue -// lldb-command:print arg -// lldbg-check:[...]$3 = 2 +// lldb-command:v arg +// lldbg-check:[...] 2 // lldbr-check:(i64) arg = 2 // lldb-command:continue -// lldb-command:print arg -// lldbg-check:[...]$4 = (4, 5) +// lldb-command:v arg +// lldbg-check:[...] (4, 5) // lldbr-check:((i32, i64)) arg = { = 4 = 5 } // lldb-command:continue -// lldb-command:print a -// lldbg-check:[...]$5 = 6 +// lldb-command:v a +// lldbg-check:[...] 6 // lldbr-check:(i32) a = 6 -// lldb-command:print b -// lldbg-check:[...]$6 = 7 +// lldb-command:v b +// lldbg-check:[...] 7 // lldbr-check:(i64) b = 7 // lldb-command:continue -// lldb-command:print a -// lldbg-check:[...]$7 = 8 +// lldb-command:v a +// lldbg-check:[...] 8 // lldbr-check:(i64) a = 8 -// lldb-command:print b -// lldbg-check:[...]$8 = 9 +// lldb-command:v b +// lldbg-check:[...] 9 // lldbr-check:(i32) b = 9 // lldb-command:continue diff --git a/tests/debuginfo/basic-types.rs b/tests/debuginfo/basic-types.rs index 8319b71bfcd..13d85d326ee 100644 --- a/tests/debuginfo/basic-types.rs +++ b/tests/debuginfo/basic-types.rs @@ -50,49 +50,49 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print b -// lldbg-check:[...]$0 = false +// lldb-command:v b +// lldbg-check:[...] false // lldbr-check:(bool) b = false -// lldb-command:print i -// lldbg-check:[...]$1 = -1 +// lldb-command:v i +// lldbg-check:[...] -1 // lldbr-check:(isize) i = -1 // NOTE: only rust-enabled lldb supports 32bit chars // lldbr-command:print c // lldbr-check:(char) c = 'a' -// lldb-command:print i8 -// lldbg-check:[...]$2 = 'D' +// lldb-command:v i8 +// lldbg-check:[...] 'D' // lldbr-check:(i8) i8 = 68 -// lldb-command:print i16 -// lldbg-check:[...]$3 = -16 +// lldb-command:v i16 +// lldbg-check:[...] -16 // lldbr-check:(i16) i16 = -16 -// lldb-command:print i32 -// lldbg-check:[...]$4 = -32 +// lldb-command:v i32 +// lldbg-check:[...] -32 // lldbr-check:(i32) i32 = -32 -// lldb-command:print i64 -// lldbg-check:[...]$5 = -64 +// lldb-command:v i64 +// lldbg-check:[...] -64 // lldbr-check:(i64) i64 = -64 -// lldb-command:print u -// lldbg-check:[...]$6 = 1 +// lldb-command:v u +// lldbg-check:[...] 1 // lldbr-check:(usize) u = 1 -// lldb-command:print u8 -// lldbg-check:[...]$7 = 'd' +// lldb-command:v u8 +// lldbg-check:[...] 'd' // lldbr-check:(u8) u8 = 100 -// lldb-command:print u16 -// lldbg-check:[...]$8 = 16 +// lldb-command:v u16 +// lldbg-check:[...] 16 // lldbr-check:(u16) u16 = 16 -// lldb-command:print u32 -// lldbg-check:[...]$9 = 32 +// lldb-command:v u32 +// lldbg-check:[...] 32 // lldbr-check:(u32) u32 = 32 -// lldb-command:print u64 -// lldbg-check:[...]$10 = 64 +// lldb-command:v u64 +// lldbg-check:[...] 64 // lldbr-check:(u64) u64 = 64 -// lldb-command:print f32 -// lldbg-check:[...]$11 = 2.5 +// lldb-command:v f32 +// lldbg-check:[...] 2.5 // lldbr-check:(f32) f32 = 2.5 -// lldb-command:print f64 -// lldbg-check:[...]$12 = 3.5 +// lldb-command:v f64 +// lldbg-check:[...] 3.5 // lldbr-check:(f64) f64 = 3.5 // === CDB TESTS =================================================================================== diff --git a/tests/debuginfo/borrowed-basic.rs b/tests/debuginfo/borrowed-basic.rs index 52d61f33e7c..e48e3dd055e 100644 --- a/tests/debuginfo/borrowed-basic.rs +++ b/tests/debuginfo/borrowed-basic.rs @@ -52,60 +52,60 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print *bool_ref -// lldbg-check:[...]$0 = true +// lldb-command:v *bool_ref +// lldbg-check:[...] true // lldbr-check:(bool) *bool_ref = true -// lldb-command:print *int_ref -// lldbg-check:[...]$1 = -1 +// lldb-command:v *int_ref +// lldbg-check:[...] -1 // lldbr-check:(isize) *int_ref = -1 // NOTE: only rust-enabled lldb supports 32bit chars // lldbr-command:print *char_ref // lldbr-check:(char) *char_ref = 'a' -// lldb-command:print *i8_ref -// lldbg-check:[...]$2 = 'D' +// lldb-command:v *i8_ref +// lldbg-check:[...] 'D' // lldbr-check:(i8) *i8_ref = 68 -// lldb-command:print *i16_ref -// lldbg-check:[...]$3 = -16 +// lldb-command:v *i16_ref +// lldbg-check:[...] -16 // lldbr-check:(i16) *i16_ref = -16 -// lldb-command:print *i32_ref -// lldbg-check:[...]$4 = -32 +// lldb-command:v *i32_ref +// lldbg-check:[...] -32 // lldbr-check:(i32) *i32_ref = -32 -// lldb-command:print *i64_ref -// lldbg-check:[...]$5 = -64 +// lldb-command:v *i64_ref +// lldbg-check:[...] -64 // lldbr-check:(i64) *i64_ref = -64 -// lldb-command:print *uint_ref -// lldbg-check:[...]$6 = 1 +// lldb-command:v *uint_ref +// lldbg-check:[...] 1 // lldbr-check:(usize) *uint_ref = 1 -// lldb-command:print *u8_ref -// lldbg-check:[...]$7 = 'd' +// lldb-command:v *u8_ref +// lldbg-check:[...] 'd' // lldbr-check:(u8) *u8_ref = 100 -// lldb-command:print *u16_ref -// lldbg-check:[...]$8 = 16 +// lldb-command:v *u16_ref +// lldbg-check:[...] 16 // lldbr-check:(u16) *u16_ref = 16 -// lldb-command:print *u32_ref -// lldbg-check:[...]$9 = 32 +// lldb-command:v *u32_ref +// lldbg-check:[...] 32 // lldbr-check:(u32) *u32_ref = 32 -// lldb-command:print *u64_ref -// lldbg-check:[...]$10 = 64 +// lldb-command:v *u64_ref +// lldbg-check:[...] 64 // lldbr-check:(u64) *u64_ref = 64 -// lldb-command:print *f32_ref -// lldbg-check:[...]$11 = 2.5 +// lldb-command:v *f32_ref +// lldbg-check:[...] 2.5 // lldbr-check:(f32) *f32_ref = 2.5 -// lldb-command:print *f64_ref -// lldbg-check:[...]$12 = 3.5 +// lldb-command:v *f64_ref +// lldbg-check:[...] 3.5 // lldbr-check:(f64) *f64_ref = 3.5 #![allow(unused_variables)] diff --git a/tests/debuginfo/borrowed-c-style-enum.rs b/tests/debuginfo/borrowed-c-style-enum.rs index 950a05a0992..1a582e8a6d9 100644 --- a/tests/debuginfo/borrowed-c-style-enum.rs +++ b/tests/debuginfo/borrowed-c-style-enum.rs @@ -22,16 +22,16 @@ // lldb-command:run -// lldb-command:print *the_a_ref -// lldbg-check:[...]$0 = TheA +// lldb-command:v *the_a_ref +// lldbg-check:[...] TheA // lldbr-check:(borrowed_c_style_enum::ABC) *the_a_ref = borrowed_c_style_enum::ABC::TheA -// lldb-command:print *the_b_ref -// lldbg-check:[...]$1 = TheB +// lldb-command:v *the_b_ref +// lldbg-check:[...] TheB // lldbr-check:(borrowed_c_style_enum::ABC) *the_b_ref = borrowed_c_style_enum::ABC::TheB -// lldb-command:print *the_c_ref -// lldbg-check:[...]$2 = TheC +// lldb-command:v *the_c_ref +// lldbg-check:[...] TheC // lldbr-check:(borrowed_c_style_enum::ABC) *the_c_ref = borrowed_c_style_enum::ABC::TheC #![allow(unused_variables)] diff --git a/tests/debuginfo/borrowed-enum.rs b/tests/debuginfo/borrowed-enum.rs index aee4631a8b3..39883ffd0b6 100644 --- a/tests/debuginfo/borrowed-enum.rs +++ b/tests/debuginfo/borrowed-enum.rs @@ -22,11 +22,11 @@ // lldb-command:run -// lldb-command:print *the_a_ref +// lldb-command:v *the_a_ref // lldbr-check:(borrowed_enum::ABC::TheA) *the_a_ref = TheA { TheA: 0, TheB: 8970181431921507452 } -// lldb-command:print *the_b_ref +// lldb-command:v *the_b_ref // lldbr-check:(borrowed_enum::ABC::TheB) *the_b_ref = { = 0 = 286331153 = 286331153 } -// lldb-command:print *univariant_ref +// lldb-command:v *univariant_ref // lldbr-check:(borrowed_enum::Univariant) *univariant_ref = { TheOnlyCase = { = 4820353753753434 } } #![allow(unused_variables)] diff --git a/tests/debuginfo/borrowed-struct.rs b/tests/debuginfo/borrowed-struct.rs index 467de7878ee..d108a29592b 100644 --- a/tests/debuginfo/borrowed-struct.rs +++ b/tests/debuginfo/borrowed-struct.rs @@ -34,32 +34,32 @@ // lldb-command:run -// lldb-command:print *stack_val_ref -// lldbg-check:[...]$0 = { x = 10 y = 23.5 } +// lldb-command:v *stack_val_ref +// lldbg-check:[...] { x = 10 y = 23.5 } // lldbr-check:(borrowed_struct::SomeStruct) *stack_val_ref = (x = 10, y = 23.5) -// lldb-command:print *stack_val_interior_ref_1 -// lldbg-check:[...]$1 = 10 +// lldb-command:v *stack_val_interior_ref_1 +// lldbg-check:[...] 10 // lldbr-check:(isize) *stack_val_interior_ref_1 = 10 -// lldb-command:print *stack_val_interior_ref_2 -// lldbg-check:[...]$2 = 23.5 +// lldb-command:v *stack_val_interior_ref_2 +// lldbg-check:[...] 23.5 // lldbr-check:(f64) *stack_val_interior_ref_2 = 23.5 -// lldb-command:print *ref_to_unnamed -// lldbg-check:[...]$3 = { x = 11 y = 24.5 } +// lldb-command:v *ref_to_unnamed +// lldbg-check:[...] { x = 11 y = 24.5 } // lldbr-check:(borrowed_struct::SomeStruct) *ref_to_unnamed = (x = 11, y = 24.5) -// lldb-command:print *unique_val_ref -// lldbg-check:[...]$4 = { x = 13 y = 26.5 } +// lldb-command:v *unique_val_ref +// lldbg-check:[...] { x = 13 y = 26.5 } // lldbr-check:(borrowed_struct::SomeStruct) *unique_val_ref = (x = 13, y = 26.5) -// lldb-command:print *unique_val_interior_ref_1 -// lldbg-check:[...]$5 = 13 +// lldb-command:v *unique_val_interior_ref_1 +// lldbg-check:[...] 13 // lldbr-check:(isize) *unique_val_interior_ref_1 = 13 -// lldb-command:print *unique_val_interior_ref_2 -// lldbg-check:[...]$6 = 26.5 +// lldb-command:v *unique_val_interior_ref_2 +// lldbg-check:[...] 26.5 // lldbr-check:(f64) *unique_val_interior_ref_2 = 26.5 #![allow(unused_variables)] diff --git a/tests/debuginfo/borrowed-tuple.rs b/tests/debuginfo/borrowed-tuple.rs index 4fe1abbaba2..4c5643deb9d 100644 --- a/tests/debuginfo/borrowed-tuple.rs +++ b/tests/debuginfo/borrowed-tuple.rs @@ -23,16 +23,16 @@ // lldb-command:run -// lldb-command:print *stack_val_ref -// lldbg-check:[...]$0 = { 0 = -14 1 = -19 } +// lldb-command:v *stack_val_ref +// lldbg-check:[...] { 0 = -14 1 = -19 } // lldbr-check:((i16, f32)) *stack_val_ref = { 0 = -14 1 = -19 } -// lldb-command:print *ref_to_unnamed -// lldbg-check:[...]$1 = { 0 = -15 1 = -20 } +// lldb-command:v *ref_to_unnamed +// lldbg-check:[...] { 0 = -15 1 = -20 } // lldbr-check:((i16, f32)) *ref_to_unnamed = { 0 = -15 1 = -20 } -// lldb-command:print *unique_val_ref -// lldbg-check:[...]$2 = { 0 = -17 1 = -22 } +// lldb-command:v *unique_val_ref +// lldbg-check:[...] { 0 = -17 1 = -22 } // lldbr-check:((i16, f32)) *unique_val_ref = { 0 = -17 1 = -22 } diff --git a/tests/debuginfo/borrowed-unique-basic.rs b/tests/debuginfo/borrowed-unique-basic.rs index ae843c355bc..d6948a12851 100644 --- a/tests/debuginfo/borrowed-unique-basic.rs +++ b/tests/debuginfo/borrowed-unique-basic.rs @@ -55,60 +55,60 @@ // lldb-command:type format add -f decimal 'unsigned char' // lldb-command:run -// lldb-command:print *bool_ref -// lldbg-check:[...]$0 = true +// lldb-command:v *bool_ref +// lldbg-check:[...] true // lldbr-check:(bool) *bool_ref = true -// lldb-command:print *int_ref -// lldbg-check:[...]$1 = -1 +// lldb-command:v *int_ref +// lldbg-check:[...] -1 // lldbr-check:(isize) *int_ref = -1 // NOTE: only rust-enabled lldb supports 32bit chars // lldbr-command:print *char_ref // lldbr-check:(char) *char_ref = 97 -// lldb-command:print *i8_ref -// lldbg-check:[...]$2 = 68 +// lldb-command:v *i8_ref +// lldbg-check:[...] 68 // lldbr-check:(i8) *i8_ref = 68 -// lldb-command:print *i16_ref -// lldbg-check:[...]$3 = -16 +// lldb-command:v *i16_ref +// lldbg-check:[...] -16 // lldbr-check:(i16) *i16_ref = -16 -// lldb-command:print *i32_ref -// lldbg-check:[...]$4 = -32 +// lldb-command:v *i32_ref +// lldbg-check:[...] -32 // lldbr-check:(i32) *i32_ref = -32 -// lldb-command:print *i64_ref -// lldbg-check:[...]$5 = -64 +// lldb-command:v *i64_ref +// lldbg-check:[...] -64 // lldbr-check:(i64) *i64_ref = -64 -// lldb-command:print *uint_ref -// lldbg-check:[...]$6 = 1 +// lldb-command:v *uint_ref +// lldbg-check:[...] 1 // lldbr-check:(usize) *uint_ref = 1 -// lldb-command:print *u8_ref -// lldbg-check:[...]$7 = 100 +// lldb-command:v *u8_ref +// lldbg-check:[...] 100 // lldbr-check:(u8) *u8_ref = 100 -// lldb-command:print *u16_ref -// lldbg-check:[...]$8 = 16 +// lldb-command:v *u16_ref +// lldbg-check:[...] 16 // lldbr-check:(u16) *u16_ref = 16 -// lldb-command:print *u32_ref -// lldbg-check:[...]$9 = 32 +// lldb-command:v *u32_ref +// lldbg-check:[...] 32 // lldbr-check:(u32) *u32_ref = 32 -// lldb-command:print *u64_ref -// lldbg-check:[...]$10 = 64 +// lldb-command:v *u64_ref +// lldbg-check:[...] 64 // lldbr-check:(u64) *u64_ref = 64 -// lldb-command:print *f32_ref -// lldbg-check:[...]$11 = 2.5 +// lldb-command:v *f32_ref +// lldbg-check:[...] 2.5 // lldbr-check:(f32) *f32_ref = 2.5 -// lldb-command:print *f64_ref -// lldbg-check:[...]$12 = 3.5 +// lldb-command:v *f64_ref +// lldbg-check:[...] 3.5 // lldbr-check:(f64) *f64_ref = 3.5 #![allow(unused_variables)] diff --git a/tests/debuginfo/box.rs b/tests/debuginfo/box.rs index f2e744e87b9..46019bcb1a7 100644 --- a/tests/debuginfo/box.rs +++ b/tests/debuginfo/box.rs @@ -16,11 +16,11 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print *a -// lldbg-check:[...]$0 = 1 +// lldb-command:v *a +// lldbg-check:[...] 1 // lldbr-check:(i32) *a = 1 -// lldb-command:print *b -// lldbg-check:[...]$1 = { 0 = 2 1 = 3.5 } +// lldb-command:v *b +// lldbg-check:[...] { 0 = 2 1 = 3.5 } // lldbr-check:((i32, f64)) *b = { 0 = 2 1 = 3.5 } #![allow(unused_variables)] diff --git a/tests/debuginfo/boxed-struct.rs b/tests/debuginfo/boxed-struct.rs index c47bffb3a38..1ee639690ea 100644 --- a/tests/debuginfo/boxed-struct.rs +++ b/tests/debuginfo/boxed-struct.rs @@ -19,12 +19,12 @@ // lldb-command:run -// lldb-command:print *boxed_with_padding -// lldbg-check:[...]$0 = { x = 99 y = 999 z = 9999 w = 99999 } +// lldb-command:v *boxed_with_padding +// lldbg-check:[...] { x = 99 y = 999 z = 9999 w = 99999 } // lldbr-check:(boxed_struct::StructWithSomePadding) *boxed_with_padding = { x = 99 y = 999 z = 9999 w = 99999 } -// lldb-command:print *boxed_with_dtor -// lldbg-check:[...]$1 = { x = 77 y = 777 z = 7777 w = 77777 } +// lldb-command:v *boxed_with_dtor +// lldbg-check:[...] { x = 77 y = 777 z = 7777 w = 77777 } // lldbr-check:(boxed_struct::StructWithDestructor) *boxed_with_dtor = { x = 77 y = 777 z = 7777 w = 77777 } #![allow(unused_variables)] diff --git a/tests/debuginfo/by-value-non-immediate-argument.rs b/tests/debuginfo/by-value-non-immediate-argument.rs index 52e3dc9a76b..e0ae4458d03 100644 --- a/tests/debuginfo/by-value-non-immediate-argument.rs +++ b/tests/debuginfo/by-value-non-immediate-argument.rs @@ -41,28 +41,28 @@ // lldb-command:run -// lldb-command:print s -// lldb-check:[...]$0 = Struct { a: 1, b: 2.5 } +// lldb-command:v s +// lldb-check:[...] Struct { a: 1, b: 2.5 } // lldb-command:continue -// lldb-command:print x -// lldb-check:[...]$1 = Struct { a: 3, b: 4.5 } -// lldb-command:print y -// lldb-check:[...]$2 = 5 -// lldb-command:print z -// lldb-check:[...]$3 = 6.5 +// lldb-command:v x +// lldb-check:[...] Struct { a: 3, b: 4.5 } +// lldb-command:v y +// lldb-check:[...] 5 +// lldb-command:v z +// lldb-check:[...] 6.5 // lldb-command:continue -// lldb-command:print a -// lldb-check:[...]$4 = (7, 8, 9.5, 10.5) +// lldb-command:v a +// lldb-check:[...] (7, 8, 9.5, 10.5) // lldb-command:continue -// lldb-command:print a -// lldb-check:[...]$5 = Newtype(11.5, 12.5, 13, 14) +// lldb-command:v a +// lldb-check:[...] Newtype(11.5, 12.5, 13, 14) // lldb-command:continue -// lldb-command:print x -// lldb-check:[...]$6 = Case1 { x: 0, y: 8970181431921507452 } +// lldb-command:v x +// lldb-check:[...] Case1 { x: 0, y: 8970181431921507452 } // lldb-command:continue #![feature(omit_gdb_pretty_printer_section)] diff --git a/tests/debuginfo/by-value-self-argument-in-trait-impl.rs b/tests/debuginfo/by-value-self-argument-in-trait-impl.rs index 247d6c27a06..5276ec82733 100644 --- a/tests/debuginfo/by-value-self-argument-in-trait-impl.rs +++ b/tests/debuginfo/by-value-self-argument-in-trait-impl.rs @@ -25,18 +25,18 @@ // lldb-command:run -// lldb-command:print self -// lldbg-check:[...]$0 = 1111 +// lldb-command:v self +// lldbg-check:[...] 1111 // lldbr-check:(isize) self = 1111 // lldb-command:continue -// lldb-command:print self -// lldbg-check:[...]$1 = { x = 2222 y = 3333 } +// lldb-command:v self +// lldbg-check:[...] { x = 2222 y = 3333 } // lldbr-check:(by_value_self_argument_in_trait_impl::Struct) self = { x = 2222 y = 3333 } // lldb-command:continue -// lldb-command:print self -// lldbg-check:[...] $2 = { 0 = 4444.5 1 = 5555 2 = 6666 3 = 7777.5 } +// lldb-command:v self +// lldbg-check:[...] { 0 = 4444.5 1 = 5555 2 = 6666 3 = 7777.5 } // lldbr-check:((f64, isize, isize, f64)) self = { 0 = 4444.5 1 = 5555 2 = 6666 3 = 7777.5 } // lldb-command:continue diff --git a/tests/debuginfo/c-style-enum-in-composite.rs b/tests/debuginfo/c-style-enum-in-composite.rs index 3f0968f09af..ec11d5f4655 100644 --- a/tests/debuginfo/c-style-enum-in-composite.rs +++ b/tests/debuginfo/c-style-enum-in-composite.rs @@ -38,32 +38,32 @@ // lldb-command:run -// lldb-command:print tuple_interior_padding -// lldbg-check:[...]$0 = { 0 = 0 1 = OneHundred } +// lldb-command:v tuple_interior_padding +// lldbg-check:[...] { 0 = 0 1 = OneHundred } // lldbr-check:((i16, c_style_enum_in_composite::AnEnum)) tuple_interior_padding = { 0 = 0 1 = OneHundred } -// lldb-command:print tuple_padding_at_end -// lldbg-check:[...]$1 = { 0 = { 0 = 1 1 = OneThousand } 1 = 2 } +// lldb-command:v tuple_padding_at_end +// lldbg-check:[...] { 0 = { 0 = 1 1 = OneThousand } 1 = 2 } // lldbr-check:(((u64, c_style_enum_in_composite::AnEnum), u64)) tuple_padding_at_end = { 0 = { 0 = 1 1 = OneThousand } 1 = 2 } -// lldb-command:print tuple_different_enums -// lldbg-check:[...]$2 = { 0 = OneThousand 1 = MountainView 2 = OneMillion 3 = Vienna } +// lldb-command:v tuple_different_enums +// lldbg-check:[...] { 0 = OneThousand 1 = MountainView 2 = OneMillion 3 = Vienna } // lldbr-check:((c_style_enum_in_composite::AnEnum, c_style_enum_in_composite::AnotherEnum, c_style_enum_in_composite::AnEnum, c_style_enum_in_composite::AnotherEnum)) tuple_different_enums = { 0 = c_style_enum_in_composite::AnEnum::OneThousand 1 = c_style_enum_in_composite::AnotherEnum::MountainView 2 = c_style_enum_in_composite::AnEnum::OneMillion 3 = c_style_enum_in_composite::AnotherEnum::Vienna } -// lldb-command:print padded_struct -// lldbg-check:[...]$3 = { a = 3 b = OneMillion c = 4 d = Toronto e = 5 } +// lldb-command:v padded_struct +// lldbg-check:[...] { a = 3 b = OneMillion c = 4 d = Toronto e = 5 } // lldbr-check:(c_style_enum_in_composite::PaddedStruct) padded_struct = { a = 3 b = c_style_enum_in_composite::AnEnum::OneMillion c = 4 d = Toronto e = 5 } -// lldb-command:print packed_struct -// lldbg-check:[...]$4 = { a = 6 b = OneHundred c = 7 d = Vienna e = 8 } +// lldb-command:v packed_struct +// lldbg-check:[...] { a = 6 b = OneHundred c = 7 d = Vienna e = 8 } // lldbr-check:(c_style_enum_in_composite::PackedStruct) packed_struct = { a = 6 b = c_style_enum_in_composite::AnEnum::OneHundred c = 7 d = Vienna e = 8 } -// lldb-command:print non_padded_struct -// lldbg-check:[...]$5 = { a = OneMillion b = MountainView c = OneThousand d = Toronto } +// lldb-command:v non_padded_struct +// lldbg-check:[...] { a = OneMillion b = MountainView c = OneThousand d = Toronto } // lldbr-check:(c_style_enum_in_composite::NonPaddedStruct) non_padded_struct = { a = c_style_enum_in_composite::AnEnum::OneMillion, b = c_style_enum_in_composite::AnotherEnum::MountainView, c = c_style_enum_in_composite::AnEnum::OneThousand, d = c_style_enum_in_composite::AnotherEnum::Toronto } -// lldb-command:print struct_with_drop -// lldbg-check:[...]$6 = { 0 = { a = OneHundred b = Vienna } 1 = 9 } +// lldb-command:v struct_with_drop +// lldbg-check:[...] { 0 = { a = OneHundred b = Vienna } 1 = 9 } // lldbr-check:((c_style_enum_in_composite::StructWithDrop, i64)) struct_with_drop = { 0 = { a = c_style_enum_in_composite::AnEnum::OneHundred b = c_style_enum_in_composite::AnotherEnum::Vienna } 1 = 9 } #![allow(unused_variables)] diff --git a/tests/debuginfo/c-style-enum.rs b/tests/debuginfo/c-style-enum.rs index 2794575d328..395b94c59a4 100644 --- a/tests/debuginfo/c-style-enum.rs +++ b/tests/debuginfo/c-style-enum.rs @@ -96,32 +96,32 @@ // lldb-command:run -// lldb-command:print auto_one -// lldbg-check:[...]$0 = One +// lldb-command:v auto_one +// lldbg-check:[...] One // lldbr-check:(c_style_enum::AutoDiscriminant) auto_one = c_style_enum::AutoDiscriminant::One -// lldb-command:print auto_two -// lldbg-check:[...]$1 = Two +// lldb-command:v auto_two +// lldbg-check:[...] Two // lldbr-check:(c_style_enum::AutoDiscriminant) auto_two = c_style_enum::AutoDiscriminant::Two -// lldb-command:print auto_three -// lldbg-check:[...]$2 = Three +// lldb-command:v auto_three +// lldbg-check:[...] Three // lldbr-check:(c_style_enum::AutoDiscriminant) auto_three = c_style_enum::AutoDiscriminant::Three -// lldb-command:print manual_one_hundred -// lldbg-check:[...]$3 = OneHundred +// lldb-command:v manual_one_hundred +// lldbg-check:[...] OneHundred // lldbr-check:(c_style_enum::ManualDiscriminant) manual_one_hundred = c_style_enum::ManualDiscriminant::OneHundred -// lldb-command:print manual_one_thousand -// lldbg-check:[...]$4 = OneThousand +// lldb-command:v manual_one_thousand +// lldbg-check:[...] OneThousand // lldbr-check:(c_style_enum::ManualDiscriminant) manual_one_thousand = c_style_enum::ManualDiscriminant::OneThousand -// lldb-command:print manual_one_million -// lldbg-check:[...]$5 = OneMillion +// lldb-command:v manual_one_million +// lldbg-check:[...] OneMillion // lldbr-check:(c_style_enum::ManualDiscriminant) manual_one_million = c_style_enum::ManualDiscriminant::OneMillion -// lldb-command:print single_variant -// lldbg-check:[...]$6 = TheOnlyVariant +// lldb-command:v single_variant +// lldbg-check:[...] TheOnlyVariant // lldbr-check:(c_style_enum::SingleVariant) single_variant = c_style_enum::SingleVariant::TheOnlyVariant #![allow(unused_variables)] diff --git a/tests/debuginfo/captured-fields-1.rs b/tests/debuginfo/captured-fields-1.rs index f5fdf4fb3d9..d96f2590570 100644 --- a/tests/debuginfo/captured-fields-1.rs +++ b/tests/debuginfo/captured-fields-1.rs @@ -25,23 +25,23 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print test -// lldbg-check:(captured_fields_1::main::{closure_env#0}) $0 = { _ref__my_ref__my_field1 = 0x[...] } +// lldb-command:v test +// lldbg-check:(captured_fields_1::main::{closure_env#0}) test = { _ref__my_ref__my_field1 = 0x[...] } // lldb-command:continue -// lldb-command:print test -// lldbg-check:(captured_fields_1::main::{closure_env#1}) $1 = { _ref__my_ref__my_field2 = 0x[...] } +// lldb-command:v test +// lldbg-check:(captured_fields_1::main::{closure_env#1}) test = { _ref__my_ref__my_field2 = 0x[...] } // lldb-command:continue -// lldb-command:print test -// lldbg-check:(captured_fields_1::main::{closure_env#2}) $2 = { _ref__my_ref = 0x[...] } +// lldb-command:v test +// lldbg-check:(captured_fields_1::main::{closure_env#2}) test = { _ref__my_ref = 0x[...] } // lldb-command:continue -// lldb-command:print test -// lldbg-check:(captured_fields_1::main::{closure_env#3}) $3 = { my_ref = 0x[...] } +// lldb-command:v test +// lldbg-check:(captured_fields_1::main::{closure_env#3}) test = { my_ref = 0x[...] } // lldb-command:continue -// lldb-command:print test -// lldbg-check:(captured_fields_1::main::{closure_env#4}) $4 = { my_var__my_field2 = 22 } +// lldb-command:v test +// lldbg-check:(captured_fields_1::main::{closure_env#4}) test = { my_var__my_field2 = 22 } // lldb-command:continue -// lldb-command:print test -// lldbg-check:(captured_fields_1::main::{closure_env#5}) $5 = { my_var = { my_field1 = 11 my_field2 = 22 } } +// lldb-command:v test +// lldbg-check:(captured_fields_1::main::{closure_env#5}) test = { my_var = { my_field1 = 11 my_field2 = 22 } } // lldb-command:continue #![allow(unused)] diff --git a/tests/debuginfo/captured-fields-2.rs b/tests/debuginfo/captured-fields-2.rs index aaf4fa1bc45..446c5c70fef 100644 --- a/tests/debuginfo/captured-fields-2.rs +++ b/tests/debuginfo/captured-fields-2.rs @@ -13,11 +13,11 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print my_ref__my_field1 -// lldbg-check:(unsigned int) $0 = 11 +// lldb-command:v my_ref__my_field1 +// lldbg-check:(unsigned int) my_ref__my_field1 = 11 // lldb-command:continue -// lldb-command:print my_var__my_field2 -// lldbg-check:(unsigned int) $1 = 22 +// lldb-command:v my_var__my_field2 +// lldbg-check:(unsigned int) my_var__my_field2 = 22 // lldb-command:continue #![allow(unused)] diff --git a/tests/debuginfo/closure-in-generic-function.rs b/tests/debuginfo/closure-in-generic-function.rs index 676a624191c..ef0f2b0b464 100644 --- a/tests/debuginfo/closure-in-generic-function.rs +++ b/tests/debuginfo/closure-in-generic-function.rs @@ -23,19 +23,19 @@ // lldb-command:run -// lldb-command:print x -// lldbg-check:[...]$0 = 0.5 +// lldb-command:v x +// lldbg-check:[...] 0.5 // lldbr-check:(f64) x = 0.5 -// lldb-command:print y -// lldbg-check:[...]$1 = 10 +// lldb-command:v y +// lldbg-check:[...] 10 // lldbr-check:(i32) y = 10 // lldb-command:continue -// lldb-command:print *x -// lldbg-check:[...]$2 = 29 +// lldb-command:v *x +// lldbg-check:[...] 29 // lldbr-check:(i32) *x = 29 -// lldb-command:print *y -// lldbg-check:[...]$3 = 110 +// lldb-command:v *y +// lldbg-check:[...] 110 // lldbr-check:(i32) *y = 110 // lldb-command:continue diff --git a/tests/debuginfo/coroutine-locals.rs b/tests/debuginfo/coroutine-locals.rs index 0430e1d313b..54b5cd577c8 100644 --- a/tests/debuginfo/coroutine-locals.rs +++ b/tests/debuginfo/coroutine-locals.rs @@ -27,32 +27,24 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print a -// lldbg-check:(int) $0 = 5 -// lldbr-check:(int) a = 5 -// lldb-command:print c -// lldbg-check:(int) $1 = 6 -// lldbr-check:(int) c = 6 -// lldb-command:print d -// lldbg-check:(int) $2 = 7 -// lldbr-check:(int) d = 7 +// lldb-command:v a +// lldb-check:(int) a = 5 +// lldb-command:v c +// lldb-check:(int) c = 6 +// lldb-command:v d +// lldb-check:(int) d = 7 // lldb-command:continue -// lldb-command:print a -// lldbg-check:(int) $3 = 7 -// lldbr-check:(int) a = 7 -// lldb-command:print c -// lldbg-check:(int) $4 = 6 -// lldbr-check:(int) c = 6 -// lldb-command:print e -// lldbg-check:(int) $5 = 8 -// lldbr-check:(int) e = 8 +// lldb-command:v a +// lldb-check:(int) a = 7 +// lldb-command:v c +// lldb-check:(int) c = 6 +// lldb-command:v e +// lldb-check:(int) e = 8 // lldb-command:continue -// lldb-command:print a -// lldbg-check:(int) $6 = 8 -// lldbr-check:(int) a = 8 -// lldb-command:print c -// lldbg-check:(int) $7 = 6 -// lldbr-check:(int) c = 6 +// lldb-command:v a +// lldb-check:(int) a = 8 +// lldb-command:v c +// lldb-check:(int) c = 6 #![feature(omit_gdb_pretty_printer_section, coroutines, coroutine_trait)] #![omit_gdb_pretty_printer_section] diff --git a/tests/debuginfo/coroutine-objects.rs b/tests/debuginfo/coroutine-objects.rs index 98b37ac2001..9e1bd5d62e7 100644 --- a/tests/debuginfo/coroutine-objects.rs +++ b/tests/debuginfo/coroutine-objects.rs @@ -25,17 +25,17 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print b -// lldbg-check:(coroutine_objects::main::{coroutine_env#0}) $0 = +// lldb-command:v b +// lldbg-check:(coroutine_objects::main::{coroutine_env#0}) b = // lldb-command:continue -// lldb-command:print b -// lldbg-check:(coroutine_objects::main::{coroutine_env#0}) $1 = +// lldb-command:v b +// lldbg-check:(coroutine_objects::main::{coroutine_env#0}) b = // lldb-command:continue -// lldb-command:print b -// lldbg-check:(coroutine_objects::main::{coroutine_env#0}) $2 = +// lldb-command:v b +// lldbg-check:(coroutine_objects::main::{coroutine_env#0}) b = // lldb-command:continue -// lldb-command:print b -// lldbg-check:(coroutine_objects::main::{coroutine_env#0}) $3 = +// lldb-command:v b +// lldbg-check:(coroutine_objects::main::{coroutine_env#0}) b = // === CDB TESTS =================================================================================== diff --git a/tests/debuginfo/cross-crate-spans.rs b/tests/debuginfo/cross-crate-spans.rs index 75550e1794c..cf3f8e1eadf 100644 --- a/tests/debuginfo/cross-crate-spans.rs +++ b/tests/debuginfo/cross-crate-spans.rs @@ -43,25 +43,25 @@ extern crate cross_crate_spans; // lldb-command:b cross_crate_spans.rs:14 // lldb-command:run -// lldb-command:print result -// lldbg-check:[...]$0 = { 0 = 17 1 = 17 } +// lldb-command:v result +// lldbg-check:[...] { 0 = 17 1 = 17 } // lldbr-check:((u32, u32)) result = { 0 = 17 1 = 17 } -// lldb-command:print a_variable -// lldbg-check:[...]$1 = 123456789 +// lldb-command:v a_variable +// lldbg-check:[...] 123456789 // lldbr-check:(u32) a_variable = 123456789 -// lldb-command:print another_variable -// lldbg-check:[...]$2 = 123456789.5 +// lldb-command:v another_variable +// lldbg-check:[...] 123456789.5 // lldbr-check:(f64) another_variable = 123456789.5 // lldb-command:continue -// lldb-command:print result -// lldbg-check:[...]$3 = { 0 = 1212 1 = 1212 } +// lldb-command:v result +// lldbg-check:[...] { 0 = 1212 1 = 1212 } // lldbr-check:((i16, i16)) result = { 0 = 1212 1 = 1212 } -// lldb-command:print a_variable -// lldbg-check:[...]$4 = 123456789 +// lldb-command:v a_variable +// lldbg-check:[...] 123456789 // lldbr-check:(u32) a_variable = 123456789 -// lldb-command:print another_variable -// lldbg-check:[...]$5 = 123456789.5 +// lldb-command:v another_variable +// lldbg-check:[...] 123456789.5 // lldbr-check:(f64) another_variable = 123456789.5 // lldb-command:continue diff --git a/tests/debuginfo/destructured-fn-argument.rs b/tests/debuginfo/destructured-fn-argument.rs index e6e697c518a..74e18a594d7 100644 --- a/tests/debuginfo/destructured-fn-argument.rs +++ b/tests/debuginfo/destructured-fn-argument.rs @@ -163,196 +163,196 @@ // lldb-command:run -// lldb-command:print a -// lldbg-check:[...]$0 = 1 +// lldb-command:v a +// lldbg-check:[...] 1 // lldbr-check:(isize) a = 1 -// lldb-command:print b -// lldbg-check:[...]$1 = false +// lldb-command:v b +// lldbg-check:[...] false // lldbr-check:(bool) b = false // lldb-command:continue -// lldb-command:print a -// lldbg-check:[...]$2 = 2 +// lldb-command:v a +// lldbg-check:[...] 2 // lldbr-check:(isize) a = 2 -// lldb-command:print b -// lldbg-check:[...]$3 = 3 +// lldb-command:v b +// lldbg-check:[...] 3 // lldbr-check:(u16) b = 3 -// lldb-command:print c -// lldbg-check:[...]$4 = 4 +// lldb-command:v c +// lldbg-check:[...] 4 // lldbr-check:(u16) c = 4 // lldb-command:continue -// lldb-command:print a -// lldbg-check:[...]$5 = 5 +// lldb-command:v a +// lldbg-check:[...] 5 // lldbr-check:(isize) a = 5 -// lldb-command:print b -// lldbg-check:[...]$6 = { 0 = 6 1 = 7 } +// lldb-command:v b +// lldbg-check:[...] { 0 = 6 1 = 7 } // lldbr-check:((u32, u32)) b = { 0 = 6 1 = 7 } // lldb-command:continue -// lldb-command:print h -// lldbg-check:[...]$7 = 8 +// lldb-command:v h +// lldbg-check:[...] 8 // lldbr-check:(i16) h = 8 -// lldb-command:print i -// lldbg-check:[...]$8 = { a = 9 b = 10 } +// lldb-command:v i +// lldbg-check:[...] { a = 9 b = 10 } // lldbr-check:(destructured_fn_argument::Struct) i = { a = 9 b = 10 } -// lldb-command:print j -// lldbg-check:[...]$9 = 11 +// lldb-command:v j +// lldbg-check:[...] 11 // lldbr-check:(i16) j = 11 // lldb-command:continue -// lldb-command:print k -// lldbg-check:[...]$10 = 12 +// lldb-command:v k +// lldbg-check:[...] 12 // lldbr-check:(i64) k = 12 -// lldb-command:print l -// lldbg-check:[...]$11 = 13 +// lldb-command:v l +// lldbg-check:[...] 13 // lldbr-check:(i32) l = 13 // lldb-command:continue -// lldb-command:print m -// lldbg-check:[...]$12 = 14 +// lldb-command:v m +// lldbg-check:[...] 14 // lldbr-check:(isize) m = 14 -// lldb-command:print n -// lldbg-check:[...]$13 = 16 +// lldb-command:v n +// lldbg-check:[...] 16 // lldbr-check:(i32) n = 16 // lldb-command:continue -// lldb-command:print o -// lldbg-check:[...]$14 = 18 +// lldb-command:v o +// lldbg-check:[...] 18 // lldbr-check:(i32) o = 18 // lldb-command:continue -// lldb-command:print p -// lldbg-check:[...]$15 = 19 +// lldb-command:v p +// lldbg-check:[...] 19 // lldbr-check:(i64) p = 19 -// lldb-command:print q -// lldbg-check:[...]$16 = 20 +// lldb-command:v q +// lldbg-check:[...] 20 // lldbr-check:(i32) q = 20 -// lldb-command:print r -// lldbg-check:[...]$17 = { a = 21 b = 22 } +// lldb-command:v r +// lldbg-check:[...] { a = 21 b = 22 } // lldbr-check:(destructured_fn_argument::Struct) r = { a = 21, b = 22 } // lldb-command:continue -// lldb-command:print s -// lldbg-check:[...]$18 = 24 +// lldb-command:v s +// lldbg-check:[...] 24 // lldbr-check:(i32) s = 24 -// lldb-command:print t -// lldbg-check:[...]$19 = 23 +// lldb-command:v t +// lldbg-check:[...] 23 // lldbr-check:(i64) t = 23 // lldb-command:continue -// lldb-command:print u -// lldbg-check:[...]$20 = 25 +// lldb-command:v u +// lldbg-check:[...] 25 // lldbr-check:(i16) u = 25 -// lldb-command:print v -// lldbg-check:[...]$21 = 26 +// lldb-command:v v +// lldbg-check:[...] 26 // lldbr-check:(i32) v = 26 -// lldb-command:print w -// lldbg-check:[...]$22 = 27 +// lldb-command:v w +// lldbg-check:[...] 27 // lldbr-check:(i64) w = 27 -// lldb-command:print x -// lldbg-check:[...]$23 = 28 +// lldb-command:v x +// lldbg-check:[...] 28 // lldbr-check:(i32) x = 28 -// lldb-command:print y -// lldbg-check:[...]$24 = 29 +// lldb-command:v y +// lldbg-check:[...] 29 // lldbr-check:(i64) y = 29 -// lldb-command:print z -// lldbg-check:[...]$25 = 30 +// lldb-command:v z +// lldbg-check:[...] 30 // lldbr-check:(i32) z = 30 -// lldb-command:print ae -// lldbg-check:[...]$26 = 31 +// lldb-command:v ae +// lldbg-check:[...] 31 // lldbr-check:(i64) ae = 31 -// lldb-command:print oe -// lldbg-check:[...]$27 = 32 +// lldb-command:v oe +// lldbg-check:[...] 32 // lldbr-check:(i32) oe = 32 -// lldb-command:print ue -// lldbg-check:[...]$28 = 33 +// lldb-command:v ue +// lldbg-check:[...] 33 // lldbr-check:(u16) ue = 33 // lldb-command:continue -// lldb-command:print aa -// lldbg-check:[...]$29 = { 0 = 34 1 = 35 } +// lldb-command:v aa +// lldbg-check:[...] { 0 = 34 1 = 35 } // lldbr-check:((isize, isize)) aa = { 0 = 34 1 = 35 } // lldb-command:continue -// lldb-command:print bb -// lldbg-check:[...]$30 = { 0 = 36 1 = 37 } +// lldb-command:v bb +// lldbg-check:[...] { 0 = 36 1 = 37 } // lldbr-check:((isize, isize)) bb = { 0 = 36 1 = 37 } // lldb-command:continue -// lldb-command:print cc -// lldbg-check:[...]$31 = 38 +// lldb-command:v cc +// lldbg-check:[...] 38 // lldbr-check:(isize) cc = 38 // lldb-command:continue -// lldb-command:print dd -// lldbg-check:[...]$32 = { 0 = 40 1 = 41 2 = 42 } +// lldb-command:v dd +// lldbg-check:[...] { 0 = 40 1 = 41 2 = 42 } // lldbr-check:((isize, isize, isize)) dd = { 0 = 40 1 = 41 2 = 42 } // lldb-command:continue -// lldb-command:print *ee -// lldbg-check:[...]$33 = { 0 = 43 1 = 44 2 = 45 } +// lldb-command:v *ee +// lldbg-check:[...] { 0 = 43 1 = 44 2 = 45 } // lldbr-check:((isize, isize, isize)) *ee = { 0 = 43 1 = 44 2 = 45 } // lldb-command:continue -// lldb-command:print *ff -// lldbg-check:[...]$34 = 46 +// lldb-command:v *ff +// lldbg-check:[...] 46 // lldbr-check:(isize) *ff = 46 -// lldb-command:print gg -// lldbg-check:[...]$35 = { 0 = 47 1 = 48 } +// lldb-command:v gg +// lldbg-check:[...] { 0 = 47 1 = 48 } // lldbr-check:((isize, isize)) gg = { 0 = 47 1 = 48 } // lldb-command:continue -// lldb-command:print *hh -// lldbg-check:[...]$36 = 50 +// lldb-command:v *hh +// lldbg-check:[...] 50 // lldbr-check:(i32) *hh = 50 // lldb-command:continue -// lldb-command:print ii -// lldbg-check:[...]$37 = 51 +// lldb-command:v ii +// lldbg-check:[...] 51 // lldbr-check:(i32) ii = 51 // lldb-command:continue -// lldb-command:print *jj -// lldbg-check:[...]$38 = 52 +// lldb-command:v *jj +// lldbg-check:[...] 52 // lldbr-check:(i32) *jj = 52 // lldb-command:continue -// lldb-command:print kk -// lldbg-check:[...]$39 = 53 +// lldb-command:v kk +// lldbg-check:[...] 53 // lldbr-check:(f64) kk = 53 -// lldb-command:print ll -// lldbg-check:[...]$40 = 54 +// lldb-command:v ll +// lldbg-check:[...] 54 // lldbr-check:(isize) ll = 54 // lldb-command:continue -// lldb-command:print mm -// lldbg-check:[...]$41 = 55 +// lldb-command:v mm +// lldbg-check:[...] 55 // lldbr-check:(f64) mm = 55 -// lldb-command:print *nn -// lldbg-check:[...]$42 = 56 +// lldb-command:v *nn +// lldbg-check:[...] 56 // lldbr-check:(isize) *nn = 56 // lldb-command:continue -// lldb-command:print oo -// lldbg-check:[...]$43 = 57 +// lldb-command:v oo +// lldbg-check:[...] 57 // lldbr-check:(isize) oo = 57 -// lldb-command:print pp -// lldbg-check:[...]$44 = 58 +// lldb-command:v pp +// lldbg-check:[...] 58 // lldbr-check:(isize) pp = 58 -// lldb-command:print qq -// lldbg-check:[...]$45 = 59 +// lldb-command:v qq +// lldbg-check:[...] 59 // lldbr-check:(isize) qq = 59 // lldb-command:continue -// lldb-command:print rr -// lldbg-check:[...]$46 = 60 +// lldb-command:v rr +// lldbg-check:[...] 60 // lldbr-check:(isize) rr = 60 -// lldb-command:print ss -// lldbg-check:[...]$47 = 61 +// lldb-command:v ss +// lldbg-check:[...] 61 // lldbr-check:(isize) ss = 61 -// lldb-command:print tt -// lldbg-check:[...]$48 = 62 +// lldb-command:v tt +// lldbg-check:[...] 62 // lldbr-check:(isize) tt = 62 // lldb-command:continue diff --git a/tests/debuginfo/destructured-for-loop-variable.rs b/tests/debuginfo/destructured-for-loop-variable.rs index 3e27d122c4b..1cad8bcfacb 100644 --- a/tests/debuginfo/destructured-for-loop-variable.rs +++ b/tests/debuginfo/destructured-for-loop-variable.rs @@ -84,90 +84,90 @@ // lldb-command:run // DESTRUCTURED STRUCT -// lldb-command:print x -// lldbg-check:[...]$0 = 400 +// lldb-command:v x +// lldbg-check:[...] 400 // lldbr-check:(i16) x = 400 -// lldb-command:print y -// lldbg-check:[...]$1 = 401.5 +// lldb-command:v y +// lldbg-check:[...] 401.5 // lldbr-check:(f32) y = 401.5 -// lldb-command:print z -// lldbg-check:[...]$2 = true +// lldb-command:v z +// lldbg-check:[...] true // lldbr-check:(bool) z = true // lldb-command:continue // DESTRUCTURED TUPLE -// lldb-command:print _i8 -// lldbg-check:[...]$3 = 0x6f +// lldb-command:v _i8 +// lldbg-check:[...] 0x6f // lldbr-check:(i8) _i8 = 111 -// lldb-command:print _u8 -// lldbg-check:[...]$4 = 0x70 +// lldb-command:v _u8 +// lldbg-check:[...] 0x70 // lldbr-check:(u8) _u8 = 112 -// lldb-command:print _i16 -// lldbg-check:[...]$5 = -113 +// lldb-command:v _i16 +// lldbg-check:[...] -113 // lldbr-check:(i16) _i16 = -113 -// lldb-command:print _u16 -// lldbg-check:[...]$6 = 114 +// lldb-command:v _u16 +// lldbg-check:[...] 114 // lldbr-check:(u16) _u16 = 114 -// lldb-command:print _i32 -// lldbg-check:[...]$7 = -115 +// lldb-command:v _i32 +// lldbg-check:[...] -115 // lldbr-check:(i32) _i32 = -115 -// lldb-command:print _u32 -// lldbg-check:[...]$8 = 116 +// lldb-command:v _u32 +// lldbg-check:[...] 116 // lldbr-check:(u32) _u32 = 116 -// lldb-command:print _i64 -// lldbg-check:[...]$9 = -117 +// lldb-command:v _i64 +// lldbg-check:[...] -117 // lldbr-check:(i64) _i64 = -117 -// lldb-command:print _u64 -// lldbg-check:[...]$10 = 118 +// lldb-command:v _u64 +// lldbg-check:[...] 118 // lldbr-check:(u64) _u64 = 118 -// lldb-command:print _f32 -// lldbg-check:[...]$11 = 119.5 +// lldb-command:v _f32 +// lldbg-check:[...] 119.5 // lldbr-check:(f32) _f32 = 119.5 -// lldb-command:print _f64 -// lldbg-check:[...]$12 = 120.5 +// lldb-command:v _f64 +// lldbg-check:[...] 120.5 // lldbr-check:(f64) _f64 = 120.5 // lldb-command:continue // MORE COMPLEX CASE -// lldb-command:print v1 -// lldbg-check:[...]$13 = 80000 +// lldb-command:v v1 +// lldbg-check:[...] 80000 // lldbr-check:(i32) v1 = 80000 -// lldb-command:print x1 -// lldbg-check:[...]$14 = 8000 +// lldb-command:v x1 +// lldbg-check:[...] 8000 // lldbr-check:(i16) x1 = 8000 -// lldb-command:print *y1 -// lldbg-check:[...]$15 = 80001.5 +// lldb-command:v *y1 +// lldbg-check:[...] 80001.5 // lldbr-check:(f32) *y1 = 80001.5 -// lldb-command:print z1 -// lldbg-check:[...]$16 = false +// lldb-command:v z1 +// lldbg-check:[...] false // lldbr-check:(bool) z1 = false -// lldb-command:print *x2 -// lldbg-check:[...]$17 = -30000 +// lldb-command:v *x2 +// lldbg-check:[...] -30000 // lldbr-check:(i16) *x2 = -30000 -// lldb-command:print y2 -// lldbg-check:[...]$18 = -300001.5 +// lldb-command:v y2 +// lldbg-check:[...] -300001.5 // lldbr-check:(f32) y2 = -300001.5 -// lldb-command:print *z2 -// lldbg-check:[...]$19 = true +// lldb-command:v *z2 +// lldbg-check:[...] true // lldbr-check:(bool) *z2 = true -// lldb-command:print v2 -// lldbg-check:[...]$20 = 854237.5 +// lldb-command:v v2 +// lldbg-check:[...] 854237.5 // lldbr-check:(f64) v2 = 854237.5 // lldb-command:continue // SIMPLE IDENTIFIER -// lldb-command:print i -// lldbg-check:[...]$21 = 1234 +// lldb-command:v i +// lldbg-check:[...] 1234 // lldbr-check:(i32) i = 1234 // lldb-command:continue -// lldb-command:print simple_struct_ident -// lldbg-check:[...]$22 = { x = 3537 y = 35437.5 z = true } +// lldb-command:v simple_struct_ident +// lldbg-check:[...] { x = 3537 y = 35437.5 z = true } // lldbr-check:(destructured_for_loop_variable::Struct) simple_struct_ident = { x = 3537 y = 35437.5 z = true } // lldb-command:continue -// lldb-command:print simple_tuple_ident -// lldbg-check:[...]$23 = { 0 = 34903493 1 = 232323 } +// lldb-command:v simple_tuple_ident +// lldbg-check:[...] { 0 = 34903493 1 = 232323 } // lldbr-check:((u32, i64)) simple_tuple_ident = { 0 = 34903493 1 = 232323 } // lldb-command:continue diff --git a/tests/debuginfo/destructured-local.rs b/tests/debuginfo/destructured-local.rs index 3e0557382b3..8d62fe5db03 100644 --- a/tests/debuginfo/destructured-local.rs +++ b/tests/debuginfo/destructured-local.rs @@ -129,157 +129,157 @@ // lldb-command:run -// lldb-command:print a -// lldbg-check:[...]$0 = 1 +// lldb-command:v a +// lldbg-check:[...] 1 // lldbr-check:(isize) a = 1 -// lldb-command:print b -// lldbg-check:[...]$1 = false +// lldb-command:v b +// lldbg-check:[...] false // lldbr-check:(bool) b = false -// lldb-command:print c -// lldbg-check:[...]$2 = 2 +// lldb-command:v c +// lldbg-check:[...] 2 // lldbr-check:(isize) c = 2 -// lldb-command:print d -// lldbg-check:[...]$3 = 3 +// lldb-command:v d +// lldbg-check:[...] 3 // lldbr-check:(u16) d = 3 -// lldb-command:print e -// lldbg-check:[...]$4 = 4 +// lldb-command:v e +// lldbg-check:[...] 4 // lldbr-check:(u16) e = 4 -// lldb-command:print f -// lldbg-check:[...]$5 = 5 +// lldb-command:v f +// lldbg-check:[...] 5 // lldbr-check:(isize) f = 5 -// lldb-command:print g -// lldbg-check:[...]$6 = { 0 = 6 1 = 7 } +// lldb-command:v g +// lldbg-check:[...] { 0 = 6 1 = 7 } // lldbr-check:((u32, u32)) g = { 0 = 6 1 = 7 } -// lldb-command:print h -// lldbg-check:[...]$7 = 8 +// lldb-command:v h +// lldbg-check:[...] 8 // lldbr-check:(i16) h = 8 -// lldb-command:print i -// lldbg-check:[...]$8 = { a = 9 b = 10 } +// lldb-command:v i +// lldbg-check:[...] { a = 9 b = 10 } // lldbr-check:(destructured_local::Struct) i = { a = 9 b = 10 } -// lldb-command:print j -// lldbg-check:[...]$9 = 11 +// lldb-command:v j +// lldbg-check:[...] 11 // lldbr-check:(i16) j = 11 -// lldb-command:print k -// lldbg-check:[...]$10 = 12 +// lldb-command:v k +// lldbg-check:[...] 12 // lldbr-check:(i64) k = 12 -// lldb-command:print l -// lldbg-check:[...]$11 = 13 +// lldb-command:v l +// lldbg-check:[...] 13 // lldbr-check:(i32) l = 13 -// lldb-command:print m -// lldbg-check:[...]$12 = 14 +// lldb-command:v m +// lldbg-check:[...] 14 // lldbr-check:(i32) m = 14 -// lldb-command:print n -// lldbg-check:[...]$13 = 16 +// lldb-command:v n +// lldbg-check:[...] 16 // lldbr-check:(i32) n = 16 -// lldb-command:print o -// lldbg-check:[...]$14 = 18 +// lldb-command:v o +// lldbg-check:[...] 18 // lldbr-check:(i32) o = 18 -// lldb-command:print p -// lldbg-check:[...]$15 = 19 +// lldb-command:v p +// lldbg-check:[...] 19 // lldbr-check:(i64) p = 19 -// lldb-command:print q -// lldbg-check:[...]$16 = 20 +// lldb-command:v q +// lldbg-check:[...] 20 // lldbr-check:(i32) q = 20 -// lldb-command:print r -// lldbg-check:[...]$17 = { a = 21 b = 22 } +// lldb-command:v r +// lldbg-check:[...] { a = 21 b = 22 } // lldbr-check:(destructured_local::Struct) r = { a = 21 b = 22 } -// lldb-command:print s -// lldbg-check:[...]$18 = 24 +// lldb-command:v s +// lldbg-check:[...] 24 // lldbr-check:(i32) s = 24 -// lldb-command:print t -// lldbg-check:[...]$19 = 23 +// lldb-command:v t +// lldbg-check:[...] 23 // lldbr-check:(i64) t = 23 -// lldb-command:print u -// lldbg-check:[...]$20 = 25 +// lldb-command:v u +// lldbg-check:[...] 25 // lldbr-check:(i32) u = 25 -// lldb-command:print v -// lldbg-check:[...]$21 = 26 +// lldb-command:v v +// lldbg-check:[...] 26 // lldbr-check:(i32) v = 26 -// lldb-command:print w -// lldbg-check:[...]$22 = 27 +// lldb-command:v w +// lldbg-check:[...] 27 // lldbr-check:(i32) w = 27 -// lldb-command:print x -// lldbg-check:[...]$23 = 28 +// lldb-command:v x +// lldbg-check:[...] 28 // lldbr-check:(i32) x = 28 -// lldb-command:print y -// lldbg-check:[...]$24 = 29 +// lldb-command:v y +// lldbg-check:[...] 29 // lldbr-check:(i64) y = 29 -// lldb-command:print z -// lldbg-check:[...]$25 = 30 +// lldb-command:v z +// lldbg-check:[...] 30 // lldbr-check:(i32) z = 30 -// lldb-command:print ae -// lldbg-check:[...]$26 = 31 +// lldb-command:v ae +// lldbg-check:[...] 31 // lldbr-check:(i64) ae = 31 -// lldb-command:print oe -// lldbg-check:[...]$27 = 32 +// lldb-command:v oe +// lldbg-check:[...] 32 // lldbr-check:(i32) oe = 32 -// lldb-command:print ue -// lldbg-check:[...]$28 = 33 +// lldb-command:v ue +// lldbg-check:[...] 33 // lldbr-check:(i32) ue = 33 -// lldb-command:print aa -// lldbg-check:[...]$29 = { 0 = 34 1 = 35 } +// lldb-command:v aa +// lldbg-check:[...] { 0 = 34 1 = 35 } // lldbr-check:((i32, i32)) aa = { 0 = 34 1 = 35 } -// lldb-command:print bb -// lldbg-check:[...]$30 = { 0 = 36 1 = 37 } +// lldb-command:v bb +// lldbg-check:[...] { 0 = 36 1 = 37 } // lldbr-check:((i32, i32)) bb = { 0 = 36 1 = 37 } -// lldb-command:print cc -// lldbg-check:[...]$31 = 38 +// lldb-command:v cc +// lldbg-check:[...] 38 // lldbr-check:(i32) cc = 38 -// lldb-command:print dd -// lldbg-check:[...]$32 = { 0 = 40 1 = 41 2 = 42 } +// lldb-command:v dd +// lldbg-check:[...] { 0 = 40 1 = 41 2 = 42 } // lldbr-check:((i32, i32, i32)) dd = { 0 = 40 1 = 41 2 = 42} -// lldb-command:print *ee -// lldbg-check:[...]$33 = { 0 = 43 1 = 44 2 = 45 } +// lldb-command:v *ee +// lldbg-check:[...] { 0 = 43 1 = 44 2 = 45 } // lldbr-check:((i32, i32, i32)) *ee = { 0 = 43 1 = 44 2 = 45} -// lldb-command:print *ff -// lldbg-check:[...]$34 = 46 +// lldb-command:v *ff +// lldbg-check:[...] 46 // lldbr-check:(i32) *ff = 46 -// lldb-command:print gg -// lldbg-check:[...]$35 = { 0 = 47 1 = 48 } +// lldb-command:v gg +// lldbg-check:[...] { 0 = 47 1 = 48 } // lldbr-check:((i32, i32)) gg = { 0 = 47 1 = 48 } -// lldb-command:print *hh -// lldbg-check:[...]$36 = 50 +// lldb-command:v *hh +// lldbg-check:[...] 50 // lldbr-check:(i32) *hh = 50 -// lldb-command:print ii -// lldbg-check:[...]$37 = 51 +// lldb-command:v ii +// lldbg-check:[...] 51 // lldbr-check:(i32) ii = 51 -// lldb-command:print *jj -// lldbg-check:[...]$38 = 52 +// lldb-command:v *jj +// lldbg-check:[...] 52 // lldbr-check:(i32) *jj = 52 -// lldb-command:print kk -// lldbg-check:[...]$39 = 53 +// lldb-command:v kk +// lldbg-check:[...] 53 // lldbr-check:(f64) kk = 53 -// lldb-command:print ll -// lldbg-check:[...]$40 = 54 +// lldb-command:v ll +// lldbg-check:[...] 54 // lldbr-check:(isize) ll = 54 -// lldb-command:print mm -// lldbg-check:[...]$41 = 55 +// lldb-command:v mm +// lldbg-check:[...] 55 // lldbr-check:(f64) mm = 55 -// lldb-command:print *nn -// lldbg-check:[...]$42 = 56 +// lldb-command:v *nn +// lldbg-check:[...] 56 // lldbr-check:(isize) *nn = 56 diff --git a/tests/debuginfo/drop-locations.rs b/tests/debuginfo/drop-locations.rs index 6404bf9c3da..15b2d0de7fe 100644 --- a/tests/debuginfo/drop-locations.rs +++ b/tests/debuginfo/drop-locations.rs @@ -43,22 +43,22 @@ // lldb-command:run // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#loc1[...] +// lldb-check:[...] #loc1 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#loc2[...] +// lldb-check:[...] #loc2 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#loc3[...] +// lldb-check:[...] #loc3 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#loc4[...] +// lldb-check:[...] #loc4 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#loc5[...] +// lldb-check:[...] #loc5 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#loc6[...] +// lldb-check:[...] #loc6 [...] fn main() { diff --git a/tests/debuginfo/empty-string.rs b/tests/debuginfo/empty-string.rs index 838e160e74e..36240730e19 100644 --- a/tests/debuginfo/empty-string.rs +++ b/tests/debuginfo/empty-string.rs @@ -17,13 +17,13 @@ // === LLDB TESTS ================================================================================== -// lldb-command: run +// lldb-command:run -// lldb-command: fr v empty_string -// lldb-check:[...]empty_string = "" { vec = size=0 } +// lldb-command:fr v empty_string +// lldb-check:[...] empty_string = "" { vec = size=0 } -// lldb-command: fr v empty_str -// lldb-check:[...]empty_str = "" { data_ptr = [...] length = 0 } +// lldb-command:fr v empty_str +// lldb-check:[...] empty_str = "" { data_ptr = [...] length = 0 } fn main() { let empty_string = String::new(); diff --git a/tests/debuginfo/enum-thinlto.rs b/tests/debuginfo/enum-thinlto.rs index 5c27fe4271c..f3f17758931 100644 --- a/tests/debuginfo/enum-thinlto.rs +++ b/tests/debuginfo/enum-thinlto.rs @@ -14,8 +14,8 @@ // lldb-command:run -// lldb-command:print *abc -// lldbg-check:(enum_thinlto::ABC) $0 = +// lldb-command:v *abc +// lldbg-check:(enum_thinlto::ABC) *abc = // lldbr-check:(enum_thinlto::ABC) *abc = (x = 0, y = 8970181431921507452) #![allow(unused_variables)] diff --git a/tests/debuginfo/evec-in-struct.rs b/tests/debuginfo/evec-in-struct.rs index d238cc9eded..2283e96c0ad 100644 --- a/tests/debuginfo/evec-in-struct.rs +++ b/tests/debuginfo/evec-in-struct.rs @@ -30,23 +30,23 @@ // lldb-command:run -// lldb-command:print no_padding1 -// lldbg-check:[...]$0 = { x = { [0] = 0 [1] = 1 [2] = 2 } y = -3 z = { [0] = 4.5 [1] = 5.5 } } +// lldb-command:v no_padding1 +// lldbg-check:[...] { x = { [0] = 0 [1] = 1 [2] = 2 } y = -3 z = { [0] = 4.5 [1] = 5.5 } } // lldbr-check:(evec_in_struct::NoPadding1) no_padding1 = { x = { [0] = 0 [1] = 1 [2] = 2 } y = -3 z = { [0] = 4.5 [1] = 5.5 } } -// lldb-command:print no_padding2 -// lldbg-check:[...]$1 = { x = { [0] = 6 [1] = 7 [2] = 8 } y = { [0] = { [0] = 9 [1] = 10 } [1] = { [0] = 11 [1] = 12 } } } +// lldb-command:v no_padding2 +// lldbg-check:[...] { x = { [0] = 6 [1] = 7 [2] = 8 } y = { [0] = { [0] = 9 [1] = 10 } [1] = { [0] = 11 [1] = 12 } } } // lldbr-check:(evec_in_struct::NoPadding2) no_padding2 = { x = { [0] = 6 [1] = 7 [2] = 8 } y = { [0] = { [0] = 9 [1] = 10 } [1] = { [0] = 11 [1] = 12 } } } -// lldb-command:print struct_internal_padding -// lldbg-check:[...]$2 = { x = { [0] = 13 [1] = 14 } y = { [0] = 15 [1] = 16 } } +// lldb-command:v struct_internal_padding +// lldbg-check:[...] { x = { [0] = 13 [1] = 14 } y = { [0] = 15 [1] = 16 } } // lldbr-check:(evec_in_struct::StructInternalPadding) struct_internal_padding = { x = { [0] = 13 [1] = 14 } y = { [0] = 15 [1] = 16 } } -// lldb-command:print single_vec -// lldbg-check:[...]$3 = { x = { [0] = 17 [1] = 18 [2] = 19 [3] = 20 [4] = 21 } } +// lldb-command:v single_vec +// lldbg-check:[...] { x = { [0] = 17 [1] = 18 [2] = 19 [3] = 20 [4] = 21 } } // lldbr-check:(evec_in_struct::SingleVec) single_vec = { x = { [0] = 17 [1] = 18 [2] = 19 [3] = 20 [4] = 21 } } -// lldb-command:print struct_padded_at_end -// lldbg-check:[...]$4 = { x = { [0] = 22 [1] = 23 } y = { [0] = 24 [1] = 25 } } +// lldb-command:v struct_padded_at_end +// lldbg-check:[...] { x = { [0] = 22 [1] = 23 } y = { [0] = 24 [1] = 25 } } // lldbr-check:(evec_in_struct::StructPaddedAtEnd) struct_padded_at_end = { x = { [0] = 22 [1] = 23 } y = { [0] = 24 [1] = 25 } } #![allow(unused_variables)] diff --git a/tests/debuginfo/extern-c-fn.rs b/tests/debuginfo/extern-c-fn.rs index 62c2b609969..b45a073ed05 100644 --- a/tests/debuginfo/extern-c-fn.rs +++ b/tests/debuginfo/extern-c-fn.rs @@ -21,17 +21,17 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print len -// lldbg-check:[...]$0 = 20 +// lldb-command:v len +// lldbg-check:[...] 20 // lldbr-check:(i32) len = 20 -// lldb-command:print local0 -// lldbg-check:[...]$1 = 19 +// lldb-command:v local0 +// lldbg-check:[...] 19 // lldbr-check:(i32) local0 = 19 -// lldb-command:print local1 -// lldbg-check:[...]$2 = true +// lldb-command:v local1 +// lldbg-check:[...] true // lldbr-check:(bool) local1 = true -// lldb-command:print local2 -// lldbg-check:[...]$3 = 20.5 +// lldb-command:v local2 +// lldbg-check:[...] 20.5 // lldbr-check:(f64) local2 = 20.5 // lldb-command:continue diff --git a/tests/debuginfo/function-arg-initialization.rs b/tests/debuginfo/function-arg-initialization.rs index 4bdaefd9bdd..05935c30bea 100644 --- a/tests/debuginfo/function-arg-initialization.rs +++ b/tests/debuginfo/function-arg-initialization.rs @@ -119,100 +119,100 @@ // lldb-command:run // IMMEDIATE ARGS -// lldb-command:print a -// lldb-check:[...]$0 = 1 -// lldb-command:print b -// lldb-check:[...]$1 = true -// lldb-command:print c -// lldb-check:[...]$2 = 2.5 +// lldb-command:v a +// lldb-check:[...] 1 +// lldb-command:v b +// lldb-check:[...] true +// lldb-command:v c +// lldb-check:[...] 2.5 // lldb-command:continue // NON IMMEDIATE ARGS -// lldb-command:print a -// lldb-check:[...]$3 = BigStruct { a: 3, b: 4, c: 5, d: 6, e: 7, f: 8, g: 9, h: 10 } -// lldb-command:print b -// lldb-check:[...]$4 = BigStruct { a: 11, b: 12, c: 13, d: 14, e: 15, f: 16, g: 17, h: 18 } +// lldb-command:v a +// lldb-check:[...] BigStruct { a: 3, b: 4, c: 5, d: 6, e: 7, f: 8, g: 9, h: 10 } +// lldb-command:v b +// lldb-check:[...] BigStruct { a: 11, b: 12, c: 13, d: 14, e: 15, f: 16, g: 17, h: 18 } // lldb-command:continue // BINDING -// lldb-command:print a -// lldb-check:[...]$5 = 19 -// lldb-command:print b -// lldb-check:[...]$6 = 20 -// lldb-command:print c -// lldb-check:[...]$7 = 21.5 +// lldb-command:v a +// lldb-check:[...] 19 +// lldb-command:v b +// lldb-check:[...] 20 +// lldb-command:v c +// lldb-check:[...] 21.5 // lldb-command:continue // ASSIGNMENT -// lldb-command:print a -// lldb-check:[...]$8 = 22 -// lldb-command:print b -// lldb-check:[...]$9 = 23 -// lldb-command:print c -// lldb-check:[...]$10 = 24.5 +// lldb-command:v a +// lldb-check:[...] 22 +// lldb-command:v b +// lldb-check:[...] 23 +// lldb-command:v c +// lldb-check:[...] 24.5 // lldb-command:continue // FUNCTION CALL -// lldb-command:print x -// lldb-check:[...]$11 = 25 -// lldb-command:print y -// lldb-check:[...]$12 = 26 -// lldb-command:print z -// lldb-check:[...]$13 = 27.5 +// lldb-command:v x +// lldb-check:[...] 25 +// lldb-command:v y +// lldb-check:[...] 26 +// lldb-command:v z +// lldb-check:[...] 27.5 // lldb-command:continue // EXPR -// lldb-command:print x -// lldb-check:[...]$14 = 28 -// lldb-command:print y -// lldb-check:[...]$15 = 29 -// lldb-command:print z -// lldb-check:[...]$16 = 30.5 +// lldb-command:v x +// lldb-check:[...] 28 +// lldb-command:v y +// lldb-check:[...] 29 +// lldb-command:v z +// lldb-check:[...] 30.5 // lldb-command:continue // RETURN EXPR -// lldb-command:print x -// lldb-check:[...]$17 = 31 -// lldb-command:print y -// lldb-check:[...]$18 = 32 -// lldb-command:print z -// lldb-check:[...]$19 = 33.5 +// lldb-command:v x +// lldb-check:[...] 31 +// lldb-command:v y +// lldb-check:[...] 32 +// lldb-command:v z +// lldb-check:[...] 33.5 // lldb-command:continue // ARITHMETIC EXPR -// lldb-command:print x -// lldb-check:[...]$20 = 34 -// lldb-command:print y -// lldb-check:[...]$21 = 35 -// lldb-command:print z -// lldb-check:[...]$22 = 36.5 +// lldb-command:v x +// lldb-check:[...] 34 +// lldb-command:v y +// lldb-check:[...] 35 +// lldb-command:v z +// lldb-check:[...] 36.5 // lldb-command:continue // IF EXPR -// lldb-command:print x -// lldb-check:[...]$23 = 37 -// lldb-command:print y -// lldb-check:[...]$24 = 38 -// lldb-command:print z -// lldb-check:[...]$25 = 39.5 +// lldb-command:v x +// lldb-check:[...] 37 +// lldb-command:v y +// lldb-check:[...] 38 +// lldb-command:v z +// lldb-check:[...] 39.5 // lldb-command:continue // WHILE EXPR -// lldb-command:print x -// lldb-check:[...]$26 = 40 -// lldb-command:print y -// lldb-check:[...]$27 = 41 -// lldb-command:print z -// lldb-check:[...]$28 = 42 +// lldb-command:v x +// lldb-check:[...] 40 +// lldb-command:v y +// lldb-check:[...] 41 +// lldb-command:v z +// lldb-check:[...] 42 // lldb-command:continue // LOOP EXPR -// lldb-command:print x -// lldb-check:[...]$29 = 43 -// lldb-command:print y -// lldb-check:[...]$30 = 44 -// lldb-command:print z -// lldb-check:[...]$31 = 45 +// lldb-command:v x +// lldb-check:[...] 43 +// lldb-command:v y +// lldb-check:[...] 44 +// lldb-command:v z +// lldb-check:[...] 45 // lldb-command:continue diff --git a/tests/debuginfo/function-arguments.rs b/tests/debuginfo/function-arguments.rs index c6b865bd458..b0afa1d0772 100644 --- a/tests/debuginfo/function-arguments.rs +++ b/tests/debuginfo/function-arguments.rs @@ -22,19 +22,19 @@ // lldb-command:run -// lldb-command:print x -// lldbg-check:[...]$0 = 111102 +// lldb-command:v x +// lldbg-check:[...] 111102 // lldbr-check:(isize) x = 111102 -// lldb-command:print y -// lldbg-check:[...]$1 = true +// lldb-command:v y +// lldbg-check:[...] true // lldbr-check:(bool) y = true // lldb-command:continue -// lldb-command:print a -// lldbg-check:[...]$2 = 2000 +// lldb-command:v a +// lldbg-check:[...] 2000 // lldbr-check:(i32) a = 2000 -// lldb-command:print b -// lldbg-check:[...]$3 = 3000 +// lldb-command:v b +// lldbg-check:[...] 3000 // lldbr-check:(i64) b = 3000 // lldb-command:continue diff --git a/tests/debuginfo/function-prologue-stepping-regular.rs b/tests/debuginfo/function-prologue-stepping-regular.rs index e52d17a70bd..a1f44105bb9 100644 --- a/tests/debuginfo/function-prologue-stepping-regular.rs +++ b/tests/debuginfo/function-prologue-stepping-regular.rs @@ -20,100 +20,100 @@ // lldb-command:run // IMMEDIATE ARGS -// lldb-command:print a -// lldb-check:[...]$0 = 1 -// lldb-command:print b -// lldb-check:[...]$1 = true -// lldb-command:print c -// lldb-check:[...]$2 = 2.5 +// lldb-command:v a +// lldb-check:[...] 1 +// lldb-command:v b +// lldb-check:[...] true +// lldb-command:v c +// lldb-check:[...] 2.5 // lldb-command:continue // NON IMMEDIATE ARGS -// lldb-command:print a -// lldb-check:[...]$3 = { a = 3, b = 4, c = 5, d = 6, e = 7, f = 8, g = 9, h = 10 } -// lldb-command:print b -// lldb-check:[...]$4 = { a = 11, b = 12, c = 13, d = 14, e = 15, f = 16, g = 17, h = 18 } +// lldb-command:v a +// lldb-check:[...] { a = 3, b = 4, c = 5, d = 6, e = 7, f = 8, g = 9, h = 10 } +// lldb-command:v b +// lldb-check:[...] { a = 11, b = 12, c = 13, d = 14, e = 15, f = 16, g = 17, h = 18 } // lldb-command:continue // BINDING -// lldb-command:print a -// lldb-check:[...]$5 = 19 -// lldb-command:print b -// lldb-check:[...]$6 = 20 -// lldb-command:print c -// lldb-check:[...]$7 = 21.5 +// lldb-command:v a +// lldb-check:[...] 19 +// lldb-command:v b +// lldb-check:[...] 20 +// lldb-command:v c +// lldb-check:[...] 21.5 // lldb-command:continue // ASSIGNMENT -// lldb-command:print a -// lldb-check:[...]$8 = 22 -// lldb-command:print b -// lldb-check:[...]$9 = 23 -// lldb-command:print c -// lldb-check:[...]$10 = 24.5 +// lldb-command:v a +// lldb-check:[...] 22 +// lldb-command:v b +// lldb-check:[...] 23 +// lldb-command:v c +// lldb-check:[...] 24.5 // lldb-command:continue // FUNCTION CALL -// lldb-command:print x -// lldb-check:[...]$11 = 25 -// lldb-command:print y -// lldb-check:[...]$12 = 26 -// lldb-command:print z -// lldb-check:[...]$13 = 27.5 +// lldb-command:v x +// lldb-check:[...] 25 +// lldb-command:v y +// lldb-check:[...] 26 +// lldb-command:v z +// lldb-check:[...] 27.5 // lldb-command:continue // EXPR -// lldb-command:print x -// lldb-check:[...]$14 = 28 -// lldb-command:print y -// lldb-check:[...]$15 = 29 -// lldb-command:print z -// lldb-check:[...]$16 = 30.5 +// lldb-command:v x +// lldb-check:[...] 28 +// lldb-command:v y +// lldb-check:[...] 29 +// lldb-command:v z +// lldb-check:[...] 30.5 // lldb-command:continue // RETURN EXPR -// lldb-command:print x -// lldb-check:[...]$17 = 31 -// lldb-command:print y -// lldb-check:[...]$18 = 32 -// lldb-command:print z -// lldb-check:[...]$19 = 33.5 +// lldb-command:v x +// lldb-check:[...] 31 +// lldb-command:v y +// lldb-check:[...] 32 +// lldb-command:v z +// lldb-check:[...] 33.5 // lldb-command:continue // ARITHMETIC EXPR -// lldb-command:print x -// lldb-check:[...]$20 = 34 -// lldb-command:print y -// lldb-check:[...]$21 = 35 -// lldb-command:print z -// lldb-check:[...]$22 = 36.5 +// lldb-command:v x +// lldb-check:[...] 34 +// lldb-command:v y +// lldb-check:[...] 35 +// lldb-command:v z +// lldb-check:[...] 36.5 // lldb-command:continue // IF EXPR -// lldb-command:print x -// lldb-check:[...]$23 = 37 -// lldb-command:print y -// lldb-check:[...]$24 = 38 -// lldb-command:print z -// lldb-check:[...]$25 = 39.5 +// lldb-command:v x +// lldb-check:[...] 37 +// lldb-command:v y +// lldb-check:[...] 38 +// lldb-command:v z +// lldb-check:[...] 39.5 // lldb-command:continue // WHILE EXPR -// lldb-command:print x -// lldb-check:[...]$26 = 40 -// lldb-command:print y -// lldb-check:[...]$27 = 41 -// lldb-command:print z -// lldb-check:[...]$28 = 42 +// lldb-command:v x +// lldb-check:[...] 40 +// lldb-command:v y +// lldb-check:[...] 41 +// lldb-command:v z +// lldb-check:[...] 42 // lldb-command:continue // LOOP EXPR -// lldb-command:print x -// lldb-check:[...]$29 = 43 -// lldb-command:print y -// lldb-check:[...]$30 = 44 -// lldb-command:print z -// lldb-check:[...]$31 = 45 +// lldb-command:v x +// lldb-check:[...] 43 +// lldb-command:v y +// lldb-check:[...] 44 +// lldb-command:v z +// lldb-check:[...] 45 // lldb-command:continue #![allow(unused_variables)] diff --git a/tests/debuginfo/generic-enum-with-different-disr-sizes.rs b/tests/debuginfo/generic-enum-with-different-disr-sizes.rs index 6a8aa831c40..7b23221213a 100644 --- a/tests/debuginfo/generic-enum-with-different-disr-sizes.rs +++ b/tests/debuginfo/generic-enum-with-different-disr-sizes.rs @@ -39,23 +39,23 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print eight_bytes1 -// lldb-check:[...]$0 = Variant1(100) -// lldb-command:print four_bytes1 -// lldb-check:[...]$1 = Variant1(101) -// lldb-command:print two_bytes1 -// lldb-check:[...]$2 = Variant1(102) -// lldb-command:print one_byte1 -// lldb-check:[...]$3 = Variant1('A') - -// lldb-command:print eight_bytes2 -// lldb-check:[...]$4 = Variant2(100) -// lldb-command:print four_bytes2 -// lldb-check:[...]$5 = Variant2(101) -// lldb-command:print two_bytes2 -// lldb-check:[...]$6 = Variant2(102) -// lldb-command:print one_byte2 -// lldb-check:[...]$7 = Variant2('A') +// lldb-command:v eight_bytes1 +// lldb-check:[...] Variant1(100) +// lldb-command:v four_bytes1 +// lldb-check:[...] Variant1(101) +// lldb-command:v two_bytes1 +// lldb-check:[...] Variant1(102) +// lldb-command:v one_byte1 +// lldb-check:[...] Variant1('A') + +// lldb-command:v eight_bytes2 +// lldb-check:[...] Variant2(100) +// lldb-command:v four_bytes2 +// lldb-check:[...] Variant2(101) +// lldb-command:v two_bytes2 +// lldb-check:[...] Variant2(102) +// lldb-command:v one_byte2 +// lldb-check:[...] Variant2('A') // lldb-command:continue diff --git a/tests/debuginfo/generic-function.rs b/tests/debuginfo/generic-function.rs index eab781d2150..e131ebfa306 100644 --- a/tests/debuginfo/generic-function.rs +++ b/tests/debuginfo/generic-function.rs @@ -29,27 +29,27 @@ // lldb-command:run -// lldb-command:print *t0 -// lldbg-check:[...]$0 = 1 +// lldb-command:v *t0 +// lldbg-check:[...] 1 // lldbr-check:(i32) *t0 = 1 -// lldb-command:print *t1 -// lldbg-check:[...]$1 = 2.5 +// lldb-command:v *t1 +// lldbg-check:[...] 2.5 // lldbr-check:(f64) *t1 = 2.5 // lldb-command:continue -// lldb-command:print *t0 -// lldbg-check:[...]$2 = 3.5 +// lldb-command:v *t0 +// lldbg-check:[...] 3.5 // lldbr-check:(f64) *t0 = 3.5 -// lldb-command:print *t1 -// lldbg-check:[...]$3 = 4 +// lldb-command:v *t1 +// lldbg-check:[...] 4 // lldbr-check:(u16) *t1 = 4 // lldb-command:continue -// lldb-command:print *t0 -// lldbg-check:[...]$4 = 5 +// lldb-command:v *t0 +// lldbg-check:[...] 5 // lldbr-check:(i32) *t0 = 5 -// lldb-command:print *t1 -// lldbg-check:[...]$5 = { a = 6 b = 7.5 } +// lldb-command:v *t1 +// lldbg-check:[...] { a = 6 b = 7.5 } // lldbr-check:(generic_function::Struct) *t1 = { a = 6 b = 7.5 } // lldb-command:continue diff --git a/tests/debuginfo/generic-functions-nested.rs b/tests/debuginfo/generic-functions-nested.rs index a146015246e..eee0c151182 100644 --- a/tests/debuginfo/generic-functions-nested.rs +++ b/tests/debuginfo/generic-functions-nested.rs @@ -35,35 +35,35 @@ // lldb-command:run -// lldb-command:print x -// lldbg-check:[...]$0 = -1 +// lldb-command:v x +// lldbg-check:[...] -1 // lldbr-check:(i32) x = -1 -// lldb-command:print y -// lldbg-check:[...]$1 = 1 +// lldb-command:v y +// lldbg-check:[...] 1 // lldbr-check:(i32) y = 1 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$2 = -1 +// lldb-command:v x +// lldbg-check:[...] -1 // lldbr-check:(i32) x = -1 -// lldb-command:print y -// lldbg-check:[...]$3 = 2.5 +// lldb-command:v y +// lldbg-check:[...] 2.5 // lldbr-check:(f64) y = 2.5 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$4 = -2.5 +// lldb-command:v x +// lldbg-check:[...] -2.5 // lldbr-check:(f64) x = -2.5 -// lldb-command:print y -// lldbg-check:[...]$5 = 1 +// lldb-command:v y +// lldbg-check:[...] 1 // lldbr-check:(i32) y = 1 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$6 = -2.5 +// lldb-command:v x +// lldbg-check:[...] -2.5 // lldbr-check:(f64) x = -2.5 -// lldb-command:print y -// lldbg-check:[...]$7 = 2.5 +// lldb-command:v y +// lldbg-check:[...] 2.5 // lldbr-check:(f64) y = 2.5 // lldb-command:continue diff --git a/tests/debuginfo/generic-method-on-generic-struct.rs b/tests/debuginfo/generic-method-on-generic-struct.rs index dd1f482f3fa..0f706740410 100644 --- a/tests/debuginfo/generic-method-on-generic-struct.rs +++ b/tests/debuginfo/generic-method-on-generic-struct.rs @@ -64,62 +64,62 @@ // lldb-command:run // STACK BY REF -// lldb-command:print *self -// lldbg-check:[...]$0 = { x = { 0 = 8888, 1 = -8888 } } +// lldb-command:v *self +// lldbg-check:[...] { x = { 0 = 8888, 1 = -8888 } } // lldbr-check:(generic_method_on_generic_struct::Struct<(u32, i32)>) *self = { x = { 0 = 8888 1 = -8888 } } -// lldb-command:print arg1 -// lldbg-check:[...]$1 = -1 +// lldb-command:v arg1 +// lldbg-check:[...] -1 // lldbr-check:(isize) arg1 = -1 -// lldb-command:print arg2 -// lldbg-check:[...]$2 = 2 +// lldb-command:v arg2 +// lldbg-check:[...] 2 // lldbr-check:(u16) arg2 = 2 // lldb-command:continue // STACK BY VAL -// lldb-command:print self -// lldbg-check:[...]$3 = { x = { 0 = 8888, 1 = -8888 } } +// lldb-command:v self +// lldbg-check:[...] { x = { 0 = 8888, 1 = -8888 } } // lldbr-check:(generic_method_on_generic_struct::Struct<(u32, i32)>) self = { x = { 0 = 8888, 1 = -8888 } } -// lldb-command:print arg1 -// lldbg-check:[...]$4 = -3 +// lldb-command:v arg1 +// lldbg-check:[...] -3 // lldbr-check:(isize) arg1 = -3 -// lldb-command:print arg2 -// lldbg-check:[...]$5 = -4 +// lldb-command:v arg2 +// lldbg-check:[...] -4 // lldbr-check:(i16) arg2 = -4 // lldb-command:continue // OWNED BY REF -// lldb-command:print *self -// lldbg-check:[...]$6 = { x = 1234.5 } +// lldb-command:v *self +// lldbg-check:[...] { x = 1234.5 } // lldbr-check:(generic_method_on_generic_struct::Struct<f64>) *self = { x = 1234.5 } -// lldb-command:print arg1 -// lldbg-check:[...]$7 = -5 +// lldb-command:v arg1 +// lldbg-check:[...] -5 // lldbr-check:(isize) arg1 = -5 -// lldb-command:print arg2 -// lldbg-check:[...]$8 = -6 +// lldb-command:v arg2 +// lldbg-check:[...] -6 // lldbr-check:(i32) arg2 = -6 // lldb-command:continue // OWNED BY VAL -// lldb-command:print self -// lldbg-check:[...]$9 = { x = 1234.5 } +// lldb-command:v self +// lldbg-check:[...] { x = 1234.5 } // lldbr-check:(generic_method_on_generic_struct::Struct<f64>) self = { x = 1234.5 } -// lldb-command:print arg1 -// lldbg-check:[...]$10 = -7 +// lldb-command:v arg1 +// lldbg-check:[...] -7 // lldbr-check:(isize) arg1 = -7 -// lldb-command:print arg2 -// lldbg-check:[...]$11 = -8 +// lldb-command:v arg2 +// lldbg-check:[...] -8 // lldbr-check:(i64) arg2 = -8 // lldb-command:continue // OWNED MOVED -// lldb-command:print *self -// lldbg-check:[...]$12 = { x = 1234.5 } +// lldb-command:v *self +// lldbg-check:[...] { x = 1234.5 } // lldbr-check:(generic_method_on_generic_struct::Struct<f64>) *self = { x = 1234.5 } -// lldb-command:print arg1 -// lldbg-check:[...]$13 = -9 +// lldb-command:v arg1 +// lldbg-check:[...] -9 // lldbr-check:(isize) arg1 = -9 -// lldb-command:print arg2 -// lldbg-check:[...]$14 = -10.5 +// lldb-command:v arg2 +// lldbg-check:[...] -10.5 // lldbr-check:(f32) arg2 = -10.5 // lldb-command:continue diff --git a/tests/debuginfo/generic-struct.rs b/tests/debuginfo/generic-struct.rs index 82ed17618aa..8c74aa42d2c 100644 --- a/tests/debuginfo/generic-struct.rs +++ b/tests/debuginfo/generic-struct.rs @@ -25,18 +25,18 @@ // lldb-command:run -// lldb-command:print int_int -// lldbg-check:[...]$0 = AGenericStruct<i32, i32> { key: 0, value: 1 } +// lldb-command:v int_int +// lldbg-check:[...] AGenericStruct<i32, i32> { key: 0, value: 1 } // lldbr-check:(generic_struct::AGenericStruct<i32, i32>) int_int = AGenericStruct<i32, i32> { key: 0, value: 1 } -// lldb-command:print int_float -// lldbg-check:[...]$1 = AGenericStruct<i32, f64> { key: 2, value: 3.5 } +// lldb-command:v int_float +// lldbg-check:[...] AGenericStruct<i32, f64> { key: 2, value: 3.5 } // lldbr-check:(generic_struct::AGenericStruct<i32, f64>) int_float = AGenericStruct<i32, f64> { key: 2, value: 3.5 } -// lldb-command:print float_int -// lldbg-check:[...]$2 = AGenericStruct<f64, i32> { key: 4.5, value: 5 } +// lldb-command:v float_int +// lldbg-check:[...] AGenericStruct<f64, i32> { key: 4.5, value: 5 } // lldbr-check:(generic_struct::AGenericStruct<f64, i32>) float_int = AGenericStruct<f64, i32> { key: 4.5, value: 5 } -// lldb-command:print float_int_float -// lldbg-check:[...]$3 = AGenericStruct<f64, generic_struct::AGenericStruct<i32, f64>> { key: 6.5, value: AGenericStruct<i32, f64> { key: 7, value: 8.5 } } +// lldb-command:v float_int_float +// lldbg-check:[...] AGenericStruct<f64, generic_struct::AGenericStruct<i32, f64>> { key: 6.5, value: AGenericStruct<i32, f64> { key: 7, value: 8.5 } } // lldbr-check:(generic_struct::AGenericStruct<f64, generic_struct::AGenericStruct<i32, f64>>) float_int_float = AGenericStruct<f64, generic_struct::AGenericStruct<i32, f64>> { key: 6.5, value: AGenericStruct<i32, f64> { key: 7, value: 8.5 } } // === CDB TESTS =================================================================================== diff --git a/tests/debuginfo/generic-tuple-style-enum.rs b/tests/debuginfo/generic-tuple-style-enum.rs index fb5deb9b198..af90c6ce30e 100644 --- a/tests/debuginfo/generic-tuple-style-enum.rs +++ b/tests/debuginfo/generic-tuple-style-enum.rs @@ -26,16 +26,16 @@ // lldb-command:run -// lldb-command:print case1 +// lldb-command:v case1 // lldbr-check:(generic_tuple_style_enum::Regular<u16, u32, u64>::Case1) case1 = { __0 = 0 __1 = 31868 __2 = 31868 __3 = 31868 __4 = 31868 } -// lldb-command:print case2 +// lldb-command:v case2 // lldbr-check:(generic_tuple_style_enum::Regular<i16, i32, i64>::Case2) case2 = Regular<i16, i32, i64>::Case2 { Case1: 0, Case2: 286331153, Case3: 286331153 } -// lldb-command:print case3 +// lldb-command:v case3 // lldbr-check:(generic_tuple_style_enum::Regular<i16, i32, i64>::Case3) case3 = Regular<i16, i32, i64>::Case3 { Case1: 0, Case2: 6438275382588823897 } -// lldb-command:print univariant +// lldb-command:v univariant // lldbr-check:(generic_tuple_style_enum::Univariant<i64>) univariant = Univariant<i64> { TheOnlyCase: Univariant<i64>::TheOnlyCase(-1) } #![feature(omit_gdb_pretty_printer_section)] diff --git a/tests/debuginfo/include_string.rs b/tests/debuginfo/include_string.rs index 6f7d2b28b41..75013ab5274 100644 --- a/tests/debuginfo/include_string.rs +++ b/tests/debuginfo/include_string.rs @@ -15,14 +15,14 @@ // lldb-command:run -// lldb-command:print string1.length -// lldbg-check:[...]$0 = 48 +// lldb-command:v string1.length +// lldbg-check:[...] 48 // lldbr-check:(usize) length = 48 -// lldb-command:print string2.length -// lldbg-check:[...]$1 = 49 +// lldb-command:v string2.length +// lldbg-check:[...] 49 // lldbr-check:(usize) length = 49 -// lldb-command:print string3.length -// lldbg-check:[...]$2 = 50 +// lldb-command:v string3.length +// lldbg-check:[...] 50 // lldbr-check:(usize) length = 50 // lldb-command:continue diff --git a/tests/debuginfo/issue-22656.rs b/tests/debuginfo/issue-22656.rs index acbe2b12a24..5a5442acd95 100644 --- a/tests/debuginfo/issue-22656.rs +++ b/tests/debuginfo/issue-22656.rs @@ -10,11 +10,11 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print v -// lldbg-check:[...]$0 = size=3 { [0] = 1 [1] = 2 [2] = 3 } +// lldb-command:v v +// lldbg-check:[...] size=3 { [0] = 1 [1] = 2 [2] = 3 } // lldbr-check:(alloc::vec::Vec<i32>) v = size=3 { [0] = 1 [1] = 2 [2] = 3 } -// lldb-command:print zs -// lldbg-check:[...]$1 = { x = y = 123 z = w = 456 } +// lldb-command:v zs +// lldbg-check:[...] { x = y = 123 z = w = 456 } // lldbr-check:(issue_22656::StructWithZeroSizedField) zs = { x = y = 123 z = w = 456 } // lldbr-command:continue diff --git a/tests/debuginfo/issue-57822.rs b/tests/debuginfo/issue-57822.rs index f4ef45f1d74..93e1a2558f6 100644 --- a/tests/debuginfo/issue-57822.rs +++ b/tests/debuginfo/issue-57822.rs @@ -20,11 +20,11 @@ // lldb-command:run -// lldb-command:print g -// lldbg-check:(issue_57822::main::{closure_env#1}) $0 = { f = { x = 1 } } +// lldb-command:v g +// lldbg-check:(issue_57822::main::{closure_env#1}) g = { f = { x = 1 } } -// lldb-command:print b -// lldbg-check:(issue_57822::main::{coroutine_env#3}) $1 = +// lldb-command:v b +// lldbg-check:(issue_57822::main::{coroutine_env#3}) b = #![feature(omit_gdb_pretty_printer_section, coroutines, coroutine_trait)] #![omit_gdb_pretty_printer_section] diff --git a/tests/debuginfo/lexical-scope-in-for-loop.rs b/tests/debuginfo/lexical-scope-in-for-loop.rs index 93be5288a64..1b1f106fece 100644 --- a/tests/debuginfo/lexical-scope-in-for-loop.rs +++ b/tests/debuginfo/lexical-scope-in-for-loop.rs @@ -44,41 +44,41 @@ // lldb-command:run // FIRST ITERATION -// lldb-command:print x -// lldbg-check:[...]$0 = 1 +// lldb-command:v x +// lldbg-check:[...] 1 // lldbr-check:(i32) x = 1 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$1 = -1 +// lldb-command:v x +// lldbg-check:[...] -1 // lldbr-check:(i32) x = -1 // lldb-command:continue // SECOND ITERATION -// lldb-command:print x -// lldbg-check:[...]$2 = 2 +// lldb-command:v x +// lldbg-check:[...] 2 // lldbr-check:(i32) x = 2 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$3 = -2 +// lldb-command:v x +// lldbg-check:[...] -2 // lldbr-check:(i32) x = -2 // lldb-command:continue // THIRD ITERATION -// lldb-command:print x -// lldbg-check:[...]$4 = 3 +// lldb-command:v x +// lldbg-check:[...] 3 // lldbr-check:(i32) x = 3 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$5 = -3 +// lldb-command:v x +// lldbg-check:[...] -3 // lldbr-check:(i32) x = -3 // lldb-command:continue // AFTER LOOP -// lldb-command:print x -// lldbg-check:[...]$6 = 1000000 +// lldb-command:v x +// lldbg-check:[...] 1000000 // lldbr-check:(i32) x = 1000000 // lldb-command:continue diff --git a/tests/debuginfo/lexical-scope-in-if.rs b/tests/debuginfo/lexical-scope-in-if.rs index 88b4244a503..d472a50f697 100644 --- a/tests/debuginfo/lexical-scope-in-if.rs +++ b/tests/debuginfo/lexical-scope-in-if.rs @@ -68,74 +68,74 @@ // lldb-command:run // BEFORE if -// lldb-command:print x -// lldbg-check:[...]$0 = 999 +// lldb-command:v x +// lldbg-check:[...] 999 // lldbr-check:(i32) x = 999 -// lldb-command:print y -// lldbg-check:[...]$1 = -1 +// lldb-command:v y +// lldbg-check:[...] -1 // lldbr-check:(i32) y = -1 // lldb-command:continue // AT BEGINNING of 'then' block -// lldb-command:print x -// lldbg-check:[...]$2 = 999 +// lldb-command:v x +// lldbg-check:[...] 999 // lldbr-check:(i32) x = 999 -// lldb-command:print y -// lldbg-check:[...]$3 = -1 +// lldb-command:v y +// lldbg-check:[...] -1 // lldbr-check:(i32) y = -1 // lldb-command:continue // AFTER 1st redeclaration of 'x' -// lldb-command:print x -// lldbg-check:[...]$4 = 1001 +// lldb-command:v x +// lldbg-check:[...] 1001 // lldbr-check:(i32) x = 1001 -// lldb-command:print y -// lldbg-check:[...]$5 = -1 +// lldb-command:v y +// lldbg-check:[...] -1 // lldbr-check:(i32) y = -1 // lldb-command:continue // AFTER 2st redeclaration of 'x' -// lldb-command:print x -// lldbg-check:[...]$6 = 1002 +// lldb-command:v x +// lldbg-check:[...] 1002 // lldbr-check:(i32) x = 1002 -// lldb-command:print y -// lldbg-check:[...]$7 = 1003 +// lldb-command:v y +// lldbg-check:[...] 1003 // lldbr-check:(i32) y = 1003 // lldb-command:continue // AFTER 1st if expression -// lldb-command:print x -// lldbg-check:[...]$8 = 999 +// lldb-command:v x +// lldbg-check:[...] 999 // lldbr-check:(i32) x = 999 -// lldb-command:print y -// lldbg-check:[...]$9 = -1 +// lldb-command:v y +// lldbg-check:[...] -1 // lldbr-check:(i32) y = -1 // lldb-command:continue // BEGINNING of else branch -// lldb-command:print x -// lldbg-check:[...]$10 = 999 +// lldb-command:v x +// lldbg-check:[...] 999 // lldbr-check:(i32) x = 999 -// lldb-command:print y -// lldbg-check:[...]$11 = -1 +// lldb-command:v y +// lldbg-check:[...] -1 // lldbr-check:(i32) y = -1 // lldb-command:continue // BEGINNING of else branch -// lldb-command:print x -// lldbg-check:[...]$12 = 1004 +// lldb-command:v x +// lldbg-check:[...] 1004 // lldbr-check:(i32) x = 1004 -// lldb-command:print y -// lldbg-check:[...]$13 = 1005 +// lldb-command:v y +// lldbg-check:[...] 1005 // lldbr-check:(i32) y = 1005 // lldb-command:continue // BEGINNING of else branch -// lldb-command:print x -// lldbg-check:[...]$14 = 999 +// lldb-command:v x +// lldbg-check:[...] 999 // lldbr-check:(i32) x = 999 -// lldb-command:print y -// lldbg-check:[...]$15 = -1 +// lldb-command:v y +// lldbg-check:[...] -1 // lldbr-check:(i32) y = -1 // lldb-command:continue diff --git a/tests/debuginfo/lexical-scope-in-match.rs b/tests/debuginfo/lexical-scope-in-match.rs index 8a9ecfad249..d5f0fcbe892 100644 --- a/tests/debuginfo/lexical-scope-in-match.rs +++ b/tests/debuginfo/lexical-scope-in-match.rs @@ -63,73 +63,73 @@ // lldb-command:run -// lldb-command:print shadowed -// lldbg-check:[...]$0 = 231 +// lldb-command:v shadowed +// lldbg-check:[...] 231 // lldbr-check:(i32) shadowed = 231 -// lldb-command:print not_shadowed -// lldbg-check:[...]$1 = 232 +// lldb-command:v not_shadowed +// lldbg-check:[...] 232 // lldbr-check:(i32) not_shadowed = 232 // lldb-command:continue -// lldb-command:print shadowed -// lldbg-check:[...]$2 = 233 +// lldb-command:v shadowed +// lldbg-check:[...] 233 // lldbr-check:(i32) shadowed = 233 -// lldb-command:print not_shadowed -// lldbg-check:[...]$3 = 232 +// lldb-command:v not_shadowed +// lldbg-check:[...] 232 // lldbr-check:(i32) not_shadowed = 232 -// lldb-command:print local_to_arm -// lldbg-check:[...]$4 = 234 +// lldb-command:v local_to_arm +// lldbg-check:[...] 234 // lldbr-check:(i32) local_to_arm = 234 // lldb-command:continue -// lldb-command:print shadowed -// lldbg-check:[...]$5 = 236 +// lldb-command:v shadowed +// lldbg-check:[...] 236 // lldbr-check:(i32) shadowed = 236 -// lldb-command:print not_shadowed -// lldbg-check:[...]$6 = 232 +// lldb-command:v not_shadowed +// lldbg-check:[...] 232 // lldbr-check:(i32) not_shadowed = 232 // lldb-command:continue -// lldb-command:print shadowed -// lldbg-check:[...]$7 = 237 +// lldb-command:v shadowed +// lldbg-check:[...] 237 // lldbr-check:(isize) shadowed = 237 -// lldb-command:print not_shadowed -// lldbg-check:[...]$8 = 232 +// lldb-command:v not_shadowed +// lldbg-check:[...] 232 // lldbr-check:(i32) not_shadowed = 232 -// lldb-command:print local_to_arm -// lldbg-check:[...]$9 = 238 +// lldb-command:v local_to_arm +// lldbg-check:[...] 238 // lldbr-check:(isize) local_to_arm = 238 // lldb-command:continue -// lldb-command:print shadowed -// lldbg-check:[...]$10 = 239 +// lldb-command:v shadowed +// lldbg-check:[...] 239 // lldbr-check:(isize) shadowed = 239 -// lldb-command:print not_shadowed -// lldbg-check:[...]$11 = 232 +// lldb-command:v not_shadowed +// lldbg-check:[...] 232 // lldbr-check:(i32) not_shadowed = 232 // lldb-command:continue -// lldb-command:print shadowed -// lldbg-check:[...]$12 = 241 +// lldb-command:v shadowed +// lldbg-check:[...] 241 // lldbr-check:(isize) shadowed = 241 -// lldb-command:print not_shadowed -// lldbg-check:[...]$13 = 232 +// lldb-command:v not_shadowed +// lldbg-check:[...] 232 // lldbr-check:(i32) not_shadowed = 232 // lldb-command:continue -// lldb-command:print shadowed -// lldbg-check:[...]$14 = 243 +// lldb-command:v shadowed +// lldbg-check:[...] 243 // lldbr-check:(i32) shadowed = 243 -// lldb-command:print *local_to_arm -// lldbg-check:[...]$15 = 244 +// lldb-command:v *local_to_arm +// lldbg-check:[...] 244 // lldbr-check:(i32) *local_to_arm = 244 // lldb-command:continue -// lldb-command:print shadowed -// lldbg-check:[...]$16 = 231 +// lldb-command:v shadowed +// lldbg-check:[...] 231 // lldbr-check:(i32) shadowed = 231 -// lldb-command:print not_shadowed -// lldbg-check:[...]$17 = 232 +// lldb-command:v not_shadowed +// lldbg-check:[...] 232 // lldbr-check:(i32) not_shadowed = 232 // lldb-command:continue diff --git a/tests/debuginfo/lexical-scope-in-stack-closure.rs b/tests/debuginfo/lexical-scope-in-stack-closure.rs index eeafed9f4db..92582e10c42 100644 --- a/tests/debuginfo/lexical-scope-in-stack-closure.rs +++ b/tests/debuginfo/lexical-scope-in-stack-closure.rs @@ -35,33 +35,33 @@ // lldb-command:run -// lldb-command:print x -// lldbg-check:[...]$0 = false +// lldb-command:v x +// lldbg-check:[...] false // lldbr-check:(bool) x = false // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$1 = false +// lldb-command:v x +// lldbg-check:[...] false // lldbr-check:(bool) x = false // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$2 = 1000 +// lldb-command:v x +// lldbg-check:[...] 1000 // lldbr-check:(isize) x = 1000 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$3 = 2.5 +// lldb-command:v x +// lldbg-check:[...] 2.5 // lldbr-check:(f64) x = 2.5 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$4 = true +// lldb-command:v x +// lldbg-check:[...] true // lldbr-check:(bool) x = true // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$5 = false +// lldb-command:v x +// lldbg-check:[...] false // lldbr-check:(bool) x = false // lldb-command:continue diff --git a/tests/debuginfo/lexical-scope-in-unconditional-loop.rs b/tests/debuginfo/lexical-scope-in-unconditional-loop.rs index ec998975bc7..b1af018f3eb 100644 --- a/tests/debuginfo/lexical-scope-in-unconditional-loop.rs +++ b/tests/debuginfo/lexical-scope-in-unconditional-loop.rs @@ -67,70 +67,70 @@ // lldb-command:run // FIRST ITERATION -// lldb-command:print x -// lldbg-check:[...]$0 = 0 +// lldb-command:v x +// lldbg-check:[...] 0 // lldbr-check:(i32) x = 0 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$1 = 1 +// lldb-command:v x +// lldbg-check:[...] 1 // lldbr-check:(i32) x = 1 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$2 = 101 +// lldb-command:v x +// lldbg-check:[...] 101 // lldbr-check:(i32) x = 101 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$3 = 101 +// lldb-command:v x +// lldbg-check:[...] 101 // lldbr-check:(i32) x = 101 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$4 = -987 +// lldb-command:v x +// lldbg-check:[...] -987 // lldbr-check:(i32) x = -987 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$5 = 101 +// lldb-command:v x +// lldbg-check:[...] 101 // lldbr-check:(i32) x = 101 // lldb-command:continue // SECOND ITERATION -// lldb-command:print x -// lldbg-check:[...]$6 = 1 +// lldb-command:v x +// lldbg-check:[...] 1 // lldbr-check:(i32) x = 1 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$7 = 2 +// lldb-command:v x +// lldbg-check:[...] 2 // lldbr-check:(i32) x = 2 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$8 = 102 +// lldb-command:v x +// lldbg-check:[...] 102 // lldbr-check:(i32) x = 102 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$9 = 102 +// lldb-command:v x +// lldbg-check:[...] 102 // lldbr-check:(i32) x = 102 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$10 = -987 +// lldb-command:v x +// lldbg-check:[...] -987 // lldbr-check:(i32) x = -987 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$11 = 102 +// lldb-command:v x +// lldbg-check:[...] 102 // lldbr-check:(i32) x = 102 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$12 = 2 +// lldb-command:v x +// lldbg-check:[...] 2 // lldbr-check:(i32) x = 2 // lldb-command:continue diff --git a/tests/debuginfo/lexical-scope-in-unique-closure.rs b/tests/debuginfo/lexical-scope-in-unique-closure.rs index 9376d039187..a08c2af05cc 100644 --- a/tests/debuginfo/lexical-scope-in-unique-closure.rs +++ b/tests/debuginfo/lexical-scope-in-unique-closure.rs @@ -35,33 +35,33 @@ // lldb-command:run -// lldb-command:print x -// lldbg-check:[...]$0 = false +// lldb-command:v x +// lldbg-check:[...] false // lldbr-check:(bool) x = false // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$1 = false +// lldb-command:v x +// lldbg-check:[...] false // lldbr-check:(bool) x = false // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$2 = 1000 +// lldb-command:v x +// lldbg-check:[...] 1000 // lldbr-check:(isize) x = 1000 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$3 = 2.5 +// lldb-command:v x +// lldbg-check:[...] 2.5 // lldbr-check:(f64) x = 2.5 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$4 = true +// lldb-command:v x +// lldbg-check:[...] true // lldbr-check:(bool) x = true // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$5 = false +// lldb-command:v x +// lldbg-check:[...] false // lldbr-check:(bool) x = false // lldb-command:continue diff --git a/tests/debuginfo/lexical-scope-in-while.rs b/tests/debuginfo/lexical-scope-in-while.rs index f70ef9c2dd1..bd885b5b10c 100644 --- a/tests/debuginfo/lexical-scope-in-while.rs +++ b/tests/debuginfo/lexical-scope-in-while.rs @@ -67,70 +67,70 @@ // lldb-command:run // FIRST ITERATION -// lldb-command:print x -// lldbg-check:[...]$0 = 0 +// lldb-command:v x +// lldbg-check:[...] 0 // lldbr-check:(i32) x = 0 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$1 = 1 +// lldb-command:v x +// lldbg-check:[...] 1 // lldbr-check:(i32) x = 1 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$2 = 101 +// lldb-command:v x +// lldbg-check:[...] 101 // lldbr-check:(i32) x = 101 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$3 = 101 +// lldb-command:v x +// lldbg-check:[...] 101 // lldbr-check:(i32) x = 101 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$4 = -987 +// lldb-command:v x +// lldbg-check:[...] -987 // lldbr-check:(i32) x = -987 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$5 = 101 +// lldb-command:v x +// lldbg-check:[...] 101 // lldbr-check:(i32) x = 101 // lldb-command:continue // SECOND ITERATION -// lldb-command:print x -// lldbg-check:[...]$6 = 1 +// lldb-command:v x +// lldbg-check:[...] 1 // lldbr-check:(i32) x = 1 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$7 = 2 +// lldb-command:v x +// lldbg-check:[...] 2 // lldbr-check:(i32) x = 2 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$8 = 102 +// lldb-command:v x +// lldbg-check:[...] 102 // lldbr-check:(i32) x = 102 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$9 = 102 +// lldb-command:v x +// lldbg-check:[...] 102 // lldbr-check:(i32) x = 102 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$10 = -987 +// lldb-command:v x +// lldbg-check:[...] -987 // lldbr-check:(i32) x = -987 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$11 = 102 +// lldb-command:v x +// lldbg-check:[...] 102 // lldbr-check:(i32) x = 102 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$12 = 2 +// lldb-command:v x +// lldbg-check:[...] 2 // lldbr-check:(i32) x = 2 // lldb-command:continue diff --git a/tests/debuginfo/lexical-scope-with-macro.rs b/tests/debuginfo/lexical-scope-with-macro.rs index 400dde6af31..76c923524fb 100644 --- a/tests/debuginfo/lexical-scope-with-macro.rs +++ b/tests/debuginfo/lexical-scope-with-macro.rs @@ -56,57 +56,57 @@ // lldb-command:run -// lldb-command:print a -// lldbg-check:[...]$0 = 10 +// lldb-command:v a +// lldbg-check:[...] 10 // lldbr-check:(i32) a = 10 -// lldb-command:print b -// lldbg-check:[...]$1 = 34 +// lldb-command:v b +// lldbg-check:[...] 34 // lldbr-check:(i32) b = 34 // lldb-command:continue -// lldb-command:print a -// lldbg-check:[...]$2 = 890242 +// lldb-command:v a +// lldbg-check:[...] 890242 // lldbr-check:(i32) a = 10 -// lldb-command:print b -// lldbg-check:[...]$3 = 34 +// lldb-command:v b +// lldbg-check:[...] 34 // lldbr-check:(i32) b = 34 // lldb-command:continue -// lldb-command:print a -// lldbg-check:[...]$4 = 10 +// lldb-command:v a +// lldbg-check:[...] 10 // lldbr-check:(i32) a = 10 -// lldb-command:print b -// lldbg-check:[...]$5 = 34 +// lldb-command:v b +// lldbg-check:[...] 34 // lldbr-check:(i32) b = 34 // lldb-command:continue -// lldb-command:print a -// lldbg-check:[...]$6 = 102 +// lldb-command:v a +// lldbg-check:[...] 102 // lldbr-check:(i32) a = 10 -// lldb-command:print b -// lldbg-check:[...]$7 = 34 +// lldb-command:v b +// lldbg-check:[...] 34 // lldbr-check:(i32) b = 34 // lldb-command:continue // Don't test this with rust-enabled lldb for now; see issue #48807 // lldbg-command:print a -// lldbg-check:[...]$8 = 110 +// lldbg-check:[...] 110 // lldbg-command:print b -// lldbg-check:[...]$9 = 34 +// lldbg-check:[...] 34 // lldbg-command:continue // lldbg-command:print a -// lldbg-check:[...]$10 = 10 +// lldbg-check:[...] 10 // lldbg-command:print b -// lldbg-check:[...]$11 = 34 +// lldbg-check:[...] 34 // lldbg-command:continue // lldbg-command:print a -// lldbg-check:[...]$12 = 10 +// lldbg-check:[...] 10 // lldbg-command:print b -// lldbg-check:[...]$13 = 34 +// lldbg-check:[...] 34 // lldbg-command:print c -// lldbg-check:[...]$14 = 400 +// lldbg-check:[...] 400 // lldbg-command:continue diff --git a/tests/debuginfo/lexical-scopes-in-block-expression.rs b/tests/debuginfo/lexical-scopes-in-block-expression.rs index 09cb8142474..5ff70270ea6 100644 --- a/tests/debuginfo/lexical-scopes-in-block-expression.rs +++ b/tests/debuginfo/lexical-scopes-in-block-expression.rs @@ -194,203 +194,203 @@ // lldb-command:run // STRUCT EXPRESSION -// lldb-command:print val -// lldbg-check:[...]$0 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$1 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$2 = 11 +// lldb-command:v val +// lldbg-check:[...] 11 // lldbr-check:(isize) val = 11 -// lldb-command:print ten -// lldbg-check:[...]$3 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$4 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$5 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue // FUNCTION CALL -// lldb-command:print val -// lldbg-check:[...]$6 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$7 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$8 = 12 +// lldb-command:v val +// lldbg-check:[...] 12 // lldbr-check:(isize) val = 12 -// lldb-command:print ten -// lldbg-check:[...]$9 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$10 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$11 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue // TUPLE EXPRESSION -// lldb-command:print val -// lldbg-check:[...]$12 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$13 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$14 = 13 +// lldb-command:v val +// lldbg-check:[...] 13 // lldbr-check:(isize) val = 13 -// lldb-command:print ten -// lldbg-check:[...]$15 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$16 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$17 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue // VEC EXPRESSION -// lldb-command:print val -// lldbg-check:[...]$18 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$19 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$20 = 14 +// lldb-command:v val +// lldbg-check:[...] 14 // lldbr-check:(isize) val = 14 -// lldb-command:print ten -// lldbg-check:[...]$21 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$22 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$23 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue // REPEAT VEC EXPRESSION -// lldb-command:print val -// lldbg-check:[...]$24 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$25 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$26 = 15 +// lldb-command:v val +// lldbg-check:[...] 15 // lldbr-check:(isize) val = 15 -// lldb-command:print ten -// lldbg-check:[...]$27 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$28 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$29 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue // ASSIGNMENT EXPRESSION -// lldb-command:print val -// lldbg-check:[...]$30 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$31 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$32 = 16 +// lldb-command:v val +// lldbg-check:[...] 16 // lldbr-check:(isize) val = 16 -// lldb-command:print ten -// lldbg-check:[...]$33 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$34 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$35 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue // ARITHMETIC EXPRESSION -// lldb-command:print val -// lldbg-check:[...]$36 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$37 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$38 = 17 +// lldb-command:v val +// lldbg-check:[...] 17 // lldbr-check:(isize) val = 17 -// lldb-command:print ten -// lldbg-check:[...]$39 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$40 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$41 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue // INDEX EXPRESSION -// lldb-command:print val -// lldbg-check:[...]$42 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$43 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$44 = 18 +// lldb-command:v val +// lldbg-check:[...] 18 // lldbr-check:(isize) val = 18 -// lldb-command:print ten -// lldbg-check:[...]$45 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue -// lldb-command:print val -// lldbg-check:[...]$46 = -1 +// lldb-command:v val +// lldbg-check:[...] -1 // lldbr-check:(i32) val = -1 -// lldb-command:print ten -// lldbg-check:[...]$47 = 10 +// lldb-command:v ten +// lldbg-check:[...] 10 // lldbr-check:(isize) ten = 10 // lldb-command:continue diff --git a/tests/debuginfo/macro-stepping.rs b/tests/debuginfo/macro-stepping.rs index 69cabd92298..71ff9798079 100644 --- a/tests/debuginfo/macro-stepping.rs +++ b/tests/debuginfo/macro-stepping.rs @@ -56,36 +56,36 @@ extern crate macro_stepping; // exports new_scope!() // lldb-command:run // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#loc1[...] +// lldb-check:[...] #loc1 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#loc2[...] +// lldb-check:[...] #loc2 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#loc3[...] +// lldb-check:[...] #loc3 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#loc4[...] +// lldb-check:[...] #loc4 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#loc5[...] +// lldb-check:[...] #loc5 [...] // lldb-command:continue // lldb-command:step // lldb-command:frame select -// lldb-check:[...]#inc-loc1[...] +// lldb-check:[...] #inc-loc1 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#inc-loc2[...] +// lldb-check:[...] #inc-loc2 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#inc-loc1[...] +// lldb-check:[...] #inc-loc1 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#inc-loc2[...] +// lldb-check:[...] #inc-loc2 [...] // lldb-command:next // lldb-command:frame select -// lldb-check:[...]#inc-loc3[...] +// lldb-check:[...] #inc-loc3 [...] macro_rules! foo { () => { diff --git a/tests/debuginfo/method-on-enum.rs b/tests/debuginfo/method-on-enum.rs index 454967c6cb7..8a57060717e 100644 --- a/tests/debuginfo/method-on-enum.rs +++ b/tests/debuginfo/method-on-enum.rs @@ -63,48 +63,48 @@ // lldb-command:run // STACK BY REF -// lldb-command:print *self -// lldb-check:[...]$0 = Variant2(117901063) -// lldb-command:print arg1 -// lldb-check:[...]$1 = -1 -// lldb-command:print arg2 -// lldb-check:[...]$2 = -2 +// lldb-command:v *self +// lldb-check:[...] Variant2(117901063) +// lldb-command:v arg1 +// lldb-check:[...] -1 +// lldb-command:v arg2 +// lldb-check:[...] -2 // lldb-command:continue // STACK BY VAL -// lldb-command:print self -// lldb-check:[...]$3 = Variant2(117901063) -// lldb-command:print arg1 -// lldb-check:[...]$4 = -3 -// lldb-command:print arg2 -// lldb-check:[...]$5 = -4 +// lldb-command:v self +// lldb-check:[...] Variant2(117901063) +// lldb-command:v arg1 +// lldb-check:[...] -3 +// lldb-command:v arg2 +// lldb-check:[...] -4 // lldb-command:continue // OWNED BY REF -// lldb-command:print *self -// lldb-check:[...]$6 = Variant1 { x: 1799, y: 1799 } -// lldb-command:print arg1 -// lldb-check:[...]$7 = -5 -// lldb-command:print arg2 -// lldb-check:[...]$8 = -6 +// lldb-command:v *self +// lldb-check:[...] Variant1 { x: 1799, y: 1799 } +// lldb-command:v arg1 +// lldb-check:[...] -5 +// lldb-command:v arg2 +// lldb-check:[...] -6 // lldb-command:continue // OWNED BY VAL -// lldb-command:print self -// lldb-check:[...]$9 = Variant1 { x: 1799, y: 1799 } -// lldb-command:print arg1 -// lldb-check:[...]$10 = -7 -// lldb-command:print arg2 -// lldb-check:[...]$11 = -8 +// lldb-command:v self +// lldb-check:[...] Variant1 { x: 1799, y: 1799 } +// lldb-command:v arg1 +// lldb-check:[...] -7 +// lldb-command:v arg2 +// lldb-check:[...] -8 // lldb-command:continue // OWNED MOVED -// lldb-command:print *self -// lldb-check:[...]$12 = Variant1 { x: 1799, y: 1799 } -// lldb-command:print arg1 -// lldb-check:[...]$13 = -9 -// lldb-command:print arg2 -// lldb-check:[...]$14 = -10 +// lldb-command:v *self +// lldb-check:[...] Variant1 { x: 1799, y: 1799 } +// lldb-command:v arg1 +// lldb-check:[...] -9 +// lldb-command:v arg2 +// lldb-check:[...] -10 // lldb-command:continue #![feature(omit_gdb_pretty_printer_section)] diff --git a/tests/debuginfo/method-on-generic-struct.rs b/tests/debuginfo/method-on-generic-struct.rs index 562798c27da..64ef0e6bb0c 100644 --- a/tests/debuginfo/method-on-generic-struct.rs +++ b/tests/debuginfo/method-on-generic-struct.rs @@ -64,62 +64,62 @@ // lldb-command:run // STACK BY REF -// lldb-command:print *self -// lldbg-check:[...]$0 = Struct<(u32, i32)> { x: (8888, -8888) } +// lldb-command:v *self +// lldbg-check:[...] Struct<(u32, i32)> { x: (8888, -8888) } // lldbr-check:(method_on_generic_struct::Struct<(u32, i32)>) *self = { x = { = 8888 = -8888 } } -// lldb-command:print arg1 -// lldbg-check:[...]$1 = -1 +// lldb-command:v arg1 +// lldbg-check:[...] -1 // lldbr-check:(isize) arg1 = -1 -// lldb-command:print arg2 -// lldbg-check:[...]$2 = -2 +// lldb-command:v arg2 +// lldbg-check:[...] -2 // lldbr-check:(isize) arg2 = -2 // lldb-command:continue // STACK BY VAL -// lldb-command:print self -// lldbg-check:[...]$3 = Struct<(u32, i32)> { x: (8888, -8888) } +// lldb-command:v self +// lldbg-check:[...] Struct<(u32, i32)> { x: (8888, -8888) } // lldbr-check:(method_on_generic_struct::Struct<(u32, i32)>) self = { x = { = 8888 = -8888 } } -// lldb-command:print arg1 -// lldbg-check:[...]$4 = -3 +// lldb-command:v arg1 +// lldbg-check:[...] -3 // lldbr-check:(isize) arg1 = -3 -// lldb-command:print arg2 -// lldbg-check:[...]$5 = -4 +// lldb-command:v arg2 +// lldbg-check:[...] -4 // lldbr-check:(isize) arg2 = -4 // lldb-command:continue // OWNED BY REF -// lldb-command:print *self -// lldbg-check:[...]$6 = Struct<f64> { x: 1234.5 } +// lldb-command:v *self +// lldbg-check:[...] Struct<f64> { x: 1234.5 } // lldbr-check:(method_on_generic_struct::Struct<f64>) *self = Struct<f64> { x: 1234.5 } -// lldb-command:print arg1 -// lldbg-check:[...]$7 = -5 +// lldb-command:v arg1 +// lldbg-check:[...] -5 // lldbr-check:(isize) arg1 = -5 -// lldb-command:print arg2 -// lldbg-check:[...]$8 = -6 +// lldb-command:v arg2 +// lldbg-check:[...] -6 // lldbr-check:(isize) arg2 = -6 // lldb-command:continue // OWNED BY VAL -// lldb-command:print self -// lldbg-check:[...]$9 = Struct<f64> { x: 1234.5 } +// lldb-command:v self +// lldbg-check:[...] Struct<f64> { x: 1234.5 } // lldbr-check:(method_on_generic_struct::Struct<f64>) self = Struct<f64> { x: 1234.5 } -// lldb-command:print arg1 -// lldbg-check:[...]$10 = -7 +// lldb-command:v arg1 +// lldbg-check:[...] -7 // lldbr-check:(isize) arg1 = -7 -// lldb-command:print arg2 -// lldbg-check:[...]$11 = -8 +// lldb-command:v arg2 +// lldbg-check:[...] -8 // lldbr-check:(isize) arg2 = -8 // lldb-command:continue // OWNED MOVED -// lldb-command:print *self -// lldbg-check:[...]$12 = Struct<f64> { x: 1234.5 } +// lldb-command:v *self +// lldbg-check:[...] Struct<f64> { x: 1234.5 } // lldbr-check:(method_on_generic_struct::Struct<f64>) *self = Struct<f64> { x: 1234.5 } -// lldb-command:print arg1 -// lldbg-check:[...]$13 = -9 +// lldb-command:v arg1 +// lldbg-check:[...] -9 // lldbr-check:(isize) arg1 = -9 -// lldb-command:print arg2 -// lldbg-check:[...]$14 = -10 +// lldb-command:v arg2 +// lldbg-check:[...] -10 // lldbr-check:(isize) arg2 = -10 // lldb-command:continue diff --git a/tests/debuginfo/method-on-struct.rs b/tests/debuginfo/method-on-struct.rs index bb94ced305d..a4129af5429 100644 --- a/tests/debuginfo/method-on-struct.rs +++ b/tests/debuginfo/method-on-struct.rs @@ -62,62 +62,62 @@ // lldb-command:run // STACK BY REF -// lldb-command:print *self -// lldbg-check:[...]$0 = { x = 100 } +// lldb-command:v *self +// lldbg-check:[...] { x = 100 } // lldbr-check:(method_on_struct::Struct) *self = Struct { x: 100 } -// lldb-command:print arg1 -// lldbg-check:[...]$1 = -1 +// lldb-command:v arg1 +// lldbg-check:[...] -1 // lldbr-check:(isize) arg1 = -1 -// lldb-command:print arg2 -// lldbg-check:[...]$2 = -2 +// lldb-command:v arg2 +// lldbg-check:[...] -2 // lldbr-check:(isize) arg2 = -2 // lldb-command:continue // STACK BY VAL -// lldb-command:print self -// lldbg-check:[...]$3 = { x = 100 } +// lldb-command:v self +// lldbg-check:[...] { x = 100 } // lldbr-check:(method_on_struct::Struct) self = Struct { x: 100 } -// lldb-command:print arg1 -// lldbg-check:[...]$4 = -3 +// lldb-command:v arg1 +// lldbg-check:[...] -3 // lldbr-check:(isize) arg1 = -3 -// lldb-command:print arg2 -// lldbg-check:[...]$5 = -4 +// lldb-command:v arg2 +// lldbg-check:[...] -4 // lldbr-check:(isize) arg2 = -4 // lldb-command:continue // OWNED BY REF -// lldb-command:print *self -// lldbg-check:[...]$6 = { x = 200 } +// lldb-command:v *self +// lldbg-check:[...] { x = 200 } // lldbr-check:(method_on_struct::Struct) *self = Struct { x: 200 } -// lldb-command:print arg1 -// lldbg-check:[...]$7 = -5 +// lldb-command:v arg1 +// lldbg-check:[...] -5 // lldbr-check:(isize) arg1 = -5 -// lldb-command:print arg2 -// lldbg-check:[...]$8 = -6 +// lldb-command:v arg2 +// lldbg-check:[...] -6 // lldbr-check:(isize) arg2 = -6 // lldb-command:continue // OWNED BY VAL -// lldb-command:print self -// lldbg-check:[...]$9 = { x = 200 } +// lldb-command:v self +// lldbg-check:[...] { x = 200 } // lldbr-check:(method_on_struct::Struct) self = Struct { x: 200 } -// lldb-command:print arg1 -// lldbg-check:[...]$10 = -7 +// lldb-command:v arg1 +// lldbg-check:[...] -7 // lldbr-check:(isize) arg1 = -7 -// lldb-command:print arg2 -// lldbg-check:[...]$11 = -8 +// lldb-command:v arg2 +// lldbg-check:[...] -8 // lldbr-check:(isize) arg2 = -8 // lldb-command:continue // OWNED MOVED -// lldb-command:print *self -// lldbg-check:[...]$12 = { x = 200 } +// lldb-command:v *self +// lldbg-check:[...] { x = 200 } // lldbr-check:(method_on_struct::Struct) *self = Struct { x: 200 } -// lldb-command:print arg1 -// lldbg-check:[...]$13 = -9 +// lldb-command:v arg1 +// lldbg-check:[...] -9 // lldbr-check:(isize) arg1 = -9 -// lldb-command:print arg2 -// lldbg-check:[...]$14 = -10 +// lldb-command:v arg2 +// lldbg-check:[...] -10 // lldbr-check:(isize) arg2 = -10 // lldb-command:continue diff --git a/tests/debuginfo/method-on-trait.rs b/tests/debuginfo/method-on-trait.rs index bc8def40105..0934c267ab1 100644 --- a/tests/debuginfo/method-on-trait.rs +++ b/tests/debuginfo/method-on-trait.rs @@ -62,62 +62,62 @@ // lldb-command:run // STACK BY REF -// lldb-command:print *self -// lldbg-check:[...]$0 = { x = 100 } +// lldb-command:v *self +// lldbg-check:[...] { x = 100 } // lldbr-check:(method_on_trait::Struct) *self = { x = 100 } -// lldb-command:print arg1 -// lldbg-check:[...]$1 = -1 +// lldb-command:v arg1 +// lldbg-check:[...] -1 // lldbr-check:(isize) arg1 = -1 -// lldb-command:print arg2 -// lldbg-check:[...]$2 = -2 +// lldb-command:v arg2 +// lldbg-check:[...] -2 // lldbr-check:(isize) arg2 = -2 // lldb-command:continue // STACK BY VAL -// lldb-command:print self -// lldbg-check:[...]$3 = { x = 100 } +// lldb-command:v self +// lldbg-check:[...] { x = 100 } // lldbr-check:(method_on_trait::Struct) self = { x = 100 } -// lldb-command:print arg1 -// lldbg-check:[...]$4 = -3 +// lldb-command:v arg1 +// lldbg-check:[...] -3 // lldbr-check:(isize) arg1 = -3 -// lldb-command:print arg2 -// lldbg-check:[...]$5 = -4 +// lldb-command:v arg2 +// lldbg-check:[...] -4 // lldbr-check:(isize) arg2 = -4 // lldb-command:continue // OWNED BY REF -// lldb-command:print *self -// lldbg-check:[...]$6 = { x = 200 } +// lldb-command:v *self +// lldbg-check:[...] { x = 200 } // lldbr-check:(method_on_trait::Struct) *self = { x = 200 } -// lldb-command:print arg1 -// lldbg-check:[...]$7 = -5 +// lldb-command:v arg1 +// lldbg-check:[...] -5 // lldbr-check:(isize) arg1 = -5 -// lldb-command:print arg2 -// lldbg-check:[...]$8 = -6 +// lldb-command:v arg2 +// lldbg-check:[...] -6 // lldbr-check:(isize) arg2 = -6 // lldb-command:continue // OWNED BY VAL -// lldb-command:print self -// lldbg-check:[...]$9 = { x = 200 } +// lldb-command:v self +// lldbg-check:[...] { x = 200 } // lldbr-check:(method_on_trait::Struct) self = { x = 200 } -// lldb-command:print arg1 -// lldbg-check:[...]$10 = -7 +// lldb-command:v arg1 +// lldbg-check:[...] -7 // lldbr-check:(isize) arg1 = -7 -// lldb-command:print arg2 -// lldbg-check:[...]$11 = -8 +// lldb-command:v arg2 +// lldbg-check:[...] -8 // lldbr-check:(isize) arg2 = -8 // lldb-command:continue // OWNED MOVED -// lldb-command:print *self -// lldbg-check:[...]$12 = { x = 200 } +// lldb-command:v *self +// lldbg-check:[...] { x = 200 } // lldbr-check:(method_on_trait::Struct) *self = { x = 200 } -// lldb-command:print arg1 -// lldbg-check:[...]$13 = -9 +// lldb-command:v arg1 +// lldbg-check:[...] -9 // lldbr-check:(isize) arg1 = -9 -// lldb-command:print arg2 -// lldbg-check:[...]$14 = -10 +// lldb-command:v arg2 +// lldbg-check:[...] -10 // lldbr-check:(isize) arg2 = -10 // lldb-command:continue diff --git a/tests/debuginfo/method-on-tuple-struct.rs b/tests/debuginfo/method-on-tuple-struct.rs index 7ac0a2d8574..9cf9c6d7fba 100644 --- a/tests/debuginfo/method-on-tuple-struct.rs +++ b/tests/debuginfo/method-on-tuple-struct.rs @@ -62,62 +62,62 @@ // lldb-command:run // STACK BY REF -// lldb-command:print *self -// lldbg-check:[...]$0 = { 0 = 100 1 = -100.5 } +// lldb-command:v *self +// lldbg-check:[...] { 0 = 100 1 = -100.5 } // lldbr-check:(method_on_tuple_struct::TupleStruct) *self = { 0 = 100 1 = -100.5 } -// lldb-command:print arg1 -// lldbg-check:[...]$1 = -1 +// lldb-command:v arg1 +// lldbg-check:[...] -1 // lldbr-check:(isize) arg1 = -1 -// lldb-command:print arg2 -// lldbg-check:[...]$2 = -2 +// lldb-command:v arg2 +// lldbg-check:[...] -2 // lldbr-check:(isize) arg2 = -2 // lldb-command:continue // STACK BY VAL -// lldb-command:print self -// lldbg-check:[...]$3 = { 0 = 100 1 = -100.5 } +// lldb-command:v self +// lldbg-check:[...] { 0 = 100 1 = -100.5 } // lldbr-check:(method_on_tuple_struct::TupleStruct) self = { 0 = 100 1 = -100.5 } -// lldb-command:print arg1 -// lldbg-check:[...]$4 = -3 +// lldb-command:v arg1 +// lldbg-check:[...] -3 // lldbr-check:(isize) arg1 = -3 -// lldb-command:print arg2 -// lldbg-check:[...]$5 = -4 +// lldb-command:v arg2 +// lldbg-check:[...] -4 // lldbr-check:(isize) arg2 = -4 // lldb-command:continue // OWNED BY REF -// lldb-command:print *self -// lldbg-check:[...]$6 = { 0 = 200 1 = -200.5 } +// lldb-command:v *self +// lldbg-check:[...] { 0 = 200 1 = -200.5 } // lldbr-check:(method_on_tuple_struct::TupleStruct) *self = { 0 = 200 1 = -200.5 } -// lldb-command:print arg1 -// lldbg-check:[...]$7 = -5 +// lldb-command:v arg1 +// lldbg-check:[...] -5 // lldbr-check:(isize) arg1 = -5 -// lldb-command:print arg2 -// lldbg-check:[...]$8 = -6 +// lldb-command:v arg2 +// lldbg-check:[...] -6 // lldbr-check:(isize) arg2 = -6 // lldb-command:continue // OWNED BY VAL -// lldb-command:print self -// lldbg-check:[...]$9 = { 0 = 200 1 = -200.5 } +// lldb-command:v self +// lldbg-check:[...] { 0 = 200 1 = -200.5 } // lldbr-check:(method_on_tuple_struct::TupleStruct) self = { 0 = 200 1 = -200.5 } -// lldb-command:print arg1 -// lldbg-check:[...]$10 = -7 +// lldb-command:v arg1 +// lldbg-check:[...] -7 // lldbr-check:(isize) arg1 = -7 -// lldb-command:print arg2 -// lldbg-check:[...]$11 = -8 +// lldb-command:v arg2 +// lldbg-check:[...] -8 // lldbr-check:(isize) arg2 = -8 // lldb-command:continue // OWNED MOVED -// lldb-command:print *self -// lldbg-check:[...]$12 = { 0 = 200 1 = -200.5 } +// lldb-command:v *self +// lldbg-check:[...] { 0 = 200 1 = -200.5 } // lldbr-check:(method_on_tuple_struct::TupleStruct) *self = { 0 = 200 1 = -200.5 } -// lldb-command:print arg1 -// lldbg-check:[...]$13 = -9 +// lldb-command:v arg1 +// lldbg-check:[...] -9 // lldbr-check:(isize) arg1 = -9 -// lldb-command:print arg2 -// lldbg-check:[...]$14 = -10 +// lldb-command:v arg2 +// lldbg-check:[...] -10 // lldbr-check:(isize) arg2 = -10 // lldb-command:continue diff --git a/tests/debuginfo/multi-cgu.rs b/tests/debuginfo/multi-cgu.rs index b2ad1d3cd95..32fd6895877 100644 --- a/tests/debuginfo/multi-cgu.rs +++ b/tests/debuginfo/multi-cgu.rs @@ -23,13 +23,13 @@ // lldb-command:run -// lldb-command:print xxx -// lldbg-check:[...]$0 = 12345 +// lldb-command:v xxx +// lldbg-check:[...] 12345 // lldbr-check:(u32) xxx = 12345 // lldb-command:continue -// lldb-command:print yyy -// lldbg-check:[...]$1 = 67890 +// lldb-command:v yyy +// lldbg-check:[...] 67890 // lldbr-check:(u64) yyy = 67890 // lldb-command:continue diff --git a/tests/debuginfo/multiple-functions-equal-var-names.rs b/tests/debuginfo/multiple-functions-equal-var-names.rs index 08446997b42..2d9caf75290 100644 --- a/tests/debuginfo/multiple-functions-equal-var-names.rs +++ b/tests/debuginfo/multiple-functions-equal-var-names.rs @@ -22,18 +22,18 @@ // lldb-command:run -// lldb-command:print abc -// lldbg-check:[...]$0 = 10101 +// lldb-command:v abc +// lldbg-check:[...] 10101 // lldbr-check:(i32) abc = 10101 // lldb-command:continue -// lldb-command:print abc -// lldbg-check:[...]$1 = 20202 +// lldb-command:v abc +// lldbg-check:[...] 20202 // lldbr-check:(i32) abc = 20202 // lldb-command:continue -// lldb-command:print abc -// lldbg-check:[...]$2 = 30303 +// lldb-command:v abc +// lldbg-check:[...] 30303 // lldbr-check:(i32) abc = 30303 #![allow(unused_variables)] diff --git a/tests/debuginfo/multiple-functions.rs b/tests/debuginfo/multiple-functions.rs index 2c4092fd5a3..5c01a427051 100644 --- a/tests/debuginfo/multiple-functions.rs +++ b/tests/debuginfo/multiple-functions.rs @@ -22,18 +22,18 @@ // lldb-command:run -// lldb-command:print a -// lldbg-check:[...]$0 = 10101 +// lldb-command:v a +// lldbg-check:[...] 10101 // lldbr-check:(i32) a = 10101 // lldb-command:continue -// lldb-command:print b -// lldbg-check:[...]$1 = 20202 +// lldb-command:v b +// lldbg-check:[...] 20202 // lldbr-check:(i32) b = 20202 // lldb-command:continue -// lldb-command:print c -// lldbg-check:[...]$2 = 30303 +// lldb-command:v c +// lldbg-check:[...] 30303 // lldbr-check:(i32) c = 30303 #![allow(unused_variables)] diff --git a/tests/debuginfo/name-shadowing-and-scope-nesting.rs b/tests/debuginfo/name-shadowing-and-scope-nesting.rs index e8860b2d104..8813793e59e 100644 --- a/tests/debuginfo/name-shadowing-and-scope-nesting.rs +++ b/tests/debuginfo/name-shadowing-and-scope-nesting.rs @@ -47,51 +47,51 @@ // lldb-command:run -// lldb-command:print x -// lldbg-check:[...]$0 = false +// lldb-command:v x +// lldbg-check:[...] false // lldbr-check:(bool) x = false -// lldb-command:print y -// lldbg-check:[...]$1 = true +// lldb-command:v y +// lldbg-check:[...] true // lldbr-check:(bool) y = true // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$2 = 10 +// lldb-command:v x +// lldbg-check:[...] 10 // lldbr-check:(i32) x = 10 -// lldb-command:print y -// lldbg-check:[...]$3 = true +// lldb-command:v y +// lldbg-check:[...] true // lldbr-check:(bool) y = true // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$4 = 10.5 +// lldb-command:v x +// lldbg-check:[...] 10.5 // lldbr-check:(f64) x = 10.5 -// lldb-command:print y -// lldbg-check:[...]$5 = 20 +// lldb-command:v y +// lldbg-check:[...] 20 // lldbr-check:(i32) y = 20 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$6 = true +// lldb-command:v x +// lldbg-check:[...] true // lldbr-check:(bool) x = true -// lldb-command:print y -// lldbg-check:[...]$7 = 2220 +// lldb-command:v y +// lldbg-check:[...] 2220 // lldbr-check:(i32) y = 2220 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$8 = 203203.5 +// lldb-command:v x +// lldbg-check:[...] 203203.5 // lldbr-check:(f64) x = 203203.5 -// lldb-command:print y -// lldbg-check:[...]$9 = 2220 +// lldb-command:v y +// lldbg-check:[...] 2220 // lldbr-check:(i32) y = 2220 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$10 = 10.5 +// lldb-command:v x +// lldbg-check:[...] 10.5 // lldbr-check:(f64) x = 10.5 -// lldb-command:print y -// lldbg-check:[...]$11 = 20 +// lldb-command:v y +// lldbg-check:[...] 20 // lldbr-check:(i32) y = 20 // lldb-command:continue diff --git a/tests/debuginfo/no_mangle-info.rs b/tests/debuginfo/no_mangle-info.rs index 15629d217ba..06c65a71b2e 100644 --- a/tests/debuginfo/no_mangle-info.rs +++ b/tests/debuginfo/no_mangle-info.rs @@ -10,10 +10,10 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:p TEST -// lldb-check: (unsigned long) $0 = 3735928559 -// lldb-command:p OTHER_TEST -// lldb-check: (unsigned long) $1 = 42 +// lldb-command:v TEST +// lldb-check:(unsigned long) TEST = 3735928559 +// lldb-command:v OTHER_TEST +// lldb-check:(unsigned long) no_mangle_info::namespace::OTHER_TEST::[...] = 42 // === CDB TESTS ================================================================================== // cdb-command: g diff --git a/tests/debuginfo/numeric-types.rs b/tests/debuginfo/numeric-types.rs index 74c9e5e1dc3..1ff72d34fbd 100644 --- a/tests/debuginfo/numeric-types.rs +++ b/tests/debuginfo/numeric-types.rs @@ -202,41 +202,41 @@ // lldb-command:run -// lldb-command:print/d nz_i8 -// lldb-check:[...]$0 = 11 { __0 = 11 } +// lldb-command:v/d nz_i8 +// lldb-check:[...] 11 { __0 = { 0 = 11 } } -// lldb-command:print nz_i16 -// lldb-check:[...]$1 = 22 { __0 = 22 } +// lldb-command:v nz_i16 +// lldb-check:[...] 22 { __0 = { 0 = 22 } } -// lldb-command:print nz_i32 -// lldb-check:[...]$2 = 33 { __0 = 33 } +// lldb-command:v nz_i32 +// lldb-check:[...] 33 { __0 = { 0 = 33 } } -// lldb-command:print nz_i64 -// lldb-check:[...]$3 = 44 { __0 = 44 } +// lldb-command:v nz_i64 +// lldb-check:[...] 44 { __0 = { 0 = 44 } } -// lldb-command:print nz_i128 -// lldb-check:[...]$4 = 55 { __0 = 55 } +// lldb-command:v nz_i128 +// lldb-check:[...] 55 { __0 = { 0 = 55 } } -// lldb-command:print nz_isize -// lldb-check:[...]$5 = 66 { __0 = 66 } +// lldb-command:v nz_isize +// lldb-check:[...] 66 { __0 = { 0 = 66 } } -// lldb-command:print/d nz_u8 -// lldb-check:[...]$6 = 77 { __0 = 77 } +// lldb-command:v/d nz_u8 +// lldb-check:[...] 77 { __0 = { 0 = 77 } } -// lldb-command:print nz_u16 -// lldb-check:[...]$7 = 88 { __0 = 88 } +// lldb-command:v nz_u16 +// lldb-check:[...] 88 { __0 = { 0 = 88 } } -// lldb-command:print nz_u32 -// lldb-check:[...]$8 = 99 { __0 = 99 } +// lldb-command:v nz_u32 +// lldb-check:[...] 99 { __0 = { 0 = 99 } } -// lldb-command:print nz_u64 -// lldb-check:[...]$9 = 100 { __0 = 100 } +// lldb-command:v nz_u64 +// lldb-check:[...] 100 { __0 = { 0 = 100 } } -// lldb-command:print nz_u128 -// lldb-check:[...]$10 = 111 { __0 = 111 } +// lldb-command:v nz_u128 +// lldb-check:[...] 111 { __0 = { 0 = 111 } } -// lldb-command:print nz_usize -// lldb-check:[...]$11 = 122 { __0 = 122 } +// lldb-command:v nz_usize +// lldb-check:[...] 122 { __0 = { 0 = 122 } } #![feature(generic_nonzero)] use std::num::*; diff --git a/tests/debuginfo/option-like-enum.rs b/tests/debuginfo/option-like-enum.rs index b2a8aa1c29a..c782796f473 100644 --- a/tests/debuginfo/option-like-enum.rs +++ b/tests/debuginfo/option-like-enum.rs @@ -47,35 +47,35 @@ // lldb-command:run -// lldb-command:print some -// lldb-check:[...]$0 = Some(&0x12345678) +// lldb-command:v some +// lldb-check:[...] Some(&0x12345678) -// lldb-command:print none -// lldb-check:[...]$1 = None +// lldb-command:v none +// lldb-check:[...] None -// lldb-command:print full -// lldb-check:[...]$2 = Full(454545, &0x87654321, 9988) +// lldb-command:v full +// lldb-check:[...] Full(454545, &0x87654321, 9988) -// lldb-command:print empty -// lldb-check:[...]$3 = Empty +// lldb-command:v empty +// lldb-check:[...] Empty -// lldb-command:print droid -// lldb-check:[...]$4 = Droid { id: 675675, range: 10000001, internals: &0x43218765 } +// lldb-command:v droid +// lldb-check:[...] Droid { id: 675675, range: 10000001, internals: &0x43218765 } -// lldb-command:print void_droid -// lldb-check:[...]$5 = Void +// lldb-command:v void_droid +// lldb-check:[...] Void -// lldb-command:print some_str -// lldb-check:[...]$6 = Some("abc") +// lldb-command:v some_str +// lldb-check:[...] Some("abc") -// lldb-command:print none_str -// lldb-check:[...]$7 = None +// lldb-command:v none_str +// lldb-check:[...] None -// lldb-command:print nested_non_zero_yep -// lldb-check:[...]$8 = Yep(10.5, NestedNonZeroField { a: 10, b: 20, c: &[...] }) +// lldb-command:v nested_non_zero_yep +// lldb-check:[...] Yep(10.5, NestedNonZeroField { a: 10, b: 20, c: &[...] }) -// lldb-command:print nested_non_zero_nope -// lldb-check:[...]$9 = Nope +// lldb-command:v nested_non_zero_nope +// lldb-check:[...] Nope #![feature(omit_gdb_pretty_printer_section)] diff --git a/tests/debuginfo/packed-struct-with-destructor.rs b/tests/debuginfo/packed-struct-with-destructor.rs index 19788339efa..f9bac844376 100644 --- a/tests/debuginfo/packed-struct-with-destructor.rs +++ b/tests/debuginfo/packed-struct-with-destructor.rs @@ -44,36 +44,36 @@ // lldb-command:run -// lldb-command:print packed -// lldbg-check:[...]$0 = { x = 123 y = 234 z = 345 } +// lldb-command:v packed +// lldbg-check:[...] { x = 123 y = 234 z = 345 } // lldbr-check:(packed_struct_with_destructor::Packed) packed = { x = 123 y = 234 z = 345 } -// lldb-command:print packedInPacked -// lldbg-check:[...]$1 = { a = 1111 b = { x = 2222 y = 3333 z = 4444 } c = 5555 d = { x = 6666 y = 7777 z = 8888 } } +// lldb-command:v packedInPacked +// lldbg-check:[...] { a = 1111 b = { x = 2222 y = 3333 z = 4444 } c = 5555 d = { x = 6666 y = 7777 z = 8888 } } // lldbr-check:(packed_struct_with_destructor::PackedInPacked) packedInPacked = { a = 1111 b = { x = 2222 y = 3333 z = 4444 } c = 5555 d = { x = 6666 y = 7777 z = 8888 } } -// lldb-command:print packedInUnpacked -// lldbg-check:[...]$2 = { a = -1111 b = { x = -2222 y = -3333 z = -4444 } c = -5555 d = { x = -6666 y = -7777 z = -8888 } } +// lldb-command:v packedInUnpacked +// lldbg-check:[...] { a = -1111 b = { x = -2222 y = -3333 z = -4444 } c = -5555 d = { x = -6666 y = -7777 z = -8888 } } // lldbr-check:(packed_struct_with_destructor::PackedInUnpacked) packedInUnpacked = { a = -1111 b = { x = -2222 y = -3333 z = -4444 } c = -5555 d = { x = -6666 y = -7777 z = -8888 } } -// lldb-command:print unpackedInPacked -// lldbg-check:[...]$3 = { a = 987 b = { x = 876 y = 765 z = 654 } c = { x = 543 y = 432 z = 321 } d = 210 } +// lldb-command:v unpackedInPacked +// lldbg-check:[...] { a = 987 b = { x = 876 y = 765 z = 654 } c = { x = 543 y = 432 z = 321 } d = 210 } // lldbr-check:(packed_struct_with_destructor::UnpackedInPacked) unpackedInPacked = { a = 987 b = { x = 876 y = 765 z = 654 } c = { x = 543 y = 432 z = 321 } d = 210 } -// lldb-command:print packedInPackedWithDrop -// lldbg-check:[...]$4 = { a = 11 b = { x = 22 y = 33 z = 44 } c = 55 d = { x = 66 y = 77 z = 88 } } +// lldb-command:v packedInPackedWithDrop +// lldbg-check:[...] { a = 11 b = { x = 22 y = 33 z = 44 } c = 55 d = { x = 66 y = 77 z = 88 } } // lldbr-check:(packed_struct_with_destructor::PackedInPackedWithDrop) packedInPackedWithDrop = { a = 11 b = { x = 22 y = 33 z = 44 } c = 55 d = { x = 66 y = 77 z = 88 } } -// lldb-command:print packedInUnpackedWithDrop -// lldbg-check:[...]$5 = { a = -11 b = { x = -22 y = -33 z = -44 } c = -55 d = { x = -66 y = -77 z = -88 } } +// lldb-command:v packedInUnpackedWithDrop +// lldbg-check:[...] { a = -11 b = { x = -22 y = -33 z = -44 } c = -55 d = { x = -66 y = -77 z = -88 } } // lldbr-check:(packed_struct_with_destructor::PackedInUnpackedWithDrop) packedInUnpackedWithDrop = { a = -11 b = { x = -22 y = -33 z = -44 } c = -55 d = { x = -66 y = -77 z = -88 } } -// lldb-command:print unpackedInPackedWithDrop -// lldbg-check:[...]$6 = { a = 98 b = { x = 87 y = 76 z = 65 } c = { x = 54 y = 43 z = 32 } d = 21 } +// lldb-command:v unpackedInPackedWithDrop +// lldbg-check:[...] { a = 98 b = { x = 87 y = 76 z = 65 } c = { x = 54 y = 43 z = 32 } d = 21 } // lldbr-check:(packed_struct_with_destructor::UnpackedInPackedWithDrop) unpackedInPackedWithDrop = { a = 98 b = { x = 87 y = 76 z = 65 } c = { x = 54 y = 43 z = 32 } d = 21 } -// lldb-command:print deeplyNested -// lldbg-check:[...]$7 = { a = { a = 1 b = { x = 2 y = 3 z = 4 } c = 5 d = { x = 6 y = 7 z = 8 } } b = { a = 9 b = { x = 10 y = 11 z = 12 } c = { x = 13 y = 14 z = 15 } d = 16 } c = { a = 17 b = { x = 18 y = 19 z = 20 } c = 21 d = { x = 22 y = 23 z = 24 } } d = { a = 25 b = { x = 26 y = 27 z = 28 } c = 29 d = { x = 30 y = 31 z = 32 } } e = { a = 33 b = { x = 34 y = 35 z = 36 } c = { x = 37 y = 38 z = 39 } d = 40 } f = { a = 41 b = { x = 42 y = 43 z = 44 } c = 45 d = { x = 46 y = 47 z = 48 } } } +// lldb-command:v deeplyNested +// lldbg-check:[...] { a = { a = 1 b = { x = 2 y = 3 z = 4 } c = 5 d = { x = 6 y = 7 z = 8 } } b = { a = 9 b = { x = 10 y = 11 z = 12 } c = { x = 13 y = 14 z = 15 } d = 16 } c = { a = 17 b = { x = 18 y = 19 z = 20 } c = 21 d = { x = 22 y = 23 z = 24 } } d = { a = 25 b = { x = 26 y = 27 z = 28 } c = 29 d = { x = 30 y = 31 z = 32 } } e = { a = 33 b = { x = 34 y = 35 z = 36 } c = { x = 37 y = 38 z = 39 } d = 40 } f = { a = 41 b = { x = 42 y = 43 z = 44 } c = 45 d = { x = 46 y = 47 z = 48 } } } // lldbr-check:(packed_struct_with_destructor::DeeplyNested) deeplyNested = { a = { a = 1 b = { x = 2 y = 3 z = 4 } c = 5 d = { x = 6 y = 7 z = 8 } } b = { a = 9 b = { x = 10 y = 11 z = 12 } c = { x = 13 y = 14 z = 15 } d = 16 } c = { a = 17 b = { x = 18 y = 19 z = 20 } c = 21 d = { x = 22 y = 23 z = 24 } } d = { a = 25 b = { x = 26 y = 27 z = 28 } c = 29 d = { x = 30 y = 31 z = 32 } } e = { a = 33 b = { x = 34 y = 35 z = 36 } c = { x = 37 y = 38 z = 39 } d = 40 } f = { a = 41 b = { x = 42 y = 43 z = 44 } c = 45 d = { x = 46 y = 47 z = 48 } } } diff --git a/tests/debuginfo/packed-struct.rs b/tests/debuginfo/packed-struct.rs index 0276a0ffb08..ea9aa22ba55 100644 --- a/tests/debuginfo/packed-struct.rs +++ b/tests/debuginfo/packed-struct.rs @@ -34,29 +34,29 @@ // lldb-command:run -// lldb-command:print packed -// lldbg-check:[...]$0 = { x = 123 y = 234 z = 345 } +// lldb-command:v packed +// lldbg-check:[...] { x = 123 y = 234 z = 345 } // lldbr-check:(packed_struct::Packed) packed = { x = 123 y = 234 z = 345 } -// lldb-command:print packedInPacked -// lldbg-check:[...]$1 = { a = 1111 b = { x = 2222 y = 3333 z = 4444 } c = 5555 d = { x = 6666 y = 7777 z = 8888 } } +// lldb-command:v packedInPacked +// lldbg-check:[...] { a = 1111 b = { x = 2222 y = 3333 z = 4444 } c = 5555 d = { x = 6666 y = 7777 z = 8888 } } // lldbr-check:(packed_struct::PackedInPacked) packedInPacked = { a = 1111 b = { x = 2222 y = 3333 z = 4444 } c = 5555 d = { x = 6666 y = 7777 z = 8888 } } -// lldb-command:print packedInUnpacked -// lldbg-check:[...]$2 = { a = -1111 b = { x = -2222 y = -3333 z = -4444 } c = -5555 d = { x = -6666 y = -7777 z = -8888 } } +// lldb-command:v packedInUnpacked +// lldbg-check:[...] { a = -1111 b = { x = -2222 y = -3333 z = -4444 } c = -5555 d = { x = -6666 y = -7777 z = -8888 } } // lldbr-check:(packed_struct::PackedInUnpacked) packedInUnpacked = { a = -1111 b = { x = -2222 y = -3333 z = -4444 } c = -5555 d = { x = -6666 y = -7777 z = -8888 } } -// lldb-command:print unpackedInPacked -// lldbg-check:[...]$3 = { a = 987 b = { x = 876 y = 765 z = 654 w = 543 } c = { x = 432 y = 321 z = 210 w = 109 } d = -98 } +// lldb-command:v unpackedInPacked +// lldbg-check:[...] { a = 987 b = { x = 876 y = 765 z = 654 w = 543 } c = { x = 432 y = 321 z = 210 w = 109 } d = -98 } // lldbr-check:(packed_struct::UnpackedInPacked) unpackedInPacked = { a = 987 b = { x = 876 y = 765 z = 654 w = 543 } c = { x = 432 y = 321 z = 210 w = 109 } d = -98 } -// lldb-command:print sizeof(packed) -// lldbg-check:[...]$4 = 14 -// lldbr-check:(usize) = 14 +// lldb-command:expr sizeof(packed) +// lldbg-check:[...] 14 +// lldbr-check:(usize) [...] 14 -// lldb-command:print sizeof(packedInPacked) -// lldbg-check:[...]$5 = 40 -// lldbr-check:(usize) = 40 +// lldb-command:expr sizeof(packedInPacked) +// lldbg-check:[...] 40 +// lldbr-check:(usize) [...] 40 #![allow(unused_variables)] #![feature(omit_gdb_pretty_printer_section)] diff --git a/tests/debuginfo/pretty-slices.rs b/tests/debuginfo/pretty-slices.rs index 4faa317d6a1..5d2086fa478 100644 --- a/tests/debuginfo/pretty-slices.rs +++ b/tests/debuginfo/pretty-slices.rs @@ -18,19 +18,19 @@ // gdb-command: print mut_str_slice // gdb-check: $4 = "mutable string slice" -// lldb-command: run +// lldb-command:run -// lldb-command: print slice -// lldb-check: (&[i32]) $0 = size=3 { [0] = 0 [1] = 1 [2] = 2 } +// lldb-command:v slice +// lldb-check:(&[i32]) slice = size=3 { [0] = 0 [1] = 1 [2] = 2 } -// lldb-command: print mut_slice -// lldb-check: (&mut [i32]) $1 = size=4 { [0] = 2 [1] = 3 [2] = 5 [3] = 7 } +// lldb-command:v mut_slice +// lldb-check:(&mut [i32]) mut_slice = size=4 { [0] = 2 [1] = 3 [2] = 5 [3] = 7 } -// lldb-command: print str_slice -// lldb-check: (&str) $2 = "string slice" { data_ptr = [...] length = 12 } +// lldb-command:v str_slice +// lldb-check:(&str) str_slice = "string slice" { data_ptr = [...] length = 12 } -// lldb-command: print mut_str_slice -// lldb-check: (&mut str) $3 = "mutable string slice" { data_ptr = [...] length = 20 } +// lldb-command:v mut_str_slice +// lldb-check:(&mut str) mut_str_slice = "mutable string slice" { data_ptr = [...] length = 20 } fn b() {} diff --git a/tests/debuginfo/pretty-std-collections.rs b/tests/debuginfo/pretty-std-collections.rs index 6e7c8dfbbe8..e9c2c4f2a1d 100644 --- a/tests/debuginfo/pretty-std-collections.rs +++ b/tests/debuginfo/pretty-std-collections.rs @@ -58,20 +58,20 @@ // lldb-command:run -// lldb-command:print vec_deque -// lldbg-check:[...]$0 = size=3 { [0] = 5 [1] = 3 [2] = 7 } +// lldb-command:v vec_deque +// lldbg-check:[...] size=3 { [0] = 5 [1] = 3 [2] = 7 } // lldbr-check:(alloc::collections::vec_deque::VecDeque<i32>) vec_deque = size=3 = { [0] = 5 [1] = 3 [2] = 7 } -// lldb-command:print vec_deque2 -// lldbg-check:[...]$1 = size=7 { [0] = 2 [1] = 3 [2] = 4 [3] = 5 [4] = 6 [5] = 7 [6] = 8 } +// lldb-command:v vec_deque2 +// lldbg-check:[...] size=7 { [0] = 2 [1] = 3 [2] = 4 [3] = 5 [4] = 6 [5] = 7 [6] = 8 } // lldbr-check:(alloc::collections::vec_deque::VecDeque<i32>) vec_deque2 = size=7 = { [0] = 2 [1] = 3 [2] = 4 [3] = 5 [4] = 6 [5] = 7 [6] = 8 } -// lldb-command:print hash_map -// lldbg-check:[...]$2 = size=4 { [0] = { 0 = 1 1 = 10 } [1] = { 0 = 2 1 = 20 } [2] = { 0 = 3 1 = 30 } [3] = { 0 = 4 1 = 40 } } +// lldb-command:v hash_map +// lldbg-check:[...] size=4 { [0] = { 0 = 1 1 = 10 } [1] = { 0 = 2 1 = 20 } [2] = { 0 = 3 1 = 30 } [3] = { 0 = 4 1 = 40 } } // lldbr-check:(std::collections::hash::map::HashMap<u64, u64, [...]>) hash_map = size=4 size=4 { [0] = { 0 = 1 1 = 10 } [1] = { 0 = 2 1 = 20 } [2] = { 0 = 3 1 = 30 } [3] = { 0 = 4 1 = 40 } } -// lldb-command:print hash_set -// lldbg-check:[...]$3 = size=4 { [0] = 1 [1] = 2 [2] = 3 [3] = 4 } +// lldb-command:v hash_set +// lldbg-check:[...] size=4 { [0] = 1 [1] = 2 [2] = 3 [3] = 4 } // lldbr-check:(std::collections::hash::set::HashSet<u64, [...]>) hash_set = size=4 { [0] = 1 [1] = 2 [2] = 3 [3] = 4 } #![allow(unused_variables)] diff --git a/tests/debuginfo/pretty-std.rs b/tests/debuginfo/pretty-std.rs index 2c2795379c9..70827d551ca 100644 --- a/tests/debuginfo/pretty-std.rs +++ b/tests/debuginfo/pretty-std.rs @@ -42,28 +42,28 @@ // === LLDB TESTS ================================================================================== -// lldb-command: run +// lldb-command:run -// lldb-command: print slice -// lldb-check:[...]$0 = &[0, 1, 2, 3] +// lldb-command:v slice +// lldb-check:[...] slice = &[0, 1, 2, 3] -// lldb-command: print vec -// lldb-check:[...]$1 = vec![4, 5, 6, 7] +// lldb-command:v vec +// lldb-check:[...] vec = vec![4, 5, 6, 7] -// lldb-command: print str_slice -// lldb-check:[...]$2 = "IAMA string slice!" +// lldb-command:v str_slice +// lldb-check:[...] str_slice = "IAMA string slice!" -// lldb-command: print string -// lldb-check:[...]$3 = "IAMA string!" +// lldb-command:v string +// lldb-check:[...] string = "IAMA string!" -// lldb-command: print some -// lldb-check:[...]$4 = Some(8) +// lldb-command:v some +// lldb-check:[...] some = Some(8) -// lldb-command: print none -// lldb-check:[...]$5 = None +// lldb-command:v none +// lldb-check:[...] none = None -// lldb-command: print os_string -// lldb-check:[...]$6 = "IAMA OS string 😃"[...] +// lldb-command:v os_string +// lldb-check:[...] os_string = "IAMA OS string 😃"[...] // === CDB TESTS ================================================================================== diff --git a/tests/debuginfo/rc_arc.rs b/tests/debuginfo/rc_arc.rs index 3cf6635a173..ca0feb1f465 100644 --- a/tests/debuginfo/rc_arc.rs +++ b/tests/debuginfo/rc_arc.rs @@ -17,10 +17,10 @@ // lldb-command:run -// lldb-command:print rc -// lldb-check:[...]$0 = strong=11, weak=1 { value = 111 } -// lldb-command:print arc -// lldb-check:[...]$1 = strong=21, weak=1 { data = 222 } +// lldb-command:v rc +// lldb-check:[...] strong=11, weak=1 { value = 111 } +// lldb-command:v arc +// lldb-check:[...] strong=21, weak=1 { data = 222 } // === CDB TESTS ================================================================================== diff --git a/tests/debuginfo/reference-debuginfo.rs b/tests/debuginfo/reference-debuginfo.rs index 1051cc7113c..339839f07cc 100644 --- a/tests/debuginfo/reference-debuginfo.rs +++ b/tests/debuginfo/reference-debuginfo.rs @@ -59,64 +59,64 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print *bool_ref -// lldbg-check:[...]$0 = true +// lldb-command:v *bool_ref +// lldbg-check:[...] true // lldbr-check:(bool) *bool_ref = true -// lldb-command:print *int_ref -// lldbg-check:[...]$1 = -1 +// lldb-command:v *int_ref +// lldbg-check:[...] -1 // lldbr-check:(isize) *int_ref = -1 // NOTE: only rust-enabled lldb supports 32bit chars // lldbr-command:print *char_ref // lldbr-check:(char) *char_ref = 'a' -// lldb-command:print *i8_ref -// lldbg-check:[...]$2 = 'D' +// lldb-command:v *i8_ref +// lldbg-check:[...] 'D' // lldbr-check:(i8) *i8_ref = 68 -// lldb-command:print *i16_ref -// lldbg-check:[...]$3 = -16 +// lldb-command:v *i16_ref +// lldbg-check:[...] -16 // lldbr-check:(i16) *i16_ref = -16 -// lldb-command:print *i32_ref -// lldbg-check:[...]$4 = -32 +// lldb-command:v *i32_ref +// lldbg-check:[...] -32 // lldbr-check:(i32) *i32_ref = -32 -// lldb-command:print *i64_ref -// lldbg-check:[...]$5 = -64 +// lldb-command:v *i64_ref +// lldbg-check:[...] -64 // lldbr-check:(i64) *i64_ref = -64 -// lldb-command:print *uint_ref -// lldbg-check:[...]$6 = 1 +// lldb-command:v *uint_ref +// lldbg-check:[...] 1 // lldbr-check:(usize) *uint_ref = 1 -// lldb-command:print *u8_ref -// lldbg-check:[...]$7 = 'd' +// lldb-command:v *u8_ref +// lldbg-check:[...] 'd' // lldbr-check:(u8) *u8_ref = 100 -// lldb-command:print *u16_ref -// lldbg-check:[...]$8 = 16 +// lldb-command:v *u16_ref +// lldbg-check:[...] 16 // lldbr-check:(u16) *u16_ref = 16 -// lldb-command:print *u32_ref -// lldbg-check:[...]$9 = 32 +// lldb-command:v *u32_ref +// lldbg-check:[...] 32 // lldbr-check:(u32) *u32_ref = 32 -// lldb-command:print *u64_ref -// lldbg-check:[...]$10 = 64 +// lldb-command:v *u64_ref +// lldbg-check:[...] 64 // lldbr-check:(u64) *u64_ref = 64 -// lldb-command:print *f32_ref -// lldbg-check:[...]$11 = 2.5 +// lldb-command:v *f32_ref +// lldbg-check:[...] 2.5 // lldbr-check:(f32) *f32_ref = 2.5 -// lldb-command:print *f64_ref -// lldbg-check:[...]$12 = 3.5 +// lldb-command:v *f64_ref +// lldbg-check:[...] 3.5 // lldbr-check:(f64) *f64_ref = 3.5 -// lldb-command:print *f64_double_ref -// lldbg-check:[...]$13 = 3.5 +// lldb-command:v *f64_double_ref +// lldbg-check:[...] 3.5 // lldbr-check:(f64) **f64_double_ref = 3.5 #![allow(unused_variables)] diff --git a/tests/debuginfo/regression-bad-location-list-67992.rs b/tests/debuginfo/regression-bad-location-list-67992.rs index c397b403026..fe410942d51 100644 --- a/tests/debuginfo/regression-bad-location-list-67992.rs +++ b/tests/debuginfo/regression-bad-location-list-67992.rs @@ -10,8 +10,8 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print a -// lldbg-check:(regression_bad_location_list_67992::Foo) $0 = [...] +// lldb-command:v a +// lldbg-check:(regression_bad_location_list_67992::Foo) [...] // lldbr-check:(regression_bad_location_list_67992::Foo) a = [...] const ARRAY_SIZE: usize = 1024; diff --git a/tests/debuginfo/self-in-default-method.rs b/tests/debuginfo/self-in-default-method.rs index eae1d58c124..374951475fc 100644 --- a/tests/debuginfo/self-in-default-method.rs +++ b/tests/debuginfo/self-in-default-method.rs @@ -62,62 +62,62 @@ // lldb-command:run // STACK BY REF -// lldb-command:print *self -// lldbg-check:[...]$0 = { x = 100 } +// lldb-command:v *self +// lldbg-check:[...] { x = 100 } // lldbr-check:(self_in_default_method::Struct) *self = Struct { x: 100 } -// lldb-command:print arg1 -// lldbg-check:[...]$1 = -1 +// lldb-command:v arg1 +// lldbg-check:[...] -1 // lldbr-check:(isize) arg1 = -1 -// lldb-command:print arg2 -// lldbg-check:[...]$2 = -2 +// lldb-command:v arg2 +// lldbg-check:[...] -2 // lldbr-check:(isize) arg2 = -2 // lldb-command:continue // STACK BY VAL -// lldb-command:print self -// lldbg-check:[...]$3 = { x = 100 } +// lldb-command:v self +// lldbg-check:[...] { x = 100 } // lldbr-check:(self_in_default_method::Struct) self = Struct { x: 100 } -// lldb-command:print arg1 -// lldbg-check:[...]$4 = -3 +// lldb-command:v arg1 +// lldbg-check:[...] -3 // lldbr-check:(isize) arg1 = -3 -// lldb-command:print arg2 -// lldbg-check:[...]$5 = -4 +// lldb-command:v arg2 +// lldbg-check:[...] -4 // lldbr-check:(isize) arg2 = -4 // lldb-command:continue // OWNED BY REF -// lldb-command:print *self -// lldbg-check:[...]$6 = { x = 200 } +// lldb-command:v *self +// lldbg-check:[...] { x = 200 } // lldbr-check:(self_in_default_method::Struct) *self = Struct { x: 200 } -// lldb-command:print arg1 -// lldbg-check:[...]$7 = -5 +// lldb-command:v arg1 +// lldbg-check:[...] -5 // lldbr-check:(isize) arg1 = -5 -// lldb-command:print arg2 -// lldbg-check:[...]$8 = -6 +// lldb-command:v arg2 +// lldbg-check:[...] -6 // lldbr-check:(isize) arg2 = -6 // lldb-command:continue // OWNED BY VAL -// lldb-command:print self -// lldbg-check:[...]$9 = { x = 200 } +// lldb-command:v self +// lldbg-check:[...] { x = 200 } // lldbr-check:(self_in_default_method::Struct) self = Struct { x: 200 } -// lldb-command:print arg1 -// lldbg-check:[...]$10 = -7 +// lldb-command:v arg1 +// lldbg-check:[...] -7 // lldbr-check:(isize) arg1 = -7 -// lldb-command:print arg2 -// lldbg-check:[...]$11 = -8 +// lldb-command:v arg2 +// lldbg-check:[...] -8 // lldbr-check:(isize) arg2 = -8 // lldb-command:continue // OWNED MOVED -// lldb-command:print *self -// lldbg-check:[...]$12 = { x = 200 } +// lldb-command:v *self +// lldbg-check:[...] { x = 200 } // lldbr-check:(self_in_default_method::Struct) *self = Struct { x: 200 } -// lldb-command:print arg1 -// lldbg-check:[...]$13 = -9 +// lldb-command:v arg1 +// lldbg-check:[...] -9 // lldbr-check:(isize) arg1 = -9 -// lldb-command:print arg2 -// lldbg-check:[...]$14 = -10 +// lldb-command:v arg2 +// lldbg-check:[...] -10 // lldbr-check:(isize) arg2 = -10 // lldb-command:continue diff --git a/tests/debuginfo/self-in-generic-default-method.rs b/tests/debuginfo/self-in-generic-default-method.rs index 92be253e18a..4759ca3ecdc 100644 --- a/tests/debuginfo/self-in-generic-default-method.rs +++ b/tests/debuginfo/self-in-generic-default-method.rs @@ -62,62 +62,62 @@ // lldb-command:run // STACK BY REF -// lldb-command:print *self -// lldbg-check:[...]$0 = { x = 987 } +// lldb-command:v *self +// lldbg-check:[...] { x = 987 } // lldbr-check:(self_in_generic_default_method::Struct) *self = Struct { x: 987 } -// lldb-command:print arg1 -// lldbg-check:[...]$1 = -1 +// lldb-command:v arg1 +// lldbg-check:[...] -1 // lldbr-check:(isize) arg1 = -1 -// lldb-command:print arg2 -// lldbg-check:[...]$2 = 2 +// lldb-command:v arg2 +// lldbg-check:[...] 2 // lldbr-check:(u16) arg2 = 2 // lldb-command:continue // STACK BY VAL -// lldb-command:print self -// lldbg-check:[...]$3 = { x = 987 } +// lldb-command:v self +// lldbg-check:[...] { x = 987 } // lldbr-check:(self_in_generic_default_method::Struct) self = Struct { x: 987 } -// lldb-command:print arg1 -// lldbg-check:[...]$4 = -3 +// lldb-command:v arg1 +// lldbg-check:[...] -3 // lldbr-check:(isize) arg1 = -3 -// lldb-command:print arg2 -// lldbg-check:[...]$5 = -4 +// lldb-command:v arg2 +// lldbg-check:[...] -4 // lldbr-check:(i16) arg2 = -4 // lldb-command:continue // OWNED BY REF -// lldb-command:print *self -// lldbg-check:[...]$6 = { x = 879 } +// lldb-command:v *self +// lldbg-check:[...] { x = 879 } // lldbr-check:(self_in_generic_default_method::Struct) *self = Struct { x: 879 } -// lldb-command:print arg1 -// lldbg-check:[...]$7 = -5 +// lldb-command:v arg1 +// lldbg-check:[...] -5 // lldbr-check:(isize) arg1 = -5 -// lldb-command:print arg2 -// lldbg-check:[...]$8 = -6 +// lldb-command:v arg2 +// lldbg-check:[...] -6 // lldbr-check:(i32) arg2 = -6 // lldb-command:continue // OWNED BY VAL -// lldb-command:print self -// lldbg-check:[...]$9 = { x = 879 } +// lldb-command:v self +// lldbg-check:[...] { x = 879 } // lldbr-check:(self_in_generic_default_method::Struct) self = Struct { x: 879 } -// lldb-command:print arg1 -// lldbg-check:[...]$10 = -7 +// lldb-command:v arg1 +// lldbg-check:[...] -7 // lldbr-check:(isize) arg1 = -7 -// lldb-command:print arg2 -// lldbg-check:[...]$11 = -8 +// lldb-command:v arg2 +// lldbg-check:[...] -8 // lldbr-check:(i64) arg2 = -8 // lldb-command:continue // OWNED MOVED -// lldb-command:print *self -// lldbg-check:[...]$12 = { x = 879 } +// lldb-command:v *self +// lldbg-check:[...] { x = 879 } // lldbr-check:(self_in_generic_default_method::Struct) *self = Struct { x: 879 } -// lldb-command:print arg1 -// lldbg-check:[...]$13 = -9 +// lldb-command:v arg1 +// lldbg-check:[...] -9 // lldbr-check:(isize) arg1 = -9 -// lldb-command:print arg2 -// lldbg-check:[...]$14 = -10.5 +// lldb-command:v arg2 +// lldbg-check:[...] -10.5 // lldbr-check:(f32) arg2 = -10.5 // lldb-command:continue diff --git a/tests/debuginfo/shadowed-argument.rs b/tests/debuginfo/shadowed-argument.rs index 33f73340a83..e7bc731336e 100644 --- a/tests/debuginfo/shadowed-argument.rs +++ b/tests/debuginfo/shadowed-argument.rs @@ -29,27 +29,27 @@ // lldb-command:run -// lldb-command:print x -// lldbg-check:[...]$0 = false +// lldb-command:v x +// lldbg-check:[...] false // lldbr-check:(bool) x = false -// lldb-command:print y -// lldbg-check:[...]$1 = true +// lldb-command:v y +// lldbg-check:[...] true // lldbr-check:(bool) y = true // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$2 = 10 +// lldb-command:v x +// lldbg-check:[...] 10 // lldbr-check:(i32) x = 10 -// lldb-command:print y -// lldbg-check:[...]$3 = true +// lldb-command:v y +// lldbg-check:[...] true // lldbr-check:(bool) y = true // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$4 = 10.5 +// lldb-command:v x +// lldbg-check:[...] 10.5 // lldbr-check:(f64) x = 10.5 -// lldb-command:print y -// lldbg-check:[...]$5 = 20 +// lldb-command:v y +// lldbg-check:[...] 20 // lldbr-check:(i32) y = 20 // lldb-command:continue diff --git a/tests/debuginfo/shadowed-variable.rs b/tests/debuginfo/shadowed-variable.rs index 60c392b15cb..3cc5fe14cb2 100644 --- a/tests/debuginfo/shadowed-variable.rs +++ b/tests/debuginfo/shadowed-variable.rs @@ -39,43 +39,43 @@ // lldb-command:run -// lldb-command:print x -// lldbg-check:[...]$0 = false +// lldb-command:v x +// lldbg-check:[...] false // lldbr-check:(bool) x = false -// lldb-command:print y -// lldbg-check:[...]$1 = true +// lldb-command:v y +// lldbg-check:[...] true // lldbr-check:(bool) y = true // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$2 = 10 +// lldb-command:v x +// lldbg-check:[...] 10 // lldbr-check:(i32) x = 10 -// lldb-command:print y -// lldbg-check:[...]$3 = true +// lldb-command:v y +// lldbg-check:[...] true // lldbr-check:(bool) y = true // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$4 = 10.5 +// lldb-command:v x +// lldbg-check:[...] 10.5 // lldbr-check:(f64) x = 10.5 -// lldb-command:print y -// lldbg-check:[...]$5 = 20 +// lldb-command:v y +// lldbg-check:[...] 20 // lldbr-check:(i32) y = 20 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$6 = 10.5 +// lldb-command:v x +// lldbg-check:[...] 10.5 // lldbr-check:(f64) x = 10.5 -// lldb-command:print y -// lldbg-check:[...]$7 = 20 +// lldb-command:v y +// lldbg-check:[...] 20 // lldbr-check:(i32) y = 20 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$8 = 11.5 +// lldb-command:v x +// lldbg-check:[...] 11.5 // lldbr-check:(f64) x = 11.5 -// lldb-command:print y -// lldbg-check:[...]$9 = 20 +// lldb-command:v y +// lldbg-check:[...] 20 // lldbr-check:(i32) y = 20 // lldb-command:continue diff --git a/tests/debuginfo/should-fail.rs b/tests/debuginfo/should-fail.rs index f3a8f52e0fa..0f153394a44 100644 --- a/tests/debuginfo/should-fail.rs +++ b/tests/debuginfo/should-fail.rs @@ -16,8 +16,8 @@ // lldb-command:run -// lldb-command:print x -// lldb-check:[...]$0 = 5 +// lldb-command:v x +// lldb-check:[...] 5 // === CDB TESTS ================================================================================== diff --git a/tests/debuginfo/simple-lexical-scope.rs b/tests/debuginfo/simple-lexical-scope.rs index f4be2035d3c..4156e68f8b1 100644 --- a/tests/debuginfo/simple-lexical-scope.rs +++ b/tests/debuginfo/simple-lexical-scope.rs @@ -39,38 +39,38 @@ // lldb-command:run -// lldb-command:print x -// lldbg-check:[...]$0 = false +// lldb-command:v x +// lldbg-check:[...] false // lldbr-check:(bool) x = false // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$1 = false +// lldb-command:v x +// lldbg-check:[...] false // lldbr-check:(bool) x = false // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$2 = 10 +// lldb-command:v x +// lldbg-check:[...] 10 // lldbr-check:(i32) x = 10 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$3 = 10 +// lldb-command:v x +// lldbg-check:[...] 10 // lldbr-check:(i32) x = 10 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$4 = 10.5 +// lldb-command:v x +// lldbg-check:[...] 10.5 // lldbr-check:(f64) x = 10.5 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$5 = 10 +// lldb-command:v x +// lldbg-check:[...] 10 // lldbr-check:(i32) x = 10 // lldb-command:continue -// lldb-command:print x -// lldbg-check:[...]$6 = false +// lldb-command:v x +// lldbg-check:[...] false // lldbr-check:(bool) x = false // lldb-command:continue diff --git a/tests/debuginfo/simple-struct.rs b/tests/debuginfo/simple-struct.rs index 100763f60b6..968a5c63e89 100644 --- a/tests/debuginfo/simple-struct.rs +++ b/tests/debuginfo/simple-struct.rs @@ -97,28 +97,28 @@ // lldb-command:run -// lldb-command:print no_padding16 -// lldbg-check:[...]$0 = { x = 10000 y = -10001 } +// lldb-command:v no_padding16 +// lldbg-check:[...] { x = 10000 y = -10001 } // lldbr-check:(simple_struct::NoPadding16) no_padding16 = { x = 10000 y = -10001 } -// lldb-command:print no_padding32 -// lldbg-check:[...]$1 = { x = -10002 y = -10003.5 z = 10004 } +// lldb-command:v no_padding32 +// lldbg-check:[...] { x = -10002 y = -10003.5 z = 10004 } // lldbr-check:(simple_struct::NoPadding32) no_padding32 = { x = -10002 y = -10003.5 z = 10004 } -// lldb-command:print no_padding64 -// lldbg-check:[...]$2 = { x = -10005.5 y = 10006 z = 10007 } +// lldb-command:v no_padding64 +// lldbg-check:[...] { x = -10005.5 y = 10006 z = 10007 } // lldbr-check:(simple_struct::NoPadding64) no_padding64 = { x = -10005.5 y = 10006 z = 10007 } -// lldb-command:print no_padding163264 -// lldbg-check:[...]$3 = { a = -10008 b = 10009 c = 10010 d = 10011 } +// lldb-command:v no_padding163264 +// lldbg-check:[...] { a = -10008 b = 10009 c = 10010 d = 10011 } // lldbr-check:(simple_struct::NoPadding163264) no_padding163264 = { a = -10008 b = 10009 c = 10010 d = 10011 } -// lldb-command:print internal_padding -// lldbg-check:[...]$4 = { x = 10012 y = -10013 } +// lldb-command:v internal_padding +// lldbg-check:[...] { x = 10012 y = -10013 } // lldbr-check:(simple_struct::InternalPadding) internal_padding = { x = 10012 y = -10013 } -// lldb-command:print padding_at_end -// lldbg-check:[...]$5 = { x = -10014 y = 10015 } +// lldb-command:v padding_at_end +// lldbg-check:[...] { x = -10014 y = 10015 } // lldbr-check:(simple_struct::PaddingAtEnd) padding_at_end = { x = -10014 y = 10015 } #![allow(unused_variables)] diff --git a/tests/debuginfo/simple-tuple.rs b/tests/debuginfo/simple-tuple.rs index 2d8905a77bf..86003105f36 100644 --- a/tests/debuginfo/simple-tuple.rs +++ b/tests/debuginfo/simple-tuple.rs @@ -99,28 +99,28 @@ // lldb-command:run -// lldb-command:print/d noPadding8 -// lldbg-check:[...]$0 = { 0 = -100 1 = 100 } +// lldb-command:v/d noPadding8 +// lldbg-check:[...] { 0 = -100 1 = 100 } // lldbr-check:((i8, u8)) noPadding8 = { 0 = -100 1 = 100 } -// lldb-command:print noPadding16 -// lldbg-check:[...]$1 = { 0 = 0 1 = 1 2 = 2 } +// lldb-command:v noPadding16 +// lldbg-check:[...] { 0 = 0 1 = 1 2 = 2 } // lldbr-check:((i16, i16, u16)) noPadding16 = { 0 = 0 1 = 1 2 = 2 } -// lldb-command:print noPadding32 -// lldbg-check:[...]$2 = { 0 = 3 1 = 4.5 2 = 5 } +// lldb-command:v noPadding32 +// lldbg-check:[...] { 0 = 3 1 = 4.5 2 = 5 } // lldbr-check:((i32, f32, u32)) noPadding32 = { 0 = 3 1 = 4.5 2 = 5 } -// lldb-command:print noPadding64 -// lldbg-check:[...]$3 = { 0 = 6 1 = 7.5 2 = 8 } +// lldb-command:v noPadding64 +// lldbg-check:[...] { 0 = 6 1 = 7.5 2 = 8 } // lldbr-check:((i64, f64, u64)) noPadding64 = { 0 = 6 1 = 7.5 2 = 8 } -// lldb-command:print internalPadding1 -// lldbg-check:[...]$4 = { 0 = 9 1 = 10 } +// lldb-command:v internalPadding1 +// lldbg-check:[...] { 0 = 9 1 = 10 } // lldbr-check:((i16, i32)) internalPadding1 = { 0 = 9 1 = 10 } -// lldb-command:print internalPadding2 -// lldbg-check:[...]$5 = { 0 = 11 1 = 12 2 = 13 3 = 14 } +// lldb-command:v internalPadding2 +// lldbg-check:[...] { 0 = 11 1 = 12 2 = 13 3 = 14 } // lldbr-check:((i16, i32, u32, u64)) internalPadding2 = { 0 = 11 1 = 12 2 = 13 3 = 14 } -// lldb-command:print paddingAtEnd -// lldbg-check:[...]$6 = { 0 = 15 1 = 16 } +// lldb-command:v paddingAtEnd +// lldbg-check:[...] { 0 = 15 1 = 16 } // lldbr-check:((i32, i16)) paddingAtEnd = { 0 = 15 1 = 16 } diff --git a/tests/debuginfo/static-method-on-struct-and-enum.rs b/tests/debuginfo/static-method-on-struct-and-enum.rs index ad078122dde..b4ec4543572 100644 --- a/tests/debuginfo/static-method-on-struct-and-enum.rs +++ b/tests/debuginfo/static-method-on-struct-and-enum.rs @@ -28,23 +28,23 @@ // lldb-command:run // STRUCT -// lldb-command:print arg1 -// lldbg-check:[...]$0 = 1 +// lldb-command:v arg1 +// lldbg-check:[...] 1 // lldbr-check:(isize) arg1 = 1 -// lldb-command:print arg2 -// lldbg-check:[...]$1 = 2 +// lldb-command:v arg2 +// lldbg-check:[...] 2 // lldbr-check:(isize) arg2 = 2 // lldb-command:continue // ENUM -// lldb-command:print arg1 -// lldbg-check:[...]$2 = -3 +// lldb-command:v arg1 +// lldbg-check:[...] -3 // lldbr-check:(isize) arg1 = -3 -// lldb-command:print arg2 -// lldbg-check:[...]$3 = 4.5 +// lldb-command:v arg2 +// lldbg-check:[...] 4.5 // lldbr-check:(f64) arg2 = 4.5 -// lldb-command:print arg3 -// lldbg-check:[...]$4 = 5 +// lldb-command:v arg3 +// lldbg-check:[...] 5 // lldbr-check:(usize) arg3 = 5 // lldb-command:continue diff --git a/tests/debuginfo/struct-in-enum.rs b/tests/debuginfo/struct-in-enum.rs index c340f71a6cc..52e419e6b47 100644 --- a/tests/debuginfo/struct-in-enum.rs +++ b/tests/debuginfo/struct-in-enum.rs @@ -26,13 +26,13 @@ // lldb-command:run -// lldb-command:print case1 -// lldb-check:[...]$0 = Case1(0, Struct { x: 2088533116, y: 2088533116, z: 31868 }) -// lldb-command:print case2 -// lldb-check:[...]$1 = Case2(0, 1229782938247303441, 4369) +// lldb-command:v case1 +// lldb-check:[...] Case1(0, Struct { x: 2088533116, y: 2088533116, z: 31868 }) +// lldb-command:v case2 +// lldb-check:[...] Case2(0, 1229782938247303441, 4369) -// lldb-command:print univariant -// lldb-check:[...]$2 = TheOnlyCase(Struct { x: 123, y: 456, z: 789 }) +// lldb-command:v univariant +// lldb-check:[...] TheOnlyCase(Struct { x: 123, y: 456, z: 789 }) #![allow(unused_variables)] #![feature(omit_gdb_pretty_printer_section)] diff --git a/tests/debuginfo/struct-in-struct.rs b/tests/debuginfo/struct-in-struct.rs index 287564a36cd..7ca0e3a5ef6 100644 --- a/tests/debuginfo/struct-in-struct.rs +++ b/tests/debuginfo/struct-in-struct.rs @@ -23,36 +23,36 @@ // lldb-command:run -// lldb-command:print three_simple_structs -// lldbg-check:[...]$0 = { x = { x = 1 } y = { x = 2 } z = { x = 3 } } +// lldb-command:v three_simple_structs +// lldbg-check:[...] { x = { x = 1 } y = { x = 2 } z = { x = 3 } } // lldbr-check:(struct_in_struct::ThreeSimpleStructs) three_simple_structs = { x = { x = 1 } y = { x = 2 } z = { x = 3 } } -// lldb-command:print internal_padding_parent -// lldbg-check:[...]$1 = { x = { x = 4 y = 5 } y = { x = 6 y = 7 } z = { x = 8 y = 9 } } +// lldb-command:v internal_padding_parent +// lldbg-check:[...] { x = { x = 4 y = 5 } y = { x = 6 y = 7 } z = { x = 8 y = 9 } } // lldbr-check:(struct_in_struct::InternalPaddingParent) internal_padding_parent = { x = { x = 4 y = 5 } y = { x = 6 y = 7 } z = { x = 8 y = 9 } } -// lldb-command:print padding_at_end_parent -// lldbg-check:[...]$2 = { x = { x = 10 y = 11 } y = { x = 12 y = 13 } z = { x = 14 y = 15 } } +// lldb-command:v padding_at_end_parent +// lldbg-check:[...] { x = { x = 10 y = 11 } y = { x = 12 y = 13 } z = { x = 14 y = 15 } } // lldbr-check:(struct_in_struct::PaddingAtEndParent) padding_at_end_parent = { x = { x = 10 y = 11 } y = { x = 12 y = 13 } z = { x = 14 y = 15 } } -// lldb-command:print mixed -// lldbg-check:[...]$3 = { x = { x = 16 y = 17 } y = { x = 18 y = 19 } z = { x = 20 } w = 21 } +// lldb-command:v mixed +// lldbg-check:[...] { x = { x = 16 y = 17 } y = { x = 18 y = 19 } z = { x = 20 } w = 21 } // lldbr-check:(struct_in_struct::Mixed) mixed = { x = { x = 16 y = 17 } y = { x = 18 y = 19 } z = { x = 20 } w = 21 } -// lldb-command:print bag -// lldbg-check:[...]$4 = { x = { x = 22 } } +// lldb-command:v bag +// lldbg-check:[...] { x = { x = 22 } } // lldbr-check:(struct_in_struct::Bag) bag = { x = { x = 22 } } -// lldb-command:print bag_in_bag -// lldbg-check:[...]$5 = { x = { x = { x = 23 } } } +// lldb-command:v bag_in_bag +// lldbg-check:[...] { x = { x = { x = 23 } } } // lldbr-check:(struct_in_struct::BagInBag) bag_in_bag = { x = { x = { x = 23 } } } -// lldb-command:print tjo -// lldbg-check:[...]$6 = { x = { x = { x = { x = 24 } } } } +// lldb-command:v tjo +// lldbg-check:[...] { x = { x = { x = { x = 24 } } } } // lldbr-check:(struct_in_struct::ThatsJustOverkill) tjo = { x = { x = { x = { x = 24 } } } } -// lldb-command:print tree -// lldbg-check:[...]$7 = { x = { x = 25 } y = { x = { x = 26 y = 27 } y = { x = 28 y = 29 } z = { x = 30 y = 31 } } z = { x = { x = { x = 32 } } } } +// lldb-command:v tree +// lldbg-check:[...] { x = { x = 25 } y = { x = { x = 26 y = 27 } y = { x = 28 y = 29 } z = { x = 30 y = 31 } } z = { x = { x = { x = 32 } } } } // lldbr-check:(struct_in_struct::Tree) tree = { x = { x = 25 } y = { x = { x = 26 y = 27 } y = { x = 28 y = 29 } z = { x = 30 y = 31 } } z = { x = { x = { x = 32 } } } } #![allow(unused_variables)] diff --git a/tests/debuginfo/struct-namespace.rs b/tests/debuginfo/struct-namespace.rs index f9262a458d5..3cae51e83dd 100644 --- a/tests/debuginfo/struct-namespace.rs +++ b/tests/debuginfo/struct-namespace.rs @@ -5,18 +5,18 @@ // Check that structs get placed in the correct namespace // lldb-command:run -// lldb-command:p struct1 -// lldbg-check:(struct_namespace::Struct1) $0 = [...] +// lldb-command:v struct1 +// lldbg-check:(struct_namespace::Struct1)[...] // lldbr-check:(struct_namespace::Struct1) struct1 = Struct1 { a: 0, b: 1 } -// lldb-command:p struct2 -// lldbg-check:(struct_namespace::Struct2) $1 = [...] +// lldb-command:v struct2 +// lldbg-check:(struct_namespace::Struct2)[...] // lldbr-check:(struct_namespace::Struct2) struct2 = { = 2 } -// lldb-command:p mod1_struct1 -// lldbg-check:(struct_namespace::mod1::Struct1) $2 = [...] +// lldb-command:v mod1_struct1 +// lldbg-check:(struct_namespace::mod1::Struct1)[...] // lldbr-check:(struct_namespace::mod1::Struct1) mod1_struct1 = Struct1 { a: 3, b: 4 } -// lldb-command:p mod1_struct2 -// lldbg-check:(struct_namespace::mod1::Struct2) $3 = [...] +// lldb-command:v mod1_struct2 +// lldbg-check:(struct_namespace::mod1::Struct2)[...] // lldbr-check:(struct_namespace::mod1::Struct2) mod1_struct2 = { = 5 } #![allow(unused_variables)] diff --git a/tests/debuginfo/struct-style-enum.rs b/tests/debuginfo/struct-style-enum.rs index 2f155d2b83e..517b76c1412 100644 --- a/tests/debuginfo/struct-style-enum.rs +++ b/tests/debuginfo/struct-style-enum.rs @@ -26,16 +26,16 @@ // lldb-command:run -// lldb-command:print case1 +// lldb-command:v case1 // lldbr-check:(struct_style_enum::Regular::Case1) case1 = { a = 0 b = 31868 c = 31868 d = 31868 e = 31868 } -// lldb-command:print case2 +// lldb-command:v case2 // lldbr-check:(struct_style_enum::Regular::Case2) case2 = Case2 { Case1: 0, Case2: 286331153, Case3: 286331153 } -// lldb-command:print case3 +// lldb-command:v case3 // lldbr-check:(struct_style_enum::Regular::Case3) case3 = Case3 { Case1: 0, Case2: 6438275382588823897 } -// lldb-command:print univariant +// lldb-command:v univariant // lldbr-check:(struct_style_enum::Univariant) univariant = Univariant { TheOnlyCase: TheOnlyCase { a: -1 } } #![allow(unused_variables)] diff --git a/tests/debuginfo/struct-with-destructor.rs b/tests/debuginfo/struct-with-destructor.rs index 9b81136e7a8..12e2ac4225c 100644 --- a/tests/debuginfo/struct-with-destructor.rs +++ b/tests/debuginfo/struct-with-destructor.rs @@ -25,20 +25,20 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print simple -// lldbg-check:[...]$0 = { x = 10 y = 20 } +// lldb-command:v simple +// lldbg-check:[...] { x = 10 y = 20 } // lldbr-check:(struct_with_destructor::WithDestructor) simple = { x = 10 y = 20 } -// lldb-command:print noDestructor -// lldbg-check:[...]$1 = { a = { x = 10 y = 20 } guard = -1 } +// lldb-command:v noDestructor +// lldbg-check:[...] { a = { x = 10 y = 20 } guard = -1 } // lldbr-check:(struct_with_destructor::NoDestructorGuarded) noDestructor = { a = { x = 10 y = 20 } guard = -1 } -// lldb-command:print withDestructor -// lldbg-check:[...]$2 = { a = { x = 10 y = 20 } guard = -1 } +// lldb-command:v withDestructor +// lldbg-check:[...] { a = { x = 10 y = 20 } guard = -1 } // lldbr-check:(struct_with_destructor::WithDestructorGuarded) withDestructor = { a = { x = 10 y = 20 } guard = -1 } -// lldb-command:print nested -// lldbg-check:[...]$3 = { a = { a = { x = 7890 y = 9870 } } } +// lldb-command:v nested +// lldbg-check:[...] { a = { a = { x = 7890 y = 9870 } } } // lldbr-check:(struct_with_destructor::NestedOuter) nested = { a = { a = { x = 7890 y = 9870 } } } #![allow(unused_variables)] diff --git a/tests/debuginfo/tuple-in-tuple.rs b/tests/debuginfo/tuple-in-tuple.rs index c1cfe64a52e..8ed0e1f9c13 100644 --- a/tests/debuginfo/tuple-in-tuple.rs +++ b/tests/debuginfo/tuple-in-tuple.rs @@ -35,28 +35,28 @@ // lldb-command:run -// lldb-command:print no_padding1 -// lldbg-check:[...]$0 = { 0 = { 0 = 0 1 = 1 } 1 = 2 2 = 3 } +// lldb-command:v no_padding1 +// lldbg-check:[...] { 0 = { 0 = 0 1 = 1 } 1 = 2 2 = 3 } // lldbr-check:(((u32, u32), u32, u32)) no_padding1 = { 0 = { 0 = 0 1 = 1 } 1 = 2 2 = 3 } -// lldb-command:print no_padding2 -// lldbg-check:[...]$1 = { 0 = 4 1 = { 0 = 5 1 = 6 } 2 = 7 } +// lldb-command:v no_padding2 +// lldbg-check:[...] { 0 = 4 1 = { 0 = 5 1 = 6 } 2 = 7 } // lldbr-check:((u32, (u32, u32), u32)) no_padding2 = { 0 = 4 1 = { 0 = 5 1 = 6 } 2 = 7 } -// lldb-command:print no_padding3 -// lldbg-check:[...]$2 = { 0 = 8 1 = 9 2 = { 0 = 10 1 = 11 } } +// lldb-command:v no_padding3 +// lldbg-check:[...] { 0 = 8 1 = 9 2 = { 0 = 10 1 = 11 } } // lldbr-check:((u32, u32, (u32, u32))) no_padding3 = { 0 = 8 1 = 9 2 = { 0 = 10 1 = 11 } } -// lldb-command:print internal_padding1 -// lldbg-check:[...]$3 = { 0 = 12 1 = { 0 = 13 1 = 14 } } +// lldb-command:v internal_padding1 +// lldbg-check:[...] { 0 = 12 1 = { 0 = 13 1 = 14 } } // lldbr-check:((i16, (i32, i32))) internal_padding1 = { 0 = 12 1 = { 0 = 13 1 = 14 } } -// lldb-command:print internal_padding2 -// lldbg-check:[...]$4 = { 0 = 15 1 = { 0 = 16 1 = 17 } } +// lldb-command:v internal_padding2 +// lldbg-check:[...] { 0 = 15 1 = { 0 = 16 1 = 17 } } // lldbr-check:((i16, (i16, i32))) internal_padding2 = { 0 = 15 1 = { 0 = 16 1 = 17 } } -// lldb-command:print padding_at_end1 -// lldbg-check:[...]$5 = { 0 = 18 1 = { 0 = 19 1 = 20 } } +// lldb-command:v padding_at_end1 +// lldbg-check:[...] { 0 = 18 1 = { 0 = 19 1 = 20 } } // lldbr-check:((i32, (i32, i16))) padding_at_end1 = { 0 = 18 1 = { 0 = 19 1 = 20 } } -// lldb-command:print padding_at_end2 -// lldbg-check:[...]$6 = { 0 = { 0 = 21 1 = 22 } 1 = 23 } +// lldb-command:v padding_at_end2 +// lldbg-check:[...] { 0 = { 0 = 21 1 = 22 } 1 = 23 } // lldbr-check:(((i32, i16), i32)) padding_at_end2 = { 0 = { 0 = 21 1 = 22 } 1 = 23 } diff --git a/tests/debuginfo/tuple-struct.rs b/tests/debuginfo/tuple-struct.rs index 5eeb1a6eed4..88b1ae19e29 100644 --- a/tests/debuginfo/tuple-struct.rs +++ b/tests/debuginfo/tuple-struct.rs @@ -35,28 +35,28 @@ // lldb-command:run -// lldb-command:print no_padding16 -// lldbg-check:[...]$0 = { 0 = 10000 1 = -10001 } +// lldb-command:v no_padding16 +// lldbg-check:[...] { 0 = 10000 1 = -10001 } // lldbr-check:(tuple_struct::NoPadding16) no_padding16 = { 0 = 10000 1 = -10001 } -// lldb-command:print no_padding32 -// lldbg-check:[...]$1 = { 0 = -10002 1 = -10003.5 2 = 10004 } +// lldb-command:v no_padding32 +// lldbg-check:[...] { 0 = -10002 1 = -10003.5 2 = 10004 } // lldbr-check:(tuple_struct::NoPadding32) no_padding32 = { 0 = -10002 1 = -10003.5 2 = 10004 } -// lldb-command:print no_padding64 -// lldbg-check:[...]$2 = { 0 = -10005.5 1 = 10006 2 = 10007 } +// lldb-command:v no_padding64 +// lldbg-check:[...] { 0 = -10005.5 1 = 10006 2 = 10007 } // lldbr-check:(tuple_struct::NoPadding64) no_padding64 = { 0 = -10005.5 1 = 10006 2 = 10007 } -// lldb-command:print no_padding163264 -// lldbg-check:[...]$3 = { 0 = -10008 1 = 10009 2 = 10010 3 = 10011 } +// lldb-command:v no_padding163264 +// lldbg-check:[...] { 0 = -10008 1 = 10009 2 = 10010 3 = 10011 } // lldbr-check:(tuple_struct::NoPadding163264) no_padding163264 = { 0 = -10008 1 = 10009 2 = 10010 3 = 10011 } -// lldb-command:print internal_padding -// lldbg-check:[...]$4 = { 0 = 10012 1 = -10013 } +// lldb-command:v internal_padding +// lldbg-check:[...] { 0 = 10012 1 = -10013 } // lldbr-check:(tuple_struct::InternalPadding) internal_padding = { 0 = 10012 1 = -10013 } -// lldb-command:print padding_at_end -// lldbg-check:[...]$5 = { 0 = -10014 1 = 10015 } +// lldb-command:v padding_at_end +// lldbg-check:[...] { 0 = -10014 1 = 10015 } // lldbr-check:(tuple_struct::PaddingAtEnd) padding_at_end = { 0 = -10014 1 = 10015 } // This test case mainly makes sure that no field names are generated for tuple structs (as opposed diff --git a/tests/debuginfo/tuple-style-enum.rs b/tests/debuginfo/tuple-style-enum.rs index e3e1684cc28..883aa658eb2 100644 --- a/tests/debuginfo/tuple-style-enum.rs +++ b/tests/debuginfo/tuple-style-enum.rs @@ -26,16 +26,16 @@ // lldb-command:run -// lldb-command:print case1 +// lldb-command:v case1 // lldbr-check:(tuple_style_enum::Regular::Case1) case1 = { = 0 = 31868 = 31868 = 31868 = 31868 } -// lldb-command:print case2 +// lldb-command:v case2 // lldbr-check:(tuple_style_enum::Regular::Case2) case2 = Case2 { Case1: 0, Case2: 286331153, Case3: 286331153 } -// lldb-command:print case3 +// lldb-command:v case3 // lldbr-check:(tuple_style_enum::Regular::Case3) case3 = Case3 { Case1: 0, Case2: 6438275382588823897 } -// lldb-command:print univariant +// lldb-command:v univariant // lldbr-check:(tuple_style_enum::Univariant) univariant = { TheOnlyCase = { = -1 } } #![allow(unused_variables)] diff --git a/tests/debuginfo/union-smoke.rs b/tests/debuginfo/union-smoke.rs index aa57ebdc844..9b1cf6e1e95 100644 --- a/tests/debuginfo/union-smoke.rs +++ b/tests/debuginfo/union-smoke.rs @@ -18,14 +18,14 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print u -// lldbg-check:[...]$0 = { a = { 0 = '\x02' 1 = '\x02' } b = 514 } +// lldb-command:v u +// lldbg-check:[...] { a = { 0 = '\x02' 1 = '\x02' } b = 514 } // lldbr-check:(union_smoke::U) u = { a = { 0 = '\x02' 1 = '\x02' } b = 514 } // Don't test this with rust-enabled lldb for now; see // https://github.com/rust-lang-nursery/lldb/issues/18 // lldbg-command:print union_smoke::SU -// lldbg-check:[...]$1 = { a = { 0 = '\x01' 1 = '\x01' } b = 257 } +// lldbg-check:[...] { a = { 0 = '\x01' 1 = '\x01' } b = 257 } #![allow(unused)] #![feature(omit_gdb_pretty_printer_section)] diff --git a/tests/debuginfo/unique-enum.rs b/tests/debuginfo/unique-enum.rs index db2b4403ec6..b3879468e0a 100644 --- a/tests/debuginfo/unique-enum.rs +++ b/tests/debuginfo/unique-enum.rs @@ -22,13 +22,13 @@ // lldb-command:run -// lldb-command:print *the_a +// lldb-command:v *the_a // lldbr-check:(unique_enum::ABC::TheA) *the_a = TheA { TheA: 0, TheB: 8970181431921507452 } -// lldb-command:print *the_b +// lldb-command:v *the_b // lldbr-check:(unique_enum::ABC::TheB) *the_b = { = 0 = 286331153 = 286331153 } -// lldb-command:print *univariant +// lldb-command:v *univariant // lldbr-check:(unique_enum::Univariant) *univariant = { TheOnlyCase = { = 123234 } } #![allow(unused_variables)] diff --git a/tests/debuginfo/var-captured-in-nested-closure.rs b/tests/debuginfo/var-captured-in-nested-closure.rs index 75ab245e13e..7772ec00337 100644 --- a/tests/debuginfo/var-captured-in-nested-closure.rs +++ b/tests/debuginfo/var-captured-in-nested-closure.rs @@ -43,43 +43,43 @@ // lldb-command:run -// lldb-command:print variable -// lldbg-check:[...]$0 = 1 +// lldb-command:v variable +// lldbg-check:[...] 1 // lldbr-check:(isize) variable = 1 -// lldb-command:print constant -// lldbg-check:[...]$1 = 2 +// lldb-command:v constant +// lldbg-check:[...] 2 // lldbr-check:(isize) constant = 2 -// lldb-command:print a_struct -// lldbg-check:[...]$2 = { a = -3 b = 4.5 c = 5 } +// lldb-command:v a_struct +// lldbg-check:[...] { a = -3 b = 4.5 c = 5 } // lldbr-check:(var_captured_in_nested_closure::Struct) a_struct = { a = -3 b = 4.5 c = 5 } -// lldb-command:print *struct_ref -// lldbg-check:[...]$3 = { a = -3 b = 4.5 c = 5 } +// lldb-command:v *struct_ref +// lldbg-check:[...] { a = -3 b = 4.5 c = 5 } // lldbr-check:(var_captured_in_nested_closure::Struct) *struct_ref = { a = -3 b = 4.5 c = 5 } -// lldb-command:print *owned -// lldbg-check:[...]$4 = 6 +// lldb-command:v *owned +// lldbg-check:[...] 6 // lldbr-check:(isize) *owned = 6 -// lldb-command:print closure_local -// lldbg-check:[...]$5 = 8 +// lldb-command:v closure_local +// lldbg-check:[...] 8 // lldbr-check:(isize) closure_local = 8 // lldb-command:continue -// lldb-command:print variable -// lldbg-check:[...]$6 = 1 +// lldb-command:v variable +// lldbg-check:[...] 1 // lldbr-check:(isize) variable = 1 -// lldb-command:print constant -// lldbg-check:[...]$7 = 2 +// lldb-command:v constant +// lldbg-check:[...] 2 // lldbr-check:(isize) constant = 2 -// lldb-command:print a_struct -// lldbg-check:[...]$8 = { a = -3 b = 4.5 c = 5 } +// lldb-command:v a_struct +// lldbg-check:[...] { a = -3 b = 4.5 c = 5 } // lldbr-check:(var_captured_in_nested_closure::Struct) a_struct = { a = -3 b = 4.5 c = 5 } -// lldb-command:print *struct_ref -// lldbg-check:[...]$9 = { a = -3 b = 4.5 c = 5 } +// lldb-command:v *struct_ref +// lldbg-check:[...] { a = -3 b = 4.5 c = 5 } // lldbr-check:(var_captured_in_nested_closure::Struct) *struct_ref = { a = -3 b = 4.5 c = 5 } -// lldb-command:print *owned -// lldbg-check:[...]$10 = 6 +// lldb-command:v *owned +// lldbg-check:[...] 6 // lldbr-check:(isize) *owned = 6 -// lldb-command:print closure_local -// lldbg-check:[...]$11 = 8 +// lldb-command:v closure_local +// lldbg-check:[...] 8 // lldbr-check:(isize) closure_local = 8 // lldb-command:continue diff --git a/tests/debuginfo/var-captured-in-sendable-closure.rs b/tests/debuginfo/var-captured-in-sendable-closure.rs index b7992deef44..782a7d11373 100644 --- a/tests/debuginfo/var-captured-in-sendable-closure.rs +++ b/tests/debuginfo/var-captured-in-sendable-closure.rs @@ -23,14 +23,14 @@ // lldb-command:run -// lldb-command:print constant -// lldbg-check:[...]$0 = 1 +// lldb-command:v constant +// lldbg-check:[...] 1 // lldbr-check:(isize) constant = 1 -// lldb-command:print a_struct -// lldbg-check:[...]$1 = { a = -2 b = 3.5 c = 4 } +// lldb-command:v a_struct +// lldbg-check:[...] { a = -2 b = 3.5 c = 4 } // lldbr-check:(var_captured_in_sendable_closure::Struct) a_struct = { a = -2 b = 3.5 c = 4 } -// lldb-command:print *owned -// lldbg-check:[...]$2 = 5 +// lldb-command:v *owned +// lldbg-check:[...] 5 // lldbr-check:(isize) *owned = 5 #![allow(unused_variables)] diff --git a/tests/debuginfo/var-captured-in-stack-closure.rs b/tests/debuginfo/var-captured-in-stack-closure.rs index eb68b081a6d..c9a93cd7b7f 100644 --- a/tests/debuginfo/var-captured-in-stack-closure.rs +++ b/tests/debuginfo/var-captured-in-stack-closure.rs @@ -39,38 +39,38 @@ // lldb-command:run -// lldb-command:print variable -// lldbg-check:[...]$0 = 1 +// lldb-command:v variable +// lldbg-check:[...] 1 // lldbr-check:(isize) variable = 1 -// lldb-command:print constant -// lldbg-check:[...]$1 = 2 +// lldb-command:v constant +// lldbg-check:[...] 2 // lldbr-check:(isize) constant = 2 -// lldb-command:print a_struct -// lldbg-check:[...]$2 = { a = -3 b = 4.5 c = 5 } +// lldb-command:v a_struct +// lldbg-check:[...] { a = -3 b = 4.5 c = 5 } // lldbr-check:(var_captured_in_stack_closure::Struct) a_struct = { a = -3 b = 4.5 c = 5 } -// lldb-command:print *struct_ref -// lldbg-check:[...]$3 = { a = -3 b = 4.5 c = 5 } +// lldb-command:v *struct_ref +// lldbg-check:[...] { a = -3 b = 4.5 c = 5 } // lldbr-check:(var_captured_in_stack_closure::Struct) *struct_ref = { a = -3 b = 4.5 c = 5 } -// lldb-command:print *owned -// lldbg-check:[...]$4 = 6 +// lldb-command:v *owned +// lldbg-check:[...] 6 // lldbr-check:(isize) *owned = 6 // lldb-command:continue -// lldb-command:print variable -// lldbg-check:[...]$5 = 2 +// lldb-command:v variable +// lldbg-check:[...] 2 // lldbr-check:(isize) variable = 2 -// lldb-command:print constant -// lldbg-check:[...]$6 = 2 +// lldb-command:v constant +// lldbg-check:[...] 2 // lldbr-check:(isize) constant = 2 -// lldb-command:print a_struct -// lldbg-check:[...]$7 = { a = -3 b = 4.5 c = 5 } +// lldb-command:v a_struct +// lldbg-check:[...] { a = -3 b = 4.5 c = 5 } // lldbr-check:(var_captured_in_stack_closure::Struct) a_struct = { a = -3 b = 4.5 c = 5 } -// lldb-command:print *struct_ref -// lldbg-check:[...]$8 = { a = -3 b = 4.5 c = 5 } +// lldb-command:v *struct_ref +// lldbg-check:[...] { a = -3 b = 4.5 c = 5 } // lldbr-check:(var_captured_in_stack_closure::Struct) *struct_ref = { a = -3 b = 4.5 c = 5 } -// lldb-command:print *owned -// lldbg-check:[...]$9 = 6 +// lldb-command:v *owned +// lldbg-check:[...] 6 // lldbr-check:(isize) *owned = 6 diff --git a/tests/debuginfo/vec-slices.rs b/tests/debuginfo/vec-slices.rs index b044110fc78..5a8481699b2 100644 --- a/tests/debuginfo/vec-slices.rs +++ b/tests/debuginfo/vec-slices.rs @@ -70,28 +70,28 @@ // lldb-command:run -// lldb-command:print empty -// lldbg-check:[...]$0 = size=0 +// lldb-command:v empty +// lldbg-check:[...] size=0 // lldbr-check:(&[i64]) empty = size=0 -// lldb-command:print singleton -// lldbg-check:[...]$1 = size=1 { [0] = 1 } +// lldb-command:v singleton +// lldbg-check:[...] size=1 { [0] = 1 } // lldbr-check:(&[i64]) singleton = &[1] -// lldb-command:print multiple -// lldbg-check:[...]$2 = size=4 { [0] = 2 [1] = 3 [2] = 4 [3] = 5 } +// lldb-command:v multiple +// lldbg-check:[...] size=4 { [0] = 2 [1] = 3 [2] = 4 [3] = 5 } // lldbr-check:(&[i64]) multiple = size=4 { [0] = 2 [1] = 3 [2] = 4 [3] = 5 } -// lldb-command:print slice_of_slice -// lldbg-check:[...]$3 = size=2 { [0] = 3 [1] = 4 } +// lldb-command:v slice_of_slice +// lldbg-check:[...] size=2 { [0] = 3 [1] = 4 } // lldbr-check:(&[i64]) slice_of_slice = size=2 { [0] = 3 [1] = 4 } -// lldb-command:print padded_tuple -// lldbg-check:[...]$4 = size=2 { [0] = { 0 = 6 1 = 7 } [1] = { 0 = 8 1 = 9 } } +// lldb-command:v padded_tuple +// lldbg-check:[...] size=2 { [0] = { 0 = 6 1 = 7 } [1] = { 0 = 8 1 = 9 } } // lldbr-check:(&[(i32, i16)]) padded_tuple = size=2 { [0] = { 0 = 6 1 = 7 } [1] = { 0 = 8 1 = 9 } } -// lldb-command:print padded_struct -// lldbg-check:[...]$5 = size=2 { [0] = { x = 10 y = 11 z = 12 } [1] = { x = 13 y = 14 z = 15 } } +// lldb-command:v padded_struct +// lldbg-check:[...] size=2 { [0] = { x = 10 y = 11 z = 12 } [1] = { x = 13 y = 14 z = 15 } } // lldbr-check:(&[vec_slices::AStruct]) padded_struct = size=2 { [0] = { x = 10 y = 11 z = 12 } [1] = { x = 13 y = 14 z = 15 } } #![allow(dead_code, unused_variables)] diff --git a/tests/debuginfo/vec.rs b/tests/debuginfo/vec.rs index 27d04094e3c..cf7de0b9b55 100644 --- a/tests/debuginfo/vec.rs +++ b/tests/debuginfo/vec.rs @@ -17,8 +17,8 @@ // === LLDB TESTS ================================================================================== // lldb-command:run -// lldb-command:print a -// lldbg-check:[...]$0 = { [0] = 1 [1] = 2 [2] = 3 } +// lldb-command:v a +// lldbg-check:[...] { [0] = 1 [1] = 2 [2] = 3 } // lldbr-check:([i32; 3]) a = { [0] = 1 [1] = 2 [2] = 3 } #![allow(unused_variables)] diff --git a/tests/mir-opt/array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.panic-abort.mir b/tests/mir-opt/array_index_is_temporary.main.SimplifyCfg-pre-optimizations.after.panic-abort.mir index 9b4c221df73..3b7c4b8796e 100644 --- a/tests/mir-opt/array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.panic-abort.mir +++ b/tests/mir-opt/array_index_is_temporary.main.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -1,4 +1,4 @@ -// MIR for `main` after SimplifyCfg-elaborate-drops +// MIR for `main` after SimplifyCfg-pre-optimizations fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/array_index_is_temporary.main.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index 4b05610f731..3dcddea0353 100644 --- a/tests/mir-opt/array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/array_index_is_temporary.main.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -1,4 +1,4 @@ -// MIR for `main` after SimplifyCfg-elaborate-drops +// MIR for `main` after SimplifyCfg-pre-optimizations fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/array_index_is_temporary.rs b/tests/mir-opt/array_index_is_temporary.rs index 3e5d5d5dd27..500b8b7f7c7 100644 --- a/tests/mir-opt/array_index_is_temporary.rs +++ b/tests/mir-opt/array_index_is_temporary.rs @@ -1,4 +1,4 @@ -//@ unit-test: SimplifyCfg-elaborate-drops +//@ unit-test: SimplifyCfg-pre-optimizations // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // Retagging (from Stacked Borrows) relies on the array index being a fresh // temporary, so that side-effects cannot change it. @@ -10,7 +10,7 @@ unsafe fn foo(z: *mut usize) -> u32 { } -// EMIT_MIR array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.mir +// EMIT_MIR array_index_is_temporary.main.SimplifyCfg-pre-optimizations.after.mir fn main() { // CHECK-LABEL: fn main( // CHECK: debug x => [[x:_.*]]; diff --git a/tests/mir-opt/asm_unwind_panic_abort.rs b/tests/mir-opt/asm_unwind_panic_abort.rs index d6830e12287..fff60942124 100644 --- a/tests/mir-opt/asm_unwind_panic_abort.rs +++ b/tests/mir-opt/asm_unwind_panic_abort.rs @@ -1,9 +1,8 @@ //! Tests that unwinding from an asm block is caught and forced to abort //! when `-C panic=abort`. -//@ only-x86_64 //@ compile-flags: -C panic=abort -//@ no-prefer-dynamic +//@ needs-asm-support #![feature(asm_unwind)] diff --git a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.panic-abort.mir b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.panic-abort.mir index 1fae40c5f40..06028487d01 100644 --- a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.panic-abort.mir +++ b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.panic-abort.mir @@ -1,6 +1,6 @@ // MIR for `main::{closure#0}::{closure#0}::{closure#0}` 0 coroutine_by_move -fn main::{closure#0}::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10}, _2: ResumeTy) -> () +fn main::{closure#0}::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:42:53: 45:10}, _2: ResumeTy) -> () yields () { debug _task_context => _2; diff --git a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.panic-unwind.mir b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.panic-unwind.mir index 1fae40c5f40..06028487d01 100644 --- a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.panic-unwind.mir +++ b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.panic-unwind.mir @@ -1,6 +1,6 @@ // MIR for `main::{closure#0}::{closure#0}::{closure#0}` 0 coroutine_by_move -fn main::{closure#0}::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10}, _2: ResumeTy) -> () +fn main::{closure#0}::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:42:53: 45:10}, _2: ResumeTy) -> () yields () { debug _task_context => _2; diff --git a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_mut.0.panic-abort.mir b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_mut.0.panic-abort.mir deleted file mode 100644 index 9886d6f68a4..00000000000 --- a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_mut.0.panic-abort.mir +++ /dev/null @@ -1,47 +0,0 @@ -// MIR for `main::{closure#0}::{closure#0}::{closure#0}` 0 coroutine_by_mut - -fn main::{closure#0}::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10}, _2: ResumeTy) -> () -yields () - { - debug _task_context => _2; - debug a => (_1.0: i32); - debug b => (*(_1.1: &i32)); - let mut _0: (); - let _3: i32; - scope 1 { - debug a => _3; - let _4: &i32; - scope 2 { - debug a => _4; - let _5: &i32; - scope 3 { - debug b => _5; - } - } - } - - bb0: { - StorageLive(_3); - _3 = (_1.0: i32); - FakeRead(ForLet(None), _3); - StorageLive(_4); - _4 = &_3; - FakeRead(ForLet(None), _4); - StorageLive(_5); - _5 = &(*(_1.1: &i32)); - FakeRead(ForLet(None), _5); - _0 = const (); - StorageDead(_5); - StorageDead(_4); - StorageDead(_3); - drop(_1) -> [return: bb1, unwind: bb2]; - } - - bb1: { - return; - } - - bb2 (cleanup): { - resume; - } -} diff --git a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_mut.0.panic-unwind.mir b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_mut.0.panic-unwind.mir deleted file mode 100644 index 9886d6f68a4..00000000000 --- a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_mut.0.panic-unwind.mir +++ /dev/null @@ -1,47 +0,0 @@ -// MIR for `main::{closure#0}::{closure#0}::{closure#0}` 0 coroutine_by_mut - -fn main::{closure#0}::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10}, _2: ResumeTy) -> () -yields () - { - debug _task_context => _2; - debug a => (_1.0: i32); - debug b => (*(_1.1: &i32)); - let mut _0: (); - let _3: i32; - scope 1 { - debug a => _3; - let _4: &i32; - scope 2 { - debug a => _4; - let _5: &i32; - scope 3 { - debug b => _5; - } - } - } - - bb0: { - StorageLive(_3); - _3 = (_1.0: i32); - FakeRead(ForLet(None), _3); - StorageLive(_4); - _4 = &_3; - FakeRead(ForLet(None), _4); - StorageLive(_5); - _5 = &(*(_1.1: &i32)); - FakeRead(ForLet(None), _5); - _0 = const (); - StorageDead(_5); - StorageDead(_4); - StorageDead(_3); - drop(_1) -> [return: bb1, unwind: bb2]; - } - - bb1: { - return; - } - - bb2 (cleanup): { - resume; - } -} diff --git a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-abort.mir b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-abort.mir index 21a9f6f8721..93447b1388d 100644 --- a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-abort.mir +++ b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-abort.mir @@ -1,10 +1,10 @@ // MIR for `main::{closure#0}::{closure#0}` 0 coroutine_closure_by_move -fn main::{closure#0}::{closure#0}(_1: {async closure@$DIR/async_closure_shims.rs:39:33: 39:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10} { - let mut _0: {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10}; +fn main::{closure#0}::{closure#0}(_1: {async closure@$DIR/async_closure_shims.rs:42:33: 42:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:42:53: 45:10} { + let mut _0: {async closure body@$DIR/async_closure_shims.rs:42:53: 45:10}; bb0: { - _0 = {coroutine@$DIR/async_closure_shims.rs:39:53: 42:10 (#0)} { a: move _2, b: move (_1.0: i32) }; + _0 = {coroutine@$DIR/async_closure_shims.rs:42:53: 45:10 (#0)} { a: move _2, b: move (_1.0: i32) }; return; } } diff --git a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-unwind.mir b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-unwind.mir index 21a9f6f8721..93447b1388d 100644 --- a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-unwind.mir +++ b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-unwind.mir @@ -1,10 +1,10 @@ // MIR for `main::{closure#0}::{closure#0}` 0 coroutine_closure_by_move -fn main::{closure#0}::{closure#0}(_1: {async closure@$DIR/async_closure_shims.rs:39:33: 39:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10} { - let mut _0: {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10}; +fn main::{closure#0}::{closure#0}(_1: {async closure@$DIR/async_closure_shims.rs:42:33: 42:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:42:53: 45:10} { + let mut _0: {async closure body@$DIR/async_closure_shims.rs:42:53: 45:10}; bb0: { - _0 = {coroutine@$DIR/async_closure_shims.rs:39:53: 42:10 (#0)} { a: move _2, b: move (_1.0: i32) }; + _0 = {coroutine@$DIR/async_closure_shims.rs:42:53: 45:10 (#0)} { a: move _2, b: move (_1.0: i32) }; return; } } diff --git a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_mut.0.panic-abort.mir b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_mut.0.panic-abort.mir deleted file mode 100644 index 1cfb6c2f3ea..00000000000 --- a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_mut.0.panic-abort.mir +++ /dev/null @@ -1,16 +0,0 @@ -// MIR for `main::{closure#0}::{closure#0}` 0 coroutine_closure_by_mut - -fn main::{closure#0}::{closure#0}(_1: &mut {async closure@$DIR/async_closure_shims.rs:39:33: 39:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10} { - debug a => _2; - debug b => ((*_1).0: i32); - let mut _0: {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10}; - let mut _3: &i32; - - bb0: { - StorageLive(_3); - _3 = &((*_1).0: i32); - _0 = {coroutine@$DIR/async_closure_shims.rs:39:53: 42:10 (#0)} { a: _2, b: move _3 }; - StorageDead(_3); - return; - } -} diff --git a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_mut.0.panic-unwind.mir b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_mut.0.panic-unwind.mir deleted file mode 100644 index 1cfb6c2f3ea..00000000000 --- a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_mut.0.panic-unwind.mir +++ /dev/null @@ -1,16 +0,0 @@ -// MIR for `main::{closure#0}::{closure#0}` 0 coroutine_closure_by_mut - -fn main::{closure#0}::{closure#0}(_1: &mut {async closure@$DIR/async_closure_shims.rs:39:33: 39:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10} { - debug a => _2; - debug b => ((*_1).0: i32); - let mut _0: {async closure body@$DIR/async_closure_shims.rs:39:53: 42:10}; - let mut _3: &i32; - - bb0: { - StorageLive(_3); - _3 = &((*_1).0: i32); - _0 = {coroutine@$DIR/async_closure_shims.rs:39:53: 42:10 (#0)} { a: _2, b: move _3 }; - StorageDead(_3); - return; - } -} diff --git a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.panic-abort.mir b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.panic-abort.mir new file mode 100644 index 00000000000..f51540bcfff --- /dev/null +++ b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.panic-abort.mir @@ -0,0 +1,10 @@ +// MIR for `main::{closure#0}::{closure#1}` 0 coroutine_closure_by_ref + +fn main::{closure#0}::{closure#1}(_1: *mut {async closure@$DIR/async_closure_shims.rs:49:29: 49:48}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:49:49: 51:10} { + let mut _0: {async closure body@$DIR/async_closure_shims.rs:49:49: 51:10}; + + bb0: { + _0 = {coroutine@$DIR/async_closure_shims.rs:49:49: 51:10 (#0)} { a: move _2 }; + return; + } +} diff --git a/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.panic-unwind.mir b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.panic-unwind.mir new file mode 100644 index 00000000000..f51540bcfff --- /dev/null +++ b/tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.panic-unwind.mir @@ -0,0 +1,10 @@ +// MIR for `main::{closure#0}::{closure#1}` 0 coroutine_closure_by_ref + +fn main::{closure#0}::{closure#1}(_1: *mut {async closure@$DIR/async_closure_shims.rs:49:29: 49:48}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:49:49: 51:10} { + let mut _0: {async closure body@$DIR/async_closure_shims.rs:49:49: 51:10}; + + bb0: { + _0 = {coroutine@$DIR/async_closure_shims.rs:49:49: 51:10 (#0)} { a: move _2 }; + return; + } +} diff --git a/tests/mir-opt/async_closure_shims.rs b/tests/mir-opt/async_closure_shims.rs index 5e875321400..7d226df6866 100644 --- a/tests/mir-opt/async_closure_shims.rs +++ b/tests/mir-opt/async_closure_shims.rs @@ -29,10 +29,13 @@ async fn call_once(f: impl AsyncFnOnce(i32)) { f(1).await; } +async fn call_normal<F: Future<Output = ()>>(f: &impl Fn(i32) -> F) { + f(1).await; +} + // EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.mir -// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_mut.0.mir -// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_mut.0.mir // EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.mir +// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.mir pub fn main() { block_on(async { let b = 2i32; @@ -42,5 +45,10 @@ pub fn main() { }; call_mut(&mut async_closure).await; call_once(async_closure).await; + + let async_closure = async move |a: i32| { + let a = &a; + }; + call_normal(&async_closure).await; }); } diff --git a/tests/mir-opt/byte_slice.main.SimplifyCfg-elaborate-drops.after.mir b/tests/mir-opt/byte_slice.main.SimplifyCfg-pre-optimizations.after.mir index 09a65e6e6a6..c53b5e48610 100644 --- a/tests/mir-opt/byte_slice.main.SimplifyCfg-elaborate-drops.after.mir +++ b/tests/mir-opt/byte_slice.main.SimplifyCfg-pre-optimizations.after.mir @@ -1,4 +1,4 @@ -// MIR for `main` after SimplifyCfg-elaborate-drops +// MIR for `main` after SimplifyCfg-pre-optimizations fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/byte_slice.rs b/tests/mir-opt/byte_slice.rs index c064e2945fd..fa616b62ad0 100644 --- a/tests/mir-opt/byte_slice.rs +++ b/tests/mir-opt/byte_slice.rs @@ -1,7 +1,7 @@ // skip-filecheck //@ compile-flags: -Z mir-opt-level=0 -// EMIT_MIR byte_slice.main.SimplifyCfg-elaborate-drops.after.mir +// EMIT_MIR byte_slice.main.SimplifyCfg-pre-optimizations.after.mir fn main() { let x = b"foo"; let y = [5u8, b'x']; diff --git a/tests/mir-opt/const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-elaborate-drops.after.mir b/tests/mir-opt/const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-pre-optimizations.after.mir index b4ae8386add..7affbf6dd40 100644 --- a/tests/mir-opt/const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-elaborate-drops.after.mir +++ b/tests/mir-opt/const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-pre-optimizations.after.mir @@ -1,4 +1,4 @@ -// MIR for `BAR::promoted[0]` after SimplifyCfg-elaborate-drops +// MIR for `BAR::promoted[0]` after SimplifyCfg-pre-optimizations const BAR::promoted[0]: &[&i32; 1] = { let mut _0: &[&i32; 1]; diff --git a/tests/mir-opt/const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-elaborate-drops.after.mir b/tests/mir-opt/const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-pre-optimizations.after.mir index 8d4bfa711e4..72cb64e275e 100644 --- a/tests/mir-opt/const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-elaborate-drops.after.mir +++ b/tests/mir-opt/const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-pre-optimizations.after.mir @@ -1,4 +1,4 @@ -// MIR for `FOO::promoted[0]` after SimplifyCfg-elaborate-drops +// MIR for `FOO::promoted[0]` after SimplifyCfg-pre-optimizations const FOO::promoted[0]: &[&i32; 1] = { let mut _0: &[&i32; 1]; diff --git a/tests/mir-opt/const_promotion_extern_static.rs b/tests/mir-opt/const_promotion_extern_static.rs index 077e74e91f4..fe258f5e8fd 100644 --- a/tests/mir-opt/const_promotion_extern_static.rs +++ b/tests/mir-opt/const_promotion_extern_static.rs @@ -6,11 +6,11 @@ extern "C" { static Y: i32 = 42; // EMIT_MIR const_promotion_extern_static.BAR.PromoteTemps.diff -// EMIT_MIR const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-elaborate-drops.after.mir +// EMIT_MIR const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-pre-optimizations.after.mir static mut BAR: *const &i32 = [&Y].as_ptr(); // EMIT_MIR const_promotion_extern_static.FOO.PromoteTemps.diff -// EMIT_MIR const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-elaborate-drops.after.mir +// EMIT_MIR const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-pre-optimizations.after.mir static mut FOO: *const &i32 = [unsafe { &X }].as_ptr(); // EMIT_MIR const_promotion_extern_static.BOP.built.after.mir diff --git a/tests/mir-opt/instrument_coverage_cleanup.main.CleanupPostBorrowck.diff b/tests/mir-opt/instrument_coverage_cleanup.main.CleanupPostBorrowck.diff new file mode 100644 index 00000000000..ff65ca77039 --- /dev/null +++ b/tests/mir-opt/instrument_coverage_cleanup.main.CleanupPostBorrowck.diff @@ -0,0 +1,56 @@ +- // MIR for `main` before CleanupPostBorrowck ++ // MIR for `main` after CleanupPostBorrowck + + fn main() -> () { + let mut _0: (); + let mut _1: bool; + + coverage branch { true: BlockMarkerId(0), false: BlockMarkerId(1) } => /the/src/instrument_coverage_cleanup.rs:15:8: 15:36 (#0) + + coverage ExpressionId(0) => Expression { lhs: Counter(0), op: Subtract, rhs: Counter(1) }; + coverage ExpressionId(1) => Expression { lhs: Counter(1), op: Add, rhs: Expression(0) }; + coverage Code(Counter(0)) => /the/src/instrument_coverage_cleanup.rs:14:1 - 15:36; + coverage Code(Expression(0)) => /the/src/instrument_coverage_cleanup.rs:15:37 - 15:39; + coverage Code(Counter(1)) => /the/src/instrument_coverage_cleanup.rs:15:39 - 15:40; + coverage Code(Expression(1)) => /the/src/instrument_coverage_cleanup.rs:16:1 - 16:2; + coverage Branch { true_term: Expression(0), false_term: Counter(1) } => /the/src/instrument_coverage_cleanup.rs:15:8 - 15:36; + + bb0: { + Coverage::CounterIncrement(0); +- Coverage::SpanMarker; ++ nop; + StorageLive(_1); + _1 = std::hint::black_box::<bool>(const true) -> [return: bb1, unwind: bb5]; + } + + bb1: { + switchInt(move _1) -> [0: bb3, otherwise: bb2]; + } + + bb2: { + Coverage::CounterIncrement(1); +- Coverage::BlockMarker(1); ++ nop; + _0 = const (); + goto -> bb4; + } + + bb3: { + Coverage::ExpressionUsed(0); +- Coverage::BlockMarker(0); ++ nop; + _0 = const (); + goto -> bb4; + } + + bb4: { + Coverage::ExpressionUsed(1); + StorageDead(_1); + return; + } + + bb5 (cleanup): { + resume; + } + } + diff --git a/tests/mir-opt/instrument_coverage_cleanup.main.InstrumentCoverage.diff b/tests/mir-opt/instrument_coverage_cleanup.main.InstrumentCoverage.diff new file mode 100644 index 00000000000..8757559149a --- /dev/null +++ b/tests/mir-opt/instrument_coverage_cleanup.main.InstrumentCoverage.diff @@ -0,0 +1,53 @@ +- // MIR for `main` before InstrumentCoverage ++ // MIR for `main` after InstrumentCoverage + + fn main() -> () { + let mut _0: (); + let mut _1: bool; + + coverage branch { true: BlockMarkerId(0), false: BlockMarkerId(1) } => /the/src/instrument_coverage_cleanup.rs:15:8: 15:36 (#0) + ++ coverage ExpressionId(0) => Expression { lhs: Counter(0), op: Subtract, rhs: Counter(1) }; ++ coverage ExpressionId(1) => Expression { lhs: Counter(1), op: Add, rhs: Expression(0) }; ++ coverage Code(Counter(0)) => /the/src/instrument_coverage_cleanup.rs:14:1 - 15:36; ++ coverage Code(Expression(0)) => /the/src/instrument_coverage_cleanup.rs:15:37 - 15:39; ++ coverage Code(Counter(1)) => /the/src/instrument_coverage_cleanup.rs:15:39 - 15:40; ++ coverage Code(Expression(1)) => /the/src/instrument_coverage_cleanup.rs:16:1 - 16:2; ++ coverage Branch { true_term: Expression(0), false_term: Counter(1) } => /the/src/instrument_coverage_cleanup.rs:15:8 - 15:36; ++ + bb0: { ++ Coverage::CounterIncrement(0); + Coverage::SpanMarker; + StorageLive(_1); + _1 = std::hint::black_box::<bool>(const true) -> [return: bb1, unwind: bb5]; + } + + bb1: { + switchInt(move _1) -> [0: bb3, otherwise: bb2]; + } + + bb2: { ++ Coverage::CounterIncrement(1); + Coverage::BlockMarker(1); + _0 = const (); + goto -> bb4; + } + + bb3: { ++ Coverage::ExpressionUsed(0); + Coverage::BlockMarker(0); + _0 = const (); + goto -> bb4; + } + + bb4: { ++ Coverage::ExpressionUsed(1); + StorageDead(_1); + return; + } + + bb5 (cleanup): { + resume; + } + } + diff --git a/tests/mir-opt/instrument_coverage_cleanup.rs b/tests/mir-opt/instrument_coverage_cleanup.rs new file mode 100644 index 00000000000..8a2fd67139b --- /dev/null +++ b/tests/mir-opt/instrument_coverage_cleanup.rs @@ -0,0 +1,22 @@ +// Test that CleanupPostBorrowck cleans up the marker statements that are +// inserted during MIR building (after InstrumentCoverage is done with them), +// but leaves the statements that were added by InstrumentCoverage. +// +// Removed statement kinds: BlockMarker, SpanMarker +// Retained statement kinds: CounterIncrement, ExpressionUsed + +//@ unit-test: InstrumentCoverage +//@ compile-flags: -Cinstrument-coverage -Zcoverage-options=branch -Zno-profiler-runtime +//@ compile-flags: --remap-path-prefix={{src-base}}=/the/src + +// EMIT_MIR instrument_coverage_cleanup.main.InstrumentCoverage.diff +// EMIT_MIR instrument_coverage_cleanup.main.CleanupPostBorrowck.diff +fn main() { + if !core::hint::black_box(true) {} +} + +// CHECK-NOT: Coverage::BlockMarker +// CHECK-NOT: Coverage::SpanMarker +// CHECK: Coverage::CounterIncrement +// CHECK-NOT: Coverage::BlockMarker +// CHECK-NOT: Coverage::SpanMarker diff --git a/tests/mir-opt/issue_99325.main.built.after.32bit.mir b/tests/mir-opt/issue_99325.main.built.after.32bit.mir index f8e195466ee..c8039dc4735 100644 --- a/tests/mir-opt/issue_99325.main.built.after.32bit.mir +++ b/tests/mir-opt/issue_99325.main.built.after.32bit.mir @@ -2,7 +2,7 @@ | User Type Annotations | 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} -| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} +| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &'static [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} | fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/issue_99325.main.built.after.64bit.mir b/tests/mir-opt/issue_99325.main.built.after.64bit.mir index f8e195466ee..c8039dc4735 100644 --- a/tests/mir-opt/issue_99325.main.built.after.64bit.mir +++ b/tests/mir-opt/issue_99325.main.built.after.64bit.mir @@ -2,7 +2,7 @@ | User Type Annotations | 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} -| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} +| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &'static [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} | fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/no_drop_for_inactive_variant.rs b/tests/mir-opt/no_drop_for_inactive_variant.rs index dd20e4a548e..c94b36971ca 100644 --- a/tests/mir-opt/no_drop_for_inactive_variant.rs +++ b/tests/mir-opt/no_drop_for_inactive_variant.rs @@ -4,7 +4,7 @@ // Ensure that there are no drop terminators in `unwrap<T>` (except the one along the cleanup // path). -// EMIT_MIR no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.mir +// EMIT_MIR no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.mir fn unwrap<T>(opt: Option<T>) -> T { match opt { Some(x) => x, diff --git a/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.panic-abort.mir b/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.panic-abort.mir index 31a6a1d8b3d..fa6c6ce8e57 100644 --- a/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.panic-abort.mir +++ b/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -1,4 +1,4 @@ -// MIR for `unwrap` after SimplifyCfg-elaborate-drops +// MIR for `unwrap` after SimplifyCfg-pre-optimizations fn unwrap(_1: Option<T>) -> T { debug opt => _1; diff --git a/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index 53352fbb19f..54fec3c0f98 100644 --- a/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -1,4 +1,4 @@ -// MIR for `unwrap` after SimplifyCfg-elaborate-drops +// MIR for `unwrap` after SimplifyCfg-pre-optimizations fn unwrap(_1: Option<T>) -> T { debug opt => _1; diff --git a/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.panic-abort.mir b/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-pre-optimizations.after.panic-abort.mir index 089adff0c56..57f3c614afa 100644 --- a/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.panic-abort.mir +++ b/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -1,4 +1,4 @@ -// MIR for `main` after SimplifyCfg-elaborate-drops +// MIR for `main` after SimplifyCfg-pre-optimizations fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index 0ef19180459..d5d466a1c30 100644 --- a/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -1,4 +1,4 @@ -// MIR for `main` after SimplifyCfg-elaborate-drops +// MIR for `main` after SimplifyCfg-pre-optimizations fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/packed_struct_drop_aligned.rs b/tests/mir-opt/packed_struct_drop_aligned.rs index 079c4e68f50..dff941c4fa0 100644 --- a/tests/mir-opt/packed_struct_drop_aligned.rs +++ b/tests/mir-opt/packed_struct_drop_aligned.rs @@ -2,7 +2,7 @@ // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -// EMIT_MIR packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.mir +// EMIT_MIR packed_struct_drop_aligned.main.SimplifyCfg-pre-optimizations.after.mir fn main() { let mut x = Packed(Aligned(Droppy(0))); x.0 = Aligned(Droppy(0)); diff --git a/tests/mir-opt/pre-codegen/checked_ops.rs b/tests/mir-opt/pre-codegen/checked_ops.rs index d36502d3547..3ff1123d0b1 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.rs +++ b/tests/mir-opt/pre-codegen/checked_ops.rs @@ -1,7 +1,6 @@ // skip-filecheck //@ compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=2 //@ needs-unwind -//@ only-x86_64 #![crate_type = "lib"] #![feature(step_trait)] diff --git a/tests/mir-opt/pre-codegen/intrinsics.rs b/tests/mir-opt/pre-codegen/intrinsics.rs index ed7320cd3c4..e5c059cda12 100644 --- a/tests/mir-opt/pre-codegen/intrinsics.rs +++ b/tests/mir-opt/pre-codegen/intrinsics.rs @@ -1,6 +1,5 @@ // skip-filecheck //@ compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -//@ only-64bit // Checks that we do not have any branches in the MIR for the two tested functions. diff --git a/tests/mir-opt/pre-codegen/loops.rs b/tests/mir-opt/pre-codegen/loops.rs index 2d179abc9f3..d0b8cc8db7a 100644 --- a/tests/mir-opt/pre-codegen/loops.rs +++ b/tests/mir-opt/pre-codegen/loops.rs @@ -1,7 +1,6 @@ // skip-filecheck //@ compile-flags: -O -Zmir-opt-level=2 -g //@ needs-unwind -//@ only-64bit #![crate_type = "lib"] diff --git a/tests/mir-opt/pre-codegen/mem_replace.rs b/tests/mir-opt/pre-codegen/mem_replace.rs index 535c1062669..9cb3a839956 100644 --- a/tests/mir-opt/pre-codegen/mem_replace.rs +++ b/tests/mir-opt/pre-codegen/mem_replace.rs @@ -1,6 +1,5 @@ // skip-filecheck //@ compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -Zinline-mir -//@ only-64bit //@ ignore-debug the standard library debug assertions leak into this test // EMIT_MIR_FOR_EACH_PANIC_STRATEGY diff --git a/tests/mir-opt/pre-codegen/range_iter.rs b/tests/mir-opt/pre-codegen/range_iter.rs index fe7d0e67f7a..5aa617227ce 100644 --- a/tests/mir-opt/pre-codegen/range_iter.rs +++ b/tests/mir-opt/pre-codegen/range_iter.rs @@ -1,6 +1,5 @@ // skip-filecheck //@ compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -//@ only-64bit // EMIT_MIR_FOR_EACH_PANIC_STRATEGY #![crate_type = "lib"] diff --git a/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir index 718dba21a95..7265a4fc942 100644 --- a/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir @@ -3,9 +3,9 @@ fn ezmap(_1: Option<i32>) -> Option<i32> { debug x => _1; let mut _0: std::option::Option<i32>; - scope 1 (inlined map::<i32, i32, {closure@$DIR/simple_option_map.rs:18:12: 18:15}>) { + scope 1 (inlined map::<i32, i32, {closure@$DIR/simple_option_map.rs:17:12: 17:15}>) { debug slf => _1; - debug f => const ZeroSized: {closure@$DIR/simple_option_map.rs:18:12: 18:15}; + debug f => const ZeroSized: {closure@$DIR/simple_option_map.rs:17:12: 17:15}; let mut _2: isize; let _3: i32; let mut _4: i32; diff --git a/tests/mir-opt/pre-codegen/simple_option_map.rs b/tests/mir-opt/pre-codegen/simple_option_map.rs index c563f6af2a5..0c432be0419 100644 --- a/tests/mir-opt/pre-codegen/simple_option_map.rs +++ b/tests/mir-opt/pre-codegen/simple_option_map.rs @@ -1,6 +1,5 @@ // skip-filecheck //@ compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -//@ only-64bit #[inline(always)] fn map<T, U, F>(slf: Option<T>, f: F) -> Option<U> diff --git a/tests/mir-opt/pre-codegen/slice_index.rs b/tests/mir-opt/pre-codegen/slice_index.rs index 80bbffbd097..1d977ee9214 100644 --- a/tests/mir-opt/pre-codegen/slice_index.rs +++ b/tests/mir-opt/pre-codegen/slice_index.rs @@ -1,6 +1,5 @@ // skip-filecheck //@ compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -//@ only-64bit //@ ignore-debug the standard library debug assertions leak into this test // EMIT_MIR_FOR_EACH_PANIC_STRATEGY diff --git a/tests/mir-opt/pre-codegen/slice_iter.rs b/tests/mir-opt/pre-codegen/slice_iter.rs index 0269eb39ddf..0fbd3706544 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.rs +++ b/tests/mir-opt/pre-codegen/slice_iter.rs @@ -1,6 +1,5 @@ // skip-filecheck //@ compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -//@ only-64bit //@ ignore-debug the standard library debug assertions leak into this test // EMIT_MIR_FOR_EACH_PANIC_STRATEGY diff --git a/tests/mir-opt/pre-codegen/try_identity.rs b/tests/mir-opt/pre-codegen/try_identity.rs index 9da02d65e15..2e17a3ae6e7 100644 --- a/tests/mir-opt/pre-codegen/try_identity.rs +++ b/tests/mir-opt/pre-codegen/try_identity.rs @@ -1,6 +1,5 @@ // skip-filecheck //@ compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -//@ only-64bit // Track the status of MIR optimizations simplifying `Ok(res?)` for both the old and new desugarings // of that syntax. diff --git a/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-abort.mir b/tests/mir-opt/retag.array_casts.SimplifyCfg-pre-optimizations.after.panic-abort.mir index 0580bf3e2d0..7124b4c1cd8 100644 --- a/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-abort.mir +++ b/tests/mir-opt/retag.array_casts.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -1,4 +1,4 @@ -// MIR for `array_casts` after SimplifyCfg-elaborate-drops +// MIR for `array_casts` after SimplifyCfg-pre-optimizations fn array_casts() -> () { let mut _0: (); diff --git a/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/retag.array_casts.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index 6f3cc9051d3..be04757f2a3 100644 --- a/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/retag.array_casts.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -1,4 +1,4 @@ -// MIR for `array_casts` after SimplifyCfg-elaborate-drops +// MIR for `array_casts` after SimplifyCfg-pre-optimizations fn array_casts() -> () { let mut _0: (); diff --git a/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-abort.mir b/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-abort.mir new file mode 100644 index 00000000000..0e568f6a568 --- /dev/null +++ b/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -0,0 +1,17 @@ +// MIR for `box_to_raw_mut` after SimplifyCfg-pre-optimizations + +fn box_to_raw_mut(_1: &mut Box<i32>) -> *mut i32 { + debug x => _1; + let mut _0: *mut i32; + let mut _2: std::boxed::Box<i32>; + let mut _3: *const i32; + + bb0: { + Retag([fn entry] _1); + _2 = deref_copy (*_1); + _3 = (((_2.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>).0: *const i32); + _0 = &raw mut (*_3); + Retag([raw] _0); + return; + } +} diff --git a/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-unwind.mir b/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-unwind.mir new file mode 100644 index 00000000000..0e568f6a568 --- /dev/null +++ b/tests/mir-opt/retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -0,0 +1,17 @@ +// MIR for `box_to_raw_mut` after SimplifyCfg-pre-optimizations + +fn box_to_raw_mut(_1: &mut Box<i32>) -> *mut i32 { + debug x => _1; + let mut _0: *mut i32; + let mut _2: std::boxed::Box<i32>; + let mut _3: *const i32; + + bb0: { + Retag([fn entry] _1); + _2 = deref_copy (*_1); + _3 = (((_2.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>).0: *const i32); + _0 = &raw mut (*_3); + Retag([raw] _0); + return; + } +} diff --git a/tests/mir-opt/retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.panic-abort.mir b/tests/mir-opt/retag.main-{closure#0}.SimplifyCfg-pre-optimizations.after.panic-abort.mir index 7f3310919ca..2620929e896 100644 --- a/tests/mir-opt/retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.panic-abort.mir +++ b/tests/mir-opt/retag.main-{closure#0}.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -1,4 +1,4 @@ -// MIR for `main::{closure#0}` after SimplifyCfg-elaborate-drops +// MIR for `main::{closure#0}` after SimplifyCfg-pre-optimizations fn main::{closure#0}(_1: &{closure@main::{closure#0}}, _2: &i32) -> &i32 { debug x => _2; diff --git a/tests/mir-opt/retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/retag.main-{closure#0}.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index 7f3310919ca..2620929e896 100644 --- a/tests/mir-opt/retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/retag.main-{closure#0}.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -1,4 +1,4 @@ -// MIR for `main::{closure#0}` after SimplifyCfg-elaborate-drops +// MIR for `main::{closure#0}` after SimplifyCfg-pre-optimizations fn main::{closure#0}(_1: &{closure@main::{closure#0}}, _2: &i32) -> &i32 { debug x => _2; diff --git a/tests/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.panic-abort.mir b/tests/mir-opt/retag.main.SimplifyCfg-pre-optimizations.after.panic-abort.mir index 96a76cc66ab..d7372a05082 100644 --- a/tests/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.panic-abort.mir +++ b/tests/mir-opt/retag.main.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -1,4 +1,4 @@ -// MIR for `main` after SimplifyCfg-elaborate-drops +// MIR for `main` after SimplifyCfg-pre-optimizations fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/retag.main.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index 2cedf4c3f5f..6ec62bfcf8c 100644 --- a/tests/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/retag.main.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -1,4 +1,4 @@ -// MIR for `main` after SimplifyCfg-elaborate-drops +// MIR for `main` after SimplifyCfg-pre-optimizations fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/retag.rs b/tests/mir-opt/retag.rs index 0f2659ebfe8..17b3c10abeb 100644 --- a/tests/mir-opt/retag.rs +++ b/tests/mir-opt/retag.rs @@ -8,8 +8,8 @@ struct Test(i32); -// EMIT_MIR retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.mir -// EMIT_MIR retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.mir +// EMIT_MIR retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.mir +// EMIT_MIR retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.mir impl Test { // Make sure we run the pass on a method, not just on bare functions. fn foo<'x>(&self, x: &'x mut i32) -> &'x mut i32 { @@ -26,8 +26,8 @@ impl Drop for Test { fn drop(&mut self) {} } -// EMIT_MIR retag.main.SimplifyCfg-elaborate-drops.after.mir -// EMIT_MIR retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.mir +// EMIT_MIR retag.main.SimplifyCfg-pre-optimizations.after.mir +// EMIT_MIR retag.main-{closure#0}.SimplifyCfg-pre-optimizations.after.mir pub fn main() { let mut x = 0; { @@ -55,7 +55,7 @@ pub fn main() { } /// Casting directly to an array should also go through `&raw` and thus add appropriate retags. -// EMIT_MIR retag.array_casts.SimplifyCfg-elaborate-drops.after.mir +// EMIT_MIR retag.array_casts.SimplifyCfg-pre-optimizations.after.mir fn array_casts() { let mut x: [usize; 2] = [0, 0]; let p = &mut x as *mut usize; @@ -65,3 +65,8 @@ fn array_casts() { let p = &x as *const usize; assert_eq!(unsafe { *p.add(1) }, 1); } + +// EMIT_MIR retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.mir +fn box_to_raw_mut(x: &mut Box<i32>) -> *mut i32 { + std::ptr::addr_of_mut!(**x) +} diff --git a/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.panic-abort.mir b/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.panic-abort.mir index 285db435f5a..b656656919e 100644 --- a/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.panic-abort.mir +++ b/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -1,4 +1,4 @@ -// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo` after SimplifyCfg-elaborate-drops +// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo` after SimplifyCfg-pre-optimizations fn <impl at $DIR/retag.rs:13:1: 13:10>::foo(_1: &Test, _2: &mut i32) -> &mut i32 { debug self => _1; diff --git a/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index 285db435f5a..b656656919e 100644 --- a/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -1,4 +1,4 @@ -// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo` after SimplifyCfg-elaborate-drops +// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo` after SimplifyCfg-pre-optimizations fn <impl at $DIR/retag.rs:13:1: 13:10>::foo(_1: &Test, _2: &mut i32) -> &mut i32 { debug self => _1; diff --git a/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.panic-abort.mir b/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.panic-abort.mir index 9ad607b2fe2..4f90413e38b 100644 --- a/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.panic-abort.mir +++ b/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -1,4 +1,4 @@ -// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo_shr` after SimplifyCfg-elaborate-drops +// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo_shr` after SimplifyCfg-pre-optimizations fn <impl at $DIR/retag.rs:13:1: 13:10>::foo_shr(_1: &Test, _2: &i32) -> &i32 { debug self => _1; diff --git a/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index 9ad607b2fe2..4f90413e38b 100644 --- a/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -1,4 +1,4 @@ -// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo_shr` after SimplifyCfg-elaborate-drops +// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo_shr` after SimplifyCfg-pre-optimizations fn <impl at $DIR/retag.rs:13:1: 13:10>::foo_shr(_1: &Test, _2: &i32) -> &i32 { debug self => _1; diff --git a/tests/mir-opt/simplify_cfg.main.SimplifyCfg-early-opt.diff b/tests/mir-opt/simplify_cfg.main.SimplifyCfg-post-analysis.diff index f20ab869b7b..0e41950d626 100644 --- a/tests/mir-opt/simplify_cfg.main.SimplifyCfg-early-opt.diff +++ b/tests/mir-opt/simplify_cfg.main.SimplifyCfg-post-analysis.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before SimplifyCfg-early-opt -+ // MIR for `main` after SimplifyCfg-early-opt +- // MIR for `main` before SimplifyCfg-post-analysis ++ // MIR for `main` after SimplifyCfg-post-analysis fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/simplify_cfg.rs b/tests/mir-opt/simplify_cfg.rs index 8dea0e50a61..b1fdc5e64a0 100644 --- a/tests/mir-opt/simplify_cfg.rs +++ b/tests/mir-opt/simplify_cfg.rs @@ -4,7 +4,7 @@ //@ no-prefer-dynamic // EMIT_MIR simplify_cfg.main.SimplifyCfg-initial.diff -// EMIT_MIR simplify_cfg.main.SimplifyCfg-early-opt.diff +// EMIT_MIR simplify_cfg.main.SimplifyCfg-post-analysis.diff fn main() { loop { if bar() { diff --git a/tests/pretty/postfix-match.rs b/tests/pretty/postfix-match.rs new file mode 100644 index 00000000000..5bb54e15275 --- /dev/null +++ b/tests/pretty/postfix-match.rs @@ -0,0 +1,21 @@ +#![feature(postfix_match)] + +fn main() { + let val = Some(42); + + val.match { + Some(_) => 2, + _ => 1 + }; + + + Some(2).match { + Some(_) => true, + None => false + }.match { + false => "ferris is cute", + true => "I turn cats in to petted cats", + }.match { + _ => (), + } +} diff --git a/tests/run-make-fulldeps/obtain-borrowck/driver.rs b/tests/run-make-fulldeps/obtain-borrowck/driver.rs index 2e3bf70e144..e67ec8690f8 100644 --- a/tests/run-make-fulldeps/obtain-borrowck/driver.rs +++ b/tests/run-make-fulldeps/obtain-borrowck/driver.rs @@ -68,7 +68,7 @@ impl rustc_driver::Callbacks for CompilerCalls { let mut bodies = Vec::new(); let crate_items = tcx.hir_crate_items(()); - for id in crate_items.items() { + for id in crate_items.free_items() { if matches!(tcx.def_kind(id.owner_id), DefKind::Fn) { bodies.push(id.owner_id); } diff --git a/tests/run-make/long-linker-command-lines/Makefile b/tests/run-make/long-linker-command-lines/Makefile index f864ea74f4a..b573038e344 100644 --- a/tests/run-make/long-linker-command-lines/Makefile +++ b/tests/run-make/long-linker-command-lines/Makefile @@ -1,6 +1,8 @@ # ignore-cross-compile include ../tools.mk +export LD_LIBRARY_PATH := $(HOST_RPATH_DIR) + all: $(RUSTC) foo.rs -g -O RUSTC="$(RUSTC_ORIGINAL)" $(call RUN,foo) diff --git a/tests/run-make/lto-linkage-used-attr/Makefile b/tests/run-make/lto-linkage-used-attr/Makefile index e78b83890ed..fed41a00f84 100644 --- a/tests/run-make/lto-linkage-used-attr/Makefile +++ b/tests/run-make/lto-linkage-used-attr/Makefile @@ -2,7 +2,6 @@ include ../tools.mk # Verify that the impl_* symbols are preserved. #108030 # only-x86_64-unknown-linux-gnu -# min-llvm-version: 17 all: $(RUSTC) -Cdebuginfo=0 -Copt-level=3 lib.rs diff --git a/tests/rustdoc-ui/invalid_associated_const.rs b/tests/rustdoc-ui/invalid_associated_const.rs index 6ab8c36f740..6f211a383a6 100644 --- a/tests/rustdoc-ui/invalid_associated_const.rs +++ b/tests/rustdoc-ui/invalid_associated_const.rs @@ -3,6 +3,7 @@ trait T { type A: S<C<X = 0i32> = 34>; //~^ ERROR associated type bindings are not allowed here + //~| ERROR associated type bindings are not allowed here } trait S { diff --git a/tests/rustdoc-ui/invalid_associated_const.stderr b/tests/rustdoc-ui/invalid_associated_const.stderr index 9c6ae0f76c6..1eb6d2714e3 100644 --- a/tests/rustdoc-ui/invalid_associated_const.stderr +++ b/tests/rustdoc-ui/invalid_associated_const.stderr @@ -4,6 +4,14 @@ error[E0229]: associated type bindings are not allowed here LL | type A: S<C<X = 0i32> = 34>; | ^^^^^^^^ associated type not allowed here -error: aborting due to 1 previous error +error[E0229]: associated type bindings are not allowed here + --> $DIR/invalid_associated_const.rs:4:17 + | +LL | type A: S<C<X = 0i32> = 34>; + | ^^^^^^^^ associated type not allowed here + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0229`. diff --git a/tests/rustdoc-ui/issue-102467.rs b/tests/rustdoc-ui/issue-102467.rs index bff876e41d6..a27e6156979 100644 --- a/tests/rustdoc-ui/issue-102467.rs +++ b/tests/rustdoc-ui/issue-102467.rs @@ -6,6 +6,7 @@ trait T { type A: S<C<X = 0i32> = 34>; //~^ ERROR associated type bindings are not allowed here + //~| ERROR associated type bindings are not allowed here } trait S { diff --git a/tests/rustdoc-ui/issue-102467.stderr b/tests/rustdoc-ui/issue-102467.stderr index 4a769f94cf2..f54a50a4e19 100644 --- a/tests/rustdoc-ui/issue-102467.stderr +++ b/tests/rustdoc-ui/issue-102467.stderr @@ -4,6 +4,14 @@ error[E0229]: associated type bindings are not allowed here LL | type A: S<C<X = 0i32> = 34>; | ^^^^^^^^ associated type not allowed here -error: aborting due to 1 previous error +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-102467.rs:7:17 + | +LL | type A: S<C<X = 0i32> = 34>; + | ^^^^^^^^ associated type not allowed here + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0229`. diff --git a/tests/rustdoc-ui/issues/issue-110900.rs b/tests/rustdoc-ui/issues/issue-110900.rs index 5f90444dfd3..5a896167083 100644 --- a/tests/rustdoc-ui/issues/issue-110900.rs +++ b/tests/rustdoc-ui/issues/issue-110900.rs @@ -1,7 +1,6 @@ //@ check-pass #![crate_type="lib"] -#![feature(associated_type_bounds)] trait A<'a> {} trait B<'b> {} diff --git a/tests/rustdoc-ui/issues/issue-96287.rs b/tests/rustdoc-ui/issues/issue-96287.rs index 08cc7ef4c90..b490c2fc03f 100644 --- a/tests/rustdoc-ui/issues/issue-96287.rs +++ b/tests/rustdoc-ui/issues/issue-96287.rs @@ -6,6 +6,7 @@ pub trait TraitWithAssoc { pub type Foo<V> = impl Trait<V::Assoc>; //~^ ERROR +//~| ERROR pub trait Trait<U> {} diff --git a/tests/rustdoc-ui/issues/issue-96287.stderr b/tests/rustdoc-ui/issues/issue-96287.stderr index 62d81534a98..9aba0332164 100644 --- a/tests/rustdoc-ui/issues/issue-96287.stderr +++ b/tests/rustdoc-ui/issues/issue-96287.stderr @@ -9,6 +9,18 @@ help: consider restricting type parameter `V` LL | pub type Foo<V: TraitWithAssoc> = impl Trait<V::Assoc>; | ++++++++++++++++ -error: aborting due to 1 previous error +error[E0220]: associated type `Assoc` not found for `V` + --> $DIR/issue-96287.rs:7:33 + | +LL | pub type Foo<V> = impl Trait<V::Assoc>; + | ^^^^^ there is an associated type `Assoc` in the trait `TraitWithAssoc` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: consider restricting type parameter `V` + | +LL | pub type Foo<V: TraitWithAssoc> = impl Trait<V::Assoc>; + | ++++++++++++++++ + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0220`. diff --git a/tests/rustdoc-ui/lints/check.stderr b/tests/rustdoc-ui/lints/check.stderr index c5ed5d0c3ef..acdb8128443 100644 --- a/tests/rustdoc-ui/lints/check.stderr +++ b/tests/rustdoc-ui/lints/check.stderr @@ -4,7 +4,6 @@ warning: missing documentation for the crate LL | / #![feature(rustdoc_missing_doc_code_examples)] LL | | LL | | -LL | | ... | LL | | LL | | pub fn foo() {} @@ -39,7 +38,6 @@ warning: missing code example in this documentation LL | / #![feature(rustdoc_missing_doc_code_examples)] LL | | LL | | -LL | | ... | LL | | LL | | pub fn foo() {} diff --git a/tests/rustdoc/display-hidden-items.rs b/tests/rustdoc/display-hidden-items.rs index 76124554767..901ca17d4d2 100644 --- a/tests/rustdoc/display-hidden-items.rs +++ b/tests/rustdoc/display-hidden-items.rs @@ -5,19 +5,22 @@ #![crate_name = "foo"] // @has 'foo/index.html' -// @has - '//*[@id="reexport.hidden_reexport"]/code' 'pub use hidden::inside_hidden as hidden_reexport;' +// @has - '//*[@class="item-name"]/span[@title="Hidden item"]' '👻' + +// @has - '//*[@id="reexport.hidden_reexport"]/code' '#[doc(hidden)] pub use hidden::inside_hidden as hidden_reexport;' #[doc(hidden)] pub use hidden::inside_hidden as hidden_reexport; // @has - '//*[@class="item-name"]/a[@class="trait"]' 'TraitHidden' // @has 'foo/trait.TraitHidden.html' +// @has - '//code' '#[doc(hidden)] pub trait TraitHidden' #[doc(hidden)] pub trait TraitHidden {} // @has 'foo/index.html' '//*[@class="item-name"]/a[@class="trait"]' 'Trait' pub trait Trait { // @has 'foo/trait.Trait.html' - // @has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' 'const BAR: u32 = 0u32' + // @has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' '#[doc(hidden)] const BAR: u32 = 0u32' #[doc(hidden)] const BAR: u32 = 0; @@ -41,14 +44,15 @@ impl Struct { } impl Trait for Struct { - // @has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' 'const BAR: u32 = 0u32' - // @has - '//*[@id="method.foo"]/*[@class="code-header"]' 'fn foo()' + // @has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' '#[doc(hidden)] const BAR: u32 = 0u32' + // @has - '//*[@id="method.foo"]/*[@class="code-header"]' '#[doc(hidden)] fn foo()' } // @has - '//*[@id="impl-TraitHidden-for-Struct"]/*[@class="code-header"]' 'impl TraitHidden for Struct' impl TraitHidden for Struct {} // @has 'foo/index.html' '//*[@class="item-name"]/a[@class="enum"]' 'HiddenEnum' // @has 'foo/enum.HiddenEnum.html' +// @has - '//code' '#[doc(hidden)] pub enum HiddenEnum' #[doc(hidden)] pub enum HiddenEnum { A, diff --git a/tests/ui/asm/fail-const-eval-issue-121099.rs b/tests/ui/asm/fail-const-eval-issue-121099.rs new file mode 100644 index 00000000000..bed6fc9b39f --- /dev/null +++ b/tests/ui/asm/fail-const-eval-issue-121099.rs @@ -0,0 +1,11 @@ +//@ build-fail +//@ needs-asm-support +#![feature(asm_const)] + +use std::arch::global_asm; + +fn main() {} + +global_asm!("/* {} */", const 1 << 500); //~ ERROR evaluation of constant value failed [E0080] + +global_asm!("/* {} */", const 1 / 0); //~ ERROR evaluation of constant value failed [E0080] diff --git a/tests/ui/asm/fail-const-eval-issue-121099.stderr b/tests/ui/asm/fail-const-eval-issue-121099.stderr new file mode 100644 index 00000000000..51d283218d2 --- /dev/null +++ b/tests/ui/asm/fail-const-eval-issue-121099.stderr @@ -0,0 +1,15 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/fail-const-eval-issue-121099.rs:9:31 + | +LL | global_asm!("/* {} */", const 1 << 500); + | ^^^^^^^^ attempt to shift left by `500_i32`, which would overflow + +error[E0080]: evaluation of constant value failed + --> $DIR/fail-const-eval-issue-121099.rs:11:31 + | +LL | global_asm!("/* {} */", const 1 / 0); + | ^^^^^ attempt to divide `1_i32` by zero + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs b/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs new file mode 100644 index 00000000000..a718eb23bed --- /dev/null +++ b/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs @@ -0,0 +1,25 @@ +// Check that we eventually catch types of assoc const bounds +// (containing late-bound vars) that are ill-formed. +#![feature(associated_const_equality)] + +trait Trait<T> { + const K: T; +} + +fn take( + _: impl Trait< + <<for<'a> fn(&'a str) -> &'a str as Project>::Out as Discard>::Out, + K = { () } + >, +) {} +//~^^^^^^ ERROR implementation of `Project` is not general enough +//~^^^^ ERROR higher-ranked subtype error +//~| ERROR higher-ranked subtype error + +trait Project { type Out; } +impl<T> Project for fn(T) -> T { type Out = T; } + +trait Discard { type Out; } +impl<T: ?Sized> Discard for T { type Out = (); } + +fn main() {} diff --git a/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr b/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr new file mode 100644 index 00000000000..967814c9c3d --- /dev/null +++ b/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr @@ -0,0 +1,25 @@ +error: higher-ranked subtype error + --> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:12:13 + | +LL | K = { () } + | ^^^^^^ + +error: higher-ranked subtype error + --> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:12:13 + | +LL | K = { () } + | ^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: implementation of `Project` is not general enough + --> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:9:4 + | +LL | fn take( + | ^^^^ implementation of `Project` is not general enough + | + = note: `Project` would have to be implemented for the type `for<'a> fn(&'a str) -> &'a str` + = note: ...but `Project` is actually implemented for the type `fn(&'0 str) -> &'0 str`, for some specific lifetime `'0` + +error: aborting due to 3 previous errors + diff --git a/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs b/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs new file mode 100644 index 00000000000..7fc6d564ca4 --- /dev/null +++ b/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs @@ -0,0 +1,22 @@ +// Check that we don't reject non-escaping late-bound vars in the type of assoc const bindings. +// There's no reason why we should disallow them. +// +//@ check-pass + +#![feature(associated_const_equality)] + +trait Trait<T> { + const K: T; +} + +fn take( + _: impl Trait< + <for<'a> fn(&'a str) -> &'a str as Discard>::Out, + K = { () } + >, +) {} + +trait Discard { type Out; } +impl<T: ?Sized> Discard for T { type Out = (); } + +fn main() {} diff --git a/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs b/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs new file mode 100644 index 00000000000..6db1e85ccfa --- /dev/null +++ b/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs @@ -0,0 +1,15 @@ +// Detect and reject escaping late-bound generic params in +// the type of assoc consts used in an equality bound. +#![feature(associated_const_equality)] + +trait Trait<'a> { + const K: &'a (); +} + +fn take(_: impl for<'r> Trait<'r, K = { &() }>) {} +//~^ ERROR the type of the associated constant `K` cannot capture late-bound generic parameters +//~| NOTE its type cannot capture the late-bound lifetime parameter `'r` +//~| NOTE the late-bound lifetime parameter `'r` is defined here +//~| NOTE `K` has type `&'r ()` + +fn main() {} diff --git a/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr b/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr new file mode 100644 index 00000000000..349fddcafe8 --- /dev/null +++ b/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr @@ -0,0 +1,12 @@ +error: the type of the associated constant `K` cannot capture late-bound generic parameters + --> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:9:35 + | +LL | fn take(_: impl for<'r> Trait<'r, K = { &() }>) {} + | -- ^ its type cannot capture the late-bound lifetime parameter `'r` + | | + | the late-bound lifetime parameter `'r` is defined here + | + = note: `K` has type `&'r ()` + +error: aborting due to 1 previous error + diff --git a/tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs b/tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs new file mode 100644 index 00000000000..06fd0a024f0 --- /dev/null +++ b/tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs @@ -0,0 +1,69 @@ +// Regression test for issue #108271. +// Detect and reject generic params in the type of assoc consts used in an equality bound. +#![feature(associated_const_equality)] + +trait Trait<'a, T: 'a, const N: usize> { + const K: &'a [T; N]; +} + +fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} +//~^ ERROR the type of the associated constant `K` must not depend on generic parameters +//~| NOTE its type must not depend on the lifetime parameter `'r` +//~| NOTE the lifetime parameter `'r` is defined here +//~| NOTE `K` has type `&'r [A; Q]` +//~| ERROR the type of the associated constant `K` must not depend on generic parameters +//~| NOTE its type must not depend on the type parameter `A` +//~| NOTE the type parameter `A` is defined here +//~| NOTE `K` has type `&'r [A; Q]` +//~| ERROR the type of the associated constant `K` must not depend on generic parameters +//~| NOTE its type must not depend on the const parameter `Q` +//~| NOTE the const parameter `Q` is defined here +//~| NOTE `K` has type `&'r [A; Q]` + +trait Project { + const SELF: Self; +} + +fn take1(_: impl Project<SELF = {}>) {} +//~^ ERROR the type of the associated constant `SELF` must not depend on `impl Trait` +//~| NOTE its type must not depend on `impl Trait` +//~| NOTE the `impl Trait` is specified here + +fn take2<P: Project<SELF = {}>>(_: P) {} +//~^ ERROR the type of the associated constant `SELF` must not depend on generic parameters +//~| NOTE its type must not depend on the type parameter `P` +//~| NOTE the type parameter `P` is defined here +//~| NOTE `SELF` has type `P` + +trait Iface<'r> { + //~^ NOTE the lifetime parameter `'r` is defined here + //~| NOTE the lifetime parameter `'r` is defined here + type Assoc<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }> + //~^ ERROR the type of the associated constant `K` must not depend on generic parameters + //~| ERROR the type of the associated constant `K` must not depend on generic parameters + //~| NOTE its type must not depend on the lifetime parameter `'r` + //~| NOTE `K` has type `&'r [Self; Q]` + //~| ERROR the type of the associated constant `K` must not depend on `Self` + //~| NOTE its type must not depend on `Self` + //~| NOTE `K` has type `&'r [Self; Q]` + //~| ERROR the type of the associated constant `K` must not depend on generic parameters + //~| NOTE its type must not depend on the const parameter `Q` + //~| NOTE the const parameter `Q` is defined here + //~| NOTE `K` has type `&'r [Self; Q]` + //~| NOTE its type must not depend on the lifetime parameter `'r` + //~| NOTE `K` has type `&'r [Self; Q]` + //~| ERROR the type of the associated constant `K` must not depend on `Self` + //~| NOTE its type must not depend on `Self` + //~| NOTE `K` has type `&'r [Self; Q]` + //~| ERROR the type of the associated constant `K` must not depend on generic parameters + //~| NOTE its type must not depend on the const parameter `Q` + //~| NOTE the const parameter `Q` is defined here + //~| NOTE `K` has type `&'r [Self; Q]` + //~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + //~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + //~| NOTE duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + where + Self: Sized + 'r; +} + +fn main() {} diff --git a/tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr b/tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr new file mode 100644 index 00000000000..6b7b714fff1 --- /dev/null +++ b/tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr @@ -0,0 +1,108 @@ +error: the type of the associated constant `K` must not depend on generic parameters + --> $DIR/assoc-const-eq-param-in-ty.rs:9:61 + | +LL | fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} + | -- the lifetime parameter `'r` is defined here ^ its type must not depend on the lifetime parameter `'r` + | + = note: `K` has type `&'r [A; Q]` + +error: the type of the associated constant `K` must not depend on generic parameters + --> $DIR/assoc-const-eq-param-in-ty.rs:9:61 + | +LL | fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} + | - the type parameter `A` is defined here ^ its type must not depend on the type parameter `A` + | + = note: `K` has type `&'r [A; Q]` + +error: the type of the associated constant `K` must not depend on generic parameters + --> $DIR/assoc-const-eq-param-in-ty.rs:9:61 + | +LL | fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} + | - ^ its type must not depend on the const parameter `Q` + | | + | the const parameter `Q` is defined here + | + = note: `K` has type `&'r [A; Q]` + +error: the type of the associated constant `SELF` must not depend on `impl Trait` + --> $DIR/assoc-const-eq-param-in-ty.rs:27:26 + | +LL | fn take1(_: impl Project<SELF = {}>) {} + | -------------^^^^------ + | | | + | | its type must not depend on `impl Trait` + | the `impl Trait` is specified here + +error: the type of the associated constant `SELF` must not depend on generic parameters + --> $DIR/assoc-const-eq-param-in-ty.rs:32:21 + | +LL | fn take2<P: Project<SELF = {}>>(_: P) {} + | - ^^^^ its type must not depend on the type parameter `P` + | | + | the type parameter `P` is defined here + | + = note: `SELF` has type `P` + +error: the type of the associated constant `K` must not depend on generic parameters + --> $DIR/assoc-const-eq-param-in-ty.rs:41:52 + | +LL | trait Iface<'r> { + | -- the lifetime parameter `'r` is defined here +... +LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }> + | ^ its type must not depend on the lifetime parameter `'r` + | + = note: `K` has type `&'r [Self; Q]` + +error: the type of the associated constant `K` must not depend on `Self` + --> $DIR/assoc-const-eq-param-in-ty.rs:41:52 + | +LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }> + | ^ its type must not depend on `Self` + | + = note: `K` has type `&'r [Self; Q]` + +error: the type of the associated constant `K` must not depend on generic parameters + --> $DIR/assoc-const-eq-param-in-ty.rs:41:52 + | +LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }> + | - ^ its type must not depend on the const parameter `Q` + | | + | the const parameter `Q` is defined here + | + = note: `K` has type `&'r [Self; Q]` + +error: the type of the associated constant `K` must not depend on generic parameters + --> $DIR/assoc-const-eq-param-in-ty.rs:41:52 + | +LL | trait Iface<'r> { + | -- the lifetime parameter `'r` is defined here +... +LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }> + | ^ its type must not depend on the lifetime parameter `'r` + | + = note: `K` has type `&'r [Self; Q]` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: the type of the associated constant `K` must not depend on `Self` + --> $DIR/assoc-const-eq-param-in-ty.rs:41:52 + | +LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }> + | ^ its type must not depend on `Self` + | + = note: `K` has type `&'r [Self; Q]` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: the type of the associated constant `K` must not depend on generic parameters + --> $DIR/assoc-const-eq-param-in-ty.rs:41:52 + | +LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }> + | - ^ its type must not depend on the const parameter `Q` + | | + | the const parameter `Q` is defined here + | + = note: `K` has type `&'r [Self; Q]` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 11 previous errors + diff --git a/tests/ui/associated-consts/issue-102335-const.rs b/tests/ui/associated-consts/issue-102335-const.rs index f60cb92da7f..969c2c43b71 100644 --- a/tests/ui/associated-consts/issue-102335-const.rs +++ b/tests/ui/associated-consts/issue-102335-const.rs @@ -3,6 +3,7 @@ trait T { type A: S<C<X = 0i32> = 34>; //~^ ERROR associated type bindings are not allowed here + //~| ERROR associated type bindings are not allowed here } trait S { diff --git a/tests/ui/associated-consts/issue-102335-const.stderr b/tests/ui/associated-consts/issue-102335-const.stderr index b69dfd51ea8..2a70425a3cc 100644 --- a/tests/ui/associated-consts/issue-102335-const.stderr +++ b/tests/ui/associated-consts/issue-102335-const.stderr @@ -4,6 +4,14 @@ error[E0229]: associated type bindings are not allowed here LL | type A: S<C<X = 0i32> = 34>; | ^^^^^^^^ associated type not allowed here -error: aborting due to 1 previous error +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-102335-const.rs:4:17 + | +LL | type A: S<C<X = 0i32> = 34>; + | ^^^^^^^^ associated type not allowed here + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0229`. diff --git a/tests/ui/associated-consts/issue-93835.rs b/tests/ui/associated-consts/issue-93835.rs index b2a437fcbfb..9cc33d53f9c 100644 --- a/tests/ui/associated-consts/issue-93835.rs +++ b/tests/ui/associated-consts/issue-93835.rs @@ -6,7 +6,6 @@ fn e() { //~| ERROR cannot find value //~| ERROR associated const equality //~| ERROR cannot find trait `p` in this scope - //~| ERROR associated type bounds } fn main() {} diff --git a/tests/ui/associated-consts/issue-93835.stderr b/tests/ui/associated-consts/issue-93835.stderr index d3ce46f6f03..dfe78b3d1f3 100644 --- a/tests/ui/associated-consts/issue-93835.stderr +++ b/tests/ui/associated-consts/issue-93835.stderr @@ -26,17 +26,7 @@ LL | type_ascribe!(p, a<p:p<e=6>>); = help: add `#![feature(associated_const_equality)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error[E0658]: associated type bounds are unstable - --> $DIR/issue-93835.rs:4:24 - | -LL | type_ascribe!(p, a<p:p<e=6>>); - | ^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0405, E0412, E0425, E0658. For more information about an error, try `rustc --explain E0405`. diff --git a/tests/ui/associated-inherent-types/issue-109299-1.rs b/tests/ui/associated-inherent-types/issue-109299-1.rs index b86e2e31e06..4546785f0b1 100644 --- a/tests/ui/associated-inherent-types/issue-109299-1.rs +++ b/tests/ui/associated-inherent-types/issue-109299-1.rs @@ -7,7 +7,9 @@ impl Lexer<i32> { type Cursor = (); } -type X = impl for<T> Fn() -> Lexer<T>::Cursor; //~ ERROR associated type `Cursor` not found for `Lexer<T>` in the current scope -//~^ ERROR: unconstrained opaque type +type X = impl for<T> Fn() -> Lexer<T>::Cursor; +//~^ ERROR associated type `Cursor` not found for `Lexer<T>` in the current scope +//~| ERROR associated type `Cursor` not found for `Lexer<T>` in the current scope +//~| ERROR: unconstrained opaque type fn main() {} diff --git a/tests/ui/associated-inherent-types/issue-109299-1.stderr b/tests/ui/associated-inherent-types/issue-109299-1.stderr index 5848fa4087d..07a00b6b9a9 100644 --- a/tests/ui/associated-inherent-types/issue-109299-1.stderr +++ b/tests/ui/associated-inherent-types/issue-109299-1.stderr @@ -10,6 +10,19 @@ LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor; = note: the associated type was found for - `Lexer<i32>` +error[E0220]: associated type `Cursor` not found for `Lexer<T>` in the current scope + --> $DIR/issue-109299-1.rs:10:40 + | +LL | struct Lexer<T>(T); + | --------------- associated item `Cursor` not found for this struct +... +LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor; + | ^^^^^^ associated item not found in `Lexer<T>` + | + = note: the associated type was found for + - `Lexer<i32>` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error: unconstrained opaque type --> $DIR/issue-109299-1.rs:10:10 | @@ -18,6 +31,6 @@ LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor; | = note: `X` must be used in combination with a concrete type within the same module -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0220`. diff --git a/tests/ui/associated-type-bounds/ambiguous-associated-type.rs b/tests/ui/associated-type-bounds/ambiguous-associated-type.rs index 4e6d8b9dd0a..ff3c6f2a95d 100644 --- a/tests/ui/associated-type-bounds/ambiguous-associated-type.rs +++ b/tests/ui/associated-type-bounds/ambiguous-associated-type.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - pub struct Flatten<I> where I: Iterator<Item: IntoIterator>, diff --git a/tests/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.rs b/tests/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.rs index 8a580e19186..ca4d1f6d920 100644 --- a/tests/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.rs +++ b/tests/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.rs @@ -8,8 +8,6 @@ // Additionally, as reported in https://github.com/rust-lang/rust/issues/63594, // we check that the spans for the error message are sane here. -#![feature(associated_type_bounds)] - fn main() {} trait Bar { diff --git a/tests/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr b/tests/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr index ad540909411..b1575abe571 100644 --- a/tests/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr +++ b/tests/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr @@ -1,5 +1,5 @@ error: associated type bounds are not allowed in `dyn` types - --> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:30:28 + --> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:28:28 | LL | type Out = Box<dyn Bar<Assoc: Copy>>; | ^^^^^^^^^^^ diff --git a/tests/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.rs b/tests/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.rs index edde549bb4b..30fa51bb175 100644 --- a/tests/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.rs +++ b/tests/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - use std::fmt::Debug; use std::iter::Once; diff --git a/tests/ui/associated-type-bounds/bad-universal-in-dyn-in-where-clause.rs b/tests/ui/associated-type-bounds/bad-universal-in-dyn-in-where-clause.rs index 81c8fe829f9..4689888719f 100644 --- a/tests/ui/associated-type-bounds/bad-universal-in-dyn-in-where-clause.rs +++ b/tests/ui/associated-type-bounds/bad-universal-in-dyn-in-where-clause.rs @@ -1,5 +1,3 @@ -#![feature(associated_type_bounds)] - trait B { type AssocType; } diff --git a/tests/ui/associated-type-bounds/bad-universal-in-dyn-in-where-clause.stderr b/tests/ui/associated-type-bounds/bad-universal-in-dyn-in-where-clause.stderr index 7d9870c72d4..5d8108f28a0 100644 --- a/tests/ui/associated-type-bounds/bad-universal-in-dyn-in-where-clause.stderr +++ b/tests/ui/associated-type-bounds/bad-universal-in-dyn-in-where-clause.stderr @@ -1,5 +1,5 @@ error: associated type bounds are not allowed in `dyn` types - --> $DIR/bad-universal-in-dyn-in-where-clause.rs:9:19 + --> $DIR/bad-universal-in-dyn-in-where-clause.rs:7:19 | LL | dyn for<'j> B<AssocType: 'j>:, | ^^^^^^^^^^^^^ diff --git a/tests/ui/associated-type-bounds/bad-universal-in-impl-sig.rs b/tests/ui/associated-type-bounds/bad-universal-in-impl-sig.rs index f465123f34c..014550823bd 100644 --- a/tests/ui/associated-type-bounds/bad-universal-in-impl-sig.rs +++ b/tests/ui/associated-type-bounds/bad-universal-in-impl-sig.rs @@ -1,5 +1,3 @@ -#![feature(associated_type_bounds)] - trait Trait { type Item; } diff --git a/tests/ui/associated-type-bounds/bad-universal-in-impl-sig.stderr b/tests/ui/associated-type-bounds/bad-universal-in-impl-sig.stderr index 8855bd9c312..a017a601a17 100644 --- a/tests/ui/associated-type-bounds/bad-universal-in-impl-sig.stderr +++ b/tests/ui/associated-type-bounds/bad-universal-in-impl-sig.stderr @@ -1,5 +1,5 @@ error: associated type bounds are not allowed in `dyn` types - --> $DIR/bad-universal-in-impl-sig.rs:10:16 + --> $DIR/bad-universal-in-impl-sig.rs:8:16 | LL | impl dyn Trait<Item: Trait2> {} | ^^^^^^^^^^^^ diff --git a/tests/ui/associated-type-bounds/bounds-on-assoc-in-trait.rs b/tests/ui/associated-type-bounds/bounds-on-assoc-in-trait.rs index dad1f644284..f69c392a8c3 100644 --- a/tests/ui/associated-type-bounds/bounds-on-assoc-in-trait.rs +++ b/tests/ui/associated-type-bounds/bounds-on-assoc-in-trait.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - use std::fmt::Debug; use std::iter::Empty; use std::ops::Range; diff --git a/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.rs b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.rs new file mode 100644 index 00000000000..1768b006622 --- /dev/null +++ b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.rs @@ -0,0 +1,18 @@ +trait Id { + type This: ?Sized; +} +impl<T: ?Sized> Id for T { + type This = T; +} + +trait Trait { + type Assoc: Id<This: Copy>; +} + +// We can't see use the `T::Assoc::This: Copy` bound to prove `T::Assoc: Copy` +fn foo<T: Trait>(x: T::Assoc) -> (T::Assoc, T::Assoc) { + (x, x) + //~^ ERROR use of moved value +} + +fn main() {} diff --git a/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.stderr b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.stderr new file mode 100644 index 00000000000..cd0e026905c --- /dev/null +++ b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid-2.stderr @@ -0,0 +1,13 @@ +error[E0382]: use of moved value: `x` + --> $DIR/cant-see-copy-bound-from-child-rigid-2.rs:14:9 + | +LL | fn foo<T: Trait>(x: T::Assoc) -> (T::Assoc, T::Assoc) { + | - move occurs because `x` has type `<T as Trait>::Assoc`, which does not implement the `Copy` trait +LL | (x, x) + | - ^ value used here after move + | | + | value moved here + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.rs b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.rs new file mode 100644 index 00000000000..6b3fd7e898d --- /dev/null +++ b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.rs @@ -0,0 +1,18 @@ +trait Id { + type This: ?Sized; +} + +trait Trait { + type Assoc: Id<This: Copy>; +} + +// We can't see use the `T::Assoc::This: Copy` bound to prove `T::Assoc: Copy` +fn foo<T: Trait>(x: T::Assoc) -> (T::Assoc, T::Assoc) +where + T::Assoc: Id<This = T::Assoc>, +{ + (x, x) + //~^ ERROR use of moved value +} + +fn main() {} diff --git a/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.stderr b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.stderr new file mode 100644 index 00000000000..3ed73918de3 --- /dev/null +++ b/tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.stderr @@ -0,0 +1,14 @@ +error[E0382]: use of moved value: `x` + --> $DIR/cant-see-copy-bound-from-child-rigid.rs:14:9 + | +LL | fn foo<T: Trait>(x: T::Assoc) -> (T::Assoc, T::Assoc) + | - move occurs because `x` has type `<T as Trait>::Assoc`, which does not implement the `Copy` trait +... +LL | (x, x) + | - ^ value used here after move + | | + | value moved here + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/associated-type-bounds/consts.rs b/tests/ui/associated-type-bounds/consts.rs index 8f90c36ed45..17de1ff5682 100644 --- a/tests/ui/associated-type-bounds/consts.rs +++ b/tests/ui/associated-type-bounds/consts.rs @@ -1,5 +1,3 @@ -#![feature(associated_type_bounds)] - pub fn accept(_: impl Trait<K: Copy>) {} //~^ ERROR expected type, found constant diff --git a/tests/ui/associated-type-bounds/consts.stderr b/tests/ui/associated-type-bounds/consts.stderr index 7f9fe5e500a..ddb677ec74d 100644 --- a/tests/ui/associated-type-bounds/consts.stderr +++ b/tests/ui/associated-type-bounds/consts.stderr @@ -1,5 +1,5 @@ error: expected type, found constant - --> $DIR/consts.rs:3:29 + --> $DIR/consts.rs:1:29 | LL | pub fn accept(_: impl Trait<K: Copy>) {} | ^------ bounds are not allowed on associated constants @@ -7,7 +7,7 @@ LL | pub fn accept(_: impl Trait<K: Copy>) {} | unexpected constant | note: the associated constant is defined here - --> $DIR/consts.rs:7:5 + --> $DIR/consts.rs:5:5 | LL | const K: i32; | ^^^^^^^^^^^^ diff --git a/tests/ui/associated-type-bounds/dont-imply-atb-in-closure-inference.rs b/tests/ui/associated-type-bounds/dont-imply-atb-in-closure-inference.rs new file mode 100644 index 00000000000..fecb3b15338 --- /dev/null +++ b/tests/ui/associated-type-bounds/dont-imply-atb-in-closure-inference.rs @@ -0,0 +1,21 @@ +//@ check-pass + +#![feature(type_alias_impl_trait)] + +trait IsPtr { + type Assoc; +} +impl<T> IsPtr for T { + type Assoc = fn(i32); +} + +type Tait = impl IsPtr<Assoc: Fn(i32)> + Fn(u32); + +fn hello() +where + Tait:, +{ + let _: Tait = |x| {}; +} + +fn main() {} diff --git a/tests/ui/associated-type-bounds/duplicate.rs b/tests/ui/associated-type-bounds/duplicate.rs index 54c8cd3fde0..2b4a01376d7 100644 --- a/tests/ui/associated-type-bounds/duplicate.rs +++ b/tests/ui/associated-type-bounds/duplicate.rs @@ -1,4 +1,3 @@ -#![feature(associated_type_bounds)] #![feature(type_alias_impl_trait)] use std::iter; @@ -133,16 +132,19 @@ where fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> { //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] + //~| ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] iter::empty() //~^ ERROR type annotations needed } fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> { //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] + //~| ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] iter::empty() //~^ ERROR type annotations needed } fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> { //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] + //~| ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] iter::empty() //~^ ERROR type annotations needed } @@ -183,10 +185,13 @@ type ETAI3<T: Iterator<Item: 'static, Item: 'static>> = impl Copy; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] type ETAI4 = impl Iterator<Item: Copy, Item: Send>; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] +//~| ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] type ETAI5 = impl Iterator<Item: Copy, Item: Copy>; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] +//~| ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] type ETAI6 = impl Iterator<Item: 'static, Item: 'static>; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] +//~| ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] trait TRI1<T: Iterator<Item: Copy, Item: Send>> {} //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] @@ -251,14 +256,17 @@ where trait TRA1 { type A: Iterator<Item: Copy, Item: Send>; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] + //~| ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] } trait TRA2 { type A: Iterator<Item: Copy, Item: Copy>; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] + //~| ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] } trait TRA3 { type A: Iterator<Item: 'static, Item: 'static>; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] + //~| ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] } fn main() {} diff --git a/tests/ui/associated-type-bounds/duplicate.stderr b/tests/ui/associated-type-bounds/duplicate.stderr index 6345ef4b798..cf4809991c3 100644 --- a/tests/ui/associated-type-bounds/duplicate.stderr +++ b/tests/ui/associated-type-bounds/duplicate.stderr @@ -1,5 +1,5 @@ error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:7:36 + --> $DIR/duplicate.rs:6:36 | LL | struct SI1<T: Iterator<Item: Copy, Item: Send>> { | ---------- ^^^^^^^^^^ re-bound here @@ -7,7 +7,7 @@ LL | struct SI1<T: Iterator<Item: Copy, Item: Send>> { | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:11:36 + --> $DIR/duplicate.rs:10:36 | LL | struct SI2<T: Iterator<Item: Copy, Item: Copy>> { | ---------- ^^^^^^^^^^ re-bound here @@ -15,7 +15,7 @@ LL | struct SI2<T: Iterator<Item: Copy, Item: Copy>> { | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:15:39 + --> $DIR/duplicate.rs:14:39 | LL | struct SI3<T: Iterator<Item: 'static, Item: 'static>> { | ------------- ^^^^^^^^^^^^^ re-bound here @@ -23,7 +23,7 @@ LL | struct SI3<T: Iterator<Item: 'static, Item: 'static>> { | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:21:29 + --> $DIR/duplicate.rs:20:29 | LL | T: Iterator<Item: Copy, Item: Send>, | ---------- ^^^^^^^^^^ re-bound here @@ -31,7 +31,7 @@ LL | T: Iterator<Item: Copy, Item: Send>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:28:29 + --> $DIR/duplicate.rs:27:29 | LL | T: Iterator<Item: Copy, Item: Copy>, | ---------- ^^^^^^^^^^ re-bound here @@ -39,7 +39,7 @@ LL | T: Iterator<Item: Copy, Item: Copy>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:35:32 + --> $DIR/duplicate.rs:34:32 | LL | T: Iterator<Item: 'static, Item: 'static>, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -47,7 +47,7 @@ LL | T: Iterator<Item: 'static, Item: 'static>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:41:34 + --> $DIR/duplicate.rs:40:34 | LL | enum EI1<T: Iterator<Item: Copy, Item: Send>> { | ---------- ^^^^^^^^^^ re-bound here @@ -55,7 +55,7 @@ LL | enum EI1<T: Iterator<Item: Copy, Item: Send>> { | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:45:34 + --> $DIR/duplicate.rs:44:34 | LL | enum EI2<T: Iterator<Item: Copy, Item: Copy>> { | ---------- ^^^^^^^^^^ re-bound here @@ -63,7 +63,7 @@ LL | enum EI2<T: Iterator<Item: Copy, Item: Copy>> { | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:49:37 + --> $DIR/duplicate.rs:48:37 | LL | enum EI3<T: Iterator<Item: 'static, Item: 'static>> { | ------------- ^^^^^^^^^^^^^ re-bound here @@ -71,7 +71,7 @@ LL | enum EI3<T: Iterator<Item: 'static, Item: 'static>> { | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:55:29 + --> $DIR/duplicate.rs:54:29 | LL | T: Iterator<Item: Copy, Item: Send>, | ---------- ^^^^^^^^^^ re-bound here @@ -79,7 +79,7 @@ LL | T: Iterator<Item: Copy, Item: Send>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:62:29 + --> $DIR/duplicate.rs:61:29 | LL | T: Iterator<Item: Copy, Item: Copy>, | ---------- ^^^^^^^^^^ re-bound here @@ -87,7 +87,7 @@ LL | T: Iterator<Item: Copy, Item: Copy>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:69:32 + --> $DIR/duplicate.rs:68:32 | LL | T: Iterator<Item: 'static, Item: 'static>, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -95,7 +95,7 @@ LL | T: Iterator<Item: 'static, Item: 'static>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:75:35 + --> $DIR/duplicate.rs:74:35 | LL | union UI1<T: Iterator<Item: Copy, Item: Send>> { | ---------- ^^^^^^^^^^ re-bound here @@ -103,7 +103,7 @@ LL | union UI1<T: Iterator<Item: Copy, Item: Send>> { | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:79:35 + --> $DIR/duplicate.rs:78:35 | LL | union UI2<T: Iterator<Item: Copy, Item: Copy>> { | ---------- ^^^^^^^^^^ re-bound here @@ -111,7 +111,7 @@ LL | union UI2<T: Iterator<Item: Copy, Item: Copy>> { | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:83:38 + --> $DIR/duplicate.rs:82:38 | LL | union UI3<T: Iterator<Item: 'static, Item: 'static>> { | ------------- ^^^^^^^^^^^^^ re-bound here @@ -119,7 +119,7 @@ LL | union UI3<T: Iterator<Item: 'static, Item: 'static>> { | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:89:29 + --> $DIR/duplicate.rs:88:29 | LL | T: Iterator<Item: Copy, Item: Send>, | ---------- ^^^^^^^^^^ re-bound here @@ -127,7 +127,7 @@ LL | T: Iterator<Item: Copy, Item: Send>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:96:29 + --> $DIR/duplicate.rs:95:29 | LL | T: Iterator<Item: Copy, Item: Copy>, | ---------- ^^^^^^^^^^ re-bound here @@ -135,7 +135,7 @@ LL | T: Iterator<Item: Copy, Item: Copy>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:103:32 + --> $DIR/duplicate.rs:102:32 | LL | T: Iterator<Item: 'static, Item: 'static>, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -143,7 +143,7 @@ LL | T: Iterator<Item: 'static, Item: 'static>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:109:32 + --> $DIR/duplicate.rs:108:32 | LL | fn FI1<T: Iterator<Item: Copy, Item: Send>>() {} | ---------- ^^^^^^^^^^ re-bound here @@ -151,7 +151,7 @@ LL | fn FI1<T: Iterator<Item: Copy, Item: Send>>() {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:111:32 + --> $DIR/duplicate.rs:110:32 | LL | fn FI2<T: Iterator<Item: Copy, Item: Copy>>() {} | ---------- ^^^^^^^^^^ re-bound here @@ -159,7 +159,7 @@ LL | fn FI2<T: Iterator<Item: Copy, Item: Copy>>() {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:113:35 + --> $DIR/duplicate.rs:112:35 | LL | fn FI3<T: Iterator<Item: 'static, Item: 'static>>() {} | ------------- ^^^^^^^^^^^^^ re-bound here @@ -167,7 +167,7 @@ LL | fn FI3<T: Iterator<Item: 'static, Item: 'static>>() {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:117:29 + --> $DIR/duplicate.rs:116:29 | LL | T: Iterator<Item: Copy, Item: Send>, | ---------- ^^^^^^^^^^ re-bound here @@ -175,7 +175,7 @@ LL | T: Iterator<Item: Copy, Item: Send>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:123:29 + --> $DIR/duplicate.rs:122:29 | LL | T: Iterator<Item: Copy, Item: Copy>, | ---------- ^^^^^^^^^^ re-bound here @@ -183,7 +183,7 @@ LL | T: Iterator<Item: Copy, Item: Copy>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:129:32 + --> $DIR/duplicate.rs:128:32 | LL | T: Iterator<Item: 'static, Item: 'static>, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -191,13 +191,23 @@ LL | T: Iterator<Item: 'static, Item: 'static>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:134:42 + --> $DIR/duplicate.rs:133:42 | LL | fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> { | ---------- ^^^^^^^^^^ re-bound here | | | `Item` bound here first +error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified + --> $DIR/duplicate.rs:133:42 + | +LL | fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> { + | ---------- ^^^^^^^^^^ re-bound here + | | + | `Item` bound here first + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0282]: type annotations needed --> $DIR/duplicate.rs:136:5 | @@ -217,8 +227,18 @@ LL | fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> { | | | `Item` bound here first +error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified + --> $DIR/duplicate.rs:139:42 + | +LL | fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> { + | ---------- ^^^^^^^^^^ re-bound here + | | + | `Item` bound here first + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0282]: type annotations needed - --> $DIR/duplicate.rs:141:5 + --> $DIR/duplicate.rs:142:5 | LL | iter::empty() | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `empty` @@ -229,15 +249,25 @@ LL | iter::empty::<T>() | +++++ error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:144:45 + --> $DIR/duplicate.rs:145:45 | LL | fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> { | ------------- ^^^^^^^^^^^^^ re-bound here | | | `Item` bound here first +error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified + --> $DIR/duplicate.rs:145:45 + | +LL | fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> { + | ------------- ^^^^^^^^^^^^^ re-bound here + | | + | `Item` bound here first + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0282]: type annotations needed - --> $DIR/duplicate.rs:146:5 + --> $DIR/duplicate.rs:148:5 | LL | iter::empty() | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `empty` @@ -248,7 +278,7 @@ LL | iter::empty::<T>() | +++++ error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:149:40 + --> $DIR/duplicate.rs:151:40 | LL | fn FAPIT1(_: impl Iterator<Item: Copy, Item: Send>) {} | ---------- ^^^^^^^^^^ re-bound here @@ -256,7 +286,7 @@ LL | fn FAPIT1(_: impl Iterator<Item: Copy, Item: Send>) {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:151:40 + --> $DIR/duplicate.rs:153:40 | LL | fn FAPIT2(_: impl Iterator<Item: Copy, Item: Copy>) {} | ---------- ^^^^^^^^^^ re-bound here @@ -264,7 +294,7 @@ LL | fn FAPIT2(_: impl Iterator<Item: Copy, Item: Copy>) {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:153:43 + --> $DIR/duplicate.rs:155:43 | LL | fn FAPIT3(_: impl Iterator<Item: 'static, Item: 'static>) {} | ------------- ^^^^^^^^^^^^^ re-bound here @@ -272,7 +302,7 @@ LL | fn FAPIT3(_: impl Iterator<Item: 'static, Item: 'static>) {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:156:35 + --> $DIR/duplicate.rs:158:35 | LL | type TAI1<T: Iterator<Item: Copy, Item: Send>> = T; | ---------- ^^^^^^^^^^ re-bound here @@ -280,7 +310,7 @@ LL | type TAI1<T: Iterator<Item: Copy, Item: Send>> = T; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:158:35 + --> $DIR/duplicate.rs:160:35 | LL | type TAI2<T: Iterator<Item: Copy, Item: Copy>> = T; | ---------- ^^^^^^^^^^ re-bound here @@ -288,7 +318,7 @@ LL | type TAI2<T: Iterator<Item: Copy, Item: Copy>> = T; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:160:38 + --> $DIR/duplicate.rs:162:38 | LL | type TAI3<T: Iterator<Item: 'static, Item: 'static>> = T; | ------------- ^^^^^^^^^^^^^ re-bound here @@ -296,7 +326,7 @@ LL | type TAI3<T: Iterator<Item: 'static, Item: 'static>> = T; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:164:29 + --> $DIR/duplicate.rs:166:29 | LL | T: Iterator<Item: Copy, Item: Send>, | ---------- ^^^^^^^^^^ re-bound here @@ -304,7 +334,7 @@ LL | T: Iterator<Item: Copy, Item: Send>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:169:29 + --> $DIR/duplicate.rs:171:29 | LL | T: Iterator<Item: Copy, Item: Copy>, | ---------- ^^^^^^^^^^ re-bound here @@ -312,7 +342,7 @@ LL | T: Iterator<Item: Copy, Item: Copy>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:174:32 + --> $DIR/duplicate.rs:176:32 | LL | T: Iterator<Item: 'static, Item: 'static>, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -320,7 +350,7 @@ LL | T: Iterator<Item: 'static, Item: 'static>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:178:36 + --> $DIR/duplicate.rs:180:36 | LL | type ETAI1<T: Iterator<Item: Copy, Item: Send>> = impl Copy; | ---------- ^^^^^^^^^^ re-bound here @@ -328,7 +358,7 @@ LL | type ETAI1<T: Iterator<Item: Copy, Item: Send>> = impl Copy; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:180:36 + --> $DIR/duplicate.rs:182:36 | LL | type ETAI2<T: Iterator<Item: Copy, Item: Copy>> = impl Copy; | ---------- ^^^^^^^^^^ re-bound here @@ -336,7 +366,7 @@ LL | type ETAI2<T: Iterator<Item: Copy, Item: Copy>> = impl Copy; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:182:39 + --> $DIR/duplicate.rs:184:39 | LL | type ETAI3<T: Iterator<Item: 'static, Item: 'static>> = impl Copy; | ------------- ^^^^^^^^^^^^^ re-bound here @@ -344,7 +374,7 @@ LL | type ETAI3<T: Iterator<Item: 'static, Item: 'static>> = impl Copy; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:184:40 + --> $DIR/duplicate.rs:186:40 | LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>; | ---------- ^^^^^^^^^^ re-bound here @@ -354,21 +384,51 @@ LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>; error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified --> $DIR/duplicate.rs:186:40 | +LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>; + | ---------- ^^^^^^^^^^ re-bound here + | | + | `Item` bound here first + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified + --> $DIR/duplicate.rs:189:40 + | LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>; | ---------- ^^^^^^^^^^ re-bound here | | | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:188:43 + --> $DIR/duplicate.rs:189:40 + | +LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>; + | ---------- ^^^^^^^^^^ re-bound here + | | + | `Item` bound here first + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified + --> $DIR/duplicate.rs:192:43 + | +LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>; + | ------------- ^^^^^^^^^^^^^ re-bound here + | | + | `Item` bound here first + +error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified + --> $DIR/duplicate.rs:192:43 | LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>; | ------------- ^^^^^^^^^^^^^ re-bound here | | | `Item` bound here first + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:191:36 + --> $DIR/duplicate.rs:196:36 | LL | trait TRI1<T: Iterator<Item: Copy, Item: Send>> {} | ---------- ^^^^^^^^^^ re-bound here @@ -376,7 +436,7 @@ LL | trait TRI1<T: Iterator<Item: Copy, Item: Send>> {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:193:36 + --> $DIR/duplicate.rs:198:36 | LL | trait TRI2<T: Iterator<Item: Copy, Item: Copy>> {} | ---------- ^^^^^^^^^^ re-bound here @@ -384,7 +444,7 @@ LL | trait TRI2<T: Iterator<Item: Copy, Item: Copy>> {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:195:39 + --> $DIR/duplicate.rs:200:39 | LL | trait TRI3<T: Iterator<Item: 'static, Item: 'static>> {} | ------------- ^^^^^^^^^^^^^ re-bound here @@ -392,7 +452,7 @@ LL | trait TRI3<T: Iterator<Item: 'static, Item: 'static>> {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:197:34 + --> $DIR/duplicate.rs:202:34 | LL | trait TRS1: Iterator<Item: Copy, Item: Send> {} | ---------- ^^^^^^^^^^ re-bound here @@ -400,7 +460,7 @@ LL | trait TRS1: Iterator<Item: Copy, Item: Send> {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:197:34 + --> $DIR/duplicate.rs:202:34 | LL | trait TRS1: Iterator<Item: Copy, Item: Send> {} | ---------- ^^^^^^^^^^ re-bound here @@ -410,7 +470,7 @@ LL | trait TRS1: Iterator<Item: Copy, Item: Send> {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:197:34 + --> $DIR/duplicate.rs:202:34 | LL | trait TRS1: Iterator<Item: Copy, Item: Send> {} | ---------- ^^^^^^^^^^ re-bound here @@ -420,7 +480,7 @@ LL | trait TRS1: Iterator<Item: Copy, Item: Send> {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:201:34 + --> $DIR/duplicate.rs:206:34 | LL | trait TRS2: Iterator<Item: Copy, Item: Copy> {} | ---------- ^^^^^^^^^^ re-bound here @@ -428,7 +488,7 @@ LL | trait TRS2: Iterator<Item: Copy, Item: Copy> {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:201:34 + --> $DIR/duplicate.rs:206:34 | LL | trait TRS2: Iterator<Item: Copy, Item: Copy> {} | ---------- ^^^^^^^^^^ re-bound here @@ -438,7 +498,7 @@ LL | trait TRS2: Iterator<Item: Copy, Item: Copy> {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:201:34 + --> $DIR/duplicate.rs:206:34 | LL | trait TRS2: Iterator<Item: Copy, Item: Copy> {} | ---------- ^^^^^^^^^^ re-bound here @@ -448,7 +508,7 @@ LL | trait TRS2: Iterator<Item: Copy, Item: Copy> {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:205:37 + --> $DIR/duplicate.rs:210:37 | LL | trait TRS3: Iterator<Item: 'static, Item: 'static> {} | ------------- ^^^^^^^^^^^^^ re-bound here @@ -456,7 +516,7 @@ LL | trait TRS3: Iterator<Item: 'static, Item: 'static> {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:205:37 + --> $DIR/duplicate.rs:210:37 | LL | trait TRS3: Iterator<Item: 'static, Item: 'static> {} | ------------- ^^^^^^^^^^^^^ re-bound here @@ -466,7 +526,7 @@ LL | trait TRS3: Iterator<Item: 'static, Item: 'static> {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:205:37 + --> $DIR/duplicate.rs:210:37 | LL | trait TRS3: Iterator<Item: 'static, Item: 'static> {} | ------------- ^^^^^^^^^^^^^ re-bound here @@ -476,7 +536,7 @@ LL | trait TRS3: Iterator<Item: 'static, Item: 'static> {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:211:29 + --> $DIR/duplicate.rs:216:29 | LL | T: Iterator<Item: Copy, Item: Send>, | ---------- ^^^^^^^^^^ re-bound here @@ -484,7 +544,7 @@ LL | T: Iterator<Item: Copy, Item: Send>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:217:29 + --> $DIR/duplicate.rs:222:29 | LL | T: Iterator<Item: Copy, Item: Copy>, | ---------- ^^^^^^^^^^ re-bound here @@ -492,7 +552,7 @@ LL | T: Iterator<Item: Copy, Item: Copy>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:223:32 + --> $DIR/duplicate.rs:228:32 | LL | T: Iterator<Item: 'static, Item: 'static>, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -500,7 +560,7 @@ LL | T: Iterator<Item: 'static, Item: 'static>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:229:32 + --> $DIR/duplicate.rs:234:32 | LL | Self: Iterator<Item: Copy, Item: Send>, | ---------- ^^^^^^^^^^ re-bound here @@ -508,7 +568,7 @@ LL | Self: Iterator<Item: Copy, Item: Send>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:229:32 + --> $DIR/duplicate.rs:234:32 | LL | Self: Iterator<Item: Copy, Item: Send>, | ---------- ^^^^^^^^^^ re-bound here @@ -518,7 +578,7 @@ LL | Self: Iterator<Item: Copy, Item: Send>, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:229:32 + --> $DIR/duplicate.rs:234:32 | LL | Self: Iterator<Item: Copy, Item: Send>, | ---------- ^^^^^^^^^^ re-bound here @@ -528,7 +588,7 @@ LL | Self: Iterator<Item: Copy, Item: Send>, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:237:32 + --> $DIR/duplicate.rs:242:32 | LL | Self: Iterator<Item: Copy, Item: Copy>, | ---------- ^^^^^^^^^^ re-bound here @@ -536,7 +596,7 @@ LL | Self: Iterator<Item: Copy, Item: Copy>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:237:32 + --> $DIR/duplicate.rs:242:32 | LL | Self: Iterator<Item: Copy, Item: Copy>, | ---------- ^^^^^^^^^^ re-bound here @@ -546,7 +606,7 @@ LL | Self: Iterator<Item: Copy, Item: Copy>, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:237:32 + --> $DIR/duplicate.rs:242:32 | LL | Self: Iterator<Item: Copy, Item: Copy>, | ---------- ^^^^^^^^^^ re-bound here @@ -556,7 +616,7 @@ LL | Self: Iterator<Item: Copy, Item: Copy>, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:245:35 + --> $DIR/duplicate.rs:250:35 | LL | Self: Iterator<Item: 'static, Item: 'static>, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -564,7 +624,7 @@ LL | Self: Iterator<Item: 'static, Item: 'static>, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:245:35 + --> $DIR/duplicate.rs:250:35 | LL | Self: Iterator<Item: 'static, Item: 'static>, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -574,7 +634,7 @@ LL | Self: Iterator<Item: 'static, Item: 'static>, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:245:35 + --> $DIR/duplicate.rs:250:35 | LL | Self: Iterator<Item: 'static, Item: 'static>, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -584,30 +644,60 @@ LL | Self: Iterator<Item: 'static, Item: 'static>, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:252:34 + --> $DIR/duplicate.rs:257:34 + | +LL | type A: Iterator<Item: Copy, Item: Send>; + | ---------- ^^^^^^^^^^ re-bound here + | | + | `Item` bound here first + +error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified + --> $DIR/duplicate.rs:257:34 | LL | type A: Iterator<Item: Copy, Item: Send>; | ---------- ^^^^^^^^^^ re-bound here | | | `Item` bound here first + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified + --> $DIR/duplicate.rs:262:34 + | +LL | type A: Iterator<Item: Copy, Item: Copy>; + | ---------- ^^^^^^^^^^ re-bound here + | | + | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:256:34 + --> $DIR/duplicate.rs:262:34 | LL | type A: Iterator<Item: Copy, Item: Copy>; | ---------- ^^^^^^^^^^ re-bound here | | | `Item` bound here first + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:260:37 + --> $DIR/duplicate.rs:267:37 | LL | type A: Iterator<Item: 'static, Item: 'static>; | ------------- ^^^^^^^^^^^^^ re-bound here | | | `Item` bound here first -error: aborting due to 72 previous errors +error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified + --> $DIR/duplicate.rs:267:37 + | +LL | type A: Iterator<Item: 'static, Item: 'static>; + | ------------- ^^^^^^^^^^^^^ re-bound here + | | + | `Item` bound here first + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 81 previous errors Some errors have detailed explanations: E0282, E0719. For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/associated-type-bounds/elision.rs b/tests/ui/associated-type-bounds/elision.rs index 5d7ed940ac6..8d35df1e4f4 100644 --- a/tests/ui/associated-type-bounds/elision.rs +++ b/tests/ui/associated-type-bounds/elision.rs @@ -1,4 +1,3 @@ -#![feature(associated_type_bounds)] #![feature(anonymous_lifetime_in_impl_trait)] // The same thing should happen for constraints in dyn trait. diff --git a/tests/ui/associated-type-bounds/elision.stderr b/tests/ui/associated-type-bounds/elision.stderr index 749dffdc4d3..36ca5a80024 100644 --- a/tests/ui/associated-type-bounds/elision.stderr +++ b/tests/ui/associated-type-bounds/elision.stderr @@ -1,5 +1,5 @@ error[E0106]: missing lifetime specifier - --> $DIR/elision.rs:5:70 + --> $DIR/elision.rs:4:70 | LL | fn f(x: &mut dyn Iterator<Item: Iterator<Item = &'_ ()>>) -> Option<&'_ ()> { x.next() } | ------------------------------------------------ ^^ expected named lifetime parameter @@ -11,7 +11,7 @@ LL | fn f<'a>(x: &'a mut dyn Iterator<Item: Iterator<Item = &'a ()>>) -> Option< | ++++ ++ ~~ ~~ error: associated type bounds are not allowed in `dyn` types - --> $DIR/elision.rs:5:27 + --> $DIR/elision.rs:4:27 | LL | fn f(x: &mut dyn Iterator<Item: Iterator<Item = &'_ ()>>) -> Option<&'_ ()> { x.next() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/associated-type-bounds/entails-sized-object-safety.rs b/tests/ui/associated-type-bounds/entails-sized-object-safety.rs index 211c67061e6..ad2cbe48209 100644 --- a/tests/ui/associated-type-bounds/entails-sized-object-safety.rs +++ b/tests/ui/associated-type-bounds/entails-sized-object-safety.rs @@ -1,7 +1,5 @@ //@ build-pass (FIXME(62277): could be check-pass?) -#![feature(associated_type_bounds)] - trait Tr1: Sized { type As1; } trait Tr2<'a>: Sized { type As2; } diff --git a/tests/ui/associated-type-bounds/enum-bounds.rs b/tests/ui/associated-type-bounds/enum-bounds.rs index b5087acb6b8..b1c42610862 100644 --- a/tests/ui/associated-type-bounds/enum-bounds.rs +++ b/tests/ui/associated-type-bounds/enum-bounds.rs @@ -1,6 +1,5 @@ //@ run-pass -#![feature(associated_type_bounds)] #![allow(dead_code)] trait Tr1 { type As1; } diff --git a/tests/ui/associated-type-bounds/fn-apit.rs b/tests/ui/associated-type-bounds/fn-apit.rs index 8e1897cc3d4..24bb5b93c99 100644 --- a/tests/ui/associated-type-bounds/fn-apit.rs +++ b/tests/ui/associated-type-bounds/fn-apit.rs @@ -2,8 +2,6 @@ //@ aux-build:fn-aux.rs #![allow(unused)] -#![feature(associated_type_bounds)] - extern crate fn_aux; use fn_aux::*; diff --git a/tests/ui/associated-type-bounds/fn-aux.rs b/tests/ui/associated-type-bounds/fn-aux.rs index 6aaa0cc895f..26ba2cc4015 100644 --- a/tests/ui/associated-type-bounds/fn-aux.rs +++ b/tests/ui/associated-type-bounds/fn-aux.rs @@ -1,8 +1,6 @@ //@ run-pass //@ aux-build:fn-aux.rs -#![feature(associated_type_bounds)] - extern crate fn_aux; use fn_aux::*; diff --git a/tests/ui/associated-type-bounds/fn-inline.rs b/tests/ui/associated-type-bounds/fn-inline.rs index 8435cb44a9a..971751cc115 100644 --- a/tests/ui/associated-type-bounds/fn-inline.rs +++ b/tests/ui/associated-type-bounds/fn-inline.rs @@ -2,8 +2,6 @@ //@ aux-build:fn-aux.rs #![allow(unused)] -#![feature(associated_type_bounds)] - extern crate fn_aux; use fn_aux::*; diff --git a/tests/ui/associated-type-bounds/fn-where.rs b/tests/ui/associated-type-bounds/fn-where.rs index 3b6b557fb11..d28860bd4cc 100644 --- a/tests/ui/associated-type-bounds/fn-where.rs +++ b/tests/ui/associated-type-bounds/fn-where.rs @@ -2,8 +2,6 @@ //@ aux-build:fn-aux.rs #![allow(unused)] -#![feature(associated_type_bounds)] - extern crate fn_aux; use fn_aux::*; diff --git a/tests/ui/associated-type-bounds/fn-wrap-apit.rs b/tests/ui/associated-type-bounds/fn-wrap-apit.rs index 4ce714d432f..7b55cd33b24 100644 --- a/tests/ui/associated-type-bounds/fn-wrap-apit.rs +++ b/tests/ui/associated-type-bounds/fn-wrap-apit.rs @@ -1,7 +1,6 @@ //@ run-pass //@ aux-build:fn-aux.rs -#![feature(associated_type_bounds)] #![allow(dead_code)] extern crate fn_aux; diff --git a/tests/ui/associated-type-bounds/higher-ranked.rs b/tests/ui/associated-type-bounds/higher-ranked.rs index 9e783c4bdca..a313b54f5b9 100644 --- a/tests/ui/associated-type-bounds/higher-ranked.rs +++ b/tests/ui/associated-type-bounds/higher-ranked.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - trait A<'a> { type Assoc: ?Sized; } diff --git a/tests/ui/associated-type-bounds/hrtb.rs b/tests/ui/associated-type-bounds/hrtb.rs index 73c7a1a5677..1bf574f2e65 100644 --- a/tests/ui/associated-type-bounds/hrtb.rs +++ b/tests/ui/associated-type-bounds/hrtb.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - trait A<'a> {} trait B<'b> {} fn foo<T>() diff --git a/tests/ui/associated-type-bounds/implied-bounds-cycle.rs b/tests/ui/associated-type-bounds/implied-bounds-cycle.rs index 785d47d4791..8f2bec889ea 100644 --- a/tests/ui/associated-type-bounds/implied-bounds-cycle.rs +++ b/tests/ui/associated-type-bounds/implied-bounds-cycle.rs @@ -1,5 +1,3 @@ -#![feature(associated_type_bounds)] - trait A { type T; } diff --git a/tests/ui/associated-type-bounds/implied-bounds-cycle.stderr b/tests/ui/associated-type-bounds/implied-bounds-cycle.stderr index 1c1c64ea5f5..9ced7431210 100644 --- a/tests/ui/associated-type-bounds/implied-bounds-cycle.stderr +++ b/tests/ui/associated-type-bounds/implied-bounds-cycle.stderr @@ -1,12 +1,12 @@ error[E0391]: cycle detected when computing the implied predicates of `B` - --> $DIR/implied-bounds-cycle.rs:7:15 + --> $DIR/implied-bounds-cycle.rs:5:15 | LL | trait B: A<T: B> {} | ^ | = note: ...which immediately requires computing the implied predicates of `B` again note: cycle used when computing normalized predicates of `B` - --> $DIR/implied-bounds-cycle.rs:7:1 + --> $DIR/implied-bounds-cycle.rs:5:1 | LL | trait B: A<T: B> {} | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/associated-type-bounds/implied-in-supertrait.rs b/tests/ui/associated-type-bounds/implied-in-supertrait.rs index 83cb07d700a..639eb8dc6db 100644 --- a/tests/ui/associated-type-bounds/implied-in-supertrait.rs +++ b/tests/ui/associated-type-bounds/implied-in-supertrait.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - trait Trait: Super<Assoc: Bound> {} trait Super { diff --git a/tests/ui/associated-type-bounds/implied-region-constraints.rs b/tests/ui/associated-type-bounds/implied-region-constraints.rs index 38219da61b4..ab03376c076 100644 --- a/tests/ui/associated-type-bounds/implied-region-constraints.rs +++ b/tests/ui/associated-type-bounds/implied-region-constraints.rs @@ -1,5 +1,3 @@ -#![feature(associated_type_bounds)] - trait Tr1 { type As1; } trait Tr2 { type As2; } diff --git a/tests/ui/associated-type-bounds/implied-region-constraints.stderr b/tests/ui/associated-type-bounds/implied-region-constraints.stderr index cddce8777ea..0aa76f732e4 100644 --- a/tests/ui/associated-type-bounds/implied-region-constraints.stderr +++ b/tests/ui/associated-type-bounds/implied-region-constraints.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/implied-region-constraints.rs:17:56 + --> $DIR/implied-region-constraints.rs:15:56 | LL | fn _bad_st<'a, 'b, T>(x: St<'a, 'b, T>) | -- -- lifetime `'b` defined here @@ -12,7 +12,7 @@ LL | let _failure_proves_not_implied_outlives_region_b: &'b T = &x.f0; = help: consider adding the following bound: `'a: 'b` error: lifetime may not live long enough - --> $DIR/implied-region-constraints.rs:38:64 + --> $DIR/implied-region-constraints.rs:36:64 | LL | fn _bad_en7<'a, 'b, T>(x: En7<'a, 'b, T>) | -- -- lifetime `'b` defined here diff --git a/tests/ui/associated-type-bounds/inside-adt.rs b/tests/ui/associated-type-bounds/inside-adt.rs index 2b4b060983e..bf520d7ee38 100644 --- a/tests/ui/associated-type-bounds/inside-adt.rs +++ b/tests/ui/associated-type-bounds/inside-adt.rs @@ -1,5 +1,3 @@ -#![feature(associated_type_bounds)] - use std::mem::ManuallyDrop; struct S1 { f: dyn Iterator<Item: Copy> } diff --git a/tests/ui/associated-type-bounds/inside-adt.stderr b/tests/ui/associated-type-bounds/inside-adt.stderr index ef45fae8f2a..ff9e2585264 100644 --- a/tests/ui/associated-type-bounds/inside-adt.stderr +++ b/tests/ui/associated-type-bounds/inside-adt.stderr @@ -1,53 +1,53 @@ error: associated type bounds are not allowed in `dyn` types - --> $DIR/inside-adt.rs:5:29 + --> $DIR/inside-adt.rs:3:29 | LL | struct S1 { f: dyn Iterator<Item: Copy> } | ^^^^^^^^^^ error: associated type bounds are not allowed in `dyn` types - --> $DIR/inside-adt.rs:7:33 + --> $DIR/inside-adt.rs:5:33 | LL | struct S2 { f: Box<dyn Iterator<Item: Copy>> } | ^^^^^^^^^^ error: associated type bounds are not allowed in `dyn` types - --> $DIR/inside-adt.rs:9:29 + --> $DIR/inside-adt.rs:7:29 | LL | struct S3 { f: dyn Iterator<Item: 'static> } | ^^^^^^^^^^^^^ error: associated type bounds are not allowed in `dyn` types - --> $DIR/inside-adt.rs:12:26 + --> $DIR/inside-adt.rs:10:26 | LL | enum E1 { V(dyn Iterator<Item: Copy>) } | ^^^^^^^^^^ error: associated type bounds are not allowed in `dyn` types - --> $DIR/inside-adt.rs:14:30 + --> $DIR/inside-adt.rs:12:30 | LL | enum E2 { V(Box<dyn Iterator<Item: Copy>>) } | ^^^^^^^^^^ error: associated type bounds are not allowed in `dyn` types - --> $DIR/inside-adt.rs:16:26 + --> $DIR/inside-adt.rs:14:26 | LL | enum E3 { V(dyn Iterator<Item: 'static>) } | ^^^^^^^^^^^^^ error: associated type bounds are not allowed in `dyn` types - --> $DIR/inside-adt.rs:19:41 + --> $DIR/inside-adt.rs:17:41 | LL | union U1 { f: ManuallyDrop<dyn Iterator<Item: Copy>> } | ^^^^^^^^^^ error: associated type bounds are not allowed in `dyn` types - --> $DIR/inside-adt.rs:21:45 + --> $DIR/inside-adt.rs:19:45 | LL | union U2 { f: ManuallyDrop<Box<dyn Iterator<Item: Copy>>> } | ^^^^^^^^^^ error: associated type bounds are not allowed in `dyn` types - --> $DIR/inside-adt.rs:23:41 + --> $DIR/inside-adt.rs:21:41 | LL | union U3 { f: ManuallyDrop<dyn Iterator<Item: 'static>> } | ^^^^^^^^^^^^^ diff --git a/tests/ui/associated-type-bounds/issue-102335-ty.rs b/tests/ui/associated-type-bounds/issue-102335-ty.rs index 363df73c1ff..5fd8b71e679 100644 --- a/tests/ui/associated-type-bounds/issue-102335-ty.rs +++ b/tests/ui/associated-type-bounds/issue-102335-ty.rs @@ -1,6 +1,7 @@ trait T { type A: S<C<i32 = u32> = ()>; //~^ ERROR associated type bindings are not allowed here + //~| ERROR associated type bindings are not allowed here } trait Q {} diff --git a/tests/ui/associated-type-bounds/issue-102335-ty.stderr b/tests/ui/associated-type-bounds/issue-102335-ty.stderr index 561ca15ab0d..3bd7566ad1e 100644 --- a/tests/ui/associated-type-bounds/issue-102335-ty.stderr +++ b/tests/ui/associated-type-bounds/issue-102335-ty.stderr @@ -4,6 +4,14 @@ error[E0229]: associated type bindings are not allowed here LL | type A: S<C<i32 = u32> = ()>; | ^^^^^^^^^ associated type not allowed here -error: aborting due to 1 previous error +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-102335-ty.rs:2:17 + | +LL | type A: S<C<i32 = u32> = ()>; + | ^^^^^^^^^ associated type not allowed here + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0229`. diff --git a/tests/ui/associated-type-bounds/issue-104916.rs b/tests/ui/associated-type-bounds/issue-104916.rs index ee29a0a2fc4..75f327e6ee7 100644 --- a/tests/ui/associated-type-bounds/issue-104916.rs +++ b/tests/ui/associated-type-bounds/issue-104916.rs @@ -1,5 +1,3 @@ -#![feature(associated_type_bounds)] - trait B { type AssocType; } diff --git a/tests/ui/associated-type-bounds/issue-104916.stderr b/tests/ui/associated-type-bounds/issue-104916.stderr index e8618b72103..21927328dad 100644 --- a/tests/ui/associated-type-bounds/issue-104916.stderr +++ b/tests/ui/associated-type-bounds/issue-104916.stderr @@ -1,5 +1,5 @@ error: associated type bounds are not allowed in `dyn` types - --> $DIR/issue-104916.rs:9:19 + --> $DIR/issue-104916.rs:7:19 | LL | dyn for<'j> B<AssocType: 'j>:, | ^^^^^^^^^^^^^ diff --git a/tests/ui/associated-type-bounds/issue-61752.rs b/tests/ui/associated-type-bounds/issue-61752.rs index 22e43ea875e..a73ba833c43 100644 --- a/tests/ui/associated-type-bounds/issue-61752.rs +++ b/tests/ui/associated-type-bounds/issue-61752.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - trait Foo { type Bar; } diff --git a/tests/ui/associated-type-bounds/issue-70292.rs b/tests/ui/associated-type-bounds/issue-70292.rs index 4b8e19904d0..1a6bdcd1a31 100644 --- a/tests/ui/associated-type-bounds/issue-70292.rs +++ b/tests/ui/associated-type-bounds/issue-70292.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - fn foo<F>(_: F) where F: for<'a> Trait<Output: 'a>, diff --git a/tests/ui/associated-type-bounds/issue-71443-1.rs b/tests/ui/associated-type-bounds/issue-71443-1.rs index 5d2a3e6cbad..58341ac3d3a 100644 --- a/tests/ui/associated-type-bounds/issue-71443-1.rs +++ b/tests/ui/associated-type-bounds/issue-71443-1.rs @@ -1,5 +1,3 @@ -#![feature(associated_type_bounds)] - struct Incorrect; fn hello<F: for<'a> Iterator<Item: 'a>>() { diff --git a/tests/ui/associated-type-bounds/issue-71443-1.stderr b/tests/ui/associated-type-bounds/issue-71443-1.stderr index 6abaaf8e182..27ef545daaa 100644 --- a/tests/ui/associated-type-bounds/issue-71443-1.stderr +++ b/tests/ui/associated-type-bounds/issue-71443-1.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-71443-1.rs:6:5 + --> $DIR/issue-71443-1.rs:4:5 | LL | fn hello<F: for<'a> Iterator<Item: 'a>>() { | - help: try adding a return type: `-> Incorrect` diff --git a/tests/ui/associated-type-bounds/issue-71443-2.rs b/tests/ui/associated-type-bounds/issue-71443-2.rs index bd072f44650..24c4c88f20b 100644 --- a/tests/ui/associated-type-bounds/issue-71443-2.rs +++ b/tests/ui/associated-type-bounds/issue-71443-2.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - fn hello<'b, F>() where for<'a> F: Iterator<Item: 'a> + 'b, diff --git a/tests/ui/associated-type-bounds/issue-79949.rs b/tests/ui/associated-type-bounds/issue-79949.rs index 4513f0a0b62..9f4a8ffa7e7 100644 --- a/tests/ui/associated-type-bounds/issue-79949.rs +++ b/tests/ui/associated-type-bounds/issue-79949.rs @@ -1,8 +1,6 @@ //@ check-pass #![allow(incomplete_features)] -#![feature(associated_type_bounds)] - trait MP { type T<'a>; } diff --git a/tests/ui/associated-type-bounds/issue-81193.rs b/tests/ui/associated-type-bounds/issue-81193.rs index 1247f835be9..caa5915819b 100644 --- a/tests/ui/associated-type-bounds/issue-81193.rs +++ b/tests/ui/associated-type-bounds/issue-81193.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - trait A<'a, 'b> {} trait B<'a, 'b, 'c> {} diff --git a/tests/ui/associated-type-bounds/issue-83017.rs b/tests/ui/associated-type-bounds/issue-83017.rs index a059b940e66..932b71cc0ae 100644 --- a/tests/ui/associated-type-bounds/issue-83017.rs +++ b/tests/ui/associated-type-bounds/issue-83017.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - trait TraitA<'a> { type AsA; } diff --git a/tests/ui/associated-type-bounds/issue-99828.rs b/tests/ui/associated-type-bounds/issue-99828.rs index 67ba50f3cbc..ab3654131f1 100644 --- a/tests/ui/associated-type-bounds/issue-99828.rs +++ b/tests/ui/associated-type-bounds/issue-99828.rs @@ -1,5 +1,6 @@ fn get_iter(vec: &[i32]) -> impl Iterator<Item = {}> + '_ { //~^ ERROR expected type, found constant + //~| ERROR expected type, found constant //~| ERROR associated const equality is incomplete vec.iter() } diff --git a/tests/ui/associated-type-bounds/issue-99828.stderr b/tests/ui/associated-type-bounds/issue-99828.stderr index 911f3ff0f5e..132d5251987 100644 --- a/tests/ui/associated-type-bounds/issue-99828.stderr +++ b/tests/ui/associated-type-bounds/issue-99828.stderr @@ -19,6 +19,18 @@ LL | fn get_iter(vec: &[i32]) -> impl Iterator<Item = {}> + '_ { note: the associated type is defined here --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL -error: aborting due to 2 previous errors +error: expected type, found constant + --> $DIR/issue-99828.rs:1:50 + | +LL | fn get_iter(vec: &[i32]) -> impl Iterator<Item = {}> + '_ { + | ---- ^^ unexpected constant + | | + | expected a type because of this associated type + | +note: the associated type is defined here + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/associated-type-bounds/nested-bounds-dont-eliminate-alias-bounds.rs b/tests/ui/associated-type-bounds/nested-bounds-dont-eliminate-alias-bounds.rs index ee4de509da6..305c117da62 100644 --- a/tests/ui/associated-type-bounds/nested-bounds-dont-eliminate-alias-bounds.rs +++ b/tests/ui/associated-type-bounds/nested-bounds-dont-eliminate-alias-bounds.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - trait Trait1 { type Assoc1: Bar; diff --git a/tests/ui/associated-type-bounds/no-gat-position.rs b/tests/ui/associated-type-bounds/no-gat-position.rs index 01740e6242e..5005c5027f4 100644 --- a/tests/ui/associated-type-bounds/no-gat-position.rs +++ b/tests/ui/associated-type-bounds/no-gat-position.rs @@ -1,5 +1,3 @@ -#![feature(associated_type_bounds)] - // Test for <https://github.com/rust-lang/rust/issues/119857>. pub trait Iter { diff --git a/tests/ui/associated-type-bounds/no-gat-position.stderr b/tests/ui/associated-type-bounds/no-gat-position.stderr index 5692b2c7d09..c348d33c3a9 100644 --- a/tests/ui/associated-type-bounds/no-gat-position.stderr +++ b/tests/ui/associated-type-bounds/no-gat-position.stderr @@ -1,5 +1,5 @@ error[E0229]: associated type bindings are not allowed here - --> $DIR/no-gat-position.rs:8:56 + --> $DIR/no-gat-position.rs:6:56 | LL | fn next<'a>(&'a mut self) -> Option<Self::Item<'a, As1: Copy>>; | ^^^^^^^^^ associated type not allowed here diff --git a/tests/ui/associated-type-bounds/overlaping-bound-suggestion.rs b/tests/ui/associated-type-bounds/overlaping-bound-suggestion.rs index 3853bc8594f..c0012564843 100644 --- a/tests/ui/associated-type-bounds/overlaping-bound-suggestion.rs +++ b/tests/ui/associated-type-bounds/overlaping-bound-suggestion.rs @@ -1,5 +1,4 @@ #![allow(bare_trait_objects)] -#![feature(associated_type_bounds)] trait Item { type Core; } diff --git a/tests/ui/associated-type-bounds/overlaping-bound-suggestion.stderr b/tests/ui/associated-type-bounds/overlaping-bound-suggestion.stderr index 03d72f2ae2c..39a2b98e2e2 100644 --- a/tests/ui/associated-type-bounds/overlaping-bound-suggestion.stderr +++ b/tests/ui/associated-type-bounds/overlaping-bound-suggestion.stderr @@ -1,11 +1,11 @@ error[E0191]: the value of the associated types `Item` and `IntoIter` in `IntoIterator` must be specified - --> $DIR/overlaping-bound-suggestion.rs:7:13 + --> $DIR/overlaping-bound-suggestion.rs:6:13 | LL | inner: <IntoIterator<Item: IntoIterator<Item: >>::IntoIterator as Item>::Core, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: specify the associated types: `IntoIterator<Item: IntoIterator<Item: >, Item = Type, IntoIter = Type>` error[E0223]: ambiguous associated type - --> $DIR/overlaping-bound-suggestion.rs:7:13 + --> $DIR/overlaping-bound-suggestion.rs:6:13 | LL | inner: <IntoIterator<Item: IntoIterator<Item: >>::IntoIterator as Item>::Core, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs index 50a8cd8e04b..c23eff79ce2 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.rs @@ -9,11 +9,9 @@ trait Trait { fn foo<T: Trait<method(i32): Send>>() {} //~^ ERROR argument types not allowed with return type notation -//~| ERROR associated type bounds are unstable fn bar<T: Trait<method() -> (): Send>>() {} //~^ ERROR return type not allowed with return type notation -//~| ERROR associated type bounds are unstable fn baz<T: Trait<method(..): Send>>() {} //~^ ERROR return type notation uses `()` instead of `(..)` for elided arguments diff --git a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr index 02bec24c628..d95249efe40 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/bad-inputs-and-output.stderr @@ -1,29 +1,9 @@ error: return type notation uses `()` instead of `(..)` for elided arguments - --> $DIR/bad-inputs-and-output.rs:18:24 + --> $DIR/bad-inputs-and-output.rs:16:24 | LL | fn baz<T: Trait<method(..): Send>>() {} | ^^ help: remove the `..` -error[E0658]: associated type bounds are unstable - --> $DIR/bad-inputs-and-output.rs:10:17 - | -LL | fn foo<T: Trait<method(i32): Send>>() {} - | ^^^^^^^^^^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: associated type bounds are unstable - --> $DIR/bad-inputs-and-output.rs:14:17 - | -LL | fn bar<T: Trait<method() -> (): Send>>() {} - | ^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/bad-inputs-and-output.rs:3:12 | @@ -40,11 +20,10 @@ LL | fn foo<T: Trait<method(i32): Send>>() {} | ^^^^^ help: remove the input types: `()` error: return type not allowed with return type notation - --> $DIR/bad-inputs-and-output.rs:14:25 + --> $DIR/bad-inputs-and-output.rs:13:25 | LL | fn bar<T: Trait<method() -> (): Send>>() {} | ^^^^^^ help: remove the return type -error: aborting due to 5 previous errors; 1 warning emitted +error: aborting due to 3 previous errors; 1 warning emitted -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.rs b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.rs index 0a98f0d2c8d..931e41bc840 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.rs @@ -1,11 +1,14 @@ //@ edition: 2021 //@ compile-flags: -Zunpretty=expanded +//@ check-pass + +// NOTE: This is not considered RTN syntax currently. +// This is simply parenthesized generics. trait Trait { async fn method() {} } fn foo<T: Trait<method(i32): Send>>() {} -//~^ ERROR associated type bounds are unstable fn main() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stderr b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stderr deleted file mode 100644 index 3007240c3ab..00000000000 --- a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error[E0658]: associated type bounds are unstable - --> $DIR/unpretty-parenthesized.rs:8:17 - | -LL | fn foo<T: Trait<method(i32): Send>>() {} - | ^^^^^^^^^^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout index 17c3b9580ca..87667553837 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout +++ b/tests/ui/associated-type-bounds/return-type-notation/unpretty-parenthesized.stdout @@ -5,6 +5,10 @@ use std::prelude::rust_2021::*; extern crate std; //@ edition: 2021 //@ compile-flags: -Zunpretty=expanded +//@ check-pass + +// NOTE: This is not considered RTN syntax currently. +// This is simply parenthesized generics. trait Trait { async fn method() {} diff --git a/tests/ui/associated-type-bounds/rpit.rs b/tests/ui/associated-type-bounds/rpit.rs index 78710621cad..cb1d7f8fcc7 100644 --- a/tests/ui/associated-type-bounds/rpit.rs +++ b/tests/ui/associated-type-bounds/rpit.rs @@ -1,7 +1,5 @@ //@ run-pass -#![feature(associated_type_bounds)] - use std::ops::Add; trait Tr1 { type As1; fn mk(self) -> Self::As1; } diff --git a/tests/ui/associated-type-bounds/rpit.stderr b/tests/ui/associated-type-bounds/rpit.stderr index 76bd75bd2ca..1091a4c573b 100644 --- a/tests/ui/associated-type-bounds/rpit.stderr +++ b/tests/ui/associated-type-bounds/rpit.stderr @@ -1,5 +1,5 @@ warning: method `tr2` is never used - --> $DIR/rpit.rs:8:20 + --> $DIR/rpit.rs:6:20 | LL | trait Tr2<'a> { fn tr2(self) -> &'a Self; } | --- ^^^ diff --git a/tests/ui/associated-type-bounds/struct-bounds.rs b/tests/ui/associated-type-bounds/struct-bounds.rs index 2c46832cb99..0c8a52539f3 100644 --- a/tests/ui/associated-type-bounds/struct-bounds.rs +++ b/tests/ui/associated-type-bounds/struct-bounds.rs @@ -1,8 +1,6 @@ //@ run-pass #![allow(unused)] -#![feature(associated_type_bounds)] - trait Tr1 { type As1; } trait Tr2 { type As2; } trait Tr3 {} diff --git a/tests/ui/associated-type-bounds/supertrait-defines-ty.rs b/tests/ui/associated-type-bounds/supertrait-defines-ty.rs index 62b23b5fbab..ed1c1fa6f03 100644 --- a/tests/ui/associated-type-bounds/supertrait-defines-ty.rs +++ b/tests/ui/associated-type-bounds/supertrait-defines-ty.rs @@ -3,8 +3,6 @@ // Make sure that we don't look into associated type bounds when looking for // supertraits that define an associated type. Fixes #76593. -#![feature(associated_type_bounds)] - trait Load: Sized { type Blob; } diff --git a/tests/ui/associated-type-bounds/trait-alias-impl-trait.rs b/tests/ui/associated-type-bounds/trait-alias-impl-trait.rs index 6ca9f80ccaf..fb6a4fcbe97 100644 --- a/tests/ui/associated-type-bounds/trait-alias-impl-trait.rs +++ b/tests/ui/associated-type-bounds/trait-alias-impl-trait.rs @@ -1,7 +1,6 @@ //@ run-pass #![allow(dead_code)] -#![feature(associated_type_bounds)] #![feature(type_alias_impl_trait)] use std::ops::Add; diff --git a/tests/ui/associated-type-bounds/trait-params.rs b/tests/ui/associated-type-bounds/trait-params.rs index 6782d688126..72a445351e7 100644 --- a/tests/ui/associated-type-bounds/trait-params.rs +++ b/tests/ui/associated-type-bounds/trait-params.rs @@ -1,7 +1,5 @@ //@ build-pass (FIXME(62277): could be check-pass?) -#![feature(associated_type_bounds)] - use std::iter::Once; use std::ops::Range; diff --git a/tests/ui/associated-type-bounds/type-alias.rs b/tests/ui/associated-type-bounds/type-alias.rs index 819a7656a44..2dccb37f37f 100644 --- a/tests/ui/associated-type-bounds/type-alias.rs +++ b/tests/ui/associated-type-bounds/type-alias.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - type _TaWhere1<T> where T: Iterator<Item: Copy> = T; //~ WARNING type_alias_bounds type _TaWhere2<T> where T: Iterator<Item: 'static> = T; //~ WARNING type_alias_bounds type _TaWhere3<T> where T: Iterator<Item: 'static> = T; //~ WARNING type_alias_bounds diff --git a/tests/ui/associated-type-bounds/type-alias.stderr b/tests/ui/associated-type-bounds/type-alias.stderr index c22b80b889e..072c471467c 100644 --- a/tests/ui/associated-type-bounds/type-alias.stderr +++ b/tests/ui/associated-type-bounds/type-alias.stderr @@ -1,5 +1,5 @@ warning: where clauses are not enforced in type aliases - --> $DIR/type-alias.rs:5:25 + --> $DIR/type-alias.rs:3:25 | LL | type _TaWhere1<T> where T: Iterator<Item: Copy> = T; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL + type _TaWhere1<T> = T; | warning: where clauses are not enforced in type aliases - --> $DIR/type-alias.rs:6:25 + --> $DIR/type-alias.rs:4:25 | LL | type _TaWhere2<T> where T: Iterator<Item: 'static> = T; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL + type _TaWhere2<T> = T; | warning: where clauses are not enforced in type aliases - --> $DIR/type-alias.rs:7:25 + --> $DIR/type-alias.rs:5:25 | LL | type _TaWhere3<T> where T: Iterator<Item: 'static> = T; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL + type _TaWhere3<T> = T; | warning: where clauses are not enforced in type aliases - --> $DIR/type-alias.rs:8:25 + --> $DIR/type-alias.rs:6:25 | LL | type _TaWhere4<T> where T: Iterator<Item: 'static + Copy + Send> = T; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +48,7 @@ LL + type _TaWhere4<T> = T; | warning: where clauses are not enforced in type aliases - --> $DIR/type-alias.rs:9:25 + --> $DIR/type-alias.rs:7:25 | LL | type _TaWhere5<T> where T: Iterator<Item: for<'a> Into<&'a u8>> = T; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL + type _TaWhere5<T> = T; | warning: where clauses are not enforced in type aliases - --> $DIR/type-alias.rs:10:25 + --> $DIR/type-alias.rs:8:25 | LL | type _TaWhere6<T> where T: Iterator<Item: Iterator<Item: Copy>> = T; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL + type _TaWhere6<T> = T; | warning: bounds on generic parameters are not enforced in type aliases - --> $DIR/type-alias.rs:12:20 + --> $DIR/type-alias.rs:10:20 | LL | type _TaInline1<T: Iterator<Item: Copy>> = T; | ^^^^^^^^^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL + type _TaInline1<T> = T; | warning: bounds on generic parameters are not enforced in type aliases - --> $DIR/type-alias.rs:13:20 + --> $DIR/type-alias.rs:11:20 | LL | type _TaInline2<T: Iterator<Item: 'static>> = T; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL + type _TaInline2<T> = T; | warning: bounds on generic parameters are not enforced in type aliases - --> $DIR/type-alias.rs:14:20 + --> $DIR/type-alias.rs:12:20 | LL | type _TaInline3<T: Iterator<Item: 'static>> = T; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + type _TaInline3<T> = T; | warning: bounds on generic parameters are not enforced in type aliases - --> $DIR/type-alias.rs:15:20 + --> $DIR/type-alias.rs:13:20 | LL | type _TaInline4<T: Iterator<Item: 'static + Copy + Send>> = T; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +120,7 @@ LL + type _TaInline4<T> = T; | warning: bounds on generic parameters are not enforced in type aliases - --> $DIR/type-alias.rs:16:20 + --> $DIR/type-alias.rs:14:20 | LL | type _TaInline5<T: Iterator<Item: for<'a> Into<&'a u8>>> = T; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +132,7 @@ LL + type _TaInline5<T> = T; | warning: bounds on generic parameters are not enforced in type aliases - --> $DIR/type-alias.rs:17:20 + --> $DIR/type-alias.rs:15:20 | LL | type _TaInline6<T: Iterator<Item: Iterator<Item: Copy>>> = T; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/associated-type-bounds/union-bounds.rs b/tests/ui/associated-type-bounds/union-bounds.rs index 8a7ba6f5ebf..b9b92a96fb0 100644 --- a/tests/ui/associated-type-bounds/union-bounds.rs +++ b/tests/ui/associated-type-bounds/union-bounds.rs @@ -1,7 +1,5 @@ //@ run-pass -#![feature(associated_type_bounds)] - #![allow(unused_assignments)] trait Tr1: Copy { type As1: Copy; } diff --git a/tests/ui/associated-types/issue-63591.rs b/tests/ui/associated-types/issue-63591.rs index 33826a24ddb..52464d94a23 100644 --- a/tests/ui/associated-types/issue-63591.rs +++ b/tests/ui/associated-types/issue-63591.rs @@ -1,6 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] #![feature(impl_trait_in_assoc_type)] fn main() {} diff --git a/tests/ui/associated-types/substs-ppaux.normal.stderr b/tests/ui/associated-types/substs-ppaux.normal.stderr index a2647f66835..8d3146be560 100644 --- a/tests/ui/associated-types/substs-ppaux.normal.stderr +++ b/tests/ui/associated-types/substs-ppaux.normal.stderr @@ -1,47 +1,51 @@ error[E0308]: mismatched types - --> $DIR/substs-ppaux.rs:16:17 + --> $DIR/substs-ppaux.rs:23:17 | -LL | fn bar<'a, T>() where T: 'a {} - | --------------------------- associated function `bar` defined here +LL | / fn bar<'a, T>() +LL | | where +LL | | T: 'a, + | |______________- associated function `bar` defined here ... -LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>; - | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item - | | - | expected due to this +LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>; + | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item + | | + | expected due to this | = note: expected unit type `()` found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>}` help: use parentheses to call this associated function | -LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>(); - | ++ +LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>(); + | ++ error[E0308]: mismatched types - --> $DIR/substs-ppaux.rs:25:17 + --> $DIR/substs-ppaux.rs:31:17 | -LL | fn bar<'a, T>() where T: 'a {} - | --------------------------- associated function `bar` defined here +LL | / fn bar<'a, T>() +LL | | where +LL | | T: 'a, + | |______________- associated function `bar` defined here ... -LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>; - | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item - | | - | expected due to this +LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>; + | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item + | | + | expected due to this | = note: expected unit type `()` found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}` help: use parentheses to call this associated function | -LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>(); - | ++ +LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>(); + | ++ error[E0308]: mismatched types - --> $DIR/substs-ppaux.rs:33:17 + --> $DIR/substs-ppaux.rs:39:17 | LL | fn baz() {} | -------- associated function `baz` defined here ... -LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz; - | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item +LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz; + | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item | | | expected due to this | @@ -49,19 +53,21 @@ LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz; found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}` help: use parentheses to call this associated function | -LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz(); - | ++ +LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz(); + | ++ error[E0308]: mismatched types - --> $DIR/substs-ppaux.rs:41:17 + --> $DIR/substs-ppaux.rs:47:17 | -LL | fn foo<'z>() where &'z (): Sized { - | -------------------------------- function `foo` defined here +LL | / fn foo<'z>() +LL | | where +LL | | &'z (): Sized, + | |__________________- function `foo` defined here ... -LL | let x: () = foo::<'static>; - | -- ^^^^^^^^^^^^^^ expected `()`, found fn item - | | - | expected due to this +LL | let x: () = foo::<'static>; + | -- ^^^^^^^^^^^^^^ expected `()`, found fn item + | | + | expected due to this | = note: expected unit type `()` found fn item `fn() {foo::<'static>}` @@ -71,18 +77,18 @@ LL | let x: () = foo::<'static>(); | ++ error[E0277]: the trait bound `str: Foo<'_, '_, u8>` is not satisfied - --> $DIR/substs-ppaux.rs:49:6 + --> $DIR/substs-ppaux.rs:55:6 | LL | <str as Foo<u8>>::bar; | ^^^ the trait `Sized` is not implemented for `str`, which is required by `str: Foo<'_, '_, u8>` | note: required for `str` to implement `Foo<'_, '_, u8>` - --> $DIR/substs-ppaux.rs:11:17 + --> $DIR/substs-ppaux.rs:15:20 | -LL | impl<'a,'b,T,S> Foo<'a, 'b, S> for T {} - | - ^^^^^^^^^^^^^^ ^ - | | - | unsatisfied trait bound introduced here +LL | impl<'a, 'b, T, S> Foo<'a, 'b, S> for T {} + | - ^^^^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here error: aborting due to 5 previous errors diff --git a/tests/ui/associated-types/substs-ppaux.rs b/tests/ui/associated-types/substs-ppaux.rs index 077ca764e24..302a6b345e4 100644 --- a/tests/ui/associated-types/substs-ppaux.rs +++ b/tests/ui/associated-types/substs-ppaux.rs @@ -3,37 +3,43 @@ // //@[verbose] compile-flags: -Z verbose-internals -trait Foo<'b, 'c, S=u32> { - fn bar<'a, T>() where T: 'a {} +trait Foo<'b, 'c, S = u32> { + fn bar<'a, T>() + where + T: 'a, + { + } fn baz() {} } -impl<'a,'b,T,S> Foo<'a, 'b, S> for T {} +impl<'a, 'b, T, S> Foo<'a, 'b, S> for T {} fn main() {} -fn foo<'z>() where &'z (): Sized { - let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>; +fn foo<'z>() +where + &'z (): Sized, +{ + let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>; //[verbose]~^ ERROR mismatched types //[verbose]~| expected unit type `()` - //[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::bar::<ReStatic, char>}` + //[verbose]~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>}` //[normal]~^^^^ ERROR mismatched types //[normal]~| expected unit type `()` //[normal]~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>}` - - let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>; + let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>; //[verbose]~^ ERROR mismatched types //[verbose]~| expected unit type `()` - //[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>}` + //[verbose]~| found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}` //[normal]~^^^^ ERROR mismatched types //[normal]~| expected unit type `()` //[normal]~| found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}` - let x: () = <i8 as Foo<'static, 'static, u8>>::baz; + let x: () = <i8 as Foo<'static, 'static, u8>>::baz; //[verbose]~^ ERROR mismatched types //[verbose]~| expected unit type `()` - //[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::baz}` + //[verbose]~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}` //[normal]~^^^^ ERROR mismatched types //[normal]~| expected unit type `()` //[normal]~| found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}` @@ -41,7 +47,7 @@ fn foo<'z>() where &'z (): Sized { let x: () = foo::<'static>; //[verbose]~^ ERROR mismatched types //[verbose]~| expected unit type `()` - //[verbose]~| found fn item `fn() {foo::<ReStatic>}` + //[verbose]~| found fn item `fn() {foo::<'static>}` //[normal]~^^^^ ERROR mismatched types //[normal]~| expected unit type `()` //[normal]~| found fn item `fn() {foo::<'static>}` diff --git a/tests/ui/associated-types/substs-ppaux.verbose.stderr b/tests/ui/associated-types/substs-ppaux.verbose.stderr index d32f44ccd64..0b5f449e576 100644 --- a/tests/ui/associated-types/substs-ppaux.verbose.stderr +++ b/tests/ui/associated-types/substs-ppaux.verbose.stderr @@ -1,88 +1,94 @@ error[E0308]: mismatched types - --> $DIR/substs-ppaux.rs:16:17 + --> $DIR/substs-ppaux.rs:23:17 | -LL | fn bar<'a, T>() where T: 'a {} - | --------------------------- associated function `bar` defined here +LL | / fn bar<'a, T>() +LL | | where +LL | | T: 'a, + | |______________- associated function `bar` defined here ... -LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>; - | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item - | | - | expected due to this +LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>; + | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item + | | + | expected due to this | = note: expected unit type `()` - found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::bar::<ReStatic, char>}` + found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::bar::<'static, char>}` help: use parentheses to call this associated function | -LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>(); - | ++ +LL | let x: () = <i8 as Foo<'static, 'static, u8>>::bar::<'static, char>(); + | ++ error[E0308]: mismatched types - --> $DIR/substs-ppaux.rs:25:17 + --> $DIR/substs-ppaux.rs:31:17 | -LL | fn bar<'a, T>() where T: 'a {} - | --------------------------- associated function `bar` defined here +LL | / fn bar<'a, T>() +LL | | where +LL | | T: 'a, + | |______________- associated function `bar` defined here ... -LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>; - | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item - | | - | expected due to this +LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>; + | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item + | | + | expected due to this | = note: expected unit type `()` - found fn item `fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>}` + found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}` help: use parentheses to call this associated function | -LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>(); - | ++ +LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>(); + | ++ error[E0308]: mismatched types - --> $DIR/substs-ppaux.rs:33:17 + --> $DIR/substs-ppaux.rs:39:17 | LL | fn baz() {} | -------- associated function `baz` defined here ... -LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz; - | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item +LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz; + | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item | | | expected due to this | = note: expected unit type `()` - found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u8>>::baz}` + found fn item `fn() {<i8 as Foo<'static, 'static, u8>>::baz}` help: use parentheses to call this associated function | -LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz(); - | ++ +LL | let x: () = <i8 as Foo<'static, 'static, u8>>::baz(); + | ++ error[E0308]: mismatched types - --> $DIR/substs-ppaux.rs:41:17 + --> $DIR/substs-ppaux.rs:47:17 | -LL | fn foo<'z>() where &'z (): Sized { - | -------------------------------- function `foo` defined here +LL | / fn foo<'z>() +LL | | where +LL | | &'z (): Sized, + | |__________________- function `foo` defined here ... -LL | let x: () = foo::<'static>; - | -- ^^^^^^^^^^^^^^ expected `()`, found fn item - | | - | expected due to this +LL | let x: () = foo::<'static>; + | -- ^^^^^^^^^^^^^^ expected `()`, found fn item + | | + | expected due to this | = note: expected unit type `()` - found fn item `fn() {foo::<ReStatic>}` + found fn item `fn() {foo::<'static>}` help: use parentheses to call this function | LL | let x: () = foo::<'static>(); | ++ error[E0277]: the trait bound `str: Foo<'?0, '?1, u8>` is not satisfied - --> $DIR/substs-ppaux.rs:49:6 + --> $DIR/substs-ppaux.rs:55:6 | LL | <str as Foo<u8>>::bar; | ^^^ the trait `Sized` is not implemented for `str`, which is required by `str: Foo<'?0, '?1, u8>` | note: required for `str` to implement `Foo<'?0, '?1, u8>` - --> $DIR/substs-ppaux.rs:11:17 + --> $DIR/substs-ppaux.rs:15:20 | -LL | impl<'a,'b,T,S> Foo<'a, 'b, S> for T {} - | - ^^^^^^^^^^^^^^ ^ - | | - | unsatisfied trait bound introduced here +LL | impl<'a, 'b, T, S> Foo<'a, 'b, S> for T {} + | - ^^^^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here error: aborting due to 5 previous errors diff --git a/tests/ui/async-await/async-await-let-else.stderr b/tests/ui/async-await/async-await-let-else.stderr index 057906b49a3..0952be2abe5 100644 --- a/tests/ui/async-await/async-await-let-else.stderr +++ b/tests/ui/async-await/async-await-let-else.stderr @@ -38,7 +38,6 @@ LL | async fn bar2<T>(_: T) -> ! { LL | | panic!() LL | | } | |_^ - = note: required because it captures the following types: `impl Future<Output = !>` note: required because it's used within this `async` fn body --> $DIR/async-await-let-else.rs:18:32 | diff --git a/tests/ui/async-await/async-closures/def-path.stderr b/tests/ui/async-await/async-closures/def-path.stderr index dae45825f37..0a1e30c1253 100644 --- a/tests/ui/async-await/async-closures/def-path.stderr +++ b/tests/ui/async-await/async-closures/def-path.stderr @@ -5,11 +5,11 @@ LL | let x = async || {}; | -- the expected `async` closure body LL | LL | let () = x(); - | ^^ --- this expression has type `{static main::{closure#0}::{closure#0}<?7t> upvar_tys=?15t witness=?6t}` + | ^^ --- this expression has type `{static main::{closure#0}::{closure#0}<?17t> upvar_tys=?16t witness=?6t}` | | | expected `async` closure body, found `()` | - = note: expected `async` closure body `{static main::{closure#0}::{closure#0}<?7t> upvar_tys=?15t witness=?6t}` + = note: expected `async` closure body `{static main::{closure#0}::{closure#0}<?17t> upvar_tys=?16t witness=?6t}` found unit type `()` error: aborting due to 1 previous error diff --git a/tests/ui/async-await/async-fn/dyn-pos.rs b/tests/ui/async-await/async-fn/dyn-pos.rs index e817a1b518f..772c7d15cfd 100644 --- a/tests/ui/async-await/async-fn/dyn-pos.rs +++ b/tests/ui/async-await/async-fn/dyn-pos.rs @@ -4,9 +4,6 @@ fn foo(x: &dyn async Fn()) {} //~^ ERROR the trait `AsyncFn` cannot be made into an object -//~| ERROR the trait `AsyncFn` cannot be made into an object -//~| ERROR the trait `AsyncFn` cannot be made into an object -//~| ERROR the trait `AsyncFn` cannot be made into an object //~| ERROR the trait `AsyncFnMut` cannot be made into an object //~| ERROR the trait `AsyncFnMut` cannot be made into an object //~| ERROR the trait `AsyncFnMut` cannot be made into an object diff --git a/tests/ui/async-await/async-fn/dyn-pos.stderr b/tests/ui/async-await/async-fn/dyn-pos.stderr index 488c5d06938..3bef5a27897 100644 --- a/tests/ui/async-await/async-fn/dyn-pos.stderr +++ b/tests/ui/async-await/async-fn/dyn-pos.stderr @@ -1,17 +1,3 @@ -error[E0038]: the trait `AsyncFn` cannot be made into an object - --> $DIR/dyn-pos.rs:5:16 - | -LL | fn foo(x: &dyn async Fn()) {} - | ^^^^^^^^^^ `AsyncFn` cannot be made into an object - | -note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> - --> $SRC_DIR/core/src/ops/async_function.rs:LL:COL - | - = note: the trait cannot be made into an object because it contains the generic associated type `CallFuture` - = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `AsyncFn` for this new enum and using it instead: - &F - std::boxed::Box<F, A> - error[E0038]: the trait `AsyncFnMut` cannot be made into an object --> $DIR/dyn-pos.rs:5:16 | @@ -21,27 +7,12 @@ LL | fn foo(x: &dyn async Fn()) {} note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> --> $SRC_DIR/core/src/ops/async_function.rs:LL:COL | - = note: the trait cannot be made into an object because it contains the generic associated type `CallMutFuture` + = note: the trait cannot be made into an object because it contains the generic associated type `CallRefFuture` = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `AsyncFnMut` for this new enum and using it instead: &F &mut F std::boxed::Box<F, A> -error[E0038]: the trait `AsyncFn` cannot be made into an object - --> $DIR/dyn-pos.rs:5:16 - | -LL | fn foo(x: &dyn async Fn()) {} - | ^^^^^^^^^^ `AsyncFn` cannot be made into an object - | -note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> - --> $SRC_DIR/core/src/ops/async_function.rs:LL:COL - | - = note: the trait cannot be made into an object because it contains the generic associated type `CallFuture` - = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `AsyncFn` for this new enum and using it instead: - &F - std::boxed::Box<F, A> - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error[E0038]: the trait `AsyncFnMut` cannot be made into an object --> $DIR/dyn-pos.rs:5:16 | @@ -51,28 +22,13 @@ LL | fn foo(x: &dyn async Fn()) {} note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> --> $SRC_DIR/core/src/ops/async_function.rs:LL:COL | - = note: the trait cannot be made into an object because it contains the generic associated type `CallMutFuture` + = note: the trait cannot be made into an object because it contains the generic associated type `CallRefFuture` = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `AsyncFnMut` for this new enum and using it instead: &F &mut F std::boxed::Box<F, A> = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error[E0038]: the trait `AsyncFn` cannot be made into an object - --> $DIR/dyn-pos.rs:5:16 - | -LL | fn foo(x: &dyn async Fn()) {} - | ^^^^^^^^^^ `AsyncFn` cannot be made into an object - | -note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> - --> $SRC_DIR/core/src/ops/async_function.rs:LL:COL - | - = note: the trait cannot be made into an object because it contains the generic associated type `CallFuture` - = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `AsyncFn` for this new enum and using it instead: - &F - std::boxed::Box<F, A> - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error[E0038]: the trait `AsyncFnMut` cannot be made into an object --> $DIR/dyn-pos.rs:5:16 | @@ -82,7 +38,7 @@ LL | fn foo(x: &dyn async Fn()) {} note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> --> $SRC_DIR/core/src/ops/async_function.rs:LL:COL | - = note: the trait cannot be made into an object because it contains the generic associated type `CallMutFuture` + = note: the trait cannot be made into an object because it contains the generic associated type `CallRefFuture` = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `AsyncFnMut` for this new enum and using it instead: &F &mut F @@ -98,14 +54,11 @@ LL | fn foo(x: &dyn async Fn()) {} note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> --> $SRC_DIR/core/src/ops/async_function.rs:LL:COL | - = note: the trait cannot be made into an object because it contains the generic associated type `CallFuture` - ::: $SRC_DIR/core/src/ops/async_function.rs:LL:COL - | - = note: the trait cannot be made into an object because it contains the generic associated type `CallMutFuture` + = note: the trait cannot be made into an object because it contains the generic associated type `CallRefFuture` = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `AsyncFn` for this new enum and using it instead: &F std::boxed::Box<F, A> -error: aborting due to 7 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/async-await/in-trait/async-example-desugared-boxed.stderr b/tests/ui/async-await/in-trait/async-example-desugared-boxed.stderr index 54aba77cc05..36f90c7bcd5 100644 --- a/tests/ui/async-await/in-trait/async-example-desugared-boxed.stderr +++ b/tests/ui/async-await/in-trait/async-example-desugared-boxed.stderr @@ -8,11 +8,13 @@ LL | fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information note: the lint level is defined here --> $DIR/async-example-desugared-boxed.rs:13:12 | LL | #[warn(refining_impl_trait)] | ^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(refining_impl_trait_reachable)]` implied by `#[warn(refining_impl_trait)]` help: replace the return type so that it matches the trait | LL | fn foo(&self) -> impl Future<Output = i32> { diff --git a/tests/ui/async-await/in-trait/async-example-desugared-manual.stderr b/tests/ui/async-await/in-trait/async-example-desugared-manual.stderr index d94afd92c56..8e39559071f 100644 --- a/tests/ui/async-await/in-trait/async-example-desugared-manual.stderr +++ b/tests/ui/async-await/in-trait/async-example-desugared-manual.stderr @@ -8,11 +8,13 @@ LL | fn foo(&self) -> MyFuture { | ^^^^^^^^ | = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information note: the lint level is defined here --> $DIR/async-example-desugared-manual.rs:21:12 | LL | #[warn(refining_impl_trait)] | ^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(refining_impl_trait_reachable)]` implied by `#[warn(refining_impl_trait)]` help: replace the return type so that it matches the trait | LL | fn foo(&self) -> impl Future<Output = i32> { diff --git a/tests/ui/async-await/in-trait/return-not-existing-pair.rs b/tests/ui/async-await/in-trait/return-not-existing-pair.rs index 68be1358f81..3889efe1f2a 100644 --- a/tests/ui/async-await/in-trait/return-not-existing-pair.rs +++ b/tests/ui/async-await/in-trait/return-not-existing-pair.rs @@ -9,8 +9,7 @@ trait MyTrait<'a, 'b, T> { impl<'a, 'b, T, U> MyTrait<T> for U { //~^ ERROR: implicit elided lifetime not allowed here [E0726] async fn foo(_: T) -> (&'a U, &'b T) {} - //~^ ERROR: method `foo` has a `&self` declaration in the trait, but not in the impl [E0186] - //~| ERROR: mismatched types [E0308] + //~^ ERROR: mismatched types [E0308] } fn main() {} diff --git a/tests/ui/async-await/in-trait/return-not-existing-pair.stderr b/tests/ui/async-await/in-trait/return-not-existing-pair.stderr index 4694e608097..13d3606abba 100644 --- a/tests/ui/async-await/in-trait/return-not-existing-pair.stderr +++ b/tests/ui/async-await/in-trait/return-not-existing-pair.stderr @@ -15,15 +15,6 @@ error[E0412]: cannot find type `ConnImpl` in this scope LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T); | ^^^^^^^^ not found in this scope -error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl - --> $DIR/return-not-existing-pair.rs:11:5 - | -LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T); - | ------------------------------------------------------------ `&self` used in trait -... -LL | async fn foo(_: T) -> (&'a U, &'b T) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&self` in impl - error[E0308]: mismatched types --> $DIR/return-not-existing-pair.rs:11:42 | @@ -33,7 +24,7 @@ LL | async fn foo(_: T) -> (&'a U, &'b T) {} = note: expected tuple `(&'a U, &'b T)` found unit type `()` -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0186, E0308, E0412, E0726. -For more information about an error, try `rustc --explain E0186`. +Some errors have detailed explanations: E0308, E0412, E0726. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/async-await/in-trait/unconstrained-impl-region.rs b/tests/ui/async-await/in-trait/unconstrained-impl-region.rs index 9382c232364..95ba1f3f277 100644 --- a/tests/ui/async-await/in-trait/unconstrained-impl-region.rs +++ b/tests/ui/async-await/in-trait/unconstrained-impl-region.rs @@ -14,6 +14,7 @@ impl<'a> Actor for () { //~^ ERROR the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates type Message = &'a (); async fn on_mount(self, _: impl Inbox<&'a ()>) {} + //~^ ERROR the trait bound `impl Inbox<&'a ()>: Inbox<&'a ()>` is not satisfied } fn main() {} diff --git a/tests/ui/async-await/in-trait/unconstrained-impl-region.stderr b/tests/ui/async-await/in-trait/unconstrained-impl-region.stderr index ef7e4ef0eb8..66819d1fcf7 100644 --- a/tests/ui/async-await/in-trait/unconstrained-impl-region.stderr +++ b/tests/ui/async-await/in-trait/unconstrained-impl-region.stderr @@ -1,9 +1,26 @@ +error[E0277]: the trait bound `impl Inbox<&'a ()>: Inbox<&'a ()>` is not satisfied + --> $DIR/unconstrained-impl-region.rs:16:5 + | +LL | async fn on_mount(self, _: impl Inbox<&'a ()>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Inbox<&'a ()>` is not implemented for `impl Inbox<&'a ()>` + | +note: required by a bound in `<() as Actor>::on_mount` + --> $DIR/unconstrained-impl-region.rs:16:37 + | +LL | async fn on_mount(self, _: impl Inbox<&'a ()>) {} + | ^^^^^^^^^^^^^ required by this bound in `<() as Actor>::on_mount` +help: consider further restricting this bound + | +LL | async fn on_mount(self, _: impl Inbox<&'a ()> + Inbox<&'a ()>) {} + | +++++++++++++++ + error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates --> $DIR/unconstrained-impl-region.rs:13:6 | LL | impl<'a> Actor for () { | ^^ unconstrained lifetime parameter -error: aborting due to 1 previous error +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0207`. +Some errors have detailed explanations: E0207, E0277. +For more information about an error, try `rustc --explain E0207`. diff --git a/tests/ui/async-await/issue-68112.stderr b/tests/ui/async-await/issue-68112.stderr index f92ac5dd0bc..96fc1633cc9 100644 --- a/tests/ui/async-await/issue-68112.stderr +++ b/tests/ui/async-await/issue-68112.stderr @@ -58,7 +58,6 @@ note: required because it appears within the type `impl Future<Output = Arc<RefC | LL | fn make_non_send_future2() -> impl Future<Output = Arc<RefCell<i32>>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: required because it captures the following types: `impl Future<Output = Arc<RefCell<i32>>>`, `Ready<i32>` note: required because it's used within this `async` block --> $DIR/issue-68112.rs:57:20 | diff --git a/tests/ui/async-await/issue-70935-complex-spans.stderr b/tests/ui/async-await/issue-70935-complex-spans.stderr index 8dc3f476ec8..85c0c0c3088 100644 --- a/tests/ui/async-await/issue-70935-complex-spans.stderr +++ b/tests/ui/async-await/issue-70935-complex-spans.stderr @@ -25,7 +25,6 @@ LL | async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> { | ___________________________________________________________________^ LL | | } | |_^ - = note: required because it captures the following types: `impl Future<Output = ()>` note: required because it's used within this `async` block --> $DIR/issue-70935-complex-spans.rs:18:5 | @@ -63,7 +62,6 @@ LL | async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> { | ___________________________________________________________________^ LL | | } | |_^ - = note: required because it captures the following types: `impl Future<Output = ()>` note: required because it's used within this `async` block --> $DIR/issue-70935-complex-spans.rs:18:5 | diff --git a/tests/ui/async-await/issues/issue-65159.rs b/tests/ui/async-await/issues/issue-65159.rs index 781f8fe88d4..78492d55fda 100644 --- a/tests/ui/async-await/issues/issue-65159.rs +++ b/tests/ui/async-await/issues/issue-65159.rs @@ -4,6 +4,7 @@ async fn copy() -> Result<()> //~^ ERROR enum takes 2 generic arguments +//~| ERROR enum takes 2 generic arguments { Ok(()) } diff --git a/tests/ui/async-await/issues/issue-65159.stderr b/tests/ui/async-await/issues/issue-65159.stderr index 19512116a66..834927060b1 100644 --- a/tests/ui/async-await/issues/issue-65159.stderr +++ b/tests/ui/async-await/issues/issue-65159.stderr @@ -11,6 +11,20 @@ help: add missing generic argument LL | async fn copy() -> Result<(), E> | +++ -error: aborting due to 1 previous error +error[E0107]: enum takes 2 generic arguments but 1 generic argument was supplied + --> $DIR/issue-65159.rs:5:20 + | +LL | async fn copy() -> Result<()> + | ^^^^^^ -- supplied 1 generic argument + | | + | expected 2 generic arguments + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: add missing generic argument + | +LL | async fn copy() -> Result<(), E> + | +++ + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0107`. diff --git a/tests/ui/async-await/issues/issue-67893.stderr b/tests/ui/async-await/issues/issue-67893.stderr index 12bbfc12552..0c28aea44bb 100644 --- a/tests/ui/async-await/issues/issue-67893.stderr +++ b/tests/ui/async-await/issues/issue-67893.stderr @@ -12,7 +12,6 @@ LL | pub async fn run() { | ------------------ within this `impl Future<Output = ()>` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `MutexGuard<'_, ()>`, which is required by `impl Future<Output = ()>: Send` - = note: required because it captures the following types: `Arc<Mutex<()>>`, `MutexGuard<'_, ()>`, `impl Future<Output = ()>` note: required because it's used within this `async` fn body --> $DIR/auxiliary/issue_67893.rs:9:20 | diff --git a/tests/ui/async-await/partial-drop-partial-reinit.rs b/tests/ui/async-await/partial-drop-partial-reinit.rs index 36b3f2bc9ff..b72552ed324 100644 --- a/tests/ui/async-await/partial-drop-partial-reinit.rs +++ b/tests/ui/async-await/partial-drop-partial-reinit.rs @@ -8,7 +8,6 @@ fn main() { //~| NOTE cannot be sent //~| NOTE bound introduced by //~| NOTE appears within the type - //~| NOTE captures the following types } fn gimme_send<T: Send>(t: T) { diff --git a/tests/ui/async-await/partial-drop-partial-reinit.stderr b/tests/ui/async-await/partial-drop-partial-reinit.stderr index a6140c6db82..0bd7d50b941 100644 --- a/tests/ui/async-await/partial-drop-partial-reinit.stderr +++ b/tests/ui/async-await/partial-drop-partial-reinit.stderr @@ -11,9 +11,8 @@ LL | async fn foo() { | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `NotSend`, which is required by `impl Future<Output = ()>: Send` = note: required because it appears within the type `(NotSend,)` - = note: required because it captures the following types: `(NotSend,)`, `impl Future<Output = ()>` note: required because it's used within this `async` fn body - --> $DIR/partial-drop-partial-reinit.rs:28:16 + --> $DIR/partial-drop-partial-reinit.rs:27:16 | LL | async fn foo() { | ________________^ @@ -25,7 +24,7 @@ LL | | bar().await; LL | | } | |_^ note: required by a bound in `gimme_send` - --> $DIR/partial-drop-partial-reinit.rs:14:18 + --> $DIR/partial-drop-partial-reinit.rs:13:18 | LL | fn gimme_send<T: Send>(t: T) { | ^^^^ required by this bound in `gimme_send` diff --git a/tests/ui/async-await/send-bound-async-closure.rs b/tests/ui/async-await/send-bound-async-closure.rs index 2732fa5d466..e4a9ae4cc75 100644 --- a/tests/ui/async-await/send-bound-async-closure.rs +++ b/tests/ui/async-await/send-bound-async-closure.rs @@ -1,5 +1,8 @@ //@ edition: 2021 //@ check-pass +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) +//@[next] compile-flags: -Znext-solver // This test verifies that we do not create a query cycle when typechecking has several inference // variables that point to the same coroutine interior type. diff --git a/tests/ui/attributes/validation-on-associated-items-issue-121537.rs b/tests/ui/attributes/validation-on-associated-items-issue-121537.rs new file mode 100644 index 00000000000..60e5a21eec7 --- /dev/null +++ b/tests/ui/attributes/validation-on-associated-items-issue-121537.rs @@ -0,0 +1,7 @@ +trait MyTrait { + #[doc = MyTrait] + //~^ ERROR attribute value must be a literal + fn myfun(); +} + +fn main() {} diff --git a/tests/ui/attributes/validation-on-associated-items-issue-121537.stderr b/tests/ui/attributes/validation-on-associated-items-issue-121537.stderr new file mode 100644 index 00000000000..9c37bb82317 --- /dev/null +++ b/tests/ui/attributes/validation-on-associated-items-issue-121537.stderr @@ -0,0 +1,8 @@ +error: attribute value must be a literal + --> $DIR/validation-on-associated-items-issue-121537.rs:2:13 + | +LL | #[doc = MyTrait] + | ^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/borrowck/clone-on-ref.fixed b/tests/ui/borrowck/clone-on-ref.fixed new file mode 100644 index 00000000000..b6927ba590e --- /dev/null +++ b/tests/ui/borrowck/clone-on-ref.fixed @@ -0,0 +1,32 @@ +//@ run-rustfix +fn foo<T: Default + Clone>(list: &mut Vec<T>) { + let mut cloned_items = Vec::new(); + for v in list.iter() { + cloned_items.push(v.clone()) + } + list.push(T::default()); + //~^ ERROR cannot borrow `*list` as mutable because it is also borrowed as immutable + drop(cloned_items); +} +fn bar<T: std::fmt::Display + Clone>(x: T) { + let a = &x; + let b = a.clone(); + drop(x); + //~^ ERROR cannot move out of `x` because it is borrowed + println!("{b}"); +} +#[derive(Debug)] +#[derive(Clone)] +struct A; +fn qux(x: A) { + let a = &x; + let b = a.clone(); + drop(x); + //~^ ERROR cannot move out of `x` because it is borrowed + println!("{b:?}"); +} +fn main() { + foo(&mut vec![1, 2, 3]); + bar(""); + qux(A); +} diff --git a/tests/ui/borrowck/clone-on-ref.rs b/tests/ui/borrowck/clone-on-ref.rs new file mode 100644 index 00000000000..f8c94d3cce3 --- /dev/null +++ b/tests/ui/borrowck/clone-on-ref.rs @@ -0,0 +1,31 @@ +//@ run-rustfix +fn foo<T: Default>(list: &mut Vec<T>) { + let mut cloned_items = Vec::new(); + for v in list.iter() { + cloned_items.push(v.clone()) + } + list.push(T::default()); + //~^ ERROR cannot borrow `*list` as mutable because it is also borrowed as immutable + drop(cloned_items); +} +fn bar<T: std::fmt::Display>(x: T) { + let a = &x; + let b = a.clone(); + drop(x); + //~^ ERROR cannot move out of `x` because it is borrowed + println!("{b}"); +} +#[derive(Debug)] +struct A; +fn qux(x: A) { + let a = &x; + let b = a.clone(); + drop(x); + //~^ ERROR cannot move out of `x` because it is borrowed + println!("{b:?}"); +} +fn main() { + foo(&mut vec![1, 2, 3]); + bar(""); + qux(A); +} diff --git a/tests/ui/borrowck/clone-on-ref.stderr b/tests/ui/borrowck/clone-on-ref.stderr new file mode 100644 index 00000000000..ee4fcadf55a --- /dev/null +++ b/tests/ui/borrowck/clone-on-ref.stderr @@ -0,0 +1,64 @@ +error[E0502]: cannot borrow `*list` as mutable because it is also borrowed as immutable + --> $DIR/clone-on-ref.rs:7:5 + | +LL | for v in list.iter() { + | ---- immutable borrow occurs here +LL | cloned_items.push(v.clone()) + | ------- this call doesn't do anything, the result is still `&T` because `T` doesn't implement `Clone` +LL | } +LL | list.push(T::default()); + | ^^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here +LL | +LL | drop(cloned_items); + | ------------ immutable borrow later used here + | +help: consider further restricting this bound + | +LL | fn foo<T: Default + Clone>(list: &mut Vec<T>) { + | +++++++ + +error[E0505]: cannot move out of `x` because it is borrowed + --> $DIR/clone-on-ref.rs:14:10 + | +LL | fn bar<T: std::fmt::Display>(x: T) { + | - binding `x` declared here +LL | let a = &x; + | -- borrow of `x` occurs here +LL | let b = a.clone(); + | ------- this call doesn't do anything, the result is still `&T` because `T` doesn't implement `Clone` +LL | drop(x); + | ^ move out of `x` occurs here +LL | +LL | println!("{b}"); + | --- borrow later used here + | +help: consider further restricting this bound + | +LL | fn bar<T: std::fmt::Display + Clone>(x: T) { + | +++++++ + +error[E0505]: cannot move out of `x` because it is borrowed + --> $DIR/clone-on-ref.rs:23:10 + | +LL | fn qux(x: A) { + | - binding `x` declared here +LL | let a = &x; + | -- borrow of `x` occurs here +LL | let b = a.clone(); + | ------- this call doesn't do anything, the result is still `&A` because `A` doesn't implement `Clone` +LL | drop(x); + | ^ move out of `x` occurs here +LL | +LL | println!("{b:?}"); + | ----- borrow later used here + | +help: consider annotating `A` with `#[derive(Clone)]` + | +LL + #[derive(Clone)] +LL | struct A; + | + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0502, E0505. +For more information about an error, try `rustc --explain E0502`. diff --git a/tests/ui/borrowck/ice-mutability-error-slicing-121807.rs b/tests/ui/borrowck/ice-mutability-error-slicing-121807.rs new file mode 100644 index 00000000000..bbdd895d763 --- /dev/null +++ b/tests/ui/borrowck/ice-mutability-error-slicing-121807.rs @@ -0,0 +1,27 @@ +//@ edition:2015 +// test for ICE #121807 begin <= end (12 <= 11) when slicing 'Self::Assoc<'_>' +// fixed by #122749 + +trait MemoryUnit { // ERROR: not all trait items implemented, missing: `read_word` + extern "C" fn read_word(&mut self) -> u8; + extern "C" fn read_dword(Self::Assoc<'_>) -> u16; + //~^ WARN anonymous parameters are deprecated and will be removed in the next edition + //~^^ WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + //~^^^ ERROR associated type `Assoc` not found for `Self` +} + +struct ROM {} + +impl MemoryUnit for ROM { +//~^ ERROR not all trait items implemented, missing: `read_word` + extern "C" fn read_dword(&'s self) -> u16 { + //~^ ERROR use of undeclared lifetime name `'s` + //~^^ ERROR method `read_dword` has a `&self` declaration in the impl, but not in the trait + let a16 = self.read_word() as u16; + let b16 = self.read_word() as u16; + + (b16 << 8) | a16 + } +} + +pub fn main() {} diff --git a/tests/ui/borrowck/ice-mutability-error-slicing-121807.stderr b/tests/ui/borrowck/ice-mutability-error-slicing-121807.stderr new file mode 100644 index 00000000000..3a6b8008fce --- /dev/null +++ b/tests/ui/borrowck/ice-mutability-error-slicing-121807.stderr @@ -0,0 +1,53 @@ +error[E0261]: use of undeclared lifetime name `'s` + --> $DIR/ice-mutability-error-slicing-121807.rs:17:31 + | +LL | extern "C" fn read_dword(&'s self) -> u16 { + | ^^ undeclared lifetime + | +help: consider introducing lifetime `'s` here + | +LL | extern "C" fn read_dword<'s>(&'s self) -> u16 { + | ++++ +help: consider introducing lifetime `'s` here + | +LL | impl<'s> MemoryUnit for ROM { + | ++++ + +warning: anonymous parameters are deprecated and will be removed in the next edition + --> $DIR/ice-mutability-error-slicing-121807.rs:7:30 + | +LL | extern "C" fn read_dword(Self::Assoc<'_>) -> u16; + | ^^^^^^^^^^^^^^^ help: try naming the parameter or explicitly ignoring it: `_: Self::Assoc<'_>` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686> + = note: `#[warn(anonymous_parameters)]` on by default + +error[E0220]: associated type `Assoc` not found for `Self` + --> $DIR/ice-mutability-error-slicing-121807.rs:7:36 + | +LL | extern "C" fn read_dword(Self::Assoc<'_>) -> u16; + | ^^^^^ associated type `Assoc` not found + +error[E0185]: method `read_dword` has a `&self` declaration in the impl, but not in the trait + --> $DIR/ice-mutability-error-slicing-121807.rs:17:5 + | +LL | extern "C" fn read_dword(Self::Assoc<'_>) -> u16; + | ------------------------------------------------- trait method declared without `&self` +... +LL | extern "C" fn read_dword(&'s self) -> u16 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&self` used in impl + +error[E0046]: not all trait items implemented, missing: `read_word` + --> $DIR/ice-mutability-error-slicing-121807.rs:15:1 + | +LL | extern "C" fn read_word(&mut self) -> u8; + | ----------------------------------------- `read_word` from trait +... +LL | impl MemoryUnit for ROM { + | ^^^^^^^^^^^^^^^^^^^^^^^ missing `read_word` in implementation + +error: aborting due to 4 previous errors; 1 warning emitted + +Some errors have detailed explanations: E0046, E0185, E0220, E0261. +For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr b/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr index 4e3bf1d7042..a66281a188d 100644 --- a/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr +++ b/tests/ui/borrowck/issue-109271-pass-self-into-closure.stderr @@ -42,8 +42,7 @@ LL | v.call(|(), this: &mut S| { | | LL | | LL | | -LL | | -LL | | _ = v; +... | LL | | v.set(); | | - first borrow occurs due to use of `v` in closure ... | diff --git a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs index 15be5fb3fac..ebffa237f96 100644 --- a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs +++ b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs @@ -15,7 +15,9 @@ impl MarketMultiplier { async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> { //~^ ERROR struct takes 0 lifetime arguments but 1 lifetime argument was supplied - //~^^ ERROR struct takes 1 generic argument but 0 generic arguments were supplied + //~| ERROR struct takes 1 generic argument but 0 generic arguments were supplied + //~| ERROR struct takes 0 lifetime arguments but 1 lifetime argument was supplied + //~| ERROR struct takes 1 generic argument but 0 generic arguments were supplied LockedMarket(coroutine.lock().unwrap().buy()) } diff --git a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr index 516c1d065e6..c0b6dcd1512 100644 --- a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr +++ b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr @@ -7,7 +7,7 @@ LL | async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> | expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters - --> $DIR/issue-82126-mismatched-subst-and-hir.rs:22:8 + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:24:8 | LL | struct LockedMarket<T>(T); | ^^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> | ^^^^^^^^^^^^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` - --> $DIR/issue-82126-mismatched-subst-and-hir.rs:22:8 + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:24:8 | LL | struct LockedMarket<T>(T); | ^^^^^^^^^^^^ - @@ -28,6 +28,38 @@ help: add missing generic argument LL | async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_, T> { | +++ -error: aborting due to 2 previous errors +error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 + | +LL | async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> { + | ^^^^^^^^^^^^---- help: remove these generics + | | + | expected 0 lifetime arguments + | +note: struct defined here, with 0 lifetime parameters + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:24:8 + | +LL | struct LockedMarket<T>(T); + | ^^^^^^^^^^^^ + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 + | +LL | async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> { + | ^^^^^^^^^^^^ expected 1 generic argument + | +note: struct defined here, with 1 generic parameter: `T` + --> $DIR/issue-82126-mismatched-subst-and-hir.rs:24:8 + | +LL | struct LockedMarket<T>(T); + | ^^^^^^^^^^^^ - + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: add missing generic argument + | +LL | async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_, T> { + | +++ + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0107`. diff --git a/tests/ui/borrowck/mut-borrow-in-loop-2.fixed b/tests/ui/borrowck/mut-borrow-in-loop-2.fixed deleted file mode 100644 index cff3c372cdb..00000000000 --- a/tests/ui/borrowck/mut-borrow-in-loop-2.fixed +++ /dev/null @@ -1,35 +0,0 @@ -//@ run-rustfix -#![allow(dead_code)] - -struct Events<R>(R); - -struct Other; - -pub trait Trait<T> { - fn handle(value: T) -> Self; -} - -// Blanket impl. (If you comment this out, compiler figures out that it -// is passing an `&mut` to a method that must be expecting an `&mut`, -// and injects an auto-reborrow.) -impl<T, U> Trait<U> for T where T: From<U> { - fn handle(_: U) -> Self { unimplemented!() } -} - -impl<'a, R> Trait<&'a mut Events<R>> for Other { - fn handle(_: &'a mut Events<R>) -> Self { unimplemented!() } -} - -fn this_compiles<'a, R>(value: &'a mut Events<R>) { - for _ in 0..3 { - Other::handle(&mut *value); - } -} - -fn this_does_not<'a, R>(value: &'a mut Events<R>) { - for _ in 0..3 { - Other::handle(&mut *value); //~ ERROR use of moved value: `value` - } -} - -fn main() {} diff --git a/tests/ui/borrowck/mut-borrow-in-loop-2.rs b/tests/ui/borrowck/mut-borrow-in-loop-2.rs index ba79b12042f..f530dfca1a3 100644 --- a/tests/ui/borrowck/mut-borrow-in-loop-2.rs +++ b/tests/ui/borrowck/mut-borrow-in-loop-2.rs @@ -1,4 +1,3 @@ -//@ run-rustfix #![allow(dead_code)] struct Events<R>(R); diff --git a/tests/ui/borrowck/mut-borrow-in-loop-2.stderr b/tests/ui/borrowck/mut-borrow-in-loop-2.stderr index 7b9a946f3ca..7a569d1da41 100644 --- a/tests/ui/borrowck/mut-borrow-in-loop-2.stderr +++ b/tests/ui/borrowck/mut-borrow-in-loop-2.stderr @@ -1,5 +1,5 @@ error[E0382]: use of moved value: `value` - --> $DIR/mut-borrow-in-loop-2.rs:31:23 + --> $DIR/mut-borrow-in-loop-2.rs:30:23 | LL | fn this_does_not<'a, R>(value: &'a mut Events<R>) { | ----- move occurs because `value` has type `&mut Events<R>`, which does not implement the `Copy` trait @@ -9,12 +9,18 @@ LL | Other::handle(value); | ^^^^^ value moved here, in previous iteration of loop | note: consider changing this parameter type in function `handle` to borrow instead if owning the value isn't necessary - --> $DIR/mut-borrow-in-loop-2.rs:9:22 + --> $DIR/mut-borrow-in-loop-2.rs:8:22 | LL | fn handle(value: T) -> Self; | ------ ^ this parameter takes ownership of the value | | | in this function +help: consider moving the expression out of the loop so it is only moved once + | +LL ~ let mut value = Other::handle(value); +LL ~ for _ in 0..3 { +LL ~ value; + | help: consider creating a fresh reborrow of `value` here | LL | Other::handle(&mut *value); diff --git a/tests/ui/cast/unsized-union-ice.rs b/tests/ui/cast/unsized-union-ice.rs new file mode 100644 index 00000000000..11aefe57f1d --- /dev/null +++ b/tests/ui/cast/unsized-union-ice.rs @@ -0,0 +1,14 @@ +// Regression test for https://github.com/rust-lang/rust/issues/122581 +// This used to ICE, because the union was unsized and the pointer casting code +// assumed that non-struct ADTs must be sized. + +union Union { + val: std::mem::ManuallyDrop<[u8]>, + //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time +} + +fn cast(ptr: *const ()) -> *const Union { + ptr as _ +} + +fn main() {} diff --git a/tests/ui/cast/unsized-union-ice.stderr b/tests/ui/cast/unsized-union-ice.stderr new file mode 100644 index 00000000000..05f86457829 --- /dev/null +++ b/tests/ui/cast/unsized-union-ice.stderr @@ -0,0 +1,23 @@ +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time + --> $DIR/unsized-union-ice.rs:6:10 + | +LL | val: std::mem::ManuallyDrop<[u8]>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: within `ManuallyDrop<[u8]>`, the trait `Sized` is not implemented for `[u8]`, which is required by `ManuallyDrop<[u8]>: Sized` +note: required because it appears within the type `ManuallyDrop<[u8]>` + --> $SRC_DIR/core/src/mem/manually_drop.rs:LL:COL + = note: no field of a union may have a dynamically sized type + = help: change the field's type to have a statically known size +help: borrowed types always have a statically known size + | +LL | val: &std::mem::ManuallyDrop<[u8]>, + | + +help: the `Box` type always has a statically known size and allocates its contents in the heap + | +LL | val: Box<std::mem::ManuallyDrop<[u8]>>, + | ++++ + + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/cfg/cfg-false-feature.stderr b/tests/ui/cfg/cfg-false-feature.stderr index 9309b59ca59..542aeaf5caf 100644 --- a/tests/ui/cfg/cfg-false-feature.stderr +++ b/tests/ui/cfg/cfg-false-feature.stderr @@ -1,15 +1,3 @@ -warning: trait aliases are experimental - --> $DIR/cfg-false-feature.rs:12:1 - | -LL | trait A = Clone; - | ^^^^^^^^^^^^^^^^ - | - = note: see issue #41517 <https://github.com/rust-lang/rust/issues/41517> for more information - = help: add `#![feature(trait_alias)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = warning: unstable syntax can change at any point in the future, causing a hard error! - = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> - warning: box pattern syntax is experimental --> $DIR/cfg-false-feature.rs:16:9 | @@ -22,5 +10,17 @@ LL | let box _ = Box::new(0); = warning: unstable syntax can change at any point in the future, causing a hard error! = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> +warning: trait aliases are experimental + --> $DIR/cfg-false-feature.rs:12:1 + | +LL | trait A = Clone; + | ^^^^^^^^^^^^^^^^ + | + = note: see issue #41517 <https://github.com/rust-lang/rust/issues/41517> for more information + = help: add `#![feature(trait_alias)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = warning: unstable syntax can change at any point in the future, causing a hard error! + = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> + warning: 2 warnings emitted diff --git a/tests/ui/check-static-values-constraints.stderr b/tests/ui/check-static-values-constraints.stderr index e7532de5647..dee1f2b1210 100644 --- a/tests/ui/check-static-values-constraints.stderr +++ b/tests/ui/check-static-values-constraints.stderr @@ -36,8 +36,11 @@ LL | field2: SafeEnum::Variant4("str".to_string()), | ^^^^^^^^^^^ | = note: calls in statics are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0010]: allocations are not allowed in statics --> $DIR/check-static-values-constraints.rs:96:5 diff --git a/tests/ui/codegen/target-cpus.rs b/tests/ui/codegen/target-cpus.rs index 85a940f9f74..2d46e00f803 100644 --- a/tests/ui/codegen/target-cpus.rs +++ b/tests/ui/codegen/target-cpus.rs @@ -1,4 +1,3 @@ //@ needs-llvm-components: webassembly -//@ min-llvm-version: 17 //@ compile-flags: --print=target-cpus --target=wasm32-unknown-unknown //@ check-pass diff --git a/tests/ui/codemap_tests/huge_multispan_highlight.rs b/tests/ui/codemap_tests/huge_multispan_highlight.rs index 623c59081d0..c2bd393589e 100644 --- a/tests/ui/codemap_tests/huge_multispan_highlight.rs +++ b/tests/ui/codemap_tests/huge_multispan_highlight.rs @@ -1,5 +1,11 @@ +//@ compile-flags: --error-format=human --color=always +//@ ignore-windows +// Temporary until next release: +//@ ignore-stage2 fn main() { - let x = "foo"; + let _ = match true { + true => ( + // last line shown in multispan header @@ -87,5 +93,148 @@ fn main() { - let y = &mut x; //~ ERROR cannot borrow + + ), + false => " + + + + + + + + + + + + + + + + + + + + + + ", + }; + let _ = match true { + true => ( + + 1 // last line shown in multispan header + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ), + false => " + + + 1 last line shown in multispan + + + + + + + + + + + + + + + + + + + + ", + }; } diff --git a/tests/ui/codemap_tests/huge_multispan_highlight.stderr b/tests/ui/codemap_tests/huge_multispan_highlight.stderr deleted file mode 100644 index d2923875c94..00000000000 --- a/tests/ui/codemap_tests/huge_multispan_highlight.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable - --> $DIR/huge_multispan_highlight.rs:90:13 - | -LL | let y = &mut x; - | ^^^^^^ cannot borrow as mutable - | -help: consider changing this to be mutable - | -LL | let mut x = "foo"; - | +++ - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0596`. diff --git a/tests/ui/codemap_tests/huge_multispan_highlight.svg b/tests/ui/codemap_tests/huge_multispan_highlight.svg new file mode 100644 index 00000000000..f26a2bd7275 --- /dev/null +++ b/tests/ui/codemap_tests/huge_multispan_highlight.svg @@ -0,0 +1,116 @@ +<svg width="750px" height="848px" xmlns="http://www.w3.org/2000/svg"> + <style> + .fg { fill: #AAAAAA } + .bg { background: #000000 } + .fg-ansi256-009 { fill: #FF5555 } + .fg-ansi256-012 { fill: #5555FF } + .container { + padding: 0 10px; + line-height: 18px; + } + .bold { font-weight: bold; } + tspan { + font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace; + white-space: pre; + line-height: 18px; + } + </style> + + <rect width="100%" height="100%" y="0" rx="4.5" class="bg" /> + + <text xml:space="preserve" class="container fg"> + <tspan x="10px" y="28px"><tspan class="fg-ansi256-009 bold">error[E0308]</tspan><tspan class="bold">: `match` arms have incompatible types</tspan> +</tspan> + <tspan x="10px" y="46px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">--> </tspan><tspan>$DIR/huge_multispan_highlight.rs:98:18</tspan> +</tspan> + <tspan x="10px" y="64px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan> +</tspan> + <tspan x="10px" y="82px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> let _ = match true {</tspan> +</tspan> + <tspan x="10px" y="100px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">----------</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">`match` arms have incompatible types</tspan> +</tspan> + <tspan x="10px" y="118px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> true => (</tspan> +</tspan> + <tspan x="10px" y="136px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">_________________-</tspan> +</tspan> + <tspan x="10px" y="154px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> // last line shown in multispan header</tspan> +</tspan> + <tspan x="10px" y="172px"><tspan class="fg-ansi256-012 bold">...</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan> +</tspan> + <tspan x="10px" y="190px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan> +</tspan> + <tspan x="10px" y="208px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> ),</tspan> +</tspan> + <tspan x="10px" y="226px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan class="fg-ansi256-012 bold">|_________-</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">this is found to be of type `()`</tspan> +</tspan> + <tspan x="10px" y="244px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> false => "</tspan> +</tspan> + <tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">__________________^</tspan> +</tspan> + <tspan x="10px" y="280px"><tspan class="fg-ansi256-012 bold">...</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan> +</tspan> + <tspan x="10px" y="298px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan> +</tspan> + <tspan x="10px" y="316px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan><tspan> ",</tspan> +</tspan> + <tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan class="fg-ansi256-009 bold">|_________^</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">expected `()`, found `&str`</tspan> +</tspan> + <tspan x="10px" y="352px"> +</tspan> + <tspan x="10px" y="370px"><tspan class="fg-ansi256-009 bold">error[E0308]</tspan><tspan class="bold">: `match` arms have incompatible types</tspan> +</tspan> + <tspan x="10px" y="388px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">--> </tspan><tspan>$DIR/huge_multispan_highlight.rs:215:18</tspan> +</tspan> + <tspan x="10px" y="406px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan> +</tspan> + <tspan x="10px" y="424px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> let _ = match true {</tspan> +</tspan> + <tspan x="10px" y="442px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">----------</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">`match` arms have incompatible types</tspan> +</tspan> + <tspan x="10px" y="460px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> true => (</tspan> +</tspan> + <tspan x="10px" y="478px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">_________________-</tspan> +</tspan> + <tspan x="10px" y="496px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan> +</tspan> + <tspan x="10px" y="514px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> 1 // last line shown in multispan header</tspan> +</tspan> + <tspan x="10px" y="532px"><tspan class="fg-ansi256-012 bold">...</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan> +</tspan> + <tspan x="10px" y="550px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan> +</tspan> + <tspan x="10px" y="568px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> ),</tspan> +</tspan> + <tspan x="10px" y="586px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan class="fg-ansi256-012 bold">|_________-</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">this is found to be of type `{integer}`</tspan> +</tspan> + <tspan x="10px" y="604px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> false => "</tspan> +</tspan> + <tspan x="10px" y="622px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">__________________^</tspan> +</tspan> + <tspan x="10px" y="640px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan> +</tspan> + <tspan x="10px" y="658px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan> +</tspan> + <tspan x="10px" y="676px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan><tspan> 1 last line shown in multispan</tspan> +</tspan> + <tspan x="10px" y="694px"><tspan class="fg-ansi256-012 bold">...</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan> +</tspan> + <tspan x="10px" y="712px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan> +</tspan> + <tspan x="10px" y="730px"><tspan class="fg-ansi256-012 bold">LL</tspan><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">|</tspan><tspan> ",</tspan> +</tspan> + <tspan x="10px" y="748px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">| </tspan><tspan class="fg-ansi256-009 bold">|_________^</tspan><tspan> </tspan><tspan class="fg-ansi256-009 bold">expected integer, found `&str`</tspan> +</tspan> + <tspan x="10px" y="766px"> +</tspan> + <tspan x="10px" y="784px"><tspan class="fg-ansi256-009 bold">error</tspan><tspan class="bold">: aborting due to 2 previous errors</tspan> +</tspan> + <tspan x="10px" y="802px"> +</tspan> + <tspan x="10px" y="820px"><tspan class="bold">For more information about this error, try `rustc --explain E0308`.</tspan> +</tspan> + <tspan x="10px" y="838px"> +</tspan> + </text> + +</svg> diff --git a/tests/ui/coherence/occurs-check/associated-type.next.stderr b/tests/ui/coherence/occurs-check/associated-type.next.stderr index 50b83b90b0b..7443459b830 100644 --- a/tests/ui/coherence/occurs-check/associated-type.next.stderr +++ b/tests/ui/coherence/occurs-check/associated-type.next.stderr @@ -1,7 +1,7 @@ -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), ())>` for type `for<'a> fn(&'a (), ())` --> $DIR/associated-type.rs:31:1 | diff --git a/tests/ui/coherence/occurs-check/associated-type.old.stderr b/tests/ui/coherence/occurs-check/associated-type.old.stderr index 655809b827e..38a02c906d4 100644 --- a/tests/ui/coherence/occurs-check/associated-type.old.stderr +++ b/tests/ui/coherence/occurs-check/associated-type.old.stderr @@ -1,11 +1,11 @@ -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, RePlaceholder(!2_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, RePlaceholder(!2_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, RePlaceholder(!2_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, RePlaceholder(!2_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, !2_0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, !2_0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, !2_0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, !2_0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), "'a")], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) } error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), _)>` for type `for<'a> fn(&'a (), _)` --> $DIR/associated-type.rs:31:1 | diff --git a/tests/ui/compiletest-self-test/auxiliary/print-it-works.rs b/tests/ui/compiletest-self-test/auxiliary/print-it-works.rs new file mode 100644 index 00000000000..09411eb121c --- /dev/null +++ b/tests/ui/compiletest-self-test/auxiliary/print-it-works.rs @@ -0,0 +1,3 @@ +fn main() { + println!("it works"); +} diff --git a/tests/ui/compiletest-self-test/test-aux-bin.rs b/tests/ui/compiletest-self-test/test-aux-bin.rs new file mode 100644 index 00000000000..9e01e3ffabf --- /dev/null +++ b/tests/ui/compiletest-self-test/test-aux-bin.rs @@ -0,0 +1,9 @@ +//@ ignore-cross-compile because we run the compiled code +//@ aux-bin: print-it-works.rs +//@ run-pass + +fn main() { + let stdout = + std::process::Command::new("auxiliary/bin/print-it-works").output().unwrap().stdout; + assert_eq!(stdout, b"it works\n"); +} diff --git a/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.rs b/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.rs index a83830178d4..0d2e65c45ea 100644 --- a/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.rs +++ b/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.rs @@ -5,11 +5,16 @@ // Can never be used as const generics. fn uwu_0<const N: &'static mut ()>() {} //~^ ERROR: forbidden as the type of a const generic +//~| HELP: add `#![feature(adt_const_params)]` +//~| HELP: add `#![feature(adt_const_params)]` +//~| HELP: add `#![feature(adt_const_params)]` +//~| HELP: add `#![feature(adt_const_params)]` +//~| HELP: add `#![feature(adt_const_params)]` +//~| HELP: add `#![feature(adt_const_params)]` // Needs the feature but can be used, so suggest adding the feature. fn owo_0<const N: &'static u32>() {} //~^ ERROR: forbidden as the type of a const generic -//~^^ HELP: add `#![feature(adt_const_params)]` // Can only be used in const generics with changes. struct Meow { @@ -18,22 +23,17 @@ struct Meow { fn meow_0<const N: Meow>() {} //~^ ERROR: forbidden as the type of a const generic -//~^^ HELP: add `#![feature(adt_const_params)]` fn meow_1<const N: &'static Meow>() {} //~^ ERROR: forbidden as the type of a const generic -//~^^ HELP: add `#![feature(adt_const_params)]` fn meow_2<const N: [Meow; 100]>() {} //~^ ERROR: forbidden as the type of a const generic -//~^^ HELP: add `#![feature(adt_const_params)]` fn meow_3<const N: (Meow, u8)>() {} //~^ ERROR: forbidden as the type of a const generic -//~^^ HELP: add `#![feature(adt_const_params)]` // This is suboptimal that it thinks it can be used // but better to suggest the feature to the user. fn meow_4<const N: (Meow, String)>() {} //~^ ERROR: forbidden as the type of a const generic -//~^^ HELP: add `#![feature(adt_const_params)]` // Non-local ADT that does not impl `ConstParamTy` fn nya_0<const N: String>() {} diff --git a/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr b/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr index 04527e3158e..cd4349623d7 100644 --- a/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr +++ b/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr @@ -7,58 +7,76 @@ LL | fn uwu_0<const N: &'static mut ()>() {} = note: the only supported types are integers, `bool` and `char` error: `&'static u32` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:10:19 + --> $DIR/suggest_feature_only_when_possible.rs:16:19 | LL | fn owo_0<const N: &'static u32>() {} | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `Meow` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:19:20 + --> $DIR/suggest_feature_only_when_possible.rs:24:20 | LL | fn meow_0<const N: Meow>() {} | ^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `&'static Meow` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:22:20 + --> $DIR/suggest_feature_only_when_possible.rs:26:20 | LL | fn meow_1<const N: &'static Meow>() {} | ^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `[Meow; 100]` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:25:20 + --> $DIR/suggest_feature_only_when_possible.rs:28:20 | LL | fn meow_2<const N: [Meow; 100]>() {} | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `(Meow, u8)` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:28:20 + --> $DIR/suggest_feature_only_when_possible.rs:30:20 | LL | fn meow_3<const N: (Meow, u8)>() {} | ^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `(Meow, String)` is forbidden as the type of a const generic parameter - --> $DIR/suggest_feature_only_when_possible.rs:34:20 + --> $DIR/suggest_feature_only_when_possible.rs:35:20 | LL | fn meow_4<const N: (Meow, String)>() {} | ^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `String` is forbidden as the type of a const generic parameter --> $DIR/suggest_feature_only_when_possible.rs:39:19 diff --git a/tests/ui/const-generics/const-param-elided-lifetime.min.stderr b/tests/ui/const-generics/const-param-elided-lifetime.min.stderr index ffe45285988..1c81b14f8f5 100644 --- a/tests/ui/const-generics/const-param-elided-lifetime.min.stderr +++ b/tests/ui/const-generics/const-param-elided-lifetime.min.stderr @@ -35,7 +35,10 @@ LL | struct A<const N: &u8>; | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:14:15 @@ -44,7 +47,10 @@ LL | impl<const N: &u8> A<N> { | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:22:15 @@ -53,7 +59,10 @@ LL | impl<const N: &u8> B for A<N> {} | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:26:17 @@ -62,7 +71,10 @@ LL | fn bar<const N: &u8>() {} | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:17:21 @@ -71,7 +83,10 @@ LL | fn foo<const M: &u8>(&self) {} | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 10 previous errors diff --git a/tests/ui/const-generics/const-param-type-depends-on-const-param.min.stderr b/tests/ui/const-generics/const-param-type-depends-on-const-param.min.stderr index daeeadeed7c..fcc86b9ac33 100644 --- a/tests/ui/const-generics/const-param-type-depends-on-const-param.min.stderr +++ b/tests/ui/const-generics/const-param-type-depends-on-const-param.min.stderr @@ -21,7 +21,10 @@ LL | pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]); | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `[u8; N]` is forbidden as the type of a const generic parameter --> $DIR/const-param-type-depends-on-const-param.rs:15:35 @@ -30,7 +33,10 @@ LL | pub struct SelfDependent<const N: [u8; N]>; | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 4 previous errors diff --git a/tests/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr b/tests/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr index 1f4b892e20f..1f67a5c09f1 100644 --- a/tests/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr +++ b/tests/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr @@ -23,7 +23,10 @@ LL | struct B<const CFG: Config> { | ^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.rs b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.rs index 9cdb4158d2b..e575d0dc9b4 100644 --- a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.rs +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.rs @@ -19,8 +19,8 @@ where //~^^ ERROR: unconstrained generic constant //~^^^ ERROR: function takes 1 generic argument but 2 generic arguments were supplied //~^^^^ ERROR: unconstrained generic constant - //~^^^^^ ERROR: unconstrained generic constant `{const expr}` - //~^^^^^^ ERROR: unconstrained generic constant `{const expr}` + //~^^^^^ ERROR: unconstrained generic constant `L + 1 + L` + //~^^^^^^ ERROR: unconstrained generic constant `L + 1` } fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr index 14c58f8d0da..9a8aa222dc1 100644 --- a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr @@ -52,19 +52,17 @@ LL | | } LL | | }], | |_____^ required by this bound in `foo` -error: unconstrained generic constant `{const expr}` +error: unconstrained generic constant `L + 1 + L` --> $DIR/issue_114151.rs:17:5 | LL | foo::<_, L>([(); L + 1 + L]); | ^^^^^^^^^^^ -error: unconstrained generic constant `{const expr}` +error: unconstrained generic constant `L + 1` --> $DIR/issue_114151.rs:17:5 | LL | foo::<_, L>([(); L + 1 + L]); | ^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 6 previous errors diff --git a/tests/ui/const-generics/generic_const_exprs/ice-generics_of-no-entry-found-for-key-113017.rs b/tests/ui/const-generics/generic_const_exprs/ice-generics_of-no-entry-found-for-key-113017.rs new file mode 100644 index 00000000000..a2f8c876b5e --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/ice-generics_of-no-entry-found-for-key-113017.rs @@ -0,0 +1,13 @@ +// test for ICE "no entry found for key" in generics_of.rs #113017 + +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +pub fn foo() +where + for<const N: usize = { || {}; 1 }> ():, + //~^ ERROR only lifetime parameters can be used in this context + //~^^ ERROR defaults for generic parameters are not allowed in `for<...>` binders +{} + +pub fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/ice-generics_of-no-entry-found-for-key-113017.stderr b/tests/ui/const-generics/generic_const_exprs/ice-generics_of-no-entry-found-for-key-113017.stderr new file mode 100644 index 00000000000..edf27f58efd --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/ice-generics_of-no-entry-found-for-key-113017.stderr @@ -0,0 +1,19 @@ +error[E0658]: only lifetime parameters can be used in this context + --> $DIR/ice-generics_of-no-entry-found-for-key-113017.rs:8:15 + | +LL | for<const N: usize = { || {}; 1 }> ():, + | ^ + | + = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information + = help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: defaults for generic parameters are not allowed in `for<...>` binders + --> $DIR/ice-generics_of-no-entry-found-for-key-113017.rs:8:9 + | +LL | for<const N: usize = { || {}; 1 }> ():, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/const-generics/generic_const_exprs/ice-predicates-of-no-entry-found-for-key-119275.rs b/tests/ui/const-generics/generic_const_exprs/ice-predicates-of-no-entry-found-for-key-119275.rs new file mode 100644 index 00000000000..4ba696f4ae0 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/ice-predicates-of-no-entry-found-for-key-119275.rs @@ -0,0 +1,18 @@ +// test for ICE #119275 "no entry found for key" in predicates_of.rs + +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +fn bug<const N: Nat>(&self) +//~^ ERROR `self` parameter is only allowed in associated functions +//~^^ ERROR cannot find type `Nat` in this scope +where + for<const N: usize = 3, T = u32> [(); COT::BYTES]:, + //~^ ERROR only lifetime parameters can be used in this context + //~^^ ERROR defaults for generic parameters are not allowed in `for<...>` binders + //~^^^ ERROR defaults for generic parameters are not allowed in `for<...>` binders + //~^^^^ ERROR failed to resolve: use of undeclared type `COT` +{ +} + +pub fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/ice-predicates-of-no-entry-found-for-key-119275.stderr b/tests/ui/const-generics/generic_const_exprs/ice-predicates-of-no-entry-found-for-key-119275.stderr new file mode 100644 index 00000000000..ee0ec38ab06 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/ice-predicates-of-no-entry-found-for-key-119275.stderr @@ -0,0 +1,46 @@ +error: `self` parameter is only allowed in associated functions + --> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:6:22 + | +LL | fn bug<const N: Nat>(&self) + | ^^^^^ not semantically valid as function parameter + | + = note: associated functions are those in `impl` or `trait` definitions + +error[E0412]: cannot find type `Nat` in this scope + --> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:6:17 + | +LL | fn bug<const N: Nat>(&self) + | ^^^ not found in this scope + +error[E0658]: only lifetime parameters can be used in this context + --> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:10:15 + | +LL | for<const N: usize = 3, T = u32> [(); COT::BYTES]:, + | ^ ^ + | + = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information + = help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: defaults for generic parameters are not allowed in `for<...>` binders + --> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:10:9 + | +LL | for<const N: usize = 3, T = u32> [(); COT::BYTES]:, + | ^^^^^^^^^^^^^^^^^^ + +error: defaults for generic parameters are not allowed in `for<...>` binders + --> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:10:29 + | +LL | for<const N: usize = 3, T = u32> [(); COT::BYTES]:, + | ^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type `COT` + --> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:10:43 + | +LL | for<const N: usize = 3, T = u32> [(); COT::BYTES]:, + | ^^^ use of undeclared type `COT` + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0412, E0433, E0658. +For more information about an error, try `rustc --explain E0412`. diff --git a/tests/ui/const-generics/generic_const_exprs/issue-109141.rs b/tests/ui/const-generics/generic_const_exprs/issue-109141.rs index 148c3bda8d2..c6dd981cced 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-109141.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-109141.rs @@ -4,6 +4,7 @@ impl EntriesBuffer { fn a(&self) -> impl Iterator { self.0.iter_mut() //~ ERROR: cannot borrow `*self.0` as mutable, as it is behind a `&` reference + //~| ERROR captures lifetime that does not appear in bounds } } diff --git a/tests/ui/const-generics/generic_const_exprs/issue-109141.stderr b/tests/ui/const-generics/generic_const_exprs/issue-109141.stderr index 8b8489ac2bc..7a9572d000d 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-109141.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-109141.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find value `HashesEntryLEN` in this scope - --> $DIR/issue-109141.rs:10:32 + --> $DIR/issue-109141.rs:11:32 | LL | struct EntriesBuffer(Box<[[u8; HashesEntryLEN]; 5]>); | ^^^^^^^^^^^^^^ not found in this scope @@ -20,7 +20,22 @@ help: consider changing this to be a mutable reference LL | fn a(&mut self) -> impl Iterator { | ~~~~~~~~~ -error: aborting due to 2 previous errors +error[E0700]: hidden type for `impl Iterator` captures lifetime that does not appear in bounds + --> $DIR/issue-109141.rs:6:9 + | +LL | fn a(&self) -> impl Iterator { + | ----- ------------- opaque type defined here + | | + | hidden type `std::slice::IterMut<'_, [u8; {const error}]>` captures the anonymous lifetime defined here +LL | self.0.iter_mut() + | ^^^^^^^^^^^^^^^^^ + | +help: to declare that `impl Iterator` captures `'_`, you can add an explicit `'_` lifetime bound + | +LL | fn a(&self) -> impl Iterator + '_ { + | ++++ + +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0425, E0596. +Some errors have detailed explanations: E0425, E0596, E0700. For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/const-generics/generic_const_exprs/unify-op-with-fn-call.stderr b/tests/ui/const-generics/generic_const_exprs/unify-op-with-fn-call.stderr index 77a7da17c13..0bf99bb8b26 100644 --- a/tests/ui/const-generics/generic_const_exprs/unify-op-with-fn-call.stderr +++ b/tests/ui/const-generics/generic_const_exprs/unify-op-with-fn-call.stderr @@ -54,7 +54,10 @@ note: impl defined here, but it is not `const` LL | impl const std::ops::Add for Foo { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: cannot call non-const fn `<Foo as Add>::add` in constants --> $DIR/unify-op-with-fn-call.rs:21:13 @@ -63,7 +66,10 @@ LL | bar::<{ std::ops::Add::add(N, N) }>(); | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: cannot call non-const fn `<usize as Add>::add` in constants --> $DIR/unify-op-with-fn-call.rs:30:14 @@ -72,7 +78,10 @@ LL | bar2::<{ std::ops::Add::add(N, N) }>(); | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 7 previous errors diff --git a/tests/ui/const-generics/ice-unexpected-inference-var-122549.rs b/tests/ui/const-generics/ice-unexpected-inference-var-122549.rs new file mode 100644 index 00000000000..126ea667290 --- /dev/null +++ b/tests/ui/const-generics/ice-unexpected-inference-var-122549.rs @@ -0,0 +1,29 @@ +// Regression test for https://github.com/rust-lang/rust/issues/122549 +// was fixed by https://github.com/rust-lang/rust/pull/122749 + +trait ConstChunksExactTrait<T> { + fn const_chunks_exact<const N: usize>(&self) -> ConstChunksExact<'a, T, { N }>; + //~^ ERROR undeclared lifetime +} + +impl<T> ConstChunksExactTrait<T> for [T] {} +//~^ ERROR not all trait items implemented, missing: `const_chunks_exact` +struct ConstChunksExact<'rem, T: 'a, const N: usize> {} +//~^ ERROR use of undeclared lifetime name `'a` +//~^^ ERROR lifetime parameter +//~^^^ ERROR type parameter +impl<'a, T, const N: usize> Iterator for ConstChunksExact<'a, T, {}> { +//~^ ERROR the const parameter `N` is not constrained by the impl trait, self type, or predicates +//~^^ ERROR mismatched types + type Item = &'a [T; N]; +} + +fn main() { + let slice = &[1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + + let mut iter = [[1, 2, 3], [4, 5, 6], [7, 8, 9]].iter(); + + for a in slice.const_chunks_exact::<3>() { + assert_eq!(a, iter.next().unwrap()); + } +} diff --git a/tests/ui/const-generics/ice-unexpected-inference-var-122549.stderr b/tests/ui/const-generics/ice-unexpected-inference-var-122549.stderr new file mode 100644 index 00000000000..afad3388145 --- /dev/null +++ b/tests/ui/const-generics/ice-unexpected-inference-var-122549.stderr @@ -0,0 +1,67 @@ +error[E0261]: use of undeclared lifetime name `'a` + --> $DIR/ice-unexpected-inference-var-122549.rs:5:70 + | +LL | fn const_chunks_exact<const N: usize>(&self) -> ConstChunksExact<'a, T, { N }>; + | ^^ undeclared lifetime + | +help: consider introducing lifetime `'a` here + | +LL | fn const_chunks_exact<'a, const N: usize>(&self) -> ConstChunksExact<'a, T, { N }>; + | +++ +help: consider introducing lifetime `'a` here + | +LL | trait ConstChunksExactTrait<'a, T> { + | +++ + +error[E0261]: use of undeclared lifetime name `'a` + --> $DIR/ice-unexpected-inference-var-122549.rs:11:34 + | +LL | struct ConstChunksExact<'rem, T: 'a, const N: usize> {} + | - ^^ undeclared lifetime + | | + | help: consider introducing lifetime `'a` here: `'a,` + +error[E0046]: not all trait items implemented, missing: `const_chunks_exact` + --> $DIR/ice-unexpected-inference-var-122549.rs:9:1 + | +LL | fn const_chunks_exact<const N: usize>(&self) -> ConstChunksExact<'a, T, { N }>; + | ------------------------------------------------------------------------------- `const_chunks_exact` from trait +... +LL | impl<T> ConstChunksExactTrait<T> for [T] {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `const_chunks_exact` in implementation + +error[E0392]: lifetime parameter `'rem` is never used + --> $DIR/ice-unexpected-inference-var-122549.rs:11:25 + | +LL | struct ConstChunksExact<'rem, T: 'a, const N: usize> {} + | ^^^^ unused lifetime parameter + | + = help: consider removing `'rem`, referring to it in a field, or using a marker such as `PhantomData` + +error[E0392]: type parameter `T` is never used + --> $DIR/ice-unexpected-inference-var-122549.rs:11:31 + | +LL | struct ConstChunksExact<'rem, T: 'a, const N: usize> {} + | ^ unused type parameter + | + = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + +error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates + --> $DIR/ice-unexpected-inference-var-122549.rs:15:13 + | +LL | impl<'a, T, const N: usize> Iterator for ConstChunksExact<'a, T, {}> { + | ^^^^^^^^^^^^^^ unconstrained const parameter + | + = note: expressions using a const parameter must map each value to a distinct output value + = note: proving the result of expressions other than the parameter are unique is not supported + +error[E0308]: mismatched types + --> $DIR/ice-unexpected-inference-var-122549.rs:15:66 + | +LL | impl<'a, T, const N: usize> Iterator for ConstChunksExact<'a, T, {}> { + | ^^ expected `usize`, found `()` + +error: aborting due to 7 previous errors + +Some errors have detailed explanations: E0046, E0207, E0261, E0308, E0392. +For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr b/tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr index 95f75c32186..5e4acd80e93 100644 --- a/tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr +++ b/tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr @@ -14,7 +14,10 @@ LL | trait Trait<const S: &'static str> {} | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/issue-93647.stderr b/tests/ui/const-generics/issue-93647.stderr index a87b59940cb..81f50a1b517 100644 --- a/tests/ui/const-generics/issue-93647.stderr +++ b/tests/ui/const-generics/issue-93647.stderr @@ -6,7 +6,10 @@ LL | (||1usize)() | = note: closures need an RFC before allowed to be called in constants = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/issues/issue-56445-1.min.stderr b/tests/ui/const-generics/issues/issue-56445-1.min.stderr index fc10aba0fec..580542bb6da 100644 --- a/tests/ui/const-generics/issues/issue-56445-1.min.stderr +++ b/tests/ui/const-generics/issues/issue-56445-1.min.stderr @@ -13,7 +13,10 @@ LL | struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>); | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/issues/issue-62878.min.stderr b/tests/ui/const-generics/issues/issue-62878.min.stderr index 984381d1669..5205726d738 100644 --- a/tests/ui/const-generics/issues/issue-62878.min.stderr +++ b/tests/ui/const-generics/issues/issue-62878.min.stderr @@ -13,7 +13,10 @@ LL | fn foo<const N: usize, const A: [u8; N]>() {} | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error[E0747]: type provided when a constant was expected --> $DIR/issue-62878.rs:10:11 @@ -22,7 +25,10 @@ LL | foo::<_, { [1] }>(); | ^ | = help: const arguments cannot yet be inferred with `_` - = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable +help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable + | +LL + #![feature(generic_arg_infer)] + | error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr index b9588e23e55..7f387cbd5a1 100644 --- a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr +++ b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr @@ -5,7 +5,10 @@ LL | fn test<const T: &'static dyn A>() { | ^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/issues/issue-67185-2.stderr b/tests/ui/const-generics/issues/issue-67185-2.stderr index 24a2d60f2e1..e39d43205c1 100644 --- a/tests/ui/const-generics/issues/issue-67185-2.stderr +++ b/tests/ui/const-generics/issues/issue-67185-2.stderr @@ -8,7 +8,10 @@ LL | <u8 as Baz>::Quaks: Bar, [u16; 4] [[u16; 3]; 3] = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the trait bound `[[u16; 3]; 2]: Bar` is not satisfied --> $DIR/issue-67185-2.rs:14:5 @@ -20,7 +23,10 @@ LL | [<u8 as Baz>::Quaks; 2]: Bar, [u16; 4] [[u16; 3]; 3] = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the trait bound `[u16; 3]: Bar` is not satisfied --> $DIR/issue-67185-2.rs:21:6 diff --git a/tests/ui/const-generics/issues/issue-68366.full.stderr b/tests/ui/const-generics/issues/issue-68366.full.stderr index dc20af77310..3363a895e47 100644 --- a/tests/ui/const-generics/issues/issue-68366.full.stderr +++ b/tests/ui/const-generics/issues/issue-68366.full.stderr @@ -5,7 +5,10 @@ LL | struct Collatz<const N: Option<usize>>; | ^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates --> $DIR/issue-68366.rs:12:7 diff --git a/tests/ui/const-generics/issues/issue-68366.min.stderr b/tests/ui/const-generics/issues/issue-68366.min.stderr index 78e49f46e1a..276f91e76dd 100644 --- a/tests/ui/const-generics/issues/issue-68366.min.stderr +++ b/tests/ui/const-generics/issues/issue-68366.min.stderr @@ -14,7 +14,10 @@ LL | struct Collatz<const N: Option<usize>>; | ^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates --> $DIR/issue-68366.rs:12:7 diff --git a/tests/ui/const-generics/issues/issue-68615-adt.min.stderr b/tests/ui/const-generics/issues/issue-68615-adt.min.stderr index 20962098bff..2f95eef98c0 100644 --- a/tests/ui/const-generics/issues/issue-68615-adt.min.stderr +++ b/tests/ui/const-generics/issues/issue-68615-adt.min.stderr @@ -5,7 +5,10 @@ LL | struct Const<const V: [usize; 0]> {} | ^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/issues/issue-68615-array.min.stderr b/tests/ui/const-generics/issues/issue-68615-array.min.stderr index 8c76f9b5d65..6d18f8195d2 100644 --- a/tests/ui/const-generics/issues/issue-68615-array.min.stderr +++ b/tests/ui/const-generics/issues/issue-68615-array.min.stderr @@ -5,7 +5,10 @@ LL | struct Foo<const V: [usize; 0] > {} | ^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/issues/issue-71169.min.stderr b/tests/ui/const-generics/issues/issue-71169.min.stderr index bba92f32a78..94d11f969ff 100644 --- a/tests/ui/const-generics/issues/issue-71169.min.stderr +++ b/tests/ui/const-generics/issues/issue-71169.min.stderr @@ -13,7 +13,10 @@ LL | fn foo<const LEN: usize, const DATA: [u8; LEN]>() {} | ^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/issues/issue-73491.min.stderr b/tests/ui/const-generics/issues/issue-73491.min.stderr index 64df76756ac..8fdd65894ef 100644 --- a/tests/ui/const-generics/issues/issue-73491.min.stderr +++ b/tests/ui/const-generics/issues/issue-73491.min.stderr @@ -5,7 +5,10 @@ LL | fn hoge<const IN: [u32; LEN]>() {} | ^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr b/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr index 2b33f35defd..e9363d42148 100644 --- a/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr +++ b/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr @@ -5,7 +5,10 @@ LL | fn a<const X: &'static [u32]>() {} | ^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/issues/issue-74101.min.stderr b/tests/ui/const-generics/issues/issue-74101.min.stderr index 7852ce5bcfc..236556addce 100644 --- a/tests/ui/const-generics/issues/issue-74101.min.stderr +++ b/tests/ui/const-generics/issues/issue-74101.min.stderr @@ -5,7 +5,10 @@ LL | fn test<const N: [u8; 1 + 2]>() {} | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `[u8; 1 + 2]` is forbidden as the type of a const generic parameter --> $DIR/issue-74101.rs:9:21 @@ -14,7 +17,10 @@ LL | struct Foo<const N: [u8; 1 + 2]>; | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/issues/issue-74255.min.stderr b/tests/ui/const-generics/issues/issue-74255.min.stderr index 63d8fc12fa4..800902860a7 100644 --- a/tests/ui/const-generics/issues/issue-74255.min.stderr +++ b/tests/ui/const-generics/issues/issue-74255.min.stderr @@ -5,7 +5,10 @@ LL | fn ice_struct_fn<const I: IceEnum>() {} | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/issues/issue-74950.min.stderr b/tests/ui/const-generics/issues/issue-74950.min.stderr index a573dac6087..086176d9959 100644 --- a/tests/ui/const-generics/issues/issue-74950.min.stderr +++ b/tests/ui/const-generics/issues/issue-74950.min.stderr @@ -5,7 +5,10 @@ LL | struct Outer<const I: Inner>; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `Inner` is forbidden as the type of a const generic parameter --> $DIR/issue-74950.rs:19:23 @@ -14,8 +17,11 @@ LL | struct Outer<const I: Inner>; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `Inner` is forbidden as the type of a const generic parameter --> $DIR/issue-74950.rs:19:23 @@ -24,8 +30,11 @@ LL | struct Outer<const I: Inner>; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `Inner` is forbidden as the type of a const generic parameter --> $DIR/issue-74950.rs:19:23 @@ -34,8 +43,11 @@ LL | struct Outer<const I: Inner>; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 4 previous errors diff --git a/tests/ui/const-generics/issues/issue-75047.min.stderr b/tests/ui/const-generics/issues/issue-75047.min.stderr index 1d7ac1b0111..f2cc76b9bed 100644 --- a/tests/ui/const-generics/issues/issue-75047.min.stderr +++ b/tests/ui/const-generics/issues/issue-75047.min.stderr @@ -5,7 +5,10 @@ LL | struct Foo<const N: [u8; Bar::<u32>::value()]>; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/issues/issue-90318.stderr b/tests/ui/const-generics/issues/issue-90318.stderr index 471a6660ce0..a534e8f8d44 100644 --- a/tests/ui/const-generics/issues/issue-90318.stderr +++ b/tests/ui/const-generics/issues/issue-90318.stderr @@ -29,7 +29,10 @@ LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/any.rs:LL:COL = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0015]: cannot call non-const operator in constants --> $DIR/issue-90318.rs:22:10 @@ -40,7 +43,10 @@ LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/any.rs:LL:COL = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 4 previous errors diff --git a/tests/ui/const-generics/late-bound-vars/late-bound-in-return-issue-77357.stderr b/tests/ui/const-generics/late-bound-vars/late-bound-in-return-issue-77357.stderr index e42bb6e8cc5..7bef98b1d5d 100644 --- a/tests/ui/const-generics/late-bound-vars/late-bound-in-return-issue-77357.stderr +++ b/tests/ui/const-generics/late-bound-vars/late-bound-in-return-issue-77357.stderr @@ -4,46 +4,5 @@ error: cannot capture late-bound lifetime in constant LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> { | -- lifetime defined here ^^ -error: overly complex generic constant - --> $DIR/late-bound-in-return-issue-77357.rs:9:46 - | -LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constants - | - = help: consider moving this anonymous constant into a `const` function - = note: this operation may be supported in the future - -error[E0391]: cycle detected when evaluating type-level constant - --> $DIR/late-bound-in-return-issue-77357.rs:9:46 - | -LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: ...which requires const-evaluating + checking `bug::{constant#0}`... - --> $DIR/late-bound-in-return-issue-77357.rs:9:46 - | -LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires caching mir of `bug::{constant#0}` for CTFE... - --> $DIR/late-bound-in-return-issue-77357.rs:9:46 - | -LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires elaborating drops for `bug::{constant#0}`... - --> $DIR/late-bound-in-return-issue-77357.rs:9:46 - | -LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires borrow-checking `bug::{constant#0}`... - --> $DIR/late-bound-in-return-issue-77357.rs:9:46 - | -LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which requires normalizing `Binder { value: ConstEvaluatable(UnevaluatedConst { def: DefId(0:8 ~ late_bound_in_return_issue_77357[9394]::bug::{constant#0}), args: [T/#0] }: usize), bound_vars: [] }`... - = note: ...which again requires evaluating type-level constant, completing the cycle - = note: cycle used when normalizing `&dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]>` - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/const-generics/lifetime-in-const-param.stderr b/tests/ui/const-generics/lifetime-in-const-param.stderr index c2fcdcf1a71..4096725c52a 100644 --- a/tests/ui/const-generics/lifetime-in-const-param.stderr +++ b/tests/ui/const-generics/lifetime-in-const-param.stderr @@ -11,7 +11,10 @@ LL | struct S<'a, const N: S2>(&'a ()); | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/min_const_generics/complex-types.stderr b/tests/ui/const-generics/min_const_generics/complex-types.stderr index 8cc75dbaff9..8e83ea58194 100644 --- a/tests/ui/const-generics/min_const_generics/complex-types.stderr +++ b/tests/ui/const-generics/min_const_generics/complex-types.stderr @@ -5,7 +5,10 @@ LL | struct Foo<const N: [u8; 0]>; | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `()` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:6:21 @@ -14,7 +17,10 @@ LL | struct Bar<const N: ()>; | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `No` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:11:21 @@ -23,7 +29,10 @@ LL | struct Fez<const N: No>; | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `&'static u8` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:14:21 @@ -32,7 +41,10 @@ LL | struct Faz<const N: &'static u8>; | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `!` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:17:21 @@ -49,7 +61,10 @@ LL | enum Goo<const N: ()> { A, B } | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `()` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:23:20 @@ -58,7 +73,10 @@ LL | union Boo<const N: ()> { a: () } | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 7 previous errors diff --git a/tests/ui/const-generics/min_const_generics/macro-fail.rs b/tests/ui/const-generics/min_const_generics/macro-fail.rs index f3df96d468c..2f101ecfb1f 100644 --- a/tests/ui/const-generics/min_const_generics/macro-fail.rs +++ b/tests/ui/const-generics/min_const_generics/macro-fail.rs @@ -13,6 +13,7 @@ impl<const N: usize> Marker<N> for Example<N> {} fn make_marker() -> impl Marker<gimme_a_const!(marker)> { //~^ ERROR: type provided when a constant was expected + //~| ERROR: type provided when a constant was expected Example::<gimme_a_const!(marker)> //~^ ERROR: type provided when a constant was expected } diff --git a/tests/ui/const-generics/min_const_generics/macro-fail.stderr b/tests/ui/const-generics/min_const_generics/macro-fail.stderr index 06a111008a3..34764982bb0 100644 --- a/tests/ui/const-generics/min_const_generics/macro-fail.stderr +++ b/tests/ui/const-generics/min_const_generics/macro-fail.stderr @@ -1,5 +1,5 @@ error: expected type, found `{` - --> $DIR/macro-fail.rs:29:27 + --> $DIR/macro-fail.rs:30:27 | LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> { | ---------------------- @@ -13,7 +13,7 @@ LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} = note: this error originates in the macro `gimme_a_const` (in Nightly builds, run with -Z macro-backtrace for more info) error: expected type, found `{` - --> $DIR/macro-fail.rs:29:27 + --> $DIR/macro-fail.rs:30:27 | LL | Example::<gimme_a_const!(marker)> | ---------------------- @@ -41,7 +41,7 @@ LL | let _fail = Example::<external_macro!()>; = note: this error originates in the macro `external_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: unexpected end of macro invocation - --> $DIR/macro-fail.rs:39:25 + --> $DIR/macro-fail.rs:40:25 | LL | macro_rules! gimme_a_const { | -------------------------- when calling this macro @@ -50,7 +50,7 @@ LL | let _fail = Example::<gimme_a_const!()>; | ^^^^^^^^^^^^^^^^ missing tokens in macro arguments | note: while trying to match meta-variable `$rusty:ident` - --> $DIR/macro-fail.rs:29:8 + --> $DIR/macro-fail.rs:30:8 | LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} | ^^^^^^^^^^^^^ @@ -62,23 +62,31 @@ LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> { | ^^^^^^^^^^^^^^^^^^^^^^ error[E0747]: type provided when a constant was expected - --> $DIR/macro-fail.rs:16:13 + --> $DIR/macro-fail.rs:14:33 + | +LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> { + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0747]: type provided when a constant was expected + --> $DIR/macro-fail.rs:17:13 | LL | Example::<gimme_a_const!(marker)> | ^^^^^^^^^^^^^^^^^^^^^^ error[E0747]: type provided when a constant was expected - --> $DIR/macro-fail.rs:36:25 + --> $DIR/macro-fail.rs:37:25 | LL | let _fail = Example::<external_macro!()>; | ^^^^^^^^^^^^^^^^^ error[E0747]: type provided when a constant was expected - --> $DIR/macro-fail.rs:39:25 + --> $DIR/macro-fail.rs:40:25 | LL | let _fail = Example::<gimme_a_const!()>; | ^^^^^^^^^^^^^^^^ -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0747`. diff --git a/tests/ui/const-generics/nested-type.min.stderr b/tests/ui/const-generics/nested-type.min.stderr index ca5af5f969f..0da2b30e3f1 100644 --- a/tests/ui/const-generics/nested-type.min.stderr +++ b/tests/ui/const-generics/nested-type.min.stderr @@ -30,7 +30,10 @@ LL | | }]>; | |__^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/slice-const-param-mismatch.min.stderr b/tests/ui/const-generics/slice-const-param-mismatch.min.stderr index 26f5af6c831..0650dafc685 100644 --- a/tests/ui/const-generics/slice-const-param-mismatch.min.stderr +++ b/tests/ui/const-generics/slice-const-param-mismatch.min.stderr @@ -5,7 +5,10 @@ LL | struct ConstString<const T: &'static str>; | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `&'static [u8]` is forbidden as the type of a const generic parameter --> $DIR/slice-const-param-mismatch.rs:9:28 @@ -14,7 +17,10 @@ LL | struct ConstBytes<const T: &'static [u8]>; | ^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error[E0308]: mismatched types --> $DIR/slice-const-param-mismatch.rs:14:35 diff --git a/tests/ui/const-generics/std/const-generics-range.min.stderr b/tests/ui/const-generics/std/const-generics-range.min.stderr index d45f749246c..67f137cf1a0 100644 --- a/tests/ui/const-generics/std/const-generics-range.min.stderr +++ b/tests/ui/const-generics/std/const-generics-range.min.stderr @@ -5,7 +5,10 @@ LL | struct _Range<const R: std::ops::Range<usize>>; | ^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `RangeFrom<usize>` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:13:28 @@ -14,7 +17,10 @@ LL | struct _RangeFrom<const R: std::ops::RangeFrom<usize>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `RangeFull` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:18:28 @@ -23,7 +29,10 @@ LL | struct _RangeFull<const R: std::ops::RangeFull>; | ^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `RangeInclusive<usize>` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:24:33 @@ -32,7 +41,10 @@ LL | struct _RangeInclusive<const R: std::ops::RangeInclusive<usize>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `RangeTo<usize>` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:29:26 @@ -41,7 +53,10 @@ LL | struct _RangeTo<const R: std::ops::RangeTo<usize>>; | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `RangeToInclusive<usize>` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:34:35 @@ -50,7 +65,10 @@ LL | struct _RangeToInclusive<const R: std::ops::RangeToInclusive<usize>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 6 previous errors diff --git a/tests/ui/const-generics/transmute-const-param-static-reference.min.stderr b/tests/ui/const-generics/transmute-const-param-static-reference.min.stderr index 25bb7ac8039..fdb6ddeb578 100644 --- a/tests/ui/const-generics/transmute-const-param-static-reference.min.stderr +++ b/tests/ui/const-generics/transmute-const-param-static-reference.min.stderr @@ -5,7 +5,10 @@ LL | struct Const<const P: &'static ()>; | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/transmute-fail.rs b/tests/ui/const-generics/transmute-fail.rs index d7bf1b47fb5..90afd232534 100644 --- a/tests/ui/const-generics/transmute-fail.rs +++ b/tests/ui/const-generics/transmute-fail.rs @@ -32,4 +32,79 @@ fn overflow(v: [[[u32; 8888888]; 9999999]; 777777777]) -> [[[u32; 9999999]; 7777 } } +fn transpose<const W: usize, const H: usize>(v: [[u32;H]; W]) -> [[u32; W]; H] { + unsafe { + std::mem::transmute(v) + //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types + } +} + +fn ident<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [[u32; H]; W] { + unsafe { + std::mem::transmute(v) + } +} + +fn flatten<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [u32; W * H] { + unsafe { + std::mem::transmute(v) + //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types + } +} + +fn coagulate<const W: usize, const H: usize>(v: [u32; H*W]) -> [[u32; W];H] { + unsafe { + std::mem::transmute(v) + //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types + } +} + +fn flatten_3d<const W: usize, const H: usize, const D: usize>( + v: [[[u32; D]; H]; W] +) -> [u32; D * W * H] { + unsafe { + std::mem::transmute(v) + //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types + } +} + +fn flatten_somewhat<const W: usize, const H: usize, const D: usize>( + v: [[[u32; D]; H]; W] +) -> [[u32; D * W]; H] { + unsafe { + std::mem::transmute(v) + //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types + } +} + +fn known_size<const L: usize>(v: [u16; L]) -> [u8; L * 2] { + unsafe { + std::mem::transmute(v) + //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types + } +} + +fn condense_bytes<const L: usize>(v: [u8; L * 2]) -> [u16; L] { + unsafe { + std::mem::transmute(v) + //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types + } +} + +fn singleton_each<const L: usize>(v: [u8; L]) -> [[u8;1]; L] { + unsafe { + std::mem::transmute(v) + //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types + } +} + +fn transpose_with_const<const W: usize, const H: usize>( + v: [[u32; 2 * H]; W + W] +) -> [[u32; W + W]; 2 * H] { + unsafe { + std::mem::transmute(v) + //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types + } +} + fn main() {} diff --git a/tests/ui/const-generics/transmute-fail.stderr b/tests/ui/const-generics/transmute-fail.stderr index 12644b9f36d..1b0d1ea50d0 100644 --- a/tests/ui/const-generics/transmute-fail.stderr +++ b/tests/ui/const-generics/transmute-fail.stderr @@ -4,8 +4,8 @@ error[E0512]: cannot transmute between types of different sizes, or dependently- LL | std::mem::transmute(v) | ^^^^^^^^^^^^^^^^^^^ | - = note: source type: `[[u32; H+1]; W]` (generic size {const expr}) - = note: target type: `[[u32; W+1]; H]` (generic size {const expr}) + = note: source type: `[[u32; H+1]; W]` (size can vary because of [u32; H+1]) + = note: target type: `[[u32; W+1]; H]` (size can vary because of [u32; W+1]) error[E0512]: cannot transmute between types of different sizes, or dependently-sized types --> $DIR/transmute-fail.rs:16:5 @@ -22,8 +22,8 @@ error[E0512]: cannot transmute between types of different sizes, or dependently- LL | std::mem::transmute(v) | ^^^^^^^^^^^^^^^^^^^ | - = note: source type: `[[u32; H]; W]` (generic size {const expr}) - = note: target type: `[u32; W * H * H]` (generic size {const expr}) + = note: source type: `[[u32; H]; W]` (size can vary because of [u32; H]) + = note: target type: `[u32; W * H * H]` (this type does not have a fixed size) error[E0512]: cannot transmute between types of different sizes, or dependently-sized types --> $DIR/transmute-fail.rs:30:5 @@ -34,6 +34,87 @@ LL | std::mem::transmute(v) = note: source type: `[[[u32; 8888888]; 9999999]; 777777777]` (values of the type `[[u32; 8888888]; 9999999]` are too big for the current architecture) = note: target type: `[[[u32; 9999999]; 777777777]; 8888888]` (values of the type `[[u32; 9999999]; 777777777]` are too big for the current architecture) +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> $DIR/transmute-fail.rs:37:5 + | +LL | std::mem::transmute(v) + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `[[u32; H]; W]` (size can vary because of [u32; H]) + = note: target type: `[[u32; W]; H]` (size can vary because of [u32; W]) + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> $DIR/transmute-fail.rs:50:5 + | +LL | std::mem::transmute(v) + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `[[u32; H]; W]` (size can vary because of [u32; H]) + = note: target type: `[u32; W * H]` (this type does not have a fixed size) + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> $DIR/transmute-fail.rs:57:5 + | +LL | std::mem::transmute(v) + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `[u32; H*W]` (this type does not have a fixed size) + = note: target type: `[[u32; W]; H]` (size can vary because of [u32; W]) + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> $DIR/transmute-fail.rs:66:5 + | +LL | std::mem::transmute(v) + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `[[[u32; D]; H]; W]` (size can vary because of [u32; D]) + = note: target type: `[u32; D * W * H]` (this type does not have a fixed size) + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> $DIR/transmute-fail.rs:75:5 + | +LL | std::mem::transmute(v) + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `[[[u32; D]; H]; W]` (size can vary because of [u32; D]) + = note: target type: `[[u32; D * W]; H]` (size can vary because of [u32; D * W]) + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> $DIR/transmute-fail.rs:82:5 + | +LL | std::mem::transmute(v) + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `[u16; L]` (this type does not have a fixed size) + = note: target type: `[u8; L * 2]` (this type does not have a fixed size) + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> $DIR/transmute-fail.rs:89:5 + | +LL | std::mem::transmute(v) + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `[u8; L * 2]` (this type does not have a fixed size) + = note: target type: `[u16; L]` (this type does not have a fixed size) + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> $DIR/transmute-fail.rs:96:5 + | +LL | std::mem::transmute(v) + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `[u8; L]` (this type does not have a fixed size) + = note: target type: `[[u8; 1]; L]` (this type does not have a fixed size) + +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> $DIR/transmute-fail.rs:105:5 + | +LL | std::mem::transmute(v) + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `[[u32; 2 * H]; W + W]` (size can vary because of [u32; 2 * H]) + = note: target type: `[[u32; W + W]; 2 * H]` (size can vary because of [u32; W + W]) + error[E0308]: mismatched types --> $DIR/transmute-fail.rs:12:53 | @@ -46,7 +127,7 @@ error[E0308]: mismatched types LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] { | ^ expected `usize`, found `bool` -error: aborting due to 6 previous errors +error: aborting due to 15 previous errors Some errors have detailed explanations: E0308, E0512. For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/transmute.rs b/tests/ui/const-generics/transmute.rs index 245fcf5670e..e8ab8637932 100644 --- a/tests/ui/const-generics/transmute.rs +++ b/tests/ui/const-generics/transmute.rs @@ -3,81 +3,12 @@ #![feature(transmute_generic_consts)] #![allow(incomplete_features)] -fn transpose<const W: usize, const H: usize>(v: [[u32;H]; W]) -> [[u32; W]; H] { - unsafe { - std::mem::transmute(v) - } -} - fn ident<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [[u32; H]; W] { unsafe { std::mem::transmute(v) } } -fn flatten<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [u32; W * H] { - unsafe { - std::mem::transmute(v) - } -} - -fn coagulate<const W: usize, const H: usize>(v: [u32; H*W]) -> [[u32; W];H] { - unsafe { - std::mem::transmute(v) - } -} - -fn flatten_3d<const W: usize, const H: usize, const D: usize>( - v: [[[u32; D]; H]; W] -) -> [u32; D * W * H] { - unsafe { - std::mem::transmute(v) - } -} - -fn flatten_somewhat<const W: usize, const H: usize, const D: usize>( - v: [[[u32; D]; H]; W] -) -> [[u32; D * W]; H] { - unsafe { - std::mem::transmute(v) - } -} - -fn known_size<const L: usize>(v: [u16; L]) -> [u8; L * 2] { - unsafe { - std::mem::transmute(v) - } -} - -fn condense_bytes<const L: usize>(v: [u8; L * 2]) -> [u16; L] { - unsafe { - std::mem::transmute(v) - } -} - -fn singleton_each<const L: usize>(v: [u8; L]) -> [[u8;1]; L] { - unsafe { - std::mem::transmute(v) - } -} - -fn transpose_with_const<const W: usize, const H: usize>( - v: [[u32; 2 * H]; W + W] -) -> [[u32; W + W]; 2 * H] { - unsafe { - std::mem::transmute(v) - } -} - fn main() { - let _ = transpose([[0; 8]; 16]); - let _ = transpose_with_const::<8,4>([[0; 8]; 16]); let _ = ident([[0; 8]; 16]); - let _ = flatten([[0; 13]; 5]); - let _: [[_; 5]; 13] = coagulate([0; 65]); - let _ = flatten_3d([[[0; 3]; 13]; 5]); - let _ = flatten_somewhat([[[0; 3]; 13]; 5]); - let _ = known_size([16; 13]); - let _: [u16; 5] = condense_bytes([16u8; 10]); - let _ = singleton_each([16; 10]); } diff --git a/tests/ui/const-generics/type-dependent/issue-71348.min.stderr b/tests/ui/const-generics/type-dependent/issue-71348.min.stderr index 6490592c1e1..f42a331a8a4 100644 --- a/tests/ui/const-generics/type-dependent/issue-71348.min.stderr +++ b/tests/ui/const-generics/type-dependent/issue-71348.min.stderr @@ -5,7 +5,10 @@ LL | trait Get<'a, const N: &'static str> { | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: `&'static str` is forbidden as the type of a const generic parameter --> $DIR/issue-71348.rs:18:25 @@ -14,7 +17,10 @@ LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Ta | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.rs b/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.rs new file mode 100644 index 00000000000..dc9782295c1 --- /dev/null +++ b/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.rs @@ -0,0 +1,20 @@ +// test for #112824 ICE type mismatching when copying! + +pub struct Opcode(pub u8); + +pub struct Opcode2(&'a S); +//~^ ERROR use of undeclared lifetime name `'a` +//~^^ ERROR cannot find type `S` in this scope + +impl Opcode2 { + pub const OP2: Opcode2 = Opcode2(Opcode(0x1)); +} + +pub fn example2(msg_type: Opcode2) -> impl FnMut(&[u8]) { + move |i| match msg_type { + Opcode2::OP2 => unimplemented!(), + //~^ ERROR could not evaluate constant pattern + } +} + +pub fn main() {} diff --git a/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.stderr b/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.stderr new file mode 100644 index 00000000000..9442eac0cf5 --- /dev/null +++ b/tests/ui/const_prop/ice-type-mismatch-when-copying-112824.stderr @@ -0,0 +1,29 @@ +error[E0261]: use of undeclared lifetime name `'a` + --> $DIR/ice-type-mismatch-when-copying-112824.rs:5:21 + | +LL | pub struct Opcode2(&'a S); + | - ^^ undeclared lifetime + | | + | help: consider introducing lifetime `'a` here: `<'a>` + +error[E0412]: cannot find type `S` in this scope + --> $DIR/ice-type-mismatch-when-copying-112824.rs:5:24 + | +LL | pub struct Opcode2(&'a S); + | ^ not found in this scope + | +help: you might be missing a type parameter + | +LL | pub struct Opcode2<S>(&'a S); + | +++ + +error: could not evaluate constant pattern + --> $DIR/ice-type-mismatch-when-copying-112824.rs:15:9 + | +LL | Opcode2::OP2 => unimplemented!(), + | ^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0261, E0412. +For more information about an error, try `rustc --explain E0261`. diff --git a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr index c06c3074116..c1748c2e237 100644 --- a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr @@ -68,7 +68,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/raw-bytes.rs:59:1 | LL | const NULL_U8: NonZero<u8> = unsafe { mem::transmute(0u8) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 1, align: 1) { @@ -79,7 +79,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/raw-bytes.rs:61:1 | LL | const NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(0usize) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { diff --git a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr index 0589280524c..eb97eab9db7 100644 --- a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr @@ -68,7 +68,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/raw-bytes.rs:59:1 | LL | const NULL_U8: NonZero<u8> = unsafe { mem::transmute(0u8) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 1, align: 1) { @@ -79,7 +79,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/raw-bytes.rs:61:1 | LL | const NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(0usize) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 8) { diff --git a/tests/ui/consts/const-eval/ub-nonnull.stderr b/tests/ui/consts/const-eval/ub-nonnull.stderr index 70b961fe1cd..ab0fb2abdb3 100644 --- a/tests/ui/consts/const-eval/ub-nonnull.stderr +++ b/tests/ui/consts/const-eval/ub-nonnull.stderr @@ -19,7 +19,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/ub-nonnull.rs:24:1 | LL | const NULL_U8: NonZero<u8> = unsafe { mem::transmute(0u8) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { @@ -30,7 +30,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/ub-nonnull.rs:26:1 | LL | const NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(0usize) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1 | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { diff --git a/tests/ui/consts/const-fn-error.stderr b/tests/ui/consts/const-fn-error.stderr index 68c335c71d9..14603e433c1 100644 --- a/tests/ui/consts/const-fn-error.stderr +++ b/tests/ui/consts/const-fn-error.stderr @@ -23,7 +23,10 @@ LL | for i in 0..x { note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0658]: mutable references are not allowed in constant functions --> $DIR/const-fn-error.rs:5:14 @@ -42,7 +45,10 @@ LL | for i in 0..x { | ^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 4 previous errors diff --git a/tests/ui/consts/const-for-feature-gate.stderr b/tests/ui/consts/const-for-feature-gate.stderr index 413d144ca0a..0f2f912572e 100644 --- a/tests/ui/consts/const-for-feature-gate.stderr +++ b/tests/ui/consts/const-for-feature-gate.stderr @@ -17,7 +17,10 @@ LL | for _ in 0..5 {} note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0658]: mutable references are not allowed in constants --> $DIR/const-for-feature-gate.rs:4:14 @@ -36,7 +39,10 @@ LL | for _ in 0..5 {} | ^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 4 previous errors diff --git a/tests/ui/consts/const-for.stderr b/tests/ui/consts/const-for.stderr index 3fb9787c0d8..8605fb8eef5 100644 --- a/tests/ui/consts/const-for.stderr +++ b/tests/ui/consts/const-for.stderr @@ -7,7 +7,10 @@ LL | for _ in 0..5 {} note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0015]: cannot call non-const fn `<std::ops::Range<i32> as Iterator>::next` in constants --> $DIR/const-for.rs:5:14 @@ -16,7 +19,10 @@ LL | for _ in 0..5 {} | ^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/consts/const-try-feature-gate.stderr b/tests/ui/consts/const-try-feature-gate.stderr index efa1fb107f6..0c4c16fc56a 100644 --- a/tests/ui/consts/const-try-feature-gate.stderr +++ b/tests/ui/consts/const-try-feature-gate.stderr @@ -17,7 +17,10 @@ LL | Some(())?; note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/option.rs:LL:COL = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0015]: `?` cannot convert from residual of `Option<()>` in constant functions --> $DIR/const-try-feature-gate.rs:4:5 @@ -28,7 +31,10 @@ LL | Some(())?; note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/option.rs:LL:COL = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 3 previous errors diff --git a/tests/ui/consts/const-try.stderr b/tests/ui/consts/const-try.stderr index 37a6598af9e..2d91424c8d3 100644 --- a/tests/ui/consts/const-try.stderr +++ b/tests/ui/consts/const-try.stderr @@ -10,7 +10,10 @@ note: impl defined here, but it is not `const` LL | impl const Try for TryMe { | ^^^^^^^^^^^^^^^^^^^^^^^^ = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: `?` cannot convert from residual of `TryMe` in constant functions --> $DIR/const-try.rs:33:5 @@ -24,7 +27,10 @@ note: impl defined here, but it is not `const` LL | impl const FromResidual<Error> for TryMe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/consts/constifconst-call-in-const-position.stderr b/tests/ui/consts/constifconst-call-in-const-position.stderr index 42ad4125824..09827f29baf 100644 --- a/tests/ui/consts/constifconst-call-in-const-position.stderr +++ b/tests/ui/consts/constifconst-call-in-const-position.stderr @@ -14,7 +14,10 @@ LL | [0; T::a()] | ^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: cannot call non-const fn `<T as Tr>::a` in constants --> $DIR/constifconst-call-in-const-position.rs:16:38 @@ -23,7 +26,10 @@ LL | const fn foo<T: ~const Tr>() -> [u8; T::a()] { | ^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 2 previous errors; 1 warning emitted diff --git a/tests/ui/consts/control-flow/dead_branches_dont_eval.rs b/tests/ui/consts/control-flow/dead_branches_dont_eval.rs new file mode 100644 index 00000000000..374349732f9 --- /dev/null +++ b/tests/ui/consts/control-flow/dead_branches_dont_eval.rs @@ -0,0 +1,46 @@ +//@ build-pass + +// issue 122301 - currently the only way to supress +// const eval and codegen of code conditional on some other const + +struct Foo<T, const N: usize>(T); + +impl<T, const N: usize> Foo<T, N> { + const BAR: () = if N == 0 { + panic!() + }; +} + +struct Invoke<T, const N: usize>(T); + +impl<T, const N: usize> Invoke<T, N> { + const FUN: fn() = if N != 0 { + || Foo::<T, N>::BAR + } else { + || {} + }; +} + +// without closures + +struct S<T>(T); +impl<T> S<T> { + const C: () = panic!(); +} + +const fn bar<T>() { S::<T>::C } + +struct ConstIf<T, const N: usize>(T); + +impl<T, const N: usize> ConstIf<T, N> { + const VAL: () = if N != 0 { + bar::<T>() // not called for N == 0, and hence not monomorphized + } else { + () + }; +} + +fn main() { + let _val = Invoke::<(), 0>::FUN(); + let _val = ConstIf::<(), 0>::VAL; +} diff --git a/tests/ui/consts/control-flow/loop.stderr b/tests/ui/consts/control-flow/loop.stderr index e162a404ace..2815b888ccd 100644 --- a/tests/ui/consts/control-flow/loop.stderr +++ b/tests/ui/consts/control-flow/loop.stderr @@ -37,7 +37,10 @@ LL | for i in 0..4 { note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0658]: mutable references are not allowed in constants --> $DIR/loop.rs:53:14 @@ -56,7 +59,10 @@ LL | for i in 0..4 { | ^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0015]: cannot convert `std::ops::Range<i32>` into an iterator in constants --> $DIR/loop.rs:60:14 @@ -67,7 +73,10 @@ LL | for i in 0..4 { note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0658]: mutable references are not allowed in constants --> $DIR/loop.rs:60:14 @@ -86,7 +95,10 @@ LL | for i in 0..4 { | ^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 8 previous errors diff --git a/tests/ui/consts/control-flow/try.stderr b/tests/ui/consts/control-flow/try.stderr index f4c42c4d819..e08f52369fa 100644 --- a/tests/ui/consts/control-flow/try.stderr +++ b/tests/ui/consts/control-flow/try.stderr @@ -17,7 +17,10 @@ LL | x?; note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/option.rs:LL:COL = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0015]: `?` cannot convert from residual of `Option<i32>` in constant functions --> $DIR/try.rs:6:5 @@ -28,7 +31,10 @@ LL | x?; note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/option.rs:LL:COL = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 3 previous errors diff --git a/tests/ui/consts/fn_trait_refs.stderr b/tests/ui/consts/fn_trait_refs.stderr index 527579d99ea..aad0ae64e85 100644 --- a/tests/ui/consts/fn_trait_refs.stderr +++ b/tests/ui/consts/fn_trait_refs.stderr @@ -81,7 +81,10 @@ LL | assert!(test_one == (1, 1, 1)); | ^^^^^^^^^^^^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: cannot call non-const operator in constants --> $DIR/fn_trait_refs.rs:75:17 @@ -90,7 +93,10 @@ LL | assert!(test_two == (2, 2)); | ^^^^^^^^^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: cannot call non-const closure in constant functions --> $DIR/fn_trait_refs.rs:17:5 @@ -99,11 +105,14 @@ LL | f() | ^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable help: consider further restricting this bound | LL | T: ~const Fn<()> + ~const Destruct + ~const std::ops::Fn<()>, | +++++++++++++++++++++++++ +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0493]: destructor of `T` cannot be evaluated at compile-time --> $DIR/fn_trait_refs.rs:13:23 @@ -121,11 +130,14 @@ LL | f() | ^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable help: consider further restricting this bound | LL | T: ~const FnMut<()> + ~const Destruct + ~const std::ops::FnMut<()>, | ++++++++++++++++++++++++++++ +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0493]: destructor of `T` cannot be evaluated at compile-time --> $DIR/fn_trait_refs.rs:20:27 @@ -143,11 +155,14 @@ LL | f() | ^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable help: consider further restricting this bound | LL | T: ~const FnOnce<()> + ~const std::ops::FnOnce<()>, | +++++++++++++++++++++++++++++ +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0493]: destructor of `T` cannot be evaluated at compile-time --> $DIR/fn_trait_refs.rs:34:21 diff --git a/tests/ui/consts/invalid-inline-const-in-match-arm.stderr b/tests/ui/consts/invalid-inline-const-in-match-arm.stderr index a88c16158f3..7579f7f9692 100644 --- a/tests/ui/consts/invalid-inline-const-in-match-arm.stderr +++ b/tests/ui/consts/invalid-inline-const-in-match-arm.stderr @@ -6,7 +6,10 @@ LL | const { (|| {})() } => {} | = note: closures need an RFC before allowed to be called in constants = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 1 previous error diff --git a/tests/ui/consts/issue-103790.stderr b/tests/ui/consts/issue-103790.stderr index abe7366483b..eecaf5ff63a 100644 --- a/tests/ui/consts/issue-103790.stderr +++ b/tests/ui/consts/issue-103790.stderr @@ -62,7 +62,10 @@ LL | struct S<const S: (), const S: S = { S }>; | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 5 previous errors diff --git a/tests/ui/consts/issue-28113.stderr b/tests/ui/consts/issue-28113.stderr index 01bbe4bc9b9..c2f53870173 100644 --- a/tests/ui/consts/issue-28113.stderr +++ b/tests/ui/consts/issue-28113.stderr @@ -6,7 +6,10 @@ LL | || -> u8 { 5 }() | = note: closures need an RFC before allowed to be called in constants = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 1 previous error diff --git a/tests/ui/consts/issue-56164.stderr b/tests/ui/consts/issue-56164.stderr index 1b267214a02..6ec4ce0fbd7 100644 --- a/tests/ui/consts/issue-56164.stderr +++ b/tests/ui/consts/issue-56164.stderr @@ -6,7 +6,10 @@ LL | const fn foo() { (||{})() } | = note: closures need an RFC before allowed to be called in constant functions = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: function pointer calls are not allowed in constant functions --> $DIR/issue-56164.rs:5:5 diff --git a/tests/ui/consts/issue-68542-closure-in-array-len.stderr b/tests/ui/consts/issue-68542-closure-in-array-len.stderr index 3c0408cbedf..b414a6e0dba 100644 --- a/tests/ui/consts/issue-68542-closure-in-array-len.stderr +++ b/tests/ui/consts/issue-68542-closure-in-array-len.stderr @@ -6,7 +6,10 @@ LL | a: [(); (|| { 0 })()] | = note: closures need an RFC before allowed to be called in constants = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 1 previous error diff --git a/tests/ui/consts/issue-73976-monomorphic.stderr b/tests/ui/consts/issue-73976-monomorphic.stderr index 465efc7bfc2..79dbed4bea8 100644 --- a/tests/ui/consts/issue-73976-monomorphic.stderr +++ b/tests/ui/consts/issue-73976-monomorphic.stderr @@ -7,7 +7,10 @@ LL | GetTypeId::<T>::VALUE == GetTypeId::<usize>::VALUE note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/any.rs:LL:COL = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 1 previous error diff --git a/tests/ui/consts/issue-90870.fixed b/tests/ui/consts/issue-90870.fixed deleted file mode 100644 index c125501f61c..00000000000 --- a/tests/ui/consts/issue-90870.fixed +++ /dev/null @@ -1,37 +0,0 @@ -// Regression test for issue #90870. - -//@ run-rustfix - -#![allow(dead_code)] - -const fn f(a: &u8, b: &u8) -> bool { - *a == *b - //~^ ERROR: cannot call non-const operator in constant functions [E0015] - //~| HELP: consider dereferencing here - //~| HELP: add `#![feature(const_trait_impl)]` -} - -const fn g(a: &&&&i64, b: &&&&i64) -> bool { - ****a == ****b - //~^ ERROR: cannot call non-const operator in constant functions [E0015] - //~| HELP: consider dereferencing here - //~| HELP: add `#![feature(const_trait_impl)]` -} - -const fn h(mut a: &[u8], mut b: &[u8]) -> bool { - while let ([l, at @ ..], [r, bt @ ..]) = (a, b) { - if *l == *r { - //~^ ERROR: cannot call non-const operator in constant functions [E0015] - //~| HELP: consider dereferencing here - //~| HELP: add `#![feature(const_trait_impl)]` - a = at; - b = bt; - } else { - return false; - } - } - - a.is_empty() && b.is_empty() -} - -fn main() {} diff --git a/tests/ui/consts/issue-90870.rs b/tests/ui/consts/issue-90870.rs index 94254fb27f9..e1929c68c70 100644 --- a/tests/ui/consts/issue-90870.rs +++ b/tests/ui/consts/issue-90870.rs @@ -1,21 +1,20 @@ // Regression test for issue #90870. -//@ run-rustfix - #![allow(dead_code)] const fn f(a: &u8, b: &u8) -> bool { +//~^ HELP: add `#![feature(const_trait_impl)]` +//~| HELP: add `#![feature(const_trait_impl)]` +//~| HELP: add `#![feature(const_trait_impl)]` a == b //~^ ERROR: cannot call non-const operator in constant functions [E0015] //~| HELP: consider dereferencing here - //~| HELP: add `#![feature(const_trait_impl)]` } const fn g(a: &&&&i64, b: &&&&i64) -> bool { a == b //~^ ERROR: cannot call non-const operator in constant functions [E0015] //~| HELP: consider dereferencing here - //~| HELP: add `#![feature(const_trait_impl)]` } const fn h(mut a: &[u8], mut b: &[u8]) -> bool { @@ -23,7 +22,6 @@ const fn h(mut a: &[u8], mut b: &[u8]) -> bool { if l == r { //~^ ERROR: cannot call non-const operator in constant functions [E0015] //~| HELP: consider dereferencing here - //~| HELP: add `#![feature(const_trait_impl)]` a = at; b = bt; } else { diff --git a/tests/ui/consts/issue-90870.stderr b/tests/ui/consts/issue-90870.stderr index 8825efd1449..df88a0c95cc 100644 --- a/tests/ui/consts/issue-90870.stderr +++ b/tests/ui/consts/issue-90870.stderr @@ -1,15 +1,18 @@ error[E0015]: cannot call non-const operator in constant functions - --> $DIR/issue-90870.rs:8:5 + --> $DIR/issue-90870.rs:9:5 | LL | a == b | ^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable help: consider dereferencing here | LL | *a == *b | + + +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0015]: cannot call non-const operator in constant functions --> $DIR/issue-90870.rs:15:5 @@ -18,24 +21,30 @@ LL | a == b | ^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable help: consider dereferencing here | LL | ****a == ****b | ++++ ++++ +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0015]: cannot call non-const operator in constant functions - --> $DIR/issue-90870.rs:23:12 + --> $DIR/issue-90870.rs:22:12 | LL | if l == r { | ^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable help: consider dereferencing here | LL | if *l == *r { | + + +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 3 previous errors diff --git a/tests/ui/consts/issue-94675.stderr b/tests/ui/consts/issue-94675.stderr index 60a56f85c11..ebfa09b2e5d 100644 --- a/tests/ui/consts/issue-94675.stderr +++ b/tests/ui/consts/issue-94675.stderr @@ -15,7 +15,10 @@ LL | self.bar[0] = baz.len(); note: impl defined here, but it is not `const` --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/consts/required-consts/collect-in-called-fn.noopt.stderr b/tests/ui/consts/required-consts/collect-in-called-fn.noopt.stderr index 14a4cb0217f..c3b641a899a 100644 --- a/tests/ui/consts/required-consts/collect-in-called-fn.noopt.stderr +++ b/tests/ui/consts/required-consts/collect-in-called-fn.noopt.stderr @@ -1,19 +1,19 @@ error[E0080]: evaluation of `Fail::<i32>::C` failed - --> $DIR/collect-in-called-fn.rs:9:19 + --> $DIR/collect-in-called-fn.rs:10:19 | LL | const C: () = panic!(); - | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-called-fn.rs:9:19 + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-called-fn.rs:10:19 | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered - --> $DIR/collect-in-called-fn.rs:18:17 + --> $DIR/collect-in-called-fn.rs:19:17 | LL | let _ = Fail::<T>::C; | ^^^^^^^^^^^^ note: the above error was encountered while instantiating `fn called::<i32>` - --> $DIR/collect-in-called-fn.rs:23:5 + --> $DIR/collect-in-called-fn.rs:24:5 | LL | called::<i32>(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/consts/required-consts/collect-in-called-fn.opt.stderr b/tests/ui/consts/required-consts/collect-in-called-fn.opt.stderr index 14a4cb0217f..c3b641a899a 100644 --- a/tests/ui/consts/required-consts/collect-in-called-fn.opt.stderr +++ b/tests/ui/consts/required-consts/collect-in-called-fn.opt.stderr @@ -1,19 +1,19 @@ error[E0080]: evaluation of `Fail::<i32>::C` failed - --> $DIR/collect-in-called-fn.rs:9:19 + --> $DIR/collect-in-called-fn.rs:10:19 | LL | const C: () = panic!(); - | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-called-fn.rs:9:19 + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-called-fn.rs:10:19 | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered - --> $DIR/collect-in-called-fn.rs:18:17 + --> $DIR/collect-in-called-fn.rs:19:17 | LL | let _ = Fail::<T>::C; | ^^^^^^^^^^^^ note: the above error was encountered while instantiating `fn called::<i32>` - --> $DIR/collect-in-called-fn.rs:23:5 + --> $DIR/collect-in-called-fn.rs:24:5 | LL | called::<i32>(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/consts/required-consts/collect-in-called-fn.rs b/tests/ui/consts/required-consts/collect-in-called-fn.rs index 55133a10cd9..93947950af2 100644 --- a/tests/ui/consts/required-consts/collect-in-called-fn.rs +++ b/tests/ui/consts/required-consts/collect-in-called-fn.rs @@ -1,5 +1,6 @@ //@revisions: noopt opt //@ build-fail +//@[noopt] compile-flags: -Copt-level=0 //@[opt] compile-flags: -O //! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is //! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090) diff --git a/tests/ui/consts/required-consts/collect-in-dead-closure.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-closure.noopt.stderr new file mode 100644 index 00000000000..75c3575a110 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-closure.noopt.stderr @@ -0,0 +1,23 @@ +error[E0080]: evaluation of `Fail::<i32>::C` failed + --> $DIR/collect-in-dead-closure.rs:9:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-closure.rs:9:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-closure.rs:17:17 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn not_called::<i32>` + --> $DIR/collect-in-dead-closure.rs:24:33 + | +LL | let _closure: fn() = || not_called::<T>(); + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-closure.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-closure.opt.stderr new file mode 100644 index 00000000000..75c3575a110 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-closure.opt.stderr @@ -0,0 +1,23 @@ +error[E0080]: evaluation of `Fail::<i32>::C` failed + --> $DIR/collect-in-dead-closure.rs:9:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-closure.rs:9:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-closure.rs:17:17 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn not_called::<i32>` + --> $DIR/collect-in-dead-closure.rs:24:33 + | +LL | let _closure: fn() = || not_called::<T>(); + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-closure.rs b/tests/ui/consts/required-consts/collect-in-dead-closure.rs new file mode 100644 index 00000000000..a00214c62db --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-closure.rs @@ -0,0 +1,30 @@ +//@revisions: noopt opt +//@ build-fail +//@[noopt] compile-flags: -Copt-level=0 +//@[opt] compile-flags: -O +//! This fails without optimizations, so it should also fail with optimizations. + +struct Fail<T>(T); +impl<T> Fail<T> { + const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed +} + +// This function is not actually called, but it is mentioned in a closure that is coerced to a +// function pointer in dead code in a function that is called. Make sure we still find this error. +#[inline(never)] +fn not_called<T>() { + if false { + let _ = Fail::<T>::C; + } +} + +#[inline(never)] +fn called<T>() { + if false { + let _closure: fn() = || not_called::<T>(); + } +} + +pub fn main() { + called::<i32>(); +} diff --git a/tests/ui/consts/required-consts/collect-in-dead-drop.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-drop.noopt.stderr index 0bf231d09f1..73790f7517d 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-drop.noopt.stderr +++ b/tests/ui/consts/required-consts/collect-in-dead-drop.noopt.stderr @@ -1,13 +1,13 @@ error[E0080]: evaluation of `Fail::<i32>::C` failed - --> $DIR/collect-in-dead-drop.rs:12:19 + --> $DIR/collect-in-dead-drop.rs:9:19 | LL | const C: () = panic!(); - | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-drop.rs:12:19 + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-drop.rs:9:19 | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered - --> $DIR/collect-in-dead-drop.rs:19:17 + --> $DIR/collect-in-dead-drop.rs:16:17 | LL | let _ = Fail::<T>::C; | ^^^^^^^^^^^^ diff --git a/tests/ui/consts/required-consts/collect-in-dead-drop.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-drop.opt.stderr new file mode 100644 index 00000000000..73790f7517d --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-drop.opt.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of `Fail::<i32>::C` failed + --> $DIR/collect-in-dead-drop.rs:9:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-drop.rs:9:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-drop.rs:16:17 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn <Fail<i32> as std::ops::Drop>::drop` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-drop.rs b/tests/ui/consts/required-consts/collect-in-dead-drop.rs index c9ffcec6903..389fcf5dfc9 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-drop.rs +++ b/tests/ui/consts/required-consts/collect-in-dead-drop.rs @@ -1,15 +1,12 @@ //@revisions: noopt opt -//@[noopt] build-fail +//@ build-fail +//@[noopt] compile-flags: -Copt-level=0 //@[opt] compile-flags: -O -//FIXME: `opt` revision currently does not stop with an error due to -//<https://github.com/rust-lang/rust/issues/107503>. -//@[opt] build-pass -//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is -//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090) +//! This fails without optimizations, so it should also fail with optimizations. struct Fail<T>(T); impl<T> Fail<T> { - const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::<i32>::C` failed + const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed } // This function is not actually called, but is mentioned implicitly as destructor in dead code in a diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn-behind-assoc-type.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-assoc-type.noopt.stderr new file mode 100644 index 00000000000..706c0d55b62 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-assoc-type.noopt.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of `Fail::<i32>::C` failed + --> $DIR/collect-in-dead-fn-behind-assoc-type.rs:10:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn-behind-assoc-type.rs:10:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-fn-behind-assoc-type.rs:16:17 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn not_called::<i32>` + --> $SRC_DIR/core/src/ops/function.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn-behind-assoc-type.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-assoc-type.opt.stderr new file mode 100644 index 00000000000..706c0d55b62 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-assoc-type.opt.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of `Fail::<i32>::C` failed + --> $DIR/collect-in-dead-fn-behind-assoc-type.rs:10:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn-behind-assoc-type.rs:10:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-fn-behind-assoc-type.rs:16:17 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn not_called::<i32>` + --> $SRC_DIR/core/src/ops/function.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn-behind-assoc-type.rs b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-assoc-type.rs new file mode 100644 index 00000000000..9c36af50bb7 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-assoc-type.rs @@ -0,0 +1,49 @@ +#![feature(impl_trait_in_assoc_type)] +//@revisions: noopt opt +//@ build-fail +//@[noopt] compile-flags: -Copt-level=0 +//@[opt] compile-flags: -O +//! This fails without optimizations, so it should also fail with optimizations. + +struct Fail<T>(T); +impl<T> Fail<T> { + const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed +} + +#[inline(never)] +fn not_called<T>() { + if false { + let _ = Fail::<T>::C; + } +} + +#[inline(never)] +fn callit_not(f: impl Fn()) { + if false { + f(); + } +} + +// Using `Fn` here is important; with `FnOnce` another shim gets involved which somehow makes this +// easier to collect properly. +trait Hideaway { + type T: Fn(); + const C: Self::T; +} +impl Hideaway for () { + type T = impl Fn(); + const C: Self::T = not_called::<i32>; +} + +#[inline(never)] +fn reveal<T: Hideaway>() { + if false { + callit_not(T::C); + } +} + +fn main() { + if false { + reveal::<()>() + } +} diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn-behind-generic.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-generic.noopt.stderr new file mode 100644 index 00000000000..581edd2b7b8 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-generic.noopt.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of `Fail::<i32>::C` failed + --> $DIR/collect-in-dead-fn-behind-generic.rs:9:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn-behind-generic.rs:9:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-fn-behind-generic.rs:15:17 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn not_called::<i32>` + --> $SRC_DIR/core/src/ops/function.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn-behind-generic.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-generic.opt.stderr new file mode 100644 index 00000000000..581edd2b7b8 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-generic.opt.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of `Fail::<i32>::C` failed + --> $DIR/collect-in-dead-fn-behind-generic.rs:9:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn-behind-generic.rs:9:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-fn-behind-generic.rs:15:17 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn not_called::<i32>` + --> $SRC_DIR/core/src/ops/function.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn-behind-generic.rs b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-generic.rs new file mode 100644 index 00000000000..5829d914ee1 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-generic.rs @@ -0,0 +1,30 @@ +//@revisions: noopt opt +//@ build-fail +//@[noopt] compile-flags: -Copt-level=0 +//@[opt] compile-flags: -O +//! This fails without optimizations, so it should also fail with optimizations. + +struct Fail<T>(T); +impl<T> Fail<T> { + const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed +} + +#[inline(never)] +fn not_called<T>() { + if false { + let _ = Fail::<T>::C; + } +} + +#[inline(never)] +fn callit_not(f: impl Fn()) { + if false { + f(); + } +} + +fn main() { + if false { + callit_not(not_called::<i32>) + } +} diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.noopt.stderr new file mode 100644 index 00000000000..07e46b8a816 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.noopt.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of `m::Fail::<i32>::C` failed + --> $DIR/collect-in-dead-fn-behind-opaque-type.rs:11:23 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn-behind-opaque-type.rs:11:23 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-fn-behind-opaque-type.rs:19:21 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn m::not_called::<i32>` + --> $SRC_DIR/core/src/ops/function.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.opt.stderr new file mode 100644 index 00000000000..07e46b8a816 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.opt.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of `m::Fail::<i32>::C` failed + --> $DIR/collect-in-dead-fn-behind-opaque-type.rs:11:23 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn-behind-opaque-type.rs:11:23 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-fn-behind-opaque-type.rs:19:21 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn m::not_called::<i32>` + --> $SRC_DIR/core/src/ops/function.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.rs b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.rs new file mode 100644 index 00000000000..795e021ceb0 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.rs @@ -0,0 +1,37 @@ +//@revisions: noopt opt +//@ build-fail +//@[noopt] compile-flags: -Copt-level=0 +//@[opt] compile-flags: -O +//! This fails without optimizations, so it should also fail with optimizations. +#![feature(type_alias_impl_trait)] + +mod m { + struct Fail<T>(T); + impl<T> Fail<T> { + const C: () = panic!(); //~ERROR evaluation of `m::Fail::<i32>::C` failed + } + + pub type NotCalledFn = impl Fn(); + + #[inline(never)] + fn not_called<T>() { + if false { + let _ = Fail::<T>::C; + } + } + + fn mk_not_called() -> NotCalledFn { + not_called::<i32> + } +} + +fn main() { + // This does not involve a constant of `FnDef` type, it generates the value via unsafe + // shenanigans instead. This ensures that we check all `FnDef` types that occur in a function, + // not just those of constants. Furthermore the `FnDef` is behind an opaque type which bust be + // normalized away to reveal the function type. + if false { + let x: m::NotCalledFn = unsafe { std::mem::transmute(()) }; + x(); + } +} diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-fn.noopt.stderr index 8bb99efe8e4..52462076ff9 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-fn.noopt.stderr +++ b/tests/ui/consts/required-consts/collect-in-dead-fn.noopt.stderr @@ -1,19 +1,19 @@ error[E0080]: evaluation of `Fail::<i32>::C` failed - --> $DIR/collect-in-dead-fn.rs:12:19 + --> $DIR/collect-in-dead-fn.rs:9:19 | LL | const C: () = panic!(); - | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn.rs:12:19 + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn.rs:9:19 | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered - --> $DIR/collect-in-dead-fn.rs:22:17 + --> $DIR/collect-in-dead-fn.rs:19:17 | LL | let _ = Fail::<T>::C; | ^^^^^^^^^^^^ note: the above error was encountered while instantiating `fn not_called::<i32>` - --> $DIR/collect-in-dead-fn.rs:29:9 + --> $DIR/collect-in-dead-fn.rs:26:9 | LL | not_called::<T>(); | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-fn.opt.stderr new file mode 100644 index 00000000000..52462076ff9 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fn.opt.stderr @@ -0,0 +1,23 @@ +error[E0080]: evaluation of `Fail::<i32>::C` failed + --> $DIR/collect-in-dead-fn.rs:9:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn.rs:9:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-fn.rs:19:17 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn not_called::<i32>` + --> $DIR/collect-in-dead-fn.rs:26:9 + | +LL | not_called::<T>(); + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn.rs b/tests/ui/consts/required-consts/collect-in-dead-fn.rs index 9e6b1519153..1c95e0c303f 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-fn.rs +++ b/tests/ui/consts/required-consts/collect-in-dead-fn.rs @@ -1,15 +1,12 @@ //@revisions: noopt opt -//@[noopt] build-fail +//@ build-fail +//@[noopt] compile-flags: -Copt-level=0 //@[opt] compile-flags: -O -//FIXME: `opt` revision currently does not stop with an error due to -//<https://github.com/rust-lang/rust/issues/107503>. -//@[opt] build-pass -//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is -//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090) +//! This fails without optimizations, so it should also fail with optimizations. struct Fail<T>(T); impl<T> Fail<T> { - const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::<i32>::C` failed + const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed } // This function is not actually called, but it is mentioned in dead code in a function that is diff --git a/tests/ui/consts/required-consts/collect-in-dead-fnptr-in-const.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-fnptr-in-const.noopt.stderr new file mode 100644 index 00000000000..dea2a342383 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fnptr-in-const.noopt.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of `Late::<i32>::FAIL` failed + --> $DIR/collect-in-dead-fnptr-in-const.rs:9:22 + | +LL | const FAIL: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fnptr-in-const.rs:9:22 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-fnptr-in-const.rs:10:28 + | +LL | const FNPTR: fn() = || Self::FAIL; + | ^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn Late::<i32>::FNPTR::{closure#0}` + --> $SRC_DIR/core/src/ops/function.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-fnptr-in-const.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-fnptr-in-const.opt.stderr new file mode 100644 index 00000000000..dea2a342383 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fnptr-in-const.opt.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of `Late::<i32>::FAIL` failed + --> $DIR/collect-in-dead-fnptr-in-const.rs:9:22 + | +LL | const FAIL: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fnptr-in-const.rs:9:22 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-fnptr-in-const.rs:10:28 + | +LL | const FNPTR: fn() = || Self::FAIL; + | ^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn Late::<i32>::FNPTR::{closure#0}` + --> $SRC_DIR/core/src/ops/function.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-fnptr-in-const.rs b/tests/ui/consts/required-consts/collect-in-dead-fnptr-in-const.rs new file mode 100644 index 00000000000..8b6344c93f3 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fnptr-in-const.rs @@ -0,0 +1,34 @@ +//@revisions: noopt opt +//@ build-fail +//@[noopt] compile-flags: -Copt-level=0 +//@[opt] compile-flags: -O +//! This fails without optimizations, so it should also fail with optimizations. + +struct Late<T>(T); +impl<T> Late<T> { + const FAIL: () = panic!(); //~ERROR evaluation of `Late::<i32>::FAIL` failed + const FNPTR: fn() = || Self::FAIL; +} + +// This function is not actually called, but it is mentioned in dead code in a function that is +// called. The function then mentions a const that evaluates to a fnptr that points to a function +// that used a const that fails to evaluate. +// This tests that when processing mentioned items, we also check the fnptrs in the final values +// of consts that we encounter. +#[inline(never)] +fn not_called<T>() { + if false { + let _ = Late::<T>::FNPTR; + } +} + +#[inline(never)] +fn called<T>() { + if false { + not_called::<T>(); + } +} + +pub fn main() { + called::<i32>(); +} diff --git a/tests/ui/consts/required-consts/collect-in-dead-fnptr.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-fnptr.noopt.stderr new file mode 100644 index 00000000000..51c68782687 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fnptr.noopt.stderr @@ -0,0 +1,23 @@ +error[E0080]: evaluation of `Fail::<i32>::C` failed + --> $DIR/collect-in-dead-fnptr.rs:9:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fnptr.rs:9:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-fnptr.rs:18:17 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn not_called::<i32>` + --> $DIR/collect-in-dead-fnptr.rs:27:28 + | +LL | let _fnptr: fn() = not_called::<T>; + | ^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-fnptr.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-fnptr.opt.stderr new file mode 100644 index 00000000000..51c68782687 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fnptr.opt.stderr @@ -0,0 +1,23 @@ +error[E0080]: evaluation of `Fail::<i32>::C` failed + --> $DIR/collect-in-dead-fnptr.rs:9:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fnptr.rs:9:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-fnptr.rs:18:17 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn not_called::<i32>` + --> $DIR/collect-in-dead-fnptr.rs:27:28 + | +LL | let _fnptr: fn() = not_called::<T>; + | ^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-fnptr.rs b/tests/ui/consts/required-consts/collect-in-dead-fnptr.rs new file mode 100644 index 00000000000..acbe34829e8 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-fnptr.rs @@ -0,0 +1,33 @@ +//@revisions: noopt opt +//@ build-fail +//@[noopt] compile-flags: -Copt-level=0 +//@[opt] compile-flags: -O +//! This fails without optimizations, so it should also fail with optimizations. + +struct Fail<T>(T); +impl<T> Fail<T> { + const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed +} + +// This function is not actually called, but it is mentioned in dead code in a function that is +// called. Make sure we still find this error. +// This ensures that we consider ReifyFnPointer coercions when gathering "mentioned" items. +#[inline(never)] +fn not_called<T>() { + if false { + let _ = Fail::<T>::C; + } +} + +#[inline(never)] +fn called<T>() { + if false { + // We don't call the function, but turn it to a function pointer. + // Make sure it still gest added to `mentioned_items`. + let _fnptr: fn() = not_called::<T>; + } +} + +pub fn main() { + called::<i32>(); +} diff --git a/tests/ui/consts/required-consts/collect-in-dead-forget.rs b/tests/ui/consts/required-consts/collect-in-dead-forget.rs index 720b7a499f7..7586004116c 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-forget.rs +++ b/tests/ui/consts/required-consts/collect-in-dead-forget.rs @@ -1,8 +1,8 @@ //@revisions: noopt opt //@build-pass +//@[noopt] compile-flags: -Copt-level=0 //@[opt] compile-flags: -O -//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is -//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090) +//! This passes without optimizations, so it can (and should) also pass with optimizations. struct Fail<T>(T); impl<T> Fail<T> { diff --git a/tests/ui/consts/required-consts/collect-in-dead-move.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-move.noopt.stderr index 5b1df78b232..2ab1f80e2d3 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-move.noopt.stderr +++ b/tests/ui/consts/required-consts/collect-in-dead-move.noopt.stderr @@ -1,13 +1,13 @@ error[E0080]: evaluation of `Fail::<i32>::C` failed - --> $DIR/collect-in-dead-move.rs:12:19 + --> $DIR/collect-in-dead-move.rs:9:19 | LL | const C: () = panic!(); - | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-move.rs:12:19 + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-move.rs:9:19 | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered - --> $DIR/collect-in-dead-move.rs:19:17 + --> $DIR/collect-in-dead-move.rs:16:17 | LL | let _ = Fail::<T>::C; | ^^^^^^^^^^^^ diff --git a/tests/ui/consts/required-consts/collect-in-dead-move.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-move.opt.stderr new file mode 100644 index 00000000000..2ab1f80e2d3 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-move.opt.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of `Fail::<i32>::C` failed + --> $DIR/collect-in-dead-move.rs:9:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-move.rs:9:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-move.rs:16:17 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn <Fail<i32> as std::ops::Drop>::drop` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-move.rs b/tests/ui/consts/required-consts/collect-in-dead-move.rs index f3a6ba8a657..6a224a375cf 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-move.rs +++ b/tests/ui/consts/required-consts/collect-in-dead-move.rs @@ -1,15 +1,12 @@ //@revisions: noopt opt -//@[noopt] build-fail +//@ build-fail +//@[noopt] compile-flags: -Copt-level=0 //@[opt] compile-flags: -O -//FIXME: `opt` revision currently does not stop with an error due to -//<https://github.com/rust-lang/rust/issues/107503>. -//@[opt] build-pass -//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is -//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090) +//! This fails without optimizations, so it should also fail with optimizations. struct Fail<T>(T); impl<T> Fail<T> { - const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::<i32>::C` failed + const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed } // This function is not actually called, but is mentioned implicitly as destructor in dead code in a diff --git a/tests/ui/consts/required-consts/collect-in-dead-vtable.noopt.stderr b/tests/ui/consts/required-consts/collect-in-dead-vtable.noopt.stderr index 56b6989b441..b4e18706489 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-vtable.noopt.stderr +++ b/tests/ui/consts/required-consts/collect-in-dead-vtable.noopt.stderr @@ -1,21 +1,21 @@ error[E0080]: evaluation of `Fail::<i32>::C` failed - --> $DIR/collect-in-dead-vtable.rs:12:19 + --> $DIR/collect-in-dead-vtable.rs:9:19 | LL | const C: () = panic!(); - | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-vtable.rs:12:19 + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-vtable.rs:9:19 | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered - --> $DIR/collect-in-dead-vtable.rs:26:21 + --> $DIR/collect-in-dead-vtable.rs:22:21 | LL | let _ = Fail::<T>::C; | ^^^^^^^^^^^^ note: the above error was encountered while instantiating `fn <std::vec::Vec<i32> as MyTrait>::not_called` - --> $DIR/collect-in-dead-vtable.rs:35:40 + --> $DIR/collect-in-dead-vtable.rs:31:40 | -LL | let gen_vtable: &dyn MyTrait = &v; // vtable "appears" here +LL | let gen_vtable: &dyn MyTrait = &v; // vtable is "mentioned" here | ^^ error: aborting due to 1 previous error diff --git a/tests/ui/consts/required-consts/collect-in-dead-vtable.opt.stderr b/tests/ui/consts/required-consts/collect-in-dead-vtable.opt.stderr new file mode 100644 index 00000000000..b4e18706489 --- /dev/null +++ b/tests/ui/consts/required-consts/collect-in-dead-vtable.opt.stderr @@ -0,0 +1,23 @@ +error[E0080]: evaluation of `Fail::<i32>::C` failed + --> $DIR/collect-in-dead-vtable.rs:9:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-vtable.rs:9:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: erroneous constant encountered + --> $DIR/collect-in-dead-vtable.rs:22:21 + | +LL | let _ = Fail::<T>::C; + | ^^^^^^^^^^^^ + +note: the above error was encountered while instantiating `fn <std::vec::Vec<i32> as MyTrait>::not_called` + --> $DIR/collect-in-dead-vtable.rs:31:40 + | +LL | let gen_vtable: &dyn MyTrait = &v; // vtable is "mentioned" here + | ^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-vtable.rs b/tests/ui/consts/required-consts/collect-in-dead-vtable.rs index f21a1cc1fc2..f63207eafec 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-vtable.rs +++ b/tests/ui/consts/required-consts/collect-in-dead-vtable.rs @@ -1,15 +1,12 @@ //@revisions: noopt opt -//@[noopt] build-fail +//@ build-fail +//@[noopt] compile-flags: -Copt-level=0 //@[opt] compile-flags: -O -//FIXME: `opt` revision currently does not stop with an error due to -//<https://github.com/rust-lang/rust/issues/107503>. -//@[opt] build-pass -//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is -//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090) +//! This fails without optimizations, so it should also fail with optimizations. struct Fail<T>(T); impl<T> Fail<T> { - const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::<i32>::C` failed + const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed } trait MyTrait { @@ -18,8 +15,7 @@ trait MyTrait { // This function is not actually called, but it is mentioned in a vtable in a function that is // called. Make sure we still find this error. -// This relies on mono-item collection checking `required_consts` in functions that are referenced -// in vtables that syntactically appear in collected functions (even inside dead code). +// This ensures that we are properly considering vtables when gathering "mentioned" items. impl<T> MyTrait for Vec<T> { fn not_called(&self) { if false { @@ -32,7 +28,7 @@ impl<T> MyTrait for Vec<T> { fn called<T>() { if false { let v: Vec<T> = Vec::new(); - let gen_vtable: &dyn MyTrait = &v; // vtable "appears" here + let gen_vtable: &dyn MyTrait = &v; // vtable is "mentioned" here } } diff --git a/tests/ui/consts/required-consts/interpret-in-const-called-fn.noopt.stderr b/tests/ui/consts/required-consts/interpret-in-const-called-fn.noopt.stderr index 75304591b9f..0e3bbbcc2ec 100644 --- a/tests/ui/consts/required-consts/interpret-in-const-called-fn.noopt.stderr +++ b/tests/ui/consts/required-consts/interpret-in-const-called-fn.noopt.stderr @@ -1,13 +1,13 @@ error[E0080]: evaluation of `Fail::<i32>::C` failed - --> $DIR/interpret-in-const-called-fn.rs:7:19 + --> $DIR/interpret-in-const-called-fn.rs:8:19 | LL | const C: () = panic!(); - | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/interpret-in-const-called-fn.rs:7:19 + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/interpret-in-const-called-fn.rs:8:19 | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered - --> $DIR/interpret-in-const-called-fn.rs:16:9 + --> $DIR/interpret-in-const-called-fn.rs:17:9 | LL | Fail::<T>::C; | ^^^^^^^^^^^^ diff --git a/tests/ui/consts/required-consts/interpret-in-const-called-fn.opt.stderr b/tests/ui/consts/required-consts/interpret-in-const-called-fn.opt.stderr index 75304591b9f..0e3bbbcc2ec 100644 --- a/tests/ui/consts/required-consts/interpret-in-const-called-fn.opt.stderr +++ b/tests/ui/consts/required-consts/interpret-in-const-called-fn.opt.stderr @@ -1,13 +1,13 @@ error[E0080]: evaluation of `Fail::<i32>::C` failed - --> $DIR/interpret-in-const-called-fn.rs:7:19 + --> $DIR/interpret-in-const-called-fn.rs:8:19 | LL | const C: () = panic!(); - | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/interpret-in-const-called-fn.rs:7:19 + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/interpret-in-const-called-fn.rs:8:19 | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered - --> $DIR/interpret-in-const-called-fn.rs:16:9 + --> $DIR/interpret-in-const-called-fn.rs:17:9 | LL | Fail::<T>::C; | ^^^^^^^^^^^^ diff --git a/tests/ui/consts/required-consts/interpret-in-const-called-fn.rs b/tests/ui/consts/required-consts/interpret-in-const-called-fn.rs index c409fae0bb9..f2e83f56f37 100644 --- a/tests/ui/consts/required-consts/interpret-in-const-called-fn.rs +++ b/tests/ui/consts/required-consts/interpret-in-const-called-fn.rs @@ -1,4 +1,5 @@ //@revisions: noopt opt +//@[noopt] compile-flags: -Copt-level=0 //@[opt] compile-flags: -O //! Make sure we error on erroneous consts even if they are unused. diff --git a/tests/ui/consts/required-consts/interpret-in-promoted.noopt.stderr b/tests/ui/consts/required-consts/interpret-in-promoted.noopt.stderr index 491131daf8d..6ab991b6471 100644 --- a/tests/ui/consts/required-consts/interpret-in-promoted.noopt.stderr +++ b/tests/ui/consts/required-consts/interpret-in-promoted.noopt.stderr @@ -6,18 +6,18 @@ error[E0080]: evaluation of constant value failed note: inside `unreachable_unchecked` --> $SRC_DIR/core/src/hint.rs:LL:COL note: inside `ub` - --> $DIR/interpret-in-promoted.rs:6:5 + --> $DIR/interpret-in-promoted.rs:7:5 | LL | std::hint::unreachable_unchecked(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: inside `FOO` - --> $DIR/interpret-in-promoted.rs:12:28 + --> $DIR/interpret-in-promoted.rs:13:28 | LL | let _x: &'static () = &ub(); | ^^^^ note: erroneous constant encountered - --> $DIR/interpret-in-promoted.rs:12:27 + --> $DIR/interpret-in-promoted.rs:13:27 | LL | let _x: &'static () = &ub(); | ^^^^^ diff --git a/tests/ui/consts/required-consts/interpret-in-promoted.opt.stderr b/tests/ui/consts/required-consts/interpret-in-promoted.opt.stderr index 491131daf8d..6ab991b6471 100644 --- a/tests/ui/consts/required-consts/interpret-in-promoted.opt.stderr +++ b/tests/ui/consts/required-consts/interpret-in-promoted.opt.stderr @@ -6,18 +6,18 @@ error[E0080]: evaluation of constant value failed note: inside `unreachable_unchecked` --> $SRC_DIR/core/src/hint.rs:LL:COL note: inside `ub` - --> $DIR/interpret-in-promoted.rs:6:5 + --> $DIR/interpret-in-promoted.rs:7:5 | LL | std::hint::unreachable_unchecked(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: inside `FOO` - --> $DIR/interpret-in-promoted.rs:12:28 + --> $DIR/interpret-in-promoted.rs:13:28 | LL | let _x: &'static () = &ub(); | ^^^^ note: erroneous constant encountered - --> $DIR/interpret-in-promoted.rs:12:27 + --> $DIR/interpret-in-promoted.rs:13:27 | LL | let _x: &'static () = &ub(); | ^^^^^ diff --git a/tests/ui/consts/required-consts/interpret-in-promoted.rs b/tests/ui/consts/required-consts/interpret-in-promoted.rs index 9c2cf4e70d3..187494180ad 100644 --- a/tests/ui/consts/required-consts/interpret-in-promoted.rs +++ b/tests/ui/consts/required-consts/interpret-in-promoted.rs @@ -1,4 +1,5 @@ //@revisions: noopt opt +//@[noopt] compile-flags: -Copt-level=0 //@[opt] compile-flags: -O //! Make sure we error on erroneous consts even if they are unused. diff --git a/tests/ui/consts/required-consts/interpret-in-static.noopt.stderr b/tests/ui/consts/required-consts/interpret-in-static.noopt.stderr index 159c9449fc0..5e8da609e76 100644 --- a/tests/ui/consts/required-consts/interpret-in-static.noopt.stderr +++ b/tests/ui/consts/required-consts/interpret-in-static.noopt.stderr @@ -1,13 +1,13 @@ error[E0080]: evaluation of `Fail::<i32>::C` failed - --> $DIR/interpret-in-static.rs:7:19 + --> $DIR/interpret-in-static.rs:8:19 | LL | const C: () = panic!(); - | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/interpret-in-static.rs:7:19 + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/interpret-in-static.rs:8:19 | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered - --> $DIR/interpret-in-static.rs:15:9 + --> $DIR/interpret-in-static.rs:16:9 | LL | Fail::<i32>::C; | ^^^^^^^^^^^^^^ diff --git a/tests/ui/consts/required-consts/interpret-in-static.opt.stderr b/tests/ui/consts/required-consts/interpret-in-static.opt.stderr index 159c9449fc0..5e8da609e76 100644 --- a/tests/ui/consts/required-consts/interpret-in-static.opt.stderr +++ b/tests/ui/consts/required-consts/interpret-in-static.opt.stderr @@ -1,13 +1,13 @@ error[E0080]: evaluation of `Fail::<i32>::C` failed - --> $DIR/interpret-in-static.rs:7:19 + --> $DIR/interpret-in-static.rs:8:19 | LL | const C: () = panic!(); - | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/interpret-in-static.rs:7:19 + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/interpret-in-static.rs:8:19 | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered - --> $DIR/interpret-in-static.rs:15:9 + --> $DIR/interpret-in-static.rs:16:9 | LL | Fail::<i32>::C; | ^^^^^^^^^^^^^^ diff --git a/tests/ui/consts/required-consts/interpret-in-static.rs b/tests/ui/consts/required-consts/interpret-in-static.rs index 559e281b2b0..8bacd030440 100644 --- a/tests/ui/consts/required-consts/interpret-in-static.rs +++ b/tests/ui/consts/required-consts/interpret-in-static.rs @@ -1,4 +1,5 @@ //@revisions: noopt opt +//@[noopt] compile-flags: -Copt-level=0 //@[opt] compile-flags: -O //! Make sure we error on erroneous consts even if they are unused. diff --git a/tests/ui/consts/try-operator.stderr b/tests/ui/consts/try-operator.stderr index c19d1a6199d..2c8b4c7fcd9 100644 --- a/tests/ui/consts/try-operator.stderr +++ b/tests/ui/consts/try-operator.stderr @@ -13,7 +13,10 @@ LL | Err(())?; note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/result.rs:LL:COL = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: `?` cannot convert from residual of `Result<bool, ()>` in constant functions --> $DIR/try-operator.rs:10:9 @@ -24,7 +27,10 @@ LL | Err(())?; note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/result.rs:LL:COL = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: `?` cannot determine the branch of `Option<()>` in constant functions --> $DIR/try-operator.rs:18:9 @@ -35,7 +41,10 @@ LL | None?; note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/option.rs:LL:COL = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: `?` cannot convert from residual of `Option<()>` in constant functions --> $DIR/try-operator.rs:18:9 @@ -46,7 +55,10 @@ LL | None?; note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/option.rs:LL:COL = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 5 previous errors diff --git a/tests/ui/consts/unstable-const-fn-in-libcore.stderr b/tests/ui/consts/unstable-const-fn-in-libcore.stderr index ee4a0f6a843..9590b3372e3 100644 --- a/tests/ui/consts/unstable-const-fn-in-libcore.stderr +++ b/tests/ui/consts/unstable-const-fn-in-libcore.stderr @@ -11,11 +11,14 @@ LL | Opt::None => f(), | ^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable help: consider further restricting this bound | LL | const fn unwrap_or_else<F: ~const FnOnce() -> T + ~const std::ops::FnOnce<()>>(self, f: F) -> T { | +++++++++++++++++++++++++++++ +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0493]: destructor of `F` cannot be evaluated at compile-time --> $DIR/unstable-const-fn-in-libcore.rs:19:60 diff --git a/tests/ui/coroutine/gen_block_is_fused_iter.rs b/tests/ui/coroutine/gen_block_is_fused_iter.rs new file mode 100644 index 00000000000..f3e19a7f54f --- /dev/null +++ b/tests/ui/coroutine/gen_block_is_fused_iter.rs @@ -0,0 +1,21 @@ +//@ revisions: next old +//@compile-flags: --edition 2024 -Zunstable-options +//@[next] compile-flags: -Znext-solver +//@ check-pass +#![feature(gen_blocks)] + +use std::iter::FusedIterator; + +fn foo() -> impl FusedIterator { + gen { yield 42 } +} + +fn bar() -> impl FusedIterator<Item = u16> { + gen { yield 42 } +} + +fn baz() -> impl FusedIterator + Iterator<Item = i64> { + gen { yield 42 } +} + +fn main() {} diff --git a/tests/ui/coroutine/issue-68112.rs b/tests/ui/coroutine/issue-68112.rs index e2be704dab7..ccec2acc976 100644 --- a/tests/ui/coroutine/issue-68112.rs +++ b/tests/ui/coroutine/issue-68112.rs @@ -65,7 +65,6 @@ fn test2() { //~^ ERROR `RefCell<i32>` cannot be shared between threads safely //~| NOTE `RefCell<i32>` cannot be shared between threads safely //~| NOTE required for - //~| NOTE captures the following types //~| NOTE use `std::sync::RwLock` instead } diff --git a/tests/ui/coroutine/issue-68112.stderr b/tests/ui/coroutine/issue-68112.stderr index ded325eda54..443195d36a3 100644 --- a/tests/ui/coroutine/issue-68112.stderr +++ b/tests/ui/coroutine/issue-68112.stderr @@ -44,7 +44,6 @@ note: required because it appears within the type `impl Coroutine<Return = Arc<R | LL | fn make_non_send_coroutine2() -> impl Coroutine<Return = Arc<RefCell<i32>>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: required because it captures the following types: `impl Coroutine<Return = Arc<RefCell<i32>>>` note: required because it's used within this coroutine --> $DIR/issue-68112.rs:60:20 | diff --git a/tests/ui/coroutine/print/coroutine-print-verbose-1.stderr b/tests/ui/coroutine/print/coroutine-print-verbose-1.stderr index 1b9ca632f0c..37db83d57f7 100644 --- a/tests/ui/coroutine/print/coroutine-print-verbose-1.stderr +++ b/tests/ui/coroutine/print/coroutine-print-verbose-1.stderr @@ -43,7 +43,6 @@ note: required because it appears within the type `Opaque(DefId(0:36 ~ coroutine | LL | fn make_non_send_coroutine2() -> impl Coroutine<Return = Arc<RefCell<i32>>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: required because it captures the following types: `Opaque(DefId(0:36 ~ coroutine_print_verbose_1[75fb]::make_non_send_coroutine2::{opaque#0}), [])` note: required because it's used within this coroutine --> $DIR/coroutine-print-verbose-1.rs:52:20 | diff --git a/tests/ui/cross-crate/auxiliary/static_init_aux.rs b/tests/ui/cross-crate/auxiliary/static_init_aux.rs index 5e172ef3198..dca708733b9 100644 --- a/tests/ui/cross-crate/auxiliary/static_init_aux.rs +++ b/tests/ui/cross-crate/auxiliary/static_init_aux.rs @@ -1,6 +1,8 @@ pub static V: &u32 = &X; pub static F: fn() = f; pub static G: fn() = G0; +pub static H: &(dyn Fn() + Sync) = &h; +pub static I: fn() = Helper(j).mk(); static X: u32 = 42; static G0: fn() = g; @@ -12,3 +14,22 @@ pub fn v() -> *const u32 { fn f() {} fn g() {} + +fn h() {} + +#[derive(Copy, Clone)] +struct Helper<T: Copy>(T); + +impl<T: Copy + FnOnce()> Helper<T> { + const fn mk(self) -> fn() { + i::<T> + } +} + +fn i<T: FnOnce()>() { + assert_eq!(std::mem::size_of::<T>(), 0); + // unsafe to work around the lack of a `Default` impl for function items + unsafe { (std::mem::transmute_copy::<(), T>(&()))() } +} + +fn j() {} diff --git a/tests/ui/cross-crate/static-init.rs b/tests/ui/cross-crate/static-init.rs index 090ad5f810e..c4697a1d010 100644 --- a/tests/ui/cross-crate/static-init.rs +++ b/tests/ui/cross-crate/static-init.rs @@ -6,6 +6,8 @@ extern crate static_init_aux as aux; static V: &u32 = aux::V; static F: fn() = aux::F; static G: fn() = aux::G; +static H: &(dyn Fn() + Sync) = aux::H; +static I: fn() = aux::I; fn v() -> *const u32 { V @@ -15,4 +17,6 @@ fn main() { assert_eq!(aux::v(), crate::v()); F(); G(); + H(); + I(); } diff --git a/tests/ui/cross/cross-fn-cache-hole.stderr b/tests/ui/cross/cross-fn-cache-hole.stderr index dec2f2553c2..b7bcbc8933f 100644 --- a/tests/ui/cross/cross-fn-cache-hole.stderr +++ b/tests/ui/cross/cross-fn-cache-hole.stderr @@ -10,7 +10,10 @@ help: this trait has no implementations, consider adding one LL | trait Bar<X> { } | ^^^^^^^^^^^^ = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the trait bound `i32: Bar<u32>` is not satisfied --> $DIR/cross-fn-cache-hole.rs:30:15 diff --git a/tests/ui/delegation/duplicate-definition-inside-trait-impl.rs b/tests/ui/delegation/duplicate-definition-inside-trait-impl.rs new file mode 100644 index 00000000000..bd685b40b2f --- /dev/null +++ b/tests/ui/delegation/duplicate-definition-inside-trait-impl.rs @@ -0,0 +1,23 @@ +#![feature(fn_delegation)] +//~^ WARN the feature `fn_delegation` is incomplete + +trait Trait { + fn foo(&self) -> u32 { 0 } +} + +struct F; +struct S; + +mod to_reuse { + use crate::S; + + pub fn foo(_: &S) -> u32 { 0 } +} + +impl Trait for S { + reuse to_reuse::foo { self } + reuse Trait::foo; + //~^ ERROR duplicate definitions with name `foo` +} + +fn main() {} diff --git a/tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr b/tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr new file mode 100644 index 00000000000..a5f9e6ad0bf --- /dev/null +++ b/tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr @@ -0,0 +1,23 @@ +error[E0201]: duplicate definitions with name `foo`: + --> $DIR/duplicate-definition-inside-trait-impl.rs:19:5 + | +LL | fn foo(&self) -> u32 { 0 } + | -------------------------- item in trait +... +LL | reuse to_reuse::foo { self } + | ---------------------------- previous definition here +LL | reuse Trait::foo; + | ^^^^^^^^^^^^^^^^^ duplicate definition + +warning: the feature `fn_delegation` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/duplicate-definition-inside-trait-impl.rs:1:12 + | +LL | #![feature(fn_delegation)] + | ^^^^^^^^^^^^^ + | + = note: see issue #118212 <https://github.com/rust-lang/rust/issues/118212> for more information + = note: `#[warn(incomplete_features)]` on by default + +error: aborting due to 1 previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0201`. diff --git a/tests/ui/diagnostic-flags/colored-session-opt-error.svg b/tests/ui/diagnostic-flags/colored-session-opt-error.svg index e8835534e04..69f452f29f3 100644 --- a/tests/ui/diagnostic-flags/colored-session-opt-error.svg +++ b/tests/ui/diagnostic-flags/colored-session-opt-error.svg @@ -1,4 +1,4 @@ -<svg width="740px" height="74px" xmlns="http://www.w3.org/2000/svg"> +<svg width="750px" height="74px" xmlns="http://www.w3.org/2000/svg"> <style> .fg { fill: #AAAAAA } .bg { background: #000000 } diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/broken_format.rs b/tests/ui/diagnostic_namespace/on_unimplemented/broken_format.rs new file mode 100644 index 00000000000..8d8917fd319 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/broken_format.rs @@ -0,0 +1,45 @@ +#[diagnostic::on_unimplemented(message = "{{Test } thing")] +//~^WARN unmatched `}` found +//~|WARN unmatched `}` found +trait ImportantTrait1 {} + +#[diagnostic::on_unimplemented(message = "Test {}")] +//~^WARN positional format arguments are not allowed here +//~|WARN positional format arguments are not allowed here +trait ImportantTrait2 {} + +#[diagnostic::on_unimplemented(message = "Test {1:}")] +//~^WARN positional format arguments are not allowed here +//~|WARN positional format arguments are not allowed here +trait ImportantTrait3 {} + +#[diagnostic::on_unimplemented(message = "Test {Self:123}")] +//~^WARN invalid format specifier +//~|WARN invalid format specifier +trait ImportantTrait4 {} + +#[diagnostic::on_unimplemented(message = "Test {Self:!}")] +//~^WARN expected `'}'`, found `'!'` +//~|WARN expected `'}'`, found `'!'` +//~|WARN unmatched `}` found +//~|WARN unmatched `}` found +trait ImportantTrait5 {} + +fn check_1(_: impl ImportantTrait1) {} +fn check_2(_: impl ImportantTrait2) {} +fn check_3(_: impl ImportantTrait3) {} +fn check_4(_: impl ImportantTrait4) {} +fn check_5(_: impl ImportantTrait5) {} + +fn main() { + check_1(()); + //~^ERROR {{Test } thing + check_2(()); + //~^ERROR Test {} + check_3(()); + //~^ERROR Test {1} + check_4(()); + //~^ERROR Test () + check_5(()); + //~^ERROR Test {Self:!} +} diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/broken_format.stderr b/tests/ui/diagnostic_namespace/on_unimplemented/broken_format.stderr new file mode 100644 index 00000000000..932e81ca48e --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/broken_format.stderr @@ -0,0 +1,193 @@ +warning: unmatched `}` found + --> $DIR/broken_format.rs:1:32 + | +LL | #[diagnostic::on_unimplemented(message = "{{Test } thing")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default + +warning: positional format arguments are not allowed here + --> $DIR/broken_format.rs:6:32 + | +LL | #[diagnostic::on_unimplemented(message = "Test {}")] + | ^^^^^^^^^^^^^^^^^^^ + | + = help: only named format arguments with the name of one of the generic types are allowed in this context + +warning: positional format arguments are not allowed here + --> $DIR/broken_format.rs:11:32 + | +LL | #[diagnostic::on_unimplemented(message = "Test {1:}")] + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: only named format arguments with the name of one of the generic types are allowed in this context + +warning: invalid format specifier + --> $DIR/broken_format.rs:16:32 + | +LL | #[diagnostic::on_unimplemented(message = "Test {Self:123}")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: no format specifier are supported in this position + +warning: expected `'}'`, found `'!'` + --> $DIR/broken_format.rs:21:32 + | +LL | #[diagnostic::on_unimplemented(message = "Test {Self:!}")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unmatched `}` found + --> $DIR/broken_format.rs:21:32 + | +LL | #[diagnostic::on_unimplemented(message = "Test {Self:!}")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: unmatched `}` found + --> $DIR/broken_format.rs:1:32 + | +LL | #[diagnostic::on_unimplemented(message = "{{Test } thing")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0277]: {{Test } thing + --> $DIR/broken_format.rs:35:13 + | +LL | check_1(()); + | ------- ^^ the trait `ImportantTrait1` is not implemented for `()` + | | + | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/broken_format.rs:4:1 + | +LL | trait ImportantTrait1 {} + | ^^^^^^^^^^^^^^^^^^^^^ +note: required by a bound in `check_1` + --> $DIR/broken_format.rs:28:20 + | +LL | fn check_1(_: impl ImportantTrait1) {} + | ^^^^^^^^^^^^^^^ required by this bound in `check_1` + +warning: positional format arguments are not allowed here + --> $DIR/broken_format.rs:6:32 + | +LL | #[diagnostic::on_unimplemented(message = "Test {}")] + | ^^^^^^^^^^^^^^^^^^^ + | + = help: only named format arguments with the name of one of the generic types are allowed in this context + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0277]: Test {} + --> $DIR/broken_format.rs:37:13 + | +LL | check_2(()); + | ------- ^^ the trait `ImportantTrait2` is not implemented for `()` + | | + | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/broken_format.rs:9:1 + | +LL | trait ImportantTrait2 {} + | ^^^^^^^^^^^^^^^^^^^^^ +note: required by a bound in `check_2` + --> $DIR/broken_format.rs:29:20 + | +LL | fn check_2(_: impl ImportantTrait2) {} + | ^^^^^^^^^^^^^^^ required by this bound in `check_2` + +warning: positional format arguments are not allowed here + --> $DIR/broken_format.rs:11:32 + | +LL | #[diagnostic::on_unimplemented(message = "Test {1:}")] + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: only named format arguments with the name of one of the generic types are allowed in this context + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0277]: Test {1} + --> $DIR/broken_format.rs:39:13 + | +LL | check_3(()); + | ------- ^^ the trait `ImportantTrait3` is not implemented for `()` + | | + | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/broken_format.rs:14:1 + | +LL | trait ImportantTrait3 {} + | ^^^^^^^^^^^^^^^^^^^^^ +note: required by a bound in `check_3` + --> $DIR/broken_format.rs:30:20 + | +LL | fn check_3(_: impl ImportantTrait3) {} + | ^^^^^^^^^^^^^^^ required by this bound in `check_3` + +warning: invalid format specifier + --> $DIR/broken_format.rs:16:32 + | +LL | #[diagnostic::on_unimplemented(message = "Test {Self:123}")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: no format specifier are supported in this position + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0277]: Test () + --> $DIR/broken_format.rs:41:13 + | +LL | check_4(()); + | ------- ^^ the trait `ImportantTrait4` is not implemented for `()` + | | + | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/broken_format.rs:19:1 + | +LL | trait ImportantTrait4 {} + | ^^^^^^^^^^^^^^^^^^^^^ +note: required by a bound in `check_4` + --> $DIR/broken_format.rs:31:20 + | +LL | fn check_4(_: impl ImportantTrait4) {} + | ^^^^^^^^^^^^^^^ required by this bound in `check_4` + +warning: expected `'}'`, found `'!'` + --> $DIR/broken_format.rs:21:32 + | +LL | #[diagnostic::on_unimplemented(message = "Test {Self:!}")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: unmatched `}` found + --> $DIR/broken_format.rs:21:32 + | +LL | #[diagnostic::on_unimplemented(message = "Test {Self:!}")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0277]: Test {Self:!} + --> $DIR/broken_format.rs:43:13 + | +LL | check_5(()); + | ------- ^^ the trait `ImportantTrait5` is not implemented for `()` + | | + | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/broken_format.rs:26:1 + | +LL | trait ImportantTrait5 {} + | ^^^^^^^^^^^^^^^^^^^^^ +note: required by a bound in `check_5` + --> $DIR/broken_format.rs:32:20 + | +LL | fn check_5(_: impl ImportantTrait5) {} + | ^^^^^^^^^^^^^^^ required by this bound in `check_5` + +error: aborting due to 5 previous errors; 12 warnings emitted + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/entry-point/imported_main_conflict.rs b/tests/ui/entry-point/imported_main_conflict.rs index e8c70b06513..06178dbeff7 100644 --- a/tests/ui/entry-point/imported_main_conflict.rs +++ b/tests/ui/entry-point/imported_main_conflict.rs @@ -1,5 +1,4 @@ -#![feature(imported_main)] -//~^ ERROR `main` is ambiguous +//~ ERROR `main` is ambiguous mod m1 { pub(crate) fn main() {} } mod m2 { pub(crate) fn main() {} } diff --git a/tests/ui/entry-point/imported_main_conflict.stderr b/tests/ui/entry-point/imported_main_conflict.stderr index 783e9345acf..3ef34962524 100644 --- a/tests/ui/entry-point/imported_main_conflict.stderr +++ b/tests/ui/entry-point/imported_main_conflict.stderr @@ -2,13 +2,13 @@ error[E0659]: `main` is ambiguous | = note: ambiguous because of multiple glob imports of a name in the same module note: `main` could refer to the function imported here - --> $DIR/imported_main_conflict.rs:6:5 + --> $DIR/imported_main_conflict.rs:5:5 | LL | use m1::*; | ^^^^^ = help: consider adding an explicit import of `main` to disambiguate note: `main` could also refer to the function imported here - --> $DIR/imported_main_conflict.rs:7:5 + --> $DIR/imported_main_conflict.rs:6:5 | LL | use m2::*; | ^^^^^ diff --git a/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs index 405d6e2a9f5..d0be240e07b 100644 --- a/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs +++ b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs @@ -1,4 +1,3 @@ -#![feature(imported_main)] #![feature(type_alias_impl_trait)] #![allow(incomplete_features)] pub mod foo { diff --git a/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr index 1e7d82a73bc..50e4cd7d39f 100644 --- a/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr +++ b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr @@ -1,5 +1,5 @@ error[E0601]: `main` function not found in crate `imported_main_const_fn_item_type_forbidden` - --> $DIR/imported_main_const_fn_item_type_forbidden.rs:11:22 + --> $DIR/imported_main_const_fn_item_type_forbidden.rs:10:22 | LL | use foo::BAR as main; | ---------------- ^ consider adding a `main` function to `$DIR/imported_main_const_fn_item_type_forbidden.rs` diff --git a/tests/ui/entry-point/imported_main_const_forbidden.rs b/tests/ui/entry-point/imported_main_const_forbidden.rs index 1508280c0fa..c478e004603 100644 --- a/tests/ui/entry-point/imported_main_const_forbidden.rs +++ b/tests/ui/entry-point/imported_main_const_forbidden.rs @@ -1,4 +1,3 @@ -#![feature(imported_main)] pub mod foo { pub const BAR: usize = 42; } diff --git a/tests/ui/entry-point/imported_main_const_forbidden.stderr b/tests/ui/entry-point/imported_main_const_forbidden.stderr index 6f34015a2cd..eb768b1b250 100644 --- a/tests/ui/entry-point/imported_main_const_forbidden.stderr +++ b/tests/ui/entry-point/imported_main_const_forbidden.stderr @@ -1,5 +1,5 @@ error[E0601]: `main` function not found in crate `imported_main_const_forbidden` - --> $DIR/imported_main_const_forbidden.rs:6:22 + --> $DIR/imported_main_const_forbidden.rs:5:22 | LL | use foo::BAR as main; | ---------------- ^ consider adding a `main` function to `$DIR/imported_main_const_forbidden.rs` diff --git a/tests/ui/entry-point/imported_main_from_extern_crate.rs b/tests/ui/entry-point/imported_main_from_extern_crate.rs index abcf2cbc05b..6d1c497052e 100644 --- a/tests/ui/entry-point/imported_main_from_extern_crate.rs +++ b/tests/ui/entry-point/imported_main_from_extern_crate.rs @@ -1,7 +1,5 @@ //@ run-pass //@ aux-build:main_functions.rs -#![feature(imported_main)] - extern crate main_functions; pub use main_functions::boilerplate as main; diff --git a/tests/ui/entry-point/imported_main_from_extern_crate_wrong_type.rs b/tests/ui/entry-point/imported_main_from_extern_crate_wrong_type.rs index 82d81a93d9d..d8ae12d200f 100644 --- a/tests/ui/entry-point/imported_main_from_extern_crate_wrong_type.rs +++ b/tests/ui/entry-point/imported_main_from_extern_crate_wrong_type.rs @@ -1,6 +1,4 @@ //@ aux-build:bad_main_functions.rs -#![feature(imported_main)] - extern crate bad_main_functions; pub use bad_main_functions::boilerplate as main; diff --git a/tests/ui/entry-point/imported_main_from_inner_mod.rs b/tests/ui/entry-point/imported_main_from_inner_mod.rs index 7212dd6182c..cede1766118 100644 --- a/tests/ui/entry-point/imported_main_from_inner_mod.rs +++ b/tests/ui/entry-point/imported_main_from_inner_mod.rs @@ -1,5 +1,4 @@ //@ run-pass -#![feature(imported_main)] pub mod foo { pub fn bar() { diff --git a/tests/ui/extenv/extenv-arg-2-not-string-literal.rs b/tests/ui/env-macro/env-arg-2-not-string-literal.rs index 66dced478f9..66dced478f9 100644 --- a/tests/ui/extenv/extenv-arg-2-not-string-literal.rs +++ b/tests/ui/env-macro/env-arg-2-not-string-literal.rs diff --git a/tests/ui/extenv/extenv-arg-2-not-string-literal.stderr b/tests/ui/env-macro/env-arg-2-not-string-literal.stderr index 9db1c0be746..843ce4823ea 100644 --- a/tests/ui/extenv/extenv-arg-2-not-string-literal.stderr +++ b/tests/ui/env-macro/env-arg-2-not-string-literal.stderr @@ -1,5 +1,5 @@ error: expected string literal - --> $DIR/extenv-arg-2-not-string-literal.rs:1:25 + --> $DIR/env-arg-2-not-string-literal.rs:1:25 | LL | fn main() { env!("one", 10); } | ^^ diff --git a/tests/ui/extenv/extenv-env-overload.rs b/tests/ui/env-macro/env-env-overload.rs index b3497ffbc88..b3497ffbc88 100644 --- a/tests/ui/extenv/extenv-env-overload.rs +++ b/tests/ui/env-macro/env-env-overload.rs diff --git a/tests/ui/extenv/extenv-env.rs b/tests/ui/env-macro/env-env.rs index 18226256b64..18226256b64 100644 --- a/tests/ui/extenv/extenv-env.rs +++ b/tests/ui/env-macro/env-env.rs diff --git a/tests/ui/extenv/extenv-escaped-var.rs b/tests/ui/env-macro/env-escaped-var.rs index d898feb78c6..d898feb78c6 100644 --- a/tests/ui/extenv/extenv-escaped-var.rs +++ b/tests/ui/env-macro/env-escaped-var.rs diff --git a/tests/ui/extenv/extenv-escaped-var.stderr b/tests/ui/env-macro/env-escaped-var.stderr index ef5e654d054..53a2ead6742 100644 --- a/tests/ui/extenv/extenv-escaped-var.stderr +++ b/tests/ui/env-macro/env-escaped-var.stderr @@ -1,5 +1,5 @@ error: environment variable `\t` not defined at compile time - --> $DIR/extenv-escaped-var.rs:2:5 + --> $DIR/env-escaped-var.rs:2:5 | LL | env!("\t"); | ^^^^^^^^^^ diff --git a/tests/ui/extenv/extenv-no-args.rs b/tests/ui/env-macro/env-no-args.rs index 2ff6d242b27..2ff6d242b27 100644 --- a/tests/ui/extenv/extenv-no-args.rs +++ b/tests/ui/env-macro/env-no-args.rs diff --git a/tests/ui/extenv/extenv-no-args.stderr b/tests/ui/env-macro/env-no-args.stderr index 36d485676c2..3a94b36cd0f 100644 --- a/tests/ui/extenv/extenv-no-args.stderr +++ b/tests/ui/env-macro/env-no-args.stderr @@ -1,5 +1,5 @@ error: `env!()` takes 1 or 2 arguments - --> $DIR/extenv-no-args.rs:1:13 + --> $DIR/env-no-args.rs:1:13 | LL | fn main() { env!(); } | ^^^^^^ diff --git a/tests/ui/extenv/extenv-not-defined-custom.rs b/tests/ui/env-macro/env-not-defined-custom.rs index 30b72783f5c..30b72783f5c 100644 --- a/tests/ui/extenv/extenv-not-defined-custom.rs +++ b/tests/ui/env-macro/env-not-defined-custom.rs diff --git a/tests/ui/extenv/extenv-not-defined-custom.stderr b/tests/ui/env-macro/env-not-defined-custom.stderr index 9b6e32bc95f..70c41bcc52e 100644 --- a/tests/ui/extenv/extenv-not-defined-custom.stderr +++ b/tests/ui/env-macro/env-not-defined-custom.stderr @@ -1,5 +1,5 @@ error: my error message - --> $DIR/extenv-not-defined-custom.rs:1:13 + --> $DIR/env-not-defined-custom.rs:1:13 | LL | fn main() { env!("__HOPEFULLY_NOT_DEFINED__", "my error message"); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/extenv/extenv-not-defined-default.rs b/tests/ui/env-macro/env-not-defined-default.rs index 1fb046c78f2..1fb046c78f2 100644 --- a/tests/ui/extenv/extenv-not-defined-default.rs +++ b/tests/ui/env-macro/env-not-defined-default.rs diff --git a/tests/ui/extenv/extenv-not-defined-default.stderr b/tests/ui/env-macro/env-not-defined-default.stderr index 5198818f89c..efd7fdb4e53 100644 --- a/tests/ui/extenv/extenv-not-defined-default.stderr +++ b/tests/ui/env-macro/env-not-defined-default.stderr @@ -1,5 +1,5 @@ error: environment variable `CARGO__HOPEFULLY_NOT_DEFINED__` not defined at compile time - --> $DIR/extenv-not-defined-default.rs:2:5 + --> $DIR/env-not-defined-default.rs:2:5 | LL | env!("CARGO__HOPEFULLY_NOT_DEFINED__"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/extenv/extenv-not-env.rs b/tests/ui/env-macro/env-not-env.rs index e903eab4e96..e903eab4e96 100644 --- a/tests/ui/extenv/extenv-not-env.rs +++ b/tests/ui/env-macro/env-not-env.rs diff --git a/tests/ui/extenv/extenv-not-string-literal.rs b/tests/ui/env-macro/env-not-string-literal.rs index 3eaa0b5daaf..3eaa0b5daaf 100644 --- a/tests/ui/extenv/extenv-not-string-literal.rs +++ b/tests/ui/env-macro/env-not-string-literal.rs diff --git a/tests/ui/extenv/extenv-not-string-literal.stderr b/tests/ui/env-macro/env-not-string-literal.stderr index 85ed442e2fe..0985459eff9 100644 --- a/tests/ui/extenv/extenv-not-string-literal.stderr +++ b/tests/ui/env-macro/env-not-string-literal.stderr @@ -1,5 +1,5 @@ error: expected string literal - --> $DIR/extenv-not-string-literal.rs:1:18 + --> $DIR/env-not-string-literal.rs:1:18 | LL | fn main() { env!(10, "two"); } | ^^ diff --git a/tests/ui/extenv/extenv-too-many-args.rs b/tests/ui/env-macro/env-too-many-args.rs index ffad1c51303..ffad1c51303 100644 --- a/tests/ui/extenv/extenv-too-many-args.rs +++ b/tests/ui/env-macro/env-too-many-args.rs diff --git a/tests/ui/extenv/extenv-too-many-args.stderr b/tests/ui/env-macro/env-too-many-args.stderr index c0fd5d57251..f156026846a 100644 --- a/tests/ui/extenv/extenv-too-many-args.stderr +++ b/tests/ui/env-macro/env-too-many-args.stderr @@ -1,5 +1,5 @@ error: `env!()` takes 1 or 2 arguments - --> $DIR/extenv-too-many-args.rs:1:13 + --> $DIR/env-too-many-args.rs:1:13 | LL | fn main() { env!("one", "two", "three"); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/extenv/issue-55897.rs b/tests/ui/env-macro/error-recovery-issue-55897.rs index b6500e54059..b6500e54059 100644 --- a/tests/ui/extenv/issue-55897.rs +++ b/tests/ui/env-macro/error-recovery-issue-55897.rs diff --git a/tests/ui/extenv/issue-55897.stderr b/tests/ui/env-macro/error-recovery-issue-55897.stderr index 2e8c05cca86..5a20bf8b168 100644 --- a/tests/ui/extenv/issue-55897.stderr +++ b/tests/ui/env-macro/error-recovery-issue-55897.stderr @@ -1,5 +1,5 @@ error: environment variable `NON_EXISTENT` not defined at compile time - --> $DIR/issue-55897.rs:10:22 + --> $DIR/error-recovery-issue-55897.rs:10:22 | LL | include!(concat!(env!("NON_EXISTENT"), "/data.rs")); | ^^^^^^^^^^^^^^^^^^^^ @@ -8,13 +8,13 @@ LL | include!(concat!(env!("NON_EXISTENT"), "/data.rs")); = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info) error: suffixes on string literals are invalid - --> $DIR/issue-55897.rs:15:22 + --> $DIR/error-recovery-issue-55897.rs:15:22 | LL | include!(concat!("NON_EXISTENT"suffix, "/data.rs")); | ^^^^^^^^^^^^^^^^^^^^ invalid suffix `suffix` error[E0432]: unresolved import `prelude` - --> $DIR/issue-55897.rs:1:5 + --> $DIR/error-recovery-issue-55897.rs:1:5 | LL | use prelude::*; | ^^^^^^^ @@ -23,7 +23,7 @@ LL | use prelude::*; | help: a similar path exists: `std::prelude` error[E0432]: unresolved import `env` - --> $DIR/issue-55897.rs:4:9 + --> $DIR/error-recovery-issue-55897.rs:4:9 | LL | use env; | ^^^ no `env` in the root diff --git a/tests/ui/extenv/issue-110547.rs b/tests/ui/env-macro/name-whitespace-issue-110547.rs index 2acfb2e671e..2acfb2e671e 100644 --- a/tests/ui/extenv/issue-110547.rs +++ b/tests/ui/env-macro/name-whitespace-issue-110547.rs diff --git a/tests/ui/extenv/issue-110547.stderr b/tests/ui/env-macro/name-whitespace-issue-110547.stderr index 10589ec2f54..5f34904d4ae 100644 --- a/tests/ui/extenv/issue-110547.stderr +++ b/tests/ui/env-macro/name-whitespace-issue-110547.stderr @@ -1,5 +1,5 @@ error: environment variable `\t` not defined at compile time - --> $DIR/issue-110547.rs:4:5 + --> $DIR/name-whitespace-issue-110547.rs:4:5 | LL | env!{"\t"}; | ^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | env!{"\t"}; = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info) error: environment variable `\t` not defined at compile time - --> $DIR/issue-110547.rs:5:5 + --> $DIR/name-whitespace-issue-110547.rs:5:5 | LL | env!("\t"); | ^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | env!("\t"); = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info) error: environment variable `\u{2069}` not defined at compile time - --> $DIR/issue-110547.rs:6:5 + --> $DIR/name-whitespace-issue-110547.rs:6:5 | LL | env!("\u{2069}"); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/extoption_env-no-args.rs b/tests/ui/env-macro/option_env-no-args.rs index bc5f77bc62e..bc5f77bc62e 100644 --- a/tests/ui/extoption_env-no-args.rs +++ b/tests/ui/env-macro/option_env-no-args.rs diff --git a/tests/ui/extoption_env-no-args.stderr b/tests/ui/env-macro/option_env-no-args.stderr index d40f905b665..d621aff770d 100644 --- a/tests/ui/extoption_env-no-args.stderr +++ b/tests/ui/env-macro/option_env-no-args.stderr @@ -1,5 +1,5 @@ error: option_env! takes 1 argument - --> $DIR/extoption_env-no-args.rs:1:13 + --> $DIR/option_env-no-args.rs:1:13 | LL | fn main() { option_env!(); } | ^^^^^^^^^^^^^ diff --git a/tests/ui/extoption_env-not-defined.rs b/tests/ui/env-macro/option_env-not-defined.rs index 90a01a80313..90a01a80313 100644 --- a/tests/ui/extoption_env-not-defined.rs +++ b/tests/ui/env-macro/option_env-not-defined.rs diff --git a/tests/ui/extoption_env-not-string-literal.rs b/tests/ui/env-macro/option_env-not-string-literal.rs index 27c3a8e83db..27c3a8e83db 100644 --- a/tests/ui/extoption_env-not-string-literal.rs +++ b/tests/ui/env-macro/option_env-not-string-literal.rs diff --git a/tests/ui/extoption_env-not-string-literal.stderr b/tests/ui/env-macro/option_env-not-string-literal.stderr index d4fec1b45c9..3d2542a0e6c 100644 --- a/tests/ui/extoption_env-not-string-literal.stderr +++ b/tests/ui/env-macro/option_env-not-string-literal.stderr @@ -1,5 +1,5 @@ error: argument must be a string literal - --> $DIR/extoption_env-not-string-literal.rs:1:25 + --> $DIR/option_env-not-string-literal.rs:1:25 | LL | fn main() { option_env!(10); } | ^^ diff --git a/tests/ui/extoption_env-too-many-args.rs b/tests/ui/env-macro/option_env-too-many-args.rs index ecc8b61ac85..ecc8b61ac85 100644 --- a/tests/ui/extoption_env-too-many-args.rs +++ b/tests/ui/env-macro/option_env-too-many-args.rs diff --git a/tests/ui/extoption_env-too-many-args.stderr b/tests/ui/env-macro/option_env-too-many-args.stderr index c7aeaac75dd..b4da3670787 100644 --- a/tests/ui/extoption_env-too-many-args.stderr +++ b/tests/ui/env-macro/option_env-too-many-args.stderr @@ -1,5 +1,5 @@ error: option_env! takes 1 argument - --> $DIR/extoption_env-too-many-args.rs:1:13 + --> $DIR/option_env-too-many-args.rs:1:13 | LL | fn main() { option_env!("one", "two"); } | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/error-codes/E0637.rs b/tests/ui/error-codes/E0637.rs index e107ea9521b..382ce3ed01f 100644 --- a/tests/ui/error-codes/E0637.rs +++ b/tests/ui/error-codes/E0637.rs @@ -2,9 +2,9 @@ fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { //~^ ERROR: `'_` cannot be used here [E0637] //~| ERROR: missing lifetime specifier if str1.len() > str2.len() { - str1 //~ ERROR: lifetime may not live long enough + str1 } else { - str2 //~ ERROR: lifetime may not live long enough + str2 } } diff --git a/tests/ui/error-codes/E0637.stderr b/tests/ui/error-codes/E0637.stderr index 217881b8e7c..d9db89ddb0c 100644 --- a/tests/ui/error-codes/E0637.stderr +++ b/tests/ui/error-codes/E0637.stderr @@ -27,25 +27,7 @@ help: consider introducing a higher-ranked lifetime here LL | T: for<'a> Into<&'a u32>, | +++++++ ++ -error: lifetime may not live long enough - --> $DIR/E0637.rs:5:9 - | -LL | fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { - | - let's call the lifetime of this reference `'1` -... -LL | str1 - | ^^^^ returning this value requires that `'1` must outlive `'static` - -error: lifetime may not live long enough - --> $DIR/E0637.rs:7:9 - | -LL | fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { - | - let's call the lifetime of this reference `'2` -... -LL | str2 - | ^^^^ returning this value requires that `'2` must outlive `'static` - -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0106, E0637. For more information about an error, try `rustc --explain E0106`. diff --git a/tests/ui/feature-gates/feature-gate-adt_const_params.stderr b/tests/ui/feature-gates/feature-gate-adt_const_params.stderr index e6eeca2e098..fcb9b8a6fc5 100644 --- a/tests/ui/feature-gates/feature-gate-adt_const_params.stderr +++ b/tests/ui/feature-gates/feature-gate-adt_const_params.stderr @@ -5,7 +5,10 @@ LL | struct Foo<const NAME: &'static str>; | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 1 previous error diff --git a/tests/ui/feature-gates/feature-gate-associated_type_bounds.rs b/tests/ui/feature-gates/feature-gate-associated_type_bounds.rs deleted file mode 100644 index 717da41f871..00000000000 --- a/tests/ui/feature-gates/feature-gate-associated_type_bounds.rs +++ /dev/null @@ -1,61 +0,0 @@ -use std::mem::ManuallyDrop; - -trait Tr1 { type As1: Copy; } -trait Tr2 { type As2: Copy; } - -struct S1; -#[derive(Copy, Clone)] -struct S2; -impl Tr1 for S1 { type As1 = S2; } - -trait _Tr3 { - type A: Iterator<Item: Copy>; - //~^ ERROR associated type bounds are unstable - - type B: Iterator<Item: 'static>; - //~^ ERROR associated type bounds are unstable -} - -struct _St1<T: Tr1<As1: Tr2>> { -//~^ ERROR associated type bounds are unstable - outest: T, - outer: T::As1, - inner: <T::As1 as Tr2>::As2, -} - -enum _En1<T: Tr1<As1: Tr2>> { -//~^ ERROR associated type bounds are unstable - Outest(T), - Outer(T::As1), - Inner(<T::As1 as Tr2>::As2), -} - -union _Un1<T: Tr1<As1: Tr2>> { -//~^ ERROR associated type bounds are unstable - outest: ManuallyDrop<T>, - outer: ManuallyDrop<T::As1>, - inner: ManuallyDrop<<T::As1 as Tr2>::As2>, -} - -type _TaWhere1<T> where T: Iterator<Item: Copy> = T; -//~^ ERROR associated type bounds are unstable - -fn _apit(_: impl Tr1<As1: Copy>) {} -//~^ ERROR associated type bounds are unstable - -fn _rpit() -> impl Tr1<As1: Copy> { S1 } -//~^ ERROR associated type bounds are unstable - -const _cdef: impl Tr1<As1: Copy> = S1; -//~^ ERROR associated type bounds are unstable -//~| ERROR `impl Trait` is not allowed in const types - -static _sdef: impl Tr1<As1: Copy> = S1; -//~^ ERROR associated type bounds are unstable -//~| ERROR `impl Trait` is not allowed in static types - -fn main() { - let _: impl Tr1<As1: Copy> = S1; - //~^ ERROR associated type bounds are unstable - //~| ERROR `impl Trait` is not allowed in the type of variable bindings -} diff --git a/tests/ui/feature-gates/feature-gate-associated_type_bounds.stderr b/tests/ui/feature-gates/feature-gate-associated_type_bounds.stderr deleted file mode 100644 index 1838eab5cda..00000000000 --- a/tests/ui/feature-gates/feature-gate-associated_type_bounds.stderr +++ /dev/null @@ -1,138 +0,0 @@ -error[E0658]: associated type bounds are unstable - --> $DIR/feature-gate-associated_type_bounds.rs:12:22 - | -LL | type A: Iterator<Item: Copy>; - | ^^^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: associated type bounds are unstable - --> $DIR/feature-gate-associated_type_bounds.rs:15:22 - | -LL | type B: Iterator<Item: 'static>; - | ^^^^^^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: associated type bounds are unstable - --> $DIR/feature-gate-associated_type_bounds.rs:19:20 - | -LL | struct _St1<T: Tr1<As1: Tr2>> { - | ^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: associated type bounds are unstable - --> $DIR/feature-gate-associated_type_bounds.rs:26:18 - | -LL | enum _En1<T: Tr1<As1: Tr2>> { - | ^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: associated type bounds are unstable - --> $DIR/feature-gate-associated_type_bounds.rs:33:19 - | -LL | union _Un1<T: Tr1<As1: Tr2>> { - | ^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: associated type bounds are unstable - --> $DIR/feature-gate-associated_type_bounds.rs:40:37 - | -LL | type _TaWhere1<T> where T: Iterator<Item: Copy> = T; - | ^^^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: associated type bounds are unstable - --> $DIR/feature-gate-associated_type_bounds.rs:43:22 - | -LL | fn _apit(_: impl Tr1<As1: Copy>) {} - | ^^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: associated type bounds are unstable - --> $DIR/feature-gate-associated_type_bounds.rs:46:24 - | -LL | fn _rpit() -> impl Tr1<As1: Copy> { S1 } - | ^^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: associated type bounds are unstable - --> $DIR/feature-gate-associated_type_bounds.rs:49:23 - | -LL | const _cdef: impl Tr1<As1: Copy> = S1; - | ^^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: associated type bounds are unstable - --> $DIR/feature-gate-associated_type_bounds.rs:53:24 - | -LL | static _sdef: impl Tr1<As1: Copy> = S1; - | ^^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: associated type bounds are unstable - --> $DIR/feature-gate-associated_type_bounds.rs:58:21 - | -LL | let _: impl Tr1<As1: Copy> = S1; - | ^^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0562]: `impl Trait` is not allowed in const types - --> $DIR/feature-gate-associated_type_bounds.rs:49:14 - | -LL | const _cdef: impl Tr1<As1: Copy> = S1; - | ^^^^^^^^^^^^^^^^^^^ - | - = note: `impl Trait` is only allowed in arguments and return types of functions and methods - -error[E0562]: `impl Trait` is not allowed in static types - --> $DIR/feature-gate-associated_type_bounds.rs:53:15 - | -LL | static _sdef: impl Tr1<As1: Copy> = S1; - | ^^^^^^^^^^^^^^^^^^^ - | - = note: `impl Trait` is only allowed in arguments and return types of functions and methods - -error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/feature-gate-associated_type_bounds.rs:58:12 - | -LL | let _: impl Tr1<As1: Copy> = S1; - | ^^^^^^^^^^^^^^^^^^^ - | - = note: `impl Trait` is only allowed in arguments and return types of functions and methods - -error: aborting due to 14 previous errors - -Some errors have detailed explanations: E0562, E0658. -For more information about an error, try `rustc --explain E0562`. diff --git a/tests/ui/feature-gates/feature-gate-deref_patterns.rs b/tests/ui/feature-gates/feature-gate-deref_patterns.rs new file mode 100644 index 00000000000..b43001f2d53 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-deref_patterns.rs @@ -0,0 +1,9 @@ +fn main() { + // We reuse the `box` syntax so this doesn't actually test the feature gate but eh. + let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental + println!("x: {}", x); + + // `box` syntax is allowed to be cfg-ed out for historical reasons (#65742). + #[cfg(FALSE)] + let box _x = Box::new('c'); +} diff --git a/tests/ui/feature-gates/feature-gate-deref_patterns.stderr b/tests/ui/feature-gates/feature-gate-deref_patterns.stderr new file mode 100644 index 00000000000..48426b50d89 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-deref_patterns.stderr @@ -0,0 +1,13 @@ +error[E0658]: box pattern syntax is experimental + --> $DIR/feature-gate-deref_patterns.rs:3:9 + | +LL | let box x = Box::new('c'); + | ^^^^^ + | + = note: see issue #29641 <https://github.com/rust-lang/rust/issues/29641> for more information + = help: add `#![feature(box_patterns)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-f128.rs b/tests/ui/feature-gates/feature-gate-f128.rs new file mode 100644 index 00000000000..7f60fb6afa0 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-f128.rs @@ -0,0 +1,15 @@ +#![allow(unused)] + +const A: f128 = 10.0; //~ ERROR the type `f128` is unstable + +pub fn main() { + let a: f128 = 100.0; //~ ERROR the type `f128` is unstable + let b = 0.0f128; //~ ERROR the type `f128` is unstable + foo(1.23); +} + +fn foo(a: f128) {} //~ ERROR the type `f128` is unstable + +struct Bar { + a: f128, //~ ERROR the type `f128` is unstable +} diff --git a/tests/ui/feature-gates/feature-gate-f128.stderr b/tests/ui/feature-gates/feature-gate-f128.stderr new file mode 100644 index 00000000000..299375c9aed --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-f128.stderr @@ -0,0 +1,53 @@ +error[E0658]: the type `f128` is unstable + --> $DIR/feature-gate-f128.rs:3:10 + | +LL | const A: f128 = 10.0; + | ^^^^ + | + = note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information + = help: add `#![feature(f128)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: the type `f128` is unstable + --> $DIR/feature-gate-f128.rs:6:12 + | +LL | let a: f128 = 100.0; + | ^^^^ + | + = note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information + = help: add `#![feature(f128)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: the type `f128` is unstable + --> $DIR/feature-gate-f128.rs:11:11 + | +LL | fn foo(a: f128) {} + | ^^^^ + | + = note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information + = help: add `#![feature(f128)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: the type `f128` is unstable + --> $DIR/feature-gate-f128.rs:14:8 + | +LL | a: f128, + | ^^^^ + | + = note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information + = help: add `#![feature(f128)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: the type `f128` is unstable + --> $DIR/feature-gate-f128.rs:7:13 + | +LL | let b = 0.0f128; + | ^^^^^^^ + | + = note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information + = help: add `#![feature(f128)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-f16.rs b/tests/ui/feature-gates/feature-gate-f16.rs new file mode 100644 index 00000000000..31d8f87f3ba --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-f16.rs @@ -0,0 +1,15 @@ +#![allow(unused)] + +const A: f16 = 10.0; //~ ERROR the type `f16` is unstable + +pub fn main() { + let a: f16 = 100.0; //~ ERROR the type `f16` is unstable + let b = 0.0f16; //~ ERROR the type `f16` is unstable + foo(1.23); +} + +fn foo(a: f16) {} //~ ERROR the type `f16` is unstable + +struct Bar { + a: f16, //~ ERROR the type `f16` is unstable +} diff --git a/tests/ui/feature-gates/feature-gate-f16.stderr b/tests/ui/feature-gates/feature-gate-f16.stderr new file mode 100644 index 00000000000..e54b54a47bd --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-f16.stderr @@ -0,0 +1,53 @@ +error[E0658]: the type `f16` is unstable + --> $DIR/feature-gate-f16.rs:3:10 + | +LL | const A: f16 = 10.0; + | ^^^ + | + = note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information + = help: add `#![feature(f16)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: the type `f16` is unstable + --> $DIR/feature-gate-f16.rs:6:12 + | +LL | let a: f16 = 100.0; + | ^^^ + | + = note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information + = help: add `#![feature(f16)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: the type `f16` is unstable + --> $DIR/feature-gate-f16.rs:11:11 + | +LL | fn foo(a: f16) {} + | ^^^ + | + = note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information + = help: add `#![feature(f16)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: the type `f16` is unstable + --> $DIR/feature-gate-f16.rs:14:8 + | +LL | a: f16, + | ^^^ + | + = note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information + = help: add `#![feature(f16)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: the type `f16` is unstable + --> $DIR/feature-gate-f16.rs:7:13 + | +LL | let b = 0.0f16; + | ^^^^^^ + | + = note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information + = help: add `#![feature(f16)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-generic_arg_infer.normal.stderr b/tests/ui/feature-gates/feature-gate-generic_arg_infer.normal.stderr index bc022476c19..97370f0489b 100644 --- a/tests/ui/feature-gates/feature-gate-generic_arg_infer.normal.stderr +++ b/tests/ui/feature-gates/feature-gate-generic_arg_infer.normal.stderr @@ -27,7 +27,10 @@ LL | let _x = foo::<_>([1,2]); | ^ | = help: const arguments cannot yet be inferred with `_` - = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable +help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable + | +LL + #![feature(generic_arg_infer)] + | error[E0658]: using `_` for array lengths is unstable --> $DIR/feature-gate-generic_arg_infer.rs:11:27 diff --git a/tests/ui/feature-gates/feature-gate-imported_main.rs b/tests/ui/feature-gates/feature-gate-imported_main.rs deleted file mode 100644 index b351d0d0e9a..00000000000 --- a/tests/ui/feature-gates/feature-gate-imported_main.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod foo { - pub fn bar() { - println!("Hello world!"); - } -} -use foo::bar as main; //~ ERROR using an imported function as entry point diff --git a/tests/ui/feature-gates/feature-gate-imported_main.stderr b/tests/ui/feature-gates/feature-gate-imported_main.stderr deleted file mode 100644 index 987bda7059c..00000000000 --- a/tests/ui/feature-gates/feature-gate-imported_main.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error[E0658]: using an imported function as entry point `main` is experimental - --> $DIR/feature-gate-imported_main.rs:6:5 - | -LL | use foo::bar as main; - | ^^^^^^^^^^^^^^^^ - | - = note: see issue #28937 <https://github.com/rust-lang/rust/issues/28937> for more information - = help: add `#![feature(imported_main)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-postfix_match.rs b/tests/ui/feature-gates/feature-gate-postfix_match.rs new file mode 100644 index 00000000000..dce7e81a9ae --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-postfix_match.rs @@ -0,0 +1,17 @@ +// Testing that postfix match doesn't work without enabling the feature + +fn main() { + let val = Some(42); + + val.match { //~ ERROR postfix match is experimental + Some(42) => "the answer to life, the universe, and everything", + _ => "might be the answer to something" + }; + + // Test that the gate works behind a cfg + #[cfg(FALSE)] + val.match { //~ ERROR postfix match is experimental + Some(42) => "the answer to life, the universe, and everything", + _ => "might be the answer to something" + }; +} diff --git a/tests/ui/feature-gates/feature-gate-postfix_match.stderr b/tests/ui/feature-gates/feature-gate-postfix_match.stderr new file mode 100644 index 00000000000..136838788dd --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-postfix_match.stderr @@ -0,0 +1,23 @@ +error[E0658]: postfix match is experimental + --> $DIR/feature-gate-postfix_match.rs:6:9 + | +LL | val.match { + | ^^^^^ + | + = note: see issue #121618 <https://github.com/rust-lang/rust/issues/121618> for more information + = help: add `#![feature(postfix_match)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: postfix match is experimental + --> $DIR/feature-gate-postfix_match.rs:13:9 + | +LL | val.match { + | ^^^^^ + | + = note: see issue #121618 <https://github.com/rust-lang/rust/issues/121618> for more information + = help: add `#![feature(postfix_match)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-trivial_bounds.stderr b/tests/ui/feature-gates/feature-gate-trivial_bounds.stderr index 5e62221628d..0ee2d93fb26 100644 --- a/tests/ui/feature-gates/feature-gate-trivial_bounds.stderr +++ b/tests/ui/feature-gates/feature-gate-trivial_bounds.stderr @@ -6,7 +6,10 @@ LL | enum E where i32: Foo { V } | = help: the trait `Foo` is implemented for `()` = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the trait bound `i32: Foo` is not satisfied --> $DIR/feature-gate-trivial_bounds.rs:12:16 @@ -16,7 +19,10 @@ LL | struct S where i32: Foo; | = help: the trait `Foo` is implemented for `()` = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the trait bound `i32: Foo` is not satisfied --> $DIR/feature-gate-trivial_bounds.rs:14:15 @@ -26,7 +32,10 @@ LL | trait T where i32: Foo {} | = help: the trait `Foo` is implemented for `()` = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the trait bound `i32: Foo` is not satisfied --> $DIR/feature-gate-trivial_bounds.rs:16:15 @@ -36,7 +45,10 @@ LL | union U where i32: Foo { f: i32 } | = help: the trait `Foo` is implemented for `()` = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the trait bound `i32: Foo` is not satisfied --> $DIR/feature-gate-trivial_bounds.rs:20:23 @@ -46,7 +58,10 @@ LL | impl Foo for () where i32: Foo { | = help: the trait `Foo` is implemented for `()` = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the trait bound `i32: Foo` is not satisfied --> $DIR/feature-gate-trivial_bounds.rs:28:14 @@ -56,7 +71,10 @@ LL | fn f() where i32: Foo | = help: the trait `Foo` is implemented for `()` = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the trait bound `String: Neg` is not satisfied --> $DIR/feature-gate-trivial_bounds.rs:36:38 @@ -65,7 +83,10 @@ LL | fn use_op(s: String) -> String where String: ::std::ops::Neg<Output=String> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Neg` is not implemented for `String` | = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: `i32` is not an iterator --> $DIR/feature-gate-trivial_bounds.rs:40:20 @@ -75,7 +96,10 @@ LL | fn use_for() where i32: Iterator { | = help: the trait `Iterator` is not implemented for `i32` = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/feature-gate-trivial_bounds.rs:52:32 @@ -85,7 +109,10 @@ LL | struct TwoStrs(str, str) where str: Sized; | = help: the trait `Sized` is not implemented for `str` = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time --> $DIR/feature-gate-trivial_bounds.rs:55:26 @@ -100,7 +127,10 @@ note: required because it appears within the type `Dst<(dyn A + 'static)>` LL | struct Dst<X: ?Sized> { | ^^^ = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/feature-gate-trivial_bounds.rs:59:30 @@ -110,7 +140,10 @@ LL | fn return_str() -> str where str: Sized { | = help: the trait `Sized` is not implemented for `str` = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error: aborting due to 11 previous errors diff --git a/tests/ui/fmt/format-args-non-identifier-diagnostics.fixed b/tests/ui/fmt/format-args-non-identifier-diagnostics.fixed new file mode 100644 index 00000000000..bd4db948067 --- /dev/null +++ b/tests/ui/fmt/format-args-non-identifier-diagnostics.fixed @@ -0,0 +1,10 @@ +// Checks that there is a suggestion for simple tuple index access expression (used where an +// identifier is expected in a format arg) to use positional arg instead. +// Issue: <https://github.com/rust-lang/rust/issues/122535>. +//@ run-rustfix + +fn main() { + let x = (1,); + println!("{0}", x.0); + //~^ ERROR invalid format string +} diff --git a/tests/ui/fmt/format-args-non-identifier-diagnostics.rs b/tests/ui/fmt/format-args-non-identifier-diagnostics.rs new file mode 100644 index 00000000000..aab705341f7 --- /dev/null +++ b/tests/ui/fmt/format-args-non-identifier-diagnostics.rs @@ -0,0 +1,10 @@ +// Checks that there is a suggestion for simple tuple index access expression (used where an +// identifier is expected in a format arg) to use positional arg instead. +// Issue: <https://github.com/rust-lang/rust/issues/122535>. +//@ run-rustfix + +fn main() { + let x = (1,); + println!("{x.0}"); + //~^ ERROR invalid format string +} diff --git a/tests/ui/fmt/format-args-non-identifier-diagnostics.stderr b/tests/ui/fmt/format-args-non-identifier-diagnostics.stderr new file mode 100644 index 00000000000..08abba2854e --- /dev/null +++ b/tests/ui/fmt/format-args-non-identifier-diagnostics.stderr @@ -0,0 +1,13 @@ +error: invalid format string: tuple index access isn't supported + --> $DIR/format-args-non-identifier-diagnostics.rs:8:16 + | +LL | println!("{x.0}"); + | ^^^ not supported in format string + | +help: consider using a positional formatting argument instead + | +LL | println!("{0}", x.0); + | ~ +++++ + +error: aborting due to 1 previous error + diff --git a/tests/ui/fmt/nested-awaits-issue-122674.rs b/tests/ui/fmt/nested-awaits-issue-122674.rs new file mode 100644 index 00000000000..f250933dadb --- /dev/null +++ b/tests/ui/fmt/nested-awaits-issue-122674.rs @@ -0,0 +1,22 @@ +// Non-regression test for issue #122674: a change in the format args visitor missed nested awaits. + +//@ edition: 2021 +//@ check-pass + +pub fn f1() -> impl std::future::Future<Output = Result<(), String>> + Send { + async { + should_work().await?; + Ok(()) + } +} + +async fn should_work() -> Result<String, String> { + let x = 1; + Err(format!("test: {}: {}", x, inner().await?)) +} + +async fn inner() -> Result<String, String> { + Ok("test".to_string()) +} + +fn main() {} diff --git a/tests/ui/generic-associated-types/issue-102335-gat.rs b/tests/ui/generic-associated-types/issue-102335-gat.rs index a7255fdcbf5..3a4a0c10771 100644 --- a/tests/ui/generic-associated-types/issue-102335-gat.rs +++ b/tests/ui/generic-associated-types/issue-102335-gat.rs @@ -1,6 +1,7 @@ trait T { type A: S<C<(), i32 = ()> = ()>; //~^ ERROR associated type bindings are not allowed here + //~| ERROR associated type bindings are not allowed here } trait Q {} diff --git a/tests/ui/generic-associated-types/issue-102335-gat.stderr b/tests/ui/generic-associated-types/issue-102335-gat.stderr index 39ca7954ede..f5e782e92fc 100644 --- a/tests/ui/generic-associated-types/issue-102335-gat.stderr +++ b/tests/ui/generic-associated-types/issue-102335-gat.stderr @@ -4,6 +4,14 @@ error[E0229]: associated type bindings are not allowed here LL | type A: S<C<(), i32 = ()> = ()>; | ^^^^^^^^ associated type not allowed here -error: aborting due to 1 previous error +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-102335-gat.rs:2:21 + | +LL | type A: S<C<(), i32 = ()> = ()>; + | ^^^^^^^^ associated type not allowed here + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0229`. diff --git a/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs b/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs index 252dc7d751e..86da6ebfaaa 100644 --- a/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs +++ b/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs @@ -29,5 +29,5 @@ where fn main() { let mut list = RcNode::<i32>::new(); - //~^ ERROR the size for values of type `Node<i32, RcFamily>` cannot be known at compilation time + //~^ ERROR trait bounds were not satisfied } diff --git a/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr b/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr index 7813370ae63..b31689dbf73 100644 --- a/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr +++ b/tests/ui/generic-associated-types/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr @@ -15,20 +15,15 @@ help: consider relaxing the implicit `Sized` restriction LL | type Pointer<T>: Deref<Target = T> + ?Sized; | ++++++++ -error[E0599]: the size for values of type `Node<i32, RcFamily>` cannot be known at compilation time +error[E0599]: the variant or associated item `new` exists for enum `Node<i32, RcFamily>`, but its trait bounds were not satisfied --> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:31:35 | LL | enum Node<T, P: PointerFamily> { - | ------------------------------ variant or associated item `new` not found for this enum because it doesn't satisfy `Node<i32, RcFamily>: Sized` + | ------------------------------ variant or associated item `new` not found for this enum ... LL | let mut list = RcNode::<i32>::new(); - | ^^^ doesn't have a size known at compile-time + | ^^^ variant or associated item cannot be called on `Node<i32, RcFamily>` due to unsatisfied trait bounds | -note: trait bound `Node<i32, RcFamily>: Sized` was not satisfied - --> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:4:18 - | -LL | type Pointer<T>: Deref<Target = T>; - | ------- ^ unsatisfied trait bound introduced here note: trait bound `(dyn Deref<Target = Node<i32, RcFamily>> + 'static): Sized` was not satisfied --> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:23:29 | @@ -37,8 +32,6 @@ LL | impl<T, P: PointerFamily> Node<T, P> LL | where LL | P::Pointer<Node<T, P>>: Sized, | ^^^^^ unsatisfied trait bound introduced here -note: the trait `Sized` must be implemented - --> $SRC_DIR/core/src/marker.rs:LL:COL error: aborting due to 2 previous errors diff --git a/tests/ui/generic-associated-types/issue-80433.rs b/tests/ui/generic-associated-types/issue-80433.rs index 6d23427f16f..53057542440 100644 --- a/tests/ui/generic-associated-types/issue-80433.rs +++ b/tests/ui/generic-associated-types/issue-80433.rs @@ -29,5 +29,5 @@ fn test_simpler<'a>(dst: &'a mut impl TestMut<Output = &'a mut f32>) fn main() { let mut t1: E<f32> = Default::default(); - test_simpler(&mut t1); //~ ERROR does not live long enough + test_simpler(&mut t1); } diff --git a/tests/ui/generic-associated-types/issue-80433.stderr b/tests/ui/generic-associated-types/issue-80433.stderr index 1ca080f5df2..a9a14d3f51c 100644 --- a/tests/ui/generic-associated-types/issue-80433.stderr +++ b/tests/ui/generic-associated-types/issue-80433.stderr @@ -48,20 +48,7 @@ LL | *dst.test_mut() = n.into(); | `dst` escapes the function body here | argument requires that `'a` must outlive `'static` -error[E0597]: `t1` does not live long enough - --> $DIR/issue-80433.rs:32:18 - | -LL | let mut t1: E<f32> = Default::default(); - | ------ binding `t1` declared here -LL | test_simpler(&mut t1); - | -------------^^^^^^^- - | | | - | | borrowed value does not live long enough - | argument requires that `t1` is borrowed for `'static` -LL | } - | - `t1` dropped here while still borrowed - -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0107, E0499, E0521, E0597. +Some errors have detailed explanations: E0107, E0499, E0521. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/generic-associated-types/issue-81712-cyclic-traits.rs b/tests/ui/generic-associated-types/issue-81712-cyclic-traits.rs index a7cc9a6053e..412eeb6e29a 100644 --- a/tests/ui/generic-associated-types/issue-81712-cyclic-traits.rs +++ b/tests/ui/generic-associated-types/issue-81712-cyclic-traits.rs @@ -13,6 +13,7 @@ trait C { trait D<T> { type CType: C<DType = Self>; //~^ ERROR missing generics for associated type + //~| ERROR missing generics for associated type } fn main() {} diff --git a/tests/ui/generic-associated-types/issue-81712-cyclic-traits.stderr b/tests/ui/generic-associated-types/issue-81712-cyclic-traits.stderr index 5eb988ea042..33c40f88f87 100644 --- a/tests/ui/generic-associated-types/issue-81712-cyclic-traits.stderr +++ b/tests/ui/generic-associated-types/issue-81712-cyclic-traits.stderr @@ -14,6 +14,23 @@ help: add missing generic argument LL | type CType: C<DType<T> = Self>; | +++ -error: aborting due to 1 previous error +error[E0107]: missing generics for associated type `C::DType` + --> $DIR/issue-81712-cyclic-traits.rs:14:19 + | +LL | type CType: C<DType = Self>; + | ^^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-81712-cyclic-traits.rs:11:10 + | +LL | type DType<T>: D<T, CType = Self>; + | ^^^^^ - + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: add missing generic argument + | +LL | type CType: C<DType<T> = Self>; + | +++ + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0107`. diff --git a/tests/ui/generic-const-items/elided-lifetimes.stderr b/tests/ui/generic-const-items/elided-lifetimes.stderr index e7df8ca5cfd..1d4a997ff60 100644 --- a/tests/ui/generic-const-items/elided-lifetimes.stderr +++ b/tests/ui/generic-const-items/elided-lifetimes.stderr @@ -28,7 +28,10 @@ LL | const I<const S: &str>: &str = ""; | ^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 4 previous errors diff --git a/tests/ui/impl-trait/erased-regions-in-hidden-ty.current.stderr b/tests/ui/impl-trait/erased-regions-in-hidden-ty.current.stderr index 5fea5353ba5..1d648162113 100644 --- a/tests/ui/impl-trait/erased-regions-in-hidden-ty.current.stderr +++ b/tests/ui/impl-trait/erased-regions-in-hidden-ty.current.stderr @@ -1,10 +1,10 @@ -error: {foo<ReEarlyParam(DefId(..), 0, 'a)>::{closure#0} closure_kind_ty=i8 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=()} +error: {foo<DefId(..)_'a/#0>::{closure#0} closure_kind_ty=i8 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=()} --> $DIR/erased-regions-in-hidden-ty.rs:12:36 | LL | fn foo<'a: 'a>(x: &'a Vec<i32>) -> impl Fn() + 'static { | ^^^^^^^^^^^^^^^^^^^ -error: Opaque(DefId(..), [ReErased]) +error: Opaque(DefId(..), ['{erased}]) --> $DIR/erased-regions-in-hidden-ty.rs:18:13 | LL | fn bar() -> impl Fn() + 'static { diff --git a/tests/ui/impl-trait/erased-regions-in-hidden-ty.next.stderr b/tests/ui/impl-trait/erased-regions-in-hidden-ty.next.stderr index 5fea5353ba5..1d648162113 100644 --- a/tests/ui/impl-trait/erased-regions-in-hidden-ty.next.stderr +++ b/tests/ui/impl-trait/erased-regions-in-hidden-ty.next.stderr @@ -1,10 +1,10 @@ -error: {foo<ReEarlyParam(DefId(..), 0, 'a)>::{closure#0} closure_kind_ty=i8 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=()} +error: {foo<DefId(..)_'a/#0>::{closure#0} closure_kind_ty=i8 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=()} --> $DIR/erased-regions-in-hidden-ty.rs:12:36 | LL | fn foo<'a: 'a>(x: &'a Vec<i32>) -> impl Fn() + 'static { | ^^^^^^^^^^^^^^^^^^^ -error: Opaque(DefId(..), [ReErased]) +error: Opaque(DefId(..), ['{erased}]) --> $DIR/erased-regions-in-hidden-ty.rs:18:13 | LL | fn bar() -> impl Fn() + 'static { diff --git a/tests/ui/impl-trait/erased-regions-in-hidden-ty.rs b/tests/ui/impl-trait/erased-regions-in-hidden-ty.rs index c18df16bd6c..9d71685f179 100644 --- a/tests/ui/impl-trait/erased-regions-in-hidden-ty.rs +++ b/tests/ui/impl-trait/erased-regions-in-hidden-ty.rs @@ -10,14 +10,14 @@ // Make sure that the compiler can handle `ReErased` in the hidden type of an opaque. fn foo<'a: 'a>(x: &'a Vec<i32>) -> impl Fn() + 'static { -//~^ ERROR 0, 'a)>::{closure#0} closure_kind_ty=i8 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=()} -// Can't write whole type because of lack of path sanitization + //~^ ERROR 'a/#0>::{closure#0} closure_kind_ty=i8 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=()} + // Can't write whole type because of lack of path sanitization || () } fn bar() -> impl Fn() + 'static { -//~^ ERROR , [ReErased]) -// Can't write whole type because of lack of path sanitization + //~^ ERROR , ['{erased}]) + // Can't write whole type because of lack of path sanitization foo(&vec![]) } diff --git a/tests/ui/impl-trait/fresh-lifetime-from-bare-trait-obj-114664.rs b/tests/ui/impl-trait/fresh-lifetime-from-bare-trait-obj-114664.rs index 41c5b9f5074..e75cfc88ef4 100644 --- a/tests/ui/impl-trait/fresh-lifetime-from-bare-trait-obj-114664.rs +++ b/tests/ui/impl-trait/fresh-lifetime-from-bare-trait-obj-114664.rs @@ -5,6 +5,8 @@ fn ice() -> impl AsRef<Fn(&())> { //~^ WARN trait objects without an explicit `dyn` are deprecated //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + //~| WARN trait objects without an explicit `dyn` are deprecated + //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! Foo } diff --git a/tests/ui/impl-trait/fresh-lifetime-from-bare-trait-obj-114664.stderr b/tests/ui/impl-trait/fresh-lifetime-from-bare-trait-obj-114664.stderr index 3cb3af89bfc..d82b2c0f606 100644 --- a/tests/ui/impl-trait/fresh-lifetime-from-bare-trait-obj-114664.stderr +++ b/tests/ui/impl-trait/fresh-lifetime-from-bare-trait-obj-114664.stderr @@ -12,5 +12,19 @@ help: if this is an object-safe trait, use `dyn` LL | fn ice() -> impl AsRef<dyn Fn(&())> { | +++ -warning: 1 warning emitted +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/fresh-lifetime-from-bare-trait-obj-114664.rs:5:24 + | +LL | fn ice() -> impl AsRef<Fn(&())> { + | ^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: if this is an object-safe trait, use `dyn` + | +LL | fn ice() -> impl AsRef<dyn Fn(&())> { + | +++ + +warning: 2 warnings emitted diff --git a/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.rs b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.rs new file mode 100644 index 00000000000..d6fa56663a3 --- /dev/null +++ b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.rs @@ -0,0 +1,30 @@ +// test for ICE #112823 +// Unexpected parameter Type(Repr) when substituting in region + +#![feature(impl_trait_in_assoc_type)] + +use std::future::Future; + +trait Stream {} + +trait X { + type LineStream<'a, Repr> + where + Self: 'a; + type LineStreamFut<'a, Repr> + where + Self: 'a; +} + +struct Y; + +impl X for Y { + type LineStream<'c, 'd> = impl Stream; + //~^ ERROR type `LineStream` has 0 type parameters but its trait declaration has 1 type parameter + type LineStreamFut<'a, Repr> = impl Future<Output = Self::LineStream<'a, Repr>>; + fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {} + //~^ ERROR `()` is not a future + //~^^ method `line_stream` is not a member of trait `X` +} + +pub fn main() {} diff --git a/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.stderr b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.stderr new file mode 100644 index 00000000000..28a0f7461e2 --- /dev/null +++ b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.stderr @@ -0,0 +1,31 @@ +error[E0407]: method `line_stream` is not a member of trait `X` + --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:25:5 + | +LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `X` + +error[E0049]: type `LineStream` has 0 type parameters but its trait declaration has 1 type parameter + --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:22:21 + | +LL | type LineStream<'a, Repr> + | -- ---- + | | + | expected 1 type parameter +... +LL | type LineStream<'c, 'd> = impl Stream; + | ^^ ^^ + | | + | found 0 type parameters + +error[E0277]: `()` is not a future + --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:25:43 + | +LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not a future + | + = help: the trait `Future` is not implemented for `()` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0049, E0277, E0407. +For more information about an error, try `rustc --explain E0049`. diff --git a/tests/ui/impl-trait/impl-fn-hrtb-bounds.rs b/tests/ui/impl-trait/impl-fn-hrtb-bounds.rs index a9ea657f10e..da7530b4e7a 100644 --- a/tests/ui/impl-trait/impl-fn-hrtb-bounds.rs +++ b/tests/ui/impl-trait/impl-fn-hrtb-bounds.rs @@ -4,19 +4,16 @@ use std::fmt::Debug; fn a() -> impl Fn(&u8) -> (impl Debug + '_) { //~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` |x| x - //~^ ERROR lifetime may not live long enough } fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) { //~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` |x| x - //~^ ERROR lifetime may not live long enough } fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) { //~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` |x| x - //~^ ERROR lifetime may not live long enough } fn d() -> impl Fn() -> (impl Debug + '_) { diff --git a/tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr b/tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr index bdb099619b7..7d108b30b76 100644 --- a/tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr +++ b/tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr @@ -1,5 +1,5 @@ error[E0106]: missing lifetime specifier - --> $DIR/impl-fn-hrtb-bounds.rs:22:38 + --> $DIR/impl-fn-hrtb-bounds.rs:19:38 | LL | fn d() -> impl Fn() -> (impl Debug + '_) { | ^^ expected named lifetime parameter @@ -22,58 +22,31 @@ note: lifetime declared here LL | fn a() -> impl Fn(&u8) -> (impl Debug + '_) { | ^ -error: lifetime may not live long enough - --> $DIR/impl-fn-hrtb-bounds.rs:6:9 - | -LL | |x| x - | -- ^ returning this value requires that `'1` must outlive `'2` - | || - | |return type of closure is impl Debug + '2 - | has type `&'1 u8` - error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/impl-fn-hrtb-bounds.rs:10:52 + --> $DIR/impl-fn-hrtb-bounds.rs:9:52 | LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) { | ^^ | note: lifetime declared here - --> $DIR/impl-fn-hrtb-bounds.rs:10:20 + --> $DIR/impl-fn-hrtb-bounds.rs:9:20 | LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) { | ^^ -error: lifetime may not live long enough - --> $DIR/impl-fn-hrtb-bounds.rs:12:9 - | -LL | |x| x - | -- ^ returning this value requires that `'1` must outlive `'2` - | || - | |return type of closure is impl Debug + '2 - | has type `&'1 u8` - error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/impl-fn-hrtb-bounds.rs:16:52 + --> $DIR/impl-fn-hrtb-bounds.rs:14:52 | LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) { | ^^ | note: lifetime declared here - --> $DIR/impl-fn-hrtb-bounds.rs:16:20 + --> $DIR/impl-fn-hrtb-bounds.rs:14:20 | LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) { | ^^ -error: lifetime may not live long enough - --> $DIR/impl-fn-hrtb-bounds.rs:18:9 - | -LL | |x| x - | -- ^ returning this value requires that `'1` must outlive `'2` - | || - | |return type of closure is impl Debug + '2 - | has type `&'1 u8` - -error: aborting due to 7 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0106, E0657. For more information about an error, try `rustc --explain E0106`. diff --git a/tests/ui/impl-trait/impl-fn-parsing-ambiguities.rs b/tests/ui/impl-trait/impl-fn-parsing-ambiguities.rs index ef9d8733509..7679b7ec478 100644 --- a/tests/ui/impl-trait/impl-fn-parsing-ambiguities.rs +++ b/tests/ui/impl-trait/impl-fn-parsing-ambiguities.rs @@ -5,7 +5,6 @@ fn a() -> impl Fn(&u8) -> impl Debug + '_ { //~^ ERROR ambiguous `+` in a type //~| ERROR cannot capture higher-ranked lifetime from outer `impl Trait` |x| x - //~^ ERROR lifetime may not live long enough } fn b() -> impl Fn() -> impl Debug + Send { diff --git a/tests/ui/impl-trait/impl-fn-parsing-ambiguities.stderr b/tests/ui/impl-trait/impl-fn-parsing-ambiguities.stderr index 3881b37a0cb..e0955faac7c 100644 --- a/tests/ui/impl-trait/impl-fn-parsing-ambiguities.stderr +++ b/tests/ui/impl-trait/impl-fn-parsing-ambiguities.stderr @@ -5,7 +5,7 @@ LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ { | ^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(impl Debug + '_)` error: ambiguous `+` in a type - --> $DIR/impl-fn-parsing-ambiguities.rs:11:24 + --> $DIR/impl-fn-parsing-ambiguities.rs:10:24 | LL | fn b() -> impl Fn() -> impl Debug + Send { | ^^^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(impl Debug + Send)` @@ -22,15 +22,6 @@ note: lifetime declared here LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ { | ^ -error: lifetime may not live long enough - --> $DIR/impl-fn-parsing-ambiguities.rs:7:9 - | -LL | |x| x - | -- ^ returning this value requires that `'1` must outlive `'2` - | || - | |return type of closure is impl Debug + '2 - | has type `&'1 u8` - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0657`. diff --git a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr index c898d17f4b7..022df6f906c 100644 --- a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr +++ b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr @@ -22,7 +22,8 @@ LL | fn iter(&self) -> impl 'a + Iterator<Item = I::Item<'a>> { | ^^ this bound is stronger than that defined on the trait | = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate - = note: `#[warn(refining_impl_trait)]` on by default + = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information + = note: `#[warn(refining_impl_trait_reachable)]` on by default help: replace the return type so that it matches the trait | LL | fn iter(&self) -> impl Iterator<Item = <Self as Iterable>::Item<'_>> + '_ { diff --git a/tests/ui/impl-trait/in-trait/foreign.rs b/tests/ui/impl-trait/in-trait/foreign.rs index e28bc9e00cb..ca759afc2e6 100644 --- a/tests/ui/impl-trait/in-trait/foreign.rs +++ b/tests/ui/impl-trait/in-trait/foreign.rs @@ -17,9 +17,29 @@ impl Foo for Local { } } -struct LocalIgnoreRefining; -impl Foo for LocalIgnoreRefining { - #[deny(refining_impl_trait)] +struct LocalOnlyRefiningA; +impl Foo for LocalOnlyRefiningA { + #[warn(refining_impl_trait)] + fn bar(self) -> Arc<String> { + //~^ WARN impl method signature does not match trait method signature + Arc::new(String::new()) + } +} + +struct LocalOnlyRefiningB; +impl Foo for LocalOnlyRefiningB { + #[warn(refining_impl_trait)] + #[allow(refining_impl_trait_reachable)] + fn bar(self) -> Arc<String> { + //~^ WARN impl method signature does not match trait method signature + Arc::new(String::new()) + } +} + +struct LocalOnlyRefiningC; +impl Foo for LocalOnlyRefiningC { + #[warn(refining_impl_trait)] + #[allow(refining_impl_trait_internal)] fn bar(self) -> Arc<String> { Arc::new(String::new()) } @@ -34,5 +54,7 @@ fn main() { let &() = Foreign.bar(); let x: Arc<String> = Local.bar(); - let x: Arc<String> = LocalIgnoreRefining.bar(); + let x: Arc<String> = LocalOnlyRefiningA.bar(); + let x: Arc<String> = LocalOnlyRefiningB.bar(); + let x: Arc<String> = LocalOnlyRefiningC.bar(); } diff --git a/tests/ui/impl-trait/in-trait/foreign.stderr b/tests/ui/impl-trait/in-trait/foreign.stderr new file mode 100644 index 00000000000..1a5a4f2432b --- /dev/null +++ b/tests/ui/impl-trait/in-trait/foreign.stderr @@ -0,0 +1,39 @@ +warning: impl trait in impl method signature does not match trait method signature + --> $DIR/foreign.rs:23:21 + | +LL | fn bar(self) -> Arc<String> { + | ^^^^^^^^^^^ + | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information +note: the lint level is defined here + --> $DIR/foreign.rs:22:12 + | +LL | #[warn(refining_impl_trait)] + | ^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(refining_impl_trait_internal)]` implied by `#[warn(refining_impl_trait)]` +help: replace the return type so that it matches the trait + | +LL | fn bar(self) -> impl Deref<Target = impl Sized> { + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +warning: impl trait in impl method signature does not match trait method signature + --> $DIR/foreign.rs:33:21 + | +LL | fn bar(self) -> Arc<String> { + | ^^^^^^^^^^^ + | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information +note: the lint level is defined here + --> $DIR/foreign.rs:31:12 + | +LL | #[warn(refining_impl_trait)] + | ^^^^^^^^^^^^^^^^^^^ +help: replace the return type so that it matches the trait + | +LL | fn bar(self) -> impl Deref<Target = impl Sized> { + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +warning: 2 warnings emitted + diff --git a/tests/ui/impl-trait/in-trait/lifetime-in-associated-trait-bound.rs b/tests/ui/impl-trait/in-trait/lifetime-in-associated-trait-bound.rs index e0d4f461974..b29d71437b9 100644 --- a/tests/ui/impl-trait/in-trait/lifetime-in-associated-trait-bound.rs +++ b/tests/ui/impl-trait/in-trait/lifetime-in-associated-trait-bound.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(associated_type_bounds)] - trait Trait { type Type; diff --git a/tests/ui/impl-trait/in-trait/refine.rs b/tests/ui/impl-trait/in-trait/refine.rs index 100e6da06a8..6813c3bbf27 100644 --- a/tests/ui/impl-trait/in-trait/refine.rs +++ b/tests/ui/impl-trait/in-trait/refine.rs @@ -25,6 +25,7 @@ impl Foo for C { struct Private; impl Foo for Private { fn bar() -> () {} + //~^ ERROR impl method signature does not match trait method signature } pub trait Arg<A> { @@ -32,6 +33,7 @@ pub trait Arg<A> { } impl Arg<Private> for A { fn bar() -> () {} + //~^ ERROR impl method signature does not match trait method signature } pub trait Late { @@ -52,6 +54,7 @@ mod unreachable { struct E; impl UnreachablePub for E { fn bar() {} + //~^ ERROR impl method signature does not match trait method signature } } diff --git a/tests/ui/impl-trait/in-trait/refine.stderr b/tests/ui/impl-trait/in-trait/refine.stderr index 96a9bc059c8..8d30b035921 100644 --- a/tests/ui/impl-trait/in-trait/refine.stderr +++ b/tests/ui/impl-trait/in-trait/refine.stderr @@ -8,11 +8,13 @@ LL | fn bar() -> impl Copy {} | ^^^^ this bound is stronger than that defined on the trait | = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information note: the lint level is defined here --> $DIR/refine.rs:1:9 | LL | #![deny(refining_impl_trait)] | ^^^^^^^^^^^^^^^^^^^ + = note: `#[deny(refining_impl_trait_reachable)]` implied by `#[deny(refining_impl_trait)]` help: replace the return type so that it matches the trait | LL | fn bar() -> impl Sized {} @@ -28,6 +30,7 @@ LL | fn bar() {} | ^^^^^^^^ | = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information help: replace the return type so that it matches the trait | LL | fn bar()-> impl Sized {} @@ -43,13 +46,47 @@ LL | fn bar() -> () {} | ^^ | = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information help: replace the return type so that it matches the trait | LL | fn bar() -> impl Sized {} | ~~~~~~~~~~ error: impl trait in impl method signature does not match trait method signature - --> $DIR/refine.rs:43:27 + --> $DIR/refine.rs:27:17 + | +LL | fn bar() -> impl Sized; + | ---------- return type from trait method defined here +... +LL | fn bar() -> () {} + | ^^ + | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information + = note: `#[deny(refining_impl_trait_internal)]` implied by `#[deny(refining_impl_trait)]` +help: replace the return type so that it matches the trait + | +LL | fn bar() -> impl Sized {} + | ~~~~~~~~~~ + +error: impl trait in impl method signature does not match trait method signature + --> $DIR/refine.rs:35:17 + | +LL | fn bar() -> impl Sized; + | ---------- return type from trait method defined here +... +LL | fn bar() -> () {} + | ^^ + | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information +help: replace the return type so that it matches the trait + | +LL | fn bar() -> impl Sized {} + | ~~~~~~~~~~ + +error: impl trait in impl method signature does not match trait method signature + --> $DIR/refine.rs:45:27 | LL | fn bar<'a>(&'a self) -> impl Sized + 'a; | --------------- return type from trait method defined here @@ -58,10 +95,27 @@ LL | fn bar(&self) -> impl Copy + '_ {} | ^^^^ this bound is stronger than that defined on the trait | = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information help: replace the return type so that it matches the trait | LL | fn bar(&self) -> impl Sized + '_ {} | ~~~~~~~~~~~~~~~ -error: aborting due to 4 previous errors +error: impl trait in impl method signature does not match trait method signature + --> $DIR/refine.rs:56:9 + | +LL | fn bar() -> impl Sized; + | ---------- return type from trait method defined here +... +LL | fn bar() {} + | ^^^^^^^^ + | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate + = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information +help: replace the return type so that it matches the trait + | +LL | fn bar()-> impl Sized {} + | +++++++++++++ + +error: aborting due to 7 previous errors diff --git a/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs index 10167ee9352..ab21dae7dc5 100644 --- a/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs +++ b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs @@ -12,6 +12,7 @@ impl<'a, I: 'a + Iterable> Iterable for &'a I { fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {} //~^ ERROR binding for associated type `Item` references lifetime `'missing` + //~| ERROR binding for associated type `Item` references lifetime `'missing` //~| ERROR `()` is not an iterator } diff --git a/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr index 96c3644f893..d8a2eef94a1 100644 --- a/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr +++ b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr @@ -4,6 +4,14 @@ error[E0582]: binding for associated type `Item` references lifetime `'missing`, LL | fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error[E0582]: binding for associated type `Item` references lifetime `'missing`, which does not appear in the trait input types + --> $DIR/span-bug-issue-121457.rs:13:51 + | +LL | fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0195]: lifetime parameters or bounds on type `Item` do not match the trait declaration --> $DIR/span-bug-issue-121457.rs:10:14 | @@ -24,7 +32,7 @@ LL | fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missin | = help: the trait `Iterator` is not implemented for `()` -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0195, E0277, E0582. For more information about an error, try `rustc --explain E0195`. diff --git a/tests/ui/impl-trait/issue-86465.rs b/tests/ui/impl-trait/issue-86465.rs deleted file mode 100644 index a79bb6474d8..00000000000 --- a/tests/ui/impl-trait/issue-86465.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![feature(type_alias_impl_trait)] - -type X<'a, 'b> = impl std::fmt::Debug; - -fn f<'t, 'u>(a: &'t u32, b: &'u u32) -> (X<'t, 'u>, X<'u, 't>) { - (a, a) - //~^ ERROR concrete type differs from previous defining opaque type use -} - -fn main() {} diff --git a/tests/ui/impl-trait/issue-86465.stderr b/tests/ui/impl-trait/issue-86465.stderr deleted file mode 100644 index e330d178d4e..00000000000 --- a/tests/ui/impl-trait/issue-86465.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: concrete type differs from previous defining opaque type use - --> $DIR/issue-86465.rs:6:5 - | -LL | (a, a) - | ^^^^^^ - | | - | expected `&'a u32`, got `&'b u32` - | this expression supplies two conflicting concrete types for the same opaque type - -error: aborting due to 1 previous error - diff --git a/tests/ui/impl-trait/issues/issue-92305.rs b/tests/ui/impl-trait/issues/issue-92305.rs index 5ecb6984cfe..be98ce807ec 100644 --- a/tests/ui/impl-trait/issues/issue-92305.rs +++ b/tests/ui/impl-trait/issues/issue-92305.rs @@ -4,6 +4,7 @@ use std::iter; fn f<T>(data: &[T]) -> impl Iterator<Item = Vec> { //~^ ERROR: missing generics for struct `Vec` [E0107] + //~| ERROR: missing generics for struct `Vec` [E0107] iter::empty() } diff --git a/tests/ui/impl-trait/issues/issue-92305.stderr b/tests/ui/impl-trait/issues/issue-92305.stderr index 88fb1fb2707..4591d2c53f7 100644 --- a/tests/ui/impl-trait/issues/issue-92305.stderr +++ b/tests/ui/impl-trait/issues/issue-92305.stderr @@ -9,6 +9,18 @@ help: add missing generic argument LL | fn f<T>(data: &[T]) -> impl Iterator<Item = Vec<T>> { | +++ -error: aborting due to 1 previous error +error[E0107]: missing generics for struct `Vec` + --> $DIR/issue-92305.rs:5:45 + | +LL | fn f<T>(data: &[T]) -> impl Iterator<Item = Vec> { + | ^^^ expected at least 1 generic argument + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: add missing generic argument + | +LL | fn f<T>(data: &[T]) -> impl Iterator<Item = Vec<T>> { + | +++ + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0107`. diff --git a/tests/ui/impl-trait/nested-rpit-hrtb.rs b/tests/ui/impl-trait/nested-rpit-hrtb.rs index c10bfbfe4dc..a696e1710f0 100644 --- a/tests/ui/impl-trait/nested-rpit-hrtb.rs +++ b/tests/ui/impl-trait/nested-rpit-hrtb.rs @@ -35,7 +35,6 @@ fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {} fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {} //~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` -//~| ERROR: the trait bound `for<'a> &'a (): Qux<'_>` is not satisfied // This should resolve. fn one_hrtb_mention_fn_trait_param<'b>() -> impl for<'a> Foo<'a, Assoc = impl Qux<'b>> {} @@ -45,7 +44,7 @@ fn one_hrtb_mention_fn_outlives<'b>() -> impl for<'a> Foo<'a, Assoc = impl Sized // This should resolve. fn one_hrtb_mention_fn_trait_param_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Qux<'b>> {} -//~^ ERROR: the trait bound `for<'a> &'a (): Qux<'b>` is not satisfied +//~^ ERROR type annotations needed: cannot satisfy `for<'a> &'a (): Qux<'b>` // This should resolve. fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'b> {} diff --git a/tests/ui/impl-trait/nested-rpit-hrtb.stderr b/tests/ui/impl-trait/nested-rpit-hrtb.stderr index 2779694a517..64f801ea685 100644 --- a/tests/ui/impl-trait/nested-rpit-hrtb.stderr +++ b/tests/ui/impl-trait/nested-rpit-hrtb.stderr @@ -1,5 +1,5 @@ error[E0261]: use of undeclared lifetime name `'b` - --> $DIR/nested-rpit-hrtb.rs:58:77 + --> $DIR/nested-rpit-hrtb.rs:57:77 | LL | fn two_htrb_outlives() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Sized + 'b> {} | ^^ undeclared lifetime @@ -15,7 +15,7 @@ LL | fn two_htrb_outlives<'b>() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Siz | ++++ error[E0261]: use of undeclared lifetime name `'b` - --> $DIR/nested-rpit-hrtb.rs:66:82 + --> $DIR/nested-rpit-hrtb.rs:65:82 | LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {} | ^^ undeclared lifetime @@ -86,26 +86,18 @@ note: lifetime declared here LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {} | ^^ -error[E0277]: the trait bound `for<'a> &'a (): Qux<'_>` is not satisfied - --> $DIR/nested-rpit-hrtb.rs:36:64 - | -LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {} - | ^^^^^^^^^^^^ the trait `for<'a> Qux<'_>` is not implemented for `&'a ()` - | - = help: the trait `Qux<'_>` is implemented for `()` - = help: for that trait implementation, expected `()`, found `&'a ()` - -error[E0277]: the trait bound `for<'a> &'a (): Qux<'b>` is not satisfied - --> $DIR/nested-rpit-hrtb.rs:47:79 +error[E0283]: type annotations needed: cannot satisfy `for<'a> &'a (): Qux<'b>` + --> $DIR/nested-rpit-hrtb.rs:46:79 | LL | fn one_hrtb_mention_fn_trait_param_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Qux<'b>> {} - | ^^^^^^^^^^^^ the trait `for<'a> Qux<'b>` is not implemented for `&'a ()` + | ^^^^^^^^^^^^ | + = note: cannot satisfy `for<'a> &'a (): Qux<'b>` = help: the trait `Qux<'_>` is implemented for `()` = help: for that trait implementation, expected `()`, found `&'a ()` error: implementation of `Bar` is not general enough - --> $DIR/nested-rpit-hrtb.rs:51:93 + --> $DIR/nested-rpit-hrtb.rs:50:93 | LL | fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'b> {} | ^^ implementation of `Bar` is not general enough @@ -114,7 +106,7 @@ LL | fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = = note: ...but it actually implements `Bar<'0>`, for some specific lifetime `'0` error[E0277]: the trait bound `for<'a, 'b> &'a (): Qux<'b>` is not satisfied - --> $DIR/nested-rpit-hrtb.rs:62:64 + --> $DIR/nested-rpit-hrtb.rs:61:64 | LL | fn two_htrb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Qux<'b>> {} | ^^^^^^^^^^^^^^^^^^^^ the trait `for<'a, 'b> Qux<'b>` is not implemented for `&'a ()` @@ -123,7 +115,7 @@ LL | fn two_htrb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> = help: for that trait implementation, expected `()`, found `&'a ()` error: implementation of `Bar` is not general enough - --> $DIR/nested-rpit-hrtb.rs:66:86 + --> $DIR/nested-rpit-hrtb.rs:65:86 | LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {} | ^^ implementation of `Bar` is not general enough @@ -131,7 +123,7 @@ LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Si = note: `()` must implement `Bar<'a>` = note: ...but it actually implements `Bar<'0>`, for some specific lifetime `'0` -error: aborting due to 12 previous errors +error: aborting due to 11 previous errors -Some errors have detailed explanations: E0261, E0277, E0657. +Some errors have detailed explanations: E0261, E0277, E0283, E0657. For more information about an error, try `rustc --explain E0261`. diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr index f77b4bd517f..7ae8306d74d 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -11,11 +11,14 @@ LL | fun(filter_positive()); | ^^^^^^^^^^^^^^^^^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable help: consider further restricting this bound | LL | const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct + ~const std::ops::Fn<(&Alias<'_>,)>>(fun: F) { | ++++++++++++++++++++++++++++++++++++ +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0493]: destructor of `F` cannot be evaluated at compile-time --> $DIR/normalize-tait-in-const.rs:25:79 diff --git a/tests/ui/impl-trait/opaque-used-in-extraneous-argument.rs b/tests/ui/impl-trait/opaque-used-in-extraneous-argument.rs index 529913479ef..8d4855c101c 100644 --- a/tests/ui/impl-trait/opaque-used-in-extraneous-argument.rs +++ b/tests/ui/impl-trait/opaque-used-in-extraneous-argument.rs @@ -7,6 +7,7 @@ fn frob() -> impl Fn<P, Output = T> + '_ {} //~| ERROR cannot find type `P` //~| ERROR cannot find type `T` //~| ERROR `Fn`-family traits' type parameters is subject to change +//~| ERROR `Fn`-family traits' type parameters is subject to change fn open_parent<'path>() { todo!() diff --git a/tests/ui/impl-trait/opaque-used-in-extraneous-argument.stderr b/tests/ui/impl-trait/opaque-used-in-extraneous-argument.stderr index b54b9f908b2..6d417488533 100644 --- a/tests/ui/impl-trait/opaque-used-in-extraneous-argument.stderr +++ b/tests/ui/impl-trait/opaque-used-in-extraneous-argument.stderr @@ -42,8 +42,19 @@ LL | fn frob() -> impl Fn<P, Output = T> + '_ {} = help: add `#![feature(unboxed_closures)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date +error[E0658]: the precise format of `Fn`-family traits' type parameters is subject to change + --> $DIR/opaque-used-in-extraneous-argument.rs:5:19 + | +LL | fn frob() -> impl Fn<P, Output = T> + '_ {} + | ^^^^^^^^^^^^^^^^^ help: use parenthetical notation instead: `Fn(P) -> T` + | + = note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information + = help: add `#![feature(unboxed_closures)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0061]: this function takes 0 arguments but 1 argument was supplied - --> $DIR/opaque-used-in-extraneous-argument.rs:16:20 + --> $DIR/opaque-used-in-extraneous-argument.rs:17:20 | LL | let old_path = frob("hello"); | ^^^^ ------- @@ -58,7 +69,7 @@ LL | fn frob() -> impl Fn<P, Output = T> + '_ {} | ^^^^ error[E0061]: this function takes 0 arguments but 1 argument was supplied - --> $DIR/opaque-used-in-extraneous-argument.rs:19:5 + --> $DIR/opaque-used-in-extraneous-argument.rs:20:5 | LL | open_parent(&old_path) | ^^^^^^^^^^^ --------- @@ -67,12 +78,12 @@ LL | open_parent(&old_path) | help: remove the extra argument | note: function defined here - --> $DIR/opaque-used-in-extraneous-argument.rs:11:4 + --> $DIR/opaque-used-in-extraneous-argument.rs:12:4 | LL | fn open_parent<'path>() { | ^^^^^^^^^^^ -error: aborting due to 6 previous errors +error: aborting due to 7 previous errors Some errors have detailed explanations: E0061, E0106, E0412, E0658. For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/impl-trait/stranded-opaque.rs b/tests/ui/impl-trait/stranded-opaque.rs index c7ab390e1fd..6ce5cbd3b55 100644 --- a/tests/ui/impl-trait/stranded-opaque.rs +++ b/tests/ui/impl-trait/stranded-opaque.rs @@ -7,6 +7,7 @@ impl Trait for i32 {} // ICE in this case. fn produce<T>() -> impl Trait<Assoc = impl Trait> { //~^ ERROR associated type `Assoc` not found for `Trait` + //~| ERROR associated type `Assoc` not found for `Trait` 16 } diff --git a/tests/ui/impl-trait/stranded-opaque.stderr b/tests/ui/impl-trait/stranded-opaque.stderr index 75f5480bc8b..5bea3e2af6b 100644 --- a/tests/ui/impl-trait/stranded-opaque.stderr +++ b/tests/ui/impl-trait/stranded-opaque.stderr @@ -4,6 +4,14 @@ error[E0220]: associated type `Assoc` not found for `Trait` LL | fn produce<T>() -> impl Trait<Assoc = impl Trait> { | ^^^^^ associated type `Assoc` not found -error: aborting due to 1 previous error +error[E0220]: associated type `Assoc` not found for `Trait` + --> $DIR/stranded-opaque.rs:8:31 + | +LL | fn produce<T>() -> impl Trait<Assoc = impl Trait> { + | ^^^^^ associated type `Assoc` not found + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0220`. diff --git a/tests/ui/inference/ice-cannot-relate-region-109178.rs b/tests/ui/inference/ice-cannot-relate-region-109178.rs new file mode 100644 index 00000000000..3282f95a992 --- /dev/null +++ b/tests/ui/inference/ice-cannot-relate-region-109178.rs @@ -0,0 +1,14 @@ +// test for ice #109178 cannot relate region: LUB(ReErased, ReError) + +#![allow(incomplete_features)] +#![crate_type = "lib"] +#![feature(adt_const_params, generic_const_exprs)] + +struct Changes<const CHANGES: &[&'static str]> +//~^ ERROR `&` without an explicit lifetime name cannot be used here +where + [(); CHANGES.len()]:, {} + +impl<const CHANGES: &[&str]> Changes<CHANGES> where [(); CHANGES.len()]: {} +//~^ ERROR `&` without an explicit lifetime name cannot be used here +//~^^ ERROR `&` without an explicit lifetime name cannot be used here diff --git a/tests/ui/inference/ice-cannot-relate-region-109178.stderr b/tests/ui/inference/ice-cannot-relate-region-109178.stderr new file mode 100644 index 00000000000..0ac924452c0 --- /dev/null +++ b/tests/ui/inference/ice-cannot-relate-region-109178.stderr @@ -0,0 +1,21 @@ +error[E0637]: `&` without an explicit lifetime name cannot be used here + --> $DIR/ice-cannot-relate-region-109178.rs:7:31 + | +LL | struct Changes<const CHANGES: &[&'static str]> + | ^ explicit lifetime name needed here + +error[E0637]: `&` without an explicit lifetime name cannot be used here + --> $DIR/ice-cannot-relate-region-109178.rs:12:21 + | +LL | impl<const CHANGES: &[&str]> Changes<CHANGES> where [(); CHANGES.len()]: {} + | ^ explicit lifetime name needed here + +error[E0637]: `&` without an explicit lifetime name cannot be used here + --> $DIR/ice-cannot-relate-region-109178.rs:12:23 + | +LL | impl<const CHANGES: &[&str]> Changes<CHANGES> where [(); CHANGES.len()]: {} + | ^ explicit lifetime name needed here + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0637`. diff --git a/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.rs b/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.rs new file mode 100644 index 00000000000..3c2aa176c0f --- /dev/null +++ b/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.rs @@ -0,0 +1,25 @@ +// test for #122098 ICE snapshot_vec.rs: index out of bounds: the len is 4 but the index is 4 + +trait LendingIterator { + type Item<'q>: 'a; + //~^ ERROR use of undeclared lifetime name `'a` + + fn for_each(mut self, mut f: Box<dyn FnMut(Self::Item<'_>) + 'static>) {} + //~^ ERROR the size for values of type `Self` cannot be known at compilation time +} + +struct Query<'q> {} +//~^ ERROR lifetime parameter `'q` is never used + +impl<'static> Query<'q> { +//~^ ERROR invalid lifetime parameter name: `'static` +//~^^ ERROR use of undeclared lifetime name `'q` + pub fn new() -> Self {} +} + +fn data() { + LendingIterator::for_each(Query::new(&data), Box::new); + //~^ ERROR this function takes 0 arguments but 1 argument was supplied +} + +pub fn main() {} diff --git a/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr b/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr new file mode 100644 index 00000000000..e2ddf474c4a --- /dev/null +++ b/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr @@ -0,0 +1,72 @@ +error[E0261]: use of undeclared lifetime name `'a` + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:4:20 + | +LL | type Item<'q>: 'a; + | ^^ undeclared lifetime + | +help: consider introducing lifetime `'a` here + | +LL | type Item<'a, 'q>: 'a; + | +++ +help: consider introducing lifetime `'a` here + | +LL | trait LendingIterator<'a> { + | ++++ + +error[E0262]: invalid lifetime parameter name: `'static` + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:14:6 + | +LL | impl<'static> Query<'q> { + | ^^^^^^^ 'static is a reserved lifetime name + +error[E0261]: use of undeclared lifetime name `'q` + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:14:21 + | +LL | impl<'static> Query<'q> { + | - ^^ undeclared lifetime + | | + | help: consider introducing lifetime `'q` here: `'q,` + +error[E0392]: lifetime parameter `'q` is never used + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:11:14 + | +LL | struct Query<'q> {} + | ^^ unused lifetime parameter + | + = help: consider removing `'q`, referring to it in a field, or using a marker such as `PhantomData` + +error[E0277]: the size for values of type `Self` cannot be known at compilation time + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:7:17 + | +LL | fn for_each(mut self, mut f: Box<dyn FnMut(Self::Item<'_>) + 'static>) {} + | ^^^^^^^^ doesn't have a size known at compile-time + | + = help: unsized fn params are gated as an unstable feature +help: consider further restricting `Self` + | +LL | fn for_each(mut self, mut f: Box<dyn FnMut(Self::Item<'_>) + 'static>) where Self: Sized {} + | +++++++++++++++++ +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn for_each(mut &self, mut f: Box<dyn FnMut(Self::Item<'_>) + 'static>) {} + | + + +error[E0061]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:21:31 + | +LL | LendingIterator::for_each(Query::new(&data), Box::new); + | ^^^^^^^^^^ ----- + | | + | unexpected argument of type `&fn() {data}` + | help: remove the extra argument + | +note: associated function defined here + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:17:12 + | +LL | pub fn new() -> Self {} + | ^^^ + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0061, E0261, E0262, E0277, E0392. +For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/inference/inference_unstable.stderr b/tests/ui/inference/inference_unstable.stderr index c48aaf9f495..51f086177db 100644 --- a/tests/ui/inference/inference_unstable.stderr +++ b/tests/ui/inference/inference_unstable.stderr @@ -7,8 +7,11 @@ LL | assert_eq!('x'.ipu_flatten(), 1); = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior! = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919> = help: call with fully qualified syntax `inference_unstable_itertools::IpuItertools::ipu_flatten(...)` to keep using the current method - = help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_flatten` = note: `#[warn(unstable_name_collisions)]` on by default +help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_flatten` + | +LL + #![feature(ipu_flatten)] + | warning: a method with this name may be added to the standard library in the future --> $DIR/inference_unstable.rs:19:20 @@ -19,7 +22,10 @@ LL | assert_eq!('x'.ipu_by_value_vs_by_ref(), 1); = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior! = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919> = help: call with fully qualified syntax `inference_unstable_itertools::IpuItertools::ipu_by_value_vs_by_ref(...)` to keep using the current method - = help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_by_value_vs_by_ref` +help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_by_value_vs_by_ref` + | +LL + #![feature(ipu_flatten)] + | warning: a method with this name may be added to the standard library in the future --> $DIR/inference_unstable.rs:22:20 @@ -30,7 +36,10 @@ LL | assert_eq!('x'.ipu_by_ref_vs_by_ref_mut(), 1); = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior! = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919> = help: call with fully qualified syntax `inference_unstable_itertools::IpuItertools::ipu_by_ref_vs_by_ref_mut(...)` to keep using the current method - = help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_by_ref_vs_by_ref_mut` +help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_by_ref_vs_by_ref_mut` + | +LL + #![feature(ipu_flatten)] + | warning: a method with this name may be added to the standard library in the future --> $DIR/inference_unstable.rs:25:40 @@ -41,17 +50,27 @@ LL | assert_eq!((&mut 'x' as *mut char).ipu_by_mut_ptr_vs_by_const_ptr(), 1) = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior! = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919> = help: call with fully qualified syntax `inference_unstable_itertools::IpuItertools::ipu_by_mut_ptr_vs_by_const_ptr(...)` to keep using the current method - = help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_by_mut_ptr_vs_by_const_ptr` +help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_by_mut_ptr_vs_by_const_ptr` + | +LL + #![feature(ipu_flatten)] + | warning: an associated constant with this name may be added to the standard library in the future --> $DIR/inference_unstable.rs:28:16 | LL | assert_eq!(char::C, 1); - | ^^^^^^^ help: use the fully qualified path to the associated const: `<char as IpuItertools>::C` + | ^^^^^^^ | = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior! = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919> - = help: add `#![feature(assoc_const_ipu_iter)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::C` +help: use the fully qualified path to the associated const + | +LL | assert_eq!(<char as IpuItertools>::C, 1); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ +help: add `#![feature(assoc_const_ipu_iter)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::C` + | +LL + #![feature(assoc_const_ipu_iter)] + | warning: 5 warnings emitted diff --git a/tests/ui/inference/issue-107090.rs b/tests/ui/inference/issue-107090.rs index d1c86fb03d7..799c3641833 100644 --- a/tests/ui/inference/issue-107090.rs +++ b/tests/ui/inference/issue-107090.rs @@ -19,7 +19,7 @@ impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> { fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T { //~^ ERROR use of undeclared lifetime name - sadness.cast() //~ ERROR: mismatched types + sadness.cast() } fn main() {} diff --git a/tests/ui/inference/issue-107090.stderr b/tests/ui/inference/issue-107090.stderr index 55825f7765b..e509e262fb1 100644 --- a/tests/ui/inference/issue-107090.stderr +++ b/tests/ui/inference/issue-107090.stderr @@ -66,19 +66,6 @@ LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, | | | help: consider introducing lifetime `'short` here: `'short,` -error[E0308]: mismatched types - --> $DIR/issue-107090.rs:22:5 - | -LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T { - | - expected this type parameter ------- expected `&'out T` because of return type -LL | -LL | sadness.cast() - | ^^^^^^^^^^^^^^ expected `&T`, found `&Foo<'_, '_, T>` - | - = note: expected reference `&'out T` - found reference `&Foo<'_, '_, T>` - -error: aborting due to 7 previous errors +error: aborting due to 6 previous errors -Some errors have detailed explanations: E0261, E0308. -For more information about an error, try `rustc --explain E0261`. +For more information about this error, try `rustc --explain E0261`. diff --git a/tests/ui/issues/issue-10412.rs b/tests/ui/issues/issue-10412.rs index 0de170161b5..68ce0c2ea3c 100644 --- a/tests/ui/issues/issue-10412.rs +++ b/tests/ui/issues/issue-10412.rs @@ -8,7 +8,6 @@ impl<'self> Serializable<str> for &'self str { //~^ ERROR lifetimes cannot use keyword names //~| ERROR lifetimes cannot use keyword names //~| ERROR implicit elided lifetime not allowed here - //~| ERROR the size for values of type `str` cannot be known at compilation time [E0277] fn serialize(val: &'self str) -> Vec<u8> { //~^ ERROR lifetimes cannot use keyword names vec![1] diff --git a/tests/ui/issues/issue-10412.stderr b/tests/ui/issues/issue-10412.stderr index 02a26034f9a..c74ba1306cc 100644 --- a/tests/ui/issues/issue-10412.stderr +++ b/tests/ui/issues/issue-10412.stderr @@ -29,13 +29,13 @@ LL | impl<'self> Serializable<str> for &'self str { | ^^^^^ error: lifetimes cannot use keyword names - --> $DIR/issue-10412.rs:12:24 + --> $DIR/issue-10412.rs:11:24 | LL | fn serialize(val: &'self str) -> Vec<u8> { | ^^^^^ error: lifetimes cannot use keyword names - --> $DIR/issue-10412.rs:16:37 + --> $DIR/issue-10412.rs:15:37 | LL | fn deserialize(repr: &[u8]) -> &'self str { | ^^^^^ @@ -51,24 +51,6 @@ help: indicate the anonymous lifetime LL | impl<'self> Serializable<'_, str> for &'self str { | +++ -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/issue-10412.rs:7:13 - | -LL | impl<'self> Serializable<str> for &'self str { - | ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `str` -note: required by an implicit `Sized` bound in `Serializable` - --> $DIR/issue-10412.rs:1:27 - | -LL | trait Serializable<'self, T> { - | ^ required by the implicit `Sized` requirement on this type parameter in `Serializable` -help: consider relaxing the implicit `Sized` restriction - | -LL | trait Serializable<'self, T: ?Sized> { - | ++++++++ - -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors -Some errors have detailed explanations: E0277, E0726. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0726`. diff --git a/tests/ui/issues/issue-17361.rs b/tests/ui/issues/issue-17361.rs index 8e85f0791d6..1b1eeb5a252 100644 --- a/tests/ui/issues/issue-17361.rs +++ b/tests/ui/issues/issue-17361.rs @@ -1,5 +1,5 @@ //@ run-pass -// Test that astconv doesn't forget about mutability of &mut str +// Test that HIR ty lowering doesn't forget about mutability of `&mut str`. //@ pretty-expanded FIXME #23616 diff --git a/tests/ui/issues/issue-25901.stderr b/tests/ui/issues/issue-25901.stderr index 673f29fff18..5c19abffa02 100644 --- a/tests/ui/issues/issue-25901.stderr +++ b/tests/ui/issues/issue-25901.stderr @@ -16,8 +16,11 @@ note: impl defined here, but it is not `const` LL | impl Deref for A { | ^^^^^^^^^^^^^^^^ = note: calls in statics are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-27942.stderr b/tests/ui/issues/issue-27942.stderr index 7ea9345a668..8ea46bae26d 100644 --- a/tests/ui/issues/issue-27942.stderr +++ b/tests/ui/issues/issue-27942.stderr @@ -6,16 +6,16 @@ LL | fn select(&self) -> BufferViewHandle<R>; | = note: expected trait `Resources<'_>` found trait `Resources<'a>` -note: the anonymous lifetime defined here... - --> $DIR/issue-27942.rs:5:15 - | -LL | fn select(&self) -> BufferViewHandle<R>; - | ^^^^^ -note: ...does not necessarily outlive the lifetime `'a` as defined here +note: the lifetime `'a` as defined here... --> $DIR/issue-27942.rs:3:18 | LL | pub trait Buffer<'a, R: Resources<'a>> { | ^^ +note: ...does not necessarily outlive the anonymous lifetime defined here + --> $DIR/issue-27942.rs:5:15 + | +LL | fn select(&self) -> BufferViewHandle<R>; + | ^^^^^ error[E0308]: mismatched types --> $DIR/issue-27942.rs:5:25 @@ -25,16 +25,16 @@ LL | fn select(&self) -> BufferViewHandle<R>; | = note: expected trait `Resources<'_>` found trait `Resources<'a>` -note: the lifetime `'a` as defined here... - --> $DIR/issue-27942.rs:3:18 - | -LL | pub trait Buffer<'a, R: Resources<'a>> { - | ^^ -note: ...does not necessarily outlive the anonymous lifetime defined here +note: the anonymous lifetime defined here... --> $DIR/issue-27942.rs:5:15 | LL | fn select(&self) -> BufferViewHandle<R>; | ^^^^^ +note: ...does not necessarily outlive the lifetime `'a` as defined here + --> $DIR/issue-27942.rs:3:18 + | +LL | pub trait Buffer<'a, R: Resources<'a>> { + | ^^ error: aborting due to 2 previous errors diff --git a/tests/ui/issues/issue-87199.rs b/tests/ui/issues/issue-87199.rs index 081c45d6151..34879c5a7ca 100644 --- a/tests/ui/issues/issue-87199.rs +++ b/tests/ui/issues/issue-87199.rs @@ -11,6 +11,7 @@ fn ref_arg<T: ?Send>(_: &T) {} //~^ warning: relaxing a default bound only does something for `?Sized` fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() } //~^ warning: relaxing a default bound only does something for `?Sized` +//~| warning: relaxing a default bound only does something for `?Sized` // Check that there's no `?Sized` relaxation! fn main() { diff --git a/tests/ui/issues/issue-87199.stderr b/tests/ui/issues/issue-87199.stderr index 34433eef5c7..a0ed2946fb4 100644 --- a/tests/ui/issues/issue-87199.stderr +++ b/tests/ui/issues/issue-87199.stderr @@ -16,8 +16,16 @@ warning: relaxing a default bound only does something for `?Sized`; all other tr LL | fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() } | ^^^^^ +warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default + --> $DIR/issue-87199.rs:12:40 + | +LL | fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() } + | ^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0277]: the size for values of type `[i32]` cannot be known at compilation time - --> $DIR/issue-87199.rs:18:15 + --> $DIR/issue-87199.rs:19:15 | LL | ref_arg::<[i32]>(&[5]); | ^^^^^ doesn't have a size known at compile-time @@ -33,6 +41,6 @@ help: consider relaxing the implicit `Sized` restriction LL | fn ref_arg<T: ?Send + ?Sized>(_: &T) {} | ++++++++ -error: aborting due to 1 previous error; 3 warnings emitted +error: aborting due to 1 previous error; 4 warnings emitted For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/lifetimes/could-not-resolve-issue-121503.rs b/tests/ui/lifetimes/could-not-resolve-issue-121503.rs index 6bc70a907d9..363162370f2 100644 --- a/tests/ui/lifetimes/could-not-resolve-issue-121503.rs +++ b/tests/ui/lifetimes/could-not-resolve-issue-121503.rs @@ -4,8 +4,7 @@ struct Struct; impl Struct { async fn box_ref_Struct(self: Box<Self, impl FnMut(&mut Self)>) -> &u32 { - //~^ ERROR the trait bound `impl FnMut(&mut Self): Allocator` is not satisfied - //~| ERROR Box<Struct, impl FnMut(&mut Self)>` cannot be used as the type of `self` without + //~^ ERROR Box<Struct, impl FnMut(&mut Self)>` cannot be used as the type of `self` without &1 } } diff --git a/tests/ui/lifetimes/could-not-resolve-issue-121503.stderr b/tests/ui/lifetimes/could-not-resolve-issue-121503.stderr index a5d8239a2df..3babf63347c 100644 --- a/tests/ui/lifetimes/could-not-resolve-issue-121503.stderr +++ b/tests/ui/lifetimes/could-not-resolve-issue-121503.stderr @@ -1,16 +1,3 @@ -error[E0277]: the trait bound `impl FnMut(&mut Self): Allocator` is not satisfied - --> $DIR/could-not-resolve-issue-121503.rs:6:5 - | -LL | async fn box_ref_Struct(self: Box<Self, impl FnMut(&mut Self)>) -> &u32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Allocator` is not implemented for `impl FnMut(&mut Self)` - | -note: required by a bound in `Box` - --> $SRC_DIR/alloc/src/boxed.rs:LL:COL -help: consider further restricting this bound - | -LL | async fn box_ref_Struct(self: Box<Self, impl FnMut(&mut Self) + std::alloc::Allocator>) -> &u32 { - | +++++++++++++++++++++++ - error[E0658]: `Box<Struct, impl FnMut(&mut Self)>` cannot be used as the type of `self` without the `arbitrary_self_types` feature --> $DIR/could-not-resolve-issue-121503.rs:6:35 | @@ -22,7 +9,6 @@ LL | async fn box_ref_Struct(self: Box<Self, impl FnMut(&mut Self)>) -> &u32 = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0277, E0658. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/lifetimes/issue-26638.rs b/tests/ui/lifetimes/issue-26638.rs index 4bec3b3415b..11c730165f2 100644 --- a/tests/ui/lifetimes/issue-26638.rs +++ b/tests/ui/lifetimes/issue-26638.rs @@ -1,6 +1,5 @@ fn parse_type(iter: Box<dyn Iterator<Item=&str>+'static>) -> &str { iter.next() } //~^ ERROR missing lifetime specifier [E0106] -//~| ERROR mismatched types fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() } //~^ ERROR missing lifetime specifier [E0106] diff --git a/tests/ui/lifetimes/issue-26638.stderr b/tests/ui/lifetimes/issue-26638.stderr index ee958686259..403a8c67ccb 100644 --- a/tests/ui/lifetimes/issue-26638.stderr +++ b/tests/ui/lifetimes/issue-26638.stderr @@ -11,7 +11,7 @@ LL | fn parse_type<'a>(iter: Box<dyn Iterator<Item=&'a str>+'static>) -> &'a str | ++++ ++ ++ error[E0106]: missing lifetime specifier - --> $DIR/issue-26638.rs:5:40 + --> $DIR/issue-26638.rs:4:40 | LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() } | ^ expected named lifetime parameter @@ -31,7 +31,7 @@ LL | fn parse_type_2(iter: fn(&u8)->&u8) -> String { iter() } | ~~~~~~ error[E0106]: missing lifetime specifier - --> $DIR/issue-26638.rs:10:22 + --> $DIR/issue-26638.rs:9:22 | LL | fn parse_type_3() -> &str { unimplemented!() } | ^ expected named lifetime parameter @@ -46,23 +46,8 @@ help: instead, you are more likely to want to return an owned value LL | fn parse_type_3() -> String { unimplemented!() } | ~~~~~~ -error[E0308]: mismatched types - --> $DIR/issue-26638.rs:1:69 - | -LL | fn parse_type(iter: Box<dyn Iterator<Item=&str>+'static>) -> &str { iter.next() } - | ---- ^^^^^^^^^^^ expected `&str`, found `Option<&str>` - | | - | expected `&str` because of return type - | - = note: expected reference `&str` - found enum `Option<&str>` -help: consider using `Option::expect` to unwrap the `Option<&str>` value, panicking if the value is an `Option::None` - | -LL | fn parse_type(iter: Box<dyn Iterator<Item=&str>+'static>) -> &str { iter.next().expect("REASON") } - | +++++++++++++++++ - error[E0061]: this function takes 1 argument but 0 arguments were supplied - --> $DIR/issue-26638.rs:5:47 + --> $DIR/issue-26638.rs:4:47 | LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() } | ^^^^-- an argument of type `&u8` is missing @@ -73,7 +58,7 @@ LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter(/* &u8 */) } | ~~~~~~~~~~~ error[E0308]: mismatched types - --> $DIR/issue-26638.rs:5:47 + --> $DIR/issue-26638.rs:4:47 | LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() } | ---- ^^^^^^ expected `&str`, found `&u8` @@ -83,7 +68,7 @@ LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() } = note: expected reference `&'static str` found reference `&u8` -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors Some errors have detailed explanations: E0061, E0106, E0308. For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/lifetimes/lifetime-errors/ex1b-return-no-names-if-else.rs b/tests/ui/lifetimes/lifetime-errors/ex1b-return-no-names-if-else.rs index 56f89b70410..d6c918843c7 100644 --- a/tests/ui/lifetimes/lifetime-errors/ex1b-return-no-names-if-else.rs +++ b/tests/ui/lifetimes/lifetime-errors/ex1b-return-no-names-if-else.rs @@ -1,7 +1,5 @@ fn foo(x: &i32, y: &i32) -> &i32 { //~ ERROR missing lifetime if x > y { x } else { y } - //~^ ERROR: lifetime may not live long enough - //~| ERROR: lifetime may not live long enough } fn main() {} diff --git a/tests/ui/lifetimes/lifetime-errors/ex1b-return-no-names-if-else.stderr b/tests/ui/lifetimes/lifetime-errors/ex1b-return-no-names-if-else.stderr index db5b039d1c2..62b0a8a04bf 100644 --- a/tests/ui/lifetimes/lifetime-errors/ex1b-return-no-names-if-else.stderr +++ b/tests/ui/lifetimes/lifetime-errors/ex1b-return-no-names-if-else.stderr @@ -10,22 +10,6 @@ help: consider introducing a named lifetime parameter LL | fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 { | ++++ ++ ++ ++ -error: lifetime may not live long enough - --> $DIR/ex1b-return-no-names-if-else.rs:2:16 - | -LL | fn foo(x: &i32, y: &i32) -> &i32 { - | - let's call the lifetime of this reference `'1` -LL | if x > y { x } else { y } - | ^ returning this value requires that `'1` must outlive `'static` - -error: lifetime may not live long enough - --> $DIR/ex1b-return-no-names-if-else.rs:2:27 - | -LL | fn foo(x: &i32, y: &i32) -> &i32 { - | - let's call the lifetime of this reference `'2` -LL | if x > y { x } else { y } - | ^ returning this value requires that `'2` must outlive `'static` - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0106`. diff --git a/tests/ui/lifetimes/unusual-rib-combinations.stderr b/tests/ui/lifetimes/unusual-rib-combinations.stderr index e3b70232ef8..320e64a2f77 100644 --- a/tests/ui/lifetimes/unusual-rib-combinations.stderr +++ b/tests/ui/lifetimes/unusual-rib-combinations.stderr @@ -56,7 +56,10 @@ LL | fn d<const C: S>() {} | ^ | = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | error: aborting due to 8 previous errors diff --git a/tests/ui/lint/decorate-ice/decorate-can-emit-warnings.rs b/tests/ui/lint/decorate-ice/decorate-can-emit-warnings.rs new file mode 100644 index 00000000000..5adb5f526dc --- /dev/null +++ b/tests/ui/lint/decorate-ice/decorate-can-emit-warnings.rs @@ -0,0 +1,11 @@ +// Checks that the following does not ICE because `decorate` is incorrectly skipped. + +//@ compile-flags: -Dunused_must_use -Awarnings --crate-type=lib + +#[must_use] +fn f() {} + +pub fn g() { + f(); + //~^ ERROR unused return value +} diff --git a/tests/ui/lint/decorate-ice/decorate-can-emit-warnings.stderr b/tests/ui/lint/decorate-ice/decorate-can-emit-warnings.stderr new file mode 100644 index 00000000000..fde81de6136 --- /dev/null +++ b/tests/ui/lint/decorate-ice/decorate-can-emit-warnings.stderr @@ -0,0 +1,14 @@ +error: unused return value of `f` that must be used + --> $DIR/decorate-can-emit-warnings.rs:9:5 + | +LL | f(); + | ^^^ + | + = note: requested on the command line with `-D unused-must-use` +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = f(); + | +++++++ + +error: aborting due to 1 previous error + diff --git a/tests/ui/lint/decorate-ice/decorate-def-path-str-ice.rs b/tests/ui/lint/decorate-ice/decorate-def-path-str-ice.rs new file mode 100644 index 00000000000..8116e36ed0d --- /dev/null +++ b/tests/ui/lint/decorate-ice/decorate-def-path-str-ice.rs @@ -0,0 +1,30 @@ +// Checks that the following does not ICE. +// +// Previously, this test ICEs when the `unused_must_use` lint is suppressed via the combination of +// `-A warnings` and `--cap-lints=warn`, because: +// +// - Its lint diagnostic struct `UnusedDef` implements `LintDiagnostic` manually and in the impl +// `def_path_str` was called (which calls `trimmed_def_path`, which will produce a +// `must_produce_diag` ICE if a trimmed def path is constructed but never emitted in a diagnostic +// because it is expensive to compute). +// - A `LintDiagnostic` has a `decorate_lint` method which decorates a `Diag` with lint-specific +// information. This method is wrapped by a `decorate` closure in `TyCtxt` diagnostic emission +// machinery, and the `decorate` closure called as late as possible. +// - `decorate`'s invocation is delayed as late as possible until `lint_level` is called. +// - If a lint's corresponding diagnostic is suppressed (to be effectively allow at the final +// emission time) via `-A warnings` or `--cap-lints=allow` (or `-A warnings` + `--cap-lints=warn` +// like in this test case), `decorate` is still called and a diagnostic is still constructed -- +// but the diagnostic is never eventually emitted, triggering the aforementioned +// `must_produce_diag` ICE due to use of `trimmed_def_path`. +// +// Issue: <https://github.com/rust-lang/rust/issues/121774>. + +//@ compile-flags: -Dunused_must_use -Awarnings --cap-lints=warn --crate-type=lib +//@ check-pass + +#[must_use] +fn f() {} + +pub fn g() { + f(); +} diff --git a/tests/ui/lint/decorate-ice/decorate-force-warn.rs b/tests/ui/lint/decorate-ice/decorate-force-warn.rs new file mode 100644 index 00000000000..e33210ed0ce --- /dev/null +++ b/tests/ui/lint/decorate-ice/decorate-force-warn.rs @@ -0,0 +1,13 @@ +// Checks that the following does not ICE because `decorate` is incorrectly skipped due to +// `--force-warn`. + +//@ compile-flags: -Dunused_must_use -Awarnings --force-warn unused_must_use --crate-type=lib +//@ check-pass + +#[must_use] +fn f() {} + +pub fn g() { + f(); + //~^ WARN unused return value +} diff --git a/tests/ui/lint/decorate-ice/decorate-force-warn.stderr b/tests/ui/lint/decorate-ice/decorate-force-warn.stderr new file mode 100644 index 00000000000..5e6b74d414b --- /dev/null +++ b/tests/ui/lint/decorate-ice/decorate-force-warn.stderr @@ -0,0 +1,14 @@ +warning: unused return value of `f` that must be used + --> $DIR/decorate-force-warn.rs:11:5 + | +LL | f(); + | ^^^ + | + = note: requested on the command line with `--force-warn unused-must-use` +help: use `let _ = ...` to ignore the resulting value + | +LL | let _ = f(); + | +++++++ + +warning: 1 warning emitted + diff --git a/tests/ui/lint/invalid_value.stderr b/tests/ui/lint/invalid_value.stderr index 955d01bd5d9..b4e7421829f 100644 --- a/tests/ui/lint/invalid_value.stderr +++ b/tests/ui/lint/invalid_value.stderr @@ -320,23 +320,19 @@ error: the type `(NonZero<u32>, i32)` does not permit zero-initialization --> $DIR/invalid_value.rs:94:41 | LL | let _val: (NonZero<u32>, i32) = mem::zeroed(); - | ^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done + | ^^^^^^^^^^^^^ this code causes undefined behavior when executed | = note: `std::num::NonZero<u32>` must be non-null + = note: because `core::num::nonzero::private::NonZeroU32Inner` must be non-null error: the type `(NonZero<u32>, i32)` does not permit being left uninitialized --> $DIR/invalid_value.rs:95:41 | LL | let _val: (NonZero<u32>, i32) = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done + | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | = note: `std::num::NonZero<u32>` must be non-null + = note: because `core::num::nonzero::private::NonZeroU32Inner` must be non-null = note: integers must be initialized error: the type `*const dyn Send` does not permit zero-initialization @@ -411,10 +407,7 @@ error: the type `OneFruitNonZero` does not permit zero-initialization --> $DIR/invalid_value.rs:106:37 | LL | let _val: OneFruitNonZero = mem::zeroed(); - | ^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done + | ^^^^^^^^^^^^^ this code causes undefined behavior when executed | = note: `OneFruitNonZero` must be non-null note: because `std::num::NonZero<u32>` must be non-null (in this field of the only potentially inhabited enum variant) @@ -422,15 +415,13 @@ note: because `std::num::NonZero<u32>` must be non-null (in this field of the on | LL | Banana(NonZero<u32>), | ^^^^^^^^^^^^ + = note: because `core::num::nonzero::private::NonZeroU32Inner` must be non-null error: the type `OneFruitNonZero` does not permit being left uninitialized --> $DIR/invalid_value.rs:107:37 | LL | let _val: OneFruitNonZero = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done + | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | = note: `OneFruitNonZero` must be non-null note: because `std::num::NonZero<u32>` must be non-null (in this field of the only potentially inhabited enum variant) @@ -438,6 +429,7 @@ note: because `std::num::NonZero<u32>` must be non-null (in this field of the on | LL | Banana(NonZero<u32>), | ^^^^^^^^^^^^ + = note: because `core::num::nonzero::private::NonZeroU32Inner` must be non-null = note: integers must be initialized error: the type `bool` does not permit being left uninitialized @@ -607,12 +599,10 @@ error: the type `NonZero<u32>` does not permit zero-initialization --> $DIR/invalid_value.rs:153:34 | LL | let _val: NonZero<u32> = mem::transmute(0); - | ^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done + | ^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | = note: `std::num::NonZero<u32>` must be non-null + = note: because `core::num::nonzero::private::NonZeroU32Inner` must be non-null error: the type `NonNull<i32>` does not permit zero-initialization --> $DIR/invalid_value.rs:156:34 diff --git a/tests/ui/lint/lint-qualification.fixed b/tests/ui/lint/lint-qualification.fixed index 6fe6ba2792f..7c8fd5236e6 100644 --- a/tests/ui/lint/lint-qualification.fixed +++ b/tests/ui/lint/lint-qualification.fixed @@ -16,7 +16,6 @@ fn main() { let _ = || -> Result<(), ()> { try!(Ok(())); Ok(()) }; // issue #37345 let _ = String::new(); //~ ERROR: unnecessary qualification - let _ = std::env::current_dir(); //~ ERROR: unnecessary qualification let _: Vec<String> = Vec::<String>::new(); //~^ ERROR: unnecessary qualification @@ -27,7 +26,7 @@ fn main() { let _: std::fmt::Result = Ok(()); // don't report unnecessary qualification because fix(#122373) for issue #121331 - let _ = <bool as Default>::default(); // issue #121999 + let _ = <bool as Default>::default(); // issue #121999 (modified) //~^ ERROR: unnecessary qualification macro_rules! m { ($a:ident, $b:ident) => { @@ -36,6 +35,7 @@ fn main() { foo::bar(); foo::$b(); // issue #96698 $a::bar(); + $a::$b(); } } m!(foo, bar); } diff --git a/tests/ui/lint/lint-qualification.rs b/tests/ui/lint/lint-qualification.rs index 19d339b006c..009b3080d5c 100644 --- a/tests/ui/lint/lint-qualification.rs +++ b/tests/ui/lint/lint-qualification.rs @@ -16,7 +16,6 @@ fn main() { let _ = || -> Result<(), ()> { try!(Ok(())); Ok(()) }; // issue #37345 let _ = std::string::String::new(); //~ ERROR: unnecessary qualification - let _ = ::std::env::current_dir(); //~ ERROR: unnecessary qualification let _: std::vec::Vec<String> = std::vec::Vec::<String>::new(); //~^ ERROR: unnecessary qualification @@ -27,7 +26,7 @@ fn main() { let _: std::fmt::Result = Ok(()); // don't report unnecessary qualification because fix(#122373) for issue #121331 - let _ = <bool as ::std::default::Default>::default(); // issue #121999 + let _ = <bool as std::default::Default>::default(); // issue #121999 (modified) //~^ ERROR: unnecessary qualification macro_rules! m { ($a:ident, $b:ident) => { @@ -36,6 +35,7 @@ fn main() { foo::bar(); foo::$b(); // issue #96698 $a::bar(); + $a::$b(); } } m!(foo, bar); } diff --git a/tests/ui/lint/lint-qualification.stderr b/tests/ui/lint/lint-qualification.stderr index 9e5c9b2df13..cefa54a12ae 100644 --- a/tests/ui/lint/lint-qualification.stderr +++ b/tests/ui/lint/lint-qualification.stderr @@ -40,19 +40,7 @@ LL + let _ = String::new(); | error: unnecessary qualification - --> $DIR/lint-qualification.rs:19:13 - | -LL | let _ = ::std::env::current_dir(); - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -help: remove the unnecessary path segments - | -LL - let _ = ::std::env::current_dir(); -LL + let _ = std::env::current_dir(); - | - -error: unnecessary qualification - --> $DIR/lint-qualification.rs:21:12 + --> $DIR/lint-qualification.rs:20:12 | LL | let _: std::vec::Vec<String> = std::vec::Vec::<String>::new(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +52,7 @@ LL + let _: Vec<String> = std::vec::Vec::<String>::new(); | error: unnecessary qualification - --> $DIR/lint-qualification.rs:21:36 + --> $DIR/lint-qualification.rs:20:36 | LL | let _: std::vec::Vec<String> = std::vec::Vec::<String>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -76,7 +64,7 @@ LL + let _: std::vec::Vec<String> = Vec::<String>::new(); | error: unused import: `std::fmt` - --> $DIR/lint-qualification.rs:25:9 + --> $DIR/lint-qualification.rs:24:9 | LL | use std::fmt; | ^^^^^^^^ @@ -88,16 +76,16 @@ LL | #![deny(unused_imports)] | ^^^^^^^^^^^^^^ error: unnecessary qualification - --> $DIR/lint-qualification.rs:30:13 + --> $DIR/lint-qualification.rs:29:13 | -LL | let _ = <bool as ::std::default::Default>::default(); // issue #121999 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let _ = <bool as std::default::Default>::default(); // issue #121999 (modified) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the unnecessary path segments | -LL - let _ = <bool as ::std::default::Default>::default(); // issue #121999 -LL + let _ = <bool as Default>::default(); // issue #121999 +LL - let _ = <bool as std::default::Default>::default(); // issue #121999 (modified) +LL + let _ = <bool as Default>::default(); // issue #121999 (modified) | -error: aborting due to 8 previous errors +error: aborting due to 7 previous errors diff --git a/tests/ui/lint/must_not_suspend/allocator.rs b/tests/ui/lint/must_not_suspend/allocator.rs new file mode 100644 index 00000000000..c2ceb3297f3 --- /dev/null +++ b/tests/ui/lint/must_not_suspend/allocator.rs @@ -0,0 +1,30 @@ +//@ edition: 2021 + +#![feature(must_not_suspend, allocator_api)] +#![deny(must_not_suspend)] + +use std::alloc::*; +use std::ptr::NonNull; + +#[must_not_suspend] +struct MyAllocatorWhichMustNotSuspend; + +unsafe impl Allocator for MyAllocatorWhichMustNotSuspend { + fn allocate(&self, l: Layout) -> Result<NonNull<[u8]>, AllocError> { + Global.allocate(l) + } + unsafe fn deallocate(&self, p: NonNull<u8>, l: Layout) { + Global.deallocate(p, l) + } +} + +async fn suspend() {} + +async fn foo() { + let x = Box::new_in(1i32, MyAllocatorWhichMustNotSuspend); + //~^ ERROR allocator `MyAllocatorWhichMustNotSuspend` held across a suspend point, but should not be + suspend().await; + drop(x); +} + +fn main() {} diff --git a/tests/ui/lint/must_not_suspend/allocator.stderr b/tests/ui/lint/must_not_suspend/allocator.stderr new file mode 100644 index 00000000000..959945f2626 --- /dev/null +++ b/tests/ui/lint/must_not_suspend/allocator.stderr @@ -0,0 +1,22 @@ +error: allocator `MyAllocatorWhichMustNotSuspend` held across a suspend point, but should not be + --> $DIR/allocator.rs:24:9 + | +LL | let x = Box::new_in(1i32, MyAllocatorWhichMustNotSuspend); + | ^ +LL | +LL | suspend().await; + | ----- the value is held across this suspend point + | +help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point + --> $DIR/allocator.rs:24:9 + | +LL | let x = Box::new_in(1i32, MyAllocatorWhichMustNotSuspend); + | ^ +note: the lint level is defined here + --> $DIR/allocator.rs:4:9 + | +LL | #![deny(must_not_suspend)] + | ^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/lint/unused-qualifications-global-paths.rs b/tests/ui/lint/unused-qualifications-global-paths.rs new file mode 100644 index 00000000000..8265c8a1694 --- /dev/null +++ b/tests/ui/lint/unused-qualifications-global-paths.rs @@ -0,0 +1,12 @@ +// Checks that `unused_qualifications` don't fire on explicit global paths. +// Issue: <https://github.com/rust-lang/rust/issues/122374>. + +//@ check-pass + +#![deny(unused_qualifications)] + +pub fn bar() -> u64 { + ::std::default::Default::default() +} + +fn main() {} diff --git a/tests/ui/lint/unused/unused-associated-item.rs b/tests/ui/lint/unused/unused-associated-item.rs new file mode 100644 index 00000000000..27cb4e979f1 --- /dev/null +++ b/tests/ui/lint/unused/unused-associated-item.rs @@ -0,0 +1,21 @@ +//@ check-pass + +#![deny(unused_must_use)] + +use std::future::Future; +use std::pin::Pin; + +trait Factory { + type Output; +} + +impl Factory for () { + type Output = Pin<Box<dyn Future<Output = ()> + 'static>>; +} + +// Make sure we don't get an `unused_must_use` error on the *associated type bound*. +fn f() -> impl Factory<Output: Future> {} + +fn main() { + f(); +} diff --git a/tests/ui/macros/derive-in-eager-expansion-hang.stderr b/tests/ui/macros/derive-in-eager-expansion-hang.stderr index e0f6d5b2de0..b61ef2a9bab 100644 --- a/tests/ui/macros/derive-in-eager-expansion-hang.stderr +++ b/tests/ui/macros/derive-in-eager-expansion-hang.stderr @@ -4,8 +4,7 @@ error: format argument must be a string literal LL | / { LL | | #[derive(Clone)] LL | | struct S; -LL | | -LL | | "" +... | LL | | } | |_____^ ... diff --git a/tests/ui/macros/paren-or-brace-expected.rs b/tests/ui/macros/paren-or-brace-expected.rs new file mode 100644 index 00000000000..1776fa78884 --- /dev/null +++ b/tests/ui/macros/paren-or-brace-expected.rs @@ -0,0 +1,9 @@ +macro_rules! foo { + ( $( $i:ident ),* ) => { + $[count($i)] + //~^ ERROR expected `(` or `{`, found `[` + //~| ERROR + }; +} + +fn main() {} diff --git a/tests/ui/macros/paren-or-brace-expected.stderr b/tests/ui/macros/paren-or-brace-expected.stderr new file mode 100644 index 00000000000..4d1dda97751 --- /dev/null +++ b/tests/ui/macros/paren-or-brace-expected.stderr @@ -0,0 +1,14 @@ +error: expected `(` or `{`, found `[` + --> $DIR/paren-or-brace-expected.rs:3:10 + | +LL | $[count($i)] + | ^^^^^^^^^^^ + +error: expected one of: `*`, `+`, or `?` + --> $DIR/paren-or-brace-expected.rs:3:10 + | +LL | $[count($i)] + | ^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/match/postfix-match/pf-match-chain.rs b/tests/ui/match/postfix-match/pf-match-chain.rs new file mode 100644 index 00000000000..80546e1963b --- /dev/null +++ b/tests/ui/match/postfix-match/pf-match-chain.rs @@ -0,0 +1,16 @@ +//@ run-pass + +#![feature(postfix_match)] + +fn main() { + 1.match { + 2 => Some(0), + _ => None, + }.match { + None => Ok(true), + Some(_) => Err("nope") + }.match { + Ok(_) => (), + Err(_) => panic!() + } +} diff --git a/tests/ui/match/postfix-match/pf-match-exhaustiveness.rs b/tests/ui/match/postfix-match/pf-match-exhaustiveness.rs new file mode 100644 index 00000000000..f4cac46f7cd --- /dev/null +++ b/tests/ui/match/postfix-match/pf-match-exhaustiveness.rs @@ -0,0 +1,7 @@ +#![feature(postfix_match)] + +fn main() { + Some(1).match { //~ non-exhaustive patterns + None => {}, + } +} diff --git a/tests/ui/match/postfix-match/pf-match-exhaustiveness.stderr b/tests/ui/match/postfix-match/pf-match-exhaustiveness.stderr new file mode 100644 index 00000000000..f458218bb5d --- /dev/null +++ b/tests/ui/match/postfix-match/pf-match-exhaustiveness.stderr @@ -0,0 +1,21 @@ +error[E0004]: non-exhaustive patterns: `Some(_)` not covered + --> $DIR/pf-match-exhaustiveness.rs:4:5 + | +LL | Some(1).match { + | ^^^^^^^ pattern `Some(_)` not covered + | +note: `Option<i32>` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Option<i32>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ None => {}, +LL ~ Some(_) => todo!(), + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0004`. diff --git a/tests/ui/match/postfix-match/pf-match-types.rs b/tests/ui/match/postfix-match/pf-match-types.rs new file mode 100644 index 00000000000..af205926fb6 --- /dev/null +++ b/tests/ui/match/postfix-match/pf-match-types.rs @@ -0,0 +1,15 @@ +#![feature(postfix_match)] + +fn main() { + Some(10).match { + //~^ NOTE `match` arms have incompatible types + Some(5) => false, + //~^ NOTE this is found to be of type `bool` + Some(2) => true, + //~^ NOTE this is found to be of type `bool` + None => (), + //~^ ERROR `match` arms have incompatible types + //~| NOTE expected `bool`, found `()` + _ => true + } +} diff --git a/tests/ui/match/postfix-match/pf-match-types.stderr b/tests/ui/match/postfix-match/pf-match-types.stderr new file mode 100644 index 00000000000..0cfc1363d5f --- /dev/null +++ b/tests/ui/match/postfix-match/pf-match-types.stderr @@ -0,0 +1,21 @@ +error[E0308]: `match` arms have incompatible types + --> $DIR/pf-match-types.rs:10:20 + | +LL | / Some(10).match { +LL | | +LL | | Some(5) => false, + | | ----- this is found to be of type `bool` +LL | | +LL | | Some(2) => true, + | | ---- this is found to be of type `bool` +LL | | +LL | | None => (), + | | ^^ expected `bool`, found `()` +... | +LL | | _ => true +LL | | } + | |_____- `match` arms have incompatible types + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/match/postfix-match/postfix-match.rs b/tests/ui/match/postfix-match/postfix-match.rs new file mode 100644 index 00000000000..03c4e8ab545 --- /dev/null +++ b/tests/ui/match/postfix-match/postfix-match.rs @@ -0,0 +1,62 @@ +//@ run-pass + +#![feature(postfix_match)] + +struct Bar { + foo: u8, + baz: u8, +} + +pub fn main() { + let thing = Some("thing"); + + thing.match { + Some("nothing") => {}, + Some(text) if text.eq_ignore_ascii_case("tapir") => {}, + Some("true") | Some("false") => {}, + Some("thing") => {}, + Some(_) => {}, + None => {} + }; + + let num = 2u8; + + num.match { + 0 => {}, + 1..=5 => {}, + _ => {}, + }; + + let slic = &[1, 2, 3, 4][..]; + + slic.match { + [1] => {}, + [2, _tail @ ..] => {}, + [1, _] => {}, + _ => {}, + }; + + slic[0].match { + 1 => 0, + i => i, + }; + + let out = (1, 2).match { + (1, 3) => 0, + (_, 1) => 0, + (1, i) => i, + _ => 3, + }; + assert!(out == 2); + + let strct = Bar { + foo: 3, + baz: 4 + }; + + strct.match { + Bar { foo: 1, .. } => {}, + Bar { baz: 2, .. } => {}, + _ => (), + }; +} diff --git a/tests/ui/moves/nested-loop-moved-value-wrong-continue.rs b/tests/ui/moves/nested-loop-moved-value-wrong-continue.rs new file mode 100644 index 00000000000..0235b291df5 --- /dev/null +++ b/tests/ui/moves/nested-loop-moved-value-wrong-continue.rs @@ -0,0 +1,50 @@ +fn foo() { + let foos = vec![String::new()]; + let bars = vec![""]; + let mut baz = vec![]; + let mut qux = vec![]; + for foo in foos { for bar in &bars { if foo == *bar { + //~^ NOTE this reinitialization might get skipped + //~| NOTE move occurs because `foo` has type `String` + //~| NOTE inside of this loop + //~| HELP consider moving the expression out of the loop + //~| NOTE in this expansion of desugaring of `for` loop + baz.push(foo); + //~^ NOTE value moved here + //~| HELP consider cloning the value + continue; + //~^ NOTE verify that your loop breaking logic is correct + //~| NOTE this `continue` advances the loop at $DIR/nested-loop-moved-value-wrong-continue.rs:6:23 + } } + qux.push(foo); + //~^ ERROR use of moved value + //~| NOTE value used here + } +} + +fn main() { + let foos = vec![String::new()]; + let bars = vec![""]; + let mut baz = vec![]; + let mut qux = vec![]; + for foo in foos { + //~^ NOTE this reinitialization might get skipped + //~| NOTE move occurs because `foo` has type `String` + for bar in &bars { + //~^ NOTE inside of this loop + //~| HELP consider moving the expression out of the loop + //~| NOTE in this expansion of desugaring of `for` loop + if foo == *bar { + baz.push(foo); + //~^ NOTE value moved here + //~| HELP consider cloning the value + continue; + //~^ NOTE verify that your loop breaking logic is correct + //~| NOTE this `continue` advances the loop at line 33 + } + } + qux.push(foo); + //~^ ERROR use of moved value + //~| NOTE value used here + } +} diff --git a/tests/ui/moves/nested-loop-moved-value-wrong-continue.stderr b/tests/ui/moves/nested-loop-moved-value-wrong-continue.stderr new file mode 100644 index 00000000000..3247513d42c --- /dev/null +++ b/tests/ui/moves/nested-loop-moved-value-wrong-continue.stderr @@ -0,0 +1,83 @@ +error[E0382]: use of moved value: `foo` + --> $DIR/nested-loop-moved-value-wrong-continue.rs:19:14 + | +LL | for foo in foos { for bar in &bars { if foo == *bar { + | --- ---------------- inside of this loop + | | + | this reinitialization might get skipped + | move occurs because `foo` has type `String`, which does not implement the `Copy` trait +... +LL | baz.push(foo); + | --- value moved here, in previous iteration of loop +... +LL | qux.push(foo); + | ^^^ value used here after move + | +note: verify that your loop breaking logic is correct + --> $DIR/nested-loop-moved-value-wrong-continue.rs:15:9 + | +LL | for foo in foos { for bar in &bars { if foo == *bar { + | --------------- ---------------- +... +LL | continue; + | ^^^^^^^^ this `continue` advances the loop at $DIR/nested-loop-moved-value-wrong-continue.rs:6:23: 18:8 +help: consider moving the expression out of the loop so it is only moved once + | +LL ~ for foo in foos { let mut value = baz.push(foo); +LL ~ for bar in &bars { if foo == *bar { +LL | + ... +LL | +LL ~ value; + | +help: consider cloning the value if the performance cost is acceptable + | +LL | baz.push(foo.clone()); + | ++++++++ + +error[E0382]: use of moved value: `foo` + --> $DIR/nested-loop-moved-value-wrong-continue.rs:46:18 + | +LL | for foo in foos { + | --- + | | + | this reinitialization might get skipped + | move occurs because `foo` has type `String`, which does not implement the `Copy` trait +... +LL | for bar in &bars { + | ---------------- inside of this loop +... +LL | baz.push(foo); + | --- value moved here, in previous iteration of loop +... +LL | qux.push(foo); + | ^^^ value used here after move + | +note: verify that your loop breaking logic is correct + --> $DIR/nested-loop-moved-value-wrong-continue.rs:41:17 + | +LL | for foo in foos { + | --------------- +... +LL | for bar in &bars { + | ---------------- +... +LL | continue; + | ^^^^^^^^ this `continue` advances the loop at line 33 +help: consider moving the expression out of the loop so it is only moved once + | +LL ~ let mut value = baz.push(foo); +LL ~ for bar in &bars { +LL | + ... +LL | if foo == *bar { +LL ~ value; + | +help: consider cloning the value if the performance cost is acceptable + | +LL | baz.push(foo.clone()); + | ++++++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/moves/recreating-value-in-loop-condition.rs b/tests/ui/moves/recreating-value-in-loop-condition.rs new file mode 100644 index 00000000000..ad012ff2978 --- /dev/null +++ b/tests/ui/moves/recreating-value-in-loop-condition.rs @@ -0,0 +1,65 @@ +fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> { + vec.into_iter() +} +fn foo() { + let vec = vec!["one", "two", "three"]; + while let Some(item) = iter(vec).next() { //~ ERROR use of moved value + //~^ HELP consider moving the expression out of the loop so it is only moved once + println!("{:?}", item); + } +} +fn bar() { + let vec = vec!["one", "two", "three"]; + loop { + //~^ HELP consider moving the expression out of the loop so it is only moved once + let Some(item) = iter(vec).next() else { //~ ERROR use of moved value + break; + }; + println!("{:?}", item); + } +} +fn baz() { + let vec = vec!["one", "two", "three"]; + loop { + //~^ HELP consider moving the expression out of the loop so it is only moved once + let item = iter(vec).next(); //~ ERROR use of moved value + //~^ HELP consider cloning + if item.is_none() { + break; + } + println!("{:?}", item); + } +} +fn qux() { + let vec = vec!["one", "two", "three"]; + loop { + //~^ HELP consider moving the expression out of the loop so it is only moved once + if let Some(item) = iter(vec).next() { //~ ERROR use of moved value + println!("{:?}", item); + break; + } + } +} +fn zap() { + loop { + let vec = vec!["one", "two", "three"]; + loop { + //~^ HELP consider moving the expression out of the loop so it is only moved once + loop { + loop { + if let Some(item) = iter(vec).next() { //~ ERROR use of moved value + println!("{:?}", item); + break; + } + } + } + } + } +} +fn main() { + foo(); + bar(); + baz(); + qux(); + zap(); +} diff --git a/tests/ui/moves/recreating-value-in-loop-condition.stderr b/tests/ui/moves/recreating-value-in-loop-condition.stderr new file mode 100644 index 00000000000..75c9633bc0a --- /dev/null +++ b/tests/ui/moves/recreating-value-in-loop-condition.stderr @@ -0,0 +1,157 @@ +error[E0382]: use of moved value: `vec` + --> $DIR/recreating-value-in-loop-condition.rs:6:33 + | +LL | let vec = vec!["one", "two", "three"]; + | --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait +LL | while let Some(item) = iter(vec).next() { + | ----------------------------^^^-------- + | | | + | | value moved here, in previous iteration of loop + | inside of this loop + | +note: consider changing this parameter type in function `iter` to borrow instead if owning the value isn't necessary + --> $DIR/recreating-value-in-loop-condition.rs:1:17 + | +LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> { + | ---- ^^^^^^ this parameter takes ownership of the value + | | + | in this function +help: consider moving the expression out of the loop so it is only moved once + | +LL ~ let mut value = iter(vec); +LL ~ while let Some(item) = value.next() { + | + +error[E0382]: use of moved value: `vec` + --> $DIR/recreating-value-in-loop-condition.rs:15:31 + | +LL | let vec = vec!["one", "two", "three"]; + | --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait +LL | loop { + | ---- inside of this loop +LL | +LL | let Some(item) = iter(vec).next() else { + | ^^^ value moved here, in previous iteration of loop + | +note: consider changing this parameter type in function `iter` to borrow instead if owning the value isn't necessary + --> $DIR/recreating-value-in-loop-condition.rs:1:17 + | +LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> { + | ---- ^^^^^^ this parameter takes ownership of the value + | | + | in this function +help: consider moving the expression out of the loop so it is only moved once + | +LL ~ let mut value = iter(vec); +LL ~ loop { +LL | +LL ~ let Some(item) = value.next() else { + | + +error[E0382]: use of moved value: `vec` + --> $DIR/recreating-value-in-loop-condition.rs:25:25 + | +LL | let vec = vec!["one", "two", "three"]; + | --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait +LL | loop { + | ---- inside of this loop +LL | +LL | let item = iter(vec).next(); + | ^^^ value moved here, in previous iteration of loop + | +note: consider changing this parameter type in function `iter` to borrow instead if owning the value isn't necessary + --> $DIR/recreating-value-in-loop-condition.rs:1:17 + | +LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> { + | ---- ^^^^^^ this parameter takes ownership of the value + | | + | in this function +help: consider moving the expression out of the loop so it is only moved once + | +LL ~ let mut value = iter(vec); +LL ~ loop { +LL | +LL ~ let item = value.next(); + | +help: consider cloning the value if the performance cost is acceptable + | +LL | let item = iter(vec.clone()).next(); + | ++++++++ + +error[E0382]: use of moved value: `vec` + --> $DIR/recreating-value-in-loop-condition.rs:37:34 + | +LL | let vec = vec!["one", "two", "three"]; + | --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait +LL | loop { + | ---- inside of this loop +LL | +LL | if let Some(item) = iter(vec).next() { + | ^^^ value moved here, in previous iteration of loop + | +note: consider changing this parameter type in function `iter` to borrow instead if owning the value isn't necessary + --> $DIR/recreating-value-in-loop-condition.rs:1:17 + | +LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> { + | ---- ^^^^^^ this parameter takes ownership of the value + | | + | in this function +help: consider moving the expression out of the loop so it is only moved once + | +LL ~ let mut value = iter(vec); +LL ~ loop { +LL | +LL ~ if let Some(item) = value.next() { + | + +error[E0382]: use of moved value: `vec` + --> $DIR/recreating-value-in-loop-condition.rs:50:46 + | +LL | let vec = vec!["one", "two", "three"]; + | --- move occurs because `vec` has type `Vec<&str>`, which does not implement the `Copy` trait +LL | loop { + | ---- inside of this loop +LL | +LL | loop { + | ---- inside of this loop +LL | loop { + | ---- inside of this loop +LL | if let Some(item) = iter(vec).next() { + | ^^^ value moved here, in previous iteration of loop + | +note: consider changing this parameter type in function `iter` to borrow instead if owning the value isn't necessary + --> $DIR/recreating-value-in-loop-condition.rs:1:17 + | +LL | fn iter<T>(vec: Vec<T>) -> impl Iterator<Item = T> { + | ---- ^^^^^^ this parameter takes ownership of the value + | | + | in this function +note: verify that your loop breaking logic is correct + --> $DIR/recreating-value-in-loop-condition.rs:52:25 + | +LL | loop { + | ---- +LL | let vec = vec!["one", "two", "three"]; +LL | loop { + | ---- +LL | +LL | loop { + | ---- +LL | loop { + | ---- +... +LL | break; + | ^^^^^ this `break` exits the loop at line 49 +help: consider moving the expression out of the loop so it is only moved once + | +LL ~ let mut value = iter(vec); +LL ~ loop { +LL | +LL | loop { +LL | loop { +LL ~ if let Some(item) = value.next() { + | + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/never_type/issue-52443.stderr b/tests/ui/never_type/issue-52443.stderr index 83afd9ef2f2..bab47064f6c 100644 --- a/tests/ui/never_type/issue-52443.stderr +++ b/tests/ui/never_type/issue-52443.stderr @@ -50,7 +50,10 @@ LL | [(); { for _ in 0usize.. {}; 0}]; note: impl defined here, but it is not `const` --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0658]: mutable references are not allowed in constants --> $DIR/issue-52443.rs:9:21 @@ -69,7 +72,10 @@ LL | [(); { for _ in 0usize.. {}; 0}]; | ^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 6 previous errors; 1 warning emitted diff --git a/tests/ui/nll/closure-requirements/escape-argument-callee.stderr b/tests/ui/nll/closure-requirements/escape-argument-callee.stderr index 8debea6a0a2..a7a59dccf22 100644 --- a/tests/ui/nll/closure-requirements/escape-argument-callee.stderr +++ b/tests/ui/nll/closure-requirements/escape-argument-callee.stderr @@ -6,7 +6,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y); | = note: defining type: test::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) mut &ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) i32, &ReBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrAnon }) i32)), + for<Region(BrAnon), Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&'^0 mut &'^1 i32, &'^2 i32)), (), ] diff --git a/tests/ui/nll/closure-requirements/escape-argument.stderr b/tests/ui/nll/closure-requirements/escape-argument.stderr index b050c0566c6..7fd1cd8c3e4 100644 --- a/tests/ui/nll/closure-requirements/escape-argument.stderr +++ b/tests/ui/nll/closure-requirements/escape-argument.stderr @@ -6,7 +6,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y); | = note: defining type: test::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) mut &ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) i32, &ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) i32)), + for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&'^0 mut &'^1 i32, &'^1 i32)), (), ] diff --git a/tests/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr b/tests/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr index bffd365b9cc..f37ce967a1b 100644 --- a/tests/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr +++ b/tests/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr @@ -6,7 +6,7 @@ LL | |_outlives1, _outlives2, _outlives3, x, y| { | = note: defining type: supply::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((std::cell::Cell<&'?1 &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) u32>, std::cell::Cell<&'?2 &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) u32>, std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) &'?3 u32>, std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) u32>, std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) u32>)), + for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((std::cell::Cell<&'?1 &'^0 u32>, std::cell::Cell<&'?2 &'^0 u32>, std::cell::Cell<&'^1 &'?3 u32>, std::cell::Cell<&'^0 u32>, std::cell::Cell<&'^1 u32>)), (), ] = note: late-bound region is '?4 diff --git a/tests/ui/nll/closure-requirements/propagate-approximated-ref.stderr b/tests/ui/nll/closure-requirements/propagate-approximated-ref.stderr index 843d307b80b..e2d0b105ab1 100644 --- a/tests/ui/nll/closure-requirements/propagate-approximated-ref.stderr +++ b/tests/ui/nll/closure-requirements/propagate-approximated-ref.stderr @@ -6,7 +6,7 @@ LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y | = note: defining type: supply::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) std::cell::Cell<&'?1 &ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrAnon }) &'?2 u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 5, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrAnon }) u32>)), + for<Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&'^0 std::cell::Cell<&'?1 &'^1 u32>, &'^2 std::cell::Cell<&'^3 &'?2 u32>, &'^4 std::cell::Cell<&'^1 u32>, &'^5 std::cell::Cell<&'^3 u32>)), (), ] = note: late-bound region is '?3 diff --git a/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr b/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr index 5ce3dae5a33..d7933a39eaa 100644 --- a/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr +++ b/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr @@ -6,7 +6,7 @@ LL | foo(cell, |cell_a, cell_x| { | = note: defining type: case1::{closure#0} with closure args [ i32, - for<Region(BrAnon)> extern "rust-call" fn((std::cell::Cell<&'?1 u32>, std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) u32>)), + for<Region(BrAnon)> extern "rust-call" fn((std::cell::Cell<&'?1 u32>, std::cell::Cell<&'^0 u32>)), (), ] @@ -36,7 +36,7 @@ LL | foo(cell, |cell_a, cell_x| { | = note: defining type: case2::{closure#0} with closure args [ i32, - for<Region(BrAnon)> extern "rust-call" fn((std::cell::Cell<&'?1 u32>, std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) u32>)), + for<Region(BrAnon)> extern "rust-call" fn((std::cell::Cell<&'?1 u32>, std::cell::Cell<&'^0 u32>)), (), ] = note: number of external vids: 2 @@ -53,17 +53,16 @@ LL | fn case2() { error[E0597]: `a` does not live long enough --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:30:26 | -LL | let a = 0; - | - binding `a` declared here -LL | let cell = Cell::new(&a); - | ^^ borrowed value does not live long enough +LL | let a = 0; + | - binding `a` declared here +LL | let cell = Cell::new(&a); + | ----------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `a` is borrowed for `'static` ... -LL | / foo(cell, |cell_a, cell_x| { -LL | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error -LL | | }) - | |______- argument requires that `a` is borrowed for `'static` -LL | } - | - `a` dropped here while still borrowed +LL | } + | - `a` dropped here while still borrowed error: aborting due to 2 previous errors diff --git a/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr b/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr index 54784df5275..ca7d187ac57 100644 --- a/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr +++ b/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr @@ -6,7 +6,7 @@ LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { | = note: defining type: supply::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) std::cell::Cell<&'?1 &ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrAnon }) u32>)), + for<Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&'^0 std::cell::Cell<&'?1 &'^1 u32>, &'^2 std::cell::Cell<&'^1 u32>, &'^3 std::cell::Cell<&'^4 u32>)), (), ] = note: late-bound region is '?2 diff --git a/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr b/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr index 53547afbfea..d11a64272a9 100644 --- a/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr +++ b/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr @@ -6,7 +6,7 @@ LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y | = note: defining type: supply::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) std::cell::Cell<&'?1 &ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrAnon }) std::cell::Cell<&'?2 &ReBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrAnon }) u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 5, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrAnon }) u32>)), + for<Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&'^0 std::cell::Cell<&'?1 &'^1 u32>, &'^2 std::cell::Cell<&'?2 &'^3 u32>, &'^4 std::cell::Cell<&'^1 u32>, &'^5 std::cell::Cell<&'^3 u32>)), (), ] = note: late-bound region is '?3 diff --git a/tests/ui/nll/closure-requirements/propagate-approximated-val.stderr b/tests/ui/nll/closure-requirements/propagate-approximated-val.stderr index 5566c76d854..4787577a6e1 100644 --- a/tests/ui/nll/closure-requirements/propagate-approximated-val.stderr +++ b/tests/ui/nll/closure-requirements/propagate-approximated-val.stderr @@ -6,7 +6,7 @@ LL | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| { | = note: defining type: test::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((std::cell::Cell<&'?1 &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) u32>, std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) &'?2 u32>, std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) u32>, std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) u32>)), + for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((std::cell::Cell<&'?1 &'^0 u32>, std::cell::Cell<&'^1 &'?2 u32>, std::cell::Cell<&'^0 u32>, std::cell::Cell<&'^1 u32>)), (), ] = note: late-bound region is '?3 diff --git a/tests/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr b/tests/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr index 0dd53f81ae1..49c65d77ddd 100644 --- a/tests/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr +++ b/tests/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr @@ -6,7 +6,7 @@ LL | |_outlives1, _outlives2, x, y| { | = note: defining type: supply::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((std::cell::Cell<&'?1 &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) u32>, std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) &'?2 u32>, std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) u32>, std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) u32>)), + for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((std::cell::Cell<&'?1 &'^0 u32>, std::cell::Cell<&'^1 &'?2 u32>, std::cell::Cell<&'^0 u32>, std::cell::Cell<&'^1 u32>)), (), ] = note: late-bound region is '?3 diff --git a/tests/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr b/tests/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr index 64deaa00fa3..669b56a0be7 100644 --- a/tests/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr +++ b/tests/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr @@ -6,7 +6,7 @@ LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { | = note: defining type: supply::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) &'?1 u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrAnon }) u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) u32>)), + for<Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&'^0 std::cell::Cell<&'^1 &'?1 u32>, &'^2 std::cell::Cell<&'^3 u32>, &'^4 std::cell::Cell<&'^1 u32>)), (), ] = note: late-bound region is '?2 diff --git a/tests/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr b/tests/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr index ee49b4dac22..75f476ac5f1 100644 --- a/tests/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr +++ b/tests/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr @@ -6,7 +6,7 @@ LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y | = note: defining type: supply::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) &'?1 u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrAnon }) &'?2 u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) u32>, &ReBound(DebruijnIndex(0), BoundRegion { var: 5, kind: BrAnon }) std::cell::Cell<&ReBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrAnon }) u32>)), + for<Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&'^0 std::cell::Cell<&'^1 &'?1 u32>, &'^2 std::cell::Cell<&'^3 &'?2 u32>, &'^4 std::cell::Cell<&'^1 u32>, &'^5 std::cell::Cell<&'^3 u32>)), (), ] = note: late-bound region is '?3 diff --git a/tests/ui/nll/closure-requirements/return-wrong-bound-region.stderr b/tests/ui/nll/closure-requirements/return-wrong-bound-region.stderr index a13caf8c298..bc5c04a27a3 100644 --- a/tests/ui/nll/closure-requirements/return-wrong-bound-region.stderr +++ b/tests/ui/nll/closure-requirements/return-wrong-bound-region.stderr @@ -6,7 +6,7 @@ LL | expect_sig(|a, b| b); // ought to return `a` | = note: defining type: test::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) i32, &ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) i32)) -> &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) i32, + for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((&'^0 i32, &'^1 i32)) -> &'^0 i32, (), ] diff --git a/tests/ui/nll/issue-54189.rs b/tests/ui/nll/issue-54189.rs index 70aecc384ef..2339a722a7b 100644 --- a/tests/ui/nll/issue-54189.rs +++ b/tests/ui/nll/issue-54189.rs @@ -1,5 +1,6 @@ fn bug() -> impl for <'r> Fn() -> &'r () { || { &() } } //~^ ERROR binding for associated type `Output` references lifetime `'r` +//~| ERROR binding for associated type `Output` references lifetime `'r` fn main() { let f = bug(); diff --git a/tests/ui/nll/issue-54189.stderr b/tests/ui/nll/issue-54189.stderr index 14ed2bb222d..ce756a91f56 100644 --- a/tests/ui/nll/issue-54189.stderr +++ b/tests/ui/nll/issue-54189.stderr @@ -4,6 +4,14 @@ error[E0582]: binding for associated type `Output` references lifetime `'r`, whi LL | fn bug() -> impl for <'r> Fn() -> &'r () { || { &() } } | ^^^^^^ -error: aborting due to 1 previous error +error[E0582]: binding for associated type `Output` references lifetime `'r`, which does not appear in the trait input types + --> $DIR/issue-54189.rs:1:35 + | +LL | fn bug() -> impl for <'r> Fn() -> &'r () { || { &() } } + | ^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0582`. diff --git a/tests/ui/nll/ty-outlives/impl-trait-captures.stderr b/tests/ui/nll/ty-outlives/impl-trait-captures.stderr index 693c5b8b0a3..3893cdf482e 100644 --- a/tests/ui/nll/ty-outlives/impl-trait-captures.stderr +++ b/tests/ui/nll/ty-outlives/impl-trait-captures.stderr @@ -1,4 +1,4 @@ -error[E0700]: hidden type for `Opaque(DefId(0:13 ~ impl_trait_captures[aeb9]::foo::{opaque#0}), [ReEarlyParam(DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a), 0, 'a), T, ReEarlyParam(DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a), 0, 'a)])` captures lifetime that does not appear in bounds +error[E0700]: hidden type for `Opaque(DefId(0:13 ~ impl_trait_captures[aeb9]::foo::{opaque#0}), [DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a)_'a/#0, T, DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a)_'a/#0])` captures lifetime that does not appear in bounds --> $DIR/impl-trait-captures.rs:11:5 | LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> { @@ -8,7 +8,7 @@ LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> { LL | x | ^ | -help: to declare that `Opaque(DefId(0:13 ~ impl_trait_captures[aeb9]::foo::{opaque#0}), [ReEarlyParam(DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a), 0, 'a), T, ReEarlyParam(DefId(0:14 ~ impl_trait_captures[aeb9]::foo::{opaque#0}::'a), 2, 'a)])` captures `ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_))`, you can add an explicit `ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_))` lifetime bound +help: to declare that `Opaque(DefId(0:13 ~ impl_trait_captures[aeb9]::foo::{opaque#0}), [DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a)_'a/#0, T, DefId(0:14 ~ impl_trait_captures[aeb9]::foo::{opaque#0}::'a)_'a/#2])` captures `ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_))`, you can add an explicit `ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_))` lifetime bound | LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_)) { | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/tests/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr b/tests/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr index acbcb9f0b70..e58764354c0 100644 --- a/tests/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr +++ b/tests/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr @@ -6,7 +6,7 @@ LL | twice(cell, value, |a, b| invoke(a, b)); | = note: defining type: generic::<T>::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((std::option::Option<std::cell::Cell<&'?1 &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) ()>>, &ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) T)), + for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((std::option::Option<std::cell::Cell<&'?1 &'^0 ()>>, &'^1 T)), (), ] = note: number of external vids: 2 @@ -28,7 +28,7 @@ LL | twice(cell, value, |a, b| invoke(a, b)); | = note: defining type: generic_fail::<T>::{closure#0} with closure args [ i16, - for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((std::option::Option<std::cell::Cell<&'?1 &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon }) ()>>, &ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon }) T)), + for<Region(BrAnon), Region(BrAnon)> extern "rust-call" fn((std::option::Option<std::cell::Cell<&'?1 &'^0 ()>>, &'^1 T)), (), ] = note: late-bound region is '?2 diff --git a/tests/ui/nll/user-annotations/adt-nullary-enums.stderr b/tests/ui/nll/user-annotations/adt-nullary-enums.stderr index 5b385feeedc..644fc94f730 100644 --- a/tests/ui/nll/user-annotations/adt-nullary-enums.stderr +++ b/tests/ui/nll/user-annotations/adt-nullary-enums.stderr @@ -1,16 +1,17 @@ error[E0597]: `c` does not live long enough --> $DIR/adt-nullary-enums.rs:33:41 | -LL | let c = 66; - | - binding `c` declared here -LL | / combine( -LL | | SomeEnum::SomeVariant(Cell::new(&c)), - | | ^^ borrowed value does not live long enough -LL | | SomeEnum::SomeOtherVariant::<Cell<&'static u32>>, -LL | | ); - | |_____- argument requires that `c` is borrowed for `'static` -LL | } - | - `c` dropped here while still borrowed +LL | let c = 66; + | - binding `c` declared here +LL | combine( +LL | SomeEnum::SomeVariant(Cell::new(&c)), + | ----------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'static` +... +LL | } + | - `c` dropped here while still borrowed error[E0597]: `c` does not live long enough --> $DIR/adt-nullary-enums.rs:41:41 diff --git a/tests/ui/nll/user-annotations/dump-adt-brace-struct.rs b/tests/ui/nll/user-annotations/dump-adt-brace-struct.rs index 9a6587a9a74..45f2b029d14 100644 --- a/tests/ui/nll/user-annotations/dump-adt-brace-struct.rs +++ b/tests/ui/nll/user-annotations/dump-adt-brace-struct.rs @@ -6,7 +6,9 @@ #![allow(warnings)] #![feature(rustc_attrs)] -struct SomeStruct<T> { t: T } +struct SomeStruct<T> { + t: T, +} #[rustc_dump_user_args] fn main() { @@ -16,5 +18,5 @@ fn main() { SomeStruct::<u32> { t: 22 }; // No lifetime bounds given. - SomeStruct::<&'static u32> { t: &22 }; //~ ERROR [&ReStatic u32] + SomeStruct::<&'static u32> { t: &22 }; //~ ERROR [&'static u32] } diff --git a/tests/ui/nll/user-annotations/dump-adt-brace-struct.stderr b/tests/ui/nll/user-annotations/dump-adt-brace-struct.stderr index 0cabc02c6b5..edf82593cee 100644 --- a/tests/ui/nll/user-annotations/dump-adt-brace-struct.stderr +++ b/tests/ui/nll/user-annotations/dump-adt-brace-struct.stderr @@ -1,5 +1,5 @@ -error: user args: UserArgs { args: [&ReStatic u32], user_self_ty: None } - --> $DIR/dump-adt-brace-struct.rs:19:5 +error: user args: UserArgs { args: [&'static u32], user_self_ty: None } + --> $DIR/dump-adt-brace-struct.rs:21:5 | LL | SomeStruct::<&'static u32> { t: &22 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/nll/user-annotations/dump-fn-method.rs b/tests/ui/nll/user-annotations/dump-fn-method.rs index 40e705ac538..26714b6ffe3 100644 --- a/tests/ui/nll/user-annotations/dump-fn-method.rs +++ b/tests/ui/nll/user-annotations/dump-fn-method.rs @@ -7,13 +7,12 @@ // Note: we reference the names T and U in the comments below. trait Bazoom<T> { - fn method<U>(&self, arg: T, arg2: U) { } + fn method<U>(&self, arg: T, arg2: U) {} } -impl<S, T> Bazoom<T> for S { -} +impl<S, T> Bazoom<T> for S {} -fn foo<'a, T>(_: T) { } +fn foo<'a, T>(_: T) {} #[rustc_dump_user_args] fn main() { @@ -26,7 +25,7 @@ fn main() { let x = foo::<u32>; x(22); - let x = foo::<&'static u32>; //~ ERROR [&ReStatic u32] + let x = foo::<&'static u32>; //~ ERROR [&'static u32] x(&22); // Here: we only want the `T` to be given, the rest should be variables. @@ -41,7 +40,7 @@ fn main() { x(&22, 44, 66); // Here: all are given and we have a lifetime. - let x = <u8 as Bazoom<&'static u16>>::method::<u32>; //~ ERROR [u8, &ReStatic u16, u32] + let x = <u8 as Bazoom<&'static u16>>::method::<u32>; //~ ERROR [u8, &'static u16, u32] x(&22, &44, 66); // Here: we want in particular that *only* the method `U` diff --git a/tests/ui/nll/user-annotations/dump-fn-method.stderr b/tests/ui/nll/user-annotations/dump-fn-method.stderr index 1daf4982511..8e847b464e1 100644 --- a/tests/ui/nll/user-annotations/dump-fn-method.stderr +++ b/tests/ui/nll/user-annotations/dump-fn-method.stderr @@ -1,23 +1,23 @@ -error: user args: UserArgs { args: [&ReStatic u32], user_self_ty: None } - --> $DIR/dump-fn-method.rs:29:13 +error: user args: UserArgs { args: [&'static u32], user_self_ty: None } + --> $DIR/dump-fn-method.rs:28:13 | LL | let x = foo::<&'static u32>; | ^^^^^^^^^^^^^^^^^^^ error: user args: UserArgs { args: [^0, u32, ^1], user_self_ty: None } - --> $DIR/dump-fn-method.rs:35:13 + --> $DIR/dump-fn-method.rs:34:13 | LL | let x = <_ as Bazoom<u32>>::method::<_>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: user args: UserArgs { args: [u8, &ReStatic u16, u32], user_self_ty: None } - --> $DIR/dump-fn-method.rs:44:13 +error: user args: UserArgs { args: [u8, &'static u16, u32], user_self_ty: None } + --> $DIR/dump-fn-method.rs:43:13 | LL | let x = <u8 as Bazoom<&'static u16>>::method::<u32>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: user args: UserArgs { args: [^0, ^1, u32], user_self_ty: None } - --> $DIR/dump-fn-method.rs:52:5 + --> $DIR/dump-fn-method.rs:51:5 | LL | y.method::<u32>(44, 66); | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/nll/user-annotations/region-error-ice-109072.rs b/tests/ui/nll/user-annotations/region-error-ice-109072.rs index 3f2ad3ccbf5..bcdc6651cf5 100644 --- a/tests/ui/nll/user-annotations/region-error-ice-109072.rs +++ b/tests/ui/nll/user-annotations/region-error-ice-109072.rs @@ -11,4 +11,5 @@ impl Lt<'missing> for () { //~ ERROR undeclared lifetime fn main() { let _: <() as Lt<'_>>::T = &(); + //~^ ERROR the trait bound `(): Lt<'_>` is not satisfied } diff --git a/tests/ui/nll/user-annotations/region-error-ice-109072.stderr b/tests/ui/nll/user-annotations/region-error-ice-109072.stderr index d90971bed25..c187c17d98c 100644 --- a/tests/ui/nll/user-annotations/region-error-ice-109072.stderr +++ b/tests/ui/nll/user-annotations/region-error-ice-109072.stderr @@ -21,6 +21,13 @@ help: consider introducing lifetime `'missing` here LL | impl<'missing> Lt<'missing> for () { | ++++++++++ -error: aborting due to 2 previous errors +error[E0277]: the trait bound `(): Lt<'_>` is not satisfied + --> $DIR/region-error-ice-109072.rs:13:13 + | +LL | let _: <() as Lt<'_>>::T = &(); + | ^^ the trait `Lt<'_>` is not implemented for `()` + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0261`. +Some errors have detailed explanations: E0261, E0277. +For more information about an error, try `rustc --explain E0261`. diff --git a/tests/ui/object-lifetime/object-lifetime-default-dyn-binding-nonstatic3.rs b/tests/ui/object-lifetime/object-lifetime-default-dyn-binding-nonstatic3.rs index 345c8a25f79..51be999a632 100644 --- a/tests/ui/object-lifetime/object-lifetime-default-dyn-binding-nonstatic3.rs +++ b/tests/ui/object-lifetime/object-lifetime-default-dyn-binding-nonstatic3.rs @@ -15,7 +15,6 @@ fn is_static<T>(_: T) where T: 'static { } // code forces us into a conservative, hacky path. fn bar(x: &str) -> &dyn Foo<Item = dyn Bar> { &() } //~^ ERROR please supply an explicit bound -//~| ERROR `(): Foo<'_>` is not satisfied fn main() { let s = format!("foo"); diff --git a/tests/ui/object-lifetime/object-lifetime-default-dyn-binding-nonstatic3.stderr b/tests/ui/object-lifetime/object-lifetime-default-dyn-binding-nonstatic3.stderr index d227c8778fe..688f8af0822 100644 --- a/tests/ui/object-lifetime/object-lifetime-default-dyn-binding-nonstatic3.stderr +++ b/tests/ui/object-lifetime/object-lifetime-default-dyn-binding-nonstatic3.stderr @@ -4,20 +4,6 @@ error[E0228]: the lifetime bound for this object type cannot be deduced from con LL | fn bar(x: &str) -> &dyn Foo<Item = dyn Bar> { &() } | ^^^^^^^ -error[E0277]: the trait bound `(): Foo<'_>` is not satisfied - --> $DIR/object-lifetime-default-dyn-binding-nonstatic3.rs:16:47 - | -LL | fn bar(x: &str) -> &dyn Foo<Item = dyn Bar> { &() } - | ^^^ the trait `Foo<'_>` is not implemented for `()` - | -help: this trait has no implementations, consider adding one - --> $DIR/object-lifetime-default-dyn-binding-nonstatic3.rs:4:1 - | -LL | trait Foo<'a> { - | ^^^^^^^^^^^^^ - = note: required for the cast from `&()` to `&dyn Foo<'_, Item = dyn Bar>` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0228, E0277. -For more information about an error, try `rustc --explain E0228`. +For more information about this error, try `rustc --explain E0228`. diff --git a/tests/ui/offset-of/offset-of-tuple.stderr b/tests/ui/offset-of/offset-of-tuple.stderr index e9aa495becd..1e2d9240267 100644 --- a/tests/ui/offset-of/offset-of-tuple.stderr +++ b/tests/ui/offset-of/offset-of-tuple.stderr @@ -202,7 +202,6 @@ LL | offset_of!(((u8, u16), (u32, u16, u8)), 0.2); | | in this macro invocation LL | | offset_of!(((u8, u16), (u32, u16, u8)), 1.2); LL | | offset_of!(((u8, u16), (u32, u16, u8)), 1.2.0); -LL | | ... | | = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/parser/attribute/attr-bad-meta-4.rs b/tests/ui/parser/attribute/attr-bad-meta-4.rs new file mode 100644 index 00000000000..cedbd1d6686 --- /dev/null +++ b/tests/ui/parser/attribute/attr-bad-meta-4.rs @@ -0,0 +1,12 @@ +macro_rules! mac { + ($attr_item: meta) => { + #[cfg($attr_item)] + //~^ ERROR expected unsuffixed literal or identifier, found `an(arbitrary token stream)` + //~| ERROR expected unsuffixed literal or identifier, found `an(arbitrary token stream)` + struct S; + } +} + +mac!(an(arbitrary token stream)); + +fn main() {} diff --git a/tests/ui/parser/attribute/attr-bad-meta-4.stderr b/tests/ui/parser/attribute/attr-bad-meta-4.stderr new file mode 100644 index 00000000000..a543bcb692e --- /dev/null +++ b/tests/ui/parser/attribute/attr-bad-meta-4.stderr @@ -0,0 +1,25 @@ +error: expected unsuffixed literal or identifier, found `an(arbitrary token stream)` + --> $DIR/attr-bad-meta-4.rs:3:15 + | +LL | #[cfg($attr_item)] + | ^^^^^^^^^^ +... +LL | mac!(an(arbitrary token stream)); + | -------------------------------- in this macro invocation + | + = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected unsuffixed literal or identifier, found `an(arbitrary token stream)` + --> $DIR/attr-bad-meta-4.rs:3:15 + | +LL | #[cfg($attr_item)] + | ^^^^^^^^^^ +... +LL | mac!(an(arbitrary token stream)); + | -------------------------------- in this macro invocation + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 2 previous errors + diff --git a/tests/ui/parser/constraints-before-generic-args-syntactic-pass.rs b/tests/ui/parser/constraints-before-generic-args-syntactic-pass.rs index 6566d8a1115..ed3ffed2f80 100644 --- a/tests/ui/parser/constraints-before-generic-args-syntactic-pass.rs +++ b/tests/ui/parser/constraints-before-generic-args-syntactic-pass.rs @@ -3,11 +3,7 @@ #[cfg(FALSE)] fn syntax() { foo::<T = u8, T: Ord, String>(); - //~^ WARN associated type bounds are unstable - //~| WARN unstable syntax foo::<T = u8, 'a, T: Ord>(); - //~^ WARN associated type bounds are unstable - //~| WARN unstable syntax } fn main() {} diff --git a/tests/ui/parser/constraints-before-generic-args-syntactic-pass.stderr b/tests/ui/parser/constraints-before-generic-args-syntactic-pass.stderr deleted file mode 100644 index 393ed704b41..00000000000 --- a/tests/ui/parser/constraints-before-generic-args-syntactic-pass.stderr +++ /dev/null @@ -1,26 +0,0 @@ -warning: associated type bounds are unstable - --> $DIR/constraints-before-generic-args-syntactic-pass.rs:5:19 - | -LL | foo::<T = u8, T: Ord, String>(); - | ^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = warning: unstable syntax can change at any point in the future, causing a hard error! - = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> - -warning: associated type bounds are unstable - --> $DIR/constraints-before-generic-args-syntactic-pass.rs:8:23 - | -LL | foo::<T = u8, 'a, T: Ord>(); - | ^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = warning: unstable syntax can change at any point in the future, causing a hard error! - = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860> - -warning: 2 warnings emitted - diff --git a/tests/ui/parser/f16-f128.rs b/tests/ui/parser/f16-f128.rs deleted file mode 100644 index 4f31dccce3c..00000000000 --- a/tests/ui/parser/f16-f128.rs +++ /dev/null @@ -1,37 +0,0 @@ -// Make sure we don't ICE while incrementally adding f16 and f128 support - -mod f16_checks { - const A: f16 = 10.0; //~ ERROR cannot find type `f16` in this scope - - pub fn main() { - let a: f16 = 100.0; //~ ERROR cannot find type `f16` in this scope - let b = 0.0f16; //~ ERROR invalid width `16` for float literal - - foo(1.23); - } - - fn foo(a: f16) {} //~ ERROR cannot find type `f16` in this scope - - struct Bar { - a: f16, //~ ERROR cannot find type `f16` in this scope - } -} - -mod f128_checks { - const A: f128 = 10.0; //~ ERROR cannot find type `f128` in this scope - - pub fn main() { - let a: f128 = 100.0; //~ ERROR cannot find type `f128` in this scope - let b = 0.0f128; //~ ERROR invalid width `128` for float literal - - foo(1.23); - } - - fn foo(a: f128) {} //~ ERROR cannot find type `f128` in this scope - - struct Bar { - a: f128, //~ ERROR cannot find type `f128` in this scope - } -} - -fn main() {} diff --git a/tests/ui/parser/f16-f128.stderr b/tests/ui/parser/f16-f128.stderr deleted file mode 100644 index d3f2227acd7..00000000000 --- a/tests/ui/parser/f16-f128.stderr +++ /dev/null @@ -1,67 +0,0 @@ -error[E0412]: cannot find type `f16` in this scope - --> $DIR/f16-f128.rs:4:14 - | -LL | const A: f16 = 10.0; - | ^^^ help: a builtin type with a similar name exists: `i16` - -error[E0412]: cannot find type `f16` in this scope - --> $DIR/f16-f128.rs:7:16 - | -LL | let a: f16 = 100.0; - | ^^^ help: a builtin type with a similar name exists: `i16` - -error[E0412]: cannot find type `f16` in this scope - --> $DIR/f16-f128.rs:13:15 - | -LL | fn foo(a: f16) {} - | ^^^ help: a builtin type with a similar name exists: `i16` - -error[E0412]: cannot find type `f16` in this scope - --> $DIR/f16-f128.rs:16:12 - | -LL | a: f16, - | ^^^ help: a builtin type with a similar name exists: `i16` - -error[E0412]: cannot find type `f128` in this scope - --> $DIR/f16-f128.rs:21:14 - | -LL | const A: f128 = 10.0; - | ^^^^ help: a builtin type with a similar name exists: `i128` - -error[E0412]: cannot find type `f128` in this scope - --> $DIR/f16-f128.rs:24:16 - | -LL | let a: f128 = 100.0; - | ^^^^ help: a builtin type with a similar name exists: `i128` - -error[E0412]: cannot find type `f128` in this scope - --> $DIR/f16-f128.rs:30:15 - | -LL | fn foo(a: f128) {} - | ^^^^ help: a builtin type with a similar name exists: `i128` - -error[E0412]: cannot find type `f128` in this scope - --> $DIR/f16-f128.rs:33:12 - | -LL | a: f128, - | ^^^^ help: a builtin type with a similar name exists: `i128` - -error: invalid width `16` for float literal - --> $DIR/f16-f128.rs:8:17 - | -LL | let b = 0.0f16; - | ^^^^^^ - | - = help: valid widths are 32 and 64 - -error: invalid width `128` for float literal - --> $DIR/f16-f128.rs:25:17 - | -LL | let b = 0.0f128; - | ^^^^^^^ - | - = help: valid widths are 32 and 64 - -error: aborting due to 10 previous errors - -For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/parser/impl-item-type-no-body-semantic-fail.stderr b/tests/ui/parser/impl-item-type-no-body-semantic-fail.stderr index 29b0b25a564..9800420072b 100644 --- a/tests/ui/parser/impl-item-type-no-body-semantic-fail.stderr +++ b/tests/ui/parser/impl-item-type-no-body-semantic-fail.stderr @@ -89,12 +89,15 @@ LL | type W: Ord where Self: Eq; | ^^^^^^^^ the trait `Eq` is not implemented for `X` | = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable help: consider annotating `X` with `#[derive(Eq)]` | LL + #[derive(Eq)] LL | struct X; | +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the trait bound `X: Eq` is not satisfied --> $DIR/impl-item-type-no-body-semantic-fail.rs:18:18 @@ -103,12 +106,15 @@ LL | type W where Self: Eq; | ^^^^^^^^ the trait `Eq` is not implemented for `X` | = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable help: consider annotating `X` with `#[derive(Eq)]` | LL + #[derive(Eq)] LL | struct X; | +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0592]: duplicate definitions with name `W` --> $DIR/impl-item-type-no-body-semantic-fail.rs:18:5 diff --git a/tests/ui/parser/issues/issue-35813-postfix-after-cast.stderr b/tests/ui/parser/issues/issue-35813-postfix-after-cast.stderr index 6a8cbd9389b..7b896ce1426 100644 --- a/tests/ui/parser/issues/issue-35813-postfix-after-cast.stderr +++ b/tests/ui/parser/issues/issue-35813-postfix-after-cast.stderr @@ -352,8 +352,11 @@ LL | static bar: &[i32] = &(&[1,2,3] as &[i32][0..1]); | ^^^^^^ | = note: calls in statics are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 40 previous errors diff --git a/tests/ui/parser/survive-peano-lesson-queue.rs b/tests/ui/parser/survive-peano-lesson-queue.rs new file mode 100644 index 00000000000..3608728594e --- /dev/null +++ b/tests/ui/parser/survive-peano-lesson-queue.rs @@ -0,0 +1,4907 @@ +//@ build-pass +// ignore-tidy-filelength +// ignore-tidy-linelength +// some very lightly modified generated code from issue rust-lang/rust#122715 +// the main differences are to strip the dependency on bumpalo so it can be tested separately +// the original purpose of this code was to implement a binomial queue, however it is extracted from Gallina +// which means that it uses an incredibly naive Peano representation of the natural numbers. +// this is fairly standard "someone did something very silly and we should try to gracefully handle it" + +#![allow(dead_code)] +#![allow(non_camel_case_types)] +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(unused_variables)] + +use std::marker::PhantomData; + +fn __nat_succ(x: u64) -> u64 { + x.checked_add(1).unwrap() +} + +macro_rules! __nat_elim { + ($zcase:expr, $pred:ident, $scase:expr, $val:expr) => { + { let v = $val; + if v == 0 { $zcase } else { let $pred = v - 1; $scase } } + } +} + +macro_rules! __andb { ($b1:expr, $b2:expr) => { $b1 && $b2 } } +macro_rules! __orb { ($b1:expr, $b2:expr) => { $b1 || $b2 } } + +fn __pos_onebit(x: u64) -> u64 { + x.checked_mul(2).unwrap() + 1 +} + +fn __pos_zerobit(x: u64) -> u64 { + x.checked_mul(2).unwrap() +} + +macro_rules! __pos_elim { + ($p:ident, $onebcase:expr, $p2:ident, $zerobcase:expr, $onecase:expr, $val:expr) => { + { + let n = $val; + if n == 1 { + $onecase + } else if (n & 1) == 0 { + let $p2 = n >> 1; + $zerobcase + } else { + let $p = n >> 1; + $onebcase + } + } + } +} + +fn __Z_frompos(z: u64) -> i64 { + use std::convert::TryFrom; + + i64::try_from(z).unwrap() +} + +fn __Z_fromneg(z : u64) -> i64 { + use std::convert::TryFrom; + + i64::try_from(z).unwrap().checked_neg().unwrap() +} + +macro_rules! __Z_elim { + ($zero_case:expr, $p:ident, $pos_case:expr, $p2:ident, $neg_case:expr, $val:expr) => { + { + let n = $val; + if n == 0 { + $zero_case + } else if n < 0 { + let $p2 = n.unsigned_abs(); + $neg_case + } else { + let $p = n as u64; + $pos_case + } + } + } +} + +fn __N_frompos(z: u64) -> u64 { + z +} + +macro_rules! __N_elim { + ($zero_case:expr, $p:ident, $pos_case:expr, $val:expr) => { + { let $p = $val; if $p == 0 { $zero_case } else { $pos_case } } + } +} + +type __pair<A, B> = (A, B); + +macro_rules! __pair_elim { + ($fst:ident, $snd:ident, $body:expr, $p:expr) => { + { let ($fst, $snd) = $p; $body } + } +} + +fn __mk_pair<A: Copy, B: Copy>(a: A, b: B) -> __pair<A, B> { (a, b) } + +fn hint_app<TArg, TRet>(f: &dyn Fn(TArg) -> TRet) -> &dyn Fn(TArg) -> TRet { + f +} + +#[derive(Debug, Clone)] +pub enum Coq_Init_Datatypes_list<'a, A> { + nil(PhantomData<&'a A>), + cons(PhantomData<&'a A>, A, &'a Coq_Init_Datatypes_list<'a, A>) +} + +type CertiCoq_Benchmarks_lib_Binom_key<'a> = u64; + +#[derive(Debug, Clone)] +pub enum CertiCoq_Benchmarks_lib_Binom_tree<'a> { + Node(PhantomData<&'a ()>, CertiCoq_Benchmarks_lib_Binom_key<'a>, &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>, &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>), + Leaf(PhantomData<&'a ()>) +} + +type CertiCoq_Benchmarks_lib_Binom_priqueue<'a> = &'a Coq_Init_Datatypes_list<'a, &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>>; + +struct Program { +} + +impl<'a> Program { +fn new() -> Self { + Program { + } +} + +fn alloc<T>(&'a self, t: T) -> &'a T { + let _alloc = Box::new(t); + Box::leak(_alloc) +} + +fn closure<TArg, TRet>(&'a self, f: impl Fn(TArg) -> TRet + 'a) -> &'a dyn Fn(TArg) -> TRet { + let _alloc = Box::new(f); + Box::leak(_alloc) +} + +fn Coq_Init_Nat_leb(&'a self, n: u64, m: u64) -> bool { + __nat_elim!( + { + true + }, + n2, { + __nat_elim!( + { + false + }, + m2, { + self.Coq_Init_Nat_leb( + n2, + m2) + }, + m) + }, + n) +} +fn Coq_Init_Nat_leb__curried(&'a self) -> &'a dyn Fn(u64) -> &'a dyn Fn(u64) -> bool { + self.closure(move |n| { + self.closure(move |m| { + self.Coq_Init_Nat_leb( + n, + m) + }) + }) +} + +fn Coq_Init_Nat_ltb(&'a self, n: u64, m: u64) -> bool { + self.Coq_Init_Nat_leb( + __nat_succ( + n), + m) +} +fn Coq_Init_Nat_ltb__curried(&'a self) -> &'a dyn Fn(u64) -> &'a dyn Fn(u64) -> bool { + self.closure(move |n| { + self.closure(move |m| { + self.Coq_Init_Nat_ltb( + n, + m) + }) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_smash(&'a self, t: &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>, u: &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>) -> &'a CertiCoq_Benchmarks_lib_Binom_tree<'a> { + match t { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, x, t1, t0) => { + match t0 { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, k, t2, t3) => { + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)) + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + match u { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, y, u1, t2) => { + match t2 { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, k, t3, t4) => { + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)) + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + match self.Coq_Init_Nat_ltb( + y, + x) { + true => { + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Node( + PhantomData, + x, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Node( + PhantomData, + y, + u1, + t1)), + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)))) + }, + false => { + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Node( + PhantomData, + y, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Node( + PhantomData, + x, + t1, + u1)), + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)))) + }, + } + }, + } + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)) + }, + } + }, + } + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)) + }, + } +} +fn CertiCoq_Benchmarks_lib_Binom_smash__curried(&'a self) -> &'a dyn Fn(&'a CertiCoq_Benchmarks_lib_Binom_tree<'a>) -> &'a dyn Fn(&'a CertiCoq_Benchmarks_lib_Binom_tree<'a>) -> &'a CertiCoq_Benchmarks_lib_Binom_tree<'a> { + self.closure(move |t| { + self.closure(move |u| { + self.CertiCoq_Benchmarks_lib_Binom_smash( + t, + u) + }) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_carry(&'a self, q: &'a Coq_Init_Datatypes_list<'a, &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>>, t: &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>) -> &'a Coq_Init_Datatypes_list<'a, &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>> { + match q { + &Coq_Init_Datatypes_list::nil(_) => { + match t { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, k, t0, t1) => { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + t, + self.alloc( + Coq_Init_Datatypes_list::nil( + PhantomData)))) + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + self.alloc( + Coq_Init_Datatypes_list::nil( + PhantomData)) + }, + } + }, + &Coq_Init_Datatypes_list::cons(_, u, q2) => { + match u { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, k, t0, t1) => { + match t { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, k0, t2, t3) => { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)), + self.CertiCoq_Benchmarks_lib_Binom_carry( + q2, + self.CertiCoq_Benchmarks_lib_Binom_smash( + t, + u)))) + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + u, + q2)) + }, + } + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + t, + q2)) + }, + } + }, + } +} +fn CertiCoq_Benchmarks_lib_Binom_carry__curried(&'a self) -> &'a dyn Fn(&'a Coq_Init_Datatypes_list<'a, &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>>) -> &'a dyn Fn(&'a CertiCoq_Benchmarks_lib_Binom_tree<'a>) -> &'a Coq_Init_Datatypes_list<'a, &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>> { + self.closure(move |q| { + self.closure(move |t| { + self.CertiCoq_Benchmarks_lib_Binom_carry( + q, + t) + }) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_insert(&'a self, x: CertiCoq_Benchmarks_lib_Binom_key<'a>, q: CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + self.CertiCoq_Benchmarks_lib_Binom_carry( + q, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Node( + PhantomData, + x, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)), + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData))))) +} +fn CertiCoq_Benchmarks_lib_Binom_insert__curried(&'a self) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_key<'a>) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + self.closure(move |x| { + self.closure(move |q| { + self.CertiCoq_Benchmarks_lib_Binom_insert( + x, + q) + }) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_insert_list(&'a self, l: &'a Coq_Init_Datatypes_list<'a, u64>, q: CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + match l { + &Coq_Init_Datatypes_list::nil(_) => { + q + }, + &Coq_Init_Datatypes_list::cons(_, x, l2) => { + self.CertiCoq_Benchmarks_lib_Binom_insert_list( + l2, + self.CertiCoq_Benchmarks_lib_Binom_insert( + x, + q)) + }, + } +} +fn CertiCoq_Benchmarks_lib_Binom_insert_list__curried(&'a self) -> &'a dyn Fn(&'a Coq_Init_Datatypes_list<'a, u64>) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + self.closure(move |l| { + self.closure(move |q| { + self.CertiCoq_Benchmarks_lib_Binom_insert_list( + l, + q) + }) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_make_list(&'a self, n: u64, l: &'a Coq_Init_Datatypes_list<'a, u64>) -> &'a Coq_Init_Datatypes_list<'a, u64> { + __nat_elim!( + { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + 0, + l)) + }, + n0, { + __nat_elim!( + { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + __nat_succ( + 0), + l)) + }, + n2, { + self.CertiCoq_Benchmarks_lib_Binom_make_list( + n2, + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + __nat_succ( + __nat_succ( + n2)), + l))) + }, + n0) + }, + n) +} +fn CertiCoq_Benchmarks_lib_Binom_make_list__curried(&'a self) -> &'a dyn Fn(u64) -> &'a dyn Fn(&'a Coq_Init_Datatypes_list<'a, u64>) -> &'a Coq_Init_Datatypes_list<'a, u64> { + self.closure(move |n| { + self.closure(move |l| { + self.CertiCoq_Benchmarks_lib_Binom_make_list( + n, + l) + }) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_empty(&'a self) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + self.alloc( + Coq_Init_Datatypes_list::nil( + PhantomData)) +} + +fn CertiCoq_Benchmarks_lib_Binom_join(&'a self, p: CertiCoq_Benchmarks_lib_Binom_priqueue<'a>, q: CertiCoq_Benchmarks_lib_Binom_priqueue<'a>, c: &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + match p { + &Coq_Init_Datatypes_list::nil(_) => { + self.CertiCoq_Benchmarks_lib_Binom_carry( + q, + c) + }, + &Coq_Init_Datatypes_list::cons(_, p1, p2) => { + match p1 { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, k, t, t0) => { + match q { + &Coq_Init_Datatypes_list::nil(_) => { + self.CertiCoq_Benchmarks_lib_Binom_carry( + p, + c) + }, + &Coq_Init_Datatypes_list::cons(_, q1, q2) => { + match q1 { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, k0, t1, t2) => { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + c, + self.CertiCoq_Benchmarks_lib_Binom_join( + p2, + q2, + self.CertiCoq_Benchmarks_lib_Binom_smash( + p1, + q1)))) + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + match c { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, k0, t1, t2) => { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)), + self.CertiCoq_Benchmarks_lib_Binom_join( + p2, + q2, + self.CertiCoq_Benchmarks_lib_Binom_smash( + c, + p1)))) + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + p1, + self.CertiCoq_Benchmarks_lib_Binom_join( + p2, + q2, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData))))) + }, + } + }, + } + }, + } + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + match q { + &Coq_Init_Datatypes_list::nil(_) => { + self.CertiCoq_Benchmarks_lib_Binom_carry( + p, + c) + }, + &Coq_Init_Datatypes_list::cons(_, q1, q2) => { + match q1 { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, k, t, t0) => { + match c { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, k0, t1, t2) => { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)), + self.CertiCoq_Benchmarks_lib_Binom_join( + p2, + q2, + self.CertiCoq_Benchmarks_lib_Binom_smash( + c, + q1)))) + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + q1, + self.CertiCoq_Benchmarks_lib_Binom_join( + p2, + q2, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData))))) + }, + } + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + c, + self.CertiCoq_Benchmarks_lib_Binom_join( + p2, + q2, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData))))) + }, + } + }, + } + }, + } + }, + } +} +fn CertiCoq_Benchmarks_lib_Binom_join__curried(&'a self) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> &'a dyn Fn(&'a CertiCoq_Benchmarks_lib_Binom_tree<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + self.closure(move |p| { + self.closure(move |q| { + self.closure(move |c| { + self.CertiCoq_Benchmarks_lib_Binom_join( + p, + q, + c) + }) + }) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_merge(&'a self, p: CertiCoq_Benchmarks_lib_Binom_priqueue<'a>, q: CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + self.CertiCoq_Benchmarks_lib_Binom_join( + p, + q, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData))) +} +fn CertiCoq_Benchmarks_lib_Binom_merge__curried(&'a self) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + self.closure(move |p| { + self.closure(move |q| { + self.CertiCoq_Benchmarks_lib_Binom_merge( + p, + q) + }) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_find_max_(&'a self, current: CertiCoq_Benchmarks_lib_Binom_key<'a>, q: CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> CertiCoq_Benchmarks_lib_Binom_key<'a> { + match q { + &Coq_Init_Datatypes_list::nil(_) => { + current + }, + &Coq_Init_Datatypes_list::cons(_, t, q2) => { + match t { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, x, t0, t1) => { + self.CertiCoq_Benchmarks_lib_Binom_find_max_( + match self.Coq_Init_Nat_ltb( + current, + x) { + true => { + x + }, + false => { + current + }, + }, + q2) + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + self.CertiCoq_Benchmarks_lib_Binom_find_max_( + current, + q2) + }, + } + }, + } +} +fn CertiCoq_Benchmarks_lib_Binom_find_max___curried(&'a self) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_key<'a>) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> CertiCoq_Benchmarks_lib_Binom_key<'a> { + self.closure(move |current| { + self.closure(move |q| { + self.CertiCoq_Benchmarks_lib_Binom_find_max_( + current, + q) + }) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_find_max(&'a self, q: CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> Option<CertiCoq_Benchmarks_lib_Binom_key<'a>> { + match q { + &Coq_Init_Datatypes_list::nil(_) => { + None + }, + &Coq_Init_Datatypes_list::cons(_, t, q2) => { + match t { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, x, t0, t1) => { + Some( + self.CertiCoq_Benchmarks_lib_Binom_find_max_( + x, + q2)) + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + self.CertiCoq_Benchmarks_lib_Binom_find_max( + q2) + }, + } + }, + } +} +fn CertiCoq_Benchmarks_lib_Binom_find_max__curried(&'a self) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> Option<CertiCoq_Benchmarks_lib_Binom_key<'a>> { + self.closure(move |q| { + self.CertiCoq_Benchmarks_lib_Binom_find_max( + q) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_unzip(&'a self, t: &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>, cont: &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + match t { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, x, t1, t2) => { + self.CertiCoq_Benchmarks_lib_Binom_unzip( + t2, + self.closure(move |q| { + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Node( + PhantomData, + x, + t1, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)))), + hint_app(cont)(q))) + })) + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + hint_app(cont)(self.alloc( + Coq_Init_Datatypes_list::nil( + PhantomData))) + }, + } +} +fn CertiCoq_Benchmarks_lib_Binom_unzip__curried(&'a self) -> &'a dyn Fn(&'a CertiCoq_Benchmarks_lib_Binom_tree<'a>) -> &'a dyn Fn(&'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + self.closure(move |t| { + self.closure(move |cont| { + self.CertiCoq_Benchmarks_lib_Binom_unzip( + t, + cont) + }) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_heap_delete_max(&'a self, t: &'a CertiCoq_Benchmarks_lib_Binom_tree<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + match t { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, x, t1, t0) => { + match t0 { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, k, t2, t3) => { + self.alloc( + Coq_Init_Datatypes_list::nil( + PhantomData)) + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + self.CertiCoq_Benchmarks_lib_Binom_unzip( + t1, + self.closure(move |u| { + u + })) + }, + } + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + self.alloc( + Coq_Init_Datatypes_list::nil( + PhantomData)) + }, + } +} +fn CertiCoq_Benchmarks_lib_Binom_heap_delete_max__curried(&'a self) -> &'a dyn Fn(&'a CertiCoq_Benchmarks_lib_Binom_tree<'a>) -> CertiCoq_Benchmarks_lib_Binom_priqueue<'a> { + self.closure(move |t| { + self.CertiCoq_Benchmarks_lib_Binom_heap_delete_max( + t) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_delete_max_aux(&'a self, m: CertiCoq_Benchmarks_lib_Binom_key<'a>, p: CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> __pair<CertiCoq_Benchmarks_lib_Binom_priqueue<'a>, CertiCoq_Benchmarks_lib_Binom_priqueue<'a>> { + match p { + &Coq_Init_Datatypes_list::nil(_) => { + __mk_pair( + self.alloc( + Coq_Init_Datatypes_list::nil( + PhantomData)), + self.alloc( + Coq_Init_Datatypes_list::nil( + PhantomData))) + }, + &Coq_Init_Datatypes_list::cons(_, t, p2) => { + match t { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, x, t1, t0) => { + match t0 { + &CertiCoq_Benchmarks_lib_Binom_tree::Node(_, k, t2, t3) => { + __mk_pair( + self.alloc( + Coq_Init_Datatypes_list::nil( + PhantomData)), + self.alloc( + Coq_Init_Datatypes_list::nil( + PhantomData))) + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + match self.Coq_Init_Nat_ltb( + x, + m) { + true => { + __pair_elim!( + k, j, { + __mk_pair( + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Node( + PhantomData, + x, + t1, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)))), + k)), + j) + }, + self.CertiCoq_Benchmarks_lib_Binom_delete_max_aux( + m, + p2)) + }, + false => { + __mk_pair( + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)), + p2)), + self.CertiCoq_Benchmarks_lib_Binom_heap_delete_max( + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Node( + PhantomData, + x, + t1, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)))))) + }, + } + }, + } + }, + &CertiCoq_Benchmarks_lib_Binom_tree::Leaf(_) => { + __pair_elim!( + k, j, { + __mk_pair( + self.alloc( + Coq_Init_Datatypes_list::cons( + PhantomData, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData)), + k)), + j) + }, + self.CertiCoq_Benchmarks_lib_Binom_delete_max_aux( + m, + p2)) + }, + } + }, + } +} +fn CertiCoq_Benchmarks_lib_Binom_delete_max_aux__curried(&'a self) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_key<'a>) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> __pair<CertiCoq_Benchmarks_lib_Binom_priqueue<'a>, CertiCoq_Benchmarks_lib_Binom_priqueue<'a>> { + self.closure(move |m| { + self.closure(move |p| { + self.CertiCoq_Benchmarks_lib_Binom_delete_max_aux( + m, + p) + }) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_delete_max(&'a self, q: CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> Option<__pair<CertiCoq_Benchmarks_lib_Binom_key<'a>, CertiCoq_Benchmarks_lib_Binom_priqueue<'a>>> { + match self.CertiCoq_Benchmarks_lib_Binom_find_max( + q) { + Some(m) => { + __pair_elim!( + q2, p, { + Some( + __mk_pair( + m, + self.CertiCoq_Benchmarks_lib_Binom_join( + q2, + p, + self.alloc( + CertiCoq_Benchmarks_lib_Binom_tree::Leaf( + PhantomData))))) + }, + self.CertiCoq_Benchmarks_lib_Binom_delete_max_aux( + m, + q)) + }, + None => { + None + }, + } +} +fn CertiCoq_Benchmarks_lib_Binom_delete_max__curried(&'a self) -> &'a dyn Fn(CertiCoq_Benchmarks_lib_Binom_priqueue<'a>) -> Option<__pair<CertiCoq_Benchmarks_lib_Binom_key<'a>, CertiCoq_Benchmarks_lib_Binom_priqueue<'a>>> { + self.closure(move |q| { + self.CertiCoq_Benchmarks_lib_Binom_delete_max( + q) + }) +} + +fn CertiCoq_Benchmarks_lib_Binom_main(&'a self) -> CertiCoq_Benchmarks_lib_Binom_key<'a> { + let a = + self.CertiCoq_Benchmarks_lib_Binom_insert_list( + self.CertiCoq_Benchmarks_lib_Binom_make_list( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + 0)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))), + self.alloc( + Coq_Init_Datatypes_list::nil( + PhantomData))), + self.CertiCoq_Benchmarks_lib_Binom_empty()); + let b = + self.CertiCoq_Benchmarks_lib_Binom_insert_list( + self.CertiCoq_Benchmarks_lib_Binom_make_list( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + __nat_succ( + 0))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))), + self.alloc( + Coq_Init_Datatypes_list::nil( + PhantomData))), + self.CertiCoq_Benchmarks_lib_Binom_empty()); + let c = + self.CertiCoq_Benchmarks_lib_Binom_merge( + a, + b); + match self.CertiCoq_Benchmarks_lib_Binom_delete_max( + c) { + Some(p) => { + __pair_elim!( + p0, k, { + p0 + }, + p) + }, + None => { + 0 + }, + } +} + +fn CertiCoq_Benchmarks_tests_binom(&'a self) -> CertiCoq_Benchmarks_lib_Binom_key<'a> { + self.CertiCoq_Benchmarks_lib_Binom_main() +} +} +fn main() { + println!("{:?}", Program::new().CertiCoq_Benchmarks_tests_binom()) +} diff --git a/tests/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr b/tests/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr index 25838fbf0ab..16a93a0d47d 100644 --- a/tests/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr +++ b/tests/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr @@ -13,7 +13,7 @@ LL | Some(_z @ ref _y) => {} | ^^ ------ value borrowed here after move | | | value moved into `_z` here - | move occurs because `_z` has type `X` which does not implement the `Copy` trait + | move occurs because `_z` has type `X`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -35,7 +35,7 @@ LL | Some(_z @ ref mut _y) => {} | ^^ ---------- value borrowed here after move | | | value moved into `_z` here - | move occurs because `_z` has type `X` which does not implement the `Copy` trait + | move occurs because `_z` has type `X`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | diff --git a/tests/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse-promotion.stderr b/tests/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse-promotion.stderr index 815a4ade995..ea04d4bc055 100644 --- a/tests/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse-promotion.stderr +++ b/tests/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse-promotion.stderr @@ -5,7 +5,7 @@ LL | let a @ ref b = U; | ^ ----- value borrowed here after move | | | value moved into `a` here - | move occurs because `a` has type `U` which does not implement the `Copy` trait + | move occurs because `a` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | diff --git a/tests/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse.stderr b/tests/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse.stderr index fd7a51388bc..25c940a3200 100644 --- a/tests/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse.stderr +++ b/tests/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse.stderr @@ -5,7 +5,7 @@ LL | let a @ ref b = U; | ^ ----- value borrowed here after move | | | value moved into `a` here - | move occurs because `a` has type `U` which does not implement the `Copy` trait + | move occurs because `a` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -20,7 +20,7 @@ LL | let a @ (mut b @ ref mut c, d @ ref e) = (U, U); | | | | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `(U, U)` which does not implement the `Copy` trait + | move occurs because `a` has type `(U, U)`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -34,7 +34,7 @@ LL | let a @ (mut b @ ref mut c, d @ ref e) = (U, U); | ^^^^^ --------- value borrowed here after move | | | value moved into `b` here - | move occurs because `b` has type `U` which does not implement the `Copy` trait + | move occurs because `b` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -48,7 +48,7 @@ LL | let a @ (mut b @ ref mut c, d @ ref e) = (U, U); | ^ ----- value borrowed here after move | | | value moved into `d` here - | move occurs because `d` has type `U` which does not implement the `Copy` trait + | move occurs because `d` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -63,7 +63,7 @@ LL | let a @ [ref mut b, ref c] = [U, U]; | | | | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `[U; 2]` which does not implement the `Copy` trait + | move occurs because `a` has type `[U; 2]`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -77,7 +77,7 @@ LL | let a @ ref b = u(); | ^ ----- value borrowed here after move | | | value moved into `a` here - | move occurs because `a` has type `U` which does not implement the `Copy` trait + | move occurs because `a` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -92,7 +92,7 @@ LL | let a @ (mut b @ ref mut c, d @ ref e) = (u(), u()); | | | | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `(U, U)` which does not implement the `Copy` trait + | move occurs because `a` has type `(U, U)`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -106,7 +106,7 @@ LL | let a @ (mut b @ ref mut c, d @ ref e) = (u(), u()); | ^^^^^ --------- value borrowed here after move | | | value moved into `b` here - | move occurs because `b` has type `U` which does not implement the `Copy` trait + | move occurs because `b` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -120,7 +120,7 @@ LL | let a @ (mut b @ ref mut c, d @ ref e) = (u(), u()); | ^ ----- value borrowed here after move | | | value moved into `d` here - | move occurs because `d` has type `U` which does not implement the `Copy` trait + | move occurs because `d` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -135,7 +135,7 @@ LL | let a @ [ref mut b, ref c] = [u(), u()]; | | | | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `[U; 2]` which does not implement the `Copy` trait + | move occurs because `a` has type `[U; 2]`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -149,7 +149,7 @@ LL | a @ Some(ref b) => {} | ^ ----- value borrowed here after move | | | value moved into `a` here - | move occurs because `a` has type `Option<U>` which does not implement the `Copy` trait + | move occurs because `a` has type `Option<U>`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -164,7 +164,7 @@ LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {} | | | | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `Option<(U, U)>` which does not implement the `Copy` trait + | move occurs because `a` has type `Option<(U, U)>`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -178,7 +178,7 @@ LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {} | ^^^^^ --------- value borrowed here after move | | | value moved into `b` here - | move occurs because `b` has type `U` which does not implement the `Copy` trait + | move occurs because `b` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -192,7 +192,7 @@ LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {} | ^ ----- value borrowed here after move | | | value moved into `d` here - | move occurs because `d` has type `U` which does not implement the `Copy` trait + | move occurs because `d` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -207,7 +207,7 @@ LL | mut a @ Some([ref b, ref mut c]) => {} | | | | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `Option<[U; 2]>` which does not implement the `Copy` trait + | move occurs because `a` has type `Option<[U; 2]>`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -221,7 +221,7 @@ LL | a @ Some(ref b) => {} | ^ ----- value borrowed here after move | | | value moved into `a` here - | move occurs because `a` has type `Option<U>` which does not implement the `Copy` trait + | move occurs because `a` has type `Option<U>`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -236,7 +236,7 @@ LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {} | | | | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `Option<(U, U)>` which does not implement the `Copy` trait + | move occurs because `a` has type `Option<(U, U)>`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -250,7 +250,7 @@ LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {} | ^^^^^ --------- value borrowed here after move | | | value moved into `b` here - | move occurs because `b` has type `U` which does not implement the `Copy` trait + | move occurs because `b` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -264,7 +264,7 @@ LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {} | ^ ----- value borrowed here after move | | | value moved into `d` here - | move occurs because `d` has type `U` which does not implement the `Copy` trait + | move occurs because `d` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -279,7 +279,7 @@ LL | mut a @ Some([ref b, ref mut c]) => {} | | | | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `Option<[U; 2]>` which does not implement the `Copy` trait + | move occurs because `a` has type `Option<[U; 2]>`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -349,7 +349,7 @@ LL | fn f1(a @ ref b: U) {} | ^ ----- value borrowed here after move | | | value moved into `a` here - | move occurs because `a` has type `U` which does not implement the `Copy` trait + | move occurs because `a` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -364,7 +364,7 @@ LL | fn f2(mut a @ (b @ ref c, mut d @ ref e): (U, U)) {} | | | | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `(U, U)` which does not implement the `Copy` trait + | move occurs because `a` has type `(U, U)`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -378,7 +378,7 @@ LL | fn f2(mut a @ (b @ ref c, mut d @ ref e): (U, U)) {} | ^ ----- value borrowed here after move | | | value moved into `b` here - | move occurs because `b` has type `U` which does not implement the `Copy` trait + | move occurs because `b` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -392,7 +392,7 @@ LL | fn f2(mut a @ (b @ ref c, mut d @ ref e): (U, U)) {} | ^^^^^ ----- value borrowed here after move | | | value moved into `d` here - | move occurs because `d` has type `U` which does not implement the `Copy` trait + | move occurs because `d` has type `U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -417,7 +417,7 @@ LL | fn f3(a @ [ref mut b, ref c]: [U; 2]) {} | | | | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `[U; 2]` which does not implement the `Copy` trait + | move occurs because `a` has type `[U; 2]`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | diff --git a/tests/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.stderr b/tests/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.stderr index 3446148d2b1..76085f897ff 100644 --- a/tests/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.stderr +++ b/tests/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.stderr @@ -78,7 +78,7 @@ LL | let a @ (ref mut b, ref mut c) = (U, U); | | | | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `(U, U)` which does not implement the `Copy` trait + | move occurs because `a` has type `(U, U)`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -94,7 +94,7 @@ LL | let a @ (b, [c, d]) = &mut val; // Same as ^-- | | | value borrowed here after move | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `&mut (U, [U; 2])` which does not implement the `Copy` trait + | move occurs because `a` has type `&mut (U, [U; 2])`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -108,7 +108,7 @@ LL | let a @ &mut ref mut b = &mut U; | ^ --------- value borrowed here after move | | | value moved into `a` here - | move occurs because `a` has type `&mut U` which does not implement the `Copy` trait + | move occurs because `a` has type `&mut U`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -123,7 +123,7 @@ LL | let a @ &mut (ref mut b, ref mut c) = &mut (U, U); | | | | | value borrowed here after move | value moved into `a` here - | move occurs because `a` has type `&mut (U, U)` which does not implement the `Copy` trait + | move occurs because `a` has type `&mut (U, U)`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | diff --git a/tests/ui/pattern/bindings-after-at/default-binding-modes-both-sides-independent.stderr b/tests/ui/pattern/bindings-after-at/default-binding-modes-both-sides-independent.stderr index 36515c1a29b..a0a43e83a6a 100644 --- a/tests/ui/pattern/bindings-after-at/default-binding-modes-both-sides-independent.stderr +++ b/tests/ui/pattern/bindings-after-at/default-binding-modes-both-sides-independent.stderr @@ -29,7 +29,7 @@ LL | Ok(ref a @ b) | Err(b @ ref a) => { | ^ ----- value borrowed here after move | | | value moved into `b` here - | move occurs because `b` has type `NotCopy` which does not implement the `Copy` trait + | move occurs because `b` has type `NotCopy`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | diff --git a/tests/ui/pattern/deref-patterns/typeck.rs b/tests/ui/pattern/deref-patterns/typeck.rs new file mode 100644 index 00000000000..ead6dcdbaf0 --- /dev/null +++ b/tests/ui/pattern/deref-patterns/typeck.rs @@ -0,0 +1,31 @@ +//@ check-pass +#![feature(deref_patterns)] +#![allow(incomplete_features)] + +use std::rc::Rc; + +fn main() { + let vec: Vec<u32> = Vec::new(); + match vec { + deref!([..]) => {} + _ => {} + } + match Box::new(true) { + deref!(true) => {} + _ => {} + } + match &Box::new(true) { + deref!(true) => {} + _ => {} + } + match &Rc::new(0) { + deref!(1..) => {} + _ => {} + } + // FIXME(deref_patterns): fails to typecheck because `"foo"` has type &str but deref creates a + // place of type `str`. + // match "foo".to_string() { + // box "foo" => {} + // _ => {} + // } +} diff --git a/tests/ui/pattern/patkind-ref-binding-issue-114896.fixed b/tests/ui/pattern/patkind-ref-binding-issue-114896.fixed new file mode 100644 index 00000000000..086a119eb77 --- /dev/null +++ b/tests/ui/pattern/patkind-ref-binding-issue-114896.fixed @@ -0,0 +1,10 @@ +//@ run-rustfix +#![allow(dead_code)] + +fn main() { + fn x(a: &char) { + let &(mut b) = a; + b.make_ascii_uppercase(); +//~^ cannot borrow `b` as mutable, as it is not declared as mutable + } +} diff --git a/tests/ui/pattern/issue-114896.rs b/tests/ui/pattern/patkind-ref-binding-issue-114896.rs index cde37f658d6..b4d6b72c01f 100644 --- a/tests/ui/pattern/issue-114896.rs +++ b/tests/ui/pattern/patkind-ref-binding-issue-114896.rs @@ -1,3 +1,6 @@ +//@ run-rustfix +#![allow(dead_code)] + fn main() { fn x(a: &char) { let &b = a; diff --git a/tests/ui/pattern/issue-114896.stderr b/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr index 285c9109e1b..68538255edd 100644 --- a/tests/ui/pattern/issue-114896.stderr +++ b/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr @@ -1,5 +1,5 @@ error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable - --> $DIR/issue-114896.rs:4:9 + --> $DIR/patkind-ref-binding-issue-114896.rs:7:9 | LL | let &b = a; | -- help: consider changing this to be mutable: `&(mut b)` diff --git a/tests/ui/pattern/patkind-ref-binding-issue-122415.fixed b/tests/ui/pattern/patkind-ref-binding-issue-122415.fixed new file mode 100644 index 00000000000..6144f062169 --- /dev/null +++ b/tests/ui/pattern/patkind-ref-binding-issue-122415.fixed @@ -0,0 +1,11 @@ +//@ run-rustfix +#![allow(dead_code)] + +fn mutate(_y: &mut i32) {} + +fn foo(&(mut x): &i32) { + mutate(&mut x); + //~^ ERROR cannot borrow `x` as mutable +} + +fn main() {} diff --git a/tests/ui/pattern/patkind-ref-binding-issue-122415.rs b/tests/ui/pattern/patkind-ref-binding-issue-122415.rs new file mode 100644 index 00000000000..b9f6416027a --- /dev/null +++ b/tests/ui/pattern/patkind-ref-binding-issue-122415.rs @@ -0,0 +1,11 @@ +//@ run-rustfix +#![allow(dead_code)] + +fn mutate(_y: &mut i32) {} + +fn foo(&x: &i32) { + mutate(&mut x); + //~^ ERROR cannot borrow `x` as mutable +} + +fn main() {} diff --git a/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr b/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr new file mode 100644 index 00000000000..39283133ac7 --- /dev/null +++ b/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr @@ -0,0 +1,11 @@ +error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable + --> $DIR/patkind-ref-binding-issue-122415.rs:7:12 + | +LL | fn foo(&x: &i32) { + | -- help: consider changing this to be mutable: `&(mut x)` +LL | mutate(&mut x); + | ^^^^^^ cannot borrow as mutable + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0596`. diff --git a/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr b/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr index 98c66c9dd07..45bdba94d78 100644 --- a/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr +++ b/tests/ui/pattern/usefulness/empty-types.exhaustive_patterns.stderr @@ -1,23 +1,23 @@ error: unreachable pattern - --> $DIR/empty-types.rs:49:9 + --> $DIR/empty-types.rs:51:9 | LL | _ => {} | ^ | note: the lint level is defined here - --> $DIR/empty-types.rs:15:9 + --> $DIR/empty-types.rs:17:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:52:9 + --> $DIR/empty-types.rs:54:9 | LL | _x => {} | ^^ error[E0004]: non-exhaustive patterns: type `&!` is non-empty - --> $DIR/empty-types.rs:56:11 + --> $DIR/empty-types.rs:58:11 | LL | match ref_never {} | ^^^^^^^^^ @@ -32,31 +32,31 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:71:9 + --> $DIR/empty-types.rs:73:9 | LL | (_, _) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:78:9 + --> $DIR/empty-types.rs:80:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:81:9 + --> $DIR/empty-types.rs:83:9 | LL | (_, _) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:85:9 + --> $DIR/empty-types.rs:87:9 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: `Ok(_)` not covered - --> $DIR/empty-types.rs:89:11 + --> $DIR/empty-types.rs:91:11 | LL | match res_u32_never {} | ^^^^^^^^^^^^^ pattern `Ok(_)` not covered @@ -75,19 +75,19 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:97:9 + --> $DIR/empty-types.rs:99:9 | LL | Err(_) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:102:9 + --> $DIR/empty-types.rs:104:9 | LL | Err(_) => {} | ^^^^^^ error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered - --> $DIR/empty-types.rs:99:11 + --> $DIR/empty-types.rs:101:11 | LL | match res_u32_never { | ^^^^^^^^^^^^^ pattern `Ok(1_u32..=u32::MAX)` not covered @@ -105,7 +105,7 @@ LL ~ Ok(1_u32..=u32::MAX) => todo!() | error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:106:9 + --> $DIR/empty-types.rs:108:9 | LL | let Ok(_x) = res_u32_never.as_ref(); | ^^^^^^ pattern `Err(_)` not covered @@ -119,121 +119,121 @@ LL | let Ok(_x) = res_u32_never.as_ref() else { todo!() }; | ++++++++++++++++ error: unreachable pattern - --> $DIR/empty-types.rs:117:9 + --> $DIR/empty-types.rs:119:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:121:9 + --> $DIR/empty-types.rs:123:9 | LL | Ok(_) => {} | ^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:124:9 + --> $DIR/empty-types.rs:126:9 | LL | Ok(_) => {} | ^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:125:9 + --> $DIR/empty-types.rs:127:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:128:9 + --> $DIR/empty-types.rs:130:9 | LL | Ok(_) => {} | ^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:129:9 + --> $DIR/empty-types.rs:131:9 | LL | Err(_) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:138:13 + --> $DIR/empty-types.rs:140:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:141:13 + --> $DIR/empty-types.rs:143:13 | LL | _ if false => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:150:13 + --> $DIR/empty-types.rs:152:13 | LL | Some(_) => {} | ^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:154:13 + --> $DIR/empty-types.rs:156:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:206:13 + --> $DIR/empty-types.rs:208:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:211:13 + --> $DIR/empty-types.rs:213:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:216:13 + --> $DIR/empty-types.rs:218:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:221:13 + --> $DIR/empty-types.rs:223:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:227:13 + --> $DIR/empty-types.rs:229:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:286:9 + --> $DIR/empty-types.rs:288:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:289:9 + --> $DIR/empty-types.rs:291:9 | LL | (_, _) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:292:9 + --> $DIR/empty-types.rs:294:9 | LL | Ok(_) => {} | ^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:293:9 + --> $DIR/empty-types.rs:295:9 | LL | Err(_) => {} | ^^^^^^ error[E0004]: non-exhaustive patterns: type `&[!]` is non-empty - --> $DIR/empty-types.rs:325:11 + --> $DIR/empty-types.rs:327:11 | LL | match slice_never {} | ^^^^^^^^^^^ @@ -247,7 +247,7 @@ LL + } | error[E0004]: non-exhaustive patterns: `&[]` not covered - --> $DIR/empty-types.rs:336:11 + --> $DIR/empty-types.rs:338:11 | LL | match slice_never { | ^^^^^^^^^^^ pattern `&[]` not covered @@ -260,7 +260,7 @@ LL + &[] => todo!() | error[E0004]: non-exhaustive patterns: `&[]` not covered - --> $DIR/empty-types.rs:349:11 + --> $DIR/empty-types.rs:352:11 | LL | match slice_never { | ^^^^^^^^^^^ pattern `&[]` not covered @@ -274,7 +274,7 @@ LL + &[] => todo!() | error[E0004]: non-exhaustive patterns: type `[!]` is non-empty - --> $DIR/empty-types.rs:355:11 + --> $DIR/empty-types.rs:359:11 | LL | match *slice_never {} | ^^^^^^^^^^^^ @@ -288,25 +288,25 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:365:9 + --> $DIR/empty-types.rs:369:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:368:9 + --> $DIR/empty-types.rs:372:9 | LL | [_, _, _] => {} | ^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:371:9 + --> $DIR/empty-types.rs:375:9 | LL | [_, ..] => {} | ^^^^^^^ error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty - --> $DIR/empty-types.rs:385:11 + --> $DIR/empty-types.rs:389:11 | LL | match array_0_never {} | ^^^^^^^^^^^^^ @@ -320,13 +320,13 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:392:9 + --> $DIR/empty-types.rs:396:9 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: `[]` not covered - --> $DIR/empty-types.rs:394:11 + --> $DIR/empty-types.rs:398:11 | LL | match array_0_never { | ^^^^^^^^^^^^^ pattern `[]` not covered @@ -340,49 +340,49 @@ LL + [] => todo!() | error: unreachable pattern - --> $DIR/empty-types.rs:413:9 + --> $DIR/empty-types.rs:417:9 | LL | Some(_) => {} | ^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:418:9 + --> $DIR/empty-types.rs:422:9 | LL | Some(_a) => {} | ^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:423:9 + --> $DIR/empty-types.rs:427:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:428:9 + --> $DIR/empty-types.rs:432:9 | LL | _a => {} | ^^ error: unreachable pattern - --> $DIR/empty-types.rs:600:9 + --> $DIR/empty-types.rs:604:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:603:9 + --> $DIR/empty-types.rs:607:9 | LL | _x => {} | ^^ error: unreachable pattern - --> $DIR/empty-types.rs:606:9 + --> $DIR/empty-types.rs:610:9 | LL | _ if false => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:609:9 + --> $DIR/empty-types.rs:613:9 | LL | _x if false => {} | ^^ diff --git a/tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr b/tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr index d5121e7043c..6e50dfe6a26 100644 --- a/tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr +++ b/tests/ui/pattern/usefulness/empty-types.min_exh_pats.stderr @@ -1,23 +1,23 @@ error: unreachable pattern - --> $DIR/empty-types.rs:49:9 + --> $DIR/empty-types.rs:51:9 | LL | _ => {} | ^ | note: the lint level is defined here - --> $DIR/empty-types.rs:15:9 + --> $DIR/empty-types.rs:17:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:52:9 + --> $DIR/empty-types.rs:54:9 | LL | _x => {} | ^^ error[E0004]: non-exhaustive patterns: type `&!` is non-empty - --> $DIR/empty-types.rs:56:11 + --> $DIR/empty-types.rs:58:11 | LL | match ref_never {} | ^^^^^^^^^ @@ -32,31 +32,31 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:71:9 + --> $DIR/empty-types.rs:73:9 | LL | (_, _) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:78:9 + --> $DIR/empty-types.rs:80:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:81:9 + --> $DIR/empty-types.rs:83:9 | LL | (_, _) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:85:9 + --> $DIR/empty-types.rs:87:9 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: `Ok(_)` not covered - --> $DIR/empty-types.rs:89:11 + --> $DIR/empty-types.rs:91:11 | LL | match res_u32_never {} | ^^^^^^^^^^^^^ pattern `Ok(_)` not covered @@ -75,19 +75,19 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:97:9 + --> $DIR/empty-types.rs:99:9 | LL | Err(_) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:102:9 + --> $DIR/empty-types.rs:104:9 | LL | Err(_) => {} | ^^^^^^ error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered - --> $DIR/empty-types.rs:99:11 + --> $DIR/empty-types.rs:101:11 | LL | match res_u32_never { | ^^^^^^^^^^^^^ pattern `Ok(1_u32..=u32::MAX)` not covered @@ -105,7 +105,7 @@ LL ~ Ok(1_u32..=u32::MAX) => todo!() | error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:106:9 + --> $DIR/empty-types.rs:108:9 | LL | let Ok(_x) = res_u32_never.as_ref(); | ^^^^^^ pattern `Err(_)` not covered @@ -119,7 +119,7 @@ LL | let Ok(_x) = res_u32_never.as_ref() else { todo!() }; | ++++++++++++++++ error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:110:9 + --> $DIR/empty-types.rs:112:9 | LL | let Ok(_x) = &res_u32_never; | ^^^^^^ pattern `&Err(_)` not covered @@ -133,67 +133,67 @@ LL | let Ok(_x) = &res_u32_never else { todo!() }; | ++++++++++++++++ error: unreachable pattern - --> $DIR/empty-types.rs:117:9 + --> $DIR/empty-types.rs:119:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:121:9 + --> $DIR/empty-types.rs:123:9 | LL | Ok(_) => {} | ^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:124:9 + --> $DIR/empty-types.rs:126:9 | LL | Ok(_) => {} | ^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:125:9 + --> $DIR/empty-types.rs:127:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:128:9 + --> $DIR/empty-types.rs:130:9 | LL | Ok(_) => {} | ^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:129:9 + --> $DIR/empty-types.rs:131:9 | LL | Err(_) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:138:13 + --> $DIR/empty-types.rs:140:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:141:13 + --> $DIR/empty-types.rs:143:13 | LL | _ if false => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:150:13 + --> $DIR/empty-types.rs:152:13 | LL | Some(_) => {} | ^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:154:13 + --> $DIR/empty-types.rs:156:13 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:163:15 + --> $DIR/empty-types.rs:165:15 | LL | match *ref_opt_void { | ^^^^^^^^^^^^^ pattern `Some(_)` not covered @@ -211,61 +211,61 @@ LL + Some(_) => todo!() | error: unreachable pattern - --> $DIR/empty-types.rs:206:13 + --> $DIR/empty-types.rs:208:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:211:13 + --> $DIR/empty-types.rs:213:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:216:13 + --> $DIR/empty-types.rs:218:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:221:13 + --> $DIR/empty-types.rs:223:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:227:13 + --> $DIR/empty-types.rs:229:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:286:9 + --> $DIR/empty-types.rs:288:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:289:9 + --> $DIR/empty-types.rs:291:9 | LL | (_, _) => {} | ^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:292:9 + --> $DIR/empty-types.rs:294:9 | LL | Ok(_) => {} | ^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:293:9 + --> $DIR/empty-types.rs:295:9 | LL | Err(_) => {} | ^^^^^^ error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:314:11 + --> $DIR/empty-types.rs:316:11 | LL | match *x {} | ^^ @@ -279,7 +279,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `(!, !)` is non-empty - --> $DIR/empty-types.rs:316:11 + --> $DIR/empty-types.rs:318:11 | LL | match *x {} | ^^ @@ -293,7 +293,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered - --> $DIR/empty-types.rs:318:11 + --> $DIR/empty-types.rs:320:11 | LL | match *x {} | ^^ patterns `Ok(_)` and `Err(_)` not covered @@ -315,7 +315,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `[!; 3]` is non-empty - --> $DIR/empty-types.rs:320:11 + --> $DIR/empty-types.rs:322:11 | LL | match *x {} | ^^ @@ -329,7 +329,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `&[!]` is non-empty - --> $DIR/empty-types.rs:325:11 + --> $DIR/empty-types.rs:327:11 | LL | match slice_never {} | ^^^^^^^^^^^ @@ -343,7 +343,7 @@ LL + } | error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered - --> $DIR/empty-types.rs:327:11 + --> $DIR/empty-types.rs:329:11 | LL | match slice_never { | ^^^^^^^^^^^ pattern `&[_, ..]` not covered @@ -356,7 +356,7 @@ LL + &[_, ..] => todo!() | error[E0004]: non-exhaustive patterns: `&[]`, `&[_]` and `&[_, _]` not covered - --> $DIR/empty-types.rs:336:11 + --> $DIR/empty-types.rs:338:11 | LL | match slice_never { | ^^^^^^^^^^^ patterns `&[]`, `&[_]` and `&[_, _]` not covered @@ -369,7 +369,7 @@ LL + &[] | &[_] | &[_, _] => todo!() | error[E0004]: non-exhaustive patterns: `&[]` and `&[_, ..]` not covered - --> $DIR/empty-types.rs:349:11 + --> $DIR/empty-types.rs:352:11 | LL | match slice_never { | ^^^^^^^^^^^ patterns `&[]` and `&[_, ..]` not covered @@ -383,7 +383,7 @@ LL + &[] | &[_, ..] => todo!() | error[E0004]: non-exhaustive patterns: type `[!]` is non-empty - --> $DIR/empty-types.rs:355:11 + --> $DIR/empty-types.rs:359:11 | LL | match *slice_never {} | ^^^^^^^^^^^^ @@ -397,25 +397,25 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:365:9 + --> $DIR/empty-types.rs:369:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:368:9 + --> $DIR/empty-types.rs:372:9 | LL | [_, _, _] => {} | ^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:371:9 + --> $DIR/empty-types.rs:375:9 | LL | [_, ..] => {} | ^^^^^^^ error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty - --> $DIR/empty-types.rs:385:11 + --> $DIR/empty-types.rs:389:11 | LL | match array_0_never {} | ^^^^^^^^^^^^^ @@ -429,13 +429,13 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:392:9 + --> $DIR/empty-types.rs:396:9 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: `[]` not covered - --> $DIR/empty-types.rs:394:11 + --> $DIR/empty-types.rs:398:11 | LL | match array_0_never { | ^^^^^^^^^^^^^ pattern `[]` not covered @@ -449,31 +449,31 @@ LL + [] => todo!() | error: unreachable pattern - --> $DIR/empty-types.rs:413:9 + --> $DIR/empty-types.rs:417:9 | LL | Some(_) => {} | ^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:418:9 + --> $DIR/empty-types.rs:422:9 | LL | Some(_a) => {} | ^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:423:9 + --> $DIR/empty-types.rs:427:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:428:9 + --> $DIR/empty-types.rs:432:9 | LL | _a => {} | ^^ error[E0004]: non-exhaustive patterns: `&Some(_)` not covered - --> $DIR/empty-types.rs:448:11 + --> $DIR/empty-types.rs:452:11 | LL | match ref_opt_never { | ^^^^^^^^^^^^^ pattern `&Some(_)` not covered @@ -491,7 +491,7 @@ LL + &Some(_) => todo!() | error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:489:11 + --> $DIR/empty-types.rs:493:11 | LL | match *ref_opt_never { | ^^^^^^^^^^^^^^ pattern `Some(_)` not covered @@ -509,7 +509,7 @@ LL + Some(_) => todo!() | error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:537:11 + --> $DIR/empty-types.rs:541:11 | LL | match *ref_res_never { | ^^^^^^^^^^^^^^ pattern `Err(_)` not covered @@ -527,7 +527,7 @@ LL + Err(_) => todo!() | error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:548:11 + --> $DIR/empty-types.rs:552:11 | LL | match *ref_res_never { | ^^^^^^^^^^^^^^ pattern `Err(_)` not covered @@ -545,7 +545,7 @@ LL + Err(_) => todo!() | error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:567:11 + --> $DIR/empty-types.rs:571:11 | LL | match *ref_tuple_half_never {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -559,31 +559,31 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:600:9 + --> $DIR/empty-types.rs:604:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:603:9 + --> $DIR/empty-types.rs:607:9 | LL | _x => {} | ^^ error: unreachable pattern - --> $DIR/empty-types.rs:606:9 + --> $DIR/empty-types.rs:610:9 | LL | _ if false => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:609:9 + --> $DIR/empty-types.rs:613:9 | LL | _x if false => {} | ^^ error[E0004]: non-exhaustive patterns: `&_` not covered - --> $DIR/empty-types.rs:634:11 + --> $DIR/empty-types.rs:638:11 | LL | match ref_never { | ^^^^^^^^^ pattern `&_` not covered @@ -597,8 +597,26 @@ LL ~ &_a if false => {}, LL + &_ => todo!() | +error[E0004]: non-exhaustive patterns: `Ok(_)` not covered + --> $DIR/empty-types.rs:654:11 + | +LL | match *ref_result_never { + | ^^^^^^^^^^^^^^^^^ pattern `Ok(_)` not covered + | +note: `Result<!, !>` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result<!, !>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Err(_) => {}, +LL + Ok(_) => todo!() + | + error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:662:11 + --> $DIR/empty-types.rs:674:11 | LL | match *x { | ^^ pattern `Some(_)` not covered @@ -615,7 +633,7 @@ LL ~ None => {}, LL + Some(_) => todo!() | -error: aborting due to 63 previous errors +error: aborting due to 64 previous errors Some errors have detailed explanations: E0004, E0005. For more information about an error, try `rustc --explain E0004`. diff --git a/tests/ui/pattern/usefulness/empty-types.never_pats.stderr b/tests/ui/pattern/usefulness/empty-types.never_pats.stderr new file mode 100644 index 00000000000..0ff2472922e --- /dev/null +++ b/tests/ui/pattern/usefulness/empty-types.never_pats.stderr @@ -0,0 +1,644 @@ +warning: the feature `never_patterns` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/empty-types.rs:14:33 + | +LL | #![cfg_attr(never_pats, feature(never_patterns))] + | ^^^^^^^^^^^^^^ + | + = note: see issue #118155 <https://github.com/rust-lang/rust/issues/118155> for more information + = note: `#[warn(incomplete_features)]` on by default + +error: unreachable pattern + --> $DIR/empty-types.rs:51:9 + | +LL | _ => {} + | ^ + | +note: the lint level is defined here + --> $DIR/empty-types.rs:17:9 + | +LL | #![deny(unreachable_patterns)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:54:9 + | +LL | _x => {} + | ^^ + +error[E0004]: non-exhaustive patterns: type `&!` is non-empty + --> $DIR/empty-types.rs:58:11 + | +LL | match ref_never {} + | ^^^^^^^^^ + | + = note: the matched value is of type `&!` + = note: references are always considered inhabited +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match ref_never { +LL + _ => todo!(), +LL + } + | + +error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty + --> $DIR/empty-types.rs:70:11 + | +LL | match tuple_half_never {} + | ^^^^^^^^^^^^^^^^ + | + = note: the matched value is of type `(u32, !)` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match tuple_half_never { +LL + _ => todo!(), +LL + } + | + +error[E0004]: non-exhaustive patterns: type `(!, !)` is non-empty + --> $DIR/empty-types.rs:77:11 + | +LL | match tuple_never {} + | ^^^^^^^^^^^ + | + = note: the matched value is of type `(!, !)` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match tuple_never { +LL + _ => todo!(), +LL + } + | + +error: unreachable pattern + --> $DIR/empty-types.rs:87:9 + | +LL | _ => {} + | ^ + +error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(!)` not covered + --> $DIR/empty-types.rs:91:11 + | +LL | match res_u32_never {} + | ^^^^^^^^^^^^^ patterns `Ok(_)` and `Err(!)` not covered + | +note: `Result<u32, !>` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result<u32, !>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms + | +LL ~ match res_u32_never { +LL + Ok(_) | Err(!) => todo!(), +LL + } + | + +error[E0004]: non-exhaustive patterns: `Err(!)` not covered + --> $DIR/empty-types.rs:93:11 + | +LL | match res_u32_never { + | ^^^^^^^^^^^^^ pattern `Err(!)` not covered + | +note: `Result<u32, !>` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result<u32, !>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Ok(_) => {}, +LL + Err(!) + | + +error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered + --> $DIR/empty-types.rs:101:11 + | +LL | match res_u32_never { + | ^^^^^^^^^^^^^ pattern `Ok(1_u32..=u32::MAX)` not covered + | +note: `Result<u32, !>` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result<u32, !>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Err(_) => {}, +LL ~ Ok(1_u32..=u32::MAX) => todo!() + | + +error[E0005]: refutable pattern in local binding + --> $DIR/empty-types.rs:106:9 + | +LL | let Ok(_x) = res_u32_never; + | ^^^^^^ pattern `Err(!)` not covered + | + = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant + = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html + = note: the matched value is of type `Result<u32, !>` +help: you might want to use `let else` to handle the variant that isn't matched + | +LL | let Ok(_x) = res_u32_never else { todo!() }; + | ++++++++++++++++ + +error[E0005]: refutable pattern in local binding + --> $DIR/empty-types.rs:108:9 + | +LL | let Ok(_x) = res_u32_never.as_ref(); + | ^^^^^^ pattern `Err(_)` not covered + | + = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant + = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html + = note: the matched value is of type `Result<&u32, &!>` +help: you might want to use `let else` to handle the variant that isn't matched + | +LL | let Ok(_x) = res_u32_never.as_ref() else { todo!() }; + | ++++++++++++++++ + +error[E0005]: refutable pattern in local binding + --> $DIR/empty-types.rs:112:9 + | +LL | let Ok(_x) = &res_u32_never; + | ^^^^^^ pattern `&Err(!)` not covered + | + = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant + = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html + = note: the matched value is of type `&Result<u32, !>` +help: you might want to use `let else` to handle the variant that isn't matched + | +LL | let Ok(_x) = &res_u32_never else { todo!() }; + | ++++++++++++++++ + +error[E0004]: non-exhaustive patterns: `Ok(!)` and `Err(!)` not covered + --> $DIR/empty-types.rs:116:11 + | +LL | match result_never {} + | ^^^^^^^^^^^^ patterns `Ok(!)` and `Err(!)` not covered + | +note: `Result<!, !>` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result<!, !>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms + | +LL ~ match result_never { +LL + Ok(!) | Err(!), +LL + } + | + +error[E0004]: non-exhaustive patterns: `Err(!)` not covered + --> $DIR/empty-types.rs:121:11 + | +LL | match result_never { + | ^^^^^^^^^^^^ pattern `Err(!)` not covered + | +note: `Result<!, !>` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result<!, !>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL | Ok(_) => {}, Err(!) + | ++++++++ + +error: unreachable pattern + --> $DIR/empty-types.rs:140:13 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:143:13 + | +LL | _ if false => {} + | ^ + +error[E0004]: non-exhaustive patterns: `Some(!)` not covered + --> $DIR/empty-types.rs:146:15 + | +LL | match opt_void { + | ^^^^^^^^ pattern `Some(!)` not covered + | +note: `Option<Void>` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Option<Void>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ None => {}, +LL + Some(!) + | + +error[E0004]: non-exhaustive patterns: `Some(!)` not covered + --> $DIR/empty-types.rs:165:15 + | +LL | match *ref_opt_void { + | ^^^^^^^^^^^^^ pattern `Some(!)` not covered + | +note: `Option<Void>` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Option<Void>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ None => {}, +LL + Some(!) + | + +error: unreachable pattern + --> $DIR/empty-types.rs:208:13 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:213:13 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:218:13 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:223:13 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:229:13 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:288:9 + | +LL | _ => {} + | ^ + +error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty + --> $DIR/empty-types.rs:316:11 + | +LL | match *x {} + | ^^ + | + = note: the matched value is of type `(u32, !)` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match *x { +LL + _ => todo!(), +LL ~ } + | + +error[E0004]: non-exhaustive patterns: type `(!, !)` is non-empty + --> $DIR/empty-types.rs:318:11 + | +LL | match *x {} + | ^^ + | + = note: the matched value is of type `(!, !)` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match *x { +LL + _ => todo!(), +LL ~ } + | + +error[E0004]: non-exhaustive patterns: `Ok(!)` and `Err(!)` not covered + --> $DIR/empty-types.rs:320:11 + | +LL | match *x {} + | ^^ patterns `Ok(!)` and `Err(!)` not covered + | +note: `Result<!, !>` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result<!, !>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms + | +LL ~ match *x { +LL + Ok(!) | Err(!), +LL ~ } + | + +error[E0004]: non-exhaustive patterns: type `[!; 3]` is non-empty + --> $DIR/empty-types.rs:322:11 + | +LL | match *x {} + | ^^ + | + = note: the matched value is of type `[!; 3]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match *x { +LL + _ => todo!(), +LL ~ } + | + +error[E0004]: non-exhaustive patterns: type `&[!]` is non-empty + --> $DIR/empty-types.rs:327:11 + | +LL | match slice_never {} + | ^^^^^^^^^^^ + | + = note: the matched value is of type `&[!]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match slice_never { +LL + _ => todo!(), +LL + } + | + +error[E0004]: non-exhaustive patterns: `&[!, ..]` not covered + --> $DIR/empty-types.rs:329:11 + | +LL | match slice_never { + | ^^^^^^^^^^^ pattern `&[!, ..]` not covered + | + = note: the matched value is of type `&[!]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ [] => {}, +LL + &[!, ..] + | + +error[E0004]: non-exhaustive patterns: `&[]`, `&[!]` and `&[!, !]` not covered + --> $DIR/empty-types.rs:338:11 + | +LL | match slice_never { + | ^^^^^^^^^^^ patterns `&[]`, `&[!]` and `&[!, !]` not covered + | + = note: the matched value is of type `&[!]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms + | +LL ~ [_, _, _, ..] => {}, +LL + &[] | &[!] | &[!, !] => todo!() + | + +error[E0004]: non-exhaustive patterns: `&[]` and `&[!, ..]` not covered + --> $DIR/empty-types.rs:352:11 + | +LL | match slice_never { + | ^^^^^^^^^^^ patterns `&[]` and `&[!, ..]` not covered + | + = note: the matched value is of type `&[!]` + = note: match arms with guards don't count towards exhaustivity +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms + | +LL ~ &[..] if false => {}, +LL + &[] | &[!, ..] => todo!() + | + +error[E0004]: non-exhaustive patterns: type `[!]` is non-empty + --> $DIR/empty-types.rs:359:11 + | +LL | match *slice_never {} + | ^^^^^^^^^^^^ + | + = note: the matched value is of type `[!]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match *slice_never { +LL + _ => todo!(), +LL + } + | + +error[E0004]: non-exhaustive patterns: type `[!; 3]` is non-empty + --> $DIR/empty-types.rs:366:11 + | +LL | match array_3_never {} + | ^^^^^^^^^^^^^ + | + = note: the matched value is of type `[!; 3]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match array_3_never { +LL + _ => todo!(), +LL + } + | + +error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty + --> $DIR/empty-types.rs:389:11 + | +LL | match array_0_never {} + | ^^^^^^^^^^^^^ + | + = note: the matched value is of type `[!; 0]` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match array_0_never { +LL + _ => todo!(), +LL + } + | + +error: unreachable pattern + --> $DIR/empty-types.rs:396:9 + | +LL | _ => {} + | ^ + +error[E0004]: non-exhaustive patterns: `[]` not covered + --> $DIR/empty-types.rs:398:11 + | +LL | match array_0_never { + | ^^^^^^^^^^^^^ pattern `[]` not covered + | + = note: the matched value is of type `[!; 0]` + = note: match arms with guards don't count towards exhaustivity +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ [..] if false => {}, +LL + [] => todo!() + | + +error[E0004]: non-exhaustive patterns: `&Some(!)` not covered + --> $DIR/empty-types.rs:452:11 + | +LL | match ref_opt_never { + | ^^^^^^^^^^^^^ pattern `&Some(!)` not covered + | +note: `Option<!>` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `&Option<!>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ &None => {}, +LL + &Some(!) + | + +error[E0004]: non-exhaustive patterns: `Some(!)` not covered + --> $DIR/empty-types.rs:493:11 + | +LL | match *ref_opt_never { + | ^^^^^^^^^^^^^^ pattern `Some(!)` not covered + | +note: `Option<!>` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Option<!>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ None => {}, +LL + Some(!) + | + +error[E0004]: non-exhaustive patterns: `Err(!)` not covered + --> $DIR/empty-types.rs:541:11 + | +LL | match *ref_res_never { + | ^^^^^^^^^^^^^^ pattern `Err(!)` not covered + | +note: `Result<!, !>` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result<!, !>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Ok(_) => {}, +LL + Err(!) + | + +error[E0004]: non-exhaustive patterns: `Err(!)` not covered + --> $DIR/empty-types.rs:552:11 + | +LL | match *ref_res_never { + | ^^^^^^^^^^^^^^ pattern `Err(!)` not covered + | +note: `Result<!, !>` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result<!, !>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Ok(_a) => {}, +LL + Err(!) + | + +error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty + --> $DIR/empty-types.rs:571:11 + | +LL | match *ref_tuple_half_never {} + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: the matched value is of type `(u32, !)` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match *ref_tuple_half_never { +LL + _ => todo!(), +LL + } + | + +error: unreachable pattern + --> $DIR/empty-types.rs:604:9 + | +LL | _ => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:607:9 + | +LL | _x => {} + | ^^ + +error: unreachable pattern + --> $DIR/empty-types.rs:610:9 + | +LL | _ if false => {} + | ^ + +error: unreachable pattern + --> $DIR/empty-types.rs:613:9 + | +LL | _x if false => {} + | ^^ + +error[E0004]: non-exhaustive patterns: `&!` not covered + --> $DIR/empty-types.rs:638:11 + | +LL | match ref_never { + | ^^^^^^^^^ pattern `&!` not covered + | + = note: the matched value is of type `&!` + = note: references are always considered inhabited + = note: match arms with guards don't count towards exhaustivity +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ &_a if false => {}, +LL + &! + | + +error[E0004]: non-exhaustive patterns: `Ok(!)` not covered + --> $DIR/empty-types.rs:654:11 + | +LL | match *ref_result_never { + | ^^^^^^^^^^^^^^^^^ pattern `Ok(!)` not covered + | +note: `Result<!, !>` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result<!, !>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Err(_) => {}, +LL + Ok(!) + | + +error[E0004]: non-exhaustive patterns: `Some(!)` not covered + --> $DIR/empty-types.rs:674:11 + | +LL | match *x { + | ^^ pattern `Some(!)` not covered + | +note: `Option<Result<!, !>>` defined here + --> $SRC_DIR/core/src/option.rs:LL:COL + ::: $SRC_DIR/core/src/option.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Option<Result<!, !>>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ None => {}, +LL + Some(!) + | + +error: aborting due to 49 previous errors; 1 warning emitted + +Some errors have detailed explanations: E0004, E0005. +For more information about an error, try `rustc --explain E0004`. diff --git a/tests/ui/pattern/usefulness/empty-types.normal.stderr b/tests/ui/pattern/usefulness/empty-types.normal.stderr index dc01ac4ddce..1d13802a2bd 100644 --- a/tests/ui/pattern/usefulness/empty-types.normal.stderr +++ b/tests/ui/pattern/usefulness/empty-types.normal.stderr @@ -1,23 +1,23 @@ error: unreachable pattern - --> $DIR/empty-types.rs:49:9 + --> $DIR/empty-types.rs:51:9 | LL | _ => {} | ^ | note: the lint level is defined here - --> $DIR/empty-types.rs:15:9 + --> $DIR/empty-types.rs:17:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/empty-types.rs:52:9 + --> $DIR/empty-types.rs:54:9 | LL | _x => {} | ^^ error[E0004]: non-exhaustive patterns: type `&!` is non-empty - --> $DIR/empty-types.rs:56:11 + --> $DIR/empty-types.rs:58:11 | LL | match ref_never {} | ^^^^^^^^^ @@ -32,7 +32,7 @@ LL + } | error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:68:11 + --> $DIR/empty-types.rs:70:11 | LL | match tuple_half_never {} | ^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL + } | error[E0004]: non-exhaustive patterns: type `(!, !)` is non-empty - --> $DIR/empty-types.rs:75:11 + --> $DIR/empty-types.rs:77:11 | LL | match tuple_never {} | ^^^^^^^^^^^ @@ -60,13 +60,13 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:85:9 + --> $DIR/empty-types.rs:87:9 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered - --> $DIR/empty-types.rs:89:11 + --> $DIR/empty-types.rs:91:11 | LL | match res_u32_never {} | ^^^^^^^^^^^^^ patterns `Ok(_)` and `Err(_)` not covered @@ -88,7 +88,7 @@ LL + } | error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:91:11 + --> $DIR/empty-types.rs:93:11 | LL | match res_u32_never { | ^^^^^^^^^^^^^ pattern `Err(_)` not covered @@ -106,7 +106,7 @@ LL + Err(_) => todo!() | error[E0004]: non-exhaustive patterns: `Ok(1_u32..=u32::MAX)` not covered - --> $DIR/empty-types.rs:99:11 + --> $DIR/empty-types.rs:101:11 | LL | match res_u32_never { | ^^^^^^^^^^^^^ pattern `Ok(1_u32..=u32::MAX)` not covered @@ -124,7 +124,7 @@ LL ~ Ok(1_u32..=u32::MAX) => todo!() | error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:104:9 + --> $DIR/empty-types.rs:106:9 | LL | let Ok(_x) = res_u32_never; | ^^^^^^ pattern `Err(_)` not covered @@ -138,7 +138,7 @@ LL | let Ok(_x) = res_u32_never else { todo!() }; | ++++++++++++++++ error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:106:9 + --> $DIR/empty-types.rs:108:9 | LL | let Ok(_x) = res_u32_never.as_ref(); | ^^^^^^ pattern `Err(_)` not covered @@ -152,7 +152,7 @@ LL | let Ok(_x) = res_u32_never.as_ref() else { todo!() }; | ++++++++++++++++ error[E0005]: refutable pattern in local binding - --> $DIR/empty-types.rs:110:9 + --> $DIR/empty-types.rs:112:9 | LL | let Ok(_x) = &res_u32_never; | ^^^^^^ pattern `&Err(_)` not covered @@ -166,7 +166,7 @@ LL | let Ok(_x) = &res_u32_never else { todo!() }; | ++++++++++++++++ error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered - --> $DIR/empty-types.rs:114:11 + --> $DIR/empty-types.rs:116:11 | LL | match result_never {} | ^^^^^^^^^^^^ patterns `Ok(_)` and `Err(_)` not covered @@ -188,7 +188,7 @@ LL + } | error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:119:11 + --> $DIR/empty-types.rs:121:11 | LL | match result_never { | ^^^^^^^^^^^^ pattern `Err(_)` not covered @@ -205,19 +205,19 @@ LL | Ok(_) => {}, Err(_) => todo!() | +++++++++++++++++++ error: unreachable pattern - --> $DIR/empty-types.rs:138:13 + --> $DIR/empty-types.rs:140:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:141:13 + --> $DIR/empty-types.rs:143:13 | LL | _ if false => {} | ^ error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:144:15 + --> $DIR/empty-types.rs:146:15 | LL | match opt_void { | ^^^^^^^^ pattern `Some(_)` not covered @@ -235,7 +235,7 @@ LL + Some(_) => todo!() | error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:163:15 + --> $DIR/empty-types.rs:165:15 | LL | match *ref_opt_void { | ^^^^^^^^^^^^^ pattern `Some(_)` not covered @@ -253,43 +253,43 @@ LL + Some(_) => todo!() | error: unreachable pattern - --> $DIR/empty-types.rs:206:13 + --> $DIR/empty-types.rs:208:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:211:13 + --> $DIR/empty-types.rs:213:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:216:13 + --> $DIR/empty-types.rs:218:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:221:13 + --> $DIR/empty-types.rs:223:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:227:13 + --> $DIR/empty-types.rs:229:13 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:286:9 + --> $DIR/empty-types.rs:288:9 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:314:11 + --> $DIR/empty-types.rs:316:11 | LL | match *x {} | ^^ @@ -303,7 +303,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `(!, !)` is non-empty - --> $DIR/empty-types.rs:316:11 + --> $DIR/empty-types.rs:318:11 | LL | match *x {} | ^^ @@ -317,7 +317,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: `Ok(_)` and `Err(_)` not covered - --> $DIR/empty-types.rs:318:11 + --> $DIR/empty-types.rs:320:11 | LL | match *x {} | ^^ patterns `Ok(_)` and `Err(_)` not covered @@ -339,7 +339,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `[!; 3]` is non-empty - --> $DIR/empty-types.rs:320:11 + --> $DIR/empty-types.rs:322:11 | LL | match *x {} | ^^ @@ -353,7 +353,7 @@ LL ~ } | error[E0004]: non-exhaustive patterns: type `&[!]` is non-empty - --> $DIR/empty-types.rs:325:11 + --> $DIR/empty-types.rs:327:11 | LL | match slice_never {} | ^^^^^^^^^^^ @@ -367,7 +367,7 @@ LL + } | error[E0004]: non-exhaustive patterns: `&[_, ..]` not covered - --> $DIR/empty-types.rs:327:11 + --> $DIR/empty-types.rs:329:11 | LL | match slice_never { | ^^^^^^^^^^^ pattern `&[_, ..]` not covered @@ -380,7 +380,7 @@ LL + &[_, ..] => todo!() | error[E0004]: non-exhaustive patterns: `&[]`, `&[_]` and `&[_, _]` not covered - --> $DIR/empty-types.rs:336:11 + --> $DIR/empty-types.rs:338:11 | LL | match slice_never { | ^^^^^^^^^^^ patterns `&[]`, `&[_]` and `&[_, _]` not covered @@ -393,7 +393,7 @@ LL + &[] | &[_] | &[_, _] => todo!() | error[E0004]: non-exhaustive patterns: `&[]` and `&[_, ..]` not covered - --> $DIR/empty-types.rs:349:11 + --> $DIR/empty-types.rs:352:11 | LL | match slice_never { | ^^^^^^^^^^^ patterns `&[]` and `&[_, ..]` not covered @@ -407,7 +407,7 @@ LL + &[] | &[_, ..] => todo!() | error[E0004]: non-exhaustive patterns: type `[!]` is non-empty - --> $DIR/empty-types.rs:355:11 + --> $DIR/empty-types.rs:359:11 | LL | match *slice_never {} | ^^^^^^^^^^^^ @@ -421,7 +421,7 @@ LL + } | error[E0004]: non-exhaustive patterns: type `[!; 3]` is non-empty - --> $DIR/empty-types.rs:362:11 + --> $DIR/empty-types.rs:366:11 | LL | match array_3_never {} | ^^^^^^^^^^^^^ @@ -435,7 +435,7 @@ LL + } | error[E0004]: non-exhaustive patterns: type `[!; 0]` is non-empty - --> $DIR/empty-types.rs:385:11 + --> $DIR/empty-types.rs:389:11 | LL | match array_0_never {} | ^^^^^^^^^^^^^ @@ -449,13 +449,13 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:392:9 + --> $DIR/empty-types.rs:396:9 | LL | _ => {} | ^ error[E0004]: non-exhaustive patterns: `[]` not covered - --> $DIR/empty-types.rs:394:11 + --> $DIR/empty-types.rs:398:11 | LL | match array_0_never { | ^^^^^^^^^^^^^ pattern `[]` not covered @@ -469,7 +469,7 @@ LL + [] => todo!() | error[E0004]: non-exhaustive patterns: `&Some(_)` not covered - --> $DIR/empty-types.rs:448:11 + --> $DIR/empty-types.rs:452:11 | LL | match ref_opt_never { | ^^^^^^^^^^^^^ pattern `&Some(_)` not covered @@ -487,7 +487,7 @@ LL + &Some(_) => todo!() | error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:489:11 + --> $DIR/empty-types.rs:493:11 | LL | match *ref_opt_never { | ^^^^^^^^^^^^^^ pattern `Some(_)` not covered @@ -505,7 +505,7 @@ LL + Some(_) => todo!() | error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:537:11 + --> $DIR/empty-types.rs:541:11 | LL | match *ref_res_never { | ^^^^^^^^^^^^^^ pattern `Err(_)` not covered @@ -523,7 +523,7 @@ LL + Err(_) => todo!() | error[E0004]: non-exhaustive patterns: `Err(_)` not covered - --> $DIR/empty-types.rs:548:11 + --> $DIR/empty-types.rs:552:11 | LL | match *ref_res_never { | ^^^^^^^^^^^^^^ pattern `Err(_)` not covered @@ -541,7 +541,7 @@ LL + Err(_) => todo!() | error[E0004]: non-exhaustive patterns: type `(u32, !)` is non-empty - --> $DIR/empty-types.rs:567:11 + --> $DIR/empty-types.rs:571:11 | LL | match *ref_tuple_half_never {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -555,31 +555,31 @@ LL + } | error: unreachable pattern - --> $DIR/empty-types.rs:600:9 + --> $DIR/empty-types.rs:604:9 | LL | _ => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:603:9 + --> $DIR/empty-types.rs:607:9 | LL | _x => {} | ^^ error: unreachable pattern - --> $DIR/empty-types.rs:606:9 + --> $DIR/empty-types.rs:610:9 | LL | _ if false => {} | ^ error: unreachable pattern - --> $DIR/empty-types.rs:609:9 + --> $DIR/empty-types.rs:613:9 | LL | _x if false => {} | ^^ error[E0004]: non-exhaustive patterns: `&_` not covered - --> $DIR/empty-types.rs:634:11 + --> $DIR/empty-types.rs:638:11 | LL | match ref_never { | ^^^^^^^^^ pattern `&_` not covered @@ -593,8 +593,26 @@ LL ~ &_a if false => {}, LL + &_ => todo!() | +error[E0004]: non-exhaustive patterns: `Ok(_)` not covered + --> $DIR/empty-types.rs:654:11 + | +LL | match *ref_result_never { + | ^^^^^^^^^^^^^^^^^ pattern `Ok(_)` not covered + | +note: `Result<!, !>` defined here + --> $SRC_DIR/core/src/result.rs:LL:COL + ::: $SRC_DIR/core/src/result.rs:LL:COL + | + = note: not covered + = note: the matched value is of type `Result<!, !>` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ Err(_) => {}, +LL + Ok(_) => todo!() + | + error[E0004]: non-exhaustive patterns: `Some(_)` not covered - --> $DIR/empty-types.rs:662:11 + --> $DIR/empty-types.rs:674:11 | LL | match *x { | ^^ pattern `Some(_)` not covered @@ -611,7 +629,7 @@ LL ~ None => {}, LL + Some(_) => todo!() | -error: aborting due to 48 previous errors +error: aborting due to 49 previous errors Some errors have detailed explanations: E0004, E0005. For more information about an error, try `rustc --explain E0004`. diff --git a/tests/ui/pattern/usefulness/empty-types.rs b/tests/ui/pattern/usefulness/empty-types.rs index 06651613010..cc71f67831d 100644 --- a/tests/ui/pattern/usefulness/empty-types.rs +++ b/tests/ui/pattern/usefulness/empty-types.rs @@ -1,4 +1,4 @@ -//@ revisions: normal min_exh_pats exhaustive_patterns +//@ revisions: normal min_exh_pats exhaustive_patterns never_pats // gate-test-min_exhaustive_patterns // // This tests correct handling of empty types in exhaustiveness checking. @@ -11,6 +11,8 @@ #![feature(never_type_fallback)] #![cfg_attr(exhaustive_patterns, feature(exhaustive_patterns))] #![cfg_attr(min_exh_pats, feature(min_exhaustive_patterns))] +#![cfg_attr(never_pats, feature(never_patterns))] +//[never_pats]~^ WARN the feature `never_patterns` is incomplete #![allow(dead_code, unreachable_code)] #![deny(unreachable_patterns)] @@ -66,14 +68,14 @@ fn basic(x: NeverBundle) { let tuple_half_never: (u32, !) = x.tuple_half_never; match tuple_half_never {} - //[normal]~^ ERROR non-empty + //[normal,never_pats]~^ ERROR non-empty match tuple_half_never { (_, _) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } let tuple_never: (!, !) = x.tuple_never; match tuple_never {} - //[normal]~^ ERROR non-empty + //[normal,never_pats]~^ ERROR non-empty match tuple_never { _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } @@ -89,7 +91,7 @@ fn basic(x: NeverBundle) { match res_u32_never {} //~^ ERROR non-exhaustive match res_u32_never { - //[normal]~^ ERROR non-exhaustive + //[normal,never_pats]~^ ERROR non-exhaustive Ok(_) => {} } match res_u32_never { @@ -102,22 +104,22 @@ fn basic(x: NeverBundle) { Err(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } let Ok(_x) = res_u32_never; - //[normal]~^ ERROR refutable + //[normal,never_pats]~^ ERROR refutable let Ok(_x) = res_u32_never.as_ref(); //~^ ERROR refutable // Non-obvious difference: here there's an implicit dereference in the patterns, which makes the // inner place !known_valid. `exhaustive_patterns` ignores this. let Ok(_x) = &res_u32_never; - //[normal,min_exh_pats]~^ ERROR refutable + //[normal,min_exh_pats,never_pats]~^ ERROR refutable let result_never: Result<!, !> = x.result_never; match result_never {} - //[normal]~^ ERROR non-exhaustive + //[normal,never_pats]~^ ERROR non-exhaustive match result_never { _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match result_never { - //[normal]~^ ERROR non-exhaustive + //[normal,never_pats]~^ ERROR non-exhaustive Ok(_) => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } match result_never { @@ -142,7 +144,7 @@ fn void_same_as_never(x: NeverBundle) { } let opt_void: Option<Void> = None; match opt_void { - //[normal]~^ ERROR non-exhaustive + //[normal,never_pats]~^ ERROR non-exhaustive None => {} } match opt_void { @@ -161,7 +163,7 @@ fn void_same_as_never(x: NeverBundle) { } let ref_opt_void: &Option<Void> = &None; match *ref_opt_void { - //[normal,min_exh_pats]~^ ERROR non-exhaustive + //[normal,min_exh_pats,never_pats]~^ ERROR non-exhaustive None => {} } match *ref_opt_void { @@ -311,13 +313,13 @@ fn invalid_empty_match(bundle: NeverBundle) { match *x {} let x: &(u32, !) = &bundle.tuple_half_never; - match *x {} //[normal,min_exh_pats]~ ERROR non-exhaustive + match *x {} //[normal,min_exh_pats,never_pats]~ ERROR non-exhaustive let x: &(!, !) = &bundle.tuple_never; - match *x {} //[normal,min_exh_pats]~ ERROR non-exhaustive + match *x {} //[normal,min_exh_pats,never_pats]~ ERROR non-exhaustive let x: &Result<!, !> = &bundle.result_never; - match *x {} //[normal,min_exh_pats]~ ERROR non-exhaustive + match *x {} //[normal,min_exh_pats,never_pats]~ ERROR non-exhaustive let x: &[!; 3] = &bundle.array_3_never; - match *x {} //[normal,min_exh_pats]~ ERROR non-exhaustive + match *x {} //[normal,min_exh_pats,never_pats]~ ERROR non-exhaustive } fn arrays_and_slices(x: NeverBundle) { @@ -325,7 +327,7 @@ fn arrays_and_slices(x: NeverBundle) { match slice_never {} //~^ ERROR non-empty match slice_never { - //[normal,min_exh_pats]~^ ERROR not covered + //[normal,min_exh_pats,never_pats]~^ ERROR not covered [] => {} } match slice_never { @@ -336,6 +338,7 @@ fn arrays_and_slices(x: NeverBundle) { match slice_never { //[normal,min_exh_pats]~^ ERROR `&[]`, `&[_]` and `&[_, _]` not covered //[exhaustive_patterns]~^^ ERROR `&[]` not covered + //[never_pats]~^^^ ERROR `&[]`, `&[!]` and `&[!, !]` not covered [_, _, _, ..] => {} } match slice_never { @@ -349,6 +352,7 @@ fn arrays_and_slices(x: NeverBundle) { match slice_never { //[normal,min_exh_pats]~^ ERROR `&[]` and `&[_, ..]` not covered //[exhaustive_patterns]~^^ ERROR `&[]` not covered + //[never_pats]~^^^ ERROR `&[]` and `&[!, ..]` not covered &[..] if false => {} } @@ -360,7 +364,7 @@ fn arrays_and_slices(x: NeverBundle) { let array_3_never: [!; 3] = x.array_3_never; match array_3_never {} - //[normal]~^ ERROR non-empty + //[normal,never_pats]~^ ERROR non-empty match array_3_never { _ => {} //[exhaustive_patterns,min_exh_pats]~ ERROR unreachable pattern } @@ -446,7 +450,7 @@ fn bindings(x: NeverBundle) { &_a => {} } match ref_opt_never { - //[normal,min_exh_pats]~^ ERROR non-exhaustive + //[normal,min_exh_pats,never_pats]~^ ERROR non-exhaustive &None => {} } match ref_opt_never { @@ -487,7 +491,7 @@ fn bindings(x: NeverBundle) { ref _a => {} } match *ref_opt_never { - //[normal,min_exh_pats]~^ ERROR non-exhaustive + //[normal,min_exh_pats,never_pats]~^ ERROR non-exhaustive None => {} } match *ref_opt_never { @@ -535,7 +539,7 @@ fn bindings(x: NeverBundle) { let ref_res_never: &Result<!, !> = &x.result_never; match *ref_res_never { - //[normal,min_exh_pats]~^ ERROR non-exhaustive + //[normal,min_exh_pats,never_pats]~^ ERROR non-exhaustive // useful, reachable Ok(_) => {} } @@ -546,7 +550,7 @@ fn bindings(x: NeverBundle) { _ => {} } match *ref_res_never { - //[normal,min_exh_pats]~^ ERROR non-exhaustive + //[normal,min_exh_pats,never_pats]~^ ERROR non-exhaustive // useful, !reachable Ok(_a) => {} } @@ -565,7 +569,7 @@ fn bindings(x: NeverBundle) { let ref_tuple_half_never: &(u32, !) = &x.tuple_half_never; match *ref_tuple_half_never {} - //[normal,min_exh_pats]~^ ERROR non-empty + //[normal,min_exh_pats,never_pats]~^ ERROR non-empty match *ref_tuple_half_never { // useful, reachable (_, _) => {} @@ -632,7 +636,7 @@ fn guards_and_validity(x: NeverBundle) { _a if false => {} } match ref_never { - //[normal,min_exh_pats]~^ ERROR non-exhaustive + //[normal,min_exh_pats,never_pats]~^ ERROR non-exhaustive // useful, !reachable &_a if false => {} } @@ -647,6 +651,14 @@ fn guards_and_validity(x: NeverBundle) { // useful, !reachable Err(_) => {} } + match *ref_result_never { + //[normal,min_exh_pats]~^ ERROR `Ok(_)` not covered + //[never_pats]~^^ ERROR `Ok(!)` not covered + // useful, reachable + Ok(_) if false => {} + // useful, reachable + Err(_) => {} + } let ref_tuple_never: &(!, !) = &x.tuple_never; match *ref_tuple_never { // useful, !reachable @@ -661,6 +673,7 @@ fn diagnostics_subtlety(x: NeverBundle) { let x: &Option<Result<!, !>> = &None; match *x { //[normal,min_exh_pats]~^ ERROR `Some(_)` not covered + //[never_pats]~^^ ERROR `Some(!)` not covered None => {} } } diff --git a/tests/ui/print_type_sizes/niche-filling.stdout b/tests/ui/print_type_sizes/niche-filling.stdout index 53a58ccc4ee..eeb5de53241 100644 --- a/tests/ui/print_type_sizes/niche-filling.stdout +++ b/tests/ui/print_type_sizes/niche-filling.stdout @@ -68,6 +68,8 @@ print-type-size type: `Union2<std::num::NonZero<u32>, u32>`: 4 bytes, alignment: print-type-size variant `Union2`: 4 bytes print-type-size field `.a`: 4 bytes print-type-size field `.b`: 4 bytes, offset: 0 bytes, alignment: 4 bytes +print-type-size type: `core::num::nonzero::private::NonZeroU32Inner`: 4 bytes, alignment: 4 bytes +print-type-size field `.0`: 4 bytes print-type-size type: `std::num::NonZero<u32>`: 4 bytes, alignment: 4 bytes print-type-size field `.0`: 4 bytes print-type-size type: `std::option::Option<std::num::NonZero<u32>>`: 4 bytes, alignment: 4 bytes diff --git a/tests/ui/privacy/effective_visibilities_invariants.stderr b/tests/ui/privacy/effective_visibilities_invariants.stderr index fd205f4058a..1c19afdcdba 100644 --- a/tests/ui/privacy/effective_visibilities_invariants.stderr +++ b/tests/ui/privacy/effective_visibilities_invariants.stderr @@ -15,7 +15,6 @@ error: module has missing stability attribute LL | / #![feature(staged_api)] LL | | LL | | pub mod m {} -LL | | ... | LL | | LL | | fn main() {} diff --git a/tests/ui/raw-ref-op/raw-ref-temp.stderr b/tests/ui/raw-ref-op/raw-ref-temp.stderr index b9666162517..1f6d85e4a7e 100644 --- a/tests/ui/raw-ref-op/raw-ref-temp.stderr +++ b/tests/ui/raw-ref-op/raw-ref-temp.stderr @@ -75,24 +75,32 @@ error[E0745]: cannot take address of a temporary | LL | let ref_ascribe = &raw const type_ascribe!(2, i32); | ^^^^^^^^^^^^^^^^^^^^^ temporary value + | + = note: this error originates in the macro `type_ascribe` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0745]: cannot take address of a temporary --> $DIR/raw-ref-temp.rs:27:36 | LL | let mut_ref_ascribe = &raw mut type_ascribe!(3, i32); | ^^^^^^^^^^^^^^^^^^^^^ temporary value + | + = note: this error originates in the macro `type_ascribe` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0745]: cannot take address of a temporary --> $DIR/raw-ref-temp.rs:29:40 | LL | let ascribe_field_ref = &raw const type_ascribe!(PAIR.0, i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value + | + = note: this error originates in the macro `type_ascribe` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0745]: cannot take address of a temporary --> $DIR/raw-ref-temp.rs:30:38 | LL | let ascribe_index_ref = &raw mut type_ascribe!(ARRAY[0], i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value + | + = note: this error originates in the macro `type_ascribe` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 16 previous errors diff --git a/tests/ui/reachable/expr_type.stderr b/tests/ui/reachable/expr_type.stderr index 70536326fd8..008b867e230 100644 --- a/tests/ui/reachable/expr_type.stderr +++ b/tests/ui/reachable/expr_type.stderr @@ -12,6 +12,7 @@ note: the lint level is defined here | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ + = note: this error originates in the macro `type_ascribe` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error diff --git a/tests/ui/resolve/conflicting-primitive-names.rs b/tests/ui/resolve/conflicting-primitive-names.rs new file mode 100644 index 00000000000..79b6990681d --- /dev/null +++ b/tests/ui/resolve/conflicting-primitive-names.rs @@ -0,0 +1,30 @@ +//@ check-pass +#![allow(non_camel_case_types)] +#![allow(unused)] + +// Ensure that primitives do not interfere with user types of similar names + +macro_rules! make_ty_mod { + ($modname:ident, $ty:tt) => { + mod $modname { + struct $ty { + a: i32, + } + + fn assignment() { + let $ty = (); + } + + fn access(a: $ty) -> i32 { + a.a + } + } + }; +} + +make_ty_mod!(check_f16, f16); +make_ty_mod!(check_f32, f32); +make_ty_mod!(check_f64, f64); +make_ty_mod!(check_f128, f128); + +fn main() {} diff --git a/tests/ui/resolve/issue-39559-2.stderr b/tests/ui/resolve/issue-39559-2.stderr index e9d8eb0835b..7f51357a56f 100644 --- a/tests/ui/resolve/issue-39559-2.stderr +++ b/tests/ui/resolve/issue-39559-2.stderr @@ -5,7 +5,10 @@ LL | let array: [usize; Dim3::dim()] | ^^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0015]: cannot call non-const fn `<Dim3 as Dim>::dim` in constants --> $DIR/issue-39559-2.rs:16:15 @@ -14,7 +17,10 @@ LL | = [0; Dim3::dim()]; | ^^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/resolve/primitive-f16-f128-shadowed.rs b/tests/ui/resolve/primitive-f16-f128-shadowed.rs new file mode 100644 index 00000000000..ed3fb44b256 --- /dev/null +++ b/tests/ui/resolve/primitive-f16-f128-shadowed.rs @@ -0,0 +1,31 @@ +//@ compile-flags: --crate-type=lib +//@ check-pass + +// Verify that gates for the `f16` and `f128` features do not apply to user types + +mod binary16 { + #[allow(non_camel_case_types)] + pub struct f16(u16); +} + +mod binary128 { + #[allow(non_camel_case_types)] + pub struct f128(u128); +} + +pub use binary128::f128; +pub use binary16::f16; + +mod private16 { + use crate::f16; + + pub trait SealedHalf {} + impl SealedHalf for f16 {} +} + +mod private128 { + use crate::f128; + + pub trait SealedQuad {} + impl SealedQuad for f128 {} +} diff --git a/tests/ui/resolve/primitive-usage.rs b/tests/ui/resolve/primitive-usage.rs new file mode 100644 index 00000000000..b00d18a4e1e --- /dev/null +++ b/tests/ui/resolve/primitive-usage.rs @@ -0,0 +1,42 @@ +//@ run-pass +#![allow(unused)] +#![feature(f128)] +#![feature(f16)] + +// Same as the feature gate tests but ensure we can use the types +mod check_f128 { + const A: f128 = 10.0; + + pub fn foo() { + let a: f128 = 100.0; + let b = 0.0f128; + bar(1.23); + } + + fn bar(a: f128) {} + + struct Bar { + a: f128, + } +} + +mod check_f16 { + const A: f16 = 10.0; + + pub fn foo() { + let a: f16 = 100.0; + let b = 0.0f16; + bar(1.23); + } + + fn bar(a: f16) {} + + struct Bar { + a: f16, + } +} + +fn main() { + check_f128::foo(); + check_f16::foo(); +} diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/check.rs b/tests/ui/rfcs/rfc-0000-never_patterns/check.rs index b6da0c20e07..0831477e749 100644 --- a/tests/ui/rfcs/rfc-0000-never_patterns/check.rs +++ b/tests/ui/rfcs/rfc-0000-never_patterns/check.rs @@ -15,12 +15,12 @@ fn no_arms_or_guards(x: Void) { //~^ ERROR a never pattern is always unreachable None => {} } - match None::<Void> { //~ ERROR: `Some(_)` not covered + match None::<Void> { //~ ERROR: `Some(!)` not covered Some(!) if true, //~^ ERROR guard on a never pattern None => {} } - match None::<Void> { //~ ERROR: `Some(_)` not covered + match None::<Void> { //~ ERROR: `Some(!)` not covered Some(!) if true => {} //~^ ERROR a never pattern is always unreachable None => {} diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr index 5497252890f..25f7343a8a8 100644 --- a/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr +++ b/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr @@ -31,11 +31,11 @@ LL | Some(never!()) => {} | this will never be executed | help: remove this expression -error[E0004]: non-exhaustive patterns: `Some(_)` not covered +error[E0004]: non-exhaustive patterns: `Some(!)` not covered --> $DIR/check.rs:18:11 | LL | match None::<Void> { - | ^^^^^^^^^^^^ pattern `Some(_)` not covered + | ^^^^^^^^^^^^ pattern `Some(!)` not covered | note: `Option<Void>` defined here --> $SRC_DIR/core/src/option.rs:LL:COL @@ -46,14 +46,14 @@ note: `Option<Void>` defined here help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, -LL + Some(_) => todo!() +LL + Some(!) | -error[E0004]: non-exhaustive patterns: `Some(_)` not covered +error[E0004]: non-exhaustive patterns: `Some(!)` not covered --> $DIR/check.rs:23:11 | LL | match None::<Void> { - | ^^^^^^^^^^^^ pattern `Some(_)` not covered + | ^^^^^^^^^^^^ pattern `Some(!)` not covered | note: `Option<Void>` defined here --> $SRC_DIR/core/src/option.rs:LL:COL @@ -64,7 +64,7 @@ note: `Option<Void>` defined here help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | LL ~ None => {}, -LL + Some(_) => todo!() +LL + Some(!) | error: aborting due to 6 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-pass.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-pass.stderr index f802841d2e4..22e8e692752 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-pass.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-pass.stderr @@ -10,7 +10,10 @@ note: impl defined here, but it is not `const` LL | impl const std::ops::Add for Int { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: cannot call non-const fn `<i32 as Plus>::plus` in constant functions --> $DIR/call-const-trait-method-pass.rs:36:7 @@ -19,7 +22,10 @@ LL | a.plus(b) | ^^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-parse-not-item.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-parse-not-item.stderr index ace2e7e46c4..12cc79f5961 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-parse-not-item.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-parse-not-item.stderr @@ -4,5 +4,13 @@ error: `~const` can only be applied to `#[const_trait]` traits LL | const fn test() -> impl ~const Fn() { | ^^^^ -error: aborting due to 1 previous error +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/const-closure-parse-not-item.rs:7:32 + | +LL | const fn test() -> impl ~const Fn() { + | ^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method-fail.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method-fail.stderr index 14c41f3e01d..151bd6facf7 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method-fail.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method-fail.stderr @@ -11,11 +11,14 @@ LL | x(()) | ^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable help: consider further restricting this bound | LL | const fn need_const_closure<T: ~const FnOnce(()) -> i32 + ~const std::ops::FnOnce<((),)>>(x: T) -> i32 { | ++++++++++++++++++++++++++++++++ +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method.stderr index 8fe11fffbf9..e2b3e352701 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method.stderr @@ -11,11 +11,14 @@ LL | x(()) | ^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable help: consider further restricting this bound | LL | const fn need_const_closure<T: ~const FnOnce(()) -> i32 + ~const std::ops::FnOnce<((),)>>(x: T) -> i32 { | ++++++++++++++++++++++++++++++++ +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closures.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closures.stderr index a225125ef53..e5a773123e9 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closures.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closures.stderr @@ -29,11 +29,14 @@ LL | f() + f() | ^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable help: consider further restricting this bound | LL | const fn answer<F: ~const Fn() -> u8 + ~const std::ops::Fn<()>>(f: &F) -> u8 { | +++++++++++++++++++++++++ +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: cannot call non-const closure in constant functions --> $DIR/const-closures.rs:24:11 @@ -42,11 +45,14 @@ LL | f() + f() | ^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable help: consider further restricting this bound | LL | const fn answer<F: ~const Fn() -> u8 + ~const std::ops::Fn<()>>(f: &F) -> u8 { | +++++++++++++++++++++++++ +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: cannot call non-const closure in constant functions --> $DIR/const-closures.rs:12:5 @@ -55,11 +61,14 @@ LL | f() * 7 | ^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable help: consider further restricting this bound | LL | F: ~const FnOnce() -> u8 + ~const std::ops::Fn<()>, | +++++++++++++++++++++++++ +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 7 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.rs index 91f1b90bdc0..51dfe29b829 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.rs @@ -3,7 +3,6 @@ #![allow(incomplete_features)] #![feature( - associated_type_bounds, const_trait_impl, effects, const_cmp, diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr index d4be71f2f46..03038eb5c84 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr @@ -1,5 +1,5 @@ error[E0277]: can't compare `()` with `()` - --> $DIR/const-impl-trait.rs:37:17 + --> $DIR/const-impl-trait.rs:36:17 | LL | assert!(cmp(&())); | --- ^^^ no implementation for `() == ()` @@ -9,13 +9,13 @@ LL | assert!(cmp(&())); = help: the trait `const PartialEq` is not implemented for `()` = help: the trait `PartialEq` is implemented for `()` note: required by a bound in `cmp` - --> $DIR/const-impl-trait.rs:14:23 + --> $DIR/const-impl-trait.rs:13:23 | LL | const fn cmp(a: &impl ~const PartialEq) -> bool { | ^^^^^^^^^^^^^^^^ required by this bound in `cmp` error[E0369]: binary operation `==` cannot be applied to type `&impl ~const PartialEq` - --> $DIR/const-impl-trait.rs:15:7 + --> $DIR/const-impl-trait.rs:14:7 | LL | a == a | - ^^ - &impl ~const PartialEq diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/cross-crate.stock.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/cross-crate.stock.stderr index ab039397edc..a0c50ac7e61 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/cross-crate.stock.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/cross-crate.stock.stderr @@ -5,7 +5,10 @@ LL | Const.func(); | ^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 1 previous error diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr index ebbe9aa2202..312818ae631 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr @@ -5,7 +5,10 @@ LL | NonConst.func(); | ^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0015]: cannot call non-const fn `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions --> $DIR/cross-crate.rs:20:11 @@ -14,7 +17,10 @@ LL | Const.func(); | ^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/ice-112822-expected-type-for-param.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/ice-112822-expected-type-for-param.rs index 7d817d09c7f..21197fcaa27 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/ice-112822-expected-type-for-param.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/ice-112822-expected-type-for-param.rs @@ -1,7 +1,9 @@ #![feature(const_trait_impl, effects)] -const fn test() -> impl ~const Fn() { //~ ERROR `~const` can only be applied to `#[const_trait]` traits - //~^ ERROR cycle detected +const fn test() -> impl ~const Fn() { + //~^ ERROR `~const` can only be applied to `#[const_trait]` traits + //~| ERROR `~const` can only be applied to `#[const_trait]` traits + //~| ERROR cycle detected const move || { //~ ERROR const closures are experimental let sl: &[u8] = b"foo"; diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/ice-112822-expected-type-for-param.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/ice-112822-expected-type-for-param.stderr index 0f6240cc03b..2f805110917 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/ice-112822-expected-type-for-param.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/ice-112822-expected-type-for-param.stderr @@ -1,5 +1,5 @@ error[E0658]: const closures are experimental - --> $DIR/ice-112822-expected-type-for-param.rs:5:5 + --> $DIR/ice-112822-expected-type-for-param.rs:7:5 | LL | const move || { | ^^^^^ @@ -14,8 +14,16 @@ error: `~const` can only be applied to `#[const_trait]` traits LL | const fn test() -> impl ~const Fn() { | ^^^^ +error: `~const` can only be applied to `#[const_trait]` traits + --> $DIR/ice-112822-expected-type-for-param.rs:3:32 + | +LL | const fn test() -> impl ~const Fn() { + | ^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0277]: can't compare `&u8` with `&u8` - --> $DIR/ice-112822-expected-type-for-param.rs:10:17 + --> $DIR/ice-112822-expected-type-for-param.rs:12:17 | LL | assert_eq!(first, &b'f'); | ^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&u8 == &u8` @@ -54,7 +62,7 @@ LL | const fn test() -> impl ~const Fn() { | ^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors Some errors have detailed explanations: E0277, E0391, E0658. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs index 1b380c989fa..281cfdaef28 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs @@ -509,17 +509,19 @@ trait StructuralPartialEq {} const fn drop<T: ~const Destruct>(_: T) {} -extern "rust-intrinsic" { - #[rustc_const_stable(feature = "const_eval_select", since = "1.0.0")] - #[rustc_safe_intrinsic] - fn const_eval_select<ARG: Tuple, F, G, RET>( - arg: ARG, - called_in_const: F, - called_at_rt: G, - ) -> RET - where - F: const FnOnce<ARG, Output = RET>, - G: FnOnce<ARG, Output = RET>; +#[rustc_const_stable(feature = "const_eval_select", since = "1.0.0")] +#[rustc_intrinsic_must_be_overridden] +#[rustc_intrinsic] +const fn const_eval_select<ARG: Tuple, F, G, RET>( + arg: ARG, + called_in_const: F, + called_at_rt: G, +) -> RET +where + F: const FnOnce<ARG, Output = RET>, + G: FnOnce<ARG, Output = RET>, +{ + loop {} } fn test_const_eval_select() { diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/generic-bound.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/generic-bound.stderr index f42fee59bf0..7905abfa40e 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/generic-bound.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/generic-bound.stderr @@ -10,7 +10,10 @@ note: impl defined here, but it is not `const` LL | impl<T> const std::ops::Add for S<T> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 1 previous error diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102985.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102985.stderr index 0fa4c8fe04c..8401d1bd4f6 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102985.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102985.stderr @@ -6,7 +6,10 @@ LL | n => n(), | = note: closures need an RFC before allowed to be called in constants = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 1 previous error diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-88155.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-88155.stderr index e5347a09598..afe1ea3b1b7 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-88155.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-88155.stderr @@ -5,7 +5,10 @@ LL | T::assoc() | ^^^^^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 1 previous error diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/match-non-const-eq.gated.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/match-non-const-eq.gated.stderr index 28254ac15a8..c7d21151661 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/match-non-const-eq.gated.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/match-non-const-eq.gated.stderr @@ -6,7 +6,10 @@ LL | "a" => (), //FIXME [gated]~ ERROR can't compare `str` with `str` in | = note: `str` cannot be compared in compile-time, and therefore cannot be used in `match`es = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 1 previous error diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/match-non-const-eq.stock.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/match-non-const-eq.stock.stderr index 5431116a1a7..0f5ecac3891 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/match-non-const-eq.stock.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/match-non-const-eq.stock.stderr @@ -6,7 +6,10 @@ LL | "a" => (), //FIXME [gated]~ ERROR can't compare `str` with `str` in | = note: `str` cannot be compared in compile-time, and therefore cannot be used in `match`es = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 1 previous error diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/non-const-op-const-closure-non-const-outer.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/non-const-op-const-closure-non-const-outer.stderr index d82a49be75e..c362a1077e3 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/non-const-op-const-closure-non-const-outer.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/non-const-op-const-closure-non-const-outer.stderr @@ -5,7 +5,10 @@ LL | (const || { (()).foo() })(); | ^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 1 previous error diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/staged-api-user-crate.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/staged-api-user-crate.stderr index 1346c4c4ae2..781191ec97c 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/staged-api-user-crate.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/staged-api-user-crate.stderr @@ -5,7 +5,10 @@ LL | Unstable::func(); | ^^^^^^^^^^^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 1 previous error diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/std-impl-gate.gated.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/std-impl-gate.gated.stderr index e51ff148339..d761fdce4bf 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/std-impl-gate.gated.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/std-impl-gate.gated.stderr @@ -11,7 +11,10 @@ LL | Default::default() | ^^^^^^^^^^^^^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 2 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/std-impl-gate.stock.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/std-impl-gate.stock.stderr index 6d624def276..b63ea695fc2 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/std-impl-gate.stock.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/std-impl-gate.stock.stderr @@ -5,7 +5,10 @@ LL | Default::default() | ^^^^^^^^^^^^^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error: aborting due to 1 previous error diff --git a/tests/ui/sanitizer/cfi-closure-fn-ptr-cast.rs b/tests/ui/sanitizer/cfi-closure-fn-ptr-cast.rs new file mode 100644 index 00000000000..a46a3afd734 --- /dev/null +++ b/tests/ui/sanitizer/cfi-closure-fn-ptr-cast.rs @@ -0,0 +1,18 @@ +// Tests that converting a closure to a function pointer works +// The notable thing being tested here is that when the closure does not capture anything, +// the call method from its Fn trait takes a ZST representing its environment. The compiler then +// uses the assumption that the ZST is non-passed to reify this into a function pointer. +// +// This checks that the reified function pointer will have the expected alias set at its call-site. + +//@ needs-sanitizer-cfi +// FIXME(#122848) Remove only-linux once OSX CFI binaries work +//@ only-linux +//@ compile-flags: --crate-type=bin -Cprefer-dynamic=off -Clto -Zsanitizer=cfi +//@ compile-flags: -C target-feature=-crt-static -C codegen-units=1 -C opt-level=0 +//@ run-pass + +pub fn main() { + let f: &fn() = &((|| ()) as _); + f(); +} diff --git a/tests/ui/sized/expr-type-error-plus-sized-obligation.rs b/tests/ui/sized/expr-type-error-plus-sized-obligation.rs new file mode 100644 index 00000000000..a96beeecab9 --- /dev/null +++ b/tests/ui/sized/expr-type-error-plus-sized-obligation.rs @@ -0,0 +1,22 @@ +#![allow(warnings)] + +fn issue_117846_repro() { + let (a, _) = if true { + produce() + } else { + (Vec::new(), &[]) //~ ERROR E0308 + }; + + accept(&a); +} + +struct Foo; +struct Bar; + +fn produce() -> (Vec<Foo>, &'static [Bar]) { + todo!() +} + +fn accept(c: &[Foo]) {} + +fn main() {} diff --git a/tests/ui/sized/expr-type-error-plus-sized-obligation.stderr b/tests/ui/sized/expr-type-error-plus-sized-obligation.stderr new file mode 100644 index 00000000000..9cf477fbd41 --- /dev/null +++ b/tests/ui/sized/expr-type-error-plus-sized-obligation.stderr @@ -0,0 +1,19 @@ +error[E0308]: `if` and `else` have incompatible types + --> $DIR/expr-type-error-plus-sized-obligation.rs:7:9 + | +LL | let (a, _) = if true { + | __________________- +LL | | produce() + | | --------- expected because of this +LL | | } else { +LL | | (Vec::new(), &[]) + | | ^^^^^^^^^^^^^^^^^ expected `(Vec<Foo>, &[Bar])`, found `(Vec<_>, &[_; 0])` +LL | | }; + | |_____- `if` and `else` have incompatible types + | + = note: expected tuple `(Vec<Foo>, &[Bar])` + found tuple `(Vec<_>, &[_; 0])` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/specialization/const_trait_impl.stderr b/tests/ui/specialization/const_trait_impl.stderr index 187049e623c..fc02f6f8f74 100644 --- a/tests/ui/specialization/const_trait_impl.stderr +++ b/tests/ui/specialization/const_trait_impl.stderr @@ -23,7 +23,10 @@ LL | const _: () = assert!(<()>::a() == 42); | ^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: cannot call non-const fn `<u8 as A>::a` in constants --> $DIR/const_trait_impl.rs:53:23 @@ -32,7 +35,10 @@ LL | const _: () = assert!(<u8>::a() == 3); | ^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error[E0015]: cannot call non-const fn `<u16 as A>::a` in constants --> $DIR/const_trait_impl.rs:54:23 @@ -41,7 +47,10 @@ LL | const _: () = assert!(<u16>::a() == 2); | ^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable +help: add `#![feature(effects)]` to the crate attributes to enable + | +LL + #![feature(effects)] + | error: aborting due to 6 previous errors diff --git a/tests/ui/specialization/defaultimpl/validation.stderr b/tests/ui/specialization/defaultimpl/validation.stderr index 5f62e8dce17..f56f16162a2 100644 --- a/tests/ui/specialization/defaultimpl/validation.stderr +++ b/tests/ui/specialization/defaultimpl/validation.stderr @@ -35,7 +35,10 @@ LL | default unsafe impl Send for S {} = help: the trait `Send` is not implemented for `S` = help: the trait `Send` is implemented for `S` = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error: impls of auto traits cannot be default --> $DIR/validation.rs:11:15 diff --git a/tests/ui/stable-mir-print/basic_function.rs b/tests/ui/stable-mir-print/basic_function.rs index 9b27a56dab1..deefef63bdb 100644 --- a/tests/ui/stable-mir-print/basic_function.rs +++ b/tests/ui/stable-mir-print/basic_function.rs @@ -2,7 +2,7 @@ //@ check-pass //@ only-x86_64 -fn foo(i:i32) -> i32 { +fn foo(i: i32) -> i32 { i + 1 } @@ -12,4 +12,13 @@ fn bar(vec: &mut Vec<i32>) -> Vec<i32> { new_vec } -fn main(){} +pub fn demux(input: u8) -> u8 { + match input { + 0 => 10, + 1 => 6, + 2 => 8, + _ => 0, + } +} + +fn main() {} diff --git a/tests/ui/stable-mir-print/basic_function.stdout b/tests/ui/stable-mir-print/basic_function.stdout index d9b33a4257c..3926c1048f5 100644 --- a/tests/ui/stable-mir-print/basic_function.stdout +++ b/tests/ui/stable-mir-print/basic_function.stdout @@ -1,234 +1,74 @@ // WARNING: This is highly experimental output it's intended for stable-mir developers only. // If you find a bug or want to improve the output open a issue at https://github.com/rust-lang/project-stable-mir. -fn foo(_0: i32) -> i32 { - let mut _0: (i32, bool); +fn foo(_1: i32) -> i32 { + let mut _0: i32; + let mut _2: (i32, bool); + debug i => _1; + bb0: { + _2 = CheckedAdd(_1, 1_i32); + assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", _1, 1_i32) -> [success: bb1, unwind continue]; + } + bb1: { + _0 = move (_2.0: i32); + return; + } } +fn bar(_1: &mut Vec<i32>) -> Vec<i32> { + let mut _0: Vec<i32>; + let mut _2: Vec<i32>; + let mut _3: &Vec<i32>; + let _4: (); + let mut _5: &mut Vec<i32>; + debug vec => _1; + debug new_vec => _2; bb0: { - _2 = 1 Add const 1_i32 - assert(!move _2 bool),"attempt to compute `{} + {}`, which would overflow", 1, const 1_i32) -> [success: bb1, unwind continue] + _3 = &(*_1); + _2 = <Vec<i32> as Clone>::clone(move _3) -> [return: bb1, unwind continue]; } bb1: { - _0 = move _2 - return + _5 = &mut _2; + _4 = Vec::<i32>::push(move _5, 1_i32) -> [return: bb2, unwind: bb3]; + } + bb2: { + _0 = move _2; + return; + } + bb3: { + drop(_2) -> [return: bb4, unwind terminate]; + } + bb4: { + resume; } -fn bar(_0: &mut Ty { - id: 10, - kind: RigidTy( - Adt( - AdtDef( - DefId { - id: 3, - name: "std::vec::Vec", - }, - ), - GenericArgs( - [ - Type( - Ty { - id: 11, - kind: Param( - ParamTy { - index: 0, - name: "T", - }, - ), - }, - ), - Type( - Ty { - id: 12, - kind: Param( - ParamTy { - index: 1, - name: "A", - }, - ), - }, - ), - ], - ), - ), - ), -}) -> Ty { - id: 10, - kind: RigidTy( - Adt( - AdtDef( - DefId { - id: 3, - name: "std::vec::Vec", - }, - ), - GenericArgs( - [ - Type( - Ty { - id: 11, - kind: Param( - ParamTy { - index: 0, - name: "T", - }, - ), - }, - ), - Type( - Ty { - id: 12, - kind: Param( - ParamTy { - index: 1, - name: "A", - }, - ), - }, - ), - ], - ), - ), - ), -} { - let mut _0: Ty { - id: 10, - kind: RigidTy( - Adt( - AdtDef( - DefId { - id: 3, - name: "std::vec::Vec", - }, - ), - GenericArgs( - [ - Type( - Ty { - id: 11, - kind: Param( - ParamTy { - index: 0, - name: "T", - }, - ), - }, - ), - Type( - Ty { - id: 12, - kind: Param( - ParamTy { - index: 1, - name: "A", - }, - ), - }, - ), - ], - ), - ), - ), -}; - let mut _1: &Ty { - id: 10, - kind: RigidTy( - Adt( - AdtDef( - DefId { - id: 3, - name: "std::vec::Vec", - }, - ), - GenericArgs( - [ - Type( - Ty { - id: 11, - kind: Param( - ParamTy { - index: 0, - name: "T", - }, - ), - }, - ), - Type( - Ty { - id: 12, - kind: Param( - ParamTy { - index: 1, - name: "A", - }, - ), - }, - ), - ], - ), - ), - ), -}; - let _2: (); - let mut _3: &mut Ty { - id: 10, - kind: RigidTy( - Adt( - AdtDef( - DefId { - id: 3, - name: "std::vec::Vec", - }, - ), - GenericArgs( - [ - Type( - Ty { - id: 11, - kind: Param( - ParamTy { - index: 0, - name: "T", - }, - ), - }, - ), - Type( - Ty { - id: 12, - kind: Param( - ParamTy { - index: 1, - name: "A", - }, - ), - }, - ), - ], - ), - ), - ), -}; } +fn demux(_1: u8) -> u8 { + let mut _0: u8; + debug input => _1; bb0: { - _3 = refShared1 - _2 = const <Vec<i32> as Clone>::clone(move _3) -> [return: bb1, unwind continue] + switchInt(_1) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1]; } bb1: { - _5 = refMut { - kind: TwoPhaseBorrow, -}2 - _4 = const Vec::<i32>::push(move _5, const 1_i32) -> [return: bb2, unwind: bb3] + _0 = 0_u8; + goto -> bb5; } bb2: { - _0 = move _2 - return + _0 = 10_u8; + goto -> bb5; } bb3: { - drop(_2) -> [return: bb4, unwind terminate] + _0 = 6_u8; + goto -> bb5; } bb4: { - resume + _0 = 8_u8; + goto -> bb5; + } + bb5: { + return; } -fn main() -> () { } +fn main() -> () { + let mut _0: (); bb0: { - return + return; } +} diff --git a/tests/ui/suggestions/issue-85347.rs b/tests/ui/suggestions/issue-85347.rs index 04d4c47d8e5..d14cf07d915 100644 --- a/tests/ui/suggestions/issue-85347.rs +++ b/tests/ui/suggestions/issue-85347.rs @@ -4,6 +4,9 @@ trait Foo { //~^ ERROR associated type takes 1 lifetime argument but 0 lifetime arguments were supplied //~| ERROR associated type bindings are not allowed here //~| HELP add missing + //~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments were supplied + //~| ERROR associated type bindings are not allowed here + //~| HELP add missing } fn main() {} diff --git a/tests/ui/suggestions/issue-85347.stderr b/tests/ui/suggestions/issue-85347.stderr index f330b3c1fad..45f87e539b4 100644 --- a/tests/ui/suggestions/issue-85347.stderr +++ b/tests/ui/suggestions/issue-85347.stderr @@ -20,7 +20,32 @@ error[E0229]: associated type bindings are not allowed here LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>; | ^^^^^^^^^^^^^ associated type not allowed here -error: aborting due to 2 previous errors +error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied + --> $DIR/issue-85347.rs:3:42 + | +LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>; + | ^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-85347.rs:3:10 + | +LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>; + | ^^^ -- + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: add missing lifetime argument + | +LL | type Bar<'a>: Deref<Target = <Self>::Bar<'a, Target = Self>>; + | +++ + +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-85347.rs:3:46 + | +LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>; + | ^^^^^^^^^^^^^ associated type not allowed here + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 4 previous errors Some errors have detailed explanations: E0107, E0229. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/suggestions/issue-86667.rs b/tests/ui/suggestions/issue-86667.rs index 8c18a879238..1f37e9a5f6d 100644 --- a/tests/ui/suggestions/issue-86667.rs +++ b/tests/ui/suggestions/issue-86667.rs @@ -6,13 +6,11 @@ async fn a(s1: &str, s2: &str) -> &str { //~^ ERROR: missing lifetime specifier [E0106] s1 - //~^ ERROR: lifetime may not live long enough } fn b(s1: &str, s2: &str) -> &str { //~^ ERROR: missing lifetime specifier [E0106] s1 - //~^ ERROR lifetime may not live long enough } fn main() {} diff --git a/tests/ui/suggestions/issue-86667.stderr b/tests/ui/suggestions/issue-86667.stderr index e3d673ff233..14dbbfffb0e 100644 --- a/tests/ui/suggestions/issue-86667.stderr +++ b/tests/ui/suggestions/issue-86667.stderr @@ -11,7 +11,7 @@ LL | async fn a<'a>(s1: &'a str, s2: &'a str) -> &'a str { | ++++ ++ ++ ++ error[E0106]: missing lifetime specifier - --> $DIR/issue-86667.rs:12:29 + --> $DIR/issue-86667.rs:11:29 | LL | fn b(s1: &str, s2: &str) -> &str { | ---- ---- ^ expected named lifetime parameter @@ -22,24 +22,6 @@ help: consider introducing a named lifetime parameter LL | fn b<'a>(s1: &'a str, s2: &'a str) -> &'a str { | ++++ ++ ++ ++ -error: lifetime may not live long enough - --> $DIR/issue-86667.rs:8:5 - | -LL | async fn a(s1: &str, s2: &str) -> &str { - | - let's call the lifetime of this reference `'1` -LL | -LL | s1 - | ^^ returning this value requires that `'1` must outlive `'static` - -error: lifetime may not live long enough - --> $DIR/issue-86667.rs:14:5 - | -LL | fn b(s1: &str, s2: &str) -> &str { - | - let's call the lifetime of this reference `'1` -LL | -LL | s1 - | ^^ returning this value requires that `'1` must outlive `'static` - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0106`. diff --git a/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.rs b/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.rs new file mode 100644 index 00000000000..34afd363129 --- /dev/null +++ b/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.rs @@ -0,0 +1,12 @@ +fn main() {} + +fn foo(_src: &crate::Foo) -> Option<i32> { + todo!() +} +fn bar(src: &crate::Foo) -> impl Iterator<Item = i32> { + [0].into_iter() + //~^ ERROR hidden type for `impl Iterator<Item = i32>` captures lifetime that does not appear in bounds + .filter_map(|_| foo(src)) +} + +struct Foo<'a>(&'a str); diff --git a/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.stderr b/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.stderr new file mode 100644 index 00000000000..aeeec3aca34 --- /dev/null +++ b/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.stderr @@ -0,0 +1,20 @@ +error[E0700]: hidden type for `impl Iterator<Item = i32>` captures lifetime that does not appear in bounds + --> $DIR/explicit-lifetime-suggestion-in-proper-span-issue-121267.rs:7:5 + | +LL | fn bar(src: &crate::Foo) -> impl Iterator<Item = i32> { + | ---------- ------------------------- opaque type defined here + | | + | hidden type `FilterMap<std::slice::Iter<'static, i32>, {closure@$DIR/explicit-lifetime-suggestion-in-proper-span-issue-121267.rs:9:21: 9:24}>` captures the anonymous lifetime defined here +LL | / [0].into_iter() +LL | | +LL | | .filter_map(|_| foo(src)) + | |_________________________________^ + | +help: to declare that `impl Iterator<Item = i32>` captures `'_`, you can introduce a named lifetime parameter `'a` + | +LL | fn bar<'a>(src: &'a crate::Foo<'a>) -> impl Iterator<Item = i32> + 'a { + | ++++ ++ ++++ ++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0700`. diff --git a/tests/ui/suggestions/missing-assoc-fn.rs b/tests/ui/suggestions/missing-assoc-fn.rs index 9af8e5a939d..260d3b33e28 100644 --- a/tests/ui/suggestions/missing-assoc-fn.rs +++ b/tests/ui/suggestions/missing-assoc-fn.rs @@ -6,7 +6,7 @@ trait TraitA<A> { fn foo<T: TraitB<Item = A>>(_: T) -> Self; fn bar<T>(_: T) -> Self; fn baz<T>(_: T) -> Self where T: TraitB, <T as TraitB>::Item: Copy; - fn bat<T: TraitB<Item: Copy>>(_: T) -> Self; //~ ERROR associated type bounds are unstable + fn bat<T: TraitB<Item: Copy>>(_: T) -> Self; } struct S; diff --git a/tests/ui/suggestions/missing-assoc-fn.stderr b/tests/ui/suggestions/missing-assoc-fn.stderr index 61a5492d583..d819f7e8bd2 100644 --- a/tests/ui/suggestions/missing-assoc-fn.stderr +++ b/tests/ui/suggestions/missing-assoc-fn.stderr @@ -1,13 +1,3 @@ -error[E0658]: associated type bounds are unstable - --> $DIR/missing-assoc-fn.rs:9:22 - | -LL | fn bat<T: TraitB<Item: Copy>>(_: T) -> Self; - | ^^^^^^^^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - error[E0046]: not all trait items implemented, missing: `foo`, `bar`, `baz`, `bat` --> $DIR/missing-assoc-fn.rs:14:1 | @@ -31,7 +21,6 @@ LL | impl FromIterator<()> for X { | = help: implement the missing item: `fn from_iter<T: IntoIterator<Item = ()>>(_: T) -> Self { todo!() }` -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0046, E0658. -For more information about an error, try `rustc --explain E0046`. +For more information about this error, try `rustc --explain E0046`. diff --git a/tests/ui/suggestions/missing-lifetime-specifier.rs b/tests/ui/suggestions/missing-lifetime-specifier.rs index 3fa7f75f862..cd7fa0c1d85 100644 --- a/tests/ui/suggestions/missing-lifetime-specifier.rs +++ b/tests/ui/suggestions/missing-lifetime-specifier.rs @@ -20,31 +20,21 @@ pub union Qux<'t, 'k, I> { trait Tar<'t, 'k, I> {} thread_local! { - //~^ ERROR lifetime may not live long enough - //~| ERROR lifetime may not live long enough static a: RefCell<HashMap<i32, Vec<Vec<Foo>>>> = RefCell::new(HashMap::new()); //~^ ERROR missing lifetime specifiers //~| ERROR missing lifetime specifiers } thread_local! { - //~^ ERROR lifetime may not live long enough - //~| ERROR lifetime may not live long enough - //~| ERROR lifetime may not live long enough static b: RefCell<HashMap<i32, Vec<Vec<&Bar>>>> = RefCell::new(HashMap::new()); //~^ ERROR missing lifetime specifiers //~| ERROR missing lifetime specifiers } thread_local! { - //~^ ERROR lifetime may not live long enough - //~| ERROR lifetime may not live long enough static c: RefCell<HashMap<i32, Vec<Vec<Qux<i32>>>>> = RefCell::new(HashMap::new()); //~^ ERROR missing lifetime specifiers //~| ERROR missing lifetime specifiers } thread_local! { - //~^ ERROR lifetime may not live long enough - //~| ERROR lifetime may not live long enough - //~| ERROR lifetime may not live long enough static d: RefCell<HashMap<i32, Vec<Vec<&Tar<i32>>>>> = RefCell::new(HashMap::new()); //~^ ERROR missing lifetime specifiers //~| ERROR missing lifetime specifiers diff --git a/tests/ui/suggestions/missing-lifetime-specifier.stderr b/tests/ui/suggestions/missing-lifetime-specifier.stderr index 62eca162148..2b85cfde7b6 100644 --- a/tests/ui/suggestions/missing-lifetime-specifier.stderr +++ b/tests/ui/suggestions/missing-lifetime-specifier.stderr @@ -1,5 +1,5 @@ error[E0106]: missing lifetime specifiers - --> $DIR/missing-lifetime-specifier.rs:25:44 + --> $DIR/missing-lifetime-specifier.rs:23:44 | LL | static a: RefCell<HashMap<i32, Vec<Vec<Foo>>>> = RefCell::new(HashMap::new()); | ^^^ expected 2 lifetime parameters @@ -11,11 +11,9 @@ LL | static a: RefCell<HashMap<i32, Vec<Vec<Foo<'static, 'static>>>>> = RefC | ++++++++++++++++++ error[E0106]: missing lifetime specifiers - --> $DIR/missing-lifetime-specifier.rs:25:44 + --> $DIR/missing-lifetime-specifier.rs:23:44 | LL | / thread_local! { -LL | | -LL | | LL | | static a: RefCell<HashMap<i32, Vec<Vec<Foo>>>> = RefCell::new(HashMap::new()); | | ^^^ expected 2 lifetime parameters LL | | @@ -26,7 +24,7 @@ LL | | } = help: this function's return type contains a borrowed value, but the signature does not say which one of `init`'s 3 lifetimes it is borrowed from error[E0106]: missing lifetime specifiers - --> $DIR/missing-lifetime-specifier.rs:33:44 + --> $DIR/missing-lifetime-specifier.rs:28:44 | LL | static b: RefCell<HashMap<i32, Vec<Vec<&Bar>>>> = RefCell::new(HashMap::new()); | ^^^^ expected 2 lifetime parameters @@ -40,12 +38,9 @@ LL | static b: RefCell<HashMap<i32, Vec<Vec<&'static Bar<'static, 'static>>> | +++++++ ++++++++++++++++++ error[E0106]: missing lifetime specifiers - --> $DIR/missing-lifetime-specifier.rs:33:44 + --> $DIR/missing-lifetime-specifier.rs:28:44 | LL | / thread_local! { -LL | | -LL | | -LL | | LL | | static b: RefCell<HashMap<i32, Vec<Vec<&Bar>>>> = RefCell::new(HashMap::new()); | | ^^^^ expected 2 lifetime parameters | | | @@ -58,7 +53,7 @@ LL | | } = help: this function's return type contains a borrowed value, but the signature does not say which one of `init`'s 4 lifetimes it is borrowed from error[E0106]: missing lifetime specifiers - --> $DIR/missing-lifetime-specifier.rs:40:47 + --> $DIR/missing-lifetime-specifier.rs:33:47 | LL | static c: RefCell<HashMap<i32, Vec<Vec<Qux<i32>>>>> = RefCell::new(HashMap::new()); | ^ expected 2 lifetime parameters @@ -70,11 +65,9 @@ LL | static c: RefCell<HashMap<i32, Vec<Vec<Qux<'static, 'static, i32>>>>> = | +++++++++++++++++ error[E0106]: missing lifetime specifiers - --> $DIR/missing-lifetime-specifier.rs:40:47 + --> $DIR/missing-lifetime-specifier.rs:33:47 | LL | / thread_local! { -LL | | -LL | | LL | | static c: RefCell<HashMap<i32, Vec<Vec<Qux<i32>>>>> = RefCell::new(HashMap::new()); | | ^ expected 2 lifetime parameters LL | | @@ -85,7 +78,7 @@ LL | | } = help: this function's return type contains a borrowed value, but the signature does not say which one of `init`'s 3 lifetimes it is borrowed from error[E0106]: missing lifetime specifiers - --> $DIR/missing-lifetime-specifier.rs:48:44 + --> $DIR/missing-lifetime-specifier.rs:38:44 | LL | static d: RefCell<HashMap<i32, Vec<Vec<&Tar<i32>>>>> = RefCell::new(HashMap::new()); | ^ ^ expected 2 lifetime parameters @@ -99,12 +92,9 @@ LL | static d: RefCell<HashMap<i32, Vec<Vec<&'static Tar<'static, 'static, i | +++++++ +++++++++++++++++ error[E0106]: missing lifetime specifiers - --> $DIR/missing-lifetime-specifier.rs:48:44 + --> $DIR/missing-lifetime-specifier.rs:38:44 | LL | / thread_local! { -LL | | -LL | | -LL | | LL | | static d: RefCell<HashMap<i32, Vec<Vec<&Tar<i32>>>>> = RefCell::new(HashMap::new()); | | ^ ^ expected 2 lifetime parameters | | | @@ -117,7 +107,7 @@ LL | | } = help: this function's return type contains a borrowed value, but the signature does not say which one of `init`'s 4 lifetimes it is borrowed from error[E0106]: missing lifetime specifier - --> $DIR/missing-lifetime-specifier.rs:58:44 + --> $DIR/missing-lifetime-specifier.rs:48:44 | LL | static f: RefCell<HashMap<i32, Vec<Vec<&Tar<'static, i32>>>>> = RefCell::new(HashMap::new()); | ^ expected named lifetime parameter @@ -129,7 +119,7 @@ LL | static f: RefCell<HashMap<i32, Vec<Vec<&'static Tar<'static, i32>>>>> = | +++++++ error[E0106]: missing lifetime specifier - --> $DIR/missing-lifetime-specifier.rs:58:44 + --> $DIR/missing-lifetime-specifier.rs:48:44 | LL | / thread_local! { LL | | static f: RefCell<HashMap<i32, Vec<Vec<&Tar<'static, i32>>>>> = RefCell::new(HashMap::new()); @@ -143,7 +133,7 @@ LL | | } = help: this function's return type contains a borrowed value, but the signature does not say which one of `init`'s 3 lifetimes it is borrowed from error[E0107]: union takes 2 lifetime arguments but 1 lifetime argument was supplied - --> $DIR/missing-lifetime-specifier.rs:54:44 + --> $DIR/missing-lifetime-specifier.rs:44:44 | LL | static e: RefCell<HashMap<i32, Vec<Vec<Qux<'static, i32>>>>> = RefCell::new(HashMap::new()); | ^^^ ------- supplied 1 lifetime argument @@ -161,7 +151,7 @@ LL | static e: RefCell<HashMap<i32, Vec<Vec<Qux<'static, 'static, i32>>>>> = | +++++++++ error[E0107]: trait takes 2 lifetime arguments but 1 lifetime argument was supplied - --> $DIR/missing-lifetime-specifier.rs:58:45 + --> $DIR/missing-lifetime-specifier.rs:48:45 | LL | static f: RefCell<HashMap<i32, Vec<Vec<&Tar<'static, i32>>>>> = RefCell::new(HashMap::new()); | ^^^ ------- supplied 1 lifetime argument @@ -178,199 +168,7 @@ help: add missing lifetime argument LL | static f: RefCell<HashMap<i32, Vec<Vec<&Tar<'static, 'static, i32>>>>> = RefCell::new(HashMap::new()); | +++++++++ -error: lifetime may not live long enough - --> $DIR/missing-lifetime-specifier.rs:22:1 - | -LL | / thread_local! { -LL | | -LL | | -LL | | static a: RefCell<HashMap<i32, Vec<Vec<Foo>>>> = RefCell::new(HashMap::new()); -LL | | -LL | | -LL | | } - | | ^ - | | | - | |_has type `Option<&mut Option<RefCell<HashMap<i32, Vec<Vec<Foo<'1, '_>>>>>>>` - | returning this value requires that `'1` must outlive `'static` - | - = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: lifetime may not live long enough - --> $DIR/missing-lifetime-specifier.rs:22:1 - | -LL | / thread_local! { -LL | | -LL | | -LL | | static a: RefCell<HashMap<i32, Vec<Vec<Foo>>>> = RefCell::new(HashMap::new()); -LL | | -LL | | -LL | | } - | | ^ - | | | - | |_has type `Option<&mut Option<RefCell<HashMap<i32, Vec<Vec<Foo<'_, '2>>>>>>>` - | returning this value requires that `'2` must outlive `'static` - | - = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: lifetime may not live long enough - --> $DIR/missing-lifetime-specifier.rs:29:1 - | -LL | / thread_local! { -LL | | -LL | | -LL | | -LL | | static b: RefCell<HashMap<i32, Vec<Vec<&Bar>>>> = RefCell::new(HashMap::new()); - | | - let's call the lifetime of this reference `'1` -LL | | -LL | | -LL | | } - | |_^ returning this value requires that `'1` must outlive `'static` - | - = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info) -help: to declare that the trait object captures data from argument `init`, you can add an explicit `'_` lifetime bound - | -LL | static b: RefCell<HashMap<i32, Vec<Vec<&Bar + '_>>>> = RefCell::new(HashMap::new()); - | ++++ - -error: lifetime may not live long enough - --> $DIR/missing-lifetime-specifier.rs:29:1 - | -LL | / thread_local! { -LL | | -LL | | -LL | | -... | -LL | | -LL | | } - | | ^ - | | | - | |_has type `Option<&mut Option<RefCell<HashMap<i32, Vec<Vec<&dyn Bar<'2, '_>>>>>>>` - | returning this value requires that `'2` must outlive `'static` - | - = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info) -help: to declare that the trait object captures data from argument `init`, you can add an explicit `'_` lifetime bound - | -LL | static b: RefCell<HashMap<i32, Vec<Vec<&Bar + '_>>>> = RefCell::new(HashMap::new()); - | ++++ - -error: lifetime may not live long enough - --> $DIR/missing-lifetime-specifier.rs:29:1 - | -LL | / thread_local! { -LL | | -LL | | -LL | | -... | -LL | | -LL | | } - | | ^ - | | | - | |_has type `Option<&mut Option<RefCell<HashMap<i32, Vec<Vec<&dyn Bar<'_, '3>>>>>>>` - | returning this value requires that `'3` must outlive `'static` - | - = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info) -help: to declare that the trait object captures data from argument `init`, you can add an explicit `'_` lifetime bound - | -LL | static b: RefCell<HashMap<i32, Vec<Vec<&Bar + '_>>>> = RefCell::new(HashMap::new()); - | ++++ - -error: lifetime may not live long enough - --> $DIR/missing-lifetime-specifier.rs:37:1 - | -LL | / thread_local! { -LL | | -LL | | -LL | | static c: RefCell<HashMap<i32, Vec<Vec<Qux<i32>>>>> = RefCell::new(HashMap::new()); -LL | | -LL | | -LL | | } - | | ^ - | | | - | |_has type `Option<&mut Option<RefCell<HashMap<i32, Vec<Vec<Qux<'1, '_, i32>>>>>>>` - | returning this value requires that `'1` must outlive `'static` - | - = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: lifetime may not live long enough - --> $DIR/missing-lifetime-specifier.rs:37:1 - | -LL | / thread_local! { -LL | | -LL | | -LL | | static c: RefCell<HashMap<i32, Vec<Vec<Qux<i32>>>>> = RefCell::new(HashMap::new()); -LL | | -LL | | -LL | | } - | | ^ - | | | - | |_has type `Option<&mut Option<RefCell<HashMap<i32, Vec<Vec<Qux<'_, '2, i32>>>>>>>` - | returning this value requires that `'2` must outlive `'static` - | - = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: lifetime may not live long enough - --> $DIR/missing-lifetime-specifier.rs:44:1 - | -LL | / thread_local! { -LL | | -LL | | -LL | | -LL | | static d: RefCell<HashMap<i32, Vec<Vec<&Tar<i32>>>>> = RefCell::new(HashMap::new()); - | | - let's call the lifetime of this reference `'1` -LL | | -LL | | -LL | | } - | |_^ returning this value requires that `'1` must outlive `'static` - | - = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info) -help: to declare that the trait object captures data from argument `init`, you can add an explicit `'_` lifetime bound - | -LL | static d: RefCell<HashMap<i32, Vec<Vec<&Tar<i32> + '_>>>> = RefCell::new(HashMap::new()); - | ++++ - -error: lifetime may not live long enough - --> $DIR/missing-lifetime-specifier.rs:44:1 - | -LL | / thread_local! { -LL | | -LL | | -LL | | -... | -LL | | -LL | | } - | | ^ - | | | - | |_has type `Option<&mut Option<RefCell<HashMap<i32, Vec<Vec<&dyn Tar<'2, '_, i32>>>>>>>` - | returning this value requires that `'2` must outlive `'static` - | - = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info) -help: to declare that the trait object captures data from argument `init`, you can add an explicit `'_` lifetime bound - | -LL | static d: RefCell<HashMap<i32, Vec<Vec<&Tar<i32> + '_>>>> = RefCell::new(HashMap::new()); - | ++++ - -error: lifetime may not live long enough - --> $DIR/missing-lifetime-specifier.rs:44:1 - | -LL | / thread_local! { -LL | | -LL | | -LL | | -... | -LL | | -LL | | } - | | ^ - | | | - | |_has type `Option<&mut Option<RefCell<HashMap<i32, Vec<Vec<&dyn Tar<'_, '3, i32>>>>>>>` - | returning this value requires that `'3` must outlive `'static` - | - = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info) -help: to declare that the trait object captures data from argument `init`, you can add an explicit `'_` lifetime bound - | -LL | static d: RefCell<HashMap<i32, Vec<Vec<&Tar<i32> + '_>>>> = RefCell::new(HashMap::new()); - | ++++ - -error: aborting due to 22 previous errors +error: aborting due to 12 previous errors Some errors have detailed explanations: E0106, E0107. For more information about an error, try `rustc --explain E0106`. diff --git a/tests/ui/suggestions/ref-pattern-binding.stderr b/tests/ui/suggestions/ref-pattern-binding.stderr index 69ce5d440af..af21c6aef70 100644 --- a/tests/ui/suggestions/ref-pattern-binding.stderr +++ b/tests/ui/suggestions/ref-pattern-binding.stderr @@ -5,7 +5,7 @@ LL | let _moved @ ref _from = String::from("foo"); | ^^^^^^ --------- value borrowed here after move | | | value moved into `_moved` here - | move occurs because `_moved` has type `String` which does not implement the `Copy` trait + | move occurs because `_moved` has type `String`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | @@ -35,7 +35,7 @@ LL | let _moved @ S { ref f } = S { f: String::from("foo") }; | ^^^^^^ ----- value borrowed here after move | | | value moved into `_moved` here - | move occurs because `_moved` has type `S` which does not implement the `Copy` trait + | move occurs because `_moved` has type `S`, which does not implement the `Copy` trait | help: borrow this binding in the pattern to avoid moving the value | diff --git a/tests/ui/suggestions/suppress-consider-slicing-issue-120605.rs b/tests/ui/suggestions/suppress-consider-slicing-issue-120605.rs new file mode 100644 index 00000000000..135535cd00a --- /dev/null +++ b/tests/ui/suggestions/suppress-consider-slicing-issue-120605.rs @@ -0,0 +1,20 @@ +pub struct Struct { + a: Vec<Struct>, +} + +impl Struct { + pub fn test(&self) { + if let [Struct { a: [] }] = &self.a { + //~^ ERROR expected an array or slice + //~| ERROR expected an array or slice + println!("matches!") + } + + if let [Struct { a: [] }] = &self.a[..] { + //~^ ERROR expected an array or slice + println!("matches!") + } + } +} + +fn main() {} diff --git a/tests/ui/suggestions/suppress-consider-slicing-issue-120605.stderr b/tests/ui/suggestions/suppress-consider-slicing-issue-120605.stderr new file mode 100644 index 00000000000..c28d67604da --- /dev/null +++ b/tests/ui/suggestions/suppress-consider-slicing-issue-120605.stderr @@ -0,0 +1,23 @@ +error[E0529]: expected an array or slice, found `Vec<Struct>` + --> $DIR/suppress-consider-slicing-issue-120605.rs:7:16 + | +LL | if let [Struct { a: [] }] = &self.a { + | ^^^^^^^^^^^^^^^^^^ ------- help: consider slicing here: `&self.a[..]` + | | + | pattern cannot match with input type `Vec<Struct>` + +error[E0529]: expected an array or slice, found `Vec<Struct>` + --> $DIR/suppress-consider-slicing-issue-120605.rs:7:29 + | +LL | if let [Struct { a: [] }] = &self.a { + | ^^ pattern cannot match with input type `Vec<Struct>` + +error[E0529]: expected an array or slice, found `Vec<Struct>` + --> $DIR/suppress-consider-slicing-issue-120605.rs:13:29 + | +LL | if let [Struct { a: [] }] = &self.a[..] { + | ^^ pattern cannot match with input type `Vec<Struct>` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0529`. diff --git a/tests/ui/suggestions/type-ascription-instead-of-path-in-type.rs b/tests/ui/suggestions/type-ascription-instead-of-path-in-type.rs index 48d19f6dd4e..c98eec4af01 100644 --- a/tests/ui/suggestions/type-ascription-instead-of-path-in-type.rs +++ b/tests/ui/suggestions/type-ascription-instead-of-path-in-type.rs @@ -6,8 +6,6 @@ fn main() { let _: Vec<A:B> = A::B; //~^ ERROR cannot find trait `B` in this scope //~| HELP you might have meant to write a path instead of an associated type bound - //~| ERROR associated type bounds are unstable - //~| HELP add `#![feature(associated_type_bounds)]` to the crate attributes to enable //~| ERROR struct takes at least 1 generic argument but 0 generic arguments were supplied //~| HELP add missing generic argument //~| ERROR associated type bindings are not allowed here diff --git a/tests/ui/suggestions/type-ascription-instead-of-path-in-type.stderr b/tests/ui/suggestions/type-ascription-instead-of-path-in-type.stderr index 9c22873e79c..834c141ec3e 100644 --- a/tests/ui/suggestions/type-ascription-instead-of-path-in-type.stderr +++ b/tests/ui/suggestions/type-ascription-instead-of-path-in-type.stderr @@ -9,16 +9,6 @@ help: you might have meant to write a path instead of an associated type bound LL | let _: Vec<A::B> = A::B; | ~~ -error[E0658]: associated type bounds are unstable - --> $DIR/type-ascription-instead-of-path-in-type.rs:6:16 - | -LL | let _: Vec<A:B> = A::B; - | ^^^ - | - = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information - = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - error[E0107]: struct takes at least 1 generic argument but 0 generic arguments were supplied --> $DIR/type-ascription-instead-of-path-in-type.rs:6:12 | @@ -36,7 +26,7 @@ error[E0229]: associated type bindings are not allowed here LL | let _: Vec<A:B> = A::B; | ^^^ associated type not allowed here -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0107, E0229, E0405, E0658. +Some errors have detailed explanations: E0107, E0229, E0405. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/suggestions/types/into-inference-needs-type.rs b/tests/ui/suggestions/types/into-inference-needs-type.rs new file mode 100644 index 00000000000..4c8b6ec2113 --- /dev/null +++ b/tests/ui/suggestions/types/into-inference-needs-type.rs @@ -0,0 +1,15 @@ +#[derive(Debug)] +enum MyError { + MainError +} + +fn main() -> Result<(), MyError> { + let vec = vec!["one", "two", "three"]; + let list = vec + .iter() + .map(|s| s.strip_prefix("t")) + .filter_map(Option::Some) + .into()?; //~ ERROR type annotations needed + + return Ok(()); +} diff --git a/tests/ui/suggestions/types/into-inference-needs-type.stderr b/tests/ui/suggestions/types/into-inference-needs-type.stderr new file mode 100644 index 00000000000..dd688f90289 --- /dev/null +++ b/tests/ui/suggestions/types/into-inference-needs-type.stderr @@ -0,0 +1,19 @@ +error[E0283]: type annotations needed + --> $DIR/into-inference-needs-type.rs:12:10 + | +LL | .into()?; + | ^^^^ + | + = note: cannot satisfy `_: From<FilterMap<Map<std::slice::Iter<'_, &str>, {closure@$DIR/into-inference-needs-type.rs:10:14: 10:17}>, fn(Option<&str>) -> Option<Option<&str>> {Option::<Option<&str>>::Some}>>` + = note: required for `FilterMap<Map<std::slice::Iter<'_, &str>, {closure@$DIR/into-inference-needs-type.rs:10:14: 10:17}>, fn(Option<&str>) -> Option<Option<&str>> {Option::<Option<&str>>::Some}>` to implement `Into<_>` +help: try using a fully qualified path to specify the expected types + | +LL ~ let list = <FilterMap<Map<std::slice::Iter<'_, &str>, _>, _> as Into<T>>::into(vec +LL | .iter() +LL | .map(|s| s.strip_prefix("t")) +LL ~ .filter_map(Option::Some))?; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/trait-bounds/super-assoc-mismatch.stderr b/tests/ui/trait-bounds/super-assoc-mismatch.stderr index 47535776348..f2c5eb47e59 100644 --- a/tests/ui/trait-bounds/super-assoc-mismatch.stderr +++ b/tests/ui/trait-bounds/super-assoc-mismatch.stderr @@ -78,7 +78,10 @@ help: this trait has no implementations, consider adding one LL | trait Sub: Super<Assoc = u16> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | error[E0277]: the trait bound `(): SubGeneric<u16>` is not satisfied --> $DIR/super-assoc-mismatch.rs:55:22 diff --git a/tests/ui/traits/alias/self-in-generics.rs b/tests/ui/traits/alias/self-in-generics.rs index dcb33b7a90a..433b741532d 100644 --- a/tests/ui/traits/alias/self-in-generics.rs +++ b/tests/ui/traits/alias/self-in-generics.rs @@ -1,4 +1,4 @@ -// astconv uses `FreshTy(0)` as a dummy `Self` type when instanciating trait objects. +// HIR ty lowering uses `FreshTy(0)` as a dummy `Self` type when instanciating trait objects. // This `FreshTy(0)` can leak into substs, causing ICEs in several places. #![feature(trait_alias)] diff --git a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs index 7d71fcdd158..cab484a120c 100644 --- a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs +++ b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs @@ -20,6 +20,7 @@ impl<T, S> Trait<T, S> for () {} fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> { //~^ ERROR trait takes 1 generic argument but 2 generic arguments were supplied //~| ERROR trait takes 1 generic argument but 2 generic arguments were supplied +//~| ERROR trait takes 1 generic argument but 2 generic arguments were supplied //~| ERROR type annotations needed 3 } diff --git a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr index f4ede4190fc..99e81a9039e 100644 --- a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr +++ b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr @@ -54,6 +54,23 @@ help: replace the generic bound with the associated type LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> { | +++++++ +error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied + --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:20:46 + | +LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> { + | ^^^^^ expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `T` + --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11 + | +LL | pub trait Trait<T> { + | ^^^^^ - + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: replace the generic bound with the associated type + | +LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> { + | +++++++ + error[E0282]: type annotations needed --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:20:41 | @@ -61,7 +78,7 @@ LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> { | ^^^^^^^^^^^^^^^^^^^ cannot infer type error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied - --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:27:18 + --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:28:18 | LL | struct Struct<T: Trait<u32, String>> { | ^^^^^ expected 1 generic argument @@ -77,7 +94,7 @@ LL | struct Struct<T: Trait<u32, Assoc = String>> { | +++++++ error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied - --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:32:23 + --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:33:23 | LL | trait AnotherTrait<T: Trait<T, i32>> {} | ^^^^^ expected 1 generic argument @@ -93,7 +110,7 @@ LL | trait AnotherTrait<T: Trait<T, Assoc = i32>> {} | +++++++ error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied - --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:35:9 + --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:36:9 | LL | impl<T: Trait<u32, String>> Struct<T> {} | ^^^^^ expected 1 generic argument @@ -109,7 +126,7 @@ LL | impl<T: Trait<u32, Assoc = String>> Struct<T> {} | +++++++ error[E0107]: struct takes 1 generic argument but 2 generic arguments were supplied - --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:41:58 + --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:42:58 | LL | impl<T: Trait<u32, Assoc=String>, U> YetAnotherTrait for Struct<T, U> {} | ^^^^^^ - help: remove this generic argument @@ -117,12 +134,12 @@ LL | impl<T: Trait<u32, Assoc=String>, U> YetAnotherTrait for Struct<T, U> {} | expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` - --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:27:8 + --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:28:8 | LL | struct Struct<T: Trait<u32, String>> { | ^^^^^^ - -error: aborting due to 10 previous errors +error: aborting due to 11 previous errors Some errors have detailed explanations: E0107, E0207, E0282. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr b/tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr index 092776edea7..8bf8536c74e 100644 --- a/tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr +++ b/tests/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr @@ -4,16 +4,16 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` d LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { | ^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined here... - --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:6 - | -LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { - | ^^ -note: ...but the lifetime must also be valid for the lifetime `'b` as defined here... +note: first, the lifetime cannot outlive the lifetime `'b` as defined here... --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:9 | LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { | ^^ +note: ...but the lifetime must also be valid for the lifetime `'a` as defined here... + --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:6 + | +LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { + | ^^ note: ...so that the types are compatible --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:28 | diff --git a/tests/ui/traits/matching-lifetimes.stderr b/tests/ui/traits/matching-lifetimes.stderr index f8119ed415d..8a802d57f5c 100644 --- a/tests/ui/traits/matching-lifetimes.stderr +++ b/tests/ui/traits/matching-lifetimes.stderr @@ -6,16 +6,16 @@ LL | fn foo(x: Foo<'b,'a>) { | = note: expected signature `fn(Foo<'a, 'b>)` found signature `fn(Foo<'b, 'a>)` -note: the lifetime `'b` as defined here... - --> $DIR/matching-lifetimes.rs:13:9 - | -LL | impl<'a,'b> Tr for Foo<'a,'b> { - | ^^ -note: ...does not necessarily outlive the lifetime `'a` as defined here +note: the lifetime `'a` as defined here... --> $DIR/matching-lifetimes.rs:13:6 | LL | impl<'a,'b> Tr for Foo<'a,'b> { | ^^ +note: ...does not necessarily outlive the lifetime `'b` as defined here + --> $DIR/matching-lifetimes.rs:13:9 + | +LL | impl<'a,'b> Tr for Foo<'a,'b> { + | ^^ error[E0308]: method not compatible with trait --> $DIR/matching-lifetimes.rs:14:5 @@ -25,16 +25,16 @@ LL | fn foo(x: Foo<'b,'a>) { | = note: expected signature `fn(Foo<'a, 'b>)` found signature `fn(Foo<'b, 'a>)` -note: the lifetime `'a` as defined here... - --> $DIR/matching-lifetimes.rs:13:6 - | -LL | impl<'a,'b> Tr for Foo<'a,'b> { - | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined here +note: the lifetime `'b` as defined here... --> $DIR/matching-lifetimes.rs:13:9 | LL | impl<'a,'b> Tr for Foo<'a,'b> { | ^^ +note: ...does not necessarily outlive the lifetime `'a` as defined here + --> $DIR/matching-lifetimes.rs:13:6 + | +LL | impl<'a,'b> Tr for Foo<'a,'b> { + | ^^ error: aborting due to 2 previous errors diff --git a/tests/ui/traits/negative-bounds/associated-constraints.rs b/tests/ui/traits/negative-bounds/associated-constraints.rs index 4a7132ccde9..795e68bb469 100644 --- a/tests/ui/traits/negative-bounds/associated-constraints.rs +++ b/tests/ui/traits/negative-bounds/associated-constraints.rs @@ -1,4 +1,4 @@ -#![feature(negative_bounds, associated_type_bounds)] +#![feature(negative_bounds)] trait Trait { type Assoc; diff --git a/tests/ui/traits/next-solver/coherence-fulfill-overflow.rs b/tests/ui/traits/next-solver/coherence/coherence-fulfill-overflow.rs index ff577da32c2..ff577da32c2 100644 --- a/tests/ui/traits/next-solver/coherence-fulfill-overflow.rs +++ b/tests/ui/traits/next-solver/coherence/coherence-fulfill-overflow.rs diff --git a/tests/ui/traits/next-solver/coherence-fulfill-overflow.stderr b/tests/ui/traits/next-solver/coherence/coherence-fulfill-overflow.stderr index 57cba790b55..57cba790b55 100644 --- a/tests/ui/traits/next-solver/coherence-fulfill-overflow.stderr +++ b/tests/ui/traits/next-solver/coherence/coherence-fulfill-overflow.stderr diff --git a/tests/ui/traits/next-solver/negative-coherence-bounds.rs b/tests/ui/traits/next-solver/coherence/negative-coherence-bounds.rs index d98cd1147ef..d98cd1147ef 100644 --- a/tests/ui/traits/next-solver/negative-coherence-bounds.rs +++ b/tests/ui/traits/next-solver/coherence/negative-coherence-bounds.rs diff --git a/tests/ui/traits/next-solver/negative-coherence-bounds.stderr b/tests/ui/traits/next-solver/coherence/negative-coherence-bounds.stderr index 4127f51f56d..4127f51f56d 100644 --- a/tests/ui/traits/next-solver/negative-coherence-bounds.stderr +++ b/tests/ui/traits/next-solver/coherence/negative-coherence-bounds.stderr diff --git a/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr index 39d453e8035..1d42dbdfe00 100644 --- a/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr +++ b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr @@ -4,7 +4,6 @@ error[E0275]: overflow evaluating the requirement `<T as Overflow>::Assoc: Sized LL | type Assoc = <T as Overflow>::Assoc; | ^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`trait_ref_is_knowable_norm_overflow`) note: required by a bound in `Overflow::Assoc` --> $DIR/trait_ref_is_knowable-norm-overflow.rs:7:5 | @@ -23,9 +22,6 @@ LL | impl<T: Copy> Trait for T {} LL | struct LocalTy; LL | impl Trait for <LocalTy as Overflow>::Assoc {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation - | - = note: overflow evaluating the requirement `_ == <LocalTy as Overflow>::Assoc` - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`trait_ref_is_knowable_norm_overflow`) error: aborting due to 2 previous errors diff --git a/tests/ui/traits/next-solver/equating-projection-cyclically.rs b/tests/ui/traits/next-solver/generalize/equating-projection-cyclically.rs index 317eb65745a..317eb65745a 100644 --- a/tests/ui/traits/next-solver/equating-projection-cyclically.rs +++ b/tests/ui/traits/next-solver/generalize/equating-projection-cyclically.rs diff --git a/tests/ui/traits/next-solver/issue-118950-root-region.stderr b/tests/ui/traits/next-solver/issue-118950-root-region.stderr index 45ff9f763cd..5cb24fa19aa 100644 --- a/tests/ui/traits/next-solver/issue-118950-root-region.stderr +++ b/tests/ui/traits/next-solver/issue-118950-root-region.stderr @@ -19,10 +19,10 @@ error: the type `<*const T as ToUnit<'a>>::Unit` is not well-formed LL | type Assoc<'a, T> = <*const T as ToUnit<'a>>::Unit; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) } -WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), 'a) }), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: ['^0.Named(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), "'a"), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: ['^0.Named(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), "'a"), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: ['^0.Named(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), "'a"), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) } +WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: ['^0.Named(DefId(0:15 ~ issue_118950_root_region[d54f]::{impl#1}::'a), "'a"), ?1t], def_id: DefId(0:8 ~ issue_118950_root_region[d54f]::Assoc) } error[E0119]: conflicting implementations of trait `Overlap<fn(_)>` for type `fn(_)` --> $DIR/issue-118950-root-region.rs:19:1 | diff --git a/tests/ui/traits/next-solver/normalize/indirectly-constrained-term.rs b/tests/ui/traits/next-solver/normalize/indirectly-constrained-term.rs new file mode 100644 index 00000000000..380477c2c3c --- /dev/null +++ b/tests/ui/traits/next-solver/normalize/indirectly-constrained-term.rs @@ -0,0 +1,45 @@ +//@ revisions: current next +//@[next] compile-flags: -Znext-solver=coherence +//@ ignore-compare-mode-next-solver (explicit revisions) +//@ check-pass + +// A regression test for `paperclip-core`. This previously failed to compile +// in the new solver. +// +// Behavior in old solver: +// We prove `Projection(<W<?0> as Unconstrained>::Assoc, ())`. This +// normalizes `<W<?0> as Unconstrained>::Assoc` to `?1` with nested goals +// `[Projection(<?0 as Unconstrained>::Assoc, ?1), Trait(?1: NoImpl)]`. +// We then unify `?1` with `()`. At this point `?1: NoImpl` does not hold, +// and we get an error. +// +// Previous behavior of the new solver: +// We prove `Projection(<W<?0> as Unconstrained>::Assoc, ())`. This normalizes +// `<W<?0> as Unconstrained>::Assoc` to `?1` and eagerly computes the nested +// goals `[Projection(<?0 as Unconstrained>::Assoc, ?1), Trait(?1: NoImpl)]`. +// These goals are both ambiguous. `NormalizesTo`` then returns `?1` as the +// normalized-to type. It discards the nested goals, forcing the certainty of +// the normalization to `Maybe`. Unifying `?1` with `()` succeeds¹. However, +// this is never propagated to the `?1: NoImpl` goal, as it only exists inside +// of the `NormalizesTo` goal. The normalized-to term always starts out as +// unconstrained. +// +// We fix this regression by returning the nested goals of `NormalizesTo` goals +// to the `AliasRelate`. This results in us checking `(): NoImpl`, same as the +// old solver. + +struct W<T: ?Sized>(T); +trait NoImpl {} +trait Unconstrained { + type Assoc; +} +impl<T: Unconstrained<Assoc = U>, U: NoImpl> Unconstrained for W<T> { + type Assoc = U; +} + + +trait Overlap {} +impl<T: Unconstrained<Assoc = ()>> Overlap for T {} +impl<U> Overlap for W<U> {} + +fn main() {} diff --git a/tests/ui/traits/next-solver/two-projection-param-candidates-are-ambiguous.rs b/tests/ui/traits/next-solver/normalize/two-projection-param-candidates-are-ambiguous.rs index 40d68dbaffd..40d68dbaffd 100644 --- a/tests/ui/traits/next-solver/two-projection-param-candidates-are-ambiguous.rs +++ b/tests/ui/traits/next-solver/normalize/two-projection-param-candidates-are-ambiguous.rs diff --git a/tests/ui/traits/next-solver/two-projection-param-candidates-are-ambiguous.stderr b/tests/ui/traits/next-solver/normalize/two-projection-param-candidates-are-ambiguous.stderr index dfff9f11b87..dfff9f11b87 100644 --- a/tests/ui/traits/next-solver/two-projection-param-candidates-are-ambiguous.stderr +++ b/tests/ui/traits/next-solver/normalize/two-projection-param-candidates-are-ambiguous.stderr diff --git a/tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.stderr b/tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.stderr index 09622bb9b6c..2b0e57966fe 100644 --- a/tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.stderr +++ b/tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.stderr @@ -3,8 +3,6 @@ error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1 == _` | LL | needs_bar::<T::Assoc1>(); | ^^^^^^^^^ - | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`) error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1: Bar` --> $DIR/recursive-self-normalization-2.rs:15:17 @@ -12,7 +10,6 @@ error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1: Bar` LL | needs_bar::<T::Assoc1>(); | ^^^^^^^^^ | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`) note: required by a bound in `needs_bar` --> $DIR/recursive-self-normalization-2.rs:12:17 | @@ -25,7 +22,6 @@ error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1: Sized` LL | needs_bar::<T::Assoc1>(); | ^^^^^^^^^ | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`) note: required by an implicit `Sized` bound in `needs_bar` --> $DIR/recursive-self-normalization-2.rs:12:14 | @@ -41,8 +37,6 @@ error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1 == _` | LL | needs_bar::<T::Assoc1>(); | ^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`) error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1 == _` --> $DIR/recursive-self-normalization-2.rs:15:5 @@ -50,7 +44,6 @@ error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1 == _` LL | needs_bar::<T::Assoc1>(); | ^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`) = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1 == _` @@ -59,7 +52,6 @@ error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1 == _` LL | needs_bar::<T::Assoc1>(); | ^^^^^^^^^ | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`) = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 6 previous errors diff --git a/tests/ui/traits/next-solver/overflow/recursive-self-normalization.stderr b/tests/ui/traits/next-solver/overflow/recursive-self-normalization.stderr index 7c058909df7..af8504dcaee 100644 --- a/tests/ui/traits/next-solver/overflow/recursive-self-normalization.stderr +++ b/tests/ui/traits/next-solver/overflow/recursive-self-normalization.stderr @@ -3,8 +3,6 @@ error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc == _` | LL | needs_bar::<T::Assoc>(); | ^^^^^^^^ - | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`) error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc: Bar` --> $DIR/recursive-self-normalization.rs:11:17 @@ -12,7 +10,6 @@ error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc: Bar` LL | needs_bar::<T::Assoc>(); | ^^^^^^^^ | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`) note: required by a bound in `needs_bar` --> $DIR/recursive-self-normalization.rs:8:17 | @@ -25,7 +22,6 @@ error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc: Sized` LL | needs_bar::<T::Assoc>(); | ^^^^^^^^ | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`) note: required by an implicit `Sized` bound in `needs_bar` --> $DIR/recursive-self-normalization.rs:8:14 | @@ -41,8 +37,6 @@ error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc == _` | LL | needs_bar::<T::Assoc>(); | ^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`) error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc == _` --> $DIR/recursive-self-normalization.rs:11:5 @@ -50,7 +44,6 @@ error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc == _` LL | needs_bar::<T::Assoc>(); | ^^^^^^^^^^^^^^^^^^^^^ | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`) = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc == _` @@ -59,7 +52,6 @@ error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc == _` LL | needs_bar::<T::Assoc>(); | ^^^^^^^^ | - = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`) = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 6 previous errors diff --git a/tests/ui/traits/span-bug-issue-121414.rs b/tests/ui/traits/span-bug-issue-121414.rs index 6fbe2c179c6..ec38d8c2de6 100644 --- a/tests/ui/traits/span-bug-issue-121414.rs +++ b/tests/ui/traits/span-bug-issue-121414.rs @@ -6,7 +6,8 @@ impl<'a> Bar for Foo<'f> { //~ ERROR undeclared lifetime type Type = u32; } -fn test() //~ ERROR implementation of `Bar` is not general enough +fn test() //~ ERROR the trait bound `for<'a> Foo<'a>: Bar` is not satisfied + //~| ERROR the trait bound `for<'a> Foo<'a>: Bar` is not satisfied where for<'a> <Foo<'a> as Bar>::Type: Sized, { diff --git a/tests/ui/traits/span-bug-issue-121414.stderr b/tests/ui/traits/span-bug-issue-121414.stderr index 3c97f64e781..e2ef6672cd5 100644 --- a/tests/ui/traits/span-bug-issue-121414.stderr +++ b/tests/ui/traits/span-bug-issue-121414.stderr @@ -6,15 +6,22 @@ LL | impl<'a> Bar for Foo<'f> { | | | help: consider introducing lifetime `'f` here: `'f,` -error: implementation of `Bar` is not general enough +error[E0277]: the trait bound `for<'a> Foo<'a>: Bar` is not satisfied + --> $DIR/span-bug-issue-121414.rs:9:1 + | +LL | / fn test() +LL | | +LL | | where +LL | | for<'a> <Foo<'a> as Bar>::Type: Sized, + | |__________________________________________^ the trait `for<'a> Bar` is not implemented for `Foo<'a>` + +error[E0277]: the trait bound `for<'a> Foo<'a>: Bar` is not satisfied --> $DIR/span-bug-issue-121414.rs:9:4 | LL | fn test() - | ^^^^ implementation of `Bar` is not general enough - | - = note: `Bar` would have to be implemented for the type `Foo<'0>`, for any lifetime `'0`... - = note: ...but `Bar` is actually implemented for the type `Foo<'1>`, for some specific lifetime `'1` + | ^^^^ the trait `for<'a> Bar` is not implemented for `Foo<'a>` -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0261`. +Some errors have detailed explanations: E0261, E0277. +For more information about an error, try `rustc --explain E0261`. diff --git a/tests/ui/traits/suggest-fully-qualified-closure.rs b/tests/ui/traits/suggest-fully-qualified-closure.rs index f401a3012da..3d28a4e6bf5 100644 --- a/tests/ui/traits/suggest-fully-qualified-closure.rs +++ b/tests/ui/traits/suggest-fully-qualified-closure.rs @@ -1,7 +1,5 @@ //@ check-fail //@ known-bug: #103705 -//@ normalize-stderr-test "\{closure@.*\}" -> "{closure@}" -//@ normalize-stderr-test "\+* ~" -> "+++ ~" // The output of this currently suggests writing a closure in the qualified path. diff --git a/tests/ui/traits/suggest-fully-qualified-closure.stderr b/tests/ui/traits/suggest-fully-qualified-closure.stderr index e077bd7ac2a..a2c1115e673 100644 --- a/tests/ui/traits/suggest-fully-qualified-closure.stderr +++ b/tests/ui/traits/suggest-fully-qualified-closure.stderr @@ -1,11 +1,11 @@ error[E0283]: type annotations needed - --> $DIR/suggest-fully-qualified-closure.rs:23:7 + --> $DIR/suggest-fully-qualified-closure.rs:21:7 | LL | q.lol(||()); | ^^^ | note: multiple `impl`s satisfying `Qqq: MyTrait<_>` found - --> $DIR/suggest-fully-qualified-closure.rs:14:1 + --> $DIR/suggest-fully-qualified-closure.rs:12:1 | LL | impl MyTrait<u32> for Qqq{ | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -14,8 +14,8 @@ LL | impl MyTrait<u64> for Qqq{ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using a fully qualified path to specify the expected types | -LL | <Qqq as MyTrait<T>>::lol::<{closure@}>(&q, ||()); - | +++ ~ +LL | <Qqq as MyTrait<T>>::lol::<_>(&q, ||()); + | +++++++++++++++++++++++++++++++ ~ error: aborting due to 1 previous error diff --git a/tests/ui/transmutability/alignment/align-fail.stderr b/tests/ui/transmutability/alignment/align-fail.stderr index c92c3d841f2..f05e55fb024 100644 --- a/tests/ui/transmutability/alignment/align-fail.stderr +++ b/tests/ui/transmutability/alignment/align-fail.stderr @@ -2,7 +2,7 @@ error[E0277]: `&[u8; 0]` cannot be safely transmuted into `&[u16; 0]` --> $DIR/align-fail.rs:21:55 | LL | ...tatic [u8; 0], &'static [u16; 0]>(); - | ^^^^^^^^^^^^^^^^^ The minimum alignment of `&[u8; 0]` (1) should be greater than that of `&[u16; 0]` (2) + | ^^^^^^^^^^^^^^^^^ the minimum alignment of `&[u8; 0]` (1) should be greater than that of `&[u16; 0]` (2) | note: required by a bound in `is_maybe_transmutable` --> $DIR/align-fail.rs:9:14 diff --git a/tests/ui/transmutability/arrays/should_require_well_defined_layout.stderr b/tests/ui/transmutability/arrays/should_require_well_defined_layout.stderr index fd21ac34183..e486928a445 100644 --- a/tests/ui/transmutability/arrays/should_require_well_defined_layout.stderr +++ b/tests/ui/transmutability/arrays/should_require_well_defined_layout.stderr @@ -2,7 +2,7 @@ error[E0277]: `[String; 0]` cannot be safely transmuted into `()` --> $DIR/should_require_well_defined_layout.rs:25:52 | LL | assert::is_maybe_transmutable::<repr_rust, ()>(); - | ^^ `[String; 0]` does not have a well-specified layout + | ^^ analyzing the transmutability of `[String; 0]` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -23,7 +23,7 @@ error[E0277]: `u128` cannot be safely transmuted into `[String; 0]` --> $DIR/should_require_well_defined_layout.rs:26:47 | LL | assert::is_maybe_transmutable::<u128, repr_rust>(); - | ^^^^^^^^^ `[String; 0]` does not have a well-specified layout + | ^^^^^^^^^ analyzing the transmutability of `[String; 0]` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -44,7 +44,7 @@ error[E0277]: `[String; 1]` cannot be safely transmuted into `()` --> $DIR/should_require_well_defined_layout.rs:31:52 | LL | assert::is_maybe_transmutable::<repr_rust, ()>(); - | ^^ `[String; 1]` does not have a well-specified layout + | ^^ analyzing the transmutability of `[String; 1]` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -65,7 +65,7 @@ error[E0277]: `u128` cannot be safely transmuted into `[String; 1]` --> $DIR/should_require_well_defined_layout.rs:32:47 | LL | assert::is_maybe_transmutable::<u128, repr_rust>(); - | ^^^^^^^^^ `[String; 1]` does not have a well-specified layout + | ^^^^^^^^^ analyzing the transmutability of `[String; 1]` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -86,7 +86,7 @@ error[E0277]: `[String; 2]` cannot be safely transmuted into `()` --> $DIR/should_require_well_defined_layout.rs:37:52 | LL | assert::is_maybe_transmutable::<repr_rust, ()>(); - | ^^ `[String; 2]` does not have a well-specified layout + | ^^ analyzing the transmutability of `[String; 2]` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -107,7 +107,7 @@ error[E0277]: `u128` cannot be safely transmuted into `[String; 2]` --> $DIR/should_require_well_defined_layout.rs:38:47 | LL | assert::is_maybe_transmutable::<u128, repr_rust>(); - | ^^^^^^^^^ `[String; 2]` does not have a well-specified layout + | ^^^^^^^^^ analyzing the transmutability of `[String; 2]` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 diff --git a/tests/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.stderr b/tests/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.stderr index b2ff04eeed9..6c88bf4ff96 100644 --- a/tests/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.stderr +++ b/tests/ui/transmutability/enums/repr/primitive_reprs_should_have_correct_length.stderr @@ -2,7 +2,7 @@ error[E0277]: `Zst` cannot be safely transmuted into `V0i8` --> $DIR/primitive_reprs_should_have_correct_length.rs:46:44 | LL | assert::is_transmutable::<Smaller, Current>(); - | ^^^^^^^ The size of `Zst` is smaller than the size of `V0i8` + | ^^^^^^^ the size of `Zst` is smaller than the size of `V0i8` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -24,7 +24,7 @@ error[E0277]: `V0i8` cannot be safely transmuted into `u16` --> $DIR/primitive_reprs_should_have_correct_length.rs:48:44 | LL | assert::is_transmutable::<Current, Larger>(); - | ^^^^^^ The size of `V0i8` is smaller than the size of `u16` + | ^^^^^^ the size of `V0i8` is smaller than the size of `u16` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -46,7 +46,7 @@ error[E0277]: `Zst` cannot be safely transmuted into `V0u8` --> $DIR/primitive_reprs_should_have_correct_length.rs:54:44 | LL | assert::is_transmutable::<Smaller, Current>(); - | ^^^^^^^ The size of `Zst` is smaller than the size of `V0u8` + | ^^^^^^^ the size of `Zst` is smaller than the size of `V0u8` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -68,7 +68,7 @@ error[E0277]: `V0u8` cannot be safely transmuted into `u16` --> $DIR/primitive_reprs_should_have_correct_length.rs:56:44 | LL | assert::is_transmutable::<Current, Larger>(); - | ^^^^^^ The size of `V0u8` is smaller than the size of `u16` + | ^^^^^^ the size of `V0u8` is smaller than the size of `u16` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -90,7 +90,7 @@ error[E0277]: `u8` cannot be safely transmuted into `V0i16` --> $DIR/primitive_reprs_should_have_correct_length.rs:68:44 | LL | assert::is_transmutable::<Smaller, Current>(); - | ^^^^^^^ The size of `u8` is smaller than the size of `V0i16` + | ^^^^^^^ the size of `u8` is smaller than the size of `V0i16` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -112,7 +112,7 @@ error[E0277]: `V0i16` cannot be safely transmuted into `u32` --> $DIR/primitive_reprs_should_have_correct_length.rs:70:44 | LL | assert::is_transmutable::<Current, Larger>(); - | ^^^^^^ The size of `V0i16` is smaller than the size of `u32` + | ^^^^^^ the size of `V0i16` is smaller than the size of `u32` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -134,7 +134,7 @@ error[E0277]: `u8` cannot be safely transmuted into `V0u16` --> $DIR/primitive_reprs_should_have_correct_length.rs:76:44 | LL | assert::is_transmutable::<Smaller, Current>(); - | ^^^^^^^ The size of `u8` is smaller than the size of `V0u16` + | ^^^^^^^ the size of `u8` is smaller than the size of `V0u16` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -156,7 +156,7 @@ error[E0277]: `V0u16` cannot be safely transmuted into `u32` --> $DIR/primitive_reprs_should_have_correct_length.rs:78:44 | LL | assert::is_transmutable::<Current, Larger>(); - | ^^^^^^ The size of `V0u16` is smaller than the size of `u32` + | ^^^^^^ the size of `V0u16` is smaller than the size of `u32` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -178,7 +178,7 @@ error[E0277]: `u16` cannot be safely transmuted into `V0i32` --> $DIR/primitive_reprs_should_have_correct_length.rs:90:44 | LL | assert::is_transmutable::<Smaller, Current>(); - | ^^^^^^^ The size of `u16` is smaller than the size of `V0i32` + | ^^^^^^^ the size of `u16` is smaller than the size of `V0i32` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -200,7 +200,7 @@ error[E0277]: `V0i32` cannot be safely transmuted into `u64` --> $DIR/primitive_reprs_should_have_correct_length.rs:92:44 | LL | assert::is_transmutable::<Current, Larger>(); - | ^^^^^^ The size of `V0i32` is smaller than the size of `u64` + | ^^^^^^ the size of `V0i32` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -222,7 +222,7 @@ error[E0277]: `u16` cannot be safely transmuted into `V0u32` --> $DIR/primitive_reprs_should_have_correct_length.rs:98:44 | LL | assert::is_transmutable::<Smaller, Current>(); - | ^^^^^^^ The size of `u16` is smaller than the size of `V0u32` + | ^^^^^^^ the size of `u16` is smaller than the size of `V0u32` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -244,7 +244,7 @@ error[E0277]: `V0u32` cannot be safely transmuted into `u64` --> $DIR/primitive_reprs_should_have_correct_length.rs:100:44 | LL | assert::is_transmutable::<Current, Larger>(); - | ^^^^^^ The size of `V0u32` is smaller than the size of `u64` + | ^^^^^^ the size of `V0u32` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -266,7 +266,7 @@ error[E0277]: `u32` cannot be safely transmuted into `V0i64` --> $DIR/primitive_reprs_should_have_correct_length.rs:112:44 | LL | assert::is_transmutable::<Smaller, Current>(); - | ^^^^^^^ The size of `u32` is smaller than the size of `V0i64` + | ^^^^^^^ the size of `u32` is smaller than the size of `V0i64` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -288,7 +288,7 @@ error[E0277]: `V0i64` cannot be safely transmuted into `u128` --> $DIR/primitive_reprs_should_have_correct_length.rs:114:44 | LL | assert::is_transmutable::<Current, Larger>(); - | ^^^^^^ The size of `V0i64` is smaller than the size of `u128` + | ^^^^^^ the size of `V0i64` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -310,7 +310,7 @@ error[E0277]: `u32` cannot be safely transmuted into `V0u64` --> $DIR/primitive_reprs_should_have_correct_length.rs:120:44 | LL | assert::is_transmutable::<Smaller, Current>(); - | ^^^^^^^ The size of `u32` is smaller than the size of `V0u64` + | ^^^^^^^ the size of `u32` is smaller than the size of `V0u64` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -332,7 +332,7 @@ error[E0277]: `V0u64` cannot be safely transmuted into `u128` --> $DIR/primitive_reprs_should_have_correct_length.rs:122:44 | LL | assert::is_transmutable::<Current, Larger>(); - | ^^^^^^ The size of `V0u64` is smaller than the size of `u128` + | ^^^^^^ the size of `V0u64` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -354,7 +354,7 @@ error[E0277]: `u8` cannot be safely transmuted into `V0isize` --> $DIR/primitive_reprs_should_have_correct_length.rs:134:44 | LL | assert::is_transmutable::<Smaller, Current>(); - | ^^^^^^^ The size of `u8` is smaller than the size of `V0isize` + | ^^^^^^^ the size of `u8` is smaller than the size of `V0isize` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -376,7 +376,7 @@ error[E0277]: `V0isize` cannot be safely transmuted into `[usize; 2]` --> $DIR/primitive_reprs_should_have_correct_length.rs:136:44 | LL | assert::is_transmutable::<Current, Larger>(); - | ^^^^^^ The size of `V0isize` is smaller than the size of `[usize; 2]` + | ^^^^^^ the size of `V0isize` is smaller than the size of `[usize; 2]` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -398,7 +398,7 @@ error[E0277]: `u8` cannot be safely transmuted into `V0usize` --> $DIR/primitive_reprs_should_have_correct_length.rs:142:44 | LL | assert::is_transmutable::<Smaller, Current>(); - | ^^^^^^^ The size of `u8` is smaller than the size of `V0usize` + | ^^^^^^^ the size of `u8` is smaller than the size of `V0usize` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 @@ -420,7 +420,7 @@ error[E0277]: `V0usize` cannot be safely transmuted into `[usize; 2]` --> $DIR/primitive_reprs_should_have_correct_length.rs:144:44 | LL | assert::is_transmutable::<Current, Larger>(); - | ^^^^^^ The size of `V0usize` is smaller than the size of `[usize; 2]` + | ^^^^^^ the size of `V0usize` is smaller than the size of `[usize; 2]` | note: required by a bound in `is_transmutable` --> $DIR/primitive_reprs_should_have_correct_length.rs:12:14 diff --git a/tests/ui/transmutability/enums/repr/should_require_well_defined_layout.stderr b/tests/ui/transmutability/enums/repr/should_require_well_defined_layout.stderr index 24730935047..2a683de6a65 100644 --- a/tests/ui/transmutability/enums/repr/should_require_well_defined_layout.stderr +++ b/tests/ui/transmutability/enums/repr/should_require_well_defined_layout.stderr @@ -2,7 +2,7 @@ error[E0277]: `void::repr_rust` cannot be safely transmuted into `()` --> $DIR/should_require_well_defined_layout.rs:27:52 | LL | assert::is_maybe_transmutable::<repr_rust, ()>(); - | ^^ `void::repr_rust` does not have a well-specified layout + | ^^ analyzing the transmutability of `void::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:13:14 @@ -24,7 +24,7 @@ error[E0277]: `u128` cannot be safely transmuted into `void::repr_rust` --> $DIR/should_require_well_defined_layout.rs:28:47 | LL | assert::is_maybe_transmutable::<u128, repr_rust>(); - | ^^^^^^^^^ `void::repr_rust` does not have a well-specified layout + | ^^^^^^^^^ analyzing the transmutability of `void::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:13:14 @@ -46,7 +46,7 @@ error[E0277]: `singleton::repr_rust` cannot be safely transmuted into `()` --> $DIR/should_require_well_defined_layout.rs:33:52 | LL | assert::is_maybe_transmutable::<repr_rust, ()>(); - | ^^ `singleton::repr_rust` does not have a well-specified layout + | ^^ analyzing the transmutability of `singleton::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:13:14 @@ -68,7 +68,7 @@ error[E0277]: `u128` cannot be safely transmuted into `singleton::repr_rust` --> $DIR/should_require_well_defined_layout.rs:34:47 | LL | assert::is_maybe_transmutable::<u128, repr_rust>(); - | ^^^^^^^^^ `singleton::repr_rust` does not have a well-specified layout + | ^^^^^^^^^ analyzing the transmutability of `singleton::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:13:14 @@ -90,7 +90,7 @@ error[E0277]: `duplex::repr_rust` cannot be safely transmuted into `()` --> $DIR/should_require_well_defined_layout.rs:39:52 | LL | assert::is_maybe_transmutable::<repr_rust, ()>(); - | ^^ `duplex::repr_rust` does not have a well-specified layout + | ^^ analyzing the transmutability of `duplex::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:13:14 @@ -112,7 +112,7 @@ error[E0277]: `u128` cannot be safely transmuted into `duplex::repr_rust` --> $DIR/should_require_well_defined_layout.rs:40:47 | LL | assert::is_maybe_transmutable::<u128, repr_rust>(); - | ^^^^^^^^^ `duplex::repr_rust` does not have a well-specified layout + | ^^^^^^^^^ analyzing the transmutability of `duplex::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:13:14 diff --git a/tests/ui/transmutability/enums/should_pad_variants.stderr b/tests/ui/transmutability/enums/should_pad_variants.stderr index 13b4c8053ad..da4294bdbce 100644 --- a/tests/ui/transmutability/enums/should_pad_variants.stderr +++ b/tests/ui/transmutability/enums/should_pad_variants.stderr @@ -2,7 +2,7 @@ error[E0277]: `Src` cannot be safely transmuted into `Dst` --> $DIR/should_pad_variants.rs:43:36 | LL | assert::is_transmutable::<Src, Dst>(); - | ^^^ The size of `Src` is smaller than the size of `Dst` + | ^^^ the size of `Src` is smaller than the size of `Dst` | note: required by a bound in `is_transmutable` --> $DIR/should_pad_variants.rs:13:14 diff --git a/tests/ui/transmutability/enums/should_respect_endianness.stderr b/tests/ui/transmutability/enums/should_respect_endianness.stderr index c2a2eb53458..9f88bb06813 100644 --- a/tests/ui/transmutability/enums/should_respect_endianness.stderr +++ b/tests/ui/transmutability/enums/should_respect_endianness.stderr @@ -2,7 +2,7 @@ error[E0277]: `Src` cannot be safely transmuted into `Unexpected` --> $DIR/should_respect_endianness.rs:35:36 | LL | assert::is_transmutable::<Src, Unexpected>(); - | ^^^^^^^^^^ At least one value of `Src` isn't a bit-valid value of `Unexpected` + | ^^^^^^^^^^ at least one value of `Src` isn't a bit-valid value of `Unexpected` | note: required by a bound in `is_transmutable` --> $DIR/should_respect_endianness.rs:13:14 diff --git a/tests/ui/transmutability/primitives/bool-mut.stderr b/tests/ui/transmutability/primitives/bool-mut.stderr index c4f295fc70a..464c2755e11 100644 --- a/tests/ui/transmutability/primitives/bool-mut.stderr +++ b/tests/ui/transmutability/primitives/bool-mut.stderr @@ -2,7 +2,7 @@ error[E0277]: `u8` cannot be safely transmuted into `bool` --> $DIR/bool-mut.rs:15:50 | LL | assert::is_transmutable::<&'static mut bool, &'static mut u8>() - | ^^^^^^^^^^^^^^^ At least one value of `u8` isn't a bit-valid value of `bool` + | ^^^^^^^^^^^^^^^ at least one value of `u8` isn't a bit-valid value of `bool` | note: required by a bound in `is_transmutable` --> $DIR/bool-mut.rs:10:14 diff --git a/tests/ui/transmutability/primitives/bool.current.stderr b/tests/ui/transmutability/primitives/bool.current.stderr index 98e4a1029c9..da6a4a44e95 100644 --- a/tests/ui/transmutability/primitives/bool.current.stderr +++ b/tests/ui/transmutability/primitives/bool.current.stderr @@ -2,7 +2,7 @@ error[E0277]: `u8` cannot be safely transmuted into `bool` --> $DIR/bool.rs:21:35 | LL | assert::is_transmutable::<u8, bool>(); - | ^^^^ At least one value of `u8` isn't a bit-valid value of `bool` + | ^^^^ at least one value of `u8` isn't a bit-valid value of `bool` | note: required by a bound in `is_transmutable` --> $DIR/bool.rs:11:14 diff --git a/tests/ui/transmutability/primitives/bool.next.stderr b/tests/ui/transmutability/primitives/bool.next.stderr index 98e4a1029c9..da6a4a44e95 100644 --- a/tests/ui/transmutability/primitives/bool.next.stderr +++ b/tests/ui/transmutability/primitives/bool.next.stderr @@ -2,7 +2,7 @@ error[E0277]: `u8` cannot be safely transmuted into `bool` --> $DIR/bool.rs:21:35 | LL | assert::is_transmutable::<u8, bool>(); - | ^^^^ At least one value of `u8` isn't a bit-valid value of `bool` + | ^^^^ at least one value of `u8` isn't a bit-valid value of `bool` | note: required by a bound in `is_transmutable` --> $DIR/bool.rs:11:14 diff --git a/tests/ui/transmutability/primitives/numbers.current.stderr b/tests/ui/transmutability/primitives/numbers.current.stderr index 7a80e444149..0a9b9d182f8 100644 --- a/tests/ui/transmutability/primitives/numbers.current.stderr +++ b/tests/ui/transmutability/primitives/numbers.current.stderr @@ -2,7 +2,7 @@ error[E0277]: `i8` cannot be safely transmuted into `i16` --> $DIR/numbers.rs:64:40 | LL | assert::is_transmutable::< i8, i16>(); - | ^^^ The size of `i8` is smaller than the size of `i16` + | ^^^ the size of `i8` is smaller than the size of `i16` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -17,7 +17,7 @@ error[E0277]: `i8` cannot be safely transmuted into `u16` --> $DIR/numbers.rs:65:40 | LL | assert::is_transmutable::< i8, u16>(); - | ^^^ The size of `i8` is smaller than the size of `u16` + | ^^^ the size of `i8` is smaller than the size of `u16` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -32,7 +32,7 @@ error[E0277]: `i8` cannot be safely transmuted into `i32` --> $DIR/numbers.rs:66:40 | LL | assert::is_transmutable::< i8, i32>(); - | ^^^ The size of `i8` is smaller than the size of `i32` + | ^^^ the size of `i8` is smaller than the size of `i32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -47,7 +47,7 @@ error[E0277]: `i8` cannot be safely transmuted into `f32` --> $DIR/numbers.rs:67:40 | LL | assert::is_transmutable::< i8, f32>(); - | ^^^ The size of `i8` is smaller than the size of `f32` + | ^^^ the size of `i8` is smaller than the size of `f32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -62,7 +62,7 @@ error[E0277]: `i8` cannot be safely transmuted into `u32` --> $DIR/numbers.rs:68:40 | LL | assert::is_transmutable::< i8, u32>(); - | ^^^ The size of `i8` is smaller than the size of `u32` + | ^^^ the size of `i8` is smaller than the size of `u32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -77,7 +77,7 @@ error[E0277]: `i8` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:69:40 | LL | assert::is_transmutable::< i8, u64>(); - | ^^^ The size of `i8` is smaller than the size of `u64` + | ^^^ the size of `i8` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -92,7 +92,7 @@ error[E0277]: `i8` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:70:40 | LL | assert::is_transmutable::< i8, i64>(); - | ^^^ The size of `i8` is smaller than the size of `i64` + | ^^^ the size of `i8` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -107,7 +107,7 @@ error[E0277]: `i8` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:71:40 | LL | assert::is_transmutable::< i8, f64>(); - | ^^^ The size of `i8` is smaller than the size of `f64` + | ^^^ the size of `i8` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -122,7 +122,7 @@ error[E0277]: `i8` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:72:39 | LL | assert::is_transmutable::< i8, u128>(); - | ^^^^ The size of `i8` is smaller than the size of `u128` + | ^^^^ the size of `i8` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -137,7 +137,7 @@ error[E0277]: `i8` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:73:39 | LL | assert::is_transmutable::< i8, i128>(); - | ^^^^ The size of `i8` is smaller than the size of `i128` + | ^^^^ the size of `i8` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -152,7 +152,7 @@ error[E0277]: `u8` cannot be safely transmuted into `i16` --> $DIR/numbers.rs:75:40 | LL | assert::is_transmutable::< u8, i16>(); - | ^^^ The size of `u8` is smaller than the size of `i16` + | ^^^ the size of `u8` is smaller than the size of `i16` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -167,7 +167,7 @@ error[E0277]: `u8` cannot be safely transmuted into `u16` --> $DIR/numbers.rs:76:40 | LL | assert::is_transmutable::< u8, u16>(); - | ^^^ The size of `u8` is smaller than the size of `u16` + | ^^^ the size of `u8` is smaller than the size of `u16` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -182,7 +182,7 @@ error[E0277]: `u8` cannot be safely transmuted into `i32` --> $DIR/numbers.rs:77:40 | LL | assert::is_transmutable::< u8, i32>(); - | ^^^ The size of `u8` is smaller than the size of `i32` + | ^^^ the size of `u8` is smaller than the size of `i32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -197,7 +197,7 @@ error[E0277]: `u8` cannot be safely transmuted into `f32` --> $DIR/numbers.rs:78:40 | LL | assert::is_transmutable::< u8, f32>(); - | ^^^ The size of `u8` is smaller than the size of `f32` + | ^^^ the size of `u8` is smaller than the size of `f32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -212,7 +212,7 @@ error[E0277]: `u8` cannot be safely transmuted into `u32` --> $DIR/numbers.rs:79:40 | LL | assert::is_transmutable::< u8, u32>(); - | ^^^ The size of `u8` is smaller than the size of `u32` + | ^^^ the size of `u8` is smaller than the size of `u32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -227,7 +227,7 @@ error[E0277]: `u8` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:80:40 | LL | assert::is_transmutable::< u8, u64>(); - | ^^^ The size of `u8` is smaller than the size of `u64` + | ^^^ the size of `u8` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -242,7 +242,7 @@ error[E0277]: `u8` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:81:40 | LL | assert::is_transmutable::< u8, i64>(); - | ^^^ The size of `u8` is smaller than the size of `i64` + | ^^^ the size of `u8` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -257,7 +257,7 @@ error[E0277]: `u8` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:82:40 | LL | assert::is_transmutable::< u8, f64>(); - | ^^^ The size of `u8` is smaller than the size of `f64` + | ^^^ the size of `u8` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -272,7 +272,7 @@ error[E0277]: `u8` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:83:39 | LL | assert::is_transmutable::< u8, u128>(); - | ^^^^ The size of `u8` is smaller than the size of `u128` + | ^^^^ the size of `u8` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -287,7 +287,7 @@ error[E0277]: `u8` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:84:39 | LL | assert::is_transmutable::< u8, i128>(); - | ^^^^ The size of `u8` is smaller than the size of `i128` + | ^^^^ the size of `u8` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -302,7 +302,7 @@ error[E0277]: `i16` cannot be safely transmuted into `i32` --> $DIR/numbers.rs:86:40 | LL | assert::is_transmutable::< i16, i32>(); - | ^^^ The size of `i16` is smaller than the size of `i32` + | ^^^ the size of `i16` is smaller than the size of `i32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -317,7 +317,7 @@ error[E0277]: `i16` cannot be safely transmuted into `f32` --> $DIR/numbers.rs:87:40 | LL | assert::is_transmutable::< i16, f32>(); - | ^^^ The size of `i16` is smaller than the size of `f32` + | ^^^ the size of `i16` is smaller than the size of `f32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -332,7 +332,7 @@ error[E0277]: `i16` cannot be safely transmuted into `u32` --> $DIR/numbers.rs:88:40 | LL | assert::is_transmutable::< i16, u32>(); - | ^^^ The size of `i16` is smaller than the size of `u32` + | ^^^ the size of `i16` is smaller than the size of `u32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -347,7 +347,7 @@ error[E0277]: `i16` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:89:40 | LL | assert::is_transmutable::< i16, u64>(); - | ^^^ The size of `i16` is smaller than the size of `u64` + | ^^^ the size of `i16` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -362,7 +362,7 @@ error[E0277]: `i16` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:90:40 | LL | assert::is_transmutable::< i16, i64>(); - | ^^^ The size of `i16` is smaller than the size of `i64` + | ^^^ the size of `i16` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -377,7 +377,7 @@ error[E0277]: `i16` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:91:40 | LL | assert::is_transmutable::< i16, f64>(); - | ^^^ The size of `i16` is smaller than the size of `f64` + | ^^^ the size of `i16` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -392,7 +392,7 @@ error[E0277]: `i16` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:92:39 | LL | assert::is_transmutable::< i16, u128>(); - | ^^^^ The size of `i16` is smaller than the size of `u128` + | ^^^^ the size of `i16` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -407,7 +407,7 @@ error[E0277]: `i16` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:93:39 | LL | assert::is_transmutable::< i16, i128>(); - | ^^^^ The size of `i16` is smaller than the size of `i128` + | ^^^^ the size of `i16` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -422,7 +422,7 @@ error[E0277]: `u16` cannot be safely transmuted into `i32` --> $DIR/numbers.rs:95:40 | LL | assert::is_transmutable::< u16, i32>(); - | ^^^ The size of `u16` is smaller than the size of `i32` + | ^^^ the size of `u16` is smaller than the size of `i32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -437,7 +437,7 @@ error[E0277]: `u16` cannot be safely transmuted into `f32` --> $DIR/numbers.rs:96:40 | LL | assert::is_transmutable::< u16, f32>(); - | ^^^ The size of `u16` is smaller than the size of `f32` + | ^^^ the size of `u16` is smaller than the size of `f32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -452,7 +452,7 @@ error[E0277]: `u16` cannot be safely transmuted into `u32` --> $DIR/numbers.rs:97:40 | LL | assert::is_transmutable::< u16, u32>(); - | ^^^ The size of `u16` is smaller than the size of `u32` + | ^^^ the size of `u16` is smaller than the size of `u32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -467,7 +467,7 @@ error[E0277]: `u16` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:98:40 | LL | assert::is_transmutable::< u16, u64>(); - | ^^^ The size of `u16` is smaller than the size of `u64` + | ^^^ the size of `u16` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -482,7 +482,7 @@ error[E0277]: `u16` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:99:40 | LL | assert::is_transmutable::< u16, i64>(); - | ^^^ The size of `u16` is smaller than the size of `i64` + | ^^^ the size of `u16` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -497,7 +497,7 @@ error[E0277]: `u16` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:100:40 | LL | assert::is_transmutable::< u16, f64>(); - | ^^^ The size of `u16` is smaller than the size of `f64` + | ^^^ the size of `u16` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -512,7 +512,7 @@ error[E0277]: `u16` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:101:39 | LL | assert::is_transmutable::< u16, u128>(); - | ^^^^ The size of `u16` is smaller than the size of `u128` + | ^^^^ the size of `u16` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -527,7 +527,7 @@ error[E0277]: `u16` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:102:39 | LL | assert::is_transmutable::< u16, i128>(); - | ^^^^ The size of `u16` is smaller than the size of `i128` + | ^^^^ the size of `u16` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -542,7 +542,7 @@ error[E0277]: `i32` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:104:40 | LL | assert::is_transmutable::< i32, u64>(); - | ^^^ The size of `i32` is smaller than the size of `u64` + | ^^^ the size of `i32` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -557,7 +557,7 @@ error[E0277]: `i32` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:105:40 | LL | assert::is_transmutable::< i32, i64>(); - | ^^^ The size of `i32` is smaller than the size of `i64` + | ^^^ the size of `i32` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -572,7 +572,7 @@ error[E0277]: `i32` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:106:40 | LL | assert::is_transmutable::< i32, f64>(); - | ^^^ The size of `i32` is smaller than the size of `f64` + | ^^^ the size of `i32` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -587,7 +587,7 @@ error[E0277]: `i32` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:107:39 | LL | assert::is_transmutable::< i32, u128>(); - | ^^^^ The size of `i32` is smaller than the size of `u128` + | ^^^^ the size of `i32` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -602,7 +602,7 @@ error[E0277]: `i32` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:108:39 | LL | assert::is_transmutable::< i32, i128>(); - | ^^^^ The size of `i32` is smaller than the size of `i128` + | ^^^^ the size of `i32` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -617,7 +617,7 @@ error[E0277]: `f32` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:110:40 | LL | assert::is_transmutable::< f32, u64>(); - | ^^^ The size of `f32` is smaller than the size of `u64` + | ^^^ the size of `f32` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -632,7 +632,7 @@ error[E0277]: `f32` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:111:40 | LL | assert::is_transmutable::< f32, i64>(); - | ^^^ The size of `f32` is smaller than the size of `i64` + | ^^^ the size of `f32` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -647,7 +647,7 @@ error[E0277]: `f32` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:112:40 | LL | assert::is_transmutable::< f32, f64>(); - | ^^^ The size of `f32` is smaller than the size of `f64` + | ^^^ the size of `f32` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -662,7 +662,7 @@ error[E0277]: `f32` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:113:39 | LL | assert::is_transmutable::< f32, u128>(); - | ^^^^ The size of `f32` is smaller than the size of `u128` + | ^^^^ the size of `f32` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -677,7 +677,7 @@ error[E0277]: `f32` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:114:39 | LL | assert::is_transmutable::< f32, i128>(); - | ^^^^ The size of `f32` is smaller than the size of `i128` + | ^^^^ the size of `f32` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -692,7 +692,7 @@ error[E0277]: `u32` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:116:40 | LL | assert::is_transmutable::< u32, u64>(); - | ^^^ The size of `u32` is smaller than the size of `u64` + | ^^^ the size of `u32` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -707,7 +707,7 @@ error[E0277]: `u32` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:117:40 | LL | assert::is_transmutable::< u32, i64>(); - | ^^^ The size of `u32` is smaller than the size of `i64` + | ^^^ the size of `u32` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -722,7 +722,7 @@ error[E0277]: `u32` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:118:40 | LL | assert::is_transmutable::< u32, f64>(); - | ^^^ The size of `u32` is smaller than the size of `f64` + | ^^^ the size of `u32` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -737,7 +737,7 @@ error[E0277]: `u32` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:119:39 | LL | assert::is_transmutable::< u32, u128>(); - | ^^^^ The size of `u32` is smaller than the size of `u128` + | ^^^^ the size of `u32` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -752,7 +752,7 @@ error[E0277]: `u32` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:120:39 | LL | assert::is_transmutable::< u32, i128>(); - | ^^^^ The size of `u32` is smaller than the size of `i128` + | ^^^^ the size of `u32` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -767,7 +767,7 @@ error[E0277]: `u64` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:122:39 | LL | assert::is_transmutable::< u64, u128>(); - | ^^^^ The size of `u64` is smaller than the size of `u128` + | ^^^^ the size of `u64` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -782,7 +782,7 @@ error[E0277]: `u64` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:123:39 | LL | assert::is_transmutable::< u64, i128>(); - | ^^^^ The size of `u64` is smaller than the size of `i128` + | ^^^^ the size of `u64` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -797,7 +797,7 @@ error[E0277]: `i64` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:125:39 | LL | assert::is_transmutable::< i64, u128>(); - | ^^^^ The size of `i64` is smaller than the size of `u128` + | ^^^^ the size of `i64` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -812,7 +812,7 @@ error[E0277]: `i64` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:126:39 | LL | assert::is_transmutable::< i64, i128>(); - | ^^^^ The size of `i64` is smaller than the size of `i128` + | ^^^^ the size of `i64` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -827,7 +827,7 @@ error[E0277]: `f64` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:128:39 | LL | assert::is_transmutable::< f64, u128>(); - | ^^^^ The size of `f64` is smaller than the size of `u128` + | ^^^^ the size of `f64` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -842,7 +842,7 @@ error[E0277]: `f64` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:129:39 | LL | assert::is_transmutable::< f64, i128>(); - | ^^^^ The size of `f64` is smaller than the size of `i128` + | ^^^^ the size of `f64` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 diff --git a/tests/ui/transmutability/primitives/numbers.next.stderr b/tests/ui/transmutability/primitives/numbers.next.stderr index 7a80e444149..0a9b9d182f8 100644 --- a/tests/ui/transmutability/primitives/numbers.next.stderr +++ b/tests/ui/transmutability/primitives/numbers.next.stderr @@ -2,7 +2,7 @@ error[E0277]: `i8` cannot be safely transmuted into `i16` --> $DIR/numbers.rs:64:40 | LL | assert::is_transmutable::< i8, i16>(); - | ^^^ The size of `i8` is smaller than the size of `i16` + | ^^^ the size of `i8` is smaller than the size of `i16` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -17,7 +17,7 @@ error[E0277]: `i8` cannot be safely transmuted into `u16` --> $DIR/numbers.rs:65:40 | LL | assert::is_transmutable::< i8, u16>(); - | ^^^ The size of `i8` is smaller than the size of `u16` + | ^^^ the size of `i8` is smaller than the size of `u16` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -32,7 +32,7 @@ error[E0277]: `i8` cannot be safely transmuted into `i32` --> $DIR/numbers.rs:66:40 | LL | assert::is_transmutable::< i8, i32>(); - | ^^^ The size of `i8` is smaller than the size of `i32` + | ^^^ the size of `i8` is smaller than the size of `i32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -47,7 +47,7 @@ error[E0277]: `i8` cannot be safely transmuted into `f32` --> $DIR/numbers.rs:67:40 | LL | assert::is_transmutable::< i8, f32>(); - | ^^^ The size of `i8` is smaller than the size of `f32` + | ^^^ the size of `i8` is smaller than the size of `f32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -62,7 +62,7 @@ error[E0277]: `i8` cannot be safely transmuted into `u32` --> $DIR/numbers.rs:68:40 | LL | assert::is_transmutable::< i8, u32>(); - | ^^^ The size of `i8` is smaller than the size of `u32` + | ^^^ the size of `i8` is smaller than the size of `u32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -77,7 +77,7 @@ error[E0277]: `i8` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:69:40 | LL | assert::is_transmutable::< i8, u64>(); - | ^^^ The size of `i8` is smaller than the size of `u64` + | ^^^ the size of `i8` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -92,7 +92,7 @@ error[E0277]: `i8` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:70:40 | LL | assert::is_transmutable::< i8, i64>(); - | ^^^ The size of `i8` is smaller than the size of `i64` + | ^^^ the size of `i8` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -107,7 +107,7 @@ error[E0277]: `i8` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:71:40 | LL | assert::is_transmutable::< i8, f64>(); - | ^^^ The size of `i8` is smaller than the size of `f64` + | ^^^ the size of `i8` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -122,7 +122,7 @@ error[E0277]: `i8` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:72:39 | LL | assert::is_transmutable::< i8, u128>(); - | ^^^^ The size of `i8` is smaller than the size of `u128` + | ^^^^ the size of `i8` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -137,7 +137,7 @@ error[E0277]: `i8` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:73:39 | LL | assert::is_transmutable::< i8, i128>(); - | ^^^^ The size of `i8` is smaller than the size of `i128` + | ^^^^ the size of `i8` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -152,7 +152,7 @@ error[E0277]: `u8` cannot be safely transmuted into `i16` --> $DIR/numbers.rs:75:40 | LL | assert::is_transmutable::< u8, i16>(); - | ^^^ The size of `u8` is smaller than the size of `i16` + | ^^^ the size of `u8` is smaller than the size of `i16` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -167,7 +167,7 @@ error[E0277]: `u8` cannot be safely transmuted into `u16` --> $DIR/numbers.rs:76:40 | LL | assert::is_transmutable::< u8, u16>(); - | ^^^ The size of `u8` is smaller than the size of `u16` + | ^^^ the size of `u8` is smaller than the size of `u16` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -182,7 +182,7 @@ error[E0277]: `u8` cannot be safely transmuted into `i32` --> $DIR/numbers.rs:77:40 | LL | assert::is_transmutable::< u8, i32>(); - | ^^^ The size of `u8` is smaller than the size of `i32` + | ^^^ the size of `u8` is smaller than the size of `i32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -197,7 +197,7 @@ error[E0277]: `u8` cannot be safely transmuted into `f32` --> $DIR/numbers.rs:78:40 | LL | assert::is_transmutable::< u8, f32>(); - | ^^^ The size of `u8` is smaller than the size of `f32` + | ^^^ the size of `u8` is smaller than the size of `f32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -212,7 +212,7 @@ error[E0277]: `u8` cannot be safely transmuted into `u32` --> $DIR/numbers.rs:79:40 | LL | assert::is_transmutable::< u8, u32>(); - | ^^^ The size of `u8` is smaller than the size of `u32` + | ^^^ the size of `u8` is smaller than the size of `u32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -227,7 +227,7 @@ error[E0277]: `u8` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:80:40 | LL | assert::is_transmutable::< u8, u64>(); - | ^^^ The size of `u8` is smaller than the size of `u64` + | ^^^ the size of `u8` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -242,7 +242,7 @@ error[E0277]: `u8` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:81:40 | LL | assert::is_transmutable::< u8, i64>(); - | ^^^ The size of `u8` is smaller than the size of `i64` + | ^^^ the size of `u8` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -257,7 +257,7 @@ error[E0277]: `u8` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:82:40 | LL | assert::is_transmutable::< u8, f64>(); - | ^^^ The size of `u8` is smaller than the size of `f64` + | ^^^ the size of `u8` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -272,7 +272,7 @@ error[E0277]: `u8` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:83:39 | LL | assert::is_transmutable::< u8, u128>(); - | ^^^^ The size of `u8` is smaller than the size of `u128` + | ^^^^ the size of `u8` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -287,7 +287,7 @@ error[E0277]: `u8` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:84:39 | LL | assert::is_transmutable::< u8, i128>(); - | ^^^^ The size of `u8` is smaller than the size of `i128` + | ^^^^ the size of `u8` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -302,7 +302,7 @@ error[E0277]: `i16` cannot be safely transmuted into `i32` --> $DIR/numbers.rs:86:40 | LL | assert::is_transmutable::< i16, i32>(); - | ^^^ The size of `i16` is smaller than the size of `i32` + | ^^^ the size of `i16` is smaller than the size of `i32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -317,7 +317,7 @@ error[E0277]: `i16` cannot be safely transmuted into `f32` --> $DIR/numbers.rs:87:40 | LL | assert::is_transmutable::< i16, f32>(); - | ^^^ The size of `i16` is smaller than the size of `f32` + | ^^^ the size of `i16` is smaller than the size of `f32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -332,7 +332,7 @@ error[E0277]: `i16` cannot be safely transmuted into `u32` --> $DIR/numbers.rs:88:40 | LL | assert::is_transmutable::< i16, u32>(); - | ^^^ The size of `i16` is smaller than the size of `u32` + | ^^^ the size of `i16` is smaller than the size of `u32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -347,7 +347,7 @@ error[E0277]: `i16` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:89:40 | LL | assert::is_transmutable::< i16, u64>(); - | ^^^ The size of `i16` is smaller than the size of `u64` + | ^^^ the size of `i16` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -362,7 +362,7 @@ error[E0277]: `i16` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:90:40 | LL | assert::is_transmutable::< i16, i64>(); - | ^^^ The size of `i16` is smaller than the size of `i64` + | ^^^ the size of `i16` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -377,7 +377,7 @@ error[E0277]: `i16` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:91:40 | LL | assert::is_transmutable::< i16, f64>(); - | ^^^ The size of `i16` is smaller than the size of `f64` + | ^^^ the size of `i16` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -392,7 +392,7 @@ error[E0277]: `i16` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:92:39 | LL | assert::is_transmutable::< i16, u128>(); - | ^^^^ The size of `i16` is smaller than the size of `u128` + | ^^^^ the size of `i16` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -407,7 +407,7 @@ error[E0277]: `i16` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:93:39 | LL | assert::is_transmutable::< i16, i128>(); - | ^^^^ The size of `i16` is smaller than the size of `i128` + | ^^^^ the size of `i16` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -422,7 +422,7 @@ error[E0277]: `u16` cannot be safely transmuted into `i32` --> $DIR/numbers.rs:95:40 | LL | assert::is_transmutable::< u16, i32>(); - | ^^^ The size of `u16` is smaller than the size of `i32` + | ^^^ the size of `u16` is smaller than the size of `i32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -437,7 +437,7 @@ error[E0277]: `u16` cannot be safely transmuted into `f32` --> $DIR/numbers.rs:96:40 | LL | assert::is_transmutable::< u16, f32>(); - | ^^^ The size of `u16` is smaller than the size of `f32` + | ^^^ the size of `u16` is smaller than the size of `f32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -452,7 +452,7 @@ error[E0277]: `u16` cannot be safely transmuted into `u32` --> $DIR/numbers.rs:97:40 | LL | assert::is_transmutable::< u16, u32>(); - | ^^^ The size of `u16` is smaller than the size of `u32` + | ^^^ the size of `u16` is smaller than the size of `u32` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -467,7 +467,7 @@ error[E0277]: `u16` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:98:40 | LL | assert::is_transmutable::< u16, u64>(); - | ^^^ The size of `u16` is smaller than the size of `u64` + | ^^^ the size of `u16` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -482,7 +482,7 @@ error[E0277]: `u16` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:99:40 | LL | assert::is_transmutable::< u16, i64>(); - | ^^^ The size of `u16` is smaller than the size of `i64` + | ^^^ the size of `u16` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -497,7 +497,7 @@ error[E0277]: `u16` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:100:40 | LL | assert::is_transmutable::< u16, f64>(); - | ^^^ The size of `u16` is smaller than the size of `f64` + | ^^^ the size of `u16` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -512,7 +512,7 @@ error[E0277]: `u16` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:101:39 | LL | assert::is_transmutable::< u16, u128>(); - | ^^^^ The size of `u16` is smaller than the size of `u128` + | ^^^^ the size of `u16` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -527,7 +527,7 @@ error[E0277]: `u16` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:102:39 | LL | assert::is_transmutable::< u16, i128>(); - | ^^^^ The size of `u16` is smaller than the size of `i128` + | ^^^^ the size of `u16` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -542,7 +542,7 @@ error[E0277]: `i32` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:104:40 | LL | assert::is_transmutable::< i32, u64>(); - | ^^^ The size of `i32` is smaller than the size of `u64` + | ^^^ the size of `i32` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -557,7 +557,7 @@ error[E0277]: `i32` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:105:40 | LL | assert::is_transmutable::< i32, i64>(); - | ^^^ The size of `i32` is smaller than the size of `i64` + | ^^^ the size of `i32` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -572,7 +572,7 @@ error[E0277]: `i32` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:106:40 | LL | assert::is_transmutable::< i32, f64>(); - | ^^^ The size of `i32` is smaller than the size of `f64` + | ^^^ the size of `i32` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -587,7 +587,7 @@ error[E0277]: `i32` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:107:39 | LL | assert::is_transmutable::< i32, u128>(); - | ^^^^ The size of `i32` is smaller than the size of `u128` + | ^^^^ the size of `i32` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -602,7 +602,7 @@ error[E0277]: `i32` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:108:39 | LL | assert::is_transmutable::< i32, i128>(); - | ^^^^ The size of `i32` is smaller than the size of `i128` + | ^^^^ the size of `i32` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -617,7 +617,7 @@ error[E0277]: `f32` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:110:40 | LL | assert::is_transmutable::< f32, u64>(); - | ^^^ The size of `f32` is smaller than the size of `u64` + | ^^^ the size of `f32` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -632,7 +632,7 @@ error[E0277]: `f32` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:111:40 | LL | assert::is_transmutable::< f32, i64>(); - | ^^^ The size of `f32` is smaller than the size of `i64` + | ^^^ the size of `f32` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -647,7 +647,7 @@ error[E0277]: `f32` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:112:40 | LL | assert::is_transmutable::< f32, f64>(); - | ^^^ The size of `f32` is smaller than the size of `f64` + | ^^^ the size of `f32` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -662,7 +662,7 @@ error[E0277]: `f32` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:113:39 | LL | assert::is_transmutable::< f32, u128>(); - | ^^^^ The size of `f32` is smaller than the size of `u128` + | ^^^^ the size of `f32` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -677,7 +677,7 @@ error[E0277]: `f32` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:114:39 | LL | assert::is_transmutable::< f32, i128>(); - | ^^^^ The size of `f32` is smaller than the size of `i128` + | ^^^^ the size of `f32` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -692,7 +692,7 @@ error[E0277]: `u32` cannot be safely transmuted into `u64` --> $DIR/numbers.rs:116:40 | LL | assert::is_transmutable::< u32, u64>(); - | ^^^ The size of `u32` is smaller than the size of `u64` + | ^^^ the size of `u32` is smaller than the size of `u64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -707,7 +707,7 @@ error[E0277]: `u32` cannot be safely transmuted into `i64` --> $DIR/numbers.rs:117:40 | LL | assert::is_transmutable::< u32, i64>(); - | ^^^ The size of `u32` is smaller than the size of `i64` + | ^^^ the size of `u32` is smaller than the size of `i64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -722,7 +722,7 @@ error[E0277]: `u32` cannot be safely transmuted into `f64` --> $DIR/numbers.rs:118:40 | LL | assert::is_transmutable::< u32, f64>(); - | ^^^ The size of `u32` is smaller than the size of `f64` + | ^^^ the size of `u32` is smaller than the size of `f64` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -737,7 +737,7 @@ error[E0277]: `u32` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:119:39 | LL | assert::is_transmutable::< u32, u128>(); - | ^^^^ The size of `u32` is smaller than the size of `u128` + | ^^^^ the size of `u32` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -752,7 +752,7 @@ error[E0277]: `u32` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:120:39 | LL | assert::is_transmutable::< u32, i128>(); - | ^^^^ The size of `u32` is smaller than the size of `i128` + | ^^^^ the size of `u32` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -767,7 +767,7 @@ error[E0277]: `u64` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:122:39 | LL | assert::is_transmutable::< u64, u128>(); - | ^^^^ The size of `u64` is smaller than the size of `u128` + | ^^^^ the size of `u64` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -782,7 +782,7 @@ error[E0277]: `u64` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:123:39 | LL | assert::is_transmutable::< u64, i128>(); - | ^^^^ The size of `u64` is smaller than the size of `i128` + | ^^^^ the size of `u64` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -797,7 +797,7 @@ error[E0277]: `i64` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:125:39 | LL | assert::is_transmutable::< i64, u128>(); - | ^^^^ The size of `i64` is smaller than the size of `u128` + | ^^^^ the size of `i64` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -812,7 +812,7 @@ error[E0277]: `i64` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:126:39 | LL | assert::is_transmutable::< i64, i128>(); - | ^^^^ The size of `i64` is smaller than the size of `i128` + | ^^^^ the size of `i64` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -827,7 +827,7 @@ error[E0277]: `f64` cannot be safely transmuted into `u128` --> $DIR/numbers.rs:128:39 | LL | assert::is_transmutable::< f64, u128>(); - | ^^^^ The size of `f64` is smaller than the size of `u128` + | ^^^^ the size of `f64` is smaller than the size of `u128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 @@ -842,7 +842,7 @@ error[E0277]: `f64` cannot be safely transmuted into `i128` --> $DIR/numbers.rs:129:39 | LL | assert::is_transmutable::< f64, i128>(); - | ^^^^ The size of `f64` is smaller than the size of `i128` + | ^^^^ the size of `f64` is smaller than the size of `i128` | note: required by a bound in `is_transmutable` --> $DIR/numbers.rs:14:14 diff --git a/tests/ui/transmutability/primitives/unit.current.stderr b/tests/ui/transmutability/primitives/unit.current.stderr index b2831dbf842..52b708d680e 100644 --- a/tests/ui/transmutability/primitives/unit.current.stderr +++ b/tests/ui/transmutability/primitives/unit.current.stderr @@ -2,7 +2,7 @@ error[E0277]: `()` cannot be safely transmuted into `u8` --> $DIR/unit.rs:31:35 | LL | assert::is_transmutable::<(), u8>(); - | ^^ The size of `()` is smaller than the size of `u8` + | ^^ the size of `()` is smaller than the size of `u8` | note: required by a bound in `is_transmutable` --> $DIR/unit.rs:16:14 diff --git a/tests/ui/transmutability/primitives/unit.next.stderr b/tests/ui/transmutability/primitives/unit.next.stderr index b2831dbf842..52b708d680e 100644 --- a/tests/ui/transmutability/primitives/unit.next.stderr +++ b/tests/ui/transmutability/primitives/unit.next.stderr @@ -2,7 +2,7 @@ error[E0277]: `()` cannot be safely transmuted into `u8` --> $DIR/unit.rs:31:35 | LL | assert::is_transmutable::<(), u8>(); - | ^^ The size of `()` is smaller than the size of `u8` + | ^^ the size of `()` is smaller than the size of `u8` | note: required by a bound in `is_transmutable` --> $DIR/unit.rs:16:14 diff --git a/tests/ui/transmutability/references/recursive-wrapper-types-bit-incompatible.stderr b/tests/ui/transmutability/references/recursive-wrapper-types-bit-incompatible.stderr index 305fca30939..2b7cab1660d 100644 --- a/tests/ui/transmutability/references/recursive-wrapper-types-bit-incompatible.stderr +++ b/tests/ui/transmutability/references/recursive-wrapper-types-bit-incompatible.stderr @@ -2,7 +2,7 @@ error[E0277]: `B` cannot be safely transmuted into `A` --> $DIR/recursive-wrapper-types-bit-incompatible.rs:23:49 | LL | assert::is_maybe_transmutable::<&'static B, &'static A>(); - | ^^^^^^^^^^ At least one value of `B` isn't a bit-valid value of `A` + | ^^^^^^^^^^ at least one value of `B` isn't a bit-valid value of `A` | note: required by a bound in `is_maybe_transmutable` --> $DIR/recursive-wrapper-types-bit-incompatible.rs:9:14 diff --git a/tests/ui/transmutability/references/reject_extension.stderr b/tests/ui/transmutability/references/reject_extension.stderr index e02ef89c4a0..88dd0313e3c 100644 --- a/tests/ui/transmutability/references/reject_extension.stderr +++ b/tests/ui/transmutability/references/reject_extension.stderr @@ -2,7 +2,7 @@ error[E0277]: `&Packed<Two>` cannot be safely transmuted into `&Packed<Four>` --> $DIR/reject_extension.rs:48:37 | LL | assert::is_transmutable::<&Src, &Dst>(); - | ^^^^ The referent size of `&Packed<Two>` (2 bytes) is smaller than that of `&Packed<Four>` (4 bytes) + | ^^^^ the referent size of `&Packed<Two>` (2 bytes) is smaller than that of `&Packed<Four>` (4 bytes) | note: required by a bound in `is_transmutable` --> $DIR/reject_extension.rs:13:14 diff --git a/tests/ui/transmutability/references/unit-to-u8.stderr b/tests/ui/transmutability/references/unit-to-u8.stderr index 7cb45e24e0a..5d73dfdc8eb 100644 --- a/tests/ui/transmutability/references/unit-to-u8.stderr +++ b/tests/ui/transmutability/references/unit-to-u8.stderr @@ -2,7 +2,7 @@ error[E0277]: `&Unit` cannot be safely transmuted into `&u8` --> $DIR/unit-to-u8.rs:22:52 | LL | assert::is_maybe_transmutable::<&'static Unit, &'static u8>(); - | ^^^^^^^^^^^ The referent size of `&Unit` (0 bytes) is smaller than that of `&u8` (1 bytes) + | ^^^^^^^^^^^ the referent size of `&Unit` (0 bytes) is smaller than that of `&u8` (1 bytes) | note: required by a bound in `is_maybe_transmutable` --> $DIR/unit-to-u8.rs:9:14 diff --git a/tests/ui/transmutability/region-infer.stderr b/tests/ui/transmutability/region-infer.stderr index 5497af2429e..03c46823838 100644 --- a/tests/ui/transmutability/region-infer.stderr +++ b/tests/ui/transmutability/region-infer.stderr @@ -2,7 +2,7 @@ error[E0277]: `()` cannot be safely transmuted into `W<'_>` --> $DIR/region-infer.rs:18:5 | LL | test(); - | ^^^^^^ The size of `()` is smaller than the size of `W<'_>` + | ^^^^^^ the size of `()` is smaller than the size of `W<'_>` | note: required by a bound in `test` --> $DIR/region-infer.rs:10:12 diff --git a/tests/ui/transmutability/structs/repr/should_require_well_defined_layout.stderr b/tests/ui/transmutability/structs/repr/should_require_well_defined_layout.stderr index 924422de538..77788f72c21 100644 --- a/tests/ui/transmutability/structs/repr/should_require_well_defined_layout.stderr +++ b/tests/ui/transmutability/structs/repr/should_require_well_defined_layout.stderr @@ -2,7 +2,7 @@ error[E0277]: `should_reject_repr_rust::unit::repr_rust` cannot be safely transm --> $DIR/should_require_well_defined_layout.rs:27:52 | LL | assert::is_maybe_transmutable::<repr_rust, ()>(); - | ^^ `should_reject_repr_rust::unit::repr_rust` does not have a well-specified layout + | ^^ analyzing the transmutability of `should_reject_repr_rust::unit::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -24,7 +24,7 @@ error[E0277]: `u128` cannot be safely transmuted into `should_reject_repr_rust:: --> $DIR/should_require_well_defined_layout.rs:28:47 | LL | assert::is_maybe_transmutable::<u128, repr_rust>(); - | ^^^^^^^^^ `should_reject_repr_rust::unit::repr_rust` does not have a well-specified layout + | ^^^^^^^^^ analyzing the transmutability of `should_reject_repr_rust::unit::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -46,7 +46,7 @@ error[E0277]: `should_reject_repr_rust::tuple::repr_rust` cannot be safely trans --> $DIR/should_require_well_defined_layout.rs:33:52 | LL | assert::is_maybe_transmutable::<repr_rust, ()>(); - | ^^ `should_reject_repr_rust::tuple::repr_rust` does not have a well-specified layout + | ^^ analyzing the transmutability of `should_reject_repr_rust::tuple::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -68,7 +68,7 @@ error[E0277]: `u128` cannot be safely transmuted into `should_reject_repr_rust:: --> $DIR/should_require_well_defined_layout.rs:34:47 | LL | assert::is_maybe_transmutable::<u128, repr_rust>(); - | ^^^^^^^^^ `should_reject_repr_rust::tuple::repr_rust` does not have a well-specified layout + | ^^^^^^^^^ analyzing the transmutability of `should_reject_repr_rust::tuple::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -90,7 +90,7 @@ error[E0277]: `should_reject_repr_rust::braces::repr_rust` cannot be safely tran --> $DIR/should_require_well_defined_layout.rs:39:52 | LL | assert::is_maybe_transmutable::<repr_rust, ()>(); - | ^^ `should_reject_repr_rust::braces::repr_rust` does not have a well-specified layout + | ^^ analyzing the transmutability of `should_reject_repr_rust::braces::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -112,7 +112,7 @@ error[E0277]: `u128` cannot be safely transmuted into `should_reject_repr_rust:: --> $DIR/should_require_well_defined_layout.rs:40:47 | LL | assert::is_maybe_transmutable::<u128, repr_rust>(); - | ^^^^^^^^^ `should_reject_repr_rust::braces::repr_rust` does not have a well-specified layout + | ^^^^^^^^^ analyzing the transmutability of `should_reject_repr_rust::braces::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -134,7 +134,7 @@ error[E0277]: `aligned::repr_rust` cannot be safely transmuted into `()` --> $DIR/should_require_well_defined_layout.rs:45:52 | LL | assert::is_maybe_transmutable::<repr_rust, ()>(); - | ^^ `aligned::repr_rust` does not have a well-specified layout + | ^^ analyzing the transmutability of `aligned::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -156,7 +156,7 @@ error[E0277]: `u128` cannot be safely transmuted into `aligned::repr_rust` --> $DIR/should_require_well_defined_layout.rs:46:47 | LL | assert::is_maybe_transmutable::<u128, repr_rust>(); - | ^^^^^^^^^ `aligned::repr_rust` does not have a well-specified layout + | ^^^^^^^^^ analyzing the transmutability of `aligned::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -178,7 +178,7 @@ error[E0277]: `packed::repr_rust` cannot be safely transmuted into `()` --> $DIR/should_require_well_defined_layout.rs:51:52 | LL | assert::is_maybe_transmutable::<repr_rust, ()>(); - | ^^ `packed::repr_rust` does not have a well-specified layout + | ^^ analyzing the transmutability of `packed::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -200,7 +200,7 @@ error[E0277]: `u128` cannot be safely transmuted into `packed::repr_rust` --> $DIR/should_require_well_defined_layout.rs:52:47 | LL | assert::is_maybe_transmutable::<u128, repr_rust>(); - | ^^^^^^^^^ `packed::repr_rust` does not have a well-specified layout + | ^^^^^^^^^ analyzing the transmutability of `packed::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -222,7 +222,7 @@ error[E0277]: `nested::repr_c` cannot be safely transmuted into `()` --> $DIR/should_require_well_defined_layout.rs:58:49 | LL | assert::is_maybe_transmutable::<repr_c, ()>(); - | ^^ `nested::repr_c` does not have a well-specified layout + | ^^ analyzing the transmutability of `nested::repr_c` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -244,7 +244,7 @@ error[E0277]: `u128` cannot be safely transmuted into `nested::repr_c` --> $DIR/should_require_well_defined_layout.rs:59:47 | LL | assert::is_maybe_transmutable::<u128, repr_c>(); - | ^^^^^^ `nested::repr_c` does not have a well-specified layout + | ^^^^^^ analyzing the transmutability of `nested::repr_c` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 diff --git a/tests/ui/transmutability/transmute-padding-ice.stderr b/tests/ui/transmutability/transmute-padding-ice.stderr index c48a5cd80ce..4c121d463c6 100644 --- a/tests/ui/transmutability/transmute-padding-ice.stderr +++ b/tests/ui/transmutability/transmute-padding-ice.stderr @@ -2,7 +2,7 @@ error[E0277]: `B` cannot be safely transmuted into `A` --> $DIR/transmute-padding-ice.rs:25:40 | LL | assert::is_maybe_transmutable::<B, A>(); - | ^ The size of `B` is smaller than the size of `A` + | ^ the size of `B` is smaller than the size of `A` | note: required by a bound in `is_maybe_transmutable` --> $DIR/transmute-padding-ice.rs:10:14 diff --git a/tests/ui/transmutability/unions/repr/should_require_well_defined_layout.stderr b/tests/ui/transmutability/unions/repr/should_require_well_defined_layout.stderr index ee0e8a66434..bec07f13103 100644 --- a/tests/ui/transmutability/unions/repr/should_require_well_defined_layout.stderr +++ b/tests/ui/transmutability/unions/repr/should_require_well_defined_layout.stderr @@ -2,7 +2,7 @@ error[E0277]: `should_reject_repr_rust::repr_rust` cannot be safely transmuted i --> $DIR/should_require_well_defined_layout.rs:29:48 | LL | assert::is_maybe_transmutable::<repr_rust, ()>(); - | ^^ `should_reject_repr_rust::repr_rust` does not have a well-specified layout + | ^^ analyzing the transmutability of `should_reject_repr_rust::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 @@ -24,7 +24,7 @@ error[E0277]: `u128` cannot be safely transmuted into `should_reject_repr_rust:: --> $DIR/should_require_well_defined_layout.rs:30:43 | LL | assert::is_maybe_transmutable::<u128, repr_rust>(); - | ^^^^^^^^^ `should_reject_repr_rust::repr_rust` does not have a well-specified layout + | ^^^^^^^^^ analyzing the transmutability of `should_reject_repr_rust::repr_rust` is not yet supported. | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_require_well_defined_layout.rs:12:14 diff --git a/tests/ui/transmutability/unions/should_pad_variants.stderr b/tests/ui/transmutability/unions/should_pad_variants.stderr index 13b4c8053ad..da4294bdbce 100644 --- a/tests/ui/transmutability/unions/should_pad_variants.stderr +++ b/tests/ui/transmutability/unions/should_pad_variants.stderr @@ -2,7 +2,7 @@ error[E0277]: `Src` cannot be safely transmuted into `Dst` --> $DIR/should_pad_variants.rs:43:36 | LL | assert::is_transmutable::<Src, Dst>(); - | ^^^ The size of `Src` is smaller than the size of `Dst` + | ^^^ the size of `Src` is smaller than the size of `Dst` | note: required by a bound in `is_transmutable` --> $DIR/should_pad_variants.rs:13:14 diff --git a/tests/ui/transmutability/unions/should_reject_contraction.stderr b/tests/ui/transmutability/unions/should_reject_contraction.stderr index a3e387a0f84..20eaa3a6b09 100644 --- a/tests/ui/transmutability/unions/should_reject_contraction.stderr +++ b/tests/ui/transmutability/unions/should_reject_contraction.stderr @@ -2,7 +2,7 @@ error[E0277]: `Superset` cannot be safely transmuted into `Subset` --> $DIR/should_reject_contraction.rs:34:41 | LL | assert::is_transmutable::<Superset, Subset>(); - | ^^^^^^ At least one value of `Superset` isn't a bit-valid value of `Subset` + | ^^^^^^ at least one value of `Superset` isn't a bit-valid value of `Subset` | note: required by a bound in `is_transmutable` --> $DIR/should_reject_contraction.rs:12:14 diff --git a/tests/ui/transmutability/unions/should_reject_disjoint.stderr b/tests/ui/transmutability/unions/should_reject_disjoint.stderr index 447ab6d9de7..ea47797c970 100644 --- a/tests/ui/transmutability/unions/should_reject_disjoint.stderr +++ b/tests/ui/transmutability/unions/should_reject_disjoint.stderr @@ -2,7 +2,7 @@ error[E0277]: `A` cannot be safely transmuted into `B` --> $DIR/should_reject_disjoint.rs:32:40 | LL | assert::is_maybe_transmutable::<A, B>(); - | ^ At least one value of `A` isn't a bit-valid value of `B` + | ^ at least one value of `A` isn't a bit-valid value of `B` | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_reject_disjoint.rs:12:14 @@ -17,7 +17,7 @@ error[E0277]: `B` cannot be safely transmuted into `A` --> $DIR/should_reject_disjoint.rs:33:40 | LL | assert::is_maybe_transmutable::<B, A>(); - | ^ At least one value of `B` isn't a bit-valid value of `A` + | ^ at least one value of `B` isn't a bit-valid value of `A` | note: required by a bound in `is_maybe_transmutable` --> $DIR/should_reject_disjoint.rs:12:14 diff --git a/tests/ui/transmutability/unions/should_reject_intersecting.stderr b/tests/ui/transmutability/unions/should_reject_intersecting.stderr index f0763bc8be7..79dec659d9d 100644 --- a/tests/ui/transmutability/unions/should_reject_intersecting.stderr +++ b/tests/ui/transmutability/unions/should_reject_intersecting.stderr @@ -2,7 +2,7 @@ error[E0277]: `A` cannot be safely transmuted into `B` --> $DIR/should_reject_intersecting.rs:35:34 | LL | assert::is_transmutable::<A, B>(); - | ^ At least one value of `A` isn't a bit-valid value of `B` + | ^ at least one value of `A` isn't a bit-valid value of `B` | note: required by a bound in `is_transmutable` --> $DIR/should_reject_intersecting.rs:13:14 @@ -17,7 +17,7 @@ error[E0277]: `B` cannot be safely transmuted into `A` --> $DIR/should_reject_intersecting.rs:36:34 | LL | assert::is_transmutable::<B, A>(); - | ^ At least one value of `B` isn't a bit-valid value of `A` + | ^ at least one value of `B` isn't a bit-valid value of `A` | note: required by a bound in `is_transmutable` --> $DIR/should_reject_intersecting.rs:13:14 diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden4.rs b/tests/ui/type-alias-impl-trait/hkl_forbidden4.rs new file mode 100644 index 00000000000..ef9fe604ea7 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/hkl_forbidden4.rs @@ -0,0 +1,25 @@ +//! This test used to ICE because, while an error was emitted, +//! we still tried to remap generic params used in the hidden type +//! to the ones of the opaque type definition. + +//@ edition: 2021 + +#![feature(type_alias_impl_trait)] +use std::future::Future; + +type FutNothing<'a> = impl 'a + Future<Output = ()>; +//~^ ERROR: unconstrained opaque type + +async fn operation(_: &mut ()) -> () { + //~^ ERROR: concrete type differs from previous + call(operation).await +} + +async fn call<F>(_f: F) +where + for<'any> F: FnMut(&'any mut ()) -> FutNothing<'any>, +{ + //~^ ERROR: expected generic lifetime parameter, found `'any` +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr b/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr new file mode 100644 index 00000000000..d7a0452727e --- /dev/null +++ b/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr @@ -0,0 +1,34 @@ +error: unconstrained opaque type + --> $DIR/hkl_forbidden4.rs:10:23 + | +LL | type FutNothing<'a> = impl 'a + Future<Output = ()>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `FutNothing` must be used in combination with a concrete type within the same module + +error: concrete type differs from previous defining opaque type use + --> $DIR/hkl_forbidden4.rs:13:1 + | +LL | async fn operation(_: &mut ()) -> () { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `FutNothing<'_>`, got `{async fn body@$DIR/hkl_forbidden4.rs:13:38: 16:2}` + | +note: previous use here + --> $DIR/hkl_forbidden4.rs:15:5 + | +LL | call(operation).await + | ^^^^^^^^^^^^^^^ + +error[E0792]: expected generic lifetime parameter, found `'any` + --> $DIR/hkl_forbidden4.rs:21:1 + | +LL | type FutNothing<'a> = impl 'a + Future<Output = ()>; + | -- this generic parameter must be used with a generic lifetime parameter +... +LL | / { +LL | | +LL | | } + | |_^ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0792`. diff --git a/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.rs b/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.rs new file mode 100644 index 00000000000..fc71d0d61ff --- /dev/null +++ b/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.rs @@ -0,0 +1,52 @@ +// test for #110696 +// failed to resolve instance for <Scope<()> as MyIndex<()>>::my_index +// ignore-tidy-linelength + +#![feature(type_alias_impl_trait)] + +use std::marker::PhantomData; + + +trait MyIndex<T> { + type O; + fn my_index(self) -> Self::O; +} +trait MyFrom<T>: Sized { + type Error; + fn my_from(value: T) -> Result<Self, Self::Error>; +} + + +trait F {} +impl F for () {} +type DummyT<T> = impl F; +fn _dummy_t<T>() -> DummyT<T> {} + +struct Phantom1<T>(PhantomData<T>); +struct Phantom2<T>(PhantomData<T>); +struct Scope<T>(Phantom2<DummyT<T>>); + +impl<T> Scope<T> { + fn new() -> Self { + unimplemented!() + } +} + +impl<T> MyFrom<Phantom2<T>> for Phantom1<T> { + type Error = (); + fn my_from(_: Phantom2<T>) -> Result<Self, Self::Error> { + unimplemented!() + } +} + +impl<T: MyFrom<Phantom2<DummyT<U>>>, U> MyIndex<DummyT<T>> for Scope<U> { + //~^ ERROR the type parameter `T` is not constrained by the impl + type O = T; + fn my_index(self) -> Self::O { + MyFrom::my_from(self.0).ok().unwrap() + } +} + +fn main() { + let _pos: Phantom1<DummyT<()>> = Scope::new().my_index(); +} diff --git a/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.stderr b/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.stderr new file mode 100644 index 00000000000..a39f77ce17f --- /dev/null +++ b/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.stderr @@ -0,0 +1,9 @@ +error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates + --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:42:6 + | +LL | impl<T: MyFrom<Phantom2<DummyT<U>>>, U> MyIndex<DummyT<T>> for Scope<U> { + | ^ unconstrained type parameter + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0207`. diff --git a/tests/ui/type-alias-impl-trait/lifetime_mismatch.rs b/tests/ui/type-alias-impl-trait/lifetime_mismatch.rs new file mode 100644 index 00000000000..9ec585d93f5 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/lifetime_mismatch.rs @@ -0,0 +1,25 @@ +#![feature(type_alias_impl_trait)] + +type Foo<'a> = impl Sized; + +fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> (Foo<'a>, Foo<'b>) { + (x, y) + //~^ ERROR opaque type used twice with different lifetimes + //~| ERROR opaque type used twice with different lifetimes +} + +type Bar<'a, 'b> = impl std::fmt::Debug; + +fn bar<'x, 'y>(i: &'x i32, j: &'y i32) -> (Bar<'x, 'y>, Bar<'y, 'x>) { + (i, j) + //~^ ERROR opaque type used twice with different lifetimes + //~| ERROR opaque type used twice with different lifetimes + //~| ERROR opaque type used twice with different lifetimes + //~| ERROR opaque type used twice with different lifetimes +} + +fn main() { + let meh = 42; + let muh = 69; + println!("{:?}", bar(&meh, &muh)); +} diff --git a/tests/ui/type-alias-impl-trait/lifetime_mismatch.stderr b/tests/ui/type-alias-impl-trait/lifetime_mismatch.stderr new file mode 100644 index 00000000000..7f54f47d27d --- /dev/null +++ b/tests/ui/type-alias-impl-trait/lifetime_mismatch.stderr @@ -0,0 +1,95 @@ +error: opaque type used twice with different lifetimes + --> $DIR/lifetime_mismatch.rs:6:5 + | +LL | (x, y) + | ^^^^^^ + | | + | lifetime `'a` used here + | lifetime `'b` previously used here + | +note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + --> $DIR/lifetime_mismatch.rs:6:5 + | +LL | (x, y) + | ^^^^^^ + +error: opaque type used twice with different lifetimes + --> $DIR/lifetime_mismatch.rs:6:5 + | +LL | (x, y) + | ^^^^^^ + | | + | lifetime `'a` used here + | lifetime `'b` previously used here + | +note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + --> $DIR/lifetime_mismatch.rs:6:5 + | +LL | (x, y) + | ^^^^^^ + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: opaque type used twice with different lifetimes + --> $DIR/lifetime_mismatch.rs:14:5 + | +LL | (i, j) + | ^^^^^^ + | | + | lifetime `'x` used here + | lifetime `'y` previously used here + | +note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + --> $DIR/lifetime_mismatch.rs:14:5 + | +LL | (i, j) + | ^^^^^^ + +error: opaque type used twice with different lifetimes + --> $DIR/lifetime_mismatch.rs:14:5 + | +LL | (i, j) + | ^^^^^^ + | | + | lifetime `'y` used here + | lifetime `'x` previously used here + | +note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + --> $DIR/lifetime_mismatch.rs:14:5 + | +LL | (i, j) + | ^^^^^^ + +error: opaque type used twice with different lifetimes + --> $DIR/lifetime_mismatch.rs:14:5 + | +LL | (i, j) + | ^^^^^^ + | | + | lifetime `'x` used here + | lifetime `'y` previously used here + | +note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + --> $DIR/lifetime_mismatch.rs:14:5 + | +LL | (i, j) + | ^^^^^^ + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: opaque type used twice with different lifetimes + --> $DIR/lifetime_mismatch.rs:14:5 + | +LL | (i, j) + | ^^^^^^ + | | + | lifetime `'y` used here + | lifetime `'x` previously used here + | +note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + --> $DIR/lifetime_mismatch.rs:14:5 + | +LL | (i, j) + | ^^^^^^ + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 6 previous errors + diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs index 3f122f10609..5bec38c5e5b 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs @@ -3,7 +3,11 @@ type Foo<'a, 'b> = impl std::fmt::Debug; fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) { - (i, i) //~ ERROR concrete type differs from previous + (i, i) + //~^ ERROR opaque type used twice with different lifetimes + //~| ERROR opaque type used twice with different lifetimes + //~| ERROR opaque type used twice with different lifetimes + //~| ERROR opaque type used twice with different lifetimes } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr index 552cf3fda30..0ccb3e2221d 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr @@ -1,11 +1,64 @@ -error: concrete type differs from previous defining opaque type use +error: opaque type used twice with different lifetimes --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 | LL | (i, i) | ^^^^^^ | | - | expected `&'a i32`, got `&'b i32` - | this expression supplies two conflicting concrete types for the same opaque type + | lifetime `'x` used here + | lifetime `'y` previously used here + | +note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 + | +LL | (i, i) + | ^^^^^^ + +error: opaque type used twice with different lifetimes + --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 + | +LL | (i, i) + | ^^^^^^ + | | + | lifetime `'y` used here + | lifetime `'x` previously used here + | +note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 + | +LL | (i, i) + | ^^^^^^ + +error: opaque type used twice with different lifetimes + --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 + | +LL | (i, i) + | ^^^^^^ + | | + | lifetime `'x` used here + | lifetime `'y` previously used here + | +note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 + | +LL | (i, i) + | ^^^^^^ + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: opaque type used twice with different lifetimes + --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 + | +LL | (i, i) + | ^^^^^^ + | | + | lifetime `'y` used here + | lifetime `'x` previously used here + | +note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types + --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 + | +LL | (i, i) + | ^^^^^^ + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: aborting due to 1 previous error +error: aborting due to 4 previous errors diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs index 40c00e553a6..aba41a9d852 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs @@ -7,15 +7,11 @@ fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>) (a.clone(), a) } -type Foo<'a, 'b> = impl std::fmt::Debug; - -fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) { - (i, j) +type Tait<'x> = impl Sized; +fn define<'a: 'b, 'b: 'a>(x: &'a u8, y: &'b u8) -> (Tait<'a>, Tait<'b>) { + ((), ()) } fn main() { println!("{}", <X<_, _> as ToString>::to_string(&f(42_i32, String::new()).1)); - let meh = 42; - let muh = 69; - println!("{:?}", foo(&meh, &muh)); } diff --git a/tests/ui/type-alias-impl-trait/not_well_formed.fixed b/tests/ui/type-alias-impl-trait/not_well_formed.fixed deleted file mode 100644 index bd45d8cddae..00000000000 --- a/tests/ui/type-alias-impl-trait/not_well_formed.fixed +++ /dev/null @@ -1,19 +0,0 @@ -//@ run-rustfix -#![feature(type_alias_impl_trait)] -#![allow(dead_code)] - -fn main() {} - -trait TraitWithAssoc { - type Assoc; -} - -type Foo<V: TraitWithAssoc> = impl Trait<V::Assoc>; //~ associated type `Assoc` not found for `V` - -trait Trait<U> {} - -impl<W> Trait<W> for () {} - -fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T> { - () -} diff --git a/tests/ui/type-alias-impl-trait/not_well_formed.rs b/tests/ui/type-alias-impl-trait/not_well_formed.rs index 7b5444ae0d3..0cf8d41c7fd 100644 --- a/tests/ui/type-alias-impl-trait/not_well_formed.rs +++ b/tests/ui/type-alias-impl-trait/not_well_formed.rs @@ -1,4 +1,4 @@ -//@ run-rustfix +// Can't rustfix because we apply the suggestion twice :^( #![feature(type_alias_impl_trait)] #![allow(dead_code)] @@ -8,7 +8,9 @@ trait TraitWithAssoc { type Assoc; } -type Foo<V> = impl Trait<V::Assoc>; //~ associated type `Assoc` not found for `V` +type Foo<V> = impl Trait<V::Assoc>; +//~^ associated type `Assoc` not found for `V` +//~| associated type `Assoc` not found for `V` trait Trait<U> {} diff --git a/tests/ui/type-alias-impl-trait/not_well_formed.stderr b/tests/ui/type-alias-impl-trait/not_well_formed.stderr index dbd80ffa4f6..a2944a1acb9 100644 --- a/tests/ui/type-alias-impl-trait/not_well_formed.stderr +++ b/tests/ui/type-alias-impl-trait/not_well_formed.stderr @@ -9,6 +9,18 @@ help: consider restricting type parameter `V` LL | type Foo<V: TraitWithAssoc> = impl Trait<V::Assoc>; | ++++++++++++++++ -error: aborting due to 1 previous error +error[E0220]: associated type `Assoc` not found for `V` + --> $DIR/not_well_formed.rs:11:29 + | +LL | type Foo<V> = impl Trait<V::Assoc>; + | ^^^^^ there is an associated type `Assoc` in the trait `TraitWithAssoc` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: consider restricting type parameter `V` + | +LL | type Foo<V: TraitWithAssoc> = impl Trait<V::Assoc>; + | ++++++++++++++++ + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0220`. diff --git a/tests/ui/type-alias-impl-trait/param_mismatch.rs b/tests/ui/type-alias-impl-trait/param_mismatch.rs new file mode 100644 index 00000000000..c7465030713 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/param_mismatch.rs @@ -0,0 +1,16 @@ +//! This test checks that when checking for opaque types that +//! only differ in lifetimes, we handle the case of non-generic +//! regions correctly. +#![feature(type_alias_impl_trait)] + +fn id(s: &str) -> &str { + s +} +type Opaque<'a> = impl Sized + 'a; +// The second `Opaque<'_>` has a higher kinded lifetime, not a generic parameter +fn test(s: &str) -> (Opaque<'_>, impl Fn(&str) -> Opaque<'_>) { + (s, id) + //~^ ERROR: expected generic lifetime parameter, found `'_` +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/param_mismatch.stderr b/tests/ui/type-alias-impl-trait/param_mismatch.stderr new file mode 100644 index 00000000000..09ec550d718 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/param_mismatch.stderr @@ -0,0 +1,12 @@ +error[E0792]: expected generic lifetime parameter, found `'_` + --> $DIR/param_mismatch.rs:12:5 + | +LL | type Opaque<'a> = impl Sized + 'a; + | -- this generic parameter must be used with a generic lifetime parameter +... +LL | (s, id) + | ^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0792`. diff --git a/tests/ui/type-alias-impl-trait/param_mismatch2.rs b/tests/ui/type-alias-impl-trait/param_mismatch2.rs new file mode 100644 index 00000000000..c7d5eaa16aa --- /dev/null +++ b/tests/ui/type-alias-impl-trait/param_mismatch2.rs @@ -0,0 +1,16 @@ +//! This test checks that when checking for opaque types that +//! only differ in lifetimes, we handle the case of non-generic +//! regions correctly. +#![feature(type_alias_impl_trait)] + +fn id(s: &str) -> &str { + s +} + +type Opaque<'a> = impl Sized + 'a; + +fn test(s: &str) -> (impl Fn(&str) -> Opaque<'_>, impl Fn(&str) -> Opaque<'_>) { + (id, id) //~ ERROR: expected generic lifetime parameter, found `'_` +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/param_mismatch2.stderr b/tests/ui/type-alias-impl-trait/param_mismatch2.stderr new file mode 100644 index 00000000000..1ecdd7c2b54 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/param_mismatch2.stderr @@ -0,0 +1,12 @@ +error[E0792]: expected generic lifetime parameter, found `'_` + --> $DIR/param_mismatch2.rs:13:5 + | +LL | type Opaque<'a> = impl Sized + 'a; + | -- this generic parameter must be used with a generic lifetime parameter +... +LL | (id, id) + | ^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0792`. diff --git a/tests/ui/type-alias-impl-trait/param_mismatch3.rs b/tests/ui/type-alias-impl-trait/param_mismatch3.rs new file mode 100644 index 00000000000..03c133d5d3c --- /dev/null +++ b/tests/ui/type-alias-impl-trait/param_mismatch3.rs @@ -0,0 +1,26 @@ +//! This test checks that when checking for opaque types that +//! only differ in lifetimes, we handle the case of non-generic +//! regions correctly. +#![feature(type_alias_impl_trait)] + +fn id2<'a, 'b>(s: (&'a str, &'b str)) -> (&'a str, &'b str) { + s +} + +type Opaque<'a> = impl Sized + 'a; + +fn test() -> impl for<'a, 'b> Fn((&'a str, &'b str)) -> (Opaque<'a>, Opaque<'b>) { + id2 //~ ERROR expected generic lifetime parameter, found `'a` +} + +fn id(s: &str) -> &str { + s +} + +type Opaque2<'a> = impl Sized + 'a; + +fn test2(s: &str) -> (impl Fn(&str) -> Opaque2<'_>, Opaque2<'_>) { + (id, s) //~ ERROR: expected generic lifetime parameter, found `'_` +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/param_mismatch3.stderr b/tests/ui/type-alias-impl-trait/param_mismatch3.stderr new file mode 100644 index 00000000000..b8805f9b7f6 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/param_mismatch3.stderr @@ -0,0 +1,21 @@ +error[E0792]: expected generic lifetime parameter, found `'a` + --> $DIR/param_mismatch3.rs:13:5 + | +LL | type Opaque<'a> = impl Sized + 'a; + | -- this generic parameter must be used with a generic lifetime parameter +... +LL | id2 + | ^^^ + +error[E0792]: expected generic lifetime parameter, found `'_` + --> $DIR/param_mismatch3.rs:23:5 + | +LL | type Opaque2<'a> = impl Sized + 'a; + | -- this generic parameter must be used with a generic lifetime parameter +... +LL | (id, s) + | ^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0792`. diff --git a/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.rs b/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.rs new file mode 100644 index 00000000000..37e0d89efc7 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.rs @@ -0,0 +1,16 @@ +// test for ICE #121472 index out of bounds un_derefer.rs +#![feature(type_alias_impl_trait)] + +trait T {} + +type Alias<'a> = impl T; + +struct S; +impl<'a> T for &'a S {} + +fn with_positive(fun: impl Fn(Alias<'_>)) {} + +fn main() { + with_positive(|&n| ()); + //~^ ERROR mismatched types +} diff --git a/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.stderr b/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.stderr new file mode 100644 index 00000000000..a224bab0705 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.stderr @@ -0,0 +1,23 @@ +error[E0308]: mismatched types + --> $DIR/underef-index-out-of-bounds-121472.rs:14:20 + | +LL | type Alias<'a> = impl T; + | ------ the expected opaque type +... +LL | with_positive(|&n| ()); + | ^^ + | | + | expected opaque type, found `&_` + | expected due to this + | + = note: expected opaque type `Alias<'_>` + found reference `&_` +help: consider removing `&` from the pattern + | +LL - with_positive(|&n| ()); +LL + with_positive(|n| ()); + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.stderr b/tests/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.stderr index 229729a9ba6..8c23eaea62e 100644 --- a/tests/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.stderr +++ b/tests/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.stderr @@ -5,8 +5,7 @@ LL | / match i { LL | | // Add `bool` to the overall `coercion`. LL | | 0 => true, | | ---- this is found to be of type `bool` -LL | | -LL | | // Necessary to cause the ICE: +... | LL | | 1 => true, | | ---- this is found to be of type `bool` ... | diff --git a/tests/ui/typeck/escaping_bound_vars.rs b/tests/ui/typeck/escaping_bound_vars.rs index f886388bfbd..985a3fdbccf 100644 --- a/tests/ui/typeck/escaping_bound_vars.rs +++ b/tests/ui/typeck/escaping_bound_vars.rs @@ -11,9 +11,6 @@ where (): Test<{ 1 + (<() as Elide(&())>::call) }>, //~^ ERROR cannot capture late-bound lifetime in constant //~| ERROR associated type bindings are not allowed here - //~| ERROR the trait bound `(): Elide<(&(),)>` is not satisfied - //~| ERROR the trait bound `(): Elide<(&(),)>` is not satisfied - //~| ERROR cannot add { } diff --git a/tests/ui/typeck/escaping_bound_vars.stderr b/tests/ui/typeck/escaping_bound_vars.stderr index 8c7dcdb7f16..bd9c95fab97 100644 --- a/tests/ui/typeck/escaping_bound_vars.stderr +++ b/tests/ui/typeck/escaping_bound_vars.stderr @@ -12,49 +12,6 @@ error[E0229]: associated type bindings are not allowed here LL | (): Test<{ 1 + (<() as Elide(&())>::call) }>, | ^^^^^^^^^^ associated type not allowed here -error[E0277]: the trait bound `(): Elide<(&(),)>` is not satisfied - --> $DIR/escaping_bound_vars.rs:11:22 - | -LL | (): Test<{ 1 + (<() as Elide(&())>::call) }>, - | ^^ the trait `Elide<(&(),)>` is not implemented for `()` - | -help: this trait has no implementations, consider adding one - --> $DIR/escaping_bound_vars.rs:5:1 - | -LL | trait Elide<T> { - | ^^^^^^^^^^^^^^ - -error[E0277]: cannot add `fn() {<() as Elide<(&(),)>>::call}` to `{integer}` - --> $DIR/escaping_bound_vars.rs:11:18 - | -LL | (): Test<{ 1 + (<() as Elide(&())>::call) }>, - | ^ no implementation for `{integer} + fn() {<() as Elide<(&(),)>>::call}` - | - = help: the trait `Add<fn() {<() as Elide<(&(),)>>::call}>` is not implemented for `{integer}` - = help: the following other types implement trait `Add<Rhs>`: - <isize as Add> - <isize as Add<&isize>> - <i8 as Add> - <i8 as Add<&i8>> - <i16 as Add> - <i16 as Add<&i16>> - <i32 as Add> - <i32 as Add<&i32>> - and 48 others - -error[E0277]: the trait bound `(): Elide<(&(),)>` is not satisfied - --> $DIR/escaping_bound_vars.rs:11:18 - | -LL | (): Test<{ 1 + (<() as Elide(&())>::call) }>, - | ^ the trait `Elide<(&(),)>` is not implemented for `()` - | -help: this trait has no implementations, consider adding one - --> $DIR/escaping_bound_vars.rs:5:1 - | -LL | trait Elide<T> { - | ^^^^^^^^^^^^^^ - -error: aborting due to 5 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0229, E0277. -For more information about an error, try `rustc --explain E0229`. +For more information about this error, try `rustc --explain E0229`. diff --git a/tests/ui/typeck/issue-91267.stderr b/tests/ui/typeck/issue-91267.stderr index 7e48b251980..399309d0ec4 100644 --- a/tests/ui/typeck/issue-91267.stderr +++ b/tests/ui/typeck/issue-91267.stderr @@ -17,6 +17,8 @@ LL | fn main() { | - expected `()` because of default return type LL | type_ascribe!(0, u8<e<5>=e>) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `u8` + | + = note: this error originates in the macro `type_ascribe` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 3 previous errors diff --git a/tests/ui/typeck/typeck_type_placeholder_item.stderr b/tests/ui/typeck/typeck_type_placeholder_item.stderr index e8f1de1ad04..8bcad56916a 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -673,7 +673,10 @@ LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); | ^^^^^^^^^^^^^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0015]: cannot call non-const fn `<Filter<std::ops::Range<i32>, {closure@$DIR/typeck_type_placeholder_item.rs:230:29: 230:32}> as Iterator>::map::<i32, {closure@$DIR/typeck_type_placeholder_item.rs:230:49: 230:52}>` in constants --> $DIR/typeck_type_placeholder_item.rs:230:45 @@ -682,7 +685,10 @@ LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); | ^^^^^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + | +LL + #![feature(const_trait_impl)] + | error[E0515]: cannot return reference to function parameter `x` --> $DIR/typeck_type_placeholder_item.rs:50:5 diff --git a/tests/ui/unboxed-closures/unboxed-closure-sugar-region.rs b/tests/ui/unboxed-closures/unboxed-closure-sugar-region.rs index 8537eb71774..ea73b8b3c4a 100644 --- a/tests/ui/unboxed-closures/unboxed-closure-sugar-region.rs +++ b/tests/ui/unboxed-closures/unboxed-closure-sugar-region.rs @@ -33,7 +33,6 @@ fn test2(x: &dyn Foo<(isize,),Output=()>, y: &dyn Foo(isize)) { //~^ ERROR trait takes 1 lifetime argument but 0 lifetime arguments were supplied // Here, the omitted lifetimes are expanded to distinct things. same_type(x, y) - //~^ ERROR borrowed data escapes outside of function } fn main() { } diff --git a/tests/ui/unboxed-closures/unboxed-closure-sugar-region.stderr b/tests/ui/unboxed-closures/unboxed-closure-sugar-region.stderr index 6e6c649ca3d..d73aef851fd 100644 --- a/tests/ui/unboxed-closures/unboxed-closure-sugar-region.stderr +++ b/tests/ui/unboxed-closures/unboxed-closure-sugar-region.stderr @@ -34,22 +34,6 @@ note: trait defined here, with 1 lifetime parameter: `'a` LL | trait Foo<'a,T> { | ^^^ -- -error[E0521]: borrowed data escapes outside of function - --> $DIR/unboxed-closure-sugar-region.rs:35:5 - | -LL | fn test2(x: &dyn Foo<(isize,),Output=()>, y: &dyn Foo(isize)) { - | - - `y` declared here, outside of the function body - | | - | `x` is a reference that is only valid in the function body - | has type `&dyn Foo<'1, (isize,), Output = ()>` -... -LL | same_type(x, y) - | ^^^^^^^^^^^^^^^ - | | - | `x` escapes the function body here - | argument requires that `'1` must outlive `'static` - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0107, E0521. -For more information about an error, try `rustc --explain E0107`. +For more information about this error, try `rustc --explain E0107`. diff --git a/tests/ui/unboxed-closures/unboxed-closures-type-mismatch-closure-from-another-scope.stderr b/tests/ui/unboxed-closures/unboxed-closures-type-mismatch-closure-from-another-scope.stderr index 1470c32d7de..5f22c781345 100644 --- a/tests/ui/unboxed-closures/unboxed-closures-type-mismatch-closure-from-another-scope.stderr +++ b/tests/ui/unboxed-closures/unboxed-closures-type-mismatch-closure-from-another-scope.stderr @@ -26,11 +26,11 @@ note: closure parameter defined here LL | let mut closure = expect_sig(|p, y| *p = y); | ^ -error[E0425]: cannot find function `deref` in this scope +error[E0423]: expected function, found macro `deref` --> $DIR/unboxed-closures-type-mismatch-closure-from-another-scope.rs:13:5 | LL | deref(p); - | ^^^^^ not found in this scope + | ^^^^^ not a function | help: use the `.` operator to call the method `Deref::deref` on `&&()` | @@ -40,5 +40,5 @@ LL + p.deref(); error: aborting due to 4 previous errors -Some errors have detailed explanations: E0308, E0425. +Some errors have detailed explanations: E0308, E0423, E0425. For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/underscore-lifetime/underscore-lifetime-binders.rs b/tests/ui/underscore-lifetime/underscore-lifetime-binders.rs index ebc38798544..3d049cc5639 100644 --- a/tests/ui/underscore-lifetime/underscore-lifetime-binders.rs +++ b/tests/ui/underscore-lifetime/underscore-lifetime-binders.rs @@ -14,7 +14,6 @@ fn meh() -> Box<dyn for<'_> Meh<'_>> //~ ERROR cannot be used here } fn foo2(_: &'_ u8, y: &'_ u8) -> &'_ u8 { y } //~ ERROR missing lifetime specifier -//~^ ERROR lifetime may not live long enough fn main() { let x = 5; diff --git a/tests/ui/underscore-lifetime/underscore-lifetime-binders.stderr b/tests/ui/underscore-lifetime/underscore-lifetime-binders.stderr index 5d2954d1d71..cd74d27dcb5 100644 --- a/tests/ui/underscore-lifetime/underscore-lifetime-binders.stderr +++ b/tests/ui/underscore-lifetime/underscore-lifetime-binders.stderr @@ -45,15 +45,7 @@ help: consider introducing a named lifetime parameter LL | fn foo2<'a>(_: &'a u8, y: &'a u8) -> &'a u8 { y } | ++++ ~~ ~~ ~~ -error: lifetime may not live long enough - --> $DIR/underscore-lifetime-binders.rs:16:43 - | -LL | fn foo2(_: &'_ u8, y: &'_ u8) -> &'_ u8 { y } - | - ^ returning this value requires that `'1` must outlive `'static` - | | - | let's call the lifetime of this reference `'1` - -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors Some errors have detailed explanations: E0106, E0637. For more information about an error, try `rustc --explain E0106`. diff --git a/tests/ui/unop-move-semantics.stderr b/tests/ui/unop-move-semantics.stderr index b6de7976ac9..187dd66b2fe 100644 --- a/tests/ui/unop-move-semantics.stderr +++ b/tests/ui/unop-move-semantics.stderr @@ -9,7 +9,7 @@ LL | LL | x.clone(); | ^ value borrowed here after move | -note: calling this operator moves the left-hand side +note: calling this operator moves the value --> $SRC_DIR/core/src/ops/bit.rs:LL:COL help: consider cloning the value if the performance cost is acceptable | @@ -57,7 +57,7 @@ LL | !*m; | |move occurs because `*m` has type `T`, which does not implement the `Copy` trait | `*m` moved due to usage in operator | -note: calling this operator moves the left-hand side +note: calling this operator moves the value --> $SRC_DIR/core/src/ops/bit.rs:LL:COL error[E0507]: cannot move out of `*n` which is behind a shared reference diff --git a/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.rs b/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.rs new file mode 100644 index 00000000000..107cfbb9ff6 --- /dev/null +++ b/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.rs @@ -0,0 +1,12 @@ +trait Trait<const N: Trait = bar> { +//~^ ERROR cannot find value `bar` in this scope +//~| ERROR cycle detected when computing type of `Trait::N` +//~| ERROR cycle detected when computing type of `Trait::N` +//~| ERROR `(dyn Trait<{const error}> + 'static)` is forbidden as the type of a const generic parameter +//~| WARN trait objects without an explicit `dyn` are deprecated +//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + fn fnc(&self) { + } +} + +fn main() {} diff --git a/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.stderr b/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.stderr new file mode 100644 index 00000000000..2d5a0ede962 --- /dev/null +++ b/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.stderr @@ -0,0 +1,60 @@ +error[E0425]: cannot find value `bar` in this scope + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:1:30 + | +LL | trait Trait<const N: Trait = bar> { + | ^^^ not found in this scope + +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:1:22 + | +LL | trait Trait<const N: Trait = bar> { + | ^^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> + = note: `#[warn(bare_trait_objects)]` on by default +help: if this is an object-safe trait, use `dyn` + | +LL | trait Trait<const N: dyn Trait = bar> { + | +++ + +error[E0391]: cycle detected when computing type of `Trait::N` + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:1:22 + | +LL | trait Trait<const N: Trait = bar> { + | ^^^^^ + | + = note: ...which immediately requires computing type of `Trait::N` again +note: cycle used when computing explicit predicates of trait `Trait` + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:1:1 + | +LL | trait Trait<const N: Trait = bar> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information + +error[E0391]: cycle detected when computing type of `Trait::N` + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:1:13 + | +LL | trait Trait<const N: Trait = bar> { + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: ...which immediately requires computing type of `Trait::N` again +note: cycle used when computing explicit predicates of trait `Trait` + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:1:1 + | +LL | trait Trait<const N: Trait = bar> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information + +error: `(dyn Trait<{const error}> + 'static)` is forbidden as the type of a const generic parameter + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:1:22 + | +LL | trait Trait<const N: Trait = bar> { + | ^^^^^ + | + = note: the only supported types are integers, `bool` and `char` + +error: aborting due to 4 previous errors; 1 warning emitted + +Some errors have detailed explanations: E0391, E0425. +For more information about an error, try `rustc --explain E0391`. diff --git a/tests/ui/wf/wf-in-foreign-fn-decls-issue-80468.rs b/tests/ui/wf/wf-in-foreign-fn-decls-issue-80468.rs index 0be5127dcc4..e6d4e2ee01a 100644 --- a/tests/ui/wf/wf-in-foreign-fn-decls-issue-80468.rs +++ b/tests/ui/wf/wf-in-foreign-fn-decls-issue-80468.rs @@ -14,4 +14,5 @@ impl Trait for Ref {} //~ ERROR: implicit elided lifetime not allowed here extern "C" { pub fn repro(_: Wrapper<Ref>); + //~^ ERROR the trait bound `Ref<'_>: Trait` is not satisfied } diff --git a/tests/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr b/tests/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr index 0af4ab022e1..59b55b2732d 100644 --- a/tests/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr +++ b/tests/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr @@ -9,6 +9,19 @@ help: indicate the anonymous lifetime LL | impl Trait for Ref<'_> {} | ++++ -error: aborting due to 1 previous error +error[E0277]: the trait bound `Ref<'_>: Trait` is not satisfied + --> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:21 + | +LL | pub fn repro(_: Wrapper<Ref>); + | ^^^^^^^^^^^^ the trait `Trait` is not implemented for `Ref<'_>` + | +note: required by a bound in `Wrapper` + --> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:8:23 + | +LL | pub struct Wrapper<T: Trait>(T); + | ^^^^^ required by this bound in `Wrapper` + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0726`. +Some errors have detailed explanations: E0277, E0726. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr b/tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr index 4cb3cdd69ad..bb99f4ad277 100644 --- a/tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr +++ b/tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr @@ -1,8 +1,8 @@ -error[E0277]: the trait bound `for<Region(BrNamed(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), 'b))> fn(&ReBound(DebruijnIndex(1), BoundRegion { var: 0, kind: BrNamed(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), 'b) }) ()): Foo` is not satisfied +error[E0277]: the trait bound `for<Region(BrNamed(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), 'b))> fn(&'^1_0.Named(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), "'b") ()): Foo` is not satisfied --> $DIR/higher-ranked-fn-type.rs:20:5 | LL | called() - | ^^^^^^^^ the trait `for<Region(BrNamed(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), 'b))> Foo` is not implemented for `fn(&ReBound(DebruijnIndex(1), BoundRegion { var: 0, kind: BrNamed(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), 'b) }) ())` + | ^^^^^^^^ the trait `for<Region(BrNamed(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), 'b))> Foo` is not implemented for `fn(&'^1_0.Named(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), "'b") ())` | help: this trait has no implementations, consider adding one --> $DIR/higher-ranked-fn-type.rs:6:1 diff --git a/triagebot.toml b/triagebot.toml index c972dce1a02..4e163a3bb1c 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -499,6 +499,10 @@ of `ObligationCtxt`. """ cc = ["@lcnr", "@compiler-errors"] +[mentions."compiler/rustc_hir_analysis/src/hir_ty_lowering"] +message = "HIR ty lowering was modified" +cc = ["@fmease"] + [mentions."compiler/rustc_error_codes/src/lib.rs"] message = "Some changes occurred in diagnostic error codes" cc = ["@GuillaumeGomez"] @@ -515,6 +519,9 @@ cc = ["@Nadrieril"] message = "Some changes occurred in exhaustiveness checking" cc = ["@Nadrieril"] +[mentions."compiler/rustc_lint/src/context/diagnostics/check_cfg.rs"] +cc = ["@Urgau"] + [mentions."library/core/src/intrinsics/simd.rs"] message = """ Some changes occurred to the platform-builtins intrinsics. Make sure the @@ -548,6 +555,10 @@ cc = ["@GuillaumeGomez"] message = "Some changes occurred in GUI tests." cc = ["@GuillaumeGomez"] +[mentions."tests/run-make/"] +message = "Some changes occurred in run-make tests." +cc = ["@jieyouxu"] + [mentions."src/librustdoc/html/static/css/themes/ayu.css"] message = "A change occurred in the Ayu theme." cc = ["@Cldfire"] @@ -571,10 +582,17 @@ cc = ["@ehuss"] [mentions."src/tools/clippy"] cc = ["@rust-lang/clippy"] +[mentions."src/tools/compiletest"] +cc = ["@jieyouxu"] + [mentions."src/tools/miri"] message = "The Miri subtree was changed" cc = ["@rust-lang/miri"] +[mentions."src/tools/run-make-support"] +message = "The run-make-support library was changed" +cc = ["@jieyouxu"] + [mentions."src/tools/rust-analyzer"] message = """ rust-analyzer is developed in its own repository. If possible, consider making \ @@ -688,6 +706,9 @@ cc = ["@rust-lang/project-exploit-mitigations", "@rcvalle"] [mentions."src/doc/unstable-book/src/language-features/no-sanitize.md"] cc = ["@rust-lang/project-exploit-mitigations", "@rcvalle"] +[mentions."src/doc/unstable-book/src/compiler-flags/check-cfg.md"] +cc = ["@Urgau"] + [mentions."tests/codegen/sanitizer"] cc = ["@rust-lang/project-exploit-mitigations", "@rcvalle"] @@ -706,6 +727,33 @@ cc = ["@rust-lang/project-exploit-mitigations", "@rcvalle"] [mentions."tests/ui/stack-protector"] cc = ["@rust-lang/project-exploit-mitigations", "@rcvalle"] +[mentions."tests/ui/check-cfg"] +cc = ["@Urgau"] + +[mentions."compiler/rustc_middle/src/mir/coverage.rs"] +message = "Some changes occurred in coverage instrumentation." +cc = ["@Zalathar"] + +[mentions."compiler/rustc_mir_build/src/build/coverageinfo.rs"] +message = "Some changes occurred in coverage instrumentation." +cc = ["@Zalathar"] + +[mentions."compiler/rustc_mir_transform/src/coverage"] +message = "Some changes occurred in coverage instrumentation." +cc = ["@Zalathar"] + +[mentions."compiler/rustc_codegen_llvm/src/coverageinfo"] +message = "Some changes occurred in coverage instrumentation." +cc = ["@Zalathar"] + +[mentions."compiler/rustc_codegen_ssa/src/mir/coverageinfo.rs"] +message = "Some changes occurred in coverage instrumentation." +cc = ["@Zalathar"] + +[mentions."tests/coverage"] +message = "Some changes occurred in coverage tests." +cc = ["@Zalathar"] + [assign] warn_non_default_branch = true contributing_url = "https://rustc-dev-guide.rust-lang.org/getting-started.html" |
