profile
viewpoint

brson/miri 209

An experimental compiler from Rust to WebAssembly (inactive - do not use)

eholk/Boot2Rust 201

EFI applications in Rust

eholk/elegant-weapons 114

An R6RS framework for creating compilers that target C.

eholk/Arduino-Pong 16

A simple Pong game for the Arduino which uses one of the OLED displays from Adafruit.

eholk/bench-dot-product 11

Several variations of a dot product benchmark.

eholk/coq-stlc 3

Proof of type safety for Simply Typed Lambda Calculus in Coq.

eholk/artifact 1

The open source design documentation tool for everybody

eholk/bdwgc 1

The Boehm-Demers-Weiser conservative C/C++ Garbage Collector (libgc, bdwgc, boehmgc)

Pull request review commentrust-lang/rust

Add help for trying to do C-like pointer arithmetics

 impl<'a, 'tcx> FnCtxt<'a, 'tcx> {                         }                     }                 }++                // Suggest using `add`, `offset` or `offset_from` for pointer - {integer},+                // pointer + {integer} or pointer - pointer.+                if op.span.can_be_used_for_suggestions() {+                    if op.node == hir::BinOpKind::Add {+                        match (lhs_ty.kind(), rhs_ty) {+                            (RawPtr(..), rhs_ty) if rhs_ty.is_integral() => {+                                let lhs_snip =+                                    self.tcx.sess.source_map().span_to_snippet(lhs_expr.span);+                                let rhs_snip =+                                    self.tcx.sess.source_map().span_to_snippet(rhs_expr.span);+                                if let Ok(lhs_snip) = lhs_snip && let Ok(rhs_snip) = rhs_snip {+                                    err.span_suggestion(+                                        expr.span,+                                        "consider using `wrapping_add` or `add` for pointer + {integer}",+                                        format!("{lhs_snip}.wrapping_add({rhs_snip})"),+                                        Applicability::MaybeIncorrect+                                    );+                                }+                            }+                            _ => {}+                        }+                    } else if op.node == hir::BinOpKind::Sub {+                        match (lhs_ty.kind(), rhs_ty) {+                            (RawPtr(..), rhs_ty) if rhs_ty.is_integral() => {+                                let lhs_snip =+                                    self.tcx.sess.source_map().span_to_snippet(lhs_expr.span);+                                let rhs_snip =+                                    self.tcx.sess.source_map().span_to_snippet(rhs_expr.span);+                                if let Ok(lhs_snip) = lhs_snip && let Ok(rhs_snip) = rhs_snip {+                                    err.span_suggestion(+                                        expr.span,+                                        "consider using `wrapping_sub` or `sub` for pointer - {integer}",+                                        format!("{lhs_snip}.wrapping_sub({rhs_snip})"),+                                        Applicability::MaybeIncorrect+                                    );+                                }+                            }+                            (RawPtr(..), rhs_ty) if rhs_ty.is_unsafe_ptr() => {+                                let lhs_snip =+                                    self.tcx.sess.source_map().span_to_snippet(lhs_expr.span);+                                let rhs_snip =+                                    self.tcx.sess.source_map().span_to_snippet(rhs_expr.span);+                                if let Ok(lhs_snip) = lhs_snip && let Ok(rhs_snip) = rhs_snip {+                                    err.span_suggestion(+                                        expr.span,+                                        "consider using `offset_from` for pointer - pointer",+                                        format!("unsafe {{ {lhs_snip}.offset_from({rhs_snip}) }}"),

Is there a safe suggestion we could make here? I didn't find one immediately after poking around the docs a little...

jieyouxu

comment created time in 5 hours

PullRequestReviewEvent

pull request commentrust-lang/rust

Implement intrinsic for swapping values

@RalfJung - do you mind if I reassign this to you? You seem to have a much better idea of what's needed than I do. Feel free to reroll if you want to review the whole thing. Thanks!

r? @RalfJung

AngelicosPhosphoros

comment created time in 5 hours

pull request commentrust-lang/rust

Make struct layout not depend on unsizeable tail

Niche layout decisions seem subtle enough that I don't really feel confident reviewing this, so I'll reroll.

r? compiler

lukas-code

comment created time in 3 days

push eventeholk/ebg

Eric Holk

