]> git.lizzy.rs Git - rust.git/commit
Auto merge of #54183 - qnighy:by-value-object-safety, r=oli-obk
authorbors <bors@rust-lang.org>
Sat, 27 Oct 2018 19:29:35 +0000 (19:29 +0000)
committerbors <bors@rust-lang.org>
Sat, 27 Oct 2018 19:29:35 +0000 (19:29 +0000)
commitcae6efc37d70ab7d353e6ab9ce229d59a65ed643
tree755deb56e86b2436a04ccbab70b3506608e36075
parentb3b87609713887a27ebd07557af14e4aa57771f3
parent2f7ea4a8725d433db4f34fca87eb7f61afb7ef9a
Auto merge of #54183 - qnighy:by-value-object-safety, r=oli-obk

Implement by-value object safety

This PR implements **by-value object safety**, which is part of unsized rvalues #48055. That means, with `#![feature(unsized_locals)]`, you can call a method `fn foo(self, ...)` on trait objects. One aim of this is to enable `Box<FnOnce>`  in the near future.

The difficulty here is this: when constructing a vtable for a trait `Foo`, we can't just put the function `<T as Foo>::foo` into the table. If `T` is no larger than `usize`, `self` is usually passed directly. However, as the caller of the vtable doesn't know the concrete `Self` type, we want a variant of `<T as Foo>::foo` where `self` is always passed by reference.

Therefore, when the compiler encounters such a method to be generated as a vtable entry, it produces a newly introduced instance called `InstanceDef::VtableShim(def_id)` (that wraps the original instance). the shim just derefs the receiver and calls the original method. We give different symbol names for the shims by appending `::{{vtable-shim}}` to the symbol path (and also adding vtable-shimness as an ingredient to the symbol hash).

r? @eddyb
src/librustc/ich/impls_ty.rs
src/librustc/ty/mod.rs
src/librustc/ty/structural_impls.rs
src/librustc_codegen_llvm/base.rs
src/librustc_mir/monomorphize/collector.rs
src/librustc_mir/shim.rs