Commit Graph

48278 Commits

Author SHA1 Message Date
Guillaume Gomez
a9a0753e96 Rollup merge of #142740 - ada4a:is-destruct-assignment-desugaring, r=fee1-dead
Clean-up `FnCtxt::is_destruct_assignment_desugaring`

I noticed the docstring thing and fixed that; then I thought I'd rewrite the method using let-chains while I'm at it, since that seemed appropriate. But I don't feel too strongly about the second change, so let me know if I should remove it
2025-06-22 17:35:34 +02:00
Guillaume Gomez
7bed341583 Rollup merge of #142594 - mejrs:new_desugaring, r=chenyukang
Add DesugaringKind::FormatLiteral

Implements `DesugaringKind::FormatLiteral` to mark the FormatArgs desugaring of format literals. The main use for this is to stop yapping about about formatting parameters if we're not anywhere near a format literal. The other use case is to fix suggestions such as https://github.com/rust-lang/rust/issues/141350. It might also be useful for new or existing diagnostics that check whether they're in a format-like macro.

cc `@xizheyin` `@fmease`
2025-06-22 17:35:33 +02:00
Guillaume Gomez
cab65efa2e Rollup merge of #142593 - blyxyas:improve-docs-itty-bitty-change, r=compiler-errors
Add a warning to LateContext::get_def_path

Preventing anyone from doing the same error as https://github.com/rust-lang/rust-clippy/pull/15043 fixed
2025-06-22 17:35:33 +02:00
Guillaume Gomez
371426334b Rollup merge of #142458 - oli-obk:dyn-incompat, r=compiler-errors
Merge unboxed trait object error suggestion into regular dyn incompat error

Another hir-walker removed from the well-formed queries. This error was always a duplicate of another, but it was able to provide more information because it could invoke `is_dyn_compatible` without worrying about cycle errors. That's also the reason we can't put the error directly into hir_ty_lowering when lowering a `dyn Trait` within an associated item signature. So instead I packed it into the error handling of wf obligation checking.
2025-06-22 17:35:32 +02:00
Urgau
188023a93c Don't suggest changing a method inside a expansion 2025-06-22 17:08:54 +02:00
Urgau
6ffd0e6c23 Address review comments 2025-06-22 16:45:16 +02:00
Martin Liska
75674e2c2a cranelift: fix target feature name type: "fxsr" 2025-06-22 16:32:54 +02:00
bors
c2ec7532ee Auto merge of #142706 - fee1-dead-contrib:push-zsznlqyrzsqo, r=oli-obk
completely deduplicate `Visitor` and `MutVisitor`

r? oli-obk

This closes rust-lang/rust#127615.

### Discussion

> * Give every `MutVisitor::visit_*` method a corresponding `flat_map_*` method.

Not every AST node exists in a location where they can be mapped to multiple instances of themselves. Not every AST node exists in a location where they can be removed from existence (e.g. `filter_map_expr`). I don't think this is doable.

> * Give every `MutVisitor::visit_*` method a corresponding `Visitor` method and vice versa

The only three remaining method-level asymmetries after this PR are `visit_stmt` and `visit_nested_use_tree` (only on `Visitor`) and `visit_span` (only on `MutVisitor`).

`visit_stmt` doesn't seem applicable to `MutVisitor` because `walk_flat_map_stmt_kind` will ask `flat_map_item` / `filter_map_expr` to potentially turn a single `Stmt` to multiple based on what a visitor wants. So only using `flat_map_stmt` seems appropriate.

`visit_nested_use_tree` is used for `rustc_resolve` to track stuff. Not useful for `MutVisitor` for now.

`visit_span` is currently not used for `MutVisitor` already, it was just kept in case we want to revive rust-lang/rust#127241. cc `@cjgillot` maybe we could remove for now and re-insert later if we find a use-case? It does involve some extra effort to maintain.

* Remaining FIXMEs