commit sha 63dc5f1b7984da971cacb664da384eb22d701c99

Add cool console progress bar

view details

Eric Holk

commit sha 567a0f9e5a8060ee9558b7585b402bb5ae159d11

Report how much time it took to build the site

view details

push time in 9 days

delete branch eholk/stackfuture

delete branch : administrivia

delete time in 11 days

push eventmicrosoft/stackfuture

Eric Holk

commit sha bd63ac01a50e731f524732601353953c1c352c93

Add missing copyright header and fix SUPPORT.md

view details

push time in 11 days

create barncheholk/stackfuture

branch : administrivia

created branch time in 11 days

push eventeholk/rust

Eric Holk

commit sha 6b795e424123adaec4cd7338e75304e2bd7bda05

#[may_dangle]

view details

push time in 11 days

push eventeholk/rust

Eric Holk

commit sha ef01d9079dd738251faf6376ed8380d58d085edf

Fix doc comment

view details

push time in 11 days

Pull request review commentrust-lang/rust

Add `alloc::rc::UniqueRc`

 fn data_offset_align(align: usize) -> usize {     let layout = Layout::new::<RcBox<()>>();     layout.size() + layout.padding_needed_for(align) }++/// A uniquely owned `Rc`+///+/// This represents an `Rc` that is known to be uniquely owned -- that is, have exactly one strong+/// reference. Multiple weak pointers can be created, but attempts to upgrade those to strong+/// references will fail unless the `UniqueRc` they point to has been converted into a regular `Rc`.+///+/// Because they are uniquely owned, the contents of a `UniqueRc` can be freely mutated. A common+/// use case is to have an object be mutable during its initialization phase but then have it become+/// immutable and converted to a normal `Rc`.+///+/// This can be used as a flexible way to create cyclic data structures, as in the example below.+///+/// ```+/// #![feature(unique_rc_arc)]+/// use std::rc::{Rc, Weak, UniqueRc};+///+/// struct Gadget {+///     #[allow(dead_code)]+///     me: Weak<Gadget>,+/// }+///+/// fn create_gadget() -> Option<Rc<Gadget>> {+///     let mut rc = UniqueRc::new(Gadget {+///         me: Weak::new(),+///     });+///     rc.me = UniqueRc::downgrade(&rc);+///     Some(UniqueRc::into_rc(rc))+/// }+///+/// create_gadget().unwrap();+/// ```+///+/// An advantage of using `UniqueRc` over [`Rc::new_cyclic`] to build cyclic data structures is that+/// [`Rc::new_cyclic`]'s `data_fn` parameter cannot be async or return a [`Result`]. As shown in the+/// previous example, `UniqueRc` allows for more flexibility in the construction of cyclic data,+/// including fallible or async constructors.+#[unstable(feature = "unique_rc_arc", issue = "none")]+#[derive(Debug)]+pub struct UniqueRc<T> {+    ptr: NonNull<RcBox<T>>,+}++impl<T> UniqueRc<T> {+    /// Creates a new `UniqueRc`+    ///+    /// Weak references to this `UniqueRc` can be created with [`UniqueRc::weak`]. Upgrading these

Good catch! Fixed.

eholk

comment created time in 11 days

PullRequestReviewEvent

Pull request review commentrust-lang/rust

Add `alloc::rc::UniqueRc`

 fn data_offset_align(align: usize) -> usize {     let layout = Layout::new::<RcBox<()>>();     layout.size() + layout.padding_needed_for(align) }++/// A uniquely owned `Rc`+///+/// This represents an `Rc` that is known to be uniquely owned -- that is, have exactly one strong+/// reference. Multiple weak pointers can be created, but attempts to upgrade those to strong+/// references will fail unless the `UniqueRc` they point to has been converted into a regular `Rc`.+///+/// Because they are uniquely owned, the contents of a `UniqueRc` can be freely mutated. A common+/// use case is to have an object be mutable during its initialization phase but then have it become+/// immutable and converted to a normal `Rc`.+///+/// This can be used as a flexible way to create cyclic data structures, as in the example below.+///+/// ```+/// #![feature(unique_rc_arc)]+/// use std::rc::{Rc, Weak, UniqueRc};+///+/// struct Gadget {+///     #[allow(dead_code)]+///     me: Weak<Gadget>,+/// }+///+/// fn create_gadget() -> Option<Rc<Gadget>> {+///     let mut rc = UniqueRc::new(Gadget {+///         me: Weak::new(),+///     });+///     rc.me = UniqueRc::downgrade(&rc);+///     Some(UniqueRc::into_rc(rc))+/// }+///+/// create_gadget().unwrap();+/// ```+///+/// An advantage of using `UniqueRc` over [`Rc::new_cyclic`] to build cyclic data structures is that+/// [`Rc::new_cyclic`]'s `data_fn` parameter cannot be async or return a [`Result`]. As shown in the+/// previous example, `UniqueRc` allows for more flexibility in the construction of cyclic data,+/// including fallible or async constructors.+#[unstable(feature = "unique_rc_arc", issue = "none")]+#[derive(Debug)]+pub struct UniqueRc<T> {+    ptr: NonNull<RcBox<T>>,+}++impl<T> UniqueRc<T> {+    /// Creates a new `UniqueRc`+    ///+    /// Weak references to this `UniqueRc` can be created with [`UniqueRc::weak`]. Upgrading these+    /// weak references will fail before the `UniqueRc` has been converted into an [`Rc`]. After+    /// converting the `UniqueRc` into an [`Rc`], any weak references created beforehand will point+    /// to the new [`Rc`].+    #[unstable(feature = "unique_rc_arc", issue = "none")]+    pub fn new(value: T) -> Self {+        Self {+            ptr: Box::leak(Box::new(RcBox {+                strong: Cell::new(0),+                // keep one weak reference so if all the weak pointers that are created are dropped+                // the UniqueRc still stays valid.+                weak: Cell::new(1),+                value,+            }))+            .into(),+        }+    }++    /// Creates a new weak reference to the `UniqueRc`+    ///+    /// Attempting to upgrade this weak reference will fail before the `UniqueRc` has been converted+    /// to a [`Rc`] using [`UniqueRc::into_rc`].+    #[unstable(feature = "unique_rc_arc", issue = "none")]+    pub fn downgrade(this: &Self) -> Weak<T> {+        // SAFETY: This pointer was allocated at creation time and we guarantee that we only have+        // one strong reference before converting to a regular Rc.+        unsafe {+            this.ptr.as_ref().inc_weak();+        }+        Weak { ptr: this.ptr }+    }++    /// Converts the `UniqueRc` into a regular [`Rc`]+    ///+    /// This consumes the `UniqueRc` and returns a regular [`Rc`] that contains the `value` that+    /// is passed to `into_rc`.+    ///+    /// Any weak references created before this method is called can now be upgraded to strong+    /// references.+    #[unstable(feature = "unique_rc_arc", issue = "none")]+    pub fn into_rc(this: Self) -> Rc<T> {+        let mut this = ManuallyDrop::new(this);+        // SAFETY: This pointer was allocated at creation time so we know it is valid.+        unsafe {+            // Convert our weak reference into a strong reference+            this.ptr.as_mut().strong.set(1);+            Rc::from_inner(this.ptr)+        }+    }+}++#[unstable(feature = "unique_rc_arc", issue = "none")]+impl<T> Deref for UniqueRc<T> {+    type Target = T;++    fn deref(&self) -> &T {+        // SAFETY: This pointer was allocated at creation time so we know it is valid.+        unsafe { &self.ptr.as_ref().value }+    }+}++#[unstable(feature = "unique_rc_arc", issue = "none")]+impl<T> DerefMut for UniqueRc<T> {+    fn deref_mut(&mut self) -> &mut T {+        // SAFETY: This pointer was allocated at creation time so we know it is valid. We know we+        // have unique ownership and therefore it's safe to make a mutable reference because+        // `UniqueRc` owns the only strong reference to itself.+        unsafe { &mut self.ptr.as_mut().value }+    }+}++#[unstable(feature = "unique_rc_arc", issue = "none")]+impl<T> Drop for UniqueRc<T> {+    fn drop(&mut self) {+        // We want to make sure the pretend weak reference we're holding gets dropped, so convert+        // ourselves into an actual Weak reference and let its destructor take over.+        Weak { ptr: self.ptr };

🤦‍♂️ Oops. Back when this was MaybeUninit I was going out of my way not to drop it and I forgot I needed to change it back. This should be fixed now.

