Resolve types properly in const eval#45488
Conversation
|
Can you add a test, with an associated |
I tried. But it was a silent error before, and it works now, so there's no difference. Using the assoc constant won't work generically out of other reasons: https://play.rust-lang.org/?gist=54e162b150e745236878f2f0eca06de3&version=stable |
|
@oli-obk There's no forwarding going on there between two impls' associated Closer to what I meant: https://play.rust-lang.org/?gist=e0ec487c9566ea8f8187eb14d82e62ac&version=nightly |
src/librustc_const_eval/eval.rs
Outdated
There was a problem hiding this comment.
Isn't this normalization also needed in the Def::Method(id) | Def::Fn(id) arm, and also for types fetched from expr_ty?
There was a problem hiding this comment.
technically we only need it for Def::AssociatedConst, but it's a nop for Def::Const
|
Another test for broken subst logic (this shouldn't ICE): #![allow(unused)]
trait Foo {
const BAR: Self;
}
impl Foo for i32 {
const BAR: Self = 4;
}
impl Foo for i64 {
const BAR: Self = 3;
}
struct Bar<T: ?Sized>(usize, std::marker::PhantomData<T>);
impl<T: ?Sized> Foo for Bar<T> {
const BAR: Self = Bar(4, std::marker::PhantomData);
}
impl<T: ?Sized> Bar<T> {
fn foo() {
let x = Self::BAR.0;
let x: &'static usize = &Self::BAR.0;
let x: [i32; Self::BAR.0] = [1, 2];
}
}
fn main() {
let x: [i32; i32::BAR as usize] = [1, 2, 3, 4];
let x: [i32; i64::BAR as usize] = [1, 2, 3];
}r+ with proper tests |
|
@arielb1 That subst doesn't come from const eval, it comes from https://github.com/rust-lang/rust/blob/master/src/librustc/traits/project.rs#L357 |
There was a problem hiding this comment.
Wait, this too, I think? Since the example doesn't use size_of anymore.
|
travis likes it + comments addressed |
|
@bors r+ |
|
📌 Commit 1ee0ff3 has been approved by |
|
☀️ Test successful - status-appveyor, status-travis |
r? @eddyb
cc @arielb1