Stream: t-compiler/rust-analyzer

Topic: Handle is Object Safe test


kev (Dec 11 2020 at 17:49, on Zulip):

Hi,

I was wondering what the utility of this test is: https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/vfs/src/loader.rs#L129 ?

Lukas Wirth (Dec 11 2020 at 17:50, on Zulip):

That solely tests that the trait Handle is object safe. If It wasn't the use of &dyn Handle as a type would error on compile time

Lukas Wirth (Dec 11 2020 at 17:50, on Zulip):

So it is kind of a compile time test.

Lukas Wirth (Dec 11 2020 at 17:51, on Zulip):

https://doc.rust-lang.org/nightly/reference/items/traits.html?highlight=object,safe#object-safety

kev (Dec 11 2020 at 17:52, on Zulip):

Lukas Wirth said:

That solely tests that the trait Handle is object safe. If It wasn't the use of &dyn Handle as a type would error on compile time

Would anything silently break if it was not object safe?

Jonas Schievink [he/him] (Dec 11 2020 at 17:53, on Zulip):

Yeah, but the test signals intent

kev (Dec 11 2020 at 17:55, on Zulip):

Jonas Schievink said:

Yeah, but the test signals intent

Ah got it

Last update: Jul 27 2021 at 20:30UTC