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

ices/79518.rs: fixed with errors #657

Merged
merged 1 commit into from
Feb 17, 2021
Merged

ices/79518.rs: fixed with errors #657

merged 1 commit into from
Feb 17, 2021

Conversation

github-actions[bot]
Copy link
Contributor

Issue: rust-lang/rust#79518

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

use std::mem;

pub trait HardcodedPayload {
    type ArrayType: AsRef<[u8]> + AsMut<[u8]> + Default + PartialEq;
    const PAYLOAD: Self::ArrayType;

    fn test() where [u8; mem::size_of::<Self::ArrayType>()]: Sized + PartialEq { //workaround for `[u8; N]`
        let mut buf = [0u8; mem::size_of::<Self::ArrayType>()];
        //*insert read here*
        if buf == Self::PAYLOAD {} //crashed here
    }
}

pub struct UserStruct {
    _a: i32,
}

impl HardcodedPayload for UserStruct {
    type ArrayType = [u8; 2];
    const PAYLOAD: Self::ArrayType = [0xff, 0xff];
}

fn main() {}
=== stdout ===
=== stderr ===
error[E0308]: mismatched types
  --> /home/runner/work/glacier/glacier/ices/79518.rs:13:19
   |
13 |         if buf == Self::PAYLOAD {} //crashed here
   |                   ^^^^^^^^^^^^^ expected array `[u8; _]`, found associated type
   |
   = note:        expected array `[u8; _]`
           found associated type `<Self as HardcodedPayload>::ArrayType`
   = help: consider constraining the associated type `<Self as HardcodedPayload>::ArrayType` to `[u8; _]`
   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
==============

=== stdout ===
=== stderr ===
error[E0308]: mismatched types
  --> /home/runner/work/glacier/glacier/ices/79518.rs:13:19
   |
13 |         if buf == Self::PAYLOAD {} //crashed here
   |                   ^^^^^^^^^^^^^ expected array `[u8; _]`, found associated type
   |
   = note:        expected array `[u8; _]`
           found associated type `<Self as HardcodedPayload>::ArrayType`
   = help: consider constraining the associated type `<Self as HardcodedPayload>::ArrayType` to `[u8; _]`
   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
==============
@JohnTitor JohnTitor merged commit f08caf8 into master Feb 17, 2021
@JohnTitor JohnTitor deleted the autofix/ices/79518.rs branch February 17, 2021 16:44
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