-
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
ICE with associated constants #24938
Comments
I don't yet know what the exact problem is, but I think that it is related to this failing test case: // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(associated_consts)]
trait AsFixedSizeArray: Sized {
const SIZE: usize;
unsafe fn as_fixed_size_array(&self)
-> &[u8; <Self as AsFixedSizeArray>::SIZE];
}
impl AsFixedSizeArray for u8 {
const SIZE: usize = 1;
fn as_fixed_size_array(&self)
-> &[u8; <Self as AsFixedSizeArray>::SIZE] {
&[*self]
}
}
fn main() {
assert_eq!([1u8], *(1u8).as_fixed_size_array());
} Output:
There are a few similar cases that I will open bugs for, some of which have a common cause, I think. |
Hmm, I've sort-of figured out how to implement a fix, but it will take a bit more time. The problem is that:
The most obvious solution is to do something similar to how associated types are currently handled using projections. (I think that @nikomatsakis mentioned something about this a while back.) I don't think that associated types are doing the right thing in all situations, but moving in that direction we could probably get a lot more code to compile. |
@quantheory |
While trying to migrate
i32::BYTES
and friends to associated constants I have encountered this ICE. It's caused by some code in libstd, but the precise location is not clear.The branch reproducing the ICE can be found here: https://github.com/petrochenkov/rust/tree/primod
cc @quantheory
The text was updated successfully, but these errors were encountered: