From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7C826CCD184 for ; Sat, 11 Oct 2025 10:33:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D35210E15A; Sat, 11 Oct 2025 10:33:14 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="LYDOZqYW"; dkim-atps=neutral Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by gabe.freedesktop.org (Postfix) with ESMTPS id DB8EE10E15A for ; Sat, 11 Oct 2025 10:33:12 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-46e4fa584e7so15660725e9.0 for ; Sat, 11 Oct 2025 03:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760178791; x=1760783591; darn=lists.freedesktop.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=UEMAqpRvkk1CnOEEkWJ/ybbuyMvUoPKtuwUvs4qymvU=; b=LYDOZqYWINKcTlsBYvgSeWqchcm7az0R1nBc2o7/6Nuse8/Qh++4u3Tr8OVH8vEyiX bajqRy8ckEYM8FZN1wCyxLQNjB6+NT0J1xF/L0ruLXh1dScftDQs5DrmIh9qZdeHv48r +Ib/+xEUt2oYFwmHyzsNGyNuVi4GFlbLUXFYggsEvtcu9K3uOyjUseiUAs/E61zMWgv3 2TwznGS8CkZ6Mk/x7jYIJQn6l+5tulqfH6Dok3kQ8aa/WexsCcY2ozjktY24oC6LjXgt HL5j/YxWA1r9KS5nP6SON30j77ET9UaJCtop2W/JNtkG+hcVL6+gpbVuSIIAOjVJWg/n HZ9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760178791; x=1760783591; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UEMAqpRvkk1CnOEEkWJ/ybbuyMvUoPKtuwUvs4qymvU=; b=X3GhFbJ48t+0oNzQA0zYgSB2g4rygAD9XYzxqNEtwZFQyJBTfyN6/QliX6M+pWDv8L 7wj/2zN3gShEvXOwKC+TUTT0VCoCAAQkmrfQJi8JPJ+WurIUUqYhQiOkuXjN+DG8Zg3G IpLcezINkAWhlU3tAsYNYdbsSkwpLOUGQjdTStACRxntNJGubvqdaUwKx7kJwZW3OjIj lX/5BmRau0ubgSJgzBJOITIqLQxqX6Y8fJf0/nJfkZ63Y/zso02p+WbamDzZrG29AfBj fkClRAP+MCocoizml1lzsCe4AgPpNu06OSRJ4C7nIvnyAyYu1IlpZXLFPipXmDYFFxCY 50bQ== X-Forwarded-Encrypted: i=1; AJvYcCVaw2jgU9GXsCZEpjmTv5mznJ5A3PnsWknpZ8rw0vlK+v87zoP6GRROepZRE5HRJvCwz0cDgWBS@lists.freedesktop.org X-Gm-Message-State: AOJu0Yy8459j0y7b+B2tsqcaquAwOCy3yMCYxlnBpOhWfs674IUPedTw 2umgoRzRJaqC81AfZRtm0zd95zr0Go99A8yZaSLQeUkL2/1ktwTFh/J8zG3jNwA7FRIlRJ8NSR3 X+rkzAjLWhdHfjXPteA== X-Google-Smtp-Source: AGHT+IE95szyP/U8+8WhwLLID98VXllUKscYx6ym55wS0AieLc/ikoex6vLfoIyhhX1iRrMI6+QUlbXsF49wksQ= X-Received: from wmcn2.prod.google.com ([2002:a05:600c:c0c2:b0:45f:28dd:87d9]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600d:416b:b0:46e:3dc3:b645 with SMTP id 5b1f17b1804b1-46fa9a87f3emr103546595e9.3.1760178791259; Sat, 11 Oct 2025 03:33:11 -0700 (PDT) Date: Sat, 11 Oct 2025 10:33:10 +0000 In-Reply-To: <20251009-bounded_ints-v2-2-ff3d7fee3ffd@nvidia.com> Mime-Version: 1.0 References: <20251009-bounded_ints-v2-0-ff3d7fee3ffd@nvidia.com> <20251009-bounded_ints-v2-2-ff3d7fee3ffd@nvidia.com> Message-ID: Subject: Re: [PATCH RFC v2 2/3] rust: kernel: add bounded integer types From: Alice Ryhl To: Alexandre Courbot Cc: Danilo Krummrich , Joel Fernandes , Yury Norov , Jesung Yang , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Andreas Hindborg , Trevor Gross , nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="utf-8" X-BeenThere: nouveau@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Nouveau development list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: nouveau-bounces@lists.freedesktop.org Sender: "Nouveau" On Thu, Oct 09, 2025 at 09:37:09PM +0900, Alexandre Courbot wrote: > Add the BoundedInt type, which restricts the number of bits allowed to > be used in a given integer value. This is useful to carry guarantees > when setting bitfields. > > Alongside this type, many `From` and `TryFrom` implementations are > provided to reduce friction when using with regular integer types. Proxy > implementations of common integer traits are also provided. > > Signed-off-by: Alexandre Courbot > + pub const fn enlarge(self) -> BoundedInt > + where > + T: Boundable, > + T: Copy, > + { > + build_assert!(NEW_NUM_BITS >= NUM_BITS); This assertion can be evaluated in const context. const { assert!(NEW_NUM_BITS >= NUM_BITS); } Alice