use syntax_pos::{Span, DUMMY_SP, ExpnId};
use rustc_data_structures::fx::FxHashSet;
+use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_index::vec::Idx;
/// ```
///
/// `'outer` is a label.
-#[derive(Clone, RustcEncodable, RustcDecodable, Copy)]
+#[derive(Clone, RustcEncodable, RustcDecodable, Copy, HashStable_Generic)]
pub struct Label {
pub ident: Ident,
}
}
}
+impl<CTX> HashStable<CTX> for Path {
+ fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
+ self.segments.len().hash_stable(hcx, hasher);
+ for segment in &self.segments {
+ segment.ident.name.hash_stable(hcx, hasher);
+ }
+ }
+}
+
impl Path {
// Convert a span and an identifier to the corresponding
// one-segment path.
/// Possible values inside of compile-time attribute lists.
///
/// E.g., the '..' in `#[name(..)]`.
-#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
+#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub enum NestedMetaItem {
/// A full MetaItem, for recursive meta items.
MetaItem(MetaItem),
/// A spanned compile-time attribute item.
///
/// E.g., `#[test]`, `#[derive(..)]`, `#[rustfmt::skip]` or `#[feature = "foo"]`.
-#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
+#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub struct MetaItem {
pub path: Path,
pub kind: MetaItemKind,
/// A compile-time attribute item.
///
/// E.g., `#[test]`, `#[derive(..)]` or `#[feature = "foo"]`.
-#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
+#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub enum MetaItemKind {
/// Word meta item.
///
}
}
+/// 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)
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.
}
/// An AST literal.
-#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
+#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub struct Lit {
/// The original literal token as written in source code.
pub token: token::Lit,
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
}
}
-#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
+#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub struct AttrItem {
pub path: Path,
pub tokens: TokenStream,