GithubHelp home page GithubHelp logo

rust-field-offset's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rust-field-offset's Issues

causes UB by calling mem::zeroed on any type

This code is highly problematic:

    pub unsafe fn new<F: for<'a> FnOnce(&'a T) -> &'a U>(f: F) -> Self {
        // Construct a "fake" T. It's not valid, but the lambda shouldn't
        // actually access it (which is why this is unsafe)
        let x = mem::zeroed();

If T is, for example, a struct containing reference type, then this causes UB by initializing a reference with 0. The comment seems to say that it is okay to do this as long as x is not accessed; that is not correct.

That said, there currently is no correct way to do what you want. This bug can only really be fixed once MaybeUninit gets stabilized.

(I also feel really uneasy with the extend to which this relies on type inference, but YMMV.^^)

Access fields of an enum variant

I cannot seem to figure out how to get the offset of fields in a enum variant. I tried Enum::Variant => field but that seems to be interfering with the second macro.

Compilation error with version 0.3.2

I'm getting following error using rust nightly:

error[E0658]: `if` is not allowed in a `const fn`
   --> /home/pranjalssh/.cargo/registry/src/github.com-1ecc6299db9ec823/field-offset-0.3.2/src/lib.rs:126:9
    |
126 |         assert!(offset + mem::size_of::<U>() <= mem::size_of::<T>());
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #49146 <https://github.com/rust-lang/rust/issues/49146> for more information
    = help: add `#![feature(const_if_match)]` to the crate attributes to enable
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
error: could not compile `field-offset`.

feature const_fn has been removed

I'm getting this in rust-nightly CI

   Compiling field-offset v0.3.3
error[E0557]: feature has been removed
 --> /github/home/.cargo/registry/src/github.com-1ecc6299db9ec823/field-offset-0.3.3/src/lib.rs:3:53
  |
3 | #![cfg_attr(fieldoffset_assert_in_const_fn, feature(const_fn))]
  |                                                     ^^^^^^^^ feature has been removed
  |
  = note: split into finer-grained feature gates

Warning from offset_of macro if called from an unsafe block

I would expect this to work without the warning.

#[macro_use]
extern crate field_offset;

struct Foo {
    bar: u8
}

pub unsafe fn f() {
    offset_of!(Foo => bar);
}
warning: unnecessary `unsafe` block
 --> src/main.rs:9:5
  |
8 | pub unsafe fn f() {
  | ----------------- because it's nested under this `unsafe` fn
9 |     offset_of!(Foo => bar);
  |     ^^^^^^^^^^^^^^^^^^^^^^^ unnecessary `unsafe` block
  |
  = note: #[warn(unused_unsafe)] on by default

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.