From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id 306EB3858404 for ; Sun, 22 Aug 2021 21:05:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 306EB3858404 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-ed1-x534.google.com with SMTP id bo19so22968577edb.9 for ; Sun, 22 Aug 2021 14:05:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MyyoRoyni6cNv5zx5g6jnSqK6DiKXmyVApaW5xAe61U=; b=ZpmPALw3mTWKOh2DU3FG/m9F8bygcQNk89rLdyZkVkqIi8JqHxxNeomCD2eE5sReLP rP4LpEVMwgg+yBJA5JAu/CpzhGjz9LcMs869ixS8JFZ+igRYiRfahUi1pYF0Jj9UjzZB 5UAJQTQNSguFfxg6E5LiSWKyfcWqCCPp1XIL6Bvntzjua6bGyw5xsGAxGWqZXqdjLNPK 6E7LKMRh5OC5S3na/cXyoiL4vVg3Mv5V/js6PSLZkDYNqmXl4vQlU0Jajppw/uCcmmlz FlHjEwmBDWeCc+8UcA+4OrhbmX8pM+lP3WI7LaMk9C1ggttsjuwUPP/0XXalb0n0aGEO Ykyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MyyoRoyni6cNv5zx5g6jnSqK6DiKXmyVApaW5xAe61U=; b=SG6X1/U7lmA1cqVmtvpjq1zZneLaGeCy6+ZDoeskCoRrjzkWiS7pr4htSF8lIo7odi XrlDuhw8dPbqoameZbxg0W2Mu6pCPFfIAc01XPUJGroviysWuSCX9/kVarEI69KDDGNM tikf4GXUA2n6e6mvq6HgPmjO1PRkUr7LrDte7wS+bYZwIkwPEnQdMkqMrYDFSdB4MrPB YeiMLsfHUI0v4UnG5j0V5r3llXQFxXfqtUf6Ysta4EYkTWJviy6B80hX6PFQy04ePOd0 E+rcOYPay0Iq/TfV9Clze13kRNngQNCt/e5HorJ5UJYpT8uFdqw7S/68t8SI7/5WLQnH 6blQ== X-Gm-Message-State: AOAM5336/MGocbwgdhR/Xeu9sozIjfhWVguhukz8lYDhNfzc5Kb7eTIb NdGIoa91Cv1+o/u8p/vsMPSH3/MFCEMSvaUjxblp2A== X-Google-Smtp-Source: ABdhPJzG4vr9YMFf6bK4BnJQB2SmASWVnCX61SW6R2jNQAE/ZrwK3ZtIPV/g1MeVSljFOA/LjdxLYpRmK3oUe1S8Z78= X-Received: by 2002:a05:6402:4d:: with SMTP id f13mr33923913edu.275.1629666299220; Sun, 22 Aug 2021 14:04:59 -0700 (PDT) MIME-Version: 1.0 References: <20210821234748.182213-1-mark@klomp.org> In-Reply-To: <20210821234748.182213-1-mark@klomp.org> From: Philip Herron Date: Sun, 22 Aug 2021 22:04:48 +0100 Message-ID: Subject: Re: [PATCH] Reject duplicate field names in structs and unions. To: Mark Wielaard Cc: gcc-rust@gcc.gnu.org Content-Type: multipart/alternative; boundary="000000000000de25e105ca2c40bd" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-rust@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: gcc-rust mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Aug 2021 21:05:10 -0000 --000000000000de25e105ca2c40bd Content-Type: text/plain; charset="UTF-8" Nice work once again, just to let you know about the little bit of duplication I think the name resolver needs a little bit of thought to handle forward declared items within a block like this: https://github.com/Rust-GCC/gccrs/issues/531. It might be as simple as calling ResolveToplevelItems when doing block expr resolution. Depending on how we fix this it might feed back a way to avoid this little bit of duplication. Thanks --Phil On Sun, 22 Aug 2021 at 00:48, Mark Wielaard wrote: > Odd things happen if structs or unions have duplicate field names. > Emit an error when lowering an struct/union item or declaration > statement and a duplicate field name is detected. A new testcase > 'dup_fields.rs' checks an error is actually produced. > --- > > https://code.wildebeest.org/git/user/mjw/gccrs/commit/?h=dup_fields > > gcc/rust/hir/rust-ast-lower-item.h | 27 ++++++++++++++++++++++++ > gcc/rust/hir/rust-ast-lower-stmt.h | 27 ++++++++++++++++++++++++ > gcc/testsuite/rust/compile/dup_fields.rs | 23 ++++++++++++++++++++ > 3 files changed, 77 insertions(+) > create mode 100644 gcc/testsuite/rust/compile/dup_fields.rs > > diff --git a/gcc/rust/hir/rust-ast-lower-item.h > b/gcc/rust/hir/rust-ast-lower-item.h > index bcf83ee63b6..b324d0b5b8b 100644 > --- a/gcc/rust/hir/rust-ast-lower-item.h > +++ b/gcc/rust/hir/rust-ast-lower-item.h > @@ -176,6 +176,25 @@ public: > struct_decl.get_locus ()); > } > > + /* Checks whether the name of a field already exists. Returns true > + and produces an error if so. */ > + static bool struct_field_name_exists (std::vector > &fields, > + HIR::StructField &new_field) > + { > + for (auto &field : fields) > + { > + if (field.get_field_name ().compare (new_field.get_field_name ()) > == 0) > + { > + RichLocation r (new_field.get_locus ()); > + r.add_range (field.get_locus ()); > + rust_error_at (r, "duplicate field name %qs", > + field.get_field_name ().c_str ()); > + return true; > + } > + } > + return false; > + } > + > void visit (AST::StructStruct &struct_decl) override > { > std::vector > generic_params; > @@ -206,6 +225,10 @@ public: > std::unique_ptr > (type), vis, > field.get_locus (), > field.get_outer_attrs ()); > + > + if (struct_field_name_exists (fields, translated_field)) > + return false; > + > fields.push_back (std::move (translated_field)); > return true; > }); > @@ -258,6 +281,10 @@ public: > std::unique_ptr > (type), > vis, variant.get_locus (), > variant.get_outer_attrs ()); > + > + if (struct_field_name_exists (variants, translated_variant)) > + return false; > + > variants.push_back (std::move (translated_variant)); > return true; > }); > diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h > b/gcc/rust/hir/rust-ast-lower-stmt.h > index c4c00ac0bee..1e72c8a2023 100644 > --- a/gcc/rust/hir/rust-ast-lower-stmt.h > +++ b/gcc/rust/hir/rust-ast-lower-stmt.h > @@ -161,6 +161,25 @@ public: > struct_decl.get_locus ()); > } > > + /* Checks whether the name of a field already exists. Returns true > + and produces an error if so. */ > + static bool struct_field_name_exists (std::vector > &fields, > + HIR::StructField &new_field) > + { > + for (auto &field : fields) > + { > + if (field.get_field_name ().compare (new_field.get_field_name ()) > == 0) > + { > + RichLocation r (new_field.get_locus ()); > + r.add_range (field.get_locus ()); > + rust_error_at (r, "duplicate field name %qs", > + field.get_field_name ().c_str ()); > + return true; > + } > + } > + return false; > + } > + > void visit (AST::StructStruct &struct_decl) override > { > std::vector > generic_params; > @@ -191,6 +210,10 @@ public: > std::unique_ptr > (type), vis, > field.get_locus (), > field.get_outer_attrs ()); > + > + if (struct_field_name_exists (fields, translated_field)) > + return false; > + > fields.push_back (std::move (translated_field)); > return true; > }); > @@ -242,6 +265,10 @@ public: > std::unique_ptr > (type), > vis, variant.get_locus (), > variant.get_outer_attrs ()); > + > + if (struct_field_name_exists (variants, translated_variant)) > + return false; > + > variants.push_back (std::move (translated_variant)); > return true; > }); > diff --git a/gcc/testsuite/rust/compile/dup_fields.rs > b/gcc/testsuite/rust/compile/dup_fields.rs > new file mode 100644 > index 00000000000..ab39955eca0 > --- /dev/null > +++ b/gcc/testsuite/rust/compile/dup_fields.rs > @@ -0,0 +1,23 @@ > +struct S { a: i32, b: i32, c: u8, a: i128 } > +// { dg-error "duplicate field" "" { target *-*-* } .-1 } > + > +union U > + { > + a: i32, > + b: i32, > + c: u8, > + b: char // { dg-error "duplicate field" "" { target *-*-* } } > + } > + > +fn main () > +{ > + struct SS { alpha: i32, beta: i32, gamma: u8, gamma: i128 } > + // { dg-error "duplicate field" "" { target *-*-* } .-1 } > + > + union UU > + { > + alpha: i32, beta: i32, > + gamma: u8, beta: char > + // { dg-error "duplicate field" "" { target *-*-* } .-1 } > + } > +} > -- > 2.32.0 > > -- > Gcc-rust mailing list > Gcc-rust@gcc.gnu.org > https://gcc.gnu.org/mailman/listinfo/gcc-rust > --000000000000de25e105ca2c40bd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Nice work once again, just to let you know about the = little bit of duplication I think the name resolver needs a little bit of t= hought to handle forward declared items within a block like this: https://github.com/Rust-G= CC/gccrs/issues/531. It might be as simple as calling ResolveToplevelIt= ems when doing block expr resolution. Depending on how we fix this it might= feed back a way to avoid this little bit of duplication.

