Commit Graph

800 Commits

Author SHA1 Message Date
bors 362211dc29 Auto merge of #154326 - JonathanBrouwer:rollup-MflIdQW, r=JonathanBrouwer
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#152710 (Unalign `PackedFingerprint` on all hosts, not just x86 and x86-64)
 - rust-lang/rust#153874 (constify const Fn*: Destruct)
 - rust-lang/rust#154097 (improve validation error messages: show surrounding type)
 - rust-lang/rust#154277 (use `minicore` more in testing inline assembly)
 - rust-lang/rust#154293 (Use verbose span suggestion for type const)
2026-03-24 18:37:19 +00:00
Jonathan Brouwer 9396ab225e Rollup merge of #154293 - reddevilmidzy:type-diag, r=fmease
Use verbose span suggestion for type const

close: https://github.com/rust-lang/rust/issues/154214

r? fmease
2026-03-24 18:14:18 +01:00
Jonathan Brouwer ab6401749a Rollup merge of #154097 - RalfJung:validity-error, r=oli-obk
improve validation error messages: show surrounding type

Also, for dyn-downcast show the type we're downcasting to.

r? @oli-obk
2026-03-24 18:14:15 +01:00
Jonathan Brouwer a1c32ca566 Rollup merge of #154276 - cyrgani:incomplete-mcp-2, r=fmease
allow `incomplete_features` in more tests

This PR allows the `incomplete_features` lint for the `traits` and `const-generics` directories. `specialization` will come in a followup PR.

Followup to rust-lang/rust#154174.
Part of https://github.com/rust-lang/rust/issues/154168.
2026-03-24 16:22:50 +01:00
Redddy e03983878f Use verbose span suggestion for type const 2026-03-24 15:02:10 +00:00
cyrgani 7df43d309c allow incomplete_features in more tests 2026-03-23 20:08:24 +00:00
bors f66622c7ec Auto merge of #152931 - khyperia:always-check-constarghastype, r=BoxyUwU
Always check `ConstArgHasType` even when otherwise ignoring



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

helping @BoxyUwU finish up https://github.com/rust-lang/rust/pull/150322, this is a simple tweak/finishing-up of that PR.

this is a breaking change that crater detected has some issues with in Boxy's PR, and hence needs a t-types FCP. I can go and help fix those crates if/once the break is signed off on.
2026-03-23 19:06:58 +00:00
Esteban Küber 3ad92c9f23 On E0277 tweak help when single type impls traits
When encountering an unmet predicate, when we point at the trait impls that do exist, if they are all for the same self type, tweak the wording to make it less verbose.
2026-03-21 02:24:36 +00:00
bors 76be1cc4ee Auto merge of #152913 - Unique-Usman:ua/constnottype, r=estebank
rustc_resolve: improve const generic errors
2026-03-20 04:12:22 +00:00
Ralf Jung 05834b2d6b improve validation error messages: show surrounding type, and more info on dyn-downcast 2026-03-19 16:37:00 +01:00
Jonathan Brouwer dfba606b52 Rollup merge of #153987 - reddevilmidzy:mgca-ast, r=BoxyUwU
mGCA: Lower const generic args to infer when needed

close: rust-lang/rust#153198

r? BoxyUwU
2026-03-19 13:42:39 +01:00
Jonathan Brouwer a3898aaeb3 Rollup merge of #153557 - Human9000-bit:issue-153525, r=BoxyUwU
fix inference variables leaking into HIR const literal lowering logic

Inference variables could leak into further const lowering logic

It ICEs when query system tries to cache `lit_to_const()` after its execution and panics, because inference variables are not hashable for some reason

Fixes rust-lang/rust#153524
Fixes rust-lang/rust#153525
2026-03-19 13:42:35 +01:00
Usman Akinyemi f60b6499d8 rustc_resolve: improve const generic errors
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
2026-03-19 11:49:30 +05:30
Esteban Küber 49bb371ca7 When single impl can satisfy inference error, suggest type
When encountering an inference error where a return type must be known, like when calling `Iterator::sum::<T>()` without specifying `T`, look for all `T` that would satisfy `Sum<S>`. If only one, suggest it.

