Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp86406lqp; Thu, 4 Apr 2024 07:45:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUKWkye/TNgyvRFocyIjzAedLqvK6IDqI/PT6gZRLMT4rsQ2z0OHgaTHdcT+YlTBYidJi/bTUyojKld4ziZGjzXzYWYHi3hSLxKGcP/0g== X-Google-Smtp-Source: AGHT+IGN0jXZANks+ojUwZe+fmijW+5Hhaed1dmbxL1ARxc8TZe+nYTJ6tQUmBqobM55nmY6udn+ X-Received: by 2002:a19:f00d:0:b0:516:bea8:f46e with SMTP id p13-20020a19f00d000000b00516bea8f46emr1947687lfc.61.1712241935116; Thu, 04 Apr 2024 07:45:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712241935; cv=pass; d=google.com; s=arc-20160816; b=ax7DU4gKWMtxyXAydnyI8IWE5XbXMWdd+4t+Iw4PLqyPtkep2K97F/A9EuBpRwXgIr UMyTKqyLryaD+cNDwIyTFct18VUv+TeRd7sZJOg/b2OBMVLVuiQdiMvExiBj+/IWeUls SVhjx4OSfuXhOS/mSkN/HxSWFrdbcmAFl4M8UZn6ulTnur+MfmNreTSQx6EJzmSdV3bB QOStZiWqI4OhEEU/YTT6ByzyuCPz+WTHRS53ZbH5bouOQ3FuuGB4U/ZS6xJkhbBqSjPd Lsf3R6E4IJNecj8SGHjUaMd2AmyPz3s9KYTysjzZCEZSkdtAKS7IkcDJan25q9ANY2ls ihvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=sCOieR3KDrxseidIEeQxtseySKtvl+xDkoYPv0qKlDU=; fh=rcm2qxjVgqzOEmzJus7/LLi9TqH2LiZQr/lgRxCtMNE=; b=qAWgtjpA2xI+J/CYtVJuFVQBdQXW5y9oDgOB2BeDBONUEmJLOXU8PmBYA05YaNFAT0 nSZJzAzZEtAaegfVvIHRdhDCA/JNXqzrEjKEtw60QvCsdFL2Jq2Dl9qkpH8MMKCKHxI3 Da1oWzDPx6xb0TNh/BmYb603ZnpMGNJwHUBXt3JnShoeS4gS5SBJb2uGFQTnMr2qr8zj xQ2yMTFAfKXIR0ZoFnslNOdrxnYU/Ey5SlbPuzEz4aqCWGPc/e9KVHnFWiGVaZW9HMw/ gLYKfO4Ji02+4A4W/yY4CxGTL7eAZNh4Qv4BXH92LcnUPakzknWCGynLjphEe9t/sCzW s+DA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mcnzliWR; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-131639-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131639-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id jt21-20020a170906ca1500b00a4e671a349esi4601497ejb.435.2024.04.04.07.45.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 07:45:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131639-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=@google.com header.s=20230601 header.b=mcnzliWR; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-131639-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131639-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 7342E1F250FD for ; Thu, 4 Apr 2024 14:42:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1665212AAC9; Thu, 4 Apr 2024 14:42:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mcnzliWR" Received: from mail-vk1-f170.google.com (mail-vk1-f170.google.com [209.85.221.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB1201CD03 for ; Thu, 4 Apr 2024 14:42:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712241727; cv=none; b=qQPVfq11saYcgtrBze9vTJ9KAveuAfoQewHeAFV2ffVKakn3MKR9oRt3rBJg2e1l/GA1R6wrTU3PntLAUOtthy6pV+agwAfoBwm8t9qm7KEnyzngOzPzCgN5xTeOa6mwQKcbqYC/YqH6/ajsoGTK//U+xvyHN0CykmToF5rAM1I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712241727; c=relaxed/simple; bh=Tl6OJL3Ay3elBPXJKELrFjWgQUqYUPxNsWZDIG4ldSU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=KuPnvXLJvJuLJGlRxFvhO0K6tB4P8KW2I9AsVQQboJnf4ES+c3fmqvU16H+Ytxiun7wjxRvBMY7V0tJ9fA3L8bHC2b6m4Hq7oRnzbq7r1uFegQ3K05zDh0QgmymUNtRqtNlvbfqTh8sxR+vhFA3iLlDcuJxVDDBODtyH9R8jt/M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mcnzliWR; arc=none smtp.client-ip=209.85.221.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-vk1-f170.google.com with SMTP id 71dfb90a1353d-4d43d602cd6so369428e0c.0 for ; Thu, 04 Apr 2024 07:42:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712241724; x=1712846524; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=sCOieR3KDrxseidIEeQxtseySKtvl+xDkoYPv0qKlDU=; b=mcnzliWRODP+SepwivmCwrju+LYKFpk9FTbZmo2UMq/Bx03djm/3f0l5qtZjfi9e1/ BDJPCHpkvD9UI80S5XWeyFFR4EpR8YVxcUTAmCgafUSNg7AHtRh0r/HHND1N6+DXhVUz accmja2zxN4Pt0mYiXEp5rNcY5WNeheUZpQhnJXAHnRXbMriB9K99FdORYLjbo5NdyL8 CqNF7MjqfFWgIsZC74Op/8DST3V3D60/q0GajPKK08nDwbw++64oKX4ipnZTkJkcZLPZ dwYaviKRVzWWW7Pwv5wnZ3gAUIm9D8Emf3FXQNY3dMZlOsT1a6k75AF973B1LiJKaKbI dfSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712241724; x=1712846524; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sCOieR3KDrxseidIEeQxtseySKtvl+xDkoYPv0qKlDU=; b=ixrxkg4zm7I2z3M55kwsovg3s2IEWFKMiC5vL/3HMKTqAENcn81+N5//UlW9AQ5mHu z+3rTMOQ0dlXf+O08O1ml0gItRq3D3lNlT80Wr39gPch5iOMiG7fAqenvMRA7JLnxDsf ctgrQUluTr9NeiwDa+taS4D4rK4p+kvLFt1GwRT2a7qkGbykbuSELA1FIe8oskTYx4iP kD/sgA0R1uk78cOFH44xlbgRa5Im9x0As4L6ID4uH9nkdlwCLFtcje5uhjxXRkxoxb6k mnjUUavBdgaX4lIELz1bDN/f466M7nZkj+xlaZY8xl/01RCc8wu/h7RTWxGj5m+V8bRW If1A== X-Forwarded-Encrypted: i=1; AJvYcCUhDxx1lCZH4ECdhb7JtTJZ0QNVYzDj7DEInBsUNm5We/YXYFt5gphWzy6kwUNZnUFJAuAmqt1ysnSQKxuLz2+bOB4zndOeSmxA766M X-Gm-Message-State: AOJu0YyiNESwFWglIgcT+qARATCE1NQSsrow4a/RHiBuWGSr9iXJvjql XhDqRaeBXadiz1dqH1zMSUwW80dBL5xLs0cJVGO/p1ePf2dVw1lBJ6cOYKcE43sW/pH/VTNe0UK lR+5YqzebdoMkBmFevNdYMSiAU5tvPtIo2N/G X-Received: by 2002:a1f:f84e:0:b0:4d3:362f:f9c1 with SMTP id w75-20020a1ff84e000000b004d3362ff9c1mr2282476vkh.13.1712241724504; Thu, 04 Apr 2024 07:42:04 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240402-linked-list-v1-0-b1c59ba7ae3b@google.com> <20240402-linked-list-v1-6-b1c59ba7ae3b@google.com> <98449574-4c1b-4281-bbd3-3ac2767020cb@proton.me> In-Reply-To: <98449574-4c1b-4281-bbd3-3ac2767020cb@proton.me> From: Alice Ryhl Date: Thu, 4 Apr 2024 16:41:53 +0200 Message-ID: Subject: Re: [PATCH 6/9] rust: list: add iterators To: 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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. 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. Alice