Re: [PATCH v3 1/5] rust: task: add safe schedule_timeout() wrapper

From: Danilo Krummrich

Date: Tue Nov 17 2026 - 08:14:21 EST


On Tue Nov 17, 2026 at 1:02 PM CET, Gary Guo wrote:
> On Tue Nov 17, 2026 at 11:56 AM GMT, Danilo Krummrich wrote:
>> On Tue Nov 17, 2026 at 12:40 PM CET, Gary Guo wrote:
>>> On Tue Nov 17, 2026 at 12:45 AM GMT, FUJITA Tomonori wrote:
>>>> On Tue, 17 Nov 2026 01:14:42 +0100
>>>> Danilo Krummrich <dakr@xxxxxxxxxx> wrote:
>>>>
>>>>> +pub fn schedule_timeout(timeout: Delta<Jiffy>) -> Delta<Jiffy> {
>>>>> + let timeout = timeout.as_jiffies().max(0);
>>>>
>>>> In earlier reviews of my patches, Gary asked me to use the function
>>>> syntax or clamp() for this instead of the method syntax [1][2]:
>>>>
>>>> let timeout = isize::max(timeout.as_jiffies(), 0);
>>>
>>> Yes, please do. I'm okay with either `isize::max` or `cmp::max`.
>>
>> The examples in [1][2] both seemed to be able to avoid a cast with this, which
>> isn't the case for this patch. There also doesn't seem to be any ambiguity in
>> the extression used in this patch. So I don't see why changing it would be
>> better.
>
> The ambiguity is "the maximum value returned will be 0" and "the minimum value
> returned will be 0". The answer is always the latter but I'd avoid the mental
> gymnastics.

To me clearly both

a.max(b) (1)

max(a, b) (2)

read as the maximum of a and b.

IIUC, what you are saying is that people may read (1) as

a.at_max(b)

which would indeed be equivalent to min(a, b).

If this is indeed commonly the case I'd suggest to raise this to become a common
rule (ideally with a lint), such that we avoid this to be discussed in reviews.

Personally, I prefer (1) for the expression above, but I don't care too much, so
I'm fine to change it. (In case I don't need to respin I'll change it on apply.)

Thanks,
Danilo