Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sized Hierarchy #137944

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open

Sized Hierarchy #137944

wants to merge 42 commits into from

Conversation

davidtwco
Copy link
Member

@davidtwco davidtwco commented Mar 3, 2025

This patch implements rust-lang/rfcs#3729. It introduces two new traits to the standard library, MetaSized and PointeeSized, and makes MetaSized and Sized into const traits (relying on unstable feature(const_trait_impl)). See the RFC for the rationale behind these traits and to discuss whether this change makes sense in the abstract.

These traits are unstable (as is their constness), so users cannot refer to them without opting-in to feature(sized_hierarchy). These traits are not behind cfgs as this would make implementation unfeasible, there would simply be too many cfgs required to add the necessary bounds everywhere. So, like Sized, these traits are automatically implemented by the compiler.

RFC 3729 describes migrations which are necessary to preserve backwards compatibility given the introduction of these traits, which are implemented and as follows:

  • On the current edition, Sized is rewritten as const Sized
    • If the sized_hierarchy feature is enabled, then an edition migration lint to rewrite the bound to const Sized will be emitted.
    • On the next edition, non-const Sized will resume being the default bound.
  • On the current edition, ?Sized is rewritten as const MetaSized
    • If the sized_hierarchy feature is enabled, then an edition migration lint to rewrite the bound to const MetaSized will be emitted.
    • On the next edition, writing ?Sized will be prohibited.
  • On the current edition, const MetaSized is added as a default supertrait for all traits w/out an explicit sizedness supertrait already.
    • If the sized_hierarchy feature is enabled, then an edition migration lint to add an explicit const MetaSized supertrait will be emitted.
    • On the next edition, there is no default const MetaSized supertrait.

Each of these migrations is not conditional on whether the item being migrated needs the migration to the stricter bound - this would be preferable but is not yet implemented (if it is possible to implement). All diagnostic output should remain the same (showing ?Sized even if the compiler sees const MetaSized) unless the sized_hierarchy feature is enabled.

Due to the use of unstable extern types in the standard library and rustc, some bounds in both projects have had to be relaxed already - this is unfortunate but unavoidable so that these extern types can continue to be used where they were before. Performing these relaxations in the standard library and rustc are desirable longer-term anyway, but some bounds are not as relaxed as they ideally would be due to the inability to relax Deref::Target (this will be investigated separately).

It is hoped that this is implemented such that it could be merged and these traits could exist "under the hood" without that being observable to the user (other than in any performance impact this has on the compiler, etc). Only once sized_hierarchy is stabilised would edition migration lints start to be emitted and diagnostic output show the "real" sizedness traits behind-the-scenes, rather than ?Sized. Some details might leak through due to the standard library relaxations, but this has not been observed in test output.

Notes:

  • Any commits starting with "upstream:" can be ignored, as these correspond to other upstream PRs that this is based on which have yet to be merged.
  • This best reviewed commit-by-commit. I've attempted to make the implementation easy to follow and keep similar changes and test output updates together.
    • Each commit has a short description describing its purpose.
    • This patch is large but it's primarily in the test suite (library: +573/-184, compiler: +1268/-310, tests: +3720/-452).
  • It is expected that this will have performance regressions initially and I'll aim to resolve those prior to merging if possible.
    • I'd appreciate feedback on how best to go about this from those familiar with the type system.
  • On my local machine, this passes all of the test suites, a stage two build and a tidy check.
  • PointeeSized is a different name from the RFC just to make it more obvious that it is different from std::ptr::Pointee but all the names are yet to be bikeshed anyway.

Fixes #79409.