`visit_lifetime` has an extra param for `Visitor` that's not in `MutVisitor`. This is again something only used by `rustc_resolve`. I think we can keep that symmetry for now.
2025-06-22 14:03:44 +00:00
Jonathan Brouwer
b24df42488 Port #[must_use] to new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-22 14:51:58 +02:00
Tomasz Miąsko
c353539109 Leave from CopyProp early when there are no replacements 2025-06-22 14:30:23 +02:00
Ada Alakbarova
fdb76e2296 Turn a comment that looks like a docstring into a docstring
rewrite using let-chains
2025-06-22 13:37:14 +02:00
klensy
2ddbe39bfb remove allow(dead_code) leftovers from serial/parallel compiler 2025-06-22 13:05:09 +03:00
bors
a30f1783fe Auto merge of #142864 - jhpratt:rollup-mf0yq8o, r=jhpratt
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#140254 (Pass -Cpanic=abort for the panic_abort crate)
 - rust-lang/rust#142600 (Port `#[rustc_pub_transparent]` to the new attribute system)
 - rust-lang/rust#142617 (improve search graph docs, reset `encountered_overflow` between reruns)
 - rust-lang/rust#142747 (rustdoc_json: conversion cleanups)
 - rust-lang/rust#142776 (All HIR attributes are outer)
 - rust-lang/rust#142800 (integer docs: remove extraneous text)
 - rust-lang/rust#142841 (Enable fmt-write-bloat for Windows)
 - rust-lang/rust#142845 (Enable textrel-on-minimal-lib for Windows)
 - rust-lang/rust#142850 (remove asm_goto feature annotation, for it is now stabilized)
 - rust-lang/rust#142860 (Notify me on tidy changes)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-22 09:49:14 +00:00
mejrs
b1d18129d1 Implement DesugaringKind::FormatLiteral 2025-06-22 10:58:25 +02:00
Jacob Pratt
bf63acfd35 Rollup merge of #142776 - dtolnay:hirattrstyle2, r=jdonszelmann
All HIR attributes are outer

Fixes https://github.com/rust-lang/rust/issues/142649. Closes https://github.com/rust-lang/rust/pull/142759.

All HIR attributes, including parsed and not yet parsed, will now be rendered as outer attributes by `rustc_hir_pretty`. The original style of the corresponding AST attribute(s) is not relevant for pretty printing, only for diagnostics.

r? ````@jdonszelmann````
2025-06-22 08:49:05 +02:00
Jacob Pratt
9c09dd51f9 Rollup merge of #142617 - lcnr:search_graph-3, r=compiler-errors
improve search graph docs, reset `encountered_overflow` between reruns

I think this shouldn't really matter for now. It will be more relevant for my current rework as we otherwise cannot partially reevaluate the root goal in case there has been overflow during the prervious iteration.

r? ````@BoxyUwU````
2025-06-22 08:49:04 +02:00
Jacob Pratt
431a822938 Rollup merge of #142600 - GrigorenkoPV:attributes/rustc_pub_transparent, r=jdonszelmann
Port `#[rustc_pub_transparent]` to the new attribute system

Very similar to rust-lang/rust#142498.

This is a part of rust-lang/rust#131229, so
r? ````@jdonszelmann````

---

For reference, the `#[rustc_pub_transparent]` attribute was created by me back in rust-lang/rust#129487.

As mentioned back in https://github.com/rust-lang/rust/pull/129487#discussion_r1730120385, this attribute does not check that it is applied to an ADT, because it checks that `#[repr(transparent)]` is also applied to the same item, which, in turn, should check for ADT.
2025-06-22 08:49:04 +02:00
bors
9972ebfcc2 Auto merge of #142675 - tmiasko:preserve-cache, r=oli-obk
Preserve caches in a call to shrink_to_fit

A small follow up to rust-lang/rust#142542.
2025-06-22 06:49:02 +00:00
Camille GILLOT
8e9552a6b5 Add a few inline directives in rustc_serialize. 2025-06-21 23:54:16 +00:00
Mark Rousskov
1f40573507 Skip collecting no-op DropGlue in vtables
Since 122662 this no longer gets used in vtables, so we're safe to fully
drop generating these empty functions. Those are eventually cleaned up
by LLVM, but it's wasteful to produce them in the first place.

