-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 #136520 - compiler-errors:redundant-layout-assert, r=…
…lcnr Remove unnecessary layout assertions for object-safe receivers The soundness of `DispatchFromDyn` relies on the fact that, like all other built-in marker-like layout traits (e.g. `Sized`, `CoerceUnsized`), the guarantees that they enforce in *generic* code via traits will result in assumptions that we can rely on in codegen. Specifically, `DispatchFromDyn` ensures that we end up with a receiver that is a valid pointer type, and its implementation validity recursively ensures that the ABI of that pointer type upholds the `Scalar` or `ScalarPair` representation for sized and unsized pointees, respectively. The check that this layout guarantee holds for arbitrary, possibly generic receiver types that also may exist in possibly impossible-to-instantiate where clauses is overkill IMO, and leads to several ICEs due to the fact that computing layouts before monomorphization is going to be fallible at best. This PR removes the check altogether, since it just exists as a sanity check from very long ago, 6f2a161. Fixes #125810 Fixes #90110 This PR is an alternative to #136195. cc `@adetaylor.` I didn't realize in that PR that the layout checks that were being modified were simply *sanity checks*, rather than being actually necessary for soundness.
- Loading branch information
Showing
6 changed files
with
42 additions
and
173 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
//@ check-pass | ||
// Regression test for #90110. | ||
|
||
// Make sure that object safety checking doesn't freak out when | ||
// we have impossible-to-satisfy `Sized` predicates. | ||
|
||
trait Parser | ||
where | ||
for<'a> (dyn Parser + 'a): Sized, | ||
{ | ||
fn parse_line(&self); | ||
} | ||
|
||
fn foo(_: &dyn Parser) {} | ||
|
||
fn main() {} |
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,19 @@ | ||
//@ check-pass | ||
|
||
// Make sure that object safety checking doesn't freak out when | ||
// we have impossible-to-satisfy `DispatchFromDyn` predicates. | ||
|
||
#![feature(dispatch_from_dyn)] | ||
#![feature(arbitrary_self_types)] | ||
|
||
use std::ops::Deref; | ||
use std::ops::DispatchFromDyn; | ||
|
||
trait Trait<T: Deref<Target = Self>> | ||
where | ||
for<'a> &'a T: DispatchFromDyn<&'a T>, | ||
{ | ||
fn foo(self: &T) -> Box<dyn Trait<T>>; | ||
} | ||
|
||
fn main() {} |
6 changes: 5 additions & 1 deletion
6
tests/crashes/57276.rs → tests/ui/self/dispatch-from-dyn-layout.rs
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