r? @ghost (I'll discuss this with relevant teams to find a reviewer)

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-run-make Area: port run-make Makefiles to rmake.rs A-rustdoc-json Area: Rustdoc JSON backend A-rustdoc-search Area: Rustdoc's search feature PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Mar 3, 2025
@rust-log-analyzer

This comment has been minimized.

@davidtwco
Copy link
Member Author

davidtwco commented Mar 3, 2025

I can reproduce this locally but I have no idea why it would be related to this patch. Clippy needed adjusting.

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Mar 3, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@traviscross traviscross added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Mar 4, 2025
@traviscross
Copy link
Contributor

cc @rust-lang/lang

@fee1-dead fee1-dead self-assigned this Mar 4, 2025
@tmiasko
Copy link
Contributor

tmiasko commented Mar 4, 2025

Does this perhaps fix #127336 by rejecting it?

@bors

This comment was marked as resolved.

@davidtwco
Copy link
Member Author

Does this perhaps fix #127336 by rejecting it?

It doesn't currently.

davidtwco added 26 commits March 6, 2025 17:47
These tests just need blessing, they don't have any interesting behaviour
changes.

Some of these tests have new errors because `LegacyReceiver` cannot be
proven to be implemented now that it is also testing for `MetaSized` -
but this is just a consequence of the other errors in the test.
While there are no non-`const Sized` types in the language, this testing
attribute will make it possible to force this for testing purposes.
Makes `{Meta,}Sized` into const traits and implements them in the trait
solvers so everything is `Sized` except ADTs with the
`rustc_non_const_sized` attribute.
Now that `MetaSized` and `Sized` are const traits, this must be reflected
in minicore.
Now that `MetaSized` and `Sized` are const traits, this must be reflected
in tests without minicore which define these language items.
With const sizedness traits, the correct migration is from `Sized`
to `const Sized` and from `?Sized` to `const MetaSized`.
There are some uses of `min_specialization` in the standard library which
now see `HostEffectPredicate` - this shouldn't prevent specialization
for the sizedness marker traits that are now const.
Some of the host effect predicates end up with
`TraitGoalProvenVia::ParamEnv` combined with
`CandidateSource::BuiltinImpl` and are discarded as a consequence.

This commit special-cases `BuiltinImplSource::Trivial` to avoid this -
that might not be precisely the correct fix but it is unclear what that
would be.

Without this, the following tests fail:

- tests/ui/associated-type-bounds/cant-see-copy-bound-from-child-rigid.rs#next
- tests/ui/associated-types/defaults-suitability.rs#next
- tests/ui/associated-types/defaults-unsound-62211-1.rs#next
- tests/ui/associated-types/defaults-unsound-62211-2.rs#next
- tests/ui/associated-types/imply-relevant-nested-item-bounds.rs#next
- tests/ui/associated-types/imply-relevant-nested-item-bounds-2.rs#next
- tests/ui/associated-types/issue-63593.rs#next
- tests/ui/associated-types/issue-54108.rs#next
- tests/ui/async-await/async-closures/constrained-but-no-upvars-yet.rs#next
- tests/ui/async-await/async-closures/is-not-fn.rs#next
- tests/ui/async-await/async-closures/is-fn.rs#next
- tests/ui/async-await/async-closures/once.rs#next
- tests/ui/async-await/async-closures/signature-inference-from-two-part-bound.rs#next
- tests/ui/async-await/async-fn/higher-ranked-async-fn.rs#next
- tests/ui/async-await/async-fn/project.rs#next
- tests/ui/async-await/return-type-notation/normalizing-self-auto-trait-issue-109924.rs#next
- tests/ui/async-await/send-bound-async-closure.rs#next
- tests/ui/borrowck/implied-bound-from-impl-header.rs#next
- tests/ui/borrowck/implied-bound-from-normalized-arg.rs#next
- tests/ui/borrowck/issue-103095.rs#next
- tests/ui/closures/deduce-signature/deduce-from-opaque-type-after-norm.rs#next
- tests/ui/closures/deduce-signature/infer-higher-ranked-signature.rs#next
- tests/ui/closures/deduce-signature/infer-signature-from-impl.rs#next
- tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.rs#next
- tests/ui/closures/deduce-signature/supertrait-signature-inference-issue-23012.rs#next
- tests/ui/closures/supertrait-hint-references-assoc-ty.rs#next
- tests/ui/coherence/coherence-overlap-negate-use-feature-gate.rs
- tests/ui/coherence/occurs-check/opaques.rs#next
- tests/ui/coherence/occurs-check/associated-type.rs#next
- tests/ui/coherence/orphan-check-alias.rs#next
- tests/ui/coherence/orphan-check-projections-nested.rs#next
- tests/ui/coherence/orphan-check-projections-not-covering-ambiguity.rs#next
- tests/ui/coherence/orphan-check-projections-not-covering.rs#next
- tests/ui/coroutine/gen_block_iterate.rs#next
- tests/ui/diagnostic_namespace/do_not_recommend/as_expression.rs#next
- tests/ui/diagnostic_namespace/do_not_recommend/does_not_acccept_args.rs#next
- tests/ui/diagnostic_namespace/do_not_recommend/nested.rs#next
- tests/ui/diagnostic_namespace/do_not_recommend/simple.rs#next
- tests/ui/diagnostic_namespace/do_not_recommend/stacked.rs#next
- tests/ui/diagnostic_namespace/do_not_recommend/type_mismatch.rs#next
- tests/ui/diagnostic_namespace/do_not_recommend/supress_suggestions_in_help.rs#next
- tests/ui/diagnostic_namespace/do_not_recommend/with_lifetime.rs#next
- tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.rs#next
- tests/ui/generic-associated-types/assume-gat-normalization-for-nested-goals.rs#next
- tests/ui/generic-associated-types/issue-74816.rs#next
- tests/ui/generic-associated-types/issue-74824.rs#next
- tests/ui/generic-associated-types/issue-91883.rs#next
- tests/ui/generic-associated-types/rigid-hr-projection-issue-93340.rs#next
- tests/ui/generic-const-items/const-trait-impl.rs
- tests/ui/higher-ranked/builtin-closure-like-bounds.rs#next
- tests/ui/higher-ranked/closure-bound-codegen-ice.rs#next
- tests/ui/higher-ranked/leak-check/candidate-from-env-universe-err-1.rs#next
- tests/ui/higher-ranked/leak-check/candidate-from-env-universe-err-2.rs#next
- tests/ui/higher-ranked/leak-check/candidate-from-env-universe-err-project.rs#next
- tests/ui/higher-ranked/leak-check/leak-check-in-selection-2.rs#next
- tests/ui/higher-ranked/leak-check/leak-check-in-selection-3.rs#next
- tests/ui/higher-ranked/leak-check/leak-check-in-selection-4-hr-nested.rs#next
- tests/ui/higher-ranked/leak-check/leak-check-in-selection-5-ambig.rs#next
- tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.rs#next
- tests/ui/higher-ranked/trait-bounds/future.rs#next
- tests/ui/higher-ranked/trait-bounds/rigid-equate-projections-in-higher-ranked-fn-signature.rs#next
- tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs#next
- tests/ui/impl-trait/auto-trait-selection-freeze.rs#next
- tests/ui/impl-trait/auto-trait-selection.rs#next
- tests/ui/impl-trait/call_method_on_inherent_impl.rs#next
- tests/ui/impl-trait/call_method_ambiguous.rs#next
- tests/ui/impl-trait/dyn-trait-elided-two-inputs-ref-assoc.rs#next
- tests/ui/impl-trait/hidden-type-is-opaque-2.rs#next
- tests/ui/impl-trait/in-trait/alias-bounds-when-not-wf.rs
- tests/ui/impl-trait/in-trait/default-body-with-rpit.rs#next
- tests/ui/impl-trait/in-trait/dyn-compatibility-sized.rs#next
- tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.rs#next
- tests/ui/impl-trait/in-trait/refine-normalize.rs#next
- tests/ui/impl-trait/issue-103181-1.rs#next
- tests/ui/impl-trait/method-resolution2.rs#next
- tests/ui/impl-trait/recursive-bound-eval.rs#next
- tests/ui/impl-trait/unsized_coercion.rs#next
- tests/ui/issues/issue-15734.rs#next
- tests/ui/methods/fulfillment-disqualifies-method.rs#next
- tests/ui/methods/leak-check-disquality.rs#next
- tests/ui/nll/check-normalized-sig-for-wf.rs#next
- tests/ui/panics/abort-on-panic.rs#next
- tests/ui/specialization/source-impl-requires-constraining-predicates.rs#next
- tests/ui/specialization/source-impl-requires-constraining-predicates-ambig.rs#next
- tests/ui/specialization/specialization-default-items-drop-coherence.rs#next
- tests/ui/traits/const-traits/assoc-type-const-bound-usage-0.rs#next
- tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.rs#next
- tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail.rs#next
- tests/ui/traits/const-traits/assoc-type.rs#next
- tests/ui/traits/const-traits/call-const-in-tilde-const.rs
- tests/ui/traits/const-traits/call-generic-method-dup-bound.rs
- tests/ui/traits/const-traits/call-generic-method-nonconst.rs
- tests/ui/traits/const-traits/const-bound-in-host.rs
- tests/ui/traits/const-traits/const-bound-on-not-const-associated-fn.rs
- tests/ui/traits/const-traits/const-cond-for-rpitit.rs
- tests/ui/traits/const-traits/const-drop-fail.rs#new_precise
- tests/ui/traits/const-traits/const-drop-fail.rs#new_stock
- tests/ui/traits/const-traits/const-drop.rs#precise
- tests/ui/traits/const-traits/const-drop.rs#stock
- tests/ui/traits/const-traits/const-in-closure.rs
- tests/ui/traits/const-traits/const-opaque.rs#no
- tests/ui/traits/const-traits/const-impl-trait.rs
- tests/ui/traits/const-traits/const-opaque.rs#yes
- tests/ui/traits/const-traits/dont-ice-on-const-pred-for-bounds.rs
- tests/ui/traits/const-traits/infer-fallback.rs
- tests/ui/traits/const-traits/issue-92230-wf-super-trait-env.rs
- tests/ui/traits/const-traits/item-bound-entailment-fails.rs
- tests/ui/traits/const-traits/item-bound-entailment.rs
- tests/ui/traits/const-traits/minicore-drop-without-feature-gate.rs#no
- tests/ui/traits/const-traits/minicore-deref-fail.rs
- tests/ui/traits/const-traits/minicore-const-fn-early-bound.rs
- tests/ui/traits/const-traits/minicore-drop-fail.rs
- tests/ui/traits/const-traits/minicore-drop-without-feature-gate.rs#yes
- tests/ui/traits/const-traits/minicore-fn-fail.rs
- tests/ui/traits/const-traits/minicore-works.rs
- tests/ui/traits/const-traits/predicate-entailment-passes.rs
- tests/ui/traits/const-traits/predicate-entailment-fails.rs
- tests/ui/traits/const-traits/super-traits-fail-2.rs#nn
- tests/ui/traits/const-traits/super-traits-fail-2.rs#ny
- tests/ui/traits/const-traits/staged-api.rs
- tests/ui/traits/const-traits/super-traits-fail-3.rs#nnn
- tests/ui/traits/const-traits/super-traits-fail-2.rs#yn
- tests/ui/traits/const-traits/super-traits-fail-2.rs#yy
- tests/ui/traits/const-traits/super-traits-fail-3.rs#nny
- tests/ui/traits/const-traits/super-traits-fail-3.rs#nyy
- tests/ui/traits/const-traits/super-traits-fail-3.rs#nyn
- tests/ui/traits/const-traits/super-traits-fail-3.rs#yyy
- tests/ui/traits/const-traits/super-traits-fail-3.rs#ynn
- tests/ui/traits/const-traits/super-traits-fail-3.rs#yyn
- tests/ui/traits/const-traits/super-traits-fail-3.rs#yny
- tests/ui/traits/const-traits/super-traits.rs
- tests/ui/traits/const-traits/tilde-const-assoc-fn-in-trait-impl.rs
- tests/ui/traits/const-traits/tilde-const-inherent-assoc-const-fn.rs
- tests/ui/traits/const-traits/tilde-const-in-struct-args.rs
- tests/ui/traits/const-traits/trait-where-clause-self-referential.rs
- tests/ui/traits/const-traits/trait-where-clause-const.rs
- tests/ui/traits/const-traits/unsatisfied-const-trait-bound.rs
- tests/ui/traits/negative-bounds/opaque-type-unsatisfied-bound.rs
- tests/ui/traits/negative-impls/negative-impl-normalizes-to.rs#next
- tests/ui/traits/next-solver/alias-bound-preference.rs#next
- tests/ui/traits/next-solver/alias-relate/alias_eq_cant_be_furthur_normalized.rs
- tests/ui/traits/next-solver/alias-eq-in-canonical-response.rs
- tests/ui/traits/next-solver/alias-bound-unsound.rs
- tests/ui/traits/next-solver/alias-relate/alias_eq_simple.rs
- tests/ui/traits/next-solver/alias-relate/opaque-hidden-ty-is-rigid-alias.rs
- tests/ui/traits/next-solver/alias-sub.rs
- tests/ui/traits/next-solver/alias-relate/deeply-nested-no-hang.rs
- tests/ui/traits/next-solver/assembly/ambig-projection-self-is-ambig.rs
- tests/ui/traits/next-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs
- tests/ui/traits/next-solver/assembly/candidates-equal-modulo-norm-1.rs
- tests/ui/traits/next-solver/async.rs#fail
- tests/ui/traits/next-solver/assembly/candidates-equal-modulo-norm-2.rs
- tests/ui/traits/next-solver/async.rs#pass
- tests/ui/traits/next-solver/assembly/param-env-alias-bound-conflict.rs
- tests/ui/traits/next-solver/auto-with-drop_tracking_mir.rs#pass
- tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.rs
- tests/ui/traits/next-solver/auto-with-drop_tracking_mir.rs#fail
- tests/ui/traits/next-solver/canonical/effect-var.rs
- tests/ui/traits/next-solver/canonical/int-var-eq-in-response.rs
- tests/ui/traits/next-solver/builtin-fn-must-return-sized.rs
- tests/ui/traits/next-solver/closure-inference-guidance.rs
- tests/ui/traits/next-solver/closure-signature-inference-2.rs
- tests/ui/traits/next-solver/closure-signature-inference-hr-ambig-alias-naming-self.rs#next
- tests/ui/traits/next-solver/coerce-ambig-alias-to-rigid-alias.rs
- tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.rs
- tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-1.rs
- tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-3.rs
- tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-2.rs
- tests/ui/traits/next-solver/const-param-placeholder.rs#pass
- tests/ui/traits/next-solver/const-param-placeholder.rs#fail
- tests/ui/traits/next-solver/constrain-alias-goals-in-unsize.rs
- tests/ui/traits/next-solver/coroutine.rs#pass
- tests/ui/traits/next-solver/coroutine.rs#fail
- tests/ui/traits/next-solver/cycles/coinduction/fixpoint-exponential-growth.rs
- tests/ui/traits/next-solver/cycles/double-cycle-inductive-coinductive.rs
- tests/ui/traits/next-solver/cycles/inductive-cycle-but-err.rs
- tests/ui/traits/next-solver/cycles/inductive-cycle-but-ok.rs
- tests/ui/traits/next-solver/cycles/inductive-fixpoint-hang.rs
- tests/ui/traits/next-solver/cycles/leak-check-coinductive-cycle.rs
- tests/ui/traits/next-solver/cycles/inductive-not-on-stack.rs
- tests/ui/traits/next-solver/cycles/mixed-cycles-1.rs
- tests/ui/traits/next-solver/cycles/mixed-cycles-2.rs
- tests/ui/traits/next-solver/cycles/provisional-cache-impacts-behavior.rs
- tests/ui/traits/next-solver/cycles/provisional-result-done.rs
- tests/ui/traits/next-solver/cycles/cycle-modulo-ambig-aliases.rs
- tests/ui/traits/next-solver/destruct.rs
- tests/ui/traits/next-solver/diagnostics/alias_relate_error_uses_structurally_normalize.rs
- tests/ui/traits/next-solver/diagnostics/deeply-normalize-type-expectation.rs
- tests/ui/traits/next-solver/diagnostics/coerce-in-may-coerce.rs
- tests/ui/traits/next-solver/diagnostics/point-at-failing-nested.rs
- tests/ui/traits/next-solver/diagnostics/projection-trait-ref.rs
- tests/ui/traits/next-solver/diagnostics/dont-pick-fnptr-bound-as-leaf.rs#next
- tests/ui/traits/next-solver/dont-loop-fulfill-on-region-constraints.rs
- tests/ui/traits/next-solver/elaborate-item-bounds.rs
- tests/ui/traits/next-solver/dont-normalize-proj-with-error.rs
- tests/ui/traits/next-solver/dyn-incompatibility.rs
- tests/ui/traits/next-solver/fn-trait-closure.rs
- tests/ui/traits/next-solver/fn-trait.rs
- tests/ui/traits/next-solver/generalize/bivariant-alias.rs#next
- tests/ui/traits/next-solver/generalize/equating-projection-cyclically.rs
- tests/ui/traits/next-solver/generalize/hr-alias-non-hr-alias-self-ty-1.rs#next
- tests/ui/traits/next-solver/generalize/hr-alias-universe-lowering-ambiguity.rs
- tests/ui/traits/next-solver/generalize/occurs-check-nested-alias.rs#next
- tests/ui/traits/next-solver/generalize/instantiate-canonical-occurs-check-failure.rs
- tests/ui/traits/next-solver/generalize/hr-alias-non-hr-alias-self-ty-2.rs#next
- tests/ui/traits/next-solver/higher-ranked-dyn-bounds.rs
- tests/ui/traits/next-solver/issue-118950-root-region.rs
- tests/ui/traits/next-solver/iter-filter-projection.rs
- tests/ui/traits/next-solver/lazy-nested-obligations-2.rs
- tests/ui/traits/next-solver/lazy-nested-obligations-3.rs
- tests/ui/traits/next-solver/nested-obligations-with-bound-vars-gat.rs
- tests/ui/traits/next-solver/nested-alias-bound.rs
- tests/ui/traits/next-solver/method/path_lookup_wf_constraints.rs
- tests/ui/traits/next-solver/non-wf-ret.rs
- tests/ui/traits/next-solver/normalization-shadowing/alias-bound-shadowed-by-env.rs
- tests/ui/traits/next-solver/normalization-shadowing/discard-impls-shadowed-by-env-1.rs
- tests/ui/traits/next-solver/normalization-shadowing/discard-impls-shadowed-by-env-3.rs
- tests/ui/traits/next-solver/normalization-shadowing/discard-impls-shadowed-by-env-2.rs#next
- tests/ui/traits/next-solver/normalization-shadowing/param-env-impl-conflict.rs
- tests/ui/traits/next-solver/normalization-shadowing/normalizes_to_ignores_unnormalizable_candidate.rs
- tests/ui/traits/next-solver/normalization-shadowing/param-candidate-shadows-project.rs
- tests/ui/traits/next-solver/normalize-in-implied_outlives_bounds.rs
- tests/ui/traits/next-solver/normalize/normalize-param-env-3.rs
- tests/ui/traits/next-solver/normalize/normalize-param-env-1.rs
- tests/ui/traits/next-solver/normalize/normalize-async-closure-in-trait.rs
- tests/ui/traits/next-solver/normalize/normalize-param-env-2.rs
- tests/ui/traits/next-solver/normalize/normalize-param-env-4.rs#next
- tests/ui/traits/next-solver/normalize/normalize-rcvr-for-inherent.rs
- tests/ui/traits/next-solver/normalize/normalize-path-for-method.rs
- tests/ui/traits/next-solver/normalize/normalize-region-obligations.rs#hrtb
- tests/ui/traits/next-solver/normalize/normalize-region-obligations.rs#normalize_obligation
- tests/ui/traits/next-solver/normalize/normalize-region-obligations.rs#normalize_param_env
- tests/ui/traits/next-solver/normalize/normalize-type-outlives-in-param-env.rs
- tests/ui/traits/next-solver/normalize/ambig-goal-infer-in-type-oulives.rs
- tests/ui/traits/next-solver/normalize/param-env-trait-candidate-2.rs
- tests/ui/traits/next-solver/normalize/two-projection-param-candidates-are-ambiguous.rs
- tests/ui/traits/next-solver/opaques/dont-remap-tait-substs.rs
- tests/ui/traits/next-solver/opaques/select-alias-bound-as-param.rs
- tests/ui/traits/next-solver/opportunistic-region-resolve.rs
- tests/ui/traits/next-solver/opaques/no-define-in-wf-check.rs#next
- tests/ui/traits/next-solver/overflow/exponential-trait-goals.rs
- tests/ui/traits/next-solver/normalize/param-env-trait-candidate-1.rs
- tests/ui/traits/next-solver/overflow/global-cache.rs
- tests/ui/traits/next-solver/overflow/nalgebra-hang.rs#next
- tests/ui/traits/next-solver/overflow/recursive-self-normalization.rs
- tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.rs
- tests/ui/traits/next-solver/pointee.rs
- tests/ui/traits/next-solver/pointer-like.rs
- tests/ui/traits/next-solver/prefer-candidate-no-constraints.rs
- tests/ui/traits/next-solver/prefer-param-env-on-ambiguity.rs
- tests/ui/traits/next-solver/projection-discr-kind.rs
- tests/ui/traits/next-solver/specialization-unconstrained.rs
- tests/ui/traits/next-solver/specialization-transmute.rs
- tests/ui/traits/next-solver/typeck/guide-ctors.rs
- tests/ui/traits/next-solver/try-example.rs
- tests/ui/traits/next-solver/typeck/normalize-in-upvar-collection.rs
- tests/ui/traits/next-solver/typeck/resolve-before-checking-builtin-ptr.rs
- tests/ui/traits/next-solver/typeck/resolve-before-checking-never.rs
- tests/ui/traits/next-solver/typeck/structurally-resolve-in-probe_adt.rs
- tests/ui/traits/next-solver/typeck/resolve-expectations.rs
- tests/ui/traits/next-solver/winnow-specializing-impls.rs
- tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.rs#next
- tests/ui/traits/normalize-supertrait.rs#next
- tests/ui/traits/pointee-normalize-equate.rs#next
- tests/ui/traits/reservation-impl/non-lattice-ok.rs#next
- tests/ui/traits/trait-upcasting/impossible-method-modulo-binders-2.rs#next
- tests/ui/traits/trait-upcasting/impossible-method-modulo-binders.rs#next
- tests/ui/traits/trait-upcasting/normalization.rs#next
- tests/ui/traits/trait-upcasting/prefer-lower-candidates.rs#next
- tests/ui/traits/winnowing/global-non-global-env-1.rs#next
- tests/ui/traits/winnowing/global-non-global-env-3.rs#next
- tests/ui/traits/winnowing/global-non-global-env-2.rs#next
- tests/ui/traits/winnowing/global-non-global-env-4.rs#next
- tests/ui/transmutability/primitives/bool.rs#next
- tests/ui/transmutability/primitives/unit.rs#next
- tests/ui/type-alias-impl-trait/assoc-type-const.rs#next
- tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs#next
- tests/ui/type-alias-impl-trait/issue-78450.rs#next
- tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs#next
- tests/ui/type-alias-impl-trait/method_resolution3.rs#next
- tests/ui/type-alias-impl-trait/method_resolution4.rs#next
- tests/ui/type-alias-impl-trait/nested_inference_failure.rs#next
- tests/ui/type-alias-impl-trait/normalize-hidden-types.rs#next
- tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs#next
- tests/ui/typeck/bad-index-due-to-nested.rs#next
- tests/ui/typeck/issue-116864.rs
- tests/ui/unsized/issue-75899.rs#next
- tests/ui/transmutability/primitives/numbers.rs#next
- tests/ui/wf/wf-in-where-clause-static.rs#next
When evaluating a host effect predicate on an opaque in `addr2line`,
running `evaluate_host_effect_from_bounds` first would create an opaque
type which wouldn't be removed from opaque type storage and that would
cause a delayed bug - creating a small reproduction of this has been
tricky but if `builtin_impls` checking is moved below
`evaluate_host_effect_from_item_bounds` then it will trigger.

The correct fix is probably to work out why the opaque type is created
and then not used, but this was particularly tricky. Given that this root
cause wasn't identified, writing a test case proved difficult.
Now that sizedness traits have been made const, pretty printing of impl
headers should print the constness of the sizedness trait.
These traits are now const and that needs to be reflected in their
printing in opaques.
This causes a bunch of tests to fail and everything appears to work
without it:

- tests/ui/coherence/orphan-check-opaque-types-not-covering.rs
- tests/ui/coherence/orphan-check-projections-covering.rs
- tests/ui/coherence/orphan-check-projections-unsat-bounds.rs#classic
- tests/ui/coherence/orphan-check-weak-aliases-not-covering.rs
- tests/ui/coherence/orphan-check-weak-aliases-covering.rs#classic
- tests/ui/specialization/issue-43037.rs#negative
- tests/ui/specialization/issue-43037.rs#current
- tests/ui/type-alias-impl-trait/coherence.rs#classic
These tests just need blessing, they don't have any interesting behaviour
changes.
Its strange to have to import sizedness traits, so add them to the
prelude in the next edition.
Implement the edition migration required by these changes - `?Sized`
becoming `const MetaSized`, `Sized` becoming `const Sized` and a
`const MetaSized` supertrait.
This should have been included in rust-lang#137606.
This test no longer crashes the compiler as `Box` no longer accepts
`PointeeSized`-types. It eventually could, but not because of
`Deref::Target` currently, so this doesn't fail anymore and there wasn't
an obvious to add new types to make it continue to fail because `Deref`
is special.
Some rustdoc tests are `no_core` and need to have `MetaSized` and
`PointeeSized` added to them. One or two tests used extern types and
needed further relaxations to work as before.
These should never be shown to users at the moment.
One clippy test is `no_core` and needs to have `MetaSized` and
`PointeeSized` added to it.
Existing lints that had special-casing for `Sized` predicates ought
to have these same special cases applied to `MetaSized` predicates.
Unexpected Clippy lint triggering is fixed in previous commits but
is necessary for `cfg(bootstrap)`.
It's unclear why this change in miri is necessary.
These error messages include lines of the standard library which have
changed and so need updated.
Unstability is propagated when staged API is not used and
`-Zforce-unstable-if-unmarked` is, but this only happened for const
functions not const traits, which ends up being an issue for some of the
minicore tests of codegen backends when introducing the sizedness traits.
As in many previous commits, adding the new traits and constness to
the minicore.
@bors

This comment was marked as resolved.

@bors
Copy link
Contributor

bors commented Mar 7, 2025

☔ The latest upstream changes (presumably #138155) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@fee1-dead fee1-dead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had an initial look until the "library/compiler" commit. Will look more into it later.

@@ -625,6 +633,24 @@ impl<'tcx> AdtDef<'tcx> {
pub fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> Option<ty::EarlyBinder<'tcx, Ty<'tcx>>> {
if self.is_struct() { tcx.adt_sized_constraint(self.did()) } else { None }
}

/// Returns a type such that `Self: MetaSized` if and only if that type is `MetaSized`,
/// or `None` if the type is always metasized.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should capitalize MetaSized here

}

/// Returns a type such that `Self: PointeeSized` if and only if that type is `PointeeSized`,
/// or `None` if the type is always pointeesized.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above


/// Returns a type such that `Self: PointeeSized` if and only if that type is `PointeeSized`,
/// or `None` if the type is always pointeesized.
pub fn pointeesized_constraint(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I think this should be named as pointee_sized_constraint for better readability? Same goes for meta_sized_constraint

Comment on lines +170 to +174
// impl {Meta,Pointee,}Sized for str, [T], dyn Trait
ty::Str | ty::Slice(_) | ty::Dynamic(..) => match sizedness {
Sizedness::Sized => Err(NoSolution),
Sizedness::MetaSized | Sizedness::PointeeSized => Ok(ty::Binder::dummy(vec![])),
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is something like [str] PointeeSized? Might be a dumb question since that's probably not well-formed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, everything is PointeeSized.

Comment on lines +191 to +192
// impl {Meta,}Sized for ()
// impl {Meta,}Sized for (T1, T2, .., Tn) where Tn: {Meta,}Sized if n >= 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these missing the `{Meta,Pointee,} or intentional?


/// Which sizedness trait - `Sized`, `MetaSized` or `PointeeSized`?
#[derive(Copy, Clone, Debug)]
pub enum Sizedness {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer it to be named as SizedTraitKind.

needs_pointeesized::<([u8], [u8])>();
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time

// tuple w/ all elements unsized
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be PointeeSized

needs_metasized::<(u32, [u8])>();
needs_pointeesized::<(u32, [u8])>();

// tuple w/ last element unsized
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PointeeSized

Comment on lines +237 to +241
struct StructAllFieldsMetaSized { x: [u8], y: [u8] }
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
needs_sized::<StructAllFieldsMetaSized>();
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
needs_metasized::<StructAllFieldsMetaSized>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused as to what this achieves with this kind of type implementing MetaSized, although that is what is described in the RfC..

Comment on lines +268 to +271
/// Trait for comparisons using the equality operator.
///
/// Implementing this trait for types provides the `==` and `!=` operators for
/// those types.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need docs for cfg(bootstrap)ed items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-run-make Area: port run-make Makefiles to rmake.rs A-rustdoc-json Area: Rustdoc JSON backend A-rustdoc-search Area: Rustdoc's search feature PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE with unsizing an extern type
8 participants