rust/tests/ui/generic-associated-types
bors 196ff446d2 Auto merge of #122493 - lukas-code:sized-constraint, r=lcnr
clean up `Sized` checking

This PR cleans up `sized_constraint` and related functions to make them simpler and faster. This should not make more or less code compile, but it can change error output in some rare cases.

## enums and unions are `Sized`, even if they are not WF

The previous code has some special handling for enums, which made them sized if and only if the last field of each variant is sized. For example given this definition (which is not WF)
```rust
enum E<T1: ?Sized, T2: ?Sized, U1: ?Sized, U2: ?Sized> {
    A(T1, T2),
    B(U1, U2),
}
```
the enum was sized if and only if `T2` and `U2` are sized, while `T1` and `T2` were ignored for `Sized` checking. After this PR this enum will always be sized.

Unsized enums are not a thing in Rust and removing this special case allows us to return an `Option<Ty>` from `sized_constraint`, rather than a `List<Ty>`.

Similarly, the old code made an union defined like this
```rust
union Union<T: ?Sized, U: ?Sized> {
    head: T,
    tail: U,
}
```
sized if and only if `U` is sized, completely ignoring `T`. This just makes no sense at all and now this union is always sized.

## apply the "perf hack" to all (non-error) types, instead of just type parameters

This "perf hack" skips evaluating `sized_constraint(adt): Sized` if `sized_constraint(adt): Sized` exactly matches a predicate defined on `adt`, for example:

```rust
// `Foo<T>: Sized` iff `T: Sized`, but we know `T: Sized` from a predicate of `Foo`
struct Foo<T /*: Sized */>(T);
```

Previously this was only applied to type parameters and now it is applied to every type. This means that for example this type is now always sized:

```rust
// Note that this definition is WF, but the type `S<T>` not WF in the global/empty ParamEnv
struct S<T>([T]) where [T]: Sized;
```

I don't anticipate this to affect compile time of any real-world program, but it makes the code a bit nicer and it also makes error messages a bit more consistent if someone does write such a cursed type.

## tuples are sized if the last type is sized

The old solver already has this behavior and this PR also implements it for the new solver and `is_trivially_sized`. This makes it so that tuples work more like a struct defined like this:

```rust
struct TupleN<T1, T2, /* ... */ Tn: ?Sized>(T1, T2, /* ... */ Tn);
```

This might improve the compile time of programs with large tuples a little, but is mostly also a consistency fix.

## `is_trivially_sized` for more types

This function is used post-typeck code (borrowck, const eval, codegen) to skip evaluating `T: Sized` in some cases. It will now return `true` in more cases, most notably `UnsafeCell<T>` and `ManuallyDrop<T>` where `T.is_trivially_sized`.

