diff options
| author | Cameron Steffen <cam.steffen94@gmail.com> | 2021-12-01 11:17:50 -0600 |
|---|---|---|
| committer | Cameron Steffen <cam.steffen94@gmail.com> | 2022-01-21 07:48:10 -0600 |
| commit | b11733534d95aebe0b4f949f8e4c8f21c312f108 (patch) | |
| tree | 12ff6db964e10b1c2e6e8f0d19a23d06c0de77c3 /compiler | |
| parent | 84e918971d643c6a33067d5125214ab800ce5307 (diff) | |
| download | rust-b11733534d95aebe0b4f949f8e4c8f21c312f108.tar.gz rust-b11733534d95aebe0b4f949f8e4c8f21c312f108.zip | |
Remove a span from hir::ExprKind::MethodCall
Diffstat (limited to 'compiler')
19 files changed, 46 insertions, 49 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 6c172d59f83..f04dc85b28a 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -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); diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index a9dbdd483fe..4e6fac5eb28 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -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); diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index cfdcd1618ba..1d10e79d300 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -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); } diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index a301c5e3456..9e54122f8dd 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -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) => { diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 1fc78f8f9e3..4c93ec7ab18 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -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 diff --git a/compiler/rustc_lint/src/array_into_iter.rs b/compiler/rustc_lint/src/array_into_iter.rs index b6151757588..a14d6020361 100644 --- a/compiler/rustc_lint/src/array_into_iter.rs +++ b/compiler/rustc_lint/src/array_into_iter.rs @@ -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), \ diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 38e1669d331..65385d4c7a1 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -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) { diff --git a/compiler/rustc_lint/src/methods.rs b/compiler/rustc_lint/src/methods.rs index 5558947de0c..ae936834754 100644 --- a/compiler/rustc_lint/src/methods.rs +++ b/compiler/rustc_lint/src/methods.rs @@ -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 diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs index 4bcd4c6d603..39b5b7afdae 100644 --- a/compiler/rustc_lint/src/noop_method_call.rs +++ b/compiler/rustc_lint/src/noop_method_call.rs @@ -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` diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 1acff13d1aa..bceb5e536e7 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -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); diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index a43388808cd..374e6ef87a7 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -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. diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 0b4579b299d..d59c12fc2fa 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -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; diff --git a/compiler/rustc_save_analysis/src/dump_visitor.rs b/compiler/rustc_save_analysis/src/dump_visitor.rs index 754c2b03e66..8b4ab77dffb 100644 --- a/compiler/rustc_save_analysis/src/dump_visitor.rs +++ b/compiler/rustc_save_analysis/src/dump_visitor.rs @@ -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); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index da0b691a958..e94c600bb49 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -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) { diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index 241dcbc64a6..2409346298d 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -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( diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index f6abeff60cd..23cc4b0ffc8 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -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) => { diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index f01b8267817..0f9803b969f 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -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() diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 4d88feb65d1..e42d94a6f40 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -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 ), diff --git a/compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs b/compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs index fc957b89990..d7d52ab823c 100644 --- a/compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs +++ b/compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs @@ -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); } |
