-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
nll: respect user type annotations with constants in expressions #54571
Comments
Assigning to myself to investigate, write up some instructions, etc |
Test case #1 (should not compile, does): #![feature(nll)]
trait Foo<'a> {
const C: &'a u32;
}
impl<'a, T> Foo<'a> for T {
const C: &'a u32 = &22;
}
fn foo<'a>(_: &'a u32) -> &'static u32 {
<() as Foo<'a>>::C
}
fn main() {
} |
Test case #2 (same story): #![feature(nll)]
struct Foo<'a> { x: &'a u32 }
impl<'a> Foo<'a> {
const C: &'a u32 = &22;
}
fn foo<'a>(_: &'a u32) -> &'static u32 {
<Foo<'a>>::C
}
fn main() {
} |
Test case #3: #![feature(nll)]
trait Foo<'a> {
const C: &'a u32;
}
impl<'a, T> Foo<'a> for T {
const C: &'a u32 = &22;
}
fn foo<'a, T: Foo<'a>>() -> &'static u32 {
<T as Foo<'a>>::C
}
fn main() {
} |
The fix for this will have to build on #55093 |
That PR adds the ability for user type annotations to be more complex than they presently are. I think we need to extend the pub enum UserTypeAnnotation<'tcx> {
Ty(CanonicalTy<'tcx>),
FnDef(DefId, CanonicalUserSubsts<'tcx>),
AdtDef(&'tcx AdtDef, CanonicalUserSubsts<'tcx>),
} So something like this: pub enum UserTypeAnnotation<'tcx> {
Ty(CanonicalTy<'tcx>),
FnDef(DefId, CanonicalUserSubsts<'tcx>),
AdtDef(&'tcx AdtDef, CanonicalUserSubsts<'tcx>),
ConstantDef(DefId, CanonicalUserSubsts<'tcx>),
} Next, there is code that instantiates these "user type annotations" in various ways in:
It looks sort of like this: match user_ty {
UserTypeAnnotation::Ty(canonical_ty) => ...,
UserTypeAnnotation::FnDef(def_id, canonical_substs) => ...,
...
} I think we need to extend this with a case for It would work like so:
If we do that, then the only thing we have left to do is to find the |
Fix in #55152 |
Breaking out from #47184 as a subtask:
We need to respect user annotations when referencing constants in expressions. First job: come up with some test cases.
The text was updated successfully, but these errors were encountered: