Rust

E0200 Unsafe Trait Impl Needs Unsafe Fix

E0200 is the missing-keyword error with a real obligation behind it: a trait declared unsafe trait may only be implemented with unsafe impl, because the trait carries invariants the compiler cannot check and the implementer is promising to uphold them. The fix the compiler offers - add one word - is mechanically trivial, and this guide shows it working on an empty trait, on traits with default methods and associated items, on generic and blanket implementations, and on a manual Send implementation. It also shows the shapes that change nothing: an empty implementation body still fails, an implementation in another module still fails, and the keyword in the wrong place - unsafe impl of a trait that is not unsafe - is a different error, E0199, whose repair is to remove the word instead.

Written December 1, 2026 · Tested with Rust 1.99.0 · 17 min read

By the end of this guide
  • The rule underneath: the implementation repeats the trait's unsafe
  • How to read the diagnostic
  • The first failure: the index example
  • The body does not matter: default methods and associated items

Written December 1, 2026

Tested with Rust 1.99.0

What this guide is

Error E0200 is about one keyword in one place. The error codes index opens: "An unsafe trait was implemented without an unsafe implementation." Its erroneous example is three lines - a struct, an unsafe trait, and a plain impl of that trait for the struct - and its repair is to mark the implementation unsafe. Nothing else in the program is wrong: the types match, the items match, and the body can be empty. The implementation is rejected because it does not repeat the trait's unsafe.

The practical payoff is knowing when the word is owed and when it is not. The keyword belongs on the implementation exactly when the trait declaration carries it - no more, no less. Adding it where the trait is safe is its own error, E0199, covered below. And the obligation is separate from calling unsafe code: an unsafe operation performed outside an unsafe block is E0133, a different code about expressions, where E0200 is about the impl item itself.

Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line.

The rule underneath: the implementation repeats the trait's unsafe

The Rust Reference's traits page states what the keyword on a trait means: "Traits items that begin with the unsafe keyword indicate that implementing the trait may be unsafe. It is safe to use a correctly implemented unsafe trait. The trait implementation must also begin with the unsafe keyword." The implementations page states the same requirement from the other side: "Unsafe traits require the trait implementation to begin with the unsafe keyword."

Read the middle sentence of the traits passage carefully, because it is the point of the design. Using a correctly implemented unsafe trait is safe - callers write ordinary safe code against it. The unsafety is concentrated at the implementation, where the implementer takes on invariants the compiler cannot verify. That is why the compiler insists the promise be written out: unsafe impl is the implementer signing for those invariants, and E0200 is the compiler refusing an unsigned implementation. The standard library's marker traits are the familiar case - the Reference names Send and Sync as examples of unsafe traits, and a manual implementation of either one follows the rule below.

How to read the diagnostic

In the probed set, an E0200 failure is a single error. The header names the trait: "the trait Bar requires an unsafe impl declaration". The span underlines the whole impl line - not a method, not a body item, the implementation header itself. Under the span sit a note and a help. The note states the reason: "the trait Bar enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the unsafe keyword". The help then performs the repair: "add unsafe to this trait implementation", rewriting the underlined line with the keyword inserted.

The order of those two parts is the guidance. The help is mechanical and always available; the note is the actual work - read the trait's documented invariants first, check that this implementation upholds them, and only then take the help. Adding the keyword to silence the error, without the check the note asks for, compiles - and leaves the promise the keyword makes unexamined.

The first failure: the index example

The smallest shape is the error index's own: an empty unsafe trait, a struct, and a plain implementation with an empty body:

Rust
struct Foo;
unsafe trait Bar { }
impl Bar for Foo { }
fn main() { println!("ok"); }
Output
error[E0200]: the trait `Bar` requires an `unsafe impl` declaration
 --> basic.rs:3:1
  |
3 | impl Bar for Foo { }
  | ^^^^^^^^^^^^^^^^
  |
  = note: the trait `Bar` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
help: add `unsafe` to this trait implementation
  |
