[dawn][common] Adds nullptr constructor for ResultOrError<Ref<T>, E>.

- Without the explicit constructor, the resolution order selects
  the unique_ptr<Error> constructor over the templated constructor so
  returning nullptr will actually return a Result with neither an error
  nor a result which is never desirable.
- The additional constructor takes precendence for nullptr so instead
  returning nullptr results in returning a null Ref which is a valid
  result.

Change-Id: I4dfb8759e3c7fd7827f17755d2f7cce529968aa5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/247997
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
diff --git a/src/dawn/common/Result.h b/src/dawn/common/Result.h
index b2e6359..2b84497 100644
--- a/src/dawn/common/Result.h
+++ b/src/dawn/common/Result.h
@@ -202,6 +202,7 @@
         requires std::convertible_to<U*, T*>
     Result(const Ref<U>& success);
     Result(std::unique_ptr<E> error);
+    constexpr Result(std::nullptr_t);
 
     template <typename U>
         requires std::convertible_to<U*, T*>
@@ -413,6 +414,9 @@
 
 // Implementation of Result<Ref<T>, E>
 template <typename T, typename E>
+constexpr Result<Ref<T>, E>::Result(std::nullptr_t) : Result(Ref<T>(nullptr)) {}
+
+template <typename T, typename E>
 template <typename U>
     requires std::convertible_to<U*, T*>
 Result<Ref<T>, E>::Result(Ref<U>&& success)
diff --git a/src/dawn/native/Buffer.cpp b/src/dawn/native/Buffer.cpp
index ebbd3ab..0f4ee02 100644
--- a/src/dawn/native/Buffer.cpp
+++ b/src/dawn/native/Buffer.cpp
@@ -744,7 +744,7 @@
 
     // If the buffer is already destroyed, we don't need to do anything.
     if (state == BufferState::Destroyed) {
-        return Ref<MapAsyncEvent>(nullptr);
+        return nullptr;
     }
 
     // For pending maps, set the pending event statuses, and return it. The caller is responsible
@@ -760,7 +760,7 @@
     }
 
     DAWN_TRY(Unmap());
-    return Ref<MapAsyncEvent>(nullptr);
+    return nullptr;
 }
 
 MaybeError BufferBase::ValidateMapAsync(wgpu::MapMode mode,