Skip to content

type validation failed: encountered undefined bytes at (*.vtable_ptr)[3] #53401

Closed
@denisandroid

Description

@denisandroid

When developing the library, I encountered a strange error which does not occur on a stable version of the compiler.
При разработке библиотеки я обнаружил странную ошибку, которая не возникает в стабильной версии компилятора.

/*
-------------------------
Versions of the compiler:
    NIGHTLY(1.30) 2018-08-14 67390c0c312ca2d8649e
    BETA(1.29) 2018-08-09 d600a945a6b189edd295

error[E0080]: this static likely exhibits undefined behavior
  --> src/main.rs:11:1
   |
11 | static mut Test: &'static Test<'static> = &Null;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered undefined bytes at (*.vtable_ptr)[3]
   |
   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

-------------------------
Versions of the compiler:
    STABLE (1.28.0)

!!Compilation is successful on the playground and on the code and only when using a stable compiler.
!!Компиляция прошла успешно на игровой площадке и в коде, и только при использовании стабильного компилятора.

*/


//The code was written in the likeness of my library
//Код был написан по подобию моей библиотеки


#[allow(dead_code)]
#[allow(non_upper_case_globals)]
static mut STATIC_TRAIT: &'static Test<'static> = &Null;


fn main() {
    
}


//Basic structure
//Основная структура
pub struct Null;

//The transformed structure
//Преобразованная структура
pub struct Null2;



pub trait Test<'a>: Test2<'a> {
    //Basic generalization available through static
    //Основное обобщение доступно через статику
}
impl<'a> Test2<'a> for Null {}
impl<'a> Test<'a> for Null {}

impl<'a> Test2<'a> for Null2 {}
impl<'a> Test<'a> for Null2 {}


//Generalized transformation. It is impossible to merge with the basic generalization
//Обобщенное преобразование. Невозможно слиться с основным обобщением
pub trait Test2<'a> {
    
    //In real code, the transformation of one structure to another
    //В реальном коде преобразование одной структуры в другую
    fn test() -> Null2 where Self: Sized + Test<'a> {
        Null2
    }
    
}

//#Ulin 17-18 :)



/*
    Additionally!!!
    Дополнительно!!!
    
    ```
    fn test() -> Null2 where Self: Sized + Test<'a> {
        Null2
    }
    ```
    Convert to ->
    
    ```
    fn test() -> Null2 where Self: Test<'a> {
        Null2
    }
    ```
    
    error[E0038]: the trait `Test` cannot be made into an object
  --> src/main.rs:39:1
   |
39 | static mut STATIC_TRAIT: &'static Test<'static> = &Null;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Test` cannot be made into an object
   |
   = note: method `test` has no receiver
   
   Ie, as I understand it, the compiler scolds itself because of the lack of function??
   Т.е., как я понимаю, компилятор ругает сам себя из-за отсутствия функции?
*/


(Playground)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions