Move methods from Map to TyCtxt, part 5.

This eliminates all methods on `Map`. Actually removing `Map` will occur
in a follow-up PR.
This commit is contained in:
Nicholas Nethercote
2025-04-02 07:04:24 +11:00
parent 4304fa2955
commit 130af3fc3a
16 changed files with 22 additions and 24 deletions

View File

@@ -143,7 +143,7 @@ pub(super) fn check<'tcx>(
if cast_from.kind() == cast_to.kind() && !expr.span.in_external_macro(cx.sess().source_map()) { if cast_from.kind() == cast_to.kind() && !expr.span.in_external_macro(cx.sess().source_map()) {
if let Some(id) = path_to_local(cast_expr) if let Some(id) = path_to_local(cast_expr)
&& !cx.tcx.hir().span(id).eq_ctxt(cast_expr.span) && !cx.tcx.hir_span(id).eq_ctxt(cast_expr.span)
{ {
// Binding context is different than the identifiers context. // Binding context is different than the identifiers context.
// Weird macro wizardry could be involved here. // Weird macro wizardry could be involved here.

View File

@@ -254,7 +254,7 @@ fn check_hash_peq<'tcx>(
|diag| { |diag| {
if let Some(local_def_id) = impl_id.as_local() { if let Some(local_def_id) = impl_id.as_local() {
let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id); let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id);
diag.span_note(cx.tcx.hir().span(hir_id), "`PartialEq` implemented here"); diag.span_note(cx.tcx.hir_span(hir_id), "`PartialEq` implemented here");
} }
}, },
); );
@@ -298,7 +298,7 @@ fn check_ord_partial_ord<'tcx>(
span_lint_and_then(cx, DERIVE_ORD_XOR_PARTIAL_ORD, span, mess, |diag| { span_lint_and_then(cx, DERIVE_ORD_XOR_PARTIAL_ORD, span, mess, |diag| {
if let Some(local_def_id) = impl_id.as_local() { if let Some(local_def_id) = impl_id.as_local() {
let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id); let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id);
diag.span_note(cx.tcx.hir().span(hir_id), "`PartialOrd` implemented here"); diag.span_note(cx.tcx.hir_span(hir_id), "`PartialOrd` implemented here");
} }
}); });
} }

View File

@@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
cx, cx,
BOXED_LOCAL, BOXED_LOCAL,
node, node,
cx.tcx.hir().span(node), cx.tcx.hir_span(node),
"local variable doesn't need to be boxed here", "local variable doesn't need to be boxed here",
); );
} }

View File

@@ -248,7 +248,7 @@ impl<'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'_, 'tcx> {
{ {
use_info use_info
.index_use .index_use
.push((index_value, cx.tcx.hir().span(parent_expr.hir_id))); .push((index_value, cx.tcx.hir_span(parent_expr.hir_id)));
return; return;
} }

View File

@@ -85,10 +85,10 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
if bk == ty::BorrowKind::Mutable { if bk == ty::BorrowKind::Mutable {
if let PlaceBase::Local(id) = cmt.place.base { if let PlaceBase::Local(id) = cmt.place.base {
if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) { if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id)); self.span_low = Some(self.cx.tcx.hir_span(diag_expr_id));
} }
if Some(id) == self.hir_id_high && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) { if Some(id) == self.hir_id_high && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id)); self.span_high = Some(self.cx.tcx.hir_span(diag_expr_id));
} }
} }
} }
@@ -97,10 +97,10 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) { fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
if let PlaceBase::Local(id) = cmt.place.base { if let PlaceBase::Local(id) = cmt.place.base {
if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) { if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id)); self.span_low = Some(self.cx.tcx.hir_span(diag_expr_id));
} }
if Some(id) == self.hir_id_high && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) { if Some(id) == self.hir_id_high && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id)); self.span_high = Some(self.cx.tcx.hir_span(diag_expr_id));
} }
} }
} }

View File