I'm anticipating that this change will improve compile time for some real world programs.
2024-03-19 04:21:14 +00:00
..
auxiliary
bugs eagerly instantiate binders to avoid relying on sub 2024-03-14 17:19:40 +01:00
extended
parse
ambig-hr-projection-issue-93340.next.stderr rebase 2024-03-14 17:19:40 +01:00
ambig-hr-projection-issue-93340.old.stderr one must imagine tidy happy 2024-03-14 17:19:40 +01:00
ambig-hr-projection-issue-93340.rs one must imagine tidy happy 2024-03-14 17:19:40 +01:00
anonymize-bound-vars.rs
assume-gat-normalization-for-nested-goals.current.stderr Mark some next-solver-behavior tests explicitly with revisions 2024-03-10 23:23:46 -04:00
assume-gat-normalization-for-nested-goals.rs Mark some next-solver-behavior tests explicitly with revisions 2024-03-10 23:23:46 -04:00
collections-project-default.rs
collections-project-default.stderr
collections.rs
collectivity-regression.rs
collectivity-regression.stderr
const_params_have_right_type.rs
const_params_have_right_type.stderr
const-generics-gat-in-trait-return-type-1.rs
const-generics-gat-in-trait-return-type-2.rs
const-generics-gat-in-trait-return-type-3.rs
constraint-assoc-type-suggestion.rs
constraint-assoc-type-suggestion.stderr
construct_with_other_type.rs
cross-crate-bounds.rs
cross-crate-bounds.stderr
elided-in-expr-position.rs
elided-in-expr-position.stderr Merge collect_mod_item_types query into check_well_formed 2024-03-07 14:26:31 +00:00
empty_generics.rs
empty_generics.stderr
equality-bound.rs
equality-bound.stderr
gat-bounds-normalize-pred.rs
gat-bounds-not-checked-with-right-substitutions.rs
gat-bounds-not-checked-with-right-substitutions.stderr
gat-in-trait-path-undeclared-lifetime.rs
gat-in-trait-path-undeclared-lifetime.stderr
gat-in-trait-path.base.stderr
gat-in-trait-path.rs
gat-trait-path-generic-type-arg.rs
gat-trait-path-generic-type-arg.stderr
gat-trait-path-missing-lifetime.rs
gat-trait-path-missing-lifetime.stderr Merge collect_mod_item_types query into check_well_formed 2024-03-07 14:26:31 +00:00
gat-trait-path-parenthesised-args.rs
gat-trait-path-parenthesised-args.stderr Merge collect_mod_item_types query into check_well_formed 2024-03-07 14:26:31 +00:00
generic_associated_type_undeclared_lifetimes.rs
generic_associated_type_undeclared_lifetimes.stderr
generic-associated-type-bounds.rs
generic-associated-types-where.rs
generic-associated-types-where.stderr
higher-ranked-self-impl-requirement.rs
impl_bounds_ok.rs
impl_bounds.rs
impl_bounds.stderr
issue-47206-where-clause.rs
issue-47206-where-clause.stderr
issue-58694-parameter-out-of-range.rs
issue-62326-parameter-out-of-range.rs
issue-67424.rs
issue-67510-pass.base.stderr
issue-67510-pass.rs
issue-67510.rs
issue-67510.stderr
issue-68641-check-gat-bounds.rs
issue-68641-check-gat-bounds.stderr
issue-68642-broken-llvm-ir.rs
issue-68642-broken-llvm-ir.stderr
issue-68643-broken-mir.rs
issue-68643-broken-mir.stderr
issue-68644-codegen-selection.rs
issue-68644-codegen-selection.stderr
issue-68645-codegen-fulfillment.rs
issue-68645-codegen-fulfillment.stderr
issue-68648-1.rs
issue-68648-2.rs
issue-68648-2.stderr
issue-68649-pass.rs
issue-68653.rs
issue-68656-unsized-values.rs
issue-68656-unsized-values.stderr
issue-70303.rs
issue-70304.rs
issue-70304.stderr
issue-71176.rs
issue-71176.stderr
issue-74684-1.rs
issue-74684-1.stderr
issue-74684-2.rs
issue-74684-2.stderr Revert "Auto merge of #122140 - oli-obk:track_errors13, r=davidtwco" 2024-03-11 21:28:16 +00:00
issue-74816.rs
issue-74816.stderr
issue-74824.rs
issue-74824.stderr
issue-76407.rs
issue-76535.base.stderr
issue-76535.extended.stderr
issue-76535.rs
issue-76826.rs
issue-78113-lifetime-mismatch-dyn-trait-box.rs
issue-78113-lifetime-mismatch-dyn-trait-box.stderr
issue-78671.base.stderr
issue-78671.extended.stderr
issue-78671.rs
issue-79422.base.stderr
issue-79422.extended.stderr
issue-79422.rs
issue-79636-1.rs
issue-79636-1.stderr
issue-79636-2.rs
issue-79636-2.stderr
issue-80433-reduced.rs
issue-80433.rs
issue-80433.stderr Merge collect_mod_item_types query into check_well_formed 2024-03-07 14:26:31 +00:00
issue-81487.rs
issue-81712-cyclic-traits.rs
issue-81712-cyclic-traits.stderr
issue-81862.rs
issue-81862.stderr
issue-84931.rs
issue-84931.stderr
issue-85921.rs
issue-86218-2.rs
issue-86218.rs
issue-86483.rs
issue-86787.rs
issue-86787.stderr
issue-87258_a.rs
issue-87258_a.stderr
issue-87258_b.rs
issue-87258_b.stderr
issue-87429-2.rs
issue-87429-associated-type-default.rs
issue-87429-associated-type-default.stderr
issue-87429-specialization.rs
issue-87429-specialization.stderr
issue-87429.rs
issue-87748.rs
issue-87750.rs
issue-88287.rs
issue-88287.stderr
issue-88360.fixed
issue-88360.rs
issue-88360.stderr
issue-88405.rs
issue-88459.rs
issue-88595.rs Make DefiningAnchor::Bind only store the opaque types that may be constrained, instead of the current infcx root item. 2024-03-11 17:19:37 +00:00
issue-88595.stderr Make DefiningAnchor::Bind only store the opaque types that may be constrained, instead of the current infcx root item. 2024-03-11 17:19:37 +00:00
issue-89008.rs
issue-89352.rs
issue-90014-tait2.next-solver.stderr Mark some next-solver-behavior tests explicitly with revisions 2024-03-10 23:23:46 -04:00
issue-90014-tait2.rs Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
issue-90014-tait2.stderr Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
issue-90014-tait.rs
issue-90014-tait.stderr
issue-90014.rs
issue-90014.stderr
issue-90729.rs
issue-91139.migrate.stderr
issue-91139.rs
issue-91139.stderr
issue-91883.rs
issue-91883.stderr
issue-92033.rs
issue-92033.stderr
issue-92096.migrate.stderr
issue-92096.rs
issue-92096.stderr
issue-92280.rs
issue-92954.rs
issue-93141.rs
issue-93262.rs
issue-93341.rs
issue-93342.rs
issue-93874.rs
issue-95305.rs
issue-95305.stderr
issue-101020.rs
issue-101020.stderr
issue-102114.current.stderr Ignore tests w/ current/next revisions from compare-mode=next-solver 2024-03-10 21:18:41 -04:00
issue-102114.next.stderr Ignore tests w/ current/next revisions from compare-mode=next-solver 2024-03-10 21:18:41 -04:00
issue-102114.rs Ignore tests w/ current/next revisions from compare-mode=next-solver 2024-03-10 21:18:41 -04:00
issue-102333.rs
issue-102335-gat.rs
issue-102335-gat.stderr
issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs clean up ADT sized constraint computation 2024-03-14 21:28:47 +01:00
issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.stderr clean up ADT sized constraint computation 2024-03-14 21:28:47 +01:00
iterable.rs
method-unsatisfied-assoc-type-predicate.rs
method-unsatisfied-assoc-type-predicate.stderr
mismatched-where-clause-regions.rs
mismatched-where-clause-regions.stderr
missing_lifetime_args.rs
missing_lifetime_args.stderr Merge collect_mod_item_types query into check_well_formed 2024-03-07 14:26:31 +00:00
missing_lifetime_const.rs
missing_lifetime_const.stderr
missing-bounds.fixed
missing-bounds.rs
missing-bounds.stderr
missing-item-sugg.rs
missing-item-sugg.stderr
missing-where-clause-on-trait.rs
missing-where-clause-on-trait.stderr
multiple-type-params-with-unmet-bounds.rs
multiple-type-params-with-unmet-bounds.stderr
own-bound-span.rs
own-bound-span.stderr
parameter_number_and_kind_impl.rs
parameter_number_and_kind_impl.stderr
parameter_number_and_kind.rs
parameter_number_and_kind.stderr
pointer_family.rs
projection-bound-cycle-generic.rs
projection-bound-cycle-generic.stderr
projection-bound-cycle.rs
projection-bound-cycle.stderr
projection-type-lifetime-mismatch.rs
projection-type-lifetime-mismatch.stderr
rigid-hr-projection-issue-93340.rs one must imagine tidy happy 2024-03-14 17:19:40 +01:00
self-outlives-lint.rs
self-outlives-lint.stderr
shadowing.rs
shadowing.stderr
streaming_iterator.rs
trait-objects.base.stderr
trait-objects.extended.stderr
trait-objects.rs
type-param-defaults.rs
type-param-defaults.stderr
unknown-lifetime-ice-119827.rs Merge collect_mod_item_types query into check_well_formed 2024-03-07 14:26:31 +00:00
unknown-lifetime-ice-119827.stderr Merge collect_mod_item_types query into check_well_formed 2024-03-07 14:26:31 +00:00
unsatisfied-item-lifetime-bound.rs
unsatisfied-item-lifetime-bound.stderr
unsatisfied-outlives-bound.rs
unsatisfied-outlives-bound.stderr
variance_constraints.rs