Rollup merge of #139232 - nnethercote:remove-Map-5, r=Zalathar

Move methods from `Map` to `TyCtxt`, part 5.

This eliminates all methods on `Map`. Actually removing `Map` will occur in a follow-up PR.

A follow-up to #137504.

r? `@Zalathar`
This commit is contained in:
Takayuki Maeda 2025-04-02 22:52:46 +09:00 committed by GitHub
commit 978ed960eb
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 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.
// Weird macro wizardry could be involved here.

View file

@ -254,7 +254,7 @@ fn check_hash_peq<'tcx>(
|diag| {
if let Some(local_def_id) = impl_id.as_local() {
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| {
if let Some(local_def_id) = impl_id.as_local() {
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,
BOXED_LOCAL,
node,
cx.tcx.hir().span(node),
cx.tcx.hir_span(node),
"local variable doesn't need to be boxed here",
);
}

View file

@ -248,7 +248,7 @@ impl<'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'_, 'tcx> {
{
use_info
.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;
}

View file

@ -85,10 +85,10 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
if bk == ty::BorrowKind::Mutable {
if let PlaceBase::Local(id) = cmt.place.base {
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) {
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) {
if let PlaceBase::Local(id) = cmt.place.base {
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) {
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.
// The invocation doesn't matter. Also we want to dedupe by the unsafe block and not by anything
// 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))
})

View file

@ -329,7 +329,7 @@ fn used_underscore_binding<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
let name = ident.name.as_str();
if 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()
&& !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(
sp,
"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,
);
if cx.effective_visibilities.is_exported(*fn_def_id) {

View file

@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
// Dereference suggestion
let sugg = |diag: &mut Diag<'_, ()>| {
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(
cx.tcx,
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);
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
&& 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<'_>) {
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
&& span.contains(body_span)
{

View file

@ -73,7 +73,7 @@ impl Context {
match cx.tcx.hir_body_owner_kind(body_owner_def_id) {
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 span.contains(body_span) {
@ -88,7 +88,7 @@ impl Context {
pub fn body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
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 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| {
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 {
if let CallState::Once { call_site } = *usage
&& 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)
{
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);
}
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 {
match e.kind {
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
// 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 (parent_id, _) = match parent_iter.next() {
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
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 {
// the parent node is not in a macro
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) {
if let PlaceBase::Local(id) = cmt.place.base {
let map = self.cx.tcx.hir();
let span = map.span(cmt.hir_id);
let span = self.cx.tcx.hir_span(cmt.hir_id);
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);