swc-project/swc · error

UnsafeId.into_id() is not allowed because it is very likely

Error message

UnsafeId.into_id() is not allowed because it is very likely to be unsafe

What it means

A deliberate guard in the IdentLike impl for UnsafeId (swc_ecma_utils ident.rs:83). UnsafeId is an identifier wrapper constructed via unsafe code that skips hygiene/symbol interning guarantees; converting it back into an Id would launder an unsound identifier into safe APIs, which is 'very likely to be unsafe'. The unreachable!() therefore fires whenever code attempts into_id() on an UnsafeId, marking that call path a programming error.

Source

Thrown at crates/swc_ecma_utils/src/ident.rs:83

    }

    #[inline]
    fn into_id(self) -> Id {
        (self.sym, self.ctxt)
    }
}

impl IdentLike for UnsafeId {
    fn from_ident(i: &Ident) -> Self {
        unsafe { unsafe_id_from_ident(i) }
    }

    fn to_id(&self) -> Id {
        unreachable!("UnsafeId.to_id() is not allowed because it is very likely to be unsafe")
    }

    fn into_id(self) -> Id {
        unreachable!("UnsafeId.into_id() is not allowed because it is very likely to be unsafe")
    }
}

View on GitHub (pinned to 5176682b65)

Solutions

  1. Do not call into_id()/to_id() on UnsafeId; keep UnsafeId confined to the unsafe fast paths that created it
  2. Convert through a safe Ident (via from_ident on a validated ident) if an Id is genuinely required
  3. Audit the call site that reaches into_id and switch it to a safe IdentLike implementation
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_ecma_utils/src/ident.rs:83 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/ec7917cb3fd46e9d. Report an issue: GitHub.