Skip to content

Make Result parametric in the error type as well #662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion googletest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ use internal::test_outcome::{TestAssertionFailure, TestOutcome};
/// of the (fatal) assertion failure which generated this result. Non-fatal
/// assertion failures, which log the failure and report the test as having
/// failed but allow it to continue running, are not encoded in this type.
pub type Result<T> = std::result::Result<T, TestAssertionFailure>;
pub type Result<T, E = TestAssertionFailure> = std::result::Result<T, E>;

/// Returns a [`Result`] corresponding to the outcome of the currently running
/// test.
Expand Down
2 changes: 1 addition & 1 deletion googletest_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
};

let (output_type, result) = match sig.output {
ReturnType::Default => (None, quote! {googletest::Result::Ok(())}),
ReturnType::Default => (None, quote! {googletest::Result::<()>::Ok(())}),
ReturnType::Type(_, ref ty) => (Some(quote! {#ty}), quote! {result}),
};

Expand Down Expand Up @@ -425,7 +425,7 @@
.into()
}

fn abbreviated_string(target: &str) -> Result<std::borrow::Cow<str>, &'static str> {

Check warning on line 428 in googletest_macro/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

lifetime flowing from input to output with different syntax can be confusing

warning: lifetime flowing from input to output with different syntax can be confusing --> googletest_macro/src/lib.rs:428:31 | 428 | fn abbreviated_string(target: &str) -> Result<std::borrow::Cow<str>, &'static str> { | ^^^^ --------------------- the lifetime gets resolved as `'_` | | | this lifetime flows to the output | = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default help: one option is to remove the lifetime for references and use the anonymous lifetime for paths | 428 | fn abbreviated_string(target: &str) -> Result<std::borrow::Cow<'_, str>, &'static str> { | +++

Check warning on line 428 in googletest_macro/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

lifetime flowing from input to output with different syntax can be confusing

warning: lifetime flowing from input to output with different syntax can be confusing --> googletest_macro/src/lib.rs:428:31 | 428 | fn abbreviated_string(target: &str) -> Result<std::borrow::Cow<str>, &'static str> { | ^^^^ --------------------- the lifetime gets resolved as `'_` | | | this lifetime flows to the output | = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default help: one option is to remove the lifetime for references and use the anonymous lifetime for paths | 428 | fn abbreviated_string(target: &str) -> Result<std::borrow::Cow<'_, str>, &'static str> { | +++

Check warning on line 428 in googletest_macro/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

lifetime flowing from input to output with different syntax can be confusing

warning: lifetime flowing from input to output with different syntax can be confusing --> googletest_macro/src/lib.rs:428:31 | 428 | fn abbreviated_string(target: &str) -> Result<std::borrow::Cow<str>, &'static str> { | ^^^^ --------------------- the lifetime gets resolved as `'_` | | | this lifetime flows to the output | = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default help: one option is to remove the lifetime for references and use the anonymous lifetime for paths | 428 | fn abbreviated_string(target: &str) -> Result<std::borrow::Cow<'_, str>, &'static str> { | +++
use std::borrow::Cow;
match target.rsplit_once(',') {
None => Err("Expect a `max_length` argument, but got none"),
Expand Down
Loading