Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

ices/73730.rs: fixed with no errors #435

Merged
merged 1 commit into from
Jul 16, 2020
Merged

Conversation

github-actions[bot]
Copy link
Contributor

Issue: rust-lang/rust#73730

#![feature(const_generics, in_band_lifetimes)]
#![allow(incomplete_features)]

use std::mem::MaybeUninit;

trait Foo<'a, A>: Iterator<Item = A> {
    fn bar<const N: usize>(&mut self) -> [A; N];

    fn foo<const N: usize>(&mut self) -> [A; N] {
        let result = self.bar();
        result
    }
}

impl<A, I: ?Sized> Foo<'a, A> for I
where
    I: Iterator<Item = A>,
{
    fn bar<const N: usize>(&mut self) -> [A; N] {
        let mut result: [MaybeUninit<A>; N] = unsafe { MaybeUninit::uninit().assume_init() };
        for (a, b) in result.iter_mut().zip(self) {
            *a = MaybeUninit::new(b);
        }
        let spam: *const [MaybeUninit<A>; N] = &result;
        unsafe { std::ptr::read(spam as *const [A; N]) }
    }
}

fn main() {
    let _: [u8; 10] = (0_u8..10).foo::<10_usize>();
}
=== stdout ===
=== stderr ===
==============

=== stdout ===
=== stderr ===
==============
@Alexendoo Alexendoo merged commit 0816e49 into master Jul 16, 2020
@Alexendoo Alexendoo deleted the autofix/ices/73730.rs branch July 16, 2020 12:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants