mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1666416 - Allow conversion from Result with convertible error type. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D90960
This commit is contained in:
parent
ee5a559a7d
commit
8804eb9be3
@ -489,6 +489,15 @@ class MOZ_MUST_USE_TYPE Result final {
|
||||
MOZ_ASSERT(isErr());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a (success/error) result from another (success/error) result with a
|
||||
* different but convertible error type. */
|
||||
template <typename E2,
|
||||
typename = std::enable_if_t<std::is_convertible_v<E2, E>>>
|
||||
MOZ_IMPLICIT Result(Result<V, E2>&& aOther)
|
||||
: mImpl(aOther.isOk() ? Impl{aOther.unwrap()}
|
||||
: Impl{aOther.unwrapErr()}) {}
|
||||
|
||||
/**
|
||||
* Implementation detail of MOZ_TRY().
|
||||
* Create an error result from another error result.
|
||||
|
@ -268,6 +268,16 @@ static Result<Ok, Failed*> ErrorGeneralization() {
|
||||
|
||||
static void TypeConversionTests() {
|
||||
MOZ_RELEASE_ASSERT(ErrorGeneralization().isErr());
|
||||
|
||||
{
|
||||
const Result<Ok, Failed*> res = Explode();
|
||||
MOZ_RELEASE_ASSERT(res.isErr());
|
||||
}
|
||||
|
||||
{
|
||||
const Result<Ok, Failed*> res = Result<Ok, Snafu*>{Ok{}};
|
||||
MOZ_RELEASE_ASSERT(res.isOk());
|
||||
}
|
||||
}
|
||||
|
||||
static void EmptyValueTest() {
|
||||
|
Loading…
Reference in New Issue
Block a user