Remove a span from hir::ExprKind::MethodCall
This commit is contained in:
parent
84e918971d
commit
b11733534d
112 changed files with 211 additions and 220 deletions
|
@ -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);
|
||||
|
|
|
@ -1669,13 +1669,13 @@ 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)`
|
||||
///
|
||||
|
@ -1683,7 +1683,7 @@ pub enum ExprKind<'hir> {
|
|||
/// 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`).
|
||||
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -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), \
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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(
|
||||
|
|
|
@ -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"),
|
||||
}
|
||||
|
@ -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) => {
|
||||
|
@ -1097,7 +1097,6 @@ 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> {
|
||||
|
@ -1105,6 +1104,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
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) => {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
),
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue