use crate::def::{CtorKind, DefKind, Res};
use crate::def_id::{DefId, CRATE_DEF_ID};
crate use crate::hir_id::{HirId, ItemLocalId};
-use crate::{itemlikevisit, LangItem};
+use crate::LangItem;
use rustc_ast::util::parser::ExprPrecedence;
use rustc_ast::{self as ast, CrateSugar, LlvmAsmDialect};
pub use rustc_ast::{CaptureBy, Movability, Mutability};
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_data_structures::fx::FxHashMap;
-use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
use rustc_index::vec::IndexVec;
use rustc_macros::HashStable_Generic;
use rustc_span::source_map::Spanned;
use rustc_target::spec::abi::Abi;
use smallvec::SmallVec;
-use std::collections::{BTreeMap, BTreeSet};
+use std::collections::BTreeMap;
use std::fmt;
#[derive(Copy, Clone, Encodable, HashStable_Generic)]
self.args.iter().any(|arg| matches!(arg, GenericArg::Type(_)))
}
+ pub fn has_err(&self) -> bool {
+ self.args.iter().any(|arg| match arg {
+ GenericArg::Type(ty) => matches!(ty.kind, TyKind::Err),
+ _ => false,
+ }) || self.bindings.iter().any(|arg| match arg.kind {
+ TypeBindingKind::Equality { ty } => matches!(ty.kind, TyKind::Err),
+ _ => false,
+ })
+ }
+
#[inline]
pub fn num_type_params(&self) -> usize {
self.args.iter().filter(|arg| matches!(arg, GenericArg::Type(_))).count()
Trait(PolyTraitRef<'hir>, TraitBoundModifier),
// FIXME(davidtwco): Introduce `PolyTraitRef::LangItem`
LangItemTrait(LangItem, Span, HirId, &'hir GenericArgs<'hir>),
- Unsized(Span),
Outlives(Lifetime),
}
+#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
+rustc_data_structures::static_assert_size!(GenericBound<'_>, 48);
+
impl GenericBound<'_> {
pub fn trait_ref(&self) -> Option<&TraitRef<'_>> {
match self {
GenericBound::Trait(t, ..) => t.span,
GenericBound::LangItemTrait(_, span, ..) => *span,
GenericBound::Outlives(l) => l.span,
- GenericBound::Unsized(span) => *span,
}
}
}
pub rhs_ty: &'hir Ty<'hir>,
}
-#[derive(Default, Encodable, Debug, HashStable_Generic)]
-pub struct ModuleItems {
- // Use BTreeSets here so items are in the same order as in the
- // list of all items in Crate
- pub items: BTreeSet<ItemId>,
- pub trait_items: BTreeSet<TraitItemId>,
- pub impl_items: BTreeSet<ImplItemId>,
- pub foreign_items: BTreeSet<ForeignItemId>,
-}
-
/// The top-level data structure that stores the entire contents of
/// the crate currently being compiled.
///
pub owners: IndexVec<LocalDefId, Option<OwnerNode<'hir>>>,
pub bodies: BTreeMap<BodyId, Body<'hir>>,
- /// A list of modules written out in the order in which they
- /// appear in the crate. This includes the main crate module.
- pub modules: BTreeMap<LocalDefId, ModuleItems>,
-
/// Map indicating what traits are in scope for places where this
/// is relevant; generated by resolve.
pub trait_map: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Box<[TraitCandidate]>>>,
}
}
-impl Crate<'_> {
- /// Visits all items in the crate in some deterministic (but
- /// unspecified) order. If you just need to process every item,
- /// but don't care about nesting, this method is the best choice.
- ///
- /// If you do care about nesting -- usually because your algorithm
- /// follows lexical scoping rules -- then you want a different
- /// approach. You should override `visit_nested_item` in your
- /// visitor and then call `intravisit::walk_crate` instead.
- pub fn visit_all_item_likes<'hir, V>(&'hir self, visitor: &mut V)
- where
- V: itemlikevisit::ItemLikeVisitor<'hir>,
- {
- for owner in self.owners.iter().filter_map(Option::as_ref) {
- match owner {
- OwnerNode::Item(item) => visitor.visit_item(item),
- OwnerNode::ForeignItem(item) => visitor.visit_foreign_item(item),
- OwnerNode::ImplItem(item) => visitor.visit_impl_item(item),
- OwnerNode::TraitItem(item) => visitor.visit_trait_item(item),
- OwnerNode::Crate(_) => {}
- }
- }
- }
-
- /// A parallel version of `visit_all_item_likes`.
- pub fn par_visit_all_item_likes<'hir, V>(&'hir self, visitor: &V)
- where
- V: itemlikevisit::ParItemLikeVisitor<'hir> + Sync + Send,
- {
- par_for_each_in(&self.owners.raw, |owner| match owner {
- Some(OwnerNode::Item(item)) => visitor.visit_item(item),
- Some(OwnerNode::ForeignItem(item)) => visitor.visit_foreign_item(item),
- Some(OwnerNode::ImplItem(item)) => visitor.visit_impl_item(item),
- Some(OwnerNode::TraitItem(item)) => visitor.visit_trait_item(item),
- Some(OwnerNode::Crate(_)) | None => {}
- })
- }
-
- pub fn items<'hir>(&'hir self) -> impl Iterator<Item = &'hir Item<'hir>> + 'hir {
- self.owners.iter().filter_map(|owner| match owner {
- Some(OwnerNode::Item(item)) => Some(*item),
- _ => None,
- })
- }
-}
-
/// 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`.
///
/// Type parameters may be stored in each `PathSegment`.
Path(QPath<'hir>),
- /// An opaque type definition itself. This is currently only used for the
- /// `opaque type Foo: Trait` item that `impl Trait` in desugars to.
+ /// An opaque type definition itself. This is only used for `impl Trait`.
///
/// The generic argument list contains the lifetimes (and in the future
/// possibly parameters) that are actually bound on the `impl Trait`.
Self::Const { .. } | Self::Sym { .. } => None,
}
}
+
+ pub fn is_clobber(&self) -> bool {
+ matches!(
+ self,
+ InlineAsmOperand::Out { reg: InlineAsmRegOrRegClass::Reg(_), late: _, expr: None }
+ )
+ }
}
#[derive(Debug, HashStable_Generic)]
/// A module.
Mod(Mod<'hir>),
/// An external module, e.g. `extern { .. }`.
- ForeignMod { abi: Abi, items: &'hir [ForeignItemRef<'hir>] },
+ ForeignMod { abi: Abi, items: &'hir [ForeignItemRef] },
/// Module-level inline assembly (from `global_asm!`).
GlobalAsm(&'hir InlineAsm<'hir>),
/// A type alias, e.g., `type Foo = Bar<u8>`.
pub of_trait: Option<TraitRef<'hir>>,
pub self_ty: &'hir Ty<'hir>,
- pub items: &'hir [ImplItemRef<'hir>],
+ pub items: &'hir [ImplItemRef],
}
impl ItemKind<'_> {
/// passes to find the impl they want without loading the ID (which
/// means fewer edges in the incremental compilation graph).
#[derive(Debug, HashStable_Generic)]
-pub struct ImplItemRef<'hir> {
+pub struct ImplItemRef {
pub id: ImplItemId,
#[stable_hasher(project(name))]
pub ident: Ident,
pub kind: AssocItemKind,
pub span: Span,
- pub vis: Visibility<'hir>,
pub defaultness: Defaultness,
}
/// passes to find the impl they want without loading the ID (which
/// means fewer edges in the incremental compilation graph).
#[derive(Debug, HashStable_Generic)]
-pub struct ForeignItemRef<'hir> {
+pub struct ForeignItemRef {
pub id: ForeignItemId,
#[stable_hasher(project(name))]
pub ident: Ident,
pub span: Span,
- pub vis: Visibility<'hir>,
}
#[derive(Debug)]
}
}
- /// Returns `Constness::Const` when this node is a const fn/impl/item,
- ///
- /// HACK(fee1-dead): or an associated type in a trait. This works because
- /// only typeck cares about const trait predicates, so although the predicates
- /// query would return const predicates when it does not need to be const,
- /// it wouldn't have any effect.
+ /// Returns `Constness::Const` when this node is a const fn/impl/item.
pub fn constness_for_typeck(&self) -> Constness {
match self {
Node::Item(Item {
Node::Item(Item { kind: ItemKind::Const(..), .. })
| Node::TraitItem(TraitItem { kind: TraitItemKind::Const(..), .. })
- | Node::TraitItem(TraitItem { kind: TraitItemKind::Type(..), .. })
| Node::ImplItem(ImplItem { kind: ImplItemKind::Const(..), .. }) => Constness::Const,
_ => Constness::NotConst,