/// User-given names or fresh (synthetic) names.
Param(LocalDefId, ParamName),
- /// User wrote nothing (e.g., the lifetime in `&u32`).
- Implicit,
-
/// Implicit lifetime in a context like `dyn Foo`. This is
/// distinguished from implicit lifetimes elsewhere because the
/// lifetime that they default to must appear elsewhere within the
/// that was already reported.
Error,
- /// User wrote specifies `'_`.
- Underscore,
+ /// User wrote an anonymous lifetime, either `'_` or nothing.
+ /// The semantics of this lifetime should be inferred by typechecking code.
+ Infer,
/// User wrote `'static`.
Static,
impl LifetimeName {
pub fn ident(&self) -> Ident {
match *self {
- LifetimeName::ImplicitObjectLifetimeDefault
- | LifetimeName::Implicit
- | LifetimeName::Error => Ident::empty(),
- LifetimeName::Underscore => Ident::with_dummy_span(kw::UnderscoreLifetime),
+ LifetimeName::ImplicitObjectLifetimeDefault | LifetimeName::Error => Ident::empty(),
+ LifetimeName::Infer => Ident::with_dummy_span(kw::UnderscoreLifetime),
LifetimeName::Static => Ident::with_dummy_span(kw::StaticLifetime),
LifetimeName::Param(_, param_name) => param_name.ident(),
}
pub fn is_anonymous(&self) -> bool {
match *self {
LifetimeName::ImplicitObjectLifetimeDefault
- | LifetimeName::Implicit
- | LifetimeName::Underscore
+ | LifetimeName::Infer
| LifetimeName::Param(_, ParamName::Fresh)
| LifetimeName::Error => true,
LifetimeName::Static | LifetimeName::Param(..) => false,
pub fn is_elided(&self) -> bool {
match self {
- LifetimeName::ImplicitObjectLifetimeDefault
- | LifetimeName::Implicit
- | LifetimeName::Underscore => true,
+ LifetimeName::ImplicitObjectLifetimeDefault | LifetimeName::Infer => true,
// It might seem surprising that `Fresh` counts as
// *not* elided -- but this is because, as far as the code
pub hir_hash: Fingerprint,
}
+#[derive(Debug, HashStable_Generic)]
+pub struct Closure<'hir> {
+ pub binder: ClosureBinder,
+ pub capture_clause: CaptureBy,
+ pub bound_generic_params: &'hir [GenericParam<'hir>],
+ pub fn_decl: &'hir FnDecl<'hir>,
+ pub body: BodyId,
+ pub fn_decl_span: Span,
+ pub movability: Option<Movability>,
+}
+
/// A block of statements `{ .. }`, which may have a label (in this case the
/// `targeted_by_break` field will be `true`) and may be `unsafe` by means of
/// the `rules` being anything but `DefaultBlock`.
pub targeted_by_break: bool,
}
+impl<'hir> Block<'hir> {
+ pub fn innermost_block(&self) -> &Block<'hir> {
+ let mut block = self;
+ while let Some(Expr { kind: ExprKind::Block(inner_block, _), .. }) = block.expr {
+ block = inner_block;
+ }
+ block
+ }
+}
+
#[derive(Debug, HashStable_Generic)]
pub struct Pat<'hir> {
#[stable_hasher(ignore)]
pub ty: Option<&'hir Ty<'hir>>,
/// Initializer expression to set the value, if any.
pub init: Option<&'hir Expr<'hir>>,
+ /// Else block for a `let...else` binding.
+ pub els: Option<&'hir Block<'hir>>,
pub hir_id: HirId,
pub span: Span,
/// Can be `ForLoopDesugar` if the `let` statement is part of a `for` loop
}
/// The type of source expression that caused this generator to be created.
-#[derive(
- Clone,
- PartialEq,
- PartialOrd,
- Eq,
- Hash,
- HashStable_Generic,
- Encodable,
- Decodable,
- Debug,
- Copy
-)]
+#[derive(Clone, PartialEq, PartialOrd, Eq, Hash, Debug, Copy)]
+#[derive(HashStable_Generic, Encodable, Decodable)]
pub enum GeneratorKind {
/// An explicit `async` block or the body of an async function.
Async(AsyncGeneratorKind),
///
/// This helps error messages but is also used to drive coercions in
/// type-checking (see #60424).
-#[derive(
- Clone,
- PartialEq,
- PartialOrd,
- Eq,
- Hash,
- HashStable_Generic,
- Encodable,
- Decodable,
- Debug,
- Copy
-)]
+#[derive(Clone, PartialEq, PartialOrd, Eq, Hash, Debug, Copy)]
+#[derive(HashStable_Generic, Encodable, Decodable)]
pub enum AsyncGeneratorKind {
/// An explicit `async` block written by the user.
Block,
}
}
+// NOTE: `IntoDiagnosticArg` impl for `ConstContext` lives in `rustc_errors`
+// due to a cyclical dependency between hir that crate.
+
/// A literal.
pub type Lit = Spanned<LitKind>;
_ => false,
}
}
+
+ pub fn method_ident(&self) -> Option<Ident> {
+ match self.kind {
+ ExprKind::MethodCall(receiver_method, ..) => Some(receiver_method.ident),
+ ExprKind::Unary(_, expr) | ExprKind::AddrOf(.., expr) => expr.method_ident(),
+ _ => None,
+ }
+ }
}
/// Checks if the specified expression is a built-in range literal.
///
/// This may also be a generator literal or an `async block` as indicated by the
/// `Option<Movability>`.
- Closure {
- capture_clause: CaptureBy,
- bound_generic_params: &'hir [GenericParam<'hir>],
- fn_decl: &'hir FnDecl<'hir>,
- body: BodyId,
- fn_decl_span: Span,
- movability: Option<Movability>,
- },
+ Closure(&'hir Closure<'hir>),
/// A block (e.g., `'label: { ... }`).
Block(&'hir Block<'hir>, Option<Label>),
pub generics: &'hir Generics<'hir>,
pub kind: TraitItemKind<'hir>,
pub span: Span,
+ pub defaultness: Defaultness,
}
impl TraitItem<'_> {
pub def_id: LocalDefId,
pub generics: &'hir Generics<'hir>,
pub kind: ImplItemKind<'hir>,
+ pub defaultness: Defaultness,
pub span: Span,
pub vis_span: Span,
}
}
}
+/// Represents `for<...>` binder before a closure
+#[derive(Copy, Clone, Debug, HashStable_Generic)]
+pub enum ClosureBinder {
+ /// Binder is not specified.
+ Default,
+ /// Binder is specified.
+ ///
+ /// Span points to the whole `for<...>`.
+ For { span: Span },
+}
+
#[derive(Encodable, Debug, HashStable_Generic)]
pub struct Mod<'hir> {
pub spans: ModSpans,
pub ident: Ident,
pub kind: AssocItemKind,
pub span: Span,
- pub defaultness: Defaultness,
}
/// A reference from an impl to one of its associated items. This
pub ident: Ident,
pub kind: AssocItemKind,
pub span: Span,
- pub defaultness: Defaultness,
/// When we are in a trait impl, link to the trait-item's id.
pub trait_item_def_id: Option<DefId>,
}
Ty(&'hir Ty<'hir>),
TypeBinding(&'hir TypeBinding<'hir>),
TraitRef(&'hir TraitRef<'hir>),
- Binding(&'hir Pat<'hir>),
Pat(&'hir Pat<'hir>),
Arm(&'hir Arm<'hir>),
Block(&'hir Block<'hir>),
| Node::Block(..)
| Node::Ctor(..)
| Node::Pat(..)
- | Node::Binding(..)
| Node::Arm(..)
| Node::Local(..)
| Node::Crate(..)
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
mod size_asserts {
- rustc_data_structures::static_assert_size!(super::Block<'static>, 48);
- rustc_data_structures::static_assert_size!(super::Expr<'static>, 64);
- rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
- rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
- rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
- rustc_data_structures::static_assert_size!(super::GenericBound<'_>, 48);
- rustc_data_structures::static_assert_size!(super::Generics<'static>, 56);
- rustc_data_structures::static_assert_size!(super::Impl<'static>, 80);
-
- rustc_data_structures::static_assert_size!(super::Item<'static>, 80);
- rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 88);
- rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 80);
- rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 72);
+ use super::*;
+ // These are in alphabetical order, which is easy to maintain.
+ rustc_data_structures::static_assert_size!(Block<'static>, 48);
+ rustc_data_structures::static_assert_size!(Expr<'static>, 56);
+ rustc_data_structures::static_assert_size!(ForeignItem<'static>, 72);
+ rustc_data_structures::static_assert_size!(GenericBound<'_>, 48);
+ rustc_data_structures::static_assert_size!(Generics<'static>, 56);
+ rustc_data_structures::static_assert_size!(ImplItem<'static>, 88);
+ rustc_data_structures::static_assert_size!(Impl<'static>, 80);
+ rustc_data_structures::static_assert_size!(Item<'static>, 80);
+ rustc_data_structures::static_assert_size!(Pat<'static>, 88);
+ rustc_data_structures::static_assert_size!(QPath<'static>, 24);
+ rustc_data_structures::static_assert_size!(TraitItem<'static>, 96);
+ rustc_data_structures::static_assert_size!(Ty<'static>, 72);
}