/// small, positive ids.
pub const DUMMY_NODE_ID: NodeId = NodeId::MAX;
-/// A modifier on a bound, currently this is only used for `?Sized`, where the
-/// modifier is `Maybe`. Negative bounds should also be handled here.
+/// A modifier on a bound, e.g., `?Sized` or `?const Trait`.
+///
+/// Negative bounds should also be handled here.
#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)]
pub enum TraitBoundModifier {
+ /// No modifiers
None,
+
+ /// `?Trait`
Maybe,
+
+ /// `?const Trait`
+ MaybeConst,
+
+ /// `?const ?Trait`
+ //
+ // This parses but will be rejected during AST validation.
+ MaybeConstMaybe,
}
/// The AST represents all type param bounds as types.
pub fn to_bound(&self) -> Option<GenericBound> {
match &self.kind {
ExprKind::Path(None, path) => Some(GenericBound::Trait(
- PolyTraitRef::new(Vec::new(), path.clone(), None, self.span),
+ PolyTraitRef::new(Vec::new(), path.clone(), self.span),
TraitBoundModifier::None,
)),
_ => None,
pub legacy: bool,
}
-// Clippy uses Hash and PartialEq
-#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, Hash, PartialEq, HashStable_Generic)]
+#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, Hash, Eq, PartialEq)]
+#[derive(HashStable_Generic)]
pub enum StrStyle {
/// A regular string, like `"foo"`.
Cooked,
}
}
-// Clippy uses Hash and PartialEq
/// Type of the integer literal based on provided suffix.
-#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq, HashStable_Generic)]
+#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, Eq, PartialEq)]
+#[derive(HashStable_Generic)]
pub enum LitIntType {
/// e.g. `42_i32`.
Signed(IntTy),
}
/// Type of the float literal based on provided suffix.
-#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq, HashStable_Generic)]
+#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, Eq, PartialEq)]
+#[derive(HashStable_Generic)]
pub enum LitFloatType {
/// A float literal with a suffix (`1f32` or `1E10f32`).
Suffixed(FloatTy),
/// Literal kind.
///
/// E.g., `"foo"`, `42`, `12.34`, or `bool`.
-// Clippy uses Hash and PartialEq
-#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq, HashStable_Generic)]
+#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Hash, Eq, PartialEq, HashStable_Generic)]
pub enum LitKind {
/// A string literal (`"foo"`).
Str(Symbol, StrStyle),
}
}
-#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
+#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)]
+#[derive(HashStable_Generic)]
pub enum Constness {
Const,
NotConst,
pub struct TraitRef {
pub path: Path,
pub ref_id: NodeId,
-
- /// The `const` modifier, if any, that appears before this trait.
- ///
- /// | | `constness` |
- /// |----------------|-----------------------------|
- /// | `Trait` | `None` |
- /// | `const Trait` | `Some(Constness::Const)` |
- /// | `?const Trait` | `Some(Constness::NotConst)` |
- pub constness: Option<Constness>,
}
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
}
impl PolyTraitRef {
- pub fn new(
- generic_params: Vec<GenericParam>,
- path: Path,
- constness: Option<Constness>,
- span: Span,
- ) -> Self {
+ pub fn new(generic_params: Vec<GenericParam>, path: Path, span: Span) -> Self {
PolyTraitRef {
bound_generic_params: generic_params,
- trait_ref: TraitRef { path, constness, ref_id: DUMMY_NODE_ID },
+ trait_ref: TraitRef { path, ref_id: DUMMY_NODE_ID },
span,
}
}
/// An implementation.
///
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
- Impl(
- Unsafety,
- ImplPolarity,
- Defaultness,
- Generics,
- Option<TraitRef>, // (optional) trait this impl implements
- P<Ty>, // self
- Vec<AssocItem>,
- ),
+ Impl {
+ unsafety: Unsafety,
+ polarity: ImplPolarity,
+ defaultness: Defaultness,
+ constness: Constness,
+ generics: Generics,
+
+ /// The trait being implemented, if any.
+ of_trait: Option<TraitRef>,
+
+ self_ty: P<Ty>,
+ items: Vec<AssocItem>,
+ },
/// A macro invocation.
///
/// E.g., `foo!(..)`.
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
- ItemKind::Mac(..) | ItemKind::MacroDef(..) | ItemKind::Impl(..) => "item",
+ ItemKind::Mac(..) | ItemKind::MacroDef(..) | ItemKind::Impl { .. } => "item",
}
}
}