diff --git a/clippy_lints/src/manual_assert.rs b/clippy_lints/src/manual_assert.rs index 501851a0f665..e5327c421355 100644 --- a/clippy_lints/src/manual_assert.rs +++ b/clippy_lints/src/manual_assert.rs @@ -63,31 +63,21 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert { let cond_sugg = sugg::Sugg::hir_with_applicability(cx, cond, "..", &mut applicability).maybe_par(); let semicolon = if is_parent_stmt(cx, expr.hir_id) { ";" } else { "" }; let base_sugg = format!("assert!({not}{cond_sugg}, {format_args_snip}){semicolon}"); - // we show to the user the suggestion without the comments, but when applying the fix, include the - // comments in the block span_lint_and_then( cx, MANUAL_ASSERT, expr.span, "only a `panic!` in `if`-then statement", |diag| { - // If we have comments, use a tool_only suggestion to add them back. - // Comments can be noisy, and this will hide them from the user's output. - if !comments.is_empty() { - diag.tool_only_span_suggestion( - expr.span.shrink_to_lo(), - "add comments back", - comments, - applicability, - ); - } + // If we have comments to retain, include them in the final suggestion, if + // not, don't. + let suggestions = if comments.is_empty() { + vec![(expr.span.shrink_to_lo(), comments), (expr.span, base_sugg.clone())] + } else { + vec![(expr.span, base_sugg.clone())] + }; - // And setup a multipart suggestion for the user-facing part. - diag.multipart_suggestion( - "replace `if`-then-`panic!` with `assert!`", - vec![(expr.span, base_sugg.clone())], - applicability, - ); + diag.multipart_suggestion("replace `if`-then-`panic!` with `assert!`", suggestions, applicability); }, ); } diff --git a/tests/ui/manual_assert.edition2018.1.fixed b/tests/ui/manual_assert.edition2018.1.fixed deleted file mode 100644 index 8de36a4c7f15..000000000000 --- a/tests/ui/manual_assert.edition2018.1.fixed +++ /dev/null @@ -1,83 +0,0 @@ -//@revisions: edition2018 edition2021 -//@[edition2018] edition:2018 -//@[edition2021] edition:2021 - -#![warn(clippy::manual_assert)] -#![allow(dead_code, unused_doc_comments)] -#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args, clippy::useless_vec)] - -macro_rules! one { - () => { - 1 - }; -} - -fn main() { - let a = vec![1, 2, 3]; - let c = Some(2); - if !a.is_empty() - && a.len() == 3 - && c.is_some() - && !a.is_empty() - && a.len() == 3 - && !a.is_empty() - && a.len() == 3 - && !a.is_empty() - && a.len() == 3 - { - panic!("qaqaq{:?}", a); - } - assert!(a.is_empty(), "qaqaq{:?}", a); - assert!(a.is_empty(), "qwqwq"); - if a.len() == 3 { - println!("qwq"); - println!("qwq"); - println!("qwq"); - } - if let Some(b) = c { - panic!("orz {}", b); - } - if a.len() == 3 { - panic!("qaqaq"); - } else { - println!("qwq"); - } - let b = vec![1, 2, 3]; - assert!(!b.is_empty(), "panic1"); - assert!(!(b.is_empty() && a.is_empty()), "panic2"); - assert!(!(a.is_empty() && !b.is_empty()), "panic3"); - assert!(!(b.is_empty() || a.is_empty()), "panic4"); - assert!(!(a.is_empty() || !b.is_empty()), "panic5"); - assert!(!a.is_empty(), "with expansion {}", one!()); - if a.is_empty() { - let _ = 0; - } else if a.len() == 1 { - panic!("panic6"); - } -} - -fn issue7730(a: u8) { - // Suggestion should preserve comment - // comment -/* this is a - multiline - comment */ -/// Doc comment -// comment after `panic!` -if a > 2 { - // comment - /* this is a - multiline - comment */ - /// Doc comment - panic!("panic with comment") // comment after `panic!` - } -} - -fn issue12505() { - struct Foo(T); - - impl Foo { - const BAR: () = assert!(!(N == 0), ); - } -} diff --git a/tests/ui/manual_assert.edition2018.2.fixed b/tests/ui/manual_assert.edition2018.2.fixed deleted file mode 100644 index 67434e75b11e..000000000000 --- a/tests/ui/manual_assert.edition2018.2.fixed +++ /dev/null @@ -1,70 +0,0 @@ -//@revisions: edition2018 edition2021 -//@[edition2018] edition:2018 -//@[edition2021] edition:2021 - -#![warn(clippy::manual_assert)] -#![allow(dead_code, unused_doc_comments)] -#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args, clippy::useless_vec)] - -macro_rules! one { - () => { - 1 - }; -} - -fn main() { - let a = vec![1, 2, 3]; - let c = Some(2); - if !a.is_empty() - && a.len() == 3 - && c.is_some() - && !a.is_empty() - && a.len() == 3 - && !a.is_empty() - && a.len() == 3 - && !a.is_empty() - && a.len() == 3 - { - panic!("qaqaq{:?}", a); - } - assert!(a.is_empty(), "qaqaq{:?}", a); - assert!(a.is_empty(), "qwqwq"); - if a.len() == 3 { - println!("qwq"); - println!("qwq"); - println!("qwq"); - } - if let Some(b) = c { - panic!("orz {}", b); - } - if a.len() == 3 { - panic!("qaqaq"); - } else { - println!("qwq"); - } - let b = vec![1, 2, 3]; - assert!(!b.is_empty(), "panic1"); - assert!(!(b.is_empty() && a.is_empty()), "panic2"); - assert!(!(a.is_empty() && !b.is_empty()), "panic3"); - assert!(!(b.is_empty() || a.is_empty()), "panic4"); - assert!(!(a.is_empty() || !b.is_empty()), "panic5"); - assert!(!a.is_empty(), "with expansion {}", one!()); - if a.is_empty() { - let _ = 0; - } else if a.len() == 1 { - panic!("panic6"); - } -} - -fn issue7730(a: u8) { - // Suggestion should preserve comment - assert!(!(a > 2), "panic with comment"); -} - -fn issue12505() { - struct Foo(T); - - impl Foo { - const BAR: () = assert!(!(N == 0), ); - } -} diff --git a/tests/ui/manual_assert.edition2018.stderr b/tests/ui/manual_assert.edition2018.stderr index a8f3896996de..62701cd3d82c 100644 --- a/tests/ui/manual_assert.edition2018.stderr +++ b/tests/ui/manual_assert.edition2018.stderr @@ -1,95 +1,77 @@ -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:30:5 - | -LL | / if !a.is_empty() { -LL | | panic!("qaqaq{:?}", a); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(a.is_empty(), "qaqaq{:?}", a);` - | - = note: `-D clippy::manual-assert` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::manual_assert)]` +thread 'rustc' panicked at /Users/scott.gerring/Documents/code/3rdparty/rust-clippy/clippy_utils/src/diagnostics.rs:50:9: +assertion `left == right` failed: span must not be empty and have no suggestion + left: Some(SubstitutionPart { span: tests/ui/manual_assert.rs:30:5: 30:5 (#0), snippet: "" }) + right: None +stack backtrace: + 0: 0x1127b15b8 - ::fmt::hd5de7b0df0729e03 + 1: 0x10fa14e64 - core::fmt::write::h2d6cb8c661d0a83d + 2: 0x1127a5960 - std::io::Write::write_fmt::h0f134b74b751e0f9 + 3: 0x1127b1478 - std::sys::backtrace::BacktraceLock::print::h93b2b495ebfc2cb2 + 4: 0x1127b3948 - std::panicking::default_hook::{{closure}}::h5e69c7a046eca612 + 5: 0x1127b3790 - std::panicking::default_hook::h9f5f5724d303148a + 6: 0x11061e57c - as core[1a7bc357c76bf42]::ops::function::Fn<(&dyn for<'a, 'b> core[1a7bc357c76bf42]::ops::function::Fn<(&'a std[a184c2360da8cf6c]::panic::PanicHookInfo<'b>,), Output = ()> + core[1a7bc357c76bf42]::marker::Send + core[1a7bc357c76bf42]::marker::Sync, &std[a184c2360da8cf6c]::panic::PanicHookInfo)>>::call + 7: 0x1127b4214 - std::panicking::rust_panic_with_hook::hab3d98f4160d14fd + 8: 0x1127b3e50 - std::panicking::begin_panic_handler::{{closure}}::h1577ffea1a58f5f7 + 9: 0x1127b1a54 - std::sys::backtrace::__rust_end_short_backtrace::hae37950ca15bb119 + 10: 0x1127b3b14 - _rust_begin_unwind + 11: 0x114e9725c - core::panicking::panic_fmt::h987dd6a54d7aba16 + 12: 0x114e975f0 - core::panicking::assert_failed_inner::h12c770c2425fee7d + 13: 0x103102510 - core::panicking::assert_failed::hc915165530e4fffb + at /Users/scott.gerring/.rustup/toolchains/nightly-2024-11-28-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/panicking.rs:373:5 + 14: 0x102190eac - clippy_utils::diagnostics::validate_diag::h239c2d3579525ceb + at /Users/scott.gerring/Documents/code/3rdparty/rust-clippy/clippy_utils/src/diagnostics.rs:50:9 + 15: 0x1021a7d1c - clippy_utils::diagnostics::span_lint_and_then::{{closure}}::h9b8b186ec716fe56 + at /Users/scott.gerring/Documents/code/3rdparty/rust-clippy/clippy_utils/src/diagnostics.rs:261:9 + 16: 0x102880df4 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hf14a66775935d916 + at /Users/scott.gerring/.rustup/toolchains/nightly-2024-11-28-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5 + 17: 0x1113b1670 - rustc_middle[7019c7ba16fcd5cd]::lint::lint_level::lint_level_impl + 18: 0x102420a80 - rustc_middle::lint::lint_level::hcb523238415a1e29 + at /Users/scott.gerring/.rustup/toolchains/nightly-2024-11-28-aarch64-apple-darwin/lib/rustlib/src/rust/compiler/rustc_middle/src/lint.rs:423:5 + 19: 0x102900f00 - rustc_middle::ty::context::TyCtxt::node_span_lint::h7532365959f7d1f5 + at /Users/scott.gerring/.rustup/toolchains/nightly-2024-11-28-aarch64-apple-darwin/lib/rustlib/src/rust/compiler/rustc_middle/src/ty/context.rs:2950:9 + 20: 0x10273a51c - ::opt_span_lint::hfbf1866d04803dc5 + at /Users/scott.gerring/.rustup/toolchains/nightly-2024-11-28-aarch64-apple-darwin/lib/rustlib/src/rust/compiler/rustc_lint/src/context.rs:669:24 + 21: 0x10271cc1c - rustc_lint::context::LintContext::span_lint::h28363b347076190e + at /Users/scott.gerring/.rustup/toolchains/nightly-2024-11-28-aarch64-apple-darwin/lib/rustlib/src/rust/compiler/rustc_lint/src/context.rs:585:9 + 22: 0x1021969c0 - clippy_utils::diagnostics::span_lint_and_then::h479f5abc48e54fa2 + at /Users/scott.gerring/Documents/code/3rdparty/rust-clippy/clippy_utils/src/diagnostics.rs:255:5 + 23: 0x102835ee4 - ::check_expr::hbc06e8db702404ba + at /Users/scott.gerring/Documents/code/3rdparty/rust-clippy/clippy_lints/src/manual_assert.rs:66:13 + 24: 0x11113bf8c - as rustc_hir[e37c4407e29c46ca]::intravisit::Visitor>::visit_expr::{closure#0} + 25: 0x111082e60 - rustc_hir[e37c4407e29c46ca]::intravisit::walk_expr::> + 26: 0x11113bfa0 - as rustc_hir[e37c4407e29c46ca]::intravisit::Visitor>::visit_expr::{closure#0} + 27: 0x11113b44c - as rustc_hir[e37c4407e29c46ca]::intravisit::Visitor>::visit_nested_body + 28: 0x11113c398 - as rustc_hir[e37c4407e29c46ca]::intravisit::Visitor>::visit_fn + 29: 0x111084964 - rustc_hir[e37c4407e29c46ca]::intravisit::walk_item::> + 30: 0x111134a3c - as rustc_hir[e37c4407e29c46ca]::intravisit::Visitor>::visit_nested_item + 31: 0x11113e570 - rustc_lint[385369ae408eed1c]::late::check_crate::{closure#0} + 32: 0x11113dc0c - rustc_lint[385369ae408eed1c]::late::check_crate + 33: 0x110f41640 - ::time::<(), rustc_interface[e97b870a1f7a7bd5]::passes::analysis::{closure#0}> + 34: 0x110ff20bc - rustc_interface[e97b870a1f7a7bd5]::passes::analysis + 35: 0x111ce813c - rustc_query_impl[3faacfedda06551]::plumbing::__rust_begin_short_backtrace::> + 36: 0x111e2433c - >::call_once + 37: 0x111bf6828 - rustc_query_system[bd441621c7ea624b]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[3faacfedda06551]::plumbing::QueryCtxt, false> + 38: 0x111d6e564 - rustc_query_impl[3faacfedda06551]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace + 39: 0x110620300 - ::enter::> + 40: 0x1105d716c - ::enter::, rustc_span[961a2807afbea68d]::ErrorGuaranteed>> + 41: 0x110610b60 - rustc_span[961a2807afbea68d]::create_session_globals_then::, rustc_interface[e97b870a1f7a7bd5]::util::run_in_thread_with_globals, rustc_driver_impl[17a93adec6f3d70a]::run_compiler::{closure#0}>::{closure#1}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#0}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}> + 42: 0x11064249c - std[a184c2360da8cf6c]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[17a93adec6f3d70a]::run_compiler::{closure#0}>::{closure#1}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#0}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>> + 43: 0x110645424 - <::spawn_unchecked_, rustc_driver_impl[17a93adec6f3d70a]::run_compiler::{closure#0}>::{closure#1}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#0}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#1} as core[1a7bc357c76bf42]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} + 44: 0x1127be2d4 - std::sys::pal::unix::thread::Thread::new::thread_start::h0b41f7e8e279ede6 + 45: 0x193cbdf94 - __pthread_joiner_wake -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:33:5 - | -LL | / if !a.is_empty() { -LL | | panic!("qwqwq"); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(a.is_empty(), "qwqwq");` +error: the compiler unexpectedly panicked. this is a bug. -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:50:5 - | -LL | / if b.is_empty() { -LL | | panic!("panic1"); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!b.is_empty(), "panic1");` +note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:53:5 - | -LL | / if b.is_empty() && a.is_empty() { -LL | | panic!("panic2"); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!(b.is_empty() && a.is_empty()), "panic2");` +note: please make sure that you have updated to the latest nightly -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:56:5 - | -LL | / if a.is_empty() && !b.is_empty() { -LL | | panic!("panic3"); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");` +note: rustc 1.85.0-nightly (6b6a867ae 2024-11-27) running on aarch64-apple-darwin -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:59:5 - | -LL | / if b.is_empty() || a.is_empty() { -LL | | panic!("panic4"); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!(b.is_empty() || a.is_empty()), "panic4");` +note: compiler flags: -Z ui-testing -Z deduplicate-diagnostics=no -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:62:5 - | -LL | / if a.is_empty() || !b.is_empty() { -LL | | panic!("panic5"); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");` - -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:65:5 - | -LL | / if a.is_empty() { -LL | | panic!("with expansion {}", one!()) -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!a.is_empty(), "with expansion {}", one!());` - -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:77:5 - | -LL | / if a > 2 { -LL | | // comment -LL | | /* this is a -LL | | multiline -... | -LL | | panic!("panic with comment") // comment after `panic!` -LL | | } - | |_____^ - | -help: replace `if`-then-`panic!` with `assert!` - | -LL | assert!(!(a > 2), "panic with comment"); - | - -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:91:25 - | -LL | const BAR: () = if N == 0 { - | _________________________^ -LL | | panic!() -LL | | }; - | |_________^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!(N == 0), )` - -error: aborting due to 10 previous errors +query stack during panic: +#0 [analysis] running analysis passes on this crate +end of query stack +note: Clippy version: clippy 0.1.85 (4afba90b20 2024-12-11) diff --git a/tests/ui/manual_assert.edition2021.1.fixed b/tests/ui/manual_assert.edition2021.1.fixed deleted file mode 100644 index 8de36a4c7f15..000000000000 --- a/tests/ui/manual_assert.edition2021.1.fixed +++ /dev/null @@ -1,83 +0,0 @@ -//@revisions: edition2018 edition2021 -//@[edition2018] edition:2018 -//@[edition2021] edition:2021 - -#![warn(clippy::manual_assert)] -#![allow(dead_code, unused_doc_comments)] -#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args, clippy::useless_vec)] - -macro_rules! one { - () => { - 1 - }; -} - -fn main() { - let a = vec![1, 2, 3]; - let c = Some(2); - if !a.is_empty() - && a.len() == 3 - && c.is_some() - && !a.is_empty() - && a.len() == 3 - && !a.is_empty() - && a.len() == 3 - && !a.is_empty() - && a.len() == 3 - { - panic!("qaqaq{:?}", a); - } - assert!(a.is_empty(), "qaqaq{:?}", a); - assert!(a.is_empty(), "qwqwq"); - if a.len() == 3 { - println!("qwq"); - println!("qwq"); - println!("qwq"); - } - if let Some(b) = c { - panic!("orz {}", b); - } - if a.len() == 3 { - panic!("qaqaq"); - } else { - println!("qwq"); - } - let b = vec![1, 2, 3]; - assert!(!b.is_empty(), "panic1"); - assert!(!(b.is_empty() && a.is_empty()), "panic2"); - assert!(!(a.is_empty() && !b.is_empty()), "panic3"); - assert!(!(b.is_empty() || a.is_empty()), "panic4"); - assert!(!(a.is_empty() || !b.is_empty()), "panic5"); - assert!(!a.is_empty(), "with expansion {}", one!()); - if a.is_empty() { - let _ = 0; - } else if a.len() == 1 { - panic!("panic6"); - } -} - -fn issue7730(a: u8) { - // Suggestion should preserve comment - // comment -/* this is a - multiline - comment */ -/// Doc comment -// comment after `panic!` -if a > 2 { - // comment - /* this is a - multiline - comment */ - /// Doc comment - panic!("panic with comment") // comment after `panic!` - } -} - -fn issue12505() { - struct Foo(T); - - impl Foo { - const BAR: () = assert!(!(N == 0), ); - } -} diff --git a/tests/ui/manual_assert.edition2021.2.fixed b/tests/ui/manual_assert.edition2021.2.fixed deleted file mode 100644 index 67434e75b11e..000000000000 --- a/tests/ui/manual_assert.edition2021.2.fixed +++ /dev/null @@ -1,70 +0,0 @@ -//@revisions: edition2018 edition2021 -//@[edition2018] edition:2018 -//@[edition2021] edition:2021 - -#![warn(clippy::manual_assert)] -#![allow(dead_code, unused_doc_comments)] -#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args, clippy::useless_vec)] - -macro_rules! one { - () => { - 1 - }; -} - -fn main() { - let a = vec![1, 2, 3]; - let c = Some(2); - if !a.is_empty() - && a.len() == 3 - && c.is_some() - && !a.is_empty() - && a.len() == 3 - && !a.is_empty() - && a.len() == 3 - && !a.is_empty() - && a.len() == 3 - { - panic!("qaqaq{:?}", a); - } - assert!(a.is_empty(), "qaqaq{:?}", a); - assert!(a.is_empty(), "qwqwq"); - if a.len() == 3 { - println!("qwq"); - println!("qwq"); - println!("qwq"); - } - if let Some(b) = c { - panic!("orz {}", b); - } - if a.len() == 3 { - panic!("qaqaq"); - } else { - println!("qwq"); - } - let b = vec![1, 2, 3]; - assert!(!b.is_empty(), "panic1"); - assert!(!(b.is_empty() && a.is_empty()), "panic2"); - assert!(!(a.is_empty() && !b.is_empty()), "panic3"); - assert!(!(b.is_empty() || a.is_empty()), "panic4"); - assert!(!(a.is_empty() || !b.is_empty()), "panic5"); - assert!(!a.is_empty(), "with expansion {}", one!()); - if a.is_empty() { - let _ = 0; - } else if a.len() == 1 { - panic!("panic6"); - } -} - -fn issue7730(a: u8) { - // Suggestion should preserve comment - assert!(!(a > 2), "panic with comment"); -} - -fn issue12505() { - struct Foo(T); - - impl Foo { - const BAR: () = assert!(!(N == 0), ); - } -} diff --git a/tests/ui/manual_assert.edition2021.stderr b/tests/ui/manual_assert.edition2021.stderr index a8f3896996de..d3349eff330f 100644 --- a/tests/ui/manual_assert.edition2021.stderr +++ b/tests/ui/manual_assert.edition2021.stderr @@ -1,95 +1,77 @@ -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:30:5 - | -LL | / if !a.is_empty() { -LL | | panic!("qaqaq{:?}", a); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(a.is_empty(), "qaqaq{:?}", a);` - | - = note: `-D clippy::manual-assert` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::manual_assert)]` +thread 'rustc' panicked at /Users/scott.gerring/Documents/code/3rdparty/rust-clippy/clippy_utils/src/diagnostics.rs:50:9: +assertion `left == right` failed: span must not be empty and have no suggestion + left: Some(SubstitutionPart { span: tests/ui/manual_assert.rs:30:5: 30:5 (#0), snippet: "" }) + right: None +stack backtrace: + 0: 0x1149315b8 - ::fmt::hd5de7b0df0729e03 + 1: 0x111b94e64 - core::fmt::write::h2d6cb8c661d0a83d + 2: 0x114925960 - std::io::Write::write_fmt::h0f134b74b751e0f9 + 3: 0x114931478 - std::sys::backtrace::BacktraceLock::print::h93b2b495ebfc2cb2 + 4: 0x114933948 - std::panicking::default_hook::{{closure}}::h5e69c7a046eca612 + 5: 0x114933790 - std::panicking::default_hook::h9f5f5724d303148a + 6: 0x11279e57c - as core[1a7bc357c76bf42]::ops::function::Fn<(&dyn for<'a, 'b> core[1a7bc357c76bf42]::ops::function::Fn<(&'a std[a184c2360da8cf6c]::panic::PanicHookInfo<'b>,), Output = ()> + core[1a7bc357c76bf42]::marker::Send + core[1a7bc357c76bf42]::marker::Sync, &std[a184c2360da8cf6c]::panic::PanicHookInfo)>>::call + 7: 0x114934214 - std::panicking::rust_panic_with_hook::hab3d98f4160d14fd + 8: 0x114933e50 - std::panicking::begin_panic_handler::{{closure}}::h1577ffea1a58f5f7 + 9: 0x114931a54 - std::sys::backtrace::__rust_end_short_backtrace::hae37950ca15bb119 + 10: 0x114933b14 - _rust_begin_unwind + 11: 0x11701725c - core::panicking::panic_fmt::h987dd6a54d7aba16 + 12: 0x1170175f0 - core::panicking::assert_failed_inner::h12c770c2425fee7d + 13: 0x105282510 - core::panicking::assert_failed::hc915165530e4fffb + at /Users/scott.gerring/.rustup/toolchains/nightly-2024-11-28-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/panicking.rs:373:5 + 14: 0x104310eac - clippy_utils::diagnostics::validate_diag::h239c2d3579525ceb + at /Users/scott.gerring/Documents/code/3rdparty/rust-clippy/clippy_utils/src/diagnostics.rs:50:9 + 15: 0x104327d1c - clippy_utils::diagnostics::span_lint_and_then::{{closure}}::h9b8b186ec716fe56 + at /Users/scott.gerring/Documents/code/3rdparty/rust-clippy/clippy_utils/src/diagnostics.rs:261:9 + 16: 0x104a00df4 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hf14a66775935d916 + at /Users/scott.gerring/.rustup/toolchains/nightly-2024-11-28-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5 + 17: 0x113531670 - rustc_middle[7019c7ba16fcd5cd]::lint::lint_level::lint_level_impl + 18: 0x1045a0a80 - rustc_middle::lint::lint_level::hcb523238415a1e29 + at /Users/scott.gerring/.rustup/toolchains/nightly-2024-11-28-aarch64-apple-darwin/lib/rustlib/src/rust/compiler/rustc_middle/src/lint.rs:423:5 + 19: 0x104a80f00 - rustc_middle::ty::context::TyCtxt::node_span_lint::h7532365959f7d1f5 + at /Users/scott.gerring/.rustup/toolchains/nightly-2024-11-28-aarch64-apple-darwin/lib/rustlib/src/rust/compiler/rustc_middle/src/ty/context.rs:2950:9 + 20: 0x1048ba51c - ::opt_span_lint::hfbf1866d04803dc5 + at /Users/scott.gerring/.rustup/toolchains/nightly-2024-11-28-aarch64-apple-darwin/lib/rustlib/src/rust/compiler/rustc_lint/src/context.rs:669:24 + 21: 0x10489cc1c - rustc_lint::context::LintContext::span_lint::h28363b347076190e + at /Users/scott.gerring/.rustup/toolchains/nightly-2024-11-28-aarch64-apple-darwin/lib/rustlib/src/rust/compiler/rustc_lint/src/context.rs:585:9 + 22: 0x1043169c0 - clippy_utils::diagnostics::span_lint_and_then::h479f5abc48e54fa2 + at /Users/scott.gerring/Documents/code/3rdparty/rust-clippy/clippy_utils/src/diagnostics.rs:255:5 + 23: 0x1049b5ee4 - ::check_expr::hbc06e8db702404ba + at /Users/scott.gerring/Documents/code/3rdparty/rust-clippy/clippy_lints/src/manual_assert.rs:66:13 + 24: 0x1132bbf8c - as rustc_hir[e37c4407e29c46ca]::intravisit::Visitor>::visit_expr::{closure#0} + 25: 0x113202e60 - rustc_hir[e37c4407e29c46ca]::intravisit::walk_expr::> + 26: 0x1132bbfa0 - as rustc_hir[e37c4407e29c46ca]::intravisit::Visitor>::visit_expr::{closure#0} + 27: 0x1132bb44c - as rustc_hir[e37c4407e29c46ca]::intravisit::Visitor>::visit_nested_body + 28: 0x1132bc398 - as rustc_hir[e37c4407e29c46ca]::intravisit::Visitor>::visit_fn + 29: 0x113204964 - rustc_hir[e37c4407e29c46ca]::intravisit::walk_item::> + 30: 0x1132b4a3c - as rustc_hir[e37c4407e29c46ca]::intravisit::Visitor>::visit_nested_item + 31: 0x1132be570 - rustc_lint[385369ae408eed1c]::late::check_crate::{closure#0} + 32: 0x1132bdc0c - rustc_lint[385369ae408eed1c]::late::check_crate + 33: 0x1130c1640 - ::time::<(), rustc_interface[e97b870a1f7a7bd5]::passes::analysis::{closure#0}> + 34: 0x1131720bc - rustc_interface[e97b870a1f7a7bd5]::passes::analysis + 35: 0x113e6813c - rustc_query_impl[3faacfedda06551]::plumbing::__rust_begin_short_backtrace::> + 36: 0x113fa433c - >::call_once + 37: 0x113d76828 - rustc_query_system[bd441621c7ea624b]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[3faacfedda06551]::plumbing::QueryCtxt, false> + 38: 0x113eee564 - rustc_query_impl[3faacfedda06551]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace + 39: 0x1127a0300 - ::enter::> + 40: 0x11275716c - ::enter::, rustc_span[961a2807afbea68d]::ErrorGuaranteed>> + 41: 0x112790b60 - rustc_span[961a2807afbea68d]::create_session_globals_then::, rustc_interface[e97b870a1f7a7bd5]::util::run_in_thread_with_globals, rustc_driver_impl[17a93adec6f3d70a]::run_compiler::{closure#0}>::{closure#1}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#0}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}> + 42: 0x1127c249c - std[a184c2360da8cf6c]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[17a93adec6f3d70a]::run_compiler::{closure#0}>::{closure#1}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#0}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>> + 43: 0x1127c5424 - <::spawn_unchecked_, rustc_driver_impl[17a93adec6f3d70a]::run_compiler::{closure#0}>::{closure#1}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#0}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1a7bc357c76bf42]::result::Result<(), rustc_span[961a2807afbea68d]::ErrorGuaranteed>>::{closure#1} as core[1a7bc357c76bf42]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} + 44: 0x11493e2d4 - std::sys::pal::unix::thread::Thread::new::thread_start::h0b41f7e8e279ede6 + 45: 0x193cbdf94 - __pthread_joiner_wake -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:33:5 - | -LL | / if !a.is_empty() { -LL | | panic!("qwqwq"); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(a.is_empty(), "qwqwq");` +error: the compiler unexpectedly panicked. this is a bug. -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:50:5 - | -LL | / if b.is_empty() { -LL | | panic!("panic1"); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!b.is_empty(), "panic1");` +note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:53:5 - | -LL | / if b.is_empty() && a.is_empty() { -LL | | panic!("panic2"); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!(b.is_empty() && a.is_empty()), "panic2");` +note: please make sure that you have updated to the latest nightly -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:56:5 - | -LL | / if a.is_empty() && !b.is_empty() { -LL | | panic!("panic3"); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");` +note: rustc 1.85.0-nightly (6b6a867ae 2024-11-27) running on aarch64-apple-darwin -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:59:5 - | -LL | / if b.is_empty() || a.is_empty() { -LL | | panic!("panic4"); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!(b.is_empty() || a.is_empty()), "panic4");` +note: compiler flags: -Z ui-testing -Z deduplicate-diagnostics=no -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:62:5 - | -LL | / if a.is_empty() || !b.is_empty() { -LL | | panic!("panic5"); -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");` - -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:65:5 - | -LL | / if a.is_empty() { -LL | | panic!("with expansion {}", one!()) -LL | | } - | |_____^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!a.is_empty(), "with expansion {}", one!());` - -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:77:5 - | -LL | / if a > 2 { -LL | | // comment -LL | | /* this is a -LL | | multiline -... | -LL | | panic!("panic with comment") // comment after `panic!` -LL | | } - | |_____^ - | -help: replace `if`-then-`panic!` with `assert!` - | -LL | assert!(!(a > 2), "panic with comment"); - | - -error: only a `panic!` in `if`-then statement - --> tests/ui/manual_assert.rs:91:25 - | -LL | const BAR: () = if N == 0 { - | _________________________^ -LL | | panic!() -LL | | }; - | |_________^ help: replace `if`-then-`panic!` with `assert!`: `assert!(!(N == 0), )` - -error: aborting due to 10 previous errors +query stack during panic: +#0 [analysis] running analysis passes on this crate +end of query stack +note: Clippy version: clippy 0.1.85 (4afba90b20 2024-12-11)