From nobody Sat Nov 15 22:25:04 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1746181461; cv=none; d=zohomail.com; s=zohoarc; b=CBX3zmZTLhRk1UoLkx4Wu5OBF0KPXLRYtqv1YgL2eZg6HsRaJYqdLV+8DKMG0k7JmYPUFwlgLRyiX8JYRldfGYIpIxeme/Di20cbm4XVLhNDZQ9HTQDYglO4vcwjU1HPiU/6I81cAAmUN3Lnnojgn2vaJKlgfmzMyluSnwxKouo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746181461; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GgDIE30XzoIywzR02KFIEjUl2Fse4v4IpzEPr0mViA8=; b=h+kVvx+kkNbucXbhpSSUHNahapFgrehHYm9mxJ+85xdr5GWvoNsRRfs2MbjiUmUUozMniVRnCyayvQcGEUA/CtWQWyV3aE05hSdwIZUqufZGaeUg4rDPQduaBB7sYevb18SuhRfOmGEzVmF/arPygz7BCLlB96sE2zt5vi3CEw0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1746181461889901.410051470429; Fri, 2 May 2025 03:24:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uAnYQ-0001Au-SL; Fri, 02 May 2025 06:23:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYM-00019R-V2 for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYK-0000ei-Pa for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:34 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-185-_sS6UGewOpy-ewFtK0RLCQ-1; Fri, 02 May 2025 06:23:30 -0400 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-39131851046so391379f8f.0 for ; Fri, 02 May 2025 03:23:30 -0700 (PDT) Received: from [192.168.10.48] ([151.95.54.106]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-441b89cc50esm40864275e9.8.2025.05.02.03.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 03:23:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746181411; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GgDIE30XzoIywzR02KFIEjUl2Fse4v4IpzEPr0mViA8=; b=I4QWKjFOUQdXa2xNqwy8ynwHj0PJyTObTcHuH4T0wd6sb/eIwEQEHfscB0RCsYx6lc46ra XU/MYoBn1HXKh1ZZ1V40rKzg0RTBuyDTURN63KW34wjfBlZ+TbgU9thzt6yfkTr0JuLAuR wR8dfGzEf+ARkz7BRHORv6DJjTwU72U= X-MC-Unique: _sS6UGewOpy-ewFtK0RLCQ-1 X-Mimecast-MFC-AGG-ID: _sS6UGewOpy-ewFtK0RLCQ_1746181409 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746181408; x=1746786208; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GgDIE30XzoIywzR02KFIEjUl2Fse4v4IpzEPr0mViA8=; b=fXOvRvWdJOypTDTjM1qgEZQrUok7XWfNPqECGfY+FKDVWn9RAWl4sQlRf9NMFoHGV2 g4T6aQOyK50wHFZDEeMOeZz+tmNZmhj/ajhcV+I5bB/KGDUoDRiO6AlGjJzOTkZUjoFh kTR4VC0eR0dLCwm70iQXWinus2ZkeDw0PsR5+Hm+rpwQeZGuZmBKouxK7TLOHjl65Trs wXDPH06GTZu4/txhPJdQC+GDnrA4AFn7h1hCFYRRsy8z4tSP5UHLtYoj2KV8ExPVGK+L 2omwKzZqQlLDpyBdEbopc1I2lp4nv+CYeOZj+0eKZRisZbartlwlEKTygBG2iWRKG6Ot iiKg== X-Gm-Message-State: AOJu0Yxjp2A9BzN5NRmpcjBfCtZ3Py+BlSeIpwAZJgQ2fkeleFN0WnK+ r12wK/XDl4A5qxN8lt5CAlvln3HXl01G/0dJKDchRxMBn4iEPkR12SFOrUZxifJ2RFTftS7l7ne 9WknyQe0sqXVSsZH0JlZLWLRbiBJcgWtnFXPVCu1buso+Q2B3GGfNuxc/S69z1XKuLAxke3p8L8 ia0HACQ/+EW3XUSPlp2n79tftfylV8O1VoRLgF X-Gm-Gg: ASbGnctOlEiWiuksAT8n+ltwwtgM9+TFoe1ptWgDOwVZ1Jg4HiN5WDxcCC1WN7f1yqZ 4Kzi7nW1yDkHiYFUB9dVBC+rohDBzGNHg6HpnVz1csxCR8ha4ExRT0z031V8cR891MVhm4O6psa g+925bBdMhG3a59iUvqHGzOcENce6Ms4eqH5S8IarQTkmTqAUvQI3erIJUxgBeqi+Z00VtRuen2 xcEhdflLgQ6JWY+YfEy7UkZniLare8TN3DI327J2dUWjXmwrqJ+Bbp5RuLQ7RJ4h9JVUGy3noeo cZWZjk94PMpBbTA= X-Received: by 2002:a05:6000:1a86:b0:39c:310a:f87e with SMTP id ffacd0b85a97d-3a099ad62acmr1819909f8f.16.1746181408370; Fri, 02 May 2025 03:23:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRzgtNEvTxvR9D0XSIaBpOuNpnosvpK5i9hJCbLJIrxsVq0m/jTT14S6CDisuK+/vtV8Q4gQ== X-Received: by 2002:a05:6000:1a86:b0:39c:310a:f87e with SMTP id ffacd0b85a97d-3a099ad62acmr1819889f8f.16.1746181407961; Fri, 02 May 2025 03:23:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 1/9] lcitool: use Rust 1.78 for Debian bookworm Date: Fri, 2 May 2025 12:23:14 +0200 Message-ID: <20250502102323.104815-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502102323.104815-1-pbonzini@redhat.com> References: <20250502102323.104815-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.644, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1746181463926019100 Content-Type: text/plain; charset="utf-8" The rustc-web package provides a newer Rust compiler (1.78) on all architectures except mips64el. Signed-off-by: Paolo Bonzini --- docs/about/build-platforms.rst | 7 ++++--- tests/lcitool/mappings.yml | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/about/build-platforms.rst b/docs/about/build-platforms.rst index 52521552c8a..bfcbb431f10 100644 --- a/docs/about/build-platforms.rst +++ b/docs/about/build-platforms.rst @@ -118,9 +118,10 @@ Rust build dependencies include bindgen or have an older version, it is recommended to install a newer version using ``cargo install bindgen-cli``. =20 - Developers may want to use Cargo-based tools in the QEMU source tree; - this requires Cargo 1.74.0. Note that Cargo is not required in order - to build QEMU. + QEMU requires Rust 1.77.0. This is available on all supported platforms + with one exception, namely the ``mips64el`` architecture on Debian bookw= orm. + For all other architectures, Debian bookworm provides a new-enough Rust + compiler in the ``rustc-web`` package. =20 Optional build dependencies Build components whose absence does not affect the ability to build QEMU diff --git a/tests/lcitool/mappings.yml b/tests/lcitool/mappings.yml index 74eb13d62b6..2ac304b72ff 100644 --- a/tests/lcitool/mappings.yml +++ b/tests/lcitool/mappings.yml @@ -64,6 +64,9 @@ mappings: python3-wheel: OpenSUSELeap15: python311-pip =20 + rust: + Debian12: rustc-web + pypi_mappings: # Request more recent version meson: --=20 2.49.0 From nobody Sat Nov 15 22:25:04 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1746181477; cv=none; d=zohomail.com; s=zohoarc; b=HdrXFDoZZ2qRsn9+WbJTqs+ZXIPZa0MjDmlbQ89uyqMrZds2IDKmHFNmsNTExAHzETtCATvDmxb9Qk+l0QZlszbU1kSi+keXt9LgT9HZkhlRm3Gg6193ppNCtFEa5V8ys6KU01Ku75i+5dvGT9kWh9mZDy6C2Kvf/9lj7ejEcyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746181477; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gzvCV0jIjpCcgfBWJ62IvsDo2orChe3xqe3a6DGJy7Q=; b=OhtifPs7o/nYealnbQX2/yJO9SLTwI8E6K79Jnai1eQzsJzmktv1NnZTNZntOnSQ8YQ5n0f1r480MspUR4Ie1sNJlxpaLgkANvmLqyyOGh2K98fvnwmoCuiHwt0SAw8md4yZkwADX8S1fb8deKbywFIYhT21fP30EO2XL0i/Iu4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1746181477912952.4972455602492; Fri, 2 May 2025 03:24:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uAnYS-0001Bv-KP; Fri, 02 May 2025 06:23:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYO-0001A6-QY for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYM-0000fC-Ri for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:36 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-329-VG3DELg8NKiZqJZKzwNkHQ-1; Fri, 02 May 2025 06:23:32 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-39c2da64df9so845256f8f.0 for ; Fri, 02 May 2025 03:23:32 -0700 (PDT) Received: from [192.168.10.48] ([151.95.54.106]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a099ae82e4sm1769656f8f.58.2025.05.02.03.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 03:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746181413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gzvCV0jIjpCcgfBWJ62IvsDo2orChe3xqe3a6DGJy7Q=; b=QEL5c3eOXABg4o638zlutmI4UjDPl0pHSvpsBr/kWcq4PBg4Tpt07cPppGnq7uyhVzebkZ WT1HrW0AA1G4uDVIcaVw3tOsi+x5jVWzq6LlOfKySCbI6ar7HN+vOXMUlvuxY7yis/knPe dGwJZGv4PD5sR6LJL5e25NLl/YmQ8xo= X-MC-Unique: VG3DELg8NKiZqJZKzwNkHQ-1 X-Mimecast-MFC-AGG-ID: VG3DELg8NKiZqJZKzwNkHQ_1746181411 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746181410; x=1746786210; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gzvCV0jIjpCcgfBWJ62IvsDo2orChe3xqe3a6DGJy7Q=; b=QeieTR7KGbJ5A9rRfT1BOKNjbwgf5tUDNaRUM2pc/dGNKM2UhdciKPJyY8lv+5NCa9 UTpF0C0C4AuI6PC6d6ydZwJVDDzfg033CFnpyJjcYujb3mR1uVIG8g2YXsYDt51gAsDo ys5og57+oKhkvAIbcgMzWKrFLSpl9xOkrwg7y15o4GjN6q3JxRqpMKY3NMiQkYh5uTqB Q1Kwys7AO0xL/z08OPhj3YQ1Hw0aGSCWGisLq822iwCqkXGPGblcecNFbG3P85/wEFCL LmnBpE8iwyeIPaAsuT5ILBYJi0m+M8moP2jVLbbvysVaQ30pplbh6+MfrnxDwGakO3Ya 6xBw== X-Gm-Message-State: AOJu0YxVqMfAQAwszBAbcYV2QmUI8GPtPznyY5q9MdfQGN1a0N8Z1gHI N6odCgq3mWVkUjDwzEJi9TLDwF+zc2iBHHiTBdvf2egZsHRp2TsbwSF/Vvbamsc+DU+G2aLqz9x XEijLQwHUGdcMgUnivBSt5UDXlbzrY10nTgyytRF7vLAD+q6BlHHn44rkIhi4/KOY+WqwQlRdhm aVTd0FuE0wtHxRGKMJNRXuav8ib+xqNuVPtiir X-Gm-Gg: ASbGnctyq/AsNC48Ouu/7VOE00HXkv7+ZkmTJCAC5e8WVuuNroU1njhgBE6SxlrOw0v eDiTuuHXwOumPe/GDS20IlPKjO7sCZdsHDHw5qhtKyRlZpAlp/sx+wLapV0Uzg8W6UTU81rp8LL uDyD3yfF6ymxvLiNRhHJfhyYb/JJVgLbCms1kd8MJmOZPRQF867Mvz6N0DWSCGbPMqU9BR/Z/J9 cjElgU9ri1Qp5GqxY2nDzsZzn2Zy9nzcWHR3teB1pMvuqEAgNyhOLOG2JoxvrOtQm0dLiCALXhC NukD/H1pEl4Or6Y= X-Received: by 2002:a05:6000:1a89:b0:39e:f89b:85ce with SMTP id ffacd0b85a97d-3a099add434mr1594634f8f.26.1746181410476; Fri, 02 May 2025 03:23:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSQATwwtvw3NZZGjjV1nPwpl8kQfPq+xK1knQ0c8q+bZLxIFZhWp9bMqgyo4MTzEBcuDNXlQ== X-Received: by 2002:a05:6000:1a89:b0:39e:f89b:85ce with SMTP id ffacd0b85a97d-3a099add434mr1594612f8f.26.1746181410049; Fri, 02 May 2025 03:23:30 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 2/9] rust: use std::ffi instead of std::os::raw Date: Fri, 2 May 2025 12:23:15 +0200 Message-ID: <20250502102323.104815-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502102323.104815-1-pbonzini@redhat.com> References: <20250502102323.104815-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.644, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1746181479677019100 Content-Type: text/plain; charset="utf-8" This is allowed since Rust 1.64.0. Signed-off-by: Paolo Bonzini Reviewed-by: Manos Pitsidianakis --- docs/devel/rust.rst | 2 -- rust/hw/char/pl011/src/device_class.rs | 2 +- rust/hw/timer/hpet/src/hpet.rs | 3 +-- rust/qemu-api/src/chardev.rs | 3 +-- rust/qemu-api/src/irq.rs | 6 +++++- rust/qemu-api/src/lib.rs | 2 +- rust/qemu-api/src/memory.rs | 3 +-- rust/qemu-api/src/qdev.rs | 3 +-- rust/qemu-api/src/qom.rs | 3 +-- rust/qemu-api/src/timer.rs | 2 +- rust/qemu-api/src/vmstate.rs | 2 +- rust/qemu-api/tests/vmstate_tests.rs | 7 ++++++- 12 files changed, 20 insertions(+), 18 deletions(-) diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index 3cc2841d4d1..c7dfba98de1 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -74,8 +74,6 @@ Supported tools QEMU supports rustc version 1.63.0 and newer. Notably, the following feat= ures are missing: =20 -* ``core::ffi`` (1.64.0). Use ``std::os::raw`` and ``std::ffi`` instead. - * ``cast_mut()``/``cast_const()`` (1.65.0). Use ``as`` instead. =20 * "let ... else" (1.65.0). Use ``if let`` instead. This is currently pat= ched diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/sr= c/device_class.rs index b4d4a7eb432..cd2dc33c207 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later =20 use std::{ - os::raw::{c_int, c_void}, + ffi::{c_int, c_void}, ptr::NonNull, }; =20 diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs index 12de2ba59a1..d4364f2f2f7 100644 --- a/rust/hw/timer/hpet/src/hpet.rs +++ b/rust/hw/timer/hpet/src/hpet.rs @@ -3,8 +3,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later =20 use std::{ - ffi::CStr, - os::raw::{c_int, c_void}, + ffi::{c_int, c_void, CStr}, pin::Pin, ptr::{addr_of_mut, null_mut, NonNull}, slice::from_ref, diff --git a/rust/qemu-api/src/chardev.rs b/rust/qemu-api/src/chardev.rs index 11e6c45afaf..146a4852da3 100644 --- a/rust/qemu-api/src/chardev.rs +++ b/rust/qemu-api/src/chardev.rs @@ -10,11 +10,10 @@ //! called. =20 use std::{ - ffi::CStr, + ffi::{c_int, c_void, CStr}, fmt::{self, Debug}, io::{self, ErrorKind, Write}, marker::PhantomPinned, - os::raw::{c_int, c_void}, ptr::addr_of_mut, slice, }; diff --git a/rust/qemu-api/src/irq.rs b/rust/qemu-api/src/irq.rs index 1222d4fde30..1526e6f63a1 100644 --- a/rust/qemu-api/src/irq.rs +++ b/rust/qemu-api/src/irq.rs @@ -4,7 +4,11 @@ =20 //! Bindings for interrupt sources =20 -use std::{ffi::CStr, marker::PhantomData, os::raw::c_int, ptr}; +use std::{ + ffi::{c_int, CStr}, + marker::PhantomData, + ptr, +}; =20 use crate::{ bindings::{self, qemu_set_irq}, diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 05f38b51d30..c3641e893b7 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -33,7 +33,7 @@ =20 use std::{ alloc::{GlobalAlloc, Layout}, - os::raw::c_void, + ffi::c_void, }; =20 #[cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)] diff --git a/rust/qemu-api/src/memory.rs b/rust/qemu-api/src/memory.rs index fdb1ea11fcf..9ef2694bd62 100644 --- a/rust/qemu-api/src/memory.rs +++ b/rust/qemu-api/src/memory.rs @@ -5,9 +5,8 @@ //! Bindings for `MemoryRegion`, `MemoryRegionOps` and `MemTxAttrs` =20 use std::{ - ffi::{CStr, CString}, + ffi::{c_uint, c_void, CStr, CString}, marker::PhantomData, - os::raw::{c_uint, c_void}, }; =20 pub use bindings::{hwaddr, MemTxAttrs}; diff --git a/rust/qemu-api/src/qdev.rs b/rust/qemu-api/src/qdev.rs index 18b4a9ba687..17c7fecabeb 100644 --- a/rust/qemu-api/src/qdev.rs +++ b/rust/qemu-api/src/qdev.rs @@ -5,8 +5,7 @@ //! Bindings to create devices and access device functionality from Rust. =20 use std::{ - ffi::{CStr, CString}, - os::raw::{c_int, c_void}, + ffi::{c_int, c_void, CStr, CString}, ptr::NonNull, }; =20 diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs index f1b4022157b..6929e4d33ae 100644 --- a/rust/qemu-api/src/qom.rs +++ b/rust/qemu-api/src/qom.rs @@ -93,11 +93,10 @@ //! without incurring into violations of orphan rules for traits. =20 use std::{ - ffi::CStr, + ffi::{c_void, CStr}, fmt, mem::ManuallyDrop, ops::{Deref, DerefMut}, - os::raw::c_void, ptr::NonNull, }; =20 diff --git a/rust/qemu-api/src/timer.rs b/rust/qemu-api/src/timer.rs index e769f8bc910..d697fd742bc 100644 --- a/rust/qemu-api/src/timer.rs +++ b/rust/qemu-api/src/timer.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later =20 use std::{ - os::raw::{c_int, c_void}, + ffi::{c_int, c_void}, pin::Pin, }; =20 diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 98152e5964d..78c7f17db13 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -25,7 +25,7 @@ //! functionality that is missing from `vmstate_of!`. =20 use core::{marker::PhantomData, mem, ptr::NonNull}; -use std::os::raw::{c_int, c_void}; +use std::ffi::{c_int, c_void}; =20 pub use crate::bindings::{VMStateDescription, VMStateField}; use crate::{ diff --git a/rust/qemu-api/tests/vmstate_tests.rs b/rust/qemu-api/tests/vms= tate_tests.rs index f7a93117e1a..9a56ffd2385 100644 --- a/rust/qemu-api/tests/vmstate_tests.rs +++ b/rust/qemu-api/tests/vmstate_tests.rs @@ -2,7 +2,12 @@ // Author(s): Zhao Liu // SPDX-License-Identifier: GPL-2.0-or-later =20 -use std::{ffi::CStr, mem::size_of, os::raw::c_void, ptr::NonNull, slice}; +use std::{ + ffi::{c_void, CStr}, + mem::size_of, + ptr::NonNull, + slice, +}; =20 use qemu_api::{ bindings::{ --=20 2.49.0 From nobody Sat Nov 15 22:25:04 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1746181573; cv=none; d=zohomail.com; s=zohoarc; b=eeep6p4H9A5/JHZk6k55FWKXW7OlvuqLZ0fJ6QEKMHWzO8fOIsQtGkmR4/chKwgkZKkdO/zcNUEUJgrFhSxLobOrp0RMj/Ra52oWM2NIL9/DErpwqYLhzWn2SlkpA1/Og0ajWO3ba2NMUYnsN3GoVdk0h9i2ZH2oGHL7JUhlAN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746181573; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0wGtDv+e42FWFLc2rz5Xnqr0uS39xEo6CeUJ4+JJbog=; b=jn4fZfHMAWTTX76fu9d/MlWdmHqF7/jH2dHrqtASo3DzchQELlsnEBJ1BARKPHWX2sx8cC/MuVCDTl9zPMHNSTYEhhVRMUThot2XIagHGTnFhf3GzfsrGtJo066lKmNqppDlEVQBFmPS62RfMupc70rQOD6oujaIljnZgJKm+Qc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1746181573695392.69037238262104; Fri, 2 May 2025 03:26:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uAnYX-0001Dh-Oj; Fri, 02 May 2025 06:23:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYT-0001CM-8h for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYP-0000gF-Tl for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:40 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-492-feQnFU4VM7O2c2IZLJ1yEQ-1; Fri, 02 May 2025 06:23:35 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3912e4e2033so498487f8f.0 for ; Fri, 02 May 2025 03:23:35 -0700 (PDT) Received: from [192.168.10.48] ([151.95.54.106]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a099b16ea2sm1684645f8f.85.2025.05.02.03.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 03:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746181416; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0wGtDv+e42FWFLc2rz5Xnqr0uS39xEo6CeUJ4+JJbog=; b=MBtjqBwX+U6ibp3Imd/56DIWP3DF6B4l/O/O64gIhiUrrpPFTWWLOBHAzyZhlIPiDfgS8p /EhbGR8Cgr46rh2c+iXY8CzvfBpJBzTrm8aKAOHfRfpzYdvXU0d9Pg36q9HyZHjPq4Oyul CWJr7/KGWTxWYSeJdZRsAxyf6tX/g9g= X-MC-Unique: feQnFU4VM7O2c2IZLJ1yEQ-1 X-Mimecast-MFC-AGG-ID: feQnFU4VM7O2c2IZLJ1yEQ_1746181414 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746181413; x=1746786213; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0wGtDv+e42FWFLc2rz5Xnqr0uS39xEo6CeUJ4+JJbog=; b=vFn5HEUcOa24X6jU5K1nNUL1cZDpCt6x/z54rZCFsDzHWFM335z83sV8SfmkECkH2h kJjw1Ja1dU6D1uAL8TlMV2TGcQEAtm4S5T1GN8KP56vE6ITeZA2WR/OHA97Hprg2tR6X Ss72Cn/EOBN9Edmu7Kz7LbsBTsdgM3CgInSrmdJxPCVCaVWPqgwi6rMLd0WuL0a/mZ+C Cc1LSJT4Ts0yUlX+OaDkMcdWv6+DpLWVi2JQRTADTx5HKN14GZ8g1xi2hvZQB3q6jPtl eN8VqkgZMVPIgUX03J4Zu0dbRRiteAhwzHz+7K1viHPTgITWNhrvg0G3lwPrqWnGmAnu LfLQ== X-Gm-Message-State: AOJu0Yxkg8ZGjMx+1HgeE3JVoI692413XlofKOWxsK6FLa78hTJ5uier 7EFLC17Kj0guJVmxSW196QV+jv1f+g9rAN0VCEh+RkFGCkWw+KdHASPMGTQyc6QXVauS5L/MX9K JvWe41OlPn5wolhN86yEpxZBHpvNQvFs1i8D9ZZF63jJzVsHCfyeKV/wTV+FrXSnHCYgIZlvhGL Q1c5zDS5QyTm2JXgcGw1sKgiC1JU53PlJCAkfh X-Gm-Gg: ASbGncuSY2i0zOEw/jM61qx9vpaHEcCpY6g+yIn6aswZPEPAycCWp6Z8IvuKzirJWVa 89Vb3/K3TEH0J2fLt1PRrhPvbB0LsMn5XNYO8TZmy2hdGBm5SkC1jnR71pxe1tKi1jRj90nY8Nu BbCAMKg1kjzImK3JZwmfWLuRrQSrEkfMp7IGD9+eI1BfCGiHKeZ1VPgXHOlePs+4EiFRWYgluEc thsP0ZmzuFAi8GTwJBGxe/kB1WFhVrLvK/yyUp4d+ZBGOEyRBotA3jRf6zu9A0FZBYElTbqIpXX ELiwsJkoLlUEi9M= X-Received: by 2002:a05:6000:2209:b0:399:6dc0:f15b with SMTP id ffacd0b85a97d-3a099af15f3mr1294157f8f.48.1746181413652; Fri, 02 May 2025 03:23:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHfMXw17xYz1tqsdhpeJ/VG91CpziOEli/SuErCOrID/k3V9+B2fqQEJvOky4PjVjinZ+XBpA== X-Received: by 2002:a05:6000:2209:b0:399:6dc0:f15b with SMTP id ffacd0b85a97d-3a099af15f3mr1294138f8f.48.1746181413173; Fri, 02 May 2025 03:23:33 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 3/9] rust: let bilge use "let ... else" Date: Fri, 2 May 2025 12:23:16 +0200 Message-ID: <20250502102323.104815-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502102323.104815-1-pbonzini@redhat.com> References: <20250502102323.104815-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.644, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1746181575715019100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Manos Pitsidianakis --- docs/devel/rust.rst | 3 -- subprojects/bilge-impl-0.2-rs.wrap | 2 - .../packagefiles/bilge-impl-1.63.0.patch | 45 ------------------- 3 files changed, 50 deletions(-) delete mode 100644 subprojects/packagefiles/bilge-impl-1.63.0.patch diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index c7dfba98de1..8167ff49aa9 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -76,9 +76,6 @@ are missing: =20 * ``cast_mut()``/``cast_const()`` (1.65.0). Use ``as`` instead. =20 -* "let ... else" (1.65.0). Use ``if let`` instead. This is currently pat= ched - in QEMU's vendored copy of the bilge crate. - * Generic Associated Types (1.65.0) =20 * ``CStr::from_bytes_with_nul()`` as a ``const`` function (1.72.0). diff --git a/subprojects/bilge-impl-0.2-rs.wrap b/subprojects/bilge-impl-0.= 2-rs.wrap index d14c3dc769b..4ccd376eb98 100644 --- a/subprojects/bilge-impl-0.2-rs.wrap +++ b/subprojects/bilge-impl-0.2-rs.wrap @@ -4,8 +4,6 @@ source_url =3D https://crates.io/api/v1/crates/bilge-impl/0= .2.0/download source_filename =3D bilge-impl-0.2.0.tar.gz source_hash =3D feb11e002038ad243af39c2068c8a72bcf147acf05025dcdb916fcc000= adb2d8 #method =3D cargo -patch_directory =3D bilge-impl-0.2-rs -diff_files =3D bilge-impl-1.63.0.patch =20 # bump this version number on every change to meson.build or the patches: # v2 diff --git a/subprojects/packagefiles/bilge-impl-1.63.0.patch b/subprojects= /packagefiles/bilge-impl-1.63.0.patch deleted file mode 100644 index 987428a6d65..00000000000 --- a/subprojects/packagefiles/bilge-impl-1.63.0.patch +++ /dev/null @@ -1,45 +0,0 @@ ---- a/src/shared/discriminant_assigner.rs -+++ b/src/shared/discriminant_assigner.rs -@@ -26,20 +26,20 @@ - let discriminant_expr =3D &discriminant.1; - let variant_name =3D &variant.ident; -=20 -- let Expr::Lit(ExprLit { lit: Lit::Int(int), .. }) =3D discriminan= t_expr else { -+ if let Expr::Lit(ExprLit { lit: Lit::Int(int), .. }) =3D discrimi= nant_expr { -+ let discriminant_value: u128 =3D int.base10_parse().unwrap_or= _else(unreachable); -+ if discriminant_value > self.max_value() { -+ abort!(variant, "Value of variant exceeds the given numbe= r of bits") -+ } -+ -+ Some(discriminant_value) -+ } else { - abort!( - discriminant_expr, - "variant `{}` is not a number", variant_name; - help =3D "only literal integers currently supported" - ) -- }; -- -- let discriminant_value: u128 =3D int.base10_parse().unwrap_or_els= e(unreachable); -- if discriminant_value > self.max_value() { -- abort!(variant, "Value of variant exceeds the given number of= bits") - } -- -- Some(discriminant_value) - } -=20 - fn assign(&mut self, variant: &Variant) -> u128 { ---- a/src/shared/fallback.rs -+++ b/src/shared/fallback.rs -@@ -22,8 +22,9 @@ - } - Unnamed(fields) =3D> { - let variant_fields =3D fields.unnamed.iter(); -- let Ok(fallback_value) =3D variant_fields.exactly_one() e= lse { -- abort!(variant, "fallback variant must have exactly o= ne field"; help =3D "use only one field or change to a unit variant") -+ let fallback_value =3D match variant_fields.exactly_one()= { -+ Ok(ok) =3D> ok, -+ _ =3D> abort!(variant, "fallback variant must have ex= actly one field"; help =3D "use only one field or change to a unit variant") - }; -=20 - if !is_last_variant { --=20 2.49.0 From nobody Sat Nov 15 22:25:04 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1746181567; cv=none; d=zohomail.com; s=zohoarc; b=n77w7YhRBR01MXDeYYn+sFlpafo1viT8Ekmsl6T6ar6epePeyPAqHmkexEP5FK5pOVxSdFLnkhy5hBrmX/hnnAq+bI7YIQBFTt5DjkRZ/1A1yICJ7l1sFcMEaEvwPSUuMWa8gpQPUFgq5X2dg/AHVbw4IZtjjqGTVRy2MPDTH94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746181567; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+KZidse3o3NrsJSDXRiipRvy3WbuaGi3BmMJMyV+q9w=; b=eH6jjmpGTCi69p722RLpoYhk8Hx6jXWm7xD9BAhq+7KSzCV4z/fA5n5VlaxrrPH7jQwPY4v4o1cx2s6hDfJckNxeA/qr1/VLKvbHjATm4pNoqI0DY7izutkUV932r1RPjOSLIZ/24mPWihXzSVYPe/CW7XkWiVxWr2O4pSMmE7M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1746181567094331.0722212983028; Fri, 2 May 2025 03:26:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uAnYW-0001DN-Io; Fri, 02 May 2025 06:23:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYU-0001Cs-KR for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYS-0000gl-0Y for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:42 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-31-iAv-wbCgNFSTQyDFoT_7BA-1; Fri, 02 May 2025 06:23:38 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-39130f02631so505988f8f.2 for ; Fri, 02 May 2025 03:23:37 -0700 (PDT) Received: from [192.168.10.48] ([151.95.54.106]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a099ae82e4sm1769890f8f.58.2025.05.02.03.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 03:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746181419; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+KZidse3o3NrsJSDXRiipRvy3WbuaGi3BmMJMyV+q9w=; b=P2SrT7MAdWaSpuE41ogmW1whuE1aM+J6Vu/QcnmToIlUdXLnzqA7l2yjmuklYIQ0rxy34y w8mYWeLd8Ct3J5ETA+p4aEcNg+OBA4InMA6S5vVCo2RvdDUwl6DlEy5d6AEmLhpLVtNi3s JtBrb6ZQgDTR8C9fv5Rbpnxc/Eb45pI= X-MC-Unique: iAv-wbCgNFSTQyDFoT_7BA-1 X-Mimecast-MFC-AGG-ID: iAv-wbCgNFSTQyDFoT_7BA_1746181417 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746181416; x=1746786216; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+KZidse3o3NrsJSDXRiipRvy3WbuaGi3BmMJMyV+q9w=; b=VWq1QbjOQYNNKqXALz4RTOC5HIwH/0QvoEgEd41fxcfB21B1RsKoOPNg0cGLFp+lqm wnjBgjQaUolh0cTeF92WNet665VJIPMOdWR3JtpA/l13h5I/HPw73yGgH1lHMzJZP2wz v/Y6BYkNzGvAPITi3JlK9RtrhuyGIghWYHVbNx1YImxBLimP22TdDRkEGqPSKy69xVdZ tKRPlhJaN1/RevNTdlZZcC/hdVdS8fNukaQIhJxSjxbgvlyZrJwMXh3w3FBrz6b6SEvn xoh61Q5GCpXRTV4sdSCe9Wouw7pcxQ+I9HzXaOUBdCZDGtCOXMPrmsvdOGs2xIqFbjrV 3dIA== X-Gm-Message-State: AOJu0YzDzyoXwnRe5shjeEqOHDBQGnrvtXxRaCJ/48YXeV9ypFHnHDqd qJOObmSqB548nLA+tANaYwwkxw3tM8oYuA67867xSRrEVvYGBUQkSXqJOAZ3AQ0zxw6UBPBBXru yFGqwQcL5fT0U8ATKME5OOyvyn/dOUq2EKNAfUzQ4MWyceA+Ru5sZ6R7JpCDKvWyL78iqtRGA87 8KrtL6I67Gls35BB7V1sQfXff4qj1l0a0dTqSo X-Gm-Gg: ASbGncuXXCoEyPgCj4bhx4Ba98iBDwwKAjWX3gLLjZFrY7ILssoBHkh2o/6k5d4g/dw /A+9wdLTw420s3OqbyKogaQI7uWvYxtfYbhpgfUaWuCP/rGE4noQZ3T9OMGuNpq+OLa+CAsQ61H C8iXvzNGwDjHHZi7ZGoBB/Ak0XwjIfCenDjKrCK88xOmEVo2hlEB+SD7arDOp+VAko7UQn5G1JQ jh+BUMcQzWX8wzstXewZw306a76EwnWvTlJxkicsJ+m9rSQsEw08ujk98YtV73liTpOBe9K4uZu TENq7LMBYVYpjqc= X-Received: by 2002:a05:6000:2211:b0:3a0:7a7c:235f with SMTP id ffacd0b85a97d-3a099ae939fmr1656679f8f.40.1746181415710; Fri, 02 May 2025 03:23:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFe841JaWdd9NmftMm7CM9LbE/3Sv/SvrR89UJ8RlEG4+lI5yeovCaZ3Vo4sZo3Qc6gS9KeDA== X-Received: by 2002:a05:6000:2211:b0:3a0:7a7c:235f with SMTP id ffacd0b85a97d-3a099ae939fmr1656652f8f.40.1746181415315; Fri, 02 May 2025 03:23:35 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 4/9] rust: qemu_api_macros: use "let ... else" Date: Fri, 2 May 2025 12:23:17 +0200 Message-ID: <20250502102323.104815-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502102323.104815-1-pbonzini@redhat.com> References: <20250502102323.104815-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.644, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1746181568717019000 Content-Type: text/plain; charset="utf-8" "let ... else" is useful when visiting syntax trees, to avoid multiple levels of indentation. Signed-off-by: Paolo Bonzini Reviewed-by: Manos Pitsidianakis --- rust/qemu-api-macros/src/lib.rs | 84 ++++++++++++++++----------------- 1 file changed, 40 insertions(+), 44 deletions(-) diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib= .rs index eda0d46d122..1448f3025a4 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -16,50 +16,47 @@ fn get_fields<'a>( input: &'a DeriveInput, msg: &str, ) -> Result<&'a Punctuated, MacroError> { - if let Data::Struct(s) =3D &input.data { - if let Fields::Named(fs) =3D &s.fields { - Ok(&fs.named) - } else { - Err(MacroError::Message( - format!("Named fields required for {}", msg), - input.ident.span(), - )) - } - } else { - Err(MacroError::Message( + let Data::Struct(s) =3D &input.data else { + return Err(MacroError::Message( format!("Struct required for {}", msg), input.ident.span(), )) - } + }; + let Fields::Named(fs) =3D &s.fields else { + return Err(MacroError::Message( + format!("Named fields required for {}", msg), + input.ident.span(), + )) + }; + Ok(&fs.named) } =20 fn get_unnamed_field<'a>(input: &'a DeriveInput, msg: &str) -> Result<&'a = Field, MacroError> { - if let Data::Struct(s) =3D &input.data { - let unnamed =3D match &s.fields { - Fields::Unnamed(FieldsUnnamed { - unnamed: ref fields, - .. - }) =3D> fields, - _ =3D> { - return Err(MacroError::Message( - format!("Tuple struct required for {}", msg), - s.fields.span(), - )) - } - }; - if unnamed.len() !=3D 1 { - return Err(MacroError::Message( - format!("A single field is required for {}", msg), - s.fields.span(), - )); - } - Ok(&unnamed[0]) - } else { - Err(MacroError::Message( + let Data::Struct(s) =3D &input.data else { + return Err(MacroError::Message( format!("Struct required for {}", msg), input.ident.span(), )) + }; + let unnamed =3D match &s.fields { + Fields::Unnamed(FieldsUnnamed { + unnamed: ref fields, + .. + }) =3D> fields, + _ =3D> { + return Err(MacroError::Message( + format!("Tuple struct required for {}", msg), + s.fields.span(), + )) + } + }; + if unnamed.len() !=3D 1 { + return Err(MacroError::Message( + format!("A single field is required for {}", msg), + s.fields.span(), + )); } + Ok(&unnamed[0]) } =20 fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<(), MacroError> { @@ -210,20 +207,19 @@ fn get_repr_uN(input: &DeriveInput, msg: &str) -> Res= ult { } =20 fn get_variants(input: &DeriveInput) -> Result<&Punctuated= , MacroError> { - if let Data::Enum(e) =3D &input.data { - if let Some(v) =3D e.variants.iter().find(|v| v.fields !=3D Fields= ::Unit) { - return Err(MacroError::Message( - "Cannot derive TryInto for enum with non-unit variants.".t= o_string(), - v.fields.span(), - )); - } - Ok(&e.variants) - } else { - Err(MacroError::Message( + let Data::Enum(e) =3D &input.data else { + return Err(MacroError::Message( "Cannot derive TryInto for union or struct.".to_string(), input.ident.span(), )) + }; + if let Some(v) =3D e.variants.iter().find(|v| v.fields !=3D Fields::Un= it) { + return Err(MacroError::Message( + "Cannot derive TryInto for enum with non-unit variants.".to_st= ring(), + v.fields.span(), + )); } + Ok(&e.variants) } =20 #[rustfmt::skip::macros(quote)] --=20 2.49.0 From nobody Sat Nov 15 22:25:04 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1746181509; cv=none; d=zohomail.com; s=zohoarc; b=fqdpvrLv3j7hr/osmyarbKmc7anXn89wSJtVXKd+LAzmHXOHjAmg8gB0/EnjEWza/pSy1oWOYfWxLpXRfClUQxGM3F+dR2YXOuVNYS5MLAzJuLqEDSfkRDzhlNX+Q2XeDjRiqjIE1h1PZ8dfV1UvGbsBWFuBBvgawbQfYx7dvYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746181509; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Yl8DNVWxw/HVdX6rB7XjjEdD8rzZehVWReue67TF40Y=; b=Jqxyh0g1r92v43dsGGcMJlcwszo0dk9LUiMEeHl6qrXuLv6FYFRiZyxk+nM9N3frHmk/HEeeOaKYoHeOjNcveje0liwcGVoLAGVvTVgm8FDhYzs002st5Z9Bm2eRqGDicvHbAVGEywldIJQ29V7wkkbEK834N8qsVSJO/h38jjg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174618150950043.69293216949552; Fri, 2 May 2025 03:25:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uAnYY-0001ES-UB; Fri, 02 May 2025 06:23:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYX-0001Df-85 for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYV-0000iA-5x for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:44 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-498-wF6_hJruNXqPBWTsZFZ0Yw-1; Fri, 02 May 2025 06:23:40 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43d0a037f97so9007315e9.2 for ; Fri, 02 May 2025 03:23:40 -0700 (PDT) Received: from [192.168.10.48] ([151.95.54.106]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-441b89cc50esm40868565e9.8.2025.05.02.03.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 03:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746181422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Yl8DNVWxw/HVdX6rB7XjjEdD8rzZehVWReue67TF40Y=; b=PdcwreAUO1v3CZeut9k+iVvh0rnPVwM/0sksoQZlJLrwZ2xOlfg4SDh/UWlQ5FmVTIwFUh ZgeMM/Lb/4N0HYD8JcmQQBYIT1psG9d071tnSYAPdnpcc3wmzDc6EtAR0rGG1b3Ks2FCOk uzn64F1VvhcDci3CxLvUrASWrpYOx0s= X-MC-Unique: wF6_hJruNXqPBWTsZFZ0Yw-1 X-Mimecast-MFC-AGG-ID: wF6_hJruNXqPBWTsZFZ0Yw_1746181419 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746181419; x=1746786219; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Yl8DNVWxw/HVdX6rB7XjjEdD8rzZehVWReue67TF40Y=; b=EGK5yMxhmIvMerihdh690b9uD7+p46XknZ7Qoi0jS2XjorjZjcwVo7Bo6U6FAL4Xt8 j0TaKA0SnTqTuNFbRYTjDm7XwQPNJOG+4bOoMrP7GdhdCbQ6zhOM+xz2gUY4mhnO4xAW byarzpxmEBr51b0SwC42V6q6+a6y2gEmoqtpFd6IAuGSzeB5a1fpbcNum71bgWfHOjO/ 11e84eP7EOjW/MyXxJaAq+BXpefHWxNGF8GBJyptUkO5uegdcfp1LY7cEgoOuwm6LM/d qKo8PgHigvSel0b2ScZMiYJJxk9fbrP1jqPz4Yz5vXaIEKmH9dA0lNpv38laG89Jpggg zImA== X-Gm-Message-State: AOJu0Ywpocm+crQe7WBQhrNFgve23zdLUZJhsMM4UeXfImhKHwV0L6cZ 0vSsc7mU55lzS5eaAEH9GmCMp6BV35XjWxWMv1fYaR2bWwx66f/1UXi94EU0uow/9190nj/BLgv pZq5uKkcxjAnNbXWYhDNOB90YL3nw6r/ukEpdJyuRoeKKs/C/qSoRs0908zGxsslOkM4J2fZ1bB cXlKL+3/Y0gZm0pF8+jralORAcUiJG/YmoFVWC X-Gm-Gg: ASbGnctmQt+f3FAneFZTnmTl/VqyW2pqQe7TqrM7U3N05A5KzAGnePT+FMRvCDWwTDm rjfVXPguG8gdmqvp2Ti4BcaVMI1irT9u5mwMOcBIitl8LCXcuPn7IMve15I9aq/i0gIbc0Z2OSL 85pfmEDb+T06yfCTnbAcsRl51neuoNhdvO7H+CGaHAfCKypoofF1eh8juMEli2FcnGa7w7MPESA wi76ACf/DyrbJg3lu+jj/L7ovoGYDi/NLuoZuyNL1f/NlM+hV7z37RTtyu4PGtggiOhF+mbtO6p MXXKTaKMKIaOk/0= X-Received: by 2002:a05:600c:1e12:b0:43d:53c:1ad6 with SMTP id 5b1f17b1804b1-441bbf2bd66mr16522235e9.26.1746181418720; Fri, 02 May 2025 03:23:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFO4trlkva0kfy15cK8IlxEl//hJufaDzfW7jYNmpK6cfxH8tX1ZLsUgTAsFrm0sVbOT9PXVA== X-Received: by 2002:a05:600c:1e12:b0:43d:53c:1ad6 with SMTP id 5b1f17b1804b1-441bbf2bd66mr16522055e9.26.1746181418320; Fri, 02 May 2025 03:23:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 5/9] rust: use MaybeUninit::zeroed() in const context Date: Fri, 2 May 2025 12:23:18 +0200 Message-ID: <20250502102323.104815-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502102323.104815-1-pbonzini@redhat.com> References: <20250502102323.104815-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.644, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1746181511533019000 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Manos Pitsidianakis --- docs/devel/rust.rst | 4 -- rust/hw/timer/hpet/src/fw_cfg.rs | 6 +- rust/qemu-api/src/zeroable.rs | 104 +++++-------------------------- 3 files changed, 18 insertions(+), 96 deletions(-) diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index 8167ff49aa9..13a002cfe69 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -83,10 +83,6 @@ are missing: * "Return position ``impl Trait`` in Traits" (1.75.0, blocker for including the pinned-init create). =20 -* ``MaybeUninit::zeroed()`` as a ``const`` function (1.75.0). QEMU's - ``Zeroable`` trait can be implemented without ``MaybeUninit::zeroed()``, - so this would be just a cleanup. - * ``c"" literals`` (stable in 1.77.0). QEMU provides a ``c_str!()`` macro to define ``CStr`` constants easily =20 diff --git a/rust/hw/timer/hpet/src/fw_cfg.rs b/rust/hw/timer/hpet/src/fw_c= fg.rs index bef03727ea3..aa08d283519 100644 --- a/rust/hw/timer/hpet/src/fw_cfg.rs +++ b/rust/hw/timer/hpet/src/fw_cfg.rs @@ -4,7 +4,7 @@ =20 use std::ptr::addr_of_mut; =20 -use qemu_api::{cell::bql_locked, impl_zeroable, zeroable::Zeroable}; +use qemu_api::{cell::bql_locked, zeroable::Zeroable}; =20 /// Each `HPETState` represents a Event Timer Block. The v1 spec supports /// up to 8 blocks. QEMU only uses 1 block (in PC machine). @@ -18,7 +18,7 @@ pub struct HPETFwEntry { pub min_tick: u16, pub page_prot: u8, } -impl_zeroable!(HPETFwEntry); +unsafe impl Zeroable for HPETFwEntry {} =20 #[repr(C, packed)] #[derive(Copy, Clone, Default)] @@ -26,7 +26,7 @@ pub struct HPETFwConfig { pub count: u8, pub hpet: [HPETFwEntry; HPET_MAX_NUM_EVENT_TIMER_BLOCK], } -impl_zeroable!(HPETFwConfig); +unsafe impl Zeroable for HPETFwConfig {} =20 #[allow(non_upper_case_globals)] #[no_mangle] diff --git a/rust/qemu-api/src/zeroable.rs b/rust/qemu-api/src/zeroable.rs index a3415a2ebcc..57d802db69b 100644 --- a/rust/qemu-api/src/zeroable.rs +++ b/rust/qemu-api/src/zeroable.rs @@ -4,89 +4,15 @@ =20 /// Encapsulates the requirement that /// `MaybeUninit::::zeroed().assume_init()` does not cause undefined -/// behavior. This trait in principle could be implemented as just: -/// -/// ``` -/// pub unsafe trait Zeroable: Default { -/// const ZERO: Self =3D unsafe { ::core::mem::MaybeUninit::::ze= roed().assume_init() }; -/// } -/// ``` -/// -/// The need for a manual implementation is only because `zeroed()` cannot -/// be used as a `const fn` prior to Rust 1.75.0. Once we can assume a new -/// enough version of the compiler, we could provide a `#[derive(Zeroable)= ]` -/// macro to check at compile-time that all struct fields are Zeroable, and -/// use the above blanket implementation of the `ZERO` constant. +/// behavior. /// /// # Safety /// -/// Because the implementation of `ZERO` is manual, it does not make -/// any assumption on the safety of `zeroed()`. However, other users of t= he -/// trait could use it that way. Do not add this trait to a type unless -/// all-zeroes is a valid value for the type. In particular, remember that -/// raw pointers can be zero, but references and `NonNull` cannot +/// Do not add this trait to a type unless all-zeroes is a valid value for= the +/// type. In particular, raw pointers can be zero, but references and `No= nNull` +/// cannot. pub unsafe trait Zeroable: Default { - const ZERO: Self; -} - -/// A macro that acts similarly to [`core::mem::zeroed()`], only is const -/// -/// ## Safety -/// -/// Similar to `core::mem::zeroed()`, except this zeroes padding bits. Zer= oed -/// padding usually isn't relevant to safety, but might be if a C union is= used. -/// -/// Just like for `core::mem::zeroed()`, an all zero byte pattern might not -/// be a valid value for a type, as is the case for references `&T` and `&= mut -/// T`. Reference types trigger a (denied by default) lint and cause immed= iate -/// undefined behavior if the lint is ignored -/// -/// ```rust compile_fail -/// use const_zero::const_zero; -/// // error: any use of this value will cause an error -/// // note: `#[deny(const_err)]` on by default -/// const STR: &str =3D unsafe{const_zero!(&'static str)}; -/// ``` -/// -/// `const_zero` does not work on unsized types: -/// -/// ```rust compile_fail -/// use const_zero::const_zero; -/// // error[E0277]: the size for values of type `[u8]` cannot be known at= compilation time -/// const BYTES: [u8] =3D unsafe{const_zero!([u8])}; -/// ``` -/// ## Differences with `core::mem::zeroed` -/// -/// `const_zero` zeroes padding bits, while `core::mem::zeroed` doesn't -#[macro_export] -macro_rules! const_zero { - // This macro to produce a type-generic zero constant is taken from the - // const_zero crate (v0.1.1): - // - // https://docs.rs/const-zero/latest/src/const_zero/lib.rs.html - // - // and used under MIT license - ($type_:ty) =3D> {{ - const TYPE_SIZE: ::core::primitive::usize =3D ::core::mem::size_of= ::<$type_>(); - union TypeAsBytes { - bytes: [::core::primitive::u8; TYPE_SIZE], - inner: ::core::mem::ManuallyDrop<$type_>, - } - const ZERO_BYTES: TypeAsBytes =3D TypeAsBytes { - bytes: [0; TYPE_SIZE], - }; - ::core::mem::ManuallyDrop::<$type_>::into_inner(ZERO_BYTES.inner) - }}; -} - -/// A wrapper to implement the `Zeroable` trait through the `const_zero` m= acro. -#[macro_export] -macro_rules! impl_zeroable { - ($type:ty) =3D> { - unsafe impl $crate::zeroable::Zeroable for $type { - const ZERO: Self =3D unsafe { $crate::const_zero!($type) }; - } - }; + const ZERO: Self =3D unsafe { ::core::mem::MaybeUninit::::zeroed= ().assume_init() }; } =20 // bindgen does not derive Default here @@ -97,13 +23,13 @@ fn default() -> Self { } } =20 -impl_zeroable!(crate::bindings::Property__bindgen_ty_1); -impl_zeroable!(crate::bindings::Property); -impl_zeroable!(crate::bindings::VMStateFlags); -impl_zeroable!(crate::bindings::VMStateField); -impl_zeroable!(crate::bindings::VMStateDescription); -impl_zeroable!(crate::bindings::MemoryRegionOps__bindgen_ty_1); -impl_zeroable!(crate::bindings::MemoryRegionOps__bindgen_ty_2); -impl_zeroable!(crate::bindings::MemoryRegionOps); -impl_zeroable!(crate::bindings::MemTxAttrs); -impl_zeroable!(crate::bindings::CharBackend); +unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 {} +unsafe impl Zeroable for crate::bindings::Property {} +unsafe impl Zeroable for crate::bindings::VMStateFlags {} +unsafe impl Zeroable for crate::bindings::VMStateField {} +unsafe impl Zeroable for crate::bindings::VMStateDescription {} +unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 {} +unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 {} +unsafe impl Zeroable for crate::bindings::MemoryRegionOps {} +unsafe impl Zeroable for crate::bindings::MemTxAttrs {} +unsafe impl Zeroable for crate::bindings::CharBackend {} --=20 2.49.0 From nobody Sat Nov 15 22:25:04 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1746181511; cv=none; d=zohomail.com; s=zohoarc; b=lkj5J3HRQ0Ot9Xvf9F8H1W2hmswOCZbIN0eWnLtN2zGeljQM0vQLrCBFzEcZxE9kvYZu/1vS23L3nhCiXXhWcb6Idl51sn8Ghz/Gi1U3Iyfar4dbskdbt0fp5JJ4iJJnV8Edl9no7OAjbCQyVjj8D5WK6C/trCfdr9pOuh2ExDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746181511; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1wYFKFukEgC4q83remIku1UKrxyAwoZsTo9ED8Ho7I0=; b=HzUxluypj54Jd3i/mhsLhweatfVi0f/ad19ECnzXLA0ArUMaapGSfdjtXRHaubIyMsqHEM8r9DF/eG3Tor8jPhjxG7aHWYMVDByT4haSjEp8mtdnMdweLt3az8XFff7IgWjvMrceBpFdxTqL/7wjvvM8iHtmFj7zb/uc/RyY1n8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1746181511690295.0195327070628; Fri, 2 May 2025 03:25:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uAnYf-0001GJ-Ay; Fri, 02 May 2025 06:23:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYb-0001FL-9Q for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYX-0000j0-Ud for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:48 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-232--tuzoninPTOXzvfRDRp73Q-1; Fri, 02 May 2025 06:23:44 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43d00017e9dso8906215e9.0 for ; Fri, 02 May 2025 03:23:43 -0700 (PDT) Received: from [192.168.10.48] ([151.95.54.106]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a099ae3403sm1730617f8f.28.2025.05.02.03.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 03:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746181425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1wYFKFukEgC4q83remIku1UKrxyAwoZsTo9ED8Ho7I0=; b=PobhkfR/XJr3FCtlH0roIVwRAr1pNBUiDCWyZMpgy6lagF+F5+++R9dTDXzLXybt2Z7Ijk IUB9yZdtlIJGdc0e/dheaI5rRhXj0q199QczjY5hHuhu+64WSaG56OaZHZPl8dsCzmuJP7 OYhPPFB/IJpvwH72xMQsfHeCZ033/u4= X-MC-Unique: -tuzoninPTOXzvfRDRp73Q-1 X-Mimecast-MFC-AGG-ID: -tuzoninPTOXzvfRDRp73Q_1746181423 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746181422; x=1746786222; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1wYFKFukEgC4q83remIku1UKrxyAwoZsTo9ED8Ho7I0=; b=RqAV9JRXn2lDtaNdh8C94nQID8Si0CeLtTFxU2xVY30sSGn+cktW/UX7IqV96+QYii opPgqvj8xL9R2hR82kLhZY49Hp9ijH2p5CZkHDVcrAinqb3nSFAUgu+ypbXRaGND0Ruf KXUQ+RIW6jrkaRSgBSQmWDOLSbMGPZQj6mR4QMQgufjkwJxC1aeVal+k2I/PPIgtPLds 89GJ+Oc20scedGMv7Ng7tr8yuG/n427fwbX9XvWZ9He7/PK5zVOqQz/ZjvW2ViaLHWeu d0xCwnADOpXEUChDoQxJHuZEZGGHBoXmWLisYebhCwz7Tzfy6y8149CA9HCeHDcou+Ky qn8g== X-Gm-Message-State: AOJu0Yz8/JBce15xJ/7I1oVA3HSVHFZKxOUfZjy2zofZAtAY7zwBUGJC U5WD5uhDKCUTZovmXgcPoZDVWZpmQaAGSY4BRSZYvAkwOJLSHHpC5muzkh072PxWBiVpNfyAtwZ zBg8CkMWnIwyzRv6vShhVrfHI2WM0TLvQBJ3RjcnT2+VZNISdqZ6ZetnqWykf4/9DZWGPfS9VPK mf1NBpBP9HuM+6lG8bA9DCCM9MSYysyPATmtu4 X-Gm-Gg: ASbGnctvb+n9ZEoaaj7xJhHj+2Vr3oWb/zV+QlRxtQ/jGVazuA8SYFDhOKJkJjwngCf hFvO3bdl3hqkIBhiauvWM/Mg0r1ZeAHTSiNF//v681MijU9SwapPiVOXkn+k/xwUfn6Nri/Bhkj T0yhObBAr6lyQx5VYyZsCLZKNfql2YbOaIsna99C/XTqrgsk8gZEPmi6nDfh1MhtAQw8NVUGy1S F4g73AcYfD4Cj/yNoYXflKPDPy026JGMHp5d0jknmjxar5fjWx5KMijWZq5QI91qiwT0w2/3YK1 zzNTkioturf8HZw= X-Received: by 2002:a05:600c:1f94:b0:43d:5ec:b2f4 with SMTP id 5b1f17b1804b1-441bbeb36afmr22245055e9.10.1746181421446; Fri, 02 May 2025 03:23:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzG6gfgMHL9lJlqgDZyxzQx3ByVYr4LexcBEYEwQxYCUQjgAKWYWeECEcC6CWq6jlHEM/aTg== X-Received: by 2002:a05:600c:1f94:b0:43d:5ec:b2f4 with SMTP id 5b1f17b1804b1-441bbeb36afmr22244595e9.10.1746181420775; Fri, 02 May 2025 03:23:40 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 6/9] rust: remove offset_of replacement Date: Fri, 2 May 2025 12:23:19 +0200 Message-ID: <20250502102323.104815-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502102323.104815-1-pbonzini@redhat.com> References: <20250502102323.104815-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.644, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1746181513912019100 Content-Type: text/plain; charset="utf-8" --- docs/devel/rust.rst | 6 - rust/Cargo.toml | 2 +- rust/hw/char/pl011/src/device.rs | 4 +- rust/hw/timer/hpet/src/hpet.rs | 4 +- rust/qemu-api-macros/src/lib.rs | 29 +---- rust/qemu-api/Cargo.toml | 3 - rust/qemu-api/build.rs | 7 -- rust/qemu-api/meson.build | 4 - rust/qemu-api/src/lib.rs | 4 - rust/qemu-api/src/offset_of.rs | 168 --------------------------- rust/qemu-api/src/qdev.rs | 6 +- rust/qemu-api/src/vmstate.rs | 10 +- rust/qemu-api/tests/tests.rs | 2 - rust/qemu-api/tests/vmstate_tests.rs | 5 +- 14 files changed, 16 insertions(+), 238 deletions(-) delete mode 100644 rust/qemu-api/src/offset_of.rs diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index 13a002cfe69..8dad90fdf98 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -86,12 +86,6 @@ are missing: * ``c"" literals`` (stable in 1.77.0). QEMU provides a ``c_str!()`` macro to define ``CStr`` constants easily =20 -* ``offset_of!`` (stable in 1.77.0). QEMU uses ``offset_of!()`` heavily; = it - provides a replacement in the ``qemu_api`` crate, but it does not support - lifetime parameters and therefore ``&'a Something`` fields in the struct - may have to be replaced by ``NonNull``. *Nested* ``offset_of= !`` - was only stabilized in Rust 1.82.0, but it is not used. - * inline const expression (stable in 1.79.0), currently worked around with associated constants in the ``FnCall`` trait. =20 diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ab1185a8143..ea2a85a1d07 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -10,7 +10,7 @@ members =3D [ [workspace.lints.rust] unexpected_cfgs =3D { level =3D "deny", check-cfg =3D [ 'cfg(MESON)', 'cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)', - 'cfg(has_offset_of)'] } +] } =20 # Occasionally, we may need to silence warnings and clippy lints that # were only introduced in newer Rust compiler versions. Do not croak diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index bb2a0f207a5..7c563ade9cd 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -74,7 +74,7 @@ fn index(&self, idx: u32) -> &Self::Output { } =20 #[repr(C)] -#[derive(Debug, Default, qemu_api_macros::offsets)] +#[derive(Debug, Default)] pub struct PL011Registers { #[doc(alias =3D "fr")] pub flags: registers::Flags, @@ -98,7 +98,7 @@ pub struct PL011Registers { } =20 #[repr(C)] -#[derive(qemu_api_macros::Object, qemu_api_macros::offsets)] +#[derive(qemu_api_macros::Object)] /// PL011 Device Model in QEMU pub struct PL011State { pub parent_obj: ParentField, diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs index d4364f2f2f7..72609c31f44 100644 --- a/rust/hw/timer/hpet/src/hpet.rs +++ b/rust/hw/timer/hpet/src/hpet.rs @@ -183,7 +183,7 @@ fn timer_handler(timer_cell: &BqlRefCell) { =20 /// HPET Timer Abstraction #[repr(C)] -#[derive(Debug, qemu_api_macros::offsets)] +#[derive(Debug)] pub struct HPETTimer { /// timer N index within the timer block (`HPETState`) #[doc(alias =3D "tn")] @@ -523,7 +523,7 @@ fn write(&mut self, reg: TimerRegister, value: u64, shi= ft: u32, len: u32) { =20 /// HPET Event Timer Block Abstraction #[repr(C)] -#[derive(qemu_api_macros::Object, qemu_api_macros::offsets)] +#[derive(qemu_api_macros::Object)] pub struct HPETState { parent_obj: ParentField, iomem: MemoryRegion, diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib= .rs index 1448f3025a4..108f434ed44 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -6,7 +6,7 @@ use quote::quote; use syn::{ parse_macro_input, parse_quote, punctuated::Punctuated, spanned::Spann= ed, token::Comma, Data, - DeriveInput, Field, Fields, FieldsUnnamed, Ident, Meta, Path, Token, T= ype, Variant, Visibility, + DeriveInput, Field, Fields, FieldsUnnamed, Ident, Meta, Path, Token, V= ariant, }; =20 mod utils; @@ -157,33 +157,6 @@ pub fn derive_opaque(input: TokenStream) -> TokenStrea= m { TokenStream::from(expanded) } =20 -#[rustfmt::skip::macros(quote)] -fn derive_offsets_or_error(input: DeriveInput) -> Result { - is_c_repr(&input, "#[derive(offsets)]")?; - - let name =3D &input.ident; - let fields =3D get_fields(&input, "#[derive(offsets)]")?; - let field_names: Vec<&Ident> =3D fields.iter().map(|f| f.ident.as_ref(= ).unwrap()).collect(); - let field_types: Vec<&Type> =3D fields.iter().map(|f| &f.ty).collect(); - let field_vis: Vec<&Visibility> =3D fields.iter().map(|f| &f.vis).coll= ect(); - - Ok(quote! { - ::qemu_api::with_offsets! { - struct #name { - #(#field_vis #field_names: #field_types,)* - } - } - }) -} - -#[proc_macro_derive(offsets)] -pub fn derive_offsets(input: TokenStream) -> TokenStream { - let input =3D parse_macro_input!(input as DeriveInput); - let expanded =3D derive_offsets_or_error(input).unwrap_or_else(Into::i= nto); - - TokenStream::from(expanded) -} - #[allow(non_snake_case)] fn get_repr_uN(input: &DeriveInput, msg: &str) -> Result= { let repr =3D input.attrs.iter().find(|attr| attr.path().is_ident("repr= ")); diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index 57747bc9341..c5b7b2464e9 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -18,9 +18,6 @@ rust-version =3D "1.63.0" qemu_api_macros =3D { path =3D "../qemu-api-macros" } libc =3D "0.2.162" =20 -[build-dependencies] -version_check =3D "~0.9" - [features] default =3D ["debug_cell"] allocator =3D [] diff --git a/rust/qemu-api/build.rs b/rust/qemu-api/build.rs index 471e6c633df..470be2a4d54 100644 --- a/rust/qemu-api/build.rs +++ b/rust/qemu-api/build.rs @@ -8,8 +8,6 @@ use std::os::windows::fs::symlink_file; use std::{env, fs::remove_file, io::Result, path::Path}; =20 -use version_check as rustc; - fn main() -> Result<()> { // Placing bindings.inc.rs in the source directory is supported // but not documented or encouraged. @@ -38,11 +36,6 @@ fn main() -> Result<()> { } symlink_file(file, dest_path)?; =20 - // Check for available rustc features - if rustc::is_min_version("1.77.0").unwrap_or(false) { - println!("cargo:rustc-cfg=3Dhas_offset_of"); - } - println!("cargo:rerun-if-changed=3Dbuild.rs"); Ok(()) } diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 858685ddd4a..95e65643ae1 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -5,9 +5,6 @@ _qemu_api_cfg =3D run_command(rustc_args, libc_dep =3D dependency('libc-0.2-rs') =20 # _qemu_api_cfg +=3D ['--cfg', 'feature=3D"allocator"'] -if rustc.version().version_compare('>=3D1.77.0') - _qemu_api_cfg +=3D ['--cfg', 'has_offset_of'] -endif if get_option('debug_mutex') _qemu_api_cfg +=3D ['--cfg', 'feature=3D"debug_cell"'] endif @@ -28,7 +25,6 @@ _qemu_api_rs =3D static_library( 'src/irq.rs', 'src/memory.rs', 'src/module.rs', - 'src/offset_of.rs', 'src/prelude.rs', 'src/qdev.rs', 'src/qom.rs', diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index c3641e893b7..90c19636660 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -23,7 +23,6 @@ pub mod irq; pub mod memory; pub mod module; -pub mod offset_of; pub mod qdev; pub mod qom; pub mod sysbus; @@ -165,6 +164,3 @@ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { } } } - -#[cfg(has_offset_of)] -pub use core::mem::offset_of; diff --git a/rust/qemu-api/src/offset_of.rs b/rust/qemu-api/src/offset_of.rs deleted file mode 100644 index 373229bbde9..00000000000 --- a/rust/qemu-api/src/offset_of.rs +++ /dev/null @@ -1,168 +0,0 @@ -// SPDX-License-Identifier: MIT - -#![doc(hidden)] -//! This module provides macros that emulate the functionality of -//! `core::mem::offset_of` on older versions of Rust. -//! -//! Documentation is hidden because it only exposes macros, which -//! are exported directly from `qemu_api`. - -/// This macro provides the same functionality as `core::mem::offset_of`, -/// except that only one level of field access is supported. The declarat= ion -/// of the struct must be wrapped with `with_offsets! { }`. -/// -/// It is needed because `offset_of!` was only stabilized in Rust 1.77. -#[cfg(not(has_offset_of))] -#[macro_export] -macro_rules! offset_of { - ($Container:ty, $field:ident) =3D> { - <$Container>::OFFSET_TO__.$field - }; -} - -/// A wrapper for struct declarations, that allows using `offset_of!` in -/// versions of Rust prior to 1.77 -#[macro_export] -macro_rules! with_offsets { - // This method to generate field offset constants comes from: - // - // https://play.rust-lang.org/?version=3Dstable&mode=3Ddebug&editi= on=3D2018&gist=3D10a22a9b8393abd7b541d8fc844bc0df - // - // used under MIT license with permission of Yandros aka Daniel Henry-= Mantilla - ( - $(#[$struct_meta:meta])* - $struct_vis:vis - struct $StructName:ident { - $( - $(#[$field_meta:meta])* - $field_vis:vis - $field_name:ident : $field_ty:ty - ),* - $(,)? - } - ) =3D> ( - #[cfg(not(has_offset_of))] - const _: () =3D { - struct StructOffsetsHelper(std::marker::PhantomData); - const END_OF_PREV_FIELD: usize =3D 0; - - // populate StructOffsetsHelper with associated consts, - // one for each field - $crate::with_offsets! { - @struct $StructName - @names [ $($field_name)* ] - @tys [ $($field_ty ,)*] - } - - // now turn StructOffsetsHelper's consts into a single stru= ct, - // applying field visibility. This provides better error mess= ages - // than if offset_of! used StructOffsetsHelper:: directly. - pub - struct StructOffsets { - $( - $field_vis - $field_name: usize, - )* - } - impl $StructName { - pub - const OFFSET_TO__: StructOffsets =3D StructOffsets { - $( - $field_name: StructOffsetsHelper::<$StructName>::$= field_name, - )* - }; - } - }; - ); - - ( - @struct $StructName:ident - @names [] - @tys [] - ) =3D> (); - - ( - @struct $StructName:ident - @names [$field_name:ident $($other_names:tt)*] - @tys [$field_ty:ty , $($other_tys:tt)*] - ) =3D> ( - #[allow(non_local_definitions)] - #[allow(clippy::modulo_one)] - impl StructOffsetsHelper<$StructName> { - #[allow(nonstandard_style)] - const $field_name: usize =3D { - const ALIGN: usize =3D std::mem::align_of::<$field_ty>(); - const TRAIL: usize =3D END_OF_PREV_FIELD % ALIGN; - END_OF_PREV_FIELD + (if TRAIL =3D=3D 0 { 0usize } else { A= LIGN - TRAIL }) - }; - } - const _: () =3D { - const END_OF_PREV_FIELD: usize =3D - StructOffsetsHelper::<$StructName>::$field_name + - std::mem::size_of::<$field_ty>() - ; - $crate::with_offsets! { - @struct $StructName - @names [$($other_names)*] - @tys [$($other_tys)*] - } - }; - ); -} - -#[cfg(test)] -mod tests { - use crate::offset_of; - - #[repr(C)] - struct Foo { - a: u16, - b: u32, - c: u64, - d: u16, - } - - #[repr(C)] - struct Bar { - pub a: u16, - pub b: u64, - c: Foo, - d: u64, - } - - crate::with_offsets! { - #[repr(C)] - struct Bar { - pub a: u16, - pub b: u64, - c: Foo, - d: u64, - } - } - - #[repr(C)] - pub struct Baz { - b: u32, - a: u8, - } - crate::with_offsets! { - #[repr(C)] - pub struct Baz { - b: u32, - a: u8, - } - } - - #[test] - fn test_offset_of() { - const OFFSET_TO_C: usize =3D offset_of!(Bar, c); - - assert_eq!(offset_of!(Bar, a), 0); - assert_eq!(offset_of!(Bar, b), 8); - assert_eq!(OFFSET_TO_C, 16); - assert_eq!(offset_of!(Bar, d), 40); - - assert_eq!(offset_of!(Baz, b), 0); - assert_eq!(offset_of!(Baz, a), 4); - } -} diff --git a/rust/qemu-api/src/qdev.rs b/rust/qemu-api/src/qdev.rs index 17c7fecabeb..1279d7a58d5 100644 --- a/rust/qemu-api/src/qdev.rs +++ b/rust/qemu-api/src/qdev.rs @@ -190,7 +190,7 @@ macro_rules! define_property { // use associated function syntax for type checking name: ::std::ffi::CStr::as_ptr($name), info: $prop, - offset: $crate::offset_of!($state, $field) as isize, + offset: ::std::mem::offset_of!($state, $field) as isize, bitnr: $bitnr, set_default: true, defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval = as u64 }, @@ -202,7 +202,7 @@ macro_rules! define_property { // use associated function syntax for type checking name: ::std::ffi::CStr::as_ptr($name), info: $prop, - offset: $crate::offset_of!($state, $field) as isize, + offset: ::std::mem::offset_of!($state, $field) as isize, set_default: true, defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval = as u64 }, ..$crate::zeroable::Zeroable::ZERO @@ -213,7 +213,7 @@ macro_rules! define_property { // use associated function syntax for type checking name: ::std::ffi::CStr::as_ptr($name), info: $prop, - offset: $crate::offset_of!($state, $field) as isize, + offset: ::std::mem::offset_of!($state, $field) as isize, set_default: false, ..$crate::zeroable::Zeroable::ZERO } diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 78c7f17db13..9a6e6b734b9 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -205,8 +205,8 @@ macro_rules! vmstate_of { name: ::core::concat!(::core::stringify!($field_name), "\0") .as_bytes() .as_ptr() as *const ::std::os::raw::c_char, - offset: $crate::offset_of!($struct_name, $field_name), - $(num_offset: $crate::offset_of!($struct_name, $num),)? + offset: ::std::mem::offset_of!($struct_name, $field_name), + $(num_offset: ::std::mem::offset_of!($struct_name, $num),)? // The calls to `call_func_with_field!` are the magic that // computes most of the VMStateField from the type of the fiel= d. info: $crate::info_enum_to_ref!($crate::call_func_with_field!( @@ -482,10 +482,10 @@ macro_rules! vmstate_struct { name: ::core::concat!(::core::stringify!($field_name), "\0") .as_bytes() .as_ptr() as *const ::std::os::raw::c_char, - $(num_offset: $crate::offset_of!($struct_name, $num),)? + $(num_offset: ::std::mem::offset_of!($struct_name, $num),)? offset: { $crate::assert_field_type!($struct_name, $field_name, $typ= e $(, num =3D $num)?); - $crate::offset_of!($struct_name, $field_name) + ::std::mem::offset_of!($struct_name, $field_name) }, size: ::core::mem::size_of::<$type>(), flags: $crate::bindings::VMStateFlags::VMS_STRUCT, @@ -517,7 +517,7 @@ macro_rules! vmstate_clock { $field_name, $crate::qom::Owned<$crate::qdev::Clock> $(, num =3D $n= um)? ); - $crate::offset_of!($struct_name, $field_name) + ::std::mem::offset_of!($struct_name, $field_name) }, size: ::core::mem::size_of::<*const $crate::qdev::Clock>(), flags: $crate::bindings::VMStateFlags( diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 99a7aab6fed..d045808c3a8 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -26,7 +26,6 @@ ..Zeroable::ZERO }; =20 -#[derive(qemu_api_macros::offsets)] #[repr(C)] #[derive(qemu_api_macros::Object)] pub struct DummyState { @@ -79,7 +78,6 @@ fn vmsd() -> Option<&'static VMStateDescription> { } } =20 -#[derive(qemu_api_macros::offsets)] #[repr(C)] #[derive(qemu_api_macros::Object)] pub struct DummyChildState { diff --git a/rust/qemu-api/tests/vmstate_tests.rs b/rust/qemu-api/tests/vms= tate_tests.rs index 9a56ffd2385..cc3527a9b6a 100644 --- a/rust/qemu-api/tests/vmstate_tests.rs +++ b/rust/qemu-api/tests/vmstate_tests.rs @@ -33,7 +33,7 @@ // - VMSTATE_VARRAY_UINT16_UNSAFE // - VMSTATE_VARRAY_MULTIPLY #[repr(C)] -#[derive(Default, qemu_api_macros::offsets)] +#[derive(Default)] struct FooA { arr: [u8; FOO_ARRAY_MAX], num: u16, @@ -154,7 +154,7 @@ fn test_vmstate_varray_multiply() { // - VMSTATE_ARRAY // - VMSTATE_STRUCT_VARRAY_UINT8 with BqlCell wrapper & test_fn #[repr(C)] -#[derive(Default, qemu_api_macros::offsets)] +#[derive(Default)] struct FooB { arr_a: [FooA; FOO_ARRAY_MAX], num_a: u8, @@ -329,7 +329,6 @@ fn test_vmstate_struct_varray_uint8_wrapper() { impl_vmstate_forward!(FooCWrapper); =20 #[repr(C)] -#[derive(qemu_api_macros::offsets)] struct FooC { ptr: *const i32, ptr_a: NonNull, --=20 2.49.0 From nobody Sat Nov 15 22:25:04 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1746181508; cv=none; d=zohomail.com; s=zohoarc; b=AfrrCJZeQ+pGhshSA9X5sgiBuKbZ2VLc+N8jehBB9AqlbRgHOTpawnk3n3DdGKFGi0jIU1/hic5a767ygtFgRB69QDTeX6do9/SFfMG5gGL4d4ECz39vWjN/1IvZ6HXHdoUBtvwXEWdmZS4ZKdKERFV/MTaV933FIVfIx34rWp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746181508; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sB1RxFzinWPdmNZOEcfcnJ1bFCbF+VuYIyWhiTfLYVU=; b=atdUmBzR1T5RJ4J6Y6QoSyxhrus6hJfl1WRtNO9cZuflf+RZ7p3ns68EUNkWAa0Slxb8YZgayrSXgYa9671y1BGyQaxdQ3fAZw5Yp5wDHWSRI17ReHm7VVW5fPC06BkqNnOQ6bNDuNH6xhXHtwTcN+e7FSiXSCUzvY/pehlBqUY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1746181508533565.163158993463; Fri, 2 May 2025 03:25:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uAnYh-0001HL-VG; Fri, 02 May 2025 06:23:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYd-0001GV-Ql for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYY-0000jF-R2 for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:51 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-395-DwNg-fv6PMijqhY-XR6hJw-1; Fri, 02 May 2025 06:23:45 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43e9b0fd00cso7759325e9.0 for ; Fri, 02 May 2025 03:23:44 -0700 (PDT) Received: from [192.168.10.48] ([151.95.54.106]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a099b0ff8esm1735567f8f.79.2025.05.02.03.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 03:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746181426; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sB1RxFzinWPdmNZOEcfcnJ1bFCbF+VuYIyWhiTfLYVU=; b=fxCVNQ5zFXylYoW2HoC4EKMBUgbR3jCJZ4kiYqLc0ioVOcnWIm3ceBCfhbRNQsthgnZSoO +R5vkyA6OASdqRtntMEE/vl7DxmRKaMciAIfqB0HE8zuHt5O56auiSdYVtekpixftAEdsu xjKXCvBWHv9IZKnKZlmB8buc4+HikJ0= X-MC-Unique: DwNg-fv6PMijqhY-XR6hJw-1 X-Mimecast-MFC-AGG-ID: DwNg-fv6PMijqhY-XR6hJw_1746181424 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746181423; x=1746786223; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sB1RxFzinWPdmNZOEcfcnJ1bFCbF+VuYIyWhiTfLYVU=; b=Ya9zDYVa8a56ii5M8I7c+lJ1yOhRzrHEAma+5rYk+KYJTA51FVQ86DIb8ns9rAMdng pWmJuBbBdGyl++tXW0cWrfPysN5FY3HbeR/HszB9pZgk2+MmNMhsgX8RfyOj/3iIBNoA CgtGTph5j8X9oT4MAJ8/9BetlcvOMtpvpr7j4BYvg3de8YA97k1vJ/KCVl6uK3++Lwsq IkCVnXfTULaKVBa5n7JUTtFl5ZY2hlXzBe1wlYDkOUiONx1GfpxQCdWhJh/SVAfPDBWp PJ475CQzcPiDL7DywfAxIugYeBX2UK7bSg2BJiUuOZd65UXyMMDY4gxnZ0NWQHPxt735 eDDg== X-Gm-Message-State: AOJu0YytPVjV1IEe+v2Eeaj8lJwf62afzpTbFQ/+lz8ciFWyf0Un7LmW AayLNp1wLITN66/fKQB9758TDFlBRAiIRrmc+TQV3/3DS0hpc8h0McEuV8CTKxMRyZI6IIvqbtB OthjVP47b/B2twlZSI6Qbfk2/pX74qWb6n4/PQMj3ChEHEA8ol/LvCJZ39SLR2MY4GTyBPY+xyp FCfKA2KfTAyV8vNCcvhbut/n28arKJXzxGQgiz X-Gm-Gg: ASbGncu3opn2bKDtxFQsn8jaQIAo16tXxdiElt7X/FI3EIDhdCuuaGWvF6a3wdPrT3/ xbRAT3pQ/jepW0Qt0zAeiYI46ZfHIKvVSjwSdQvpgIPAXMvwQytqj6DfueJ6946LylmMs7/DSJz 2wSeinrcGfoqBAG2CbGm0lG1hWADdSSGKwxfdwExL6xvN9k2rohDansPwkzy6ddEpRPOhFoT0kB idtHC+cF4w4oiP0vhm6XPPcPz0HD6hGgqFEru9J9SLj1JS6S0/i+rxUVedsyRaHtDChYUL8P3zm BTZIob93mxA0/1I= X-Received: by 2002:a05:600c:1c8f:b0:439:4c1e:d810 with SMTP id 5b1f17b1804b1-441bb856814mr17472105e9.9.1746181422691; Fri, 02 May 2025 03:23:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFo/CB01mjIxY+wHYXz92ytwjkhlH+lKUIXyo63UxM/+IAjbZkIZl18HA1DOVK5f16XQhYkFA== X-Received: by 2002:a05:600c:1c8f:b0:439:4c1e:d810 with SMTP id 5b1f17b1804b1-441bb856814mr17471845e9.9.1746181422163; Fri, 02 May 2025 03:23:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 7/9] rust: replace c_str! with c"" literals Date: Fri, 2 May 2025 12:23:20 +0200 Message-ID: <20250502102323.104815-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502102323.104815-1-pbonzini@redhat.com> References: <20250502102323.104815-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.644, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1746181509797019100 Signed-off-by: Paolo Bonzini Reviewed-by: Manos Pitsidianakis --- docs/devel/rust.rst | 8 +--- rust/Cargo.lock | 1 - rust/hw/char/pl011/src/device_class.rs | 11 +++-- rust/hw/char/pl011/src/lib.rs | 6 +-- rust/hw/timer/hpet/src/hpet.rs | 19 ++++---- rust/hw/timer/hpet/src/lib.rs | 4 +- rust/qemu-api/meson.build | 1 - rust/qemu-api/src/c_str.rs | 61 -------------------------- rust/qemu-api/src/cell.rs | 4 +- rust/qemu-api/src/lib.rs | 1 - rust/qemu-api/src/vmstate.rs | 2 +- rust/qemu-api/tests/tests.rs | 9 ++-- rust/qemu-api/tests/vmstate_tests.rs | 15 +++---- 13 files changed, 32 insertions(+), 110 deletions(-) delete mode 100644 rust/qemu-api/src/c_str.rs diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index 8dad90fdf98..cae2634a2e9 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -78,14 +78,9 @@ are missing: =20 * Generic Associated Types (1.65.0) =20 -* ``CStr::from_bytes_with_nul()`` as a ``const`` function (1.72.0). - * "Return position ``impl Trait`` in Traits" (1.75.0, blocker for including the pinned-init create). =20 -* ``c"" literals`` (stable in 1.77.0). QEMU provides a ``c_str!()`` macro - to define ``CStr`` constants easily - * inline const expression (stable in 1.79.0), currently worked around with associated constants in the ``FnCall`` trait. =20 @@ -168,7 +163,6 @@ module status ``bitops`` complete ``callbacks`` complete ``cell`` stable -``c_str`` complete ``errno`` complete ``irq`` complete ``memory`` stable @@ -425,7 +419,7 @@ Adding dependencies Generally, the set of dependent crates is kept small. Think twice before adding a new external crate, especially if it comes with a large set of dependencies itself. Sometimes QEMU only needs a small subset of the -functionality; see for example QEMU's ``assertions`` or ``c_str`` modules. +functionality; see for example QEMU's ``assertions`` module. =20 On top of this recommendation, adding external crates to QEMU is a slightly complicated process, mostly due to the need to teach Meson how diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 2ebf0a11ea4..13d580c693b 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -108,7 +108,6 @@ version =3D "0.1.0" dependencies =3D [ "libc", "qemu_api_macros", - "version_check", ] =20 [[package]] diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/sr= c/device_class.rs index cd2dc33c207..d328d846323 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -9,7 +9,6 @@ =20 use qemu_api::{ bindings::{qdev_prop_bool, qdev_prop_chr}, - c_str, prelude::*, vmstate::VMStateDescription, vmstate_clock, vmstate_fields, vmstate_of, vmstate_struct, vmstate_sub= sections, vmstate_unused, @@ -25,7 +24,7 @@ extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> = bool { =20 /// Migration subsection for [`PL011State`] clock. static VMSTATE_PL011_CLOCK: VMStateDescription =3D VMStateDescription { - name: c_str!("pl011/clock").as_ptr(), + name: c"pl011/clock".as_ptr(), version_id: 1, minimum_version_id: 1, needed: Some(pl011_clock_needed), @@ -46,7 +45,7 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, versio= n_id: c_int) -> c_int { } =20 static VMSTATE_PL011_REGS: VMStateDescription =3D VMStateDescription { - name: c_str!("pl011/regs").as_ptr(), + name: c"pl011/regs".as_ptr(), version_id: 2, minimum_version_id: 2, fields: vmstate_fields! { @@ -70,7 +69,7 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, versio= n_id: c_int) -> c_int { }; =20 pub static VMSTATE_PL011: VMStateDescription =3D VMStateDescription { - name: c_str!("pl011").as_ptr(), + name: c"pl011".as_ptr(), version_id: 2, minimum_version_id: 2, post_load: Some(pl011_post_load), @@ -87,14 +86,14 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, vers= ion_id: c_int) -> c_int { qemu_api::declare_properties! { PL011_PROPERTIES, qemu_api::define_property!( - c_str!("chardev"), + c"chardev", PL011State, char_backend, unsafe { &qdev_prop_chr }, CharBackend ), qemu_api::define_property!( - c_str!("migrate-clk"), + c"migrate-clk", PL011State, migrate_clock, unsafe { &qdev_prop_bool }, diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index dbae76991c9..5c4fbc9d148 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -12,13 +12,11 @@ //! See [`PL011State`](crate::device::PL011State) for the device model typ= e and //! the [`registers`] module for register types. =20 -use qemu_api::c_str; - mod device; mod device_class; mod registers; =20 pub use device::pl011_create; =20 -pub const TYPE_PL011: &::std::ffi::CStr =3D c_str!("pl011"); -pub const TYPE_PL011_LUMINARY: &::std::ffi::CStr =3D c_str!("pl011_luminar= y"); +pub const TYPE_PL011: &::std::ffi::CStr =3D c"pl011"; +pub const TYPE_PL011_LUMINARY: &::std::ffi::CStr =3D c"pl011_luminary"; diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs index 72609c31f44..6afef083a57 100644 --- a/rust/hw/timer/hpet/src/hpet.rs +++ b/rust/hw/timer/hpet/src/hpet.rs @@ -14,7 +14,6 @@ address_space_memory, address_space_stl_le, qdev_prop_bit, qdev_pr= op_bool, qdev_prop_uint32, qdev_prop_uint8, }, - c_str, cell::{BqlCell, BqlRefCell}, irq::InterruptSource, memory::{ @@ -908,7 +907,7 @@ impl ObjectImpl for HPETState { qemu_api::declare_properties! { HPET_PROPERTIES, qemu_api::define_property!( - c_str!("timers"), + c"timers", HPETState, num_timers, unsafe { &qdev_prop_uint8 }, @@ -916,7 +915,7 @@ impl ObjectImpl for HPETState { default =3D HPET_MIN_TIMERS ), qemu_api::define_property!( - c_str!("msi"), + c"msi", HPETState, flags, unsafe { &qdev_prop_bit }, @@ -925,7 +924,7 @@ impl ObjectImpl for HPETState { default =3D false, ), qemu_api::define_property!( - c_str!("hpet-intcap"), + c"hpet-intcap", HPETState, int_route_cap, unsafe { &qdev_prop_uint32 }, @@ -933,7 +932,7 @@ impl ObjectImpl for HPETState { default =3D 0 ), qemu_api::define_property!( - c_str!("hpet-offset-saved"), + c"hpet-offset-saved", HPETState, hpet_offset_saved, unsafe { &qdev_prop_bool }, @@ -974,7 +973,7 @@ impl ObjectImpl for HPETState { } =20 static VMSTATE_HPET_RTC_IRQ_LEVEL: VMStateDescription =3D VMStateDescripti= on { - name: c_str!("hpet/rtc_irq_level").as_ptr(), + name: c"hpet/rtc_irq_level".as_ptr(), version_id: 1, minimum_version_id: 1, needed: Some(hpet_rtc_irq_level_needed), @@ -985,7 +984,7 @@ impl ObjectImpl for HPETState { }; =20 static VMSTATE_HPET_OFFSET: VMStateDescription =3D VMStateDescription { - name: c_str!("hpet/offset").as_ptr(), + name: c"hpet/offset".as_ptr(), version_id: 1, minimum_version_id: 1, needed: Some(hpet_offset_needed), @@ -996,7 +995,7 @@ impl ObjectImpl for HPETState { }; =20 static VMSTATE_HPET_TIMER: VMStateDescription =3D VMStateDescription { - name: c_str!("hpet_timer").as_ptr(), + name: c"hpet_timer".as_ptr(), version_id: 1, minimum_version_id: 1, fields: vmstate_fields! { @@ -1011,10 +1010,10 @@ impl ObjectImpl for HPETState { ..Zeroable::ZERO }; =20 -const VALIDATE_TIMERS_NAME: &CStr =3D c_str!("num_timers must match"); +const VALIDATE_TIMERS_NAME: &CStr =3D c"num_timers must match"; =20 static VMSTATE_HPET: VMStateDescription =3D VMStateDescription { - name: c_str!("hpet").as_ptr(), + name: c"hpet".as_ptr(), version_id: 2, minimum_version_id: 1, pre_save: Some(hpet_pre_save), diff --git a/rust/hw/timer/hpet/src/lib.rs b/rust/hw/timer/hpet/src/lib.rs index 5e7c961c289..1954584a87e 100644 --- a/rust/hw/timer/hpet/src/lib.rs +++ b/rust/hw/timer/hpet/src/lib.rs @@ -7,9 +7,7 @@ //! This library implements a device model for the IA-PC HPET (High //! Precision Event Timers) device in QEMU. =20 -use qemu_api::c_str; - pub mod fw_cfg; pub mod hpet; =20 -pub const TYPE_HPET: &::std::ffi::CStr =3D c_str!("hpet"); +pub const TYPE_HPET: &::std::ffi::CStr =3D c"hpet"; diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 95e65643ae1..1696df705bf 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -20,7 +20,6 @@ _qemu_api_rs =3D static_library( 'src/callbacks.rs', 'src/cell.rs', 'src/chardev.rs', - 'src/c_str.rs', 'src/errno.rs', 'src/irq.rs', 'src/memory.rs', diff --git a/rust/qemu-api/src/c_str.rs b/rust/qemu-api/src/c_str.rs deleted file mode 100644 index 3fa61b59c76..00000000000 --- a/rust/qemu-api/src/c_str.rs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2024 Red Hat, Inc. -// Author(s): Paolo Bonzini -// SPDX-License-Identifier: GPL-2.0-or-later - -#![doc(hidden)] -//! This module provides a macro to define a constant of type -//! [`CStr`](std::ffi::CStr), for compatibility with versions of -//! Rust that lack `c""` literals. -//! -//! Documentation is hidden because it only exposes macros, which -//! are exported directly from `qemu_api`. - -#[macro_export] -/// Given a string constant _without_ embedded or trailing NULs, return -/// a `CStr`. -/// -/// Needed for compatibility with Rust <1.77. -macro_rules! c_str { - ($str:expr) =3D> {{ - const STRING: &str =3D concat!($str, "\0"); - const BYTES: &[u8] =3D STRING.as_bytes(); - - // "for" is not allowed in const context... oh well, - // everybody loves some lisp. This could be turned into - // a procedural macro if this is a problem; alternatively - // Rust 1.72 makes CStr::from_bytes_with_nul a const function. - const fn f(b: &[u8], i: usize) { - if i =3D=3D b.len() - 1 { - } else if b[i] =3D=3D 0 { - panic!("c_str argument contains NUL") - } else { - f(b, i + 1) - } - } - f(BYTES, 0); - - // SAFETY: absence of NULs apart from the final byte was checked a= bove - unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(BYTES) } - }}; -} - -#[cfg(test)] -mod tests { - use std::ffi::CStr; - - use crate::c_str; - - #[test] - fn test_cstr_macro() { - let good =3D c_str!("=F0=9F=A6=80"); - let good_bytes =3D b"\xf0\x9f\xa6\x80\0"; - assert_eq!(good.to_bytes_with_nul(), good_bytes); - } - - #[test] - fn test_cstr_macro_const() { - const GOOD: &CStr =3D c_str!("=F0=9F=A6=80"); - const GOOD_BYTES: &[u8] =3D b"\xf0\x9f\xa6\x80\0"; - assert_eq!(GOOD.to_bytes_with_nul(), GOOD_BYTES); - } -} diff --git a/rust/qemu-api/src/cell.rs b/rust/qemu-api/src/cell.rs index ab0785a2692..b35d19723f6 100644 --- a/rust/qemu-api/src/cell.rs +++ b/rust/qemu-api/src/cell.rs @@ -77,13 +77,13 @@ //! //! ``` //! # use qemu_api::prelude::*; -//! # use qemu_api::{c_str, cell::BqlRefCell, irq::InterruptSource, irq::I= RQState}; +//! # use qemu_api::{cell::BqlRefCell, irq::InterruptSource, irq::IRQState= }; //! # use qemu_api::{sysbus::SysBusDevice, qom::Owned, qom::ParentField}; //! # const N_GPIOS: usize =3D 8; //! # struct PL061Registers { /* ... */ } //! # unsafe impl ObjectType for PL061State { //! # type Class =3D ::Class; -//! # const TYPE_NAME: &'static std::ffi::CStr =3D c_str!("pl061"); +//! # const TYPE_NAME: &'static std::ffi::CStr =3D c"pl061"; //! # } //! struct PL061State { //! parent_obj: ParentField, diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 90c19636660..234a94e3c29 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -15,7 +15,6 @@ =20 pub mod assertions; pub mod bitops; -pub mod c_str; pub mod callbacks; pub mod cell; pub mod chardev; diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 9a6e6b734b9..389f1a6f62a 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -426,7 +426,7 @@ unsafe impl<$base> VMState for $type where $base: VMSta= te $($where)* { macro_rules! vmstate_unused { ($size:expr) =3D> {{ $crate::bindings::VMStateField { - name: $crate::c_str!("unused").as_ptr(), + name: c"unused".as_ptr(), size: $size, info: unsafe { ::core::ptr::addr_of!($crate::bindings::vmstate= _info_unused_buffer) }, flags: $crate::bindings::VMStateFlags::VMS_BUFFER, diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index d045808c3a8..a658a49fcfd 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -6,7 +6,6 @@ =20 use qemu_api::{ bindings::{module_call_init, module_init_type, qdev_prop_bool}, - c_str, cell::{self, BqlCell}, declare_properties, define_property, prelude::*, @@ -21,7 +20,7 @@ =20 // Test that macros can compile. pub static VMSTATE: VMStateDescription =3D VMStateDescription { - name: c_str!("name").as_ptr(), + name: c"name".as_ptr(), unmigratable: true, ..Zeroable::ZERO }; @@ -48,7 +47,7 @@ pub fn class_init(self: &mut DummyClass) { declare_properties! { DUMMY_PROPERTIES, define_property!( - c_str!("migrate-clk"), + c"migrate-clk", DummyState, migrate_clock, unsafe { &qdev_prop_bool }, @@ -58,7 +57,7 @@ pub fn class_init(self: &mut DummyClass) { =20 unsafe impl ObjectType for DummyState { type Class =3D DummyClass; - const TYPE_NAME: &'static CStr =3D c_str!("dummy"); + const TYPE_NAME: &'static CStr =3D c"dummy"; } =20 impl ObjectImpl for DummyState { @@ -92,7 +91,7 @@ pub struct DummyChildClass { =20 unsafe impl ObjectType for DummyChildState { type Class =3D DummyChildClass; - const TYPE_NAME: &'static CStr =3D c_str!("dummy_child"); + const TYPE_NAME: &'static CStr =3D c"dummy_child"; } =20 impl ObjectImpl for DummyChildState { diff --git a/rust/qemu-api/tests/vmstate_tests.rs b/rust/qemu-api/tests/vms= tate_tests.rs index cc3527a9b6a..ad0fc5cd5dd 100644 --- a/rust/qemu-api/tests/vmstate_tests.rs +++ b/rust/qemu-api/tests/vmstate_tests.rs @@ -14,7 +14,6 @@ vmstate_info_bool, vmstate_info_int32, vmstate_info_int64, vmstate= _info_int8, vmstate_info_uint64, vmstate_info_uint8, vmstate_info_unused_buffe= r, VMStateFlags, }, - c_str, cell::{BqlCell, Opaque}, impl_vmstate_forward, vmstate::{VMStateDescription, VMStateField}, @@ -43,7 +42,7 @@ struct FooA { } =20 static VMSTATE_FOOA: VMStateDescription =3D VMStateDescription { - name: c_str!("foo_a").as_ptr(), + name: c"foo_a".as_ptr(), version_id: 1, minimum_version_id: 1, fields: vmstate_fields! { @@ -173,7 +172,7 @@ fn validate_foob(_state: &FooB, _version_id: u8) -> boo= l { } =20 static VMSTATE_FOOB: VMStateDescription =3D VMStateDescription { - name: c_str!("foo_b").as_ptr(), + name: c"foo_b".as_ptr(), version_id: 2, minimum_version_id: 1, fields: vmstate_fields! { @@ -337,7 +336,7 @@ struct FooC { } =20 static VMSTATE_FOOC: VMStateDescription =3D VMStateDescription { - name: c_str!("foo_c").as_ptr(), + name: c"foo_c".as_ptr(), version_id: 3, minimum_version_id: 1, fields: vmstate_fields! { @@ -452,13 +451,13 @@ fn validate_food_2(_state: &FooD, _version_id: u8) ->= bool { } =20 static VMSTATE_FOOD: VMStateDescription =3D VMStateDescription { - name: c_str!("foo_d").as_ptr(), + name: c"foo_d".as_ptr(), version_id: 3, minimum_version_id: 1, fields: vmstate_fields! { - vmstate_validate!(FooD, c_str!("foo_d_0"), FooD::validate_food_0), - vmstate_validate!(FooD, c_str!("foo_d_1"), FooD::validate_food_1), - vmstate_validate!(FooD, c_str!("foo_d_2"), validate_food_2), + vmstate_validate!(FooD, c"foo_d_0", FooD::validate_food_0), + vmstate_validate!(FooD, c"foo_d_1", FooD::validate_food_1), + vmstate_validate!(FooD, c"foo_d_2", validate_food_2), }, ..Zeroable::ZERO }; --=20 2.49.0 From nobody Sat Nov 15 22:25:04 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1746181513; cv=none; d=zohomail.com; s=zohoarc; b=I4VHavZkdCeVIFyESY2DsxGhKS/uzj+L0S0K5CfYnHi+ZpUUehiro2S7oBtCr3gYRxrjjf9qWLijguGQpO2D6VAY6ckYiBIA6Xs7vBGhp5xPvXfjgolEhJZ3wZK/Az6lwsys1OmOdyMOCYeJE3IL3Rn7pvcD0jXb3409MLo0f7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746181513; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yjgeAmjjptt4bC7ZVHkPoYUwGWimgF5Hq5dOUJ/c8mk=; b=J0bzrS3wyGo395uorN//qZMjgXDuF42HmCznNaXM6VBsuAM6K5a7ocWv/feqTyPrXtri+zuLUDes5jfNxEzkfWBC8+uwwAYibzb0HzLJGcz5cFVCoeS3rLmQmZb+mLmkbtnf/wbJf5jEae7jzBFnOkxKzqPPLOvK9UkFctfmcjc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1746181513573133.55301360058274; Fri, 2 May 2025 03:25:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uAnYj-0001Ht-5p; Fri, 02 May 2025 06:23:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYd-0001GP-L7 for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYb-0000jp-N6 for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:51 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-322-rxCBwC-PMH-5uL9iMFqHkw-1; Fri, 02 May 2025 06:23:47 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43f251dc364so10000845e9.2 for ; Fri, 02 May 2025 03:23:47 -0700 (PDT) Received: from [192.168.10.48] ([151.95.54.106]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-441b89cc67fsm40682395e9.5.2025.05.02.03.23.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 03:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746181429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yjgeAmjjptt4bC7ZVHkPoYUwGWimgF5Hq5dOUJ/c8mk=; b=ix9U6cF7UEn5alfIpKjudz1TX4t7jV4Yolsi3rCpzw0xyVbMqgMAUQPkF8SFpsAdwXCjD2 7KL/7rf0hyEPKhqg8KYZudUlSLCWym/AS48gGdXsnnNxDILQWNxc3Qip7PYfNDiJO60BsZ YohupM9IWKONkYxlxxWfx9oGEPzt3N8= X-MC-Unique: rxCBwC-PMH-5uL9iMFqHkw-1 X-Mimecast-MFC-AGG-ID: rxCBwC-PMH-5uL9iMFqHkw_1746181427 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746181426; x=1746786226; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yjgeAmjjptt4bC7ZVHkPoYUwGWimgF5Hq5dOUJ/c8mk=; b=QQOx8sKmcJzsEi7qegTc7SbPJSus4k78fO5vJsrOb9Gu66tshUIi6fS7ke2qAY/coX 9DEbwROWYim8k7vEK/4qJ/Mgx1lx59fDogOCsuoFTomxaOcIgitSLEtATP5Ni3wK+XUf b13wl6hiKcpM+IFFrnwL11pFuBP9vSN1DaKYA+e1ucq7TPOH1JPyP0odxI3E5GzZ5FXd nZureASX8tDEqDA98xh3EovsxCHcxtgYKbZjDbRrI/whdXGeSlCjjh1E78SIUJmLw7mz DJvPmRjgAxqPYzs7/pz0FgvRHwVO3hZV/uS9tB2HiUS9p9IfB4l5u8HqTqtANg8ORG7A BoDg== X-Gm-Message-State: AOJu0Yw6XLocPqtr7+PlZSL+TSqI7jCUfTUfrAuCupEY6zm6yI6bDvyA H88nLeHHoSKoQdUDBMdy+Dx8liLm+zZm2UWo/T1ntNy2TCOrTfsmchKUUXc+85mVTwz3BD9Z7Uo nZN4YeMpBcP8/JaBGnB9S+8TWNyMTOHuJONgHt2jKd7q98jYvVqwpUCU8ugp5XPqtdZMFF4Pao1 g+f+PDrfcOus/ISt4C6mpNHKEZUPFhHU+cFY/F X-Gm-Gg: ASbGncsrB8GpwApbcbCb3UEnA2k6nEc+FRXXnglEx5pV9cmy8yJUi5O/h1TTKhoE/Ix Z1XWpxTdnCqBS/XconpYq9zGi0IqUXlkRP7OxDzBXBYBewujTN+QVEh9VLo+/WrfmisILCeT3Ql 9qdEJ0mTd1eXgzg87w2vbq4UH9PRzpETUeIujX2SlPoC/XnyjKD+iaEOEflUmL2i2v87ISRy7Q4 b2kWDIF9aRzxxaOtnt+dSiz6fDVBDY0JX3ZCSaiO9n1hKwAGUcRz09sRpJOovrwehvSbDeUtB2R w9rgEtdA2x2iO4E= X-Received: by 2002:a05:600c:4e94:b0:43b:ce3c:19d0 with SMTP id 5b1f17b1804b1-441bbf37ee3mr12825455e9.29.1746181425730; Fri, 02 May 2025 03:23:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpLIh/UxlZVWi7hqjePlhUGWWx01PChVRCAeQUiUz1sUQyw1j2XB65NV17GrXgkMCdfNHcQw== X-Received: by 2002:a05:600c:4e94:b0:43b:ce3c:19d0 with SMTP id 5b1f17b1804b1-441bbf37ee3mr12825255e9.29.1746181425294; Fri, 02 May 2025 03:23:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 8/9] rust: enable clippy::ptr_cast_constness Date: Fri, 2 May 2025 12:23:21 +0200 Message-ID: <20250502102323.104815-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502102323.104815-1-pbonzini@redhat.com> References: <20250502102323.104815-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.644, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1746181515716019100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Manos Pitsidianakis --- docs/devel/rust.rst | 2 -- rust/Cargo.toml | 2 +- rust/clippy.toml | 2 +- rust/hw/char/pl011/Cargo.toml | 2 +- rust/hw/timer/hpet/Cargo.toml | 2 +- rust/hw/timer/hpet/src/hpet.rs | 2 +- rust/qemu-api-macros/Cargo.toml | 2 +- rust/qemu-api/Cargo.toml | 2 +- rust/qemu-api/src/cell.rs | 2 +- rust/qemu-api/src/chardev.rs | 2 +- rust/qemu-api/src/qom.rs | 4 ++-- rust/qemu-api/src/timer.rs | 2 +- 12 files changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index cae2634a2e9..92550d9d581 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -74,8 +74,6 @@ Supported tools QEMU supports rustc version 1.63.0 and newer. Notably, the following feat= ures are missing: =20 -* ``cast_mut()``/``cast_const()`` (1.65.0). Use ``as`` instead. - * Generic Associated Types (1.65.0) =20 * "Return position ``impl Trait`` in Traits" (1.75.0, blocker for including diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ea2a85a1d07..bcf43718cf9 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -64,6 +64,7 @@ no_effect_underscore_binding =3D "deny" option_option =3D "deny" or_fun_call =3D "deny" ptr_as_ptr =3D "deny" +ptr_cast_constness =3D "deny" pub_underscore_fields =3D "deny" redundant_clone =3D "deny" redundant_closure_for_method_calls =3D "deny" @@ -85,7 +86,6 @@ used_underscore_binding =3D "deny" =20 # nice to have, but cannot be enabled yet #wildcard_imports =3D "deny" # still have many bindings::* imports -#ptr_cast_constness =3D "deny" # needs 1.65.0 for cast_mut()/cast_const() =20 # these may have false positives #option_if_let_else =3D "deny" diff --git a/rust/clippy.toml b/rust/clippy.toml index 5d190f91dec..933e46a2ffb 100644 --- a/rust/clippy.toml +++ b/rust/clippy.toml @@ -1,2 +1,2 @@ doc-valid-idents =3D ["PrimeCell", ".."] -msrv =3D "1.63.0" +msrv =3D "1.77.0" diff --git a/rust/hw/char/pl011/Cargo.toml b/rust/hw/char/pl011/Cargo.toml index f2296cad58b..4766badd73e 100644 --- a/rust/hw/char/pl011/Cargo.toml +++ b/rust/hw/char/pl011/Cargo.toml @@ -9,7 +9,7 @@ resolver =3D "2" publish =3D false keywords =3D [] categories =3D [] -rust-version =3D "1.63.0" +rust-version =3D "1.77.0" =20 [lib] crate-type =3D ["staticlib"] diff --git a/rust/hw/timer/hpet/Cargo.toml b/rust/hw/timer/hpet/Cargo.toml index 147f216e725..c6c48b2f887 100644 --- a/rust/hw/timer/hpet/Cargo.toml +++ b/rust/hw/timer/hpet/Cargo.toml @@ -5,7 +5,7 @@ edition =3D "2021" authors =3D ["Zhao Liu "] license =3D "GPL-2.0-or-later" description =3D "IA-PC High Precision Event Timer emulation in Rust" -rust-version =3D "1.63.0" +rust-version =3D "1.77.0" =20 [lib] crate-type =3D ["staticlib"] diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs index 6afef083a57..779681d6509 100644 --- a/rust/hw/timer/hpet/src/hpet.rs +++ b/rust/hw/timer/hpet/src/hpet.rs @@ -218,7 +218,7 @@ fn init(&mut self, index: u8, state: &HPETState) { // SAFETY: the HPETTimer will only be used after the timer // is initialized below. qemu_timer: unsafe { Timer::new() }, - state: NonNull::new(state as *const _ as *mut _).unwrap(), + state: NonNull::new((state as *const HPETState).cast_mut()).un= wrap(), config: 0, cmp: 0, fsb: 0, diff --git a/rust/qemu-api-macros/Cargo.toml b/rust/qemu-api-macros/Cargo.t= oml index 89dee1cfb39..8344b1f939d 100644 --- a/rust/qemu-api-macros/Cargo.toml +++ b/rust/qemu-api-macros/Cargo.toml @@ -9,7 +9,7 @@ resolver =3D "2" publish =3D false keywords =3D [] categories =3D [] -rust-version =3D "1.63.0" +rust-version =3D "1.77.0" =20 [lib] proc-macro =3D true diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index c5b7b2464e9..be00ef1ae9b 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -12,7 +12,7 @@ resolver =3D "2" publish =3D false keywords =3D [] categories =3D [] -rust-version =3D "1.63.0" +rust-version =3D "1.77.0" =20 [dependencies] qemu_api_macros =3D { path =3D "../qemu-api-macros" } diff --git a/rust/qemu-api/src/cell.rs b/rust/qemu-api/src/cell.rs index b35d19723f6..05ce09f6cb6 100644 --- a/rust/qemu-api/src/cell.rs +++ b/rust/qemu-api/src/cell.rs @@ -1016,7 +1016,7 @@ pub const fn as_mut_ptr(&self) -> *mut T { =20 /// Returns a raw pointer to the opaque data. pub const fn as_ptr(&self) -> *const T { - self.as_mut_ptr() as *const _ + self.as_mut_ptr().cast_const() } =20 /// Returns a raw pointer to the opaque data that can be passed to a diff --git a/rust/qemu-api/src/chardev.rs b/rust/qemu-api/src/chardev.rs index 146a4852da3..6e0590d758e 100644 --- a/rust/qemu-api/src/chardev.rs +++ b/rust/qemu-api/src/chardev.rs @@ -160,7 +160,7 @@ pub fn enable_handlers< receive_cb, event_cb, None, - (owner as *const T as *mut T).cast::(), + (owner as *const T).cast_mut().cast::(), core::ptr::null_mut(), true, ); diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs index 6929e4d33ae..9766a607e73 100644 --- a/rust/qemu-api/src/qom.rs +++ b/rust/qemu-api/src/qom.rs @@ -388,7 +388,7 @@ fn as_mut_ptr(&self) -> *mut U { #[allow(clippy::as_ptr_cast_mut)] { - self.as_ptr::() as *mut _ + self.as_ptr::().cast_mut() } } } @@ -637,7 +637,7 @@ pub unsafe fn from_raw(ptr: *const T) -> Self { // SAFETY NOTE: while NonNull requires a mutable pointer, only // Deref is implemented so the pointer passed to from_raw // remains const - Owned(NonNull::new(ptr as *mut T).unwrap()) + Owned(NonNull::new(ptr.cast_mut()).unwrap()) } =20 /// Obtain a raw C pointer from a reference. `src` is consumed diff --git a/rust/qemu-api/src/timer.rs b/rust/qemu-api/src/timer.rs index d697fd742bc..868bd88575f 100644 --- a/rust/qemu-api/src/timer.rs +++ b/rust/qemu-api/src/timer.rs @@ -81,7 +81,7 @@ pub fn init_full<'timer, 'opaque: 'timer, T, F>( scale as c_int, attributes as c_int, Some(timer_cb), - (opaque as *const T).cast::() as *mut c_void, + (opaque as *const T).cast::().cast_mut(), ) } } --=20 2.49.0 From nobody Sat Nov 15 22:25:04 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1746181508; cv=none; d=zohomail.com; s=zohoarc; b=K9c9A0MF5ReMBiJh+sNSN0WdujaLsOIlonfO2yg1wli5Dz5HocwyRe5lKDMRq+JoPyKhkhQweD4OCVIYvPD6frnnP9Pn9kWgD/3lXIAT3ntMp6WuW340Eo0xcn5NPGaxChcn0hkop+BKKGdidoRXjidOnyLmzsuMmq9BDoHhtpo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746181508; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QzRX5l4/8S+wmKPEV9zweUNzezcyi85OyNacxdgQyIo=; b=cjH5kkKyRPJIN9vMJNQm0zGMyhnfjSQvnpA0iOs13ly9USqzIDwRGLVddPLTljoWmvDZavWEVpoa1TyWPcDLgM5uz4gMPoMuHpoprMXTVnpLnA8/55bajojT3i4ZJKYNWiUoWYeqaJq9PQGfoRQUUaYLO0+iUTOK2duv3cAfcmw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1746181508228770.1299668828153; Fri, 2 May 2025 03:25:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uAnYk-0001J1-UG; Fri, 02 May 2025 06:23:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYg-0001H0-Oc for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAnYe-0000kQ-MI for qemu-devel@nongnu.org; Fri, 02 May 2025 06:23:54 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-191-1ovr3I_gNbifhneQ5DwSQA-1; Fri, 02 May 2025 06:23:50 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-44059976a1fso8493845e9.1 for ; Fri, 02 May 2025 03:23:50 -0700 (PDT) Received: from [192.168.10.48] ([151.95.54.106]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a099ae0bb5sm1727497f8f.7.2025.05.02.03.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 03:23:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746181431; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QzRX5l4/8S+wmKPEV9zweUNzezcyi85OyNacxdgQyIo=; b=cA25XMwGKfqdWRXDpPs4fkStFhg7vNYuDSFuAqDWqGyMtRIAj8TJkq+d1SHzsgypIpYK/q cus5UuivNpAbBX2kxXFKXjHsWuhHNZQCJM8JJK/RFAliImbf0gcHShWPVMk962cgWWA4Tl bn2Wyyr/gM9H/PEbwQz78oO0YbJv/uo= X-MC-Unique: 1ovr3I_gNbifhneQ5DwSQA-1 X-Mimecast-MFC-AGG-ID: 1ovr3I_gNbifhneQ5DwSQA_1746181429 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746181428; x=1746786228; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QzRX5l4/8S+wmKPEV9zweUNzezcyi85OyNacxdgQyIo=; b=Mn2WkalZU5paOGaYa9XomIAfifoMFhONCMVe+2+maTb5m1CLr15tKTKGOOUM8lgYMy IIBuzmmGRI9i3wCd6OQ3xShSx6buJDNvOHAXS1jOkivjbewH7I0PLScVt/AaXJjRYBm8 4KmYYWAZ88OurdE56Ziv6ySYJ+LeH7WtMynuQZaIWWESLNyQ0IsrmTaTtiyWq9FEMAmH kKdWvH1fyz2WftsN7rBEoEnhT+fZk22PhAAbhfEx//qoYIhhvhz/PfbZwZ1SNE0OF2XF tzwG5gw4Q7Lls0cFP45p4jlOSxws9NSO5n+AbTcqDZUsx5DsLgFnU+bRW4I+bjeF6Y2g 9ngA== X-Gm-Message-State: AOJu0YyMAltP9l1p2grPWKR0o7trezUKtw1AnHuUnRpzNJjbPzkFU8s8 YgG3nvwDAK3ob+DTg7psE+Fznere+vJgs98nnrabNiRCKAVGKxkBUKGyBjZiJd6pbeI20Hekfe8 147FRscIUNKHdfeat3DTygjNBz7kwc7chV096E73TowQsp3OdOS5rZGd9g1HuFDAjeDSD7Oms8J v31ti+wwbrXfA0jTuytki1FjOHdtVrG3QeZzsk X-Gm-Gg: ASbGncvKwsOioMM/mikopBs+UzacCUhlH2UKC9e1qSL+bwC/g9OyUY+j8RY5ePDRPJB mpmg/uxkIIbkcpDT7SG3e7f5aLs5v1LTYg68vj5t+yZySWHi7ZTQ7EXYtSx/A58h+YEL2M+0LCB ehekNawKxgbIkrN/rYzCbAAqMD+paZJkSG1oIorAZ2TnZgXJFKtB9rXlmn/l6EVb1zZYhxXIy6M xW7HzdVr9E31+yRopuc6QZA+nve2vEhnddAlOhs6JV8DqOQw2UoQTlYEg1Eu1IjAosSuhYv8nyG 9Ug2FArIsNATAI8= X-Received: by 2002:a05:6000:1e51:b0:3a0:8819:3b69 with SMTP id ffacd0b85a97d-3a099ad61afmr1230259f8f.21.1746181428239; Fri, 02 May 2025 03:23:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMCuL9/GFEL0oohdP93JrNdFJ3TfQpoPEVsACDzA5eV9MT/4vPp30JD/56X+ULw6GdjstbZQ== X-Received: by 2002:a05:6000:1e51:b0:3a0:8819:3b69 with SMTP id ffacd0b85a97d-3a099ad61afmr1230237f8f.21.1746181427702; Fri, 02 May 2025 03:23:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 9/9] docs: rust: update for newer minimum supported version Date: Fri, 2 May 2025 12:23:22 +0200 Message-ID: <20250502102323.104815-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250502102323.104815-1-pbonzini@redhat.com> References: <20250502102323.104815-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.644, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1746181509598019100 Content-Type: text/plain; charset="utf-8" Remove leftover notes for Rust changes between 1.63.0 and 1.77.0. Signed-off-by: Paolo Bonzini --- docs/devel/rust.rst | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index 92550d9d581..4de86375021 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -71,14 +71,9 @@ Building Rust code with ``--enable-modules`` is not supp= orted yet. Supported tools ''''''''''''''' =20 -QEMU supports rustc version 1.63.0 and newer. Notably, the following feat= ures +QEMU supports rustc version 1.77.0 and newer. Notably, the following feat= ures are missing: =20 -* Generic Associated Types (1.65.0) - -* "Return position ``impl Trait`` in Traits" (1.75.0, blocker for including - the pinned-init create). - * inline const expression (stable in 1.79.0), currently worked around with associated constants in the ``FnCall`` trait. =20 @@ -103,12 +98,6 @@ are missing: =20 __ https://github.com/rust-lang/rust/pull/125258 =20 -It is expected that QEMU will advance its minimum supported version of -rustc to 1.77.0 as soon as possible; as of January 2025, blockers -for that right now are Debian bookworm and 32-bit MIPS processors. -This unfortunately means that references to statics in constants will -remain an issue. - QEMU also supports version 0.60.x of bindgen, which is missing option ``--generate-cstr``. This option requires version 0.66.x and will be adopted as soon as supporting these older versions is not necessary --=20 2.49.0