Skip to content

Fix wrong substitution code #4106

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
Apr 23, 2020
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
2 changes: 1 addition & 1 deletion crates/ra_hir_ty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ pub trait TypeWalk {
&mut |ty, binders| {
if let &mut Ty::Bound(bound) = ty {
if bound.debruijn >= binders {
*ty = substs.0[bound.index].clone();
*ty = substs.0[bound.index].clone().shift_bound_vars(binders);
Copy link
Member

@matklad matklad Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there perhaps some way we could make similar wrong code crash on all examples, and not only just on the bad ones?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like, if this happens to work most of the time, b/c binders is 0, can we remember a number which tells the nesting/how many times we should shift, and than assert everywhere that nesting levels match?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how -- if I remember to assert, I can just do it correctly in that place. We could validate types to check that the binders are correct, but that will also only crash if we try to bind to indexes that don't exist.

}
}
},
Expand Down
41 changes: 41 additions & 0 deletions crates/ra_hir_ty/src/tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,44 @@ fn foo(b: Bar) {
"###
);
}

#[test]
fn issue_4053_diesel_where_clauses() {
assert_snapshot!(
infer(r#"
trait BoxedDsl<DB> {
type Output;
fn internal_into_boxed(self) -> Self::Output;
}

struct SelectStatement<From, Select, Distinct, Where, Order, LimitOffset, GroupBy, Locking> {
order: Order,
}

trait QueryFragment<DB: Backend> {}

trait Into<T> { fn into(self) -> T; }

impl<F, S, D, W, O, LOf, DB> BoxedDsl<DB>
for SelectStatement<F, S, D, W, O, LOf, G>
where
O: Into<dyn QueryFragment<DB>>,
{
type Output = XXX;

fn internal_into_boxed(self) -> Self::Output {
self.order.into();
}
}
"#),
@r###"
[66; 70) 'self': Self
[268; 272) 'self': Self
[467; 471) 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
[489; 523) '{ ... }': ()
[499; 503) 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
[499; 509) 'self.order': O
[499; 516) 'self.o...into()': dyn QueryFragment<DB>
"###
);
}