```
error[E0283]: type annotations needed
  --> $DIR/cannot-infer-iterator-sum-return-type.rs:4:9
   |
LL |     let sum = v
   |         ^^^
...
LL |         .sum(); // `sum::<T>` needs `T` to be specified
   |          --- type must be known at this point
   |
   = note: cannot satisfy `_: Sum<i32>`
help: the trait `Sum` is implemented for `i32`
  --> $SRC_DIR/core/src/iter/traits/accum.rs:LL:COL
  ::: $SRC_DIR/core/src/iter/traits/accum.rs:LL:COL
   |
   = note: in this macro invocation
note: required by a bound in `std::iter::Iterator::sum`
  --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
   = note: this error originates in the macro `integer_sum_product` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider giving `sum` an explicit type, where the type for type parameter `S` is specified
   |
LL |     let sum: i32 = v
   |            +++++
```
2026-03-18 18:16:47 +00:00
khyperia e9c273e377 Always check ConstArgHasType even when otherwise ignoring 2026-03-18 11:48:09 +01:00
Jonathan Brouwer 270bca8608 Rollup merge of #153994 - cyrgani:no-invalid-test-dir, r=Kivooeo
move `tests/ui/invalid` tests to new folders

Just some renaming of tests to remove another vague directory.

r? @Kivooeo
2026-03-17 21:20:03 +01:00
Jonathan Brouwer 6f13b5244c Rollup merge of #153795 - arferreira:turbofish-span-improvement, r=Kivooeo,eggyal
Point turbofish inference errors at the uninferred generic arg

Follow-up to rust-lang/rust#153751.

When a method call has a turbofish with an uninferred generic argument, point the diagnostic span at the specific `_` that couldn't be inferred instead of the method name.

Before:
```rust
LL |     S.f::<u32, _>(42);
   |       ^ cannot infer type of the type parameter `B`
```

After:
```rust
LL |     S.f::<u32, _>(42);
   |                ^ cannot infer type of the type parameter `B`
```

Path expressions (`None::<_>`, `foo::<_>()`) are not handled yet, that's a separate code path.

cc @eggyal
2026-03-17 21:20:02 +01:00
Jonathan Brouwer 907464d1b7 Rollup merge of #153682 - estebank:tweak-e0599-note, r=wesleywiser
Tweak E0599 note

When not finding a method for a type, but finding it for a single other impl, special case the output to emit a single message instead of a list.

```
error[E0599]: no associated item named `C` found for struct `Fail<i32, u32>` in the current scope
  --> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:15:23
   |
LL | struct Fail<T: Proj<Assoc = U>, U>(T);
   | ---------------------------------- associated item `C` not found for this struct
...
LL |     Fail::<i32, u32>::C
   |                       ^ associated item not found in `Fail<i32, u32>`
   |
   = note: the associated item was found for `Fail<i32, i32>`
```
instead of

```
   = note: the associated item was found for
           - `Fail<i32, i32>`
```
2026-03-17 21:20:01 +01:00
Jonathan Brouwer 888990ba13 Rollup merge of #153967 - estebank:infer_must_implement, r=petrochenkov
Tweak wording of failed predicate in inference error

Special case message talking about `Predicate` that couldn't be satisfied when in inference errors so that we don't say "cannot satisfy `_: Trait`" and instead say "type must implement `Trait`".
2026-03-17 17:51:30 +01:00
human9000 5113488163 Improve ty::Infer handling during const literal lowering
Co-authored-by: BoxyUwU <rust@boxyuwu.dev>
2026-03-17 21:02:09 +05:00
human9000 11810b8dd9 fix inference variables leaking into HIR const lowering logic 2026-03-17 21:02:09 +05:00
Redddy 924374c75b mGCA: Lower const generic args to infer when needed 2026-03-17 15:24:03 +00:00
cyrgani 72732f2013 move tests/ui/invalid tests to new folders 2026-03-17 10:07:52 +00:00
ywxt 6a0ce16654 Ignore tests for the parallel frontend 2026-03-17 17:39:59 +08:00
Esteban Küber 9b1eb935bc Tweak wording of failed predicate in inference error
Special case message talking about `Predicate` that couldn't be satisfied when in inference errors so that we don't say "cannot satisfy `_: Trait`" and instead say "type must implement `Trait`".
2026-03-16 17:58:49 +00:00
Jonathan Brouwer 42c5d9a455 Rollup merge of #153359 - zedddie:const-param-ty-trait-gating, r=BoxyUwU
Gate `ConstParamTy_` trait behind `const_param_ty_trait` feature

