Skip to content

Commit 636a78a

Browse files
committed
Auto merge of #103633 - compiler-errors:beta-revert-rcvr-args-split, r=pnkfelix
Revert "Do not consider method call receiver as an argument in AST." Reverts #100232, including a few places where there were merge conflicts after this landed. r? `@pnkfelix` cc `@cjgillot` cc #103430 the nightly workaround for this issue.
2 parents a317055 + 4d01f53 commit 636a78a

File tree

21 files changed

+59
-105
lines changed

21 files changed

+59
-105
lines changed

Diff for: compiler/rustc_ast/src/ast.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1338,13 +1338,14 @@ pub enum ExprKind {
13381338
///
13391339
/// The `PathSegment` represents the method name and its generic arguments
13401340
/// (within the angle brackets).
1341-
/// The standalone `Expr` is the receiver expression.
1342-
/// The vector of `Expr` is the arguments.
1343-
/// `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
1344-
/// `ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, x, [a, b, c, d])`.
1341+
/// The first element of the vector of an `Expr` is the expression that evaluates
1342+
/// to the object on which the method is being called on (the receiver),
1343+
/// and the remaining elements are the rest of the arguments.
1344+
/// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
1345+
/// `ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, [x, a, b, c, d])`.
13451346
/// This `Span` is the span of the function, without the dot and receiver
13461347
/// (e.g. `foo(a, b)` in `x.foo(a, b)`
1347-
MethodCall(PathSegment, P<Expr>, Vec<P<Expr>>, Span),
1348+
MethodCall(PathSegment, Vec<P<Expr>>, Span),
13481349
/// A tuple (e.g., `(a, b, c, d)`).
13491350
Tup(Vec<P<Expr>>),
13501351
/// A binary operation (e.g., `a + b`, `a * b`).

Diff for: compiler/rustc_ast/src/mut_visit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1297,11 +1297,10 @@ pub fn noop_visit_expr<T: MutVisitor>(
12971297
vis.visit_expr(f);
12981298
visit_exprs(args, vis);
12991299
}
1300-
ExprKind::MethodCall(PathSegment { ident, id, args }, receiver, exprs, span) => {
1300+
ExprKind::MethodCall(PathSegment { ident, id, args }, exprs, span) => {
13011301
vis.visit_ident(ident);
13021302
vis.visit_id(id);
13031303
visit_opt(args, |args| vis.visit_generic_args(args));
1304-
vis.visit_expr(receiver);
13051304
visit_exprs(exprs, vis);
13061305
vis.visit_span(span);
13071306
}

Diff for: compiler/rustc_ast/src/util/parser.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
396396
contains_exterior_struct_lit(&x)
397397
}
398398

399-
ast::ExprKind::MethodCall(_, ref receiver, _, _) => {
399+
ast::ExprKind::MethodCall(.., ref exprs, _) => {
400400
// X { y: 1 }.bar(...)
401-
contains_exterior_struct_lit(&receiver)
401+
contains_exterior_struct_lit(&exprs[0])
402402
}
403403

404404
_ => false,

Diff for: compiler/rustc_ast/src/visit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,8 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
795795
visitor.visit_expr(callee_expression);
796796
walk_list!(visitor, visit_expr, arguments);
797797
}
798-
ExprKind::MethodCall(ref segment, ref receiver, ref arguments, _span) => {
798+
ExprKind::MethodCall(ref segment, ref arguments, _span) => {
799799
visitor.visit_path_segment(segment);
800-
visitor.visit_expr(receiver);
801800
walk_list!(visitor, visit_expr, arguments);
802801
}
803802
ExprKind::Binary(_, ref left_expression, ref right_expression) => {

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
6060
hir::ExprKind::Call(f, self.lower_exprs(args))
6161
}
6262
}
63-
ExprKind::MethodCall(ref seg, ref receiver, ref args, span) => {
63+
ExprKind::MethodCall(ref seg, ref args, span) => {
6464
let hir_seg = self.arena.alloc(self.lower_path_segment(
6565
e.span,
6666
seg,
6767
ParamMode::Optional,
6868
ParenthesizedGenericArgs::Err,
6969
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
7070
));
71-
let receiver = self.lower_expr(receiver);
71+
let receiver = self.lower_expr(&args[0]);
7272
let args =
73-
self.arena.alloc_from_iter(args.iter().map(|x| self.lower_expr_mut(x)));
73+
self.arena.alloc_from_iter(args[1..].iter().map(|x| self.lower_expr_mut(x)));
7474
hir::ExprKind::MethodCall(hir_seg, receiver, args, self.lower_span(span))
7575
}
7676
ExprKind::Binary(binop, ref lhs, ref rhs) => {

Diff for: compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,9 @@ impl<'a> State<'a> {
193193
self.print_call_post(args)
194194
}
195195

196-
fn print_expr_method_call(
197-
&mut self,
198-
segment: &ast::PathSegment,
199-
receiver: &ast::Expr,
200-
base_args: &[P<ast::Expr>],
201-
) {
202-
self.print_expr_maybe_paren(receiver, parser::PREC_POSTFIX);
196+
fn print_expr_method_call(&mut self, segment: &ast::PathSegment, args: &[P<ast::Expr>]) {
197+
let base_args = &args[1..];
198+
self.print_expr_maybe_paren(&args[0], parser::PREC_POSTFIX);
203199
self.word(".");
204200
self.print_ident(segment.ident);
205201
if let Some(ref args) = segment.args {
@@ -307,8 +303,8 @@ impl<'a> State<'a> {
307303
ast::ExprKind::Call(ref func, ref args) => {
308304
self.print_expr_call(func, &args);
309305
}
310-
ast::ExprKind::MethodCall(ref segment, ref receiver, ref args, _) => {
311-
self.print_expr_method_call(segment, &receiver, &args);
306+
ast::ExprKind::MethodCall(ref segment, ref args, _) => {
307+
self.print_expr_method_call(segment, &args);
312308
}
313309
ast::ExprKind::Binary(op, ref lhs, ref rhs) => {
314310
self.print_expr_binary(op, lhs, rhs);

Diff for: compiler/rustc_builtin_macros/src/assert/context.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ impl<'cx, 'a> Context<'cx, 'a> {
241241
self.manage_cond_expr(prefix);
242242
self.manage_cond_expr(suffix);
243243
}
244-
ExprKind::MethodCall(_, _,ref mut local_exprs, _) => {
245-
for local_expr in local_exprs.iter_mut() {
244+
ExprKind::MethodCall(_, ref mut local_exprs, _) => {
245+
for local_expr in local_exprs.iter_mut().skip(1) {
246246
self.manage_cond_expr(local_expr);
247247
}
248248
}
@@ -378,12 +378,14 @@ impl<'cx, 'a> Context<'cx, 'a> {
378378
id: DUMMY_NODE_ID,
379379
ident: Ident::new(sym::try_capture, self.span),
380380
},
381-
expr_paren(self.cx, self.span, self.cx.expr_addr_of(self.span, wrapper)),
382-
vec![expr_addr_of_mut(
383-
self.cx,
384-
self.span,
385-
self.cx.expr_path(Path::from_ident(capture)),
386-
)],
381+
vec![
382+
expr_paren(self.cx, self.span, self.cx.expr_addr_of(self.span, wrapper)),
383+
expr_addr_of_mut(
384+
self.cx,
385+
self.span,
386+
self.cx.expr_path(Path::from_ident(capture)),
387+
),
388+
],
387389
self.span,
388390
))
389391
.add_trailing_semicolon();
@@ -441,11 +443,10 @@ fn expr_addr_of_mut(cx: &ExtCtxt<'_>, sp: Span, e: P<Expr>) -> P<Expr> {
441443
fn expr_method_call(
442444
cx: &ExtCtxt<'_>,
443445
path: PathSegment,
444-
receiver: P<Expr>,
445446
args: Vec<P<Expr>>,
446447
span: Span,
447448
) -> P<Expr> {
448-
cx.expr(span, ExprKind::MethodCall(path, receiver, args, span))
449+
cx.expr(span, ExprKind::MethodCall(path, args, span))
449450
}
450451

451452
fn expr_paren(cx: &ExtCtxt<'_>, sp: Span, e: P<Expr>) -> P<Expr> {

Diff for: compiler/rustc_lint/src/unused.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,8 @@ trait UnusedDelimLint {
608608
ref call_or_other => {
609609
let (args_to_check, ctx) = match *call_or_other {
610610
Call(_, ref args) => (&args[..], UnusedDelimsCtx::FunctionArg),
611-
MethodCall(_, _, ref args, _) => (&args[..], UnusedDelimsCtx::MethodArg),
611+
// first "argument" is self (which sometimes needs delims)
612+
MethodCall(_, ref args, _) => (&args[1..], UnusedDelimsCtx::MethodArg),
612613
// actual catch-all arm
613614
_ => {
614615
return;

Diff for: compiler/rustc_parse/src/parser/expr.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ impl<'a> Parser<'a> {
832832
ExprKind::Index(_, _) => "indexing",
833833
ExprKind::Try(_) => "`?`",
834834
ExprKind::Field(_, _) => "a field access",
835-
ExprKind::MethodCall(_, _, _, _) => "a method call",
835+
ExprKind::MethodCall(_, _, _) => "a method call",
836836
ExprKind::Call(_, _) => "a function call",
837837
ExprKind::Await(_) => "`.await`",
838838
ExprKind::Err => return Ok(with_postfix),
@@ -1259,10 +1259,12 @@ impl<'a> Parser<'a> {
12591259

12601260
if self.check(&token::OpenDelim(Delimiter::Parenthesis)) {
12611261
// Method call `expr.f()`
1262-
let args = self.parse_paren_expr_seq()?;
1262+
let mut args = self.parse_paren_expr_seq()?;
1263+
args.insert(0, self_arg);
1264+
12631265
let fn_span = fn_span_lo.to(self.prev_token.span);
12641266
let span = lo.to(self.prev_token.span);
1265-
Ok(self.mk_expr(span, ExprKind::MethodCall(segment, self_arg, args, fn_span)))
1267+
Ok(self.mk_expr(span, ExprKind::MethodCall(segment, args, fn_span)))
12661268
} else {
12671269
// Field access `expr.f`
12681270
if let Some(args) = segment.args {

Diff for: compiler/rustc_resolve/src/late.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3793,8 +3793,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
37933793
ExprKind::Field(ref subexpression, _) => {
37943794
self.resolve_expr(subexpression, Some(expr));
37953795
}
3796-
ExprKind::MethodCall(ref segment, ref receiver, ref arguments, _) => {
3797-
self.resolve_expr(receiver, Some(expr));
3796+
ExprKind::MethodCall(ref segment, ref arguments, _) => {
3797+
let mut arguments = arguments.iter();
3798+
self.resolve_expr(arguments.next().unwrap(), Some(expr));
37983799
for argument in arguments {
37993800
self.resolve_expr(argument, None);
38003801
}

Diff for: compiler/rustc_resolve/src/late/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
10171017

10181018
let (lhs_span, rhs_span) = match &expr.kind {
10191019
ExprKind::Field(base, ident) => (base.span, ident.span),
1020-
ExprKind::MethodCall(_, receiver, _, span) => (receiver.span, *span),
1020+
ExprKind::MethodCall(_, args, span) => (args[0].span, *span),
10211021
_ => return false,
10221022
};
10231023

Diff for: src/test/ui-fulldeps/pprust-expr-roundtrip.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
7373
2 => {
7474
let seg = PathSegment::from_ident(Ident::from_str("x"));
7575
iter_exprs(depth - 1, &mut |e| {
76-
g(ExprKind::MethodCall(seg.clone(), e, vec![make_x()], DUMMY_SP))
76+
g(ExprKind::MethodCall(seg.clone(), vec![e, make_x()], DUMMY_SP))
7777
});
7878
iter_exprs(depth - 1, &mut |e| {
79-
g(ExprKind::MethodCall(seg.clone(), make_x(), vec![e], DUMMY_SP))
79+
g(ExprKind::MethodCall(seg.clone(), vec![make_x(), e], DUMMY_SP))
8080
});
8181
}
8282
3..=8 => {

Diff for: src/test/ui/cfg/cfg-method-receiver.rs

-12
This file was deleted.

Diff for: src/test/ui/cfg/cfg-method-receiver.stderr

-34
This file was deleted.

Diff for: src/tools/clippy/clippy_lints/src/double_parens.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ impl EarlyLintPass for DoubleParens {
6161
}
6262
}
6363
},
64-
ExprKind::MethodCall(_, _, ref params, _) => {
65-
if let [ref param] = params[..] {
64+
ExprKind::MethodCall(_, ref params, _) => {
65+
if params.len() == 2 {
66+
let param = &params[1];
6667
if let ExprKind::Paren(_) = param.kind {
6768
span_lint(cx, DOUBLE_PARENS, param.span, msg);
6869
}

Diff for: src/tools/clippy/clippy_lints/src/option_env_unwrap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ declare_lint_pass!(OptionEnvUnwrap => [OPTION_ENV_UNWRAP]);
3737
impl EarlyLintPass for OptionEnvUnwrap {
3838
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
3939
if_chain! {
40-
if let ExprKind::MethodCall(path_segment, receiver, _, _) = &expr.kind;
40+
if let ExprKind::MethodCall(path_segment, args, _) = &expr.kind;
4141
if matches!(path_segment.ident.name, sym::expect | sym::unwrap);
42-
if let ExprKind::Call(caller, _) = &receiver.kind;
42+
if let ExprKind::Call(caller, _) = &args[0].kind;
4343
if is_direct_expn_of(caller.span, "option_env").is_some();
4444
then {
4545
span_lint_and_help(

Diff for: src/tools/clippy/clippy_lints/src/precedence.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ impl EarlyLintPass for Precedence {
109109
let mut arg = operand;
110110

111111
let mut all_odd = true;
112-
while let ExprKind::MethodCall(path_segment, receiver, _, _) = &arg.kind {
112+
while let ExprKind::MethodCall(path_segment, args, _) = &arg.kind {
113113
let path_segment_str = path_segment.ident.name.as_str();
114114
all_odd &= ALLOWED_ODD_FUNCTIONS
115115
.iter()
116116
.any(|odd_function| **odd_function == *path_segment_str);
117-
arg = receiver;
117+
arg = args.first().expect("A method always has a receiver.");
118118
}
119119

120120
if_chain! {

Diff for: src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ fn ident_difference_expr_with_base_location(
595595
| (Unary(_, _), Unary(_, _))
596596
| (Binary(_, _, _), Binary(_, _, _))
597597
| (Tup(_), Tup(_))
598-
| (MethodCall(_, _, _, _), MethodCall(_, _, _, _))
598+
| (MethodCall(_, _, _), MethodCall(_, _, _))
599599
| (Call(_, _), Call(_, _))
600600
| (ConstBlock(_), ConstBlock(_))
601601
| (Array(_), Array(_))

Diff for: src/tools/clippy/clippy_lints/src/unused_rounding.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ declare_clippy_lint! {
3030
declare_lint_pass!(UnusedRounding => [UNUSED_ROUNDING]);
3131

3232
fn is_useless_rounding(expr: &Expr) -> Option<(&str, String)> {
33-
if let ExprKind::MethodCall(name_ident, receiver, _, _) = &expr.kind
33+
if let ExprKind::MethodCall(name_ident, args, _) = &expr.kind
3434
&& let method_name = name_ident.ident.name.as_str()
3535
&& (method_name == "ceil" || method_name == "round" || method_name == "floor")
36-
&& let ExprKind::Lit(spanned) = &receiver.kind
36+
&& !args.is_empty()
37+
&& let ExprKind::Lit(spanned) = &args[0].kind
3738
&& let LitKind::Float(symbol, ty) = spanned.kind {
3839
let f = symbol.as_str().parse::<f64>().unwrap();
3940
let f_str = symbol.to_string() + if let LitFloatType::Suffixed(ty) = ty {

Diff for: src/tools/clippy/clippy_utils/src/ast_utils.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
147147
(Array(l), Array(r)) | (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
148148
(Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value),
149149
(Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
150-
(MethodCall(lc, ls, la, _), MethodCall(rc, rs, ra, _)) => {
151-
eq_path_seg(lc, rc) && eq_expr(ls, rs) && over(la, ra, |l, r| eq_expr(l, r))
152-
},
150+
(MethodCall(lc, la, _), MethodCall(rc, ra, _)) => eq_path_seg(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
153151
(Binary(lo, ll, lr), Binary(ro, rl, rr)) => lo.node == ro.node && eq_expr(ll, rl) && eq_expr(lr, rr),
154152
(Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r),
155153
(Lit(l), Lit(r)) => l.kind == r.kind,

Diff for: src/tools/rustfmt/src/chains.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl ChainItemKind {
145145

146146
fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, Span) {
147147
let (kind, span) = match expr.kind {
148-
ast::ExprKind::MethodCall(ref segment, ref receiver, ref expressions, _) => {
148+
ast::ExprKind::MethodCall(ref segment, ref expressions, _) => {
149149
let types = if let Some(ref generic_args) = segment.args {
150150
if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
151151
data.args
@@ -163,7 +163,7 @@ impl ChainItemKind {
163163
} else {
164164
vec![]
165165
};
166-
let span = mk_sp(receiver.span.hi(), expr.span.hi());
166+
let span = mk_sp(expressions[0].span.hi(), expr.span.hi());
167167
let kind = ChainItemKind::MethodCall(segment.clone(), types, expressions.clone());
168168
(kind, span)
169169
}
@@ -253,7 +253,7 @@ impl ChainItem {
253253
format!("::<{}>", type_list.join(", "))
254254
};
255255
let callee_str = format!(".{}{}", rewrite_ident(context, method_name), type_str);
256-
rewrite_call(context, &callee_str, &args, span, shape)
256+
rewrite_call(context, &callee_str, &args[1..], span, shape)
257257
}
258258
}
259259

@@ -400,8 +400,8 @@ impl Chain {
400400
// is a try! macro, we'll convert it to shorthand when the option is set.
401401
fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option<ast::Expr> {
402402
match expr.kind {
403-
ast::ExprKind::MethodCall(_, ref receiver, _, _) => {
404-
Some(Self::convert_try(&receiver, context))
403+
ast::ExprKind::MethodCall(_, ref expressions, _) => {
404+
Some(Self::convert_try(&expressions[0], context))
405405
}
406406
ast::ExprKind::Field(ref subexpr, _)
407407
| ast::ExprKind::Try(ref subexpr)

0 commit comments

Comments
 (0)