This also adds a missing test for fn-ptr casts, which do still need to
generate no-op drop glue. It's possible a future optimization could
point all of those at the same drop glue (e.g., for *mut ()) rather than
for each separate type, but that would require extra work for CFI and
isn't particularly easy to do anyway.
2025-06-21 18:59:36 -04:00
Folkert de Vries
a123a36a1f centralize -Zmin-function-alignment logic 2025-06-22 00:47:10 +02:00
bors
d4e1159b8c Auto merge of #142546 - cjgillot:reachable-jump, r=compiler-errors
Only traverse reachable blocks in JumpThreading.

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

We only compute loop headers for reachable blocks. We shouldn't try to perform an opt on unreachable blocks anyway.
2025-06-21 18:54:29 +00:00
Pavel Grigorenko
d86d3f3742 Port #[rustc_pub_transparent] to the new attribute system 2025-06-21 21:52:25 +03:00
David Tolnay
6729b667ce All HIR attributes are outer 2025-06-21 11:11:34 -07:00
David Tolnay
86f40acce3 Remove style() from AttributeExt trait 2025-06-21 11:09:13 -07:00
David Tolnay
e51c37c34c Add AttributeExt::doc_resolution_scope 2025-06-21 11:09:12 -07:00
Jana Dönszelmann
c693bc268a Rollup merge of #142698 - tgross35:concat-byte-cstr-diag, r=petrochenkov
Improve diagnostics for `concat_bytes!` with C string  literals

Use the same error as other invalid types for `concat_bytes!`, rather
than using `ConcatCStrLit` from `concat!`. Also add more information
with a note about why this doesn't work, and a suggestion to use a
null-terminated byte string instead.
2025-06-21 15:32:06 +02:00
Jana Dönszelmann
6ed5d48cec Rollup merge of #142690 - petrochenkov:expnoparam, r=compiler-errors
expand: Remove some unnecessary generic parameters
2025-06-21 15:32:06 +02:00
Jana Dönszelmann
cd857f4bef Rollup merge of #142539 - GrigorenkoPV:attributes/may_dangle, r=jdonszelmann
Port `#[may_dangle]` to the new attribute system

Very similar to rust-lang/rust#142498.

This is a part of rust-lang/rust#131229, so
r? `@jdonszelmann`
2025-06-21 15:32:05 +02:00
Urgau
1b5ec3fa1d Add emit_span_lint_lazy to lazily create LintDiagnostic structs 2025-06-21 13:40:05 +02:00
Urgau
8b88265133 Lazily collect NonUpperCaseGlobalSubTool diagnostics 2025-06-21 13:26:57 +02:00
Matthias Krüger
4e87031f2e Rollup merge of #142804 - zachs18:rename-layouts-to-layoutdata-in-comments, r=saethlin
Rename `LayoutS` to `LayoutData` in comments

`LayoutS` was renamed to `LayoutData`, but some comments in the compiler were not changed. This updates comments in the compiler (and one section of commented-out code in rust-analyzer) to refer to `LayoutData` instead of `LayoutS`.

cc <https://github.com/rust-lang/rust/pull/132252>, `@workingjubilee`
2025-06-21 10:53:28 +02:00
Matthias Krüger
6a49a35109 Rollup merge of #142801 - compiler-errors:gen-blocks, r=oli-obk
Use gen blocks in the compiler instead of `from_coroutine`

r? oli-obk
2025-06-21 10:53:28 +02:00
Matthias Krüger
24f797ed84 Rollup merge of #142787 - samueltardieu:diag-items-for-clippy, r=Manishearth,Urgau
Add diagnostic items for Clippy

Clippy still uses some paths to access items from the standard library. Adding the missing diagnostic items allows removing the last remaining paths.

