Commit Graph

41 Commits

Author SHA1 Message Date
León Orell Valerian Liehr f8bce56b39 Don't look for non-type-level assoc consts when checking trait object types 2026-03-17 01:52:28 +01:00
Esteban Küber 37684bdfc5 Make all multipart suggestions verbose
The ShowAlways style of suggestions is usually easier to understand than the inline style.
2026-02-18 18:33:35 +00:00
León Orell Valerian Liehr 618c15eb6c Reject const projections behind trait aliases that mention Self
This fully rewords the diagnostic that was previously only emitted for assoc ty bindings.
That's because it incorrectly called trait aliases *type aliases* and didn't really
make it clear what the root cause is.

The added test used to ICE prior to this change.

I've double-checked that the preexisting test I've modified still ICEs in
nightly-2025-03-29.
2026-01-21 12:53:47 +01:00
León Orell Valerian Liehr 233a45c41a Fix handling of const params defaults that ref Self & generalize diag
We used to lower such bad defaulted const args in trait object types to
`{type error}`; now correctly lower them to `{const error}`.

The added tests used to ICE prior to this change.
2026-01-21 12:53:47 +01:00
León Orell Valerian Liehr 9b861ace46 Generalize diag for missing assoc types to account for assoc consts 2026-01-21 12:53:46 +01:00
León Orell Valerian Liehr 8d524f096d mGCA: Make traits with type assoc consts dyn compatible...
...but require all assoc consts to be specified via bindings.
2026-01-21 12:53:44 +01:00
Zachary S c3205f98dd Replace #[rustc_do_not_implement_via_object] with #[rustc_dyn_incompatible_trait], which makes the marked trait dyn-incompatible.
Removes the attribute from `MetaSized` and `PointeeSized`, with a special case in the trait solvers for `MetaSized`.

`dyn MetaSized` is a perfectly cromulent type, and seems to only have had #[rustc_do_not_implement_via_object] so the builtin object
candidate does not overlap with the builtin MetaSized impl that all `dyn` types get.
Resolves this with a special case by checking `is_sizedness_trait` where the trait solvers previously checked `implement_via_object`.

`dyn PointeeSized` alone is rejected for other reasons (since `dyn PointeeSized` is considered to have no principal trait because `PointeeSized`
is removed at an earlier stage of the compiler), but `(dyn PointeeSized + Send)` is valid and equivalent to `dyn Send`.

Add suggestions from code review

Update compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs and tests

Co-authored-by: lcnr <rust@lcnr.de>
2026-01-20 12:54:40 -06:00
xonx4l 4b000cfacd Merge E0412 into E0425 2025-12-02 18:25:13 +00:00
Christian Poveda b2ab7cf980 Gate 2015 UI tests 2025-11-27 11:19:00 -05:00
reddevilmidzy a4ee7f8964 Add regression test for 128705 2025-11-21 23:03:39 +09:00
David Wood c50aebba78 trait_sel: don't require predicates of aliases hold
No longer require that we prove that the predicates of aliases hold when
checking the well-formedness of the alias. This permits more uses of GATs
and changes the output of yet more tests.
2025-10-15 09:35:05 +01:00
Oneirical 957fa10d50 Add test batch 3 2025-09-12 14:45:12 -04:00
Karol Zwolak d14b83e378 bless tests with new lint messages 2025-08-19 21:27:10 +02:00
Oneirical 7196d8cd66 Rehome tests/ui/issues/ tests [3/?] 2025-08-04 16:43:53 -04:00
Camille GILLOT 7c6496145f Check statics' type in type_of. 2025-07-25 23:39:26 +00:00
dianne 41e6f767b6 future-incompat lints: don't link to the nightly edition-guide version 2025-07-16 01:44:02 -07:00
Michael Goulet 250b5d204f Make missing lifetime suggestion verbose 2025-06-24 18:59:42 +00:00
Oli Scherer 1d41c2c01c Merge unboxed trait object error suggestion into regular dyn incompat error 2025-06-13 13:54:06 +00:00
Oli Scherer 3fff727e87 Use more detailed spans in dyn compat errors within bodies 2025-05-27 08:18:11 +00:00
Michael Goulet a59c86ab44 Deduplicate dyn compatibility violations due to coercion 2025-05-26 10:57:54 +00:00
Michael Goulet d0413436d5 Do not try to confirm non-dyn compatible method 2025-05-23 12:20:35 +00:00
Michael Goulet 45598de704 Do not gather local all together at the beginning of typeck 2025-05-05 14:27:09 +00:00
Vadim Petrochenkov b3f75353a2 UI tests: add missing diagnostic kinds where possible 2025-04-08 23:06:31 +03:00
Stuart Cook 5913c5248b Rollup merge of #139124 - xtexx:gh-139082, r=compiler-errors
compiler: report error when trait object type param reference self

