Skip to content
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

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

Closed
denisandroid opened this issue Aug 15, 2018 · 7 comments
Closed
Labels
P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@denisandroid
Copy link

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)

@csmoe csmoe added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Aug 16, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Aug 16, 2018

Minimal repro:

pub const STATIC_TRAIT: &Test = &();

fn main() {}

pub trait Test {
    fn test() where Self: Sized {}
}

impl Test for () {}

@RalfJung
Copy link
Member

Fixed by #53424 -- still investigating whether that is accidental or deliberate. ;)

@RalfJung
Copy link
Member

I am not sure where it is getting the [3] from, but the handling of fat pointers in the sanity check is not optimal, and greatly improved by my PR. I suppose that's what fixed this problem.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 16, 2018

The [3] is the 4th field, so the function pointer for test, which shouldn't exist

I'll create a separate beta fix, #53424 is not backportable

@RalfJung
Copy link
Member

Oh, this is walking the actual vtable?

Well then maybe this if fixed because I am not doing that any more.^^ I did not know that it had any meaningful layout...

@oli-obk
Copy link
Contributor

oli-obk commented Aug 16, 2018

Yea, that walk was pretty useless anyway. We should just extend your code (which knows the self type) to properly check all the vtable fields instead of attempting to layout the vtable without Self

@nikomatsakis nikomatsakis added P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 23, 2018
bors added a commit that referenced this issue Aug 26, 2018
[beta] Don't sanity check function pointers in vtables

cc #53401

There's no beta nomination because the full fix (#53424) is not backportable
@pnkfelix
Copy link
Member

closing as this is fixed on beta (by #53425) and master (by #53424).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants