lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJ-ks9=prR2TNFhqip8MsjtTWKkoUhoMG75v2mSLF1UaRNwJLg@mail.gmail.com>
Date: Tue, 27 May 2025 10:57:11 -0400
From: Tamir Duberstein <tamird@...il.com>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Benno Lossin <lossin@...nel.org>, Michal Rostecki <vadorovsky@...tonmail.com>, 
	Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, 
	Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, 
	Björn Roy Baron <bjorn3_gh@...tonmail.com>, 
	Andreas Hindborg <a.hindborg@...nel.org>, Trevor Gross <tmgross@...ch.edu>, 
	Brendan Higgins <brendan.higgins@...ux.dev>, David Gow <davidgow@...gle.com>, 
	Rae Moar <rmoar@...gle.com>, Danilo Krummrich <dakr@...nel.org>, 
	Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>, Maxime Ripard <mripard@...nel.org>, 
	Thomas Zimmermann <tzimmermann@...e.de>, David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>, 
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>, "Rafael J. Wysocki" <rafael@...nel.org>, 
	Luis Chamberlain <mcgrof@...nel.org>, Russ Weight <russ.weight@...ux.dev>, 
	FUJITA Tomonori <fujita.tomonori@...il.com>, Rob Herring <robh@...nel.org>, 
	Saravana Kannan <saravanak@...gle.com>, Peter Zijlstra <peterz@...radead.org>, 
	Ingo Molnar <mingo@...hat.com>, Will Deacon <will@...nel.org>, Waiman Long <longman@...hat.com>, 
	Nathan Chancellor <nathan@...nel.org>, Nick Desaulniers <nick.desaulniers+lkml@...il.com>, 
	Bill Wendling <morbo@...gle.com>, Justin Stitt <justinstitt@...gle.com>, Andrew Lunn <andrew@...n.ch>, 
	Heiner Kallweit <hkallweit1@...il.com>, Russell King <linux@...linux.org.uk>, 
	"David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>, 
	Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>, Bjorn Helgaas <bhelgaas@...gle.com>, 
	Arnd Bergmann <arnd@...db.de>, Jens Axboe <axboe@...nel.dk>, 
	Krzysztof Wilczyński <kwilczynski@...nel.org>, 
	rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org, 
	linux-kselftest@...r.kernel.org, kunit-dev@...glegroups.com, 
	dri-devel@...ts.freedesktop.org, netdev@...r.kernel.org, 
	devicetree@...r.kernel.org, llvm@...ts.linux.dev, linux-pci@...r.kernel.org, 
	nouveau@...ts.freedesktop.org, linux-block@...r.kernel.org
Subject: Re: [PATCH v10 2/5] rust: support formatting of foreign types

On Tue, May 27, 2025 at 8:44 AM Alice Ryhl <aliceryhl@...gle.com> wrote:
>
> On Tue, May 27, 2025 at 12:18 AM Tamir Duberstein <tamird@...il.com> wrote:
> > > > +}
> > > > +
> > > > +fn make_ident<'a, T: IntoIterator<Item = &'a str>>(
> > > > +    span: Span,
> > > > +    names: T,
> > > > +) -> impl Iterator<Item = TokenTree> + use<'a, T> {
> > > > +    names.into_iter().flat_map(move |name| {
> > > > +        [
> > > > +            TokenTree::Punct(Punct::new(':', Spacing::Joint)),
> > > > +            TokenTree::Punct(Punct::new(':', Spacing::Alone)),
> > > > +            TokenTree::Ident(Ident::new(name, span)),
> > > > +        ]
> > > > +    })
> > > > +}
> > > > diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs
> > > > index d31e50c446b0..fa956eaa3ba7 100644
> > > > --- a/rust/macros/lib.rs
> > > > +++ b/rust/macros/lib.rs
> > > > @@ -10,6 +10,7 @@
> > > >  mod quote;
> > > >  mod concat_idents;
> > > >  mod export;
> > > > +mod fmt;
> > > >  mod helpers;
> > > >  mod kunit;
> > > >  mod module;
> > > > @@ -196,6 +197,24 @@ pub fn export(attr: TokenStream, ts: TokenStream) -> TokenStream {
> > > >      export::export(attr, ts)
> > > >  }
> > > >
> > > > +/// Like [`core::format_args!`], but automatically wraps arguments in [`kernel::fmt::Adapter`].
> > > > +///
> > > > +/// This macro allows generating `core::fmt::Arguments` while ensuring that each argument is wrapped
> > > > +/// with `::kernel::fmt::Adapter`, which customizes formatting behavior for kernel logging.
> > > > +///
> > > > +/// Named arguments used in the format string (e.g. `{foo}`) are detected and resolved from local
> > > > +/// bindings. All positional and named arguments are automatically wrapped.
> > > > +///
> > > > +/// This macro is an implementation detail of other kernel logging macros like [`pr_info!`] and
> > > > +/// should not typically be used directly.
> > > > +///
> > > > +/// [`kernel::fmt::Adapter`]: ../kernel/fmt/struct.Adapter.html
> > > > +/// [`pr_info!`]: ../kernel/macro.pr_info.html
> > > > +#[proc_macro]
> > > > +pub fn fmt(input: TokenStream) -> TokenStream {
> > >
> > > I'm wondering if we should name this `format_args` instead in order to
> > > better communicate that it's a replacement for `core::format_args!`.
> >
> > Unfortunately that introduces ambiguity in cases where
> > kernel::prelude::* is imported because core::format_args is in core's
> > prelude.
>
> I'm pretty sure that glob imports are higher priority than the core
> prelude? Or is this because there are macros that now incorrectly use
> kernel::prelude::format_args when they should use the one from core?

compiler says no, e.g.:

error[E0659]: `format_args` is ambiguous
    --> rust/doctests_kernel_generated.rs:8783:25
     |
8783 |     kernel::kunit::info(format_args!("    #
rust_doctest_kernel_workqueue_rs_3.location:
rust/kernel/workqueue.rs:77\n"));
     |                         ^^^^^^^^^^^ ambiguous name
     |
     = note: ambiguous because of a conflict between a name from a
glob import and an outer scope during import or macro resolution
     = note: `format_args` could refer to a macro from prelude
note: `format_args` could also refer to the macro imported here
    --> rust/doctests_kernel_generated.rs:8772:9
     |
8772 |     use kernel::prelude::*;
     |         ^^^^^^^^^^^^^^^^^^
     = help: consider adding an explicit import of `format_args` to disambiguate

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