Skip to content

Commit f3763f3

Browse files
committed
Address review comments
1 parent 13b5c36 commit f3763f3

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

chalk-solve/src/clauses.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,18 +358,18 @@ fn program_clauses_that_could_match<I: Interner>(
358358

359359
let trait_datum = db.trait_datum(trait_id);
360360

361+
let self_ty = alias.self_type_parameter(interner);
362+
361363
// Flounder if the self-type is unknown and the trait is non-enumerable.
362364
//
363365
// e.g., Normalize(<?X as Iterator>::Item = u32)
364-
if (alias.self_type_parameter(interner).is_var(interner))
365-
&& trait_datum.is_non_enumerable_trait()
366-
{
366+
if (self_ty.is_var(interner)) && trait_datum.is_non_enumerable_trait() {
367367
return Err(Floundered);
368368
}
369369

370370
if let Some(well_known) = trait_datum.well_known {
371371
builtin_traits::add_builtin_assoc_program_clauses(
372-
db, builder, well_known, proj,
372+
db, builder, well_known, self_ty,
373373
);
374374
}
375375

chalk-solve/src/clauses/builtin_traits.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{builder::ClauseBuilder, generalize};
22
use crate::{Interner, RustIrDatabase, TraitRef, WellKnownTrait};
3-
use chalk_ir::{AliasTy, ProjectionTy, Substitution, Ty};
3+
use chalk_ir::{Substitution, Ty};
44

55
mod clone;
66
mod copy;
@@ -48,12 +48,10 @@ pub fn add_builtin_assoc_program_clauses<I: Interner>(
4848
db: &dyn RustIrDatabase<I>,
4949
builder: &mut ClauseBuilder<'_, I>,
5050
well_known: WellKnownTrait,
51-
proj: &ProjectionTy<I>,
51+
self_ty: Ty<I>,
5252
) {
5353
match well_known {
5454
WellKnownTrait::FnOnce => {
55-
let interner = db.interner();
56-
let self_ty = AliasTy::Projection(proj.clone()).self_type_parameter(interner);
5755
let trait_id = db.well_known_trait_id(well_known).unwrap();
5856
fn_family::add_fn_trait_program_clauses(db, builder, trait_id, self_ty);
5957
}

chalk-solve/src/clauses/builtin_traits/fn_family.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ use chalk_ir::{
88
};
99

1010
/// Handles clauses for FnOnce/FnMut/Fn.
11-
/// If `assoc_output` is `true`, we push a clause of the form
12-
/// `Normalize(<fn(A) -> B as FnOnce<(A,)>>::Output -> B) :- Implemented(fn(A) -> B as FnOnce<(A,)>`
11+
/// If `self_ty` is a function, we push a clause of the form
12+
/// `fn(A1, A2, ..., AN) -> O: FnTrait<(A1, A2, ..., AN)>`, where `FnTrait`
13+
/// is the trait corresponding to `trait_id` (FnOnce/FnMut/Fn)
1314
///
14-
/// If `assoc_output` is `false`, we push a clause of the form
15-
/// `Implemented(fn(A) -> B as FnOnce<(A,)>)`
15+
/// If `trait_id` is `FnOnce`, we also push a clause for the output type of the form:
16+
/// `Normalize(<fn(A) -> B as FnOnce<(A,)>>::Output -> B)`
17+
/// We do not add the usual `Implemented(fn(A) -> b as FnOnce<(A,)>` clause
18+
/// as a condition, since we already called `push_fact` with it
1619
pub fn add_fn_trait_program_clauses<I: Interner>(
1720
db: &dyn RustIrDatabase<I>,
1821
builder: &mut ClauseBuilder<'_, I>,
@@ -25,10 +28,10 @@ pub fn add_fn_trait_program_clauses<I: Interner>(
2528
let (binders, orig_sub) = fn_val.into_binders_and_value(interner);
2629
let bound_ref = Binders::new(VariableKinds::from(interner, binders), orig_sub);
2730
builder.push_binders(&bound_ref, |builder, orig_sub| {
28-
let all_params: Vec<_> = orig_sub.iter(interner).cloned().collect();
29-
3031
// The last parameter represents the function return type
31-
let (arg_sub, fn_output_ty) = all_params.split_at(all_params.len() - 1);
32+
let (arg_sub, fn_output_ty) = orig_sub
33+
.parameters(interner)
34+
.split_at(orig_sub.len(interner) - 1);
3235
let arg_sub = Substitution::from(interner, arg_sub);
3336
let fn_output_ty = fn_output_ty[0].assert_ty_ref(interner);
3437

0 commit comments

Comments
 (0)