Skip to content
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

Something wrong with 6.8 Extras in "An Ok Unsafe Queue" #228

Open
karakoz opened this issue Apr 5, 2022 · 0 comments
Open

Something wrong with 6.8 Extras in "An Ok Unsafe Queue" #228

karakoz opened this issue Apr 5, 2022 · 0 comments

Comments

@karakoz
Copy link
Contributor

karakoz commented Apr 5, 2022

There are unmodified code from stack implementation after the "Let's steal some iterator impls from the stack:"
Compiler yells with:

error[E0599]: no method named `as_deref` found for raw pointer `*mut fifth::Node<T>` in the current scope
   --> src/fifth.rs:110:35
    |
110 |             self.next = node.next.as_deref();
    |                                   ^^^^^^^^ help: there is an associated function with a similar name: `as_ref`
    |
    = note: try using `<*const T>::as_ref()` to get a reference to the type behind the pointer: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref
    = note: using `<*const T>::as_ref()` on a pointer which is unaligned or points to invalid or uninitialized memory is undefined behavior

error[E0599]: no method named `as_deref_mut` found for raw pointer `*mut fifth::Node<T>` in the current scope
   --> src/fifth.rs:121:35
    |
121 |             self.next = node.next.as_deref_mut();
    |                                   ^^^^^^^^^^^^ method not found in `*mut fifth::Node<T>`
    |
    = note: try using `<*const T>::as_ref()` to get a reference to the type behind the pointer: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref
    = note: using `<*const T>::as_ref()` on a pointer which is unaligned or points to invalid or uninitialized memory is undefined behavior

Which is correct. I think. We should modify the Iter and IterMut impls to use unsafe methods as_ref() and as_mut() like it made in final code. Because Node.next is a raw pointer now.
Am I right?
And maybe it's worth adding a note about stealing tests for iters?

P.S. I really loved your tutorial. It's wonderful.

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

No branches or pull requests

1 participant