Skip to content

Unify constant expressions, mark them as safe, and allow proper pointer arithmetic #259

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

Closed
wants to merge 1 commit into from

Conversation

mahkoh
Copy link
Contributor

@mahkoh mahkoh commented Sep 23, 2014

  • Ensure that, if a constant expression is accepted in one position, then
    it's also accepted in every other position that expects constant
    expressions.
  • Don't force the user to write unsafe { } in constant expressions.
  • Allow arbitrary pointer arithmetic in constant expressions. This includes
    dereferencing the pointer as long as the value is not being read.

Rendered

@mahkoh
Copy link
Contributor Author

mahkoh commented Sep 23, 2014

Here are the implementations of offset_of and align_of:

macro_rules! offset_of {
    ($T:ty, $f:ident) => {
        unsafe { 
            &(*(0u as *const $T)).$f as *const _ as uint
        }
    }
}

macro_rules! align_of {
    ($T:ty) => {{
        #[repr(C)]
        struct TMP {
            _b: u8,
            t: $T,
        }
        offset_of!(TMP, t)
    }}
}

This means that, with this, no special-case CTFE is necessary to get the size and alignment of objects. (You still have to store the expressions if type parameters are involved.)

@aturon
Copy link
Member

aturon commented Feb 12, 2015

Ping @brson

@mahkoh mahkoh closed this Feb 28, 2015
withoutboats pushed a commit to withoutboats/rfcs that referenced this pull request Jan 15, 2017
Add `FutureFrom` trait for future-based conversion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants