-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix #56806 by using delay_span_bug
in object safety layout sanity checks
#57229
Conversation
If it's possible for the user to trigger it, it should be addressed, even if it isn't something that's likely to be input. But that can be left for a future PR. It would be good to open an issue to keep track of it, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with the copyright notice removed.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
delay_span_bug
in object safety layout sanity checksdelay_span_bug
in object safety layout sanity checks
@mikeyhew: sorry for the delay — could you squash the changes? After that, r=me. |
It's possible that `is_object_safe` is called on a trait that is ill-formed, and we shouldn't ICE unless there are no errors being raised. Using `delay_span_bug` solves this. fixes rust-lang#56806
@varkor squashed |
@bors r+ |
📌 Commit 2433526 has been approved by |
Fix rust-lang#56806 by using `delay_span_bug` in object safety layout sanity checks It's possible that `is_object_safe` is called on a trait method that with an invalid receiver type. This caused an ICE in rust-lang#56806, because `receiver_is_dispatchable` returns `true` for `self: Box<dyn Trait>`, which causes one of the layout sanity checks in object_safety.rs to fail. Replacing `bug!` with `delay_span_bug` solves this. The fact that `receiver_is_dispatchable` returns `true` here could be considered a bug. It passes the check that the method implements, though: `Box<dyn Trait>` implements `DispatchFromDyn<Box<dyn Trait>>` because `dyn Trait` implements `Unsize<dyn Trait>`. It would be good to hear what @eddyb and @nikomatsakis think. Note that I only added a test for the case encountered in rust-lang#56806. I could not come up with a case that triggered an ICE from the other check, `bug!("receiver when Self = dyn Trait should be ScalarPair, found Scalar")`. There is no way, to my knowledge, that you can make `receiver_is_dispatchable` return true but still have a `Scalar` ABI when `Self = dyn Trait`. One other case I encountered while debugging rust-lang#56806 was that if you have a type parameter `T` that implements `Deref<Target=Self>` and `DispatchFromDyn<T>`, and use it as a method receiver, it will cause an ICE during `is_object_safe` because `T` has no layout ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d9b7497b3be0ca8382fa7d9497263214)): ```rust trait Trait<T: Deref<Target=Self> + DispatchFromDyn<T>> { fn foo(self: T) -> dyn Trait<T>; } ``` I don't intend to remove the ICE there because it is a pathological case, especially since there is no way to implement `DispatchFromDyn<T>` for `T` — the checks in typeck/coherence/builtin.rs do not allow that. fixes rust-lang#56806 r? @varkor
Rollup of 17 pull requests Successful merges: - #57219 (Remove some unused code) - #57229 (Fix #56806 by using `delay_span_bug` in object safety layout sanity checks) - #57233 (Rename and fix nolink-with-link-args test) - #57238 (Fix backtraces for inlined functions on Windows) - #57249 (Fix broken links to second edition TRPL.) - #57267 (src/jemalloc is gone, remove its mention from COPYRIGHT) - #57273 (Update the stdsimd submodule) - #57278 (Add Clippy to config.toml.example) - #57295 (Fix 'be be' constructs) - #57311 (VaList::copy should not require a mutable ref) - #57312 (`const fn` is no longer coming soon (const keyword docs)) - #57313 (Improve Box<T> -> Pin<Box<T>> conversion) - #57314 (Fix repeated word typos) - #57326 (Doc rewording, use the same name `writer`) - #57338 (rustdoc: force binary filename for compiled doctests) - #57342 (librustc_mir: Make qualify_min_const_fn module public) - #57343 (Calculate privacy access only via query) Failed merges: - #57340 (Use correct tracking issue for c_variadic) r? @ghost
It's possible that
is_object_safe
is called on a trait method that with an invalid receiver type. This caused an ICE in #56806, becausereceiver_is_dispatchable
returnstrue
forself: Box<dyn Trait>
, which causes one of the layout sanity checks in object_safety.rs to fail. Replacingbug!
withdelay_span_bug
solves this.The fact that
receiver_is_dispatchable
returnstrue
here could be considered a bug. It passes the check that the method implements, though:Box<dyn Trait>
implementsDispatchFromDyn<Box<dyn Trait>>
becausedyn Trait
implementsUnsize<dyn Trait>
. It would be good to hear what @eddyb and @nikomatsakis think.Note that I only added a test for the case encountered in #56806. I could not come up with a case that triggered an ICE from the other check,
bug!("receiver when Self = dyn Trait should be ScalarPair, found Scalar")
. There is no way, to my knowledge, that you can makereceiver_is_dispatchable
return true but still have aScalar
ABI whenSelf = dyn Trait
.One other case I encountered while debugging #56806 was that if you have a type parameter
T
that implementsDeref<Target=Self>
andDispatchFromDyn<T>
, and use it as a method receiver, it will cause an ICE duringis_object_safe
becauseT
has no layout (playground):I don't intend to remove the ICE there because it is a pathological case, especially since there is no way to implement
DispatchFromDyn<T>
forT
— the checks in typeck/coherence/builtin.rs do not allow that.fixes #56806
r? @varkor