Thanks

--Phil

On Sun, 22 Aug 2021 at 00:= 48, Mark Wielaard <mark@klomp.org&= gt; wrote:
Odd t= hings happen if structs or unions have duplicate field names.
Emit an error when lowering an struct/union item or declaration
statement and a duplicate field name is detected.=C2=A0 A new testcase
'= dup_fields.rs' checks an error is actually produced.
---

https://code.wildebeest.org/git= /user/mjw/gccrs/commit/?h=3Ddup_fields

=C2=A0gcc/rust/hir/rust-ast-lower-item.h=C2=A0 =C2=A0 =C2=A0 =C2=A0| 27 +++= +++++++++++++++++++++
=C2=A0gcc/rust/hir/rust-ast-lower-stmt.h=C2=A0 =C2=A0 =C2=A0 =C2=A0| 27 +++= +++++++++++++++++++++
=C2=A0gcc/testsuite/rust/compile/dup_fields.rs | 23 ++++++++++++++++++++
=C2=A03 files changed, 77 insertions(+)
=C2=A0create mode 100644 gcc/testsuite/rust/compile/dup_fields.rs

diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-low= er-item.h
index bcf83ee63b6..b324d0b5b8b 100644
--- a/gcc/rust/hir/rust-ast-lower-item.h
+++ b/gcc/rust/hir/rust-ast-lower-item.h
@@ -176,6 +176,25 @@ public:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct_decl.get_locus ());
=C2=A0 =C2=A0}

