Commit Graph

48977 Commits

Author SHA1 Message Date
Pierre Tardy
bc14ad38a3 strip prefix of temporary file names when it exceeds filesystem name length limit
When doing lto, rustc generates filenames that are concatenating many information.

In the case of this testcase, it is concatenating crate name and rust file name, plus some hash, and the extension.
In some other cases it will concatenate even more information reducing the maximum effective crate name to about 110 chars on linux filesystems where
filename max length is 255

This commit is ensuring that the temporary file names are limited in size, while still reasonabily ensuring the unicity (with hashing of the stripped part)
2025-08-10 15:50:40 +02:00
bors
ec7c026125 Auto merge of #144863 - cjgillot:live-or-dead, r=Urgau
Simplify dead code lint

This PR scratches a few itches I had when looking at that code.

The perf improvement comes from keeping the `scanned` set through several marking phases. This pretty much divides by 2 the number of HIR traversals.
2025-08-05 18:10:21 +00:00
Samuel Tardieu
5c11681820 Rollup merge of #144920 - compiler-errors:span-arg, r=lqd
Dont print arg span in MIR dump for tail call

r? WaffleLapkin

This makes the MIR dump for tail call terminators consistent w/ regular calls.
2025-08-05 03:51:42 +02:00
Samuel Tardieu
58a7b873cf Rollup merge of #144890 - WaffleLapkin:project_fields, r=lcnr
Add `InterpCx::project_fields`

I was hoping for a much bigger improvement and this is lukewarm at best ^^'

Still, I think this makes sense.
2025-08-05 03:51:40 +02:00
Samuel Tardieu
7ad5281f3b Rollup merge of #144877 - Zalathar:coverage-various, r=lcnr
coverage: Various small cleanups

This PR is a collection of small coverage-related changes that I accumulated while working towards other coverage improvements.

Each change should hopefully be fairly straightforward.
2025-08-05 03:51:39 +02:00
Samuel Tardieu
149ee59876 Rollup merge of #144866 - JonathanBrouwer:should_emit_fix, r=jdonszelmann
Remove `SHOULD_EMIT_LINTS` in favor of `should_emit`

r? ``@jdonszelmann``
2025-08-05 03:51:37 +02:00
Samuel Tardieu
eee8d775fe Rollup merge of #144817 - WaffleLapkin:reject-referety, r=Urgau
Properly reject tail calls to `&FnPtr` or `&FnDef`

Fixes rust-lang/rust#144795
2025-08-05 03:51:36 +02:00
Samuel Tardieu
a1e41a0227 Rollup merge of #144776 - nnethercote:Printer-cleanups, r=cjgillot
`Printer` cleanups

The trait `Printer` is implemented by six types, and the sub-trait `PrettyPrinter` is implemented by three of those types. The traits and the impls are complex and a bit of a mess. This PR starts to clean them up.

r? ``@davidtwco``
2025-08-05 03:51:34 +02:00
Samuel Tardieu
4cb0ebd24f Rollup merge of #144741 - ShoyuVanilla:tilde-const-in-block, r=fee1-dead
fix: Error on illegal `[const]`s inside blocks within legal positions

Fixes rust-lang/rust#132067

I initially considered moving `[const]` validations to `rustc_ast_lowering`, but that approach would require adding constness information to `AssocCtxt`, which introduces significant changes - especially within `rustc_expand` - just to support a single use case here:

3fb1b53a9d/compiler/rustc_ast_passes/src/ast_validation.rs (L1596-L1610)

Instead, I believe it's sufficient to simply "reset" `[const]` allowness whenever we enter a new block.
2025-08-05 03:51:34 +02:00
Camille GILLOT
d0da6ca110 Update doc-comment. 2025-08-04 23:02:27 +00:00
Camille GILLOT
e0a89c4b14 Simplify maybe_record_as_seed. 2025-08-04 23:00:45 +00:00
Michael Goulet
878acaa795 Dont print arg span in MIR dump for tail call 2025-08-04 18:35:43 +00:00
Waffle Lapkin
cf7b67420b add project_fields helper function 2025-08-04 11:34:46 +02:00
Guillaume Gomez
21bd67796e Merge commit '482e8540a1b757ed7bccc2041c5400f051fdb01e' into subtree-update_cg_gcc_2025-08-04 2025-08-04 10:49:43 +02:00
Waffle Lapkin
e3ed3e0f1c small refactor of InterpResult
- don't need type alias to default type argument
- `Residual` impl allows to use more std APIs (like `<[T; N]>::try_map`)
2025-08-04 10:08:01 +02:00
Waffle Lapkin
8b65f3d0e8 properly reject tail calls to &FnPtr or &FnDef 2025-08-04 09:09:49 +02:00
Waffle Lapkin
4f94bbf13d drive-by cleanup: fix outdated documentation 2025-08-04 09:06:02 +02:00
Stuart Cook
7307dc0ca1 Rollup merge of #144694 - compiler-errors:with-self-ty, r=SparrowLii
Distinguish prepending and replacing self ty in predicates

