Commit Graph

19780 Commits

Author SHA1 Message Date
Jieyou Xu
2beccc4d8e Adjust some run-make tests on cross-compile 2025-06-19 07:38:01 +08:00
bors
044514eb26 Auto merge of #142689 - Urgau:rollup-4ho6835, r=Urgau
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#135656 (Add `-Z hint-mostly-unused` to tell rustc that most of a crate will go unused)
 - rust-lang/rust#138237 (Get rid of `EscapeDebugInner`.)
 - rust-lang/rust#141614 (lint direct use of rustc_type_ir )
 - rust-lang/rust#142123 (Implement initial support for timing sections (`--json=timings`))
 - rust-lang/rust#142377 (Try unremapping compiler sources)
 - rust-lang/rust#142674 (remove duplicate crash test)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-18 21:19:39 +00:00
Urgau
bf38e5dee3 Rollup merge of #142377 - Urgau:unremap-rustc-dev, r=jieyouxu
Try unremapping compiler sources

See [#t-compiler/help > Span pointing to wrong file location (`rustc-dev` component)](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Span.20pointing.20to.20wrong.20file.20location.20.28.60rustc-dev.60.20component.29/with/521087083).

This PR is a follow-up to rust-lang/rust#141751 regarding the compiler side.

Specifically we now take into account the `CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR` env from rust-lang/rust#141751 when trying to unremap sources from `$sysroot/lib/rustlib/rustc-src/rust` (the `rustc-dev` component install directory).

Best reviewed commit by commit.

cc ``@samueltardieu``
r? ``@jieyouxu``
2025-06-18 19:40:32 +02:00
Urgau
4df9f2f841 Emit the usages suggestions as tool-only suggestions 2025-06-18 19:15:10 +02:00
Boxy
377d8fa4e3 Reviews 2025-06-18 17:51:22 +01:00
Jakub Beránek
0093ca5c76 Rollup merge of #141610 - BoxyUwU:stabilize_generic_arg_infer, r=lcnr,traviscross
Stabilize `feature(generic_arg_infer)`

Fixes rust-lang/rust#85077

r? lcnr

cc ````@rust-lang/project-const-generics````
2025-06-18 18:06:49 +02:00
Jakub Beránek
ff146112f6 Rollup merge of #140774 - workingjubilee:should-force-frame-pointers-favor-the-target-or-cli, r=jieyouxu
Affirm `-Cforce-frame-pointers=off` does not override

This PR exists to document that we (that is, the compiler reviewer) implicitly made a decision in rust-lang/rust#86652 that defies the expectations of some programmers. Some programmers believe `-Cforce-frame-pointers=false` should obey the programmer in all cases, forcing the compiler to avoid generating frame pointers, even if the target specification would indicate they must be generated. However, many targets rely on frame pointers for fast or sound unwinding.

T-compiler had a weekly triage meeting on 2025-05-22. This topic was put to discussion because some programmers may expect the target-overriding behavior. In that meeting we decided removing frame pointers, at least with regards to the contract of the `-Cforce-frame-pointers` option, is not required, even if `=off` is passed, and that we will not do so if the target would expect them. This follows from the documentation here: https://doc.rust-lang.org/rustc/codegen-options/index.html#force-frame-pointers

We may separately pursue trying to clarify the situation more emphatically in our documentation, or warn when people pass the option when it doesn't do anything.
2025-06-18 18:06:48 +02:00
Romain Perier
a1a3bef6f0 Implement lint against direct uses of rustc_type_ir in compiler crates
This commit adds a lint to prevent the use of rustc_type_ir in random
compiler crates, except for type system internals traits, which are
explicitly allowed. Moreover, this fixes diagnostic_items() to include
the CRATE_OWNER_ID, otherwise rustc_diagnostic_item attribute is ignored
on the crate root.
2025-06-18 16:01:41 +02:00
Jana Dönszelmann
815f0b71c7 better template for repr attributes 2025-06-18 13:48:42 +02:00
Jana Dönszelmann
b64fd13a04 convert the optimize attribute to a new parser 2025-06-18 13:48:42 +02:00
Jakub Beránek
a27bdea4b7 Enable automatic cross-compilation in run-make tests 2025-06-18 18:39:25 +08:00
Folkert de Vries
1fdf2b5620 add #[align] attribute
Right now it's used for functions with `fn_align`, in the future it will
get more uses (statics, struct fields, etc.)
2025-06-18 12:37:08 +02:00
bors
6f935a044d Auto merge of #141061 - dpaoliello:shimasfn, r=bjorn3
Change __rust_no_alloc_shim_is_unstable to be a function

This fixes a long sequence of issues:

1. A customer reported that building for Arm64EC was broken: #138541
2. This was caused by a bug in my original implementation of Arm64EC support, namely that only functions on Arm64EC need to be decorated with `#` but Rust was decorating statics as well.
3. Once I corrected Rust to only decorate functions, I started linking failures where the linker couldn't find statics exported by dylib dependencies. This was caused by the compiler not marking exported statics in the generated DEF file with `DATA`, thus they were being exported as functions not data.
4. Once I corrected the way that the DEF files were being emitted, the linker started failing saying that it couldn't find `__rust_no_alloc_shim_is_unstable`. This is because the MSVC linker requires the declarations of statics imported from other dylibs to be marked with `dllimport` (whereas it will happily link to functions imported from other dylibs whether they are marked `dllimport` or not).
5. I then made a change to ensure that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport`, but the MSVC linker started emitting warnings that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport` but was declared in an obj file. This is a harmless warning which is a performance hint: anything that's marked `dllimport` must be indirected via an `__imp` symbol so I added a linker arg in the target to suppress the warning.
6. A customer then reported a similar warning when using `lld-link` (<https://github.com/rust-lang/rust/pull/140176#issuecomment-2872448443>). I don't think it was an implementation difference between the two linkers but rather that, depending on the obj that the declaration versus uses of `__rust_no_alloc_shim_is_unstable` landed in we would get different warnings, so I suppressed that warning as well: #140954.
7. Another customer reported that they weren't using the Rust compiler to invoke the linker, thus these warnings were breaking their build: <https://github.com/rust-lang/rust/pull/140176#issuecomment-2881867433>. At that point, my original change was reverted (#141024) leaving Arm64EC broken yet again.

Taking a step back, a lot of these linker issues arise from the fact that `__rust_no_alloc_shim_is_unstable` is marked as `extern "Rust"` in the standard library and, therefore, assumed to be a foreign item from a different crate BUT the Rust compiler may choose to generate it either in the current crate, some other crate that will be statically linked in OR some other crate that will by dynamically imported.

Worse yet, it is impossible while building a given crate to know if `__rust_no_alloc_shim_is_unstable` will statically linked or dynamically imported: it might be that one of its dependent crates is the one with an allocator kind set and thus that crate (which is compiled later) will decide depending if it has any dylib dependencies or not to import `__rust_no_alloc_shim_is_unstable` or generate it. Thus, there is no way to know if the declaration of `__rust_no_alloc_shim_is_unstable` should be marked with `dllimport` or not.

There is a simple fix for all this: there is no reason `__rust_no_alloc_shim_is_unstable` must be a static. It needs to be some symbol that must be linked in; thus, it could easily be a function instead. As a function, there is no need to mark it as `dllimport` when dynamically imported which avoids the entire mess above.

There may be a perf hit for changing the `volatile load` to be a `tail call`, so I'm happy to change that part back (although I question what the codegen of a `volatile load` would look like, and if the backend is going to try to use load-acquire semantics).

Build with this change applied BEFORE #140176 was reverted to demonstrate that there are no linking issues with either MSVC or MinGW: <https://github.com/rust-lang/rust/actions/runs/15078657205>

Incidentally, I fixed `tests/run-make/no-alloc-shim` to work with MSVC as I needed it to be able to test locally (FYI for #128602)

r? `@bjorn3`
cc `@jieyouxu`
2025-06-18 09:24:40 +00:00
Mara Bos
a693c52173 Bless/update tests. 2025-06-18 10:20:43 +02:00
Mara Bos
58a5ab5a6d Update unpretty tests. 2025-06-18 10:20:20 +02:00
Mara Bos
f608da2ad8 Remove 'this error originates in format_args_nl' from test output.
This message is no longer generated.

This is probably a good thing. The relevant span is entirely in user
code, and "format_args_nl" is an implementation detail with a name that
isn't even public.
2025-06-18 10:20:20 +02:00
Mara Bos
4ca0f01a5a Update mir-opt tests. 2025-06-18 10:20:20 +02:00
Mara Bos
ddd9ee9756 Remove outdated test.
We no longer error in this case!
2025-06-18 10:20:20 +02:00
bors
1bb335244c Auto merge of #138165 - jdonszelmann:inline, r=oli-obk
Rewrite `inline` attribute parser to use new infrastructure and improve diagnostics for all parsed attributes

r? `@oli-obk`

This PR:
- creates a new parser for inline attributes
- creates consistent error messages and error codes between attribute parsers; inline and others
- as such changes a few error messages for other attributes to be (in my eyes) much more consistent
- tests ast-lowering lints introduced by rust-lang/rust#138164 since this is now useful for the first time
- Coalesce some useless error codes

Builds on top of rust-lang/rust#138164

Closes rust-lang/rust#137950
2025-06-18 06:25:21 +00:00
bors
27733d46d7 Auto merge of #130887 - Soveu:repeatn, r=scottmcm
Safer implementation of RepeatN

I've seen the "Use MaybeUninit for RepeatN" commit while reading This Week In Rust and immediately thought about something I've written some time ago - https://github.com/Soveu/repeat_finite/blob/master/src/lib.rs.

Using the fact, that `Option` will find niche in `(T, NonZeroUsize)`, we can construct something that has the same size as `(T, usize)` while completely getting rid of `MaybeUninit`.
This leaves only `unsafe` on `TrustedLen`, which is pretty neat.
2025-06-18 03:18:10 +00:00
Andrew Zhogin
eee2d7b101 AsyncDrop trait without sync Drop generates an error 2025-06-18 09:04:34 +07:00
Urgau
42bb66add3 Also emit suggestions for usages in the non_upper_case_globals lint 2025-06-18 00:06:37 +02:00
Jana Dönszelmann
780b902111 fix clippy 2025-06-17 23:22:51 +02:00
Jana Dönszelmann
5ab5f8a24a make error codes reflect reality better 2025-06-17 23:22:51 +02:00
Jacob Pratt
f663823fd5 Rollup merge of #142631 - xizheyin:142143, r=Urgau
Dont suggest remove semi inside macro expansion for redundant semi lint

Fixes rust-lang/rust#142143

r? compiler
2025-06-17 23:19:39 +02:00
Jacob Pratt
e95fb09dfb Rollup merge of #142371 - fee1-dead-contrib:push-xqlkumzurkus, r=petrochenkov
avoid `&mut P<T>` in `visit_expr` etc methods

trying a different way than rust-lang/rust#141636
r? ghost
2025-06-17 23:19:34 +02:00
Jacob Pratt
0772ee7f8b Rollup merge of #142100 - lolbinarycat:rustdoc-srcIndex-138467, r=GuillaumeGomez
rustdoc: make srcIndex no longer a global variable

this is one-time initialization data, it can just
be a function parameter.

while we're doing that, we can more the json parsing into the function and save a few extra bytes of storage for free, at least in the case of multiple crates in a doc bundle.

fixes https://github.com/rust-lang/rust/issues/138467
2025-06-17 23:19:33 +02:00
Jacob Pratt
17ab49a94a Rollup merge of #141608 - moatom:proc_macro-140238, r=dtolnay
Add support for repetition to `proc_macro::quote`

Progress toward: rust-lang/rust#140238
2025-06-17 23:19:32 +02:00
Jana Dönszelmann
672452d573 use consistent attr errors in all attribute parsers 2025-06-17 23:19:31 +02:00
Jana Dönszelmann
ee976bbbca fix bugs in inline/force_inline and diagnostics of all attr parsers 2025-06-17 23:19:31 +02:00
Daniel Paoliello
81f7eebb23 Add a missing colon at the end of the expected panic message in location-detail-unwrap-multiline.rs 2025-06-17 12:24:44 -07:00
bors
f3db63916e Auto merge of #142613 - workingjubilee:rollup-yuod2hg, r=workingjubilee
Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#138538 (Make performance description of String::{insert,insert_str,remove} more precise)
 - rust-lang/rust#141946 (std: refactor explanation of `NonNull`)
 - rust-lang/rust#142216 (Miscellaneous RefCell cleanups)
 - rust-lang/rust#142542 (Manually invalidate caches in SimplifyCfg.)
 - rust-lang/rust#142563 (Refine run-make test ignores due to unpredictable `i686-pc-windows-gnu` unwind mechanism)
 - rust-lang/rust#142570 (Reject union default field values)
 - rust-lang/rust#142584 (Handle same-crate macro for borrowck semicolon suggestion)
 - rust-lang/rust#142585 (Update books)
 - rust-lang/rust#142586 (Fold unnecessary `visit_struct_field_def` in AstValidator)
 - rust-lang/rust#142587 (Make sure to propagate result from `visit_expr_fields`)
 - rust-lang/rust#142595 (Revert overeager warning for misuse of `--print native-static-libs`)
 - rust-lang/rust#142598 (Set elf e_flags on ppc64 targets according to abi)
 - rust-lang/rust#142601 (Add a comment to `FORMAT_VERSION`.)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-17 18:14:08 +00:00
xizheyin
72fbf3ea61 Dont suggest remove semi inside macro expansion for redundant semi lint
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-18 00:36:51 +08:00
xizheyin
fd9c1b962a Find correct span when suggesting using clone
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-17 23:48:47 +08:00
xizheyin
02dac5cd78 add test suggest-clone-in-macro-issue-139253.rs
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-17 23:42:57 +08:00
bors
86d0aef804 Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obk
Sized Hierarchy: Part I

This patch implements the non-const parts of rust-lang/rfcs#3729. It introduces two new traits to the standard library, `MetaSized` and `PointeeSized`. See the RFC for the rationale behind these traits and to discuss whether this change makes sense in the abstract.

These traits are unstable (as is their constness), so users cannot refer to them without opting-in to `feature(sized_hierarchy)`. These traits are not behind `cfg`s as this would make implementation unfeasible, there would simply be too many `cfg`s required to add the necessary bounds everywhere. So, like `Sized`, these traits are automatically implemented by the compiler.

RFC 3729 describes changes which are necessary to preserve backwards compatibility given the introduction of these traits, which are implemented and as follows:

- `?Sized` is rewritten as `MetaSized`
- `MetaSized` is added as a default supertrait for all traits w/out an explicit sizedness supertrait already.

There are no edition migrations implemented in this,  as these are primarily required for the constness parts of the RFC and prior to stabilisation of this (and so will come in follow-up PRs alongside the const parts). All diagnostic output should remain the same (showing `?Sized` even if the compiler sees `MetaSized`) unless the `sized_hierarchy` feature is enabled.

Due to the use of unstable extern types in the standard library and rustc, some bounds in both projects have had to be relaxed already - this is unfortunate but unavoidable so that these extern types can continue to be used where they were before. Performing these relaxations in the standard library and rustc are desirable longer-term anyway, but some bounds are not as relaxed as they ideally would be due to the inability to relax `Deref::Target` (this will be investigated separately).

It is hoped that this is implemented such that it could be merged and these traits could exist "under the hood" without that being observable to the user (other than in any performance impact this has on the compiler, etc). Some details might leak through due to the standard library relaxations, but this has not been observed in test output.

**Notes:**

- Any commits starting with "upstream:" can be ignored, as these correspond to other upstream PRs that this is based on which have yet to be merged.
- This best reviewed commit-by-commit. I've attempted to make the implementation easy to follow and keep similar changes and test output updates together.
  - Each commit has a short description describing its purpose.
  - This patch is large but it's primarily in the test suite.
- I've worked on the performance of this patch and a few optimisations are implemented so that the performance impact is neutral-to-minor.
- `PointeeSized` is a different name from the RFC just to make it more obvious that it is different from `std::ptr::Pointee` but all the names are yet to be bikeshed anyway.
- `@nikomatsakis` has confirmed [that this can proceed as an experiment from the t-lang side](https://rust-lang.zulipchat.com/#narrow/channel/435869-project-goals/topic/SVE.20and.20SME.20on.20AArch64.20.28goals.23270.29/near/506196491)
- FCP in https://github.com/rust-lang/rust/pull/137944#issuecomment-2912207485

Fixes rust-lang/rust#79409.

r? `@ghost` (I'll discuss this with relevant teams to find a reviewer)
2025-06-17 15:08:50 +00:00
xizheyin
1ab8ff57d6 Add test suggest-remove-semi-in-macro-expansion-issue-142143.rs
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-17 22:37:24 +08:00
Boxy
ae65625252 Dont replace escaping bound vars in item sigs 2025-06-17 14:48:17 +01:00
Boxy
9961747414 rebase 2025-06-17 14:28:46 +01:00
Boxy
2a950b5637 Test whether we use DeepRejectCtxt 2025-06-17 14:18:34 +01:00
Boxy
442862bc78 Don't build ParamEnv and do trait solving in ItemCtxts 2025-06-17 14:18:34 +01:00
Jubilee
99c8475e52 Rollup merge of #142595 - workingjubilee:revert-warning-138139, r=ChrisDenton
Revert overeager warning for misuse of `--print native-static-libs`

In a PR to emit warnings on misuse of `--print native-static-libs`, we did not consider the matter of composing parts of build systems. If you are not directly invoking rustc, it can be difficult to know when you will in fact compile a staticlib, so making sure uses `--print native-static-lib` correctly can be just a nuisance.

Next cycle we can reland a slightly more narrowly focused variant or one that focuses on `--emit` instead of `--print native-static-libs`. But in its current state, I am not sure the warning is very useful.
2025-06-17 00:28:20 -07:00
Jubilee
5df238921f Rollup merge of #142587 - compiler-errors:try-visit-expr-fields, r=jieyouxu
Make sure to propagate result from `visit_expr_fields`

We weren't propagating the `ControlFlow::Break` out of a struct field, which means that the solution implemented in rust-lang/rust#130443 didn't work for nested fields.

Fixes rust-lang/rust#142525.
2025-06-17 00:28:19 -07:00
Jubilee
b27b74f80e Rollup merge of #142584 - Urgau:span-borrowck-139049, r=fmease
Handle same-crate macro for borrowck semicolon suggestion

Handles https://github.com/rust-lang/rust/pull/142543#discussion_r2149545623

cc ``@m-ou-se``
r? ``@fmease``
2025-06-17 00:28:17 -07:00
Jubilee
d4f23cdc91 Rollup merge of #142570 - jieyouxu:disunion, r=estebank
Reject union default field values

Fixes rust-lang/rust#142555.

The [`default_field_values` RFC][rfc] does not specify that default field values may be used on `union`s, and it's not clear how default field values may be used with `union`s without an design extension to the RFC. So, for now, reject trying to use default field values with `union`s.

### Review notes

- The first commit adds the `union` with default field values test case to `tests/ui/structs/default-field-values/failures.rs`, where `union`s with default field values are currently accepted.
- The second commit rejects trying to supply default field values to `union` definitions.
- When `default_field_values` feature gate is disabled, we show the feature gate error when the user tries to write `union`s with default field values. When the feature gate is enabled, we reject this usage with
   > unions cannot have default field values

``@rustbot`` label: +F-default_field_values

[rfc]: https://rust-lang.github.io/rfcs/3681-default-field-values.html
2025-06-17 00:28:17 -07:00
Jubilee Young
5a449fb40b tests: remove define so dso_local attr does not disrupt test 2025-06-16 23:21:23 -07:00
Jieyou Xu
aa8c6f83b6 Don't match on platform-specific directory not found message 2025-06-17 10:53:11 +08:00
Jieyou Xu
1dbedaf405 Refine run-make test ignores due to unpredictable i686-pc-windows-gnu unwind mechanism 2025-06-17 10:49:28 +08:00
binarycat
00c104225f rustdoc: make srcIndex no longer a global variable
this is one-time initialization data, it can just
be a function parameter.

we also move the json parsing into createSrcSidebar
to save a few bytes.
2025-06-16 20:22:24 -05:00
Jieyou Xu
2dd9cc1130 Reject union default field values 2025-06-17 07:27:58 +08:00