From 870e5a26ee465a935050ee04f8edbb520d5278e6 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 15 Jun 2025 00:26:43 +0000 Subject: [PATCH 01/14] cargo update compiler & tools dependencies: Locking 31 packages to latest compatible versions Updating adler2 v2.0.0 -> v2.0.1 Updating cfg-if v1.0.0 -> v1.0.1 Updating clap v4.5.39 -> v4.5.40 Updating clap_builder v4.5.39 -> v4.5.40 Updating clap_derive v4.5.32 -> v4.5.40 Updating clap_lex v0.7.4 -> v0.7.5 Updating getopts v0.2.21 -> v0.2.23 Updating hermit-abi v0.5.1 -> v0.5.2 Updating jiff v0.2.14 -> v0.2.15 Updating jiff-static v0.2.14 -> v0.2.15 Updating libc v0.2.172 -> v0.2.173 Updating memchr v2.7.4 -> v2.7.5 Updating minifier v0.3.5 -> v0.3.6 Updating miniz_oxide v0.8.8 -> v0.8.9 Updating object v0.37.0 -> v0.37.1 Updating redox_syscall v0.5.12 -> v0.5.13 Updating rustc-demangle v0.1.24 -> v0.1.25 Updating syn v2.0.101 -> v2.0.103 Updating thread_local v1.1.8 -> v1.1.9 Updating unicode-width v0.2.0 -> v0.2.1 Updating wasi v0.11.0+wasi-snapshot-preview1 -> v0.11.1+wasi-snapshot-preview1 Updating wasm-encoder v0.233.0 -> v0.235.0 Removing wasmparser v0.232.0 Removing wasmparser v0.233.0 Adding wasmparser v0.234.0 Adding wasmparser v0.235.0 Updating wast v233.0.0 -> v235.0.0 Updating wat v1.233.0 -> v1.235.0 Updating windows v0.61.1 -> v0.61.3 Updating windows-link v0.1.1 -> v0.1.3 Adding windows-sys v0.60.2 Updating windows-targets v0.53.0 -> v0.53.2 Updating winnow v0.7.10 -> v0.7.11 note: pass `--verbose` to see 39 unchanged dependencies behind latest library dependencies: Locking 1 package to latest compatible version Updating libc v0.2.172 -> v0.2.173 note: pass `--verbose` to see 4 unchanged dependencies behind latest rustbook dependencies: Locking 19 packages to latest compatible versions Updating adler2 v2.0.0 -> v2.0.1 Updating cc v1.2.26 -> v1.2.27 Updating cfg-if v1.0.0 -> v1.0.1 Updating clap v4.5.39 -> v4.5.40 Updating clap_builder v4.5.39 -> v4.5.40 Updating clap_complete v4.5.52 -> v4.5.54 Updating clap_derive v4.5.32 -> v4.5.40 Updating clap_lex v0.7.4 -> v0.7.5 Updating getopts v0.2.21 -> v0.2.23 Updating jiff v0.2.14 -> v0.2.15 Updating jiff-static v0.2.14 -> v0.2.15 Updating libc v0.2.172 -> v0.2.173 Updating memchr v2.7.4 -> v2.7.5 Updating miniz_oxide v0.8.8 -> v0.8.9 Updating redox_syscall v0.5.12 -> v0.5.13 Updating syn v2.0.101 -> v2.0.103 Removing unicode-width v0.1.14 Removing unicode-width v0.2.0 Adding unicode-width v0.2.1 Updating windows-link v0.1.1 -> v0.1.3 Updating winnow v0.7.10 -> v0.7.11 --- Cargo.lock | 240 ++++++++++++++++++---------------- library/Cargo.lock | 4 +- src/tools/rustbook/Cargo.lock | 86 ++++++------ 3 files changed, 166 insertions(+), 164 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index df2842bddb386..2b107b11cff81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "adler2" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "aes" @@ -75,7 +75,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "710e8eae58854cdc1790fcb56cca04d712a17be849eeb81da2a724bf4bae2bc4" dependencies = [ "anstyle", - "unicode-width 0.2.0", + "unicode-width 0.2.1", ] [[package]] @@ -136,7 +136,7 @@ dependencies = [ "anstyle-lossy", "anstyle-parse", "html-escape", - "unicode-width 0.2.0", + "unicode-width 0.2.1", ] [[package]] @@ -204,7 +204,7 @@ dependencies = [ "rustc-hash 2.1.1", "serde", "serde_derive", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -216,7 +216,7 @@ dependencies = [ "memchr", "serde", "serde_derive", - "winnow 0.7.10", + "winnow 0.7.11", ] [[package]] @@ -431,9 +431,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "cfg_aliases" @@ -487,9 +487,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.39" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd60e63e9be68e5fb56422e397cf9baddded06dae1d2e523401542383bc72a9f" +checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" dependencies = [ "clap_builder", "clap_derive", @@ -507,9 +507,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.39" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89cc6392a1f72bbeb820d71f32108f61fdaf18bc526e1d23954168a67759ef51" +checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" dependencies = [ "anstream", "anstyle", @@ -519,21 +519,21 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.32" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" +checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] name = "clap_lex" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "clippy" @@ -558,7 +558,7 @@ dependencies = [ "rustc_tools_util 0.4.2", "serde", "serde_json", - "syn 2.0.101", + "syn 2.0.103", "tempfile", "termize", "tokio", @@ -673,7 +673,7 @@ dependencies = [ "nom", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -748,7 +748,7 @@ dependencies = [ "encode_unicode", "libc", "once_cell", - "unicode-width 0.2.0", + "unicode-width 0.2.1", "windows-sys 0.59.0", ] @@ -900,7 +900,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -911,7 +911,7 @@ checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" dependencies = [ "darling_core", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -939,7 +939,7 @@ checksum = "e73f2692d4bd3cac41dca28934a39894200c9fabf49586d77d0e5954af1d7902" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -960,7 +960,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -970,7 +970,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" dependencies = [ "derive_builder_core", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -982,7 +982,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -1050,7 +1050,7 @@ dependencies = [ "libc", "option-ext", "redox_users 0.5.0", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -1072,7 +1072,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -1352,7 +1352,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -1416,11 +1416,11 @@ dependencies = [ [[package]] name = "getopts" -version = "0.2.21" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +checksum = "cba6ae63eb948698e300f645f87c70f76630d505f23b8907cf1e193ee85048c1" dependencies = [ - "unicode-width 0.1.14", + "unicode-width 0.2.1", ] [[package]] @@ -1431,7 +1431,7 @@ checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi 0.11.1+wasi-snapshot-preview1", ] [[package]] @@ -1511,9 +1511,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f154ce46856750ed433c8649605bf7ed2de3bc35fd9d2a9f30cddd873c80cb08" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" [[package]] name = "hex" @@ -1775,7 +1775,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -1859,7 +1859,7 @@ dependencies = [ "console", "number_prefix", "portable-atomic", - "unicode-width 0.2.0", + "unicode-width 0.2.1", "web-time", ] @@ -1933,9 +1933,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "jiff" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a194df1107f33c79f4f93d02c80798520551949d59dfad22b6157048a88cca93" +checksum = "be1f93b8b1eb69c77f24bbb0afdf66f54b632ee39af40ca21c4365a1d7347e49" dependencies = [ "jiff-static", "log", @@ -1946,13 +1946,13 @@ dependencies = [ [[package]] name = "jiff-static" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c6e1db7ed32c6c71b759497fae34bf7933636f75a251b9e736555da426f6442" +checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -2045,9 +2045,9 @@ checksum = "9fa0e2a1fcbe2f6be6c42e342259976206b383122fc152e872795338b5a3f3a7" [[package]] name = "libc" -version = "0.2.172" +version = "0.2.173" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +checksum = "d8cfeafaffdbc32176b64fb251369d52ea9f0a8fbc6f8759edffef7b525d64bb" [[package]] name = "libdbus-sys" @@ -2085,7 +2085,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" dependencies = [ "cfg-if", - "windows-targets 0.53.0", + "windows-targets 0.53.2", ] [[package]] @@ -2223,7 +2223,7 @@ checksum = "88a9689d8d44bf9964484516275f5cd4c9b59457a6940c1d5d0ecbb94510a36b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -2261,9 +2261,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "memmap2" @@ -2276,9 +2276,9 @@ dependencies = [ [[package]] name = "minifier" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bfdc64e2f805f3d12965f10522000bae36e88d2cfea44112331f467d4f4bf68" +checksum = "14f1541610994bba178cb36757e102d06a52a2d9612aa6d34c64b3b377c5d943" [[package]] name = "minimal-lexical" @@ -2288,9 +2288,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" dependencies = [ "adler2", ] @@ -2512,15 +2512,15 @@ dependencies = [ [[package]] name = "object" -version = "0.37.0" +version = "0.37.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6273adb7096cf9ab4335f258e627d8230e69d40d45567d678f552dcec6245215" +checksum = "03fd943161069e1768b4b3d050890ba48730e590f57e56d4aa04e7e090e61b4a" dependencies = [ "crc32fast", "hashbrown", "indexmap", "memchr", - "wasmparser 0.232.0", + "wasmparser 0.234.0", ] [[package]] @@ -2725,7 +2725,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -3014,9 +3014,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.12" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" +checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6" dependencies = [ "bitflags", ] @@ -3148,9 +3148,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.24" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" [[package]] name = "rustc-hash" @@ -3440,7 +3440,7 @@ dependencies = [ "itertools", "libc", "measureme", - "object 0.37.0", + "object 0.37.1", "rustc-demangle", "rustc_abi", "rustc_ast", @@ -3481,7 +3481,7 @@ dependencies = [ "either", "itertools", "libc", - "object 0.37.0", + "object 0.37.1", "pathdiff", "regex", "rustc_abi", @@ -3741,7 +3741,7 @@ dependencies = [ "fluent-syntax", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", "unic-langid", ] @@ -3890,7 +3890,7 @@ version = "0.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -4037,7 +4037,7 @@ version = "0.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", "synstructure", ] @@ -4242,7 +4242,7 @@ dependencies = [ "thin-vec", "tracing", "unicode-normalization", - "unicode-width 0.2.0", + "unicode-width 0.2.1", ] [[package]] @@ -4491,7 +4491,7 @@ dependencies = [ "sha1", "sha2", "tracing", - "unicode-width 0.2.0", + "unicode-width 0.2.1", ] [[package]] @@ -4516,7 +4516,7 @@ name = "rustc_target" version = "0.0.0" dependencies = [ "bitflags", - "object 0.37.0", + "object 0.37.1", "rustc_abi", "rustc_data_structures", "rustc_fs_util", @@ -4637,7 +4637,7 @@ version = "0.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", "synstructure", ] @@ -4728,7 +4728,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -4856,7 +4856,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -5096,9 +5096,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.101" +version = "2.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +checksum = "e4307e30089d6fd6aff212f2da3a1f9e32f3223b1f010fb09b7c95f90f3ca1e8" dependencies = [ "proc-macro2", "quote", @@ -5113,7 +5113,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -5246,7 +5246,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -5257,7 +5257,7 @@ checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -5274,12 +5274,11 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.1.8" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" dependencies = [ "cfg-if", - "once_cell", ] [[package]] @@ -5433,7 +5432,7 @@ checksum = "1b1ffbcf9c6f6b99d386e7444eb608ba646ae452a36b39737deb9663b610f662" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -5604,7 +5603,7 @@ checksum = "a1249a628de3ad34b821ecb1001355bca3940bcb2f88558f1a8bd82e977f75b5" dependencies = [ "proc-macro-hack", "quote", - "syn 2.0.101", + "syn 2.0.103", "unic-langid-impl", ] @@ -5672,9 +5671,9 @@ checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "unicode-width" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" +checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c" [[package]] name = "unicode-xid" @@ -5775,9 +5774,9 @@ dependencies = [ [[package]] name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasi" @@ -5816,7 +5815,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", "wasm-bindgen-shared", ] @@ -5838,7 +5837,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5901,12 +5900,12 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.233.0" +version = "0.235.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9679ae3cf7cfa2ca3a327f7fab97f27f3294d402fd1a76ca8ab514e17973e4d3" +checksum = "b3bc393c395cb621367ff02d854179882b9a351b4e0c93d1397e6090b53a5c2a" dependencies = [ "leb128fmt", - "wasmparser 0.233.0", + "wasmparser 0.235.0", ] [[package]] @@ -5946,18 +5945,18 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.232.0" +version = "0.234.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "917739b33bb1eb0e9a49bcd2637a351931be4578d0cc4d37b908d7a797784fbb" +checksum = "be22e5a8f600afce671dd53c8d2dd26b4b7aa810fd18ae27dfc49737f3e02fc5" dependencies = [ "bitflags", ] [[package]] name = "wasmparser" -version = "0.233.0" +version = "0.235.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b51cb03afce7964bbfce46602d6cb358726f36430b6ba084ac6020d8ce5bc102" +checksum = "161296c618fa2d63f6ed5fffd1112937e803cb9ec71b32b01a76321555660917" dependencies = [ "bitflags", "indexmap", @@ -5966,22 +5965,22 @@ dependencies = [ [[package]] name = "wast" -version = "233.0.0" +version = "235.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eaf4099d8d0c922b83bf3c90663f5666f0769db9e525184284ebbbdb1dd2180" +checksum = "1eda4293f626c99021bb3a6fbe4fbbe90c0e31a5ace89b5f620af8925de72e13" dependencies = [ "bumpalo", "leb128fmt", "memchr", - "unicode-width 0.2.0", - "wasm-encoder 0.233.0", + "unicode-width 0.2.1", + "wasm-encoder 0.235.0", ] [[package]] name = "wat" -version = "1.233.0" +version = "1.235.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d9bc80f5e4b25ea086ef41b91ccd244adde45d931c384d94a8ff64ab8bd7d87" +checksum = "e777e0327115793cb96ab220b98f85327ec3d11f34ec9e8d723264522ef206aa" dependencies = [ "wast", ] @@ -6029,9 +6028,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.61.1" +version = "0.61.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5ee8f3d025738cb02bad7868bbb5f8a6327501e870bf51f1b455b0a2454a419" +checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" dependencies = [ "windows-collections", "windows-core", @@ -6092,7 +6091,7 @@ checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -6103,14 +6102,14 @@ checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] name = "windows-link" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] name = "windows-numerics" @@ -6167,6 +6166,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.2", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -6200,9 +6208,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.53.0" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b" +checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef" dependencies = [ "windows_aarch64_gnullvm 0.53.0", "windows_aarch64_msvc 0.53.0", @@ -6372,9 +6380,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" +checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" dependencies = [ "memchr", ] @@ -6507,7 +6515,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", "synstructure", ] @@ -6519,7 +6527,7 @@ checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", "synstructure", ] @@ -6540,7 +6548,7 @@ checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -6560,7 +6568,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", "synstructure", ] @@ -6605,7 +6613,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] [[package]] @@ -6616,5 +6624,5 @@ checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.101", + "syn 2.0.103", ] diff --git a/library/Cargo.lock b/library/Cargo.lock index 1bd97e7b5273b..c7d59655ea462 100644 --- a/library/Cargo.lock +++ b/library/Cargo.lock @@ -141,9 +141,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.172" +version = "0.2.173" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +checksum = "d8cfeafaffdbc32176b64fb251369d52ea9f0a8fbc6f8759edffef7b525d64bb" dependencies = [ "rustc-std-workspace-core", ] diff --git a/src/tools/rustbook/Cargo.lock b/src/tools/rustbook/Cargo.lock index ed67fa7d1a9e3..3e83a2168ff1a 100644 --- a/src/tools/rustbook/Cargo.lock +++ b/src/tools/rustbook/Cargo.lock @@ -4,9 +4,9 @@ version = 4 [[package]] name = "adler2" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "aho-corasick" @@ -156,18 +156,18 @@ checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee" [[package]] name = "cc" -version = "1.2.26" +version = "1.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956a5e21988b87f372569b66183b78babf23ebc2e744b733e4350a752c4dafac" +checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc" dependencies = [ "shlex", ] [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "chrono" @@ -185,9 +185,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.39" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd60e63e9be68e5fb56422e397cf9baddded06dae1d2e523401542383bc72a9f" +checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" dependencies = [ "clap_builder", "clap_derive", @@ -195,9 +195,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.39" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89cc6392a1f72bbeb820d71f32108f61fdaf18bc526e1d23954168a67759ef51" +checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" dependencies = [ "anstream", "anstyle", @@ -208,18 +208,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.5.52" +version = "4.5.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a554639e42d0c838336fc4fbedb9e2df3ad1fa4acda149f9126b4ccfcd7900f" +checksum = "aad5b1b4de04fead402672b48897030eec1f3bfe1550776322f59f6d6e6a5677" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.5.32" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" +checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" dependencies = [ "heck", "proc-macro2", @@ -229,9 +229,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "colorchoice" @@ -527,11 +527,11 @@ dependencies = [ [[package]] name = "getopts" -version = "0.2.21" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +checksum = "cba6ae63eb948698e300f645f87c70f76630d505f23b8907cf1e193ee85048c1" dependencies = [ - "unicode-width 0.1.14", + "unicode-width", ] [[package]] @@ -768,9 +768,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "jiff" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a194df1107f33c79f4f93d02c80798520551949d59dfad22b6157048a88cca93" +checksum = "be1f93b8b1eb69c77f24bbb0afdf66f54b632ee39af40ca21c4365a1d7347e49" dependencies = [ "jiff-static", "log", @@ -781,9 +781,9 @@ dependencies = [ [[package]] name = "jiff-static" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c6e1db7ed32c6c71b759497fae34bf7933636f75a251b9e736555da426f6442" +checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4" dependencies = [ "proc-macro2", "quote", @@ -808,9 +808,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.172" +version = "0.2.173" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +checksum = "d8cfeafaffdbc32176b64fb251369d52ea9f0a8fbc6f8759edffef7b525d64bb" [[package]] name = "linereader" @@ -966,15 +966,15 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "miniz_oxide" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" dependencies = [ "adler2", ] @@ -1325,7 +1325,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5b8e8a7c20c600f9b98cbf46b64e63d5c9e69deb98cee1ff264de9f1dda5d" dependencies = [ - "unicode-width 0.2.0", + "unicode-width", ] [[package]] @@ -1345,9 +1345,9 @@ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" [[package]] name = "redox_syscall" -version = "0.5.12" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" +checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6" dependencies = [ "bitflags 2.9.1", ] @@ -1548,9 +1548,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.101" +version = "2.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +checksum = "e4307e30089d6fd6aff212f2da3a1f9e32f3223b1f010fb09b7c95f90f3ca1e8" dependencies = [ "proc-macro2", "quote", @@ -1760,15 +1760,9 @@ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "unicode-width" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" - -[[package]] -name = "unicode-width" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" +checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c" [[package]] name = "url" @@ -1940,9 +1934,9 @@ dependencies = [ [[package]] name = "windows-link" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] name = "windows-result" @@ -2037,9 +2031,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" +checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" dependencies = [ "memchr", ] From 7c1553c85bf0c6566bffa5a22e91a9c517458ab9 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 16 Jun 2025 07:30:09 -0400 Subject: [PATCH 02/14] Bless unicode test Most likely caused by updating unicode-width v0.2.0 -> v0.2.1, the change seems reasonable enough. --- .../ui/diagnostic-width/non-whitespace-trimming-unicode.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/diagnostic-width/non-whitespace-trimming-unicode.stderr b/tests/ui/diagnostic-width/non-whitespace-trimming-unicode.stderr index 5408825d8cd6d..18d80810ab0c3 100644 --- a/tests/ui/diagnostic-width/non-whitespace-trimming-unicode.stderr +++ b/tests/ui/diagnostic-width/non-whitespace-trimming-unicode.stderr @@ -1,7 +1,7 @@ error[E0308]: mismatched types --> $DIR/non-whitespace-trimming-unicode.rs:4:415 | -LL | ...♣♤♥♦♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚈⚉4"; let _: () = 42; let _: &str = "🦀☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓ ☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳☴☵☶☷☸☹☺☻☼... +LL | ...♣♤♥♦♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚈⚉4"; let _: () = 42; let _: &str = "🦀☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓ ☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳☴☵☶☷☸☹☺☻☼☽ ... | -- ^^ expected `()`, found integer | | | expected due to this From 442862bc78b24f6019e4f3e32cfe2380dd480f26 Mon Sep 17 00:00:00 2001 From: Boxy Date: Thu, 24 Apr 2025 10:49:06 +0100 Subject: [PATCH 03/14] Don't build `ParamEnv` and do trait solving in `ItemCtxt`s --- compiler/rustc_hir_analysis/src/collect.rs | 70 +++++++- .../src/hir_ty_lowering/errors.rs | 7 +- .../src/hir_ty_lowering/mod.rs | 151 +++++------------- compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs | 76 ++++++++- .../rustc_middle/src/ty/inhabitedness/mod.rs | 10 +- compiler/rustc_type_ir/src/fast_reject.rs | 7 + tests/crashes/136678.rs | 18 --- tests/crashes/138131.rs | 9 +- .../bound_vars_in_args.rs | 23 +++ .../bound_vars_in_args.stderr | 37 +++++ .../bugs/cycle-iat-inside-of-adt.stderr | 33 ---- .../cycle-iat-inside-of-where-predicate.rs | 16 -- ...cycle-iat-inside-of-where-predicate.stderr | 37 ----- .../candidate-with-alias-2.rs | 26 +++ .../candidate-with-alias-2.stderr | 20 +++ .../candidate-with-alias.rs | 27 ++++ .../iat-in-where-bound.rs | 14 ++ ...-inside-of-adt.rs => iat-inside-of-adt.rs} | 9 +- .../inhabited-predicates.rs} | 7 +- .../inhabited-predicates.stderr | 27 ++++ .../multiple-candidates-in-adt-field-1.rs | 23 +++ .../multiple-candidates-in-adt-field-2.rs | 29 ++++ .../multiple-candidates-in-adt-field-2.stderr | 20 +++ .../multiple-candidates-in-adt-field-3.rs | 27 ++++ ...-self-type-differs-shadowing-trait-item.rs | 2 +- ...fers-shadowing-trait-item.uncovered.stderr | 18 +-- .../really_deep_self_ty_mismatch.rs | 26 +++ .../const-generics/mgca/unresolved-iac-1.rs | 11 ++ .../mgca/unresolved-iac-1.stderr | 16 ++ .../const-generics/mgca/unresolved-iac-2.rs | 14 ++ .../mgca/unresolved-iac-2.stderr | 15 ++ 31 files changed, 576 insertions(+), 249 deletions(-) delete mode 100644 tests/crashes/136678.rs create mode 100644 tests/ui/associated-inherent-types/bound_vars_in_args.rs create mode 100644 tests/ui/associated-inherent-types/bound_vars_in_args.stderr delete mode 100644 tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-adt.stderr delete mode 100644 tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-where-predicate.rs delete mode 100644 tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-where-predicate.stderr create mode 100644 tests/ui/associated-inherent-types/candidate-with-alias-2.rs create mode 100644 tests/ui/associated-inherent-types/candidate-with-alias-2.stderr create mode 100644 tests/ui/associated-inherent-types/candidate-with-alias.rs create mode 100644 tests/ui/associated-inherent-types/iat-in-where-bound.rs rename tests/ui/associated-inherent-types/{bugs/cycle-iat-inside-of-adt.rs => iat-inside-of-adt.rs} (61%) rename tests/{crashes/125879.rs => ui/associated-inherent-types/inhabited-predicates.rs} (50%) create mode 100644 tests/ui/associated-inherent-types/inhabited-predicates.stderr create mode 100644 tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-1.rs create mode 100644 tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-2.rs create mode 100644 tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-2.stderr create mode 100644 tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-3.rs create mode 100644 tests/ui/associated-inherent-types/really_deep_self_ty_mismatch.rs create mode 100644 tests/ui/const-generics/mgca/unresolved-iac-1.rs create mode 100644 tests/ui/const-generics/mgca/unresolved-iac-1.stderr create mode 100644 tests/ui/const-generics/mgca/unresolved-iac-2.rs create mode 100644 tests/ui/const-generics/mgca/unresolved-iac-2.stderr diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 6e22ac5a28a85..fd8c702a76b34 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -34,16 +34,22 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::traits::{DynCompatibilityViolation, ObligationCause}; use rustc_middle::query::Providers; use rustc_middle::ty::util::{Discr, IntTypeExt}; -use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypingMode, fold_regions}; +use rustc_middle::ty::{ + self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, TypingMode, fold_regions, +}; use rustc_middle::{bug, span_bug}; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; use rustc_trait_selection::error_reporting::traits::suggestions::NextTypeParamName; use rustc_trait_selection::infer::InferCtxtExt; -use rustc_trait_selection::traits::{ObligationCtxt, hir_ty_lowering_dyn_compatibility_violations}; +use rustc_trait_selection::traits::{ + FulfillmentError, ObligationCtxt, hir_ty_lowering_dyn_compatibility_violations, +}; use tracing::{debug, instrument}; use crate::errors; -use crate::hir_ty_lowering::{FeedConstTy, HirTyLowerer, RegionInferReason}; +use crate::hir_ty_lowering::{ + FeedConstTy, HirTyLowerer, InherentAssocCandidate, RegionInferReason, +}; pub(crate) mod dump; mod generics_of; @@ -364,6 +370,64 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { self.tcx.at(span).type_param_predicates((self.item_def_id, def_id, assoc_ident)) } + #[instrument(level = "debug", skip(self, _span), ret)] + fn select_inherent_assoc_candidates( + &self, + _span: Span, + self_ty: Ty<'tcx>, + candidates: Vec, + ) -> (Vec, Vec>) { + assert!(!self_ty.has_infer()); + + // We don't just call the normal normalization routine here as we can't provide the + // correct `ParamEnv` and it seems dubious to invoke arbitrary trait solving under + // the wrong `ParamEnv`. Expanding free aliases doesn't need a `ParamEnv` so we do + // this just to make resolution a little bit smarter. + let self_ty = self.tcx.expand_free_alias_tys(self_ty); + debug!("select_inherent_assoc_candidates: self_ty={:?}", self_ty); + + // We make an infcx and replace any escaping vars with placeholders so that IAT res + // with type/const bound vars in arguments is slightly smarter. `for >::IAT` + // would otherwise unify with `impl Foo` when ideally we would not. + let infcx = self.tcx().infer_ctxt().build(TypingMode::non_body_analysis()); + let mut universes = if self_ty.has_escaping_bound_vars() { + vec![None; self_ty.outer_exclusive_binder().as_usize()] + } else { + vec![] + }; + let candidates = + rustc_trait_selection::traits::with_replaced_escaping_bound_vars( + &infcx, + &mut universes, + self_ty, + |self_ty| { + candidates + .into_iter() + .filter(|&InherentAssocCandidate { impl_, .. }| { + let impl_ty = self.tcx().type_of(impl_).instantiate_identity(); + + // See comment on doing this operation for `self_ty` + let impl_ty = self.tcx.expand_free_alias_tys(impl_ty); + debug!("select_inherent_assoc_candidates: impl_ty={:?}", impl_ty); + + // We treat parameters in the self ty as rigid and parameters in the impl ty as infers + // because it allows `impl Foo` to unify with `Foo::IAT`, while also disallowing + // `Foo::IAT` from unifying with `impl Foo`. + // + // We don't really care about a depth limit here because we're only working with user-written types + // and if they wrote a type that would take hours to walk then that's kind of on them. On the other + // hand the default depth limit is relatively low and could realistically be hit by users in normal + // cases. + ty::DeepRejectCtxt::relate_rigid_infer(self.tcx) + .types_may_unify_with_depth(self_ty, impl_ty, usize::MAX) + }) + .collect() + }, + ); + + (candidates, vec![]) + } + fn lower_assoc_item_path( &self, span: Span, diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs index 45fee0fa4024e..f62e149191da0 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs @@ -26,6 +26,7 @@ use rustc_trait_selection::traits::{ use smallvec::SmallVec; use tracing::debug; +use super::InherentAssocCandidate; use crate::errors::{ self, AssocItemConstraintsNotAllowedHere, ManualImplementation, MissingTypeParams, ParenthesizedFnTraitExpansion, TraitObjectDeclaredWithNoTraits, @@ -742,7 +743,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { &self, name: Ident, self_ty: Ty<'tcx>, - candidates: Vec<(DefId, (DefId, DefId))>, + candidates: Vec, fulfillment_errors: Vec>, span: Span, assoc_tag: ty::AssocTag, @@ -776,8 +777,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { let type_candidates = candidates .iter() .take(limit) - .map(|&(impl_, _)| { - format!("- `{}`", tcx.at(span).type_of(impl_).instantiate_identity()) + .map(|cand| { + format!("- `{}`", tcx.at(span).type_of(cand.impl_).instantiate_identity()) }) .collect::>() .join("\n"); diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index bf407cbaccb5a..b99f7b44661ec 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -33,13 +33,14 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, AnonConst, GenericArg, GenericArgs, HirId}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; -use rustc_infer::traits::{DynCompatibilityViolation, ObligationCause}; +use rustc_infer::traits::DynCompatibilityViolation; +use rustc_macros::{TypeFoldable, TypeVisitable}; use rustc_middle::middle::stability::AllowUnstable; use rustc_middle::mir::interpret::LitToConstInput; use rustc_middle::ty::print::PrintPolyTraitRefExt as _; use rustc_middle::ty::{ - self, Const, GenericArgKind, GenericArgsRef, GenericParamDefKind, ParamEnv, Ty, TyCtxt, - TypeVisitableExt, TypingMode, Upcast, fold_regions, + self, Const, GenericArgKind, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, TypeVisitableExt, + TypingMode, Upcast, fold_regions, }; use rustc_middle::{bug, span_bug}; use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS; @@ -47,7 +48,7 @@ use rustc_session::parse::feature_err; use rustc_span::{DUMMY_SP, Ident, Span, kw, sym}; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::wf::object_region_bounds; -use rustc_trait_selection::traits::{self, ObligationCtxt}; +use rustc_trait_selection::traits::{self, FulfillmentError}; use tracing::{debug, instrument}; use crate::check::check_abi_fn_ptr; @@ -99,6 +100,13 @@ pub enum RegionInferReason<'a> { OutlivesBound, } +#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Debug)] +pub struct InherentAssocCandidate { + pub impl_: DefId, + pub assoc_item: DefId, + pub scope: DefId, +} + /// A context which can lower type-system entities from the [HIR][hir] to /// the [`rustc_middle::ty`] representation. /// @@ -148,6 +156,13 @@ pub trait HirTyLowerer<'tcx> { assoc_ident: Ident, ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]>; + fn select_inherent_assoc_candidates( + &self, + span: Span, + self_ty: Ty<'tcx>, + candidates: Vec, + ) -> (Vec, Vec>); + /// Lower a path to an associated item (of a trait) to a projection. /// /// This method has to be defined by the concrete lowering context because @@ -1449,48 +1464,32 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { .filter_map(|&impl_| { let (item, scope) = self.probe_assoc_item_unchecked(name, assoc_tag, block, impl_)?; - Some((impl_, (item.def_id, scope))) + Some(InherentAssocCandidate { impl_, assoc_item: item.def_id, scope }) }) .collect(); - if candidates.is_empty() { - return Ok(None); - } - - // - // Select applicable inherent associated type candidates modulo regions. - // - - // In contexts that have no inference context, just make a new one. - // We do need a local variable to store it, though. - let infcx = match self.infcx() { - Some(infcx) => infcx, - None => { - assert!(!self_ty.has_infer()); - &tcx.infer_ctxt().ignoring_regions().build(TypingMode::non_body_analysis()) - } - }; + let (applicable_candidates, fulfillment_errors) = + self.select_inherent_assoc_candidates(span, self_ty, candidates.clone()); - // FIXME(inherent_associated_types): Acquiring the ParamEnv this early leads to cycle errors - // when inside of an ADT (#108491) or where clause. - let param_env = tcx.param_env(block.owner); + let InherentAssocCandidate { impl_, assoc_item, scope: def_scope } = + match &applicable_candidates[..] { + &[] => Err(self.report_unresolved_inherent_assoc_item( + name, + self_ty, + candidates, + fulfillment_errors, + span, + assoc_tag, + )), - let mut universes = if self_ty.has_escaping_bound_vars() { - vec![None; self_ty.outer_exclusive_binder().as_usize()] - } else { - vec![] - }; + &[applicable_candidate] => Ok(applicable_candidate), - let (impl_, (assoc_item, def_scope)) = crate::traits::with_replaced_escaping_bound_vars( - infcx, - &mut universes, - self_ty, - |self_ty| { - self.select_inherent_assoc_candidates( - infcx, name, span, self_ty, param_env, candidates, assoc_tag, - ) - }, - )?; + &[_, ..] => Err(self.report_ambiguous_inherent_assoc_item( + name, + candidates.into_iter().map(|cand| cand.assoc_item).collect(), + span, + )), + }?; self.check_assoc_item(assoc_item, name, def_scope, block, span); @@ -1507,78 +1506,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { Ok(Some((assoc_item, args))) } - fn select_inherent_assoc_candidates( - &self, - infcx: &InferCtxt<'tcx>, - name: Ident, - span: Span, - self_ty: Ty<'tcx>, - param_env: ParamEnv<'tcx>, - candidates: Vec<(DefId, (DefId, DefId))>, - assoc_tag: ty::AssocTag, - ) -> Result<(DefId, (DefId, DefId)), ErrorGuaranteed> { - let tcx = self.tcx(); - let mut fulfillment_errors = Vec::new(); - - let applicable_candidates: Vec<_> = candidates - .iter() - .copied() - .filter(|&(impl_, _)| { - infcx.probe(|_| { - let ocx = ObligationCtxt::new_with_diagnostics(infcx); - let self_ty = ocx.normalize(&ObligationCause::dummy(), param_env, self_ty); - - let impl_args = infcx.fresh_args_for_item(span, impl_); - let impl_ty = tcx.type_of(impl_).instantiate(tcx, impl_args); - let impl_ty = ocx.normalize(&ObligationCause::dummy(), param_env, impl_ty); - - // Check that the self types can be related. - if ocx.eq(&ObligationCause::dummy(), param_env, impl_ty, self_ty).is_err() { - return false; - } - - // Check whether the impl imposes obligations we have to worry about. - let impl_bounds = tcx.predicates_of(impl_).instantiate(tcx, impl_args); - let impl_bounds = - ocx.normalize(&ObligationCause::dummy(), param_env, impl_bounds); - let impl_obligations = traits::predicates_for_generics( - |_, _| ObligationCause::dummy(), - param_env, - impl_bounds, - ); - ocx.register_obligations(impl_obligations); - - let mut errors = ocx.select_where_possible(); - if !errors.is_empty() { - fulfillment_errors.append(&mut errors); - return false; - } - - true - }) - }) - .collect(); - - match &applicable_candidates[..] { - &[] => Err(self.report_unresolved_inherent_assoc_item( - name, - self_ty, - candidates, - fulfillment_errors, - span, - assoc_tag, - )), - - &[applicable_candidate] => Ok(applicable_candidate), - - &[_, ..] => Err(self.report_ambiguous_inherent_assoc_item( - name, - applicable_candidates.into_iter().map(|(_, (candidate, _))| candidate).collect(), - span, - )), - } - } - /// Given name and kind search for the assoc item in the provided scope and check if it's accessible[^1]. /// /// [^1]: I.e., accessible in the provided scope wrt. visibility and stability. diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index e979798a40294..d8efb0aac4d75 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -12,7 +12,9 @@ use hir::def_id::CRATE_DEF_ID; use rustc_errors::DiagCtxtHandle; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, HirId, ItemLocalMap}; -use rustc_hir_analysis::hir_ty_lowering::{HirTyLowerer, RegionInferReason}; +use rustc_hir_analysis::hir_ty_lowering::{ + HirTyLowerer, InherentAssocCandidate, RegionInferReason, +}; use rustc_infer::infer; use rustc_infer::traits::{DynCompatibilityViolation, Obligation}; use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt}; @@ -20,7 +22,9 @@ use rustc_session::Session; use rustc_span::{self, DUMMY_SP, ErrorGuaranteed, Ident, Span, sym}; use rustc_trait_selection::error_reporting::TypeErrCtxt; use rustc_trait_selection::error_reporting::infer::sub_relations::SubRelations; -use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode, ObligationCtxt}; +use rustc_trait_selection::traits::{ + self, FulfillmentError, ObligationCause, ObligationCauseCode, ObligationCtxt, +}; use crate::coercion::DynamicCoerceMany; use crate::fallback::DivergingFallbackBehavior; @@ -310,6 +314,74 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { )) } + fn select_inherent_assoc_candidates( + &self, + span: Span, + self_ty: Ty<'tcx>, + candidates: Vec, + ) -> (Vec, Vec>) { + let tcx = self.tcx(); + let infcx = &self.infcx; + + let mut universes = if self_ty.has_escaping_bound_vars() { + vec![None; self_ty.outer_exclusive_binder().as_usize()] + } else { + vec![] + }; + + let mut fulfillment_errors = vec![]; + let candidates = + traits::with_replaced_escaping_bound_vars(infcx, &mut universes, self_ty, |self_ty| { + candidates + .into_iter() + .filter(|&InherentAssocCandidate { impl_, .. }| { + infcx.probe(|_| { + let ocx = ObligationCtxt::new_with_diagnostics(self); + let self_ty = + ocx.normalize(&ObligationCause::dummy(), self.param_env, self_ty); + + let impl_args = infcx.fresh_args_for_item(span, impl_); + let impl_ty = tcx.type_of(impl_).instantiate(tcx, impl_args); + let impl_ty = + ocx.normalize(&ObligationCause::dummy(), self.param_env, impl_ty); + + // Check that the self types can be related. + if ocx + .eq(&ObligationCause::dummy(), self.param_env, impl_ty, self_ty) + .is_err() + { + return false; + } + + // Check whether the impl imposes obligations we have to worry about. + let impl_bounds = tcx.predicates_of(impl_).instantiate(tcx, impl_args); + let impl_bounds = ocx.normalize( + &ObligationCause::dummy(), + self.param_env, + impl_bounds, + ); + let impl_obligations = traits::predicates_for_generics( + |_, _| ObligationCause::dummy(), + self.param_env, + impl_bounds, + ); + ocx.register_obligations(impl_obligations); + + let mut errors = ocx.select_where_possible(); + if !errors.is_empty() { + fulfillment_errors.append(&mut errors); + return false; + } + + true + }) + }) + .collect() + }); + + (candidates, fulfillment_errors) + } + fn lower_assoc_item_path( &self, span: Span, diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs index d8bab58545fcc..2a336cc21f492 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs @@ -127,7 +127,9 @@ impl<'tcx> Ty<'tcx> { InhabitedPredicate::True } Never => InhabitedPredicate::False, - Param(_) | Alias(ty::Projection | ty::Free, _) => InhabitedPredicate::GenericType(self), + Param(_) | Alias(ty::Inherent | ty::Projection | ty::Free, _) => { + InhabitedPredicate::GenericType(self) + } Alias(ty::Opaque, alias_ty) => { match alias_ty.def_id.as_local() { // Foreign opaque is considered inhabited. @@ -139,12 +141,6 @@ impl<'tcx> Ty<'tcx> { } } } - // FIXME(inherent_associated_types): Most likely we can just map to `GenericType` like above. - // However it's unclear if the args passed to `InhabitedPredicate::instantiate` are of the correct - // format, i.e. don't contain parent args. If you hit this case, please verify this beforehand. - Alias(ty::Inherent, _) => { - bug!("unimplemented: inhabitedness checking for inherent projections") - } Tuple(tys) if tys.is_empty() => InhabitedPredicate::True, // use a query for more complex cases Adt(..) | Array(..) | Tuple(_) => tcx.inhabited_predicate_type(self), diff --git a/compiler/rustc_type_ir/src/fast_reject.rs b/compiler/rustc_type_ir/src/fast_reject.rs index fa5e8d43702ce..a5d461c57cd40 100644 --- a/compiler/rustc_type_ir/src/fast_reject.rs +++ b/compiler/rustc_type_ir/src/fast_reject.rs @@ -240,6 +240,13 @@ impl bool { + if lhs == rhs { + return true; + } + self.types_may_unify_inner(lhs, rhs, depth_limit) + } + fn args_may_unify_inner( self, obligation_args: I::GenericArgs, diff --git a/tests/crashes/136678.rs b/tests/crashes/136678.rs deleted file mode 100644 index e7d7de23bfeba..0000000000000 --- a/tests/crashes/136678.rs +++ /dev/null @@ -1,18 +0,0 @@ -//@ known-bug: #136678 -#![feature(inherent_associated_types)] -#![feature(generic_const_exprs)] -#![allow(incomplete_features)] - -struct B; - -struct Test; - -impl Test { - type B = B<{ A }>; - - fn test(a: Self::B) -> Self::B { - a - } -} - -pub fn main() {} diff --git a/tests/crashes/138131.rs b/tests/crashes/138131.rs index f400c02de8d6f..d0f91b748401e 100644 --- a/tests/crashes/138131.rs +++ b/tests/crashes/138131.rs @@ -1,12 +1,15 @@ //@ known-bug: #138131 -#![feature(min_generic_const_args)] -#![feature(inherent_associated_types)] + +#![feature(min_generic_const_args, generic_const_items)] + +const BAR<'a>: usize = 10; + struct Foo<'a> { x: &'a (), } impl<'a> Foo<'a> { - fn foo(_: [u8; Foo::X]) {} + fn foo(_: [u8; BAR]) {} } fn main() {} diff --git a/tests/ui/associated-inherent-types/bound_vars_in_args.rs b/tests/ui/associated-inherent-types/bound_vars_in_args.rs new file mode 100644 index 0000000000000..276e3cf1da044 --- /dev/null +++ b/tests/ui/associated-inherent-types/bound_vars_in_args.rs @@ -0,0 +1,23 @@ +#![feature(non_lifetime_binders, inherent_associated_types)] +#![expect(incomplete_features)] + +// Test that we can resolve to the right IAT when the self type +// contains a bound type. + +struct Foo(T); + +impl Foo<[u8]> { + type IAT = u8; +} + +impl Foo { + type IAT = u8; +} + +struct Bar +//~^ ERROR: the size for values of type `T` cannot be known at compilation time +//~| ERROR: the size for values of type `T` cannot be known at compilation time +where + for Foo::IAT: Sized; + +fn main() {} diff --git a/tests/ui/associated-inherent-types/bound_vars_in_args.stderr b/tests/ui/associated-inherent-types/bound_vars_in_args.stderr new file mode 100644 index 0000000000000..108f1e531af68 --- /dev/null +++ b/tests/ui/associated-inherent-types/bound_vars_in_args.stderr @@ -0,0 +1,37 @@ +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/bound_vars_in_args.rs:17:1 + | +LL | struct Bar + | ^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `T` +note: required by a bound in `Foo::IAT` + --> $DIR/bound_vars_in_args.rs:13:9 + | +LL | impl Foo { + | ^^^^^ required by this bound in `Foo::IAT` +LL | type IAT = u8; + | --- required by a bound in this associated type + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/bound_vars_in_args.rs:17:1 + | +LL | / struct Bar +LL | | +LL | | +LL | | where +LL | | for Foo::IAT: Sized; + | |______________________________^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `T` +note: required by a bound in `Foo::IAT` + --> $DIR/bound_vars_in_args.rs:13:9 + | +LL | impl Foo { + | ^^^^^ required by this bound in `Foo::IAT` +LL | type IAT = u8; + | --- required by a bound in this associated type + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-adt.stderr b/tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-adt.stderr deleted file mode 100644 index 7f8ed89852522..0000000000000 --- a/tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-adt.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error[E0391]: cycle detected when computing predicates of `Foo` - --> $DIR/cycle-iat-inside-of-adt.rs:7:1 - | -LL | struct Foo { - | ^^^^^^^^^^ - | -note: ...which requires computing inferred outlives-predicates of `Foo`... - --> $DIR/cycle-iat-inside-of-adt.rs:7:1 - | -LL | struct Foo { - | ^^^^^^^^^^ - = note: ...which requires computing the inferred outlives-predicates for items in this crate... -note: ...which requires computing type of `Foo::bar`... - --> $DIR/cycle-iat-inside-of-adt.rs:8:5 - | -LL | bar: Self::Bar, - | ^^^^^^^^^^^^^^ -note: ...which requires computing normalized predicates of `Foo`... - --> $DIR/cycle-iat-inside-of-adt.rs:7:1 - | -LL | struct Foo { - | ^^^^^^^^^^ - = note: ...which again requires computing predicates of `Foo`, completing the cycle -note: cycle used when checking that `Foo` is well-formed - --> $DIR/cycle-iat-inside-of-adt.rs:7:1 - | -LL | struct Foo { - | ^^^^^^^^^^ - = 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 1 previous error - -For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-where-predicate.rs b/tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-where-predicate.rs deleted file mode 100644 index 902094b986286..0000000000000 --- a/tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-where-predicate.rs +++ /dev/null @@ -1,16 +0,0 @@ -//@ known-bug: unknown - -#![feature(inherent_associated_types)] -#![allow(incomplete_features)] - -// FIXME(inherent_associated_types): This shouldn't lead to a cycle error. - -fn user() where S::P: std::fmt::Debug {} - -struct S; - -impl S { - type P = (); -} - -fn main() {} diff --git a/tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-where-predicate.stderr b/tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-where-predicate.stderr deleted file mode 100644 index e97a5df9d4917..0000000000000 --- a/tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-where-predicate.stderr +++ /dev/null @@ -1,37 +0,0 @@ -error[E0391]: cycle detected when computing predicates of `user` - --> $DIR/cycle-iat-inside-of-where-predicate.rs:8:1 - | -LL | fn user() where S::P: std::fmt::Debug {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: ...which requires computing explicit predicates of `user`... - --> $DIR/cycle-iat-inside-of-where-predicate.rs:8:1 - | -LL | fn user() where S::P: std::fmt::Debug {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires computing normalized predicates of `user`... - --> $DIR/cycle-iat-inside-of-where-predicate.rs:8:1 - | -LL | fn user() where S::P: std::fmt::Debug {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which again requires computing predicates of `user`, completing the cycle -note: cycle used when checking that `user` is well-formed - --> $DIR/cycle-iat-inside-of-where-predicate.rs:8:1 - | -LL | fn user() where S::P: std::fmt::Debug {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = 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[E0392]: type parameter `T` is never used - --> $DIR/cycle-iat-inside-of-where-predicate.rs:10:10 - | -LL | struct S; - | ^ unused type parameter - | - = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` - = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0391, E0392. -For more information about an error, try `rustc --explain E0391`. diff --git a/tests/ui/associated-inherent-types/candidate-with-alias-2.rs b/tests/ui/associated-inherent-types/candidate-with-alias-2.rs new file mode 100644 index 0000000000000..d7be825a9c22e --- /dev/null +++ b/tests/ui/associated-inherent-types/candidate-with-alias-2.rs @@ -0,0 +1,26 @@ +#![feature(inherent_associated_types)] +#![expect(incomplete_features)] + +trait Identity { + type Assoc; +} +impl Identity for T { + type Assoc = T; +} + +struct Foo(T); +impl Foo<::Assoc> { + type Inherent = u8; +} +impl Foo<::Assoc> { + type Inherent = u32; +} + +struct Bar { + field: >::Inherent, + //~^ ERROR: multiple applicable items in scope +} + +fn main() { + Bar { field: 10_u8 }; +} diff --git a/tests/ui/associated-inherent-types/candidate-with-alias-2.stderr b/tests/ui/associated-inherent-types/candidate-with-alias-2.stderr new file mode 100644 index 0000000000000..335e35a95778d --- /dev/null +++ b/tests/ui/associated-inherent-types/candidate-with-alias-2.stderr @@ -0,0 +1,20 @@ +error[E0034]: multiple applicable items in scope + --> $DIR/candidate-with-alias-2.rs:20:23 + | +LL | field: >::Inherent, + | ^^^^^^^^ multiple `Inherent` found + | +note: candidate #1 is defined in an impl for the type `Foo<::Assoc>` + --> $DIR/candidate-with-alias-2.rs:13:5 + | +LL | type Inherent = u8; + | ^^^^^^^^^^^^^ +note: candidate #2 is defined in an impl for the type `Foo<::Assoc>` + --> $DIR/candidate-with-alias-2.rs:16:5 + | +LL | type Inherent = u32; + | ^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0034`. diff --git a/tests/ui/associated-inherent-types/candidate-with-alias.rs b/tests/ui/associated-inherent-types/candidate-with-alias.rs new file mode 100644 index 0000000000000..d4dd002a77415 --- /dev/null +++ b/tests/ui/associated-inherent-types/candidate-with-alias.rs @@ -0,0 +1,27 @@ +//@ check-pass + +#![feature(inherent_associated_types)] +#![expect(incomplete_features)] + +trait Identity { + type Assoc; +} +impl Identity for T { + type Assoc = T; +} + +struct Foo(T); +impl Foo<::Assoc> { + type Inherent = u8; +} +impl Foo { + type Inherent = u32; +} + +struct Bar { + field: >::Inherent, +} + +fn main() { + Bar { field: 10_u8 }; +} diff --git a/tests/ui/associated-inherent-types/iat-in-where-bound.rs b/tests/ui/associated-inherent-types/iat-in-where-bound.rs new file mode 100644 index 0000000000000..3b8b95eec9a42 --- /dev/null +++ b/tests/ui/associated-inherent-types/iat-in-where-bound.rs @@ -0,0 +1,14 @@ +//@ check-pass + +#![feature(inherent_associated_types)] +#![allow(incomplete_features)] + +fn user() where S::P: std::fmt::Debug {} + +struct S(T); + +impl S { + type P = (); +} + +fn main() {} diff --git a/tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-adt.rs b/tests/ui/associated-inherent-types/iat-inside-of-adt.rs similarity index 61% rename from tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-adt.rs rename to tests/ui/associated-inherent-types/iat-inside-of-adt.rs index 64168cb8c14f8..3d88016d0f87b 100644 --- a/tests/ui/associated-inherent-types/bugs/cycle-iat-inside-of-adt.rs +++ b/tests/ui/associated-inherent-types/iat-inside-of-adt.rs @@ -1,8 +1,7 @@ -//@ known-bug: #108491 +//@ check-pass #![feature(inherent_associated_types)] #![allow(incomplete_features)] -// FIXME(inherent_associated_types): This should pass. struct Foo { bar: Self::Bar, @@ -11,4 +10,8 @@ impl Foo { pub type Bar = usize; } -fn main() {} +fn main() { + Foo { + bar: 10_usize, + }; +} diff --git a/tests/crashes/125879.rs b/tests/ui/associated-inherent-types/inhabited-predicates.rs similarity index 50% rename from tests/crashes/125879.rs rename to tests/ui/associated-inherent-types/inhabited-predicates.rs index 4318842e45518..2b041d4e1be20 100644 --- a/tests/crashes/125879.rs +++ b/tests/ui/associated-inherent-types/inhabited-predicates.rs @@ -1,8 +1,10 @@ -//@ known-bug: rust-lang/rust#125879 +//@ check-pass + #![feature(inherent_associated_types)] -#![allow(incomplete_features)] +#![expect(incomplete_features)] pub type PubAlias0 = PubTy::PrivAssocTy; +//~^ WARN: associated type `PubTy::PrivAssocTy` is more private than the item `PubAlias0` pub struct PubTy; impl PubTy { @@ -10,6 +12,7 @@ impl PubTy { } pub struct S(pub PubAlias0); +//~^ WARN: associated type `PubTy::PrivAssocTy` is more private than the item `S::0` pub unsafe fn foo(a: S) -> S { a diff --git a/tests/ui/associated-inherent-types/inhabited-predicates.stderr b/tests/ui/associated-inherent-types/inhabited-predicates.stderr new file mode 100644 index 0000000000000..e43cd034e6758 --- /dev/null +++ b/tests/ui/associated-inherent-types/inhabited-predicates.stderr @@ -0,0 +1,27 @@ +warning: associated type `PubTy::PrivAssocTy` is more private than the item `PubAlias0` + --> $DIR/inhabited-predicates.rs:6:1 + | +LL | pub type PubAlias0 = PubTy::PrivAssocTy; + | ^^^^^^^^^^^^^^^^^^ type alias `PubAlias0` is reachable at visibility `pub` + | +note: but associated type `PubTy::PrivAssocTy` is only usable at visibility `pub(crate)` + --> $DIR/inhabited-predicates.rs:11:5 + | +LL | type PrivAssocTy = (); + | ^^^^^^^^^^^^^^^^ + = note: `#[warn(private_interfaces)]` on by default + +warning: associated type `PubTy::PrivAssocTy` is more private than the item `S::0` + --> $DIR/inhabited-predicates.rs:14:14 + | +LL | pub struct S(pub PubAlias0); + | ^^^^^^^^^^^^^ field `S::0` is reachable at visibility `pub` + | +note: but associated type `PubTy::PrivAssocTy` is only usable at visibility `pub(crate)` + --> $DIR/inhabited-predicates.rs:11:5 + | +LL | type PrivAssocTy = (); + | ^^^^^^^^^^^^^^^^ + +warning: 2 warnings emitted + diff --git a/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-1.rs b/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-1.rs new file mode 100644 index 0000000000000..7723ee9c58d90 --- /dev/null +++ b/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-1.rs @@ -0,0 +1,23 @@ +//@ check-pass + +#![feature(inherent_associated_types)] +#![expect(incomplete_features)] + +// Test that when resolving an IAT we select candidates based +// off whether the self type matches not just the name of the IAT + +struct Foo(T); +impl Foo { + type Inherent = u8; +} +impl Foo { + type Inherent = u32; +} + +struct Bar { + field: >::Inherent, +} + +fn main() { + Bar { field: 10_u32 }; +} diff --git a/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-2.rs b/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-2.rs new file mode 100644 index 0000000000000..b942c303d3e84 --- /dev/null +++ b/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-2.rs @@ -0,0 +1,29 @@ +#![feature(inherent_associated_types)] +#![expect(incomplete_features)] + +// Test that when we have an unnormalized projection we don't normalize it +// to determine which IAT to resolve to. + +struct Foo(T); +impl Foo { + type Inherent = u16; +} +impl Foo { + type Inherent = u32; +} + +struct Bar { + field: ::This>>::Inherent, + //~^ ERROR: multiple applicable items in scope +} + +trait Identity { + type This; +} +impl Identity for T { type This = T; } + +fn main() { + Bar { + field: 1_u16, + }; +} diff --git a/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-2.stderr b/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-2.stderr new file mode 100644 index 0000000000000..df8c124f77fab --- /dev/null +++ b/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-2.stderr @@ -0,0 +1,20 @@ +error[E0034]: multiple applicable items in scope + --> $DIR/multiple-candidates-in-adt-field-2.rs:16:43 + | +LL | field: ::This>>::Inherent, + | ^^^^^^^^ multiple `Inherent` found + | +note: candidate #1 is defined in an impl for the type `Foo` + --> $DIR/multiple-candidates-in-adt-field-2.rs:9:5 + | +LL | type Inherent = u16; + | ^^^^^^^^^^^^^ +note: candidate #2 is defined in an impl for the type `Foo` + --> $DIR/multiple-candidates-in-adt-field-2.rs:12:5 + | +LL | type Inherent = u32; + | ^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0034`. diff --git a/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-3.rs b/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-3.rs new file mode 100644 index 0000000000000..4c5b382463d54 --- /dev/null +++ b/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-3.rs @@ -0,0 +1,27 @@ +//@ check-pass + +#![feature(inherent_associated_types, lazy_type_alias)] +#![expect(incomplete_features)] + +// Test that we *do* normalize free aliases in order to resolve +// between multiple IAT candidates + +type Free = u8; + +struct Foo(T); +impl Foo { + type Assoc = u16; +} +impl Foo { + type Assoc = u32; +} + +struct Bar { + field: >::Assoc, +} + +fn main() { + Bar { + field: 1_u16, + }; +} diff --git a/tests/ui/associated-inherent-types/not-found-self-type-differs-shadowing-trait-item.rs b/tests/ui/associated-inherent-types/not-found-self-type-differs-shadowing-trait-item.rs index c205cb800d2f6..337fd8fa00c55 100644 --- a/tests/ui/associated-inherent-types/not-found-self-type-differs-shadowing-trait-item.rs +++ b/tests/ui/associated-inherent-types/not-found-self-type-differs-shadowing-trait-item.rs @@ -27,5 +27,5 @@ impl S<()> { fn main() { let _: S::::Pr = (); //[shadowed]~^ ERROR associated type `Pr` not found - //[uncovered]~^^ ERROR ambiguous associated type + //[uncovered]~^^ ERROR associated type `Pr` not found } diff --git a/tests/ui/associated-inherent-types/not-found-self-type-differs-shadowing-trait-item.uncovered.stderr b/tests/ui/associated-inherent-types/not-found-self-type-differs-shadowing-trait-item.uncovered.stderr index 3e914e0538d0b..f35158c5b4101 100644 --- a/tests/ui/associated-inherent-types/not-found-self-type-differs-shadowing-trait-item.uncovered.stderr +++ b/tests/ui/associated-inherent-types/not-found-self-type-differs-shadowing-trait-item.uncovered.stderr @@ -1,15 +1,15 @@ -error[E0223]: ambiguous associated type - --> $DIR/not-found-self-type-differs-shadowing-trait-item.rs:28:12 +error[E0220]: associated type `Pr` not found for `S` in the current scope + --> $DIR/not-found-self-type-differs-shadowing-trait-item.rs:28:23 | +LL | struct S(T); + | ----------- associated type `Pr` not found for this struct +... LL | let _: S::::Pr = (); - | ^^^^^^^^^^^^^ - | -help: use fully-qualified syntax - | -LL - let _: S::::Pr = (); -LL + let _: as Tr>::Pr = (); + | ^^ associated item not found in `S` | + = note: the associated type was found for + error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0223`. +For more information about this error, try `rustc --explain E0220`. diff --git a/tests/ui/associated-inherent-types/really_deep_self_ty_mismatch.rs b/tests/ui/associated-inherent-types/really_deep_self_ty_mismatch.rs new file mode 100644 index 0000000000000..eac33f631bbc4 --- /dev/null +++ b/tests/ui/associated-inherent-types/really_deep_self_ty_mismatch.rs @@ -0,0 +1,26 @@ +//@ check-pass + +#![feature(inherent_associated_types)] +#![expect(incomplete_features)] + +// Test that IAT resolution doesn't bail out when the self type is +// very nested. + +struct Foo(T); +#[rustfmt::skip] +impl Foo>>>>>>>>>> { + type Inherent = u16; +} +#[rustfmt::skip] +impl Foo>>>>>>>>>> { + type Inherent = u32; +} + +#[rustfmt::skip] +struct Bar { + field: >>>>>>>>>>>::Inherent, +} + +fn main() { + Bar { field: 1_u16 }; +} diff --git a/tests/ui/const-generics/mgca/unresolved-iac-1.rs b/tests/ui/const-generics/mgca/unresolved-iac-1.rs new file mode 100644 index 0000000000000..a0700aa5b65f4 --- /dev/null +++ b/tests/ui/const-generics/mgca/unresolved-iac-1.rs @@ -0,0 +1,11 @@ +#![feature(min_generic_const_args)] +#![feature(inherent_associated_types)] +#![expect(incomplete_features)] + +struct A(Box<[u8; Box::b]>); +//~^ ERROR: associated constant `b` not found for + +impl A { + fn c(self) { self.0.d() } +} +fn main() {} diff --git a/tests/ui/const-generics/mgca/unresolved-iac-1.stderr b/tests/ui/const-generics/mgca/unresolved-iac-1.stderr new file mode 100644 index 0000000000000..4bf1191e786a5 --- /dev/null +++ b/tests/ui/const-generics/mgca/unresolved-iac-1.stderr @@ -0,0 +1,16 @@ +error[E0220]: associated constant `b` not found for `Box<{type error}, {type error}>` in the current scope + --> $DIR/unresolved-iac-1.rs:5:24 + | +LL | struct A(Box<[u8; Box::b]>); + | ^ associated item not found in `Box<{type error}, {type error}>` + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + ::: $SRC_DIR/alloc/src/boxed.rs:LL:COL + | + = note: associated constant `b` not found for this struct + | + = note: the associated constant was found for + + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0220`. diff --git a/tests/ui/const-generics/mgca/unresolved-iac-2.rs b/tests/ui/const-generics/mgca/unresolved-iac-2.rs new file mode 100644 index 0000000000000..72bb5d7f627a2 --- /dev/null +++ b/tests/ui/const-generics/mgca/unresolved-iac-2.rs @@ -0,0 +1,14 @@ +#![feature(min_generic_const_args)] +#![feature(inherent_associated_types)] +#![expect(incomplete_features)] + +struct Foo<'a> { + x: &'a (), +} + +impl<'a> Foo<'a> { + fn foo(_: [u8; Foo::X]) {} + //~^ ERROR: associated constant `X` not found for `Foo<'_>` in the current scope +} + +fn main() {} diff --git a/tests/ui/const-generics/mgca/unresolved-iac-2.stderr b/tests/ui/const-generics/mgca/unresolved-iac-2.stderr new file mode 100644 index 0000000000000..a6c12877a4e09 --- /dev/null +++ b/tests/ui/const-generics/mgca/unresolved-iac-2.stderr @@ -0,0 +1,15 @@ +error[E0220]: associated constant `X` not found for `Foo<'_>` in the current scope + --> $DIR/unresolved-iac-2.rs:10:25 + | +LL | struct Foo<'a> { + | -------------- associated constant `X` not found for this struct +... +LL | fn foo(_: [u8; Foo::X]) {} + | ^ associated item not found in `Foo<'_>` + | + = note: the associated constant was found for + + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0220`. From 2a950b5637febcf7e526942d6755698defcec2a6 Mon Sep 17 00:00:00 2001 From: Boxy Date: Tue, 27 May 2025 18:21:24 +0100 Subject: [PATCH 04/14] Test whether we use DeepRejectCtxt --- compiler/rustc_hir_analysis/src/collect.rs | 12 ++++--- .../impl_params_are_infers.rs | 34 +++++++++++++++++++ .../impl_params_are_infers.stderr | 20 +++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 tests/ui/associated-inherent-types/impl_params_are_infers.rs create mode 100644 tests/ui/associated-inherent-types/impl_params_are_infers.stderr diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index fd8c702a76b34..ea4194079a638 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -414,10 +414,14 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { // because it allows `impl Foo` to unify with `Foo::IAT`, while also disallowing // `Foo::IAT` from unifying with `impl Foo`. // - // We don't really care about a depth limit here because we're only working with user-written types - // and if they wrote a type that would take hours to walk then that's kind of on them. On the other - // hand the default depth limit is relatively low and could realistically be hit by users in normal - // cases. + // We don't really care about a depth limit here because we're only working with user-written + // types and if they wrote a type that would take hours to walk then that's kind of on them. On + // the other hand the default depth limit is relatively low and could realistically be hit by + // users in normal cases. + // + // `DeepRejectCtxt` leads to slightly worse IAT resolution than real type equality in cases + // where the `impl_ty` has repeated uses of generic parameters. E.g. `impl Foo` would + // be considered a valid candidate when resolving `Foo::IAT`. ty::DeepRejectCtxt::relate_rigid_infer(self.tcx) .types_may_unify_with_depth(self_ty, impl_ty, usize::MAX) }) diff --git a/tests/ui/associated-inherent-types/impl_params_are_infers.rs b/tests/ui/associated-inherent-types/impl_params_are_infers.rs new file mode 100644 index 0000000000000..55d29a35a231a --- /dev/null +++ b/tests/ui/associated-inherent-types/impl_params_are_infers.rs @@ -0,0 +1,34 @@ +#![feature(inherent_associated_types)] +#![expect(incomplete_features)] + +// Test whether IAT resolution in item signatures will actually instantiate the +// impl's params with infers before equating self types, or if we "cheat" and +// use a heuristic (e.g. DeepRejectCtxt). + +struct Foo(T, U, V); + +impl Foo { + type IAT = u8; +} + +impl Foo { + type IAT = u16; +} + +trait Identity { + type This; +} +impl Identity for T { + type This = T; +} + +struct Bar { + // It would be illegal to resolve to `Foo::IAT` as `T` and `U` are + // different types. However, currently we treat all impl-side params sort of like + // they're infers and assume they can unify with anything, so we consider it a + // valid candidate. + field: Foo::This>::IAT, + //~^ ERROR: multiple applicable items in scope +} + +fn main() {} diff --git a/tests/ui/associated-inherent-types/impl_params_are_infers.stderr b/tests/ui/associated-inherent-types/impl_params_are_infers.stderr new file mode 100644 index 0000000000000..fd31693cbedc2 --- /dev/null +++ b/tests/ui/associated-inherent-types/impl_params_are_infers.stderr @@ -0,0 +1,20 @@ +error[E0034]: multiple applicable items in scope + --> $DIR/impl_params_are_infers.rs:30:48 + | +LL | field: Foo::This>::IAT, + | ^^^ multiple `IAT` found + | +note: candidate #1 is defined in an impl for the type `Foo` + --> $DIR/impl_params_are_infers.rs:11:5 + | +LL | type IAT = u8; + | ^^^^^^^^ +note: candidate #2 is defined in an impl for the type `Foo` + --> $DIR/impl_params_are_infers.rs:15:5 + | +LL | type IAT = u16; + | ^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0034`. From 9961747414891126720b22050f2b049f0e2457c7 Mon Sep 17 00:00:00 2001 From: Boxy Date: Tue, 17 Jun 2025 14:28:46 +0100 Subject: [PATCH 05/14] rebase --- tests/ui/const-generics/mgca/unresolved-iac-1.rs | 11 ----------- .../const-generics/mgca/unresolved-iac-1.stderr | 16 ---------------- tests/ui/const-generics/mgca/unresolved-iac-2.rs | 14 -------------- .../const-generics/mgca/unresolved-iac-2.stderr | 15 --------------- 4 files changed, 56 deletions(-) delete mode 100644 tests/ui/const-generics/mgca/unresolved-iac-1.rs delete mode 100644 tests/ui/const-generics/mgca/unresolved-iac-1.stderr delete mode 100644 tests/ui/const-generics/mgca/unresolved-iac-2.rs delete mode 100644 tests/ui/const-generics/mgca/unresolved-iac-2.stderr diff --git a/tests/ui/const-generics/mgca/unresolved-iac-1.rs b/tests/ui/const-generics/mgca/unresolved-iac-1.rs deleted file mode 100644 index a0700aa5b65f4..0000000000000 --- a/tests/ui/const-generics/mgca/unresolved-iac-1.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![feature(min_generic_const_args)] -#![feature(inherent_associated_types)] -#![expect(incomplete_features)] - -struct A(Box<[u8; Box::b]>); -//~^ ERROR: associated constant `b` not found for - -impl A { - fn c(self) { self.0.d() } -} -fn main() {} diff --git a/tests/ui/const-generics/mgca/unresolved-iac-1.stderr b/tests/ui/const-generics/mgca/unresolved-iac-1.stderr deleted file mode 100644 index 4bf1191e786a5..0000000000000 --- a/tests/ui/const-generics/mgca/unresolved-iac-1.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0220]: associated constant `b` not found for `Box<{type error}, {type error}>` in the current scope - --> $DIR/unresolved-iac-1.rs:5:24 - | -LL | struct A(Box<[u8; Box::b]>); - | ^ associated item not found in `Box<{type error}, {type error}>` - --> $SRC_DIR/alloc/src/boxed.rs:LL:COL - ::: $SRC_DIR/alloc/src/boxed.rs:LL:COL - | - = note: associated constant `b` not found for this struct - | - = note: the associated constant was found for - - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0220`. diff --git a/tests/ui/const-generics/mgca/unresolved-iac-2.rs b/tests/ui/const-generics/mgca/unresolved-iac-2.rs deleted file mode 100644 index 72bb5d7f627a2..0000000000000 --- a/tests/ui/const-generics/mgca/unresolved-iac-2.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![feature(min_generic_const_args)] -#![feature(inherent_associated_types)] -#![expect(incomplete_features)] - -struct Foo<'a> { - x: &'a (), -} - -impl<'a> Foo<'a> { - fn foo(_: [u8; Foo::X]) {} - //~^ ERROR: associated constant `X` not found for `Foo<'_>` in the current scope -} - -fn main() {} diff --git a/tests/ui/const-generics/mgca/unresolved-iac-2.stderr b/tests/ui/const-generics/mgca/unresolved-iac-2.stderr deleted file mode 100644 index a6c12877a4e09..0000000000000 --- a/tests/ui/const-generics/mgca/unresolved-iac-2.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0220]: associated constant `X` not found for `Foo<'_>` in the current scope - --> $DIR/unresolved-iac-2.rs:10:25 - | -LL | struct Foo<'a> { - | -------------- associated constant `X` not found for this struct -... -LL | fn foo(_: [u8; Foo::X]) {} - | ^ associated item not found in `Foo<'_>` - | - = note: the associated constant was found for - - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0220`. From ae65625252df45569940336bea6df8fe0c4826e6 Mon Sep 17 00:00:00 2001 From: Boxy Date: Tue, 17 Jun 2025 14:45:47 +0100 Subject: [PATCH 06/14] Dont replace escaping bound vars in item sigs --- compiler/rustc_hir_analysis/src/collect.rs | 76 ++++++++----------- compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs | 75 +++++++++--------- tests/crashes/138131.rs | 15 ---- .../bound_vars_in_args.rs | 3 +- .../bound_vars_in_args.stderr | 41 +++------- .../issue-109299-1.rs | 4 +- .../issue-109299-1.stderr | 28 +------ 7 files changed, 82 insertions(+), 160 deletions(-) delete mode 100644 tests/crashes/138131.rs diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index ea4194079a638..176d955bf032d 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -380,54 +380,44 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { assert!(!self_ty.has_infer()); // We don't just call the normal normalization routine here as we can't provide the - // correct `ParamEnv` and it seems dubious to invoke arbitrary trait solving under + // correct `ParamEnv` and it would be wrong to invoke arbitrary trait solving under // the wrong `ParamEnv`. Expanding free aliases doesn't need a `ParamEnv` so we do // this just to make resolution a little bit smarter. let self_ty = self.tcx.expand_free_alias_tys(self_ty); debug!("select_inherent_assoc_candidates: self_ty={:?}", self_ty); - // We make an infcx and replace any escaping vars with placeholders so that IAT res - // with type/const bound vars in arguments is slightly smarter. `for >::IAT` - // would otherwise unify with `impl Foo` when ideally we would not. - let infcx = self.tcx().infer_ctxt().build(TypingMode::non_body_analysis()); - let mut universes = if self_ty.has_escaping_bound_vars() { - vec![None; self_ty.outer_exclusive_binder().as_usize()] - } else { - vec![] - }; - let candidates = - rustc_trait_selection::traits::with_replaced_escaping_bound_vars( - &infcx, - &mut universes, - self_ty, - |self_ty| { - candidates - .into_iter() - .filter(|&InherentAssocCandidate { impl_, .. }| { - let impl_ty = self.tcx().type_of(impl_).instantiate_identity(); - - // See comment on doing this operation for `self_ty` - let impl_ty = self.tcx.expand_free_alias_tys(impl_ty); - debug!("select_inherent_assoc_candidates: impl_ty={:?}", impl_ty); - - // We treat parameters in the self ty as rigid and parameters in the impl ty as infers - // because it allows `impl Foo` to unify with `Foo::IAT`, while also disallowing - // `Foo::IAT` from unifying with `impl Foo`. - // - // We don't really care about a depth limit here because we're only working with user-written - // types and if they wrote a type that would take hours to walk then that's kind of on them. On - // the other hand the default depth limit is relatively low and could realistically be hit by - // users in normal cases. - // - // `DeepRejectCtxt` leads to slightly worse IAT resolution than real type equality in cases - // where the `impl_ty` has repeated uses of generic parameters. E.g. `impl Foo` would - // be considered a valid candidate when resolving `Foo::IAT`. - ty::DeepRejectCtxt::relate_rigid_infer(self.tcx) - .types_may_unify_with_depth(self_ty, impl_ty, usize::MAX) - }) - .collect() - }, - ); + let candidates = candidates + .into_iter() + .filter(|&InherentAssocCandidate { impl_, .. }| { + let impl_ty = self.tcx().type_of(impl_).instantiate_identity(); + + // See comment on doing this operation for `self_ty` + let impl_ty = self.tcx.expand_free_alias_tys(impl_ty); + debug!("select_inherent_assoc_candidates: impl_ty={:?}", impl_ty); + + // We treat parameters in the self ty as rigid and parameters in the impl ty as infers + // because it allows `impl Foo` to unify with `Foo::IAT`, while also disallowing + // `Foo::IAT` from unifying with `impl Foo`. + // + // We don't really care about a depth limit here because we're only working with user-written + // types and if they wrote a type that would take hours to walk then that's kind of on them. On + // the other hand the default depth limit is relatively low and could realistically be hit by + // users in normal cases. + // + // `DeepRejectCtxt` leads to slightly worse IAT resolution than real type equality in cases + // where the `impl_ty` has repeated uses of generic parameters. E.g. `impl Foo` would + // be considered a valid candidate when resolving `Foo::IAT`. + // + // Not replacing escaping bound vars in `self_ty` with placeholders also leads to slightly worse + // resolution, but it probably won't come up in practice and it would be backwards compatible + // to switch over to doing that. + ty::DeepRejectCtxt::relate_rigid_infer(self.tcx).types_may_unify_with_depth( + self_ty, + impl_ty, + usize::MAX, + ) + }) + .collect(); (candidates, vec![]) } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index d8efb0aac4d75..8c18642e54a18 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -322,6 +322,39 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { ) -> (Vec, Vec>) { let tcx = self.tcx(); let infcx = &self.infcx; + let mut fulfillment_errors = vec![]; + + let mut filter_iat_candidate = |self_ty, impl_| { + let ocx = ObligationCtxt::new_with_diagnostics(self); + let self_ty = ocx.normalize(&ObligationCause::dummy(), self.param_env, self_ty); + + let impl_args = infcx.fresh_args_for_item(span, impl_); + let impl_ty = tcx.type_of(impl_).instantiate(tcx, impl_args); + let impl_ty = ocx.normalize(&ObligationCause::dummy(), self.param_env, impl_ty); + + // Check that the self types can be related. + if ocx.eq(&ObligationCause::dummy(), self.param_env, impl_ty, self_ty).is_err() { + return false; + } + + // Check whether the impl imposes obligations we have to worry about. + let impl_bounds = tcx.predicates_of(impl_).instantiate(tcx, impl_args); + let impl_bounds = ocx.normalize(&ObligationCause::dummy(), self.param_env, impl_bounds); + let impl_obligations = traits::predicates_for_generics( + |_, _| ObligationCause::dummy(), + self.param_env, + impl_bounds, + ); + ocx.register_obligations(impl_obligations); + + let mut errors = ocx.select_where_possible(); + if !errors.is_empty() { + fulfillment_errors.append(&mut errors); + return false; + } + + true + }; let mut universes = if self_ty.has_escaping_bound_vars() { vec![None; self_ty.outer_exclusive_binder().as_usize()] @@ -329,52 +362,12 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { vec![] }; - let mut fulfillment_errors = vec![]; let candidates = traits::with_replaced_escaping_bound_vars(infcx, &mut universes, self_ty, |self_ty| { candidates .into_iter() .filter(|&InherentAssocCandidate { impl_, .. }| { - infcx.probe(|_| { - let ocx = ObligationCtxt::new_with_diagnostics(self); - let self_ty = - ocx.normalize(&ObligationCause::dummy(), self.param_env, self_ty); - - let impl_args = infcx.fresh_args_for_item(span, impl_); - let impl_ty = tcx.type_of(impl_).instantiate(tcx, impl_args); - let impl_ty = - ocx.normalize(&ObligationCause::dummy(), self.param_env, impl_ty); - - // Check that the self types can be related. - if ocx - .eq(&ObligationCause::dummy(), self.param_env, impl_ty, self_ty) - .is_err() - { - return false; - } - - // Check whether the impl imposes obligations we have to worry about. - let impl_bounds = tcx.predicates_of(impl_).instantiate(tcx, impl_args); - let impl_bounds = ocx.normalize( - &ObligationCause::dummy(), - self.param_env, - impl_bounds, - ); - let impl_obligations = traits::predicates_for_generics( - |_, _| ObligationCause::dummy(), - self.param_env, - impl_bounds, - ); - ocx.register_obligations(impl_obligations); - - let mut errors = ocx.select_where_possible(); - if !errors.is_empty() { - fulfillment_errors.append(&mut errors); - return false; - } - - true - }) + infcx.probe(|_| filter_iat_candidate(self_ty, impl_)) }) .collect() }); diff --git a/tests/crashes/138131.rs b/tests/crashes/138131.rs deleted file mode 100644 index d0f91b748401e..0000000000000 --- a/tests/crashes/138131.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ known-bug: #138131 - -#![feature(min_generic_const_args, generic_const_items)] - -const BAR<'a>: usize = 10; - -struct Foo<'a> { - x: &'a (), -} - -impl<'a> Foo<'a> { - fn foo(_: [u8; BAR]) {} -} - -fn main() {} diff --git a/tests/ui/associated-inherent-types/bound_vars_in_args.rs b/tests/ui/associated-inherent-types/bound_vars_in_args.rs index 276e3cf1da044..0baa242af7689 100644 --- a/tests/ui/associated-inherent-types/bound_vars_in_args.rs +++ b/tests/ui/associated-inherent-types/bound_vars_in_args.rs @@ -15,9 +15,8 @@ impl Foo { } struct Bar -//~^ ERROR: the size for values of type `T` cannot be known at compilation time -//~| ERROR: the size for values of type `T` cannot be known at compilation time where for Foo::IAT: Sized; + //~^ ERROR: multiple applicable items in scope fn main() {} diff --git a/tests/ui/associated-inherent-types/bound_vars_in_args.stderr b/tests/ui/associated-inherent-types/bound_vars_in_args.stderr index 108f1e531af68..9e880476f6a96 100644 --- a/tests/ui/associated-inherent-types/bound_vars_in_args.stderr +++ b/tests/ui/associated-inherent-types/bound_vars_in_args.stderr @@ -1,37 +1,20 @@ -error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/bound_vars_in_args.rs:17:1 +error[E0034]: multiple applicable items in scope + --> $DIR/bound_vars_in_args.rs:19:20 | -LL | struct Bar - | ^^^^^^^^^^ doesn't have a size known at compile-time +LL | for Foo::IAT: Sized; + | ^^^ multiple `IAT` found | - = help: the trait `Sized` is not implemented for `T` -note: required by a bound in `Foo::IAT` - --> $DIR/bound_vars_in_args.rs:13:9 +note: candidate #1 is defined in an impl for the type `Foo<[u8]>` + --> $DIR/bound_vars_in_args.rs:10:5 | -LL | impl Foo { - | ^^^^^ required by this bound in `Foo::IAT` LL | type IAT = u8; - | --- required by a bound in this associated type - -error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/bound_vars_in_args.rs:17:1 - | -LL | / struct Bar -LL | | -LL | | -LL | | where -LL | | for Foo::IAT: Sized; - | |______________________________^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `T` -note: required by a bound in `Foo::IAT` - --> $DIR/bound_vars_in_args.rs:13:9 + | ^^^^^^^^ +note: candidate #2 is defined in an impl for the type `Foo` + --> $DIR/bound_vars_in_args.rs:14:5 | -LL | impl Foo { - | ^^^^^ required by this bound in `Foo::IAT` LL | type IAT = u8; - | --- required by a bound in this associated type + | ^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0034`. diff --git a/tests/ui/associated-inherent-types/issue-109299-1.rs b/tests/ui/associated-inherent-types/issue-109299-1.rs index 4546785f0b1c4..3132d9fef6975 100644 --- a/tests/ui/associated-inherent-types/issue-109299-1.rs +++ b/tests/ui/associated-inherent-types/issue-109299-1.rs @@ -8,8 +8,6 @@ impl Lexer { } type X = impl for Fn() -> Lexer::Cursor; -//~^ ERROR associated type `Cursor` not found for `Lexer` in the current scope -//~| ERROR associated type `Cursor` not found for `Lexer` in the current scope -//~| ERROR: unconstrained opaque type +//~^ 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 6bc7a539680c1..bc8ea6acf28cf 100644 --- a/tests/ui/associated-inherent-types/issue-109299-1.stderr +++ b/tests/ui/associated-inherent-types/issue-109299-1.stderr @@ -6,31 +6,5 @@ LL | type X = impl for Fn() -> Lexer::Cursor; | = note: `X` must be used in combination with a concrete type within the same crate -error[E0220]: associated type `Cursor` not found for `Lexer` in the current scope - --> $DIR/issue-109299-1.rs:10:40 - | -LL | struct Lexer(T); - | --------------- associated type `Cursor` not found for this struct -... -LL | type X = impl for Fn() -> Lexer::Cursor; - | ^^^^^^ associated item not found in `Lexer` - | - = note: the associated type was found for - - `Lexer` - -error[E0220]: associated type `Cursor` not found for `Lexer` in the current scope - --> $DIR/issue-109299-1.rs:10:40 - | -LL | struct Lexer(T); - | --------------- associated type `Cursor` not found for this struct -... -LL | type X = impl for Fn() -> Lexer::Cursor; - | ^^^^^^ associated item not found in `Lexer` - | - = note: the associated type was found for - - `Lexer` - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0220`. From 57fdde331b225b8a8c1010dcc69868ccf7a1747d Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 17 Jun 2025 18:03:45 +0000 Subject: [PATCH 07/14] Update libc to 0.2.174 This includes a fix for building on gnux32. [1]: https://github.com/rust-lang/libc/releases/tag/0.2.174 --- Cargo.lock | 4 ++-- library/Cargo.lock | 4 ++-- src/tools/rustbook/Cargo.lock | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b107b11cff81..b31bb7ce062b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2045,9 +2045,9 @@ checksum = "9fa0e2a1fcbe2f6be6c42e342259976206b383122fc152e872795338b5a3f3a7" [[package]] name = "libc" -version = "0.2.173" +version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8cfeafaffdbc32176b64fb251369d52ea9f0a8fbc6f8759edffef7b525d64bb" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libdbus-sys" diff --git a/library/Cargo.lock b/library/Cargo.lock index c7d59655ea462..34012d6943b79 100644 --- a/library/Cargo.lock +++ b/library/Cargo.lock @@ -141,9 +141,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.173" +version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8cfeafaffdbc32176b64fb251369d52ea9f0a8fbc6f8759edffef7b525d64bb" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" dependencies = [ "rustc-std-workspace-core", ] diff --git a/src/tools/rustbook/Cargo.lock b/src/tools/rustbook/Cargo.lock index 3e83a2168ff1a..7bf3bb195ee09 100644 --- a/src/tools/rustbook/Cargo.lock +++ b/src/tools/rustbook/Cargo.lock @@ -808,9 +808,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.173" +version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8cfeafaffdbc32176b64fb251369d52ea9f0a8fbc6f8759edffef7b525d64bb" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "linereader" From 81f7eebb23cf4583d3c6d14009935aafe5326316 Mon Sep 17 00:00:00 2001 From: Daniel Paoliello Date: Tue, 17 Jun 2025 12:24:44 -0700 Subject: [PATCH 08/14] Add a missing colon at the end of the expected panic message in location-detail-unwrap-multiline.rs --- tests/ui/panics/location-detail-unwrap-multiline.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/panics/location-detail-unwrap-multiline.rs b/tests/ui/panics/location-detail-unwrap-multiline.rs index 56e1760d851bb..e49e11a60610b 100644 --- a/tests/ui/panics/location-detail-unwrap-multiline.rs +++ b/tests/ui/panics/location-detail-unwrap-multiline.rs @@ -1,7 +1,7 @@ //@ run-fail //@ compile-flags: -Cstrip=none -Cdebuginfo=line-tables-only -Copt-level=0 //@ exec-env:RUST_BACKTRACE=1 -//@ regex-error-pattern: location-detail-unwrap-multiline\.rs:11(:10)?\n +//@ regex-error-pattern: location-detail-unwrap-multiline\.rs:11(:10)?:\n //@ needs-unwind //@ ignore-android FIXME #17520 From 66e056a3a7f16a61865ce5feb581d267e400016b Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 17 Jun 2025 16:10:35 -0700 Subject: [PATCH 09/14] library: Increase timeout on mpmc test to reduce flakes This recently spuriously failed in a rollup, so I think we can afford to increase the base timeout and the amount of time slept for to provide a much wider margin for the timeout to be reached. --- library/std/tests/sync/mpmc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/tests/sync/mpmc.rs b/library/std/tests/sync/mpmc.rs index 594fc2180d83f..bf80ab96a88bd 100644 --- a/library/std/tests/sync/mpmc.rs +++ b/library/std/tests/sync/mpmc.rs @@ -463,12 +463,12 @@ fn oneshot_single_thread_recv_timeout() { fn stress_recv_timeout_two_threads() { let (tx, rx) = channel(); let stress = stress_factor() + 50; - let timeout = Duration::from_millis(5); + let timeout = Duration::from_millis(10); thread::spawn(move || { for i in 0..stress { if i % 2 == 0 { - thread::sleep(timeout * 2); + thread::sleep(timeout * 4); } tx.send(1usize).unwrap(); } From eee2d7b1016d6f2743c5f61989b28e05fefd9aff Mon Sep 17 00:00:00 2001 From: Andrew Zhogin Date: Tue, 17 Jun 2025 10:14:05 +0700 Subject: [PATCH 10/14] AsyncDrop trait without sync Drop generates an error --- compiler/rustc_hir_analysis/messages.ftl | 3 +++ compiler/rustc_hir_analysis/src/check/mod.rs | 10 +++++++++- compiler/rustc_hir_analysis/src/errors.rs | 8 ++++++++ .../async-drop/async-without-sync.rs | 19 +++++++++++++++++++ .../async-drop/async-without-sync.stderr | 10 ++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/ui/async-await/async-drop/async-without-sync.rs create mode 100644 tests/ui/async-await/async-drop/async-without-sync.stderr diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index f768bd157abc8..bd2252c1bf8fd 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -46,6 +46,9 @@ hir_analysis_associated_type_trait_uninferred_generic_params = cannot use the {$ hir_analysis_associated_type_trait_uninferred_generic_params_multipart_suggestion = use a fully qualified path with explicit lifetimes +hir_analysis_async_drop_without_sync_drop = `AsyncDrop` impl without `Drop` impl + .help = type implementing `AsyncDrop` trait must also implement `Drop` trait to be used in sync context and unwinds + hir_analysis_auto_deref_reached_recursion_limit = reached the recursion limit while auto-dereferencing `{$ty}` .label = deref recursion limit reached .help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`) diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index c5c7e6b2aa722..de8cbc3a57ff2 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -113,7 +113,15 @@ pub fn provide(providers: &mut Providers) { } fn adt_destructor(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option { - tcx.calculate_dtor(def_id, always_applicable::check_drop_impl) + let dtor = tcx.calculate_dtor(def_id, always_applicable::check_drop_impl); + if dtor.is_none() && tcx.features().async_drop() { + if let Some(async_dtor) = adt_async_destructor(tcx, def_id) { + // When type has AsyncDrop impl, but doesn't have Drop impl, generate error + let span = tcx.def_span(async_dtor.impl_did); + tcx.dcx().emit_err(errors::AsyncDropWithoutSyncDrop { span }); + } + } + dtor } fn adt_async_destructor(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option { diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 8de2aec95a7b2..318aaab50f4d4 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -1712,3 +1712,11 @@ pub(crate) struct AbiCustomClothedFunction { )] pub naked_span: Span, } + +#[derive(Diagnostic)] +#[diag(hir_analysis_async_drop_without_sync_drop)] +#[help] +pub(crate) struct AsyncDropWithoutSyncDrop { + #[primary_span] + pub span: Span, +} diff --git a/tests/ui/async-await/async-drop/async-without-sync.rs b/tests/ui/async-await/async-drop/async-without-sync.rs new file mode 100644 index 0000000000000..8a748636cc783 --- /dev/null +++ b/tests/ui/async-await/async-drop/async-without-sync.rs @@ -0,0 +1,19 @@ +//@ edition: 2024 +#![feature(async_drop)] +#![allow(incomplete_features)] +#![crate_type = "lib"] + +use std::future::AsyncDrop; +use std::pin::Pin; + +async fn foo() { + let _st = St; +} + +struct St; + +impl AsyncDrop for St { //~ ERROR: `AsyncDrop` impl without `Drop` impl + async fn drop(self: Pin<&mut Self>) { + println!("123"); + } +} diff --git a/tests/ui/async-await/async-drop/async-without-sync.stderr b/tests/ui/async-await/async-drop/async-without-sync.stderr new file mode 100644 index 0000000000000..0eaca322dc034 --- /dev/null +++ b/tests/ui/async-await/async-drop/async-without-sync.stderr @@ -0,0 +1,10 @@ +error: `AsyncDrop` impl without `Drop` impl + --> $DIR/async-without-sync.rs:15:1 + | +LL | impl AsyncDrop for St { + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: type implementing `AsyncDrop` trait must also implement `Drop` trait to be used in sync context and unwinds + +error: aborting due to 1 previous error + From 1fdf2b562070ec98c5b32ee67b8c6d8145127a6e Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Mon, 9 Jun 2025 20:08:52 +0200 Subject: [PATCH 11/14] add `#[align]` attribute Right now it's used for functions with `fn_align`, in the future it will get more uses (statics, struct fields, etc.) --- .../src/attributes.rs | 3 + compiler/rustc_attr_parsing/messages.ftl | 3 + .../rustc_attr_parsing/src/attributes/repr.rs | 58 +++++++++++++- compiler/rustc_attr_parsing/src/context.rs | 3 +- .../src/session_diagnostics.rs | 8 ++ .../rustc_codegen_ssa/src/codegen_attrs.rs | 14 +--- compiler/rustc_feature/src/builtin_attrs.rs | 1 + .../src/middle/codegen_fn_attrs.rs | 3 +- compiler/rustc_parse/src/validate_attr.rs | 1 + compiler/rustc_passes/messages.ftl | 15 ++-- compiler/rustc_passes/src/check_attr.rs | 75 ++++++++++++------- compiler/rustc_passes/src/errors.rs | 30 ++++++-- src/tools/miri/tests/pass/fn_align.rs | 10 +-- tests/assembly/naked-functions/wasm32.rs | 2 +- tests/codegen/align-fn.rs | 22 +++--- tests/codegen/min-function-alignment.rs | 6 +- tests/codegen/naked-fn/aligned.rs | 2 +- .../naked-fn/min-function-alignment.rs | 4 +- tests/ui/asm/naked-with-invalid-repr-attr.rs | 3 +- .../asm/naked-with-invalid-repr-attr.stderr | 12 +-- .../attributes/arg-error-issue-121425.stderr | 12 +-- tests/ui/attributes/invalid-repr.rs | 2 +- tests/ui/attributes/invalid-repr.stderr | 4 +- tests/ui/attributes/malformed-fn-align.rs | 17 ++++- tests/ui/attributes/malformed-fn-align.stderr | 69 +++++++++++++++-- .../ui/feature-gates/feature-gate-fn_align.rs | 7 +- .../feature-gate-fn_align.stderr | 37 ++++++--- tests/ui/repr/attr-usage-repr.rs | 2 +- tests/ui/repr/attr-usage-repr.stderr | 4 +- tests/ui/repr/malformed-repr-hints.stderr | 24 +++--- 30 files changed, 320 insertions(+), 133 deletions(-) diff --git a/compiler/rustc_attr_data_structures/src/attributes.rs b/compiler/rustc_attr_data_structures/src/attributes.rs index d4c4345604969..cdc01dc6c91ad 100644 --- a/compiler/rustc_attr_data_structures/src/attributes.rs +++ b/compiler/rustc_attr_data_structures/src/attributes.rs @@ -182,6 +182,9 @@ impl Deprecation { #[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] pub enum AttributeKind { // tidy-alphabetical-start + /// Represents `#[align(N)]`. + Align { align: Align, span: Span }, + /// Represents `#[rustc_allow_const_fn_unstable]`. AllowConstFnUnstable(ThinVec), diff --git a/compiler/rustc_attr_parsing/messages.ftl b/compiler/rustc_attr_parsing/messages.ftl index b9b386635f630..0891afc003e14 100644 --- a/compiler/rustc_attr_parsing/messages.ftl +++ b/compiler/rustc_attr_parsing/messages.ftl @@ -44,6 +44,9 @@ attr_parsing_incorrect_repr_format_packed_expect_integer = attr_parsing_incorrect_repr_format_packed_one_or_zero_arg = incorrect `repr(packed)` attribute format: `packed` takes exactly one parenthesized argument, or no parentheses at all +attr_parsing_invalid_alignment_value = + invalid alignment value: {$error_part} + attr_parsing_invalid_issue_string = `issue` must be a non-zero numeric string or "none" .must_not_be_zero = `issue` must not be "0", use "none" instead diff --git a/compiler/rustc_attr_parsing/src/attributes/repr.rs b/compiler/rustc_attr_parsing/src/attributes/repr.rs index ae9e7871874d6..c9f9f34bdb7c1 100644 --- a/compiler/rustc_attr_parsing/src/attributes/repr.rs +++ b/compiler/rustc_attr_parsing/src/attributes/repr.rs @@ -4,7 +4,7 @@ use rustc_attr_data_structures::{AttributeKind, IntType, ReprAttr}; use rustc_feature::{AttributeTemplate, template}; use rustc_span::{DUMMY_SP, Span, Symbol, sym}; -use super::{CombineAttributeParser, ConvertFn}; +use super::{AcceptMapping, AttributeParser, CombineAttributeParser, ConvertFn, FinalizeContext}; use crate::context::{AcceptContext, Stage}; use crate::parser::{ArgParser, MetaItemListParser, MetaItemParser}; use crate::session_diagnostics; @@ -203,7 +203,7 @@ fn parse_repr_align( }); } Align => { - cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg { + cx.emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg { span: param_span, }); } @@ -266,3 +266,57 @@ fn parse_alignment(node: &LitKind) -> Result { Err("not an unsuffixed integer") } } + +/// Parse #[align(N)]. +#[derive(Default)] +pub(crate) struct AlignParser(Option<(Align, Span)>); + +impl AlignParser { + const PATH: &'static [Symbol] = &[sym::align]; + const TEMPLATE: AttributeTemplate = template!(Word, List: ""); + + fn parse<'c, S: Stage>( + &mut self, + cx: &'c mut AcceptContext<'_, '_, S>, + args: &'c ArgParser<'_>, + ) { + match args { + ArgParser::NoArgs | ArgParser::NameValue(_) => { + cx.expected_list(cx.attr_span); + } + ArgParser::List(list) => { + let Some(align) = list.single() else { + cx.expected_single_argument(list.span); + return; + }; + + let Some(lit) = align.lit() else { + cx.emit_err(session_diagnostics::IncorrectReprFormatExpectInteger { + span: align.span(), + }); + + return; + }; + + match parse_alignment(&lit.kind) { + Ok(literal) => self.0 = Ord::max(self.0, Some((literal, cx.attr_span))), + Err(message) => { + cx.emit_err(session_diagnostics::InvalidAlignmentValue { + span: lit.span, + error_part: message, + }); + } + } + } + } + } +} + +impl AttributeParser for AlignParser { + const ATTRIBUTES: AcceptMapping = &[(Self::PATH, Self::TEMPLATE, Self::parse)]; + + fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option { + let (align, span) = self.0?; + Some(AttributeKind::Align { align, span }) + } +} diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 51c1760da300c..d7570634c1f7e 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -19,7 +19,7 @@ use crate::attributes::confusables::ConfusablesParser; use crate::attributes::deprecation::DeprecationParser; use crate::attributes::inline::{InlineParser, RustcForceInlineParser}; use crate::attributes::lint_helpers::AsPtrParser; -use crate::attributes::repr::ReprParser; +use crate::attributes::repr::{AlignParser, ReprParser}; use crate::attributes::stability::{ BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser, }; @@ -90,6 +90,7 @@ macro_rules! attribute_parsers { attribute_parsers!( pub(crate) static ATTRIBUTE_PARSERS = [ // tidy-alphabetical-start + AlignParser, BodyStabilityParser, ConfusablesParser, ConstStabilityParser, diff --git a/compiler/rustc_attr_parsing/src/session_diagnostics.rs b/compiler/rustc_attr_parsing/src/session_diagnostics.rs index 57ac92a0ca190..337921a318c38 100644 --- a/compiler/rustc_attr_parsing/src/session_diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/session_diagnostics.rs @@ -450,6 +450,14 @@ pub(crate) struct EmptyConfusables { pub span: Span, } +#[derive(Diagnostic)] +#[diag(attr_parsing_invalid_alignment_value, code = E0589)] +pub(crate) struct InvalidAlignmentValue { + #[primary_span] + pub span: Span, + pub error_part: &'static str, +} + #[derive(Diagnostic)] #[diag(attr_parsing_repr_ident, code = E0565)] pub(crate) struct ReprIdent { diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 188a9a98ce7a0..98742255063f7 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -3,7 +3,6 @@ use std::str::FromStr; use rustc_abi::ExternAbi; use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode}; use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr}; -use rustc_attr_data_structures::ReprAttr::ReprAlign; use rustc_attr_data_structures::{ AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr, find_attr, }; @@ -110,17 +109,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } }; - if let hir::Attribute::Parsed(p) = attr { - match p { - AttributeKind::Repr(reprs) => { - codegen_fn_attrs.alignment = reprs - .iter() - .filter_map(|(r, _)| if let ReprAlign(x) = r { Some(*x) } else { None }) - .max(); - } - - _ => {} - } + if let hir::Attribute::Parsed(AttributeKind::Align { align, .. }) = attr { + codegen_fn_attrs.alignment = Some(*align); } let Some(Ident { name, .. }) = attr.ident() else { diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index b5218ec267cce..5b1f1684d54c1 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -495,6 +495,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ), ungated!(no_link, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), ungated!(repr, Normal, template!(List: "C"), DuplicatesOk, EncodeCrossCrate::No), + gated!(align, Normal, template!(List: "alignment"), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(align)), ungated!(unsafe(Edition2024) export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No), ungated!(unsafe(Edition2024) link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No), ungated!(unsafe(Edition2024) no_mangle, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), diff --git a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs index f21cf5fa45e69..2f16d385efb34 100644 --- a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs +++ b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs @@ -47,8 +47,7 @@ pub struct CodegenFnAttrs { /// be generated against a specific instruction set. Only usable on architectures which allow /// switching between multiple instruction sets. pub instruction_set: Option, - /// The `#[repr(align(...))]` attribute. Indicates the value of which the function should be - /// aligned to. + /// The `#[align(...)]` attribute. Determines the alignment of the function body. pub alignment: Option, /// The `#[patchable_function_entry(...)]` attribute. Indicates how many nops should be around /// the function entry. diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs index b3096e46b09ca..a12215a44f95d 100644 --- a/compiler/rustc_parse/src/validate_attr.rs +++ b/compiler/rustc_parse/src/validate_attr.rs @@ -289,6 +289,7 @@ fn emit_malformed_attribute( | sym::rustc_force_inline | sym::rustc_confusables | sym::repr + | sym::align | sym::deprecated ) { return; diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index 7c237d708c0ad..c1a2b3b29733f 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -13,6 +13,10 @@ passes_abi_ne = passes_abi_of = fn_abi_of({$fn_name}) = {$fn_abi} +passes_align_should_be_repr_align = + `#[align(...)]` is not supported on {$item} items + .suggestion = use `#[repr(align(...))]` instead + passes_allow_incoherent_impl = `rustc_allow_incoherent_impl` attribute should be applied to impl items .label = the only currently supported targets are inherent methods @@ -29,10 +33,6 @@ passes_attr_application_struct = attribute should be applied to a struct .label = not a struct -passes_attr_application_struct_enum_function_method_union = - attribute should be applied to a struct, enum, function, associated function, or union - .label = not a struct, enum, function, associated function, or union - passes_attr_application_struct_enum_union = attribute should be applied to a struct, enum, or union .label = not a struct, enum, or union @@ -583,13 +583,14 @@ passes_remove_fields = *[other] fields } -passes_repr_align_function = - `repr(align)` attributes on functions are unstable - passes_repr_align_greater_than_target_max = alignment must not be greater than `isize::MAX` bytes .note = `isize::MAX` is {$size} for the current target +passes_repr_align_should_be_align = + `#[repr(align(...))]` is not supported on {$item} items + .help = use `#[align(...)]` instead + passes_repr_conflicting = conflicting representation hints diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 5ce803aa1f8a0..50d6c5d9764a5 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -146,6 +146,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } Attribute::Parsed(AttributeKind::Repr(_)) => { /* handled below this loop and elsewhere */ } + Attribute::Parsed(AttributeKind::Align { align, span: repr_span }) => { + self.check_align(span, target, *align, *repr_span) + } + Attribute::Parsed( AttributeKind::BodyStability { .. } | AttributeKind::ConstStabilityIndirect @@ -643,6 +647,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { sym::naked, sym::instruction_set, sym::repr, + sym::align, sym::rustc_std_internal_symbol, // code generation sym::cold, @@ -679,7 +684,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { // this check can be part of the parser and be removed here match other_attr { Attribute::Parsed( - AttributeKind::Deprecation { .. } | AttributeKind::Repr { .. }, + AttributeKind::Deprecation { .. } + | AttributeKind::Repr { .. } + | AttributeKind::Align { .. }, ) => { continue; } @@ -1964,6 +1971,28 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } + /// Checks if the `#[align]` attributes on `item` are valid. + fn check_align(&self, span: Span, target: Target, align: Align, repr_span: Span) { + match target { + Target::Fn | Target::Method(_) => {} + Target::Struct | Target::Union | Target::Enum => { + self.dcx().emit_err(errors::AlignShouldBeReprAlign { + span: repr_span, + item: target.name(), + align_bytes: align.bytes(), + }); + } + _ => { + self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { + hint_span: repr_span, + span, + }); + } + } + + self.check_align_value(align, repr_span); + } + /// Checks if the `#[repr]` attributes on `item` are valid. fn check_repr( &self, @@ -2016,23 +2045,16 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match target { Target::Struct | Target::Union | Target::Enum => {} Target::Fn | Target::Method(_) => { - if !self.tcx.features().fn_align() { - feature_err( - &self.tcx.sess, - sym::fn_align, - *repr_span, - fluent::passes_repr_align_function, - ) - .emit(); - } + self.dcx().emit_err(errors::ReprAlignShouldBeAlign { + span: *repr_span, + item: target.name(), + }); } _ => { - self.dcx().emit_err( - errors::AttrApplication::StructEnumFunctionMethodUnion { - hint_span: *repr_span, - span, - }, - ); + self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { + hint_span: *repr_span, + span, + }); } } @@ -2090,21 +2112,16 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match target { Target::Struct | Target::Union | Target::Enum => continue, Target::Fn | Target::Method(_) => { - feature_err( - &self.tcx.sess, - sym::fn_align, - *repr_span, - fluent::passes_repr_align_function, - ) - .emit(); + self.dcx().emit_err(errors::ReprAlignShouldBeAlign { + span: *repr_span, + item: target.name(), + }); } _ => { - self.dcx().emit_err( - errors::AttrApplication::StructEnumFunctionMethodUnion { - hint_span: *repr_span, - span, - }, - ); + self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { + hint_span: *repr_span, + span, + }); } } } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index f0d4b610f6384..587d9170f067c 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1308,13 +1308,6 @@ pub(crate) enum AttrApplication { #[label] span: Span, }, - #[diag(passes_attr_application_struct_enum_function_method_union, code = E0517)] - StructEnumFunctionMethodUnion { - #[primary_span] - hint_span: Span, - #[label] - span: Span, - }, } #[derive(Diagnostic)] @@ -1816,3 +1809,26 @@ pub(crate) enum UnexportableItem<'a> { field_name: &'a str, }, } + +#[derive(Diagnostic)] +#[diag(passes_repr_align_should_be_align)] +pub(crate) struct ReprAlignShouldBeAlign { + #[primary_span] + #[help] + pub span: Span, + pub item: &'static str, +} + +#[derive(Diagnostic)] +#[diag(passes_align_should_be_repr_align)] +pub(crate) struct AlignShouldBeReprAlign { + #[primary_span] + #[suggestion( + style = "verbose", + applicability = "machine-applicable", + code = "#[repr(align({align_bytes}))]" + )] + pub span: Span, + pub item: &'static str, + pub align_bytes: u64, +} diff --git a/src/tools/miri/tests/pass/fn_align.rs b/src/tools/miri/tests/pass/fn_align.rs index 550bb1cb4d718..28f9299588003 100644 --- a/src/tools/miri/tests/pass/fn_align.rs +++ b/src/tools/miri/tests/pass/fn_align.rs @@ -1,21 +1,21 @@ //@compile-flags: -Zmin-function-alignment=8 #![feature(fn_align)] -// When a function uses `repr(align(N))`, the function address should be a multiple of `N`. +// When a function uses `align(N)`, the function address should be a multiple of `N`. -#[repr(align(256))] +#[align(256)] fn foo() {} -#[repr(align(16))] +#[align(16)] fn bar() {} -#[repr(align(4))] +#[align(4)] fn baz() {} fn main() { assert!((foo as usize).is_multiple_of(256)); assert!((bar as usize).is_multiple_of(16)); - // The maximum of `repr(align(N))` and `-Zmin-function-alignment=N` is used. + // The maximum of `align(N)` and `-Zmin-function-alignment=N` is used. assert!((baz as usize).is_multiple_of(8)); } diff --git a/tests/assembly/naked-functions/wasm32.rs b/tests/assembly/naked-functions/wasm32.rs index 984152f2b4530..5f114246ad557 100644 --- a/tests/assembly/naked-functions/wasm32.rs +++ b/tests/assembly/naked-functions/wasm32.rs @@ -37,7 +37,7 @@ extern "C" fn nop() { #[unsafe(naked)] #[linkage = "weak"] // wasm functions cannot be aligned, so this has no effect -#[repr(align(32))] +#[align(32)] extern "C" fn weak_aligned_nop() { naked_asm!("nop") } diff --git a/tests/codegen/align-fn.rs b/tests/codegen/align-fn.rs index 660d8cd2bbf4f..267da0602406e 100644 --- a/tests/codegen/align-fn.rs +++ b/tests/codegen/align-fn.rs @@ -5,7 +5,7 @@ // CHECK: align 16 #[no_mangle] -#[repr(align(16))] +#[align(16)] pub fn fn_align() {} pub struct A; @@ -13,12 +13,12 @@ pub struct A; impl A { // CHECK: align 16 #[no_mangle] - #[repr(align(16))] + #[align(16)] pub fn method_align(self) {} // CHECK: align 16 #[no_mangle] - #[repr(align(16))] + #[align(16)] pub fn associated_fn() {} } @@ -26,19 +26,19 @@ trait T: Sized { fn trait_fn() {} // CHECK: align 32 - #[repr(align(32))] + #[align(32)] fn trait_method(self) {} } impl T for A { // CHECK: align 16 #[no_mangle] - #[repr(align(16))] + #[align(16)] fn trait_fn() {} // CHECK: align 16 #[no_mangle] - #[repr(align(16))] + #[align(16)] fn trait_method(self) {} } @@ -51,18 +51,20 @@ pub fn foo() { // CHECK-LABEL: align_specified_twice_1 // CHECK-SAME: align 64 #[no_mangle] -#[repr(align(32), align(64))] +#[align(32)] +#[align(64)] pub fn align_specified_twice_1() {} // CHECK-LABEL: align_specified_twice_2 // CHECK-SAME: align 128 #[no_mangle] -#[repr(align(128), align(32))] +#[align(128)] +#[align(32)] pub fn align_specified_twice_2() {} // CHECK-LABEL: align_specified_twice_3 // CHECK-SAME: align 256 #[no_mangle] -#[repr(align(32))] -#[repr(align(256))] +#[align(32)] +#[align(256)] pub fn align_specified_twice_3() {} diff --git a/tests/codegen/min-function-alignment.rs b/tests/codegen/min-function-alignment.rs index 7c0ad12402aad..75f845572a4af 100644 --- a/tests/codegen/min-function-alignment.rs +++ b/tests/codegen/min-function-alignment.rs @@ -18,16 +18,16 @@ pub fn no_explicit_align() {} // align16: align 16 // align1024: align 1024 #[no_mangle] -#[repr(align(8))] +#[align(8)] pub fn lower_align() {} -// the higher value of min-function-alignment and repr(align) wins out +// the higher value of min-function-alignment and the align attribute wins out // // CHECK-LABEL: @higher_align // align16: align 32 // align1024: align 1024 #[no_mangle] -#[repr(align(32))] +#[align(32)] pub fn higher_align() {} // cold functions follow the same rules as other functions diff --git a/tests/codegen/naked-fn/aligned.rs b/tests/codegen/naked-fn/aligned.rs index 47ef779f1b217..f9fce8e5a5d59 100644 --- a/tests/codegen/naked-fn/aligned.rs +++ b/tests/codegen/naked-fn/aligned.rs @@ -8,7 +8,7 @@ use std::arch::naked_asm; // CHECK: .balign 16 // CHECK-LABEL: naked_empty: -#[repr(align(16))] +#[align(16)] #[no_mangle] #[unsafe(naked)] pub extern "C" fn naked_empty() { diff --git a/tests/codegen/naked-fn/min-function-alignment.rs b/tests/codegen/naked-fn/min-function-alignment.rs index 1d778be8c90dc..59554c1cae554 100644 --- a/tests/codegen/naked-fn/min-function-alignment.rs +++ b/tests/codegen/naked-fn/min-function-alignment.rs @@ -16,7 +16,7 @@ pub extern "C" fn naked_no_explicit_align() { // CHECK: .balign 16 #[no_mangle] -#[repr(align(8))] +#[align(8)] #[unsafe(naked)] pub extern "C" fn naked_lower_align() { core::arch::naked_asm!("ret") @@ -24,7 +24,7 @@ pub extern "C" fn naked_lower_align() { // CHECK: .balign 32 #[no_mangle] -#[repr(align(32))] +#[align(32)] #[unsafe(naked)] pub extern "C" fn naked_higher_align() { core::arch::naked_asm!("ret") diff --git a/tests/ui/asm/naked-with-invalid-repr-attr.rs b/tests/ui/asm/naked-with-invalid-repr-attr.rs index 96eed70dc5504..bfbbf29a69ee7 100644 --- a/tests/ui/asm/naked-with-invalid-repr-attr.rs +++ b/tests/ui/asm/naked-with-invalid-repr-attr.rs @@ -19,8 +19,9 @@ extern "C" fn example2() { naked_asm!("") } -#[repr(align(16), C)] +#[repr(C)] //~^ ERROR attribute should be applied to a struct, enum, or union [E0517] +#[align(16)] #[unsafe(naked)] extern "C" fn example3() { //~^ NOTE not a struct, enum, or union diff --git a/tests/ui/asm/naked-with-invalid-repr-attr.stderr b/tests/ui/asm/naked-with-invalid-repr-attr.stderr index f173a39e5bf6d..4eb4a4e5a0482 100644 --- a/tests/ui/asm/naked-with-invalid-repr-attr.stderr +++ b/tests/ui/asm/naked-with-invalid-repr-attr.stderr @@ -23,10 +23,10 @@ LL | | } | |_- not a struct, enum, or union error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/naked-with-invalid-repr-attr.rs:22:19 + --> $DIR/naked-with-invalid-repr-attr.rs:22:8 | -LL | #[repr(align(16), C)] - | ^ +LL | #[repr(C)] + | ^ ... LL | / extern "C" fn example3() { LL | | @@ -35,7 +35,7 @@ LL | | } | |_- not a struct, enum, or union error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/naked-with-invalid-repr-attr.rs:31:8 + --> $DIR/naked-with-invalid-repr-attr.rs:32:8 | LL | #[repr(C, packed)] | ^ @@ -48,7 +48,7 @@ LL | | } | |_- not a struct, enum, or union error[E0517]: attribute should be applied to a struct or union - --> $DIR/naked-with-invalid-repr-attr.rs:31:11 + --> $DIR/naked-with-invalid-repr-attr.rs:32:11 | LL | #[repr(C, packed)] | ^^^^^^ @@ -61,7 +61,7 @@ LL | | } | |_- not a struct or union error[E0517]: attribute should be applied to an enum - --> $DIR/naked-with-invalid-repr-attr.rs:41:8 + --> $DIR/naked-with-invalid-repr-attr.rs:42:8 | LL | #[repr(u8)] | ^^ diff --git a/tests/ui/attributes/arg-error-issue-121425.stderr b/tests/ui/attributes/arg-error-issue-121425.stderr index 6e71f15fdc872..1beb99b1703cf 100644 --- a/tests/ui/attributes/arg-error-issue-121425.stderr +++ b/tests/ui/attributes/arg-error-issue-121425.stderr @@ -1,9 +1,3 @@ -error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses - --> $DIR/arg-error-issue-121425.rs:16:8 - | -LL | #[repr(align())] - | ^^^^^^^ - error[E0693]: incorrect `repr(align)` attribute format: `align` expects a literal integer as argument --> $DIR/arg-error-issue-121425.rs:4:14 | @@ -22,6 +16,12 @@ error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer LL | #[repr(align("str"))] | ^^^^^ +error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses + --> $DIR/arg-error-issue-121425.rs:16:8 + | +LL | #[repr(align())] + | ^^^^^^^ + error[E0552]: incorrect `repr(packed)` attribute format: `packed` expects a literal integer as argument --> $DIR/arg-error-issue-121425.rs:21:15 | diff --git a/tests/ui/attributes/invalid-repr.rs b/tests/ui/attributes/invalid-repr.rs index 10a487c127ec8..d7933533405c4 100644 --- a/tests/ui/attributes/invalid-repr.rs +++ b/tests/ui/attributes/invalid-repr.rs @@ -1,5 +1,5 @@ #[repr(align(16))] -//~^ ERROR attribute should be applied to a struct, enum, function, associated function, or union +//~^ ERROR attribute should be applied to a struct, enum, or union pub type Foo = i32; fn main() {} diff --git a/tests/ui/attributes/invalid-repr.stderr b/tests/ui/attributes/invalid-repr.stderr index 681460ad0812f..3f5a305c6b700 100644 --- a/tests/ui/attributes/invalid-repr.stderr +++ b/tests/ui/attributes/invalid-repr.stderr @@ -1,11 +1,11 @@ -error[E0517]: attribute should be applied to a struct, enum, function, associated function, or union +error[E0517]: attribute should be applied to a struct, enum, or union --> $DIR/invalid-repr.rs:1:8 | LL | #[repr(align(16))] | ^^^^^^^^^ LL | LL | pub type Foo = i32; - | ------------------- not a struct, enum, function, associated function, or union + | ------------------- not a struct, enum, or union error: aborting due to 1 previous error diff --git a/tests/ui/attributes/malformed-fn-align.rs b/tests/ui/attributes/malformed-fn-align.rs index 4aaad01b7235e..35ffd6d8acce9 100644 --- a/tests/ui/attributes/malformed-fn-align.rs +++ b/tests/ui/attributes/malformed-fn-align.rs @@ -2,6 +2,21 @@ #![crate_type = "lib"] trait MyTrait { - #[repr(align)] //~ ERROR invalid `repr(align)` attribute: `align` needs an argument + #[align] //~ ERROR malformed `align` attribute input fn myfun(); } + +#[align = 16] //~ ERROR malformed `align` attribute input +fn f1() {} + +#[align("hello")] //~ ERROR invalid alignment value: not an unsuffixed integer +fn f2() {} + +#[align(0)] //~ ERROR invalid alignment value: not a power of two +fn f3() {} + +#[repr(align(16))] //~ ERROR `#[repr(align(...))]` is not supported on function items +fn f4() {} + +#[align(16)] //~ ERROR `#[align(...)]` is not supported on struct items +struct S1; diff --git a/tests/ui/attributes/malformed-fn-align.stderr b/tests/ui/attributes/malformed-fn-align.stderr index 57913c48ef787..765255c2c3a95 100644 --- a/tests/ui/attributes/malformed-fn-align.stderr +++ b/tests/ui/attributes/malformed-fn-align.stderr @@ -1,9 +1,66 @@ -error[E0589]: invalid `repr(align)` attribute: `align` needs an argument - --> $DIR/malformed-fn-align.rs:5:12 +error[E0539]: malformed `align` attribute input + --> $DIR/malformed-fn-align.rs:5:5 + | +LL | #[align] + | ^^^^^^^^ expected this to be a list + | +help: try changing it to one of the following valid forms of the attribute + | +LL | #[align()] + | ++++++++++++++++++++++ + +error[E0539]: malformed `align` attribute input + --> $DIR/malformed-fn-align.rs:9:1 + | +LL | #[align = 16] + | ^^^^^^^^^^^^^ expected this to be a list + | +help: try changing it to one of the following valid forms of the attribute + | +LL - #[align = 16] +LL + #[align()] + | +LL - #[align = 16] +LL + #[align] + | + +error[E0589]: invalid alignment value: not an unsuffixed integer + --> $DIR/malformed-fn-align.rs:12:9 + | +LL | #[align("hello")] + | ^^^^^^^ + +error[E0589]: invalid alignment value: not a power of two + --> $DIR/malformed-fn-align.rs:15:9 + | +LL | #[align(0)] + | ^ + +error: `#[repr(align(...))]` is not supported on function items + --> $DIR/malformed-fn-align.rs:18:8 + | +LL | #[repr(align(16))] + | ^^^^^^^^^ + | +help: use `#[align(...)]` instead + --> $DIR/malformed-fn-align.rs:18:8 + | +LL | #[repr(align(16))] + | ^^^^^^^^^ + +error: `#[align(...)]` is not supported on struct items + --> $DIR/malformed-fn-align.rs:21:1 + | +LL | #[align(16)] + | ^^^^^^^^^^^^ + | +help: use `#[repr(align(...))]` instead + | +LL - #[align(16)] +LL + #[repr(align(16))] | -LL | #[repr(align)] - | ^^^^^ help: supply an argument here: `align(...)` -error: aborting due to 1 previous error +error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0589`. +Some errors have detailed explanations: E0539, E0589. +For more information about an error, try `rustc --explain E0539`. diff --git a/tests/ui/feature-gates/feature-gate-fn_align.rs b/tests/ui/feature-gates/feature-gate-fn_align.rs index 744877704dd11..b6c300e5cbe61 100644 --- a/tests/ui/feature-gates/feature-gate-fn_align.rs +++ b/tests/ui/feature-gates/feature-gate-fn_align.rs @@ -1,9 +1,12 @@ #![crate_type = "lib"] -#[repr(align(16))] //~ ERROR `repr(align)` attributes on functions are unstable +#[align(16)] +//~^ ERROR the `#[align]` attribute is an experimental feature fn requires_alignment() {} trait MyTrait { - #[repr(align)] //~ ERROR invalid `repr(align)` attribute: `align` needs an argument + #[align] + //~^ ERROR the `#[align]` attribute is an experimental feature + //~| ERROR malformed `align` attribute input fn myfun(); } diff --git a/tests/ui/feature-gates/feature-gate-fn_align.stderr b/tests/ui/feature-gates/feature-gate-fn_align.stderr index ff17c29fe0296..93ef136dc73cd 100644 --- a/tests/ui/feature-gates/feature-gate-fn_align.stderr +++ b/tests/ui/feature-gates/feature-gate-fn_align.stderr @@ -1,20 +1,35 @@ -error[E0589]: invalid `repr(align)` attribute: `align` needs an argument - --> $DIR/feature-gate-fn_align.rs:7:12 +error[E0658]: the `#[align]` attribute is an experimental feature + --> $DIR/feature-gate-fn_align.rs:3:1 | -LL | #[repr(align)] - | ^^^^^ help: supply an argument here: `align(...)` +LL | #[align(16)] + | ^^^^^^^^^^^^ + | + = note: see issue #82232 for more information + = help: add `#![feature(fn_align)]` 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]: `repr(align)` attributes on functions are unstable - --> $DIR/feature-gate-fn_align.rs:3:8 +error[E0658]: the `#[align]` attribute is an experimental feature + --> $DIR/feature-gate-fn_align.rs:8:5 | -LL | #[repr(align(16))] - | ^^^^^^^^^ +LL | #[align] + | ^^^^^^^^ | = note: see issue #82232 for more information = help: add `#![feature(fn_align)]` 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 +error[E0539]: malformed `align` attribute input + --> $DIR/feature-gate-fn_align.rs:8:5 + | +LL | #[align] + | ^^^^^^^^ expected this to be a list + | +help: try changing it to one of the following valid forms of the attribute + | +LL | #[align()] + | ++++++++++++++++++++++ + +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0589, E0658. -For more information about an error, try `rustc --explain E0589`. +Some errors have detailed explanations: E0539, E0658. +For more information about an error, try `rustc --explain E0539`. diff --git a/tests/ui/repr/attr-usage-repr.rs b/tests/ui/repr/attr-usage-repr.rs index cbf99f16e036b..ca63ac564fc57 100644 --- a/tests/ui/repr/attr-usage-repr.rs +++ b/tests/ui/repr/attr-usage-repr.rs @@ -45,7 +45,7 @@ enum EInt { B, } -#[repr()] //~ ERROR attribute should be applied to a struct, enum, function, associated function, or union [E0517] +#[repr()] //~ ERROR attribute should be applied to a struct, enum, or union [E0517] type SirThisIsAType = i32; #[repr()] diff --git a/tests/ui/repr/attr-usage-repr.stderr b/tests/ui/repr/attr-usage-repr.stderr index a25e68c483f66..a62992c597a2e 100644 --- a/tests/ui/repr/attr-usage-repr.stderr +++ b/tests/ui/repr/attr-usage-repr.stderr @@ -36,13 +36,13 @@ LL | | B, LL | | } | |_- not a struct -error[E0517]: attribute should be applied to a struct, enum, function, associated function, or union +error[E0517]: attribute should be applied to a struct, enum, or union --> $DIR/attr-usage-repr.rs:48:1 | LL | #[repr()] | ^^^^^^^^^ LL | type SirThisIsAType = i32; - | -------------------------- not a struct, enum, function, associated function, or union + | -------------------------- not a struct, enum, or union error: aborting due to 5 previous errors diff --git a/tests/ui/repr/malformed-repr-hints.stderr b/tests/ui/repr/malformed-repr-hints.stderr index 7a6e9ccc73eb1..6fb927557619f 100644 --- a/tests/ui/repr/malformed-repr-hints.stderr +++ b/tests/ui/repr/malformed-repr-hints.stderr @@ -1,15 +1,3 @@ -error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses - --> $DIR/malformed-repr-hints.rs:14:8 - | -LL | #[repr(align(2, 4))] - | ^^^^^^^^^^^ - -error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses - --> $DIR/malformed-repr-hints.rs:18:8 - | -LL | #[repr(align())] - | ^^^^^^^ - error[E0552]: incorrect `repr(packed)` attribute format: `packed` takes exactly one parenthesized argument, or no parentheses at all --> $DIR/malformed-repr-hints.rs:6:8 | @@ -22,6 +10,18 @@ error[E0589]: invalid `repr(align)` attribute: `align` needs an argument LL | #[repr(align)] | ^^^^^ help: supply an argument here: `align(...)` +error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses + --> $DIR/malformed-repr-hints.rs:14:8 + | +LL | #[repr(align(2, 4))] + | ^^^^^^^^^^^ + +error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses + --> $DIR/malformed-repr-hints.rs:18:8 + | +LL | #[repr(align())] + | ^^^^^^^ + error[E0552]: invalid representation hint: `Rust` does not take a parenthesized argument list --> $DIR/malformed-repr-hints.rs:23:8 | From 377d8fa4e3057838f20dd1eb1669d4ebaf8a561a Mon Sep 17 00:00:00 2001 From: Boxy Date: Wed, 18 Jun 2025 15:04:03 +0100 Subject: [PATCH 12/14] Reviews --- compiler/rustc_type_ir/src/fast_reject.rs | 3 --- tests/ui/associated-inherent-types/bound_vars_in_args.rs | 4 ++-- .../ui/associated-inherent-types/candidate-with-alias-2.rs | 3 +++ .../associated-inherent-types/candidate-with-alias-2.stderr | 6 +++--- tests/ui/associated-inherent-types/candidate-with-alias.rs | 3 +++ .../multiple-candidates-in-adt-field-2.rs | 4 ++-- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_type_ir/src/fast_reject.rs b/compiler/rustc_type_ir/src/fast_reject.rs index a5d461c57cd40..d88c88fc6f3f5 100644 --- a/compiler/rustc_type_ir/src/fast_reject.rs +++ b/compiler/rustc_type_ir/src/fast_reject.rs @@ -241,9 +241,6 @@ impl bool { - if lhs == rhs { - return true; - } self.types_may_unify_inner(lhs, rhs, depth_limit) } diff --git a/tests/ui/associated-inherent-types/bound_vars_in_args.rs b/tests/ui/associated-inherent-types/bound_vars_in_args.rs index 0baa242af7689..49a9ef31cd67c 100644 --- a/tests/ui/associated-inherent-types/bound_vars_in_args.rs +++ b/tests/ui/associated-inherent-types/bound_vars_in_args.rs @@ -1,8 +1,8 @@ #![feature(non_lifetime_binders, inherent_associated_types)] #![expect(incomplete_features)] -// Test that we can resolve to the right IAT when the self type -// contains a bound type. +// Test whether we can resolve to the right IAT when the self type +// contains a bound type. This should ideally use the second impl. struct Foo(T); diff --git a/tests/ui/associated-inherent-types/candidate-with-alias-2.rs b/tests/ui/associated-inherent-types/candidate-with-alias-2.rs index d7be825a9c22e..551d30a8786e0 100644 --- a/tests/ui/associated-inherent-types/candidate-with-alias-2.rs +++ b/tests/ui/associated-inherent-types/candidate-with-alias-2.rs @@ -1,6 +1,9 @@ #![feature(inherent_associated_types)] #![expect(incomplete_features)] +// A behaviour test showcasing that we do not normalize associated types in +// the impl self ty when assembling IAT candidates + trait Identity { type Assoc; } diff --git a/tests/ui/associated-inherent-types/candidate-with-alias-2.stderr b/tests/ui/associated-inherent-types/candidate-with-alias-2.stderr index 335e35a95778d..2b79b65f22ba0 100644 --- a/tests/ui/associated-inherent-types/candidate-with-alias-2.stderr +++ b/tests/ui/associated-inherent-types/candidate-with-alias-2.stderr @@ -1,16 +1,16 @@ error[E0034]: multiple applicable items in scope - --> $DIR/candidate-with-alias-2.rs:20:23 + --> $DIR/candidate-with-alias-2.rs:23:23 | LL | field: >::Inherent, | ^^^^^^^^ multiple `Inherent` found | note: candidate #1 is defined in an impl for the type `Foo<::Assoc>` - --> $DIR/candidate-with-alias-2.rs:13:5 + --> $DIR/candidate-with-alias-2.rs:16:5 | LL | type Inherent = u8; | ^^^^^^^^^^^^^ note: candidate #2 is defined in an impl for the type `Foo<::Assoc>` - --> $DIR/candidate-with-alias-2.rs:16:5 + --> $DIR/candidate-with-alias-2.rs:19:5 | LL | type Inherent = u32; | ^^^^^^^^^^^^^ diff --git a/tests/ui/associated-inherent-types/candidate-with-alias.rs b/tests/ui/associated-inherent-types/candidate-with-alias.rs index d4dd002a77415..a84da195c26b0 100644 --- a/tests/ui/associated-inherent-types/candidate-with-alias.rs +++ b/tests/ui/associated-inherent-types/candidate-with-alias.rs @@ -3,6 +3,9 @@ #![feature(inherent_associated_types)] #![expect(incomplete_features)] +// A behaviour test showcasing that IAT resolution can pick the right +// candidate even if it has an alias, if it's the only candidate. + trait Identity { type Assoc; } diff --git a/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-2.rs b/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-2.rs index b942c303d3e84..8a6d1896f7d29 100644 --- a/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-2.rs +++ b/tests/ui/associated-inherent-types/multiple-candidates-in-adt-field-2.rs @@ -1,8 +1,8 @@ #![feature(inherent_associated_types)] #![expect(incomplete_features)] -// Test that when we have an unnormalized projection we don't normalize it -// to determine which IAT to resolve to. +// Test that when we have an unnormalized projection in the IAT self ty +// we don't normalize it to determine which IAT to resolve to. struct Foo(T); impl Foo { From b47d36d8d1c22aa036021cc7a3c91f9edce043dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 17 Jun 2025 09:47:37 +0200 Subject: [PATCH 13/14] Remove `override_build_kind` It doesn't seem to be needed, we can just use `Kind::Check` explicitly. --- src/bootstrap/src/core/build_steps/check.rs | 26 +++----------------- src/bootstrap/src/core/build_steps/clippy.rs | 2 +- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index f47873590a17b..f5dae626a89bd 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -199,13 +199,6 @@ pub struct Rustc { /// /// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc crates: Vec, - /// Override `Builder::kind` on cargo invocations. - /// - /// By default, `Builder::kind` is propagated as the subcommand to the cargo invocations. - /// However, there are cases when this is not desirable. For example, when running `x clippy $tool_name`, - /// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library, - /// which is not useful if we only want to lint a few crates with specific rules. - override_build_kind: Option, } impl Rustc { @@ -215,12 +208,7 @@ impl Rustc { .into_iter() .map(|krate| krate.name.to_string()) .collect(); - Self { target, crates, override_build_kind: None } - } - - pub fn build_kind(mut self, build_kind: Option) -> Self { - self.override_build_kind = build_kind; - self + Self { target, crates } } } @@ -235,7 +223,7 @@ impl Step for Rustc { fn make_run(run: RunConfig<'_>) { let crates = run.make_run_crates(Alias::Compiler); - run.builder.ensure(Rustc { target: run.target, crates, override_build_kind: None }); + run.builder.ensure(Rustc { target: run.target, crates }); } /// Builds the compiler. @@ -256,7 +244,7 @@ impl Step for Rustc { builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host)); builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target)); } else { - builder.ensure(Std::new(target).build_kind(self.override_build_kind)); + builder.ensure(Std::new(target)); } let mut cargo = builder::Cargo::new( @@ -265,17 +253,11 @@ impl Step for Rustc { Mode::Rustc, SourceType::InTree, target, - self.override_build_kind.unwrap_or(builder.kind), + Kind::Check, ); rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates); - // For ./x.py clippy, don't run with --all-targets because - // linting tests and benchmarks can produce very noisy results - if builder.kind != Kind::Clippy { - cargo.arg("--all-targets"); - } - // Explicitly pass -p for all compiler crates -- this will force cargo // to also check the tests/benches/examples for these crates, rather // than just the leaf crate. diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index 788a3b9601d9d..f1932479d4679 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -289,7 +289,7 @@ macro_rules! lint_any { let target = self.target; if !builder.download_rustc() { - builder.ensure(check::Rustc::new(target, builder).build_kind(Some(Kind::Check))); + builder.ensure(check::Rustc::new(target, builder)); }; let cargo = prepare_tool_cargo( From 887566881f92051cf29be482fae0b8c9cced1af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 17 Jun 2025 13:09:43 +0200 Subject: [PATCH 14/14] Remove useless conditions about Clippy We should always just use `Kind::Check` for the check steps, as Clippy now has an entirely separate set of steps. --- src/bootstrap/src/core/build_steps/check.rs | 51 ++++---------------- src/bootstrap/src/core/build_steps/clippy.rs | 2 +- 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index f5dae626a89bd..fcd4f4078adb4 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -21,13 +21,6 @@ pub struct Std { /// /// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc crates: Vec, - /// Override `Builder::kind` on cargo invocations. - /// - /// By default, `Builder::kind` is propagated as the subcommand to the cargo invocations. - /// However, there are cases when this is not desirable. For example, when running `x clippy $tool_name`, - /// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library, - /// which is not useful if we only want to lint a few crates with specific rules. - override_build_kind: Option, /// Never use this from outside calls. It is intended for internal use only within `check::Std::make_run` /// and `check::Std::run`. custom_stage: Option, @@ -37,12 +30,7 @@ impl Std { const CRATE_OR_DEPS: &[&str] = &["sysroot", "coretests", "alloctests"]; pub fn new(target: TargetSelection) -> Self { - Self { target, crates: vec![], override_build_kind: None, custom_stage: None } - } - - pub fn build_kind(mut self, kind: Option) -> Self { - self.override_build_kind = kind; - self + Self { target, crates: vec![], custom_stage: None } } } @@ -68,12 +56,7 @@ impl Step for Std { 1 }; - run.builder.ensure(Std { - target: run.target, - crates, - override_build_kind: None, - custom_stage: Some(stage), - }); + run.builder.ensure(Std { target: run.target, crates, custom_stage: Some(stage) }); } fn run(self, builder: &Builder<'_>) { @@ -116,7 +99,7 @@ impl Step for Std { Mode::Std, SourceType::InTree, target, - self.override_build_kind.unwrap_or(builder.kind), + Kind::Check, ); std_cargo(builder, target, compiler.stage, &mut cargo); @@ -147,9 +130,8 @@ impl Step for Std { } drop(_guard); - // don't run on std twice with x.py clippy // don't check test dependencies if we haven't built libtest - if builder.kind == Kind::Clippy || !self.crates.iter().any(|krate| krate == "test") { + if !self.crates.iter().any(|krate| krate == "test") { return; } @@ -165,7 +147,7 @@ impl Step for Std { Mode::Std, SourceType::InTree, target, - self.override_build_kind.unwrap_or(builder.kind), + Kind::Check, ); // If we're not in stage 0, tests and examples will fail to compile @@ -382,14 +364,9 @@ impl Step for RustAnalyzer { cargo.allow_features(crate::core::build_steps::tool::RustAnalyzer::ALLOW_FEATURES); - // For ./x.py clippy, don't check those targets because - // linting tests and benchmarks can produce very noisy results - if builder.kind != Kind::Clippy { - // can't use `--all-targets` because `--examples` doesn't work well - cargo.arg("--bins"); - cargo.arg("--tests"); - cargo.arg("--benches"); - } + cargo.arg("--bins"); + cargo.arg("--tests"); + cargo.arg("--benches"); // Cargo's output path in a given stage, compiled by a particular // compiler for the specified target. @@ -450,11 +427,7 @@ impl Step for Compiletest { cargo.allow_features(COMPILETEST_ALLOW_FEATURES); - // For ./x.py clippy, don't run with --all-targets because - // linting tests and benchmarks can produce very noisy results - if builder.kind != Kind::Clippy { - cargo.arg("--all-targets"); - } + cargo.arg("--all-targets"); let stamp = BuildStamp::new(&builder.cargo_out(compiler, mode, self.target)) .with_prefix("compiletest-check"); @@ -528,11 +501,7 @@ fn run_tool_check_step( &[], ); - // For ./x.py clippy, don't run with --all-targets because - // linting tests and benchmarks can produce very noisy results - if builder.kind != Kind::Clippy { - cargo.arg("--all-targets"); - } + cargo.arg("--all-targets"); let stamp = BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target)) .with_prefix(&format!("{}-check", step_type_name.to_lowercase())); diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index f1932479d4679..ebf0caccfbc98 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -217,7 +217,7 @@ impl Step for Rustc { builder.ensure(compile::Std::new(compiler, compiler.host)); builder.ensure(compile::Std::new(compiler, target)); } else { - builder.ensure(check::Std::new(target).build_kind(Some(Kind::Check))); + builder.ensure(check::Std::new(target)); } }