Code Monkey home page Code Monkey logo

downcast-rs's People

Contributors

asomers avatar fkoep avatar fkoep-ses avatar jiangliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

downcast-rs's Issues

to_trait_object posssibly unsound

I'm referring to https://github.com/fkoep/downcast-rs/blob/master/src/lib.rs#L107-L117

One thing that seems scary, is it's relying on the internal layout of https://doc.rust-lang.org/std/raw/struct.TraitObject.html . This is nightly specifically because it's not stable (See rust-lang/rust#27751 ) , so if the layout were to change for whatever reason (However unlikely) it would probably break this horribly (And what's more, it would probably work fine on some compiler versions but not others, and possibly not break with just a guaranteed panic but with memory-unsafety/UB).

The assert assert_eq!(mem::size_of::<&T>(), mem::size_of::<TraitObject>()); doesn't feel sufficient to me to guarantee that what is being done is safe. If I recall correctly, slices references(Which satisfy the :?Sized check) have the same size but mean a completely different thing.

Nemo157 on the community discord's #black-magic channel pointed out TraitObject also must be repr(C) for there to be any layout guarantees about it (Reordering, etc).

clippy warns about unsafe functions missing Safety section

The latest clippy (rustc nightly 1.41.0) warns that downcast's generated methods lack a # Safety section in their docs. The appropriate course of action would probably be to silence the warning with #![allow(clippy::missing_safety_doc)].

Build is broken with rustc nightly 1.33.0

The build is broken on the latest Rust nightly

> rustup run nightly rustc --version
rustc 1.33.0-nightly (bf669d1e3 2019-01-25)
> cargo +nightly test
   Compiling downcast v0.9.2 (/usr/home/somers/src/rust/downcast-rs)
error[E0034]: multiple applicable items in scope
   --> src/lib.rs:120:38
    |
120 |     fn is_type(&self) -> bool { self.type_id() == TypeId::of::<T>() }
    |                                      ^^^^^^^ multiple `type_id` found
    |
note: candidate #1 is defined in the trait `Any`
   --> src/lib.rs:29:5
    |
29  |     fn type_id(&self) -> TypeId { TypeId::of::<Self>() }
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: to disambiguate the method call, write `Any::type_id(&self)` instead
note: candidate #2 is defined in the trait `std::any::Any`
    = help: to disambiguate the method call, write `std::any::Any::type_id(&self)` instead

error[E0034]: multiple applicable items in scope
   --> src/lib.rs:120:38
    |
120 |     fn is_type(&self) -> bool { self.type_id() == TypeId::of::<T>() }
    |                                      ^^^^^^^ multiple `type_id` found
    |
note: candidate #1 is defined in the trait `Any`
   --> src/lib.rs:29:5
    |
29  |     fn type_id(&self) -> TypeId { TypeId::of::<Self>() }
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: to disambiguate the method call, write `Any::type_id(&self)` instead
note: candidate #2 is defined in the trait `std::any::Any`
    = help: to disambiguate the method call, write `std::any::Any::type_id(&self)` instead

error: aborting due to previous error

For more information about this error, try `rustc --explain E0034`.
error: aborting due to previous error

For more information about this error, try `rustc --explain E0034`.
error: Could not compile `downcast`.
warning: build failed, waiting for other jobs to finish...
error: Could not compile `downcast`.

To learn more, run the command again with --verbose.

New release?

Would it be possible to make another release of this crate? I'm especially interested in the #[allow(missing_docs)] fix. And for reasons I don't fully understand, downcast works with my crate, but downcast-rs does not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.