-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rsjudge-utils): ✅ fixed a potential misuse of
log_if_error
macro
- Loading branch information
1 parent
c4ee29c
commit ed3f06b
Showing
7 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0308]: mismatched types | ||
--> tests/logging_on_non_result.test:19:27 | ||
| | ||
19 | let _ = log_if_error!(S); | ||
| --------------^- | ||
| | | | ||
| | expected `Result<_, _>`, found `S` | ||
| arguments to this function are incorrect | ||
| | ||
= note: expected enum `Result<_, _>` | ||
found struct `S` | ||
note: method defined here | ||
--> $RUST/core/src/result.rs | ||
| | ||
| pub fn map_err<F, O: FnOnce(E) -> F>(self, op: O) -> Result<T, F> { | ||
| ^^^^^^^ | ||
help: try wrapping the expression in a variant of `Result` | ||
| | ||
19 | let _ = log_if_error!(Ok(S)); | ||
| +++ + | ||
19 | let _ = log_if_error!(Err(S)); | ||
| ++++ + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::fmt::Display; | ||
|
||
use rsjudge_utils::log_if_error; | ||
|
||
fn main() { | ||
#[derive(Debug)] | ||
struct S; | ||
impl Display for S { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "S") | ||
} | ||
} | ||
impl S { | ||
fn map_err<F: FnOnce(Self) -> Self>(self, f: F) -> Self { | ||
f(self) | ||
} | ||
} | ||
|
||
let _ = log_if_error!(S); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use trybuild::TestCases; | ||
|
||
#[test] | ||
fn tests() { | ||
let test_cases = TestCases::new(); | ||
test_cases.compile_fail("tests/logging_on_non_result.test"); | ||
} |