Fixes #139082.

Emits an error when `Self` is found in the projection bounds of a trait
object. In type aliases, `Self` has no meaning, so `type A = &'static
dyn B` where `trait B = Fn() -> Self` will expands to `type A = &'static
Fn() -> Self` which is illegal, causing the region solver to bail out
when hitting the uninferred Self.

r? ````@compiler-errors```` ````@fee1-dead````
2025-04-08 20:55:04 +10:00
Bennet Bleßmann 7dd57f085c update/bless tests 2025-04-06 21:41:47 +02:00
xtex fdefffecb2 compiler: report error when trait object type param reference self
Fixes #139082.

Emits an error when `Self` is found in the projection bounds of a trait
object. In type aliases, `Self` has no meaning, so `type A = &'static
dyn B` where `trait B = Fn() -> Self` will expands to `type A = &'static
Fn() -> Self` which is illegal, causing the region solver to bail out
when hitting the uninferred Self.

Bug: #139082
Signed-off-by: xtex <xtexchooser@duck.com>
2025-04-03 17:35:51 +08:00
Yotam Ofek 5da1ba41b3 Fix typo in hir lowering lint diag 2025-03-14 21:03:21 +00:00
Michael Goulet f3d31f77e4 Remove dyn_compatible_for_dispatch 2025-02-24 18:48:40 +00:00
Michael Goulet 72bd174c43 Do not deduplicate list of associated types provided by dyn principal 2025-02-21 19:32:45 +00:00
Michael Goulet 309e371f7b Ignore Self in bounds check for associated types with Self:Sized 2025-02-15 20:38:14 +00:00
lcnr 83a02619d5 fallout :skull_emoji: 2025-02-14 00:37:23 +01:00
Esteban Küber f0845adb0c Show diff suggestion format on verbose replacement
```
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
  --> $DIR/attempted-access-non-fatal.rs:7:15
   |
LL |     let _ = 2.l;
   |               ^
   |
help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix
   |
LL -     let _ = 2.l;
LL +     let _ = 2.0f64;
   |
```
2025-02-10 20:21:39 +00:00
León Orell Valerian Liehr 57b5d3af62 Compiler: Finalize dyn compatibility renaming 2025-01-26 21:20:31 +01:00
Michael Goulet ea9a253ff1 Properly report error when object type param default references self 2025-01-24 04:07:10 +00:00
Taylor Cramer d00d4dfe0d Refactor dyn-compatibility error and suggestions
This CL makes a number of small changes to dyn compatibility errors:
- "object safety" has been renamed to "dyn-compatibility" throughout
- "Convert to enum" suggestions are no longer generated when there
  exists a type-generic impl of the trait or an impl for `dyn OtherTrait`
- Several error messages are reorganized for user readability

Additionally, the dyn compatibility error creation code has been
split out into functions.

cc #132713
cc #133267
2025-01-22 09:20:57 -08:00
Michael Goulet 824a867e82 Rework trait expansion to happen once explicitly 2025-01-15 01:26:24 +00:00
Lukas Markeffsky 93bb639ad6 taint fcx on selection errors during unsizing 2025-01-02 19:16:00 +01:00
Michael Goulet 43e2fd5086 Fix ICE when multiple supertrait substitutions need assoc but only one is provided 2024-12-11 19:53:40 +00:00
Michael Goulet fa7449d130 Do not create trait object type if missing associated types 2024-11-30 17:05:47 +00:00
VulnBandit 9a2772e1c2 Don't assume traits used as type are trait objs 2024-10-11 17:36:04 +02:00
León Orell Valerian Liehr 20cebae312 UI tests: Rename "object safe" to "dyn compatible" 2024-10-10 01:13:29 +02:00