Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4d8b66a

Browse files
committed
Auto merge of rust-lang#92787 - camsteffen:methodcall-span, r=Mark-Simulacrum
Remove a `Span` from `hir::ExprKind::MethodCall` It's just a copy of `MethodCall.0.ident.span`.
2 parents 84e9189 + b117335 commit 4d8b66a

File tree

112 files changed

+211
-220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+211
-220
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
5656
ImplTraitContext::disallowed(),
5757
));
5858
let args = self.lower_exprs(args);
59-
hir::ExprKind::MethodCall(
60-
hir_seg,
61-
self.lower_span(seg.ident.span),
62-
args,
63-
self.lower_span(span),
64-
)
59+
hir::ExprKind::MethodCall(hir_seg, args, self.lower_span(span))
6560
}
6661
ExprKind::Binary(binop, ref lhs, ref rhs) => {
6762
let binop = self.lower_binop(binop);

compiler/rustc_hir/src/hir.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,21 +1669,21 @@ pub enum ExprKind<'hir> {
16691669
Call(&'hir Expr<'hir>, &'hir [Expr<'hir>]),
16701670
/// A method call (e.g., `x.foo::<'static, Bar, Baz>(a, b, c, d)`).
16711671
///
1672-
/// The `PathSegment`/`Span` represent the method name and its generic arguments
1672+
/// The `PathSegment` represents the method name and its generic arguments
16731673
/// (within the angle brackets).
1674-
/// The first element of the vector of `Expr`s is the expression that evaluates
1674+
/// The first element of the `&[Expr]` is the expression that evaluates
16751675
/// to the object on which the method is being called on (the receiver),
16761676
/// and the remaining elements are the rest of the arguments.
16771677
/// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
1678-
/// `ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, [x, a, b, c, d])`.
1678+
/// `ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, [x, a, b, c, d], span)`.
16791679
/// The final `Span` represents the span of the function and arguments
16801680
/// (e.g. `foo::<Bar, Baz>(a, b, c, d)` in `x.foo::<Bar, Baz>(a, b, c, d)`
16811681
///
16821682
/// To resolve the called method to a `DefId`, call [`type_dependent_def_id`] with
16831683
/// the `hir_id` of the `MethodCall` node itself.
16841684
///
16851685
/// [`type_dependent_def_id`]: ../ty/struct.TypeckResults.html#method.type_dependent_def_id
1686-
MethodCall(&'hir PathSegment<'hir>, Span, &'hir [Expr<'hir>], Span),
1686+
MethodCall(&'hir PathSegment<'hir>, &'hir [Expr<'hir>], Span),
16871687
/// A tuple (e.g., `(a, b, c, d)`).
16881688
Tup(&'hir [Expr<'hir>]),
16891689
/// A binary operation (e.g., `a + b`, `a * b`).
@@ -3257,7 +3257,7 @@ impl<'hir> Node<'hir> {
32573257
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
32583258
mod size_asserts {
32593259
rustc_data_structures::static_assert_size!(super::Block<'static>, 48);
3260-
rustc_data_structures::static_assert_size!(super::Expr<'static>, 64);
3260+
rustc_data_structures::static_assert_size!(super::Expr<'static>, 56);
32613261
rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
32623262
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
32633263
rustc_data_structures::static_assert_size!(super::Ty<'static>, 80);

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
11491149
visitor.visit_expr(callee_expression);
11501150
walk_list!(visitor, visit_expr, arguments);
11511151
}
1152-
ExprKind::MethodCall(ref segment, _, arguments, _) => {
1152+
ExprKind::MethodCall(ref segment, arguments, _) => {
11531153
visitor.visit_path_segment(expression.span, segment);
11541154
walk_list!(visitor, visit_expr, arguments);
11551155
}

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ impl<'a> State<'a> {
14271427
hir::ExprKind::Call(ref func, ref args) => {
14281428
self.print_expr_call(&func, args);
14291429
}
1430-
hir::ExprKind::MethodCall(ref segment, _, ref args, _) => {
1430+
hir::ExprKind::MethodCall(ref segment, ref args, _) => {
14311431
self.print_expr_method_call(segment, args);
14321432
}
14331433
hir::ExprKind::Binary(op, ref lhs, ref rhs) => {

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
121121
}
122122
}
123123
}
124-
if let ExprKind::MethodCall(_, call_span, exprs, _) = expr.kind {
125-
if call_span == self.target_span
124+
if let ExprKind::MethodCall(segment, exprs, _) = expr.kind {
125+
if segment.ident.span == self.target_span
126126
&& Some(self.target)
127127
== self.infcx.in_progress_typeck_results.and_then(|typeck_results| {
128128
typeck_results
@@ -531,7 +531,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
531531
// 3 | let _ = x.sum() as f64;
532532
// | ^^^ cannot infer type for `S`
533533
span
534-
} else if let Some(ExprKind::MethodCall(_, call_span, _, _)) =
534+
} else if let Some(ExprKind::MethodCall(segment, ..)) =
535535
local_visitor.found_method_call.map(|e| &e.kind)
536536
{
537537
// Point at the call instead of the whole expression:
@@ -542,7 +542,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
542542
// | ^^^^^^^ cannot infer type
543543
// |
544544
// = note: cannot resolve `<_ as std::ops::Try>::Ok == _`
545-
if span.contains(*call_span) { *call_span } else { span }
545+
if span.contains(segment.ident.span) { segment.ident.span } else { span }
546546
} else {
547547
span
548548
};
@@ -709,7 +709,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
709709
};
710710
err.span_label(pattern.span, msg);
711711
} else if let Some(e) = local_visitor.found_method_call {
712-
if let ExprKind::MethodCall(segment, _, exprs, _) = &e.kind {
712+
if let ExprKind::MethodCall(segment, exprs, _) = &e.kind {
713713
// Suggest impl candidates:
714714
//
715715
// error[E0283]: type annotations needed

compiler/rustc_lint/src/array_into_iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
6161
}
6262

6363
// We only care about method call expressions.
64-
if let hir::ExprKind::MethodCall(call, span, args, _) = &expr.kind {
64+
if let hir::ExprKind::MethodCall(call, args, _) = &expr.kind {
6565
if call.ident.name != sym::into_iter {
6666
return;
6767
}
@@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
119119
// to an array or to a slice.
120120
_ => bug!("array type coerced to something other than array or slice"),
121121
};
122-
cx.struct_span_lint(ARRAY_INTO_ITER, *span, |lint| {
122+
cx.struct_span_lint(ARRAY_INTO_ITER, call.ident.span, |lint| {
123123
let mut diag = lint.build(&format!(
124124
"this method call resolves to `<&{} as IntoIterator>::into_iter` \
125125
(due to backwards compatibility), \

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2494,7 +2494,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
24942494
_ => {}
24952495
}
24962496
}
2497-
} else if let hir::ExprKind::MethodCall(_, _, ref args, _) = expr.kind {
2497+
} else if let hir::ExprKind::MethodCall(_, ref args, _) = expr.kind {
24982498
// Find problematic calls to `MaybeUninit::assume_init`.
24992499
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?;
25002500
if cx.tcx.is_diagnostic_item(sym::assume_init, def_id) {

compiler/rustc_lint/src/methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn in_macro(span: Span) -> bool {
4444
fn first_method_call<'tcx>(
4545
expr: &'tcx Expr<'tcx>,
4646
) -> Option<(&'tcx PathSegment<'tcx>, &'tcx [Expr<'tcx>])> {
47-
if let ExprKind::MethodCall(path, _, args, _) = &expr.kind {
47+
if let ExprKind::MethodCall(path, args, _) = &expr.kind {
4848
if args.iter().any(|e| e.span.from_expansion()) { None } else { Some((path, *args)) }
4949
} else {
5050
None

compiler/rustc_lint/src/noop_method_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ declare_lint_pass!(NoopMethodCall => [NOOP_METHOD_CALL]);
4040
impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
4141
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
4242
// We only care about method calls.
43-
let ExprKind::MethodCall(call, _, elements, _) = &expr.kind else {
43+
let ExprKind::MethodCall(call, elements, _) = &expr.kind else {
4444
return
4545
};
4646
// We only care about method calls corresponding to the `Clone`, `Deref` and `Borrow`

compiler/rustc_lint/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ impl InvalidAtomicOrdering {
14641464
sym::AtomicI128,
14651465
];
14661466
if_chain! {
1467-
if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind;
1467+
if let ExprKind::MethodCall(ref method_path, args, _) = &expr.kind;
14681468
if recognized_names.contains(&method_path.ident.name);
14691469
if let Some(m_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
14701470
if let Some(impl_did) = cx.tcx.impl_of_method(m_def_id);

0 commit comments

Comments
 (0)