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

Shorthand projections inside RPITITs fail to resolve #132372

Closed
Vollbrecht opened this issue Oct 30, 2024 · 4 comments · Fixed by #132373
Closed

Shorthand projections inside RPITITs fail to resolve #132372

Vollbrecht opened this issue Oct 30, 2024 · 4 comments · Fixed by #132373
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) A-type-system Area: Type system C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@Vollbrecht
Copy link

Vollbrecht commented Oct 30, 2024

Recent rust nigthly version can't compile previously working code, duo to compiler not being able to find associated type inside a "async fn in trait" definition.

Code

Compiling this code:

#![allow(async_fn_in_trait)]
pub trait foo {}

pub trait bar {
    type foo: foo;
}
pub trait baz {
    async fn boom<X: bar>() -> Result<(), X::foo>;
}

I expected to see this happen: In previous version up to nightly-2024-10-28 this code compiled

Instead, this happened: It stoped compiling with the error

error[E0220]: associated type `foo` not found for `X`
8 |     async fn boom<X: bar>() -> Result<(), X::foo>;
  |                                              ^^^ there is an associated type `foo` in the trait `bar`

Version it worked on

nightly-2024-10-28

Version with regression

nightly-2024-10-29

rustc --version --verbose:

rustc 1.84.0-nightly (1e4f10ba6 2024-10-29)
binary: rustc
commit-hash: 1e4f10ba6476e48a42a79b9f846a2d9366525b9e
commit-date: 2024-10-29
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

No, code just stops compiling.

@Vollbrecht Vollbrecht added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Oct 30, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 30, 2024
@fmease fmease added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-async-await Area: Async & Await A-associated-items Area: Associated items (types, constants & functions) and removed regression-untriaged Untriaged performance or correctness regression. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 30, 2024
@Dirbaio
Copy link
Contributor

Dirbaio commented Oct 30, 2024

minimized it a bit more: playground

#![allow(async_fn_in_trait)]

pub trait Bar {
    type Foo;
}

pub trait Baz {
    async fn boom<X: Bar>() -> X::Foo;
}

bisected:

searched nightlies: from nightly-2024-10-28 to nightly-2024-10-30
regressed nightly: nightly-2024-10-30
searched commit range: 3f1be1e...1e4f10b
regressed commit: 2dece5b

Regression in rust-lang-ci@96aebe2
The PR introducing the regression in this rollup is #132194: Collect item bounds for RPITITs from trait where clauses ju…

@fmease
Copy link
Member

fmease commented Oct 30, 2024

cc @compiler-errors

@fmease
Copy link
Member

fmease commented Oct 30, 2024

Alt:

pub trait Bar {
    type Foo;
}

pub trait Baz {
    fn boom<X: Bar>() -> impl std::future::Future<Output = X::Foo>; //~ ERROR associated type `Foo` not found for `X`
}

@compiler-errors
Copy link
Member

@rustbot claim

@fmease fmease removed the A-async-await Area: Async & Await label Oct 30, 2024
@fmease fmease changed the title async fn in trait cannot find associated type in trait error Shorthand projections inside RPITITs fail to resolve Oct 30, 2024
@fmease fmease added A-type-system Area: Type system T-types Relevant to the types team, which will review and decide on the PR/issue. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue S-has-bisection Status: a bisection has been found for this issue labels Oct 30, 2024
@bors bors closed this as completed in efd5645 Oct 31, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 31, 2024
Rollup merge of rust-lang#132373 - compiler-errors:rpitit-bound, r=fmease

Make sure `type_param_predicates` resolves correctly for RPITIT

After rust-lang#132194, we end up lowering the item bounds for an RPITIT in an `ItemCtxt` whose def id is the *synthetic GAT*, not the opaque type from the HIR.

This means that when we're resolving a shorthand projection like `T::Assoc`, we call the `type_param_predicates` function with the `item_def_id` of the *GAT* and not the opaque. That function operates on the HIR, and is not designed to work with the `Node::Synthetic` that gets fed for items synthesized by the compiler...

This PR reuses the trick we use elsewhere in lowering, where we intercept whether an item comes from RPITIT lowering, and forwards the query off to the correct item.

Fixes rust-lang#132372
@fmease fmease removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-type-system Area: Type system C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants