|
1 | | -use clippy_utils::diagnostics::span_lint_and_sugg; |
| 1 | +use clippy_utils::diagnostics::span_lint_and_then; |
2 | 2 | use clippy_utils::is_lint_allowed; |
3 | 3 | use clippy_utils::macros::span_is_local; |
4 | 4 | use clippy_utils::source::snippet; |
@@ -105,45 +105,51 @@ fn check_str(cx: &LateContext<'_>, span: Span, id: HirId) { |
105 | 105 |
|
106 | 106 | let string = snippet(cx, span, ""); |
107 | 107 | if string.chars().any(|c| ['\u{200B}', '\u{ad}', '\u{2060}'].contains(&c)) { |
108 | | - span_lint_and_sugg( |
109 | | - cx, |
110 | | - INVISIBLE_CHARACTERS, |
111 | | - span, |
112 | | - "invisible character detected", |
113 | | - "consider replacing the string with", |
114 | | - string |
115 | | - .replace('\u{200B}', "\\u{200B}") |
116 | | - .replace('\u{ad}', "\\u{AD}") |
117 | | - .replace('\u{2060}', "\\u{2060}"), |
118 | | - Applicability::MachineApplicable, |
119 | | - ); |
| 108 | + #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")] |
| 109 | + span_lint_and_then(cx, INVISIBLE_CHARACTERS, span, "invisible character detected", |diag| { |
| 110 | + diag.span_suggestion( |
| 111 | + span, |
| 112 | + "consider replacing the string with", |
| 113 | + string |
| 114 | + .replace('\u{200B}', "\\u{200B}") |
| 115 | + .replace('\u{ad}', "\\u{AD}") |
| 116 | + .replace('\u{2060}', "\\u{2060}"), |
| 117 | + Applicability::MachineApplicable, |
| 118 | + ); |
| 119 | + }); |
120 | 120 | } |
121 | 121 |
|
122 | 122 | if string.chars().any(|c| c as u32 > 0x7F) { |
123 | | - span_lint_and_sugg( |
| 123 | + #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")] |
| 124 | + span_lint_and_then( |
124 | 125 | cx, |
125 | 126 | NON_ASCII_LITERAL, |
126 | 127 | span, |
127 | 128 | "literal non-ASCII character detected", |
128 | | - "consider replacing the string with", |
129 | | - if is_lint_allowed(cx, UNICODE_NOT_NFC, id) { |
130 | | - escape(string.chars()) |
131 | | - } else { |
132 | | - escape(string.nfc()) |
| 129 | + |diag| { |
| 130 | + diag.span_suggestion( |
| 131 | + span, |
| 132 | + "consider replacing the string with", |
| 133 | + if is_lint_allowed(cx, UNICODE_NOT_NFC, id) { |
| 134 | + escape(string.chars()) |
| 135 | + } else { |
| 136 | + escape(string.nfc()) |
| 137 | + }, |
| 138 | + Applicability::MachineApplicable, |
| 139 | + ); |
133 | 140 | }, |
134 | | - Applicability::MachineApplicable, |
135 | 141 | ); |
136 | 142 | } |
137 | 143 |
|
138 | 144 | if is_lint_allowed(cx, NON_ASCII_LITERAL, id) && string.chars().zip(string.nfc()).any(|(a, b)| a != b) { |
139 | | - span_lint_and_sugg( |
140 | | - cx, |
141 | | - UNICODE_NOT_NFC, |
142 | | - span, |
143 | | - "non-NFC Unicode sequence detected", |
144 | | - "consider replacing the string with", |
145 | | - string.nfc().collect::<String>(), |
146 | | - Applicability::MachineApplicable, |
147 | | - ); |
| 145 | + #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")] |
| 146 | + span_lint_and_then(cx, UNICODE_NOT_NFC, span, "non-NFC Unicode sequence detected", |diag| { |
| 147 | + diag.span_suggestion( |
| 148 | + span, |
| 149 | + "consider replacing the string with", |
| 150 | + string.nfc().collect::<String>(), |
| 151 | + Applicability::MachineApplicable, |
| 152 | + ); |
| 153 | + }); |
148 | 154 | } |
149 | 155 | } |
0 commit comments