Commit Graph

48471 Commits

Author SHA1 Message Date
Jubilee
5df238921f Rollup merge of #142587 - compiler-errors:try-visit-expr-fields, r=jieyouxu
Make sure to propagate result from `visit_expr_fields`

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

Fixes rust-lang/rust#142525.
2025-06-17 00:28:19 -07:00
Jubilee
301815496e Rollup merge of #142586 - compiler-errors:remove-visit-struct-field-def, r=fmease
Fold unnecessary `visit_struct_field_def` in AstValidator

We don't need it anymore since we removed the `_: struct { }` syntax experiment.
2025-06-17 00:28:19 -07:00
Jubilee
b27b74f80e Rollup merge of #142584 - Urgau:span-borrowck-139049, r=fmease
Handle same-crate macro for borrowck semicolon suggestion

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

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

Fixes rust-lang/rust#142555.

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

### Review notes

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

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

[rfc]: https://rust-lang.github.io/rfcs/3681-default-field-values.html
2025-06-17 00:28:17 -07:00
Jubilee
725d8291ab Rollup merge of #142542 - cjgillot:invalidate-simplify-cfg, r=SparrowLii
Manually invalidate caches in SimplifyCfg.

The current `SimplifyCfg` pass unconditionally invalidates CFG caches. This is unfortunate if there are no modifications that require this invalidation.
2025-06-17 00:28:16 -07:00
Jubilee Young
679a2e3a5b compiler: Redescribe rustc_target search algo more accurately 2025-06-16 21:29:06 -07:00
Jubilee Young
de792eb030 compiler: Redescribe rustc_target::spec more accurately 2025-06-16 21:03:50 -07:00
blyxyas
6d040856df Add a warning to LateContext::get_def_path 2025-06-17 02:07:01 +02:00
Jieyou Xu
2dd9cc1130 Reject union default field values 2025-06-17 07:27:58 +08:00
David Wood
3d128856ce cranelift/gcc: {Meta,Pointee,}Sized in minicore
As in many previous commits, adding the new traits to minicore, but this
time for cranelift and gcc.
2025-06-16 23:04:37 +00:00
David Wood
d531a84e51 trait_sel: skip nominal_obligations for Sized
`nominal_obligations` calls `predicates_of` on a `Sized` obligation,
effectively elaborating the trait and making the well-formedness checking
machinery do a bunch of extra work checking a `MetaSized` obligation is
well-formed, but given that both `Sized` and `MetaSized` are built-ins,
if `Sized` is otherwise well-formed, so `MetaSized` will be.
2025-06-16 23:04:36 +00:00
David Wood
607eb322a8 trait_sel: skip elaboration of sizedness supertrait
As a performance optimization, skip elaborating the supertraits of
`Sized`, and if a `MetaSized` obligation is being checked, then look for
a `Sized` predicate in the parameter environment. This makes the
`ParamEnv` smaller which should improve compiler performance as it avoids
all the iteration over the larger `ParamEnv`.
2025-06-16 23:04:36 +00:00
David Wood
47abf2e144 trait_sel: extend fast path with sized hierarchy
Extend the fast path for `Sized` traits to include constness and
`MetaSized`.
2025-06-16 23:04:35 +00:00
David Wood
118d4e62c3 middle: print {Meta,Pointee}Sized in opaques
When `sized_hierarchy` is enabled, rustc should print `MetaSized` or
`PointeeSized` instead of `?Sized` in opaques.
2025-06-16 23:04:34 +00:00
David Wood
9044b78c0d trait_sel: print {Meta,Pointee}Sized impl headers
When printing impl headers in a diagnostic, the compiler has to account
for `?Sized` implying `MetaSized` and new `MetaSized` and `PointeeSized`
bounds.
2025-06-16 23:04:34 +00:00
David Wood
e6238ba7db trait_sel: sort {Meta,Pointee}Sized diagnostics last
Like `Sized` diagnostics, sorting `MetaSized` and `PointeeSized`
diagnostics last prevents earlier more useful diagnostics from being
skipped because there has already been error tainting.
2025-06-16 23:04:34 +00:00
David Wood
1229c82094 trait_sel: MetaSized bounds in dispatchable check
Given the necessary additions of bounds to these traits and their impls
in the standard library, it is necessary to add `MetaSized` bounds to
the obligation which is proven as part of checking for dyn
dispatchability.
2025-06-16 23:04:34 +00:00
David Wood
7ab1321f97 trait_sel: stash {Meta,Pointee}Sized errors
`Sized` errors are currently stashed to improve diagnostics and this
must happen with `{Meta,Pointee}Sized` too to maintain diagnostic
output.
2025-06-16 23:04:34 +00:00
David Wood
86ab2b60cd hir_analysis: add {Meta,Pointee}Sized bounds
Opting-out of `Sized` with `?Sized` is now equivalent to adding a
`MetaSized` bound, and adding a `MetaSized` or `PointeeSized` bound
is equivalent to removing the default `Sized` bound - this commit
implements this change in `rustc_hir_analysis::hir_ty_lowering`.

