Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4194986rdb; Mon, 11 Dec 2023 11:30:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAOSLTWoo/87uE7KM5Sb4Q+aWLzZJl7ufayVs/INN6ZB0UI5aCZ9QNHds56odvOacuftNZ X-Received: by 2002:a05:6e02:1a88:b0:35d:5543:45dd with SMTP id k8-20020a056e021a8800b0035d554345ddmr7487912ilv.22.1702323051169; Mon, 11 Dec 2023 11:30:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702323051; cv=none; d=google.com; s=arc-20160816; b=UzyW9ehl3p1Eqrj12qp5bYtkfei+DeoIt5M+KOKZSbWXFo1ysPhovnTq8HmJpBpUSA zZy8dKl6qbiPGaUoo1XGK1GrubWbKPKFfIyhinRDFXnJ/efhzVp0PWnWiIqTyV76mRde Tnjp9/NxSGHFEdJpe3JoHfxx4hZcLvX/K191k/9CqaYI6KN4jG1RyDxpALlh0SBf80ST QGpQD3nLxAp4m3dGWWjUEwpdK992X/d9TaZT1nC3ybKvftdHxi359qi+m6Av9DAqokaW X3718BFu+tLZesz3XKPidrs59Mw1DwG0eiwbpWvQ9uabpxXhmVafc630V4xrHaIiIBRF s2eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :date:dkim-signature; bh=ZvbWUAFMmN9CwyCE8z5cp5KvI4mt6HMigT944NpeNaI=; fh=OGOdlSOz0RuEDdbIabAQ7xVcSKDxIiA+5g9VGuDRRdM=; b=BMG8/WiITN2Fn42JvoOvtR7OwMe+NGsTgLRZ07I11cc01Qqe9z8WS/JCqL8oGGM41T UGi70+QSCGzII15eniu9Vo9D+twNLry8KSBBstd5awvALf8B+EYkTTSk/09UBnxezkJL /U7r3872vWAW7139Xf0k+/Datb1Rq0tMG10UEstN07khO+GshpyPABmRztQxYTKYr6Yz sNfy3Ybw/MsSh+g+6nKrYMwo64hxW2ZTK0AIsVGqq47l9XLuLtjuBaXfX/Ook71xSBYx F1+qh5NLZZT4SJlIohETISLOgP9a1iNec/AqU74pcwJXJmaTdwtqz6svmWwVI88VptxV dnwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=oez5vhlldzbmfa37ze5u6zgypa.protonmail header.b=RL8B0uOJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id 194-20020a6300cb000000b005bddb7249e0si6352903pga.313.2023.12.11.11.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 11:30:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=oez5vhlldzbmfa37ze5u6zgypa.protonmail header.b=RL8B0uOJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 805D5805937A; Mon, 11 Dec 2023 11:30:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344410AbjLKTad (ORCPT + 99 others); Mon, 11 Dec 2023 14:30:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbjLKTab (ORCPT ); Mon, 11 Dec 2023 14:30:31 -0500 Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40D95B3; Mon, 11 Dec 2023 11:30:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=oez5vhlldzbmfa37ze5u6zgypa.protonmail; t=1702323034; x=1702582234; bh=ZvbWUAFMmN9CwyCE8z5cp5KvI4mt6HMigT944NpeNaI=; 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=RL8B0uOJcCwNVHWVJYyDCGgsBtdjDZAwBFEFprLad5/31BcaTZ/obv974Pnztj36e WxbdXBKBnCSHR6MPXNsa1bLaHOPiPINWfbD87Uw7rcgSGJ3ehQm3G2ZaObFF9YmFGc mkJialwWbEU8Gwv29hbx1KxMjRonP1sERdbEahR2vLt5J0L8DGY6apYl1K+A0Uq8vW GnWt/UF9FA4ix3HUjkOSPqIx1b6L6RymbisMJ9PLKwKbjtouuj9ABmOe+wX0sZaeGZ Jxe1A70SOutTmcoKdJWzIfoEUC1pIfLBd6pTzKdtJA2GJqRQMj3UUiYnUfucH2CXet c8+UkybW9uocQ== Date: Mon, 11 Dec 2023 19:30:26 +0000 To: Boqun Feng From: Benno Lossin Cc: Alice Ryhl , a.hindborg@samsung.com, alex.gaynor@gmail.com, arve@android.com, bjorn3_gh@protonmail.com, brauner@kernel.org, cmllamas@google.com, dan.j.williams@intel.com, dxu@dxuuu.xyz, gary@garyguo.net, gregkh@linuxfoundation.org, joel@joelfernandes.org, keescook@chromium.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, maco@android.com, ojeda@kernel.org, peterz@infradead.org, rust-for-linux@vger.kernel.org, surenb@google.com, tglx@linutronix.de, tkjos@android.com, viro@zeniv.linux.org.uk, wedsonaf@gmail.com, willy@infradead.org Subject: Re: [PATCH v2 2/7] rust: cred: add Rust abstraction for `struct cred` Message-ID: In-Reply-To: References: <20231211153429.4161511-1-aliceryhl@google.com> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 11 Dec 2023 11:30:48 -0800 (PST) On 12/11/23 18:35, Boqun Feng wrote: > On Mon, Dec 11, 2023 at 03:34:29PM +0000, Alice Ryhl wrote: >> Boqun Feng writes: >>> On Wed, Dec 06, 2023 at 11:59:47AM +0000, Alice Ryhl wrote: >>> [...] >>>> @@ -151,6 +152,21 @@ pub fn as_ptr(&self) -> *mut bindings::file { >>>> self.0.get() >>>> } >>>> >>>> + /// Returns the credentials of the task that originally opened th= e file. >>>> + pub fn cred(&self) -> &Credential { >>> >>> I wonder whether it would be helpful if we use explicit lifetime here: >>> >>> pub fn cred<'file>(&'file self) -> &'file Credential >>> >>> It might be easier for people to get. For example, the lifetime of the >>> returned Credential reference is constrainted by 'file, the lifetime of >>> the file reference. >>> >>> But yes, maybe need to hear others' feedback first. >>> >>> Regards, >>> Boqun >> >> That would trigger a compiler warning because the lifetime is >> unnecessary. >> >=20 > We can disable that warning if people need the information. Code is > mostly for reading, less often for compilation and changes. >=20 >> The safety comment explains what the signature means. I think that >> should be enough. >> >=20 > For someone who has a good understanding of Rust lifetime (and the > elision), yes. But I'm wondering whether all the people feel the same > way. So in this example, I think it should be straight forward what happens to the lifetimes, since there is only one to begin with. If we want to do this, I think we should have some rules around it. A general piece of advice I can offer is this: - when there are no lifetimes in the return type of a function, then you probably do not care about the lifetimes (they will all be distinct and there are no relationships between them). - when there is a single input and a single output lifetime, then they are the same. - the other cases are not so simple, but most of the time they will require explicit annotations. I left out some details, you can read more at [1]. Most cases where it is not obvious which lifetime relations exist are already rejected by the compiler. The only exception is if there is a `&self` or `&mut self` parameter, then that one has precedence. So we could also explicitly annotate those. Since they are also rare, I think this would be fine. [1]: https://doc.rust-lang.org/nomicon/lifetime-elision.html --=20 Cheers, Benno