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

"constructing invalid value: wrong trait in wide pointer vtable" for seemingly identical traits #3541

Open
Jules-Bertholet opened this issue May 3, 2024 · 4 comments
Labels
A-validation Area: This affects enforcing the validity invariant, and related UB checking C-bug Category: This is a bug. I-false-UB Impact: makes Miri falsely report UB, i.e., a false positive (with default settings)

Comments

@Jules-Bertholet
Copy link
Contributor

Jules-Bertholet commented May 3, 2024

I don't have a minimal reduction atm, but the issue can be reproduced by cloning https://github.com/Jules-Bertholet/unsized-vec and running cargo miri test -p emplacable. This results in the following report of UB:

constructing invalid value: wrong trait in wide pointer vtable: expected `for<'b> std::ops::FnMut(std::alloc::Layout, <[std::boxed::Box<i32>] as std::ptr::Pointee>::Metadata, &'b mut (dyn std::ops::FnMut(*mut std::marker::PhantomData<[std::boxed::Box<i32>]>) + 'b))`, but encountered `for<'a> std::ops::FnMut<(std::alloc::Layout, usize, &'a mut (dyn std::ops::FnMut(*mut std::marker::PhantomData<[std::boxed::Box<i32>]>) + 'a))>`

But the two traits are the same! <[std::boxed::Box<i32>] as std::ptr::Pointee>::Metadata is usize, and for<'a> ... vs for<'b> ... should not make a difference either.

@rustbot label I-false-UB A-validation

@rustbot rustbot added A-validation Area: This affects enforcing the validity invariant, and related UB checking I-false-UB Impact: makes Miri falsely report UB, i.e., a false positive (with default settings) labels May 3, 2024
@RalfJung
Copy link
Member

RalfJung commented May 3, 2024

Probably the use of != around here is wrong. @lcnr what is the proper way to compare two Option<ty::Binder<'tcx, ExistentialTraitRef<'tcx>>>?

@RalfJung RalfJung added the C-bug Category: This is a bug. label May 3, 2024
@lcnr
Copy link
Contributor

lcnr commented May 4, 2024

let ocx = ObligationCtxt::new(infcx);
let param_env = ty::ParamEnv::reveal_all(); // in an empty environment post borrowck
ocx.eq(param_env, lhs, rhs)?; // equate the two trait refs
ocx.select_all_or_error().is_empty() // and check any potential nested constraints

@RalfJung
Copy link
Member

RalfJung commented May 5, 2024

Thanks! We actually have a param_env in the interpreter so I guess it won't be reveal_all. But we don't have a infcx.

@lcnr
Copy link
Contributor

lcnr commented May 6, 2024

you can create a local one, given that the input should not refer to either placeholders or inference variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-validation Area: This affects enforcing the validity invariant, and related UB checking C-bug Category: This is a bug. I-false-UB Impact: makes Miri falsely report UB, i.e., a false positive (with default settings)
Projects
None yet
Development

No branches or pull requests

4 participants