+=C2=A0 /* Checks whether the name of a field already exists.=C2=A0 Returns= true
+=C2=A0 =C2=A0 =C2=A0and produces an error if so.=C2=A0 */
+=C2=A0 static bool struct_field_name_exists (std::vector<HIR::StructFie= ld> &fields,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0HIR::Stru= ctField &new_field)
+=C2=A0 {
+=C2=A0 =C2=A0 for (auto &field : fields)
+=C2=A0 =C2=A0 =C2=A0 {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (field.get_field_name ().compare (new_field.= get_field_name ()) =3D=3D 0)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0RichLocation r (new_field.get_loc= us ());
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0r.add_range (field.get_locus ());=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rust_error_at (r, "duplicate= field name %qs",
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 field.get_field_name ().c_str ());
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return true;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
+=C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 return false;
+=C2=A0 }
+
=C2=A0 =C2=A0void visit (AST::StructStruct &struct_decl) override
=C2=A0 =C2=A0{
=C2=A0 =C2=A0 =C2=A0std::vector<std::unique_ptr<HIR::GenericParam>= > generic_params;
@@ -206,6 +225,10 @@ public:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0st= d::unique_ptr<HIR::Type> (type), vis,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fi= eld.get_locus (),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fi= eld.get_outer_attrs ());
+
+=C2=A0 =C2=A0 =C2=A0 if (struct_field_name_exists (fields, translated_fiel= d))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return false;
+
=C2=A0 =C2=A0 =C2=A0 =C2=A0fields.push_back (std::move (translated_field));=
=C2=A0 =C2=A0 =C2=A0 =C2=A0return true;
=C2=A0 =C2=A0 =C2=A0});
@@ -258,6 +281,10 @@ public:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0std::unique_ptr<HIR::Type> (type),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0vis, variant.get_locus (),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0variant.get_outer_attrs ());
+
+=C2=A0 =C2=A0 =C2=A0 if (struct_field_name_exists (variants, translated_va= riant))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return false;
+
=C2=A0 =C2=A0 =C2=A0 =C2=A0variants.push_back (std::move (translated_varian= t));
=C2=A0 =C2=A0 =C2=A0 =C2=A0return true;
=C2=A0 =C2=A0 =C2=A0});
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h b/gcc/rust/hir/rust-ast-low= er-stmt.h
index c4c00ac0bee..1e72c8a2023 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.h
+++ b/gcc/rust/hir/rust-ast-lower-stmt.h
@@ -161,6 +161,25 @@ public:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct_decl.get_locus ());
=C2=A0 =C2=A0}

