summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/try_err.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /src/tools/clippy/tests/ui/try_err.rs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/try_err.rs')
-rw-r--r--src/tools/clippy/tests/ui/try_err.rs65
1 files changed, 23 insertions, 42 deletions
diff --git a/src/tools/clippy/tests/ui/try_err.rs b/src/tools/clippy/tests/ui/try_err.rs
index bc6979bf4..86aeb75cd 100644
--- a/src/tools/clippy/tests/ui/try_err.rs
+++ b/src/tools/clippy/tests/ui/try_err.rs
@@ -1,11 +1,11 @@
// run-rustfix
-// aux-build:macro_rules.rs
+// aux-build:proc_macros.rs
#![deny(clippy::try_err)]
#![allow(clippy::unnecessary_wraps, clippy::needless_question_mark)]
-#[macro_use]
-extern crate macro_rules;
+extern crate proc_macros;
+use proc_macros::{external, inline_macros};
use std::io;
use std::task::Poll;
@@ -79,36 +79,22 @@ fn nested_error() -> Result<i32, i32> {
Ok(1)
}
-// Bad suggestion when in macro (see #6242)
-macro_rules! try_validation {
- ($e: expr) => {{
- match $e {
+#[inline_macros]
+fn calling_macro() -> Result<i32, i32> {
+ // macro
+ inline!(
+ match $(Ok::<_, i32>(5)) {
Ok(_) => 0,
Err(_) => Err(1)?,
}
- }};
-}
-
-macro_rules! ret_one {
- () => {
- 1
- };
-}
-
-macro_rules! try_validation_in_macro {
- ($e: expr) => {{
- match $e {
+ );
+ // `Err` arg is another macro
+ inline!(
+ match $(Ok::<_, i32>(5)) {
Ok(_) => 0,
- Err(_) => Err(ret_one!())?,
+ Err(_) => Err(inline!(1))?,
}
- }};
-}
-
-fn calling_macro() -> Result<i32, i32> {
- // macro
- try_validation!(Ok::<_, i32>(5));
- // `Err` arg is another macro
- try_validation_in_macro!(Ok::<_, i32>(5));
+ );
Ok(5)
}
@@ -121,24 +107,19 @@ fn main() {
calling_macro().unwrap();
// We don't want to lint in external macros
- try_err!();
-}
-
-macro_rules! bar {
- () => {
- String::from("aasdfasdfasdfa")
- };
-}
-
-macro_rules! foo {
- () => {
- bar!()
- };
+ external! {
+ pub fn try_err_fn() -> Result<i32, i32> {
+ let err: i32 = 1;
+ // To avoid warnings during rustfix
+ if true { Err(err)? } else { Ok(2) }
+ }
+ }
}
+#[inline_macros]
pub fn macro_inside(fail: bool) -> Result<i32, String> {
if fail {
- Err(foo!())?;
+ Err(inline!(inline!(String::from("aasdfasdfasdfa"))))?;
}
Ok(0)
}