There are two kinds of functions called `with_self_ty`:
1. Prepends the `Self` type onto an `ExistentialPredicate` which lacks it in its internal representation.
2. Replaces the `Self` type of an existing predicate, either for diagnostics purposes or in the new trait solver when normalizing that self type.

This PR distinguishes these two because I often want to only grep for one of them. Namely, let's call it `with_replaced_self_ty` when all we're doing is replacing the self type.
2025-08-04 14:58:09 +10:00
Zalathar
b37c214ec2 coverage: Represent CovmapVersion as an enum
Using an enum here was historically not worth the extra hassle, but now we can
lean on `#[derive(TryFromU32)]` to hide most of the boilerplate.
2025-08-04 13:48:41 +10:00
Zalathar
f496e83fe9 coverage: Simplify access to debug/testing -Zcoverage-options flags 2025-08-04 13:48:41 +10:00
Zalathar
fb39d3ed88 coverage: Push async special case down into extract_refined_covspans 2025-08-04 13:48:41 +10:00
Zalathar
51e62a09a3 coverage: Remove -Zcoverage-options=no-mir-spans
This flag turned out to be less useful than anticipated, and interferes with
work towards expansion support.
2025-08-04 13:48:40 +10:00
Zalathar
16843ce427 coverage: Hoist counter_for_bcb out of its loop
Having this helper function in the loop was confusing, because it doesn't rely
on anything that changes between loop iterations.
2025-08-04 11:55:40 +10:00
Zalathar
33706fc17f coverage: Include an Instance in CovfunRecord for debug messages 2025-08-04 11:55:25 +10:00
Stuart Cook
2105044784 Rollup merge of #144746 - petrochenkov:extpreltidy, r=b-naber
resolve: Cleanups and micro-optimizations to extern prelude

This is what can be done without changing the structure of `ExternPreludeEntry`, like in https://github.com/rust-lang/rust/pull/144737.

See individual commits for details.
2025-08-04 11:24:39 +10:00
Stuart Cook
0225f8b09c Rollup merge of #144706 - zachs18:fix-144661, r=RalfJung
Do not give function allocations alignment in consteval and Miri.

We do not yet have a (clear and T-lang approved) design for how `#[align(N)]` on functions should affect function pointers' addresses on various platforms, so for now do not give function pointers alignment in consteval and Miri.

----

Old summary:

Not a full solution to <https://github.com/rust-lang/rust/issues/144661>, but fixes the immediate issue by making function allocations all have alignment 1 in consteval, ignoring `#[rustc_align(N)]`, so the compiler doesn't know if any offset other than 0 is non-null.

A more "principlied" solution would probably be to make function pointers to `#[instruction_set(arm::t32)]` functions be at offset 1 of an align-`max(2, align attribute)` allocation instead of at offset 0 of their allocation during consteval, and on wasm to either disallow `#[align(N)]` where N > 1, or to pad the function table such that the function pointer of a `#[align(N)]` function is a multiple of `N` at runtime.
2025-08-04 11:24:39 +10:00
Stuart Cook
2a947a0efa Rollup merge of #144322 - Urgau:dangling-ptr-from-locals, r=oli-obk
Add lint against dangling pointers from local variables

## `dangling_pointers_from_locals`

*warn-by-default*

The `dangling_pointers_from_locals` lint detects getting a pointer to data of a local that will be dropped at the end of the function.

### Example

```rust
fn f() -> *const u8 {
    let x = 0;
    &x // returns a dangling ptr to `x`
}
```

```text
warning: a dangling pointer will be produced because the local variable `x` will be dropped
  --> $DIR/dangling-pointers-from-locals.rs:10:5
   |
LL | fn simple() -> *const u8 {
   |                --------- return type of the function is `*const u8`
LL |     let x = 0;
   |         - `x` is defined inside the function and will be drop at the end of the function
LL |     &x
   |     ^^
   |
   = note: pointers do not have a lifetime; after returning, the `u8` will be deallocated at the end of the function because nothing is referencing it as far as the type system is concerned
   = note: `#[warn(dangling_pointers_from_locals)]` on by default
