about summary refs log tree commit diff
path: root/tests
AgeCommit message (Collapse)AuthorLines
2025-03-16Auto merge of #137278 - heiseish:101210-extra-codegen-tests, r=scottmcmbors-20/+121
added some new test to check for result and options opt Apologies for the delay. Finally have some time to get back into contributing. ## Context - Added some tests to show optimization on result and options for 64 and 128 bits - Relevant issue https://github.com/rust-lang/rust/issues/101210 ## Some newb questions from me - [x] My local llvm IR has `nuw` in `result_nop_match_128` etc whereas [godbolt version](https://rust.godbolt.org/z/Td9zoT5zn) doesn't have. So I put optional there, but not sure if it's desirable (maybe I'm not using the compiled llvm in the repo). I ran the test with ```bash ./x test tests/codegen/try_question_mark_nop.rs ``` - [x] Unless I'm reading it wrongly, but `option_nop_match_128` and `option_nop_traits_128` look to be **not** optimized away? Update: Here's the test for future reference ```rust // CHECK-LABEL: `@option_nop_match_128` #[no_mangle] pub fn option_nop_match_128(x: Option<i128>) -> Option<i128> { // CHECK: start: // CHECK-NEXT: %trunc = trunc nuw i128 %0 to i1 // CHECK-NEXT: br i1 %trunc, label %bb3, label %bb4 // CHECK: bb3: // CHECK-NEXT: %2 = getelementptr inbounds {{(nuw )?}}i8, ptr %_0, i64 16 // CHECK-NEXT: store i128 %1, ptr %2, align 16 // CHECK: bb4: // CHECK-NEXT: %storemerge = phi i128 [ 1, %bb3 ], [ 0, %start ] // CHECK-NEXT: store i128 %storemerge, ptr %_0, align 16 // CHECK-NEXT: ret void match x { Some(x) => Some(x), None => None, } } ``` r? `@scottmcm`
2025-03-16Rollup merge of #138484 - xizheyin:issue-138392, r=compiler-errors许杰友 Jieyou Xu (Joe)-0/+43
Use lit span when suggesting suffix lit cast Fixes #138392
2025-03-16Rollup merge of #138472 - KonaeAkira:master, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-0/+17
Add codegen test for #129795 Adds test for #129795. Min LLVM version is 20 because the optimization only happens since LLVM 20.
2025-03-16Rollup merge of #138471 - spencer3035:move-ui-test-1ofn, r=jieyouxu许杰友 Jieyou Xu (Joe)-47/+43
Clean up some tests in tests/ui I cleaned up 3 top level tests, keeping the changes minor because it is my first PR and wanted to get feedback before doing more changes/PRs. Tracking issues: https://github.com/rust-lang/rust/issues/73494 https://github.com/rust-lang/rust/issues/133895 r? jieyouxu
2025-03-16Rollup merge of #137956 - compiler-errors:rtn-rustdoc, r=fmease许杰友 Jieyou Xu (Joe)-0/+36
Add RTN support to rustdoc This adds support to rustdoc and rustdoc-json for rendering `(..)` RTN (return type notation) style generics. --- Cleaning `rustc_middle::ty::Ty` is not correct still, though, and ends up rendering a function like: ```rust pub fn foreign<T: Foreign<bar(..): Send>>() where <T as Foreign>::bar(..): 'static, T::bar(..): Sync, ``` Into this: ```rust pub fn foreign<T>() where T: Foreign, impl Future<Output = ()>: Send + 'static + Sync, ``` This is because `clean_middle_ty` doesn't actually have sufficient context about whether the RPITIT is in its "defining scope" or not, so we don't know if the type was originally written like `-> impl Trait` or with RTN like `T::method(..)`. Partially addresses #123996 (i.e., HIR side, not middle::ty one)
2025-03-15Add RTN support to rustdocMichael Goulet-0/+36
2025-03-15Don't drop Rvalue::WrapUnsafeBinder during GVNMichael Goulet-0/+94
2025-03-15improves duplicate lang item testSpencer-21/+23
2025-03-15improves duplicate label testSpencer-1/+4
2025-03-15improves outer mod attribute testSpencer-25/+16
2025-03-15Rollup merge of #138514 - compiler-errors:fake-borrow-ref-to-value, r=oli-obkMatthias Krüger-0/+163
Remove fake borrows of refs that are converted into non-refs in `MakeByMoveBody` Remove fake borrows of closure captures if that capture has been replaced with a by-move version of that capture. For example, given an async closure that looks like: ``` let f: Foo; let c = async move || { match f { ... } }; ``` ... in this pair of coroutine-closure + coroutine, we capture `Foo` in the parent and `&Foo` in the child. We will emit two fake borrows like: ``` _2 = &fake shallow (*(_1.0: &Foo)); _3 = &fake shallow (_1.0: &Foo); ``` However, since the by-move-body transform is responsible for replacing `_1.0: &Foo` with `_1.0: Foo` (since the `AsyncFnOnce` coroutine will own `Foo` by value), that makes the second fake borrow obsolete since we never have an upvar of type `&Foo`, and we should replace it with a `nop`. As a side-note, we don't actually even care about fake borrows here at all since they're fully a MIR borrowck artifact, and we don't need to borrowck by-move MIR bodies. But it's best to preserve as much as we can between these two bodies :) Fixes #138501 r? oli-obk
2025-03-15Rollup merge of #138283 - compiler-errors:enforce-const-param, r=BoxyUwUMatthias Krüger-0/+69
Enforce type of const param correctly in MIR typeck Properly intercepts and then annotates the type for a `ConstKind::Param` in the MIR. This code should probably be cleaned up, it's kinda spaghetti, but no better structure really occurred to me when writing this case. We could probably gate this behind the feature gate or add a fast path when the args have no free regions if perf is bad. r? `@BoxyUwU`
2025-03-15Auto merge of #138379 - estebank:macro-backtrace-note, r=petrochenkovbors-463/+4
Do not suggest using `-Zmacro-backtrace` for builtin macros For macros that are implemented on the compiler, or that are annotated with `rustc_diagnostic_item`, which have arbitrary implementations from the point of view of the user and might as well be intrinsics, we do *not* mention the `-Zmacro-backtrace` flag. This includes `derive`s and standard macros like `panic!` and `format!`. This PR adds a field to every `Span`'s `ExpnData` stating whether it comes from a builtin macro. This is determined by the macro being annotated with either `#[rustc_builtin_macro]` or `#[rustc_diagnostic_item]`. An alternative to using these attributes that already exist for other uses would be to introduce another attribute like `#[rustc_no_backtrace]` to have finer control on which macros are affected (for example, an error within `vec![]` now doesn't mention the backtrace, but one could make the case that it should). Ideally, instead of carrying this information in the `ExpnData` we'd instead try to query the `DefId` of the macro (that is already stored) to see if it is annotated in some way, but we do not have access to the `TyCtxt` from `rustc_errors`. r? `@petrochenkov`
2025-03-15Rollup merge of #138518 - yotamofek:pr/hir-lint-typo, r=compiler-errorsLeón Orell Valerian Liehr-12/+12
Fix typo in hir lowering lint diag
2025-03-15Rollup merge of #138482 - nnethercote:fix-hir-printing, r=compiler-errorsLeón Orell Valerian Liehr-1/+73
Fix HIR printing of parameters HIR pretty printing does the wrong thing for anonymous parameters, and there is no test coverage for it. This PR remedies both of those things. r? ``@lcnr``
2025-03-15Rollup merge of #138460 - xizheyin:issue-138319, r=petrochenkovLeón Orell Valerian Liehr-0/+71
Pass struct field HirId when check_expr_struct_fields Fixes #138319 r? compiler cc ``@Mark-Simulacrum``
2025-03-15Rollup merge of #138056 - heiher:loong64v1.1-features, r=petrochenkovLeón Orell Valerian Liehr-16/+23
rustc_target: Add target features for LoongArch v1.1 This patch adds new target features for LoongArch v1.1: * div32 * lam-bh * lamcas * ld-seq-sa * scq
2025-03-14Fix typo in hir lowering lint diagYotam Ofek-12/+12
2025-03-14Do not suggest using `-Zmacro-backtrace` for builtin macrosEsteban Küber-463/+4
For macros that are implemented on the compiler, we do *not* mention the `-Zmacro-backtrace` flag. This includes `derive`s and standard macros.
2025-03-14Remove fake borrows of refs that are converted into non-refs in MakeByMoveBodyMichael Goulet-0/+163
2025-03-14Rollup merge of #137619 - Pyr0de:issue_137249, r=fmeaseLeón Orell Valerian Liehr-0/+19
Provide helpful diagnostics for shebang lookalikes When `[` is not found after a `#!`, a note will be added to the exisiting error ``` error: expected `[`, found `/` --> src/main.rs:2:3 | 2 | #!/usr/bin/env -S cargo +nightly -Zscript | ^ expected `[` | = note: the token sequence `#!` here looks like the start of a shebang interpreter directive but it is not = help: if you meant this to be a shebang interpreter directive, move it to the very start of the file ``` Fixes #137249 r? `@fmease`
2025-03-14Rollup merge of #134720 - malezjaa:feat/crate-type-valid-values, r=jieyouxuLeón Orell Valerian Liehr-6/+12
Display valid crate types in error message for --crate-type flag This PR improves the error message for the --crate-type flag. When an invalid crate type is provided, the compiler will now show a list of valid options. ### Before ![image](https://github.com/user-attachments/assets/4922e4e5-eeca-40cd-ac1c-1c6319a81aee) ### After ![image](https://github.com/user-attachments/assets/67ea1f35-aa41-4e4f-8691-47c273d0cff9) I based the implementation on `OutputType::shorthands_display` Closes #70183
2025-03-14Use lit span when suggesting suffix lit castxizheyin-0/+43
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-14Show valid crate types when the user passes unknown `--crate-type` valuemalezjaa-6/+12
Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
2025-03-14Auto merge of #138480 - jhpratt:rollup-y3b8wu5, r=jhprattbors-13/+36
Rollup of 16 pull requests Successful merges: - #136001 (Overhaul examples for PermissionsExt) - #136230 (Reword incorrect documentation about SocketAddr having varying layout) - #136892 (Sync Fuchsia target spec with clang Fuchsia driver) - #136911 (Add documentation URL to selected jobs) - #137870 ( Improve HashMap docs for const and static initializers) - #138179 (Add `src/tools/x` to the main workspace) - #138389 (use `expect` instead of `allow`) - #138396 (Enable metrics and verbose tests in PR CI) - #138398 (atomic intrinsics: clarify which types are supported and (if applicable) what happens with provenance) - #138432 (fix: remove the check of lld not supporting `@response-file)` - #138434 (Visit `PatField` when collecting lint levels) - #138441 (update error message) - #138442 (EUV: fix place of deref pattern's interior's scrutinee) - #138457 (Remove usage of legacy scheme paths on RedoxOS) - #138461 (Remove an outdated line from a test comment) - #138466 (Remove myself from libs review) Failed merges: - #138452 (Remove `RUN_CHECK_WITH_PARALLEL_QUERIES`) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-14Pass precise HirId when calling check_stabilityxizheyin-0/+71
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-14Rollup merge of #138461 - WaffleLapkin:indate-comment, r=ehussJacob Pratt-1/+0
Remove an outdated line from a test comment They *used* to not work, however this was fixed in the PR that added the test. I forgot to remove this line or possibly lost its removal while rebasing. r? `@ehuss`
2025-03-14Rollup merge of #138442 - dianne:deref-pat-euv-fix, r=compiler-errorsJacob Pratt-12/+15
EUV: fix place of deref pattern's interior's scrutinee The place previously used here was that of the temporary holding the reference returned by `Deref::deref` or `DerefMut::deref_mut`. However, since the inner pattern of `deref!(inner)` expects the deref-target type itself, this would ICE when that type was inspected (e.g. by the EUV case for slice patterns). This adds a deref projection to fix that. Since current in-tree consumers of EUV (upvar inference and clippy) don't care about Rvalues, the place could be simplified to `self.cat_rvalue(pat.hir_id, self.pat_ty_adjusted(subpat)?)` to save some cycles. I personally find EUV to be a bit fragile, so I've opted for pedantic correctness. Maybe a `HACK` comment would suffice though? Fixes #125059 r? `@compiler-errors`
2025-03-14Rollup merge of #138434 - compiler-errors:lint-level-pat-field, r=jieyouxuJacob Pratt-0/+21
Visit `PatField` when collecting lint levels Fixes #138428 Side-note, I vaguely skimmed over the other nodes we could be visiting here and it doesn't *seem* to me that we're missing anything, though I may be mistaken given recent(?) support for attrs in where clauses(??). Can be fixed in a follow-up PR.
2025-03-14Auto merge of #138157 - scottmcm:inline-more-tiny-things, r=oli-obkbors-169/+351
Allow more top-down inlining for single-BB callees This means that things like `<usize as Step>::forward_unchecked` and `<PartialOrd for f32>::le` will inline even if we've already done a bunch of inlining to find the calls to them. Fixes #138136 ~~Draft as it's built atop #138135, which adds a mir-opt test that's a nice demonstration of this. To see just this change, look at <https://github.com/rust-lang/rust/pull/138157/commits/48f63e3be552605c2933056b77bf23a326757f92>~~ Rebased to be just the inlining change, as the other existing tests show it great.
2025-03-14Check type of const param correctly in MIR typeckMichael Goulet-0/+69
2025-03-14rustc_target: Add target features for LoongArch v1.1WANG Rui-16/+23
2025-03-14Fix formatting (line too long)KonaeAkira-1/+2
2025-03-14Auto merge of #138391 - scottmcm:SSA-discriminants, r=WaffleLapkinbors-28/+30
Don't `alloca` just to look at a discriminant Today we're making LLVM do a bunch of extra work when you match on trivial stuff like `Option<bool>` or `ControlFlow<u8>`. This PR changes that so that simple types like `Option<u32>` or `Result<(), Box<Error>>` can stay as `OperandValue::ScalarPair` and we can still read the discriminant from them, rather than needing to write them into memory to have a `PlaceValue` just to get the discriminant out. Fixes #137503
2025-03-14Add codegen test for modulo with power-of-two divisorKonaeAkira-0/+16
2025-03-14Fix HIR param pretty printing some more.Nicholas Nethercote-2/+2
Anonymous params are currently represented with `kw::Empty`, so handle that properly. (Subsequent commits will get rid of the `kw::Empty`.)
2025-03-14Handle `_` properly in a couple of places.Nicholas Nethercote-4/+4
Currently (PatKind::Wild` (i.e. `_`) gets turned by `lower_fn_params_to_names` into an empty identifier, which means it is printed incorrectly by HIR pretty printing. And likewise for `lower_fn_params_to_names`, which affects some error messages. This commit fixes them. This requires a slight tweak in a couple of places to continue using parameter numbers in some error messages. And it improves the output of `tests/ui/typeck/cyclic_type_ice.rs`: `/* _ */` is a better suggestion than `/* */`.
2025-03-14Add a pretty printing test for fn params.Nicholas Nethercote-0/+72
Note that multiple parts of the output are incorrect. The following commits will fix this.
2025-03-13Remove an outdated line from a test commentWaffle Lapkin-1/+0
They *used* to not work, however this was fixed in the PR that added the test. I forgot to remove this line or possibly lost its removal while rebasing.
2025-03-13Rollup merge of #138399 - Bryanskiy:delegation-extern-fn, r=petrochenkovMatthias Krüger-0/+49
Delegation: allow foreign fns `reuse` In example: ```rust unsafe extern "C" { fn foo(); } reuse foo as bar; ``` Desugaring before: ```rust fn bar() { foo() //~^ ERROR call to unsafe function `foo` is unsafe and requires unsafe function or block } ``` after: ```rust unsafe extern "C" fn bar() { foo() } ``` Fixes https://github.com/rust-lang/rust/issues/127412 r? `@petrochenkov`
2025-03-13Rollup merge of #138126 - compiler-errors:rtn-for-sugg, r=oli-obkMatthias Krüger-0/+53
Add an opt-out in pretty printing for RTN rendering Today, we render RPITIT types like `impl Sized { T::method(..) }` when RTN is enabled. This is very useful for diagnostics, since it's often not clear what the `impl Sized` type means by itself, and it makes it clear that that's an RPITIT that can be bounded using RTN syntax. See #115624. However, since we don't distinguish types that are rendered for the purposes of printing messages vs suggestions, this representation leaks into suggestions and turns into code that can't be parsed. This PR adds a new `with_types_for_suggestion! {}` and `with_types_for_signature! {}` options to the pretty printing architecture to make it clear that we're rendering a type for code suggestions. This can be applied later as we find that we need it.
2025-03-13Provide helpful diagnostics for shebang lookalikesPyrode-0/+19
2025-03-13Auto merge of #138450 - matthiaskrgr:rollup-4im25vf, r=matthiaskrgrbors-4/+39
Rollup of 6 pull requests Successful merges: - #137816 (attempt to support `BinaryFormat::Xcoff` in `naked_asm!`) - #138109 (make precise capturing args in rustdoc Json typed) - #138343 (Enable `f16` tests for `powf`) - #138356 (bump libc to 0.2.171 to fix xous) - #138371 (Update compiletest's `has_asm_support` to match rustc) - #138404 (Cleanup sysroot locating a bit) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-13Delegation: allow foreign fns `reuse`Bryanskiy-0/+49
2025-03-13Rollup merge of #138404 - bjorn3:sysroot_handling_cleanup, ↵Matthias Krüger-1/+1
r=petrochenkov,jieyouxu Cleanup sysroot locating a bit All commits should preserve existing behavior.
2025-03-13Rollup merge of #138109 - Kohei316:feat/rust-doc-precise-capturing-arg, ↵Matthias Krüger-3/+3
r=aDotInTheVoid,compiler-errors make precise capturing args in rustdoc Json typed close #137616 This PR includes below changes. - Add `rustc_hir::PreciseCapturingArgKind` which allows the query system to return a arg's data. - Add `rustdoc::clean::types::PreciseCapturingArg` and change to use it. - Add `rustdoc-json-types::PreciseCapturingArg` and change to use it. - Update `tests/rustdoc-json/impl-trait-precise-capturing.rs`. - Bump `rustdoc_json_types::FORMAT_VERSION`.
2025-03-13Rollup merge of #137816 - folkertdev:naked-asm-xcoff, r=NoratriebMatthias Krüger-0/+35
attempt to support `BinaryFormat::Xcoff` in `naked_asm!` Fixes https://github.com/rust-lang/rust/issues/137219 So, the inline assembly support for xcoff is extremely limited. The LLVM [XCOFFAsmParser](https://github.com/llvm/llvm-project/blob/1b25c0c4da968fe78921ce77736e5baef4db75e3/llvm/lib/MC/MCParser/XCOFFAsmParser.cpp) does not support many of the attributes that LLVM itself emits, and that should exist based on [the assembler docs](https://www.ibm.com/docs/en/ssw_aix_71/assembler/assembler_pdf.pdf). It also does accept some that should not exist based on those docs. So, I've tried to do the best I can given those limitations. At least it's better than emitting the directives for elf and having that fail somewhere deep in LLVM. Given that inline assembly for this target is incomplete (under `asm_experimental_arch`), I think that's OK (and again I don't see how we can do better given the limitations in LLVM). r? ```@Noratrieb``` (given that you reviewed https://github.com/rust-lang/rust/pull/136637) It seems reasonable to ping the [`powerpc64-ibm-aix` target maintainers](https://doc.rust-lang.org/rustc/platform-support/aix.html), hopefully they have thoughts too: ```@daltenty``` ```@gilamn5tr```
2025-03-13Rollup merge of #138346 - folkertdev:naked-asm-windows-endef, r=ChrisDentonMatthias Krüger-24/+48
naked functions: on windows emit `.endef` without the symbol name tracking issue: https://github.com/rust-lang/rust/issues/90957 fixes https://github.com/rust-lang/rust/issues/138320 The `.endef` directive does not take the name as an argument. Apparently the LLVM x86_64 parser does accept this, but on i686 it's rejected. In general `i686` does some special name mangling stuff, so it's good to include it in the naked function tests. r? ````@ChrisDenton```` (because windows)
2025-03-13Rollup merge of #138162 - ehuss:library-2024, r=cuviperMatthias Krüger-12/+25
Update the standard library to Rust 2024 This updates the standard library to Rust 2024. This includes the following notable changes: - Macros are updated to use new expression fragment specifiers. This PR includes a test to illustrate the changes, primarily allowing `const {...}` expressions now. - Some tests show a change in MIR drop order. We do not believe this will be an observable change ([see zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/268952-edition/topic/standard.20library.20migration/near/500972873)). Fixes https://github.com/rust-lang/rust/issues/133081
2025-03-13EUV: fix place of deref pattern's interior's scrutineedianne-12/+15
The place previously used here was that of the temporary holding the reference returned by `Deref::deref` or `DerefMut::deref_mut`. However, since the inner pattern of `deref!(inner)` expects the deref-target type itself, this would ICE when that type was inspected (e.g. by the EUV case for slice patterns). This adds a deref projection to fix that. Since current in-tree consumers of EUV (upvar inference and clippy) don't care about Rvalues, the place could be simplified to `self.cat_rvalue(pat.hir_id, self.pat_ty_adjusted(subpat)?)` to save some cycles. I personally find EUV to be a bit fragile, so I've opted for pedantic correctness. Maybe a `HACK` comment would suffice though?