+=C2=A0 /* Checks whether the name of a field already exists.=C2=A0 Returns= true
+=C2=A0 =C2=A0 =C2=A0and produces an error if so.=C2=A0 */
+=C2=A0 static bool struct_field_name_exists (std::vector<HIR::StructFie= ld> &fields,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0HIR::Stru= ctField &new_field)
+=C2=A0 {
+=C2=A0 =C2=A0 for (auto &field : fields)
+=C2=A0 =C2=A0 =C2=A0 {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (field.get_field_name ().compare (new_field.= get_field_name ()) =3D=3D 0)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0RichLocation r (new_field.get_loc= us ());
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0r.add_range (field.get_locus ());=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rust_error_at (r, "duplicate= field name %qs",
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 field.get_field_name ().c_str ());
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return true;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
+=C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 return false;
+=C2=A0 }
+
=C2=A0 =C2=A0void visit (AST::StructStruct &struct_decl) override
=C2=A0 =C2=A0{
=C2=A0 =C2=A0 =C2=A0std::vector<std::unique_ptr<HIR::GenericParam>= > generic_params;
@@ -191,6 +210,10 @@ public:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0st= d::unique_ptr<HIR::Type> (type), vis,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fi= eld.get_locus (),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fi= eld.get_outer_attrs ());
+
+=C2=A0 =C2=A0 =C2=A0 if (struct_field_name_exists (fields, translated_fiel= d))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return false;
+
=C2=A0 =C2=A0 =C2=A0 =C2=A0fields.push_back (std::move (translated_field));=
=C2=A0 =C2=A0 =C2=A0 =C2=A0return true;
=C2=A0 =C2=A0 =C2=A0});
@@ -242,6 +265,10 @@ public:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0std::unique_ptr<HIR::Type> (type),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0vis, variant.get_locus (),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0variant.get_outer_attrs ());
+
+=C2=A0 =C2=A0 =C2=A0 if (struct_field_name_exists (variants, translated_va= riant))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return false;
+
=C2=A0 =C2=A0 =C2=A0 =C2=A0variants.push_back (std::move (translated_varian= t));
=C2=A0 =C2=A0 =C2=A0 =C2=A0return true;
=C2=A0 =C2=A0 =C2=A0});
diff --git a/gcc/testsuite/rust/compile/dup_fields.rs b/gcc/testsuite/rust/c= ompile/dup_fields.rs
new file mode 100644
index 00000000000..ab39955eca0
--- /dev/null
+++ b/gcc/testsuite/rust/compile/dup_fields.rs
@@ -0,0 +1,23 @@
+struct S { a: i32, b: i32, c: u8, a: i128 }
+// { dg-error "duplicate field" "" { target *-*-* } .-= 1 }
+
+union U
+=C2=A0 {
+=C2=A0 =C2=A0 a: i32,
+=C2=A0 =C2=A0 b: i32,
+=C2=A0 =C2=A0 c: u8,
+=C2=A0 =C2=A0 b: char // { dg-error "duplicate field" "&quo= t; { target *-*-* } }
+=C2=A0 }
+
+fn main ()
+{
+=C2=A0 struct SS { alpha: i32, beta: i32, gamma: u8, gamma: i128 }
+=C2=A0 // { dg-error "duplicate field" "" { target *-*= -* } .-1 }
+
+=C2=A0 union UU
+=C2=A0 =C2=A0 {
+=C2=A0 =C2=A0 =C2=A0 alpha: i32, beta: i32,
+=C2=A0 =C2=A0 =C2=A0 gamma: u8, beta: char
+=C2=A0 =C2=A0 =C2=A0 // { dg-error "duplicate field" ""= ; { target *-*-* } .-1 }
+=C2=A0 =C2=A0 }
+}
--
2.32.0

--
Gcc-rust mailing list
Gcc-rust@gcc.gnu.= org
https://gcc.gnu.org/mailman/listinfo/gcc-rust
--000000000000de25e105ca2c40bd--