```

### Explanation

Returning a pointer from a local value will not prolong its lifetime, which means that the value can be dropped and the allocation freed while the pointer still exists, making the pointer dangling.

If you need stronger guarantees, consider using references instead, as they are statically verified by the borrow-checker to never dangle.

------

This is related to GitHub codeql [CWE-825](https://github.com/github/codeql/blob/main/rust/ql/src/queries/security/CWE-825/AccessAfterLifetimeBad.rs) which shows examples of such simple miss-use.

It should be noted that C compilers warns against such patterns even without `-Wall`, https://godbolt.org/z/P7z98arrc.

------

`@rustbot` labels +I-lang-nominated +T-lang
cc `@traviscross`
r? compiler
2025-08-04 11:24:36 +10:00
Nicholas Nethercote
cc62d55298 Avoid some code duplication.
`print_binder` can call `wrap_binder`.
2025-08-04 08:18:28 +10:00
Samuel Tardieu
018c172b22 Rollup merge of #144851 - WaffleLapkin:instrinsic-deny, r=compiler-errors,scottmcm
Forbid tail calling intrinsics

There is only one intrinsic that can be called on stable, as far as I can find, (`transmute`). And in general tail calling intrinsics doesn't make much sense.

Alternative to rust-lang/rust#144815 (and thus closes rust-lang/rust#144815)
Fixes https://github.com/rust-lang/rust/issues/144806

r? ``@scottmcm``
2025-08-03 21:57:02 +02:00
Samuel Tardieu
621a8326db Rollup merge of #144829 - Kivooeo:strip-flag, r=WaffleLapkin
Use full flag name in strip command for Darwin

Darwin always uses `rust-objcopy` which supports long-form flags

Solaris unchanged due to not having support for `--discard-all` and only `-x`

fixes https://github.com/rust-lang/rust/issues/135038

r? ````@WaffleLapkin```` (since bot will ping you anyway, feel free to reroll)
2025-08-03 21:57:00 +02:00
Samuel Tardieu
c7f248186b Rollup merge of #144824 - Kivooeo:update-links, r=Noratrieb
Updated test links in compiler

Updated test links since a bunch of tests got moved around from the top level recently

r? compiler
2025-08-03 21:57:00 +02:00
Samuel Tardieu
5b751d75b4 Rollup merge of #144822 - Zalathar:hash-owner-nodes, r=compiler-errors
Return a struct with named fields from `hash_owner_nodes`

While looking through this code for other reasons, I noticed a nice opportunity to return a struct with named fields instead of a tuple. The first patch also introduces an early-return to flatten the rest of `hash_owner_nodes`.

There are further changes that could potentially be made here (renaming things, `Option<Hashes>` instead of optional fields), but I'm not deeply familiar with this code so I didn't want to disturb the calling code too much.
2025-08-03 21:56:59 +02:00
Samuel Tardieu
7100b2deec Rollup merge of #144816 - Noratrieb:e0562-impl-trait, r=WaffleLapkin
Update E0562 to account for the new impl trait positions

fixes rust-lang/rust#142683
2025-08-03 21:56:58 +02:00
Samuel Tardieu
f3297d8fd3 Rollup merge of #144808 - Veykril:push-uttkuyswqnzt, r=compiler-errors
`Interner` arg to `EarlyBinder` does not affect auto traits

Conceptually `EarlyBinder` does not contain an `Interner` so it shouldn't tell Rust it does via `PhantomData`. This is necessary for rust-analyzer as it stores `EarlyBinder`s in query results which require `Sync`, placing restrictions on our interner setup.

r? compiler-errors
2025-08-03 21:56:58 +02:00
Samuel Tardieu
3823f0bc07 Rollup merge of #144738 - bjorn3:remove_omit_gdb_pretty_printer_section, r=jieyouxu
Remove the omit_gdb_pretty_printer_section attribute

Disabling loading of pretty printers in the debugger itself is more reliable. Before this commit the .gdb_debug_scripts section couldn't be included in dylibs or rlibs as otherwise there is no way to disable the section anymore without recompiling the entire standard library.
2025-08-03 21:56:56 +02:00
Samuel Tardieu
531486e095 Rollup merge of #142678 - BoxyUwU:gai_cleanup, r=nnethercote
Misc cleanups of `generic_arg_infer` related HIR logic

r? ````@nnethercote````
2025-08-03 21:56:54 +02:00
Jonathan Brouwer
f92934f43a Remove SHOULD_EMIT_LINTS in favor of should_emit 2025-08-03 21:48:23 +02:00
Waffle Lapkin
c539890ae6 forbid tail calling intrinsics 2025-08-03 21:21:39 +02:00
Shoyu Vanilla
7d78968bd0 fix: Error on illegal [const]s inside blocks within legal positions 2025-08-04 01:48:28 +09:00
bors
f34ba774c7 Auto merge of #144732 - lcnr:ignore-shadowed-impls, r=compiler-errors
dont assemble shadowed impl candidates

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/109.

I've originally intended to fix this by supporting lazy reevaluation when rerunning cycles. This ended up being really difficult, see https://github.com/lcnr/search_graph for my notes used while working on this. It is also insufficient for the `rayon-hang-2.rs` test as we end up with goals which we need to rerun for all combinations of provisional results. While landing such an optimization in the future may still be desirable, it is very difficult and insufficient to fix these hangs. Also see the relevant [zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/rustc-rayon.20hang/near/527850058).

I was previously opposed to avoiding assembling shadowed impls as it may prevent future improvements in this area, cc rust-lang/rust#141226. Going to track this and the reasoning behind it in https://github.com/rust-lang/trait-system-refactor-initiative/issues/226.

r? `@BoxyUwU` `@compiler-errors`
2025-08-03 15:33:31 +00:00
Nicholas Nethercote
2434d8cecf Remove unused arg from path_append_impl.
None of the impls use it.
2025-08-03 19:58:59 +10:00
Nicholas Nethercote
03dab500a2 Remove p!.
It's a cryptic macro that makes some things slightly more concise in
`PrettyPrinter`. E.g. if you declare `define_scope_printer!(p)` in a
scope you can then call `p! to get these transformations:
```
p!("foo");         -->  write!(p, "foo")?;
p!(print(ty));     -->  ty.print(p)?;
p!(method(args));  -->  p.method(args)?;
```
You can also chain calls, e.g.:
```
p!("foo", print(ty));  -->  write!(p, "foo")?; ty.print(p)?;
```
Ultimately this doesn't seem worth it. The macro definition is hard to
read, the call sites are hard to read, `define_scope_printer!` is pretty
gross, and the code size reductions are small. Tellingly, many normal
`write!` and `print` calls are sprinkled throughout the code, probably
because people have made modifications and didn't want to use or
understand how to use `p!`.

