|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_then; |
2 | 2 | use clippy_utils::macros::{find_assert_eq_args, root_macro_call_first_node}; |
| 3 | +use clippy_utils::source::walk_span_to_context; |
3 | 4 | use clippy_utils::sugg::Sugg; |
4 | 5 | use clippy_utils::sym; |
5 | 6 | use clippy_utils::ty::{implements_trait, is_copy}; |
@@ -130,22 +131,24 @@ impl<'tcx> LateLintPass<'tcx> for BoolAssertComparison { |
130 | 131 |
|
131 | 132 | let mut suggestions = vec![(name_span, non_eq_mac.to_string()), (lit_span, String::new())]; |
132 | 133 |
|
133 | | - if let Some(sugg) = Sugg::hir_opt(cx, non_lit_expr) { |
134 | | - let sugg = if bool_value ^ eq_macro { |
135 | | - !sugg.maybe_paren() |
136 | | - } else if ty::Bool == *non_lit_ty.kind() { |
137 | | - sugg |
138 | | - } else { |
139 | | - !!sugg.maybe_paren() |
140 | | - }; |
141 | | - suggestions.push((non_lit_expr.span, sugg.to_string())); |
| 134 | + let mut applicability = Applicability::MachineApplicable; |
| 135 | + let sugg = Sugg::hir_with_context(cx, non_lit_expr, macro_call.span.ctxt(), "..", &mut applicability); |
| 136 | + let sugg = if bool_value ^ eq_macro { |
| 137 | + !sugg.maybe_paren() |
| 138 | + } else if ty::Bool == *non_lit_ty.kind() { |
| 139 | + sugg |
| 140 | + } else { |
| 141 | + !!sugg.maybe_paren() |
| 142 | + }; |
| 143 | + let non_lit_expr_span = |
| 144 | + walk_span_to_context(non_lit_expr.span, macro_call.span.ctxt()).unwrap_or(non_lit_expr.span); |
| 145 | + suggestions.push((non_lit_expr_span, sugg.to_string())); |
142 | 146 |
|
143 | | - diag.multipart_suggestion( |
144 | | - format!("replace it with `{non_eq_mac}!(..)`"), |
145 | | - suggestions, |
146 | | - Applicability::MachineApplicable, |
147 | | - ); |
148 | | - } |
| 147 | + diag.multipart_suggestion( |
| 148 | + format!("replace it with `{non_eq_mac}!(..)`"), |
| 149 | + suggestions, |
| 150 | + applicability, |
| 151 | + ); |
149 | 152 | }, |
150 | 153 | ); |
151 | 154 | } |
|
0 commit comments