Skip to content

Commit 7026d42

Browse files
committed
Introduce substitute method on Binder
1 parent e561538 commit 7026d42

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

chalk-ir/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ macro_rules! impl_debugs {
2525
use crate::cast::Cast;
2626
use crate::fold::shift::Shift;
2727
use crate::fold::{
28-
DefaultInferenceFolder, DefaultPlaceholderFolder, DefaultTypeFolder, Fold, FreeVarFolder,
28+
DefaultInferenceFolder, DefaultPlaceholderFolder, DefaultTypeFolder, Fold, FreeVarFolder, Subst,
2929
};
3030
use chalk_engine::fallible::*;
3131
use lalrpop_intern::InternedString;
@@ -823,6 +823,13 @@ impl<T> Binders<T> {
823823
}
824824
}
825825

826+
impl<T> Binders<T> where T: Fold {
827+
pub fn substitute(&self, parameters: &[Parameter]) -> T::Result {
828+
assert_eq!(self.binders.len(), parameters.len());
829+
Subst::apply(parameters, &self.value)
830+
}
831+
}
832+
826833
/// Allows iterating over a Binders<Vec<T>>, for instance.
827834
/// Each element will include the same set of parameter bounds.
828835
impl<V: IntoIterator> IntoIterator for Binders<V> {

chalk-solve/src/clauses.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use self::program_clauses::ToProgramClauses;
33
use crate::RustIrDatabase;
44
use chalk_ir::cast::{Cast, Caster};
55
use chalk_ir::could_match::CouldMatch;
6-
use chalk_ir::fold::Subst;
76
use chalk_ir::*;
87
use rustc_hash::FxHashSet;
98
use std::sync::Arc;
@@ -172,7 +171,7 @@ fn program_clauses_that_could_match(
172171
match trait_ref.self_type_parameter() {
173172
Some(Ty::Opaque(qwc)) | Some(Ty::Dyn(qwc)) => {
174173
let self_ty = trait_ref.self_type_parameter().unwrap(); // This cannot be None
175-
let wc = Subst::apply(&[self_ty.cast()], &qwc.value);
174+
let wc = qwc.substitute(&[self_ty.cast()]);
176175
clauses.extend(wc.into_iter().casted());
177176
}
178177
_ => {}

0 commit comments

Comments
 (0)