-
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
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 |
@@ -289,6 +267,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>, | |||
match cx.tables.qpath_def(qpath, e.hir_id) { | |||
Def::Const(def_id) | | |||
Def::AssociatedConst(def_id) => { | |||
let substs = tcx.normalize_associated_type_in_env(&substs, cx.param_env); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
// except according to those terms. | ||
|
||
#![feature(const_size_of)] | ||
#![allow(unused)] |
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.
You should remove this.
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(const_size_of)] |
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.
Wait, this too, I think? Since the example doesn't use size_of
anymore.
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.
done
travis likes it + comments addressed |
@bors r+ |
📌 Commit 1ee0ff3 has been approved by |
☀️ Test successful - status-appveyor, status-travis |
r? @eddyb
cc @arielb1