3 | unsafe impl Bar for Foo { }
  | ++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0200`.

The whole implementation line is underlined, and the note and help follow it. Nothing in the body is at fault - the body is empty - and nothing about the struct is at fault. The single defect is the missing keyword on the impl, which is why the span covers exactly that line and nothing else.

The body does not matter: default methods and associated items

A first guess is that the error has something to do with what the implementation must provide. It does not. An unsafe trait whose only item is a method with a default body needs nothing from an implementation at all - the implementation below is again empty - and it fails with the same code and the same header:

Rust
struct Foo;
unsafe trait Bar {
    fn greet(&self) -> String { String::from("hi") }
}
impl Bar for Foo { }
fn main() {
    let f = Foo;
    println!("{}", f.greet());
}
Output
error[E0200]: the trait `Bar` requires an `unsafe impl` declaration
 --> defaultmethod.rs:5:1
  |
5 | impl Bar for Foo { }
  | ^^^^^^^^^^^^^^^^
  |
  = note: the trait `Bar` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
help: add `unsafe` to this trait implementation
  |
5 | unsafe impl Bar for Foo { }
  | ++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0200`.

The other end of the scale fails identically. This unsafe trait has an associated type, an associated constant, and a required method, and the implementation supplies all three, with the right types and values:

Rust
struct Foo;
unsafe trait Bar {
    type Item;
    const MAX: u32;
    fn item(&self) -> Self::Item;
}
impl Bar for Foo {
    type Item = u32;
    const MAX: u32 = 10;
    fn item(&self) -> u32 { 3 }
}
fn main() {
    let f = Foo;
    println!("{} {}", f.item(), Foo::MAX);
}
Output
error[E0200]: the trait `Bar` requires an `unsafe impl` declaration
 --> assoc.rs:7:1
  |
