Commit Graph

21219 Commits

Author SHA1 Message Date
Kivooeo
23f1767c80 allow taking address to union field 2025-08-31 17:23:32 +00:00
bors
f73bcd50a4 Auto merge of #146053 - joboet:split-paths-regression, r=Mark-Simulacrum
std: fix `SplitPaths` regression

Fixes rust-lang/rust#146045 by defining the TAIT more precisely, ensuring that `'a` does not need to be live on drop.
2025-08-31 16:19:09 +00:00
joboet
6d8d952e48 std: fix SplitPaths regression 2025-08-31 13:46:52 +02:00
Matthias Krüger
e5f96e3b43 Rollup merge of #145592 - nilotpal-n7:fix-format-alignment, r=lcnr
Fix format string grammar in docs and improve alignment error message for #144023

This PR improves error messages and documentation for format strings involving alignment and formatting traits.

Highlights:

- Clearer error messages for invalid alignment specifiers (e.g., `{0:#X>18}`), showing the expected `<`, `^`, or `>` and a working example:

    println!("{0:>#18X}", value);

- Updated UI test `format-alignment-hash.rs` to reflect the improved error output.
- Documentation clarification: ensures examples correctly show how width, alignment, and traits like `x`, `X`, `#` combine.

Motivation:
Previously, using `#` with alignment and width produced confusing errors. This PR guides users on the correct syntax and provides actionable examples.

Testing:
- Built the compiler (`./x build`)
- Blessed and ran UI tests (`./x. test src/test/ui/fmt/format-alignment-hash.rs --bless`)
- Verified full test suite passes (`./x test`)

Issue: rust-lang/rust#144023
2025-08-31 13:40:35 +02:00
Matthias Krüger
0e28b4201a Rollup merge of #144443 - WaffleLapkin:integer-target-pointer-width, r=Noratrieb
Make target pointer width in target json an integer

