1
Fork 0

Minor updates based on review comments.

This commit is contained in:
Nicholas Nethercote 2022-07-08 07:57:34 +10:00
parent 16a286b003
commit 0578697a63

View file

@ -245,7 +245,8 @@ pub struct MethodDef<'a> {
pub struct Substructure<'a> { pub struct Substructure<'a> {
/// ident of self /// ident of self
pub type_ident: Ident, pub type_ident: Ident,
/// verbatim access to any non-selflike arguments /// Verbatim access to any non-selflike arguments, i.e. arguments that
/// don't have type `&Self`.
pub nonselflike_args: &'a [P<Expr>], pub nonselflike_args: &'a [P<Expr>],
pub fields: &'a SubstructureFields<'a>, pub fields: &'a SubstructureFields<'a>,
} }
@ -934,10 +935,9 @@ impl<'a> MethodDef<'a> {
let arg_expr = cx.expr_ident(span, ident); let arg_expr = cx.expr_ident(span, ident);
match *ty { match ty {
// for static methods, just treat any Self // Selflike (`&Self`) arguments only occur in non-static methods.
// arguments as a normal arg Ref(box Self_, _) if !self.is_static() => {
Ref(ref ty, _) if matches!(**ty, Self_) && !self.is_static() => {
selflike_args.push(cx.expr_deref(span, arg_expr)) selflike_args.push(cx.expr_deref(span, arg_expr))
} }
Self_ => cx.span_bug(span, "`Self` in non-return position"), Self_ => cx.span_bug(span, "`Self` in non-return position"),
@ -1459,11 +1459,8 @@ impl<'a> TraitDef<'a> {
prefixes prefixes
.iter() .iter()
.map(|prefix| { .map(|prefix| {
let pieces: Vec<_> = struct_def let pieces_iter =
.fields() struct_def.fields().iter().enumerate().map(|(i, struct_field)| {
.iter()
.enumerate()
.map(|(i, struct_field)| {
let sp = struct_field.span.with_ctxt(self.span.ctxt()); let sp = struct_field.span.with_ctxt(self.span.ctxt());
let binding_mode = if use_temporaries { let binding_mode = if use_temporaries {
ast::BindingMode::ByValue(ast::Mutability::Not) ast::BindingMode::ByValue(ast::Mutability::Not)
@ -1477,14 +1474,12 @@ impl<'a> TraitDef<'a> {
struct_field.ident, struct_field.ident,
cx.pat(path.span, PatKind::Ident(binding_mode, path, None)), cx.pat(path.span, PatKind::Ident(binding_mode, path, None)),
) )
}) });
.collect();
let struct_path = struct_path.clone(); let struct_path = struct_path.clone();
match *struct_def { match *struct_def {
VariantData::Struct(..) => { VariantData::Struct(..) => {
let field_pats = pieces let field_pats = pieces_iter
.into_iter()
.map(|(sp, ident, pat)| { .map(|(sp, ident, pat)| {
if ident.is_none() { if ident.is_none() {
cx.span_bug( cx.span_bug(
@ -1506,7 +1501,7 @@ impl<'a> TraitDef<'a> {
cx.pat_struct(self.span, struct_path, field_pats) cx.pat_struct(self.span, struct_path, field_pats)
} }
VariantData::Tuple(..) => { VariantData::Tuple(..) => {
let subpats = pieces.into_iter().map(|(_, _, subpat)| subpat).collect(); let subpats = pieces_iter.map(|(_, _, subpat)| subpat).collect();
cx.pat_tuple_struct(self.span, struct_path, subpats) cx.pat_tuple_struct(self.span, struct_path, subpats)
} }
VariantData::Unit(..) => cx.pat_path(self.span, struct_path), VariantData::Unit(..) => cx.pat_path(self.span, struct_path),