Skip to content

Commit 82a8472

Browse files
authored
Merge pull request #84 from scalexm/issue-70
Fix `UnselectedProjectionTy` parameters
2 parents 43d5b58 + acc622c commit 82a8472

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

chalk-parse/src/parser.lalrpop

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ ProjectionTy: ProjectionTy = {
139139

140140
UnselectedProjectionTy: UnselectedProjectionTy = {
141141
<ty:TyWithoutFor> "::" <name:Id> <a:Angle<Parameter>> => {
142-
let mut args = vec![Parameter::Ty(ty)];
143-
args.extend(a);
142+
let mut args = a;
143+
args.push(Parameter::Ty(ty));
144144
UnselectedProjectionTy {
145145
name: name,
146146
args: args,

src/ir/debug.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,13 @@ impl Debug for ProjectionTy {
121121

122122
impl Debug for UnselectedProjectionTy {
123123
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
124+
let len = self.parameters.len();
124125
write!(
125126
fmt,
126127
"{:?}::{}{:?}",
127-
self.parameters[0],
128+
self.parameters[len - 1],
128129
self.type_name,
129-
Angle(&self.parameters[1..])
130+
Angle(&self.parameters[0..(len - 1)])
130131
)
131132
}
132133
}

src/lower/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ impl ir::AssociatedTyValue {
11171117
///
11181118
/// ```notrust
11191119
/// forall<'a, T> {
1120-
/// (Vec<T>: Iterable<IntoIter<'a> = Iter<'a, T>>) :-
1120+
/// Normalize(<Vec<T> as Iterable>::IntoIter<'a> -> Iter<'a, T>>) :-
11211121
/// (Vec<T>: Iterable), // (1)
11221122
/// (T: 'a) // (2)
11231123
/// }
@@ -1127,9 +1127,9 @@ impl ir::AssociatedTyValue {
11271127
///
11281128
/// ```notrust
11291129
/// forall<'a, T> {
1130-
/// Vec<T>::IntoIter<'a> ==> Iter<'a, T> :-
1130+
/// UnselectedNormalize(Vec<T>::IntoIter<'a> -> Iter<'a, T>) :-
11311131
/// InScope(Iterable),
1132-
/// <Vec<T> as Iterable>::IntoIter<'a> ==> Iter<'a, T>
1132+
/// Normalize(<Vec<T> as Iterable>::IntoIter<'a> -> Iter<'a, T>)
11331133
/// }
11341134
/// ```
11351135
fn to_program_clauses(
@@ -1161,19 +1161,25 @@ impl ir::AssociatedTyValue {
11611161
.chain(self.value.value.where_clauses.clone().cast())
11621162
.collect();
11631163

1164+
// Bound parameters + `Self` type of the trait-ref
11641165
let parameters: Vec<_> = {
11651166
// First add refs to the bound parameters (`'a`, in above example)
11661167
let parameters = self.value.binders.iter().zip(0..).map(|p| p.to_parameter());
11671168

1168-
// Then add the trait-ref parameters (`Vec<T>`, in above example)
1169+
// Then add the `Self` type (`Vec<T>`, in above example)
11691170
parameters
1170-
.chain(impl_trait_ref.parameters.clone())
1171+
.chain(Some(impl_trait_ref.parameters[0].clone()))
11711172
.collect()
11721173
};
11731174

11741175
let projection = ir::ProjectionTy {
11751176
associated_ty_id: self.associated_ty_id,
1176-
parameters: parameters.clone(),
1177+
1178+
// Add the remaining parameters of the trait-ref if any
1179+
parameters: parameters.iter()
1180+
.chain(&impl_trait_ref.parameters[1..])
1181+
.cloned()
1182+
.collect(),
11771183
};
11781184

11791185
let normalize_goal = ir::DomainGoal::Normalize(ir::Normalize {

src/solve/test/mod.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,57 @@ fn unselected_projection() {
17941794
}
17951795
}
17961796

1797+
#[test]
1798+
fn unselected_projection_with_atc() {
1799+
test! {
1800+
program {
1801+
trait Foo {
1802+
type Item<'a>;
1803+
}
1804+
1805+
struct Ref<'a, T> { }
1806+
struct i32 { }
1807+
1808+
impl Foo for i32 {
1809+
type Item<'a> = Ref<'a, i32>;
1810+
}
1811+
}
1812+
goal {
1813+
forall<'a> {
1814+
if (InScope(Foo)) {
1815+
i32::Item<'a> = Ref<'a, i32>
1816+
}
1817+
}
1818+
} yields {
1819+
"Unique"
1820+
}
1821+
}
1822+
}
1823+
1824+
#[test]
1825+
fn unselected_projection_with_parametric_trait() {
1826+
test! {
1827+
program {
1828+
trait Foo<T> {
1829+
type Item;
1830+
}
1831+
1832+
struct i32 { }
1833+
1834+
impl Foo<i32> for i32 {
1835+
type Item = i32;
1836+
}
1837+
}
1838+
goal {
1839+
if (InScope(Foo)) {
1840+
i32::Item = i32
1841+
}
1842+
} yields {
1843+
"Unique"
1844+
}
1845+
}
1846+
}
1847+
17971848
#[test]
17981849
fn overflow_universe() {
17991850
test! {

0 commit comments

Comments
 (0)