|
8 | 8 | //! Thank you!
|
9 | 9 | //! ~The `INTERNAL_METADATA_COLLECTOR` lint
|
10 | 10 |
|
11 |
| -use rustc_errors::{emitter::MAX_SUGGESTION_HIGHLIGHT_LINES, Applicability, Diagnostic, MultiSpan}; |
| 11 | +use rustc_errors::{Applicability, Diagnostic, MultiSpan}; |
12 | 12 | use rustc_hir::HirId;
|
13 | 13 | use rustc_lint::{LateContext, Lint, LintContext};
|
14 | 14 | use rustc_span::source_map::Span;
|
@@ -213,93 +213,6 @@ pub fn span_lint_and_sugg<'a, T: LintContext>(
|
213 | 213 | });
|
214 | 214 | }
|
215 | 215 |
|
216 |
| -/// Like [`span_lint_and_sugg`] with a focus on the edges. The output will either |
217 |
| -/// emit single span or multispan suggestion depending on the number of its lines. |
218 |
| -/// |
219 |
| -/// If the given suggestion string has more lines than the maximum display length defined by |
220 |
| -/// [`MAX_SUGGESTION_HIGHLIGHT_LINES`][`rustc_errors::emitter::MAX_SUGGESTION_HIGHLIGHT_LINES`], |
221 |
| -/// this function will split the suggestion and span to showcase the change for the top and |
222 |
| -/// bottom edge of the code. For normal suggestions, in one display window, the help message |
223 |
| -/// will be combined with a colon. |
224 |
| -/// |
225 |
| -/// Multipart suggestions like the one being created here currently cannot be |
226 |
| -/// applied by rustfix (See [rustfix#141](https://github.com/rust-lang/rustfix/issues/141)). |
227 |
| -/// Testing rustfix with this lint emission function might require a file with |
228 |
| -/// suggestions that can be fixed and those that can't. See |
229 |
| -/// [clippy#8520](https://github.com/rust-lang/rust-clippy/pull/8520/files) for |
230 |
| -/// an example and of this. |
231 |
| -/// |
232 |
| -/// # Example for a long suggestion |
233 |
| -/// |
234 |
| -/// ```text |
235 |
| -/// error: called `map(..).flatten()` on `Option` |
236 |
| -/// --> $DIR/map_flatten.rs:8:10 |
237 |
| -/// | |
238 |
| -/// LL | .map(|x| { |
239 |
| -/// | __________^ |
240 |
| -/// LL | | if x <= 5 { |
241 |
| -/// LL | | Some(x) |
242 |
| -/// LL | | } else { |
243 |
| -/// ... | |
244 |
| -/// LL | | }) |
245 |
| -/// LL | | .flatten(); |
246 |
| -/// | |__________________^ |
247 |
| -/// | |
248 |
| -/// = note: `-D clippy::map-flatten` implied by `-D warnings` |
249 |
| -/// help: try replacing `map` with `and_then` |
250 |
| -/// | |
251 |
| -/// LL ~ .and_then(|x| { |
252 |
| -/// LL + if x <= 5 { |
253 |
| -/// LL + Some(x) |
254 |
| -/// | |
255 |
| -/// help: and remove the `.flatten()` |
256 |
| -/// | |
257 |
| -/// LL + None |
258 |
| -/// LL + } |
259 |
| -/// LL ~ }); |
260 |
| -/// | |
261 |
| -/// ``` |
262 |
| -pub fn span_lint_and_sugg_for_edges( |
263 |
| - cx: &LateContext<'_>, |
264 |
| - lint: &'static Lint, |
265 |
| - sp: Span, |
266 |
| - msg: &str, |
267 |
| - helps: &[&str; 2], |
268 |
| - sugg: String, |
269 |
| - applicability: Applicability, |
270 |
| -) { |
271 |
| - span_lint_and_then(cx, lint, sp, msg, |diag| { |
272 |
| - let sugg_lines_count = sugg.lines().count(); |
273 |
| - if sugg_lines_count > MAX_SUGGESTION_HIGHLIGHT_LINES { |
274 |
| - let sm = cx.sess().source_map(); |
275 |
| - if let (Ok(line_upper), Ok(line_bottom)) = (sm.lookup_line(sp.lo()), sm.lookup_line(sp.hi())) { |
276 |
| - let split_idx = MAX_SUGGESTION_HIGHLIGHT_LINES / 2; |
277 |
| - let span_upper = sm.span_until_char( |
278 |
| - sp.with_hi(line_upper.sf.lines(|lines| lines[line_upper.line + split_idx])), |
279 |
| - '\n', |
280 |
| - ); |
281 |
| - let span_bottom = sp.with_lo(line_bottom.sf.lines(|lines| lines[line_bottom.line - split_idx])); |
282 |
| - |
283 |
| - let sugg_lines_vec = sugg.lines().collect::<Vec<&str>>(); |
284 |
| - let sugg_upper = sugg_lines_vec[..split_idx].join("\n"); |
285 |
| - let sugg_bottom = sugg_lines_vec[sugg_lines_count - split_idx..].join("\n"); |
286 |
| - |
287 |
| - diag.span_suggestion(span_upper, helps[0], sugg_upper, applicability); |
288 |
| - diag.span_suggestion(span_bottom, helps[1], sugg_bottom, applicability); |
289 |
| - |
290 |
| - return; |
291 |
| - } |
292 |
| - } |
293 |
| - diag.span_suggestion_with_style( |
294 |
| - sp, |
295 |
| - &helps.join(", "), |
296 |
| - sugg, |
297 |
| - applicability, |
298 |
| - rustc_errors::SuggestionStyle::ShowAlways, |
299 |
| - ); |
300 |
| - }); |
301 |
| -} |
302 |
| - |
303 | 216 | /// Create a suggestion made from several `span → replacement`.
|
304 | 217 | ///
|
305 | 218 | /// Note: in the JSON format (used by `compiletest_rs`), the help message will
|
|
0 commit comments