* [PATCH] rust: error: allow specifying error type on `Result`
@ 2023-05-02 12:40 Alice Ryhl
2023-05-02 13:59 ` Asahi Lina
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Alice Ryhl @ 2023-05-02 12:40 UTC (permalink / raw)
To: Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
rust-for-linux, linux-kernel, patches, Alice Ryhl
Currently, if the `kernel::error::Result` type is in scope (which is
often is, since it's in the kernel's prelude), you cannot write
`Result<T, SomeOtherErrorType>` when you want to use a different error
type than `kernel::error::Error`.
To solve this we change the error type from being hard-coded to just
being a default generic parameter. This still lets you write `Result<T>`
when you just want to use the `Error` error type, but also lets you
write `Result<T, SomeOtherErrorType>` when necessary.
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
rust/kernel/error.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
index 5f4114b30b94..01dd4d2f63d2 100644
--- a/rust/kernel/error.rs
+++ b/rust/kernel/error.rs
@@ -177,7 +177,7 @@ impl From<core::convert::Infallible> for Error {
/// Note that even if a function does not return anything when it succeeds,
/// it should still be modeled as returning a `Result` rather than
/// just an [`Error`].
-pub type Result<T = ()> = core::result::Result<T, Error>;
+pub type Result<T = (), E = Error> = core::result::Result<T, E>;
/// Converts an integer as returned by a C kernel function to an error if it's negative, and
/// `Ok(())` otherwise.
base-commit: ea76e08f4d901a450619831a255e9e0a4c0ed162
--
2.40.1.495.gc816e09b53d-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: error: allow specifying error type on `Result`
2023-05-02 12:40 [PATCH] rust: error: allow specifying error type on `Result` Alice Ryhl
@ 2023-05-02 13:59 ` Asahi Lina
2023-05-02 18:05 ` Benno Lossin
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Asahi Lina @ 2023-05-02 13:59 UTC (permalink / raw)
To: Alice Ryhl, Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
rust-for-linux, linux-kernel, patches
On 02/05/2023 21.40, Alice Ryhl wrote:
> Currently, if the `kernel::error::Result` type is in scope (which is
> often is, since it's in the kernel's prelude), you cannot write
> `Result<T, SomeOtherErrorType>` when you want to use a different error
> type than `kernel::error::Error`.
>
> To solve this we change the error type from being hard-coded to just
> being a default generic parameter. This still lets you write `Result<T>`
> when you just want to use the `Error` error type, but also lets you
> write `Result<T, SomeOtherErrorType>` when necessary.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> rust/kernel/error.rs | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
> index 5f4114b30b94..01dd4d2f63d2 100644
> --- a/rust/kernel/error.rs
> +++ b/rust/kernel/error.rs
> @@ -177,7 +177,7 @@ impl From<core::convert::Infallible> for Error {
> /// Note that even if a function does not return anything when it succeeds,
> /// it should still be modeled as returning a `Result` rather than
> /// just an [`Error`].
> -pub type Result<T = ()> = core::result::Result<T, Error>;
> +pub type Result<T = (), E = Error> = core::result::Result<T, E>;
>
> /// Converts an integer as returned by a C kernel function to an error if it's negative, and
> /// `Ok(())` otherwise.
>
> base-commit: ea76e08f4d901a450619831a255e9e0a4c0ed162
Reviewed-by: Asahi Lina <lina@asahilina.net>
~~ Lina
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: error: allow specifying error type on `Result`
2023-05-02 12:40 [PATCH] rust: error: allow specifying error type on `Result` Alice Ryhl
2023-05-02 13:59 ` Asahi Lina
@ 2023-05-02 18:05 ` Benno Lossin
2023-05-08 11:39 ` Gary Guo
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Benno Lossin @ 2023-05-02 18:05 UTC (permalink / raw)
To: Alice Ryhl
Cc: Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor, Boqun Feng,
Gary Guo, Björn Roy Baron, rust-for-linux, linux-kernel,
patches
On 02.05.23 14:40, Alice Ryhl wrote:
> Currently, if the `kernel::error::Result` type is in scope (which is
> often is, since it's in the kernel's prelude), you cannot write
> `Result<T, SomeOtherErrorType>` when you want to use a different error
> type than `kernel::error::Error`.
>
> To solve this we change the error type from being hard-coded to just
> being a default generic parameter. This still lets you write `Result<T>`
> when you just want to use the `Error` error type, but also lets you
> write `Result<T, SomeOtherErrorType>` when necessary.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
> ---
> rust/kernel/error.rs | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
> index 5f4114b30b94..01dd4d2f63d2 100644
> --- a/rust/kernel/error.rs
> +++ b/rust/kernel/error.rs
> @@ -177,7 +177,7 @@ impl From<core::convert::Infallible> for Error {
> /// Note that even if a function does not return anything when it succeeds,
> /// it should still be modeled as returning a `Result` rather than
> /// just an [`Error`].
> -pub type Result<T = ()> = core::result::Result<T, Error>;
> +pub type Result<T = (), E = Error> = core::result::Result<T, E>;
>
> /// Converts an integer as returned by a C kernel function to an error if it's negative, and
> /// `Ok(())` otherwise.
>
> base-commit: ea76e08f4d901a450619831a255e9e0a4c0ed162
> --
> 2.40.1.495.gc816e09b53d-goog
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: error: allow specifying error type on `Result`
2023-05-02 12:40 [PATCH] rust: error: allow specifying error type on `Result` Alice Ryhl
2023-05-02 13:59 ` Asahi Lina
2023-05-02 18:05 ` Benno Lossin
@ 2023-05-08 11:39 ` Gary Guo
2023-05-15 19:09 ` Andreas Hindborg
2023-05-31 17:09 ` Miguel Ojeda
4 siblings, 0 replies; 6+ messages in thread
From: Gary Guo @ 2023-05-08 11:39 UTC (permalink / raw)
To: Alice Ryhl
Cc: Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor, Boqun Feng,
Björn Roy Baron, Benno Lossin, rust-for-linux, linux-kernel,
patches
On Tue, 2 May 2023 12:40:15 +0000
Alice Ryhl <aliceryhl@google.com> wrote:
> Currently, if the `kernel::error::Result` type is in scope (which is
> often is, since it's in the kernel's prelude), you cannot write
> `Result<T, SomeOtherErrorType>` when you want to use a different error
> type than `kernel::error::Error`.
>
> To solve this we change the error type from being hard-coded to just
> being a default generic parameter. This still lets you write `Result<T>`
> when you just want to use the `Error` error type, but also lets you
> write `Result<T, SomeOtherErrorType>` when necessary.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
> ---
> rust/kernel/error.rs | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
> index 5f4114b30b94..01dd4d2f63d2 100644
> --- a/rust/kernel/error.rs
> +++ b/rust/kernel/error.rs
> @@ -177,7 +177,7 @@ impl From<core::convert::Infallible> for Error {
> /// Note that even if a function does not return anything when it succeeds,
> /// it should still be modeled as returning a `Result` rather than
> /// just an [`Error`].
> -pub type Result<T = ()> = core::result::Result<T, Error>;
> +pub type Result<T = (), E = Error> = core::result::Result<T, E>;
>
> /// Converts an integer as returned by a C kernel function to an error if it's negative, and
> /// `Ok(())` otherwise.
>
> base-commit: ea76e08f4d901a450619831a255e9e0a4c0ed162
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: error: allow specifying error type on `Result`
2023-05-02 12:40 [PATCH] rust: error: allow specifying error type on `Result` Alice Ryhl
` (2 preceding siblings ...)
2023-05-08 11:39 ` Gary Guo
@ 2023-05-15 19:09 ` Andreas Hindborg
2023-05-31 17:09 ` Miguel Ojeda
4 siblings, 0 replies; 6+ messages in thread
From: Andreas Hindborg @ 2023-05-15 19:09 UTC (permalink / raw)
To: Alice Ryhl
Cc: Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, rust-for-linux,
linux-kernel, patches
Alice Ryhl <aliceryhl@google.com> writes:
> Currently, if the `kernel::error::Result` type is in scope (which is
> often is, since it's in the kernel's prelude), you cannot write
> `Result<T, SomeOtherErrorType>` when you want to use a different error
> type than `kernel::error::Error`.
>
> To solve this we change the error type from being hard-coded to just
> being a default generic parameter. This still lets you write `Result<T>`
> when you just want to use the `Error` error type, but also lets you
> write `Result<T, SomeOtherErrorType>` when necessary.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
> rust/kernel/error.rs | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
> index 5f4114b30b94..01dd4d2f63d2 100644
> --- a/rust/kernel/error.rs
> +++ b/rust/kernel/error.rs
> @@ -177,7 +177,7 @@ impl From<core::convert::Infallible> for Error {
> /// Note that even if a function does not return anything when it succeeds,
> /// it should still be modeled as returning a `Result` rather than
> /// just an [`Error`].
> -pub type Result<T = ()> = core::result::Result<T, Error>;
> +pub type Result<T = (), E = Error> = core::result::Result<T, E>;
>
> /// Converts an integer as returned by a C kernel function to an error if it's negative, and
> /// `Ok(())` otherwise.
>
> base-commit: ea76e08f4d901a450619831a255e9e0a4c0ed162
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: error: allow specifying error type on `Result`
2023-05-02 12:40 [PATCH] rust: error: allow specifying error type on `Result` Alice Ryhl
` (3 preceding siblings ...)
2023-05-15 19:09 ` Andreas Hindborg
@ 2023-05-31 17:09 ` Miguel Ojeda
4 siblings, 0 replies; 6+ messages in thread
From: Miguel Ojeda @ 2023-05-31 17:09 UTC (permalink / raw)
To: Alice Ryhl
Cc: Miguel Ojeda, Wedson Almeida Filho, Alex Gaynor, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, rust-for-linux,
linux-kernel, patches
On Tue, May 2, 2023 at 2:40 PM Alice Ryhl <aliceryhl@google.com> wrote:
>
> Currently, if the `kernel::error::Result` type is in scope (which is
> often is, since it's in the kernel's prelude), you cannot write
> `Result<T, SomeOtherErrorType>` when you want to use a different error
> type than `kernel::error::Error`.
>
> To solve this we change the error type from being hard-coded to just
> being a default generic parameter. This still lets you write `Result<T>`
> when you just want to use the `Error` error type, but also lets you
> write `Result<T, SomeOtherErrorType>` when necessary.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Applied to `rust-next` -- thanks everyone!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-05-31 17:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-02 12:40 [PATCH] rust: error: allow specifying error type on `Result` Alice Ryhl
2023-05-02 13:59 ` Asahi Lina
2023-05-02 18:05 ` Benno Lossin
2023-05-08 11:39 ` Gary Guo
2023-05-15 19:09 ` Andreas Hindborg
2023-05-31 17:09 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).