Skip to content

Commit 32c9ffb

Browse files
committed
Clarify args terminology.
The deriving code has inconsistent terminology to describe args. In some places it distinguishes between: - the `&self` arg (if present), versus - all other args. In other places it distinguishes between: - the `&self` arg (if present) and any other arguments with the same type (in practice there is at most one, e.g. in `PartialEq::eq`), versus - all other args. The terms "self_args" and "nonself_args" are sometimes used for the former distinction, and sometimes for the latter. "args" is also sometimes used for "all other args". This commit makes the code consistently uses "self_args"/"nonself_args" for the former and "selflike_args"/"nonselflike_args" for the latter. This change makes the code easier to read. The commit also adds a panic on an impossible path (the `Self_` case) in `extract_arg_details`.
1 parent 052495d commit 32c9ffb

File tree

11 files changed

+147
-109
lines changed

11 files changed

+147
-109
lines changed

compiler/rustc_builtin_macros/src/deriving/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn expand_deriving_clone(
8080
name: sym::clone,
8181
generics: Bounds::empty(),
8282
explicit_self: true,
83-
args: Vec::new(),
83+
nonself_args: Vec::new(),
8484
ret_ty: Self_,
8585
attributes: attrs,
8686
unify_fieldless_variants: false,

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn expand_deriving_eq(
3232
name: sym::assert_receiver_is_total_eq,
3333
generics: Bounds::empty(),
3434
explicit_self: true,
35-
args: vec![],
35+
nonself_args: vec![],
3636
ret_ty: Unit,
3737
attributes: attrs,
3838
unify_fieldless_variants: true,

compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn expand_deriving_ord(
2828
name: sym::cmp,
2929
generics: Bounds::empty(),
3030
explicit_self: true,
31-
args: vec![(self_ref(), sym::other)],
31+
nonself_args: vec![(self_ref(), sym::other)],
3232
ret_ty: Path(path_std!(cmp::Ordering)),
3333
attributes: attrs,
3434
unify_fieldless_variants: true,

compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn expand_deriving_partial_eq(
6969
name: $name,
7070
generics: Bounds::empty(),
7171
explicit_self: true,
72-
args: vec![(self_ref(), sym::other)],
72+
nonself_args: vec![(self_ref(), sym::other)],
7373
ret_ty: Path(path_local!(bool)),
7474
attributes: attrs,
7575
unify_fieldless_variants: true,

compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn expand_deriving_partial_ord(
2626
name: sym::partial_cmp,
2727
generics: Bounds::empty(),
2828
explicit_self: true,
29-
args: vec![(self_ref(), sym::other)],
29+
nonself_args: vec![(self_ref(), sym::other)],
3030
ret_ty,
3131
attributes: attrs,
3232
unify_fieldless_variants: true,

compiler/rustc_builtin_macros/src/deriving/debug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn expand_deriving_debug(
2828
name: sym::fmt,
2929
generics: Bounds::empty(),
3030
explicit_self: true,
31-
args: vec![(fmtr, sym::f)],
31+
nonself_args: vec![(fmtr, sym::f)],
3232
ret_ty: Path(path_std!(fmt::Result)),
3333
attributes: Vec::new(),
3434
unify_fieldless_variants: false,
@@ -53,7 +53,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
5353
// We want to make sure we have the ctxt set so that we can use unstable methods
5454
let span = cx.with_def_site_ctxt(span);
5555
let name = cx.expr_lit(span, ast::LitKind::Str(ident.name, ast::StrStyle::Cooked));
56-
let fmt = substr.nonself_args[0].clone();
56+
let fmt = substr.nonselflike_args[0].clone();
5757

5858
// Struct and tuples are similar enough that we use the same code for both,
5959
// with some extra pieces for structs due to the field names.

compiler/rustc_builtin_macros/src/deriving/decodable.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ pub fn expand_deriving_rustc_decodable(
3636
)],
3737
},
3838
explicit_self: false,
39-
args: vec![(Ref(Box::new(Path(Path::new_local(typaram))), Mutability::Mut), sym::d)],
39+
nonself_args: vec![(
40+
Ref(Box::new(Path(Path::new_local(typaram))), Mutability::Mut),
41+
sym::d,
42+
)],
4043
ret_ty: Path(Path::new_(
4144
pathvec_std!(result::Result),
4245
vec![
@@ -63,7 +66,7 @@ fn decodable_substructure(
6366
substr: &Substructure<'_>,
6467
krate: Symbol,
6568
) -> BlockOrExpr {
66-
let decoder = substr.nonself_args[0].clone();
69+
let decoder = substr.nonselflike_args[0].clone();
6770
let recurse = vec![
6871
Ident::new(krate, trait_span),
6972
Ident::new(sym::Decodable, trait_span),

compiler/rustc_builtin_macros/src/deriving/default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn expand_deriving_default(
3434
name: kw::Default,
3535
generics: Bounds::empty(),
3636
explicit_self: false,
37-
args: Vec::new(),
37+
nonself_args: Vec::new(),
3838
ret_ty: Self_,
3939
attributes: attrs,
4040
unify_fieldless_variants: false,

compiler/rustc_builtin_macros/src/deriving/encodable.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ pub fn expand_deriving_rustc_encodable(
120120
)],
121121
},
122122
explicit_self: true,
123-
args: vec![(Ref(Box::new(Path(Path::new_local(typaram))), Mutability::Mut), sym::s)],
123+
nonself_args: vec![(
124+
Ref(Box::new(Path(Path::new_local(typaram))), Mutability::Mut),
125+
sym::s,
126+
)],
124127
ret_ty: Path(Path::new_(
125128
pathvec_std!(result::Result),
126129
vec![
@@ -147,7 +150,7 @@ fn encodable_substructure(
147150
substr: &Substructure<'_>,
148151
krate: Symbol,
149152
) -> BlockOrExpr {
150-
let encoder = substr.nonself_args[0].clone();
153+
let encoder = substr.nonselflike_args[0].clone();
151154
// throw an underscore in front to suppress unused variable warnings
152155
let blkarg = Ident::new(sym::_e, trait_span);
153156
let blkencoder = cx.expr_ident(trait_span, blkarg);

0 commit comments

Comments
 (0)