Skip to content

Commit c8b9e85

Browse files
committed
span: move MultiSpan
`MultiSpan` contains labels, which are more complicated with the introduction of diagnostic translation and will use types from `rustc_errors` - however, `rustc_errors` depends on `rustc_span` so `rustc_span` cannot use types like `DiagnosticMessage` without dependency cycles. Introduce a new `rustc_error_messages` crate that can contain `DiagnosticMessage` and `MultiSpan`. Signed-off-by: David Wood <[email protected]>
1 parent bb5b250 commit c8b9e85

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

clippy_lints/src/collapsible_match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ use clippy_utils::higher::IfLetOrMatch;
33
use clippy_utils::visitors::is_local_used;
44
use clippy_utils::{is_lang_ctor, is_unit_expr, path_to_local, peel_blocks_with_stmt, peel_ref_operators, SpanlessEq};
55
use if_chain::if_chain;
6+
use rustc_errors::MultiSpan;
67
use rustc_hir::LangItem::OptionNone;
78
use rustc_hir::{Arm, Expr, Guard, HirId, Pat, PatKind};
89
use rustc_lint::{LateContext, LateLintPass};
910
use rustc_session::{declare_lint_pass, declare_tool_lint};
10-
use rustc_span::{MultiSpan, Span};
11+
use rustc_span::Span;
1112

1213
declare_clippy_lint! {
1314
/// ### What it does

clippy_lints/src/doc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_ast::token::CommentKind;
1111
use rustc_data_structures::fx::FxHashSet;
1212
use rustc_data_structures::sync::Lrc;
1313
use rustc_errors::emitter::EmitterWriter;
14-
use rustc_errors::{Applicability, Handler, SuggestionStyle};
14+
use rustc_errors::{Applicability, Handler, MultiSpan, SuggestionStyle};
1515
use rustc_hir as hir;
1616
use rustc_hir::intravisit::{self, Visitor};
1717
use rustc_hir::{AnonConst, Expr};
@@ -25,7 +25,7 @@ use rustc_session::parse::ParseSess;
2525
use rustc_session::{declare_tool_lint, impl_lint_pass};
2626
use rustc_span::def_id::LocalDefId;
2727
use rustc_span::edition::Edition;
28-
use rustc_span::source_map::{BytePos, FilePathMapping, MultiSpan, SourceMap, Span};
28+
use rustc_span::source_map::{BytePos, FilePathMapping, SourceMap, Span};
2929
use rustc_span::{sym, FileName, Pos};
3030
use std::io;
3131
use std::ops::Range;

clippy_lints/src/loops/needless_collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use clippy_utils::ty::is_type_diagnostic_item;
66
use clippy_utils::{can_move_expr_to_closure, is_trait_method, path_to_local, path_to_local_id, CaptureKind};
77
use if_chain::if_chain;
88
use rustc_data_structures::fx::FxHashMap;
9-
use rustc_errors::Applicability;
9+
use rustc_errors::{Applicability, MultiSpan};
1010
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
1111
use rustc_hir::{Block, Expr, ExprKind, HirId, HirIdSet, Local, Mutability, Node, PatKind, Stmt, StmtKind};
1212
use rustc_lint::LateContext;
1313
use rustc_middle::hir::nested_filter;
1414
use rustc_middle::ty::subst::GenericArgKind;
1515
use rustc_middle::ty::{self, Ty};
1616
use rustc_span::sym;
17-
use rustc_span::{MultiSpan, Span};
17+
use rustc_span::Span;
1818

1919
const NEEDLESS_COLLECT_MSG: &str = "avoid using `collect()` when not needed";
2020

clippy_lints/src/ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::source::snippet_opt;
55
use clippy_utils::ty::expr_sig;
66
use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local, paths};
77
use if_chain::if_chain;
8-
use rustc_errors::Applicability;
8+
use rustc_errors::{Applicability, MultiSpan};
99
use rustc_hir::def_id::DefId;
1010
use rustc_hir::hir_id::HirIdMap;
1111
use rustc_hir::intravisit::{walk_expr, Visitor};
@@ -19,8 +19,8 @@ use rustc_middle::hir::nested_filter;
1919
use rustc_middle::ty::{self, Ty};
2020
use rustc_session::{declare_lint_pass, declare_tool_lint};
2121
use rustc_span::source_map::Span;
22+
use rustc_span::sym;
2223
use rustc_span::symbol::Symbol;
23-
use rustc_span::{sym, MultiSpan};
2424
use std::fmt;
2525
use std::iter;
2626

clippy_utils/src/diagnostics.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
//! Thank you!
99
//! ~The `INTERNAL_METADATA_COLLECTOR` lint
1010
11-
use rustc_errors::{emitter::MAX_SUGGESTION_HIGHLIGHT_LINES, Applicability, Diagnostic};
11+
use rustc_errors::{emitter::MAX_SUGGESTION_HIGHLIGHT_LINES, Applicability, Diagnostic, MultiSpan};
1212
use rustc_hir::HirId;
1313
use rustc_lint::{LateContext, Lint, LintContext};
14-
use rustc_span::source_map::{MultiSpan, Span};
14+
use rustc_span::source_map::Span;
1515
use std::env;
1616

1717
fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) {
@@ -155,7 +155,13 @@ where
155155
});
156156
}
157157

158-
pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) {
158+
pub fn span_lint_hir(
159+
cx: &LateContext<'_>,
160+
lint: &'static Lint,
161+
hir_id: HirId,
162+
sp: Span,
163+
msg: &str,
164+
) {
159165
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| {
160166
let mut diag = diag.build(msg);
161167
docs_link(&mut diag, lint);
@@ -272,9 +278,14 @@ pub fn span_lint_and_sugg_for_edges(
272278
let sugg_lines_count = sugg.lines().count();
273279
if sugg_lines_count > MAX_SUGGESTION_HIGHLIGHT_LINES {
274280
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())) {
281+
if let (Ok(line_upper), Ok(line_bottom)) =
282+
(sm.lookup_line(sp.lo()), sm.lookup_line(sp.hi()))
283+
{
276284
let split_idx = MAX_SUGGESTION_HIGHLIGHT_LINES / 2;
277-
let span_upper = sm.span_until_char(sp.with_hi(line_upper.sf.lines[line_upper.line + split_idx]), '\n');
285+
let span_upper = sm.span_until_char(
286+
sp.with_hi(line_upper.sf.lines[line_upper.line + split_idx]),
287+
'\n',
288+
);
278289
let span_bottom = sp.with_lo(line_bottom.sf.lines[line_bottom.line - split_idx]);
279290

280291
let sugg_lines_vec = sugg.lines().collect::<Vec<&str>>();

0 commit comments

Comments
 (0)