Initially even when user wasn't using unsized const params, the only way to implement/name `ConstParamTy_` was to use `#![feature(unsized_const_params]`, now its gated under `const_param_ty_trait` feature, implied by `unsized_const_params`.

I've also changed use of `unsized_const_params` in tests which were using it only to implement `ConstParamTy_` without using unsized

r? BoxyUwU
2026-03-16 13:11:00 +01:00
Esteban Küber 249f52c1e0 Fix 32bit test 2026-03-14 23:24:23 +00:00
Esteban Küber 87d8f5885b Provide more context on type errors in const context
- On `const` and `static` point at the type (like we do for let bindings)
- On fn calls, point at const parameter in fn definition
- On type, point at const parameter in type definition
- On array type lengths, explain that array length is always `usize`
- On enum variant discriminant, mention `repr`
2026-03-14 20:13:43 +00:00
arferreira e485708b84 Point turbofish inference errors at the uninferred generic arg 2026-03-13 07:29:05 -04:00
Esteban Küber ed25d008a0 Tweak E0599 note
When not finding a method for a type, but finding it for a single other impl, special case the output to emit a single message instead of a list.

```
error[E0599]: no associated item named `C` found for struct `Fail<i32, u32>` in the current scope
  --> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:15:23
   |
LL | struct Fail<T: Proj<Assoc = U>, U>(T);
   | ---------------------------------- associated item `C` not found for this struct
...
LL |     Fail::<i32, u32>::C
   |                       ^ associated item not found in `Fail<i32, u32>`
   |
   = note: the associated item was found for `Fail<i32, i32>`
```
instead of

```
   = note: the associated item was found for
           - `Fail<i32, i32>`
```
2026-03-11 00:43:04 +00:00
Guillaume Gomez 4e2a519d12 Remove TyCtxt::node_span_lint usage from rustc_trait_selection 2026-03-09 11:35:33 +01:00
Yuki Okushi 1190845a3d Do not emit ConstEvaluatable goals if type-const 2026-03-06 21:51:31 +09:00
zedddie ba06eb8e7a gate ConstParamTy_ trait behind const_param_ty_trait feature 2026-03-06 05:39:07 +01:00
Jonathan Brouwer 9632fd893d Rollup merge of #152906 - lapla-cogito:issue_152653, r=BoxyUwU
Make `const_lit_matches_ty` check literal suffixes for exact type match

`const_lit_matches_ty` ignored literal suffixes. This let the `try_lower_anon_const_lit` fast path produce a mistyped `ty::Const::Value`, bypassing the type mismatch error that typeck would otherwise report.
2026-03-05 19:41:59 +01:00
Jonathan Brouwer 1c44dbd580 Rollup merge of #152164 - mu001999-contrib:lint/unused_features, r=JonathanBrouwer
Lint unused features

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152164)*

Fixes rust-lang/rust#44232
Fixes rust-lang/rust#151752

---

This PR records used features through query side effect, then reports unsued features finally.
2026-03-04 19:30:36 +01:00
mu001999 0436634084 Remove unused features in tests 2026-03-04 08:06:45 +08:00
human9000 ee1d0cfbe6 MGCA: fix type error handling for array and tuple lowering logic 2026-03-03 17:08:26 +05:00
Jonathan Brouwer 87bd517707 Rollup merge of #153034 - arferreira:fix-trivial-bound-diagnostic, r=Kivooeo
Remove unhelpful hint from trivial bound errors

The `= help: see issue #48214` hint on trivial bound errors isn't useful, most users hitting these errors aren't trying to use the `trivial_bounds` feature. The `disabled_nightly_features` call already handles suggesting the feature gate on nightly.

Closes rust-lang/rust#152872
2026-03-03 07:14:15 +01:00
lapla 0bb020ace9 Make const_lit_matches_ty check literal suffixes for exact type match 2026-03-01 12:47:52 +09:00
Jonathan Brouwer 794ac4e0a2 Rollup merge of #152794 - reddevilmidzy:mgca-print, r=BoxyUwU
Fix ICE in `try_to_raw_bytes` when array elements have mismatched

