about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorArthur Lafrance <lafrancearthur@gmail.com>2023-10-16 01:05:11 -0700
committerArthur Lafrance <lafrancearthur@gmail.com>2023-10-16 19:50:29 -0700
commit5895102c4dab67e7962bd76e1204bcf0fab467c5 (patch)
treea77eeb1996668ace4767fdf6344417e5ac31e156 /compiler
parentf77dea89e183b638841d42d4d7bea48058a98e76 (diff)
downloadrust-5895102c4dab67e7962bd76e1204bcf0fab467c5.tar.gz
rust-5895102c4dab67e7962bd76e1204bcf0fab467c5.zip
debug Span::ctxt() call detection
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_typeck/src/callee.rs2
-rw-r--r--compiler/rustc_lint/messages.ftl2
-rw-r--r--compiler/rustc_lint/src/internal.rs23
-rw-r--r--compiler/rustc_lint/src/lints.rs4
-rw-r--r--compiler/rustc_mir_transform/src/coverage/spans.rs2
-rw-r--r--compiler/rustc_span/src/span_encoding.rs2
-rw-r--r--compiler/rustc_span/src/symbol.rs2
7 files changed, 12 insertions, 25 deletions
diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs
index 512d73fc103..1c23ccd1579 100644
--- a/compiler/rustc_hir_typeck/src/callee.rs
+++ b/compiler/rustc_hir_typeck/src/callee.rs
@@ -650,7 +650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 .sess
                 .source_map()
                 .is_multiline(call_expr.span.with_lo(callee_expr.span.hi()))
-                && call_expr.span.ctxt() == callee_expr.span.ctxt();
+                && call_expr.span.eq_ctxt(callee_expr.span);
             if call_is_multiline {
                 err.span_suggestion(
                     callee_expr.span.shrink_to_hi(),
diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl
index 261451e530e..4c4d2933bf4 100644
--- a/compiler/rustc_lint/messages.ftl
+++ b/compiler/rustc_lint/messages.ftl
@@ -494,7 +494,7 @@ lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
 
 lint_requested_level = requested on the command line with `{$level} {$lint_name}`
 
-lint_span_use_eq_ctxt = use `eq_ctxt()` not `ctxt() == ctxt()`
+lint_span_use_eq_ctxt = use `.eq_ctxt()` instead of `.ctxt() == .ctxt()`
 
 lint_supertrait_as_deref_target = `{$t}` implements `Deref` with supertrait `{$target_principal}` as target
     .label = target type is set here
diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs
index c2aa768e945..34f241e8c8d 100644
--- a/compiler/rustc_lint/src/internal.rs
+++ b/compiler/rustc_lint/src/internal.rs
@@ -538,13 +538,9 @@ impl LateLintPass<'_> for BadOptAccess {
     }
 }
 
-// some things i'm not sure about:
-//   * is Warn the right level?
-//   * the way i verify that the right method is being called (path + diag item check)
-
 declare_tool_lint! {
     pub rustc::SPAN_USE_EQ_CTXT,
-    Warn, // is this the right level?
+    Allow,
     "Use of `==` with `Span::ctxt` rather than `Span::eq_ctxt`",
     report_in_external_macro: true
 }
@@ -555,11 +551,7 @@ impl<'tcx> LateLintPass<'tcx> for SpanUseEqCtxt {
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) {
         if let ExprKind::Binary(BinOp { node: BinOpKind::Eq, .. }, lhs, rhs) = expr.kind {
             if is_span_ctxt_call(cx, lhs) && is_span_ctxt_call(cx, rhs) {
-                cx.emit_spanned_lint(
-                    SPAN_USE_EQ_CTXT,
-                    expr.span,
-                    SpanUseEqCtxtDiag { msg: "fail" },
-                );
+                cx.emit_spanned_lint(SPAN_USE_EQ_CTXT, expr.span, SpanUseEqCtxtDiag);
             }
         }
     }
@@ -567,13 +559,10 @@ impl<'tcx> LateLintPass<'tcx> for SpanUseEqCtxt {
 
 fn is_span_ctxt_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
     match &expr.kind {
-        ExprKind::MethodCall(path, receiver, _, _) => {
-            path.ident.name.as_str() == "ctxt"
-                && cx
-                    .typeck_results()
-                    .type_dependent_def_id(receiver.hir_id)
-                    .is_some_and(|did| cx.tcx.is_diagnostic_item(sym::Span, did))
-        }
+        ExprKind::MethodCall(..) => cx
+            .typeck_results()
+            .type_dependent_def_id(expr.hir_id)
+            .is_some_and(|call_did| cx.tcx.is_diagnostic_item(sym::SpanCtxt, call_did)),
 
         _ => false,
     }
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs
index a02bee506df..4eaf8bbf5de 100644
--- a/compiler/rustc_lint/src/lints.rs
+++ b/compiler/rustc_lint/src/lints.rs
@@ -902,9 +902,7 @@ pub struct QueryInstability {
 
 #[derive(LintDiagnostic)]
 #[diag(lint_span_use_eq_ctxt)]
-pub struct SpanUseEqCtxtDiag<'a> {
-    pub msg: &'a str,
-}
+pub struct SpanUseEqCtxtDiag;
 
 #[derive(LintDiagnostic)]
 #[diag(lint_tykind_kind)]
diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs
index 1d1be8f2492..f1a0f762041 100644
--- a/compiler/rustc_mir_transform/src/coverage/spans.rs
+++ b/compiler/rustc_mir_transform/src/coverage/spans.rs
@@ -404,7 +404,7 @@ impl<'a> CoverageSpansGenerator<'a> {
 
         let Some(visible_macro) = curr.visible_macro(self.body_span) else { return };
         if let Some(prev) = &self.some_prev
-            && prev.expn_span.ctxt() == curr.expn_span.ctxt()
+            && prev.expn_span.eq_ctxt(curr.expn_span)
         {
             return;
         }
diff --git a/compiler/rustc_span/src/span_encoding.rs b/compiler/rustc_span/src/span_encoding.rs
index 7c7f8448c97..f7d17a267d6 100644
--- a/compiler/rustc_span/src/span_encoding.rs
+++ b/compiler/rustc_span/src/span_encoding.rs
@@ -75,7 +75,6 @@ use rustc_data_structures::fx::FxIndexSet;
 /// the dependency to the parent definition's span. This is performed
 /// using the callback `SPAN_TRACK` to access the query engine.
 ///
-#[cfg_attr(not(test), rustc_diagnostic_item = "Span")]
 #[derive(Clone, Copy, Eq, PartialEq, Hash)]
 #[rustc_pass_by_value]
 pub struct Span {
@@ -213,6 +212,7 @@ impl Span {
 
     /// This function is used as a fast path when decoding the full `SpanData` is not necessary.
     /// It's a cut-down version of `data_untracked`.
+    #[cfg_attr(not(test), rustc_diagnostic_item = "SpanCtxt")]
     #[inline]
     pub fn ctxt(self) -> SyntaxContext {
         if self.len_with_tag_or_marker != BASE_LEN_INTERNED_MARKER {
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 9598b2d0310..be8c65862dc 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -303,7 +303,7 @@ symbols! {
         SliceIndex,
         SliceIter,
         Some,
-        Span,
+        SpanCtxt,
         String,
         StructuralEq,
         StructuralPartialEq,