   }
 }
 
-@objc public enum _NSCocoaError : Int, _ObjectiveCBridgeableErrorType {
+/// Helper protocol for _BridgedNSError, which used used to provide
+/// default implementations.
+public protocol __BridgedNSError : RawRepresentable {
+  static var _NSErrorDomain: String { get }
+}
+
+public extension __BridgedNSError where RawValue == Int {
+  public final var _domain: String { return Self._NSErrorDomain }
+  public final var _code: Int { return rawValue }
+
+  public init?(rawValue: Int) {
+    self = unsafeBitCast(rawValue, Self.self)
+  }
+
+  public init?(_bridgedNSError: NSError) {
+    if _bridgedNSError.domain != Self._NSErrorDomain {
+      return nil
+    }
+
+    if let result = Self(rawValue: _bridgedNSError.code) {
+      self = result
+    } else {
+      return nil
+    }
+  }
+}
+
+/// Describes a raw representable type that is bridged to a particular
+/// NSError domain.
+///
+/// This protocol is used primarily to generate the conformance to
+/// _ObjectiveCBridgeableErrorType for such an enum.
+public protocol _BridgedNSError : __BridgedNSError,
+                                  _ObjectiveCBridgeableErrorType {
+  /// The NSError domain to which this type is bridged.
+  static var _NSErrorDomain: String { get }
+}
+
+/// Enumeration that describes the error codes within the Cocoa error
+/// domain.
+@objc public enum _NSCocoaError : Int, _BridgedNSError {
   // Foundation errors
   case FileNoSuchFileError = 4
   case FileLockingError = 255

  @available(OSX, introduced=10.10) @available(iOS, introduced=8.0)
  case BackgroundSessionWasDisconnected = -997

  public var _domain: String { return NSURLErrorDomain }
  public var _code: Int { return rawValue }

  public init?(rawValue: Int) {
    self = unsafeBitCast(rawValue, _NSURLError.self)
  }

  public init?(_bridgedNSError: NSError) {
    if _bridgedNSError.domain != NSURLErrorDomain {
      return nil
    }

    if let result = _NSURLError(rawValue: _bridgedNSError.code) {
      self = result
    } else {
      return nil
    }
  }
}

  }
#endif

  public static var _NSErrorDomain: String { return NSCocoaErrorDomain }
}

/// Enumeration that describes the error codes within the NSURL error
/// domain.
@objc public enum _NSURLError : Int, _BridgedNSError {
  case Unknown = -1
  case Cancelled = -999
  case BadURL = -1000
