Commit Graph

48471 Commits

Author SHA1 Message Date
bors
0fb279be1d Auto merge of #143867 - fmease:rollup-5tll6m9, r=fmease
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#143776 (std: move NuttX to use arc4random for random number generation)
 - rust-lang/rust#143778 (Some const_trait_impl test cleanups)
 - rust-lang/rust#143782 (Disambiguate between rustc vs std having debug assertions in `run-make-support` and `run-make` tests)
 - rust-lang/rust#143791 (Update sysinfo version to `0.36.0`)
 - rust-lang/rust#143796 (Fix ICE for parsed attributes with longer path not handled by CheckAttribute)
 - rust-lang/rust#143798 (Remove format short command trait)
 - rust-lang/rust#143803 (New tracking issues for const_ops and const_cmp)
 - rust-lang/rust#143814 (htmldocck: better error messages for some negative directives)
 - rust-lang/rust#143817 (Access `wasi_sdk_path` instead of reading environment variable in bootstrap)
 - rust-lang/rust#143822 (./x test miri: fix cleaning the miri_ui directory)
 - rust-lang/rust#143823 ([COMPILETEST-UNTANGLE 5/N] Test mode adjustments and other assorted cleanups)
 - rust-lang/rust#143841 (Label clippy changes with `T-clippy`)

Failed merges:

 - rust-lang/rust#143850 (Compiletest: Simplify {Html,Json}DocCk directive handling)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-13 08:24:04 +00:00
Jana Dönszelmann
a5ab6829c6 warn on align on fields to avoid breaking changes 2025-07-13 08:26:21 +02:00
León Orell Valerian Liehr
b0e559a976 Rollup merge of #143796 - JonathanBrouwer:fix-builtin-attribute-prefix, r=jdonszelmann
Fix ICE for parsed attributes with longer path not handled by CheckAttribute

Fixes https://github.com/rust-lang/rust/issues/137590
Fixes https://github.com/rust-lang/rust/issues/143789

r? ```@jdonszelmann```
2025-07-13 07:21:21 +02:00
bors
d2baa49a10 Auto merge of #143213 - dianne:lower-cond-tweaks, r=cjgillot
de-duplicate condition scoping logic between AST→HIR lowering and `ScopeTree` construction

There was some overlap between `rustc_ast_lowering::LoweringContext::lower_cond` and `rustc_hir_analysis::check::region::resolve_expr`, so I've removed the former and migrated its logic to the latter, with some simplifications.

Consequences:
- For `while` and `if` expressions' `let`-chains, this changes the `HirId`s for the `&&`s to properly correspond to their AST nodes. This is how guards were handled already.
- This makes match guards share previously-duplicated logic with `if`/`while` expressions. This will also be used by guard pattern[^1] guards.
- Aside from legacy syntax extensions (e.g. some builtin macros) that directly feed AST to the compiler, it's currently impossible to put attributes directly on `&&` operators in `let` chains[^2]. Nonetheless, attributes on `&&` operators in `let` chains in `if`/`while` expression conditions are no longer silently ignored and will be lowered.
- This no longer wraps conditions in `DropTemps`, so the HIR and THIR will be slightly smaller.
- `DesugaringKind::CondTemporary` is now gone. It's no longer applied to any spans, and all uses of it were dead since they were made to account for `if` and `while` being desugared to `match` on a boolean scrutinee.
- Should be a marginal perf improvement beyond that due to leveraging [`ScopeTree` construction](5e749eb66f/compiler/rustc_hir_analysis/src/check/region.rs (L312-L355))'s clever handling of `&&` and `||`:
  - This removes some unnecessary terminating scopes that were placed around top-level `&&` and `||` operators in conditions. When lowered to MIR, logical operator chains don't create intermediate boolean temporaries, so there's no temporary to drop. The linked snippet handles wrapping the operands in terminating scopes as necessary, in case they create temporaries.
  - The linked snippet takes care of letting `let` temporaries live and terminating other operands, so we don't need separate traversals of `&&` chains for that.

