about summary refs log tree commit diff
path: root/tests
AgeCommit message (Collapse)AuthorLines
2024-10-01Auto merge of #131111 - matthiaskrgr:rollup-n6do187, r=matthiaskrgrbors-8/+10
Rollup of 4 pull requests Successful merges: - #130005 (Replace -Z default-hidden-visibility with -Z default-visibility) - #130229 (ptr::add/sub: do not claim equivalence with `offset(c as isize)`) - #130773 (Update Unicode escapes in `/library/core/src/char/methods.rs`) - #130933 (rustdoc: lists items that contain multiple paragraphs are more clear) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-01Rollup merge of #130005 - davidlattimore:protected-vis-flag, r=UrgauMatthias Krüger-8/+10
Replace -Z default-hidden-visibility with -Z default-visibility Issue #105518
2024-10-01Auto merge of #131098 - GuillaumeGomez:rollup-kk74was, r=GuillaumeGomezbors-7/+58
Rollup of 5 pull requests Successful merges: - #130630 (Support clobber_abi and vector/access registers (clobber-only) in s390x inline assembly) - #131042 (Instantiate binders in `supertrait_vtable_slot`) - #131079 (Update wasm-component-ld to 0.5.9) - #131085 (make test_lots_of_insertions test take less long in Miri) - #131088 (add fixme to remove LLVM_ENABLE_TERMINFO when minimal llvm version is 19) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-01Rollup merge of #131042 - compiler-errors:supertrait-vtable, r=lcnrGuillaume Gomez-7/+8
Instantiate binders in `supertrait_vtable_slot` `supertrait_vtable_slot` was previously using structural equality when probing for the vtable slot, which led to an ICE since we need a *subtype* match, not an exact match. Fixes #131027 r? lcnr
2024-10-01Rollup merge of #130630 - taiki-e:s390x-clobber-abi, r=AmanieuGuillaume Gomez-0/+50
Support clobber_abi and vector/access registers (clobber-only) in s390x inline assembly This supports `clobber_abi` which is one of the requirements of stabilization mentioned in #93335. This also supports vector registers (as `vreg`) and access registers (as `areg`) as clobber-only, which need to support clobbering of them to implement clobber_abi. Refs: - "1.2.1.1. Register Preservation Rules" section in ELF Application Binary Interface s390x Supplement, Version 1.6.1 (lzsabi_s390x.pdf in https://github.com/IBM/s390x-abi/releases/tag/v1.6.1) - Register definition in LLVM: - Vector registers https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/SystemZ/SystemZRegisterInfo.td#L249 - Access registers https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/SystemZ/SystemZRegisterInfo.td#L332 I have three questions: - ~~ELF Application Binary Interface s390x Supplement says that `cc` (condition code, bits 18-19 of PSW) is "Volatile". However, we do not have a register class for `cc` and instead mark `cc` as clobbered unless `preserves_flags` is specified (https://github.com/rust-lang/rust/pull/111331). Therefore, in the current implementation, if both `preserves_flags` and `clobber_abi` are specified, `cc` is not marked as clobbered. Is this okay? Or even if `preserves_flags` is used, should `cc` be marked as clobbered if `clobber_abi` is used?~~ UPDATE: resolved https://github.com/rust-lang/rust/pull/130630#issuecomment-2367923121 - ~~ELF Application Binary Interface s390x Supplement says that `pm` (program mask, bits 20-23 of PSW) is "Cleared". There does not appear to be any registers associated with this in either [LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/SystemZ/SystemZRegisterInfo.td) or [GCC](https://github.com/gcc-mirror/gcc/blob/33ccc1314dcdb0b988a9276ca6b6ce9b07bea21e/gcc/config/s390/s390.h#L407-L431), so at this point I don't see any way other than to just ignore it. Is this okay as-is?~~ UPDATE: resolved https://github.com/rust-lang/rust/pull/130630#issuecomment-2367923121 - Is "areg" a good name for register class name for access registers? It may be a bit confusing between that and `reg_addr`, which uses the “a” constraint (https://github.com/rust-lang/rust/pull/119431)... Note: - GCC seems to [recognize only `a0` and `a1`](https://github.com/gcc-mirror/gcc/blob/33ccc1314dcdb0b988a9276ca6b6ce9b07bea21e/gcc/config/s390/s390.h#L428-L429), and using `a[2-15]` [causes errors](https://godbolt.org/z/a46vx8jjn). Given that cg_gcc has a similar problem with other architecture (https://github.com/rust-lang/rustc_codegen_gcc/issues/485), I don't feel this is a blocker for this PR, but it is worth mentioning here. - `vreg` should be able to accept `#[repr(simd)]` types as input if the `vector` target feature added in https://github.com/rust-lang/rust/pull/127506 is enabled, but core_arch has no s390x vector type and both `#[repr(simd)]` and `core::simd` are unstable, so I have not implemented it in this PR. EDIT: And supporting it is probably more complex than doing the equivalent on other architectures... https://github.com/rust-lang/rust/pull/88245#issuecomment-905559591 cc `@uweigand` r? `@Amanieu` `@rustbot` label +O-SystemZ
2024-10-01Auto merge of #126839 - obeis:mpmc, r=Amanieubors-3/+26
Add multi-producer, multi-consumer channel (mpmc) Closes #125712 Tracking issue: #126840 r? m-ou-se
2024-10-01Replace -Z default-hidden-visibility with -Z default-visibilityDavid Lattimore-8/+10
MCP: https://github.com/rust-lang/compiler-team/issues/782 Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2024-10-01Auto merge of #129972 - eholk:stabilize-expr_2021, r=compiler-errors,traviscrossbors-57/+36
Stabilize expr_2021 fragment specifier in all editions This is part of the `expr`/`expr_2021` fragment specifier for Edition 2024 (#123742). The RFC says we can support expr_2021 in as many editions as is practical, and there's nothing particularly hard about supporting it all the way back to 2015. In editions 2021 and earlier, `expr` and `expr_2021` are synonyms. Their behavior diverges starting in Edition 2024. This is checked by the `expr_2021_inline_const.rs` test. cc `@vincenzopalazzo` `@rust-lang/wg-macros` `@traviscross`
2024-10-01Stabilize expr_2021 fragment in all editionsEric Holk-57/+36
Co-authored-by: Michael Goulet <michael@errs.io> Co-authored-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-10-01Auto merge of #131076 - lukas-code:doc-stab2, r=notriddlebors-8/+43
rustdoc: rewrite stability inheritance as a doc pass Since doc inlining can almost arbitrarily change the module hierarchy, we can't just use the HIR ancestors of an item to compute its effective stability. This PR moves the stability inheritance that I implemented in https://github.com/rust-lang/rust/pull/130798 into a new doc pass `propagate-stability` that runs after doc inlining and uses the post-inlining ancestors of an item to correctly compute its effective stability. fixes https://github.com/rust-lang/rust/issues/131020 r? `@notriddle`
2024-10-01Auto merge of #130587 - coolreader18:field-variant-doclink-disambig, ↵bors-23/+82
r=notriddle,jyn514 Add `field@` and `variant@` doc-link disambiguators I'm not sure if this is big enough to need an fcp or not, but this is something I found missing when trying to refer to a field in macro-generated docs, not knowing if a method might be defined as well. Obviously, there are definitely other uses. In the case where it's not disambiguated, methods (and I suppose other associated items in the value namespace) still take priority, which `@jyn514` said was an oversight but I think is probably the desired behavior 99% of the time anyway - shadowing a field with an accessor method is a very common pattern. If fields and methods with the same name started conflicting, it would be a breaking change. Though, to quote them: > jyn: maybe you can break this only if both [the method and the field] are public > jyn: rustc has some future-incompat warning level > jyn: that gets through -A warnings and --cap-lints from cargo That'd be out of scope of this PR, though. Fixes #80283
2024-09-30Rollup merge of #130966 - RalfJung:ptr-metadata-const-stable, r=scottmcmTrevor Gross-0/+70
make ptr metadata functions callable from stable const fn So far this was done with a bunch of `rustc_allow_const_fn_unstable`. But those should be the exception, not the norm. If we are confident we can expose the ptr metadata APIs *indirectly* in stable const fn, we should just mark them as `rustc_const_stable`. And we better be confident we can do that since it's already been done a while ago. ;) In particular this marks two intrinsics as const-stable: `aggregate_raw_ptr`, `ptr_metadata`. This should be uncontroversial, they are trivial to implement in the interpreter. Cc `@rust-lang/wg-const-eval` `@rust-lang/lang`
2024-09-30Rollup merge of #130877 - taiki-e:riscv-atomic, r=AmanieuTrevor Gross-2/+2
rustc_target: Add RISC-V atomic-related features This adds the following three target features to unstable riscv_target_feature. - `zaamo` (Zaamo Extension 1.0.0): Atomic Memory Operations (`amo*.{w,d}{,.aq,.rl,.aqrl}`) ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L229-L231), [available since LLVM 19](https://github.com/llvm/llvm-project/commit/8be079cdddfd628d356d9ddb5ab397ea95fb1030)) - `zabha` (Zabha Extension 1.0.0): Byte and Halfword Atomic Memory Operations (`amo*.{b,h}{,.aq,.rl,.aqrl}`) ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L238-L240), [available since LLVM 19](https://github.com/llvm/llvm-project/commit/6b7444964a8d028989beee554a1f5c61d16a1cac)) - `zalrsc` (Zalrsc Extension 1.0.0): Load-Reserved/Store-Conditional Instructions (`lr.{w,d}{,.aq,.rl,.aqrl}` and `sc.{w,d}{,.aq,.rl,.aqrl}`) ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L261-L263), [available since LLVM 19](https://github.com/llvm/llvm-project/commit/8be079cdddfd628d356d9ddb5ab397ea95fb1030)) (Zacas Extension is not included here because it is still marked as experimental in LLVM 19 https://github.com/llvm/llvm-project/commit/70e7d26e560173c8b9db4c75ab4a3004cd5f021a and will become non-experimental in LLVM 20 https://github.com/llvm/llvm-project/commit/614aeda93b2225c6eb42b00ba189ba7ca2585c60) `a` implies `zaamo` and `zalrsc`, and `zabha` implies `zaamo`: - After Zaamo and Zalrsc Extensions are frozen, riscv-isa-manual says "The A extension comprises instructions provided by the Zaamo and Zalrsc extensions" (https://github.com/riscv/riscv-isa-manual/commit/e87412e621f11f4aac61a3b9d5e73e98a64b3432), and [`a` implies `zaamo` and `zalrsc` in GCC](https://github.com/gcc-mirror/gcc/blob/08693e29ec186fd7941d0b73d4d466388971fe2f/gcc/config/riscv/arch-canonicalize#L44). However, in LLVM, [`a` does not define them as implying `zaamo` and `zalrsc`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/RISCV/RISCVFeatures.td#L206). - Zabha and Zaamo are in a similar situation, [riscv-isa-manual](https://github.com/riscv/riscv-isa-manual/blob/main/src/zabha.adoc) says "The Zabha extension depends upon the Zaamo standard extension", and [`zabha` implies `zaamo` in GCC](https://github.com/gcc-mirror/gcc/blob/08693e29ec186fd7941d0b73d4d466388971fe2f/gcc/config/riscv/arch-canonicalize#L45-L46), but [does not in LLVM (but enabling `zabha` without `zaamo` or `a` is not allowed)](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/TargetParser/RISCVISAInfo.cpp#L776-L778). r? `@Amanieu` `@rustbot` label +O-riscv +A-target-feature
2024-09-30rustdoc: rewrite stability inheritance as a passLukas Markeffsky-8/+43
2024-09-30add test ensuring we cannot call const-stable unstable functionsRalf Jung-0/+70
2024-09-30Add multi-producer, multi-consumer channel (mpmc)Obei Sideg-3/+26
2024-09-30Instantiate binders in supertrait_vtable_slotMichael Goulet-7/+8
2024-09-30Rollup merge of #131038 - onkoe:fix/adt_const_params_leak_118179, ↵Matthias Krüger-319/+135
r=compiler-errors Fix `adt_const_params` leaking `{type error}` in error msg Fixes the confusing diagnostic described in #118179. (users would see `{type error}` in some situations, which is pretty weird) `adt_const_params` tracking issue: #95174
2024-09-30Rollup merge of #131035 - dingxiangfei2009:tweak-if-let-rescope-lint, r=jieyouxuMatthias Krüger-5/+117
Preserve brackets around if-lets and skip while-lets r? `@jieyouxu` Tracked by #124085 Fresh out of #129466, we have discovered 9 crates that the lint did not successfully migrate because the span of `if let` includes the surrounding brackets `(..)` like the following, which surprised me a bit. ```rust if (if let .. { .. } else { .. }) { // ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // the span somehow includes the surrounding brackets } ``` There is one crate that failed the migration because some suggestion spans cross the macro expansion boundaries. Surely there is no way to patch them with `match` rewrite. To handle this case, we will instead require all spans to be tested for admissibility as suggestion spans. Besides, there are 4 false negative cases discovered with desugared-`while let`. We don't need to lint them, because the `else` branch surely contains exactly one statement because the drop order is not changed whatsoever in this case. ```rust while let Some(value) = droppy().get() { .. } // is desugared into loop { if let Some(value) = droppy().get() { .. } else { break; // here can be nothing observable in this block } } ``` I believe this is the one and only false positive that I have found. I think we have finally nailed all the corner cases this time.
2024-09-30apply suggestionsDing Xiang Fei-7/+73
2024-09-30Rollup merge of #131057 - Urgau:cfg-erronous-unsafe, r=jieyouxuMatthias Krüger-3/+31
Reject leading unsafe in `cfg!(...)` and `--check-cfg` This PR reject leading unsafe in `cfg!(...)` and `--check-cfg`. Fixes (after-backport) https://github.com/rust-lang/rust/issues/131055 r? `@jieyouxu`
2024-09-30Rollup merge of #130895 - RalfJung:asm-tests, r=nnethercoteMatthias Krüger-96/+22
make type-check-4 asm tests about non-const expressions These tests recently got changed in https://github.com/rust-lang/rust/pull/129759. I asked the PR author to make the tests read from a `static mut` (rather than just making them "pass"), but I now think that was a mistake: previously the tests failed because the const was not a valid const expression, after the PR they failed because the const failed to evaluate. So this PR restores the tests to "fail because the const is not a valid const expression". That can be done in a target-independent way so I unified the x86 and aarch64 tests into one. Cc `@oli-obk` as the original [author](https://github.com/rust-lang/rust/commit/0d88631059742db30c44edadd1c8a2f51c8eb971) of these tests -- not sure if you still remember what they were intended to test.
2024-09-30make type-check-4 asm tests about non-const expressionsRalf Jung-96/+22
2024-09-30Reject leading unsafe in `cfg!(...)` and `--check-cfg`.Urgau-3/+31
2024-09-29fix(hir_analysis/wfcheck): don't leak {type error}Barrett Ray-319/+135
avoid `{type error}` being leaked in user-facing messages, particularly when using the `adt_const_params` feature
2024-09-30Auto merge of #129499 - fee1-dead-contrib:supereffects, r=compiler-errorsbors-53/+21
properly elaborate effects implied bounds for super traits Summary: This PR makes it so that we elaborate `<T as Tr>::Fx: EffectsCompat<somebool>` into `<T as SuperTr>::Fx: EffectsCompat<somebool>` when we know that `trait Tr: ~const SuperTr`. Some discussion at https://github.com/rust-lang/project-const-traits/issues/2. r? project-const-traits `@rust-lang/project-const-traits:` how do we feel about this approach?
2024-09-29Auto merge of #131002 - steffahn:rustdoc-long-names-fix, r=notriddlebors-14/+14
In redesigned rustdoc toolbar: Adjust spacings and sizing to improve behavior with over-long names Fixes #130993. Some additional adjustments also fix more issues I’ve noticed such as: * on small screens, opening search made the 3 bottons move down very slightly (because the row with the crate picker got larger, enlarging the whole grid), this is fixed with a `min-height: 60px` on the toolbar * with long names in the “breadcrumps” area, wrapping was very broken * ![Screenshot_20240929_031831](https://github.com/user-attachments/assets/6f46bbb7-004b-4606-bf17-8a6f3289a8f7) * fixed: * ![Screenshot_20240929_035312](https://github.com/user-attachments/assets/4e2f8dd2-043e-4279-b588-0a72c7533f8e) * the left grid area has a minimal width (105px); like before, that leaves about enough space for crate names becoming as short as “all cra…”; to save even more space, there’s support for a little bit of extra squeezing of the buttons * ![Screenshot_20240929_034511](https://github.com/user-attachments/assets/7c6788ee-8ec1-4a38-b341-8d67704f5575) * ![Screenshot_20240929_034525](https://github.com/user-attachments/assets/e141756d-37a9-4205-bc4d-235ddd1c0609) * ![Screenshot_20240929_034535](https://github.com/user-attachments/assets/526447f3-48b6-47aa-8a60-e5b0d4d055f0) I’m really not super good with HTML or CSS stuff at all; there seem to be many magical numbers already, I’ve just used `px` values until things look right, I hope that’s okay 🤷‍♂️ r? `@GuillaumeGomez` cc `@notriddle`
2024-09-30preserve brackets around if-lets and skip while-letsDing Xiang Fei-3/+49
2024-09-29Rollup merge of #130990 - RalfJung:mir-const-normalize, r=compiler-errorsMatthias Krüger-11/+4
try to get rid of mir::Const::normalize It was easy to make this compile, let's see if anything breaks... r? `@compiler-errors`
2024-09-29rustdoc-gui: fix test casesMichael Howell-14/+14
2024-09-29Auto merge of #131022 - matthiaskrgr:rollup-g9y1v11, r=matthiaskrgrbors-56/+120
Rollup of 5 pull requests Successful merges: - #130931 (Rename `standalone` doctest attribute into `standalone_crate`) - #131000 (Weekly `cargo update`) - #131011 (cleanup: don't `.into()` identical types) - #131013 (cleanup: don't manually `unwrap_or_default()`) - #131014 (cleanup: don't clone types that are Copy) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-29Rollup merge of #130931 - GuillaumeGomez:standalone-crate, r=notriddleMatthias Krüger-56/+120
Rename `standalone` doctest attribute into `standalone_crate` Following [zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/Renaming.20code.20block.20.22standalone.22.20attribute.3F) and poll results. r? `@notriddle`
2024-09-29Auto merge of #130975 - matthiaskrgr:nice_ice_shall_suffice, r=jieyouxubors-0/+89
crashes: more tests r? `@jieyouxu`
2024-09-29Rename doctest attribute `standalone-crate` into `standalone_crate` for ↵Guillaume Gomez-9/+9
coherency
2024-09-29crashes: more testsMatthias Krüger-0/+89
2024-09-29Auto merge of #130983 - GuillaumeGomez:wait-for-false, r=notriddlebors-12/+6
Update `browser-ui-test` version and make use of `wait-for*-false` commands I added `wait-for*-false` commands, making possible these changes. r? `@notriddle`
2024-09-29adjust testRalf Jung-11/+4
2024-09-29Auto merge of #129687 - Urgau:rfc3127-sysroot-2, r=jieyouxubors-0/+58
Implement RFC3137 trim-paths sysroot changes - take 2 This PR is a continuation of https://github.com/rust-lang/rust/pull/118149. Nothing really changed, except for https://github.com/rust-lang/rust/pull/129408 which I was able to trigger locally. Original description: > Implement parts of #111540 > > Right now, backtraces into sysroot always shows /rustc/$hash in diagnostics, e.g. > > ``` > thread 'main' panicked at 'hello world', map-panic.rs:2:50 > stack backtrace: > 0: std::panicking::begin_panic > at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:616:12 > 1: map_panic::main::{{closure}} > at ./map-panic.rs:2:50 > 2: core::option::Option<T>::map > at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/option.rs:929:29 > 3: map_panic::main > at ./map-panic.rs:2:30 > 4: core::ops::function::FnOnce::call_once > at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/ops/function.rs:248:5 > note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. > ``` > > [RFC 3127 said](https://rust-lang.github.io/rfcs/3127-trim-paths.html#changing-handling-of-sysroot-path-in-rustc) > > > We want to change this behaviour such that, when rust-src source files can be discovered, the virtual path is discarded and therefore the local path will be embedded, unless there is a --remap-path-prefix that causes this local path to be remapped in the usual way. > > This PR implements this behaviour. When `rust-src` is present at compile time, rustc replaces /rustc/$hash with a real path into local rust-src with best effort. To sanitise this, users must explicitly supply `--remap-path-prefix=<path to rust-src>=foo`. cc `@cbeuw` Fix #105907 Fix #85463 try-job: dist-x86_64-linux try-job: x86_64-msvc try-job: dist-x86_64-msvc try-job: armhf-gnu
2024-09-28Auto merge of #123778 - jhorstmann:optimize-upper-lower-auto-vectorization, ↵bors-0/+23
r=the8472 Improve autovectorization of to_lowercase / to_uppercase functions Refactor the code in the `convert_while_ascii` helper function to make it more suitable for auto-vectorization and also process the full ascii prefix of the string. The generic case conversion logic will only be invoked starting from the first non-ascii character. The runtime on a microbenchmark with a small ascii-only input decreases from ~55ns to ~18ns per iteration. The new implementation also reduces the amount of unsafe code and encapsulates all unsafe inside the helper function. Fixes #123712
2024-09-28remap-path-prefix-sysroot: remap {{src-base}} as wellUrgau-1/+2
This is done to cover the path of the test it-self as it may not live on the same root directory as {{rust-src-base}}, which can be the case if {{rust-src-base}} is coming from a extracted dist build (cc opt-dist)
2024-09-28Improve mistyped docblock attribute warning messagesGuillaume Gomez-58/+58
2024-09-28Add regression tests for mistyped `standalone-crate` attributeGuillaume Gomez-0/+64
2024-09-28Rename `standalone` doctest attribute into `standalone-crate`Guillaume Gomez-2/+2
2024-09-28Make use of `wait-for*-false` commandsGuillaume Gomez-12/+6
2024-09-28Rollup merge of #130960 - cuviper:cdylib-soname, r=petrochenkovMatthias Krüger-6/+10
Only add an automatic SONAME for Rust dylibs #126094 added an automatic relative `SONAME` to all dynamic libraries, but it was really only needed for Rust `--crate-type="dylib"`. In Fedora, it was a surprise to see `SONAME` on `"cdylib"` libraries like Python modules, especially because that generates an undesirable RPM `Provides`. We can instead add a `SONAME` just for Rust dylibs by passing the crate-type argument farther. Ref: https://bugzilla.redhat.com/show_bug.cgi?id=2314879
2024-09-28Rollup merge of #130953 - workingjubilee:rename-a-few-ctypes-tests, r=fee1-deadMatthias Krüger-11/+20
Rename a few tests to make tidy happier A somewhat random smattering of tests that I have recently looked at, and thus had cause to research and write down the reason for their existence.
2024-09-28Rollup merge of #130944 - lukas-code:ptr-ptr-sub, r=compiler-errorsMatthias Krüger-6/+64
Allow instantiating trait object binder in ptr-to-ptr casts For unsizing coercions between trait objects with the same principal, we already allow instantiating the for binder. For example, coercing `Box<dyn for<'a> Trait<'a>` to `Box<dyn Trait<'static>>` is allowed. Since ptr-to-ptr casts will insert an unsizing coercion before the cast if possible, this has the consequence that the following compiles already: ```rust // This compiles today. fn cast<'b>(x: *mut dyn for<'a> Trait<'a>) -> *mut dyn Trait<'b> { // lowered as (roughly) // tmp: *mut dyn Trait<'?0> = Unsize(x) // requires dyn for<'a> Trait<'a> <: dyn Trait<'?0> // ret: *mut dyn Trait<'b> = PtrToPtr(tmp) // requires dyn Trait<'?0> == dyn Trait<'b> x as _ } ``` However, if no unsizing coercion is inserted then this currently fails to compile as one type is more general than the other. This PR will allow this code to compile, too, by changing ptr-to-ptr casts of pointers with vtable metadata to use sutyping instead of type equality. ```rust // This will compile after this PR. fn cast<'b>(x: *mut dyn for<'a> Trait<'a>) -> *mut Wrapper<dyn Trait<'b>> { // lowered as (roughly) // no Unsize here! // ret: *mut Wrapper<dyn Trait<'b>> = PtrToPtr(x) // requires dyn for<'a> Trait<'a> == dyn Trait<'b> x as _ } ``` Note that it is already possible to work around the current restrictions and make the code compile before this PR by splitting the cast in two, so this shouldn't allow a new class of programs to compile: ```rust // Workaround that compiles today. fn cast<'b>(x: *mut dyn for<'a> Trait<'a>) -> *mut Wrapper<dyn Trait<'b>> { x as *mut dyn Trait<'_> as _ } ``` r? `@compiler-errors` cc `@WaffleLapkin`
2024-09-28Rollup merge of #130924 - surechen:fix_130851, r=compiler-errorsMatthias Krüger-0/+73
Make clashing_extern_declarations considering generic args for ADT field In following example, G<u16> should be recognized as different from G<u32> : ```rust #[repr(C)] pub struct G<T> { g: [T; 4] } pub mod x { extern "C" { pub fn g(_: super::G<u16>); } } pub mod y { extern "C" { pub fn g(_: super::G<u32>); } } ``` fixes #130851
2024-09-28Rollup merge of #130866 - compiler-errors:dyn-instantiate-binder, r=lcnrMatthias Krüger-44/+63
Allow instantiating object trait binder when upcasting This PR fixes two bugs (that probably need an FCP). ### We use equality rather than subtyping for upcasting dyn conversions This code should be valid: ```rust #![feature(trait_upcasting)] trait Foo: for<'h> Bar<'h> {} trait Bar<'a> {} fn foo(x: &dyn Foo) { let y: &dyn Bar<'static> = x; } ``` But instead: ``` error[E0308]: mismatched types --> src/lib.rs:7:32 | 7 | let y: &dyn Bar<'static> = x; | ^ one type is more general than the other | = note: expected existential trait ref `for<'h> Bar<'h>` found existential trait ref `Bar<'_>` ``` And so should this: ```rust #![feature(trait_upcasting)] fn foo(x: &dyn for<'h> Fn(&'h ())) { let y: &dyn FnOnce(&'static ()) = x; } ``` But instead: ``` error[E0308]: mismatched types --> src/lib.rs:4:39 | 4 | let y: &dyn FnOnce(&'static ()) = x; | ^ one type is more general than the other | = note: expected existential trait ref `for<'h> FnOnce<(&'h (),)>` found existential trait ref `FnOnce<(&(),)>` ``` Specifically, both of these fail because we use *equality* when comparing the supertrait to the *target* of the unsize goal. For the first example, since our supertrait is `for<'h> Bar<'h>` but our target is `Bar<'static>`, there's a higher-ranked type mismatch even though we *should* be able to instantiate that supertrait binder when upcasting. Similarly for the second example. ### New solver uses equality rather than subtyping for no-op (i.e. non-upcasting) dyn conversions This code should be valid in the new solver, like it is with the old solver: ```rust // -Znext-solver fn foo<'a>(x: &mut for<'h> dyn Fn(&'h ())) { let _: &mut dyn Fn(&'a ()) = x; } ``` But instead: ``` error: lifetime may not live long enough --> <source>:2:11 | 1 | fn foo<'a>(x: &mut dyn for<'h> Fn(&'h ())) { | -- lifetime `'a` defined here 2 | let _: &mut dyn Fn(&'a ()) = x; | ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` | = note: requirement occurs because of a mutable reference to `dyn Fn(&())` ``` Specifically, this fails because we try to coerce `&mut dyn for<'h> Fn(&'h ())` to `&mut dyn Fn(&'a ())`, which registers an `dyn for<'h> Fn(&'h ()): dyn Fn(&'a ())` goal. This fails because the new solver uses *equating* rather than *subtyping* in `Unsize` goals. This is *mostly* not a problem... You may wonder why the same code passes on the new solver for immutable references: ``` // -Znext-solver fn foo<'a>(x: &dyn Fn(&())) { let _: &dyn Fn(&'a ()) = x; // works } ``` That's because in this case, we first try to coerce via `Unsize`, but due to the leak check the goal fails. Then, later in coercion, we fall back to a simple subtyping operation, which *does* work. Since `&T` is covariant over `T`, but `&mut T` is invariant, that's where the discrepancy between these two examples crops up. --- r? lcnr or reassign :D
2024-09-28rustc_target: Add RISC-V atomic-related featuresTaiki Endo-2/+2