 /// Describes the code of an error.
 public protocol _ErrorCodeProtocol : Equatable {
   /// The corresponding error code.
-  associatedtype _ErrorType
-
-  // FIXME: We want _ErrorType to be _BridgedStoredNSError and have its
-  // Code match Self, but we cannot express those requirements yet.
-}
-
-extension _ErrorCodeProtocol where Self._ErrorType: _BridgedStoredNSError {
+  associatedtype _ErrorType: _BridgedStoredNSError where _ErrorType.Code == Self
+}
+
+extension _ErrorCodeProtocol {
   /// Allow one to match an error code against an arbitrary error.
   public static func ~=(match: Self, error: Error) -> Bool {
     guard let specificError = error as? Self._ErrorType else { return false }
 
-    // FIXME: Work around IRGen crash when we set Code == Code._ErrorType.Code.
-    let specificCode = specificError.code as! Self
-    return match == specificCode
+    return match == specificError.code
   }
 }
 

}

/// Various helper implementations for _BridgedStoredNSError
public extension _BridgedStoredNSError
    where Code: RawRepresentable, Code.RawValue: SignedInteger {
  // FIXME: Generalize to Integer.
  public var code: Code {
    return Code(rawValue: numericCast(_nsError.code))!
  }

  /// Initialize an error within this domain with the given ``code``
  /// and ``userInfo``.
  public init(_ code: Code, userInfo: [String : Any] = [:]) {
    self.init(_nsError: NSError(domain: Self.errorDomain,
                                code: numericCast(code.rawValue),
                                userInfo: _stringDictToAnyHashableDict(userInfo)))
  }

  /// The user-info dictionary for an error that was bridged from
  /// NSError.
  public var userInfo: [String : Any] { return errorUserInfo }
}

/// Implementation of _ObjectiveCBridgeableError for all _BridgedStoredNSErrors.
public extension _BridgedStoredNSError {
  /// Default implementation of ``init(_bridgedNSError:)`` to provide
  /// bridging from NSError.
  public init?(_bridgedNSError error: NSError) {
    if error.domain != Self.errorDomain {
      return nil
    }