[^1]: rust-lang/rust#129967
[^2]: Case-by-case, here's my justification: `#[attr] e1 && e2` applies the attribute to `e1`. In `#[attr] (e1 && e2)` , the attribute is on the parentheses in the AST, plus it'd fail to parse if `e1` or `e2` contains a `let`. In `#[attr] expands_to_let_chain!()`, the attribute would already be ignored (rust-lang/rust#63221) and it'd fail to parse anyway; even if the expansion site is a condition, the expansion wouldn't be parsed with `Restrictions::ALLOW_LET`. If it *was* allowed, the notion of a "reparse context" from https://github.com/rust-lang/rust/issues/61733#issuecomment-509626449 would be necessary in order to make `let`-chains left-associative; multiple places in the compiler assume they are.
2025-07-13 04:20:07 +00:00
bors
b1d2f2c64c Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk
Split up the `unknown_or_malformed_diagnostic_attributes` lint

This splits up the lint into the following lint group:
- `unknown_diagnostic_attributes` - triggers if the attribute is unknown to the current compiler
- `misplaced_diagnostic_attributes` - triggers if the attribute exists but it is not placed on the item kind it's meant for
- `malformed_diagnostic_attributes` - triggers if the attribute's syntax or options are invalid
- `malformed_diagnostic_format_literals` - triggers if the format string literal is invalid, for example if it has unpaired curly braces or invalid parameters
- this pr doesn't create it, but future lints for things like deprecations can also go here.

This PR does not start emitting lints in places that previously did not.

## Motivation

I want to have finer control over what `unknown_or_malformed_diagnostic_attributes` does

I have a project with fairly low msrv that is/will have a lower msrv than future diagnostic attributes. So lints will be emitted when I or others compile it on a lower msrv.

At this time, there are two options to silence these lints:

-  `#[allow(unknown_or_malformed_diagnostic_attributes)]` - this risks diagnostic regressions if I (or others) mess up using the attribute, or if the attribute's syntax ever changes.
- write a build script to detect the compiler version and emit cfgs, and then conditionally enable the attribute:
    ```rust
    #[cfg_attr(rust_version_99, diagnostic::new_attr_in_rust_99(thing = ..))]`
    struct Foo;
    ```
    or conditionally `allow`  the lint:
    ```rust
   // lib.rs
   #![cfg_attr(not(current_rust), allow(unknown_or_malformed_diagnostic_attributes))]
   ```

I like to avoid using build scripts if I can, so the following works much better for me. That is what this PR will let me do in the future:
```rust
    #[allow(unknown_diagnostic_attribute, reason = "attribute came out in rust 1.99 but msrv is 1.70")]
    #[diagnostic::new_attr_in_rust_99(thing = ..)]`
    struct Foo;
2025-07-13 01:11:56 +00:00
Jonathan Brouwer
86349e31dd Port #[omit_gdb_pretty_printer_section] to the new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-12 22:55:48 +02:00
Michael Goulet
736bfa12de Clean up implementation of RPITIT assoc item lowering 2025-07-12 19:31:15 +00:00
bohan
47e15d90e1 query RPITIT in a trait or impl 2025-07-13 02:52:13 +08:00
bohan
dc6c3300fc compute all rpitit of a trait 2025-07-13 02:52:13 +08:00
Jonathan Brouwer
ef82007ed7 Port #[automatically_derived] to the new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-12 17:48:50 +02:00
LorrensP-2158466
e3fc6e5348 merge source and target bindings into single field 2025-07-12 17:42:02 +02:00
bors
bfc046a4b8 Auto merge of #143624 - tmiasko:copy-prop-borrowed, r=cjgillot
Propagate from borrowed locals in CopyProp

r? cjgillot
2025-07-12 13:48:36 +00:00
b-naber
9ed5378cfd replace binding and shadowed_glob on NameResolution with non_glob_binding and glob_binding 2025-07-12 15:06:32 +02:00
bors
915e535244 Auto merge of #143810 - matthiaskrgr:rollup-iw7a23z, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#143403 (Port several trait/coherence-related attributes the new attribute system)
 - rust-lang/rust#143633 (fix: correct assertion to check for 'noinline' attribute presence before removal)
 - rust-lang/rust#143647 (Clarify and expand documentation for std::sys_common dependency structure)
 - rust-lang/rust#143716 (compiler: doc/comment some codegen-for-functions interfaces)
 - rust-lang/rust#143747 (Add target maintainer information for aarch64-unknown-linux-musl)
 - rust-lang/rust#143759 (Fix typos in function names in the `target_feature` test)
 - rust-lang/rust#143767 (Bump `src/tools/x` to Edition 2024 and some cleanups)
 - rust-lang/rust#143769 (Remove support for SwitchInt edge effects in backward dataflow)
 - rust-lang/rust#143770 (build-helper: clippy fixes)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-12 10:46:43 +00:00
bors
2f9c9cede6 Auto merge of #143766 - matthiaskrgr:rollup-0x7t69s, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#142391 (rust: library: Add `setsid` method to `CommandExt` trait)
 - rust-lang/rust#143302 (`tests/ui`: A New Order [27/N])
 - rust-lang/rust#143303 (`tests/ui`: A New Order [28/28] FINAL PART)
 - rust-lang/rust#143568 (std: sys: net: uefi: tcp4: Add timeout support)
 - rust-lang/rust#143611 (Mention more APIs in `ParseIntError` docs)
 - rust-lang/rust#143661 (chore: Improve how the other suggestions message gets rendered)
 - rust-lang/rust#143708 (fix: Include frontmatter in -Zunpretty output )
 - rust-lang/rust#143718 (Make UB transmutes really UB in LLVM)

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: i686-gnu-nopt-1
try-job: test-various
2025-07-12 07:44:04 +00:00
Matthias Krüger
1d2aa4d8dd Rollup merge of #143769 - tmiasko:rm-backward-switch-int, r=lqd
Remove support for SwitchInt edge effects in backward dataflow

Those effects are untested and unused. Remove them along with the implementation of `BasicBlocks::switch_sources`.
2025-07-11 19:45:26 +02:00
Matthias Krüger
b18064f2f2 Rollup merge of #143716 - workingjubilee:document-some-codegen-backend-stuff, r=bjorn3,fee1-dead
compiler: doc/comment some codegen-for-functions interfaces

An out-of-date comment gets updated and some underdocumented functions get documented.
2025-07-11 19:45:24 +02:00
Matthias Krüger
7f3204f34d Rollup merge of #143633 - dillona:noinline-assert, r=fee1-dead
fix: correct assertion to check for 'noinline' attribute presence before removal
2025-07-11 19:45:23 +02:00
Matthias Krüger
c8780fff6a Rollup merge of #143403 - GrigorenkoPV:attributes/traits, r=jdonszelmann
Port several trait/coherence-related attributes the new attribute system

Part of rust-lang/rust#131229

This ports:
- `#[const_trait]`
- `#[rustc_deny_explicit_impl]`
- `#[rustc_do_not_implement_via_object]`
- `#[rustc_coinductive]`
- `#[type_const]`
- `#[rustc_specialization_trait]`
- `#[rustc_unsafe_specialization_marker]`
- `#[marker]`
- `#[fundamental]`
- `#[rustc_paren_sugar]`
- `#[rustc_allow_incoherent_impl]`
- `#[rustc_coherence_is_core]`

This also changes `#[marker]` to error on duplicates instead of warning.
cc rust-lang/rust#142838, but I don't think it matters too much, since it's unstable.

r? ``@oli-obk``
2025-07-11 19:45:22 +02:00
Jonathan Brouwer
2f05fa6fff Fix ICE for parsed attributes with longer path not handled by CheckAttrVisitor
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-11 17:02:57 +02:00
León Orell Valerian Liehr
28af500757 Opaque type collection: Guard against endlessly recursing free alias types 2025-07-11 15:56:57 +02:00
bjorn3
87958ad683 Avoid building C++ for rustc_llvm with --compile-time-deps
This saves about 30s.
2025-07-11 13:32:03 +00:00
Tomasz Miąsko
5b6d661039 Remove support for SwitchInt edge effects in backward dataflow analyses
Those effects are untested and unused. Remove them along with
the implementation of `BasicBlocks::switch_sources`.
2025-07-11 10:56:50 +02:00
Jubilee Young
39f7707fea compiler: comment on some call-related codegen fn in cg_ssa
Partially documents the situation due to LLVM CFI.
2025-07-11 01:08:21 -07:00
Tomasz Miąsko
011d4aa81f Call get_switch_int_data on a block with SwitchInt terminator
Fix a mix-up of a block with its predecessors in handling of SwitchInt
edge effects for backward analysis. Note that this functionality is
currently unused, so change has no practical impact.
2025-07-11 08:49:11 +02:00
Matthias Krüger
e43481e362 Rollup merge of #143718 - scottmcm:ub-transmute-is-ub, r=WaffleLapkin
Make UB transmutes really UB in LLVM

Ralf suggested in <https://github.com/rust-lang/rust/pull/143410#discussion_r2184928123> that UB transmutes shouldn't be trapping, which happened for the one path *that* PR was changing, but there's another path as well, so *this* PR changes that other path to match.

r? codegen
2025-07-11 07:35:22 +02:00
Matthias Krüger
dbd2f30395 Rollup merge of #143708 - epage:pretty, r=compiler-errors
fix: Include frontmatter in -Zunpretty output

In the implementation (rust-lang/rust#140035), this was left as an open question for
the tracking issue (rust-lang/rust#136889).  My assumption is that this should be
carried over.

The test was carried over from rust-lang/rust#137193 which was superseded by rust-lang/rust#140035.

Thankfully, either way, `-Zunpretty` is unstable and we can always
change it even if we stabilize frontmatter.
2025-07-11 07:35:21 +02:00
Matthias Krüger
140f2fa5ae Rollup merge of #143661 - Muscraft:other-suggestion-message, r=estebank
chore: Improve how the other suggestions message gets rendered

Note: This change is part of my ongoing work to use `annotate-snippets` as `rustc`'s emitter

This change started as a way to remove some specialty code paths from `annotate-snippets`, by making the "and {} other candidates" message get rendered like a secondary message with no level, but turned into a fix for the message's Unicode output. Before this change, when using the Unicode output, the other suggestions message would get rendered outside of the main suggestion block, making it feel disconnected from what it was referring to. This change makes it so that the message is on the last line of the block, aligning its rendering with other secondary messages, and making it clear what the message is referring to.

Before:
```
error[E0433]: failed to resolve: use of undeclared type `IntoIter`
   ╭▸ $DIR/issue-82956.rs:28:24
   │
LL │         let mut iter = IntoIter::new(self);
   │                        ━━━━━━━━ use of undeclared type `IntoIter`
   ╰╴
help: consider importing one of these structs
   ╭╴
LL + use std::array::IntoIter;
   ├╴
LL + use std::collections::binary_heap::IntoIter;
   ├╴
LL + use std::collections::btree_map::IntoIter;
   ├╴
LL + use std::collections::btree_set::IntoIter;
   ╰╴
     and 9 other candidates
```

After:
```
error[E0433]: failed to resolve: use of undeclared type `IntoIter`
   ╭▸ $DIR/issue-82956.rs:28:24
   │
LL │         let mut iter = IntoIter::new(self);
   │                        ━━━━━━━━ use of undeclared type `IntoIter`
   ╰╴
help: consider importing one of these structs
   ╭╴
LL + use std::array::IntoIter;
   ├╴
LL + use std::collections::binary_heap::IntoIter;
   ├╴
LL + use std::collections::btree_map::IntoIter;
   ├╴
LL + use std::collections::btree_set::IntoIter;
   │
   ╰ and 9 other candidates
```
2025-07-11 07:35:20 +02:00
bors
855e0fe46e Auto merge of #142911 - mejrs:unsized, r=compiler-errors
Remove support for dynamic allocas

Followup to rust-lang/rust#141811
2025-07-11 05:27:32 +00:00
Trevor Gross
3a1bb04166 Rollup merge of #143744 - fmease:lta-expand-proper-depth, r=compiler-errors
Properly track the depth when expanding free alias types

Decrease the depth after the fold so as not to affect the depth for unrelated same-level constituent types. My bad.

Fixes rust-lang/rust#142419.
2025-07-10 20:20:41 -04:00
Trevor Gross
58e5c2629d Rollup merge of #143742 - estebank:borrow-suggestion, r=compiler-errors
Rework borrowing suggestions to use `Expr` instead of just `Span`

In the suggestion machinery for borrowing expressions and types, always use the available obligation `Span` to find the appropriate `Expr` to perform appropriateness checks no the `ExprKind` instead of on the textual snippet corresponding to the `Span`. (We were already doing this, but only for a subset of cases.) This now better handles situations where parentheses and `<>` are needed for correct syntax (`&(foo + bar)`, `(&foo).bar()`, `<&Foo>::bar()`, etc.).

Unify the logic for the case where `&` *and* `&mut` are appropriate with the logic for only one of those cases. (Instead of having two branches for emitting the suggestion, we now have a single one, using `Diag::multipart_suggestions` always.)

Handle the case when `S::foo()` should have been `<&S>::foo()` (instead of suggesting the prior `&S::foo()`. Fix rust-lang/rust#143393.

Make `Diag::multipart_suggestions` always verbose. CC rust-lang/rust#141973.
2025-07-10 20:20:40 -04:00
Trevor Gross
44f40e95d5 Rollup merge of #143728 - LorrensP-2158466:refactor-resolve-extraction, r=petrochenkov
Resolve refactor: extraction of `finalize_module_binding` and `single_import_can_define_name`

This pr the work Vadim asked for in https://github.com/rust-lang/rust/pull/142547#issuecomment-3001339385. This part:
> finalize_module_binding/single_import_can_define_name extraction

Cherry-picked commits of b-naber. Extraction of 2 processes in `resolve_ident_in_module_unadjusted`:
- `finalize_module_binding`
- `single_import_can_define_name`

r? ```@petrochenkov```
2025-07-10 20:20:40 -04:00
Trevor Gross
6e3d017b2f Rollup merge of #143722 - oli-obk:sound-llvm, r=dianqk
Make some "safe" llvm ops actually sound

Noticed while doing other refactorings

it may cause some extra unnecessary allocations, but the current use sites are rare ones anyway
2025-07-10 20:20:39 -04:00
mejrs
a7bf5c4fa2 Split up the unknown_or_malformed_diagnostic_attributes lint 2025-07-11 01:24:24 +02:00
Matthias Krüger
b4089bf417 Rollup merge of #143640 - oli-obk:const-fn-traits, r=compiler-errors
Constify `Fn*` traits

r? `@compiler-errors` `@fee1-dead`

this should unlock a few things. A few `const_closures` tests have broken even more than before, but that feature is marked as incomplete anyway

cc rust-lang/rust#67792
2025-07-10 20:28:49 +02:00
Matthias Krüger
95cbacd019 Rollup merge of #143632 - dillona:ffi-param-names, r=jieyouxu
fix: correct parameter names in LLVMRustBuildMinNum and LLVMRustBuildMaxNum FFI declarations
2025-07-10 20:28:48 +02:00
Matthias Krüger
9e6af56e12 Rollup merge of #143599 - folkertdev:x86-asm-syntax-global-naked-asm, r=Amanieu
emit `.att_syntax` when global/naked asm use that option

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

LLVM would error when using `-Cllvm-args=-x86-asm-syntax=intel` in combination with global/naked assembly with `att_syntax`. It turns out that for LLVM you do in this case need to emit `.att_syntax`.

r? `@Amanieu`
2025-07-10 20:28:47 +02:00
Matthias Krüger
b11e9e31dd Rollup merge of #143446 - usamoi:export-executable-symbols, r=bjorn3,oli-obk
use `--dynamic-list` for exporting executable symbols

closes rust-lang/rust#101610
cc rust-lang/rust#84161

https://sourceware.org/binutils/docs-2.39/ld/VERSION.html:

> --dynamic-list=dynamic-list-file
Specify the name of a dynamic list file to the linker. This is typically used when creating shared libraries to specify a list of global symbols whose references shouldn’t be bound to the definition within the shared library, or creating dynamically linked executables to specify a list of symbols which should be added to the symbol table in the executable. This option is only meaningful on ELF platforms which support shared libraries.

`ld.lld --help`:

>   --dynamic-list=<file>: Similar to --export-dynamic-symbol-list. When creating a shared object, this additionally implies -Bsymbolic but does not set DF_SYMBOLIC

>  --export-dynamic-symbol-list=file: Read a list of dynamic symbol patterns. Apply --export-dynamic-symbol on each pattern

>  --export-dynamic-symbol=glob: (executable) Put matched symbols in the dynamic symbol table. (shared object) References to matched non-local STV_DEFAULT symbols shouldn't be bound to definitions within the shared object. Does not imply -Bsymbolic.

>  --export-dynamic: Put symbols in the dynamic symbol table

Use `--dynamic-list` because it's older than `--export-dynamic-symbol-list` (binutils 2.35)

try-job: dist-i586-gnu-i586-i686-musl
2025-07-10 20:28:46 +02:00
León Orell Valerian Liehr
341f12df67 Properly track the depth when expanding free alias types 2025-07-10 19:49:32 +02:00
Esteban Küber
0674eca2f0 Make Diag::multipart_suggestions always verbose 2025-07-10 17:23:29 +00:00
Esteban Küber
7dfc3e9af4 Rework borrowing suggestions to use Expr instead of just Span
In the suggestion machinery for borrowing expressions and types, always use the available obligation `Span` to find the appropriate `Expr` to perform appropriateness checks no the `ExprKind` instead of on the textual snippet corresponding to the `Span`.

Unify the logic for the case where `&` *and* `&mut` are appropriate with the logic for only one of those cases.

Handle the case when `S::foo()` should have been `<&S>::foo()` (instead of suggesting the prior `&S::foo()`.
2025-07-10 17:23:29 +00:00
Scott McMurray
f5fc8727db Add BuilderMethods::unreachable_nonterminator
So places that need `unreachable` but in the middle of a basic block can call that instead of figuring out the best way to do it.
2025-07-10 09:17:28 -07:00
Mu001999
889582e704 Check assoc consts and tys later like assoc fns 2025-07-10 23:39:54 +08:00
Ed Page
a11ee5614c fix: Include frontmatter in -Zunpretty output
In the implementation (#140035), this was left as an open question for
the tracking issue (#136889).  My assumption is that this should be
carried over.

Thankfully, either way, `-Zunpretty` is unstable and we can always
change it even if we stabilize frontmatter.
2025-07-10 10:26:02 -05:00
Ed Page
df53b3dc04 test(lexer): Add frontmatter unit test 2025-07-10 10:25:29 -05:00
Nia Espera
8d0e0c6d6f interpret/allocation: expose init + write_wildcards on a range 2025-07-10 16:33:31 +02:00
Scott Schafer
d67bf6095a chore: Improve how the other suggestions message gets rendered 2025-07-10 08:00:20 -06:00
b-naber
7632c55abb extract single_import_can_define_name and finalize_glob_module_binding 2025-07-10 15:30:28 +02:00
Matthias Krüger
8c5398a7f7 Rollup merge of #143675 - hkBst:overflowing-1, r=oli-obk
improve lint doc text
2025-07-10 15:19:34 +02:00
Matthias Krüger
90ead986d5 Rollup merge of #143666 - nilehmann:nested_bodies_in_consumers, r=lcnr
Re-expose nested bodies in rustc_borrowck::consumers

After https://github.com/rust-lang/rust/pull/138499, it's not possible anymore to get borrowck information for nested bodies via `get_body_with_borrowck_facts`. This PR re-exposes nested bodies by returning a map containing the typeck root and all its nested bodies. To collect the bodies, a map is added to `BorrowCheckRootCtxt`, and a body is inserted every time `do_mir_borrowck` is called.

r? ``@lcnr``
2025-07-10 15:19:32 +02:00