close: rust-lang/rust#152683

After rust-lang/rust#152001, suffixed integer literals preserve their own type during const lowering, so `try_to_raw_bytes` could call `.to_u8()` on a scalar with size > 1, causing an ICE. Fix by using `try_to_bits(Size::from_bytes(1)).ok()` instead.

r? BoxyUwU
2026-02-28 19:55:50 +01:00
reddevilmidzy a5789d0a02 Fix ICE in try_to_raw_bytes when array elements have mismatched scalar
sizes
2026-02-26 04:36:03 +00:00
Jacob Pratt cd09c56e45 Rollup merge of #153075 - reddevilmidzy:mgca-neg, r=BoxyUwU
mGCA: Lower negated literals directly and reject non-integer negations

follow up rust-lang/rust#152001
resolve: rust-lang/rust#152246

r? BoxyUwU
2026-02-25 21:42:54 -05:00
Redddy 5127108400 mGCA: drop literal anon-const special case in parser 2026-02-25 04:05:12 +00:00
Jacob Pratt cc8a33aeaa Rollup merge of #152952 - zedddie:improve-diag, r=BoxyUwU
mGCA: improve ogca diagnostic message

r? BoxyUwU
2026-02-24 22:51:39 -05:00
Redddy d13924caa7 mGCA: Reject negated non-integer literals in const args 2026-02-25 03:16:17 +00:00
Jonathan Brouwer b8999f2b20 Rollup merge of #152492 - biscuitrescue:fix-array-valtree-wf, r=BoxyUwU
mGCA: Enforce WF element types for array valtrees

Fixes rust-lang/rust#152125

Extends WellFormedness checking for const generics to validate that array element types in ValTrees match the declared element type.

### Problem
Before commit, this would have incorrectly compiled

``` rust
#![feature(adt_const_params, min_generic_const_args)]

use std::marker::ConstParamTy;

#[derive(Eq, PartialEq, ConstParamTy)]
struct Foo;

struct Bar;

fn foo<const N: [Foo; 1]>() {}

fn main() {
    foo::<{ [Bar] }>();
}
```

### Solution
Added a `ty::Array` arm to checking WellFormedness (similar to the existing `ty::Tuple` arm from rust-lang/rust#150713) which creates `ConstArgHasType` obligations for each array element, ensuring they match the array's declared element type.

I attempted to combine the `Tuple` and `Array` arms into a single arm, but this proved difficult due to pattern matching limitations, and the separate arm is more readable anyway.

### Tests

Added UI test which verifies that the type mismatch is now properly caught, and also returns an appropriate test message

r? @BoxyUwU
2026-02-24 14:41:55 +01:00
arferreira d3bd9e6103 Remove unhelpful hint from trivial bound errors 2026-02-24 00:04:45 -05:00
Jonathan Brouwer 388032363d Rollup merge of #152385 - LaneAsade:gate-type-const-defaults, r=BoxyUwU
Feature gate for defaulted associated type_consts with associated_type_defaults

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152385)*

This PR for issue rust-lang/rust#130288 extends a feature gate that was already present for defaulted associated types to defaulted type consts under associated_type_defaults.

Code added:
```
if ctxt == AssocCtxt::Trait && rhs.is_some() {
                    gate!(
                        &self,
                        associated_type_defaults,
                        i.span,
                        "associated type defaults are unstable"
                    );
                }
```

Error produced:
```
error[E0658]: associated type defaults are unstable
  --> $DIR/type-const-associated-default.rs:4:5
   |
LL |     type const N: usize = 10;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #29661 <https://github.com/rust-lang/rust/issues/29661> for more information
   = help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
  --> $DIR/type-const-associated-default.rs:1:12
   |
LL | #![feature(min_generic_const_args)]
   |            ^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
   = note: `#[warn(incomplete_features)]` on by default

error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0658`.

```
Thanks to @BoxyUwU for the guidance on this issue.
2026-02-22 20:14:23 +01:00
zedddie 2b3a2da610 mGCA: improve diag message with ogca 2026-02-21 21:06:01 +01:00
LaneAsade 84140cf4e1 gate defaulted type consts with associated_type_defaults 2026-02-19 10:07:06 +05:30