Closes rust-lang/rust-clippy#5393
2025-06-21 10:53:26 +02:00
Matthias Krüger
504092f415 Rollup merge of #142597 - folkertdev:abi-cannot-be-called, r=workingjubilee
error on calls to ABIs that cannot be called

We recently added `extern "custom"`, which cannot be called using a rust call expression. But there are more ABIs that can't be called in that way, because the call does not semantically make sense.

More details are in https://github.com/rust-lang/rust/issues/140566#issuecomment-2846205457

r? `@workingjubilee`

try-job: x86_64-gnu-llvm-19-3
2025-06-21 10:53:25 +02:00
Trevor Gross
432c7d0235 Rollup merge of #142765 - workingjubilee:more-abimap-docs, r=compiler-errors
rustc_target: document public AbiMap-related fn and variants
2025-06-20 23:25:58 -04:00
Trevor Gross
44d50f9acf Rollup merge of #142716 - nnethercote:adjust-with_generic_param_rib, r=petrochenkov
Adjust `with_generic_param_rib`.

Currently all of its call sites construct a `LifetimeRibKind::Generics` value, which `with_generic_param_rib` then deconstructs (and panics if it's a different `LifetimeRibKind` variant).

This commit makes the code simpler and shorter: the call sites just pass in the three values and `with_generic_param_rib` constructs the `LifetimeRibKind::Generics` value from them.

r? `@petrochenkov`
2025-06-20 23:25:57 -04:00
Trevor Gross
4455d1e57b Rollup merge of #142571 - cjgillot:borrowed-classes, r=oli-obk
Reason about borrowed classes in CopyProp.

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

The current implementation of `CopyProp` avoids unifying two borrowed locals, as this would change the result of address comparison.

However, the implementation was inconsistent with the general algorithm, which identifies equivalence classes of locals and then replaces all locals by a single representative of their equivalence class.

This PR fixes it by forbidding the unification of two *classes* if any of those contain a borrowed local.
2025-06-20 23:25:55 -04:00
Trevor Gross
c93fac7d64 Rollup merge of #142485 - mu001999-contrib:dead-code/adt-pattern, r=petrochenkov
Marks ADT live if it appears in pattern

Marks ADT live if it appears in pattern, it implies the construction of the ADT.
1. Then we can detect unused private ADTs impl `Default`, without special logics for `Default` and other std traits.
2. We can also remove `rustc_trivial_field_reads` on `Default`, and the logic in `should_ignore_item` (introduced by rust-lang/rust#126302).

Fixes rust-lang/rust#120770

Extracted from rust-lang/rust#128637.
r? `@petrochenkov`
2025-06-20 23:25:55 -04:00
Trevor Gross
8751016e20 Rollup merge of #142476 - dtolnay:attrbinop, r=fmease
Insert parentheses around binary operation with attribute

Fixes the bug found by `@fmease` in https://github.com/rust-lang/rust/pull/134661#pullrequestreview-2538983253.

Previously, `-Zunpretty=expanded` would expand this program as follows:

```rust
#![feature(stmt_expr_attributes)]
#![allow(unused_attributes)]

macro_rules! group {
    ($e:expr) => {
        $e
    };
}

macro_rules! extra {
    ($e:expr) => {
        #[allow()] $e
    };
}

fn main() {
    let _ = #[allow()] 1 + 1;
    let _ = group!(#[allow()] 1) + 1;
    let _ = 1 + group!(#[allow()] 1);
    let _ = extra!({ 0 }) + 1;
    let _ = extra!({ 0 } + 1);
}
```

```console
let _ = #[allow()] 1 + 1;
let _ = #[allow()] 1 + 1;
let _ = 1 + #[allow()] 1;
let _ = #[allow()] { 0 } + 1;
let _ = #[allow()] { 0 } + 1;
```

The first 4 statements are the correct expansion, but the last one is not. The attribute is supposed to apply to the entire binary operation, not only to the left operand.

After this PR, the 5th statement will expand to:

```console
let _ = #[allow()] ({ 0 } + 1);
```

In the future, as some subset of `stmt_expr_attributes` approaches stabilization, it is possible that we will need to do parenthesization for a number of additional cases depending on the outcome of https://github.com/rust-lang/rust/issues/127436. But for now, at least this PR makes the pretty-printer align with the current behavior of the parser.

r? fmease
2025-06-20 23:25:54 -04:00
Trevor Gross
7b355110df Rollup merge of #142384 - celinval:chores-rayon-mv, r=oli-obk
Bringing `rustc_rayon_core` in tree as `rustc_thread_pool`

This PR moves [`rustc_rayon_core`](https://github.com/rust-lang/rustc-rayon/tree/5fadf44/rayon-core) from commit `5fadf44` as suggested in [this zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/187679-t-compiler.2Fparallel-rustc/topic/Bringing.20.60rustc_rayon_core.60.20in.20tree). I tried to split the work into separate commits so it is easy to review. The first commit is a simple copy and paste from the fork, and subsequent changes were made to use the new crate and to ensure the new crate complies with different format and lint expectations.

**Call-out:** I was also wondering if I need to make any further changes to accommodate licensing requirements.

r? oli-obk
2025-06-20 23:25:54 -04:00
bors
15c701fbc9 Auto merge of #142794 - tgross35:rollup-iae7okj, r=tgross35
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#142331 (Add `trim_prefix` and `trim_suffix` methods for both `slice` and `str` types.)
 - rust-lang/rust#142491 (Rework #[cold] attribute parser)
 - rust-lang/rust#142494 (Fix missing docs in `rustc_attr_parsing`)
 - rust-lang/rust#142495 (Better template for `#[repr]` attributes)
 - rust-lang/rust#142497 (Fix random failure when JS code is executed when the whole file was not read yet)
 - rust-lang/rust#142575 (Ensure copy* intrinsics also perform the static self-init checks)
 - rust-lang/rust#142650 (Refactor Translator)
 - rust-lang/rust#142713 (mbe: Refactor transcription)
 - rust-lang/rust#142755 (rustdoc: Remove `FormatRenderer::cache`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-20 23:09:48 +00:00
David Tolnay
12a855d2c8 Insert parentheses around binary operation with attribute 2025-06-20 13:49:12 -07:00
Cameron Steffen
26a6b55717 Recover from semicolon field separator 2025-06-20 15:30:09 -05:00
Pavel Grigorenko
045faa8c5c Port #[may_dangle] to the new attribute system 2025-06-20 22:39:14 +03:00
Michael Goulet
48060c97c8 Use gen blocks in the compiler instead of from_coroutine 2025-06-20 18:57:52 +00:00
Michael Goulet
582c2df9dd Collapse Analysis|Borrowck|PostBorrowckAnalysis when there are no opaques 2025-06-20 18:57:00 +00:00
Jakub Beránek
e7cc4ec8f7 Rollup merge of #142769 - jdonszelmann:remove-useless-new-method, r=tgross35
remove equivalent new method on context

Noticed the two had converged so much they literally became equivalent. So one could go hehe
2025-06-20 20:03:25 +02:00
Jakub Beránek
31663db896 Rollup merge of #142767 - nnethercote:symbol-cleanups, r=petrochenkov
Some symbol and PathRoot cleanups

I'm looking into unifying how we join and print paths. Here are some preliminary cleanups.

r? ``@petrochenkov``
2025-06-20 20:03:24 +02:00
Jakub Beránek
065a5fb225 Rollup merge of #142715 - folkertdev:fn-align-corrections, r=jdonszelmann
correct template for `#[align]` attribute

Tracking issue: https://github.com/rust-lang/rust/issues/82232
related: https://github.com/rust-lang/rust/pull/142507

I didn't fully understand what `template!` did, clearly. An empty `#[align]` attribute was still rejected later, but without this change it does get suggested in certain cases.

I've also updated some outdated references to `#[repr(align)]` on functions.

r? ``@jdonszelmann``
2025-06-20 20:03:21 +02:00