about summary refs log tree commit diff
path: root/tests
AgeCommit message (Collapse)AuthorLines
2024-09-17Auto merge of #129970 - lukas-code:LayoutCalculator, r=compiler-errorsbors-47/+149
layout computation: gracefully handle unsized types in unexpected locations This PR reworks the layout computation to eagerly return an error when encountering an unsized field where a sized field was expected, rather than delaying a bug and attempting to recover a layout. This is required, because with trivially false where clauses like `[T]: Sized`, any field can possible be an unsized type, without causing a compile error. Since this PR removes the `delayed_bug` method from the `LayoutCalculator` trait, it essentially becomes the same as the `HasDataLayout` trait, so I've also refactored the `LayoutCalculator` to be a simple wrapper struct around a type that implements `HasDataLayout`. The majority of the diff is whitespace changes, so viewing with whitespace ignored is advised. implements https://github.com/rust-lang/rust/pull/123169#issuecomment-2025788480 r? `@compiler-errors` or compiler fixes https://github.com/rust-lang/rust/issues/123134 fixes https://github.com/rust-lang/rust/issues/124182 fixes https://github.com/rust-lang/rust/issues/126939 fixes https://github.com/rust-lang/rust/issues/127737
2024-09-17get rid of an old hackLukas Markeffsky-13/+45
For structs that cannot be unsized, the layout algorithm sometimes moves unsized fields to the end of the struct, which circumvented the error for unexpected unsized fields and returned an unsized layout anyway. This commit makes it so that the unexpected unsized error is always returned for structs that cannot be unsized, allowing us to remove an old hack and fixing some old ICE.
2024-09-16Auto merge of #130444 - matthiaskrgr:rollup-onlrjva, r=matthiaskrgrbors-27/+96
Rollup of 3 pull requests Successful merges: - #130033 (Don't call `fn_arg_names` query for non-`fn` foreign items in resolver) - #130282 (Do not report an excessive number of overflow errors for an ever-growing deref impl) - #130437 (Avoid crashing on variadic functions when producing arg-mismatch errors) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-16Rollup merge of #130437 - jder:issue-130372, r=compiler-errorsMatthias Krüger-27/+31
Avoid crashing on variadic functions when producing arg-mismatch errors Fixes #130372 by accommodating how variadic functions change the argument list length between HIR body and FnDecls. Also degrades the zip_eq to a debug_assert! to match other asserts in the area to avoid being disruptive to users. There is at least one other crash in this area I am working on in #130400 and also considering how we might refactor some of this code to hoist some of this logic up higher. r? `@compiler-errors`
2024-09-16Rollup merge of #130282 - compiler-errors:over-overflow, r=BoxyUwUMatthias Krüger-0/+37
Do not report an excessive number of overflow errors for an ever-growing deref impl Check that we don't first hit the recursion limit in `get_field_candidates_considering_privacy` before probing for methods when we have a method lookup failure and we want to see if `.field.method()` exists. We also silence overflow error messages if we're probing for methods for diagnostics. Also renames some functions to make it clearer that they're only for diagnostics, and sprinkle some `Autoderef::silence_errors` around to silence unnecessary overflow errors that come from diagnostics. Fixes #130224.
2024-09-16Rollup merge of #130033 - compiler-errors:foreign-fn-types, r=BoxyUwUMatthias Krüger-0/+28
Don't call `fn_arg_names` query for non-`fn` foreign items in resolver Fixes #130015
2024-09-16Avoid crashing on variadic functions when producing arg-mismatch errorsJesse Rusak-27/+31
2024-09-16Auto merge of #130439 - matthiaskrgr:rollup-1lkzo74, r=matthiaskrgrbors-10/+84
Rollup of 4 pull requests Successful merges: - #123436 (linker: Allow MSVC to use import libraries following the Meson/MinGW convention) - #130410 (Don't ICE when generating `Fn` shim for async closure with borrowck error) - #130412 (Don't ICE when RPITIT captures more method args than trait definition) - #130436 (Ignore reduce-fadd-unordered on SGX platform) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-16Rollup merge of #130436 - fortanix:raoul/fix_reduce_add_unordered_test, ↵Matthias Krüger-0/+1
r=RalfJung Ignore reduce-fadd-unordered on SGX platform #130325 added the `tests/assembly/simd/reduce-fadd-unordered.rs` test. Unfortunately, the use of `CHECK: ret` makes that this test is not compatible with LVI mitigations applied for the SGX target. This PR makes sure this test is ignored for the SGX target, until a nicer solution is available.
2024-09-16Rollup merge of #130412 - compiler-errors:rpitit-overcapture, r=jieyouxuMatthias Krüger-9/+58
Don't ICE when RPITIT captures more method args than trait definition Make sure we don't ICE when an RPITIT captures more method args than the trait definition, which is not allowed. This was because we were using the wrong def id for error reporting. Due to the default lifetime capture rules of RPITITs (capturing everything in scope), this is only doable if we use precise capturing, which isn't currently allowed for RPITITs anyways but we still end up reaching the relevant codepaths. Fixes #129850
2024-09-16Don't ICE when generating Fn shim for async closure with borrowck errorMichael Goulet-1/+25
2024-09-16Don't ICE when RPITIT captures more method args than trait definitionMichael Goulet-9/+58
2024-09-16Introduce distinct error codes for precise capturingMichael Goulet-5/+31
2024-09-16Do precise capturing arg validation in resolveMichael Goulet-18/+22
2024-09-16Ignore reduce-fadd-unordered on SGX platformRaoul Strackx-0/+1
2024-09-16layout computation: eagerly error for unexpected unsized fieldsLukas Markeffsky-38/+108
2024-09-16Auto merge of #129716 - compiler-errors:closure-debuginfo, r=cjgillotbors-0/+19
Don't use `typeck_root_def_id` in codegen for finding closure's root Generating debuginfo in codegen currently peels off all the closure-specific generics (which presumably is done because they're redundant). This doesn't currently work correctly for the bodies we synthesize for async closures's returned coroutines (#128506), leading to #129702. Specifically, `typeck_root_def_id` for some `DefKind::SyntheticCoroutineBody` just returns itself (because it loops while `is_typeck_child` is `true`, and that returns `false` for this defkind), which means we don't end up peeling off the coroutine-specific generics, and we end up encountering an otherwise unreachable `CoroutineWitness` type leading to an ICE. This PR fixes `is_typeck_child` to consider `DefKind::SyntheticCorotuineBody` to be a typeck child, fixing `typeck_root_def_id` and suppressing this debuginfo bug. Fixes #129702
2024-09-15Rollup merge of #130325 - workingjubilee:plus-minus-zero-redux, ↵Jubilee-0/+29
r=RalfJung,jieyouxu Use -0.0 in `intrinsics::simd::reduce_add_unordered` -0.0 is the actual neutral additive float, not +0.0, and this matters to codegen. try-job: aarch64-gnu
2024-09-16Auto merge of #130220 - RalfJung:float-classify, r=workingjubileebors-27/+75
simplify float::classify logic I played around with the float-classify test in the hope of triggering x87 bugs by strategically adding `black_box`, and still the exact expression `@beetrees` suggested [here](https://github.com/rust-lang/rust/pull/129835#issuecomment-2325661597) remains the only case I found where we get the wrong result on x87. Curiously, this bug only occurs when MIR optimizations are enabled -- probably the extra inlining that does is required for LLVM to hit the right "bad" case in the backend. But even for that case, it makes no difference whether `classify` is implemented in the simple bit-pattern-based version or the more complicated version we had before. Without even a single testcase that can distinguish our `classify` from the naive version, I suggest we switch to the naive version.
2024-09-15Use -0.0 in `intrinsics::simd::reduce_add_unordered`Jubilee Young-0/+29
-0.0 is the actual neutral additive float, not +0.0, and this matters to codegen.
2024-09-15Rollup merge of #130409 - matthiaskrgr:ccccrashes, r=compiler-errorsMatthias Krüger-0/+93
tests: more ice tests r? `@jieyouxu`
2024-09-15const: don't ICE when encountering a mutable ref to immutable memoryRalf Jung-29/+35
2024-09-15tests: more ice testsMatthias Krüger-0/+93
2024-09-15Rollup merge of #130342 - RalfJung:slice-idx-overflow, r=saethlinMatthias Krüger-0/+22
interpret, miri: fix dealing with overflow during slice indexing and allocation This is mostly to fix https://github.com/rust-lang/rust/issues/130284. I then realized we're using somewhat sketchy arguments for a similar multiplication in `copy`/`copy_nonoverlapping`/`write_bytes`, so I made them all share the same function that checks exactly the right thing. (The intrinsics would previously fail on allocations larger than `1 << 47` bytes... which are theoretically possible maybe? Anyway it seems conceptually wrong to use any other bound than `isize::MAX` here.)
2024-09-15Rollup merge of #130293 - gurry:130142-lint-level-issue, r=cjgillotMatthias Krüger-3/+58
Fix lint levels not getting overridden by attrs on `Stmt` nodes Fixes #130142. See comments on the issue for context. r? `@cjgillot`
2024-09-15Rollup merge of #130371 - saethlin:transmutability-enum-ice, r=compiler-errorsMatthias Krüger-22/+9
Correctly account for niche-optimized tags in rustc_transmute This is a bit hacky, but it fixes the ICE and makes it possible to run the safe transmute check on every `mem::transmute` check we instantiate. I want to write a lint that needs to do that, but this stands well on its own. cc `@jswrenn` here's the fix I alluded to yesterday :) Fixes #123693
2024-09-15Rollup merge of #129195 - RalfJung:const-mut-refs, r=fee1-deadMatthias Krüger-1261/+309
Stabilize `&mut` (and `*mut`) as well as `&Cell` (and `*const Cell`) in const This stabilizes `const_mut_refs` and `const_refs_to_cell`. That allows a bunch of new things in const contexts: - Mentioning `&mut` types - Creating `&mut` and `*mut` values - Creating `&T` and `*const T` values where `T` contains interior mutability - Dereferencing `&mut` and `*mut` values (both for reads and writes) The same rules as at runtime apply: mutating immutable data is UB. This includes mutation through pointers derived from shared references; the following is diagnosed with a hard error: ```rust #[allow(invalid_reference_casting)] const _: () = { let mut val = 15; let ptr = &val as *const i32 as *mut i32; unsafe { *ptr = 16; } }; ``` The main limitation that is enforced is that the final value of a const (or non-`mut` static) may not contain `&mut` values nor interior mutable `&` values. This is necessary because the memory those references point to becomes *read-only* when the constant is done computing, so (interior) mutable references to such memory would be pretty dangerous. We take a multi-layered approach here to ensuring no mutable references escape the initializer expression: - A static analysis rejects (interior) mutable references when the referee looks like it may outlive the current MIR body. - To be extra sure, this static check is complemented by a "safety net" of dynamic checks. ("Dynamic" in the sense of "running during/after const-evaluation, e.g. at runtime of this code" -- in contrast to "static" which works entirely by looking at the MIR without evaluating it.) - After the final value is computed, we do a type-driven traversal of the entire value, and if we find any `&mut` or interior-mutable `&` we error out. - However, the type-driven traversal cannot traverse `union` or raw pointers, so there is a second dynamic check where if the final value of the const contains any pointer that was not derived from a shared reference, we complain. This is currently a future-compat lint, but will become an ICE in #128543. On the off-chance that it's actually possible to trigger this lint on stable, I'd prefer if we could make it an ICE before stabilizing const_mut_refs, but it's not a hard blocker. This part of the "safety net" is only active for mutable references since with shared references, it has false positives. Altogether this should prevent people from leaking (interior) mutable references out of the const initializer. While updating the tests I learned that surprisingly, this code gets rejected: ```rust const _: Vec<i32> = { let mut x = Vec::<i32>::new(); //~ ERROR destructor of `Vec<i32>` cannot be evaluated at compile-time let r = &mut x; let y = x; y }; ``` The analysis that rejects destructors in `const` is very conservative when it sees an `&mut` being created to `x`, and then considers `x` to be always live. See [here](https://github.com/rust-lang/rust/issues/65394#issuecomment-541499219) for a longer explanation. `const_precise_live_drops` will solve this, so I consider this problem to be tracked by https://github.com/rust-lang/rust/issues/73255. Cc `@rust-lang/wg-const-eval` `@rust-lang/lang` Cc https://github.com/rust-lang/rust/issues/57349 Cc https://github.com/rust-lang/rust/issues/80384
2024-09-15also stabilize const_refs_to_cellRalf Jung-232/+104
2024-09-15const_refs_to_cell: dont let mutable references sneak past the interior ↵Ralf Jung-9/+46
mutability check
2024-09-15stabilize const_mut_refsRalf Jung-1100/+239
2024-09-15Rollup merge of #130061 - theemathas:box_vec_non_null, ↵Stuart Cook-4/+4
r=MarkSimulacrum,workingjubilee Add `NonNull` convenience methods to `Box` and `Vec` Implements the ACP: https://github.com/rust-lang/libs-team/issues/418. The docs for the added methods are mostly copied from the existing methods that use raw pointers instead of `NonNull`. I'm new to this "contributing to rustc" thing, so I'm sorry if I did something wrong. In particular, I don't know what the process is for creating a new unstable feature. Please advise me if I should do something. Thank you.
2024-09-14Auto merge of #129753 - folkertdev:stabilize-const-extern-fn, r=RalfJungbors-89/+67
stabilize `const_extern_fn` closes https://github.com/rust-lang/rust/issues/64926 tracking issue: https://github.com/rust-lang/rust/issues/64926 reference PR: https://github.com/rust-lang/reference/pull/1596 ## Stabilizaton Report ### Summary Using `const extern "Rust"` and `const extern "C"` was already stabilized (since version 1.62.0, see https://github.com/rust-lang/rust/pull/95346). This PR stabilizes the other calling conventions: it is now possible to write `const unsafe extern "calling-convention" fn` and `const extern "calling-convention" fn` for any supported calling convention: ```rust const extern "C-unwind" fn foo1(val: u8) -> u8 { val + 1} const extern "stdcall" fn foo2(val: u8) -> u8 { val + 1} const unsafe extern "C-unwind" fn bar1(val: bool) -> bool { !val } const unsafe extern "stdcall" fn bar2(val: bool) -> bool { !val } ``` This can be used to const-ify an `extern fn`, or conversely, to make a `const fn` callable from external code. r? T-lang cc `@RalfJung`
2024-09-14Correctly account for niche-optimized tagsBen Kimock-23/+1
2024-09-14Add a testBen Kimock-0/+9
2024-09-14Auto merge of #128543 - RalfJung:const-interior-mut, r=fee1-deadbors-472/+93
const-eval interning: accept interior mutable pointers in final value …but keep rejecting mutable references This fixes https://github.com/rust-lang/rust/issues/121610 by no longer firing the lint when there is a pointer with interior mutability in the final value of the constant. On stable, such pointers can be created with code like: ```rust pub enum JsValue { Undefined, Object(Cell<bool>), } impl Drop for JsValue { fn drop(&mut self) {} } // This does *not* get promoted since `JsValue` has a destructor. // However, the outer scope rule applies, still giving this 'static lifetime. const UNDEFINED: &JsValue = &JsValue::Undefined; ``` It's not great to accept such values since people *might* think that it is legal to mutate them with unsafe code. (This is related to how "infectious" `UnsafeCell` is, which is a [wide open question](https://github.com/rust-lang/unsafe-code-guidelines/issues/236).) However, we [explicitly document](https://doc.rust-lang.org/reference/behavior-considered-undefined.html) that things created by `const` are immutable. Furthermore, we also accept the following even more questionable code without any lint today: ```rust let x: &'static Option<Cell<i32>> = &None; ``` This is even more questionable since it does *not* involve a `const`, and yet still puts the data into immutable memory. We could view this as promotion [potentially introducing UB](https://github.com/rust-lang/unsafe-code-guidelines/issues/493). However, we've accepted this since ~forever and it's [too late to reject this now](https://github.com/rust-lang/rust/pull/122789); the pattern is just too useful. So basically, if you think that `UnsafeCell` should be tracked fully precisely, then you should want the lint we currently emit to be removed, which this PR does. If you think `UnsafeCell` should "infect" surrounding `enum`s, the big problem is really https://github.com/rust-lang/unsafe-code-guidelines/issues/493 which does not trigger the lint -- the cases the lint triggers on are actually the "harmless" ones as there is an explicit surrounding `const` explaining why things end up being immutable. What all this goes to show is that the hard error added in https://github.com/rust-lang/rust/pull/118324 (later turned into the future-compat lint that I am now suggesting we remove) was based on some wrong assumptions, at least insofar as it concerns shared references. Furthermore, that lint does not help at all for the most problematic case here where the potential UB is completely implicit. (In fact, the lint is actively in the way of [my preferred long-term strategy](https://github.com/rust-lang/unsafe-code-guidelines/issues/493#issuecomment-2028674105) for dealing with this UB.) So I think we should go back to square one and remove that error/lint for shared references. For mutable references, it does seem to work as intended, so we can keep it. Here it serves as a safety net in case the static checks that try to contain mutable references to the inside of a const initializer are not working as intended; I therefore made the check ICE to encourage users to tell us if that safety net is triggered. Closes https://github.com/rust-lang/rust/issues/122153 by removing the lint. Cc `@rust-lang/opsem` `@rust-lang/lang`
2024-09-14Consider synthetic closure bodies to be typeck childrenMichael Goulet-0/+19
2024-09-14Auto merge of #130357 - fmease:rollup-j3ej4q0, r=fmeasebors-413/+298
Rollup of 6 pull requests Successful merges: - #130017 (coverage: Extract `executor::block_on` from several async coverage tests) - #130268 (simd_shuffle: require index argument to be a vector) - #130290 (Stabilize entry_insert) - #130294 (Lifetime cleanups) - #130343 (docs: Enable required feature for 'closure_returning_async_block' lint) - #130349 (Fix `Parser::break_up_float`'s right span) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-14Rollup merge of #130349 - ShE3py:break_up_float, r=fmeaseLeón Orell Valerian Liehr-24/+24
Fix `Parser::break_up_float`'s right span ```rs use std::mem::offset_of; fn main() { offset_of!((u8,), 0.0); } ``` Before: ``` error[E0609]: no field `0` on type `u8` --> ./main.rs:4:25 | 4 | offset_of!((u8,), 0.0); | _____--------------------^- | | | | | in this macro invocation 5 | | } ... | | = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error ``` After: ``` error[E0609]: no field `0` on type `u8` --> ./main.rs:4:25 | 4 | offset_of!((u8,), 0.0); | ^ error: aborting due to 1 previous error ``` --- `@rustbot` label +A-parser +D-imprecise-spans
2024-09-14Rollup merge of #130268 - RalfJung:simd-shuffle-idx-vector, r=compiler-errorsLeón Orell Valerian Liehr-112/+132
simd_shuffle: require index argument to be a vector Remove some codegen hacks by forcing the SIMD shuffle `index` argument to be a vector, which means (thanks to https://github.com/rust-lang/rust/pull/128537) that it will automatically be passed as an immediate in LLVM. The only special-casing we still have is for the extra sanity-checks we add that ensure that the indices are all in-bounds. (And the GCC backend needs to do a bunch of work since the Rust intrinsic is modeled after what LLVM expects, which seems to be quite different from what GCC expects.) Fixes https://github.com/rust-lang/rust/issues/128738, see that issue for more context.
2024-09-14Rollup merge of #130017 - Zalathar:executor, r=Mark-SimulacrumLeón Orell Valerian Liehr-277/+142
coverage: Extract `executor::block_on` from several async coverage tests By moving `block_on` to an auxiliary crate, we avoid having to keep a separate copy of it in every async test.
2024-09-14stabilize `const_extern_fn`Folkert de Vries-89/+67
2024-09-14Auto merge of #128299 - DianQK:clone-copy, r=cjgillotbors-52/+1551
Simplify the canonical clone method and the copy-like forms to copy Fixes #128081. The optimized clone method ends up as the following MIR: ``` _2 = copy ((*_1).0: i32); _3 = copy ((*_1).1: u64); _4 = copy ((*_1).2: [i8; 3]); _0 = Foo { a: move _2, b: move _3, c: move _4 }; ``` We can transform this to: ``` _0 = copy (*_1); ``` r? `@cjgillot`
2024-09-14simd_shuffle: require index argument to be a vectorRalf Jung-112/+132
2024-09-14Fix lint levels not getting overridden by attrs on `Stmt` nodesGurinder Singh-3/+58
2024-09-14Fix `Parser::break_up_float`'s right spanLieselotte-24/+24
2024-09-14Rollup merge of #130311 - heiseish:issue-70849-fix, r=fmeaseStuart Cook-0/+23
(fix) conflicting negative impl marker ## Context This MR fixes the error message for conflicting negative trait impls by adding the corresponding the polarity marker to the trait name. ## Issues - closes #70849 r​? `@fmease`
2024-09-14Rollup merge of #130267 - TimNN:patch-2, r=nikicStuart Cook-2/+2
small_data_threshold.rs: Adapt to LLVM head changes When compiled against LLVM head, `small_data_threshold.rs` [fails with](https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/31051#0191e508-f11d-437b-a4a0-5e18247debc9): ``` /.../small_data_threshold.rs:61:12: error: RISCV: expected string not found in input --   | //@ RISCV: .section .sdata,   | ^   | /.../small_data_threshold.s:1:1: note: scanning from here   | .text   | ^   | /.../small_data_threshold.s:6:2: note: possible intended match here   | .section .sdata.U,"aw",`@progbits`   | ^ ``` I don't know how exactly the current output looks like, or if there was a specific reason for including the trailing comma on the first line. I only saw a failure for RISCV, but it seemed sensible to adjust MIPS as well. CI passes with this patch applied: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/31053 `@rustbot` label: +llvm-main cc `@paulmenage`
2024-09-14interpret: fix dealing with overflow during slice indexingRalf Jung-0/+22
2024-09-14Auto merge of #128991 - Nadrieril:rustfix-unreachable-pattern, r=compiler-errorsbors-93/+469
Add a machine-applicable suggestion to "unreachable pattern"
2024-09-14Update try_question_mark_nop.rs testDianQK-1/+6