}
}
+/// The kind of borrow in an `AddrOf` expression,
+/// e.g., `&place` or `&raw const place`.
+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
+#[derive(RustcEncodable, RustcDecodable, HashStable_Generic)]
+pub enum BorrowKind {
+ /// A raw borrow, `&raw const $expr` or `&raw mut $expr`.
+ /// The resulting type is either `*const T` or `*mut T`
+ /// where `T = typeof($expr)`.
+ Ref,
+ /// A normal borrow, `&$expr` or `&mut $expr`.
+ /// The resulting type is either `&'a T` or `&'a mut T`
+ /// where `T = typeof($expr)` and `'a` is some lifetime.
+ Raw,
+}
+
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
pub enum BinOpKind {
/// The `+` operator (addition)
/// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct field.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Field {
+ pub attrs: ThinVec<Attribute>,
+ pub id: NodeId,
+ pub span: Span,
pub ident: Ident,
pub expr: P<Expr>,
- pub span: Span,
pub is_shorthand: bool,
- pub attrs: ThinVec<Attribute>,
- pub id: NodeId,
pub is_placeholder: bool,
}
ExprKind::Paren(expr) => expr.to_ty().map(TyKind::Paren)?,
- ExprKind::AddrOf(mutbl, expr) => expr
+ ExprKind::AddrOf(BorrowKind::Ref, mutbl, expr) => expr
.to_ty()
.map(|ty| TyKind::Rptr(None, MutTy { ty, mutbl: *mutbl }))?,
/// Optionally "qualified" (e.g., `<Vec<T> as SomeTrait>::SomeType`).
Path(Option<QSelf>, Path),
- /// A referencing operation (`&a` or `&mut a`).
- AddrOf(Mutability, P<Expr>),
+ /// A referencing operation (`&a`, `&mut a`, `&raw const a` or `&raw mut a`).
+ AddrOf(BorrowKind, Mutability, P<Expr>),
/// A `break`, with an optional label to break, and an optional expression.
Break(Option<Label>, Option<P<Expr>>),
/// A `continue`, with an optional label.
/// signature) or provided (meaning it has a default implementation).
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct TraitItem {
+ pub attrs: Vec<Attribute>,
pub id: NodeId,
+ pub span: Span,
+ pub vis: Visibility,
pub ident: Ident,
- pub attrs: Vec<Attribute>,
+
pub generics: Generics,
pub kind: TraitItemKind,
- pub span: Span,
/// See `Item::tokens` for what this is.
pub tokens: Option<TokenStream>,
}
/// Represents anything within an `impl` block.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct ImplItem {
+ pub attrs: Vec<Attribute>,
pub id: NodeId,
- pub ident: Ident,
+ pub span: Span,
pub vis: Visibility,
+ pub ident: Ident,
+
pub defaultness: Defaultness,
- pub attrs: Vec<Attribute>,
pub generics: Generics,
pub kind: ImplItemKind,
- pub span: Span,
/// See `Item::tokens` for what this is.
pub tokens: Option<TokenStream>,
}
IntTy::I128 => 128,
})
}
+
+ pub fn normalize(&self, target_width: u32) -> Self {
+ match self {
+ IntTy::Isize => match target_width {
+ 16 => IntTy::I16,
+ 32 => IntTy::I32,
+ 64 => IntTy::I64,
+ _ => unreachable!(),
+ },
+ _ => *self,
+ }
+ }
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic,
UintTy::U128 => 128,
})
}
+
+ pub fn normalize(&self, target_width: u32) -> Self {
+ match self {
+ UintTy::Usize => match target_width {
+ 16 => UintTy::U16,
+ 32 => UintTy::U32,
+ 64 => UintTy::U64,
+ _ => unreachable!(),
+ },
+ _ => *self,
+ }
+ }
}
/// A constraint on an associated type (e.g., `A = Bar` in `Foo<A = Bar>` or
pub struct EnumDef {
pub variants: Vec<Variant>,
}
-
/// Enum variant.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Variant {
- /// Name of the variant.
- pub ident: Ident,
/// Attributes of the variant.
pub attrs: Vec<Attribute>,
/// Id of the variant (not the constructor, see `VariantData::ctor_id()`).
pub id: NodeId,
+ /// Span
+ pub span: Span,
+ /// The visibility of the variant. Syntactically accepted but not semantically.
+ pub vis: Visibility,
+ /// Name of the variant.
+ pub ident: Ident,
+
/// Fields and constructor id of the variant.
pub data: VariantData,
/// Explicit discriminant, e.g., `Foo = 1`.
pub disr_expr: Option<AnonConst>,
- /// Span
- pub span: Span,
/// Is a macro placeholder
pub is_placeholder: bool,
}
/// E.g., `bar: usize` as in `struct Foo { bar: usize }`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct StructField {
+ pub attrs: Vec<Attribute>,
+ pub id: NodeId,
pub span: Span,
- pub ident: Option<Ident>,
pub vis: Visibility,
- pub id: NodeId,
+ pub ident: Option<Ident>,
+
pub ty: P<Ty>,
- pub attrs: Vec<Attribute>,
pub is_placeholder: bool,
}
/// The name might be a dummy name in case of anonymous items.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Item {
- pub ident: Ident,
pub attrs: Vec<Attribute>,
pub id: NodeId,
- pub kind: ItemKind,
- pub vis: Visibility,
pub span: Span,
+ pub vis: Visibility,
+ pub ident: Ident,
+
+ pub kind: ItemKind,
/// Original tokens this item was parsed from. This isn't necessarily
/// available for all items, although over time more and more items should
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct ForeignItem {
- pub ident: Ident,
pub attrs: Vec<Attribute>,
- pub kind: ForeignItemKind,
pub id: NodeId,
pub span: Span,
pub vis: Visibility,
+ pub ident: Ident,
+
+ pub kind: ForeignItemKind,
}
/// An item within an `extern` block.