eholk

comment created time in 11 days

PullRequestReviewEvent

push eventeholk/rust

Eric Holk

commit sha 2f71d30885a4bbda910a8877600205442efc3d6e

initialize phantom field

view details

Eric Holk

commit sha 70d989c19722b7f9a02bb73948199315a410b371

Drop UniqueRc contents when dropping UniqueRc

view details

push time in 11 days

push eventeholk/rust

Eric Holk

commit sha 43072c3f0b25e5e3b8f01c92477ea56032482bf9

Update library/alloc/src/rc.rs Co-authored-by: Jacob Lifshay <programmerjake@gmail.com>

view details

push time in 11 days

Pull request review commentrust-lang/rust

Add `alloc::rc::UniqueRc`

 fn data_offset_align(align: usize) -> usize {     let layout = Layout::new::<RcBox<()>>();     layout.size() + layout.padding_needed_for(align) }++/// A uniquely owned `Rc`+///+/// This represents an `Rc` that is known to be uniquely owned -- that is, have exactly one strong+/// reference. Multiple weak pointers can be created, but attempts to upgrade those to strong+/// references will fail unless the `UniqueRc` they point to has been converted into a regular `Rc`.+///+/// Because they are uniquely owned, the contents of a `UniqueRc` can be freely mutated. A common+/// use case is to have an object be mutable during its initialization phase but then have it become+/// immutable and converted to a normal `Rc`.+///+/// This can be used as a flexible way to create cyclic data structures, as in the example below.+///+/// ```+/// #![feature(unique_rc_arc)]+/// use std::rc::{Rc, Weak, UniqueRc};+///+/// struct Gadget {+///     #[allow(dead_code)]+///     me: Weak<Gadget>,+/// }+///+/// fn create_gadget() -> Option<Rc<Gadget>> {+///     let mut rc = UniqueRc::new(Gadget {+///         me: Weak::new(),+///     });+///     rc.me = UniqueRc::downgrade(&rc);+///     Some(UniqueRc::into_rc(rc))+/// }+///+/// create_gadget().unwrap();+/// ```+///+/// An advantage of using `UniqueRc` over [`Rc::new_cyclic`] to build cyclic data structures is that+/// [`Rc::new_cyclic`]'s `data_fn` parameter cannot be async or return a [`Result`]. As shown in the+/// previous example, `UniqueRc` allows for more flexibility in the construction of cyclic data,+/// including fallible or async constructors.+#[unstable(feature = "unique_rc_arc", issue = "none")]+#[derive(Debug)]+pub struct UniqueRc<T> {+    ptr: NonNull<RcBox<T>>,+}++impl<T> UniqueRc<T> {+    /// Creates a new `UniqueRc`+    ///+    /// Weak references to this `UniqueRc` can be created with [`UniqueRc::weak`]. Upgrading these+    /// weak references will fail before the `UniqueRc` has been converted into an [`Rc`]. After+    /// converting the `UniqueRc` into an [`Rc`], any weak references created beforehand will point+    /// to the new [`Rc`].+    #[unstable(feature = "unique_rc_arc", issue = "none")]+    pub fn new(value: T) -> Self {+        Self {+            ptr: Box::leak(Box::new(RcBox {+                strong: Cell::new(0),+                // keep one weak reference so if all the weak pointers that are created are dropped+                // the UniqueRc still stays valid.+                weak: Cell::new(1),+                value,+            }))+            .into(),+        }+    }++    /// Creates a new weak reference to the `UniqueRc`+    ///+    /// Attempting to upgrade this weak reference will fail before the `UniqueRc` has been converted+    /// to a [`Rc`] using [`UniqueRc::into_rc`].+    #[unstable(feature = "unique_rc_arc", issue = "none")]+    pub fn downgrade(this: &Self) -> Weak<T> {+        // SAFETY: This pointer was allocated at creation time and we guarantee that we only have+        // one strong reference before converting to a regular Rc.+        unsafe {+            this.ptr.as_ref().inc_weak();+        }+        Weak { ptr: this.ptr }+    }++    /// Converts the `UniqueRc` into a regular [`Rc`]+    ///+    /// This consumes the `UniqueRc` and returns a regular [`Rc`] that contains the `value` that+    /// is passed to `into_rc`.+    ///+    /// Any weak references created before this method is called can now be upgraded to strong+    /// references.+    #[unstable(feature = "unique_rc_arc", issue = "none")]+    pub fn into_rc(this: Self) -> Rc<T> {+        let mut this = ManuallyDrop::new(this);+        // SAFETY: This pointer was allocated at creation time so we know it is valid.+        unsafe {+            // Convert our weak reference into a strong reference+            this.ptr.as_mut().strong.set(1);+            Rc::from_inner(this.ptr)+        }+    }+}++#[unstable(feature = "unique_rc_arc", issue = "none")]+impl<T> Deref for UniqueRc<T> {+    type Target = T;++    fn deref(&self) -> &T {+        // SAFETY: This pointer was allocated at creation time so we know it is valid.+        unsafe { &self.ptr.as_ref().value }+    }+}++#[unstable(feature = "unique_rc_arc", issue = "none")]+impl<T> DerefMut for UniqueRc<T> {+    fn deref_mut(&mut self) -> &mut T {+        // SAFETY: This pointer was allocated at creation time so we know it is valid. We know we+        // have unique ownership and therefore it's safe to make a mutable reference because+        // `UniqueRc` owns the only strong reference to itself.+        unsafe { &mut self.ptr.as_mut().value }