`MetaSized` is also added as a supertrait of all traits, as this is
necessary to preserve backwards compatibility.

Unfortunately, non-global where clauses being preferred over item bounds
(where `PointeeSized` bounds would be proven) - which can result in
errors when a `PointeeSized` supertrait/bound/predicate is added to some
items. Rather than `PointeeSized` being a bound on everything, it can
be the absence of a bound on everything, as `?Sized` was.
2025-06-16 23:04:33 +00:00
David Wood
f0b84b8dcf lint: don't consider sizedness in upcastable lint
Adding a sizedness supertrait shouldn't require multiple vtables so
shouldn't be linted against.
2025-06-16 23:04:33 +00:00
David Wood
884d0e031a library/compiler: add PointeeSized bounds
As core uses an extern type (`ptr::VTable`), the default `?Sized` to
`MetaSized` migration isn't sufficient, and some code that previously
accepted `VTable` needs relaxed to continue to accept extern types.

Similarly, the compiler uses many extern types in `rustc_codegen_llvm`
and in the `rustc_middle::ty::List` implementation (`OpaqueListContents`)
some bounds must be relaxed to continue to accept these types.

Unfortunately, due to the current inability to relax `Deref::Target`,
some of the bounds in the standard library are forced to be stricter than
they ideally would be.
2025-06-16 23:04:33 +00:00
Manuel Drehwald
6359123d25 add and use generic get_const_int function 2025-06-16 14:23:06 -07:00
ostylk
9c1180b623 indicate ppc64 elf abi in e_flags 2025-06-16 22:13:05 +02:00
ostylk
7859a37ffe explicitly set llvm_abiname option on existing ppc64 targets 2025-06-16 21:49:27 +02:00
Jubilee Young
7b29a5d282 Revert overeager warning for misuse of --print native-static-libs
In a PR to emit warnings on misuse of `--print native-static-libs`,
we did not consider the matter of composing parts of build systems.
If you are not directly invoking rustc, it can be difficult to know
when you will in fact compile a staticlib, so making sure everyone
uses `--print native-static-lib` correctly can be just a nuisance.

This reverts the following commits:
- f66787a08d
- 72a9219e82
- 98bb597c05
- c59b70841c

Next cycle we can reland a slightly more narrowly focused variant or one
that focuses on `--emit` instead of `--print native-static-libs`.
But in its current state, I am not sure the warning is very useful.
2025-06-16 12:43:36 -07:00
Celina G. Val
6da3bf853e Apply suggestions from code review
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2025-06-16 12:27:47 -07:00
Michael Goulet
ac8b506ca7 Fix some unused fields in AST visitor 2025-06-16 18:23:31 +00:00
Urgau
994794a50b Handle same-crate macro for borrowck semicolon suggestion 2025-06-16 19:58:01 +02:00
Jakub Beránek
b1ba2cdf41 Rollup merge of #142573 - lcnr:search_graph-3, r=lqd
`fn candidate_is_applicable` to method

