Ad Space — Top Banner

E0614

Rust Programming Language

Severity: Minor

What Does This Error Mean?

You used the * dereference operator on a type that does not support it. Dereferencing only works on references, pointers, and types that implement Deref. Remove the * operator or use the correct method to access the value.

Affected Models

  • Rust stable
  • Rust nightly
  • Cargo build
  • Rust 2021 edition

Common Causes

  • Using * on an owned value like String or Vec instead of a reference to one
  • Applying * to an integer, float, or other primitive that is not a reference
  • Dereferencing a custom type that does not implement the Deref trait
  • Accidentally adding an extra * when the value is already owned, not a reference
  • Confusing a pointer-like wrapper (like Box or Rc) with a raw reference

How to Fix It

  1. Remove the extra * if the value is already owned and not a reference.

    Example: let s = String::from('hello'); let c = *s; — this is wrong. s is owned, just use s directly.

  2. Check the type of the variable — hover over it in VS Code to see its actual type.

    If it shows String instead of &String, you do not need to dereference it. Use it directly.

  3. If you have a Box<T>, Rc<T>, or Arc<T>, dereference it to get a reference to the inner value.

    Example: let x: Box<i32> = Box::new(5); let val = *x; — this works because Box implements Deref.

  4. Implement the Deref trait on your custom type if you want * to work on it.

    impl Deref for MyType { type Target = i32; fn deref(&self) -> &i32 { &self.inner } } — then *my_val works.

  5. For raw pointers (*const T or *mut T), dereference inside an unsafe block.

    Raw pointer dereferences require unsafe { *raw_ptr } — Rust cannot guarantee their safety automatically.

When to Call a Professional

E0614 is a straightforward compile-time error you can fix yourself. It usually means an extra * was added by mistake or the variable is not the type you expected.

Frequently Asked Questions

When does dereferencing work automatically in Rust?

Rust applies automatic deref coercion in many situations. When you call a method, Rust automatically dereferences as many times as needed to find the method. Manual * is only needed in specific situations like comparing references or passing to functions expecting a reference.

What is the Deref trait and how does it work?

The Deref trait lets a type behave like a reference when * is used. Box<T> implements Deref so *my_box gives you a &T. String implements Deref<Target=str> so &my_string automatically becomes &str when needed.

What is the difference between a reference and a raw pointer in Rust?

References (&T) are safe — Rust guarantees they are always valid. Raw pointers (*const T, *mut T) are unsafe — Rust cannot guarantee their validity. Deref on raw pointers requires an unsafe block because Rust cannot verify the pointer is valid.