This commit removes it.
2025-08-03 19:58:56 +10:00
Nicholas Nethercote
03bc1be8dd Simplify SymbolMangler::print_type.
`Bound`/`Placeholder`/`Infer`/`Error` shouldn't occur, so we can handle
them in the second exhaustive `match`, and ignore them in the first
non-exhaustive `match`.
2025-08-03 19:58:00 +10:00
Nicholas Nethercote
1698c8e322 Rename Printer variables.
Currently they are mostly named `cx`, which is a terrible name for a
type that impls `Printer`/`PrettyPrinter`, and is easy to confuse with
other types like `TyCtxt`. This commit changes them to `p`. A couple of
existing `p` variables had to be renamed to make way.
2025-08-03 19:58:00 +10:00
Nicholas Nethercote
e7d6a0776b Remove type_name::AbsolutePathPrinter::comma_sep.
It's equivalent to the default `PrettyPrinter::comma_sep`.
2025-08-03 19:58:00 +10:00
Nicholas Nethercote
bd0a308ca2 Inline and remove two FmtPrinter methods.
They each have a single call site.
2025-08-03 19:58:00 +10:00
Nicholas Nethercote
df524163be Mark Printer methods as unreachable where appropriate.
This helps me understand the structure of the code a lot.

If any of these are actually reachable, we can put the old code back,
add a new test case, and we will have improved our test coverage.
2025-08-03 19:58:00 +10:00
bors
7cd950546b Auto merge of #144704 - compiler-errors:explode-wf, r=lcnr
expand WF obligations when checking method calls

Don't wrap a bunch of signatures in `FnPtr` then check their WF; instead, check the WFness of each input/output separately.

This is useful for the new trait solver, since because we stall on root obligations we end up needing to repeatedly recompute the WFness of possibly very large function signature types if it ends up bottoming out in ambiguity.

This may also give us more chances to hit the WF fast path for certain types like built-ins.

Finally, this just seems conceptually correct to do. There's nothing conceptually that suggests that wrapping the function signature in an fn pointer makes sense at all to do; I'm guessing that it was just convenient so that we didn't have to register WF obligations in a loop, but it doesn't affect the readability of this code at all.
2025-08-03 09:29:54 +00:00
bors
da19b9d24c Auto merge of #144677 - nnethercote:bound-const-handling, r=lcnr
Improve bound const handling

A few changes to make const handling more similar to type handling.

r? `@compiler-errors` -errors
2025-08-03 05:26:43 +00:00
Camille GILLOT
effc509b40 Simplify lint emission. 2025-08-03 02:48:58 +00:00