-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Install projection from RPITIT to default trait method opaque correctly #109198
Conversation
@rustbot author Actually don't think we need some of this stuff I'm doing here. |
e41f976
to
8d922eb
Compare
@rustbot ready |
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; | ||
} |
There was a problem hiding this comment.
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?.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, .. } = |
There was a problem hiding this comment.
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?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that works too.
This looks good to me, r=me after mine is merged and rebased. |
@bors r=spastorino |
…-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
…-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
…-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
…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
…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`
…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`
…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``
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!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.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