r? `@BoxyUwU`
2025-06-16 19:54:37 +02:00
Jakub Beránek
d1ed469d26 Rollup merge of #142554 - nnethercote:fix-PathSource-lifetimes, r=petrochenkov
Fix `PathSource` lifetimes.

It currently has two, which don't accurately capture what's happening -- the `TupleStruct` spans are allocated in `ResolverArenas`, which is different to where the `Expr` is allocated -- and require some "outlives" constraints to be used.

This commit adds another lifetime, renames the existing ones, and removes the "outlives" constraints.

r? `@petrochenkov`
2025-06-16 19:54:35 +02:00
Jakub Beránek
1e950ef1b2 Rollup merge of #142498 - GrigorenkoPV:as-ptr-refactor, r=jdonszelmann
Port `#[rustc_as_ptr]` to the new attribute system

It might make sense to introduce some new parser analogous to `Single`, but even more simple: for parsing attributes that take no arguments and may appear only once (such as `#[rustc_as_ptr]` or `#[rustc_const_stable_indirect]`). Not sure if this should be a single `impl` parsing all such attributes, or one impl per attribute. Or how it will play along with the upcoming rework of attribute validation. Or how these argumentless attributes should be called (I've loosely referred to them as `markers` in the name of the new module in this PR, but not sure how good it is).

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

---

For reference, the `#[rustc_as_ptr]` attribute was created back in rust-lang/rust#132732 as a followup to rust-lang/rust#128985.
2025-06-16 19:54:34 +02:00
Jakub Beránek
d68432a1a9 Rollup merge of #142341 - xizheyin:142311, r=fee1-dead
Don't suggest converting `///` to `//` when expecting `,`

Fixes rust-lang/rust#142311
2025-06-16 19:54:33 +02:00
Jakub Beránek
4479d42d60 Rollup merge of #139340 - beetrees:riscv-float-struct-abi, r=workingjubilee
Fix RISC-V C function ABI when passing/returning structs containing floats

RISC-V passes structs containing only one or two floats (or a float and integer pair) in registers, as long as the individual floats/integers fit in a single corresponding register (see [the ABI specification](https://github.com/riscv-non-isa/riscv-elf-psabi-doc/releases/download/v1.0/riscv-abi.pdf) for details). Before this PR, Rust would not check what offset the second float/integer was at, instead assuming that it was at the standard offset for its default alignment. However, as the offset can be affected by `#[repr(align(N))]` and `#[repr(packed)]`, this caused miscompilations (see #115609). To fix this, this PR introduces a `rest_offset` field to `CastTarget` that can be used to explicitly specify at what offset the `rest` part of the cast is located at.

While fixing this, I discovered another bug: the size of the cast target was being used as the size of the MIR return place (when the function was using a `PassMode::Cast` return type). However, the cast target is allowed to be smaller than the size of the actual type, causing a miscompilation. This PR fixes this issue by using the largest of the size of the type and the size of the cast target as the size of the MIR return place, ensuring all reads/writes will be inbounds.

Fixes the RISC-V part of #115609.

cc target maintainers of `riscv64gc-unknown-linux-gnu`: `@kito-cheng` `@michaelmaitland` `@robin-randhawa-sifive` `@topperc`

r? `@workingjubilee`
2025-06-16 19:54:32 +02:00
Daniel Paoliello
6906b44e1c Change __rust_no_alloc_shim_is_unstable to be a function 2025-06-16 10:54:07 -07:00
Michael Goulet
ad60d8eace Make sure to propagate result from visit_expr_fields 2025-06-16 17:49:33 +00:00
Michael Goulet
8a7b50a5da Fold unnecessary visit_struct_field_def in AstValidator 2025-06-16 17:48:21 +00:00
Manuel Drehwald
7d3a1d49ab make more CodegenCx function generic 2025-06-16 10:36:15 -07:00
Pavel Grigorenko
da8d6bbd50 Port #[rustc_as_ptr] to the new attribute system 2025-06-16 18:13:27 +03:00
xizheyin
c63665cd73 Dont suggest converting /// to regular comment when it appears after missing , in list
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-16 23:07:11 +08:00
David Wood
3b0e1c17d2 trait_sel: {Meta,Pointee}Sized on ?Sized types
Expand the automatic implementation of `MetaSized` and `PointeeSized` so
that it is also implemented on non-`Sized` types, just not `ty::Foreign`
(extern type).
2025-06-16 15:00:22 +00:00
David Wood
d43da6f4de trait_sel: {Meta,Pointee}Sized on Sized types
Introduce the `MetaSized` and `PointeeSized` traits as supertraits of
`Sized` and initially implement it on everything that currently
implements `Sized` to isolate any changes that simply adding the
traits introduces.
2025-06-16 15:00:22 +00:00
Camille GILLOT
c4b67c6d87 Reason about borrowed classes in CopyProp. 2025-06-16 14:17:13 +00:00
Camille GILLOT
a2d96875a5 Add comment. 2025-06-16 12:31:36 +00:00
Jakub Beránek
f1dd5fb56e Rollup merge of #142561 - nnethercote:fix-njn-comment, r=chenyukang
Remove an `njn:` comment accidentaly left behind.

r? `@chenyukang`
2025-06-16 14:31:14 +02:00
Jakub Beránek
1a56184460 Rollup merge of #142530 - fee1-dead-contrib:push-klusvwusyqvq, r=compiler-errors
use `if let` guards where possible

these crates already enable the feature
2025-06-16 14:31:14 +02:00
Jakub Beránek
dc16682824 Rollup merge of #142528 - fee1-dead-contrib:push-rlxklunqkwmv, r=RalfJung
clarify `rustc_do_not_const_check` comment

~~Given that we have used this attribute for other reasons before it seems appropriate to make this a "usually".~~

Add function name as a pointer

cc ```@rust-lang/wg-const-eval```
2025-06-16 14:31:13 +02:00
Jakub Beránek
2c4abc0f45 Rollup merge of #142450 - xizheyin:rustc-query-doc, r=SparrowLii
Add documentation on top of `rustc_middle/src/query/mod.rs`

The `rustc-dev-guide` gives a high-level intro, but many details—especially about how the code works and modifiers in `query xxx(){...}`—are only in code comments or the macro implementation. This doc makes it easier for contributors and code readers to understand the workflow and available modifiers without jumping between files and docs.

This PR adds a comprehensive module-level doc comment to `rustc_middle::query::mod.rs` that:
1. Provides an overview of the query system and macro-based query definitions for reading code more easily
2. Centralizes documentation for all query modifiers (previously scattered or only in `rustc_macro` code), closely following the authoritative list in QueryModifiers.
2025-06-16 14:31:12 +02:00
Jakub Beránek
3795658357 Rollup merge of #142082 - xizheyin:rustc_attr_data_structures, r=jdonszelmann
Refactor `rustc_attr_data_structures` documentation

I was reading through `AttributeKind` and realized that attributes like `InlineAttr` didn't appear in it, however, I found them in `rustc_codegen_ssa` and understood why (guessing).

There's almost no overall documentation for this crate, I've added the organized documentation at the top of `lib.rs`, and I've grouped the Attributes into two categories: `AttributeKind` that run all through the compiler, and the ones that are only used in `codegen_ssa`, such as `InlineAttr`, `OptimizeAttr`, `InstructionSetAttr`.

Also, I've added documentation for `AttributeKind` that further explains why attributes like `InlineAttr` don't appear in it, with examples for each variant.

r? ```@jdonszelmann```
2025-06-16 14:31:09 +02:00
lcnr
7fb9284fb3 candidate_is_applicable to method 2025-06-16 14:01:01 +02:00
Jakub Beránek
60a59ae523 Emit linker timing section 2025-06-16 11:51:17 +02:00