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

ices/62222.rs: fixed with errors #269

Merged
merged 1 commit into from
Jan 24, 2020
Merged

ices/62222.rs: fixed with errors #269

merged 1 commit into from
Jan 24, 2020

Conversation

github-actions[bot]
Copy link
Contributor

Issue: rust-lang/rust#62222

#![feature(const_generics)]

use std::mem::{self, MaybeUninit};

#[repr(transparent)]
pub struct Vector<T, const N: usize>([T; N]);

impl<T, const N: usize> Vector<T, {N}> {
    pub fn x(self) -> T {
        let mut head = MaybeUninit::<T>::uninit();
        let mut tail = MaybeUninit::<[T; N - 1]>::uninit();
        let mut from = MaybeUninit::new(self);
        let tailp: *mut T = unsafe { mem::transmute(&mut tail) };
        let fromp: *mut MaybeUninit<T> = unsafe { mem::transmute(&mut from) };
        unsafe {
            head.as_mut_ptr().write(
                fromp
                    .replace(MaybeUninit::uninit())
                    .assume_init()
            );
        }
        for i in 1..N {
            unsafe {
                tailp.add(i - 1).write(
                    fromp
                        .add(i)
                        .replace(MaybeUninit::uninit())
                        .assume_init()
                );
            }
        }
        unsafe { tail.assume_init(); } // Drop the tail
        unsafe { head.assume_init() }
    }
}

fn main() {}
=== stdout ===
=== stderr ===
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> /home/runner/work/glacier/glacier/ices/62222.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

error: constant expression depends on a generic parameter
  --> /home/runner/work/glacier/glacier/ices/62222.rs:11:24
   |
11 |         let mut tail = MaybeUninit::<[T; N - 1]>::uninit();
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
  --> /home/runner/work/glacier/glacier/ices/62222.rs:11:24
   |
11 |         let mut tail = MaybeUninit::<[T; N - 1]>::uninit();
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
  --> /home/runner/work/glacier/glacier/ices/62222.rs:13:38
   |
13 |         let tailp: *mut T = unsafe { mem::transmute(&mut tail) };
   |                                      ^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
  --> /home/runner/work/glacier/glacier/ices/62222.rs:32:18
   |
32 |         unsafe { tail.assume_init(); } // Drop the tail
   |                  ^^^^^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: aborting due to 4 previous errors

==============

=== stdout ===
=== stderr ===
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> /home/runner/work/glacier/glacier/ices/62222.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

error: constant expression depends on a generic parameter
  --> /home/runner/work/glacier/glacier/ices/62222.rs:11:24
   |
11 |         let mut tail = MaybeUninit::<[T; N - 1]>::uninit();
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
  --> /home/runner/work/glacier/glacier/ices/62222.rs:11:24
   |
11 |         let mut tail = MaybeUninit::<[T; N - 1]>::uninit();
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
  --> /home/runner/work/glacier/glacier/ices/62222.rs:13:38
   |
13 |         let tailp: *mut T = unsafe { mem::transmute(&mut tail) };
   |                                      ^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
  --> /home/runner/work/glacier/glacier/ices/62222.rs:32:18
   |
32 |         unsafe { tail.assume_init(); } // Drop the tail
   |                  ^^^^^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: aborting due to 4 previous errors

==============
@Alexendoo Alexendoo merged commit d6c986b into master Jan 24, 2020
@Alexendoo Alexendoo deleted the autofix/ices/62222.rs branch January 24, 2020 12:10
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