impl_item_ids.push_back (lowered->get_impl_mappings ().get_hirid ());
}
- Polarity polarity = Positive;
+ BoundPolarity polarity = BoundPolarity::RegularBound;
HIR::ImplBlock *hir_impl_block = new HIR::ImplBlock (
mapping, std::move (impl_items), std::move (generic_params),
std::unique_ptr<HIR::Type> (impl_type), nullptr, where_clause, polarity,
impl_item_ids.push_back (lowered->get_impl_mappings ().get_hirid ());
}
- Polarity polarity = impl_block.is_exclam () ? Positive : Negative;
+ BoundPolarity polarity = impl_block.is_exclam ()
+ ? BoundPolarity::RegularBound
+ : BoundPolarity::NegativeBound;
HIR::ImplBlock *hir_impl_block = new HIR::ImplBlock (
mapping, std::move (impl_items), std::move (generic_params),
std::unique_ptr<HIR::Type> (impl_type),
mappings->get_next_hir_id (crate_num),
UNKNOWN_LOCAL_DEFID);
+ BoundPolarity polarity = bound.has_opening_question_mark ()
+ ? BoundPolarity::AntiBound
+ : BoundPolarity::RegularBound;
translated = new HIR::TraitBound (mapping, *trait_path, bound.get_locus (),
- bound.is_in_parens (),
- bound.has_opening_question_mark ());
+ bound.is_in_parens (), polarity);
}
void
{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)
{
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 ());
std::unique_ptr<Type> impl_type;
std::unique_ptr<TypePath> trait_ref;
WhereClause where_clause;
- Polarity polarity;
+ BoundPolarity polarity;
location_t locus;
std::vector<std::unique_ptr<ImplItem>> impl_items;
std::vector<std::unique_ptr<GenericParam>> generic_params,
std::unique_ptr<Type> impl_type,
std::unique_ptr<TypePath> trait_ref, WhereClause where_clause,
- Polarity polarity, Visibility vis, AST::AttrVec inner_attrs,
+ BoundPolarity polarity, Visibility vis, AST::AttrVec inner_attrs,
AST::AttrVec outer_attrs, location_t locus)
: VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
WithInnerAttrs (std::move (inner_attrs)),
bool has_where_clause () const { return !where_clause.is_empty (); }
// Returns the polarity of the impl.
- Polarity get_polarity () const { return polarity; }
+ BoundPolarity get_polarity () const { return polarity; }
location_t get_locus () const override final { return locus; }
class TraitBound : public TypeParamBound
{
bool in_parens;
- bool opening_question_mark;
+ BoundPolarity polarity;
std::vector<LifetimeParam> for_lifetimes;
TypePath type_path;
location_t locus;
TraitBound (Analysis::NodeMapping mapping, TypePath type_path,
location_t locus, bool in_parens = false,
- bool opening_question_mark = false,
+ BoundPolarity polarity = BoundPolarity::RegularBound,
std::vector<LifetimeParam> for_lifetimes
= std::vector<LifetimeParam> ())
- : in_parens (in_parens), opening_question_mark (opening_question_mark),
+ : in_parens (in_parens), polarity (polarity),
for_lifetimes (std::move (for_lifetimes)),
type_path (std::move (type_path)), locus (locus), mappings (mapping)
{}
std::vector<LifetimeParam> &get_for_lifetimes () { return for_lifetimes; }
bool get_in_parens () { return in_parens; }
- bool get_opening_question_mark () { return opening_question_mark; }
+ BoundPolarity get_polarity () { return polarity; }
BoundType get_bound_type () const final override { return TRAITBOUND; }
{
std::string str ("TraitBound:");
- str += "\n Has opening question mark: ";
- if (opening_question_mark)
+ switch (polarity)
{
- str += "true";
- }
- else
- {
- str += "false";
+ case RegularBound:
+ break;
+ case NegativeBound:
+ str += "!";
+ break;
+ case AntiBound:
+ str += "?";
+ break;
}
str += "\n For lifetimes: ";
Normal
};
-enum Polarity
+enum BoundPolarity
{
- Positive,
- Negative
+ RegularBound,
+ NegativeBound,
+ AntiBound,
};
enum AsyncConstStatus
Analysis::NodeMapping node (0, 0, 0, 0);
builtinMarker
= new HIR::ImplBlock (node, {}, {}, nullptr, nullptr, HIR::WhereClause ({}),
- Positive,
+ BoundPolarity::RegularBound,
HIR::Visibility (HIR::Visibility::VisType::PUBLIC),
{}, {}, UNDEF_LOCATION);
}