3376 Commits

Author SHA1 Message Date
Matthias Krüger
149ad71e05 Rollup merge of #144291 - oli-obk:const_trait_alias, r=fee1-dead
Constify trait aliases

Allow `const trait Foo = Bar + [const] Baz;` trait alias declarations. Their rules are the same as with super traits of const traits. So `[const] Baz` or `const Baz` is only required for `[const] Foo` or `const Foo` bounds respectively.

tracking issue rust-lang/rust#41517 (part of the general trait alias feature gate, but I can split it out into a separate const trait alias feature gate. I just assumed that const traits would stabilize before trait aliases, and we'd want to stabilize trait aliases together with const trait aliases at the same time)

r? ``@compiler-errors`` ``@fee1-dead``
2025-10-31 02:39:14 +01:00
bors
6906167e01 Auto merge of #148193 - camsteffen:remove-qpath-langitem, r=cjgillot
Remove `QPath::LangItem`

Closes rust-lang/rust#115178.

r? cjgillot
2025-10-30 10:04:21 +00:00
Oli Scherer
544a5a3e0e Make const trait aliases work in next solver 2025-10-30 08:05:37 +00:00
Oli Scherer
8b122f1e11 Generate const predicates for const trait aliases 2025-10-30 08:05:37 +00:00
Oli Scherer
5f6772c2a7 Constify trait aliases 2025-10-30 08:05:37 +00:00
Matthias Krüger
1fe148371a Rollup merge of #148173 - tiif:fix-opaque-ice, r=BoxyUwU
Emit delayed bug during wfck for stranded opaque

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

## Problem

The fundamental issue here is ``OpaqueTypeCollector`` operates on ``rustc_middle::Ty``, but ``check_type_wf`` operates on HIR.

Since [check_type_wf](2f7620a5cc/compiler/rustc_hir_analysis/src/check/wfcheck.rs (L2262)) operates on HIR, it can see the stranded opaque and tries to infer it's hidden type. But ``OpaqueTypeCollector`` operates on ``rustc_middle::Ty``, so the ``OpaqueTypeCollector`` can no longer see a stranded opaque, hence its hidden type could not be inferred.

As a result, the tests ICE'ed at 34a8c7368c/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs (L253)

## Proposed solution

This PR detects stranded opaque types during wf check and emit a delayed bug for it.

## Alternative solution

`@BoxyUwU` and I had considered rewriting ``OpaqueTypeCollector`` to be a HIR visitor instead of a ``rustc_middle::Ty`` visitor, but we believe a HIR-based ``OpaqueTypeCollector`` will not work and might not worth the cost of rewriting.

## Acknowledgement

This PR is a joint effort with `@BoxyUwU` :3
2025-10-28 17:49:29 +01:00
tiif
c797724ed5 Add delayed bug for stranded opaque 2025-10-28 13:02:24 +00:00
Stuart Cook
ef8003bbb9 Rollup merge of #147185 - RalfJung:repr-c-not-zst, r=petrochenkov
repr(transparent): do not consider repr(C) types to be 1-ZST

Context: https://github.com/rust-lang/unsafe-code-guidelines/issues/552

