mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
create def ids for impl traits during ast lowering
This commit is contained in:
parent
65445a571c
commit
b2bef02bcd
@ -61,8 +61,8 @@ use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
|||||||
use rustc_hir::definitions::DefPathData;
|
use rustc_hir::definitions::DefPathData;
|
||||||
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
|
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
|
||||||
use rustc_index::vec::{Idx, IndexVec};
|
use rustc_index::vec::{Idx, IndexVec};
|
||||||
use rustc_middle::span_bug;
|
|
||||||
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
|
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
|
||||||
|
use rustc_middle::{bug, span_bug};
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::source_map::DesugaringKind;
|
use rustc_span::source_map::DesugaringKind;
|
||||||
@ -1060,13 +1060,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
// Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`. We do this by
|
// Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`. We do this by
|
||||||
// constructing the HIR for `impl bounds...` and then lowering that.
|
// 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();
|
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| {
|
self.with_dyn_type_scope(false, |this| {
|
||||||
let node_id = this.next_node_id();
|
let node_id = this.next_node_id();
|
||||||
@ -1357,9 +1351,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
def_node_id,
|
def_node_id,
|
||||||
bounds,
|
bounds,
|
||||||
false,
|
false,
|
||||||
&ImplTraitContext::TypeAliasesOpaqueTy,
|
itctx,
|
||||||
),
|
),
|
||||||
ImplTraitContext::Universal => {
|
ImplTraitContext::Universal => {
|
||||||
|
self.create_def(
|
||||||
|
self.current_hir_id_owner.def_id,
|
||||||
|
def_node_id,
|
||||||
|
DefPathData::ImplTrait,
|
||||||
|
);
|
||||||
let span = t.span;
|
let span = t.span;
|
||||||
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
|
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
|
||||||
let (param, bounds, path) =
|
let (param, bounds, path) =
|
||||||
@ -1453,7 +1452,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
// frequently opened issues show.
|
// frequently opened issues show.
|
||||||
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
|
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);
|
debug!(?opaque_ty_def_id);
|
||||||
|
|
||||||
// Contains the new lifetime definitions created for the TAIT (if any).
|
// Contains the new lifetime definitions created for the TAIT (if any).
|
||||||
|
@ -14,7 +14,7 @@ use rustc_index::vec::Idx;
|
|||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
use rustc_span::def_id::StableCrateId;
|
use rustc_span::def_id::StableCrateId;
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
use rustc_span::Span;
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1131,7 +1131,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
|
|||||||
.filter_map(|(def_id, info)| {
|
.filter_map(|(def_id, info)| {
|
||||||
let _ = info.as_owner()?;
|
let _ = info.as_owner()?;
|
||||||
let def_path_hash = definitions.def_path_hash(def_id);
|
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);
|
debug_assert_eq!(span.parent(), None);
|
||||||
Some((def_path_hash, span))
|
Some((def_path_hash, span))
|
||||||
})
|
})
|
||||||
|
@ -12,7 +12,7 @@ use rustc_session::cstore::CrateStore;
|
|||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::source_map::SourceMap;
|
use rustc_span::source_map::SourceMap;
|
||||||
use rustc_span::symbol::Symbol;
|
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
|
/// 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.,
|
/// enough information to transform `DefId`s and `HirId`s into stable `DefPath`s (i.e.,
|
||||||
@ -185,7 +185,7 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn def_span(&self, def_id: LocalDefId) -> Span {
|
fn def_span(&self, def_id: LocalDefId) -> Span {
|
||||||
self.source_span[def_id]
|
*self.source_span.get(def_id).unwrap_or(&DUMMY_SP)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -285,21 +285,6 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
|
|||||||
fn visit_ty(&mut self, ty: &'a Ty) {
|
fn visit_ty(&mut self, ty: &'a Ty) {
|
||||||
match ty.kind {
|
match ty.kind {
|
||||||
TyKind::MacCall(..) => self.visit_macro_invoc(ty.id),
|
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),
|
_ => visit::walk_ty(self, ty),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ note: generator is not `Send` as this value is used across a yield
|
|||||||
--> $DIR/generator-print-verbose-1.rs:35:9
|
--> $DIR/generator-print-verbose-1.rs:35:9
|
||||||
|
|
|
|
||||||
LL | let _non_send_gen = make_non_send_generator();
|
LL | let _non_send_gen = make_non_send_generator();
|
||||||
| ------------- has type `Opaque(DefId(0:34 ~ generator_print_verbose_1[749a]::make_non_send_generator::{opaque#0}), [])` which is not `Send`
|
| ------------- has type `Opaque(DefId(0:44 ~ generator_print_verbose_1[749a]::make_non_send_generator::{opaque#0}), [])` which is not `Send`
|
||||||
LL | yield;
|
LL | yield;
|
||||||
| ^^^^^ yield occurs here, with `_non_send_gen` maybe used later
|
| ^^^^^ yield occurs here, with `_non_send_gen` maybe used later
|
||||||
LL | };
|
LL | };
|
||||||
@ -35,17 +35,17 @@ note: required because it's used within this generator
|
|||||||
|
|
|
|
||||||
LL | || {
|
LL | || {
|
||||||
| ^^
|
| ^^
|
||||||
note: required because it appears within the type `Opaque(DefId(0:39 ~ generator_print_verbose_1[749a]::make_gen2::{opaque#0}), [std::sync::Arc<std::cell::RefCell<i32>>])`
|
note: required because it appears within the type `Opaque(DefId(0:45 ~ generator_print_verbose_1[749a]::make_gen2::{opaque#0}), [std::sync::Arc<std::cell::RefCell<i32>>])`
|
||||||
--> $DIR/generator-print-verbose-1.rs:41:30
|
--> $DIR/generator-print-verbose-1.rs:41:30
|
||||||
|
|
|
|
||||||
LL | pub fn make_gen2<T>(t: T) -> impl Generator<Return = T> {
|
LL | pub fn make_gen2<T>(t: T) -> impl Generator<Return = T> {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
note: required because it appears within the type `Opaque(DefId(0:42 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`
|
note: required because it appears within the type `Opaque(DefId(0:46 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`
|
||||||
--> $DIR/generator-print-verbose-1.rs:47:34
|
--> $DIR/generator-print-verbose-1.rs:47:34
|
||||||
|
|
|
|
||||||
LL | fn make_non_send_generator2() -> impl Generator<Return = Arc<RefCell<i32>>> {
|
LL | fn make_non_send_generator2() -> impl Generator<Return = Arc<RefCell<i32>>> {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
= note: required because it captures the following types: `Opaque(DefId(0:42 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`, `()`
|
= note: required because it captures the following types: `Opaque(DefId(0:46 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`, `()`
|
||||||
note: required because it's used within this generator
|
note: required because it's used within this generator
|
||||||
--> $DIR/generator-print-verbose-1.rs:52:20
|
--> $DIR/generator-print-verbose-1.rs:52:20
|
||||||
|
|
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
error[E0700]: hidden type for `Opaque(DefId(0:11 ~ impl_trait_captures[1afc]::foo::{opaque#0}), [ReStatic, T, ReEarlyBound(0, 'a)])` captures lifetime that does not appear in bounds
|
error[E0700]: hidden type for `Opaque(DefId(0:13 ~ impl_trait_captures[1afc]::foo::{opaque#0}), [ReStatic, T, ReEarlyBound(0, 'a)])` captures lifetime that does not appear in bounds
|
||||||
--> $DIR/impl-trait-captures.rs:11:5
|
--> $DIR/impl-trait-captures.rs:11:5
|
||||||
|
|
|
|
||||||
LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> {
|
LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> {
|
||||||
| -- hidden type `&ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_)) T` captures the anonymous lifetime defined here
|
| -- hidden type `&ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[1afc]::foo::'_), '_)) T` captures the anonymous lifetime defined here
|
||||||
LL | x
|
LL | x
|
||||||
| ^
|
| ^
|
||||||
|
|
|
|
||||||
help: to declare that the `impl Trait` captures `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_))`, you can add an explicit `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_))` lifetime bound
|
help: to declare that the `impl Trait` captures `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[1afc]::foo::'_), '_))`, you can add an explicit `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[1afc]::foo::'_), '_))` lifetime bound
|
||||||
|
|
|
|
||||||
LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_)) {
|
LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[1afc]::foo::'_), '_)) {
|
||||||
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
Loading…
Reference in New Issue
Block a user