Uh oh!
There was an error while loading. Please reload this page.
support anon consts in binders - #79313
Conversation
There was a problem hiding this comment.
cc @eddyb
Can we somehow circumvent this? 🤔
I don't think we can just replace the bound vars with placeholders here either.
I think that places which actually try to evaluate the constant do still have to satisfy the ConstEvaluatable predicate but it does allow for
// check-pass#![feature(const_generics)]#![allow(incomplete_features)]traitBaz<constN:usize>{}fntest<T>(){// FIXME(const_generics): This should error.let _a:Box<dynfor<'a>Baz<{let _:&'a();
std::mem::size_of::<T>()}>>;}fnmain(){test::<u32>();}which is less than ideal
641de1b to
fd6e7c0Comparelcnr
commented
Nov 24, 2020
cc @varkor@eddyb@nikomatsakis, this might also be interesting to you |
bors
commented
Nov 29, 2020
☔ The latest upstream changes (presumably #79511) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels: |
There was a problem hiding this comment.
Would replacing AnonConst by &'hir AnonConst<'hir> help with the size?
There was a problem hiding this comment.
yeah, probably 👍
I want to wait for a first review before looking into perf though, so I don't waste time on an approach we don't want in the end
bors
commented
Dec 20, 2020
☔ The latest upstream changes (presumably #80163) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels: |
JohnCSimon
commented
Feb 1, 2021
@rustbot label: -S-waiting-on-review +S-waiting-on-author |
Dylan-DPC-zz
commented
Feb 18, 2021
@lcnr any updates on this? |
want to talk about this with project-const-generic in the near future before doing much here. |
lcnr
commented
Jul 8, 2021
probably want to wait with this pr until @rust-lang/project-const-generics figures out how to deal with unused params in general as that will influence the way we want to implement this change. |
closes#72129
The first 2 commits are taken from #79298 which are used in some of the added tests.
This allows us to deal with anonymous constants inside of binders, for example
struct Foo<T>(T) where for<'a> [T; { let _: &'a (); 3 }]: Sized;.What's the problem and how am I trying to solve it?
Looking at the above example,
'ais bound region. As we typeck the anonymous constant separately we would pretty much always work inside of the binder and having bound regions is not supported there.What we instead want is to treat
'ainside of the anon const as an early bound region. To achieve this we to add some additional generic params to the createdAnonConst.So we pretty much want to desugar the above example into.
Note that we add another generic param to
ANON_CONST.To achieve this we extend
hir::AnonConstto remember both it's new synthetic generic parameters as well as the potentially use lifetime arguments originating from a binder. This is now working well enough to warrant a review.Once the general approach is ironed out I still want to update lifetime resolution to warn for
for<'a> [u8; 3 + 4]: Sizedthat'ais unused. We also still have to think a bit about perf, though we can probably put the generics into a optional allocation.r? @matthewjasper