about summary refs log tree commit diff
path: root/tests
AgeCommit message (Collapse)AuthorLines
2025-03-17Auto merge of #127173 - bjorn3:mangle_rustc_std_internal_symbol, ↵bors-6/+94
r=wesleywiser,jieyouxu Mangle rustc_std_internal_symbols functions This reduces the risk of issues when using a staticlib or rust dylib compiled with a different rustc version in a rust program. Currently this will either (in the case of staticlib) cause a linker error due to duplicate symbol definitions, or (in the case of rust dylibs) cause rustc_std_internal_symbols functions to be silently overridden. As rust gets more commonly used inside the implementation of libraries consumed with a C interface (like Spidermonkey, Ruby YJIT (curently has to do partial linking of all rust code to hide all symbols not part of the C api), the Rusticl OpenCL implementation in mesa) this is becoming much more of an issue. With this PR the only symbols remaining with an unmangled name are rust_eh_personality (LLVM doesn't allow renaming it) and `__rust_no_alloc_shim_is_unstable`. Helps mitigate https://github.com/rust-lang/rust/issues/104707 try-job: aarch64-gnu-debug try-job: aarch64-apple try-job: x86_64-apple-1 try-job: x86_64-mingw-1 try-job: i686-mingw-1 try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: test-various try-job: armhf-gnu
2025-03-17Auto merge of #138611 - matthiaskrgr:rollup-hmjbqva, r=matthiaskrgrbors-31/+530
Rollup of 7 pull requests Successful merges: - #133870 (Stabilize `asm_goto` feature gate) - #137449 (Denote `ControlFlow` as `#[must_use]`) - #137465 (mir_build: Avoid some useless work when visiting "primary" bindings) - #138349 (Emit function declarations for functions with `#[linkage="extern_weak"]`) - #138412 (Install licenses into `share/doc/rust/licenses`) - #138577 (rustdoc-json: Don't also include `#[deprecated]` in `Item::attrs`) - #138588 (Avoid double lowering of idents) Failed merges: - #138321 ([bootstrap] Distribute split debuginfo if present) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-17Auto merge of #137081 - ↵bors-1/+1
Shourya742:2025-02-15-change-config.toml-to-bootstrap.toml, r=onur-ozkan,jieyouxu,kobzol change config.toml to bootstrap.toml Currently, both Bootstrap and Cargo uses same name as their configuration file, which can be confusing. This PR is based on a discussion to rename `config.toml` to `bootstrap.toml` for Bootstrap. Closes: https://github.com/rust-lang/rust/issues/126875. I have split the PR into atomic commits to make it easier to review. Once the changes are finalized, I will squash them. I am particularly concerned about the changes made to modules that are not part of Bootstrap. How should we handle those changes? Should we ping the respective maintainers?
2025-03-17Rollup merge of #138577 - aDotInTheVoid:deprecate-deprecations, r=GuillaumeGomezMatthias Krüger-0/+38
rustdoc-json: Don't also include `#[deprecated]` in `Item::attrs` Closes #138378 Not sure if this should bump `FORMAT_VERSION` or not. CC `@Enselic` `@LukeMathWalker` `@obi1kenobi` r? `@GuillaumeGomez,` best reviewed commit-by-commit
2025-03-17Rollup merge of #138349 - 1c3t3a:external-weak-cfi, r=rcvalleMatthias Krüger-0/+24
Emit function declarations for functions with `#[linkage="extern_weak"]` Currently, when declaring an extern weak function in Rust, we use the following syntax: ```rust unsafe extern "C" { #[linkage = "extern_weak"] static FOO: Option<unsafe extern "C" fn() -> ()>; } ``` This allows runtime-checking the extern weak symbol through the Option. When emitting LLVM-IR, the Rust compiler currently emits this static as an i8, and a pointer that is initialized with the value of the global i8 and represents the nullabilty e.g. ``` `@FOO` = extern_weak global i8 `@_rust_extern_with_linkage_FOO` = internal global ptr `@FOO` ``` This approach does not work well with CFI, where we need to attach CFI metadata to a concrete function declaration, which was pointed out in https://github.com/rust-lang/rust/issues/115199. This change switches to emitting a proper function declaration instead of a global i8. This allows CFI to work for extern_weak functions. Example: ``` `@_rust_extern_with_linkage_FOO` = internal global ptr `@FOO` ... declare !type !61 !type !62 !type !63 !type !64 extern_weak void `@FOO(double)` unnamed_addr #6 ``` We keep initializing the Rust internal symbol with the function declaration, which preserves the correct behavior for runtime checking the Option. r? `@rcvalle` cc `@jakos-sec` try-job: test-various
2025-03-17Rollup merge of #137465 - Zalathar:visit-primary, r=oli-obkMatthias Krüger-0/+463
mir_build: Avoid some useless work when visiting "primary" bindings While looking over `visit_primary_bindings`, I noticed that it does a bunch of extra work to build up a collection of “user-type projections”, even though 2/3 of its call sites don't even use them. Those callers can get the same result via `thir::Pat::walk_always`. (And it turns out that doing so also avoids creating some redundant user-type entries in MIR for some binding constructs.) I also noticed that even when the user-type projections *are* used, the process of building them ends up eagerly cloning some nested vectors at every recursion step, even in cases where they won't be used because the current subpattern has no bindings. To avoid this, the visit method now assembles a linked list on the stack containing the information that *would* be needed to create projections, and only creates the concrete projections as needed when a primary binding is encountered. Some relevant prior PRs: - #55274 - https://github.com/rust-lang/rust/commit/0bfe184b1ad14db4b002c3a272adf44e1839822f in #55937 --- There should be no user-visible change in compiler output.
2025-03-17Rollup merge of #133870 - nbdd0121:asm, r=traviscross,nnethercoteMatthias Krüger-31/+5
Stabilize `asm_goto` feature gate Stabilize `asm_goto` feature (tracked by #119364). The issue will remain open and be updated to track `asm_goto_with_outputs`. Reference PR: https://github.com/rust-lang/reference/pull/1693 # Stabilization Report This feature adds a `label <block>` operand type to `asm!`. `<block>` must be a block expression with type unit or never. The address of the block is substituted and the assembly may jump to the block. When block completes the `asm!` block returns and continues execution. The block starts a new safety context and unsafe operations within must have additional `unsafe`s; the effect of `unsafe` that surrounds `asm!` block is cancelled. See https://github.com/rust-lang/rust/issues/119364#issuecomment-2316037703 and https://github.com/rust-lang/rust/pull/131544. It's currently forbidden to use `asm_goto` with output operands; that is still unstable under `asm_goto_with_outputs`. Example: ```rust unsafe { asm!( "jmp {}", label { println!("Jumped from asm!"); } ); } ``` Tests: - tests/ui/asm/x86_64/goto.rs - tests/ui/asm/x86_64/goto-block-safe.stderr - tests/ui/asm/x86_64/bad-options.rs - tests/codegen/asm/goto.rs
2025-03-17Only run symbols-all-mangled test on ELF targetsbjorn3-0/+1
2025-03-17Ignore symbols that don't contain rust as substring for executablesbjorn3-8/+7
For staticlib we still keep checking symbols that don't contain rust as substring.
2025-03-17Add test that all symbols we expect to be mangled are actually mangledbjorn3-0/+88
2025-03-17Remove implicit #[no_mangle] for #[rustc_std_internal_symbol]bjorn3-6/+6
2025-03-17Stabilize asm_gotoGary Guo-31/+5
2025-03-17Rollup merge of #138586 - jyn514:doc-register-tool, r=jieyouxuJacob Pratt-0/+24
Document `#![register_tool]` cc https://github.com/rust-lang/rust/issues/66079
2025-03-17Rollup merge of #138517 - compiler-errors:better-child-capture, r=oli-obkJacob Pratt-0/+109
Improve upvar analysis for deref of child capture Two fixes to the heuristic I implemented in #123660. As I noted in the code: > Luckily, if this function is not correct, then the program is not unsound, since we still borrowck and validate the choices made from this function -- the only side-effect is that the user may receive unnecessary borrowck errors. This indeed fixes unnecessary borrowck errors. r? oli-obk --- The heuristic is only valid if we deref a `&T`, not a `&mut T` or `Box<T>`, so make sure to check the type. This fixes: ```rust struct Foo { precise: i32 } fn mut_ref_inside_mut(f: &mut Foo) { let x: impl AsyncFn() = async move || { let y = &f.precise; }; } ``` Since the capture from `f` to `&f.precise` needs to be treated as a lending borrow from the parent coroutine-closure to the child coroutine. --- The heuristic is also valid if *any* deref projection in the child capture's projections is a `&T`, but we were only looking at the last one. This ensures that this function is considered not to be lending: ```rust struct Foo { precise: i32 } fn ref_inside_mut(f: &mut &Foo) { let x: impl Fn() -> _ = async move || { let y = &f.precise; }; } ``` (Specifically, checking that `impl Fn() -> _` is satisfied is exercising that the coroutine is not considered to be lending.)
2025-03-17Rollup merge of #136355 - ↵Jacob Pratt-1/+69
GuillaumeGomez:proc-macro_add_value_retrieval_methods, r=Amanieu Add `*_value` methods to proc_macro lib This is the implementation of https://github.com/rust-lang/libs-team/issues/459. It allows to get the actual value (unescaped) of the different string literals. Part of https://github.com/rust-lang/rust/issues/136652. r? libs-api
2025-03-17Emit function declarations for functions with #[linkage="extern_weak"]Bastian Kersting-0/+24
Currently, when declaring an extern weak function in Rust, we use the following syntax: ```rust unsafe extern "C" { #[linkage = "extern_weak"] static FOO: Option<unsafe extern "C" fn() -> ()>; } ``` This allows runtime-checking the extern weak symbol through the Option. When emitting LLVM-IR, the Rust compiler currently emits this static as an i8, and a pointer that is initialized with the value of the global i8 and represents the nullabilty e.g. ``` @FOO = extern_weak global i8 @_rust_extern_with_linkage_FOO = internal global ptr @FOO ``` This approach does not work well with CFI, where we need to attach CFI metadata to a concrete function declaration, which was pointed out in https://github.com/rust-lang/rust/issues/115199. This change switches to emitting a proper function declaration instead of a global i8. This allows CFI to work for extern_weak functions. We keep initializing the Rust internal symbol with the function declaration, which preserves the correct behavior for runtime checking the Option. Co-authored-by: Jakob Koschel <jakobkoschel@google.com>
2025-03-17replace config.toml to bootstrap.toml in src/ci, src/etc/* and tests/run-makebit-aloo-1/+1
2025-03-17Document `#![register_tool]`jyn-0/+24
2025-03-16Rollup merge of #138552 - jieyouxu:print-request-cleanups, r=UrgauJacob Pratt-5/+103
Misc print request handling cleanups + a centralized test for print request stability gating I was working on implementing `--print=supported-crate-types`, then I noticed some things that were mildly annoying me, so I pulled out these changes. In this PR: - First commit adds a centralized test `tests/ui/print/stability.rs` that is responsible for exercising stability gating of the print requests. - AFAICT we didn't have any test that systematically checks this. - I coalesced `tests/ui/feature-gates/feature-gate-print-check-cfg.rs` (for `--print=check-cfg`) into this test too, since `--print=check-cfg` is only `-Z unstable-options`-gated like other unstable print requests, and is not additionally feature-gated. cc ``@Urgau`` in case you have any concerns. - Second commit alphabetically sorts the `PrintKind` enum for consistency because the `PRINT_KINDS` list (using the enum) is *already* alphabetically sorted. - Third commit pulls out two helpers: 1. A helper `check_print_request_stability` for checking stability of print requests and the diagnostics for using unstable print requests without `-Z unstable-options`, to avoid repeating the same logic over and over. 2. A helper `emit_unknown_print_request_help` for the unknown print request diagnostics to make print request collection control flow more obvious. - Fourth commit renames `PrintKind::{TargetSpec,AllTargetSpecs}` to `PrintKind::{TargetSpecJson,AllTargetSpecsJson}` to better reflect their actual print names, `--print={target-spec-json,all-target-specs-json}`. r? ``@nnethercote`` (or compiler/reroll)
2025-03-16rustdoc-json: Don't also include `#[deprecated]` in `Item::attrs`Alona Enraght-Moony-8/+8
2025-03-16rustdoc-json: Add tests for `#[deprecated(...)]`Alona Enraght-Moony-0/+38
2025-03-16Add a centralized test for print request stability gatingJieyou Xu-5/+103
I can't find any dedicated tests that actually exercises the stability gating (via `-Z unstable-options`) of print requests, so here's a dedicated one. I coalesced `tests/ui/feature-gates/feature-gate-print-check-cfg.rs` into this test, because AFAICT that print request is not feature gated, but only `-Z unstable-options`-gated just like other unstable print requests.
2025-03-16Add test for new proc_macro literal methodsGuillaume Gomez-1/+53
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-16Split `visit_primary_bindings` into two variantsZalathar-6/+2
The existing method does some non-obvious extra work to collect user types and build user-type projections, which is specifically needed by `declare_bindings` and not by the other two callers.
2025-03-16Add a mir-opt test that demonstrates user type annotationsZalathar-0/+467
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-14Improve upvar analysis for deref of child captureMichael Goulet-0/+109
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>