Closed Bug 1661476 Opened 4 years ago Closed 4 years ago

Prevent Result<const V, E> or Result<V, const E> from being instantiated

Categories

(Core :: MFBT, task)

task

Tracking

()

RESOLVED FIXED
82 Branch
Tracking Status
firefox82 --- fixed

People

(Reporter: sg, Assigned: sg)

References

Details

Attachments

(1 file)

Result<const V, E> is not meaningful to express that the success value must not be changed within a Result, because Result provides this guarantee anyway. OTOH, when unwrapping the value, const has no effect, it is still possible to unwrap into a non-const V.

However, Result<const V, E> has the negative side-effect of preventing moving instances of that type. To prevent this, and to avoid confusion on the effect of const V, this should be prevented via a static_assert.

Also, documentation should be extended to make the non-modifiability of the success value clear(er) to developers using and evolving Result.

Note that Result<const V*, E> remains possible and useful, just Result<const V* const, E> will no longer be possible.

Summary: Prevent Result<const V, E> from being instantiated → Prevent Result<const V, E> or Result<V, const E> from being instantiated

Same goes for const E.

Also, remove the existing uses of Result<const nsCString, nsresult> in URLPreloader
and Result<CryptoScheme, const nsCString> in SampleIterator.

Pushed by sgiesecke@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/52ef06111f20
Prevent Result<const V, E> or Result<V, const E> from being instantiated. r=froydnj
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 82 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: