Skip to content

coercion ?0: Sized check, rewrite to not rely on fulfill internals #104490

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

Open
lcnr opened this issue Nov 16, 2022 · 1 comment
Open

coercion ?0: Sized check, rewrite to not rely on fulfill internals #104490

lcnr opened this issue Nov 16, 2022 · 1 comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-types Relevant to the types team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Comments

@lcnr
Copy link
Contributor

lcnr commented Nov 16, 2022

The behavior of fn coerce_unsized for some inference variable ?0 changes depending on whether there's a pending ?0: Sized obligation in the fulfillment context:

match selcx.select(&obligation.with(trait_pred)) {
// Uncertain or unimplemented.
Ok(None) => {
if trait_pred.def_id() == unsize_did {
let trait_pred = self.resolve_vars_if_possible(trait_pred);
let self_ty = trait_pred.skip_binder().self_ty();
let unsize_ty = trait_pred.skip_binder().trait_ref.substs[1].expect_ty();
debug!("coerce_unsized: ambiguous unsize case for {:?}", trait_pred);
match (&self_ty.kind(), &unsize_ty.kind()) {
(ty::Infer(ty::TyVar(v)), ty::Dynamic(..))
if self.type_var_is_sized(*v) =>

This pending obligation can be a nested obligation, e.g. we may have only added a Vec<?0>: Debug obligation to the fulfillment context. But proving that adds a nested ?0: Sized obligation from the impl candidate to the FulfillmentContext, which then influences coercion.

As our new solver should try to fully prove obligations instead of selecting a candidate and adding nested obligations to the root, this has to change.

cc @rust-lang/initiative-trait-system-refactor

@lcnr lcnr added T-types Relevant to the types team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Nov 16, 2022
@compiler-errors
Copy link
Member

#50753 is related

@Enselic Enselic added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-types Relevant to the types team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

No branches or pull requests

3 participants