aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/rust-hir-dump.cc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-07-18 12:12:22 +0100
committerPhilip Herron <philip.herron@embecosm.com>2023-07-29 23:51:27 +0000
commitf284cff3ff950198c9f175200deb8ca48d498921 (patch)
tree82eaa85a1ed9c7fdf918c4fdd79b859bd4e18691 /gcc/rust/hir/rust-hir-dump.cc
parent7bb4d1b7502ce905f4fef89c7dba8b37cd12acdf (diff)
downloadgcc-f284cff3ff950198c9f175200deb8ca48d498921.zip
gcc-f284cff3ff950198c9f175200deb8ca48d498921.tar.gz
gcc-f284cff3ff950198c9f175200deb8ca48d498921.tar.bz2
gccrs: Track trait bound polarity properly
Trait bounds can have three forms in Rust the regular trait bound, '!' the negative trait bound to enforice that this trait must not be implmented and '?' the anti trait bound to remove this bound. This patch extends our Polarity enum to include the Anti trait bound and updates the HIR lowering code to track this properly. Addresses #2443 gcc/rust/ChangeLog: * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): use new BoundPolarity enum * hir/rust-ast-lower-type.cc (ASTLoweringTypeBounds::visit): likewise * hir/rust-hir-dump.cc (BoundPolarityString): new helper (Dump::visit): update hir dump * hir/tree/rust-hir-item.h (class ImplBlock): likewise * hir/tree/rust-hir-type.h (class TraitBound): likewise * hir/tree/rust-hir.cc (TraitBound::as_string): fix as string * util/rust-common.h (enum Polarity): add new anti bound (enum BoundPolarity): likewise * util/rust-hir-map.cc (Mappings::Mappings): update naming Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/hir/rust-hir-dump.cc')
-rw-r--r--gcc/rust/hir/rust-hir-dump.cc18
1 files changed, 16 insertions, 2 deletions
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 9294666..c134c80 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -52,6 +52,21 @@ std::string Dump::delims[2][2] = {
{std::string ("["), std::string ("]")},
};
+static std::string
+BoundPolarityString (BoundPolarity polarity)
+{
+ switch (polarity)
+ {
+ case RegularBound:
+ return "regular";
+ case NegativeBound:
+ return "negative";
+ case AntiBound:
+ return "anti";
+ }
+ return "unknown";
+}
+
void
Dump::go (HIR::Crate &e)
{
@@ -2276,8 +2291,7 @@ Dump::visit (TraitBound &e)
begin ("TraitBound");
do_mappings (e.get_mappings ());
put_field ("in_parens", std::to_string (e.get_in_parens ()));
- put_field ("opening_question_mark",
- std::to_string (e.get_opening_question_mark ()));
+ put_field ("polarity", BoundPolarityString (e.get_polarity ()));
visit_collection ("for_lifetime", e.get_for_lifetimes ());
visit_field ("type_path", e.get_path ());