Skip to content

Commit 69f2493

Browse files
committed
clean-up a bit
1 parent 49e2f37 commit 69f2493

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

clippy_lints/src/manual_assert.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::macros::{is_panic, root_macro_call};
3-
use clippy_utils::{higher, is_else_clause, is_parent_stmt, peel_blocks_with_stmt, span_extract_comment, sugg};
3+
use clippy_utils::source::snippet_opt;
4+
use clippy_utils::sugg::Sugg;
5+
use clippy_utils::{higher, is_else_clause, is_parent_stmt, peel_blocks_with_stmt, span_extract_comment};
46
use rustc_errors::Applicability;
57
use rustc_hir::{Expr, ExprKind};
68
use rustc_lint::{LateContext, LateLintPass, LintContext};
@@ -41,8 +43,8 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert {
4143
&& let then = peel_blocks_with_stmt(then)
4244
&& let Some(macro_call) = root_macro_call(then.span)
4345
&& is_panic(cx, macro_call.def_id)
44-
&& !cx.tcx.sess.source_map().is_multiline(cond.span)
45-
&& let Ok(panic_snippet) = cx.sess().source_map().span_to_snippet(macro_call.span)
46+
&& !cx.sess().source_map().is_multiline(cond.span)
47+
&& let Some(panic_snippet) = snippet_opt(cx.sess(), macro_call.span)
4648
&& let Some(panic_snippet) = panic_snippet.strip_suffix(')')
4749
&& let Some((_, format_args_snip)) = panic_snippet.split_once('(')
4850
// Don't change `else if foo { panic!(..) }` to `else { assert!(foo, ..) }` as it just
@@ -55,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert {
5557
if !comments.is_empty() {
5658
comments += "\n";
5759
}
58-
let cond_sugg = !sugg::Sugg::hir_with_context(cx, cond, expr.span.ctxt(), "..", &mut applicability);
60+
let cond_sugg = !Sugg::hir_with_context(cx, cond, expr.span.ctxt(), "..", &mut applicability);
5961
let semicolon = if is_parent_stmt(cx, expr.hir_id) { ";" } else { "" };
6062
let sugg = format!("assert!({cond_sugg}, {format_args_snip}){semicolon}");
6163
// we show to the user the suggestion without the comments, but when applying the fix, include the

0 commit comments

Comments
 (0)