Skip to content

fix: Fix retrieval of AsyncFnOnce::Output #829

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

Merged
merged 1 commit into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion chalk-integration/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use chalk_ir::{
use chalk_solve::rust_ir::{
AdtDatum, AdtRepr, AdtSizeAlign, AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId,
ClosureKind, CoroutineDatum, CoroutineWitnessDatum, FnDefDatum, FnDefInputsAndOutputDatum,
ImplDatum, OpaqueTyDatum, TraitDatum, WellKnownTrait,
ImplDatum, OpaqueTyDatum, TraitDatum, WellKnownAssocType, WellKnownTrait,
};
use chalk_solve::{RustIrDatabase, Solution, SubstitutionResult};
use salsa::Database;
Expand Down Expand Up @@ -183,6 +183,15 @@ impl RustIrDatabase<ChalkIr> for ChalkDatabase {
.well_known_trait_id(well_known_trait)
}

fn well_known_assoc_type_id(
&self,
assoc_type: WellKnownAssocType,
) -> Option<AssocTypeId<ChalkIr>> {
self.program_ir()
.unwrap()
.well_known_assoc_type_id(assoc_type)
}

fn program_clauses_for_env(
&self,
environment: &Environment<ChalkIr>,
Expand Down
8 changes: 8 additions & 0 deletions chalk-integration/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,14 @@ impl RustIrDatabase<ChalkIr> for Program {
self.well_known_traits.get(&well_known_trait).copied()
}

fn well_known_assoc_type_id(
&self,
_assoc_type: chalk_solve::rust_ir::WellKnownAssocType,
) -> Option<AssocTypeId<ChalkIr>> {
// FIXME
None
}

fn program_clauses_for_env(
&self,
environment: &chalk_ir::Environment<ChalkIr>,
Expand Down
13 changes: 4 additions & 9 deletions chalk-solve/src/clauses/builtin_traits/fn_family.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::clauses::ClauseBuilder;
use crate::rust_ir::{ClosureKind, FnDefInputsAndOutputDatum, WellKnownTrait};
use crate::rust_ir::{ClosureKind, FnDefInputsAndOutputDatum, WellKnownAssocType, WellKnownTrait};
use crate::{Interner, RustIrDatabase, TraitRef};
use chalk_ir::cast::Cast;
use chalk_ir::{
Expand Down Expand Up @@ -83,14 +83,9 @@ fn push_clauses<I: Interner>(

if let WellKnownTrait::AsyncFnOnce = well_known {
builder.push_bound_ty(|builder, ty| {
let trait_datum = db.trait_datum(trait_id);
assert_eq!(
trait_datum.associated_ty_ids.len(),
2,
"AsyncFnOnce trait should have exactly two associated types, found {:?}",
trait_datum.associated_ty_ids
);
let output_id = trait_datum.associated_ty_ids[1];
let output_id = db
.well_known_assoc_type_id(WellKnownAssocType::AsyncFnOnceOutput)
.unwrap();
let async_alias = AliasTy::Projection(ProjectionTy {
associated_ty_id: output_id,
substitution,
Expand Down
7 changes: 7 additions & 0 deletions chalk-solve/src/display/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ impl<I: Interner, DB: RustIrDatabase<I>> RustIrDatabase<I> for StubWrapper<'_, D
self.db.well_known_trait_id(well_known_trait)
}

fn well_known_assoc_type_id(
&self,
assoc_type: crate::rust_ir::WellKnownAssocType,
) -> Option<chalk_ir::AssocTypeId<I>> {
self.db.well_known_assoc_type_id(assoc_type)
}

fn program_clauses_for_env(
&self,
environment: &chalk_ir::Environment<I>,
Expand Down
3 changes: 3 additions & 0 deletions chalk-solve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ pub trait RustIrDatabase<I: Interner>: Debug {
/// Returns id of a trait lang item, if found
fn well_known_trait_id(&self, well_known_trait: WellKnownTrait) -> Option<TraitId<I>>;

/// Returns id of a associated type, if found.
fn well_known_assoc_type_id(&self, assoc_type: WellKnownAssocType) -> Option<AssocTypeId<I>>;

/// Calculates program clauses from an env. This is intended to call the
/// `program_clauses_for_env` function and then possibly cache the clauses.
fn program_clauses_for_env(&self, environment: &Environment<I>) -> ProgramClauses<I>;
Expand Down
12 changes: 12 additions & 0 deletions chalk-solve/src/logging_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ where
trait_id
}

fn well_known_assoc_type_id(&self, assoc_type: WellKnownAssocType) -> Option<AssocTypeId<I>> {
let assoc_type_id = self.ws.db().well_known_assoc_type_id(assoc_type);
if let Some(id) = assoc_type_id {
self.record(self.ws.db().associated_ty_data(id).trait_id);
}
assoc_type_id
}

fn program_clauses_for_env(
&self,
environment: &chalk_ir::Environment<I>,
Expand Down Expand Up @@ -489,6 +497,10 @@ where
self.db.well_known_trait_id(well_known_trait)
}

fn well_known_assoc_type_id(&self, assoc_type: WellKnownAssocType) -> Option<AssocTypeId<I>> {
self.db.well_known_assoc_type_id(assoc_type)
}

fn program_clauses_for_env(
&self,
environment: &chalk_ir::Environment<I>,
Expand Down
9 changes: 9 additions & 0 deletions chalk-solve/src/rust_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ pub enum WellKnownTrait {

chalk_ir::const_visit!(WellKnownTrait);

/// A list of the associated types that are "well known" to chalk, which means that
/// the chalk-solve crate has special, hard-coded impls for them.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub enum WellKnownAssocType {
AsyncFnOnceOutput,
}

chalk_ir::const_visit!(WellKnownAssocType);

impl<I: Interner> TraitDatum<I> {
pub fn is_auto_trait(&self) -> bool {
self.flags.auto
Expand Down
6 changes: 6 additions & 0 deletions tests/display/unique_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ where
) -> Option<chalk_ir::TraitId<I>> {
self.db.well_known_trait_id(well_known_trait)
}
fn well_known_assoc_type_id(
&self,
assoc_type: chalk_solve::rust_ir::WellKnownAssocType,
) -> Option<chalk_ir::AssocTypeId<I>> {
self.db.well_known_assoc_type_id(assoc_type)
}
fn program_clauses_for_env(
&self,
environment: &chalk_ir::Environment<I>,
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ impl RustIrDatabase<ChalkIr> for MockDatabase {
unimplemented!()
}

fn well_known_assoc_type_id(
&self,
assoc_type: WellKnownAssocType,
) -> Option<AssocTypeId<ChalkIr>> {
unimplemented!()
}

fn program_clauses_for_env(
&self,
environment: &Environment<ChalkIr>,
Expand Down
Loading