Skip to content

Commit abd029d

Browse files
committed
fix some nits
1 parent 748f735 commit abd029d

File tree

11 files changed

+43
-50
lines changed

11 files changed

+43
-50
lines changed

chalk-ir/src/fold.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ where
8787
/// Top-level callback: invoked for each `Lifetime<I>` that is
8888
/// encountered when folding. By default, invokes
8989
/// `super_fold_with`, which will in turn invoke the more
90-
/// specialized folding methods below, like `fold_free_lifetime_ty`.
90+
/// specialized folding methods below, like `fold_free_var_lifetime`.
9191
fn fold_lifetime(
9292
&mut self,
9393
lifetime: &Lifetime<I>,
@@ -99,7 +99,7 @@ where
9999
/// Top-level callback: invoked for each `Const<I>` that is
100100
/// encountered when folding. By default, invokes
101101
/// `super_fold_with`, which will in turn invoke the more
102-
/// specialized folding methods below, like `fold_free_lifetime_ty`.
102+
/// specialized folding methods below, like `fold_free_var_const`.
103103
fn fold_const(
104104
&mut self,
105105
constant: &Const<I>,
@@ -187,8 +187,8 @@ where
187187
}
188188
}
189189

190-
/// If overriden to return true, we will panic when a free
191-
/// placeholder type/lifetime is encountered.
190+
/// If overridden to return true, we will panic when a free
191+
/// placeholder type/lifetime/const is encountered.
192192
fn forbid_free_placeholders(&self) -> bool {
193193
false
194194
}
@@ -234,7 +234,7 @@ where
234234
outer_binder: DebruijnIndex,
235235
) -> Fallible<Const<TI>> {
236236
if self.forbid_free_placeholders() {
237-
panic!("unexpected placeholder lifetime `{:?}`", universe)
237+
panic!("unexpected placeholder const `{:?}`", universe)
238238
} else {
239239
Ok(universe.to_const(self.target_interner()))
240240
}
@@ -497,7 +497,6 @@ where
497497
I: Interner,
498498
TI: TargetInterner<I>,
499499
{
500-
#[allow(unused_variables)]
501500
fn super_fold_with<'i>(
502501
&self,
503502
folder: &mut dyn Folder<'i, I, TI>,

chalk-ir/src/fold/subst.rs

+21-23
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,30 @@ impl<'i, I: Interner> Folder<'i, I> for Subst<'_, 'i, I> {
2828
self
2929
}
3030

31+
/// We are eliminating one binder, but binders outside of that get preserved.
32+
///
33+
/// So e.g. consider this:
34+
///
35+
/// ```notrust
36+
/// for<A, B> { for<C> { [A, C] } }
37+
/// // ^ the binder we are substituing with `[u32]`
38+
/// ```
39+
///
40+
/// Here, `A` would be `^1.0` and `C` would be `^0.0`. We will replace `^0.0` with the
41+
/// 0th index from the list (`u32`). We will convert `^1.0` (A) to `^0.0` -- i.e., shift
42+
/// it **out** of one level of binder (the `for<C>` binder we are eliminating).
43+
///
44+
/// This gives us as a result:
45+
///
46+
/// ```notrust
47+
/// for<A, B> { [A, u32] }
48+
/// ^ represented as `^0.0`
49+
/// ```
3150
fn fold_free_var_ty(
3251
&mut self,
3352
bound_var: BoundVar,
3453
outer_binder: DebruijnIndex,
3554
) -> Fallible<Ty<I>> {
36-
// We are eliminating one binder, but binders outside of that get preserved.
37-
//
38-
// So e.g. consider this:
39-
//
40-
// ```
41-
// for<A, B> { for<C> { [A, C] } }
42-
// // ^ the binder we are substituing with `[u32]`
43-
// ```
44-
//
45-
// Here, `A` would be `^1.0` and `C` would be `^0.0`. We will replace `^0.0` with the
46-
// 0th index from the list (`u32`). We will convert `^1.0` (A) to `^0.0` -- i.e., shift
47-
// it **out** of one level of binder (the `for<C>` binder we are eliminating).
48-
//
49-
// This gives us as a result:
50-
//
51-
// ```
52-
// for<A, B> { [A, u32] }
53-
// ^ represented as `^0.0`
54-
// ```
5555
if let Some(index) = bound_var.index_if_innermost() {
5656
match self.parameters[index].data(self.interner()) {
5757
ParameterKind::Ty(t) => Ok(t.shifted_in_from(self.interner(), outer_binder)),
@@ -66,13 +66,12 @@ impl<'i, I: Interner> Folder<'i, I> for Subst<'_, 'i, I> {
6666
}
6767
}
6868

69+
/// see `fold_free_var_ty`
6970
fn fold_free_var_lifetime(
7071
&mut self,
7172
bound_var: BoundVar,
7273
outer_binder: DebruijnIndex,
7374
) -> Fallible<Lifetime<I>> {
74-
// see comment in `fold_free_var_ty`
75-
7675
if let Some(index) = bound_var.index_if_innermost() {
7776
match self.parameters[index].data(self.interner()) {
7877
ParameterKind::Lifetime(l) => Ok(l.shifted_in_from(self.interner(), outer_binder)),
@@ -87,13 +86,12 @@ impl<'i, I: Interner> Folder<'i, I> for Subst<'_, 'i, I> {
8786
}
8887
}
8988

89+
/// see `fold_free_var_ty`
9090
fn fold_free_var_const(
9191
&mut self,
9292
bound_var: BoundVar,
9393
outer_binder: DebruijnIndex,
9494
) -> Fallible<Const<I>> {
95-
// see comment in `fold_free_var_ty`
96-
9795
if let Some(index) = bound_var.index_if_innermost() {
9896
match self.parameters[index].data(self.interner()) {
9997
ParameterKind::Const(c) => Ok(c.shifted_in_from(self.interner(), outer_binder)),

chalk-ir/src/interner.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,11 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
517517

518518
/// Create an "interned" const from `const`. This is not
519519
/// normally invoked directly; instead, you invoke
520-
/// `LifetimeData::intern` (which will ultimately call this
520+
/// `ConstData::intern` (which will ultimately call this
521521
/// method).
522522
fn intern_const(&self, constant: ConstData<Self>) -> Self::InternedConst;
523523

524-
/// Lookup the `ConstData` that was interned to create a `InternedLifetime`.
524+
/// Lookup the `ConstData` that was interned to create a `InternedConst`.
525525
fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a ConstData<Self>;
526526

527527
fn const_eq(&self, c1: &Self::InternedConcreteConst, c2: &Self::InternedConcreteConst) -> bool;

chalk-ir/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ impl<I: Interner> Const<I> {
686686
}
687687
}
688688

689-
/// True if this lifetime is a "bound" lifetime, and hence
689+
/// True if this const is a "bound" const, and hence
690690
/// needs to be shifted across binders. Meant for debug assertions.
691691
pub fn needs_shift(&self, interner: &I) -> bool {
692692
match self.data(interner) {
@@ -718,7 +718,7 @@ pub struct ConcreteConst<I: Interner> {
718718
}
719719

720720
impl<I: Interner> ConcreteConst<I> {
721-
pub fn c_eq(&self, other: &ConcreteConst<I>, interner: &I) -> bool {
721+
pub fn const_eq(&self, other: &ConcreteConst<I>, interner: &I) -> bool {
722722
interner.const_eq(&self.interned, &other.interned)
723723
}
724724
}

chalk-ir/src/visit.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ where
134134

135135
/// If overridden to return true, then visiting will panic if a
136136
/// free variable is encountered. This should be done if free
137-
/// type/lifetime variables are not expected.
137+
/// type/lifetime/const variables are not expected.
138138
fn forbid_free_vars(&self) -> bool {
139139
false
140140
}
@@ -211,7 +211,7 @@ where
211211
Self::Result::new()
212212
}
213213

214-
/// If overriden to return true, we will panic when a free
214+
/// If overridden to return true, we will panic when a free
215215
/// placeholder type/lifetime is encountered.
216216
fn forbid_free_placeholders(&self) -> bool {
217217
false
@@ -258,7 +258,7 @@ where
258258
_outer_binder: DebruijnIndex,
259259
) -> Self::Result {
260260
if self.forbid_free_placeholders() {
261-
panic!("unexpected placeholder lifetime `{:?}`", universe)
261+
panic!("unexpected placeholder const `{:?}`", universe)
262262
} else {
263263
Self::Result::new()
264264
}
@@ -445,7 +445,6 @@ impl<I: Interner> Visit<I> for Const<I> {
445445
}
446446

447447
impl<I: Interner> SuperVisit<I> for Const<I> {
448-
#[allow(unused_variables)]
449448
fn super_visit_with<'i, R: VisitResult>(
450449
&self,
451450
visitor: &mut dyn Visitor<'i, I, Result = R>,

chalk-solve/src/infer.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,11 @@ impl<I: Interner> InferenceTable<I> {
142142
}
143143

144144
/// If type `leaf` is a free inference variable, and that variable has been
145-
/// bound, returns `Some(T)` where `T` is the type to which it has been bound.
146-
///
147-
/// `binders` is the number of binders under which `leaf` appears;
148-
/// the return value will also be shifted accordingly so that it
149-
/// can appear under that same number of binders.
145+
/// bound, returns `Some(P)` where `P` is the parameter to which it has been bound.
150146
pub(crate) fn probe_var(&mut self, leaf: InferenceVar) -> Option<Parameter<I>> {
151147
match self.unify.probe_value(EnaVariable::from(leaf)) {
152148
InferenceValue::Unbound(_) => None,
153-
InferenceValue::Bound(ref val) => Some(val.clone()),
149+
InferenceValue::Bound(val) => Some(val),
154150
}
155151
}
156152

chalk-solve/src/infer/instantiate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<I: Interner> InferenceTable<I> {
9696
lt.cast(interner)
9797
}
9898
ParameterKind::Ty(()) => placeholder_idx.to_ty(interner).cast(interner),
99-
ParameterKind::Const(_) => placeholder_idx.to_const(interner).cast(interner),
99+
ParameterKind::Const(()) => placeholder_idx.to_const(interner).cast(interner),
100100
}
101101
})
102102
.collect();

chalk-solve/src/infer/unify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl<'t, I: Interner> Unifier<'t, I> {
383383
}
384384

385385
(&ConstData::Concrete(ref ev1), &ConstData::Concrete(ref ev2)) => {
386-
if ev1.c_eq(ev2, interner) {
386+
if ev1.const_eq(ev2, interner) {
387387
Ok(())
388388
} else {
389389
Err(NoSolution)

chalk-solve/src/solve/slg.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl<I: Interner> MayInvalidate<'_, I> {
466466
}
467467
}
468468

469-
// Returns true if the two types could be unequal.
469+
/// Returns true if the two types could be unequal.
470470
fn aggregate_tys(&mut self, new: &Ty<I>, current: &Ty<I>) -> bool {
471471
let interner = self.interner;
472472
match (new.data(interner), current.data(interner)) {
@@ -530,11 +530,12 @@ impl<I: Interner> MayInvalidate<'_, I> {
530530
}
531531
}
532532

533+
/// Returns true if the two consts could be unequal.
533534
fn aggregate_lifetimes(&mut self, _: &Lifetime<I>, _: &Lifetime<I>) -> bool {
534535
true
535536
}
536537

537-
// Returns true if the two consts could be unequal.
538+
/// Returns true if the two consts could be unequal.
538539
fn aggregate_consts(&mut self, new: &Const<I>, current: &Const<I>) -> bool {
539540
let interner = self.interner;
540541
match (new.data(interner), current.data(interner)) {
@@ -559,7 +560,7 @@ impl<I: Interner> MayInvalidate<'_, I> {
559560
self.aggregate_placeholders(p1, p2)
560561
}
561562

562-
(ConstData::Concrete(c1), ConstData::Concrete(c2)) => !c1.c_eq(c2, interner),
563+
(ConstData::Concrete(c1), ConstData::Concrete(c2)) => !c1.const_eq(c2, interner),
563564

564565
// Only variants left are placeholder = concrete, which always fails
565566
(ConstData::Placeholder(_), _) | (ConstData::Concrete(_), _) => true,

chalk-solve/src/solve/slg/aggregate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
451451
}
452452
}
453453
(ConstData::Concrete(e1), ConstData::Concrete(e2)) => {
454-
if e1.c_eq(e2, interner) {
454+
if e1.const_eq(e2, interner) {
455455
c1.clone()
456456
} else {
457457
self.new_const_variable()

chalk-solve/src/solve/slg/resolvent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ impl<'i, I: Interner> Zipper<'i, I> for AnswerSubstitutor<'i, I> {
504504
}
505505

506506
(ConstData::Concrete(c1), ConstData::Concrete(c2)) => {
507-
assert!(c1.c_eq(c2, interner));
507+
assert!(c1.const_eq(c2, interner));
508508
Ok(())
509509
}
510510

0 commit comments

Comments
 (0)