r? Noratrieb
cc `@RalfJung` (https://github.com/rust-lang/rust/pull/142352/files#r2230380120)

try-job: x86_64-rust-for-linux
2025-08-31 13:40:34 +02:00
bors
64a99db105 Auto merge of #145582 - estebank:issue-107806, r=chenyukang
Detect missing `if let` or `let-else`

During `let` binding parse error and encountering a block, detect if there is a likely missing `if` or `else`:

```
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{`
  --> $DIR/missing-if-let-or-let-else.rs:14:25
   |
LL |     let Some(x) = foo() {
   |                         ^ expected one of `.`, `;`, `?`, `else`, or an operator
   |
help: you might have meant to use `if let`
   |
LL |     if let Some(x) = foo() {
   |     ++
help: alternatively, you might have meant to use `let else`
   |
LL |     let Some(x) = foo() else {
   |                         ++++
```

Fix rust-lang/rust#107806.
2025-08-31 03:00:54 +00:00
yukang
263766bcc2 suggest method name with maybe ty mismatch 2025-08-31 10:55:14 +08:00
Esteban Küber
f5b5e67f0f More targeted parentheses suggestion for match statement intended as expression
```
error[E0308]: mismatched types
  --> $DIR/expr-as-stmt.rs:69:5
   |
LL |     match () { () => 1 } + match () { () => 1 }
   |     ^^^^^^^^^^^^^^^^^^^^ expected `()`, found integer
   |
help: parentheses are required to parse this as an expression
   |
LL |     (match () { () => 1 }) + match () { () => 1 }
   |     +                    +
```
2025-08-31 01:43:57 +00:00
Esteban Küber
a7e32a5319 Provide suggestion when encountering match () { () => 1 } + match () { () => 1 }
```
error[E0308]: mismatched types
  --> $DIR/expr-as-stmt.rs:69:5
   |
LL |     match () { () => 1 } + match () { () => 1 }
   |     ^^^^^^^^^^^^^^^^^^^^ expected `()`, found integer
   |
help: consider using a semicolon here
   |
LL |     match () { () => 1 }; + match () { () => 1 }
   |                         +
help: alternatively, parentheses are required to parse this as an expression
   |
LL |     (match () { () => 1 }) + match () { () => 1 }
   |     +                    +
```

Parentheses are needed for the `match` to be unambiguously parsed as an expression and not a statement when chaining with binops that are also unops.
2025-08-31 00:42:58 +00:00
Esteban Küber
18a36bccf5 Detect negative literal inferred to unsigned integer
```
error[E0277]: the trait bound `usize: Neg` is not satisfied
  --> $DIR/negative-literal-infered-to-unsigned.rs:2:14
   |
LL |     for x in -5..5 {
   |              ^^ the trait `Neg` is not implemented for `usize`
   |
help: consider specifying an integer type that can be negative
   |
LL |     for x in -5isize..5 {
   |                +++++
```
2025-08-30 23:28:58 +00:00
Esteban Küber
86085b4f65 Avoid unnecessary suggestion in or-pattern 2025-08-30 17:44:23 +00:00
Esteban Küber
3355f4bced Suggest constant on unused binding in a pattern
```
error: unused variable: `Batery`
  --> $DIR/binding-typo-2.rs:110:9
   |
LL |         Batery => {}
   |         ^^^^^^
   |
help: if this is intentional, prefix it with an underscore
   |
LL |         _Batery => {}
   |         +
help: you might have meant to pattern match on the similarly named constant `Battery`
   |
LL |         Battery => {}
   |            +
```
2025-08-30 17:02:44 +00:00
Esteban Küber
00f6fe1b6c On unused binding in pattern, suggest unit struct/variant with similar name
When encountering a typo in a pattern that gets interpreted as an unused binding, look for unit struct/variant of the same type as the binding:

```
error: unused variable: `Non`
  --> $DIR/binding-typo-2.rs:36:9
   |
LL |         Non => {}
   |         ^^^
   |
help: if this is intentional, prefix it with an underscore
   |
LL |         _Non => {}
   |         +
help: you might have meant to pattern match on the similarly named variant `None`
   |
LL -         Non => {}
LL +         std::prelude::v1::None => {}
   |
```
2025-08-30 16:24:26 +00:00
bors
e95db591a4 Auto merge of #146026 - Zalathar:rollup-urbmv0t, r=Zalathar
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#143462 (fix(lib-std-fs): handle `usize` overflow in `read*`)
 - rust-lang/rust#144651 (Implementation: `#[feature(nonpoison_condvar)]`)
 - rust-lang/rust#145465 (Stabilize `array_repeat` feature)
 - rust-lang/rust#145776 (Optimize `.ilog({2,10})` to `.ilog{2,10}()`)
 - rust-lang/rust#145969 (Add Duration::from_nanos_u128)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-30 11:08:59 +00:00
Stuart Cook
b5c19e839f Rollup merge of #145465 - Kivooeo:stabilize-array_repeat, r=joboet
Stabilize `array_repeat` feature

This closes [tracking issue](https://github.com/rust-lang/rust/issues/126695) and stabilises `array::repeat`
2025-08-30 20:29:06 +10:00
Martin Nordholts
2ce6154b32 compiler: Include span of too huge array with -Cdebuginfo=2
We have a few ui tests to ensure we emit an error if we encounter too
big arrays. Before this fix, compiling the tests with `-Cdebuginfo=2`
would not include the spans of the instantiation sites, because the
error is then emitted from a different code path that does not include
the span.

Propagate the span to the error also in the debuginfo case, so the tests
passes regardless of debuginfo level.
2025-08-30 11:09:29 +02:00
bors
846e377215 Auto merge of #123319 - no92:managarm-target, r=davidtwco
Add managarm as a tier 3 target

This PR aims to introduce the `x86_64-unknown-managarm-mlibc` as a tier 3 target to Rust.

[managarm](https://github.com/managarm/managarm) is a microkernel with fully asynchronous I/O that also provides a POSIX server. Despite the differences, managarm provides good compatability with POSIX and Linux APIs. As a rule of thumb, barring OS-specific code, it should be mostly source-compatible with Linux.

We have been shipping a patched rust for over 25 releases now, and we would like to upstream our work. For a smoother process, this PR only adds the target to rustc and some documentation. `std` support will be added in a future PR.

## Addressing the tier 3 target policy

> A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

`@no92,` `@64` and `@Dennisbonke` will be target maintainers.

> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.
> - Target names should not introduce undue confusion or ambiguity unless absolutely necessary to maintain ecosystem compatibility. For example, if the name of the target makes people extremely likely to form incorrect beliefs about what it targets, the name should be changed or augmented to disambiguate it.
> - If possible, use only letters, numbers, dashes and underscores for the name. Periods (.) are known to cause issues in Cargo.

`x86_64-unknown-managarm-mlibc` is what we use for LLVM as well.

> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.
> - The target must not introduce license incompatibilities.
> - Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).
> - The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.
> - Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.
> - "onerous" here is an intentionally subjective term. At a minimum, "onerous" legal/licensing terms include but are not limited to: non-disclosure requirements, non-compete requirements, contributor license agreements (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms, requirements conditional on the employer or employment of any particular Rust developers, revocable terms, any requirements that create liability for the Rust project or its developers or users, or any requirements that adversely affect the livelihood or prospects of the Rust project or its developers or users.

[managarm](https://github.com/managarm/managarm) is licensed as MIT. No dependencies were added.

> Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.
> - This requirement does not prevent part or all of this policy from being cited in an explicit contract or work agreement (e.g. to implement or maintain support for a target). This requirement exists to ensure that a developer or team responsible for reviewing and approving a target does not face any legal threats or obligations that would prevent them from freely exercising their judgment in such approval, even if such judgment involves subjective matters or goes beyond the letter of these requirements.

Understood. None of the listed maintainers are on a Rust team.

> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

Support for `std` will be provided in a future PR. Only minor changes are required, however they depend on support in the `libc` crate which will be PRed in soon.

> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

The steps needed to take are described in the documentation provided with this PR.

> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via `@)` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.
> - Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications.

Understood.

> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.
> - In particular, this may come up when working on closely related targets, such as variations of the same architecture with different features. Avoid introducing unconditional uses of features that another variation of the target may not have; use conditional compilation or runtime detection, as appropriate, to let each target run code supported by that target.

We have no indication that anything breaks due to this PR.

> Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target.

No problems here, as we target `x86_64`.

r? compiler-team
2025-08-30 07:59:16 +00:00
Esteban Küber
cb9cd8f830 On binding not present in all patterns, look at consts and unit structs/variants for suggestions
When encountering an or-pattern with a binding not available in all patterns, look for consts and unit struct/variants that have similar names as the binding to detect typos.

```
error[E0408]: variable `Ban` is not bound in all patterns
  --> $DIR/binding-typo.rs:22:9
   |
LL |         (Foo, _) | (Ban, Foo) => {}
   |         ^^^^^^^^    --- variable not in all patterns
   |         |
   |         pattern doesn't bind `Ban`
   |
help: you might have meant to use the similarly named unit variant `Bar`
   |
LL -         (Foo, _) | (Ban, Foo) => {}
LL +         (Foo, _) | (Bar, Foo) => {}
   |
```

For items that are not in the immedate scope, suggest the full path for them:

```
error[E0408]: variable `Non` is not bound in all patterns
  --> $DIR/binding-typo-2.rs:51:16
   |
LL |         (Non | Some(_))=> {}
   |          ---   ^^^^^^^ pattern doesn't bind `Non`
   |          |
   |          variable not in all patterns
   |
help: you might have meant to use the similarly named unit variant `None`
   |
LL -         (Non | Some(_))=> {}
LL +         (core::option::Option::None | Some(_))=> {}
   |
```
2025-08-30 02:54:46 +00:00
Trevor Gross
65a846ad8a Rollup merge of #145967 - Enselic:big-enum-debuginfo-span, r=wesleywiser
compiler: Include span of too huge enum with `-Cdebuginfo=2`

We have the ui test `tests/ui/limits/huge-enum.rs` to ensure we emit an error if we encounter too big enums. Before this fix, compiling the test with `-Cdebuginfo=2` would not include the span of the instantiation site, because the error is then emitted from a different code path that does not include the span.

Propagate the span to the error also in the debuginfo case, so the test passes regardless of debuginfo level. I'm sure we can propagate spans in more places, but let's start small.

## Test failure without the fix

Here is what the failure looks like if you run the test without the fix:

```
[ui] tests/ui/limits/huge-enum.rs#full-debuginfo ... F
.

failures:

---- [ui] tests/ui/limits/huge-enum.rs#full-debuginfo stdout ----
Saved the actual stderr to `/home/martin/src/rust/build/x86_64-unknown-linux-gnu/test/ui/limits/huge-enum.full-debuginfo/huge-enum.full-debuginfo.stderr`
diff of stderr:

1       error: values of the type `Option<TYPE>` are too big for the target architecture
-         --> $DIR/huge-enum.rs:17:9
-          |
-       LL |     let big: BIG = None;
-          |         ^^^
6
7       error: aborting due to 1 previous error
8

The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args limits/huge-enum.rs`
```

as can be seen, the `span` used to be missing with `debuginfo=2`.

## See also

This is one small step towards resolving rust-lang/rust#61117.

cc https://github.com/rust-lang/rust/pull/144499 which began running UI tests with `rust.debuginfo-level-tests=1`. This PR is part of preparing for increasing that to debuglevel 2.
2025-08-29 19:33:03 -05:00
Trevor Gross
ed9e767c01 Rollup merge of #145467 - Kivooeo:stabilize-strict_provenance_atomic_ptr, r=scottmcm
Stabilize `strict_provenance_atomic_ptr` feature

This closes [tracking issue](https://github.com/rust-lang/rust/issues/99108) and stabilises `AtomicPtr::{fetch_ptr_add, fetch_ptr_sub, fetch_byte_add, fetch_byte_sub, fetch_or, fetch_and, fetch_xor}`

---

EDIT: FCP completed at https://github.com/rust-lang/rust/issues/99108#issuecomment-3168260347
2025-08-29 19:33:02 -05:00
Esteban Küber
bd0ea615f7 Add test for typo in or-pattern binding 2025-08-29 20:39:36 +00:00
Vadim Petrochenkov
8930d3a750 resolve: Avoid a regression from splitting prelude into two scopes 2025-08-29 16:58:51 +03:00
Matthias Krüger
47f1df5ca3 Rollup merge of #145676 - Oneirical:uncountable-integer-9, r=jieyouxu
Rehome 30 `tests/ui/issues/` tests to other subdirectories under `tests/ui/` [#2 of Batch #2]

Part of rust-lang/rust#133895

Methodology:

1. Refer to the previously written `tests/ui/SUMMARY.md`
2. Find an appropriate category for the test, using the original issue thread and the test contents.
3. Add the issue URL at the bottom (not at the top, as that would mess up stderr line numbers)
4. Rename the tests to make their purpose clearer

Inspired by the methodology that `@Kivooeo` was using.

r? `@jieyouxu`
2025-08-29 12:37:30 +02:00
Matthias Krüger
e15744e7a4 Rollup merge of #145675 - Oneirical:uncountable-integer-8, r=jieyouxu
Rehome 30 `tests/ui/issues/` tests to other subdirectories under `tests/ui/` [#1 of Batch #2]

Part of rust-lang/rust#133895

Methodology:

1. Refer to the previously written `tests/ui/SUMMARY.md`
2. Find an appropriate category for the test, using the original issue thread and the test contents.
3. Add the issue URL at the bottom (not at the top, as that would mess up stderr line numbers)
4. Rename the tests to make their purpose clearer

Inspired by the methodology that `@Kivooeo` was using.

r? `@jieyouxu`
2025-08-29 12:37:30 +02:00
bjorn3
fc7de9979e Ensure we emit an allocator shim when only some crate types need one 2025-08-29 08:39:34 +00:00
Alice Ryhl
46727f4cb0 Stabilize file_as_c_str 2025-08-29 08:33:54 +00:00
bors
41f2b6b39e Auto merge of #145978 - Zalathar:rollup-0dzk72g, r=Zalathar
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#143713 (Add a mailmap entry for gnzlbg)
 - rust-lang/rust#144275 (implement Sum and Product for Saturating(u*))
 - rust-lang/rust#144354 (fix(std): Fix undefined reference to __my_thread_exit on QNX 8.0)
 - rust-lang/rust#145387 (Remove TmpLayout in layout_of_enum)
 - rust-lang/rust#145793 (std library: use execinfo library also on NetBSD.)
 - rust-lang/rust#145884 (Test `instrument-mcount` codegen)
 - rust-lang/rust#145947 (Add more to the `[workspace.dependencies]` section in the top-level `Cargo.toml`)
 - rust-lang/rust#145972 (fix `core::marker::Destruct` doc)
 - rust-lang/rust#145977 (tests: Ignore basic-stepping.rs on riscv64)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-29 03:40:14 +00:00
Stuart Cook
31eafafe3b Rollup merge of #145977 - CaiWeiran:basic-stepping-test, r=jieyouxu
tests: Ignore basic-stepping.rs on riscv64

Same as [PR 145745](https://github.com/rust-lang/rust/pull/145745)

r? `@lqd`
2025-08-29 12:54:13 +10:00
Caiweiran
a54567e76c tests: Ignore basic-stepping.rs on riscv64 2025-08-29 08:11:48 +00:00
Stuart Cook
4ccf8ca720 Rollup merge of #145884 - clubby789:test-mcount, r=Mark-Simulacrum
Test `instrument-mcount` codegen

Closes rust-lang/rust#92109 by testing that a call to `mcount` is actually emitted
2025-08-29 12:54:11 +10:00
bors
ef8d1d6f5b Auto merge of #145377 - ChayimFriedman2:solver-def-id, r=lcnr
Switch next solver to use a specific associated type for trait def id

The compiler just puts `DefId` in there, but rust-analyzer uses different types for each kind of item.

See [the Zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/185405-t-compiler.2Frust-analyzer/topic/Implmentating.20New.20Trait.20Solver/near/534329794). In short, it will be a tremendous help to r-a to use specific associated types, while for the solver and the compiler it's a small change. So I ported `TraitId`, as a proof of concept and it's also likely the most impactful.

r? types
2025-08-29 00:32:21 +00:00
no92
6577a0ffdb compiler: Add {x86_64,aarch64,riscv64gc}-unknown-managarm-mlibc targets
Co-authored-by: Dennis Bonke <dennis@managarm.org>
2025-08-29 00:49:29 +02:00
bors
f2824da98d Auto merge of #145970 - GuillaumeGomez:rollup-pr11qds, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#142472 (Add new `doc(attribute = "...")` attribute)
 - rust-lang/rust#145368 (CFI: Make `lto` and `linker-plugin-lto` work the same for `compiler_builtins`)
 - rust-lang/rust#145853 (Improve error messages around invalid literals in attribute arguments)
 - rust-lang/rust#145920 (bootstrap: Explicitly mark the end of a failed test's captured output)
 - rust-lang/rust#145937 (add doc-hidden to exports in attribute prelude)
 - rust-lang/rust#145965 (Move exporting of profiler and sanitizer symbols to the LLVM backend)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-28 19:57:03 +00:00
Guillaume Gomez
56c68e78dd Rollup merge of #145853 - JonathanBrouwer:fix-lit-parsing, r=jdonszelmann
Improve error messages around invalid literals in attribute arguments

r? `@jdonszelmann`

This previously created two errors, which is a bit ugly and the second one didn't add any value
Blocked on https://github.com/rust-lang/rust/pull/143193
2025-08-28 21:41:01 +02:00
Guillaume Gomez
9e4a283615 Rollup merge of #145368 - rcvalle:rust-cfi-fix-142284, r=dianqk
CFI: Make `lto` and `linker-plugin-lto` work the same for `compiler_builtins`

Fix rust-lang/rust#142284 by ensuring that `#![no_builtins]` crates can still emit bitcode when proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto) is used.
2025-08-28 21:41:01 +02:00
Guillaume Gomez
f948c79911 Rollup merge of #142472 - GuillaumeGomez:doc-attribute-attribute, r=fmease
Add new `doc(attribute = "...")` attribute

Fixes rust-lang/rust#141123.

The implementation and purpose of this new `#[doc(attribute = "...")]` attribute is very close to `#[doc(keyword = "...")]`. Which means that luckily for us, most of the code needed was already in place and `@Noratrieb` nicely wrote a first draft that helped me implement this new attribute very fast.

Now with all this said, there is one thing I didn't do yet: adding a `rustdoc-js-std` test. I added GUI tests with search results for attributes so should be fine but I still plan on adding one for it once documentation for builtin attributes will be written into the core/std libs.

You can test it [here](https://rustdoc.crud.net/imperio/doc-attribute-attribute/foo/index.html).

cc `@Noratrieb` `@Veykril`
2025-08-28 21:41:00 +02:00
Ed Page
142e25e356 fix(lexer): Don't require frontmatters to be escaped with indented fences
The RFC only limits hyphens at the beginning of lines and not if they
are indented or embedded in other content.

Sticking to that approach was confirmed by the T-lang liason at
https://github.com/rust-lang/rust/issues/141367#issuecomment-3202217544

There is a regression in error message quality which I'm leaving for
someone if they feel this needs improving.
2025-08-28 14:08:33 -05:00
Martin Nordholts
4edfeb2f60 compiler: Include span of too huge enum with -Cdebuginfo=2
We have a ui test to ensure we emit an error if we encounter too big
enums. Before this fix, compiling the test with `-Cdebuginfo=2` would
not include the span of the instantiation site, because the error is
then emitted from a different code path that does not include the span.

Propagate the span to the error also in the debuginfo case, so the test
passes regardless of debuginfo level.
2025-08-28 20:37:09 +02:00
Jonathan Brouwer
e0bdc46d94 Update uitest stderr
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-28 20:05:04 +02:00
Jonathan Brouwer
2c7dfa91b5 Add another case to the bad-lit-suffixes test
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-28 19:23:55 +02:00
bors
35d55b34bf Auto merge of #145807 - zachs18:only-consider-auto-traits-empty, r=compiler-errors
When determining if a trait has no entries for the purposes of omitting vptrs from subtrait vtables, consider its transitive supertraits' entries, instead of just its own entries.

When determining if a non-first supertrait vptr can be omitted from a subtrait vtable, check if the supertrait or any of its (transitive) supertraits have methods, instead of only checking if the supertrait itself has methods.

This fixes the soundness issue where a vptr would be omitted for a supertrait with no methods but that itself had a supertrait with methods, while still optimizing the case where the supertrait is "truly" empty (it has no own vtable entries, and none of its (transitive) supertraits have any own vtable entries).

Fixes <https://github.com/rust-lang/rust/issues/145752>

-----

Old description:

~~Treat all non-auto traits as non-empty (possibly having methods) for purposes of determining if we need to emit a vptr for a non-direct supertrait (and for new "sibling" entries after a direct or non-direct supertrait).~~

This fixes (I believe) the soundness issue, ~~but regresses vtable sizes and possibly upcasting perf in some cases when using trait hierarchies with empty non-auto traits (see `tests/ui/traits/vtable/multiple-markers.stderr`) since we use vptrs in some cases where we could re-use the vtable.~~

Fixes <https://github.com/rust-lang/rust/issues/145752>

Re-opens (not anymore) <https://github.com/rust-lang/rust/issues/114942>

Should not affect <https://github.com/rust-lang/rust/issues/131813> (i.e. the soundness issue is still fixed, ~~though the relevant vtables in the `trait Evil` example will be larger now~~)

cc implementation history <https://github.com/rust-lang/rust/pull/131864> <https://github.com/rust-lang/rust/pull/113856>

-----

~~It should be possible to check if a trait has any methods from itself *or* supertraits (instead of just from itself), but to fix the immediate soundness issue, just assume any non-auto trait could have methods. A more optimistic check can be implemented later (or if someone does it soon it could just supercede this PR 😄).~~ Done in latest push

`@rustbot` label A-dyn-trait F-trait_upcasting
2025-08-28 16:49:32 +00:00
Guillaume Gomez
f3c023433f Add ui test for unsupported doc(attribute = "...") case for attributes with namespace 2025-08-28 18:24:58 +02:00
Guillaume Gomez
75cbd05d19 Add tests for doc(attribute = "...") attribute 2025-08-28 15:56:30 +02:00
Stuart Cook
72727b1654 Rollup merge of #145941 - Urgau:int_to_ptr_transmutes-unsized, r=lcnr
Disable `integer_to_ptr_transmutes` suggestion for unsized types

This PR disables the machine-applicable `integer_to_ptr_transmutes` lint suggestion for unsized types, as [`std::ptr::with_exposed_provenance`](https://doc.rust-lang.org/std/ptr/fn.with_exposed_provenance.html) requires sized types.

We should probably mention [`std::ptr::from_raw_parts`](https://doc.rust-lang.org/std/ptr/fn.from_raw_parts.html) when it becomes stable.

Related to https://github.com/rust-lang/rust/issues/145935
2025-08-28 23:10:37 +10:00
Stuart Cook
c838117620 Rollup merge of #145928 - Darksonn:file_as_c_str, r=joshtriplett
Rename `Location::file_with_nul` to `file_as_c_str`

This renames the method to be consistent with the ongoing T-libs-api FCP found at https://github.com/rust-lang/rust/issues/141727#issuecomment-3228016708.

I did not rename the unstable feature as we are going to be stabilizing it soon anyway. This will probably break RfL, so it will require an updated commit hash for the Linux Kernel that I will add here soon.

r? `@Amanieu`
2025-08-28 23:10:35 +10:00
Stuart Cook
2fae59ac96 Rollup merge of #144864 - Muscraft:no-source-fixes, r=jieyouxu
No source fixes

This PR started as a fix for a rendering bug that [got noticed in #143661](https://github.com/rust-lang/rust/pull/143661#discussion_r2199109530), but turned into a fix for any rendering bugs related to files with no source.
- Don't add an end column separator after a file with no source
- Add column separator before secondary messages with no source
- Render continuation between no source labels

Before
```
error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
   ╭▸ $DIR/multi-suggestion.rs:17:13
   │
LL │     let _ = std::collections::HashMap();
   │             ━━━━━━━━━━━━━━━━━━━━━━━━━━━
   ╭▸ $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
   │
   ╰ note: `std::collections::HashMap` defined here
   ╰╴
note: constructor is not visible here due to private fields
   ╭▸ $SRC_DIR/alloc/src/boxed.rs:LL:COL
   │
   ╰ note: private field
   │
   ╰ note: private field
```

After
```
error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
   ╭▸ $DIR/multi-suggestion.rs:17:13
   │
LL │     let _ = std::collections::HashMap();
   │             ━━━━━━━━━━━━━━━━━━━━━━━━━━━
   ╰╴
   ╭▸ $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
   │
   ╰ note: `std::collections::HashMap` defined here
note: constructor is not visible here due to private fields
   ╭▸ $SRC_DIR/alloc/src/boxed.rs:LL:COL
   │
   ├ note: private field
   │
   ╰ note: private field
```

Note: This PR also makes it so `rustc` and `annotate-snippets` match in these cases
2025-08-28 23:10:34 +10:00
Stuart Cook
a65ed63b3b Rollup merge of #143193 - JonathanBrouwer:link_rework, r=jdonszelmann
Port `#[link]` to the new attribute parsing infrastructure

Ports `link` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197
2025-08-28 23:10:33 +10:00
bors
43a216604a Auto merge of #145949 - jhpratt:rollup-smzd7tr, r=jhpratt
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#145382 (Add assembly test for `-Zreg-struct-return` option)
 - rust-lang/rust#145746 (Fix STD build failing for target_os = "espidf")
 - rust-lang/rust#145826 (Use AcceptContext in AttribueParser::check_target)
 - rust-lang/rust#145894 (Ensure the coordinator thread terminates before its channels drop)
 - rust-lang/rust#145946 (Remove unnecessary `[dependencies.unicode-properties]` entries.)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-28 03:06:52 +00:00
Jacob Pratt
a1c543e165 Rollup merge of #145382 - winstonallo:reg-struct-return-asm-test, r=tgross35
Add assembly test for `-Zreg-struct-return` option

r? `@tgross35`

As discussed in rust-lang/rust#145309 with `@tgross35` and `@ojeda,` I added assembly tests for the `-Zreg-struct-return` option verifying that it changes the ABI from hidden pointer to register-return on x86_32.

The test covers:
- Direct struct construction, showing register return vs hidden pointer
- External function calls returning structs, showing ABI mismatch handling

Different memory layouts affect ABI mismatch handling, but register returns use the same register allocation regardless of struct field layout (apart from the fact that they use smaller registers for smaller structs, of course).

[Here](https://godbolt.org/z/dcW6rnMG3) is a compiler explorer with 2 examples. Let me know if there is anything more I could add. Since register returns only happen for structs up to the size of 2 registers, I figured testing the pivot value (8 bytes) would be most critical.
2025-08-27 21:51:52 -04:00
bors
d36f964125 Auto merge of #145877 - nikic:capture-address, r=tmiasko
Use captures(address) instead of captures(none) for indirect args

While provenance cannot be captured through these arguments, the address / object identity can.

Fixes https://github.com/rust-lang/rust/issues/137668.

r? `@ghost`
2025-08-28 00:01:22 +00:00