You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the compiler, `ANON_CONST_1` and `ANON_CONST_2` are completely different, so
37
+
we have to somehow look into unevaluated constants to check whether they should
38
+
unify.
39
+
40
+
For this we use [InferCtxt::try_unify_abstract_consts](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/infer/struct.InferCtxt.html#method.try_unify_abstract_consts).
41
+
This builds a custom AST for the two inputs from their THIR. This is then used for
42
+
the actual comparison.
43
+
44
+
### Lazy normalization for constants
45
+
19
46
We do not eagerly evaluate constant as they can be used in the `where`-clauses of their
20
47
parent item, for example:
21
48
@@ -32,7 +59,7 @@ its parents caller bounds, but is also part of another bound itself.
32
59
If we were to eagerly evaluate this constant while computing its parents bounds
33
60
this would cause a query cycle.
34
61
35
-
### Generic arguments of anonymous constants
62
+
### Unused generic arguments of anonymous constants
36
63
37
64
Anonymous constants inherit the generic parameters of their parent, which is
38
65
why the array length in `foo<const N: usize>() -> [u8; N + 1]` can use `N`.
@@ -41,25 +68,7 @@ Without any manual adjustments, this causes us to include parameters even if
41
68
the constant doesn't use them in any way. This can cause
42
69
[some interesting errors][pcg-unused-substs] and breaks some already stable code.
43
70
44
-
To deal with this, we intend to look at the generic parameters explicitly mentioned
45
-
by the constants and then search the predicates of its parents to figure out which
46
-
of the other generic parameters are reachable by our constant.
47
-
48
-
**TODO**: Expand this section once the parameter filtering is implemented.
49
-
50
-
As constants can be part of their parents `where`-clauses, we mention unevaluated
51
-
constants in their parents predicates. It is therefore necessary to mention unevaluated
52
-
constants before we have computed the generic parameters
53
-
available to these constants.
54
-
55
-
To do this unevaluated constants start out with [`substs_`] being `None` while assuming
56
-
that their generic arguments could be arbitrary generic parameters.
57
-
When first accessing the generic arguments of an unevaluated constants, we then replace
58
-
`substs_` with the actual default arguments of a constants, which are the generic parameters
59
-
of their parent we assume to be used by this constant.
0 commit comments