Skip to content

Commit

Permalink
Remove a span from hir::ExprKind::MethodCall
Browse files Browse the repository at this point in the history
  • Loading branch information
camsteffen committed Jan 21, 2022
1 parent 84e9189 commit b117335
Show file tree
Hide file tree
Showing 112 changed files with 211 additions and 220 deletions.
7 changes: 1 addition & 6 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ImplTraitContext::disallowed(),
));
let args = self.lower_exprs(args);
hir::ExprKind::MethodCall(
hir_seg,
self.lower_span(seg.ident.span),
args,
self.lower_span(span),
)
hir::ExprKind::MethodCall(hir_seg, args, self.lower_span(span))
}
ExprKind::Binary(binop, ref lhs, ref rhs) => {
let binop = self.lower_binop(binop);
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1669,21 +1669,21 @@ pub enum ExprKind<'hir> {
Call(&'hir Expr<'hir>, &'hir [Expr<'hir>]),
/// A method call (e.g., `x.foo::<'static, Bar, Baz>(a, b, c, d)`).
///
/// The `PathSegment`/`Span` represent the method name and its generic arguments
/// The `PathSegment` represents the method name and its generic arguments
/// (within the angle brackets).
/// The first element of the vector of `Expr`s is the expression that evaluates
/// The first element of the `&[Expr]` is the expression that evaluates
/// to the object on which the method is being called on (the receiver),
/// and the remaining elements are the rest of the arguments.
/// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
/// `ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, [x, a, b, c, d])`.
/// `ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, [x, a, b, c, d], span)`.
/// The final `Span` represents the span of the function and arguments
/// (e.g. `foo::<Bar, Baz>(a, b, c, d)` in `x.foo::<Bar, Baz>(a, b, c, d)`
///
/// To resolve the called method to a `DefId`, call [`type_dependent_def_id`] with
/// the `hir_id` of the `MethodCall` node itself.
///
/// [`type_dependent_def_id`]: ../ty/struct.TypeckResults.html#method.type_dependent_def_id
MethodCall(&'hir PathSegment<'hir>, Span, &'hir [Expr<'hir>], Span),
MethodCall(&'hir PathSegment<'hir>, &'hir [Expr<'hir>], Span),
/// A tuple (e.g., `(a, b, c, d)`).
Tup(&'hir [Expr<'hir>]),
/// A binary operation (e.g., `a + b`, `a * b`).
Expand Down Expand Up @@ -3257,7 +3257,7 @@ impl<'hir> Node<'hir> {
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
mod size_asserts {
rustc_data_structures::static_assert_size!(super::Block<'static>, 48);
rustc_data_structures::static_assert_size!(super::Expr<'static>, 64);
rustc_data_structures::static_assert_size!(super::Expr<'static>, 56);
rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
rustc_data_structures::static_assert_size!(super::Ty<'static>, 80);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
visitor.visit_expr(callee_expression);
walk_list!(visitor, visit_expr, arguments);
}
ExprKind::MethodCall(ref segment, _, arguments, _) => {
ExprKind::MethodCall(ref segment, arguments, _) => {
visitor.visit_path_segment(expression.span, segment);
walk_list!(visitor, visit_expr, arguments);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ impl<'a> State<'a> {
hir::ExprKind::Call(ref func, ref args) => {
self.print_expr_call(&func, args);
}
hir::ExprKind::MethodCall(ref segment, _, ref args, _) => {
hir::ExprKind::MethodCall(ref segment, ref args, _) => {
self.print_expr_method_call(segment, args);
}
hir::ExprKind::Binary(op, ref lhs, ref rhs) => {
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
}
}
}
if let ExprKind::MethodCall(_, call_span, exprs, _) = expr.kind {
if call_span == self.target_span
if let ExprKind::MethodCall(segment, exprs, _) = expr.kind {
if segment.ident.span == self.target_span
&& Some(self.target)
== self.infcx.in_progress_typeck_results.and_then(|typeck_results| {
typeck_results
Expand Down Expand Up @@ -531,7 +531,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// 3 | let _ = x.sum() as f64;
// | ^^^ cannot infer type for `S`
span
} else if let Some(ExprKind::MethodCall(_, call_span, _, _)) =
} else if let Some(ExprKind::MethodCall(segment, ..)) =
local_visitor.found_method_call.map(|e| &e.kind)
{
// Point at the call instead of the whole expression:
Expand All @@ -542,7 +542,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// | ^^^^^^^ cannot infer type
// |
// = note: cannot resolve `<_ as std::ops::Try>::Ok == _`
if span.contains(*call_span) { *call_span } else { span }
if span.contains(segment.ident.span) { segment.ident.span } else { span }
} else {
span
};
Expand Down Expand Up @@ -709,7 +709,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
};
err.span_label(pattern.span, msg);
} else if let Some(e) = local_visitor.found_method_call {
if let ExprKind::MethodCall(segment, _, exprs, _) = &e.kind {
if let ExprKind::MethodCall(segment, exprs, _) = &e.kind {
// Suggest impl candidates:
//
// error[E0283]: type annotations needed
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/array_into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
}

// We only care about method call expressions.
if let hir::ExprKind::MethodCall(call, span, args, _) = &expr.kind {
if let hir::ExprKind::MethodCall(call, args, _) = &expr.kind {
if call.ident.name != sym::into_iter {
return;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
// to an array or to a slice.
_ => bug!("array type coerced to something other than array or slice"),
};
cx.struct_span_lint(ARRAY_INTO_ITER, *span, |lint| {
cx.struct_span_lint(ARRAY_INTO_ITER, call.ident.span, |lint| {
let mut diag = lint.build(&format!(
"this method call resolves to `<&{} as IntoIterator>::into_iter` \
(due to backwards compatibility), \
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
_ => {}
}
}
} else if let hir::ExprKind::MethodCall(_, _, ref args, _) = expr.kind {
} else if let hir::ExprKind::MethodCall(_, ref args, _) = expr.kind {
// Find problematic calls to `MaybeUninit::assume_init`.
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?;
if cx.tcx.is_diagnostic_item(sym::assume_init, def_id) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn in_macro(span: Span) -> bool {
fn first_method_call<'tcx>(
expr: &'tcx Expr<'tcx>,
) -> Option<(&'tcx PathSegment<'tcx>, &'tcx [Expr<'tcx>])> {
if let ExprKind::MethodCall(path, _, args, _) = &expr.kind {
if let ExprKind::MethodCall(path, args, _) = &expr.kind {
if args.iter().any(|e| e.span.from_expansion()) { None } else { Some((path, *args)) }
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/noop_method_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ declare_lint_pass!(NoopMethodCall => [NOOP_METHOD_CALL]);
impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
// We only care about method calls.
let ExprKind::MethodCall(call, _, elements, _) = &expr.kind else {
let ExprKind::MethodCall(call, elements, _) = &expr.kind else {
return
};
// We only care about method calls corresponding to the `Clone`, `Deref` and `Borrow`
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ impl InvalidAtomicOrdering {
sym::AtomicI128,
];
if_chain! {
if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind;
if let ExprKind::MethodCall(ref method_path, args, _) = &expr.kind;
if recognized_names.contains(&method_path.ident.name);
if let Some(m_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
if let Some(impl_did) = cx.tcx.impl_of_method(m_def_id);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ impl<'tcx> Cx<'tcx> {

let kind = match expr.kind {
// Here comes the interesting stuff:
hir::ExprKind::MethodCall(_, method_span, ref args, fn_span) => {
hir::ExprKind::MethodCall(segment, ref args, fn_span) => {
// Rewrite a.b(c) into UFCS form like Trait::b(a, c)
let expr = self.method_callee(expr, method_span, None);
let expr = self.method_callee(expr, segment.ident.span, None);
// When we apply adjustments to the receiver, use the span of
// the overall method call for better diagnostics. args[0]
// is guaranteed to exist, since a method call always has a receiver.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,9 +1203,9 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
return;
}
}
hir::ExprKind::MethodCall(_, span, _, _) => {
hir::ExprKind::MethodCall(segment, ..) => {
// Method calls have to be checked specially.
self.span = span;
self.span = segment.ident.span;
if let Some(def_id) = self.typeck_results().type_dependent_def_id(expr.hir_id) {
if self.visit(self.tcx.type_of(def_id)).is_break() {
return;
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_save_analysis/src/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,9 +1363,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
let res = self.save_ctxt.get_path_res(hir_expr.hir_id);
self.process_struct_lit(ex, path, fields, adt.variant_of_res(res), *rest)
}
hir::ExprKind::MethodCall(ref seg, _, args, _) => {
self.process_method_call(ex, seg, args)
}
hir::ExprKind::MethodCall(ref seg, args, _) => self.process_method_call(ex, seg, args),
hir::ExprKind::Field(ref sub_ex, _) => {
self.visit_expr(&sub_ex);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2322,7 +2322,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if let Some(Node::Expr(hir::Expr {
kind:
hir::ExprKind::Call(hir::Expr { span, .. }, _)
| hir::ExprKind::MethodCall(_, span, ..),
| hir::ExprKind::MethodCall(
hir::PathSegment { ident: Ident { span, .. }, .. },
..,
),
..
})) = hir.find(call_hir_id)
{
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let expr_parent = self.tcx.hir().get_parent_node(*expr_hir_id);
let hir = self.tcx.hir().find(expr_parent);
let closure_params_len = closure_fn_decl.inputs.len();
let (method_path, method_span, method_expr) = match (hir, closure_params_len) {
let (method_path, method_expr) = match (hir, closure_params_len) {
(
Some(Node::Expr(hir::Expr {
kind: hir::ExprKind::MethodCall(path, span, expr, _),
kind: hir::ExprKind::MethodCall(segment, expr, _),
..
})),
1,
) => (path, span, expr),
) => (segment, expr),
_ => return None,
};

Expand All @@ -483,10 +483,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|| self_ty.starts_with("std::option::Option")
|| self_ty.starts_with("std::result::Result"))
&& (name == sym::map || name == sym::and_then);
match (is_as_ref_able, self.sess().source_map().span_to_snippet(*method_span)) {
match (is_as_ref_able, self.sess().source_map().span_to_snippet(method_path.ident.span)) {
(true, Ok(src)) => {
let suggestion = format!("as_ref().{}", src);
Some((*method_span, "consider using `as_ref` instead", suggestion))
Some((method_path.ident.span, "consider using `as_ref` instead", suggestion))
}
_ => None,
}
Expand Down Expand Up @@ -643,8 +643,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
if self.can_coerce(ref_ty, expected) {
let mut sugg_sp = sp;
if let hir::ExprKind::MethodCall(ref segment, sp, ref args, _) = expr.kind {
let clone_trait = self.tcx.require_lang_item(LangItem::Clone, Some(sp));
if let hir::ExprKind::MethodCall(ref segment, ref args, _) = expr.kind {
let clone_trait =
self.tcx.require_lang_item(LangItem::Clone, Some(segment.ident.span));
if let ([arg], Some(true), sym::clone) = (
&args[..],
self.typeck_results.borrow().type_dependent_def_id(expr.hir_id).map(
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// we skip issuing a warning because it is autogenerated code.
ExprKind::Call(..) if expr.span.is_desugaring(DesugaringKind::TryBlock) => {}
ExprKind::Call(callee, _) => self.warn_if_unreachable(expr.hir_id, callee.span, "call"),
ExprKind::MethodCall(_, ref span, _, _) => {
self.warn_if_unreachable(expr.hir_id, *span, "call")
ExprKind::MethodCall(segment, ..) => {
self.warn_if_unreachable(expr.hir_id, segment.ident.span, "call")
}
_ => self.warn_if_unreachable(expr.hir_id, expr.span, "expression"),
}
Expand Down Expand Up @@ -306,8 +306,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
ExprKind::Block(body, _) => self.check_block_with_expected(&body, expected),
ExprKind::Call(callee, args) => self.check_call(expr, &callee, args, expected),
ExprKind::MethodCall(segment, span, args, _) => {
self.check_method_call(expr, segment, span, args, expected)
ExprKind::MethodCall(segment, args, _) => {
self.check_method_call(expr, segment, args, expected)
}
ExprKind::Cast(e, t) => self.check_expr_cast(e, t, expr),
ExprKind::Type(e, t) => {
Expand Down Expand Up @@ -1097,14 +1097,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
expr: &'tcx hir::Expr<'tcx>,
segment: &hir::PathSegment<'_>,
span: Span,
args: &'tcx [hir::Expr<'tcx>],
expected: Expectation<'tcx>,
) -> Ty<'tcx> {
let rcvr = &args[0];
let rcvr_t = self.check_expr(&rcvr);
// no need to check for bot/err -- callee does that
let rcvr_t = self.structurally_resolved_type(args[0].span, rcvr_t);
let span = segment.ident.span;

let method = match self.lookup_method(rcvr_t, segment, span, expr, rcvr, args) {
Ok(method) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if found != self.tcx.types.unit {
return;
}
if let ExprKind::MethodCall(path_segment, _, [rcvr, ..], _) = expr.kind {
if let ExprKind::MethodCall(path_segment, [rcvr, ..], _) = expr.kind {
if self
.typeck_results
.borrow()
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir::ExprKind::Call(hir::Expr { span, .. }, args) => {
(*span, *span, &args[..], None)
}
hir::ExprKind::MethodCall(path_segment, span, args, _) => (
*span,
hir::ExprKind::MethodCall(path_segment, args, _) => (
path_segment.ident.span,
// `sp` doesn't point at the whole `foo.bar()`, only at `bar`.
path_segment
.args
Expand All @@ -161,7 +161,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.source_map()
.next_point(tcx.sess.source_map().next_point(arg.span()))
})
.unwrap_or(*span),
.unwrap_or(path_segment.ident.span),
&args[1..], // Skip the receiver.
None, // methods are never ctors
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DropRangeVisitor<'a, 'tcx> {

self.handle_uninhabited_return(expr);
}
ExprKind::MethodCall(_, _, exprs, _) => {
ExprKind::MethodCall(_, exprs, _) => {
for expr in exprs {
self.visit_expr(expr);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/span_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
}

fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'tcx>) {
if let ExprKind::MethodCall(segment, method_span, _, _) = expr.kind {
if let ExprKind::MethodCall(segment, ..) = expr.kind {
if let Some(hir_id) = segment.hir_id {
let hir = self.tcx.hir();
let body_id = hir.enclosing_body_owner(hir_id);
Expand All @@ -141,7 +141,7 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
});
if let Some(def_id) = typeck_results.type_dependent_def_id(expr.hir_id) {
self.matches.insert(
method_span,
segment.ident.span,
match hir.span_if_local(def_id) {
Some(span) => LinkFromSrc::Local(clean::Span::new(span)),
None => LinkFromSrc::External(def_id),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/scrape_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ where
return;
}
}
hir::ExprKind::MethodCall(_, _, _, span) => {
hir::ExprKind::MethodCall(_, _, span) => {
let types = tcx.typeck(ex.hir_id.owner);
let def_id = if let Some(def_id) = types.type_dependent_def_id(ex.hir_id) {
def_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
// do not lint if the closure is called using an iterator (see #1141)
if_chain! {
if let Some(parent) = get_parent_expr(self.cx, expr);
if let ExprKind::MethodCall(_, _, [self_arg, ..], _) = &parent.kind;
if let ExprKind::MethodCall(_, [self_arg, ..], _) = &parent.kind;
let caller = self.cx.typeck_results().expr_ty(self_arg);
if let Some(iter_id) = self.cx.tcx.get_diagnostic_item(sym::Iterator);
if implements_trait(self.cx, caller, iter_id, &[]);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
))
})
},
ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => {
ExprKind::MethodCall(path, args, _) if args.len() == 1 => {
let type_of_receiver = cx.typeck_results().expr_ty(&args[0]);
if !is_type_diagnostic_item(cx, type_of_receiver, sym::Option)
&& !is_type_diagnostic_item(cx, type_of_receiver, sym::Result)
Expand Down
Loading

0 comments on commit b117335

Please sign in to comment.