-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
support anon consts in binders #79313
Conversation
)); | ||
// FIXME(const_generics): Do we actually end up having to deal with | ||
// this bound later or is this unsound? | ||
if !substs.has_escaping_bound_vars() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)]
trait Baz<const N: usize> {}
fn test<T>() {
// FIXME(const_generics): This should error.
let _a: Box<dyn for<'a> Baz<{
let _: &'a ();
std::mem::size_of::<T>()
}>>;
}
fn main() {
test::<u32>();
}
which is less than ideal
641de1b
to
fd6e7c0
Compare
cc @varkor @eddyb @nikomatsakis, this might also be interesting to you |
☔ 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:
|
@@ -1371,7 +1373,7 @@ pub struct Expr<'hir> { | |||
|
|||
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger. | |||
#[cfg(target_arch = "x86_64")] | |||
rustc_data_structures::static_assert_size!(Expr<'static>, 72); | |||
rustc_data_structures::static_assert_size!(Expr<'static>, 144); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would replacing AnonConst
by &'hir AnonConst<'hir>
help with the size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
☔ 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:
|
@rustbot label: -S-waiting-on-review +S-waiting-on-author |
@lcnr any updates on this? |
want to talk about this with project-const-generic in the near future before doing much here. |
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,
'a
is 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
'a
inside 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::AnonConst
to 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]: Sized
that'a
is unused. We also still have to think a bit about perf, though we can probably put the generics into a optional allocation.r? @matthewjasper