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

Install projection from RPITIT to default trait method opaque correctly #109198

Merged
merged 9 commits into from
Mar 17, 2023

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Mar 16, 2023

  1. For new lowering strategy -Zlower-impl-trait-in-trait-to-assoc-ty, install the correct default trait method projection predicates (RPITIT -> opaque). This makes default trait body tests pass!

  2. Fix two WF-checking bugs -- first, we want to make sure that we're always looking for an opaque type in check_return_position_impl_trait_in_trait_bounds. That's because the RPITIT projections are normalized to opaques during wfcheck. Second, fix RPITIT's param-envs by not adding the projection predicates that we install on trait methods to make default RPITITs work -- I left a comment why.

  3. Also, just a small drive-by for rustc_on_unimplemented. Not sure if it affects any tests, but can't hurt.

r? @spastorino, based off of #109140

@rustbot rustbot added 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-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 16, 2023
@compiler-errors
Copy link
Member Author

@rustbot author

Actually don't think we need some of this stuff I'm doing here.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 16, 2023
@compiler-errors
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 16, 2023
@compiler-errors
Copy link
Member Author

Sorry, second commit is mistitled -- should probably be something like "fix param-env and wfcheck for default trait body RPITITs", but I'm going to sleep.

// get out of alignment, or else we do actually need to substitute these predicates.
if let Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) = tcx.opt_rpitit_info(def_id) {
predicates = tcx.predicates_of(fn_def_id).instantiate_identity(tcx).predicates;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this part of the change is what makes the tests included in this commit pass, right?.

Copy link
Member Author

Choose a reason for hiding this comment

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

both changes are needed to make the test pass, otherwise the error message goes from a "needs type info" error to a wfchecking error, iirc.

&& let Some(opaque_def_id) = opaque_ty.def_id.as_local()
&& let opaque = tcx.hir().expect_item(opaque_def_id).expect_opaque_ty()
&& let hir::OpaqueTyOrigin::FnReturn(source) | hir::OpaqueTyOrigin::AsyncFn(source) = opaque.origin
&& source == fn_def_id
Copy link
Member

Choose a reason for hiding this comment

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

If I understand correct this is equivalent to what was before but done a little bit better, or are there actual difference? if so in which cases?.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not equivalent. If we call is_impl_trait_in_trait on an opaque def id, then it returns false.

Copy link
Member Author

Choose a reason for hiding this comment

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

Without this, some tests begin to spuriously pass wfcheck.

Copy link
Member Author

@compiler-errors compiler-errors Mar 16, 2023

Choose a reason for hiding this comment

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

the first commit in the stack "breaks" tests/ui/impl-trait/in-trait/wf-bounds.rs by actually projecting the RPITIT to a real opaque type, so this commit fixes the test by always checking for an opaque type.

Copy link
Member

Choose a reason for hiding this comment

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

the first commit in the stack "breaks" tests/ui/impl-trait/in-trait/wf-bounds.rs by actually projecting the RPITIT to a real opaque type, so this commit fixes the test by always checking for an opaque type.

Ahh right, because we project the projection to an opaque, that's the thing.

if let Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) = tcx.opt_rpitit_info(def_id) {
return tcx.param_env(fn_def_id);
}

// Compute the bounds on Self and the type parameters.
let ty::InstantiatedPredicates { mut predicates, .. } =
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't be more clear if this is an else of the if let from below?.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that works too.

@spastorino
Copy link
Member

This looks good to me, r=me after mine is merged and rebased.

@compiler-errors
Copy link
Member Author

@bors r=spastorino

@bors
Copy link
Contributor

bors commented Mar 16, 2023

📌 Commit 8d922eb has been approved by spastorino

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 16, 2023
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Mar 16, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 16, 2023
…-body, r=spastorino

Install projection from RPITIT to default trait method opaque correctly

1. For new lowering strategy `-Zlower-impl-trait-in-trait-to-assoc-ty`, install the correct default trait method projection predicates (RPITIT -> opaque). This makes default trait body tests pass!

2. Fix two WF-checking bugs -- first, we want to make sure that we're always looking for an opaque type in `check_return_position_impl_trait_in_trait_bounds`. That's because the RPITIT projections are normalized to opaques during wfcheck. Second, fix RPITIT's param-envs by not adding the projection predicates that we install on trait methods to make default RPITITs work -- I left a comment why.

3. Also, just a small drive-by for `rustc_on_unimplemented`. Not sure if it affects any tests, but can't hurt.

r? `@spastorino,` based off of rust-lang#109140
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 17, 2023
…-body, r=spastorino

Install projection from RPITIT to default trait method opaque correctly

1. For new lowering strategy `-Zlower-impl-trait-in-trait-to-assoc-ty`, install the correct default trait method projection predicates (RPITIT -> opaque). This makes default trait body tests pass!

2. Fix two WF-checking bugs -- first, we want to make sure that we're always looking for an opaque type in `check_return_position_impl_trait_in_trait_bounds`. That's because the RPITIT projections are normalized to opaques during wfcheck. Second, fix RPITIT's param-envs by not adding the projection predicates that we install on trait methods to make default RPITITs work -- I left a comment why.

3. Also, just a small drive-by for `rustc_on_unimplemented`. Not sure if it affects any tests, but can't hurt.

r? ``@spastorino,`` based off of rust-lang#109140
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 17, 2023
…-body, r=spastorino

Install projection from RPITIT to default trait method opaque correctly

1. For new lowering strategy `-Zlower-impl-trait-in-trait-to-assoc-ty`, install the correct default trait method projection predicates (RPITIT -> opaque). This makes default trait body tests pass!

2. Fix two WF-checking bugs -- first, we want to make sure that we're always looking for an opaque type in `check_return_position_impl_trait_in_trait_bounds`. That's because the RPITIT projections are normalized to opaques during wfcheck. Second, fix RPITIT's param-envs by not adding the projection predicates that we install on trait methods to make default RPITITs work -- I left a comment why.

3. Also, just a small drive-by for `rustc_on_unimplemented`. Not sure if it affects any tests, but can't hurt.

r? ```@spastorino,``` based off of rust-lang#109140
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 17, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#108958 (Remove box expressions from HIR)
 - rust-lang#109044 (Prevent stable `libtest` from supporting `-Zunstable-options`)
 - rust-lang#109155 (Fix riscv64 fuchsia LLVM target name)
 - rust-lang#109156 (Fix linker detection for clang with prefix)
 - rust-lang#109181 (inherit_overflow: adapt pattern to also work with v0 mangling)
 - rust-lang#109198 (Install projection from RPITIT to default trait method opaque correctly)
 - rust-lang#109215 (Use sort_by_key instead of sort_by)
 - rust-lang#109229 (Fix invalid markdown link references)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 246d989 into rust-lang:master Mar 17, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 17, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 17, 2023
…er-errors

Add revisions for -Zlower-impl-trait-in-trait-to-assoc-ty fixed tests

Needs to go on top of rust-lang#109198

r? `@compiler-errors`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 17, 2023
…er-errors

Add revisions for -Zlower-impl-trait-in-trait-to-assoc-ty fixed tests

Needs to go on top of rust-lang#109198

r? `@compiler-errors`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 18, 2023
…er-errors

Add revisions for -Zlower-impl-trait-in-trait-to-assoc-ty fixed tests

Needs to go on top of rust-lang#109198

r? ``@compiler-errors``
@compiler-errors compiler-errors deleted the new-rpitit-default-body branch August 11, 2023 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants