summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_hir
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_hir')
-rw-r--r--compiler/rustc_hir/src/hir.rs48
-rw-r--r--compiler/rustc_hir/src/hir_id.rs6
-rw-r--r--compiler/rustc_hir/src/intravisit.rs1
-rw-r--r--compiler/rustc_hir/src/lang_items.rs8
-rw-r--r--compiler/rustc_hir/src/pat_util.rs11
-rw-r--r--compiler/rustc_hir/src/stable_hash_impls.rs17
6 files changed, 49 insertions, 42 deletions
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index 19d3d41c9..35a72f868 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -328,7 +328,7 @@ pub struct GenericArgs<'hir> {
/// Were arguments written in parenthesized form `Fn(T) -> U`?
/// This is required mostly for pretty-printing and diagnostics,
/// but also for changing lifetime elision rules to be "function-like".
- pub parenthesized: bool,
+ pub parenthesized: GenericArgsParentheses,
/// The span encompassing arguments and the surrounding brackets `<>` or `()`
/// Foo<A, B, AssocTy = D> Fn(T, U, V) -> W
/// ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^
@@ -340,11 +340,16 @@ pub struct GenericArgs<'hir> {
impl<'hir> GenericArgs<'hir> {
pub const fn none() -> Self {
- Self { args: &[], bindings: &[], parenthesized: false, span_ext: DUMMY_SP }
+ Self {
+ args: &[],
+ bindings: &[],
+ parenthesized: GenericArgsParentheses::No,
+ span_ext: DUMMY_SP,
+ }
}
pub fn inputs(&self) -> &[Ty<'hir>] {
- if self.parenthesized {
+ if self.parenthesized == GenericArgsParentheses::ParenSugar {
for arg in self.args {
match arg {
GenericArg::Lifetime(_) => {}
@@ -417,6 +422,17 @@ impl<'hir> GenericArgs<'hir> {
}
}
+#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug)]
+#[derive(HashStable_Generic)]
+pub enum GenericArgsParentheses {
+ No,
+ /// Bounds for `feature(return_type_notation)`, like `T: Trait<method(..): Send>`,
+ /// where the args are explicitly elided with `..`
+ ReturnTypeNotation,
+ /// parenthesized function-family traits, like `T: Fn(u32) -> i32`
+ ParenSugar,
+}
+
/// A modifier on a bound, currently this is only used for `?Sized`, where the
/// modifier is `Maybe`. Negative bounds should also be handled here.
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug)]
@@ -815,12 +831,13 @@ pub struct ParentedNode<'tcx> {
#[derive(Debug)]
pub struct AttributeMap<'tcx> {
pub map: SortedMap<ItemLocalId, &'tcx [Attribute]>,
- pub hash: Fingerprint,
+ // Only present when the crate hash is needed.
+ pub opt_hash: Option<Fingerprint>,
}
impl<'tcx> AttributeMap<'tcx> {
pub const EMPTY: &'static AttributeMap<'static> =
- &AttributeMap { map: SortedMap::new(), hash: Fingerprint::ZERO };
+ &AttributeMap { map: SortedMap::new(), opt_hash: Some(Fingerprint::ZERO) };
#[inline]
pub fn get(&self, id: ItemLocalId) -> &'tcx [Attribute] {
@@ -832,10 +849,9 @@ impl<'tcx> AttributeMap<'tcx> {
/// These nodes are mapped by `ItemLocalId` alongside the index of their parent node.
/// The HIR tree, including bodies, is pre-hashed.
pub struct OwnerNodes<'tcx> {
- /// Pre-computed hash of the full HIR.
- pub hash_including_bodies: Fingerprint,
- /// Pre-computed hash of the item signature, without recursing into the body.
- pub hash_without_bodies: Fingerprint,
+ /// Pre-computed hash of the full HIR. Used in the crate hash. Only present
+ /// when incr. comp. is enabled.
+ pub opt_hash_including_bodies: Option<Fingerprint>,
/// Full HIR for the current owner.
// The zeroth node's parent should never be accessed: the owner's parent is computed by the
// hir_owner_parent query. It is set to `ItemLocalId::INVALID` to force an ICE if accidentally
@@ -872,8 +888,7 @@ impl fmt::Debug for OwnerNodes<'_> {
.collect::<Vec<_>>(),
)
.field("bodies", &self.bodies)
- .field("hash_without_bodies", &self.hash_without_bodies)
- .field("hash_including_bodies", &self.hash_including_bodies)
+ .field("opt_hash_including_bodies", &self.opt_hash_including_bodies)
.finish()
}
}
@@ -940,7 +955,8 @@ impl<T> MaybeOwner<T> {
#[derive(Debug)]
pub struct Crate<'hir> {
pub owners: IndexVec<LocalDefId, MaybeOwner<&'hir OwnerInfo<'hir>>>,
- pub hir_hash: Fingerprint,
+ // Only present when incr. comp. is enabled.
+ pub opt_hir_hash: Option<Fingerprint>,
}
#[derive(Debug, HashStable_Generic)]
@@ -1673,7 +1689,6 @@ pub struct Expr<'hir> {
impl Expr<'_> {
pub fn precedence(&self) -> ExprPrecedence {
match self.kind {
- ExprKind::Box(_) => ExprPrecedence::Box,
ExprKind::ConstBlock(_) => ExprPrecedence::ConstBlock,
ExprKind::Array(_) => ExprPrecedence::Array,
ExprKind::Call(..) => ExprPrecedence::Call,
@@ -1763,7 +1778,6 @@ impl Expr<'_> {
| ExprKind::Lit(_)
| ExprKind::ConstBlock(..)
| ExprKind::Unary(..)
- | ExprKind::Box(..)
| ExprKind::AddrOf(..)
| ExprKind::Binary(..)
| ExprKind::Yield(..)
@@ -1851,7 +1865,6 @@ impl Expr<'_> {
| ExprKind::InlineAsm(..)
| ExprKind::AssignOp(..)
| ExprKind::ConstBlock(..)
- | ExprKind::Box(..)
| ExprKind::Binary(..)
| ExprKind::Yield(..)
| ExprKind::DropTemps(..)
@@ -1862,8 +1875,7 @@ impl Expr<'_> {
/// To a first-order approximation, is this a pattern?
pub fn is_approximately_pattern(&self) -> bool {
match &self.kind {
- ExprKind::Box(_)
- | ExprKind::Array(_)
+ ExprKind::Array(_)
| ExprKind::Call(..)
| ExprKind::Tup(_)
| ExprKind::Lit(_)
@@ -1910,8 +1922,6 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool {
#[derive(Debug, HashStable_Generic)]
pub enum ExprKind<'hir> {
- /// A `box x` expression.
- Box(&'hir Expr<'hir>),
/// Allow anonymous constants from an inline `const` block
ConstBlock(AnonConst),
/// An array (e.g., `[a, b, c, d]`).
diff --git a/compiler/rustc_hir/src/hir_id.rs b/compiler/rustc_hir/src/hir_id.rs
index 404abe2b0..37ac37231 100644
--- a/compiler/rustc_hir/src/hir_id.rs
+++ b/compiler/rustc_hir/src/hir_id.rs
@@ -22,6 +22,12 @@ impl From<OwnerId> for HirId {
}
}
+impl From<OwnerId> for DefId {
+ fn from(value: OwnerId) -> Self {
+ value.to_def_id()
+ }
+}
+
impl OwnerId {
#[inline]
pub fn to_def_id(self) -> DefId {
diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs
index cc0f64017..234256ab5 100644
--- a/compiler/rustc_hir/src/intravisit.rs
+++ b/compiler/rustc_hir/src/intravisit.rs
@@ -682,7 +682,6 @@ pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonCo
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) {
visitor.visit_id(expression.hir_id);
match expression.kind {
- ExprKind::Box(ref subexpression) => visitor.visit_expr(subexpression),
ExprKind::Array(subexpressions) => {
walk_list!(visitor, visit_expr, subexpressions);
}
diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs
index 60fa5a99e..8f91a96f9 100644
--- a/compiler/rustc_hir/src/lang_items.rs
+++ b/compiler/rustc_hir/src/lang_items.rs
@@ -49,7 +49,7 @@ impl LanguageItems {
self.get(it).ok_or_else(|| LangItemError(it))
}
- pub fn iter<'a>(&'a self) -> impl Iterator<Item = (LangItem, DefId)> + 'a {
+ pub fn iter(&self) -> impl Iterator<Item = (LangItem, DefId)> + '_ {
self.items
.iter()
.enumerate()
@@ -166,6 +166,9 @@ language_item_table! {
Freeze, sym::freeze, freeze_trait, Target::Trait, GenericRequirement::Exact(0);
+ FnPtrTrait, sym::fn_ptr_trait, fn_ptr_trait, Target::Trait, GenericRequirement::Exact(0);
+ FnPtrAddr, sym::fn_ptr_addr, fn_ptr_addr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
+
Drop, sym::drop, drop_trait, Target::Trait, GenericRequirement::None;
Destruct, sym::destruct, destruct_trait, Target::Trait, GenericRequirement::None;
@@ -237,6 +240,7 @@ language_item_table! {
PanicDisplay, sym::panic_display, panic_display, Target::Fn, GenericRequirement::None;
ConstPanicFmt, sym::const_panic_fmt, const_panic_fmt, Target::Fn, GenericRequirement::None;
PanicBoundsCheck, sym::panic_bounds_check, panic_bounds_check_fn, Target::Fn, GenericRequirement::Exact(0);
+ PanicMisalignedPointerDereference, sym::panic_misaligned_pointer_dereference, panic_misaligned_pointer_dereference_fn, Target::Fn, GenericRequirement::Exact(0);
PanicInfo, sym::panic_info, panic_info, Target::Struct, GenericRequirement::None;
PanicLocation, sym::panic_location, panic_location, Target::Struct, GenericRequirement::None;
PanicImpl, sym::panic_impl, panic_impl, Target::Fn, GenericRequirement::None;
@@ -296,12 +300,12 @@ language_item_table! {
// FIXME(swatinem): the following lang items are used for async lowering and
// should become obsolete eventually.
ResumeTy, sym::ResumeTy, resume_ty, Target::Struct, GenericRequirement::None;
- IdentityFuture, sym::identity_future, identity_future_fn, Target::Fn, GenericRequirement::None;
GetContext, sym::get_context, get_context_fn, Target::Fn, GenericRequirement::None;
Context, sym::Context, context, Target::Struct, GenericRequirement::None;
FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
+ Option, sym::Option, option_type, Target::Enum, GenericRequirement::None;
OptionSome, sym::Some, option_some_variant, Target::Variant, GenericRequirement::None;
OptionNone, sym::None, option_none_variant, Target::Variant, GenericRequirement::None;
diff --git a/compiler/rustc_hir/src/pat_util.rs b/compiler/rustc_hir/src/pat_util.rs
index e870aa543..838c123f8 100644
--- a/compiler/rustc_hir/src/pat_util.rs
+++ b/compiler/rustc_hir/src/pat_util.rs
@@ -2,7 +2,6 @@ use crate::def::{CtorOf, DefKind, Res};
use crate::def_id::DefId;
use crate::hir::{self, BindingAnnotation, ByRef, HirId, PatKind};
use rustc_data_structures::fx::FxHashSet;
-use rustc_span::hygiene::DesugaringKind;
use rustc_span::symbol::Ident;
use rustc_span::Span;
@@ -136,14 +135,4 @@ impl hir::Pat<'_> {
});
result
}
-
- /// If the pattern is `Some(<pat>)` from a desugared for loop, returns the inner pattern
- pub fn for_loop_some(&self) -> Option<&Self> {
- if self.span.desugaring_kind() == Some(DesugaringKind::ForLoop) {
- if let hir::PatKind::Struct(_, [pat_field], _) = self.kind {
- return Some(pat_field.pat);
- }
- }
- None
- }
}
diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs
index 85d0e02d0..97fa710b3 100644
--- a/compiler/rustc_hir/src/stable_hash_impls.rs
+++ b/compiler/rustc_hir/src/stable_hash_impls.rs
@@ -100,24 +100,23 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'
// `local_id_to_def_id` is also ignored because is dependent on the body, then just hashing
// the body satisfies the condition of two nodes being different have different
// `hash_stable` results.
- let OwnerNodes { hash_including_bodies, hash_without_bodies: _, nodes: _, bodies: _ } =
- *self;
- hash_including_bodies.hash_stable(hcx, hasher);
+ let OwnerNodes { opt_hash_including_bodies, nodes: _, bodies: _ } = *self;
+ opt_hash_including_bodies.unwrap().hash_stable(hcx, hasher);
}
}
impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for AttributeMap<'tcx> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
- // We ignore the `map` since it refers to information included in `hash` which is hashed in
- // the collector and used for the crate hash.
- let AttributeMap { hash, map: _ } = *self;
- hash.hash_stable(hcx, hasher);
+ // We ignore the `map` since it refers to information included in `opt_hash` which is
+ // hashed in the collector and used for the crate hash.
+ let AttributeMap { opt_hash, map: _ } = *self;
+ opt_hash.unwrap().hash_stable(hcx, hasher);
}
}
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Crate<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
- let Crate { owners: _, hir_hash } = self;
- hir_hash.hash_stable(hcx, hasher)
+ let Crate { owners: _, opt_hir_hash } = self;
+ opt_hir_hash.unwrap().hash_stable(hcx, hasher)
}
}