@@ -1785,44 +1785,86 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
17851785 )
17861786 or
17871787 exists ( TypeParameter tp , TypePath suffix , TypePath mid , TypePath pathToTp |
1788+ exists ( TypeParameter constrainedTp , DeclarationPosition dpos |
1789+ typeParameterConstraintHasTypeParameter ( target , constrainedTp , constraint , pathToTp ,
1790+ tp ) and
1791+ accessDeclarationPositionMatch ( apos , dpos ) and
1792+ constrainedTp = target .getDeclaredType ( dpos , _)
1793+ )
1794+ |
17881795 /*
17891796 * Example:
17901797 *
17911798 * ```rust
1799+ * struct S<T> { ... }
1800+ *
17921801 * struct MyThing<A> { ... }
17931802 *
17941803 * trait MyTrait<B> { ... }
17951804 *
17961805 * impl<T> MyTrait<T> for MyThing<T> { ... }
17971806 *
1798- * fn bar<T1, T2: MyTrait<T1>>(x: T1, y: T2 ) {}
1807+ * fn bar<T1, T2: MyTrait<T1>>(x: T1, y: Option<T2> ) {}
17991808 *
1800- * let x: i32 = ...;
1809+ * let x: S< i32> = ...;
18011810 * let y = MyThing(Default::default());
1802- * bar(x, y );
1811+ * bar(x, Some(y) );
18031812 * ```
18041813 *
1805- * At `term` = `bar(x, y )`, we have
1814+ * At `term` = `bar([x], Some(y) )`, we have
18061815 * - `constraint = MyTrait<T1>`,
1807- * - `pathToTypeParamInConstraint` = `"B"`,
1808- * - `pathToTypeParamInSub` = `"A"`,
1809- * - `prefix` = `suffix` = `mid` = `""`,
1816+ * - `pathToTypeParamInConstraint` = `"MyTrait<B>"`,
1817+ * - `pathToTypeParamInSub` = `"MyThing<A>"`,
1818+ * - `prefix` = `"Option<T>"`
1819+ * - `mid` = `""`,
18101820 * - `tp = T1`,
1811- * - `pathToTp` = `"B"`, and
1812- * - `result` = `i32`.
1821+ * - `pathToTp` = `"MyTrait<B>"`, and
1822+ * - `suffix` = `""` and `result` = `S`, or
1823+ * - `suffix` = `"Option<T>"` and `result` = `i32`.
18131824 *
1814- * That is, it allows us to infer that the type of `y` is `MyThing<i32>`.
1825+ * That is, it allows us to infer that the type of `y` is `MyThing<S< i32> >`.
18151826 */
18161827
18171828 typeMatch ( a , e , target , suffix , result , tp ) and
1818- exists ( TypeParameter constrainedTp , DeclarationPosition dpos |
1819- typeParameterConstraintHasTypeParameter ( target , constrainedTp , constraint , pathToTp ,
1820- tp ) and
1821- accessDeclarationPositionMatch ( apos , dpos ) and
1822- constrainedTp = target .getDeclaredType ( dpos , _)
1823- ) and
18241829 pathToTp = pathToTypeParamInConstraint .appendInverse ( mid ) and
18251830 path = prefix .append ( pathToTypeParamInSub .append ( mid ) .append ( suffix ) )
1831+ or
1832+ /*
1833+ * Example:
1834+ *
1835+ * ```rust
1836+ * struct S<T> { ... }
1837+ *
1838+ * struct MyThing<A> { ... }
1839+ *
1840+ * trait MyTrait<B> { ... }
1841+ *
1842+ * impl<T> MyTrait<[T;1]> for MyThing<T> { ... }
1843+ *
1844+ * fn bar<T1, T2: MyTrait<T1>>(x: T1, y: Option<T2>) {}
1845+ *
1846+ * let x: S<i32> = ...;
1847+ * let y = MyThing(Default::default());
1848+ * bar([x], Some(y));
1849+ * ```
1850+ *
1851+ * At `term` = `bar([x], Some(y))`, we have
1852+ * - `constraint = MyTrait<T1>`,
1853+ * - `pathToTypeParamInConstraint` = `"MyTrait<B>.[]<TArray>"`,
1854+ * - `pathToTypeParamInSub` = `"MyThing<A>"`,
1855+ * - `prefix` = `"Option<T>"`
1856+ * - `mid` = `"[]<TArray>"`,
1857+ * - `tp = T1`,
1858+ * - `pathToTp` = `"MyTrait<B>"`, and
1859+ * - `suffix` = `""` and `result` = `S`, or
1860+ * - `suffix` = `"Option<T>"` and `result` = `i32`.
1861+ *
1862+ * That is, it allows us to infer that the type of `y` is `MyThing<S<i32>>`.
1863+ */
1864+
1865+ pathToTypeParamInConstraint = pathToTp .appendInverse ( mid ) and
1866+ typeMatch ( a , e , target , mid .appendInverse ( suffix ) , result , tp ) and
1867+ path = prefix .append ( pathToTypeParamInSub .append ( suffix ) )
18261868 )
18271869 )
18281870 }
0 commit comments