Thanks! Is there a way I can test for this? It seems like a thing we might need miri to check.

eholk

comment created time in 11 days

PullRequestReviewEvent

push eventeholk/rust

Eric Holk

commit sha c0a89646cf852ba74cc61e60455317500908e92d

Update library/alloc/src/rc.rs Co-authored-by: Jacob Lifshay <programmerjake@gmail.com>

view details

push time in 11 days

pull request commentrust-lang/rust

[RFC-2011] Expand more expressions

Looks good to me. Thanks!

@bors r+

c410-f3r

comment created time in 11 days

Pull request review commentrust-lang/rust

Always capture slice when pattern requires checking the length

 impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {                         // to borrow discr.                         needs_to_be_read = true;                     }+                    PatKind::Slice(&[], Some(_), &[]) if !discr_place.place.base_ty.is_array() => {+                        // If the pattern is a wildcard only, we don't need to read the length+                    }+                    PatKind::Slice(..) if !discr_place.place.base_ty.is_array() => {+                        needs_to_be_read = true;+                    }                     PatKind::Or(_)                     | PatKind::Box(_)                     | PatKind::Slice(..)

@clubby789 - you marked @cjgillot's suggestions as resolved, but it'd be helpful to see a quick comment about why. It looks like these are mainly code organization suggestions rather than a functional change, so maybe you decided you preferred the way it was written at first?

clubby789

comment created time in 11 days

PullRequestReviewEvent

pull request commentrust-lang/rust

Consider lint check attributes on match arms

Looks good to me. Thanks!

@bors r+

lowr

comment created time in 11 days

pull request commentrust-lang/rust

Add `alloc::rc::UniqueRc`

I updated the PR to implement UniqueRc<T> as a thing that always holds an initialized T and provides a DerefMut impl so you can freely mutate its contents before converting it to an Rc.

I also changed all the functions to not have a self, since the pattern for Rc and such is to avoid adding new methods that could conflict with methods on the underlying T.

Finally, I renamed UniqueRc::weak to UniqueRc::downgrade for better symmetry with Rc.

eholk

comment created time in 12 days

push eventeholk/rust

Eric Holk

commit sha 564380a23f77616ab5a5a1e1f75dee5e41f75ec9

Make UniqueRc actually a uniquely owned Rc

view details

Eric Holk

commit sha 9631369a8075564d769868019299688206ae01d4

Update docs, comments, and change API to not add more methods

view details

Eric Holk

commit sha bfe046e726dabcbb06d51ca761ccd6fe09f8b4e4

UniqueRc::weak -> UniqueRc::downgrade

view details

push time in 12 days

pull request commentrust-lang/rust

Add `alloc::rc::UniqueRc`

for UniqueRc at least, it does require modifying Rc's internals in order to prevent Weak::upgrade from working until the UniqueRc has been converted into an Rc

Oh, good point. Thanks for pointing that out!

eholk

comment created time in 12 days

CommitCommentEvent
more