This experiments with a [suggestion](https://github.com/rust-lang/rfcs/pull/3845#discussion_r2388463698) by ```@RustyYato``` to stop considering repr(C) types as 1-ZST for the purpose of repr(transparent). If we go with https://github.com/rust-lang/rfcs/pull/3845 (or another approach for fixing repr(C)), they will anyway not be ZST on all targets any more, so this removes a portability hazard. Furthermore, zero-sized repr(C) structs [may have to be treated](https://github.com/rust-lang/unsafe-code-guidelines/issues/552#issuecomment-3250657813) as non-ZST for the win64 ABI (at least that's what gcc/clang do), so allowing them to be ignored in repr(transparent) types is not entirely coherent.

Turns out we already have an FCW for repr(transparent), namely https://github.com/rust-lang/rust/issues/78586. This extends that lint to also check for repr(C).
2025-10-28 20:39:32 +11:00
Cameron Steffen
ead5e120a5 Remove QPath::LangItem 2025-10-27 21:19:38 -05:00
Ralf Jung
b9b29c4379 repr(transparent): do not consider repr(C) types to be 1-ZST 2025-10-27 19:25:14 +01:00
David Wood
82a4049844 hir_analysis: add missing sizedness bounds
Default sizedness bounds were not being added to
`explicit_super_predicates_of` and `explicit_implied_predicates_of`
which meant that a trait bound added to a associated type projection
would be missing the implied predicate of the default sizedness
supertrait of that trait.

An unexpected consequence of this change was that the check for multiple
principals was now finding an additional `MetaSized` principal when
eagerly expanding trait aliases. Instead of special-casing trait aliases
as different from traits and not adding a `MetaSized` supertrait to trait
aliases, filter out `MetaSized` when lowering `dyn Trait`.
2025-10-24 15:28:34 +01:00
Oli Scherer
375899c940 Allow unsizing pattern types with pointer base 2025-10-21 11:22:51 +00:00
Oli Scherer
ad4bd083f3 Add not-null pointer patterns to pattern types 2025-10-21 11:22:51 +00:00
Stuart Cook
f87f9a456c Rollup merge of #147734 - fmease:tighten-relaxed, r=lcnr
Further tighten up relaxed bounds

Follow-up to rust-lang/rust#142693, rust-lang/rust#135331 and rust-lang/rust#135841.
Fixes rust-lang/rust#143122.

* Reject relaxed bounds `?Trait` in the bounds of trait aliases.
  Just like `trait Trait {}` doesn't mean `trait Trait: Sized {}` and we therefore reject `trait Trait: ?Sized {}`, `trait Trait =;` (sic!) doesn't mean `trait Trait = Sized;` (never did!) and as a logical consequence `trait Trait = ?Sized;` is meaningless and should be forbidden.
* Don't permit `?Sized` in more places (e.g., supertrait bounds, trait object types) if feature `more_maybe_bounds` is enabled.
  That internal feature is only meant to allow the user to define & use *new* default traits (that have fewer rules to follow for now to ease experimentation).
* Unconditionally check that the `Trait` in `?Trait` is a default trait.
  Previously, we would only perform this check in selected places which was very brittle and led to bugs slipping through.
* Slightly improve diagnostics.
2025-10-20 22:30:53 +11:00
Cameron Steffen
b323f567d9 Remove Option from impl_trait_header 2025-10-17 08:36:34 -05:00
Cameron Steffen
e60e9f0826 Split impl_(opt_)trait_ref 2025-10-17 08:36:34 -05:00
Cameron Steffen
ca5073759c Remove some impl_trait_ref usages 2025-10-17 08:36:34 -05:00
Cameron Steffen
c17b2dc283 Split trait_id_of_impl into impl(_opt)_trait_id 2025-10-17 08:36:34 -05:00
León Orell Valerian Liehr
65814c80e8 Guard us against degenerate default traits 2025-10-16 19:53:32 +02:00
León Orell Valerian Liehr
03dfb84ee1 More robustly reject relaxing non-default trait bounds 2025-10-16 19:53:32 +02:00
León Orell Valerian Liehr
ce68cd3762 Reject relaxed bounds inside trait alias bounds 2025-10-16 19:53:31 +02:00
Matthias Krüger
334b3af42c Rollup merge of #144438 - dawidl022:contracts/guarded-lowering, r=oli-obk
Guard HIR lowered contracts with `contract_checks`

Refactor contract HIR lowering to ensure no contract code is executed when contract-checks are disabled.

The call to `contract_checks` is moved to inside the lowered fn body, and contract closures are built conditionally, ensuring no side-effects present in contracts occur when those are disabled. This partially addresses rust-lang/rust#139548, i.e. the bad behavior no longer happens with contract checks disabled (`-Zcontract-checks=no`).

The change is made in preparation for adding contract variable declarations - variables declared before the `requires` assertion, and accessible from both `requires` and `ensures`, but not in the function body (PR rust-lang/rust#144444). As those declarations may also have side-effects, it's good to guard them with `contract_checks` - the new lowering approach allows for this to be done easily.

Contracts tracking issue: rust-lang/rust#128044

**Known limiatations**:

- It is still possible to early return from the *function* from within a contract, e.g.

  ```rust
  #[ensures({if x > 0 { return 0 }; |_| true})]
  fn foo(x: u32) -> i32 {
      42
  }
  ```

  When `foo` is called with an argument greater than 0, instead of `42`, `0` will be returned.

  As this is not a regression, it is not addressed in this PR. However, it may be worth revisiting later down the line, as users may expect a form of early return from *contract specifications*, and so returning from the entire *function* could cause confusion.

- ~Contracts are still not optimised out when disabled. Currently, even when contracts are disabled, the code generated causes existing optimisations to fail, meaning even disabled contracts could impact runtime performance. This issue is blocking rust-lang/rust#136578, and has not been addressed in this PR, i.e. the `mir-opt` and `codegen` tests that fail in rust-lang/rust#136578 still fail with these new HIR lowering changes.~ Contracts should now be optimised out when disabled, however some regressions tests still need to be added to be sure that is indeed the case.
2025-10-16 19:35:22 +02:00
lcnr
4dfbf11644 cleanup ErrorGuaranteed handling 2025-10-14 11:31:32 +02:00
bors
4b94758d2b Auto merge of #147640 - matthiaskrgr:rollup-fio3d88, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#144266 (Supress swapping lhs and rhs in equality suggestion in extern macro )
 - rust-lang/rust#147471 (Assert that non-extended temporaries and `super let` bindings have scopes)
 - rust-lang/rust#147533 (Renumber return local after state transform)
 - rust-lang/rust#147566 (rewrite outlives placeholder constraints to outlives static when handling opaque types)
 - rust-lang/rust#147613 (Make logging filters work again by moving EnvFilter into its own layer)
 - rust-lang/rust#147615 (reduce calls to attr.span() in old doc attr parsing)
 - rust-lang/rust#147636 (miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-13 19:22:06 +00:00
Matthias Krüger
2a10082bcc Rollup merge of #147471 - dianne:assert-temporary-scope, r=nnethercote
Assert that non-extended temporaries and `super let` bindings have scopes

This PR clarifies a point of confusion in the compiler: all bodies have an outer temporary drop scope, including `static` and `const` item bodies[^1]. Whenever a temporary should be dropped in its enclosing temporary scope, it should have a temporary scope to be dropped in so that its drop can be scheduled[^2]. As such, I've updated some relevant comments and made `ScopeTree::default_temporary_scope` and `RvalueScopes::temporary_scope` panic when an enclosing temporary scope isn't found instead of allowing potential bugs where potentially-drop-sensitive temporaries are effectively given static lifetimes.

Since non-extended `super let` bindings are dropped in their block's enclosing temporary scope, this applies to them as well: the enclosing temporary scope should exist.

[^1]: See https://github.com/rust-lang/rust/blob/master/compiler/rustc_hir_analysis/src/check/region.rs#L773-L778 for non-`fn`/closure bodies. The `this.cx.var_parent = None;` enables [lifetime extension to `'static` lifetimes](https://doc.rust-lang.org/stable/reference/destructors.html#r-destructors.scope.lifetime-extension.static) and the `ScopeData::Destruction` scope ensures non-extended temporaries are dropped in the body expression's scope.

[^2]: For certain borrowed temporaries, drops that don't require running destructors may later be removed by constant promotion. That is unrelated to this PR.
2025-10-13 16:54:12 +02:00
bors
9b8264604e Auto merge of #147629 - GuillaumeGomez:rollup-i1zinjv, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#147514 (repr_transparent_external_private_fields: normalize types during traversal)
 - rust-lang/rust#147605 (Add doc links between `{integer}::from_str_radix` and `from_str`)
 - rust-lang/rust#147608 (cg_llvm: Use `LLVMDIBuilderCreateGlobalVariableExpression`)
 - rust-lang/rust#147623 (Clear `ChunkedBitSet` without reallocating)
 - rust-lang/rust#147625 (Add a warning when running tests with the GCC backend and debug assertions are enabled)
 - rust-lang/rust#147626 (Generalize configuring LLD as the default linker in bootstrap)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-13 12:13:05 +00:00
Guillaume Gomez
4a7e152511 Rollup merge of #147514 - RalfJung:transparent-nonexhaustive-normalize, r=lcnr
repr_transparent_external_private_fields: normalize types during traversal

Determining whether a type is a 1-ZST will internally do full normalization, so we better do the same when scanning for non-exhaustive types.

r? ``@lcnr``
2025-10-13 11:25:21 +02:00
bors
956f47c32f Auto merge of #147502 - camsteffen:split-overlapping-impls, r=fmease
Split overlapping_{inherent,trait}_impls

This yielded some perf improvement for me. Reduces some calls to `impl_trait_header` query. But I think the llvm optimization is more relevant.
2025-10-13 09:05:36 +00:00
Dawid Lachowicz
2a5dac7682 Remove no longer used contract_checks intrinsic
The contract_checks compiler flag is now used to determine
if runtime contract checks should be enabled, as opposed
to the compiler intrinsic as previously.
2025-10-11 00:16:44 +01:00
Dawid Lachowicz
e4ead0ec70 Guard HIR lowered contracts with contract_checks
Refactor contract HIR lowering to ensure no contract code is
executed when contract-checks are disabled.

The call to contract_checks is moved to inside the lowered fn
body, and contract closures are built conditionally, ensuring
no side-effects present in contracts occur when those are disabled.
2025-10-11 00:16:29 +01:00
Matthias Krüger
802f72201d Rollup merge of #147479 - folkertdev:cmse-refactor-warnings, r=davidtwco
cmse: improve error messages

tracking issue: https://github.com/rust-lang/rust/issues/81391
tracking issue: https://github.com/rust-lang/rust/issues/75835

Improves the cmse error messages (e.g. by using more accurate spans), and attempts to clean up the control flow a bit. This is partially in preparation for one final addition: warnings when `union` types or types with niches cross the security boundary. That will be a folllow-up.

Meant to be reviewed commit-by-commit

r? ``@davidtwco``
2025-10-09 20:41:23 +02:00
Ralf Jung
345241536f repr_transparent_external_private_fields: normalize types during traversal 2025-10-09 11:15:31 +02:00
Stuart Cook
9ace0de26b Rollup merge of #147489 - chenyukang:yukang-prefer-repeat-n, r=Kivooeo,oli-obk
Prefer to use repeat_n over repeat().take()

More from https://github.com/rust-lang/rust/pull/147464, but batch processed with `ast-grep` to find and replace.

second commit add notes for library: affaf532f9

r? ``@RalfJung``
2025-10-09 18:43:26 +11:00
Cameron Steffen
735ddcc05a Split overlapping_{inherent,trait}_impls 2025-10-08 18:45:11 -05:00
yukang
53c79f4523 bless format 2025-10-09 01:29:16 +08:00
yukang
1654cce210 prefer to use repeat_n over repeat and take 2025-10-09 01:24:55 +08:00
Folkert de Vries
bd5f908152 cmse: simplify input/output check control flow 2025-10-08 16:36:49 +02:00
Folkert de Vries
760ea07840 cmse: more accurate span for generic arguments 2025-10-08 16:36:45 +02:00
Folkert de Vries
98d3864310 cmse: rephrase error message when signature uses generics 2025-10-08 16:36:45 +02:00
Folkert de Vries
b47de64cdb cmse: rephrase error message when types don't fit 2025-10-08 16:36:18 +02:00
Folkert de Vries
f4d8bd3b47 cmse: more accurate spans for excess parameters
Use the span of the types that don't fit, rather than the span of the
whole signature.
2025-10-08 16:21:50 +02:00
dianne
444eb4cc12 assert that non-extended temporaries have scopes 2025-10-08 06:12:09 -07:00
Folkert de Vries
f62be66e94 cmse: additional impl Trait tests 2025-10-08 13:25:12 +02:00
Boxy Uwu
8e9b0c4ca9 rename select_where_possible and select_all_or_error 2025-10-07 23:02:23 +01:00
Matthias Krüger
7ab1fd1816 Rollup merge of #147243 - folkertdev:cmse-bail-impl-trait, r=davidtwco
cmse: disallow `impl Trait` in `cmse-nonsecure-entry` return types

tracking issue: https://github.com/rust-lang/rust/issues/75835
fixes https://github.com/rust-lang/rust/issues/147242

Refactors some logic to be more robust in the future, and then disallows `impl Trait` as a return type for the cmse ABIs.

The `is_valid_cmse_output_layout` function disallows `union` values like before. That is not entirely correct, but preserves the current behavior. Some additional logic is needed for `union` values (and any types where parts may be uninitialized) that I'll tackle in a later PR.

can be reviewed commit-by-commit.

r? types
2025-10-07 17:42:11 +02:00
Folkert de Vries
fbdc685ed0 cmse: disallow impl Trait in cmse-nonsecure-entry return types 2025-10-07 17:31:08 +02:00
bors
4b9c62b4da Auto merge of #147138 - jackh726:split-canonical-bound, r=lcnr
Split Bound index into Canonical and Bound

See [#t-types/trait-system-refactor > perf `async-closures/post-mono-higher-ranked-hang.rs`](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/perf.20.60async-closures.2Fpost-mono-higher-ranked-hang.2Ers.60/with/541535613) for context

Things compile and tests pass, but not sure if this actually solves the perf issue (edit: it does). Opening up this to do a perf (and maybe crater) run.

r? lcnr
2025-10-02 08:09:33 +00:00
bors
4da69dfff1 Auto merge of #147235 - matthiaskrgr:rollup-a0es1x9, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#146593 (Allow specifying multiple bounds for same associated item, except in trait objects)
 - rust-lang/rust#147177 ([DebugInfo] Fix MSVC tuple child creation)
 - rust-lang/rust#147195 (iter repeat: add tests for new count and last behavior)
 - rust-lang/rust#147202 (Swap order of `resolve_coroutine_interiors` and `handle_opaque_type_uses`)
 - rust-lang/rust#147204 (Refactor ArrayWindows to use a slice)
 - rust-lang/rust#147219 (Add proper error handling for closure in impl)
 - rust-lang/rust#147226 (include `outer_inclusive_binder` of pattern types)
 - rust-lang/rust#147230 (Fix typo in 'unfulfilled_lint_expectation' to plural)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-01 18:45:43 +00:00
Folkert de Vries
a7bd285a6a cmse: use BackendRepr to determine valid 64-bit return types 2025-10-01 20:40:52 +02:00
Matthias Krüger
ae60ebd46d Rollup merge of #147219 - Kivooeo:typeof-is-imposter, r=jdonszelmann
Add proper error handling for closure in impl

Fixes https://github.com/rust-lang/rust/issues/147146
Fixes https://github.com/rust-lang/rust/issues/146620

Not sure if it can cause any regressions or anything, as for test also have no idea where to store this one

cc ```@theemathas```

r? compiler
2025-10-01 18:42:37 +02:00