-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
lazy_normalization_consts breaks unsize coercion in rare cases #78369
Comments
The issue is here rust/compiler/rustc_trait_selection/src/traits/select/confirmation.rs Lines 846 to 854 in f5230fb
in combination with rust/compiler/rustc_middle/src/ty/walk.rs Line 199 in f5230fb
We currently look at all substs while we should only look at the generic params which are actually mentioned by the constant. I am currently thinking about moving cc @oli-obk |
I don't think we can remove |
I am not too sure how to actually do this yet... probably by adding an optional reference to we might not be able to just evaluate |
At that point you're just talking about caching, so one thing that we could also do is change the |
…r=nikomatsakis lazily "compute" anon const default substs Continuing the work of rust-lang#83086, this implements the discussed solution for the [unused substs problem](https://github.com/rust-lang/project-const-generics/blob/master/design-docs/anon-const-substs.md#unused-substs). As of now, anonymous constants inherit all of their parents generics, even if they do not use them, e.g. in `fn foo<T, const N: usize>() -> [T; N + 1]`, the array length has `T` as a generic parameter even though it doesn't use it. These *unused substs* cause some backwards incompatible, and imo incorrect behavior, e.g. rust-lang#78369. --- We do not actually filter any generic parameters here and the `default_anon_const_substs` query still a dummy which only checks that - we now prevent the previously existing query cycles and are able to call `predicates_of(parent)` when computing the substs of anonymous constants - the default anon consts substs only include the typeflags we assume it does. Implementing that filtering will be left as future work. --- The idea of this PR is to delay the creation of the anon const substs until after we've computed `predicates_of` for the parent of the anon const. As the predicates of the parent can however contain the anon const we still have to create a `ty::Const` for it. We do this by changing the substs field of `ty::Unevaluated` to an option and modifying accesses to instead call the method `unevaluated.substs(tcx)` which returns the substs as before. If the substs - now `substs_` - of `ty::Unevaluated` are `None`, it means that the anon const currently has its default substs, i.e. the substs it has when first constructed, which are the generic parameters it has available. To be able to call `unevaluated.substs(tcx)` in a `TypeVisitor`, we add the non-defaulted method `fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>>`. In case `tcx_for_anon_const_substs` returns `None`, unknown anon const default substs are skipped entirely. Even when `substs_` is `None` we still have to treat the constant as if it has its default substs. To do this, `TypeFlags` are modified so that it is clear whether they can still change when *exposing* any anon const default substs. A new flag, `HAS_UNKNOWN_DEFAULT_CONST_SUBSTS`, is added in case some default flags are missing. The rest of this PR are some smaller changes to either not cause cycles by trying to access the default anon const substs too early or to be able to access the `tcx` in previously unused locations. cc `@rust-lang/project-const-generics` r? `@nikomatsakis`
This works on stable but fails with the following error when using
lazy_normalization_consts
For this to fail the struct has to contain a type referencing an unevaluated constant,
struct P<T: ?Sized>([u8; 5], T)
does work.assigning to myself, but won't get to this right away. If you are interested in working on this before that feel free to do so.
cc @nikomatsakis @varkor
The text was updated successfully, but these errors were encountered: