Re: [PATCH v6] rust: kernel: add support for bits/genmask macros
From: Alexandre Courbot
Date: Mon Jun 16 2025 - 11:03:30 EST
On Mon Jun 16, 2025 at 11:56 PM JST, Daniel Almeida wrote:
> Hi Alex,
>
>> On 16 Jun 2025, at 11:52, Alexandre Courbot <acourbot@xxxxxxxxxx> wrote:
>>
>> On Mon Jun 16, 2025 at 11:45 PM JST, Daniel Almeida wrote:
>>>
>>>
>>>> On 16 Jun 2025, at 11:42, Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx> wrote:
>>>>
>>>> Hi Boqun,
>>>>
>>>>>
>>>>> We should tell/educate people to do the right thing, if a..b is not
>>>>> inclusive in Rust, then we should treat them as non-inclusive in Rust
>>>>> kernel code. Otherwise you create confusion for no reason. My assumption
>>>>> is that most people will ask "what's the right way to do this" first
>>>>> instead of replicating the old way.
>>>>>
>>>>> Regards,
>>>>> Boqun
>>>>>
>>>>
>>>> This is just my opinion, of course:
>>>>
>>>> I _hardly_ believe this will be the case. When people see genmask and two
>>>> numbers, they expect the range to be inclusive, full stop (at least IMHO). That's how it has
>>>> worked for decades, so it’s only natural to expect this behavior to transfer over.
>>>>
>>>> However, I do understand and agree with your point, and I will change the
>>>> implementation here to comply. Perhaps we can use some markdown to alert users?
>>>>
>>>> — Daniel
>>>
>>> Or better yet, perhaps we should only support a..=b.
>>
>> ... or just drop the ranges and do as Daniel initially did, using two
>> arguments. But I agree with Boqun that we should not deviate from the
>> official interpretation of ranges if we use them - the fact that `Range`
>> is exclusive on its upper bound is documented and a property of the type
>> itself.
>
> By the same token, I agree that we should use ranges instead of two arguments,
> if said two arguments represent a range anyways. So my vote is for a..=b JFYI.
That works for me, it has the benefit of being absolutely clear that the
range is inclusive.