7 | impl Bar for Foo {
  | ^^^^^^^^^^^^^^^^
  |
  = note: the trait `Bar` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
help: add `unsafe` to this trait implementation
  |
7 | unsafe impl Bar for Foo {
  | ++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0200`.

Every item the trait demands is present and correct, and the error is unchanged: same code, same header naming the trait, same underlined impl line, same note and help. What an implementation provides - nothing, defaults, or the full set of associated items - plays no part in E0200. The check is on the implementation header alone, against the trait declaration alone.

The shape does not matter: generic, blanket, and cross-module implementations

The implementation's form does not change the answer either. A generic implementation, with the keyword missing, fails the same way:

Rust
struct Wrapper<T> { value: T }
unsafe trait Bar { }
impl<T> Bar for Wrapper<T> { }
fn main() { println!("ok"); }
Output
error[E0200]: the trait `Bar` requires an `unsafe impl` declaration
 --> generic.rs:3:1
  |
3 | impl<T> Bar for Wrapper<T> { }
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: the trait `Bar` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
help: add `unsafe` to this trait implementation
  |
3 | unsafe impl<T> Bar for Wrapper<T> { }
  | ++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0200`.

A blanket implementation - one impl for every Vec<T> - fails the same way:

Rust
unsafe trait Bar { }
impl<T> Bar for Vec<T> { }
fn main() { println!("ok"); }
Output
error[E0200]: the trait `Bar` requires an `unsafe impl` declaration
 --> blanket.rs:2:1
  |
2 | impl<T> Bar for Vec<T> { }
  | ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: the trait `Bar` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
help: add `unsafe` to this trait implementation
  |
2 | unsafe impl<T> Bar for Vec<T> { }
  | ++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0200`.

And moving the implementation away from the trait and the type changes nothing. Here the trait is declared at the top level, the struct lives in a public module, and the implementation stands outside that module:

Rust
unsafe trait Bar { }
pub mod inner {
    pub struct Foo;
}
impl Bar for inner::Foo { }
fn main() { println!("ok"); }
Output
error[E0200]: the trait `Bar` requires an `unsafe impl` declaration
 --> othermod.rs:5:1
  |
5 | impl Bar for inner::Foo { }
  | ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: the trait `Bar` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
help: add `unsafe` to this trait implementation
  |
5 | unsafe impl Bar for inner::Foo { }
  | ++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0200`.

Same code, same header, same repair offered. There is no scope in which a plain impl of an unsafe trait is accepted, in the probed set: not the defining module, not another module, not a generic or blanket form. The keyword is a property of the implementation item itself, checked wherever the item is written.

The standard-library case: a manual Send implementation

The unsafe trait most Rust code meets is not one it declares. Send is an unsafe trait, so a manual implementation of it for a type the compiler will not auto-derive it for - here a struct holding a raw pointer - hits the same error, with the header naming Send:

Rust
struct Holder { ptr: *const u8 }
impl Send for Holder { }
fn main() { println!("ok"); }
Output
error[E0200]: the trait `Send` requires an `unsafe impl` declaration
 --> sendplain.rs:2:1
  |
2 | impl Send for Holder { }
  | ^^^^^^^^^^^^^^^^^^^^
  |
  = note: the trait `Send` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
help: add `unsafe` to this trait implementation
  |
2 | unsafe impl Send for Holder { }
  | ++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0200`.

The note and help are the same, with Send in the trait's place. This is the shape in which E0200 usually arrives in real code: not a toy trait in the same file, but a marker trait whose invariants - this type really may be transferred to another thread - the implementer has to stand behind personally. The repair is the same one word, and the note's instruction matters most here: review what Send promises before signing for it.

The repair, and the controls

Adding unsafe to the implementation is the whole repair. The first failure, with a required method added so the result is observable, compiles and runs:

Rust
struct Foo;
unsafe trait Bar {
    fn value(&self) -> i32;
}
unsafe impl Bar for Foo {
    fn value(&self) -> i32 { 42 }
}
fn main() {
    let f = Foo;
    println!("{}", f.value());
}
Output
42

The output is 42, the value the method returns. Calling the method is ordinary safe code - the Reference's "it is safe to use a correctly implemented unsafe trait" in action. The unsafety was discharged once, at the impl, by the keyword.

The same repair closes every failing shape above. The default-method trait, implemented with unsafe impl and an empty body, compiles and runs - the default body is what executes:

Rust
struct Foo;
unsafe trait Bar {
    fn greet(&self) -> String { String::from("hi") }
}
unsafe impl Bar for Foo { }
fn main() {
    let f = Foo;
    println!("{}", f.greet());
}
Output
hi

The output is hi, the default method's string. The associated-items trait, with the keyword added, compiles and runs:

Rust
struct Foo;
unsafe trait Bar {
    type Item;
    const MAX: u32;
    fn item(&self) -> Self::Item;
}
unsafe impl Bar for Foo {
    type Item = u32;
    const MAX: u32 = 10;
    fn item(&self) -> u32 { 3 }
}
fn main() {
    let f = Foo;
    println!("{} {}", f.item(), <Foo as Bar>::MAX);
}
Output
3 10

The output is 3 10 - the method's return value and the associated constant. The generic implementation, with the keyword added, compiles and runs:

Rust
struct Wrapper<T> { value: T }
unsafe trait Bar {
    fn tag(&self) -> &'static str { "wrapped" }
}
unsafe impl<T> Bar for Wrapper<T> { }
fn main() {
    let w = Wrapper { value: 5 };
    println!("{} {}", w.tag(), w.value);
}
Output
wrapped 5

The output is wrapped 5 - the default method's label and the wrapped value. And the manual Send implementation, with the keyword added, compiles and runs:

Rust
struct Holder { ptr: *const u8 }
unsafe impl Send for Holder { }
fn main() {
    let h = Holder { ptr: std::ptr::null() };
    println!("{}", h.ptr.is_null());
}
Output
true

The output is true - the stored pointer is null, as constructed. In each pair, the repair itself is the single keyword on the impl line, exactly the edit the diagnostic's help proposes; where a running version prints a value, the trait or main also carries the smallest body needed to produce it.

One control bounds the rule from the other side. A trait declared without unsafe, implemented without unsafe, compiles and runs:

Rust
struct Foo;
trait Bar {
    fn value(&self) -> i32;
}
impl Bar for Foo {
    fn value(&self) -> i32 { 7 }
}
fn main() {
    let f = Foo;
    println!("{}", f.value());
}
Output
7

The output is 7, the method's value. A safe trait asks for no promise, so its implementations carry no keyword. The pairing is exact: in the probed set, unsafe on the trait and unsafe on the implementation appear together or not at all.

The trap: the keyword on the wrong trait is E0199

Trap
Because the repair is one word, the tempting shortcut is to write unsafe impl liberally - or to leave it in place after a trait stops being unsafe. That direction fails too, with the mirror error. Here the trait is safe and the implementation is marked unsafe:
Rust
struct Foo;
trait Bar { }
unsafe impl Bar for Foo { }
fn main() { println!("ok"); }
Output
error[E0199]: implementing the trait `Bar` is not unsafe
 --> safeunsafe.rs:3:1
  |
3 | unsafe impl Bar for Foo { }
  | ^^^^^^^^^^^^^^^^^^^^^^^
  |
help: remove `unsafe` from this trait implementation
  |
3 - unsafe impl Bar for Foo { }
3 + impl Bar for Foo { }
  |

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0199`.

The code is E0199, not E0200: "implementing the trait Bar is not unsafe". The span again underlines the whole implementation line, and the help is the exact reverse of E0200's - "remove unsafe from this trait implementation", striking the keyword out. The error index's E0199 page states the rule plainly: "A trait implementation was marked as unsafe while the trait is safe."

The pair of codes is a matched set, and together they pin the keyword down. E0200: the trait is unsafe and the implementation is not - add the word. E0199: the trait is safe and the implementation is marked unsafe - remove the word. When one of them fires, do not guess which side is wrong. Read the trait declaration: the declaration is the source of truth, and the implementation is the side that moves - unless the declaration itself is what changed, which is the last fix below.

Fixes in reach order

First, when the implementation genuinely upholds the trait's invariants, add unsafe to the implementation - the diagnostic's own help, and the repair every failing shape above took. Do the note's work before the help's edit: read the trait's documentation for the invariants it enforces, check this implementation against each one, and add the keyword as the record of that check, not as a substitute for it.

Second, for a standard-library marker trait such as Send or Sync, the same fix applies and the same caution doubles. The implementation compiles the moment the keyword lands, but the promise is about thread behavior the compiler cannot check. If the type is not in fact safe to transfer or share, the correct outcome is not a quieter error - it is no manual implementation at all, and a design that lets the compiler derive the marker or rules the sharing out.

Third, when the trait is yours and the declaration is the side that is wrong, fix the declaration instead. If a trait you control carries unsafe but imposes no invariants an implementer must uphold, removing unsafe from the trait declaration turns it into the control shape above - a safe trait with plain implementations, which compiles. Every existing implementation of it must drop its own unsafe in the same change, or those implementations become the E0199 trap. Conversely, if implementations in the wild are failing E0200 against your trait, that is the declaration working as designed: the keyword on the trait is what forces each implementer to sign.

Last, match the repair to the code. An E0199 diagnostic is repaired by removing the keyword from the implementation (or by making the trait genuinely unsafe, if that is the intent) - never by adding anything. An E0200 diagnostic is never repaired by touching the trait's items, the implementation's body, or the module layout: in the probed set, none of those participated in the error.

Decision summary

E0200, in this guide's probed set, fired exactly when an implementation of an unsafe trait was written without unsafe on the impl: an empty implementation of an empty trait, an implementation of a trait with only a default method, a complete implementation of a trait with an associated type, constant, and method, a generic implementation, a blanket implementation, an implementation written outside the type's module, and a manual Send implementation. Adding unsafe to the implementation made every one of those shapes compile and run, with no other change. The error did not fire for a safe trait with a plain implementation, and the reverse mismatch - a safe trait with an unsafe impl - was not E0200 but E0199, repaired by removing the keyword. The trait declaration alone decides which keyword the implementation must carry.

Checklist

  • Read the header first: in the probed set, E0200 names the trait that requires the unsafe impl, and the span underlines the whole implementation line - the defect is in the header, never in the body or the items supplied.
  • Do the note's work before the help's edit: the diagnostic itself instructs reviewing the trait's invariants and confirming this implementation upholds them before adding the unsafe keyword.
  • Do not chase shape changes: in the probed set, empty bodies, default methods, associated items, generic and blanket forms, and implementations in other modules all failed identically - none of them is the lever.
  • Expect this error from the standard library, not only from your own traits: a manual Send implementation without unsafe is E0200, and its repair carries a thread-safety promise the compiler cannot check.
  • Keep the pair straight: unsafe trait with a plain implementation is E0200 (add the keyword); safe trait with an unsafe impl is E0199 (remove it). The trait declaration is the source of truth for which side moves.
  • If the trait is yours, the declaration is editable: dropping an unneeded unsafe from it makes plain implementations correct - and every existing unsafe impl of it must drop the keyword in the same change, or it becomes E0199.

Sources

  • Rust error codes index, E0200 - an unsafe trait was implemented without an unsafe implementation; the erroneous example impl Bar for Foo against unsafe trait Bar, and the repair: unsafe traits must have unsafe implementations, resolved by marking the implementation as unsafe.
  • Rust error codes index, E0199 - the mirror code: a trait implementation was marked as unsafe while the trait is safe; safe traits should not have unsafe implementations, and removing the unsafe marker on the implementation resolves it.
  • The Rust Reference, Traits - trait items that begin with the unsafe keyword indicate that implementing the trait may be unsafe; it is safe to use a correctly implemented unsafe trait; the trait implementation must also begin with the unsafe keyword; Send and Sync are named as examples of unsafe traits.
  • The Rust Reference, Implementations - unsafe traits require the trait implementation to begin with the unsafe keyword.

Keep Exploring