mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
create def ids for impl traits during ast lowering
This commit is contained in:
@@ -61,8 +61,8 @@
|
||||
use rustc_hir::definitions::DefPathData;
|
||||
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::hygiene::MacroKind;
|
||||
use rustc_span::source_map::DesugaringKind;
|
||||
@@ -1060,13 +1060,7 @@ fn lower_assoc_ty_constraint(
|
||||
// Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`. We do this by
|
||||
// constructing the HIR for `impl bounds...` and then lowering that.
|
||||
|
||||
let parent_def_id = self.current_hir_id_owner;
|
||||
let impl_trait_node_id = self.next_node_id();
|
||||
self.create_def(
|
||||
parent_def_id.def_id,
|
||||
impl_trait_node_id,
|
||||
DefPathData::ImplTrait,
|
||||
);
|
||||
|
||||
self.with_dyn_type_scope(false, |this| {
|
||||
let node_id = this.next_node_id();
|
||||
@@ -1357,9 +1351,14 @@ fn lower_ty_direct(&mut self, t: &Ty, itctx: &ImplTraitContext) -> hir::Ty<'hir>
|
||||
def_node_id,
|
||||
bounds,
|
||||
false,
|
||||
&ImplTraitContext::TypeAliasesOpaqueTy,
|
||||
itctx,
|
||||
),
|
||||
ImplTraitContext::Universal => {
|
||||
self.create_def(
|
||||
self.current_hir_id_owner.def_id,
|
||||
def_node_id,
|
||||
DefPathData::ImplTrait,
|
||||
);
|
||||
let span = t.span;
|
||||
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
|
||||
let (param, bounds, path) =
|
||||
@@ -1453,7 +1452,17 @@ fn lower_opaque_impl_trait(
|
||||
// frequently opened issues show.
|
||||
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
|
||||
|
||||
let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
|
||||
let opaque_ty_def_id = match origin {
|
||||
hir::OpaqueTyOrigin::TyAlias => self.create_def(
|
||||
self.current_hir_id_owner.def_id,
|
||||
opaque_ty_node_id,
|
||||
DefPathData::ImplTrait,
|
||||
),
|
||||
hir::OpaqueTyOrigin::FnReturn(fn_def_id) => {
|
||||
self.create_def(fn_def_id, opaque_ty_node_id, DefPathData::ImplTrait)
|
||||
}
|
||||
hir::OpaqueTyOrigin::AsyncFn(..) => bug!("unreachable"),
|
||||
};
|
||||
debug!(?opaque_ty_def_id);
|
||||
|
||||
// Contains the new lifetime definitions created for the TAIT (if any).
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_span::def_id::StableCrateId;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
#[inline]
|
||||
@@ -1131,7 +1131,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
|
||||
.filter_map(|(def_id, info)| {
|
||||
let _ = info.as_owner()?;
|
||||
let def_path_hash = definitions.def_path_hash(def_id);
|
||||
let span = resolutions.source_span[def_id];
|
||||
let span = resolutions.source_span.get(def_id).unwrap_or(&DUMMY_SP);
|
||||
debug_assert_eq!(span.parent(), None);
|
||||
Some((def_path_hash, span))
|
||||
})
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
use rustc_session::Session;
|
||||
use rustc_span::source_map::SourceMap;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::{BytePos, CachingSourceMapView, SourceFile, Span, SpanData};
|
||||
use rustc_span::{BytePos, CachingSourceMapView, SourceFile, Span, SpanData, DUMMY_SP};
|
||||
|
||||
/// This is the context state available during incr. comp. hashing. It contains
|
||||
/// enough information to transform `DefId`s and `HirId`s into stable `DefPath`s (i.e.,
|
||||
@@ -185,7 +185,7 @@ fn def_path_hash(&self, def_id: DefId) -> DefPathHash {
|
||||
|
||||
#[inline]
|
||||
fn def_span(&self, def_id: LocalDefId) -> Span {
|
||||
self.source_span[def_id]
|
||||
*self.source_span.get(def_id).unwrap_or(&DUMMY_SP)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -285,21 +285,6 @@ fn visit_expr(&mut self, expr: &'a Expr) {
|
||||
fn visit_ty(&mut self, ty: &'a Ty) {
|
||||
match ty.kind {
|
||||
TyKind::MacCall(..) => self.visit_macro_invoc(ty.id),
|
||||
TyKind::ImplTrait(node_id, _) => {
|
||||
let parent_def = match self.impl_trait_context {
|
||||
ImplTraitContext::Universal(item_def) => self.resolver.create_def(
|
||||
item_def,
|
||||
node_id,
|
||||
DefPathData::ImplTrait,
|
||||
self.expansion.to_expn_id(),
|
||||
ty.span,
|
||||
),
|
||||
ImplTraitContext::Existential => {
|
||||
self.create_def(node_id, DefPathData::ImplTrait, ty.span)
|
||||
}
|
||||
};
|
||||
self.with_parent(parent_def, |this| visit::walk_ty(this, ty))
|
||||
}
|
||||
_ => visit::walk_ty(self, ty),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user