@@ -253,7 +253,7 @@ impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe {
// Remove the syntax context to hide "in this macro invocation" in the diagnostic. // Remove the syntax context to hide "in this macro invocation" in the diagnostic.
// The invocation doesn't matter. Also we want to dedupe by the unsafe block and not by anything // The invocation doesn't matter. Also we want to dedupe by the unsafe block and not by anything
// related to the callsite. // related to the callsite.
let span = cx.tcx.hir().span(id); let span = cx.tcx.hir_span(id);
(id, Span::new(span.lo(), span.hi(), SyntaxContext::root(), None)) (id, Span::new(span.lo(), span.hi(), SyntaxContext::root(), None))
}) })

View File

@@ -329,7 +329,7 @@ fn used_underscore_binding<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
let name = ident.name.as_str(); let name = ident.name.as_str();
if name.starts_with('_') if name.starts_with('_')
&& !name.starts_with("__") && !name.starts_with("__")
&& let definition_span = cx.tcx.hir().span(definition_hir_id) && let definition_span = cx.tcx.hir_span(definition_hir_id)
&& !definition_span.from_expansion() && !definition_span.from_expansion()
&& !fulfill_or_allowed(cx, USED_UNDERSCORE_BINDING, [expr.hir_id, definition_hir_id]) && !fulfill_or_allowed(cx, USED_UNDERSCORE_BINDING, [expr.hir_id, definition_hir_id])
{ {

View File

@@ -280,7 +280,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
diag.span_suggestion( diag.span_suggestion(
sp, sp,
"consider changing to".to_string(), "consider changing to".to_string(),
format!("&{}", snippet(cx, cx.tcx.hir().span(inner_ty.ty.hir_id), "_"),), format!("&{}", snippet(cx, cx.tcx.hir_span(inner_ty.ty.hir_id), "_"),),
Applicability::Unspecified, Applicability::Unspecified,
); );
if cx.effective_visibilities.is_exported(*fn_def_id) { if cx.effective_visibilities.is_exported(*fn_def_id) {

View File

@@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
// Dereference suggestion // Dereference suggestion
let sugg = |diag: &mut Diag<'_, ()>| { let sugg = |diag: &mut Diag<'_, ()>| {
if let ty::Adt(def, ..) = ty.kind() { if let ty::Adt(def, ..) = ty.kind() {
if let Some(span) = cx.tcx.hir().span_if_local(def.did()) { if let Some(span) = cx.tcx.hir_span_if_local(def.did()) {
if type_allowed_to_implement_copy( if type_allowed_to_implement_copy(
cx.tcx, cx.tcx,
cx.param_env, cx.param_env,

View File

@@ -354,7 +354,7 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
let body_owner_kind = cx.tcx.hir_body_owner_kind(body_owner_def_id); let body_owner_kind = cx.tcx.hir_body_owner_kind(body_owner_def_id);
if let hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_) = body_owner_kind { if let hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_) = body_owner_kind {
let body_span = cx.tcx.hir().span_with_body(body_owner); let body_span = cx.tcx.hir_span_with_body(body_owner);
if let Some(span) = self.const_span if let Some(span) = self.const_span
&& span.contains(body_span) && span.contains(body_span)
{ {
@@ -366,7 +366,7 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
fn check_body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { fn check_body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
let body_owner = cx.tcx.hir_body_owner(body.id()); let body_owner = cx.tcx.hir_body_owner(body.id());
let body_span = cx.tcx.hir().span(body_owner); let body_span = cx.tcx.hir_span(body_owner);
if let Some(span) = self.const_span if let Some(span) = self.const_span
&& span.contains(body_span) && span.contains(body_span)
{ {

View File

@@ -73,7 +73,7 @@ impl Context {
match cx.tcx.hir_body_owner_kind(body_owner_def_id) { match cx.tcx.hir_body_owner_kind(body_owner_def_id) {
hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const { .. } => { hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const { .. } => {
let body_span = cx.tcx.hir().span_with_body(body_owner); let body_span = cx.tcx.hir_span_with_body(body_owner);
if let Some(span) = self.const_span { if let Some(span) = self.const_span {
if span.contains(body_span) { if span.contains(body_span) {
@@ -88,7 +88,7 @@ impl Context {
pub fn body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) { pub fn body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
let body_owner = cx.tcx.hir_body_owner(body.id()); let body_owner = cx.tcx.hir_body_owner(body.id());
let body_span = cx.tcx.hir().span_with_body(body_owner); let body_span = cx.tcx.hir_span_with_body(body_owner);
if let Some(span) = self.const_span { if let Some(span) = self.const_span {
if span.contains(body_span) { if span.contains(body_span) {

View File

@@ -218,7 +218,7 @@ fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span)
}, },
}; };
span_lint_and_then(cx, lint, span, msg, |diag| { span_lint_and_then(cx, lint, span, msg, |diag| {
diag.span_note(cx.tcx.hir().span(shadowed), "previous binding is here"); diag.span_note(cx.tcx.hir_span(shadowed), "previous binding is here");
}); });
} }

View File

@@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for SingleCallFn {
for (&def_id, usage) in &self.def_id_to_usage { for (&def_id, usage) in &self.def_id_to_usage {
if let CallState::Once { call_site } = *usage if let CallState::Once { call_site } = *usage
&& let fn_hir_id = cx.tcx.local_def_id_to_hir_id(def_id) && let fn_hir_id = cx.tcx.local_def_id_to_hir_id(def_id)
&& let fn_span = cx.tcx.hir().span_with_body(fn_hir_id) && let fn_span = cx.tcx.hir_span_with_body(fn_hir_id)
&& !self.is_function_allowed(cx, def_id, fn_hir_id, fn_span) && !self.is_function_allowed(cx, def_id, fn_hir_id, fn_span)
{ {
span_lint_hir_and_then( span_lint_hir_and_then(

View File

@@ -2990,7 +2990,7 @@ pub fn expr_use_ctxt<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> ExprU
{ {
adjustments = cx.typeck_results().expr_adjustments(e); adjustments = cx.typeck_results().expr_adjustments(e);
} }
same_ctxt &= cx.tcx.hir().span(parent_id).ctxt() == ctxt; same_ctxt &= cx.tcx.hir_span(parent_id).ctxt() == ctxt;
if let Node::Expr(e) = parent { if let Node::Expr(e) = parent {
match e.kind { match e.kind {
ExprKind::If(e, _, _) | ExprKind::Match(e, _, _) if e.hir_id != child_id => { ExprKind::If(e, _, _) | ExprKind::Match(e, _, _) if e.hir_id != child_id => {

View File

@@ -178,7 +178,6 @@ pub fn first_node_in_macro(cx: &LateContext<'_>, node: &impl HirNode) -> Option<
// get the parent node, possibly skipping over a statement // get the parent node, possibly skipping over a statement
// if the parent is not found, it is sensible to return `Some(root)` // if the parent is not found, it is sensible to return `Some(root)`
let hir = cx.tcx.hir();
let mut parent_iter = cx.tcx.hir_parent_iter(node.hir_id()); let mut parent_iter = cx.tcx.hir_parent_iter(node.hir_id());
let (parent_id, _) = match parent_iter.next() { let (parent_id, _) = match parent_iter.next() {
None => return Some(ExpnId::root()), None => return Some(ExpnId::root()),
@@ -190,7 +189,7 @@ pub fn first_node_in_macro(cx: &LateContext<'_>, node: &impl HirNode) -> Option<
}; };
// get the macro expansion of the parent node // get the macro expansion of the parent node
let parent_span = hir.span(parent_id); let parent_span = cx.tcx.hir_span(parent_id);
let Some(parent_macro_call) = macro_backtrace(parent_span).next() else { let Some(parent_macro_call) = macro_backtrace(parent_span).next() else {
// the parent node is not in a macro // the parent node is not in a macro
return Some(ExpnId::root()); return Some(ExpnId::root());

View File

@@ -839,8 +839,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) { fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
if let PlaceBase::Local(id) = cmt.place.base { if let PlaceBase::Local(id) = cmt.place.base {
let map = self.cx.tcx.hir(); let span = self.cx.tcx.hir_span(cmt.hir_id);
let span = map.span(cmt.hir_id);
let start_span = Span::new(self.next_pos, span.lo(), span.ctxt(), None); let start_span = Span::new(self.next_pos, span.lo(), span.ctxt(), None);
let mut start_snip = snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability); let mut start_snip = snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);