forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#131864 - lrh2000:upcast_reorder, r=WaffleLa…
…pkin Never emit `vptr` for empty/auto traits Emiting `vptr`s for empty/auto traits is unnecessary (rust-lang#114942) and causes unsoundness in `trait_upcasting` (rust-lang#131813). This PR should ensure that we never emit vtables for such traits. See the linked issues for more details. I'm not sure if I can add tests for the vtable layout. So this PR only adds tests for the soundness hole (i.e., the segmentation fault will disappear after this PR). Fixes rust-lang#114942 Fixes rust-lang#131813 Cc rust-lang#65991 (tracking issue for `trait_upcasting`) r? `@WaffleLapkin` (per rust-lang#131813 (comment))
- Loading branch information
Showing
4 changed files
with
36 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//@ run-pass | ||
// | ||
// issue: <https://github.com/rust-lang/rust/issues/131813> | ||
|
||
#![feature(trait_upcasting)] | ||
|
||
trait Pollable { | ||
#[allow(unused)] | ||
fn poll(&self) {} | ||
} | ||
trait FileIo: Pollable + Send + Sync { | ||
fn read(&self) {} | ||
} | ||
trait Terminal: Send + Sync + FileIo {} | ||
|
||
struct A; | ||
|
||
impl Pollable for A {} | ||
impl FileIo for A {} | ||
impl Terminal for A {} | ||
|
||
fn main() { | ||
let a = A; | ||
|
||
let b = &a as &dyn Terminal; | ||
let c = b as &dyn FileIo; | ||
|
||
c.read(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters