Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp91397lqp; Thu, 4 Apr 2024 07:53:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW+X4mlWWsWDTiNLG3sDZoNyXvnaPR7fVHQiBNQSG0ATuoUp5pw1lDOmsFC5YDJ/QibchbwvqLto20+qe+wPldiY4SJEDHA00Zk4BDw2w== X-Google-Smtp-Source: AGHT+IGtzzJih5aWVEEv5K9tGV2kAUO6AeK2tKp06+hGY3D/ABQg8a34vuSqqpU46TDMAhfXxE3e X-Received: by 2002:a17:907:9729:b0:a46:94c7:49a5 with SMTP id jg41-20020a170907972900b00a4694c749a5mr2261280ejc.40.1712242421625; Thu, 04 Apr 2024 07:53:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712242421; cv=pass; d=google.com; s=arc-20160816; b=PiFrGRkpll2BprLZL0yHwGXNTakndM1neo+Aez40S2Sb+69OTI4QcmFNwtz0CIFryD Sv7LOvjDH9Mm++k0OuXNT9On9YaQQ5TUNIY4MGPbnQdkL2G2M8MdelikROuZTjguMiJ9 CVZYfTw7XRu5FpRIrb/W875V58RFDvL+x0TXpmHEB7CHoentvDaHoqIzMr/wLP2UGyZE z+W83VtuFz2Edt+b16roKPGjd8Nn4j3RObJHA3m+4ajn9beXPyv4JO2xQgTLkIVH/FD3 kT7kOLQN3r6l0M9u3zzZ3CcwVcoaklkS4cMPTkMm0/bZwdN2F6t7lcS81ZFxElrLWAEm w2Pg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=KHjrZ7L/o/5RAJWobPfw5bBLIJX2aXSEBFmB1P0i8VM=; fh=NVLHYNxTFxZg90CuAUl5EFs9nACqSf1JvKaCbeMsn7U=; b=Bd5OGXTr9nKQ0wIKlNRJ87+RFYRgR0zZ1o6SqD6Xq3aJtNUpU2raJvjvV9IB7WmkTV AmKRP4h6kKa0H2uB4EwudKhlorWMwqC689144ZR8vnvciKMD2TiwlxClq1id6tT5u7xl iOg9Xemn6RJlhyRZPEs+B69YZsbSFjKOEVFlXPlMokakVgmQpRmee6mDZeSPzrHwIlf3 9Ico9afUrqHwehVa46L7Uw9udfbl1gzU645sMIa6tPWlwbBqDyCm/UjfqCokpTEJCCUI 8i1AWn6pVD7NrgIZW4Cdsw+0wAff97XnLT2/7VherKY2yZB7Nrje7tmC8R07AC5RYhYV 60lA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=FKUU19VO; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-131655-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131655-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p6-20020a1709060e8600b00a4e8fd83163si2482185ejf.2.2024.04.04.07.53.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 07:53:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131655-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=FKUU19VO; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-131655-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131655-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 25F731F2A6BF for ; Thu, 4 Apr 2024 14:52:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 146DD1D547; Thu, 4 Apr 2024 14:52:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="FKUU19VO" Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DD5A41C68 for ; Thu, 4 Apr 2024 14:52:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712242362; cv=none; b=L+7Q3xIh1yK+QEVPa+0xJyYd06R0qUDyYs6S43bU7wPRqMcLsooIAG6yzGVuYdDgfy3o3DvAb80jQ0ea6XUfsHew/54CM6j3F6z/NN+0kg1KY1t+ovT451Uq9gEOaZLZrSyyhNuU7BA9VAFu6RA1tm7ihZIxWTQVIRS/kA6ptr4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712242362; c=relaxed/simple; bh=BkLSbtK8Nf5PzWncO5eh4M62k+sCM5Hlzp2GGZnYD2c=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bSNMxwjyBcOrr6gJrRbEivBqc4kVr1eUiGqaNfC0kPABVWtXnkNp6dYm/TBtngVYQdmEsgkq/ogO4lDk9ORoF5Kzct+6qlf5O8PSB0daXQWUjQV/NlMA/u6cwt3fhd09/W4jwQA3daVzHxEJzrg+Qya/hE3D2Zuyz+QIGLvZfjY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=FKUU19VO; arc=none smtp.client-ip=185.70.43.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1712242358; x=1712501558; bh=KHjrZ7L/o/5RAJWobPfw5bBLIJX2aXSEBFmB1P0i8VM=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=FKUU19VO9s8jHrtlRm0l4Oa9EYZ2LNskf59Lccmcx00wF0/hXavvOgNkICFTEXLr7 eG8K7G3KU5pArEJW1gis6nSeajzvP2+wZKnU/5xlzLO0blbAsz6A1+2W0eg145IwXW 1WBT+UOh3kz9e2WPI7eCgFETHOBtzCx9B8WXSpaZmm5YO2aclP7CMZJuvy9C0AXB1B u32vOV45Rtj7N4O/KWnUd6tK57LEGDdDBFRODtwfYX811JHexOP0qc3UMDnpmTQe9G lgNRtR0HIUvn0T7dFeSnhvU4H7Z8ukRI8WsWOyMmKN/iU42EwvP3Tn9x49eaTq3Tyt gH0efbnKxXcLg== Date: Thu, 04 Apr 2024 14:52:31 +0000 To: Alice Ryhl From: Benno Lossin Cc: Miguel Ojeda , Andrew Morton , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Marco Elver , Kees Cook , Coly Li , Paolo Abeni , Pierre Gondois , Ingo Molnar , Jakub Kicinski , Wei Yang , Matthew Wilcox , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: Re: [PATCH 6/9] rust: list: add iterators Message-ID: <4045af19-05a4-48f0-9ca1-0d8d4d2b865c@proton.me> In-Reply-To: References: <20240402-linked-list-v1-0-b1c59ba7ae3b@google.com> <20240402-linked-list-v1-6-b1c59ba7ae3b@google.com> <98449574-4c1b-4281-bbd3-3ac2767020cb@proton.me> Feedback-ID: 71780778:user:proton Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 04.04.24 16:41, Alice Ryhl wrote: > On Thu, Apr 4, 2024 at 4:36=E2=80=AFPM Benno Lossin wrote: >> >> On 02.04.24 14:17, Alice Ryhl wrote: >>> +/// the end of the list. The `stop` pointer points at the first value = in the same list, or it is >>> +/// null if the list is empty. >>> +#[derive(Clone)] >>> +pub struct Iter<'a, T: ?Sized + ListItem, const ID: u64 =3D 0> { >>> + current: *mut ListLinksFields, >>> + stop: *mut ListLinksFields, >>> + _ty: PhantomData<&'a ListArc>, >>> +} >>> + >>> +impl<'a, T: ?Sized + ListItem, const ID: u64> Iterator for Iter<'a= , T, ID> { >>> + type Item =3D ArcBorrow<'a, T>; >>> + >>> + fn next(&mut self) -> Option> { >>> + if self.current.is_null() { >>> + return None; >>> + } >>> + >>> + let current =3D self.current; >>> + >>> + // SAFETY: We just checked that `current` is not null, so it i= s in a list, and hence not >>> + // dangling. There's no race because the iterator holds an imm= utable borrow to the list. >> >> This (that the iterator holds an immutable borrow) is not true (there >> is no `&List` field in `Iter`), but you can make that an invariant >> instead. >=20 > What I mean is that the borrow-checker will consider the `List` to be > borrowed by `Iter`. Whether or not there is a real reference or not > doesn't matter. Yes, but that is implementation detail of the safe function `List::iter`, so I think it must also be captured by an invariant. --=20 Cheers, Benno